[Home] [Help]
PACKAGE BODY: APPS.INV_RCV_COMMON_APIS
Source
1 PACKAGE BODY inv_rcv_common_apis AS
2 /* $Header: INVRCVCB.pls 120.32.12020000.5 2013/01/30 07:55:35 alxue ship $*/
3
4 -- Global constant holding the package name
5 g_pkg_name CONSTANT VARCHAR2(30) := 'inv_RCV_COMMON_APIS';
6
7 PROCEDURE print_debug(p_err_msg VARCHAR2, p_level NUMBER) IS
8 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9 BEGIN
10 IF (l_debug = 1) THEN
11 inv_mobile_helper_functions.tracelog(p_err_msg => p_err_msg, p_module => 'inv_RCV_COMMON_APIS', p_level => p_level);
12 END IF;
13 END print_debug;
14
15 PROCEDURE init_startup_values(p_organization_id IN NUMBER) IS
16 l_message VARCHAR2(240);
17 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
18 BEGIN
19 IF (l_debug = 1) THEN
20 print_debug('enter init_startup_values : 10', 1);
21 END IF;
22
23 -- query po_startup_value
24 init_form_values(
25 p_organization_id
26 , g_po_startup_value.inv_org_id --bug 5195963
27 , g_po_startup_value.org_name
28 , g_po_startup_value.org_location
29 , g_po_startup_value.sob_id
30 , g_po_startup_value.ussgl_value
31 , g_po_startup_value.period_name
32 , g_po_startup_value.gl_date
33 , g_po_startup_value.category_set_id
34 , g_po_startup_value.structure_id
35 , g_po_startup_value.user_id
36 , g_po_startup_value.logon_id
37 , g_po_startup_value.creation_date
38 , g_po_startup_value.update_date
39 , g_po_startup_value.inv_status
40 , g_po_startup_value.po_status
41 , g_po_startup_value.qa_status
42 , g_po_startup_value.wip_status
43 , g_po_startup_value.pa_status
44 , g_po_startup_value.oe_status
45 , g_po_startup_value.override_routing
46 , g_po_startup_value.transaction_mode
47 , g_po_startup_value.receipt_traveller
48 , g_po_startup_value.receipt_num_code
49 , g_po_startup_value.receipt_num_type
50 , g_po_startup_value.po_num_type
51 , g_po_startup_value.coa_id
52 , g_po_startup_value.allow_express
53 , g_po_startup_value.allow_cascade
54 , g_po_startup_value.org_locator_control
55 , g_po_startup_value.negative_inv_receipt_code
56 , g_po_startup_value.gl_set_of_bks_id
57 , g_po_startup_value.blind_receiving_flag
58 , g_po_startup_value.allow_unordered
59 , g_po_startup_value.display_inverse_rate
60 , g_po_startup_value.currency_code
61 , g_po_startup_value.project_reference_enabled
62 , g_po_startup_value.project_control_level
63 , g_po_startup_value.effectivity_control
64 , g_po_startup_value.employee_id
65 , g_po_startup_value.wms_install_status
66 , g_po_startup_value.wms_purchased
67 , l_message
68 );
69
70 IF (l_debug = 1) THEN
71 print_debug('init_startup_values : 20', 4);
72 END IF;
73
74 IF g_rcv_global_var.transaction_header_id IS NULL THEN
75 SELECT mtl_material_transactions_s.NEXTVAL
76 INTO g_rcv_global_var.transaction_header_id
77 FROM DUAL;
78 END IF;
79
80 gen_txn_group_id;
81
82 IF (l_debug = 1) THEN
83 print_debug('exit init_startup_values : 30', 1);
84 END IF;
85 END init_startup_values;
86
87 -- Bug 4087032 Need to write a wrapper on LENGTH function as
88 -- it creates compiltaion issues in 8i env.
89 FUNCTION get_serial_length(p_from_ser IN VARCHAR2)
90 return NUMBER is
91 BEGIN
92 return length(p_from_ser);
93 END get_serial_length;
94
95 -- for testing only ?? need INV standard api for this
96 FUNCTION get_to_serial_number(p_from_ser VARCHAR2, p_primary_quantity NUMBER)
97 RETURN VARCHAR2 IS
98 l_to_ser VARCHAR2(30);
99 l_number NUMBER;
100 l_temp_prefix VARCHAR2(30);
101 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
102 BEGIN
103 inv_validate.number_from_sequence(p_from_ser, l_temp_prefix, l_number);
104 l_number := l_number + p_primary_quantity - 1;
105 l_to_ser := SUBSTR(p_from_ser, 1, LENGTH(p_from_ser) - LENGTH(l_number)) || l_number;
106 RETURN l_to_ser;
107 END get_to_serial_number;
108
109 PROCEDURE insert_mtlt(p_mtlt_rec mtl_transaction_lots_temp%ROWTYPE) IS
110 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
111 BEGIN
112 INSERT INTO mtl_transaction_lots_temp
113 (
114 transaction_temp_id
115 , last_update_date
116 , last_updated_by
117 , creation_date
118 , created_by
119 , last_update_login
120 , request_id
121 , program_application_id
122 , program_id
123 , program_update_date
124 , transaction_quantity
125 , primary_quantity
126 , lot_number
127 , lot_expiration_date
128 , ERROR_CODE
129 , serial_transaction_temp_id
130 , group_header_id
131 , put_away_rule_id
132 , pick_rule_id
133 , description
134 , vendor_id
135 , supplier_lot_number
136 , territory_code
137 , --country_of_origin,
138 origination_date
139 , date_code
140 , grade_code
141 , change_date
142 , maturity_date
143 , status_id
144 , retest_date
145 , age
146 , item_size
147 , color
148 , volume
149 , volume_uom
150 , place_of_origin
151 , --kill_date,
152 best_by_date
153 , LENGTH
154 , length_uom
155 , recycled_content
156 , thickness
157 , thickness_uom
158 , width
159 , width_uom
160 , curl_wrinkle_fold
161 , lot_attribute_category
162 , c_attribute1
163 , c_attribute2
164 , c_attribute3
165 , c_attribute4
166 , c_attribute5
167 , c_attribute6
168 , c_attribute7
169 , c_attribute8
170 , c_attribute9
171 , c_attribute10
172 , c_attribute11
173 , c_attribute12
174 , c_attribute13
175 , c_attribute14
176 , c_attribute15
177 , c_attribute16
178 , c_attribute17
179 , c_attribute18
180 , c_attribute19
181 , c_attribute20
182 , d_attribute1
183 , d_attribute2
184 , d_attribute3
185 , d_attribute4
186 , d_attribute5
187 , d_attribute6
188 , d_attribute7
189 , d_attribute8
190 , d_attribute9
191 , d_attribute10
192 , n_attribute1
193 , n_attribute2
194 , n_attribute3
195 , n_attribute4
196 , n_attribute5
197 , n_attribute6
198 , n_attribute7
199 , n_attribute8
200 , n_attribute9
201 , n_attribute10
202 , vendor_name
203 , SECONDARY_QUANTITY --OPM Convergence
204 , SECONDARY_UNIT_OF_MEASURE --OPM Convergence
205 )
206 VALUES (
207 p_mtlt_rec.transaction_temp_id
208 , p_mtlt_rec.last_update_date
209 , p_mtlt_rec.last_updated_by
210 , p_mtlt_rec.creation_date
211 , p_mtlt_rec.created_by
212 , p_mtlt_rec.last_update_login
213 , p_mtlt_rec.request_id
214 , p_mtlt_rec.program_application_id
215 , p_mtlt_rec.program_id
216 , p_mtlt_rec.program_update_date
217 , p_mtlt_rec.transaction_quantity
218 , p_mtlt_rec.primary_quantity
219 , p_mtlt_rec.lot_number
220 , p_mtlt_rec.lot_expiration_date
221 , p_mtlt_rec.ERROR_CODE
222 , p_mtlt_rec.serial_transaction_temp_id
223 , p_mtlt_rec.group_header_id
224 , p_mtlt_rec.put_away_rule_id
225 , p_mtlt_rec.pick_rule_id
226 , p_mtlt_rec.description
227 , p_mtlt_rec.vendor_id
228 , p_mtlt_rec.supplier_lot_number
229 , p_mtlt_rec.territory_code
230 , --p_mtlt_rec.country_of_origin,
231 p_mtlt_rec.origination_date
232 , p_mtlt_rec.date_code
233 , p_mtlt_rec.grade_code
234 , p_mtlt_rec.change_date
235 , p_mtlt_rec.maturity_date
236 , p_mtlt_rec.status_id
237 , p_mtlt_rec.retest_date
238 , p_mtlt_rec.age
239 , p_mtlt_rec.item_size
240 , p_mtlt_rec.color
241 , p_mtlt_rec.volume
242 , p_mtlt_rec.volume_uom
243 , p_mtlt_rec.place_of_origin
244 , --p_mtlt_rec.kill_date,
245 p_mtlt_rec.best_by_date
246 , p_mtlt_rec.LENGTH
247 , p_mtlt_rec.length_uom
248 , p_mtlt_rec.recycled_content
249 , p_mtlt_rec.thickness
250 , p_mtlt_rec.thickness_uom
251 , p_mtlt_rec.width
252 , p_mtlt_rec.width_uom
253 , p_mtlt_rec.curl_wrinkle_fold
254 , p_mtlt_rec.lot_attribute_category
255 , p_mtlt_rec.c_attribute1
256 , p_mtlt_rec.c_attribute2
257 , p_mtlt_rec.c_attribute3
258 , p_mtlt_rec.c_attribute4
259 , p_mtlt_rec.c_attribute5
260 , p_mtlt_rec.c_attribute6
261 , p_mtlt_rec.c_attribute7
262 , p_mtlt_rec.c_attribute8
263 , p_mtlt_rec.c_attribute9
264 , p_mtlt_rec.c_attribute10
265 , p_mtlt_rec.c_attribute11
266 , p_mtlt_rec.c_attribute12
267 , p_mtlt_rec.c_attribute13
268 , p_mtlt_rec.c_attribute14
269 , p_mtlt_rec.c_attribute15
270 , p_mtlt_rec.c_attribute16
271 , p_mtlt_rec.c_attribute17
272 , p_mtlt_rec.c_attribute18
273 , p_mtlt_rec.c_attribute19
274 , p_mtlt_rec.c_attribute20
275 , p_mtlt_rec.d_attribute1
276 , p_mtlt_rec.d_attribute2
277 , p_mtlt_rec.d_attribute3
278 , p_mtlt_rec.d_attribute4
279 , p_mtlt_rec.d_attribute5
280 , p_mtlt_rec.d_attribute6
281 , p_mtlt_rec.d_attribute7
282 , p_mtlt_rec.d_attribute8
283 , p_mtlt_rec.d_attribute9
284 , p_mtlt_rec.d_attribute10
285 , p_mtlt_rec.n_attribute1
286 , p_mtlt_rec.n_attribute2
287 , p_mtlt_rec.n_attribute3
288 , p_mtlt_rec.n_attribute4
289 , p_mtlt_rec.n_attribute5
290 , p_mtlt_rec.n_attribute6
291 , p_mtlt_rec.n_attribute7
292 , p_mtlt_rec.n_attribute8
293 , p_mtlt_rec.n_attribute9
294 , p_mtlt_rec.n_attribute10
295 , p_mtlt_rec.vendor_name
296 , p_mtlt_rec.SECONDARY_QUANTITY --OPM Convergence
297 , p_mtlt_rec.SECONDARY_UNIT_OF_MEASURE --OPM Convergence
298 );
299 END insert_mtlt;
300
301 --bug# 2783559
302 -- Nested LPn changes.
303
304 PROCEDURE check_lot_serial_codes(
305 p_lpn_id IN NUMBER
306 , p_req_header_id IN NUMBER
307 , p_shipment_header_id IN NUMBER
308 , x_lot_ser_flag OUT NOCOPY VARCHAR2
309 , x_return_status OUT NOCOPY VARCHAR2
310 , x_msg_count OUT NOCOPY NUMBER
311 , x_msg_data OUT NOCOPY VARCHAR2
312 ) IS
313 -- Nested LPN changes changed the cursor to get all items within an LPN
314 -- along with its child LPNs.
315
316 -- Bug 3440456
317 -- The following cursor is changed for performance
318 --
319 /*
320 CURSOR get_all_items_in_lpn(p_lpn_id NUMBER) IS
321 SELECT wlc.inventory_item_id
322 FROM wms_lpn_contents wlc, wms_license_plate_numbers wln
323 WHERE wln.lpn_id = wlc.parent_lpn_id
324 AND lpn_id IN(SELECT lpn_id
325 FROM wms_license_plate_numbers
326 START WITH lpn_id = p_lpn_id
327 CONNECT BY parent_lpn_id = PRIOR lpn_id);
328 */
329
330 CURSOR get_all_items_in_lpn(p_lpn_id NUMBER) IS
331 SELECT wlc.inventory_item_id
332 FROM wms_lpn_contents wlc
333 WHERE wlc.parent_lpn_id
334 IN ( SELECT lpn_id
335 FROM wms_license_plate_numbers
336 START WITH lpn_id = p_lpn_id
337 CONNECT BY parent_lpn_id = PRIOR lpn_id);
338
339 l_item_id NUMBER;
340 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
341 l_msg_count NUMBER;
342 l_msg_data VARCHAR2(4000);
343 l_progress VARCHAR2(10);
344 l_lot_ser_flag VARCHAR(1) := 'Y';
345 l_debug NUMBER := 1;
346 BEGIN
347 l_lot_ser_flag := 'Y'; -- 'Y -match ' 'N- not match'
348 l_progress := 10;
349
350 IF (l_debug = 1) THEN
351 print_debug('lpn_id: ' || TO_CHAR(p_lpn_id), 1);
352 print_debug('shipment num : ' || p_shipment_header_id, 1);
353 print_debug(' req num: ' || p_req_header_id, 1);
354 END IF;
355
356 OPEN get_all_items_in_lpn(p_lpn_id);
357
358 LOOP
359 FETCH get_all_items_in_lpn INTO l_item_id;
360 EXIT WHEN get_all_items_in_lpn%NOTFOUND;
361
362 IF p_req_header_id IS NOT NULL THEN
363 SELECT 'N'
364 INTO l_lot_ser_flag
365 FROM po_requisition_headers prh, po_requisition_lines prl, rcv_shipment_lines rsl, mtl_system_items msi1, mtl_system_items msi2
366 WHERE prh.requisition_header_id = p_req_header_id
367 AND prl.requisition_header_id = prh.requisition_header_id
368 AND rsl.requisition_line_id = prl.requisition_line_id
369 AND rsl.item_id = msi1.inventory_item_id
370 AND rsl.item_id = l_item_id
371 AND msi1.organization_id = rsl.from_organization_id
372 AND(
373 (NVL(msi1.lot_control_code, 1) = 1
374 AND NVL(msi2.lot_control_code, 1) = 2)
375 OR(NVL(msi1.serial_number_control_code, 1) IN(1, 6)
376 AND NVL(msi2.serial_number_control_code, 1) IN(2, 5))
377 OR(NVL(msi1.revision_qty_control_code, 1) = 1
378 AND NVL(msi2.revision_qty_control_code, 1) = 2)
379 )
380 AND rsl.item_id = msi2.inventory_item_id
381 AND msi2.organization_id = rsl.to_organization_id
382 AND ROWNUM = 1;
383 ELSIF p_shipment_header_id IS NOT NULL THEN
384 SELECT 'N'
385 INTO l_lot_ser_flag
386 FROM rcv_shipment_lines rsl, rcv_shipment_headers rsh, mtl_system_items msi1, mtl_system_items msi2
387 WHERE rsh.shipment_header_id = p_shipment_header_id
388 AND rsl.shipment_header_id = rsh.shipment_header_id
389 AND rsl.item_id = msi1.inventory_item_id
390 AND msi1.organization_id = rsl.from_organization_id
391 AND rsl.item_id = l_item_id
392 AND(
393 (NVL(msi1.lot_control_code, 1) = 1
394 AND NVL(msi2.lot_control_code, 1) = 2)
395 OR(NVL(msi1.serial_number_control_code, 1) IN(1, 6)
396 AND NVL(msi2.serial_number_control_code, 1) IN(2, 5))
397 OR(NVL(msi1.revision_qty_control_code, 1) = 1
398 AND NVL(msi2.revision_qty_control_code, 1) = 2)
399 )
400 AND rsl.item_id = msi2.inventory_item_id
401 AND msi2.organization_id = rsl.to_organization_id
402 AND ROWNUM = 1;
403 END IF;
404
405 IF (l_lot_ser_flag = 'N') THEN
406 EXIT;
407 END IF;
408 END LOOP;
409
410 x_lot_ser_flag := l_lot_ser_flag;
411 EXCEPTION
412 WHEN NO_DATA_FOUND THEN -- item controls are valid
413 x_lot_ser_flag := 'Y';
414 WHEN OTHERS THEN
415 x_lot_ser_flag := 'N';
416 x_return_status := fnd_api.g_ret_sts_unexp_error;
417 print_debug(SQLCODE, 1);
418
419 IF get_all_items_in_lpn%ISOPEN THEN
420 CLOSE get_all_items_in_lpn;
421 END IF;
422
423 IF SQLCODE IS NOT NULL THEN
424 inv_mobile_helper_functions.sql_error('check_lot_serial_codes', l_progress, SQLCODE);
425 END IF;
426 END check_lot_serial_codes;
427
428 PROCEDURE insert_msnt(p_msnt_rec mtl_serial_numbers_temp%ROWTYPE) IS
429 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
430 BEGIN
431 INSERT INTO mtl_serial_numbers_temp
432 (
433 transaction_temp_id
434 , last_update_date
435 , last_updated_by
436 , creation_date
437 , created_by
438 , last_update_login
439 , request_id
440 , program_application_id
441 , program_id
442 , program_update_date
443 , vendor_serial_number
444 , vendor_lot_number
445 , fm_serial_number
446 , to_serial_number
447 , serial_prefix
448 , ERROR_CODE
449 , group_header_id
450 , parent_serial_number
451 , end_item_unit_number
452 , serial_attribute_category
453 , territory_code
454 , --country_of_origin,
455 origination_date
456 , c_attribute1
457 , c_attribute2
458 , c_attribute3
459 , c_attribute4
460 , c_attribute5
461 , c_attribute6
462 , c_attribute7
463 , c_attribute8
464 , c_attribute9
465 , c_attribute10
466 , c_attribute11
467 , c_attribute12
468 , c_attribute13
469 , c_attribute14
470 , c_attribute15
471 , c_attribute16
472 , c_attribute17
473 , c_attribute18
474 , c_attribute19
475 , c_attribute20
476 , d_attribute1
477 , d_attribute2
478 , d_attribute3
479 , d_attribute4
480 , d_attribute5
481 , d_attribute6
482 , d_attribute7
483 , d_attribute8
484 , d_attribute9
485 , d_attribute10
486 , n_attribute1
487 , n_attribute2
488 , n_attribute3
489 , n_attribute4
490 , n_attribute5
491 , n_attribute6
492 , n_attribute7
493 , n_attribute8
494 , n_attribute9
495 , n_attribute10
496 , status_id
497 , time_since_new
498 , cycles_since_new
499 , time_since_overhaul
500 , cycles_since_overhaul
501 , time_since_repair
502 , cycles_since_repair
503 , time_since_visit
504 , cycles_since_visit
505 , time_since_mark
506 , cycles_since_mark
507 , number_of_repairs
508 )
509 VALUES (
510 p_msnt_rec.transaction_temp_id
511 , p_msnt_rec.last_update_date
512 , p_msnt_rec.last_updated_by
513 , p_msnt_rec.creation_date
514 , p_msnt_rec.created_by
515 , p_msnt_rec.last_update_login
516 , p_msnt_rec.request_id
517 , p_msnt_rec.program_application_id
518 , p_msnt_rec.program_id
519 , p_msnt_rec.program_update_date
520 , p_msnt_rec.vendor_serial_number
521 , p_msnt_rec.vendor_lot_number
522 , p_msnt_rec.fm_serial_number
523 , p_msnt_rec.to_serial_number
524 , p_msnt_rec.serial_prefix
525 , p_msnt_rec.ERROR_CODE
526 , p_msnt_rec.group_header_id
527 , p_msnt_rec.parent_serial_number
528 , p_msnt_rec.end_item_unit_number
529 , p_msnt_rec.serial_attribute_category
530 , p_msnt_rec.territory_code
531 , --p_msnt_rec.country_of_origin,
532 p_msnt_rec.origination_date
533 , p_msnt_rec.c_attribute1
534 , p_msnt_rec.c_attribute2
535 , p_msnt_rec.c_attribute3
536 , p_msnt_rec.c_attribute4
537 , p_msnt_rec.c_attribute5
538 , p_msnt_rec.c_attribute6
539 , p_msnt_rec.c_attribute7
540 , p_msnt_rec.c_attribute8
541 , p_msnt_rec.c_attribute9
542 , p_msnt_rec.c_attribute10
543 , p_msnt_rec.c_attribute11
544 , p_msnt_rec.c_attribute12
545 , p_msnt_rec.c_attribute13
546 , p_msnt_rec.c_attribute14
547 , p_msnt_rec.c_attribute15
548 , p_msnt_rec.c_attribute16
549 , p_msnt_rec.c_attribute17
550 , p_msnt_rec.c_attribute18
551 , p_msnt_rec.c_attribute19
552 , p_msnt_rec.c_attribute20
553 , p_msnt_rec.d_attribute1
554 , p_msnt_rec.d_attribute2
555 , p_msnt_rec.d_attribute3
556 , p_msnt_rec.d_attribute4
557 , p_msnt_rec.d_attribute5
558 , p_msnt_rec.d_attribute6
559 , p_msnt_rec.d_attribute7
560 , p_msnt_rec.d_attribute8
561 , p_msnt_rec.d_attribute9
562 , p_msnt_rec.d_attribute10
563 , p_msnt_rec.n_attribute1
564 , p_msnt_rec.n_attribute2
565 , p_msnt_rec.n_attribute3
566 , p_msnt_rec.n_attribute4
567 , p_msnt_rec.n_attribute5
568 , p_msnt_rec.n_attribute6
569 , p_msnt_rec.n_attribute7
570 , p_msnt_rec.n_attribute8
571 , p_msnt_rec.n_attribute9
572 , p_msnt_rec.n_attribute10
573 , p_msnt_rec.status_id
574 , p_msnt_rec.time_since_new
575 , p_msnt_rec.cycles_since_new
576 , p_msnt_rec.time_since_overhaul
577 , p_msnt_rec.cycles_since_overhaul
578 , p_msnt_rec.time_since_repair
579 , p_msnt_rec.cycles_since_repair
580 , p_msnt_rec.time_since_visit
581 , p_msnt_rec.cycles_since_visit
582 , p_msnt_rec.time_since_mark
583 , p_msnt_rec.cycles_since_mark
584 , p_msnt_rec.number_of_repairs
585 );
586 END insert_msnt;
587
588 FUNCTION break_serials_only(p_original_tid IN mtl_serial_numbers_temp.transaction_temp_id%TYPE, p_new_transactions_tb IN trans_rec_tb_tp)
589 RETURN BOOLEAN IS
590 CURSOR c_serials IS
591 SELECT *
592 FROM mtl_serial_numbers_temp
593 WHERE transaction_temp_id = p_original_tid;
594
595 l_msnt_rec mtl_serial_numbers_temp%ROWTYPE;
596 l_new_transaction_temp_id mtl_serial_numbers_temp.transaction_temp_id%TYPE;
597 l_new_primary_quantity NUMBER; -- the quanity user wants to split
598 l_transaction_temp_id mtl_transaction_lots_temp.transaction_temp_id%TYPE;
599 l_from_ser mtl_serial_numbers_temp.fm_serial_number%TYPE;
600 l_to_ser mtl_serial_numbers_temp.to_serial_number%TYPE;
601 l_new_ser mtl_serial_numbers_temp.fm_serial_number%TYPE;
602 l_from_ser_num NUMBER; -- number part of from serial
603 l_to_ser_num NUMBER; -- number part of to serial
604 l_primary_quantity NUMBER; -- the quantity within this serial record
605 l_prefix_temp VARCHAR2(30);
606 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
607 BEGIN
608 FOR i IN 1 .. p_new_transactions_tb.COUNT LOOP -- Loop through all the transaction lines need to be splitted
609 l_new_transaction_temp_id := p_new_transactions_tb(i).transaction_id;
610 l_new_primary_quantity := p_new_transactions_tb(i).primary_quantity;
611 OPEN c_serials;
612
613 LOOP -- Loop through all the lot record for this transaction
614 FETCH c_serials INTO l_msnt_rec;
615 EXIT WHEN c_serials%NOTFOUND;
616 l_from_ser := l_msnt_rec.fm_serial_number;
617 l_to_ser := l_msnt_rec.to_serial_number;
618 -- get the actual number of from and to serial
619 inv_validate.number_from_sequence(l_from_ser, l_prefix_temp, l_from_ser_num);
620 inv_validate.number_from_sequence(l_to_ser, l_prefix_temp, l_to_ser_num);
621 l_primary_quantity := l_to_ser_num - l_from_ser_num + 1; -- initial qty for this ser record
622 l_transaction_temp_id := l_msnt_rec.transaction_temp_id; -- initial txn_int_id for this ser rec
623
624 IF (l_primary_quantity > l_new_primary_quantity) -- new quantity detailed completely
625 -- and there is remaining ser qty
626 THEN
627 l_msnt_rec.transaction_temp_id := l_new_transaction_temp_id;
628 -- need standard INV api to replace this func
629 l_msnt_rec.to_serial_number := get_to_serial_number(l_from_ser, l_new_primary_quantity);
630 insert_msnt(l_msnt_rec); -- insert one line with new to-ser-number and new txn_id
631 -- Update the existing ser rec with start serial number ??
632 l_new_ser := get_to_serial_number(l_from_ser, l_new_primary_quantity + 1);
633
634 UPDATE mtl_serial_numbers_temp
635 SET fm_serial_number = l_new_ser
636 WHERE transaction_temp_id = l_transaction_temp_id
637 AND fm_serial_number = l_from_ser
638 AND to_serial_number = l_to_ser;
639
640 EXIT; -- exit serial loop
641 ELSIF(l_primary_quantity < l_new_primary_quantity) THEN
642 -- new quantity is partially detailed
643 -- ser rec qty is exhausted
644 -- need to continue ser loop in this case
645
646 -- Update the ser rec with new transaction interface ID
647 UPDATE mtl_serial_numbers_temp
648 SET transaction_temp_id = l_new_transaction_temp_id
649 WHERE transaction_temp_id = l_transaction_temp_id
650 AND fm_serial_number = l_from_ser
651 AND to_serial_number = l_to_ser;
652
653 -- reduce the new qty
654 l_new_primary_quantity := l_new_primary_quantity - l_primary_quantity;
655 ELSIF(l_primary_quantity = l_new_primary_quantity) THEN
656 -- exact match
657
658 -- Update the lot rec with new transaction interface ID
659 UPDATE mtl_serial_numbers_temp
660 SET transaction_temp_id = l_new_transaction_temp_id
661 WHERE transaction_temp_id = l_transaction_temp_id
662 AND fm_serial_number = l_from_ser
663 AND to_serial_number = l_to_ser;
664
665 EXIT; -- exit serial loop
666 END IF;
667 END LOOP; -- end serial loop
668
669 CLOSE c_serials;
670 END LOOP; -- end transaction line loop
671
672 RETURN TRUE;
673 EXCEPTION
674 WHEN OTHERS THEN
675 IF c_serials%ISOPEN THEN
676 CLOSE c_serials;
677 END IF;
678
679 RAISE;
680 END break_serials_only;
681
682 FUNCTION break_lots_only(p_original_tid IN mtl_transaction_lots_temp.transaction_temp_id%TYPE,
683 p_new_transactions_tb IN trans_rec_tb_tp)
684 RETURN BOOLEAN IS
685 CURSOR c_lots IS
686 SELECT ROWID
687 , transaction_temp_id
688 , last_update_date
689 , last_updated_by
690 , creation_date
691 , created_by
692 , last_update_login
693 , request_id
694 , program_application_id
695 , program_id
696 , program_update_date
697 , transaction_quantity
698 , secondary_quantity --invconv kkillams
699 , primary_quantity
700 , lot_number
701 , lot_expiration_date
702 , ERROR_CODE
703 , serial_transaction_temp_id
704 , group_header_id
705 , put_away_rule_id
706 , pick_rule_id
707 , description
708 , vendor_id
709 , supplier_lot_number
710 , territory_code
711 , origination_date
712 , date_code
713 , grade_code
714 , change_date
715 , maturity_date
716 , status_id
717 , retest_date
718 , age
719 , item_size
720 , color
721 , volume
722 , volume_uom
723 , place_of_origin
724 , best_by_date
725 , LENGTH
726 , length_uom
727 , recycled_content
728 , thickness
729 , thickness_uom
730 , width
731 , width_uom
732 , curl_wrinkle_fold
733 , lot_attribute_category
734 , c_attribute1
735 , c_attribute2
736 , c_attribute3
737 , c_attribute4
738 , c_attribute5
739 , c_attribute6
740 , c_attribute7
741 , c_attribute8
742 , c_attribute9
743 , c_attribute10
744 , c_attribute11
745 , c_attribute12
746 , c_attribute13
747 , c_attribute14
748 , c_attribute15
749 , c_attribute16
750 , c_attribute17
751 , c_attribute18
752 , c_attribute19
753 , c_attribute20
754 , d_attribute1
755 , d_attribute2
756 , d_attribute3
757 , d_attribute4
758 , d_attribute5
759 , d_attribute6
760 , d_attribute7
761 , d_attribute8
762 , d_attribute9
763 , d_attribute10
764 , n_attribute1
765 , n_attribute2
766 , n_attribute3
767 , n_attribute4
768 , n_attribute5
769 , n_attribute6
770 , n_attribute7
771 , n_attribute8
772 , n_attribute9
773 , n_attribute10
774 , vendor_name
775 FROM mtl_transaction_lots_temp
776 WHERE transaction_temp_id = p_original_tid
777 ORDER BY DECODE(
778 inv_rcv_common_apis.g_order_lots_by
779 , inv_rcv_common_apis.g_order_lots_by_exp_date, lot_expiration_date
780 , inv_rcv_common_apis.g_order_lots_by_creation_date, creation_date
781 , lot_expiration_date
782 );
783
784 --Changed the order by for bug 2422193
785 --ORDER BY lot_expiration_date,creation_date;
786
787 l_mtlt_rec mtl_transaction_lots_temp%ROWTYPE;
788 l_new_transaction_temp_id mtl_transaction_lots_temp.transaction_temp_id%TYPE;
789 l_new_primary_quantity NUMBER; -- the quanity user wants to split
790 l_transaction_temp_id mtl_transaction_lots_temp.transaction_temp_id%TYPE;
791 l_primary_quantity NUMBER; -- the primary qty for lot
792 l_transaction_quantity NUMBER;
793 l_sec_transaction_quantity NUMBER; --invconv kkillams
794 l_new_secondary_quantity NUMBER; -- the quanity user wants to split
795 l_lot_number mtl_transaction_lots_temp.lot_number%TYPE;
796 --BUG 2673970
797 l_rowid ROWID;
798 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
799 BEGIN
800 FOR i IN 1 .. p_new_transactions_tb.COUNT LOOP -- Loop through all the transaction lines need to be splitted
801 l_new_transaction_temp_id := p_new_transactions_tb(i).transaction_id;
802 l_new_primary_quantity := p_new_transactions_tb(i).primary_quantity;
803 l_new_secondary_quantity := p_new_transactions_tb(i).secondary_quantity;
804
805 OPEN c_lots;
806 LOOP -- Loop through all the lot record for this transaction
807
808 --BUG 2673970
809 FETCH c_lots INTO l_rowid
810 , l_mtlt_rec.transaction_temp_id
811 , l_mtlt_rec.last_update_date
812 , l_mtlt_rec.last_updated_by
813 , l_mtlt_rec.creation_date
814 , l_mtlt_rec.created_by
815 , l_mtlt_rec.last_update_login
816 , l_mtlt_rec.request_id
817 , l_mtlt_rec.program_application_id
818 , l_mtlt_rec.program_id
819 , l_mtlt_rec.program_update_date
820 , l_mtlt_rec.transaction_quantity
821 , l_mtlt_rec.secondary_quantity --invconv kkillams
822 , l_mtlt_rec.primary_quantity
823 , l_mtlt_rec.lot_number
824 , l_mtlt_rec.lot_expiration_date
825 , l_mtlt_rec.ERROR_CODE
826 , l_mtlt_rec.serial_transaction_temp_id
827 , l_mtlt_rec.group_header_id
828 , l_mtlt_rec.put_away_rule_id
829 , l_mtlt_rec.pick_rule_id
830 , l_mtlt_rec.description
831 , l_mtlt_rec.vendor_id
832 , l_mtlt_rec.supplier_lot_number
833 , l_mtlt_rec.territory_code
834 , l_mtlt_rec.origination_date
835 , l_mtlt_rec.date_code
836 , l_mtlt_rec.grade_code
837 , l_mtlt_rec.change_date
838 , l_mtlt_rec.maturity_date
839 , l_mtlt_rec.status_id
840 , l_mtlt_rec.retest_date
841 , l_mtlt_rec.age
842 , l_mtlt_rec.item_size
843 , l_mtlt_rec.color
844 , l_mtlt_rec.volume
845 , l_mtlt_rec.volume_uom
846 , l_mtlt_rec.place_of_origin
847 , l_mtlt_rec.best_by_date
848 , l_mtlt_rec.LENGTH
849 , l_mtlt_rec.length_uom
850 , l_mtlt_rec.recycled_content
851 , l_mtlt_rec.thickness
852 , l_mtlt_rec.thickness_uom
853 , l_mtlt_rec.width
854 , l_mtlt_rec.width_uom
855 , l_mtlt_rec.curl_wrinkle_fold
856 , l_mtlt_rec.lot_attribute_category
857 , l_mtlt_rec.c_attribute1
858 , l_mtlt_rec.c_attribute2
859 , l_mtlt_rec.c_attribute3
860 , l_mtlt_rec.c_attribute4
861 , l_mtlt_rec.c_attribute5
862 , l_mtlt_rec.c_attribute6
863 , l_mtlt_rec.c_attribute7
864 , l_mtlt_rec.c_attribute8
865 , l_mtlt_rec.c_attribute9
866 , l_mtlt_rec.c_attribute10
867 , l_mtlt_rec.c_attribute11
868 , l_mtlt_rec.c_attribute12
869 , l_mtlt_rec.c_attribute13
870 , l_mtlt_rec.c_attribute14
871 , l_mtlt_rec.c_attribute15
872 , l_mtlt_rec.c_attribute16
873 , l_mtlt_rec.c_attribute17
874 , l_mtlt_rec.c_attribute18
875 , l_mtlt_rec.c_attribute19
876 , l_mtlt_rec.c_attribute20
877 , l_mtlt_rec.d_attribute1
878 , l_mtlt_rec.d_attribute2
879 , l_mtlt_rec.d_attribute3
880 , l_mtlt_rec.d_attribute4
881 , l_mtlt_rec.d_attribute5
882 , l_mtlt_rec.d_attribute6
883 , l_mtlt_rec.d_attribute7
884 , l_mtlt_rec.d_attribute8
885 , l_mtlt_rec.d_attribute9
886 , l_mtlt_rec.d_attribute10
887 , l_mtlt_rec.n_attribute1
888 , l_mtlt_rec.n_attribute2
889 , l_mtlt_rec.n_attribute3
890 , l_mtlt_rec.n_attribute4
891 , l_mtlt_rec.n_attribute5
892 , l_mtlt_rec.n_attribute6
893 , l_mtlt_rec.n_attribute7
894 , l_mtlt_rec.n_attribute8
895 , l_mtlt_rec.n_attribute9
896 , l_mtlt_rec.n_attribute10
897 , l_mtlt_rec.vendor_name;
898 EXIT WHEN c_lots%NOTFOUND;
899 l_primary_quantity := l_mtlt_rec.primary_quantity; -- initial qty for this lot
900 l_transaction_temp_id := l_mtlt_rec.transaction_temp_id; -- initial txn_int_id for this lot
901 l_lot_number := l_mtlt_rec.lot_number;
902 l_transaction_quantity := l_mtlt_rec.transaction_quantity;
903 l_sec_transaction_quantity := l_mtlt_rec.secondary_quantity; --invconv kkillams
904
905 IF (l_primary_quantity > l_new_primary_quantity) -- new quantity detailed completely
906 -- and there is remaining lot qty
907 THEN
908 l_mtlt_rec.transaction_temp_id := l_new_transaction_temp_id;
909 l_mtlt_rec.primary_quantity := l_new_primary_quantity;
910 l_mtlt_rec.transaction_quantity := l_transaction_quantity * l_new_primary_quantity / l_primary_quantity;
911 --invconv kkillams
912 IF ( NVL(l_sec_transaction_quantity,-9999) > 0 ) THEN --9527367
913 l_mtlt_rec.secondary_quantity := l_sec_transaction_quantity * l_new_secondary_quantity / l_sec_transaction_quantity;
914 END IF;
915 print_debug('insert_mtlt',1);
916 insert_mtlt(l_mtlt_rec); -- insert one line with new quantity and new txn_id
917 l_primary_quantity := l_primary_quantity - l_new_primary_quantity;
918 l_transaction_quantity := l_transaction_quantity - l_mtlt_rec.transaction_quantity;
919 --invconv kkillams
920 IF ( NVL(l_sec_transaction_quantity,-9999) > 0 ) THEN --9527367
921 l_sec_transaction_quantity := l_sec_transaction_quantity - l_mtlt_rec.secondary_quantity ;
922 END IF;
923
924 print_debug('Update 1 mtl_transaction_lots_temp',1);
925 -- Update the existing lot rec with reduced quantity
926 UPDATE mtl_transaction_lots_temp
927 SET primary_quantity = l_primary_quantity
928 , transaction_quantity = l_transaction_quantity
929 , secondary_quantity = l_sec_transaction_quantity
930 WHERE transaction_temp_id = l_transaction_temp_id
931 AND lot_number = l_lot_number
932 AND ROWID = l_rowid;
933
934 EXIT; -- exit lot loop
935 ELSIF(l_primary_quantity < l_new_primary_quantity) THEN
936 -- new quantity is partially detailed
937 -- lot qty is exhausted
938 -- need to continue lot loop in this case
939
940 -- Update the lot rec with new transaction interface ID
941 print_debug('Update 2 mtl_transaction_lots_temp',1);
942 UPDATE mtl_transaction_lots_temp
943 SET transaction_temp_id = l_new_transaction_temp_id
944 WHERE transaction_temp_id = l_transaction_temp_id
945 AND lot_number = l_lot_number
946 AND ROWID = l_rowid;
947
948 -- reduce the new qty
949 l_new_primary_quantity := l_new_primary_quantity - l_primary_quantity;
950 l_new_secondary_quantity := l_new_secondary_quantity - l_sec_transaction_quantity; --invconv kkillams
951 ELSIF(l_primary_quantity = l_new_primary_quantity) THEN
952 -- exact match
953
954 print_debug('Update 3 mtl_transaction_lots_temp',1);
955 -- Update the lot rec with new transaction interface ID
956 UPDATE mtl_transaction_lots_temp
957 SET transaction_temp_id = l_new_transaction_temp_id
958 WHERE transaction_temp_id = l_transaction_temp_id
959 AND lot_number = l_lot_number
960 AND ROWID = l_rowid;
961
962 EXIT; -- exit lot loop
963 END IF;
964 END LOOP; -- end lot loop
965
966 CLOSE c_lots;
967 END LOOP; -- end transaction line loop
968
969 RETURN TRUE;
970 EXCEPTION
971 WHEN OTHERS THEN
972 IF c_lots%ISOPEN THEN
973 CLOSE c_lots;
974 END IF;
975
976 RAISE;
977 END break_lots_only;
978
979 FUNCTION break_lots_serials(
980 p_original_tid IN mtl_transaction_lots_temp.transaction_temp_id%TYPE
981 , p_new_transactions_tb IN trans_rec_tb_tp
982 )
983 RETURN BOOLEAN IS
984 CURSOR c_lots IS
985 SELECT ROWID
986 , transaction_temp_id
987 , last_update_date
988 , last_updated_by
989 , creation_date
990 , created_by
991 , last_update_login
992 , request_id
993 , program_application_id
994 , program_id
995 , program_update_date
996 , transaction_quantity
997 , secondary_quantity --invconv kkillams
998 , primary_quantity
999 , lot_number
1000 , lot_expiration_date
1001 , ERROR_CODE
1002 , serial_transaction_temp_id
1003 , group_header_id
1004 , put_away_rule_id
1005 , pick_rule_id
1006 , description
1007 , vendor_id
1008 , supplier_lot_number
1009 , territory_code
1010 , origination_date
1011 , date_code
1012 , grade_code
1013 , change_date
1014 , maturity_date
1015 , status_id
1016 , retest_date
1017 , age
1018 , item_size
1019 , color
1020 , volume
1021 , volume_uom
1022 , place_of_origin
1023 , best_by_date
1024 , LENGTH
1025 , length_uom
1026 , recycled_content
1027 , thickness
1028 , thickness_uom
1029 , width
1030 , width_uom
1031 , curl_wrinkle_fold
1032 , lot_attribute_category
1033 , c_attribute1
1034 , c_attribute2
1035 , c_attribute3
1036 , c_attribute4
1037 , c_attribute5
1038 , c_attribute6
1039 , c_attribute7
1040 , c_attribute8
1041 , c_attribute9
1042 , c_attribute10
1043 , c_attribute11
1044 , c_attribute12
1045 , c_attribute13
1046 , c_attribute14
1047 , c_attribute15
1048 , c_attribute16
1049 , c_attribute17
1050 , c_attribute18
1051 , c_attribute19
1052 , c_attribute20
1053 , d_attribute1
1054 , d_attribute2
1055 , d_attribute3
1056 , d_attribute4
1057 , d_attribute5
1058 , d_attribute6
1059 , d_attribute7
1060 , d_attribute8
1061 , d_attribute9
1062 , d_attribute10
1063 , n_attribute1
1064 , n_attribute2
1065 , n_attribute3
1066 , n_attribute4
1067 , n_attribute5
1068 , n_attribute6
1069 , n_attribute7
1070 , n_attribute8
1071 , n_attribute9
1072 , n_attribute10
1073 , vendor_name
1074 FROM mtl_transaction_lots_temp
1075 WHERE transaction_temp_id = p_original_tid
1076 ORDER BY DECODE(
1077 inv_rcv_common_apis.g_order_lots_by
1078 , inv_rcv_common_apis.g_order_lots_by_exp_date, lot_expiration_date
1079 , inv_rcv_common_apis.g_order_lots_by_creation_date, creation_date
1080 , lot_expiration_date
1081 );
1082
1083 --Changed the order by for bug 2422193
1084 --ORDER BY lot_expiration_date,creation_date;
1085 l_mtlt_rec mtl_transaction_lots_temp%ROWTYPE;
1086 l_new_transaction_temp_id mtl_transaction_lots_temp.transaction_temp_id%TYPE;
1087 l_new_primary_quantity NUMBER; -- the quanity user wants to split
1088 l_transaction_temp_id mtl_transaction_lots_temp.transaction_temp_id%TYPE;
1089 l_primary_quantity NUMBER; -- the transaction qty for lot
1090 l_transaction_quantity NUMBER;
1091 l_lot_number mtl_transaction_lots_temp.lot_number%TYPE;
1092 l_serial_transaction_temp_id mtl_serial_numbers_temp.transaction_temp_id%TYPE;
1093 l_tran_rec_tb trans_rec_tb_tp;
1094 l_sec_transaction_quantity NUMBER; --invconv kkillams
1095 l_new_secondary_quantity NUMBER; -- the quanity user wants to split
1096 --BUG 2673970
1097 l_rowid ROWID;
1098 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1099
1100 BEGIN
1101 FOR i IN 1 .. p_new_transactions_tb.COUNT LOOP -- Loop through all the transaction lines need to be splitted
1102 l_new_transaction_temp_id := p_new_transactions_tb(i).transaction_id;
1103 l_new_primary_quantity := p_new_transactions_tb(i).primary_quantity;
1104 l_new_secondary_quantity := p_new_transactions_tb(i).secondary_quantity; --invconv
1105 OPEN c_lots;
1106
1107 LOOP -- Loop through all the lot record for this transaction
1108
1109 --BUG 2673970
1110 FETCH c_lots INTO l_rowid
1111 , l_mtlt_rec.transaction_temp_id
1112 , l_mtlt_rec.last_update_date
1113 , l_mtlt_rec.last_updated_by
1114 , l_mtlt_rec.creation_date
1115 , l_mtlt_rec.created_by
1116 , l_mtlt_rec.last_update_login
1117 , l_mtlt_rec.request_id
1118 , l_mtlt_rec.program_application_id
1119 , l_mtlt_rec.program_id
1120 , l_mtlt_rec.program_update_date
1121 , l_mtlt_rec.transaction_quantity
1122 , l_mtlt_rec.secondary_quantity --invconv kkillams
1123 , l_mtlt_rec.primary_quantity
1124 , l_mtlt_rec.lot_number
1125 , l_mtlt_rec.lot_expiration_date
1126 , l_mtlt_rec.ERROR_CODE
1127 , l_mtlt_rec.serial_transaction_temp_id
1128 , l_mtlt_rec.group_header_id
1129 , l_mtlt_rec.put_away_rule_id
1130 , l_mtlt_rec.pick_rule_id
1131 , l_mtlt_rec.description
1132 , l_mtlt_rec.vendor_id
1133 , l_mtlt_rec.supplier_lot_number
1134 , l_mtlt_rec.territory_code
1135 , l_mtlt_rec.origination_date
1136 , l_mtlt_rec.date_code
1137 , l_mtlt_rec.grade_code
1138 , l_mtlt_rec.change_date
1139 , l_mtlt_rec.maturity_date
1140 , l_mtlt_rec.status_id
1141 , l_mtlt_rec.retest_date
1142 , l_mtlt_rec.age
1143 , l_mtlt_rec.item_size
1144 , l_mtlt_rec.color
1145 , l_mtlt_rec.volume
1146 , l_mtlt_rec.volume_uom
1147 , l_mtlt_rec.place_of_origin
1148 , l_mtlt_rec.best_by_date
1149 , l_mtlt_rec.LENGTH
1150 , l_mtlt_rec.length_uom
1151 , l_mtlt_rec.recycled_content
1152 , l_mtlt_rec.thickness
1153 , l_mtlt_rec.thickness_uom
1154 , l_mtlt_rec.width
1155 , l_mtlt_rec.width_uom
1156 , l_mtlt_rec.curl_wrinkle_fold
1157 , l_mtlt_rec.lot_attribute_category
1158 , l_mtlt_rec.c_attribute1
1159 , l_mtlt_rec.c_attribute2
1160 , l_mtlt_rec.c_attribute3
1161 , l_mtlt_rec.c_attribute4
1162 , l_mtlt_rec.c_attribute5
1163 , l_mtlt_rec.c_attribute6
1164 , l_mtlt_rec.c_attribute7
1165 , l_mtlt_rec.c_attribute8
1166 , l_mtlt_rec.c_attribute9
1167 , l_mtlt_rec.c_attribute10
1168 , l_mtlt_rec.c_attribute11
1169 , l_mtlt_rec.c_attribute12
1170 , l_mtlt_rec.c_attribute13
1171 , l_mtlt_rec.c_attribute14
1172 , l_mtlt_rec.c_attribute15
1173 , l_mtlt_rec.c_attribute16
1174 , l_mtlt_rec.c_attribute17
1175 , l_mtlt_rec.c_attribute18
1176 , l_mtlt_rec.c_attribute19
1177 , l_mtlt_rec.c_attribute20
1178 , l_mtlt_rec.d_attribute1
1179 , l_mtlt_rec.d_attribute2
1180 , l_mtlt_rec.d_attribute3
1181 , l_mtlt_rec.d_attribute4
1182 , l_mtlt_rec.d_attribute5
1183 , l_mtlt_rec.d_attribute6
1184 , l_mtlt_rec.d_attribute7
1185 , l_mtlt_rec.d_attribute8
1186 , l_mtlt_rec.d_attribute9
1187 , l_mtlt_rec.d_attribute10
1188 , l_mtlt_rec.n_attribute1
1189 , l_mtlt_rec.n_attribute2
1190 , l_mtlt_rec.n_attribute3
1191 , l_mtlt_rec.n_attribute4
1192 , l_mtlt_rec.n_attribute5
1193 , l_mtlt_rec.n_attribute6
1194 , l_mtlt_rec.n_attribute7
1195 , l_mtlt_rec.n_attribute8
1196 , l_mtlt_rec.n_attribute9
1197 , l_mtlt_rec.n_attribute10
1198 , l_mtlt_rec.vendor_name;
1199 EXIT WHEN c_lots%NOTFOUND;
1200 l_primary_quantity := l_mtlt_rec.primary_quantity; -- initial qty for this lot
1201 l_transaction_temp_id := l_mtlt_rec.transaction_temp_id; -- initial txn_int_id for this lot
1202 l_serial_transaction_temp_id := l_mtlt_rec.serial_transaction_temp_id;
1203 l_lot_number := l_mtlt_rec.lot_number;
1204 l_sec_transaction_quantity := l_mtlt_rec.secondary_quantity; -- initial qty for this lot
1205
1206 IF (l_primary_quantity > l_new_primary_quantity) -- new quantity detailed completely
1207 -- and there is remaining lot qty
1208 THEN
1209 l_mtlt_rec.transaction_temp_id := l_new_transaction_temp_id;
1210 l_mtlt_rec.primary_quantity := l_new_primary_quantity;
1211 l_transaction_quantity := l_mtlt_rec.transaction_quantity;
1212 l_mtlt_rec.secondary_quantity := l_new_secondary_quantity;
1213
1214 SELECT mtl_material_transactions_s.NEXTVAL
1215 INTO l_mtlt_rec.serial_transaction_temp_id
1216 FROM DUAL;
1217
1218 l_mtlt_rec.transaction_quantity := l_transaction_quantity * l_new_primary_quantity / l_primary_quantity;
1219 insert_mtlt(l_mtlt_rec); -- insert one line with new quantity and new txn_id
1220 l_tran_rec_tb(1).transaction_id := l_mtlt_rec.serial_transaction_temp_id;
1221 l_tran_rec_tb(1).primary_quantity := l_new_primary_quantity;
1222 IF ( NVL(l_mtlt_rec.secondary_quantity,-99999) > 0 AND NVL(l_sec_transaction_quantity,-9999) > 0 ) THEN --9527367
1223 l_mtlt_rec.secondary_quantity := l_sec_transaction_quantity * l_new_secondary_quantity / l_sec_transaction_quantity;
1224 END IF;
1225
1226 IF break_serials_only(l_serial_transaction_temp_id, l_tran_rec_tb) THEN
1227 NULL;
1228 END IF;
1229
1230 l_primary_quantity := l_primary_quantity - l_new_primary_quantity;
1231 l_transaction_quantity := l_transaction_quantity - l_mtlt_rec.transaction_quantity;
1232 l_sec_transaction_quantity := l_sec_transaction_quantity - l_mtlt_rec.secondary_quantity;
1233
1234 -- Update the existing lot rec with reduced quantity
1235 UPDATE mtl_transaction_lots_temp
1236 SET primary_quantity = l_primary_quantity
1237 , transaction_quantity = l_transaction_quantity
1238 , secondary_quantity = l_sec_transaction_quantity
1239 WHERE transaction_temp_id = l_transaction_temp_id
1240 AND lot_number = l_lot_number
1241 AND ROWID = l_rowid;
1242
1243 EXIT; -- exit lot loop
1244 ELSIF(l_primary_quantity < l_new_primary_quantity) THEN
1245 -- new quantity is partially detailed
1246 -- lot qty is exhausted
1247 -- need to continue lot loop in this case
1248
1249 -- Update the lot rec with new transaction interface ID
1250 UPDATE mtl_transaction_lots_temp
1251 SET transaction_temp_id = l_new_transaction_temp_id
1252 WHERE transaction_temp_id = l_transaction_temp_id
1253 AND lot_number = l_lot_number
1254 AND ROWID = l_rowid;
1255
1256 -- reduce the new qty
1257 l_new_primary_quantity := l_new_primary_quantity - l_primary_quantity;
1258 l_new_secondary_quantity := l_new_secondary_quantity - l_sec_transaction_quantity;
1259 ELSIF(l_primary_quantity = l_new_primary_quantity) THEN
1260 -- exact match
1261
1262 -- Update the lot rec with new transaction interface ID
1263 UPDATE mtl_transaction_lots_temp
1264 SET transaction_temp_id = l_new_transaction_temp_id
1265 WHERE transaction_temp_id = l_transaction_temp_id
1266 AND lot_number = l_lot_number
1267 AND ROWID = l_rowid;
1268
1269 EXIT; -- exit lot loop
1270 END IF;
1271 END LOOP; -- end lot loop
1272
1273 CLOSE c_lots;
1274 END LOOP; -- end transaction line loop
1275
1276 RETURN TRUE;
1277 EXCEPTION
1278 WHEN OTHERS THEN
1279 IF c_lots%ISOPEN THEN
1280 CLOSE c_lots;
1281 END IF;
1282
1283 RAISE;
1284 END break_lots_serials;
1285
1286 PROCEDURE BREAK(
1287 p_original_tid IN mtl_transaction_lots_temp.transaction_temp_id%TYPE
1288 , p_new_transactions_tb IN trans_rec_tb_tp
1289 , p_lot_control_code IN NUMBER
1290 , p_serial_control_code IN NUMBER
1291 ) IS
1292 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1293 BEGIN
1294 print_debug('Entered BREAK',1);
1295 --lots and not serials -- ?? VERIFY THIS
1296 IF (p_lot_control_code = 2
1297 AND p_serial_control_code IN(1)) THEN
1298 print_debug('break_lots_only',1);
1299 IF break_lots_only(p_original_tid, p_new_transactions_tb) THEN
1300 NULL;
1301 END IF;
1302 --serials not lots
1303 -- Toshiba Fixes for RMA
1304 ELSIF(p_lot_control_code = 1
1305 AND p_serial_control_code NOT IN(1)) THEN
1306 print_debug('break_serials_only',1);
1307 IF break_serials_only(p_original_tid, p_new_transactions_tb) THEN
1308 NULL;
1309 END IF;
1310 --both lot and serial
1311 ELSIF(p_lot_control_code = 2
1312 AND p_serial_control_code NOT IN(1)) THEN
1313 print_debug('break_lots_serials',1);
1314 IF break_lots_serials(p_original_tid, p_new_transactions_tb) THEN
1315 NULL;
1316 END IF;
1317 END IF;
1318 END BREAK;
1319
1320 PROCEDURE gen_receipt_num(
1321 x_receipt_num OUT NOCOPY VARCHAR2
1322 , p_organization_id NUMBER
1323 , x_return_status OUT NOCOPY VARCHAR2
1324 , x_msg_count OUT NOCOPY NUMBER
1325 , x_msg_data OUT NOCOPY VARCHAR2
1326 ) IS
1327 PRAGMA AUTONOMOUS_TRANSACTION;
1328 l_receipt_exists NUMBER;
1329 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
1330 l_msg_count NUMBER;
1331 l_msg_data VARCHAR2(400);
1332 l_progress VARCHAR2(10);
1333 l_receipt_code VARCHAR2(25);
1334 l_temp_rcpt_num VARCHAR(30); --bug6014386
1335 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1336 BEGIN
1337 x_return_status := fnd_api.g_ret_sts_success;
1338 l_progress := '10';
1339
1340 IF (l_debug = 1) THEN
1341 print_debug('Enter gen_receipt_num 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1342 END IF;
1343
1344 /* Commented for bug 6014386
1345 UPDATE rcv_parameters
1346 SET next_receipt_num = next_receipt_num + 1
1347 WHERE organization_id = p_organization_id;
1348
1349 COMMIT;
1350 l_progress := '20';
1351
1352 SELECT TO_CHAR(next_receipt_num)
1353 INTO x_receipt_num
1354 FROM rcv_parameters
1355 WHERE organization_id = p_organization_id;
1356
1357 l_progress := '30';
1358
1359 BEGIN
1360 SELECT 1
1361 INTO l_receipt_exists
1362 FROM rcv_shipment_headers rsh
1363 WHERE receipt_num = x_receipt_num
1364 AND ship_to_org_id = p_organization_id;
1365 EXCEPTION
1366 WHEN NO_DATA_FOUND THEN
1367 l_receipt_exists := 0;
1368 WHEN OTHERS THEN
1369 RAISE; -- ? multi row selected
1370 END;
1371
1372 l_progress := '40';
1373
1374 IF (l_receipt_exists = 1) THEN
1375 -- need to handle receipt_num generation error ?
1376 po_message_s.app_error('RCV_RC_RESET_AUTO_NUMBER');
1377 END IF;
1378
1379 Bug 6014386 , commented upto here*/
1380
1381 /*Fix for bug6014386 Begin.
1382 If next receipt number is not unique, we need to loop through
1383 and find a unique number instead of erroring the transaction. */
1384
1385 SELECT to_char(next_receipt_num + 1)
1386 INTO l_temp_rcpt_num
1387 FROM rcv_parameters
1388 WHERE organization_id = p_organization_id
1389 FOR UPDATE OF next_receipt_num;
1390
1391 l_progress := '20';
1392
1393 LOOP
1394 SELECT COUNT(1)
1395 INTO l_receipt_exists
1396 FROM rcv_shipment_headers rsh
1397 WHERE rsh.receipt_num = l_temp_rcpt_num
1398 AND rsh.ship_to_org_id = p_organization_id ;
1399
1400 IF l_receipt_exists = 0 THEN
1401 UPDATE rcv_parameters
1402 SET next_receipt_num = l_temp_rcpt_num
1403 WHERE organization_id = p_organization_id ;
1404
1405 COMMIT; --commit the autonomous transaction
1406
1407 EXIT;
1408 ELSE
1409 l_temp_rcpt_num := TO_CHAR(TO_NUMBER(l_temp_rcpt_num) + 1); --increment the receipt number
1410 END IF;
1411 END LOOP;
1412
1413 x_receipt_num := l_temp_rcpt_num;
1414
1415 --Bug6014386.End
1416
1417 l_progress := '50';
1418
1419 IF (l_debug = 1) THEN
1420 print_debug('Exit gen_receipt_num 20 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1421 END IF;
1422 EXCEPTION
1423 WHEN OTHERS THEN
1424 x_return_status := fnd_api.g_ret_sts_unexp_error;
1425
1426 IF SQLCODE IS NOT NULL THEN
1427 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.gen_receipt_num', l_progress, SQLCODE);
1428 END IF;
1429
1430 fnd_message.set_name('PO', 'PO_SP_GET_NEXT_AUTO_RECEIPT_NM');
1431 fnd_msg_pub.ADD;
1432 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
1433 END gen_receipt_num;
1434
1435 PROCEDURE rcv_gen_receipt_num(
1436 x_receipt_num OUT NOCOPY VARCHAR2
1437 , p_organization_id NUMBER
1438 , x_return_status OUT NOCOPY VARCHAR2
1439 , x_msg_count OUT NOCOPY NUMBER
1440 , x_msg_data OUT NOCOPY VARCHAR2
1441 ) IS
1442 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1443 BEGIN
1444 x_return_status := fnd_api.g_ret_sts_success;
1445
1446 IF (l_debug = 1) THEN
1447 print_debug('Enter rcv_gen_receipt_num 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1448 END IF;
1449
1450 IF g_rcv_global_var.receipt_num IS NULL THEN
1451 IF (l_debug = 1) THEN
1452 print_debug('Receipt number is null', 4);
1453 END IF;
1454
1455 inv_rcv_common_apis.gen_receipt_num(
1456 x_receipt_num => g_rcv_global_var.receipt_num
1457 , p_organization_id => p_organization_id
1458 , x_return_status => x_return_status
1459 , x_msg_count => x_msg_count
1460 , x_msg_data => x_msg_data
1461 );
1462 END IF;
1463
1464 IF (l_debug = 1) THEN
1465 print_debug('Generated the receipt number:' || g_rcv_global_var.receipt_num, 4);
1466 END IF;
1467
1468 x_receipt_num := g_rcv_global_var.receipt_num;
1469 END rcv_gen_receipt_num;
1470
1471 PROCEDURE rcv_clear_global IS
1472 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
1473 l_msg_count NUMBER;
1474 l_msg_data VARCHAR2(400);
1475 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1476 BEGIN
1477 g_po_startup_value := NULL;
1478 g_rcv_global_var := NULL;
1479 g_lot_status_tb.DELETE;
1480 inv_rcv_std_rcpt_apis.g_shipment_header_id := NULL;
1481 inv_rcv_std_rcpt_apis.g_rcpt_match_table_gross.DELETE;
1482 inv_rcv_std_rcpt_apis.g_receipt_detail_index := 1;
1483 inv_rcv_std_rcpt_apis.g_dummy_lpn_id := NULL;
1484 inv_rcv_std_deliver_apis.g_rcvtxn_detail_index := 1;
1485 inv_rcv_std_deliver_apis.g_rcvtxn_match_table_gross.DELETE;
1486
1487 --Calling the procedure to clear the Global variable which conatains Lot Numbers (Bug # 3156689)
1488 clear_lot_rec;
1489
1490 -- clear the message stack.
1491 fnd_msg_pub.delete_msg;
1492 gen_txn_group_id;
1493
1494 -- set wms_purchased flag
1495 IF wms_install.check_install(l_return_status, l_msg_count, l_msg_data, NULL) THEN
1496 -- calling lpn_pack_complete to revert the weight/volume change
1497 IF (l_debug = 1) THEN
1498 print_debug('Calling wms_container_pub.lpn_pack_complete ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1499 print_debug('wms_container_pub.G_LPN_WT_VOL_CHANGES.count ' || wms_container_pub.g_lpn_wt_vol_changes.COUNT, 4);
1500 END IF;
1501
1502 IF wms_container_pub.lpn_pack_complete(1) THEN
1503 NULL;
1504 END IF;
1505 END IF;
1506
1507 -- Bug 2355294
1508 -- Clear the Label Printing Record Structure
1509 inv_label_pvt1.g_rcv_label_print_rec_tb.DELETE;
1510 COMMIT;
1511 END rcv_clear_global;
1512
1513 PROCEDURE init_form_values(
1514 p_org_id IN NUMBER
1515 , x_inv_org_id OUT NOCOPY NUMBER ----bug 5195963
1516 , x_org_name OUT NOCOPY VARCHAR2
1517 , x_org_location OUT NOCOPY VARCHAR2
1518 , x_sob_id OUT NOCOPY NUMBER
1519 , x_ussgl_value OUT NOCOPY VARCHAR2
1520 , x_period_name OUT NOCOPY VARCHAR2
1521 , x_gl_date OUT NOCOPY DATE
1522 , x_category_set_id OUT NOCOPY NUMBER
1523 , x_structure_id OUT NOCOPY NUMBER
1524 , x_user_id OUT NOCOPY NUMBER
1525 , x_logon_id OUT NOCOPY NUMBER
1526 , x_creation_date OUT NOCOPY DATE
1527 , x_update_date OUT NOCOPY DATE
1528 , x_inv_status OUT NOCOPY VARCHAR2
1529 , x_po_status OUT NOCOPY VARCHAR2
1530 , x_qa_status OUT NOCOPY VARCHAR2
1531 , x_wip_status OUT NOCOPY VARCHAR2
1532 , x_pa_status OUT NOCOPY VARCHAR2
1533 , x_oe_status OUT NOCOPY VARCHAR2
1534 , x_override_routing OUT NOCOPY VARCHAR2
1535 , x_transaction_mode OUT NOCOPY VARCHAR2
1536 , x_receipt_traveller OUT NOCOPY VARCHAR2
1537 , x_receipt_num_code OUT NOCOPY VARCHAR2
1538 , x_receipt_num_type OUT NOCOPY VARCHAR2
1539 , x_po_num_type OUT NOCOPY VARCHAR2
1540 , x_coa_id OUT NOCOPY NUMBER
1541 , x_allow_express OUT NOCOPY VARCHAR2
1542 , x_allow_cascade OUT NOCOPY VARCHAR2
1543 , x_org_locator_control OUT NOCOPY NUMBER
1544 , x_negative_inv_receipt_code OUT NOCOPY NUMBER
1545 , x_gl_set_of_bks_id OUT NOCOPY VARCHAR2
1546 , x_blind_receiving_flag OUT NOCOPY VARCHAR2
1547 , x_allow_unordered OUT NOCOPY VARCHAR2
1548 , x_display_inverse_rate OUT NOCOPY VARCHAR2
1549 , x_currency_code OUT NOCOPY VARCHAR2
1550 , x_project_reference_enabled OUT NOCOPY NUMBER
1551 , x_project_control_level OUT NOCOPY NUMBER
1552 , x_effectivity_control OUT NOCOPY NUMBER
1553 , x_employee_id OUT NOCOPY NUMBER
1554 , x_wms_install_status OUT NOCOPY VARCHAR2
1555 , x_wms_purchased OUT NOCOPY VARCHAR2
1556 , x_message OUT NOCOPY VARCHAR2
1557 ) IS
1558 l_org_id NUMBER := p_org_id;
1559 l_employee_name VARCHAR2(240);
1560 l_requestor_location_id NUMBER;
1561 l_location_code VARCHAR2(80);
1562 l_employee_is_buyer BOOLEAN;
1563 l_is_emp BOOLEAN;
1564 l_temp BOOLEAN;
1565 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
1566 l_msg_count NUMBER;
1567 l_msg_data VARCHAR2(400);
1568 l_progress VARCHAR2(10);
1569 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1570 BEGIN
1571 IF (l_debug = 1) THEN
1572 print_debug('enter init_form_values : 10', 1);
1573 END IF;
1574
1575 l_progress := '10';
1576
1577 /* Bug 3440456 */
1578 -- For performance reason this is being as replaced as below.
1579 /*
1580 SELECT ood.set_of_books_id
1581 , sob.currency_code
1582 INTO x_sob_id
1583 , x_currency_code
1584 FROM org_organization_definitions ood, gl_sets_of_books sob
1585 WHERE organization_id = p_org_id
1586 AND sob.set_of_books_id = ood.set_of_books_id;
1587 */
1588 x_inv_org_id := p_org_id; --bug 5195963
1589
1590 SELECT TO_NUMBER(hoi.org_information1)
1591 , sob.currency_code
1592 INTO x_sob_id
1593 , x_currency_code
1594 FROM hr_organization_information hoi, gl_sets_of_books sob
1595 WHERE hoi.organization_id = p_org_id
1596 AND (hoi.org_information_context || '') = 'Accounting Information'
1597 AND sob.set_of_books_id = to_number(hoi.org_information1);
1598
1599 l_progress := '20';
1600
1601 BEGIN
1602 SELECT location_code
1603 INTO x_org_location
1604 FROM hr_locations hrl, hr_organization_units hou
1605 WHERE hou.location_id = hrl.location_id
1606 AND hou.organization_id = p_org_id;
1607 EXCEPTION
1608 WHEN OTHERS THEN
1609 -- no_data_found, more than one row, etc.
1610 -- for any exception we just don't set org_location
1611 NULL;
1612 END;
1613
1614 l_progress := '30';
1615
1616 IF (l_debug = 1) THEN
1617 print_debug('init_form_values : 20', 4);
1618 END IF;
1619
1620 po_setup_s1.get_install_status(
1621 x_inv_status
1622 , x_po_status
1623 , x_qa_status
1624 , x_wip_status
1625 , x_oe_status
1626 , x_pa_status);
1627
1628 IF (l_debug = 1) THEN
1629 print_debug('init_form_values : 30', 4);
1630 END IF;
1631
1632 l_progress := '40';
1633 rcv_setup_s2.get_startup_values(
1634 x_sob_id
1635 , l_org_id
1636 , x_org_name
1637 , x_ussgl_value
1638 , x_override_routing
1639 , x_transaction_mode
1640 , x_receipt_traveller
1641 , x_period_name
1642 , x_gl_date
1643 , x_category_set_id
1644 , x_structure_id
1645 , x_receipt_num_code
1646 , x_receipt_num_type
1647 , x_po_num_type
1648 , x_allow_express
1649 , x_allow_cascade
1650 , x_user_id
1651 , x_logon_id
1652 , x_creation_date
1653 , x_update_date
1654 , x_coa_id
1655 , x_org_locator_control
1656 , x_negative_inv_receipt_code
1657 , x_gl_set_of_bks_id
1658 , x_blind_receiving_flag
1659 , x_allow_unordered
1660 );
1661
1662 IF (l_debug = 1) THEN
1663 print_debug('init_form_values : 40', 4);
1664 END IF;
1665
1666 l_progress := '50';
1667
1668 SELECT user_defined_receipt_num_code
1669 , manual_receipt_num_type
1670 INTO x_receipt_num_code
1671 , x_receipt_num_type
1672 FROM rcv_parameters
1673 WHERE organization_id = p_org_id;
1674
1675 l_progress := '60';
1676 fnd_profile.get('DISPLAY_INVERSE_RATE', x_display_inverse_rate);
1677
1678 IF x_display_inverse_rate IS NULL THEN
1679 x_display_inverse_rate := 'N';
1680 END IF;
1681
1682 l_progress := '70';
1683
1684 IF p_org_id IS NOT NULL THEN
1685 IF (l_debug = 1) THEN
1686 print_debug('init_form_values : 50', 4);
1687 END IF;
1688
1689 po_core_s4.get_mtl_parameters(
1690 p_org_id
1691 , NULL
1692 , x_project_reference_enabled
1693 , x_project_control_level);
1694 END IF;
1695
1696 l_progress := '80';
1697
1698 IF (pjm_unit_eff.enabled = 'Y') THEN
1699 x_effectivity_control := 1;
1700 ELSE
1701 x_effectivity_control := 2;
1702 END IF;
1703
1704 l_progress := '90';
1705
1706 IF (l_debug = 1) THEN
1707 print_debug('init_form_values : 60', 4);
1708 END IF;
1709
1710 l_temp := po_employees_sv.get_employee(
1711 x_employee_id
1712 , l_employee_name
1713 , l_requestor_location_id
1714 , l_location_code
1715 , l_employee_is_buyer
1716 , l_is_emp);
1717
1718 l_progress := '100';
1719
1720 -- set wms_installed flag
1721 IF wms_install.check_install(l_return_status, l_msg_count, l_msg_data, p_org_id) THEN
1722 x_wms_install_status := 'I';
1723 ELSE
1724 x_wms_install_status := 'U';
1725 END IF;
1726
1727 l_progress := '110';
1728
1729 -- set wms_purchased flag
1730 IF wms_install.check_install(l_return_status, l_msg_count, l_msg_data, NULL) THEN
1731 x_wms_purchased := 'I';
1732 ELSE
1733 x_wms_purchased := 'U';
1734 END IF;
1735
1736 l_progress := '120';
1737
1738 IF (l_debug = 1) THEN
1739 print_debug('init_form_values : 70 ', 4);
1740 print_debug('x_wms_install_status = ' || x_wms_install_status, 4);
1741 print_debug('x_wms_purchased = ' || x_wms_purchased, 4);
1742 END IF;
1743
1744 IF g_rcv_global_var.receipt_num IS NULL THEN
1745 IF (l_debug = 1) THEN
1746 print_debug('init_form_values : 75 ', 4);
1747 END IF;
1748
1749 inv_rcv_common_apis.rcv_gen_receipt_num(
1750 x_receipt_num => g_rcv_global_var.receipt_num
1751 , p_organization_id => p_org_id
1752 , x_return_status => l_return_status
1753 , x_msg_count => l_msg_count
1754 , x_msg_data => l_msg_data
1755 );
1756 END IF;
1757
1758 IF (l_debug = 1) THEN
1759 print_debug('exit init_form_values : 80 ', 1);
1760 END IF;
1761 EXCEPTION
1762 WHEN OTHERS THEN
1763 IF (l_debug = 1) THEN
1764 print_debug('Exitting init_form_values - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1765 END IF;
1766
1767 --
1768 IF SQLCODE IS NOT NULL THEN
1769 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.init_form_values', l_progress, SQLCODE);
1770 END IF;
1771
1772 -- Get message count and data
1773 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => l_msg_data);
1774 RAISE;
1775 END init_form_values;
1776
1777 -- Added the overloaded method to return the value of inv patch level
1778 -- and the po patch level to the UI. The earlier method is stubbed out
1779 -- to call this method in order to avoid pre-reqs.
1780 PROCEDURE init_rcv_ui_startup_values(
1781 p_organization_id IN NUMBER
1782 , x_org_id OUT NOCOPY NUMBER
1783 , x_org_location OUT NOCOPY VARCHAR2
1784 , x_org_locator_control OUT NOCOPY NUMBER
1785 , x_manual_po_num_type OUT NOCOPY VARCHAR2
1786 , x_wms_install_status OUT NOCOPY VARCHAR2
1787 , x_wms_purchased OUT NOCOPY VARCHAR2
1788 , x_return_status OUT NOCOPY VARCHAR2
1789 , x_msg_data OUT NOCOPY VARCHAR2
1790 , x_inv_patch_level OUT NOCOPY NUMBER
1791 , x_po_patch_level OUT NOCOPY NUMBER
1792 , x_wms_patch_level OUT NOCOPY NUMBER
1793 ) IS
1794 l_msg_count NUMBER;
1795 l_progress VARCHAR2(5);
1796 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1797 BEGIN
1798 IF (l_debug = 1) THEN
1799 print_debug('Entering init_rcv_ui_startup_values:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1800 END IF;
1801
1802 x_return_status := fnd_api.g_ret_sts_success;
1803 x_org_id := p_organization_id;
1804 x_inv_patch_level := inv_rcv_common_apis.g_inv_patch_level;
1805 x_po_patch_level := inv_rcv_common_apis.g_po_patch_level;
1806 x_wms_patch_level := inv_rcv_common_apis.g_wms_patch_level;
1807 l_progress := '10';
1808
1809 /* Bug 3440456 */
1810 -- For performance reason this is being as replaced as below.
1811 /*
1812 SELECT ood.set_of_books_id
1813 , sob.currency_code
1814 INTO g_po_startup_value.sob_id
1815 , g_po_startup_value.currency_code
1816 FROM org_organization_definitions ood, gl_sets_of_books sob
1817 WHERE organization_id = p_organization_id
1818 AND sob.set_of_books_id = ood.set_of_books_id;
1819 */
1820
1821 SELECT TO_NUMBER(hoi.org_information1)
1822 , sob.currency_code
1823 INTO g_po_startup_value.sob_id
1824 , g_po_startup_value.currency_code
1825 FROM hr_organization_information hoi, gl_sets_of_books sob
1826 WHERE hoi.organization_id = p_organization_id
1827 AND (hoi.org_information_context || '') = 'Accounting Information'
1828 AND sob.set_of_books_id = to_number(hoi.org_information1);
1829
1830 l_progress := '20';
1831
1832 -- set default org location
1833 BEGIN
1834 SELECT location_code
1835 INTO x_org_location
1836 FROM hr_locations hrl, hr_organization_units hou
1837 WHERE hou.location_id = hrl.location_id
1838 AND hou.organization_id = p_organization_id;
1839
1840 l_progress := '40';
1841 EXCEPTION
1842 WHEN OTHERS THEN
1843 -- no_data_found, more than one row, etc.
1844 -- for any exception we just don't set org_location
1845 NULL;
1846 END;
1847
1848 -- set stock locator control code
1849 l_progress := '50';
1850
1851 SELECT NVL(stock_locator_control_code, 1)
1852 INTO x_org_locator_control
1853 FROM mtl_parameters
1854 WHERE organization_id = p_organization_id;
1855
1856 l_progress := '60';
1857
1858 -- set manual po number type
1859 BEGIN
1860 l_progress := '70';
1861
1862 SELECT NVL(manual_po_num_type, 'ALPHANUMERIC')
1863 INTO x_manual_po_num_type
1864 FROM po_system_parameters
1865 WHERE ROWNUM = 1;
1866
1867 l_progress := '80';
1868 EXCEPTION
1869 WHEN OTHERS THEN
1870 x_manual_po_num_type := 'ALPHANUMERIC';
1871 END;
1872
1873 -- set wms_installed flag
1874 l_progress := '90';
1875
1876 IF wms_install.check_install(x_return_status, l_msg_count, x_msg_data, p_organization_id) THEN
1877 x_wms_install_status := 'I';
1878 ELSE
1879 x_wms_install_status := 'U';
1880 END IF;
1881
1882 IF x_return_status = fnd_api.g_ret_sts_error THEN
1883 fnd_message.set_name('INV', 'WMS_INSTALL_CHK_ERROR'); -- error checking ems installation
1884 fnd_msg_pub.ADD;
1885 RAISE fnd_api.g_exc_error;
1886 END IF;
1887
1888 l_progress := '110';
1889
1890 -- set wms_purchased flag
1891 IF wms_install.check_install(x_return_status, l_msg_count, x_msg_data, NULL) THEN
1892 x_wms_purchased := 'I';
1893 ELSE
1894 x_wms_purchased := 'U';
1895 END IF;
1896
1897 IF x_return_status = fnd_api.g_ret_sts_error THEN
1898 fnd_message.set_name('INV', 'WMS_INSTALL_CHK_ERROR'); -- error checking ems installation
1899 fnd_msg_pub.ADD;
1900 RAISE fnd_api.g_exc_error;
1901 END IF;
1902
1903 l_progress := '120';
1904 -- generate the group id to be used for all the records till the
1905 -- user revisits the menu.
1906 gen_txn_group_id;
1907 l_progress := '130';
1908
1909 IF (l_debug = 1) THEN
1910 print_debug('Exitting init_rcv_ui_startup_values:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1911 END IF;
1912 EXCEPTION
1913 WHEN fnd_api.g_exc_error THEN
1914 x_return_status := fnd_api.g_ret_sts_error;
1915
1916 IF (l_debug = 1) THEN
1917 print_debug('Exitting init_rcv_ui_startup_values - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1918 END IF;
1919 WHEN fnd_api.g_exc_unexpected_error THEN
1920 x_return_status := fnd_api.g_ret_sts_unexp_error;
1921
1922 IF (l_debug = 1) THEN
1923 print_debug('Exitting init_rcv_ui_startup_values - unexpected error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1924 END IF;
1925 WHEN OTHERS THEN
1926 x_return_status := fnd_api.g_ret_sts_unexp_error;
1927
1928 IF (l_debug = 1) THEN
1929 print_debug('Exitting init_rcv_ui_startup_values - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1930 END IF;
1931
1932 --
1933 IF SQLCODE IS NOT NULL THEN
1934 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.init_rcv_ui_startup_values', l_progress, SQLCODE);
1935 END IF;
1936
1937 -- Get message count and data
1938 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_msg_data);
1939 END init_rcv_ui_startup_values;
1940
1941 PROCEDURE init_rcv_ui_startup_values(
1942 p_organization_id IN NUMBER
1943 , x_org_id OUT NOCOPY NUMBER
1944 , x_org_location OUT NOCOPY VARCHAR2
1945 , x_org_locator_control OUT NOCOPY NUMBER
1946 , x_manual_po_num_type OUT NOCOPY VARCHAR2
1947 , x_wms_install_status OUT NOCOPY VARCHAR2
1948 , x_wms_purchased OUT NOCOPY VARCHAR2
1949 , x_return_status OUT NOCOPY VARCHAR2
1950 , x_msg_data OUT NOCOPY VARCHAR2
1951 ) IS
1952 l_inv_patch_level NUMBER;
1953 l_po_patch_level NUMBER;
1954 l_wms_patch_level NUMBER;
1955 BEGIN
1956 init_rcv_ui_startup_values(
1957 p_organization_id => p_organization_id
1958 , x_org_id => x_org_id
1959 , x_org_location => x_org_location
1960 , x_org_locator_control => x_org_locator_control
1961 , x_manual_po_num_type => x_manual_po_num_type
1962 , x_wms_install_status => x_wms_install_status
1963 , x_wms_purchased => x_wms_purchased
1964 , x_return_status => x_return_status
1965 , x_msg_data => x_msg_data
1966 , x_inv_patch_level => l_inv_patch_level
1967 , x_po_patch_level => l_po_patch_level
1968 , x_wms_patch_level => l_wms_patch_level
1969 );
1970 END init_rcv_ui_startup_values;
1971
1972 /*************************************************
1973 * Name: get_po_routing_id
1974 * This API returns routing id for a given PO header ID
1975 * Routing ID is defined at PO line-location level (po_line_locations_all)
1976 * We use the following rule to set headers routing ID
1977 * If there is one line detail needs inspection the entire PO needs inspection
1978 * elsif there is one line detail needs direct receiving the entire PO direct
1979 * else (all line detail are standard) the entire PO is standard
1980 * rounting lookups: 1. standard 2. Inspect 3. Direct
1981 ******************************************************/
1982 PROCEDURE get_po_routing_id(
1983 x_po_routing_id OUT NOCOPY NUMBER
1984 , x_is_expense OUT NOCOPY VARCHAR2
1985 , p_po_header_id IN NUMBER
1986 , p_po_release_id IN NUMBER
1987 , p_po_line_id IN NUMBER
1988 , p_item_id IN NUMBER
1989 , p_item_desc IN VARCHAR2 DEFAULT NULL
1990 , p_organization_id IN NUMBER DEFAULT NULL -- Bug 8242448
1991 ) IS
1992 -- l_po_routing_id NUMBER := 3; It should not be initialized with value 3,
1993 -- otherwise, the searching will not go
1994 -- to item level/org level.
1995 l_po_routing_id NUMBER;
1996 l_po_ll_routing_id NUMBER;
1997 l_dest_context VARCHAR2(30);
1998 l_po_dest_context VARCHAR2(30);
1999 -- Bug 8242448, Code changes start
2000 l_wms_enabled VARCHAR2(1) := 'N';
2001 l_msg_count NUMBER;
2002 l_msg_data VARCHAR2(300);
2003 l_return_status VARCHAR2(300);
2004 -- Bug 8242448, Code changes end
2005
2006 /* Bug 3812507: Changing the select query in the cursors po_ll_routing_cur
2007 and pod_dest_context_cur to improve performance */
2008
2009 CURSOR po_ll_routing_cur IS
2010 -- SELECT Nvl(poll.receiving_routing_id, 1) Value 1 should not be selected
2011 -- in case of Nvl, otherwise the
2012 -- searching mechanism will not
2013 -- go to item/org level.
2014 SELECT poll.receiving_routing_id
2015 -- p_po_release_id is null and p_po_line_id is null
2016 FROM po_line_locations poll, po_lines pol
2017 WHERE pol.po_header_id = p_po_header_id
2018 AND poll.po_line_id = pol.po_line_id
2019 AND p_po_release_id is NULL
2020 AND p_po_line_id is null
2021 AND (pol.item_id = p_item_id OR (p_item_id IS NULL
2022 AND pol.item_id IS NULL AND pol.item_description = p_item_desc))
2023 AND NVL(poll.approved_flag, 'N') = 'Y'
2024 AND NVL(poll.cancel_flag, 'N') = 'N'
2025 AND NVL(poll.closed_code, 'OPEN')NOT IN ('CLOSED','CLOSED FOR RECEIVING','FINALLY CLOSED')
2026 /*Fix for bug #4755862*/
2027 AND poll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED')
2028 UNION ALL
2029 SELECT poll.receiving_routing_id
2030 -- p_po_release_id is null and p_po_line_id is not null
2031 FROM po_line_locations poll, po_lines pol
2032 WHERE poll.po_header_id = p_po_header_id
2033 AND poll.po_line_id = pol.po_line_id
2034 AND p_po_release_id is NULL
2035 AND (p_po_line_id is not null AND poll.po_line_id = p_po_line_id)
2036 AND (pol.ITEM_ID = p_item_id OR (p_item_id IS NULL
2037 AND pol.item_id IS NULL AND pol.item_description = p_item_desc ))
2038 AND NVL(poll.approved_flag, 'N') = 'Y'
2039 AND NVL(poll.cancel_flag, 'N') = 'N'
2040 AND NVL(poll.closed_code, 'OPEN') NOT IN ('CLOSED','CLOSED FOR RECEIVING','FINALLY CLOSED')
2041 /*Fix for bug #4755862*/
2042 AND poll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED')
2043 UNION ALL
2044 SELECT poll.receiving_routing_id
2045 -- p_po_release_id is not null
2046 FROM po_line_locations poll, po_lines pol
2047 WHERE poll.po_header_id = p_po_header_id
2048 AND poll.po_line_id = pol.po_line_id
2049 AND (p_po_release_id is NOT NULL AND poll.po_release_id = p_po_release_id)
2050 AND (p_po_line_id is null or poll.po_line_id = p_po_line_id)
2051 AND (pol.item_id = p_item_id OR (p_item_id IS NULL
2052 AND pol.item_id IS NULL AND pol.item_description = p_item_desc))
2053 AND NVL(poll.approved_flag, 'N') = 'Y'
2054 AND NVL(poll.cancel_flag, 'N') = 'N'
2055 AND NVL(poll.closed_code, 'OPEN') NOT IN ('CLOSED','CLOSED FOR RECEIVING','FINALLY CLOSED')
2056 /*Fix for bug #4755862*/
2057 AND poll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED');
2058 /*
2059 SELECT poll.receiving_routing_id
2060 FROM po_line_locations poll, po_lines pol
2061 WHERE poll.po_header_id = p_po_header_id
2062 AND NVL(poll.po_release_id, -1) = NVL(p_po_release_id, NVL(poll.po_release_id, -1))
2063 AND NVL(poll.po_line_id, -1) = NVL(p_po_line_id, NVL(poll.po_line_id, -1))
2064 --AND pol.item_id = p_item_id
2065 AND (pol.item_id = p_item_id
2066 OR (p_item_id IS NULL
2067 AND pol.item_id IS NULL
2068 AND pol.item_description = p_item_desc
2069 )
2070 )
2071 AND pol.po_line_id = poll.po_line_id
2072 AND NVL(poll.approved_flag, 'N') = 'Y'
2073 AND NVL(poll.cancel_flag, 'N') = 'N'
2074 AND NVL(poll.closed_code, 'OPEN') <> 'FINALLY CLOSED'
2075 AND poll.shipment_type IN ('STANDARD', 'BLANKET', 'SCHEDULED');
2076 */
2077
2078 CURSOR pod_dest_context_cur IS
2079 SELECT DISTINCT NVL(POD.DESTINATION_TYPE_CODE,POD.DESTINATION_CONTEXT)
2080 -- p_po_release_id is null and p_po_line_id is null
2081 FROM PO_DISTRIBUTIONS POD, PO_LINES POL, PO_LINE_LOCATIONS POLL
2082 WHERE POL.PO_HEADER_ID = p_po_header_id
2083 AND POLL.PO_LINE_ID = POL.PO_LINE_ID
2084 AND POLL.SHIP_TO_ORGANIZATION_ID = NVL(p_organization_id, POLL.SHIP_TO_ORGANIZATION_ID) -- Bug 8242448
2085 AND POD.LINE_LOCATION_ID = POLL.LINE_LOCATION_ID
2086 AND p_po_release_id is NULL
2087 AND p_po_line_id is NULL
2088 AND (POL.ITEM_ID = p_item_id OR (p_item_id IS NULL
2089 AND POL.ITEM_ID IS NULL AND POL.ITEM_DESCRIPTION = p_item_desc ))
2090 AND NVL(POLL.APPROVED_FLAG,'N') = 'Y'
2091 AND NVL(POLL.CANCEL_FLAG,'N') = 'N'
2092 /*Added for Bug#7281141- getting the distributions against only the open line locations
2093 AND NVL(POLL.CLOSED_CODE,'OPEN') <> 'FINALLY CLOSED' */
2094 AND NVL(POLL.CLOSED_CODE,'OPEN') NOT IN ('CLOSED','CLOSED FOR RECEIVING','FINALLY CLOSED')
2095 AND POLL.SHIPMENT_TYPE IN ( 'STANDARD','BLANKET','SCHEDULED' )
2096 UNION ALL
2097 SELECT DISTINCT NVL(POD.DESTINATION_TYPE_CODE,POD.DESTINATION_CONTEXT)
2098 -- p_po_release_id is null and p_po_line_id is not null
2099 FROM PO_DISTRIBUTIONS POD, PO_LINES POL, PO_LINE_LOCATIONS POLL
2100 WHERE POLL.PO_HEADER_ID = p_po_header_id
2101 AND POLL.PO_LINE_ID = POL.PO_LINE_ID
2102 AND POLL.SHIP_TO_ORGANIZATION_ID = NVL(p_organization_id, POLL.SHIP_TO_ORGANIZATION_ID) -- Bug 8242448
2103 AND POD.LINE_LOCATION_ID = POLL.LINE_LOCATION_ID
2104 AND p_po_release_id is NULL
2105 AND (p_po_line_id is NOT NULL AND POLL.PO_LINE_ID = p_po_line_id)
2106 AND (POL.ITEM_ID = p_item_id OR (p_item_id IS NULL
2107 AND POL.ITEM_ID IS NULL AND POL.ITEM_DESCRIPTION = p_item_desc ))
2108 AND NVL(POLL.APPROVED_FLAG,'N') = 'Y'
2109 AND NVL(POLL.CANCEL_FLAG,'N') = 'N'
2110 /*Added for Bug#7281141- getting the distributions against only the open line locations
2111 AND NVL(POLL.CLOSED_CODE,'OPEN') <> 'FINALLY CLOSED' */
2112 AND NVL(POLL.CLOSED_CODE,'OPEN') NOT IN ('CLOSED','CLOSED FOR RECEIVING','FINALLY CLOSED')
2113 AND POLL.SHIPMENT_TYPE IN ( 'STANDARD','BLANKET','SCHEDULED' )
2114 UNION ALL
2115 SELECT DISTINCT NVL(POD.DESTINATION_TYPE_CODE,POD.DESTINATION_CONTEXT)
2116 -- p_po_release_id is not NULL
2117 FROM PO_DISTRIBUTIONS POD, PO_LINES POL, PO_LINE_LOCATIONS POLL
2118 WHERE POLL.PO_HEADER_ID = p_po_header_id
2119 AND POLL.PO_LINE_ID = POL.PO_LINE_ID
2120 AND POLL.SHIP_TO_ORGANIZATION_ID = NVL(p_organization_id, POLL.SHIP_TO_ORGANIZATION_ID) -- Bug 8242448
2121 AND POD.LINE_LOCATION_ID = POLL.LINE_LOCATION_ID
2122 AND (p_po_release_id is NOT NULL AND POLL.PO_RELEASE_ID = p_po_release_id)
2123 AND (p_po_line_id is null or poll.po_line_id = p_po_line_id)
2124 AND (pol.item_id = p_item_id OR (p_item_id IS NULL
2125 AND pol.item_id IS NULL AND pol.item_description = p_item_desc))
2126 AND NVL(POLL.APPROVED_FLAG,'N') = 'Y'
2127 AND NVL(POLL.CANCEL_FLAG,'N') = 'N'
2128 AND NVL(POLL.CLOSED_CODE,'OPEN') <> 'FINALLY CLOSED'
2129 AND POLL.SHIPMENT_TYPE IN ( 'STANDARD','BLANKET','SCHEDULED' );
2130
2131 -- Bug 8242448 - Code changes start
2132
2133 -- As part of bug # 7281141, the cursor 'pod_dest_context_cur' is modified to fetch the
2134 -- distributions against po line locations whose closed_code not in status 'CLOSED','
2135 -- CLOSED FOR RECEIVING', 'FINALLY CLOSED', for a wms org. But for a non-wms org we
2136 -- need to fetch the destination type code during deliver transaction also, in order to
2137 -- prompt the user to enter the deliver to location instead of subinventory and locator
2138 -- in case of expense destination. Hence added the following cursor which will retrieve
2139 -- distributions against po line locations whose closed_code <> 'FINALLY CLOSED'.
2140
2141 CURSOR pod_dest_context_inv_cur IS
2142 SELECT DISTINCT NVL(POD.DESTINATION_TYPE_CODE,POD.DESTINATION_CONTEXT)
2143 FROM PO_DISTRIBUTIONS POD, PO_LINES POL, PO_LINE_LOCATIONS POLL
2144 WHERE POL.PO_HEADER_ID = p_po_header_id
2145 AND POLL.PO_LINE_ID = POL.PO_LINE_ID
2146 AND POLL.SHIP_TO_ORGANIZATION_ID = NVL(p_organization_id, POLL.SHIP_TO_ORGANIZATION_ID)
2147 AND POD.LINE_LOCATION_ID = POLL.LINE_LOCATION_ID
2148 AND p_po_release_id is NULL
2149 AND p_po_line_id is NULL
2150 AND (POL.ITEM_ID = p_item_id OR (p_item_id IS NULL
2151 AND POL.ITEM_ID IS NULL AND POL.ITEM_DESCRIPTION = p_item_desc ))
2152 AND NVL(POLL.APPROVED_FLAG,'N') = 'Y'
2153 AND NVL(POLL.CANCEL_FLAG,'N') = 'N'
2154 AND NVL(POLL.CLOSED_CODE,'OPEN') <> 'FINALLY CLOSED'
2155 AND POLL.SHIPMENT_TYPE IN ( 'STANDARD','BLANKET','SCHEDULED' )
2156 UNION ALL
2157 SELECT DISTINCT NVL(POD.DESTINATION_TYPE_CODE,POD.DESTINATION_CONTEXT)
2158 FROM PO_DISTRIBUTIONS POD, PO_LINES POL, PO_LINE_LOCATIONS POLL
2159 WHERE POLL.PO_HEADER_ID = p_po_header_id
2160 AND POLL.PO_LINE_ID = POL.PO_LINE_ID
2161 AND POLL.SHIP_TO_ORGANIZATION_ID = NVL(p_organization_id, POLL.SHIP_TO_ORGANIZATION_ID)
2162 AND POD.LINE_LOCATION_ID = POLL.LINE_LOCATION_ID
2163 AND p_po_release_id is NULL
2164 AND (p_po_line_id is NOT NULL AND POLL.PO_LINE_ID = p_po_line_id)
2165 AND (POL.ITEM_ID = p_item_id OR (p_item_id IS NULL
2166 AND POL.ITEM_ID IS NULL AND POL.ITEM_DESCRIPTION = p_item_desc ))
2167 AND NVL(POLL.APPROVED_FLAG,'N') = 'Y'
2168 AND NVL(POLL.CANCEL_FLAG,'N') = 'N'
2169 AND NVL(POLL.CLOSED_CODE,'OPEN') <> 'FINALLY CLOSED'
2170 AND POLL.SHIPMENT_TYPE IN ( 'STANDARD','BLANKET','SCHEDULED' )
2171 UNION ALL
2172 SELECT DISTINCT NVL(POD.DESTINATION_TYPE_CODE,POD.DESTINATION_CONTEXT)
2173 FROM PO_DISTRIBUTIONS POD, PO_LINES POL, PO_LINE_LOCATIONS POLL
2174 WHERE POLL.PO_HEADER_ID = p_po_header_id
2175 AND POLL.PO_LINE_ID = POL.PO_LINE_ID
2176 AND POLL.SHIP_TO_ORGANIZATION_ID = NVL(p_organization_id, POLL.SHIP_TO_ORGANIZATION_ID)
2177 AND POD.LINE_LOCATION_ID = POLL.LINE_LOCATION_ID
2178 AND (p_po_release_id is NOT NULL AND POLL.PO_RELEASE_ID = p_po_release_id)
2179 AND (p_po_line_id is null or poll.po_line_id = p_po_line_id)
2180 AND (pol.item_id = p_item_id OR (p_item_id IS NULL
2181 AND pol.item_id IS NULL AND pol.item_description = p_item_desc))
2182 AND NVL(POLL.APPROVED_FLAG,'N') = 'Y'
2183 AND NVL(POLL.CANCEL_FLAG,'N') = 'N'
2184 AND NVL(POLL.CLOSED_CODE,'OPEN') <> 'FINALLY CLOSED'
2185 AND POLL.SHIPMENT_TYPE IN ( 'STANDARD','BLANKET','SCHEDULED' );
2186
2187 -- Bug 8242448 - Code changes end
2188
2189 /*
2190 SELECT DISTINCT Nvl(pod.destination_type_code,pod.destination_context)
2191 FROM po_distributions pod, po_lines pol, po_line_locations poll
2192 WHERE pod.po_header_id = p_po_header_id
2193 AND NVL(poll.po_release_id, -1) = NVL(p_po_release_id, NVL(poll.po_release_id, -1))
2194 AND NVL(poll.po_line_id, -1) = NVL(p_po_line_id, NVL(poll.po_line_id, -1))
2195 --AND pol.item_id = p_item_id
2196 AND pod.line_location_id = poll.line_location_id
2197 AND (pol.item_id = p_item_id
2198 OR (p_item_id IS NULL
2199 AND pol.item_id IS NULL
2200 AND pol.item_description = p_item_desc
2201 )
2202 )
2203 AND pol.po_line_id = poll.po_line_id
2204 AND NVL(poll.approved_flag, 'N') = 'Y'
2205 AND NVL(poll.cancel_flag, 'N') = 'N'
2206 AND NVL(poll.closed_code, 'OPEN') <> 'FINALLY CLOSED'
2207 AND poll.shipment_type IN ('STANDARD', 'BLANKET', 'SCHEDULED');
2208 */
2209
2210 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2211 BEGIN
2212 OPEN po_ll_routing_cur;
2213
2214 IF (l_debug = 1) THEN
2215 print_debug('header_id ' || TO_CHAR(p_po_header_id), 4);
2216 print_debug('line_id ' || TO_CHAR(p_po_line_id), 4);
2217 print_debug('p_po_release_id ' || TO_CHAR(p_po_release_id), 4); -- Bug 8242448
2218 print_debug('p_organization_id ' || TO_CHAR(p_organization_id), 4); -- Bug 8242448
2219 print_debug('item_id ' || TO_CHAR(p_item_id), 4);
2220 print_debug('item_desc ' || p_item_desc, 4);
2221 END IF;
2222
2223 x_is_expense := 'N';
2224
2225 LOOP
2226 FETCH po_ll_routing_cur INTO l_po_ll_routing_id;
2227 EXIT WHEN po_ll_routing_cur%NOTFOUND;
2228
2229 IF (l_debug = 1) THEN
2230 print_debug('l_po_ll_routing_id ' || l_po_ll_routing_id, 4);
2231 END IF;
2232
2233 IF l_po_ll_routing_id = 2 THEN -- inspection
2234 l_po_routing_id := 2;
2235 EXIT; -- inspection overrides everything
2236 ELSIF l_po_ll_routing_id = 1 THEN -- standard
2237 l_po_routing_id := 1; -- standard overrides direct
2238 ELSIF(l_po_ll_routing_id = 3
2239 AND NVL(l_po_routing_id, 3) >= 3) THEN -- direct
2240 l_po_routing_id := 3; -- direct is default if not null
2241 END IF;
2242 END LOOP;
2243
2244 CLOSE po_ll_routing_cur;
2245
2246 IF (l_debug = 1) THEN
2247 print_debug('routing_id ' || TO_CHAR(l_po_routing_id), 4);
2248 END IF;
2249
2250 /*
2251 if l_po_ll_routing_id is not null then
2252 l_po_routing_id := l_po_ll_routing_id;
2253 end if;
2254 */
2255 x_po_routing_id := l_po_routing_id;
2256 l_dest_context := 'INITIAL';
2257
2258 -- Bug 8242448
2259 IF wms_install.check_install(l_return_status, l_msg_count, l_msg_data, p_organization_id) THEN
2260 l_wms_enabled := 'Y';
2261 END IF;
2262
2263 IF (l_debug = 1) THEN
2264 print_debug('l_wms_enabled == ' || l_wms_enabled, 4);
2265 END IF;
2266
2267 IF l_wms_enabled = 'N' THEN -- Bug 8242448
2268 OPEN pod_dest_context_inv_cur;
2269 ELSE
2270 OPEN pod_dest_context_cur;
2271 END IF;
2272
2273 LOOP
2274
2275 IF l_wms_enabled = 'N' THEN -- Bug 8242448
2276 FETCH pod_dest_context_inv_cur INTO l_po_dest_context;
2277 EXIT WHEN pod_dest_context_inv_cur%NOTFOUND;
2278 ELSE
2279 FETCH pod_dest_context_cur INTO l_po_dest_context;
2280 EXIT WHEN pod_dest_context_cur%NOTFOUND;
2281 END IF;
2282
2283 IF (l_debug = 1) THEN
2284 print_debug('pod dest context ' || l_po_dest_context, 4);
2285 END IF;
2286
2287 IF l_dest_context <> l_po_dest_context THEN -- inspection
2288 l_dest_context := l_po_dest_context;
2289 END IF;
2290
2291 IF l_dest_context = 'EXPENSE' THEN
2292 x_is_expense := 'Y';
2293 EXIT ; --Added for Bug#7281141
2294 END IF;
2295 END LOOP;
2296
2297 -- Bug 8242448, Closing the cursors
2298
2299 IF pod_dest_context_cur%ISOPEN THEN
2300 CLOSE pod_dest_context_cur;
2301 END IF;
2302
2303 IF pod_dest_context_inv_cur%ISOPEN THEN
2304 CLOSE pod_dest_context_inv_cur;
2305 END IF;
2306
2307 IF (l_debug = 1) THEN
2308 print_debug('x_is_expense == ' || x_is_expense, 4);
2309 END IF;
2310
2311 EXCEPTION
2312 WHEN OTHERS THEN
2313 IF po_ll_routing_cur%ISOPEN THEN
2314 CLOSE po_ll_routing_cur;
2315 END IF;
2316
2317 IF pod_dest_context_cur%ISOPEN THEN
2318 CLOSE pod_dest_context_cur; -- Bug 8242448
2319 END IF;
2320
2321 IF pod_dest_context_inv_cur%ISOPEN THEN -- Bug 8242448
2322 CLOSE pod_dest_context_inv_cur;
2323 END IF;
2324
2325 IF (l_debug = 1) THEN
2326 print_debug('Exception while getting the shipment routing', 4);
2327 END IF;
2328
2329 RAISE;
2330 END get_po_routing_id;
2331
2332 /*************************************************
2333 * Name: get_asn_routing_id
2334 * This API returns routing id for a given shipment_header_ID,
2335 * lpn_id, po_header_id combination.
2336 * PO_header_id, po_line_id and item_id are queried based on the combination,
2337 * and then passed to get_po_routing_id.
2338 * If any of the lines has a direct routing, this API will return direct.
2339 *******************************************************/
2340 PROCEDURE get_asn_routing_id(
2341 x_asn_routing_id OUT NOCOPY NUMBER
2342 , x_return_status OUT NOCOPY VARCHAR2
2343 , x_msg_count OUT NOCOPY NUMBER
2344 , x_msg_data OUT NOCOPY VARCHAR2
2345 , p_shipment_header_id IN NUMBER
2346 , p_lpn_id IN NUMBER
2347 , p_po_header_id IN NUMBER
2348 ) IS
2349 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
2350 l_msg_count NUMBER;
2351 l_msg_data VARCHAR2(400);
2352 l_progress VARCHAR2(10);
2353 l_po_header_id NUMBER;
2354 l_po_line_id NUMBER;
2355 l_po_release_id NUMBER;
2356 l_item_id NUMBER;
2357 l_asn_routing_id NUMBER := 3; -- direct
2358 l_is_expense VARCHAR2(1);
2359 l_temp_asn_routing_id NUMBER := 3; --Bug 5500463
2360 l_rsl_routing_id NUMBER; --14354069
2361
2362 CURSOR l_curs_asn_lpn_content IS
2363 SELECT NVL(p_po_header_id, rsl.po_header_id) po_header_id
2364 , rsl.po_line_id po_line_id
2365 , rsl.po_release_id po_release_id
2366 , rsl.item_id item_id
2367 , rsl.routing_header_id rsl_routing_id -- 14354069
2368 FROM rcv_shipment_lines rsl
2369 WHERE rsl.shipment_header_id = p_shipment_header_id
2370 AND rsl.po_header_id = NVL(p_po_header_id, rsl.po_header_id)
2371 AND(EXISTS(SELECT 1
2372 FROM wms_lpn_contents wlc
2373 WHERE wlc.source_line_id = rsl.po_line_id
2374 AND wlc.parent_lpn_id = p_lpn_id)
2375 OR p_lpn_id IS NULL);
2376
2377 -- bug 3213241
2378 CURSOR l_curs_asn_lpn_content_new IS
2379 SELECT NVL(p_po_header_id, rsl.po_header_id) po_header_id
2380 , rsl.po_line_id po_line_id
2381 , rsl.po_release_id po_release_id
2382 , rsl.item_id item_id
2383 , rsl.routing_header_id rsl_routing_id -- 14354069
2384 FROM rcv_shipment_lines rsl
2385 WHERE rsl.shipment_header_id = p_shipment_header_id
2386 AND rsl.po_header_id = NVL(p_po_header_id, rsl.po_header_id)
2387 AND (( ( rsl.asn_lpn_id IS NOT NULL
2388 AND rsl.asn_lpn_id in
2389 (SELECT wlpn.lpn_id
2390 FROM wms_license_plate_numbers wlpn
2391 start with lpn_id = p_lpn_id
2392 CONNECT BY parent_lpn_id = PRIOR lpn_id
2393 )
2394 )
2395 OR (rsl.asn_lpn_id IS NULL
2396 AND exists (SELECT 1
2397 FROM wms_lpn_contents wlc
2398 WHERE wlc.source_line_id = rsl.po_line_id
2399 AND wlc.parent_lpn_id = p_lpn_id)
2400 )
2401 )
2402 OR
2403 (p_lpn_id IS NULL)
2404 );
2405
2406 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2407 BEGIN
2408 IF (l_debug = 1) THEN
2409 print_debug('Enter get_asn_routing_id 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2410 print_debug('p_shipment_header_id => ' || p_shipment_header_id, 4);
2411 print_debug('p_lpn_id => ' || p_lpn_id, 4);
2412 print_debug('p_po_header_id => ' || p_po_header_id, 4);
2413 END IF;
2414
2415 x_return_status := fnd_api.g_ret_sts_success;
2416 l_progress := '10';
2417
2418 IF ((inv_rcv_common_apis.g_wms_patch_level >= inv_rcv_common_apis.g_patchset_j) or
2419 (inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j)) THEN
2420 IF (l_debug = 1) THEN
2421 print_debug('In GET ASN ROUTING ID for/after patchsetJ ', 4);
2422 END IF;
2423 OPEN l_curs_asn_lpn_content_new;
2424 ELSE
2425 IF (l_debug = 1) THEN
2426 print_debug('In GET ASN ROUTING ID before patchsetJ ', 4);
2427 END IF;
2428 OPEN l_curs_asn_lpn_content;
2429 END IF;
2430
2431 l_progress := '20';
2432
2433 LOOP
2434 IF ((inv_rcv_common_apis.g_wms_patch_level >= inv_rcv_common_apis.g_patchset_j) or
2435 (inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j)) THEN
2436 FETCH l_curs_asn_lpn_content_new INTO l_po_header_id, l_po_line_id, l_po_release_id, l_item_id , l_rsl_routing_id; -- 14354069
2437 EXIT WHEN l_curs_asn_lpn_content_new%NOTFOUND;
2438 ElSE
2439 FETCH l_curs_asn_lpn_content INTO l_po_header_id, l_po_line_id, l_po_release_id, l_item_id , l_rsl_routing_id; -- 14354069
2440 EXIT WHEN l_curs_asn_lpn_content%NOTFOUND;
2441 END IF;
2442
2443 l_progress := '30';
2444
2445 IF (l_debug = 1) THEN
2446 print_debug('l_rsl_routing_id =>' || l_rsl_routing_id, 4);
2447 print_debug('l_po_header_id => ' || l_po_header_id, 4);
2448 print_debug('l_po_release_id => ' || l_po_release_id, 4);
2449 print_debug('l_po_line_id => ' || l_po_line_id, 4);
2450 print_debug('l_item_id => ' || l_item_id, 4);
2451 END IF;
2452
2453 IF (l_rsl_routing_id is NULL) THEN --14354069
2454
2455 IF (l_debug = 1) THEN
2456 print_debug('Parameters passed to get_po_routing_id' , 4);
2457 print_debug('l_po_header_id => ' || l_po_header_id, 4);
2458 print_debug('l_po_release_id => ' || l_po_release_id, 4);
2459 print_debug('l_po_line_id => ' || l_po_line_id, 4);
2460 print_debug('l_item_id => ' || l_item_id, 4);
2461 END IF;
2462
2463 get_po_routing_id(
2464 x_po_routing_id => l_asn_routing_id
2465 , x_is_expense => l_is_expense
2466 , p_po_header_id => l_po_header_id
2467 , p_po_release_id => l_po_release_id
2468 , p_po_line_id => l_po_line_id
2469 , p_item_id => l_item_id
2470 );
2471
2472 IF (l_debug = 1) THEN
2473 print_debug('Result of get_po_routing_id : l_asn_routing_id = ' || l_asn_routing_id, 4);
2474 END IF;
2475
2476 ELSE
2477 l_asn_routing_id := l_rsl_routing_id;
2478 IF (l_debug = 1) THEN
2479 print_debug('Result of routing_id : l_asn_routing_id = ' || l_asn_routing_id, 4);
2480 END IF;
2481 END IF; -- 14354069 Changes end here
2482
2483 l_progress := '40';
2484
2485 /*Begin Bug 5500463
2486 IF l_asn_routing_id <> 3 THEN -- direct found
2487 EXIT;
2488 END IF; */
2489 IF l_asn_routing_id = 2 THEN
2490 EXIT;
2491 ELSIF l_asn_routing_id = 1 THEN
2492 NULL;
2493 ELSIF l_asn_routing_id = 3 THEN
2494 IF (l_temp_asn_routing_id < 3) THEN
2495 l_asn_routing_id := l_temp_asn_routing_id;
2496 END IF;
2497 END IF;
2498
2499 IF (l_asn_routing_id < 3) THEN
2500 l_temp_asn_routing_id := l_asn_routing_id;
2501 END IF;
2502 --End Bug 5500463
2503 END LOOP;
2504
2505 l_progress := '50';
2506 IF ((inv_rcv_common_apis.g_wms_patch_level >= inv_rcv_common_apis.g_patchset_j) or
2507 (inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j)) THEN
2508 CLOSE l_curs_asn_lpn_content_new;
2509 ELSE
2510 CLOSE l_curs_asn_lpn_content;
2511 END IF;
2512
2513 l_progress := '60';
2514 x_asn_routing_id := l_asn_routing_id;
2515
2516 IF (l_debug = 1) THEN
2517 print_debug('Complete get_asn_routing_id : ' || x_asn_routing_id || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2518 END IF;
2519 EXCEPTION
2520 WHEN OTHERS THEN
2521 x_return_status := fnd_api.g_ret_sts_unexp_error;
2522
2523 IF l_curs_asn_lpn_content%ISOPEN THEN
2524 CLOSE l_curs_asn_lpn_content;
2525 END IF;
2526
2527 IF l_curs_asn_lpn_content_new%ISOPEN THEN
2528 CLOSE l_curs_asn_lpn_content_new;
2529 END IF;
2530
2531 IF SQLCODE IS NOT NULL THEN
2532 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.get_asn_routing_id', l_progress, SQLCODE);
2533 END IF;
2534
2535 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
2536
2537 IF (l_debug = 1) THEN
2538 print_debug('get_asn_routing_id: Other exception ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2539 END IF;
2540 END get_asn_routing_id;
2541
2542 /*************************************************
2543 * Name: get_intshp_routing_id
2544 * This API returns routing id for a given shipment header ID
2545 * Routing ID is defined at shipment line level (rcv_shipment_lines)
2546 * We use the following rule to set headers routing ID
2547 * If there is one line detail needs inspection the entire shipment needs inspection
2548 * elsif there is one line detail needs direct receiving the entire shipmentneeds direct
2549 * else (all line detail are standard) the entire shipment is standard
2550 * rounting lookups: 1. standard 2. Inspect 3. Direct
2551 ******************************************************/
2552 PROCEDURE get_intshp_routing_id(
2553 x_intshp_routing_id OUT NOCOPY NUMBER
2554 , x_is_expense OUT NOCOPY VARCHAR2
2555 , p_shipment_header_id IN NUMBER
2556 , p_item_id IN NUMBER
2557 , p_item_desc IN VARCHAR2 DEFAULT NULL
2558 , p_organization_id IN NUMBER -- Bug 8242448
2559 ) IS
2560 l_intshp_routing_id NUMBER;
2561 l_intran_routing_id NUMBER;
2562 l_po_header_id NUMBER;
2563 l_is_expense VARCHAR2(3) := 'N';
2564 -- Bug 8242448
2565 l_po_line_id NUMBER;
2566 l_po_release_id NUMBER;
2567
2568 CURSOR intshp_rsl_routing_cur IS
2569 SELECT NVL(routing_header_id, 1)
2570 , po_header_id
2571 , po_line_id -- Bug 8242448
2572 , po_release_id -- Bug 8242448
2573 FROM rcv_shipment_lines
2574 WHERE shipment_header_id = p_shipment_header_id
2575 AND(
2576 (item_id IS NULL
2577 AND p_item_id IS NULL
2578 AND item_description = p_item_desc
2579 AND source_document_code = 'PO')
2580 OR (item_id = NVL(p_item_id, item_id))
2581 );
2582
2583 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2584 BEGIN
2585 OPEN intshp_rsl_routing_cur;
2586
2587 IF (l_debug = 1) THEN
2588 print_debug('shipment header_id ' || TO_CHAR(p_shipment_header_id), 4);
2589 print_debug('item_id ' || TO_CHAR(p_item_id), 4);
2590 END IF;
2591
2592 LOOP
2593 FETCH intshp_rsl_routing_cur INTO l_intshp_routing_id, l_po_header_id, l_po_line_id, l_po_release_id; -- Bug 8242448
2594 EXIT WHEN intshp_rsl_routing_cur%NOTFOUND;
2595
2596 IF (l_debug = 1) THEN
2597 print_debug('l_intshp_routing_id: ' || l_intshp_routing_id, 4);
2598 END IF;
2599
2600 IF l_intshp_routing_id = 2 THEN -- inspection
2601 l_intran_routing_id := 2;
2602 EXIT; -- inspection overrides everything
2603 ELSIF l_intshp_routing_id = 1 THEN -- standard
2604 l_intran_routing_id := 1; -- standard overrides direct
2605 ELSIF(l_intshp_routing_id = 3
2606 AND NVL(l_intran_routing_id, 3) >= 3) THEN -- direct
2607 l_intran_routing_id := 3; -- direct is default if not null
2608 END IF;
2609
2610 IF l_po_header_id IS NOT NULL THEN
2611 get_po_routing_id(
2612 l_intshp_routing_id
2613 , l_is_expense
2614 , l_po_header_id
2615 , l_po_release_id -- Bug 8242448
2616 , l_po_line_id -- Bug 8242448
2617 , p_item_id
2618 , p_item_desc
2619 , p_organization_id); -- Bug 8242448
2620 END IF;
2621 END LOOP;
2622
2623 CLOSE intshp_rsl_routing_cur;
2624
2625 IF (l_debug = 1) THEN
2626 print_debug('routing_id ' || TO_CHAR(l_intran_routing_id), 4);
2627 print_debug('is_expesne ' || l_is_expense, 4);
2628 END IF;
2629
2630 IF l_is_expense = 'N' THEN
2631 BEGIN
2632 SELECT 'Y'
2633 INTO l_is_expense
2634 FROM po_requisition_lines prl
2635 , rcv_shipment_lines rsl
2636 WHERE prl.requisition_line_id = rsl.requisition_line_id
2637 AND prl.destination_type_code = 'EXPENSE'
2638 AND rsl.shipment_header_id = p_shipment_header_id
2639 AND rsl.item_id = NVL(p_item_id, rsl.item_id)
2640 AND ROWNUM = 1;
2641 EXCEPTION
2642 WHEN OTHERS THEN
2643 l_is_expense := 'N';
2644 END;
2645 END IF;
2646
2647 IF (l_debug = 1) THEN
2648 print_debug('REQ:is_expesne ' || l_is_expense, 4);
2649 END IF;
2650
2651 x_intshp_routing_id := l_intran_routing_id;
2652 x_is_expense := l_is_expense;
2653 EXCEPTION
2654 WHEN OTHERS THEN
2655 IF intshp_rsl_routing_cur%ISOPEN THEN
2656 CLOSE intshp_rsl_routing_cur;
2657 END IF;
2658
2659 IF (l_debug = 1) THEN
2660 print_debug('Exception while getting the shipment routing', 4);
2661 END IF;
2662
2663 RAISE;
2664 END get_intshp_routing_id;
2665
2666 /*************************************************
2667 * Name: get_default_routing_id
2668 * This API returns the default routing id
2669 * It first uses the item level value
2670 * if that is null then it uses the vendor level value
2671 * even if that is null it uses the org level value which if null is = 1
2672 * We use the following rule to set headers routing ID
2673 * rounting lookups: 1. standard 2. Inspect 3. Direct
2674 ******************************************************/
2675 PROCEDURE get_default_routing_id(
2676 x_default_routing_id OUT NOCOPY NUMBER
2677 , p_item_id IN NUMBER
2678 , p_organization_id IN NUMBER
2679 , p_vendor_id IN NUMBER
2680 ) IS
2681 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2682 BEGIN
2683 /* select item level controls that are not specifid at the purchase
2684 ** order level
2685 */
2686 IF (NVL(p_item_id, 0) <> 0) THEN
2687 BEGIN
2688 IF (l_debug = 1) THEN
2689 print_debug('p_item_id ' || TO_CHAR(p_item_id) || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2690 print_debug('p_org_id ' || TO_CHAR(p_organization_id) || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2691 END IF;
2692
2693 SELECT NVL(x_default_routing_id, receiving_routing_id)
2694 INTO x_default_routing_id
2695 FROM mtl_system_items
2696 WHERE inventory_item_id = p_item_id
2697 AND organization_id = p_organization_id;
2698 EXCEPTION
2699 WHEN NO_DATA_FOUND THEN
2700 NULL;
2701 WHEN OTHERS THEN
2702 RAISE;
2703 END;
2704 END IF;
2705
2706 IF (l_debug = 1) THEN
2707 print_debug('routing id ' || TO_CHAR(x_default_routing_id) || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2708 END IF;
2709
2710 /*
2711 ** select vendor level controls not defined in the previous levels
2712 */
2713 IF (NVL(p_vendor_id, 0) <> 0) THEN
2714 BEGIN
2715 SELECT NVL(x_default_routing_id, receiving_routing_id)
2716 INTO x_default_routing_id
2717 FROM po_vendors
2718 WHERE vendor_id = p_vendor_id;
2719 EXCEPTION
2720 WHEN NO_DATA_FOUND THEN
2721 NULL;
2722 WHEN OTHERS THEN
2723 RAISE;
2724 END;
2725 END IF;
2726
2727 /*
2728 ** select organization level controls not defined in the previous levels
2729 */
2730 BEGIN
2731 SELECT NVL(x_default_routing_id, NVL(receiving_routing_id, 1))
2732 INTO x_default_routing_id
2733 FROM rcv_parameters
2734 WHERE organization_id = p_organization_id;
2735 EXCEPTION
2736 WHEN NO_DATA_FOUND THEN
2737 NULL;
2738 WHEN OTHERS THEN
2739 RAISE;
2740 END;
2741 END get_default_routing_id;
2742
2743 /*************************************************
2744 * Name: get_routing_id
2745 * This API returns routing id for a given PO header ID or shipment header
2746 * id or for the rma
2747 ******************************************************/
2748 PROCEDURE get_routing_id(
2749 x_routing_id OUT NOCOPY NUMBER
2750 , x_return_status OUT NOCOPY VARCHAR2
2751 , x_msg_count OUT NOCOPY NUMBER
2752 , x_msg_data OUT NOCOPY VARCHAR2
2753 , x_is_expense OUT NOCOPY VARCHAR2
2754 , p_po_header_id IN NUMBER
2755 , p_po_release_id IN NUMBER
2756 , p_po_line_id IN NUMBER
2757 , p_shipment_header_id IN NUMBER
2758 , p_oe_order_header_id IN NUMBER
2759 , p_item_id IN NUMBER
2760 , p_organization_id IN NUMBER
2761 , p_vendor_id IN NUMBER
2762 , p_lpn_id IN NUMBER DEFAULT NULL
2763 , p_item_desc IN VARCHAR2 DEFAULT NULL
2764 , p_from_lpn_id IN NUMBER DEFAULT NULL
2765 , p_project_id IN NUMBER DEFAULT NULL
2766 , p_task_id IN NUMBER DEFAULT NULL
2767 ) IS
2768 l_msg_count NUMBER;
2769 l_msg_data VARCHAR2(400);
2770 l_return_status VARCHAR2(1);
2771 l_progress VARCHAR2(10);
2772 l_lpn_context NUMBER := 5;
2773 l_sub VARCHAR2(10);
2774 l_locator_id NUMBER;
2775 l_restrict_locator_code NUMBER;
2776 l_restrict_sub_code NUMBER;
2777 l_dummy NUMBER;
2778 l_transaction_type NUMBER := 18; -- defaulted for PO receipt.
2779 l_is_expense VARCHAR2(1) := 'N';
2780 l_lpn_loaded NUMBER := 0;
2781 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2782 l_is_valid_item VARCHAR2(1) := 'Y';
2783 l_project_id NUMBER;
2784 l_task_id NUMBER;
2785 l_pjm_org NUMBER := 2;
2786 l_client_code VARCHAR(40); /* Bug 9158529: LSP Changes */
2787 BEGIN
2788 x_return_status := fnd_api.g_ret_sts_success;
2789 x_is_expense := 'N';
2790 l_progress := '10';
2791
2792 IF (l_debug = 1) THEN
2793 print_debug('Enter get_routing_id 10' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2794 END IF;
2795
2796 /** Project Task Commingle check **/
2797 IF ((inv_rcv_common_apis.g_wms_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
2798 (inv_rcv_common_apis.g_PO_patch_level >= inv_rcv_common_apis.g_patchset_j_po) AND
2799 p_lpn_id IS NOT NULL AND
2800 p_lpn_id <> 0 ) THEN
2801
2802 SELECT NVL(project_reference_enabled, 2)
2803 INTO l_pjm_org
2804 FROM mtl_parameters
2805 WHERE organization_id = p_organization_id;
2806
2807 --Do the commingling check only for a PJM org
2808 IF (l_pjm_org = 1) THEN
2809
2810 /* Get Project_id,task_id from move order line and also from rti*/
2811 BEGIN
2812 SELECT project_id,task_id
2813 INTO l_project_id,l_task_id
2814 FROM mtl_txn_request_lines
2815 WHERE lpn_id = p_lpn_id
2816 AND ROWNUM=1;
2817
2818 IF (l_debug=1) THEN
2819 print_debug('Found project and task from move order ', 3);
2820 print_debug('project_id: ' || l_project_id ,3);
2821 print_debug('task_id ' || l_task_id ,3);
2822 END IF;
2823 EXCEPTION
2824 WHEN no_data_found THEN
2825 --If no MOL found, then get project and task from RTI
2826 BEGIN
2827 SELECT project_id,task_id
2828 INTO l_project_id,l_task_id
2829 FROM rcv_transactions_interface
2830 WHERE transfer_lpn_id = p_lpn_id
2831 AND transaction_type = 'RECEIVE'
2832 AND transaction_status_code = 'PENDING'
2833 AND processing_status_code <> 'ERROR'
2834 AND ROWNUM=1;
2835
2836 IF (l_debug=1) THEN
2837 print_debug('Found project and task from RTI: ', 3 );
2838 print_debug('project_id: ' || l_project_id , 3);
2839 print_debug('task_id ' || l_task_id , 3);
2840 END IF;
2841 EXCEPTION
2842 WHEN no_data_found THEN
2843 l_project_id := p_project_id;
2844 l_task_id := p_task_id;
2845 END; --End check for RTI
2846 END; --End check for MOL
2847
2848 IF (NVL(p_project_id,-9999) <> NVL(l_project_id,-9999)) OR
2849 (NVL(p_task_id,-9999) <> NVL(l_task_id,-9999)) THEN
2850 x_return_status := fnd_api.g_ret_sts_error;
2851 x_msg_data := 'INV_PRJ_ERR';
2852 fnd_message.set_name('INV', 'INV_PRJ_ERR');
2853 fnd_msg_pub.ADD;
2854 END IF; --End if check for proj/task comm error
2855 END IF; --End IF the current org is PJM org
2856 END IF; --END if WMS and PO patch levels are >= J and lpn_id is not null
2857
2858 /** Project Task Commingle check Ends here **/
2859
2860 IF p_po_header_id IS NULL
2861 AND p_item_id IS NULL
2862 AND p_shipment_header_id IS NULL THEN
2863 IF (l_debug = 1) THEN
2864 print_debug('One time item can only be recd. on PO, PO not given.', 4);
2865 END IF;
2866
2867 x_return_status := fnd_api.g_ret_sts_unexp_error;
2868 RETURN;
2869 END IF;
2870
2871 IF p_po_header_id IS NOT NULL THEN
2872 l_progress := '20';
2873
2874 IF (l_debug = 1) THEN
2875 print_debug('get_routing_id 20' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2876 END IF;
2877
2878 IF p_item_id IS NULL THEN
2879 IF p_item_desc IS NULL THEN
2880 IF (l_debug = 1) THEN
2881 print_debug('Item desc. and item id both cannot be null', 4);
2882 END IF;
2883
2884 x_return_status := fnd_api.g_ret_sts_unexp_error;
2885 RETURN;
2886 END IF;
2887
2888 x_is_expense := 'Y';
2889 END IF;
2890
2891 get_po_routing_id(
2892 x_routing_id
2893 , l_is_expense
2894 , p_po_header_id
2895 , p_po_release_id
2896 , p_po_line_id
2897 , p_item_id
2898 , p_item_desc
2899 , p_organization_id); -- Bug 8242448
2900
2901 IF x_is_expense <> 'Y' THEN
2902 x_is_expense := l_is_expense;
2903 END IF;
2904
2905 l_progress := '30';
2906 ELSIF p_shipment_header_id IS NOT NULL THEN
2907 IF (l_debug = 1) THEN
2908 print_debug('get_routing_id 30' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2909 END IF;
2910
2911 l_transaction_type := 61;
2912 l_progress := '40';
2913 get_intshp_routing_id(x_routing_id, l_is_expense, p_shipment_header_id,
2914 p_item_id, p_item_desc, p_organization_id); -- Bug 8242448
2915
2916 IF x_is_expense <> 'Y' THEN
2917 x_is_expense := l_is_expense;
2918 END IF;
2919
2920 l_progress := '50';
2921 ELSIF p_oe_order_header_id IS NOT NULL THEN
2922 IF (l_debug = 1) THEN
2923 print_debug('get_routing_id 52' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2924 END IF;
2925
2926 l_transaction_type := 15;
2927 l_progress := '54';
2928
2929 BEGIN
2930 SELECT return_inspection_requirement
2931 INTO x_routing_id
2932 FROM mtl_system_items
2933 WHERE inventory_item_id = p_item_id
2934 AND organization_id = p_organization_id;
2935 EXCEPTION
2936 WHEN OTHERS THEN
2937 NULL;
2938 END;
2939
2940 -- 1 return_inspection_requirement implies inspection is reqd.
2941 -- so set the routing to inspection required else set it based
2942 -- on organization level profile.
2943 IF x_routing_id = 1 THEN
2944 x_routing_id := 2;
2945 ELSE
2946 x_routing_id := NULL;
2947 -- Bug 3569361
2948 -- Get the routing details from rcv parameters related po enhancement 3124881
2949 Begin
2950 IF (l_debug = 1) THEN
2951 print_debug('get_routing_id 52.1 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2952 END IF;
2953
2954 /* Bug 9158529: LSP Changes */
2955
2956 IF (NVL(FND_PROFILE.VALUE('WMS_DEPLOYMENT_MODE'), 1) = 3) THEN
2957
2958
2959 l_client_code := wms_deploy.get_client_code(p_item_id);
2960
2961
2962 If (l_client_code IS NOT NULL) THEN
2963
2964 select RMA_RECEIPT_ROUTING_ID
2965 into x_routing_id
2966 from mtl_client_parameters
2967 WHERE client_code = l_client_code;
2968
2969
2970 else
2971
2972 select rma_receipt_routing_id
2973 into x_routing_id
2974 from rcv_parameters
2975 where organization_id = p_organization_id;
2976
2977 End If;
2978
2979 Else
2980
2981
2982 select rma_receipt_routing_id
2983 into x_routing_id
2984 from rcv_parameters
2985 where organization_id = p_organization_id;
2986
2987 END IF;
2988
2989 /* End Bug 9158529 */
2990
2991 Exception
2992 When OTHERS then
2993 IF (l_debug = 1) THEN
2994 print_debug('get_routing_id - can not fetch routing id from rcv parameters ', 4);
2995 print_debug('get_routing_id 52.2 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2996 END IF;
2997 End;
2998 END IF;
2999
3000 l_progress := '56';
3001 END IF;
3002
3003 IF x_routing_id IS NULL THEN
3004 IF (l_debug = 1) THEN
3005 print_debug('get_routing_id 40' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3006 END IF;
3007
3008 l_progress := '60';
3009 get_default_routing_id(x_routing_id, p_item_id, p_organization_id, p_vendor_id);
3010 l_progress := '70';
3011 END IF;
3012
3013 IF (l_debug = 1) THEN
3014 print_debug('get_routing_id complete' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3015 END IF;
3016
3017 IF p_lpn_id IS NOT NULL THEN
3018 BEGIN
3019 SELECT NVL(lpn_context, 5)
3020 , NVL(subinventory_code, '@@@')
3021 , NVL(locator_id, -1)
3022 INTO l_lpn_context
3023 , l_sub
3024 , l_locator_id
3025 FROM wms_license_plate_numbers
3026 WHERE lpn_id = p_lpn_id;
3027 EXCEPTION
3028 WHEN OTHERS THEN
3029 l_lpn_context := 5;
3030 END;
3031
3032 IF (
3033 (x_routing_id = 3
3034 AND l_lpn_context NOT IN(1, 5, 6, 7) --Added 6 above for bug # 2169351. added 7 - rnrao
3035 )
3036 OR --Added 3 here for the bug#2129214
3037 (
3038 x_routing_id IN(1, 2)
3039 AND l_lpn_context NOT IN(3, 5, 6, 7)
3040 ) --Added 6 above for bug # 2169351 added 7 - rnrao
3041 ) THEN
3042 x_return_status := fnd_api.g_ret_sts_error;
3043 -- print_debug('invalid lpn context ',9);
3044 x_msg_data := 'INV_INVALID_LPN_CONTEXT';
3045 fnd_message.set_name('INV', 'INV_INVALID_LPN_CONTEXT');
3046 fnd_msg_pub.ADD;
3047 RETURN;
3048 END IF;
3049
3050 IF (l_debug = 1) THEN
3051 print_debug('get_routing_id complete 111:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3052 END IF;
3053
3054 --Do not allow receipt into a loaded LPN
3055 IF (l_lpn_context IN (1, 3)) THEN
3056 l_lpn_loaded := 0;
3057 BEGIN
3058 SELECT 1
3059 INTO l_lpn_loaded
3060 FROM DUAL
3061 WHERE EXISTS(
3062 SELECT 1
3063 FROM wms_dispatched_tasks wdt, mtl_txn_request_lines mtrl
3064 WHERE wdt.move_order_line_id = mtrl.line_id
3065 AND wdt.organization_id = p_organization_id
3066 AND wdt.status = 4
3067 AND mtrl.lpn_id IN
3068 (
3069 SELECT wlpn1.lpn_id
3070 FROM wms_license_plate_numbers wlpn1
3071 WHERE wlpn1.outermost_lpn_id =
3072 (
3073 SELECT outermost_lpn_id
3074 FROM wms_license_plate_numbers wlpn2
3075 WHERE wlpn2.lpn_id = p_lpn_id
3076 )
3077 )
3078 );
3079 EXCEPTION
3080 WHEN OTHERS THEN
3081 l_lpn_loaded := 0;
3082 END;
3083
3084 IF (l_lpn_loaded = 1) THEN
3085 x_return_status := fnd_api.g_ret_sts_error;
3086 print_debug('get_routing_id: LPN is a loaded LPN',9);
3087 x_msg_data := 'WMS_CONT_INVALID_LPN';
3088 fnd_message.set_name('WMS', 'WMS_LOADED_ERROR');
3089 fnd_msg_pub.ADD;
3090 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
3091 fnd_msg_pub.ADD;
3092 RETURN;
3093 END IF;
3094 END IF;
3095
3096 -- Do the lpn related validations if the lpn context is 1 that is in inventory.
3097 IF l_lpn_context = 1 THEN
3098 SELECT NVL(restrict_locators_code, 2)
3099 , NVL(restrict_subinventories_code, 2)
3100 INTO l_restrict_locator_code
3101 , l_restrict_sub_code
3102 FROM mtl_system_items
3103 WHERE inventory_item_id = p_item_id
3104 AND organization_id = p_organization_id;
3105
3106 IF l_sub <> '@@@' THEN
3107 IF l_restrict_sub_code = 1 THEN -- item restricted to predefined subs
3108 BEGIN
3109 SELECT 1
3110 INTO l_dummy
3111 FROM DUAL
3112 WHERE EXISTS(
3113 SELECT 1
3114 FROM mtl_item_sub_inventories mis
3115 WHERE mis.organization_id = p_organization_id
3116 AND mis.inventory_item_id = p_item_id
3117 AND mis.secondary_inventory = l_sub
3118 AND inv_material_status_grp.is_status_applicable('TRUE', NULL, l_transaction_type, NULL, NULL, p_organization_id
3119 , p_item_id, l_sub, NULL, NULL, NULL, 'Z') = 'Y');
3120 EXCEPTION
3121 WHEN OTHERS THEN
3122 x_return_status := fnd_api.g_ret_sts_error;
3123 x_msg_data := 'INV_INT_RESSUBEXP';
3124 fnd_message.set_name('INV', 'INV_INT_RESSUBEXP');
3125 fnd_msg_pub.ADD;
3126 fnd_message.set_name('WMS', 'WMS_TD_LPN_LOC_NOT_FOUND');
3127 fnd_msg_pub.ADD;
3128 RETURN;
3129 END;
3130 ELSE -- item not under subinventory restrictions.
3131 BEGIN
3132 SELECT 1
3133 INTO l_dummy
3134 FROM DUAL
3135 WHERE EXISTS(
3136 SELECT 1
3137 FROM mtl_secondary_inventories msi
3138 WHERE msi.organization_id = p_organization_id
3139 AND NVL(msi.disable_date, TRUNC(SYSDATE + 1)) > TRUNC(SYSDATE)
3140 AND msi.secondary_inventory_name = l_sub
3141 AND inv_material_status_grp.is_status_applicable('TRUE', NULL, l_transaction_type, NULL, NULL, p_organization_id
3142 , p_item_id, l_sub, NULL, NULL, NULL, 'Z') = 'Y');
3143 EXCEPTION
3144 WHEN OTHERS THEN
3145 x_return_status := fnd_api.g_ret_sts_error;
3146 x_msg_data := 'INV_SUB_RESTRICT';
3147 fnd_message.set_name('INV', 'INV_SUB_RESTRICT');
3148 fnd_msg_pub.ADD;
3149 fnd_message.set_name('INV', 'INV_INVALID_SUBINV');
3150 fnd_msg_pub.ADD;
3151 fnd_message.set_name('WMS', 'WMS_TD_LPN_LOC_NOT_FOUND');
3152 fnd_msg_pub.ADD;
3153 RETURN;
3154 END;
3155 END IF; -- subinventory restrictions
3156
3157 IF l_locator_id <> -1 THEN
3158 IF l_restrict_locator_code = 1 THEN
3159 -- item under restricted locator control
3160 BEGIN
3161 SELECT 1
3162 INTO l_dummy
3163 FROM DUAL
3164 WHERE EXISTS(
3165 SELECT 1
3166 FROM mtl_secondary_locators msl
3167 WHERE msl.organization_id = p_organization_id
3168 AND msl.inventory_item_id = p_item_id
3169 AND msl.subinventory_code = l_sub
3170 AND msl.secondary_locator = l_locator_id
3171 AND inv_material_status_grp.is_status_applicable(
3172 'TRUE'
3173 , NULL
3174 , l_transaction_type
3175 , NULL
3176 , NULL
3177 , p_organization_id
3178 , p_item_id
3179 , l_sub
3180 , l_locator_id
3181 , NULL
3182 , NULL
3183 , 'L'
3184 ) = 'Y');
3185 EXCEPTION
3186 WHEN OTHERS THEN
3187 x_return_status := fnd_api.g_ret_sts_error;
3188 x_msg_data := 'INV_CCEOI_LOC_NOT_IN_LIST';
3189 fnd_message.set_name('INV', 'INV_CCEOI_LOC_NOT_IN_LIST');
3190 fnd_msg_pub.ADD;
3191 fnd_message.set_name('WMS', 'WMS_TD_LPN_LOC_NOT_FOUND');
3192 fnd_msg_pub.ADD;
3193 RETURN;
3194 END;
3195 ELSE -- item not under restricted locator control
3196 BEGIN
3197 SELECT 1
3198 INTO l_dummy
3199 FROM DUAL
3200 WHERE EXISTS(
3201 SELECT 1
3202 FROM mtl_item_locations mil
3203 WHERE mil.organization_id = p_organization_id
3204 AND mil.subinventory_code = l_sub
3205 AND NVL(mil.disable_date, TRUNC(SYSDATE + 1)) > TRUNC(SYSDATE)
3206 AND mil.inventory_location_id = l_locator_id
3207 AND inv_material_status_grp.is_status_applicable(
3208 'TRUE'
3209 , NULL
3210 , l_transaction_type
3211 , NULL
3212 , NULL
3213 , p_organization_id
3214 , p_item_id
3215 , l_sub
3216 , l_locator_id
3217 , NULL
3218 , NULL
3219 , 'L'
3220 ) = 'Y');
3221 EXCEPTION
3222 WHEN OTHERS THEN
3223 x_return_status := fnd_api.g_ret_sts_error;
3224 x_msg_data := 'INV_TRX_LOCATOR_NA_DUE_MS';
3225 fnd_message.set_name('INV', 'INV_TRX_LOCATOR_NA_DUE_MS');
3226 fnd_message.set_token('TOKEN1', '');
3227 fnd_msg_pub.ADD;
3228 fnd_message.set_name('WMS', 'WMS_TD_LPN_LOC_NOT_FOUND');
3229 fnd_msg_pub.ADD;
3230 RETURN;
3231 END;
3232 END IF; -- locator restrictions
3233 END IF; -- l_locator_id <> -1
3234 END IF; -- l_sub <> '@@@'
3235 END IF; -- l_lpn_context = 1
3236
3237 -- Nested LPN changes do not update LPN status after patchset J
3238 IF inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po
3239 OR inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j
3240 OR inv_rcv_common_apis.g_wms_patch_level < inv_rcv_common_apis.g_patchset_j THEN
3241 IF (l_lpn_context = 5) THEN
3242 -- Bug 2357196
3243 -- For an expense item do not set the lpn context to 1 or 3
3244 IF NVL(x_is_expense, 'N') <> 'Y' THEN
3245 UPDATE wms_license_plate_numbers
3246 SET lpn_context = DECODE(x_routing_id, 3, 1, 3)
3247 WHERE lpn_id = p_lpn_id;
3248 END IF;
3249 END IF;
3250 END IF;
3251 END IF; -- p_lpn_id <> null
3252 -- print_debug('get_routing_id complete 444:' || to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'),1 );
3253 EXCEPTION
3254 WHEN OTHERS THEN
3255 x_return_status := fnd_api.g_ret_sts_unexp_error;
3256
3257 IF (l_debug = 1) THEN
3258 print_debug('Exiting get_routing_id - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3259 END IF;
3260
3261 IF SQLCODE IS NOT NULL THEN
3262 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.get_routing_id', l_progress, SQLCODE);
3263 END IF;
3264
3265 -- Get message count and data
3266 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3267 END get_routing_id;
3268
3269 PROCEDURE create_lpn(
3270 p_organization_id NUMBER
3271 , p_lpn IN VARCHAR2
3272 , p_lpn_id OUT NOCOPY NUMBER
3273 , x_return_status OUT NOCOPY VARCHAR2
3274 , x_msg_data OUT NOCOPY VARCHAR2
3275 ) IS
3276 l_lpn_rec wms_container_pub.lpn;
3277 l_return_status VARCHAR2(1);
3278 l_msg_count NUMBER;
3279 l_msg_data VARCHAR2(400);
3280 l_progress VARCHAR2(10);
3281 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3282 BEGIN
3283 IF (l_debug = 1) THEN
3284 print_debug('create_lpn 10: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3285 print_debug('Parameters passed : 10.1 p_lpn = ' || p_lpn, 4);
3286 print_debug('Parameters passed : 10.2 p_organization_id = ' || p_organization_id, 4);
3287 END IF;
3288
3289 l_progress := '10';
3290 x_return_status := fnd_api.g_ret_sts_success;
3291 SAVEPOINT rcv_create_lpn_sp;
3292 l_lpn_rec.license_plate_number := p_lpn;
3293
3294 IF wms_container_pub.validate_lpn(l_lpn_rec) = inv_validate.f THEN
3295 l_progress := '20';
3296 wms_container_pub.create_lpn(
3297 p_api_version => 1.0
3298 , x_return_status => l_return_status
3299 , x_msg_count => l_msg_count
3300 , x_msg_data => l_msg_data
3301 , p_lpn => p_lpn
3302 , p_organization_id => p_organization_id
3303 , x_lpn_id => p_lpn_id
3304 , p_source => 5
3305 );
3306
3307 IF l_return_status = fnd_api.g_ret_sts_error THEN
3308 fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
3309 fnd_msg_pub.ADD;
3310
3311 IF (l_debug = 1) THEN
3312 print_debug('create_lpn 20.1: wms_container_pub.create_lpn RAISE FND_API.G_EXC_ERROR' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
3313 , 4);
3314 END IF;
3315
3316 RAISE fnd_api.g_exc_error;
3317 END IF;
3318
3319 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
3320 fnd_message.set_name('WMS', 'WMS_LPN_GENERATION_FAIL');
3321 fnd_msg_pub.ADD;
3322
3323 IF (l_debug = 1) THEN
3324 print_debug('create_lpn 20.2: wms_container_pub.create_lpn RAISE FND_API.G_EXC_UNEXPECTED_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3325 END IF;
3326
3327 RAISE fnd_api.g_exc_unexpected_error;
3328 END IF;
3329 ELSE -- lpn exists
3330 IF (l_debug = 1) THEN
3331 print_debug('create_lpn 30', 4);
3332 END IF;
3333
3334 l_progress := '30';
3335
3336 SELECT lpn_id
3337 INTO p_lpn_id
3338 FROM wms_license_plate_numbers
3339 WHERE license_plate_number = p_lpn;
3340
3341 l_progress := '40';
3342 END IF;
3343
3344 IF (l_debug = 1) THEN
3345 print_debug('create_lpn compete - x_lpn = ' || p_lpn_id || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3346 END IF;
3347 EXCEPTION
3348 WHEN fnd_api.g_exc_error THEN
3349 ROLLBACK TO rcv_create_lpn_sp;
3350 x_return_status := fnd_api.g_ret_sts_error;
3351 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_msg_data);
3352 WHEN fnd_api.g_exc_unexpected_error THEN
3353 ROLLBACK TO rcv_create_lpn_sp;
3354 x_return_status := fnd_api.g_ret_sts_unexp_error;
3355 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_msg_data);
3356 WHEN OTHERS THEN
3357 ROLLBACK TO rcv_create_lpn_sp;
3358 x_return_status := fnd_api.g_ret_sts_unexp_error;
3359
3360 IF SQLCODE IS NOT NULL THEN
3361 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.create_lpn', l_progress, SQLCODE);
3362 END IF;
3363
3364 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_msg_data);
3365 END create_lpn;
3366
3367 -- This api creates a record in the mtl_transaction_lots_temp
3368 -- It checks if the p_transaction_temp_id is null, if it is, then it
3369 -- generates a new id and returns that.
3370 PROCEDURE insert_lot(
3371 p_transaction_temp_id IN OUT NOCOPY NUMBER
3372 , p_created_by IN NUMBER
3373 , p_transaction_qty IN NUMBER
3374 , p_primary_qty IN NUMBER
3375 , p_lot_number IN VARCHAR2
3376 , p_expiration_date IN DATE
3377 , p_status_id IN NUMBER := NULL
3378 , x_serial_transaction_temp_id OUT NOCOPY NUMBER
3379 , x_return_status OUT NOCOPY VARCHAR2
3380 , x_msg_data OUT NOCOPY VARCHAR2
3381 , p_secondary_quantity IN NUMBER --OPM Convergence
3382
3383 ) IS
3384 l_return NUMBER;
3385 l_progress VARCHAR2(10);
3386 l_count NUMBER := 0;
3387 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3388 BEGIN
3389 x_return_status := fnd_api.g_ret_sts_success;
3390 l_progress := '10';
3391
3392 IF (l_debug = 1) THEN
3393 print_debug('Enter insert_lot: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3394 print_debug('p_transaction_temp_id:' || p_transaction_temp_id, 4);
3395 print_debug('p_transaction_qty:' || p_transaction_qty, 4);
3396 print_debug('p_primary_qty:' || p_primary_qty, 4);
3397 print_debug('p_lot_number:' || p_lot_number, 4);
3398 print_debug('p_expiration_date:' || p_expiration_date, 4);
3399 print_debug('p_status_id:' || p_status_id, 4);
3400 END IF;
3401
3402 /* For Bug#2266537. check if the lot being inserted is already there in MTLT
3403 with the same temp_id. If so then the quantity of the lot is updated
3404 instead of generating a new lot.*/
3405 IF p_transaction_temp_id IS NOT NULL THEN
3406 BEGIN
3407 SELECT 1
3408 , serial_transaction_temp_id
3409 INTO l_count
3410 , x_serial_transaction_temp_id
3411 FROM mtl_transaction_lots_temp
3412 WHERE transaction_temp_id = p_transaction_temp_id
3413 AND lot_number = p_lot_number
3414 AND ROWNUM = 1;
3415 EXCEPTION
3416 WHEN NO_DATA_FOUND THEN
3417 l_count := 0;
3418 WHEN OTHERS THEN
3419 l_count := 0;
3420
3421 IF (l_debug = 1) THEN
3422 print_debug('Exception trying to find lot existance', 4);
3423 END IF;
3424 END;
3425 ELSE
3426 l_count := 0;
3427 END IF;
3428
3429 IF l_count = 1 THEN
3430 IF (l_debug = 1) THEN
3431 print_debug('Updating mtlt existing rec', 4);
3432 END IF;
3433
3434 UPDATE mtl_transaction_lots_temp
3435 SET transaction_quantity = transaction_quantity + p_transaction_qty
3436 , primary_quantity = primary_quantity + p_primary_qty
3437 WHERE transaction_temp_id = p_transaction_temp_id
3438 AND lot_number = p_lot_number;
3439 ELSE
3440 IF p_transaction_temp_id IS NULL THEN
3441 SELECT mtl_material_transactions_s.NEXTVAL
3442 INTO p_transaction_temp_id
3443 FROM DUAL;
3444 END IF;
3445
3446 l_progress := '20';
3447 l_return :=
3448 inv_trx_util_pub.insert_lot_trx(
3449 p_trx_tmp_id => p_transaction_temp_id
3450 , p_user_id => p_created_by
3451 , p_lot_number => p_lot_number
3452 , p_trx_qty => p_transaction_qty
3453 , p_pri_qty => p_primary_qty
3454 , p_exp_date => p_expiration_date
3455 , p_status_id => p_status_id
3456 , x_ser_trx_id => x_serial_transaction_temp_id
3457 , x_proc_msg => x_msg_data
3458 , p_secondary_qty => p_secondary_quantity --OPM Convergence
3459 );
3460 l_progress := '30';
3461
3462 -- if the trx manager returned a 1 then it could not insert the row
3463 IF l_return = 1 THEN
3464 l_progress := '40';
3465 x_return_status := fnd_api.g_ret_sts_error;
3466 END IF;
3467
3468 l_progress := '50';
3469
3470 IF (l_debug = 1) THEN
3471 print_debug('Exitting insert_lot : 60 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3472 END IF;
3473 END IF;
3474 EXCEPTION
3475 WHEN OTHERS THEN
3476 x_return_status := fnd_api.g_ret_sts_unexp_error;
3477
3478 IF SQLCODE IS NOT NULL THEN
3479 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.insert_lot', l_progress, SQLCODE);
3480 END IF;
3481
3482 IF (l_debug = 1) THEN
3483 print_debug('Exitting insert_lot - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3484 END IF;
3485
3486 --
3487 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3488 fnd_msg_pub.add_exc_msg(g_pkg_name, 'insert_lot');
3489 END IF;
3490 END insert_lot;
3491
3492 -- This api creates a record in the mtl_transaction_serial_temp
3493 -- It checks if the p_transaction_temp_id is null, if it is, then it
3494 -- generates a new id and returns that.
3495 PROCEDURE insert_serial(
3496 p_serial_transaction_temp_id IN OUT NOCOPY NUMBER
3497 , p_org_id IN NUMBER
3498 , p_item_id IN NUMBER
3499 , p_rev IN VARCHAR2
3500 , p_lot IN VARCHAR2
3501 , p_txn_src_id IN NUMBER
3502 , p_txn_action_id IN NUMBER
3503 , p_created_by IN NUMBER
3504 , p_from_serial IN VARCHAR2
3505 , p_to_serial IN VARCHAR2
3506 , p_status_id IN NUMBER := NULL
3507 , x_return_status OUT NOCOPY VARCHAR2
3508 , x_msg_data OUT NOCOPY VARCHAR2
3509 ) IS
3510 l_return NUMBER;
3511 l_to_serial VARCHAR2(30);
3512 l_progress VARCHAR2(10);
3513 l_msg_count NUMBER;
3514 l_success NUMBER := 0;
3515 l_count NUMBER := 0;
3516 l_temp_qty NUMBER := 0;
3517 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3518 BEGIN
3519 x_return_status := fnd_api.g_ret_sts_success;
3520 l_progress := '10';
3521
3522 IF (l_debug = 1) THEN
3523 print_debug('Enter insert_serial: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3524 END IF;
3525
3526 SAVEPOINT rcv_insert_serial_sp;
3527 l_to_serial := p_to_serial;
3528 /** we are now calling INV_SERIAL_NUMBER_PUB instead of inv_trx_mgr, for "I" project vipathak
3529 **/
3530 l_return :=
3531 inv_serial_number_pub.validate_serials(
3532 p_org_id => p_org_id
3533 , p_item_id => p_item_id
3534 , p_qty => l_temp_qty
3535 , p_rev => p_rev
3536 , p_lot => p_lot
3537 , p_start_ser => p_from_serial
3538 , p_trx_src_id => p_txn_src_id
3539 , p_trx_action_id => p_txn_action_id
3540 , x_end_ser => l_to_serial
3541 , x_proc_msg => x_msg_data
3542 );
3543 l_progress := '20';
3544
3545 IF l_return = 1 THEN
3546 fnd_message.set_name('INV', 'INVALID_SERIAL_NUMBER');
3547 fnd_msg_pub.ADD;
3548 RAISE fnd_api.g_exc_error;
3549 END IF;
3550
3551 l_progress := '25';
3552 l_count := 0;
3553
3554 -- Bug 4087032 Need to write a wrapper on LENGTH function as
3555 -- it creates compiltaion issues in 8i env. in the below query
3556
3557 BEGIN
3558 SELECT 1
3559 INTO l_count
3560 FROM mtl_serial_numbers_temp msnt, mtl_transaction_lots_temp mtlt, mtl_material_transactions_temp mmtt
3561 WHERE (
3562 (p_from_serial BETWEEN msnt.fm_serial_number AND msnt.to_serial_number
3563 AND get_serial_Length(p_from_serial) = get_serial_Length(msnt.fm_serial_number)
3564 AND get_serial_Length(msnt.fm_serial_number) = get_serial_Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number)))
3565 OR
3566 (p_to_serial BETWEEN msnt.fm_serial_number AND msnt.to_serial_number
3567 AND get_serial_Length(p_to_serial) = get_serial_Length(msnt.fm_serial_number)
3568 AND get_serial_Length(msnt.fm_serial_number) = get_serial_Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number)))
3569 )
3570 AND mmtt.inventory_item_id = p_item_id
3571 AND mmtt.organization_id = p_org_id
3572 AND mtlt.transaction_temp_id(+) = mmtt.transaction_temp_id
3573 AND msnt.transaction_temp_id = NVL(mtlt.serial_transaction_temp_id, mmtt.transaction_temp_id);
3574 EXCEPTION
3575 WHEN OTHERS THEN
3576 l_count := 0;
3577 END;
3578
3579 IF l_count <> 0 THEN
3580 fnd_message.set_name('INV', 'INVALID_SERIAL_NUMBER');
3581 fnd_msg_pub.ADD;
3582 RAISE fnd_api.g_exc_error;
3583 END IF;
3584
3585 l_progress := '30';
3586
3587 IF p_serial_transaction_temp_id IS NULL THEN
3588 l_progress := '40';
3589
3590 SELECT mtl_material_transactions_s.NEXTVAL
3591 INTO p_serial_transaction_temp_id
3592 FROM DUAL;
3593
3594 l_progress := '50';
3595 END IF;
3596
3597 l_progress := '60';
3598 l_return :=
3599 inv_trx_util_pub.insert_ser_trx(
3600 p_trx_tmp_id => p_serial_transaction_temp_id
3601 , p_user_id => p_created_by
3602 , p_fm_ser_num => p_from_serial
3603 , p_to_ser_num => p_to_serial
3604 , p_status_id => p_status_id
3605 , x_proc_msg => x_msg_data
3606 );
3607 l_progress := '70';
3608
3609 BEGIN
3610 UPDATE mtl_serial_numbers
3611 SET group_mark_id = p_serial_transaction_temp_id
3612 WHERE inventory_item_id = p_item_id
3613 AND serial_number BETWEEN p_from_serial AND p_to_serial
3614 AND LENGTH(serial_number) = LENGTH(p_from_serial);
3615 EXCEPTION
3616 WHEN OTHERS THEN
3617 IF (l_debug = 1) THEN
3618 print_debug('Exception updating grp. id', 4);
3619 END IF;
3620 END;
3621
3622 IF (l_debug = 1) THEN
3623 print_debug('Insert serial vals' || p_item_id || ':' || p_from_serial || ':' || p_to_serial, 4);
3624 print_debug('Insert serial, inserted with ' || p_serial_transaction_temp_id || ':' || l_success, 4);
3625 END IF;
3626
3627 -- if the trx manager returned a 1 then it could not insert the row
3628 IF l_return = 1 THEN
3629 RAISE fnd_api.g_exc_error;
3630 END IF;
3631
3632 l_progress := '80';
3633
3634 IF (l_debug = 1) THEN
3635 print_debug('Exitting insert_serial : 90 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3636 END IF;
3637 EXCEPTION
3638 WHEN fnd_api.g_exc_error THEN
3639 ROLLBACK TO rcv_insert_serial_sp;
3640 x_return_status := fnd_api.g_ret_sts_error;
3641
3642 IF (l_debug = 1) THEN
3643 print_debug('Exitting insert_serial - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3644 END IF;
3645
3646 -- Get message count and data
3647 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_msg_data);
3648 WHEN OTHERS THEN
3649 x_return_status := fnd_api.g_ret_sts_unexp_error;
3650
3651 IF SQLCODE IS NOT NULL THEN
3652 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.insert_serial', l_progress, SQLCODE);
3653 END IF;
3654
3655 IF (l_debug = 1) THEN
3656 print_debug('Exitting insert_serial - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3657 END IF;
3658
3659 --
3660 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
3661 fnd_msg_pub.add_exc_msg(g_pkg_name, 'insert_serial');
3662 END IF;
3663 END insert_serial;
3664
3665 -- Bug 9274276
3666 PROCEDURE get_rma_uom_code (x_return_status OUT NOCOPY VARCHAR2,
3667 x_uom_code OUT NOCOPY VARCHAR2,
3668 p_order_header_id IN NUMBER,
3669 p_item_id IN NUMBER,
3670 p_organization_id IN NUMBER)
3671 IS
3672 l_progress VARCHAR2 (10);
3673 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
3674 l_count NUMBER;
3675 BEGIN
3676 x_return_status := fnd_api.g_ret_sts_success;
3677
3678 IF (l_debug = 1)
3679 THEN
3680 print_debug ('Parameters passed : 10.1: p_order_header_id - ' || p_order_header_id, 4);
3681 print_debug ('Parameters passed : 10.2: p_item_id - ' || p_item_id, 4);
3682 print_debug ('Parameters passed : 10.3: p_organization_id - ' || p_organization_id, 4);
3683 END IF;
3684
3685 x_uom_code := '@@@';
3686 l_progress := '10';
3687 l_count := 0;
3688
3689 IF p_order_header_id IS NOT NULL AND p_item_id IS NOT NULL
3690 THEN
3691 l_progress := '20';
3692 BEGIN
3693 SELECT COUNT (DISTINCT oel.order_quantity_uom)
3694 INTO l_count
3695 FROM oe_order_lines_all oel, oe_order_headers_all oeh
3696 WHERE oel.header_id = p_order_header_id
3697 --AND oel.ordered_item_id = p_item_id -- commented for Bug 12640725
3698 AND oel.inventory_item_id = p_item_id -- added for Bug 12640725
3699 AND NVL (OEL.SHIP_FROM_ORG_ID, OEH.SHIP_FROM_ORG_ID) = p_organization_id
3700 AND OEL.LINE_CATEGORY_CODE = 'RETURN'
3701 AND oel.cancelled_flag = 'N'
3702 AND oel.open_flag = 'Y'
3703 AND oel.booked_flag = 'Y'
3704 AND OEL.FLOW_STATUS_CODE = 'AWAITING_RETURN'
3705 AND OEL.ORDERED_QUANTITY > NVL (OEL.SHIPPED_QUANTITY, 0)
3706 AND oeh.header_id = oel.header_id
3707 AND OEH.OPEN_FLAG = 'Y';
3708 EXCEPTION
3709 WHEN NO_DATA_FOUND
3710 THEN
3711 l_count := 0;
3712 END;
3713
3714 IF l_count = 1
3715 THEN
3716 l_progress := '30';
3717 BEGIN
3718 SELECT inv_ui_item_lovs.get_conversion_rate (oel.order_quantity_uom,
3719 p_organization_id,
3720 --oel.ordered_item_id) -- commented for Bug 12640725
3721 oel.inventory_item_id) -- added for Bug 12640725
3722 INTO x_uom_code
3723 FROM oe_order_lines_all oel
3724 WHERE oel.header_id = p_order_header_id
3725 --AND oel.ordered_item_id = p_item_id -- commented for Bug 12640725
3726 AND oel.inventory_item_id = p_item_id -- added for Bug 12640725
3727 AND oel.line_category_code = 'RETURN'
3728 AND oel.cancelled_flag = 'N'
3729 AND oel.open_flag = 'Y'
3730 AND oel.booked_flag = 'Y'
3731 AND oel.flow_status_code = 'AWAITING_RETURN'
3732 AND EXISTS (SELECT 1
3733 FROM oe_order_headers_all oeh
3734 WHERE oeh.open_flag = 'Y' AND oeh.header_id = oel.header_id)
3735 AND ROWNUM = 1;
3736 EXCEPTION
3737 WHEN OTHERS
3738 THEN
3739 x_uom_code := '@@@';
3740 END;
3741 END IF;
3742 END IF;
3743 EXCEPTION
3744 WHEN OTHERS
3745 THEN
3746 x_return_status := fnd_api.g_ret_sts_unexp_error;
3747
3748 IF SQLCODE IS NOT NULL
3749 THEN
3750 inv_mobile_helper_functions.sql_error ('inv_rcv_common_apis.get_rma_uom_code', l_progress, SQLCODE);
3751 END IF;
3752
3753 IF (l_debug = 1)
3754 THEN
3755 print_debug ('Exitting get_rma_uom_code - other exception:' || l_progress || ' ' || TO_CHAR (SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3756 END IF;
3757
3758 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
3759 THEN
3760 fnd_msg_pub.add_exc_msg (g_pkg_name, 'get_rma_uom_code');
3761 END IF;
3762 END get_rma_uom_code;
3763 -- Bug 9274276
3764
3765 -- Bug 9274276
3766 PROCEDURE get_asn_uom_code (x_return_status OUT NOCOPY VARCHAR2,
3767 x_uom_code OUT NOCOPY VARCHAR2,
3768 p_shipment_header_id IN NUMBER,
3769 p_item_id IN NUMBER,
3770 p_organization_id IN NUMBER)
3771 IS
3772 l_progress VARCHAR2 (10);
3773 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
3774 l_count NUMBER;
3775 BEGIN
3776 x_return_status := fnd_api.g_ret_sts_success;
3777
3778 IF (l_debug = 1)
3779 THEN
3780 print_debug ('Parameters passed : 10.1: p_shipment_header_id - ' || p_shipment_header_id, 4);
3781 print_debug ('Parameters passed : 10.2: p_item_id - ' || p_item_id, 4);
3782 print_debug ('Parameters passed : 10.3: p_organization_id - ' || p_organization_id, 4);
3783 END IF;
3784
3785 x_uom_code := '@@@';
3786 l_progress := '10';
3787 l_count := 0;
3788
3789 IF p_shipment_header_id IS NOT NULL AND p_item_id IS NOT NULL
3790 THEN
3791 l_progress := '20';
3792 BEGIN
3793 SELECT COUNT (DISTINCT rsl.unit_of_measure)
3794 INTO l_count
3795 FROM rcv_shipment_lines rsl
3796 WHERE rsl.shipment_header_id = p_shipment_header_id
3797 AND rsl.unit_of_measure IS NOT NULL
3798 AND rsl.shipment_line_status_code <> 'FULLY RECEIVED'
3799 AND rsl.item_id = p_item_id
3800 AND rsl.asn_line_flag = 'Y'
3801 AND rsl.to_organization_id = p_organization_id;
3802 EXCEPTION
3803 WHEN NO_DATA_FOUND
3804 THEN
3805 l_count := 0;
3806 END;
3807
3808 IF l_count = 1
3809 THEN
3810 l_progress := '30';
3811 BEGIN
3812 SELECT inv_ui_item_lovs.get_conversion_rate (mum.uom_code, p_organization_id, rsl.item_id)
3813 INTO x_uom_code
3814 FROM rcv_shipment_lines rsl, mtl_units_of_measure mum
3815 WHERE rsl.shipment_header_id = p_shipment_header_id
3816 AND rsl.unit_of_measure IS NOT NULL
3817 AND rsl.shipment_line_status_code <> 'FULLY RECEIVED'
3818 AND rsl.item_id = p_item_id
3819 AND mum.unit_of_measure(+) = rsl.unit_of_measure
3820 AND rsl.asn_line_flag = 'Y'
3821 AND rsl.to_organization_id = p_organization_id
3822 AND ROWNUM = 1;
3823 EXCEPTION
3824 WHEN OTHERS
3825 THEN
3826 x_uom_code := '@@@';
3827 END;
3828 END IF;
3829 END IF;
3830 EXCEPTION
3831 WHEN OTHERS
3832 THEN
3833 x_return_status := fnd_api.g_ret_sts_unexp_error;
3834
3835 IF SQLCODE IS NOT NULL
3836 THEN
3837 inv_mobile_helper_functions.sql_error ('inv_rcv_common_apis.get_asn_uom_code', l_progress, SQLCODE);
3838 END IF;
3839
3840 IF (l_debug = 1)
3841 THEN
3842 print_debug (
3843 'Exitting get_asn_uom_code - other exception:' || l_progress || ' ' || TO_CHAR (SYSDATE, 'YYYY-MM-DD HH:DD:SS'),1);
3844 END IF;
3845
3846 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
3847 THEN
3848 fnd_msg_pub.add_exc_msg (g_pkg_name, 'get_asn_uom_code');
3849 END IF;
3850 END get_asn_uom_code;
3851 -- Bug 9274276
3852
3853 -- Bug 9274276
3854 PROCEDURE get_asn_uom_code (x_return_status OUT NOCOPY VARCHAR2,
3855 x_uom_code OUT NOCOPY VARCHAR2,
3856 p_shipment_header_id IN NUMBER,
3857 p_item_id IN NUMBER,
3858 p_organization_id IN NUMBER,
3859 P_item_desc IN Varchar2)
3860 IS
3861 l_progress VARCHAR2 (10);
3862 l_class VARCHAR2 (10);
3863 l_debug NUMBER := NVL (fnd_profile.VALUE ('INV_DEBUG_TRACE'), 0);
3864 BEGIN
3865 x_return_status := fnd_api.g_ret_sts_success;
3866
3867 IF (l_debug = 1)
3868 THEN
3869 print_debug ('Parameters passed : 10.1: p_shipment_header_id - ' || p_shipment_header_id, 4);
3870 print_debug ('Parameters passed : 10.2: p_item_id - ' || p_item_id, 4);
3871 print_debug ('Parameters passed : 10.3: p_organization_id - ' || p_organization_id, 4);
3872 print_debug ('Parameters passed : 10.5: P_item_desc - ' || P_item_desc, 4);
3873 END IF;
3874
3875 x_uom_code := '@@@';
3876 l_progress := '10';
3877
3878 IF p_shipment_header_id IS NOT NULL AND P_item_desc IS NOT NULL
3879 THEN
3880 l_progress := '20';
3881 BEGIN
3882 SELECT mum.uom_code, mum.uom_class
3883 INTO x_uom_code, l_class
3884 FROM rcv_shipment_lines rsl, mtl_units_of_measure mum
3885 WHERE rsl.shipment_header_id = p_shipment_header_id
3886 AND rsl.unit_of_measure IS NOT NULL
3887 AND rsl.shipment_line_status_code <> 'FULLY RECEIVED'
3888 AND rsl.item_description = p_item_desc
3889 AND mum.unit_of_measure(+) = rsl.unit_of_measure
3890 AND rsl.asn_line_flag = 'Y'
3891 AND rsl.to_organization_id = p_organization_id
3892 AND ROWNUM = 1;
3893
3894 SELECT INV_UI_RCV_LOVS.get_conversion_rate_expense (muom.uom_code,
3895 p_organization_id,
3896 0,
3897 x_uom_code)
3898 INTO x_uom_code
3899 FROM mtl_uom_conversions_val_v muc, mtl_units_of_measure muom
3900 WHERE muc.uom_class = l_class
3901 AND muc.item_id = 0
3902 AND NVL (muc.disable_date, SYSDATE + 1) > SYSDATE
3903 AND muc.unit_of_measure = muom.unit_of_measure
3904 AND NVL (muom.disable_date, SYSDATE + 1) > SYSDATE
3905 AND muom.uom_code LIKE (x_uom_code)
3906 ORDER BY muc.unit_of_measure;
3907 EXCEPTION
3908 WHEN NO_DATA_FOUND
3909 THEN
3910 x_uom_code := '@@@';
3911 END;
3912 ELSIF p_shipment_header_id IS NOT NULL AND p_item_desc IS NULL
3913 THEN
3914 l_progress := '30';
3915 BEGIN
3916 SELECT mum.uom_code, mum.uom_class
3917 INTO x_uom_code, l_class
3918 FROM rcv_shipment_lines rsl, mtl_units_of_measure mum
3919 WHERE rsl.shipment_header_id = p_shipment_header_id
3920 AND rsl.unit_of_measure IS NOT NULL
3921 AND rsl.shipment_line_status_code <> 'FULLY RECEIVED'
3922 AND rsl.item_id IS NULL
3923 AND mum.UNIT_OF_MEASURE(+) = rsl.unit_of_measure
3924 AND RSL.ASN_LINE_FLAG = 'Y'
3925 AND rsl.TO_ORGANIZATION_ID = p_organization_id
3926 AND ROWNUM = 1;
3927
3928 SELECT INV_UI_RCV_LOVS.get_conversion_rate_expense (muom.uom_code,
3929 p_organization_id,
3930 0,
3931 x_uom_code)
3932 INTO x_uom_code
3933 FROM mtl_uom_conversions_val_v muc, mtl_units_of_measure muom
3934 WHERE muc.uom_class = l_class
3935 AND muc.item_id = 0
3936 AND NVL (muc.disable_date, SYSDATE + 1) > SYSDATE
3937 AND muc.unit_of_measure = muom.unit_of_measure
3938 AND NVL (muom.disable_date, SYSDATE + 1) > SYSDATE
3939 AND muom.uom_code LIKE (x_uom_code)
3940 ORDER BY muc.unit_of_measure;
3941 EXCEPTION
3942 WHEN NO_DATA_FOUND
3943 THEN
3944 x_uom_code := '@@@';
3945 END;
3946 END IF;
3947 EXCEPTION
3948 WHEN OTHERS
3949 THEN
3950 x_return_status := fnd_api.g_ret_sts_unexp_error;
3951
3952 IF SQLCODE IS NOT NULL
3953 THEN
3954 inv_mobile_helper_functions.sql_error ('inv_rcv_common_apis.get_asn_uom_code', l_progress, SQLCODE);
3955 END IF;
3956
3957 IF (l_debug = 1)
3958 THEN
3959 print_debug ('Exitting get_asn_uom_code - other exception:' || l_progress || ' ' || TO_CHAR (SYSDATE, 'YYYY-MM-DD HH:DD:SS'),1);
3960 END IF;
3961
3962 IF fnd_msg_pub.check_msg_level (fnd_msg_pub.g_msg_lvl_unexp_error)
3963 THEN
3964 fnd_msg_pub.add_exc_msg (g_pkg_name, 'get_asn_uom_code');
3965 END IF;
3966 END get_asn_uom_code;
3967 -- Bug 9274276
3968
3969 --BUG#3062591
3970 PROCEDURE get_uom_code(
3971 x_return_status OUT NOCOPY VARCHAR2
3972 , x_uom_code OUT NOCOPY VARCHAR2
3973 , p_po_header_id IN NUMBER
3974 , p_item_id IN NUMBER
3975 , p_organization_id IN NUMBER
3976 , p_line_no IN NUMBER --BUG 4500676
3977 , p_item_desc IN VARCHAR2 --BUG 4500676
3978 ) IS
3979 l_progress VARCHAR2(10);
3980 l_class VARCHAR2(10);
3981 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3982 l_count NUMBER;
3983 BEGIN
3984 x_return_status := fnd_api.g_ret_sts_success;
3985 IF (l_debug = 1) THEN
3986 print_debug('Entering get_uom_code',4);
3987 print_debug('Parameters passed : 10.1: p_po_header_id - ' || p_po_header_id , 4);
3988 print_debug('Parameters passed : 10.2: p_item_id - ' || p_item_id, 4);
3989 print_debug('Parameters passed : 10.3: p_organization_id - ' || p_organization_id, 4);
3990 print_debug('Parameters passed : 10.4: p_line_no - ' || p_line_no , 4);
3991 print_debug('Parameters passed : 10.5: p_item_desc - ' || p_item_desc, 4);
3992 END IF;
3993
3994 x_uom_code := '@@@';
3995 l_progress := '10';
3996 l_count := 0;
3997
3998 --BUG 4500676: Add logic to retrieve uom_code for expense item
3999 IF p_po_header_id IS NOT NULL AND p_item_id IS NULL and p_line_no is not null THEN
4000 l_progress := '20';
4001 BEGIN
4002 SELECT mum.uom_code, mum.uom_class
4003 INTO x_uom_code, l_class
4004 FROM po_lines pol, mtl_units_of_measure mum
4005 WHERE pol.po_header_id = p_po_header_id
4006 AND pol.unit_meas_lookup_code IS NOT NULL
4007 AND pol.line_num = p_line_no
4008 AND pol.unit_meas_lookup_code = mum.unit_of_measure
4009 AND pol.po_line_id IN (SELECT poll.po_line_id
4010 FROM po_line_locations_all poll, po_lines_all po
4011 WHERE poll.po_header_id = po.po_header_id
4012 AND Nvl(poll.approved_flag,'N') = 'Y'
4013 AND Nvl(poll.cancel_flag,'N') = 'N'
4014 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING')
4015 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
4016 AND poll.ship_to_organization_id = p_organization_id
4017 AND poll.po_line_id = po.po_line_id
4018 AND po.po_header_id = p_po_header_id)
4019 AND ROWNUM=1;
4020 SELECT INV_UI_RCV_LOVS.get_conversion_rate_expense(muom.uom_code,p_organization_id ,0,x_uom_code )
4021 into x_uom_code
4022 from
4023 mtl_uom_conversions_val_v muc ,
4024 mtl_units_of_measure muom
4025 where muc.uom_class = l_class
4026 and muc.item_id = 0
4027 and nvl(muc.disable_date,sysdate+1)>sysdate
4028 and muc.unit_of_measure = muom.unit_of_measure
4029 and nvl(muom.disable_date,sysdate+1) > sysdate
4030 and muom.uom_code like (x_uom_code)
4031 order by muc.unit_of_measure;
4032 EXCEPTION
4033 WHEN NO_DATA_FOUND THEN
4034 x_uom_code := '@@@';
4035 END;
4036 Elsif p_po_header_id IS NOT NULL AND p_item_id IS NULL and p_line_no is null and p_item_desc is not null THEN
4037 l_progress := '30';
4038 BEGIN
4039 SELECT mum.uom_code, mum.uom_class
4040 INTO x_uom_code, l_class
4041 FROM po_lines pol, mtl_units_of_measure mum
4042 WHERE pol.po_header_id = p_po_header_id
4043 AND pol.unit_meas_lookup_code IS NOT NULL
4044 AND pol.unit_meas_lookup_code = mum.unit_of_measure
4045 AND pol.item_description = p_item_desc
4046 AND pol.po_line_id IN (SELECT poll.po_line_id
4047 FROM po_line_locations_all poll, po_lines_all po
4048 WHERE poll.po_header_id = po.po_header_id
4049 AND Nvl(poll.approved_flag,'N') = 'Y'
4050 AND Nvl(poll.cancel_flag,'N') = 'N'
4051 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING')
4052 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
4053 AND poll.ship_to_organization_id = p_organization_id
4054 AND poll.po_line_id = po.po_line_id
4055 AND po.po_header_id = p_po_header_id)
4056 AND ROWNUM=1;
4057 SELECT INV_UI_RCV_LOVS.get_conversion_rate_expense(muom.uom_code, p_organization_id ,0,x_uom_code )
4058 into x_uom_code
4059 from
4060 mtl_uom_conversions_val_v muc ,
4061 mtl_units_of_measure muom
4062 where muc.uom_class = l_class
4063 and muc.item_id = 0
4064 and nvl(muc.disable_date,sysdate+1)>sysdate
4065 and muc.unit_of_measure = muom.unit_of_measure
4066 and nvl(muom.disable_date,sysdate+1) > sysdate
4067 and muom.uom_code like (x_uom_code)
4068 order by muc.unit_of_measure;
4069 EXCEPTION
4070 WHEN NO_DATA_FOUND THEN
4071 x_uom_code := '@@@';
4072 END;
4073 --END BUG 4500676
4074
4075 ELSIF p_po_header_id IS NOT NULL AND p_item_id IS NOT NULL THEN
4076 l_progress := '20';
4077 BEGIN
4078 SELECT COUNT(DISTINCT pol.unit_meas_lookup_code)
4079 INTO l_count
4080 FROM po_lines pol
4081 WHERE pol.po_header_id = p_po_header_id
4082 AND pol.unit_meas_lookup_code IS NOT NULL
4083 AND pol.item_id = p_item_id
4084 AND pol.po_line_id IN (SELECT poll.po_line_id
4085 FROM po_line_locations_all poll, po_lines_all po
4086 WHERE poll.po_header_id = po.po_header_id
4087 AND Nvl(poll.approved_flag,'N') = 'Y'
4088 AND Nvl(poll.cancel_flag,'N') = 'N'
4089 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING')
4090 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
4091 AND poll.ship_to_organization_id = p_organization_id
4092 AND poll.po_line_id = po.po_line_id
4093 AND po.item_id = p_item_id
4094 AND po.po_header_id = p_po_header_id);
4095 EXCEPTION
4096 WHEN NO_DATA_FOUND THEN
4097 l_count := 0;
4098 END;
4099
4100 IF l_count = 1 THEN
4101 l_progress := '30';
4102 BEGIN
4103 SELECT inv_ui_item_lovs.get_conversion_rate(mum.uom_code,
4104 p_organization_id,
4105 pol.item_id)
4106 INTO x_uom_code
4107 FROM po_lines pol
4108 , mtl_units_of_measure mum
4109 WHERE pol.po_header_id = p_po_header_id
4110 AND pol.unit_meas_lookup_code IS NOT NULL
4111 AND pol.item_id = p_item_id
4112 AND mum.UNIT_OF_MEASURE(+) = pol.UNIT_MEAS_LOOKUP_CODE
4113 AND pol.po_line_id IN (SELECT poll.po_line_id
4114 FROM po_line_locations_all poll, po_lines_all po
4115 WHERE poll.po_header_id = po.po_header_id
4116 AND Nvl(poll.approved_flag,'N') = 'Y'
4117 AND Nvl(poll.cancel_flag,'N') = 'N'
4118 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING')
4119 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
4120 AND poll.ship_to_organization_id = p_organization_id
4121 AND poll.po_line_id = po.po_line_id
4122 AND po.item_id = p_item_id
4123 AND po.po_header_id = p_po_header_id)
4124 AND ROWNUM = 1;
4125 EXCEPTION
4126 WHEN OTHERS THEN
4127 x_uom_code := '@@@';
4128 END;
4129 END IF;
4130 END IF;
4131
4132 IF (l_debug = 1) THEN
4133 print_debug('x_uom_code:'||x_uom_code,4);
4134 END IF;
4135 EXCEPTION
4136 WHEN OTHERS THEN
4137 x_return_status := fnd_api.g_ret_sts_unexp_error;
4138 IF SQLCODE IS NOT NULL THEN
4139 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_uom_code', l_progress, SQLCODE);
4140 END IF;
4141
4142 IF (l_debug = 1) THEN
4143 print_debug('Exitting get_uom_code - other exception:' || l_progress ||' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4144 END IF;
4145
4146 --
4147 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
4148 fnd_msg_pub.add_exc_msg(g_pkg_name, 'get_uom_code');
4149 END IF;
4150
4151 END get_uom_code;--BUG#3062591
4152
4153 -- This api is used to return the possible value that can be used for
4154 -- subinventory when the item and PO/Shipment Number/RMA are entered.
4155 -- For RMA it always returns null for subinventory.
4156 PROCEDURE get_sub_code(
4157 x_return_status OUT NOCOPY VARCHAR2,
4158 x_msg_count OUT NOCOPY NUMBER,
4159 x_msg_data OUT NOCOPY VARCHAR2,
4160 x_sub_code OUT NOCOPY VARCHAR2,
4161 x_locator_segs OUT NOCOPY VARCHAR2,
4162 x_locator_id OUT NOCOPY NUMBER,
4163 x_lpn_context OUT NOCOPY NUMBER,
4164 x_default_source OUT NOCOPY VARCHAR2,
4165 p_po_header_id IN NUMBER,
4166 p_po_release_id IN NUMBER,
4167 p_po_line_id IN NUMBER,
4168 p_shipment_header_id IN NUMBER,
4169 p_oe_order_header_id IN NUMBER,
4170 p_item_id IN NUMBER,
4171 p_organization_id IN NUMBER,
4172 p_lpn_id IN NUMBER DEFAULT NULL,
4173 p_project_id IN NUMBER DEFAULT NULL,
4174 p_task_id IN NUMBER DEFAULT NULL) IS
4175 l_count NUMBER;
4176 l_locator_id NUMBER := -1;
4177 l_lpn_context NUMBER := 5;
4178 l_lpn_controlled_flag NUMBER := 2;
4179 l_progress VARCHAR2(10);
4180 l_auto_transact_code VARCHAR2(10);
4181 l_is_pjm_org NUMBER := 2;
4182 l_loc_project_id NUMBER;
4183 l_loc_task_id NUMBER;
4184 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4185 l_kanban_card_id NUMBER := -999; --Bug 4671198
4186 l_count_lpn NUMBER := 0; --Bug 5928199
4187 BEGIN
4188 x_return_status := fnd_api.g_ret_sts_success;
4189
4190 /* Two new parameter x_lpn_context and x_default_source have been added
4191 * to return the lpn_context and a flag that indicates how the
4192 * subinventory and locator have been defaulted. Possible values are:
4193 * LPN -> Sub and locator are derived from WMS_LICENSE_PLATE_NUMBERS
4194 * RTI -> Sub and locator are derived from RCV_TRANSACTIONS_INTERFACE
4195 * DOC -> Sub and locator are derived from document (POD/RSL/REQ)
4196 * ITD -> Sub and locator are derived from item transaction defaults
4197 * NONE -> There is no default sub and locator being returned
4198 * This validation is applicable only if INV and PO patch levels are J or
4199 * higher and is used by the Receipt UI to default the sub and locator beans.
4200 * If patch levels are < J, this variable would hold the value NONE
4201 */
4202 x_default_source := 'NONE';
4203 x_lpn_context := 5;
4204
4205 IF (l_debug = 1) THEN
4206 print_debug('Enter get_sub_code: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4207 print_debug('Parameters passed : 10.1: p_po_header_id - ' || p_po_header_id, 4);
4208 print_debug('Parameters passed : 10.2: p_po_release_id - ' || p_po_release_id, 4);
4209 print_debug('Parameters passed : 10.3: p_po_line_id - ' || p_po_line_id, 4);
4210 print_debug('Parameters passed : 10.4: p_shipment_header_id - ' || p_shipment_header_id, 4);
4211 print_debug('Parameters passed : 10.5: p_oe_order_header_id - ' || p_oe_order_header_id, 4);
4212 print_debug('Parameters passed : 10.6: p_item_id - ' || p_item_id, 4);
4213 print_debug('Parameters passed : 10.7: p_organization_id - ' || p_organization_id, 4);
4214 print_debug('Parameters passed : 10.8: p_lpn_id - ' || p_lpn_id, 4);
4215 print_debug('Parameters passed : 10.9: p_project_id - ' || p_project_id, 4);
4216 print_debug('Parameters passed : 10.10: p_task_id - ' || p_task_id, 4);
4217 END IF;
4218
4219 x_sub_code := '@@@';
4220 x_locator_segs := '@@@';
4221 x_locator_id := -1;
4222 l_progress := '10';
4223
4224 IF (p_lpn_id IS NOT NULL AND p_lpn_id > 0) THEN
4225 BEGIN
4226 SELECT NVL(subinventory_code, '@@@')
4227 , NVL(locator_id, -1)
4228 , lpn_context
4229 INTO x_sub_code
4230 , l_locator_id
4231 , l_lpn_context
4232 FROM wms_license_plate_numbers
4233 WHERE lpn_id = p_lpn_id;
4234
4235
4236 --added for Bug 5928199
4237 select count(*) into l_count_lpn
4238 from wms_lpn_contents
4239 WHERE parent_lpn_id = p_lpn_id;
4240
4241 --Set the out variable for lpn_context
4242 x_lpn_context := l_lpn_context;
4243 --added for Bug 5928199
4244 IF (l_debug = 1) THEN
4245 print_debug('lpn_context'||l_lpn_context||'l_locator_id'||l_locator_id||'x_sub_code'||x_sub_code,4);
4246 END IF;
4247
4248 --Bug #3360067
4249 --If the LPN resides in inventory and the current org is PJM-enabled
4250 --get the project_id and task_id from MTL_ITEM_LOCATIONS for this locator
4251 --and compare the project and task of the locator with those passed
4252 --In case of project/task commingling, raise an error indicating the same
4253 --Added extra condition l_count_lpn <> 0 for Bug 5928199
4254 IF (l_lpn_context = 1 AND l_locator_id IS NOT NULL AND l_count_lpn <> 0) THEN
4255
4256 SELECT NVL(project_reference_enabled, 2)
4257 INTO l_is_pjm_org
4258 FROM mtl_parameters
4259 WHERE organization_id = p_organization_id;
4260
4261 IF (l_is_pjm_org = 1) THEN
4262 SELECT mil.project_id
4263 , mil.task_id
4264 INTO l_loc_project_id
4265 , l_loc_task_id
4266 FROM mtl_item_locations mil
4267 WHERE mil.organization_id = p_organization_id
4268 AND mil.inventory_location_id = l_locator_id;
4269
4270 IF (l_debug = 1) THEN
4271 print_debug('l_loc_project_id'||l_loc_project_id||'l_loc_task_id'||l_loc_task_id,4);
4272 print_debug('p_project_id'||p_project_id||'p_task_id'||p_task_id,4);
4273 END IF;
4274
4275 IF (NVL(p_project_id,-9999) <> NVL(l_loc_project_id,-9999)) OR
4276 (NVL(p_task_id,-9999) <> NVL(l_loc_task_id,-9999)) THEN
4277 x_return_status := fnd_api.g_ret_sts_error;
4278 x_msg_data := 'INV_PRJ_ERR';
4279 fnd_message.set_name('INV', 'INV_PRJ_ERR');
4280 fnd_msg_pub.ADD;
4281 END IF; --End if check for proj/task comm error
4282 END IF; --END IF current org is PJM enabled
4283 END IF; --END IF lpn_context = 1
4284
4285 IF ((inv_rcv_common_apis.g_wms_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
4286 (inv_rcv_common_apis.g_po_patch_level >= inv_rcv_common_apis.g_patchset_j_po)) THEN
4287
4288 --If the LPN has a sub/loc associated, set the defaulting source
4289 IF x_sub_code <> '@@@' AND l_locator_id IS NOT NULL THEN
4290 x_default_source := 'LPN';
4291 END IF;
4292
4293 IF (l_lpn_context = 5 AND x_sub_code = '@@@') THEN
4294
4295 IF (l_debug = 1) THEN
4296 print_debug('get_sub_code: WMS and PO are J or higher: should also check for sub/loc from RTI', 4);
4297 END IF;
4298
4299 --Get the subinventory, locator_id and routing from rcv_transactions_interface
4300 --If there exists one and it is not direct then error out with the
4301 --"Invalid LPN context" error since we cannot commingle routings in the same LPN
4302 BEGIN
4303 SELECT NVL(subinventory, '@@@')
4304 , NVL(locator_id, -1)
4305 , auto_transact_code
4306 INTO x_sub_code
4307 , l_locator_id
4308 , l_auto_transact_code
4309 FROM rcv_transactions_interface
4310 WHERE transfer_lpn_id = p_lpn_id
4311 AND transaction_type = 'RECEIVE'
4312 AND transaction_status_code = 'PENDING'
4313 AND processing_status_code <> 'ERROR'
4314 AND ROWNUM = 1;
4315
4316 IF (NVL(l_auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN
4317 x_return_status := fnd_api.g_ret_sts_error;
4318 x_msg_data := 'INV_CANNOT_COMMINGLE_ROUTING';
4319 fnd_message.set_name('INV', 'INV_CANNOT_COMMINGLE_ROUTING');
4320 fnd_msg_pub.ADD;
4321 RETURN;
4322 END IF;
4323 EXCEPTION
4324 WHEN OTHERS THEN
4325 x_sub_code := '@@@';
4326 l_locator_id := -1;
4327 END;
4328
4329 --If the RTI record has a sub/loc associated, set the defaulting source
4330 IF x_sub_code <> '@@@' THEN
4331 x_default_source := 'RTI';
4332 END IF;
4333
4334 END IF; --END IF LPN context is defined but not used
4335 END IF; --END IF patch levels are J or higher
4336 EXCEPTION
4337 WHEN OTHERS THEN
4338 x_sub_code := '@@@';
4339 l_locator_id := -1;
4340 l_lpn_context := 5;
4341 END;
4342 END IF;
4343
4344 IF x_sub_code = '@@@' THEN
4345 IF p_po_header_id IS NOT NULL THEN
4346 l_progress := '20';
4347
4348 BEGIN
4349 SELECT COUNT(DISTINCT pod.destination_subinventory)
4350 INTO l_count
4351 FROM po_distributions pod
4352 WHERE pod.po_header_id = p_po_header_id
4353 AND pod.po_line_id = NVL(p_po_line_id, pod.po_line_id)
4354 AND NVL(pod.po_release_id, -1) = NVL(p_po_release_id, NVL(pod.po_release_id, -1))
4355 AND pod.destination_subinventory IS NOT NULL
4356 AND pod.po_line_id IN(SELECT pol.po_line_id
4357 FROM po_lines pol
4358 WHERE pol.item_id = p_item_id);
4359 EXCEPTION
4360 WHEN NO_DATA_FOUND THEN
4361 l_count := 0;
4362 END;
4363 l_progress := '35';
4364 BEGIN
4365 SELECT pod.destination_subinventory, nvl(kanban_card_id, -999) --Bug 4671198
4366 INTO x_sub_code, l_kanban_card_id --Bug 4671198
4367 FROM po_distributions pod
4368 WHERE pod.po_header_id = p_po_header_id
4369 AND pod.po_line_id = NVL(p_po_line_id, pod.po_line_id)
4370 AND NVL(pod.po_release_id, -1) = NVL(p_po_release_id, NVL(pod.po_release_id, -1))
4371 AND pod.destination_subinventory IS NOT NULL
4372 AND pod.po_line_id IN(SELECT pol.po_line_id
4373 FROM po_lines pol
4374 WHERE pol.item_id = p_item_id)
4375 AND ROWNUM = 1;
4376 EXCEPTION
4377 WHEN OTHERS THEN
4378 x_sub_code := '@@@';
4379 END;
4380
4381 --Begin bug 4671198
4382 IF ((x_sub_code <> '@@@') AND (l_kanban_card_id <> -999)) THEN
4383
4384 BEGIN
4385 SELECT NVL(locator_id, -1)
4386 INTO l_locator_id
4387 FROM mtl_kanban_cards
4388 WHERE kanban_card_id = l_kanban_card_id
4389 AND subinventory_name = x_sub_code;
4390
4391 EXCEPTION
4392 WHEN NO_DATA_FOUND THEN
4393 l_locator_id := -1;
4394 END;
4395 END IF;
4396 --End Bug 4671198
4397
4398 --If the document (POD) has a sub/loc associated, set the defaulting source
4399 IF x_sub_code <> '@@@' THEN
4400 x_default_source := 'DOC';
4401 END IF;
4402 --END IF;
4403
4404 l_progress := '37';
4405 ELSIF p_shipment_header_id IS NOT NULL THEN
4406 l_progress := '40';
4407
4408 BEGIN
4409 SELECT COUNT(DISTINCT rsl.to_subinventory)
4410 INTO l_count
4411 FROM rcv_shipment_lines rsl
4412 WHERE rsl.shipment_header_id = p_shipment_header_id
4413 AND rsl.item_id = NVL(p_item_id, rsl.item_id)
4414 AND rsl.to_subinventory IS NOT NULL;
4415 EXCEPTION
4416 WHEN NO_DATA_FOUND THEN
4417 l_count := 0;
4418 END;
4419
4420 l_progress := '50';
4421
4422 IF l_count = 1 THEN
4423 l_progress := '55';
4424
4425 BEGIN
4426 SELECT rsl.to_subinventory
4427 , NVL(rsl.locator_id, -1)
4428 INTO x_sub_code
4429 , l_locator_id
4430 FROM rcv_shipment_lines rsl
4431 WHERE rsl.shipment_header_id = p_shipment_header_id
4432 AND rsl.item_id = NVL(p_item_id, rsl.item_id)
4433 AND rsl.to_subinventory IS NOT NULL
4434 AND ROWNUM = 1;
4435 EXCEPTION
4436 WHEN OTHERS THEN
4437 x_sub_code := '@@@';
4438 l_locator_id := -1;
4439 END;
4440 --If the document (RSL) has a sub/loc associated, set the defaulting source
4441 IF x_sub_code <> '@@@' THEN
4442 x_default_source := 'DOC';
4443 END IF;
4444 END IF;
4445 END IF;
4446 END IF;
4447
4448 l_progress := '60';
4449
4450 IF x_sub_code = '@@@' THEN
4451 l_progress := '70';
4452
4453 BEGIN
4454 SELECT subinventory_code
4455 INTO x_sub_code
4456 FROM mtl_item_sub_defaults
4457 WHERE inventory_item_id = p_item_id
4458 AND organization_id = p_organization_id
4459 AND default_type = 2;
4460 EXCEPTION
4461 WHEN OTHERS THEN
4462 x_sub_code := '@@@';
4463 END;
4464
4465 l_progress := '80';
4466
4467 /* Bug 2323718: Changed the query so that records are filtered on Project and Task */
4468 IF x_sub_code <> '@@@' THEN
4469 l_progress := '90';
4470
4471 --Set the defaulting type to indicate that the sub is available in item defaults
4472 x_default_source := 'ITD';
4473
4474 BEGIN
4475 SELECT mild.locator_id
4476 INTO l_locator_id
4477 FROM mtl_item_loc_defaults mild, mtl_item_locations mil
4478 WHERE mild.inventory_item_id = p_item_id
4479 AND mild.organization_id = p_organization_id
4480 AND mild.subinventory_code = x_sub_code
4481 AND mil.inventory_location_id = mild.locator_id
4482 AND(p_project_id IS NULL
4483 OR(p_project_id = -9999
4484 AND mil.project_id IS NULL)
4485 OR mil.project_id = p_project_id)
4486 AND NVL(mil.task_id, -1) = NVL(p_task_id, NVL(mil.task_id, -1))
4487 AND mild.default_type = 2;
4488 EXCEPTION
4489 WHEN OTHERS THEN
4490 l_locator_id := -1;
4491 END;
4492 END IF;
4493
4494 --BUG 5972088
4495 -- Bug# 7013341, removed the condition x_locator_segs ='@@@' and added
4496 -- the condition l_locator_id = -1 instead, as x_locator_segs is assigned a
4497 -- valid value only at the end of this function once a valid locator ccid
4498 -- is identified from the above code logic.
4499 -- Hence there could be a scenario where l_locator_id is having a valid locator_id
4500 -- but x_locator_segs is still '@@@'.
4501 ELSIF x_sub_code <> '@@@' AND l_locator_id = -1 THEN
4502 -- End of bug# 7013341
4503 l_progress := '90';
4504 --Set the defaulting type to indicate that the sub is available in item defaults
4505 x_default_source := 'ITD';
4506 BEGIN
4507 SELECT mild.locator_id
4508 INTO l_locator_id
4509 FROM mtl_item_loc_defaults mild, mtl_item_locations mil
4510 WHERE mild.inventory_item_id = p_item_id
4511 AND mild.organization_id = p_organization_id
4512 AND mild.subinventory_code = x_sub_code
4513 AND mil.inventory_location_id = mild.locator_id
4514 AND(p_project_id IS NULL
4515 OR(p_project_id = -9999
4516 AND mil.project_id IS NULL)
4517 OR mil.project_id = p_project_id)
4518 AND NVL(mil.task_id, -1) = NVL(p_task_id, NVL(mil.task_id, -1))
4519 AND mild.default_type = 2;
4520 EXCEPTION
4521 WHEN OTHERS THEN
4522 l_locator_id := -1;
4523 END;
4524 --END BUG 5972088
4525
4526 END IF;
4527
4528 l_progress := '100';
4529
4530 /* Bug 2323718: Returning INV_PROJECT.get_locsegs rather than conc. segments */
4531 IF l_locator_id <> -1 THEN
4532 l_progress := '110';
4533
4534 BEGIN
4535 SELECT inv_project.get_locsegs(inventory_location_id, organization_id)
4536 INTO x_locator_segs
4537 FROM mtl_item_locations
4538 WHERE organization_id = p_organization_id
4539 AND inventory_location_id = l_locator_id;
4540
4541 x_locator_id := l_locator_id;
4542 EXCEPTION
4543 WHEN OTHERS THEN
4544 x_locator_segs := '@@@';
4545 x_locator_id := -1;
4546 END;
4547 END IF;
4548
4549 l_progress := '120';
4550
4551 --If the INV or PO patch levels are < J, then we can reset the OUT variable
4552 --x_default_source since it would not be used for UI validations
4553 IF ((inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j) OR
4554 (inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po)) THEN
4555 x_default_source := 'NONE';
4556 x_lpn_context := 5;
4557 ELSE
4558 --If there was no sub/locator defaulted then reset the out variable
4559 IF ((NVL(x_sub_code, '@@@') = '@@@') OR (x_locator_id IS NULL OR x_locator_id = -1)) THEN
4560 x_default_source := 'NONE';
4561 END IF;
4562 END IF;
4563
4564 IF (l_debug = 1) THEN
4565 print_debug('Exitting get_sub_code : 120 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4566 print_debug('with values: x_locator_segs: ' || x_locator_segs || 'x_locator_id: ' || x_locator_id || 'x_sub_code: ' || x_sub_code,1);
4567 print_debug('x_lpn_context: ' || x_lpn_context || 'x_default_source: ' || x_default_source, 1);
4568 END IF;
4569
4570 EXCEPTION
4571 WHEN OTHERS THEN
4572 x_return_status := fnd_api.g_ret_sts_unexp_error;
4573
4574 IF SQLCODE IS NOT NULL THEN
4575 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_sub_code', l_progress, SQLCODE);
4576 END IF;
4577
4578 IF (l_debug = 1) THEN
4579 print_debug('Exitting get_sub_code - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4580 END IF;
4581
4582 --
4583 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
4584 fnd_msg_pub.add_exc_msg(g_pkg_name, 'get_sub_code');
4585 END IF;
4586 END get_sub_code;
4587
4588 -- This api is used to return the possible value that can be used for
4589 -- subinventory when the item and PO/Shipment Number/RMA are entered.
4590 -- For RMA it always returns null for subinventory.
4591 PROCEDURE get_sub_code(
4592 x_return_status OUT NOCOPY VARCHAR2,
4593 x_msg_count OUT NOCOPY NUMBER,
4594 x_msg_data OUT NOCOPY VARCHAR2,
4595 x_sub_code OUT NOCOPY VARCHAR2,
4596 x_locator_segs OUT NOCOPY VARCHAR2,
4597 x_locator_id OUT NOCOPY NUMBER,
4598 p_po_header_id IN NUMBER,
4599 p_po_release_id IN NUMBER,
4600 p_po_line_id IN NUMBER,
4601 p_shipment_header_id IN NUMBER,
4602 p_oe_order_header_id IN NUMBER,
4603 p_item_id IN NUMBER,
4604 p_organization_id IN NUMBER,
4605 p_lpn_id IN NUMBER DEFAULT NULL,
4606 p_project_id IN NUMBER DEFAULT NULL,
4607 p_task_id IN NUMBER DEFAULT NULL) IS
4608 l_lpn_context NUMBER;
4609 l_default_source VARCHAR2(10);
4610 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4611 BEGIN
4612 IF (l_debug = 1) THEN
4613 print_debug('Enter get_sub_code: default implementation:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4614 END IF;
4615
4616 get_sub_code(
4617 x_return_status => x_return_status,
4618 x_msg_count => x_msg_count,
4619 x_msg_data => x_msg_data,
4620 x_sub_code => x_sub_code,
4621 x_locator_segs => x_locator_segs,
4622 x_locator_id => x_locator_id,
4623 x_lpn_context => l_lpn_context,
4624 x_default_source => l_default_source,
4625 p_po_header_id => p_po_header_id,
4626 p_po_release_id => p_po_release_id,
4627 p_po_line_id => p_po_line_id,
4628 p_shipment_header_id => p_shipment_header_id,
4629 p_oe_order_header_id => p_oe_order_header_id,
4630 p_item_id => p_item_id,
4631 p_organization_id => p_organization_id,
4632 p_lpn_id => p_lpn_id,
4633 p_project_id => p_project_id,
4634 p_task_id => p_task_id);
4635 END get_sub_code;
4636
4637
4638 --Bug 3890706 - Added the procedure to select the location based on the entry in the PO form.
4639
4640 PROCEDURE get_location_code
4641 (
4642 x_return_status OUT NOCOPY VARCHAR2,
4643 x_location_code OUT NOCOPY VARCHAR2,
4644 p_po_header_id IN NUMBER,
4645 p_item_id IN NUMBER,
4646 p_po_line_id IN NUMBER,
4647 p_po_release_id IN NUMBER,
4648 p_organization_id IN NUMBER,
4649 p_shipment_header_id IN NUMBER DEFAULT NULL,
4650 p_from_lpn_id IN NUMBER DEFAULT NULL)
4651
4652 IS
4653 l_progress VARCHAR2(10);
4654 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4655
4656 BEGIN
4657
4658 x_location_code := '' ;
4659 x_return_status := fnd_api.g_ret_sts_success;
4660
4661 IF (l_debug = 1) THEN
4662 print_debug('Enter get_location_code: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4663 print_debug('Parameters passed : 10.1: p_po_header_id - ' || p_po_header_id, 4);
4664 print_debug('Parameters passed : 10.2: p_item_id - ' || p_item_id, 4);
4665 print_debug('Parameters passed : 10.3: p_po_release_id - ' || p_po_release_id, 4);
4666 print_debug('Parameters passed : 10.4: p_po_line_id - ' || p_po_line_id, 4);
4667 print_debug('Parameters passed : 10.5: org_id - ' || p_organization_id, 4);
4668 print_debug('Parameters passed : 10.6: p_shipment_header_id - ' || p_shipment_header_id, 4);
4669 print_debug('Parameters passed : 10.7: p_from_lpn_id - ' || p_from_lpn_id, 4);
4670 END IF;
4671
4672 l_progress := '10';
4673
4674 IF p_po_header_id IS NOT NULL THEN
4675
4676 -- bug 8643313
4677 BEGIN
4678 /* bug 14305407 modified the query to improve the performance */
4679 SELECT distinct(hl.location_code)
4680 INTO x_location_code
4681 FROM po_distributions_all pda,po_lines_all pol, po_line_locations_all pll, hr_locations hl
4682 WHERE pda.po_header_id = pll.po_header_id
4683 AND pda.line_location_id = pll.line_location_id
4684 AND pda.po_line_id = pll.po_line_id
4685 AND pda.po_header_id = pol.po_header_id
4686 AND pda.po_line_id = pol.po_line_id
4687 AND pda.deliver_to_location_id = hl.location_id
4688 AND pda.po_header_id = p_po_header_id
4689 AND pda.destination_organization_id = p_organization_id
4690 AND pda.po_line_id = NVL(p_po_line_id, pda.po_line_id)
4691 AND pll.po_line_id = NVL(p_po_line_id, pll.po_line_id)
4692 AND NVL(pda.po_release_id, -1) = NVL(p_po_release_id, NVL(pda.po_release_id, -1))
4693 AND NVL(pll.po_release_id, -1) = NVL(p_po_release_id, NVL(pll.po_release_id, -1))
4694 AND Nvl(pol.item_id,-9999) = NVL(p_item_id,Nvl(pol.item_id,-9999))
4695 AND pll.receiving_routing_id = 3;
4696 /*end bug 14305407*/
4697
4698 EXCEPTION
4699 WHEN No_Data_Found THEN
4700 x_location_code := null;
4701 WHEN too_many_rows THEN
4702 x_location_code := null;
4703 WHEN OTHERS THEN
4704 x_location_code := null;
4705
4706 END;
4707
4708 IF (x_location_code IS NULL) THEN
4709
4710 -- bug 864331
4711 /* bug 14305407 modified the query to improve the performance */
4712 SELECT distinct( hl.location_code )
4713 INTO x_location_code
4714 FROM hr_locations hl, po_line_locations poll,po_lines pol
4715 WHERE hl.location_id = poll.ship_to_location_id
4716 AND poll.po_header_id = pol.po_header_id
4717 AND poll.po_line_id = pol.po_line_id
4718 AND poll.po_header_id = p_po_header_id
4719 AND poll.ship_to_organization_id= p_organization_id
4720 AND poll.po_line_id = NVL(p_po_line_id, poll.po_line_id)
4721 AND NVL(poll.po_release_id, -1) = NVL(p_po_release_id, NVL(poll.po_release_id, -1))
4722 AND NVL(poll.po_release_id, -1) = NVL(p_po_release_id, NVL(poll.po_release_id, -1))
4723 AND Nvl(poll.approved_flag,'N') = 'Y'
4724 AND Nvl(poll.cancel_flag,'N') = 'N'
4725 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING')
4726 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
4727 AND Nvl(pol.item_id,-9999) = NVL(p_item_id,Nvl(pol.item_id,-9999)); --BUG 4500676
4728 /* end bug 14305407*/
4729 END IF; -- bug 864331
4730
4731 l_progress :='20';
4732 IF (l_debug = 1) THEN
4733 print_debug('Checking the value for location: ' || x_location_code, 4);
4734 END IF;
4735 ELSIF p_shipment_header_id IS NOT NULL THEN
4736 SELECT distinct( hl.location_code )
4737 into x_location_code
4738 FROM hr_locations hl, rcv_shipment_lines rsl
4739 WHERE hl.location_id = nvl(rsl.deliver_to_location_id,rsl.ship_to_location_id)--bug10349270 for ASN receipt,we should get the default location against RSL.ship_to_location
4740 AND rsl.shipment_header_id = p_shipment_header_id
4741 AND rsl.item_id = NVL(p_item_id, rsl.item_id)
4742 AND rsl.to_organization_id = p_organization_id
4743 AND NVL(rsl.asn_lpn_id,-1) = NVL(p_from_lpn_id,NVL(rsl.asn_lpn_id,-1))
4744 AND rsl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED');
4745
4746 IF (l_debug = 1) THEN
4747 print_debug('Checking the value for location of Shipment: ' || x_location_code, 4);
4748 END IF;
4749
4750 END IF;
4751
4752 EXCEPTION
4753 WHEN too_many_rows THEN
4754 l_progress := '30' ;
4755 IF (l_debug = 1) THEN
4756 print_debug('There are multiple values for location ', 4);
4757 END IF;
4758 x_location_code := '';
4759 RETURN;
4760 WHEN no_data_found THEN
4761 l_progress:= '40' ;
4762 x_location_code := '';
4763 RETURN;
4764
4765 WHEN OTHERS THEN
4766 x_return_status := fnd_api.g_ret_sts_unexp_error;
4767
4768 IF SQLCODE IS NOT NULL THEN
4769 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_location_code', l_progress, SQLCODE);
4770 END IF;
4771
4772 IF (l_debug = 1) THEN
4773 print_debug('Exitting get_location_code - other exception: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4774 END IF;
4775
4776 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
4777 fnd_msg_pub.add_exc_msg(g_pkg_name, 'get_location_code');
4778 END IF;
4779
4780 END get_location_code;
4781
4782
4783 --End of fix for the Bug 3890706.
4784
4785 --Bug 4003683 -Added the procedure to default the revision for the item.
4786
4787 PROCEDURE GET_REVISION_CODE(
4788 x_return_status OUT NOCOPY VARCHAR2,
4789 x_revision_code OUT NOCOPY VARCHAR2,
4790 p_document_type IN VARCHAR2 DEFAULT NULL,
4791 p_po_header_id IN NUMBER DEFAULT NULL,
4792 p_po_line_id IN NUMBER DEFAULT NULL,
4793 p_po_release_id IN NUMBER DEFAULT NULL,
4794 p_req_header_id IN NUMBER DEFAULT NULL,
4795 p_shipment_header_id IN NUMBER DEFAULT NULL,
4796 p_item_id IN NUMBER DEFAULT NULL,
4797 p_organization_id IN NUMBER,
4798 p_oe_order_header_id IN NUMBER DEFAULT NULL) -- Bug #:5768262 Added parameter p_oe_order_header_id to default the revision of item for RMA
4799
4800 IS
4801 l_progress VARCHAR2(10);
4802 l_shipment_header_id NUMBER ;
4803 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4804 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
4805 l_msg_count NUMBER;
4806 l_msg_data VARCHAR2(4000);
4807 l_rcvreq_use_intship VARCHAR2(1) := 'N' ;
4808 l_doc_type VARCHAR2(50) := ' ';
4809
4810
4811 BEGIN
4812 l_shipment_header_id := p_shipment_header_id;
4813 x_revision_code := '' ;
4814 x_return_status := fnd_api.g_ret_sts_success;
4815
4816 IF (l_debug = 1) THEN
4817 print_debug('Enter get_revision_code: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4818 print_debug('Parameters passed : 10.1: p_document_type - ' || p_document_type, 4);
4819 print_debug('Parameters passed : 10.2: p_po_header_id - ' || p_po_header_id, 4);
4820 print_debug('Parameters passed : 10.3: p_po_line_id - ' || p_po_line_id, 4);
4821 print_debug('Parameters passed : 10.4: p_po_release_id - ' || p_po_release_id, 4);
4822 print_debug('Parameters passed : 10.6: p_req_header_id - ' || p_req_header_id, 4);
4823 print_debug('Parameters passed : 10.7: p_shipment_header_id - ' || p_shipment_header_id,4);
4824 print_debug('Parameters passed : 10.8: p_item_id - ' || p_item_id,4);
4825 print_debug('Parameters passed : 10.8: p_organization_id - ' || p_organization_id,4);
4826 print_debug('Parameters passed : 10.8: p_oe_order_header_id - '|| p_oe_order_header_id,4);
4827 END IF;
4828
4829 l_progress := '10';
4830
4831 IF p_document_type= 'PO' THEN
4832 l_progress := '20';
4833
4834 IF (l_debug = 1) THEN
4835 print_debug('Entering the document type for PO: ' || l_progress, 4);
4836 END IF;
4837
4838 SELECT DISTINCT (pol.item_revision)
4839 INTO x_revision_code
4840 FROM po_line_locations poll,po_lines pol
4841 WHERE pol.po_header_id = p_po_header_id
4842 AND NVL(poll.po_line_id,-1) = NVL(p_po_line_id, NVL(poll.po_line_id, -1))
4843 AND NVL(pol.item_id,-1) = NVL(p_item_id,NVL(pol.item_id, -1))
4844 AND poll.ship_to_organization_id= p_organization_id
4845 AND NVL(poll.po_release_id, -1) = NVL(p_po_release_id, NVL(poll.po_release_id, -1))
4846 AND pol.po_line_id = poll.po_line_id
4847 AND NVL(poll.po_release_id, -1) = NVL(p_po_release_id, NVL(poll.po_release_id, -1))
4848 AND Nvl(poll.approved_flag,'N') = 'Y'
4849 AND Nvl(poll.cancel_flag,'N') = 'N'
4850 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING')
4851 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED');
4852
4853
4854 ELSIF p_document_type IN ( 'REQ', 'INTSHIP' ,'ASN') THEN
4855
4856 l_progress := '30';
4857
4858 IF (l_debug = 1) THEN
4859 print_debug('Entering the document type for REQ/INTSHIP/ASN: ' || l_progress, 4);
4860 END IF;
4861
4862 IF p_document_type = 'REQ' THEN
4863
4864 get_req_shipment_header_id(
4865 x_shipment_header_id => l_shipment_header_id
4866 , x_return_status => x_return_status
4867 , x_msg_count => l_msg_count
4868 , x_msg_data => l_msg_data
4869 , p_organization_id => p_organization_id
4870 , p_requiition_header_id => p_req_header_id
4871 , p_item_id => p_item_id
4872 , p_rcv_txn_type => 'RECEIPT'
4873 , p_lpn_id => NULL
4874 ) ;
4875
4876 END IF;
4877
4878 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4879 IF (l_debug = 1) THEN
4880 print_debug('ERROR occured while getting Shipment Header ID for REQ' , 4);
4881 END IF;
4882 RAISE fnd_api.g_exc_error;
4883 END IF;
4884
4885 IF p_document_type = 'INTSHIP' THEN
4886 BEGIN
4887 SELECT 'Y'
4888 INTO l_rcvreq_use_intship
4889 FROM dual
4890 WHERE EXISTS ( SELECT 1
4891 FROM rcv_shipment_lines
4892 WHERE shipment_header_id = l_shipment_header_id
4893 AND requisition_line_id IS NOT NULL
4894 AND source_document_code = 'REQ'
4895 );
4896 EXCEPTION
4897 WHEN OTHERS THEN
4898 l_rcvreq_use_intship := 'N' ;
4899 END;
4900
4901 IF l_rcvreq_use_intship = 'Y' THEN
4902 l_doc_type := 'REQ' ;
4903 ELSE
4904 l_doc_type := 'INVENTORY';
4905 END IF;
4906 END IF;
4907
4908 SELECT DISTINCT(rsl.item_revision)
4909 INTO x_revision_code
4910 FROM rcv_shipment_lines rsl
4911 WHERE rsl.shipment_header_id = l_shipment_header_id
4912 AND rsl.to_organization_id = p_organization_id
4913 AND rsl.item_id = NVL(p_item_id,rsl.item_id)
4914 AND rsl.source_document_code = DECODE (p_document_type, 'INTSHIP', l_doc_type, 'REQ' ,'REQ', 'ASN','PO', 'REQ' )
4915 AND rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED');
4916
4917 ELSIF p_document_type = 'RMA' THEN
4918 /* Bug #: 5768262 Adding code for handling RMA to defulting revision on receive through mobile. */
4919 /* This code will default the revision if RMA contains only one line or more than one line
4920 /* with the same revision.
4921 /* This code will be for 11.5.10 only. We are not handling this functionality in 11.5.9 for an RMA
4922 /* as unable to enter revision for an item on the order line. */
4923 IF ((inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
4924 (inv_rcv_common_apis.g_po_patch_level >= inv_rcv_common_apis.g_patchset_j_po)) THEN
4925 l_progress := '40';
4926
4927 print_debug('Patchset J code - Defaulting revision for RMA',4);
4928 IF (l_debug = 1) THEN
4929 print_debug('Entering the document type for RMA: ' || l_progress, 4);
4930 END IF;
4931
4932 SELECT DISTINCT(OEL.item_revision)
4933 INTO x_revision_code
4934 FROM
4935 OE_ORDER_LINES_all OEL,
4936 OE_ORDER_HEADERS_all OEH
4937 WHERE OEL.LINE_CATEGORY_CODE='RETURN'
4938 AND OEL.INVENTORY_ITEM_ID = p_item_id
4939 AND nvl(OEL.SHIP_FROM_ORG_ID, OEH.SHIP_FROM_ORG_ID) = p_organization_id
4940 AND OEL.HEADER_ID = OEH.HEADER_ID
4941 AND OEH.HEADER_ID = p_oe_order_header_id
4942 AND OEL.ORDERED_QUANTITY > NVL(OEL.SHIPPED_QUANTITY,0)
4943 AND OEL.FLOW_STATUS_CODE = 'AWAITING_RETURN';
4944 END IF;
4945 /* End of modifications for the Bug #:5768262 */
4946 END IF;
4947
4948 IF (l_debug = 1) THEN
4949 print_debug('Getting the value for revision: ' || x_revision_code, 4);
4950 END IF;
4951
4952 l_progress := '60';
4953
4954 EXCEPTION
4955
4956 WHEN NO_DATA_FOUND THEN
4957 IF (l_debug = 1) THEN
4958 print_debug('There are no values for revision to be returned ', 4);
4959 END IF;
4960 x_revision_code := '' ;
4961 RETURN;
4962
4963
4964 WHEN TOO_MANY_ROWS THEN
4965 IF (l_debug = 1) THEN
4966 print_debug('There is more than one value for revision to be returned ', 4);
4967 END IF;
4968 x_revision_code := '' ;
4969 RETURN;
4970
4971 WHEN OTHERS THEN
4972 x_return_status := fnd_api.g_ret_sts_unexp_error;
4973
4974 IF SQLCODE IS NOT NULL THEN
4975 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_revision_code', l_progress, SQLCODE);
4976 END IF;
4977
4978 IF (l_debug = 1) THEN
4979 print_debug('Exitting get_revision_code - other exception: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4980 END IF;
4981
4982 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
4983 fnd_msg_pub.add_exc_msg(g_pkg_name, 'get_revision_code');
4984 END IF;
4985
4986 END GET_REVISION_CODE;
4987
4988 --End of fix for Bug 4003683
4989
4990
4991 /**************************************************************************
4992 As part of the Bug - 2181558, this code is commented out. The process of
4993 copying the lot attributes from the parent lot to the destination lot is
4994 carried out in the INV_LOT_API_PUB package.
4995
4996 PROCEDURE populatelotattributes
4997 (x_return_status OUT VARCHAR2,
4998 p_organization_id IN NUMBER,
4999 p_from_organization_id IN NUMBER,
5000 p_inventory_item_id IN NUMBER,
5001 p_lot_number IN VARCHAR2,
5002 p_exists IN VARCHAR2)
5003 IS
5004 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5005 BEGIN
5006 IF (l_debug = 1) THEN
5007 print_debug('Updating the lot number attributes',4);
5008 END IF;
5009 UPDATE mtl_lot_numbers
5010 SET (VENDOR_ID,
5011 GRADE_CODE,
5012 ORIGINATION_DATE,
5013 DATE_CODE,
5014 STATUS_ID,
5015 CHANGE_DATE,
5016 AGE,
5017 RETEST_DATE,
5018 MATURITY_DATE,
5019 LOT_ATTRIBUTE_CATEGORY,
5020 ITEM_SIZE,
5021 COLOR,
5022 VOLUME,
5023 VOLUME_UOM,
5024 PLACE_OF_ORIGIN,
5025 BEST_BY_DATE,
5026 LENGTH,
5027 LENGTH_UOM,
5028 RECYCLED_CONTENT,
5029 THICKNESS,
5030 THICKNESS_UOM,
5031 WIDTH,
5032 WIDTH_UOM,
5033 CURL_WRINKLE_FOLD,
5034 C_ATTRIBUTE1,
5035 C_ATTRIBUTE2,
5036 C_ATTRIBUTE3,
5037 C_ATTRIBUTE4,
5038 C_ATTRIBUTE5,
5039 C_ATTRIBUTE6,
5040 C_ATTRIBUTE7,
5041 C_ATTRIBUTE8,
5042 C_ATTRIBUTE9,
5043 C_ATTRIBUTE10,
5044 C_ATTRIBUTE11,
5045 C_ATTRIBUTE12,
5046 C_ATTRIBUTE13,
5047 C_ATTRIBUTE14,
5048 C_ATTRIBUTE15,
5049 C_ATTRIBUTE16,
5050 C_ATTRIBUTE17,
5051 C_ATTRIBUTE18,
5052 C_ATTRIBUTE19,
5053 C_ATTRIBUTE20,
5054 D_ATTRIBUTE1,
5055 D_ATTRIBUTE2,
5056 D_ATTRIBUTE3,
5057 D_ATTRIBUTE4,
5058 D_ATTRIBUTE5,
5059 D_ATTRIBUTE6,
5060 D_ATTRIBUTE7,
5061 D_ATTRIBUTE8,
5062 D_ATTRIBUTE9,
5063 D_ATTRIBUTE10,
5064 N_ATTRIBUTE1,
5065 N_ATTRIBUTE2,
5066 N_ATTRIBUTE3,
5067 N_ATTRIBUTE4,
5068 N_ATTRIBUTE5,
5069 N_ATTRIBUTE6,
5070 N_ATTRIBUTE7,
5071 N_ATTRIBUTE8,
5072 N_ATTRIBUTE10,
5073 SUPPLIER_LOT_NUMBER,
5074 N_ATTRIBUTE9,
5075 TERRITORY_CODE,
5076 vendor_name,
5077 attribute_category,
5078 attribute1,
5079 attribute2,
5080 attribute3,
5081 attribute4,
5082 attribute5,
5083 attribute6,
5084 attribute7,
5085 attribute8,
5086 attribute9,
5087 attribute10,
5088 attribute11,
5089 attribute12,
5090 attribute13,
5091 attribute14,
5092 attribute15
5093 ) =
5094 (SELECT VENDOR_ID,
5095 GRADE_CODE,
5096 ORIGINATION_DATE,
5097 DATE_CODE,
5098 STATUS_ID,
5099 CHANGE_DATE,
5100 AGE,
5101 RETEST_DATE,
5102 MATURITY_DATE,
5103 LOT_ATTRIBUTE_CATEGORY,
5104 ITEM_SIZE,
5105 COLOR,
5106 VOLUME,
5107 VOLUME_UOM,
5108 PLACE_OF_ORIGIN,
5109 BEST_BY_DATE,
5110 LENGTH,
5111 LENGTH_UOM,
5112 RECYCLED_CONTENT,
5113 THICKNESS,
5114 THICKNESS_UOM,
5115 WIDTH,
5116 WIDTH_UOM,
5117 CURL_WRINKLE_FOLD,
5118 C_ATTRIBUTE1,
5119 C_ATTRIBUTE2,
5120 C_ATTRIBUTE3,
5121 C_ATTRIBUTE4,
5122 C_ATTRIBUTE5,
5123 C_ATTRIBUTE6,
5124 C_ATTRIBUTE7,
5125 C_ATTRIBUTE8,
5126 C_ATTRIBUTE9,
5127 C_ATTRIBUTE10,
5128 C_ATTRIBUTE11,
5129 C_ATTRIBUTE12,
5130 C_ATTRIBUTE13,
5131 C_ATTRIBUTE14,
5132 C_ATTRIBUTE15,
5133 C_ATTRIBUTE16,
5134 C_ATTRIBUTE17,
5135 C_ATTRIBUTE18,
5136 C_ATTRIBUTE19,
5137 C_ATTRIBUTE20,
5138 D_ATTRIBUTE1,
5139 D_ATTRIBUTE2,
5140 D_ATTRIBUTE3,
5141 D_ATTRIBUTE4,
5142 D_ATTRIBUTE5,
5143 D_ATTRIBUTE6,
5144 D_ATTRIBUTE7,
5145 D_ATTRIBUTE8,
5146 D_ATTRIBUTE9,
5147 D_ATTRIBUTE10,
5148 N_ATTRIBUTE1,
5149 N_ATTRIBUTE2,
5150 N_ATTRIBUTE3,
5151 N_ATTRIBUTE4,
5152 N_ATTRIBUTE5,
5153 N_ATTRIBUTE6,
5154 N_ATTRIBUTE7,
5155 N_ATTRIBUTE8,
5156 N_ATTRIBUTE10,
5157 SUPPLIER_LOT_NUMBER,
5158 N_ATTRIBUTE9,
5159 TERRITORY_CODE,
5160 vendor_name,
5161 attribute_category,
5162 attribute1,
5163 attribute2,
5164 attribute3,
5165 attribute4,
5166 attribute5,
5167 attribute6,
5168 attribute7,
5169 attribute8,
5170 attribute9,
5171 attribute10,
5172 attribute11,
5173 attribute12,
5174 attribute13,
5175 attribute14,
5176 attribute15
5177 FROM mtl_lot_numbers
5178 WHERE organization_id = p_from_organization_id
5179 AND inventory_item_id = p_inventory_item_id
5180 AND lot_number = p_lot_number)
5181 WHERE organization_id = p_organization_id
5182 AND inventory_item_id = p_inventory_item_id
5183 AND lot_number = p_lot_number;
5184 EXCEPTION
5185 WHEN OTHERS THEN
5186 x_return_status := fnd_api.g_ret_sts_unexp_error ;
5187 IF SQLCODE IS NOT NULL THEN
5188 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_sub_code', '10', SQLCODE);
5189 END IF;
5190 IF (l_debug = 1) THEN
5191 print_debug('Exitting populatelotattributes - other exception:'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 1);
5192 END IF;
5193 --
5194 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
5195 THEN
5196 fnd_msg_pub.add_exc_msg
5197 ( g_pkg_name
5198 , 'populatelotattributes'
5199 );
5200 END IF;
5201
5202 END populatelotattributes;
5203 ******************************************************************************************/
5204
5205 -- This is a wrapper to call inventory INV_LOT_API_PUB.insertLot
5206 -- it stores the inserted lot info in a global variable for
5207 -- transaction exception rollback
5208 PROCEDURE insert_dynamic_lot(
5209 p_api_version IN NUMBER
5210 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5211 , p_commit IN VARCHAR2 := fnd_api.g_false
5212 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
5213 , p_inventory_item_id IN NUMBER
5214 , p_organization_id IN NUMBER
5215 , p_lot_number IN VARCHAR2
5216 , p_expiration_date IN OUT NOCOPY DATE
5217 , p_transaction_temp_id IN NUMBER DEFAULT NULL
5218 , p_transaction_action_id IN NUMBER DEFAULT NULL
5219 , p_transfer_organization_id IN NUMBER DEFAULT NULL
5220 , p_status_id IN NUMBER
5221 , p_update_status IN VARCHAR2 := 'FALSE'
5222 , x_object_id OUT NOCOPY NUMBER
5223 , x_return_status OUT NOCOPY VARCHAR2
5224 , x_msg_count OUT NOCOPY NUMBER
5225 , x_msg_data OUT NOCOPY VARCHAR2
5226 , p_parent_lot_number IN VARCHAR2 DEFAULT NULL -- bug 10176719 - inserting parent lot number
5227 , p_origination_type IN NUMBER DEFAULT NULL -- bug 15896641 - inserting origination type
5228 ) IS
5229 l_exists VARCHAR2(7) := 'FALSE';
5230 v_temp VARCHAR2(50);
5231 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5232 l_stacked_messages VARCHAR2(1000);
5233 l_status_id NUMBER; --Added bug3853202
5234 l_status_enabled VARCHAR2(1); --Added bug3998321
5235 l_dest_status_enabled VARCHAR2(1); --Added bug4035918
5236 BEGIN
5237 x_return_status := fnd_api.g_ret_sts_success;
5238
5239 IF (l_debug = 1) THEN
5240 print_debug('Inside insert_dynamic_lot', 4);
5241 END IF;
5242
5243 IF inv_lot_api_pub.validate_unique_lot(
5244 p_org_id => p_organization_id
5245 , p_inventory_item_id => p_inventory_item_id
5246 , p_lot_uniqueness => NULL
5247 , p_auto_lot_number => p_lot_number
5248 ) THEN
5249 /*Added select for bug 3853202*/
5250
5251 IF p_transfer_organization_id IS NOT NULL THEN
5252 BEGIN
5253 SELECT STATUS_ID
5254 INTO l_status_id
5255 FROM MTL_LOT_NUMBERS
5256 WHERE LOT_NUMBER = p_lot_number
5257 AND ORGANIZATION_ID = p_transfer_organization_id
5258 AND INVENTORY_ITEM_ID = p_inventory_item_id;
5259
5260 SELECT lot_status_enabled --Added select for bug3998321
5261 INTO l_status_enabled
5262 FROM
5263 mtl_system_items
5264 WHERE
5265 inventory_item_id=p_inventory_item_id and
5266 organization_id=p_transfer_organization_id;
5267
5268 SELECT lot_status_enabled --Added select for bug4035918
5269 INTO l_dest_status_enabled
5270 FROM
5271 mtl_system_items
5272 WHERE
5273 inventory_item_id=p_inventory_item_id and
5274 organization_id=p_organization_id;
5275
5276 SELECT 'TRUE'
5277 INTO l_exists
5278 FROM mtl_lot_numbers
5279 WHERE lot_number = p_lot_number
5280 AND organization_id = p_organization_id
5281 AND inventory_item_id = p_inventory_item_id;
5282 EXCEPTION
5283 WHEN NO_DATA_FOUND THEN
5284 l_exists := 'FALSE';
5285 END;
5286 ELSE
5287 l_exists := 'FALSE';
5288 END IF;
5289
5290 IF l_status_id IS NULL THEN --Added bug 3853202
5291 l_status_id := p_status_id;
5292 END IF;
5293
5294 IF (l_debug = 1) THEN
5295 print_debug('Lot uniqueness passed so inserting lot:' || l_exists, 4);
5296 END IF;
5297
5298 inv_lot_api_pub.insertlot(
5299 p_api_version => p_api_version
5300 , p_init_msg_list => p_init_msg_list
5301 , p_commit => p_commit
5302 , p_validation_level => p_validation_level
5303 , p_inventory_item_id => p_inventory_item_id
5304 , p_organization_id => p_organization_id
5305 , p_lot_number => p_lot_number
5306 , p_expiration_date => p_expiration_date
5307 , p_transaction_temp_id => p_transaction_temp_id
5308 , p_transaction_action_id => p_transaction_action_id
5309 , p_transfer_organization_id => p_transfer_organization_id
5310 , x_object_id => x_object_id
5311 , x_return_status => x_return_status
5312 , x_msg_count => x_msg_count
5313 , x_msg_data => x_msg_data
5314 , p_parent_lot_number => p_parent_lot_number --bug 10176719 - inserting parent lot number
5315 , p_origination_type => p_origination_type --bug 15896641 - inserting origination type
5316 );
5317 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
5318 inv_mobile_helper_functions.get_stacked_messages(l_stacked_messages);
5319 IF (l_debug = 1) THEN
5320 print_debug('The following messege is removed: ' ||
5321 l_stacked_messages,1);
5322 END IF;
5323 x_msg_count := 0;
5324 x_msg_data := NULL;
5325 END IF;
5326
5327 /**************************************************************************
5328 As part of the Bug - 2181558, this code is commented out. The process of
5329 copying the lot attributes from the parent lot to the destination lot is
5330 carried out in the INV_LOT_API_PUB package.
5331
5332 -- bug 2180480
5333 IF p_transfer_organization_id IS NOT NULL AND
5334 l_exists = 'FALSE' THEN
5335 -- Can come here from the receiving UI only if it is an
5336 -- intransit shipment receipt or an internal req. receipt
5337 -- for a new lot number
5338 populatelotattributes(x_return_status => x_return_status,
5339 p_lot_number => p_lot_number,
5340 p_organization_id => p_organization_id,
5341 p_from_organization_id => p_transfer_organization_id,
5342 p_inventory_item_id => p_inventory_item_id,
5343 p_exists => l_exists);
5344 END IF;
5345 ***************************************************************************/
5346 ELSE
5347 IF (l_debug = 1) THEN
5348 print_debug('Lot uniqueness did not pass so not inserting lot', 4);
5349 END IF;
5350
5351 x_return_status := fnd_api.g_ret_sts_unexp_error;
5352 fnd_message.set_name('INV', 'LOT_UNIQUENESS_VIOLATED');
5353 fnd_msg_pub.ADD;
5354 RAISE fnd_api.g_exc_error;
5355 RETURN;
5356 END IF;
5357
5358 IF (((x_return_status = fnd_api.g_ret_sts_success)
5359 AND(p_update_status = 'TRUE'))
5360 OR (p_transfer_organization_id IS NOT NULL AND
5361 l_exists = 'FALSE' AND l_status_enabled = 'Y' AND l_dest_status_enabled = 'Y')) THEN --Added OR condition for bug 3853202, Added l_status_enabled bug3998321
5362 --Added l_dest_status_enabled = 'Y' bug4035918
5363 inv_material_status_grp.update_status(
5364 p_api_version_number => p_api_version
5365 , p_init_msg_lst => NULL
5366 , x_return_status => x_return_status
5367 , x_msg_count => x_msg_count
5368 , x_msg_data => x_msg_data
5369 , p_update_method => inv_material_status_pub.g_update_method_receive
5370 , p_status_id => l_status_id --Changed from p_status_id bug3853202
5371 , p_organization_id => p_organization_id
5372 , p_inventory_item_id => p_inventory_item_id
5373 , p_sub_code => NULL
5374 , p_locator_id => NULL
5375 , p_lot_number => p_lot_number
5376 , p_serial_number => NULL
5377 , p_to_serial_number => NULL
5378 , p_object_type => 'O'
5379 );
5380 END IF;
5381 END insert_dynamic_lot;
5382
5383 -- This is a wrapper to call inventory insert_range_serial
5384 PROCEDURE insert_range_serial(
5385 p_api_version IN NUMBER
5386 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5387 , p_commit IN VARCHAR2 := fnd_api.g_false
5388 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
5389 , p_inventory_item_id IN NUMBER
5390 , p_organization_id IN NUMBER
5391 , p_from_serial_number IN VARCHAR2
5392 , p_to_serial_number IN VARCHAR2
5393 , p_revision IN VARCHAR2
5394 , p_lot_number IN VARCHAR2
5395 , p_primary_lot_quantity IN NUMBER
5396 , p_transaction_action_id IN NUMBER
5397 , p_current_status IN NUMBER
5398 , p_serial_status_id IN NUMBER
5399 , p_update_serial_status IN VARCHAR2
5400 , p_inspection_required IN NUMBER DEFAULT NULL
5401 , p_hdr_id IN NUMBER
5402 , p_from_lpn_id IN NUMBER
5403 , p_to_lpn_id IN NUMBER
5404 , p_primary_uom_code IN VARCHAR2
5405 , p_call_pack_unpack IN VARCHAR2
5406 , x_return_status OUT NOCOPY VARCHAR2
5407 , x_msg_count OUT NOCOPY NUMBER
5408 , x_msg_data OUT NOCOPY VARCHAR2
5409 , p_subinventory IN VARCHAR2 DEFAULT NULL
5410 , p_locator_id IN NUMBER DEFAULT NULL
5411 ) IS
5412 l_object_id NUMBER;
5413 l_success NUMBER;
5414 l_temp_var NUMBER;
5415 l_progress VARCHAR2(10);
5416 l_serial_packed_in_other_lpn NUMBER;
5417 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5418 l_inv_po_j_higher BOOLEAN := FALSE;
5419 l_rcv_serial_flag VARCHAR2(1) := 'N';
5420 BEGIN
5421 IF (l_debug = 1) THEN
5422 print_debug('Enter insert_range_serial: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5423 END IF;
5424
5425 x_return_status := fnd_api.g_ret_sts_success;
5426 l_progress := '10';
5427 SAVEPOINT rcv_insert_range_serial_sp;
5428
5429 -- Reported by Toshiba Issue where same Serials were getting processed
5430 -- Sanity Check to ensure if the Serials are not Yet Received/Packed into a different
5431 -- LPN i,e other than the Transaction LPN.
5432 -- LPN context 7 is added for receioving ASN's
5433 -- Added inventory_item_id check in the below sql because same serial might exist
5434 -- for two diff items.
5435 /* FP-J Lot/Serial Support Enhancement - Check for status of Resides in Receiving (7) also */
5436 SELECT COUNT(1)
5437 INTO l_serial_packed_in_other_lpn
5438 FROM mtl_serial_numbers msn
5439 WHERE msn.current_status IN (5, 7)
5440 AND EXISTS(SELECT 'x'
5441 FROM wms_license_plate_numbers wlpn
5442 WHERE wlpn.lpn_context NOT IN(5, 6, 7)
5443 AND wlpn.lpn_id = msn.lpn_id)
5444 AND msn.lpn_id IS NOT NULL
5445 AND msn.serial_number BETWEEN p_from_serial_number AND p_to_serial_number
5446 AND Length(msn.serial_number) = Length(p_from_serial_number)
5447 AND Length(p_from_serial_number) = Length(Nvl(p_to_serial_number,p_from_serial_number))
5448 AND msn.inventory_item_id = p_inventory_item_id
5449 AND ROWNUM = 1;
5450
5451 IF l_serial_packed_in_other_lpn >= 1 THEN
5452 IF (l_debug = 1) THEN
5453 print_debug('Insert_range_serial: Serial Number already Packed/Received with a Diff LPN '
5454 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5455 , 1);
5456 END IF;
5457
5458 fnd_message.set_name('INV', 'INV_DUPLICATE_SERIAL');
5459 fnd_msg_pub.ADD;
5460 fnd_message.set_name('INV', 'INV_FAIL_VALIDATE_SERIAL');
5461 fnd_msg_pub.ADD;
5462 RAISE fnd_api.g_exc_error;
5463 END IF;
5464
5465 l_progress := '20';
5466
5467 /* FP-J Lot/Serial Support Enhancement -
5468 * Get the patch levels for INV and PO. If they are J or higher, we do not
5469 * want to update certain columns like lpn_id, inspection_status,
5470 * subinventory, locator etc. for the serial number.
5471 * So have declared a new flag p_rcv_serial_flag which should be passed as Y
5472 * to skip the updates to the serial
5473 * If either INV or PO J is not installed, then this flag would be set to
5474 * the value 'N' so that the updates continue as usual.
5475 */
5476 IF ((inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j) OR
5477 (inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po)) THEN
5478 l_inv_po_j_higher := FALSE;
5479 l_rcv_serial_flag := 'N';
5480 ELSE
5481 l_inv_po_j_higher := TRUE;
5482 l_rcv_serial_flag := 'Y';
5483 END IF;
5484
5485 inv_serial_number_pub.insert_range_serial(
5486 p_api_version => p_api_version
5487 , p_init_msg_list => p_init_msg_list
5488 , p_commit => p_commit
5489 , p_validation_level => p_validation_level
5490 , p_inventory_item_id => p_inventory_item_id
5491 , p_organization_id => p_organization_id
5492 , p_from_serial_number => p_from_serial_number
5493 , p_to_serial_number => p_to_serial_number
5494 , p_initialization_date => SYSDATE
5495 , p_completion_date => NULL
5496 , p_ship_date => NULL
5497 , p_revision => p_revision
5498 , p_lot_number => p_lot_number
5499 , p_current_locator_id => NULL
5500 , p_subinventory_code => NULL
5501 , p_trx_src_id => NULL
5502 , p_unit_vendor_id => NULL
5503 , p_vendor_lot_number => NULL
5504 , p_vendor_serial_number => NULL
5505 , p_receipt_issue_type => NULL
5506 , p_txn_src_id => NULL
5507 , p_txn_src_name => NULL
5508 , p_txn_src_type_id => NULL
5509 , p_transaction_id => NULL
5510 , p_current_status => p_current_status
5511 , p_parent_item_id => NULL
5512 , p_parent_serial_number => NULL
5513 , p_cost_group_id => NULL
5514 , p_transaction_action_id => p_transaction_action_id
5515 , p_transaction_temp_id => NULL
5516 , p_status_id => NULL
5517 , p_inspection_status => p_inspection_required
5518 , x_object_id => l_object_id
5519 , x_return_status => x_return_status
5520 , x_msg_count => x_msg_count
5521 , x_msg_data => x_msg_data
5522 , p_rcv_serial_flag => l_rcv_serial_flag
5523 );
5524
5525 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5526 fnd_message.set_name('INV', 'INV_LOT_COMMIT_FAILURE');
5527 fnd_msg_pub.ADD;
5528 RAISE fnd_api.g_exc_error;
5529 END IF;
5530
5531 l_progress := '30';
5532
5533 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5534 RAISE fnd_api.g_exc_error;
5535 END IF;
5536
5537 /* FP-J Lot/Serial Support Enhancement
5538 * If INV and PO patchset levels are "J" or higher, then do not call packunpact
5539 * from UI since it would be handled by the receiving TM.
5540 * Similarly, need not mark the serials since it would be done in the insert_msni
5541 * API upon creating the MSNI interface records
5542 */
5543 IF (l_inv_po_j_higher = FALSE) THEN
5544
5545 IF p_update_serial_status = 'TRUE' THEN
5546 l_progress := '40';
5547 inv_material_status_grp.update_status(
5548 p_api_version_number => p_api_version
5549 , p_init_msg_lst => NULL
5550 , x_return_status => x_return_status
5551 , x_msg_count => x_msg_count
5552 , x_msg_data => x_msg_data
5553 , p_update_method => inv_material_status_pub.g_update_method_receive
5554 , p_status_id => p_serial_status_id
5555 , p_organization_id => p_organization_id
5556 , p_inventory_item_id => p_inventory_item_id
5557 , p_sub_code => NULL
5558 , p_locator_id => NULL
5559 , p_lot_number => p_lot_number
5560 , p_serial_number => p_from_serial_number
5561 , p_to_serial_number => p_to_serial_number
5562 , p_object_type => 'S'
5563 );
5564 END IF;
5565
5566 l_progress := '50';
5567 serial_check.inv_mark_serial(
5568 from_serial_number => p_from_serial_number
5569 , to_serial_number => p_to_serial_number
5570 , item_id => p_inventory_item_id
5571 , org_id => p_organization_id
5572 , hdr_id => p_hdr_id
5573 , temp_id => NULL
5574 , lot_temp_id => NULL
5575 , success => l_success
5576 );
5577 l_progress := '60';
5578
5579 IF p_call_pack_unpack = 'TRUE' THEN
5580 l_progress := '70';
5581 inv_rcv_std_rcpt_apis.packunpack_container(
5582 p_api_version => p_api_version
5583 , p_init_msg_list => p_init_msg_list
5584 , p_commit => p_commit
5585 , x_return_status => x_return_status
5586 , x_msg_count => x_msg_count
5587 , x_msg_data => x_msg_data
5588 , p_from_lpn_id => p_from_lpn_id
5589 , p_lpn_id => p_to_lpn_id
5590 , p_content_item_id => p_inventory_item_id
5591 , p_revision => p_revision
5592 , p_lot_number => p_lot_number
5593 , p_from_serial_number => p_from_serial_number
5594 , p_to_serial_number => p_to_serial_number
5595 , p_uom => p_primary_uom_code
5596 , p_quantity => p_primary_lot_quantity
5597 , p_organization_id => p_organization_id
5598 , p_subinventory => p_subinventory
5599 , p_locator_id => p_locator_id
5600 , p_operation => '1'
5601 );
5602 END IF;
5603
5604 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5605 fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL');
5606 fnd_msg_pub.ADD;
5607 RAISE fnd_api.g_exc_error;
5608 END IF;
5609 ELSE
5610 print_debug('insert_range_serial: INV and PO patchset levels are J or higher. No packunpack from UI. No marking from here', 4);
5611 END IF; --END IF check INV and PO patch levels
5612
5613 l_progress := '80';
5614
5615 IF (l_debug = 1) THEN
5616 print_debug('Exit insert_range_serial 90:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5617 END IF;
5618 EXCEPTION
5619 WHEN fnd_api.g_exc_error THEN
5620 ROLLBACK TO rcv_insert_range_serial_sp;
5621 x_return_status := fnd_api.g_ret_sts_error;
5622
5623 IF (l_debug = 1) THEN
5624 print_debug('Exitting insert_range_serial - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5625 END IF;
5626
5627 -- Get message count and data
5628 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5629 WHEN fnd_api.g_exc_unexpected_error THEN
5630 ROLLBACK TO rcv_insert_range_serial_sp;
5631
5632 IF (l_debug = 1) THEN
5633 print_debug('Exitting insert_range_serial - unexpected error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5634 END IF;
5635
5636 x_return_status := fnd_api.g_ret_sts_unexp_error;
5637 -- Get message count and data
5638 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5639 WHEN OTHERS THEN
5640 ROLLBACK TO rcv_insert_range_serial_sp;
5641
5642 IF (l_debug = 1) THEN
5643 print_debug('Exitting insert_range_serial - other exceptions:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5644 END IF;
5645
5646 x_return_status := fnd_api.g_ret_sts_unexp_error;
5647
5648 IF SQLCODE IS NOT NULL THEN
5649 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.insert_range_serial', l_progress, SQLCODE);
5650 END IF;
5651
5652 --
5653 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
5654 fnd_msg_pub.add_exc_msg(g_pkg_name, 'insert_range_serial');
5655 END IF;
5656
5657 -- Get message count and data
5658 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5659 END;
5660
5661 PROCEDURE update_serial_status(
5662 p_api_version IN NUMBER
5663 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5664 , p_commit IN VARCHAR2 := fnd_api.g_false
5665 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
5666 , p_inventory_item_id IN NUMBER
5667 , p_organization_id IN NUMBER
5668 , p_from_serial_number IN VARCHAR2
5669 , p_to_serial_number IN VARCHAR2
5670 , p_current_status IN NUMBER
5671 , p_serial_status_id IN NUMBER
5672 , p_update_serial_status IN VARCHAR2
5673 , p_lot_number IN VARCHAR2
5674 , p_primary_lot_quantity IN NUMBER
5675 , p_inspection_required IN NUMBER
5676 , p_hdr_id IN NUMBER
5677 , p_from_lpn_id IN NUMBER
5678 , p_to_lpn_id IN NUMBER
5679 , p_revision IN VARCHAR2
5680 , p_primary_uom_code IN VARCHAR2
5681 , p_call_pack_unpack IN VARCHAR2
5682 , x_return_status OUT NOCOPY VARCHAR2
5683 , x_msg_count OUT NOCOPY NUMBER
5684 , x_msg_data OUT NOCOPY VARCHAR2
5685 , p_subinventory IN VARCHAR2 DEFAULT NULL
5686 , p_locator_id IN NUMBER DEFAULT NULL
5687 , p_txn_src_id IN VARCHAR2 DEFAULT NULL
5688 ) IS
5689 l_from_ser_number NUMBER;
5690 l_to_ser_number NUMBER;
5691 l_range_numbers NUMBER;
5692 l_temp_prefix VARCHAR2(30);
5693 l_cur_serial_number VARCHAR2(30);
5694 l_cur_ser_number NUMBER;
5695 l_success NUMBER;
5696 l_serial_num_length NUMBER;
5697 l_prefix_length NUMBER;
5698 l_num_suffix VARCHAR2(30);
5699 l_progress VARCHAR2(10);
5700 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5701 l_restrict_rcpt_ser VARCHAR2(1) := NVL(fnd_profile.VALUE('INV_RESTRICT_RCPT_SER'), '0');
5702 l_serial_control_code VARCHAR2(10);
5703 l_txn_cnt VARCHAR2(10);
5704 BEGIN
5705 IF (l_debug = 1) THEN
5706 print_debug('Enter update_serial_status: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5707 END IF;
5708
5709 l_progress := '10';
5710 x_return_status := fnd_api.g_ret_sts_success;
5711 SAVEPOINT rcv_update_serial_sp;
5712 l_progress := '20';
5713
5714 --
5715 -- For RMA's and Serial Control at SALES ORDER ISSUE don't allow the same Serial to be re-received
5716 -- when the serial status is 1 and it is already received once
5717 -- Similar Bug 2685220
5718 --
5719
5720 IF (p_txn_src_id = '12'
5721 AND l_restrict_rcpt_ser = '1') THEN
5722 IF (l_debug = 1) THEN
5723 print_debug('Update Serial Status : RMA and restrict rcpt ser is Set', 1);
5724 END IF;
5725
5726 get_serial_ctrl(x_return_status, l_serial_control_code, p_organization_id, p_inventory_item_id);
5727
5728 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5729 IF (l_debug = 1) THEN
5730 print_debug('Update Serial Status : Failed in getting serial control code ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5731 END IF;
5732
5733 fnd_message.set_name('INV', 'INV_FAIL_VALIDATE_SERIAL');
5734 fnd_msg_pub.ADD;
5735 RAISE fnd_api.g_exc_error;
5736 END IF;
5737
5738 IF l_serial_control_code = '6' THEN
5739 IF (l_debug = 1) THEN
5740 print_debug('Update Serial Status : Before Duplicate Serial Check , RMA and Serial Ctrl as SALES ISSUE', 1);
5741 END IF;
5742
5743 BEGIN
5744 SELECT '1'
5745 INTO l_txn_cnt
5746 FROM DUAL
5747 WHERE EXISTS(
5748 SELECT '1'
5749 FROM mtl_serial_numbers
5750 WHERE inventory_item_id = p_inventory_item_id
5751 AND current_organization_id = p_organization_id
5752 AND current_status = 1
5753 AND serial_number BETWEEN p_from_serial_number AND p_to_serial_number
5754 AND Length(serial_number) = Length(p_from_serial_number)
5755 AND Length(p_from_serial_number) = Length(Nvl(p_to_serial_number, p_from_serial_number))
5756 AND last_txn_source_type_id = 12);
5757
5758 IF l_txn_cnt > 0 THEN
5759 IF (l_debug = 1) THEN
5760 print_debug('Update_serial_status: After Duplicate Serial Check , RMA and Serial Ctrl as SALES ISSUE Failed Here', 1);
5761 END IF;
5762
5763 fnd_message.set_name('INV', 'INV_FAIL_VALIDATE_SERIAL');
5764 fnd_msg_pub.ADD;
5765 RAISE fnd_api.g_exc_error;
5766 END IF;
5767 EXCEPTION
5768 WHEN NO_DATA_FOUND THEN
5769 NULL;
5770 END;
5771 END IF;
5772 END IF;
5773
5774 -- get the number part of the to serial
5775 inv_validate.number_from_sequence(p_to_serial_number, l_temp_prefix, l_to_ser_number);
5776 l_progress := '30';
5777 -- get the number part of the from serial
5778 inv_validate.number_from_sequence(p_from_serial_number, l_temp_prefix, l_from_ser_number);
5779 l_progress := '40';
5780 -- total number of serials inserted into mtl_serial_numbers
5781 l_range_numbers := l_to_ser_number - l_from_ser_number + 1;
5782 l_serial_num_length := LENGTH(p_from_serial_number);
5783 l_prefix_length := LENGTH(l_temp_prefix);
5784
5785 FOR i IN 1 .. l_range_numbers LOOP
5786 l_cur_ser_number := l_from_ser_number + i - 1;
5787 -- concatenate the serial number to be inserted
5788 l_cur_serial_number := l_temp_prefix || LPAD(l_cur_ser_number, l_serial_num_length - NVL(l_prefix_length, 0), '0');
5789 l_progress := '50';
5790
5791 /* FP-J Lot/Serial Support Enhancement
5792 * If INV and PO patchset levels are "J" or higher, then do not call update statis
5793 * from UI since it would be handled by the receiving TM.
5794 */
5795 IF ((inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j) OR
5796 (inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po)) THEN
5797 UPDATE mtl_serial_numbers
5798 SET previous_status = current_status
5799 , current_status = p_current_status
5800 , inspection_status = p_inspection_required
5801 , lot_number = p_lot_number
5802 , revision = p_revision
5803 , current_organization_id = p_organization_id
5804 WHERE serial_number = l_cur_serial_number
5805 AND inventory_item_id = p_inventory_item_id;
5806 ELSE
5807 print_debug('update_serial_status: INV and PO patchset levels are J or higher.', 4);
5808 print_debug('update_serial_status: Updating revision lot_number if serial code of the item is predefined and current status is defined but not used', 4);
5809 UPDATE mtl_serial_numbers
5810 SET lot_number = p_lot_number
5811 , revision = p_revision
5812 WHERE serial_number = l_cur_serial_number
5813 AND inventory_item_id = p_inventory_item_id
5814 AND current_status IN (1, 4, 5, 6);
5815 END IF; --END IF check INV and PO patch levels
5816
5817 l_progress := '60';
5818
5819 IF p_update_serial_status = 'TRUE' THEN
5820 l_progress := '70';
5821 inv_material_status_grp.update_status(
5822 p_api_version_number => p_api_version
5823 , p_init_msg_lst => NULL
5824 , x_return_status => x_return_status
5825 , x_msg_count => x_msg_count
5826 , x_msg_data => x_msg_data
5827 , p_update_method => inv_material_status_pub.g_update_method_receive
5828 , p_status_id => p_serial_status_id
5829 , p_organization_id => p_organization_id
5830 , p_inventory_item_id => p_inventory_item_id
5831 , p_sub_code => NULL
5832 , p_locator_id => NULL
5833 , p_lot_number => p_lot_number
5834 , p_serial_number => l_cur_serial_number
5835 , p_to_serial_number => NULL
5836 , p_object_type => 'S'
5837 );
5838 END IF;
5839
5840 l_progress := '80';
5841
5842 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5843 RAISE fnd_api.g_exc_error;
5844 END IF;
5845 END LOOP;
5846
5847 l_progress := '90';
5848
5849 /* FP-J Lot/Serial Support Enhancement
5850 * If INV and PO patchset levels are "J" or higher, then do not call packunpact
5851 * from UI since it would be handled by the receiving TM.
5852 * Similarly, need not mark the serials since it would be done in the insert_msni
5853 * API upon creating the MSNI interface records
5854 */
5855 IF ((inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j) OR
5856 (inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po)) THEN
5857 serial_check.inv_mark_serial(
5858 from_serial_number => p_from_serial_number
5859 , to_serial_number => p_to_serial_number
5860 , item_id => p_inventory_item_id
5861 , org_id => p_organization_id
5862 , hdr_id => p_hdr_id
5863 , temp_id => NULL
5864 , lot_temp_id => NULL
5865 , success => l_success
5866 );
5867 l_progress := '100';
5868
5869 IF p_call_pack_unpack = 'TRUE' THEN
5870 l_progress := '110';
5871 inv_rcv_std_rcpt_apis.packunpack_container(
5872 p_api_version => p_api_version
5873 , p_init_msg_list => p_init_msg_list
5874 , p_commit => p_commit
5875 , x_return_status => x_return_status
5876 , x_msg_count => x_msg_count
5877 , x_msg_data => x_msg_data
5878 , p_from_lpn_id => p_from_lpn_id
5879 , p_lpn_id => p_to_lpn_id
5880 , p_content_item_id => p_inventory_item_id
5881 , p_revision => p_revision
5882 , p_lot_number => p_lot_number
5883 , p_from_serial_number => p_from_serial_number
5884 , p_to_serial_number => p_to_serial_number
5885 , p_uom => p_primary_uom_code
5886 , p_quantity => p_primary_lot_quantity
5887 , p_organization_id => p_organization_id
5888 , p_subinventory => p_subinventory
5889 , p_locator_id => p_locator_id
5890 , p_operation => '1'
5891 );
5892 END IF;
5893
5894 l_progress := '120';
5895
5896 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5897 fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL');
5898 fnd_msg_pub.ADD;
5899 RAISE fnd_api.g_exc_error;
5900 END IF;
5901 ELSE
5902 print_debug('update_serial_status: INV and PO patchset levels are J or higher. No packunpack from UI. No marking from here', 4);
5903 END IF; --END IF check INV and PO patch levels
5904
5905 l_progress := '130';
5906
5907 IF (l_debug = 1) THEN
5908 print_debug('Exit update_serial_status 140:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5909 END IF;
5910 EXCEPTION
5911 WHEN fnd_api.g_exc_error THEN
5912 ROLLBACK TO rcv_update_serial_sp;
5913 x_return_status := fnd_api.g_ret_sts_error;
5914
5915 IF (l_debug = 1) THEN
5916 print_debug('Exitting update_serial_status - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5917 END IF;
5918
5919 -- Get message count and data
5920 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5921 WHEN fnd_api.g_exc_unexpected_error THEN
5922 ROLLBACK TO rcv_update_serial_sp;
5923 x_return_status := fnd_api.g_ret_sts_unexp_error;
5924
5925 IF (l_debug = 1) THEN
5926 print_debug('Exitting update_serial_status - unexpected error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5927 END IF;
5928
5929 -- Get message count and data
5930 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5931 WHEN OTHERS THEN
5932 ROLLBACK TO rcv_update_serial_sp;
5933 x_return_status := fnd_api.g_ret_sts_unexp_error;
5934
5935 IF (l_debug = 1) THEN
5936 print_debug('Exitting update_serial_status - other exceptions:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5937 END IF;
5938
5939 IF SQLCODE IS NOT NULL THEN
5940 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.update_serial_status', l_progress, SQLCODE);
5941 END IF;
5942
5943 --
5944 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
5945 fnd_msg_pub.add_exc_msg(g_pkg_name, 'update_serial_status');
5946 END IF;
5947
5948 -- Get message count and data
5949 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5950 END update_serial_status;
5951
5952 PROCEDURE process_lot(
5953 p_api_version IN NUMBER
5954 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
5955 , p_commit IN VARCHAR2 := fnd_api.g_false
5956 , p_validation_level IN NUMBER := fnd_api.g_valid_level_full
5957 , p_inventory_item_id IN NUMBER
5958 , p_organization_id IN NUMBER
5959 , p_lot_number IN VARCHAR2
5960 , p_expiration_date IN OUT NOCOPY DATE
5961 , p_transaction_temp_id IN NUMBER DEFAULT NULL
5962 , p_transaction_action_id IN NUMBER DEFAULT NULL
5963 , p_transfer_organization_id IN NUMBER DEFAULT NULL
5964 , p_status_id IN NUMBER
5965 , p_update_status IN VARCHAR2 := 'FALSE'
5966 , p_is_new_lot IN VARCHAR2 := 'TRUE'
5967 , p_call_pack_unpack IN VARCHAR2 := 'FALSE'
5968 , p_from_lpn_id IN NUMBER
5969 , p_to_lpn_id IN NUMBER
5970 , p_revision IN VARCHAR2
5971 , p_lot_primary_qty IN NUMBER
5972 , p_primary_uom_code IN VARCHAR2
5973 , p_transaction_uom_code IN VARCHAR2 DEFAULT NULL
5974 , x_object_id OUT NOCOPY NUMBER
5975 , x_return_status OUT NOCOPY VARCHAR2
5976 , x_msg_count OUT NOCOPY NUMBER
5977 , x_msg_data OUT NOCOPY VARCHAR2
5978 , p_subinventory IN VARCHAR2 DEFAULT NULL
5979 , p_locator_id IN NUMBER DEFAULT NULL
5980 , p_lot_secondary_qty IN NUMBER --OPM Convergence
5981 , p_secondary_uom_code IN VARCHAR2 --OPM Convergence
5982 , p_parent_lot_number IN VARCHAR2 DEFAULT NULL --bug 10176719 - inserting parent lot number
5983 , p_origination_type IN NUMBER DEFAULT NULL --bug 15896641 - inserting origination type
5984 ) IS
5985 l_progress VARCHAR2(10);
5986 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5987 BEGIN
5988 IF (l_debug = 1) THEN
5989 print_debug('Enter process_lot: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5990 print_debug('Organization ID = ' || TO_CHAR(p_organization_id), 1);
5991 print_debug('To Organization ID = ' || TO_CHAR(p_transfer_organization_id), 1);
5992 print_debug('transaction_temp_id = ' || TO_CHAR(p_transaction_temp_id), 1);
5993 print_debug('Lot Number = ' || p_lot_number, 1);
5994 print_debug('Item ID = ' || TO_CHAR(p_inventory_item_id), 1);
5995 print_debug('origination type = ' || TO_CHAR(p_origination_type), 1);
5996 END IF;
5997
5998 x_return_status := fnd_api.g_ret_sts_success;
5999 l_progress := '10';
6000 SAVEPOINT rcv_process_lot_sp;
6001 inv_rcv_std_rcpt_apis.populate_lot_rec(
6002 p_lot_number => p_lot_number
6003 , p_primary_qty => p_lot_primary_qty
6004 , p_txn_uom_code => p_transaction_uom_code
6005 , p_org_id => p_organization_id
6006 , p_item_id => p_inventory_item_id
6007 , p_secondary_quantity => p_lot_secondary_qty --OPM Convergence
6008 );
6009 l_progress := '20';
6010
6011 IF p_is_new_lot = 'TRUE' THEN
6012 l_progress := '30';
6013 insert_dynamic_lot(
6014 p_api_version => p_api_version
6015 , p_init_msg_list => p_init_msg_list
6016 , p_commit => p_commit
6017 , p_validation_level => p_validation_level
6018 , p_inventory_item_id => p_inventory_item_id
6019 , p_organization_id => p_organization_id
6020 , p_lot_number => p_lot_number
6021 , p_expiration_date => p_expiration_date
6022 , p_transaction_temp_id => p_transaction_temp_id
6023 , p_transaction_action_id => p_transaction_action_id
6024 , p_transfer_organization_id => p_transfer_organization_id
6025 , p_status_id => p_status_id
6026 , p_update_status => p_update_status
6027 , x_object_id => x_object_id
6028 , x_return_status => x_return_status
6029 , x_msg_count => x_msg_count
6030 , x_msg_data => x_msg_data
6031 , p_parent_lot_number => p_parent_lot_number -- bug 10176719 - inserting parent lot number
6032 , p_origination_type => p_origination_type -- bug 15896641 - inserting origination type
6033 );
6034 END IF;
6035
6036 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6037 fnd_message.set_name('INV', 'INV_LOT_COMMIT_FAILURE');
6038 fnd_msg_pub.ADD;
6039 RAISE fnd_api.g_exc_error;
6040 END IF;
6041
6042 l_progress := '40';
6043
6044 /* FP-J Lot/Serial Support Enhancement
6045 * If INV and PO patchset levels are "J" or higher, then do not call packunpact
6046 * from UI since it would be handled by the receiving TM.
6047 */
6048 IF ((inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j) OR
6049 (inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po)) THEN
6050 IF p_call_pack_unpack = 'TRUE' THEN
6051 l_progress := '50';
6052 inv_rcv_std_rcpt_apis.packunpack_container(
6053 p_api_version => p_api_version
6054 , p_init_msg_list => p_init_msg_list
6055 , p_commit => p_commit
6056 , x_return_status => x_return_status
6057 , x_msg_count => x_msg_count
6058 , x_msg_data => x_msg_data
6059 , p_from_lpn_id => p_from_lpn_id
6060 , p_lpn_id => p_to_lpn_id
6061 , p_content_item_id => p_inventory_item_id
6062 , p_revision => p_revision
6063 , p_lot_number => p_lot_number
6064 , p_quantity => p_lot_primary_qty
6065 , p_uom => p_primary_uom_code
6066 , p_organization_id => p_organization_id
6067 , p_subinventory => p_subinventory
6068 , p_locator_id => p_locator_id
6069 , p_operation => '1'
6070 );
6071 END IF;
6072 ELSE
6073 print_debug('process_lot: INV and PO patchset levels are J or higher. No packunpack from UI. ', 4);
6074 END IF; --END IF check INV and PO patch levels
6075
6076 l_progress := '60';
6077
6078 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6079 fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL');
6080 fnd_msg_pub.ADD;
6081 RAISE fnd_api.g_exc_error;
6082 END IF;
6083
6084 IF (l_debug = 1) THEN
6085 print_debug('Exit process_lot 70:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6086 END IF;
6087 EXCEPTION
6088 WHEN fnd_api.g_exc_error THEN
6089 ROLLBACK TO rcv_process_lot_sp;
6090 x_return_status := fnd_api.g_ret_sts_error;
6091
6092 IF (l_debug = 1) THEN
6093 print_debug('Exitting process_lot - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6094 END IF;
6095
6096 -- Get message count and data
6097 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6098 WHEN fnd_api.g_exc_unexpected_error THEN
6099 ROLLBACK TO rcv_process_lot_sp;
6100 x_return_status := fnd_api.g_ret_sts_unexp_error;
6101
6102 IF (l_debug = 1) THEN
6103 print_debug('Exitting process_lot - unexpected error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6104 END IF;
6105
6106 -- Get message count and data
6107 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6108 WHEN OTHERS THEN
6109 ROLLBACK TO rcv_process_lot_sp;
6110 x_return_status := fnd_api.g_ret_sts_unexp_error;
6111
6112 IF (l_debug = 1) THEN
6113 print_debug('Exitting process_lot - other exceptions:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6114 END IF;
6115
6116 IF SQLCODE IS NOT NULL THEN
6117 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.process_lot', l_progress, SQLCODE);
6118 END IF;
6119
6120 --
6121 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6122 fnd_msg_pub.add_exc_msg(g_pkg_name, 'process_lot');
6123 END IF;
6124
6125 -- Get message count and data
6126 fnd_msg_pub.count_and_get(
6127 p_encoded => fnd_api.g_false,
6128 p_count => x_msg_count,
6129 p_data => x_msg_data);
6130 END process_lot;
6131
6132 PROCEDURE gen_txn_group_id IS
6133 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6134 BEGIN
6135 IF g_rcv_global_var.interface_group_id IS NULL THEN
6136 SELECT rcv_interface_groups_s.NEXTVAL
6137 INTO g_rcv_global_var.interface_group_id
6138 FROM DUAL;
6139 END IF;
6140 END gen_txn_group_id;
6141
6142 PROCEDURE validate_trx_date(
6143 p_trx_date IN DATE
6144 , p_organization_id IN NUMBER
6145 , p_sob_id IN NUMBER
6146 , x_return_status OUT NOCOPY VARCHAR2
6147 , x_error_code OUT NOCOPY VARCHAR2
6148 ) IS
6149 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6150 BEGIN
6151 x_return_status := fnd_api.g_ret_sts_success;
6152
6153 IF (p_trx_date > SYSDATE) THEN
6154 x_return_status := fnd_api.g_ret_sts_error;
6155 fnd_message.set_name('PO', 'RCV_TRX_FUTURE_DATE_NA');
6156 fnd_msg_pub.ADD;
6157 RETURN;
6158 END IF;
6159
6160 BEGIN
6161 IF NOT(po_dates_s.val_open_period(p_trx_date, p_sob_id, 'SQLGL', p_organization_id)) THEN
6162 x_return_status := fnd_api.g_ret_sts_error;
6163 fnd_message.set_name('PO', 'PO_PO_ENTER_OPEN_GL_DATE');
6164 fnd_msg_pub.ADD;
6165 RETURN;
6166 END IF;
6167
6168 IF NOT(po_dates_s.val_open_period(p_trx_date, p_sob_id, 'PO', p_organization_id)) THEN
6169 x_return_status := fnd_api.g_ret_sts_error;
6170 fnd_message.set_name('PO', 'PO_PO_ENTER_OPEN_GL_DATE');
6171 fnd_msg_pub.ADD;
6172 RETURN;
6173 END IF;
6174 EXCEPTION
6175 WHEN OTHERS THEN
6176 x_return_status := fnd_api.g_ret_sts_error;
6177
6178 IF SQLCODE IS NOT NULL THEN
6179 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.validate_trx_date', '10', SQLCODE);
6180 END IF;
6181
6182 fnd_message.set_name('PO', 'PO_PO_ENTER_OPEN_GL_DATE');
6183 fnd_msg_pub.ADD;
6184 RETURN;
6185 END;
6186
6187 BEGIN
6188 IF NOT(po_dates_s.val_open_period(p_trx_date, p_sob_id, 'INV', p_organization_id)) THEN
6189 x_return_status := fnd_api.g_ret_sts_error;
6190 fnd_message.set_name('PO', 'PO_INV_NO_OPEN_PERIOD');
6191 fnd_msg_pub.ADD;
6192 RETURN;
6193 END IF;
6194 EXCEPTION
6195 WHEN OTHERS THEN
6196 x_return_status := fnd_api.g_ret_sts_error;
6197
6198 IF SQLCODE IS NOT NULL THEN
6199 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.validate_trx_date', '20', SQLCODE);
6200 END IF;
6201
6202 fnd_message.set_name('PO', 'PO_INV_NO_OPEN_PERIOD');
6203 fnd_msg_pub.ADD;
6204 RETURN;
6205 END;
6206 END validate_trx_date;
6207
6208 -- Bug 2086271
6209 PROCEDURE get_req_shipment_header_id(
6210 x_shipment_header_id OUT NOCOPY NUMBER
6211 , x_return_status OUT NOCOPY VARCHAR2
6212 , x_msg_count OUT NOCOPY NUMBER
6213 , x_msg_data OUT NOCOPY VARCHAR2
6214 , p_organization_id IN NUMBER
6215 , p_requiition_header_id IN NUMBER
6216 , p_item_id IN NUMBER
6217 , p_rcv_txn_type IN VARCHAR2
6218 , p_lpn_id IN NUMBER DEFAULT NULL
6219 ) IS
6220 l_from_org_id NUMBER;
6221 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6222 BEGIN
6223 get_req_shipment_header_id(
6224 x_shipment_header_id => x_shipment_header_id
6225 , x_from_org_id => l_from_org_id
6226 , x_return_status => x_return_status
6227 , x_msg_count => x_msg_count
6228 , x_msg_data => x_msg_data
6229 , p_organization_id => p_organization_id
6230 , p_requiition_header_id => p_requiition_header_id
6231 , p_item_id => p_item_id
6232 , p_rcv_txn_type => p_rcv_txn_type
6233 , p_lpn_id => p_lpn_id
6234 );
6235 END get_req_shipment_header_id;
6236
6237 PROCEDURE get_req_shipment_header_id(
6238 x_shipment_header_id OUT NOCOPY NUMBER
6239 , x_from_org_id OUT NOCOPY NUMBER
6240 , x_return_status OUT NOCOPY VARCHAR2
6241 , x_msg_count OUT NOCOPY NUMBER
6242 , x_msg_data OUT NOCOPY VARCHAR2
6243 , p_organization_id IN NUMBER
6244 , p_requiition_header_id IN NUMBER
6245 , p_item_id IN NUMBER
6246 , p_rcv_txn_type IN VARCHAR2
6247 , p_lpn_id IN NUMBER DEFAULT NULL
6248 ) IS
6249 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
6250 l_msg_count NUMBER;
6251 l_msg_data VARCHAR2(400);
6252 l_progress VARCHAR2(10);
6253 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6254 BEGIN
6255 x_return_status := fnd_api.g_ret_sts_success;
6256
6257 IF (l_debug = 1) THEN
6258 print_debug('Enter get_req_shipment_header_id 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6259 END IF;
6260
6261 l_progress := '10';
6262
6263 IF p_rcv_txn_type = 'RCVTXN' THEN
6264 l_progress := '20';
6265
6266 BEGIN
6267 SELECT DISTINCT rsl.shipment_header_id
6268 , rsl.from_organization_id
6269 INTO x_shipment_header_id
6270 , x_from_org_id
6271 FROM rcv_shipment_lines rsl
6272 WHERE item_id = p_item_id
6273 AND to_organization_id = p_organization_id
6274 AND EXISTS(
6275 SELECT 1
6276 FROM po_requisition_lines prl, rcv_transactions rt, rcv_supply rs
6277 WHERE prl.requisition_header_id = p_requiition_header_id
6278 AND rsl.requisition_line_id = prl.requisition_line_id
6279 AND prl.item_id = p_item_id
6280 AND prl.source_type_code = 'INVENTORY'
6281 AND rs.req_line_id = prl.requisition_line_id
6282 AND rs.rcv_transaction_id = rt.transaction_id
6283 AND rt.transaction_type <> 'UNORDERED'
6284 AND rs.quantity > 0
6285 AND rs.supply_type_code = 'RECEIVING'
6286 AND rs.to_organization_id = p_organization_id
6287 AND rt.organization_id = p_organization_id
6288 AND(
6289 EXISTS(
6290 SELECT 1
6291 FROM rcv_transactions rt1
6292 WHERE rt1.transaction_id = rt.transaction_id
6293 AND rt1.inspection_status_code <> 'NOT INSPECTED'
6294 AND rt1.routing_header_id = 2)
6295 OR rt.routing_header_id <> 2
6296 OR rt.routing_header_id IS NULL
6297 ));
6298 EXCEPTION
6299 WHEN TOO_MANY_ROWS THEN
6300 fnd_message.set_name('INV', 'INV_RCV_REQ_SHIP_MISMATCH');
6301 fnd_msg_pub.ADD;
6302
6303 IF (l_debug = 1) THEN
6304 print_debug(
6305 'get_req_shipment_header_id 20 - returns more than one shipment header ID for RCVTXN '
6306 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6307 , 1
6308 );
6309 END IF;
6310
6311 RAISE fnd_api.g_exc_error;
6312 END;
6313
6314 l_progress := '30';
6315 ELSIF p_rcv_txn_type = 'RECEIPT' THEN
6316 l_progress := '40';
6317
6318 IF (p_item_id IS NULL
6319 AND p_lpn_id IS NOT NULL) THEN -- through reqexp.
6320
6321 /*
6322 Change the below code to cater to Empty LPN scenario,
6323 With Nested LPNs the given LPN may be empty but not its child LPNs.
6324 */
6325
6326 BEGIN
6327 /* Bug 3440456 */
6328 -- For performance reason this is being as replaced as below.
6329 /*
6330 SELECT DISTINCT rsl.shipment_header_id
6331 , rsl.from_organization_id
6332 INTO x_shipment_header_id
6333 , x_from_org_id
6334 FROM rcv_shipment_lines rsl, wms_lpn_contents wlc,wms_license_plate_numbers wln
6335 WHERE rsl.item_id = wlc.inventory_item_id
6336 AND to_organization_id = p_organization_id
6337 AND wln.lpn_id IN ( SELECT lpn_id
6338 FROM wms_license_plate_numbers
6339 START WITH lpn_id = p_lpn_id
6340 CONNECT BY parent_lpn_id = PRIOR lpn_id)
6341 AND wlc.parent_lpn_id = wln.lpn_id
6342 AND EXISTS(
6343 SELECT 1
6344 FROM po_requisition_lines_all prl, mtl_supply ms
6345 WHERE prl.requisition_header_id = p_requiition_header_id
6346 AND prl.requisition_header_id = ms.req_header_id
6347 AND prl.requisition_line_id = ms.req_line_id
6348 AND ms.supply_type_code = 'SHIPMENT'
6349 AND ms.quantity > 0
6350 AND ms.supply_source_id = rsl.shipment_line_id
6351 AND prl.item_id = wlc.inventory_item_id
6352 AND prl.item_id = ms.item_id);
6353 */
6354
6355 SELECT DISTINCT rsl.shipment_header_id
6356 , rsl.from_organization_id
6357 INTO x_shipment_header_id
6358 , x_from_org_id
6359 FROM rcv_shipment_lines rsl, wms_lpn_contents wlc
6360 WHERE rsl.item_id = wlc.inventory_item_id
6361 AND to_organization_id = p_organization_id
6362 AND wlc.parent_lpn_id IN ( SELECT lpn_id
6363 FROM wms_license_plate_numbers
6364 START WITH lpn_id = p_lpn_id
6365 CONNECT BY parent_lpn_id = PRIOR lpn_id)
6366 AND EXISTS(
6367 SELECT 1
6368 FROM po_requisition_lines_all prl, mtl_supply ms
6369 WHERE prl.requisition_header_id = p_requiition_header_id
6370 AND prl.requisition_header_id = ms.req_header_id
6371 AND prl.requisition_line_id = ms.req_line_id
6372 AND ms.supply_type_code = 'SHIPMENT'
6373 AND ms.quantity > 0
6374 AND ms.supply_source_id = rsl.shipment_line_id
6375 AND prl.item_id = wlc.inventory_item_id
6376 AND prl.item_id = ms.item_id);
6377 EXCEPTION
6378 WHEN TOO_MANY_ROWS THEN
6379 fnd_message.set_name('INV', 'INV_RCV_REQ_SHIP_MISMATCH');
6380 fnd_msg_pub.ADD;
6381
6382 IF (l_debug = 1) THEN
6383 print_debug('get_req_shipment_header_id for reqexp 35 - returns more than one shipment header ID for RECEIPT ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6384 , 1
6385 );
6386 END IF;
6387
6388 RAISE fnd_api.g_exc_error;
6389 WHEN NO_DATA_FOUND THEN
6390 fnd_message.set_name('INV', 'INV_LPN_ZERO_AVAIL_QTY');
6391 fnd_msg_pub.ADD;
6392 IF (l_debug = 1) THEN
6393 print_debug('get_req_shipment_header_id for reqexp 40 retruned no rows ', 4);
6394 END IF;
6395
6396 RAISE fnd_api.g_exc_error;
6397 END; -- Express Int Req Receiving
6398 ELSE
6399 BEGIN
6400 SELECT DISTINCT rsl.shipment_header_id
6401 , rsl.from_organization_id
6402 INTO x_shipment_header_id
6403 , x_from_org_id
6404 FROM rcv_shipment_lines rsl
6405 WHERE item_id = p_item_id
6406 AND to_organization_id = p_organization_id
6407 AND EXISTS(
6408 SELECT 1
6409 FROM po_requisition_lines prl
6410 WHERE prl.requisition_header_id = p_requiition_header_id
6411 AND rsl.requisition_line_id = prl.requisition_line_id
6412 AND prl.item_id = p_item_id);
6413 EXCEPTION
6414 WHEN TOO_MANY_ROWS THEN
6415 fnd_message.set_name('INV', 'INV_RCV_REQ_SHIP_MISMATCH');
6416 fnd_msg_pub.ADD;
6417
6418 IF (l_debug = 1) THEN
6419 print_debug('get_req_shipment_header_id 30 - returns more than one shipment header ID for RECEIPT ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6420 END IF;
6421
6422 RAISE fnd_api.g_exc_error;
6423 END;
6424
6425 l_progress := '50';
6426 END IF;
6427 ELSIF p_rcv_txn_type = 'INSPECT' THEN
6428 --BUG 3421219: Need to handle inspection as well
6429 BEGIN
6430 SELECT DISTINCT rsl.shipment_header_id
6431 , rsl.from_organization_id
6432 INTO x_shipment_header_id
6433 , x_from_org_id
6434 FROM rcv_shipment_lines rsl
6435 WHERE item_id = p_item_id
6436 AND to_organization_id = p_organization_id
6437 AND EXISTS(
6438 SELECT 1
6439 FROM po_requisition_lines prl, rcv_transactions rt, rcv_supply rs
6440 WHERE prl.requisition_header_id = p_requiition_header_id
6441 AND rsl.requisition_line_id = prl.requisition_line_id
6442 AND prl.item_id = p_item_id
6443 AND prl.source_type_code = 'INVENTORY'
6444 AND rs.req_line_id = prl.requisition_line_id
6445 AND rs.rcv_transaction_id = rt.transaction_id
6446 AND rt.transaction_type <> 'UNORDERED'
6447 AND rs.quantity > 0
6448 AND rs.supply_type_code = 'RECEIVING'
6449 AND rs.to_organization_id = p_organization_id
6450 AND rt.organization_id = p_organization_id
6451 AND(EXISTS(
6452 SELECT 1
6453 FROM rcv_transactions rt1
6454 WHERE rt1.transaction_id = rt.transaction_id
6455 AND rt1.inspection_status_code = 'NOT INSPECTED'
6456 AND rt1.routing_header_id = 2)
6457 ));
6458 EXCEPTION
6459 WHEN TOO_MANY_ROWS THEN
6460 fnd_message.set_name('INV', 'INV_RCV_REQ_SHIP_MISMATCH');
6461 fnd_msg_pub.ADD;
6462
6463 IF (l_debug = 1) THEN
6464 print_debug(
6465 'get_req_shipment_header_id 20 - returns more than one shipment header ID for RCVTXN '
6466 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6467 , 1
6468 );
6469 END IF;
6470
6471 RAISE fnd_api.g_exc_error;
6472 END;
6473
6474 l_progress := '30';
6475 ELSE
6476 l_progress := '60';
6477 fnd_message.set_name('INV', 'INV_RCV_TXN_NOT_DEFINED');
6478 fnd_msg_pub.ADD;
6479
6480 IF (l_debug = 1) THEN
6481 print_debug('get_req_shipment_header_id 30 - receiving Txn type ' || p_rcv_txn_type || ' not defined. ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6482 END IF;
6483
6484 RAISE fnd_api.g_exc_unexpected_error;
6485 l_progress := '70';
6486 END IF;
6487
6488 IF (l_debug = 1) THEN
6489 print_debug('Exitting get_req_shipment_header_id 60 - x_shipment_header_id = ' || x_shipment_header_id || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6490 END IF;
6491 EXCEPTION
6492 WHEN fnd_api.g_exc_error THEN
6493 x_return_status := fnd_api.g_ret_sts_error;
6494
6495 IF (l_debug = 1) THEN
6496 print_debug('Exiting get_req_shipment_header_id - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6497 END IF;
6498
6499 -- Get message count and data
6500 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6501 WHEN fnd_api.g_exc_unexpected_error THEN
6502 x_return_status := fnd_api.g_ret_sts_unexp_error;
6503
6504 IF (l_debug = 1) THEN
6505 print_debug('Exitting get_req_shipment_header_id - unexpected error:' || l_progress || ' '
6506 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6507 , 1);
6508 END IF;
6509
6510 -- Get message count and data
6511 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6512 WHEN OTHERS THEN
6513 x_return_status := fnd_api.g_ret_sts_unexp_error;
6514
6515 IF (l_debug = 1) THEN
6516 print_debug('Exitting get_req_shipment_header_id - other exceptions:' || l_progress || ' '
6517 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6518 , 1);
6519 END IF;
6520
6521 IF SQLCODE IS NOT NULL THEN
6522 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.get_req_shipment_header_id', l_progress, SQLCODE);
6523 END IF;
6524 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6525 END;
6526
6527 PROCEDURE do_check(
6528 p_organization_id IN NUMBER
6529 , p_inventory_item_id IN NUMBER
6530 , p_transaction_type_id IN NUMBER
6531 , p_primary_quantity IN NUMBER
6532 , x_return_status OUT NOCOPY VARCHAR2
6533 , x_msg_data OUT NOCOPY VARCHAR2
6534 , x_msg_count OUT NOCOPY NUMBER
6535 ) IS
6536 l_progress VARCHAR2(10);
6537 l_check_result VARCHAR2(1);
6538 l_seq_num NUMBER;
6539 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6540 BEGIN
6541 x_return_status := fnd_api.g_ret_sts_success;
6542 l_progress := '10';
6543 --
6544 inv_shortcheckexec_pvt.checkprerequisites(
6545 p_api_version => 1.0
6546 , p_init_msg_list => 'F'
6547 , x_return_status => x_return_status
6548 , x_msg_count => x_msg_count
6549 , x_msg_data => x_msg_data
6550 , p_sum_detail_flag => 2
6551 , p_organization_id => p_organization_id
6552 , p_inventory_item_id => p_inventory_item_id
6553 , p_transaction_type_id => p_transaction_type_id
6554 , x_check_result => l_check_result
6555 );
6556
6557 --
6558 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6559 fnd_message.set_name('INV', 'INV_RCV_SHORTAGE_FAILED');
6560 fnd_msg_pub.ADD;
6561 RAISE fnd_api.g_exc_error;
6562 END IF;
6563
6564 l_progress := '20';
6565
6566 IF (l_debug = 1) THEN
6567 print_debug('do_check check_result - ' || l_check_result, 4);
6568 END IF;
6569
6570 --
6571 IF l_check_result = 'T' THEN
6572 inv_shortcheckexec_pvt.execcheck(
6573 p_api_version => 1.0
6574 , p_init_msg_list => 'F'
6575 , p_commit => 'F'
6576 , x_return_status => x_return_status
6577 , x_msg_count => x_msg_count
6578 , x_msg_data => x_msg_data
6579 , p_sum_detail_flag => 2
6580 , p_organization_id => p_organization_id
6581 , p_inventory_item_id => p_inventory_item_id
6582 , p_comp_att_qty_flag => 1
6583 , p_primary_quantity => p_primary_quantity
6584 , x_seq_num => l_seq_num
6585 , x_check_result => l_check_result
6586 );
6587
6588 --
6589 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6590 fnd_message.set_name('INV', 'INV_RCV_SHORTAGE_FAILED');
6591 fnd_msg_pub.ADD;
6592 RAISE fnd_api.g_exc_error;
6593 END IF;
6594
6595 l_progress := '30';
6596
6597 --Bug #4059722
6598 --Need to clear the quantity tree cache for subsequent calls
6599 inv_quantity_tree_pub.clear_quantity_cache;
6600
6601 IF l_check_result = 'T' THEN
6602 fnd_message.set_name('INV', 'INV_RCV_SHORTAGE_EXISTS');
6603 fnd_msg_pub.ADD;
6604 x_return_status := 'W';
6605 END IF;
6606 END IF;
6607 EXCEPTION
6608 WHEN fnd_api.g_exc_error THEN
6609 x_return_status := fnd_api.g_ret_sts_error;
6610
6611 IF (l_debug = 1) THEN
6612 print_debug('Exiting do_check - execution error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6613 END IF;
6614
6615 -- Get message count and data
6616 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6617 WHEN fnd_api.g_exc_unexpected_error THEN
6618 x_return_status := fnd_api.g_ret_sts_unexp_error;
6619
6620 IF (l_debug = 1) THEN
6621 print_debug('Exitting do_check - unexpected error:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6622 END IF;
6623
6624 -- Get message count and data
6625 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6626 WHEN OTHERS THEN
6627 x_return_status := fnd_api.g_ret_sts_unexp_error;
6628
6629 IF (l_debug = 1) THEN
6630 print_debug('Exitting get_req_shipment_header_id - other exceptions:' || l_progress || ' '
6631 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6632 , 1);
6633 END IF;
6634
6635 IF SQLCODE IS NOT NULL THEN
6636 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.get_req_shipment_header_id', l_progress, SQLCODE);
6637 END IF;
6638
6639 -- Get message count and data
6640 fnd_msg_pub.count_and_get(
6641 p_encoded => fnd_api.g_false,
6642 p_count => x_msg_count,
6643 p_data => x_msg_data);
6644 END do_check;
6645
6646 /*
6647 * Procedure to to get serial control of the item at
6648 * source org. Called directly in the case of Intransit
6649 * shipment transaction.
6650 * For Int Req, the overloaded method calls this procedure
6651 * Written as part of fix for Bug #1751998
6652 */
6653 PROCEDURE get_serial_ctrl(
6654 x_return_status OUT NOCOPY VARCHAR2
6655 , x_serial_control OUT NOCOPY NUMBER
6656 , p_from_org_id IN NUMBER
6657 , p_item_id IN NUMBER
6658 ) IS
6659 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6660 BEGIN
6661 x_return_status := 'S';
6662
6663 SELECT serial_number_control_code
6664 INTO x_serial_control
6665 FROM mtl_system_items
6666 WHERE inventory_item_id = p_item_id
6667 AND organization_id = p_from_org_id;
6668 EXCEPTION
6669 WHEN OTHERS THEN
6670 x_return_status := 'F';
6671 END get_serial_ctrl;
6672
6673 /* Procedure to get the project and task from the
6674 source document
6675 */
6676 PROCEDURE get_document_project_task(
6677 x_return_status OUT NOCOPY VARCHAR2
6678 , x_project_tasks_count OUT NOCOPY NUMBER
6679 , x_distributions_count OUT NOCOPY NUMBER
6680 , p_document_type IN VARCHAR2
6681 , p_po_header_id IN NUMBER
6682 , p_po_line_id IN NUMBER
6683 , p_oe_header_id IN NUMBER
6684 , p_req_header_id IN NUMBER
6685 , p_shipment_header_id IN NUMBER
6686 , p_item_id IN NUMBER
6687 , p_item_rev IN VARCHAR2
6688 ) IS
6689 l_project_tasks_count NUMBER := 0;
6690 l_distributions_count NUMBER := 0;
6691 l_progress VARCHAR2(10);
6692 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6693 BEGIN
6694 IF (l_debug = 1) THEN
6695 print_debug('Entered get_document_project_task ' || p_document_type, 4);
6696 END IF;
6697
6698 l_progress := '10';
6699 x_return_status := fnd_api.g_ret_sts_success;
6700
6701 IF p_document_type = 'PO' THEN
6702 SELECT COUNT(COUNT(*)) -- get the no of project/tasks combinations
6703 INTO l_project_tasks_count
6704 FROM po_distributions_all pod, po_lines_all pol
6705 WHERE pod.po_header_id = p_po_header_id
6706 AND pod.po_line_id = NVL(p_po_line_id, pod.po_line_id)
6707 AND pod.project_id IS NOT NULL
6708 AND pod.po_header_id = pol.po_header_id
6709 AND pod.po_line_id = pol.po_line_id
6710 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6711 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6712 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6713 AND pol.item_revision = p_item_rev)
6714 )
6715 GROUP BY pod.project_id, pod.task_id;
6716
6717 SELECT COUNT(*)
6718 INTO l_distributions_count
6719 FROM po_distributions_all pod, po_lines_all pol
6720 WHERE pod.po_header_id = p_po_header_id
6721 AND pod.po_line_id = NVL(p_po_line_id, pod.po_line_id)
6722 AND pod.po_header_id = pol.po_header_id
6723 AND pod.po_line_id = pol.po_line_id
6724 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6725 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6726 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6727 AND pol.item_revision = p_item_rev)
6728 );
6729
6730 ELSIF p_document_type = 'ASN' THEN
6731 SELECT COUNT(COUNT(*))
6732 INTO l_project_tasks_count
6733 FROM po_distributions_all pod, rcv_shipment_lines rsl
6734 WHERE pod.po_header_id = rsl.po_header_id
6735 AND rsl.shipment_header_id = p_shipment_header_id
6736 AND (p_item_id IS NULL OR rsl.item_id = p_item_id)
6737 AND ( (p_item_rev IS NULL OR rsl.item_revision IS NULL) OR
6738 (p_item_rev IS NOT NULL AND rsl.item_revision IS NOT NULL
6739 AND rsl.item_revision = p_item_rev)
6740 )
6741 AND pod.project_id IS NOT NULL
6742 GROUP BY project_id, task_id;
6743
6744 SELECT COUNT(COUNT(*))
6745 INTO l_distributions_count
6746 FROM po_distributions_all pod, rcv_shipment_lines rsl
6747 WHERE pod.po_header_id = rsl.po_header_id
6748 AND rsl.po_line_id = pod.po_line_id(+)
6749 AND rsl.po_line_location_id = pod.line_location_id(+)
6750 AND rsl.shipment_header_id = p_shipment_header_id
6751 AND (p_item_id IS NULL OR rsl.item_id = p_item_id)
6752 AND ( (p_item_rev IS NULL OR rsl.item_revision IS NULL) OR
6753 (p_item_rev IS NOT NULL AND rsl.item_revision IS NOT NULL
6754 AND rsl.item_revision = p_item_rev)
6755 )
6756 GROUP BY project_id, task_id;
6757 ELSIF p_document_type = 'REQ' THEN
6758 SELECT COUNT(COUNT(*))
6759 INTO l_project_tasks_count
6760 FROM po_req_distributions_all pod, po_requisition_lines_all pol
6761 WHERE pol.requisition_header_id = p_req_header_id
6762 AND pod.requisition_line_id = pol.requisition_line_id
6763 AND pod.project_id IS NOT NULL
6764 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6765 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6766 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6767 AND pol.item_revision = p_item_rev)
6768 )
6769 GROUP BY project_id, task_id;
6770
6771 SELECT COUNT(*)
6772 INTO l_distributions_count
6773 FROM po_req_distributions_all pod, po_requisition_lines_all pol
6774 WHERE pol.requisition_header_id = p_req_header_id
6775 AND pod.requisition_line_id = pol.requisition_line_id
6776 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6777 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6778 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6779 AND pol.item_revision = p_item_rev)
6780 );
6781
6782 /*Added as part of bug - 5928199*/
6783 ELSIF p_document_type = 'INTSHIP' THEN
6784 IF (l_debug = 1) THEN
6785 print_debug('p_document_type: ' || p_document_type, 4);
6786 print_debug('p_req_header_id: ' || p_req_header_id, 4);
6787 print_debug('p_item_id: ' || p_item_id, 4);
6788 print_debug('p_item_rev: ' || p_item_rev, 4);
6789 END IF;
6790
6791 SELECT COUNT(COUNT(*))
6792 INTO l_project_tasks_count
6793 FROM po_req_distributions_all pod, po_requisition_lines_all pol
6794 WHERE pol.requisition_header_id = p_req_header_id
6795 AND pod.requisition_line_id = pol.requisition_line_id
6796 AND pod.project_id IS NOT NULL
6797 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6798 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6799 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6800 AND pol.item_revision = p_item_rev)
6801 )
6802 GROUP BY project_id, task_id;
6803 IF (l_debug = 1) THEN
6804 print_debug('l_project_tasks_count: ' || l_project_tasks_count, 4);
6805 END IF;
6806
6807
6808 SELECT COUNT(*)
6809 INTO l_distributions_count
6810 FROM po_req_distributions_all pod, po_requisition_lines_all pol
6811 WHERE pol.requisition_header_id = p_req_header_id
6812 AND pod.requisition_line_id = pol.requisition_line_id
6813 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6814 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6815 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6816 AND pol.item_revision = p_item_rev)
6817 );
6818 IF (l_debug = 1) THEN
6819 print_debug('l_distributions_count: ' || l_distributions_count, 4);
6820 END IF;
6821 /*End of Bug - 5928199*/
6822
6823 ELSIF p_document_type = 'RMA' THEN
6824 SELECT COUNT(COUNT(*))
6825 INTO l_project_tasks_count
6826 FROM oe_order_lines l
6827 WHERE l.line_category_code = 'RETURN'
6828 AND l.header_id = p_oe_header_id
6829 AND l.project_id IS NOT NULL
6830 AND (p_item_id IS NULL OR l.inventory_item_id = p_item_id)
6831 AND ( (p_item_rev IS NULL OR l.item_revision IS NULL) OR
6832 (p_item_rev IS NOT NULL AND l.item_revision IS NOT NULL
6833 AND l.item_revision = p_item_rev)
6834 )
6835 GROUP BY project_id, task_id;
6836
6837 SELECT COUNT(*)
6838 INTO l_distributions_count
6839 FROM oe_order_lines l
6840 WHERE l.line_category_code = 'RETURN'
6841 AND l.header_id = p_oe_header_id
6842 AND (p_item_id IS NULL OR l.inventory_item_id = p_item_id)
6843 AND ( (p_item_rev IS NULL OR l.item_revision IS NULL) OR
6844 (p_item_rev IS NOT NULL AND l.item_revision IS NOT NULL
6845 AND l.item_revision = p_item_rev)
6846 );
6847 ELSIF p_document_type = 'RECEIPT' THEN
6848 IF p_po_header_id IS NOT NULL THEN
6849 SELECT COUNT(COUNT(*)) -- get the no of project/tasks combinations
6850 INTO l_project_tasks_count
6851 FROM po_distributions_all pod, po_lines_all pol
6852 WHERE pod.po_header_id = p_po_header_id
6853 AND pod.project_id IS NOT NULL
6854 AND pod.po_header_id = pol.po_header_id
6855 AND pod.po_line_id = pol.po_line_id
6856 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6857 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6858 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6859 AND pol.item_revision = p_item_rev)
6860 )
6861 GROUP BY pod.project_id, pod.task_id;
6862
6863 SELECT COUNT(*)
6864 INTO l_distributions_count
6865 FROM po_distributions_all pod, po_lines_all pol
6866 WHERE pod.po_header_id = p_po_header_id
6867 AND pod.po_header_id = pol.po_header_id
6868 AND pod.po_line_id = pol.po_line_id
6869 AND (p_item_id IS NULL OR pol.item_id = p_item_id)
6870 AND ( (p_item_rev IS NULL OR pol.item_revision IS NULL) OR
6871 (p_item_rev IS NOT NULL AND pol.item_revision IS NOT NULL
6872 AND pol.item_revision = p_item_rev)
6873 );
6874 ELSIF p_oe_header_id IS NOT NULL THEN
6875 SELECT COUNT(COUNT(*))
6876 INTO l_project_tasks_count
6877 FROM oe_order_lines l
6878 WHERE l.line_category_code = 'RETURN'
6879 AND l.header_id = p_oe_header_id
6880 AND l.project_id IS NOT NULL
6881 AND (p_item_id IS NULL OR l.inventory_item_id = p_item_id)
6882 AND ( (p_item_rev IS NULL OR l.item_revision IS NULL) OR
6883 (p_item_rev IS NOT NULL AND l.item_revision IS NOT NULL
6884 AND l.item_revision = p_item_rev)
6885 )
6886 GROUP BY project_id, task_id;
6887
6888 SELECT COUNT(*)
6889 INTO l_distributions_count
6890 FROM oe_order_lines l
6891 WHERE l.line_category_code = 'RETURN'
6892 AND l.header_id = p_oe_header_id
6893 AND (p_item_id IS NULL OR l.inventory_item_id = p_item_id)
6894 AND ( (p_item_rev IS NULL OR l.item_revision IS NULL) OR
6895 (p_item_rev IS NOT NULL AND l.item_revision IS NOT NULL
6896 AND l.item_revision = p_item_rev)
6897 );
6898 END IF;
6899 END IF;
6900
6901 IF (l_debug = 1) THEN
6902 print_debug('get_document_project_task: Project count ' || TO_CHAR(l_project_tasks_count) ||
6903 'distribution count: ' || TO_CHAR(l_distributions_count), 4);
6904 END IF;
6905 x_project_tasks_count := l_project_tasks_count;
6906 x_distributions_count := l_distributions_count;
6907 EXCEPTION
6908 WHEN NO_DATA_FOUND THEN
6909 l_progress := '20';
6910 x_return_status := fnd_api.g_ret_sts_error;
6911 x_project_tasks_count := 0;
6912
6913 IF (l_debug = 1) THEN
6914 print_debug('in get_document_project_task ' || l_progress, 4);
6915 END IF;
6916 WHEN OTHERS THEN
6917 l_progress := '30';
6918 x_return_status := fnd_api.g_ret_sts_error;
6919 x_project_tasks_count := 0;
6920
6921 IF (l_debug = 1) THEN
6922 print_debug('in get_document_project_task ' || l_progress, 4);
6923 END IF;
6924 END;
6925
6926 /*
6927 * Procedure to to get serial control of the item at
6928 * source org. Called in the case of Internal
6929 * Requisition transaction.
6930 * First get the source org corresponding to the current line
6931 * and then call the overloaded procedure above to get the
6932 * serial control code at the source org.
6933 * Written as part of fix for Bug #1751998
6934 */
6935 PROCEDURE get_serial_ctrl(
6936 x_return_status OUT NOCOPY VARCHAR2
6937 , x_serial_control OUT NOCOPY NUMBER
6938 , p_to_org_id IN NUMBER
6939 , p_ship_head_id IN NUMBER
6940 , p_requisition_id IN NUMBER
6941 , p_item_id IN NUMBER
6942 ) IS
6943 l_from_org_id NUMBER := 0;
6944 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6945 BEGIN
6946 x_return_status := 'S';
6947
6948 /*Get the From Organization for the item using shipment header
6949 Id, Requisition #, To Organization Id and Item ID
6950 */
6951 SELECT DISTINCT rsl.from_organization_id
6952 INTO l_from_org_id
6953 FROM rcv_shipment_lines rsl
6954 WHERE item_id = p_item_id
6955 AND to_organization_id = p_to_org_id
6956 AND shipment_header_id = p_ship_head_id
6957 AND EXISTS(
6958 SELECT 1
6959 FROM po_requisition_lines prl
6960 WHERE prl.requisition_header_id = p_requisition_id
6961 AND rsl.requisition_line_id = prl.requisition_line_id
6962 AND prl.item_id = p_item_id);
6963
6964 --Get the serial control of the item at the source org
6965 inv_rcv_common_apis.get_serial_ctrl(x_return_status => x_return_status, x_serial_control => x_serial_control
6966 , p_from_org_id => l_from_org_id, p_item_id => p_item_id);
6967 EXCEPTION
6968 WHEN OTHERS THEN
6969 x_return_status := 'F';
6970 END get_serial_ctrl;
6971
6972 -- MANEESH - BEGIN CHANGES - FOR CROSS REFERENCE ITEM CREATION
6973
6974 PROCEDURE create_cross_reference(
6975 p_api_version IN NUMBER
6976 , p_init_msg_list IN VARCHAR2 := fnd_api.g_false
6977 , p_commit IN VARCHAR2 := fnd_api.g_false
6978 , p_organization_id IN NUMBER
6979 , p_inventory_item_id IN NUMBER
6980 , p_cross_reference IN VARCHAR2
6981 , p_cross_reference_type IN VARCHAR2
6982 , x_return_status OUT NOCOPY VARCHAR2
6983 , x_msg_count OUT NOCOPY NUMBER
6984 , x_msg_data OUT NOCOPY VARCHAR2
6985 ) IS
6986 l_progress VARCHAR2(10);
6987 l_cross_reference VARCHAR2(25);
6988 l_inventory_item_id NUMBER;
6989 l_user_id NUMBER;
6990 l_login_id NUMBER;
6991 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6992 BEGIN
6993 l_progress := '0';
6994
6995 IF (l_debug = 1) THEN
6996 print_debug('Entered CREATE_CROSS_REFERENCE - Progress = ' || l_progress, 9);
6997 END IF;
6998
6999 x_return_status := fnd_api.g_ret_sts_success;
7000 SAVEPOINT rcv_create_cross_reference_sp;
7001
7002 -- Make sure that cross_reference does not exist as a master item.
7003 BEGIN
7004 SELECT inventory_item_id
7005 INTO l_inventory_item_id
7006 FROM mtl_system_items_kfv
7007 WHERE concatenated_segments = p_cross_reference;
7008
7009 l_progress := '10';
7010
7011 IF (l_debug = 1) THEN
7012 print_debug('Cross Reference matches a master item - Progress = ' || l_progress, 9);
7013 END IF;
7014
7015 fnd_message.set_name('INV', 'INV_CROSS_REF_MATCHES_ITEM');
7016 fnd_msg_pub.ADD;
7017 RAISE fnd_api.g_exc_error;
7018 EXCEPTION
7019 WHEN NO_DATA_FOUND THEN
7020 l_progress := '15';
7021 END;
7022
7023 -- Make sure that cross_ref_item does not already exist.
7024 BEGIN
7025 SELECT cross_reference
7026 INTO l_cross_reference
7027 FROM mtl_cross_references
7028 WHERE cross_reference = p_cross_reference
7029 AND cross_reference_type = p_cross_reference_type
7030 AND organization_id = p_organization_id;
7031
7032 l_progress := '20';
7033
7034 IF (l_debug = 1) THEN
7035 print_debug('Cross Reference already exists - Progress = ' || l_progress, 9);
7036 END IF;
7037
7038 fnd_message.set_name('INV', 'INV_CROSS_REF_EXISTS');
7039 fnd_msg_pub.ADD;
7040 RAISE fnd_api.g_exc_error;
7041 EXCEPTION
7042 WHEN NO_DATA_FOUND THEN
7043 l_progress := '25';
7044 END;
7045
7046 l_user_id := fnd_global.user_id;
7047 l_login_id := fnd_global.login_id;
7048 l_progress := '30';
7049
7050 -- Insert the record in mtl_cross_references
7051 INSERT INTO mtl_cross_references
7052 (
7053 inventory_item_id
7054 , organization_id
7055 , cross_reference_type
7056 , cross_reference
7057 , last_update_date
7058 , last_updated_by
7059 , creation_date
7060 , created_by
7061 , last_update_login
7062 , org_independent_flag
7063 )
7064 VALUES (
7065 p_inventory_item_id
7066 , p_organization_id
7067 , p_cross_reference_type
7068 , p_cross_reference
7069 , SYSDATE
7070 , l_user_id
7071 , SYSDATE
7072 , l_user_id
7073 , l_login_id
7074 , 'N'
7075 );
7076
7077 x_return_status := fnd_api.g_ret_sts_success;
7078 l_progress := '40';
7079
7080 IF (l_debug = 1) THEN
7081 print_debug('create_cross_reference complete - progress = ' || l_progress, 9);
7082 END IF;
7083 EXCEPTION
7084 WHEN fnd_api.g_exc_error THEN
7085 ROLLBACK TO rcv_create_cross_reference_sp;
7086 x_return_status := fnd_api.g_ret_sts_error;
7087 fnd_msg_pub.count_and_get(
7088 p_encoded => fnd_api.g_false,
7089 p_count => x_msg_count,
7090 p_data => x_msg_data);
7091 WHEN fnd_api.g_exc_unexpected_error THEN
7092 ROLLBACK TO rcv_create_cross_reference_sp;
7093 x_return_status := fnd_api.g_ret_sts_unexp_error;
7094 fnd_msg_pub.count_and_get(
7095 p_encoded => fnd_api.g_false,
7096 p_count => x_msg_count,
7097 p_data => x_msg_data);
7098 WHEN OTHERS THEN
7099 ROLLBACK TO rcv_create_cross_reference_sp;
7100 x_return_status := fnd_api.g_ret_sts_unexp_error;
7101
7102 IF SQLCODE IS NOT NULL THEN
7103 inv_mobile_helper_functions.sql_error('INV_RCV_COMMON_APIS.create_cross_reference', l_progress, SQLCODE);
7104 END IF;
7105
7106 fnd_msg_pub.count_and_get(
7107 p_encoded => fnd_api.g_false,
7108 p_count => x_msg_count,
7109 p_data => x_msg_data);
7110 END create_cross_reference;
7111
7112 -- MANEESH - END CHANGES - FOR CROSS REFERENCE ITEM CREATION
7113
7114 /*
7115 * Procedure to to get lot control of the item at
7116 * source org. Called directly in the case of Intransit
7117 * shipment transaction.
7118 * For Int Req, the overloaded method calls this procedure
7119 * Written as part of fix for Bug #2156143.
7120 */
7121 PROCEDURE get_lot_ctrl(
7122 x_return_status OUT NOCOPY VARCHAR2
7123 , x_msg_count OUT NOCOPY NUMBER
7124 , x_msg_data OUT NOCOPY VARCHAR2
7125 , x_lot_control OUT NOCOPY NUMBER
7126 , p_from_org_id IN NUMBER
7127 , p_item_id IN NUMBER
7128 ) IS
7129 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7130 BEGIN
7131 x_return_status := fnd_api.g_ret_sts_success;
7132
7133 SELECT lot_control_code
7134 INTO x_lot_control
7135 FROM mtl_system_items
7136 WHERE inventory_item_id = p_item_id
7137 AND organization_id = p_from_org_id;
7138 EXCEPTION
7139 WHEN fnd_api.g_exc_error THEN
7140 x_return_status := fnd_api.g_ret_sts_error;
7141 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7142 WHEN fnd_api.g_exc_unexpected_error THEN
7143 x_return_status := fnd_api.g_ret_sts_unexp_error;
7144 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7145 WHEN OTHERS THEN
7146 x_return_status := fnd_api.g_ret_sts_unexp_error;
7147
7148 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7149 fnd_msg_pub.add_exc_msg(g_pkg_name, 'GET_LOT_CTRL');
7150 END IF;
7151
7152 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7153 END get_lot_ctrl;
7154
7155 /*
7156 * Procedure to to get lot control of the item at
7157 * source org. Called in the case of Internal
7158 * Requisition transaction.
7159 * First get the source org corresponding to the current line
7160 * and then call the overloaded procedure above to get the
7161 * lot control code at the source org.
7162 * Written as part of fix for Bug #2156143
7163 */
7164 PROCEDURE get_lot_ctrl(
7165 x_return_status OUT NOCOPY VARCHAR2
7166 , x_msg_count OUT NOCOPY NUMBER
7167 , x_msg_data OUT NOCOPY VARCHAR2
7168 , x_lot_control OUT NOCOPY NUMBER
7169 , p_to_org_id IN NUMBER
7170 , p_ship_head_id IN NUMBER
7171 , p_requisition_id IN NUMBER
7172 , p_item_id IN NUMBER
7173 ) IS
7174 l_from_org_id NUMBER := 0;
7175 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7176 BEGIN
7177 x_return_status := fnd_api.g_ret_sts_success;
7178
7179 /*Get the From Organization for the item using shipment header
7180 Id, Requisition #, To Organization Id and Item ID
7181 */
7182 SELECT DISTINCT rsl.from_organization_id
7183 INTO l_from_org_id
7184 FROM rcv_shipment_lines rsl
7185 WHERE item_id = p_item_id
7186 AND to_organization_id = p_to_org_id
7187 AND shipment_header_id = p_ship_head_id
7188 AND EXISTS(
7189 SELECT 1
7190 FROM po_requisition_lines prl
7191 WHERE prl.requisition_header_id = p_requisition_id
7192 AND rsl.requisition_line_id = prl.requisition_line_id
7193 AND prl.item_id = p_item_id);
7194
7195 --Get the lot control of the item at the source org
7196 inv_rcv_common_apis.get_lot_ctrl(
7197 x_return_status => x_return_status
7198 , x_msg_count => x_msg_count
7199 , x_msg_data => x_msg_data
7200 , x_lot_control => x_lot_control
7201 , p_from_org_id => l_from_org_id
7202 , p_item_id => p_item_id
7203 );
7204 EXCEPTION
7205 WHEN fnd_api.g_exc_error THEN
7206 x_return_status := fnd_api.g_ret_sts_error;
7207 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7208 WHEN fnd_api.g_exc_unexpected_error THEN
7209 x_return_status := fnd_api.g_ret_sts_unexp_error;
7210 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7211 WHEN OTHERS THEN
7212 x_return_status := fnd_api.g_ret_sts_unexp_error;
7213
7214 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7215 fnd_msg_pub.add_exc_msg(g_pkg_name, 'GET_LOT_CTRL');
7216 END IF;
7217
7218 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
7219 END get_lot_ctrl;
7220
7221 PROCEDURE get_default_task(
7222 x_return_status OUT NOCOPY VARCHAR2
7223 , x_task_number OUT NOCOPY VARCHAR2
7224 , p_document_type IN VARCHAR2
7225 , p_po_header_id IN NUMBER DEFAULT NULL
7226 , p_po_line_id IN NUMBER DEFAULT NULL
7227 , p_oe_header_id IN NUMBER DEFAULT NULL
7228 , p_req_header_id IN NUMBER DEFAULT NULL
7229 , p_shipment_header_id IN NUMBER DEFAULT NULL
7230 , p_item_id IN NUMBER DEFAULT NULL
7231 , p_item_rev IN VARCHAR2 DEFAULT NULL
7232 , p_project_id IN NUMBER DEFAULT NULL
7233 ) IS
7234 l_progress VARCHAR2(10);
7235 l_task_id NUMBER;
7236 --l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7237 l_debug NUMBER := 1;
7238 BEGIN
7239 IF (l_debug = 1) THEN
7240 print_debug('Entered get_document_project_task ' || p_document_type, 4);
7241 --dbms_output.put_line('Entered get_document_project_task '|| p_document_type);
7242 END IF;
7243
7244 l_progress := '10';
7245 x_return_status := fnd_api.g_ret_sts_success;
7246
7247 IF p_project_id IS NULL THEN
7248 IF (l_debug = 1) THEN
7249 print_debug('project id is null', 4);
7250 --dbms_output.put_line('project id is null');
7251 END IF;
7252
7253 RETURN;
7254 END IF;
7255
7256 IF p_document_type = 'PO' THEN
7257 BEGIN
7258 SELECT pod.task_id
7259 INTO l_task_id
7260 FROM po_distributions_all pod, po_lines_all pol
7261 WHERE pod.po_header_id = p_po_header_id
7262 AND pod.po_line_id = NVL(p_po_line_id, pod.po_line_id)
7263 AND pod.project_id = p_project_id
7264 AND pod.po_header_id = pol.po_header_id
7265 AND pod.po_line_id = pol.po_line_id
7266 AND(p_item_id IS NULL
7267 OR pol.item_id = p_item_id)
7268 AND(p_item_rev IS NULL
7269 OR pol.item_revision = p_item_rev);
7270 EXCEPTION
7271 WHEN OTHERS THEN
7272 IF (l_debug = 1) THEN
7273 print_debug('error ' || SQLERRM, 4);
7274 --dbms_output.put_line('error '||SQLERRM);
7275 END IF;
7276 END;
7277
7278 IF (l_debug = 1) THEN
7279 print_debug('task= ' || TO_CHAR(l_task_id), 4);
7280 --dbms_output.put_line('task= '||to_char(l_task_id));
7281 END IF;
7282 ELSIF p_document_type = 'ASN' THEN
7283 BEGIN
7284 SELECT pod.task_id
7285 INTO l_task_id
7286 FROM po_distributions_all pod, rcv_shipment_lines rsl
7287 WHERE pod.po_header_id = rsl.po_header_id
7288 AND rsl.po_line_id = pod.po_line_id(+)
7289 AND rsl.po_line_location_id = pod.line_location_id(+)
7290 AND rsl.shipment_header_id = p_shipment_header_id
7291 AND pod.project_id = p_project_id
7292 AND(p_item_id IS NULL
7293 OR rsl.item_id = p_item_id)
7294 AND(p_item_rev IS NULL
7295 OR rsl.item_revision = p_item_rev);
7296 EXCEPTION
7297 WHEN OTHERS THEN
7298 IF (l_debug = 1) THEN
7299 print_debug('error ' || SQLERRM, 4);
7300 --dbms_output.put_line('error '||SQLERRM);
7301 END IF;
7302 END;
7303 ELSIF p_document_type = 'REQ' THEN
7304 BEGIN
7305 SELECT pod.task_id
7306 INTO l_task_id
7307 FROM po_req_distributions_all pod, po_requisition_lines_all pol
7308 WHERE pol.requisition_header_id = p_req_header_id
7309 AND pod.requisition_line_id = pol.requisition_line_id
7310 AND pod.project_id = p_project_id
7311 AND(p_item_id IS NULL
7312 OR pol.item_id = p_item_id)
7313 AND(p_item_rev IS NULL
7314 OR pol.item_revision = p_item_rev);
7315 EXCEPTION
7316 WHEN OTHERS THEN
7317 IF (l_debug = 1) THEN
7318 print_debug('error ' || SQLERRM, 4);
7319 --dbms_output.put_line('error '||SQLERRM);
7320 END IF;
7321 END;
7322 ELSIF p_document_type = 'RMA' THEN
7323 BEGIN
7324 SELECT l.task_id
7325 INTO l_task_id
7326 FROM oe_order_lines l
7327 WHERE l.line_category_code = 'RETURN'
7328 AND l.header_id = p_oe_header_id
7329 AND l.project_id = p_project_id
7330 AND(p_item_id IS NULL
7331 OR l.inventory_item_id = p_item_id)
7332 AND(p_item_rev IS NULL
7333 OR l.item_revision = p_item_rev);
7334 EXCEPTION
7335 WHEN OTHERS THEN
7336 IF (l_debug = 1) THEN
7337 print_debug('error ' || SQLERRM, 4);
7338 --dbms_output.put_line('error '||SQLERRM);
7339 END IF;
7340 END;
7341 ELSIF p_document_type = 'RECEIPT' THEN
7342 IF p_po_header_id IS NOT NULL THEN
7343 BEGIN
7344 SELECT pod.task_id
7345 INTO l_task_id
7346 FROM po_distributions_all pod, po_lines_all pol
7347 WHERE pod.po_header_id = p_po_header_id
7348 AND pod.project_id = p_project_id
7349 AND pod.po_header_id = pol.po_header_id
7350 AND pod.po_line_id = pol.po_line_id
7351 AND(p_item_id IS NULL
7352 OR pol.item_id = p_item_id)
7353 AND(p_item_rev IS NULL
7354 OR pol.item_revision = p_item_rev)
7355 GROUP BY pod.project_id, pod.task_id;
7356 EXCEPTION
7357 WHEN OTHERS THEN
7358 IF (l_debug = 1) THEN
7359 print_debug('error ' || SQLERRM, 4);
7360 --dbms_output.put_line('error '||SQLERRM);
7361 END IF;
7362 END;
7363 END IF;
7364 ELSIF p_oe_header_id IS NOT NULL THEN
7365 BEGIN
7366 SELECT task_id
7367 INTO l_task_id
7368 FROM oe_order_lines l
7369 WHERE l.line_category_code = 'RETURN'
7370 AND l.header_id = p_oe_header_id
7371 AND l.project_id = p_project_id
7372 AND(p_item_id IS NULL
7373 OR l.inventory_item_id = p_item_id)
7374 AND(p_item_rev IS NULL
7375 OR l.item_revision = p_item_rev)
7376 GROUP BY project_id, task_id;
7377 EXCEPTION
7378 WHEN OTHERS THEN
7379 IF (l_debug = 1) THEN
7380 print_debug('error ' || SQLERRM, 4);
7381 --dbms_output.put_line('error '||SQLERRM);
7382 END IF;
7383 END;
7384 END IF;
7385
7386 BEGIN
7387 IF (l_task_id IS NOT NULL) THEN
7388 x_task_number := inv_projectlocator_pub.get_task_number(l_task_id);
7389 print_debug('error ' || SQLERRM, 4);
7390 --dbms_output.put_line('task '||x_task_number);
7391 END IF;
7392 EXCEPTION
7393 WHEN OTHERS THEN
7394 NULL;
7395 END;
7396 END;
7397
7398 /**
7399 * This procedure checks for the following
7400 * 1. Whether the given LPN or its child LPN has contents. If
7401 * either the given
7402 * LPN or its child LPNs do not have any contents then
7403 * through error.
7404 * 2. Check If the LPN is already processed, and there is a
7405 * RTI record exists
7406 * for the LPN.
7407
7408 * @param p_lpn_id
7409 * @param x_return_status
7410 * @param x_msg_count
7411 * @param x_msg_data
7412 **/
7413 PROCEDURE validate_nested_lpn(
7414 p_lpn_id IN NUMBER
7415 , x_lpn_flag OUT NOCOPY VARCHAR2
7416 , x_return_status OUT NOCOPY VARCHAR2
7417 , x_msg_count OUT NOCOPY NUMBER
7418 , x_msg_data OUT NOCOPY VARCHAR2
7419 ) IS
7420 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
7421 l_msg_count NUMBER;
7422 l_msg_data VARCHAR2(4000);
7423 l_progress VARCHAR2(10);
7424 l_valid_lpn_flag VARCHAR(1) := 'Y';
7425 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7426 BEGIN
7427 x_lpn_flag := 'N'; -- 'Y -validlpn ' 'N- Invalid lpn'
7428 l_progress := 10;
7429
7430 IF (l_debug = 1) THEN
7431 print_debug('lpn_id: ' || TO_CHAR(p_lpn_id), 1);
7432 END IF;
7433
7434 -- Check at least one child LPN has contents.
7435
7436 BEGIN
7437 -- Bug 3440456
7438 -- The following is changed because the join with WLPN is unnecessary
7439 /*SELECT 'Y'
7440 INTO x_lpn_flag
7441 FROM wms_license_plate_numbers lpn, wms_lpn_contents wlc
7442 WHERE lpn.lpn_id = wlc.parent_lpn_id
7443 AND lpn_id IN (SELECT lpn_id
7444 FROM wms_license_plate_numbers wln
7445 START WITH lpn_id = p_lpn_id
7446 CONNECT BY parent_lpn_id = PRIOR lpn_id);*/
7447
7448 -- Bug# 3633708: Performance Fixes
7449 -- The following query is bad because it does a full table scan on WLC
7450 /*SELECT 'Y'
7451 INTO x_lpn_flag
7452 FROM wms_lpn_contents wlc
7453 WHERE wlc.parent_lpn_id IN (SELECT lpn_id
7454 FROM wms_license_plate_numbers wln
7455 START WITH lpn_id = p_lpn_id
7456 CONNECT BY parent_lpn_id = PRIOR lpn_id);*/
7457
7458 -- Bug# 3633708: Performance Fixes
7459 -- Use this query instead
7460 SELECT 'Y'
7461 INTO x_lpn_flag
7462 FROM wms_license_plate_numbers wln
7463 WHERE EXISTS (SELECT '1'
7464 FROM wms_lpn_contents wlc
7465 WHERE wlc.parent_lpn_id = wln.lpn_id)
7466 START WITH wln.lpn_id = p_lpn_id
7467 CONNECT BY wln.parent_lpn_id = PRIOR wln.lpn_id;
7468
7469 EXCEPTION
7470 WHEN NO_DATA_FOUND THEN -- item controls are valid
7471 x_lpn_flag := 'N';
7472 WHEN TOO_MANY_ROWS THEN
7473 x_lpn_flag := 'Y';
7474 END;
7475
7476 IF x_lpn_flag = 'N' THEN
7477 RETURN;
7478 END IF;
7479
7480 -- Check None of the child LPNs are already processed and have pending RTI transactions
7481
7482 BEGIN
7483 --
7484 -- 3440456
7485 -- Retrieval of x_lpn_flag is changed
7486 --
7487 SELECT 'Y'
7488 INTO x_lpn_flag
7489 FROM wms_license_plate_numbers lpn, wms_lpn_contents wlc, rcv_transactions_interface rti
7490 WHERE lpn.lpn_id = wlc.parent_lpn_id
7491 AND lpn.lpn_id = rti.lpn_id
7492 AND rti.transaction_status_code = 'PENDING'
7493 AND lpn.lpn_id IN(SELECT lpn_id
7494 FROM wms_license_plate_numbers wln
7495 START WITH lpn_id = p_lpn_id
7496 CONNECT BY parent_lpn_id = PRIOR lpn_id);
7497 EXCEPTION
7498 WHEN NO_DATA_FOUND THEN
7499 x_lpn_flag := 'N';
7500 WHEN TOO_MANY_ROWS THEN
7501 x_lpn_flag := 'Y';
7502 END;
7503 EXCEPTION
7504 WHEN OTHERS THEN
7505 x_lpn_flag := 'N';
7506 x_return_status := fnd_api.g_ret_sts_unexp_error;
7507 print_debug(SQLCODE, 1);
7508
7509 IF SQLCODE IS NOT NULL THEN
7510 l_progress := 100;
7511 inv_mobile_helper_functions.sql_error('validate_nested_lpns', l_progress, SQLCODE);
7512 END IF;
7513 END validate_nested_lpn;
7514
7515 /**
7516 * This procedure takes in the LPN and fetches the LPN context,
7517 * subinventory code and locator id.
7518 * If the LPN resides in receiving, it also fetches the subinventory
7519 * and locator for that LPN
7520 **/
7521 PROCEDURE get_rcv_sub_loc(
7522 x_return_status OUT NOCOPY VARCHAR2
7523 , x_msg_count OUT NOCOPY NUMBER
7524 , x_msg_data OUT NOCOPY VARCHAR2
7525 , x_lpn_context OUT NOCOPY NUMBER
7526 , x_locator_segs OUT NOCOPY VARCHAR2
7527 , x_location_id OUT NOCOPY NUMBER
7528 , x_location_code OUT NOCOPY VARCHAR2
7529 , x_sub_code OUT NOCOPY VARCHAR2
7530 , x_locator_id OUT NOCOPY NUMBER
7531 , p_lpn_id IN NUMBER
7532 , p_organization_id IN NUMBER) IS
7533 l_count NUMBER;
7534 l_progress VARCHAR2(10);
7535 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7536 l_sub_code mtl_secondary_inventories.secondary_inventory_name%TYPE;
7537 l_locator_id NUMBER;
7538 l_location_id NUMBER;
7539 l_auto_transact_code VARCHAR2(10);
7540 BEGIN
7541 x_return_status := fnd_api.g_ret_sts_success;
7542
7543 IF (l_debug = 1) THEN
7544 print_debug('Enter get_rcv_sub_loc: 10:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7545 print_debug('Parameters passed : 10.1: p_organization_id - ' || p_organization_id, 4);
7546 print_debug('Parameters passed : 10.2: p_lpn_id - ' || p_lpn_id, 4);
7547 END IF;
7548
7549 --First check the lpn_context
7550 l_progress := '20';
7551 BEGIN
7552 SELECT lpn_context
7553 , subinventory_code
7554 , locator_id
7555 INTO x_lpn_context
7556 , l_sub_code
7557 , l_locator_id
7558 FROM wms_license_plate_numbers
7559 WHERE lpn_id = p_lpn_id;
7560 EXCEPTION
7561 WHEN OTHERS THEN
7562 x_lpn_context := 5;
7563 x_locator_segs := NULL;
7564 x_locator_id := NULL;
7565 x_location_id := NULL;
7566 x_location_code := NULL;
7567 x_sub_code := NULL;
7568 RETURN;
7569 END;
7570
7571 --If the LPN has a subinventory associated, get the location_code
7572 --from hr_locations using location_id in mtl_secondary_inventories for that sub
7573 IF (l_debug = 1) THEN
7574 print_debug('get_rcv_sub_loc: 20: values from WLPN - context: ' || x_lpn_context ||
7575 ', sub_code: ' || l_sub_code || ', loc_id: ' || l_locator_id, 4);
7576 END IF;
7577
7578 IF l_sub_code IS NULL THEN
7579 BEGIN
7580 l_progress := '30';
7581 --Get the subinventory, locator_id and routing from rcv_transactions_interface
7582 --If there exists one and it is not direct then error out with the
7583 --"Invalid LPN context" error since we cannot commingle routings in the same LPN
7584 SELECT subinventory
7585 , locator_id
7586 , location_id
7587 , auto_transact_code
7588 INTO l_sub_code
7589 , l_locator_id
7590 , l_location_id
7591 , l_auto_transact_code
7592 FROM rcv_transactions_interface
7593 WHERE transfer_lpn_id = p_lpn_id
7594 AND transaction_type = 'RECEIVE'
7595 AND transaction_status_code = 'PENDING'
7596 AND processing_status_code <> 'ERROR'
7597 AND ROWNUM = 1;
7598
7599
7600 IF (NVL(l_auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7601 x_return_status := fnd_api.g_ret_sts_error;
7602 IF ((inv_rcv_common_apis.g_wms_patch_level >= inv_rcv_common_apis.g_patchset_j) or
7603 (inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j)) THEN
7604 x_msg_data := 'INV_CANNOT_COMMINGLE_ROUTING';
7605 fnd_message.set_name('INV', 'INV_CANNOT_COMMINGLE_ROUTING');
7606 ELSE
7607 x_msg_data := 'INV_INVALID_LPN_CONTEXT';
7608 fnd_message.set_name('INV', 'INV_INVALID_LPN_CONTEXT');
7609 END IF;
7610 fnd_msg_pub.ADD;
7611 RETURN;
7612 END IF;
7613 EXCEPTION
7614 WHEN NO_DATA_FOUND THEN
7615 BEGIN
7616 l_progress := 40;
7617 SELECT to_subinventory
7618 , to_locator_id
7619 , location_id
7620 INTO l_sub_code
7621 , l_locator_id
7622 , l_location_id
7623 FROM rcv_supply
7624 WHERE lpn_id = p_lpn_id
7625 AND to_organization_id = p_organization_id
7626 AND ROWNUM = 1;
7627 EXCEPTION
7628 WHEN OTHERS THEN
7629 x_sub_code := NULL;
7630 x_locator_id := NULL;
7631 x_locator_segs := NULL;
7632 x_location_id := NULL;
7633 x_location_code := NULL;
7634 RETURN;
7635 END;
7636 WHEN OTHERS THEN
7637 IF (l_debug = 1) THEN
7638 print_debug('get_sub_code: 20.5: Error occurred while fetching values from RTI', 1);
7639 END IF;
7640 RAISE FND_API.G_EXC_ERROR;
7641 END;
7642 END IF; --END IF l_sub_code IS NULL
7643
7644 x_locator_segs := NULL;
7645 x_location_code := NULL;
7646
7647 l_progress := '50';
7648
7649 IF l_sub_code IS NOT NULL THEN
7650 BEGIN
7651 SELECT location_code
7652 , location_id
7653 INTO x_location_code
7654 , x_location_id
7655 from hr_locations hl
7656 WHERE EXISTS
7657 ( SELECT 1
7658 FROM mtl_secondary_inventories msi
7659 WHERE organization_id = p_organization_id
7660 AND secondary_inventory_name = l_sub_code
7661 AND msi.location_id = hl.location_id)
7662 AND ROWNUM = 1;
7663 EXCEPTION
7664 WHEN OTHERS THEN
7665 x_location_id := NULL;
7666 x_location_code := NULL;
7667 END;
7668 ELSIF l_location_id IS NOT NULL THEN
7669 BEGIN
7670 l_progress := '60';
7671 SELECT location_code
7672 , location_id
7673 INTO x_location_code
7674 , x_location_id
7675 FROM hr_locations hl
7676 WHERE location_id = l_location_id
7677 AND ROWNUM = 1;
7678 EXCEPTION
7679 WHEN OTHERS THEN
7680 l_sub_code := NULL;
7681 l_locator_id := NULL;
7682 x_location_id := NULL;
7683 x_location_code := NULL;
7684 END;
7685 END IF;
7686
7687 --Get the locator segments only if sub and locator_id are set
7688 IF (l_sub_code IS NOT NULL AND l_locator_id IS NOT NULL) THEN
7689 l_progress := '70';
7690 BEGIN
7691 SELECT inv_project.get_locsegs(inventory_location_id, organization_id)
7692 INTO x_locator_segs
7693 FROM mtl_item_locations
7694 WHERE organization_id = p_organization_id
7695 AND inventory_location_id = l_locator_id;
7696 EXCEPTION
7697 WHEN OTHERS THEN
7698 x_locator_segs := NULL;
7699 END;
7700 END IF;
7701
7702 --Finally assign the values for output variables
7703 x_sub_code := l_sub_code;
7704 x_locator_id := l_locator_id;
7705
7706 IF (l_debug = 1) THEN
7707 print_debug(' lpn_context ' || x_lpn_context, 4);
7708 print_debug(' sub_code ' || x_sub_code, 4);
7709 print_debug(' location_code ' || x_location_code, 4);
7710 print_debug(' location_id ' || x_location_id, 4);
7711 print_debug(' locator_segs ' || x_locator_segs, 4);
7712 END IF;
7713
7714 EXCEPTION
7715 WHEN OTHERS THEN
7716 x_return_status := fnd_api.g_ret_sts_unexp_error;
7717 IF SQLCODE IS NOT NULL THEN
7718 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_sub_code', l_progress, SQLCODE);
7719 END IF;
7720 IF (l_debug = 1) THEN
7721 print_debug('Exitting get_sub_code - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7722 END IF;
7723 --
7724 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7725 fnd_msg_pub.add_exc_msg(g_pkg_name, 'get_sub_code');
7726 END IF;
7727 END get_rcv_sub_loc;
7728
7729 PROCEDURE validate_from_lpn(
7730 p_lpn_id IN NUMBER
7731 , p_req_id IN VARCHAR2
7732 , x_lpn_flag OUT NOCOPY VARCHAR2
7733 , x_count_of_lpns OUT NOCOPY NUMBER
7734 , x_return_status OUT NOCOPY VARCHAR2
7735 , x_msg_count OUT NOCOPY NUMBER
7736 , x_msg_data OUT NOCOPY VARCHAR2
7737 , p_shipment_num IN VARCHAR2
7738 , p_org_id IN NUMBER
7739 ) IS
7740 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
7741 l_msg_count NUMBER;
7742 l_msg_data VARCHAR2(4000);
7743 l_progress VARCHAR2(10);
7744 l_req_num VARCHAR2(10);
7745 l_valid_lpn_flag VARCHAR(1) := 'Y';
7746 l_order_header_id NUMBER;
7747 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7748 BEGIN
7749
7750 -- Intialize variables
7751 x_lpn_flag := 'Y'; -- 'Y -validlpn ' 'N- Invalid lpn'
7752 x_count_of_lpns := 1;
7753 x_return_status := fnd_api.g_ret_sts_success;
7754 l_progress := 10;
7755
7756
7757 IF (l_debug = 1) THEN
7758 print_debug('lpn_id: ' || TO_CHAR(p_lpn_id), 1);
7759 print_debug('req id : ' || p_req_id,1);
7760 END IF;
7761 -- Check if there is any existing RTI Record for the given LPN or their childs.
7762
7763 BEGIN
7764 SELECT 'N' INTO x_lpn_flag
7765 FROM rcv_transactions_interface
7766 WHERE lpn_id IN ( SELECT lpn_id FROM wms_license_plate_numbers
7767 START WITH lpn_id = p_lpn_id
7768 CONNECT BY parent_lpn_id = PRIOR lpn_id)
7769 AND transaction_status_code = 'PENDING'
7770 AND processing_status_code <> 'ERROR'
7771 AND ROWNUM = 1 ;
7772 EXCEPTION
7773 WHEN no_data_found THEN
7774 x_lpn_flag := 'Y';
7775 WHEN too_many_rows THEN
7776 x_lpn_flag := 'N';
7777 END;
7778
7779 IF (l_debug = 1) THEN
7780 print_debug('x_lpn_flag after checking for RTI records: ' || x_lpn_flag, 1);
7781 END IF;
7782
7783
7784 -- Get Sales order header id for the given LPN
7785
7786 l_progress := '10';
7787 IF (p_req_id IS NOT NULL) AND (x_lpn_flag = 'Y') THEN
7788 SELECT segment1
7789 INTO l_req_num
7790 FROM po_requisition_headers_all
7791 WHERE requisition_header_id = p_req_id;
7792
7793 IF (l_debug = 1) THEN
7794 print_debug('segment1 : ' || l_req_num, 1);
7795 END IF;
7796
7797
7798 l_progress := '20';
7799 SELECT header_id
7800 INTO l_order_header_id
7801 FROM oe_order_headers_all
7802 WHERE orig_sys_document_ref = l_req_num
7803 AND order_source_id = 10;
7804
7805 IF (l_debug = 1) THEN
7806 print_debug('oe_order_header_id : ' || l_order_header_id, 1);
7807 END IF;
7808
7809
7810 l_progress := '30';
7811
7812 /* Bug 5073354 : Changed following query to access the base table wsh_delivery_details
7813 ** instead of using the view wsh_delivery_details_ob_grp_v and
7814 ** wsh_delivery_assignments instead of wsh_delivery_assignments_v. This
7815 ** is being done to overcome performance issues reported for 10G database.
7816 */
7817
7818 -- verify the LPN belongs choosen internal order.
7819 BEGIN
7820 SELECT 'Y' INTO x_lpn_flag
7821 FROM wsh_delivery_details wdd,
7822 wsh_delivery_assignments wda,
7823 wsh_delivery_details wdd1
7824 WHERE wdd.lpn_id IN
7825 (SELECT lpn_id FROM wms_license_plate_numbers
7826 START WITH lpn_id = p_lpn_id
7827 CONNECT BY parent_lpn_id = PRIOR lpn_id)
7828 AND wdd.delivery_detail_id = wda.parent_delivery_detail_id
7829 AND wda.delivery_detail_id = wdd1.delivery_detail_id
7830 AND NVL(wdd.line_direction,'O') IN ('O','IO')
7831 AND wdd1.source_header_id = l_order_header_id
7832 AND ROWNUM = 1;
7833 EXCEPTION
7834 WHEN NO_DATA_FOUND THEN
7835 x_lpn_flag := 'N';
7836 WHEN TOO_MANY_ROWS THEN
7837 x_lpn_flag := 'Y';
7838 END;
7839 l_progress := 40;
7840
7841 IF (l_debug = 1) THEN
7842 print_debug('x_lpn_flag after checking lpn belongs to this internal order : ' || x_lpn_flag, 1);
7843 END IF;
7844
7845 /* Bug 5073354 : Changed following query to access the base table wsh_delivery_details
7846 ** instead of using the view wsh_delivery_details_ob_grp_v and
7847 ** wsh_delivery_assignments instead of wsh_delivery_assignments_v. This
7848 ** is being done to overcome performance issues reported for 10G database.
7849 */
7850
7851 -- Verify this LPN does not belong any other internal requision
7852 IF(x_lpn_flag = 'Y') THEN
7853
7854 --BUG 4237975: break up query that joins wlpn with wsh
7855 --to improve performance
7856 FOR l_lpn_rec IN (SELECT lpn_id FROM wms_license_plate_numbers
7857 START WITH lpn_id = p_lpn_id
7858 CONNECT BY parent_lpn_id = PRIOR lpn_id) LOOP
7859 BEGIN
7860 SELECT 'N' INTO x_lpn_flag
7861 FROM wsh_delivery_details wdd,
7862 wsh_delivery_assignments wda,
7863 wsh_delivery_details wdd1
7864 WHERE wdd.lpn_id = l_lpn_rec.lpn_id
7865 AND wdd.delivery_detail_id = wda.parent_delivery_detail_id
7866 AND wda.delivery_detail_id = wdd1.delivery_detail_id
7867 AND NVL(wdd.line_direction,'O') IN ('O','IO')
7868 AND wdd1.source_header_id <> l_order_header_id
7869 AND ROWNUM = 1;
7870 EXCEPTION
7871 WHEN TOO_MANY_ROWS THEN
7872 x_lpn_flag := 'N';
7873 WHEN OTHERS THEN
7874 NULL;
7875 END;
7876
7877 IF (x_lpn_flag = 'N') THEN
7878 EXIT;
7879 END IF;
7880 END LOOP;
7881
7882
7883 IF (l_debug = 1) THEN
7884 print_debug('x_lpn_flag after checking lpn belongs oter internal orders : ' || x_lpn_flag, 1);
7885 END IF;
7886
7887 END IF;
7888
7889
7890 l_progress :=50;
7891
7892 IF (l_debug = 1) THEN
7893 print_debug('x_lpn_flag: ' || x_lpn_flag, 4);
7894 END IF;
7895
7896 /* Bug 5073354 : Changed following query to access the base table wsh_delivery_details
7897 ** instead of using the view wsh_delivery_details_ob_grp_v and
7898 ** wsh_delivery_assignments instead of wsh_delivery_assignments_v. This
7899 ** is being done to overcome performance issues reported for 10G database.
7900 */
7901
7902 -- Check are there any LPNs left for this order.
7903 BEGIN
7904 SELECT 1 INTO x_count_of_lpns
7905 FROM wsh_delivery_details wdd,
7906 wsh_delivery_assignments wda,
7907 wsh_delivery_details wdd1
7908 WHERE wdd.lpn_id NOT IN
7909 (SELECT lpn_id FROM wms_license_plate_numbers
7910 START WITH lpn_id = p_lpn_id
7911 CONNECT BY parent_lpn_id = PRIOR lpn_id)
7912 AND wdd.delivery_detail_id = wda.parent_delivery_detail_id
7913 AND wda.delivery_detail_id = wdd1.delivery_detail_id
7914 AND NVL(wdd.line_direction,'O') IN ('O','IO')
7915 AND wdd1.source_header_id = l_order_header_id
7916 AND NOT EXISTS
7917 (SELECT lpn_id FROM rcv_transactions_interface
7918 WHERE lpn_id = wdd.lpn_id
7919 AND transaction_status_code = 'PENDING'
7920 AND processing_status_code <> 'ERROR')
7921 AND ROWNUM = 1;
7922 EXCEPTION
7923 WHEN NO_DATA_FOUND THEN
7924 x_count_of_lpns := 0;
7925 WHEN TOO_MANY_ROWS THEN
7926 x_count_of_lpns := 1;
7927 END;
7928
7929 IF (l_debug = 1) THEN
7930 print_debug('x_count_of_lpns: ' || x_count_of_lpns, 4);
7931 END IF;
7932
7933 ELSIF (p_shipment_num IS NOT NULL) THEN
7934 IF (l_debug = 1) THEN
7935 print_debug('p_shipment_num = ' || p_shipment_num, 4);
7936 END IF;
7937
7938 BEGIN
7939 SELECT 1 INTO x_count_of_lpns
7940 FROM wms_license_plate_numbers wlpn1, rcv_shipment_headers rsh
7941 WHERE rsh.shipment_num = p_shipment_num
7942 AND wlpn1.source_name = rsh.shipment_num
7943 AND ((wlpn1.lpn_context = 6 AND wlpn1.organization_id = rsh.organization_id) OR
7944 (wlpn1.lpn_context = 7 AND wlpn1.organization_id = rsh.ship_to_org_id))
7945 AND EXISTS (SELECT wlpn2.lpn_id
7946 FROM wms_license_plate_numbers wlpn2
7947 START WITH wlpn2.lpn_id = wlpn1.lpn_id
7948 CONNECT BY PRIOR wlpn2.lpn_id = wlpn2.parent_lpn_id
7949 INTERSECT
7950 SELECT rsl.asn_lpn_id
7951 FROM rcv_shipment_lines rsl
7952 WHERE rsl.shipment_header_id = rsh.shipment_header_id
7953 AND NOT exists (SELECT 1
7954 FROM rcv_transactions_interface rti
7955 WHERE rti.lpn_id = rsl.asn_lpn_id
7956 AND rti.transfer_lpn_id = rsl.asn_lpn_id
7957 AND rti.to_organization_id = rsl.to_organization_id
7958 AND rti.processing_status_code <> 'ERROR'
7959 AND rti.transaction_status_code <> 'ERROR'
7960 )
7961 AND rsl.asn_lpn_id NOT IN (SELECT wlpn3.lpn_id
7962 FROM wms_license_plate_numbers wlpn3
7963 START WITH wlpn3.lpn_id = p_lpn_id
7964 CONNECT BY PRIOR wlpn3.lpn_id = wlpn3.parent_lpn_id
7965 )
7966 );
7967 EXCEPTION
7968 WHEN no_data_found THEN
7969 x_count_of_lpns := 0;
7970 WHEN too_many_rows THEN
7971 x_count_of_lpns := 1;
7972 END;
7973
7974 IF (l_debug = 1) THEN
7975 print_debug('Num of unprocessed LPNs: ' || x_count_of_lpns, 4);
7976 END IF;
7977
7978 END IF; -- End if for p_req_header_id is not null
7979
7980 l_progress := 60;
7981
7982 EXCEPTION
7983 WHEN OTHERS THEN
7984 x_return_status := fnd_api.g_ret_sts_unexp_error;
7985
7986 IF SQLCODE IS NOT NULL THEN
7987 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.validate_from_lpn', l_progress, SQLCODE);
7988 END IF;
7989
7990 IF (l_debug = 1) THEN
7991 print_debug('Exitting validate_from_lpn - other exception:' || l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7992 END IF;
7993
7994 --
7995 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7996 fnd_msg_pub.add_exc_msg(g_pkg_name, 'validate_from_lpn');
7997 END IF;
7998
7999 END validate_from_lpn;
8000
8001
8002 /****************************************************
8003 * This procedure clears the lot numbers from the
8004 * global variable when there is an error.
8005 * This procedure has been added for fixing the bug ( # 3156689)
8006 ****************************************************/
8007
8008 PROCEDURE clear_lot_rec
8009 IS
8010 BEGIN
8011 print_debug('Enter clear_lot_rec: 1 '|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 1);
8012
8013 inv_rcv_std_rcpt_apis.g_rcpt_lot_qty_rec_tb.DELETE;
8014
8015 print_debug('clear_lot_rec: 2 End of Procedure ',1);
8016
8017 END clear_lot_rec;
8018
8019 --<R12 MOAC START>
8020
8021 /* Function get_operating_unit_id returns the org_id. */
8022
8023 FUNCTION get_operating_unit_id ( p_receipt_source_code IN VARCHAR2,
8024 p_po_header_id IN NUMBER,
8025 p_req_line_id IN NUMBER,
8026 p_oe_order_header_id IN NUMBER
8027 )
8028 RETURN NUMBER IS
8029
8030 l_operating_unit_id MO_GLOB_ORG_ACCESS_TMP.ORGANIZATION_ID%TYPE;
8031
8032 l_progress VARCHAR2(10);
8033 l_debug NUMBER;
8034
8035 BEGIN
8036
8037 IF p_receipt_source_code = 'VENDOR' THEN
8038
8039 l_progress := '010';
8040
8041 IF p_po_header_id IS NOT NULL THEN
8042
8043 Select org_id
8044 into l_operating_unit_id
8045 from po_headers_all
8046 where po_header_id = p_po_header_id;
8047
8048 END IF;
8049
8050 ELSIF p_receipt_source_code = 'INTERNAL ORDER' THEN
8051
8052 l_progress := '020';
8053
8054 IF p_req_line_id IS NOT NULL THEN
8055
8056 Select org_id
8057 into l_operating_unit_id
8058 from po_requisition_lines_all
8059 where requisition_line_id = p_req_line_id;
8060
8061 END IF;
8062
8063 ELSIF p_receipt_source_code = 'CUSTOMER' THEN
8064
8065 l_progress := '030';
8066
8067 IF p_oe_order_header_id IS NOT NULL THEN
8068
8069 Select org_id
8070 into l_operating_unit_id
8071 from oe_order_headers_all
8072 where header_id = p_oe_order_header_id;
8073
8074 END IF;
8075
8076 END IF;
8077
8078 RETURN l_operating_unit_id;
8079
8080 EXCEPTION
8081 WHEN NO_DATA_FOUND THEN
8082
8083 l_debug := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8084
8085 IF (l_debug = 1) THEN
8086 print_debug('Error getting org_id in get_operating_unit_id(): '||l_progress, 1);
8087 END IF;
8088
8089 END get_operating_unit_id;
8090
8091 --<R12 MOAC END>
8092
8093 /** Start of fix for bug 5065079 (FP of bug 4651362)
8094 * Following procedure is added to count the number of open shipments for
8095 * an internal requisition.
8096 **/
8097 PROCEDURE count_req_open_shipments
8098 (p_organization_id IN NUMBER,
8099 p_requisition_header_id IN NUMBER,
8100 x_return_status OUT NOCOPY VARCHAR2 ,
8101 x_msg_count OUT NOCOPY NUMBER ,
8102 x_msg_data OUT NOCOPY VARCHAR2,
8103 x_open_shipments OUT NOCOPY NUMBER
8104 )IS
8105 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8106 BEGIN
8107 x_return_status := fnd_api.g_ret_sts_success;
8108 IF (l_debug = 1) THEN
8109 print_debug('Enter check_req_open_shipments 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8110 print_debug(' p_requisition_header_id =>'||p_requisition_header_id,1);
8111
8112 END IF;
8113 BEGIN
8114 SELECT count(DISTINCT rsl.shipment_header_id)
8115 INTO x_open_shipments
8116 FROM rcv_shipment_lines rsl, po_requisition_lines prl
8117 WHERE to_organization_id = p_organization_id
8118 AND nvl(rsl.shipment_line_status_code, ' ') <> 'FULLY RECEIVED'
8119 AND prl.requisition_header_id = p_requisition_header_id
8120 AND rsl.requisition_line_id = prl.requisition_line_id;
8121
8122 EXCEPTION
8123 WHEN OTHERS THEN
8124 IF (l_debug = 1) THEN
8125 print_debug(' Unable to query shipment. SQLCODE:'||SQLCODE||' SQLERM:'||Sqlerrm,1);
8126 END IF;
8127 x_open_shipments := 0;
8128 END;
8129
8130 IF (l_debug = 1) THEN
8131 print_debug('x_open_shipments:'||x_open_shipments,1);
8132 END IF;
8133
8134 EXCEPTION
8135 WHEN OTHERS THEN
8136 x_return_status := fnd_api.g_ret_sts_unexp_error;
8137 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8138 IF (l_debug = 1) THEN
8139 print_debug('check_req_open_shipments 30 - Unexpected error',1);
8140 END IF;
8141 END count_req_open_shipments;
8142
8143 -- Bug 5068944 (FP of bug 4992317)
8144 -- Defaulting the UOM from Receipt Transaction for Deliver Transaction of PO
8145 PROCEDURE get_rec_uom_code(
8146 x_return_status OUT NOCOPY VARCHAR2
8147 , x_uom_code OUT NOCOPY VARCHAR2
8148 , p_shipment_header_id IN NUMBER
8149 , p_item_id IN NUMBER
8150 , p_organization_id IN NUMBER
8151 ) IS
8152 l_progress VARCHAR2(10);
8153 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8154 l_uom_code VARCHAR2(3);
8155 BEGIN
8156 x_return_status := fnd_api.g_ret_sts_success;
8157 x_uom_code := NULL;
8158 IF (l_debug = 1) THEN
8159 print_debug('Entering get_rec_uom_code',4);
8160 print_debug('Parameters passed : 10.1: p_shipment_header_id - ' || p_shipment_header_id , 4);
8161 print_debug('Parameters passed : 10.2: p_item_id - ' || p_item_id, 4);
8162 print_debug('Parameters passed : 10.3: p_organization_id - ' || p_organization_id, 4);
8163 END IF;
8164
8165 l_progress := '10';
8166
8167 IF p_shipment_header_id IS NOT NULL AND p_item_id IS NOT NULL THEN
8168 l_progress := '20';
8169 BEGIN
8170 SELECT DISTINCT mum.uom_code
8171 INTO l_uom_code
8172 FROM rcv_transactions rt , rcv_shipment_lines rsl, mtl_units_of_measure mum
8173 WHERE rt.transaction_type = 'RECEIVE'
8174 AND rsl.item_id = p_item_id
8175 AND rt.organization_id = p_organization_id
8176 AND rsl.shipment_header_id = rt.shipment_header_id
8177 AND rt.unit_of_measure IS NOT NULL
8178 AND rt.shipment_header_id = p_shipment_header_id
8179 AND mum.unit_of_measure(+) = rt.unit_of_measure;
8180 EXCEPTION
8181 WHEN OTHERS THEN
8182 l_uom_code := NULL;
8183 END;
8184
8185 IF (l_uom_code IS NOT NULL) THEN
8186 x_uom_code := inv_ui_item_lovs.get_conversion_rate
8187 (l_uom_code,
8188 p_organization_id,
8189 p_item_id);
8190 ELSE
8191 x_uom_code := NULL;
8192 END IF;--END IF (l_uom_code IS NOT NULL) THEN
8193 END IF;--IF p_shipment_header_id IS NOT NULL AND p_item_id IS NOT NULL THEN
8194
8195 IF (l_debug = 1) THEN
8196 print_debug('l_uom_code:'||l_uom_code,4);
8197 print_debug('x_uom_code:'||x_uom_code,4);
8198 END IF;
8199
8200 EXCEPTION
8201 WHEN OTHERS THEN
8202
8203 x_return_status := fnd_api.g_ret_sts_unexp_error;
8204
8205 IF SQLCODE IS NOT NULL THEN
8206 inv_mobile_helper_functions.sql_error('inv_rcv_common_apis.get_rec_uom_code', l_progress, SQLCODE);
8207 END IF;
8208
8209 IF (l_debug = 1) THEN
8210 print_debug('Exiting get_rec_uom_code - other exception:' || l_progress ||' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8211 END IF;
8212
8213 --
8214 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8215 fnd_msg_pub.add_exc_msg(g_pkg_name, 'get_rec_uom_code');
8216 END IF;
8217
8218 END get_rec_uom_code; -- Bug 5068944 Ends
8219
8220 END inv_rcv_common_apis;