1 PACKAGE BODY rcv_roi_transaction
2 /* $Header: RCVPRETB.pls 120.83.12020000.7 2013/01/25 03:45:12 honwei ship $*/
3 AS
4 g_asn_debug VARCHAR2(1) := asn_debug.is_debug_on; -- Bug 9152790: rcv debug enhancement
5 x_progress VARCHAR2(3);
6 g_pkg_name CONSTANT VARCHAR2(30) := 'RCV_ROI_TRANSACTION';
7 x_drop_ship_flag VARCHAR2(1) := 'N';
8 x_auto_deliver VARCHAR2(1);
9 e_validation_error EXCEPTION;
10
11 -- Bug 14725305 added for dropship project po
12 -- This will just create a new locator for dynamic locator setup.
13 FUNCTION getloc(x_locid OUT NOCOPY NUMBER, p_org_id NUMBER, p_locctrl NUMBER, p_segmentarray fnd_flex_ext.segmentarray) return BOOLEAN is
14 l_nseg NUMBER;
15 l_seglist fnd_flex_key_api.segment_list;
16 l_fftype fnd_flex_key_api.flexfield_type;
17 l_ffstru fnd_flex_key_api.structure_type;
18 l_segment_type fnd_flex_key_api.segment_type;
19 l_locator VARCHAR2(32000);
20 l_error_exp VARCHAR2(250);
21 l_structure_list fnd_flex_key_api.structure_list;
22 l_nstru NUMBER;
23 l_index NUMBER;
24 l_locid NUMBER;
25 l_delim VARCHAR2(1);
26 l_val BOOLEAN := FALSE;
27 DYNAMIC CONSTANT NUMBER := 3;
28 l_operation VARCHAR2(100);
29 -- Local array to hold the data for getting the cancatenated segment.
30 l_segmentarray fnd_flex_ext.segmentarray;
31 BEGIN
32
33 fnd_flex_key_api.set_session_mode('seed_data');
34
35 -- find flex field type
36 l_fftype := fnd_flex_key_api.find_flexfield('INV', 'MTLL');
37
38 -- find flex structure type
39 l_ffstru := fnd_flex_key_api.find_structure(l_fftype, 101);
40 -- find segment list for the key flex field
41 fnd_flex_key_api.get_segments(l_fftype, l_ffstru, TRUE, l_nseg, l_seglist);
42
43 -- find segment delimiter
44 l_delim := l_ffstru.segment_separator;
45
46 -- get the corresponding column for all segments
47 --
48 -- The default segments for the LocatorKFF is SEGMENT1 - SEGMENT20
49 -- 'To_number(Substr(l_segment_type.column_name, 8))' gives the
50 -- number of the segment i.e. 1 - 20 which is used as index to
51 -- fetch the corresponding columns from segments array
52 --
53 FOR l_loop IN 1..l_nseg LOOP
54
55 l_segment_type := fnd_flex_key_api.find_segment(l_fftype, l_ffstru, l_seglist(l_loop));
56 -- Bug Fix#4747090
57 --l_segmentarray contains data in the order flexfield is defined. Used in creating cancatenated segments for validation.
58 l_segmentarray(l_loop) := p_segmentarray(To_number(Substr(l_segment_type.column_name, 8)));
59 END LOOP;
60
61 -- Gets the encoded cancatenated string
62 l_locator := fnd_flex_ext.concatenate_segments(n_segments => l_nseg,
63 segments => l_segmentarray,
64 delimiter => l_delim);
65 IF (g_asn_debug = 'Y') THEN
66 asn_debug.put_line('Locator is : ' || l_locator);
67 END IF;
68
69 /*
70 * If Locator control allows dynamic creation then create the combination
71 * if it does not already exist else just check if it exists.
72 */
73 if p_locctrl = 3 then
74 l_operation := 'CREATE_COMBINATION';
75 else
76 l_operation := 'FIND_COMBINATION';
77 end if;
78
79 l_val := FND_FLEX_KEYVAL.Validate_Segs(
80 OPERATION => l_operation,
81 APPL_SHORT_NAME => 'INV',
82 KEY_FLEX_CODE => 'MTLL',
83 STRUCTURE_NUMBER => 101,
84 CONCAT_SEGMENTS => l_locator,
85 VALUES_OR_IDS => 'I',
86 DATA_SET => p_org_id ) ;
87 if l_val then
88 x_locid := fnd_flex_keyval.combination_id;
89 else
90 x_locid := NULL;
91 l_error_exp := substr(fnd_flex_key_api.message(),1,240);
92 IF (g_asn_debug = 'Y') THEN
93 asn_debug.put_line('Error in getloc : ' || l_error_exp);
94 asn_debug.put_line('Error in getloc : error_segment :' || FND_FLEX_KEYVAL.error_segment);
95 asn_debug.put_line('Error in getloc : error_message :' || FND_FLEX_KEYVAL.error_message);
96 asn_debug.put_line('Error in getloc : encoded_error_message :' || FND_FLEX_KEYVAL.encoded_error_message);
97 END IF;
98 end if;
99
100 return l_val;
101
102 EXCEPTION
103
104 WHEN OTHERS THEN
105
106 l_error_exp := substr(fnd_flex_key_api.message(),1,240);
107 IF (g_asn_debug = 'Y') THEN
108 asn_debug.put_line('Error in getloc : ' || l_error_exp);
109 asn_debug.put_line('Error:'||substr(sqlerrm,1,250));
110 END IF;
111 x_locid := NULL;
112 RETURN FALSE;
113
114 END getloc;
115
116 /* Bug 14725305 added for dropship project po, the logic is:
117 1. Default the subinventory as in default_to_subloc_info.
118 2. If locator control is 2/3
119 get the default locator with project and task.
120 if no default locator with proj/task found
121 if locator control =2
122 raise error.
123 if locator control=3
124 get the default locator without proj/task (this will be used as the physical location)
125 getloc: create a new locator by passing segment19/20 as the current proj/task.
126 once the locator is created, stamp the below fields in MIL
127 - status (using material status api)
128 - physical location id (ie, default locator without proj/task )
129 - subinventory (defaulted subinv)
130 3. Copied the remaining logic from default_to_subloc_info.
131 */
132 PROCEDURE default_for_pjm_dropship(
133 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
134 n IN BINARY_INTEGER
135 ) IS
136 l_from_subinventory rcv_transactions.from_subinventory%TYPE;
137 l_from_locator_id rcv_transactions.from_locator_id%TYPE;
138 x_locator_control NUMBER;
139 x_default_subinventory VARCHAR2(10);
140 x_default_locator_id NUMBER;
141 x_success BOOLEAN;
142 l_segmentarray fnd_flex_ext.segmentarray;
143 l_loc_id number;
144 BEGIN
145 IF (g_asn_debug = 'Y') THEN
146 asn_debug.put_line('inside default_for_pjm_dropship');
147 END IF;
148
149 /* Get default subinventory from the setup if it is a direct delivery
150 * or just a delivery and if subinventory is null.
151 */
152 IF (x_cascaded_table(n).transaction_type IN('RECEIVE', 'DELIVER')) THEN --{
153 IF ( (x_cascaded_table(n).auto_transact_code <> 'RECEIVE')
154 OR x_cascaded_table(n).auto_transact_code IS NULL) THEN --{
155 /*
156 ** A subinventory must have been defined on the po or a default
157 ** must be available for the item. If it's not already defined
158 ** then go get it out of inventory. If you're using express
159 ** then it's ok to get the default rather than having it be
160 ** defined on the record
161 */
162 IF (x_cascaded_table(n).subinventory IS NULL) THEN --{
163 /*
164 ** If you're using express then it's ok to get the default
165 ** rather than having it be defined on the record
166 */
167 x_progress := '120';
168 po_subinventories_s.get_default_subinventory(x_cascaded_table(n).to_organization_id,
169 x_cascaded_table(n).item_id,
170 x_cascaded_table(n).subinventory
171 );
172
173 IF (g_asn_debug = 'Y') THEN
174 asn_debug.put_line('Defaulting subinventory from item: Sub = ' || x_cascaded_table(n).subinventory);
175 END IF;
176 END IF; --} (X_cascaded_table(n).subinventory IS NULL)
177 END IF; --}
178
179 /* We can have sub/loc for receive and deliver transaction. If subinventory
180 * is not null and locator_id is null, then get the default locator_id if
181 * the there is a locator.
182 */
183 IF (x_cascaded_table(n).subinventory IS NOT NULL) THEN --{
184 x_progress := '122';
185 po_subinventories_s.get_locator_control(x_cascaded_table(n).to_organization_id,
186 x_cascaded_table(n).subinventory,
187 x_cascaded_table(n).item_id,
188 x_locator_control
189 );
190
191 IF (g_asn_debug = 'Y') THEN
192 asn_debug.put_line('Locator Control = ' || TO_CHAR(x_locator_control));
193 END IF;
194
195 /*
196 ** If locator control is 2 which means it is under predefined
197 ** locator contol or 3 which means it's under dynamic (any value)
198 ** locator control then you need to go get the default locator id
199 */
200 IF ( ( x_locator_control = 2 OR x_locator_control = 3)
201 AND x_cascaded_table(n).locator_id IS NULL) THEN --{
202 x_progress := '123';
203
204 BEGIN
205 SELECT mld.locator_id
206 INTO x_cascaded_table(n).locator_id
207 FROM mtl_item_loc_defaults mld,
208 mtl_item_locations mil
209 WHERE mld.inventory_item_id = x_cascaded_table(n).item_id
210 AND mld.organization_id = x_cascaded_table(n).to_organization_id
211 AND mld.subinventory_code = x_cascaded_table(n).subinventory
212 AND mld.default_type = 2
213 AND mld.organization_id = mil.organization_id
214 AND mld.locator_id = mil.inventory_location_id
215 AND trunc(NVL(mil.disable_date, trunc(sysdate+1))) > trunc(sysdate)
216 AND mil.segment19 = x_cascaded_table(n).project_id
217 AND mil.project_id = x_cascaded_table(n).project_id
218 AND nvl(mil.segment20,-99) = nvl(x_cascaded_table(n).task_id,-99)
219 AND nvl(mil.task_id,-99) = nvl(x_cascaded_table(n).task_id,-99);
220
221 EXCEPTION
222 WHEN NO_DATA_FOUND THEN
223
224 IF (x_locator_control = 2) THEN
225 IF (g_asn_debug = 'Y') THEN
226 asn_debug.put_line('Cause: Receiving preprocessor could not default a locator for this trxn.');
227 END IF;
228
229 -- Change the transaction back to ASN import
230 x_cascaded_table(n).transaction_type := 'SHIP';
231 x_cascaded_table(n).auto_transact_code := 'SHIP';
232 -- Reset the flag so that it won't affect the next transaction.
233 x_auto_deliver := 'N';
234 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
235
236 -- Log po_interface_errors
237 rcv_error_pkg.set_error_message('RCV_ALL_REQUIRED_LOCATOR');
238 rcv_error_pkg.log_interface_warning('LOCATOR_ID');
239
240 RETURN;
241 END IF;
242
243 BEGIN
244 SELECT mld.locator_id,
245 segment1, segment2, segment3, segment4, segment5, segment6,
246 segment7, segment8, segment9, segment10, segment11, segment12,
247 segment13, segment14, segment15, segment16, segment17, segment18
248 INTO l_loc_id,
249 l_segmentarray(1), l_segmentarray(2), l_segmentarray(3),
250 l_segmentarray(4), l_segmentarray(5), l_segmentarray(6),
251 l_segmentarray(7), l_segmentarray(8), l_segmentarray(9),
252 l_segmentarray(10), l_segmentarray(11), l_segmentarray(12),
253 l_segmentarray(13), l_segmentarray(14), l_segmentarray(15),
254 l_segmentarray(16), l_segmentarray(17), l_segmentarray(18)
255 FROM mtl_item_loc_defaults mld,
256 mtl_item_locations mil
257 WHERE mld.inventory_item_id = x_cascaded_table(n).item_id
258 AND mld.organization_id = x_cascaded_table(n).to_organization_id
259 AND mld.subinventory_code = x_cascaded_table(n).subinventory
260 AND mld.default_type = 2
261 AND mld.organization_id = mil.organization_id
262 AND mld.locator_id = mil.inventory_location_id
263 AND trunc(NVL(mil.disable_date, trunc(sysdate+1))) > trunc(sysdate);
264
265 l_segmentarray(19) := x_cascaded_table(n).project_id;
266 l_segmentarray(20) := x_cascaded_table(n).task_id;
267
268 IF NOT (getloc(x_cascaded_table(n).locator_id , x_cascaded_table(n).to_organization_id, x_locator_control, l_segmentarray ) ) THEN
269
270 IF (g_asn_debug = 'Y') THEN
271 asn_debug.put_line('Cause: Receiving preprocessor could not default/create a locator for this trxn.');
272 END IF;
273
274 x_cascaded_table(n).locator_id := NULL;
275 -- Change the transaction back to ASN import
276 x_cascaded_table(n).transaction_type := 'SHIP';
277 x_cascaded_table(n).auto_transact_code := 'SHIP';
278 -- Reset the flag so that it won't affect the next transaction.
279 x_auto_deliver := 'N';
280 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
281
282 -- Log po_interface_errors
283 rcv_error_pkg.set_error_message('RCV_ALL_REQUIRED_LOCATOR');
284 rcv_error_pkg.log_interface_warning('LOCATOR_ID');
285
286 RETURN;
287
288 END IF;
289
290 update mtl_item_locations
291 set subinventory_code = x_cascaded_table(n).subinventory,
292 status_id = inv_material_status_pkg.get_default_locator_status(x_cascaded_table(n).to_organization_id, x_cascaded_table(n).subinventory),
293 physical_location_id = l_loc_id
294 where inventory_location_id = x_cascaded_table(n).locator_id;
295
296 EXCEPTION
297 WHEN NO_DATA_FOUND THEN
298 IF (g_asn_debug = 'Y') THEN
299 asn_debug.put_line('Cause: Receiving preprocessor could not default/create a locator for this trxn.');
300 END IF;
301
302 x_cascaded_table(n).locator_id := NULL;
303 -- Change the transaction back to ASN import
304 x_cascaded_table(n).transaction_type := 'SHIP';
305 x_cascaded_table(n).auto_transact_code := 'SHIP';
306 -- Reset the flag so that it won't affect the next transaction.
307 x_auto_deliver := 'N';
308 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
309
310 -- Log po_interface_errors
311 rcv_error_pkg.set_error_message('RCV_ALL_REQUIRED_LOCATOR');
312 rcv_error_pkg.log_interface_warning('LOCATOR_ID');
313
314 return;
315
316 WHEN OTHERS THEN
317 po_message_s.sql_error('get_default_locator', x_progress, sqlcode);
318 RAISE;
319 END;
320
321 WHEN OTHERS THEN
322 po_message_s.sql_error('get_default_locator', x_progress, sqlcode);
323 RAISE;
324 END;
325
326 IF (g_asn_debug = 'Y') THEN
327 asn_debug.put_line('Defaulting locator from Sub: Locator_id = ' || TO_CHAR(x_cascaded_table(n).locator_id));
328 END IF;
329 END IF; --}
330 END IF; --} matches subinventory not null
331
332 IF ( (x_cascaded_table(n).auto_transact_code <> 'RECEIVE')
333 OR x_cascaded_table(n).auto_transact_code IS NULL) THEN --{
334 x_default_subinventory := x_cascaded_table(n).subinventory;
335 x_default_locator_id := x_cascaded_table(n).locator_id;
336 /*
337 ** Call the put away function
338 */
339 x_success := rcv_sub_locator_sv.put_away_api(x_cascaded_table(n).po_line_location_id,
340 x_cascaded_table(n).po_distribution_id,
341 x_cascaded_table(n).shipment_line_id,
342 x_cascaded_table(n).receipt_source_code,
343 x_cascaded_table(n).from_organization_id,
344 x_cascaded_table(n).to_organization_id,
345 x_cascaded_table(n).item_id,
346 x_cascaded_table(n).item_revision,
347 x_cascaded_table(n).vendor_id,
348 x_cascaded_table(n).ship_to_location_id,
349 x_cascaded_table(n).deliver_to_location_id,
350 x_cascaded_table(n).deliver_to_person_id,
351 x_cascaded_table(n).quantity,
352 x_cascaded_table(n).primary_quantity,
353 x_cascaded_table(n).primary_unit_of_measure,
354 x_cascaded_table(n).quantity,
355 x_cascaded_table(n).unit_of_measure,
356 x_cascaded_table(n).routing_header_id,
357 x_default_subinventory,
358 x_default_locator_id,
359 x_cascaded_table(n).subinventory,
360 x_cascaded_table(n).locator_id
361 );
362 END IF; --}
363
364 /* If subinventory is still null, we need to disable dropship asn auto deliver if it has
365 * been enabled and change the transaction back to ASN import*/
366 IF ( (x_auto_deliver = 'Y') AND
367 (x_cascaded_table(n).subinventory IS NULL)) THEN --{
368
369 IF (g_asn_debug = 'Y') THEN
370 asn_debug.put_line('Warning: Changing the dropship ASN auto deliver back to ASN import.');
371 asn_debug.put_line('Cause: Receiving preprocessor could not default a subinventory for this trxn.');
372 END IF;
373
374 -- Change the transaction back to ASN import
375 x_cascaded_table(n).transaction_type := 'SHIP';
376 x_cascaded_table(n).auto_transact_code := 'SHIP';
377 -- Reset the flag so that it won't affect the next transaction.
378 x_auto_deliver := 'N';
379 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
380
381 -- Log po_interface_errors
382 rcv_error_pkg.set_error_message('RCV_ASN_AUTO_DEL_NO_SUBINV');
383 rcv_error_pkg.log_interface_warning('SUBINVENTORY');
384 END IF; --}
385
386 RETURN;
387 END IF; --}
388
389
390
391 /* If parent_interface_id is not null then it means it is a parent
392 * child relation ship. So look in rti. If parent_transaction_id
393 * is not null, then look in rcv_transactions.
394 */
395 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
396 SELECT from_subinventory,
397 from_locator_id
398 INTO l_from_subinventory,
399 l_from_locator_id
400 FROM rcv_transactions_interface rti
401 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
402 ELSIF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
403 SELECT from_subinventory,
404 from_locator_id
405 INTO l_from_subinventory,
406 l_from_locator_id
407 FROM rcv_transactions rt
408 WHERE rt.transaction_id = x_cascaded_table(n).parent_transaction_id;
409 END IF;
410
411 IF (g_asn_debug = 'Y') THEN
412 asn_debug.put_line('l_from_subinventory, ' || l_from_subinventory);
413 asn_debug.put_line('l_from_locator_id ' || l_from_locator_id);
414 END IF;
415
416 x_cascaded_table(n).subinventory := l_from_subinventory;
417 x_cascaded_table(n).locator_id := l_from_locator_id;
418
419 EXCEPTION
420 WHEN OTHERS THEN
421 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
422 rcv_error_pkg.set_sql_error_message('default_for_pjm_dropship', '000');
423 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
424 END default_for_pjm_dropship;
425
426 -- End bug 14725305
427
428 PROCEDURE derive_vendor_rcv_line(
429 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
430 n IN OUT NOCOPY BINARY_INTEGER,
431 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
432 x_header_record IN rcv_roi_preprocessor.header_rec_type
433 ) IS
434 l_po_header_id po_headers_all.po_header_id%type;
435 l_return_status VARCHAR2(1) :='S';
436 l_complex_flag varchar2(1);
437 l_interface_source_code rcv_transactions_interface.interface_source_code%type;
438 BEGIN
439 x_progress := '000';
440 -- Derive PO header and line at the beginning to differentiate between services/goods matching basis
441 -- 1) derive po header info
442 derive_po_header_info(x_cascaded_table, n);
443 derive_asn_header_info(x_cascaded_table,
444 n,
445 x_header_record
446 );
447 /* Bug 3588165 : Moved the call to derive_ship_to_org_info() before
448 derive_po_line_info(). This is done since derive_po_line_info()
449 uses the To_Organization_Id information to derive the
450 Primary_Unit_Of_Measure. Earlier Primary UOM used to be null
451 and the UOM conversion Procedure was raising an exception.
452 */
453
454 -- 2) derive ship to org info
455 derive_ship_to_org_info(x_cascaded_table,
456 n,
457 x_header_record
458 );
459 x_progress := '001';
460 -- 3) derive po line info
461 derive_po_line_info(x_cascaded_table, n);
462 x_progress := '002';
463
464 IF (g_asn_debug = 'Y') THEN
465 asn_debug.put_line('X_progress ' || x_progress);
466 END IF;
467
468 /* R12 Complex Work.
469 * We should be able to create Work Confirmations only through
470 * the iSP screen.
471 */
472
473 l_po_header_id := x_cascaded_table(n).po_header_id;
474
475 PO_COMPLEX_WORK_GRP.is_complex_work_po(
476 1.0,
477 l_po_header_id,
478 l_return_status,
479 l_complex_flag);
480 IF (l_return_status IS NOT NULL AND
481 l_return_status = FND_API.g_ret_sts_success) THEN
482 IF( g_asn_debug = 'Y' ) THEN
483 asn_debug.put_line('l_return_status ' || l_return_status);
484 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
485 END IF;
486 ELSE
487 IF( g_asn_debug = 'Y') THEN
488 asn_debug.put_line('l_return_status ' || l_return_status);
489 END IF;
490 END IF;
491
492 IF (l_complex_flag = 'Y') THEN
493
494 l_interface_source_code :=
495 x_cascaded_table(n).interface_source_code;
496
497 if (x_cascaded_table(n).transaction_type = 'SHIP' and
498 l_interface_source_code <> 'ISP') then
499 asn_debug.put_line('We do not support transaction type ' || x_cascaded_table(n).transaction_type || ' for complex work POs unless they come through the iSP UI');
500 rcv_error_pkg.set_error_message('RCV_INVALID_TRANSACTION_TYPE');
501 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
502 end if;
503 /* Receipt for Work Confirmation does not come through
504 * preprocessor. Hence error out.
505 */
506 if (x_cascaded_table(n).transaction_type = 'RECEIVE') then
507 asn_debug.put_line('You cannot process a receipt against this PO using the Open Interface. Please create a Work Confirmation request instead.');
508 rcv_error_pkg.set_error_message('RCV_WC_CREATE');
509 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
510
511 end if;
512 End if;
513
514
515 -- 4) derive vendor information
516 derive_vendor_info(x_cascaded_table, n);
517 x_progress := '004';
518
519 IF (g_asn_debug = 'Y') THEN
520 asn_debug.put_line('X_progress ' || x_progress);
521 END IF;
522
523 -- 5) derive vendor site info
524 /* Call derive vendor_site_procedure here */
525 /* UK1 -> vendor_site_id
526 UK2 -> vendor_site_code + vendor_id + org_id */
527 derive_vendor_site_info(x_cascaded_table, n);
528 x_progress := '005';
529
530 IF (g_asn_debug = 'Y') THEN
531 asn_debug.put_line('X_progress ' || x_progress);
532 END IF;
533
534 -- 6) derive item info
535 derive_item_info(x_cascaded_table, n);
536 x_progress := '010';
537 -- 7) derive substitute item info
538 derive_substitute_item_info(x_cascaded_table, n);
539 x_progress := '020';
540 -- 8) derive from org info
541 derive_from_org_info(x_cascaded_table, n);
542 x_progress := '035';
543 -- 9) derive in transit org info
544 derive_transit_org_info(x_cascaded_table, n);
545 x_progress := '040';
546 -- 10) derive location info
547 derive_location_info(x_cascaded_table, n);
548 x_progress := '045';
549 -- 11) derive ship to location info
550 derive_ship_to_location_info(x_cascaded_table, n);
551 x_progress := '050';
552 -- 12) derive routing header info
553 derive_routing_header_info(x_cascaded_table, n);
554 x_progress := '070';
555 -- 13) derive routing step info
556 derive_routing_step_info(x_cascaded_table, n);
557 x_progress := '080';
558 -- 14) derive deliver to person info
559 derive_deliver_to_person_info(x_cascaded_table, n);
560 x_progress := '085';
561 -- 14) derive deliver to loc info
562 derive_deliver_to_loc_info(x_cascaded_table, n);
563 x_progress := '090';
564 -- 15) derive subinv/locator info
565 --derive_locator_info(x_cascaded_table, n);
566 --derive_from_locator_id(x_cascaded_table, n); -- WMS Change
567 derive_to_locator_id(x_cascaded_table, n); -- WMS Change
568 x_progress := '091';
569 -- 16) derive reason info
570 derive_reason_info(x_cascaded_table, n);
571 x_progress := '092';
572 -- derive auto transact code
573 derive_auto_transact_code(x_cascaded_table, n);
574
575 -- quantity > 0
576 /* Complex Work Start.
577 * We have a separate procedure derive_matching_basis
578 * to get the matching basis now. This is because we
579 * are going to get the matching_basis from
580 * po_line_locations and hence moved it from
581 * derive_po_line_info.
582 */
583 IF (g_asn_debug = 'Y') THEN
584 asn_debug.put_line('Before calling derive matching basis ');
585 END IF;
586 derive_matching_basis(x_cascaded_table,n);
587
588 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
589 derive_vendor_rcv_line_amt(x_cascaded_table,
590 n,
591 temp_cascaded_table,
592 x_header_record
593 );
594 ELSE
595 derive_vendor_rcv_line_qty(x_cascaded_table,
596 n,
597 temp_cascaded_table,
598 x_header_record
599 );
600 END IF;
601 /* Complex Work.
602 * Add exception block.
603 */
604 exception
605 when others then
606 IF (g_asn_debug = 'Y') THEN
607 asn_debug.put_line('Exception in derive_vendor_rcv_line '||x_progress);
608 END IF;
609 raise;
610 END derive_vendor_rcv_line;
611
612 PROCEDURE default_vendor_rcv_line(
613 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
614 n IN BINARY_INTEGER,
615 x_header_id IN rcv_headers_interface.header_interface_id%TYPE,
616 x_header_record IN rcv_roi_preprocessor.header_rec_type
617 ) IS
618 x_progress VARCHAR2(3);
619 x_locator_control NUMBER;
620 x_default_subinventory VARCHAR2(10);
621 x_default_locator_id NUMBER;
622 x_success BOOLEAN;
623 x_tax_name VARCHAR2(50); -- Bug 6331613
624 x_vendor_site_id NUMBER;
625 x_vendor_site_code VARCHAR2(20);
626 item_id_record rcv_shipment_line_sv.item_id_record_type;
627
628 /* bug2382337:
629 * Change the name of the parameters passed into the cursor
630 */
631 CURSOR shipments(
632 v_header_id NUMBER,
633 v_line_id NUMBER,
634 v_line_location_id NUMBER
635 ) IS
636 SELECT ph.revision_num,
637 pl.line_num,
638 nvl(pll.description,pl.item_description) item_description,--Complex work
639 pll.tax_code_id,
640 pll.po_release_id,
641 pll.ship_to_location_id,
642 pll.ship_to_organization_id,
643 pll.shipment_num,
644 pll.receiving_routing_id,
645 pll.country_of_origin_code,
646 pl.job_id,
647 pll.value_basis , --Complex Work
648 pl.purchase_basis,
649 pll.matching_basis --Complex Work
650 FROM po_line_locations pll,
651 po_lines pl,
652 po_headers ph
653 WHERE ph.po_header_id = pl.po_header_id
654 AND pl.po_line_id = pll.po_line_id
655 AND ph.po_header_id = v_header_id
656 AND pl.po_line_id = v_line_id
657 AND pll.line_location_id = v_line_location_id
658 AND NVL(pll.approved_flag, 'N') = 'Y'
659 AND NVL(pll.cancel_flag, 'N') = 'N'
660 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED'
661 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT');
662
663 default_po_info shipments%ROWTYPE;
664 BEGIN
665 IF (g_asn_debug = 'Y') THEN
666 asn_debug.put_line('Enter default_shipment_line');
667 END IF;
668
669 x_progress := '000';
670 -- set default_shipment_line values
671
672 x_cascaded_table(n).header_interface_id := x_header_id;
673 x_cascaded_table(n).shipment_line_status_code := 'OPEN';
674
675 IF x_cascaded_table(n).source_document_code IS NULL THEN
676 x_cascaded_table(n).source_document_code := 'PO';
677
678 IF (g_asn_debug = 'Y') THEN
679 asn_debug.put_line('Defaulting SOURCE_DOCUMENT_CODE ' || x_cascaded_table(n).source_document_code);
680 END IF;
681 END IF;
682
683 /* Fix for bug 2564646.
684 If AUTO_TRANSACT_CODE is RECEIVE then it means it is a receive
685 transaction and destination_type_code should be RECEIVING. Even
686 if the end user populates destination_type_code as INVENTORY
687 when AUTO_TRANSACT_CODE is RECEIVE, we now overwrite the value
688 of DESTINATION_TYPE_CODE to RECEIVING by adding the OR condition
689 to the following IF statement.
690 */
691 IF x_cascaded_table(n).destination_type_code IS NULL
692 OR ( x_cascaded_table(n).destination_type_code = 'INVENTORY'
693 AND x_cascaded_table(n).auto_transact_code = 'RECEIVE') THEN
694 x_cascaded_table(n).destination_type_code := 'RECEIVING';
695
696 IF (g_asn_debug = 'Y') THEN
697 asn_debug.put_line('Defaulting DESTINATION_TYPE_CODE ' || x_cascaded_table(n).destination_type_code);
698 END IF;
699 END IF;
700
701 IF x_cascaded_table(n).transaction_type IS NULL THEN
702 x_cascaded_table(n).transaction_type := 'SHIP';
703
704 IF (g_asn_debug = 'Y') THEN
705 asn_debug.put_line('Defaulting TRANSACTION_TYPE ' || x_cascaded_table(n).transaction_type);
706 END IF;
707 END IF;
708
709 IF x_cascaded_table(n).processing_mode_code IS NULL THEN
710 x_cascaded_table(n).processing_mode_code := 'BATCH';
711
712 IF (g_asn_debug = 'Y') THEN
713 asn_debug.put_line('Defaulting PROCESSING_MODE_CODE ' || x_cascaded_table(n).processing_mode_code);
714 END IF;
715 END IF;
716
717 x_cascaded_table(n).processing_status_code := 'RUNNING';
718
719 IF x_cascaded_table(n).processing_status_code IS NULL THEN
720 -- This has to be set to running otherwise C code in rvtbm
721 -- will not pick it up
722 x_cascaded_table(n).processing_status_code := 'RUNNING';
723
724 IF (g_asn_debug = 'Y') THEN
725 asn_debug.put_line('Defaulting PROCESSING_STATUS_CODE ' || x_cascaded_table(n).processing_status_code);
726 END IF;
727 END IF;
728
729 IF x_cascaded_table(n).transaction_status_code IS NULL THEN
730 x_cascaded_table(n).transaction_status_code := 'PENDING';
731
732 IF (g_asn_debug = 'Y') THEN
733 asn_debug.put_line('Defaulting TRANSACTION_STATUS_CODE ' || x_cascaded_table(n).transaction_status_code);
734 END IF;
735 END IF;
736
737 -- Default auto_transact_code if it is null
738 IF x_cascaded_table(n).auto_transact_code IS NULL THEN
739 IF (g_asn_debug = 'Y') THEN
740 asn_debug.put_line('Setting auto_transact_code to transaction_type ' || x_cascaded_table(n).transaction_type);
741 END IF;
742
743 x_cascaded_table(n).auto_transact_code := x_cascaded_table(n).transaction_type;
744 END IF;
745
746 -- default only if all attributes are null
747 IF x_cascaded_table(n).vendor_id IS NULL
748 AND x_cascaded_table(n).vendor_name IS NULL
749 AND x_cascaded_table(n).vendor_num IS NULL THEN --{
750 x_cascaded_table(n).vendor_id := x_header_record.header_record.vendor_id;
751 x_cascaded_table(n).vendor_name := x_header_record.header_record.vendor_name;
752 x_cascaded_table(n).vendor_num := x_header_record.header_record.vendor_num;
753
754 IF (g_asn_debug = 'Y') THEN
755 asn_debug.put_line('Defaulting from HEADER VENDOR_ID ' || TO_CHAR(x_cascaded_table(n).vendor_id));
756 asn_debug.put_line('Defaulting from HEADER VENDOR_NAME ' || x_cascaded_table(n).vendor_name);
757 asn_debug.put_line('Defaulting from HEADER VENDOR_NUM ' || x_cascaded_table(n).vendor_num);
758 END IF;
759 END IF; --}
760
761 -- default only if all attributes are null
762
763 IF x_cascaded_table(n).vendor_site_id IS NULL
764 AND x_cascaded_table(n).vendor_site_code IS NULL THEN --{
765 x_cascaded_table(n).vendor_site_id := x_header_record.header_record.vendor_site_id;
766 x_cascaded_table(n).vendor_site_code := x_header_record.header_record.vendor_site_code;
767
768 /* Fix for bug 2296720.
769 If both vendor_site_id and vendor_site_code are not populated
770 in interface tables, and if there are multiple vendor sites
771 associated to a particular vendor then we default them from PO
772 using the po_header_id of rcv_transactions_interface for each
773 line.
774 */
775 IF x_cascaded_table(n).vendor_site_id IS NULL
776 AND x_cascaded_table(n).vendor_site_code IS NULL THEN --{
777 SELECT vendor_site_id
778 INTO x_vendor_site_id
779 FROM po_headers
780 WHERE po_header_id = x_cascaded_table(n).po_header_id
781 AND vendor_id = x_cascaded_table(n).vendor_id;
782
783 SELECT vendor_site_code
784 INTO x_vendor_site_code
785 FROM po_vendor_sites
786 WHERE vendor_site_id = x_vendor_site_id
787 AND vendor_id = x_cascaded_table(n).vendor_id;
788
789 x_cascaded_table(n).vendor_site_id := x_vendor_site_id;
790 x_cascaded_table(n).vendor_site_code := x_vendor_site_code;
791 END IF; --}
792
793 IF (g_asn_debug = 'Y') THEN
794 asn_debug.put_line('Defaulting from HEADER VENDOR_SITE_ID ' || TO_CHAR(x_cascaded_table(n).vendor_site_id));
795 asn_debug.put_line('Defaulting from HEADER VENDOR_SITE_CODE ' || x_cascaded_table(n).vendor_site_code);
796 END IF;
797 END IF; --}
798
799 -- default only if all attributes are null
800
801 IF x_cascaded_table(n).from_organization_id IS NULL
802 AND x_cascaded_table(n).from_organization_code IS NULL THEN
803 x_cascaded_table(n).from_organization_id := x_header_record.header_record.from_organization_id;
804 x_cascaded_table(n).from_organization_code := x_header_record.header_record.from_organization_code;
805
806 IF (g_asn_debug = 'Y') THEN
807 asn_debug.put_line('Defaulting from HEADER FROM_ORGANIZATION_ID ' || TO_CHAR(x_cascaded_table(n).from_organization_id));
808 asn_debug.put_line('Defaulting from HEADER FROM_ORGANIZATION_CODE ' || x_cascaded_table(n).from_organization_code);
809 END IF;
810 END IF;
811
812 -- default only if all attributes are null
813 IF x_cascaded_table(n).to_organization_id IS NULL
814 AND x_cascaded_table(n).to_organization_code IS NULL THEN
815 x_cascaded_table(n).to_organization_id := x_header_record.header_record.ship_to_organization_id;
816 x_cascaded_table(n).to_organization_code := x_header_record.header_record.ship_to_organization_code;
817
818 IF (g_asn_debug = 'Y') THEN
819 asn_debug.put_line('Defaulting from HEADER TO_ORGANIZATION_ID ' || TO_CHAR(x_cascaded_table(n).to_organization_id));
820 asn_debug.put_line('Defaulting from HEADER TO_ORGANIZATION_CODE ' || x_cascaded_table(n).to_organization_code);
821 END IF;
822 END IF;
823
824 -- default only if all attributes are null
825 IF x_cascaded_table(n).currency_code IS NULL
826 AND x_cascaded_table(n).currency_conversion_type IS NULL
827 AND x_cascaded_table(n).currency_conversion_rate IS NULL
828 AND x_cascaded_table(n).currency_conversion_date IS NULL THEN --{
829 x_cascaded_table(n).currency_code := x_header_record.header_record.currency_code;
830 x_cascaded_table(n).currency_conversion_type := x_header_record.header_record.conversion_rate_type;
831 x_cascaded_table(n).currency_conversion_rate := x_header_record.header_record.conversion_rate;
832 x_cascaded_table(n).currency_conversion_date := x_header_record.header_record.conversion_rate_date;
833
834 IF (g_asn_debug = 'Y') THEN
835 asn_debug.put_line('Defaulting from HEADER CURRENCY_CODE ' || x_cascaded_table(n).currency_code);
836 asn_debug.put_line('Defaulting from HEADER CURRENCY_CONVERSION_TYPE ' || x_cascaded_table(n).currency_conversion_type);
837 asn_debug.put_line('Defaulting from HEADER CURRENCY_CONVERSION_RATE ' || TO_CHAR(x_cascaded_table(n).currency_conversion_rate));
838 asn_debug.put_line('Defaulting from HEADER CURRENCY_CONVERSION_DATE ' || TO_CHAR(x_cascaded_table(n).currency_conversion_date, 'DD/MM/YYYY'));
839 END IF;
840 END IF; --}
841
842 IF ( x_cascaded_table(n).ship_to_location_id IS NULL
843 AND x_cascaded_table(n).ship_to_location_code IS NULL) THEN -- Check this with George
844 x_cascaded_table(n).ship_to_location_code := x_header_record.header_record.location_code;
845 x_cascaded_table(n).ship_to_location_id := x_header_record.header_record.location_id;
846
847 IF (g_asn_debug = 'Y') THEN
848 asn_debug.put_line('Defaulting from HEADER LOCATION_ID ' || TO_CHAR(x_cascaded_table(n).location_id));
849 END IF;
850 END IF;
851
852 IF x_cascaded_table(n).shipment_num IS NULL THEN
853 x_cascaded_table(n).shipment_num := x_header_record.header_record.shipment_num;
854
855 IF (g_asn_debug = 'Y') THEN
856 asn_debug.put_line('Defaulting from HEADER SHIPMENT_NUM ' || x_cascaded_table(n).shipment_num);
857 END IF;
858 END IF;
859
860 IF x_cascaded_table(n).freight_carrier_code IS NULL THEN
861 x_cascaded_table(n).freight_carrier_code := x_header_record.header_record.freight_carrier_code;
862
863 IF (g_asn_debug = 'Y') THEN
864 asn_debug.put_line('Defaulting from HEADER FREIGHT_CARRIER_CODE ' || x_cascaded_table(n).freight_carrier_code);
865 END IF;
866 END IF;
867
868 IF x_cascaded_table(n).bill_of_lading IS NULL THEN
869 x_cascaded_table(n).bill_of_lading := x_header_record.header_record.bill_of_lading;
870
871 IF (g_asn_debug = 'Y') THEN
872 asn_debug.put_line('Defaulting from HEADER BILL_OF_LADING ' || x_cascaded_table(n).bill_of_lading);
873 END IF;
874 END IF;
875
876 IF x_cascaded_table(n).packing_slip IS NULL THEN
877 x_cascaded_table(n).packing_slip := x_header_record.header_record.packing_slip;
878
879 IF (g_asn_debug = 'Y') THEN
880 asn_debug.put_line('Defaulting from HEADER PACKING_SLIP ' || x_cascaded_table(n).packing_slip);
881 END IF;
882 END IF;
883
884 IF x_cascaded_table(n).shipped_date IS NULL THEN
885 x_cascaded_table(n).shipped_date := x_header_record.header_record.shipped_date;
886
887 IF (g_asn_debug = 'Y') THEN
888 asn_debug.put_line('Defaulting from HEADER SHIPPED_DATE ' || TO_CHAR(x_cascaded_table(n).shipped_date, 'DD/MM/YYYY'));
889 END IF;
890 END IF;
891
892 IF x_cascaded_table(n).expected_receipt_date IS NULL THEN
893 x_cascaded_table(n).expected_receipt_date := x_header_record.header_record.expected_receipt_date;
894
895 IF (g_asn_debug = 'Y') THEN
896 asn_debug.put_line('Defaulting from HEADER EXPECTED_RECEIPT_DATE ' || TO_CHAR(x_cascaded_table(n).expected_receipt_date, 'DD/MM/YYYY'));
897 END IF;
898 END IF;
899
900 IF x_cascaded_table(n).num_of_containers IS NULL
901 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
902 x_cascaded_table(n).num_of_containers := x_header_record.header_record.num_of_containers;
903
904 IF (g_asn_debug = 'Y') THEN
905 asn_debug.put_line('Defaulting from HEADER NUM_OF_CONTAINERS ' || TO_CHAR(x_cascaded_table(n).num_of_containers));
906 END IF;
907 END IF;
908
909 IF x_cascaded_table(n).waybill_airbill_num IS NULL
910 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
911 x_cascaded_table(n).waybill_airbill_num := x_header_record.header_record.waybill_airbill_num;
912
913 IF (g_asn_debug = 'Y') THEN
914 asn_debug.put_line('Defaulting from HEADER WAYBILL_AIRBILL_NUM ' || x_cascaded_table(n).waybill_airbill_num);
915 END IF;
916 END IF;
917
918 IF x_cascaded_table(n).tax_name IS NULL THEN
919 x_cascaded_table(n).tax_name := x_header_record.header_record.tax_name;
920
921 IF (g_asn_debug = 'Y') THEN
922 asn_debug.put_line('Defaulting from HEADER TAX_NAME ' || x_cascaded_table(n).tax_name);
923 END IF;
924 END IF;
925
926 /* Bug 3299421 : WMS Mobile applications do not need the item_revision to
927 be defaulted during preprocessing for transactions other than
928 "Deliver". Added the condition in the If clause where we
929 check if the transaction is from mobile and if so do not
930 default the item revision.
931 */
932 IF x_cascaded_table(n).item_revision IS NULL
933 AND (NVL(x_cascaded_table(n).mobile_txn, 'N') = 'N')
934 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN --{
935 IF (g_asn_debug = 'Y') THEN
936 asn_debug.put_line('Enter defaulting item revision');
937 END IF;
938
939 item_id_record.item_id := x_cascaded_table(n).item_id;
940 item_id_record.po_line_id := x_cascaded_table(n).po_line_id;
941 item_id_record.po_line_location_id := x_cascaded_table(n).po_line_location_id;
942 item_id_record.to_organization_id := x_cascaded_table(n).to_organization_id;
943 item_id_record.item_revision := x_cascaded_table(n).item_revision;
944 item_id_record.error_record.error_status := 'S';
945 item_id_record.error_record.error_message := NULL;
946 rcv_transactions_interface_sv.default_item_revision(item_id_record);
947 x_cascaded_table(n).item_revision := item_id_record.item_revision;
948
949 IF (g_asn_debug = 'Y') THEN
950 asn_debug.put_line(NVL(item_id_record.item_revision, 'Item Revision is null'));
951 END IF;
952
953 x_cascaded_table(n).error_status := item_id_record.error_record.error_status;
954 x_cascaded_table(n).error_message := item_id_record.error_record.error_message;
955 END IF; --}
956
957 IF x_cascaded_table(n).po_revision_num IS NULL
958 OR x_cascaded_table(n).freight_carrier_code IS NULL
959 OR x_cascaded_table(n).document_line_num IS NULL
960 OR ( x_cascaded_table(n).item_description IS NULL
961 AND x_cascaded_table(n).matching_basis <> 'AMOUNT')
962 OR ( x_cascaded_table(n).job_id IS NULL
963 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR')
964 OR x_cascaded_table(n).tax_name IS NULL
965 OR --FRKHAN 12/18/98 add country of origin check
966 x_cascaded_table(n).country_of_origin_code IS NULL
967 OR x_cascaded_table(n).po_release_id IS NULL
968 OR ( x_cascaded_table(n).ship_to_location_id IS NULL
969 AND x_cascaded_table(n).ship_to_location_code IS NULL)
970 OR ( x_cascaded_table(n).to_organization_id IS NULL
971 AND x_cascaded_table(n).to_organization_code IS NULL)
972 OR x_cascaded_table(n).document_shipment_line_num IS NULL
973 OR ( x_cascaded_table(n).routing_header_id IS NULL
974 AND x_cascaded_table(n).routing_code IS NULL) THEN --{
975 IF (g_asn_debug = 'Y') THEN
976 asn_debug.put_line('Defaulting values from PO ');
977 END IF;
978
979 OPEN shipments(x_cascaded_table(n).po_header_id,
980 x_cascaded_table(n).po_line_id,
981 x_cascaded_table(n).po_line_location_id
982 );
983 FETCH shipments INTO default_po_info;
984
985 IF shipments%FOUND THEN --{
986 IF x_cascaded_table(n).po_revision_num IS NULL THEN
987 IF (g_asn_debug = 'Y') THEN
988 asn_debug.put_line('Defaulting PO HEADER revision num ' || default_po_info.revision_num);
989 END IF;
990
991 x_cascaded_table(n).po_revision_num := default_po_info.revision_num;
992 END IF;
993
994 IF x_cascaded_table(n).document_line_num IS NULL THEN
995 IF (g_asn_debug = 'Y') THEN
996 asn_debug.put_line('Defaulting po line num ' || TO_CHAR(default_po_info.line_num));
997 END IF;
998
999 x_cascaded_table(n).document_line_num := default_po_info.line_num;
1000 END IF;
1001
1002 IF x_cascaded_table(n).item_description IS NULL
1003 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
1004 IF (g_asn_debug = 'Y') THEN
1005 asn_debug.put_line('Defaulting item description from PO ' || default_po_info.item_description);
1006 END IF;
1007
1008 x_cascaded_table(n).item_description := default_po_info.item_description;
1009 END IF;
1010
1011 IF x_cascaded_table(n).tax_name IS NULL
1012 AND default_po_info.tax_code_id IS NOT NULL THEN --{
1013 IF (g_asn_debug = 'Y') THEN
1014 asn_debug.put_line('Defaulting tax name based on PO ' || TO_CHAR(default_po_info.tax_code_id));
1015 END IF;
1016
1017 -- Need to join to ap_tax_codes to get tax_name
1018 BEGIN
1019 SELECT NAME
1020 INTO x_tax_name
1021 FROM ap_tax_codes
1022 WHERE ap_tax_codes.tax_id = default_po_info.tax_code_id;
1023
1024 x_cascaded_table(n).tax_name := x_tax_name;
1025 EXCEPTION
1026 WHEN OTHERS THEN
1027 IF (g_asn_debug = 'Y') THEN
1028 asn_debug.put_line('Some error occured in the tax name derivation');
1029 END IF;
1030 END;
1031 END IF; --}
1032
1033 --FRKHAN 12/18/98 default country of origin from PO
1034
1035 IF x_cascaded_table(n).country_of_origin_code IS NULL THEN
1036 IF (g_asn_debug = 'Y') THEN
1037 asn_debug.put_line('Defaulting country of origin from PO ' || default_po_info.country_of_origin_code);
1038 END IF;
1039
1040 x_cascaded_table(n).country_of_origin_code := default_po_info.country_of_origin_code;
1041 END IF;
1042
1043 IF x_cascaded_table(n).po_release_id IS NULL THEN
1044 IF (g_asn_debug = 'Y') THEN
1045 asn_debug.put_line('Defaulting PO Release ID from PO ' || TO_CHAR(default_po_info.po_release_id));
1046 END IF;
1047
1048 x_cascaded_table(n).po_release_id := default_po_info.po_release_id;
1049 END IF;
1050
1051 IF x_cascaded_table(n).ship_to_location_id IS NULL THEN
1052 IF (g_asn_debug = 'Y') THEN
1053 asn_debug.put_line('Defaulting PO ship_to_location_id ' || TO_CHAR(default_po_info.ship_to_location_id));
1054 END IF;
1055
1056 x_cascaded_table(n).ship_to_location_id := default_po_info.ship_to_location_id;
1057 END IF;
1058
1059 IF x_cascaded_table(n).to_organization_id IS NULL THEN
1060 IF (g_asn_debug = 'Y') THEN
1061 asn_debug.put_line('Defaulting PO to_organization_id ' || TO_CHAR(default_po_info.ship_to_organization_id));
1062 END IF;
1063
1064 x_cascaded_table(n).to_organization_id := default_po_info.ship_to_organization_id;
1065 END IF;
1066
1067 IF x_cascaded_table(n).document_shipment_line_num IS NULL THEN
1068 IF (g_asn_debug = 'Y') THEN
1069 asn_debug.put_line('Defaulting PO shipment_line_num ' || TO_CHAR(default_po_info.shipment_num));
1070 END IF;
1071
1072 x_cascaded_table(n).document_shipment_line_num := default_po_info.shipment_num;
1073 END IF;
1074
1075 IF x_cascaded_table(n).routing_header_id IS NULL THEN
1076 IF (g_asn_debug = 'Y') THEN
1077 asn_debug.put_line('Defaulting PO routing_header_id ' || TO_CHAR(default_po_info.receiving_routing_id));
1078 END IF;
1079
1080 x_cascaded_table(n).routing_header_id := default_po_info.receiving_routing_id;
1081 END IF;
1082
1083 IF x_cascaded_table(n).job_id IS NULL
1084 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR' THEN
1085 IF (g_asn_debug = 'Y') THEN
1086 asn_debug.put_line('Defaulting PO job_id ' ||(default_po_info.job_id));
1087 END IF;
1088
1089 x_cascaded_table(n).job_id := default_po_info.job_id;
1090 END IF;
1091 END IF; --} matches if shipments found
1092 END IF; --}
1093
1094 IF (g_asn_debug = 'Y') THEN
1095 asn_debug.put_line('Primary UOM = ' || x_cascaded_table(n).primary_unit_of_measure);
1096 END IF;
1097
1098 /*
1099 ** Default the subinventory and locator if they have not been set either through the interface
1100 ** or defaulted from the purchase order
1101 */
1102 --- WMS Changes
1103 IF (x_cascaded_table(n).matching_basis <> 'AMOUNT') THEN
1104 /* Bug 14725305 */
1105 IF ( x_auto_deliver = 'Y' AND
1106 x_cascaded_table(n).project_id IS NOT NULL) THEN
1107
1108 default_for_pjm_dropship(x_cascaded_table, n);
1109 ELSE
1110 default_to_subloc_info(x_cascaded_table, n);
1111 END IF;
1112 END IF;
1113
1114 /*
1115 ** Make sure to set the location_id properly
1116 */
1117 IF ( NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER'
1118 OR x_cascaded_table(n).transaction_type = 'DELIVER') THEN
1119 x_cascaded_table(n).location_id := x_cascaded_table(n).deliver_to_location_id;
1120 ELSE
1121 x_cascaded_table(n).location_id := x_cascaded_table(n).ship_to_location_id;
1122 END IF;
1123
1124 IF (g_asn_debug = 'Y') THEN
1125 asn_debug.put_line('Set Location_id = ' || TO_CHAR(x_cascaded_table(n).location_id));
1126 END IF;
1127
1128 IF x_cascaded_table(n).waybill_airbill_num IS NULL
1129 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
1130 x_cascaded_table(n).waybill_airbill_num := x_header_record.header_record.waybill_airbill_num;
1131
1132 IF (g_asn_debug = 'Y') THEN
1133 asn_debug.put_line('Defaulting from HEADER WAYBILL_AIRBILL_NUM ' || x_cascaded_table(n).waybill_airbill_num);
1134 END IF;
1135 END IF;
1136
1137 x_progress := '010';
1138
1139 IF (g_asn_debug = 'Y') THEN
1140 asn_debug.put_line('Exit default_shipment_line');
1141 END IF;
1142 EXCEPTION
1143 WHEN OTHERS THEN
1144 IF (g_asn_debug = 'Y') THEN
1145 asn_debug.put_line('Exception in default_vendor_rcv_line ');
1146 END IF;
1147 END default_vendor_rcv_line;
1148
1149 PROCEDURE validate_vendor_rcv_line(
1150 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1151 n IN BINARY_INTEGER,
1152 x_asn_type IN rcv_headers_interface.asn_type%TYPE,
1153 x_header_record IN rcv_roi_preprocessor.header_rec_type
1154 ) IS
1155 l_parent_deliver_to_person_id NUMBER := null; --Bug#6375015
1156 l_skip_validation NUMBER := 0; --Bug#6375015
1157 BEGIN
1158 IF (g_asn_debug = 'Y') THEN
1159 asn_debug.put_line('Enter validate_shipment_line');
1160 END IF;
1161
1162 x_progress := '000';
1163
1164 IF x_cascaded_table(n).matching_basis = 'AMOUNT' THEN
1165 validate_non_services_fields(x_cascaded_table, n);
1166 END IF;
1167
1168 validate_transaction_date(x_cascaded_table, n);
1169
1170 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
1171 IF (x_asn_type = 'ASBN') THEN
1172 validate_quantity_invoiced(x_cascaded_table, n);
1173 END IF;
1174 END IF;
1175
1176 /* lcm changes */
1177 validate_lcm_line (x_cascaded_table, n, x_asn_type,x_header_record);
1178
1179 IF (g_asn_debug = 'Y') THEN
1180 asn_debug.put_line('After lcm line validation : ' || x_cascaded_table(n).error_status);
1181 END IF;
1182
1183
1184 /* FPJ SERVICES.
1185 * We dont need to validate uom, item_id for Service based PO
1186 * shipments.
1187 */
1188 IF (x_cascaded_table(n).matching_basis <> 'AMOUNT') THEN
1189 validate_transaction_uom(x_cascaded_table, n);
1190
1191 IF (g_asn_debug = 'Y') THEN
1192 asn_debug.put_line('After validate_transaction_uom: ' || x_cascaded_table(n).error_status);
1193 END IF;
1194
1195 validate_item_info(x_cascaded_table, n);
1196
1197 IF (g_asn_debug = 'Y') THEN
1198 asn_debug.put_line('After validate_item_info: ' || x_cascaded_table(n).error_status);
1199 END IF;
1200
1201 validate_freight_carrier_code(x_cascaded_table, n);
1202
1203 IF (g_asn_debug = 'Y') THEN
1204 asn_debug.put_line('After validate_freight_carrier_code: ' || x_cascaded_table(n).error_status);
1205 END IF;
1206
1207 validate_subinventory(x_cascaded_table, n);
1208
1209 IF (g_asn_debug = 'Y') THEN
1210 asn_debug.put_line('After validate_subinventory: ' || x_cascaded_table(n).error_status);
1211 END IF;
1212
1213 validate_locator(x_cascaded_table, n);
1214
1215 IF (g_asn_debug = 'Y') THEN
1216 asn_debug.put_line('After validate_locator: ' || x_cascaded_table(n).error_status);
1217 END IF;
1218
1219 validate_deliver_to_loc(x_cascaded_table, n);
1220
1221 IF (g_asn_debug = 'Y') THEN
1222 asn_debug.put_line('After validate_deliver_to_loc: ' || x_cascaded_table(n).error_status);
1223 END IF;
1224
1225 validate_shipped_qty(x_cascaded_table, n);
1226
1227 IF (g_asn_debug = 'Y') THEN
1228 asn_debug.put_line('After validate_shipped_qty: ' || x_cascaded_table(n).error_status);
1229 END IF;
1230 END IF;
1231
1232 validate_dest_type(x_cascaded_table, n);
1233
1234 IF (g_asn_debug = 'Y') THEN
1235 asn_debug.put_line('After validate_dest_type: ' || x_cascaded_table(n).error_status);
1236 END IF;
1237
1238 IF (x_cascaded_table(n).transaction_type = 'RECEIVE') THEN
1239 validate_ship_to_loc(x_cascaded_table, n);
1240
1241 IF (g_asn_debug = 'Y') THEN
1242 asn_debug.put_line('After validate_ship_to_loc: ' || x_cascaded_table(n).error_status);
1243 END IF;
1244 END IF;
1245
1246 /* Bug:6375015
1247 There is no defaulting done for the deliver_to_person_id or validation against the parent_txn's
1248 deliver_to_person_id in case of ROI transaction. But in case of forms we are defaluting the
1249 deliver_to_person_id, if there is no validation failure on the deliver_to_person_id in Receipts/
1250 Receiving Transaction forms. If there is validation failure, deliver_to_person_id is nulled out
1251 and user can enter any deliver_to_person who is active in case of Receipts/Receiving Trasactions
1252 form. In case of Returns/Corrections, deliver_to_person_id is not editable and it is defaulted
1253 from the parent transaction, even if that person is terminated.
1254 So, added the following code to synch up the behaviour of forms and ROI
1255 a) if deliver_to_person_id is null, default the deliver_to_person_id from the
1256 parent_txn/source_document PO as done in forms.
1257 b) If the deliver_to_person_id is not null, we have to validate against the
1258 parent_txn's deliver_to_person.
1259 c) Skip the call to validate_deliver_to_person, if deliver_to_person is defaulted
1260 from the parent transaction.
1261 */
1262 /* code fix for the Bug:6375015 starts */
1263 IF (x_cascaded_table(n).deliver_to_person_id is null) THEN
1264 IF (g_asn_debug = 'Y') THEN
1265 asn_debug.put_line('Inside deliver_to_person_id is null...');
1266 END IF;
1267
1268 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
1269 --In case of transaction_type DELIVER, we need parent transaction.
1270 --If this condition is not added, it will try to defalut the deliver_to_person
1271 --of the parent transaction. But form is not behaving like that.
1272 --So added this condition to default the deliver_to_person of the source document.
1273 IF (g_asn_debug = 'Y') THEN
1274 asn_debug.put_line('Transaction type is DELIVER...');
1275 asn_debug.put_line('defaulting deliver_to_person_id from source document PO');
1276 END IF;
1277 get_deliver_to_person_from_po(x_cascaded_table,n);
1278 IF (g_asn_debug = 'Y') THEN
1279 asn_debug.put_line('After call to get_deliver_to_person_from_po...');
1280 END IF;
1281 ELSIF (x_cascaded_table(n).parent_transaction_id is not null) THEN
1282 IF (g_asn_debug = 'Y') THEN
1283 asn_debug.put_line('Inside parent_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_transaction_id);
1284 END IF;
1285 l_parent_deliver_to_person_id := get_deliver_to_person_from_rt(x_cascaded_table,n);
1286 --We can safely skip the validate_deliver_to_person call
1287 l_skip_validation := 1;
1288 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
1289 IF (g_asn_debug = 'Y') THEN
1290 asn_debug.put_line('deliver_to_person_is is set to :'||l_parent_deliver_to_person_id);
1291 END IF;
1292 ELSIF (x_cascaded_table(n).parent_interface_txn_id is not null) THEN
1293 IF (g_asn_debug = 'Y') THEN
1294 asn_debug.put_line('Inside parent_interface_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_interface_txn_id);
1295 END IF;
1296 l_parent_deliver_to_person_id := get_deliver_to_person_from_rti(x_cascaded_table,n);
1297 --We can safely skip the validate_deliver_to_person call
1298 l_skip_validation := 1;
1299 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
1300 IF (g_asn_debug = 'Y') THEN
1301 asn_debug.put_line('deliver_to_person_is is set to :'||l_parent_deliver_to_person_id);
1302 END IF;
1303 ELSE--IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
1304 IF (g_asn_debug = 'Y') THEN
1305 asn_debug.put_line('defaulting deliver_to_person_id from source document PO');
1306 END IF;
1307 get_deliver_to_person_from_po(x_cascaded_table,n);
1308 IF (g_asn_debug = 'Y') THEN
1309 asn_debug.put_line('After call to get_deliver_to_person_from_po...');
1310 END IF;
1311 END IF;--IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
1312 ELSE--IF (x_cascaded_table(n).deliver_to_person_id is null) THEN
1313 IF (g_asn_debug = 'Y') THEN
1314 asn_debug.put_line('Inside deliver_to_person_id is not null and the value is :'||x_cascaded_table(n).deliver_to_person_id);
1315 END IF;
1316
1317 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
1318 --In forms user can select any active deliver_to_person for DELIVER transaction.
1319 --In case of transaction_type DELIVER, we need parent transaction.
1320 --If this condition is not added, it will validate against the deliver_to_person mentioned
1321 --the parent RECEIVE transaction. But form is not behaving like that.
1322 --So, added this condition to skip deliver_to_person validation against parent txn
1323 IF (g_asn_debug = 'Y') THEN
1324 asn_debug.put_line('Transaction type is DELIVER...');
1325 END IF;
1326 ELSIF (x_cascaded_table(n).parent_transaction_id is not null) THEN
1327 IF (g_asn_debug = 'Y') THEN
1328 asn_debug.put_line('Inside parent_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_transaction_id);
1329 END IF;
1330 l_parent_deliver_to_person_id := get_deliver_to_person_from_rt(x_cascaded_table,n);
1331 --We can safely skip the validate_deliver_to_person call, validation against
1332 --parent transaction is handled here itself.
1333 l_skip_validation := 1;
1334 IF nvl(l_parent_deliver_to_person_id,-99) <> x_cascaded_table(n).deliver_to_person_id THEN
1335 IF (g_asn_debug = 'Y') THEN
1336 asn_debug.put_line('RTI.deliver_to_person_id is different to that of parent txn...');
1337 END IF;
1338 --deliver_to_person_id mismatches with the parent txn's deliver_to_person, so clear it off
1339 x_cascaded_table(n).deliver_to_person_id := null;
1340 x_cascaded_table(n).deliver_to_person_name := null;
1341
1342 --set the deliver_to_person_id to that of parent transaction
1343 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
1344 IF (g_asn_debug = 'Y') THEN
1345 asn_debug.put_line('deliver_to_person_is is set to that of parent RT txn');
1346 END IF;
1347 END IF;
1348 ELSIF (x_cascaded_table(n).parent_interface_txn_id is not null) THEN
1349 IF (g_asn_debug = 'Y') THEN
1350 asn_debug.put_line('Inside parent_interface_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_interface_txn_id);
1351 END IF;
1352 l_parent_deliver_to_person_id := get_deliver_to_person_from_rti(x_cascaded_table,n);
1353 --We can safely skip the validate_deliver_to_person call, validation against
1354 --parent transaction is handled here itself.
1355 l_skip_validation := 1;
1356 IF nvl(l_parent_deliver_to_person_id,-99) <> x_cascaded_table(n).deliver_to_person_id THEN
1357 IF (g_asn_debug = 'Y') THEN
1358 asn_debug.put_line('RTI.deliver_to_person_id is different to that of parent txn...');
1359 END IF;
1360 --deliver_to_person_id mismatches with the parent txn's deliver_to_person, so clear it off
1361 x_cascaded_table(n).deliver_to_person_id := null;
1362 x_cascaded_table(n).deliver_to_person_name := null;
1363
1364 --set the deliver_to_person_id to that of parent transaction
1365 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
1366
1367 IF (g_asn_debug = 'Y') THEN
1368 asn_debug.put_line('deliver_to_person_is is set to that of parent RT txn');
1369 END IF;
1370 END IF;
1371 END IF;--IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
1372 END IF;--IF (x_cascaded_table(n).deliver_to_person_id is null) THEN
1373
1374 IF l_skip_validation = 0 THEN
1375 IF (g_asn_debug = 'Y') THEN
1376 asn_debug.put_line('validate_deliver_to_person is called');
1377 END IF;
1378 validate_deliver_to_person(x_cascaded_table, n);
1379 IF (g_asn_debug = 'Y') THEN
1380 asn_debug.put_line('After validate_deliver_to_person: ' || x_cascaded_table(n).error_status);
1381 END IF;
1382 ELSE
1383 IF (g_asn_debug = 'Y') THEN
1384 asn_debug.put_line('call to validate_deliver_to_person is skipped');
1385 END IF;
1386 END IF;/* code fix for the Bug:6375015 ends */
1387
1388 IF (g_asn_debug = 'Y') THEN
1389 asn_debug.put_line('After validate_deliver_to_person: ' || x_cascaded_table(n).error_status);
1390 END IF;
1391
1392 validate_routing_record(x_cascaded_table, n);
1393
1394 IF (g_asn_debug = 'Y') THEN
1395 asn_debug.put_line('After validate_routing_record: ' || x_cascaded_table(n).error_status);
1396 END IF;
1397
1398 validate_tax_code(x_cascaded_table,
1399 n,
1400 x_asn_type
1401 ); /* Bug3454491 (1) */
1402
1403 IF (g_asn_debug = 'Y') THEN
1404 asn_debug.put_line('After validate_tax_code: ' || x_cascaded_table(n).error_status);
1405 END IF;
1406
1407 validate_country_of_origin(x_cascaded_table, n);
1408
1409 IF (g_asn_debug = 'Y') THEN
1410 asn_debug.put_line('After validate_country_of_origin: ' || x_cascaded_table(n).error_status);
1411 END IF;
1412
1413 /* 13703578 - ASL validation is not required while receiving */
1414 /* validate_asl(x_cascaded_table, n);
1415
1416 IF (g_asn_debug = 'Y') THEN
1417 asn_debug.put_line('After validate_asl: ' || x_cascaded_table(n).error_status);
1418 END IF; */
1419
1420 validate_ref_integrity(x_cascaded_table,
1421 n,
1422 x_header_record
1423 );
1424
1425 IF (g_asn_debug = 'Y') THEN
1426 asn_debug.put_line('After validate_ref_integrity: ' || x_cascaded_table(n).error_status);
1427 END IF;
1428
1429 exchange_sub_items(x_cascaded_table, n);
1430
1431 IF (g_asn_debug = 'Y') THEN
1432 asn_debug.put_line('After exchange_sub_items: ' || x_cascaded_table(n).error_status);
1433 END IF;
1434
1435 validate_consigned_inventory(x_cascaded_table,
1436 n,
1437 x_asn_type
1438 ); /* Bug3454491 (2) */
1439
1440 IF (g_asn_debug = 'Y') THEN
1441 asn_debug.put_line('After validate_consigned_inventory: ' || x_cascaded_table(n).error_status);
1442 END IF;
1443
1444 validate_inspection_status(x_cascaded_table, n);
1445
1446 IF (g_asn_debug = 'Y') THEN
1447 asn_debug.put_line('After validate_inspection_status: ' || x_cascaded_table(n).error_status);
1448 END IF;
1449
1450 validate_transaction_type(x_cascaded_table, n);
1451
1452 IF (g_asn_debug = 'Y') THEN
1453 asn_debug.put_line('After validate_transaction_type: ' || x_cascaded_table(n).error_status);
1454 END IF;
1455
1456 /** OPM change Bug# 3061052**/
1457 validate_opm_attributes(x_cascaded_table, n);
1458
1459 IF (g_asn_debug = 'Y') THEN
1460 asn_debug.put_line('After validate_opm_attributes: ' || x_cascaded_table(n).error_status);
1461 END IF;
1462
1463 /* If destination_type_code is inventory then we need to make
1464 * sure that we can correct this qty since it might have been
1465 * already reserved in inventory.
1466 */
1467 IF (x_cascaded_table(n).destination_type_code = 'INVENTORY') THEN --{
1468 rcv_roi_return.derive_inv_qty(x_cascaded_table, n);
1469
1470 IF (g_asn_debug = 'Y') THEN
1471 asn_debug.put_line('After derive_inv_qty: ' || x_cascaded_table(n).error_status);
1472 END IF;
1473 END IF; --}
1474
1475 validate_parent_rtv (x_cascaded_table, n); -- rtv project
1476
1477 IF (g_asn_debug = 'Y') THEN
1478 asn_debug.put_line('Leave validate_vendor_rcv_line: ' || x_cascaded_table(n).error_status || ' ' || x_cascaded_table(n).error_message);
1479 END IF;
1480 EXCEPTION
1481 WHEN OTHERS THEN
1482 IF (g_asn_debug = 'Y') THEN
1483 asn_debug.put_line('Unexpected exception in validate_vendor_rcv_line: ' || SQLERRM);
1484 END IF;
1485 END validate_vendor_rcv_line;
1486
1487 PROCEDURE validate_amt_based_rcv_line(
1488 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1489 n IN BINARY_INTEGER,
1490 x_asn_type IN rcv_headers_interface.asn_type%TYPE,
1491 x_header_record IN rcv_roi_preprocessor.header_rec_type
1492 ) IS
1493 BEGIN
1494 IF (g_asn_debug = 'Y') THEN
1495 asn_debug.put_line('Enter validate_amt_based_rcv_line');
1496 END IF;
1497
1498 x_progress := '000';
1499 validate_transaction_date(x_cascaded_table, n);
1500 x_progress := '010';
1501
1502 IF (x_asn_type = 'ASBN') THEN
1503 validate_quantity_invoiced(x_cascaded_table, n);
1504 END IF;
1505
1506 x_progress := '020';
1507 validate_dest_type(x_cascaded_table, n);
1508 x_progress := '030';
1509 validate_ship_to_loc(x_cascaded_table, n);
1510 x_progress := '040';
1511 validate_tax_code(x_cascaded_table,
1512 n,
1513 x_asn_type
1514 ); /* Bug3454491 (3) */
1515 x_progress := '050';
1516 validate_ref_integrity(x_cascaded_table,
1517 n,
1518 x_header_record
1519 );
1520
1521 IF (g_asn_debug = 'Y') THEN
1522 asn_debug.put_line('After validate_ref_integrity');
1523 END IF;
1524
1525 x_progress := '060';
1526 validate_transaction_type(x_cascaded_table, n);
1527
1528 IF (g_asn_debug = 'Y') THEN
1529 asn_debug.put_line('After validate_transaction_type');
1530 END IF;
1531
1532 x_progress := '070';
1533 validate_temp_labor_info(x_cascaded_table,
1534 n,
1535 x_header_record
1536 );
1537
1538 IF (g_asn_debug = 'Y') THEN
1539 asn_debug.put_line('After validate_temp_labour_info');
1540 END IF;
1541
1542 x_progress := '080';
1543 validate_amount(x_cascaded_table,
1544 n,
1545 x_header_record
1546 );
1547
1548 IF (g_asn_debug = 'Y') THEN
1549 asn_debug.put_line('After validate_amount');
1550 END IF;
1551 EXCEPTION
1552 WHEN OTHERS THEN
1553 IF (g_asn_debug = 'Y') THEN
1554 asn_debug.put_line('Exception at ' || x_progress);
1555 asn_debug.put_line(SQLERRM);
1556 asn_debug.put_line('Exit validate_amt_based_rcv_line');
1557 END IF;
1558 END validate_amt_based_rcv_line;
1559
1560 PROCEDURE derive_ship_to_org_info(
1561 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1562 n IN OUT NOCOPY BINARY_INTEGER,
1563 x_header_record IN rcv_roi_preprocessor.header_rec_type
1564 ) IS
1565 ship_to_org_record rcv_shipment_object_sv.organization_id_record_type;
1566 x_to_organization_code VARCHAR2(5);
1567 BEGIN
1568 -- default org from header in case it is null at the line level
1569 asn_debug.put_line('error derive_ship_to_org_info' || x_cascaded_table(n).error_status);
1570 x_cascaded_table(n).error_status := 'S';
1571 asn_debug.put_line('the to_org_code = ' || x_cascaded_table(n).to_organization_code);
1572
1573 IF x_cascaded_table(n).to_organization_code IS NULL
1574 AND x_cascaded_table(n).error_status IN('S', 'W') THEN
1575 asn_debug.put_line('Attempting to default the org from the ship to location');
1576
1577 IF (g_asn_debug = 'Y') THEN
1578 asn_debug.put_line('Attempting to default the org from the ship to location');
1579 END IF;
1580
1581 IF (x_cascaded_table(n).ship_to_location_code IS NOT NULL) THEN
1582 SELECT MAX(org.organization_code)
1583 INTO x_to_organization_code
1584 FROM hr_locations hl,
1585 mtl_parameters org
1586 WHERE x_cascaded_table(n).ship_to_location_code = hl.location_code
1587 AND hl.inventory_organization_id = org.organization_id;
1588
1589 x_cascaded_table(n).to_organization_code := x_to_organization_code;
1590
1591 IF (g_asn_debug = 'Y') THEN
1592 asn_debug.put_line('Set Org Code using location code = ' || x_cascaded_table(n).to_organization_code);
1593 END IF;
1594 END IF;
1595
1596 IF ( x_cascaded_table(n).to_organization_code IS NULL
1597 AND x_header_record.header_record.ship_to_organization_code IS NOT NULL) THEN
1598 IF (g_asn_debug = 'Y') THEN
1599 asn_debug.put_line('Will default org change DUH to ' || x_header_record.header_record.ship_to_organization_code);
1600 END IF;
1601
1602 x_cascaded_table(n).to_organization_code := x_header_record.header_record.ship_to_organization_code;
1603 END IF;
1604 END IF;
1605
1606 -- call derivation procedures if conditions are met
1607
1608 asn_debug.put_line('to_organization_id ' || x_cascaded_table(n).to_organization_id);
1609 asn_debug.put_line('to_organization_code ' || x_cascaded_table(n).to_organization_code);
1610
1611 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1612 AND ( x_cascaded_table(n).to_organization_id IS NULL
1613 AND x_cascaded_table(n).to_organization_code IS NOT NULL) THEN
1614 IF (g_asn_debug = 'Y') THEN
1615 asn_debug.put_line('X_Progress ' || x_progress);
1616 END IF;
1617
1618 ship_to_org_record.organization_code := x_cascaded_table(n).to_organization_code;
1619 ship_to_org_record.organization_id := x_cascaded_table(n).to_organization_id;
1620 ship_to_org_record.error_record.error_status := 'S';
1621 ship_to_org_record.error_record.error_message := NULL;
1622
1623 IF (g_asn_debug = 'Y') THEN
1624 asn_debug.put_line('Into Derive Organization Record Procedure');
1625 END IF;
1626
1627 po_orgs_sv.derive_org_info(ship_to_org_record);
1628
1629 IF (g_asn_debug = 'Y') THEN
1630 asn_debug.put_line('Debug Output after organization procedure');
1631 asn_debug.put_line(ship_to_org_record.organization_code);
1632 asn_debug.put_line(TO_CHAR(ship_to_org_record.organization_id));
1633 asn_debug.put_line(ship_to_org_record.error_record.error_status);
1634 asn_debug.put_line('Debug organization output over');
1635 END IF;
1636
1637 x_cascaded_table(n).to_organization_code := ship_to_org_record.organization_code;
1638 x_cascaded_table(n).to_organization_id := ship_to_org_record.organization_id;
1639 x_cascaded_table(n).error_status := ship_to_org_record.error_record.error_status;
1640 x_cascaded_table(n).error_message := ship_to_org_record.error_record.error_message;
1641 END IF;
1642 END derive_ship_to_org_info;
1643
1644 PROCEDURE derive_vendor_info(
1645 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1646 n IN OUT NOCOPY BINARY_INTEGER
1647 ) IS
1648 vendor_record rcv_shipment_header_sv.vendorrectype;
1649 BEGIN
1650 asn_debug.put_line('i am inside the derive_vendor_info method');
1651
1652 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
1653 IF ( x_cascaded_table(n).vendor_name IS NOT NULL
1654 OR x_cascaded_table(n).vendor_num IS NOT NULL
1655 OR x_cascaded_table(n).vendor_id IS NOT NULL) THEN
1656 vendor_record.vendor_name := x_cascaded_table(n).vendor_name;
1657 vendor_record.vendor_num := x_cascaded_table(n).vendor_num;
1658 vendor_record.vendor_id := x_cascaded_table(n).vendor_id;
1659 vendor_record.error_record.error_message := x_cascaded_table(n).error_message;
1660 vendor_record.error_record.error_status := x_cascaded_table(n).error_status;
1661
1662 IF (g_asn_debug = 'Y') THEN
1663 asn_debug.put_line('In Vendor Procedure');
1664 END IF;
1665
1666 po_vendors_sv.derive_vendor_info(vendor_record);
1667
1668 IF (g_asn_debug = 'Y') THEN
1669 asn_debug.put_line(TO_CHAR(vendor_record.vendor_id));
1670 asn_debug.put_line(vendor_record.vendor_name);
1671 asn_debug.put_line(vendor_record.vendor_num);
1672 asn_debug.put_line(vendor_record.error_record.error_status);
1673 asn_debug.put_line(vendor_record.error_record.error_message);
1674 END IF;
1675
1676 x_cascaded_table(n).vendor_name := vendor_record.vendor_name;
1677 x_cascaded_table(n).vendor_num := vendor_record.vendor_num;
1678 x_cascaded_table(n).vendor_id := vendor_record.vendor_id;
1679 x_cascaded_table(n).error_message := vendor_record.error_record.error_message;
1680 x_cascaded_table(n).error_status := vendor_record.error_record.error_status;
1681 END IF;
1682 END IF;
1683 END derive_vendor_info;
1684
1685 PROCEDURE derive_vendor_site_info(
1686 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1687 n IN OUT NOCOPY BINARY_INTEGER
1688 ) IS
1689 vendor_site_record rcv_shipment_header_sv.vendorsiterectype;
1690 BEGIN
1691 IF x_cascaded_table(n).error_status IN('S', 'W')
1692 AND ( x_cascaded_table(n).vendor_site_code IS NOT NULL
1693 OR x_cascaded_table(n).vendor_site_id IS NOT NULL) THEN
1694 vendor_site_record.vendor_site_code := x_cascaded_table(n).vendor_site_code;
1695 vendor_site_record.vendor_id := x_cascaded_table(n).vendor_id;
1696 vendor_site_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
1697 vendor_site_record.organization_id := x_cascaded_table(n).to_organization_id;
1698 vendor_site_record.error_record.error_message := x_cascaded_table(n).error_message;
1699 vendor_site_record.error_record.error_status := x_cascaded_table(n).error_status;
1700
1701 IF (g_asn_debug = 'Y') THEN
1702 asn_debug.put_line('In Vendor Site Procedure');
1703 END IF;
1704
1705 po_vendor_sites_sv.derive_vendor_site_info(vendor_site_record);
1706
1707 IF (g_asn_debug = 'Y') THEN
1708 asn_debug.put_line(vendor_site_record.vendor_site_code);
1709 asn_debug.put_line(vendor_site_record.vendor_site_id);
1710 END IF;
1711
1712 x_cascaded_table(n).vendor_site_code := vendor_site_record.vendor_site_code;
1713 x_cascaded_table(n).vendor_id := vendor_site_record.vendor_id;
1714 x_cascaded_table(n).vendor_site_id := vendor_site_record.vendor_site_id;
1715 x_cascaded_table(n).to_organization_id := vendor_site_record.organization_id;
1716 x_cascaded_table(n).error_message := vendor_site_record.error_record.error_message;
1717 x_cascaded_table(n).error_status := vendor_site_record.error_record.error_status;
1718 END IF;
1719 END derive_vendor_site_info;
1720
1721 PROCEDURE derive_po_header_info(
1722 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1723 n IN OUT NOCOPY BINARY_INTEGER
1724 ) IS
1725 vendor_site_record rcv_shipment_header_sv.vendorsiterectype;
1726 document_num_record rcv_shipment_line_sv.document_num_record_type;
1727 BEGIN
1728 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1729 AND ( x_cascaded_table(n).po_header_id IS NULL
1730 AND x_cascaded_table(n).document_num IS NOT NULL) THEN
1731 IF (g_asn_debug = 'Y') THEN
1732 asn_debug.put_line('X_progress ' || x_progress);
1733 asn_debug.put_line('shipment_header_id ' || x_cascaded_table(n).shipment_header_id);
1734 END IF;
1735
1736 document_num_record.document_num := x_cascaded_table(n).document_num;
1737 document_num_record.error_record.error_status := 'S';
1738 document_num_record.error_record.error_message := NULL;
1739
1740 IF (g_asn_debug = 'Y') THEN
1741 asn_debug.put_line('Derive po_header_id');
1742 END IF;
1743
1744 rcv_transactions_interface_sv.get_po_header_id(document_num_record);
1745 x_cascaded_table(n).po_header_id := document_num_record.po_header_id;
1746 x_cascaded_table(n).error_status := document_num_record.error_record.error_status;
1747 x_cascaded_table(n).error_message := document_num_record.error_record.error_message;
1748 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1749 'DOCUMENT_NUM',
1750 FALSE
1751 );
1752
1753 IF (g_asn_debug = 'Y') THEN
1754 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).po_header_id));
1755 END IF;
1756 END IF;
1757 END derive_po_header_info;
1758
1759 PROCEDURE derive_asn_header_info(
1760 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1761 n IN OUT NOCOPY BINARY_INTEGER,
1762 x_header_record IN rcv_roi_preprocessor.header_rec_type
1763 ) IS
1764 BEGIN
1765 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
1766 /*
1767 ** Bug 4523892
1768 ** Removed the code that was checking if the current transaction
1769 ** was against ASN or PO since global variable g_txn_against_asn
1770 ** holds that information and is being used here
1771 */
1772 IF ( NVL(x_header_record.header_record.asn_type, 'STD') = 'STD'
1773 AND x_cascaded_table(n).transaction_type = 'RECEIVE'
1774 AND (rcv_roi_header.g_txn_against_asn = 'Y')) THEN --{ /* Bug4523892 */
1775
1776 x_cascaded_table(n).shipment_header_id := x_header_record.header_record.receipt_header_id;
1777
1778 IF (g_asn_debug = 'Y') THEN
1779 asn_debug.put_line('shipment_header_id in derive_asn_header_info ' || x_cascaded_table(n).shipment_header_id);
1780 END IF;
1781
1782 IF (x_cascaded_table(n).shipment_header_id IS NULL) THEN --{
1783 IF (g_asn_debug = 'Y') THEN
1784 asn_debug.put_line('Cannot derive shipment_header_id');
1785 END IF;
1786
1787 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1788 rcv_error_pkg.set_error_message('RCV_NO_SHIP_ID', x_cascaded_table(n).error_message);
1789 rcv_error_pkg.set_token('NUMBER', x_cascaded_table(n).shipment_num);
1790 rcv_error_pkg.log_interface_error('SHIPMENT_NUM', FALSE);
1791 END IF; --}
1792 END IF; --}
1793 END IF; --}
1794 EXCEPTION
1795 WHEN OTHERS THEN
1796 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
1797 rcv_error_pkg.set_sql_error_message('derive_asn_header_info', '000');
1798 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
1799 rcv_error_pkg.log_interface_error('SHIPMENT_NUM', FALSE);
1800 END derive_asn_header_info;
1801
1802 PROCEDURE derive_item_info(
1803 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1804 n IN OUT NOCOPY BINARY_INTEGER
1805 ) IS
1806 item_id_record rcv_shipment_line_sv.item_id_record_type;
1807 BEGIN
1808 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1809 AND ( x_cascaded_table(n).item_id IS NULL
1810 AND (x_cascaded_table(n).item_num IS NOT NULL)) THEN
1811 IF (g_asn_debug = 'Y') THEN
1812 asn_debug.put_line('X_progress ' || x_progress);
1813 END IF;
1814
1815 item_id_record.item_num := x_cascaded_table(n).item_num;
1816 item_id_record.vendor_item_num := NULL; -- x_cascaded_table(n).vendor_item_num;
1817 item_id_record.to_organization_id := x_cascaded_table(n).to_organization_id;
1818 item_id_record.error_record.error_status := 'S';
1819 item_id_record.error_record.error_message := NULL;
1820
1821 IF (g_asn_debug = 'Y') THEN
1822 asn_debug.put_line('Derive item_id');
1823 END IF;
1824
1825 rcv_transactions_interface_sv.get_item_id(item_id_record);
1826 x_cascaded_table(n).item_id := item_id_record.item_id;
1827 x_cascaded_table(n).primary_unit_of_measure := item_id_record.primary_unit_of_measure;
1828 x_cascaded_table(n).use_mtl_lot := item_id_record.use_mtl_lot; -- bug 608353
1829 x_cascaded_table(n).use_mtl_serial := item_id_record.use_mtl_serial; -- bug 608353
1830 x_cascaded_table(n).error_status := item_id_record.error_record.error_status;
1831 x_cascaded_table(n).error_message := item_id_record.error_record.error_message;
1832 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1833 'ITEM_NUM',
1834 FALSE
1835 );
1836 END IF;
1837 END derive_item_info;
1838
1839 PROCEDURE derive_substitute_item_info(
1840 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1841 n IN OUT NOCOPY BINARY_INTEGER
1842 ) IS
1843 sub_item_id_record rcv_shipment_line_sv.sub_item_id_record_type;
1844 BEGIN
1845 /* FPJ Services.
1846 * We do not support Substitute Receipts for service POs.
1847 */
1848 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
1849 RETURN;
1850 END IF;
1851
1852 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1853 AND ( x_cascaded_table(n).substitute_item_id IS NULL
1854 AND (x_cascaded_table(n).substitute_item_num IS NOT NULL)) THEN
1855 IF (g_asn_debug = 'Y') THEN
1856 asn_debug.put_line('X_progress ' || x_progress);
1857 END IF;
1858
1859 sub_item_id_record.substitute_item_num := x_cascaded_table(n).substitute_item_num;
1860 sub_item_id_record.vendor_item_num := NULL; -- x_cascaded_table(n).vendor_item_num;
1861 sub_item_id_record.error_record.error_status := 'S';
1862 sub_item_id_record.error_record.error_message := NULL;
1863
1864 IF (g_asn_debug = 'Y') THEN
1865 asn_debug.put_line('Derive Substitute Item Id');
1866 END IF;
1867
1868 rcv_transactions_interface_sv.get_sub_item_id(sub_item_id_record);
1869 x_cascaded_table(n).substitute_item_id := sub_item_id_record.substitute_item_id;
1870 x_cascaded_table(n).error_status := sub_item_id_record.error_record.error_status;
1871 x_cascaded_table(n).error_message := sub_item_id_record.error_record.error_message;
1872
1873 IF (g_asn_debug = 'Y') THEN
1874 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).substitute_item_id));
1875 END IF;
1876
1877 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1878 'SUBSTITUTE_ITEM_NUM',
1879 FALSE
1880 );
1881 END IF;
1882 END derive_substitute_item_info;
1883
1884 PROCEDURE derive_po_line_info(
1885 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1886 n IN OUT NOCOPY BINARY_INTEGER
1887 ) IS
1888 po_line_id_record rcv_shipment_line_sv.po_line_id_record_type;
1889 release_id_record rcv_shipment_line_sv.release_id_record_type;
1890 l_asn_type rcv_shipment_headers.asn_type%type;
1891 l_error_column VARCHAR2(30); --Bugfix 4881909
1892 l_is_clm_po VARCHAR2(5) := 'N'; -- <Bug 9342280 : Added for CLM project>
1893 BEGIN
1894 IF (g_asn_debug = 'Y') THEN
1895 asn_debug.put_line('In derive_po_line_info');
1896 END IF;
1897
1898 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1899 AND ( x_cascaded_table(n).po_line_id IS NULL
1900 AND x_cascaded_table(n).po_header_id IS NOT NULL
1901 AND x_cascaded_table(n).document_line_num IS NOT NULL) THEN
1902 IF (g_asn_debug = 'Y') THEN
1903 asn_debug.put_line('X_progress ' || x_progress);
1904 END IF;
1905
1906 po_line_id_record.po_header_id := x_cascaded_table(n).po_header_id;
1907 po_line_id_record.document_line_num := x_cascaded_table(n).document_line_num;
1908 po_line_id_record.po_line_id := x_cascaded_table(n).po_line_id;
1909 po_line_id_record.item_id := x_cascaded_table(n).item_id;
1910 po_line_id_record.error_record.error_status := 'S';
1911 po_line_id_record.error_record.error_message := NULL;
1912
1913 IF (g_asn_debug = 'Y') THEN
1914 asn_debug.put_line('Derive po_line_id');
1915 END IF;
1916
1917 rcv_transactions_interface_sv.get_po_line_id(po_line_id_record);
1918
1919 IF x_cascaded_table(n).item_id IS NULL THEN
1920 x_cascaded_table(n).item_id := po_line_id_record.item_id;
1921 END IF;
1922
1923 x_cascaded_table(n).po_line_id := po_line_id_record.po_line_id;
1924 x_cascaded_table(n).error_status := po_line_id_record.error_record.error_status;
1925 x_cascaded_table(n).error_message := po_line_id_record.error_record.error_message;
1926
1927 IF (g_asn_debug = 'Y') THEN
1928 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).po_line_id));
1929 END IF;
1930
1931 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1932 'DOCUMENT_LINE_NUM',
1933 FALSE
1934 );
1935 END IF; -- set line id
1936
1937 IF (g_asn_debug = 'Y') THEN
1938 asn_debug.put_line('po_line_id to get matching_basis ' || TO_CHAR(x_cascaded_table(n).po_line_id));
1939 END IF;
1940
1941 -- <Bug 9342280 : Added for CLM project>
1942 l_is_clm_po := po_clm_intg_grp.is_clm_po(p_po_header_id => NULL,
1943 p_po_line_id => x_cascaded_table(n).po_line_id,
1944 p_po_line_location_id => NULL,
1945 p_po_distribution_id => NULL);
1946
1947
1948 IF l_is_clm_po = 'Y' THEN
1949
1950 BEGIN
1951
1952 SELECT po_line_id
1953 INTO x_cascaded_table(n).po_line_id
1954 FROM po_lines_trx_v
1955 WHERE po_header_id = x_cascaded_table(n).po_header_id
1956 AND po_line_id = x_cascaded_table(n).po_line_id;
1957
1958 EXCEPTION
1959 WHEN no_data_found THEN
1960 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1961 rcv_error_pkg.set_error_message('RCV_CLM_INVALID_PO_LINE',x_cascaded_table(n).error_message);
1962 rcv_error_pkg.set_token('DOCNUM',x_cascaded_table(n).document_num);
1963 rcv_error_pkg.set_token('DOCLINE',x_cascaded_table(n).document_line_num);
1964 rcv_error_pkg.log_interface_error('DOCUMENT_LINE_NUM', FALSE);
1965 END;
1966 END IF;
1967 -- <END CLM>
1968
1969 /* Complex Work Start.
1970 * Moving the logic to derive matching_basis
1971 * to a separate procedure derive_matching_basis.
1972 -- Determine whether this is a services line type
1973 IF x_cascaded_table(n).po_line_id IS NOT NULL THEN
1974 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
1975 NVL(purchase_basis, 'GOODS'),
1976 NVL(matching_basis, 'QUANTITY')
1977 INTO x_cascaded_table(n).value_basis,
1978 x_cascaded_table(n).purchase_basis,
1979 x_cascaded_table(n).matching_basis
1980 FROM po_lines
1981 WHERE po_line_id = x_cascaded_table(n).po_line_id;
1982 ELSE
1983 -- we require line info for receiving against services lines
1984 x_cascaded_table(n).matching_basis := 'QUANTITY';
1985 x_cascaded_table(n).purchase_basis := 'GOODS';
1986 END IF;
1987
1988 IF (g_asn_debug = 'Y') THEN
1989 asn_debug.put_line('matching_basis ' || x_cascaded_table(n).matching_basis);
1990 END IF;
1991
1992 Complex Work End*/
1993 -- Get the primary uom in case item_id was determined on the basis of the po_line_id
1994 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1995 AND x_cascaded_table(n).item_id IS NOT NULL THEN
1996 /*BEGIN Bug 5592084: Incase the PRIMARY_UNIT_OF_MEASURE has value
1997 defined in MSI but doesnt match the one defined for the item
1998 then we need to raise an error.
1999 Commenting out below condition to ensure that the validation
2000 is done for the primary_unit_of_measure in all cases i.e. irrespective
2001 of value being specified or not in RTI.
2002 */
2003 --AND x_cascaded_table(n).primary_unit_of_measure IS NULL THEN
2004 DECLARE
2005 l_primary_unit_of_measure mtl_system_items.primary_unit_of_measure%TYPE;
2006 BEGIN
2007 /* BUG 608353 */
2008 SELECT primary_unit_of_measure
2009 INTO l_primary_unit_of_measure
2010 FROM mtl_system_items
2011 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
2012 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
2013 IF (g_asn_debug = 'Y') THEN
2014 asn_debug.put_line('Primary UOM from RTI :' || x_cascaded_table(n).primary_unit_of_measure);
2015 asn_debug.put_line('Derived PRIMARY UOM from MSI:' || l_primary_unit_of_measure);
2016 END IF;
2017 IF (NVL(x_cascaded_table(n).primary_unit_of_measure, l_primary_unit_of_measure) <> l_primary_unit_of_measure) THEN
2018 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2019 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE');
2020 rcv_error_pkg.set_token('COLUMN', 'PRIMARY_UNIT_OF_MEASURE');
2021 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).primary_unit_of_measure);
2022 rcv_error_pkg.set_token('SYS_VALUE', l_primary_unit_of_measure);
2023 rcv_error_pkg.log_interface_error('PRIMARY_UNIT_OF_MEASURE');
2024 ELSE
2025 x_cascaded_table(n).primary_unit_of_measure := l_primary_unit_of_measure;
2026 END IF;
2027 IF (g_asn_debug = 'Y') THEN
2028 asn_debug.put_line('Primary UOM: ' || x_cascaded_table(n).primary_unit_of_measure);
2029 END IF;
2030 EXCEPTION
2031 WHEN NO_DATA_FOUND THEN
2032 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
2033 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE_NE');
2034 rcv_error_pkg.set_token('COLUMN', 'PRIMARY_UNIT_OF_MEASURE');
2035 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).primary_unit_of_measure);
2036 rcv_error_pkg.log_interface_warning('PRIMARY_UNIT_OF_MEASURE');
2037 END;
2038 /*END Bug 5592084*/
2039 END IF; -- set primary_uom
2040
2041 /* We need to get the value of use_mtl_lot and use_mtl_serial
2042 * irrespective of whether primary_uom is populated in rti.
2043 */
2044 /*
2045 BEGIN Comment: Bug: 4735484
2046 IF ((x_cascaded_table(n).error_status IN('S', 'W')
2047 AND x_cascaded_table(n).item_id IS NOT NULL)
2048 AND (x_cascaded_table(n).use_mtl_lot IS NULL
2049 OR x_cascaded_table(n).use_mtl_serial IS NULL)) THEN
2050 BEGIN
2051 SELECT NVL(x_cascaded_table(n).use_mtl_lot, lot_control_code),
2052 NVL(x_cascaded_table(n).use_mtl_serial, serial_number_control_code)
2053 INTO x_cascaded_table(n).use_mtl_lot,
2054 x_cascaded_table(n).use_mtl_serial
2055 FROM mtl_system_items
2056 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
2057 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
2058
2059 IF (g_asn_debug = 'Y') THEN
2060 asn_debug.put_line('use_mtl_lot: ' || x_cascaded_table(n).use_mtl_lot);
2061 asn_debug.put_line('use_mtl_serial: ' || x_cascaded_table(n).use_mtl_serial);
2062 END IF;
2063 EXCEPTION
2064 WHEN NO_DATA_FOUND THEN
2065 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
2066 rcv_error_pkg.set_error_message('PO_RI_INVALID_ITEM_ID', x_cascaded_table(n).error_message);
2067 rcv_error_pkg.log_interface_warning('DOCUMENT_LINE_NUM');
2068 END;
2069 END IF; -- set primary_uom
2070 END Comment: Bug: 4735484
2071 */
2072 /* Bug 2020269 : uom_code needs to be derived from unit_of_measure
2073 entered in rcv_transactions_interface.
2074 */
2075 IF (x_cascaded_table(n).unit_of_measure IS NOT NULL) THEN
2076 IF (g_asn_debug = 'Y') THEN
2077 asn_debug.put_line('X_progress ' || x_progress);
2078 END IF;
2079
2080 SELECT muom.uom_code
2081 INTO x_cascaded_table(n).uom_code
2082 FROM mtl_units_of_measure muom
2083 WHERE muom.unit_of_measure = x_cascaded_table(n).unit_of_measure;
2084 ELSE
2085 IF (g_asn_debug = 'Y') THEN
2086 asn_debug.put_line('uom_code not dereived as unit_of_measure is null');
2087 END IF;
2088 END IF; -- set uom_code
2089
2090 x_progress := '026';
2091
2092 /* Bug 1830177. If the po_line_id is null then we do not populate the correct
2093 * po_release_id even if we specify the release_num since we do not enter
2094 * this block. Removed the condition x_cascaded_table(n).po_line_id is not null
2095 */
2096 /* R12 Complex Work.
2097 * We cannot create releases for a work confirmations.
2098 */
2099 If ( x_cascaded_table(n).header_interface_id is not null) then
2100 select asn_type
2101 into l_asn_type
2102 from rcv_headers_interface
2103 where header_interface_id =
2104 x_cascaded_table(n).header_interface_id;
2105 end if;
2106
2107 /* Bug 8758194 In case of Blanket POs with multiple releases for the same line, if po_release_id is populated
2108 in RTI, the following condition was failing since it was checking for po_release_id to be NULL, and hence
2109 the derivation of values was not taking place. Commented the unnecessary condition to ensure that derivation
2110 of values goes through fine for such a case. Further, modified the DEBUG messages.
2111 Moreover, Added code to derive the release number from po_releases_all if the po_release_id is populated and
2112 release_num is not populated in RTI.
2113 */
2114 IF (nvl(l_asn_type,'STD') <> 'WC' ) THEN --{
2115 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2116 /* AND x_cascaded_table(n).po_release_id IS NULL -- Bug 8758194 */
2117 AND -- Maybe we need an or with shipnum,relnum
2118 x_cascaded_table(n).po_header_id IS NOT NULL THEN --{
2119 IF (g_asn_debug = 'Y') THEN
2120 asn_debug.put_line('X_progress ' || x_progress);
2121 END IF;
2122
2123 IF (x_cascaded_table(n).po_release_id IS NOT NULL AND x_cascaded_table(n).release_num IS NULL) THEN
2124 IF (g_asn_debug = 'Y') THEN
2125 asn_debug.put_line('Deriving Release Number based on PO Release ID '||x_cascaded_table(n).po_release_id);
2126 END IF;
2127
2128 SELECT release_num
2129 INTO x_cascaded_table(n).release_num
2130 FROM po_releases_all
2131 WHERE po_header_id = x_cascaded_table(n).po_header_id
2132 AND po_release_id = x_cascaded_table(n).po_release_id;
2133
2134 IF (g_asn_debug = 'Y') THEN
2135 asn_debug.put_line('x_cascaded_table(n).release_num : ' || x_cascaded_table(n).release_num);
2136 END IF;
2137 END IF;
2138
2139 release_id_record.po_header_id := x_cascaded_table(n).po_header_id;
2140 release_id_record.release_num := x_cascaded_table(n).release_num;
2141 release_id_record.po_line_id := x_cascaded_table(n).po_line_id;
2142 release_id_record.shipment_num := x_cascaded_table(n).document_shipment_line_num;
2143 release_id_record.error_record.error_status := 'S';
2144 release_id_record.error_record.error_message := NULL;
2145
2146 IF (g_asn_debug = 'Y') THEN
2147 asn_debug.put_line('Derive po_line_location_id, shipment_num, po_release_id');
2148 END IF;
2149
2150 IF (g_asn_debug = 'Y') THEN
2151 asn_debug.put_line('### po_header_id : ' || release_id_record.po_header_id);
2152 asn_debug.put_line('### release_num : ' || release_id_record.release_num);
2153 asn_debug.put_line('### po_line_id : ' || release_id_record.po_line_id);
2154 asn_debug.put_line('### po_line_location_id : ' || release_id_record.po_line_location_id);
2155 asn_debug.put_line('### shipment_num : ' || release_id_record.shipment_num);
2156 asn_debug.put_line('### po_release_id : ' || release_id_record.po_release_id);
2157 END IF;
2158
2159 po_releases_sv4.get_po_release_id(release_id_record);
2160
2161 IF (g_asn_debug = 'Y') THEN
2162 asn_debug.put_line('^^^ po_header_id : ' || release_id_record.po_header_id);
2163 asn_debug.put_line('^^^ release_num : ' || release_id_record.release_num);
2164 asn_debug.put_line('^^^ po_line_id : ' || release_id_record.po_line_id);
2165 asn_debug.put_line('^^^ po_line_location_id : ' || release_id_record.po_line_location_id);
2166 asn_debug.put_line('^^^ shipment_num : ' || release_id_record.shipment_num);
2167 asn_debug.put_line('^^^ po_release_id : ' || release_id_record.po_release_id);
2168 END IF;
2169 /* End of fix for Bug 8758194 */
2170
2171 x_cascaded_table(n).error_status := release_id_record.error_record.error_status;
2172 x_cascaded_table(n).error_message := release_id_record.error_record.error_message;
2173
2174 /* po_releases_sv4 does not follow error handling paradigm */
2175 l_error_column := 'RELEASE_NUM';
2176 IF (x_cascaded_table(n).error_status = 'F') THEN
2177 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2178 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
2179
2180 /* Bug 4881909: Setting necessary tokens for messages to be logged in po_interface_errors
2181 ** if release number or PO shipment line information is in error.
2182 */
2183
2184 IF release_id_record.error_record.error_message = 'RCV_ITEM_PO_REL_ID' THEN
2185
2186 rcv_error_pkg.set_token('NUMBER', x_cascaded_table(n).release_num);
2187
2188 ELSIF release_id_record.error_record.error_message = 'RCV_ROI_INVALID_PO_SHIP_NUM' THEN
2189 rcv_error_pkg.set_token('PO_SHIP_NUM', x_cascaded_table(n).document_shipment_line_num);
2190 rcv_error_pkg.set_token('PONUM', x_cascaded_table(n).document_num);
2191 l_error_column := 'DOCUMENT_SHIPMENT_LINE_NUM';
2192
2193 ELSIF release_id_record.error_record.error_message = 'RCV_ROI_INVALID_REL_SHIP_NUM' THEN
2194 rcv_error_pkg.set_token('PO_SHIP_NUM', x_cascaded_table(n).document_shipment_line_num);
2195 rcv_error_pkg.set_token('PONUM', x_cascaded_table(n).document_num);
2196 rcv_error_pkg.set_token('RELEASE', x_cascaded_table(n).release_num);
2197 l_error_column := 'DOCUMENT_SHIPMENT_LINE_NUM';
2198
2199 ELSIF release_id_record.error_record.error_message = 'RCV_ROI_INVALID_RELEASE_NUM' THEN
2200
2201 rcv_error_pkg.set_token('RELEASE', x_cascaded_table(n).release_num);
2202 rcv_error_pkg.set_token('PONUM', x_cascaded_table(n).document_num);
2203
2204 END IF;
2205 END IF;
2206
2207
2208 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,l_error_column, FALSE);
2209
2210 IF x_cascaded_table(n).po_line_location_id IS NULL THEN
2211 x_cascaded_table(n).po_line_location_id := release_id_record.po_line_location_id;
2212
2213 IF (g_asn_debug = 'Y') THEN
2214 asn_debug.put_line('PO_LINE_LOCATION_ID ' || TO_CHAR(x_cascaded_table(n).po_line_location_id));
2215 END IF;
2216 END IF;
2217
2218 IF x_cascaded_table(n).document_shipment_line_num IS NULL THEN
2219 x_cascaded_table(n).document_shipment_line_num := release_id_record.shipment_num;
2220
2221 IF (g_asn_debug = 'Y') THEN
2222 asn_debug.put_line('DOCUMENT_SHIPMENT_NUM ' || TO_CHAR(x_cascaded_table(n).document_shipment_line_num));
2223 END IF;
2224 END IF;
2225
2226 x_cascaded_table(n).po_release_id := release_id_record.po_release_id;
2227
2228 IF (g_asn_debug = 'Y') THEN
2229 asn_debug.put_line('PO_RELEASE_ID ' || TO_CHAR(x_cascaded_table(n).po_release_id));
2230 END IF;
2231 END IF; -- }set release info
2232 End if; --}-- <> 'WC'
2233 /* Complex Work.
2234 * Add exception block.
2235 */
2236 exception
2237 when others then
2238 IF (g_asn_debug = 'Y') THEN
2239 asn_debug.put_line('Exception in derive_po_line_info'||x_progress);
2240 END IF;
2241 raise;
2242 END derive_po_line_info;
2243
2244 PROCEDURE derive_from_org_info(
2245 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2246 n IN OUT NOCOPY BINARY_INTEGER
2247 ) IS
2248 ship_to_org_record rcv_shipment_object_sv.organization_id_record_type;
2249 BEGIN
2250 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2251 AND ( x_cascaded_table(n).from_organization_id IS NULL
2252 AND x_cascaded_table(n).from_organization_code IS NOT NULL) THEN
2253 IF (g_asn_debug = 'Y') THEN
2254 asn_debug.put_line('X_progress ' || x_progress);
2255 END IF;
2256
2257 ship_to_org_record.organization_code := x_cascaded_table(n).from_organization_code;
2258 ship_to_org_record.organization_id := x_cascaded_table(n).from_organization_id;
2259 ship_to_org_record.error_record.error_status := 'S';
2260 ship_to_org_record.error_record.error_message := NULL;
2261
2262 IF (g_asn_debug = 'Y') THEN
2263 asn_debug.put_line('In From Organization Procedure');
2264 END IF;
2265
2266 po_orgs_sv.derive_org_info(ship_to_org_record);
2267
2268 IF (g_asn_debug = 'Y') THEN
2269 asn_debug.put_line('From organization code ' || ship_to_org_record.organization_code);
2270 asn_debug.put_line('From organization id ' || TO_CHAR(ship_to_org_record.organization_id));
2271 asn_debug.put_line('From organization error status ' || ship_to_org_record.error_record.error_status);
2272 END IF;
2273
2274 x_cascaded_table(n).from_organization_code := ship_to_org_record.organization_code;
2275 x_cascaded_table(n).from_organization_id := ship_to_org_record.organization_id;
2276 x_cascaded_table(n).error_status := ship_to_org_record.error_record.error_status;
2277 x_cascaded_table(n).error_message := ship_to_org_record.error_record.error_message;
2278
2279 /* po_orgs_sv does not follow error handling paradigm */
2280 IF (x_cascaded_table(n).error_status = 'F') THEN
2281 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2282 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
2283 END IF;
2284
2285 END IF;
2286 END derive_from_org_info;
2287
2288 PROCEDURE derive_transit_org_info(
2289 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2290 n IN OUT NOCOPY BINARY_INTEGER
2291 ) IS
2292 ship_to_org_record rcv_shipment_object_sv.organization_id_record_type;
2293 BEGIN
2294 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2295 AND ( x_cascaded_table(n).intransit_owning_org_id IS NULL
2296 AND x_cascaded_table(n).intransit_owning_org_code IS NOT NULL) THEN
2297 IF (g_asn_debug = 'Y') THEN
2298 asn_debug.put_line('X_progress ' || x_progress);
2299 END IF;
2300
2301 ship_to_org_record.organization_code := x_cascaded_table(n).intransit_owning_org_code;
2302 ship_to_org_record.organization_id := x_cascaded_table(n).intransit_owning_org_id;
2303 ship_to_org_record.error_record.error_status := 'S';
2304 ship_to_org_record.error_record.error_message := NULL;
2305
2306 IF (g_asn_debug = 'Y') THEN
2307 asn_debug.put_line('In Intransit Owning Org Record Procedure');
2308 END IF;
2309
2310 po_orgs_sv.derive_org_info(ship_to_org_record);
2311
2312 IF (g_asn_debug = 'Y') THEN
2313 asn_debug.put_line('Intransit organization code ' || ship_to_org_record.organization_code);
2314 asn_debug.put_line('Intransit organization id ' || TO_CHAR(ship_to_org_record.organization_id));
2315 asn_debug.put_line('Intransit error status ' || ship_to_org_record.error_record.error_status);
2316 END IF;
2317
2318 x_cascaded_table(n).intransit_owning_org_code := ship_to_org_record.organization_code;
2319 x_cascaded_table(n).intransit_owning_org_id := ship_to_org_record.organization_id;
2320 x_cascaded_table(n).error_status := ship_to_org_record.error_record.error_status;
2321 x_cascaded_table(n).error_message := ship_to_org_record.error_record.error_message;
2322
2323 /* po_orgs_sv does not follow error handling paradigm */
2324 IF (x_cascaded_table(n).error_status = 'F') THEN
2325 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2326 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
2327 END IF;
2328
2329 END IF;
2330 END derive_transit_org_info;
2331
2332 PROCEDURE derive_location_info(
2333 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2334 n IN OUT NOCOPY BINARY_INTEGER
2335 ) IS
2336 location_id_record rcv_shipment_object_sv.location_id_record_type;
2337 BEGIN
2338 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2339 AND ( x_cascaded_table(n).location_id IS NULL
2340 AND x_cascaded_table(n).location_code IS NOT NULL) THEN
2341 IF (g_asn_debug = 'Y') THEN
2342 asn_debug.put_line('X_progress ' || x_progress);
2343 END IF;
2344
2345 location_id_record.location_code := x_cascaded_table(n).location_code;
2346 location_id_record.error_record.error_status := 'S';
2347 location_id_record.error_record.error_message := NULL;
2348
2349 IF (g_asn_debug = 'Y') THEN
2350 asn_debug.put_line('Derive location_id');
2351 END IF;
2352
2353 rcv_transactions_interface_sv.get_location_id(location_id_record);
2354 x_cascaded_table(n).location_id := location_id_record.location_id;
2355 x_cascaded_table(n).error_status := location_id_record.error_record.error_status;
2356 x_cascaded_table(n).error_message := location_id_record.error_record.error_message;
2357 END IF;
2358 END derive_location_info;
2359
2360 PROCEDURE derive_ship_to_location_info(
2361 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2362 n IN OUT NOCOPY BINARY_INTEGER
2363 ) IS
2364 location_id_record rcv_shipment_object_sv.location_id_record_type;
2365 BEGIN
2366 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2367 AND ( x_cascaded_table(n).ship_to_location_id IS NULL
2368 AND x_cascaded_table(n).ship_to_location_code IS NOT NULL) THEN
2369 IF (g_asn_debug = 'Y') THEN
2370 asn_debug.put_line('X_progress ' || x_progress);
2371 END IF;
2372
2373 location_id_record.location_code := x_cascaded_table(n).ship_to_location_code;
2374 location_id_record.error_record.error_status := 'S';
2375 location_id_record.error_record.error_message := NULL;
2376
2377 IF (g_asn_debug = 'Y') THEN
2378 asn_debug.put_line('Derive ship to location_id');
2379 END IF;
2380
2381 rcv_transactions_interface_sv.get_location_id(location_id_record);
2382 x_cascaded_table(n).ship_to_location_id := location_id_record.location_id;
2383 x_cascaded_table(n).error_status := location_id_record.error_record.error_status;
2384 x_cascaded_table(n).error_message := location_id_record.error_record.error_message;
2385 END IF;
2386 END derive_ship_to_location_info;
2387
2388 PROCEDURE derive_routing_header_info(
2389 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2390 n IN OUT NOCOPY BINARY_INTEGER
2391 ) IS
2392 routing_header_id_record rcv_shipment_line_sv.routing_header_id_rec_type;
2393 BEGIN
2394 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2395 AND ( x_cascaded_table(n).routing_header_id IS NULL
2396 AND x_cascaded_table(n).routing_code IS NOT NULL) THEN
2397 IF (g_asn_debug = 'Y') THEN
2398 asn_debug.put_line('X_progress ' || x_progress);
2399 END IF;
2400
2401 routing_header_id_record.routing_code := x_cascaded_table(n).routing_code;
2402 routing_header_id_record.error_record.error_status := 'S';
2403 routing_header_id_record.error_record.error_message := NULL;
2404
2405 IF (g_asn_debug = 'Y') THEN
2406 asn_debug.put_line('Derive routing_header_id');
2407 END IF;
2408
2409 rcv_transactions_interface_sv.get_routing_header_id(routing_header_id_record);
2410 x_cascaded_table(n).routing_header_id := routing_header_id_record.routing_header_id;
2411 x_cascaded_table(n).error_status := routing_header_id_record.error_record.error_status;
2412 x_cascaded_table(n).error_message := routing_header_id_record.error_record.error_message;
2413 END IF;
2414 END derive_routing_header_info;
2415
2416 PROCEDURE derive_routing_step_info(
2417 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2418 n IN OUT NOCOPY BINARY_INTEGER
2419 ) IS
2420 routing_step_id_record rcv_shipment_line_sv.routing_step_id_rec_type;
2421 BEGIN
2422 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2423 AND ( x_cascaded_table(n).routing_step_id IS NULL
2424 AND x_cascaded_table(n).routing_step IS NOT NULL) THEN
2425 IF (g_asn_debug = 'Y') THEN
2426 asn_debug.put_line('X_progress ' || x_progress);
2427 END IF;
2428
2429 routing_step_id_record.routing_step := x_cascaded_table(n).routing_step;
2430 routing_step_id_record.error_record.error_status := 'S';
2431 routing_step_id_record.error_record.error_message := NULL;
2432
2433 IF (g_asn_debug = 'Y') THEN
2434 asn_debug.put_line('Derive routing Step Id');
2435 END IF;
2436
2437 rcv_transactions_interface_sv.get_routing_step_id(routing_step_id_record);
2438 x_cascaded_table(n).routing_step_id := routing_step_id_record.routing_step_id;
2439 x_cascaded_table(n).error_status := routing_step_id_record.error_record.error_status;
2440 x_cascaded_table(n).error_message := routing_step_id_record.error_record.error_message;
2441 END IF;
2442 END derive_routing_step_info;
2443
2444 PROCEDURE derive_deliver_to_person_info(
2445 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2446 n IN OUT NOCOPY BINARY_INTEGER
2447 ) IS
2448 employee_id_record rcv_shipment_object_sv.employee_id_record_type;
2449 BEGIN
2450 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2451 AND ( x_cascaded_table(n).deliver_to_person_id IS NULL
2452 AND x_cascaded_table(n).deliver_to_person_name IS NOT NULL) THEN
2453 IF (g_asn_debug = 'Y') THEN
2454 asn_debug.put_line('X_progress ' || x_progress);
2455 END IF;
2456
2457 employee_id_record.employee_name := x_cascaded_table(n).deliver_to_person_name;
2458 employee_id_record.employee_id := x_cascaded_table(n).deliver_to_person_id;
2459 employee_id_record.error_record.error_status := 'S';
2460 employee_id_record.error_record.error_message := NULL;
2461
2462 IF (g_asn_debug = 'Y') THEN
2463 asn_debug.put_line('In Derive deliver_to_person_id Information');
2464 END IF;
2465
2466 po_employees_sv.derive_employee_info(employee_id_record);
2467
2468 IF (g_asn_debug = 'Y') THEN
2469 asn_debug.put_line('Employee name ' || employee_id_record.employee_name);
2470 asn_debug.put_line('Employee id ' || TO_CHAR(employee_id_record.employee_id));
2471 asn_debug.put_line('Employee error status ' || employee_id_record.error_record.error_status);
2472 END IF;
2473
2474 x_cascaded_table(n).deliver_to_person_name := employee_id_record.employee_name;
2475 x_cascaded_table(n).deliver_to_person_id := employee_id_record.employee_id;
2476 x_cascaded_table(n).error_status := employee_id_record.error_record.error_status;
2477 x_cascaded_table(n).error_message := employee_id_record.error_record.error_message;
2478
2479 /* po_orgs_sv does not follow error handling paradigm */
2480 IF (x_cascaded_table(n).error_status = 'F') THEN
2481 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2482 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
2483 END IF;
2484
2485 END IF;
2486 END derive_deliver_to_person_info;
2487
2488 PROCEDURE derive_deliver_to_loc_info(
2489 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2490 n IN OUT NOCOPY BINARY_INTEGER
2491 ) IS
2492 location_id_record rcv_shipment_object_sv.location_id_record_type;
2493 BEGIN
2494 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2495 AND ( x_cascaded_table(n).deliver_to_location_id IS NULL
2496 AND x_cascaded_table(n).deliver_to_location_code IS NOT NULL) THEN
2497 IF (g_asn_debug = 'Y') THEN
2498 asn_debug.put_line('X_progress ' || x_progress);
2499 END IF;
2500
2501 location_id_record.location_code := x_cascaded_table(n).deliver_to_location_code;
2502 location_id_record.error_record.error_status := 'S';
2503 location_id_record.error_record.error_message := NULL;
2504
2505 IF (g_asn_debug = 'Y') THEN
2506 asn_debug.put_line('Derive deliver_to_location_id');
2507 END IF;
2508
2509 rcv_transactions_interface_sv.get_location_id(location_id_record);
2510 x_cascaded_table(n).deliver_to_location_id := location_id_record.location_id;
2511 x_cascaded_table(n).error_status := location_id_record.error_record.error_status;
2512 x_cascaded_table(n).error_message := location_id_record.error_record.error_message;
2513 END IF;
2514 END derive_deliver_to_loc_info;
2515
2516 /* WMS Change for receiving(from) locators */
2517 PROCEDURE derive_from_locator_id(
2518 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2519 n IN OUT NOCOPY BINARY_INTEGER
2520 ) IS
2521 BEGIN
2522 IF ( x_cascaded_table(n).from_locator_id IS NULL
2523 AND x_cascaded_table(n).from_locator IS NOT NULL) THEN
2524 IF (g_asn_debug = 'Y') THEN
2525 asn_debug.put_line('inside derive_from_locator_id');
2526 END IF;
2527
2528 SELECT MAX(ml.inventory_location_id)
2529 INTO x_cascaded_table(n).from_locator_id
2530 FROM mtl_item_locations_kfv ml
2531 WHERE ml.concatenated_segments = x_cascaded_table(n).from_locator
2532 AND ( ml.disable_date > SYSDATE
2533 OR ml.disable_date IS NULL)
2534 AND NVL(ml.subinventory_code, 'z') = NVL(x_cascaded_table(n).from_subinventory, 'z')
2535 AND x_cascaded_table(n).to_organization_id = ml.organization_id;
2536
2537 IF (x_cascaded_table(n).from_locator_id IS NULL) THEN
2538 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2539 rcv_error_pkg.set_error_message('RCV_ALL_INVALID_LOCATOR', x_cascaded_table(n).error_message);
2540 END IF;
2541 END IF;
2542 EXCEPTION
2543 WHEN OTHERS THEN
2544 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2545 rcv_error_pkg.set_sql_error_message('derive_from_locator_id', '000');
2546 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2547 END derive_from_locator_id;
2548
2549 PROCEDURE derive_to_locator_id(
2550 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2551 n IN OUT NOCOPY BINARY_INTEGER
2552 ) IS
2553 BEGIN
2554 IF ( x_cascaded_table(n).locator_id IS NULL
2555 AND x_cascaded_table(n).LOCATOR IS NOT NULL
2556 AND x_cascaded_table(n).subinventory IS NOT NULL) THEN /* Bug3993867 */
2557
2558 IF (g_asn_debug = 'Y') THEN
2559 asn_debug.put_line('inside derive_to_locator_id');
2560 END IF;
2561
2562 SELECT MAX(ml.inventory_location_id)
2563 INTO x_cascaded_table(n).locator_id
2564 FROM mtl_item_locations_kfv ml
2565 WHERE ml.concatenated_segments = x_cascaded_table(n).LOCATOR
2566 AND ( ml.disable_date > SYSDATE
2567 OR ml.disable_date IS NULL)
2568 AND NVL(ml.subinventory_code, 'z') = NVL(x_cascaded_table(n).subinventory, 'z')
2569 AND x_cascaded_table(n).to_organization_id = ml.organization_id;
2570
2571 IF (x_cascaded_table(n).locator_id IS NULL) THEN
2572 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2573 rcv_error_pkg.set_error_message('RCV_ALL_INVALID_LOCATOR', x_cascaded_table(n).error_message); /* Bug 3591830 - Changed message name from RCV_ASN_FROM_LOCATOR_ID to RCV_ALL_INVALID_LOCATOR */
2574 END IF;
2575 END IF;
2576 EXCEPTION
2577 WHEN OTHERS THEN
2578 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2579 rcv_error_pkg.set_sql_error_message('derive_to_locator_id', '000');
2580 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2581 END derive_to_locator_id;
2582
2583 PROCEDURE validate_non_services_fields(
2584 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2585 n IN BINARY_INTEGER
2586 ) IS
2587 BEGIN
2588 IF (g_asn_debug = 'Y') THEN
2589 asn_debug.put_line('In validate_non_services_fields');
2590 END IF;
2591
2592 IF x_cascaded_table(n).matching_basis = 'AMOUNT' THEN --{
2593 IF (g_asn_debug = 'Y') THEN
2594 asn_debug.put_line('In first part validate_non_services_fields');
2595 END IF;
2596
2597 /* Bug 5186378: Added the following condtions,
2598 * 1) source_doc_quantity <> 0 and
2599 * 2) primary_quantity <> 0
2600 */
2601 IF x_cascaded_table(n).item_id IS NOT NULL
2602 OR x_cascaded_table(n).item_revision IS NOT NULL
2603 OR x_cascaded_table(n).substitute_item_num IS NOT NULL
2604 OR x_cascaded_table(n).substitute_item_id IS NOT NULL
2605 OR x_cascaded_table(n).quantity IS NOT NULL
2606 OR ( x_cascaded_table(n).primary_quantity IS NOT NULL
2607 AND x_cascaded_table(n).primary_quantity <> 0 )
2608 OR ( x_cascaded_table(n).source_doc_quantity IS NOT NULL
2609 AND x_cascaded_table(n).source_doc_quantity <> 0 )
2610 OR x_cascaded_table(n).vendor_cum_shipped_qty IS NOT NULL
2611 OR x_cascaded_table(n).quantity_shipped IS NOT NULL
2612 OR x_cascaded_table(n).quantity_invoiced IS NOT NULL
2613 OR x_cascaded_table(n).secondary_quantity IS NOT NULL
2614 OR ( x_cascaded_table(n).job_id IS NOT NULL
2615 AND ( x_cascaded_table(n).value_basis = 'FIXED PRICE'
2616 AND x_cascaded_table(n).purchase_basis = 'SERVICES')) THEN --{
2617 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2618 rcv_error_pkg.set_error_message('RCV_IRRELEVANT_VALUES', x_cascaded_table(n).error_message);
2619 rcv_error_pkg.log_interface_error('MATCHING_BASIS', FALSE);
2620 END IF; --}
2621
2622 IF x_cascaded_table(n).error_status IN('S', 'W') THEN --{
2623 IF ( x_cascaded_table(n).value_basis = 'RATE'
2624 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR') THEN
2625 IF (g_asn_debug = 'Y') THEN
2626 asn_debug.put_line('RATE/TEMP LABOR. They can have the foll values. Hence return.');
2627 END IF;
2628
2629 RETURN;
2630 END IF;
2631
2632 IF ( x_cascaded_table(n).unit_of_measure IS NOT NULL
2633 OR x_cascaded_table(n).primary_unit_of_measure IS NOT NULL
2634 OR x_cascaded_table(n).secondary_unit_of_measure IS NOT NULL
2635 OR x_cascaded_table(n).source_doc_unit_of_measure IS NOT NULL
2636 OR x_cascaded_table(n).uom_code IS NOT NULL
2637 OR x_cascaded_table(n).secondary_uom_code IS NOT NULL
2638 OR x_cascaded_table(n).po_unit_price IS NOT NULL
2639 OR x_cascaded_table(n).timecard_id IS NOT NULL
2640 OR x_cascaded_table(n).timecard_ovn IS NOT NULL
2641 ) THEN --{
2642 IF (g_asn_debug = 'Y') THEN
2643 asn_debug.put_line('Not RATE/TEMP LABOR');
2644 END IF;
2645
2646 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2647 rcv_error_pkg.set_error_message('RCV_IRRELEVANT_VALUES', x_cascaded_table(n).error_message);
2648 rcv_error_pkg.log_interface_error('MATCHING_BASIS', FALSE);
2649 END IF; --}
2650 END IF; --}
2651 END IF; --}
2652
2653 IF (g_asn_debug = 'Y') THEN
2654 asn_debug.put_line('Leave validate_non_services_fields');
2655 END IF;
2656 EXCEPTION
2657 WHEN OTHERS THEN
2658 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2659 rcv_error_pkg.set_sql_error_message('derive_to_locator_id', '000');
2660 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2661 rcv_error_pkg.log_interface_error('MATCHING_BASIS', FALSE);
2662 END validate_non_services_fields;
2663
2664 /* We cannot default_from_subloc and default_to_subloc since
2665 * for deliver txn, we need from values but not to values.
2666 * Also for transfer these values are different. So it is
2667 * better to separate them out.
2668 */
2669 PROCEDURE default_from_subloc_info(
2670 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2671 n IN BINARY_INTEGER
2672 ) IS
2673 l_from_subinventory rcv_transactions.from_subinventory%TYPE;
2674 l_from_locator_id rcv_transactions.from_locator_id%TYPE;
2675 l_to_subinventory rcv_transactions.subinventory%TYPE;
2676 l_to_locator_id rcv_transactions.locator_id%TYPE;
2677 BEGIN
2678 IF (g_asn_debug = 'Y') THEN
2679 asn_debug.put_line('inside default_from_subloc_info');
2680 END IF;
2681
2682 /* If parent_interface_id is not null then it means it is a parent
2683 * child relation ship. So look in rti. If parent_transaction_id
2684 * is not null, then look in rcv_transactions.
2685 */
2686 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
2687 SELECT subinventory,
2688 locator_id,
2689 from_subinventory,
2690 from_locator_id
2691 INTO l_to_subinventory,
2692 l_to_locator_id,
2693 l_from_subinventory,
2694 l_from_locator_id
2695 FROM rcv_transactions_interface rti
2696 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
2697 ELSIF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
2698 SELECT subinventory,
2699 locator_id,
2700 from_subinventory,
2701 from_locator_id
2702 INTO l_to_subinventory,
2703 l_to_locator_id,
2704 l_from_subinventory,
2705 l_from_locator_id
2706 FROM rcv_transactions rt
2707 WHERE rt.transaction_id = x_cascaded_table(n).parent_transaction_id;
2708 END IF;
2709
2710 IF (g_asn_debug = 'Y') THEN
2711 asn_debug.put_line('l_to_subinventory ' || l_to_subinventory);
2712 asn_debug.put_line('l_to_locator_id ' || l_to_locator_id);
2713 asn_debug.put_line('l_from_subinventory, ' || l_from_subinventory);
2714 asn_debug.put_line('l_from_locator_id ' || l_from_locator_id);
2715 END IF;
2716
2717 /* For Accept, Reject and +ve corrections, from_subinventory and
2718 * from_locator is same as that of the parent. For RTV, this will come here only
2719 * when user has not specified from_subinventory.
2720 */
2721 /* Bug 3557343.
2722 * For Accept/Reject transactions, we want the from_sub/from_loc
2723 * to be the same as that of the parent's to_sub/to_loc since
2724 * we cannot change the sub/loc at the time of inspection. So
2725 * it will remain in the same sub/loc making both from and to
2726 * sub/loc the same as that of the parent.
2727 */
2728 IF ( x_cascaded_table(n).transaction_type = 'CORRECT'
2729 AND SIGN(x_cascaded_table(n).quantity) = 1) THEN
2730 x_cascaded_table(n).from_subinventory := l_from_subinventory;
2731 x_cascaded_table(n).from_locator_id := l_from_locator_id;
2732 ELSE /* For all other transaction types */
2733 x_cascaded_table(n).from_subinventory := l_to_subinventory;
2734 x_cascaded_table(n).from_locator_id := l_to_locator_id;
2735 END IF;
2736
2737 IF (g_asn_debug = 'Y') THEN
2738 asn_debug.put_line('x_cascaded_table(n).from_subinventory ' || x_cascaded_table(n).from_subinventory);
2739 asn_debug.put_line('x_cascaded_table(n).from_locator_id ' || x_cascaded_table(n).from_locator_id);
2740 END IF;
2741 EXCEPTION
2742 WHEN OTHERS THEN
2743 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2744 rcv_error_pkg.set_sql_error_message('default_from_subloc_info', '000');
2745 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2746 END default_from_subloc_info;
2747
2748 PROCEDURE default_to_subloc_info(
2749 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2750 n IN BINARY_INTEGER
2751 ) IS
2752 l_from_subinventory rcv_transactions.from_subinventory%TYPE;
2753 l_from_locator_id rcv_transactions.from_locator_id%TYPE;
2754 l_to_subinventory rcv_transactions.subinventory%TYPE;
2755 l_to_locator_id rcv_transactions.locator_id%TYPE;
2756 x_locator_control NUMBER;
2757 x_default_subinventory VARCHAR2(10);
2758 x_default_locator_id NUMBER;
2759 x_success BOOLEAN;
2760 BEGIN
2761 IF (g_asn_debug = 'Y') THEN
2762 asn_debug.put_line('inside default_to_subloc_info');
2763 END IF;
2764
2765 /* Get default subinventory from the setup if it is a direct delivery
2766 * or just a delivery and if subinventory is null.
2767 */
2768 IF (x_cascaded_table(n).transaction_type IN('RECEIVE', 'DELIVER')) THEN --{
2769 IF ( (x_cascaded_table(n).auto_transact_code <> 'RECEIVE')
2770 OR x_cascaded_table(n).auto_transact_code IS NULL) THEN --{
2771 /*
2772 ** A subinventory must have been defined on the po or a default
2773 ** must be available for the item. If it's not already defined
2774 ** then go get it out of inventory. If you're using express
2775 ** then it's ok to get the default rather than having it be
2776 ** defined on the record
2777 */
2778 IF (x_cascaded_table(n).subinventory IS NULL) THEN --{
2779 /*
2780 ** If you're using express then it's ok to get the default
2781 ** rather than having it be defined on the record
2782 */
2783 x_progress := '120';
2784 po_subinventories_s.get_default_subinventory(x_cascaded_table(n).to_organization_id,
2785 x_cascaded_table(n).item_id,
2786 x_cascaded_table(n).subinventory
2787 );
2788
2789 IF (g_asn_debug = 'Y') THEN
2790 asn_debug.put_line('Defaulting subinventory from item: Sub = ' || x_cascaded_table(n).subinventory);
2791 END IF;
2792 END IF; --} (X_cascaded_table(n).subinventory IS NULL)
2793 END IF; --}
2794
2795 /* We can have sub/loc for receive and deliver transaction. If subinventory
2796 * is not null and locator_id is null, then get the default locator_id if
2797 * the there is a locator.
2798 */
2799 IF (x_cascaded_table(n).subinventory IS NOT NULL) THEN --{
2800 x_progress := '122';
2801 po_subinventories_s.get_locator_control(x_cascaded_table(n).to_organization_id,
2802 x_cascaded_table(n).subinventory,
2803 x_cascaded_table(n).item_id,
2804 x_locator_control
2805 );
2806
2807 IF (g_asn_debug = 'Y') THEN
2808 asn_debug.put_line('Locator Control = ' || TO_CHAR(x_locator_control));
2809 END IF;
2810
2811 /*
2812 ** If locator control is 2 which means it is under predefined
2813 ** locator contol or 3 which means it's under dynamic (any value)
2814 ** locator control then you need to go get the default locator id
2815 */
2816 IF ( ( x_locator_control = 2
2817 OR x_locator_control = 3)
2818 AND x_cascaded_table(n).locator_id IS NULL) THEN --{
2819 x_progress := '123';
2820 po_subinventories_s.get_default_locator(x_cascaded_table(n).to_organization_id,
2821 x_cascaded_table(n).item_id,
2822 x_cascaded_table(n).subinventory,
2823 x_cascaded_table(n).locator_id
2824 );
2825
2826 IF (g_asn_debug = 'Y') THEN
2827 asn_debug.put_line('Defaulting locator from Sub: Locator_id = ' || TO_CHAR(x_cascaded_table(n).locator_id));
2828 END IF;
2829 END IF; --}
2830 END IF; --} matches subinventory not null
2831
2832 IF ( (x_cascaded_table(n).auto_transact_code <> 'RECEIVE')
2833 OR x_cascaded_table(n).auto_transact_code IS NULL) THEN --{
2834 x_default_subinventory := x_cascaded_table(n).subinventory;
2835 x_default_locator_id := x_cascaded_table(n).locator_id;
2836 /*
2837 ** Call the put away function
2838 */
2839 x_success := rcv_sub_locator_sv.put_away_api(x_cascaded_table(n).po_line_location_id,
2840 x_cascaded_table(n).po_distribution_id,
2841 x_cascaded_table(n).shipment_line_id,
2842 x_cascaded_table(n).receipt_source_code,
2843 x_cascaded_table(n).from_organization_id,
2844 x_cascaded_table(n).to_organization_id,
2845 x_cascaded_table(n).item_id,
2846 x_cascaded_table(n).item_revision,
2847 x_cascaded_table(n).vendor_id,
2848 x_cascaded_table(n).ship_to_location_id,
2849 x_cascaded_table(n).deliver_to_location_id,
2850 x_cascaded_table(n).deliver_to_person_id,
2851 x_cascaded_table(n).quantity,
2852 x_cascaded_table(n).primary_quantity,
2853 x_cascaded_table(n).primary_unit_of_measure,
2854 x_cascaded_table(n).quantity,
2855 x_cascaded_table(n).unit_of_measure,
2856 x_cascaded_table(n).routing_header_id,
2857 x_default_subinventory,
2858 x_default_locator_id,
2859 x_cascaded_table(n).subinventory,
2860 x_cascaded_table(n).locator_id
2861 );
2862 END IF; --}
2863
2864 /* If subinventory is still null, we need to disable dropship asn auto deliver if it has
2865 * been enabled and change the transaction back to ASN import*/
2866 IF ( (x_auto_deliver = 'Y') AND
2867 (x_cascaded_table(n).subinventory IS NULL)) THEN --{
2868
2869 IF (g_asn_debug = 'Y') THEN
2870 asn_debug.put_line('Warning: Changing the dropship ASN auto deliver back to ASN import.');
2871 asn_debug.put_line('Cause: Receiving preprocessor could not default a subinventory for this trxn.');
2872 END IF;
2873
2874 -- Change the transaction back to ASN import
2875 x_cascaded_table(n).transaction_type := 'SHIP';
2876 x_cascaded_table(n).auto_transact_code := 'SHIP';
2877 -- Reset the flag so that it won't affect the next transaction.
2878 x_auto_deliver := 'N';
2879 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
2880
2881 -- Log po_interface_errors
2882 rcv_error_pkg.set_error_message('RCV_ASN_AUTO_DEL_NO_SUBINV');
2883 rcv_error_pkg.log_interface_warning('SUBINVENTORY');
2884 END IF; --}
2885
2886 RETURN;
2887 END IF; --}
2888
2889 /* Bug 3568861.
2890 * We need to default the subinventory_code and locator_id
2891 * based on the transfer_lpn_id or lpn_id if they are not null
2892 * null based on the transactions. If they are null, then we
2893 * need to default from the parent. For +ve correct or
2894 * RTR, default using transfer_lpn_id. For -ve correct use lpn_id
2895 * to default sub/loc.
2896 */
2897 IF ( ( ( x_cascaded_table(n).transaction_type = 'CORRECT'
2898 AND SIGN(x_cascaded_table(n).quantity) = 1)
2899 OR (x_cascaded_table(n).transaction_type = 'RETURN TO RECEIVING'))
2900 AND (x_cascaded_table(n).transfer_lpn_id IS NOT NULL)) THEN
2901 IF (g_asn_debug = 'Y') THEN
2902 asn_debug.put_line('+Ve correct or RTR with transfer_lpn_id not null');
2903 END IF;
2904
2905 SELECT subinventory_code,
2906 locator_id
2907 INTO x_cascaded_table(n).subinventory,
2908 x_cascaded_table(n).locator_id
2909 FROM wms_license_plate_numbers
2910 WHERE lpn_id = x_cascaded_table(n).transfer_lpn_id;
2911
2912 IF (g_asn_debug = 'Y') THEN
2913 asn_debug.put_line('Sub is ' || x_cascaded_table(n).subinventory);
2914 asn_debug.put_line('Loc is ' || x_cascaded_table(n).locator_id);
2915 asn_debug.put_line('Return ');
2916 END IF;
2917
2918 RETURN;
2919 END IF;
2920
2921 IF ( ( x_cascaded_table(n).transaction_type = 'CORRECT'
2922 AND SIGN(x_cascaded_table(n).quantity) = -1)
2923 AND (x_cascaded_table(n).lpn_id IS NOT NULL)) THEN
2924 IF (g_asn_debug = 'Y') THEN
2925 asn_debug.put_line('-Ve correct with lpn_id not null');
2926 END IF;
2927
2928 SELECT subinventory_code,
2929 locator_id
2930 INTO x_cascaded_table(n).subinventory,
2931 x_cascaded_table(n).locator_id
2932 FROM wms_license_plate_numbers
2933 WHERE lpn_id = x_cascaded_table(n).lpn_id;
2934
2935 IF (g_asn_debug = 'Y') THEN
2936 asn_debug.put_line('Sub is ' || x_cascaded_table(n).subinventory);
2937 asn_debug.put_line('Loc is ' || x_cascaded_table(n).locator_id);
2938 asn_debug.put_line('Return ');
2939 END IF;
2940
2941 RETURN;
2942 END IF;
2943
2944 /* End of bug 3568861. */
2945
2946 /* If parent_interface_id is not null then it means it is a parent
2947 * child relation ship. So look in rti. If parent_transaction_id
2948 * is not null, then look in rcv_transactions.
2949 */
2950 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
2951 SELECT subinventory,
2952 locator_id,
2953 from_subinventory,
2954 from_locator_id
2955 INTO l_to_subinventory,
2956 l_to_locator_id,
2957 l_from_subinventory,
2958 l_from_locator_id
2959 FROM rcv_transactions_interface rti
2960 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
2961 ELSIF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
2962 SELECT subinventory,
2963 locator_id,
2964 from_subinventory,
2965 from_locator_id
2966 INTO l_to_subinventory,
2967 l_to_locator_id,
2968 l_from_subinventory,
2969 l_from_locator_id
2970 FROM rcv_transactions rt
2971 WHERE rt.transaction_id = x_cascaded_table(n).parent_transaction_id;
2972 END IF;
2973
2974 IF (g_asn_debug = 'Y') THEN
2975 asn_debug.put_line('l_to_subinventory ' || l_to_subinventory);
2976 asn_debug.put_line('l_to_locator_id ' || l_to_locator_id);
2977 asn_debug.put_line('l_from_subinventory, ' || l_from_subinventory);
2978 asn_debug.put_line('l_from_locator_id ' || l_from_locator_id);
2979 END IF;
2980
2981 /* For Accept, Reject and +ve corrections, to_subinventory and
2982 * to_locator is same as that of the parent.
2983 */
2984 IF ( (x_cascaded_table(n).transaction_type IN('ACCEPT', 'REJECT'))
2985 OR ( x_cascaded_table(n).transaction_type = 'CORRECT'
2986 AND SIGN(x_cascaded_table(n).quantity) = 1)) THEN
2987 x_cascaded_table(n).subinventory := l_to_subinventory;
2988 x_cascaded_table(n).locator_id := l_to_locator_id;
2989 ELSE /* For all other transaction types */
2990 x_cascaded_table(n).subinventory := l_from_subinventory;
2991 x_cascaded_table(n).locator_id := l_from_locator_id;
2992 END IF;
2993
2994 IF (g_asn_debug = 'Y') THEN
2995 asn_debug.put_line('x_cascaded_table(n).subinventory ' || x_cascaded_table(n).subinventory);
2996 asn_debug.put_line('x_cascaded_table(n).locator_id ' || x_cascaded_table(n).locator_id);
2997 END IF;
2998
2999 EXCEPTION
3000 WHEN OTHERS THEN
3001 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
3002 rcv_error_pkg.set_sql_error_message('default_to_subloc_info', '000');
3003 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
3004 END default_to_subloc_info;
3005
3006 /* WMS Change End */
3007 PROCEDURE derive_reason_info(
3008 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
3009 n IN OUT NOCOPY BINARY_INTEGER
3010 ) IS
3011 reason_id_record rcv_shipment_line_sv.reason_id_record_type;
3012 BEGIN
3013 IF (x_cascaded_table(n).error_status IN('S', 'W'))
3014 AND ( x_cascaded_table(n).reason_id IS NULL
3015 AND x_cascaded_table(n).reason_name IS NOT NULL) THEN
3016 IF (g_asn_debug = 'Y') THEN
3017 asn_debug.put_line('X_progress ' || x_progress);
3018 END IF;
3019
3020 reason_id_record.reason_name := x_cascaded_table(n).reason_name;
3021 reason_id_record.error_record.error_status := 'S';
3022 reason_id_record.error_record.error_message := NULL;
3023
3024 IF (g_asn_debug = 'Y') THEN
3025 asn_debug.put_line('Derive Reason_id');
3026 END IF;
3027
3028 rcv_transactions_interface_sv.get_reason_id(reason_id_record);
3029 x_cascaded_table(n).reason_id := reason_id_record.reason_id;
3030 x_cascaded_table(n).error_status := reason_id_record.error_record.error_status;
3031 x_cascaded_table(n).error_message := reason_id_record.error_record.error_message;
3032 END IF;
3033 END derive_reason_info;
3034
3035 PROCEDURE derive_auto_transact_code(
3036 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
3037 n IN OUT NOCOPY BINARY_INTEGER
3038 ) IS
3039 BEGIN
3040 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
3041 /* Moved dropship flag drivation here so that it's available
3042 * for use in all transaction types*/
3043 BEGIN
3044 SELECT drop_ship_flag
3045 INTO x_drop_ship_flag
3046 FROM po_line_locations_all
3047 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
3048 -- if no data found, do nothing
3049 EXCEPTION
3050 WHEN NO_DATA_FOUND THEN
3051 IF (g_asn_debug = 'Y') THEN
3052 asn_debug.put_line('No data found for dropship flag');
3053 END IF;
3054 END;
3055
3056 /* FPJ Services. If matching_basis is AMOUNT, then this is a service
3057 * type PO. We allow only direct delivery for these POs. Set
3058 * routing_header_id to 3 and set auto_transact_code = DELIVER and
3059 * return.
3060 */
3061 IF ( x_cascaded_table(n).transaction_type = 'RECEIVE'
3062 AND x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
3063 /* If auto_transact_code is not deliver, then give a warning
3064 * and default it to deliver.
3065 */
3066 IF (x_cascaded_table(n).auto_transact_code <> 'DELIVER') THEN --{
3067 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
3068 rcv_error_pkg.set_error_message('RCV_DIRECT_DEL_REQ', x_cascaded_table(n).error_message);
3069 rcv_error_pkg.log_interface_warning('DOCUMENT_NUM');
3070
3071 IF (g_asn_debug = 'Y') THEN
3072 asn_debug.put_line('AFter Warning insert into po_interface_errors ' || x_cascaded_table(n).error_message);
3073 END IF;
3074 END IF; --}
3075
3076 IF (g_asn_debug = 'Y') THEN
3077 asn_debug.put_line('Matching Basis is Amount:Setting RCV Routing to Direct Deliver');
3078 END IF;
3079
3080 x_cascaded_table(n).routing_header_id := 3;
3081 x_cascaded_table(n).auto_transact_code := 'DELIVER';
3082 RETURN;
3083 END IF;
3084
3085 /* FPJ SERVICES END. */
3086 IF x_cascaded_table(n).transaction_type = 'SHIP' THEN
3087 /* For ASNs from a drop shipment order, set receving routing to
3088 * Direct Deliver, and if the profile option "PO: Automatically
3089 * Deliver Drop Ship ASNs" is set to Y, set auto_transact_code
3090 * to 'DELIVER'
3091 *
3092 * FPJ International Drop Shipment project - pjiang
3093 */
3094 IF x_drop_ship_flag = 'Y' THEN
3095 IF (g_asn_debug = 'Y') THEN
3096 asn_debug.put_line('Dropship: Setting RCV Routing to Direct Deliver');
3097 END IF;
3098
3099 x_cascaded_table(n).routing_header_id := 3;
3100 fnd_profile.get('PO_AUTO_DELIVER_DROPSHIP_ASN', x_auto_deliver);
3101
3102 IF x_auto_deliver = 'Y' THEN
3103 IF (g_asn_debug = 'Y') THEN
3104 asn_debug.put_line('Dropship: Auto deliver feature enabled, ' || 'set auto_transact_code to DELIVER for drop ship ASNs');
3105 END IF;
3106
3107 x_cascaded_table(n).auto_transact_code := 'DELIVER';
3108 END IF; -- end auto deliver
3109 END IF; -- end drop_ship_flag = 'Y' (external dropship)
3110 END IF; -- end transaction_type = 'SHIP' (ASN)
3111
3112 IF ( x_cascaded_table(n).auto_transact_code IS NULL
3113 AND x_cascaded_table(n).transaction_type IN('SHIP', 'RECEIVE')) THEN
3114 IF (g_asn_debug = 'Y') THEN
3115 asn_debug.put_line('X_progress ' || x_progress);
3116 asn_debug.put_line('Setting auto_transact_code to transaction_type ' || x_cascaded_table(n).transaction_type);
3117 END IF;
3118
3119 x_cascaded_table(n).auto_transact_code := x_cascaded_table(n).transaction_type;
3120 END IF;
3121 END IF;
3122
3123 x_progress := '093';
3124
3125 -- Change transaction type based on combination of
3126 -- transaction_type and auto_transact_code
3127
3128 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
3129 IF (g_asn_debug = 'Y') THEN
3130 asn_debug.put_line('X_progress ' || x_progress);
3131 END IF;
3132
3133 IF x_cascaded_table(n).transaction_type = 'SHIP'
3134 AND x_cascaded_table(n).auto_transact_code = 'DELIVER' THEN
3135 IF (g_asn_debug = 'Y') THEN
3136 asn_debug.put_line('Changing the transaction_type to RECEIVE FROM SHIP');
3137 END IF;
3138
3139 x_cascaded_table(n).transaction_type := 'RECEIVE';
3140 END IF;
3141 END IF;
3142 END derive_auto_transact_code;
3143
3144 PROCEDURE derive_vendor_rcv_line_qty(
3145 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
3146 n IN OUT NOCOPY BINARY_INTEGER,
3147 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
3148 x_header_record IN rcv_roi_preprocessor.header_rec_type
3149 ) IS
3150 x_include_closed_po VARCHAR2(1); -- Bug 1887728
3151
3152 /* R12 Complex Work.
3153 * Use line_location_id instead of shipment_num since it
3154 * is not unique for a line_id in the case of complex work POs.
3155 * If user has given a PO shipment number through ROI, then
3156 * defaulting package would have derived the line_location_id.
3157 * Changed cursor shipments and count_shipments.
3158 */
3159 CURSOR shipments(
3160 header_id NUMBER,
3161 v_item_id NUMBER,
3162 v_po_line_num NUMBER,
3163 v_po_release_id NUMBER,
3164 v_line_location_id NUMBER,
3165 v_ship_to_org_id NUMBER,
3166 v_ship_to_location_id NUMBER,
3167 v_vendor_product_num VARCHAR2
3168 ) IS
3169 SELECT pll.line_location_id,
3170 pll.unit_meas_lookup_code,
3171 pll.unit_of_measure_class,
3172 NVL(pll.promised_date, pll.need_by_date) promised_date,
3173 pll.ship_to_organization_id,
3174 pll.quantity quantity_ordered,
3175 pll.quantity_shipped,
3176 pll.receipt_days_exception_code,
3177 pll.qty_rcv_tolerance,
3178 pll.qty_rcv_exception_code,
3179 pll.days_early_receipt_allowed,
3180 pll.days_late_receipt_allowed,
3181 NVL(pll.price_override, pl.unit_price) unit_price,
3182 pll.match_option, -- 1845702
3183 pl.category_id,
3184 nvl(pll.description,pl.item_description) item_description,--Complex work
3185 pl.po_line_id,
3186 ph.currency_code,
3187 ph.rate_type, -- 1845702
3188 0 po_distribution_id,
3189 0 code_combination_id,
3190 0 req_distribution_id,
3191 0 deliver_to_location_id,
3192 0 deliver_to_person_id,
3193 ph.rate_date rate_date, --1845702
3194 ph.rate rate, --1845702
3195 '' destination_type_code,
3196 0 destination_organization_id,
3197 '' destination_subinventory,
3198 0 wip_entity_id,
3199 0 wip_operation_seq_num,
3200 0 wip_resource_seq_num,
3201 0 wip_repetitive_schedule_id,
3202 0 wip_line_id,
3203 0 bom_resource_id,
3204 0 project_id, /* Bug 14725305 */
3205 0 task_id, /* Bug 14725305 */
3206 '' ussgl_transaction_code,
3207 pll.ship_to_location_id,
3208 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
3209 TO_NUMBER(NULL) shipment_line_id, --shipment_line_id
3210 pl.item_id
3211 FROM po_line_locations pll,
3212 po_lines pl,
3213 po_headers ph
3214 WHERE ph.po_header_id = header_id
3215 AND pll.po_header_id = header_id
3216 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
3217 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
3218 AND pll.line_location_id = NVL(v_line_location_id, pll.line_location_id) --Bug: 5357628
3219 AND pll.po_line_id = pl.po_line_id
3220 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
3221 AND NVL(pll.approved_flag, 'N') = 'Y'
3222 AND NVL(pll.cancel_flag, 'N') = 'N'
3223 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
3224 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
3225 OR ( NVL(x_include_closed_po, 'N') = 'N'
3226 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
3227 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
3228 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
3229 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
3230 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'))
3231 ORDER BY NVL(pll.promised_date, Nvl(pll.need_by_date,pll.creation_date)), Nvl(pll.need_by_date,pll.creation_date), pll.creation_date; --bug10022180
3232
3233 CURSOR count_shipments(
3234 header_id NUMBER,
3235 v_item_id NUMBER,
3236 v_po_line_num NUMBER,
3237 v_po_release_id NUMBER,
3238 v_line_location_id NUMBER,
3239 v_ship_to_org_id NUMBER,
3240 v_ship_to_location_id NUMBER,
3241 v_vendor_product_num VARCHAR2
3242 ) IS
3243 SELECT COUNT(*)
3244 FROM po_line_locations pll,
3245 po_lines pl,
3246 po_headers ph
3247 WHERE ph.po_header_id = header_id
3248 AND pll.po_header_id = header_id
3249 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
3250 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
3251 AND pll.line_location_id = NVL(v_line_location_id, pll.line_location_id) --Bug: 5357628
3252 AND pll.po_line_id = pl.po_line_id
3253 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
3254 AND NVL(pll.approved_flag, 'N') = 'Y'
3255 AND NVL(pll.cancel_flag, 'N') = 'N'
3256 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
3257 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
3258 OR ( NVL(x_include_closed_po, 'N') = 'N'
3259 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
3260 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
3261 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
3262 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
3263 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'));
3264
3265 /***** Bug # 1553154
3266 ***** There was a performance issue since the cursor COUNT_DISTRIBUTIONS
3267 ***** was driving through PO_LINE_LOCATIONS_ALL. Modified the Select
3268 ***** statement so that it will drive through PO_HEADERS_ALL
3269 ***** followed by PO_LINES_ALL which is followed by PO_LINE_LOCATIONS_ALL
3270 ***** so that there is an improvement in performance.
3271 *****/
3272 CURSOR distributions(
3273 header_id NUMBER,
3274 v_item_id NUMBER,
3275 v_po_line_num NUMBER,
3276 v_po_release_id NUMBER,
3277 v_shipment_num NUMBER,
3278 v_distribution_num NUMBER,
3279 v_ship_to_org_id NUMBER,
3280 v_ship_to_location_id NUMBER,
3281 v_vendor_product_num VARCHAR2
3282 ) IS
3283 SELECT pll.line_location_id,
3284 pll.unit_meas_lookup_code,
3285 pll.unit_of_measure_class,
3286 NVL(pll.promised_date, pll.need_by_date) promised_date,
3287 pll.ship_to_organization_id,
3288 pll.quantity quantity_ordered,
3289 pll.quantity_shipped,
3290 pll.receipt_days_exception_code,
3291 pll.qty_rcv_tolerance,
3292 pll.qty_rcv_exception_code,
3293 pll.days_early_receipt_allowed,
3294 pll.days_late_receipt_allowed,
3295 NVL(pll.price_override, pl.unit_price) unit_price,
3296 pll.match_option, -- 1845702
3297 pl.category_id,
3298 nvl(pll.description,pl.item_description) item_description,--Complex work
3299 pl.po_line_id,
3300 ph.currency_code,
3301 ph.rate_type, -- 1845702
3302 pod.po_distribution_id,
3303 pod.code_combination_id,
3304 pod.req_distribution_id,
3305 pod.deliver_to_location_id,
3306 pod.deliver_to_person_id,
3307 pod.rate_date,
3308 pod.rate,
3309 pod.destination_type_code,
3310 pod.destination_organization_id,
3311 pod.destination_subinventory,
3312 pod.wip_entity_id,
3313 pod.wip_operation_seq_num,
3314 pod.wip_resource_seq_num,
3315 pod.wip_repetitive_schedule_id,
3316 pod.wip_line_id,
3317 pod.bom_resource_id,
3318 pod.project_id, /* Bug 14725305 */
3319 pod.task_id, /* Bug 14725305 */
3320 pod.ussgl_transaction_code,
3321 pll.ship_to_location_id,
3322 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
3323 TO_NUMBER(NULL) shipment_line_id, -- shipment_line_id
3324 pl.item_id
3325 FROM po_distributions pod,
3326 po_line_locations pll,
3327 po_lines pl,
3328 po_headers ph
3329 WHERE ph.po_header_id = header_id
3330 AND pl.po_header_id = ph.po_header_id
3331 AND pll.po_line_id = pl.po_line_id
3332 AND pod.line_location_id = pll.line_location_id
3333 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
3334 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
3335 AND pll.shipment_num = NVL(v_shipment_num, pll.shipment_num)
3336 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
3337 AND NVL(pll.approved_flag, 'N') = 'Y'
3338 AND NVL(pll.cancel_flag, 'N') = 'N'
3339 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
3340 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
3341 OR ( NVL(x_include_closed_po, 'N') = 'N'
3342 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
3343 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
3344 AND pod.distribution_num = NVL(v_distribution_num, pod.distribution_num)
3345 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
3346 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
3347 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'))
3348 ORDER BY NVL(pll.promised_date, Nvl(pll.need_by_date,pll.creation_date)), Nvl(pll.need_by_date,pll.creation_date), pll.creation_date; --bug10022180
3349
3350 /***** Bug # 1553154
3351 ***** There was a performance issue since the cursor DISTRIBUTIONS
3352 ***** was driving through PO_HEADERS_ALL followed by PO_DISTRIBUTIONS_ALL
3353 ***** Modified the Select statement so that it will drive through
3354 ***** PO_HEADERS_ALL followed by PO_LINES_ALL which is followed by
3355 ***** PO_LINE_LOCATIONS_ALL which in turn is followed by
3356 ***** PO_DISTRIBUTIONS_ALL so that there is an improvement in
3357 ***** Performance
3358 *****/
3359 CURSOR count_distributions(
3360 header_id NUMBER,
3361 v_item_id NUMBER,
3362 v_po_line_num NUMBER,
3363 v_po_release_id NUMBER,
3364 v_shipment_num NUMBER,
3365 v_distribution_num NUMBER,
3366 v_ship_to_org_id NUMBER,
3367 v_ship_to_location_id NUMBER,
3368 v_vendor_product_num VARCHAR2
3369 ) IS
3370 SELECT COUNT(*)
3371 FROM po_distributions pod,
3372 po_line_locations pll,
3373 po_lines pl,
3374 po_headers ph
3375 WHERE ph.po_header_id = header_id
3376 AND pl.po_header_id = ph.po_header_id
3377 AND pll.po_line_id = pl.po_line_id
3378 AND pod.line_location_id = pll.line_location_id
3379 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
3380 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
3381 AND pll.shipment_num = NVL(v_shipment_num, pll.shipment_num)
3382 AND pod.distribution_num = NVL(v_distribution_num, pod.distribution_num)
3383 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
3384 AND NVL(pll.approved_flag, 'N') = 'Y'
3385 AND NVL(pll.cancel_flag, 'N') = 'N'
3386 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
3387 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
3388 OR ( NVL(x_include_closed_po, 'N') = 'N'
3389 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
3390 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
3391 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
3392 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
3393 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'));
3394
3395 /*
3396 ** Debug: had to change this to the distribution record
3397 ** Might be a compatibility issue between the two record definitions
3398 */
3399 x_shipmentdistributionrec distributions%ROWTYPE;
3400 x_record_count NUMBER;
3401 x_remaining_quantity NUMBER := 0;
3402 x_remaining_qty_po_uom NUMBER := 0;
3403 x_bkp_qty NUMBER := 0;
3404 x_progress VARCHAR2(3);
3405 x_to_organization_code VARCHAR2(5);
3406 x_converted_trx_qty NUMBER := 0;
3407 transaction_ok BOOLEAN := FALSE;
3408 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
3409 high_range_date DATE;
3410 low_range_date DATE;
3411 rows_fetched NUMBER := 0;
3412 x_tolerable_qty NUMBER := 0;
3413 x_first_trans BOOLEAN := TRUE;
3414 x_sysdate DATE := SYSDATE;
3415 current_n BINARY_INTEGER := 0;
3416 insert_into_table BOOLEAN := FALSE;
3417 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
3418 tax_amount_factor NUMBER;
3419 lastrecord BOOLEAN := FALSE;
3420 po_asn_uom_qty NUMBER;
3421 po_primary_uom_qty NUMBER;
3422 already_allocated_qty NUMBER := 0;
3423 x_item_id NUMBER;
3424 x_approved_flag VARCHAR(1);
3425 x_cancel_flag VARCHAR(1);
3426 x_closed_code VARCHAR(25);
3427 x_shipment_type VARCHAR(25);
3428 x_ship_to_organization_id NUMBER;
3429 x_ship_to_location_id NUMBER;
3430 /* temp_ship_to_location_id number;
3431 temp_mirror_ship_to_loc_id number ;
3432 temp_enf_ship_to_loc_code varchar(25) ; */
3433 /* The above 3 variables added for bug 1898283 */
3434 x_vendor_product_num VARCHAR(25);
3435 x_temp_count NUMBER;
3436 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
3437 /* 1887728 -Added the following variables */
3438 profile_user_id NUMBER := -1;
3439 profile_appl_id NUMBER := -1;
3440 profile_resp_id NUMBER := -1;
3441 defined BOOLEAN;
3442 /* 1845702 */
3443 x_sob_id NUMBER := NULL;
3444 x_rate NUMBER;
3445 x_allow_rate_override VARCHAR2(1);
3446 /* Bug# 1548597 */
3447 x_secondary_available_qty NUMBER := 0;
3448 l_receipt_source_code rcv_shipment_headers.receipt_source_code%TYPE;
3449 l_shipment_line_status_code rcv_shipment_lines.shipment_line_status_code%TYPE;
3450 l_asn_line_flag rcv_shipment_lines.asn_line_flag%TYPE;
3451 l_asn_exists_code rcv_parameters.receipt_asn_exists_code%TYPE;
3452 l_does_asn_exist VARCHAR2(1) := 'N';
3453 l_asn_count NUMBER := 0;
3454 l_dist_count number; /* Bug#3746516 */
3455 l_rate_date po_headers.rate_date%type; /* Bug#3746516 */
3456 x_is_asn BOOLEAN;
3457 l_return_status VARCHAR2(1) :='S';
3458 l_complex_flag varchar2(1) := 'N';
3459 l_blind_receiving_flag VARCHAR2(1) := 'N'; -- Bug 6796920
3460 x_po_header_id number; /* Bug 9169143: LSP Changes */
3461 l_client_code VARCHAR(40); /* Bug 9169143: LSP Changes */
3462
3463 -- <Bug 9342280 : Added for CLM project>
3464 l_is_clm_po VARCHAR2(5) := 'N';
3465 l_partial_funded_flag VARCHAR2(5) := 'N';
3466 -- <CLM END>
3467
3468 BEGIN
3469 --check line quanity > 0
3470 x_progress := '097';
3471 profile_user_id := fnd_profile.VALUE('USER_ID');
3472 profile_resp_id := fnd_profile.VALUE('RESPONSIBILITY_ID');
3473 profile_appl_id := fnd_profile.VALUE('APPLICATION_ID');
3474 fnd_profile.get_specific('RCV_CLOSED_PO_DEFAULT_OPTION',
3475 profile_user_id,
3476 profile_resp_id,
3477 profile_appl_id,
3478 x_include_closed_po,
3479 defined
3480 );
3481
3482 IF (g_asn_debug = 'Y') THEN
3483 asn_debug.put_line('Include closed PO profile value ' || x_include_closed_po);
3484 END IF;
3485
3486 IF (g_asn_debug = 'Y') THEN
3487 asn_debug.put_line('X_progress ' || x_progress);
3488 END IF;
3489
3490 IF x_cascaded_table(n).error_status IN('S', 'W')
3491 AND x_cascaded_table(n).quantity <= 0 THEN --{
3492 IF (g_asn_debug = 'Y') THEN
3493 asn_debug.put_line('Quantity is <= zero. Cascade will fail');
3494 END IF;
3495
3496 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3497 rcv_error_pkg.set_error_message('RCV_ITEM_NO_SHIP_QTY', x_cascaded_table(n).error_message);
3498 rcv_error_pkg.set_token('ITEM', x_cascaded_table(n).item_num);
3499 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
3500 END IF; --} end qty > 0 check
3501
3502 -- the following steps will create a set of rows linking the line_record with
3503 -- its corresponding po_line_location rows until the quantity value from
3504 -- the asn is consumed. (Cascade)
3505
3506 /* 2119137 : If the user populates rcv_transactions_interface
3507 with po_line_id, then ROI errors out with
3508 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
3509 is not provided for one time items. Modified the "if" criteria in
3510 such a way that the ROI validation does'nt error out when
3511 po_line_id is populated for one time items. */
3512 x_progress := '098';
3513
3514 IF (g_asn_debug = 'Y') THEN
3515 asn_debug.put_line('X_progress ' || x_progress);
3516 END IF;
3517
3518 IF ( ( x_cascaded_table(n).po_header_id IS NOT NULL
3519 AND ( x_cascaded_table(n).item_id IS NOT NULL
3520 OR x_cascaded_table(n).vendor_item_num IS NOT NULL
3521 OR x_cascaded_table(n).po_line_id IS NOT NULL
3522 OR x_cascaded_table(n).document_line_num IS NOT NULL))
3523 OR (x_cascaded_table(n).shipment_header_id IS NOT NULL AND x_cascaded_table(n).shipment_line_id IS NOT NULL)
3524 AND x_cascaded_table(n).error_status IN('S', 'W')
3525 ) THEN --{
3526
3527 -- Copy record from main table to temp table
3528 IF (g_asn_debug = 'Y') THEN
3529 asn_debug.put_line('Copy record from main table to temp table');
3530 END IF;
3531
3532 current_n := 1;
3533 temp_cascaded_table(current_n) := x_cascaded_table(n);
3534
3535 IF (x_cascaded_table(n).shipment_header_id IS NOT NULL AND x_cascaded_table(n).shipment_line_id IS NOT NULL) THEN
3536 x_is_asn := TRUE;
3537 ELSE
3538 x_is_asn := FALSE;
3539 END IF;
3540
3541 -- Get all rows which meet this condition
3542 IF (g_asn_debug = 'Y') THEN
3543 asn_debug.put_line('Get all rows which meet this condition');
3544 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
3545 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
3546
3547 IF (x_is_asn = TRUE) THEN
3548 asn_debug.put_line('This is a Receive against an ASN');
3549 ELSE
3550 asn_debug.put_line('This is a Receive against a PO');
3551 END IF;
3552 END IF;
3553
3554 -- bug 1362237 Deriving the document_line_num
3555 -- and document_shipment_line_num when line_id and/or line_location_id
3556 -- are provided.
3557
3558 IF temp_cascaded_table(current_n).document_line_num IS NULL
3559 AND temp_cascaded_table(current_n).po_line_id IS NOT NULL THEN --{
3560 BEGIN
3561 SELECT line_num
3562 INTO temp_cascaded_table(current_n).document_line_num
3563 FROM po_lines
3564 WHERE po_line_id = temp_cascaded_table(current_n).po_line_id;
3565 EXCEPTION
3566 WHEN OTHERS THEN
3567 IF (g_asn_debug = 'Y') THEN
3568 asn_debug.put_line('wrong po_line_id entered in rcv_transactions_interface');
3569 END IF;
3570 END;
3571 END IF; --}
3572
3573 IF temp_cascaded_table(current_n).document_shipment_line_num IS NULL
3574 AND temp_cascaded_table(current_n).po_line_location_id IS NOT NULL THEN --{
3575 BEGIN
3576 SELECT shipment_num
3577 INTO temp_cascaded_table(current_n).document_shipment_line_num
3578 FROM po_line_locations
3579 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
3580 EXCEPTION
3581 WHEN OTHERS THEN
3582 IF (g_asn_debug = 'Y') THEN
3583 asn_debug.put_line('wrong po_line_location_id entered in rcv_transactions_interface');
3584 END IF;
3585 END;
3586 END IF; --}
3587
3588 IF temp_cascaded_table(current_n).document_distribution_num IS NULL
3589 AND temp_cascaded_table(current_n).po_distribution_id IS NOT NULL THEN --{
3590 BEGIN
3591 SELECT distribution_num
3592 INTO temp_cascaded_table(current_n).document_distribution_num
3593 FROM po_distributions
3594 WHERE po_distribution_id = temp_cascaded_table(current_n).po_distribution_id;
3595 EXCEPTION
3596 WHEN OTHERS THEN
3597 IF (g_asn_debug = 'Y') THEN
3598 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
3599 END IF;
3600 END;
3601 END IF; --}
3602
3603 /* Bug 1898283 : The Receiving control of "Enforce Ship to Location was
3604 not working for ROI. So corrected the code so that it now behaves the same way as
3605 the Form Behaves. i.e.,
3606 Proceed without any error messages if the enforcement is set to "None"
3607 Enter error message in po_interface_errors if the enforcement is "Warning"
3608 Enter error message in po_interface_errors if the enforcement is "Reject"
3609 and error out.
3610 This validation is done by comparing the enforce_ship_location_code from
3611 po_line_locations and assigning the proper ship_location_id into a
3612 temporary variable temp_mirror_ship_to_loc_id and passing the temp
3613 variable as a parameter to open the cursor "Distributions".
3614 */
3615 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3616 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3617
3618 -- if txn != deliver
3619 IF (g_asn_debug = 'Y') THEN
3620 asn_debug.put_line('Open Shipment records');
3621 asn_debug.put_line('Shipment Header Id if this is an ASN receive ' || TO_CHAR(temp_cascaded_table(current_n).shipment_header_id));
3622 asn_debug.put_line('PO Header id ' || TO_CHAR(temp_cascaded_table(current_n).po_header_id));
3623 asn_debug.put_line('Item Id ' || TO_CHAR(temp_cascaded_table(current_n).item_id));
3624 asn_debug.put_line('PO Line Num ' || TO_CHAR(temp_cascaded_table(current_n).document_line_num));
3625 asn_debug.put_line('PO Release Id ' || TO_CHAR(temp_cascaded_table(current_n).po_release_id));
3626 asn_debug.put_line('Shipment Line num ' || TO_CHAR(temp_cascaded_table(current_n).document_shipment_line_num));
3627 asn_debug.put_line('Document distribution num ' || TO_CHAR(temp_cascaded_table(current_n).document_distribution_num));
3628 asn_debug.put_line('Ship To Organization ID ' || TO_CHAR(temp_cascaded_table(current_n).to_organization_id));
3629 asn_debug.put_line('Ship To Location Id ' || TO_CHAR(NVL(temp_cascaded_table(current_n).ship_to_location_id, x_header_record.header_record.location_id)));
3630 asn_debug.put_line('Vendor Item Num ' || temp_cascaded_table(current_n).vendor_item_num);
3631 asn_debug.put_line('Proceed to open cursor');
3632 END IF;
3633
3634 /* Bug 2208664 : Nullified the ship_to_location_id when calling
3635 the cursors shipments, count_shipments, distributions and
3636 count_distributions. The proper value of ship_to_location_id will
3637 be set after values are fetched and validated for the
3638 location control code set at PO.
3639 */
3640 /* IF (x_is_asn = TRUE) THEN --{ */
3641 /* Forward port for Bug 4523892 , the use of x_is_asn is commented to make it consistent
3642 with the previous code line
3643 */
3644 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3645 IF (g_asn_debug = 'Y') THEN
3646 asn_debug.put_line('Open ASN Shipment records');
3647 asn_debug.put_line('shipment_header_id ' || temp_cascaded_table(current_n).shipment_header_id);
3648 asn_debug.put_line('shipment_line_id ' || temp_cascaded_table(current_n).shipment_line_id);
3649 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3650 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3651 asn_debug.put_line('document_num ' || temp_cascaded_table(current_n).document_line_num);
3652 asn_debug.put_line('document_shipment_line_num ' || temp_cascaded_table(current_n).document_shipment_line_num);
3653 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3654 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3655 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3656 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3657 END IF;
3658
3659 OPEN asn_shipments(temp_cascaded_table(current_n).shipment_header_id,
3660 temp_cascaded_table(current_n).shipment_line_id,
3661 temp_cascaded_table(current_n).po_header_id,
3662 temp_cascaded_table(current_n).item_id,
3663 temp_cascaded_table(current_n).document_line_num,
3664 temp_cascaded_table(current_n).document_shipment_line_num,
3665 temp_cascaded_table(current_n).po_release_id,
3666 temp_cascaded_table(current_n).to_organization_id,
3667 NULL, -- ship_to_location_id
3668 temp_cascaded_table(current_n).vendor_item_num,
3669 x_include_closed_po
3670 );
3671
3672 -- count_shipments just gets the count of rows found in shipments
3673 IF (g_asn_debug = 'Y') THEN
3674 asn_debug.put_line('After Open ASN Shipment records');
3675 END IF;
3676
3677 OPEN count_asn_shipments(temp_cascaded_table(current_n).shipment_header_id,
3678 temp_cascaded_table(current_n).shipment_line_id,
3679 temp_cascaded_table(current_n).po_header_id,
3680 temp_cascaded_table(current_n).item_id,
3681 temp_cascaded_table(current_n).document_line_num,
3682 temp_cascaded_table(current_n).document_shipment_line_num,
3683 temp_cascaded_table(current_n).po_release_id,
3684 temp_cascaded_table(current_n).to_organization_id,
3685 NULL, -- ship_to_location_id
3686 temp_cascaded_table(current_n).vendor_item_num,
3687 x_include_closed_po
3688 );
3689
3690 IF (g_asn_debug = 'Y') THEN
3691 asn_debug.put_line('After Open Count ASN Shipment records');
3692 END IF;
3693 ELSE --}{
3694 IF (g_asn_debug = 'Y') THEN
3695 asn_debug.put_line('Open PO Shipment records');
3696 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3697 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3698 asn_debug.put_line('document_line_num ' || temp_cascaded_table(current_n).document_line_num);
3699 asn_debug.put_line('line_location_id ' || temp_cascaded_table(current_n).po_line_location_id);
3700 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3701 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3702 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3703 END IF;
3704
3705 OPEN shipments(temp_cascaded_table(current_n).po_header_id,
3706 temp_cascaded_table(current_n).item_id,
3707 temp_cascaded_table(current_n).document_line_num,
3708 temp_cascaded_table(current_n).po_release_id,
3709 temp_cascaded_table(current_n).po_line_location_id,
3710 temp_cascaded_table(current_n).to_organization_id,
3711 NULL, -- ship_to_location_id
3712 temp_cascaded_table(current_n).vendor_item_num
3713 );
3714 -- count_shipments just gets the count of rows found in shipments
3715
3716 OPEN count_shipments(temp_cascaded_table(current_n).po_header_id,
3717 temp_cascaded_table(current_n).item_id,
3718 temp_cascaded_table(current_n).document_line_num,
3719 temp_cascaded_table(current_n).po_release_id,
3720 temp_cascaded_table(current_n).po_line_location_id,
3721 temp_cascaded_table(current_n).to_organization_id,
3722 NULL, -- ship_to_location_id
3723 temp_cascaded_table(current_n).vendor_item_num
3724 );
3725 END IF; --}
3726
3727 IF (g_asn_debug = 'Y') THEN
3728 asn_debug.put_line('After opening relavant records for Receive');
3729 END IF;
3730 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
3731 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --}{
3732 IF (g_asn_debug = 'Y') THEN
3733 asn_debug.put_line('Open Distribution records');
3734 asn_debug.put_line('Ship Header id ' || TO_CHAR(temp_cascaded_table(current_n).shipment_header_id));
3735 asn_debug.put_line('PO Header id ' || TO_CHAR(temp_cascaded_table(current_n).po_header_id));
3736 asn_debug.put_line('Item Id ' || TO_CHAR(temp_cascaded_table(current_n).item_id));
3737 asn_debug.put_line('PO Line Num ' || TO_CHAR(temp_cascaded_table(current_n).document_line_num));
3738 asn_debug.put_line('PO Release Id ' || TO_CHAR(temp_cascaded_table(current_n).po_release_id));
3739 asn_debug.put_line('Shipment Line num ' || TO_CHAR(temp_cascaded_table(current_n).document_shipment_line_num));
3740 asn_debug.put_line('Distribution num ' || TO_CHAR(temp_cascaded_table(current_n).document_distribution_num));
3741 asn_debug.put_line('Ship To Organization ID ' || TO_CHAR(temp_cascaded_table(current_n).to_organization_id));
3742 asn_debug.put_line('Ship To Location Id ' || TO_CHAR(NVL(temp_cascaded_table(current_n).ship_to_location_id, x_header_record.header_record.location_id)));
3743 asn_debug.put_line('Vendor Item Num ' || temp_cascaded_table(current_n).vendor_item_num);
3744 asn_debug.put_line('Proceed to open cursor');
3745 END IF;
3746
3747 /* IF (x_is_asn = TRUE) THEN --{ This call is replaced by forward port of 4523892 */
3748 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3749 IF (g_asn_debug = 'Y') THEN
3750 asn_debug.put_line('Open ASN Distribution records');
3751 asn_debug.put_line('shipment_header_id ' || temp_cascaded_table(current_n).shipment_header_id);
3752 asn_debug.put_line('shipment_line_id ' || temp_cascaded_table(current_n).shipment_line_id);
3753 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3754 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3755 asn_debug.put_line('document_num ' || temp_cascaded_table(current_n).document_line_num);
3756 asn_debug.put_line('document_shipment_line_num ' || temp_cascaded_table(current_n).document_shipment_line_num);
3757 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3758 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3759 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3760 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3761 END IF;
3762
3763 OPEN asn_distributions(temp_cascaded_table(current_n).shipment_header_id,
3764 temp_cascaded_table(current_n).shipment_line_id,
3765 temp_cascaded_table(current_n).po_header_id,
3766 temp_cascaded_table(current_n).item_id,
3767 temp_cascaded_table(current_n).document_line_num,
3768 temp_cascaded_table(current_n).document_shipment_line_num,
3769 temp_cascaded_table(current_n).document_distribution_num,
3770 temp_cascaded_table(current_n).po_release_id,
3771 temp_cascaded_table(current_n).to_organization_id,
3772 NULL, -- ship_to_location_id
3773 temp_cascaded_table(current_n).vendor_item_num,
3774 x_include_closed_po
3775 );
3776
3777 IF (g_asn_debug = 'Y') THEN
3778 asn_debug.put_line('After Open ASN distribution records');
3779 END IF;
3780
3781 OPEN count_asn_distributions(temp_cascaded_table(current_n).shipment_header_id,
3782 temp_cascaded_table(current_n).shipment_line_id,
3783 temp_cascaded_table(current_n).po_header_id,
3784 temp_cascaded_table(current_n).item_id,
3785 temp_cascaded_table(current_n).document_line_num,
3786 temp_cascaded_table(current_n).document_shipment_line_num,
3787 temp_cascaded_table(current_n).document_distribution_num,
3788 temp_cascaded_table(current_n).po_release_id,
3789 temp_cascaded_table(current_n).to_organization_id,
3790 NULL, -- ship_to_location_id
3791 temp_cascaded_table(current_n).vendor_item_num,
3792 x_include_closed_po
3793 );
3794
3795 IF (g_asn_debug = 'Y') THEN
3796 asn_debug.put_line('After Open count ASN distribution records');
3797 END IF;
3798 ELSE --}{
3799 IF (g_asn_debug = 'Y') THEN
3800 asn_debug.put_line('Open PO Distribution records');
3801 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3802 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3803 asn_debug.put_line('document_num ' || temp_cascaded_table(current_n).document_line_num);
3804 asn_debug.put_line('document_shipment_line_num ' || temp_cascaded_table(current_n).document_shipment_line_num);
3805 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3806 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3807 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3808 END IF;
3809
3810 OPEN distributions(temp_cascaded_table(current_n).po_header_id,
3811 temp_cascaded_table(current_n).item_id,
3812 temp_cascaded_table(current_n).document_line_num,
3813 temp_cascaded_table(current_n).po_release_id,
3814 temp_cascaded_table(current_n).document_shipment_line_num,
3815 temp_cascaded_table(current_n).document_distribution_num,
3816 temp_cascaded_table(current_n).to_organization_id,
3817 NULL, -- ship_to_location_id
3818 temp_cascaded_table(current_n).vendor_item_num
3819 );
3820 -- count_distributions just gets the count of rows found in distributions
3821
3822 OPEN count_distributions(temp_cascaded_table(current_n).po_header_id,
3823 temp_cascaded_table(current_n).item_id,
3824 temp_cascaded_table(current_n).document_line_num,
3825 temp_cascaded_table(current_n).po_release_id,
3826 temp_cascaded_table(current_n).document_shipment_line_num,
3827 temp_cascaded_table(current_n).document_distribution_num,
3828 temp_cascaded_table(current_n).to_organization_id,
3829 NULL, -- ship_to_location_id
3830 temp_cascaded_table(current_n).vendor_item_num
3831 );
3832 END IF; --}
3833
3834 IF (g_asn_debug = 'Y') THEN
3835 asn_debug.put_line('After opening relavant records for Direct delivery');
3836 END IF;
3837 END IF; -- for txn = deliver --}
3838
3839
3840 -- Assign shipped quantity to remaining quantity
3841
3842 IF (g_asn_debug = 'Y') THEN
3843 asn_debug.put_line('Assign shipped quantity to remaining quantity');
3844 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
3845 END IF;
3846
3847 x_remaining_quantity := temp_cascaded_table(current_n).quantity;
3848 x_bkp_qty := x_remaining_quantity; -- used for decrementing cum qty for first record
3849 x_remaining_qty_po_uom := 0;
3850
3851 IF (g_asn_debug = 'Y') THEN
3852 asn_debug.put_line('Have assigned the quantity');
3853 END IF;
3854
3855 -- Calculate tax_amount_factor for calculating tax_amount for
3856 -- each cascaded line
3857
3858 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
3859 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_quantity;
3860 ELSE
3861 tax_amount_factor := 0;
3862 END IF;
3863
3864 IF (g_asn_debug = 'Y') THEN
3865 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
3866 asn_debug.put_line('Shipped Quantity : ' || TO_CHAR(x_remaining_quantity));
3867 END IF;
3868
3869 x_first_trans := TRUE;
3870 transaction_ok := FALSE;
3871
3872 /*
3873 ** Get the count of the number of records depending on the
3874 ** the transaction type
3875 */
3876 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3877 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3878 /* IF (x_is_asn = TRUE) THEN --{ This is replaced by forward port for bug 4523892 */
3879 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3880 IF (g_asn_debug = 'Y') THEN
3881 asn_debug.put_line('Count of asn shipments');
3882 END IF;
3883
3884 FETCH count_asn_shipments INTO x_record_count;
3885 ELSE --}{
3886 IF (g_asn_debug = 'Y') THEN
3887 asn_debug.put_line('Count of PO shipments');
3888 END IF;
3889
3890 FETCH count_shipments INTO x_record_count;
3891 END IF; --}
3892 ELSE --}{
3893 /* IF (x_is_asn = TRUE) THEN --{ This is replaced by forward port for Bug 4523892 */
3894 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3895 IF (g_asn_debug = 'Y') THEN
3896 asn_debug.put_line('Count of asn distributions');
3897 END IF;
3898
3899 FETCH count_asn_distributions INTO x_record_count;
3900 ELSE --}{
3901 IF (g_asn_debug = 'Y') THEN
3902 asn_debug.put_line('Count of PO distributions');
3903 END IF;
3904
3905 FETCH count_distributions INTO x_record_count;
3906 END IF; --}
3907 END IF; --}
3908
3909 IF (g_asn_debug = 'Y') THEN
3910 asn_debug.put_line('Before starting Cascade');
3911 END IF;
3912
3913 IF (g_asn_debug = 'Y') THEN
3914 asn_debug.put_line('Record Count = ' || x_record_count);
3915 END IF;
3916
3917 LOOP --{
3918 IF (g_asn_debug = 'Y') THEN
3919 asn_debug.put_line('Backup Qty ' || TO_CHAR(x_bkp_qty));
3920 asn_debug.put_line('Remaining Quantity ASN UOM ' || TO_CHAR(x_remaining_quantity));
3921 END IF;
3922
3923 IF (g_asn_debug = 'Y') THEN
3924 asn_debug.put_line('open shipments and fetch');
3925 END IF;
3926
3927 /*
3928 ** Fetch the appropriate record
3929 */
3930 IF (g_asn_debug = 'Y') THEN
3931 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
3932 END IF;
3933
3934 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3935 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3936 IF (g_asn_debug = 'Y') THEN
3937 asn_debug.put_line('Fetching Shipments Cursor');
3938 END IF;
3939
3940 IF (shipments%ISOPEN) THEN
3941 FETCH shipments INTO x_shipmentdistributionrec;
3942
3943 IF (shipments%NOTFOUND) THEN
3944 lastrecord := TRUE;
3945 END IF;
3946
3947 rows_fetched := shipments%ROWCOUNT;
3948 ELSIF(asn_shipments%ISOPEN) THEN
3949 FETCH asn_shipments INTO x_shipmentdistributionrec;
3950
3951 IF (asn_shipments%NOTFOUND) THEN
3952 lastrecord := TRUE;
3953 END IF;
3954
3955 rows_fetched := asn_shipments%ROWCOUNT;
3956 END IF;
3957
3958 /*
3959 ** Check if this is the last record
3960 */
3961 IF (g_asn_debug = 'Y') THEN
3962 asn_debug.put_line('Shipment Rows fetched ' || TO_CHAR(rows_fetched));
3963 END IF;
3964 -- }
3965 ELSE -- txn = deliver and other cases --{
3966 IF (g_asn_debug = 'Y') THEN
3967 asn_debug.put_line('Fetching Distributions Cursor');
3968 END IF;
3969
3970 IF (distributions%ISOPEN) THEN
3971 FETCH distributions INTO x_shipmentdistributionrec;
3972
3973 IF (distributions%NOTFOUND) THEN
3974 lastrecord := TRUE;
3975 END IF;
3976
3977 rows_fetched := distributions%ROWCOUNT;
3978 ELSIF(asn_distributions%ISOPEN) THEN
3979 FETCH asn_distributions INTO x_shipmentdistributionrec;
3980
3981 IF (asn_distributions%NOTFOUND) THEN
3982 lastrecord := TRUE;
3983 END IF;
3984
3985 rows_fetched := asn_distributions%ROWCOUNT;
3986 END IF;
3987
3988 /*
3989 ** Check if this is the last record
3990 */
3991 IF (g_asn_debug = 'Y') THEN
3992 asn_debug.put_line('Distribution Rows fetched ' || TO_CHAR(rows_fetched));
3993 END IF;
3994 END IF; -- matches if condition of txn ! deliver --}
3995
3996 IF ( lastrecord
3997 OR x_remaining_quantity <= 0) THEN --{
3998 IF (g_asn_debug = 'Y') THEN
3999 asn_debug.put_line('Hit exit condition');
4000 END IF;
4001
4002 IF NOT x_first_trans THEN
4003 -- x_first_trans has been reset which means some cascade has
4004 -- happened. Otherwise current_n = 1
4005 current_n := current_n - 1;
4006 END IF;
4007
4008 -- do the tolerance act here
4009 IF (g_asn_debug = 'Y') THEN
4010 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
4011 asn_debug.put_line('Check which condition has occured');
4012 END IF;
4013
4014 -- lastrecord...we have run out of rows and we still have quantity to allocate
4015 IF (round(x_remaining_quantity,6) > 0) THEN --{ Bug 13703497
4016 IF (g_asn_debug = 'Y') THEN
4017 asn_debug.put_line('There is quantity remaining');
4018 asn_debug.put_line('Need to check qty tolerances');
4019 END IF;
4020
4021 IF rows_fetched > 0
4022 AND NOT x_first_trans THEN --{
4023 -- we had got atleast some rows from our shipments cursor
4024 -- we have atleast one row cascaded (not null line_location_id)
4025 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
4026 INTO x_qty_rcv_exception_code
4027 FROM po_line_locations
4028 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
4029
4030 IF (g_asn_debug = 'Y') THEN
4031 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
4032 asn_debug.put_line('quantity ' || temp_cascaded_table(current_n).quantity);
4033 asn_debug.put_line('x_converted_trx_qty ' || x_converted_trx_qty);
4034 END IF;
4035
4036 -- Bug 6796920 Start
4037 BEGIN
4038 select blind_receiving_flag
4039 into l_blind_receiving_flag
4040 from rcv_parameters
4041 where organization_id = temp_cascaded_table(current_n).to_organization_id;
4042 EXCEPTION
4043 when others THEN
4044 NULL;
4045 END;
4046
4047 IF (g_asn_debug = 'Y') THEN
4048 asn_debug.put_line('Current Organization id = '|| temp_cascaded_table(current_n).to_organization_id);
4049 asn_debug.put_line('Blind Receiving Flag = '|| l_blind_receiving_flag);
4050 END IF;
4051 -- Bug 6796920 End
4052
4053 -- The following if condition is commented out as part of bug 6796920
4054 -- IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
4055 /* Bug# 1807842 */
4056 /* Bug 3506964.
4057 * This is the forward fix for 3222672. Before the
4058 * foll condition used to have <. We had changed
4059 * it to <= as part of our ROI rewrite. But since
4060 * quantity can never be greater than
4061 * x_converted_trx_qty, this is equivalent to removing
4062 * the whole condition. So commenting this out.
4063 IF (
4064 temp_cascaded_table(current_n).quantity <=
4065 x_converted_trx_qty
4066 ) THEN --{
4067 */
4068 IF (g_asn_debug = 'Y') THEN
4069 asn_debug.put_line('Tolerable quantity ' || TO_CHAR(x_converted_trx_qty));
4070 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
4071 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
4072 asn_debug.put_line('Assign remaining ASN UOM qty ' || TO_CHAR(x_remaining_quantity) || ' to last record');
4073 asn_debug.put_line('Assign remaining PO UOM qty ' || TO_CHAR(x_remaining_qty_po_uom) || ' to last record');
4074 END IF;
4075 /* Bug 4907269.
4076 x_remaining_quantity is the unused transaction qty, it has to be rounded to 6 decimals
4077 so that quantity and primary quantity will computed correctly rounded to 6 decimals.
4078 */
4079
4080 x_remaining_quantity := round(x_remaining_quantity,6);
4081
4082 temp_cascaded_table(current_n).quantity := temp_cascaded_table(current_n).quantity + x_remaining_quantity;
4083 temp_cascaded_table(current_n).quantity_shipped := temp_cascaded_table(current_n).quantity_shipped + x_remaining_quantity;
4084 temp_cascaded_table(current_n).source_doc_quantity := temp_cascaded_table(current_n).source_doc_quantity + x_remaining_qty_po_uom;
4085 temp_cascaded_table(current_n).primary_quantity := temp_cascaded_table(current_n).primary_quantity
4086 + rcv_transactions_interface_sv.convert_into_correct_qty(x_remaining_quantity,
4087 temp_cascaded_table(1).unit_of_measure,
4088 temp_cascaded_table(1).item_id,
4089 temp_cascaded_table(1).primary_unit_of_measure
4090 );
4091
4092 IF (g_asn_debug = 'Y') THEN
4093 asn_debug.put_line('primary_qty for the last row ' || temp_cascaded_table(current_n).primary_quantity);
4094 asn_debug.put_line('quantity for the last row ' || temp_cascaded_table(current_n).quantity);
4095 END IF;
4096
4097 /* Bug 3506964.
4098 END IF; Bug# 1807842 --}
4099 */
4100
4101 -- Vendor Cum Qty
4102
4103 IF NVL(temp_cascaded_table(current_n).vendor_cum_shipped_qty, 0) <> 0 THEN
4104 temp_cascaded_table(current_n).vendor_cum_shipped_qty := temp_cascaded_table(current_n).vendor_cum_shipped_qty + temp_cascaded_table(current_n).primary_quantity;
4105 END IF;
4106
4107 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).quantity * tax_amount_factor, 6);
4108
4109 IF (g_asn_debug = 'Y') THEN
4110 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
4111 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
4112 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
4113 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
4114 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
4115 END IF;
4116
4117 -- <Bug 9342280 : Added for CLM project>
4118 get_clm_info( 'QUANTITY',
4119 x_cascaded_table,
4120 n,
4121 l_is_clm_po,
4122 l_partial_funded_flag);
4123
4124 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
4125
4126 x_qty_rcv_exception_code := 'REJECT';
4127
4128 END IF;
4129 --<END CLM>
4130
4131 -- Bug 6796920 - Modified the following if condition to check for blind receiving flag
4132 IF (x_qty_rcv_exception_code = 'WARNING' AND NVL(l_blind_receiving_flag,'N') <> 'Y') THEN --{
4133 IF (g_asn_debug = 'Y') THEN
4134 asn_debug.put_line('IN WARNING');
4135 END IF;
4136
4137 IF (g_asn_debug = 'Y') THEN
4138 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
4139 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
4140 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
4141 END IF;
4142
4143 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
4144 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
4145 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
4146 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
4147 rcv_error_pkg.log_interface_warning('QUANTITY');
4148
4149 IF (g_asn_debug = 'Y') THEN
4150 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
4151 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
4152 asn_debug.put_line('Need to insert into po_interface_errors');
4153 END IF;
4154 -- Commented out the following END IF as part of bug 6796920
4155 -- END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
4156
4157 IF (g_asn_debug = 'Y') THEN
4158 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
4159 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
4160 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
4161 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
4162 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
4163 END IF;
4164 -- }
4165 -- ELSIF x_qty_rcv_exception_code = 'REJECT' THEN -- elseif for NONE/WARNING --{
4166 -- Bug 6796920 - Modified the following elsif condition to check for blind receiving flag
4167
4168 ELSIF (x_qty_rcv_exception_code = 'REJECT' AND NVL(l_blind_receiving_flag,'N') <> 'Y') THEN
4169
4170 IF (g_asn_debug = 'Y') THEN
4171 asn_debug.put_line('Extra ASN UOM Quantity ' || TO_CHAR(x_remaining_quantity));
4172 asn_debug.put_line('Extra PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
4173 END IF;
4174
4175 IF (g_asn_debug = 'Y') THEN
4176 asn_debug.put_line('delete the temp table ');
4177 END IF;
4178
4179 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4180
4181 -- <Bug 9342280 : Added for CLM project>
4182 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
4183
4184 rcv_error_pkg.set_error_message(
4185 'RCV_TRX_QTY_EXCEEDS_CLM_FUNDED',
4186 x_cascaded_table(n).error_message);
4187 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(n).quantity);
4188 rcv_error_pkg.set_token('QTY_B', x_cascaded_table(n).quantity - x_remaining_quantity);
4189
4190 ELSE
4191 -- <CLM END>
4192 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
4193 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(n).quantity);
4194 rcv_error_pkg.set_token('QTY_B', x_cascaded_table(n).quantity - x_remaining_quantity);
4195
4196 END IF; -- <Bug 9342280 : Added for CLM project>
4197
4198 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
4199
4200 IF temp_cascaded_table.COUNT > 0 THEN
4201 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
4202 temp_cascaded_table.DELETE(i);
4203 END LOOP;
4204 END IF;
4205
4206 IF (g_asn_debug = 'Y') THEN
4207 asn_debug.put_line('mark the actual table with error status');
4208 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
4209 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
4210 END IF;
4211
4212 IF (g_asn_debug = 'Y') THEN
4213 asn_debug.put_line('Need to insert a row into po_interface_errors');
4214 END IF;
4215 END IF; --} matches if(none/warning) and elseif(reject)
4216 --}
4217 ELSE --{ else for rows fetched = 0 OR x_first_trans = true
4218 IF rows_fetched = 0 THEN
4219 IF (g_asn_debug = 'Y') THEN
4220 asn_debug.put_line('No rows were retrieved from cursor.');
4221 END IF;
4222 ELSIF x_first_trans THEN
4223 IF (g_asn_debug = 'Y') THEN
4224 asn_debug.put_line('No rows were cascaded');
4225 END IF;
4226 END IF;
4227
4228 x_temp_count := 1;
4229
4230 /* nwang add error messages */
4231 /* Bug 2340533 - Added a message RCV_ASN_NO_OPEN_SHIPMENTS which conveys that
4232 no shipments exists for receiving for the given PO.
4233 */
4234 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
4235 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
4236 -- Bug 2551443 Removed po_distributions from the FROM clause
4237 IF (g_asn_debug = 'Y') THEN
4238 asn_debug.put_line('This is receive');
4239 END IF;
4240
4241 IF (x_is_asn = FALSE) THEN --{
4242 SELECT COUNT(*)
4243 INTO x_temp_count
4244 FROM po_line_locations pll,
4245 po_lines pl,
4246 po_headers ph
4247 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
4248 AND pll.po_header_id = ph.po_header_id
4249 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
4250 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
4251 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
4252 AND pll.po_line_id = pl.po_line_id;
4253 END IF; --}
4254
4255 IF (g_asn_debug = 'Y') THEN
4256 asn_debug.put_line('x_temp_count ' || x_temp_count);
4257 END IF;
4258
4259 IF x_temp_count = 0 THEN --{
4260 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4261 rcv_error_pkg.set_error_message('RCV_ASN_NO_OPEN_SHIPMENTS', x_cascaded_table(n).error_message);
4262 rcv_error_pkg.set_token('PONUM', temp_cascaded_table(current_n).document_num);
4263 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
4264 ELSE -- x_item_count != 0 --}{
4265 IF (x_is_asn = FALSE) THEN --{
4266 IF (g_asn_debug = 'Y') THEN
4267 asn_debug.put_line('Get the flag values');
4268 END IF;
4269
4270 SELECT NVL(pl.item_id, 0),
4271 NVL(pll.approved_flag, 'N'),
4272 NVL(pll.cancel_flag, 'N'),
4273 NVL(pll.closed_code, 'OPEN'),
4274 pll.shipment_type,
4275 pll.ship_to_organization_id,
4276 pll.ship_to_location_id,
4277 NVL(pl.vendor_product_num, '-999')
4278 INTO x_item_id,
4279 x_approved_flag,
4280 x_cancel_flag,
4281 x_closed_code,
4282 x_shipment_type,
4283 x_ship_to_organization_id,
4284 x_ship_to_location_id,
4285 x_vendor_product_num
4286 FROM po_line_locations pll,
4287 po_lines pl,
4288 po_headers ph
4289 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
4290 AND pll.po_header_id = ph.po_header_id
4291 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
4292 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
4293 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
4294 AND pll.po_line_id = pl.po_line_id;
4295
4296 IF (g_asn_debug = 'Y') THEN
4297 asn_debug.put_line('x_item_id ' || x_item_id);
4298 asn_debug.put_line('x_approved_flag ' || x_approved_flag);
4299 asn_debug.put_line('x_cancel_flag ' || x_cancel_flag);
4300 asn_debug.put_line('x_closed_code ' || x_closed_code);
4301 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
4302 asn_debug.put_line('x_shipment_type ' || x_shipment_type);
4303 asn_debug.put_line('x_ship_to_organization_id ' || x_ship_to_organization_id);
4304 asn_debug.put_line('x_ship_to_location_id ' || x_ship_to_location_id);
4305 asn_debug.put_line('x_vendor_product_num ' || x_vendor_product_num);
4306 END IF;
4307 END IF; --}
4308 END IF; --} -- x_temp_count = 0
4309 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
4310 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --}{
4311 IF (g_asn_debug = 'Y') THEN
4312 asn_debug.put_line('This is deliver');
4313 END IF;
4314
4315 IF (x_is_asn = FALSE) THEN --{
4316 SELECT COUNT(*)
4317 INTO x_temp_count
4318 FROM po_distributions pod,
4319 po_line_locations pll,
4320 po_lines pl,
4321 po_headers ph
4322 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
4323 AND pll.po_header_id = ph.po_header_id
4324 AND pll.line_location_id = pod.line_location_id
4325 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
4326 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
4327 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
4328 AND pll.po_line_id = pl.po_line_id
4329 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
4330 END IF; --}
4331
4332 IF (g_asn_debug = 'Y') THEN
4333 asn_debug.put_line('x_temp_count ' || x_temp_count);
4334 END IF;
4335
4336 IF x_temp_count = 0 THEN --{
4337 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4338 rcv_error_pkg.set_error_message('RCV_ASN_INVALID_DIST_NUM', x_cascaded_table(n).error_message);
4339 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_distribution_num);
4340 rcv_error_pkg.log_interface_error('DOCUMENT_DISTRIBUTION_NUM', FALSE);
4341 ELSE -- x_temp_count != 0 --}{
4342 IF (x_is_asn = FALSE) THEN --{
4343 IF (g_asn_debug = 'Y') THEN
4344 asn_debug.put_line('Get flag values ');
4345 END IF;
4346
4347 SELECT NVL(pl.item_id, 0),
4348 NVL(pll.approved_flag, 'N'),
4349 NVL(pll.cancel_flag, 'N'),
4350 NVL(pll.closed_code, 'OPEN'),
4351 pll.shipment_type,
4352 pll.ship_to_organization_id,
4353 pll.ship_to_location_id,
4354 NVL(pl.vendor_product_num, '-999')
4355 INTO x_item_id,
4356 x_approved_flag,
4357 x_cancel_flag,
4358 x_closed_code,
4359 x_shipment_type,
4360 x_ship_to_organization_id,
4361 x_ship_to_location_id,
4362 x_vendor_product_num
4363 FROM po_distributions pod,
4364 po_line_locations pll,
4365 po_lines pl,
4366 po_headers ph
4367 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
4368 AND pll.po_header_id = ph.po_header_id
4369 AND pll.line_location_id = pod.line_location_id
4370 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
4371 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
4372 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
4373 AND pll.po_line_id = pl.po_line_id
4374 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
4375
4376 IF (g_asn_debug = 'Y') THEN
4377 asn_debug.put_line('x_item_id ' || x_item_id);
4378 asn_debug.put_line('x_approved_flag ' || x_approved_flag);
4379 asn_debug.put_line('x_cancel_flag ' || x_cancel_flag);
4380 asn_debug.put_line('x_closed_code ' || x_closed_code);
4381 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
4382 asn_debug.put_line('x_shipment_type ' || x_shipment_type);
4383 asn_debug.put_line('x_ship_to_organization_id ' || x_ship_to_organization_id);
4384 asn_debug.put_line('x_ship_to_location_id ' || x_ship_to_location_id);
4385 asn_debug.put_line('x_vendor_product_num ' || x_vendor_product_num);
4386 END IF;
4387 END IF; --}
4388 END IF; -- x_temp_count = 0; --}
4389 END IF; -- transaction_type <> 'DELIVER' --}
4390
4391 IF (x_is_asn = TRUE) THEN --{
4392 IF (g_asn_debug = 'Y') THEN
4393 asn_debug.put_line('Shipment header_id not null ');
4394 END IF;
4395
4396 SELECT NVL(rsl.item_id, 0),
4397 NVL(pll.approved_flag, 'N'),
4398 NVL(pll.cancel_flag, 'N'),
4399 NVL(pll.closed_code, 'OPEN'),
4400 pll.shipment_type,
4401 rsl.to_organization_id,
4402 rsl.ship_to_location_id,
4403 NVL(pl.vendor_product_num, '-999'),
4404 rsh.receipt_source_code,
4405 rsl.shipment_line_status_code,
4406 NVL(rsl.asn_line_flag, 'N')
4407 INTO x_item_id,
4408 x_approved_flag,
4409 x_cancel_flag,
4410 x_closed_code,
4411 x_shipment_type,
4412 x_ship_to_organization_id,
4413 x_ship_to_location_id,
4414 x_vendor_product_num,
4415 l_receipt_source_code,
4416 l_shipment_line_status_code,
4417 l_asn_line_flag
4418 FROM po_line_locations pll,
4419 po_lines pl,
4420 po_headers ph,
4421 rcv_shipment_headers rsh,
4422 rcv_shipment_lines rsl
4423 WHERE rsh.shipment_header_id = temp_cascaded_table(current_n).shipment_header_id
4424 AND rsl.shipment_line_id = temp_cascaded_table(current_n).shipment_line_id
4425 AND rsl.po_header_id = temp_cascaded_table(current_n).po_header_id
4426 AND rsl.po_line_id = temp_cascaded_table(current_n).po_line_id
4427 AND rsl.po_line_location_id = temp_cascaded_table(current_n).po_line_location_id
4428 AND rsl.po_line_id = pl.po_line_id
4429 AND rsl.po_line_location_id = pll.line_location_id
4430 AND ph.po_header_id = rsl.po_header_id
4431 AND rsh.shipment_header_id = rsl.shipment_header_id
4432 AND pll.po_header_id = ph.po_header_id
4433 AND pl.po_line_id = temp_cascaded_table(current_n).po_line_id
4434 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id,0)
4435 AND pll.line_location_id = temp_cascaded_table(current_n).po_line_location_id
4436 AND pll.po_line_id = pl.po_line_id;
4437
4438 IF (g_asn_debug = 'Y') THEN
4439 asn_debug.put_line('x_item_id ' || x_item_id);
4440 asn_debug.put_line('x_approved_flag ' || x_approved_flag);
4441 asn_debug.put_line('x_cancel_flag ' || x_cancel_flag);
4442 asn_debug.put_line('x_closed_code ' || x_closed_code);
4443 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
4444 asn_debug.put_line('x_shipment_type ' || x_shipment_type);
4445 asn_debug.put_line('x_ship_to_organization_id ' || x_ship_to_organization_id);
4446 asn_debug.put_line('x_ship_to_location_id ' || x_ship_to_location_id);
4447 asn_debug.put_line('x_vendor_product_num ' || x_vendor_product_num);
4448 asn_debug.put_line('l_receipt_source_code ' || l_receipt_source_code);
4449 asn_debug.put_line('l_shipment_line_status_code ' || l_shipment_line_status_code);
4450 asn_debug.put_line('l_asn_line_flag ' || l_asn_line_flag);
4451 END IF;
4452 END IF; --}
4453
4454 IF (x_temp_count <> 0) THEN --{
4455 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4456
4457 IF (g_asn_debug = 'Y') THEN
4458 asn_debug.put_line('Should give us the exact error ');
4459 END IF;
4460
4461 IF x_item_id <> NVL(temp_cascaded_table(current_n).item_id, x_item_id) THEN
4462 IF (g_asn_debug = 'Y') THEN
4463 asn_debug.put_line('This item is not allowed ');
4464 END IF;
4465
4466 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4467 rcv_error_pkg.set_error_message('RCV_ASN_ITEM_NOT_ALLOWED', x_cascaded_table(n).error_message);
4468 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).item_num);
4469 rcv_error_pkg.log_interface_error('ITEM_NUM', FALSE);
4470 END IF;
4471
4472 IF x_approved_flag <> 'Y' THEN
4473 IF (g_asn_debug = 'Y') THEN
4474 asn_debug.put_line('This PO is not approved');
4475 END IF;
4476
4477 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4478 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_APPROVED', x_cascaded_table(n).error_message);
4479 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4480 rcv_error_pkg.set_token('PO_NUM', temp_cascaded_table(current_n).document_num);
4481 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4482 END IF;
4483
4484 IF x_cancel_flag <> 'N' THEN
4485 IF (g_asn_debug = 'Y') THEN
4486 asn_debug.put_line('This PO is cancelled');
4487 END IF;
4488
4489 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4490 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_CANCELLED', x_cascaded_table(n).error_message);
4491 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4492 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4493 END IF;
4494
4495 /* Bug 3548556.
4496 * We used to record the error only when it
4497 * is finally closed. But this is an error only
4498 * the include closed PO option is Yes. If it is
4499 * Yes, then we need to error out when closed_code
4500 * is FINALLY CLOSED, CLOSED FOR RECEIVING OR
4501 * CLOSED. So changed the foll code to include
4502 * the condition x_include_closed_po and
4503 * added the if condition below to look for
4504 * the other closed codes when include closed
4505 * po profile option is set to No.
4506 */
4507 IF ( NVL(x_include_closed_po, 'N') = 'Y'
4508 AND x_closed_code = 'FINALLY CLOSED') THEN
4509 IF (g_asn_debug = 'Y') THEN
4510 asn_debug.put_line('This PO is finally closed and the profile option to include closed POs is Y');
4511 END IF;
4512
4513 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4514 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_FINALLY_CLOSED', x_cascaded_table(n).error_message); --Bug 10020071
4515 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4516 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4517 END IF;
4518
4519 IF ( NVL(x_include_closed_po, 'N') = 'N'
4520 AND x_closed_code IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING')) THEN
4521 IF (g_asn_debug = 'Y') THEN
4522 asn_debug.put_line('This PO is not open and the profile option to include closed POs is N');
4523 END IF;
4524
4525 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4526 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_OPEN', x_cascaded_table(n).error_message);
4527 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4528 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4529 END IF;
4530
4531 IF x_shipment_type NOT IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT') THEN
4532 IF (g_asn_debug = 'Y') THEN
4533 asn_debug.put_line('This PO shipment type cannot be received');
4534 END IF;
4535
4536 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4537 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIPMT_TYPE', x_cascaded_table(n).error_message);
4538 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4539 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4540 END IF;
4541
4542 IF x_ship_to_organization_id <> NVL(temp_cascaded_table(current_n).to_organization_id, x_ship_to_organization_id) THEN
4543 IF (g_asn_debug = 'Y') THEN
4544 asn_debug.put_line('Ship_to_org in PO does not match the user entered value');
4545 END IF;
4546
4547 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4548 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_ORG', x_cascaded_table(n).error_message);
4549 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).to_organization_code);
4550 rcv_error_pkg.log_interface_error('TO_ORGANIZATION_CODE', FALSE);
4551 END IF;
4552
4553 IF x_ship_to_location_id <> NVL(NVL(temp_cascaded_table(current_n).ship_to_location_id, x_header_record.header_record.location_id), x_ship_to_location_id) THEN
4554 IF (g_asn_debug = 'Y') THEN
4555 asn_debug.put_line('Ship_to_loc in PO does not match the user entered value');
4556 END IF;
4557
4558 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4559 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
4560 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_code);
4561 rcv_error_pkg.log_interface_error('SHIP_TO_LOCATION_CODE', FALSE);
4562 END IF;
4563
4564 IF x_vendor_product_num <> NVL(temp_cascaded_table(current_n).vendor_item_num, x_vendor_product_num) THEN
4565 IF (g_asn_debug = 'Y') THEN
4566 asn_debug.put_line('Vendor_prod_num in PO does not match the user entered value');
4567 END IF;
4568
4569 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4570 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_VENDOR_PROD_NUM', x_cascaded_table(n).error_message);
4571 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).vendor_item_num);
4572 rcv_error_pkg.log_interface_error('VENDOR_ITEM_NUM', FALSE);
4573 END IF;
4574
4575 IF (g_asn_debug = 'Y') THEN
4576 asn_debug.put_line('Should have give us the exact error ');
4577 END IF;
4578
4579 /* IF (x_is_asn = TRUE) THEN --{ This is replaced by forward port for Bug 4523892 */
4580 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
4581 /* Error messages specific to asns. */
4582 IF (g_asn_debug = 'Y') THEN
4583 asn_debug.put_line('Error messages specific to asn');
4584 END IF;
4585
4586 IF l_receipt_source_code <> 'VENDOR' THEN
4587 IF (g_asn_debug = 'Y') THEN
4588 asn_debug.put_line('Receipt source code not VENDOR');
4589 END IF;
4590
4591 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4592 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_RECEIPT_SRC_CODE', x_cascaded_table(n).error_message); -- Bug 7593902
4593 rcv_error_pkg.set_token('RECEIPT_SRC_CODE', l_receipt_source_code); -- Bug 7593902
4594 rcv_error_pkg.log_interface_error('SHIPMENT_NUMBER', FALSE);
4595 END IF;
4596
4597 IF ( l_shipment_line_status_code = 'FULLY RECEIVED'
4598 OR l_asn_line_flag <> 'Y') THEN
4599 IF (g_asn_debug = 'Y') THEN
4600 asn_debug.put_line('ASN line flag is not Y and status code is Fully closed');
4601 END IF;
4602
4603 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4604 rcv_error_pkg.set_error_message('RCV_ASN_NO_EXPECTED_RECEIPTS', x_cascaded_table(n).error_message);
4605 rcv_error_pkg.log_interface_error('SHIPMENT_NUMBER', FALSE);
4606 END IF;
4607
4608 IF (g_asn_debug = 'Y') THEN
4609 asn_debug.put_line('Should have give us the exact error for ASN ');
4610 END IF;
4611 END IF; --}
4612 END IF; -- x_temp_count = 0;}
4613
4614 -- Delete the temp_cascaded_table just to be sure
4615
4616 IF temp_cascaded_table.COUNT > 0 THEN
4617 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
4618 temp_cascaded_table.DELETE(i);
4619 END LOOP;
4620 END IF;
4621 END IF; --} end else for rows fetched = 0 OR x_first_trans = true
4622 -- end x_remaining_qty > 0 => this is the last record
4623 ELSE --
4624 -- Bug 13703497
4625 x_remaining_quantity := 0;
4626 x_remaining_qty_po_uom := 0;
4627
4628 IF (g_asn_debug = 'Y') THEN
4629 asn_debug.put_line('Remaining ASN UOM quantity is zero ' || TO_CHAR(x_remaining_quantity));
4630 asn_debug.put_line('Remaining PO UOM quantity is zero ' || TO_CHAR(x_remaining_qty_po_uom));
4631 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
4632 END IF;
4633 END IF; --} ends the check for whether last record has been reached
4634
4635 -- close cursors
4636
4637 IF (g_asn_debug = 'Y') THEN
4638 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions');
4639 END IF;
4640
4641 IF shipments%ISOPEN THEN
4642 CLOSE shipments;
4643 END IF;
4644
4645 IF count_shipments%ISOPEN THEN
4646 CLOSE count_shipments;
4647 END IF;
4648
4649 IF distributions%ISOPEN THEN
4650 CLOSE distributions;
4651 END IF;
4652
4653 IF count_distributions%ISOPEN THEN
4654 CLOSE count_distributions;
4655 END IF;
4656
4657 IF asn_shipments%ISOPEN THEN
4658 CLOSE asn_shipments;
4659 END IF;
4660
4661 IF count_asn_shipments%ISOPEN THEN
4662 CLOSE count_asn_shipments;
4663 END IF;
4664
4665 IF asn_distributions%ISOPEN THEN
4666 CLOSE asn_distributions;
4667 END IF;
4668
4669 IF count_asn_distributions%ISOPEN THEN
4670 CLOSE count_asn_distributions;
4671 END IF;
4672
4673 EXIT;
4674 END IF; --} matches lastrecord or x_remaining_quantity <= 0
4675
4676 -- eliminate the row if it fails the date check
4677
4678 IF (g_asn_debug = 'Y') THEN
4679 asn_debug.put_line('Count in temp_cascade_table : ' || TO_CHAR(temp_cascaded_table.COUNT));
4680 asn_debug.put_line('Cursor record ' || TO_CHAR(rows_fetched));
4681 asn_debug.put_line('Check date tolerance');
4682 END IF;
4683
4684 rcv_transactions_interface_sv.check_date_tolerance(NVL(temp_cascaded_table(1).expected_receipt_date, x_header_record.header_record.expected_receipt_date), -- Bug 487222
4685 x_shipmentdistributionrec.promised_date,
4686 x_shipmentdistributionrec.days_early_receipt_allowed,
4687 x_shipmentdistributionrec.days_late_receipt_allowed,
4688 x_shipmentdistributionrec.receipt_days_exception_code
4689 );
4690
4691 /* Bug 3296214.
4692 * We need to use the control actions set in the Receiving
4693 * Options window. Get the control code from rcv_parameters.
4694 * If the transaction type is RECEIVE and if there is an
4695 * ASN existing for that PO, then depending on this value
4696 * we should either allow or error out.
4697 */
4698
4699 /* Bug 9169143: LSP Changes */
4700
4701
4702 begin
4703 x_po_header_id := x_cascaded_table(n).po_header_id;
4704 if (nvl(fnd_profile.value('wms_deployment_mode'), 1) = 3) then
4705 l_client_code := wms_deploy.get_po_client_code(x_po_header_id);
4706 if (l_client_code is not null) then
4707 select nvl(max(receipt_asn_exists_code),'none')
4708 into l_asn_exists_code
4709 from mtl_client_parameters
4710 where client_code = l_client_code;
4711
4712 if (g_asn_debug = 'y') then
4713 asn_debug.put_line('asn code in mtl_client_parameters'|| l_asn_exists_code);
4714 end if;
4715 else
4716 select nvl(max(receipt_asn_exists_code),'none')
4717 into l_asn_exists_code
4718 from rcv_parameters
4719 where organization_id = x_cascaded_table(n).to_organization_id;
4720
4721 if (g_asn_debug = 'y') then
4722 asn_debug.put_line('asn code in rcv_parameters'|| l_asn_exists_code);
4723 end if;
4724 end if;
4725 else
4726 select nvl(max(receipt_asn_exists_code),'none')
4727 into l_asn_exists_code
4728 from rcv_parameters
4729 where organization_id = x_cascaded_table(n).to_organization_id ;
4730
4731 if (g_asn_debug = 'y') then
4732 asn_debug.put_line('asn code in rcv_parameters '|| l_asn_exists_code);
4733 end if;
4734 end if;
4735 exception
4736 when others then
4737 l_asn_exists_code := 'none';
4738 end;
4739
4740 /* End LSP changes */
4741
4742 /* This check is not done for receiving against ASNs. So check
4743 * whether x_cascaded_table(n).shipment_header_id is null which
4744 * will be for the case of a receipt against a PO shipment.
4745 */
4746 IF ( (x_cascaded_table(n).transaction_type = 'RECEIVE')
4747 AND l_asn_exists_code IN('WARNING', 'REJECT')
4748 AND (rcv_roi_header.g_txn_against_asn = 'N')) THEN --{ Bug#4523892
4749 /* AND (x_is_asn = FALSE)) THEN --{ This is replaced by forward port for 4523892 */
4750 IF (g_asn_debug = 'Y') THEN
4751 asn_debug.put_line('ASN CODE IN Warning or Reject ');
4752 END IF;
4753
4754 /* Bug 4287932 In case of ASBN the ASN control action was
4755 * not getting applied. Added ASBN in the asn_type in
4756 * select below.
4757 */
4758
4759 SELECT COUNT(*)
4760 INTO l_asn_count
4761 FROM rcv_shipment_headers rsh,
4762 rcv_shipment_lines rsl
4763 WHERE rsh.shipment_header_id = rsl.shipment_header_id
4764 AND NVL(rsh.asn_type, 'STD') IN ('ASN','ASBN') --4287932
4765 AND NVL(rsl.shipment_line_status_code, 'EXPECTED') NOT IN('CANCELLED', 'FULLY RECEIVED')
4766 AND rsl.po_line_location_id = x_shipmentdistributionrec.line_location_id;
4767
4768 IF (g_asn_debug = 'Y') THEN
4769 asn_debug.put_line('l_asn_count ' || l_asn_count);
4770 END IF;
4771
4772 IF (l_asn_count <> 0) THEN --{
4773 IF (l_asn_exists_code = 'WARNING') THEN --{
4774 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
4775 rcv_error_pkg.set_error_message('RCV_ASN_EXISTS_FOR_POLINE', x_cascaded_table(n).error_message);
4776 rcv_error_pkg.log_interface_warning('DOCUMENT_NUM');
4777
4778 IF (g_asn_debug = 'Y') THEN
4779 asn_debug.put_line('AFter Warning insert into po_interface_errors ' || x_cascaded_table(n).error_message);
4780 END IF;
4781 END IF; --}
4782
4783 IF (l_asn_exists_code = 'REJECT') THEN --{
4784 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4785 rcv_error_pkg.set_error_message('RCV_ASN_EXISTS_FOR_POLINE', x_cascaded_table(n).error_message);
4786 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_num);
4787 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
4788
4789 IF (g_asn_debug = 'Y') THEN
4790 asn_debug.put_line('AFter Reject insert into po_interface_errors ' || x_cascaded_table(n).error_message);
4791 END IF;
4792 END IF; --}
4793 ELSE --}{
4794 /* This is a receipt against a PO but there is no ASN.
4795 */
4796 l_asn_exists_code := 'NONE';
4797 END IF; --}
4798 ELSE --}{
4799 /* This is an ASN transaction or receipt against an ASN or
4800 * else the asn code is NONE */
4801 l_asn_exists_code := 'NONE';
4802 END IF; --}
4803
4804 IF (l_asn_exists_code IN('NONE', 'WARNING')) THEN --{
4805 /* bug 1060261 - added error message to be shown when the expected date is outside tolerance range */
4806 IF (x_shipmentdistributionrec.receipt_days_exception_code = 'REJECT') THEN --{
4807 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4808 rcv_error_pkg.set_error_message('RCV_ASN_DATE_OUT_TOL', x_cascaded_table(n).error_message);
4809 rcv_error_pkg.set_token('DELIVERY DATE', NVL(temp_cascaded_table(1).expected_receipt_date, x_header_record.header_record.expected_receipt_date));
4810 rcv_error_pkg.log_interface_error('EXPECTED_RECEIPT_DATE', FALSE);
4811 END IF; --}
4812
4813 IF (g_asn_debug = 'Y') THEN
4814 asn_debug.put_line('Days exception Code ' || NVL(x_shipmentdistributionrec.receipt_days_exception_code, 'XXX'));
4815 END IF;
4816
4817 -- Check shipto_location enforcement
4818
4819 rcv_transactions_interface_sv.check_shipto_enforcement(x_shipmentdistributionrec.ship_to_location_id,
4820 NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id),
4821 x_shipmentdistributionrec.enforce_ship_to_location_code
4822 );
4823
4824 IF (g_asn_debug = 'Y') THEN
4825 asn_debug.put_line('Enforce ShipToLocation ' || NVL(x_shipmentdistributionrec.enforce_ship_to_location_code, 'XXX'));
4826 END IF;
4827
4828 /* Bug 2208664 : Enter error message in po_interface_errors if enforce_ship_to_location_code is 'WARNING', and
4829 Enter error message in po_interface_errors if enforce_ship_to_location_code is 'REJECT' and error out
4830 */
4831 IF (x_shipmentdistributionrec.enforce_ship_to_location_code = 'REJECT') THEN --{
4832 BEGIN
4833 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4834 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
4835 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
4836 rcv_error_pkg.log_interface_error('SHIP_TO_LOCATION_ID', FALSE);
4837 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
4838 END;
4839 ELSIF(x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING') THEN --} {
4840 BEGIN
4841 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
4842 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
4843 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
4844 rcv_error_pkg.log_interface_warning('SHIP_TO_LOCATION_ID');
4845 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
4846 END;
4847 END IF; --}matches ship_to_loc_code = warning
4848 END IF; --} matches l_asn_exists_code = NONE
4849
4850 IF (x_shipmentdistributionrec.receipt_days_exception_code = 'NONE')
4851 AND -- derived by the date tolerance procedure
4852 (x_shipmentdistributionrec.enforce_ship_to_location_code IN('NONE', 'WARNING'))
4853 AND (l_asn_exists_code IN('NONE', 'WARNING')) THEN --{
4854 -- derived by shipto_enforcement
4855 -- Changes to accept Vendor_Item_num without ITEM_ID/NUM
4856 -- Item_id could be null if the ASN has the vendor_item_num provided
4857 -- We need to put a value into item_id based on the cursor
4858 -- We need to also figure out the primary unit for the item_id
4859 -- We will do it for the first record only. Subsequent records in the
4860 -- temp_table are copies of the previous one
4861 -- Assuming that vendor_item_num refers to a single item. If the items
4862 -- could be different then we need to move this somewhere below
4863 IF (x_first_trans)
4864 AND temp_cascaded_table(current_n).item_id IS NULL THEN --{
4865 temp_cascaded_table(current_n).item_id := x_shipmentdistributionrec.item_id;
4866
4867 IF (g_asn_debug = 'Y') THEN
4868 asn_debug.put_line('Cursor Item Id is ' || TO_CHAR(temp_cascaded_table(current_n).item_id));
4869 END IF;
4870
4871 -- Bug 4881909 : For one-time items item_id would be null. Added check
4872 -- for item_id in the following IF statement
4873 IF x_cascaded_table(n).primary_unit_of_measure IS NULL
4874 AND temp_cascaded_table(current_n).item_id IS NOT NULL THEN --{
4875 BEGIN
4876 SELECT primary_unit_of_measure
4877 INTO temp_cascaded_table(current_n).primary_unit_of_measure
4878 FROM mtl_system_items
4879 WHERE mtl_system_items.inventory_item_id = temp_cascaded_table(current_n).item_id
4880 AND mtl_system_items.organization_id = temp_cascaded_table(current_n).to_organization_id;
4881
4882 IF (g_asn_debug = 'Y') THEN
4883 asn_debug.put_line('Primary UOM: ' || temp_cascaded_table(current_n).primary_unit_of_measure);
4884 END IF;
4885 EXCEPTION
4886 WHEN NO_DATA_FOUND THEN
4887 temp_cascaded_table(current_n).error_status := rcv_error_pkg.g_ret_sts_warning;
4888 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY', temp_cascaded_table(current_n).error_message);
4889 rcv_error_pkg.set_token('PRIMARY_UNIT', '');
4890 rcv_error_pkg.set_token('SHIPMENT_UNIT', '');
4891 rcv_error_pkg.log_interface_warning('ITEM_ID');
4892
4893 IF (g_asn_debug = 'Y') THEN
4894 asn_debug.put_line('Primary UOM error');
4895 END IF;
4896 END;
4897 END IF; --}
4898 END IF; --}
4899
4900 insert_into_table := FALSE;
4901 already_allocated_qty := 0;
4902
4903 /*
4904 ** Get the available quantity for the shipment or distribution
4905 ** that is available for allocation by this interface transaction
4906 */
4907 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
4908 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
4909 NULL;
4910
4911 /*Bug# 1548597 */
4912 /* IF (x_is_asn = FALSE) THEN --{ Replaced by forward port 4523892 */
4913 IF (rcv_roi_header.g_txn_against_asn = 'N') THEN --{ Bug#4523892
4914 IF (g_asn_debug = 'Y') THEN
4915 asn_debug.put_line('Receiving against a Po');
4916 END IF;
4917
4918 rcv_quantities_s.get_available_quantity('RECEIVE',
4919 x_shipmentdistributionrec.line_location_id,
4920 'VENDOR',
4921 NULL,
4922 NULL,
4923 NULL,
4924 x_converted_trx_qty,
4925 x_tolerable_qty,
4926 x_shipmentdistributionrec.unit_meas_lookup_code,
4927 x_secondary_available_qty
4928 );
4929 ELSE --}{
4930 IF (g_asn_debug = 'Y') THEN
4931 asn_debug.put_line('Receiving an ASN');
4932 END IF;
4933
4934 rcv_quantities_s.get_available_asn_quantity('RECEIVE',
4935 x_shipmentdistributionrec.shipment_line_id,
4936 x_shipmentdistributionrec.line_location_id,
4937 NULL, --po_distribution_id
4938 x_shipmentdistributionrec.unit_meas_lookup_code,
4939 x_converted_trx_qty,
4940 x_tolerable_qty,
4941 x_secondary_available_qty
4942 );
4943
4944 IF (g_asn_debug = 'Y') THEN
4945 asn_debug.put_line('x_converted_trx_qty ' || x_converted_trx_qty);
4946 asn_debug.put_line('x_tolerable_qty ' || x_tolerable_qty);
4947 asn_debug.put_line('x_secondary_available_qty ' || x_secondary_available_qty);
4948 END IF;
4949 END IF; --}
4950
4951
4952 -- If qtys have already been allocated for this po_line_location_id during
4953 -- a cascade process which has not been written to the db yet, we need to
4954 -- decrement it from the total available quantity
4955 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
4956 -- po_line_location_id
4957
4958 IF n > 1 THEN -- We will do this for all rows except the 1st
4959 FOR i IN 1 ..(n - 1) LOOP
4960 IF x_cascaded_table(i).po_line_location_id = x_shipmentdistributionrec.line_location_id THEN
4961 already_allocated_qty := already_allocated_qty + x_cascaded_table(i).source_doc_quantity;
4962 END IF;
4963 END LOOP;
4964 END IF;
4965 ELSE --} { for txn != deliver
4966 /* Bug# 1548597*/
4967 /* IF (x_is_asn = FALSE) THEN --{ Replaced by forward port 4523892 */
4968 IF (rcv_roi_header.g_txn_against_asn = 'N') THEN --{ Bug#4523892
4969 IF (g_asn_debug = 'Y') THEN
4970 asn_debug.put_line('Direct delivery against a Po');
4971 END IF;
4972
4973 rcv_quantities_s.get_available_quantity('DIRECT RECEIPT',
4974 x_shipmentdistributionrec.po_distribution_id,
4975 'VENDOR',
4976 NULL,
4977 NULL,
4978 NULL,
4979 x_converted_trx_qty,
4980 x_tolerable_qty,
4981 x_shipmentdistributionrec.unit_meas_lookup_code,
4982 x_secondary_available_qty
4983 );
4984 ELSE --}{
4985 IF (g_asn_debug = 'Y') THEN
4986 asn_debug.put_line('Direct delivery for an ASN');
4987 END IF;
4988
4989 rcv_quantities_s.get_available_asn_quantity('DIRECT RECEIPT',
4990 x_shipmentdistributionrec.shipment_line_id,
4991 x_shipmentdistributionrec.line_location_id,
4992 x_shipmentdistributionrec.po_distribution_id,
4993 x_shipmentdistributionrec.unit_meas_lookup_code,
4994 x_converted_trx_qty,
4995 x_tolerable_qty,
4996 x_secondary_available_qty
4997 );
4998
4999 IF (g_asn_debug = 'Y') THEN
5000 asn_debug.put_line('x_converted_trx_qty ' || x_converted_trx_qty);
5001 asn_debug.put_line('x_tolerable_qty ' || x_tolerable_qty);
5002 asn_debug.put_line('x_secondary_available_qty ' || x_secondary_available_qty);
5003 END IF;
5004 END IF; --}
5005
5006 /* Bug# 1337787 - Calculated the x_tolerable_qty in
5007 rcv_quantities_s.get_available_quantity procedure */
5008
5009 -- x_tolerable_qty := x_converted_trx_qty;
5010 -- If qtys have already been allocated for this po_distribution_id during
5011 -- a cascade process which has not been written to the db yet, we need to
5012 -- decrement it from the total available quantity
5013 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
5014 -- po_distribution_id
5015
5016 IF n > 1 THEN -- We will do this for all rows except the 1st
5017 FOR i IN 1 ..(n - 1) LOOP
5018 IF x_cascaded_table(i).po_distribution_id = x_shipmentdistributionrec.po_distribution_id THEN
5019 already_allocated_qty := already_allocated_qty + x_cascaded_table(i).source_doc_quantity;
5020 END IF;
5021 END LOOP;
5022 END IF;
5023 END IF; --} for txn =deliver
5024
5025 IF (g_asn_debug = 'Y') THEN
5026 asn_debug.put_line('After call to get_available quantity');
5027 asn_debug.put_line('Available Quantity ' || TO_CHAR(x_converted_trx_qty));
5028 asn_debug.put_line('Tolerable Quantity ' || TO_CHAR(x_tolerable_qty));
5029 asn_debug.put_line('Already Shipped Quantity ' || TO_CHAR(NVL(x_shipmentdistributionrec.quantity_shipped, 0)));
5030 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
5031 END IF;
5032
5033 -- if qty has already been allocated then reduce available and tolerable
5034 -- qty by the allocated amount
5035
5036 IF NVL(already_allocated_qty, 0) > 0 THEN --{
5037 x_converted_trx_qty := x_converted_trx_qty - already_allocated_qty;
5038 x_tolerable_qty := x_tolerable_qty - already_allocated_qty;
5039
5040 IF x_converted_trx_qty < 0 THEN
5041 x_converted_trx_qty := 0;
5042 END IF;
5043
5044 IF x_tolerable_qty < 0 THEN
5045 x_tolerable_qty := 0;
5046 END IF;
5047
5048 IF (g_asn_debug = 'Y') THEN
5049 asn_debug.put_line('Have some allocated quantity. Will reduce qty');
5050 asn_debug.put_line('Allocated Qty ' || TO_CHAR(already_allocated_qty));
5051 asn_debug.put_line('After reducing by allocated qty');
5052 asn_debug.put_line('Available Quantity ' || TO_CHAR(x_converted_trx_qty));
5053 asn_debug.put_line('Tolerable Quantity ' || TO_CHAR(x_tolerable_qty));
5054 asn_debug.put_line('Already Shipped Quantity ' || TO_CHAR(NVL(x_shipmentdistributionrec.quantity_shipped, 0)));
5055 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
5056 END IF;
5057 END IF; --}
5058
5059 -- We can use the first record since the item_id and uom are not going to change
5060 -- Check that we can convert between ASN-> PO uom
5061 -- PO -> ASN uom
5062 -- PO -> PRIMARY uom
5063 -- If any of the conversions fail then we cannot use that record
5064
5065 x_remaining_qty_po_uom := 0; -- initialize
5066 po_asn_uom_qty := 0; -- initialize
5067 po_primary_uom_qty := 0; -- initialize
5068
5069 /* Bug 5203841.
5070 * In complex work POs,there is a case where the rate based
5071 * PO shipment has matching_basis as Quantity based. But
5072 * item_id is null. Since there is no uom conversion in
5073 * the case of complex work POs, the old code would
5074 * return the original quantity whereas the new one
5075 * errors out. Reverting to old code for complex work POs.
5076 */
5077 PO_COMPLEX_WORK_GRP.is_complex_work_po(
5078 1.0,
5079 temp_cascaded_table(1).po_header_id, --Bug: 5357628
5080 l_return_status,
5081 l_complex_flag);
5082
5083 IF (l_return_status IS NOT NULL AND
5084 l_return_status = FND_API.g_ret_sts_success) THEN
5085 IF( g_asn_debug = 'Y' ) THEN
5086 asn_debug.put_line('l_return_status ' || l_return_status);
5087 asn_debug.put_line('l_po_header_id ' || temp_cascaded_table(1).po_header_id);
5088 END IF;
5089 ELSE
5090 IF( g_asn_debug = 'Y') THEN
5091 asn_debug.put_line('l_return_status ' || l_return_status);
5092 END IF;
5093 END IF;
5094
5095 if ( l_complex_flag = 'Y' ) then --{
5096 x_remaining_qty_po_uom := rcv_transactions_interface_sv.convert_into_correct_qty(x_remaining_quantity,
5097
5098 temp_cascaded_table(1).unit_of_measure,
5099
5100 temp_cascaded_table(1).item_id,
5101
5102 x_shipmentdistributionrec.unit_meas_lookup_code
5103
5104 );
5105 -- using arbit qty for PO->ASN, PO->PRIMARY UOM conversion as this is just a check
5106
5107 po_asn_uom_qty := rcv_transactions_interface_sv.convert_into_correct_qty(1000,
5108
5109 x_shipmentdistributionrec.unit_meas_lookup_code,
5110
5111 temp_cascaded_table(1).item_id,
5112
5113 temp_cascaded_table(1).unit_of_measure
5114
5115 );
5116 po_primary_uom_qty := rcv_transactions_interface_sv.convert_into_correct_qty(1000,
5117
5118 x_shipmentdistributionrec.unit_meas_lookup_code,
5119
5120 temp_cascaded_table(1).item_id,
5121
5122 temp_cascaded_table(1).primary_unit_of_measure
5123
5124 );
5125 else --}{
5126 -- For bug 8625167, to handle exception while converting uom
5127 -- Bug 4898703 - START {
5128 /*x_remaining_qty_po_uom := x_remaining_quantity * po_uom_s.po_uom_convert(temp_cascaded_table(1).unit_of_measure,
5129 x_shipmentdistributionrec.unit_meas_lookup_code,
5130 temp_cascaded_table(1).item_id
5131 );
5132 -- using arbit qty for PO->ASN, PO->PRIMARY UOM conversion as this is just a check
5133
5134 po_asn_uom_qty := 1000 * po_uom_s.po_uom_convert( x_shipmentdistributionrec.unit_meas_lookup_code,
5135 temp_cascaded_table(1).unit_of_measure,
5136 temp_cascaded_table(1).item_id
5137 );
5138 po_primary_uom_qty := 1000 * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
5139 temp_cascaded_table(1).primary_unit_of_measure,
5140 temp_cascaded_table(1).item_id
5141 );*/
5142 -- Bug 4898703 - END }
5143
5144 -- Bug 4898703 - START {
5145 BEGIN
5146 x_remaining_qty_po_uom := x_remaining_quantity * po_uom_s.po_uom_convert(temp_cascaded_table(1).unit_of_measure,
5147 x_shipmentdistributionrec.unit_meas_lookup_code,
5148 temp_cascaded_table(1).item_id
5149 );
5150 EXCEPTION
5151 when OTHERS THEN
5152 IF (g_asn_debug = 'Y') THEN
5153 asn_debug.put_line('Error: fail to calculate the x_remaining_qty_po_uom');
5154 END IF;
5155 x_remaining_qty_po_uom := 0;
5156 END;
5157
5158 BEGIN
5159 -- using arbit qty for PO->ASN, PO->PRIMARY UOM conversion as this is just a check
5160
5161 po_asn_uom_qty := 1000 * po_uom_s.po_uom_convert( x_shipmentdistributionrec.unit_meas_lookup_code,
5162 temp_cascaded_table(1).unit_of_measure,
5163 temp_cascaded_table(1).item_id
5164 );
5165 EXCEPTION
5166 when OTHERS THEN
5167 IF (g_asn_debug = 'Y') THEN
5168 asn_debug.put_line('Error: fail to calculate the po_asn_uom_qty');
5169 END IF;
5170 po_asn_uom_qty := 0;
5171 END;
5172
5173 BEGIN
5174 po_primary_uom_qty := 1000 * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
5175 temp_cascaded_table(1).primary_unit_of_measure,
5176 temp_cascaded_table(1).item_id
5177 );
5178 -- Bug 4898703 - END }
5179 EXCEPTION
5180 when OTHERS THEN
5181 IF (g_asn_debug = 'Y') THEN
5182 asn_debug.put_line('Error: fail to calculate the po_primary_uom_qty');
5183 END IF;
5184 po_primary_uom_qty := 0;
5185 END;
5186 -- end for bug 8625167
5187
5188 end if ; -- Bug 5203841. }
5189
5190 IF x_remaining_qty_po_uom = 0
5191 OR -- no point in going further for this record
5192 po_asn_uom_qty = 0
5193 OR -- as we cannot convert between the ASN -> PO uoms
5194 po_primary_uom_qty = 0 THEN --{ -- PO -> ASN uom, PO -> PRIMARY UOM
5195 IF (g_asn_debug = 'Y') THEN
5196 asn_debug.put_line('Populating an error message in the interface tables');
5197 asn_debug.put_line('Cannot interconvert between diff UOMs');
5198 asn_debug.put_line('This po_line cannot be used as the uoms ');
5199 asn_debug.put_line(temp_cascaded_table(1).unit_of_measure || ' ' || x_shipmentdistributionrec.unit_meas_lookup_code);
5200 asn_debug.put_line('cannot be converted for item ' || TO_CHAR(temp_cascaded_table(1).item_id));
5201 END IF; -- bug 8625167, correct the existing logic to throw exception if g_asn_debug is set to 'N'.
5202 /* Start Bug 3654053 : Need to populate the po_interface_errors
5203 table if the UOM conversion errors out.
5204 */
5205 IF po_primary_uom_qty = 0 THEN
5206 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5207 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY', x_cascaded_table(n).error_message);
5208 rcv_error_pkg.set_token('SHIPMENT_UNIT', x_shipmentdistributionrec.unit_meas_lookup_code);
5209 rcv_error_pkg.set_token('PRIMARY_UNIT', x_cascaded_table(n).primary_unit_of_measure);
5210 rcv_error_pkg.log_interface_error('PRIMARY_UNIT_OF_MEASURE', FALSE);
5211 ELSE
5212 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5213 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PO', x_cascaded_table(n).error_message);
5214 rcv_error_pkg.set_token('SHIPMENT_UNIT', temp_cascaded_table(1).unit_of_measure);
5215
5216 -- For bug 8625167, the token PRIMARY_UNIT is wrong, it should be PO_UNIT
5217 --rcv_error_pkg.set_token('PRIMARY_UNIT', x_shipmentdistributionrec.unit_meas_lookup_code);
5218 rcv_error_pkg.set_token('PO_UNIT', x_shipmentdistributionrec.unit_meas_lookup_code);
5219 -- End for bug 8625167
5220
5221 rcv_error_pkg.log_interface_error('UNIT_OF_MEASURE', FALSE);
5222 END IF;
5223 /* End Bug 3654053 */
5224 -- For bug 8625167, correct the existing logic to throw exception if g_asn_debug is set to 'N'.
5225 --END IF;
5226 -- End for bug 8625167
5227 ELSE -- we have converted the qty between uoms succesfully } {
5228 IF (g_asn_debug = 'Y') THEN
5229 asn_debug.put_line('Current Item Id ' || TO_CHAR(temp_cascaded_table(1).item_id));
5230 asn_debug.put_line('Current ASN Quantity ' || TO_CHAR(x_remaining_quantity));
5231 asn_debug.put_line('Current ASN UOM ' || temp_cascaded_table(1).unit_of_measure);
5232 asn_debug.put_line('Converted PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
5233 asn_debug.put_line('PO UOM ' || x_shipmentdistributionrec.unit_meas_lookup_code);
5234 END IF;
5235
5236 -- If last row set available = tolerable - shipped
5237 -- else = available - shipped
5238 /** Debug: We're a bit screwed here. How do we know if the shipment is taken into account here.
5239 **I guess if the transaction has the shipment line id then we should take the quantity from the shipped quantity.
5240 **Need to walk through the different scenarios
5241 */
5242 IF rows_fetched = x_record_count THEN --{
5243 x_converted_trx_qty := x_tolerable_qty - NVL(x_shipmentdistributionrec.quantity_shipped, 0);
5244
5245 IF (g_asn_debug = 'Y') THEN
5246 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_trx_qty));
5247 END IF;
5248 ELSE --} {
5249 x_converted_trx_qty := x_converted_trx_qty - NVL(x_shipmentdistributionrec.quantity_shipped, 0);
5250
5251 IF (g_asn_debug = 'Y') THEN
5252 asn_debug.put_line('Not Last Row : ' || TO_CHAR(x_converted_trx_qty));
5253 END IF;
5254 END IF; --}
5255
5256 IF x_converted_trx_qty > 0 THEN --{
5257 IF (x_converted_trx_qty < x_remaining_qty_po_uom) THEN -- compare like uoms {
5258 IF (g_asn_debug = 'Y') THEN
5259 asn_debug.put_line('We are in > Qty branch');
5260 END IF;
5261
5262 x_remaining_qty_po_uom := x_remaining_qty_po_uom - x_converted_trx_qty;
5263 -- change asn uom qty so both qtys are in sync
5264
5265 /* Bug 5203841.
5266 * In complex work POs,there is a case where the rate based
5267 * PO shipment has matching_basis as Quantity based. But
5268 * item_id is null. Since there is no uom conversion in
5269 * the case of complex work POs, the old code would
5270 * return the original quantity whereas the new one
5271 * errors out. Reverting to old code for complex work POs.
5272 */
5273 if ( l_complex_flag = 'Y' ) then --{
5274 x_remaining_quantity :=
5275 rcv_transactions_interface_sv.convert_into_correct_qty(
5276 x_remaining_qty_po_uom,
5277 x_shipmentdistributionrec.unit_meas_lookup_code,
5278 temp_cascaded_table(1).item_id,
5279 temp_cascaded_table(1).unit_of_measure);
5280
5281 else --}{
5282 -- Bug 4898703
5283 x_remaining_quantity := x_remaining_qty_po_uom * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
5284 temp_cascaded_table(1).unit_of_measure,
5285 temp_cascaded_table(1).item_id );
5286 end if; -- 5203841 }
5287 insert_into_table := TRUE;
5288 ELSE --} {
5289 IF (g_asn_debug = 'Y') THEN
5290 asn_debug.put_line('We are in <= Qty branch ');
5291 END IF;
5292
5293 x_converted_trx_qty := x_remaining_qty_po_uom;
5294 insert_into_table := TRUE;
5295 x_remaining_qty_po_uom := 0;
5296 x_remaining_quantity := 0;
5297 END IF; --}
5298 ELSE -- no qty for this record but if last row we need it } {
5299 IF rows_fetched = x_record_count THEN --{ last row needs to be inserted anyway
5300 -- so that the row can be used based on qty tolerance checks
5301 IF (g_asn_debug = 'Y') THEN
5302 asn_debug.put_line('Quantity is less then 0 but last record');
5303 END IF;
5304
5305 insert_into_table := TRUE;
5306 x_converted_trx_qty := 0;
5307 ELSE --} {
5308 IF (g_asn_debug = 'Y') THEN
5309 asn_debug.put_line('<= 0 Quantity but more records in cursor');
5310 END IF;
5311
5312 x_remaining_qty_po_uom := 0; -- we may have a diff uom on the next iteration
5313
5314 IF (g_asn_debug = 'Y') THEN
5315 asn_debug.put_line('We have to deal with remaining_qty > 0 and x_converted_trx_qty -ve');
5316 END IF;
5317
5318 insert_into_table := FALSE;
5319 END IF; --}
5320 END IF; --}
5321 END IF; --} remaining_qty_po_uom <> 0
5322
5323 IF insert_into_table THEN --{
5324 IF (x_first_trans) THEN --{
5325 IF (g_asn_debug = 'Y') THEN
5326 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
5327 END IF;
5328
5329 x_first_trans := FALSE;
5330
5331 IF NVL(temp_cascaded_table(current_n).vendor_cum_shipped_qty, 0) <> 0 THEN --{
5332 IF (g_asn_debug = 'Y') THEN
5333 asn_debug.put_line('The cum qty from vendor is ' || TO_CHAR(temp_cascaded_table(current_n).vendor_cum_shipped_qty));
5334 END IF;
5335
5336 /* The vendor sends us cum_qty which also includes the current shipment ???.
5337 We need to allocate the correct cum_qty to each row as the cascade happens
5338 The algorithm is as follows
5339 reset cum_qty = cum_qty - total_shipped_qty (x_bkp_qty) in the 1st run
5340 Later reset cum_qty = cum_qty + primary_qty for each insert.Since we always
5341 copy the previous record this should work pretty well */
5342
5343 /* Bug 5203841.
5344 * In complex work POs,there is a case where the rate based
5345 * PO shipment has matching_basis as Quantity based. But
5346 * item_id is null. Since there is no uom conversion in
5347 * the case of complex work POs, the old code would
5348 * return the original quantity whereas the new one
5349 * errors out. Reverting to old code for complex work POs.
5350 */
5351 if ( l_complex_flag = 'Y' ) then --{
5352 temp_cascaded_table(current_n).vendor_cum_shipped_qty :=
5353 temp_cascaded_table(current_n).vendor_cum_shipped_qty
5354 - rcv_transactions_interface_sv.convert_into_correct_qty
5355 (x_bkp_qty,
5356 temp_cascaded_table(current_n).unit_of_measure,
5357 temp_cascaded_table(current_n).item_id,
5358 temp_cascaded_table(current_n).primary_unit_of_measure);
5359
5360 else --}{
5361 -- Bug 4898703
5362 temp_cascaded_table(current_n).vendor_cum_shipped_qty := temp_cascaded_table(current_n).vendor_cum_shipped_qty
5363 - (x_bkp_qty * po_uom_s.po_uom_convert(temp_cascaded_table(current_n).unit_of_measure,
5364 temp_cascaded_table(current_n).primary_unit_of_measure,
5365 temp_cascaded_table(current_n).item_id
5366 ));
5367 end if; -- 5203841 }
5368
5369 IF (g_asn_debug = 'Y') THEN
5370 asn_debug.put_line('Cum qty - current shipment ' || TO_CHAR(temp_cascaded_table(current_n).vendor_cum_shipped_qty));
5371 END IF;
5372 END IF; --}
5373 ELSE --} { ! x_first_trans
5374 IF (g_asn_debug = 'Y') THEN
5375 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
5376 END IF;
5377
5378 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
5379 END IF; --} matches x_first_transfer
5380
5381 /* source_doc_quantity -> in po_uom
5382 primary_quantity -> in primary_uom
5383 cum_qty -> in primary_uom
5384 quantity,quantity_shipped -> in ASN uom */
5385 temp_cascaded_table(current_n).source_doc_quantity := x_converted_trx_qty; -- in po uom
5386 temp_cascaded_table(current_n).source_doc_unit_of_measure := x_shipmentdistributionrec.unit_meas_lookup_code;
5387 -- bug 1363369 fix carried forward FROM bug# 1337314
5388 -- No need to do the following conversion if the cursor returns one row
5389 -- for a corresponding record in the interface, as the quantity is already in asn uom.
5390 -- If the cursor fetches more than one row then the quantity in the interface will be
5391 -- distributed accross the fetched rows and hence need to do the following conversion.
5392 --IF x_record_count > 1 THEN -- {
5393
5394 /* Bug 5203841.
5395 * In complex work POs,there is a case where the rate based
5396 * PO shipment has matching_basis as Quantity based. But
5397 * item_id is null. Since there is no uom conversion in
5398 * the case of complex work POs, the old code would
5399 * return the original quantity whereas the new one
5400 * errors out. Reverting to old code for complex work POs.
5401 */
5402 if ( l_complex_flag = 'Y' ) then --{
5403 temp_cascaded_table(current_n).quantity := rcv_transactions_interface_sv.convert_into_correct_qty(x_converted_trx_qty,
5404
5405 x_shipmentdistributionrec.unit_meas_lookup_code,
5406
5407 temp_cascaded_table(current_n).item_id,
5408
5409 temp_cascaded_table(current_n).unit_of_measure
5410
5411 ); -- in asn uom
5412 --END IF; --}
5413 else --}{
5414 -- Bug 4898703 - START {
5415 temp_cascaded_table(current_n).quantity := x_converted_trx_qty * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
5416 temp_cascaded_table(current_n).unit_of_measure,
5417 temp_cascaded_table(current_n).item_id
5418 ); -- in asn uom
5419 --END IF; --}
5420 if ( x_shipmentdistributionrec.unit_meas_lookup_code <> temp_cascaded_table(current_n).unit_of_measure) then -- Bug 9701360
5421 temp_cascaded_table(current_n).quantity := round(temp_cascaded_table(current_n).quantity, 6);
5422 end if;
5423 end if; -- 5203841 }
5424 temp_cascaded_table(current_n).quantity_shipped := temp_cascaded_table(current_n).quantity; -- in asn uom
5425
5426 -- Primary qty in Primary UOM
5427 /* Bug 5203841.
5428 * In complex work POs,there is a case where the rate based
5429 * PO shipment has matching_basis as Quantity based. But
5430 * item_id is null. Since there is no uom conversion in
5431 * the case of complex work POs, the old code would
5432 * return the original quantity whereas the new one
5433 * errors out. Reverting to old code for complex work POs.
5434 */
5435 if ( l_complex_flag = 'Y' ) then --{
5436 temp_cascaded_table(current_n).primary_quantity := rcv_transactions_interface_sv.convert_into_correct_qty(x_converted_trx_qty,
5437 x_shipmentdistributionrec.unit_meas_lookup_code,
5438
5439 temp_cascaded_table(current_n).item_id,
5440
5441 temp_cascaded_table(current_n).primary_unit_of_measure
5442
5443 );
5444
5445
5446
5447 else -- }{
5448 temp_cascaded_table(current_n).primary_quantity := x_converted_trx_qty * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
5449 temp_cascaded_table(current_n).primary_unit_of_measure,
5450 temp_cascaded_table(current_n).item_id
5451 );
5452 if ( x_shipmentdistributionrec.unit_meas_lookup_code <> temp_cascaded_table(current_n).primary_unit_of_measure) then -- Bug 9701360
5453 temp_cascaded_table(current_n).primary_quantity := round(temp_cascaded_table(current_n).primary_quantity,6);
5454 end if;
5455
5456 end if; -- 5203841 }
5457 -- Bug 4898703 - END }
5458
5459 IF (g_asn_debug = 'Y') THEN
5460 asn_debug.put_line('primary_qty ' || temp_cascaded_table(current_n).primary_quantity);
5461 asn_debug.put_line('quantity ' || temp_cascaded_table(current_n).quantity);
5462 END IF;
5463
5464 -- Assuming vendor_cum_shipped_qty is in PRIMARY UOM
5465 IF NVL(temp_cascaded_table(current_n).vendor_cum_shipped_qty, 0) <> 0 THEN --{
5466 temp_cascaded_table(current_n).vendor_cum_shipped_qty := temp_cascaded_table(current_n).vendor_cum_shipped_qty + temp_cascaded_table(current_n).primary_quantity;
5467 END IF; --}
5468
5469 temp_cascaded_table(current_n).inspection_status_code := 'NOT INSPECTED';
5470 temp_cascaded_table(current_n).interface_source_code := NVL(temp_cascaded_table(current_n).interface_source_code,'RCV'); -- Bug 10127806
5471 temp_cascaded_table(current_n).currency_code := x_shipmentdistributionrec.currency_code;
5472 temp_cascaded_table(current_n).po_unit_price := x_shipmentdistributionrec.unit_price;
5473 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).quantity * tax_amount_factor, 4);
5474
5475 IF (g_asn_debug = 'Y') THEN
5476 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
5477 END IF;
5478
5479 temp_cascaded_table(current_n).category_id := x_shipmentdistributionrec.category_id;
5480 temp_cascaded_table(current_n).item_description := x_shipmentdistributionrec.item_description;
5481 temp_cascaded_table(current_n).unit_of_measure_class := x_shipmentdistributionrec.unit_of_measure_class;
5482
5483 IF temp_cascaded_table(current_n).to_organization_id IS NULL THEN --{
5484 temp_cascaded_table(current_n).to_organization_id := x_shipmentdistributionrec.ship_to_organization_id;
5485 END IF; --}
5486
5487 temp_cascaded_table(current_n).po_line_id := x_shipmentdistributionrec.po_line_id;
5488 temp_cascaded_table(current_n).po_line_location_id := x_shipmentdistributionrec.line_location_id;
5489 temp_cascaded_table(current_n).shipment_line_id := x_shipmentdistributionrec.shipment_line_id;
5490
5491 IF x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING' THEN --{
5492 IF (g_asn_debug = 'Y') THEN
5493 asn_debug.put_line('Message to warn about different shiptolocations');
5494 END IF;
5495 END IF; --}
5496
5497 /* ksareddy - 2329928 Ported changes by bao in branch to cache set_of_books_id */
5498 IF (rcv_transactions_interface_sv.x_set_of_books_id IS NULL) THEN
5499 SELECT set_of_books_id
5500 INTO rcv_transactions_interface_sv.x_set_of_books_id
5501 FROM financials_system_parameters;
5502 END IF;
5503
5504 x_sob_id := rcv_transactions_interface_sv.x_set_of_books_id;
5505 /* Bug 1845702
5506 * Currency rate and date can be changed at the time of receipt
5507 * depending on the profile ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE.
5508 * This was not handled in the open interface. Introduced code
5509 * to handle the changes at the time of receipt
5510 */
5511 /* Bug#3746516 Added the following if condition so as to get the value of the profile
5512 ** option only when the match option is receipt and thus to avoid executing the below
5513 ** function call always.
5514 */
5515 IF (x_ShipmentDistributionRec.match_option = 'R') THEN
5516 x_allow_rate_override := NVL(fnd_profile.value('ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE'), 'N');
5517 END IF;
5518
5519 IF (g_asn_debug = 'Y') THEN
5520 asn_debug.put_line('Match Option:' || x_ShipmentDistributionRec.match_option ||
5521 'Profile value ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE:' ||
5522 x_allow_rate_override);
5523 END IF;
5524
5525 /* Bug#3746516 - START
5526 ** Modified the following code to consider all the possible scenarios such that the
5527 ** rate and the rate date values will be derived correctly and the correct rate and
5528 ** rate date values will now be posted in rcv_transactions table so that there will
5529 ** not be any discrepency in the calculations and hence all the data between the two
5530 ** tables rcv_transactions and rcv_receiving_sub_ledger will be in sync. */
5531
5532 BEGIN
5533
5534 SELECT count(po_distribution_id),max(rate),max(rate_date)
5535 INTO l_dist_count,x_rate,l_rate_date
5536 FROM po_distributions
5537 WHERE line_location_id = x_ShipmentDistributionRec.line_location_id
5538 HAVING count(po_distribution_id) = 1;
5539
5540 EXCEPTION
5541 WHEN NO_DATA_FOUND THEN
5542 l_dist_count := 2;
5543 END;
5544
5545 IF (g_asn_debug = 'Y') THEN
5546 asn_debug.put_line('No of Distributions:' || l_dist_count ||
5547 ':: Rate and Rate_date in po distributions' || x_rate ||
5548 '::' || l_rate_date);
5549 END IF;
5550
5551 IF (x_ShipmentDistributionRec.match_option = 'P') THEN --{
5552
5553 IF (l_dist_count = 1) THEN --{
5554 temp_cascaded_table(current_n).currency_conversion_date := l_rate_date;
5555 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
5556 ELSE
5557 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
5558 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
5559 END IF; --}
5560
5561 /* Bug 13013727 Modified the following code to handle the cases where Match Option is 'Receipt'.
5562 The Rate Date needs to be defaulted from Transaction Date for such cases, and NOT from PO_DISTRIBUTIONS.
5563 Also, the corresponding Rate needs to be calculated in case of Rate Type <> 'User'. */
5564 ELSIF (x_ShipmentDistributionRec.match_option = 'R') THEN
5565
5566 IF (x_ShipmentDistributionRec.rate_type = 'User') THEN --{
5567
5568 IF ( x_allow_rate_override ='N') THEN --{
5569
5570 IF (l_dist_count = 1) THEN --{
5571 temp_cascaded_table(current_n).currency_conversion_date :=
5572 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_cascaded_table(n).transaction_date);
5573 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
5574 ELSE
5575 temp_cascaded_table(current_n).currency_conversion_date :=
5576 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_cascaded_table(n).transaction_date);
5577 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
5578 END IF; --}
5579
5580 ELSIF ( x_allow_rate_override ='Y') THEN
5581
5582 IF (l_dist_count = 1) THEN --{
5583 temp_cascaded_table(current_n).currency_conversion_date :=
5584 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_cascaded_table(n).transaction_date);
5585 temp_cascaded_table(current_n).currency_conversion_rate :=
5586 nvl(temp_cascaded_table(current_n).currency_conversion_rate,x_rate);
5587 ELSE
5588 temp_cascaded_table(current_n).currency_conversion_date :=
5589 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_cascaded_table(n).transaction_date);
5590 temp_cascaded_table(current_n).currency_conversion_rate :=
5591 nvl(temp_cascaded_table(current_n).currency_conversion_rate,x_ShipmentDistributionRec.rate);
5592 END IF; --}
5593 END IF; --}
5594
5595 ELSE
5596
5597 IF ( temp_cascaded_table(current_n).currency_conversion_date IS NOT NULL ) THEN --{
5598 /* Bug 13013727 Calculating the corresponding Rate here. Modified code to handle the exception and log a
5599 message into the log file if there is no Rate defined for the particular Rate Date and Rate Type */
5600 BEGIN
5601 x_rate := gl_currency_api.get_rate(x_sob_Id,
5602 x_ShipmentDistributionRec.currency_code,
5603 temp_cascaded_table(current_n).currency_conversion_date,
5604 x_ShipmentDistributionRec.rate_type);
5605 x_rate := round(x_rate,28);
5606 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
5607 EXCEPTION
5608 WHEN OTHERS THEN
5609 IF (g_asn_debug = 'Y') THEN
5610 asn_debug.put_line('Exception 1 ::'||SQLERRM||':: occurred while deriving the rate for currency_conversion_date : '||temp_cascaded_table(current_n).currency_conversion_date
5611 ||' for the rate type : '||x_ShipmentDistributionRec.rate_type);
5612 asn_debug.put_line('The rate returned is : '||temp_cascaded_table(current_n).currency_conversion_rate);
5613 END IF;
5614 RAISE;
5615 END;
5616 ELSE
5617 /* Bug 13013727 Calculating the corresponding Rate here. Modified code to handle the exception and log a
5618 message into the log file if there is no Rate defined for the particular Rate Date and Rate Type */
5619 BEGIN
5620 temp_cascaded_table(current_n).currency_conversion_date := x_cascaded_table(n).transaction_date;
5621 x_rate := gl_currency_api.get_rate(x_sob_Id,
5622 x_ShipmentDistributionRec.currency_code,
5623 temp_cascaded_table(current_n).currency_conversion_date,
5624 x_ShipmentDistributionRec.rate_type);
5625 x_rate := round(x_rate,28);
5626 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
5627 EXCEPTION
5628 WHEN OTHERS THEN
5629 IF (g_asn_debug = 'Y') THEN
5630 asn_debug.put_line('Exception 2 ::'||SQLERRM||':: occurred while deriving the rate for currency_conversion_date : '||temp_cascaded_table(current_n).currency_conversion_date
5631 ||' for the rate type : '||x_ShipmentDistributionRec.rate_type);
5632 asn_debug.put_line('The rate returned is : '||temp_cascaded_table(current_n).currency_conversion_rate);
5633 END IF;
5634 RAISE;
5635 END;
5636 END IF; --}
5637
5638 END IF; --}
5639
5640 END IF; --}
5641 /* End of fix for Bug 13013727 */
5642
5643 temp_cascaded_table(current_n).currency_conversion_type := x_ShipmentDistributionRec.rate_type;
5644
5645 IF (g_asn_debug = 'Y') THEN
5646 asn_debug.put_line('Rate, Rate type and Rate_date ::' ||
5647 temp_cascaded_table(current_n).currency_conversion_rate ||
5648 '::' || temp_cascaded_table(current_n).currency_conversion_type ||
5649 '::' || temp_cascaded_table(current_n).currency_conversion_date);
5650 END IF;
5651
5652 /* Bug#3746516 - END */
5653
5654 -- Copy the distribution specific information only if this is a direct receipt.
5655
5656 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
5657 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
5658 temp_cascaded_table(current_n).po_distribution_id := x_shipmentdistributionrec.po_distribution_id;
5659 temp_cascaded_table(current_n).charge_account_id := x_shipmentdistributionrec.code_combination_id;
5660 temp_cascaded_table(current_n).req_distribution_id := x_shipmentdistributionrec.req_distribution_id;
5661 --temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
5662 --temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
5663 temp_cascaded_table(current_n).destination_type_code := x_shipmentdistributionrec.destination_type_code;
5664 temp_cascaded_table(current_n).destination_context := x_shipmentdistributionrec.destination_type_code;
5665
5666 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
5667 temp_cascaded_table(current_n).deliver_to_location_id := x_shipmentdistributionrec.deliver_to_location_id;
5668 END IF;
5669
5670 /* Bug 2392074 - If the deliver_to_person mentioned in the po_distributions is
5671 invalid or inactive at the time of Receipt we need to clear the deliver to person,
5672 as this is an optional field. */
5673 IF (NVL(temp_cascaded_table(current_n).deliver_to_person_id, 0) = 0) THEN --{
5674 temp_cascaded_table(current_n).deliver_to_person_id := x_shipmentdistributionrec.deliver_to_person_id;
5675
5676 IF (temp_cascaded_table(current_n).deliver_to_person_id IS NOT NULL) THEN --{
5677 BEGIN
5678 SELECT NVL(MAX(hre.full_name), 'notfound')
5679 INTO x_full_name
5680 FROM hr_employees_current_v hre
5681 WHERE ( hre.inactive_date IS NULL
5682 OR hre.inactive_date > SYSDATE)
5683 AND hre.employee_id = temp_cascaded_table(current_n).deliver_to_person_id;
5684
5685 IF (x_full_name = 'notfound') THEN
5686 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
5687 END IF;
5688 EXCEPTION
5689 WHEN NO_DATA_FOUND THEN
5690 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
5691
5692 IF (g_asn_debug = 'Y') THEN
5693 asn_debug.put_line('The deliver to person entered in PO is currently inactive');
5694 asn_debug.put_line(' So it is cleared off');
5695 END IF;
5696 WHEN OTHERS THEN
5697 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
5698
5699 IF (g_asn_debug = 'Y') THEN
5700 asn_debug.put_line('Some exception has occured');
5701 asn_debug.put_line('This exception is due to the PO deliver to person');
5702 asn_debug.put_line('The deliver to person is optional');
5703 asn_debug.put_line('So cleared off the deliver to person');
5704 END IF;
5705 END;
5706 END IF; --}
5707 END IF; --}
5708
5709 IF (temp_cascaded_table(current_n).subinventory IS NULL) THEN
5710 temp_cascaded_table(current_n).subinventory := x_shipmentdistributionrec.destination_subinventory;
5711
5712 /* Bug3993867 - START
5713 ** Added the call to procedure derive_to_locator_id() here
5714 ** so that incases where subinventory and
5715 ** locator_id are not populated into RTI, locator_id could be
5716 ** derived at this point as the subinventory is known now.
5717 */
5718 IF (g_asn_debug = 'Y') THEN
5719 asn_debug.put_line('Derived Subinventory from PO Distribution:' || temp_cascaded_table(current_n).subinventory);
5720 END IF;
5721
5722 derive_to_locator_id(temp_cascaded_table, current_n);
5723
5724 IF (g_asn_debug = 'Y') THEN
5725 asn_debug.put_line('Derived Locator_ID:' || temp_cascaded_table(current_n).locator_id);
5726 END IF;
5727
5728 /* Bug3993867 - END */
5729
5730 END IF;
5731
5732 temp_cascaded_table(current_n).wip_entity_id := x_shipmentdistributionrec.wip_entity_id;
5733 temp_cascaded_table(current_n).wip_operation_seq_num := x_shipmentdistributionrec.wip_operation_seq_num;
5734 temp_cascaded_table(current_n).wip_resource_seq_num := x_shipmentdistributionrec.wip_resource_seq_num;
5735 temp_cascaded_table(current_n).wip_repetitive_schedule_id := x_shipmentdistributionrec.wip_repetitive_schedule_id;
5736 temp_cascaded_table(current_n).wip_line_id := x_shipmentdistributionrec.wip_line_id;
5737 temp_cascaded_table(current_n).bom_resource_id := x_shipmentdistributionrec.bom_resource_id;
5738 temp_cascaded_table(current_n).project_id := x_shipmentdistributionrec.project_id; /* Bug 14725305 */
5739 temp_cascaded_table(current_n).task_id := x_shipmentdistributionrec.task_id; /* Bug 14725305 */
5740 -- bug 1361786
5741 IF (temp_cascaded_table(current_n).ussgl_transaction_code IS NULL) THEN
5742 temp_cascaded_table(current_n).ussgl_transaction_code := x_shipmentdistributionrec.ussgl_transaction_code;
5743 END IF;
5744 END IF; --} matches txn != deliver
5745
5746 current_n := current_n + 1;
5747
5748 IF (g_asn_debug = 'Y') THEN
5749 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
5750 END IF;
5751 END IF; --} matches if insert into table
5752 END IF; --} matches shipmentdistributionrec.receipt_days_exception_code = none
5753 END LOOP; --}
5754 ELSE --} {
5755 -- error_status and error_message are set after validate_quantity_shipped
5756 IF (g_asn_debug = 'Y') THEN
5757 asn_debug.put_line('No shipment_header_id/po_header_id/item_id ');
5758 END IF;
5759
5760 IF (g_asn_debug = 'Y') THEN
5761 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
5762 END IF;
5763
5764 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
5765 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5766 rcv_error_pkg.set_error_message('RCV_ASN_NO_PO_LINE_LOCATION_ID', x_cascaded_table(n).error_message);
5767 rcv_error_pkg.set_token('DOCUMENT_NUM', x_cascaded_table(n).document_num);
5768 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
5769 END IF; --}
5770
5771 RETURN;
5772 END IF; -- } of (asn quantity_shipped was valid)
5773
5774 -- OPM change.Bug# 3061052
5775 -- if original receiving transaction line is split and secondary quantity is specified then
5776 -- set secondary quantity for the split lines to NULL.In such a case,secondary quantity for the
5777 -- split lines will be calculating by the system in opm_roi_grp.validate_lot API.
5778 /* INVCONV , It checks for OPM insatallation. This needs to be removed , Punit Kumar */
5779
5780 IF /* gml_process_flags.opm_installed = 1
5781 AND*/ x_cascaded_table(n).secondary_quantity IS NOT NULL THEN
5782 IF temp_cascaded_table.COUNT > 1 THEN
5783 FOR j IN 1 .. temp_cascaded_table.COUNT LOOP
5784 temp_cascaded_table(j).secondary_quantity := NULL;
5785 END LOOP;
5786 END IF;
5787 END IF;
5788
5789 IF shipments%ISOPEN THEN
5790 CLOSE shipments;
5791 END IF;
5792
5793 IF count_shipments%ISOPEN THEN
5794 CLOSE count_shipments;
5795 END IF;
5796
5797 IF distributions%ISOPEN THEN
5798 CLOSE distributions;
5799 END IF;
5800
5801 IF count_distributions%ISOPEN THEN
5802 CLOSE count_distributions;
5803 END IF;
5804
5805 IF asn_shipments%ISOPEN THEN
5806 CLOSE asn_shipments;
5807 END IF;
5808
5809 IF count_asn_shipments%ISOPEN THEN
5810 CLOSE count_asn_shipments;
5811 END IF;
5812
5813 IF asn_distributions%ISOPEN THEN
5814 CLOSE asn_distributions;
5815 END IF;
5816
5817 IF count_asn_distributions%ISOPEN THEN
5818 CLOSE count_asn_distributions;
5819 END IF;
5820
5821 IF (g_asn_debug = 'Y') THEN
5822 asn_debug.put_line('Exit explode_line_quantity');
5823 END IF;
5824 EXCEPTION
5825 WHEN OTHERS THEN
5826 IF (g_asn_debug = 'Y') THEN
5827 asn_debug.put_line('Exception in derive_vendor_rcv_line_qty');
5828 END IF;
5829
5830 IF shipments%ISOPEN THEN
5831 CLOSE shipments;
5832 END IF;
5833
5834 IF count_shipments%ISOPEN THEN
5835 CLOSE count_shipments;
5836 END IF;
5837
5838 IF distributions%ISOPEN THEN
5839 CLOSE distributions;
5840 END IF;
5841
5842 IF count_distributions%ISOPEN THEN
5843 CLOSE count_distributions;
5844 END IF;
5845
5846 IF asn_shipments%ISOPEN THEN
5847 CLOSE asn_shipments;
5848 END IF;
5849
5850 IF count_asn_shipments%ISOPEN THEN
5851 CLOSE count_asn_shipments;
5852 END IF;
5853
5854 IF asn_distributions%ISOPEN THEN
5855 CLOSE asn_distributions;
5856 END IF;
5857
5858 IF count_asn_distributions%ISOPEN THEN
5859 CLOSE count_asn_distributions;
5860 END IF;
5861
5862 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
5863 rcv_error_pkg.set_sql_error_message('derive_vendor_rcv_line_qty', x_progress);
5864 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
5865
5866 IF (g_asn_debug = 'Y') THEN
5867 asn_debug.put_line(TO_CHAR(n));
5868 asn_debug.put_line(SQLERRM);
5869 asn_debug.put_line('error ' || x_progress);
5870 END IF;
5871 END derive_vendor_rcv_line_qty;
5872
5873 PROCEDURE derive_vendor_rcv_line_amt(
5874 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
5875 n IN OUT NOCOPY BINARY_INTEGER,
5876 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
5877 x_header_record IN rcv_roi_preprocessor.header_rec_type
5878 ) IS
5879 x_include_closed_po VARCHAR2(1); -- Bug 1887728
5880
5881 CURSOR shipments(
5882 v_po_line_id NUMBER,
5883 v_po_line_location_id NUMBER,
5884 v_po_release_id NUMBER
5885 ) IS
5886 SELECT pll.line_location_id,
5887 NVL(pll.promised_date, pll.need_by_date) promised_date,
5888 pll.ship_to_organization_id,
5889 pll.amount amount_ordered,
5890 pll.amount_shipped ,
5891 pll.receipt_days_exception_code,
5892 pll.qty_rcv_tolerance,
5893 pll.qty_rcv_exception_code,
5894 pll.days_early_receipt_allowed,
5895 pll.days_late_receipt_allowed,
5896 pll.match_option,
5897 pl.job_id,
5898 pl.po_line_id,
5899 ph.currency_code,
5900 ph.rate_type,
5901 0 po_distribution_id,
5902 0 code_combination_id,
5903 0 req_distribution_id,
5904 0 deliver_to_location_id,
5905 0 deliver_to_person_id,
5906 ph.rate_date rate_date,
5907 ph.rate rate,
5908 '' destination_type_code,
5909 0 destination_organization_id,
5910 '' destination_subinventory,
5911 0 wip_entity_id,
5912 0 wip_operation_seq_num,
5913 0 wip_resource_seq_num,
5914 0 wip_repetitive_schedule_id,
5915 0 wip_line_id,
5916 0 bom_resource_id,
5917 '' ussgl_transaction_code,
5918 pll.ship_to_location_id,
5919 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
5920 pl.item_id
5921 FROM po_line_locations pll,
5922 po_lines pl,
5923 po_headers ph
5924 WHERE pl.po_line_id = v_po_line_id
5925 AND pll.po_line_id = v_po_line_id
5926 AND ph.po_header_id = pl.po_header_id
5927 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
5928 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
5929 AND NVL(pll.approved_flag, 'N') = 'Y'
5930 AND NVL(pll.cancel_flag, 'N') = 'N'
5931 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
5932 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
5933 OR ( NVL(x_include_closed_po, 'N') = 'N'
5934 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
5935 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
5936 ORDER BY NVL(pll.promised_date, pll.need_by_date);
5937
5938 CURSOR count_shipments(
5939 v_po_line_id NUMBER,
5940 v_po_line_location_id NUMBER,
5941 v_po_release_id NUMBER
5942 ) IS
5943 SELECT COUNT(*)
5944 FROM po_line_locations pll,
5945 po_lines pl,
5946 po_headers ph
5947 WHERE pl.po_line_id = v_po_line_id
5948 AND pll.po_line_id = v_po_line_id
5949 AND ph.po_header_id = pl.po_header_id
5950 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
5951 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
5952 AND NVL(pll.approved_flag, 'N') = 'Y'
5953 AND NVL(pll.cancel_flag, 'N') = 'N'
5954 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
5955 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
5956 OR ( NVL(x_include_closed_po, 'N') = 'N'
5957 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
5958 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT');
5959
5960 CURSOR distributions(
5961 v_po_line_id NUMBER,
5962 v_po_line_location_id NUMBER,
5963 v_po_distribution_id NUMBER,
5964 v_po_release_id NUMBER
5965 ) IS
5966 SELECT pll.line_location_id,
5967 NVL(pll.promised_date, pll.need_by_date) promised_date,
5968 pll.ship_to_organization_id,
5969 pll.amount amount_ordered,
5970 pll.amount_shipped,
5971 pll.receipt_days_exception_code,
5972 pll.qty_rcv_tolerance,
5973 pll.qty_rcv_exception_code,
5974 pll.days_early_receipt_allowed,
5975 pll.days_late_receipt_allowed,
5976 pll.match_option,
5977 pl.job_id,
5978 pl.po_line_id,
5979 ph.currency_code,
5980 ph.rate_type,
5981 pod.po_distribution_id,
5982 pod.code_combination_id,
5983 pod.req_distribution_id,
5984 pod.deliver_to_location_id,
5985 pod.deliver_to_person_id,
5986 pod.rate_date,
5987 pod.rate,
5988 pod.destination_type_code,
5989 pod.destination_organization_id,
5990 pod.destination_subinventory,
5991 pod.wip_entity_id,
5992 pod.wip_operation_seq_num,
5993 pod.wip_resource_seq_num,
5994 pod.wip_repetitive_schedule_id,
5995 pod.wip_line_id,
5996 pod.bom_resource_id,
5997 pod.ussgl_transaction_code,
5998 pll.ship_to_location_id,
5999 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
6000 pl.item_id
6001 FROM po_distributions pod,
6002 po_line_locations pll,
6003 po_lines pl,
6004 po_headers ph
6005 WHERE pl.po_line_id = v_po_line_id
6006 AND pll.po_line_id = v_po_line_id
6007 AND ph.po_header_id = pl.po_header_id
6008 AND pod.line_location_id = pll.line_location_id
6009 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
6010 AND pod.po_distribution_id = NVL(v_po_distribution_id, pod.po_distribution_id)
6011 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
6012 AND NVL(pll.approved_flag, 'N') = 'Y'
6013 AND NVL(pll.cancel_flag, 'N') = 'N'
6014 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
6015 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
6016 OR ( NVL(x_include_closed_po, 'N') = 'N'
6017 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
6018 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
6019 ORDER BY NVL(pll.promised_date, pll.need_by_date);
6020
6021 CURSOR count_distributions(
6022 v_po_line_id NUMBER,
6023 v_po_line_location_id NUMBER,
6024 v_po_distribution_id NUMBER,
6025 v_po_release_id NUMBER
6026 ) IS
6027 SELECT COUNT(*)
6028 FROM po_distributions pod,
6029 po_line_locations pll,
6030 po_lines pl,
6031 po_headers ph
6032 WHERE pl.po_line_id = v_po_line_id
6033 AND pll.po_line_id = v_po_line_id
6034 AND ph.po_header_id = pl.po_header_id
6035 AND pod.line_location_id = pll.line_location_id
6036 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
6037 AND pod.po_distribution_id = NVL(v_po_distribution_id, pod.po_distribution_id)
6038 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
6039 AND NVL(pll.approved_flag, 'N') = 'Y'
6040 AND NVL(pll.cancel_flag, 'N') = 'N'
6041 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
6042 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
6043 OR ( NVL(x_include_closed_po, 'N') = 'N'
6044 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
6045 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT');
6046
6047 /*
6048 ** Debug: had to change this to the distribution record
6049 ** Might be a compatibility issue between the two record definitions
6050 */
6051 x_shipmentdistributionrec distributions%ROWTYPE;
6052 x_record_count NUMBER;
6053 x_remaining_amount NUMBER := 0;
6054 x_progress VARCHAR2(3);
6055 x_to_organization_code VARCHAR2(5);
6056 x_converted_trx_amt NUMBER := 0;
6057 transaction_ok BOOLEAN := FALSE;
6058 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
6059 high_range_date DATE;
6060 low_range_date DATE;
6061 rows_fetched NUMBER := 0;
6062 x_tolerable_amt NUMBER := 0;
6063 x_first_trans BOOLEAN := TRUE;
6064 x_sysdate DATE := SYSDATE;
6065 current_n BINARY_INTEGER := 0;
6066 insert_into_table BOOLEAN := FALSE;
6067 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
6068 tax_amount_factor NUMBER;
6069 lastrecord BOOLEAN := FALSE;
6070 already_allocated_amt NUMBER := 0;
6071 x_release_id NUMBER;
6072 x_approved_flag VARCHAR(1);
6073 x_cancel_flag VARCHAR(1);
6074 x_closed_code VARCHAR(25);
6075 x_shipment_type VARCHAR(25);
6076 x_temp_count NUMBER;
6077 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
6078 profile_user_id NUMBER := -1;
6079 profile_appl_id NUMBER := -1;
6080 profile_resp_id NUMBER := -1;
6081 defined BOOLEAN;
6082 x_sob_id NUMBER := NULL;
6083 x_rate NUMBER;
6084 x_allow_rate_override VARCHAR2(1);
6085 l_time_count NUMBER;
6086 l_dist_count number; /* Bug#3746516 */
6087 l_rate_date po_headers.rate_date%type; /* Bug#3746516 */
6088
6089 -- <Bug 9342280 : Added for CLM project>
6090 l_is_clm_po VARCHAR2(5) := 'N';
6091 l_partial_funded_flag VARCHAR2(5) := 'N';
6092 -- <CLM END>
6093 BEGIN
6094 --check line quanity > 0
6095 x_progress := '097';
6096
6097 IF (g_asn_debug = 'Y') THEN
6098 asn_debug.put_line('derive_vendor_rcv_line_amt ' || x_progress);
6099 END IF;
6100
6101 profile_user_id := fnd_profile.VALUE('USER_ID');
6102 profile_resp_id := fnd_profile.VALUE('RESPONSIBILITY_ID');
6103 profile_appl_id := fnd_profile.VALUE('APPLICATION_ID');
6104 fnd_profile.get_specific('RCV_CLOSED_PO_DEFAULT_OPTION',
6105 profile_user_id,
6106 profile_resp_id,
6107 profile_appl_id,
6108 x_include_closed_po,
6109 defined
6110 );
6111
6112 IF (g_asn_debug = 'Y') THEN
6113 asn_debug.put_line('Include closed PO profile value ' || x_include_closed_po);
6114 END IF;
6115
6116 /* We do not support ASN/ASBN for Serive based PO shipments. So
6117 * error out in that case.
6118 */
6119 /* Complex Work project*/
6120 IF ((x_cascaded_table(n).transaction_type = 'SHIP') and
6121 (x_header_record.header_record.asn_type <> 'WC' )) THEN --{
6122 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6123 rcv_error_pkg.set_error_message('RCV_NO_SERVICE_SUPPORT_TRX', x_cascaded_table(n).error_message);
6124 rcv_error_pkg.set_token('TRX_TYPE', x_cascaded_table(n).transaction_type);
6125 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
6126 END IF; --}
6127
6128 /* Support for RATE based from OTL */
6129 IF ( x_cascaded_table(n).value_basis = 'RATE'
6130 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR') THEN --{
6131 IF (g_asn_debug = 'Y') THEN
6132 asn_debug.put_line('Rate/Temp Labor');
6133 END IF;
6134
6135 /* Bug 3648861.
6136 * The where condition has
6137 * and pol.po_line_id=po_line_id.
6138 * It should be
6139 * and pol.po_line_id=x_cascaded_table(n).po_line_id
6140 * Changed the condition.
6141 */
6142 SELECT COUNT(*)
6143 INTO l_time_count
6144 FROM hxc_time_building_blocks bb,
6145 po_lines pol
6146 WHERE bb.time_building_block_id = x_cascaded_table(n).timecard_id
6147 AND bb.object_version_number = x_cascaded_table(n).timecard_ovn
6148 AND bb.SCOPE = 'TIMECARD'
6149 AND bb.resource_type = 'PERSON'
6150 AND bb.resource_id IN(SELECT person_id
6151 FROM per_all_assignments_f
6152 WHERE assignment_type = 'C')
6153 AND pol.po_line_id = x_cascaded_table(n).po_line_id
6154 AND pol.order_type_lookup_code = 'RATE'
6155 AND pol.purchase_basis = 'TEMP LABOR';
6156
6157 IF (g_asn_debug = 'Y') THEN
6158 asn_debug.put_line('count ' || l_time_count);
6159 END IF;
6160
6161 IF (l_time_count = 0) THEN --{
6162 IF (g_asn_debug = 'Y') THEN
6163 asn_debug.put_line('We do not support RATE/TEMP LABOR through ROI unless it comes through OTL');
6164 END IF;
6165
6166 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6167 rcv_error_pkg.set_error_message('RCV_NO_RATE_UNLESS_OTL', x_cascaded_table(n).error_message);
6168 rcv_error_pkg.set_token('TRX_TYPE', x_cascaded_table(n).transaction_type);
6169 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
6170 END IF; --}
6171 END IF; --}
6172
6173 /* Bug 6610047.
6174 * Changes made to allow receipts with zero amount for timecards
6175 * by commenting the validation to check for zero amount on the
6176 * receipt.
6177 */
6178
6179
6180 /* IF x_cascaded_table(n).error_status IN('S', 'W')
6181 AND x_cascaded_table(n).amount <= 0 THEN --{
6182 IF (g_asn_debug = 'Y') THEN
6183 asn_debug.put_line('Amount is <= zero. Cascade will fail');
6184 END IF;
6185
6186 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6187 rcv_error_pkg.set_error_message('RCV_ITEM_NO_SHIP_QTY', x_cascaded_table(n).error_message);
6188 rcv_error_pkg.set_token('ITEM', x_cascaded_table(n).item_num);
6189 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
6190 END IF; --} end amt > 0 check
6191 */
6192 -- the following steps will create a set of rows linking the line_record with
6193 -- its corresponding po_line_location rows until the quantity value from
6194 -- the asn is consumed. (Cascade)
6195
6196 /* 2119137 : If the user populates rcv_transactions_interface
6197 with po_line_id, then ROI errors out with
6198 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
6199 is not provided for one time items. Modified the "if" criteria in
6200 such a way that the ROI validation does'nt error out when
6201 po_line_id is populated for one time items. */
6202 x_progress := '098';
6203
6204 IF (g_asn_debug = 'Y') THEN
6205 asn_debug.put_line('X_progress ' || x_progress);
6206 END IF;
6207
6208 IF ( x_cascaded_table(n).po_line_id IS NOT NULL
6209 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
6210
6211 -- Copy record from main table to temp table
6212 IF (g_asn_debug = 'Y') THEN
6213 asn_debug.put_line('Copy record from main table to temp table');
6214 END IF;
6215
6216 current_n := 1;
6217 temp_cascaded_table(current_n) := x_cascaded_table(n);
6218
6219 -- Get all rows which meet this condition
6220 IF (g_asn_debug = 'Y') THEN
6221 asn_debug.put_line('Get all rows which meet this condition');
6222 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
6223 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
6224 END IF;
6225
6226 -- bug 1362237 Deriving the document_line_num
6227 -- and document_shipment_line_num when line_id and/or line_location_id
6228 -- are provided.
6229
6230 IF temp_cascaded_table(current_n).document_line_num IS NULL
6231 AND temp_cascaded_table(current_n).po_line_id IS NOT NULL THEN --{
6232 BEGIN
6233 SELECT line_num
6234 INTO temp_cascaded_table(current_n).document_line_num
6235 FROM po_lines
6236 WHERE po_line_id = temp_cascaded_table(current_n).po_line_id;
6237 EXCEPTION
6238 WHEN OTHERS THEN
6239 IF (g_asn_debug = 'Y') THEN
6240 asn_debug.put_line('wrong po_line_id entered in rcv_transactions_interface');
6241 END IF;
6242 END;
6243 END IF; --}
6244
6245 IF temp_cascaded_table(current_n).document_shipment_line_num IS NULL
6246 AND temp_cascaded_table(current_n).po_line_location_id IS NOT NULL THEN --{
6247 BEGIN
6248 SELECT shipment_num
6249 INTO temp_cascaded_table(current_n).document_shipment_line_num
6250 FROM po_line_locations
6251 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
6252 EXCEPTION
6253 WHEN OTHERS THEN
6254 IF (g_asn_debug = 'Y') THEN
6255 asn_debug.put_line('wrong po_line_location_id entered in rcv_transactions_interface');
6256 END IF;
6257 END;
6258 END IF; --}
6259
6260 IF temp_cascaded_table(current_n).document_distribution_num IS NULL
6261 AND temp_cascaded_table(current_n).po_distribution_id IS NOT NULL THEN --{
6262 BEGIN
6263 SELECT distribution_num
6264 INTO temp_cascaded_table(current_n).document_distribution_num
6265 FROM po_distributions
6266 WHERE po_distribution_id = temp_cascaded_table(current_n).po_distribution_id;
6267 EXCEPTION
6268 WHEN OTHERS THEN
6269 IF (g_asn_debug = 'Y') THEN
6270 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
6271 END IF;
6272 END;
6273 END IF; --}
6274
6275 /* Bug 1898283 : The Receiving control of "Enforce Ship to Location was
6276 not working for ROI. So corrected the code so that it now behaves the same way as
6277 the Form Behaves. i.e.,
6278 Proceed without any error messages if the enforcement is set to "None"
6279 Enter error message in po_interface_errors if the enforcement is "Warning"
6280 Enter error message in po_interface_errors if the enforcement is "Reject"
6281 and error out.
6282 This validation is done by comparing the enforce_ship_location_code from
6283 po_line_locations and assigning the proper ship_location_id into a
6284 temporary variable temp_mirror_ship_to_loc_id and passing the temp
6285 variable as a parameter to open the cursor "Distributions".
6286 */
6287 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
6288 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
6289
6290 -- if txn != deliver
6291 IF (g_asn_debug = 'Y') THEN
6292 asn_debug.put_line('Open Shipment records');
6293 asn_debug.put_line('PO Header id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_id));
6294 asn_debug.put_line('Item Id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_location_id));
6295 asn_debug.put_line('Proceed to open cursor');
6296 END IF;
6297
6298 /* Bug 2208664 : Nullified the ship_to_location_id when calling
6299 the cursors shipments, count_shipments, distributions and
6300 count_distributions. The proper value of ship_to_location_id will
6301 be set after values are fetched and validated for the
6302 location control code set at PO.
6303 */
6304 OPEN shipments(temp_cascaded_table(current_n).po_line_id,
6305 temp_cascaded_table(current_n).po_line_location_id,
6306 temp_cascaded_table(current_n).po_release_id
6307 );
6308 -- count_shipments just gets the count of rows found in shipments
6309 OPEN count_shipments(temp_cascaded_table(current_n).po_line_id,
6310 temp_cascaded_table(current_n).po_line_location_id,
6311 temp_cascaded_table(current_n).po_release_id
6312 );
6313 -- }
6314 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
6315 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
6316 IF (g_asn_debug = 'Y') THEN
6317 asn_debug.put_line('Open Distribution records');
6318 asn_debug.put_line('PO Line id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_id));
6319 asn_debug.put_line('Line location Id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_location_id));
6320 asn_debug.put_line('PO Distribution id ' || TO_CHAR(temp_cascaded_table(current_n).po_distribution_id));
6321 asn_debug.put_line('PO RElease id ' || TO_CHAR(temp_cascaded_table(current_n).po_release_id));
6322 asn_debug.put_line('Proceed to open cursor');
6323 END IF;
6324
6325 OPEN distributions(temp_cascaded_table(current_n).po_line_id,
6326 temp_cascaded_table(current_n).po_line_location_id,
6327 temp_cascaded_table(current_n).po_distribution_id,
6328 temp_cascaded_table(current_n).po_release_id
6329 );
6330 -- count_distributions just gets the count of rows found in distributions
6331 OPEN count_distributions(temp_cascaded_table(current_n).po_line_id,
6332 temp_cascaded_table(current_n).po_line_location_id,
6333 temp_cascaded_table(current_n).po_distribution_id,
6334 temp_cascaded_table(current_n).po_release_id
6335 );
6336 END IF; -- for txn = deliver --}
6337
6338
6339 -- Assign transaction amount to remaining amount
6340
6341 IF (g_asn_debug = 'Y') THEN
6342 asn_debug.put_line('Assign ordered_amount to remaining amount');
6343 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
6344 END IF;
6345
6346 x_remaining_amount := temp_cascaded_table(current_n).amount;
6347
6348 IF (g_asn_debug = 'Y') THEN
6349 asn_debug.put_line('Have assigned the amount ' || TO_CHAR(x_remaining_amount));
6350 END IF;
6351
6352 -- Calculate tax_amount_factor for calculating tax_amount for
6353 -- each cascaded line
6354 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
6355 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_amount;
6356 ELSE
6357 tax_amount_factor := 0;
6358 END IF;
6359
6360 IF (g_asn_debug = 'Y') THEN
6361 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
6362 END IF;
6363
6364 x_first_trans := TRUE;
6365 transaction_ok := FALSE;
6366
6367 /*
6368 ** Get the count of the number of records depending on the
6369 ** the transaction type
6370 */
6371 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
6372 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN
6373 FETCH count_shipments INTO x_record_count;
6374 ELSE
6375 FETCH count_distributions INTO x_record_count;
6376 END IF;
6377
6378 IF (g_asn_debug = 'Y') THEN
6379 asn_debug.put_line('Before starting Cascade');
6380 END IF;
6381
6382 IF (g_asn_debug = 'Y') THEN
6383 asn_debug.put_line('Record Count = ' || x_record_count);
6384 END IF;
6385
6386 asn_debug.put_line('record count ' || x_record_count);
6387
6388 LOOP --{
6389 IF (g_asn_debug = 'Y') THEN
6390 asn_debug.put_line('Remaining Amount ' || TO_CHAR(x_remaining_amount));
6391 END IF;
6392
6393 IF (g_asn_debug = 'Y') THEN
6394 asn_debug.put_line('open shipments and fetch');
6395 END IF;
6396
6397 /*
6398 ** Fetch the appropriate record
6399 */
6400 IF (g_asn_debug = 'Y') THEN
6401 asn_debug.put_line('transaction_type = ' || x_cascaded_table(n).transaction_type);
6402 END IF;
6403
6404 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
6405 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
6406 IF (g_asn_debug = 'Y') THEN
6407 asn_debug.put_line('Fetching Shipments Cursor');
6408 END IF;
6409
6410 FETCH shipments INTO x_shipmentdistributionrec;
6411
6412 /*
6413 ** Check if this is the last record
6414 */
6415 IF (shipments%NOTFOUND) THEN
6416 lastrecord := TRUE;
6417 END IF;
6418
6419 rows_fetched := shipments%ROWCOUNT;
6420
6421 IF (g_asn_debug = 'Y') THEN
6422 asn_debug.put_line('Shipment Rows fetched ' || TO_CHAR(rows_fetched));
6423 END IF;
6424 -- }
6425 ELSE -- txn = deliver and other cases --{
6426 IF (g_asn_debug = 'Y') THEN
6427 asn_debug.put_line('Fetching Distributions Cursor in amount proc');
6428 END IF;
6429
6430 FETCH distributions INTO x_shipmentdistributionrec;
6431
6432 /*
6433 ** Check if this is the last record
6434 */
6435 IF (distributions%NOTFOUND) THEN
6436 lastrecord := TRUE;
6437 END IF;
6438
6439 rows_fetched := distributions%ROWCOUNT;
6440
6441 IF (g_asn_debug = 'Y') THEN
6442 asn_debug.put_line('Distribution Rows fetched ' || TO_CHAR(rows_fetched));
6443 END IF;
6444 END IF; -- matches if condition of txn ! deliver --}
6445
6446 IF ( lastrecord
6447 OR x_remaining_amount <= 0) THEN --{
6448 IF (g_asn_debug = 'Y') THEN
6449 asn_debug.put_line('Hit exit condition');
6450 END IF;
6451
6452 IF NOT x_first_trans THEN
6453 -- x_first_trans has been reset which means some cascade has
6454 -- happened. Otherwise current_n = 1
6455 current_n := current_n - 1;
6456 END IF;
6457
6458 -- do the tolerance act here
6459 IF (g_asn_debug = 'Y') THEN
6460 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
6461 asn_debug.put_line('Check which condition has occured');
6462 END IF;
6463
6464 -- lastrecord...we have run out of rows and we still have quantity to allocate
6465 IF x_remaining_amount > 0 THEN --{
6466 IF (g_asn_debug = 'Y') THEN
6467 asn_debug.put_line('There is amount remaining');
6468 asn_debug.put_line('Need to check qty/amt tolerances');
6469 END IF;
6470
6471 IF rows_fetched > 0
6472 AND NOT x_first_trans THEN --{
6473 -- we had got atleast some rows from our shipments cursor
6474 -- we have atleast one row cascaded (not null line_location_id)
6475 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
6476 INTO x_qty_rcv_exception_code
6477 FROM po_line_locations
6478 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
6479
6480 IF (g_asn_debug = 'Y') THEN
6481 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
6482 END IF;
6483
6484 -- <Bug 9342280 : Added for CLM project>
6485 get_clm_info( 'AMOUNT',
6486 x_cascaded_table,
6487 n,
6488 l_is_clm_po,
6489 l_partial_funded_flag);
6490
6491 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
6492
6493 x_qty_rcv_exception_code := 'REJECT';
6494
6495 END IF;
6496 --<END CLM>
6497
6498 IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
6499 /* Bug# 1807842 */
6500 -- Bug 3506964.
6501 IF (temp_cascaded_table(current_n).amount < x_converted_trx_amt) THEN --{
6502 IF (g_asn_debug = 'Y') THEN
6503 asn_debug.put_line('Tolerable amount ' || TO_CHAR(x_converted_trx_amt));
6504 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).amount));
6505 asn_debug.put_line('Current shipped amount ' || TO_CHAR(temp_cascaded_table(current_n).amount_shipped));
6506 asn_debug.put_line('Assign remaining amount ' || TO_CHAR(x_remaining_amount) || ' to last record');
6507 END IF;
6508
6509 temp_cascaded_table(current_n).amount := temp_cascaded_table(current_n).amount + x_remaining_amount;
6510 temp_cascaded_table(current_n).amount_shipped := temp_cascaded_table(current_n).amount_shipped + x_remaining_amount;
6511
6512 END IF; /* Bug# 1807842 */ --}
6513
6514 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).amount * tax_amount_factor, 6);
6515
6516 IF (g_asn_debug = 'Y') THEN
6517 asn_debug.put_line('Current amount ' || TO_CHAR(temp_cascaded_table(current_n).amount));
6518 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
6519 asn_debug.put_line('Current shipped amount ' || TO_CHAR(temp_cascaded_table(current_n).amount_shipped));
6520 END IF;
6521
6522 IF x_qty_rcv_exception_code = 'WARNING' THEN --{
6523 IF (g_asn_debug = 'Y') THEN
6524 asn_debug.put_line('IN WARNING');
6525 END IF;
6526
6527 temp_cascaded_table(current_n).error_status := 'W';
6528 temp_cascaded_table(current_n).error_message := 'RCV_SHIP_QTY_OVER_TOLERANCE';
6529
6530 IF (g_asn_debug = 'Y') THEN
6531 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
6532 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
6533 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
6534 END IF;
6535
6536 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
6537 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
6538 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
6539 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_amount);
6540 rcv_error_pkg.log_interface_warning('QUANTITY');
6541
6542 IF (g_asn_debug = 'Y') THEN
6543 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
6544 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
6545 asn_debug.put_line('Need to insert into po_interface_errors');
6546 END IF;
6547 END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
6548
6549 IF (g_asn_debug = 'Y') THEN
6550 asn_debug.put_line('Current amount ' || TO_CHAR(temp_cascaded_table(current_n).amount));
6551 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
6552 asn_debug.put_line('Current shipped amount ' || TO_CHAR(temp_cascaded_table(current_n).amount_shipped));
6553 END IF;
6554 -- }
6555 ELSIF x_qty_rcv_exception_code = 'REJECT' THEN -- elseif for NONE/WARNING --{
6556 IF (g_asn_debug = 'Y') THEN
6557 asn_debug.put_line('Extra Amount ' || TO_CHAR(x_remaining_amount));
6558 END IF;
6559
6560 IF (g_asn_debug = 'Y') THEN
6561 asn_debug.put_line('delete the temp table ');
6562 END IF;
6563
6564 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6565
6566 -- <Bug 9342280 : Added for CLM project>
6567 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
6568
6569 rcv_error_pkg.set_error_message(
6570 'RCV_TRX_QTY_EXCEEDS_CLM_FUNDED',
6571 x_cascaded_table(n).error_message);
6572 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(n).amount);
6573 rcv_error_pkg.set_token('QTY_B', x_cascaded_table(n).amount - x_remaining_amount);
6574
6575 ELSE
6576 -- <CLM END>
6577
6578 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
6579 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(n).amount);
6580 rcv_error_pkg.set_token('QTY_B', x_cascaded_table(n).amount - x_remaining_amount);
6581
6582 END IF; -- <Bug 9342280 : Added for CLM project>
6583
6584 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
6585 temp_cascaded_table.DELETE;
6586
6587 IF (g_asn_debug = 'Y') THEN
6588 asn_debug.put_line('mark the actual table with error status');
6589 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
6590 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
6591 END IF;
6592
6593 IF (g_asn_debug = 'Y') THEN
6594 asn_debug.put_line('Need to insert a row into po_interface_errors');
6595 END IF;
6596 END IF; --} matches if(none/warning) and elseif(reject)
6597 --}
6598 ELSE --{ else for rows fetched = 0 OR x_first_trans = true
6599 IF rows_fetched = 0 THEN
6600 IF (g_asn_debug = 'Y') THEN
6601 asn_debug.put_line('No rows were retrieved from cursor.');
6602 END IF;
6603 ELSIF x_first_trans THEN
6604 IF (g_asn_debug = 'Y') THEN
6605 asn_debug.put_line('No rows were cascaded');
6606 END IF;
6607 END IF;
6608
6609 x_temp_count := 1;
6610
6611 /* nwang add error messages */
6612 /* Bug 2340533 - Added a message RCV_ASN_NO_OPEN_SHIPMENTS which conveys that
6613 no shipments exists for receiving for the given PO.
6614 */
6615 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
6616 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
6617 -- Bug 2551443 Removed po_distributions from the FROM clause
6618 SELECT COUNT(*)
6619 INTO x_temp_count
6620 FROM DUAL
6621 WHERE EXISTS(SELECT 1
6622 FROM po_line_locations pll,
6623 po_lines pl
6624 WHERE pl.po_line_id = temp_cascaded_table(current_n).po_line_id
6625 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
6626 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
6627 AND pll.po_line_id = pl.po_line_id);
6628
6629 IF x_temp_count = 0 THEN
6630 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6631 rcv_error_pkg.set_error_message('RCV_ASN_NO_OPEN_SHIPMENTS', x_cascaded_table(n).error_message);
6632 rcv_error_pkg.set_token('PONUM', temp_cascaded_table(current_n).document_num);
6633 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
6634 ELSE -- x_temp_count != 0
6635 SELECT NVL(pll.po_release_id, 0),
6636 NVL(pll.approved_flag, 'N'),
6637 NVL(pll.cancel_flag, 'N'),
6638 NVL(pll.closed_code, 'OPEN'),
6639 pll.shipment_type
6640 INTO x_release_id,
6641 x_approved_flag,
6642 x_cancel_flag,
6643 x_closed_code,
6644 x_shipment_type
6645 FROM po_line_locations pll,
6646 po_lines pl,
6647 po_headers ph
6648 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
6649 AND pll.po_header_id = ph.po_header_id
6650 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
6651 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
6652 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
6653 AND pll.po_line_id = pl.po_line_id;
6654 END IF; -- x_temp_count = 0
6655 -- }
6656 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
6657 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
6658 SELECT COUNT(*)
6659 INTO x_temp_count
6660 FROM po_distributions pod,
6661 po_line_locations pll,
6662 po_lines pl,
6663 po_headers ph
6664 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
6665 AND pll.po_header_id = ph.po_header_id
6666 AND pll.line_location_id = pod.line_location_id
6667 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
6668 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
6669 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
6670 AND pll.po_line_id = pl.po_line_id
6671 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
6672
6673 IF x_temp_count = 0 THEN
6674 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6675 rcv_error_pkg.set_error_message('RCV_ASN_INVALID_DIST_NUM', x_cascaded_table(n).error_message);
6676 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_distribution_num);
6677 rcv_error_pkg.log_interface_error('DOCUMENT_DISTRIBUTION_NUM', FALSE);
6678 ELSE -- x_temp_count != 0
6679 SELECT NVL(pll.po_release_id, 0),
6680 NVL(pll.approved_flag, 'N'),
6681 NVL(pll.cancel_flag, 'N'),
6682 NVL(pll.closed_code, 'OPEN'),
6683 pll.shipment_type
6684 INTO x_release_id,
6685 x_approved_flag,
6686 x_cancel_flag,
6687 x_closed_code,
6688 x_shipment_type
6689 FROM po_distributions pod,
6690 po_line_locations pll,
6691 po_lines pl,
6692 po_headers ph
6693 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
6694 AND pll.po_header_id = ph.po_header_id
6695 AND pll.line_location_id = pod.line_location_id
6696 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
6697 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
6698 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
6699 AND pll.po_line_id = pl.po_line_id
6700 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
6701 END IF; -- x_temp_count = 0;
6702 END IF; -- transaction_type <> 'DELIVER' --}
6703
6704 IF (x_temp_count <> 0) THEN --{
6705 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6706
6707 IF x_release_id <> NVL(temp_cascaded_table(current_n).po_release_id, x_release_id) THEN
6708 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6709 rcv_error_pkg.set_error_message('RCV_ASN_ITEM_NOT_ALLOWED', x_cascaded_table(n).error_message);
6710 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).item_num);
6711 rcv_error_pkg.log_interface_error('ITEM_NUM', FALSE);
6712 END IF;
6713
6714 IF x_approved_flag <> 'Y' THEN
6715 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6716 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_APPROVED', x_cascaded_table(n).error_message);
6717 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6718 rcv_error_pkg.set_token('PO_NUM', temp_cascaded_table(current_n).document_num);
6719 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6720 END IF;
6721
6722 IF x_cancel_flag <> 'N' THEN
6723 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6724 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_CANCELLED', x_cascaded_table(n).error_message);
6725 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6726 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6727 END IF;
6728
6729 IF ( x_include_closed_po = 'Y'
6730 AND x_closed_code = 'FINALLY CLOSED') THEN
6731 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6732 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_FINALLY_CLOSED', x_cascaded_table(n).error_message);
6733 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6734 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6735 END IF;
6736
6737 IF ( x_include_closed_po = 'N'
6738 AND x_closed_code IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING')) THEN
6739 IF (g_asn_debug = 'Y') THEN
6740 asn_debug.put_line('This PO is not open and the profile option to include closed POs is N');
6741 END IF;
6742
6743 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6744 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_OPEN', x_cascaded_table(n).error_message);
6745 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6746 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6747 END IF;
6748
6749 IF x_shipment_type NOT IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT') THEN
6750 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6751 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIPMT_TYPE', x_cascaded_table(n).error_message);
6752 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6753 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6754 END IF;
6755 END IF; -- x_temp_count = 0;}
6756
6757 -- Delete the temp_cascaded_table just to be sure
6758
6759 temp_cascaded_table.DELETE;
6760 END IF; --} end else for rows fetched = 0 OR x_first_trans = true
6761 -- end x_remaining_qty > 0 => this is the last record
6762 ELSE --
6763 IF (g_asn_debug = 'Y') THEN
6764 asn_debug.put_line('Remaining amount is zero ' || TO_CHAR(x_remaining_amount));
6765 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
6766 END IF;
6767 /* Bug 6610047.
6768 * To allow, receipts with zero amount for timecards from now on.
6769 * Added below code to populate certain data into temp_cascaded_table()
6770 * structure to make zero amount receipts flow to work.
6771 */
6772 IF (temp_cascaded_table(current_n).value_basis = 'RATE'
6773 AND temp_cascaded_table(current_n).purchase_basis = 'TEMP LABOR'
6774 AND temp_cascaded_table(current_n).amount = 0) THEN --{
6775
6776 IF (g_asn_debug = 'Y') THEN
6777 asn_debug.put_line('Rate/Temp Labor with amount = 0');
6778 END IF;
6779
6780 temp_cascaded_table(current_n).po_distribution_id := x_shipmentdistributionrec.po_distribution_id;
6781 temp_cascaded_table(current_n).charge_account_id := x_shipmentdistributionrec.code_combination_id;
6782 temp_cascaded_table(current_n).destination_type_code := x_shipmentdistributionrec.destination_type_code;
6783 temp_cascaded_table(current_n).destination_context := x_shipmentdistributionrec.destination_type_code;
6784
6785 IF (temp_cascaded_table(current_n).currency_conversion_date IS NULL) THEN
6786 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
6787 END IF;
6788
6789 IF (temp_cascaded_table(current_n).currency_conversion_rate IS NULL) THEN
6790 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
6791 END IF;
6792
6793 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
6794 temp_cascaded_table(current_n).deliver_to_location_id := x_shipmentdistributionrec.deliver_to_location_id;
6795 END IF;
6796
6797 END IF; /* Bug 6610047 - End */
6798
6799 END IF; --} ends the check for whether last record has been reached
6800
6801 -- close cursors
6802
6803 IF (g_asn_debug = 'Y') THEN
6804 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions');
6805 END IF;
6806
6807 IF shipments%ISOPEN THEN
6808 CLOSE shipments;
6809 END IF;
6810
6811 IF count_shipments%ISOPEN THEN
6812 CLOSE count_shipments;
6813 END IF;
6814
6815 IF distributions%ISOPEN THEN
6816 CLOSE distributions;
6817 END IF;
6818
6819 IF count_distributions%ISOPEN THEN
6820 CLOSE count_distributions;
6821 END IF;
6822
6823 EXIT;
6824 END IF; --} matches lastrecord or x_remaining_amount <= 0
6825
6826 -- eliminate the row if it fails the date check
6827
6828 IF (g_asn_debug = 'Y') THEN
6829 asn_debug.put_line('Count in temp_cascade_table : ' || TO_CHAR(temp_cascaded_table.COUNT));
6830 asn_debug.put_line('Cursor record ' || TO_CHAR(rows_fetched));
6831 asn_debug.put_line('Check date tolerance');
6832 END IF;
6833
6834 /* FPJ Services.
6835 * We do not check date_tolerances if matching_basis is
6836 * AMOUNT except when value basis is Fixed and
6837 * purchase basis is Service.
6838 * Bug 3570773. We did not have this check here but in
6839 * derive_vendor_rcv_line_qty. But it does not really matter since
6840 * we cannot set date tolerances for serive line types except
6841 * Fixed Price / Services.
6842 */
6843 IF ( NVL(x_cascaded_table(n).value_basis, 'QUANTITY') <> 'RATE'
6844 AND NVL(x_cascaded_table(n).purchase_basis, 'GOODS') <> 'TEMP_LABOR') THEN
6845 IF (g_asn_debug = 'Y') THEN
6846 asn_debug.put_line('Check date tolerance for a Fixed Price services line');
6847 END IF;
6848
6849 rcv_transactions_interface_sv.check_date_tolerance(NVL(temp_cascaded_table(1).expected_receipt_date, x_header_record.header_record.expected_receipt_date), -- Bug 487222
6850 x_shipmentdistributionrec.promised_date,
6851 x_shipmentdistributionrec.days_early_receipt_allowed,
6852 x_shipmentdistributionrec.days_late_receipt_allowed,
6853 x_shipmentdistributionrec.receipt_days_exception_code
6854 );
6855 ELSE
6856 -- default receipt_days_exception_code to NONE for rate based temp
6857 -- labor lines.
6858 x_shipmentdistributionrec.receipt_days_exception_code := 'NONE';
6859 END IF;
6860
6861 /* FPJ SERVICES END */
6862
6863 /* bug 1060261 - added error message to be shown when the expected date is outside tolerance range */
6864 IF (x_shipmentdistributionrec.receipt_days_exception_code = 'REJECT') THEN --{
6865 IF (g_asn_debug = 'Y') THEN
6866 asn_debug.put_line('Receipt days exception code is Reject. So error out.');
6867 END IF;
6868
6869 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6870 rcv_error_pkg.set_error_message('RCV_ASN_DATE_OUT_TOL', x_cascaded_table(n).error_message);
6871 rcv_error_pkg.set_token('DELIVERY DATE', NVL(temp_cascaded_table(1).expected_receipt_date, x_header_record.header_record.expected_receipt_date));
6872 rcv_error_pkg.log_interface_error('EXPECTED_RECEIPT_DATE', FALSE);
6873 END IF; --}
6874
6875 IF (g_asn_debug = 'Y') THEN
6876 asn_debug.put_line('Days exception Code ' || NVL(x_shipmentdistributionrec.receipt_days_exception_code, 'XXX'));
6877 END IF;
6878
6879 -- Check shipto_location enforcement
6880
6881 rcv_transactions_interface_sv.check_shipto_enforcement(x_shipmentdistributionrec.ship_to_location_id,
6882 NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id),
6883 x_shipmentdistributionrec.enforce_ship_to_location_code
6884 );
6885
6886 IF (g_asn_debug = 'Y') THEN
6887 asn_debug.put_line('Enforce ShipToLocation ' || NVL(x_shipmentdistributionrec.enforce_ship_to_location_code, 'XXX'));
6888 END IF;
6889
6890 /* Bug 2208664 : Enter error message in po_interface_errors if enforce_ship_to_location_code is 'WARNING', and
6891 Enter error message in po_interface_errors if enforce_ship_to_location_code is 'REJECT' and error out
6892 */
6893 IF (x_shipmentdistributionrec.enforce_ship_to_location_code = 'REJECT') THEN --{
6894 BEGIN
6895 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6896 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
6897 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
6898 rcv_error_pkg.log_interface_error('SHIP_TO_LOCATION_ID', FALSE);
6899 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
6900 END;
6901 ELSIF(x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING') THEN --} {
6902 BEGIN
6903 x_cascaded_table(n).error_status := 'W';
6904 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
6905 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
6906 rcv_error_pkg.log_interface_warning('SHIP_TO_LOCATION_ID');
6907 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
6908 END;
6909 END IF; --}matches ship_to_loc_code = warning
6910
6911 IF (NVL(x_shipmentdistributionrec.receipt_days_exception_code, 'NONE') = 'NONE')
6912 AND -- derived by the date tolerance procedure
6913 (x_shipmentdistributionrec.enforce_ship_to_location_code IN('NONE', 'WARNING')) THEN --{
6914 -- derived by shipto_enforcement
6915 insert_into_table := FALSE;
6916 already_allocated_amt := 0;
6917
6918 /*
6919 ** Get the available quantity for the shipment or distribution
6920 ** that is available for allocation by this interface transaction
6921 */
6922 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
6923 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
6924 /*Bug# 1548597 */
6925 IF (g_asn_debug = 'Y') THEN
6926 asn_debug.put_line('call get_available_amount for Receive');
6927 END IF;
6928
6929 rcv_quantities_s.get_available_amount('RECEIVE',
6930 x_shipmentdistributionrec.line_location_id,
6931 'VENDOR',
6932 NULL,
6933 NULL,
6934 NULL,
6935 x_converted_trx_amt,
6936 x_tolerable_amt
6937 );
6938
6939 -- If qtys have already been allocated for this po_line_location_id during
6940 -- a cascade process which has not been written to the db yet, we need to
6941 -- decrement it from the total available quantity
6942 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
6943 -- po_line_location_id
6944
6945 IF n > 1 THEN -- We will do this for all rows except the 1st
6946 FOR i IN 1 ..(n - 1) LOOP
6947 IF x_cascaded_table(i).po_line_location_id = x_shipmentdistributionrec.line_location_id THEN
6948 already_allocated_amt := already_allocated_amt + x_cascaded_table(i).amount;
6949 END IF;
6950 END LOOP;
6951 END IF;
6952 ELSE --} { for txn != deliver
6953 IF (g_asn_debug = 'Y') THEN
6954 asn_debug.put_line('call get_available_amount for Direct Delivery');
6955 END IF;
6956
6957 /* Bug# 1548597*/
6958 rcv_quantities_s.get_available_amount('DIRECT RECEIPT',
6959 x_shipmentdistributionrec.po_distribution_id,
6960 'VENDOR',
6961 NULL,
6962 NULL,
6963 NULL,
6964 x_converted_trx_amt,
6965 x_tolerable_amt
6966 );
6967
6968 /* Bug# 1337787 - Calculated the x_tolerable_qty in
6969 rcv_quantities_s.get_available_quantity procedure */
6970
6971 -- x_tolerable_qty := x_converted_trx_qty;
6972 -- If qtys have already been allocated for this po_distribution_id during
6973 -- a cascade process which has not been written to the db yet, we need to
6974 -- decrement it from the total available quantity
6975 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
6976 -- po_distribution_id
6977
6978 IF n > 1 THEN -- We will do this for all rows except the 1st
6979 FOR i IN 1 ..(n - 1) LOOP
6980 IF x_cascaded_table(i).po_distribution_id = x_shipmentdistributionrec.po_distribution_id THEN
6981 already_allocated_amt := already_allocated_amt + x_cascaded_table(i).amount;
6982 END IF;
6983 END LOOP;
6984 END IF;
6985 END IF; --} for txn =deliver
6986
6987 IF (g_asn_debug = 'Y') THEN
6988 asn_debug.put_line('After call to get_available quantity');
6989 asn_debug.put_line('Available Amount ' || TO_CHAR(x_converted_trx_amt));
6990 asn_debug.put_line('Tolerable Amount ' || TO_CHAR(x_tolerable_amt));
6991 asn_debug.put_line('Already Shipped amount ' || TO_CHAR(NVL(x_shipmentdistributionrec.amount_shipped, 0)));
6992 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
6993 END IF;
6994
6995 -- if amt has already been allocated then reduce available and tolerable
6996 -- amt by the allocated amount
6997
6998 IF NVL(already_allocated_amt, 0) > 0 THEN --{
6999 x_converted_trx_amt := x_converted_trx_amt - already_allocated_amt;
7000 x_tolerable_amt := x_tolerable_amt - already_allocated_amt;
7001
7002 IF x_converted_trx_amt < 0 THEN
7003 x_converted_trx_amt := 0;
7004 END IF;
7005
7006 IF x_tolerable_amt < 0 THEN
7007 x_tolerable_amt := 0;
7008 END IF;
7009
7010 IF (g_asn_debug = 'Y') THEN
7011 asn_debug.put_line('Have some allocated amount. Will reduce amt');
7012 asn_debug.put_line('Allocated Amt ' || TO_CHAR(already_allocated_amt));
7013 asn_debug.put_line('After reducing by allocated amt');
7014 asn_debug.put_line('Available Amount ' || TO_CHAR(x_converted_trx_amt));
7015 asn_debug.put_line('Tolerable Amount ' || TO_CHAR(x_tolerable_amt));
7016 asn_debug.put_line('Already Shipped amount ' || TO_CHAR(NVL(x_shipmentdistributionrec.amount_shipped, 0)));
7017 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
7018 END IF;
7019 END IF; --}
7020
7021 -- If last row set available = tolerable - shipped
7022 -- else = available - shipped
7023
7024 IF rows_fetched = x_record_count THEN --{
7025 x_converted_trx_amt := x_tolerable_amt;
7026 x_converted_trx_amt := x_tolerable_amt - NVL(x_shipmentdistributionrec.amount_shipped, 0);
7027
7028 IF (g_asn_debug = 'Y') THEN
7029 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_trx_amt));
7030 END IF;
7031 ELSE --} {
7032 IF (g_asn_debug = 'Y') THEN
7033 x_converted_trx_amt := x_converted_trx_amt - NVL(x_shipmentdistributionrec.amount_shipped, 0);
7034 asn_debug.put_line('Not Last Row : ' || TO_CHAR(x_converted_trx_amt));
7035 END IF;
7036 END IF; --}
7037
7038 IF x_converted_trx_amt > 0 THEN --{
7039 IF (x_converted_trx_amt < x_remaining_amount) THEN -- compare like uoms {
7040 IF (g_asn_debug = 'Y') THEN
7041 asn_debug.put_line('We are in > amt branch');
7042 END IF;
7043
7044 x_remaining_amount := x_remaining_amount - x_converted_trx_amt;
7045 insert_into_table := TRUE;
7046 ELSE --} {
7047 IF (g_asn_debug = 'Y') THEN
7048 asn_debug.put_line('We are in <= amt branch ');
7049 END IF;
7050
7051 x_converted_trx_amt := x_remaining_amount;
7052 insert_into_table := TRUE;
7053 x_remaining_amount := 0;
7054 END IF; --}
7055 ELSE -- no amt for this record but if last row we need it } {
7056 IF rows_fetched = x_record_count THEN --{ last row needs to be inserted anyway
7057 -- so that the row can be used based on qty tolerance checks
7058 IF (g_asn_debug = 'Y') THEN
7059 asn_debug.put_line('Amount is less then 0 but last record');
7060 END IF;
7061
7062 insert_into_table := TRUE;
7063 x_converted_trx_amt := 0;
7064 ELSE --} {
7065 IF (g_asn_debug = 'Y') THEN
7066 asn_debug.put_line('<= 0 amount but more records in cursor');
7067 END IF;
7068
7069 x_remaining_amount := 0;
7070
7071 IF (g_asn_debug = 'Y') THEN
7072 asn_debug.put_line('We have to deal with remaining_qty > 0 and x_converted_trx_qty -ve');
7073 END IF;
7074
7075 insert_into_table := FALSE;
7076 END IF; --}
7077 END IF; --} remaining_amount <> 0
7078
7079 IF insert_into_table THEN --{
7080 IF (x_first_trans) THEN --{
7081 IF (g_asn_debug = 'Y') THEN
7082 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
7083 END IF;
7084
7085 x_first_trans := FALSE;
7086 ELSE --} { ! x_first_trans
7087 IF (g_asn_debug = 'Y') THEN
7088 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
7089 END IF;
7090
7091 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
7092 END IF; --} matches x_first_transfer
7093
7094 temp_cascaded_table(current_n).amount_shipped := temp_cascaded_table(current_n).amount;
7095 temp_cascaded_table(current_n).inspection_status_code := 'NOT INSPECTED';
7096 temp_cascaded_table(current_n).interface_source_code := NVL(temp_cascaded_table(current_n).interface_source_code,'RCV'); -- Bug 10127806
7097 temp_cascaded_table(current_n).currency_code := x_shipmentdistributionrec.currency_code;
7098 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).amount * tax_amount_factor, 6);
7099
7100 IF (g_asn_debug = 'Y') THEN
7101 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
7102 END IF;
7103
7104 IF temp_cascaded_table(current_n).to_organization_id IS NULL THEN --{
7105 temp_cascaded_table(current_n).to_organization_id := x_shipmentdistributionrec.ship_to_organization_id;
7106 END IF; --}
7107
7108 temp_cascaded_table(current_n).po_line_id := x_shipmentdistributionrec.po_line_id;
7109 temp_cascaded_table(current_n).po_line_location_id := x_shipmentdistributionrec.line_location_id;
7110
7111 IF x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING' THEN --{
7112 IF (g_asn_debug = 'Y') THEN
7113 asn_debug.put_line('Message to warn about different shiptolocations');
7114 END IF;
7115 END IF; --}
7116
7117 /* ksareddy - 2329928 Ported changes by bao in branch to cache set_of_books_id */
7118 IF (rcv_transactions_interface_sv.x_set_of_books_id IS NULL) THEN
7119 SELECT set_of_books_id
7120 INTO rcv_transactions_interface_sv.x_set_of_books_id
7121 FROM financials_system_parameters;
7122 END IF;
7123
7124 x_sob_id := rcv_transactions_interface_sv.x_set_of_books_id;
7125 /* Bug 1845702
7126 * Currency rate and date can be changed at the time of receipt
7127 * depending on the profile ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE.
7128 * This was not handled in the open interface. Introduced code
7129 * to handle the changes at the time of receipt
7130 */
7131 /* Bug#3746516 Added the following if condition so as to get the value of the profile
7132 ** option only when the match option is receipt and thus to avoid executing the below
7133 ** function call always.
7134 */
7135 IF (x_ShipmentDistributionRec.match_option = 'R') THEN
7136 x_allow_rate_override := NVL(fnd_profile.value('ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE'), 'N');
7137 END IF;
7138
7139 IF (g_asn_debug = 'Y') THEN
7140 asn_debug.put_line('Match Option:' || x_ShipmentDistributionRec.match_option ||
7141 'Profile value ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE:' ||
7142 x_allow_rate_override);
7143 END IF;
7144
7145 /* Bug#3746516 - START
7146 ** Modified the following code to consider all the possble scenarios such that the
7147 ** rate and the rate date values will be derived correctly and the correct rate and
7148 ** rate date values will now be posted in rcv_transactions table so that there will
7149 ** not be any discrepency in the calculations and hence all the data between the two
7150 ** tables rcv_transactions and rcv_receiving_sub_ledger will be in sync.
7151 ** Assuming that only Direct delivery of Amount Based lines are possible and
7152 ** x_ShipmentDistributionRec would thus have only distribution information. */
7153
7154 IF (x_ShipmentDistributionRec.match_option = 'P') THEN --{
7155
7156 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
7157 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
7158
7159 /* Bug 13013727 Modified the following code to handle the cases where Match Option is 'Receipt'.
7160 The Rate Date needs to be defaulted from Transaction Date for such cases, and NOT from PO_DISTRIBUTIONS.
7161 Also, the corresponding Rate needs to be calculated in case of Rate Type <> 'User'. */
7162 ELSIF (x_ShipmentDistributionRec.match_option = 'R') THEN
7163
7164 IF (x_ShipmentDistributionRec.rate_type = 'User') THEN --{
7165
7166 IF ( x_allow_rate_override ='N') THEN --{
7167
7168 temp_cascaded_table(current_n).currency_conversion_date :=
7169 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_cascaded_table(n).transaction_date);
7170 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
7171
7172 ELSIF ( x_allow_rate_override ='Y') THEN
7173
7174 temp_cascaded_table(current_n).currency_conversion_date :=
7175 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_cascaded_table(n).transaction_date);
7176 temp_cascaded_table(current_n).currency_conversion_rate :=
7177 nvl(temp_cascaded_table(current_n).currency_conversion_rate,x_ShipmentDistributionRec.rate);
7178 END IF; --}
7179
7180 ELSE
7181
7182 IF ( temp_cascaded_table(current_n).currency_conversion_date IS NOT NULL ) THEN --{
7183 /* Bug 13013727 Calculating the corresponding Rate here. Modified code to handle the exception and log a
7184 message into the log file if there is no Rate defined for the particular Rate Date and Rate Type */
7185 BEGIN
7186 x_rate := gl_currency_api.get_rate(x_sob_Id,
7187 x_ShipmentDistributionRec.currency_code,
7188 temp_cascaded_table(current_n).currency_conversion_date,
7189 x_ShipmentDistributionRec.rate_type);
7190 x_rate := round(x_rate,28);
7191 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
7192 EXCEPTION
7193 WHEN OTHERS THEN
7194 IF (g_asn_debug = 'Y') THEN
7195 asn_debug.put_line('Exception 3 ::'||SQLERRM||':: occurred while deriving the rate for currency_conversion_date : '||temp_cascaded_table(current_n).currency_conversion_date
7196 ||' for the rate type : '||x_ShipmentDistributionRec.rate_type);
7197 asn_debug.put_line('The rate returned is : '||temp_cascaded_table(current_n).currency_conversion_rate);
7198 END IF;
7199 RAISE;
7200 END;
7201 ELSE
7202 /* Bug 13013727 Calculating the corresponding Rate here. Modified code to handle the exception and log a
7203 message into the log file if there is no Rate defined for the particular Rate Date and Rate Type */
7204 BEGIN
7205 temp_cascaded_table(current_n).currency_conversion_date := x_cascaded_table(n).transaction_date;
7206 x_rate := gl_currency_api.get_rate(x_sob_Id,
7207 x_ShipmentDistributionRec.currency_code,
7208 temp_cascaded_table(current_n).currency_conversion_date,
7209 x_ShipmentDistributionRec.rate_type);
7210 x_rate := round(x_rate,28);
7211 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
7212 EXCEPTION
7213 WHEN OTHERS THEN
7214 IF (g_asn_debug = 'Y') THEN
7215 asn_debug.put_line('Exception 4 ::'||SQLERRM||':: occurred while deriving the rate for currency_conversion_date : '||temp_cascaded_table(current_n).currency_conversion_date
7216 ||' for the rate type : '||x_ShipmentDistributionRec.rate_type);
7217 asn_debug.put_line('The rate returned is : '||temp_cascaded_table(current_n).currency_conversion_rate);
7218 END IF;
7219 RAISE;
7220 END;
7221 END IF; --}
7222
7223 END IF; --}
7224
7225 END IF; --}
7226 /* End of fix for Bug 13013727 */
7227
7228 temp_cascaded_table(current_n).currency_conversion_type := x_ShipmentDistributionRec.rate_type;
7229
7230 IF (g_asn_debug = 'Y') THEN
7231 asn_debug.put_line('Rate, Rate type and Rate_date ::' ||
7232 temp_cascaded_table(current_n).currency_conversion_rate ||
7233 '::' || temp_cascaded_table(current_n).currency_conversion_type ||
7234 '::' || temp_cascaded_table(current_n).currency_conversion_date);
7235 END IF;
7236
7237 /* Bug#3746516 - END */
7238
7239 -- Copy the distribution specific information only if this is a direct receipt.
7240
7241 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7242 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
7243 temp_cascaded_table(current_n).po_distribution_id := x_shipmentdistributionrec.po_distribution_id;
7244 temp_cascaded_table(current_n).charge_account_id := x_shipmentdistributionrec.code_combination_id;
7245 temp_cascaded_table(current_n).req_distribution_id := x_shipmentdistributionrec.req_distribution_id;
7246 temp_cascaded_table(current_n).destination_type_code := x_shipmentdistributionrec.destination_type_code;
7247 temp_cascaded_table(current_n).destination_context := x_shipmentdistributionrec.destination_type_code;
7248
7249 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
7250 temp_cascaded_table(current_n).deliver_to_location_id := x_shipmentdistributionrec.deliver_to_location_id;
7251 END IF;
7252
7253 /* Bug 2392074 - If the deliver_to_person mentioned in the po_distributions is
7254 invalid or inactive at the time of Receipt we need to clear the deliver to person,
7255 as this is an optional field. */
7256 IF (NVL(temp_cascaded_table(current_n).deliver_to_person_id, 0) = 0) THEN --{
7257 temp_cascaded_table(current_n).deliver_to_person_id := x_shipmentdistributionrec.deliver_to_person_id;
7258
7259 IF (temp_cascaded_table(current_n).deliver_to_person_id IS NOT NULL) THEN --{
7260 BEGIN
7261 SELECT NVL(MAX(hre.full_name), 'notfound')
7262 INTO x_full_name
7263 FROM hr_employees_current_v hre
7264 WHERE ( hre.inactive_date IS NULL
7265 OR hre.inactive_date > SYSDATE)
7266 AND hre.employee_id = temp_cascaded_table(current_n).deliver_to_person_id;
7267
7268 IF (x_full_name = 'notfound') THEN
7269 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
7270 END IF;
7271 EXCEPTION
7272 WHEN NO_DATA_FOUND THEN
7273 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
7274
7275 IF (g_asn_debug = 'Y') THEN
7276 asn_debug.put_line('The deliver to person entered in PO is currently inactive');
7277 asn_debug.put_line(' So it is cleared off');
7278 END IF;
7279 WHEN OTHERS THEN
7280 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
7281
7282 IF (g_asn_debug = 'Y') THEN
7283 asn_debug.put_line('Some exception has occured');
7284 asn_debug.put_line('This exception is due to the PO deliver to person');
7285 asn_debug.put_line('The deliver to person is optional');
7286 asn_debug.put_line('So cleared off the deliver to person');
7287 END IF;
7288 END;
7289 END IF; --}
7290 END IF; --}
7291
7292 -- bug 1361786
7293
7294 IF (temp_cascaded_table(current_n).ussgl_transaction_code IS NULL) THEN
7295 temp_cascaded_table(current_n).ussgl_transaction_code := x_shipmentdistributionrec.ussgl_transaction_code;
7296 END IF;
7297 END IF; --} matches txn != deliver
7298
7299 current_n := current_n + 1;
7300
7301 IF (g_asn_debug = 'Y') THEN
7302 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
7303 END IF;
7304 END IF; --} matches if insert into table
7305 END IF; --} matches shipmentdistributionrec.receipt_days_exception_code = none
7306 END LOOP; --}
7307 ELSE --} {
7308 -- error_status and error_message are set after validate_quantity_shipped
7309 IF (g_asn_debug = 'Y') THEN
7310 asn_debug.put_line('No po_header_id/item_id ');
7311 END IF;
7312
7313 IF (g_asn_debug = 'Y') THEN
7314 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
7315 END IF;
7316
7317 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
7318 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
7319 rcv_error_pkg.set_error_message('RCV_ASN_NO_PO_LINE_LOCATION_ID', x_cascaded_table(n).error_message);
7320 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
7321 END IF; --}
7322
7323 RETURN;
7324 END IF; -- } of (asn quantity_shipped was valid)
7325
7326 IF shipments%ISOPEN THEN
7327 CLOSE shipments;
7328 END IF;
7329
7330 IF count_shipments%ISOPEN THEN
7331 CLOSE count_shipments;
7332 END IF;
7333
7334 IF distributions%ISOPEN THEN
7335 CLOSE distributions;
7336 END IF;
7337
7338 IF count_distributions%ISOPEN THEN
7339 CLOSE count_distributions;
7340 END IF;
7341
7342 IF (g_asn_debug = 'Y') THEN
7343 asn_debug.put_line('Exit derive_vendor_rcv_line_amt');
7344 END IF;
7345 EXCEPTION
7346 WHEN OTHERS THEN
7347 IF (g_asn_debug = 'Y') THEN
7348 asn_debug.put_line('Exception in derive_vendor_rcv_line_amt');
7349 END IF;
7350
7351 IF shipments%ISOPEN THEN
7352 CLOSE shipments;
7353 END IF;
7354
7355 IF count_shipments%ISOPEN THEN
7356 CLOSE count_shipments;
7357 END IF;
7358
7359 IF distributions%ISOPEN THEN
7360 CLOSE distributions;
7361 END IF;
7362
7363 IF count_distributions%ISOPEN THEN
7364 CLOSE count_distributions;
7365 END IF;
7366
7367 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
7368 rcv_error_pkg.set_sql_error_message('derive_vendor_rcv_line_qty', x_progress);
7369 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7370 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
7371
7372 IF (g_asn_debug = 'Y') THEN
7373 asn_debug.put_line(TO_CHAR(n));
7374 asn_debug.put_line(SQLERRM);
7375 asn_debug.put_line('error ' || x_progress);
7376 END IF;
7377 END derive_vendor_rcv_line_amt;
7378
7379 PROCEDURE validate_transaction_date(
7380 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7381 n IN BINARY_INTEGER
7382 ) IS
7383 x_val_open_ok BOOLEAN := NULL;
7384 x_sob_id NUMBER := NULL;
7385 x_error_status VARCHAR2(1);
7386 x_creation_date DATE;
7387 x_shipped_date DATE;
7388
7389 BEGIN
7390 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7391 RETURN;
7392 END IF;
7393
7394 x_error_status := rcv_error_pkg.g_ret_sts_error;
7395
7396 /*Bug 2327318 Implemented the validation Transaction date should not be greater than
7397 sysdate */
7398 IF (x_cascaded_table(n).transaction_date > SYSDATE) THEN
7399 rcv_error_pkg.set_error_message('RCV_TRX_FUTURE_DATE_NA');
7400 RAISE e_validation_error;
7401 END IF;
7402
7403 /*Bug 6141065: Start: Implemented the validation, Transaction date should not
7404 pre-date the creation_date or shippped_date in rcv_shipment_headers */
7405 IF (x_cascaded_table(n).shipment_num IS NOT NULL AND
7406 x_cascaded_table(n).to_organization_id IS NOT NULL AND
7407 x_cascaded_table(n).transaction_date IS NOT NULL) THEN
7408
7409 IF (g_asn_debug = 'Y') THEN
7410 asn_debug.put_line('Shipment Num ' || x_cascaded_table(n).shipment_num);
7411 asn_debug.put_line('To Organization ID ' || x_cascaded_table(n).to_organization_id);
7412 asn_debug.put_line('Transaction Date ' || x_cascaded_table(n).transaction_date);
7413 END IF;
7414
7415 BEGIN
7416 SELECT creation_date, shipped_date
7417 INTO x_creation_date, x_shipped_date
7418 FROM rcv_shipment_headers
7419 WHERE shipment_num = x_cascaded_table(n).shipment_num
7420 AND ship_to_org_id = x_cascaded_table(n).to_organization_id;
7421
7422 IF (g_asn_debug = 'Y') THEN
7423 asn_debug.put_line('Creation Date ' || x_creation_date);
7424 asn_debug.put_line('Shipped Date ' || x_shipped_date);
7425 END IF;
7426
7427
7428 IF ( -- x_cascaded_table(n).transaction_date < x_creation_date OR
7429 -- Bug 8899155 receipt date can be less than receipt's creation date
7430 x_cascaded_table(n).transaction_date < x_shipped_date) THEN
7431 rcv_error_pkg.set_error_message('RCV_TRX_DATE_GT_SHIP_DATE');
7432 RAISE e_validation_error;
7433 END IF;
7434
7435 EXCEPTION
7436 WHEN NO_DATA_FOUND THEN
7437 NULL;
7438 IF (g_asn_debug = 'Y') THEN
7439 asn_debug.put_line('No Shipment Header exists');
7440 END IF;
7441 END;
7442 END IF;
7443 /* Bug 6141065: End */
7444
7445 /* Bug 2653229 - To check if the transaction date falls in the open period only
7446 when the auto transact code is not SHIP. */
7447 IF (x_cascaded_table(n).auto_transact_code <> 'SHIP') THEN --{
7448 /* Bug# 2379848 - We were only checking for GL and PO periods
7449 and not for INV periods. Also we were displaying the same
7450 error message always */
7451 BEGIN
7452 SELECT set_of_books_id
7453 INTO x_sob_id
7454 FROM financials_system_parameters;
7455 EXCEPTION
7456 WHEN NO_DATA_FOUND THEN
7457 NULL;
7458
7459 IF (g_asn_debug = 'Y') THEN
7460 asn_debug.put_line('Set of books id not defined');
7461 END IF;
7462 END;
7463
7464 BEGIN
7465 x_val_open_ok := po_dates_s.val_open_period(x_cascaded_table(n).transaction_date,
7466 x_sob_id,
7467 'SQLGL',
7468 x_cascaded_table(n).to_organization_id
7469 );
7470 EXCEPTION
7471 WHEN OTHERS THEN
7472 IF (g_asn_debug = 'Y') THEN
7473 asn_debug.put_line('Exception in val_open_period');
7474 END IF;
7475
7476 x_val_open_ok := FALSE;
7477 END;
7478
7479 IF NOT(x_val_open_ok) THEN --{
7480 rcv_error_pkg.set_error_message('PO_CNL_NO_PERIOD');
7481 RAISE e_validation_error;
7482 END IF; --}
7483
7484 BEGIN
7485 x_val_open_ok := po_dates_s.val_open_period(x_cascaded_table(n).transaction_date,
7486 x_sob_id,
7487 'INV',
7488 x_cascaded_table(n).to_organization_id
7489 );
7490 EXCEPTION
7491 WHEN OTHERS THEN
7492 IF (g_asn_debug = 'Y') THEN
7493 asn_debug.put_line('Exception in val_open_period of trx_date');
7494 END IF;
7495
7496 x_val_open_ok := FALSE;
7497 END;
7498
7499 IF NOT(x_val_open_ok) THEN --{
7500 rcv_error_pkg.set_error_message('PO_INV_NO_OPEN_PERIOD');
7501 RAISE e_validation_error;
7502 END IF; --}
7503
7504 BEGIN
7505 x_val_open_ok := po_dates_s.val_open_period(x_cascaded_table(n).transaction_date,
7506 x_sob_id,
7507 'PO',
7508 x_cascaded_table(n).to_organization_id
7509 );
7510 EXCEPTION
7511 WHEN OTHERS THEN
7512 x_val_open_ok := FALSE;
7513
7514 IF (g_asn_debug = 'Y') THEN
7515 asn_debug.put_line('Exception in val_open_period of gl_date');
7516 END IF;
7517 END;
7518
7519 IF NOT(x_val_open_ok) THEN --{
7520 rcv_error_pkg.set_error_message('PO_PO_ENTER_OPEN_GL_DATE');
7521 RAISE e_validation_error;
7522 END IF; --} /* End of Bug# 2379848 */
7523 END IF; --} auto transact code = SHIP
7524 EXCEPTION
7525 WHEN e_validation_error THEN
7526 x_cascaded_table(n).error_status := x_error_status;
7527 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7528 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7529 'TRANSACTION_DATE',
7530 FALSE
7531 );
7532 END validate_transaction_date;
7533
7534 PROCEDURE validate_quantity_invoiced(
7535 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7536 n IN BINARY_INTEGER
7537 ) IS
7538 quantity_invoiced_record rcv_shipment_line_sv.quantity_invoiced_record_type;
7539 BEGIN
7540 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7541 RETURN;
7542 END IF;
7543
7544 quantity_invoiced_record.quantity_invoiced := x_cascaded_table(n).quantity_invoiced;
7545 quantity_invoiced_record.error_record.error_status := 'S';
7546 quantity_invoiced_record.error_record.error_message := NULL;
7547 rcv_transactions_interface_sv1.validate_quantity_invoiced(quantity_invoiced_record);
7548 x_cascaded_table(n).error_status := quantity_invoiced_record.error_record.error_status;
7549 x_cascaded_table(n).error_message := quantity_invoiced_record.error_record.error_message;
7550 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7551 'UNIT_OF_MEASURE',
7552 FALSE
7553 );
7554 END validate_quantity_invoiced;
7555
7556 PROCEDURE validate_transaction_uom(
7557 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7558 n IN BINARY_INTEGER
7559 ) IS
7560 uom_record rcv_shipment_line_sv.quantity_shipped_record_type;
7561 BEGIN
7562 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7563 RETURN;
7564 END IF;
7565
7566 IF (g_asn_debug = 'Y') THEN
7567 asn_debug.put_line('Before call to validate UOM');
7568 asn_debug.put_line('Quantity ' || TO_CHAR(x_cascaded_table(n).quantity));
7569 asn_debug.put_line('unit_of_measure ' || x_cascaded_table(n).unit_of_measure);
7570 END IF;
7571
7572 uom_record.quantity_shipped := x_cascaded_table(n).quantity;
7573 uom_record.unit_of_measure := x_cascaded_table(n).unit_of_measure;
7574 uom_record.item_id := x_cascaded_table(n).item_id;
7575 uom_record.po_line_id := x_cascaded_table(n).po_line_id;
7576 uom_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7577 uom_record.po_header_id := x_cascaded_table(n).po_header_id;
7578 uom_record.primary_unit_of_measure := x_cascaded_table(n).primary_unit_of_measure;
7579 uom_record.error_record.error_status := 'S';
7580 uom_record.error_record.error_message := NULL;
7581
7582 IF (g_asn_debug = 'Y') THEN
7583 asn_debug.put_line('Validating UOM');
7584 END IF;
7585
7586 rcv_transactions_interface_sv1.validate_uom(uom_record);
7587 x_cascaded_table(n).error_status := uom_record.error_record.error_status;
7588 x_cascaded_table(n).error_message := uom_record.error_record.error_message;
7589 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7590 'UNIT_OF_MEASURE',
7591 FALSE
7592 );
7593 END validate_transaction_uom;
7594
7595 PROCEDURE validate_item_info(
7596 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7597 n IN BINARY_INTEGER
7598 ) IS
7599 item_revision_record rcv_shipment_line_sv.item_id_record_type;
7600 sub_item_id_record rcv_shipment_line_sv.sub_item_id_record_type;
7601 item_id_record rcv_shipment_line_sv.item_id_record_type;
7602 l_asn_sub_item_txn varchar2(1); --Bug: 5598511
7603 l_pol_item_id po_lines_all.item_id%type; --Bug: 5598511
7604 BEGIN
7605 -- validate item id
7606 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7607 RETURN;
7608 END IF;
7609
7610 IF (g_asn_debug = 'Y') THEN
7611 asn_debug.put_line('Validating Item');
7612 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).item_id));
7613 END IF;
7614
7615 /*
7616 ** If this is a one time item shipment and you've matched up based on a
7617 ** document line num then skip the processing based on setting the validation
7618 ** for the item to be the same as what is set on the line.
7619 */
7620 IF ( x_cascaded_table(n).item_id IS NULL
7621 AND x_cascaded_table(n).po_line_id IS NOT NULL) THEN --{
7622 item_id_record.error_record.error_status := x_cascaded_table(n).error_status;
7623 item_id_record.error_record.error_message := x_cascaded_table(n).error_message;
7624 ELSE
7625 asn_debug.put_line('before doing validate int org rcv item ');
7626
7627 /* Bug 5182693 : Skip validate item for ASN transactions with substitute item */
7628
7629 asn_debug.put_line('substitute_item_id: '|| x_cascaded_table(n).substitute_item_id);
7630 asn_debug.put_line('g_txn_against_asn : '|| rcv_roi_header.g_txn_against_asn);
7631 /** Bug: 5598511
7632 * For ASN, substitution item id will be populated only during ASN creation and
7633 * not during the receipt of ASN. In order to bypass item validation for ASN added the
7634 * condition ' AND rcv_roi_header.g_txn_against_asn = 'N' '
7635 */
7636 IF rcv_roi_header.g_txn_against_asn = 'Y' THEN
7637 l_pol_item_id := nvl(rcv_table_functions.get_pol_row_from_id(x_cascaded_table(n).po_line_id).item_id,-999);
7638 IF x_cascaded_table(n).item_id <> l_pol_item_id THEN
7639 l_asn_sub_item_txn := 'Y';
7640 ELSE
7641 l_asn_sub_item_txn := 'N';
7642 END IF;
7643 ELSE
7644 l_asn_sub_item_txn := 'N';
7645 END IF;
7646 IF (x_cascaded_table(n).substitute_item_id IS NULL AND rcv_roi_header.g_txn_against_asn = 'N')
7647 OR (l_asn_sub_item_txn = 'N' AND rcv_roi_header.g_txn_against_asn = 'Y') --Bug: 5598511
7648 OR rcv_roi_header.g_txn_against_asn = 'N' THEN --{
7649 rcv_roi_header_common.validate_item(x_cascaded_table, n); -- bug 608353
7650 END IF; --}
7651 END IF; --}
7652
7653 asn_debug.put_line('after doing validate item the error status is ' || x_cascaded_table(n).error_status);
7654 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'ITEM_NUM');
7655 item_id_record.item_description := x_cascaded_table(n).item_description;
7656 item_id_record.error_record.error_status := 'S';
7657 item_id_record.error_record.error_message := NULL;
7658
7659 IF (g_asn_debug = 'Y') THEN
7660 asn_debug.put_line('Validating Item Description ' || x_cascaded_table(n).item_description);
7661 END IF;
7662
7663 rcv_transactions_interface_sv1.validate_item_description(item_id_record);
7664 x_cascaded_table(n).error_status := item_id_record.error_record.error_status;
7665 x_cascaded_table(n).error_message := item_id_record.error_record.error_message;
7666
7667 IF (g_asn_debug = 'Y') THEN
7668 asn_debug.put_line('Error status after validate item description ' || x_cascaded_table(n).error_status);
7669 END IF;
7670
7671 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'ITEM_DESCRIPTION');
7672
7673 IF (x_cascaded_table(n).substitute_item_id IS NOT NULL) THEN --{
7674 IF (g_asn_debug = 'Y') THEN
7675 asn_debug.put_line('Validating Substitute Item');
7676 END IF;
7677
7678 rcv_roi_header_common.validate_substitute_item(x_cascaded_table, n);
7679 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'SUBSTITUTE_ITEM_NUM');
7680 END IF;
7681
7682 IF (x_cascaded_table(n).item_id IS NOT NULL) THEN -- Bug 12538097
7683 rcv_roi_header_common.validate_item_revision(x_cascaded_table, n);
7684 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'ITEM_REVISION');
7685 END IF; -- End Bug 12538097
7686
7687 EXCEPTION
7688 WHEN rcv_error_pkg.e_fatal_error THEN
7689 NULL;
7690 END validate_item_info;
7691
7692 PROCEDURE validate_freight_carrier_code(
7693 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7694 n IN BINARY_INTEGER
7695 ) IS
7696 X_rsh_freight_carrier_code rcv_shipment_headers.freight_carrier_code%TYPE := '-999999'; /* Bug 8722496 */
7697 freight_carrier_record rcv_shipment_line_sv.freight_carrier_record_type;
7698 BEGIN
7699 --validate freight carrier code
7700 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7701 RETURN;
7702 END IF;
7703
7704 IF (x_cascaded_table(n).freight_carrier_code IS NOT NULL) THEN --{
7705
7706 /*Bug 8722496
7707 Adding IF conditions to ensure that the validation call for freight carriers is not made for
7708 Internal Orders and Inter-org transfers when rcv_shipment_headers.freight_carrier_code is
7709 already populated.
7710 */
7711 BEGIN
7712 IF (x_cascaded_table(n).receipt_source_code IN ('INTERNAL ORDER','INVENTORY')) THEN
7713 SELECT Nvl(rsh.freight_carrier_code,'-999')
7714 INTO X_rsh_freight_carrier_code
7715 FROM rcv_shipment_headers rsh
7716 WHERE rsh.shipment_num = x_cascaded_table(n).shipment_num
7717 AND rsh.ship_to_org_id = x_cascaded_table(n).to_organization_id
7718 AND rsh.receipt_source_code IN ('INVENTORY','INTERNAL ORDER');
7719
7720 IF (X_rsh_freight_carrier_code = x_cascaded_table(n).freight_carrier_code) THEN
7721 RETURN;
7722 END IF;
7723 END IF;
7724
7725 EXCEPTION
7726 WHEN OTHERS THEN
7727 asn_debug.put_line('Erroring out in rcv_roi_transaction.validate_freight_carrier_code');
7728 asn_debug.put_line(SQLERRM);
7729 END;
7730 /* End of fix for Bug 8722496 */
7731
7732 freight_carrier_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7733 freight_carrier_record.freight_carrier_code := x_cascaded_table(n).freight_carrier_code;
7734 freight_carrier_record.po_header_id := x_cascaded_table(n).po_header_id;
7735 freight_carrier_record.error_record.error_status := 'S';
7736 freight_carrier_record.error_record.error_message := NULL;
7737
7738 IF (g_asn_debug = 'Y') THEN
7739 asn_debug.put_line('Validating Freight Carrier');
7740 END IF;
7741
7742 rcv_transactions_interface_sv1.validate_freight_carrier(freight_carrier_record);
7743 x_cascaded_table(n).error_status := freight_carrier_record.error_record.error_status;
7744 x_cascaded_table(n).error_message := freight_carrier_record.error_record.error_message;
7745 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7746 'FREIGHT_CARRIER_CODE',
7747 FALSE
7748 );
7749 END IF; --}
7750 END validate_freight_carrier_code;
7751
7752 PROCEDURE validate_dest_type(
7753 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7754 n IN BINARY_INTEGER
7755 ) IS
7756 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
7757 BEGIN
7758 /*
7759 ** Validate Destination Type. This value is always required
7760 */
7761 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7762 RETURN;
7763 END IF;
7764
7765 po_lookup_code_record.lookup_code := x_cascaded_table(n).destination_type_code;
7766 po_lookup_code_record.lookup_type := 'RCV DESTINATION TYPE';
7767 po_lookup_code_record.error_record.error_status := 'S';
7768 po_lookup_code_record.error_record.error_message := NULL;
7769
7770 IF (g_asn_debug = 'Y') THEN
7771 asn_debug.put_line('Validating Destination Type Code');
7772 END IF;
7773
7774 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
7775 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
7776 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
7777 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7778 'DESTINATION_TYPE_CODE',
7779 FALSE
7780 );
7781 END validate_dest_type;
7782
7783 PROCEDURE validate_ship_to_loc(
7784 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7785 n IN BINARY_INTEGER
7786 ) IS
7787 location_record rcv_shipment_line_sv.location_record_type;
7788 BEGIN
7789 /*
7790 ** Validate ship_to_location. This value is always required
7791 */
7792 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7793 RETURN;
7794 END IF;
7795
7796
7797 /* Skipping validation of ship_to_location in case of direct delivery Bug 8306879*/
7798 IF ( x_cascaded_table(n).transaction_type = 'RECEIVE'
7799 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7800
7801 IF (g_asn_debug = 'Y') THEN
7802 asn_debug.put_line('Skipped Ship To Location Validation for Direct Delivery');
7803 END IF;
7804
7805 RETURN;
7806 END IF;
7807
7808 /* End Bug 8306879 */
7809
7810
7811 location_record.location_id := x_cascaded_table(n).ship_to_location_id;
7812 location_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7813 location_record.destination_type_code := x_cascaded_table(n).destination_type_code;
7814 location_record.location_type_code := 'SHIP_TO';
7815 location_record.transaction_date := x_cascaded_table(n).transaction_date;
7816 location_record.error_record.error_status := 'S';
7817 location_record.error_record.error_message := NULL;
7818
7819 IF (g_asn_debug = 'Y') THEN
7820 asn_debug.put_line('Validating Ship To Location');
7821 END IF;
7822
7823 rcv_transactions_interface_sv1.validate_location(location_record);
7824 x_cascaded_table(n).error_status := location_record.error_record.error_status;
7825 x_cascaded_table(n).error_message := location_record.error_record.error_message;
7826 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7827 'SHIP_TO_LOCATION_ID',
7828 FALSE
7829 );
7830 END validate_ship_to_loc;
7831
7832 PROCEDURE validate_deliver_to_person(
7833 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7834 n IN BINARY_INTEGER
7835 ) IS
7836 employee_record rcv_shipment_line_sv.employee_record_type;
7837 BEGIN
7838 /*
7839 ** Validate deliver to person. This value is always optional
7840 */
7841 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7842 RETURN;
7843 END IF;
7844
7845 employee_record.employee_id := x_cascaded_table(n).deliver_to_person_id;
7846 employee_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7847 employee_record.destination_type_code := x_cascaded_table(n).destination_type_code;
7848 employee_record.transaction_date := x_cascaded_table(n).transaction_date;
7849 employee_record.error_record.error_status := 'S';
7850 employee_record.error_record.error_message := NULL;
7851
7852 IF (g_asn_debug = 'Y') THEN
7853 asn_debug.put_line('Validating Deliver to Person');
7854 END IF;
7855
7856 rcv_transactions_interface_sv1.validate_employee(employee_record);
7857
7858 /* Bug:6375015
7859 If the deliver_to_person_id provided is invalid/terminated employee no need
7860 to fail the transaction, as deliver_to_person_id is not the mandatory field.
7861 In case of Receivng forms, if we find the deliver_to_person_id is invalid/
7862 terminated employee we just null out the deliver_to_person_id and proceed
7863 further. So, commented out the following code, which sets the RTI to error and
7864 logging of error message in po_interface_errors and added code to null out the
7865 deliver_to_person_id in case of validation failure for deliver_to_person_id
7866 in order to synch the behaviour of ROI as to that of forms.*/
7867
7868 IF employee_record.error_record.error_status <> 'S' THEN--Start of bug#6375015 fix
7869 IF (g_asn_debug = 'Y') THEN
7870 asn_debug.put_line('validate_employee returned error, setting deliver_to_person_id null');
7871 END IF;
7872 --Validation failure for the deliver_to_person_id
7873 x_cascaded_table(n).deliver_to_person_id := null;
7874 x_cascaded_table(n).deliver_to_person_name := null;
7875 ELSE
7876 IF (g_asn_debug = 'Y') THEN
7877 asn_debug.put_line('validate_employee returned success');
7878 END IF;
7879 END IF;--End of bug#6375015 fix
7880
7881 /* WDK there was a second validation for
7882 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7883 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7884 But the code was an exact repeat - thus fully redundant - not sure what the
7885 purpose was so removed it
7886 */
7887 END validate_deliver_to_person;
7888
7889 PROCEDURE validate_routing_record(
7890 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7891 n IN BINARY_INTEGER
7892 ) IS
7893 x_error_status VARCHAR2(1);
7894
7895 /* Added for bug#16174998*/
7896 l_insp_status rcv_transactions.inspection_status_code%TYPE :=NULL;
7897 BEGIN
7898 x_error_status := rcv_error_pkg.g_ret_sts_error;
7899
7900 /*
7901 ** Validate routing record bug 639750
7902 */
7903 IF (g_asn_debug = 'Y') THEN
7904 asn_debug.put_line('Validating routing_header_id');
7905 END IF;
7906
7907 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7908 RETURN;
7909 END IF;
7910
7911 IF ( x_cascaded_table(n).transaction_type = 'RECEIVE'
7912 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7913 /* 1 is Standard Receipt, 2 is Inspection Required */
7914 IF ( (x_cascaded_table(n).routing_header_id) IN(1, 2)
7915 AND NVL(rcv_setup_s.get_override_routing, 'N') = 'N') THEN
7916 rcv_error_pkg.set_error_message('RCV_ASN_DELIVER_ROUTING_FAILED');
7917 RAISE e_validation_error;
7918 END IF;
7919 END IF;
7920
7921 IF (x_cascaded_table(n).transaction_type IN('ACCEPT', 'REJECT')) THEN --{
7922 IF ( (x_cascaded_table(n).routing_header_id) IN(3)
7923 AND NVL(rcv_setup_s.get_override_routing, 'N') = 'N') THEN --{
7924 asn_debug.put_line('We cannot do inspection on this record .');
7925 rcv_error_pkg.set_error_message('RCV_INSPECT_ROUTING_FAILED');
7926 RAISE e_validation_error;
7927 END IF; --}
7928 END IF; --}
7929
7930 /* Bug#16174998
7931 * If profile RCV override routing is No, Deliver txn should not be allowed for Inspection Required routing
7932 * until Inspect txn is created. */
7933 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7934 AND (x_cascaded_table(n).routing_header_id) = 2
7935 AND NVL(rcv_setup_s.get_override_routing, 'N') = 'N') THEN
7936
7937 BEGIN
7938
7939 IF x_cascaded_table(n).parent_transaction_id IS NOT NULL THEN
7940
7941 SELECT rt.inspection_status_code
7942 INTO l_insp_status
7943 FROM rcv_transactions rt
7944 WHERE rt.transaction_id = x_cascaded_table(n).parent_transaction_id;
7945
7946 ELSE
7947
7948 SELECT rti.inspection_status_code
7949 INTO l_insp_status
7950 FROM rcv_transactions_interface rti
7951 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
7952
7953 END IF;
7954
7955 EXCEPTION
7956 WHEN OTHERS THEN
7957 l_insp_status := NULL;
7958 END;
7959
7960 IF l_insp_status = 'NOT INSPECTED' THEN
7961
7962 asn_debug.put_line('We cannot do deliver on this record .');
7963 rcv_error_pkg.set_error_message('RCV_ASN_DELIVER_ROUTING_FAILED');
7964 RAISE e_validation_error;
7965
7966 END IF;
7967
7968 END IF;
7969
7970 /* End for bug#16174998*/
7971 EXCEPTION
7972 WHEN e_validation_error THEN
7973 x_cascaded_table(n).error_status := x_error_status;
7974 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7975
7976 -- This case statement assigns the appropriate tokens
7977 -- all error messages must be found in the case statement
7978 -- if the error message has no token then use a null statement
7979 IF x_cascaded_table(n).error_message = 'RCV_ASN_DELIVER_ROUTING_FAILED' THEN
7980 NULL;
7981 ELSIF x_cascaded_table(n).error_message = 'RCV_INSPECT_ROUTING_FAILED' THEN
7982 NULL;
7983 END IF;
7984
7985 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7986 'ROUTING_HEADER_ID',
7987 FALSE
7988 );
7989 END validate_routing_record;
7990
7991 PROCEDURE validate_deliver_to_loc(
7992 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7993 n IN BINARY_INTEGER
7994 ) IS
7995 location_record rcv_shipment_line_sv.location_record_type;
7996 BEGIN
7997 /*
7998 ** Validate deliver_to_location. If this is an expense or shop floor
7999 ** destination then the value is required
8000 */
8001 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8002 RETURN;
8003 END IF;
8004
8005 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
8006 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
8007 location_record.location_id := x_cascaded_table(n).deliver_to_location_id;
8008 location_record.to_organization_id := x_cascaded_table(n).to_organization_id;
8009 location_record.destination_type_code := x_cascaded_table(n).destination_type_code;
8010 location_record.location_type_code := 'DELIVER_TO';
8011 location_record.transaction_date := x_cascaded_table(n).transaction_date;
8012 location_record.error_record.error_status := 'S';
8013 location_record.error_record.error_message := NULL;
8014
8015 IF (g_asn_debug = 'Y') THEN
8016 asn_debug.put_line('Validating Deliver To Location');
8017 END IF;
8018
8019 rcv_transactions_interface_sv1.validate_location(location_record);
8020 x_cascaded_table(n).error_status := location_record.error_record.error_status;
8021 x_cascaded_table(n).error_message := location_record.error_record.error_message;
8022 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8023 'DELIVER_TO_LOCATION_ID',
8024 FALSE
8025 );
8026 END IF;
8027 END validate_deliver_to_loc;
8028
8029 /* WMS Changes */
8030 PROCEDURE validate_subinventory(
8031 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8032 n IN BINARY_INTEGER
8033 ) IS
8034 x_subinventory VARCHAR2(10) := NULL;
8035 l_api_version CONSTANT NUMBER := 1.0;
8036 l_return_status VARCHAR2(1);
8037 l_msg_count NUMBER;
8038 l_msg_data fnd_new_messages.MESSAGE_TEXT%TYPE;
8039 l_msg_buf VARCHAR2(2000);
8040 l_progress VARCHAR2(3) := '001';
8041 x_error_status VARCHAR2(1);
8042 l_transaction_type_id NUMBER;
8043
8044 BEGIN
8045 x_error_status := rcv_error_pkg.g_ret_sts_error;
8046
8047 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8048 RETURN;
8049 END IF;
8050
8051 /* We can derive from_subinventory for Return transactions and derive
8052 * to_subinventory for receive, transfer and transfer transactions.
8053 */
8054 IF (g_asn_debug = 'Y') THEN
8055 asn_debug.put_line('Validating Subinventory ');
8056 END IF;
8057
8058 /* bug 3367485: for dropship deliver, skip subinventory validation as
8059 * Inventory has relaxed the subinventory validation for logical trxns
8060 */
8061 /* Commented this out as we will not support ASN auto deliver while
8062 * subinventory is null. See updates on Bug 3367485 */
8063 /* IF (x_drop_ship_flag = 'Y') THEN
8064 IF (g_asn_debug = 'Y') THEN
8065 asn_debug.put_line('Skip subinventory validation for dropship deliver ');
8066 END IF;
8067
8068 RETURN;
8069 END IF; */
8070
8071 IF ( ( x_cascaded_table(n).transaction_type = 'DELIVER'
8072 OR x_cascaded_table(n).auto_transact_code = 'DELIVER')
8073 AND x_cascaded_table(n).destination_type_code <> 'INVENTORY') THEN --{
8074 IF (g_asn_debug = 'Y') THEN
8075 asn_debug.put_line('No need to validate Subinventory if the destination_type is Expense. So return');
8076 END IF;
8077
8078 RETURN;
8079 END IF;
8080
8081 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
8082 OR x_cascaded_table(n).auto_transact_code = 'DELIVER') THEN --{
8083 IF (x_cascaded_table(n).subinventory IS NULL) THEN
8084 rcv_error_pkg.set_error_message('RCV_DEST_SUB_NA');
8085 RAISE e_validation_error;
8086 END IF;
8087
8088 /*
8089 ** Validate the subinventory
8090 */
8091 x_progress := '010';
8092
8093 IF (g_asn_debug = 'Y') THEN
8094 asn_debug.put_line('subinventory ' || x_cascaded_table(n).subinventory);
8095 asn_debug.put_line('to_organization_id ' || x_cascaded_table(n).to_organization_id);
8096 asn_debug.put_line('transaction_date ' || x_cascaded_table(n).transaction_date);
8097 asn_debug.put_line('item_id ' || x_cascaded_table(n).item_id);
8098 END IF;
8099
8100 SELECT NVL(MAX(secondary_inventory_name), 'notfound')
8101 INTO x_subinventory
8102 FROM mtl_secondary_inventories msub,
8103 mtl_system_items msi
8104 WHERE msub.secondary_inventory_name = x_cascaded_table(n).subinventory
8105 AND msub.organization_id = x_cascaded_table(n).to_organization_id
8106 AND x_cascaded_table(n).transaction_date < NVL(msub.disable_date, x_cascaded_table(n).transaction_date + 1)
8107 AND msi.inventory_item_id = x_cascaded_table(n).item_id
8108 AND msi.organization_id = x_cascaded_table(n).to_organization_id
8109 AND ( msi.restrict_subinventories_code = 2
8110 OR ( msi.restrict_subinventories_code = 1
8111 AND EXISTS(SELECT NULL
8112 FROM mtl_item_sub_inventories mis
8113 WHERE mis.organization_id = x_cascaded_table(n).to_organization_id
8114 AND mis.inventory_item_id = x_cascaded_table(n).item_id
8115 AND mis.secondary_inventory = x_cascaded_table(n).subinventory)
8116 )
8117 );
8118
8119 IF (x_subinventory = 'notfound') THEN
8120 IF (g_asn_debug = 'Y') THEN
8121 asn_debug.put_line('subinventory not found. error ');
8122 END IF;
8123
8124 rcv_error_pkg.set_error_message('RCV_DEST_SUB_INVALID');
8125 RAISE e_validation_error;
8126 END IF;
8127
8128 -- Bug 10253000: Start Validate material status on subinventory level
8129
8130 IF x_cascaded_table(n).receipt_source_code = 'VENDOR' THEN
8131 l_transaction_type_id := 18;
8132
8133 ELSIF x_cascaded_table(n).receipt_source_code = 'INVENTORY' THEN
8134 l_transaction_type_id := 12;
8135
8136 ELSIF x_cascaded_table(n).receipt_source_code = 'INTERNAL ORDER' THEN
8137 l_transaction_type_id := 61;
8138
8139 ELSIF x_cascaded_table(n).receipt_source_code = 'CUSTOMER' THEN
8140 l_transaction_type_id := 15;
8141
8142 ELSE
8143 l_transaction_type_id := -99;
8144 END IF;
8145
8146 IF (inv_material_status_grp.is_status_applicable
8147 (NULL,
8148 NULL,
8149 l_transaction_type_id,
8150 NULL,
8151 NULL,
8152 x_cascaded_table(n).to_organization_id,
8153 NULL,
8154 x_cascaded_table(n).subinventory,
8155 NULL,
8156 NULL,
8157 NULL,
8158 'Z') <> 'Y') THEN
8159 IF (g_asn_debug = 'Y') THEN
8160 asn_debug.put_line('subinventory is invalidate. error ');
8161 END IF;
8162
8163 rcv_error_pkg.set_error_message('RCV_DEST_SUB_INVALID');
8164 RAISE e_validation_error;
8165
8166 END IF;
8167 -- Bug 10253000: End
8168
8169 ELSE --}{
8170 inv_rcv_integration_apis.validate_sub_loc(l_api_version,
8171 'FALSE',
8172 l_return_status,
8173 l_msg_count,
8174 l_msg_data,
8175 x_cascaded_table(n).GROUP_ID,
8176 x_cascaded_table(n).request_id,
8177 x_cascaded_table(n).interface_transaction_id,
8178 1
8179 );
8180
8181 IF (l_return_status = fnd_api.g_ret_sts_error) THEN
8182 RAISE fnd_api.g_exc_error;
8183 ELSIF(l_return_status = fnd_api.g_ret_sts_unexp_error) THEN
8184 RAISE fnd_api.g_exc_unexpected_error;
8185 END IF;
8186 END IF; --}
8187 EXCEPTION
8188 WHEN e_validation_error THEN
8189 x_cascaded_table(n).error_status := x_error_status;
8190 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
8191
8192 -- This case statement assigns the appropriate tokens
8193 -- all error messages must be found in the case statement
8194 -- if the error message has no token then use a null statement
8195 IF x_cascaded_table(n).error_message = 'RCV_DEST_SUB_NA' THEN
8196 NULL;
8197 ELSIF x_cascaded_table(n).error_message = 'RCV_DEST_SUB_INVALID' THEN
8198 NULL;
8199 END IF;
8200
8201 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8202 'SUBINVENTORY',
8203 FALSE
8204 );
8205 WHEN OTHERS THEN
8206 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
8207 rcv_error_pkg.set_sql_error_message('validate_subinventory', l_progress);
8208 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
8209 rcv_error_pkg.log_interface_error('SUBINVENTORY', FALSE);
8210 END validate_subinventory;
8211
8212 PROCEDURE validate_locator(
8213 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8214 n IN BINARY_INTEGER
8215 ) IS
8216 locator_record rcv_shipment_line_sv.locator_record_type;
8217 l_transaction_type_id NUMBER;
8218
8219 BEGIN
8220 /*
8221 ** Validate locator if inventory destination or if not inventory
8222 ** destintion make sure to null out the locator_id
8223 */
8224 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8225 RETURN;
8226 END IF;
8227
8228 IF (g_asn_debug = 'Y') THEN
8229 asn_debug.put_line('Trx Type = ' || x_cascaded_table(n).transaction_type || 'Auto Trx Code = ' || x_cascaded_table(n).auto_transact_code);
8230 END IF;
8231
8232 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
8233 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
8234 IF (g_asn_debug = 'Y') THEN
8235 asn_debug.put_line('Valid Loc - Destination Type Code = ' || x_cascaded_table(n).destination_type_code);
8236 END IF;
8237
8238 IF (x_cascaded_table(n).destination_type_code = 'INVENTORY') THEN
8239 locator_record.locator_id := x_cascaded_table(n).locator_id;
8240 locator_record.subinventory := x_cascaded_table(n).subinventory;
8241 locator_record.to_organization_id := x_cascaded_table(n).to_organization_id;
8242 locator_record.destination_type_code := x_cascaded_table(n).destination_type_code;
8243 locator_record.item_id := x_cascaded_table(n).item_id;
8244 locator_record.transaction_date := x_cascaded_table(n).transaction_date;
8245
8246 --Bug13844195
8247 locator_record.receipt_source_code := x_cascaded_table(n).receipt_source_code; --Bug13844195
8248 locator_record.po_distribution_id := x_cascaded_table(n).po_distribution_id; --Bug13844195
8249 locator_record.source_document_code := x_cascaded_table(n).source_document_code; --Bug13844195
8250 locator_record.project_id := x_cascaded_table(n).project_id; --Bug13844195
8251 locator_record.task_id := x_cascaded_table(n).task_id; --Bug13844195
8252 --End Bug 13844195
8253
8254 IF (g_asn_debug = 'Y') THEN
8255 asn_debug.put_line('Locator = ' || TO_CHAR(locator_record.locator_id));
8256 asn_debug.put_line('Subinventory = ' || locator_record.subinventory);
8257 asn_debug.put_line('To Org = ' || locator_record.to_organization_id);
8258 asn_debug.put_line('Dest Type = ' || locator_record.destination_type_code);
8259 asn_debug.put_line('Item Id = ' || locator_record.item_id);
8260 END IF;
8261
8262 locator_record.error_record.error_status := 'S';
8263 locator_record.error_record.error_message := NULL;
8264
8265 IF (g_asn_debug = 'Y') THEN
8266 asn_debug.put_line('Validating Locator');
8267 END IF;
8268
8269 rcv_transactions_interface_sv1.validate_locator(locator_record);
8270 rcv_transactions_interface_sv1.validate_project_locator(locator_record); --Bug13844195
8271 x_cascaded_table(n).error_status := locator_record.error_record.error_status;
8272 x_cascaded_table(n).error_message := locator_record.error_record.error_message;
8273
8274 -- Bug 13817635 added
8275 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8276 'LOCATOR_ID',
8277 FALSE
8278 );
8279 -- Bug 13817635 ended
8280
8281 /* Bug 5468345.
8282 * If the user has specified locator_id or locator_num and org/sub/item is not under locator control,
8283 * then the rcv_transactions_interface_sv1.validate_locator procedure nulls out the locator_id.
8284 * We need to copy this back to the x_cascaded_table. This used to cause data corruption.
8285 * Changed the code to null it.
8286 */
8287
8288 if locator_record.locator_id is null then
8289
8290 asn_debug.put_line('Locator_id is nulled out');
8291 x_cascaded_table(n).locator_id := locator_record.locator_id;
8292 end if;
8293
8294
8295 IF (g_asn_debug = 'Y') THEN
8296 asn_debug.put_line('Loc Error Status = ' || locator_record.error_record.error_status);
8297 asn_debug.put_line('Loc Error Msg = ' || locator_record.error_record.error_message);
8298 asn_debug.put_line('Locator_id = ' || locator_record.locator_id);
8299 END IF;
8300
8301 -- Bug 10253000 : Validate Material Status on locator level
8302
8303 IF x_cascaded_table(n).receipt_source_code = 'VENDOR' THEN
8304 l_transaction_type_id := 18;
8305
8306 ELSIF x_cascaded_table(n).receipt_source_code = 'INVENTORY' THEN
8307 l_transaction_type_id := 12;
8308
8309 ELSIF x_cascaded_table(n).receipt_source_code = 'INTERNAL ORDER' THEN
8310 l_transaction_type_id := 61;
8311
8312 ELSIF x_cascaded_table(n).receipt_source_code = 'CUSTOMER' THEN
8313 l_transaction_type_id := 15;
8314
8315 ELSE
8316 l_transaction_type_id := -99;
8317 END IF;
8318
8319 IF (inv_material_status_grp.is_status_applicable
8320 (NULL,
8321 NULL,
8322 l_transaction_type_id,
8323 NULL,
8324 NULL,
8325 x_cascaded_table(n).to_organization_id,
8326 NULL,
8327 NULL,
8328 x_cascaded_table(n).locator_id,
8329 NULL,
8330 NULL,
8331 'L') <> 'Y') THEN
8332 rcv_error_pkg.set_error_message('RCV_ALL_INVALID_LOCATOR');
8333 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
8334 x_cascaded_table(n).error_message := 'RCV_ALL_INVALID_LOCATOR';
8335 locator_record.error_record.error_status := rcv_error_pkg.g_ret_sts_error;
8336 locator_record.error_record.error_message := 'RCV_ALL_REQUIRED_LOCATOR';
8337 END IF;
8338 -- Bug 10253000 : End
8339
8340 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8341 'LOCATOR_ID',
8342 FALSE
8343 );
8344 ELSE --}{
8345 x_cascaded_table(n).locator_id := NULL;
8346 x_cascaded_table(n).LOCATOR := NULL;
8347 IF (g_asn_debug = 'Y') THEN
8348 asn_debug.put_line('locator_id ' || x_cascaded_table(n).locator_id);
8349 asn_debug.put_line('locator ' || x_cascaded_table(n).locator);
8350 END IF;
8351 END IF; --}
8352 END IF;
8353 END validate_locator;
8354
8355 PROCEDURE validate_tax_code(
8356 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8357 n IN BINARY_INTEGER,
8358 /* Bug3454491 (4) */
8359 x_asn_type IN rcv_headers_interface.asn_type%TYPE
8360 ) IS
8361 tax_name_record rcv_shipment_line_sv.tax_name_record_type;
8362 BEGIN
8363 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8364 RETURN;
8365 END IF;
8366
8367 IF (x_cascaded_table(n).tax_name IS NOT NULL) THEN
8368 IF (x_asn_type = 'ASBN') THEN
8369 tax_name_record.tax_name := x_cascaded_table(n).tax_name;
8370 tax_name_record.error_record.error_status := 'S';
8371 tax_name_record.error_record.error_message := NULL;
8372
8373 IF (g_asn_debug = 'Y') THEN
8374 asn_debug.put_line('Validating Tax Code');
8375 END IF;
8376
8377 rcv_transactions_interface_sv1.validate_tax_code(tax_name_record);
8378 x_cascaded_table(n).error_status := tax_name_record.error_record.error_status;
8379 x_cascaded_table(n).error_message := tax_name_record.error_record.error_message;
8380 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8381 'TAX_NAME',
8382 FALSE
8383 );
8384 END IF;
8385 END IF;
8386 END validate_tax_code;
8387
8388 PROCEDURE validate_country_of_origin(
8389 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8390 n IN BINARY_INTEGER
8391 ) IS
8392 country_of_origin_record rcv_shipment_line_sv.country_of_origin_record_type;
8393 BEGIN
8394 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8395 RETURN;
8396 END IF;
8397
8398 --FRKHAN 12/18/98 validate country of origin code
8399 IF (x_cascaded_table(n).country_of_origin_code IS NOT NULL) THEN
8400 country_of_origin_record.country_of_origin_code := x_cascaded_table(n).country_of_origin_code;
8401 country_of_origin_record.error_record.error_status := 'S';
8402 country_of_origin_record.error_record.error_message := NULL;
8403
8404 IF (g_asn_debug = 'Y') THEN
8405 asn_debug.put_line('Validating Country of Origin Code');
8406 END IF;
8407
8408 rcv_transactions_interface_sv1.validate_country_of_origin(country_of_origin_record);
8409 x_cascaded_table(n).error_status := country_of_origin_record.error_record.error_status;
8410 x_cascaded_table(n).error_message := country_of_origin_record.error_record.error_message;
8411 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8412 'COUNTRY_OF_ORIGIN_CODE',
8413 FALSE
8414 );
8415 END IF;
8416 END validate_country_of_origin;
8417
8418 PROCEDURE validate_asl(
8419 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8420 n IN BINARY_INTEGER
8421 ) IS
8422 asl_record rcv_shipment_line_sv.ref_integrity_record_type;
8423 BEGIN
8424 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8425 RETURN;
8426 END IF;
8427
8428 asl_record.po_header_id := x_cascaded_table(n).po_header_id;
8429 asl_record.vendor_id := x_cascaded_table(n).vendor_id;
8430 asl_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
8431 asl_record.item_id := x_cascaded_table(n).item_id;
8432 asl_record.to_organization_id := x_cascaded_table(n).to_organization_id;
8433 asl_record.error_record.error_status := 'S';
8434 asl_record.error_record.error_message := NULL;
8435
8436 IF (g_asn_debug = 'Y') THEN
8437 asn_debug.put_line('Validating ASL');
8438 END IF;
8439
8440 rcv_transactions_interface_sv1.validate_asl(asl_record);
8441 x_cascaded_table(n).error_status := asl_record.error_record.error_status;
8442 x_cascaded_table(n).error_message := asl_record.error_record.error_message;
8443 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8444 'SUPPLY_AGREEMENT_FLAG',
8445 FALSE
8446 );
8447 END validate_asl;
8448
8449 PROCEDURE validate_shipped_qty(
8450 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8451 n IN BINARY_INTEGER
8452 ) IS
8453 cum_quantity_record rcv_shipment_line_sv.cum_quantity_record_type;
8454 BEGIN
8455 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8456 RETURN;
8457 END IF;
8458
8459 IF NVL(x_cascaded_table(n).vendor_cum_shipped_qty, 0) <> 0 THEN
8460 cum_quantity_record.to_organization_id := x_cascaded_table(n).to_organization_id;
8461 cum_quantity_record.po_header_id := x_cascaded_table(n).po_header_id;
8462 cum_quantity_record.vendor_cum_shipped_qty := x_cascaded_table(n).vendor_cum_shipped_qty;
8463 cum_quantity_record.item_id := x_cascaded_table(n).item_id;
8464 cum_quantity_record.vendor_id := x_cascaded_table(n).vendor_id;
8465 cum_quantity_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
8466 cum_quantity_record.primary_unit_of_measure := x_cascaded_table(n).primary_unit_of_measure;
8467 cum_quantity_record.quantity_shipped := x_cascaded_table(n).quantity;
8468 cum_quantity_record.unit_of_measure := x_cascaded_table(n).unit_of_measure;
8469 cum_quantity_record.transaction_date := x_cascaded_table(n).transaction_date;
8470 cum_quantity_record.error_record.error_status := 'S';
8471 cum_quantity_record.error_record.error_message := NULL;
8472
8473 IF (g_asn_debug = 'Y') THEN
8474 asn_debug.put_line('Validating Cum Qty Shipped');
8475 END IF;
8476
8477 rcv_transactions_interface_sv1.validate_cum_quantity_shipped(cum_quantity_record);
8478 x_cascaded_table(n).error_status := cum_quantity_record.error_record.error_status;
8479 x_cascaded_table(n).error_message := cum_quantity_record.error_record.error_message;
8480 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8481 'VENDOR_CUM_SHIPPED_QTY',
8482 FALSE
8483 );
8484 END IF; -- vendor_cum_shipped_qty <> 0
8485 END validate_shipped_qty;
8486
8487 PROCEDURE validate_ref_integrity(
8488 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8489 n IN BINARY_INTEGER,
8490 x_header_record IN rcv_roi_preprocessor.header_rec_type
8491 ) IS
8492 ref_integrity_record rcv_shipment_line_sv.ref_integrity_record_type;
8493 l_job_id po_lines.job_id%TYPE;
8494 l_item_description po_lines.item_description%TYPE;
8495 l_category_id po_lines.category_id%TYPE;
8496 x_error_status VARCHAR2(1);
8497 BEGIN
8498 x_error_status := rcv_error_pkg.g_ret_sts_error;
8499
8500 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8501 RETURN;
8502 END IF;
8503
8504 IF (g_asn_debug = 'Y') THEN
8505 asn_debug.put_line('Validating ref integrity');
8506 END IF;
8507
8508 ref_integrity_record.to_organization_id := x_cascaded_table(n).to_organization_id;
8509 ref_integrity_record.po_line_location_id := x_cascaded_table(n).po_line_location_id;
8510 ref_integrity_record.po_header_id := x_cascaded_table(n).po_header_id;
8511 ref_integrity_record.po_line_id := x_cascaded_table(n).po_line_id;
8512 ref_integrity_record.vendor_id := x_cascaded_table(n).vendor_id;
8513 ref_integrity_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
8514 ref_integrity_record.vendor_item_num := x_cascaded_table(n).vendor_item_num;
8515
8516 /*
8517 Bug 6447564.
8518 Added below line to pass parent_txn_id value to the proc validate_ref_integ()
8519 So that we may take the vendor site id from parent txn if parent_txn_id not null.
8520 */
8521 ref_integrity_record.parent_txn_id := x_cascaded_table(n).PARENT_TRANSACTION_ID;
8522
8523
8524 /* Bug 3210821.
8525 * We default po_revision_num from RT for all the
8526 * transactions other than receive or direct delivery.
8527 * Hence we should not be validationg this against the
8528 * revision_num in PO header since it might heve been
8529 * changed. So set po_revision_num to null if it is any other
8530 * transaction other than RECEIVE. This would take care of
8531 * direct delivery also since trx_type will be receive for
8532 * that also.
8533 */
8534 IF (x_cascaded_table(n).transaction_type = 'RECEIVE') THEN
8535 ref_integrity_record.po_revision_num := x_cascaded_table(n).po_revision_num;
8536
8537 IF (g_asn_debug = 'Y') THEN
8538 asn_debug.put_line('Trx_type RECEIVE and revision num is ' || ref_integrity_record.po_revision_num);
8539 END IF;
8540 ELSE
8541 ref_integrity_record.po_revision_num := NULL;
8542
8543 IF (g_asn_debug = 'Y') THEN
8544 asn_debug.put_line('Trx_type is not RECEIVE and revision num is ' || ref_integrity_record.po_revision_num);
8545 END IF;
8546 END IF;
8547
8548 /* End of 3210821. */
8549 ref_integrity_record.error_record.error_status := 'S';
8550 ref_integrity_record.error_record.error_message := NULL;
8551 --replacing call with a validate_ref_integ call with the method in thid package
8552 -- rcv_transactions_interface_sv1.validate_ref_integ (ref_integrity_record,X_header_record);
8553 validate_ref_integ(ref_integrity_record, x_header_record);
8554
8555 IF (g_asn_debug = 'Y') THEN
8556 asn_debug.put_line('After Validating Ref Integ: ' || ref_integrity_record.error_record.error_status);
8557 END IF;
8558
8559 x_cascaded_table(n).error_status := ref_integrity_record.error_record.error_status;
8560 x_cascaded_table(n).error_message := ref_integrity_record.error_record.error_message;
8561 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'TRANSACTIONS_INTERFACE_ID');
8562
8563 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN --{
8564 IF (g_asn_debug = 'Y') THEN
8565 asn_debug.put_line('job_id ' || x_cascaded_table(n).job_id);
8566 asn_debug.put_line('item_description ' || x_cascaded_table(n).item_description);
8567 asn_debug.put_line('category_id ' || x_cascaded_table(n).category_id);
8568 END IF;
8569
8570 IF (x_cascaded_table(n).job_id IS NOT NULL) THEN
8571 IF (g_asn_debug = 'Y') THEN
8572 asn_debug.put_line('Before select l_job_id ' || l_job_id);
8573 END IF;
8574
8575 SELECT NVL(MAX(job_id), 0)
8576 INTO l_job_id
8577 FROM po_lines
8578 WHERE po_line_id = x_cascaded_table(n).po_line_id
8579 AND job_id = x_cascaded_table(n).job_id;
8580
8581 IF (g_asn_debug = 'Y') THEN
8582 asn_debug.put_line('After select l_job_id ' || l_job_id);
8583 END IF;
8584
8585 IF (l_job_id = 0) THEN
8586 rcv_error_pkg.set_error_message('RCV_NOT_PO_JOB_ID');
8587 RAISE e_validation_error;
8588 END IF;
8589 END IF;
8590
8591 IF (x_cascaded_table(n).item_description IS NOT NULL) THEN
8592
8593 /* Complex work.
8594 * For work confirmations check in shipment level. If
8595 * null then in po_lines. For other POs
8596 * check in po_lines.
8597 */
8598
8599 If (nvl(x_header_record.header_record.asn_type,'STD') = 'WC') then --{
8600
8601 BEGIN
8602 SELECT (description)
8603 INTO l_item_description
8604 FROM po_line_locations
8605 WHERE line_location_id =
8606 x_cascaded_table(n).po_line_location_id
8607 AND description = x_cascaded_table(n).item_description;
8608
8609 EXCEPTION
8610 WHEN NO_DATA_FOUND THEN
8611 BEGIN
8612 SELECT (item_description)
8613 INTO l_item_description
8614 FROM po_lines
8615 WHERE po_line_id = x_cascaded_table(n).po_line_id
8616 AND item_description =
8617 x_cascaded_table(n).item_description;
8618 EXCEPTION
8619 WHEN NO_DATA_FOUND THEN
8620 l_item_description := 'NO DATA';
8621 END;
8622
8623 END;
8624
8625 else --}{
8626 BEGIN
8627 SELECT (item_description)
8628 INTO l_item_description
8629 FROM po_lines
8630 WHERE po_line_id = x_cascaded_table(n).po_line_id
8631 AND item_description = x_cascaded_table(n).item_description;
8632 EXCEPTION
8633 WHEN NO_DATA_FOUND THEN
8634 l_item_description := 'NO DATA';
8635 END;
8636
8637 End if; --}
8638
8639 IF (g_asn_debug = 'Y') THEN
8640 asn_debug.put_line('After select l_item_description ' || l_item_description);
8641 END IF;
8642
8643 IF (l_item_description = 'NO DATA') THEN
8644 rcv_error_pkg.set_error_message('RCV_NOT_PO_ITEM_DESC');
8645 RAISE e_validation_error;
8646 END IF;
8647 END IF;
8648
8649 IF (x_cascaded_table(n).category_id IS NOT NULL) THEN
8650 SELECT NVL(MAX(category_id), 0)
8651 INTO l_category_id
8652 FROM po_lines
8653 WHERE po_line_id = x_cascaded_table(n).po_line_id
8654 AND category_id = x_cascaded_table(n).category_id;
8655
8656 IF (g_asn_debug = 'Y') THEN
8657 asn_debug.put_line('After select l_category_id ' || l_category_id);
8658 END IF;
8659
8660 IF (l_category_id = 0) THEN
8661 rcv_error_pkg.set_error_message('RCV_NOT_PO_CATEGORY');
8662 RAISE e_validation_error;
8663 END IF;
8664 END IF;
8665
8666 IF (g_asn_debug = 'Y') THEN
8667 asn_debug.put_line('l_job_id ' || l_job_id);
8668 asn_debug.put_line('l_item_description ' || l_item_description);
8669 asn_debug.put_line('l_category_id ' || l_category_id);
8670 asn_debug.put_line('x_cascaded_table(n).error_status ' || x_cascaded_table(n).error_status);
8671 END IF;
8672 END IF; --}
8673
8674 IF (g_asn_debug = 'Y') THEN
8675 asn_debug.put_line('Leave validate_ref_integrity');
8676 END IF;
8677 EXCEPTION
8678 WHEN e_validation_error THEN
8679 x_cascaded_table(n).error_status := x_error_status;
8680 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
8681
8682 IF x_cascaded_table(n).error_message = 'RCV_NOT_PO_JOB_ID' THEN
8683 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8684 'JOB_ID',
8685 FALSE
8686 );
8687 ELSIF x_cascaded_table(n).error_message = 'RCV_NOT_PO_ITEM_DESC' THEN
8688 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8689 'ITEM_DESCRIPTION',
8690 FALSE
8691 );
8692 ELSIF x_cascaded_table(n).error_message = 'RCV_NOT_PO_CATEGORY' THEN
8693 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
8694 'CATEGORY_ID',
8695 FALSE
8696 );
8697 END IF;
8698 WHEN rcv_error_pkg.e_fatal_error THEN
8699 NULL;
8700 WHEN OTHERS THEN
8701 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
8702 rcv_error_pkg.set_sql_error_message('validate_ref_integrity', '000');
8703 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
8704 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
8705 END validate_ref_integrity;
8706
8707 PROCEDURE exchange_sub_items(
8708 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8709 n IN BINARY_INTEGER
8710 ) IS
8711 location_record rcv_shipment_line_sv.location_record_type;
8712 x_item_id NUMBER;
8713 x_primary_uom mtl_system_items.primary_unit_of_measure%TYPE := NULL;
8714 x_uom_class VARCHAR2(10);
8715 x_uom_count NUMBER(10);
8716 prim_uom_qty NUMBER;
8717 x_error_status VARCHAR2(1);
8718 l_item_description mtl_system_items_vl.description%type; --bug 4697949
8719 BEGIN
8720 x_error_status := rcv_error_pkg.g_ret_sts_error;
8721
8722 -- If substitute item has been specified then we need to switch the item_id with the
8723 -- substitute item. Also make sure that we can receive the substitute item in the
8724 -- ASN UOM. Convert the primary_quantity in item.primary uom to the substitute_item.primary_uom
8725 -- If this fails then the transaction is in error
8726
8727 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8728 RETURN;
8729 END IF;
8730
8731 IF x_cascaded_table(n).substitute_item_id IS NOT NULL THEN --{
8732
8733 -- exchange_sub_item(x_cascaded_table,n);
8734 -- the call to exchange sub item is not made
8735 -- instead the code of exchange sub item is put there
8736 SELECT COUNT(*)
8737 INTO x_uom_count
8738 FROM mtl_item_uoms_view
8739 WHERE organization_id = x_cascaded_table(n).to_organization_id
8740 AND inventory_item_id(+) = x_cascaded_table(n).substitute_item_id
8741 AND unit_of_measure = x_cascaded_table(n).unit_of_measure;
8742
8743 IF x_uom_count = 0 THEN
8744 IF (g_asn_debug = 'Y') THEN
8745 asn_debug.put_line('The substitute item cannot be received in ASN uom' || x_cascaded_table(n).unit_of_measure);
8746 END IF;
8747
8748 rcv_error_pkg.set_error_message('RCV_ITEM_SUB_NOT_ALLOWED');
8749 RAISE e_validation_error;
8750 END IF;
8751
8752 SELECT MAX(primary_unit_of_measure)
8753 INTO x_primary_uom
8754 FROM mtl_system_items
8755 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
8756 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
8757
8758 IF x_primary_uom IS NULL THEN
8759 IF (g_asn_debug = 'Y') THEN
8760 asn_debug.put_line('No Primary UOM for substitute item');
8761 END IF;
8762
8763 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY');
8764 RAISE e_validation_error;
8765 END IF;
8766
8767 IF (g_asn_debug = 'Y') THEN
8768 asn_debug.put_line('Primary UOM for substitute item is ' || x_primary_uom);
8769 END IF;
8770
8771 IF x_primary_uom <> x_cascaded_table(n).primary_unit_of_measure THEN --{
8772 prim_uom_qty := rcv_transactions_interface_sv.convert_into_correct_qty(x_cascaded_table(n).quantity,
8773 x_cascaded_table(n).unit_of_measure,
8774 x_cascaded_table(n).item_id,
8775 x_primary_uom
8776 );
8777
8778 IF prim_uom_qty = 0 THEN
8779 IF (g_asn_debug = 'Y') THEN
8780 asn_debug.put_line('Not possible to convert between asn and primary UOM');
8781 END IF;
8782
8783 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY');
8784 RAISE e_validation_error;
8785 END IF;
8786
8787 x_cascaded_table(n).primary_unit_of_measure := x_primary_uom;
8788 x_cascaded_table(n).primary_quantity := prim_uom_qty;
8789 END IF; --}
8790
8791 /* added for bug 4697949. querying msi to get the description of
8792 substitute item*/
8793 BEGIN
8794 select description
8795 into l_item_description
8796 from mtl_system_items_vl
8797 where inventory_item_id = x_cascaded_table(n).substitute_item_id
8798 and organization_id = x_cascaded_table(n).to_organization_id;
8799 EXCEPTION
8800 when others then
8801 l_item_description := null;
8802 END;
8803
8804 x_item_id := x_cascaded_table(n).item_id;
8805 x_cascaded_table(n).item_id := x_cascaded_table(n).substitute_item_id;
8806 x_cascaded_table(n).item_description := l_item_description; --bug 4697949
8807 x_cascaded_table(n).substitute_item_id := x_item_id; -- Just for debugging purposes.
8808
8809 -- end of exchange sub item code which has been copied over from rcvtisvb++++++++++++++++++++++
8810 END IF; --}
8811 EXCEPTION
8812 WHEN e_validation_error THEN
8813 x_cascaded_table(n).error_status := x_error_status;
8814 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
8815
8816 IF x_cascaded_table(n).error_message = 'RCV_ITEM_SUB_NOT_ALLOWED' THEN
8817 rcv_error_pkg.set_token('ITEM', x_cascaded_table(n).substitute_item_id);
8818 ELSIF x_cascaded_table(n).error_message = 'RCV_UOM_NO_CONV_PRIMARY' THEN
8819 rcv_error_pkg.set_token('SHIPMENT_UNIT', x_cascaded_table(n).primary_unit_of_measure);
8820 rcv_error_pkg.set_token('PRIMARY_UNIT', x_primary_uom);
8821 END IF;
8822 END exchange_sub_items;
8823
8824 PROCEDURE validate_consigned_inventory(
8825 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8826 n IN BINARY_INTEGER,
8827 /* Bug3454491 (5) */
8828 x_asn_type IN rcv_headers_interface.asn_type%TYPE
8829 ) IS
8830 l_consigned_po_rec rcv_shipment_line_sv.po_line_location_id_rtype;
8831 l_consumption_po_rec rcv_shipment_line_sv.document_num_record_type;
8832 l_consumption_release_rec rcv_shipment_line_sv.release_id_record_type;
8833 BEGIN
8834 /* <Consigned Inventory Pre-Processor FPI START> */
8835
8836 /* Reject ASBN transaction if it's a shipment against Consigned PO */
8837 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
8838 RETURN;
8839 END IF;
8840
8841 IF (x_asn_type = 'ASBN')
8842 AND (x_cascaded_table(n).po_line_location_id IS NOT NULL) THEN
8843 l_consigned_po_rec.po_line_location_id := x_cascaded_table(n).po_line_location_id;
8844 l_consigned_po_rec.error_record.error_status := 'S';
8845 l_consigned_po_rec.error_record.error_message := NULL;
8846
8847 IF (g_asn_debug = 'Y') THEN
8848 asn_debug.put_line('Validating ASBN for Consigned PO');
8849 END IF;
8850
8851 rcv_transactions_interface_sv1.validate_consigned_po(l_consigned_po_rec);
8852
8853 IF (g_asn_debug = 'Y') THEN
8854 asn_debug.put_line('After Validating ASBN for Consigned PO');
8855 END IF;
8856
8857 x_cascaded_table(n).error_status := l_consigned_po_rec.error_record.error_status;
8858 x_cascaded_table(n).error_message := l_consigned_po_rec.error_record.error_message;
8859
8860 IF (g_asn_debug = 'Y') THEN
8861 asn_debug.put_line('Error status ' || l_consigned_po_rec.error_record.error_status);
8862 asn_debug.put_line('Error name: ' || l_consigned_po_rec.error_record.error_message);
8863 END IF;
8864
8865 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PO_LINE_LOCATION_ID');
8866 END IF; -- IF ( (X_asn_type = 'ASBN')
8867
8868 /*
8869 ** Reject ASN, ASBN or Receipt transactions against Consumption PO
8870 */
8871 IF (x_cascaded_table(n).po_header_id IS NOT NULL)
8872 AND (x_cascaded_table(n).po_release_id IS NULL) THEN
8873 l_consumption_po_rec.po_header_id := x_cascaded_table(n).po_header_id;
8874 l_consumption_po_rec.error_record.error_status := 'S';
8875 l_consumption_po_rec.error_record.error_message := NULL;
8876
8877 IF (g_asn_debug = 'Y') THEN
8878 asn_debug.put_line('Validating Consumption PO');
8879 END IF;
8880
8881 rcv_transactions_interface_sv1.validate_consumption_po(l_consumption_po_rec);
8882
8883 IF (g_asn_debug = 'Y') THEN
8884 asn_debug.put_line('After Validating Consumption PO');
8885 END IF;
8886
8887 x_cascaded_table(n).error_status := l_consumption_po_rec.error_record.error_status;
8888 x_cascaded_table(n).error_message := l_consumption_po_rec.error_record.error_message;
8889
8890 IF (g_asn_debug = 'Y') THEN
8891 asn_debug.put_line('Error status ' || l_consumption_po_rec.error_record.error_status);
8892 asn_debug.put_line('Error name: ' || l_consumption_po_rec.error_record.error_message);
8893 END IF;
8894
8895 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PO_HEADER_ID');
8896 END IF;
8897
8898 /*
8899 ** Reject ASN, ASBN or Receipt transactions against Consumption Release
8900 */
8901 IF (x_cascaded_table(n).po_release_id IS NOT NULL) THEN
8902 l_consumption_release_rec.po_release_id := x_cascaded_table(n).po_release_id;
8903 l_consumption_release_rec.error_record.error_status := 'S';
8904 l_consumption_release_rec.error_record.error_message := NULL;
8905
8906 IF (g_asn_debug = 'Y') THEN
8907 asn_debug.put_line('Validating Consumption Release');
8908 END IF;
8909
8910 rcv_transactions_interface_sv1.validate_consumption_release(l_consumption_release_rec);
8911
8912 IF (g_asn_debug = 'Y') THEN
8913 asn_debug.put_line('After Validating Consumption Release');
8914 END IF;
8915
8916 x_cascaded_table(n).error_status := l_consumption_release_rec.error_record.error_status;
8917 x_cascaded_table(n).error_message := l_consumption_release_rec.error_record.error_message;
8918
8919 IF (g_asn_debug = 'Y') THEN
8920 asn_debug.put_line('Error status ' || l_consumption_release_rec.error_record.error_status);
8921 asn_debug.put_line('Error name: ' || l_consumption_release_rec.error_record.error_message);
8922 END IF;
8923
8924 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PO_RELEASE_ID');
8925 END IF;
8926 /* <Consigned Inventory Pre-Processor FPI END> */
8927 EXCEPTION
8928 WHEN rcv_error_pkg.e_fatal_error THEN
8929 NULL;
8930 END validate_consigned_inventory;
8931
8932 PROCEDURE validate_ref_integ(
8933 x_ref_integrity_rec IN OUT NOCOPY rcv_shipment_line_sv.ref_integrity_record_type,
8934 x_header_record IN rcv_roi_preprocessor.header_rec_type
8935 ) IS
8936 x_po_vendor_id po_headers.vendor_id%TYPE := NULL;
8937 x_po_line_id po_lines.po_line_id%TYPE;
8938 x_po_vendor_site_id po_headers.vendor_site_id%TYPE := NULL;
8939 x_progress VARCHAR2(3);
8940 x_error_status VARCHAR2(1);
8941 BEGIN
8942 x_error_status := rcv_error_pkg.g_ret_sts_error;
8943
8944 IF (x_ref_integrity_rec.vendor_item_num IS NOT NULL) THEN
8945 SELECT NVL(MAX(po_line_id), 0)
8946 INTO x_po_line_id
8947 FROM po_lines
8948 WHERE po_line_id = x_ref_integrity_rec.po_line_id
8949 AND vendor_product_num = x_ref_integrity_rec.vendor_item_num;
8950
8951 IF (x_po_line_id = 0) THEN
8952 rcv_error_pkg.set_error_message('RCV_NOT_PO_VEN_ITEM');
8953 RAISE e_validation_error;
8954 END IF;
8955 END IF;
8956
8957 IF (g_asn_debug = 'Y') THEN
8958 asn_debug.put_line('Validating vendor id in PO ' || TO_CHAR(x_ref_integrity_rec.vendor_id));
8959 asn_debug.put_line('PO Header Id ' || TO_CHAR(x_ref_integrity_rec.po_header_id));
8960 END IF;
8961
8962 IF x_ref_integrity_rec.vendor_id IS NOT NULL THEN
8963 SELECT NVL(MAX(vendor_id), 0)
8964 INTO x_po_vendor_id
8965 FROM po_headers
8966 WHERE po_header_id = x_ref_integrity_rec.po_header_id
8967 AND vendor_id = x_ref_integrity_rec.vendor_id;
8968
8969 IF (x_po_vendor_id = 0) THEN
8970 rcv_error_pkg.set_error_message('RCV_NOT_PO_VEN');
8971 RAISE e_validation_error;
8972 END IF;
8973 END IF;
8974
8975 -- Check for header.vendor = lines.vendor
8976 IF x_header_record.header_record.vendor_id IS NOT NULL THEN
8977 IF x_header_record.header_record.vendor_id <> NVL(x_ref_integrity_rec.vendor_id, x_header_record.header_record.vendor_id) THEN
8978 rcv_error_pkg.set_error_message('RCV_ERC_MISMATCH_PO_VENDOR');
8979 RAISE e_validation_error;
8980 END IF;
8981 END IF;
8982
8983 IF x_ref_integrity_rec.vendor_site_id IS NOT NULL THEN
8984 /*
8985 BUG 6447564.
8986 Changed the vendor_site_id validation code.
8987 Added parent_txn_id condition so as to take into account,
8988 the possibility that the vendor_site can change on a PO even after
8989 receipts have been created.
8990 So now incase of null parent txn id we see from PO_headers and
8991 incase of non-null parent_txn_id we look for the parent txn's vendor_site_id.
8992 */
8993 IF (x_ref_integrity_rec.parent_txn_id IS NULL) THEN
8994
8995 SELECT NVL(MAX(vendor_site_id), 0)
8996 INTO x_po_vendor_site_id
8997 FROM po_headers
8998 WHERE po_header_id = x_ref_integrity_rec.po_header_id
8999 AND vendor_site_id = x_ref_integrity_rec.vendor_site_id;
9000
9001 asn_debug.put_line('vendor_site_id from PO_HEADERS ' || TO_CHAR(x_po_vendor_site_id));
9002
9003 END IF;
9004
9005 IF (x_ref_integrity_rec.parent_txn_id IS NOT NULL) THEN
9006
9007 SELECT NVL(MAX(vendor_site_id), 0)
9008 INTO x_po_vendor_site_id
9009 FROM rcv_transactions
9010 WHERE po_header_id = x_ref_integrity_rec.po_header_id
9011 AND transaction_id = x_ref_integrity_rec.parent_txn_id
9012 AND vendor_site_id = x_ref_integrity_rec.vendor_site_id;
9013
9014 asn_debug.put_line('vendor_site_id from RCV_TRANSACTIONS ' || TO_CHAR(x_po_vendor_site_id));
9015
9016 END IF;
9017
9018
9019 IF (x_po_vendor_site_id = 0) THEN
9020 rcv_error_pkg.set_error_message('RCV_NOT_PO_VEN_SITE');
9021 RAISE e_validation_error;
9022 END IF;
9023 END IF;
9024
9025 IF x_ref_integrity_rec.po_revision_num IS NOT NULL THEN
9026 IF (g_asn_debug = 'Y') THEN
9027 asn_debug.put_line('po_revision_num: ' || x_ref_integrity_rec.po_revision_num);
9028 END IF;
9029
9030 SELECT NVL(MAX(vendor_site_id), 0)
9031 INTO x_po_vendor_site_id
9032 FROM po_headers
9033 WHERE po_header_id = x_ref_integrity_rec.po_header_id
9034 AND revision_num = x_ref_integrity_rec.po_revision_num;
9035
9036 IF (x_po_vendor_site_id = 0) THEN
9037 rcv_error_pkg.set_error_message('RCV_NOT_PO_REVISION');
9038 RAISE e_validation_error;
9039 END IF;
9040 END IF;
9041 EXCEPTION
9042 WHEN e_validation_error THEN
9043 x_ref_integrity_rec.error_record.error_status := x_error_status;
9044 x_ref_integrity_rec.error_record.error_message := rcv_error_pkg.get_last_message;
9045
9046 IF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_VEN_ITEM' THEN
9047 rcv_error_pkg.set_token('PO_SUPPLIER_ITEM', '');
9048 rcv_error_pkg.set_token('SHIPMENT_SUPPLIER_ITEM', x_ref_integrity_rec.vendor_item_num);
9049 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_VEN' THEN
9050 rcv_error_pkg.set_token('PO_SUPPLIER', '');
9051 rcv_error_pkg.set_token('SHIPMENT_SUPPLIER', x_ref_integrity_rec.vendor_id);
9052 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_ERC_MISMATCH_PO_VENDOR' THEN
9053 NULL;
9054 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_VEN_SITE' THEN
9055 rcv_error_pkg.set_token('PO_SUPPLIER_SITE', '');
9056 rcv_error_pkg.set_token('SHIPMENT_SUPPLIER_SITE', x_ref_integrity_rec.vendor_site_id);
9057 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_REVISION' THEN
9058 rcv_error_pkg.set_token('PO_REV', '');
9059 rcv_error_pkg.set_token('SHIPMENT_REV', x_ref_integrity_rec.po_revision_num);
9060 END IF;
9061 END validate_ref_integ;
9062
9063 PROCEDURE validate_temp_labor_info(
9064 v_trans_tab IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9065 n IN BINARY_INTEGER,
9066 v_header_record IN rcv_roi_preprocessor.header_rec_type
9067 ) IS
9068 x_error_status VARCHAR2(1);
9069 BEGIN
9070 x_error_status := rcv_error_pkg.g_ret_sts_error;
9071
9072 IF v_trans_tab(n).error_status NOT IN('S', 'W') THEN
9073 RETURN;
9074 END IF;
9075
9076 IF v_trans_tab(n).matching_basis = 'AMOUNT'
9077 AND v_trans_tab(n).purchase_basis = 'TEMP LABOR' THEN
9078 IF v_trans_tab(n).job_id IS NULL
9079 OR v_trans_tab(n).timecard_id IS NULL
9080 OR v_trans_tab(n).timecard_ovn IS NULL THEN
9081 rcv_error_pkg.set_error_message('RCV_NO_TEMP_LABOR_INFO');
9082 RAISE e_validation_error;
9083 END IF;
9084 END IF;
9085 EXCEPTION
9086 WHEN e_validation_error THEN
9087 v_trans_tab(n).error_status := x_error_status;
9088 v_trans_tab(n).error_message := rcv_error_pkg.get_last_message;
9089
9090 IF v_trans_tab(n).error_message = 'RCV_NO_TEMP_LABOR_INFO' THEN
9091 NULL;
9092 END IF;
9093 END validate_temp_labor_info;
9094
9095 PROCEDURE validate_amount(
9096 v_trans_tab IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9097 n IN BINARY_INTEGER,
9098 v_header_record IN rcv_roi_preprocessor.header_rec_type
9099 ) IS
9100 x_error_status VARCHAR2(1);
9101 BEGIN
9102 x_error_status := rcv_error_pkg.g_ret_sts_error;
9103
9104 IF v_trans_tab(n).error_status NOT IN('S', 'W') THEN
9105 RETURN;
9106 END IF;
9107
9108 IF v_trans_tab(n).matching_basis = 'AMOUNT' THEN
9109 IF v_trans_tab(n).amount IS NULL
9110 OR v_trans_tab(n).amount <= 0 THEN
9111 rcv_error_pkg.set_error_message('RCV_NO_AMOUNT');
9112 RAISE e_validation_error;
9113 END IF;
9114 END IF;
9115 EXCEPTION
9116 WHEN e_validation_error THEN
9117 v_trans_tab(n).error_status := x_error_status;
9118 v_trans_tab(n).error_message := rcv_error_pkg.get_last_message;
9119
9120 IF v_trans_tab(n).error_message = 'RCV_NO_AMOUNT' THEN
9121 NULL;
9122 END IF;
9123 END validate_amount;
9124
9125 PROCEDURE handle_rcv_asn_transactions(
9126 v_trans_tab IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9127 v_header_record IN OUT NOCOPY rcv_roi_preprocessor.header_rec_type
9128 ) IS
9129 v_current_interface_id NUMBER;
9130 v_prior_interface_id NUMBER;
9131 i BINARY_INTEGER := 0;
9132 e_o_t BINARY_INTEGER := 0;
9133 x_rowid VARCHAR2(255);
9134 l_wms_return_status VARCHAR2(1);
9135 l_wms_msg_count NUMBER;
9136 l_wms_msg_data VARCHAR2(400);
9137 lorgid NUMBER; -- For Bug 2110031
9138 --WMS lot serial support
9139 l_orig_trx_id rcv_transactions_interface.interface_transaction_id%TYPE;
9140 l_ls_table inv_rcv_integration_apis.child_rec_tb_tp;
9141 l_ls_table_idx BINARY_INTEGER := 0;
9142 l_api_version NUMBER := 1.0;
9143 l_return_status VARCHAR2(1);
9144 l_msg_count NUMBER;
9145 l_msg_data fnd_new_messages.MESSAGE_TEXT%TYPE;
9146 l_group_id rcv_transactions_interface.GROUP_ID%TYPE;
9147 l_header_interface_id rcv_transactions_interface.header_interface_id%TYPE;
9148 l_interface_transaction_id rcv_transactions_interface.interface_transaction_id%TYPE;
9149 l_return BOOLEAN := TRUE;
9150 l_message VARCHAR2(2000);
9151 l_trx_type rcv_transactions_interface.transaction_type%TYPE;
9152 l_src_doc_code rcv_transactions_interface.source_document_code%TYPE;
9153 l_ship_head_id rcv_transactions_interface.shipment_header_id%TYPE;
9154 l_count NUMBER;
9155 l_cnt NUMBER;
9156 x_fail_all_lines VARCHAR2(1):='N';
9157 BEGIN
9158 IF v_trans_tab.COUNT > 0 THEN --{
9159 i := v_trans_tab.FIRST;
9160 e_o_t := v_trans_tab.LAST;
9161 v_current_interface_id := -999;
9162 v_prior_interface_id := -999;
9163
9164 /* Delete only once from the rcv_transactions_interface table for every
9165 group of pl/sql table rows that have the same interface id */
9166 FOR j IN i .. e_o_t LOOP
9167 asn_debug.put_line('Transaction Type ' || v_trans_tab(j).transaction_type);
9168 v_current_interface_id := v_trans_tab(j).interface_transaction_id;
9169 l_ls_table_idx := l_ls_table.COUNT + 1;
9170
9171 /* SELECT GROUP_SEQUENCE_ID_S.nextval into V_TRANS_TAB(j).GROUP_ID
9172 from dual; -- Check whether this has to be unique */
9173 -- Will use the group_id from the header_record as the pre-processor
9174 -- needs the header and transactions group id to be the same
9175 IF (v_trans_tab(j).transaction_type IN('RECEIVE', 'SHIP')) THEN
9176 v_trans_tab(j).GROUP_ID := v_header_record.header_record.GROUP_ID;
9177 END IF;
9178
9179 asn_debug.put_line('Group id ' || TO_CHAR(v_trans_tab(j).GROUP_ID));
9180 /* Assigning to_organization_id to lorgid which is passed
9181 as a parameter to WMS_INSTALL function .Also added
9182 debug messages .*/
9183 lorgid := v_trans_tab(j).to_organization_id;
9184 asn_debug.put_line('organization id ' || TO_CHAR(v_trans_tab(j).to_organization_id));
9185 asn_debug.put_line('lorgid ' || TO_CHAR(lorgid));
9186
9187 IF v_current_interface_id <> v_prior_interface_id THEN
9188 asn_debug.put_line('Handle the original interface id ' || TO_CHAR(v_trans_tab(j).interface_transaction_id));
9189 asn_debug.put_line('delete from rcv_transactions_interface rowid ' || v_trans_tab(j).row_id);
9190 asn_debug.put_line('matching_basis=' || v_trans_tab(j).matching_basis);
9191
9192 /* WMS Changes */
9193 IF v_trans_tab(j).matching_basis <> 'AMOUNT' THEN
9194 l_orig_trx_id := v_trans_tab(j).interface_transaction_id;
9195 -- add to lot serial table
9196 l_ls_table(l_ls_table_idx).orig_interface_trx_id := l_orig_trx_id;
9197 l_ls_table(l_ls_table_idx).new_interface_trx_id := l_orig_trx_id;
9198 l_ls_table(l_ls_table_idx).quantity := v_trans_tab(j).quantity;
9199 END IF;
9200
9201 IF (g_asn_debug = 'Y') THEN
9202 asn_debug.put_line('Deleting RTI ' || v_trans_tab(j).interface_transaction_id);
9203 END IF;
9204
9205 rcv_trx_interface_delete_pkg.delete_row(v_trans_tab(j).row_id);
9206 /* V_TRANS_TAB(j).INTERFACE_TRANSACTION_ID := NULL; */ -- need to maintain the interface transaction id
9207 -- for error reporting
9208 x_rowid := NULL;
9209
9210 /* FPJ WMS.
9211 * lpn_group_id should not be null if there is lpn info.
9212 */
9213 IF ( ( v_trans_tab(j).lpn_id IS NOT NULL
9214 OR v_trans_tab(j).transfer_lpn_id IS NOT NULL
9215 OR v_trans_tab(j).license_plate_number IS NOT NULL
9216 OR v_trans_tab(j).transfer_license_plate_number IS NOT NULL)
9217 AND v_trans_tab(j).lpn_group_id IS NULL
9218 ) THEN
9219 SELECT rcv_interface_groups_s.NEXTVAL
9220 INTO v_trans_tab(j).lpn_group_id
9221 FROM DUAL;
9222 END IF;
9223
9224 IF (g_asn_debug = 'Y') THEN
9225 asn_debug.put_line('Inserting new RTI');
9226 asn_debug.put_line('category_id ' || v_trans_tab(j).category_id);
9227 asn_debug.put_line('quantity ' || v_trans_tab(j).quantity);
9228 asn_debug.put_line('amount ' || v_trans_tab(j).amount);
9229 asn_debug.put_line('unit_of_measure ' || v_trans_tab(j).unit_of_measure);
9230 asn_debug.put_line('interface_source_code ' || v_trans_tab(j).interface_source_code);
9231 asn_debug.put_line('interface_source_line_id ' || v_trans_tab(j).interface_source_line_id);
9232 asn_debug.put_line('inv_transaction_id ' || v_trans_tab(j).inv_transaction_id);
9233 asn_debug.put_line('item_id ' || v_trans_tab(j).item_id);
9234 asn_debug.put_line('item_description ' || v_trans_tab(j).item_description);
9235 asn_debug.put_line('item_revision ' || v_trans_tab(j).item_revision);
9236 asn_debug.put_line('uom_code ' || v_trans_tab(j).uom_code);
9237 asn_debug.put_line('employee_id ' || v_trans_tab(j).employee_id);
9238 asn_debug.put_line('auto_transact_code ' || v_trans_tab(j).auto_transact_code);
9239 asn_debug.put_line('shipment_header_id ' || v_trans_tab(j).shipment_header_id);
9240 asn_debug.put_line('shipment_header_id ' || v_header_record.header_record.receipt_header_id);
9241 asn_debug.put_line('shipment_line_id ' || v_trans_tab(j).shipment_line_id);
9242 asn_debug.put_line('ship_to_location_id ' || v_trans_tab(j).ship_to_location_id);
9243 asn_debug.put_line('primary_quantity ' || v_trans_tab(j).primary_quantity);
9244 asn_debug.put_line('primary_unit_of_measure ' || v_trans_tab(j).primary_unit_of_measure);
9245 asn_debug.put_line('receipt_source_code ' || v_trans_tab(j).receipt_source_code);
9246 asn_debug.put_line('vendor_id ' || v_trans_tab(j).vendor_id);
9247 asn_debug.put_line('vendor_site_id ' || v_trans_tab(j).vendor_site_id);
9248 asn_debug.put_line('from_organization_id ' || v_trans_tab(j).from_organization_id);
9249 asn_debug.put_line('from_subinventory ' || v_trans_tab(j).from_subinventory);
9250 asn_debug.put_line('to_organization_id ' || v_trans_tab(j).to_organization_id);
9251 asn_debug.put_line('intransit_owning_org_id ' || v_trans_tab(j).intransit_owning_org_id);
9252 asn_debug.put_line('routing_header_id ' || v_trans_tab(j).routing_header_id);
9253 asn_debug.put_line('routing_step_id ' || v_trans_tab(j).routing_step_id);
9254 asn_debug.put_line('source_document_code ' || v_trans_tab(j).source_document_code);
9255 asn_debug.put_line('parent_transaction_id ' || v_trans_tab(j).parent_transaction_id);
9256 asn_debug.put_line('po_header_id ' || v_trans_tab(j).po_header_id);
9257 asn_debug.put_line('po_revision_num ' || v_trans_tab(j).po_revision_num);
9258 asn_debug.put_line('po_line_id ' || v_trans_tab(j).po_line_id);
9259 asn_debug.put_line('po_line_location_id ' || v_trans_tab(j).po_line_location_id);
9260 asn_debug.put_line('po_unit_price ' || v_trans_tab(j).po_unit_price);
9261 asn_debug.put_line('currency_code ' || v_trans_tab(j).currency_code);
9262 asn_debug.put_line('currency_conversion_type ' || v_trans_tab(j).currency_conversion_type);
9263 asn_debug.put_line('currency_conversion_rate ' || v_trans_tab(j).currency_conversion_rate);
9264 asn_debug.put_line('currency_conversion_date ' || TO_CHAR(v_trans_tab(j).currency_conversion_date, 'DD-MON-YYYY HH24:MI:SS'));
9265 asn_debug.put_line('po_distribution_id ' || v_trans_tab(j).po_distribution_id);
9266 asn_debug.put_line('requisition_line_id ' || v_trans_tab(j).requisition_line_id);
9267 asn_debug.put_line('req_distribution_id ' || v_trans_tab(j).req_distribution_id);
9268 asn_debug.put_line('charge_account_id ' || v_trans_tab(j).charge_account_id);
9269 asn_debug.put_line('substitute_unordered_code ' || v_trans_tab(j).substitute_unordered_code);
9270 asn_debug.put_line('receipt_exception_flag ' || v_trans_tab(j).receipt_exception_flag);
9271 asn_debug.put_line('accrual_status_code ' || v_trans_tab(j).accrual_status_code);
9272 asn_debug.put_line('inspection_status_code ' || v_trans_tab(j).inspection_status_code);
9273 asn_debug.put_line('inspection_quality_code ' || v_trans_tab(j).inspection_quality_code);
9274 asn_debug.put_line('destination_type_code ' || v_trans_tab(j).destination_type_code);
9275 asn_debug.put_line('deliver_to_person_id ' || v_trans_tab(j).deliver_to_person_id);
9276 asn_debug.put_line('location_id ' || v_trans_tab(j).location_id);
9277 asn_debug.put_line('deliver_to_location_id ' || v_trans_tab(j).deliver_to_location_id);
9278 asn_debug.put_line('subinventory ' || v_trans_tab(j).subinventory);
9279 asn_debug.put_line('locator_id ' || v_trans_tab(j).locator_id);
9280 asn_debug.put_line('wip_entity_id ' || v_trans_tab(j).wip_entity_id);
9281 asn_debug.put_line('wip_line_id ' || v_trans_tab(j).wip_line_id);
9282 asn_debug.put_line('shipment_num ' || v_trans_tab(j).shipment_num);
9283 asn_debug.put_line('source_doc_quantity ' || v_trans_tab(j).source_doc_quantity);
9284 asn_debug.put_line('from_locator_id ' || v_trans_tab(j).from_locator_id);
9285 asn_debug.put_line('oe_order_header_id ' || v_trans_tab(j).oe_order_header_id);
9286 asn_debug.put_line('oe_order_line_id ' || v_trans_tab(j).oe_order_line_id);
9287 asn_debug.put_line('customer_id ' || v_trans_tab(j).customer_id);
9288 asn_debug.put_line('customer_site_id ' || v_trans_tab(j).customer_site_id);
9289 asn_debug.put_line('lpn_id ' || v_trans_tab(j).lpn_id);
9290 asn_debug.put_line('transfer_lpn_id ' || v_trans_tab(j).transfer_lpn_id);
9291 asn_debug.put_line('lpn_group_id ' || v_trans_tab(j).lpn_group_id);
9292 asn_debug.put_line('project_id ' || v_trans_tab(j).project_id);
9293 asn_debug.put_line('task_id ' || v_trans_tab(j).task_id);
9294 asn_debug.put_line('timecard_id ' ||
9295 v_trans_tab(j).timecard_id);
9296 asn_debug.put_line('timecard_ovn ' ||
9297 v_trans_tab(j).timecard_ovn);
9298 asn_debug.put_line('org_id ' || v_trans_tab(j).org_id); --<R12 MOAC>
9299
9300 asn_debug.put_line('matching_basis ' ||
9301 v_trans_tab(j).matching_basis);
9302 asn_debug.put_line('amount_shipped ' ||
9303 v_trans_tab(j).amount_shipped);
9304 asn_debug.put_line('requested_amount ' ||
9305 v_trans_tab(j).requested_amount);
9306 asn_debug.put_line('material_stored_amount ' ||
9307 v_trans_tab(j).material_stored_amount);
9308 asn_debug.put_line('replenish_order_line_id' ||
9309 v_trans_tab(j).replenish_order_line_id);
9310 asn_debug.put_line('express_transaction' || v_trans_tab(j).express_transaction); -- Bug 14067935
9311 asn_debug.put_line('lcm_shipment_line_id' || v_trans_tab(j).lcm_shipment_line_id);
9312 asn_debug.put_line('unit_landed_cost' || v_trans_tab(j).unit_landed_cost);
9313
9314 END IF;
9315
9316 rcv_asn_interface_trx_ins_pkg.insert_row(v_trans_tab(j).row_id,
9317 v_trans_tab(j).interface_transaction_id,
9318 v_trans_tab(j).GROUP_ID,
9319 v_trans_tab(j).last_update_date,
9320 v_trans_tab(j).last_updated_by,
9321 v_trans_tab(j).creation_date,
9322 v_trans_tab(j).created_by,
9323 v_trans_tab(j).last_update_login,
9324 v_trans_tab(j).request_id,
9325 v_trans_tab(j).program_application_id,
9326 v_trans_tab(j).program_id,
9327 v_trans_tab(j).program_update_date,
9328 v_trans_tab(j).transaction_type,
9329 v_trans_tab(j).transaction_date,
9330 v_trans_tab(j).processing_status_code,
9331 v_trans_tab(j).processing_mode_code,
9332 v_trans_tab(j).processing_request_id,
9333 v_trans_tab(j).transaction_status_code,
9334 v_trans_tab(j).category_id,
9335 v_trans_tab(j).quantity,
9336 v_trans_tab(j).unit_of_measure,
9337 v_trans_tab(j).interface_source_code,
9338 v_trans_tab(j).interface_source_line_id,
9339 v_trans_tab(j).inv_transaction_id,
9340 v_trans_tab(j).item_id,
9341 v_trans_tab(j).item_description,
9342 v_trans_tab(j).item_revision,
9343 v_trans_tab(j).uom_code,
9344 v_trans_tab(j).employee_id,
9345 v_trans_tab(j).auto_transact_code,
9346 NVL(v_trans_tab(j).shipment_header_id, v_header_record.header_record.receipt_header_id),
9347 v_trans_tab(j).shipment_line_id,
9348 v_trans_tab(j).ship_to_location_id,
9349 v_trans_tab(j).primary_quantity,
9350 v_trans_tab(j).primary_unit_of_measure,
9351 v_trans_tab(j).receipt_source_code,
9352 v_trans_tab(j).vendor_id,
9353 v_trans_tab(j).vendor_site_id,
9354 v_trans_tab(j).from_organization_id,
9355 v_trans_tab(j).from_subinventory,
9356 v_trans_tab(j).to_organization_id,
9357 v_trans_tab(j).intransit_owning_org_id,
9358 v_trans_tab(j).routing_header_id,
9359 v_trans_tab(j).routing_step_id,
9360 v_trans_tab(j).source_document_code,
9361 v_trans_tab(j).parent_transaction_id,
9362 v_trans_tab(j).po_header_id,
9363 v_trans_tab(j).po_revision_num,
9364 v_trans_tab(j).po_release_id,
9365 v_trans_tab(j).po_line_id,
9366 v_trans_tab(j).po_line_location_id,
9367 v_trans_tab(j).po_unit_price,
9368 v_trans_tab(j).currency_code,
9369 v_trans_tab(j).currency_conversion_type,
9370 v_trans_tab(j).currency_conversion_rate,
9371 v_trans_tab(j).currency_conversion_date,
9372 v_trans_tab(j).po_distribution_id,
9373 v_trans_tab(j).requisition_line_id,
9374 v_trans_tab(j).req_distribution_id,
9375 v_trans_tab(j).charge_account_id,
9376 v_trans_tab(j).substitute_unordered_code,
9377 v_trans_tab(j).receipt_exception_flag,
9378 v_trans_tab(j).accrual_status_code,
9379 v_trans_tab(j).inspection_status_code,
9380 v_trans_tab(j).inspection_quality_code,
9381 v_trans_tab(j).destination_type_code,
9382 v_trans_tab(j).deliver_to_person_id,
9383 v_trans_tab(j).location_id,
9384 v_trans_tab(j).deliver_to_location_id,
9385 v_trans_tab(j).subinventory,
9386 v_trans_tab(j).locator_id,
9387 v_trans_tab(j).wip_entity_id,
9388 v_trans_tab(j).wip_line_id,
9389 v_trans_tab(j).department_code,
9390 v_trans_tab(j).wip_repetitive_schedule_id,
9391 v_trans_tab(j).wip_operation_seq_num,
9392 v_trans_tab(j).wip_resource_seq_num,
9393 v_trans_tab(j).bom_resource_id,
9394 v_trans_tab(j).shipment_num,
9395 v_trans_tab(j).freight_carrier_code,
9396 v_trans_tab(j).bill_of_lading,
9397 v_trans_tab(j).packing_slip,
9398 v_trans_tab(j).shipped_date,
9399 v_trans_tab(j).expected_receipt_date,
9400 v_trans_tab(j).actual_cost,
9401 v_trans_tab(j).transfer_cost,
9402 v_trans_tab(j).transportation_cost,
9403 v_trans_tab(j).transportation_account_id,
9404 v_trans_tab(j).num_of_containers,
9405 v_trans_tab(j).waybill_airbill_num,
9406 v_trans_tab(j).vendor_item_num,
9407 v_trans_tab(j).vendor_lot_num,
9408 v_trans_tab(j).rma_reference,
9409 v_trans_tab(j).comments,
9410 v_trans_tab(j).attribute_category,
9411 v_trans_tab(j).attribute1,
9412 v_trans_tab(j).attribute2,
9413 v_trans_tab(j).attribute3,
9414 v_trans_tab(j).attribute4,
9415 v_trans_tab(j).attribute5,
9416 v_trans_tab(j).attribute6,
9417 v_trans_tab(j).attribute7,
9418 v_trans_tab(j).attribute8,
9419 v_trans_tab(j).attribute9,
9420 v_trans_tab(j).attribute10,
9421 v_trans_tab(j).attribute11,
9422 v_trans_tab(j).attribute12,
9423 v_trans_tab(j).attribute13,
9424 v_trans_tab(j).attribute14,
9425 v_trans_tab(j).attribute15,
9426 v_trans_tab(j).ship_head_attribute_category,
9427 v_trans_tab(j).ship_head_attribute1,
9428 v_trans_tab(j).ship_head_attribute2,
9429 v_trans_tab(j).ship_head_attribute3,
9430 v_trans_tab(j).ship_head_attribute4,
9431 v_trans_tab(j).ship_head_attribute5,
9432 v_trans_tab(j).ship_head_attribute6,
9433 v_trans_tab(j).ship_head_attribute7,
9434 v_trans_tab(j).ship_head_attribute8,
9435 v_trans_tab(j).ship_head_attribute9,
9436 v_trans_tab(j).ship_head_attribute10,
9437 v_trans_tab(j).ship_head_attribute11,
9438 v_trans_tab(j).ship_head_attribute12,
9439 v_trans_tab(j).ship_head_attribute13,
9440 v_trans_tab(j).ship_head_attribute14,
9441 v_trans_tab(j).ship_head_attribute15,
9442 v_trans_tab(j).ship_line_attribute_category,
9443 v_trans_tab(j).ship_line_attribute1,
9444 v_trans_tab(j).ship_line_attribute2,
9445 v_trans_tab(j).ship_line_attribute3,
9446 v_trans_tab(j).ship_line_attribute4,
9447 v_trans_tab(j).ship_line_attribute5,
9448 v_trans_tab(j).ship_line_attribute6,
9449 v_trans_tab(j).ship_line_attribute7,
9450 v_trans_tab(j).ship_line_attribute8,
9451 v_trans_tab(j).ship_line_attribute9,
9452 v_trans_tab(j).ship_line_attribute10,
9453 v_trans_tab(j).ship_line_attribute11,
9454 v_trans_tab(j).ship_line_attribute12,
9455 v_trans_tab(j).ship_line_attribute13,
9456 v_trans_tab(j).ship_line_attribute14,
9457 v_trans_tab(j).ship_line_attribute15,
9458 v_trans_tab(j).ussgl_transaction_code,
9459 v_trans_tab(j).government_context,
9460 v_trans_tab(j).reason_id,
9461 v_trans_tab(j).destination_context,
9462 v_trans_tab(j).source_doc_quantity,
9463 v_trans_tab(j).source_doc_unit_of_measure,
9464 v_trans_tab(j).movement_id,
9465 v_trans_tab(j).header_interface_id,
9466 v_trans_tab(j).vendor_cum_shipped_qty,
9467 v_trans_tab(j).item_num,
9468 v_trans_tab(j).document_num,
9469 v_trans_tab(j).document_line_num,
9470 v_trans_tab(j).truck_num,
9471 v_trans_tab(j).ship_to_location_code,
9472 v_trans_tab(j).container_num,
9473 v_trans_tab(j).substitute_item_num,
9474 v_trans_tab(j).notice_unit_price,
9475 v_trans_tab(j).item_category,
9476 v_trans_tab(j).location_code,
9477 v_trans_tab(j).vendor_name,
9478 v_trans_tab(j).vendor_num,
9479 v_trans_tab(j).vendor_site_code,
9480 v_trans_tab(j).from_organization_code,
9481 v_trans_tab(j).to_organization_code,
9482 v_trans_tab(j).intransit_owning_org_code,
9483 v_trans_tab(j).routing_code,
9484 v_trans_tab(j).routing_step,
9485 v_trans_tab(j).release_num,
9486 v_trans_tab(j).document_shipment_line_num,
9487 v_trans_tab(j).document_distribution_num,
9488 v_trans_tab(j).deliver_to_person_name,
9489 v_trans_tab(j).deliver_to_location_code,
9490 v_trans_tab(j).use_mtl_lot,
9491 v_trans_tab(j).use_mtl_serial,
9492 v_trans_tab(j).LOCATOR,
9493 v_trans_tab(j).reason_name,
9494 v_trans_tab(j).validation_flag,
9495 v_trans_tab(j).substitute_item_id,
9496 v_trans_tab(j).quantity_shipped,
9497 v_trans_tab(j).quantity_invoiced,
9498 v_trans_tab(j).tax_name,
9499 v_trans_tab(j).tax_amount,
9500 v_trans_tab(j).req_num,
9501 v_trans_tab(j).req_line_num,
9502 v_trans_tab(j).req_distribution_num,
9503 v_trans_tab(j).wip_entity_name,
9504 v_trans_tab(j).wip_line_code,
9505 v_trans_tab(j).resource_code,
9506 v_trans_tab(j).shipment_line_status_code,
9507 v_trans_tab(j).barcode_label,
9508 v_trans_tab(j).country_of_origin_code,
9509 v_trans_tab(j).from_locator_id, --WMS Change
9510 v_trans_tab(j).qa_collection_id,
9511 v_trans_tab(j).oe_order_header_id,
9512 v_trans_tab(j).oe_order_line_id,
9513 v_trans_tab(j).customer_id,
9514 v_trans_tab(j).customer_site_id,
9515 v_trans_tab(j).customer_item_num,
9516 v_trans_tab(j).create_debit_memo_flag,
9517 v_trans_tab(j).put_away_rule_id,
9518 v_trans_tab(j).put_away_strategy_id,
9519 v_trans_tab(j).lpn_id,
9520 v_trans_tab(j).transfer_lpn_id,
9521 v_trans_tab(j).cost_group_id,
9522 v_trans_tab(j).mobile_txn,
9523 v_trans_tab(j).mmtt_temp_id,
9524 v_trans_tab(j).transfer_cost_group_id,
9525 v_trans_tab(j).secondary_quantity,
9526 v_trans_tab(j).secondary_unit_of_measure,
9527 v_trans_tab(j).secondary_uom_code,
9528 v_trans_tab(j).qc_grade,
9529 v_trans_tab(j).oe_order_num,
9530 v_trans_tab(j).oe_order_line_num,
9531 v_trans_tab(j).customer_account_number,
9532 v_trans_tab(j).customer_party_name,
9533 v_trans_tab(j).source_transaction_num,
9534 v_trans_tab(j).parent_source_transaction_num,
9535 v_trans_tab(j).parent_interface_txn_id,
9536 v_trans_tab(j).customer_item_id,
9537 v_trans_tab(j).interface_available_qty,
9538 v_trans_tab(j).interface_transaction_qty,
9539 v_trans_tab(j).from_locator,
9540 v_trans_tab(j).lpn_group_id,
9541 v_trans_tab(j).order_transaction_id,
9542 v_trans_tab(j).license_plate_number,
9543 v_trans_tab(j).transfer_license_plate_number,
9544 v_trans_tab(j).amount,
9545 v_trans_tab(j).job_id,
9546 v_trans_tab(j).project_id,
9547 v_trans_tab(j).task_id,
9548 v_trans_tab(j).asn_attach_id,
9549 v_trans_tab(j).timecard_id,
9550 v_trans_tab(j).timecard_ovn,
9551 v_trans_tab(j).interface_available_amt,
9552 v_trans_tab(j).interface_transaction_amt,
9553 v_trans_tab(j).org_id, --<R12 MOAC>
9554 v_trans_tab(j).matching_basis,
9555 v_trans_tab(j).amount_shipped,
9556 v_trans_tab(j).requested_amount,
9557 v_trans_tab(j).material_stored_amount,
9558 v_trans_tab(j).replenish_order_line_id,
9559 v_trans_tab(j).express_transaction,--NULL, -- Bug 14067935
9560 v_trans_tab(j).lcm_shipment_line_id, -- lcm changes
9561 v_trans_tab(j).unit_landed_cost -- lcm changes
9562 );
9563 asn_debug.put_line('RowId ' || v_trans_tab(j).row_id);
9564 asn_debug.put_line('Interface Id ' || TO_CHAR(v_trans_tab(j).interface_transaction_id));
9565 v_prior_interface_id := v_current_interface_id;
9566 v_trans_tab.DELETE(j);
9567 ELSE
9568 asn_debug.put_line('insert into rcv_transactions_interface with new id ');
9569 /* Since we are inserting 1-> many rows need to generate a new interface id */
9570 v_trans_tab(j).interface_transaction_id := NULL;
9571 x_rowid := NULL;
9572
9573 /* FPJ WMS.
9574 * lpn_group_id should not be null if there is lpn info. But
9575 * since this is a split line coming from the original rti line,
9576 * this has to have the same lpn group id.
9577 */
9578 IF ( ( v_trans_tab(j).lpn_id IS NOT NULL
9579 OR v_trans_tab(j).transfer_lpn_id IS NOT NULL
9580 OR v_trans_tab(j).license_plate_number IS NOT NULL
9581 OR v_trans_tab(j).transfer_license_plate_number IS NOT NULL)
9582 AND v_trans_tab(j).lpn_group_id IS NULL
9583 ) THEN
9584 SELECT rcv_interface_groups_s.CURRVAL
9585 INTO v_trans_tab(j).lpn_group_id
9586 FROM DUAL;
9587 END IF;
9588
9589 IF (g_asn_debug = 'Y') THEN
9590 asn_debug.put_line('category_id ' || v_trans_tab(j).category_id);
9591 asn_debug.put_line('quantity ' || v_trans_tab(j).quantity);
9592 asn_debug.put_line('amount ' || v_trans_tab(j).amount);
9593 asn_debug.put_line('unit_of_measure ' || v_trans_tab(j).unit_of_measure);
9594 asn_debug.put_line('interface_source_code ' || v_trans_tab(j).interface_source_code);
9595 asn_debug.put_line('interface_source_line_id ' || v_trans_tab(j).interface_source_line_id);
9596 asn_debug.put_line('inv_transaction_id ' || v_trans_tab(j).inv_transaction_id);
9597 asn_debug.put_line('item_id ' || v_trans_tab(j).item_id);
9598 asn_debug.put_line('item_description ' || v_trans_tab(j).item_description);
9599 asn_debug.put_line('item_revision ' || v_trans_tab(j).item_revision);
9600 asn_debug.put_line('uom_code ' || v_trans_tab(j).uom_code);
9601 asn_debug.put_line('employee_id ' || v_trans_tab(j).employee_id);
9602 asn_debug.put_line('auto_transact_code ' || v_trans_tab(j).auto_transact_code);
9603 asn_debug.put_line('shipment_header_id ' || v_trans_tab(j).shipment_header_id);
9604 asn_debug.put_line('shipment_header_id ' || v_header_record.header_record.receipt_header_id);
9605 asn_debug.put_line('shipment_line_id ' || v_trans_tab(j).shipment_line_id);
9606 asn_debug.put_line('ship_to_location_id ' || v_trans_tab(j).ship_to_location_id);
9607 asn_debug.put_line('primary_quantity ' || v_trans_tab(j).primary_quantity);
9608 asn_debug.put_line('primary_unit_of_measure ' || v_trans_tab(j).primary_unit_of_measure);
9609 asn_debug.put_line('receipt_source_code ' || v_trans_tab(j).receipt_source_code);
9610 asn_debug.put_line('vendor_id ' || v_trans_tab(j).vendor_id);
9611 asn_debug.put_line('vendor_site_id ' || v_trans_tab(j).vendor_site_id);
9612 asn_debug.put_line('from_organization_id ' || v_trans_tab(j).from_organization_id);
9613 asn_debug.put_line('from_subinventory ' || v_trans_tab(j).from_subinventory);
9614 asn_debug.put_line('to_organization_id ' || v_trans_tab(j).to_organization_id);
9615 asn_debug.put_line('intransit_owning_org_id ' || v_trans_tab(j).intransit_owning_org_id);
9616 asn_debug.put_line('routing_header_id ' || v_trans_tab(j).routing_header_id);
9617 asn_debug.put_line('routing_step_id ' || v_trans_tab(j).routing_step_id);
9618 asn_debug.put_line('source_document_code ' || v_trans_tab(j).source_document_code);
9619 asn_debug.put_line('parent_transaction_id ' || v_trans_tab(j).parent_transaction_id);
9620 asn_debug.put_line('po_header_id ' || v_trans_tab(j).po_header_id);
9621 asn_debug.put_line('po_revision_num ' || v_trans_tab(j).po_revision_num);
9622 asn_debug.put_line('po_line_id ' || v_trans_tab(j).po_line_id);
9623 asn_debug.put_line('po_line_location_id ' || v_trans_tab(j).po_line_location_id);
9624 asn_debug.put_line('po_unit_price ' || v_trans_tab(j).po_unit_price);
9625 asn_debug.put_line('currency_code ' || v_trans_tab(j).currency_code);
9626 asn_debug.put_line('currency_conversion_type ' || v_trans_tab(j).currency_conversion_type);
9627 asn_debug.put_line('currency_conversion_rate ' || v_trans_tab(j).currency_conversion_rate);
9628 asn_debug.put_line('currency_conversion_date ' || TO_CHAR(v_trans_tab(j).currency_conversion_date, 'DD-MON-YYYY HH24:MI:SS'));
9629 asn_debug.put_line('po_distribution_id ' || v_trans_tab(j).po_distribution_id);
9630 asn_debug.put_line('requisition_line_id ' || v_trans_tab(j).requisition_line_id);
9631 asn_debug.put_line('req_distribution_id ' || v_trans_tab(j).req_distribution_id);
9632 asn_debug.put_line('charge_account_id ' || v_trans_tab(j).charge_account_id);
9633 asn_debug.put_line('substitute_unordered_code ' || v_trans_tab(j).substitute_unordered_code);
9634 asn_debug.put_line('receipt_exception_flag ' || v_trans_tab(j).receipt_exception_flag);
9635 asn_debug.put_line('accrual_status_code ' || v_trans_tab(j).accrual_status_code);
9636 asn_debug.put_line('inspection_status_code ' || v_trans_tab(j).inspection_status_code);
9637 asn_debug.put_line('inspection_quality_code ' || v_trans_tab(j).inspection_quality_code);
9638 asn_debug.put_line('destination_type_code ' || v_trans_tab(j).destination_type_code);
9639 asn_debug.put_line('deliver_to_person_id ' || v_trans_tab(j).deliver_to_person_id);
9640 asn_debug.put_line('location_id ' || v_trans_tab(j).location_id);
9641 asn_debug.put_line('deliver_to_location_id ' || v_trans_tab(j).deliver_to_location_id);
9642 asn_debug.put_line('subinventory ' || v_trans_tab(j).subinventory);
9643 asn_debug.put_line('locator_id ' || v_trans_tab(j).locator_id);
9644 asn_debug.put_line('wip_entity_id ' || v_trans_tab(j).wip_entity_id);
9645 asn_debug.put_line('wip_line_id ' || v_trans_tab(j).wip_line_id);
9646 asn_debug.put_line('shipment_num ' || v_trans_tab(j).shipment_num);
9647 asn_debug.put_line('source_doc_quantity ' || v_trans_tab(j).source_doc_quantity);
9648 asn_debug.put_line('from_locator_id ' || v_trans_tab(j).from_locator_id);
9649 asn_debug.put_line('oe_order_header_id ' || v_trans_tab(j).oe_order_header_id);
9650 asn_debug.put_line('oe_order_line_id ' || v_trans_tab(j).oe_order_line_id);
9651 asn_debug.put_line('customer_id ' || v_trans_tab(j).customer_id);
9652 asn_debug.put_line('customer_site_id ' || v_trans_tab(j).customer_site_id);
9653 asn_debug.put_line('lpn_id ' || v_trans_tab(j).lpn_id);
9654 asn_debug.put_line('transfer_lpn_id ' || v_trans_tab(j).transfer_lpn_id);
9655 asn_debug.put_line('lpn_group_id ' || v_trans_tab(j).lpn_group_id);
9656 asn_debug.put_line('project_id ' || v_trans_tab(j).project_id);
9657 asn_debug.put_line('task_id ' || v_trans_tab(j).task_id);
9658 asn_debug.put_line('timecard_id ' || v_trans_tab(j).timecard_id);
9659 asn_debug.put_line('timecard_ovn ' || v_trans_tab(j).timecard_ovn);
9660 asn_debug.put_line('org_id ' || v_trans_tab(j).org_id); --<R12 MOAC>
9661 asn_debug.put_line('matching_basis ' ||
9662 v_trans_tab(j).matching_basis);
9663 asn_debug.put_line('amount_shipped ' ||
9664 v_trans_tab(j).amount_shipped);
9665 asn_debug.put_line('requested_amount ' ||
9666 v_trans_tab(j).requested_amount);
9667 asn_debug.put_line('material_stored_amount ' ||
9668 v_trans_tab(j).material_stored_amount);
9669 asn_debug.put_line('replenish_order_line_id' ||
9670 v_trans_tab(j).replenish_order_line_id);
9671 asn_debug.put_line('express_transaction' || v_trans_tab(j).express_transaction); -- Bug 14067935
9672 END IF;
9673
9674 rcv_asn_interface_trx_ins_pkg.insert_row(v_trans_tab(j).row_id,
9675 v_trans_tab(j).interface_transaction_id,
9676 v_trans_tab(j).GROUP_ID,
9677 v_trans_tab(j).last_update_date,
9678 v_trans_tab(j).last_updated_by,
9679 v_trans_tab(j).creation_date,
9680 v_trans_tab(j).created_by,
9681 v_trans_tab(j).last_update_login,
9682 v_trans_tab(j).request_id,
9683 v_trans_tab(j).program_application_id,
9684 v_trans_tab(j).program_id,
9685 v_trans_tab(j).program_update_date,
9686 v_trans_tab(j).transaction_type,
9687 v_trans_tab(j).transaction_date,
9688 v_trans_tab(j).processing_status_code,
9689 v_trans_tab(j).processing_mode_code,
9690 v_trans_tab(j).processing_request_id,
9691 v_trans_tab(j).transaction_status_code,
9692 v_trans_tab(j).category_id,
9693 v_trans_tab(j).quantity,
9694 v_trans_tab(j).unit_of_measure,
9695 v_trans_tab(j).interface_source_code,
9696 v_trans_tab(j).interface_source_line_id,
9697 v_trans_tab(j).inv_transaction_id,
9698 v_trans_tab(j).item_id,
9699 v_trans_tab(j).item_description,
9700 v_trans_tab(j).item_revision,
9701 v_trans_tab(j).uom_code,
9702 v_trans_tab(j).employee_id,
9703 v_trans_tab(j).auto_transact_code,
9704 NVL(v_trans_tab(j).shipment_header_id, v_header_record.header_record.receipt_header_id),
9705 v_trans_tab(j).shipment_line_id,
9706 v_trans_tab(j).ship_to_location_id,
9707 v_trans_tab(j).primary_quantity,
9708 v_trans_tab(j).primary_unit_of_measure,
9709 v_trans_tab(j).receipt_source_code,
9710 v_trans_tab(j).vendor_id,
9711 v_trans_tab(j).vendor_site_id,
9712 v_trans_tab(j).from_organization_id,
9713 v_trans_tab(j).from_subinventory,
9714 v_trans_tab(j).to_organization_id,
9715 v_trans_tab(j).intransit_owning_org_id,
9716 v_trans_tab(j).routing_header_id,
9717 v_trans_tab(j).routing_step_id,
9718 v_trans_tab(j).source_document_code,
9719 v_trans_tab(j).parent_transaction_id,
9720 v_trans_tab(j).po_header_id,
9721 v_trans_tab(j).po_revision_num,
9722 v_trans_tab(j).po_release_id,
9723 v_trans_tab(j).po_line_id,
9724 v_trans_tab(j).po_line_location_id,
9725 v_trans_tab(j).po_unit_price,
9726 v_trans_tab(j).currency_code,
9727 v_trans_tab(j).currency_conversion_type,
9728 v_trans_tab(j).currency_conversion_rate,
9729 v_trans_tab(j).currency_conversion_date,
9730 v_trans_tab(j).po_distribution_id,
9731 v_trans_tab(j).requisition_line_id,
9732 v_trans_tab(j).req_distribution_id,
9733 v_trans_tab(j).charge_account_id,
9734 v_trans_tab(j).substitute_unordered_code,
9735 v_trans_tab(j).receipt_exception_flag,
9736 v_trans_tab(j).accrual_status_code,
9737 v_trans_tab(j).inspection_status_code,
9738 v_trans_tab(j).inspection_quality_code,
9739 v_trans_tab(j).destination_type_code,
9740 v_trans_tab(j).deliver_to_person_id,
9741 v_trans_tab(j).location_id,
9742 v_trans_tab(j).deliver_to_location_id,
9743 v_trans_tab(j).subinventory,
9744 v_trans_tab(j).locator_id,
9745 v_trans_tab(j).wip_entity_id,
9746 v_trans_tab(j).wip_line_id,
9747 v_trans_tab(j).department_code,
9748 v_trans_tab(j).wip_repetitive_schedule_id,
9749 v_trans_tab(j).wip_operation_seq_num,
9750 v_trans_tab(j).wip_resource_seq_num,
9751 v_trans_tab(j).bom_resource_id,
9752 v_trans_tab(j).shipment_num,
9753 v_trans_tab(j).freight_carrier_code,
9754 v_trans_tab(j).bill_of_lading,
9755 v_trans_tab(j).packing_slip,
9756 v_trans_tab(j).shipped_date,
9757 v_trans_tab(j).expected_receipt_date,
9758 v_trans_tab(j).actual_cost,
9759 v_trans_tab(j).transfer_cost,
9760 v_trans_tab(j).transportation_cost,
9761 v_trans_tab(j).transportation_account_id,
9762 v_trans_tab(j).num_of_containers,
9763 v_trans_tab(j).waybill_airbill_num,
9764 v_trans_tab(j).vendor_item_num,
9765 v_trans_tab(j).vendor_lot_num,
9766 v_trans_tab(j).rma_reference,
9767 v_trans_tab(j).comments,
9768 v_trans_tab(j).attribute_category,
9769 v_trans_tab(j).attribute1,
9770 v_trans_tab(j).attribute2,
9771 v_trans_tab(j).attribute3,
9772 v_trans_tab(j).attribute4,
9773 v_trans_tab(j).attribute5,
9774 v_trans_tab(j).attribute6,
9775 v_trans_tab(j).attribute7,
9776 v_trans_tab(j).attribute8,
9777 v_trans_tab(j).attribute9,
9778 v_trans_tab(j).attribute10,
9779 v_trans_tab(j).attribute11,
9780 v_trans_tab(j).attribute12,
9781 v_trans_tab(j).attribute13,
9782 v_trans_tab(j).attribute14,
9783 v_trans_tab(j).attribute15,
9784 v_trans_tab(j).ship_head_attribute_category,
9785 v_trans_tab(j).ship_head_attribute1,
9786 v_trans_tab(j).ship_head_attribute2,
9787 v_trans_tab(j).ship_head_attribute3,
9788 v_trans_tab(j).ship_head_attribute4,
9789 v_trans_tab(j).ship_head_attribute5,
9790 v_trans_tab(j).ship_head_attribute6,
9791 v_trans_tab(j).ship_head_attribute7,
9792 v_trans_tab(j).ship_head_attribute8,
9793 v_trans_tab(j).ship_head_attribute9,
9794 v_trans_tab(j).ship_head_attribute10,
9795 v_trans_tab(j).ship_head_attribute11,
9796 v_trans_tab(j).ship_head_attribute12,
9797 v_trans_tab(j).ship_head_attribute13,
9798 v_trans_tab(j).ship_head_attribute14,
9799 v_trans_tab(j).ship_head_attribute15,
9800 v_trans_tab(j).ship_line_attribute_category,
9801 v_trans_tab(j).ship_line_attribute1,
9802 v_trans_tab(j).ship_line_attribute2,
9803 v_trans_tab(j).ship_line_attribute3,
9804 v_trans_tab(j).ship_line_attribute4,
9805 v_trans_tab(j).ship_line_attribute5,
9806 v_trans_tab(j).ship_line_attribute6,
9807 v_trans_tab(j).ship_line_attribute7,
9808 v_trans_tab(j).ship_line_attribute8,
9809 v_trans_tab(j).ship_line_attribute9,
9810 v_trans_tab(j).ship_line_attribute10,
9811 v_trans_tab(j).ship_line_attribute11,
9812 v_trans_tab(j).ship_line_attribute12,
9813 v_trans_tab(j).ship_line_attribute13,
9814 v_trans_tab(j).ship_line_attribute14,
9815 v_trans_tab(j).ship_line_attribute15,
9816 v_trans_tab(j).ussgl_transaction_code,
9817 v_trans_tab(j).government_context,
9818 v_trans_tab(j).reason_id,
9819 v_trans_tab(j).destination_context,
9820 v_trans_tab(j).source_doc_quantity,
9821 v_trans_tab(j).source_doc_unit_of_measure,
9822 v_trans_tab(j).movement_id,
9823 v_trans_tab(j).header_interface_id,
9824 v_trans_tab(j).vendor_cum_shipped_qty,
9825 v_trans_tab(j).item_num,
9826 v_trans_tab(j).document_num,
9827 v_trans_tab(j).document_line_num,
9828 v_trans_tab(j).truck_num,
9829 v_trans_tab(j).ship_to_location_code,
9830 v_trans_tab(j).container_num,
9831 v_trans_tab(j).substitute_item_num,
9832 v_trans_tab(j).notice_unit_price,
9833 v_trans_tab(j).item_category,
9834 v_trans_tab(j).location_code,
9835 v_trans_tab(j).vendor_name,
9836 v_trans_tab(j).vendor_num,
9837 v_trans_tab(j).vendor_site_code,
9838 v_trans_tab(j).from_organization_code,
9839 v_trans_tab(j).to_organization_code,
9840 v_trans_tab(j).intransit_owning_org_code,
9841 v_trans_tab(j).routing_code,
9842 v_trans_tab(j).routing_step,
9843 v_trans_tab(j).release_num,
9844 v_trans_tab(j).document_shipment_line_num,
9845 v_trans_tab(j).document_distribution_num,
9846 v_trans_tab(j).deliver_to_person_name,
9847 v_trans_tab(j).deliver_to_location_code,
9848 v_trans_tab(j).use_mtl_lot,
9849 v_trans_tab(j).use_mtl_serial,
9850 v_trans_tab(j).LOCATOR,
9851 v_trans_tab(j).reason_name,
9852 v_trans_tab(j).validation_flag,
9853 v_trans_tab(j).substitute_item_id,
9854 v_trans_tab(j).quantity_shipped,
9855 v_trans_tab(j).quantity_invoiced,
9856 v_trans_tab(j).tax_name,
9857 v_trans_tab(j).tax_amount,
9858 v_trans_tab(j).req_num,
9859 v_trans_tab(j).req_line_num,
9860 v_trans_tab(j).req_distribution_num,
9861 v_trans_tab(j).wip_entity_name,
9862 v_trans_tab(j).wip_line_code,
9863 v_trans_tab(j).resource_code,
9864 v_trans_tab(j).shipment_line_status_code,
9865 v_trans_tab(j).barcode_label,
9866 v_trans_tab(j).country_of_origin_code,
9867 v_trans_tab(j).from_locator_id, --WMS Change
9868 v_trans_tab(j).qa_collection_id,
9869 v_trans_tab(j).oe_order_header_id,
9870 v_trans_tab(j).oe_order_line_id,
9871 v_trans_tab(j).customer_id,
9872 v_trans_tab(j).customer_site_id,
9873 v_trans_tab(j).customer_item_num,
9874 v_trans_tab(j).create_debit_memo_flag,
9875 v_trans_tab(j).put_away_rule_id,
9876 v_trans_tab(j).put_away_strategy_id,
9877 v_trans_tab(j).lpn_id,
9878 v_trans_tab(j).transfer_lpn_id,
9879 v_trans_tab(j).cost_group_id,
9880 v_trans_tab(j).mobile_txn,
9881 v_trans_tab(j).mmtt_temp_id,
9882 v_trans_tab(j).transfer_cost_group_id,
9883 v_trans_tab(j).secondary_quantity,
9884 v_trans_tab(j).secondary_unit_of_measure,
9885 v_trans_tab(j).secondary_uom_code,
9886 v_trans_tab(j).qc_grade,
9887 v_trans_tab(j).oe_order_num,
9888 v_trans_tab(j).oe_order_line_num,
9889 v_trans_tab(j).customer_account_number,
9890 v_trans_tab(j).customer_party_name,
9891 v_trans_tab(j).source_transaction_num,
9892 v_trans_tab(j).parent_source_transaction_num,
9893 v_trans_tab(j).parent_interface_txn_id,
9894 v_trans_tab(j).customer_item_id,
9895 v_trans_tab(j).interface_available_qty,
9896 v_trans_tab(j).interface_transaction_qty,
9897 v_trans_tab(j).from_locator,
9898 v_trans_tab(j).lpn_group_id,
9899 v_trans_tab(j).order_transaction_id,
9900 v_trans_tab(j).license_plate_number,
9901 v_trans_tab(j).transfer_license_plate_number,
9902 v_trans_tab(j).amount,
9903 v_trans_tab(j).job_id,
9904 v_trans_tab(j).project_id,
9905 v_trans_tab(j).task_id,
9906 v_trans_tab(j).asn_attach_id,
9907 v_trans_tab(j).timecard_id,
9908 v_trans_tab(j).timecard_ovn,
9909 v_trans_tab(j).interface_available_amt,
9910 v_trans_tab(j).interface_transaction_amt,
9911 v_trans_tab(j).org_id, --<R12 MOAC>
9912 v_trans_tab(j).matching_basis,
9913 v_trans_tab(j).amount_shipped,
9914 v_trans_tab(j).requested_amount,
9915 v_trans_tab(j).material_stored_amount,
9916 v_trans_tab(j).replenish_order_line_id,
9917 v_trans_tab(j).express_transaction -- Bug 14067935
9918 );
9919 asn_debug.put_line('RowId ' || v_trans_tab(j).row_id);
9920 asn_debug.put_line('Interface Id ' || TO_CHAR(v_trans_tab(j).interface_transaction_id));
9921 asn_debug.put_line('matching_basis=' || v_trans_tab(j).matching_basis);
9922
9923 IF v_trans_tab(j).matching_basis <> 'AMOUNT' THEN
9924 l_ls_table(l_ls_table_idx).orig_interface_trx_id := l_orig_trx_id;
9925 l_ls_table(l_ls_table_idx).new_interface_trx_id := v_trans_tab(j).interface_transaction_id;
9926 l_ls_table(l_ls_table_idx).quantity := v_trans_tab(j).quantity;
9927 END IF;
9928
9929 v_trans_tab.DELETE(j);
9930 END IF;
9931
9932 /* Checking if WMS is intalled before calling WMS_ASN_INTERFACE_PROCESS
9933 for Bug 2110031 */
9934 IF (wms_install.check_install(l_wms_return_status,
9935 l_wms_msg_count,
9936 l_wms_msg_data,
9937 lorgid
9938 )) THEN
9939 BEGIN
9940 wms_asn_interface.process(l_wms_return_status,
9941 l_wms_msg_count,
9942 l_wms_msg_data,
9943 v_current_interface_id
9944 );
9945 EXCEPTION
9946 WHEN OTHERS THEN
9947 NULL;
9948 END;
9949 END IF;
9950 END LOOP;
9951
9952 /* FPJ WMS Change. Call WMS api to split lot and serial rows in
9953 * mtl_transaction_lots_interface and mtl_serial_numbers_interface
9954 * tables. This needs to be called for each split rti row with both
9955 * the original rti row interface_id since the interface rows are
9956 * still linked to rti with the interface_transaction_id. This api
9957 * will split the mtli and msni rows similar to rti rows and will
9958 * link with the correct ids.
9959 */
9960 IF (g_asn_debug = 'Y') THEN
9961 asn_debug.put_line('l_ls_table.COUNT: ' || l_ls_table.COUNT);
9962 END IF;
9963
9964 IF l_ls_table.COUNT > 0 THEN --{
9965 IF (g_asn_debug = 'Y') THEN
9966 asn_debug.put_line('Calling split_lot_serial');
9967 END IF;
9968
9969 l_return := inv_rcv_integration_apis.split_lot_serial(p_api_version => l_api_version,
9970 p_init_msg_lst => fnd_api.g_false,
9971 x_return_status => l_return_status,
9972 x_msg_count => l_msg_count,
9973 x_msg_data => l_msg_data,
9974 p_new_rti_info => l_ls_table
9975 );
9976
9977 IF (g_asn_debug = 'Y') THEN
9978 asn_debug.put_line('After split_lot_serial Api');
9979 END IF;
9980
9981 -- if lot serial validation failed, then fail all these split rows
9982 IF ( (NOT l_return)
9983 OR (l_return_status <> fnd_api.g_ret_sts_success)) THEN --{
9984 IF (g_asn_debug = 'Y') THEN
9985 asn_debug.put_line('split_lot_serial Api has errors');
9986
9987 IF l_return THEN
9988 asn_debug.put_line('return value: true');
9989 ELSE
9990 asn_debug.put_line('return value: false');
9991 END IF;
9992
9993 asn_debug.put_line('x_return_status: ' || l_return_status);
9994 asn_debug.put_line('x_msg_count: ' || l_msg_count);
9995 asn_debug.put_line('x_msg_data: ' || l_msg_data);
9996 END IF;
9997
9998 l_message := fnd_msg_pub.get(p_msg_index => fnd_msg_pub.g_last, p_encoded => fnd_api.g_false);
9999
10000 FOR k IN l_ls_table.FIRST .. e_o_t LOOP
10001 /* We error out the rti row here.
10002 * Erroring out the other lpm_group rows
10003 * or ASN rows are taken care in RCVPREPB.pls.
10004 */
10005 UPDATE rcv_transactions_interface
10006 SET processing_status_code = 'ERROR'
10007 WHERE interface_transaction_id = l_ls_table(k).new_interface_trx_id;
10008
10009 SELECT GROUP_ID,
10010 header_interface_id,
10011 interface_transaction_id,
10012 transaction_type,
10013 source_document_code,
10014 shipment_header_id
10015 INTO l_group_id,
10016 l_header_interface_id,
10017 l_interface_transaction_id,
10018 l_trx_type,
10019 l_src_doc_code,
10020 l_ship_head_id
10021 FROM rcv_transactions_interface
10022 WHERE interface_transaction_id = l_ls_table(k).new_interface_trx_id;
10023
10024 fnd_profile.get('RCV_FAIL_IF_LINE_FAILS', x_fail_all_lines);
10025 IF ( x_fail_all_lines='Y') THEN
10026 rcv_roi_preprocessor.update_rti_error
10027 (null,
10028 null,
10029 l_header_interface_id,
10030 null);
10031 END IF;
10032
10033 IF (l_message IS NOT NULL) THEN
10034 rcv_error_pkg.log_interface_error_message(l_message);
10035 ELSE
10036 rcv_error_pkg.set_error_message('RCV_SPLIT_LOT_SERIAL_ERROR');
10037 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
10038 END IF;
10039 END LOOP;
10040 /*Bug 10351737 Deleteing the orphan rsh records*/
10041
10042 IF l_header_interface_id IS NOT NULL THEN
10043 SELECT count(1)
10044 INTO l_count
10045 FROM rcv_transactions_interface
10046 WHERE header_interface_id=l_header_interface_id;
10047
10048 SELECT count(1)
10049 INTO l_cnt
10050 FROM rcv_transactions_interface
10051 WHERE header_interface_id=l_header_interface_id
10052 AND processing_status_code='ERROR';
10053
10054 IF (l_count=l_cnt AND l_trx_type in ('SHIP','RECEIVE') AND l_src_doc_code='PO') THEN
10055 UPDATE rcv_headers_interface rhi
10056 SET processing_status_code='ERROR'
10057 WHERE header_interface_id=l_header_interface_id;
10058
10059 asn_debug.put_line('Deleting the rsh record with shipment_header_id = '||l_ship_head_id);
10060 DELETE FROM rcv_shipment_headers rsh
10061 WHERE shipment_header_id=l_ship_head_id
10062 AND NOT EXISTS (SELECT 1 from rcv_shipment_lines
10063 WHERE shipment_header_id=rsh.shipment_header_id)
10064 AND NOT EXISTS (SELECT 1 from rcv_transactions rt
10065 WHERE rt.shipment_header_id = rsh.shipment_header_id);
10066 END IF;
10067 END IF;
10068
10069 /* update rcv_headers_interface rhi
10070 set processing_status_code='ERROR'
10071 where header_interface_id=l_header_interface_id
10072 and not exists(select 1 from rcv_transactions_interface
10073 where header_interface_id=l_header_interface_id
10074 and processing_status_code='RUNNING');
10075
10076 delete from rcv_shipment_headers rsh
10077 where
10078 and not exists(select 1 from rcv_transactions_interface
10079 where shipment_header_id=rsh.shipment_header_id
10080 and processing_status_code='RUNNING');*/
10081
10082 END IF; --} if split_lot_serial failed
10083 END IF; --} if l_ls_table.count > 0
10084 END IF; --} if v_trans_tab.count > 0
10085
10086 IF (g_asn_debug = 'Y') THEN
10087 asn_debug.put_line('Exit handle_rcv_asn_transactions');
10088 END IF;
10089 END handle_rcv_asn_transactions;
10090
10091 PROCEDURE derive_vendor_trans_del(
10092 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
10093 n IN OUT NOCOPY BINARY_INTEGER,
10094 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
10095 x_header_record IN rcv_roi_preprocessor.header_rec_type
10096 ) IS
10097 test NUMBER;
10098 BEGIN
10099 IF (g_asn_debug = 'Y') THEN
10100 asn_debug.put_line('enter derive_vendor_trans_del ');
10101 END IF;
10102
10103
10104 /* Derive the to_org_id */
10105 derive_ship_to_org_info(x_cascaded_table,
10106 n,
10107 x_header_record
10108 );
10109
10110 IF (x_cascaded_table(n).unit_of_measure IS NOT NULL) THEN
10111 IF (g_asn_debug = 'Y') THEN
10112 asn_debug.put_line('X_progress ' || x_progress);
10113 END IF;
10114
10115 SELECT muom.uom_code
10116 INTO x_cascaded_table(n).uom_code
10117 FROM mtl_units_of_measure muom
10118 WHERE muom.unit_of_measure = x_cascaded_table(n).unit_of_measure;
10119 ELSE
10120 IF (g_asn_debug = 'Y') THEN
10121 asn_debug.put_line('uom_code not derived as unit_of_measure is null');
10122 END IF;
10123 END IF;
10124
10125 x_progress := '026';
10126
10127 /* Locator info derivation is done for the Receiving locators FPJ
10128 * project. Need to verify this with karun to see whether this is
10129 * needed for Transfer also.
10130 */
10131 IF (x_cascaded_table(n).transaction_type = 'TRANSFER') THEN
10132 derive_location_info(x_cascaded_table, n);
10133 derive_from_locator_id(x_cascaded_table, n); -- WMS Change
10134 derive_to_locator_id(x_cascaded_table, n); -- WMS Change
10135 END IF;
10136
10137 x_progress := '091';
10138 derive_reason_info(x_cascaded_table, n);
10139 /* Auto_transact_code is null for all these transaction types */
10140 x_cascaded_table(n).auto_transact_code := NULL;
10141 derive_trans_del_line_quantity(x_cascaded_table,
10142 n,
10143 temp_cascaded_table
10144 );
10145 END derive_vendor_trans_del;
10146
10147 PROCEDURE derive_parent_id(
10148 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
10149 n IN OUT NOCOPY BINARY_INTEGER
10150 ) IS
10151 derive_values_from_plsql_table BOOLEAN := FALSE;
10152 cascaded_table_index NUMBER;
10153 derive_values_from_rti BOOLEAN := FALSE;
10154 l_processing_status_code rcv_transactions_interface.processing_status_code%TYPE;
10155 x_error_status VARCHAR2(1);
10156 e_unexpected_error EXCEPTION;
10157
10158 /* Bug# 9855182 */
10159 l_transaction_type rcv_transactions_interface.transaction_type%TYPE;
10160 l_auto_transact_code rcv_transactions_interface.auto_transact_code%TYPE;
10161 /* Bug# 9855182 End*/
10162 BEGIN
10163 x_error_status := rcv_error_pkg.g_ret_sts_error;
10164
10165 /* We need to derive parent_trx_id if we can. Else if it is
10166 * a child of a parent in this same run, we can get all the values
10167 * from rti since we would have already derived for that or
10168 * from the pl/sql table if we have not posted it back to rti.
10169 * Parent-Child relationship
10170 */
10171
10172
10173 /* This can be a third party which means we will have
10174 * parent_source_transaction_num populated or it is a child of
10175 * some other transaction.
10176 */
10177 IF (g_asn_debug = 'Y') THEN
10178 asn_debug.put_line('Enter Derive_parent_id');
10179 END IF;
10180
10181 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN --{
10182 /* Check whether it is still in cascaded table */
10183 FOR i IN 1 ..(n - 1) LOOP
10184 IF (x_cascaded_table(i).interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id) THEN
10185 derive_values_from_plsql_table := TRUE;
10186 cascaded_table_index := i;
10187
10188 IF (g_asn_debug = 'Y') THEN
10189 asn_debug.put_line('set derive_values_from_plsql_table true ' || cascaded_table_index);
10190 END IF;
10191
10192 x_cascaded_table(n).derive := 'Y';
10193 x_cascaded_table(n).derive_index := cascaded_table_index;
10194 EXIT;
10195 END IF;
10196 END LOOP;
10197
10198 /* Derive the values from RTI if already posted */
10199 IF (NOT derive_values_from_plsql_table) THEN --{
10200 derive_values_from_rti := TRUE;
10201 x_cascaded_table(n).derive := 'Y';
10202
10203 IF (g_asn_debug = 'Y') THEN
10204 asn_debug.put_line('set derive_values_from_rti true ' || x_cascaded_table(n).derive_index);
10205 END IF;
10206 END IF; /*if (not derived_values_from_table) then */ --}
10207 END IF; --}
10208
10209 -- Bug 7651646: Start
10210 IF ( (x_cascaded_table(n).parent_interface_txn_id IS NULL)
10211 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)
10212 AND (x_cascaded_table(n).parent_transaction_id IS NULL) ) THEN
10213 IF (g_asn_debug = 'Y') THEN
10214 asn_debug.put_line('Deriving parent_transaction_id from parent_source_transaction_num');
10215 END IF;
10216
10217 BEGIN
10218 SELECT transaction_id
10219 INTO x_cascaded_table(n).parent_transaction_id
10220 FROM rcv_transactions
10221 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
10222 EXCEPTION
10223 WHEN NO_DATA_FOUND THEN
10224 rcv_error_pkg.set_error_message('RCV_NO_PARENT_SRC_TRANSACTION');
10225 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
10226 RAISE e_validation_error;
10227 WHEN TOO_MANY_ROWS THEN
10228 rcv_error_pkg.set_error_message('RCV_DUP_SRC_TRANSACTION');
10229 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
10230 RAISE e_validation_error;
10231 END;
10232
10233 END IF;
10234 -- Bug 7651646: End
10235
10236 IF ( x_cascaded_table(n).parent_interface_txn_id IS NULL
10237 AND x_cascaded_table(n).parent_transaction_id IS NULL) THEN --{
10238 /* This is an error. It will come here when the user has
10239 * provided parent_source_transaction_num but that did not match with
10240 * with any parent in rcv_transactions or with any
10241 * row in rti or the pl/sql table. Hence need to insert
10242 * into po_interface_errors saying that this is a child
10243 * without any parent in rti or rt.
10244 */
10245 IF (g_asn_debug = 'Y') THEN
10246 asn_debug.put_line('NO PARENT');
10247 END IF;
10248
10249 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION');
10250 RAISE e_validation_error;
10251 ELSIF(x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN --}{
10252 IF (NOT derive_values_from_plsql_table) THEN --{
10253 BEGIN
10254 SELECT processing_status_code,
10255 /* Bug# 9855182 */
10256 transaction_type,
10257 auto_transact_code
10258 /* Bug# 9855182 End*/
10259 INTO l_processing_status_code,
10260 /* Bug# 9855182 */
10261 l_transaction_type,
10262 l_auto_transact_code
10263 /* Bug# 9855182 End*/
10264 FROM rcv_transactions_interface
10265 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
10266 EXCEPTION
10267 WHEN OTHERS THEN
10268 IF (g_asn_debug = 'Y') THEN
10269 asn_debug.put_line('Exception in rti with parent_interface_txn_id ');
10270 END IF;
10271
10272 RAISE e_unexpected_error;
10273 END;
10274
10275 IF (g_asn_debug = 'Y') THEN
10276 asn_debug.put_line('l_processing_status_code from rti ' || l_processing_status_code);
10277 END IF;
10278
10279 IF (l_processing_status_code = 'ERROR') THEN
10280 rcv_error_pkg.set_error_message('RCV_PARENT_RECORD_ERRORED');
10281 RAISE e_validation_error;
10282 END IF;
10283
10284 /* Bug# 9855182 */
10285 IF ((x_cascaded_table(n).transaction_type = 'RETURN TO VENDOR') OR
10286 (x_cascaded_table(n).transaction_type = 'CORRECT' AND
10287 sign(x_cascaded_table(n).quantity) = -1)) THEN
10288
10289 IF l_transaction_type = 'RECEIVE' AND
10290 l_auto_transact_code = 'DELIVER' THEN
10291 rcv_error_pkg.set_error_message('RCV_INVALID_PARENT_TRX_TYPE');
10292 RAISE e_validation_error;
10293 END IF;
10294 END IF;
10295 /* Bug# 9855182 End*/
10296
10297
10298 ELSE --}{
10299 IF (x_cascaded_table(cascaded_table_index).processing_status_code = 'ERROR') THEN
10300 rcv_error_pkg.set_error_message('RCV_PARENT_RECORD_ERRORED');
10301 RAISE e_validation_error;
10302 END IF;
10303
10304 /* Bug# 9855182 */
10305 IF ((x_cascaded_table(n).transaction_type = 'RETURN TO VENDOR') OR
10306 (x_cascaded_table(n).transaction_type = 'CORRECT' AND
10307 sign(x_cascaded_table(n).quantity) = -1)) THEN
10308
10309 IF x_cascaded_table(cascaded_table_index).transaction_type = 'RECEIVE' AND
10310 x_cascaded_table(cascaded_table_index).auto_transact_code = 'DELIVER' THEN
10311 rcv_error_pkg.set_error_message('RCV_INVALID_PARENT_TRX_TYPE');
10312 RAISE e_validation_error;
10313 END IF;
10314 END IF;
10315 /* Bug# 9855182 End*/
10316
10317 END IF; --}
10318 END IF; /* Insert error if parent_interface_txn_id is null*/ --}
10319 EXCEPTION
10320 WHEN e_validation_error THEN
10321 x_cascaded_table(n).error_status := x_error_status;
10322 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
10323
10324 -- This case statement assigns the appropriate tokens
10325 -- all error messages must be found in the case statement
10326 -- if the error message has no token then use a null statement
10327 IF x_cascaded_table(n).error_message = 'RCV_NO_PARENT_TRANSACTION' THEN
10328 NULL;
10329 ELSIF x_cascaded_table(n).error_message = 'RCV_PARENT_RECORD_ERRORED' THEN
10330 NULL;
10331 END IF;
10332
10333 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
10334 WHEN e_unexpected_error THEN
10335 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
10336 rcv_error_pkg.set_sql_error_message('derive_parent_id', '000');
10337 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
10338 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
10339 END derive_parent_id;
10340
10341 PROCEDURE derive_trans_del_line_quantity(
10342 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
10343 n IN OUT NOCOPY BINARY_INTEGER,
10344 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type
10345 ) IS
10346 x_include_closed_po VARCHAR2(1); -- Bug 1887728
10347 /*
10348 ** Might be a compatibility issue between the two record definitions
10349 */
10350 x_record_count NUMBER;
10351 x_remaining_quantity NUMBER := 0;
10352 x_remaining_qty_po_uom NUMBER := 0;
10353 x_bkp_qty NUMBER := 0;
10354 x_progress VARCHAR2(3);
10355 x_to_organization_code VARCHAR2(5);
10356 x_converted_trx_qty NUMBER := 0;
10357 transaction_ok BOOLEAN := FALSE;
10358 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
10359 high_range_date DATE;
10360 low_range_date DATE;
10361 rows_fetched NUMBER := 0;
10362 x_tolerable_qty NUMBER := 0;
10363 x_first_trans BOOLEAN := TRUE;
10364 x_sysdate DATE := SYSDATE;
10365 current_n BINARY_INTEGER := 0;
10366 insert_into_table BOOLEAN := FALSE;
10367 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
10368 tax_amount_factor NUMBER;
10369 lastrecord BOOLEAN := FALSE;
10370 po_asn_uom_qty NUMBER;
10371 po_primary_uom_qty NUMBER;
10372 already_allocated_qty NUMBER := 0;
10373 x_item_id NUMBER;
10374 x_approved_flag VARCHAR(1);
10375 x_cancel_flag VARCHAR(1);
10376 x_closed_code VARCHAR(25);
10377 x_shipment_type VARCHAR(25);
10378 x_ship_to_organization_id NUMBER;
10379 x_ship_to_location_id NUMBER;
10380 /* temp_ship_to_location_id number;
10381 temp_mirror_ship_to_loc_id number ;
10382 temp_enf_ship_to_loc_code varchar(25) ; */
10383 /* The above 3 variables added for bug 1898283 */
10384 x_vendor_product_num VARCHAR(25);
10385 x_temp_count NUMBER;
10386 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
10387 /* 1887728 -Added the following variables */
10388 profile_user_id NUMBER := -1;
10389 profile_appl_id NUMBER := -1;
10390 profile_resp_id NUMBER := -1;
10391 defined BOOLEAN;
10392 /* 1845702 */
10393 x_sob_id NUMBER := NULL;
10394 x_rate NUMBER;
10395 x_allow_rate_override VARCHAR2(1);
10396 /* Bug# 1548597 */
10397 x_secondary_available_qty NUMBER := 0;
10398 firstrecord BOOLEAN := TRUE;
10399
10400 /********************************************************************/
10401 /* Bug 3356796. Changed destination_subinventory from 0 to '' as
10402 * it is a varchar column.
10403 */
10404 CURSOR po_transfer(
10405 v_parent_trx_id NUMBER,
10406 v_to_organization_id NUMBER
10407 ) IS
10408 SELECT rsup.po_line_location_id,
10409 rsup.po_header_id po_head_id,
10410 rsup.po_line_id line_id,
10411 rsup.rcv_transaction_id rcv_transaction_id,
10412 poh.segment1 document_num,
10413 pol.line_num line_number,
10414 rt.transaction_date transaction_date,
10415 rt.transaction_type,
10416 rt.unit_of_measure unit_of_meas,
10417 rt.primary_unit_of_measure,
10418 rt.primary_quantity,
10419 rsup.to_organization_id,
10420 rt.po_unit_price unit_price,
10421 rsl.category_id,
10422 rsl.item_description,
10423 rsup.po_line_id,
10424 rt.location_id,
10425 rsup.item_id,
10426 0 deliver_to_person_id,
10427 0 deliver_to_location_id,
10428 '' destination_subinventory,
10429 0 po_distribution_id,
10430 rsup.destination_type_code,
10431 0 code_combination_id,
10432 0 req_distribution_id,
10433 0 destination_organization_id,
10434 0 wip_entity_id,
10435 0 wip_operation_seq_num,
10436 0 wip_resource_seq_num,
10437 0 wip_repetitive_schedule_id,
10438 0 wip_line_id,
10439 0 bom_resource_id,
10440 0 ussgl_transaction_code,
10441 rt.quantity qty,
10442 0 interface_available_qty
10443 FROM rcv_supply rsup,
10444 rcv_transactions rt,
10445 rcv_shipment_lines rsl,
10446 po_headers poh,
10447 po_lines pol
10448 WHERE rt.transaction_id = v_parent_trx_id
10449 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
10450 AND rsup.supply_type_code = 'RECEIVING'
10451 AND poh.po_header_id = rsup.po_header_id
10452 AND pol.po_line_id = rsup.po_line_id
10453 AND pol.po_header_id = poh.po_header_id
10454 AND rsl.shipment_line_id = rsup.shipment_line_id
10455 AND rt.transaction_id = rsup.rcv_transaction_id
10456 AND rt.transaction_type <> 'UNORDERED'
10457 ORDER BY transaction_date DESC,
10458 document_num,
10459 line_number;
10460
10461 CURSOR po_transfer_rti(
10462 v_parent_inter_trx_id NUMBER
10463 ) IS
10464 SELECT rti.po_line_location_id,
10465 rti.po_header_id po_head_id,
10466 rti.po_line_id line_id,
10467 rti.interface_transaction_id rcv_transaction_id,
10468 rti.document_num,
10469 rti.document_line_num line_number,
10470 rti.transaction_date transaction_date,
10471 rti.transaction_type,
10472 rti.unit_of_measure unit_of_meas,
10473 rti.primary_unit_of_measure,
10474 rti.primary_quantity,
10475 rti.to_organization_id,
10476 rti.po_unit_price unit_price,
10477 rti.category_id,
10478 rti.item_description,
10479 rti.po_line_id,
10480 rti.location_id,
10481 rti.item_id,
10482 0 deliver_to_person_id,
10483 0 deliver_to_location_id,
10484 '' destination_subinventory,
10485 0 po_distribution_id,
10486 rti.destination_type_code,
10487 0 code_combination_id,
10488 0 req_distribution_id,
10489 0 destination_organization_id,
10490 0 wip_entity_id,
10491 0 wip_operation_seq_num,
10492 0 wip_resource_seq_num,
10493 0 wip_repetitive_schedule_id,
10494 0 wip_line_id,
10495 0 bom_resource_id,
10496 0 ussgl_transaction_code,
10497 rti.quantity qty,
10498 rti.interface_available_qty
10499 FROM rcv_transactions_interface rti
10500 WHERE interface_transaction_id = v_parent_inter_trx_id;
10501
10502 /* Bug 3292329.
10503 We used to use the same cursor for single deliver and
10504 Transfers, inspections etc. Because of this we had the
10505 the join to po_distributions table. For transfers of
10506 a received shipment line against a PO shipment with multiple
10507 distribution, this results in multiple rows which is incorrect.
10508 So declared a new cursor for single deliver which is the same
10509 as that of tranfer cursor but with distribution info.
10510 */
10511 CURSOR po_single_deliver(
10512 v_parent_trx_id NUMBER,
10513 v_to_organization_id NUMBER
10514 ) IS
10515 SELECT rsup.po_line_location_id,
10516 rsup.po_header_id po_head_id,
10517 rsup.po_line_id line_id,
10518 rsup.rcv_transaction_id rcv_transaction_id,
10519 poh.segment1 document_num,
10520 pol.line_num line_number,
10521 rt.transaction_date transaction_date,
10522 rt.transaction_type,
10523 rt.unit_of_measure unit_of_meas,
10524 rt.primary_unit_of_measure,
10525 rt.primary_quantity,
10526 rsup.to_organization_id,
10527 rt.po_unit_price unit_price,
10528 rsl.category_id,
10529 rsl.item_description,
10530 rsup.po_line_id,
10531 rt.location_id,
10532 rsup.item_id,
10533 pod.deliver_to_person_id,
10534 pod.deliver_to_location_id,
10535 pod.destination_subinventory,
10536 pod.po_distribution_id,
10537 pod.destination_type_code,
10538 pod.code_combination_id,
10539 pod.req_distribution_id,
10540 pod.destination_organization_id,
10541 pod.wip_entity_id,
10542 pod.wip_operation_seq_num,
10543 pod.wip_resource_seq_num,
10544 pod.wip_repetitive_schedule_id,
10545 pod.wip_line_id,
10546 pod.bom_resource_id,
10547 pod.ussgl_transaction_code,
10548 rt.quantity qty,
10549 0 interface_available_qty
10550 FROM rcv_supply rsup,
10551 rcv_transactions rt,
10552 rcv_shipment_lines rsl,
10553 po_headers poh,
10554 po_lines pol,
10555 po_distributions pod
10556 WHERE rt.transaction_id = v_parent_trx_id
10557 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
10558 AND rsup.supply_type_code = 'RECEIVING'
10559 AND poh.po_header_id = rsup.po_header_id
10560 AND pol.po_line_id = rsup.po_line_id
10561 AND pol.po_header_id = poh.po_header_id
10562 AND rsl.shipment_line_id = rsup.shipment_line_id
10563 AND rt.transaction_id = rsup.rcv_transaction_id
10564 AND rt.transaction_type <> 'UNORDERED'
10565 AND rt.po_header_id = pod.po_header_id
10566 AND pod.po_line_id = pol.po_line_id
10567 AND rt.po_line_location_id = pod.line_location_id
10568 AND ( pod.po_line_id IS NOT NULL
10569 AND pod.line_location_id IS NOT NULL)
10570 ORDER BY transaction_date DESC,
10571 document_num,
10572 line_number;
10573
10574 /* Bug 5354379:
10575 Added the condition pod.line_location_id = rti.po_line_location_id to
10576 get the correct pod.po_distribution_id for the po_line_location_id
10577 populated in the RTI. */
10578
10579 CURSOR po_single_deliver_rti(
10580 v_parent_inter_trx_id NUMBER
10581 ) IS
10582 SELECT rti.po_line_location_id,
10583 rti.po_header_id po_head_id,
10584 rti.po_line_id line_id,
10585 rti.interface_transaction_id rcv_transaction_id,
10586 rti.document_num,
10587 rti.document_line_num line_number,
10588 rti.transaction_date transaction_date,
10589 rti.transaction_type,
10590 rti.unit_of_measure unit_of_meas,
10591 rti.primary_unit_of_measure,
10592 rti.primary_quantity,
10593 rti.to_organization_id,
10594 rti.po_unit_price unit_price,
10595 rti.category_id,
10596 rti.item_description,
10597 rti.po_line_id,
10598 rti.location_id,
10599 rti.item_id,
10600 pod.deliver_to_person_id,
10601 pod.deliver_to_location_id,
10602 pod.destination_subinventory,
10603 pod.po_distribution_id,
10604 pod.destination_type_code,
10605 pod.code_combination_id,
10606 pod.req_distribution_id,
10607 pod.destination_organization_id,
10608 pod.wip_entity_id,
10609 pod.wip_operation_seq_num,
10610 pod.wip_resource_seq_num,
10611 pod.wip_repetitive_schedule_id,
10612 pod.wip_line_id,
10613 pod.bom_resource_id,
10614 pod.ussgl_transaction_code,
10615 rti.quantity qty,
10616 rti.interface_available_qty
10617 FROM rcv_transactions_interface rti,
10618 po_distributions pod
10619 WHERE interface_transaction_id = v_parent_inter_trx_id
10620 AND pod.line_location_id = rti.po_line_location_id --Bug:5354379
10621 AND pod.po_header_id = rti.po_header_id
10622 AND ( pod.po_line_id IS NOT NULL
10623 AND pod.line_location_id IS NOT NULL);
10624
10625 CURSOR po_deliver(
10626 v_parent_trx_id NUMBER,
10627 v_to_organization_id NUMBER,
10628 x_dist_num NUMBER
10629 ) IS
10630 SELECT rsup.po_line_location_id,
10631 rsup.po_header_id po_head_id,
10632 rsup.po_line_id line_id,
10633 rsup.rcv_transaction_id rcv_transaction_id,
10634 poh.segment1 document_num,
10635 pol.line_num line_number,
10636 rt.transaction_date transaction_date,
10637 rt.transaction_type,
10638 rt.unit_of_measure unit_of_meas,
10639 rt.primary_unit_of_measure,
10640 rt.primary_quantity,
10641 rsup.to_organization_id,
10642 rt.po_unit_price unit_price,
10643 rsl.category_id,
10644 rsl.item_description,
10645 rsup.po_line_id,
10646 rt.location_id,
10647 rsup.item_id,
10648 pod.deliver_to_person_id,
10649 pod.deliver_to_location_id,
10650 pod.destination_subinventory,
10651 pod.po_distribution_id,
10652 pod.destination_type_code,
10653 pod.code_combination_id,
10654 pod.req_distribution_id,
10655 pod.destination_organization_id,
10656 pod.wip_entity_id,
10657 pod.wip_operation_seq_num,
10658 pod.wip_resource_seq_num,
10659 pod.wip_repetitive_schedule_id,
10660 pod.wip_line_id,
10661 pod.bom_resource_id,
10662 pod.ussgl_transaction_code,
10663 rt.quantity qty,
10664 0 interface_available_qty
10665 FROM rcv_supply rsup,
10666 rcv_transactions rt,
10667 rcv_shipment_lines rsl,
10668 po_headers poh,
10669 po_lines pol,
10670 po_distributions pod
10671 WHERE rt.transaction_id = v_parent_trx_id
10672 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
10673 AND rsup.supply_type_code = 'RECEIVING'
10674 AND poh.po_header_id = rsup.po_header_id
10675 AND pol.po_line_id = rsup.po_line_id
10676 AND pol.po_header_id = poh.po_header_id
10677 AND rsl.shipment_line_id = rsup.shipment_line_id
10678 AND rt.transaction_id = rsup.rcv_transaction_id
10679 AND rt.transaction_type <> 'UNORDERED'
10680 AND rt.po_line_location_id = pod.line_location_id
10681 AND pod.distribution_num = x_dist_num
10682 AND ( pod.po_line_id IS NOT NULL
10683 AND pod.line_location_id IS NOT NULL)
10684 ORDER BY pod.po_distribution_id;
10685
10686 CURSOR po_deliver_rti(
10687 v_parent_inter_trx_id NUMBER,
10688 x_dist_num NUMBER
10689 ) IS
10690 SELECT rti.po_line_location_id,
10691 rti.po_header_id po_head_id,
10692 rti.po_line_id line_id,
10693 rti.interface_transaction_id rcv_transaction_id,
10694 rti.document_num,
10695 rti.document_line_num line_number,
10696 rti.transaction_date transaction_date,
10697 rti.transaction_type,
10698 rti.unit_of_measure unit_of_meas,
10699 rti.primary_unit_of_measure,
10700 rti.primary_quantity,
10701 rti.to_organization_id,
10702 rti.po_unit_price unit_price,
10703 rti.category_id,
10704 rti.item_description,
10705 rti.po_line_id,
10706 rti.location_id,
10707 rti.item_id,
10708 pod.deliver_to_person_id,
10709 pod.deliver_to_location_id,
10710 pod.destination_subinventory,
10711 pod.po_distribution_id,
10712 pod.destination_type_code,
10713 pod.code_combination_id,
10714 pod.req_distribution_id,
10715 pod.destination_organization_id,
10716 pod.wip_entity_id,
10717 pod.wip_operation_seq_num,
10718 pod.wip_resource_seq_num,
10719 pod.wip_repetitive_schedule_id,
10720 pod.wip_line_id,
10721 pod.bom_resource_id,
10722 pod.ussgl_transaction_code,
10723 rti.quantity qty,
10724 rti.interface_available_qty
10725 FROM rcv_transactions_interface rti,
10726 po_distributions pod
10727 WHERE interface_transaction_id = v_parent_inter_trx_id
10728 AND pod.distribution_num = x_dist_num
10729 AND pod.po_header_id = rti.po_header_id
10730 AND pod.line_location_id = rti.po_line_location_id --Bug:5354379
10731 AND ( pod.po_line_id IS NOT NULL
10732 AND pod.line_location_id IS NOT NULL);
10733
10734 CURSOR cust_transfer(
10735 v_parent_trx_id NUMBER,
10736 v_to_organization_id NUMBER
10737 ) IS
10738 SELECT rsup.po_line_location_id,
10739 rsup.po_header_id po_head_id,
10740 rsup.po_line_id line_id,
10741 rsup.rcv_transaction_id rcv_transaction_id,
10742 poh.segment1 document_num,
10743 pol.line_num line_number,
10744 rt.transaction_date transaction_date,
10745 rt.transaction_type,
10746 rt.unit_of_measure unit_of_meas,
10747 rt.primary_unit_of_measure,
10748 rt.primary_quantity,
10749 rsup.to_organization_id,
10750 rt.po_unit_price unit_price,
10751 rsl.category_id,
10752 rsl.item_description,
10753 rsup.po_line_id,
10754 rt.location_id,
10755 rsup.item_id,
10756 pod.deliver_to_person_id,
10757 pod.deliver_to_location_id,
10758 pod.destination_subinventory,
10759 pod.po_distribution_id,
10760 pod.destination_type_code,
10761 pod.code_combination_id,
10762 pod.req_distribution_id,
10763 pod.destination_organization_id,
10764 pod.wip_entity_id,
10765 pod.wip_operation_seq_num,
10766 pod.wip_resource_seq_num,
10767 pod.wip_repetitive_schedule_id,
10768 pod.wip_line_id,
10769 pod.bom_resource_id,
10770 pod.ussgl_transaction_code,
10771 rt.quantity qty,
10772 0 interface_available_qty
10773 FROM rcv_supply rsup,
10774 rcv_transactions rt,
10775 rcv_shipment_lines rsl,
10776 po_headers poh,
10777 po_lines pol,
10778 po_distributions pod
10779 WHERE rt.transaction_id = v_parent_trx_id
10780 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
10781 AND rsup.supply_type_code = 'RECEIVING'
10782 AND poh.po_header_id = rsup.po_header_id
10783 AND pol.po_line_id = rsup.po_line_id
10784 AND pol.po_header_id = poh.po_header_id
10785 AND rsl.shipment_line_id = rsup.shipment_line_id
10786 AND rt.transaction_id = rsup.rcv_transaction_id
10787 AND rt.transaction_type <> 'UNORDERED'
10788 AND rt.po_header_id = pod.po_header_id
10789 AND ( pod.po_line_id IS NOT NULL
10790 AND pod.line_location_id IS NOT NULL);
10791
10792 --Bug 9072630 Added the below cursor rti_processed to find the total quantities of processed rtis in
10793 --Supply uom which is needed to calculate the effective qty that can be processed.
10794 CURSOR rti_processed(
10795 v_group_id NUMBER,
10796 v_po_line_location_id NUMBER,
10797 v_rcv_transaction_id NUMBER,
10798 v_interface_transaction_id NUMBER
10799 ) IS
10800 SELECT nvl(quantity,0) quantity,unit_of_measure
10801 FROM rcv_transactions_interface
10802 WHERE (transaction_status_code = 'PENDING'
10803 AND processing_status_code <> 'ERROR')
10804 AND transaction_type = 'DELIVER'
10805 AND group_id = v_group_id
10806 AND po_line_location_id = v_po_line_location_id
10807 AND parent_transaction_id=v_rcv_transaction_id
10808 AND interface_transaction_id < v_interface_transaction_id
10809 ORDER BY interface_transaction_id;
10810
10811 /* Bug 3356796. Changed x_po_transferrec to po_deliver%ROWTYPE
10812 * from po_transfer%ROWTYPE since po_deliver has all the columns
10813 * that are required for deliver and using po_transfer gives
10814 * PL/SQL conversion error.
10815 */
10816 l_unit_of_measure po_line_locations.unit_meas_lookup_code%TYPE;
10817 x_po_transferrec po_deliver%ROWTYPE;
10818 x_temp_parent_trx_qty NUMBER := 0;
10819 x_converted_parent_trx_qty NUMBER := 0;
10820 x_temp_convert_parent_trx_qty NUMBER := 0;
10821 x_remaining_qty_parent_uom NUMBER := 0;
10822 l_to_organization_id NUMBER := 0;
10823 x_temp_already_allocated_qty NUMBER := 0;
10824 derive_values_from_table BOOLEAN := FALSE;
10825 derive_values_from_rti BOOLEAN := FALSE;
10826 already_derived BOOLEAN := FALSE;
10827 cascaded_table_index NUMBER;
10828 l_num_of_distributions NUMBER;
10829 temp_index NUMBER;
10830 l_supply_code rcv_supply.supply_type_code%TYPE;
10831 l_transaction_type rcv_transactions.transaction_type%TYPE;
10832 /* FPJ SERVICES */
10833 l_value_basis po_lines.order_type_lookup_code%TYPE;
10834 l_purchase_basis po_lines.purchase_basis%TYPE;
10835 l_matching_basis po_lines.matching_basis%TYPE;
10836 l_service_po_line_id po_lines.po_line_id%TYPE;
10837 l_total_rec_quantity NUMBER;
10838 l_converted_distribution_qty NUMBER;
10839 l_distribution_qty NUMBER;
10840 l_converted_transaction_qty NUMBER;
10841 l_ship_unit po_line_locations.unit_meas_lookup_code%TYPE;
10842 l_po_header_id po_headers_all.po_header_id%type;
10843 l_return_status VARCHAR2(1) :='S';
10844 l_complex_flag varchar2(1);
10845
10846 /* Bug 5354379 */
10847 l_po_deliver_rti_cursor_opened NUMBER := 0;
10848 l_fetch_mtl_supply VARCHAR2(2) := 'S'; --'S' fetched mtl_supply successfully or 'E' error
10849 l_interface_txn_id NUMBER := -1;
10850 l_transaction_id NUMBER := -1;
10851 l_loop_exit_status VARCHAR2(2) := 'S'; --'S' loop exited successfully by fetching RECEIVE txnid from RT or 'E' error
10852 l_exit VARCHAR2(2) := 'N';-- 'Y' exit loop, 'N' dont exit the loop
10853 l_parent_interface_txn_id NUMBER := -1;
10854 l_parent_transaction_id NUMBER := -1;
10855 l_parent_receive_txn_in_rt VARCHAR2(2) := 'Y';-- 'Y'->Receive txn is in RT, so mtl_supply exists or 'N' RECEIVE txn still in RTI
10856 l_total_receiving_quantity NUMBER := 0; --Sum of received qty of preprocessed RECEIVE txn in RTI with same group_id
10857 l_total_deliver_quantity NUMBER := 0;--Sum of delivered qty of preprocessed DELIVER txn(excluding current DELIVER txn) in RTI with same group_id
10858 l_deliver_quantity NUMBER := 0; --Deliver qty for the current deliver txn
10859 l_receive_quantity NUMBER := 0;
10860 /* Bug 5354379 */
10861
10862 /* Bug 5354379 */
10863 /** Bug:6030094
10864 * PO number can be alpha numeric. So changing the
10865 * l_po_num definition from NUMBER to po_headers_all.segment1%type
10866 */
10867 l_po_num po_headers_all.segment1%type := null;
10868 l_po_line_num NUMBER := 0;
10869 l_po_line_loc_num NUMBER := 0;
10870 l_po_dist_num NUMBER := 0;
10871 /* Bug 5354379 */
10872 l_po_rel_num NUMBER := -1; --5439085
10873 --Bug 8631613
10874 l_temp_qty NUMBER;
10875 l_pri_temp_qty NUMBER;
10876 --Bug 8631613
10877
10878 -- <Bug 9342280 : Added for CLM project>
10879 l_is_clm_po VARCHAR2(5) := 'N';
10880 l_partial_funded_flag VARCHAR2(5) := 'N';
10881 -- <CLM END>
10882 BEGIN
10883 IF (g_asn_debug = 'Y') THEN
10884 asn_debug.put_line('enter derive_quantity ' || x_cascaded_table(n).parent_transaction_id);
10885 END IF;
10886
10887 --Bug 7651646
10888 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
10889 already_derived := TRUE;
10890 END IF;
10891
10892 IF ( NOT already_derived
10893 AND (x_cascaded_table(n).parent_interface_txn_id IS NULL)
10894 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN
10895 BEGIN
10896 SELECT transaction_id
10897 INTO x_cascaded_table(n).parent_transaction_id
10898 FROM rcv_transactions
10899 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
10900
10901 already_derived := TRUE;
10902 EXCEPTION
10903 WHEN NO_DATA_FOUND THEN
10904 rcv_error_pkg.set_error_message('RCV_NO_PARENT_SRC_TRANSACTION');
10905 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
10906 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
10907 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
10908 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
10909
10910 WHEN TOO_MANY_ROWS THEN
10911 rcv_error_pkg.set_error_message('RCV_DUP_SRC_TRANSACTION');
10912 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
10913 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
10914 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
10915 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
10916 END;
10917 END IF;
10918
10919 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
10920 SELECT po_header_id
10921 INTO x_cascaded_table(n).po_header_id
10922 FROM rcv_transactions
10923 WHERE transaction_id = x_cascaded_table(n).parent_transaction_id;
10924
10925 SELECT COUNT(*)
10926 INTO l_num_of_distributions
10927 FROM po_distributions pod,
10928 rcv_supply rs
10929 WHERE pod.line_location_id = rs.po_line_location_id
10930 AND rs.rcv_transaction_id = x_cascaded_table(n).parent_transaction_id;
10931
10932 IF (l_num_of_distributions = 0) then
10933 /* FP for Bug 4654553.(fixed as a part of bug 5354379)Most probably this is due to non availability
10934 of receiving supply in rcv_supply.Either the items are fully
10935 delivered to inventory or returned back to supplier.
10936 In such a case raise an error and fail the transaction.
10937 */
10938
10939 IF (g_asn_debug = 'Y') THEN
10940 asn_debug.put_line('l_num_of_distributions is 0');
10941 END IF;
10942
10943 x_cascaded_table(n).error_status := 'F';
10944 rcv_error_pkg.set_error_message('RCV_NO_RECEIVE_SUPPLY', x_cascaded_table(n).error_message);
10945 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
10946 return;
10947
10948 END IF; /* End of FP for bug 4654553 */
10949 IF ( (x_cascaded_table(n).transaction_type = 'DELIVER')
10950 AND (l_num_of_distributions > 1)) THEN --{
10951 IF (g_asn_debug = 'Y') THEN
10952 asn_debug.put_line(' open po_deliver table ' || x_cascaded_table(n).parent_transaction_id);
10953 END IF;
10954
10955 /* Bug3553796 - Deriving Distribution number when Distribution
10956 id is available. */
10957
10958 /* Bug3553796 - START */
10959 IF ( x_cascaded_table(n).po_distribution_id IS NOT NULL
10960 AND (x_cascaded_table(n).document_distribution_num IS NULL)) THEN
10961 BEGIN
10962 IF (g_asn_debug = 'Y') THEN
10963 asn_debug.put_line('Deriving Distribution Number from Distribution Id:' || x_cascaded_table(n).po_distribution_id);
10964 END IF;
10965
10966 SELECT distribution_num
10967 INTO x_cascaded_table(n).document_distribution_num
10968 FROM po_distributions
10969 WHERE po_distribution_id = x_cascaded_table(n).po_distribution_id;
10970
10971 IF (g_asn_debug = 'Y') THEN
10972 asn_debug.put_line('Derived Distribution Number:' || x_cascaded_table(n).document_distribution_num);
10973 END IF;
10974 EXCEPTION
10975 WHEN OTHERS THEN
10976 IF (g_asn_debug = 'Y') THEN
10977 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
10978 END IF;
10979 END;
10980 END IF;
10981
10982 /* Bug3553796 - END */
10983 IF (x_cascaded_table(n).document_distribution_num IS NULL) THEN --{
10984 IF (g_asn_debug = 'Y') THEN
10985 asn_debug.put_line('Distribution num is required for delivering multi distribution Po');
10986 END IF;
10987
10988 x_cascaded_table(n).error_status := 'F';
10989 rcv_error_pkg.set_error_message('RCV_DIST_NUM_REQ', x_cascaded_table(n).error_message);
10990 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
10991 END IF; --}
10992
10993 OPEN po_deliver(x_cascaded_table(n).parent_transaction_id,
10994 x_cascaded_table(n).to_organization_id,
10995 x_cascaded_table(n).document_distribution_num
10996 );
10997 already_derived := TRUE;
10998 ELSE --}{ /* Transfer, accept, reject and deliver with only one distribution */
10999 -- end if;
11000 already_derived := TRUE;
11001 END IF; --}
11002 END IF; --}
11003
11004 IF (g_asn_debug = 'Y') THEN
11005 asn_debug.put_line('l_num_of_distributions ' || l_num_of_distributions);
11006 END IF;
11007
11008 IF already_derived THEN --{
11009 IF ( (x_cascaded_table(n).transaction_type = 'DELIVER')
11010 AND (l_num_of_distributions = 1)) THEN --{
11011 IF (g_asn_debug = 'Y') THEN
11012 asn_debug.put_line(' open po_single_deliver table ' || x_cascaded_table(n).parent_transaction_id);
11013 END IF;
11014
11015 OPEN po_single_deliver(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
11016 ELSIF(x_cascaded_table(n).transaction_type <> 'DELIVER') THEN --}{
11017 /* For transfers, accept and reject */
11018 IF (g_asn_debug = 'Y') THEN
11019 asn_debug.put_line(' open po_transfer table ' || x_cascaded_table(n).parent_transaction_id);
11020 END IF;
11021
11022 OPEN po_transfer(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
11023 END IF; --}
11024 END IF; ---}
11025
11026 IF (NOT already_derived) THEN --{
11027 derive_parent_id(x_cascaded_table, n);
11028
11029 /* This means that there was no error in
11030 * derive_parent_id which means that the
11031 * this is a child and need to get the values
11032 * from the rti and not from the plsql table.
11033 */
11034 IF ( (x_cascaded_table(n).error_status <> 'E')
11035 AND ( x_cascaded_table(n).derive = 'Y'
11036 AND x_cascaded_table(n).derive_index = 0)) THEN --{
11037 /* if derive_values_from_table is true, then we
11038 * derive the values from the pl/sql tables later
11039 * at the time when we try to see which cursor is open.
11040 * We will have x_cascaded_table(n).
11041 * parent_interface_txn_id) populated with teh
11042 * correct value.
11043 */
11044 SELECT COUNT(*)
11045 INTO l_num_of_distributions
11046 FROM po_distributions
11047 WHERE line_location_id = (SELECT po_line_location_id
11048 FROM rcv_transactions_interface
11049 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id);
11050
11051 IF (g_asn_debug = 'Y') THEN
11052 asn_debug.put_line('l_num_of_distributions ' || l_num_of_distributions);
11053 END IF;
11054
11055 IF ( (x_cascaded_table(n).transaction_type = 'DELIVER')
11056 AND (l_num_of_distributions = 1)) THEN --{
11057 IF (g_asn_debug = 'Y') THEN
11058 asn_debug.put_line(' open Single deliver cursor from rti');
11059 END IF;
11060
11061 OPEN po_single_deliver_rti(x_cascaded_table(n).parent_interface_txn_id);
11062 ELSIF( (x_cascaded_table(n).transaction_type = 'DELIVER')
11063 AND (l_num_of_distributions > 1)) THEN --}{
11064
11065 /* Bug 5354379: {
11066 If the po_distribution_id is populated in RTI, then derive the
11067 distribution number from po_distributions_all table */
11068
11069 IF ( x_cascaded_table(n).po_distribution_id IS NOT NULL
11070 AND (x_cascaded_table(n).document_distribution_num IS NULL)) THEN
11071
11072 BEGIN
11073 IF (g_asn_debug = 'Y') THEN
11074 asn_debug.put_line('Deriving Distribution Number from Distribution Id:' || x_cascaded_table(n).po_distribution_id);
11075 END IF;
11076
11077 SELECT distribution_num
11078 INTO x_cascaded_table(n).document_distribution_num
11079 FROM po_distributions
11080 WHERE po_distribution_id = x_cascaded_table(n).po_distribution_id;
11081
11082 IF (g_asn_debug = 'Y') THEN
11083 asn_debug.put_line('Derived Distribution Number:' || x_cascaded_table(n).document_distribution_num);
11084 END IF;
11085
11086 EXCEPTION
11087 WHEN OTHERS THEN
11088 IF (g_asn_debug = 'Y') THEN
11089 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
11090 END IF;
11091 END;
11092 END IF;
11093 -- } bug 5354379
11094
11095 IF (x_cascaded_table(n).document_distribution_num IS NULL) THEN --{
11096 IF (g_asn_debug = 'Y') THEN
11097 asn_debug.put_line('Distribution num is required for delivering multi distribution Po');
11098 END IF;
11099
11100 x_cascaded_table(n).error_status := 'F';
11101 rcv_error_pkg.set_error_message('RCV_DIST_NUM_REQ', x_cascaded_table(n).error_message);
11102 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
11103 END IF; --}
11104
11105 IF (g_asn_debug = 'Y') THEN
11106 asn_debug.put_line(' open Multi deliver cursor from rti');
11107 END IF;
11108
11109 OPEN po_deliver_rti(x_cascaded_table(n).parent_interface_txn_id, x_cascaded_table(n).document_distribution_num);
11110 l_po_deliver_rti_cursor_opened := 1;--Bug 5354379
11111 ELSE --}{
11112 IF (g_asn_debug = 'Y') THEN
11113 asn_debug.put_line(' open transfer cursor from rti');
11114 END IF;
11115
11116 OPEN po_transfer_rti(x_cascaded_table(n).parent_interface_txn_id);
11117 END IF; --}
11118 END IF; --}
11119 END IF; --}
11120
11121 /******************************************************************/
11122 --check line quanity > 0
11123 x_progress := '097';
11124
11125 IF (g_asn_debug = 'Y') THEN
11126 asn_debug.put_line('X_progress ' || x_progress);
11127 END IF;
11128
11129 IF x_cascaded_table(n).error_status IN('S', 'W')
11130 AND x_cascaded_table(n).quantity <= 0 THEN --{
11131 IF (g_asn_debug = 'Y') THEN
11132 asn_debug.put_line('Quantity is <= zero. Cascade will fail');
11133 END IF;
11134
11135 x_cascaded_table(n).error_status := 'F';
11136 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
11137 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
11138 END IF; --} end qty > 0 check
11139
11140 -- the following steps will create a set of rows linking the line_record with
11141 -- its corresponding po_line_location rows until the quantity value from
11142 -- the asn is consumed. (Cascade)
11143
11144 /* 2119137 : If the user populates rcv_transactions_interface
11145 with po_line_id, then ROI errors out with
11146 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
11147 is not provided for one time items. Modified the "if" criteria in
11148 such a way that the ROI validation does'nt error out when
11149 po_line_id is populated for one time items. */
11150 x_progress := '098';
11151
11152 IF (g_asn_debug = 'Y') THEN
11153 asn_debug.put_line('X_progress ' || x_progress);
11154 END IF;
11155
11156 IF ( ( x_cascaded_table(n).parent_transaction_id IS NOT NULL
11157 OR x_cascaded_table(n).parent_interface_txn_id IS NOT NULL)
11158 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
11159
11160 -- Copy record from main table to temp table
11161 IF (g_asn_debug = 'Y') THEN
11162 asn_debug.put_line('Copy record from main table to temp table');
11163 END IF;
11164
11165 current_n := 1;
11166 temp_cascaded_table(current_n) := x_cascaded_table(n);
11167
11168 -- Get all rows which meet this condition
11169 IF (g_asn_debug = 'Y') THEN
11170 asn_debug.put_line('Get all rows which meet this condition');
11171 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
11172 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
11173 END IF;
11174
11175 -- Assign shipped quantity to remaining quantity
11176 IF (g_asn_debug = 'Y') THEN
11177 asn_debug.put_line('Assign populated quantity to remaining quantity ' || temp_cascaded_table(current_n).quantity);
11178 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
11179 END IF;
11180
11181 x_remaining_quantity := temp_cascaded_table(current_n).quantity;
11182 x_bkp_qty := x_remaining_quantity; -- used for decrementing cum qty for first record
11183 x_remaining_qty_po_uom := 0;
11184
11185 IF (g_asn_debug = 'Y') THEN
11186 asn_debug.put_line('Have assigned the quantity ' || x_remaining_quantity);
11187 END IF;
11188
11189 -- Calculate tax_amount_factor for calculating tax_amount for
11190 -- each cascaded line
11191
11192 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
11193 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_quantity;
11194 ELSE
11195 tax_amount_factor := 0;
11196 END IF;
11197
11198 IF (g_asn_debug = 'Y') THEN
11199 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
11200 asn_debug.put_line('Shipped Quantity : ' || TO_CHAR(x_remaining_quantity));
11201 END IF;
11202
11203 x_first_trans := TRUE;
11204 transaction_ok := FALSE;
11205
11206 IF (g_asn_debug = 'Y') THEN
11207 asn_debug.put_line('Before starting Cascade');
11208 END IF;
11209
11210 IF (g_asn_debug = 'Y') THEN
11211 asn_debug.put_line('Record Count = ' || x_record_count);
11212 END IF;
11213
11214 LOOP --{
11215 IF (g_asn_debug = 'Y') THEN
11216 asn_debug.put_line('Backup Qty ' || TO_CHAR(x_bkp_qty));
11217 asn_debug.put_line('Remaining Quantity ASN UOM ' || TO_CHAR(x_remaining_quantity));
11218 END IF;
11219
11220 /*
11221 ** Fetch the appropriate record
11222 */
11223 IF (g_asn_debug = 'Y') THEN
11224 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
11225 END IF;
11226
11227 IF (po_transfer%ISOPEN) THEN --{
11228 IF (g_asn_debug = 'Y') THEN
11229 asn_debug.put_line(' fetch po_transfer');
11230 END IF;
11231
11232 FETCH po_transfer INTO x_po_transferrec;
11233
11234 IF (po_transfer%NOTFOUND) THEN
11235 lastrecord := TRUE;
11236 END IF;
11237
11238 rows_fetched := po_transfer%ROWCOUNT;
11239 ELSIF(po_single_deliver%ISOPEN) THEN --}{
11240 IF (g_asn_debug = 'Y') THEN
11241 asn_debug.put_line(' fetch po_single_deliver');
11242 END IF;
11243
11244 FETCH po_single_deliver INTO x_po_transferrec;
11245
11246 IF (po_single_deliver%NOTFOUND) THEN
11247 IF (g_asn_debug = 'Y') THEN
11248 asn_debug.put_line('Single Deliver last row');
11249 END IF;
11250
11251 lastrecord := TRUE;
11252 END IF;
11253
11254 rows_fetched := po_single_deliver%ROWCOUNT;
11255 ELSIF(po_transfer_rti%ISOPEN) THEN --}{
11256 IF (g_asn_debug = 'Y') THEN
11257 asn_debug.put_line(' fetch po_transfer_rti');
11258 END IF;
11259
11260 FETCH po_transfer_rti INTO x_po_transferrec;
11261
11262 IF (po_transfer_rti%NOTFOUND) THEN
11263 IF (g_asn_debug = 'Y') THEN
11264 asn_debug.put_line('transfer last row');
11265 END IF;
11266
11267 lastrecord := TRUE;
11268 END IF;
11269
11270 rows_fetched := po_transfer_rti%ROWCOUNT;
11271 ELSIF(po_single_deliver_rti%ISOPEN) THEN --}{
11272 IF (g_asn_debug = 'Y') THEN
11273 asn_debug.put_line(' fetch po_single_deliver_rti');
11274 END IF;
11275
11276 FETCH po_single_deliver_rti INTO x_po_transferrec;
11277
11278 IF (po_single_deliver_rti%NOTFOUND) THEN
11279 IF (g_asn_debug = 'Y') THEN
11280 asn_debug.put_line('single_deliver_rti last row');
11281 END IF;
11282
11283 lastrecord := TRUE;
11284 END IF;
11285
11286 rows_fetched := po_single_deliver_rti%ROWCOUNT;
11287 ELSIF( po_deliver%ISOPEN
11288 AND x_cascaded_table(n).document_distribution_num IS NOT NULL) THEN --}{
11289 IF (g_asn_debug = 'Y') THEN
11290 asn_debug.put_line(' fetch po_deliver');
11291 END IF;
11292
11293 FETCH po_deliver INTO x_po_transferrec;
11294
11295 IF (po_deliver%NOTFOUND) THEN
11296 lastrecord := TRUE;
11297 END IF;
11298
11299 IF (firstrecord) THEN
11300 IF (g_asn_debug = 'Y') THEN
11301 asn_debug.put_line('first record for multi distributions');
11302 END IF;
11303
11304 firstrecord := FALSE;
11305
11306 SELECT quantity
11307 INTO l_total_rec_quantity
11308 FROM rcv_supply
11309 WHERE rcv_transaction_id = x_po_transferrec.rcv_transaction_id
11310 AND supply_type_code = 'RECEIVING';
11311 END IF;
11312
11313 IF (g_asn_debug = 'Y') THEN
11314 asn_debug.put_line(' l_total_rec_quantity ' || l_total_rec_quantity);
11315 END IF;
11316
11317 rows_fetched := po_deliver%ROWCOUNT;
11318 ELSIF(po_deliver_rti%ISOPEN) THEN --}{
11319 IF (g_asn_debug = 'Y') THEN
11320 asn_debug.put_line(' fetch po_deliver_rti');
11321 END IF;
11322
11323 FETCH po_deliver_rti INTO x_po_transferrec;
11324
11325 IF (po_deliver_rti%NOTFOUND) THEN
11326 IF (g_asn_debug = 'Y') THEN
11327 asn_debug.put_line('deliver_rti last row');
11328 END IF;
11329
11330 lastrecord := TRUE;
11331 END IF;
11332
11333 l_total_rec_quantity := x_po_transferrec.qty;
11334
11335 IF (g_asn_debug = 'Y') THEN
11336 asn_debug.put_line(' l_total_rec_quantity if multi distribution from rti ' || x_po_transferrec.qty);
11337 END IF;
11338
11339 rows_fetched := po_deliver_rti%ROWCOUNT;
11340 ELSIF(temp_cascaded_table(current_n).derive = 'Y') THEN --}{
11341 /* GET VALUES FROM THE PLSQL TABLE */
11342 /* Populate x_po_transferrec with these values since
11343 * we are using x_po_transferrec later.
11344 * We have temp_cascaded_table(current_n).
11345 * parent_interface_txn_id) populated with
11346 * with the correct value. Also we have cascaded_table_index
11347 * with the correct pl/sql table index number;
11348 */
11349 IF (g_asn_debug = 'Y') THEN
11350 asn_debug.put_line(' fetch pl/sql table');
11351 END IF;
11352
11353 temp_index := temp_cascaded_table(current_n).derive_index;
11354 x_po_transferrec.po_line_location_id := x_cascaded_table(temp_index).po_line_location_id;
11355 x_po_transferrec.po_head_id := x_cascaded_table(temp_index).po_header_id;
11356 x_po_transferrec.line_id := x_cascaded_table(temp_index).po_line_id;
11357 x_po_transferrec.unit_of_meas := x_cascaded_table(temp_index).unit_of_measure;
11358 x_po_transferrec.document_num := x_cascaded_table(temp_index).document_num;
11359 x_po_transferrec.line_number := x_cascaded_table(temp_index).document_line_num;
11360 x_po_transferrec.transaction_date := x_cascaded_table(temp_index).transaction_date;
11361 x_po_transferrec.transaction_type := x_cascaded_table(temp_index).transaction_type;
11362 x_po_transferrec.primary_unit_of_measure := x_cascaded_table(temp_index).primary_unit_of_measure;
11363 x_po_transferrec.primary_quantity := x_cascaded_table(temp_index).primary_quantity;
11364 x_po_transferrec.to_organization_id := x_cascaded_table(temp_index).to_organization_id;
11365 x_po_transferrec.unit_price := x_cascaded_table(temp_index).po_unit_price;
11366 x_po_transferrec.category_id := x_cascaded_table(temp_index).category_id;
11367 x_po_transferrec.item_description := x_cascaded_table(temp_index).item_description;
11368 x_po_transferrec.location_id := x_cascaded_table(temp_index).location_id;
11369 x_po_transferrec.item_id := x_cascaded_table(temp_index).item_id;
11370 x_po_transferrec.deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
11371 x_po_transferrec.deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
11372 x_po_transferrec.destination_subinventory := x_cascaded_table(temp_index).subinventory;
11373 x_po_transferrec.po_distribution_id := x_cascaded_table(temp_index).po_distribution_id;
11374 x_po_transferrec.destination_type_code := x_cascaded_table(temp_index).destination_type_code;
11375 x_po_transferrec.code_combination_id := x_cascaded_table(temp_index).charge_account_id;
11376 x_po_transferrec.req_distribution_id := x_cascaded_table(temp_index).req_distribution_id;
11377 x_po_transferrec.wip_entity_id := x_cascaded_table(temp_index).wip_entity_id;
11378 x_po_transferrec.wip_operation_seq_num := x_cascaded_table(temp_index).wip_operation_seq_num;
11379 x_po_transferrec.wip_resource_seq_num := x_cascaded_table(temp_index).wip_resource_seq_num;
11380 x_po_transferrec.wip_repetitive_schedule_id := x_cascaded_table(temp_index).wip_repetitive_schedule_id;
11381 x_po_transferrec.wip_line_id := x_cascaded_table(temp_index).wip_line_id;
11382 x_po_transferrec.bom_resource_id := x_cascaded_table(temp_index).bom_resource_id;
11383 x_po_transferrec.ussgl_transaction_code := x_cascaded_table(temp_index).ussgl_transaction_code;
11384 x_po_transferrec.qty := x_cascaded_table(temp_index).quantity;
11385 rows_fetched := 1;
11386 lastrecord := TRUE;
11387 END IF; --}
11388
11389
11390 --x_remaining_quantity:= temp_cascaded_table(current_n).quantity;
11391
11392 IF (g_asn_debug = 'Y') THEN
11393 asn_debug.put_line('Transfer Rows fetched ' || TO_CHAR(rows_fetched));
11394 asn_debug.put_line('po_line_id ' || TO_CHAR(x_po_transferrec.po_line_id));
11395 asn_debug.put_line('po_dist ' || TO_CHAR(x_po_transferrec.po_distribution_id));
11396 asn_debug.put_line('Transfer remainaing qty ' || x_remaining_quantity);
11397 END IF;
11398
11399 /* { Bug 5354379: To log meaningful error message with the PO number, PO line number
11400 PO line location number and distribution number and transaction qty.
11401 Using the message RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO instead of
11402 RCV_TRX_QTY_EXCEEDS_AVAILABLE */
11403 BEGIN
11404 select segment1
11405 into l_po_num
11406 from po_headers_all
11407 where po_header_id = x_po_transferrec.po_head_id;
11408
11409 select line_num
11410 into l_po_line_num
11411 from po_lines_all
11412 where po_line_id = x_po_transferrec.po_line_id;
11413
11414 select shipment_num
11415 into l_po_line_loc_num
11416 from po_line_locations_all
11417 where line_location_id = x_po_transferrec.po_line_location_id;
11418
11419 select distribution_num
11420 into l_po_dist_num
11421 from po_distributions_all
11422 where po_distribution_id = x_po_transferrec.po_distribution_id;
11423
11424 if x_cascaded_table(n).po_release_id is not null then --5439085
11425 select release_num
11426 into l_po_rel_num
11427 from po_releases_all
11428 where po_release_id = x_cascaded_table(n).po_release_id;
11429 end if;
11430 EXCEPTION
11431 WHEN NO_DATA_FOUND THEN
11432 IF (g_asn_debug = 'Y') THEN
11433 asn_debug.put_line('No data found exception while getting document info for PO');
11434 END IF;
11435 END;
11436 -- } Bug 5354379
11437
11438 /* FPJ SERVICES START.
11439 * We do not support Transfer/Deliver/Inspect transaction for a
11440 * Serive based PO.
11441 */
11442 /* R12 Complex work.
11443 * We do not support any other receiving transactions other
11444 * than direct receipt. Error out if it is complex work PO.
11445 */
11446 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
11447 IF (g_asn_debug = 'Y') THEN
11448 asn_debug.put_line('Parent_txn_id ' || x_cascaded_table(n).parent_transaction_id);
11449 END IF;
11450
11451 SELECT po_line_id,po_header_id
11452 INTO l_service_po_line_id,l_po_header_id
11453 FROM rcv_transactions
11454 WHERE transaction_id = x_cascaded_table(n).parent_transaction_id;
11455 ELSIF(x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
11456 IF (g_asn_debug = 'Y') THEN
11457 asn_debug.put_line('parent_interface_txn_id ' || x_cascaded_table(n).parent_interface_txn_id);
11458 END IF;
11459
11460 SELECT po_line_id,po_header_id
11461 INTO l_service_po_line_id,l_po_header_id
11462 FROM rcv_transactions_interface
11463 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
11464 END IF;
11465
11466 IF (g_asn_debug = 'Y') THEN
11467 asn_debug.put_line('l_service_po_line_id ' || l_service_po_line_id);
11468 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
11469 END IF;
11470
11471 IF l_service_po_line_id IS NOT NULL THEN --{
11472 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
11473 NVL(purchase_basis, 'GOODS'),
11474 NVL(matching_basis, 'QUANTITY')
11475 INTO l_value_basis,
11476 l_purchase_basis,
11477 l_matching_basis
11478 FROM po_lines
11479 WHERE po_line_id = l_service_po_line_id;
11480
11481 IF (l_matching_basis = 'AMOUNT') THEN
11482 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
11483 rcv_error_pkg.set_error_message('RCV_NO_SERVICE_SUPPORT_TRX', x_cascaded_table(n).error_message);
11484 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
11485 END IF;
11486 END IF; --}
11487
11488 /* FPJ SERVICES END. */
11489
11490 /* R12 Complex work.
11491 * We do not support any other receiving transactions other
11492 * than direct receipt. Error out if it is complex work PO.
11493 */
11494
11495 PO_COMPLEX_WORK_GRP.is_complex_work_po(
11496 1.0,
11497 l_po_header_id,
11498 l_return_status,
11499 l_complex_flag);
11500 IF (l_return_status IS NOT NULL AND
11501 l_return_status = FND_API.g_ret_sts_success) THEN
11502 IF( g_asn_debug = 'Y' ) THEN
11503 asn_debug.put_line('l_return_status ' || l_return_status);
11504 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
11505 END IF;
11506 ELSE
11507 IF( g_asn_debug = 'Y') THEN
11508 asn_debug.put_line('l_return_status ' || l_return_status);
11509 END IF;
11510 END IF;
11511
11512 IF (l_complex_flag = 'Y') THEN
11513 asn_debug.put_line('We do not support transaction type ' || x_cascaded_table(n).transaction_type || ' for complex work POs');
11514 rcv_error_pkg.set_error_message('RCV_INVALID_TRANSACTION_TYPE');
11515 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
11516 End if;
11517
11518
11519
11520
11521
11522 IF ( lastrecord
11523 OR x_remaining_quantity <= 0) THEN --{
11524 IF (g_asn_debug = 'Y') THEN
11525 asn_debug.put_line('Hit exit condition');
11526 END IF;
11527
11528 IF NOT x_first_trans THEN
11529 -- x_first_trans has been reset which means some cascade has
11530 -- happened. Otherwise current_n = 1
11531 IF (g_asn_debug = 'Y') THEN
11532 asn_debug.put_line('current_n before is ' || current_n);
11533 END IF;
11534
11535 current_n := current_n - 1;
11536 END IF;
11537
11538 -- do the tolerance act here
11539 IF (g_asn_debug = 'Y') THEN
11540 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
11541 asn_debug.put_line('Check which condition has occured');
11542 END IF;
11543
11544 -- lastrecord...we have run out of rows and we still have quantity to allocate
11545 IF (round(x_remaining_quantity,6) > 0) THEN --{ Bug 13703497
11546 IF (g_asn_debug = 'Y') THEN
11547 asn_debug.put_line('There is quantity remaining');
11548 asn_debug.put_line('Need to check qty tolerances');
11549 END IF;
11550
11551 IF rows_fetched > 0
11552 AND NOT x_first_trans THEN --{
11553 NULL;
11554
11555 /* for transfer,accept an reject type we dont have the
11556 * tolerance check. Hence error out.
11557 * We cannot transfer quantities more than that was received.
11558 */
11559 IF (g_asn_debug = 'Y') THEN
11560 asn_debug.put_line(' in transfer Extra ASN UOM Quantity ' || TO_CHAR(x_remaining_quantity));
11561 asn_debug.put_line('Extra PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
11562 END IF;
11563
11564 IF (g_asn_debug = 'Y') THEN
11565 asn_debug.put_line('delete the temp table ');
11566 END IF;
11567
11568 -- <Bug 9342280 : Added for CLM project>
11569 IF x_cascaded_table(n).transaction_type = 'DELIVER' THEN
11570 get_clm_info( 'QUANTITY',
11571 x_cascaded_table,
11572 n,
11573 l_is_clm_po,
11574 l_partial_funded_flag);
11575 END IF;
11576 -- <CLM END>
11577
11578 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
11579
11580 -- <Bug 9342280 : Added for CLM project>
11581 IF (l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' AND
11582 x_cascaded_table(n).transaction_type = 'DELIVER') THEN
11583
11584 IF l_po_rel_num = -1 THEN
11585
11586 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEEDS_FUNDED', x_cascaded_table(n).error_message);
11587 ELSE
11588 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEED_FUNDED', x_cascaded_table(n).error_message);
11589 rcv_error_pkg.set_token('RELNUM', l_po_rel_num);
11590 END IF;
11591
11592 rcv_error_pkg.set_token('TXNQTY', x_cascaded_table(n).quantity);
11593 rcv_error_pkg.set_token('AVLQTY', x_cascaded_table(n).quantity - x_remaining_quantity);
11594 rcv_error_pkg.set_token('PONUM', l_po_num);
11595 rcv_error_pkg.set_token('LINENUM', l_po_line_num);
11596 rcv_error_pkg.set_token('SHIPNUM', l_po_line_loc_num);
11597 rcv_error_pkg.set_token('DISTNUM', l_po_dist_num);
11598
11599 ELSE
11600 -- <CLM END>
11601
11602 IF l_po_rel_num = -1 THEN--Bug 5439085
11603 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
11604 ELSE
11605 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
11606 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
11607 END IF;
11608 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
11609 rcv_error_pkg.set_token('AVLQTY',x_cascaded_table(n).quantity - x_remaining_quantity);
11610 rcv_error_pkg.set_token('PONUM', l_po_num );
11611 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
11612 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
11613 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
11614
11615 END IF; -- <Bug 9342280 : Added for CLM project>
11616
11617 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
11618
11619 IF temp_cascaded_table.COUNT > 0 THEN
11620 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
11621 temp_cascaded_table.DELETE(i);
11622 END LOOP;
11623 END IF;
11624
11625 IF (g_asn_debug = 'Y') THEN
11626 asn_debug.put_line('mark the actual table with error status');
11627 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
11628 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
11629 END IF;
11630
11631 IF (g_asn_debug = 'Y') THEN
11632 asn_debug.put_line('Need to insert a row into po_interface_errors for transfer');
11633 END IF;
11634 ELSE --}{ else for rows fetched = 0 OR x_first_trans = true
11635 IF rows_fetched = 0 THEN
11636 IF (g_asn_debug = 'Y') THEN
11637 asn_debug.put_line('No rows were retrieved from cursor.');
11638 END IF;
11639 ELSIF x_first_trans THEN
11640 IF (g_asn_debug = 'Y') THEN
11641 asn_debug.put_line('No rows were cascaded');
11642 END IF;
11643 END IF;
11644
11645 x_temp_count := 1;
11646 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
11647
11648 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
11649
11650 SELECT transaction_type
11651 INTO l_transaction_type
11652 FROM rcv_transactions
11653 WHERE transaction_id = temp_cascaded_table(current_n).parent_transaction_id;
11654
11655 IF l_transaction_type = 'UNORDERED' THEN
11656 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
11657 rcv_error_pkg.set_error_message('RCV_INVALID_PARENT_TRX_TYPE', x_cascaded_table(n).error_message);
11658 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
11659 ELSE -- all other cases can be categorized as no receive supply
11660 rcv_error_pkg.set_error_message('RCV_NO_RECEIVE_SUPPLY', x_cascaded_table(n).error_message);
11661 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
11662 END IF;
11663 END IF; --}
11664
11665 -- Delete the temp_cascaded_table just to be sure
11666
11667 IF temp_cascaded_table.COUNT > 0 THEN
11668 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
11669 temp_cascaded_table.DELETE(i);
11670 END LOOP;
11671 END IF;
11672 END IF; --} end else for rows fetched = 0 OR x_first_trans = true
11673 -- end x_remaining_qty > 0 => this is the last record
11674 ELSE -- }{
11675 -- Bug 13703497
11676 x_remaining_quantity := 0;
11677 x_remaining_qty_po_uom := 0;
11678
11679 IF (g_asn_debug = 'Y') THEN
11680 asn_debug.put_line('Remaining UOM quantity is zero ' || TO_CHAR(x_remaining_quantity));
11681 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
11682 END IF;
11683 END IF; --} ends the check for whether last record has been reached
11684
11685 -- close cursors
11686
11687 IF (g_asn_debug = 'Y') THEN
11688 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions ' || current_n);
11689 END IF;
11690
11691 IF po_transfer%ISOPEN THEN
11692 CLOSE po_transfer;
11693 END IF;
11694
11695 IF po_transfer_rti%ISOPEN THEN
11696 CLOSE po_transfer_rti;
11697 END IF;
11698
11699 IF po_single_deliver%ISOPEN THEN
11700 CLOSE po_single_deliver;
11701 END IF;
11702
11703 IF po_single_deliver_rti%ISOPEN THEN
11704 CLOSE po_single_deliver_rti;
11705 END IF;
11706
11707 IF po_deliver%ISOPEN THEN
11708 CLOSE po_deliver;
11709 END IF;
11710
11711 IF (g_asn_debug = 'Y') THEN
11712 asn_debug.put_line('before exit current_n is ' || current_n);
11713 END IF;
11714
11715 EXIT;
11716 END IF; --} matches lastrecord or x_remaining_quantity <= 0
11717
11718 -- eliminate the row if it fails the date check
11719
11720 IF (g_asn_debug = 'Y') THEN
11721 asn_debug.put_line(' Entering qty calculateion for transfer');
11722 END IF;
11723
11724 IF (x_first_trans)
11725 AND temp_cascaded_table(current_n).item_id IS NULL THEN
11726 temp_cascaded_table(current_n).item_id := x_po_transferrec.item_id;
11727 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_transferrec.primary_unit_of_measure;
11728 END IF;
11729
11730 insert_into_table := FALSE;
11731 already_allocated_qty := 0;
11732 get_interface_available_qty(temp_cascaded_table,
11733 current_n,
11734 x_converted_parent_trx_qty
11735 );
11736
11737 IF (g_asn_debug = 'Y') THEN
11738 asn_debug.put_line('trans_del interface qty ' || x_converted_parent_trx_qty);
11739 END IF;
11740
11741 /* If this is a deliver for a multi distribution PO shipment
11742 * line and if its parent is in rti, then x_converted_parent_trx_qty
11743 * will not be 0 and l_num_of_distributions will be > 1. In this
11744 * case we need to make sure that the transaction qty is less than
11745 * or equal to the available qty in rti and also less than or
11746 * equal to the qty in po_distributions.
11747 */
11748 IF ( (temp_cascaded_table(1).transaction_type = 'DELIVER')
11749 AND (l_num_of_distributions > 1)) THEN --{
11750 IF (g_asn_debug = 'Y') THEN
11751 asn_debug.put_line('before getting available qty for standard multi distributions deliver ');
11752 END IF;
11753
11754 -- <Bug 9342280 : Added for CLM project>
11755 get_clm_info('QUANTITY',
11756 x_cascaded_table,
11757 n,
11758 l_is_clm_po,
11759 l_partial_funded_flag);
11760 -- <CLM END>
11761
11762
11763 /* Bug 5354379:
11764 We should not compare the transaction quantity with the po_distributions_all.ordered_quantity,
11765 because we won't be able to do DELIVER txn for the RECEIVE txns with overreceipt made.
11766 If the RECEIVE txn for that DELIVER txns lies in RT, we have to make use of mtl_supply
11767 to get the AVAILABLE quantity for DELIVER txn.
11768 If the RECEIVE txn for that DELIVER txns lies in RTI, there is no mtl_supply or rcv_supply.
11769 So, get the available qty from RTI for that DELIVER txn
11770 */
11771
11772 IF l_po_deliver_rti_cursor_opened = 1 THEN --{ l_po_deliver_rti_cursor_opened = 1
11773 IF (g_asn_debug = 'Y') THEN
11774 asn_debug.put_line('In l_po_deliver_rti_cursor_opened...');
11775 END IF;
11776 l_interface_txn_id := x_cascaded_table(n).interface_transaction_id;
11777
11778 --In the following 2 loops, trying to get the RECEIVE txn id for the current DELIVER txn.
11779 --Once the controll comes out of the LOOP successfully,
11780 --If the "RECEIVE txn for the current DELIVER txn is available in RT,
11781 --RECEIVE txn id is fetched from RT and it will be available in the variable l_parent_transaction_id
11782
11783 --If the "RECEIVE txn for the current DELIVER txn is available in RTI,
11784 --RECEIVE interface txn id is fetched from RTI and it will be available in the variable l_parent_interface_txn_id
11785
11786 LOOP --{ loop1
11787 IF (g_asn_debug = 'Y') THEN
11788 asn_debug.put_line('Inside LOOP1 to fetch RECEIVE txn_id....');
11789 asn_debug.put_line('Fetching record from RTI, l_interface_txn_id'||l_interface_txn_id);
11790 END IF;
11791
11792 BEGIN --{
11793 SELECT parent_interface_txn_id,
11794 parent_transaction_id,
11795 transaction_type
11796 INTO l_parent_interface_txn_id,
11797 l_parent_transaction_id,
11798 l_transaction_type
11799 FROM rcv_transactions_interface
11800 WHERE interface_transaction_id = l_interface_txn_id;
11801
11802 IF l_parent_transaction_id IS NOT NULL THEN--{
11803 --parent txn is available in rcv_transactions table
11804 l_transaction_id := l_parent_transaction_id;
11805 LOOP --{ loop2
11806 --Fetch the record from rcv_transactions table
11807 IF (g_asn_debug = 'Y') THEN
11808 asn_debug.put_line('Inside LOOP2 to fetch RECEIVE txn_id....');
11809 asn_debug.put_line('Fetching record from RT, l_transaction_id'||l_transaction_id);
11810 END IF;
11811
11812 SELECT transaction_type,
11813 parent_transaction_id
11814 INTO l_transaction_type,
11815 l_parent_transaction_id
11816 FROM rcv_transactions
11817 WHERE transaction_id = l_transaction_id;
11818
11819 IF l_transaction_type = 'RECEIVE' THEN --{
11820 --exit loop1 and loop2
11821 --return l_transaction_id
11822 l_parent_transaction_id := l_transaction_id;
11823 IF (g_asn_debug = 'Y') THEN
11824 asn_debug.put_line('Fetched RECEIVE txn_id from RT....'||l_parent_transaction_id);
11825 END IF;
11826 l_exit := 'Y';
11827 EXIT; --exit loop2
11828 ELSIF l_parent_transaction_id IS NOT NULL THEN
11829 --continue LOOP2, till you fetch RECEIVE txnid
11830 l_transaction_id := l_parent_transaction_id;
11831 ELSE
11832 --Error condition
11833 l_exit := 'Y';
11834 l_loop_exit_status := 'E';
11835 IF (g_asn_debug = 'Y') THEN
11836 asn_debug.put_line('Error condition..parent_txn_id is null, not able to fetch RECEIVE txn_id');
11837 END IF;
11838 EXIT; --exit loop2
11839 END IF; --} l_transaction_type = 'RECEIVE'
11840 END LOOP; --{ loop2
11841
11842 ELSIF l_parent_interface_txn_id IS NOT NULL THEN --{ l_parent_interface_txn_id IS NOT NULL
11843 --parent txn is available in rcv_transactions_intreface table
11844 --continue LOOP1, till you fetch RECEIVE txnid
11845 l_interface_txn_id := l_parent_interface_txn_id;
11846 --}l_parent_interface_txn_id IS NOT NULL
11847 ELSE --{
11848 --Check whether, the RECEIVE txn for this DELIVER is in RTI
11849 --Then we have to get AVAILABLE qty from RTI, as there is no RS or MS
11850 --For the RECEIVE txn only RHI will be there, there won't be no parent_txn_id or
11851 --parent_interface_txn_id
11852 IF l_transaction_type = 'RECEIVE' THEN --{
11853 --exit loop1 and return l_interface_txn_id
11854 --This is the RECEIVE txn in RTI
11855 l_parent_interface_txn_id := l_interface_txn_id;
11856 l_parent_receive_txn_in_rt := 'N';
11857 l_loop_exit_status := 'S';
11858 IF (g_asn_debug = 'Y') THEN
11859 asn_debug.put_line('Fetched RECEIVE interface txn_id from RTI....'||l_parent_interface_txn_id);
11860 END IF;
11861 ELSE
11862 --Error condtion
11863 l_loop_exit_status := 'E';
11864 IF (g_asn_debug = 'Y') THEN
11865 asn_debug.put_line('Error condition..parent_interface_txn_id is null, not able to fetch RECEIVE txn_id');
11866 END IF;
11867 END IF;
11868 l_exit := 'Y';
11869 EXIT; --exit loop1
11870 --}
11871 END IF;--} l_parent_transaction_id is not null
11872 EXCEPTION
11873 WHEN NO_DATA_FOUND then
11874 l_exit := 'Y';
11875 l_loop_exit_status := 'E';
11876 IF (g_asn_debug = 'Y') THEN
11877 asn_debug.put_line('No data found exception occured in Fetching RECEIVE txn_id');
11878 END IF;
11879 END;--} BEGIN ends
11880
11881 --Check Exit condition met
11882 IF l_exit = 'Y' THEN
11883 IF (g_asn_debug = 'Y') THEN
11884 asn_debug.put_line('Exiting the loop to Fetch RECEIVE txn_id....');
11885 END IF;
11886 EXIT;--exit loop1
11887 END IF;
11888 END LOOP; --}loop1
11889
11890 --Check Loop exited successfuly by fetching the RECEIVE txn id
11891 IF l_loop_exit_status = 'E' THEN --{
11892 --Error out this DELIVER txn and set RTI record status to 'E'
11893 IF (g_asn_debug = 'Y') THEN
11894 asn_debug.put_line('Error out this DELIVER txn and set RTI record status to Error, as not able get RECEIVE txn_id....');
11895 END IF;
11896 x_cascaded_table(n).error_status := 'E';
11897 ELSIF l_loop_exit_status = 'S' THEN --{ l_loop_exit_status = 'S'
11898 --Check where to get the AVAILABLE qty for this DELIVER txn
11899 -- if l_parent_receive_txn_in_rt is 'Y', Fetch the AVAILABLE qty from mtl_supply
11900 -- if l_parent_receive_txn_in_rt is 'N', Fetch the AVAILABLE qty from rcv_transactions_interface
11901 IF l_parent_receive_txn_in_rt = 'Y' THEN--{ l_parent_receive_txn_in_rt = 'Y'
11902 --Fetch AVAILABLE qty from mtl_supply using l_parent_transaction_id
11903
11904 BEGIN --{
11905 IF (g_asn_debug = 'Y') THEN
11906 asn_debug.put_line('Fetching mtl_supply, from the fetched RECEIVE txn_id....'||l_parent_transaction_id);
11907 asn_debug.put_line('PO distribution id....'||x_po_transferrec.po_distribution_id);
11908 END IF;
11909 /*Fetch the available qty for DELIVER txn based on the shipment line from mtl_supply.
11910 Reason: When RECEIPT txn is performed through forms, we won't get distribution details.
11911 For eg: Assume PO with 1 line(qty15) 1shipment(15) and
11912 2distributions(1st distribution qty:10 and 2nd distribution qty:5)
11913 Through forms perform ACCEPT txn for qty 15 and perform delivery on
11914 ditribution1 for qty:15. Transaction is allowed.
11915 We should have same behavoiur, when it is done through ROI also.
11916 Another case, When user peforms Overreceipt for the similar PO(mentioned above)through
11917 forms for qty 30. As per Cascading logic, in mtl_supply we are having qty:10 for distribution1
11918 and qty:20 in case of distribution2. But user is not aware of this cascading done in mtl_supply.
11919 So, we have to allow over delivery on the specified distribution, if it is with in the
11920 received qty for that shipment line.
11921 So, modifying the following sql to get Available qty based on shipment_line*/
11922 -- x_cascaded_table(n) is holding current DELIVER txn record
11923 SELECT nvl(sum(quantity),0)
11924 INTO l_distribution_qty
11925 FROM mtl_supply
11926 WHERE supply_source_id = l_parent_transaction_id
11927 AND po_line_location_id = x_cascaded_table(n).po_line_location_id
11928 AND supply_type_code = 'RECEIVING';
11929
11930 SELECT unit_meas_lookup_code
11931 INTO l_ship_unit
11932 FROM po_line_locations
11933 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
11934
11935 EXCEPTION
11936 WHEN NO_DATA_FOUND THEN
11937 --Error out DELIVER txn and set RTI status to 'E'
11938 l_fetch_mtl_supply := 'E';
11939 IF (g_asn_debug = 'Y') THEN
11940 asn_debug.put_line('No data found exception in fetching mtl_supply');
11941 END IF;
11942 END; --} Begin ends
11943
11944 IF l_fetch_mtl_supply = 'E' THEN
11945 --Error out this DELIVER txn and set RTI record status to 'E'
11946 IF (g_asn_debug = 'Y') THEN
11947 asn_debug.put_line('mtl_supply doesnot exist. error out the DELIVER txn...');
11948 END IF;
11949 x_cascaded_table(n).error_status := 'E';
11950
11951 -- <Bug 9342280 : Added for CLM project>
11952
11953 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
11954
11955 IF l_po_rel_num = -1 THEN
11956
11957 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEEDS_FUNDED',x_cascaded_table(n).error_message);
11958 ELSE
11959 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEED_FUNDED',x_cascaded_table(n).error_message);
11960 rcv_error_pkg.set_token('RELNUM', l_po_rel_num);
11961 END IF;
11962
11963 rcv_error_pkg.set_token('TXNQTY', x_cascaded_table(n).quantity);
11964 rcv_error_pkg.set_token('AVLQTY', 0);
11965 rcv_error_pkg.set_token('PONUM', l_po_num);
11966 rcv_error_pkg.set_token('LINENUM', l_po_line_num);
11967 rcv_error_pkg.set_token('SHIPNUM', l_po_line_loc_num);
11968 rcv_error_pkg.set_token('DISTNUM', l_po_dist_num);
11969
11970 ELSE
11971 -- <CLM END>
11972
11973 IF l_po_rel_num = -1 THEN--Bug 5439085
11974 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
11975 ELSE
11976 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
11977 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
11978 END IF;
11979 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
11980 rcv_error_pkg.set_token('AVLQTY',0);
11981 rcv_error_pkg.set_token('PONUM', l_po_num );
11982 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
11983 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
11984 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
11985
11986 END IF; -- <Bug 9342280 : Added for CLM project>
11987
11988 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
11989 END IF;
11990
11991 IF (g_asn_debug = 'Y') THEN
11992 asn_debug.put_line('l_distribution_qty:'||l_distribution_qty);
11993 asn_debug.put_line('Check whether l_distribution_qty is already consumed by other DELIVER txn submitted with same group_id');
11994 END IF;
11995
11996 --Fetch sum of quantity of only pre processed 'DELIVER' txns in RTI for that group_id
11997 --and po_shipment_line, to get total_deliver_qty for that po_shipment_line
11998 --( by this filter interface_transaction_id < x_po_transferrec.interface_transaction_id,
11999 -- only fetching preprocessed deliver txn)
12000 --Removing the condition on po_distribution_id, as we are honouring the DELIVER txn
12001 --based on the shipment_level quantity available in mtl_supply
12002 BEGIN--{
12003 SELECT nvl(sum(quantity),0)
12004 INTO l_total_deliver_quantity
12005 FROM rcv_transactions_interface
12006 WHERE (transaction_status_code = 'PENDING'
12007 AND processing_status_code <> 'ERROR')
12008 AND transaction_type = 'DELIVER'
12009 AND group_id = x_cascaded_table(n).group_id
12010 AND po_line_location_id = x_po_transferrec.po_line_location_id
12011 AND interface_transaction_id < x_cascaded_table(n).interface_transaction_id;
12012 EXCEPTION
12013 WHEN NO_DATA_FOUND then
12014 IF (g_asn_debug = 'Y') THEN
12015 asn_debug.put_line('No data found exception while fetching sum of delivered qty..');
12016 END IF;
12017 l_total_deliver_quantity := 0;
12018 END;--} Begin ends
12019
12020 IF (g_asn_debug = 'Y') THEN
12021 asn_debug.put_line('Sum of delivered qty for preprocessed DELIVERED txns..'||l_total_deliver_quantity);
12022 END IF;
12023
12024 --x_cascaded_table(n).quantity -> transaction qty of current Deliver txn
12025 -- l_distribution_qty -> qty available in mtl_supply
12026 -- l_total_deliver_quantity -> Quantity already consumed by the DELIVER txns(only precprocessed RTI record) submitted with the same group_id
12027 IF x_cascaded_table(n).quantity > (l_distribution_qty - l_total_deliver_quantity) THEN --{ x_cascaded_table(n).quantity > (l_distribution_qty - l_total_deliver_quantity)
12028 --Error out this DELIVERY txn, as it results in Over delivery on that distribution
12029 IF (g_asn_debug = 'Y') THEN
12030 asn_debug.put_line('Error out this DELIVERY txn, as it results in Over delivery on that distribution'||x_po_transferrec.po_distribution_id);
12031 END IF;
12032 x_cascaded_table(n).error_status := 'E';
12033
12034 -- <Bug 9342280 : Added for CLM project>
12035
12036 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
12037
12038 IF l_po_rel_num = -1 THEN
12039
12040 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEEDS_FUNDED',x_cascaded_table(n).error_message);
12041 ELSE
12042
12043 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEED_FUNDED',x_cascaded_table(n).error_message);
12044 rcv_error_pkg.set_token('RELNUM', l_po_rel_num);
12045 END IF;
12046
12047 rcv_error_pkg.set_token('TXNQTY', x_cascaded_table(n).quantity);
12048 rcv_error_pkg.set_token('AVLQTY',l_distribution_qty - l_total_deliver_quantity);
12049 rcv_error_pkg.set_token('PONUM', l_po_num);
12050 rcv_error_pkg.set_token('LINENUM', l_po_line_num);
12051 rcv_error_pkg.set_token('SHIPNUM', l_po_line_loc_num);
12052 rcv_error_pkg.set_token('DISTNUM', l_po_dist_num);
12053
12054 ELSE
12055 -- <CLM END>
12056
12057 IF l_po_rel_num = -1 THEN--Bug 5439085
12058 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
12059 ELSE
12060 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
12061 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
12062 END IF;
12063 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
12064 rcv_error_pkg.set_token('AVLQTY',l_distribution_qty - l_total_deliver_quantity);
12065 rcv_error_pkg.set_token('PONUM', l_po_num );
12066 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
12067 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
12068 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
12069
12070 END IF; -- <Bug 9342280 : Added for CLM project>
12071
12072 rcv_error_pkg.log_interface_error('QUANTITY',FALSE);
12073 END IF;--} x_cascaded_table(n).quantity > (l_distribution_qty - l_total_deliver_quantity)
12074 --} l_parent_receive_txn_in_rt = 'Y'
12075 ELSIF l_parent_receive_txn_in_rt = 'N' THEN--{ l_parent_receive_txn_in_rt = 'N'
12076 --Fetch the AVAILABLE qty from rcv_transactions_interface using l_parent_interface_txn_id
12077 IF (g_asn_debug = 'Y') THEN
12078 asn_debug.put_line('Fetching AVAILABLE qty from fetched RECEIVE interface_txn_id....');
12079 END IF;
12080
12081 --Fetch sum of quantity of all preprocessed 'RECEIVE' txns loaded in RTI for that group_id
12082 --and po_line_location_id, to get total_receive_qty for that po_line_location_id
12083 --( by this filter interface_transaction_id < x_po_transferrec.interface_transaction_id,
12084 -- only fetching preprocessed RECEIVE txn)
12085 --x_po_transferrec.interface_transaction_id is holding 'DELIVER' txn id
12086 IF (g_asn_debug = 'Y') THEN
12087 asn_debug.put_line('Fetching sum of received qty for preprocessed RECEIVE txns....');
12088 END IF;
12089
12090 BEGIN --{
12091 SELECT nvl(sum(quantity),0)
12092 INTO l_total_receiving_quantity
12093 FROM rcv_transactions_interface
12094 WHERE (transaction_status_code = 'PENDING'
12095 AND processing_status_code <> 'ERROR')
12096 AND transaction_type = 'RECEIVE'
12097 AND auto_transact_code <> 'DELIVER'
12098 AND group_id = x_cascaded_table(n).group_id
12099 AND po_line_location_id = x_po_transferrec.po_line_location_id
12100 AND interface_transaction_id < x_cascaded_table(n).interface_transaction_id;
12101 EXCEPTION
12102 WHEN NO_DATA_FOUND then
12103 IF (g_asn_debug = 'Y') THEN
12104 asn_debug.put_line('No data found exception while fetching sum of received qty..');
12105 END IF;
12106 l_total_receiving_quantity := 0;
12107 END;--} Begin ends
12108
12109 IF (g_asn_debug = 'Y') THEN
12110 asn_debug.put_line('Sum of received qty for preprocessed RECEIVE txns..'||l_total_receiving_quantity);
12111 asn_debug.put_line('Fetching sum of Delivered qty for preprocessed DELIVER txns, excluding current deliver txn...');
12112 END IF;
12113
12114 --Fetch sum of quantity of only pre processed 'DELIVER' txns in RTI for that group_id
12115 --and po_line_location_id, to get total_deliver_qty for that po_distribution_id
12116 --( by this filter interface_transaction_id < x_po_transferrec.interface_transaction_id,
12117 -- only fetching preprocessed deliver txn)
12118
12119 BEGIN
12120 SELECT nvl(sum(quantity),0)
12121 INTO l_total_deliver_quantity
12122 FROM rcv_transactions_interface
12123 WHERE (transaction_status_code = 'PENDING'
12124 AND processing_status_code <> 'ERROR')
12125 AND transaction_type = 'DELIVER'
12126 AND group_id = x_cascaded_table(n).group_id
12127 AND po_line_location_id = x_po_transferrec.po_line_location_id
12128 AND interface_transaction_id < x_cascaded_table(n).interface_transaction_id;
12129 EXCEPTION
12130 WHEN NO_DATA_FOUND then
12131 IF (g_asn_debug = 'Y') THEN
12132 asn_debug.put_line('No data found exception while fetching sum of delivered qty..');
12133 END IF;
12134 l_total_deliver_quantity := 0;
12135 END;
12136
12137 IF (g_asn_debug = 'Y') THEN
12138 asn_debug.put_line('Sum of delivered qty for preprocessed DELIVERED txns..'||l_total_deliver_quantity);
12139 asn_debug.put_line('Fetching receive qty for RECEIVE txn...');
12140 END IF;
12141
12142 --Fetch the receive quantity for the 'RECEIVE'txn of the current DELIVER txn
12143 SELECT quantity
12144 INTO l_receive_quantity
12145 FROM rcv_transactions_interface
12146 WHERE interface_transaction_id = l_parent_interface_txn_id;
12147
12148 IF (g_asn_debug = 'Y') THEN
12149 asn_debug.put_line('Receive qty for RECEIVE txn...'||l_receive_quantity);
12150 asn_debug.put_line('Fetching deliver qty for DELIVER txn...');
12151 END IF;
12152 --Fetch the deliver quantity for the current 'DELIVER'txn
12153 SELECT quantity
12154 INTO l_deliver_quantity
12155 FROM rcv_transactions_interface
12156 WHERE interface_transaction_id = x_cascaded_table(n).interface_transaction_id;
12157
12158 IF (g_asn_debug = 'Y') THEN
12159 asn_debug.put_line('Deliver qty for DELIVER txn...'||l_deliver_quantity);
12160 END IF;
12161
12162 IF (l_total_deliver_quantity + l_deliver_quantity) <= l_total_receiving_quantity THEN --{ (l_total_deliver_quantity + l_deliver_quantity) <= l_total_receiving_quantity
12163 --Not over delivery txn
12164 --Check whether Receive txn line_location-id and deliver_txn line_location_id are same
12165 --and validate delivery qty is within the received qty
12166 IF (g_asn_debug = 'Y') THEN
12167 asn_debug.put_line('Not Over Delivery txn...');
12168 END IF;
12169 IF l_deliver_quantity <= l_receive_quantity THEN
12170 --Allow this deliver transaction
12171 IF (g_asn_debug = 'Y') THEN
12172 asn_debug.put_line('Delivery qty <= received qty...');
12173 END IF;
12174 l_distribution_qty := l_receive_quantity;
12175 ELSE
12176 --Over delivery for that Receive txn on the spefied distribution, error out this deliver txn
12177 IF (g_asn_debug = 'Y') THEN
12178 asn_debug.put_line('deliver qty > received qty.');
12179 END IF;
12180 x_cascaded_table(n).error_status := 'E';
12181
12182 -- <Bug 9342280 : Added for CLM project>
12183
12184 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
12185
12186 IF l_po_rel_num = -1 THEN
12187
12188 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEEDS_FUNDED',x_cascaded_table(n).error_message);
12189 ELSE
12190 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEED_FUNDED',x_cascaded_table(n).error_message);
12191 rcv_error_pkg.set_token('RELNUM', l_po_rel_num);
12192 END IF;
12193
12194 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
12195 rcv_error_pkg.set_token('AVLQTY', l_receive_quantity);
12196 rcv_error_pkg.set_token('PONUM', l_po_num);
12197 rcv_error_pkg.set_token('LINENUM', l_po_line_num);
12198 rcv_error_pkg.set_token('SHIPNUM', l_po_line_loc_num);
12199 rcv_error_pkg.set_token('DISTNUM', l_po_dist_num);
12200
12201 ELSE
12202 -- <CLM END>
12203
12204 IF l_po_rel_num = -1 THEN--Bug 5439085
12205 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
12206 ELSE
12207 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
12208 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
12209 END IF;
12210 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
12211 rcv_error_pkg.set_token('AVLQTY',l_receive_quantity);
12212 rcv_error_pkg.set_token('PONUM', l_po_num );
12213 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
12214 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
12215 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
12216
12217 END IF; -- <Bug 9342280 : Added for CLM project>
12218
12219 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
12220 END IF;
12221 ELSE
12222 --Over delivery for that Receive txn on the spefied distribution, error out this deliver txn
12223 IF (g_asn_debug = 'Y') THEN
12224 asn_debug.put_line('Trying to perform over Delivery txn, on the specified distribution...Error out this Deliver txn..');
12225 END IF;
12226 x_cascaded_table(n).error_status := 'E';
12227
12228 -- <Bug 9342280 : Added for CLM project>
12229 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
12230
12231 IF l_po_rel_num = -1 THEN
12232
12233 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEEDS_FUNDED',x_cascaded_table(n).error_message);
12234 ELSE
12235 rcv_error_pkg.set_error_message('RCV_ROI_TRX_QTY_EXCEED_FUNDED',x_cascaded_table(n).error_message);
12236 rcv_error_pkg.set_token('RELNUM', l_po_rel_num);
12237 END IF;
12238
12239 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
12240 rcv_error_pkg.set_token('AVLQTY',l_total_receiving_quantity);
12241 rcv_error_pkg.set_token('PONUM', l_po_num);
12242 rcv_error_pkg.set_token('LINENUM', l_po_line_num);
12243 rcv_error_pkg.set_token('SHIPNUM', l_po_line_loc_num);
12244 rcv_error_pkg.set_token('DISTNUM', l_po_dist_num);
12245
12246 ELSE
12247 -- <CLM END>
12248
12249 IF l_po_rel_num = -1 THEN--Bug 5439085
12250 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
12251 ELSE
12252 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
12253 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
12254 END IF;
12255 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
12256 rcv_error_pkg.set_token('AVLQTY',l_total_receiving_quantity);
12257 rcv_error_pkg.set_token('PONUM', l_po_num );
12258 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
12259 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
12260 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
12261
12262 END IF; -- <Bug 9342280 : Added for CLM project>
12263
12264 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
12265 END IF;--} (l_total_deliver_quantity + l_deliver_quantity) <= l_total_receiving_quantity
12266 --} l_parent_receive_txn_in_rt = 'N'
12267 END IF;--} l_parent_receive_txn_in_rt = 'Y'
12268 --} l_loop_exit_status = 'S'
12269 END IF; --} l_loop_exit_status = 'E
12270 --}l_po_deliver_rti_cursor_opened = 1
12271 ELSE--{ l_po_deliver_rti_cursor_opened != 1
12272
12273 -- <Bug 9342280 : Added for CLM project>
12274 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
12275
12276 select ms.quantity, ms.unit_of_measure
12277 into l_distribution_qty, l_ship_unit
12278 from mtl_supply ms
12279 where ms.supply_source_id = x_po_transferrec.rcv_transaction_id
12280 and ms.po_distribution_id = x_po_transferrec.po_distribution_id
12281 and ms.supply_type_code = 'RECEIVING';
12282
12283 ELSE
12284 --<END CLM>
12285
12286 -- Bug 7675516: Picking l_ship_unit from MS instead of PLL.
12287 --Bug 9072630 The query on mtl_supply should be based on line_location_id as for a
12288 --Multi distributed PO user can deliver qty. for any of the distribution attached to it.
12289 SELECT nvl(sum(ms.quantity),0),
12290 ms.unit_of_measure
12291 INTO l_distribution_qty,
12292 l_ship_unit
12293 FROM mtl_supply ms
12294 WHERE ms.supply_source_id = x_po_transferrec.rcv_transaction_id
12295 AND ms.po_line_location_id = x_po_transferrec.po_line_location_id
12296 AND ms.supply_type_code = 'RECEIVING'
12297 GROUP BY ms.unit_of_measure;
12298 -- End Bug 7675516
12299 --Bug 9072630 The qty. returned by mtl_supply should be used of considering the already
12300 --processed qty. in rti.
12301 l_total_deliver_quantity:=0;
12302 FOR rtirec in rti_processed(x_cascaded_table(n).group_id,
12303 x_po_transferrec.po_line_location_id,
12304 x_po_transferrec.rcv_transaction_id,
12305 x_cascaded_table(n).interface_transaction_id) LOOP
12306 l_deliver_quantity:=rtirec.quantity;
12307 l_unit_of_measure:=rtirec.unit_of_measure;
12308 asn_debug.put_line('Quantity in RTI Processed before uom conversion is = '||l_deliver_quantity
12309 ||' in uom = '||l_unit_of_measure);
12310 if(l_ship_unit<>l_unit_of_measure) then
12311 l_deliver_quantity := convert_into_correct_qty(l_deliver_quantity,
12312 l_unit_of_measure,
12313 temp_cascaded_table(current_n).item_id,
12314 l_ship_unit
12315 );
12316 asn_debug.put_line('Quantity in RTI Processed after uom conversion is = '||l_deliver_quantity
12317 ||' in uom = '||l_ship_unit);
12318 end if;
12319 l_total_deliver_quantity:=l_total_deliver_quantity+l_deliver_quantity;
12320 asn_debug.put_line('Total Quantity in RTI is = '||l_total_deliver_quantity
12321 ||' in uom = '||l_ship_unit);
12322 END LOOP;
12323 asn_debug.put_line('Total quantity in RTI Processed is = '||l_total_deliver_quantity
12324 ||' in uom = '||l_ship_unit);
12325 l_distribution_qty:=l_distribution_qty-l_total_deliver_quantity;
12326
12327 END IF; -- <Bug 9342280 : Added for CLM project>
12328
12329 --} l_po_deliver_rti_cursor_opened != 1
12330 END IF; ----}l_po_deliver_rti_cursor_opened = 1
12331
12332 -- Bug 7675516
12333 IF (g_asn_debug = 'Y') THEN
12334 asn_debug.put_line('l_distribution_qty = ' || l_distribution_qty);
12335 asn_debug.put_line('l_ship_unit = ' || l_ship_unit);
12336 asn_debug.put_line('temp_cascaded_table(current_n).item_id = ' || temp_cascaded_table(current_n).item_id);
12337 asn_debug.put_line('x_po_transferrec.unit_of_meas = ' || x_po_transferrec.unit_of_meas);
12338 asn_debug.put_line('temp_cascaded_table(current_n).quantity = ' || temp_cascaded_table(current_n).quantity);
12339 asn_debug.put_line('temp_cascaded_table(current_n).unit_of_measure = ' || temp_cascaded_table(current_n).unit_of_measure);
12340 END IF;
12341 -- End Bug 7675516
12342 -- } bugfix 5354379
12343
12344 /* Convert ordered_qty in po_distributions to
12345 * the parent's uom */
12346 l_converted_distribution_qty := convert_into_correct_qty(l_distribution_qty,
12347 l_ship_unit,
12348 temp_cascaded_table(current_n).item_id,
12349 x_po_transferrec.unit_of_meas
12350 ); -- in parents uom
12351 /* Convert transaction_uom in rti to the parent's uom */
12352 l_converted_transaction_qty := convert_into_correct_qty(temp_cascaded_table(current_n).quantity,
12353 temp_cascaded_table(current_n).unit_of_measure,
12354 temp_cascaded_table(current_n).item_id,
12355 x_po_transferrec.unit_of_meas
12356 ); -- in parents uom
12357
12358 IF (g_asn_debug = 'Y') THEN
12359 asn_debug.put_line('l_total_rec_quantity ' || l_total_rec_quantity);
12360 asn_debug.put_line('l_converted_transaction_qty ' || l_converted_transaction_qty);
12361 asn_debug.put_line('l_converted_distribution_qty ' || l_converted_distribution_qty);
12362 END IF;
12363
12364 IF ( (l_converted_transaction_qty <= l_total_rec_quantity)
12365 AND (l_converted_transaction_qty <= l_converted_distribution_qty)) THEN
12366 x_converted_parent_trx_qty := l_total_rec_quantity;
12367 ELSE
12368 x_converted_parent_trx_qty := 0;
12369 END IF;
12370
12371 IF (g_asn_debug = 'Y') THEN
12372 asn_debug.put_line('Available qty for standard multiple distributions deliver ' || x_converted_parent_trx_qty);
12373 asn_debug.put_line('l_converted_distribution_qty ' || l_converted_distribution_qty);
12374 asn_debug.put_line('l_converted_transaction_qty ' || l_converted_transaction_qty);
12375 END IF;
12376 END IF; --}
12377
12378 IF ( (x_converted_parent_trx_qty = 0)
12379 AND ( (temp_cascaded_table(1).transaction_type <> 'DELIVER')
12380 OR ( temp_cascaded_table(1).transaction_type = 'DELIVER'
12381 AND l_num_of_distributions = 1))) THEN --{
12382 IF (g_asn_debug = 'Y') THEN
12383 asn_debug.put_line('calling transfer get_available_qty ');
12384 END IF;
12385
12386 rcv_quantities_s.get_available_quantity('TRANSFER',
12387 x_po_transferrec.rcv_transaction_id,
12388 'VENDOR',
12389 NULL,
12390 x_po_transferrec.rcv_transaction_id,
12391 NULL,
12392 x_converted_parent_trx_qty,
12393 x_tolerable_qty,
12394 x_po_transferrec.unit_of_meas,
12395 /*Bug# 1548597 */
12396 x_secondary_available_qty
12397 );
12398 END IF; --}
12399
12400 IF (g_asn_debug = 'Y') THEN
12401 asn_debug.put_line('qty from GET_AVAILABLE_QUANTITY for transfer is ' || x_converted_parent_trx_qty);
12402 END IF;
12403
12404 x_remaining_qty_parent_uom := convert_into_correct_qty(x_remaining_quantity,
12405 temp_cascaded_table(1).unit_of_measure,
12406 temp_cascaded_table(1).item_id,
12407 x_po_transferrec.unit_of_meas
12408 );
12409
12410 IF (x_remaining_qty_parent_uom = 0) THEN
12411 IF (g_asn_debug = 'Y') THEN
12412 asn_debug.put_line(' Transfer Need an error message in the interface tables');
12413 END IF;
12414 ELSE
12415 /* Converted qty successfully and we have some quantity on which we can act */
12416 IF (g_asn_debug = 'Y') THEN
12417 asn_debug.put_line('Converted trx qty that is available ' || x_converted_parent_trx_qty);
12418 asn_debug.put_line('Remaining qty in parents uom that is available ' || x_remaining_qty_parent_uom);
12419 END IF;
12420
12421 IF (x_converted_parent_trx_qty > 0) THEN --{
12422 --Bug 8631613 Rounding the remaining qty to 14 decimals.
12423 IF (x_converted_parent_trx_qty < Round(x_remaining_qty_parent_uom,7)) THEN --{
12424 /* Total quantity available to transfer is less than the qty
12425 * that the user wants to transfer. Hence we would error out but
12426 * to keep the old code we will get the remaining code here and
12427 * error out later.
12428 */
12429 x_remaining_qty_parent_uom := x_remaining_qty_parent_uom - x_converted_parent_trx_qty;
12430
12431 IF (temp_cascaded_table(current_n).unit_of_measure <> x_po_transferrec.unit_of_meas) THEN
12432 x_remaining_quantity := convert_into_correct_qty(x_remaining_qty_parent_uom,
12433 x_po_transferrec.unit_of_meas,
12434 temp_cascaded_table(1).item_id,
12435 temp_cascaded_table(1).unit_of_measure
12436 );
12437 ELSE
12438 x_remaining_quantity := x_remaining_qty_parent_uom;
12439 END IF;
12440
12441 insert_into_table := TRUE;
12442 ELSE --}{
12443 IF (g_asn_debug = 'Y') THEN
12444 asn_debug.put_line('We are in >= Qty branch ');
12445 END IF;
12446
12447 x_converted_parent_trx_qty := x_remaining_qty_parent_uom;
12448 insert_into_table := TRUE;
12449 x_remaining_qty_parent_uom := 0;
12450 x_remaining_quantity := 0;
12451 END IF; --} /* if (x_converted_parent_trx_qty < x_remaining_qty_parent_uom) then */
12452 ELSE /* x_converted_parent_trx_qty >0 */ --}{
12453 IF rows_fetched = x_record_count THEN -- { last row needs to be inserted anyway
12454 -- so that the row can be used based on qty tolerance
12455 -- checks
12456 IF (g_asn_debug = 'Y') THEN
12457 asn_debug.put_line('Quantity is less then 0 but last record');
12458 END IF;
12459
12460 insert_into_table := TRUE;
12461 x_converted_trx_qty := 0;
12462 ELSE --}{
12463 IF (g_asn_debug = 'Y') THEN
12464 asn_debug.put_line('<= 0 Quantity but more records in cursor');
12465 END IF;
12466
12467 x_remaining_qty_po_uom := 0; -- we may have a diff uom on the next iteration
12468
12469 IF (g_asn_debug = 'Y') THEN
12470 asn_debug.put_line('We have to deal with remaining_qty > 0 and x_converted_trx_qty -ve');
12471 END IF;
12472
12473 insert_into_table := FALSE;
12474 END IF; --}
12475 END IF; /*x_converted_parent_trx_qty >0 */ --}
12476 END IF;
12477
12478 /* Converted qty successfully and we have some quantity on which we can act */
12479 IF (g_asn_debug = 'Y') THEN
12480 asn_debug.put_line('Transaction qty in terms of the parents uom is ' || x_converted_parent_trx_qty);
12481 END IF;
12482
12483 IF insert_into_table THEN --{ --start
12484 IF (x_first_trans) THEN --{
12485 IF (g_asn_debug = 'Y') THEN
12486 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
12487 END IF;
12488
12489 x_first_trans := FALSE;
12490 ELSE --}{
12491 IF (g_asn_debug = 'Y') THEN
12492 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
12493 END IF;
12494
12495 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
12496 END IF; --}
12497
12498 temp_cascaded_table(current_n).po_header_id := x_po_transferrec.po_head_id;
12499 temp_cascaded_table(current_n).po_line_id := x_po_transferrec.line_id;
12500 temp_cascaded_table(current_n).po_line_location_id := x_po_transferrec.po_line_location_id;
12501 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_transferrec.primary_unit_of_measure;
12502
12503 IF (temp_cascaded_table(current_n).unit_of_measure <> x_po_transferrec.unit_of_meas) THEN
12504 --Bug 8631613 For some conversions residual qty. is causing issues while doing put away.
12505 l_temp_qty := convert_into_correct_qty(x_converted_parent_trx_qty,
12506 x_po_transferrec.unit_of_meas,
12507 temp_cascaded_table(current_n).item_id,
12508 temp_cascaded_table(current_n).unit_of_measure
12509 );
12510 IF ( Round(l_temp_qty,7) <> temp_cascaded_table(current_n).quantity ) THEN
12511 temp_cascaded_table(current_n).quantity := l_temp_qty;
12512 END IF;
12513 /*temp_cascaded_table(current_n).quantity := convert_into_correct_qty(x_converted_parent_trx_qty,
12514 x_po_transferrec.unit_of_meas,
12515 temp_cascaded_table(current_n).item_id,
12516 temp_cascaded_table(current_n).unit_of_measure
12517 ); -- in asn uom*/
12518 --Bug 8631613
12519
12520 IF (g_asn_debug = 'Y') THEN
12521 asn_debug.put_line('Transaction qty in terms of the transaction uom is ' || temp_cascaded_table(current_n).quantity);
12522 END IF;
12523 ELSE
12524 temp_cascaded_table(current_n).quantity := x_converted_parent_trx_qty;
12525 END IF;
12526
12527 IF (temp_cascaded_table(current_n).primary_unit_of_measure <> x_po_transferrec.unit_of_meas) THEN
12528 --Bug 8631613
12529 l_pri_temp_qty := convert_into_correct_qty(x_converted_parent_trx_qty,
12530 x_po_transferrec.unit_of_meas,
12531 temp_cascaded_table(current_n).item_id,
12532 temp_cascaded_table(current_n).primary_unit_of_measure
12533 );
12534 IF (Round(l_pri_temp_qty,7) <> NVL(temp_cascaded_table(current_n).primary_quantity,-1)) THEN
12535 temp_cascaded_table(current_n).primary_quantity := l_pri_temp_qty;
12536 END IF;
12537 /*
12538 temp_cascaded_table(current_n).primary_quantity := convert_into_correct_qty(x_converted_parent_trx_qty,
12539 x_po_transferrec.unit_of_meas,
12540 temp_cascaded_table(current_n).item_id,
12541 temp_cascaded_table(current_n).primary_unit_of_measure
12542 ); */
12543 --Bug 8631613 );
12544 ELSE
12545 temp_cascaded_table(current_n).primary_quantity := x_converted_parent_trx_qty;
12546 END IF;
12547
12548 IF (g_asn_debug = 'Y') THEN
12549 asn_debug.put_line('Transaction qty in terms of the primary uom is ' || temp_cascaded_table(current_n).primary_quantity);
12550 END IF;
12551
12552 IF (NVL(x_cascaded_table(n).transaction_type, 'RECEIVE') = 'DELIVER') THEN --{
12553 temp_cascaded_table(current_n).po_distribution_id := x_po_transferrec.po_distribution_id;
12554 temp_cascaded_table(current_n).charge_account_id := x_po_transferrec.code_combination_id;
12555 temp_cascaded_table(current_n).req_distribution_id := x_po_transferrec.req_distribution_id;
12556 -- temp_cascaded_table(current_n).currency_conversion_date := x_po_transferrec.rate_date;
12557 -- temp_cascaded_table(current_n).currency_conversion_rate := x_po_transferrec.rate;
12558 temp_cascaded_table(current_n).destination_type_code := x_po_transferrec.destination_type_code;
12559 temp_cascaded_table(current_n).destination_context := x_po_transferrec.destination_type_code;
12560
12561 IF (g_asn_debug = 'Y') THEN
12562 asn_debug.put_line(' po_dist ' || temp_cascaded_table(current_n).po_distribution_id);
12563 END IF;
12564
12565 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
12566 temp_cascaded_table(current_n).deliver_to_location_id := x_po_transferrec.deliver_to_location_id;
12567 END IF;
12568
12569 IF (g_asn_debug = 'Y') THEN
12570 asn_debug.put_line(' deliver_to_person_id ' || temp_cascaded_table(current_n).deliver_to_person_id);
12571 END IF;
12572
12573 /* Bug 2392074 - If the deliver_to_person mentioned in the po_distributions is
12574 invalid or inactive at the time of Receipt we need to clear the deliver to person,
12575 as this is an optional field. */
12576 IF (NVL(temp_cascaded_table(current_n).deliver_to_person_id, 0) = 0) THEN --{
12577 temp_cascaded_table(current_n).deliver_to_person_id := x_po_transferrec.deliver_to_person_id;
12578
12579 IF (temp_cascaded_table(current_n).deliver_to_person_id IS NOT NULL) THEN --{
12580 BEGIN
12581 SELECT NVL(MAX(hre.full_name), 'notfound')
12582 INTO x_full_name
12583 FROM hr_employees_current_v hre
12584 WHERE ( hre.inactive_date IS NULL
12585 OR hre.inactive_date > SYSDATE)
12586 AND hre.employee_id = temp_cascaded_table(current_n).deliver_to_person_id;
12587
12588 IF (x_full_name = 'notfound') THEN
12589 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
12590 END IF;
12591 EXCEPTION
12592 WHEN NO_DATA_FOUND THEN
12593 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
12594
12595 IF (g_asn_debug = 'Y') THEN
12596 asn_debug.put_line('The deliver to person entered in PO is currently inactive');
12597 asn_debug.put_line(' So it is cleared off');
12598 END IF;
12599 WHEN OTHERS THEN
12600 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
12601
12602 IF (g_asn_debug = 'Y') THEN
12603 asn_debug.put_line('Some exception has occured');
12604 asn_debug.put_line('This exception is due to the PO deliver to person');
12605 asn_debug.put_line('The deliver to person is optional');
12606 asn_debug.put_line('So cleared off the deliver to person');
12607 END IF;
12608 END;
12609 END IF; --}
12610 END IF; --}
12611
12612 IF (g_asn_debug = 'Y') THEN
12613 asn_debug.put_line(' subinventory ' || temp_cascaded_table(current_n).subinventory);
12614 END IF;
12615
12616 IF (temp_cascaded_table(current_n).subinventory IS NULL) THEN
12617 temp_cascaded_table(current_n).subinventory := x_po_transferrec.destination_subinventory;
12618 END IF;
12619
12620 IF (g_asn_debug = 'Y') THEN
12621 asn_debug.put_line(' wip_entity_id ' || temp_cascaded_table(current_n).wip_entity_id);
12622 END IF;
12623
12624 temp_cascaded_table(current_n).wip_entity_id := x_po_transferrec.wip_entity_id;
12625 temp_cascaded_table(current_n).wip_operation_seq_num := x_po_transferrec.wip_operation_seq_num;
12626 temp_cascaded_table(current_n).wip_resource_seq_num := x_po_transferrec.wip_resource_seq_num;
12627 temp_cascaded_table(current_n).wip_repetitive_schedule_id := x_po_transferrec.wip_repetitive_schedule_id;
12628 temp_cascaded_table(current_n).wip_line_id := x_po_transferrec.wip_line_id;
12629 temp_cascaded_table(current_n).bom_resource_id := x_po_transferrec.bom_resource_id;
12630
12631 IF (g_asn_debug = 'Y') THEN
12632 asn_debug.put_line(' ussgl_transaction_code ' || temp_cascaded_table(current_n).ussgl_transaction_code);
12633 END IF;
12634
12635 -- bug 1361786
12636 IF (temp_cascaded_table(current_n).ussgl_transaction_code IS NULL) THEN
12637 temp_cascaded_table(current_n).ussgl_transaction_code := x_po_transferrec.ussgl_transaction_code;
12638 END IF;
12639 END IF; --}
12640
12641 current_n := current_n + 1;
12642
12643 IF (g_asn_debug = 'Y') THEN
12644 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
12645 END IF;
12646 END IF; --}
12647 /* Get the available qty in PRIMARY UOM */
12648 /*
12649 PO_UOM_S.UOM_CONVERT (x_converted_trx_qty,
12650 l_uom,
12651 x_item_id,
12652 x_primary_uom,
12653 l_primary_available_qty );
12654 */
12655 END LOOP; --}
12656 ELSE --} {
12657 -- error_status and error_message are set after validate_quantity_shipped
12658 IF (g_asn_debug = 'Y') THEN
12659 asn_debug.put_line('No parent_transaction_id or parent_interface_transaction_id ');
12660 END IF;
12661
12662 IF (g_asn_debug = 'Y') THEN
12663 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
12664 END IF;
12665
12666 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
12667 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12668
12669 IF (x_cascaded_table(n).error_message IS NULL) THEN
12670 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION', x_cascaded_table(n).error_message);
12671 END IF;
12672
12673 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12674 END IF; --}
12675 END IF; -- } of (asn quantity_shipped was valid)
12676
12677 IF (g_asn_debug = 'Y') THEN
12678 asn_debug.put_line('before closing cursors current_n is ' || temp_cascaded_table.COUNT);
12679 END IF;
12680
12681 IF po_transfer%ISOPEN THEN
12682 CLOSE po_transfer;
12683 END IF;
12684
12685 IF po_transfer_rti%ISOPEN THEN
12686 CLOSE po_transfer_rti;
12687 END IF;
12688
12689 IF po_single_deliver%ISOPEN THEN
12690 CLOSE po_single_deliver;
12691 END IF;
12692
12693 IF po_single_deliver_rti%ISOPEN THEN
12694 CLOSE po_single_deliver_rti;
12695 END IF;
12696
12697 IF po_deliver%ISOPEN THEN
12698 CLOSE po_deliver;
12699 END IF;
12700
12701 IF (g_asn_debug = 'Y') THEN
12702 asn_debug.put_line('Exit explode_line_quantity');
12703 END IF;
12704 EXCEPTION
12705 WHEN OTHERS THEN
12706 IF (g_asn_debug = 'Y') THEN
12707 asn_debug.put_line('Exception in derive_trans_del_quantity ');
12708 END IF;
12709
12710 IF po_transfer%ISOPEN THEN
12711 CLOSE po_transfer;
12712 END IF;
12713
12714 IF po_transfer_rti%ISOPEN THEN
12715 CLOSE po_transfer_rti;
12716 END IF;
12717
12718 IF po_single_deliver%ISOPEN THEN
12719 CLOSE po_single_deliver;
12720 END IF;
12721
12722 IF po_single_deliver_rti%ISOPEN THEN
12723 CLOSE po_single_deliver_rti;
12724 END IF;
12725
12726 IF po_deliver%ISOPEN THEN
12727 CLOSE po_deliver;
12728 END IF;
12729
12730 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
12731 rcv_error_pkg.set_sql_error_message('derive_trans_del_line_quantity', x_progress);
12732 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
12733 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
12734
12735 IF (g_asn_debug = 'Y') THEN
12736 asn_debug.put_line(TO_CHAR(n));
12737 asn_debug.put_line(SQLERRM);
12738 asn_debug.put_line('error ' || x_progress);
12739 END IF;
12740 END derive_trans_del_line_quantity;
12741
12742 /*
12743 * Default information from parent transaction for transfer and deliver
12744 * This procedure was originally written for vendor source transactions
12745 * but since the code is the same for RMAs, the cursor has been expanded
12746 * to include RMA information as well and the procedure reused for RMAs.
12747 */
12748 PROCEDURE default_vendor_trans_del(
12749 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
12750 n IN BINARY_INTEGER
12751 ) IS
12752 p_trx_record rcv_roi_header_common.common_default_record_type;
12753
12754 CURSOR po_transfer(
12755 v_parent_trx_id NUMBER
12756 ) IS
12757 SELECT rt.po_revision_num,
12758 rsl.item_description,
12759 rsup.po_release_id,
12760 rt.location_id loc_id,
12761 rt.organization_id,
12762 rt.inspection_status_code,
12763 rt.routing_header_id,
12764 rt.currency_code,
12765 rt.currency_conversion_rate,
12766 rt.currency_conversion_type,
12767 rt.currency_conversion_date,
12768 rt.location_id,
12769 rsup.shipment_header_id,
12770 rsup.shipment_line_id,
12771 rsl.category_id,
12772 rt.vendor_id,
12773 rt.vendor_site_id,
12774 rt.po_unit_price,
12775 rt.movement_id,
12776 rt.deliver_to_person_id,
12777 rt.deliver_to_location_id,
12778 rt.subinventory,
12779 rt.transfer_lpn_id,
12780 rt.oe_order_header_id,
12781 rt.oe_order_line_id,
12782 rt.customer_id,
12783 rt.customer_site_id,
12784 rt.source_document_code
12785 FROM rcv_transactions rt,
12786 rcv_shipment_lines rsl,
12787 rcv_supply rsup
12788 WHERE rt.transaction_id = v_parent_trx_id
12789 AND rt.transaction_id = rsup.rcv_transaction_id
12790 AND rsup.supply_type_code = 'RECEIVING'
12791 AND rsl.shipment_line_id = rsup.shipment_line_id
12792 AND rt.transaction_id = rsup.rcv_transaction_id
12793 AND rt.transaction_type <> 'UNORDERED';
12794
12795 CURSOR po_transfer_rti(
12796 v_parent_inter_trx_id NUMBER
12797 ) IS
12798 SELECT rti.po_revision_num,
12799 rti.item_description,
12800 rti.po_release_id,
12801 rti.location_id loc_id,
12802 rti.to_organization_id organization_id,
12803 rti.inspection_status_code,
12804 rti.routing_header_id,
12805 rti.currency_code,
12806 rti.currency_conversion_rate,
12807 rti.currency_conversion_type,
12808 rti.currency_conversion_date,
12809 rti.location_id,
12810 rti.shipment_header_id,
12811 rti.shipment_line_id,
12812 rti.category_id,
12813 rti.vendor_id,
12814 rti.vendor_site_id,
12815 rti.po_unit_price,
12816 rti.movement_id,
12817 rti.deliver_to_person_id,
12818 rti.deliver_to_location_id,
12819 rti.subinventory,
12820 rti.transfer_lpn_id,
12821 rti.oe_order_header_id,
12822 rti.oe_order_line_id,
12823 rti.customer_id,
12824 rti.customer_site_id,
12825 rti.source_document_code
12826 FROM rcv_transactions_interface rti
12827 WHERE interface_transaction_id = v_parent_inter_trx_id;
12828
12829 default_po_transfer_info po_transfer%ROWTYPE;
12830 x_progress VARCHAR2(3);
12831 x_locator_control NUMBER;
12832 x_default_subinventory VARCHAR2(10);
12833 x_default_locator_id NUMBER;
12834 x_success BOOLEAN;
12835 x_tax_name VARCHAR2(50); -- Bug 6331613
12836 x_vendor_site_id NUMBER;
12837 x_vendor_site_code VARCHAR2(20);
12838 /* default variables */
12839 l_project_id NUMBER;
12840 l_task_id NUMBER;
12841 l_locator_id NUMBER;
12842 temp_index NUMBER;
12843 /* pjiang debug */
12844 err_num NUMBER;
12845 err_msg VARCHAR2(100);
12846 BEGIN
12847 -- default the fields that are covered in the common defaulting logic
12848 p_trx_record.destination_type_code := x_cascaded_table(n).destination_type_code;
12849 p_trx_record.transaction_type := x_cascaded_table(n).transaction_type;
12850 p_trx_record.processing_mode_code := x_cascaded_table(n).processing_mode_code;
12851 p_trx_record.processing_status_code := x_cascaded_table(n).processing_status_code;
12852 p_trx_record.transaction_status_code := x_cascaded_table(n).transaction_status_code;
12853 p_trx_record.auto_transact_code := x_cascaded_table(n).auto_transact_code;
12854 rcv_roi_header_common.commondefaultcode(p_trx_record);
12855 x_cascaded_table(n).destination_type_code := p_trx_record.destination_type_code;
12856 x_cascaded_table(n).transaction_type := p_trx_record.transaction_type;
12857 x_cascaded_table(n).processing_mode_code := p_trx_record.processing_mode_code;
12858 x_cascaded_table(n).processing_status_code := p_trx_record.processing_status_code;
12859 x_cascaded_table(n).transaction_status_code := p_trx_record.transaction_status_code;
12860 x_cascaded_table(n).auto_transact_code := p_trx_record.auto_transact_code;
12861
12862 IF (g_asn_debug = 'Y') THEN
12863 asn_debug.put_line('Enter Default');
12864 END IF;
12865
12866 IF x_cascaded_table(n).source_document_code IS NULL THEN
12867 IF x_cascaded_table(n).receipt_source_code = 'CUSTOMER' THEN
12868 x_cascaded_table(n).source_document_code := 'RMA';
12869 ELSE
12870 x_cascaded_table(n).source_document_code := 'PO';
12871 END IF;
12872
12873 IF (g_asn_debug = 'Y') THEN
12874 asn_debug.put_line('Defaulting SOURCE_DOCUMENT_CODE ' || x_cascaded_table(n).source_document_code);
12875 END IF;
12876 END IF;
12877
12878 IF (x_cascaded_table(n).derive = 'Y') THEN --{
12879 IF (x_cascaded_table(n).derive_index <> 0) THEN --{
12880 NULL;
12881 /* Get the values from pl/sql table */
12882 temp_index := x_cascaded_table(n).derive_index;
12883 x_cascaded_table(n).po_revision_num := x_cascaded_table(temp_index).po_revision_num;
12884 x_cascaded_table(n).item_description := x_cascaded_table(temp_index).item_description;
12885 x_cascaded_table(n).po_release_id := x_cascaded_table(temp_index).po_release_id;
12886 x_cascaded_table(n).to_organization_id := x_cascaded_table(temp_index).to_organization_id;
12887 x_cascaded_table(n).inspection_status_code := x_cascaded_table(temp_index).inspection_status_code;
12888 x_cascaded_table(n).routing_header_id := x_cascaded_table(temp_index).routing_header_id;
12889 x_cascaded_table(n).currency_code := x_cascaded_table(temp_index).currency_code;
12890 x_cascaded_table(n).currency_conversion_rate := x_cascaded_table(temp_index).currency_conversion_rate;
12891 x_cascaded_table(n).currency_conversion_type := x_cascaded_table(temp_index).currency_conversion_type;
12892 x_cascaded_table(n).currency_conversion_date := x_cascaded_table(temp_index).currency_conversion_date;
12893 x_cascaded_table(n).shipment_header_id := x_cascaded_table(temp_index).shipment_header_id;
12894 x_cascaded_table(n).shipment_line_id := x_cascaded_table(temp_index).shipment_line_id;
12895 x_cascaded_table(n).category_id := x_cascaded_table(temp_index).category_id;
12896 x_cascaded_table(n).vendor_id := x_cascaded_table(temp_index).vendor_id;
12897 x_cascaded_table(n).vendor_site_id := x_cascaded_table(temp_index).vendor_site_id;
12898 x_cascaded_table(n).po_unit_price := x_cascaded_table(temp_index).po_unit_price;
12899
12900 -- default the parent's to_lpn into the child's from_lpn
12901 /* Bug 3444284.
12902 * We dont need to default lpn_ids. WMS will take care of
12903 * populating these columns. So this case of giving a warning
12904 * will not arise as it will be defaulted by them
12905 */
12906 IF (x_cascaded_table(n).location_id IS NULL) THEN
12907 x_cascaded_table(n).location_id := x_cascaded_table(temp_index).location_id;
12908 END IF;
12909
12910 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN --{
12911 IF (NVL(x_cascaded_table(n).deliver_to_person_id, 0) = 0) THEN
12912 x_cascaded_table(n).deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
12913 END IF;
12914
12915 IF (NVL(x_cascaded_table(n).deliver_to_location_id, 0) = 0) THEN
12916 x_cascaded_table(n).deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
12917 END IF;
12918
12919 IF (x_cascaded_table(n).subinventory IS NULL) THEN
12920 x_cascaded_table(n).subinventory := x_cascaded_table(temp_index).subinventory;
12921 END IF;
12922 END IF; --}
12923 ELSE --} {
12924 IF (g_asn_debug = 'Y') THEN
12925 asn_debug.put_line('open cursor Default RTI');
12926 END IF;
12927
12928 OPEN po_transfer_rti(x_cascaded_table(n).parent_interface_txn_id);
12929 END IF; --}
12930 ELSE -- } {
12931 OPEN po_transfer(x_cascaded_table(n).parent_transaction_id);
12932 END IF; --}
12933
12934 IF (po_transfer%ISOPEN) THEN
12935 IF (g_asn_debug = 'Y') THEN
12936 asn_debug.put_line('fetch cursor Default');
12937 END IF;
12938
12939 FETCH po_transfer INTO default_po_transfer_info;
12940 ELSIF(po_transfer_rti%ISOPEN) THEN
12941 FETCH po_transfer_rti INTO default_po_transfer_info;
12942 END IF;
12943
12944 IF ( ( po_transfer%ISOPEN
12945 AND po_transfer%FOUND)
12946 OR ( po_transfer_rti%ISOPEN
12947 AND po_transfer_rti%FOUND)) THEN --{
12948 IF (g_asn_debug = 'Y') THEN --{
12949 asn_debug.put_line('Defaulting Transfer po_revision_num' || default_po_transfer_info.po_revision_num);
12950 asn_debug.put_line('Defaulting Transfer item_description' || default_po_transfer_info.item_description);
12951 asn_debug.put_line('Defaulting Transfer po_release_id' || default_po_transfer_info.po_release_id);
12952 asn_debug.put_line('Defaulting Transfer location_id' || default_po_transfer_info.loc_id);
12953 asn_debug.put_line('Defaulting Transfer organization_id' || default_po_transfer_info.organization_id);
12954 asn_debug.put_line('Defaulting Transfer routing_header_id' || default_po_transfer_info.routing_header_id);
12955 asn_debug.put_line('Defaulting Transfer currency_code' || default_po_transfer_info.currency_code);
12956 asn_debug.put_line('Defaulting Transfer currency_conversion_rate' || default_po_transfer_info.currency_conversion_rate);
12957 asn_debug.put_line('Defaulting Transfer currency_conversion_type' || default_po_transfer_info.currency_conversion_type);
12958 asn_debug.put_line('Defaulting Transfer currency_conversion_date' || default_po_transfer_info.currency_conversion_date);
12959 asn_debug.put_line('Defaulting Transfer shipment_header_id' || default_po_transfer_info.shipment_header_id);
12960 asn_debug.put_line('Defaulting Transfer shipment_line_id' || default_po_transfer_info.shipment_line_id);
12961 asn_debug.put_line('Defaulting Transfer category_id' || default_po_transfer_info.category_id);
12962 asn_debug.put_line('Defaulting Transfer vendor_id' || default_po_transfer_info.vendor_id);
12963 asn_debug.put_line('Defaulting Transfer vendor_site_id' || default_po_transfer_info.vendor_site_id);
12964 asn_debug.put_line('Defaulting Transfer DELIVER_TO_PERSON_ID' || default_po_transfer_info.deliver_to_person_id);
12965 asn_debug.put_line('Defaulting Transfer DELIVER_TO_LOCATION_ID' || default_po_transfer_info.deliver_to_location_id);
12966 asn_debug.put_line('Defaulting Transfer SUBINVENTORY' || default_po_transfer_info.subinventory);
12967 asn_debug.put_line('Defaulting Transfer CUSTOMER_ID' || default_po_transfer_info.customer_id);
12968 asn_debug.put_line('Defaulting Transfer CUSTOMER_SITE_ID' || default_po_transfer_info.customer_site_id);
12969 END IF; --}
12970
12971 IF x_cascaded_table(n).oe_order_header_id IS NULL
12972 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
12973 x_cascaded_table(n).oe_order_header_id := default_po_transfer_info.oe_order_header_id;
12974
12975 IF (g_asn_debug = 'Y') THEN
12976 asn_debug.put_line('Defaulting Transfer oe_order_header_id ' || x_cascaded_table(n).oe_order_header_id);
12977 END IF;
12978 END IF;
12979
12980 IF x_cascaded_table(n).oe_order_line_id IS NULL
12981 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
12982 x_cascaded_table(n).oe_order_line_id := default_po_transfer_info.oe_order_line_id;
12983
12984 IF (g_asn_debug = 'Y') THEN
12985 asn_debug.put_line('Defaulting Transfer oe_order_line_id ' || x_cascaded_table(n).oe_order_line_id);
12986 END IF;
12987 END IF;
12988
12989 x_cascaded_table(n).po_revision_num := default_po_transfer_info.po_revision_num;
12990 x_cascaded_table(n).item_description := default_po_transfer_info.item_description;
12991 x_cascaded_table(n).po_release_id := default_po_transfer_info.po_release_id;
12992 x_cascaded_table(n).to_organization_id := default_po_transfer_info.organization_id;
12993 x_cascaded_table(n).inspection_status_code := default_po_transfer_info.inspection_status_code;
12994 x_cascaded_table(n).routing_header_id := default_po_transfer_info.routing_header_id;
12995 x_cascaded_table(n).currency_code := default_po_transfer_info.currency_code;
12996 x_cascaded_table(n).currency_conversion_rate := default_po_transfer_info.currency_conversion_rate;
12997 x_cascaded_table(n).currency_conversion_type := default_po_transfer_info.currency_conversion_type;
12998 x_cascaded_table(n).currency_conversion_date := default_po_transfer_info.currency_conversion_date;
12999 x_cascaded_table(n).shipment_header_id := default_po_transfer_info.shipment_header_id;
13000 x_cascaded_table(n).shipment_line_id := default_po_transfer_info.shipment_line_id;
13001 x_cascaded_table(n).category_id := default_po_transfer_info.category_id;
13002 x_cascaded_table(n).vendor_id := default_po_transfer_info.vendor_id;
13003 x_cascaded_table(n).vendor_site_id := default_po_transfer_info.vendor_site_id;
13004
13005 /* We used to get the unit_price from the cursor where it picks
13006 * up from the parent. But since PO unit_price can be change
13007 * retroactively, we need to pick up the unit_price from PO
13008 * directly. Since we would have derived line_location_id
13009 * and po_line_id at this point, use the values here. Since
13010 * we come here for defaulting RMA also, we need to do this
13011 * only when receipt_source_code is VENDOR.
13012 * x_cascaded_table(n).po_unit_price :=
13013 DEFAULT_Po_transfer_info.po_unit_price;
13014 */
13015 IF (x_cascaded_table(n).receipt_source_code = 'VENDOR') THEN --{
13016 SELECT NVL(pll.price_override, pl.unit_price)
13017 INTO x_cascaded_table(n).po_unit_price
13018 FROM po_line_locations pll,
13019 po_lines pl
13020 WHERE pll.line_location_id = x_cascaded_table(n).po_line_location_id
13021 AND pl.po_line_id = x_cascaded_table(n).po_line_id
13022 AND pl.po_line_id = pll.po_line_id;
13023
13024 IF (g_asn_debug = 'Y') THEN
13025 asn_debug.put_line('Defaulting Transfer po_unit_price' || x_cascaded_table(n).po_unit_price);
13026 END IF;
13027 END IF; --}
13028
13029 x_cascaded_table(n).customer_id := default_po_transfer_info.customer_id;
13030 x_cascaded_table(n).customer_site_id := default_po_transfer_info.customer_site_id;
13031
13032 -- default the parent's to_lpn into the child's from_lpn
13033 /* Bug 3444284.
13034 * We dont need to default lpn_ids. WMS will take care of
13035 * populating these columns. So this case of giving a warning
13036 * will not arise as it will be defaulted by them
13037
13038 */
13039 IF (x_cascaded_table(n).location_id IS NULL) THEN
13040 x_cascaded_table(n).location_id := default_po_transfer_info.loc_id;
13041 END IF;
13042
13043 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN --{
13044 IF (NVL(x_cascaded_table(n).deliver_to_person_id, 0) = 0) THEN
13045 x_cascaded_table(n).deliver_to_person_id := default_po_transfer_info.deliver_to_person_id;
13046 END IF;
13047
13048 IF (NVL(x_cascaded_table(n).deliver_to_location_id, 0) = 0) THEN
13049 x_cascaded_table(n).deliver_to_location_id := default_po_transfer_info.deliver_to_location_id;
13050 END IF;
13051
13052 IF (x_cascaded_table(n).subinventory IS NULL) THEN
13053 x_cascaded_table(n).subinventory := default_po_transfer_info.subinventory;
13054 END IF;
13055 END IF; --}
13056 END IF; -- if po_transfer%found is true }
13057
13058 /* The following code will be common for all the transactions not just for transfer to
13059 * get the use_mtl_lot and use_mtl_serial.
13060 */
13061 /*
13062 BEGIN Comment: Bug: 4735484
13063 IF x_cascaded_table(n).item_id IS NOT NULL THEN
13064 SELECT NVL(x_cascaded_table(n).use_mtl_lot, lot_control_code),
13065 NVL(x_cascaded_table(n).use_mtl_serial, serial_number_control_code)
13066 INTO x_cascaded_table(n).use_mtl_lot,
13067 x_cascaded_table(n).use_mtl_serial
13068 FROM mtl_system_items
13069 WHERE mtl_system_items.inventory_item_id = NVL(x_cascaded_table(n).item_id, 0)
13070 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
13071 END IF;
13072 END Comment: Bug: 4735484
13073 */
13074 x_cascaded_table(n).interface_source_code := NVL(x_cascaded_table(n).interface_source_code,'RCV'); -- Bug 10127806;
13075
13076 IF (x_cascaded_table(n).transaction_type = 'ACCEPT') THEN
13077 x_cascaded_table(n).inspection_status_code := 'ACCEPTED';
13078 x_cascaded_table(n).destination_context := 'RECEIVING';
13079 ELSIF(x_cascaded_table(n).transaction_type = 'REJECT') THEN
13080 x_cascaded_table(n).inspection_status_code := 'REJECTED';
13081 x_cascaded_table(n).destination_context := 'RECEIVING';
13082 END IF;
13083
13084 /* Only for deliver, to_subinventory is a required field. If the user
13085 * has not provided then we will not default for the other transactions.
13086 * from_subinventory will be the to_sub of the parent .
13087 */
13088 ---WMS Changes
13089 default_from_subloc_info(x_cascaded_table, n);
13090
13091 /* Bug 3557343.
13092 * We need to default to_sub/to_loc for other transactions also. We
13093 * used to do it only for deliver transactions. Now do it for
13094 * ACCEPT/REJECT transactions also.
13095 */
13096 IF (x_cascaded_table(n).transaction_type IN('DELIVER', 'ACCEPT', 'REJECT')) THEN
13097 default_to_subloc_info(x_cascaded_table, n);
13098 END IF;
13099
13100 /*
13101 ** Make sure to set the location_id properly
13102 */
13103 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
13104 x_cascaded_table(n).location_id := x_cascaded_table(n).deliver_to_location_id;
13105 END IF;
13106
13107 IF (g_asn_debug = 'Y') THEN
13108 asn_debug.put_line('Set Location_id = ' || TO_CHAR(x_cascaded_table(n).location_id));
13109 END IF;
13110
13111 IF (g_asn_debug = 'Y') THEN
13112 asn_debug.put_line('Exit default_vendor_trans_del');
13113 END IF;
13114
13115 IF po_transfer%ISOPEN THEN
13116 CLOSE po_transfer;
13117 END IF;
13118
13119 IF po_transfer_rti%ISOPEN THEN
13120 CLOSE po_transfer_rti;
13121 END IF;
13122 EXCEPTION
13123 WHEN OTHERS THEN
13124 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
13125 rcv_error_pkg.set_sql_error_message('default_vendor_trans_del', '000');
13126 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
13127 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
13128 END default_vendor_trans_del;
13129
13130
13131 PROCEDURE derive_correction_line(
13132 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
13133 n IN OUT NOCOPY BINARY_INTEGER,
13134 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
13135 x_header_record IN rcv_roi_preprocessor.header_rec_type
13136 ) IS
13137 l_po_header_id po_headers_all.po_header_id%type;
13138 l_return_status VARCHAR2(1) :='S';
13139 l_complex_flag varchar2(1);
13140 l_asn_type rcv_shipment_headers.asn_type%TYPE; --9534775
13141
13142 BEGIN
13143 IF (g_asn_debug = 'Y') THEN
13144 asn_debug.put_line('enter derive_correction_line ');
13145 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
13146 END IF;
13147
13148 /* Derive the to_org_id */
13149 derive_ship_to_org_info(x_cascaded_table,
13150 n,
13151 x_header_record
13152 );
13153
13154 IF (x_cascaded_table(n).unit_of_measure IS NOT NULL) THEN
13155 IF (g_asn_debug = 'Y') THEN
13156 asn_debug.put_line('X_progress ' || x_progress);
13157 END IF;
13158
13159 SELECT muom.uom_code
13160 INTO x_cascaded_table(n).uom_code
13161 FROM mtl_units_of_measure muom
13162 WHERE muom.unit_of_measure = x_cascaded_table(n).unit_of_measure;
13163 ELSE
13164 IF (g_asn_debug = 'Y') THEN
13165 asn_debug.put_line('uom_code not derived as unit_of_measure is null');
13166 END IF;
13167 END IF;
13168
13169 x_progress := '091';
13170 derive_reason_info(x_cascaded_table, n);
13171 /* Auto_transact_code is null for all these transaction types */
13172 x_cascaded_table(n).auto_transact_code := NULL;
13173
13174 -- Determine whether this is a services line type
13175 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
13176 IF (g_asn_debug = 'Y') THEN
13177 asn_debug.put_line('parent_transaction_id ' || x_cascaded_table(n).parent_transaction_id);
13178 END IF;
13179
13180 SELECT po_line_id,po_header_id
13181 INTO x_cascaded_table(n).po_line_id,l_po_header_id
13182 FROM rcv_transactions
13183 WHERE transaction_id = x_cascaded_table(n).parent_transaction_id;
13184 ELSIF(x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
13185 IF (g_asn_debug = 'Y') THEN
13186 asn_debug.put_line('parent_interface_txn_id ' || x_cascaded_table(n).parent_interface_txn_id);
13187 END IF;
13188
13189 SELECT po_line_id,po_header_id
13190 INTO x_cascaded_table(n).po_line_id,l_po_header_id
13191 FROM rcv_transactions_interface
13192 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
13193 END IF;
13194
13195 IF (g_asn_debug = 'Y') THEN
13196 asn_debug.put_line('po_line_id ' || x_cascaded_table(n).po_line_id);
13197 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
13198 END IF;
13199
13200 /* R12 Complex work.
13201 * We do not support any other receiving transactions other
13202 * than direct receipt. Error out if it is complex work PO.
13203 */
13204
13205 PO_COMPLEX_WORK_GRP.is_complex_work_po(
13206 1.0,
13207 l_po_header_id,
13208 l_return_status,
13209 l_complex_flag);
13210 IF (l_return_status IS NOT NULL AND
13211 l_return_status = FND_API.g_ret_sts_success) THEN
13212 IF( g_asn_debug = 'Y' ) THEN
13213 asn_debug.put_line('l_return_status ' || l_return_status);
13214 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
13215 END IF;
13216 ELSE
13217 IF( g_asn_debug = 'Y') THEN
13218 asn_debug.put_line('l_return_status ' || l_return_status);
13219 END IF;
13220 END IF;
13221
13222 /*Bug 9534775 need support wc -ve correction */
13223 IF (l_complex_flag = 'Y') THEN
13224 select asn_type
13225 into l_asn_type
13226 from rcv_shipment_headers
13227 where shipment_header_id = x_cascaded_table(n).shipment_header_id;
13228
13229 IF( g_asn_debug = 'Y') THEN
13230 asn_debug.put_line('enter l_complex_flag = Y ');
13231 asn_debug.put_line('asn_type ' || l_asn_type);
13232 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
13233 asn_debug.put_line('amount ' || x_cascaded_table(n).amount);
13234 END IF;
13235 IF (l_asn_type ='WC' AND (nvl(x_cascaded_table(n).quantity,0) >0 OR nvl(x_cascaded_table(n).amount,0) > 0) ) THEN
13236 asn_debug.put_line('We do not support positive transaction type of ' || x_cascaded_table(n).transaction_type || ' for complex work POs');
13237 rcv_error_pkg.set_error_message('RCV_INVALID_TRANSACTION_TYPE');
13238 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
13239 END IF;
13240 End if;
13241
13242 IF x_cascaded_table(n).po_line_id IS NOT NULL THEN
13243 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
13244 NVL(purchase_basis, 'GOODS'),
13245 NVL(matching_basis, 'QUANTITY')
13246 INTO x_cascaded_table(n).value_basis,
13247 x_cascaded_table(n).purchase_basis,
13248 x_cascaded_table(n).matching_basis
13249 FROM po_lines
13250 WHERE po_line_id = x_cascaded_table(n).po_line_id;
13251 ELSE
13252 -- we require line info for receiving against services lines
13253 x_cascaded_table(n).matching_basis := 'QUANTITY';
13254 x_cascaded_table(n).purchase_basis := 'GOODS';
13255 END IF;
13256
13257 /**Bug 9534775 wc -ve correct , fetch value_basis/matching_basis from po_line_locations **/
13258 IF x_cascaded_table(n).po_line_location_id IS NOT NULL
13259 AND l_complex_flag = 'Y' THEN
13260
13261 SELECT NVL(value_basis, 'QUANTITY'),
13262 NVL(matching_basis, 'QUANTITY')
13263 INTO x_cascaded_table(n).value_basis,
13264 x_cascaded_table(n).matching_basis
13265 FROM po_line_locations
13266 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
13267
13268 END IF;
13269 /**End Bug 9534775**/
13270
13271 IF (g_asn_debug = 'Y') THEN
13272 asn_debug.put_line('matching_basis ' || x_cascaded_table(n).matching_basis);
13273 END IF;
13274
13275 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
13276 derive_correction_line_amt(x_cascaded_table,
13277 n,
13278 temp_cascaded_table
13279 );
13280 ELSE
13281 derive_correction_line_qty(x_cascaded_table,
13282 n,
13283 temp_cascaded_table
13284 );
13285 END IF;
13286
13287 IF (g_asn_debug = 'Y') THEN
13288 asn_debug.put_line('exit derive_correction_line');
13289 asn_debug.put_line('quantity ' || temp_cascaded_table(n).quantity);
13290 END IF;
13291 EXCEPTION
13292 WHEN OTHERS THEN
13293 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
13294 rcv_error_pkg.set_sql_error_message('derive_correction_line', '000');
13295 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
13296 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
13297 END derive_correction_line;
13298
13299 PROCEDURE derive_correction_line_qty(
13300 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
13301 n IN OUT NOCOPY BINARY_INTEGER,
13302 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type
13303 ) IS
13304 x_include_closed_po VARCHAR2(1); -- Bug 1887728
13305 /*
13306 ** Might be a compatibility issue between the two record definitions
13307 */
13308 x_record_count NUMBER;
13309 x_remaining_quantity NUMBER := 0;
13310 x_remaining_qty_po_uom NUMBER := 0;
13311 x_bkp_qty NUMBER := 0;
13312 x_progress VARCHAR2(3);
13313 x_to_organization_code VARCHAR2(5);
13314 x_converted_trx_qty NUMBER := 0;
13315 transaction_ok BOOLEAN := FALSE;
13316 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
13317 high_range_date DATE;
13318 low_range_date DATE;
13319 rows_fetched NUMBER := 0;
13320 x_tolerable_qty NUMBER := 0;
13321 x_first_trans BOOLEAN := TRUE;
13322 x_sysdate DATE := SYSDATE;
13323 current_n BINARY_INTEGER := 0;
13324 insert_into_table BOOLEAN := FALSE;
13325 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
13326 tax_amount_factor NUMBER;
13327 lastrecord BOOLEAN := FALSE;
13328 po_asn_uom_qty NUMBER;
13329 po_primary_uom_qty NUMBER;
13330 already_allocated_qty NUMBER := 0;
13331 x_item_id NUMBER;
13332 x_approved_flag VARCHAR(1);
13333 x_cancel_flag VARCHAR(1);
13334 x_closed_code VARCHAR(25);
13335 x_shipment_type VARCHAR(25);
13336 x_ship_to_organization_id NUMBER;
13337 x_ship_to_location_id NUMBER;
13338 /* temp_ship_to_location_id number;
13339 temp_mirror_ship_to_loc_id number ;
13340 temp_enf_ship_to_loc_code varchar(25) ; */
13341 /* The above 3 variables added for bug 1898283 */
13342 x_vendor_product_num VARCHAR(25);
13343 x_temp_count NUMBER;
13344 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
13345 /* 1887728 -Added the following variables */
13346 profile_user_id NUMBER := -1;
13347 profile_appl_id NUMBER := -1;
13348 profile_resp_id NUMBER := -1;
13349 defined BOOLEAN;
13350 /* 1845702 */
13351 x_sob_id NUMBER := NULL;
13352 x_rate NUMBER;
13353 x_allow_rate_override VARCHAR2(1);
13354 /* Bug# 1548597 */
13355 x_secondary_available_qty NUMBER := 0;
13356
13357 /********************************************************************/
13358 CURSOR po_correct(
13359 v_parent_trx_id NUMBER,
13360 v_to_organization_id NUMBER
13361 ) IS
13362 SELECT rt.po_line_location_id,
13363 rt.po_header_id po_head_id,
13364 rt.po_line_id line_id,
13365 rt.transaction_id rcv_transaction_id,
13366 rt.parent_transaction_id grand_parent_txn_id,
13367 poh.segment1 document_num,
13368 pol.line_num line_number,
13369 rt.transaction_date transaction_date,
13370 rt.transaction_type parent_transaction_type,
13371 rt.quantity qty,
13372 rt.unit_of_measure unit_of_meas,
13373 rt.primary_unit_of_measure,
13374 rt.primary_quantity,
13375 rt.organization_id,
13376 rt.po_unit_price unit_price,
13377 rsl.category_id,
13378 rsl.item_description,
13379 rt.po_line_id,
13380 rt.location_id,
13381 rsl.item_id,
13382 rt.deliver_to_person_id,
13383 rt.deliver_to_location_id,
13384 rt.subinventory destination_subinventory,
13385 rt.po_distribution_id,
13386 rt.destination_type_code,
13387 rt.wip_entity_id,
13388 rt.wip_operation_seq_num,
13389 rt.wip_resource_seq_num,
13390 rt.wip_repetitive_schedule_id,
13391 rt.wip_line_id,
13392 rt.bom_resource_id,
13393 rsl.ussgl_transaction_code
13394 FROM rcv_transactions rt,
13395 rcv_shipment_lines rsl,
13396 po_headers poh,
13397 po_lines pol
13398 WHERE rt.transaction_id = v_parent_trx_id
13399 AND rt.organization_id = NVL(v_to_organization_id, rt.organization_id)
13400 AND ( rt.transaction_type IN('RECEIVE', 'TRANSFER', 'ACCEPT', 'REJECT', 'MATCH')
13401 OR ( rt.transaction_type IN('RETURN TO VENDOR', 'RETURN TO CUSTOMER')
13402 AND NOT EXISTS(SELECT 'rtv to processed matched unordered receipt'
13403 FROM rcv_transactions rt2,
13404 rcv_transactions rt3
13405 WHERE rt2.transaction_id = rt.parent_transaction_id
13406 AND rt2.transaction_type = 'UNORDERED'
13407 AND rt3.transaction_type = 'MATCH'
13408 AND rt3.parent_transaction_id = rt2.transaction_id)
13409 AND NOT EXISTS(SELECT 'rtv to unprocessed matched unordered receipt'
13410 FROM rcv_transactions rt2,
13411 rcv_transactions_interface rti
13412 WHERE rt2.transaction_id = rt.parent_transaction_id
13413 AND rt2.transaction_type = 'UNORDERED'
13414 AND rti.transaction_type = 'MATCH'
13415 AND rti.parent_transaction_id = rt2.transaction_id)
13416 )
13417 OR ( rt.transaction_type = 'DELIVER'
13418 AND NOT( rt.destination_type_code = 'INVENTORY'
13419 AND rt.source_document_code IN('REQ', 'INVENTORY', 'RMA')))
13420 OR ( rt.transaction_type = 'UNORDERED'
13421 AND NOT EXISTS(SELECT 'processed matched rows'
13422 FROM rcv_transactions rt2
13423 WHERE rt2.parent_transaction_id = rt.transaction_id
13424 AND rt2.transaction_type = 'MATCH')
13425 AND NOT EXISTS(SELECT 'unprocessed matched rows'
13426 FROM rcv_transactions_interface rti
13427 WHERE rti.parent_transaction_id = rt.transaction_id
13428 AND rti.transaction_type = 'MATCH')
13429 )
13430 )
13431 AND NOT EXISTS(SELECT 'purchase order shipment cancelled or fc'
13432 FROM po_line_locations pll
13433 WHERE pll.line_location_id = rt.po_line_location_id
13434 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
13435 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED'))
13436 AND (rt.shipment_line_id = rsl.shipment_line_id)
13437 AND (poh.po_header_id = rt.po_header_id)
13438 AND (pol.po_line_id = rt.po_line_id)
13439 AND ( rt.dropship_type_code = 3
13440 OR rt.dropship_type_code IS NULL)
13441 ORDER BY rt.transaction_id;
13442
13443 CURSOR po_correct_rti(
13444 v_parent_interface_txn_id NUMBER
13445 ) IS
13446 SELECT rti.po_line_location_id,
13447 rti.po_header_id po_head_id,
13448 rti.po_line_id line_id,
13449 rti.interface_transaction_id rcv_transaction_id,
13450 rti.parent_transaction_id grand_parent_txn_id,
13451 rti.document_num,
13452 rti.document_line_num line_number,
13453 rti.transaction_date transaction_date,
13454 rti.transaction_type parent_transaction_type,
13455 rti.quantity qty,
13456 rti.unit_of_measure unit_of_meas,
13457 rti.primary_unit_of_measure,
13458 rti.primary_quantity,
13459 rti.to_organization_id organization_id,
13460 rti.po_unit_price unit_price,
13461 rti.category_id,
13462 rti.item_description,
13463 rti.po_line_id,
13464 rti.location_id,
13465 rti.item_id,
13466 rti.deliver_to_person_id,
13467 rti.deliver_to_location_id,
13468 rti.subinventory destination_subinventory,
13469 rti.po_distribution_id,
13470 rti.destination_type_code,
13471 rti.wip_entity_id,
13472 rti.wip_operation_seq_num,
13473 rti.wip_resource_seq_num,
13474 rti.wip_repetitive_schedule_id,
13475 rti.wip_line_id,
13476 rti.bom_resource_id,
13477 rti.ussgl_transaction_code
13478 FROM rcv_transactions_interface rti
13479 WHERE interface_transaction_id = v_parent_interface_txn_id;
13480
13481 x_po_correctrec po_correct%ROWTYPE;
13482 x_temp_parent_trx_qty NUMBER := 0;
13483 x_converted_parent_trx_qty NUMBER := 0;
13484 x_temp_convert_parent_trx_qty NUMBER := 0;
13485 x_remaining_qty_parent_uom NUMBER := 0;
13486 l_to_organization_id NUMBER := 0;
13487 l_transaction_type rcv_transactions.transaction_type%TYPE;
13488 x_temp_already_allocated_qty NUMBER := 0;
13489 derive_values_from_table BOOLEAN := FALSE;
13490 derive_values_from_rti BOOLEAN := FALSE;
13491 already_derived BOOLEAN := FALSE;
13492 cascaded_table_index NUMBER;
13493 l_grand_parent_trx_id rcv_transactions.parent_transaction_id%TYPE;
13494 temp_index NUMBER;
13495 l_line_loc_id po_line_locations.line_location_id%TYPE;
13496 l_exist VARCHAR2(30);
13497 l_exist1 VARCHAR2(30);
13498 l_exist2 VARCHAR2(30);
13499 l_destination_type_code rcv_transactions.destination_type_code%TYPE;
13500 l_source_document_code rcv_transactions.source_document_code%TYPE;
13501 /* Bug#5369121 */
13502 l_primary_uom rcv_transactions_interface.unit_of_measure%TYPE;
13503 l_transaction_uom rcv_transactions.unit_of_measure%TYPE;
13504 l_interface_quantity NUMBER;
13505 l_interface_qty_in_trx_uom NUMBER;
13506 l_item_id NUMBER;
13507 /* Bug#5369121 */
13508
13509 -- <Bug 9342280 : Added for CLM project>
13510 l_is_clm_po VARCHAR2(5) := 'N';
13511 l_partial_funded_flag VARCHAR2(5) := 'N';
13512 -- <CLM END>
13513 BEGIN
13514 IF (g_asn_debug = 'Y') THEN
13515 asn_debug.put_line('enter derive_quantity ' || x_cascaded_table(n).parent_transaction_id);
13516 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
13517 END IF;
13518
13519 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
13520 already_derived := TRUE;
13521 END IF; --}
13522
13523 IF ( NOT already_derived
13524 AND (x_cascaded_table(n).parent_interface_txn_id IS NULL)
13525 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN --{
13526 /* This means that there can be a row in RT with src_txn_id
13527 * populated or it can be a child.
13528 */
13529 BEGIN
13530 SELECT transaction_id
13531 INTO x_cascaded_table(n).parent_transaction_id
13532 FROM rcv_transactions
13533 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
13534
13535 already_derived := TRUE;
13536 EXCEPTION
13537 -- Bug 7651646
13538 WHEN NO_DATA_FOUND THEN
13539 rcv_error_pkg.set_error_message('RCV_NO_PARENT_SRC_TRANSACTION');
13540 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
13541 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13542 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
13543 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13544
13545 WHEN TOO_MANY_ROWS THEN
13546 rcv_error_pkg.set_error_message('RCV_DUP_SRC_TRANSACTION');
13547 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
13548 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13549 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
13550 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13551 END;
13552 END IF; --}
13553
13554 IF already_derived THEN --{
13555 IF (g_asn_debug = 'Y') THEN
13556 asn_debug.put_line(' open po_correct table ' || x_cascaded_table(n).parent_transaction_id);
13557 END IF;
13558
13559 OPEN po_correct(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
13560 END IF; ---}
13561
13562 IF (NOT already_derived) THEN --{
13563 derive_parent_id(x_cascaded_table, n);
13564
13565 /* This means that there was no error in
13566 * derive_parent_id which means that the
13567 * this is a child and need to get the values
13568 * from the rti and not from the plsql table.
13569 */
13570 IF ( (x_cascaded_table(n).error_status <> 'E')
13571 AND ( x_cascaded_table(n).derive = 'Y'
13572 AND x_cascaded_table(n).derive_index = 0)) THEN
13573 /* if derive_values_from_table is true, then we
13574 * derive the values from the pl/sql tables later
13575 * at the time when we try to see which cursor is open.
13576 * We will have x_cascaded_table(n).
13577 * parent_interface_txn_id) populated with teh
13578 * correct value.
13579 */
13580 IF (g_asn_debug = 'Y') THEN
13581 asn_debug.put_line(' open correct cursor from rti');
13582 END IF;
13583
13584 OPEN po_correct_rti(x_cascaded_table(n).parent_interface_txn_id);
13585 END IF;
13586 END IF; --}
13587
13588 /******************************************************************/
13589 --check line quanity > 0
13590 x_progress := '097';
13591
13592 IF (g_asn_debug = 'Y') THEN
13593 asn_debug.put_line('X_progress ' || x_progress);
13594 END IF;
13595
13596 IF x_cascaded_table(n).error_status IN('S', 'W')
13597 AND x_cascaded_table(n).quantity = 0 THEN --{
13598 IF (g_asn_debug = 'Y') THEN
13599 asn_debug.put_line('Quantity is <= zero. Cascade will fail');
13600 END IF;
13601
13602 x_cascaded_table(n).error_status := 'F';
13603 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
13604 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
13605 END IF; --} end qty > 0 check
13606
13607 -- the following steps will create a set of rows linking the line_record with
13608 -- its corresponding po_line_location rows until the quantity value from
13609 -- the asn is consumed. (Cascade)
13610
13611 /* 2119137 : If the user populates rcv_transactions_interface
13612 with po_line_id, then ROI errors out with
13613 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
13614 is not provided for one time items. Modified the "if" criteria in
13615 such a way that the ROI validation does'nt error out when
13616 po_line_id is populated for one time items. */
13617 x_progress := '098';
13618
13619 IF (g_asn_debug = 'Y') THEN
13620 asn_debug.put_line('X_progress ' || x_progress);
13621 END IF;
13622
13623 IF ( ( x_cascaded_table(n).parent_transaction_id IS NOT NULL
13624 OR x_cascaded_table(n).parent_interface_txn_id IS NOT NULL)
13625 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
13626
13627 -- Copy record from main table to temp table
13628 IF (g_asn_debug = 'Y') THEN
13629 asn_debug.put_line('Copy record from main table to temp table');
13630 END IF;
13631
13632 current_n := 1;
13633 temp_cascaded_table(current_n) := x_cascaded_table(n);
13634
13635 -- Get all rows which meet this condition
13636 IF (g_asn_debug = 'Y') THEN
13637 asn_debug.put_line('Get all rows which meet this condition');
13638 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
13639 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
13640 END IF;
13641
13642 -- Assign shipped quantity to remaining quantity
13643 IF (g_asn_debug = 'Y') THEN
13644 asn_debug.put_line('Assign populated quantity to remaining quantity');
13645 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
13646 END IF;
13647
13648 x_remaining_quantity := temp_cascaded_table(current_n).quantity;
13649 x_bkp_qty := x_remaining_quantity; -- used for decrementing cum qty for first record
13650 x_remaining_qty_po_uom := 0;
13651
13652 IF (g_asn_debug = 'Y') THEN
13653 asn_debug.put_line('Have assigned the quantity');
13654 END IF;
13655
13656 -- Calculate tax_amount_factor for calculating tax_amount for
13657 -- each cascaded line
13658
13659 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
13660 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_quantity;
13661 ELSE
13662 tax_amount_factor := 0;
13663 END IF;
13664
13665 IF (g_asn_debug = 'Y') THEN
13666 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
13667 asn_debug.put_line('transaction Quantity : ' || TO_CHAR(x_remaining_quantity));
13668 END IF;
13669
13670 x_first_trans := TRUE;
13671 transaction_ok := FALSE;
13672
13673 IF (g_asn_debug = 'Y') THEN
13674 asn_debug.put_line('Before starting Cascade');
13675 END IF;
13676
13677 IF (g_asn_debug = 'Y') THEN
13678 asn_debug.put_line('Record Count = ' || x_record_count);
13679 END IF;
13680
13681 LOOP --{
13682 IF (g_asn_debug = 'Y') THEN
13683 asn_debug.put_line('Backup Qty ' || TO_CHAR(x_bkp_qty));
13684 asn_debug.put_line('Remaining Quantity ' || TO_CHAR(x_remaining_quantity));
13685 END IF;
13686
13687 /*
13688 ** Fetch the appropriate record
13689 */
13690 IF (g_asn_debug = 'Y') THEN
13691 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
13692 END IF;
13693
13694 IF (po_correct%ISOPEN) THEN --{
13695 IF (g_asn_debug = 'Y') THEN
13696 asn_debug.put_line(' fetch po_correct');
13697 END IF;
13698
13699 FETCH po_correct INTO x_po_correctrec;
13700
13701 IF (po_correct%NOTFOUND) THEN
13702 lastrecord := TRUE;
13703 END IF;
13704
13705 rows_fetched := po_correct%ROWCOUNT;
13706 ELSIF(po_correct_rti%ISOPEN) THEN --}{
13707 IF (g_asn_debug = 'Y') THEN
13708 asn_debug.put_line(' fetch po_correct_rti');
13709 END IF;
13710
13711 FETCH po_correct_rti INTO x_po_correctrec;
13712
13713 IF (po_correct_rti%NOTFOUND) THEN
13714 IF (g_asn_debug = 'Y') THEN
13715 asn_debug.put_line('correct last row');
13716 END IF;
13717
13718 lastrecord := TRUE;
13719 END IF;
13720
13721 rows_fetched := po_correct_rti%ROWCOUNT;
13722 ELSIF(temp_cascaded_table(current_n).derive = 'Y') THEN --}{
13723 /* GET VALUES FROM THE PLSQL TABLE */
13724 /* Populate x_po_correctrec with these values since
13725 * we are using x_po_correctrec later.
13726 * We have temp_cascaded_table(current_n).
13727 * parent_interface_txn_id) populated with
13728 * with the correct value. Also we have cascaded_table_index
13729 * with the correct pl/sql table index number;
13730 */
13731 IF (g_asn_debug = 'Y') THEN
13732 asn_debug.put_line(' fetch pl/sql table');
13733 END IF;
13734
13735 temp_index := temp_cascaded_table(current_n).derive_index;
13736 x_po_correctrec.po_line_location_id := x_cascaded_table(temp_index).po_line_location_id;
13737 x_po_correctrec.po_head_id := x_cascaded_table(temp_index).po_header_id;
13738 x_po_correctrec.line_id := x_cascaded_table(temp_index).po_line_id;
13739 x_po_correctrec.unit_of_meas := x_cascaded_table(temp_index).unit_of_measure;
13740 x_po_correctrec.grand_parent_txn_id := x_cascaded_table(temp_index).parent_transaction_id;
13741 x_po_correctrec.document_num := x_cascaded_table(temp_index).document_num;
13742 x_po_correctrec.line_number := x_cascaded_table(temp_index).document_line_num;
13743 x_po_correctrec.transaction_date := x_cascaded_table(temp_index).transaction_date;
13744 x_po_correctrec.parent_transaction_type := x_cascaded_table(temp_index).transaction_type;
13745 x_po_correctrec.qty := x_cascaded_table(temp_index).quantity;
13746 x_po_correctrec.primary_unit_of_measure := x_cascaded_table(temp_index).primary_unit_of_measure;
13747 x_po_correctrec.primary_quantity := x_cascaded_table(temp_index).primary_quantity;
13748 x_po_correctrec.organization_id := x_cascaded_table(temp_index).to_organization_id;
13749 x_po_correctrec.unit_price := x_cascaded_table(temp_index).po_unit_price;
13750 x_po_correctrec.category_id := x_cascaded_table(temp_index).category_id;
13751 x_po_correctrec.item_description := x_cascaded_table(temp_index).item_description;
13752 x_po_correctrec.location_id := x_cascaded_table(temp_index).location_id;
13753 x_po_correctrec.item_id := x_cascaded_table(temp_index).item_id;
13754 x_po_correctrec.deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
13755 x_po_correctrec.deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
13756 x_po_correctrec.destination_subinventory := x_cascaded_table(temp_index).subinventory;
13757 x_po_correctrec.po_distribution_id := x_cascaded_table(temp_index).po_distribution_id;
13758 x_po_correctrec.destination_type_code := x_cascaded_table(temp_index).destination_type_code;
13759 x_po_correctrec.wip_entity_id := x_cascaded_table(temp_index).wip_entity_id;
13760 x_po_correctrec.wip_operation_seq_num := x_cascaded_table(temp_index).wip_operation_seq_num;
13761 x_po_correctrec.wip_resource_seq_num := x_cascaded_table(temp_index).wip_resource_seq_num;
13762 x_po_correctrec.wip_repetitive_schedule_id := x_cascaded_table(temp_index).wip_repetitive_schedule_id;
13763 x_po_correctrec.wip_line_id := x_cascaded_table(temp_index).wip_line_id;
13764 x_po_correctrec.bom_resource_id := x_cascaded_table(temp_index).bom_resource_id;
13765 x_po_correctrec.ussgl_transaction_code := x_cascaded_table(temp_index).ussgl_transaction_code;
13766 /* Also fetch parent transaction type and grand parent trx id into
13767 * the correct variables.
13768 */
13769 rows_fetched := 1;
13770 lastrecord := TRUE;
13771 END IF; --}
13772 --x_remaining_quantity:= temp_cascaded_table(current_n).quantity;
13773
13774 IF (g_asn_debug = 'Y') THEN
13775 asn_debug.put_line('Correct Rows fetched ' || TO_CHAR(rows_fetched));
13776 asn_debug.put_line('po_line_id ' || TO_CHAR(x_po_correctrec.po_line_id));
13777 asn_debug.put_line('po_dist ' || TO_CHAR(x_po_correctrec.po_distribution_id));
13778 asn_debug.put_line('correct remainaing qty ' || x_remaining_quantity);
13779 END IF;
13780
13781 IF (lastrecord) THEN --{
13782 IF (g_asn_debug = 'Y') THEN
13783 asn_debug.put_line('Hit exit condition');
13784 END IF;
13785
13786 IF NOT x_first_trans THEN
13787 -- x_first_trans has been reset which means some cascade has
13788 -- happened. Otherwise current_n = 1
13789 IF (g_asn_debug = 'Y') THEN
13790 asn_debug.put_line('current_n before is ' || current_n);
13791 END IF;
13792
13793 current_n := current_n - 1;
13794 END IF;
13795
13796 -- do the tolerance act here
13797 IF (g_asn_debug = 'Y') THEN
13798 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
13799 asn_debug.put_line('Check which condition has occured');
13800 END IF;
13801
13802 -- lastrecord...we have run out of rows and we still have quantity to allocate
13803 /* Do abs(x_remaining_quantity) since it can be a negative
13804 * or positive correction.
13805 */
13806 IF ABS(x_remaining_quantity) > 0 THEN --{
13807 IF (g_asn_debug = 'Y') THEN
13808 asn_debug.put_line('There is quantity remaining ');
13809 asn_debug.put_line('tolerable quantity now in plsql table ' || temp_cascaded_table(current_n).quantity);
13810 asn_debug.put_line('rows_fetched ' || rows_fetched);
13811 END IF;
13812
13813 IF NOT x_first_trans THEN
13814 IF (g_asn_debug = 'Y') THEN
13815 asn_debug.put_line('not fisrt txn');
13816 END IF;
13817 END IF;
13818
13819 IF rows_fetched > 0
13820 AND NOT x_first_trans THEN --{
13821 IF (g_asn_debug = 'Y') THEN
13822 asn_debug.put_line(' inside transaction_type ' || x_po_correctrec.parent_transaction_type);
13823 END IF;
13824
13825 IF (SIGN(x_cascaded_table(current_n).quantity) = 1) THEN --{
13826 IF (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH')) THEN --{
13827 IF (g_asn_debug = 'Y') THEN
13828 asn_debug.put_line('Need to check qty tolerances');
13829 END IF;
13830
13831 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
13832 INTO x_qty_rcv_exception_code
13833 FROM po_line_locations
13834 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
13835
13836 IF (g_asn_debug = 'Y') THEN
13837 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
13838 END IF;
13839
13840 IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
13841 /* Bug# 1807842 */
13842 IF (temp_cascaded_table(current_n).quantity <= x_converted_parent_trx_qty) THEN --{
13843 IF (g_asn_debug = 'Y') THEN
13844 asn_debug.put_line('Tolerable quantity ' || TO_CHAR(x_converted_parent_trx_qty));
13845 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
13846 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
13847 asn_debug.put_line('Assign remaining ASN UOM qty ' || TO_CHAR(x_remaining_quantity) || ' to last record');
13848 asn_debug.put_line('Assign remaining PO UOM qty ' || TO_CHAR(x_remaining_qty_po_uom) || ' to last record');
13849 END IF;
13850
13851 temp_cascaded_table(current_n).quantity := temp_cascaded_table(current_n).quantity + x_remaining_quantity;
13852 temp_cascaded_table(current_n).primary_quantity := temp_cascaded_table(current_n).primary_quantity
13853 + rcv_transactions_interface_sv.convert_into_correct_qty(x_remaining_quantity,
13854 temp_cascaded_table(1).unit_of_measure,
13855 temp_cascaded_table(1).item_id,
13856 temp_cascaded_table(1).primary_unit_of_measure
13857 );
13858 END IF; /* Bug# 1807842 */ --}
13859
13860 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).quantity * tax_amount_factor, 6);
13861
13862 IF (g_asn_debug = 'Y') THEN
13863 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
13864 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
13865 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
13866 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
13867 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
13868 END IF;
13869
13870 -- <Bug 9342280 : Added for CLM project>
13871 get_clm_info( 'QUANTITY',
13872 x_cascaded_table,
13873 n,
13874 l_is_clm_po,
13875 l_partial_funded_flag);
13876
13877 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
13878
13879 x_qty_rcv_exception_code := 'REJECT';
13880
13881 END IF;
13882 --<END CLM>
13883
13884 IF x_qty_rcv_exception_code = 'WARNING' THEN --{
13885 IF (g_asn_debug = 'Y') THEN
13886 asn_debug.put_line('IN WARNING');
13887 END IF;
13888
13889 temp_cascaded_table(current_n).error_status := 'W';
13890 temp_cascaded_table(current_n).error_message := 'RCV_ALL_QTY_OVER_TOLERANCE';
13891
13892 IF (g_asn_debug = 'Y') THEN
13893 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
13894 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
13895 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
13896 END IF;
13897
13898 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
13899 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
13900 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
13901 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
13902 rcv_error_pkg.log_interface_warning('QUANTITY');
13903
13904 IF (g_asn_debug = 'Y') THEN
13905 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
13906 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
13907 asn_debug.put_line('Need to insert into po_interface_errors');
13908 END IF;
13909 END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
13910
13911 IF (g_asn_debug = 'Y') THEN
13912 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
13913 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
13914 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
13915 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
13916 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
13917 END IF;
13918 END IF; --}
13919 END IF; --}
13920
13921 IF ( ( (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH'))
13922 AND x_qty_rcv_exception_code = 'REJECT')
13923 OR (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH'))) THEN --{
13924 IF (g_asn_debug = 'Y') THEN
13925 asn_debug.put_line('Extra ASN UOM Quantity ' || TO_CHAR(x_remaining_quantity));
13926 asn_debug.put_line('Extra PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
13927 END IF;
13928
13929 IF (g_asn_debug = 'Y') THEN
13930 asn_debug.put_line('delete the temp table ');
13931 END IF;
13932
13933 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13934
13935 -- <Bug 9342280 : Added for CLM project>
13936 IF (x_po_correctrec.parent_transaction_type IN ('RECEIVE', 'MATCH', 'DELIVER')) AND
13937 (l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y') THEN
13938
13939 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_CLM_FUNDED', x_cascaded_table(n).error_message);
13940 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
13941 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
13942
13943 ELSE
13944 -- <CLM END>
13945
13946 rcv_error_pkg.set_error_message('RCV_CORRECT_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
13947 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
13948 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
13949
13950 END IF; -- <Bug 9342280 : Added for CLM project>
13951
13952 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
13953
13954 IF temp_cascaded_table.COUNT > 0 THEN
13955 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
13956 temp_cascaded_table.DELETE(i);
13957 END LOOP;
13958 END IF;
13959
13960 IF (g_asn_debug = 'Y') THEN
13961 asn_debug.put_line('mark the actual table with error status');
13962 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
13963 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
13964 END IF;
13965
13966 IF (g_asn_debug = 'Y') THEN
13967 asn_debug.put_line('Need to insert a row into po_interface_errors');
13968 END IF;
13969 END IF; --} matches if(none/warning) and elseif(reject)
13970 END IF; --}
13971
13972 IF (SIGN(x_cascaded_table(current_n).quantity) = -1) THEN --{
13973 /* for correct,accept an reject type we dont have the
13974 * tolerance check. Hence error out.
13975 * We cannot correct quantities more than that was received.
13976 */
13977 IF (g_asn_debug = 'Y') THEN
13978 asn_debug.put_line(' in correct extra Quantity ' || TO_CHAR(x_remaining_quantity));
13979 END IF;
13980
13981 IF (g_asn_debug = 'Y') THEN
13982 asn_debug.put_line('delete the temp table ');
13983 END IF;
13984 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13985 rcv_error_pkg.set_error_message('RCV_CORRECT_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
13986 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(current_n).quantity);
13987 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity);
13988 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
13989
13990 IF temp_cascaded_table.COUNT > 0 THEN
13991 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
13992 temp_cascaded_table.DELETE(i);
13993 END LOOP;
13994 END IF;
13995
13996 IF (g_asn_debug = 'Y') THEN
13997 asn_debug.put_line('mark the actual table with error status');
13998 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
13999 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
14000 END IF;
14001
14002 IF (g_asn_debug = 'Y') THEN
14003 asn_debug.put_line('Need to insert a row into po_interface_errors for correct');
14004 END IF;
14005 END IF; --}
14006 ELSE --}{ else for rows fetched = 0 OR x_first_trans = true
14007 IF rows_fetched = 0 THEN
14008 IF (g_asn_debug = 'Y') THEN
14009 asn_debug.put_line('No rows were retrieved from cursor.');
14010 END IF;
14011 ELSIF x_first_trans THEN
14012 IF (g_asn_debug = 'Y') THEN
14013 asn_debug.put_line('No rows were cascaded');
14014 END IF;
14015 END IF;
14016
14017 x_temp_count := 1;
14018 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14019
14020 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
14021 /* Give an error just like it is done for the
14022 * the receipt transaction;
14023 */
14024 SELECT parent_transaction_id,
14025 transaction_type,
14026 po_line_location_id,
14027 destination_type_code,
14028 source_document_code
14029 INTO l_grand_parent_trx_id,
14030 l_transaction_type,
14031 l_line_loc_id,
14032 l_destination_type_code,
14033 l_source_document_code
14034 FROM rcv_transactions rt
14035 WHERE rt.transaction_id = temp_cascaded_table(current_n).parent_transaction_id;
14036
14037 IF (l_transaction_type = 'DELIVER') THEN --{
14038 IF ( l_destination_type_code = 'INVENTORY'
14039 OR l_source_document_code IN('REQ', 'INVENTORY', 'RMA')) THEN
14040 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14041 rcv_error_pkg.set_error_message('RCV_INVAL_SOURCE_DOC_FOR_DEL', x_cascaded_table(n).error_message);
14042 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14043 END IF;
14044 END IF; --}
14045
14046 IF (l_transaction_type = 'UNORDERED') THEN --{
14047 SELECT MAX('record_exist')
14048 INTO l_exist
14049 FROM rcv_transactions rt2
14050 WHERE rt2.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
14051 AND rt2.transaction_type = 'MATCH';
14052
14053 SELECT MAX('record_exist')
14054 INTO l_exist1
14055 FROM rcv_transactions_interface rti
14056 WHERE rti.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
14057 AND rti.transaction_type = 'MATCH';
14058
14059 IF l_exist = 'record_exist' THEN --{
14060 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14061 rcv_error_pkg.set_error_message('RCV_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
14062 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14063 END IF; --}
14064
14065 IF l_exist1 = 'record_exist' THEN --{
14066 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14067 rcv_error_pkg.set_error_message('RCV_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
14068 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14069 END IF; --}
14070 END IF; --}
14071
14072 IF (l_transaction_type = 'RETURN TO VENDOR') THEN --{
14073 SELECT MAX('record_exist')
14074 INTO l_exist
14075 FROM rcv_transactions rt2,
14076 rcv_transactions rt3
14077 WHERE rt2.transaction_id = l_grand_parent_trx_id
14078 AND rt2.transaction_type = 'UNORDERED'
14079 AND rt3.transaction_type = 'MATCH'
14080 AND rt3.parent_transaction_id = rt2.transaction_id;
14081
14082 SELECT MAX('record_exist')
14083 INTO l_exist1
14084 FROM rcv_transactions rt2,
14085 rcv_transactions_interface rti
14086 WHERE rt2.transaction_id = l_grand_parent_trx_id
14087 AND rt2.transaction_type = 'UNORDERED'
14088 AND rti.transaction_type = 'MATCH'
14089 AND rti.parent_transaction_id = rt2.transaction_id;
14090
14091 IF l_exist = 'record_exist' THEN --{
14092 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14093 rcv_error_pkg.set_error_message('RCV_RET_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
14094 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14095 END IF; --}
14096
14097 IF l_exist1 = 'record_exist' THEN --{
14098 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14099 rcv_error_pkg.set_error_message('RCV_RET_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
14100 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14101 END IF; --}
14102 END IF; --}
14103
14104 SELECT MAX('record_exist')
14105 INTO l_exist2
14106 FROM po_line_locations pll
14107 WHERE pll.line_location_id = l_line_loc_id
14108 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
14109 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED');
14110
14111 IF l_exist2 = 'record_exist' THEN
14112 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14113 rcv_error_pkg.set_error_message('RCV_PO_SHIPMENT_CANCELLED', x_cascaded_table(n).error_message);
14114 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14115 END IF;
14116 END IF; --}
14117
14118 -- Delete the temp_cascaded_table just to be sure
14119
14120 IF temp_cascaded_table.COUNT > 0 THEN
14121 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
14122 temp_cascaded_table.DELETE(i);
14123 END LOOP;
14124 END IF;
14125 END IF; --}
14126 ELSE -- }{
14127 IF (g_asn_debug = 'Y') THEN
14128 asn_debug.put_line('Remaining UOM quantity is zero ' || TO_CHAR(x_remaining_quantity));
14129 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
14130 END IF;
14131 END IF; --} ends the check for whether last record has been reached
14132
14133 -- close cursors
14134
14135 IF (g_asn_debug = 'Y') THEN
14136 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions ' || current_n);
14137 END IF;
14138
14139 IF po_correct%ISOPEN THEN
14140 CLOSE po_correct;
14141 END IF;
14142
14143 IF po_correct_rti%ISOPEN THEN
14144 CLOSE po_correct_rti;
14145 END IF;
14146
14147 IF (g_asn_debug = 'Y') THEN
14148 asn_debug.put_line('before exit current_n is ' || current_n);
14149 END IF;
14150
14151 EXIT;
14152 END IF; --} matches lastrecord or x_remaining_quantity <= 0
14153
14154 -- bug fix 5269121 :it is wrong to
14155 --copy the parents unit of measure into the childs unit of measure, as this will be the one
14156 --which will be finally populated into RT for the child record (correction record).
14157 --temp_cascaded_table(current_n).unit_of_measure := x_po_correctrec.unit_of_meas;
14158
14159 IF (g_asn_debug = 'Y') THEN
14160 asn_debug.put_line(' Entering qty calculation for correct');
14161 END IF;
14162
14163 IF (x_first_trans)
14164 AND temp_cascaded_table(current_n).item_id IS NULL THEN
14165 temp_cascaded_table(current_n).item_id := x_po_correctrec.item_id;
14166 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_correctrec.primary_unit_of_measure;
14167 END IF;
14168
14169 insert_into_table := FALSE;
14170 already_allocated_qty := 0;
14171
14172 IF (g_asn_debug = 'Y') THEN
14173 asn_debug.put_line('calling Correct get_available_qty ' || x_po_correctrec.parent_transaction_type);
14174 END IF;
14175
14176 get_interface_available_qty(temp_cascaded_table,
14177 current_n,
14178 x_converted_parent_trx_qty
14179 );
14180
14181 IF (g_asn_debug = 'Y') THEN
14182 asn_debug.put_line('correct interface_available_qty ' || x_converted_parent_trx_qty);
14183 END IF;
14184
14185 /* x_converted_parent_trx_qty will be 0 when this is not a child
14186 * transaction to any rti row. Also for correct, grand parent
14187 * may already be processed and for positive correction we
14188 * might need to get the quantity from the grand parent.
14189 */
14190 IF (x_converted_parent_trx_qty = 0) THEN --{
14191 IF (g_asn_debug = 'Y') THEN
14192 asn_debug.put_line('interface qty is 0');
14193 END IF;
14194
14195 IF (SIGN(temp_cascaded_table(current_n).quantity) = -1) THEN --{
14196 rcv_quantities_s.get_available_quantity('CORRECT',
14197 x_po_correctrec.rcv_transaction_id,
14198 'VENDOR',
14199 x_po_correctrec.parent_transaction_type,
14200 NULL,
14201 'NEGATIVE',
14202 x_converted_parent_trx_qty,
14203 x_tolerable_qty,
14204 x_po_correctrec.unit_of_meas,
14205 x_secondary_available_qty
14206 );
14207
14208 /* Bug#5369121 - START */
14209 IF (g_asn_debug = 'Y') THEN
14210 asn_debug.put_line('x_converted_parent_trx_qty:' || x_converted_parent_trx_qty);
14211 asn_debug.put_line('transaction_quantity:' || temp_cascaded_table(current_n).quantity);
14212 END IF;
14213
14214 IF (x_converted_parent_trx_qty < ABS(temp_cascaded_table(current_n).quantity)) THEN
14215
14216 SELECT rt.unit_of_measure,
14217 rsl.item_id,
14218 rt.primary_unit_of_measure
14219 INTO l_transaction_uom,
14220 l_item_id,
14221 l_primary_uom
14222 FROM rcv_transactions rt,
14223 rcv_shipment_lines rsl
14224 WHERE rsl.shipment_line_id = rt.shipment_line_id
14225 AND rt.transaction_id = x_po_correctrec.rcv_transaction_id;
14226
14227 SELECT NVL(SUM(interface_transaction_qty),0)
14228 INTO l_interface_quantity
14229 FROM rcv_transactions_interface
14230 WHERE (transaction_status_code = 'PENDING'
14231 AND processing_status_code <> 'ERROR')
14232 --bug# 9583207 to comment group_id condition
14233 --AND group_id = temp_cascaded_table(current_n).group_id
14234 AND transaction_type = 'CORRECT'
14235 AND parent_transaction_id IN ( SELECT transaction_id
14236 FROM rcv_transactions
14237 WHERE parent_transaction_id = x_po_correctrec.rcv_transaction_id);
14238
14239 IF (l_interface_quantity = 0) THEN
14240
14241 /*
14242 ** There is no unprocessed quantity. Simply set the
14243 ** x_interface_qty_in_trx_uom to 0. There is no need for uom
14244 ** conversion.
14245 */
14246
14247 l_interface_qty_in_trx_uom := 0;
14248
14249 ELSE
14250
14251 /*
14252 ** There is unprocessed quantity. Convert it to the transaction uom
14253 ** so that the available quantity can be calculated in the trx uom
14254 */
14255 IF (g_asn_debug = 'Y') THEN
14256 asn_debug.put_line('Before uom_convert:');
14257 asn_debug.put_line('l_interface_quantity' || l_interface_quantity);
14258 asn_debug.put_line('l_primary_uom' || l_primary_uom);
14259 asn_debug.put_line('l_transaction_uom' || l_transaction_uom);
14260 asn_debug.put_line('l_item_id' || l_item_id);
14261 END IF;
14262
14263 po_uom_s.uom_convert(l_interface_quantity, l_primary_uom, l_item_id,
14264 l_transaction_uom, l_interface_qty_in_trx_uom);
14265
14266 END IF;
14267
14268 x_converted_parent_trx_qty := x_converted_parent_trx_qty - l_interface_qty_in_trx_uom;
14269
14270 IF (g_asn_debug = 'Y') THEN
14271 asn_debug.put_line('x_converted_parent_trx_qty:' || x_converted_parent_trx_qty);
14272 END IF;
14273
14274 END IF;
14275 /* Bug#5369121 - END */
14276 ELSE --}{
14277 IF (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH', 'UNORDERED')) THEN
14278 l_grand_parent_trx_id := x_po_correctrec.grand_parent_txn_id;
14279 ELSIF(x_po_correctrec.parent_transaction_type IN('MATCH', 'RECEIVE')) THEN
14280 IF (temp_cascaded_table(current_n).parent_transaction_id IS NOT NULL) THEN
14281 l_grand_parent_trx_id := x_po_correctrec.po_line_location_id;
14282 ELSIF(temp_cascaded_table(current_n).parent_interface_txn_id IS NOT NULL) THEN
14283 /* We would have the value derived in the x_cascaded_table
14284 * but not have inserted it back into rti.
14285 */
14286 l_grand_parent_trx_id := temp_cascaded_table(current_n).po_line_location_id;
14287 END IF;
14288 ELSIF(x_po_correctrec.parent_transaction_type = 'UNORDERED') THEN
14289 l_grand_parent_trx_id := x_po_correctrec.rcv_transaction_id;
14290 END IF;
14291
14292 IF (l_grand_parent_trx_id IS NOT NULL) THEN
14293 rcv_quantities_s.get_available_quantity('CORRECT',
14294 x_po_correctrec.rcv_transaction_id,
14295 'VENDOR',
14296 x_po_correctrec.parent_transaction_type,
14297 l_grand_parent_trx_id,
14298 'POSITIVE',
14299 x_converted_parent_trx_qty,
14300 x_tolerable_qty,
14301 x_po_correctrec.unit_of_meas,
14302 x_secondary_available_qty
14303 );
14304 END IF;
14305 END IF; --}
14306 END IF; --} -- interface_available_qty is 0.
14307
14308 IF (g_asn_debug = 'Y') THEN
14309 asn_debug.put_line('qty from GET_AVAILABLE_QUANTITY for correct is ' || x_converted_parent_trx_qty);
14310 asn_debug.put_line('tolerable qty from GET_AVAILABLE_QUANTITY for correct is ' || x_tolerable_qty);
14311 END IF;
14312
14313 IF (x_remaining_quantity = 0) THEN
14314 IF (g_asn_debug = 'Y') THEN
14315 asn_debug.put_line(' correct Need an error message in the interface tables');
14316 END IF;
14317 ELSE
14318 /* Converted successfully and have some quantity on which we can act */
14319 IF (g_asn_debug = 'Y') THEN
14320 asn_debug.put_line('Converted trx qty that is available ' || x_converted_parent_trx_qty);
14321 asn_debug.put_line('Remaining qty in parents uom that is available ' || x_remaining_quantity);
14322 END IF;
14323
14324 /* x_tolerable_quantity will be > 0 only for correction
14325 * against a receive transcation.
14326 */
14327 IF ( (SIGN(temp_cascaded_table(current_n).quantity) = 1)
14328 AND (x_tolerable_qty > 0)) THEN --{
14329 x_converted_parent_trx_qty := x_tolerable_qty;
14330
14331 IF (g_asn_debug = 'Y') THEN
14332 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_parent_trx_qty));
14333 END IF;
14334 END IF; --}
14335
14336 IF (g_asn_debug = 'Y') THEN
14337 asn_debug.put_line('x_converted_parent_trx_qty : ' || TO_CHAR(x_converted_parent_trx_qty));
14338 END IF;
14339
14340 IF (x_converted_parent_trx_qty > 0) THEN --{
14341 /* Compare with abs(x_remaining_qty) here since we want
14342 * to make sure that the qty we have is greater than
14343 * the available qty irrespective of whether this is
14344 * positive or negative correction.
14345 */
14346 IF (x_converted_parent_trx_qty < ABS(x_remaining_quantity)) THEN --{
14347 /* Total quantity available to correct is less than the qty
14348 * that the user wants to correct. Hence we would error out but
14349 * to keep the old code we will get the remaining code here and
14350 * error out later.
14351 */
14352 x_remaining_quantity := x_remaining_quantity - SIGN(temp_cascaded_table(current_n).quantity) * x_converted_parent_trx_qty;
14353 x_converted_parent_trx_qty := SIGN(temp_cascaded_table(current_n).quantity) * x_converted_parent_trx_qty;
14354
14355 IF (g_asn_debug = 'Y') THEN
14356 asn_debug.put_line('remaning qty after allocation is : ' || TO_CHAR(x_remaining_quantity));
14357 END IF;
14358
14359 insert_into_table := TRUE;
14360 ELSE --}{
14361 IF (g_asn_debug = 'Y') THEN
14362 asn_debug.put_line('We are in >= Qty branch ');
14363 END IF;
14364
14365 x_converted_parent_trx_qty := x_remaining_quantity;
14366 insert_into_table := TRUE;
14367 x_remaining_quantity := 0;
14368 END IF; --} /* if (x_converted_parent_trx_qty < x_remaining_quantity) then */
14369 ELSE /* x_converted_parent_trx_qty >0 */ --}{
14370
14371 -- so that the row can be used based on qty tolerance
14372 -- checks
14373 IF (g_asn_debug = 'Y') THEN
14374 asn_debug.put_line('Quantity is less then 0 but last record');
14375 END IF;
14376
14377 insert_into_table := TRUE;
14378 x_converted_parent_trx_qty := 0;
14379 END IF; /*x_converted_parent_trx_qty >0 */ --}
14380 END IF; --} just added this
14381
14382 /* Converted qty successfully and we have some quantity on which we can act */
14383 IF (g_asn_debug = 'Y') THEN
14384 asn_debug.put_line('Transaction qty in terms of the parents uom is ' || x_converted_parent_trx_qty);
14385 END IF;
14386
14387 IF insert_into_table THEN --{
14388 IF (x_first_trans) THEN --{
14389 IF (g_asn_debug = 'Y') THEN
14390 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
14391 END IF;
14392
14393 x_first_trans := FALSE;
14394 ELSE --}{
14395 IF (g_asn_debug = 'Y') THEN
14396 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
14397 END IF;
14398
14399 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
14400 END IF; --}
14401
14402 temp_cascaded_table(current_n).po_header_id := x_po_correctrec.po_head_id;
14403 temp_cascaded_table(current_n).po_line_id := x_po_correctrec.line_id;
14404 temp_cascaded_table(current_n).po_line_location_id := x_po_correctrec.po_line_location_id;
14405 temp_cascaded_table(current_n).po_distribution_id := x_po_correctrec.po_distribution_id;
14406 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_correctrec.primary_unit_of_measure;
14407 temp_cascaded_table(current_n).quantity := x_converted_parent_trx_qty;
14408
14409 IF (temp_cascaded_table(current_n).primary_unit_of_measure <> x_po_correctrec.unit_of_meas) THEN
14410 temp_cascaded_table(current_n).primary_quantity := convert_into_correct_qty(x_converted_parent_trx_qty,
14411 x_po_correctrec.unit_of_meas,
14412 temp_cascaded_table(current_n).item_id,
14413 temp_cascaded_table(current_n).primary_unit_of_measure
14414 );
14415 ELSE
14416 temp_cascaded_table(current_n).primary_quantity := x_converted_parent_trx_qty;
14417 END IF;
14418
14419 IF (g_asn_debug = 'Y') THEN
14420 asn_debug.put_line('Transaction qty in terms of the primary uom is ' || temp_cascaded_table(current_n).primary_quantity);
14421 END IF;
14422
14423 current_n := current_n + 1;
14424
14425 IF (g_asn_debug = 'Y') THEN
14426 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
14427 END IF;
14428 END IF; --}
14429 /* Get the available qty in PRIMARY UOM */
14430 /*
14431 PO_UOM_S.UOM_CONVERT (x_converted_trx_qty,
14432 l_uom,
14433 x_item_id,
14434 x_primary_uom,
14435 l_primary_available_qty );
14436 */
14437 END LOOP; --}
14438 ELSE --} {
14439 -- error_status and error_message are set after validate_quantity_shipped
14440 IF (g_asn_debug = 'Y') THEN
14441 asn_debug.put_line('No po_header_id/item_id ');
14442 END IF;
14443
14444 IF (g_asn_debug = 'Y') THEN
14445 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
14446 END IF;
14447
14448 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
14449 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14450
14451 IF (x_cascaded_table(n).error_message IS NULL) THEN
14452 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION', x_cascaded_table(n).error_message);
14453 END IF;
14454
14455 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID');
14456 END IF; --}
14457
14458 RETURN;
14459 END IF; -- } of (asn quantity_shipped was valid)
14460
14461 IF (g_asn_debug = 'Y') THEN
14462 asn_debug.put_line('before closing cursors current_n is ' || temp_cascaded_table.COUNT);
14463 END IF;
14464
14465 IF po_correct%ISOPEN THEN
14466 CLOSE po_correct;
14467 END IF;
14468
14469 IF po_correct_rti%ISOPEN THEN
14470 CLOSE po_correct_rti;
14471 END IF;
14472
14473 IF (g_asn_debug = 'Y') THEN
14474 asn_debug.put_line('Exit explode_line_quantity');
14475 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
14476 END IF;
14477 EXCEPTION
14478 WHEN OTHERS THEN
14479 IF (g_asn_debug = 'Y') THEN
14480 asn_debug.put_line('Exception in derive_correction_line_quantity ');
14481 END IF;
14482
14483 IF po_correct%ISOPEN THEN
14484 CLOSE po_correct;
14485 END IF;
14486
14487 IF po_correct_rti%ISOPEN THEN
14488 CLOSE po_correct_rti;
14489 END IF;
14490
14491 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14492 rcv_error_pkg.set_sql_error_message('derive_correction_line_qty', x_progress);
14493 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14494 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14495
14496 IF (g_asn_debug = 'Y') THEN
14497 asn_debug.put_line(TO_CHAR(n));
14498 asn_debug.put_line(SQLERRM);
14499 asn_debug.put_line('error ' || x_progress);
14500 END IF;
14501 END derive_correction_line_qty;
14502
14503 PROCEDURE derive_correction_line_amt(
14504 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14505 n IN OUT NOCOPY BINARY_INTEGER,
14506 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type
14507 ) IS
14508 x_include_closed_po VARCHAR2(1); -- Bug 1887728
14509 /*
14510 ** Might be a compatibility issue between the two record definitions
14511 */
14512 x_record_count NUMBER;
14513 x_remaining_amount NUMBER := 0;
14514 x_progress VARCHAR2(3);
14515 x_to_organization_code VARCHAR2(5);
14516 x_converted_trx_amt NUMBER := 0;
14517 transaction_ok BOOLEAN := FALSE;
14518 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
14519 high_range_date DATE;
14520 low_range_date DATE;
14521 rows_fetched NUMBER := 0;
14522 x_tolerable_amt NUMBER := 0;
14523 x_first_trans BOOLEAN := TRUE;
14524 x_sysdate DATE := SYSDATE;
14525 current_n BINARY_INTEGER := 0;
14526 insert_into_table BOOLEAN := FALSE;
14527 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
14528 tax_amount_factor NUMBER;
14529 lastrecord BOOLEAN := FALSE;
14530 already_allocated_amt NUMBER := 0;
14531 x_item_id NUMBER;
14532 x_approved_flag VARCHAR(1);
14533 x_cancel_flag VARCHAR(1);
14534 x_closed_code VARCHAR(25);
14535 x_shipment_type VARCHAR(25);
14536 x_temp_count NUMBER;
14537 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
14538 profile_user_id NUMBER := -1;
14539 profile_appl_id NUMBER := -1;
14540 profile_resp_id NUMBER := -1;
14541 defined BOOLEAN;
14542 x_sob_id NUMBER := NULL;
14543 x_rate NUMBER;
14544 x_allow_rate_override VARCHAR2(1);
14545
14546 /********************************************************************/
14547 CURSOR po_correct(
14548 v_parent_trx_id NUMBER,
14549 v_to_organization_id NUMBER
14550 ) IS
14551 SELECT rt.po_line_location_id,
14552 rt.po_header_id,
14553 rt.po_line_id,
14554 rt.transaction_id rcv_transaction_id,
14555 rt.parent_transaction_id grand_parent_txn_id,
14556 poh.segment1 document_num,
14557 pol.line_num line_number,
14558 rt.transaction_date transaction_date,
14559 rt.transaction_type parent_transaction_type,
14560 rt.amount,
14561 rt.organization_id,
14562 rt.location_id,
14563 rsl.job_id,
14564 rt.deliver_to_person_id,
14565 rt.deliver_to_location_id,
14566 rt.po_distribution_id,
14567 rt.destination_type_code,
14568 rsl.ussgl_transaction_code
14569 FROM rcv_transactions rt,
14570 rcv_shipment_lines rsl,
14571 po_headers poh,
14572 po_lines pol
14573 WHERE rt.transaction_id = v_parent_trx_id
14574 AND rt.organization_id = NVL(v_to_organization_id, rt.organization_id)
14575 AND ( rt.transaction_type IN('RECEIVE', 'TRANSFER', 'ACCEPT', 'REJECT', 'MATCH')
14576 OR ( rt.transaction_type IN('RETURN TO VENDOR', 'RETURN TO CUSTOMER')
14577 AND NOT EXISTS(SELECT 'rtv to processed matched unordered receipt'
14578 FROM rcv_transactions rt2,
14579 rcv_transactions rt3
14580 WHERE rt2.transaction_id = rt.parent_transaction_id
14581 AND rt2.transaction_type = 'UNORDERED'
14582 AND rt3.transaction_type = 'MATCH'
14583 AND rt3.parent_transaction_id = rt2.transaction_id)
14584 AND NOT EXISTS(SELECT 'rtv to unprocessed matched unordered receipt'
14585 FROM rcv_transactions rt2,
14586 rcv_transactions_interface rti
14587 WHERE rt2.transaction_id = rt.parent_transaction_id
14588 AND rt2.transaction_type = 'UNORDERED'
14589 AND rti.transaction_type = 'MATCH'
14590 AND rti.parent_transaction_id = rt2.transaction_id)
14591 )
14592 OR ( rt.transaction_type = 'DELIVER'
14593 AND NOT( rt.destination_type_code = 'INVENTORY'
14594 AND rt.source_document_code IN('REQ', 'INVENTORY', 'RMA')))
14595 OR ( rt.transaction_type = 'UNORDERED'
14596 AND NOT EXISTS(SELECT 'processed matched rows'
14597 FROM rcv_transactions rt2
14598 WHERE rt2.parent_transaction_id = rt.transaction_id
14599 AND rt2.transaction_type = 'MATCH')
14600 AND NOT EXISTS(SELECT 'unprocessed matched rows'
14601 FROM rcv_transactions_interface rti
14602 WHERE rti.parent_transaction_id = rt.transaction_id
14603 AND rti.transaction_type = 'MATCH')
14604 )
14605 )
14606 AND NOT EXISTS(SELECT 'purchase order shipment cancelled or fc'
14607 FROM po_line_locations pll
14608 WHERE pll.line_location_id = rt.po_line_location_id
14609 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
14610 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED'))
14611 AND (rt.shipment_line_id = rsl.shipment_line_id)
14612 AND (poh.po_header_id = rt.po_header_id)
14613 AND (pol.po_line_id = rt.po_line_id)
14614 ORDER BY rt.transaction_id;
14615
14616 CURSOR po_correct_rti(
14617 v_parent_interface_txn_id NUMBER
14618 ) IS
14619 SELECT rti.po_line_location_id,
14620 rti.po_header_id,
14621 rti.po_line_id,
14622 rti.interface_transaction_id rcv_transaction_id,
14623 rti.parent_transaction_id grand_parent_txn_id,
14624 rti.document_num,
14625 rti.document_line_num line_number,
14626 rti.transaction_date transaction_date,
14627 rti.transaction_type parent_transaction_type,
14628 rti.amount,
14629 rti.to_organization_id organization_id,
14630 rti.location_id,
14631 rti.job_id,
14632 rti.deliver_to_person_id,
14633 rti.deliver_to_location_id,
14634 rti.po_distribution_id,
14635 rti.destination_type_code,
14636 rti.ussgl_transaction_code
14637 FROM rcv_transactions_interface rti
14638 WHERE interface_transaction_id = v_parent_interface_txn_id;
14639
14640 x_po_correctrec po_correct%ROWTYPE;
14641 x_temp_parent_trx_amt NUMBER := 0;
14642 x_converted_parent_trx_amt NUMBER := 0;
14643 x_temp_convert_parent_trx_amt NUMBER := 0;
14644 l_to_organization_id NUMBER := 0;
14645 l_transaction_type rcv_transactions.transaction_type%TYPE;
14646 x_temp_already_allocated_qty NUMBER := 0;
14647 derive_values_from_table BOOLEAN := FALSE;
14648 derive_values_from_rti BOOLEAN := FALSE;
14649 already_derived BOOLEAN := FALSE;
14650 cascaded_table_index NUMBER;
14651 l_grand_parent_trx_id rcv_transactions.parent_transaction_id%TYPE;
14652 temp_index NUMBER;
14653 l_line_loc_id po_line_locations.line_location_id%TYPE;
14654 l_exist VARCHAR2(30);
14655 l_exist1 VARCHAR2(30);
14656 l_exist2 VARCHAR2(30);
14657 l_destination_type_code rcv_transactions.destination_type_code%TYPE;
14658 l_source_document_code rcv_transactions.source_document_code%TYPE;
14659 l_time_count NUMBER;
14660
14661 -- <Bug 9342280 : Added for CLM project>
14662 l_is_clm_po VARCHAR2(5) := 'N';
14663 l_partial_funded_flag VARCHAR2(5) := 'N';
14664 -- <CLM END>
14665 BEGIN
14666 IF (g_asn_debug = 'Y') THEN
14667 asn_debug.put_line('enter derive_amount ' || x_cascaded_table(n).parent_transaction_id);
14668 END IF;
14669
14670 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
14671 already_derived := TRUE;
14672 END IF; --}
14673
14674 IF ( NOT already_derived
14675 AND (x_cascaded_table(n).parent_interface_txn_id IS NULL)
14676 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN --{
14677 /* This means that there can be a row in RT with src_txn_id
14678 * populated or it can be a child.
14679 */
14680 BEGIN
14681 SELECT transaction_id
14682 INTO x_cascaded_table(n).parent_transaction_id
14683 FROM rcv_transactions
14684 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
14685
14686 already_derived := TRUE;
14687 EXCEPTION
14688 -- Bug 7651646
14689 WHEN NO_DATA_FOUND THEN
14690 rcv_error_pkg.set_error_message('RCV_NO_PARENT_SRC_TRANSACTION');
14691 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
14692 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14693 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14694 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14695
14696 WHEN TOO_MANY_ROWS THEN
14697 rcv_error_pkg.set_error_message('RCV_DUP_SRC_TRANSACTION');
14698 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).parent_source_transaction_num);
14699 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14700 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14701 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
14702 END;
14703 END IF; --}
14704
14705 IF already_derived THEN --{
14706 IF (g_asn_debug = 'Y') THEN
14707 asn_debug.put_line(' open po_correct table ' || x_cascaded_table(n).parent_transaction_id);
14708 END IF;
14709
14710 OPEN po_correct(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
14711 END IF; ---}
14712
14713 IF (NOT already_derived) THEN --{
14714 derive_parent_id(x_cascaded_table, n);
14715
14716 /* This means that there was no error in
14717 * derive_parent_id which means that the
14718 * this is a child and need to get the values
14719 * from the rti and not from the plsql table.
14720 */
14721 IF ( (x_cascaded_table(n).error_status <> 'E')
14722 AND ( x_cascaded_table(n).derive = 'Y'
14723 AND x_cascaded_table(n).derive_index = 0)) THEN
14724 /* if derive_values_from_table is true, then we
14725 * derive the values from the pl/sql tables later
14726 * at the time when we try to see which cursor is open.
14727 * We will have x_cascaded_table(n).
14728 * parent_interface_txn_id) populated with teh
14729 * correct value.
14730 */
14731 IF (g_asn_debug = 'Y') THEN
14732 asn_debug.put_line(' open correct cursor from rti');
14733 END IF;
14734
14735 OPEN po_correct_rti(x_cascaded_table(n).parent_interface_txn_id);
14736 END IF;
14737 END IF; --}
14738
14739 /******************************************************************/
14740 --check line amount > 0
14741 x_progress := '097';
14742
14743 IF (g_asn_debug = 'Y') THEN
14744 asn_debug.put_line('X_progress ' || x_progress);
14745 END IF;
14746 /* Bug 6610047.
14747 * To allow corrections to timecards with zero amounts.
14748 * Commented the validation which checks for zero amount on the correction.
14749
14750 /* IF x_cascaded_table(n).error_status IN('S', 'W')
14751 AND x_cascaded_table(n).amount = 0 THEN --{
14752 IF (g_asn_debug = 'Y') THEN
14753 asn_debug.put_line('Amount is <= zero. Cascade will fail');
14754 END IF;
14755
14756 x_cascaded_table(n).error_status := 'F';
14757 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
14758 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
14759 END IF; --} end qty > 0 check
14760 */
14761 -- the following steps will create a set of rows linking the line_record with
14762 -- its corresponding po_line_location rows until the quantity value from
14763 -- the asn is consumed. (Cascade)
14764
14765 /* 2119137 : If the user populates rcv_transactions_interface
14766 with po_line_id, then ROI errors out with
14767 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
14768 is not provided for one time items. Modified the "if" criteria in
14769 such a way that the ROI validation does'nt error out when
14770 po_line_id is populated for one time items. */
14771 x_progress := '098';
14772
14773 IF (g_asn_debug = 'Y') THEN
14774 asn_debug.put_line('X_progress ' || x_progress);
14775 END IF;
14776
14777 IF ( ( x_cascaded_table(n).parent_transaction_id IS NOT NULL
14778 OR x_cascaded_table(n).parent_interface_txn_id IS NOT NULL)
14779 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
14780
14781 -- Copy record from main table to temp table
14782 IF (g_asn_debug = 'Y') THEN
14783 asn_debug.put_line('Copy record from main table to temp table');
14784 END IF;
14785
14786 current_n := 1;
14787 temp_cascaded_table(current_n) := x_cascaded_table(n);
14788
14789 -- Get all rows which meet this condition
14790 IF (g_asn_debug = 'Y') THEN
14791 asn_debug.put_line('Get all rows which meet this condition');
14792 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
14793 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
14794 END IF;
14795
14796 -- Assign shipped amount to remaining amount
14797 IF (g_asn_debug = 'Y') THEN
14798 asn_debug.put_line('Assign populated amount to remaining amount');
14799 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
14800 END IF;
14801
14802 x_remaining_amount := temp_cascaded_table(current_n).amount;
14803
14804 IF (g_asn_debug = 'Y') THEN
14805 asn_debug.put_line('Have assigned the amount');
14806 END IF;
14807
14808 -- Calculate tax_amount_factor for calculating tax_amount for
14809 -- each cascaded line
14810
14811 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
14812 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_amount;
14813 ELSE
14814 tax_amount_factor := 0;
14815 END IF;
14816
14817 IF (g_asn_debug = 'Y') THEN
14818 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
14819 asn_debug.put_line('transaction amount : ' || TO_CHAR(x_remaining_amount));
14820 END IF;
14821
14822 x_first_trans := TRUE;
14823 transaction_ok := FALSE;
14824
14825 IF (g_asn_debug = 'Y') THEN
14826 asn_debug.put_line('Before starting Cascade');
14827 END IF;
14828
14829 IF (g_asn_debug = 'Y') THEN
14830 asn_debug.put_line('Record Count = ' || x_record_count);
14831 END IF;
14832
14833 LOOP --{
14834 IF (g_asn_debug = 'Y') THEN
14835 asn_debug.put_line('Remaining Quantity ' || TO_CHAR(x_remaining_amount));
14836 END IF;
14837
14838 /*
14839 ** Fetch the appropriate record
14840 */
14841 IF (g_asn_debug = 'Y') THEN
14842 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
14843 END IF;
14844
14845 IF (po_correct%ISOPEN) THEN --{
14846 IF (g_asn_debug = 'Y') THEN
14847 asn_debug.put_line(' fetch po_correct');
14848 END IF;
14849
14850 FETCH po_correct INTO x_po_correctrec;
14851
14852 IF (po_correct%NOTFOUND) THEN
14853 lastrecord := TRUE;
14854 END IF;
14855
14856 rows_fetched := po_correct%ROWCOUNT;
14857 ELSIF(po_correct_rti%ISOPEN) THEN --}{
14858 IF (g_asn_debug = 'Y') THEN
14859 asn_debug.put_line(' fetch po_correct_rti');
14860 END IF;
14861
14862 FETCH po_correct_rti INTO x_po_correctrec;
14863
14864 IF (po_correct_rti%NOTFOUND) THEN
14865 IF (g_asn_debug = 'Y') THEN
14866 asn_debug.put_line('correct last row');
14867 END IF;
14868
14869 lastrecord := TRUE;
14870 END IF;
14871
14872 rows_fetched := po_correct_rti%ROWCOUNT;
14873 ELSIF(temp_cascaded_table(current_n).derive = 'Y') THEN --}{
14874 /* GET VALUES FROM THE PLSQL TABLE */
14875 /* Populate x_po_correctrec with these values since
14876 * we are using x_po_correctrec later.
14877 * We have temp_cascaded_table(current_n).
14878 * parent_interface_txn_id) populated with
14879 * with the correct value. Also we have cascaded_table_index
14880 * with the correct pl/sql table index number;
14881 */
14882 IF (g_asn_debug = 'Y') THEN
14883 asn_debug.put_line(' fetch pl/sql table');
14884 END IF;
14885
14886 temp_index := temp_cascaded_table(current_n).derive_index;
14887 x_po_correctrec.po_line_location_id := x_cascaded_table(temp_index).po_line_location_id;
14888 x_po_correctrec.po_header_id := x_cascaded_table(temp_index).po_header_id;
14889 x_po_correctrec.po_line_id := x_cascaded_table(temp_index).po_line_id;
14890 x_po_correctrec.grand_parent_txn_id := x_cascaded_table(temp_index).parent_transaction_id;
14891 x_po_correctrec.document_num := x_cascaded_table(temp_index).document_num;
14892 x_po_correctrec.line_number := x_cascaded_table(temp_index).document_line_num;
14893 x_po_correctrec.transaction_date := x_cascaded_table(temp_index).transaction_date;
14894 x_po_correctrec.parent_transaction_type := x_cascaded_table(temp_index).transaction_type;
14895 x_po_correctrec.amount := x_cascaded_table(temp_index).amount;
14896 x_po_correctrec.organization_id := x_cascaded_table(temp_index).to_organization_id;
14897 x_po_correctrec.location_id := x_cascaded_table(temp_index).location_id;
14898 x_po_correctrec.job_id := x_cascaded_table(temp_index).job_id;
14899 x_po_correctrec.deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
14900 x_po_correctrec.deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
14901 x_po_correctrec.po_distribution_id := x_cascaded_table(temp_index).po_distribution_id;
14902 x_po_correctrec.destination_type_code := x_cascaded_table(temp_index).destination_type_code;
14903 x_po_correctrec.ussgl_transaction_code := x_cascaded_table(temp_index).ussgl_transaction_code;
14904 /* Also fetch parent transaction type and grand parent trx id into
14905 * the correct variables.
14906 */
14907 rows_fetched := 1;
14908 lastrecord := TRUE;
14909 END IF; --}
14910
14911 IF (g_asn_debug = 'Y') THEN
14912 asn_debug.put_line('Correct Rows fetched ' || TO_CHAR(rows_fetched));
14913 asn_debug.put_line('po_line_id ' || TO_CHAR(x_po_correctrec.po_line_id));
14914 asn_debug.put_line('po_dist ' || TO_CHAR(x_po_correctrec.po_distribution_id));
14915 asn_debug.put_line('correct remainaing amount ' || x_remaining_amount);
14916 END IF;
14917
14918 /* Support for RATE based from OTL */
14919 IF ( x_cascaded_table(n).value_basis = 'RATE'
14920 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR') THEN --{
14921 IF (g_asn_debug = 'Y') THEN
14922 asn_debug.put_line('Rate/Temp Labor');
14923 END IF;
14924
14925 /* Bug 3648861.
14926 * The where condition has
14927 * and pol.po_line_id=po_line_id.
14928 * It should be
14929 * and pol.po_line_id=x_cascaded_table(n).po_line_id
14930 * Changed the condition.
14931 */
14932 SELECT COUNT(*)
14933 INTO l_time_count
14934 FROM hxc_time_building_blocks bb,
14935 po_lines pol
14936 WHERE bb.time_building_block_id = x_cascaded_table(n).timecard_id
14937 AND bb.object_version_number = x_cascaded_table(n).timecard_ovn
14938 AND bb.SCOPE = 'TIMECARD'
14939 AND bb.resource_type = 'PERSON'
14940 AND bb.resource_id IN(SELECT person_id
14941 FROM per_all_assignments_f
14942 WHERE assignment_type = 'C')
14943 AND pol.po_line_id = x_cascaded_table(n).po_line_id
14944 AND pol.order_type_lookup_code = 'RATE'
14945 AND pol.purchase_basis = 'TEMP LABOR';
14946
14947 IF (g_asn_debug = 'Y') THEN
14948 asn_debug.put_line('count ' || l_time_count);
14949 END IF;
14950
14951 IF (l_time_count = 0) THEN --{
14952 IF (g_asn_debug = 'Y') THEN
14953 asn_debug.put_line('We do not support RATE/TEMP LABOR through ROI unless it comes through OTL');
14954 END IF;
14955
14956 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14957 rcv_error_pkg.set_error_message('RCV_NO_RATE_UNLESS_OTL', x_cascaded_table(n).error_message);
14958 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
14959 END IF; --}
14960 END IF; --}
14961
14962 IF (lastrecord) THEN --{
14963 IF (g_asn_debug = 'Y') THEN
14964 asn_debug.put_line('Hit exit condition');
14965 END IF;
14966
14967 IF NOT x_first_trans THEN
14968 -- x_first_trans has been reset which means some cascade has
14969 -- happened. Otherwise current_n = 1
14970 IF (g_asn_debug = 'Y') THEN
14971 asn_debug.put_line('current_n before is ' || current_n);
14972 END IF;
14973
14974 current_n := current_n - 1;
14975 END IF;
14976
14977 -- do the tolerance act here
14978 IF (g_asn_debug = 'Y') THEN
14979 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
14980 asn_debug.put_line('Check which condition has occured');
14981 END IF;
14982
14983 -- lastrecord...we have run out of rows and we still have quantity to allocate
14984 /* Do abs(x_remaining_quantity) since it can be a negative
14985 * or positive correction.
14986 */
14987 IF ABS(x_remaining_amount) > 0 THEN --{
14988 IF (g_asn_debug = 'Y') THEN
14989 asn_debug.put_line('There is amount remaining ');
14990 asn_debug.put_line('tolerable amount now in plsql table ' || temp_cascaded_table(current_n).amount);
14991 asn_debug.put_line('rows_fetched ' || rows_fetched);
14992 END IF;
14993
14994 IF NOT x_first_trans THEN
14995 IF (g_asn_debug = 'Y') THEN
14996 asn_debug.put_line('not fisrt txn');
14997 END IF;
14998 END IF;
14999
15000 IF rows_fetched > 0
15001 AND NOT x_first_trans THEN --{
15002 IF (g_asn_debug = 'Y') THEN
15003 asn_debug.put_line(' inside transaction_type ' || x_po_correctrec.parent_transaction_type);
15004 END IF;
15005
15006 IF (SIGN(x_cascaded_table(current_n).amount) = 1) THEN --{
15007 IF (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH')) THEN --{
15008 IF (g_asn_debug = 'Y') THEN
15009 asn_debug.put_line('Need to check amount tolerances');
15010 END IF;
15011
15012 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
15013 INTO x_qty_rcv_exception_code
15014 FROM po_line_locations
15015 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
15016
15017 IF (g_asn_debug = 'Y') THEN
15018 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
15019 END IF;
15020
15021 IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
15022 /* Bug# 1807842 */
15023 IF (temp_cascaded_table(current_n).amount <= x_converted_trx_amt) THEN --{
15024 IF (g_asn_debug = 'Y') THEN
15025 asn_debug.put_line('Tolerable quantity ' || TO_CHAR(x_converted_trx_amt));
15026 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).amount));
15027 asn_debug.put_line('Assign remaining amount ' || TO_CHAR(x_remaining_amount) || ' to last record');
15028 END IF;
15029
15030 temp_cascaded_table(current_n).amount := temp_cascaded_table(current_n).amount + x_remaining_amount;
15031 END IF; /* Bug# 1807842 */ --}
15032
15033 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).amount * tax_amount_factor, 6);
15034
15035 IF (g_asn_debug = 'Y') THEN
15036 asn_debug.put_line('Current amount ' || TO_CHAR(temp_cascaded_table(current_n).amount));
15037 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
15038 END IF;
15039
15040 -- <Bug 9342280 : Added for CLM project>
15041 get_clm_info( 'AMOUNT',
15042 x_cascaded_table,
15043 n,
15044 l_is_clm_po,
15045 l_partial_funded_flag);
15046
15047 IF l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y' THEN
15048
15049 x_qty_rcv_exception_code := 'REJECT';
15050
15051 END IF;
15052 --<END CLM>
15053
15054 IF x_qty_rcv_exception_code = 'WARNING' THEN --{
15055 IF (g_asn_debug = 'Y') THEN
15056 asn_debug.put_line('IN WARNING');
15057 END IF;
15058
15059 temp_cascaded_table(current_n).error_status := 'W';
15060 temp_cascaded_table(current_n).error_message := 'RCV_ALL_AMT_OVER_TOLERANCE';
15061
15062 IF (g_asn_debug = 'Y') THEN
15063 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
15064 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
15065 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
15066 END IF;
15067
15068 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
15069 rcv_error_pkg.set_error_message('RCV_ALL_AMT_OVER_TOLERANCE', x_cascaded_table(n).error_message);
15070 rcv_error_pkg.set_token('AMT_A', temp_cascaded_table(current_n).amount);
15071 rcv_error_pkg.set_token('AMT_B', temp_cascaded_table(current_n).amount - x_remaining_amount);
15072 rcv_error_pkg.log_interface_warning('AMOUNT');
15073
15074 IF (g_asn_debug = 'Y') THEN
15075 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
15076 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
15077 asn_debug.put_line('Need to insert into po_interface_errors');
15078 END IF;
15079 END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
15080
15081 IF (g_asn_debug = 'Y') THEN
15082 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).amount));
15083 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
15084 END IF;
15085 END IF; --}
15086 END IF; --}
15087
15088 IF ( ( (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH'))
15089 AND x_qty_rcv_exception_code = 'REJECT')
15090 OR (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH'))) THEN --{
15091 IF (g_asn_debug = 'Y') THEN
15092 asn_debug.put_line('Extra amount ' || TO_CHAR(x_remaining_amount));
15093 END IF;
15094
15095 IF (g_asn_debug = 'Y') THEN
15096 asn_debug.put_line('delete the temp table ');
15097 END IF;
15098
15099 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15100
15101 -- <Bug 9342280 : Added for CLM project>
15102 IF (x_po_correctrec.parent_transaction_type IN ('RECEIVE', 'MATCH', 'DELIVER')) AND
15103 (l_is_clm_po = 'Y' AND l_partial_funded_flag = 'Y') THEN
15104
15105 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_CLM_FUNDED', x_cascaded_table(n).error_message);
15106 rcv_error_pkg.set_token('QTY_A',temp_cascaded_table(current_n).amount);
15107 rcv_error_pkg.set_token('QTY_B',temp_cascaded_table(current_n).amount - x_remaining_amount);
15108
15109 ELSE
15110 -- <CLM END>
15111
15112 rcv_error_pkg.set_error_message('RCV_CORRECT_AMT_OVER_TOLERANCE', x_cascaded_table(n).error_message);
15113 rcv_error_pkg.set_token('AMT_A', temp_cascaded_table(current_n).amount);
15114 rcv_error_pkg.set_token('AMT_B', temp_cascaded_table(current_n).amount - x_remaining_amount);
15115
15116 END IF; -- <Bug 9342280 : Added for CLM project>
15117
15118 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
15119 temp_cascaded_table.DELETE;
15120
15121 IF (g_asn_debug = 'Y') THEN
15122 asn_debug.put_line('mark the actual table with error status');
15123 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
15124 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
15125 END IF;
15126
15127 IF (g_asn_debug = 'Y') THEN
15128 asn_debug.put_line('Need to insert a row into po_interface_errors');
15129 END IF;
15130 END IF; --} matches if(none/warning) and elseif(reject)
15131 END IF; --}
15132
15133 IF (SIGN(x_cascaded_table(current_n).amount) = -1) THEN --{
15134 /* for correct,accept an reject type we dont have the
15135 * tolerance check. Hence error out.
15136 * We cannot correct quantities more than that was received.
15137 */
15138 IF (g_asn_debug = 'Y') THEN
15139 asn_debug.put_line(' in correct extra amount ' || TO_CHAR(x_remaining_amount));
15140 asn_debug.put_line('delete the temp table ');
15141 END IF;
15142
15143 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15144 rcv_error_pkg.set_error_message('RCV_CORRECT_AMT_OVER_TOLERANCE', x_cascaded_table(n).error_message);
15145 rcv_error_pkg.set_token('AMT_A', temp_cascaded_table(current_n).amount);
15146 rcv_error_pkg.set_token('AMT_B', temp_cascaded_table(current_n).amount - x_remaining_amount);
15147 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
15148 temp_cascaded_table.DELETE;
15149
15150 IF (g_asn_debug = 'Y') THEN
15151 asn_debug.put_line('mark the actual table with error status');
15152 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
15153 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
15154 asn_debug.put_line('Need to insert a row into po_interface_errors for correct');
15155 END IF;
15156 END IF; --}
15157 ELSE --}{ else for rows fetched = 0 OR x_first_trans = true
15158 IF rows_fetched = 0 THEN
15159 IF (g_asn_debug = 'Y') THEN
15160 asn_debug.put_line('No rows were retrieved from cursor.');
15161 END IF;
15162 ELSIF x_first_trans THEN
15163 IF (g_asn_debug = 'Y') THEN
15164 asn_debug.put_line('No rows were cascaded');
15165 END IF;
15166 END IF;
15167
15168 x_temp_count := 1;
15169 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15170
15171 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
15172 /* Give an error just like it is done for the
15173 * the receipt transaction;
15174 */
15175 SELECT parent_transaction_id,
15176 transaction_type,
15177 po_line_location_id,
15178 destination_type_code,
15179 source_document_code
15180 INTO l_grand_parent_trx_id,
15181 l_transaction_type,
15182 l_line_loc_id,
15183 l_destination_type_code,
15184 l_source_document_code
15185 FROM rcv_transactions rt
15186 WHERE rt.transaction_id = temp_cascaded_table(current_n).parent_transaction_id;
15187
15188 IF (l_transaction_type = 'DELIVER') THEN --{
15189 IF ( l_destination_type_code = 'INVENTORY'
15190 OR l_source_document_code IN('REQ', 'INVENTORY', 'RMA')) THEN
15191 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15192 rcv_error_pkg.set_error_message('RCV_INVAL_SOURCE_DOC_FOR_DEL', x_cascaded_table(n).error_message);
15193 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
15194 END IF;
15195 END IF; --}
15196
15197 IF (l_transaction_type = 'UNORDERED') THEN --{
15198 SELECT MAX('record_exist')
15199 INTO l_exist
15200 FROM rcv_transactions rt2
15201 WHERE rt2.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
15202 AND rt2.transaction_type = 'MATCH';
15203
15204 SELECT MAX('record_exist')
15205 INTO l_exist1
15206 FROM rcv_transactions_interface rti
15207 WHERE rti.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
15208 AND rti.transaction_type = 'MATCH';
15209
15210 IF l_exist = 'record_exist' THEN --{
15211 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15212 rcv_error_pkg.set_error_message('RCV_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
15213 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
15214 END IF; --}
15215
15216 IF l_exist1 = 'record_exist' THEN --{
15217 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15218 rcv_error_pkg.set_error_message('RCV_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
15219 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
15220 END IF; --}
15221 END IF; --}
15222
15223 IF (l_transaction_type = 'RETURN TO VENDOR') THEN --{
15224 SELECT MAX('record_exist')
15225 INTO l_exist
15226 FROM rcv_transactions rt2,
15227 rcv_transactions rt3
15228 WHERE rt2.transaction_id = l_grand_parent_trx_id
15229 AND rt2.transaction_type = 'UNORDERED'
15230 AND rt3.transaction_type = 'MATCH'
15231 AND rt3.parent_transaction_id = rt2.transaction_id;
15232
15233 SELECT MAX('record_exist')
15234 INTO l_exist1
15235 FROM rcv_transactions rt2,
15236 rcv_transactions_interface rti
15237 WHERE rt2.transaction_id = l_grand_parent_trx_id
15238 AND rt2.transaction_type = 'UNORDERED'
15239 AND rti.transaction_type = 'MATCH'
15240 AND rti.parent_transaction_id = rt2.transaction_id;
15241
15242 IF l_exist = 'record_exist' THEN --{
15243 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15244 rcv_error_pkg.set_error_message('RCV_RET_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
15245 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
15246 END IF; --}
15247
15248 IF l_exist1 = 'record_exist' THEN --{
15249 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15250 rcv_error_pkg.set_error_message('RCV_RET_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
15251 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
15252 END IF; --}
15253 END IF; --}
15254
15255 SELECT MAX('record_exist')
15256 INTO l_exist2
15257 FROM po_line_locations pll
15258 WHERE pll.line_location_id = l_line_loc_id
15259 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
15260 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED');
15261
15262 IF l_exist2 = 'record_exist' THEN
15263 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15264 rcv_error_pkg.set_error_message('RCV_PO_SHIPMENT_CANCELLED', x_cascaded_table(n).error_message);
15265 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
15266 END IF;
15267 END IF; --}
15268
15269 -- Delete the temp_cascaded_table just to be sure
15270
15271 temp_cascaded_table.DELETE;
15272 END IF; --}
15273 ELSE -- }{
15274 IF (g_asn_debug = 'Y') THEN
15275 asn_debug.put_line('Remaining amount is zero ' || TO_CHAR(x_remaining_amount));
15276 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
15277 END IF;
15278 END IF; --} ends the check for whether last record has been reached
15279
15280 -- close cursors
15281
15282 IF (g_asn_debug = 'Y') THEN
15283 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions ' || current_n);
15284 END IF;
15285
15286 IF po_correct%ISOPEN THEN
15287 CLOSE po_correct;
15288 END IF;
15289
15290 IF po_correct_rti%ISOPEN THEN
15291 CLOSE po_correct_rti;
15292 END IF;
15293
15294 IF (g_asn_debug = 'Y') THEN
15295 asn_debug.put_line('before exit current_n is ' || current_n);
15296 END IF;
15297
15298 EXIT;
15299 END IF; --} matches lastrecord or x_remaining_quantity <= 0
15300
15301 IF (g_asn_debug = 'Y') THEN
15302 asn_debug.put_line(' Entering amount calculation for correct');
15303 END IF;
15304
15305 /* If destination_type_code is inventory then we need to make
15306 * sure that we can correct this qty since it might have been
15307 * already reserved in inventory.
15308 */
15309 IF (x_cascaded_table(n).destination_type_code = 'INVENTORY') THEN --{
15310 rcv_roi_return.derive_inv_qty(x_cascaded_table, n);
15311
15312 IF (x_cascaded_table(n).error_status = 'E') THEN
15313 /* Exit from loop */
15314 EXIT;
15315 END IF;
15316 END IF; --}
15317
15318 insert_into_table := FALSE;
15319 already_allocated_amt := 0;
15320
15321 IF (g_asn_debug = 'Y') THEN
15322 asn_debug.put_line('calling Correct get_available_amount ' || x_po_correctrec.parent_transaction_type);
15323 END IF;
15324
15325 get_interface_available_amt(temp_cascaded_table,
15326 current_n,
15327 x_converted_parent_trx_amt
15328 );
15329
15330 IF (g_asn_debug = 'Y') THEN
15331 asn_debug.put_line('correct interface_available_amt ' || x_converted_parent_trx_amt);
15332 END IF;
15333
15334 /* x_converted_parent_trx_qty will be 0 when this is not a child
15335 * transaction to any rti row. Also for correct, grand parent
15336 * may already be processed and for positive correction we
15337 * might need to get the quantity from the grand parent.
15338 */
15339 IF (x_converted_parent_trx_amt = 0) THEN --{
15340 IF (g_asn_debug = 'Y') THEN
15341 asn_debug.put_line('interface amount is 0');
15342 END IF;
15343
15344 IF (SIGN(temp_cascaded_table(current_n).amount) = -1) THEN --{
15345 asn_debug.put_line('Before call to get_available_amt for negative correction');
15346 rcv_quantities_s.get_available_amount('CORRECT',
15347 x_po_correctrec.rcv_transaction_id,
15348 'VENDOR',
15349 x_po_correctrec.parent_transaction_type,
15350 NULL,
15351 'NEGATIVE',
15352 x_converted_parent_trx_amt,
15353 x_tolerable_amt
15354 );
15355 ELSE --}{
15356 IF (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH', 'UNORDERED')) THEN
15357 l_grand_parent_trx_id := x_po_correctrec.grand_parent_txn_id;
15358 asn_debug.put_line('Parent_trx not in receive and gp is ' || l_grand_parent_trx_id);
15359 ELSIF(x_po_correctrec.parent_transaction_type IN('MATCH', 'RECEIVE')) THEN
15360 IF (temp_cascaded_table(current_n).parent_transaction_id IS NOT NULL) THEN
15361 l_grand_parent_trx_id := x_po_correctrec.po_line_location_id;
15362 asn_debug.put_line('Parent_trx in receive and parent_trx_id not null gp is ' || l_grand_parent_trx_id);
15363 ELSIF(temp_cascaded_table(current_n).parent_interface_txn_id IS NOT NULL) THEN
15364 /* We would have the value derived in the x_cascaded_table
15365 * but not have inserted it back into rti.
15366 */
15367 l_grand_parent_trx_id := temp_cascaded_table(current_n).po_line_location_id;
15368 asn_debug.put_line('Parent_trx in receive and parent_inter_trx_id not null gp is ' || l_grand_parent_trx_id);
15369 END IF;
15370 ELSIF(x_po_correctrec.parent_transaction_type = 'UNORDERED') THEN
15371 l_grand_parent_trx_id := x_po_correctrec.rcv_transaction_id;
15372 END IF;
15373
15374 IF (l_grand_parent_trx_id IS NOT NULL) THEN
15375 asn_debug.put_line('gp before get_avail_amt for +ve corr' || l_grand_parent_trx_id);
15376 rcv_quantities_s.get_available_amount('CORRECT',
15377 x_po_correctrec.rcv_transaction_id,
15378 'VENDOR',
15379 x_po_correctrec.parent_transaction_type,
15380 l_grand_parent_trx_id,
15381 'POSITIVE',
15382 x_converted_parent_trx_amt,
15383 x_tolerable_amt
15384 );
15385 END IF;
15386 END IF; --}
15387 END IF; --} -- interface_available_qty is 0.
15388
15389 IF (g_asn_debug = 'Y') THEN
15390 asn_debug.put_line('amount from GET_AVAILABLE_AMOUNT for correct is ' || x_converted_parent_trx_amt);
15391 END IF;
15392
15393 IF (x_remaining_amount = 0) THEN
15394 IF (g_asn_debug = 'Y') THEN
15395 asn_debug.put_line(' correct Need an error message in the interface tables');
15396 END IF;
15397 ELSE
15398 /* Converted successfully and have some quantity on which we can act */
15399 IF (g_asn_debug = 'Y') THEN
15400 asn_debug.put_line('Converted trx amt that is available ' || x_converted_parent_trx_amt);
15401 asn_debug.put_line('Remaining amt that is available ' || x_remaining_amount);
15402 END IF;
15403
15404 IF ( (rows_fetched = x_record_count)
15405 AND (SIGN(temp_cascaded_table(current_n).amount) = 1)) THEN --{
15406 x_converted_trx_amt := x_tolerable_amt;
15407
15408 IF (g_asn_debug = 'Y') THEN
15409 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_trx_amt));
15410 END IF;
15411 END IF; --}
15412
15413 IF (x_converted_parent_trx_amt > 0) THEN --{
15414 /* Compare with abs(x_remaining_qty) here since we want
15415 * to make sure that the qty we have is greater than
15416 * the available qty irrespective of whether this is
15417 * positive or negative correction.
15418 */
15419 IF (x_converted_parent_trx_amt < ABS(x_remaining_amount)) THEN --{
15420 /* Total quantity available to correct is less than the qty
15421 * that the user wants to correct. Hence we would error out but
15422 * to keep the old code we will get the remaining code here and
15423 * error out later.
15424 */
15425 x_remaining_amount := x_remaining_amount - SIGN(temp_cascaded_table(current_n).amount) * x_converted_parent_trx_amt;
15426 x_converted_parent_trx_amt := SIGN(temp_cascaded_table(current_n).amount) * x_converted_parent_trx_amt;
15427
15428 IF (g_asn_debug = 'Y') THEN
15429 asn_debug.put_line('remaning amt after allocation is : ' || TO_CHAR(x_remaining_amount));
15430 END IF;
15431
15432 insert_into_table := TRUE;
15433 ELSE --}{
15434 IF (g_asn_debug = 'Y') THEN
15435 asn_debug.put_line('We are in >= amount branch ');
15436 END IF;
15437
15438 x_converted_parent_trx_amt := x_remaining_amount;
15439 insert_into_table := TRUE;
15440 x_remaining_amount := 0;
15441 END IF; --} /* if (x_converted_parent_trx_qty < x_remaining_quantity) then */
15442 ELSE /* x_converted_parent_trx_qty >0 */ --}{
15443
15444 -- so that the row can be used based on qty tolerance
15445 -- checks
15446 IF (g_asn_debug = 'Y') THEN
15447 asn_debug.put_line('amount is less then 0 but last record');
15448 END IF;
15449
15450 insert_into_table := TRUE;
15451 x_converted_trx_amt := 0;
15452 END IF; /*x_converted_parent_trx_qty >0 */ --}
15453 END IF; --} just added this
15454
15455 /* Converted amt successfully and we have some amount on which we can act */
15456 IF (g_asn_debug = 'Y') THEN
15457 asn_debug.put_line('Transaction amt is ' || x_converted_parent_trx_amt);
15458 END IF;
15459
15460 IF insert_into_table THEN --{
15461 IF (x_first_trans) THEN --{
15462 IF (g_asn_debug = 'Y') THEN
15463 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
15464 END IF;
15465
15466 x_first_trans := FALSE;
15467 ELSE --}{
15468 IF (g_asn_debug = 'Y') THEN
15469 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
15470 END IF;
15471
15472 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
15473 END IF; --}
15474
15475 temp_cascaded_table(current_n).po_header_id := x_po_correctrec.po_header_id;
15476 temp_cascaded_table(current_n).po_line_id := x_po_correctrec.po_line_id;
15477 temp_cascaded_table(current_n).po_line_location_id := x_po_correctrec.po_line_location_id;
15478 temp_cascaded_table(current_n).po_distribution_id := x_po_correctrec.po_distribution_id;
15479 temp_cascaded_table(current_n).amount := x_converted_parent_trx_amt;
15480
15481 IF (g_asn_debug = 'Y') THEN
15482 asn_debug.put_line('Transaction amt ' || temp_cascaded_table(current_n).amount);
15483 END IF;
15484
15485 current_n := current_n + 1;
15486
15487 IF (g_asn_debug = 'Y') THEN
15488 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
15489 END IF;
15490 END IF; --}
15491 END LOOP; --}
15492 ELSE --} {
15493 -- error_status and error_message are set after validate_quantity_shipped
15494 IF (g_asn_debug = 'Y') THEN
15495 asn_debug.put_line('No po_header_id/item_id ');
15496 END IF;
15497
15498 IF (g_asn_debug = 'Y') THEN
15499 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
15500 END IF;
15501
15502 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
15503 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
15504
15505 IF (x_cascaded_table(n).error_message IS NULL) THEN
15506 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION', x_cascaded_table(n).error_message);
15507 END IF;
15508
15509 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID');
15510 END IF; --}
15511
15512 RETURN;
15513 END IF; -- } of (asn quantity_shipped was valid)
15514
15515 IF (g_asn_debug = 'Y') THEN
15516 asn_debug.put_line('before closing cursors current_n is ' || temp_cascaded_table.COUNT);
15517 END IF;
15518
15519 IF po_correct%ISOPEN THEN
15520 CLOSE po_correct;
15521 END IF;
15522
15523 IF po_correct_rti%ISOPEN THEN
15524 CLOSE po_correct_rti;
15525 END IF;
15526
15527 IF (g_asn_debug = 'Y') THEN
15528 asn_debug.put_line('Exit derive_correction_line_amt');
15529 END IF;
15530 EXCEPTION
15531 WHEN OTHERS THEN
15532 IF (g_asn_debug = 'Y') THEN
15533 asn_debug.put_line('Exception in derive_correction_line_amt ');
15534 END IF;
15535
15536 IF po_correct%ISOPEN THEN
15537 CLOSE po_correct;
15538 END IF;
15539
15540 IF po_correct_rti%ISOPEN THEN
15541 CLOSE po_correct_rti;
15542 END IF;
15543
15544 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
15545 rcv_error_pkg.set_sql_error_message('derive_correction_line_amt', x_progress);
15546 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
15547 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15548
15549 IF (g_asn_debug = 'Y') THEN
15550 asn_debug.put_line(TO_CHAR(n));
15551 asn_debug.put_line(SQLERRM);
15552 asn_debug.put_line('error ' || x_progress);
15553 END IF;
15554 END derive_correction_line_amt;
15555
15556 PROCEDURE default_vendor_correct(
15557 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15558 n IN BINARY_INTEGER
15559 ) IS
15560 p_trx_record rcv_roi_header_common.common_default_record_type;
15561
15562 CURSOR po_correct(
15563 v_parent_trx_id NUMBER
15564 ) IS
15565 SELECT rt.po_revision_num,
15566 rsl.item_description,
15567 rt.po_release_id,
15568 rt.location_id loc_id,
15569 rt.organization_id,
15570 rt.routing_header_id,
15571 rt.destination_type_code,
15572 rt.destination_context,
15573 rt.inspection_status_code,
15574 rt.currency_code,
15575 rt.currency_conversion_rate,
15576 rt.currency_conversion_type,
15577 rt.currency_conversion_date,
15578 rt.location_id,
15579 rt.shipment_header_id,
15580 rt.shipment_line_id,
15581 rsl.category_id,
15582 rt.vendor_id,
15583 rt.vendor_site_id,
15584 rt.po_unit_price,
15585 rt.movement_id,
15586 rt.deliver_to_person_id,
15587 rt.deliver_to_location_id,
15588 rt.subinventory,
15589 rt.lpn_id,
15590 rt.transfer_lpn_id,
15591 rt.oe_order_header_id,
15592 rt.oe_order_line_id,
15593 rt.customer_id,
15594 rt.customer_site_id,
15595 rt.source_document_code,
15596 rt.job_id
15597 FROM rcv_transactions rt,
15598 rcv_shipment_lines rsl
15599 WHERE rt.transaction_id = v_parent_trx_id
15600 AND ( rt.transaction_type IN('RECEIVE', 'TRANSFER', 'ACCEPT', 'REJECT', 'MATCH')
15601 OR ( rt.transaction_type IN('RETURN TO VENDOR', 'RETURN TO CUSTOMER')
15602 AND NOT EXISTS(SELECT 'rtv to processed matched unordered receipt'
15603 FROM rcv_transactions rt2,
15604 rcv_transactions rt3
15605 WHERE rt2.transaction_id = rt.parent_transaction_id
15606 AND rt2.transaction_type = 'UNORDERED'
15607 AND rt3.transaction_type = 'MATCH'
15608 AND rt3.parent_transaction_id = rt2.transaction_id)
15609 AND NOT EXISTS(SELECT 'rtv to unprocessed matched unordered receipt'
15610 FROM rcv_transactions rt2,
15611 rcv_transactions_interface rti
15612 WHERE rt2.transaction_id = rt.parent_transaction_id
15613 AND rt2.transaction_type = 'UNORDERED'
15614 AND rti.transaction_type = 'MATCH'
15615 AND rti.parent_transaction_id = rt2.transaction_id)
15616 )
15617 OR ( rt.transaction_type = 'DELIVER'
15618 AND NOT( rt.destination_type_code = 'INVENTORY'
15619 AND rt.source_document_code IN('REQ', 'INVENTORY')))
15620 OR ( rt.transaction_type = 'UNORDERED'
15621 AND NOT EXISTS(SELECT 'processed matched rows'
15622 FROM rcv_transactions rt2
15623 WHERE rt2.parent_transaction_id = rt.transaction_id
15624 AND rt2.transaction_type = 'MATCH')
15625 AND NOT EXISTS(SELECT 'unprocessed matched rows'
15626 FROM rcv_transactions_interface rti
15627 WHERE rti.parent_transaction_id = rt.transaction_id
15628 AND rti.transaction_type = 'MATCH')
15629 )
15630 )
15631 AND NOT EXISTS(SELECT 'purchase order shipment cancelled or fc'
15632 FROM po_line_locations pll
15633 WHERE pll.line_location_id = rt.po_line_location_id
15634 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
15635 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED'))
15636 AND (rt.shipment_line_id = rsl.shipment_line_id)
15637 ORDER BY rt.transaction_id;
15638
15639 CURSOR po_correct_rti(
15640 v_parent_inter_trx_id NUMBER
15641 ) IS
15642 SELECT rti.po_revision_num,
15643 rti.item_description,
15644 rti.po_release_id,
15645 rti.location_id loc_id,
15646 rti.to_organization_id organization_id,
15647 rti.routing_header_id,
15648 rti.destination_type_code,
15649 rti.destination_context,
15650 rti.inspection_status_code,
15651 rti.currency_code,
15652 rti.currency_conversion_rate,
15653 rti.currency_conversion_type,
15654 rti.currency_conversion_date,
15655 rti.location_id,
15656 rti.shipment_header_id,
15657 rti.shipment_line_id,
15658 rti.category_id,
15659 rti.vendor_id,
15660 rti.vendor_site_id,
15661 rti.po_unit_price,
15662 rti.movement_id,
15663 rti.deliver_to_person_id,
15664 rti.deliver_to_location_id,
15665 rti.subinventory,
15666 rti.lpn_id,
15667 rti.transfer_lpn_id,
15668 rti.oe_order_header_id,
15669 rti.oe_order_line_id,
15670 rti.customer_id,
15671 rti.customer_site_id,
15672 rti.source_document_code,
15673 rti.job_id
15674 FROM rcv_transactions_interface rti
15675 WHERE interface_transaction_id = v_parent_inter_trx_id;
15676
15677 default_po_correct_info po_correct%ROWTYPE;
15678 x_progress VARCHAR2(3);
15679 x_locator_control NUMBER;
15680 x_default_subinventory VARCHAR2(10);
15681 x_default_locator_id NUMBER;
15682 x_success BOOLEAN;
15683 x_tax_name VARCHAR2(50); -- Bug 6331613
15684 x_vendor_site_id NUMBER;
15685 x_vendor_site_code VARCHAR2(20);
15686 l_project_id NUMBER;
15687 l_task_id NUMBER;
15688 l_locator_id NUMBER;
15689 temp_index NUMBER;
15690 lpn_error NUMBER := 0;
15691 BEGIN
15692 p_trx_record.destination_type_code := x_cascaded_table(n).destination_type_code;
15693 p_trx_record.transaction_type := x_cascaded_table(n).transaction_type;
15694 p_trx_record.processing_mode_code := x_cascaded_table(n).processing_mode_code;
15695 p_trx_record.processing_status_code := x_cascaded_table(n).processing_status_code;
15696 p_trx_record.transaction_status_code := x_cascaded_table(n).transaction_status_code;
15697 p_trx_record.auto_transact_code := x_cascaded_table(n).auto_transact_code;
15698 rcv_roi_header_common.commondefaultcode(p_trx_record);
15699 x_cascaded_table(n).destination_type_code := p_trx_record.destination_type_code;
15700 x_cascaded_table(n).transaction_type := p_trx_record.transaction_type;
15701 x_cascaded_table(n).processing_mode_code := p_trx_record.processing_mode_code;
15702 x_cascaded_table(n).processing_status_code := p_trx_record.processing_status_code;
15703 x_cascaded_table(n).transaction_status_code := p_trx_record.transaction_status_code;
15704 x_cascaded_table(n).auto_transact_code := p_trx_record.auto_transact_code;
15705
15706 IF (g_asn_debug = 'Y') THEN
15707 asn_debug.put_line('Enter Default for Correct transaction');
15708 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
15709 END IF;
15710
15711 IF x_cascaded_table(n).source_document_code IS NULL THEN
15712 IF x_cascaded_table(n).receipt_source_code = 'CUSTOMER' THEN
15713 x_cascaded_table(n).source_document_code := 'RMA';
15714 ELSE
15715 x_cascaded_table(n).source_document_code := 'PO';
15716 END IF;
15717
15718 IF (g_asn_debug = 'Y') THEN
15719 asn_debug.put_line('Defaulting SOURCE_DOCUMENT_CODE ' || x_cascaded_table(n).source_document_code);
15720 END IF;
15721 END IF;
15722
15723 IF (x_cascaded_table(n).derive = 'Y') THEN --{
15724 IF (x_cascaded_table(n).derive_index <> 0) THEN --{
15725 NULL;
15726 /* Get the values from pl/sql table */
15727 temp_index := x_cascaded_table(n).derive_index;
15728 x_cascaded_table(n).po_revision_num := x_cascaded_table(temp_index).po_revision_num;
15729 x_cascaded_table(n).item_description := x_cascaded_table(temp_index).item_description;
15730 x_cascaded_table(n).destination_type_code := x_cascaded_table(temp_index).destination_type_code;
15731 x_cascaded_table(n).destination_context := x_cascaded_table(temp_index).destination_context;
15732 x_cascaded_table(n).inspection_status_code := x_cascaded_table(temp_index).inspection_status_code;
15733 x_cascaded_table(n).po_release_id := x_cascaded_table(temp_index).po_release_id;
15734 x_cascaded_table(n).to_organization_id := x_cascaded_table(temp_index).to_organization_id;
15735 x_cascaded_table(n).from_organization_id := x_cascaded_table(temp_index).from_organization_id;
15736 x_cascaded_table(n).routing_header_id := x_cascaded_table(temp_index).routing_header_id;
15737 x_cascaded_table(n).currency_code := x_cascaded_table(temp_index).currency_code;
15738 x_cascaded_table(n).currency_conversion_rate := x_cascaded_table(temp_index).currency_conversion_rate;
15739 x_cascaded_table(n).currency_conversion_type := x_cascaded_table(temp_index).currency_conversion_type;
15740 x_cascaded_table(n).currency_conversion_date := x_cascaded_table(temp_index).currency_conversion_date;
15741 x_cascaded_table(n).shipment_header_id := x_cascaded_table(temp_index).shipment_header_id;
15742 x_cascaded_table(n).shipment_line_id := x_cascaded_table(temp_index).shipment_line_id;
15743 x_cascaded_table(n).category_id := x_cascaded_table(temp_index).category_id;
15744 x_cascaded_table(n).vendor_id := x_cascaded_table(temp_index).vendor_id;
15745 x_cascaded_table(n).vendor_site_id := x_cascaded_table(temp_index).vendor_site_id;
15746 x_cascaded_table(n).po_unit_price := x_cascaded_table(temp_index).po_unit_price;
15747 x_cascaded_table(n).location_id := x_cascaded_table(temp_index).location_id;
15748 x_cascaded_table(n).deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
15749 x_cascaded_table(n).deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
15750 x_cascaded_table(n).subinventory := x_cascaded_table(temp_index).subinventory;
15751 x_cascaded_table(n).job_id := x_cascaded_table(temp_index).job_id;
15752 -- LPN defaulting
15753 /* Bug 3444284.
15754 * We dont need to default lpn_ids. WMS will take care of
15755 * populating these columns. So this case of giving a warning
15756 * will not arise as it will be defaulted by them
15757 */
15758 ELSE --} {
15759 IF (g_asn_debug = 'Y') THEN
15760 asn_debug.put_line('open cursor Default RTI');
15761 END IF;
15762
15763 OPEN po_correct_rti(x_cascaded_table(n).parent_interface_txn_id);
15764 END IF; --}
15765 ELSE -- } {
15766 OPEN po_correct(x_cascaded_table(n).parent_transaction_id);
15767 END IF; --}
15768
15769 IF (po_correct%ISOPEN) THEN
15770 IF (g_asn_debug = 'Y') THEN
15771 asn_debug.put_line('fetch cursor Default ' || x_cascaded_table(n).parent_transaction_id);
15772 END IF;
15773
15774 FETCH po_correct INTO default_po_correct_info;
15775 ELSIF(po_correct_rti%ISOPEN) THEN
15776 FETCH po_correct_rti INTO default_po_correct_info;
15777 END IF;
15778
15779 IF ( ( po_correct%ISOPEN
15780 AND po_correct%FOUND)
15781 OR ( po_correct_rti%ISOPEN
15782 AND po_correct_rti%FOUND)) THEN --{
15783 IF (g_asn_debug = 'Y') THEN --{
15784 asn_debug.put_line('Defaulting Correct po_revision_num' || default_po_correct_info.po_revision_num);
15785 asn_debug.put_line('Defaulting Correct item_description' || default_po_correct_info.item_description);
15786 asn_debug.put_line('Defaulting Correct po_release_id' || default_po_correct_info.po_release_id);
15787 asn_debug.put_line('Defaulting Correct location_id' || default_po_correct_info.loc_id);
15788 asn_debug.put_line('Defaulting Correct organization_id' || default_po_correct_info.organization_id);
15789 asn_debug.put_line('Defaulting Correct routing_header_id' || default_po_correct_info.routing_header_id);
15790 asn_debug.put_line('Defaulting Correct currency_code' || default_po_correct_info.currency_code);
15791 asn_debug.put_line('Defaulting Correct currency_conversion_rate' || default_po_correct_info.currency_conversion_rate);
15792 asn_debug.put_line('Defaulting Correct currency_conversion_type' || default_po_correct_info.currency_conversion_type);
15793 asn_debug.put_line('Defaulting Correct currency_conversion_date' || default_po_correct_info.currency_conversion_date);
15794 asn_debug.put_line('Defaulting Correct shipment_header_id' || default_po_correct_info.shipment_header_id);
15795 asn_debug.put_line('Defaulting Correct shipment_line_id' || default_po_correct_info.shipment_line_id);
15796 asn_debug.put_line('Defaulting Correct category_id' || default_po_correct_info.category_id);
15797 asn_debug.put_line('Defaulting Correct vendor_id' || default_po_correct_info.vendor_id);
15798 asn_debug.put_line('Defaulting Correct vendor_site_id' || default_po_correct_info.vendor_site_id);
15799 asn_debug.put_line('Defaulting Correct po_unit_price' || default_po_correct_info.po_unit_price);
15800 asn_debug.put_line('Defaulting Correct DELIVER_TO_PERSON_ID' || default_po_correct_info.deliver_to_person_id);
15801 asn_debug.put_line('Defaulting Correct DELIVER_TO_LOCATION_ID' || default_po_correct_info.deliver_to_location_id);
15802 asn_debug.put_line('Defaulting Correct SUBINVENTORY' || default_po_correct_info.subinventory);
15803 asn_debug.put_line('Defaulting Correct CUSTOMER_ID' || default_po_correct_info.customer_id);
15804 asn_debug.put_line('Defaulting Correct CUSTOMER_SITE_ID' || default_po_correct_info.customer_site_id);
15805 asn_debug.put_line('Defaulting Correct job_id' || default_po_correct_info.job_id);
15806 END IF; --}
15807
15808 IF x_cascaded_table(n).oe_order_header_id IS NULL
15809 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
15810 x_cascaded_table(n).oe_order_header_id := default_po_correct_info.oe_order_header_id;
15811
15812 IF (g_asn_debug = 'Y') THEN
15813 asn_debug.put_line('Defaulting Transfer oe_order_header_id ' || x_cascaded_table(n).oe_order_header_id);
15814 END IF;
15815 END IF;
15816
15817 IF x_cascaded_table(n).oe_order_line_id IS NULL
15818 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
15819 x_cascaded_table(n).oe_order_line_id := default_po_correct_info.oe_order_line_id;
15820
15821 IF (g_asn_debug = 'Y') THEN
15822 asn_debug.put_line('Defaulting Transfer oe_order_line_id ' || x_cascaded_table(n).oe_order_line_id);
15823 END IF;
15824 END IF;
15825
15826 x_cascaded_table(n).po_revision_num := default_po_correct_info.po_revision_num;
15827 x_cascaded_table(n).item_description := default_po_correct_info.item_description;
15828 x_cascaded_table(n).destination_type_code := default_po_correct_info.destination_type_code;
15829 x_cascaded_table(n).destination_context := default_po_correct_info.destination_context;
15830 x_cascaded_table(n).inspection_status_code := default_po_correct_info.inspection_status_code;
15831 x_cascaded_table(n).po_release_id := default_po_correct_info.po_release_id;
15832 x_cascaded_table(n).to_organization_id := default_po_correct_info.organization_id;
15833 x_cascaded_table(n).from_organization_id := default_po_correct_info.organization_id;
15834 x_cascaded_table(n).routing_header_id := default_po_correct_info.routing_header_id;
15835 x_cascaded_table(n).currency_code := default_po_correct_info.currency_code;
15836 x_cascaded_table(n).currency_conversion_rate := default_po_correct_info.currency_conversion_rate;
15837 x_cascaded_table(n).currency_conversion_type := default_po_correct_info.currency_conversion_type;
15838 x_cascaded_table(n).currency_conversion_date := default_po_correct_info.currency_conversion_date;
15839 x_cascaded_table(n).shipment_header_id := default_po_correct_info.shipment_header_id;
15840 x_cascaded_table(n).shipment_line_id := default_po_correct_info.shipment_line_id;
15841 x_cascaded_table(n).category_id := default_po_correct_info.category_id;
15842 x_cascaded_table(n).vendor_id := default_po_correct_info.vendor_id;
15843 x_cascaded_table(n).vendor_site_id := default_po_correct_info.vendor_site_id;
15844 x_cascaded_table(n).job_id := default_po_correct_info.job_id;
15845
15846 /* We used to get the unit_price from the cursor where it picks
15847 * up from the parent. But since PO unit_price can be change
15848 * retroactively, we need to pick up the unit_price from PO
15849 * directly. Since we would have derived line_location_id
15850 * and po_line_id at this point, use the values here. Since
15851 * we come here for defaulting RMA also, we need to do this
15852 * only when receipt_source_code is VENDOR.
15853 * x_cascaded_table(n).po_unit_price :=
15854 default_po_correct_info.po_unit_price;
15855 */
15856 IF (x_cascaded_table(n).receipt_source_code = 'VENDOR') THEN --{
15857 SELECT NVL(pll.price_override, pl.unit_price)
15858 INTO x_cascaded_table(n).po_unit_price
15859 FROM po_line_locations pll,
15860 po_lines pl
15861 WHERE pll.line_location_id = x_cascaded_table(n).po_line_location_id
15862 AND pl.po_line_id = x_cascaded_table(n).po_line_id
15863 AND pl.po_line_id = pll.po_line_id;
15864
15865 IF (g_asn_debug = 'Y') THEN
15866 asn_debug.put_line('Defaulting Correct po_unit_price' || x_cascaded_table(n).po_unit_price);
15867 END IF;
15868 END IF; --}
15869
15870 x_cascaded_table(n).location_id := default_po_correct_info.loc_id;
15871 x_cascaded_table(n).deliver_to_person_id := default_po_correct_info.deliver_to_person_id;
15872 x_cascaded_table(n).deliver_to_location_id := default_po_correct_info.deliver_to_location_id;
15873 x_cascaded_table(n).subinventory := default_po_correct_info.subinventory;
15874 -- LPN defaulting
15875 asn_debug.put_line(' defaulting lpn_id and transfer_lpn_id for int org cor');
15876 /* Bug 3444284.
15877 * We dont need to default lpn_ids. WMS will take care of
15878 * populating these columns. So this case of giving a warning
15879 * will not arise as it will be defaulted by them
15880 */
15881 END IF; -- if po_transfer%found is true }
15882
15883 /* Default the from and to subinventory and locator_id */
15884 ----WMS Changes
15885 IF x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
15886 default_from_subloc_info(x_cascaded_table, n);
15887 default_to_subloc_info(x_cascaded_table, n);
15888
15889 /* The following code will be common for all the transactions not just for transfer to
15890 * get the use_mtl_lot and use_mtl_serial.
15891 */
15892 /* Bug 5076685: For one time items, item_id won't be available. We need to
15893 have a check for item_id not null, before hitting the
15894 mtl_system_items table.Added the IF - END IF statement. */
15895 /*
15896 BEGIN Comment: Bug: 4735484
15897 IF x_cascaded_table(n).item_id IS NOT NULL THEN
15898 SELECT NVL(x_cascaded_table(n).use_mtl_lot, lot_control_code),
15899 NVL(x_cascaded_table(n).use_mtl_serial, serial_number_control_code)
15900 INTO x_cascaded_table(n).use_mtl_lot,
15901 x_cascaded_table(n).use_mtl_serial
15902 FROM mtl_system_items
15903 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
15904 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
15905 END IF;
15906 END Comment: Bug: 4735484
15907 */
15908 END IF;
15909
15910 IF (g_asn_debug = 'Y') THEN
15911 asn_debug.put_line('Set Location_id = ' || TO_CHAR(x_cascaded_table(n).location_id));
15912 asn_debug.put_line(' quantity ' || x_cascaded_table(n).quantity);
15913 END IF;
15914
15915 IF (g_asn_debug = 'Y') THEN
15916 asn_debug.put_line('Exit default_vendor_correct');
15917 END IF;
15918
15919 IF po_correct%ISOPEN THEN
15920 CLOSE po_correct;
15921 END IF;
15922
15923 IF po_correct_rti%ISOPEN THEN
15924 CLOSE po_correct_rti;
15925 END IF;
15926 EXCEPTION
15927 WHEN OTHERS THEN
15928 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
15929 rcv_error_pkg.set_sql_error_message('default_vendor_correct', x_progress);
15930 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
15931 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15932 END default_vendor_correct;
15933
15934 FUNCTION convert_into_correct_qty(
15935 source_qty IN NUMBER,
15936 source_uom IN VARCHAR2,
15937 item_id IN NUMBER,
15938 dest_uom IN VARCHAR2
15939 )
15940 RETURN NUMBER IS
15941 correct_qty NUMBER;
15942 BEGIN
15943 IF source_uom <> dest_uom THEN
15944 po_uom_s.uom_convert(source_qty,
15945 source_uom,
15946 item_id,
15947 dest_uom,
15948 correct_qty
15949 );
15950 ELSE
15951 correct_qty := source_qty;
15952 END IF;
15953
15954 RETURN(correct_qty);
15955 EXCEPTION
15956 WHEN OTHERS THEN
15957 IF (g_asn_debug = 'Y') THEN
15958 asn_debug.put_line('Could not convert between UOMs');
15959 asn_debug.put_line('Will return 0');
15960 END IF;
15961
15962 correct_qty := 0;
15963 RETURN(correct_qty);
15964 END;
15965
15966 PROCEDURE validate_source_type(
15967 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15968 n IN BINARY_INTEGER
15969 ) IS
15970 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
15971 BEGIN
15972 /*
15973 ** Validate Source Type. This value is always required
15974 */
15975 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
15976 RETURN;
15977 END IF;
15978
15979 IF (x_cascaded_table(n).transaction_type <> 'RECEIVE') THEN --{
15980 IF (x_cascaded_table(n).source_document_code = 'PO') THEN --{
15981 SELECT type_lookup_code
15982 INTO po_lookup_code_record.lookup_code
15983 FROM po_headers
15984 WHERE po_header_id = x_cascaded_table(n).po_header_id;
15985
15986 po_lookup_code_record.lookup_type := 'PO TYPE';
15987 ELSE --}{
15988 po_lookup_code_record.lookup_code := x_cascaded_table(n).receipt_source_code;
15989 po_lookup_code_record.lookup_type := 'SHIPMENT SOURCE TYPE';
15990 END IF; --}
15991
15992 po_lookup_code_record.error_record.error_status := 'S';
15993 po_lookup_code_record.error_record.error_message := NULL;
15994
15995 IF (g_asn_debug = 'Y') THEN
15996 asn_debug.put_line('Validating Source Type Code');
15997 END IF;
15998
15999 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
16000 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
16001 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
16002 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
16003 'SOURCE_TYPE_CODE',
16004 FALSE
16005 );
16006 END IF;
16007 EXCEPTION
16008 WHEN OTHERS THEN
16009 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16010 rcv_error_pkg.set_sql_error_message('validate_source_type', '000');
16011 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16012 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16013 END validate_source_type;
16014
16015 PROCEDURE validate_transaction_type(
16016 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16017 n IN BINARY_INTEGER
16018 ) IS
16019 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
16020 BEGIN
16021 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
16022 RETURN;
16023 END IF;
16024
16025 IF (x_cascaded_table(n).transaction_type <> 'RECEIVE') THEN --{
16026 po_lookup_code_record.lookup_code := x_cascaded_table(n).transaction_type;
16027 po_lookup_code_record.lookup_type := 'RCV TRANSACTION TYPE';
16028 po_lookup_code_record.error_record.error_status := 'S';
16029 po_lookup_code_record.error_record.error_message := NULL;
16030
16031 IF (g_asn_debug = 'Y') THEN
16032 asn_debug.put_line('Validating Destination Type Code');
16033 END IF;
16034
16035 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
16036 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
16037 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
16038 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
16039 'TRANSACTION_TYPE_CODE',
16040 FALSE
16041 );
16042 END IF; --}
16043 EXCEPTION
16044 WHEN OTHERS THEN
16045 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16046 rcv_error_pkg.set_sql_error_message('validate_transaction_type', '000');
16047 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16048 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16049 END validate_transaction_type;
16050
16051 PROCEDURE validate_inspection_status(
16052 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16053 n IN BINARY_INTEGER
16054 ) IS
16055 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
16056 BEGIN
16057 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
16058 RETURN;
16059 END IF;
16060
16061 IF (x_cascaded_table(n).inspection_status_code IS NOT NULL) THEN --{
16062 po_lookup_code_record.lookup_code := x_cascaded_table(n).inspection_status_code;
16063 po_lookup_code_record.lookup_type := 'INSPECTION STATUS';
16064 po_lookup_code_record.error_record.error_status := 'S';
16065 po_lookup_code_record.error_record.error_message := NULL;
16066
16067 IF (g_asn_debug = 'Y') THEN
16068 asn_debug.put_line('Validating INSPECTION STATUS ');
16069 END IF;
16070
16071 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
16072 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
16073 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
16074 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
16075 'INSPECTION_STATUS_CODE',
16076 FALSE
16077 );
16078 END IF; --}
16079 EXCEPTION
16080 WHEN OTHERS THEN
16081 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16082 rcv_error_pkg.set_sql_error_message('validate_inspection_status', '000');
16083 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16084 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16085 END validate_inspection_status;
16086
16087 /** OPM change Bug# 3061052**/
16088 -- added validate_opm_attributes to validate OPM specific columns.
16089
16090 PROCEDURE validate_opm_attributes(
16091 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16092 n IN BINARY_INTEGER
16093 ) IS
16094 /*INVCONV, gml_opm_roi_grp.opm_record_type to be removed , Punit Kumar */
16095 --l_opm_record_type gml_opm_roi_grp.opm_record_type;
16096
16097 l_att_rec RCV_TRANSACTIONS_INTERFACE_SV1.attributes_record_type;
16098 l_column_name VARCHAR2(50);
16099 l_tokenname1 VARCHAR2(30);
16100 l_tokenvalue1 VARCHAR2(1800);
16101 l_quantity_shipped NUMBER;
16102 l_secondary_quantity_shipped NUMBER;
16103 l_transaction_id NUMBER; /*BUG#10380635 */
16104
16105 /*INVCONV*/
16106 l_return_status VARCHAR2(1) := NULL;
16107 x_return_status VARCHAR2(1) :='S';
16108 l_msg_count NUMBER;
16109 l_msg_data VARCHAR2(100);
16110 /*end , INVCONV*/
16111
16112 BEGIN
16113
16114 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
16115 RETURN;
16116 END IF;
16117
16118 /*INVCONV , It checks for OPM insatallation. This needs to be removed , Punit Kumar*/
16119 /*
16120 IF ( gml_process_flags.opm_installed = 1
16121 AND x_cascaded_table(n).item_id IS NOT NULL
16122 AND gml_process_flags.check_process_orgn(p_organization_id => x_cascaded_table(n).to_organization_id) = 1 ) THEN
16123 IF (g_asn_debug = 'Y') THEN
16124 asn_debug.put_line('In validate opm attributes');
16125 END IF;
16126 */
16127
16128 IF (g_asn_debug = 'Y') THEN
16129 asn_debug.put_line('In validate opm attributes');
16130 END IF;
16131
16132
16133 -- if receiving full qty against an ASN/Internal Order , default the secondary qty from shipment line
16134 -- if there is no secondary qty specified on the reciept line.
16135 /*INVCONV, added INVENTORY to account for Inter Org Transfers. Punit Kumar*/
16136 IF x_cascaded_table(n).receipt_source_code IN('VENDOR', 'INTERNAL ORDER' , 'INVENTORY')
16137 /*end , INVCONV*/
16138 AND x_cascaded_table(n).shipment_header_id IS NOT NULL
16139 AND x_cascaded_table(n).shipment_line_id IS NOT NULL
16140 AND x_cascaded_table(n).secondary_quantity IS NULL THEN
16141 BEGIN
16142 SELECT quantity_shipped,
16143 secondary_quantity_shipped
16144 INTO l_quantity_shipped,
16145 l_secondary_quantity_shipped
16146 FROM rcv_shipment_lines
16147 WHERE shipment_header_id = x_cascaded_table(n).shipment_header_id
16148 AND shipment_line_id = x_cascaded_table(n).shipment_line_id;
16149 EXCEPTION
16150 WHEN OTHERS THEN
16151 NULL;
16152 END;
16153
16154 IF (g_asn_debug = 'Y') THEN
16155 asn_debug.put_line('quantity shipped = ' || l_quantity_shipped);
16156 asn_debug.put_line('secondary qty shipped = ' || l_secondary_quantity_shipped);
16157 END IF;
16158
16159 IF l_quantity_shipped = x_cascaded_table(n).quantity THEN
16160 x_cascaded_table(n).secondary_quantity := l_secondary_quantity_shipped;
16161 END IF;
16162 ELSIF x_cascaded_table(n).receipt_source_code = 'VENDOR'
16163 AND x_cascaded_table(n).shipment_header_id IS NULL
16164 AND x_cascaded_table(n).secondary_quantity IS NULL THEN
16165 -- if the receipt line qty is same as po shipment qty
16166 -- default the po shipment secondary qty to receipt line secondary qty.
16167
16168 BEGIN
16169 SELECT quantity,
16170 secondary_quantity
16171 INTO l_quantity_shipped,
16172 l_secondary_quantity_shipped
16173 FROM po_line_locations
16174 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
16175 EXCEPTION
16176 WHEN OTHERS THEN
16177 NULL;
16178 END;
16179
16180 IF (g_asn_debug = 'Y') THEN
16181 asn_debug.put_line('po shipment qty = ' || l_quantity_shipped);
16182 asn_debug.put_line('po shipment secondary qty = ' || l_secondary_quantity_shipped);
16183 END IF;
16184
16185 IF l_quantity_shipped = x_cascaded_table(n).quantity THEN
16186 x_cascaded_table(n).secondary_quantity := l_secondary_quantity_shipped;
16187 END IF;
16188 END IF;
16189
16190 /*INVCONV, Remove the population of l_opm_record_type and populate l_att_rec. Punit Kumar*/
16191
16192 /*
16193 l_opm_record_type.receipt_source_code := x_cascaded_table(n).receipt_source_code;
16194 l_opm_record_type.to_organization_id := x_cascaded_table(n).to_organization_id;
16195 l_opm_record_type.item_num := x_cascaded_table(n).item_num;
16196 l_opm_record_type.item_id := x_cascaded_table(n).item_id;
16197 l_opm_record_type.unit_of_measure := x_cascaded_table(n).unit_of_measure;
16198 l_opm_record_type.secondary_unit_of_measure := x_cascaded_table(n).secondary_unit_of_measure;
16199 l_opm_record_type.secondary_uom_code := x_cascaded_table(n).secondary_uom_code;
16200 l_opm_record_type.quantity := x_cascaded_table(n).quantity;
16201 l_opm_record_type.secondary_quantity := x_cascaded_table(n).secondary_quantity;
16202 l_opm_record_type.qc_grade := x_cascaded_table(n).qc_grade;
16203 l_opm_record_type.rti_id := x_cascaded_table(n).interface_transaction_id;
16204 -- bug# 3664014
16205 -- added some more parameters. validate_opm_parameters API reads these parameters from
16206 -- rcv_transactions_interface table which does hold the latest data. All the latest data
16207 -- are in the cascaded table.
16208
16209 l_opm_record_type.transaction_type := x_cascaded_table(n).transaction_type;
16210 l_opm_record_type.destination_type_code := x_cascaded_table(n).destination_type_code;
16211 l_opm_record_type.locator_id := x_cascaded_table(n).locator_id;
16212 l_opm_record_type.header_interface_id := x_cascaded_table(n).header_interface_id;
16213 l_opm_record_type.GROUP_ID := x_cascaded_table(n).GROUP_ID;
16214 l_opm_record_type.primary_quantity := x_cascaded_table(n).primary_quantity;
16215 l_opm_record_type.from_locator_id := x_cascaded_table(n).from_locator_id;
16216
16217 IF (g_asn_debug = 'Y') THEN
16218 asn_debug.put_line('unit_of_measure = ' || l_opm_record_type.unit_of_measure);
16219 asn_debug.put_line('secondary unit_of_measure = ' || l_opm_record_type.secondary_unit_of_measure);
16220 asn_debug.put_line('Quantity = ' || l_opm_record_type.quantity);
16221 asn_debug.put_line('Secondary Quantity = ' || l_opm_record_type.secondary_quantity);
16222 asn_debug.put_line('Item Id = ' || l_opm_record_type.item_id);
16223 END IF;
16224
16225 l_opm_record_type.error_record.error_status := 'S';
16226 l_opm_record_type.error_record.error_message := NULL;
16227
16228 */
16229
16230 l_att_rec.inventory_item_id := x_cascaded_table(n).item_id ; /*RTI.item_id */
16231 l_att_rec.transaction_quantity := x_cascaded_table(n).quantity; /*RTI.quantity(transaction quantity)*/
16232 l_att_rec.transaction_unit_of_measure := x_cascaded_table(n).unit_of_measure; /*RTI.UNIT_OF_MEASURE -(transaction unit_of_measure) */
16233 l_att_rec.secondary_quantity := x_cascaded_table(n).secondary_quantity; /*RTI.secondary_quantity */
16234 l_att_rec.secondary_unit_of_measure := x_cascaded_table(n).secondary_unit_of_measure; /*RTI.Secondary_UNIT_OF_MEASURE*/
16235 l_att_rec.secondary_uom_code := x_cascaded_table(n).secondary_uom_code; /*RTI.secondary_uom_code*/
16236 l_att_rec.to_organization_id := x_cascaded_table(n).to_organization_id; /*RTI.to_organization_id*/
16237 ---error handling
16238 l_att_rec.error_record.error_status := 'S';
16239 l_att_rec.error_record.error_message := NULL;
16240 l_transaction_id :=x_cascaded_table(n).interface_transaction_id; /*BUG#10380635 */
16241
16242
16243 IF (g_asn_debug = 'Y') THEN
16244 asn_debug.put_line('printing the values before calling RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
16245 asn_debug.put_line('unit_of_measure = ' || l_att_rec.transaction_unit_of_measure);
16246 asn_debug.put_line('secondary unit_of_measure = ' || l_att_rec.secondary_unit_of_measure);
16247 asn_debug.put_line('Quantity = ' || l_att_rec.transaction_quantity);
16248 asn_debug.put_line('Secondary Quantity = ' || l_att_rec.secondary_quantity);
16249 asn_debug.put_line('Item Id = ' || l_att_rec.inventory_item_id);
16250 asn_debug.put_line('Secondary_uom_code = ' || l_att_rec.secondary_uom_code);
16251 asn_debug.put_line('to organization id = ' || l_att_rec.to_organization_id);
16252 asn_debug.put_line('Transaction_id = ' || l_transaction_id); /*BUG#10380635 */
16253 END IF;
16254
16255 /*INVCONV ,validate_opm_parameters procedure is being called to validate the OPM
16256 specific parameters.Now it shall be replaced with a new routine which shall
16257 validate these parameters for discrete items also.Remove the call to
16258 gml_opm_roi_grp.validate_opm_parameters(l_att_rec) , Punit Kumar
16259 */
16260 /*
16261 gml_opm_roi_grp.validate_opm_parameters(l_opm_record_type);
16262 x_cascaded_table(n).error_status := l_opm_record_type.error_record.error_status;
16263 x_cascaded_table(n).error_message := l_opm_record_type.error_record.error_message;
16264
16265 IF (g_asn_debug = 'Y') THEN
16266 asn_debug.put_line('OPM Error Status = ' || l_opm_record_type.error_record.error_status);
16267 asn_debug.put_line('OPM Error Msg = ' || l_opm_record_type.error_record.error_message);
16268 END IF;
16269 */
16270
16271 IF x_cascaded_table(n).item_id IS NOT NULL THEN
16272
16273 IF (g_asn_debug = 'Y') THEN
16274 asn_debug.put_line('Before calling new API RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
16275 END IF;
16276
16277
16278 RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS (
16279 1.0,
16280 'F',
16281 x_att_rec =>l_att_rec,
16282 x_return_status =>l_return_status,
16283 x_msg_count =>l_msg_count,
16284 x_msg_data =>l_msg_data,
16285 p_transaction_id => l_transaction_id /*BUG#10380635 */
16286 );
16287 END IF;
16288
16289 /* INVCONV , remove the following error handling.Introduced new error handling below*/
16290 /*
16291 IF x_cascaded_table(n).error_status NOT IN('S', 'W') THEN
16292 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
16293
16294 IF (x_cascaded_table(n).error_message = 'PO_PDOI_INVALID_UOM_CODE') THEN
16295 rcv_error_pkg.set_token('VALUE', x_cascaded_table(n).secondary_uom_code);
16296 END IF;
16297 END IF;
16298
16299 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'SECONDARY_UOM_CODE');
16300
16301 */
16302 /* error handling , INVCONV*/
16303 x_cascaded_table(n).error_status := l_att_rec.error_record.error_status;
16304 x_cascaded_table(n).error_message := l_att_rec.error_record.error_message;
16305
16306 IF (g_asn_debug = 'Y') THEN
16307 asn_debug.put_line('After calling new API RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
16308 asn_debug.put_line('return status of RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS = ' || x_cascaded_table(n).error_status);
16309 asn_debug.put_line('return message of RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS = ' || x_cascaded_table(n).error_message);
16310 END IF;
16311
16312
16313 /*If call fails*/
16314 IF x_cascaded_table(n).error_status IN ('U' ,'E') THEN
16315 IF (g_asn_debug = 'Y') THEN
16316 asn_debug.put_line('RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS call failed');
16317 END IF;
16318
16319 /*log error in po_interface_errors*/
16320 rcv_error_pkg.log_interface_message(
16321 x_cascaded_table(n).error_status,
16322 'Secondary Parameter',
16323 FALSE
16324 );
16325 RETURN;
16326 END IF;
16327
16328 /*On successful call populate the following*/
16329 x_cascaded_table(n).secondary_unit_of_measure := l_att_rec.secondary_unit_of_measure;
16330 x_cascaded_table(n).secondary_uom_code := l_att_rec.secondary_uom_code;
16331 x_cascaded_table(n).secondary_quantity := l_att_rec.secondary_quantity;
16332
16333 IF (g_asn_debug = 'Y') THEN
16334 asn_debug.put_line('populating the return values from RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
16335 asn_debug.put_line('secondary unit_of_measure = ' || x_cascaded_table(n).secondary_unit_of_measure);
16336 asn_debug.put_line('Secondary Quantity = ' ||x_cascaded_table(n).secondary_quantity );
16337 asn_debug.put_line('Secondary_uom_code = ' ||x_cascaded_table(n).secondary_uom_code);
16338 END IF;
16339
16340
16341 /* INVCONV ,qc_grade not handled here */
16342 /* x_cascaded_table(n).qc_grade := l_opm_record_type.qc_grade;
16343 */
16344
16345 /* INVCONV, opm installation check no more required */
16346 /*
16347 ELSE --GML_PROCESS_FLAGS.opm_installed <> 1
16348 x_cascaded_table(n).secondary_uom_code := NULL;
16349 x_cascaded_table(n).secondary_unit_of_measure := NULL;
16350 x_cascaded_table(n).secondary_quantity := NULL;
16351 x_cascaded_table(n).qc_grade := NULL;
16352 END IF; -- IF (GML_PROCESS_FLAGS.opm_installed = 1
16353
16354 end , INVCONV */
16355
16356
16357 EXCEPTION
16358 WHEN rcv_error_pkg.e_fatal_error THEN
16359 NULL;
16360 WHEN OTHERS THEN
16361 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16362 rcv_error_pkg.set_sql_error_message('log_interface_error', '000');
16363 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16364 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16365 END validate_opm_attributes;
16366
16367
16368 PROCEDURE get_interface_available_qty(
16369 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16370 n IN BINARY_INTEGER,
16371 x_interface_qty OUT NOCOPY NUMBER
16372 ) IS
16373 l_grandparent_interface_trx_id NUMBER;
16374 l_interface_qty NUMBER;
16375 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
16376 l_parent_uom rcv_transactions_interface.unit_of_measure%TYPE;
16377 l_grandparent_uom rcv_transactions_interface.unit_of_measure%TYPE;
16378 test NUMBER;
16379 BEGIN
16380 x_interface_qty := 0; --Initialise
16381
16382 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
16383 RETURN;
16384 END IF;
16385
16386 BEGIN
16387 SELECT parent_interface_txn_id,
16388 transaction_type,
16389 unit_of_measure,
16390 interface_available_qty
16391 INTO l_grandparent_interface_trx_id,
16392 l_parent_trx_type,
16393 l_parent_uom,
16394 l_interface_qty
16395 FROM rcv_transactions_interface
16396 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16397 EXCEPTION
16398 /* For a receive transaction, both parent_trx_id and
16399 * interface_parent_trx_id will be null.
16400 */
16401 WHEN NO_DATA_FOUND THEN
16402 l_interface_qty := 0;
16403 END;
16404
16405 IF (g_asn_debug = 'Y') THEN
16406 asn_debug.put_line('get_interface_qty l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
16407 asn_debug.put_line('get_interface_qty l_parent_trx_type ' || l_parent_trx_type);
16408 asn_debug.put_line('get_interface_qty l_parent_uom ' || l_parent_uom);
16409 asn_debug.put_line('get_interface_qty l_interface_qty ' || l_interface_qty);
16410 END IF;
16411
16412 IF ( x_cascaded_table(n).transaction_type = 'CORRECT'
16413 AND SIGN(x_cascaded_table(n).quantity) = 1) THEN --{
16414 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN --{
16415 BEGIN
16416 SELECT interface_available_qty,
16417 unit_of_measure
16418 INTO l_interface_qty,
16419 l_grandparent_uom
16420 FROM rcv_transactions_interface
16421 WHERE interface_transaction_id = l_grandparent_interface_trx_id;
16422
16423 /* Should be in terms of parent transaction uom */
16424 x_interface_qty := convert_into_correct_qty(l_interface_qty,
16425 l_grandparent_uom,
16426 x_cascaded_table(n).item_id,
16427 l_parent_uom
16428 );
16429 EXCEPTION
16430 WHEN NO_DATA_FOUND THEN
16431 x_interface_qty := 0;
16432 END;
16433 END IF; --}
16434 ELSE --}{
16435 x_interface_qty := l_interface_qty;
16436 END IF; --}
16437
16438 IF (g_asn_debug = 'Y') THEN
16439 asn_debug.put_line('get_interface_qty x_interface_qty ' || x_interface_qty);
16440 END IF;
16441
16442 x_interface_qty := NVL(x_interface_qty, 0);
16443 EXCEPTION
16444 WHEN OTHERS THEN
16445 x_interface_qty := 0;
16446 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16447 rcv_error_pkg.set_sql_error_message('get_interface_available_qty', '000');
16448 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16449 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16450 END get_interface_available_qty;
16451
16452 PROCEDURE get_interface_available_amt(
16453 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16454 n IN BINARY_INTEGER,
16455 x_interface_amt OUT NOCOPY NUMBER
16456 ) IS
16457 l_grandparent_interface_trx_id NUMBER;
16458 l_interface_amt NUMBER;
16459 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
16460 test NUMBER;
16461 BEGIN
16462 x_interface_amt := 0; --Initialise
16463
16464 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
16465 RETURN;
16466 END IF;
16467
16468 BEGIN
16469 SELECT parent_interface_txn_id,
16470 transaction_type,
16471 interface_available_amt
16472 INTO l_grandparent_interface_trx_id,
16473 l_parent_trx_type,
16474 l_interface_amt
16475 FROM rcv_transactions_interface
16476 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16477 EXCEPTION
16478 /* For a receive transaction, both parent_trx_id and
16479 * interface_parent_trx_id will be null.
16480 */
16481 WHEN NO_DATA_FOUND THEN
16482 l_interface_amt := 0;
16483 END;
16484
16485 IF (g_asn_debug = 'Y') THEN
16486 asn_debug.put_line('get_interface_qty l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
16487 asn_debug.put_line('get_interface_qty l_parent_trx_type ' || l_parent_trx_type);
16488 asn_debug.put_line('get_interface_amt l_interface_amt ' || l_interface_amt);
16489 END IF;
16490
16491 IF ( x_cascaded_table(n).transaction_type = 'CORRECT'
16492 AND SIGN(x_cascaded_table(n).amount) = 1) THEN --{
16493 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN --{
16494 BEGIN
16495 SELECT interface_available_amt
16496 INTO x_interface_amt
16497 FROM rcv_transactions_interface
16498 WHERE interface_transaction_id = l_grandparent_interface_trx_id;
16499 EXCEPTION
16500 WHEN NO_DATA_FOUND THEN
16501 x_interface_amt := 0;
16502 END;
16503 END IF; --}
16504 ELSE --}{
16505 x_interface_amt := l_interface_amt;
16506 END IF; --}
16507
16508 IF (g_asn_debug = 'Y') THEN
16509 asn_debug.put_line('get_interface_amt x_interface_amt ' || x_interface_amt);
16510 END IF;
16511
16512 x_interface_amt := NVL(x_interface_amt, 0);
16513 EXCEPTION
16514 WHEN OTHERS THEN
16515 x_interface_amt := 0;
16516 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16517 rcv_error_pkg.set_sql_error_message('get_interface_available_amt', '000');
16518 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16519 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16520 END get_interface_available_amt;
16521
16522 PROCEDURE update_interface_available_qty(
16523 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16524 n IN BINARY_INTEGER
16525 ) IS
16526 l_grandparent_interface_trx_id NUMBER;
16527 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
16528 l_interface_transaction_qty rcv_transactions_interface.interface_transaction_qty%TYPE := 0;
16529 BEGIN
16530 /* Update interface_available_qty for the current rti row. */
16531 x_cascaded_table(n).interface_available_qty := x_cascaded_table(n).quantity;
16532
16533 IF (g_asn_debug = 'Y') THEN
16534 asn_debug.put_line('update_interace_qty x_interface_qty ' || x_cascaded_table(n).interface_available_qty);
16535 END IF;
16536
16537 /* Update interface_available_qty in the parent rti row */
16538 BEGIN
16539 SELECT parent_interface_txn_id,
16540 transaction_type
16541 INTO l_grandparent_interface_trx_id,
16542 l_parent_trx_type
16543 FROM rcv_transactions_interface
16544 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16545 EXCEPTION
16546 WHEN NO_DATA_FOUND THEN
16547 /* For an rti of receive or an rti row with parent in RT, select
16548 * will not result any rows.
16549 */
16550 NULL;
16551 END;
16552
16553 IF (g_asn_debug = 'Y') THEN
16554 asn_debug.put_line('update_interace_qty l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
16555 asn_debug.put_line('update_interace_qty l_parent_trx_type ' || l_parent_trx_type);
16556 END IF;
16557
16558 IF (x_cascaded_table(n).transaction_type = 'CORRECT') THEN --{
16559 UPDATE rcv_transactions_interface rti
16560 SET rti.interface_available_qty = rti.interface_available_qty + x_cascaded_table(n).quantity
16561 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16562
16563 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN
16564 UPDATE rcv_transactions_interface rti
16565 SET rti.interface_available_qty = rti.interface_available_qty - x_cascaded_table(n).quantity
16566 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
16567 END IF;
16568 ELSE --}{
16569 UPDATE rcv_transactions_interface rti
16570 SET rti.interface_available_qty = rti.interface_available_qty - x_cascaded_table(n).quantity
16571 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16572
16573 IF ( x_cascaded_table(n).transaction_type = 'RETURN TO RECEIVING'
16574 AND l_grandparent_interface_trx_id IS NOT NULL) THEN
16575 UPDATE rcv_transactions_interface rti
16576 SET rti.interface_available_qty = rti.interface_available_qty + x_cascaded_table(n).quantity
16577 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
16578 END IF;
16579 END IF; --}
16580
16581 IF (g_asn_debug = 'Y') THEN
16582 asn_debug.put_line('update_interace_qty calling update_total_transaction_qty ');
16583 END IF;
16584
16585 /* Update temp table with the correct quantity*/
16586 update_total_transaction_qty(x_cascaded_table(n).interface_transaction_id,
16587 x_cascaded_table(n).parent_transaction_id,
16588 x_cascaded_table(n).parent_interface_txn_id,
16589 x_cascaded_table(n).primary_quantity,
16590 x_cascaded_table(n).transaction_type,
16591 l_interface_transaction_qty
16592 );
16593
16594 IF (l_interface_transaction_qty <> 0) THEN
16595 x_cascaded_table(n).interface_transaction_qty := l_interface_transaction_qty;
16596 END IF;
16597 EXCEPTION
16598 WHEN OTHERS THEN
16599 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16600 rcv_error_pkg.set_sql_error_message('update_interface_available_qty', '000');
16601 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16602 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16603 END update_interface_available_qty;
16604
16605 PROCEDURE update_interface_available_amt(
16606 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16607 n IN BINARY_INTEGER
16608 ) IS
16609 l_grandparent_interface_trx_id NUMBER;
16610 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
16611 l_interface_transaction_amt rcv_transactions_interface.interface_transaction_amt%TYPE := 0;
16612 BEGIN
16613 /* Update interface_available_qty for the current rti row. */
16614 x_cascaded_table(n).interface_available_amt := x_cascaded_table(n).amount;
16615
16616 IF (g_asn_debug = 'Y') THEN
16617 asn_debug.put_line('update_interace_qty x_interface_amt ' || x_cascaded_table(n).interface_available_amt);
16618 END IF;
16619
16620 /* Update interface_available_qty in the parent rti row */
16621 BEGIN
16622 SELECT parent_interface_txn_id,
16623 transaction_type
16624 INTO l_grandparent_interface_trx_id,
16625 l_parent_trx_type
16626 FROM rcv_transactions_interface
16627 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16628 EXCEPTION
16629 WHEN NO_DATA_FOUND THEN
16630 /* For an rti of receive or an rti row with parent in RT, select
16631 * will not result any rows.
16632 */
16633 NULL;
16634 END;
16635
16636 IF (g_asn_debug = 'Y') THEN
16637 asn_debug.put_line('update_interface_amt l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
16638 asn_debug.put_line('update_interface_amt l_parent_trx_type ' || l_parent_trx_type);
16639 END IF;
16640
16641 IF (x_cascaded_table(n).transaction_type = 'CORRECT') THEN --{
16642 UPDATE rcv_transactions_interface rti
16643 SET rti.interface_available_amt = rti.interface_available_amt + x_cascaded_table(n).amount
16644 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16645
16646 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN
16647 UPDATE rcv_transactions_interface rti
16648 SET rti.interface_available_amt = rti.interface_available_amt - x_cascaded_table(n).amount
16649 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
16650 END IF;
16651 ELSE --}{
16652 UPDATE rcv_transactions_interface rti
16653 SET rti.interface_available_amt = rti.interface_available_amt - x_cascaded_table(n).amount
16654 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
16655
16656 IF ( x_cascaded_table(n).transaction_type = 'RETURN TO RECEIVING'
16657 AND l_grandparent_interface_trx_id IS NOT NULL) THEN
16658 UPDATE rcv_transactions_interface rti
16659 SET rti.interface_available_amt = rti.interface_available_amt + x_cascaded_table(n).amount
16660 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
16661 END IF;
16662 END IF; --}
16663
16664 IF (g_asn_debug = 'Y') THEN
16665 asn_debug.put_line('update_interface_amt calling update_total_transaction_amt ');
16666 END IF;
16667
16668 /* Update temp table with the correct quantity */
16669 update_total_transaction_amt(x_cascaded_table(n).interface_transaction_id,
16670 x_cascaded_table(n).parent_transaction_id,
16671 x_cascaded_table(n).parent_interface_txn_id,
16672 x_cascaded_table(n).amount,
16673 x_cascaded_table(n).transaction_type,
16674 l_interface_transaction_amt
16675 );
16676
16677 IF (l_interface_transaction_amt <> 0) THEN
16678 x_cascaded_table(n).interface_transaction_amt := l_interface_transaction_amt;
16679 END IF;
16680 EXCEPTION
16681 WHEN OTHERS THEN
16682 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16683 rcv_error_pkg.set_sql_error_message('update_interface_available_amt', '000');
16684 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16685 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16686 END update_interface_available_amt;
16687
16688 PROCEDURE update_total_transaction_qty(
16689 p_interface_transaction_id IN rcv_transactions_interface.interface_transaction_id%TYPE,
16690 p_parent_transaction_id IN rcv_transactions_interface.parent_transaction_id%TYPE,
16691 p_parent_interface_txn_id IN rcv_transactions_interface.parent_interface_txn_id%TYPE,
16692 p_primary_quantity IN rcv_transactions_interface.quantity%TYPE,
16693 p_transaction_type IN rcv_transactions_interface.transaction_type%TYPE,
16694 x_interface_transaction_qty OUT NOCOPY rcv_transactions_interface.interface_transaction_qty%TYPE
16695 ) IS
16696 l_child_count NUMBER;
16697 l_grand_parent_id NUMBER;
16698 BEGIN
16699 x_interface_transaction_qty := 0;
16700
16701 /* Insert into temp table since we need to update this value
16702 * when we process children.
16703 */
16704 IF (g_asn_debug = 'Y') THEN
16705 asn_debug.put_line('update_total_transaction_qty p_parent_transaction_id ' || p_parent_transaction_id);
16706 asn_debug.put_line('update_total_transaction_qty child count ' || l_child_count);
16707 asn_debug.put_line('update_total_transaction_qty p_primary_quantity ' || p_primary_quantity);
16708 END IF;
16709
16710 /* Bug 3459152.
16711 * We need to update interface_transaction_qty for SHIP transaction
16712 * also. Otherwise we will be able to create 2 asn shipment lines
16713 * for the same shipment if they are run in the same group.
16714 */
16715 IF ( ( p_parent_transaction_id IS NULL
16716 AND p_transaction_type IN('RECEIVE', 'SHIP'))
16717 OR (p_parent_transaction_id IS NOT NULL)) THEN --{
16718 IF (g_asn_debug = 'Y') THEN
16719 asn_debug.put_line('update_total_transaction_qty updating rti row with parent' || p_interface_transaction_id || ',quantity ' || p_primary_quantity);
16720 END IF;
16721
16722 x_interface_transaction_qty := p_primary_quantity;
16723 RETURN;
16724 END IF; --}
16725
16726 IF (p_parent_interface_txn_id IS NOT NULL) THEN --{
16727 IF (g_asn_debug = 'Y') THEN
16728 asn_debug.put_line('update_total_transaction_qty parent_interface_txn_id is not null ');
16729 asn_debug.put_line('update_total_transaction_qty p_primary_quantity ' || p_primary_quantity);
16730 END IF;
16731
16732 SELECT parent_transaction_id
16733 INTO l_grand_parent_id
16734 FROM rcv_transactions_interface
16735 WHERE interface_transaction_id = p_parent_interface_txn_id;
16736
16737 IF (g_asn_debug = 'Y') THEN
16738 asn_debug.put_line('update_total_transaction_qty l_grand_parent_id ' || l_grand_parent_id);
16739 END IF;
16740
16741 IF ( (l_grand_parent_id IS NOT NULL)
16742 AND (p_transaction_type = 'CORRECT')) THEN
16743 UPDATE rcv_transactions_interface rti
16744 SET rti.interface_transaction_qty = rti.interface_transaction_qty + p_primary_quantity
16745 WHERE interface_transaction_id = p_parent_interface_txn_id;
16746 END IF;
16747
16748 IF ( (l_grand_parent_id IS NOT NULL)
16749 AND (p_transaction_type = 'RETURN TO RECEIVING')) THEN
16750 UPDATE rcv_transactions_interface rti
16751 SET rti.interface_transaction_qty = rti.interface_transaction_qty - p_primary_quantity
16752 WHERE interface_transaction_id = p_parent_interface_txn_id;
16753 END IF;
16754 END IF; --}
16755 EXCEPTION
16756 WHEN OTHERS THEN
16757 rcv_error_pkg.set_sql_error_message('update_total_transaction_qty', '000');
16758 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16759 RAISE;
16760 END update_total_transaction_qty;
16761
16762 PROCEDURE update_total_transaction_amt(
16763 p_interface_transaction_id IN rcv_transactions_interface.interface_transaction_id%TYPE,
16764 p_parent_transaction_id IN rcv_transactions_interface.parent_transaction_id%TYPE,
16765 p_parent_interface_txn_id IN rcv_transactions_interface.parent_interface_txn_id%TYPE,
16766 p_amount IN rcv_transactions_interface.amount%TYPE,
16767 p_transaction_type IN rcv_transactions_interface.transaction_type%TYPE,
16768 x_interface_transaction_amt OUT NOCOPY rcv_transactions_interface.interface_transaction_amt%TYPE
16769 ) IS
16770 l_child_count NUMBER;
16771 l_grand_parent_id NUMBER;
16772 BEGIN
16773 x_interface_transaction_amt := 0;
16774
16775 /* Insert into temp table since we need to update this value
16776 * when we process children.
16777 */
16778 IF (g_asn_debug = 'Y') THEN
16779 asn_debug.put_line('update_total_transaction_amt p_parent_transaction_id ' || p_parent_transaction_id);
16780 asn_debug.put_line('update_total_transaction_amt child count ' || l_child_count);
16781 asn_debug.put_line('update_total_transaction_amt p_primary_quantity ' || p_amount);
16782 END IF;
16783
16784 IF ( ( p_parent_transaction_id IS NULL
16785 AND p_transaction_type IN('RECEIVE', 'SHIP'))
16786 OR (p_parent_transaction_id IS NOT NULL)) THEN --{
16787 IF (g_asn_debug = 'Y') THEN
16788 asn_debug.put_line('update_total_transaction_amt updating rti row with parent' || p_interface_transaction_id || ',amount ' || p_amount);
16789 END IF;
16790
16791 x_interface_transaction_amt := p_amount;
16792 RETURN;
16793 END IF; --}
16794
16795 IF (p_parent_interface_txn_id IS NOT NULL) THEN --{
16796 IF (g_asn_debug = 'Y') THEN
16797 asn_debug.put_line('update_total_transaction_amt parent_interface_txn_id is not null ');
16798 asn_debug.put_line('update_total_transaction_amt p_amount ' || p_amount);
16799 END IF;
16800
16801 SELECT parent_transaction_id
16802 INTO l_grand_parent_id
16803 FROM rcv_transactions_interface
16804 WHERE interface_transaction_id = p_parent_interface_txn_id;
16805
16806 IF (g_asn_debug = 'Y') THEN
16807 asn_debug.put_line('update_total_transaction_amt l_grand_parent_id ' || l_grand_parent_id);
16808 END IF;
16809
16810 IF ( (l_grand_parent_id IS NOT NULL)
16811 AND (p_transaction_type = 'CORRECT')) THEN
16812 UPDATE rcv_transactions_interface rti
16813 SET rti.interface_transaction_amt = rti.interface_transaction_amt + p_amount
16814 WHERE interface_transaction_id = p_parent_interface_txn_id;
16815 END IF;
16816
16817 IF ( (l_grand_parent_id IS NOT NULL)
16818 AND (p_transaction_type = 'RETURN TO RECEIVING')) THEN
16819 UPDATE rcv_transactions_interface rti
16820 SET rti.interface_transaction_amt = rti.interface_transaction_amt - p_amount
16821 WHERE interface_transaction_id = p_parent_interface_txn_id;
16822 END IF;
16823 END IF; --}
16824 EXCEPTION
16825 WHEN OTHERS THEN
16826 rcv_error_pkg.set_sql_error_message('update_total_transaction_amt', '000');
16827 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
16828 RAISE;
16829 END update_total_transaction_amt;
16830
16831 PROCEDURE derive_matching_basis(
16832 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
16833 n IN BINARY_INTEGER
16834 ) IS
16835 x_progress varchar2(3);
16836 begin
16837 x_progress := '000';
16838
16839 /* Complex Work Start.
16840 * Only for Complex Work POs we can have mixed
16841 * Service and quantity shipments. And for this
16842 * PO we will always have the line and shipment
16843 * information provided. So first get the
16844 * matching_basis from po_line_locations. For
16845 * non complex work POs, all the shipment will
16846 * have the same matching_basis as that of the
16847 * line and hence there wont be a problem if
16848 * the shipment number is given for a service or
16849 * quantity based POs. We will have po_line_id at
16850 * this point since we would have derived it in
16851 * derive_po_line_info.
16852 */
16853 IF (g_asn_debug = 'Y') THEN
16854 asn_debug.put_line('po_line_id '
16855 ||x_cascaded_table(n).po_line_id);
16856 asn_debug.put_line('po_line_location_id '
16857 ||x_cascaded_table(n).po_line_location_id);
16858 asn_debug.put_line('shipment_num '
16859 ||x_cascaded_table(n).document_shipment_line_num);
16860 END IF;
16861
16862 IF(x_cascaded_table(n).po_line_id IS NOT NULL)
16863 AND
16864 (x_cascaded_table(n).po_line_location_id is not null) THEN--{
16865 begin
16866
16867 SELECT NVL(pll.value_basis, 'QUANTITY'),
16868 NVL(pll.matching_basis, 'QUANTITY'),
16869 NVL(pl.purchase_basis,'GOODS')
16870 INTO x_cascaded_table(n).value_basis,
16871 x_cascaded_table(n).matching_basis,
16872 x_cascaded_table(n).purchase_basis
16873 FROM po_line_locations_all pll,
16874 po_lines_all pl
16875 WHERE pl.po_line_id = x_cascaded_table(n).po_line_id
16876 and pl.po_line_id = pll.po_line_id
16877 and pll.line_location_id =x_cascaded_table(n).po_line_location_id;
16878 exception
16879 when no_data_found then
16880 IF (g_asn_debug = 'Y') THEN
16881 asn_debug.put_line('NO data found in derive_match_basis '
16882 ||'for PO shipments with line and line_loc_id info');
16883 END IF;
16884 x_cascaded_table(n).error_status :=
16885 rcv_error_pkg.g_ret_sts_unexp_error;
16886 rcv_error_pkg.set_sql_error_message(
16887 ' when no data in derive_matching_basis '||
16888 'line and line_loc_id info' ,
16889 x_progress);
16890 x_cascaded_table(n).error_message :=
16891 rcv_error_pkg.get_last_message;
16892 when others then
16893 IF (g_asn_debug = 'Y') THEN
16894 asn_debug.put_line('when others in derive_match_basis '
16895 ||'for PO shipments with line and line_loc_id info');
16896 END IF;
16897 x_cascaded_table(n).error_status :=
16898 rcv_error_pkg.g_ret_sts_unexp_error;
16899 rcv_error_pkg.set_sql_error_message(
16900 'when others in derive_matching_basis with '||
16901 'line and line_loc_id info',
16902 x_progress);
16903 x_cascaded_table(n).error_message :=
16904 rcv_error_pkg.get_last_message;
16905 end;
16906 ELSIF((x_cascaded_table(n).po_line_id IS NOT NULL)
16907 AND
16908 (x_cascaded_table(n).document_shipment_line_num is not null)) THEN--}{
16909 begin
16910 SELECT NVL(pll.value_basis, 'QUANTITY'),
16911 NVL(pll.matching_basis, 'QUANTITY'),
16912 NVL(pl.purchase_basis,'GOODS')
16913 INTO x_cascaded_table(n).value_basis,
16914 x_cascaded_table(n).matching_basis,
16915 x_cascaded_table(n).purchase_basis
16916 FROM po_line_locations_all pll,
16917 po_lines_all pl
16918 WHERE pl.po_line_id = x_cascaded_table(n).po_line_id
16919 and pl.po_line_id = pll.po_line_id
16920 and pll.shipment_num =
16921 x_cascaded_table(n).document_shipment_line_num;
16922 exception
16923 when too_many_rows then
16924 IF (g_asn_debug = 'Y') THEN
16925 asn_debug.put_line('too many rows in derive_match_basis ' ||'for PO shipments with line and ship info');
16926 END IF;
16927 x_cascaded_table(n).error_status :=
16928 rcv_error_pkg.g_ret_sts_unexp_error;
16929 rcv_error_pkg.set_sql_error_message(
16930 ' too many rows in derive_matching_basis '||
16931 'line and ship info' ,
16932 x_progress);
16933 x_cascaded_table(n).error_message :=
16934 rcv_error_pkg.get_last_message;
16935 when no_data_found then
16936 IF (g_asn_debug = 'Y') THEN
16937 asn_debug.put_line('NO data found in derive_match_basis ' ||'for PO shipments with line and ship info');
16938 END IF;
16939 x_cascaded_table(n).error_status :=
16940 rcv_error_pkg.g_ret_sts_unexp_error;
16941 rcv_error_pkg.set_sql_error_message(
16942 ' when no data in derive_matching_basis '||
16943 'line and ship info' ,
16944 x_progress);
16945 x_cascaded_table(n).error_message :=
16946 rcv_error_pkg.get_last_message;
16947 when others then
16948 IF (g_asn_debug = 'Y') THEN
16949 asn_debug.put_line('when others in derive_match_basis '
16950 ||'for PO shipments with line and ship info');
16951 END IF;
16952 x_cascaded_table(n).error_status :=
16953 rcv_error_pkg.g_ret_sts_unexp_error;
16954 rcv_error_pkg.set_sql_error_message(
16955 'when others in derive_matching_basis with '||
16956 'line and ship info',
16957 x_progress);
16958 x_cascaded_table(n).error_message :=
16959 rcv_error_pkg.get_last_message;
16960 end;
16961 ELSIF x_cascaded_table(n).po_line_id IS NOT NULL THEN --}{
16962 begin
16963 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
16964 NVL(purchase_basis, 'GOODS'),
16965 NVL(matching_basis, 'QUANTITY')
16966 INTO x_cascaded_table(n).value_basis,
16967 x_cascaded_table(n).purchase_basis,
16968 x_cascaded_table(n).matching_basis
16969 FROM po_lines_all
16970 WHERE po_line_id = x_cascaded_table(n).po_line_id;
16971 exception
16972 when no_data_found then
16973 IF (g_asn_debug = 'Y') THEN
16974 asn_debug.put_line('NO data found in derive_match_basis '
16975 ||'for PO shipments with line info');
16976 END IF;
16977 x_cascaded_table(n).error_status :=
16978 rcv_error_pkg.g_ret_sts_unexp_error;
16979 rcv_error_pkg.set_sql_error_message(
16980 ' when no data in derive_matching_basis with '||
16981 'line info ',
16982 x_progress);
16983 x_cascaded_table(n).error_message :=
16984 rcv_error_pkg.get_last_message;
16985 when others then
16986 IF (g_asn_debug = 'Y') THEN
16987 asn_debug.put_line('when others in derive_match_basis '
16988 ||'for PO shipments with line info');
16989 END IF;
16990 x_cascaded_table(n).error_status :=
16991 rcv_error_pkg.g_ret_sts_unexp_error;
16992 rcv_error_pkg.set_sql_error_message(
16993 'when others in derive_matching_basis with '||
16994 'line info',
16995 x_progress);
16996 x_cascaded_table(n).error_message :=
16997 rcv_error_pkg.get_last_message;
16998 end;
16999 ELSE --}{
17000 -- we require line info for receiving against services lines
17001 x_cascaded_table(n).matching_basis := 'QUANTITY';
17002 x_cascaded_table(n).purchase_basis := 'GOODS';
17003 END IF;
17004
17005 IF (g_asn_debug = 'Y') THEN
17006 asn_debug.put_line('matching_basis ' ||
17007 x_cascaded_table(n).matching_basis);
17008 END IF;
17009 EXCEPTION
17010 WHEN OTHERS THEN
17011 rcv_error_pkg.set_sql_error_message(
17012 'update_total_transaction_amt',
17013 '000');
17014 rcv_error_pkg.log_interface_error(
17015 'TRANSACTIONS_INTERFACE_ID',
17016 FALSE);
17017 RAISE;
17018 END derive_matching_basis;
17019
17020 /* Procedure get_deliver_to_person_from_po() is added as part of Bug#6375015 fix.
17021 get_deliver_to_person_from_po() is called from validate_vendor_rcv_line().
17022 At that point of time, all the defaulting and derivation would have happened,
17023 so po_line_location_id or po_distribution_id would be available.
17024 This procedure tries to default the deliver_to_person_id mentioned in the pod of
17025 Purchase order. If po_distribution_id is not known, it will try to get the
17026 value based on po_line_location only if the poll has got single distribution.
17027 */
17028 PROCEDURE get_deliver_to_person_from_po(
17029 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17030 n IN BINARY_INTEGER
17031 ) IS
17032 l_deliver_to_person_id NUMBER;
17033 l_distribution_count NUMBER;
17034 BEGIN
17035 --At this point po_distribution_id or po_line_location_id would have been derived or defaulted.
17036 IF (g_asn_debug = 'Y') THEN
17037 asn_debug.put_line('Inside get_deliver_to_person_from_po...');
17038 END IF;
17039 IF (x_cascaded_table(n).po_distribution_id is not null) THEN
17040 IF (g_asn_debug = 'Y') THEN
17041 asn_debug.put_line('Inside pod is not null..pod value :'||x_cascaded_table(n).po_distribution_id);
17042 END IF;
17043
17044 BEGIN
17045 select deliver_to_person_id
17046 into l_deliver_to_person_id
17047 from po_distributions_all
17048 where po_distribution_id = x_cascaded_table(n).po_distribution_id;
17049
17050 x_cascaded_table(n).deliver_to_person_id := l_deliver_to_person_id;
17051 IF (g_asn_debug = 'Y') THEN
17052 asn_debug.put_line('defaulted deliver_to_person_id as:'||l_deliver_to_person_id);
17053 END IF;
17054 EXCEPTION
17055 WHEN OTHERS then
17056 IF (g_asn_debug = 'Y') THEN
17057 asn_debug.put_line('Exception occured while getting deliver_to_person_id thru pod');
17058 END IF;
17059 END;
17060 ELSIF (x_cascaded_table(n).po_line_location_id is not null) THEN
17061 IF (g_asn_debug = 'Y') THEN
17062 asn_debug.put_line('Inside poll not null..poll value :'||x_cascaded_table(n).po_line_location_id);
17063 END IF;
17064
17065 BEGIN
17066 select count(po_distribution_id)
17067 into l_distribution_count
17068 from po_distributions_all
17069 where line_location_id = x_cascaded_table(n).po_line_location_id;
17070
17071 IF (g_asn_debug = 'Y') THEN
17072 asn_debug.put_line('Inside poll not null..l_distribution_count:'||l_distribution_count);
17073 END IF;
17074
17075 IF l_distribution_count = 1 THEN
17076 select deliver_to_person_id
17077 into l_deliver_to_person_id
17078 from po_distributions_all
17079 where line_location_id = x_cascaded_table(n).po_line_location_id;
17080
17081 x_cascaded_table(n).deliver_to_person_id := l_deliver_to_person_id;
17082 IF (g_asn_debug = 'Y') THEN
17083 asn_debug.put_line('defaulted deliver_to_person_id as:'||l_deliver_to_person_id);
17084 END IF;
17085 ELSE--l_distribution_count = 1
17086 IF (g_asn_debug = 'Y') THEN
17087 asn_debug.put_line('deliver_to_person_id not defalued as poll has multiple distributions');
17088 END IF;
17089 END IF;--l_distribution_count = 1
17090 EXCEPTION
17091 WHEN OTHERS then
17092 IF (g_asn_debug = 'Y') THEN
17093 asn_debug.put_line('Exception occured while getting deliver_to_person_id thru poll');
17094 END IF;
17095 END;
17096 END IF;--(x_cascaded_table(n).po_distribution_id is not null)
17097 END get_deliver_to_person_from_po;
17098
17099 /* Function get_deliver_to_person_from_rt() is added as part of Bug#6375015 fix.
17100 This function is called from validate_vendor_rcv_line() and it tries to default
17101 the deliver_to_person_id mentioned in the parent transaction(i.e from rcv_transactions).
17102 */
17103 FUNCTION get_deliver_to_person_from_rt(
17104 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17105 n IN BINARY_INTEGER
17106 ) RETURN NUMBER IS
17107 l_parent_deliver_to_person_id NUMBER := null;
17108 BEGIN
17109 select deliver_to_person_id
17110 into l_parent_deliver_to_person_id
17111 from rcv_transactions
17112 where transaction_id = x_cascaded_table(n).parent_transaction_id;
17113
17114 IF (g_asn_debug = 'Y') THEN
17115 asn_debug.put_line('Got deliver_to_person_id of parent txn as:'||l_parent_deliver_to_person_id);
17116 END IF;
17117 return l_parent_deliver_to_person_id;
17118 EXCEPTION
17119 WHEN OTHERS then
17120 IF (g_asn_debug = 'Y') THEN
17121 asn_debug.put_line('Exception occured in get_deliver_to_person_from_rt');
17122 END IF;
17123 return null;
17124 END get_deliver_to_person_from_rt;
17125
17126 /* Function get_deliver_to_person_from_rti() is added as part of Bug#6375015 fix.
17127 This function is called from validate_vendor_rcv_line() and it tries to default
17128 the deliver_to_person_id mentioned in the parent transaction(i.e from rcv_transactions_interface).
17129 */
17130
17131 FUNCTION get_deliver_to_person_from_rti(
17132 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17133 n IN BINARY_INTEGER
17134 ) RETURN NUMBER IS
17135 l_parent_deliver_to_person_id NUMBER := null;
17136 BEGIN
17137 select deliver_to_person_id
17138 into l_parent_deliver_to_person_id
17139 from rcv_transactions_interface
17140 where interface_transaction_id = x_cascaded_table(n).parent_transaction_id;
17141
17142 IF (g_asn_debug = 'Y') THEN
17143 asn_debug.put_line('Got deliver_to_person_id of parent txn as:'||l_parent_deliver_to_person_id);
17144 END IF;
17145 return l_parent_deliver_to_person_id;
17146 EXCEPTION
17147 WHEN OTHERS then
17148 IF (g_asn_debug = 'Y') THEN
17149 asn_debug.put_line('Exception occured in get_deliver_to_person_from_rti');
17150 END IF;
17151 return null;
17152 END get_deliver_to_person_from_rti;
17153
17154 PROCEDURE validate_lcm_line
17155 ( x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17156 n IN binary_integer,
17157 x_asn_type IN rcv_headers_interface.asn_type%type,
17158 x_header_record IN rcv_roi_preprocessor.header_rec_type
17159 ) IS
17160
17161 l_pre_rcv_flag VARCHAR2(1);
17162 l_lcm_shipment_flag VARCHAR2(1);
17163 l_lsl_exists NUMBER := 0;
17164 l_rsl_qty NUMBER;
17165 l_rsl_uom rcv_shipment_lines.unit_of_measure%type;
17166 -- Bug 7607281
17167 l_sec_rsl_qty NUMBER;
17168 l_sec_rsl_uom rcv_shipment_lines.secondary_unit_of_measure%type;
17169 l_lsl_id NUMBER;
17170 v_sobid NUMBER;
17171 l_lcm_date rcv_shipment_headers.conversion_date%type;
17172 p_api_version NUMBER := 1.0;
17173 p_init_msg_list VARCHAR2(1);
17174 p_commit VARCHAR2(1);
17175 x_return_status VARCHAR2(1);
17176 x_msg_count NUMBER;
17177 x_msg_data VARCHAR2(2000);
17178 x_currency_code rcv_transactions.currency_code%type;
17179 x_currency_conversion_type rcv_transactions.currency_conversion_type%type;
17180 x_currency_conversion_rate NUMBER;
17181 -- Bug 10357707
17182 l_functional_currency cst_organization_definitions.currency_code%type;
17183 l_po_currency po_headers_all.currency_code%type;
17184
17185 BEGIN
17186 IF (g_asn_debug = 'Y') THEN
17187 asn_debug.put_line('In validate_lcm_line');
17188 asn_debug.put_line('x_cascaded_table(n).error_status ' || x_cascaded_table(n).error_status);
17189 asn_debug.put_line('x_cascaded_table(n).transaction_type ' || x_cascaded_table(n).transaction_type);
17190 END IF;
17191
17192 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
17193 RETURN;
17194 END IF;
17195
17196 l_pre_rcv_flag := rcv_table_functions.is_pre_rcv_org(x_cascaded_table(n).to_organization_id);
17197 l_lcm_shipment_flag := rcv_table_functions.is_lcm_shipment (x_cascaded_table(n).po_line_location_id);
17198
17199 IF (g_asn_debug = 'Y') THEN
17200 asn_debug.put_line('x_cascaded_table(n).to_organization_id ' || x_cascaded_table(n).to_organization_id);
17201 asn_debug.put_line('l_pre_rcv_flag => ' || l_pre_rcv_flag);
17202 asn_debug.put_line('x_cascaded_table(n).po_line_location_id ' || x_cascaded_table(n).po_line_location_id);
17203 asn_debug.put_line('l_lcm_shipment_flag => ' || l_lcm_shipment_flag);
17204 asn_debug.put_line('x_asn_type => ' || x_asn_type);
17205 END IF;
17206
17207 IF (l_lcm_shipment_flag = 'Y') THEN
17208
17209 IF (x_cascaded_table(n).transaction_type not in ('SHIP','RECEIVE')) THEN
17210 IF (x_cascaded_table(n).lcm_shipment_line_id IS NULL) THEN
17211 --
17212 asn_debug.put_line('Error: lcm_shipment_line_id should not be null ');
17213 x_cascaded_table(n).error_status := 'E';
17214 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NOT_NULL', x_cascaded_table(n).error_message);
17215 rcv_error_pkg.set_token('COLUMN_NAME', 'LCM_SHIPMENT_LINE_ID');
17216 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
17217 --
17218 END IF;
17219 RETURN;
17220 END IF;
17221 IF (l_pre_rcv_flag = 'Y') THEN
17222 IF (x_asn_type = 'ASN') THEN
17223 --
17224 asn_debug.put_line('Error: ' || x_asn_type || ' is not supported as the org is pre-receive enabled ');
17225 x_cascaded_table(n).error_status := 'E';
17226 rcv_error_pkg.set_error_message('RCV_ASN_IMPORT_NOT_ALLOWED', x_cascaded_table(n).error_message);
17227 rcv_error_pkg.set_token('ASN_TYPE',x_asn_type);
17228 rcv_error_pkg.set_token('ORG_ID',x_cascaded_table(n).to_organization_id);
17229 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'ASN_TYPE',FALSE);
17230 RETURN;
17231 --
17232 END IF;
17233 IF (x_cascaded_table(n).lcm_shipment_line_id IS NULL) THEN
17234 --
17235 asn_debug.put_line('Error: lcm_shipment_line_id should not be null ');
17236 x_cascaded_table(n).error_status := 'E';
17237 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NOT_NULL', x_cascaded_table(n).error_message);
17238 rcv_error_pkg.set_token('COLUMN_NAME', 'LCM_SHIPMENT_LINE_ID');
17239 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
17240 RETURN;
17241 --
17242 END IF;
17243 IF (g_asn_debug = 'Y') THEN
17244 asn_debug.put_line('x_cascaded_table(n).lcm_shipment_line_id => ' || x_cascaded_table(n).lcm_shipment_line_id);
17245 END IF;
17246 IF (x_cascaded_table(n).unit_landed_cost IS NULL) THEN
17247 --
17248 asn_debug.put_line('Error: unit_landed_cost should not be null ');
17249 x_cascaded_table(n).error_status := 'E';
17250 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NOT_NULL', x_cascaded_table(n).error_message);
17251 rcv_error_pkg.set_token('COLUMN_NAME', 'UNIT_LANDED_COST');
17252 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'UNIT_LANDED_COST',FALSE);
17253 RETURN;
17254 --
17255 END IF;
17256 IF (g_asn_debug = 'Y') THEN
17257 asn_debug.put_line('x_cascaded_table(n).unit_landed_cost => ' || x_cascaded_table(n).unit_landed_cost);
17258 END IF;
17259 IF (x_asn_type = 'LCM') THEN /* LCM import */
17260 --
17261 SELECT count(1)
17262 INTO l_lsl_exists
17263 FROM rcv_shipment_lines
17264 WHERE lcm_shipment_line_id is not null
17265 AND lcm_shipment_line_id = x_cascaded_table(n).lcm_shipment_line_id;
17266
17267 asn_debug.put_line('Checking RSL: l_lsl_exists => ' || l_lsl_exists, null, 14);
17268
17269 IF (l_lsl_exists = 0) THEN
17270 SELECT count(1)
17271 INTO l_lsl_exists
17272 FROM rcv_transactions_interface
17273 WHERE lcm_shipment_line_id is not null
17274 AND lcm_shipment_line_id = x_cascaded_table(n).lcm_shipment_line_id
17275 AND processing_status_code = 'RUNNING'
17276 AND interface_transaction_id <> x_cascaded_table(n).interface_transaction_id;
17277
17278 asn_debug.put_line('Checking RTI: l_lsl_exists => ' || l_lsl_exists, null, 14);
17279 END IF;
17280
17281 IF (l_lsl_exists > 0) THEN
17282 --
17283 asn_debug.put_line('Error: Duplicate lcm_shipment_line_id');
17284 x_cascaded_table(n).error_status := 'E';
17285 rcv_error_pkg.set_error_message('RCV_DUP_LCM_SHIPMENT_LINE', x_cascaded_table(n).error_message);
17286 rcv_error_pkg.set_token('VALUE', x_cascaded_table(n).lcm_shipment_line_id);
17287 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
17288 RETURN;
17289 --
17290 END IF;
17291 --
17292 END IF;
17293 IF (x_cascaded_table(n).transaction_type = 'RECEIVE' AND
17294 x_cascaded_table(n).shipment_line_id IS NOT NULL) THEN
17295 -- We need to restrict partial receipts of LCM shipment.
17296 SELECT rsl.quantity_shipped,
17297 rsl.unit_of_measure,
17298 rsl.secondary_quantity_shipped,
17299 rsl.secondary_unit_of_measure,
17300 rsl.lcm_shipment_line_id
17301 INTO l_rsl_qty, l_rsl_uom, l_sec_rsl_qty, l_sec_rsl_uom, l_lsl_id
17302 FROM rcv_shipment_lines rsl
17303 WHERE rsl.shipment_line_id = x_cascaded_table(n).shipment_line_id;
17304 --
17305 IF (l_rsl_qty <> x_cascaded_table(n).quantity) THEN
17306 --
17307 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
17308 asn_debug.put_line('l_rsl_qty => ' || l_rsl_qty, null, 14);
17309 asn_debug.put_line('x_cascaded_table(n).quantity => ' || x_cascaded_table(n).quantity, null, 14);
17310 asn_debug.put_line('Error: Partial receipt not allowed');
17311 x_cascaded_table(n).error_status := 'E';
17312 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
17313 rcv_error_pkg.set_token('COLUMN', 'QUANTITY');
17314 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).quantity);
17315 rcv_error_pkg.set_token('SYS_VALUE', l_rsl_qty);
17316 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'QUANTITY',FALSE);
17317 RETURN;
17318 --
17319 END IF;
17320 IF (l_rsl_uom <> x_cascaded_table(n).unit_of_measure) THEN
17321 --
17322 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
17323 asn_debug.put_line('l_rsl_uom => ' || l_rsl_uom, null, 14);
17324 asn_debug.put_line('x_cascaded_table(n).unit_of_measure => ' || x_cascaded_table(n).unit_of_measure, null, 14);
17325 asn_debug.put_line('Error: Partial receipt not allowed');
17326 x_cascaded_table(n).error_status := 'E';
17327 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
17328 rcv_error_pkg.set_token('COLUMN', 'UNIT_OF_MEASURE');
17329 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).unit_of_measure);
17330 rcv_error_pkg.set_token('SYS_VALUE', l_rsl_uom);
17331 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'UNIT_OF_MEASURE',FALSE);
17332 RETURN;
17333 --
17334 END IF;
17335 -- Bug 7607281
17336 IF(x_cascaded_table(n).mobile_txn<>'Y') THEN
17337 IF (nvl (l_sec_rsl_qty, -99) <> nvl(x_cascaded_table(n).secondary_quantity,-99)) THEN
17338 --
17339 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
17340 asn_debug.put_line('l_sec_rsl_qty => ' || l_sec_rsl_qty, null, 14);
17341 asn_debug.put_line('x_cascaded_table(n).secondary_quantity => ' || x_cascaded_table(n).secondary_quantity, null, 14);
17342 asn_debug.put_line('Error: Partial receipt not allowed');
17343 x_cascaded_table(n).error_status := 'E';
17344 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
17345 rcv_error_pkg.set_token('COLUMN', 'SECONDARY_QUANTITY');
17346 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).secondary_quantity);
17347 rcv_error_pkg.set_token('SYS_VALUE', l_sec_rsl_qty);
17348 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_QUANTITY',FALSE);
17349 RETURN;
17350 --
17351 END IF;
17352 --
17353 IF (nvl(l_sec_rsl_uom,'-99') <> nvl(x_cascaded_table(n).secondary_unit_of_measure,'-99')) THEN
17354 --
17355 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
17356 asn_debug.put_line('l_sec_rsl_uom => ' || l_sec_rsl_uom, null, 14);
17357 asn_debug.put_line('x_cascaded_table(n).secondary_unit_of_measure => ' || x_cascaded_table(n).secondary_unit_of_measure, null, 14);
17358 asn_debug.put_line('Error: Partial receipt not allowed');
17359 x_cascaded_table(n).error_status := 'E';
17360 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
17361 rcv_error_pkg.set_token('COLUMN', 'SECONDARY_UNIT_OF_MEASURE');
17362 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).secondary_unit_of_measure);
17363 rcv_error_pkg.set_token('SYS_VALUE', l_sec_rsl_uom);
17364 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
17365 RETURN;
17366 --
17367 END IF;
17368 END IF;
17369
17370 -- Bug 10357707: Start
17371 SELECT cod.currency_code, poh.currency_code
17372 INTO l_functional_currency, l_po_currency
17373 FROM cst_organization_definitions cod,
17374 po_headers_all poh
17375 WHERE cod.operating_unit = poh.org_id
17376 AND cod.organization_id = x_cascaded_table(n).to_organization_id
17377 AND poh.po_header_id = x_cascaded_table(n).po_header_id;
17378
17379 IF (l_functional_currency = l_po_currency) THEN
17380 IF (g_asn_debug = 'Y') THEN
17381 asn_debug.put_line('Returning since PO uses functional currency');
17382 END IF;
17383 RETURN;
17384 END IF;
17385 -- Bug 10357707: End
17386
17387 -- Bug 9689804: Start
17388 inl_integration_grp.Get_CurrencyInfo
17389 ( p_api_version => p_api_version,
17390 p_init_msg_list => p_init_msg_list,
17391 p_commit => p_commit,
17392 p_ship_line_id => l_lsl_id,
17393 x_return_status => x_return_status,
17394 x_msg_count => x_msg_count,
17395 x_msg_data => x_msg_data,
17396 x_currency_code => x_currency_code,
17397 x_currency_conversion_type => x_currency_conversion_type,
17398 x_currency_conversion_date => l_lcm_date,
17399 x_currency_conversion_rate => x_currency_conversion_rate );
17400
17401 asn_debug.put_line('x_return_status : ' || x_return_status);
17402 asn_debug.put_line('x_currency_code : ' || x_currency_code);
17403 asn_debug.put_line('x_currency_conversion_type : ' || x_currency_conversion_type);
17404 asn_debug.put_line('l_lcm_date : ' || l_lcm_date);
17405 asn_debug.put_line('x_currency_conversion_rate : ' || x_currency_conversion_rate);
17406
17407 IF (x_return_status <> 'S') THEN
17408 raise fnd_api.g_exc_error;
17409 END IF;
17410
17411 IF (x_currency_code IS NULL) THEN
17412 x_cascaded_table(n).error_status := 'E';
17413 rcv_error_pkg.set_error_message('RCV_LCM_CURRENCY_CODE_NULL', x_cascaded_table(n).error_message);
17414 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
17415 RETURN;
17416 ELSIF (x_currency_conversion_type IS NULL) THEN
17417 x_cascaded_table(n).error_status := 'E';
17418 rcv_error_pkg.set_error_message('RCV_LCM_CURRENCY_TYPE_NULL', x_cascaded_table(n).error_message);
17419 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
17420 RETURN;
17421 ELSIF (x_currency_conversion_rate IS NULL) THEN
17422 x_cascaded_table(n).error_status := 'E';
17423 rcv_error_pkg.set_error_message('RCV_LCM_CURRENCY_RATE_NULL', x_cascaded_table(n).error_message);
17424 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
17425 RETURN;
17426 ELSIF (l_lcm_date IS NULL) THEN
17427 x_cascaded_table(n).error_status := 'E';
17428 rcv_error_pkg.set_error_message('RCV_LCM_CURRENCY_DATE_NULL', x_cascaded_table(n).error_message);
17429 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
17430 RETURN;
17431 END IF;
17432
17433 x_cascaded_table(n).currency_code := x_currency_code;
17434 x_cascaded_table(n).currency_conversion_type := x_currency_conversion_type;
17435 x_cascaded_table(n).currency_conversion_date := l_lcm_date;
17436 x_cascaded_table(n).currency_conversion_rate := x_currency_conversion_rate;
17437 -- Bug 9689804: End
17438
17439 END IF;
17440 END IF;
17441 ELSE
17442 IF (x_asn_type = 'LCM') THEN
17443 --
17444 asn_debug.put_line('Error: Non-lcm shipment line cannot be attached to an LCM shipment');
17445 x_cascaded_table(n).error_status := 'E';
17446 rcv_error_pkg.set_error_message('RCV_INVALID_LCM_SHIPMENT', x_cascaded_table(n).error_message);
17447 rcv_error_pkg.set_token('SHIPMENT', x_header_record.header_record.shipment_num);
17448 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'PO_LINE_LOCATION_ID',FALSE);
17449 RETURN;
17450 --
17451 END IF;
17452 IF (x_cascaded_table(n).lcm_shipment_line_id IS NOT NULL) THEN
17453 --
17454 asn_debug.put_line('Error: lcm_shipment_line_id should be null for a non-lcm shipment');
17455 x_cascaded_table(n).error_status := 'E';
17456 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NULL', x_cascaded_table(n).error_message);
17457 rcv_error_pkg.set_token('COLUMN_NAME', 'LCM_SHIPMENT_LINE_ID');
17458 rcv_error_pkg.set_token('VALUE', x_cascaded_table(n).lcm_shipment_line_id);
17459 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
17460 RETURN;
17461 --
17462 END IF;
17463
17464 END IF;
17465
17466 IF (g_asn_debug = 'Y') THEN
17467 asn_debug.put_line('Exitting validate_lcm_line');
17468 END IF;
17469
17470 EXCEPTION
17471 WHEN OTHERS THEN
17472 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
17473 rcv_error_pkg.set_sql_error_message('validate_lcm_line' , '000');
17474 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
17475 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
17476
17477 IF (g_asn_debug = 'Y') THEN
17478 asn_debug.put_line('Unexpected exception in validate_lcm_line: ' || SQLERRM);
17479 END IF;
17480
17481 END validate_lcm_line;
17482
17483 -- Bug 7651646
17484 PROCEDURE validate_src_txn(
17485 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17486 n IN BINARY_INTEGER
17487 ) IS
17488 l_count NUMBER := 0;
17489 BEGIN
17490 IF (x_cascaded_table(n).source_transaction_num is not null) THEN
17491 SELECT count(1)
17492 INTO l_count
17493 FROM rcv_transactions
17494 WHERE source_transaction_num = x_cascaded_table(n).source_transaction_num;
17495
17496 asn_debug.put_line('RT l_count : ' || l_count);
17497
17498 IF (l_count = 0) then
17499
17500 SELECT count(1)
17501 INTO l_count
17502 FROM rcv_transactions_interface
17503 WHERE source_transaction_num = x_cascaded_table(n).source_transaction_num
17504 AND processing_status_code = 'RUNNING'
17505 AND interface_transaction_id <> x_cascaded_table(n).interface_transaction_id;
17506
17507 asn_debug.put_line('RTI l_count : ' || l_count);
17508 END IF;
17509
17510 IF (l_count >0 ) then
17511 rcv_error_pkg.set_error_message('RCV_DUP_SRC_TRANSACTION');
17512 rcv_error_pkg.set_token('VALUE',x_cascaded_table(n).source_transaction_num);
17513 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
17514 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
17515 rcv_error_pkg.log_interface_error('SOURCE_TRANSACTION_NUM', FALSE);
17516 END IF;
17517 End IF;
17518 EXCEPTION
17519 WHEN OTHERS then
17520 IF (g_asn_debug = 'Y') THEN
17521 asn_debug.put_line('Exception in the validate_src_txn');
17522 END IF;
17523 END validate_src_txn;
17524
17525 -- <Bug 9342280 : Added for CLM project>
17526 PROCEDURE get_clm_info(p_validate_type VARCHAR2,
17527 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17528 n IN BINARY_INTEGER,
17529 x_is_clm_po IN OUT NOCOPY VARCHAR2,
17530 x_partial_funded_flag IN OUT NOCOPY VARCHAR2) IS
17531
17532 l_distribution_type VARCHAR2(100);
17533 l_matching_basis VARCHAR2(100);
17534 l_accrue_on_receipt_flag VARCHAR2(100);
17535 l_code_combination_id NUMBER;
17536 l_budget_account_id NUMBER;
17537 l_unit_meas_lookup_code VARCHAR2(100);
17538 l_funded_value NUMBER;
17539 l_quantity_funded NUMBER;
17540 l_amount_funded NUMBER;
17541 l_quantity_received NUMBER;
17542 l_amount_received NUMBER;
17543 l_quantity_delivered NUMBER;
17544 l_amount_delivered NUMBER;
17545 l_quantity_billed NUMBER;
17546 l_amount_billed NUMBER;
17547 l_quantity_cancelled NUMBER;
17548 l_amount_cancelled NUMBER;
17549 l_return_status_clm VARCHAR2(100);
17550
17551 BEGIN
17552
17553 IF (x_cascaded_table(n).error_status NOT IN ('S', 'W')) THEN
17554
17555 RETURN;
17556
17557 END IF;
17558
17559 x_is_clm_po := 'N';
17560 x_partial_funded_flag := 'N';
17561
17562 IF (g_asn_debug = 'Y') THEN
17563 asn_debug.put_line('before calling po_clm_intg_grp.is_clm_po()');
17564 END IF;
17565
17566 x_is_clm_po := po_clm_intg_grp.is_clm_po(p_po_header_id => NULL,
17567 p_po_line_id => NULL,
17568 p_po_line_location_id => x_cascaded_table(n).po_line_location_id,
17569 p_po_distribution_id => x_cascaded_table(n).po_distribution_id);
17570
17571 IF (g_asn_debug = 'Y') THEN
17572 asn_debug.put_line('p_po_line_location_id : ' || x_cascaded_table(n).po_line_location_id);
17573 asn_debug.put_line('p_po_distribution_id : ' || x_cascaded_table(n).po_distribution_id);
17574 asn_debug.put_line('x_is_clm_po: ' || x_is_clm_po);
17575 END IF;
17576
17577 IF x_is_clm_po = 'Y' THEN
17578
17579 IF (g_asn_debug = 'Y') THEN
17580 asn_debug.put_line('before calling po_clm_intg_grp.get_funding_info()');
17581 END IF;
17582
17583 po_clm_intg_grp.get_funding_info(p_po_header_id => NULL,
17584 p_po_line_id => NULL,
17585 p_line_location_id => x_cascaded_table(n).po_line_location_id,
17586 p_po_distribution_id => x_cascaded_table(n).po_distribution_id,
17587 x_distribution_type => l_distribution_type,
17588 x_matching_basis => l_matching_basis,
17589 x_accrue_on_receipt_flag => l_accrue_on_receipt_flag,
17590 x_code_combination_id => l_code_combination_id,
17591 x_budget_account_id => l_budget_account_id,
17592 x_partial_funded_flag => x_partial_funded_flag,
17593 x_unit_meas_lookup_code => l_unit_meas_lookup_code,
17594 x_funded_value => l_funded_value,
17595 x_quantity_funded => l_quantity_funded,
17596 x_amount_funded => l_amount_funded,
17597 x_quantity_received => l_quantity_received,
17598 x_amount_received => l_amount_received,
17599 x_quantity_delivered => l_quantity_delivered,
17600 x_amount_delivered => l_amount_delivered,
17601 x_quantity_billed => l_quantity_billed,
17602 x_amount_billed => l_amount_billed,
17603 x_quantity_cancelled => l_quantity_cancelled,
17604 x_amount_cancelled => l_amount_cancelled,
17605 x_return_status => l_return_status_clm);
17606
17607 IF (g_asn_debug = 'Y') THEN
17608 asn_debug.put_line('x_partial_funded_flag : ' || x_partial_funded_flag);
17609 END IF;
17610
17611 IF p_validate_type = 'QUANTITY' THEN
17612 ASN_DEBug.put_line('l_quantity_funded: ' || l_quantity_funded);
17613 asn_debug.put_line('l_quantity_received : ' || l_quantity_received);
17614 asn_debug.put_line('l_quantity_delivered : ' || l_quantity_delivered);
17615 asn_debug.put_line('l_quantity_cancelled: ' || l_quantity_cancelled);
17616 ELSE
17617 asn_debug.put_line('l_amount_funded: ' || l_amount_funded);
17618 asn_debug.put_line('l_amount_received : ' || l_amount_received);
17619 asn_debug.put_line('l_amount_delivered : ' || l_amount_delivered);
17620 asn_debug.put_line('l_amount_cancelled: ' || l_amount_cancelled);
17621 END IF;
17622
17623 END IF;
17624
17625 EXCEPTION
17626 WHEN OTHERS THEN
17627 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
17628 rcv_error_pkg.set_sql_error_message('get_clm_info', '000');
17629 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
17630 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
17631 'po_line_location_id',
17632 FALSE);
17633 IF (g_asn_debug = 'Y') THEN
17634 asn_debug.put_line('Unexpected exception in get_clm_info: ' ||
17635 SQLERRM);
17636 END IF;
17637 END get_clm_info;
17638 -- <CLM END>
17639
17640 -- Bug#9705269 :Start
17641 PROCEDURE validate_shipment_source(
17642 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17643 n IN BINARY_INTEGER
17644 ) IS
17645 l_mmt_transaction_id rcv_shipment_lines.mmt_transaction_id%type;
17646 l_record_exists number := 0;
17647 x_error_status VARCHAR2(1);
17648 BEGIN
17649 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
17650 RETURN;
17651 END IF;
17652
17653 x_error_status := rcv_error_pkg.g_ret_sts_error;
17654 asn_debug.put_line('Before rcv_roi_transaction.validate_shipment_source');
17655 asn_debug.put_line('shipment_line_id: '||x_cascaded_table(n).shipment_line_id);
17656
17657 IF x_cascaded_table(n).shipment_line_id IS NOT NULL THEN
17658 SELECT mmt_transaction_id
17659 INTO l_mmt_transaction_id
17660 FROM rcv_shipment_lines
17661 WHERE shipment_line_id = x_cascaded_table(n).shipment_line_id;
17662
17663 IF l_mmt_transaction_id IS NOT NULL THEN
17664 SELECT COUNT(*)
17665 INTO l_record_exists
17666 FROM mtl_material_transactions
17667 WHERE transaction_id = l_mmt_transaction_id;
17668
17669 IF l_record_exists = 0 THEN
17670 rcv_error_pkg.set_error_message('RCV_INVALID_SHIPMENT_SOURCE');
17671 RAISE e_validation_error;
17672 END IF;
17673 END IF;
17674 END IF;
17675 asn_debug.put_line('after rcv_roi_transaction.validate_shipment_source');
17676 EXCEPTION
17677 WHEN rcv_error_pkg.e_fatal_error THEN
17678 NULL;
17679 WHEN e_validation_error THEN
17680 x_cascaded_table(n).error_status := x_error_status;
17681 x_cascaded_table(n).error_message:= rcv_error_pkg.get_last_message;
17682 rcv_error_pkg.set_token('MMT_TXN_ID', l_mmt_transaction_id);
17683 rcv_error_pkg.set_token('RSL_ID', x_cascaded_table(n).shipment_line_id);
17684 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'MMT_TRANSACTION_ID',FALSE);
17685 END validate_shipment_source;
17686 -- Bug#9705269 :End
17687
17688 -- rtv project : start
17689 PROCEDURE validate_parent_rtv
17690 ( x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
17691 n IN BINARY_INTEGER) IS
17692
17693 l_count number := 0;
17694 BEGIN
17695 IF (x_cascaded_table(n).error_status NOT IN ('S', 'W')) THEN
17696 RETURN;
17697 END IF;
17698
17699 IF (x_cascaded_table(n).transaction_type = 'CORRECT' and x_cascaded_table(n).po_header_id is not null ) THEN
17700 select count(*)
17701 into l_count
17702 from rcv_transactions rt,
17703 wsh_delivery_details wdd
17704 where rt.transaction_id = x_cascaded_table(n).parent_transaction_id
17705 and rt.transaction_type in ('RETURN TO RECEIVING', 'RETURN TO VENDOR')
17706 and rt.interface_source_line_id = wdd.delivery_detail_id
17707 and wdd.source_code ='RTV';
17708
17709 IF ( l_count > 0 ) THEN
17710 rcv_error_pkg.set_error_message ('RCV_RTV_CORRECT_NOT_ALLOWED');
17711 rcv_error_pkg.set_token('RTV_PARENT', x_cascaded_table(n).PARENT_TRANSACTION_ID);
17712 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
17713 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
17714 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PARENT_TRANSACTION_ID', FALSE );
17715 END IF;
17716 END IF;
17717
17718 EXCEPTION
17719 WHEN OTHERS THEN
17720 rcv_error_pkg.set_sql_error_message('validate_parent_rtv', '000');
17721 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
17722 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
17723 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
17724 END validate_parent_rtv;
17725 -- rtv project: end
17726
17727 END rcv_roi_transaction;