1 PACKAGE BODY rcv_roi_transaction
2 /* $Header: RCVPRETB.pls 120.41.12010000.3 2008/12/26 20:15:38 vthevark ship $*/
3 AS
4 g_asn_debug VARCHAR2(1) := NVL(fnd_profile.VALUE('RCV_DEBUG_MODE'), 'N');
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 PROCEDURE derive_vendor_rcv_line(
12 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
13 n IN OUT NOCOPY BINARY_INTEGER,
14 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15 x_header_record IN rcv_roi_preprocessor.header_rec_type
16 ) IS
17 l_po_header_id po_headers_all.po_header_id%type;
18 l_return_status VARCHAR2(1) :='S';
19 l_complex_flag varchar2(1);
20 l_interface_source_code rcv_transactions_interface.interface_source_code%type;
21 BEGIN
22 x_progress := '000';
23 -- Derive PO header and line at the beginning to differentiate between services/goods matching basis
24 -- 1) derive po header info
25 derive_po_header_info(x_cascaded_table, n);
26 derive_asn_header_info(x_cascaded_table,
27 n,
28 x_header_record
29 );
30 /* Bug 3588165 : Moved the call to derive_ship_to_org_info() before
31 derive_po_line_info(). This is done since derive_po_line_info()
32 uses the To_Organization_Id information to derive the
33 Primary_Unit_Of_Measure. Earlier Primary UOM used to be null
34 and the UOM conversion Procedure was raising an exception.
35 */
36
37 -- 2) derive ship to org info
38 derive_ship_to_org_info(x_cascaded_table,
39 n,
40 x_header_record
41 );
42 x_progress := '001';
43 -- 3) derive po line info
44 derive_po_line_info(x_cascaded_table, n);
45 x_progress := '002';
46
47 IF (g_asn_debug = 'Y') THEN
48 asn_debug.put_line('X_progress ' || x_progress);
49 END IF;
50
51 /* R12 Complex Work.
52 * We should be able to create Work Confirmations only through
53 * the iSP screen.
54 */
55
56 l_po_header_id := x_cascaded_table(n).po_header_id;
57
58 PO_COMPLEX_WORK_GRP.is_complex_work_po(
59 1.0,
60 l_po_header_id,
61 l_return_status,
62 l_complex_flag);
63 IF (l_return_status IS NOT NULL AND
64 l_return_status = FND_API.g_ret_sts_success) THEN
65 IF( g_asn_debug = 'Y' ) THEN
66 asn_debug.put_line('l_return_status ' || l_return_status);
67 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
68 END IF;
69 ELSE
70 IF( g_asn_debug = 'Y') THEN
71 asn_debug.put_line('l_return_status ' || l_return_status);
72 END IF;
73 END IF;
74
75 IF (l_complex_flag = 'Y') THEN
76
77 l_interface_source_code :=
78 x_cascaded_table(n).interface_source_code;
79
80 if (x_cascaded_table(n).transaction_type = 'SHIP' and
81 l_interface_source_code <> 'ISP') then
82 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');
83 rcv_error_pkg.set_error_message('RCV_INVALID_TRANSACTION_TYPE');
84 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
85 end if;
86 /* Receipt for Work Confirmation does not come through
87 * preprocessor. Hence error out.
88 */
89 if (x_cascaded_table(n).transaction_type = 'RECEIVE') then
90 asn_debug.put_line('You cannot process a receipt against this PO using the Open Interface. Please create a Work Confirmation request instead.');
91 rcv_error_pkg.set_error_message('RCV_WC_CREATE');
92 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
93
94 end if;
95 End if;
96
97
98 -- 4) derive vendor information
99 derive_vendor_info(x_cascaded_table, n);
100 x_progress := '004';
101
102 IF (g_asn_debug = 'Y') THEN
103 asn_debug.put_line('X_progress ' || x_progress);
104 END IF;
105
106 -- 5) derive vendor site info
107 /* Call derive vendor_site_procedure here */
108 /* UK1 -> vendor_site_id
109 UK2 -> vendor_site_code + vendor_id + org_id */
110 derive_vendor_site_info(x_cascaded_table, n);
111 x_progress := '005';
112
113 IF (g_asn_debug = 'Y') THEN
114 asn_debug.put_line('X_progress ' || x_progress);
115 END IF;
116
117 -- 6) derive item info
118 derive_item_info(x_cascaded_table, n);
119 x_progress := '010';
120 -- 7) derive substitute item info
121 derive_substitute_item_info(x_cascaded_table, n);
122 x_progress := '020';
123 -- 8) derive from org info
124 derive_from_org_info(x_cascaded_table, n);
125 x_progress := '035';
126 -- 9) derive in transit org info
127 derive_transit_org_info(x_cascaded_table, n);
128 x_progress := '040';
129 -- 10) derive location info
130 derive_location_info(x_cascaded_table, n);
131 x_progress := '045';
132 -- 11) derive ship to location info
133 derive_ship_to_location_info(x_cascaded_table, n);
134 x_progress := '050';
135 -- 12) derive routing header info
136 derive_routing_header_info(x_cascaded_table, n);
137 x_progress := '070';
138 -- 13) derive routing step info
139 derive_routing_step_info(x_cascaded_table, n);
140 x_progress := '080';
141 -- 14) derive deliver to person info
142 derive_deliver_to_person_info(x_cascaded_table, n);
143 x_progress := '085';
144 -- 14) derive deliver to loc info
145 derive_deliver_to_loc_info(x_cascaded_table, n);
146 x_progress := '090';
147 -- 15) derive subinv/locator info
148 --derive_locator_info(x_cascaded_table, n);
149 --derive_from_locator_id(x_cascaded_table, n); -- WMS Change
150 derive_to_locator_id(x_cascaded_table, n); -- WMS Change
151 x_progress := '091';
152 -- 16) derive reason info
153 derive_reason_info(x_cascaded_table, n);
154 x_progress := '092';
155 -- derive auto transact code
156 derive_auto_transact_code(x_cascaded_table, n);
157
158 -- quantity > 0
159 /* Complex Work Start.
160 * We have a separate procedure derive_matching_basis
161 * to get the matching basis now. This is because we
162 * are going to get the matching_basis from
163 * po_line_locations and hence moved it from
164 * derive_po_line_info.
165 */
166 IF (g_asn_debug = 'Y') THEN
167 asn_debug.put_line('Before calling derive matching basis ');
168 END IF;
169 derive_matching_basis(x_cascaded_table,n);
170
171 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
172 derive_vendor_rcv_line_amt(x_cascaded_table,
173 n,
174 temp_cascaded_table,
175 x_header_record
176 );
177 ELSE
178 derive_vendor_rcv_line_qty(x_cascaded_table,
179 n,
180 temp_cascaded_table,
181 x_header_record
182 );
183 END IF;
184 /* Complex Work.
185 * Add exception block.
186 */
187 exception
188 when others then
189 IF (g_asn_debug = 'Y') THEN
190 asn_debug.put_line('Exception in derive_vendor_rcv_line '||x_progress);
191 END IF;
192 raise;
193 END derive_vendor_rcv_line;
194
195 PROCEDURE default_vendor_rcv_line(
196 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
197 n IN BINARY_INTEGER,
198 x_header_id IN rcv_headers_interface.header_interface_id%TYPE,
199 x_header_record IN rcv_roi_preprocessor.header_rec_type
200 ) IS
201 x_progress VARCHAR2(3);
202 x_locator_control NUMBER;
203 x_default_subinventory VARCHAR2(10);
204 x_default_locator_id NUMBER;
205 x_success BOOLEAN;
206 x_tax_name VARCHAR2(50); -- Bug 6331613
207 x_vendor_site_id NUMBER;
208 x_vendor_site_code VARCHAR2(20);
209 item_id_record rcv_shipment_line_sv.item_id_record_type;
210
211 /* bug2382337:
212 * Change the name of the parameters passed into the cursor
213 */
214 CURSOR shipments(
215 v_header_id NUMBER,
216 v_line_id NUMBER,
217 v_line_location_id NUMBER
218 ) IS
219 SELECT ph.revision_num,
220 pl.line_num,
221 nvl(pll.description,pl.item_description) item_description,--Complex work
222 pll.tax_code_id,
223 pll.po_release_id,
224 pll.ship_to_location_id,
225 pll.ship_to_organization_id,
226 pll.shipment_num,
227 pll.receiving_routing_id,
228 pll.country_of_origin_code,
229 pl.job_id,
230 pll.value_basis , --Complex Work
231 pl.purchase_basis,
232 pll.matching_basis --Complex Work
233 FROM po_line_locations pll,
234 po_lines pl,
235 po_headers ph
236 WHERE ph.po_header_id = pl.po_header_id
237 AND pl.po_line_id = pll.po_line_id
238 AND ph.po_header_id = v_header_id
239 AND pl.po_line_id = v_line_id
240 AND pll.line_location_id = v_line_location_id
241 AND NVL(pll.approved_flag, 'N') = 'Y'
242 AND NVL(pll.cancel_flag, 'N') = 'N'
243 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED'
244 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT');
245
246 default_po_info shipments%ROWTYPE;
247 BEGIN
248 IF (g_asn_debug = 'Y') THEN
249 asn_debug.put_line('Enter default_shipment_line');
250 END IF;
251
252 x_progress := '000';
253 -- set default_shipment_line values
254
255 x_cascaded_table(n).header_interface_id := x_header_id;
256 x_cascaded_table(n).shipment_line_status_code := 'OPEN';
257
258 IF x_cascaded_table(n).source_document_code IS NULL THEN
259 x_cascaded_table(n).source_document_code := 'PO';
260
261 IF (g_asn_debug = 'Y') THEN
262 asn_debug.put_line('Defaulting SOURCE_DOCUMENT_CODE ' || x_cascaded_table(n).source_document_code);
263 END IF;
264 END IF;
265
266 /* Fix for bug 2564646.
267 If AUTO_TRANSACT_CODE is RECEIVE then it means it is a receive
268 transaction and destination_type_code should be RECEIVING. Even
269 if the end user populates destination_type_code as INVENTORY
270 when AUTO_TRANSACT_CODE is RECEIVE, we now overwrite the value
271 of DESTINATION_TYPE_CODE to RECEIVING by adding the OR condition
272 to the following IF statement.
273 */
274 IF x_cascaded_table(n).destination_type_code IS NULL
275 OR ( x_cascaded_table(n).destination_type_code = 'INVENTORY'
276 AND x_cascaded_table(n).auto_transact_code = 'RECEIVE') THEN
277 x_cascaded_table(n).destination_type_code := 'RECEIVING';
278
279 IF (g_asn_debug = 'Y') THEN
280 asn_debug.put_line('Defaulting DESTINATION_TYPE_CODE ' || x_cascaded_table(n).destination_type_code);
281 END IF;
282 END IF;
283
284 IF x_cascaded_table(n).transaction_type IS NULL THEN
285 x_cascaded_table(n).transaction_type := 'SHIP';
286
287 IF (g_asn_debug = 'Y') THEN
288 asn_debug.put_line('Defaulting TRANSACTION_TYPE ' || x_cascaded_table(n).transaction_type);
289 END IF;
290 END IF;
291
292 IF x_cascaded_table(n).processing_mode_code IS NULL THEN
293 x_cascaded_table(n).processing_mode_code := 'BATCH';
294
295 IF (g_asn_debug = 'Y') THEN
296 asn_debug.put_line('Defaulting PROCESSING_MODE_CODE ' || x_cascaded_table(n).processing_mode_code);
297 END IF;
298 END IF;
299
300 x_cascaded_table(n).processing_status_code := 'RUNNING';
301
302 IF x_cascaded_table(n).processing_status_code IS NULL THEN
303 -- This has to be set to running otherwise C code in rvtbm
304 -- will not pick it up
305 x_cascaded_table(n).processing_status_code := 'RUNNING';
306
307 IF (g_asn_debug = 'Y') THEN
308 asn_debug.put_line('Defaulting PROCESSING_STATUS_CODE ' || x_cascaded_table(n).processing_status_code);
309 END IF;
310 END IF;
311
312 IF x_cascaded_table(n).transaction_status_code IS NULL THEN
313 x_cascaded_table(n).transaction_status_code := 'PENDING';
314
315 IF (g_asn_debug = 'Y') THEN
316 asn_debug.put_line('Defaulting TRANSACTION_STATUS_CODE ' || x_cascaded_table(n).transaction_status_code);
317 END IF;
318 END IF;
319
320 -- Default auto_transact_code if it is null
321 IF x_cascaded_table(n).auto_transact_code IS NULL THEN
322 IF (g_asn_debug = 'Y') THEN
323 asn_debug.put_line('Setting auto_transact_code to transaction_type ' || x_cascaded_table(n).transaction_type);
324 END IF;
325
326 x_cascaded_table(n).auto_transact_code := x_cascaded_table(n).transaction_type;
327 END IF;
328
329 -- default only if all attributes are null
330 IF x_cascaded_table(n).vendor_id IS NULL
331 AND x_cascaded_table(n).vendor_name IS NULL
332 AND x_cascaded_table(n).vendor_num IS NULL THEN --{
333 x_cascaded_table(n).vendor_id := x_header_record.header_record.vendor_id;
334 x_cascaded_table(n).vendor_name := x_header_record.header_record.vendor_name;
335 x_cascaded_table(n).vendor_num := x_header_record.header_record.vendor_num;
336
337 IF (g_asn_debug = 'Y') THEN
338 asn_debug.put_line('Defaulting from HEADER VENDOR_ID ' || TO_CHAR(x_cascaded_table(n).vendor_id));
339 asn_debug.put_line('Defaulting from HEADER VENDOR_NAME ' || x_cascaded_table(n).vendor_name);
340 asn_debug.put_line('Defaulting from HEADER VENDOR_NUM ' || x_cascaded_table(n).vendor_num);
341 END IF;
342 END IF; --}
343
344 -- default only if all attributes are null
345
346 IF x_cascaded_table(n).vendor_site_id IS NULL
347 AND x_cascaded_table(n).vendor_site_code IS NULL THEN --{
348 x_cascaded_table(n).vendor_site_id := x_header_record.header_record.vendor_site_id;
349 x_cascaded_table(n).vendor_site_code := x_header_record.header_record.vendor_site_code;
350
351 /* Fix for bug 2296720.
352 If both vendor_site_id and vendor_site_code are not populated
353 in interface tables, and if there are multiple vendor sites
354 associated to a particular vendor then we default them from PO
355 using the po_header_id of rcv_transactions_interface for each
356 line.
357 */
358 IF x_cascaded_table(n).vendor_site_id IS NULL
359 AND x_cascaded_table(n).vendor_site_code IS NULL THEN --{
360 SELECT vendor_site_id
361 INTO x_vendor_site_id
362 FROM po_headers
363 WHERE po_header_id = x_cascaded_table(n).po_header_id
364 AND vendor_id = x_cascaded_table(n).vendor_id;
365
366 SELECT vendor_site_code
367 INTO x_vendor_site_code
368 FROM po_vendor_sites
369 WHERE vendor_site_id = x_vendor_site_id
370 AND vendor_id = x_cascaded_table(n).vendor_id;
371
372 x_cascaded_table(n).vendor_site_id := x_vendor_site_id;
373 x_cascaded_table(n).vendor_site_code := x_vendor_site_code;
374 END IF; --}
375
376 IF (g_asn_debug = 'Y') THEN
377 asn_debug.put_line('Defaulting from HEADER VENDOR_SITE_ID ' || TO_CHAR(x_cascaded_table(n).vendor_site_id));
378 asn_debug.put_line('Defaulting from HEADER VENDOR_SITE_CODE ' || x_cascaded_table(n).vendor_site_code);
379 END IF;
380 END IF; --}
381
382 -- default only if all attributes are null
383
384 IF x_cascaded_table(n).from_organization_id IS NULL
385 AND x_cascaded_table(n).from_organization_code IS NULL THEN
386 x_cascaded_table(n).from_organization_id := x_header_record.header_record.from_organization_id;
387 x_cascaded_table(n).from_organization_code := x_header_record.header_record.from_organization_code;
388
389 IF (g_asn_debug = 'Y') THEN
390 asn_debug.put_line('Defaulting from HEADER FROM_ORGANIZATION_ID ' || TO_CHAR(x_cascaded_table(n).from_organization_id));
391 asn_debug.put_line('Defaulting from HEADER FROM_ORGANIZATION_CODE ' || x_cascaded_table(n).from_organization_code);
392 END IF;
393 END IF;
394
395 -- default only if all attributes are null
396 IF x_cascaded_table(n).to_organization_id IS NULL
397 AND x_cascaded_table(n).to_organization_code IS NULL THEN
398 x_cascaded_table(n).to_organization_id := x_header_record.header_record.ship_to_organization_id;
399 x_cascaded_table(n).to_organization_code := x_header_record.header_record.ship_to_organization_code;
400
401 IF (g_asn_debug = 'Y') THEN
402 asn_debug.put_line('Defaulting from HEADER TO_ORGANIZATION_ID ' || TO_CHAR(x_cascaded_table(n).to_organization_id));
403 asn_debug.put_line('Defaulting from HEADER TO_ORGANIZATION_CODE ' || x_cascaded_table(n).to_organization_code);
404 END IF;
405 END IF;
406
407 -- default only if all attributes are null
408 IF x_cascaded_table(n).currency_code IS NULL
409 AND x_cascaded_table(n).currency_conversion_type IS NULL
410 AND x_cascaded_table(n).currency_conversion_rate IS NULL
411 AND x_cascaded_table(n).currency_conversion_date IS NULL THEN --{
412 x_cascaded_table(n).currency_code := x_header_record.header_record.currency_code;
413 x_cascaded_table(n).currency_conversion_type := x_header_record.header_record.conversion_rate_type;
414 x_cascaded_table(n).currency_conversion_rate := x_header_record.header_record.conversion_rate;
415 x_cascaded_table(n).currency_conversion_date := x_header_record.header_record.conversion_rate_date;
416
417 IF (g_asn_debug = 'Y') THEN
418 asn_debug.put_line('Defaulting from HEADER CURRENCY_CODE ' || x_cascaded_table(n).currency_code);
419 asn_debug.put_line('Defaulting from HEADER CURRENCY_CONVERSION_TYPE ' || x_cascaded_table(n).currency_conversion_type);
420 asn_debug.put_line('Defaulting from HEADER CURRENCY_CONVERSION_RATE ' || TO_CHAR(x_cascaded_table(n).currency_conversion_rate));
421 asn_debug.put_line('Defaulting from HEADER CURRENCY_CONVERSION_DATE ' || TO_CHAR(x_cascaded_table(n).currency_conversion_date, 'DD/MM/YYYY'));
422 END IF;
423 END IF; --}
424
425 IF ( x_cascaded_table(n).ship_to_location_id IS NULL
426 AND x_cascaded_table(n).ship_to_location_code IS NULL) THEN -- Check this with George
427 x_cascaded_table(n).ship_to_location_code := x_header_record.header_record.location_code;
428 x_cascaded_table(n).ship_to_location_id := x_header_record.header_record.location_id;
429
430 IF (g_asn_debug = 'Y') THEN
431 asn_debug.put_line('Defaulting from HEADER LOCATION_ID ' || TO_CHAR(x_cascaded_table(n).location_id));
432 END IF;
433 END IF;
434
435 IF x_cascaded_table(n).shipment_num IS NULL THEN
436 x_cascaded_table(n).shipment_num := x_header_record.header_record.shipment_num;
437
438 IF (g_asn_debug = 'Y') THEN
439 asn_debug.put_line('Defaulting from HEADER SHIPMENT_NUM ' || x_cascaded_table(n).shipment_num);
440 END IF;
441 END IF;
442
443 IF x_cascaded_table(n).freight_carrier_code IS NULL THEN
444 x_cascaded_table(n).freight_carrier_code := x_header_record.header_record.freight_carrier_code;
445
446 IF (g_asn_debug = 'Y') THEN
447 asn_debug.put_line('Defaulting from HEADER FREIGHT_CARRIER_CODE ' || x_cascaded_table(n).freight_carrier_code);
448 END IF;
449 END IF;
450
451 IF x_cascaded_table(n).bill_of_lading IS NULL THEN
452 x_cascaded_table(n).bill_of_lading := x_header_record.header_record.bill_of_lading;
453
454 IF (g_asn_debug = 'Y') THEN
455 asn_debug.put_line('Defaulting from HEADER BILL_OF_LADING ' || x_cascaded_table(n).bill_of_lading);
456 END IF;
457 END IF;
458
459 IF x_cascaded_table(n).packing_slip IS NULL THEN
460 x_cascaded_table(n).packing_slip := x_header_record.header_record.packing_slip;
461
462 IF (g_asn_debug = 'Y') THEN
463 asn_debug.put_line('Defaulting from HEADER PACKING_SLIP ' || x_cascaded_table(n).packing_slip);
464 END IF;
465 END IF;
466
467 IF x_cascaded_table(n).shipped_date IS NULL THEN
468 x_cascaded_table(n).shipped_date := x_header_record.header_record.shipped_date;
469
470 IF (g_asn_debug = 'Y') THEN
471 asn_debug.put_line('Defaulting from HEADER SHIPPED_DATE ' || TO_CHAR(x_cascaded_table(n).shipped_date, 'DD/MM/YYYY'));
472 END IF;
473 END IF;
474
475 IF x_cascaded_table(n).expected_receipt_date IS NULL THEN
476 x_cascaded_table(n).expected_receipt_date := x_header_record.header_record.expected_receipt_date;
477
478 IF (g_asn_debug = 'Y') THEN
479 asn_debug.put_line('Defaulting from HEADER EXPECTED_RECEIPT_DATE ' || TO_CHAR(x_cascaded_table(n).expected_receipt_date, 'DD/MM/YYYY'));
480 END IF;
481 END IF;
482
483 IF x_cascaded_table(n).num_of_containers IS NULL
484 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
485 x_cascaded_table(n).num_of_containers := x_header_record.header_record.num_of_containers;
486
487 IF (g_asn_debug = 'Y') THEN
488 asn_debug.put_line('Defaulting from HEADER NUM_OF_CONTAINERS ' || TO_CHAR(x_cascaded_table(n).num_of_containers));
489 END IF;
490 END IF;
491
492 IF x_cascaded_table(n).waybill_airbill_num IS NULL
493 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
494 x_cascaded_table(n).waybill_airbill_num := x_header_record.header_record.waybill_airbill_num;
495
496 IF (g_asn_debug = 'Y') THEN
497 asn_debug.put_line('Defaulting from HEADER WAYBILL_AIRBILL_NUM ' || x_cascaded_table(n).waybill_airbill_num);
498 END IF;
499 END IF;
500
501 IF x_cascaded_table(n).tax_name IS NULL THEN
502 x_cascaded_table(n).tax_name := x_header_record.header_record.tax_name;
503
504 IF (g_asn_debug = 'Y') THEN
505 asn_debug.put_line('Defaulting from HEADER TAX_NAME ' || x_cascaded_table(n).tax_name);
506 END IF;
507 END IF;
508
509 /* Bug 3299421 : WMS Mobile applications do not need the item_revision to
510 be defaulted during preprocessing for transactions other than
511 "Deliver". Added the condition in the If clause where we
512 check if the transaction is from mobile and if so do not
513 default the item revision.
514 */
515 IF x_cascaded_table(n).item_revision IS NULL
516 AND (NVL(x_cascaded_table(n).mobile_txn, 'N') = 'N')
517 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN --{
518 IF (g_asn_debug = 'Y') THEN
519 asn_debug.put_line('Enter defaulting item revision');
520 END IF;
521
522 item_id_record.item_id := x_cascaded_table(n).item_id;
523 item_id_record.po_line_id := x_cascaded_table(n).po_line_id;
524 item_id_record.po_line_location_id := x_cascaded_table(n).po_line_location_id;
525 item_id_record.to_organization_id := x_cascaded_table(n).to_organization_id;
526 item_id_record.item_revision := x_cascaded_table(n).item_revision;
527 item_id_record.error_record.error_status := 'S';
528 item_id_record.error_record.error_message := NULL;
529 rcv_transactions_interface_sv.default_item_revision(item_id_record);
530 x_cascaded_table(n).item_revision := item_id_record.item_revision;
531
532 IF (g_asn_debug = 'Y') THEN
533 asn_debug.put_line(NVL(item_id_record.item_revision, 'Item Revision is null'));
534 END IF;
535
536 x_cascaded_table(n).error_status := item_id_record.error_record.error_status;
537 x_cascaded_table(n).error_message := item_id_record.error_record.error_message;
538 END IF; --}
539
540 IF x_cascaded_table(n).po_revision_num IS NULL
541 OR x_cascaded_table(n).freight_carrier_code IS NULL
542 OR x_cascaded_table(n).document_line_num IS NULL
543 OR ( x_cascaded_table(n).item_description IS NULL
544 AND x_cascaded_table(n).matching_basis <> 'AMOUNT')
545 OR ( x_cascaded_table(n).job_id IS NULL
546 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR')
547 OR x_cascaded_table(n).tax_name IS NULL
548 OR --FRKHAN 12/18/98 add country of origin check
549 x_cascaded_table(n).country_of_origin_code IS NULL
550 OR x_cascaded_table(n).po_release_id IS NULL
551 OR ( x_cascaded_table(n).ship_to_location_id IS NULL
552 AND x_cascaded_table(n).ship_to_location_code IS NULL)
553 OR ( x_cascaded_table(n).to_organization_id IS NULL
554 AND x_cascaded_table(n).to_organization_code IS NULL)
555 OR x_cascaded_table(n).document_shipment_line_num IS NULL
556 OR ( x_cascaded_table(n).routing_header_id IS NULL
557 AND x_cascaded_table(n).routing_code IS NULL) THEN --{
558 IF (g_asn_debug = 'Y') THEN
559 asn_debug.put_line('Defaulting values from PO ');
560 END IF;
561
562 OPEN shipments(x_cascaded_table(n).po_header_id,
563 x_cascaded_table(n).po_line_id,
564 x_cascaded_table(n).po_line_location_id
565 );
566 FETCH shipments INTO default_po_info;
567
568 IF shipments%FOUND THEN --{
569 IF x_cascaded_table(n).po_revision_num IS NULL THEN
570 IF (g_asn_debug = 'Y') THEN
571 asn_debug.put_line('Defaulting PO HEADER revision num ' || default_po_info.revision_num);
572 END IF;
573
574 x_cascaded_table(n).po_revision_num := default_po_info.revision_num;
575 END IF;
576
577 IF x_cascaded_table(n).document_line_num IS NULL THEN
578 IF (g_asn_debug = 'Y') THEN
579 asn_debug.put_line('Defaulting po line num ' || TO_CHAR(default_po_info.line_num));
580 END IF;
581
582 x_cascaded_table(n).document_line_num := default_po_info.line_num;
583 END IF;
584
585 IF x_cascaded_table(n).item_description IS NULL
586 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
587 IF (g_asn_debug = 'Y') THEN
588 asn_debug.put_line('Defaulting item description from PO ' || default_po_info.item_description);
589 END IF;
590
591 x_cascaded_table(n).item_description := default_po_info.item_description;
592 END IF;
593
594 IF x_cascaded_table(n).tax_name IS NULL
595 AND default_po_info.tax_code_id IS NOT NULL THEN --{
596 IF (g_asn_debug = 'Y') THEN
597 asn_debug.put_line('Defaulting tax name based on PO ' || TO_CHAR(default_po_info.tax_code_id));
598 END IF;
599
600 -- Need to join to ap_tax_codes to get tax_name
601 BEGIN
602 SELECT NAME
603 INTO x_tax_name
604 FROM ap_tax_codes
605 WHERE ap_tax_codes.tax_id = default_po_info.tax_code_id;
606
607 x_cascaded_table(n).tax_name := x_tax_name;
608 EXCEPTION
609 WHEN OTHERS THEN
610 IF (g_asn_debug = 'Y') THEN
611 asn_debug.put_line('Some error occured in the tax name derivation');
612 END IF;
613 END;
614 END IF; --}
615
616 --FRKHAN 12/18/98 default country of origin from PO
617
618 IF x_cascaded_table(n).country_of_origin_code IS NULL THEN
619 IF (g_asn_debug = 'Y') THEN
620 asn_debug.put_line('Defaulting country of origin from PO ' || default_po_info.country_of_origin_code);
621 END IF;
622
623 x_cascaded_table(n).country_of_origin_code := default_po_info.country_of_origin_code;
624 END IF;
625
626 IF x_cascaded_table(n).po_release_id IS NULL THEN
627 IF (g_asn_debug = 'Y') THEN
628 asn_debug.put_line('Defaulting PO Release ID from PO ' || TO_CHAR(default_po_info.po_release_id));
629 END IF;
630
631 x_cascaded_table(n).po_release_id := default_po_info.po_release_id;
632 END IF;
633
634 IF x_cascaded_table(n).ship_to_location_id IS NULL THEN
635 IF (g_asn_debug = 'Y') THEN
636 asn_debug.put_line('Defaulting PO ship_to_location_id ' || TO_CHAR(default_po_info.ship_to_location_id));
637 END IF;
638
639 x_cascaded_table(n).ship_to_location_id := default_po_info.ship_to_location_id;
640 END IF;
641
642 IF x_cascaded_table(n).to_organization_id IS NULL THEN
643 IF (g_asn_debug = 'Y') THEN
644 asn_debug.put_line('Defaulting PO to_organization_id ' || TO_CHAR(default_po_info.ship_to_organization_id));
645 END IF;
646
647 x_cascaded_table(n).to_organization_id := default_po_info.ship_to_organization_id;
648 END IF;
649
650 IF x_cascaded_table(n).document_shipment_line_num IS NULL THEN
651 IF (g_asn_debug = 'Y') THEN
652 asn_debug.put_line('Defaulting PO shipment_line_num ' || TO_CHAR(default_po_info.shipment_num));
653 END IF;
654
655 x_cascaded_table(n).document_shipment_line_num := default_po_info.shipment_num;
656 END IF;
657
658 IF x_cascaded_table(n).routing_header_id IS NULL THEN
659 IF (g_asn_debug = 'Y') THEN
660 asn_debug.put_line('Defaulting PO routing_header_id ' || TO_CHAR(default_po_info.receiving_routing_id));
661 END IF;
662
663 x_cascaded_table(n).routing_header_id := default_po_info.receiving_routing_id;
664 END IF;
665
666 IF x_cascaded_table(n).job_id IS NULL
667 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR' THEN
668 IF (g_asn_debug = 'Y') THEN
669 asn_debug.put_line('Defaulting PO job_id ' ||(default_po_info.job_id));
670 END IF;
671
672 x_cascaded_table(n).job_id := default_po_info.job_id;
673 END IF;
674 END IF; --} matches if shipments found
675 END IF; --}
676
677 IF (g_asn_debug = 'Y') THEN
678 asn_debug.put_line('Primary UOM = ' || x_cascaded_table(n).primary_unit_of_measure);
679 END IF;
680
681 /*
682 ** Default the subinventory and locator if they have not been set either through the interface
683 ** or defaulted from the purchase order
684 */
685 --- WMS Changes
686 IF x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
687 default_to_subloc_info(x_cascaded_table, n);
688 END IF;
689
690 /*
691 ** Make sure to set the location_id properly
692 */
693 IF ( NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER'
694 OR x_cascaded_table(n).transaction_type = 'DELIVER') THEN
695 x_cascaded_table(n).location_id := x_cascaded_table(n).deliver_to_location_id;
696 ELSE
697 x_cascaded_table(n).location_id := x_cascaded_table(n).ship_to_location_id;
698 END IF;
699
700 IF (g_asn_debug = 'Y') THEN
701 asn_debug.put_line('Set Location_id = ' || TO_CHAR(x_cascaded_table(n).location_id));
702 END IF;
703
704 IF x_cascaded_table(n).waybill_airbill_num IS NULL
705 AND x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
706 x_cascaded_table(n).waybill_airbill_num := x_header_record.header_record.waybill_airbill_num;
707
708 IF (g_asn_debug = 'Y') THEN
709 asn_debug.put_line('Defaulting from HEADER WAYBILL_AIRBILL_NUM ' || x_cascaded_table(n).waybill_airbill_num);
710 END IF;
711 END IF;
712
713 x_progress := '010';
714
715 IF (g_asn_debug = 'Y') THEN
716 asn_debug.put_line('Exit default_shipment_line');
717 END IF;
718 EXCEPTION
719 WHEN OTHERS THEN
720 IF (g_asn_debug = 'Y') THEN
721 asn_debug.put_line('Exception in default_vendor_rcv_line ');
722 END IF;
723 END default_vendor_rcv_line;
724
725 PROCEDURE validate_vendor_rcv_line(
726 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
727 n IN BINARY_INTEGER,
728 x_asn_type IN rcv_headers_interface.asn_type%TYPE,
729 x_header_record IN rcv_roi_preprocessor.header_rec_type
730 ) IS
731 l_parent_deliver_to_person_id NUMBER := null; --Bug#6375015
732 l_skip_validation NUMBER := 0; --Bug#6375015
733 BEGIN
734 IF (g_asn_debug = 'Y') THEN
735 asn_debug.put_line('Enter validate_shipment_line');
736 END IF;
737
738 x_progress := '000';
739
740 IF x_cascaded_table(n).matching_basis = 'AMOUNT' THEN
741 validate_non_services_fields(x_cascaded_table, n);
742 END IF;
743
744 validate_transaction_date(x_cascaded_table, n);
745
746 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
747 IF (x_asn_type = 'ASBN') THEN
748 validate_quantity_invoiced(x_cascaded_table, n);
749 END IF;
750 END IF;
751
752 /* lcm changes */
753 validate_lcm_line (x_cascaded_table, n, x_asn_type,x_header_record);
754
755 IF (g_asn_debug = 'Y') THEN
756 asn_debug.put_line('After lcm line validation : ' || x_cascaded_table(n).error_status);
757 END IF;
758
759
760 /* FPJ SERVICES.
761 * We dont need to validate uom, item_id for Service based PO
762 * shipments.
763 */
764 IF (x_cascaded_table(n).matching_basis <> 'AMOUNT') THEN
765 validate_transaction_uom(x_cascaded_table, n);
766
767 IF (g_asn_debug = 'Y') THEN
768 asn_debug.put_line('After validate_transaction_uom: ' || x_cascaded_table(n).error_status);
769 END IF;
770
771 validate_item_info(x_cascaded_table, n);
772
773 IF (g_asn_debug = 'Y') THEN
774 asn_debug.put_line('After validate_item_info: ' || x_cascaded_table(n).error_status);
775 END IF;
776
777 validate_freight_carrier_code(x_cascaded_table, n);
778
779 IF (g_asn_debug = 'Y') THEN
780 asn_debug.put_line('After validate_freight_carrier_code: ' || x_cascaded_table(n).error_status);
781 END IF;
782
783 validate_subinventory(x_cascaded_table, n);
784
785 IF (g_asn_debug = 'Y') THEN
786 asn_debug.put_line('After validate_subinventory: ' || x_cascaded_table(n).error_status);
787 END IF;
788
789 validate_locator(x_cascaded_table, n);
790
791 IF (g_asn_debug = 'Y') THEN
792 asn_debug.put_line('After validate_locator: ' || x_cascaded_table(n).error_status);
793 END IF;
794
795 validate_deliver_to_loc(x_cascaded_table, n);
796
797 IF (g_asn_debug = 'Y') THEN
798 asn_debug.put_line('After validate_deliver_to_loc: ' || x_cascaded_table(n).error_status);
799 END IF;
800
801 validate_shipped_qty(x_cascaded_table, n);
802
803 IF (g_asn_debug = 'Y') THEN
804 asn_debug.put_line('After validate_shipped_qty: ' || x_cascaded_table(n).error_status);
805 END IF;
806 END IF;
807
808 validate_dest_type(x_cascaded_table, n);
809
810 IF (g_asn_debug = 'Y') THEN
811 asn_debug.put_line('After validate_dest_type: ' || x_cascaded_table(n).error_status);
812 END IF;
813
814 IF (x_cascaded_table(n).transaction_type = 'RECEIVE') THEN
815 validate_ship_to_loc(x_cascaded_table, n);
816
817 IF (g_asn_debug = 'Y') THEN
818 asn_debug.put_line('After validate_ship_to_loc: ' || x_cascaded_table(n).error_status);
819 END IF;
820 END IF;
821
822 /* Bug:6375015
823 There is no defaulting done for the deliver_to_person_id or validation against the parent_txn's
824 deliver_to_person_id in case of ROI transaction. But in case of forms we are defaluting the
825 deliver_to_person_id, if there is no validation failure on the deliver_to_person_id in Receipts/
826 Receiving Transaction forms. If there is validation failure, deliver_to_person_id is nulled out
827 and user can enter any deliver_to_person who is active in case of Receipts/Receiving Trasactions
828 form. In case of Returns/Corrections, deliver_to_person_id is not editable and it is defaulted
829 from the parent transaction, even if that person is terminated.
830 So, added the following code to synch up the behaviour of forms and ROI
831 a) if deliver_to_person_id is null, default the deliver_to_person_id from the
832 parent_txn/source_document PO as done in forms.
833 b) If the deliver_to_person_id is not null, we have to validate against the
834 parent_txn's deliver_to_person.
835 c) Skip the call to validate_deliver_to_person, if deliver_to_person is defaulted
836 from the parent transaction.
837 */
838 /* code fix for the Bug:6375015 starts */
839 IF (x_cascaded_table(n).deliver_to_person_id is null) THEN
840 IF (g_asn_debug = 'Y') THEN
841 asn_debug.put_line('Inside deliver_to_person_id is null...');
842 END IF;
843
844 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
845 --In case of transaction_type DELIVER, we need parent transaction.
846 --If this condition is not added, it will try to defalut the deliver_to_person
847 --of the parent transaction. But form is not behaving like that.
848 --So added this condition to default the deliver_to_person of the source document.
849 IF (g_asn_debug = 'Y') THEN
850 asn_debug.put_line('Transaction type is DELIVER...');
851 asn_debug.put_line('defaulting deliver_to_person_id from source document PO');
852 END IF;
853 get_deliver_to_person_from_po(x_cascaded_table,n);
854 IF (g_asn_debug = 'Y') THEN
855 asn_debug.put_line('After call to get_deliver_to_person_from_po...');
856 END IF;
857 ELSIF (x_cascaded_table(n).parent_transaction_id is not null) THEN
858 IF (g_asn_debug = 'Y') THEN
859 asn_debug.put_line('Inside parent_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_transaction_id);
860 END IF;
861 l_parent_deliver_to_person_id := get_deliver_to_person_from_rt(x_cascaded_table,n);
862 --We can safely skip the validate_deliver_to_person call
863 l_skip_validation := 1;
864 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
865 IF (g_asn_debug = 'Y') THEN
866 asn_debug.put_line('deliver_to_person_is is set to :'||l_parent_deliver_to_person_id);
867 END IF;
868 ELSIF (x_cascaded_table(n).parent_interface_txn_id is not null) THEN
869 IF (g_asn_debug = 'Y') THEN
870 asn_debug.put_line('Inside parent_interface_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_interface_txn_id);
871 END IF;
872 l_parent_deliver_to_person_id := get_deliver_to_person_from_rti(x_cascaded_table,n);
873 --We can safely skip the validate_deliver_to_person call
874 l_skip_validation := 1;
875 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
876 IF (g_asn_debug = 'Y') THEN
877 asn_debug.put_line('deliver_to_person_is is set to :'||l_parent_deliver_to_person_id);
878 END IF;
879 ELSE--IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
880 IF (g_asn_debug = 'Y') THEN
881 asn_debug.put_line('defaulting deliver_to_person_id from source document PO');
882 END IF;
883 get_deliver_to_person_from_po(x_cascaded_table,n);
884 IF (g_asn_debug = 'Y') THEN
885 asn_debug.put_line('After call to get_deliver_to_person_from_po...');
886 END IF;
887 END IF;--IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
888 ELSE--IF (x_cascaded_table(n).deliver_to_person_id is null) THEN
889 IF (g_asn_debug = 'Y') THEN
890 asn_debug.put_line('Inside deliver_to_person_id is not null and the value is :'||x_cascaded_table(n).deliver_to_person_id);
891 END IF;
892
893 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
894 --In forms user can select any active deliver_to_person for DELIVER transaction.
895 --In case of transaction_type DELIVER, we need parent transaction.
896 --If this condition is not added, it will validate against the deliver_to_person mentioned
897 --the parent RECEIVE transaction. But form is not behaving like that.
898 --So, added this condition to skip deliver_to_person validation against parent txn
899 IF (g_asn_debug = 'Y') THEN
900 asn_debug.put_line('Transaction type is DELIVER...');
901 END IF;
902 ELSIF (x_cascaded_table(n).parent_transaction_id is not null) THEN
903 IF (g_asn_debug = 'Y') THEN
904 asn_debug.put_line('Inside parent_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_transaction_id);
905 END IF;
906 l_parent_deliver_to_person_id := get_deliver_to_person_from_rt(x_cascaded_table,n);
907 --We can safely skip the validate_deliver_to_person call, validation against
908 --parent transaction is handled here itself.
909 l_skip_validation := 1;
910 IF nvl(l_parent_deliver_to_person_id,-99) <> x_cascaded_table(n).deliver_to_person_id THEN
911 IF (g_asn_debug = 'Y') THEN
912 asn_debug.put_line('RTI.deliver_to_person_id is different to that of parent txn...');
913 END IF;
914 --deliver_to_person_id mismatches with the parent txn's deliver_to_person, so clear it off
915 x_cascaded_table(n).deliver_to_person_id := null;
916 x_cascaded_table(n).deliver_to_person_name := null;
917
918 --set the deliver_to_person_id to that of parent transaction
919 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
920 IF (g_asn_debug = 'Y') THEN
921 asn_debug.put_line('deliver_to_person_is is set to that of parent RT txn');
922 END IF;
923 END IF;
924 ELSIF (x_cascaded_table(n).parent_interface_txn_id is not null) THEN
925 IF (g_asn_debug = 'Y') THEN
926 asn_debug.put_line('Inside parent_interface_transaction_id.is not null and the value is:'||x_cascaded_table(n).parent_interface_txn_id);
927 END IF;
928 l_parent_deliver_to_person_id := get_deliver_to_person_from_rti(x_cascaded_table,n);
929 --We can safely skip the validate_deliver_to_person call, validation against
930 --parent transaction is handled here itself.
931 l_skip_validation := 1;
932 IF nvl(l_parent_deliver_to_person_id,-99) <> x_cascaded_table(n).deliver_to_person_id THEN
933 IF (g_asn_debug = 'Y') THEN
934 asn_debug.put_line('RTI.deliver_to_person_id is different to that of parent txn...');
935 END IF;
936 --deliver_to_person_id mismatches with the parent txn's deliver_to_person, so clear it off
937 x_cascaded_table(n).deliver_to_person_id := null;
938 x_cascaded_table(n).deliver_to_person_name := null;
939
940 --set the deliver_to_person_id to that of parent transaction
941 x_cascaded_table(n).deliver_to_person_id := l_parent_deliver_to_person_id;
942
943 IF (g_asn_debug = 'Y') THEN
944 asn_debug.put_line('deliver_to_person_is is set to that of parent RT txn');
945 END IF;
946 END IF;
947 END IF;--IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
948 END IF;--IF (x_cascaded_table(n).deliver_to_person_id is null) THEN
949
950 IF l_skip_validation = 0 THEN
951 IF (g_asn_debug = 'Y') THEN
952 asn_debug.put_line('validate_deliver_to_person is called');
953 END IF;
954 validate_deliver_to_person(x_cascaded_table, n);
955 IF (g_asn_debug = 'Y') THEN
956 asn_debug.put_line('After validate_deliver_to_person: ' || x_cascaded_table(n).error_status);
957 END IF;
958 ELSE
959 IF (g_asn_debug = 'Y') THEN
960 asn_debug.put_line('call to validate_deliver_to_person is skipped');
961 END IF;
962 END IF;/* code fix for the Bug:6375015 ends */
963
964 IF (g_asn_debug = 'Y') THEN
965 asn_debug.put_line('After validate_deliver_to_person: ' || x_cascaded_table(n).error_status);
966 END IF;
967
968 validate_routing_record(x_cascaded_table, n);
969
970 IF (g_asn_debug = 'Y') THEN
971 asn_debug.put_line('After validate_routing_record: ' || x_cascaded_table(n).error_status);
972 END IF;
973
974 validate_tax_code(x_cascaded_table,
975 n,
976 x_asn_type
977 ); /* Bug3454491 (1) */
978
979 IF (g_asn_debug = 'Y') THEN
980 asn_debug.put_line('After validate_tax_code: ' || x_cascaded_table(n).error_status);
981 END IF;
982
983 validate_country_of_origin(x_cascaded_table, n);
984
985 IF (g_asn_debug = 'Y') THEN
986 asn_debug.put_line('After validate_country_of_origin: ' || x_cascaded_table(n).error_status);
987 END IF;
988
989 validate_asl(x_cascaded_table, n);
990
991 IF (g_asn_debug = 'Y') THEN
992 asn_debug.put_line('After validate_asl: ' || x_cascaded_table(n).error_status);
993 END IF;
994
995 validate_ref_integrity(x_cascaded_table,
996 n,
997 x_header_record
998 );
999
1000 IF (g_asn_debug = 'Y') THEN
1001 asn_debug.put_line('After validate_ref_integrity: ' || x_cascaded_table(n).error_status);
1002 END IF;
1003
1004 exchange_sub_items(x_cascaded_table, n);
1005
1006 IF (g_asn_debug = 'Y') THEN
1007 asn_debug.put_line('After exchange_sub_items: ' || x_cascaded_table(n).error_status);
1008 END IF;
1009
1010 validate_consigned_inventory(x_cascaded_table,
1011 n,
1012 x_asn_type
1013 ); /* Bug3454491 (2) */
1014
1015 IF (g_asn_debug = 'Y') THEN
1016 asn_debug.put_line('After validate_consigned_inventory: ' || x_cascaded_table(n).error_status);
1017 END IF;
1018
1019 validate_inspection_status(x_cascaded_table, n);
1020
1021 IF (g_asn_debug = 'Y') THEN
1022 asn_debug.put_line('After validate_inspection_status: ' || x_cascaded_table(n).error_status);
1023 END IF;
1024
1025 validate_transaction_type(x_cascaded_table, n);
1026
1027 IF (g_asn_debug = 'Y') THEN
1028 asn_debug.put_line('After validate_transaction_type: ' || x_cascaded_table(n).error_status);
1029 END IF;
1030
1031 /** OPM change Bug# 3061052**/
1032 validate_opm_attributes(x_cascaded_table, n);
1033
1034 IF (g_asn_debug = 'Y') THEN
1035 asn_debug.put_line('After validate_opm_attributes: ' || x_cascaded_table(n).error_status);
1036 END IF;
1037
1038 /* If destination_type_code is inventory then we need to make
1039 * sure that we can correct this qty since it might have been
1040 * already reserved in inventory.
1041 */
1042 IF (x_cascaded_table(n).destination_type_code = 'INVENTORY') THEN --{
1043 rcv_roi_return.derive_inv_qty(x_cascaded_table, n);
1044
1045 IF (g_asn_debug = 'Y') THEN
1046 asn_debug.put_line('After derive_inv_qty: ' || x_cascaded_table(n).error_status);
1047 END IF;
1048 END IF; --}
1049
1050 IF (g_asn_debug = 'Y') THEN
1051 asn_debug.put_line('Leave validate_vendor_rcv_line: ' || x_cascaded_table(n).error_status || ' ' || x_cascaded_table(n).error_message);
1052 END IF;
1053 EXCEPTION
1054 WHEN OTHERS THEN
1055 IF (g_asn_debug = 'Y') THEN
1056 asn_debug.put_line('Unexpected exception in validate_vendor_rcv_line: ' || SQLERRM);
1057 END IF;
1058 END validate_vendor_rcv_line;
1059
1060 PROCEDURE validate_amt_based_rcv_line(
1061 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1062 n IN BINARY_INTEGER,
1063 x_asn_type IN rcv_headers_interface.asn_type%TYPE,
1064 x_header_record IN rcv_roi_preprocessor.header_rec_type
1065 ) IS
1066 BEGIN
1067 IF (g_asn_debug = 'Y') THEN
1068 asn_debug.put_line('Enter validate_amt_based_rcv_line');
1069 END IF;
1070
1071 x_progress := '000';
1072 validate_transaction_date(x_cascaded_table, n);
1073 x_progress := '010';
1074
1075 IF (x_asn_type = 'ASBN') THEN
1076 validate_quantity_invoiced(x_cascaded_table, n);
1077 END IF;
1078
1079 x_progress := '020';
1080 validate_dest_type(x_cascaded_table, n);
1081 x_progress := '030';
1082 validate_ship_to_loc(x_cascaded_table, n);
1083 x_progress := '040';
1084 validate_tax_code(x_cascaded_table,
1085 n,
1086 x_asn_type
1087 ); /* Bug3454491 (3) */
1088 x_progress := '050';
1089 validate_ref_integrity(x_cascaded_table,
1090 n,
1091 x_header_record
1092 );
1093
1094 IF (g_asn_debug = 'Y') THEN
1095 asn_debug.put_line('After validate_ref_integrity');
1096 END IF;
1097
1098 x_progress := '060';
1099 validate_transaction_type(x_cascaded_table, n);
1100
1101 IF (g_asn_debug = 'Y') THEN
1102 asn_debug.put_line('After validate_transaction_type');
1103 END IF;
1104
1105 x_progress := '070';
1106 validate_temp_labor_info(x_cascaded_table,
1107 n,
1108 x_header_record
1109 );
1110
1111 IF (g_asn_debug = 'Y') THEN
1112 asn_debug.put_line('After validate_temp_labour_info');
1113 END IF;
1114
1115 x_progress := '080';
1116 validate_amount(x_cascaded_table,
1117 n,
1118 x_header_record
1119 );
1120
1121 IF (g_asn_debug = 'Y') THEN
1122 asn_debug.put_line('After validate_amount');
1123 END IF;
1124 EXCEPTION
1125 WHEN OTHERS THEN
1126 IF (g_asn_debug = 'Y') THEN
1127 asn_debug.put_line('Exception at ' || x_progress);
1128 asn_debug.put_line(SQLERRM);
1129 asn_debug.put_line('Exit validate_amt_based_rcv_line');
1130 END IF;
1131 END validate_amt_based_rcv_line;
1132
1133 PROCEDURE derive_ship_to_org_info(
1134 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1135 n IN OUT NOCOPY BINARY_INTEGER,
1136 x_header_record IN rcv_roi_preprocessor.header_rec_type
1137 ) IS
1138 ship_to_org_record rcv_shipment_object_sv.organization_id_record_type;
1139 x_to_organization_code VARCHAR2(5);
1140 BEGIN
1141 -- default org from header in case it is null at the line level
1142 asn_debug.put_line('error derive_ship_to_org_info' || x_cascaded_table(n).error_status);
1143 x_cascaded_table(n).error_status := 'S';
1144 asn_debug.put_line('the to_org_code = ' || x_cascaded_table(n).to_organization_code);
1145
1146 IF x_cascaded_table(n).to_organization_code IS NULL
1147 AND x_cascaded_table(n).error_status IN('S', 'W') THEN
1148 asn_debug.put_line('Attempting to default the org from the ship to location');
1149
1150 IF (g_asn_debug = 'Y') THEN
1151 asn_debug.put_line('Attempting to default the org from the ship to location');
1152 END IF;
1153
1154 IF (x_cascaded_table(n).ship_to_location_code IS NOT NULL) THEN
1155 SELECT MAX(org.organization_code)
1156 INTO x_to_organization_code
1157 FROM hr_locations hl,
1158 mtl_parameters org
1159 WHERE x_cascaded_table(n).ship_to_location_code = hl.location_code
1160 AND hl.inventory_organization_id = org.organization_id;
1161
1162 x_cascaded_table(n).to_organization_code := x_to_organization_code;
1163
1164 IF (g_asn_debug = 'Y') THEN
1165 asn_debug.put_line('Set Org Code using location code = ' || x_cascaded_table(n).to_organization_code);
1166 END IF;
1167 END IF;
1168
1169 IF ( x_cascaded_table(n).to_organization_code IS NULL
1170 AND x_header_record.header_record.ship_to_organization_code IS NOT NULL) THEN
1171 IF (g_asn_debug = 'Y') THEN
1172 asn_debug.put_line('Will default org change DUH to ' || x_header_record.header_record.ship_to_organization_code);
1173 END IF;
1174
1175 x_cascaded_table(n).to_organization_code := x_header_record.header_record.ship_to_organization_code;
1176 END IF;
1177 END IF;
1178
1179 -- call derivation procedures if conditions are met
1180
1181 asn_debug.put_line('to_organization_id ' || x_cascaded_table(n).to_organization_id);
1182 asn_debug.put_line('to_organization_code ' || x_cascaded_table(n).to_organization_code);
1183
1184 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1185 AND ( x_cascaded_table(n).to_organization_id IS NULL
1186 AND x_cascaded_table(n).to_organization_code IS NOT NULL) THEN
1187 IF (g_asn_debug = 'Y') THEN
1188 asn_debug.put_line('X_Progress ' || x_progress);
1189 END IF;
1190
1191 ship_to_org_record.organization_code := x_cascaded_table(n).to_organization_code;
1192 ship_to_org_record.organization_id := x_cascaded_table(n).to_organization_id;
1193 ship_to_org_record.error_record.error_status := 'S';
1194 ship_to_org_record.error_record.error_message := NULL;
1195
1196 IF (g_asn_debug = 'Y') THEN
1197 asn_debug.put_line('Into Derive Organization Record Procedure');
1198 END IF;
1199
1200 po_orgs_sv.derive_org_info(ship_to_org_record);
1201
1202 IF (g_asn_debug = 'Y') THEN
1203 asn_debug.put_line('Debug Output after organization procedure');
1204 asn_debug.put_line(ship_to_org_record.organization_code);
1205 asn_debug.put_line(TO_CHAR(ship_to_org_record.organization_id));
1206 asn_debug.put_line(ship_to_org_record.error_record.error_status);
1207 asn_debug.put_line('Debug organization output over');
1208 END IF;
1209
1210 x_cascaded_table(n).to_organization_code := ship_to_org_record.organization_code;
1211 x_cascaded_table(n).to_organization_id := ship_to_org_record.organization_id;
1212 x_cascaded_table(n).error_status := ship_to_org_record.error_record.error_status;
1213 x_cascaded_table(n).error_message := ship_to_org_record.error_record.error_message;
1214 END IF;
1215 END derive_ship_to_org_info;
1216
1217 PROCEDURE derive_vendor_info(
1218 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1219 n IN OUT NOCOPY BINARY_INTEGER
1220 ) IS
1221 vendor_record rcv_shipment_header_sv.vendorrectype;
1222 BEGIN
1223 asn_debug.put_line('i am inside the derive_vendor_info method');
1224
1225 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
1226 IF ( x_cascaded_table(n).vendor_name IS NOT NULL
1227 OR x_cascaded_table(n).vendor_num IS NOT NULL
1228 OR x_cascaded_table(n).vendor_id IS NOT NULL) THEN
1229 vendor_record.vendor_name := x_cascaded_table(n).vendor_name;
1230 vendor_record.vendor_num := x_cascaded_table(n).vendor_num;
1231 vendor_record.vendor_id := x_cascaded_table(n).vendor_id;
1232 vendor_record.error_record.error_message := x_cascaded_table(n).error_message;
1233 vendor_record.error_record.error_status := x_cascaded_table(n).error_status;
1234
1235 IF (g_asn_debug = 'Y') THEN
1236 asn_debug.put_line('In Vendor Procedure');
1237 END IF;
1238
1239 po_vendors_sv.derive_vendor_info(vendor_record);
1240
1241 IF (g_asn_debug = 'Y') THEN
1242 asn_debug.put_line(TO_CHAR(vendor_record.vendor_id));
1243 asn_debug.put_line(vendor_record.vendor_name);
1244 asn_debug.put_line(vendor_record.vendor_num);
1245 asn_debug.put_line(vendor_record.error_record.error_status);
1246 asn_debug.put_line(vendor_record.error_record.error_message);
1247 END IF;
1248
1249 x_cascaded_table(n).vendor_name := vendor_record.vendor_name;
1250 x_cascaded_table(n).vendor_num := vendor_record.vendor_num;
1251 x_cascaded_table(n).vendor_id := vendor_record.vendor_id;
1252 x_cascaded_table(n).error_message := vendor_record.error_record.error_message;
1253 x_cascaded_table(n).error_status := vendor_record.error_record.error_status;
1254 END IF;
1255 END IF;
1256 END derive_vendor_info;
1257
1258 PROCEDURE derive_vendor_site_info(
1259 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1260 n IN OUT NOCOPY BINARY_INTEGER
1261 ) IS
1262 vendor_site_record rcv_shipment_header_sv.vendorsiterectype;
1263 BEGIN
1264 IF x_cascaded_table(n).error_status IN('S', 'W')
1265 AND ( x_cascaded_table(n).vendor_site_code IS NOT NULL
1266 OR x_cascaded_table(n).vendor_site_id IS NOT NULL) THEN
1267 vendor_site_record.vendor_site_code := x_cascaded_table(n).vendor_site_code;
1268 vendor_site_record.vendor_id := x_cascaded_table(n).vendor_id;
1269 vendor_site_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
1270 vendor_site_record.organization_id := x_cascaded_table(n).to_organization_id;
1271 vendor_site_record.error_record.error_message := x_cascaded_table(n).error_message;
1272 vendor_site_record.error_record.error_status := x_cascaded_table(n).error_status;
1273
1274 IF (g_asn_debug = 'Y') THEN
1275 asn_debug.put_line('In Vendor Site Procedure');
1276 END IF;
1277
1278 po_vendor_sites_sv.derive_vendor_site_info(vendor_site_record);
1279
1280 IF (g_asn_debug = 'Y') THEN
1281 asn_debug.put_line(vendor_site_record.vendor_site_code);
1282 asn_debug.put_line(vendor_site_record.vendor_site_id);
1283 END IF;
1284
1285 x_cascaded_table(n).vendor_site_code := vendor_site_record.vendor_site_code;
1286 x_cascaded_table(n).vendor_id := vendor_site_record.vendor_id;
1287 x_cascaded_table(n).vendor_site_id := vendor_site_record.vendor_site_id;
1288 x_cascaded_table(n).to_organization_id := vendor_site_record.organization_id;
1289 x_cascaded_table(n).error_message := vendor_site_record.error_record.error_message;
1290 x_cascaded_table(n).error_status := vendor_site_record.error_record.error_status;
1291 END IF;
1292 END derive_vendor_site_info;
1293
1294 PROCEDURE derive_po_header_info(
1295 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1296 n IN OUT NOCOPY BINARY_INTEGER
1297 ) IS
1298 vendor_site_record rcv_shipment_header_sv.vendorsiterectype;
1299 document_num_record rcv_shipment_line_sv.document_num_record_type;
1300 BEGIN
1301 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1302 AND ( x_cascaded_table(n).po_header_id IS NULL
1303 AND x_cascaded_table(n).document_num IS NOT NULL) THEN
1304 IF (g_asn_debug = 'Y') THEN
1305 asn_debug.put_line('X_progress ' || x_progress);
1306 asn_debug.put_line('shipment_header_id ' || x_cascaded_table(n).shipment_header_id);
1307 END IF;
1308
1309 document_num_record.document_num := x_cascaded_table(n).document_num;
1310 document_num_record.error_record.error_status := 'S';
1311 document_num_record.error_record.error_message := NULL;
1312
1313 IF (g_asn_debug = 'Y') THEN
1314 asn_debug.put_line('Derive po_header_id');
1315 END IF;
1316
1317 rcv_transactions_interface_sv.get_po_header_id(document_num_record);
1318 x_cascaded_table(n).po_header_id := document_num_record.po_header_id;
1319 x_cascaded_table(n).error_status := document_num_record.error_record.error_status;
1320 x_cascaded_table(n).error_message := document_num_record.error_record.error_message;
1321 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1322 'DOCUMENT_NUM',
1323 FALSE
1324 );
1325
1326 IF (g_asn_debug = 'Y') THEN
1327 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).po_header_id));
1328 END IF;
1329 END IF;
1330 END derive_po_header_info;
1331
1332 PROCEDURE derive_asn_header_info(
1333 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1334 n IN OUT NOCOPY BINARY_INTEGER,
1335 x_header_record IN rcv_roi_preprocessor.header_rec_type
1336 ) IS
1337 BEGIN
1338 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
1339 /*
1340 ** Bug 4523892
1341 ** Removed the code that was checking if the current transaction
1342 ** was against ASN or PO since global variable g_txn_against_asn
1343 ** holds that information and is being used here
1344 */
1345 IF ( NVL(x_header_record.header_record.asn_type, 'STD') = 'STD'
1346 AND x_cascaded_table(n).transaction_type = 'RECEIVE'
1347 AND (rcv_roi_header.g_txn_against_asn = 'Y')) THEN --{ /* Bug4523892 */
1348
1349 x_cascaded_table(n).shipment_header_id := x_header_record.header_record.receipt_header_id;
1350
1351 IF (g_asn_debug = 'Y') THEN
1352 asn_debug.put_line('shipment_header_id in derive_asn_header_info ' || x_cascaded_table(n).shipment_header_id);
1353 END IF;
1354
1355 IF (x_cascaded_table(n).shipment_header_id IS NULL) THEN --{
1356 IF (g_asn_debug = 'Y') THEN
1357 asn_debug.put_line('Cannot derive shipment_header_id');
1358 END IF;
1359
1360 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1361 rcv_error_pkg.set_error_message('RCV_NO_SHIP_ID', x_cascaded_table(n).error_message);
1362 rcv_error_pkg.set_token('NUMBER', x_cascaded_table(n).shipment_num);
1363 rcv_error_pkg.log_interface_error('SHIPMENT_NUM', FALSE);
1364 END IF; --}
1365 END IF; --}
1366 END IF; --}
1367 EXCEPTION
1368 WHEN OTHERS THEN
1369 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
1370 rcv_error_pkg.set_sql_error_message('derive_asn_header_info', '000');
1371 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
1372 rcv_error_pkg.log_interface_error('SHIPMENT_NUM', FALSE);
1373 END derive_asn_header_info;
1374
1375 PROCEDURE derive_item_info(
1376 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1377 n IN OUT NOCOPY BINARY_INTEGER
1378 ) IS
1379 item_id_record rcv_shipment_line_sv.item_id_record_type;
1380 BEGIN
1381 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1382 AND ( x_cascaded_table(n).item_id IS NULL
1383 AND (x_cascaded_table(n).item_num IS NOT NULL)) THEN
1384 IF (g_asn_debug = 'Y') THEN
1385 asn_debug.put_line('X_progress ' || x_progress);
1386 END IF;
1387
1388 item_id_record.item_num := x_cascaded_table(n).item_num;
1389 item_id_record.vendor_item_num := NULL; -- x_cascaded_table(n).vendor_item_num;
1390 item_id_record.to_organization_id := x_cascaded_table(n).to_organization_id;
1391 item_id_record.error_record.error_status := 'S';
1392 item_id_record.error_record.error_message := NULL;
1393
1394 IF (g_asn_debug = 'Y') THEN
1395 asn_debug.put_line('Derive item_id');
1396 END IF;
1397
1398 rcv_transactions_interface_sv.get_item_id(item_id_record);
1399 x_cascaded_table(n).item_id := item_id_record.item_id;
1400 x_cascaded_table(n).primary_unit_of_measure := item_id_record.primary_unit_of_measure;
1401 x_cascaded_table(n).use_mtl_lot := item_id_record.use_mtl_lot; -- bug 608353
1402 x_cascaded_table(n).use_mtl_serial := item_id_record.use_mtl_serial; -- bug 608353
1403 x_cascaded_table(n).error_status := item_id_record.error_record.error_status;
1404 x_cascaded_table(n).error_message := item_id_record.error_record.error_message;
1405 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1406 'ITEM_NUM',
1407 FALSE
1408 );
1409 END IF;
1410 END derive_item_info;
1411
1412 PROCEDURE derive_substitute_item_info(
1413 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1414 n IN OUT NOCOPY BINARY_INTEGER
1415 ) IS
1416 sub_item_id_record rcv_shipment_line_sv.sub_item_id_record_type;
1417 BEGIN
1418 /* FPJ Services.
1419 * We do not support Substitute Receipts for service POs.
1420 */
1421 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
1422 RETURN;
1423 END IF;
1424
1425 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1426 AND ( x_cascaded_table(n).substitute_item_id IS NULL
1427 AND (x_cascaded_table(n).substitute_item_num IS NOT NULL)) THEN
1428 IF (g_asn_debug = 'Y') THEN
1429 asn_debug.put_line('X_progress ' || x_progress);
1430 END IF;
1431
1432 sub_item_id_record.substitute_item_num := x_cascaded_table(n).substitute_item_num;
1433 sub_item_id_record.vendor_item_num := NULL; -- x_cascaded_table(n).vendor_item_num;
1434 sub_item_id_record.error_record.error_status := 'S';
1435 sub_item_id_record.error_record.error_message := NULL;
1436
1437 IF (g_asn_debug = 'Y') THEN
1438 asn_debug.put_line('Derive Substitute Item Id');
1439 END IF;
1440
1441 rcv_transactions_interface_sv.get_sub_item_id(sub_item_id_record);
1442 x_cascaded_table(n).substitute_item_id := sub_item_id_record.substitute_item_id;
1443 x_cascaded_table(n).error_status := sub_item_id_record.error_record.error_status;
1444 x_cascaded_table(n).error_message := sub_item_id_record.error_record.error_message;
1445
1446 IF (g_asn_debug = 'Y') THEN
1447 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).substitute_item_id));
1448 END IF;
1449
1450 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1451 'SUBSTITUTE_ITEM_NUM',
1452 FALSE
1453 );
1454 END IF;
1455 END derive_substitute_item_info;
1456
1457 PROCEDURE derive_po_line_info(
1458 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1459 n IN OUT NOCOPY BINARY_INTEGER
1460 ) IS
1461 po_line_id_record rcv_shipment_line_sv.po_line_id_record_type;
1462 release_id_record rcv_shipment_line_sv.release_id_record_type;
1463 l_asn_type rcv_shipment_headers.asn_type%type;
1464 l_error_column VARCHAR2(30); --Bugfix 4881909
1465 BEGIN
1466 IF (g_asn_debug = 'Y') THEN
1467 asn_debug.put_line('In derive_po_line_info');
1468 END IF;
1469
1470 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1471 AND ( x_cascaded_table(n).po_line_id IS NULL
1472 AND x_cascaded_table(n).po_header_id IS NOT NULL
1473 AND x_cascaded_table(n).document_line_num IS NOT NULL) THEN
1474 IF (g_asn_debug = 'Y') THEN
1475 asn_debug.put_line('X_progress ' || x_progress);
1476 END IF;
1477
1478 po_line_id_record.po_header_id := x_cascaded_table(n).po_header_id;
1479 po_line_id_record.document_line_num := x_cascaded_table(n).document_line_num;
1480 po_line_id_record.po_line_id := x_cascaded_table(n).po_line_id;
1481 po_line_id_record.item_id := x_cascaded_table(n).item_id;
1482 po_line_id_record.error_record.error_status := 'S';
1483 po_line_id_record.error_record.error_message := NULL;
1484
1485 IF (g_asn_debug = 'Y') THEN
1486 asn_debug.put_line('Derive po_line_id');
1487 END IF;
1488
1489 rcv_transactions_interface_sv.get_po_line_id(po_line_id_record);
1490
1491 IF x_cascaded_table(n).item_id IS NULL THEN
1492 x_cascaded_table(n).item_id := po_line_id_record.item_id;
1493 END IF;
1494
1495 x_cascaded_table(n).po_line_id := po_line_id_record.po_line_id;
1496 x_cascaded_table(n).error_status := po_line_id_record.error_record.error_status;
1497 x_cascaded_table(n).error_message := po_line_id_record.error_record.error_message;
1498
1499 IF (g_asn_debug = 'Y') THEN
1500 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).po_line_id));
1501 END IF;
1502
1503 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
1504 'DOCUMENT_LINE_NUM',
1505 FALSE
1506 );
1507 END IF; -- set line id
1508
1509 IF (g_asn_debug = 'Y') THEN
1510 asn_debug.put_line('po_line_id to get matching_basis ' || TO_CHAR(x_cascaded_table(n).po_line_id));
1511 END IF;
1512
1513 /* Complex Work Start.
1514 * Moving the logic to derive matching_basis
1515 * to a separate procedure derive_matching_basis.
1516 -- Determine whether this is a services line type
1517 IF x_cascaded_table(n).po_line_id IS NOT NULL THEN
1518 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
1519 NVL(purchase_basis, 'GOODS'),
1520 NVL(matching_basis, 'QUANTITY')
1521 INTO x_cascaded_table(n).value_basis,
1522 x_cascaded_table(n).purchase_basis,
1523 x_cascaded_table(n).matching_basis
1524 FROM po_lines
1525 WHERE po_line_id = x_cascaded_table(n).po_line_id;
1526 ELSE
1527 -- we require line info for receiving against services lines
1528 x_cascaded_table(n).matching_basis := 'QUANTITY';
1529 x_cascaded_table(n).purchase_basis := 'GOODS';
1530 END IF;
1531
1532 IF (g_asn_debug = 'Y') THEN
1533 asn_debug.put_line('matching_basis ' || x_cascaded_table(n).matching_basis);
1534 END IF;
1535
1536 Complex Work End*/
1537 -- Get the primary uom in case item_id was determined on the basis of the po_line_id
1538 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1539 AND x_cascaded_table(n).item_id IS NOT NULL THEN
1540 /*BEGIN Bug 5592084: Incase the PRIMARY_UNIT_OF_MEASURE has value
1541 defined in MSI but doesnt match the one defined for the item
1542 then we need to raise an error.
1543 Commenting out below condition to ensure that the validation
1544 is done for the primary_unit_of_measure in all cases i.e. irrespective
1545 of value being specified or not in RTI.
1546 */
1547 --AND x_cascaded_table(n).primary_unit_of_measure IS NULL THEN
1548 DECLARE
1549 l_primary_unit_of_measure mtl_system_items.primary_unit_of_measure%TYPE;
1550 BEGIN
1551 /* BUG 608353 */
1552 SELECT primary_unit_of_measure
1553 INTO l_primary_unit_of_measure
1554 FROM mtl_system_items
1555 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
1556 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
1557 IF (g_asn_debug = 'Y') THEN
1558 asn_debug.put_line('Primary UOM from RTI :' || x_cascaded_table(n).primary_unit_of_measure);
1559 asn_debug.put_line('Derived PRIMARY UOM from MSI:' || l_primary_unit_of_measure);
1560 END IF;
1561 IF (NVL(x_cascaded_table(n).primary_unit_of_measure, l_primary_unit_of_measure) <> l_primary_unit_of_measure) THEN
1562 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1563 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE');
1564 rcv_error_pkg.set_token('COLUMN', 'PRIMARY_UNIT_OF_MEASURE');
1565 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).primary_unit_of_measure);
1566 rcv_error_pkg.set_token('SYS_VALUE', l_primary_unit_of_measure);
1567 rcv_error_pkg.log_interface_error('PRIMARY_UNIT_OF_MEASURE');
1568 ELSE
1569 x_cascaded_table(n).primary_unit_of_measure := l_primary_unit_of_measure;
1570 END IF;
1571 IF (g_asn_debug = 'Y') THEN
1572 asn_debug.put_line('Primary UOM: ' || x_cascaded_table(n).primary_unit_of_measure);
1573 END IF;
1574 EXCEPTION
1575 WHEN NO_DATA_FOUND THEN
1576 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
1577 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE_NE');
1578 rcv_error_pkg.set_token('COLUMN', 'PRIMARY_UNIT_OF_MEASURE');
1579 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).primary_unit_of_measure);
1580 rcv_error_pkg.log_interface_warning('PRIMARY_UNIT_OF_MEASURE');
1581 END;
1582 /*END Bug 5592084*/
1583 END IF; -- set primary_uom
1584
1585 /* We need to get the value of use_mtl_lot and use_mtl_serial
1586 * irrespective of whether primary_uom is populated in rti.
1587 */
1588 /*
1589 BEGIN Comment: Bug: 4735484
1590 IF ((x_cascaded_table(n).error_status IN('S', 'W')
1591 AND x_cascaded_table(n).item_id IS NOT NULL)
1592 AND (x_cascaded_table(n).use_mtl_lot IS NULL
1593 OR x_cascaded_table(n).use_mtl_serial IS NULL)) THEN
1594 BEGIN
1595 SELECT NVL(x_cascaded_table(n).use_mtl_lot, lot_control_code),
1596 NVL(x_cascaded_table(n).use_mtl_serial, serial_number_control_code)
1597 INTO x_cascaded_table(n).use_mtl_lot,
1598 x_cascaded_table(n).use_mtl_serial
1599 FROM mtl_system_items
1600 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
1601 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
1602
1603 IF (g_asn_debug = 'Y') THEN
1604 asn_debug.put_line('use_mtl_lot: ' || x_cascaded_table(n).use_mtl_lot);
1605 asn_debug.put_line('use_mtl_serial: ' || x_cascaded_table(n).use_mtl_serial);
1606 END IF;
1607 EXCEPTION
1608 WHEN NO_DATA_FOUND THEN
1609 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
1610 rcv_error_pkg.set_error_message('PO_RI_INVALID_ITEM_ID', x_cascaded_table(n).error_message);
1611 rcv_error_pkg.log_interface_warning('DOCUMENT_LINE_NUM');
1612 END;
1613 END IF; -- set primary_uom
1614 END Comment: Bug: 4735484
1615 */
1616 /* Bug 2020269 : uom_code needs to be derived from unit_of_measure
1617 entered in rcv_transactions_interface.
1618 */
1619 IF (x_cascaded_table(n).unit_of_measure IS NOT NULL) THEN
1620 IF (g_asn_debug = 'Y') THEN
1621 asn_debug.put_line('X_progress ' || x_progress);
1622 END IF;
1623
1624 SELECT muom.uom_code
1625 INTO x_cascaded_table(n).uom_code
1626 FROM mtl_units_of_measure muom
1627 WHERE muom.unit_of_measure = x_cascaded_table(n).unit_of_measure;
1628 ELSE
1629 IF (g_asn_debug = 'Y') THEN
1630 asn_debug.put_line('uom_code not dereived as unit_of_measure is null');
1631 END IF;
1632 END IF; -- set uom_code
1633
1634 x_progress := '026';
1635
1636 /* Bug 1830177. If the po_line_id is null then we do not populate the correct
1637 * po_release_id even if we specify the release_num since we do not enter
1638 * this block. Removed the condition x_cascaded_table(n).po_line_id is not null
1639 */
1640 /* R12 Complex Work.
1641 * We cannot create releases for a work confirmations.
1642 */
1643 If ( x_cascaded_table(n).header_interface_id is not null) then
1644 select asn_type
1645 into l_asn_type
1646 from rcv_headers_interface
1647 where header_interface_id =
1648 x_cascaded_table(n).header_interface_id;
1649 end if;
1650
1651 If (nvl(l_asn_type,'STD') <> 'WC' ) THEN --{
1652 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1653 AND x_cascaded_table(n).po_release_id IS NULL
1654 AND -- Maybe we need an or with shipnum,relnum
1655 x_cascaded_table(n).po_header_id IS NOT NULL THEN --{
1656 IF (g_asn_debug = 'Y') THEN
1657 asn_debug.put_line('X_progress ' || x_progress);
1658 END IF;
1659
1660 release_id_record.po_header_id := x_cascaded_table(n).po_header_id;
1661 release_id_record.release_num := x_cascaded_table(n).release_num;
1662 release_id_record.po_line_id := x_cascaded_table(n).po_line_id;
1663 release_id_record.shipment_num := x_cascaded_table(n).document_shipment_line_num;
1664 release_id_record.error_record.error_status := 'S';
1665 release_id_record.error_record.error_message := NULL;
1666
1667 IF (g_asn_debug = 'Y') THEN
1668 asn_debug.put_line('Derive po_line_location_id, shipment_num, po_release_id');
1669 END IF;
1670
1671 IF (g_asn_debug = 'Y') THEN
1672 asn_debug.put_line('### po_header_id ' || release_id_record.po_header_id);
1673 asn_debug.put_line('### release_num ' || release_id_record.release_num);
1674 asn_debug.put_line('### po_line_id ' || release_id_record.po_line_id);
1675 asn_debug.put_line('### shipment_num ' || release_id_record.shipment_num);
1676 asn_debug.put_line('### po_rel_id ' || release_id_record.po_release_id);
1677 END IF;
1678
1679 po_releases_sv4.get_po_release_id(release_id_record);
1680
1681 IF (g_asn_debug = 'Y') THEN
1682 asn_debug.put_line('^^^ po_header_id ' || release_id_record.po_header_id);
1683 asn_debug.put_line('^^^ release_num ' || release_id_record.release_num);
1684 asn_debug.put_line('^^^ po_line_id ' || release_id_record.po_line_id);
1685 asn_debug.put_line('^^^ shipment_num ' || release_id_record.shipment_num);
1686 asn_debug.put_line('^^^ po_rel_id ' || release_id_record.po_release_id);
1687 END IF;
1688
1689 x_cascaded_table(n).error_status := release_id_record.error_record.error_status;
1690 x_cascaded_table(n).error_message := release_id_record.error_record.error_message;
1691
1692 /* po_releases_sv4 does not follow error handling paradigm */
1693 l_error_column := 'RELEASE_NUM';
1694 IF (x_cascaded_table(n).error_status = 'F') THEN
1695 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1696 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
1697
1698 /* Bug 4881909: Setting necessary tokens for messages to be logged in po_interface_errors
1699 ** if release number or PO shipment line information is in error.
1700 */
1701
1702 IF release_id_record.error_record.error_message = 'RCV_ITEM_PO_REL_ID' THEN
1703
1704 rcv_error_pkg.set_token('NUMBER', x_cascaded_table(n).release_num);
1705
1706 ELSIF release_id_record.error_record.error_message = 'RCV_ROI_INVALID_PO_SHIP_NUM' THEN
1707 rcv_error_pkg.set_token('PO_SHIP_NUM', x_cascaded_table(n).document_shipment_line_num);
1708 rcv_error_pkg.set_token('PONUM', x_cascaded_table(n).document_num);
1709 l_error_column := 'DOCUMENT_SHIPMENT_LINE_NUM';
1710
1711 ELSIF release_id_record.error_record.error_message = 'RCV_ROI_INVALID_REL_SHIP_NUM' THEN
1712 rcv_error_pkg.set_token('PO_SHIP_NUM', x_cascaded_table(n).document_shipment_line_num);
1713 rcv_error_pkg.set_token('PONUM', x_cascaded_table(n).document_num);
1714 rcv_error_pkg.set_token('RELEASE', x_cascaded_table(n).release_num);
1715 l_error_column := 'DOCUMENT_SHIPMENT_LINE_NUM';
1716
1717 ELSIF release_id_record.error_record.error_message = 'RCV_ROI_INVALID_RELEASE_NUM' THEN
1718
1719 rcv_error_pkg.set_token('RELEASE', x_cascaded_table(n).release_num);
1720 rcv_error_pkg.set_token('PONUM', x_cascaded_table(n).document_num);
1721
1722 END IF;
1723 END IF;
1724
1725
1726 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,l_error_column, FALSE);
1727
1728 IF x_cascaded_table(n).po_line_location_id IS NULL THEN
1729 x_cascaded_table(n).po_line_location_id := release_id_record.po_line_location_id;
1730
1731 IF (g_asn_debug = 'Y') THEN
1732 asn_debug.put_line('PO_LINE_LOCATION_ID ' || TO_CHAR(x_cascaded_table(n).po_line_location_id));
1733 END IF;
1734 END IF;
1735
1736 IF x_cascaded_table(n).document_shipment_line_num IS NULL THEN
1737 x_cascaded_table(n).document_shipment_line_num := release_id_record.shipment_num;
1738
1739 IF (g_asn_debug = 'Y') THEN
1740 asn_debug.put_line('DOCUMENT_SHIPMENT_NUM ' || TO_CHAR(x_cascaded_table(n).document_shipment_line_num));
1741 END IF;
1742 END IF;
1743
1744 x_cascaded_table(n).po_release_id := release_id_record.po_release_id;
1745
1746 IF (g_asn_debug = 'Y') THEN
1747 asn_debug.put_line('PO_RELEASE_ID ' || TO_CHAR(x_cascaded_table(n).po_release_id));
1748 END IF;
1749 END IF; -- }set release info
1750 End if; --}-- <> 'WC'
1751 /* Complex Work.
1752 * Add exception block.
1753 */
1754 exception
1755 when others then
1756 IF (g_asn_debug = 'Y') THEN
1757 asn_debug.put_line('Exception in derive_po_line_info'||x_progress);
1758 END IF;
1759 raise;
1760 END derive_po_line_info;
1761
1762 PROCEDURE derive_from_org_info(
1763 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1764 n IN OUT NOCOPY BINARY_INTEGER
1765 ) IS
1766 ship_to_org_record rcv_shipment_object_sv.organization_id_record_type;
1767 BEGIN
1768 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1769 AND ( x_cascaded_table(n).from_organization_id IS NULL
1770 AND x_cascaded_table(n).from_organization_code IS NOT NULL) THEN
1771 IF (g_asn_debug = 'Y') THEN
1772 asn_debug.put_line('X_progress ' || x_progress);
1773 END IF;
1774
1775 ship_to_org_record.organization_code := x_cascaded_table(n).from_organization_code;
1776 ship_to_org_record.organization_id := x_cascaded_table(n).from_organization_id;
1777 ship_to_org_record.error_record.error_status := 'S';
1778 ship_to_org_record.error_record.error_message := NULL;
1779
1780 IF (g_asn_debug = 'Y') THEN
1781 asn_debug.put_line('In From Organization Procedure');
1782 END IF;
1783
1784 po_orgs_sv.derive_org_info(ship_to_org_record);
1785
1786 IF (g_asn_debug = 'Y') THEN
1787 asn_debug.put_line('From organization code ' || ship_to_org_record.organization_code);
1788 asn_debug.put_line('From organization id ' || TO_CHAR(ship_to_org_record.organization_id));
1789 asn_debug.put_line('From organization error status ' || ship_to_org_record.error_record.error_status);
1790 END IF;
1791
1792 x_cascaded_table(n).from_organization_code := ship_to_org_record.organization_code;
1793 x_cascaded_table(n).from_organization_id := ship_to_org_record.organization_id;
1794 x_cascaded_table(n).error_status := ship_to_org_record.error_record.error_status;
1795 x_cascaded_table(n).error_message := ship_to_org_record.error_record.error_message;
1796
1797 /* po_orgs_sv does not follow error handling paradigm */
1798 IF (x_cascaded_table(n).error_status = 'F') THEN
1799 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1800 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
1801 END IF;
1802
1803 END IF;
1804 END derive_from_org_info;
1805
1806 PROCEDURE derive_transit_org_info(
1807 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1808 n IN OUT NOCOPY BINARY_INTEGER
1809 ) IS
1810 ship_to_org_record rcv_shipment_object_sv.organization_id_record_type;
1811 BEGIN
1812 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1813 AND ( x_cascaded_table(n).intransit_owning_org_id IS NULL
1814 AND x_cascaded_table(n).intransit_owning_org_code IS NOT NULL) THEN
1815 IF (g_asn_debug = 'Y') THEN
1816 asn_debug.put_line('X_progress ' || x_progress);
1817 END IF;
1818
1819 ship_to_org_record.organization_code := x_cascaded_table(n).intransit_owning_org_code;
1820 ship_to_org_record.organization_id := x_cascaded_table(n).intransit_owning_org_id;
1821 ship_to_org_record.error_record.error_status := 'S';
1822 ship_to_org_record.error_record.error_message := NULL;
1823
1824 IF (g_asn_debug = 'Y') THEN
1825 asn_debug.put_line('In Intransit Owning Org Record Procedure');
1826 END IF;
1827
1828 po_orgs_sv.derive_org_info(ship_to_org_record);
1829
1830 IF (g_asn_debug = 'Y') THEN
1831 asn_debug.put_line('Intransit organization code ' || ship_to_org_record.organization_code);
1832 asn_debug.put_line('Intransit organization id ' || TO_CHAR(ship_to_org_record.organization_id));
1833 asn_debug.put_line('Intransit error status ' || ship_to_org_record.error_record.error_status);
1834 END IF;
1835
1836 x_cascaded_table(n).intransit_owning_org_code := ship_to_org_record.organization_code;
1837 x_cascaded_table(n).intransit_owning_org_id := ship_to_org_record.organization_id;
1838 x_cascaded_table(n).error_status := ship_to_org_record.error_record.error_status;
1839 x_cascaded_table(n).error_message := ship_to_org_record.error_record.error_message;
1840
1841 /* po_orgs_sv does not follow error handling paradigm */
1842 IF (x_cascaded_table(n).error_status = 'F') THEN
1843 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
1844 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
1845 END IF;
1846
1847 END IF;
1848 END derive_transit_org_info;
1849
1850 PROCEDURE derive_location_info(
1851 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1852 n IN OUT NOCOPY BINARY_INTEGER
1853 ) IS
1854 location_id_record rcv_shipment_object_sv.location_id_record_type;
1855 BEGIN
1856 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1857 AND ( x_cascaded_table(n).location_id IS NULL
1858 AND x_cascaded_table(n).location_code IS NOT NULL) THEN
1859 IF (g_asn_debug = 'Y') THEN
1860 asn_debug.put_line('X_progress ' || x_progress);
1861 END IF;
1862
1863 location_id_record.location_code := x_cascaded_table(n).location_code;
1864 location_id_record.error_record.error_status := 'S';
1865 location_id_record.error_record.error_message := NULL;
1866
1867 IF (g_asn_debug = 'Y') THEN
1868 asn_debug.put_line('Derive location_id');
1869 END IF;
1870
1871 rcv_transactions_interface_sv.get_location_id(location_id_record);
1872 x_cascaded_table(n).location_id := location_id_record.location_id;
1873 x_cascaded_table(n).error_status := location_id_record.error_record.error_status;
1874 x_cascaded_table(n).error_message := location_id_record.error_record.error_message;
1875 END IF;
1876 END derive_location_info;
1877
1878 PROCEDURE derive_ship_to_location_info(
1879 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1880 n IN OUT NOCOPY BINARY_INTEGER
1881 ) IS
1882 location_id_record rcv_shipment_object_sv.location_id_record_type;
1883 BEGIN
1884 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1885 AND ( x_cascaded_table(n).ship_to_location_id IS NULL
1886 AND x_cascaded_table(n).ship_to_location_code IS NOT NULL) THEN
1887 IF (g_asn_debug = 'Y') THEN
1888 asn_debug.put_line('X_progress ' || x_progress);
1889 END IF;
1890
1891 location_id_record.location_code := x_cascaded_table(n).ship_to_location_code;
1892 location_id_record.error_record.error_status := 'S';
1893 location_id_record.error_record.error_message := NULL;
1894
1895 IF (g_asn_debug = 'Y') THEN
1896 asn_debug.put_line('Derive ship to location_id');
1897 END IF;
1898
1899 rcv_transactions_interface_sv.get_location_id(location_id_record);
1900 x_cascaded_table(n).ship_to_location_id := location_id_record.location_id;
1901 x_cascaded_table(n).error_status := location_id_record.error_record.error_status;
1902 x_cascaded_table(n).error_message := location_id_record.error_record.error_message;
1903 END IF;
1904 END derive_ship_to_location_info;
1905
1906 PROCEDURE derive_routing_header_info(
1907 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1908 n IN OUT NOCOPY BINARY_INTEGER
1909 ) IS
1910 routing_header_id_record rcv_shipment_line_sv.routing_header_id_rec_type;
1911 BEGIN
1912 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1913 AND ( x_cascaded_table(n).routing_header_id IS NULL
1914 AND x_cascaded_table(n).routing_code IS NOT NULL) THEN
1915 IF (g_asn_debug = 'Y') THEN
1916 asn_debug.put_line('X_progress ' || x_progress);
1917 END IF;
1918
1919 routing_header_id_record.routing_code := x_cascaded_table(n).routing_code;
1920 routing_header_id_record.error_record.error_status := 'S';
1921 routing_header_id_record.error_record.error_message := NULL;
1922
1923 IF (g_asn_debug = 'Y') THEN
1924 asn_debug.put_line('Derive routing_header_id');
1925 END IF;
1926
1927 rcv_transactions_interface_sv.get_routing_header_id(routing_header_id_record);
1928 x_cascaded_table(n).routing_header_id := routing_header_id_record.routing_header_id;
1929 x_cascaded_table(n).error_status := routing_header_id_record.error_record.error_status;
1930 x_cascaded_table(n).error_message := routing_header_id_record.error_record.error_message;
1931 END IF;
1932 END derive_routing_header_info;
1933
1934 PROCEDURE derive_routing_step_info(
1935 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1936 n IN OUT NOCOPY BINARY_INTEGER
1937 ) IS
1938 routing_step_id_record rcv_shipment_line_sv.routing_step_id_rec_type;
1939 BEGIN
1940 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1941 AND ( x_cascaded_table(n).routing_step_id IS NULL
1942 AND x_cascaded_table(n).routing_step IS NOT NULL) THEN
1943 IF (g_asn_debug = 'Y') THEN
1944 asn_debug.put_line('X_progress ' || x_progress);
1945 END IF;
1946
1947 routing_step_id_record.routing_step := x_cascaded_table(n).routing_step;
1948 routing_step_id_record.error_record.error_status := 'S';
1949 routing_step_id_record.error_record.error_message := NULL;
1950
1951 IF (g_asn_debug = 'Y') THEN
1952 asn_debug.put_line('Derive routing Step Id');
1953 END IF;
1954
1955 rcv_transactions_interface_sv.get_routing_step_id(routing_step_id_record);
1956 x_cascaded_table(n).routing_step_id := routing_step_id_record.routing_step_id;
1957 x_cascaded_table(n).error_status := routing_step_id_record.error_record.error_status;
1958 x_cascaded_table(n).error_message := routing_step_id_record.error_record.error_message;
1959 END IF;
1960 END derive_routing_step_info;
1961
1962 PROCEDURE derive_deliver_to_person_info(
1963 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
1964 n IN OUT NOCOPY BINARY_INTEGER
1965 ) IS
1966 employee_id_record rcv_shipment_object_sv.employee_id_record_type;
1967 BEGIN
1968 IF (x_cascaded_table(n).error_status IN('S', 'W'))
1969 AND ( x_cascaded_table(n).deliver_to_person_id IS NULL
1970 AND x_cascaded_table(n).deliver_to_person_name IS NOT NULL) THEN
1971 IF (g_asn_debug = 'Y') THEN
1972 asn_debug.put_line('X_progress ' || x_progress);
1973 END IF;
1974
1975 employee_id_record.employee_name := x_cascaded_table(n).deliver_to_person_name;
1976 employee_id_record.employee_id := x_cascaded_table(n).deliver_to_person_id;
1977 employee_id_record.error_record.error_status := 'S';
1978 employee_id_record.error_record.error_message := NULL;
1979
1980 IF (g_asn_debug = 'Y') THEN
1981 asn_debug.put_line('In Derive deliver_to_person_id Information');
1982 END IF;
1983
1984 po_employees_sv.derive_employee_info(employee_id_record);
1985
1986 IF (g_asn_debug = 'Y') THEN
1987 asn_debug.put_line('Employee name ' || employee_id_record.employee_name);
1988 asn_debug.put_line('Employee id ' || TO_CHAR(employee_id_record.employee_id));
1989 asn_debug.put_line('Employee error status ' || employee_id_record.error_record.error_status);
1990 END IF;
1991
1992 x_cascaded_table(n).deliver_to_person_name := employee_id_record.employee_name;
1993 x_cascaded_table(n).deliver_to_person_id := employee_id_record.employee_id;
1994 x_cascaded_table(n).error_status := employee_id_record.error_record.error_status;
1995 x_cascaded_table(n).error_message := employee_id_record.error_record.error_message;
1996
1997 /* po_orgs_sv does not follow error handling paradigm */
1998 IF (x_cascaded_table(n).error_status = 'F') THEN
1999 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2000 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
2001 END IF;
2002
2003 END IF;
2004 END derive_deliver_to_person_info;
2005
2006 PROCEDURE derive_deliver_to_loc_info(
2007 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2008 n IN OUT NOCOPY BINARY_INTEGER
2009 ) IS
2010 location_id_record rcv_shipment_object_sv.location_id_record_type;
2011 BEGIN
2012 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2013 AND ( x_cascaded_table(n).deliver_to_location_id IS NULL
2014 AND x_cascaded_table(n).deliver_to_location_code IS NOT NULL) THEN
2015 IF (g_asn_debug = 'Y') THEN
2016 asn_debug.put_line('X_progress ' || x_progress);
2017 END IF;
2018
2019 location_id_record.location_code := x_cascaded_table(n).deliver_to_location_code;
2020 location_id_record.error_record.error_status := 'S';
2021 location_id_record.error_record.error_message := NULL;
2022
2023 IF (g_asn_debug = 'Y') THEN
2024 asn_debug.put_line('Derive deliver_to_location_id');
2025 END IF;
2026
2027 rcv_transactions_interface_sv.get_location_id(location_id_record);
2028 x_cascaded_table(n).deliver_to_location_id := location_id_record.location_id;
2029 x_cascaded_table(n).error_status := location_id_record.error_record.error_status;
2030 x_cascaded_table(n).error_message := location_id_record.error_record.error_message;
2031 END IF;
2032 END derive_deliver_to_loc_info;
2033
2034 /* WMS Change for receiving(from) locators */
2035 PROCEDURE derive_from_locator_id(
2036 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2037 n IN OUT NOCOPY BINARY_INTEGER
2038 ) IS
2039 BEGIN
2040 IF ( x_cascaded_table(n).from_locator_id IS NULL
2041 AND x_cascaded_table(n).from_locator IS NOT NULL) THEN
2042 IF (g_asn_debug = 'Y') THEN
2043 asn_debug.put_line('inside derive_from_locator_id');
2044 END IF;
2045
2046 SELECT MAX(ml.inventory_location_id)
2047 INTO x_cascaded_table(n).from_locator_id
2048 FROM mtl_item_locations_kfv ml
2049 WHERE ml.concatenated_segments = x_cascaded_table(n).from_locator
2050 AND ( ml.disable_date > SYSDATE
2051 OR ml.disable_date IS NULL)
2052 AND NVL(ml.subinventory_code, 'z') = NVL(x_cascaded_table(n).from_subinventory, 'z')
2053 AND x_cascaded_table(n).to_organization_id = ml.organization_id;
2054
2055 IF (x_cascaded_table(n).from_locator_id IS NULL) THEN
2056 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2057 rcv_error_pkg.set_error_message('RCV_ALL_INVALID_LOCATOR', x_cascaded_table(n).error_message);
2058 END IF;
2059 END IF;
2060 EXCEPTION
2061 WHEN OTHERS THEN
2062 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2063 rcv_error_pkg.set_sql_error_message('derive_from_locator_id', '000');
2064 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2065 END derive_from_locator_id;
2066
2067 PROCEDURE derive_to_locator_id(
2068 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2069 n IN OUT NOCOPY BINARY_INTEGER
2070 ) IS
2071 BEGIN
2072 IF ( x_cascaded_table(n).locator_id IS NULL
2073 AND x_cascaded_table(n).LOCATOR IS NOT NULL
2074 AND x_cascaded_table(n).subinventory IS NOT NULL) THEN /* Bug3993867 */
2075
2076 IF (g_asn_debug = 'Y') THEN
2077 asn_debug.put_line('inside derive_to_locator_id');
2078 END IF;
2079
2080 SELECT MAX(ml.inventory_location_id)
2081 INTO x_cascaded_table(n).locator_id
2082 FROM mtl_item_locations_kfv ml
2083 WHERE ml.concatenated_segments = x_cascaded_table(n).LOCATOR
2084 AND ( ml.disable_date > SYSDATE
2085 OR ml.disable_date IS NULL)
2086 AND NVL(ml.subinventory_code, 'z') = NVL(x_cascaded_table(n).subinventory, 'z')
2087 AND x_cascaded_table(n).to_organization_id = ml.organization_id;
2088
2089 IF (x_cascaded_table(n).locator_id IS NULL) THEN
2090 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2091 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 */
2092 END IF;
2093 END IF;
2094 EXCEPTION
2095 WHEN OTHERS THEN
2096 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2097 rcv_error_pkg.set_sql_error_message('derive_to_locator_id', '000');
2098 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2099 END derive_to_locator_id;
2100
2101 PROCEDURE validate_non_services_fields(
2102 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2103 n IN BINARY_INTEGER
2104 ) IS
2105 BEGIN
2106 IF (g_asn_debug = 'Y') THEN
2107 asn_debug.put_line('In validate_non_services_fields');
2108 END IF;
2109
2110 IF x_cascaded_table(n).matching_basis = 'AMOUNT' THEN --{
2111 IF (g_asn_debug = 'Y') THEN
2112 asn_debug.put_line('In first part validate_non_services_fields');
2113 END IF;
2114
2115 /* Bug 5186378: Added the following condtions,
2116 * 1) source_doc_quantity <> 0 and
2117 * 2) primary_quantity <> 0
2118 */
2119 IF x_cascaded_table(n).item_id IS NOT NULL
2120 OR x_cascaded_table(n).item_revision IS NOT NULL
2121 OR x_cascaded_table(n).substitute_item_num IS NOT NULL
2122 OR x_cascaded_table(n).substitute_item_id IS NOT NULL
2123 OR x_cascaded_table(n).quantity IS NOT NULL
2124 OR ( x_cascaded_table(n).primary_quantity IS NOT NULL
2125 AND x_cascaded_table(n).primary_quantity <> 0 )
2126 OR ( x_cascaded_table(n).source_doc_quantity IS NOT NULL
2127 AND x_cascaded_table(n).source_doc_quantity <> 0 )
2128 OR x_cascaded_table(n).vendor_cum_shipped_qty IS NOT NULL
2129 OR x_cascaded_table(n).quantity_shipped IS NOT NULL
2130 OR x_cascaded_table(n).quantity_invoiced IS NOT NULL
2131 OR x_cascaded_table(n).secondary_quantity IS NOT NULL
2132 OR ( x_cascaded_table(n).job_id IS NOT NULL
2133 AND ( x_cascaded_table(n).value_basis = 'FIXED PRICE'
2134 AND x_cascaded_table(n).purchase_basis = 'SERVICES')) THEN --{
2135 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2136 rcv_error_pkg.set_error_message('RCV_IRRELEVANT_VALUES', x_cascaded_table(n).error_message);
2137 rcv_error_pkg.log_interface_error('MATCHING_BASIS', FALSE);
2138 END IF; --}
2139
2140 IF x_cascaded_table(n).error_status IN('S', 'W') THEN --{
2141 IF ( x_cascaded_table(n).value_basis = 'RATE'
2142 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR') THEN
2143 IF (g_asn_debug = 'Y') THEN
2144 asn_debug.put_line('RATE/TEMP LABOR. They can have the foll values. Hence return.');
2145 END IF;
2146
2147 RETURN;
2148 END IF;
2149
2150 IF ( x_cascaded_table(n).unit_of_measure IS NOT NULL
2151 OR x_cascaded_table(n).primary_unit_of_measure IS NOT NULL
2152 OR x_cascaded_table(n).secondary_unit_of_measure IS NOT NULL
2153 OR x_cascaded_table(n).source_doc_unit_of_measure IS NOT NULL
2154 OR x_cascaded_table(n).uom_code IS NOT NULL
2155 OR x_cascaded_table(n).secondary_uom_code IS NOT NULL
2156 OR x_cascaded_table(n).po_unit_price IS NOT NULL
2157 OR x_cascaded_table(n).timecard_id IS NOT NULL
2158 OR x_cascaded_table(n).timecard_ovn IS NOT NULL
2159 ) THEN --{
2160 IF (g_asn_debug = 'Y') THEN
2161 asn_debug.put_line('Not RATE/TEMP LABOR');
2162 END IF;
2163
2164 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
2165 rcv_error_pkg.set_error_message('RCV_IRRELEVANT_VALUES', x_cascaded_table(n).error_message);
2166 rcv_error_pkg.log_interface_error('MATCHING_BASIS', FALSE);
2167 END IF; --}
2168 END IF; --}
2169 END IF; --}
2170
2171 IF (g_asn_debug = 'Y') THEN
2172 asn_debug.put_line('Leave validate_non_services_fields');
2173 END IF;
2174 EXCEPTION
2175 WHEN OTHERS THEN
2176 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2177 rcv_error_pkg.set_sql_error_message('derive_to_locator_id', '000');
2178 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2179 rcv_error_pkg.log_interface_error('MATCHING_BASIS', FALSE);
2180 END validate_non_services_fields;
2181
2182 /* We cannot default_from_subloc and default_to_subloc since
2183 * for deliver txn, we need from values but not to values.
2184 * Also for transfer these values are different. So it is
2185 * better to separate them out.
2186 */
2187 PROCEDURE default_from_subloc_info(
2188 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2189 n IN BINARY_INTEGER
2190 ) IS
2191 l_from_subinventory rcv_transactions.from_subinventory%TYPE;
2192 l_from_locator_id rcv_transactions.from_locator_id%TYPE;
2193 l_to_subinventory rcv_transactions.subinventory%TYPE;
2194 l_to_locator_id rcv_transactions.locator_id%TYPE;
2195 BEGIN
2196 IF (g_asn_debug = 'Y') THEN
2197 asn_debug.put_line('inside default_from_subloc_info');
2198 END IF;
2199
2200 /* If parent_interface_id is not null then it means it is a parent
2201 * child relation ship. So look in rti. If parent_transaction_id
2202 * is not null, then look in rcv_transactions.
2203 */
2204 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
2205 SELECT subinventory,
2206 locator_id,
2207 from_subinventory,
2208 from_locator_id
2209 INTO l_to_subinventory,
2210 l_to_locator_id,
2211 l_from_subinventory,
2212 l_from_locator_id
2213 FROM rcv_transactions_interface rti
2214 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
2215 ELSIF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
2216 SELECT subinventory,
2217 locator_id,
2218 from_subinventory,
2219 from_locator_id
2220 INTO l_to_subinventory,
2221 l_to_locator_id,
2222 l_from_subinventory,
2223 l_from_locator_id
2224 FROM rcv_transactions rt
2225 WHERE rt.transaction_id = x_cascaded_table(n).parent_transaction_id;
2226 END IF;
2227
2228 IF (g_asn_debug = 'Y') THEN
2229 asn_debug.put_line('l_to_subinventory ' || l_to_subinventory);
2230 asn_debug.put_line('l_to_locator_id ' || l_to_locator_id);
2231 asn_debug.put_line('l_from_subinventory, ' || l_from_subinventory);
2232 asn_debug.put_line('l_from_locator_id ' || l_from_locator_id);
2233 END IF;
2234
2235 /* For Accept, Reject and +ve corrections, from_subinventory and
2236 * from_locator is same as that of the parent. For RTV, this will come here only
2237 * when user has not specified from_subinventory.
2238 */
2239 /* Bug 3557343.
2240 * For Accept/Reject transactions, we want the from_sub/from_loc
2241 * to be the same as that of the parent's to_sub/to_loc since
2242 * we cannot change the sub/loc at the time of inspection. So
2243 * it will remain in the same sub/loc making both from and to
2244 * sub/loc the same as that of the parent.
2245 */
2246 IF ( x_cascaded_table(n).transaction_type = 'CORRECT'
2247 AND SIGN(x_cascaded_table(n).quantity) = 1) THEN
2248 x_cascaded_table(n).from_subinventory := l_from_subinventory;
2249 x_cascaded_table(n).from_locator_id := l_from_locator_id;
2250 ELSE /* For all other transaction types */
2251 x_cascaded_table(n).from_subinventory := l_to_subinventory;
2252 x_cascaded_table(n).from_locator_id := l_to_locator_id;
2253 END IF;
2254
2255 IF (g_asn_debug = 'Y') THEN
2256 asn_debug.put_line('x_cascaded_table(n).from_subinventory ' || x_cascaded_table(n).from_subinventory);
2257 asn_debug.put_line('x_cascaded_table(n).from_locator_id ' || x_cascaded_table(n).from_locator_id);
2258 END IF;
2259 EXCEPTION
2260 WHEN OTHERS THEN
2261 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2262 rcv_error_pkg.set_sql_error_message('default_from_subloc_info', '000');
2263 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2264 END default_from_subloc_info;
2265
2266 PROCEDURE default_to_subloc_info(
2267 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2268 n IN BINARY_INTEGER
2269 ) IS
2270 l_from_subinventory rcv_transactions.from_subinventory%TYPE;
2271 l_from_locator_id rcv_transactions.from_locator_id%TYPE;
2272 l_to_subinventory rcv_transactions.subinventory%TYPE;
2273 l_to_locator_id rcv_transactions.locator_id%TYPE;
2274 x_locator_control NUMBER;
2275 x_default_subinventory VARCHAR2(10);
2276 x_default_locator_id NUMBER;
2277 x_success BOOLEAN;
2278 BEGIN
2279 IF (g_asn_debug = 'Y') THEN
2280 asn_debug.put_line('inside default_to_subloc_info');
2281 END IF;
2282
2283 /* Get default subinventory from the setup if it is a direct delivery
2284 * or just a delivery and if subinventory is null.
2285 */
2286 IF (x_cascaded_table(n).transaction_type IN('RECEIVE', 'DELIVER')) THEN --{
2287 IF ( (x_cascaded_table(n).auto_transact_code <> 'RECEIVE')
2288 OR x_cascaded_table(n).auto_transact_code IS NULL) THEN --{
2289 /*
2290 ** A subinventory must have been defined on the po or a default
2291 ** must be available for the item. If it's not already defined
2292 ** then go get it out of inventory. If you're using express
2293 ** then it's ok to get the default rather than having it be
2294 ** defined on the record
2295 */
2296 IF (x_cascaded_table(n).subinventory IS NULL) THEN --{
2297 /*
2298 ** If you're using express then it's ok to get the default
2299 ** rather than having it be defined on the record
2300 */
2301 x_progress := '120';
2302 po_subinventories_s.get_default_subinventory(x_cascaded_table(n).to_organization_id,
2303 x_cascaded_table(n).item_id,
2304 x_cascaded_table(n).subinventory
2305 );
2306
2307 IF (g_asn_debug = 'Y') THEN
2308 asn_debug.put_line('Defaulting subinventory from item: Sub = ' || x_cascaded_table(n).subinventory);
2309 END IF;
2310 END IF; --} (X_cascaded_table(n).subinventory IS NULL)
2311 END IF; --}
2312
2313 /* We can have sub/loc for receive and deliver transaction. If subinventory
2314 * is not null and locator_id is null, then get the default locator_id if
2315 * the there is a locator.
2316 */
2317 IF (x_cascaded_table(n).subinventory IS NOT NULL) THEN --{
2318 x_progress := '122';
2319 po_subinventories_s.get_locator_control(x_cascaded_table(n).to_organization_id,
2320 x_cascaded_table(n).subinventory,
2321 x_cascaded_table(n).item_id,
2322 x_locator_control
2323 );
2324
2325 IF (g_asn_debug = 'Y') THEN
2326 asn_debug.put_line('Locator Control = ' || TO_CHAR(x_locator_control));
2327 END IF;
2328
2329 /*
2330 ** If locator control is 2 which means it is under predefined
2331 ** locator contol or 3 which means it's under dynamic (any value)
2332 ** locator control then you need to go get the default locator id
2333 */
2334 IF ( ( x_locator_control = 2
2335 OR x_locator_control = 3)
2336 AND x_cascaded_table(n).locator_id IS NULL) THEN --{
2337 x_progress := '123';
2338 po_subinventories_s.get_default_locator(x_cascaded_table(n).to_organization_id,
2339 x_cascaded_table(n).item_id,
2340 x_cascaded_table(n).subinventory,
2341 x_cascaded_table(n).locator_id
2342 );
2343
2344 IF (g_asn_debug = 'Y') THEN
2345 asn_debug.put_line('Defaulting locator from Sub: Locator_id = ' || TO_CHAR(x_cascaded_table(n).locator_id));
2346 END IF;
2347 END IF; --}
2348 END IF; --} matches subinventory not null
2349
2350 IF ( (x_cascaded_table(n).auto_transact_code <> 'RECEIVE')
2351 OR x_cascaded_table(n).auto_transact_code IS NULL) THEN --{
2352 x_default_subinventory := x_cascaded_table(n).subinventory;
2353 x_default_locator_id := x_cascaded_table(n).locator_id;
2354 /*
2355 ** Call the put away function
2356 */
2357 x_success := rcv_sub_locator_sv.put_away_api(x_cascaded_table(n).po_line_location_id,
2358 x_cascaded_table(n).po_distribution_id,
2359 x_cascaded_table(n).shipment_line_id,
2360 x_cascaded_table(n).receipt_source_code,
2361 x_cascaded_table(n).from_organization_id,
2362 x_cascaded_table(n).to_organization_id,
2363 x_cascaded_table(n).item_id,
2364 x_cascaded_table(n).item_revision,
2365 x_cascaded_table(n).vendor_id,
2366 x_cascaded_table(n).ship_to_location_id,
2367 x_cascaded_table(n).deliver_to_location_id,
2368 x_cascaded_table(n).deliver_to_person_id,
2369 x_cascaded_table(n).quantity,
2370 x_cascaded_table(n).primary_quantity,
2371 x_cascaded_table(n).primary_unit_of_measure,
2372 x_cascaded_table(n).quantity,
2373 x_cascaded_table(n).unit_of_measure,
2374 x_cascaded_table(n).routing_header_id,
2375 x_default_subinventory,
2376 x_default_locator_id,
2377 x_cascaded_table(n).subinventory,
2378 x_cascaded_table(n).locator_id
2379 );
2380 END IF; --}
2381
2382 /* If subinventory is still null, we need to disable dropship asn auto deliver if it has
2383 * been enabled and change the transaction back to ASN import*/
2384 IF ( (x_auto_deliver = 'Y') AND
2385 (x_cascaded_table(n).subinventory IS NULL)) THEN --{
2386
2387 IF (g_asn_debug = 'Y') THEN
2388 asn_debug.put_line('Warning: Changing the dropship ASN auto deliver back to ASN import.');
2389 asn_debug.put_line('Cause: Receiving preprocessor could not default a subinventory for this trxn.');
2390 END IF;
2391
2392 -- Change the transaction back to ASN import
2393 x_cascaded_table(n).transaction_type := 'SHIP';
2394 x_cascaded_table(n).auto_transact_code := 'SHIP';
2395 -- Reset the flag so that it won't affect the next transaction.
2396 x_auto_deliver := 'N';
2397 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
2398
2399 -- Log po_interface_errors
2400 rcv_error_pkg.set_error_message('RCV_ASN_AUTO_DEL_NO_SUBINV');
2401 rcv_error_pkg.log_interface_warning('SUBINVENTORY');
2402 END IF; --}
2403
2404 RETURN;
2405 END IF; --}
2406
2407 /* Bug 3568861.
2408 * We need to default the subinventory_code and locator_id
2409 * based on the transfer_lpn_id or lpn_id if they are not null
2410 * null based on the transactions. If they are null, then we
2411 * need to default from the parent. For +ve correct or
2412 * RTR, default using transfer_lpn_id. For -ve correct use lpn_id
2413 * to default sub/loc.
2414 */
2415 IF ( ( ( x_cascaded_table(n).transaction_type = 'CORRECT'
2416 AND SIGN(x_cascaded_table(n).quantity) = 1)
2417 OR (x_cascaded_table(n).transaction_type = 'RETURN TO RECEIVING'))
2418 AND (x_cascaded_table(n).transfer_lpn_id IS NOT NULL)) THEN
2419 IF (g_asn_debug = 'Y') THEN
2420 asn_debug.put_line('+Ve correct or RTR with transfer_lpn_id not null');
2421 END IF;
2422
2423 SELECT subinventory_code,
2424 locator_id
2425 INTO x_cascaded_table(n).subinventory,
2426 x_cascaded_table(n).locator_id
2427 FROM wms_license_plate_numbers
2428 WHERE lpn_id = x_cascaded_table(n).transfer_lpn_id;
2429
2430 IF (g_asn_debug = 'Y') THEN
2431 asn_debug.put_line('Sub is ' || x_cascaded_table(n).subinventory);
2432 asn_debug.put_line('Loc is ' || x_cascaded_table(n).locator_id);
2433 asn_debug.put_line('Return ');
2434 END IF;
2435
2436 RETURN;
2437 END IF;
2438
2439 IF ( ( x_cascaded_table(n).transaction_type = 'CORRECT'
2440 AND SIGN(x_cascaded_table(n).quantity) = -1)
2441 AND (x_cascaded_table(n).lpn_id IS NOT NULL)) THEN
2442 IF (g_asn_debug = 'Y') THEN
2443 asn_debug.put_line('-Ve correct with lpn_id not null');
2444 END IF;
2445
2446 SELECT subinventory_code,
2447 locator_id
2448 INTO x_cascaded_table(n).subinventory,
2449 x_cascaded_table(n).locator_id
2450 FROM wms_license_plate_numbers
2451 WHERE lpn_id = x_cascaded_table(n).lpn_id;
2452
2453 IF (g_asn_debug = 'Y') THEN
2454 asn_debug.put_line('Sub is ' || x_cascaded_table(n).subinventory);
2455 asn_debug.put_line('Loc is ' || x_cascaded_table(n).locator_id);
2456 asn_debug.put_line('Return ');
2457 END IF;
2458
2459 RETURN;
2460 END IF;
2461
2462 /* End of bug 3568861. */
2463
2464 /* If parent_interface_id is not null then it means it is a parent
2465 * child relation ship. So look in rti. If parent_transaction_id
2466 * is not null, then look in rcv_transactions.
2467 */
2468 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
2469 SELECT subinventory,
2470 locator_id,
2471 from_subinventory,
2472 from_locator_id
2473 INTO l_to_subinventory,
2474 l_to_locator_id,
2475 l_from_subinventory,
2476 l_from_locator_id
2477 FROM rcv_transactions_interface rti
2478 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
2479 ELSIF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
2480 SELECT subinventory,
2481 locator_id,
2482 from_subinventory,
2483 from_locator_id
2484 INTO l_to_subinventory,
2485 l_to_locator_id,
2486 l_from_subinventory,
2487 l_from_locator_id
2488 FROM rcv_transactions rt
2489 WHERE rt.transaction_id = x_cascaded_table(n).parent_transaction_id;
2490 END IF;
2491
2492 IF (g_asn_debug = 'Y') THEN
2493 asn_debug.put_line('l_to_subinventory ' || l_to_subinventory);
2494 asn_debug.put_line('l_to_locator_id ' || l_to_locator_id);
2495 asn_debug.put_line('l_from_subinventory, ' || l_from_subinventory);
2496 asn_debug.put_line('l_from_locator_id ' || l_from_locator_id);
2497 END IF;
2498
2499 /* For Accept, Reject and +ve corrections, to_subinventory and
2500 * to_locator is same as that of the parent.
2501 */
2502 IF ( (x_cascaded_table(n).transaction_type IN('ACCEPT', 'REJECT'))
2503 OR ( x_cascaded_table(n).transaction_type = 'CORRECT'
2504 AND SIGN(x_cascaded_table(n).quantity) = 1)) THEN
2505 x_cascaded_table(n).subinventory := l_to_subinventory;
2506 x_cascaded_table(n).locator_id := l_to_locator_id;
2507 ELSE /* For all other transaction types */
2508 x_cascaded_table(n).subinventory := l_from_subinventory;
2509 x_cascaded_table(n).locator_id := l_from_locator_id;
2510 END IF;
2511
2512 IF (g_asn_debug = 'Y') THEN
2513 asn_debug.put_line('x_cascaded_table(n).subinventory ' || x_cascaded_table(n).subinventory);
2514 asn_debug.put_line('x_cascaded_table(n).locator_id ' || x_cascaded_table(n).locator_id);
2515 END IF;
2516
2517 EXCEPTION
2518 WHEN OTHERS THEN
2519 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
2520 rcv_error_pkg.set_sql_error_message('default_to_subloc_info', '000');
2521 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
2522 END default_to_subloc_info;
2523
2524 /* WMS Change End */
2525 PROCEDURE derive_reason_info(
2526 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2527 n IN OUT NOCOPY BINARY_INTEGER
2528 ) IS
2529 reason_id_record rcv_shipment_line_sv.reason_id_record_type;
2530 BEGIN
2531 IF (x_cascaded_table(n).error_status IN('S', 'W'))
2532 AND ( x_cascaded_table(n).reason_id IS NULL
2533 AND x_cascaded_table(n).reason_name IS NOT NULL) THEN
2534 IF (g_asn_debug = 'Y') THEN
2535 asn_debug.put_line('X_progress ' || x_progress);
2536 END IF;
2537
2538 reason_id_record.reason_name := x_cascaded_table(n).reason_name;
2539 reason_id_record.error_record.error_status := 'S';
2540 reason_id_record.error_record.error_message := NULL;
2541
2542 IF (g_asn_debug = 'Y') THEN
2543 asn_debug.put_line('Derive Reason_id');
2544 END IF;
2545
2546 rcv_transactions_interface_sv.get_reason_id(reason_id_record);
2547 x_cascaded_table(n).reason_id := reason_id_record.reason_id;
2548 x_cascaded_table(n).error_status := reason_id_record.error_record.error_status;
2549 x_cascaded_table(n).error_message := reason_id_record.error_record.error_message;
2550 END IF;
2551 END derive_reason_info;
2552
2553 PROCEDURE derive_auto_transact_code(
2554 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2555 n IN OUT NOCOPY BINARY_INTEGER
2556 ) IS
2557 BEGIN
2558 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
2559 /* Moved dropship flag drivation here so that it's available
2560 * for use in all transaction types*/
2561 BEGIN
2562 SELECT drop_ship_flag
2563 INTO x_drop_ship_flag
2564 FROM po_line_locations_all
2565 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
2566 -- if no data found, do nothing
2567 EXCEPTION
2568 WHEN NO_DATA_FOUND THEN
2569 IF (g_asn_debug = 'Y') THEN
2570 asn_debug.put_line('No data found for dropship flag');
2571 END IF;
2572 END;
2573
2574 /* FPJ Services. If matching_basis is AMOUNT, then this is a service
2575 * type PO. We allow only direct delivery for these POs. Set
2576 * routing_header_id to 3 and set auto_transact_code = DELIVER and
2577 * return.
2578 */
2579 IF ( x_cascaded_table(n).transaction_type = 'RECEIVE'
2580 AND x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
2581 /* If auto_transact_code is not deliver, then give a warning
2582 * and default it to deliver.
2583 */
2584 IF (x_cascaded_table(n).auto_transact_code <> 'DELIVER') THEN --{
2585 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
2586 rcv_error_pkg.set_error_message('RCV_DIRECT_DEL_REQ', x_cascaded_table(n).error_message);
2587 rcv_error_pkg.log_interface_warning('DOCUMENT_NUM');
2588
2589 IF (g_asn_debug = 'Y') THEN
2590 asn_debug.put_line('AFter Warning insert into po_interface_errors ' || x_cascaded_table(n).error_message);
2591 END IF;
2592 END IF; --}
2593
2594 IF (g_asn_debug = 'Y') THEN
2595 asn_debug.put_line('Matching Basis is Amount:Setting RCV Routing to Direct Deliver');
2596 END IF;
2597
2598 x_cascaded_table(n).routing_header_id := 3;
2599 x_cascaded_table(n).auto_transact_code := 'DELIVER';
2600 RETURN;
2601 END IF;
2602
2603 /* FPJ SERVICES END. */
2604 IF x_cascaded_table(n).transaction_type = 'SHIP' THEN
2605 /* For ASNs from a drop shipment order, set receving routing to
2606 * Direct Deliver, and if the profile option "PO: Automatically
2607 * Deliver Drop Ship ASNs" is set to Y, set auto_transact_code
2608 * to 'DELIVER'
2609 *
2610 * FPJ International Drop Shipment project - pjiang
2611 */
2612 IF x_drop_ship_flag = 'Y' THEN
2613 IF (g_asn_debug = 'Y') THEN
2614 asn_debug.put_line('Dropship: Setting RCV Routing to Direct Deliver');
2615 END IF;
2616
2617 x_cascaded_table(n).routing_header_id := 3;
2618 fnd_profile.get('PO_AUTO_DELIVER_DROPSHIP_ASN', x_auto_deliver);
2619
2620 IF x_auto_deliver = 'Y' THEN
2621 IF (g_asn_debug = 'Y') THEN
2622 asn_debug.put_line('Dropship: Auto deliver feature enabled, ' || 'set auto_transact_code to DELIVER for drop ship ASNs');
2623 END IF;
2624
2625 x_cascaded_table(n).auto_transact_code := 'DELIVER';
2626 END IF; -- end auto deliver
2627 END IF; -- end drop_ship_flag = 'Y' (external dropship)
2628 END IF; -- end transaction_type = 'SHIP' (ASN)
2629
2630 IF ( x_cascaded_table(n).auto_transact_code IS NULL
2631 AND x_cascaded_table(n).transaction_type IN('SHIP', 'RECEIVE')) THEN
2632 IF (g_asn_debug = 'Y') THEN
2633 asn_debug.put_line('X_progress ' || x_progress);
2634 asn_debug.put_line('Setting auto_transact_code to transaction_type ' || x_cascaded_table(n).transaction_type);
2635 END IF;
2636
2637 x_cascaded_table(n).auto_transact_code := x_cascaded_table(n).transaction_type;
2638 END IF;
2639 END IF;
2640
2641 x_progress := '093';
2642
2643 -- Change transaction type based on combination of
2644 -- transaction_type and auto_transact_code
2645
2646 IF (x_cascaded_table(n).error_status IN('S', 'W')) THEN
2647 IF (g_asn_debug = 'Y') THEN
2648 asn_debug.put_line('X_progress ' || x_progress);
2649 END IF;
2650
2651 IF x_cascaded_table(n).transaction_type = 'SHIP'
2652 AND x_cascaded_table(n).auto_transact_code = 'DELIVER' THEN
2653 IF (g_asn_debug = 'Y') THEN
2654 asn_debug.put_line('Changing the transaction_type to RECEIVE FROM SHIP');
2655 END IF;
2656
2657 x_cascaded_table(n).transaction_type := 'RECEIVE';
2658 END IF;
2659 END IF;
2660 END derive_auto_transact_code;
2661
2662 PROCEDURE derive_vendor_rcv_line_qty(
2663 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2664 n IN OUT NOCOPY BINARY_INTEGER,
2665 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
2666 x_header_record IN rcv_roi_preprocessor.header_rec_type
2667 ) IS
2668 x_include_closed_po VARCHAR2(1); -- Bug 1887728
2669
2670 /* R12 Complex Work.
2671 * Use line_location_id instead of shipment_num since it
2672 * is not unique for a line_id in the case of complex work POs.
2673 * If user has given a PO shipment number through ROI, then
2674 * defaulting package would have derived the line_location_id.
2675 * Changed cursor shipments and count_shipments.
2676 */
2677 CURSOR shipments(
2678 header_id NUMBER,
2679 v_item_id NUMBER,
2680 v_po_line_num NUMBER,
2681 v_po_release_id NUMBER,
2682 v_line_location_id NUMBER,
2683 v_ship_to_org_id NUMBER,
2684 v_ship_to_location_id NUMBER,
2685 v_vendor_product_num VARCHAR2
2686 ) IS
2687 SELECT pll.line_location_id,
2688 pll.unit_meas_lookup_code,
2689 pll.unit_of_measure_class,
2690 NVL(pll.promised_date, pll.need_by_date) promised_date,
2691 pll.ship_to_organization_id,
2692 pll.quantity quantity_ordered,
2693 pll.quantity_shipped,
2694 pll.receipt_days_exception_code,
2695 pll.qty_rcv_tolerance,
2696 pll.qty_rcv_exception_code,
2697 pll.days_early_receipt_allowed,
2698 pll.days_late_receipt_allowed,
2699 NVL(pll.price_override, pl.unit_price) unit_price,
2700 pll.match_option, -- 1845702
2701 pl.category_id,
2702 nvl(pll.description,pl.item_description) item_description,--Complex work
2703 pl.po_line_id,
2704 ph.currency_code,
2705 ph.rate_type, -- 1845702
2706 0 po_distribution_id,
2707 0 code_combination_id,
2708 0 req_distribution_id,
2709 0 deliver_to_location_id,
2710 0 deliver_to_person_id,
2711 ph.rate_date rate_date, --1845702
2712 ph.rate rate, --1845702
2713 '' destination_type_code,
2714 0 destination_organization_id,
2715 '' destination_subinventory,
2716 0 wip_entity_id,
2717 0 wip_operation_seq_num,
2718 0 wip_resource_seq_num,
2719 0 wip_repetitive_schedule_id,
2720 0 wip_line_id,
2721 0 bom_resource_id,
2722 '' ussgl_transaction_code,
2723 pll.ship_to_location_id,
2724 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
2725 TO_NUMBER(NULL) shipment_line_id, --shipment_line_id
2726 pl.item_id
2727 FROM po_line_locations pll,
2728 po_lines pl,
2729 po_headers ph
2730 WHERE ph.po_header_id = header_id
2731 AND pll.po_header_id = header_id
2732 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
2733 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
2734 AND pll.line_location_id = NVL(v_line_location_id, pll.line_location_id) --Bug: 5357628
2735 AND pll.po_line_id = pl.po_line_id
2736 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
2737 AND NVL(pll.approved_flag, 'N') = 'Y'
2738 AND NVL(pll.cancel_flag, 'N') = 'N'
2739 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
2740 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
2741 OR ( NVL(x_include_closed_po, 'N') = 'N'
2742 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
2743 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
2744 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
2745 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
2746 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'))
2747 ORDER BY NVL(pll.promised_date, pll.need_by_date);
2748
2749 CURSOR count_shipments(
2750 header_id NUMBER,
2751 v_item_id NUMBER,
2752 v_po_line_num NUMBER,
2753 v_po_release_id NUMBER,
2754 v_line_location_id NUMBER,
2755 v_ship_to_org_id NUMBER,
2756 v_ship_to_location_id NUMBER,
2757 v_vendor_product_num VARCHAR2
2758 ) IS
2759 SELECT COUNT(*)
2760 FROM po_line_locations pll,
2761 po_lines pl,
2762 po_headers ph
2763 WHERE ph.po_header_id = header_id
2764 AND pll.po_header_id = header_id
2765 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
2766 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
2767 AND pll.line_location_id = NVL(v_line_location_id, pll.line_location_id) --Bug: 5357628
2768 AND pll.po_line_id = pl.po_line_id
2769 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
2770 AND NVL(pll.approved_flag, 'N') = 'Y'
2771 AND NVL(pll.cancel_flag, 'N') = 'N'
2772 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
2773 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
2774 OR ( NVL(x_include_closed_po, 'N') = 'N'
2775 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
2776 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
2777 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
2778 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
2779 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'));
2780
2781 /***** Bug # 1553154
2782 ***** There was a performance issue since the cursor COUNT_DISTRIBUTIONS
2783 ***** was driving through PO_LINE_LOCATIONS_ALL. Modified the Select
2784 ***** statement so that it will drive through PO_HEADERS_ALL
2785 ***** followed by PO_LINES_ALL which is followed by PO_LINE_LOCATIONS_ALL
2786 ***** so that there is an improvement in performance.
2787 *****/
2788 CURSOR distributions(
2789 header_id NUMBER,
2790 v_item_id NUMBER,
2791 v_po_line_num NUMBER,
2792 v_po_release_id NUMBER,
2793 v_shipment_num NUMBER,
2794 v_distribution_num NUMBER,
2795 v_ship_to_org_id NUMBER,
2796 v_ship_to_location_id NUMBER,
2797 v_vendor_product_num VARCHAR2
2798 ) IS
2799 SELECT pll.line_location_id,
2800 pll.unit_meas_lookup_code,
2801 pll.unit_of_measure_class,
2802 NVL(pll.promised_date, pll.need_by_date) promised_date,
2803 pll.ship_to_organization_id,
2804 pll.quantity quantity_ordered,
2805 pll.quantity_shipped,
2806 pll.receipt_days_exception_code,
2807 pll.qty_rcv_tolerance,
2808 pll.qty_rcv_exception_code,
2809 pll.days_early_receipt_allowed,
2810 pll.days_late_receipt_allowed,
2811 NVL(pll.price_override, pl.unit_price) unit_price,
2812 pll.match_option, -- 1845702
2813 pl.category_id,
2814 nvl(pll.description,pl.item_description) item_description,--Complex work
2815 pl.po_line_id,
2816 ph.currency_code,
2817 ph.rate_type, -- 1845702
2818 pod.po_distribution_id,
2819 pod.code_combination_id,
2820 pod.req_distribution_id,
2821 pod.deliver_to_location_id,
2822 pod.deliver_to_person_id,
2823 pod.rate_date,
2824 pod.rate,
2825 pod.destination_type_code,
2826 pod.destination_organization_id,
2827 pod.destination_subinventory,
2828 pod.wip_entity_id,
2829 pod.wip_operation_seq_num,
2830 pod.wip_resource_seq_num,
2831 pod.wip_repetitive_schedule_id,
2832 pod.wip_line_id,
2833 pod.bom_resource_id,
2834 pod.ussgl_transaction_code,
2835 pll.ship_to_location_id,
2836 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
2837 TO_NUMBER(NULL) shipment_line_id, -- shipment_line_id
2838 pl.item_id
2839 FROM po_distributions pod,
2840 po_line_locations pll,
2841 po_lines pl,
2842 po_headers ph
2843 WHERE ph.po_header_id = header_id
2844 AND pl.po_header_id = ph.po_header_id
2845 AND pll.po_line_id = pl.po_line_id
2846 AND pod.line_location_id = pll.line_location_id
2847 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
2848 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
2849 AND pll.shipment_num = NVL(v_shipment_num, pll.shipment_num)
2850 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
2851 AND NVL(pll.approved_flag, 'N') = 'Y'
2852 AND NVL(pll.cancel_flag, 'N') = 'N'
2853 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
2854 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
2855 OR ( NVL(x_include_closed_po, 'N') = 'N'
2856 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
2857 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
2858 AND pod.distribution_num = NVL(v_distribution_num, pod.distribution_num)
2859 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
2860 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
2861 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'))
2862 ORDER BY NVL(pll.promised_date, pll.need_by_date);
2863
2864 /***** Bug # 1553154
2865 ***** There was a performance issue since the cursor DISTRIBUTIONS
2866 ***** was driving through PO_HEADERS_ALL followed by PO_DISTRIBUTIONS_ALL
2867 ***** Modified the Select statement so that it will drive through
2868 ***** PO_HEADERS_ALL followed by PO_LINES_ALL which is followed by
2869 ***** PO_LINE_LOCATIONS_ALL which in turn is followed by
2870 ***** PO_DISTRIBUTIONS_ALL so that there is an improvement in
2871 ***** Performance
2872 *****/
2873 CURSOR count_distributions(
2874 header_id NUMBER,
2875 v_item_id NUMBER,
2876 v_po_line_num NUMBER,
2877 v_po_release_id NUMBER,
2878 v_shipment_num NUMBER,
2879 v_distribution_num NUMBER,
2880 v_ship_to_org_id NUMBER,
2881 v_ship_to_location_id NUMBER,
2882 v_vendor_product_num VARCHAR2
2883 ) IS
2884 SELECT COUNT(*)
2885 FROM po_distributions pod,
2886 po_line_locations pll,
2887 po_lines pl,
2888 po_headers ph
2889 WHERE ph.po_header_id = header_id
2890 AND pl.po_header_id = ph.po_header_id
2891 AND pll.po_line_id = pl.po_line_id
2892 AND pod.line_location_id = pll.line_location_id
2893 AND pl.line_num = NVL(v_po_line_num, pl.line_num)
2894 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
2895 AND pll.shipment_num = NVL(v_shipment_num, pll.shipment_num)
2896 AND pod.distribution_num = NVL(v_distribution_num, pod.distribution_num)
2897 AND NVL(pl.item_id, 0) = NVL(v_item_id, NVL(pl.item_id, 0)) -- v_item_id could be null
2898 AND NVL(pll.approved_flag, 'N') = 'Y'
2899 AND NVL(pll.cancel_flag, 'N') = 'N'
2900 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
2901 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
2902 OR ( NVL(x_include_closed_po, 'N') = 'N'
2903 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
2904 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
2905 AND pll.ship_to_organization_id = NVL(v_ship_to_org_id, pll.ship_to_organization_id)
2906 AND pll.ship_to_location_id = NVL(v_ship_to_location_id, pll.ship_to_location_id)
2907 AND NVL(pl.vendor_product_num, '-999') = NVL(v_vendor_product_num, NVL(pl.vendor_product_num, '-999'));
2908
2909 /*
2910 ** Debug: had to change this to the distribution record
2911 ** Might be a compatibility issue between the two record definitions
2912 */
2913 x_shipmentdistributionrec distributions%ROWTYPE;
2914 x_record_count NUMBER;
2915 x_remaining_quantity NUMBER := 0;
2916 x_remaining_qty_po_uom NUMBER := 0;
2917 x_bkp_qty NUMBER := 0;
2918 x_progress VARCHAR2(3);
2919 x_to_organization_code VARCHAR2(5);
2920 x_converted_trx_qty NUMBER := 0;
2921 transaction_ok BOOLEAN := FALSE;
2922 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
2923 high_range_date DATE;
2924 low_range_date DATE;
2925 rows_fetched NUMBER := 0;
2926 x_tolerable_qty NUMBER := 0;
2927 x_first_trans BOOLEAN := TRUE;
2928 x_sysdate DATE := SYSDATE;
2929 current_n BINARY_INTEGER := 0;
2930 insert_into_table BOOLEAN := FALSE;
2931 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
2932 tax_amount_factor NUMBER;
2933 lastrecord BOOLEAN := FALSE;
2934 po_asn_uom_qty NUMBER;
2935 po_primary_uom_qty NUMBER;
2936 already_allocated_qty NUMBER := 0;
2937 x_item_id NUMBER;
2938 x_approved_flag VARCHAR(1);
2939 x_cancel_flag VARCHAR(1);
2940 x_closed_code VARCHAR(25);
2941 x_shipment_type VARCHAR(25);
2942 x_ship_to_organization_id NUMBER;
2943 x_ship_to_location_id NUMBER;
2944 /* temp_ship_to_location_id number;
2945 temp_mirror_ship_to_loc_id number ;
2946 temp_enf_ship_to_loc_code varchar(25) ; */
2947 /* The above 3 variables added for bug 1898283 */
2948 x_vendor_product_num VARCHAR(25);
2949 x_temp_count NUMBER;
2950 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
2951 /* 1887728 -Added the following variables */
2952 profile_user_id NUMBER := -1;
2953 profile_appl_id NUMBER := -1;
2954 profile_resp_id NUMBER := -1;
2955 defined BOOLEAN;
2956 /* 1845702 */
2957 x_sob_id NUMBER := NULL;
2958 x_rate NUMBER;
2959 x_allow_rate_override VARCHAR2(1);
2960 /* Bug# 1548597 */
2961 x_secondary_available_qty NUMBER := 0;
2962 l_receipt_source_code rcv_shipment_headers.receipt_source_code%TYPE;
2963 l_shipment_line_status_code rcv_shipment_lines.shipment_line_status_code%TYPE;
2964 l_asn_line_flag rcv_shipment_lines.asn_line_flag%TYPE;
2965 l_asn_exists_code rcv_parameters.receipt_asn_exists_code%TYPE;
2966 l_does_asn_exist VARCHAR2(1) := 'N';
2967 l_asn_count NUMBER := 0;
2968 l_dist_count number; /* Bug#3746516 */
2969 l_rate_date po_headers.rate_date%type; /* Bug#3746516 */
2970 x_is_asn BOOLEAN;
2971 l_return_status VARCHAR2(1) :='S';
2972 l_complex_flag varchar2(1) := 'N';
2973 l_blind_receiving_flag VARCHAR2(1) := 'N'; -- Bug 6796920
2974 BEGIN
2975 --check line quanity > 0
2976 x_progress := '097';
2977 profile_user_id := fnd_profile.VALUE('USER_ID');
2978 profile_resp_id := fnd_profile.VALUE('RESPONSIBILITY_ID');
2979 profile_appl_id := fnd_profile.VALUE('APPLICATION_ID');
2980 fnd_profile.get_specific('RCV_CLOSED_PO_DEFAULT_OPTION',
2981 profile_user_id,
2982 profile_resp_id,
2983 profile_appl_id,
2984 x_include_closed_po,
2985 defined
2986 );
2987
2988 IF (g_asn_debug = 'Y') THEN
2989 asn_debug.put_line('Include closed PO profile value ' || x_include_closed_po);
2990 END IF;
2991
2992 IF (g_asn_debug = 'Y') THEN
2993 asn_debug.put_line('X_progress ' || x_progress);
2994 END IF;
2995
2996 IF x_cascaded_table(n).error_status IN('S', 'W')
2997 AND x_cascaded_table(n).quantity <= 0 THEN --{
2998 IF (g_asn_debug = 'Y') THEN
2999 asn_debug.put_line('Quantity is <= zero. Cascade will fail');
3000 END IF;
3001
3002 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3003 rcv_error_pkg.set_error_message('RCV_ITEM_NO_SHIP_QTY', x_cascaded_table(n).error_message);
3004 rcv_error_pkg.set_token('ITEM', x_cascaded_table(n).item_num);
3005 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
3006 END IF; --} end qty > 0 check
3007
3008 -- the following steps will create a set of rows linking the line_record with
3009 -- its corresponding po_line_location rows until the quantity value from
3010 -- the asn is consumed. (Cascade)
3011
3012 /* 2119137 : If the user populates rcv_transactions_interface
3013 with po_line_id, then ROI errors out with
3014 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
3015 is not provided for one time items. Modified the "if" criteria in
3016 such a way that the ROI validation does'nt error out when
3017 po_line_id is populated for one time items. */
3018 x_progress := '098';
3019
3020 IF (g_asn_debug = 'Y') THEN
3021 asn_debug.put_line('X_progress ' || x_progress);
3022 END IF;
3023
3024 IF ( ( x_cascaded_table(n).po_header_id IS NOT NULL
3025 AND ( x_cascaded_table(n).item_id IS NOT NULL
3026 OR x_cascaded_table(n).vendor_item_num IS NOT NULL
3027 OR x_cascaded_table(n).po_line_id IS NOT NULL
3028 OR x_cascaded_table(n).document_line_num IS NOT NULL))
3029 OR (x_cascaded_table(n).shipment_header_id IS NOT NULL AND x_cascaded_table(n).shipment_line_id IS NOT NULL)
3030 AND x_cascaded_table(n).error_status IN('S', 'W')
3031 ) THEN --{
3032
3033 -- Copy record from main table to temp table
3034 IF (g_asn_debug = 'Y') THEN
3035 asn_debug.put_line('Copy record from main table to temp table');
3036 END IF;
3037
3038 current_n := 1;
3039 temp_cascaded_table(current_n) := x_cascaded_table(n);
3040
3041 IF (x_cascaded_table(n).shipment_header_id IS NOT NULL AND x_cascaded_table(n).shipment_line_id IS NOT NULL) THEN
3042 x_is_asn := TRUE;
3043 ELSE
3044 x_is_asn := FALSE;
3045 END IF;
3046
3047 -- Get all rows which meet this condition
3048 IF (g_asn_debug = 'Y') THEN
3049 asn_debug.put_line('Get all rows which meet this condition');
3050 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
3051 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
3052
3053 IF (x_is_asn = TRUE) THEN
3054 asn_debug.put_line('This is a Receive against an ASN');
3055 ELSE
3056 asn_debug.put_line('This is a Receive against a PO');
3057 END IF;
3058 END IF;
3059
3060 -- bug 1362237 Deriving the document_line_num
3061 -- and document_shipment_line_num when line_id and/or line_location_id
3062 -- are provided.
3063
3064 IF temp_cascaded_table(current_n).document_line_num IS NULL
3065 AND temp_cascaded_table(current_n).po_line_id IS NOT NULL THEN --{
3066 BEGIN
3067 SELECT line_num
3068 INTO temp_cascaded_table(current_n).document_line_num
3069 FROM po_lines
3070 WHERE po_line_id = temp_cascaded_table(current_n).po_line_id;
3071 EXCEPTION
3072 WHEN OTHERS THEN
3073 IF (g_asn_debug = 'Y') THEN
3074 asn_debug.put_line('wrong po_line_id entered in rcv_transactions_interface');
3075 END IF;
3076 END;
3077 END IF; --}
3078
3079 IF temp_cascaded_table(current_n).document_shipment_line_num IS NULL
3080 AND temp_cascaded_table(current_n).po_line_location_id IS NOT NULL THEN --{
3081 BEGIN
3082 SELECT shipment_num
3083 INTO temp_cascaded_table(current_n).document_shipment_line_num
3084 FROM po_line_locations
3085 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
3086 EXCEPTION
3087 WHEN OTHERS THEN
3088 IF (g_asn_debug = 'Y') THEN
3089 asn_debug.put_line('wrong po_line_location_id entered in rcv_transactions_interface');
3090 END IF;
3091 END;
3092 END IF; --}
3093
3094 IF temp_cascaded_table(current_n).document_distribution_num IS NULL
3095 AND temp_cascaded_table(current_n).po_distribution_id IS NOT NULL THEN --{
3096 BEGIN
3097 SELECT distribution_num
3098 INTO temp_cascaded_table(current_n).document_distribution_num
3099 FROM po_distributions
3100 WHERE po_distribution_id = temp_cascaded_table(current_n).po_distribution_id;
3101 EXCEPTION
3102 WHEN OTHERS THEN
3103 IF (g_asn_debug = 'Y') THEN
3104 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
3105 END IF;
3106 END;
3107 END IF; --}
3108
3109 /* Bug 1898283 : The Receiving control of "Enforce Ship to Location was
3110 not working for ROI. So corrected the code so that it now behaves the same way as
3111 the Form Behaves. i.e.,
3112 Proceed without any error messages if the enforcement is set to "None"
3113 Enter error message in po_interface_errors if the enforcement is "Warning"
3114 Enter error message in po_interface_errors if the enforcement is "Reject"
3115 and error out.
3116 This validation is done by comparing the enforce_ship_location_code from
3117 po_line_locations and assigning the proper ship_location_id into a
3118 temporary variable temp_mirror_ship_to_loc_id and passing the temp
3119 variable as a parameter to open the cursor "Distributions".
3120 */
3121 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3122 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3123
3124 -- if txn != deliver
3125 IF (g_asn_debug = 'Y') THEN
3126 asn_debug.put_line('Open Shipment records');
3127 asn_debug.put_line('Shipment Header Id if this is an ASN receive ' || TO_CHAR(temp_cascaded_table(current_n).shipment_header_id));
3128 asn_debug.put_line('PO Header id ' || TO_CHAR(temp_cascaded_table(current_n).po_header_id));
3129 asn_debug.put_line('Item Id ' || TO_CHAR(temp_cascaded_table(current_n).item_id));
3130 asn_debug.put_line('PO Line Num ' || TO_CHAR(temp_cascaded_table(current_n).document_line_num));
3131 asn_debug.put_line('PO Release Id ' || TO_CHAR(temp_cascaded_table(current_n).po_release_id));
3132 asn_debug.put_line('Shipment Line num ' || TO_CHAR(temp_cascaded_table(current_n).document_shipment_line_num));
3133 asn_debug.put_line('Document distribution num ' || TO_CHAR(temp_cascaded_table(current_n).document_distribution_num));
3134 asn_debug.put_line('Ship To Organization ID ' || TO_CHAR(temp_cascaded_table(current_n).to_organization_id));
3135 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)));
3136 asn_debug.put_line('Vendor Item Num ' || temp_cascaded_table(current_n).vendor_item_num);
3137 asn_debug.put_line('Proceed to open cursor');
3138 END IF;
3139
3140 /* Bug 2208664 : Nullified the ship_to_location_id when calling
3141 the cursors shipments, count_shipments, distributions and
3142 count_distributions. The proper value of ship_to_location_id will
3143 be set after values are fetched and validated for the
3144 location control code set at PO.
3145 */
3146 /* IF (x_is_asn = TRUE) THEN --{ */
3147 /* Forward port for Bug 4523892 , the use of x_is_asn is commented to make it consistent
3148 with the previous code line
3149 */
3150 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3151 IF (g_asn_debug = 'Y') THEN
3152 asn_debug.put_line('Open ASN Shipment records');
3153 asn_debug.put_line('shipment_header_id ' || temp_cascaded_table(current_n).shipment_header_id);
3154 asn_debug.put_line('shipment_line_id ' || temp_cascaded_table(current_n).shipment_line_id);
3155 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3156 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3157 asn_debug.put_line('document_num ' || temp_cascaded_table(current_n).document_line_num);
3158 asn_debug.put_line('document_shipment_line_num ' || temp_cascaded_table(current_n).document_shipment_line_num);
3159 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3160 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3161 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3162 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3163 END IF;
3164
3165 OPEN asn_shipments(temp_cascaded_table(current_n).shipment_header_id,
3166 temp_cascaded_table(current_n).shipment_line_id,
3167 temp_cascaded_table(current_n).po_header_id,
3168 temp_cascaded_table(current_n).item_id,
3169 temp_cascaded_table(current_n).document_line_num,
3170 temp_cascaded_table(current_n).document_shipment_line_num,
3171 temp_cascaded_table(current_n).po_release_id,
3172 temp_cascaded_table(current_n).to_organization_id,
3173 NULL, -- ship_to_location_id
3174 temp_cascaded_table(current_n).vendor_item_num,
3175 x_include_closed_po
3176 );
3177
3178 -- count_shipments just gets the count of rows found in shipments
3179 IF (g_asn_debug = 'Y') THEN
3180 asn_debug.put_line('After Open ASN Shipment records');
3181 END IF;
3182
3183 OPEN count_asn_shipments(temp_cascaded_table(current_n).shipment_header_id,
3184 temp_cascaded_table(current_n).shipment_line_id,
3185 temp_cascaded_table(current_n).po_header_id,
3186 temp_cascaded_table(current_n).item_id,
3187 temp_cascaded_table(current_n).document_line_num,
3188 temp_cascaded_table(current_n).document_shipment_line_num,
3189 temp_cascaded_table(current_n).po_release_id,
3190 temp_cascaded_table(current_n).to_organization_id,
3191 NULL, -- ship_to_location_id
3192 temp_cascaded_table(current_n).vendor_item_num,
3193 x_include_closed_po
3194 );
3195
3196 IF (g_asn_debug = 'Y') THEN
3197 asn_debug.put_line('After Open Count ASN Shipment records');
3198 END IF;
3199 ELSE --}{
3200 IF (g_asn_debug = 'Y') THEN
3201 asn_debug.put_line('Open PO Shipment records');
3202 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3203 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3204 asn_debug.put_line('document_line_num ' || temp_cascaded_table(current_n).document_line_num);
3205 asn_debug.put_line('line_location_id ' || temp_cascaded_table(current_n).po_line_location_id);
3206 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3207 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3208 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3209 END IF;
3210
3211 OPEN shipments(temp_cascaded_table(current_n).po_header_id,
3212 temp_cascaded_table(current_n).item_id,
3213 temp_cascaded_table(current_n).document_line_num,
3214 temp_cascaded_table(current_n).po_release_id,
3215 temp_cascaded_table(current_n).po_line_location_id,
3216 temp_cascaded_table(current_n).to_organization_id,
3217 NULL, -- ship_to_location_id
3218 temp_cascaded_table(current_n).vendor_item_num
3219 );
3220 -- count_shipments just gets the count of rows found in shipments
3221
3222 OPEN count_shipments(temp_cascaded_table(current_n).po_header_id,
3223 temp_cascaded_table(current_n).item_id,
3224 temp_cascaded_table(current_n).document_line_num,
3225 temp_cascaded_table(current_n).po_release_id,
3226 temp_cascaded_table(current_n).po_line_location_id,
3227 temp_cascaded_table(current_n).to_organization_id,
3228 NULL, -- ship_to_location_id
3229 temp_cascaded_table(current_n).vendor_item_num
3230 );
3231 END IF; --}
3232
3233 IF (g_asn_debug = 'Y') THEN
3234 asn_debug.put_line('After opening relavant records for Receive');
3235 END IF;
3236 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
3237 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --}{
3238 IF (g_asn_debug = 'Y') THEN
3239 asn_debug.put_line('Open Distribution records');
3240 asn_debug.put_line('Ship Header id ' || TO_CHAR(temp_cascaded_table(current_n).shipment_header_id));
3241 asn_debug.put_line('PO Header id ' || TO_CHAR(temp_cascaded_table(current_n).po_header_id));
3242 asn_debug.put_line('Item Id ' || TO_CHAR(temp_cascaded_table(current_n).item_id));
3243 asn_debug.put_line('PO Line Num ' || TO_CHAR(temp_cascaded_table(current_n).document_line_num));
3244 asn_debug.put_line('PO Release Id ' || TO_CHAR(temp_cascaded_table(current_n).po_release_id));
3245 asn_debug.put_line('Shipment Line num ' || TO_CHAR(temp_cascaded_table(current_n).document_shipment_line_num));
3246 asn_debug.put_line('Distribution num ' || TO_CHAR(temp_cascaded_table(current_n).document_distribution_num));
3247 asn_debug.put_line('Ship To Organization ID ' || TO_CHAR(temp_cascaded_table(current_n).to_organization_id));
3248 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)));
3249 asn_debug.put_line('Vendor Item Num ' || temp_cascaded_table(current_n).vendor_item_num);
3250 asn_debug.put_line('Proceed to open cursor');
3251 END IF;
3252
3253 /* IF (x_is_asn = TRUE) THEN --{ This call is replaced by forward port of 4523892 */
3254 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3255 IF (g_asn_debug = 'Y') THEN
3256 asn_debug.put_line('Open ASN Distribution records');
3257 asn_debug.put_line('shipment_header_id ' || temp_cascaded_table(current_n).shipment_header_id);
3258 asn_debug.put_line('shipment_line_id ' || temp_cascaded_table(current_n).shipment_line_id);
3259 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3260 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3261 asn_debug.put_line('document_num ' || temp_cascaded_table(current_n).document_line_num);
3262 asn_debug.put_line('document_shipment_line_num ' || temp_cascaded_table(current_n).document_shipment_line_num);
3263 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3264 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3265 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3266 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3267 END IF;
3268
3269 OPEN asn_distributions(temp_cascaded_table(current_n).shipment_header_id,
3270 temp_cascaded_table(current_n).shipment_line_id,
3271 temp_cascaded_table(current_n).po_header_id,
3272 temp_cascaded_table(current_n).item_id,
3273 temp_cascaded_table(current_n).document_line_num,
3274 temp_cascaded_table(current_n).document_shipment_line_num,
3275 temp_cascaded_table(current_n).document_distribution_num,
3276 temp_cascaded_table(current_n).po_release_id,
3277 temp_cascaded_table(current_n).to_organization_id,
3278 NULL, -- ship_to_location_id
3279 temp_cascaded_table(current_n).vendor_item_num,
3280 x_include_closed_po
3281 );
3282
3283 IF (g_asn_debug = 'Y') THEN
3284 asn_debug.put_line('After Open ASN distribution records');
3285 END IF;
3286
3287 OPEN count_asn_distributions(temp_cascaded_table(current_n).shipment_header_id,
3288 temp_cascaded_table(current_n).shipment_line_id,
3289 temp_cascaded_table(current_n).po_header_id,
3290 temp_cascaded_table(current_n).item_id,
3291 temp_cascaded_table(current_n).document_line_num,
3292 temp_cascaded_table(current_n).document_shipment_line_num,
3293 temp_cascaded_table(current_n).document_distribution_num,
3294 temp_cascaded_table(current_n).po_release_id,
3295 temp_cascaded_table(current_n).to_organization_id,
3296 NULL, -- ship_to_location_id
3297 temp_cascaded_table(current_n).vendor_item_num,
3298 x_include_closed_po
3299 );
3300
3301 IF (g_asn_debug = 'Y') THEN
3302 asn_debug.put_line('After Open count ASN distribution records');
3303 END IF;
3304 ELSE --}{
3305 IF (g_asn_debug = 'Y') THEN
3306 asn_debug.put_line('Open PO Distribution records');
3307 asn_debug.put_line('po_header_id ' || temp_cascaded_table(current_n).po_header_id);
3308 asn_debug.put_line('item_id ' || temp_cascaded_table(current_n).item_id);
3309 asn_debug.put_line('document_num ' || temp_cascaded_table(current_n).document_line_num);
3310 asn_debug.put_line('document_shipment_line_num ' || temp_cascaded_table(current_n).document_shipment_line_num);
3311 asn_debug.put_line('po_release_id ' || temp_cascaded_table(current_n).po_release_id);
3312 asn_debug.put_line('to_organization_id ' || temp_cascaded_table(current_n).to_organization_id);
3313 asn_debug.put_line('vendor_item_num ' || temp_cascaded_table(current_n).vendor_item_num);
3314 END IF;
3315
3316 OPEN distributions(temp_cascaded_table(current_n).po_header_id,
3317 temp_cascaded_table(current_n).item_id,
3318 temp_cascaded_table(current_n).document_line_num,
3319 temp_cascaded_table(current_n).po_release_id,
3320 temp_cascaded_table(current_n).document_shipment_line_num,
3321 temp_cascaded_table(current_n).document_distribution_num,
3322 temp_cascaded_table(current_n).to_organization_id,
3323 NULL, -- ship_to_location_id
3324 temp_cascaded_table(current_n).vendor_item_num
3325 );
3326 -- count_distributions just gets the count of rows found in distributions
3327
3328 OPEN count_distributions(temp_cascaded_table(current_n).po_header_id,
3329 temp_cascaded_table(current_n).item_id,
3330 temp_cascaded_table(current_n).document_line_num,
3331 temp_cascaded_table(current_n).po_release_id,
3332 temp_cascaded_table(current_n).document_shipment_line_num,
3333 temp_cascaded_table(current_n).document_distribution_num,
3334 temp_cascaded_table(current_n).to_organization_id,
3335 NULL, -- ship_to_location_id
3336 temp_cascaded_table(current_n).vendor_item_num
3337 );
3338 END IF; --}
3339
3340 IF (g_asn_debug = 'Y') THEN
3341 asn_debug.put_line('After opening relavant records for Direct delivery');
3342 END IF;
3343 END IF; -- for txn = deliver --}
3344
3345
3346 -- Assign shipped quantity to remaining quantity
3347
3348 IF (g_asn_debug = 'Y') THEN
3349 asn_debug.put_line('Assign shipped quantity to remaining quantity');
3350 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
3351 END IF;
3352
3353 x_remaining_quantity := temp_cascaded_table(current_n).quantity;
3354 x_bkp_qty := x_remaining_quantity; -- used for decrementing cum qty for first record
3355 x_remaining_qty_po_uom := 0;
3356
3357 IF (g_asn_debug = 'Y') THEN
3358 asn_debug.put_line('Have assigned the quantity');
3359 END IF;
3360
3361 -- Calculate tax_amount_factor for calculating tax_amount for
3362 -- each cascaded line
3363
3364 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
3365 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_quantity;
3366 ELSE
3367 tax_amount_factor := 0;
3368 END IF;
3369
3370 IF (g_asn_debug = 'Y') THEN
3371 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
3372 asn_debug.put_line('Shipped Quantity : ' || TO_CHAR(x_remaining_quantity));
3373 END IF;
3374
3375 x_first_trans := TRUE;
3376 transaction_ok := FALSE;
3377
3378 /*
3379 ** Get the count of the number of records depending on the
3380 ** the transaction type
3381 */
3382 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3383 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3384 /* IF (x_is_asn = TRUE) THEN --{ This is replaced by forward port for bug 4523892 */
3385 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3386 IF (g_asn_debug = 'Y') THEN
3387 asn_debug.put_line('Count of asn shipments');
3388 END IF;
3389
3390 FETCH count_asn_shipments INTO x_record_count;
3391 ELSE --}{
3392 IF (g_asn_debug = 'Y') THEN
3393 asn_debug.put_line('Count of PO shipments');
3394 END IF;
3395
3396 FETCH count_shipments INTO x_record_count;
3397 END IF; --}
3398 ELSE --}{
3399 /* IF (x_is_asn = TRUE) THEN --{ This is replaced by forward port for Bug 4523892 */
3400 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
3401 IF (g_asn_debug = 'Y') THEN
3402 asn_debug.put_line('Count of asn distributions');
3403 END IF;
3404
3405 FETCH count_asn_distributions INTO x_record_count;
3406 ELSE --}{
3407 IF (g_asn_debug = 'Y') THEN
3408 asn_debug.put_line('Count of PO distributions');
3409 END IF;
3410
3411 FETCH count_distributions INTO x_record_count;
3412 END IF; --}
3413 END IF; --}
3414
3415 IF (g_asn_debug = 'Y') THEN
3416 asn_debug.put_line('Before starting Cascade');
3417 END IF;
3418
3419 IF (g_asn_debug = 'Y') THEN
3420 asn_debug.put_line('Record Count = ' || x_record_count);
3421 END IF;
3422
3423 LOOP --{
3424 IF (g_asn_debug = 'Y') THEN
3425 asn_debug.put_line('Backup Qty ' || TO_CHAR(x_bkp_qty));
3426 asn_debug.put_line('Remaining Quantity ASN UOM ' || TO_CHAR(x_remaining_quantity));
3427 END IF;
3428
3429 IF (g_asn_debug = 'Y') THEN
3430 asn_debug.put_line('open shipments and fetch');
3431 END IF;
3432
3433 /*
3434 ** Fetch the appropriate record
3435 */
3436 IF (g_asn_debug = 'Y') THEN
3437 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
3438 END IF;
3439
3440 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3441 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3442 IF (g_asn_debug = 'Y') THEN
3443 asn_debug.put_line('Fetching Shipments Cursor');
3444 END IF;
3445
3446 IF (shipments%ISOPEN) THEN
3447 FETCH shipments INTO x_shipmentdistributionrec;
3448
3449 IF (shipments%NOTFOUND) THEN
3450 lastrecord := TRUE;
3451 END IF;
3452
3453 rows_fetched := shipments%ROWCOUNT;
3454 ELSIF(asn_shipments%ISOPEN) THEN
3455 FETCH asn_shipments INTO x_shipmentdistributionrec;
3456
3457 IF (asn_shipments%NOTFOUND) THEN
3458 lastrecord := TRUE;
3459 END IF;
3460
3461 rows_fetched := asn_shipments%ROWCOUNT;
3462 END IF;
3463
3464 /*
3465 ** Check if this is the last record
3466 */
3467 IF (g_asn_debug = 'Y') THEN
3468 asn_debug.put_line('Shipment Rows fetched ' || TO_CHAR(rows_fetched));
3469 END IF;
3470 -- }
3471 ELSE -- txn = deliver and other cases --{
3472 IF (g_asn_debug = 'Y') THEN
3473 asn_debug.put_line('Fetching Distributions Cursor');
3474 END IF;
3475
3476 IF (distributions%ISOPEN) THEN
3477 FETCH distributions INTO x_shipmentdistributionrec;
3478
3479 IF (distributions%NOTFOUND) THEN
3480 lastrecord := TRUE;
3481 END IF;
3482
3483 rows_fetched := distributions%ROWCOUNT;
3484 ELSIF(asn_distributions%ISOPEN) THEN
3485 FETCH asn_distributions INTO x_shipmentdistributionrec;
3486
3487 IF (asn_distributions%NOTFOUND) THEN
3488 lastrecord := TRUE;
3489 END IF;
3490
3491 rows_fetched := asn_distributions%ROWCOUNT;
3492 END IF;
3493
3494 /*
3495 ** Check if this is the last record
3496 */
3497 IF (g_asn_debug = 'Y') THEN
3498 asn_debug.put_line('Distribution Rows fetched ' || TO_CHAR(rows_fetched));
3499 END IF;
3500 END IF; -- matches if condition of txn ! deliver --}
3501
3502 IF ( lastrecord
3503 OR x_remaining_quantity <= 0) THEN --{
3504 IF (g_asn_debug = 'Y') THEN
3505 asn_debug.put_line('Hit exit condition');
3506 END IF;
3507
3508 IF NOT x_first_trans THEN
3509 -- x_first_trans has been reset which means some cascade has
3510 -- happened. Otherwise current_n = 1
3511 current_n := current_n - 1;
3512 END IF;
3513
3514 -- do the tolerance act here
3515 IF (g_asn_debug = 'Y') THEN
3516 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
3517 asn_debug.put_line('Check which condition has occured');
3518 END IF;
3519
3520 -- lastrecord...we have run out of rows and we still have quantity to allocate
3521 IF x_remaining_quantity > 0 THEN --{
3522 IF (g_asn_debug = 'Y') THEN
3523 asn_debug.put_line('There is quantity remaining');
3524 asn_debug.put_line('Need to check qty tolerances');
3525 END IF;
3526
3527 IF rows_fetched > 0
3528 AND NOT x_first_trans THEN --{
3529 -- we had got atleast some rows from our shipments cursor
3530 -- we have atleast one row cascaded (not null line_location_id)
3531 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
3532 INTO x_qty_rcv_exception_code
3533 FROM po_line_locations
3534 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
3535
3536 IF (g_asn_debug = 'Y') THEN
3537 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
3538 asn_debug.put_line('quantity ' || temp_cascaded_table(current_n).quantity);
3539 asn_debug.put_line('x_converted_trx_qty ' || x_converted_trx_qty);
3540 END IF;
3541
3542 -- Bug 6796920 Start
3543 BEGIN
3544 select blind_receiving_flag
3545 into l_blind_receiving_flag
3546 from rcv_parameters
3547 where organization_id = temp_cascaded_table(current_n).to_organization_id;
3548 EXCEPTION
3549 when others THEN
3550 NULL;
3551 END;
3552
3553 IF (g_asn_debug = 'Y') THEN
3554 asn_debug.put_line('Current Organization id = '|| temp_cascaded_table(current_n).to_organization_id);
3555 asn_debug.put_line('Blind Receiving Flag = '|| l_blind_receiving_flag);
3556 END IF;
3557 -- Bug 6796920 End
3558
3559 -- The following if condition is commented out as part of bug 6796920
3560 -- IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
3561 /* Bug# 1807842 */
3562 /* Bug 3506964.
3563 * This is the forward fix for 3222672. Before the
3564 * foll condition used to have <. We had changed
3565 * it to <= as part of our ROI rewrite. But since
3566 * quantity can never be greater than
3567 * x_converted_trx_qty, this is equivalent to removing
3568 * the whole condition. So commenting this out.
3569 IF (
3570 temp_cascaded_table(current_n).quantity <=
3571 x_converted_trx_qty
3572 ) THEN --{
3573 */
3574 IF (g_asn_debug = 'Y') THEN
3575 asn_debug.put_line('Tolerable quantity ' || TO_CHAR(x_converted_trx_qty));
3576 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
3577 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
3578 asn_debug.put_line('Assign remaining ASN UOM qty ' || TO_CHAR(x_remaining_quantity) || ' to last record');
3579 asn_debug.put_line('Assign remaining PO UOM qty ' || TO_CHAR(x_remaining_qty_po_uom) || ' to last record');
3580 END IF;
3581 /* Bug 4907269.
3582 x_remaining_quantity is the unused transaction qty, it has to be rounded to 6 decimals
3583 so that quantity and primary quantity will computed correctly rounded to 6 decimals.
3584 */
3585
3586 x_remaining_quantity := round(x_remaining_quantity,6);
3587
3588 temp_cascaded_table(current_n).quantity := temp_cascaded_table(current_n).quantity + x_remaining_quantity;
3589 temp_cascaded_table(current_n).quantity_shipped := temp_cascaded_table(current_n).quantity_shipped + x_remaining_quantity;
3590 temp_cascaded_table(current_n).source_doc_quantity := temp_cascaded_table(current_n).source_doc_quantity + x_remaining_qty_po_uom;
3591 temp_cascaded_table(current_n).primary_quantity := temp_cascaded_table(current_n).primary_quantity
3592 + rcv_transactions_interface_sv.convert_into_correct_qty(x_remaining_quantity,
3593 temp_cascaded_table(1).unit_of_measure,
3594 temp_cascaded_table(1).item_id,
3595 temp_cascaded_table(1).primary_unit_of_measure
3596 );
3597
3598 IF (g_asn_debug = 'Y') THEN
3599 asn_debug.put_line('primary_qty for the last row ' || temp_cascaded_table(current_n).primary_quantity);
3600 asn_debug.put_line('quantity for the last row ' || temp_cascaded_table(current_n).quantity);
3601 END IF;
3602
3603 /* Bug 3506964.
3604 END IF; Bug# 1807842 --}
3605 */
3606
3607 -- Vendor Cum Qty
3608
3609 IF NVL(temp_cascaded_table(current_n).vendor_cum_shipped_qty, 0) <> 0 THEN
3610 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;
3611 END IF;
3612
3613 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).quantity * tax_amount_factor, 6);
3614
3615 IF (g_asn_debug = 'Y') THEN
3616 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
3617 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
3618 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
3619 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
3620 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
3621 END IF;
3622
3623 -- Bug 6796920 - Modified the following if condition to check for blind receiving flag
3624 IF (x_qty_rcv_exception_code = 'WARNING' AND NVL(l_blind_receiving_flag,'N') <> 'Y') THEN --{
3625 IF (g_asn_debug = 'Y') THEN
3626 asn_debug.put_line('IN WARNING');
3627 END IF;
3628
3629 IF (g_asn_debug = 'Y') THEN
3630 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
3631 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
3632 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
3633 END IF;
3634
3635 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
3636 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
3637 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
3638 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
3639 rcv_error_pkg.log_interface_warning('QUANTITY');
3640
3641 IF (g_asn_debug = 'Y') THEN
3642 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
3643 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
3644 asn_debug.put_line('Need to insert into po_interface_errors');
3645 END IF;
3646 -- Commented out the following END IF as part of bug 6796920
3647 -- END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
3648
3649 IF (g_asn_debug = 'Y') THEN
3650 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
3651 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
3652 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
3653 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
3654 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
3655 END IF;
3656 -- }
3657 -- ELSIF x_qty_rcv_exception_code = 'REJECT' THEN -- elseif for NONE/WARNING --{
3658 -- Bug 6796920 - Modified the following elsif condition to check for blind receiving flag
3659 ELSIF (x_qty_rcv_exception_code = 'REJECT' AND NVL(l_blind_receiving_flag,'N') <> 'Y') THEN
3660 IF (g_asn_debug = 'Y') THEN
3661 asn_debug.put_line('Extra ASN UOM Quantity ' || TO_CHAR(x_remaining_quantity));
3662 asn_debug.put_line('Extra PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
3663 END IF;
3664
3665 IF (g_asn_debug = 'Y') THEN
3666 asn_debug.put_line('delete the temp table ');
3667 END IF;
3668
3669 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3670 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
3671 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(n).quantity);
3672 rcv_error_pkg.set_token('QTY_B', x_cascaded_table(n).quantity - x_remaining_quantity);
3673 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
3674
3675 IF temp_cascaded_table.COUNT > 0 THEN
3676 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
3677 temp_cascaded_table.DELETE(i);
3678 END LOOP;
3679 END IF;
3680
3681 IF (g_asn_debug = 'Y') THEN
3682 asn_debug.put_line('mark the actual table with error status');
3683 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
3684 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
3685 END IF;
3686
3687 IF (g_asn_debug = 'Y') THEN
3688 asn_debug.put_line('Need to insert a row into po_interface_errors');
3689 END IF;
3690 END IF; --} matches if(none/warning) and elseif(reject)
3691 --}
3692 ELSE --{ else for rows fetched = 0 OR x_first_trans = true
3693 IF rows_fetched = 0 THEN
3694 IF (g_asn_debug = 'Y') THEN
3695 asn_debug.put_line('No rows were retrieved from cursor.');
3696 END IF;
3697 ELSIF x_first_trans THEN
3698 IF (g_asn_debug = 'Y') THEN
3699 asn_debug.put_line('No rows were cascaded');
3700 END IF;
3701 END IF;
3702
3703 x_temp_count := 1;
3704
3705 /* nwang add error messages */
3706 /* Bug 2340533 - Added a message RCV_ASN_NO_OPEN_SHIPMENTS which conveys that
3707 no shipments exists for receiving for the given PO.
3708 */
3709 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
3710 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
3711 -- Bug 2551443 Removed po_distributions from the FROM clause
3712 IF (g_asn_debug = 'Y') THEN
3713 asn_debug.put_line('This is receive');
3714 END IF;
3715
3716 IF (x_is_asn = FALSE) THEN --{
3717 SELECT COUNT(*)
3718 INTO x_temp_count
3719 FROM po_line_locations pll,
3720 po_lines pl,
3721 po_headers ph
3722 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
3723 AND pll.po_header_id = ph.po_header_id
3724 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
3725 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
3726 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
3727 AND pll.po_line_id = pl.po_line_id;
3728 END IF; --}
3729
3730 IF (g_asn_debug = 'Y') THEN
3731 asn_debug.put_line('x_temp_count ' || x_temp_count);
3732 END IF;
3733
3734 IF x_temp_count = 0 THEN --{
3735 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3736 rcv_error_pkg.set_error_message('RCV_ASN_NO_OPEN_SHIPMENTS', x_cascaded_table(n).error_message);
3737 rcv_error_pkg.set_token('PONUM', temp_cascaded_table(current_n).document_num);
3738 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
3739 ELSE -- x_item_count != 0 --}{
3740 IF (x_is_asn = FALSE) THEN --{
3741 IF (g_asn_debug = 'Y') THEN
3742 asn_debug.put_line('Get the flag values');
3743 END IF;
3744
3745 SELECT NVL(pl.item_id, 0),
3746 NVL(pll.approved_flag, 'N'),
3747 NVL(pll.cancel_flag, 'N'),
3748 NVL(pll.closed_code, 'OPEN'),
3749 pll.shipment_type,
3750 pll.ship_to_organization_id,
3751 pll.ship_to_location_id,
3752 NVL(pl.vendor_product_num, '-999')
3753 INTO x_item_id,
3754 x_approved_flag,
3755 x_cancel_flag,
3756 x_closed_code,
3757 x_shipment_type,
3758 x_ship_to_organization_id,
3759 x_ship_to_location_id,
3760 x_vendor_product_num
3761 FROM po_line_locations pll,
3762 po_lines pl,
3763 po_headers ph
3764 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
3765 AND pll.po_header_id = ph.po_header_id
3766 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
3767 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
3768 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
3769 AND pll.po_line_id = pl.po_line_id;
3770
3771 IF (g_asn_debug = 'Y') THEN
3772 asn_debug.put_line('x_item_id ' || x_item_id);
3773 asn_debug.put_line('x_approved_flag ' || x_approved_flag);
3774 asn_debug.put_line('x_cancel_flag ' || x_cancel_flag);
3775 asn_debug.put_line('x_closed_code ' || x_closed_code);
3776 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3777 asn_debug.put_line('x_shipment_type ' || x_shipment_type);
3778 asn_debug.put_line('x_ship_to_organization_id ' || x_ship_to_organization_id);
3779 asn_debug.put_line('x_ship_to_location_id ' || x_ship_to_location_id);
3780 asn_debug.put_line('x_vendor_product_num ' || x_vendor_product_num);
3781 END IF;
3782 END IF; --}
3783 END IF; --} -- x_temp_count = 0
3784 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
3785 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --}{
3786 IF (g_asn_debug = 'Y') THEN
3787 asn_debug.put_line('This is deliver');
3788 END IF;
3789
3790 IF (x_is_asn = FALSE) THEN --{
3791 SELECT COUNT(*)
3792 INTO x_temp_count
3793 FROM po_distributions pod,
3794 po_line_locations pll,
3795 po_lines pl,
3796 po_headers ph
3797 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
3798 AND pll.po_header_id = ph.po_header_id
3799 AND pll.line_location_id = pod.line_location_id
3800 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
3801 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
3802 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
3803 AND pll.po_line_id = pl.po_line_id
3804 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
3805 END IF; --}
3806
3807 IF (g_asn_debug = 'Y') THEN
3808 asn_debug.put_line('x_temp_count ' || x_temp_count);
3809 END IF;
3810
3811 IF x_temp_count = 0 THEN --{
3812 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3813 rcv_error_pkg.set_error_message('RCV_ASN_INVALID_DIST_NUM', x_cascaded_table(n).error_message);
3814 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_distribution_num);
3815 rcv_error_pkg.log_interface_error('DOCUMENT_DISTRIBUTION_NUM', FALSE);
3816 ELSE -- x_temp_count != 0 --}{
3817 IF (x_is_asn = FALSE) THEN --{
3818 IF (g_asn_debug = 'Y') THEN
3819 asn_debug.put_line('Get flag values ');
3820 END IF;
3821
3822 SELECT NVL(pl.item_id, 0),
3823 NVL(pll.approved_flag, 'N'),
3824 NVL(pll.cancel_flag, 'N'),
3825 NVL(pll.closed_code, 'OPEN'),
3826 pll.shipment_type,
3827 pll.ship_to_organization_id,
3828 pll.ship_to_location_id,
3829 NVL(pl.vendor_product_num, '-999')
3830 INTO x_item_id,
3831 x_approved_flag,
3832 x_cancel_flag,
3833 x_closed_code,
3834 x_shipment_type,
3835 x_ship_to_organization_id,
3836 x_ship_to_location_id,
3837 x_vendor_product_num
3838 FROM po_distributions pod,
3839 po_line_locations pll,
3840 po_lines pl,
3841 po_headers ph
3842 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
3843 AND pll.po_header_id = ph.po_header_id
3844 AND pll.line_location_id = pod.line_location_id
3845 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
3846 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
3847 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
3848 AND pll.po_line_id = pl.po_line_id
3849 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
3850
3851 IF (g_asn_debug = 'Y') THEN
3852 asn_debug.put_line('x_item_id ' || x_item_id);
3853 asn_debug.put_line('x_approved_flag ' || x_approved_flag);
3854 asn_debug.put_line('x_cancel_flag ' || x_cancel_flag);
3855 asn_debug.put_line('x_closed_code ' || x_closed_code);
3856 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3857 asn_debug.put_line('x_shipment_type ' || x_shipment_type);
3858 asn_debug.put_line('x_ship_to_organization_id ' || x_ship_to_organization_id);
3859 asn_debug.put_line('x_ship_to_location_id ' || x_ship_to_location_id);
3860 asn_debug.put_line('x_vendor_product_num ' || x_vendor_product_num);
3861 END IF;
3862 END IF; --}
3863 END IF; -- x_temp_count = 0; --}
3864 END IF; -- transaction_type <> 'DELIVER' --}
3865
3866 IF (x_is_asn = TRUE) THEN --{
3867 IF (g_asn_debug = 'Y') THEN
3868 asn_debug.put_line('Shipment header_id not null ');
3869 END IF;
3870
3871 SELECT NVL(rsl.item_id, 0),
3872 NVL(pll.approved_flag, 'N'),
3873 NVL(pll.cancel_flag, 'N'),
3874 NVL(pll.closed_code, 'OPEN'),
3875 pll.shipment_type,
3876 rsl.to_organization_id,
3877 rsl.ship_to_location_id,
3878 NVL(pl.vendor_product_num, '-999'),
3879 rsh.receipt_source_code,
3880 rsl.shipment_line_status_code,
3881 NVL(rsl.asn_line_flag, 'N')
3882 INTO x_item_id,
3883 x_approved_flag,
3884 x_cancel_flag,
3885 x_closed_code,
3886 x_shipment_type,
3887 x_ship_to_organization_id,
3888 x_ship_to_location_id,
3889 x_vendor_product_num,
3890 l_receipt_source_code,
3891 l_shipment_line_status_code,
3892 l_asn_line_flag
3893 FROM po_line_locations pll,
3894 po_lines pl,
3895 po_headers ph,
3896 rcv_shipment_headers rsh,
3897 rcv_shipment_lines rsl
3898 WHERE rsh.shipment_header_id = temp_cascaded_table(current_n).shipment_header_id
3899 AND rsl.shipment_line_id = temp_cascaded_table(current_n).shipment_line_id
3900 AND rsl.po_header_id = temp_cascaded_table(current_n).po_header_id
3901 AND rsl.po_line_id = temp_cascaded_table(current_n).po_line_id
3902 AND rsl.po_line_location_id = temp_cascaded_table(current_n).po_line_location_id
3903 AND rsl.po_line_id = pl.po_line_id
3904 AND rsl.po_line_location_id = pll.line_location_id
3905 AND ph.po_header_id = rsl.po_header_id
3906 AND rsh.shipment_header_id = rsl.shipment_header_id
3907 AND pll.po_header_id = ph.po_header_id
3908 AND pl.po_line_id = temp_cascaded_table(current_n).po_line_id
3909 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id,0)
3910 AND pll.line_location_id = temp_cascaded_table(current_n).po_line_location_id
3911 AND pll.po_line_id = pl.po_line_id;
3912
3913 IF (g_asn_debug = 'Y') THEN
3914 asn_debug.put_line('x_item_id ' || x_item_id);
3915 asn_debug.put_line('x_approved_flag ' || x_approved_flag);
3916 asn_debug.put_line('x_cancel_flag ' || x_cancel_flag);
3917 asn_debug.put_line('x_closed_code ' || x_closed_code);
3918 asn_debug.put_line('x_include_closed_po ' || x_include_closed_po);
3919 asn_debug.put_line('x_shipment_type ' || x_shipment_type);
3920 asn_debug.put_line('x_ship_to_organization_id ' || x_ship_to_organization_id);
3921 asn_debug.put_line('x_ship_to_location_id ' || x_ship_to_location_id);
3922 asn_debug.put_line('x_vendor_product_num ' || x_vendor_product_num);
3923 asn_debug.put_line('l_receipt_source_code ' || l_receipt_source_code);
3924 asn_debug.put_line('l_shipment_line_status_code ' || l_shipment_line_status_code);
3925 asn_debug.put_line('l_asn_line_flag ' || l_asn_line_flag);
3926 END IF;
3927 END IF; --}
3928
3929 IF (x_temp_count <> 0) THEN --{
3930 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3931
3932 IF (g_asn_debug = 'Y') THEN
3933 asn_debug.put_line('Should give us the exact error ');
3934 END IF;
3935
3936 IF x_item_id <> NVL(temp_cascaded_table(current_n).item_id, x_item_id) THEN
3937 IF (g_asn_debug = 'Y') THEN
3938 asn_debug.put_line('This item is not allowed ');
3939 END IF;
3940
3941 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3942 rcv_error_pkg.set_error_message('RCV_ASN_ITEM_NOT_ALLOWED', x_cascaded_table(n).error_message);
3943 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).item_num);
3944 rcv_error_pkg.log_interface_error('ITEM_NUM', FALSE);
3945 END IF;
3946
3947 IF x_approved_flag <> 'Y' THEN
3948 IF (g_asn_debug = 'Y') THEN
3949 asn_debug.put_line('This PO is not approved');
3950 END IF;
3951
3952 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3953 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_APPROVED', x_cascaded_table(n).error_message);
3954 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
3955 rcv_error_pkg.set_token('PO_NUM', temp_cascaded_table(current_n).document_num);
3956 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
3957 END IF;
3958
3959 IF x_cancel_flag <> 'N' THEN
3960 IF (g_asn_debug = 'Y') THEN
3961 asn_debug.put_line('This PO is cancelled');
3962 END IF;
3963
3964 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3965 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_CANCELLED', x_cascaded_table(n).error_message);
3966 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
3967 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
3968 END IF;
3969
3970 /* Bug 3548556.
3971 * We used to record the error only when it
3972 * is finally closed. But this is an error only
3973 * the include closed PO option is Yes. If it is
3974 * Yes, then we need to error out when closed_code
3975 * is FINALLY CLOSED, CLOSED FOR RECEIVING OR
3976 * CLOSED. So changed the foll code to include
3977 * the condition x_include_closed_po and
3978 * added the if condition below to look for
3979 * the other closed codes when include closed
3980 * po profile option is set to No.
3981 */
3982 IF ( NVL(x_include_closed_po, 'N') = 'Y'
3983 AND x_closed_code = 'FINALLY CLOSED') THEN
3984 IF (g_asn_debug = 'Y') THEN
3985 asn_debug.put_line('This PO is finally closed and the profile option to include closed POs is Y');
3986 END IF;
3987
3988 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
3989 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_CANCELLED', x_cascaded_table(n).error_message);
3990 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
3991 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
3992 END IF;
3993
3994 IF ( NVL(x_include_closed_po, 'N') = 'N'
3995 AND x_closed_code IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING')) THEN
3996 IF (g_asn_debug = 'Y') THEN
3997 asn_debug.put_line('This PO is not open and the profile option to include closed POs is N');
3998 END IF;
3999
4000 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4001 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_OPEN', x_cascaded_table(n).error_message);
4002 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4003 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4004 END IF;
4005
4006 IF x_shipment_type NOT IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT') THEN
4007 IF (g_asn_debug = 'Y') THEN
4008 asn_debug.put_line('This PO shipment type cannot be received');
4009 END IF;
4010
4011 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4012 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIPMT_TYPE', x_cascaded_table(n).error_message);
4013 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
4014 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
4015 END IF;
4016
4017 IF x_ship_to_organization_id <> NVL(temp_cascaded_table(current_n).to_organization_id, x_ship_to_organization_id) THEN
4018 IF (g_asn_debug = 'Y') THEN
4019 asn_debug.put_line('Ship_to_org in PO does not match the user entered value');
4020 END IF;
4021
4022 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4023 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_ORG', x_cascaded_table(n).error_message);
4024 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).to_organization_code);
4025 rcv_error_pkg.log_interface_error('TO_ORGANIZATION_CODE', FALSE);
4026 END IF;
4027
4028 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
4029 IF (g_asn_debug = 'Y') THEN
4030 asn_debug.put_line('Ship_to_loc in PO does not match the user entered value');
4031 END IF;
4032
4033 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4034 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
4035 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_code);
4036 rcv_error_pkg.log_interface_error('SHIP_TO_LOCATION_CODE', FALSE);
4037 END IF;
4038
4039 IF x_vendor_product_num <> NVL(temp_cascaded_table(current_n).vendor_item_num, x_vendor_product_num) THEN
4040 IF (g_asn_debug = 'Y') THEN
4041 asn_debug.put_line('Vendor_prod_num in PO does not match the user entered value');
4042 END IF;
4043
4044 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4045 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_VENDOR_PROD_NUM', x_cascaded_table(n).error_message);
4046 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).vendor_item_num);
4047 rcv_error_pkg.log_interface_error('VENDOR_ITEM_NUM', FALSE);
4048 END IF;
4049
4050 IF (g_asn_debug = 'Y') THEN
4051 asn_debug.put_line('Should have give us the exact error ');
4052 END IF;
4053
4054 /* IF (x_is_asn = TRUE) THEN --{ This is replaced by forward port for Bug 4523892 */
4055 IF (rcv_roi_header.g_txn_against_asn = 'Y') THEN --{ Bug#4523892
4056 /* Error messages specific to asns. */
4057 IF (g_asn_debug = 'Y') THEN
4058 asn_debug.put_line('Error messages specific to asn');
4059 END IF;
4060
4061 IF l_receipt_source_code <> 'VENDOR' THEN
4062 IF (g_asn_debug = 'Y') THEN
4063 asn_debug.put_line('Receipt source code not VENDOR');
4064 END IF;
4065
4066 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4067 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_RECEIPT_SOURCE_CODE', x_cascaded_table(n).error_message);
4068 rcv_error_pkg.log_interface_error('SHIPMENT_NUMBER', FALSE);
4069 END IF;
4070
4071 IF ( l_shipment_line_status_code = 'FULLY RECEIVED'
4072 OR l_asn_line_flag <> 'Y') THEN
4073 IF (g_asn_debug = 'Y') THEN
4074 asn_debug.put_line('ASN line flag is not Y and status code is Fully closed');
4075 END IF;
4076
4077 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4078 rcv_error_pkg.set_error_message('RCV_ASN_NO_EXPECTED_RECEIPTS', x_cascaded_table(n).error_message);
4079 rcv_error_pkg.log_interface_error('SHIPMENT_NUMBER', FALSE);
4080 END IF;
4081
4082 IF (g_asn_debug = 'Y') THEN
4083 asn_debug.put_line('Should have give us the exact error for ASN ');
4084 END IF;
4085 END IF; --}
4086 END IF; -- x_temp_count = 0;}
4087
4088 -- Delete the temp_cascaded_table just to be sure
4089
4090 IF temp_cascaded_table.COUNT > 0 THEN
4091 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
4092 temp_cascaded_table.DELETE(i);
4093 END LOOP;
4094 END IF;
4095 END IF; --} end else for rows fetched = 0 OR x_first_trans = true
4096 -- end x_remaining_qty > 0 => this is the last record
4097 ELSE --
4098 IF (g_asn_debug = 'Y') THEN
4099 asn_debug.put_line('Remaining ASN UOM quantity is zero ' || TO_CHAR(x_remaining_quantity));
4100 asn_debug.put_line('Remaining PO UOM quantity is zero ' || TO_CHAR(x_remaining_qty_po_uom));
4101 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
4102 END IF;
4103 END IF; --} ends the check for whether last record has been reached
4104
4105 -- close cursors
4106
4107 IF (g_asn_debug = 'Y') THEN
4108 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions');
4109 END IF;
4110
4111 IF shipments%ISOPEN THEN
4112 CLOSE shipments;
4113 END IF;
4114
4115 IF count_shipments%ISOPEN THEN
4116 CLOSE count_shipments;
4117 END IF;
4118
4119 IF distributions%ISOPEN THEN
4120 CLOSE distributions;
4121 END IF;
4122
4123 IF count_distributions%ISOPEN THEN
4124 CLOSE count_distributions;
4125 END IF;
4126
4127 IF asn_shipments%ISOPEN THEN
4128 CLOSE asn_shipments;
4129 END IF;
4130
4131 IF count_asn_shipments%ISOPEN THEN
4132 CLOSE count_asn_shipments;
4133 END IF;
4134
4135 IF asn_distributions%ISOPEN THEN
4136 CLOSE asn_distributions;
4137 END IF;
4138
4139 IF count_asn_distributions%ISOPEN THEN
4140 CLOSE count_asn_distributions;
4141 END IF;
4142
4143 EXIT;
4144 END IF; --} matches lastrecord or x_remaining_quantity <= 0
4145
4146 -- eliminate the row if it fails the date check
4147
4148 IF (g_asn_debug = 'Y') THEN
4149 asn_debug.put_line('Count in temp_cascade_table : ' || TO_CHAR(temp_cascaded_table.COUNT));
4150 asn_debug.put_line('Cursor record ' || TO_CHAR(rows_fetched));
4151 asn_debug.put_line('Check date tolerance');
4152 END IF;
4153
4154 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
4155 x_shipmentdistributionrec.promised_date,
4156 x_shipmentdistributionrec.days_early_receipt_allowed,
4157 x_shipmentdistributionrec.days_late_receipt_allowed,
4158 x_shipmentdistributionrec.receipt_days_exception_code
4159 );
4160
4161 /* Bug 3296214.
4162 * We need to use the control actions set in the Receiving
4163 * Options window. Get the control code from rcv_parameters.
4164 * If the transaction type is RECEIVE and if there is an
4165 * ASN existing for that PO, then depending on this value
4166 * we should either allow or error out.
4167 */
4168 BEGIN
4169 SELECT NVL(MAX(receipt_asn_exists_code), 'NONE')
4170 INTO l_asn_exists_code
4171 FROM rcv_parameters
4172 WHERE organization_id = x_cascaded_table(n).to_organization_id;
4173 EXCEPTION
4174 WHEN OTHERS THEN
4175 l_asn_exists_code := 'NONE';
4176 END;
4177
4178 IF (g_asn_debug = 'Y') THEN
4179 asn_debug.put_line('ASN CODE IN rcv_parameters ' || l_asn_exists_code);
4180 END IF;
4181
4182 /* This check is not done for receiving against ASNs. So check
4183 * whether x_cascaded_table(n).shipment_header_id is null which
4184 * will be for the case of a receipt against a PO shipment.
4185 */
4186 IF ( (x_cascaded_table(n).transaction_type = 'RECEIVE')
4187 AND l_asn_exists_code IN('WARNING', 'REJECT')
4188 AND (rcv_roi_header.g_txn_against_asn = 'N')) THEN --{ Bug#4523892
4189 /* AND (x_is_asn = FALSE)) THEN --{ This is replaced by forward port for 4523892 */
4190 IF (g_asn_debug = 'Y') THEN
4191 asn_debug.put_line('ASN CODE IN Warning or Reject ');
4192 END IF;
4193
4194 /* Bug 4287932 In case of ASBN the ASN control action was
4195 * not getting applied. Added ASBN in the asn_type in
4196 * select below.
4197 */
4198
4199 SELECT COUNT(*)
4200 INTO l_asn_count
4201 FROM rcv_shipment_headers rsh,
4202 rcv_shipment_lines rsl
4203 WHERE rsh.shipment_header_id = rsl.shipment_header_id
4204 AND NVL(rsh.asn_type, 'STD') IN ('ASN','ASBN') --4287932
4205 AND NVL(rsl.shipment_line_status_code, 'EXPECTED') NOT IN('CANCELLED', 'FULLY RECEIVED')
4206 AND rsl.po_line_location_id = x_shipmentdistributionrec.line_location_id;
4207
4208 IF (g_asn_debug = 'Y') THEN
4209 asn_debug.put_line('l_asn_count ' || l_asn_count);
4210 END IF;
4211
4212 IF (l_asn_count <> 0) THEN --{
4213 IF (l_asn_exists_code = 'WARNING') THEN --{
4214 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
4215 rcv_error_pkg.set_error_message('RCV_ASN_EXISTS_FOR_POLINE', x_cascaded_table(n).error_message);
4216 rcv_error_pkg.log_interface_warning('DOCUMENT_NUM');
4217
4218 IF (g_asn_debug = 'Y') THEN
4219 asn_debug.put_line('AFter Warning insert into po_interface_errors ' || x_cascaded_table(n).error_message);
4220 END IF;
4221 END IF; --}
4222
4223 IF (l_asn_exists_code = 'REJECT') THEN --{
4224 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4225 rcv_error_pkg.set_error_message('RCV_ASN_EXISTS_FOR_POLINE', x_cascaded_table(n).error_message);
4226 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_num);
4227 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
4228
4229 IF (g_asn_debug = 'Y') THEN
4230 asn_debug.put_line('AFter Reject insert into po_interface_errors ' || x_cascaded_table(n).error_message);
4231 END IF;
4232 END IF; --}
4233 ELSE --}{
4234 /* This is a receipt against a PO but there is no ASN.
4235 */
4236 l_asn_exists_code := 'NONE';
4237 END IF; --}
4238 ELSE --}{
4239 /* This is an ASN transaction or receipt against an ASN or
4240 * else the asn code is NONE */
4241 l_asn_exists_code := 'NONE';
4242 END IF; --}
4243
4244 IF (l_asn_exists_code IN('NONE', 'WARNING')) THEN --{
4245 /* bug 1060261 - added error message to be shown when the expected date is outside tolerance range */
4246 IF (x_shipmentdistributionrec.receipt_days_exception_code = 'REJECT') THEN --{
4247 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4248 rcv_error_pkg.set_error_message('RCV_ASN_DATE_OUT_TOL', x_cascaded_table(n).error_message);
4249 rcv_error_pkg.set_token('DELIVERY DATE', NVL(temp_cascaded_table(1).expected_receipt_date, x_header_record.header_record.expected_receipt_date));
4250 rcv_error_pkg.log_interface_error('EXPECTED_RECEIPT_DATE', FALSE);
4251 END IF; --}
4252
4253 IF (g_asn_debug = 'Y') THEN
4254 asn_debug.put_line('Days exception Code ' || NVL(x_shipmentdistributionrec.receipt_days_exception_code, 'XXX'));
4255 END IF;
4256
4257 -- Check shipto_location enforcement
4258
4259 rcv_transactions_interface_sv.check_shipto_enforcement(x_shipmentdistributionrec.ship_to_location_id,
4260 NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id),
4261 x_shipmentdistributionrec.enforce_ship_to_location_code
4262 );
4263
4264 IF (g_asn_debug = 'Y') THEN
4265 asn_debug.put_line('Enforce ShipToLocation ' || NVL(x_shipmentdistributionrec.enforce_ship_to_location_code, 'XXX'));
4266 END IF;
4267
4268 /* Bug 2208664 : Enter error message in po_interface_errors if enforce_ship_to_location_code is 'WARNING', and
4269 Enter error message in po_interface_errors if enforce_ship_to_location_code is 'REJECT' and error out
4270 */
4271 IF (x_shipmentdistributionrec.enforce_ship_to_location_code = 'REJECT') THEN --{
4272 BEGIN
4273 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4274 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
4275 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
4276 rcv_error_pkg.log_interface_error('SHIP_TO_LOCATION_ID', FALSE);
4277 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
4278 END;
4279 ELSIF(x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING') THEN --} {
4280 BEGIN
4281 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
4282 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
4283 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
4284 rcv_error_pkg.log_interface_warning('SHIP_TO_LOCATION_ID');
4285 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
4286 END;
4287 END IF; --}matches ship_to_loc_code = warning
4288 END IF; --} matches l_asn_exists_code = NONE
4289
4290 IF (x_shipmentdistributionrec.receipt_days_exception_code = 'NONE')
4291 AND -- derived by the date tolerance procedure
4292 (x_shipmentdistributionrec.enforce_ship_to_location_code IN('NONE', 'WARNING'))
4293 AND (l_asn_exists_code IN('NONE', 'WARNING')) THEN --{
4294 -- derived by shipto_enforcement
4295 -- Changes to accept Vendor_Item_num without ITEM_ID/NUM
4296 -- Item_id could be null if the ASN has the vendor_item_num provided
4297 -- We need to put a value into item_id based on the cursor
4298 -- We need to also figure out the primary unit for the item_id
4299 -- We will do it for the first record only. Subsequent records in the
4300 -- temp_table are copies of the previous one
4301 -- Assuming that vendor_item_num refers to a single item. If the items
4302 -- could be different then we need to move this somewhere below
4303 IF (x_first_trans)
4304 AND temp_cascaded_table(current_n).item_id IS NULL THEN --{
4305 temp_cascaded_table(current_n).item_id := x_shipmentdistributionrec.item_id;
4306
4307 IF (g_asn_debug = 'Y') THEN
4308 asn_debug.put_line('Cursor Item Id is ' || TO_CHAR(temp_cascaded_table(current_n).item_id));
4309 END IF;
4310
4311 -- Bug 4881909 : For one-time items item_id would be null. Added check
4312 -- for item_id in the following IF statement
4313 IF x_cascaded_table(n).primary_unit_of_measure IS NULL
4314 AND temp_cascaded_table(current_n).item_id IS NOT NULL THEN --{
4315 BEGIN
4316 SELECT primary_unit_of_measure
4317 INTO temp_cascaded_table(current_n).primary_unit_of_measure
4318 FROM mtl_system_items
4319 WHERE mtl_system_items.inventory_item_id = temp_cascaded_table(current_n).item_id
4320 AND mtl_system_items.organization_id = temp_cascaded_table(current_n).to_organization_id;
4321
4322 IF (g_asn_debug = 'Y') THEN
4323 asn_debug.put_line('Primary UOM: ' || temp_cascaded_table(current_n).primary_unit_of_measure);
4324 END IF;
4325 EXCEPTION
4326 WHEN NO_DATA_FOUND THEN
4327 temp_cascaded_table(current_n).error_status := rcv_error_pkg.g_ret_sts_warning;
4328 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY', temp_cascaded_table(current_n).error_message);
4329 rcv_error_pkg.set_token('PRIMARY_UNIT', '');
4330 rcv_error_pkg.set_token('SHIPMENT_UNIT', '');
4331 rcv_error_pkg.log_interface_warning('ITEM_ID');
4332
4333 IF (g_asn_debug = 'Y') THEN
4334 asn_debug.put_line('Primary UOM error');
4335 END IF;
4336 END;
4337 END IF; --}
4338 END IF; --}
4339
4340 insert_into_table := FALSE;
4341 already_allocated_qty := 0;
4342
4343 /*
4344 ** Get the available quantity for the shipment or distribution
4345 ** that is available for allocation by this interface transaction
4346 */
4347 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
4348 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
4349 NULL;
4350
4351 /*Bug# 1548597 */
4352 /* IF (x_is_asn = FALSE) THEN --{ Replaced by forward port 4523892 */
4353 IF (rcv_roi_header.g_txn_against_asn = 'N') THEN --{ Bug#4523892
4354 IF (g_asn_debug = 'Y') THEN
4355 asn_debug.put_line('Receiving against a Po');
4356 END IF;
4357
4358 rcv_quantities_s.get_available_quantity('RECEIVE',
4359 x_shipmentdistributionrec.line_location_id,
4360 'VENDOR',
4361 NULL,
4362 NULL,
4363 NULL,
4364 x_converted_trx_qty,
4365 x_tolerable_qty,
4366 x_shipmentdistributionrec.unit_meas_lookup_code,
4367 x_secondary_available_qty
4368 );
4369 ELSE --}{
4370 IF (g_asn_debug = 'Y') THEN
4371 asn_debug.put_line('Receiving an ASN');
4372 END IF;
4373
4374 rcv_quantities_s.get_available_asn_quantity('RECEIVE',
4375 x_shipmentdistributionrec.shipment_line_id,
4376 x_shipmentdistributionrec.line_location_id,
4377 NULL, --po_distribution_id
4378 x_shipmentdistributionrec.unit_meas_lookup_code,
4379 x_converted_trx_qty,
4380 x_tolerable_qty,
4381 x_secondary_available_qty
4382 );
4383
4384 IF (g_asn_debug = 'Y') THEN
4385 asn_debug.put_line('x_converted_trx_qty ' || x_converted_trx_qty);
4386 asn_debug.put_line('x_tolerable_qty ' || x_tolerable_qty);
4387 asn_debug.put_line('x_secondary_available_qty ' || x_secondary_available_qty);
4388 END IF;
4389 END IF; --}
4390
4391
4392 -- If qtys have already been allocated for this po_line_location_id during
4393 -- a cascade process which has not been written to the db yet, we need to
4394 -- decrement it from the total available quantity
4395 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
4396 -- po_line_location_id
4397
4398 IF n > 1 THEN -- We will do this for all rows except the 1st
4399 FOR i IN 1 ..(n - 1) LOOP
4400 IF x_cascaded_table(i).po_line_location_id = x_shipmentdistributionrec.line_location_id THEN
4401 already_allocated_qty := already_allocated_qty + x_cascaded_table(i).source_doc_quantity;
4402 END IF;
4403 END LOOP;
4404 END IF;
4405 ELSE --} { for txn != deliver
4406 /* Bug# 1548597*/
4407 /* IF (x_is_asn = FALSE) THEN --{ Replaced by forward port 4523892 */
4408 IF (rcv_roi_header.g_txn_against_asn = 'N') THEN --{ Bug#4523892
4409 IF (g_asn_debug = 'Y') THEN
4410 asn_debug.put_line('Direct delivery against a Po');
4411 END IF;
4412
4413 rcv_quantities_s.get_available_quantity('DIRECT RECEIPT',
4414 x_shipmentdistributionrec.po_distribution_id,
4415 'VENDOR',
4416 NULL,
4417 NULL,
4418 NULL,
4419 x_converted_trx_qty,
4420 x_tolerable_qty,
4421 x_shipmentdistributionrec.unit_meas_lookup_code,
4422 x_secondary_available_qty
4423 );
4424 ELSE --}{
4425 IF (g_asn_debug = 'Y') THEN
4426 asn_debug.put_line('Direct delivery for an ASN');
4427 END IF;
4428
4429 rcv_quantities_s.get_available_asn_quantity('DIRECT RECEIPT',
4430 x_shipmentdistributionrec.shipment_line_id,
4431 x_shipmentdistributionrec.line_location_id,
4432 x_shipmentdistributionrec.po_distribution_id,
4433 x_shipmentdistributionrec.unit_meas_lookup_code,
4434 x_converted_trx_qty,
4435 x_tolerable_qty,
4436 x_secondary_available_qty
4437 );
4438
4439 IF (g_asn_debug = 'Y') THEN
4440 asn_debug.put_line('x_converted_trx_qty ' || x_converted_trx_qty);
4441 asn_debug.put_line('x_tolerable_qty ' || x_tolerable_qty);
4442 asn_debug.put_line('x_secondary_available_qty ' || x_secondary_available_qty);
4443 END IF;
4444 END IF; --}
4445
4446 /* Bug# 1337787 - Calculated the x_tolerable_qty in
4447 rcv_quantities_s.get_available_quantity procedure */
4448
4449 -- x_tolerable_qty := x_converted_trx_qty;
4450 -- If qtys have already been allocated for this po_distribution_id during
4451 -- a cascade process which has not been written to the db yet, we need to
4452 -- decrement it from the total available quantity
4453 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
4454 -- po_distribution_id
4455
4456 IF n > 1 THEN -- We will do this for all rows except the 1st
4457 FOR i IN 1 ..(n - 1) LOOP
4458 IF x_cascaded_table(i).po_distribution_id = x_shipmentdistributionrec.po_distribution_id THEN
4459 already_allocated_qty := already_allocated_qty + x_cascaded_table(i).source_doc_quantity;
4460 END IF;
4461 END LOOP;
4462 END IF;
4463 END IF; --} for txn =deliver
4464
4465 IF (g_asn_debug = 'Y') THEN
4466 asn_debug.put_line('After call to get_available quantity');
4467 asn_debug.put_line('Available Quantity ' || TO_CHAR(x_converted_trx_qty));
4468 asn_debug.put_line('Tolerable Quantity ' || TO_CHAR(x_tolerable_qty));
4469 asn_debug.put_line('Already Shipped Quantity ' || TO_CHAR(NVL(x_shipmentdistributionrec.quantity_shipped, 0)));
4470 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
4471 END IF;
4472
4473 -- if qty has already been allocated then reduce available and tolerable
4474 -- qty by the allocated amount
4475
4476 IF NVL(already_allocated_qty, 0) > 0 THEN --{
4477 x_converted_trx_qty := x_converted_trx_qty - already_allocated_qty;
4478 x_tolerable_qty := x_tolerable_qty - already_allocated_qty;
4479
4480 IF x_converted_trx_qty < 0 THEN
4481 x_converted_trx_qty := 0;
4482 END IF;
4483
4484 IF x_tolerable_qty < 0 THEN
4485 x_tolerable_qty := 0;
4486 END IF;
4487
4488 IF (g_asn_debug = 'Y') THEN
4489 asn_debug.put_line('Have some allocated quantity. Will reduce qty');
4490 asn_debug.put_line('Allocated Qty ' || TO_CHAR(already_allocated_qty));
4491 asn_debug.put_line('After reducing by allocated qty');
4492 asn_debug.put_line('Available Quantity ' || TO_CHAR(x_converted_trx_qty));
4493 asn_debug.put_line('Tolerable Quantity ' || TO_CHAR(x_tolerable_qty));
4494 asn_debug.put_line('Already Shipped Quantity ' || TO_CHAR(NVL(x_shipmentdistributionrec.quantity_shipped, 0)));
4495 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
4496 END IF;
4497 END IF; --}
4498
4499 -- We can use the first record since the item_id and uom are not going to change
4500 -- Check that we can convert between ASN-> PO uom
4501 -- PO -> ASN uom
4502 -- PO -> PRIMARY uom
4503 -- If any of the conversions fail then we cannot use that record
4504
4505 x_remaining_qty_po_uom := 0; -- initialize
4506 po_asn_uom_qty := 0; -- initialize
4507 po_primary_uom_qty := 0; -- initialize
4508
4509 /* Bug 5203841.
4510 * In complex work POs,there is a case where the rate based
4511 * PO shipment has matching_basis as Quantity based. But
4512 * item_id is null. Since there is no uom conversion in
4513 * the case of complex work POs, the old code would
4514 * return the original quantity whereas the new one
4515 * errors out. Reverting to old code for complex work POs.
4516 */
4517 PO_COMPLEX_WORK_GRP.is_complex_work_po(
4518 1.0,
4519 temp_cascaded_table(1).po_header_id, --Bug: 5357628
4520 l_return_status,
4521 l_complex_flag);
4522
4523 IF (l_return_status IS NOT NULL AND
4524 l_return_status = FND_API.g_ret_sts_success) THEN
4525 IF( g_asn_debug = 'Y' ) THEN
4526 asn_debug.put_line('l_return_status ' || l_return_status);
4527 asn_debug.put_line('l_po_header_id ' || temp_cascaded_table(1).po_header_id);
4528 END IF;
4529 ELSE
4530 IF( g_asn_debug = 'Y') THEN
4531 asn_debug.put_line('l_return_status ' || l_return_status);
4532 END IF;
4533 END IF;
4534
4535 if ( l_complex_flag = 'Y' ) then --{
4536 x_remaining_qty_po_uom := rcv_transactions_interface_sv.convert_into_correct_qty(x_remaining_quantity,
4537
4538 temp_cascaded_table(1).unit_of_measure,
4539
4540 temp_cascaded_table(1).item_id,
4541
4542 x_shipmentdistributionrec.unit_meas_lookup_code
4543
4544 );
4545 -- using arbit qty for PO->ASN, PO->PRIMARY UOM conversion as this is just a check
4546
4547 po_asn_uom_qty := rcv_transactions_interface_sv.convert_into_correct_qty(1000,
4548
4549 x_shipmentdistributionrec.unit_meas_lookup_code,
4550
4551 temp_cascaded_table(1).item_id,
4552
4553 temp_cascaded_table(1).unit_of_measure
4554
4555 );
4556 po_primary_uom_qty := rcv_transactions_interface_sv.convert_into_correct_qty(1000,
4557
4558 x_shipmentdistributionrec.unit_meas_lookup_code,
4559
4560 temp_cascaded_table(1).item_id,
4561
4562 temp_cascaded_table(1).primary_unit_of_measure
4563
4564 );
4565 else --}{
4566 -- Bug 4898703 - START {
4567 x_remaining_qty_po_uom := x_remaining_quantity * po_uom_s.po_uom_convert(temp_cascaded_table(1).unit_of_measure,
4568 x_shipmentdistributionrec.unit_meas_lookup_code,
4569 temp_cascaded_table(1).item_id
4570 );
4571 -- using arbit qty for PO->ASN, PO->PRIMARY UOM conversion as this is just a check
4572
4573 po_asn_uom_qty := 1000 * po_uom_s.po_uom_convert( x_shipmentdistributionrec.unit_meas_lookup_code,
4574 temp_cascaded_table(1).unit_of_measure,
4575 temp_cascaded_table(1).item_id
4576 );
4577 po_primary_uom_qty := 1000 * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
4578 temp_cascaded_table(1).primary_unit_of_measure,
4579 temp_cascaded_table(1).item_id
4580 );
4581 -- Bug 4898703 - END }
4582
4583 end if ; -- Bug 5203841. }
4584
4585 IF x_remaining_qty_po_uom = 0
4586 OR -- no point in going further for this record
4587 po_asn_uom_qty = 0
4588 OR -- as we cannot convert between the ASN -> PO uoms
4589 po_primary_uom_qty = 0 THEN --{ -- PO -> ASN uom, PO -> PRIMARY UOM
4590 IF (g_asn_debug = 'Y') THEN
4591 asn_debug.put_line('Populating an error message in the interface tables');
4592 asn_debug.put_line('Cannot interconvert between diff UOMs');
4593 asn_debug.put_line('This po_line cannot be used as the uoms ');
4594 asn_debug.put_line(temp_cascaded_table(1).unit_of_measure || ' ' || x_shipmentdistributionrec.unit_meas_lookup_code);
4595 asn_debug.put_line('cannot be converted for item ' || TO_CHAR(temp_cascaded_table(1).item_id));
4596
4597 /* Start Bug 3654053 : Need to populate the po_interface_errors
4598 table if the UOM conversion errors out.
4599 */
4600 IF po_primary_uom_qty = 0 THEN
4601 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4602 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY', x_cascaded_table(n).error_message);
4603 rcv_error_pkg.set_token('SHIPMENT_UNIT', x_shipmentdistributionrec.unit_meas_lookup_code);
4604 rcv_error_pkg.set_token('PRIMARY_UNIT', x_cascaded_table(n).primary_unit_of_measure);
4605 rcv_error_pkg.log_interface_error('PRIMARY_UNIT_OF_MEASURE', FALSE);
4606 ELSE
4607 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
4608 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PO', x_cascaded_table(n).error_message);
4609 rcv_error_pkg.set_token('SHIPMENT_UNIT', temp_cascaded_table(1).unit_of_measure);
4610 rcv_error_pkg.set_token('PRIMARY_UNIT', x_shipmentdistributionrec.unit_meas_lookup_code);
4611 rcv_error_pkg.log_interface_error('UNIT_OF_MEASURE', FALSE);
4612 END IF;
4613 /* End Bug 3654053 */
4614 END IF;
4615 ELSE -- we have converted the qty between uoms succesfully } {
4616 IF (g_asn_debug = 'Y') THEN
4617 asn_debug.put_line('Current Item Id ' || TO_CHAR(temp_cascaded_table(1).item_id));
4618 asn_debug.put_line('Current ASN Quantity ' || TO_CHAR(x_remaining_quantity));
4619 asn_debug.put_line('Current ASN UOM ' || temp_cascaded_table(1).unit_of_measure);
4620 asn_debug.put_line('Converted PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
4621 asn_debug.put_line('PO UOM ' || x_shipmentdistributionrec.unit_meas_lookup_code);
4622 END IF;
4623
4624 -- If last row set available = tolerable - shipped
4625 -- else = available - shipped
4626 /** Debug: We're a bit screwed here. How do we know if the shipment is taken into account here.
4627 **I guess if the transaction has the shipment line id then we should take the quantity from the shipped quantity.
4628 **Need to walk through the different scenarios
4629 */
4630 IF rows_fetched = x_record_count THEN --{
4631 x_converted_trx_qty := x_tolerable_qty - NVL(x_shipmentdistributionrec.quantity_shipped, 0);
4632
4633 IF (g_asn_debug = 'Y') THEN
4634 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_trx_qty));
4635 END IF;
4636 ELSE --} {
4637 x_converted_trx_qty := x_converted_trx_qty - NVL(x_shipmentdistributionrec.quantity_shipped, 0);
4638
4639 IF (g_asn_debug = 'Y') THEN
4640 asn_debug.put_line('Not Last Row : ' || TO_CHAR(x_converted_trx_qty));
4641 END IF;
4642 END IF; --}
4643
4644 IF x_converted_trx_qty > 0 THEN --{
4645 IF (x_converted_trx_qty < x_remaining_qty_po_uom) THEN -- compare like uoms {
4646 IF (g_asn_debug = 'Y') THEN
4647 asn_debug.put_line('We are in > Qty branch');
4648 END IF;
4649
4650 x_remaining_qty_po_uom := x_remaining_qty_po_uom - x_converted_trx_qty;
4651 -- change asn uom qty so both qtys are in sync
4652
4653 /* Bug 5203841.
4654 * In complex work POs,there is a case where the rate based
4655 * PO shipment has matching_basis as Quantity based. But
4656 * item_id is null. Since there is no uom conversion in
4657 * the case of complex work POs, the old code would
4658 * return the original quantity whereas the new one
4659 * errors out. Reverting to old code for complex work POs.
4660 */
4661 if ( l_complex_flag = 'Y' ) then --{
4662 x_remaining_quantity :=
4663 rcv_transactions_interface_sv.convert_into_correct_qty(
4664 x_remaining_qty_po_uom,
4665 x_shipmentdistributionrec.unit_meas_lookup_code,
4666 temp_cascaded_table(1).item_id,
4667 temp_cascaded_table(1).unit_of_measure);
4668
4669 else --}{
4670 -- Bug 4898703
4671 x_remaining_quantity := x_remaining_qty_po_uom * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
4672 temp_cascaded_table(1).unit_of_measure,
4673 temp_cascaded_table(1).item_id );
4674 end if; -- 5203841 }
4675 insert_into_table := TRUE;
4676 ELSE --} {
4677 IF (g_asn_debug = 'Y') THEN
4678 asn_debug.put_line('We are in <= Qty branch ');
4679 END IF;
4680
4681 x_converted_trx_qty := x_remaining_qty_po_uom;
4682 insert_into_table := TRUE;
4683 x_remaining_qty_po_uom := 0;
4684 x_remaining_quantity := 0;
4685 END IF; --}
4686 ELSE -- no qty for this record but if last row we need it } {
4687 IF rows_fetched = x_record_count THEN --{ last row needs to be inserted anyway
4688 -- so that the row can be used based on qty tolerance checks
4689 IF (g_asn_debug = 'Y') THEN
4690 asn_debug.put_line('Quantity is less then 0 but last record');
4691 END IF;
4692
4693 insert_into_table := TRUE;
4694 x_converted_trx_qty := 0;
4695 ELSE --} {
4696 IF (g_asn_debug = 'Y') THEN
4697 asn_debug.put_line('<= 0 Quantity but more records in cursor');
4698 END IF;
4699
4700 x_remaining_qty_po_uom := 0; -- we may have a diff uom on the next iteration
4701
4702 IF (g_asn_debug = 'Y') THEN
4703 asn_debug.put_line('We have to deal with remaining_qty > 0 and x_converted_trx_qty -ve');
4704 END IF;
4705
4706 insert_into_table := FALSE;
4707 END IF; --}
4708 END IF; --}
4709 END IF; --} remaining_qty_po_uom <> 0
4710
4711 IF insert_into_table THEN --{
4712 IF (x_first_trans) THEN --{
4713 IF (g_asn_debug = 'Y') THEN
4714 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
4715 END IF;
4716
4717 x_first_trans := FALSE;
4718
4719 IF NVL(temp_cascaded_table(current_n).vendor_cum_shipped_qty, 0) <> 0 THEN --{
4720 IF (g_asn_debug = 'Y') THEN
4721 asn_debug.put_line('The cum qty from vendor is ' || TO_CHAR(temp_cascaded_table(current_n).vendor_cum_shipped_qty));
4722 END IF;
4723
4724 /* The vendor sends us cum_qty which also includes the current shipment ???.
4725 We need to allocate the correct cum_qty to each row as the cascade happens
4726 The algorithm is as follows
4727 reset cum_qty = cum_qty - total_shipped_qty (x_bkp_qty) in the 1st run
4728 Later reset cum_qty = cum_qty + primary_qty for each insert.Since we always
4729 copy the previous record this should work pretty well */
4730
4731 /* Bug 5203841.
4732 * In complex work POs,there is a case where the rate based
4733 * PO shipment has matching_basis as Quantity based. But
4734 * item_id is null. Since there is no uom conversion in
4735 * the case of complex work POs, the old code would
4736 * return the original quantity whereas the new one
4737 * errors out. Reverting to old code for complex work POs.
4738 */
4739 if ( l_complex_flag = 'Y' ) then --{
4740 temp_cascaded_table(current_n).vendor_cum_shipped_qty :=
4741 temp_cascaded_table(current_n).vendor_cum_shipped_qty
4742 - rcv_transactions_interface_sv.convert_into_correct_qty
4743 (x_bkp_qty,
4744 temp_cascaded_table(current_n).unit_of_measure,
4745 temp_cascaded_table(current_n).item_id,
4746 temp_cascaded_table(current_n).primary_unit_of_measure);
4747
4748 else --}{
4749 -- Bug 4898703
4750 temp_cascaded_table(current_n).vendor_cum_shipped_qty := temp_cascaded_table(current_n).vendor_cum_shipped_qty
4751 - (x_bkp_qty * po_uom_s.po_uom_convert(temp_cascaded_table(current_n).unit_of_measure,
4752 temp_cascaded_table(current_n).primary_unit_of_measure,
4753 temp_cascaded_table(current_n).item_id
4754 ));
4755 end if; -- 5203841 }
4756
4757 IF (g_asn_debug = 'Y') THEN
4758 asn_debug.put_line('Cum qty - current shipment ' || TO_CHAR(temp_cascaded_table(current_n).vendor_cum_shipped_qty));
4759 END IF;
4760 END IF; --}
4761 ELSE --} { ! x_first_trans
4762 IF (g_asn_debug = 'Y') THEN
4763 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
4764 END IF;
4765
4766 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
4767 END IF; --} matches x_first_transfer
4768
4769 /* source_doc_quantity -> in po_uom
4770 primary_quantity -> in primary_uom
4771 cum_qty -> in primary_uom
4772 quantity,quantity_shipped -> in ASN uom */
4773 temp_cascaded_table(current_n).source_doc_quantity := x_converted_trx_qty; -- in po uom
4774 temp_cascaded_table(current_n).source_doc_unit_of_measure := x_shipmentdistributionrec.unit_meas_lookup_code;
4775 -- bug 1363369 fix carried forward FROM bug# 1337314
4776 -- No need to do the following conversion if the cursor returns one row
4777 -- for a corresponding record in the interface, as the quantity is already in asn uom.
4778 -- If the cursor fetches more than one row then the quantity in the interface will be
4779 -- distributed accross the fetched rows and hence need to do the following conversion.
4780 --IF x_record_count > 1 THEN -- {
4781
4782 /* Bug 5203841.
4783 * In complex work POs,there is a case where the rate based
4784 * PO shipment has matching_basis as Quantity based. But
4785 * item_id is null. Since there is no uom conversion in
4786 * the case of complex work POs, the old code would
4787 * return the original quantity whereas the new one
4788 * errors out. Reverting to old code for complex work POs.
4789 */
4790 if ( l_complex_flag = 'Y' ) then --{
4791 temp_cascaded_table(current_n).quantity := rcv_transactions_interface_sv.convert_into_correct_qty(x_converted_trx_qty,
4792
4793 x_shipmentdistributionrec.unit_meas_lookup_code,
4794
4795 temp_cascaded_table(current_n).item_id,
4796
4797 temp_cascaded_table(current_n).unit_of_measure
4798
4799 ); -- in asn uom
4800 --END IF; --}
4801 else --}{
4802 -- Bug 4898703 - START {
4803 temp_cascaded_table(current_n).quantity := x_converted_trx_qty * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
4804 temp_cascaded_table(current_n).unit_of_measure,
4805 temp_cascaded_table(current_n).item_id
4806 ); -- in asn uom
4807 --END IF; --}
4808 temp_cascaded_table(current_n).quantity := round(temp_cascaded_table(current_n).quantity, 6);
4809 end if; -- 5203841 }
4810 temp_cascaded_table(current_n).quantity_shipped := temp_cascaded_table(current_n).quantity; -- in asn uom
4811
4812 -- Primary qty in Primary UOM
4813 /* Bug 5203841.
4814 * In complex work POs,there is a case where the rate based
4815 * PO shipment has matching_basis as Quantity based. But
4816 * item_id is null. Since there is no uom conversion in
4817 * the case of complex work POs, the old code would
4818 * return the original quantity whereas the new one
4819 * errors out. Reverting to old code for complex work POs.
4820 */
4821 if ( l_complex_flag = 'Y' ) then --{
4822 temp_cascaded_table(current_n).primary_quantity := rcv_transactions_interface_sv.convert_into_correct_qty(x_converted_trx_qty,
4823 x_shipmentdistributionrec.unit_meas_lookup_code,
4824
4825 temp_cascaded_table(current_n).item_id,
4826
4827 temp_cascaded_table(current_n).primary_unit_of_measure
4828
4829 );
4830
4831
4832
4833 else -- }{
4834 temp_cascaded_table(current_n).primary_quantity := x_converted_trx_qty * po_uom_s.po_uom_convert(x_shipmentdistributionrec.unit_meas_lookup_code,
4835 temp_cascaded_table(current_n).primary_unit_of_measure,
4836 temp_cascaded_table(current_n).item_id
4837 );
4838 temp_cascaded_table(current_n).primary_quantity := round(temp_cascaded_table(current_n).primary_quantity,6);
4839
4840 end if; -- 5203841 }
4841 -- Bug 4898703 - END }
4842
4843 IF (g_asn_debug = 'Y') THEN
4844 asn_debug.put_line('primary_qty ' || temp_cascaded_table(current_n).primary_quantity);
4845 asn_debug.put_line('quantity ' || temp_cascaded_table(current_n).quantity);
4846 END IF;
4847
4848 -- Assuming vendor_cum_shipped_qty is in PRIMARY UOM
4849 IF NVL(temp_cascaded_table(current_n).vendor_cum_shipped_qty, 0) <> 0 THEN --{
4850 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;
4851 END IF; --}
4852
4853 temp_cascaded_table(current_n).inspection_status_code := 'NOT INSPECTED';
4854 temp_cascaded_table(current_n).interface_source_code := 'RCV';
4855 temp_cascaded_table(current_n).currency_code := x_shipmentdistributionrec.currency_code;
4856 temp_cascaded_table(current_n).po_unit_price := x_shipmentdistributionrec.unit_price;
4857 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).quantity * tax_amount_factor, 4);
4858
4859 IF (g_asn_debug = 'Y') THEN
4860 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
4861 END IF;
4862
4863 temp_cascaded_table(current_n).category_id := x_shipmentdistributionrec.category_id;
4864 temp_cascaded_table(current_n).item_description := x_shipmentdistributionrec.item_description;
4865 temp_cascaded_table(current_n).unit_of_measure_class := x_shipmentdistributionrec.unit_of_measure_class;
4866
4867 IF temp_cascaded_table(current_n).to_organization_id IS NULL THEN --{
4868 temp_cascaded_table(current_n).to_organization_id := x_shipmentdistributionrec.ship_to_organization_id;
4869 END IF; --}
4870
4871 temp_cascaded_table(current_n).po_line_id := x_shipmentdistributionrec.po_line_id;
4872 temp_cascaded_table(current_n).po_line_location_id := x_shipmentdistributionrec.line_location_id;
4873 temp_cascaded_table(current_n).shipment_line_id := x_shipmentdistributionrec.shipment_line_id;
4874
4875 IF x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING' THEN --{
4876 IF (g_asn_debug = 'Y') THEN
4877 asn_debug.put_line('Message to warn about different shiptolocations');
4878 END IF;
4879 END IF; --}
4880
4881 /* ksareddy - 2329928 Ported changes by bao in branch to cache set_of_books_id */
4882 IF (rcv_transactions_interface_sv.x_set_of_books_id IS NULL) THEN
4883 SELECT set_of_books_id
4884 INTO rcv_transactions_interface_sv.x_set_of_books_id
4885 FROM financials_system_parameters;
4886 END IF;
4887
4888 x_sob_id := rcv_transactions_interface_sv.x_set_of_books_id;
4889 /* Bug 1845702
4890 * Currency rate and date can be changed at the time of receipt
4891 * depending on the profile ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE.
4892 * This was not handled in the open interface. Introduced code
4893 * to handle the changes at the time of receipt
4894 */
4895 /* Bug#3746516 Added the following if condition so as to get the value of the profile
4896 ** option only when the match option is receipt and thus to avoid executing the below
4897 ** function call always.
4898 */
4899 IF (x_ShipmentDistributionRec.match_option = 'R') THEN
4900 x_allow_rate_override := NVL(fnd_profile.value('ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE'), 'N');
4901 END IF;
4902
4903 IF (g_asn_debug = 'Y') THEN
4904 asn_debug.put_line('Match Option:' || x_ShipmentDistributionRec.match_option ||
4905 'Profile value ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE:' ||
4906 x_allow_rate_override);
4907 END IF;
4908
4909 /* Bug#3746516 - START
4910 ** Modified the following code to consider all the possible scenarios such that the
4911 ** rate and the rate date values will be derived correctly and the correct rate and
4912 ** rate date values will now be posted in rcv_transactions table so that there will
4913 ** not be any discrepency in the calculations and hence all the data between the two
4914 ** tables rcv_transactions and rcv_receiving_sub_ledger will be in sync. */
4915
4916 BEGIN
4917
4918 SELECT count(po_distribution_id),max(rate),max(rate_date)
4919 INTO l_dist_count,x_rate,l_rate_date
4920 FROM po_distributions
4921 WHERE line_location_id = x_ShipmentDistributionRec.line_location_id
4922 HAVING count(po_distribution_id) = 1;
4923
4924 EXCEPTION
4925 WHEN NO_DATA_FOUND THEN
4926 l_dist_count := 2;
4927 END;
4928
4929 IF (g_asn_debug = 'Y') THEN
4930 asn_debug.put_line('No of Distributions:' || l_dist_count ||
4931 ':: Rate and Rate_date in po distributions' || x_rate ||
4932 '::' || l_rate_date);
4933 END IF;
4934
4935 IF (x_ShipmentDistributionRec.match_option = 'P') THEN --{
4936
4937 IF (l_dist_count = 1) THEN --{
4938 temp_cascaded_table(current_n).currency_conversion_date := l_rate_date;
4939 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
4940 ELSE
4941 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
4942 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
4943 END IF; --}
4944
4945 ELSIF (x_ShipmentDistributionRec.match_option = 'R') THEN
4946
4947 IF (x_ShipmentDistributionRec.rate_type = 'User') THEN --{
4948
4949 IF ( x_allow_rate_override ='N') THEN --{
4950
4951 IF (l_dist_count = 1) THEN --{
4952 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
4953 temp_cascaded_table(current_n).currency_conversion_date := l_rate_date;
4954 ELSE
4955 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
4956 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
4957 END IF; --}
4958
4959 ELSIF ( x_allow_rate_override ='Y') THEN
4960
4961 IF (l_dist_count = 1) THEN --{
4962 temp_cascaded_table(current_n).currency_conversion_date :=
4963 nvl(temp_cascaded_table(current_n).currency_conversion_date,l_rate_date);
4964 temp_cascaded_table(current_n).currency_conversion_rate :=
4965 nvl(temp_cascaded_table(current_n).currency_conversion_rate,x_rate);
4966 ELSE
4967 temp_cascaded_table(current_n).currency_conversion_date :=
4968 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_ShipmentDistributionRec.rate_date);
4969 temp_cascaded_table(current_n).currency_conversion_rate :=
4970 nvl(temp_cascaded_table(current_n).currency_conversion_rate,x_ShipmentDistributionRec.rate);
4971 END IF; --}
4972 END IF; --}
4973
4974 ELSE
4975
4976 IF ( temp_cascaded_table(current_n).currency_conversion_date IS NOT NULL ) THEN --{
4977
4978 x_rate := gl_currency_api.get_rate(x_sob_Id,
4979 x_ShipmentDistributionRec.currency_code,
4980 temp_cascaded_table(current_n).currency_conversion_date,
4981 x_ShipmentDistributionRec.rate_type);
4982 x_rate := round(x_rate,28);
4983 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
4984
4985 ELSE
4986
4987 IF (l_dist_count = 1) THEN --{
4988 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
4989 temp_cascaded_table(current_n).currency_conversion_date := l_rate_date;
4990 ELSE
4991 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
4992 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
4993 END IF; --}
4994
4995 END IF; --}
4996
4997 END IF; --}
4998
4999 END IF; --}
5000
5001 temp_cascaded_table(current_n).currency_conversion_type := x_ShipmentDistributionRec.rate_type;
5002
5003 IF (g_asn_debug = 'Y') THEN
5004 asn_debug.put_line('Rate, Rate type and Rate_date ::' ||
5005 temp_cascaded_table(current_n).currency_conversion_rate ||
5006 '::' || temp_cascaded_table(current_n).currency_conversion_type ||
5007 '::' || temp_cascaded_table(current_n).currency_conversion_date);
5008 END IF;
5009
5010 /* Bug#3746516 - END */
5011
5012 -- Copy the distribution specific information only if this is a direct receipt.
5013
5014 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
5015 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
5016 temp_cascaded_table(current_n).po_distribution_id := x_shipmentdistributionrec.po_distribution_id;
5017 temp_cascaded_table(current_n).charge_account_id := x_shipmentdistributionrec.code_combination_id;
5018 temp_cascaded_table(current_n).req_distribution_id := x_shipmentdistributionrec.req_distribution_id;
5019 --temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
5020 --temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
5021 temp_cascaded_table(current_n).destination_type_code := x_shipmentdistributionrec.destination_type_code;
5022 temp_cascaded_table(current_n).destination_context := x_shipmentdistributionrec.destination_type_code;
5023
5024 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
5025 temp_cascaded_table(current_n).deliver_to_location_id := x_shipmentdistributionrec.deliver_to_location_id;
5026 END IF;
5027
5028 /* Bug 2392074 - If the deliver_to_person mentioned in the po_distributions is
5029 invalid or inactive at the time of Receipt we need to clear the deliver to person,
5030 as this is an optional field. */
5031 IF (NVL(temp_cascaded_table(current_n).deliver_to_person_id, 0) = 0) THEN --{
5032 temp_cascaded_table(current_n).deliver_to_person_id := x_shipmentdistributionrec.deliver_to_person_id;
5033
5034 IF (temp_cascaded_table(current_n).deliver_to_person_id IS NOT NULL) THEN --{
5035 BEGIN
5036 SELECT NVL(MAX(hre.full_name), 'notfound')
5037 INTO x_full_name
5038 FROM hr_employees_current_v hre
5039 WHERE ( hre.inactive_date IS NULL
5040 OR hre.inactive_date > SYSDATE)
5041 AND hre.employee_id = temp_cascaded_table(current_n).deliver_to_person_id;
5042
5043 IF (x_full_name = 'notfound') THEN
5044 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
5045 END IF;
5046 EXCEPTION
5047 WHEN NO_DATA_FOUND THEN
5048 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
5049
5050 IF (g_asn_debug = 'Y') THEN
5051 asn_debug.put_line('The deliver to person entered in PO is currently inactive');
5052 asn_debug.put_line(' So it is cleared off');
5053 END IF;
5054 WHEN OTHERS THEN
5055 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
5056
5057 IF (g_asn_debug = 'Y') THEN
5058 asn_debug.put_line('Some exception has occured');
5059 asn_debug.put_line('This exception is due to the PO deliver to person');
5060 asn_debug.put_line('The deliver to person is optional');
5061 asn_debug.put_line('So cleared off the deliver to person');
5062 END IF;
5063 END;
5064 END IF; --}
5065 END IF; --}
5066
5067 IF (temp_cascaded_table(current_n).subinventory IS NULL) THEN
5068 temp_cascaded_table(current_n).subinventory := x_shipmentdistributionrec.destination_subinventory;
5069
5070 /* Bug3993867 - START
5071 ** Added the call to procedure derive_to_locator_id() here
5072 ** so that incases where subinventory and
5073 ** locator_id are not populated into RTI, locator_id could be
5074 ** derived at this point as the subinventory is known now.
5075 */
5076 IF (g_asn_debug = 'Y') THEN
5077 asn_debug.put_line('Derived Subinventory from PO Distribution:' || temp_cascaded_table(current_n).subinventory);
5078 END IF;
5079
5080 derive_to_locator_id(temp_cascaded_table, current_n);
5081
5082 IF (g_asn_debug = 'Y') THEN
5083 asn_debug.put_line('Derived Locator_ID:' || temp_cascaded_table(current_n).locator_id);
5084 END IF;
5085
5086 /* Bug3993867 - END */
5087
5088 END IF;
5089
5090 temp_cascaded_table(current_n).wip_entity_id := x_shipmentdistributionrec.wip_entity_id;
5091 temp_cascaded_table(current_n).wip_operation_seq_num := x_shipmentdistributionrec.wip_operation_seq_num;
5092 temp_cascaded_table(current_n).wip_resource_seq_num := x_shipmentdistributionrec.wip_resource_seq_num;
5093 temp_cascaded_table(current_n).wip_repetitive_schedule_id := x_shipmentdistributionrec.wip_repetitive_schedule_id;
5094 temp_cascaded_table(current_n).wip_line_id := x_shipmentdistributionrec.wip_line_id;
5095 temp_cascaded_table(current_n).bom_resource_id := x_shipmentdistributionrec.bom_resource_id;
5096
5097 -- bug 1361786
5098 IF (temp_cascaded_table(current_n).ussgl_transaction_code IS NULL) THEN
5099 temp_cascaded_table(current_n).ussgl_transaction_code := x_shipmentdistributionrec.ussgl_transaction_code;
5100 END IF;
5101 END IF; --} matches txn != deliver
5102
5103 current_n := current_n + 1;
5104
5105 IF (g_asn_debug = 'Y') THEN
5106 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
5107 END IF;
5108 END IF; --} matches if insert into table
5109 END IF; --} matches shipmentdistributionrec.receipt_days_exception_code = none
5110 END LOOP; --}
5111 ELSE --} {
5112 -- error_status and error_message are set after validate_quantity_shipped
5113 IF (g_asn_debug = 'Y') THEN
5114 asn_debug.put_line('No shipment_header_id/po_header_id/item_id ');
5115 END IF;
5116
5117 IF (g_asn_debug = 'Y') THEN
5118 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
5119 END IF;
5120
5121 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
5122 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5123 rcv_error_pkg.set_error_message('RCV_ASN_NO_PO_LINE_LOCATION_ID', x_cascaded_table(n).error_message);
5124 rcv_error_pkg.set_token('DOCUMENT_NUM', x_cascaded_table(n).document_num);
5125 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
5126 END IF; --}
5127
5128 RETURN;
5129 END IF; -- } of (asn quantity_shipped was valid)
5130
5131 -- OPM change.Bug# 3061052
5132 -- if original receiving transaction line is split and secondary quantity is specified then
5133 -- set secondary quantity for the split lines to NULL.In such a case,secondary quantity for the
5134 -- split lines will be calculating by the system in opm_roi_grp.validate_lot API.
5135 /* INVCONV , It checks for OPM insatallation. This needs to be removed , Punit Kumar */
5136
5137 IF /* gml_process_flags.opm_installed = 1
5138 AND*/ x_cascaded_table(n).secondary_quantity IS NOT NULL THEN
5139 IF temp_cascaded_table.COUNT > 1 THEN
5140 FOR j IN 1 .. temp_cascaded_table.COUNT LOOP
5141 temp_cascaded_table(j).secondary_quantity := NULL;
5142 END LOOP;
5143 END IF;
5144 END IF;
5145
5146 IF shipments%ISOPEN THEN
5147 CLOSE shipments;
5148 END IF;
5149
5150 IF count_shipments%ISOPEN THEN
5151 CLOSE count_shipments;
5152 END IF;
5153
5154 IF distributions%ISOPEN THEN
5155 CLOSE distributions;
5156 END IF;
5157
5158 IF count_distributions%ISOPEN THEN
5159 CLOSE count_distributions;
5160 END IF;
5161
5162 IF asn_shipments%ISOPEN THEN
5163 CLOSE asn_shipments;
5164 END IF;
5165
5166 IF count_asn_shipments%ISOPEN THEN
5167 CLOSE count_asn_shipments;
5168 END IF;
5169
5170 IF asn_distributions%ISOPEN THEN
5171 CLOSE asn_distributions;
5172 END IF;
5173
5174 IF count_asn_distributions%ISOPEN THEN
5175 CLOSE count_asn_distributions;
5176 END IF;
5177
5178 IF (g_asn_debug = 'Y') THEN
5179 asn_debug.put_line('Exit explode_line_quantity');
5180 END IF;
5181 EXCEPTION
5182 WHEN OTHERS THEN
5183 IF (g_asn_debug = 'Y') THEN
5184 asn_debug.put_line('Exception in derive_vendor_rcv_line_qty');
5185 END IF;
5186
5187 IF shipments%ISOPEN THEN
5188 CLOSE shipments;
5189 END IF;
5190
5191 IF count_shipments%ISOPEN THEN
5192 CLOSE count_shipments;
5193 END IF;
5194
5195 IF distributions%ISOPEN THEN
5196 CLOSE distributions;
5197 END IF;
5198
5199 IF count_distributions%ISOPEN THEN
5200 CLOSE count_distributions;
5201 END IF;
5202
5203 IF asn_shipments%ISOPEN THEN
5204 CLOSE asn_shipments;
5205 END IF;
5206
5207 IF count_asn_shipments%ISOPEN THEN
5208 CLOSE count_asn_shipments;
5209 END IF;
5210
5211 IF asn_distributions%ISOPEN THEN
5212 CLOSE asn_distributions;
5213 END IF;
5214
5215 IF count_asn_distributions%ISOPEN THEN
5216 CLOSE count_asn_distributions;
5217 END IF;
5218
5219 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
5220 rcv_error_pkg.set_sql_error_message('derive_vendor_rcv_line_qty', x_progress);
5221 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
5222
5223 IF (g_asn_debug = 'Y') THEN
5224 asn_debug.put_line(TO_CHAR(n));
5225 asn_debug.put_line(SQLERRM);
5226 asn_debug.put_line('error ' || x_progress);
5227 END IF;
5228 END derive_vendor_rcv_line_qty;
5229
5230 PROCEDURE derive_vendor_rcv_line_amt(
5231 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
5232 n IN OUT NOCOPY BINARY_INTEGER,
5233 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
5234 x_header_record IN rcv_roi_preprocessor.header_rec_type
5235 ) IS
5236 x_include_closed_po VARCHAR2(1); -- Bug 1887728
5237
5238 CURSOR shipments(
5239 v_po_line_id NUMBER,
5240 v_po_line_location_id NUMBER,
5241 v_po_release_id NUMBER
5242 ) IS
5243 SELECT pll.line_location_id,
5244 NVL(pll.promised_date, pll.need_by_date) promised_date,
5245 pll.ship_to_organization_id,
5246 pll.amount amount_ordered,
5247 pll.amount_shipped ,
5248 pll.receipt_days_exception_code,
5249 pll.qty_rcv_tolerance,
5250 pll.qty_rcv_exception_code,
5251 pll.days_early_receipt_allowed,
5252 pll.days_late_receipt_allowed,
5253 pll.match_option,
5254 pl.job_id,
5255 pl.po_line_id,
5256 ph.currency_code,
5257 ph.rate_type,
5258 0 po_distribution_id,
5259 0 code_combination_id,
5260 0 req_distribution_id,
5261 0 deliver_to_location_id,
5262 0 deliver_to_person_id,
5263 ph.rate_date rate_date,
5264 ph.rate rate,
5265 '' destination_type_code,
5266 0 destination_organization_id,
5267 '' destination_subinventory,
5268 0 wip_entity_id,
5269 0 wip_operation_seq_num,
5270 0 wip_resource_seq_num,
5271 0 wip_repetitive_schedule_id,
5272 0 wip_line_id,
5273 0 bom_resource_id,
5274 '' ussgl_transaction_code,
5275 pll.ship_to_location_id,
5276 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
5277 pl.item_id
5278 FROM po_line_locations pll,
5279 po_lines pl,
5280 po_headers ph
5281 WHERE pl.po_line_id = v_po_line_id
5282 AND pll.po_line_id = v_po_line_id
5283 AND ph.po_header_id = pl.po_header_id
5284 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
5285 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
5286 AND NVL(pll.approved_flag, 'N') = 'Y'
5287 AND NVL(pll.cancel_flag, 'N') = 'N'
5288 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
5289 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
5290 OR ( NVL(x_include_closed_po, 'N') = 'N'
5291 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
5292 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
5293 ORDER BY NVL(pll.promised_date, pll.need_by_date);
5294
5295 CURSOR count_shipments(
5296 v_po_line_id NUMBER,
5297 v_po_line_location_id NUMBER,
5298 v_po_release_id NUMBER
5299 ) IS
5300 SELECT COUNT(*)
5301 FROM po_line_locations pll,
5302 po_lines pl,
5303 po_headers ph
5304 WHERE pl.po_line_id = v_po_line_id
5305 AND pll.po_line_id = v_po_line_id
5306 AND ph.po_header_id = pl.po_header_id
5307 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
5308 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
5309 AND NVL(pll.approved_flag, 'N') = 'Y'
5310 AND NVL(pll.cancel_flag, 'N') = 'N'
5311 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
5312 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
5313 OR ( NVL(x_include_closed_po, 'N') = 'N'
5314 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
5315 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT');
5316
5317 CURSOR distributions(
5318 v_po_line_id NUMBER,
5319 v_po_line_location_id NUMBER,
5320 v_po_distribution_id NUMBER,
5321 v_po_release_id NUMBER
5322 ) IS
5323 SELECT pll.line_location_id,
5324 NVL(pll.promised_date, pll.need_by_date) promised_date,
5325 pll.ship_to_organization_id,
5326 pll.amount amount_ordered,
5327 pll.amount_shipped,
5328 pll.receipt_days_exception_code,
5329 pll.qty_rcv_tolerance,
5330 pll.qty_rcv_exception_code,
5331 pll.days_early_receipt_allowed,
5332 pll.days_late_receipt_allowed,
5333 pll.match_option,
5334 pl.job_id,
5335 pl.po_line_id,
5336 ph.currency_code,
5337 ph.rate_type,
5338 pod.po_distribution_id,
5339 pod.code_combination_id,
5340 pod.req_distribution_id,
5341 pod.deliver_to_location_id,
5342 pod.deliver_to_person_id,
5343 pod.rate_date,
5344 pod.rate,
5345 pod.destination_type_code,
5346 pod.destination_organization_id,
5347 pod.destination_subinventory,
5348 pod.wip_entity_id,
5349 pod.wip_operation_seq_num,
5350 pod.wip_resource_seq_num,
5351 pod.wip_repetitive_schedule_id,
5352 pod.wip_line_id,
5353 pod.bom_resource_id,
5354 pod.ussgl_transaction_code,
5355 pll.ship_to_location_id,
5356 NVL(pll.enforce_ship_to_location_code, 'NONE') enforce_ship_to_location_code,
5357 pl.item_id
5358 FROM po_distributions pod,
5359 po_line_locations pll,
5360 po_lines pl,
5361 po_headers ph
5362 WHERE pl.po_line_id = v_po_line_id
5363 AND pll.po_line_id = v_po_line_id
5364 AND ph.po_header_id = pl.po_header_id
5365 AND pod.line_location_id = pll.line_location_id
5366 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
5367 AND pod.po_distribution_id = NVL(v_po_distribution_id, pod.po_distribution_id)
5368 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
5369 AND NVL(pll.approved_flag, 'N') = 'Y'
5370 AND NVL(pll.cancel_flag, 'N') = 'N'
5371 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
5372 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
5373 OR ( NVL(x_include_closed_po, 'N') = 'N'
5374 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
5375 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT')
5376 ORDER BY NVL(pll.promised_date, pll.need_by_date);
5377
5378 CURSOR count_distributions(
5379 v_po_line_id NUMBER,
5380 v_po_line_location_id NUMBER,
5381 v_po_distribution_id NUMBER,
5382 v_po_release_id NUMBER
5383 ) IS
5384 SELECT COUNT(*)
5385 FROM po_distributions pod,
5386 po_line_locations pll,
5387 po_lines pl,
5388 po_headers ph
5389 WHERE pl.po_line_id = v_po_line_id
5390 AND pll.po_line_id = v_po_line_id
5391 AND ph.po_header_id = pl.po_header_id
5392 AND pod.line_location_id = pll.line_location_id
5393 AND pll.line_location_id = NVL(v_po_line_location_id, pll.line_location_id)
5394 AND pod.po_distribution_id = NVL(v_po_distribution_id, pod.po_distribution_id)
5395 AND NVL(pll.po_release_id, 0) = NVL(v_po_release_id, NVL(pll.po_release_id, 0))
5396 AND NVL(pll.approved_flag, 'N') = 'Y'
5397 AND NVL(pll.cancel_flag, 'N') = 'N'
5398 AND ( ( NVL(x_include_closed_po, 'N') = 'Y'
5399 AND NVL(pll.closed_code, 'OPEN') <> 'FINALLY CLOSED')
5400 OR ( NVL(x_include_closed_po, 'N') = 'N'
5401 AND (NVL(pll.closed_code, 'OPEN') NOT IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING'))))
5402 AND pll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT');
5403
5404 /*
5405 ** Debug: had to change this to the distribution record
5406 ** Might be a compatibility issue between the two record definitions
5407 */
5408 x_shipmentdistributionrec distributions%ROWTYPE;
5409 x_record_count NUMBER;
5410 x_remaining_amount NUMBER := 0;
5411 x_progress VARCHAR2(3);
5412 x_to_organization_code VARCHAR2(5);
5413 x_converted_trx_amt NUMBER := 0;
5414 transaction_ok BOOLEAN := FALSE;
5415 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
5416 high_range_date DATE;
5417 low_range_date DATE;
5418 rows_fetched NUMBER := 0;
5419 x_tolerable_amt NUMBER := 0;
5420 x_first_trans BOOLEAN := TRUE;
5421 x_sysdate DATE := SYSDATE;
5422 current_n BINARY_INTEGER := 0;
5423 insert_into_table BOOLEAN := FALSE;
5424 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
5425 tax_amount_factor NUMBER;
5426 lastrecord BOOLEAN := FALSE;
5427 already_allocated_amt NUMBER := 0;
5428 x_release_id NUMBER;
5429 x_approved_flag VARCHAR(1);
5430 x_cancel_flag VARCHAR(1);
5431 x_closed_code VARCHAR(25);
5432 x_shipment_type VARCHAR(25);
5433 x_temp_count NUMBER;
5434 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
5435 profile_user_id NUMBER := -1;
5436 profile_appl_id NUMBER := -1;
5437 profile_resp_id NUMBER := -1;
5438 defined BOOLEAN;
5439 x_sob_id NUMBER := NULL;
5440 x_rate NUMBER;
5441 x_allow_rate_override VARCHAR2(1);
5442 l_time_count NUMBER;
5443 l_dist_count number; /* Bug#3746516 */
5444 l_rate_date po_headers.rate_date%type; /* Bug#3746516 */
5445 BEGIN
5446 --check line quanity > 0
5447 x_progress := '097';
5448
5449 IF (g_asn_debug = 'Y') THEN
5450 asn_debug.put_line('derive_vendor_rcv_line_amt ' || x_progress);
5451 END IF;
5452
5453 profile_user_id := fnd_profile.VALUE('USER_ID');
5454 profile_resp_id := fnd_profile.VALUE('RESPONSIBILITY_ID');
5455 profile_appl_id := fnd_profile.VALUE('APPLICATION_ID');
5456 fnd_profile.get_specific('RCV_CLOSED_PO_DEFAULT_OPTION',
5457 profile_user_id,
5458 profile_resp_id,
5459 profile_appl_id,
5460 x_include_closed_po,
5461 defined
5462 );
5463
5464 IF (g_asn_debug = 'Y') THEN
5465 asn_debug.put_line('Include closed PO profile value ' || x_include_closed_po);
5466 END IF;
5467
5468 /* We do not support ASN/ASBN for Serive based PO shipments. So
5469 * error out in that case.
5470 */
5471 /* Complex Work project*/
5472 IF ((x_cascaded_table(n).transaction_type = 'SHIP') and
5473 (x_header_record.header_record.asn_type <> 'WC' )) THEN --{
5474 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5475 rcv_error_pkg.set_error_message('RCV_NO_SERVICE_SUPPORT_TRX', x_cascaded_table(n).error_message);
5476 rcv_error_pkg.set_token('TRX_TYPE', x_cascaded_table(n).transaction_type);
5477 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
5478 END IF; --}
5479
5480 /* Support for RATE based from OTL */
5481 IF ( x_cascaded_table(n).value_basis = 'RATE'
5482 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR') THEN --{
5483 IF (g_asn_debug = 'Y') THEN
5484 asn_debug.put_line('Rate/Temp Labor');
5485 END IF;
5486
5487 /* Bug 3648861.
5488 * The where condition has
5489 * and pol.po_line_id=po_line_id.
5490 * It should be
5491 * and pol.po_line_id=x_cascaded_table(n).po_line_id
5492 * Changed the condition.
5493 */
5494 SELECT COUNT(*)
5495 INTO l_time_count
5496 FROM hxc_time_building_blocks bb,
5497 po_lines pol
5498 WHERE bb.time_building_block_id = x_cascaded_table(n).timecard_id
5499 AND bb.object_version_number = x_cascaded_table(n).timecard_ovn
5500 AND bb.SCOPE = 'TIMECARD'
5501 AND bb.resource_type = 'PERSON'
5502 AND bb.resource_id IN(SELECT person_id
5503 FROM per_all_assignments_f
5504 WHERE assignment_type = 'C')
5505 AND pol.po_line_id = x_cascaded_table(n).po_line_id
5506 AND pol.order_type_lookup_code = 'RATE'
5507 AND pol.purchase_basis = 'TEMP LABOR';
5508
5509 IF (g_asn_debug = 'Y') THEN
5510 asn_debug.put_line('count ' || l_time_count);
5511 END IF;
5512
5513 IF (l_time_count = 0) THEN --{
5514 IF (g_asn_debug = 'Y') THEN
5515 asn_debug.put_line('We do not support RATE/TEMP LABOR through ROI unless it comes through OTL');
5516 END IF;
5517
5518 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5519 rcv_error_pkg.set_error_message('RCV_NO_RATE_UNLESS_OTL', x_cascaded_table(n).error_message);
5520 rcv_error_pkg.set_token('TRX_TYPE', x_cascaded_table(n).transaction_type);
5521 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
5522 END IF; --}
5523 END IF; --}
5524
5525 /* Bug 6610047.
5526 * Changes made to allow receipts with zero amount for timecards
5527 * by commenting the validation to check for zero amount on the
5528 * receipt.
5529 */
5530
5531
5532 /* IF x_cascaded_table(n).error_status IN('S', 'W')
5533 AND x_cascaded_table(n).amount <= 0 THEN --{
5534 IF (g_asn_debug = 'Y') THEN
5535 asn_debug.put_line('Amount is <= zero. Cascade will fail');
5536 END IF;
5537
5538 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5539 rcv_error_pkg.set_error_message('RCV_ITEM_NO_SHIP_QTY', x_cascaded_table(n).error_message);
5540 rcv_error_pkg.set_token('ITEM', x_cascaded_table(n).item_num);
5541 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
5542 END IF; --} end amt > 0 check
5543 */
5544 -- the following steps will create a set of rows linking the line_record with
5545 -- its corresponding po_line_location rows until the quantity value from
5546 -- the asn is consumed. (Cascade)
5547
5548 /* 2119137 : If the user populates rcv_transactions_interface
5549 with po_line_id, then ROI errors out with
5550 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
5551 is not provided for one time items. Modified the "if" criteria in
5552 such a way that the ROI validation does'nt error out when
5553 po_line_id is populated for one time items. */
5554 x_progress := '098';
5555
5556 IF (g_asn_debug = 'Y') THEN
5557 asn_debug.put_line('X_progress ' || x_progress);
5558 END IF;
5559
5560 IF ( x_cascaded_table(n).po_line_id IS NOT NULL
5561 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
5562
5563 -- Copy record from main table to temp table
5564 IF (g_asn_debug = 'Y') THEN
5565 asn_debug.put_line('Copy record from main table to temp table');
5566 END IF;
5567
5568 current_n := 1;
5569 temp_cascaded_table(current_n) := x_cascaded_table(n);
5570
5571 -- Get all rows which meet this condition
5572 IF (g_asn_debug = 'Y') THEN
5573 asn_debug.put_line('Get all rows which meet this condition');
5574 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
5575 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
5576 END IF;
5577
5578 -- bug 1362237 Deriving the document_line_num
5579 -- and document_shipment_line_num when line_id and/or line_location_id
5580 -- are provided.
5581
5582 IF temp_cascaded_table(current_n).document_line_num IS NULL
5583 AND temp_cascaded_table(current_n).po_line_id IS NOT NULL THEN --{
5584 BEGIN
5585 SELECT line_num
5586 INTO temp_cascaded_table(current_n).document_line_num
5587 FROM po_lines
5588 WHERE po_line_id = temp_cascaded_table(current_n).po_line_id;
5589 EXCEPTION
5590 WHEN OTHERS THEN
5591 IF (g_asn_debug = 'Y') THEN
5592 asn_debug.put_line('wrong po_line_id entered in rcv_transactions_interface');
5593 END IF;
5594 END;
5595 END IF; --}
5596
5597 IF temp_cascaded_table(current_n).document_shipment_line_num IS NULL
5598 AND temp_cascaded_table(current_n).po_line_location_id IS NOT NULL THEN --{
5599 BEGIN
5600 SELECT shipment_num
5601 INTO temp_cascaded_table(current_n).document_shipment_line_num
5602 FROM po_line_locations
5603 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
5604 EXCEPTION
5605 WHEN OTHERS THEN
5606 IF (g_asn_debug = 'Y') THEN
5607 asn_debug.put_line('wrong po_line_location_id entered in rcv_transactions_interface');
5608 END IF;
5609 END;
5610 END IF; --}
5611
5612 IF temp_cascaded_table(current_n).document_distribution_num IS NULL
5613 AND temp_cascaded_table(current_n).po_distribution_id IS NOT NULL THEN --{
5614 BEGIN
5615 SELECT distribution_num
5616 INTO temp_cascaded_table(current_n).document_distribution_num
5617 FROM po_distributions
5618 WHERE po_distribution_id = temp_cascaded_table(current_n).po_distribution_id;
5619 EXCEPTION
5620 WHEN OTHERS THEN
5621 IF (g_asn_debug = 'Y') THEN
5622 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
5623 END IF;
5624 END;
5625 END IF; --}
5626
5627 /* Bug 1898283 : The Receiving control of "Enforce Ship to Location was
5628 not working for ROI. So corrected the code so that it now behaves the same way as
5629 the Form Behaves. i.e.,
5630 Proceed without any error messages if the enforcement is set to "None"
5631 Enter error message in po_interface_errors if the enforcement is "Warning"
5632 Enter error message in po_interface_errors if the enforcement is "Reject"
5633 and error out.
5634 This validation is done by comparing the enforce_ship_location_code from
5635 po_line_locations and assigning the proper ship_location_id into a
5636 temporary variable temp_mirror_ship_to_loc_id and passing the temp
5637 variable as a parameter to open the cursor "Distributions".
5638 */
5639 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
5640 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
5641
5642 -- if txn != deliver
5643 IF (g_asn_debug = 'Y') THEN
5644 asn_debug.put_line('Open Shipment records');
5645 asn_debug.put_line('PO Header id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_id));
5646 asn_debug.put_line('Item Id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_location_id));
5647 asn_debug.put_line('Proceed to open cursor');
5648 END IF;
5649
5650 /* Bug 2208664 : Nullified the ship_to_location_id when calling
5651 the cursors shipments, count_shipments, distributions and
5652 count_distributions. The proper value of ship_to_location_id will
5653 be set after values are fetched and validated for the
5654 location control code set at PO.
5655 */
5656 OPEN shipments(temp_cascaded_table(current_n).po_line_id,
5657 temp_cascaded_table(current_n).po_line_location_id,
5658 temp_cascaded_table(current_n).po_release_id
5659 );
5660 -- count_shipments just gets the count of rows found in shipments
5661 OPEN count_shipments(temp_cascaded_table(current_n).po_line_id,
5662 temp_cascaded_table(current_n).po_line_location_id,
5663 temp_cascaded_table(current_n).po_release_id
5664 );
5665 -- }
5666 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
5667 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
5668 IF (g_asn_debug = 'Y') THEN
5669 asn_debug.put_line('Open Distribution records');
5670 asn_debug.put_line('PO Line id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_id));
5671 asn_debug.put_line('Line location Id ' || TO_CHAR(temp_cascaded_table(current_n).po_line_location_id));
5672 asn_debug.put_line('PO Distribution id ' || TO_CHAR(temp_cascaded_table(current_n).po_distribution_id));
5673 asn_debug.put_line('PO RElease id ' || TO_CHAR(temp_cascaded_table(current_n).po_release_id));
5674 asn_debug.put_line('Proceed to open cursor');
5675 END IF;
5676
5677 OPEN distributions(temp_cascaded_table(current_n).po_line_id,
5678 temp_cascaded_table(current_n).po_line_location_id,
5679 temp_cascaded_table(current_n).po_distribution_id,
5680 temp_cascaded_table(current_n).po_release_id
5681 );
5682 -- count_distributions just gets the count of rows found in distributions
5683 OPEN count_distributions(temp_cascaded_table(current_n).po_line_id,
5684 temp_cascaded_table(current_n).po_line_location_id,
5685 temp_cascaded_table(current_n).po_distribution_id,
5686 temp_cascaded_table(current_n).po_release_id
5687 );
5688 END IF; -- for txn = deliver --}
5689
5690
5691 -- Assign transaction amount to remaining amount
5692
5693 IF (g_asn_debug = 'Y') THEN
5694 asn_debug.put_line('Assign ordered_amount to remaining amount');
5695 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
5696 END IF;
5697
5698 x_remaining_amount := temp_cascaded_table(current_n).amount;
5699
5700 IF (g_asn_debug = 'Y') THEN
5701 asn_debug.put_line('Have assigned the amount ' || TO_CHAR(x_remaining_amount));
5702 END IF;
5703
5704 -- Calculate tax_amount_factor for calculating tax_amount for
5705 -- each cascaded line
5706 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
5707 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_amount;
5708 ELSE
5709 tax_amount_factor := 0;
5710 END IF;
5711
5712 IF (g_asn_debug = 'Y') THEN
5713 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
5714 END IF;
5715
5716 x_first_trans := TRUE;
5717 transaction_ok := FALSE;
5718
5719 /*
5720 ** Get the count of the number of records depending on the
5721 ** the transaction type
5722 */
5723 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
5724 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN
5725 FETCH count_shipments INTO x_record_count;
5726 ELSE
5727 FETCH count_distributions INTO x_record_count;
5728 END IF;
5729
5730 IF (g_asn_debug = 'Y') THEN
5731 asn_debug.put_line('Before starting Cascade');
5732 END IF;
5733
5734 IF (g_asn_debug = 'Y') THEN
5735 asn_debug.put_line('Record Count = ' || x_record_count);
5736 END IF;
5737
5738 asn_debug.put_line('record count ' || x_record_count);
5739
5740 LOOP --{
5741 IF (g_asn_debug = 'Y') THEN
5742 asn_debug.put_line('Remaining Amount ' || TO_CHAR(x_remaining_amount));
5743 END IF;
5744
5745 IF (g_asn_debug = 'Y') THEN
5746 asn_debug.put_line('open shipments and fetch');
5747 END IF;
5748
5749 /*
5750 ** Fetch the appropriate record
5751 */
5752 IF (g_asn_debug = 'Y') THEN
5753 asn_debug.put_line('transaction_type = ' || x_cascaded_table(n).transaction_type);
5754 END IF;
5755
5756 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
5757 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
5758 IF (g_asn_debug = 'Y') THEN
5759 asn_debug.put_line('Fetching Shipments Cursor');
5760 END IF;
5761
5762 FETCH shipments INTO x_shipmentdistributionrec;
5763
5764 /*
5765 ** Check if this is the last record
5766 */
5767 IF (shipments%NOTFOUND) THEN
5768 lastrecord := TRUE;
5769 END IF;
5770
5771 rows_fetched := shipments%ROWCOUNT;
5772
5773 IF (g_asn_debug = 'Y') THEN
5774 asn_debug.put_line('Shipment Rows fetched ' || TO_CHAR(rows_fetched));
5775 END IF;
5776 -- }
5777 ELSE -- txn = deliver and other cases --{
5778 IF (g_asn_debug = 'Y') THEN
5779 asn_debug.put_line('Fetching Distributions Cursor in amount proc');
5780 END IF;
5781
5782 FETCH distributions INTO x_shipmentdistributionrec;
5783
5784 /*
5785 ** Check if this is the last record
5786 */
5787 IF (distributions%NOTFOUND) THEN
5788 lastrecord := TRUE;
5789 END IF;
5790
5791 rows_fetched := distributions%ROWCOUNT;
5792
5793 IF (g_asn_debug = 'Y') THEN
5794 asn_debug.put_line('Distribution Rows fetched ' || TO_CHAR(rows_fetched));
5795 END IF;
5796 END IF; -- matches if condition of txn ! deliver --}
5797
5798 IF ( lastrecord
5799 OR x_remaining_amount <= 0) THEN --{
5800 IF (g_asn_debug = 'Y') THEN
5801 asn_debug.put_line('Hit exit condition');
5802 END IF;
5803
5804 IF NOT x_first_trans THEN
5805 -- x_first_trans has been reset which means some cascade has
5806 -- happened. Otherwise current_n = 1
5807 current_n := current_n - 1;
5808 END IF;
5809
5810 -- do the tolerance act here
5811 IF (g_asn_debug = 'Y') THEN
5812 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
5813 asn_debug.put_line('Check which condition has occured');
5814 END IF;
5815
5816 -- lastrecord...we have run out of rows and we still have quantity to allocate
5817 IF x_remaining_amount > 0 THEN --{
5818 IF (g_asn_debug = 'Y') THEN
5819 asn_debug.put_line('There is amount remaining');
5820 asn_debug.put_line('Need to check qty/amt tolerances');
5821 END IF;
5822
5823 IF rows_fetched > 0
5824 AND NOT x_first_trans THEN --{
5825 -- we had got atleast some rows from our shipments cursor
5826 -- we have atleast one row cascaded (not null line_location_id)
5827 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
5828 INTO x_qty_rcv_exception_code
5829 FROM po_line_locations
5830 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
5831
5832 IF (g_asn_debug = 'Y') THEN
5833 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
5834 END IF;
5835
5836 IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
5837 /* Bug# 1807842 */
5838 -- Bug 3506964.
5839 IF (temp_cascaded_table(current_n).amount < x_converted_trx_amt) THEN --{
5840 IF (g_asn_debug = 'Y') THEN
5841 asn_debug.put_line('Tolerable amount ' || TO_CHAR(x_converted_trx_amt));
5842 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).amount));
5843 asn_debug.put_line('Current shipped amount ' || TO_CHAR(temp_cascaded_table(current_n).amount_shipped));
5844 asn_debug.put_line('Assign remaining amount ' || TO_CHAR(x_remaining_amount) || ' to last record');
5845 END IF;
5846
5847 temp_cascaded_table(current_n).amount := temp_cascaded_table(current_n).amount + x_remaining_amount;
5848 temp_cascaded_table(current_n).amount_shipped := temp_cascaded_table(current_n).amount_shipped + x_remaining_amount;
5849
5850 END IF; /* Bug# 1807842 */ --}
5851
5852 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).amount * tax_amount_factor, 6);
5853
5854 IF (g_asn_debug = 'Y') THEN
5855 asn_debug.put_line('Current amount ' || TO_CHAR(temp_cascaded_table(current_n).amount));
5856 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
5857 asn_debug.put_line('Current shipped amount ' || TO_CHAR(temp_cascaded_table(current_n).amount_shipped));
5858 END IF;
5859
5860 IF x_qty_rcv_exception_code = 'WARNING' THEN --{
5861 IF (g_asn_debug = 'Y') THEN
5862 asn_debug.put_line('IN WARNING');
5863 END IF;
5864
5865 temp_cascaded_table(current_n).error_status := 'W';
5866 temp_cascaded_table(current_n).error_message := 'RCV_SHIP_QTY_OVER_TOLERANCE';
5867
5868 IF (g_asn_debug = 'Y') THEN
5869 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
5870 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
5871 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
5872 END IF;
5873
5874 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
5875 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
5876 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
5877 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_amount);
5878 rcv_error_pkg.log_interface_warning('QUANTITY');
5879
5880 IF (g_asn_debug = 'Y') THEN
5881 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
5882 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
5883 asn_debug.put_line('Need to insert into po_interface_errors');
5884 END IF;
5885 END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
5886
5887 IF (g_asn_debug = 'Y') THEN
5888 asn_debug.put_line('Current amount ' || TO_CHAR(temp_cascaded_table(current_n).amount));
5889 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
5890 asn_debug.put_line('Current shipped amount ' || TO_CHAR(temp_cascaded_table(current_n).amount_shipped));
5891 END IF;
5892 -- }
5893 ELSIF x_qty_rcv_exception_code = 'REJECT' THEN -- elseif for NONE/WARNING --{
5894 IF (g_asn_debug = 'Y') THEN
5895 asn_debug.put_line('Extra Amount ' || TO_CHAR(x_remaining_amount));
5896 END IF;
5897
5898 IF (g_asn_debug = 'Y') THEN
5899 asn_debug.put_line('delete the temp table ');
5900 END IF;
5901
5902 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5903 rcv_error_pkg.set_error_message('RCV_SHIP_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
5904 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(n).amount);
5905 rcv_error_pkg.set_token('QTY_B', x_cascaded_table(n).amount - x_remaining_amount);
5906 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
5907 temp_cascaded_table.DELETE;
5908
5909 IF (g_asn_debug = 'Y') THEN
5910 asn_debug.put_line('mark the actual table with error status');
5911 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
5912 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
5913 END IF;
5914
5915 IF (g_asn_debug = 'Y') THEN
5916 asn_debug.put_line('Need to insert a row into po_interface_errors');
5917 END IF;
5918 END IF; --} matches if(none/warning) and elseif(reject)
5919 --}
5920 ELSE --{ else for rows fetched = 0 OR x_first_trans = true
5921 IF rows_fetched = 0 THEN
5922 IF (g_asn_debug = 'Y') THEN
5923 asn_debug.put_line('No rows were retrieved from cursor.');
5924 END IF;
5925 ELSIF x_first_trans THEN
5926 IF (g_asn_debug = 'Y') THEN
5927 asn_debug.put_line('No rows were cascaded');
5928 END IF;
5929 END IF;
5930
5931 x_temp_count := 1;
5932
5933 /* nwang add error messages */
5934 /* Bug 2340533 - Added a message RCV_ASN_NO_OPEN_SHIPMENTS which conveys that
5935 no shipments exists for receiving for the given PO.
5936 */
5937 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
5938 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
5939 -- Bug 2551443 Removed po_distributions from the FROM clause
5940 SELECT COUNT(*)
5941 INTO x_temp_count
5942 FROM DUAL
5943 WHERE EXISTS(SELECT 1
5944 FROM po_line_locations pll,
5945 po_lines pl
5946 WHERE pl.po_line_id = temp_cascaded_table(current_n).po_line_id
5947 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
5948 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
5949 AND pll.po_line_id = pl.po_line_id);
5950
5951 IF x_temp_count = 0 THEN
5952 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5953 rcv_error_pkg.set_error_message('RCV_ASN_NO_OPEN_SHIPMENTS', x_cascaded_table(n).error_message);
5954 rcv_error_pkg.set_token('PONUM', temp_cascaded_table(current_n).document_num);
5955 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
5956 ELSE -- x_temp_count != 0
5957 SELECT NVL(pll.po_release_id, 0),
5958 NVL(pll.approved_flag, 'N'),
5959 NVL(pll.cancel_flag, 'N'),
5960 NVL(pll.closed_code, 'OPEN'),
5961 pll.shipment_type
5962 INTO x_release_id,
5963 x_approved_flag,
5964 x_cancel_flag,
5965 x_closed_code,
5966 x_shipment_type
5967 FROM po_line_locations pll,
5968 po_lines pl,
5969 po_headers ph
5970 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
5971 AND pll.po_header_id = ph.po_header_id
5972 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
5973 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
5974 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
5975 AND pll.po_line_id = pl.po_line_id;
5976 END IF; -- x_temp_count = 0
5977 -- }
5978 ELSIF( x_cascaded_table(n).transaction_type = 'DELIVER'
5979 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
5980 SELECT COUNT(*)
5981 INTO x_temp_count
5982 FROM po_distributions pod,
5983 po_line_locations pll,
5984 po_lines pl,
5985 po_headers ph
5986 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
5987 AND pll.po_header_id = ph.po_header_id
5988 AND pll.line_location_id = pod.line_location_id
5989 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
5990 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
5991 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
5992 AND pll.po_line_id = pl.po_line_id
5993 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
5994
5995 IF x_temp_count = 0 THEN
5996 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
5997 rcv_error_pkg.set_error_message('RCV_ASN_INVALID_DIST_NUM', x_cascaded_table(n).error_message);
5998 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_distribution_num);
5999 rcv_error_pkg.log_interface_error('DOCUMENT_DISTRIBUTION_NUM', FALSE);
6000 ELSE -- x_temp_count != 0
6001 SELECT NVL(pll.po_release_id, 0),
6002 NVL(pll.approved_flag, 'N'),
6003 NVL(pll.cancel_flag, 'N'),
6004 NVL(pll.closed_code, 'OPEN'),
6005 pll.shipment_type
6006 INTO x_release_id,
6007 x_approved_flag,
6008 x_cancel_flag,
6009 x_closed_code,
6010 x_shipment_type
6011 FROM po_distributions pod,
6012 po_line_locations pll,
6013 po_lines pl,
6014 po_headers ph
6015 WHERE ph.po_header_id = temp_cascaded_table(current_n).po_header_id
6016 AND pll.po_header_id = ph.po_header_id
6017 AND pll.line_location_id = pod.line_location_id
6018 AND pl.line_num = NVL(temp_cascaded_table(current_n).document_line_num, pl.line_num)
6019 AND NVL(pll.po_release_id, 0) = NVL(temp_cascaded_table(current_n).po_release_id, NVL(pll.po_release_id, 0))
6020 AND pll.line_location_id = NVL(temp_cascaded_table(current_n).po_line_location_id, pll.line_location_id)
6021 AND pll.po_line_id = pl.po_line_id
6022 AND pod.distribution_num = NVL(temp_cascaded_table(current_n).document_distribution_num, pod.distribution_num);
6023 END IF; -- x_temp_count = 0;
6024 END IF; -- transaction_type <> 'DELIVER' --}
6025
6026 IF (x_temp_count <> 0) THEN --{
6027 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6028
6029 IF x_release_id <> NVL(temp_cascaded_table(current_n).po_release_id, x_release_id) THEN
6030 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6031 rcv_error_pkg.set_error_message('RCV_ASN_ITEM_NOT_ALLOWED', x_cascaded_table(n).error_message);
6032 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).item_num);
6033 rcv_error_pkg.log_interface_error('ITEM_NUM', FALSE);
6034 END IF;
6035
6036 IF x_approved_flag <> 'Y' THEN
6037 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6038 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_APPROVED', x_cascaded_table(n).error_message);
6039 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6040 rcv_error_pkg.set_token('PO_NUM', temp_cascaded_table(current_n).document_num);
6041 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6042 END IF;
6043
6044 IF x_cancel_flag <> 'N' THEN
6045 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6046 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_CANCELLED', x_cascaded_table(n).error_message);
6047 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6048 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6049 END IF;
6050
6051 IF ( x_include_closed_po = 'Y'
6052 AND x_closed_code = 'FINALLY CLOSED') THEN
6053 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6054 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_FINALLY_CLOSED', x_cascaded_table(n).error_message);
6055 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6056 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6057 END IF;
6058
6059 IF ( x_include_closed_po = 'N'
6060 AND x_closed_code IN('FINALLY CLOSED', 'CLOSED', 'CLOSED FOR RECEIVING')) THEN
6061 IF (g_asn_debug = 'Y') THEN
6062 asn_debug.put_line('This PO is not open and the profile option to include closed POs is N');
6063 END IF;
6064
6065 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6066 rcv_error_pkg.set_error_message('RCV_ASN_SHIPMT_NOT_OPEN', x_cascaded_table(n).error_message);
6067 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6068 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6069 END IF;
6070
6071 IF x_shipment_type NOT IN('STANDARD', 'BLANKET', 'SCHEDULED','PREPAYMENT') THEN
6072 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6073 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIPMT_TYPE', x_cascaded_table(n).error_message);
6074 rcv_error_pkg.set_token('NUMBER', temp_cascaded_table(current_n).document_shipment_line_num);
6075 rcv_error_pkg.log_interface_error('DOCUMENT_SHIPMENT_LINE_NUM', FALSE);
6076 END IF;
6077 END IF; -- x_temp_count = 0;}
6078
6079 -- Delete the temp_cascaded_table just to be sure
6080
6081 temp_cascaded_table.DELETE;
6082 END IF; --} end else for rows fetched = 0 OR x_first_trans = true
6083 -- end x_remaining_qty > 0 => this is the last record
6084 ELSE --
6085 IF (g_asn_debug = 'Y') THEN
6086 asn_debug.put_line('Remaining amount is zero ' || TO_CHAR(x_remaining_amount));
6087 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
6088 END IF;
6089 /* Bug 6610047.
6090 * To allow, receipts with zero amount for timecards from now on.
6091 * Added below code to populate certain data into temp_cascaded_table()
6092 * structure to make zero amount receipts flow to work.
6093 */
6094 IF (temp_cascaded_table(current_n).value_basis = 'RATE'
6095 AND temp_cascaded_table(current_n).purchase_basis = 'TEMP LABOR'
6096 AND temp_cascaded_table(current_n).amount = 0) THEN --{
6097
6098 IF (g_asn_debug = 'Y') THEN
6099 asn_debug.put_line('Rate/Temp Labor with amount = 0');
6100 END IF;
6101
6102 temp_cascaded_table(current_n).po_distribution_id := x_shipmentdistributionrec.po_distribution_id;
6103 temp_cascaded_table(current_n).charge_account_id := x_shipmentdistributionrec.code_combination_id;
6104 temp_cascaded_table(current_n).destination_type_code := x_shipmentdistributionrec.destination_type_code;
6105 temp_cascaded_table(current_n).destination_context := x_shipmentdistributionrec.destination_type_code;
6106
6107 IF (temp_cascaded_table(current_n).currency_conversion_date IS NULL) THEN
6108 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
6109 END IF;
6110
6111 IF (temp_cascaded_table(current_n).currency_conversion_rate IS NULL) THEN
6112 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
6113 END IF;
6114
6115 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
6116 temp_cascaded_table(current_n).deliver_to_location_id := x_shipmentdistributionrec.deliver_to_location_id;
6117 END IF;
6118
6119 END IF; /* Bug 6610047 - End */
6120
6121 END IF; --} ends the check for whether last record has been reached
6122
6123 -- close cursors
6124
6125 IF (g_asn_debug = 'Y') THEN
6126 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions');
6127 END IF;
6128
6129 IF shipments%ISOPEN THEN
6130 CLOSE shipments;
6131 END IF;
6132
6133 IF count_shipments%ISOPEN THEN
6134 CLOSE count_shipments;
6135 END IF;
6136
6137 IF distributions%ISOPEN THEN
6138 CLOSE distributions;
6139 END IF;
6140
6141 IF count_distributions%ISOPEN THEN
6142 CLOSE count_distributions;
6143 END IF;
6144
6145 EXIT;
6146 END IF; --} matches lastrecord or x_remaining_amount <= 0
6147
6148 -- eliminate the row if it fails the date check
6149
6150 IF (g_asn_debug = 'Y') THEN
6151 asn_debug.put_line('Count in temp_cascade_table : ' || TO_CHAR(temp_cascaded_table.COUNT));
6152 asn_debug.put_line('Cursor record ' || TO_CHAR(rows_fetched));
6153 asn_debug.put_line('Check date tolerance');
6154 END IF;
6155
6156 /* FPJ Services.
6157 * We do not check date_tolerances if matching_basis is
6158 * AMOUNT except when value basis is Fixed and
6159 * purchase basis is Service.
6160 * Bug 3570773. We did not have this check here but in
6161 * derive_vendor_rcv_line_qty. But it does not really matter since
6162 * we cannot set date tolerances for serive line types except
6163 * Fixed Price / Services.
6164 */
6165 IF ( NVL(x_cascaded_table(n).value_basis, 'QUANTITY') <> 'RATE'
6166 AND NVL(x_cascaded_table(n).purchase_basis, 'GOODS') <> 'TEMP_LABOR') THEN
6167 IF (g_asn_debug = 'Y') THEN
6168 asn_debug.put_line('Check date tolerance for a Fixed Price services line');
6169 END IF;
6170
6171 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
6172 x_shipmentdistributionrec.promised_date,
6173 x_shipmentdistributionrec.days_early_receipt_allowed,
6174 x_shipmentdistributionrec.days_late_receipt_allowed,
6175 x_shipmentdistributionrec.receipt_days_exception_code
6176 );
6177 ELSE
6178 -- default receipt_days_exception_code to NONE for rate based temp
6179 -- labor lines.
6180 x_shipmentdistributionrec.receipt_days_exception_code := 'NONE';
6181 END IF;
6182
6183 /* FPJ SERVICES END */
6184
6185 /* bug 1060261 - added error message to be shown when the expected date is outside tolerance range */
6186 IF (x_shipmentdistributionrec.receipt_days_exception_code = 'REJECT') THEN --{
6187 IF (g_asn_debug = 'Y') THEN
6188 asn_debug.put_line('Receipt days exception code is Reject. So error out.');
6189 END IF;
6190
6191 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6192 rcv_error_pkg.set_error_message('RCV_ASN_DATE_OUT_TOL', x_cascaded_table(n).error_message);
6193 rcv_error_pkg.set_token('DELIVERY DATE', NVL(temp_cascaded_table(1).expected_receipt_date, x_header_record.header_record.expected_receipt_date));
6194 rcv_error_pkg.log_interface_error('EXPECTED_RECEIPT_DATE', FALSE);
6195 END IF; --}
6196
6197 IF (g_asn_debug = 'Y') THEN
6198 asn_debug.put_line('Days exception Code ' || NVL(x_shipmentdistributionrec.receipt_days_exception_code, 'XXX'));
6199 END IF;
6200
6201 -- Check shipto_location enforcement
6202
6203 rcv_transactions_interface_sv.check_shipto_enforcement(x_shipmentdistributionrec.ship_to_location_id,
6204 NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id),
6205 x_shipmentdistributionrec.enforce_ship_to_location_code
6206 );
6207
6208 IF (g_asn_debug = 'Y') THEN
6209 asn_debug.put_line('Enforce ShipToLocation ' || NVL(x_shipmentdistributionrec.enforce_ship_to_location_code, 'XXX'));
6210 END IF;
6211
6212 /* Bug 2208664 : Enter error message in po_interface_errors if enforce_ship_to_location_code is 'WARNING', and
6213 Enter error message in po_interface_errors if enforce_ship_to_location_code is 'REJECT' and error out
6214 */
6215 IF (x_shipmentdistributionrec.enforce_ship_to_location_code = 'REJECT') THEN --{
6216 BEGIN
6217 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6218 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
6219 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
6220 rcv_error_pkg.log_interface_error('SHIP_TO_LOCATION_ID', FALSE);
6221 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
6222 END;
6223 ELSIF(x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING') THEN --} {
6224 BEGIN
6225 x_cascaded_table(n).error_status := 'W';
6226 rcv_error_pkg.set_error_message('RCV_ASN_INVAL_SHIP_TO_LOC', x_cascaded_table(n).error_message);
6227 rcv_error_pkg.set_token('VALUE', temp_cascaded_table(current_n).ship_to_location_id);
6228 rcv_error_pkg.log_interface_warning('SHIP_TO_LOCATION_ID');
6229 x_shipmentdistributionrec.ship_to_location_id := NVL(temp_cascaded_table(1).ship_to_location_id, x_header_record.header_record.location_id);
6230 END;
6231 END IF; --}matches ship_to_loc_code = warning
6232
6233 IF (NVL(x_shipmentdistributionrec.receipt_days_exception_code, 'NONE') = 'NONE')
6234 AND -- derived by the date tolerance procedure
6235 (x_shipmentdistributionrec.enforce_ship_to_location_code IN('NONE', 'WARNING')) THEN --{
6236 -- derived by shipto_enforcement
6237 insert_into_table := FALSE;
6238 already_allocated_amt := 0;
6239
6240 /*
6241 ** Get the available quantity for the shipment or distribution
6242 ** that is available for allocation by this interface transaction
6243 */
6244 IF ( x_cascaded_table(n).transaction_type <> 'DELIVER'
6245 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN --{
6246 /*Bug# 1548597 */
6247 IF (g_asn_debug = 'Y') THEN
6248 asn_debug.put_line('call get_available_amount for Receive');
6249 END IF;
6250
6251 rcv_quantities_s.get_available_amount('RECEIVE',
6252 x_shipmentdistributionrec.line_location_id,
6253 'VENDOR',
6254 NULL,
6255 NULL,
6256 NULL,
6257 x_converted_trx_amt,
6258 x_tolerable_amt
6259 );
6260
6261 -- If qtys have already been allocated for this po_line_location_id during
6262 -- a cascade process which has not been written to the db yet, we need to
6263 -- decrement it from the total available quantity
6264 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
6265 -- po_line_location_id
6266
6267 IF n > 1 THEN -- We will do this for all rows except the 1st
6268 FOR i IN 1 ..(n - 1) LOOP
6269 IF x_cascaded_table(i).po_line_location_id = x_shipmentdistributionrec.line_location_id THEN
6270 already_allocated_amt := already_allocated_amt + x_cascaded_table(i).amount;
6271 END IF;
6272 END LOOP;
6273 END IF;
6274 ELSE --} { for txn != deliver
6275 IF (g_asn_debug = 'Y') THEN
6276 asn_debug.put_line('call get_available_amount for Direct Delivery');
6277 END IF;
6278
6279 /* Bug# 1548597*/
6280 rcv_quantities_s.get_available_amount('DIRECT RECEIPT',
6281 x_shipmentdistributionrec.po_distribution_id,
6282 'VENDOR',
6283 NULL,
6284 NULL,
6285 NULL,
6286 x_converted_trx_amt,
6287 x_tolerable_amt
6288 );
6289
6290 /* Bug# 1337787 - Calculated the x_tolerable_qty in
6291 rcv_quantities_s.get_available_quantity procedure */
6292
6293 -- x_tolerable_qty := x_converted_trx_qty;
6294 -- If qtys have already been allocated for this po_distribution_id during
6295 -- a cascade process which has not been written to the db yet, we need to
6296 -- decrement it from the total available quantity
6297 -- We traverse the actual pl/sql table and accumulate the quantity by matching the
6298 -- po_distribution_id
6299
6300 IF n > 1 THEN -- We will do this for all rows except the 1st
6301 FOR i IN 1 ..(n - 1) LOOP
6302 IF x_cascaded_table(i).po_distribution_id = x_shipmentdistributionrec.po_distribution_id THEN
6303 already_allocated_amt := already_allocated_amt + x_cascaded_table(i).amount;
6304 END IF;
6305 END LOOP;
6306 END IF;
6307 END IF; --} for txn =deliver
6308
6309 IF (g_asn_debug = 'Y') THEN
6310 asn_debug.put_line('After call to get_available quantity');
6311 asn_debug.put_line('Available Amount ' || TO_CHAR(x_converted_trx_amt));
6312 asn_debug.put_line('Tolerable Amount ' || TO_CHAR(x_tolerable_amt));
6313 asn_debug.put_line('Already Shipped amount ' || TO_CHAR(NVL(x_shipmentdistributionrec.amount_shipped, 0)));
6314 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
6315 END IF;
6316
6317 -- if amt has already been allocated then reduce available and tolerable
6318 -- amt by the allocated amount
6319
6320 IF NVL(already_allocated_amt, 0) > 0 THEN --{
6321 x_converted_trx_amt := x_converted_trx_amt - already_allocated_amt;
6322 x_tolerable_amt := x_tolerable_amt - already_allocated_amt;
6323
6324 IF x_converted_trx_amt < 0 THEN
6325 x_converted_trx_amt := 0;
6326 END IF;
6327
6328 IF x_tolerable_amt < 0 THEN
6329 x_tolerable_amt := 0;
6330 END IF;
6331
6332 IF (g_asn_debug = 'Y') THEN
6333 asn_debug.put_line('Have some allocated amount. Will reduce amt');
6334 asn_debug.put_line('Allocated Amt ' || TO_CHAR(already_allocated_amt));
6335 asn_debug.put_line('After reducing by allocated amt');
6336 asn_debug.put_line('Available Amount ' || TO_CHAR(x_converted_trx_amt));
6337 asn_debug.put_line('Tolerable Amount ' || TO_CHAR(x_tolerable_amt));
6338 asn_debug.put_line('Already Shipped amount ' || TO_CHAR(NVL(x_shipmentdistributionrec.amount_shipped, 0)));
6339 asn_debug.put_line('Pointer to temp table ' || TO_CHAR(current_n));
6340 END IF;
6341 END IF; --}
6342
6343 -- If last row set available = tolerable - shipped
6344 -- else = available - shipped
6345
6346 IF rows_fetched = x_record_count THEN --{
6347 x_converted_trx_amt := x_tolerable_amt;
6348 x_converted_trx_amt := x_tolerable_amt - NVL(x_shipmentdistributionrec.amount_shipped, 0);
6349
6350 IF (g_asn_debug = 'Y') THEN
6351 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_trx_amt));
6352 END IF;
6353 ELSE --} {
6354 IF (g_asn_debug = 'Y') THEN
6355 x_converted_trx_amt := x_converted_trx_amt - NVL(x_shipmentdistributionrec.amount_shipped, 0);
6356 asn_debug.put_line('Not Last Row : ' || TO_CHAR(x_converted_trx_amt));
6357 END IF;
6358 END IF; --}
6359
6360 IF x_converted_trx_amt > 0 THEN --{
6361 IF (x_converted_trx_amt < x_remaining_amount) THEN -- compare like uoms {
6362 IF (g_asn_debug = 'Y') THEN
6363 asn_debug.put_line('We are in > amt branch');
6364 END IF;
6365
6366 x_remaining_amount := x_remaining_amount - x_converted_trx_amt;
6367 insert_into_table := TRUE;
6368 ELSE --} {
6369 IF (g_asn_debug = 'Y') THEN
6370 asn_debug.put_line('We are in <= amt branch ');
6371 END IF;
6372
6373 x_converted_trx_amt := x_remaining_amount;
6374 insert_into_table := TRUE;
6375 x_remaining_amount := 0;
6376 END IF; --}
6377 ELSE -- no amt for this record but if last row we need it } {
6378 IF rows_fetched = x_record_count THEN --{ last row needs to be inserted anyway
6379 -- so that the row can be used based on qty tolerance checks
6380 IF (g_asn_debug = 'Y') THEN
6381 asn_debug.put_line('Amount is less then 0 but last record');
6382 END IF;
6383
6384 insert_into_table := TRUE;
6385 x_converted_trx_amt := 0;
6386 ELSE --} {
6387 IF (g_asn_debug = 'Y') THEN
6388 asn_debug.put_line('<= 0 amount but more records in cursor');
6389 END IF;
6390
6391 x_remaining_amount := 0;
6392
6393 IF (g_asn_debug = 'Y') THEN
6394 asn_debug.put_line('We have to deal with remaining_qty > 0 and x_converted_trx_qty -ve');
6395 END IF;
6396
6397 insert_into_table := FALSE;
6398 END IF; --}
6399 END IF; --} remaining_amount <> 0
6400
6401 IF insert_into_table THEN --{
6402 IF (x_first_trans) THEN --{
6403 IF (g_asn_debug = 'Y') THEN
6404 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
6405 END IF;
6406
6407 x_first_trans := FALSE;
6408 ELSE --} { ! x_first_trans
6409 IF (g_asn_debug = 'Y') THEN
6410 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
6411 END IF;
6412
6413 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
6414 END IF; --} matches x_first_transfer
6415
6416 temp_cascaded_table(current_n).amount_shipped := temp_cascaded_table(current_n).amount;
6417 temp_cascaded_table(current_n).inspection_status_code := 'NOT INSPECTED';
6418 temp_cascaded_table(current_n).interface_source_code := 'RCV';
6419 temp_cascaded_table(current_n).currency_code := x_shipmentdistributionrec.currency_code;
6420 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).amount * tax_amount_factor, 6);
6421
6422 IF (g_asn_debug = 'Y') THEN
6423 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
6424 END IF;
6425
6426 IF temp_cascaded_table(current_n).to_organization_id IS NULL THEN --{
6427 temp_cascaded_table(current_n).to_organization_id := x_shipmentdistributionrec.ship_to_organization_id;
6428 END IF; --}
6429
6430 temp_cascaded_table(current_n).po_line_id := x_shipmentdistributionrec.po_line_id;
6431 temp_cascaded_table(current_n).po_line_location_id := x_shipmentdistributionrec.line_location_id;
6432
6433 IF x_shipmentdistributionrec.enforce_ship_to_location_code = 'WARNING' THEN --{
6434 IF (g_asn_debug = 'Y') THEN
6435 asn_debug.put_line('Message to warn about different shiptolocations');
6436 END IF;
6437 END IF; --}
6438
6439 /* ksareddy - 2329928 Ported changes by bao in branch to cache set_of_books_id */
6440 IF (rcv_transactions_interface_sv.x_set_of_books_id IS NULL) THEN
6441 SELECT set_of_books_id
6442 INTO rcv_transactions_interface_sv.x_set_of_books_id
6443 FROM financials_system_parameters;
6444 END IF;
6445
6446 x_sob_id := rcv_transactions_interface_sv.x_set_of_books_id;
6447 /* Bug 1845702
6448 * Currency rate and date can be changed at the time of receipt
6449 * depending on the profile ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE.
6450 * This was not handled in the open interface. Introduced code
6451 * to handle the changes at the time of receipt
6452 */
6453 /* Bug#3746516 Added the following if condition so as to get the value of the profile
6454 ** option only when the match option is receipt and thus to avoid executing the below
6455 ** function call always.
6456 */
6457 IF (x_ShipmentDistributionRec.match_option = 'R') THEN
6458 x_allow_rate_override := NVL(fnd_profile.value('ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE'), 'N');
6459 END IF;
6460
6461 IF (g_asn_debug = 'Y') THEN
6462 asn_debug.put_line('Match Option:' || x_ShipmentDistributionRec.match_option ||
6463 'Profile value ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE:' ||
6464 x_allow_rate_override);
6465 END IF;
6466
6467 /* Bug#3746516 - START
6468 ** Modified the following code to consider all the possble scenarios such that the
6469 ** rate and the rate date values will be derived correctly and the correct rate and
6470 ** rate date values will now be posted in rcv_transactions table so that there will
6471 ** not be any discrepency in the calculations and hence all the data between the two
6472 ** tables rcv_transactions and rcv_receiving_sub_ledger will be in sync.
6473 ** Assuming that only Direct delivery of Amount Based lines are possible and
6474 ** x_ShipmentDistributionRec would thus have only distribution information. */
6475
6476 IF (x_ShipmentDistributionRec.match_option = 'P') THEN --{
6477
6478 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
6479 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
6480
6481 ELSIF (x_ShipmentDistributionRec.match_option = 'R') THEN
6482
6483 IF (x_ShipmentDistributionRec.rate_type = 'User') THEN --{
6484
6485 IF ( x_allow_rate_override ='N') THEN --{
6486
6487 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
6488 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
6489
6490 ELSIF ( x_allow_rate_override ='Y') THEN
6491
6492 temp_cascaded_table(current_n).currency_conversion_date :=
6493 nvl(temp_cascaded_table(current_n).currency_conversion_date,x_ShipmentDistributionRec.rate_date);
6494 temp_cascaded_table(current_n).currency_conversion_rate :=
6495 nvl(temp_cascaded_table(current_n).currency_conversion_rate,x_ShipmentDistributionRec.rate);
6496 END IF; --}
6497
6498 ELSE
6499
6500 IF ( temp_cascaded_table(current_n).currency_conversion_date IS NOT NULL ) THEN --{
6501
6502 x_rate := gl_currency_api.get_rate(x_sob_Id,
6503 x_ShipmentDistributionRec.currency_code,
6504 temp_cascaded_table(current_n).currency_conversion_date,
6505 x_ShipmentDistributionRec.rate_type);
6506 x_rate := round(x_rate,28);
6507 temp_cascaded_table(current_n).currency_conversion_rate := x_rate;
6508
6509 ELSE
6510
6511 temp_cascaded_table(current_n).currency_conversion_rate := x_ShipmentDistributionRec.rate;
6512 temp_cascaded_table(current_n).currency_conversion_date := x_ShipmentDistributionRec.rate_date;
6513
6514 END IF; --}
6515
6516 END IF; --}
6517
6518 END IF; --}
6519
6520 temp_cascaded_table(current_n).currency_conversion_type := x_ShipmentDistributionRec.rate_type;
6521
6522 IF (g_asn_debug = 'Y') THEN
6523 asn_debug.put_line('Rate, Rate type and Rate_date ::' ||
6524 temp_cascaded_table(current_n).currency_conversion_rate ||
6525 '::' || temp_cascaded_table(current_n).currency_conversion_type ||
6526 '::' || temp_cascaded_table(current_n).currency_conversion_date);
6527 END IF;
6528
6529 /* Bug#3746516 - END */
6530
6531 -- Copy the distribution specific information only if this is a direct receipt.
6532
6533 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
6534 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN --{
6535 temp_cascaded_table(current_n).po_distribution_id := x_shipmentdistributionrec.po_distribution_id;
6536 temp_cascaded_table(current_n).charge_account_id := x_shipmentdistributionrec.code_combination_id;
6537 temp_cascaded_table(current_n).req_distribution_id := x_shipmentdistributionrec.req_distribution_id;
6538 temp_cascaded_table(current_n).destination_type_code := x_shipmentdistributionrec.destination_type_code;
6539 temp_cascaded_table(current_n).destination_context := x_shipmentdistributionrec.destination_type_code;
6540
6541 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
6542 temp_cascaded_table(current_n).deliver_to_location_id := x_shipmentdistributionrec.deliver_to_location_id;
6543 END IF;
6544
6545 /* Bug 2392074 - If the deliver_to_person mentioned in the po_distributions is
6546 invalid or inactive at the time of Receipt we need to clear the deliver to person,
6547 as this is an optional field. */
6548 IF (NVL(temp_cascaded_table(current_n).deliver_to_person_id, 0) = 0) THEN --{
6549 temp_cascaded_table(current_n).deliver_to_person_id := x_shipmentdistributionrec.deliver_to_person_id;
6550
6551 IF (temp_cascaded_table(current_n).deliver_to_person_id IS NOT NULL) THEN --{
6552 BEGIN
6553 SELECT NVL(MAX(hre.full_name), 'notfound')
6554 INTO x_full_name
6555 FROM hr_employees_current_v hre
6556 WHERE ( hre.inactive_date IS NULL
6557 OR hre.inactive_date > SYSDATE)
6558 AND hre.employee_id = temp_cascaded_table(current_n).deliver_to_person_id;
6559
6560 IF (x_full_name = 'notfound') THEN
6561 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
6562 END IF;
6563 EXCEPTION
6564 WHEN NO_DATA_FOUND THEN
6565 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
6566
6567 IF (g_asn_debug = 'Y') THEN
6568 asn_debug.put_line('The deliver to person entered in PO is currently inactive');
6569 asn_debug.put_line(' So it is cleared off');
6570 END IF;
6571 WHEN OTHERS THEN
6572 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
6573
6574 IF (g_asn_debug = 'Y') THEN
6575 asn_debug.put_line('Some exception has occured');
6576 asn_debug.put_line('This exception is due to the PO deliver to person');
6577 asn_debug.put_line('The deliver to person is optional');
6578 asn_debug.put_line('So cleared off the deliver to person');
6579 END IF;
6580 END;
6581 END IF; --}
6582 END IF; --}
6583
6584 -- bug 1361786
6585
6586 IF (temp_cascaded_table(current_n).ussgl_transaction_code IS NULL) THEN
6587 temp_cascaded_table(current_n).ussgl_transaction_code := x_shipmentdistributionrec.ussgl_transaction_code;
6588 END IF;
6589 END IF; --} matches txn != deliver
6590
6591 current_n := current_n + 1;
6592
6593 IF (g_asn_debug = 'Y') THEN
6594 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
6595 END IF;
6596 END IF; --} matches if insert into table
6597 END IF; --} matches shipmentdistributionrec.receipt_days_exception_code = none
6598 END LOOP; --}
6599 ELSE --} {
6600 -- error_status and error_message are set after validate_quantity_shipped
6601 IF (g_asn_debug = 'Y') THEN
6602 asn_debug.put_line('No po_header_id/item_id ');
6603 END IF;
6604
6605 IF (g_asn_debug = 'Y') THEN
6606 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
6607 END IF;
6608
6609 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
6610 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
6611 rcv_error_pkg.set_error_message('RCV_ASN_NO_PO_LINE_LOCATION_ID', x_cascaded_table(n).error_message);
6612 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
6613 END IF; --}
6614
6615 RETURN;
6616 END IF; -- } of (asn quantity_shipped was valid)
6617
6618 IF shipments%ISOPEN THEN
6619 CLOSE shipments;
6620 END IF;
6621
6622 IF count_shipments%ISOPEN THEN
6623 CLOSE count_shipments;
6624 END IF;
6625
6626 IF distributions%ISOPEN THEN
6627 CLOSE distributions;
6628 END IF;
6629
6630 IF count_distributions%ISOPEN THEN
6631 CLOSE count_distributions;
6632 END IF;
6633
6634 IF (g_asn_debug = 'Y') THEN
6635 asn_debug.put_line('Exit derive_vendor_rcv_line_amt');
6636 END IF;
6637 EXCEPTION
6638 WHEN OTHERS THEN
6639 IF (g_asn_debug = 'Y') THEN
6640 asn_debug.put_line('Exception in derive_vendor_rcv_line_amt');
6641 END IF;
6642
6643 IF shipments%ISOPEN THEN
6644 CLOSE shipments;
6645 END IF;
6646
6647 IF count_shipments%ISOPEN THEN
6648 CLOSE count_shipments;
6649 END IF;
6650
6651 IF distributions%ISOPEN THEN
6652 CLOSE distributions;
6653 END IF;
6654
6655 IF count_distributions%ISOPEN THEN
6656 CLOSE count_distributions;
6657 END IF;
6658
6659 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
6660 rcv_error_pkg.set_sql_error_message('derive_vendor_rcv_line_qty', x_progress);
6661 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
6662 rcv_error_pkg.log_interface_error('DOCUMENT_NUM', FALSE);
6663
6664 IF (g_asn_debug = 'Y') THEN
6665 asn_debug.put_line(TO_CHAR(n));
6666 asn_debug.put_line(SQLERRM);
6667 asn_debug.put_line('error ' || x_progress);
6668 END IF;
6669 END derive_vendor_rcv_line_amt;
6670
6671 PROCEDURE validate_transaction_date(
6672 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
6673 n IN BINARY_INTEGER
6674 ) IS
6675 x_val_open_ok BOOLEAN := NULL;
6676 x_sob_id NUMBER := NULL;
6677 x_error_status VARCHAR2(1);
6678 BEGIN
6679 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
6680 RETURN;
6681 END IF;
6682
6683 x_error_status := rcv_error_pkg.g_ret_sts_error;
6684
6685 /*Bug 2327318 Implemented the validation Transaction date should not be greater than
6686 sysdate */
6687 IF (x_cascaded_table(n).transaction_date > SYSDATE) THEN
6688 rcv_error_pkg.set_error_message('RCV_TRX_FUTURE_DATE_NA');
6689 RAISE e_validation_error;
6690 END IF;
6691
6692 /* Bug 2653229 - To check if the transaction date falls in the open period only
6693 when the auto transact code is not SHIP. */
6694 IF (x_cascaded_table(n).auto_transact_code <> 'SHIP') THEN --{
6695 /* Bug# 2379848 - We were only checking for GL and PO periods
6696 and not for INV periods. Also we were displaying the same
6697 error message always */
6698 BEGIN
6699 SELECT set_of_books_id
6700 INTO x_sob_id
6701 FROM financials_system_parameters;
6702 EXCEPTION
6703 WHEN NO_DATA_FOUND THEN
6704 NULL;
6705
6706 IF (g_asn_debug = 'Y') THEN
6707 asn_debug.put_line('Set of books id not defined');
6708 END IF;
6709 END;
6710
6711 BEGIN
6712 x_val_open_ok := po_dates_s.val_open_period(x_cascaded_table(n).transaction_date,
6713 x_sob_id,
6714 'SQLGL',
6715 x_cascaded_table(n).to_organization_id
6716 );
6717 EXCEPTION
6718 WHEN OTHERS THEN
6719 IF (g_asn_debug = 'Y') THEN
6720 asn_debug.put_line('Exception in val_open_period');
6721 END IF;
6722
6723 x_val_open_ok := FALSE;
6724 END;
6725
6726 IF NOT(x_val_open_ok) THEN --{
6727 rcv_error_pkg.set_error_message('PO_CNL_NO_PERIOD');
6728 RAISE e_validation_error;
6729 END IF; --}
6730
6731 BEGIN
6732 x_val_open_ok := po_dates_s.val_open_period(x_cascaded_table(n).transaction_date,
6733 x_sob_id,
6734 'INV',
6735 x_cascaded_table(n).to_organization_id
6736 );
6737 EXCEPTION
6738 WHEN OTHERS THEN
6739 IF (g_asn_debug = 'Y') THEN
6740 asn_debug.put_line('Exception in val_open_period of trx_date');
6741 END IF;
6742
6743 x_val_open_ok := FALSE;
6744 END;
6745
6746 IF NOT(x_val_open_ok) THEN --{
6747 rcv_error_pkg.set_error_message('PO_INV_NO_OPEN_PERIOD');
6748 RAISE e_validation_error;
6749 END IF; --}
6750
6751 BEGIN
6752 x_val_open_ok := po_dates_s.val_open_period(x_cascaded_table(n).transaction_date,
6753 x_sob_id,
6754 'PO',
6755 x_cascaded_table(n).to_organization_id
6756 );
6757 EXCEPTION
6758 WHEN OTHERS THEN
6759 x_val_open_ok := FALSE;
6760
6761 IF (g_asn_debug = 'Y') THEN
6762 asn_debug.put_line('Exception in val_open_period of gl_date');
6763 END IF;
6764 END;
6765
6766 IF NOT(x_val_open_ok) THEN --{
6767 rcv_error_pkg.set_error_message('PO_PO_ENTER_OPEN_GL_DATE');
6768 RAISE e_validation_error;
6769 END IF; --} /* End of Bug# 2379848 */
6770 END IF; --} auto transact code = SHIP
6771 EXCEPTION
6772 WHEN e_validation_error THEN
6773 x_cascaded_table(n).error_status := x_error_status;
6774 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
6775 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
6776 'TRANSACTION_DATE',
6777 FALSE
6778 );
6779 END validate_transaction_date;
6780
6781 PROCEDURE validate_quantity_invoiced(
6782 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
6783 n IN BINARY_INTEGER
6784 ) IS
6785 quantity_invoiced_record rcv_shipment_line_sv.quantity_invoiced_record_type;
6786 BEGIN
6787 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
6788 RETURN;
6789 END IF;
6790
6791 quantity_invoiced_record.quantity_invoiced := x_cascaded_table(n).quantity_invoiced;
6792 quantity_invoiced_record.error_record.error_status := 'S';
6793 quantity_invoiced_record.error_record.error_message := NULL;
6794 rcv_transactions_interface_sv1.validate_quantity_invoiced(quantity_invoiced_record);
6795 x_cascaded_table(n).error_status := quantity_invoiced_record.error_record.error_status;
6796 x_cascaded_table(n).error_message := quantity_invoiced_record.error_record.error_message;
6797 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
6798 'UNIT_OF_MEASURE',
6799 FALSE
6800 );
6801 END validate_quantity_invoiced;
6802
6803 PROCEDURE validate_transaction_uom(
6804 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
6805 n IN BINARY_INTEGER
6806 ) IS
6807 uom_record rcv_shipment_line_sv.quantity_shipped_record_type;
6808 BEGIN
6809 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
6810 RETURN;
6811 END IF;
6812
6813 IF (g_asn_debug = 'Y') THEN
6814 asn_debug.put_line('Before call to validate UOM');
6815 asn_debug.put_line('Quantity ' || TO_CHAR(x_cascaded_table(n).quantity));
6816 asn_debug.put_line('unit_of_measure ' || x_cascaded_table(n).unit_of_measure);
6817 END IF;
6818
6819 uom_record.quantity_shipped := x_cascaded_table(n).quantity;
6820 uom_record.unit_of_measure := x_cascaded_table(n).unit_of_measure;
6821 uom_record.item_id := x_cascaded_table(n).item_id;
6822 uom_record.po_line_id := x_cascaded_table(n).po_line_id;
6823 uom_record.to_organization_id := x_cascaded_table(n).to_organization_id;
6824 uom_record.po_header_id := x_cascaded_table(n).po_header_id;
6825 uom_record.primary_unit_of_measure := x_cascaded_table(n).primary_unit_of_measure;
6826 uom_record.error_record.error_status := 'S';
6827 uom_record.error_record.error_message := NULL;
6828
6829 IF (g_asn_debug = 'Y') THEN
6830 asn_debug.put_line('Validating UOM');
6831 END IF;
6832
6833 rcv_transactions_interface_sv1.validate_uom(uom_record);
6834 x_cascaded_table(n).error_status := uom_record.error_record.error_status;
6835 x_cascaded_table(n).error_message := uom_record.error_record.error_message;
6836 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
6837 'UNIT_OF_MEASURE',
6838 FALSE
6839 );
6840 END validate_transaction_uom;
6841
6842 PROCEDURE validate_item_info(
6843 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
6844 n IN BINARY_INTEGER
6845 ) IS
6846 item_revision_record rcv_shipment_line_sv.item_id_record_type;
6847 sub_item_id_record rcv_shipment_line_sv.sub_item_id_record_type;
6848 item_id_record rcv_shipment_line_sv.item_id_record_type;
6849 l_asn_sub_item_txn varchar2(1); --Bug: 5598511
6850 l_pol_item_id po_lines_all.item_id%type; --Bug: 5598511
6851 BEGIN
6852 -- validate item id
6853 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
6854 RETURN;
6855 END IF;
6856
6857 IF (g_asn_debug = 'Y') THEN
6858 asn_debug.put_line('Validating Item');
6859 asn_debug.put_line(TO_CHAR(x_cascaded_table(n).item_id));
6860 END IF;
6861
6862 /*
6863 ** If this is a one time item shipment and you've matched up based on a
6864 ** document line num then skip the processing based on setting the validation
6865 ** for the item to be the same as what is set on the line.
6866 */
6867 IF ( x_cascaded_table(n).item_id IS NULL
6868 AND x_cascaded_table(n).po_line_id IS NOT NULL) THEN --{
6869 item_id_record.error_record.error_status := x_cascaded_table(n).error_status;
6870 item_id_record.error_record.error_message := x_cascaded_table(n).error_message;
6871 ELSE
6872 asn_debug.put_line('before doing validate int org rcv item ');
6873
6874 /* Bug 5182693 : Skip validate item for ASN transactions with substitute item */
6875
6876 asn_debug.put_line('substitute_item_id: '|| x_cascaded_table(n).substitute_item_id);
6877 asn_debug.put_line('g_txn_against_asn : '|| rcv_roi_header.g_txn_against_asn);
6878 /** Bug: 5598511
6879 * For ASN, substitution item id will be populated only during ASN creation and
6880 * not during the receipt of ASN. In order to bypass item validation for ASN added the
6881 * condition ' AND rcv_roi_header.g_txn_against_asn = 'N' '
6882 */
6883 IF rcv_roi_header.g_txn_against_asn = 'Y' THEN
6884 l_pol_item_id := nvl(rcv_table_functions.get_pol_row_from_id(x_cascaded_table(n).po_line_id).item_id,-999);
6885 IF x_cascaded_table(n).item_id <> l_pol_item_id THEN
6886 l_asn_sub_item_txn := 'Y';
6887 ELSE
6888 l_asn_sub_item_txn := 'N';
6889 END IF;
6890 ELSE
6891 l_asn_sub_item_txn := 'N';
6892 END IF;
6893 IF (x_cascaded_table(n).substitute_item_id IS NULL AND rcv_roi_header.g_txn_against_asn = 'N')
6894 OR (l_asn_sub_item_txn = 'N' AND rcv_roi_header.g_txn_against_asn = 'Y') --Bug: 5598511
6895 OR rcv_roi_header.g_txn_against_asn = 'N' THEN --{
6896 rcv_roi_header_common.validate_item(x_cascaded_table, n); -- bug 608353
6897 END IF; --}
6898 END IF; --}
6899
6900 asn_debug.put_line('after doing validate item the error status is ' || x_cascaded_table(n).error_status);
6901 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'ITEM_NUM');
6902 item_id_record.item_description := x_cascaded_table(n).item_description;
6903 item_id_record.error_record.error_status := 'S';
6904 item_id_record.error_record.error_message := NULL;
6905
6906 IF (g_asn_debug = 'Y') THEN
6907 asn_debug.put_line('Validating Item Description ' || x_cascaded_table(n).item_description);
6908 END IF;
6909
6910 rcv_transactions_interface_sv1.validate_item_description(item_id_record);
6911 x_cascaded_table(n).error_status := item_id_record.error_record.error_status;
6912 x_cascaded_table(n).error_message := item_id_record.error_record.error_message;
6913
6914 IF (g_asn_debug = 'Y') THEN
6915 asn_debug.put_line('Error status after validate item description ' || x_cascaded_table(n).error_status);
6916 END IF;
6917
6918 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'ITEM_DESCRIPTION');
6919
6920 IF (x_cascaded_table(n).substitute_item_id IS NOT NULL) THEN --{
6921 IF (g_asn_debug = 'Y') THEN
6922 asn_debug.put_line('Validating Substitute Item');
6923 END IF;
6924
6925 rcv_roi_header_common.validate_substitute_item(x_cascaded_table, n);
6926 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'SUBSTITUTE_ITEM_NUM');
6927 END IF;
6928
6929 IF (x_cascaded_table(n).item_revision IS NOT NULL) THEN --{
6930 rcv_roi_header_common.validate_item_revision(x_cascaded_table, n);
6931 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'ITEM_REVISION');
6932 END IF;
6933 EXCEPTION
6934 WHEN rcv_error_pkg.e_fatal_error THEN
6935 NULL;
6936 END validate_item_info;
6937
6938 PROCEDURE validate_freight_carrier_code(
6939 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
6940 n IN BINARY_INTEGER
6941 ) IS
6942 freight_carrier_record rcv_shipment_line_sv.freight_carrier_record_type;
6943 BEGIN
6944 --validate freight carrier code
6945 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
6946 RETURN;
6947 END IF;
6948
6949 IF (x_cascaded_table(n).freight_carrier_code IS NOT NULL) THEN --{
6950 freight_carrier_record.to_organization_id := x_cascaded_table(n).to_organization_id;
6951 freight_carrier_record.freight_carrier_code := x_cascaded_table(n).freight_carrier_code;
6952 freight_carrier_record.po_header_id := x_cascaded_table(n).po_header_id;
6953 freight_carrier_record.error_record.error_status := 'S';
6954 freight_carrier_record.error_record.error_message := NULL;
6955
6956 IF (g_asn_debug = 'Y') THEN
6957 asn_debug.put_line('Validating Freight Carrier');
6958 END IF;
6959
6960 rcv_transactions_interface_sv1.validate_freight_carrier(freight_carrier_record);
6961 x_cascaded_table(n).error_status := freight_carrier_record.error_record.error_status;
6962 x_cascaded_table(n).error_message := freight_carrier_record.error_record.error_message;
6963 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
6964 'FREIGHT_CARRIER_CODE',
6965 FALSE
6966 );
6967 END IF; --}
6968 END validate_freight_carrier_code;
6969
6970 PROCEDURE validate_dest_type(
6971 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
6972 n IN BINARY_INTEGER
6973 ) IS
6974 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
6975 BEGIN
6976 /*
6977 ** Validate Destination Type. This value is always required
6978 */
6979 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
6980 RETURN;
6981 END IF;
6982
6983 po_lookup_code_record.lookup_code := x_cascaded_table(n).destination_type_code;
6984 po_lookup_code_record.lookup_type := 'RCV DESTINATION TYPE';
6985 po_lookup_code_record.error_record.error_status := 'S';
6986 po_lookup_code_record.error_record.error_message := NULL;
6987
6988 IF (g_asn_debug = 'Y') THEN
6989 asn_debug.put_line('Validating Destination Type Code');
6990 END IF;
6991
6992 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
6993 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
6994 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
6995 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
6996 'DESTINATION_TYPE_CODE',
6997 FALSE
6998 );
6999 END validate_dest_type;
7000
7001 PROCEDURE validate_ship_to_loc(
7002 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7003 n IN BINARY_INTEGER
7004 ) IS
7005 location_record rcv_shipment_line_sv.location_record_type;
7006 BEGIN
7007 /*
7008 ** Validate ship_to_location. This value is always required
7009 */
7010 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7011 RETURN;
7012 END IF;
7013
7014 location_record.location_id := x_cascaded_table(n).ship_to_location_id;
7015 location_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7016 location_record.destination_type_code := x_cascaded_table(n).destination_type_code;
7017 location_record.location_type_code := 'SHIP_TO';
7018 location_record.transaction_date := x_cascaded_table(n).transaction_date;
7019 location_record.error_record.error_status := 'S';
7020 location_record.error_record.error_message := NULL;
7021
7022 IF (g_asn_debug = 'Y') THEN
7023 asn_debug.put_line('Validating Ship To Location');
7024 END IF;
7025
7026 rcv_transactions_interface_sv1.validate_location(location_record);
7027 x_cascaded_table(n).error_status := location_record.error_record.error_status;
7028 x_cascaded_table(n).error_message := location_record.error_record.error_message;
7029 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7030 'SHIP_TO_LOCATION_ID',
7031 FALSE
7032 );
7033 END validate_ship_to_loc;
7034
7035 PROCEDURE validate_deliver_to_person(
7036 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7037 n IN BINARY_INTEGER
7038 ) IS
7039 employee_record rcv_shipment_line_sv.employee_record_type;
7040 BEGIN
7041 /*
7042 ** Validate deliver to person. This value is always optional
7043 */
7044 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7045 RETURN;
7046 END IF;
7047
7048 employee_record.employee_id := x_cascaded_table(n).deliver_to_person_id;
7049 employee_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7050 employee_record.destination_type_code := x_cascaded_table(n).destination_type_code;
7051 employee_record.transaction_date := x_cascaded_table(n).transaction_date;
7052 employee_record.error_record.error_status := 'S';
7053 employee_record.error_record.error_message := NULL;
7054
7055 IF (g_asn_debug = 'Y') THEN
7056 asn_debug.put_line('Validating Deliver to Person');
7057 END IF;
7058
7059 rcv_transactions_interface_sv1.validate_employee(employee_record);
7060
7061 /* Bug:6375015
7062 If the deliver_to_person_id provided is invalid/terminated employee no need
7063 to fail the transaction, as deliver_to_person_id is not the mandatory field.
7064 In case of Receivng forms, if we find the deliver_to_person_id is invalid/
7065 terminated employee we just null out the deliver_to_person_id and proceed
7066 further. So, commented out the following code, which sets the RTI to error and
7067 logging of error message in po_interface_errors and added code to null out the
7068 deliver_to_person_id in case of validation failure for deliver_to_person_id
7069 in order to synch the behaviour of ROI as to that of forms.*/
7070
7071 IF employee_record.error_record.error_status <> 'S' THEN--Start of bug#6375015 fix
7072 IF (g_asn_debug = 'Y') THEN
7073 asn_debug.put_line('validate_employee returned error, setting deliver_to_person_id null');
7074 END IF;
7075 --Validation failure for the deliver_to_person_id
7076 x_cascaded_table(n).deliver_to_person_id := null;
7077 x_cascaded_table(n).deliver_to_person_name := null;
7078 ELSE
7079 IF (g_asn_debug = 'Y') THEN
7080 asn_debug.put_line('validate_employee returned success');
7081 END IF;
7082 END IF;--End of bug#6375015 fix
7083
7084 /* WDK there was a second validation for
7085 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7086 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7087 But the code was an exact repeat - thus fully redundant - not sure what the
7088 purpose was so removed it
7089 */
7090 END validate_deliver_to_person;
7091
7092 PROCEDURE validate_routing_record(
7093 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7094 n IN BINARY_INTEGER
7095 ) IS
7096 x_error_status VARCHAR2(1);
7097 BEGIN
7098 x_error_status := rcv_error_pkg.g_ret_sts_error;
7099
7100 /*
7101 ** Validate routing record bug 639750
7102 */
7103 IF (g_asn_debug = 'Y') THEN
7104 asn_debug.put_line('Validating routing_header_id');
7105 END IF;
7106
7107 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7108 RETURN;
7109 END IF;
7110
7111 IF ( x_cascaded_table(n).transaction_type = 'RECEIVE'
7112 AND NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7113 /* 1 is Standard Receipt, 2 is Inspection Required */
7114 IF ( (x_cascaded_table(n).routing_header_id) IN(1, 2)
7115 AND NVL(rcv_setup_s.get_override_routing, 'N') = 'N') THEN
7116 rcv_error_pkg.set_error_message('RCV_ASN_DELIVER_ROUTING_FAILED');
7117 RAISE e_validation_error;
7118 END IF;
7119 END IF;
7120
7121 IF (x_cascaded_table(n).transaction_type IN('ACCEPT', 'REJECT')) THEN --{
7122 IF ( (x_cascaded_table(n).routing_header_id) IN(3)
7123 AND NVL(rcv_setup_s.get_override_routing, 'N') = 'N') THEN --{
7124 asn_debug.put_line('We cannot do inspection on this record .');
7125 rcv_error_pkg.set_error_message('RCV_INSPECT_ROUTING_FAILED');
7126 RAISE e_validation_error;
7127 END IF; --}
7128 END IF; --}
7129 EXCEPTION
7130 WHEN e_validation_error THEN
7131 x_cascaded_table(n).error_status := x_error_status;
7132 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7133
7134 -- This case statement assigns the appropriate tokens
7135 -- all error messages must be found in the case statement
7136 -- if the error message has no token then use a null statement
7137 IF x_cascaded_table(n).error_message = 'RCV_ASN_DELIVER_ROUTING_FAILED' THEN
7138 NULL;
7139 ELSIF x_cascaded_table(n).error_message = 'RCV_INSPECT_ROUTING_FAILED' THEN
7140 NULL;
7141 END IF;
7142
7143 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7144 'ROUTING_HEADER_ID',
7145 FALSE
7146 );
7147 END validate_routing_record;
7148
7149 PROCEDURE validate_deliver_to_loc(
7150 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7151 n IN BINARY_INTEGER
7152 ) IS
7153 location_record rcv_shipment_line_sv.location_record_type;
7154 BEGIN
7155 /*
7156 ** Validate deliver_to_location. If this is an expense or shop floor
7157 ** destination then the value is required
7158 */
7159 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7160 RETURN;
7161 END IF;
7162
7163 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7164 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7165 location_record.location_id := x_cascaded_table(n).deliver_to_location_id;
7166 location_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7167 location_record.destination_type_code := x_cascaded_table(n).destination_type_code;
7168 location_record.location_type_code := 'DELIVER_TO';
7169 location_record.transaction_date := x_cascaded_table(n).transaction_date;
7170 location_record.error_record.error_status := 'S';
7171 location_record.error_record.error_message := NULL;
7172
7173 IF (g_asn_debug = 'Y') THEN
7174 asn_debug.put_line('Validating Deliver To Location');
7175 END IF;
7176
7177 rcv_transactions_interface_sv1.validate_location(location_record);
7178 x_cascaded_table(n).error_status := location_record.error_record.error_status;
7179 x_cascaded_table(n).error_message := location_record.error_record.error_message;
7180 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7181 'DELIVER_TO_LOCATION_ID',
7182 FALSE
7183 );
7184 END IF;
7185 END validate_deliver_to_loc;
7186
7187 /* WMS Changes */
7188 PROCEDURE validate_subinventory(
7189 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7190 n IN BINARY_INTEGER
7191 ) IS
7192 x_subinventory VARCHAR2(10) := NULL;
7193 l_api_version CONSTANT NUMBER := 1.0;
7194 l_return_status VARCHAR2(1);
7195 l_msg_count NUMBER;
7196 l_msg_data fnd_new_messages.MESSAGE_TEXT%TYPE;
7197 l_msg_buf VARCHAR2(2000);
7198 l_progress VARCHAR2(3) := '001';
7199 x_error_status VARCHAR2(1);
7200 BEGIN
7201 x_error_status := rcv_error_pkg.g_ret_sts_error;
7202
7203 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7204 RETURN;
7205 END IF;
7206
7207 /* We can derive from_subinventory for Return transactions and derive
7208 * to_subinventory for receive, transfer and transfer transactions.
7209 */
7210 IF (g_asn_debug = 'Y') THEN
7211 asn_debug.put_line('Validating Subinventory ');
7212 END IF;
7213
7214 /* bug 3367485: for dropship deliver, skip subinventory validation as
7215 * Inventory has relaxed the subinventory validation for logical trxns
7216 */
7217 /* Commented this out as we will not support ASN auto deliver while
7218 * subinventory is null. See updates on Bug 3367485 */
7219 /* IF (x_drop_ship_flag = 'Y') THEN
7220 IF (g_asn_debug = 'Y') THEN
7221 asn_debug.put_line('Skip subinventory validation for dropship deliver ');
7222 END IF;
7223
7224 RETURN;
7225 END IF; */
7226
7227 IF ( ( x_cascaded_table(n).transaction_type = 'DELIVER'
7228 OR x_cascaded_table(n).auto_transact_code = 'DELIVER')
7229 AND x_cascaded_table(n).destination_type_code <> 'INVENTORY') THEN --{
7230 IF (g_asn_debug = 'Y') THEN
7231 asn_debug.put_line('No need to validate Subinventory if the destination_type is Expense. So return');
7232 END IF;
7233
7234 RETURN;
7235 END IF;
7236
7237 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7238 OR x_cascaded_table(n).auto_transact_code = 'DELIVER') THEN --{
7239 IF (x_cascaded_table(n).subinventory IS NULL) THEN
7240 rcv_error_pkg.set_error_message('RCV_DEST_SUB_NA');
7241 RAISE e_validation_error;
7242 END IF;
7243
7244 /*
7245 ** Validate the subinventory
7246 */
7247 x_progress := '010';
7248
7249 IF (g_asn_debug = 'Y') THEN
7250 asn_debug.put_line('subinventory ' || x_cascaded_table(n).subinventory);
7251 asn_debug.put_line('to_organization_id ' || x_cascaded_table(n).to_organization_id);
7252 asn_debug.put_line('transaction_date ' || x_cascaded_table(n).transaction_date);
7253 asn_debug.put_line('item_id ' || x_cascaded_table(n).item_id);
7254 END IF;
7255
7256 SELECT NVL(MAX(secondary_inventory_name), 'notfound')
7257 INTO x_subinventory
7258 FROM mtl_secondary_inventories msub,
7259 mtl_system_items msi
7260 WHERE msub.secondary_inventory_name = x_cascaded_table(n).subinventory
7261 AND msub.organization_id = x_cascaded_table(n).to_organization_id
7262 AND x_cascaded_table(n).transaction_date < NVL(msub.disable_date, x_cascaded_table(n).transaction_date + 1)
7263 AND msi.inventory_item_id = x_cascaded_table(n).item_id
7264 AND msi.organization_id = x_cascaded_table(n).to_organization_id
7265 AND ( msi.restrict_subinventories_code = 2
7266 OR ( msi.restrict_subinventories_code = 1
7267 AND EXISTS(SELECT NULL
7268 FROM mtl_item_sub_inventories mis
7269 WHERE mis.organization_id = x_cascaded_table(n).to_organization_id
7270 AND mis.inventory_item_id = x_cascaded_table(n).item_id
7271 AND mis.secondary_inventory = x_cascaded_table(n).subinventory)
7272 )
7273 );
7274
7275 IF (x_subinventory = 'notfound') THEN
7276 IF (g_asn_debug = 'Y') THEN
7277 asn_debug.put_line('subinventory not found. error ');
7278 END IF;
7279
7280 rcv_error_pkg.set_error_message('RCV_DEST_SUB_INVALID');
7281 RAISE e_validation_error;
7282 END IF;
7283 ELSE --}{
7284 inv_rcv_integration_apis.validate_sub_loc(l_api_version,
7285 'FALSE',
7286 l_return_status,
7287 l_msg_count,
7288 l_msg_data,
7289 x_cascaded_table(n).GROUP_ID,
7290 x_cascaded_table(n).request_id,
7291 x_cascaded_table(n).interface_transaction_id,
7292 1
7293 );
7294
7295 IF (l_return_status = fnd_api.g_ret_sts_error) THEN
7296 RAISE fnd_api.g_exc_error;
7297 ELSIF(l_return_status = fnd_api.g_ret_sts_unexp_error) THEN
7298 RAISE fnd_api.g_exc_unexpected_error;
7299 END IF;
7300 END IF; --}
7301 EXCEPTION
7302 WHEN e_validation_error THEN
7303 x_cascaded_table(n).error_status := x_error_status;
7304 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7305
7306 -- This case statement assigns the appropriate tokens
7307 -- all error messages must be found in the case statement
7308 -- if the error message has no token then use a null statement
7309 IF x_cascaded_table(n).error_message = 'RCV_DEST_SUB_NA' THEN
7310 NULL;
7311 ELSIF x_cascaded_table(n).error_message = 'RCV_DEST_SUB_INVALID' THEN
7312 NULL;
7313 END IF;
7314
7315 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7316 'SUBINVENTORY',
7317 FALSE
7318 );
7319 WHEN OTHERS THEN
7320 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
7321 rcv_error_pkg.set_sql_error_message('validate_subinventory', l_progress);
7322 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7323 rcv_error_pkg.log_interface_error('SUBINVENTORY', FALSE);
7324 END validate_subinventory;
7325
7326 PROCEDURE validate_locator(
7327 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7328 n IN BINARY_INTEGER
7329 ) IS
7330 locator_record rcv_shipment_line_sv.locator_record_type;
7331 BEGIN
7332 /*
7333 ** Validate locator if inventory destination or if not inventory
7334 ** destintion make sure to null out the locator_id
7335 */
7336 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7337 RETURN;
7338 END IF;
7339
7340 IF (g_asn_debug = 'Y') THEN
7341 asn_debug.put_line('Trx Type = ' || x_cascaded_table(n).transaction_type || 'Auto Trx Code = ' || x_cascaded_table(n).auto_transact_code);
7342 END IF;
7343
7344 IF ( x_cascaded_table(n).transaction_type = 'DELIVER'
7345 OR NVL(x_cascaded_table(n).auto_transact_code, 'RECEIVE') = 'DELIVER') THEN
7346 IF (g_asn_debug = 'Y') THEN
7347 asn_debug.put_line('Valid Loc - Destination Type Code = ' || x_cascaded_table(n).destination_type_code);
7348 END IF;
7349
7350 IF (x_cascaded_table(n).destination_type_code = 'INVENTORY') THEN
7351 locator_record.locator_id := x_cascaded_table(n).locator_id;
7352 locator_record.subinventory := x_cascaded_table(n).subinventory;
7353 locator_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7354 locator_record.destination_type_code := x_cascaded_table(n).destination_type_code;
7355 locator_record.item_id := x_cascaded_table(n).item_id;
7356 locator_record.transaction_date := x_cascaded_table(n).transaction_date;
7357
7358 IF (g_asn_debug = 'Y') THEN
7359 asn_debug.put_line('Locator = ' || TO_CHAR(locator_record.locator_id));
7360 asn_debug.put_line('Subinventory = ' || locator_record.subinventory);
7361 asn_debug.put_line('To Org = ' || locator_record.to_organization_id);
7362 asn_debug.put_line('Dest Type = ' || locator_record.destination_type_code);
7363 asn_debug.put_line('Item Id = ' || locator_record.item_id);
7364 END IF;
7365
7366 locator_record.error_record.error_status := 'S';
7367 locator_record.error_record.error_message := NULL;
7368
7369 IF (g_asn_debug = 'Y') THEN
7370 asn_debug.put_line('Validating Locator');
7371 END IF;
7372
7373 rcv_transactions_interface_sv1.validate_locator(locator_record);
7374 x_cascaded_table(n).error_status := locator_record.error_record.error_status;
7375 x_cascaded_table(n).error_message := locator_record.error_record.error_message;
7376
7377 /* Bug 5468345.
7378 * If the user has specified locator_id or locator_num and org/sub/item is not under locator control,
7379 * then the rcv_transactions_interface_sv1.validate_locator procedure nulls out the locator_id.
7380 * We need to copy this back to the x_cascaded_table. This used to cause data corruption.
7381 * Changed the code to null it.
7382 */
7383
7384 if locator_record.locator_id is null then
7385
7386 asn_debug.put_line('Locator_id is nulled out');
7387 x_cascaded_table(n).locator_id := locator_record.locator_id;
7388 end if;
7389
7390
7391 IF (g_asn_debug = 'Y') THEN
7392 asn_debug.put_line('Loc Error Status = ' || locator_record.error_record.error_status);
7393 asn_debug.put_line('Loc Error Msg = ' || locator_record.error_record.error_message);
7394 asn_debug.put_line('Locator_id = ' || locator_record.locator_id);
7395 END IF;
7396
7397 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7398 'LOCATOR_ID',
7399 FALSE
7400 );
7401 ELSE --}{
7402 x_cascaded_table(n).locator_id := NULL;
7403 x_cascaded_table(n).LOCATOR := NULL;
7404 IF (g_asn_debug = 'Y') THEN
7405 asn_debug.put_line('locator_id ' || x_cascaded_table(n).locator_id);
7406 asn_debug.put_line('locator ' || x_cascaded_table(n).locator);
7407 END IF;
7408 END IF; --}
7409 END IF;
7410 END validate_locator;
7411
7412 PROCEDURE validate_tax_code(
7413 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7414 n IN BINARY_INTEGER,
7415 /* Bug3454491 (4) */
7416 x_asn_type IN rcv_headers_interface.asn_type%TYPE
7417 ) IS
7418 tax_name_record rcv_shipment_line_sv.tax_name_record_type;
7419 BEGIN
7420 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7421 RETURN;
7422 END IF;
7423
7424 IF (x_cascaded_table(n).tax_name IS NOT NULL) THEN
7425 IF (x_asn_type = 'ASBN') THEN
7426 tax_name_record.tax_name := x_cascaded_table(n).tax_name;
7427 tax_name_record.error_record.error_status := 'S';
7428 tax_name_record.error_record.error_message := NULL;
7429
7430 IF (g_asn_debug = 'Y') THEN
7431 asn_debug.put_line('Validating Tax Code');
7432 END IF;
7433
7434 rcv_transactions_interface_sv1.validate_tax_code(tax_name_record);
7435 x_cascaded_table(n).error_status := tax_name_record.error_record.error_status;
7436 x_cascaded_table(n).error_message := tax_name_record.error_record.error_message;
7437 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7438 'TAX_NAME',
7439 FALSE
7440 );
7441 END IF;
7442 END IF;
7443 END validate_tax_code;
7444
7445 PROCEDURE validate_country_of_origin(
7446 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7447 n IN BINARY_INTEGER
7448 ) IS
7449 country_of_origin_record rcv_shipment_line_sv.country_of_origin_record_type;
7450 BEGIN
7451 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7452 RETURN;
7453 END IF;
7454
7455 --FRKHAN 12/18/98 validate country of origin code
7456 IF (x_cascaded_table(n).country_of_origin_code IS NOT NULL) THEN
7457 country_of_origin_record.country_of_origin_code := x_cascaded_table(n).country_of_origin_code;
7458 country_of_origin_record.error_record.error_status := 'S';
7459 country_of_origin_record.error_record.error_message := NULL;
7460
7461 IF (g_asn_debug = 'Y') THEN
7462 asn_debug.put_line('Validating Country of Origin Code');
7463 END IF;
7464
7465 rcv_transactions_interface_sv1.validate_country_of_origin(country_of_origin_record);
7466 x_cascaded_table(n).error_status := country_of_origin_record.error_record.error_status;
7467 x_cascaded_table(n).error_message := country_of_origin_record.error_record.error_message;
7468 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7469 'COUNTRY_OF_ORIGIN_CODE',
7470 FALSE
7471 );
7472 END IF;
7473 END validate_country_of_origin;
7474
7475 PROCEDURE validate_asl(
7476 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7477 n IN BINARY_INTEGER
7478 ) IS
7479 asl_record rcv_shipment_line_sv.ref_integrity_record_type;
7480 BEGIN
7481 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7482 RETURN;
7483 END IF;
7484
7485 asl_record.po_header_id := x_cascaded_table(n).po_header_id;
7486 asl_record.vendor_id := x_cascaded_table(n).vendor_id;
7487 asl_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
7488 asl_record.item_id := x_cascaded_table(n).item_id;
7489 asl_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7490 asl_record.error_record.error_status := 'S';
7491 asl_record.error_record.error_message := NULL;
7492
7493 IF (g_asn_debug = 'Y') THEN
7494 asn_debug.put_line('Validating ASL');
7495 END IF;
7496
7497 rcv_transactions_interface_sv1.validate_asl(asl_record);
7498 x_cascaded_table(n).error_status := asl_record.error_record.error_status;
7499 x_cascaded_table(n).error_message := asl_record.error_record.error_message;
7500 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7501 'SUPPLY_AGREEMENT_FLAG',
7502 FALSE
7503 );
7504 END validate_asl;
7505
7506 PROCEDURE validate_shipped_qty(
7507 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7508 n IN BINARY_INTEGER
7509 ) IS
7510 cum_quantity_record rcv_shipment_line_sv.cum_quantity_record_type;
7511 BEGIN
7512 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7513 RETURN;
7514 END IF;
7515
7516 IF NVL(x_cascaded_table(n).vendor_cum_shipped_qty, 0) <> 0 THEN
7517 cum_quantity_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7518 cum_quantity_record.po_header_id := x_cascaded_table(n).po_header_id;
7519 cum_quantity_record.vendor_cum_shipped_qty := x_cascaded_table(n).vendor_cum_shipped_qty;
7520 cum_quantity_record.item_id := x_cascaded_table(n).item_id;
7521 cum_quantity_record.vendor_id := x_cascaded_table(n).vendor_id;
7522 cum_quantity_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
7523 cum_quantity_record.primary_unit_of_measure := x_cascaded_table(n).primary_unit_of_measure;
7524 cum_quantity_record.quantity_shipped := x_cascaded_table(n).quantity;
7525 cum_quantity_record.unit_of_measure := x_cascaded_table(n).unit_of_measure;
7526 cum_quantity_record.transaction_date := x_cascaded_table(n).transaction_date;
7527 cum_quantity_record.error_record.error_status := 'S';
7528 cum_quantity_record.error_record.error_message := NULL;
7529
7530 IF (g_asn_debug = 'Y') THEN
7531 asn_debug.put_line('Validating Cum Qty Shipped');
7532 END IF;
7533
7534 rcv_transactions_interface_sv1.validate_cum_quantity_shipped(cum_quantity_record);
7535 x_cascaded_table(n).error_status := cum_quantity_record.error_record.error_status;
7536 x_cascaded_table(n).error_message := cum_quantity_record.error_record.error_message;
7537 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7538 'VENDOR_CUM_SHIPPED_QTY',
7539 FALSE
7540 );
7541 END IF; -- vendor_cum_shipped_qty <> 0
7542 END validate_shipped_qty;
7543
7544 PROCEDURE validate_ref_integrity(
7545 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7546 n IN BINARY_INTEGER,
7547 x_header_record IN rcv_roi_preprocessor.header_rec_type
7548 ) IS
7549 ref_integrity_record rcv_shipment_line_sv.ref_integrity_record_type;
7550 l_job_id po_lines.job_id%TYPE;
7551 l_item_description po_lines.item_description%TYPE;
7552 l_category_id po_lines.category_id%TYPE;
7553 x_error_status VARCHAR2(1);
7554 BEGIN
7555 x_error_status := rcv_error_pkg.g_ret_sts_error;
7556
7557 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7558 RETURN;
7559 END IF;
7560
7561 IF (g_asn_debug = 'Y') THEN
7562 asn_debug.put_line('Validating ref integrity');
7563 END IF;
7564
7565 ref_integrity_record.to_organization_id := x_cascaded_table(n).to_organization_id;
7566 ref_integrity_record.po_line_location_id := x_cascaded_table(n).po_line_location_id;
7567 ref_integrity_record.po_header_id := x_cascaded_table(n).po_header_id;
7568 ref_integrity_record.po_line_id := x_cascaded_table(n).po_line_id;
7569 ref_integrity_record.vendor_id := x_cascaded_table(n).vendor_id;
7570 ref_integrity_record.vendor_site_id := x_cascaded_table(n).vendor_site_id;
7571 ref_integrity_record.vendor_item_num := x_cascaded_table(n).vendor_item_num;
7572
7573 /*
7574 Bug 6447564.
7575 Added below line to pass parent_txn_id value to the proc validate_ref_integ()
7576 So that we may take the vendor site id from parent txn if parent_txn_id not null.
7577 */
7578 ref_integrity_record.parent_txn_id := x_cascaded_table(n).PARENT_TRANSACTION_ID;
7579
7580
7581 /* Bug 3210821.
7582 * We default po_revision_num from RT for all the
7583 * transactions other than receive or direct delivery.
7584 * Hence we should not be validationg this against the
7585 * revision_num in PO header since it might heve been
7586 * changed. So set po_revision_num to null if it is any other
7587 * transaction other than RECEIVE. This would take care of
7588 * direct delivery also since trx_type will be receive for
7589 * that also.
7590 */
7591 IF (x_cascaded_table(n).transaction_type = 'RECEIVE') THEN
7592 ref_integrity_record.po_revision_num := x_cascaded_table(n).po_revision_num;
7593
7594 IF (g_asn_debug = 'Y') THEN
7595 asn_debug.put_line('Trx_type RECEIVE and revision num is ' || ref_integrity_record.po_revision_num);
7596 END IF;
7597 ELSE
7598 ref_integrity_record.po_revision_num := NULL;
7599
7600 IF (g_asn_debug = 'Y') THEN
7601 asn_debug.put_line('Trx_type is not RECEIVE and revision num is ' || ref_integrity_record.po_revision_num);
7602 END IF;
7603 END IF;
7604
7605 /* End of 3210821. */
7606 ref_integrity_record.error_record.error_status := 'S';
7607 ref_integrity_record.error_record.error_message := NULL;
7608 --replacing call with a validate_ref_integ call with the method in thid package
7609 -- rcv_transactions_interface_sv1.validate_ref_integ (ref_integrity_record,X_header_record);
7610 validate_ref_integ(ref_integrity_record, x_header_record);
7611
7612 IF (g_asn_debug = 'Y') THEN
7613 asn_debug.put_line('After Validating Ref Integ: ' || ref_integrity_record.error_record.error_status);
7614 END IF;
7615
7616 x_cascaded_table(n).error_status := ref_integrity_record.error_record.error_status;
7617 x_cascaded_table(n).error_message := ref_integrity_record.error_record.error_message;
7618 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'TRANSACTIONS_INTERFACE_ID');
7619
7620 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN --{
7621 IF (g_asn_debug = 'Y') THEN
7622 asn_debug.put_line('job_id ' || x_cascaded_table(n).job_id);
7623 asn_debug.put_line('item_description ' || x_cascaded_table(n).item_description);
7624 asn_debug.put_line('category_id ' || x_cascaded_table(n).category_id);
7625 END IF;
7626
7627 IF (x_cascaded_table(n).job_id IS NOT NULL) THEN
7628 IF (g_asn_debug = 'Y') THEN
7629 asn_debug.put_line('Before select l_job_id ' || l_job_id);
7630 END IF;
7631
7632 SELECT NVL(MAX(job_id), 0)
7633 INTO l_job_id
7634 FROM po_lines
7635 WHERE po_line_id = x_cascaded_table(n).po_line_id
7636 AND job_id = x_cascaded_table(n).job_id;
7637
7638 IF (g_asn_debug = 'Y') THEN
7639 asn_debug.put_line('After select l_job_id ' || l_job_id);
7640 END IF;
7641
7642 IF (l_job_id = 0) THEN
7643 rcv_error_pkg.set_error_message('RCV_NOT_PO_JOB_ID');
7644 RAISE e_validation_error;
7645 END IF;
7646 END IF;
7647
7648 IF (x_cascaded_table(n).item_description IS NOT NULL) THEN
7649
7650 /* Complex work.
7651 * For work confirmations check in shipment level. If
7652 * null then in po_lines. For other POs
7653 * check in po_lines.
7654 */
7655
7656 If (nvl(x_header_record.header_record.asn_type,'STD') = 'WC') then --{
7657
7658 BEGIN
7659 SELECT (description)
7660 INTO l_item_description
7661 FROM po_line_locations
7662 WHERE line_location_id =
7663 x_cascaded_table(n).po_line_location_id
7664 AND description = x_cascaded_table(n).item_description;
7665
7666 EXCEPTION
7667 WHEN NO_DATA_FOUND THEN
7668 BEGIN
7669 SELECT (item_description)
7670 INTO l_item_description
7671 FROM po_lines
7672 WHERE po_line_id = x_cascaded_table(n).po_line_id
7673 AND item_description =
7674 x_cascaded_table(n).item_description;
7675 EXCEPTION
7676 WHEN NO_DATA_FOUND THEN
7677 l_item_description := 'NO DATA';
7678 END;
7679
7680 END;
7681
7682 else --}{
7683 BEGIN
7684 SELECT (item_description)
7685 INTO l_item_description
7686 FROM po_lines
7687 WHERE po_line_id = x_cascaded_table(n).po_line_id
7688 AND item_description = x_cascaded_table(n).item_description;
7689 EXCEPTION
7690 WHEN NO_DATA_FOUND THEN
7691 l_item_description := 'NO DATA';
7692 END;
7693
7694 End if; --}
7695
7696 IF (g_asn_debug = 'Y') THEN
7697 asn_debug.put_line('After select l_item_description ' || l_item_description);
7698 END IF;
7699
7700 IF (l_item_description = 'NO DATA') THEN
7701 rcv_error_pkg.set_error_message('RCV_NOT_PO_ITEM_DESC');
7702 RAISE e_validation_error;
7703 END IF;
7704 END IF;
7705
7706 IF (x_cascaded_table(n).category_id IS NOT NULL) THEN
7707 SELECT NVL(MAX(category_id), 0)
7708 INTO l_category_id
7709 FROM po_lines
7710 WHERE po_line_id = x_cascaded_table(n).po_line_id
7711 AND category_id = x_cascaded_table(n).category_id;
7712
7713 IF (g_asn_debug = 'Y') THEN
7714 asn_debug.put_line('After select l_category_id ' || l_category_id);
7715 END IF;
7716
7717 IF (l_category_id = 0) THEN
7718 rcv_error_pkg.set_error_message('RCV_NOT_PO_CATEGORY');
7719 RAISE e_validation_error;
7720 END IF;
7721 END IF;
7722
7723 IF (g_asn_debug = 'Y') THEN
7724 asn_debug.put_line('l_job_id ' || l_job_id);
7725 asn_debug.put_line('l_item_description ' || l_item_description);
7726 asn_debug.put_line('l_category_id ' || l_category_id);
7727 asn_debug.put_line('x_cascaded_table(n).error_status ' || x_cascaded_table(n).error_status);
7728 END IF;
7729 END IF; --}
7730
7731 IF (g_asn_debug = 'Y') THEN
7732 asn_debug.put_line('Leave validate_ref_integrity');
7733 END IF;
7734 EXCEPTION
7735 WHEN e_validation_error THEN
7736 x_cascaded_table(n).error_status := x_error_status;
7737 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7738
7739 IF x_cascaded_table(n).error_message = 'RCV_NOT_PO_JOB_ID' THEN
7740 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7741 'JOB_ID',
7742 FALSE
7743 );
7744 ELSIF x_cascaded_table(n).error_message = 'RCV_NOT_PO_ITEM_DESC' THEN
7745 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7746 'ITEM_DESCRIPTION',
7747 FALSE
7748 );
7749 ELSIF x_cascaded_table(n).error_message = 'RCV_NOT_PO_CATEGORY' THEN
7750 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
7751 'CATEGORY_ID',
7752 FALSE
7753 );
7754 END IF;
7755 WHEN rcv_error_pkg.e_fatal_error THEN
7756 NULL;
7757 WHEN OTHERS THEN
7758 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
7759 rcv_error_pkg.set_sql_error_message('validate_ref_integrity', '000');
7760 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7761 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
7762 END validate_ref_integrity;
7763
7764 PROCEDURE exchange_sub_items(
7765 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7766 n IN BINARY_INTEGER
7767 ) IS
7768 location_record rcv_shipment_line_sv.location_record_type;
7769 x_item_id NUMBER;
7770 x_primary_uom mtl_system_items.primary_unit_of_measure%TYPE := NULL;
7771 x_uom_class VARCHAR2(10);
7772 x_uom_count NUMBER(10);
7773 prim_uom_qty NUMBER;
7774 x_error_status VARCHAR2(1);
7775 l_item_description mtl_system_items_vl.description%type; --bug 4697949
7776 BEGIN
7777 x_error_status := rcv_error_pkg.g_ret_sts_error;
7778
7779 -- If substitute item has been specified then we need to switch the item_id with the
7780 -- substitute item. Also make sure that we can receive the substitute item in the
7781 -- ASN UOM. Convert the primary_quantity in item.primary uom to the substitute_item.primary_uom
7782 -- If this fails then the transaction is in error
7783
7784 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7785 RETURN;
7786 END IF;
7787
7788 IF x_cascaded_table(n).substitute_item_id IS NOT NULL THEN --{
7789
7790 -- exchange_sub_item(x_cascaded_table,n);
7791 -- the call to exchange sub item is not made
7792 -- instead the code of exchange sub item is put there
7793 SELECT COUNT(*)
7794 INTO x_uom_count
7795 FROM mtl_item_uoms_view
7796 WHERE organization_id = x_cascaded_table(n).to_organization_id
7797 AND inventory_item_id(+) = x_cascaded_table(n).substitute_item_id
7798 AND unit_of_measure = x_cascaded_table(n).unit_of_measure;
7799
7800 IF x_uom_count = 0 THEN
7801 IF (g_asn_debug = 'Y') THEN
7802 asn_debug.put_line('The substitute item cannot be received in ASN uom' || x_cascaded_table(n).unit_of_measure);
7803 END IF;
7804
7805 rcv_error_pkg.set_error_message('RCV_ITEM_SUB_NOT_ALLOWED');
7806 RAISE e_validation_error;
7807 END IF;
7808
7809 SELECT MAX(primary_unit_of_measure)
7810 INTO x_primary_uom
7811 FROM mtl_system_items
7812 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
7813 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
7814
7815 IF x_primary_uom IS NULL THEN
7816 IF (g_asn_debug = 'Y') THEN
7817 asn_debug.put_line('No Primary UOM for substitute item');
7818 END IF;
7819
7820 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY');
7821 RAISE e_validation_error;
7822 END IF;
7823
7824 IF (g_asn_debug = 'Y') THEN
7825 asn_debug.put_line('Primary UOM for substitute item is ' || x_primary_uom);
7826 END IF;
7827
7828 IF x_primary_uom <> x_cascaded_table(n).primary_unit_of_measure THEN --{
7829 prim_uom_qty := rcv_transactions_interface_sv.convert_into_correct_qty(x_cascaded_table(n).quantity,
7830 x_cascaded_table(n).unit_of_measure,
7831 x_cascaded_table(n).item_id,
7832 x_primary_uom
7833 );
7834
7835 IF prim_uom_qty = 0 THEN
7836 IF (g_asn_debug = 'Y') THEN
7837 asn_debug.put_line('Not possible to convert between asn and primary UOM');
7838 END IF;
7839
7840 rcv_error_pkg.set_error_message('RCV_UOM_NO_CONV_PRIMARY');
7841 RAISE e_validation_error;
7842 END IF;
7843
7844 x_cascaded_table(n).primary_unit_of_measure := x_primary_uom;
7845 x_cascaded_table(n).primary_quantity := prim_uom_qty;
7846 END IF; --}
7847
7848 /* added for bug 4697949. querying msi to get the description of
7849 substitute item*/
7850 BEGIN
7851 select description
7852 into l_item_description
7853 from mtl_system_items_vl
7854 where inventory_item_id = x_cascaded_table(n).substitute_item_id
7855 and organization_id = x_cascaded_table(n).to_organization_id;
7856 EXCEPTION
7857 when others then
7858 l_item_description := null;
7859 END;
7860
7861 x_item_id := x_cascaded_table(n).item_id;
7862 x_cascaded_table(n).item_id := x_cascaded_table(n).substitute_item_id;
7863 x_cascaded_table(n).item_description := l_item_description; --bug 4697949
7864 x_cascaded_table(n).substitute_item_id := x_item_id; -- Just for debugging purposes.
7865
7866 -- end of exchange sub item code which has been copied over from rcvtisvb++++++++++++++++++++++
7867 END IF; --}
7868 EXCEPTION
7869 WHEN e_validation_error THEN
7870 x_cascaded_table(n).error_status := x_error_status;
7871 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
7872
7873 IF x_cascaded_table(n).error_message = 'RCV_ITEM_SUB_NOT_ALLOWED' THEN
7874 rcv_error_pkg.set_token('ITEM', x_cascaded_table(n).substitute_item_id);
7875 ELSIF x_cascaded_table(n).error_message = 'RCV_UOM_NO_CONV_PRIMARY' THEN
7876 rcv_error_pkg.set_token('SHIPMENT_UNIT', x_cascaded_table(n).primary_unit_of_measure);
7877 rcv_error_pkg.set_token('PRIMARY_UNIT', x_primary_uom);
7878 END IF;
7879 END exchange_sub_items;
7880
7881 PROCEDURE validate_consigned_inventory(
7882 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
7883 n IN BINARY_INTEGER,
7884 /* Bug3454491 (5) */
7885 x_asn_type IN rcv_headers_interface.asn_type%TYPE
7886 ) IS
7887 l_consigned_po_rec rcv_shipment_line_sv.po_line_location_id_rtype;
7888 l_consumption_po_rec rcv_shipment_line_sv.document_num_record_type;
7889 l_consumption_release_rec rcv_shipment_line_sv.release_id_record_type;
7890 BEGIN
7891 /* <Consigned Inventory Pre-Processor FPI START> */
7892
7893 /* Reject ASBN transaction if it's a shipment against Consigned PO */
7894 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
7895 RETURN;
7896 END IF;
7897
7898 IF (x_asn_type = 'ASBN')
7899 AND (x_cascaded_table(n).po_line_location_id IS NOT NULL) THEN
7900 l_consigned_po_rec.po_line_location_id := x_cascaded_table(n).po_line_location_id;
7901 l_consigned_po_rec.error_record.error_status := 'S';
7902 l_consigned_po_rec.error_record.error_message := NULL;
7903
7904 IF (g_asn_debug = 'Y') THEN
7905 asn_debug.put_line('Validating ASBN for Consigned PO');
7906 END IF;
7907
7908 rcv_transactions_interface_sv1.validate_consigned_po(l_consigned_po_rec);
7909
7910 IF (g_asn_debug = 'Y') THEN
7911 asn_debug.put_line('After Validating ASBN for Consigned PO');
7912 END IF;
7913
7914 x_cascaded_table(n).error_status := l_consigned_po_rec.error_record.error_status;
7915 x_cascaded_table(n).error_message := l_consigned_po_rec.error_record.error_message;
7916
7917 IF (g_asn_debug = 'Y') THEN
7918 asn_debug.put_line('Error status ' || l_consigned_po_rec.error_record.error_status);
7919 asn_debug.put_line('Error name: ' || l_consigned_po_rec.error_record.error_message);
7920 END IF;
7921
7922 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PO_LINE_LOCATION_ID');
7923 END IF; -- IF ( (X_asn_type = 'ASBN')
7924
7925 /*
7926 ** Reject ASN, ASBN or Receipt transactions against Consumption PO
7927 */
7928 IF (x_cascaded_table(n).po_header_id IS NOT NULL)
7929 AND (x_cascaded_table(n).po_release_id IS NULL) THEN
7930 l_consumption_po_rec.po_header_id := x_cascaded_table(n).po_header_id;
7931 l_consumption_po_rec.error_record.error_status := 'S';
7932 l_consumption_po_rec.error_record.error_message := NULL;
7933
7934 IF (g_asn_debug = 'Y') THEN
7935 asn_debug.put_line('Validating Consumption PO');
7936 END IF;
7937
7938 rcv_transactions_interface_sv1.validate_consumption_po(l_consumption_po_rec);
7939
7940 IF (g_asn_debug = 'Y') THEN
7941 asn_debug.put_line('After Validating Consumption PO');
7942 END IF;
7943
7944 x_cascaded_table(n).error_status := l_consumption_po_rec.error_record.error_status;
7945 x_cascaded_table(n).error_message := l_consumption_po_rec.error_record.error_message;
7946
7947 IF (g_asn_debug = 'Y') THEN
7948 asn_debug.put_line('Error status ' || l_consumption_po_rec.error_record.error_status);
7949 asn_debug.put_line('Error name: ' || l_consumption_po_rec.error_record.error_message);
7950 END IF;
7951
7952 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PO_HEADER_ID');
7953 END IF;
7954
7955 /*
7956 ** Reject ASN, ASBN or Receipt transactions against Consumption Release
7957 */
7958 IF (x_cascaded_table(n).po_release_id IS NOT NULL) THEN
7959 l_consumption_release_rec.po_release_id := x_cascaded_table(n).po_release_id;
7960 l_consumption_release_rec.error_record.error_status := 'S';
7961 l_consumption_release_rec.error_record.error_message := NULL;
7962
7963 IF (g_asn_debug = 'Y') THEN
7964 asn_debug.put_line('Validating Consumption Release');
7965 END IF;
7966
7967 rcv_transactions_interface_sv1.validate_consumption_release(l_consumption_release_rec);
7968
7969 IF (g_asn_debug = 'Y') THEN
7970 asn_debug.put_line('After Validating Consumption Release');
7971 END IF;
7972
7973 x_cascaded_table(n).error_status := l_consumption_release_rec.error_record.error_status;
7974 x_cascaded_table(n).error_message := l_consumption_release_rec.error_record.error_message;
7975
7976 IF (g_asn_debug = 'Y') THEN
7977 asn_debug.put_line('Error status ' || l_consumption_release_rec.error_record.error_status);
7978 asn_debug.put_line('Error name: ' || l_consumption_release_rec.error_record.error_message);
7979 END IF;
7980
7981 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'PO_RELEASE_ID');
7982 END IF;
7983 /* <Consigned Inventory Pre-Processor FPI END> */
7984 EXCEPTION
7985 WHEN rcv_error_pkg.e_fatal_error THEN
7986 NULL;
7987 END validate_consigned_inventory;
7988
7989 PROCEDURE validate_ref_integ(
7990 x_ref_integrity_rec IN OUT NOCOPY rcv_shipment_line_sv.ref_integrity_record_type,
7991 x_header_record IN rcv_roi_preprocessor.header_rec_type
7992 ) IS
7993 x_po_vendor_id po_headers.vendor_id%TYPE := NULL;
7994 x_po_line_id po_lines.po_line_id%TYPE;
7995 x_po_vendor_site_id po_headers.vendor_site_id%TYPE := NULL;
7996 x_progress VARCHAR2(3);
7997 x_error_status VARCHAR2(1);
7998 BEGIN
7999 x_error_status := rcv_error_pkg.g_ret_sts_error;
8000
8001 IF (x_ref_integrity_rec.vendor_item_num IS NOT NULL) THEN
8002 SELECT NVL(MAX(po_line_id), 0)
8003 INTO x_po_line_id
8004 FROM po_lines
8005 WHERE po_line_id = x_ref_integrity_rec.po_line_id
8006 AND vendor_product_num = x_ref_integrity_rec.vendor_item_num;
8007
8008 IF (x_po_line_id = 0) THEN
8009 rcv_error_pkg.set_error_message('RCV_NOT_PO_VEN_ITEM');
8010 RAISE e_validation_error;
8011 END IF;
8012 END IF;
8013
8014 IF (g_asn_debug = 'Y') THEN
8015 asn_debug.put_line('Validating vendor id in PO ' || TO_CHAR(x_ref_integrity_rec.vendor_id));
8016 asn_debug.put_line('PO Header Id ' || TO_CHAR(x_ref_integrity_rec.po_header_id));
8017 END IF;
8018
8019 IF x_ref_integrity_rec.vendor_id IS NOT NULL THEN
8020 SELECT NVL(MAX(vendor_id), 0)
8021 INTO x_po_vendor_id
8022 FROM po_headers
8023 WHERE po_header_id = x_ref_integrity_rec.po_header_id
8024 AND vendor_id = x_ref_integrity_rec.vendor_id;
8025
8026 IF (x_po_vendor_id = 0) THEN
8027 rcv_error_pkg.set_error_message('RCV_NOT_PO_VEN');
8028 RAISE e_validation_error;
8029 END IF;
8030 END IF;
8031
8032 -- Check for header.vendor = lines.vendor
8033 IF x_header_record.header_record.vendor_id IS NOT NULL THEN
8034 IF x_header_record.header_record.vendor_id <> NVL(x_ref_integrity_rec.vendor_id, x_header_record.header_record.vendor_id) THEN
8035 rcv_error_pkg.set_error_message('RCV_ERC_MISMATCH_PO_VENDOR');
8036 RAISE e_validation_error;
8037 END IF;
8038 END IF;
8039
8040 IF x_ref_integrity_rec.vendor_site_id IS NOT NULL THEN
8041 /*
8042 BUG 6447564.
8043 Changed the vendor_site_id validation code.
8044 Added parent_txn_id condition so as to take into account,
8045 the possibility that the vendor_site can change on a PO even after
8046 receipts have been created.
8047 So now incase of null parent txn id we see from PO_headers and
8048 incase of non-null parent_txn_id we look for the parent txn's vendor_site_id.
8049 */
8050 IF (x_ref_integrity_rec.parent_txn_id IS NULL) THEN
8051
8052 SELECT NVL(MAX(vendor_site_id), 0)
8053 INTO x_po_vendor_site_id
8054 FROM po_headers
8055 WHERE po_header_id = x_ref_integrity_rec.po_header_id
8056 AND vendor_site_id = x_ref_integrity_rec.vendor_site_id;
8057
8058 asn_debug.put_line('vendor_site_id from PO_HEADERS ' || TO_CHAR(x_po_vendor_site_id));
8059
8060 END IF;
8061
8062 IF (x_ref_integrity_rec.parent_txn_id IS NOT NULL) THEN
8063
8064 SELECT NVL(MAX(vendor_site_id), 0)
8065 INTO x_po_vendor_site_id
8066 FROM rcv_transactions
8067 WHERE po_header_id = x_ref_integrity_rec.po_header_id
8068 AND transaction_id = x_ref_integrity_rec.parent_txn_id
8069 AND vendor_site_id = x_ref_integrity_rec.vendor_site_id;
8070
8071 asn_debug.put_line('vendor_site_id from RCV_TRANSACTIONS ' || TO_CHAR(x_po_vendor_site_id));
8072
8073 END IF;
8074
8075
8076 IF (x_po_vendor_site_id = 0) THEN
8077 rcv_error_pkg.set_error_message('RCV_NOT_PO_VEN_SITE');
8078 RAISE e_validation_error;
8079 END IF;
8080 END IF;
8081
8082 IF x_ref_integrity_rec.po_revision_num IS NOT NULL THEN
8083 IF (g_asn_debug = 'Y') THEN
8084 asn_debug.put_line('po_revision_num: ' || x_ref_integrity_rec.po_revision_num);
8085 END IF;
8086
8087 SELECT NVL(MAX(vendor_site_id), 0)
8088 INTO x_po_vendor_site_id
8089 FROM po_headers
8090 WHERE po_header_id = x_ref_integrity_rec.po_header_id
8091 AND revision_num = x_ref_integrity_rec.po_revision_num;
8092
8093 IF (x_po_vendor_site_id = 0) THEN
8094 rcv_error_pkg.set_error_message('RCV_NOT_PO_REVISION');
8095 RAISE e_validation_error;
8096 END IF;
8097 END IF;
8098 EXCEPTION
8099 WHEN e_validation_error THEN
8100 x_ref_integrity_rec.error_record.error_status := x_error_status;
8101 x_ref_integrity_rec.error_record.error_message := rcv_error_pkg.get_last_message;
8102
8103 IF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_VEN_ITEM' THEN
8104 rcv_error_pkg.set_token('PO_SUPPLIER_ITEM', '');
8105 rcv_error_pkg.set_token('SHIPMENT_SUPPLIER_ITEM', x_ref_integrity_rec.vendor_item_num);
8106 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_VEN' THEN
8107 rcv_error_pkg.set_token('PO_SUPPLIER', '');
8108 rcv_error_pkg.set_token('SHIPMENT_SUPPLIER', x_ref_integrity_rec.vendor_id);
8109 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_ERC_MISMATCH_PO_VENDOR' THEN
8110 NULL;
8111 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_VEN_SITE' THEN
8112 rcv_error_pkg.set_token('PO_SUPPLIER_SITE', '');
8113 rcv_error_pkg.set_token('SHIPMENT_SUPPLIER_SITE', x_ref_integrity_rec.vendor_site_id);
8114 ELSIF x_ref_integrity_rec.error_record.error_message = 'RCV_NOT_PO_REVISION' THEN
8115 rcv_error_pkg.set_token('PO_REV', '');
8116 rcv_error_pkg.set_token('SHIPMENT_REV', x_ref_integrity_rec.po_revision_num);
8117 END IF;
8118 END validate_ref_integ;
8119
8120 PROCEDURE validate_temp_labor_info(
8121 v_trans_tab IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8122 n IN BINARY_INTEGER,
8123 v_header_record IN rcv_roi_preprocessor.header_rec_type
8124 ) IS
8125 x_error_status VARCHAR2(1);
8126 BEGIN
8127 x_error_status := rcv_error_pkg.g_ret_sts_error;
8128
8129 IF v_trans_tab(n).error_status NOT IN('S', 'W') THEN
8130 RETURN;
8131 END IF;
8132
8133 IF v_trans_tab(n).matching_basis = 'AMOUNT'
8134 AND v_trans_tab(n).purchase_basis = 'TEMP LABOR' THEN
8135 IF v_trans_tab(n).job_id IS NULL
8136 OR v_trans_tab(n).timecard_id IS NULL
8137 OR v_trans_tab(n).timecard_ovn IS NULL THEN
8138 rcv_error_pkg.set_error_message('RCV_NO_TEMP_LABOR_INFO');
8139 RAISE e_validation_error;
8140 END IF;
8141 END IF;
8142 EXCEPTION
8143 WHEN e_validation_error THEN
8144 v_trans_tab(n).error_status := x_error_status;
8145 v_trans_tab(n).error_message := rcv_error_pkg.get_last_message;
8146
8147 IF v_trans_tab(n).error_message = 'RCV_NO_TEMP_LABOR_INFO' THEN
8148 NULL;
8149 END IF;
8150 END validate_temp_labor_info;
8151
8152 PROCEDURE validate_amount(
8153 v_trans_tab IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8154 n IN BINARY_INTEGER,
8155 v_header_record IN rcv_roi_preprocessor.header_rec_type
8156 ) IS
8157 x_error_status VARCHAR2(1);
8158 BEGIN
8159 x_error_status := rcv_error_pkg.g_ret_sts_error;
8160
8161 IF v_trans_tab(n).error_status NOT IN('S', 'W') THEN
8162 RETURN;
8163 END IF;
8164
8165 IF v_trans_tab(n).matching_basis = 'AMOUNT' THEN
8166 IF v_trans_tab(n).amount IS NULL
8167 OR v_trans_tab(n).amount <= 0 THEN
8168 rcv_error_pkg.set_error_message('RCV_NO_AMOUNT');
8169 RAISE e_validation_error;
8170 END IF;
8171 END IF;
8172 EXCEPTION
8173 WHEN e_validation_error THEN
8174 v_trans_tab(n).error_status := x_error_status;
8175 v_trans_tab(n).error_message := rcv_error_pkg.get_last_message;
8176
8177 IF v_trans_tab(n).error_message = 'RCV_NO_AMOUNT' THEN
8178 NULL;
8179 END IF;
8180 END validate_amount;
8181
8182 PROCEDURE handle_rcv_asn_transactions(
8183 v_trans_tab IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
8184 v_header_record IN OUT NOCOPY rcv_roi_preprocessor.header_rec_type
8185 ) IS
8186 v_current_interface_id NUMBER;
8187 v_prior_interface_id NUMBER;
8188 i BINARY_INTEGER := 0;
8189 e_o_t BINARY_INTEGER := 0;
8190 x_rowid VARCHAR2(255);
8191 l_wms_return_status VARCHAR2(1);
8192 l_wms_msg_count NUMBER;
8193 l_wms_msg_data VARCHAR2(400);
8194 lorgid NUMBER; -- For Bug 2110031
8195 --WMS lot serial support
8196 l_orig_trx_id rcv_transactions_interface.interface_transaction_id%TYPE;
8197 l_ls_table inv_rcv_integration_apis.child_rec_tb_tp;
8198 l_ls_table_idx BINARY_INTEGER := 0;
8199 l_api_version NUMBER := 1.0;
8200 l_return_status VARCHAR2(1);
8201 l_msg_count NUMBER;
8202 l_msg_data fnd_new_messages.MESSAGE_TEXT%TYPE;
8203 l_group_id rcv_transactions_interface.GROUP_ID%TYPE;
8204 l_header_interface_id rcv_transactions_interface.header_interface_id%TYPE;
8205 l_interface_transaction_id rcv_transactions_interface.interface_transaction_id%TYPE;
8206 l_return BOOLEAN := TRUE;
8207 l_message VARCHAR2(2000);
8208 BEGIN
8209 IF v_trans_tab.COUNT > 0 THEN --{
8210 i := v_trans_tab.FIRST;
8211 e_o_t := v_trans_tab.LAST;
8212 v_current_interface_id := -999;
8213 v_prior_interface_id := -999;
8214
8215 /* Delete only once from the rcv_transactions_interface table for every
8216 group of pl/sql table rows that have the same interface id */
8217 FOR j IN i .. e_o_t LOOP
8218 asn_debug.put_line('Transaction Type ' || v_trans_tab(j).transaction_type);
8219 v_current_interface_id := v_trans_tab(j).interface_transaction_id;
8220 l_ls_table_idx := l_ls_table.COUNT + 1;
8221
8222 /* SELECT GROUP_SEQUENCE_ID_S.nextval into V_TRANS_TAB(j).GROUP_ID
8223 from dual; -- Check whether this has to be unique */
8224 -- Will use the group_id from the header_record as the pre-processor
8225 -- needs the header and transactions group id to be the same
8226 IF (v_trans_tab(j).transaction_type IN('RECEIVE', 'SHIP')) THEN
8227 v_trans_tab(j).GROUP_ID := v_header_record.header_record.GROUP_ID;
8228 END IF;
8229
8230 asn_debug.put_line('Group id ' || TO_CHAR(v_trans_tab(j).GROUP_ID));
8231 /* Assigning to_organization_id to lorgid which is passed
8232 as a parameter to WMS_INSTALL function .Also added
8233 debug messages .*/
8234 lorgid := v_trans_tab(j).to_organization_id;
8235 asn_debug.put_line('organization id ' || TO_CHAR(v_trans_tab(j).to_organization_id));
8236 asn_debug.put_line('lorgid ' || TO_CHAR(lorgid));
8237
8238 IF v_current_interface_id <> v_prior_interface_id THEN
8239 asn_debug.put_line('Handle the original interface id ' || TO_CHAR(v_trans_tab(j).interface_transaction_id));
8240 asn_debug.put_line('delete from rcv_transactions_interface rowid ' || v_trans_tab(j).row_id);
8241 asn_debug.put_line('matching_basis=' || v_trans_tab(j).matching_basis);
8242
8243 /* WMS Changes */
8244 IF v_trans_tab(j).matching_basis <> 'AMOUNT' THEN
8245 l_orig_trx_id := v_trans_tab(j).interface_transaction_id;
8246 -- add to lot serial table
8247 l_ls_table(l_ls_table_idx).orig_interface_trx_id := l_orig_trx_id;
8248 l_ls_table(l_ls_table_idx).new_interface_trx_id := l_orig_trx_id;
8249 l_ls_table(l_ls_table_idx).quantity := v_trans_tab(j).quantity;
8250 END IF;
8251
8252 IF (g_asn_debug = 'Y') THEN
8253 asn_debug.put_line('Deleting RTI ' || v_trans_tab(j).interface_transaction_id);
8254 END IF;
8255
8256 rcv_trx_interface_delete_pkg.delete_row(v_trans_tab(j).row_id);
8257 /* V_TRANS_TAB(j).INTERFACE_TRANSACTION_ID := NULL; */ -- need to maintain the interface transaction id
8258 -- for error reporting
8259 x_rowid := NULL;
8260
8261 /* FPJ WMS.
8262 * lpn_group_id should not be null if there is lpn info.
8263 */
8264 IF ( ( v_trans_tab(j).lpn_id IS NOT NULL
8265 OR v_trans_tab(j).transfer_lpn_id IS NOT NULL
8266 OR v_trans_tab(j).license_plate_number IS NOT NULL
8267 OR v_trans_tab(j).transfer_license_plate_number IS NOT NULL)
8268 AND v_trans_tab(j).lpn_group_id IS NULL
8269 ) THEN
8270 SELECT rcv_interface_groups_s.NEXTVAL
8271 INTO v_trans_tab(j).lpn_group_id
8272 FROM DUAL;
8273 END IF;
8274
8275 IF (g_asn_debug = 'Y') THEN
8276 asn_debug.put_line('Inserting new RTI');
8277 asn_debug.put_line('category_id ' || v_trans_tab(j).category_id);
8278 asn_debug.put_line('quantity ' || v_trans_tab(j).quantity);
8279 asn_debug.put_line('amount ' || v_trans_tab(j).amount);
8280 asn_debug.put_line('unit_of_measure ' || v_trans_tab(j).unit_of_measure);
8281 asn_debug.put_line('interface_source_code ' || v_trans_tab(j).interface_source_code);
8282 asn_debug.put_line('interface_source_line_id ' || v_trans_tab(j).interface_source_line_id);
8283 asn_debug.put_line('inv_transaction_id ' || v_trans_tab(j).inv_transaction_id);
8284 asn_debug.put_line('item_id ' || v_trans_tab(j).item_id);
8285 asn_debug.put_line('item_description ' || v_trans_tab(j).item_description);
8286 asn_debug.put_line('item_revision ' || v_trans_tab(j).item_revision);
8287 asn_debug.put_line('uom_code ' || v_trans_tab(j).uom_code);
8288 asn_debug.put_line('employee_id ' || v_trans_tab(j).employee_id);
8289 asn_debug.put_line('auto_transact_code ' || v_trans_tab(j).auto_transact_code);
8290 asn_debug.put_line('shipment_header_id ' || v_trans_tab(j).shipment_header_id);
8291 asn_debug.put_line('shipment_header_id ' || v_header_record.header_record.receipt_header_id);
8292 asn_debug.put_line('shipment_line_id ' || v_trans_tab(j).shipment_line_id);
8293 asn_debug.put_line('ship_to_location_id ' || v_trans_tab(j).ship_to_location_id);
8294 asn_debug.put_line('primary_quantity ' || v_trans_tab(j).primary_quantity);
8295 asn_debug.put_line('primary_unit_of_measure ' || v_trans_tab(j).primary_unit_of_measure);
8296 asn_debug.put_line('receipt_source_code ' || v_trans_tab(j).receipt_source_code);
8297 asn_debug.put_line('vendor_id ' || v_trans_tab(j).vendor_id);
8298 asn_debug.put_line('vendor_site_id ' || v_trans_tab(j).vendor_site_id);
8299 asn_debug.put_line('from_organization_id ' || v_trans_tab(j).from_organization_id);
8300 asn_debug.put_line('from_subinventory ' || v_trans_tab(j).from_subinventory);
8301 asn_debug.put_line('to_organization_id ' || v_trans_tab(j).to_organization_id);
8302 asn_debug.put_line('intransit_owning_org_id ' || v_trans_tab(j).intransit_owning_org_id);
8303 asn_debug.put_line('routing_header_id ' || v_trans_tab(j).routing_header_id);
8304 asn_debug.put_line('routing_step_id ' || v_trans_tab(j).routing_step_id);
8305 asn_debug.put_line('source_document_code ' || v_trans_tab(j).source_document_code);
8306 asn_debug.put_line('parent_transaction_id ' || v_trans_tab(j).parent_transaction_id);
8307 asn_debug.put_line('po_header_id ' || v_trans_tab(j).po_header_id);
8308 asn_debug.put_line('po_revision_num ' || v_trans_tab(j).po_revision_num);
8309 asn_debug.put_line('po_line_id ' || v_trans_tab(j).po_line_id);
8310 asn_debug.put_line('po_line_location_id ' || v_trans_tab(j).po_line_location_id);
8311 asn_debug.put_line('po_unit_price ' || v_trans_tab(j).po_unit_price);
8312 asn_debug.put_line('currency_code ' || v_trans_tab(j).currency_code);
8313 asn_debug.put_line('currency_conversion_type ' || v_trans_tab(j).currency_conversion_type);
8314 asn_debug.put_line('currency_conversion_rate ' || v_trans_tab(j).currency_conversion_rate);
8315 asn_debug.put_line('currency_conversion_date ' || TO_CHAR(v_trans_tab(j).currency_conversion_date, 'DD-MON-YYYY HH24:MI:SS'));
8316 asn_debug.put_line('po_distribution_id ' || v_trans_tab(j).po_distribution_id);
8317 asn_debug.put_line('requisition_line_id ' || v_trans_tab(j).requisition_line_id);
8318 asn_debug.put_line('req_distribution_id ' || v_trans_tab(j).req_distribution_id);
8319 asn_debug.put_line('charge_account_id ' || v_trans_tab(j).charge_account_id);
8320 asn_debug.put_line('substitute_unordered_code ' || v_trans_tab(j).substitute_unordered_code);
8321 asn_debug.put_line('receipt_exception_flag ' || v_trans_tab(j).receipt_exception_flag);
8322 asn_debug.put_line('accrual_status_code ' || v_trans_tab(j).accrual_status_code);
8323 asn_debug.put_line('inspection_status_code ' || v_trans_tab(j).inspection_status_code);
8324 asn_debug.put_line('inspection_quality_code ' || v_trans_tab(j).inspection_quality_code);
8325 asn_debug.put_line('destination_type_code ' || v_trans_tab(j).destination_type_code);
8326 asn_debug.put_line('deliver_to_person_id ' || v_trans_tab(j).deliver_to_person_id);
8327 asn_debug.put_line('location_id ' || v_trans_tab(j).location_id);
8328 asn_debug.put_line('deliver_to_location_id ' || v_trans_tab(j).deliver_to_location_id);
8329 asn_debug.put_line('subinventory ' || v_trans_tab(j).subinventory);
8330 asn_debug.put_line('locator_id ' || v_trans_tab(j).locator_id);
8331 asn_debug.put_line('wip_entity_id ' || v_trans_tab(j).wip_entity_id);
8332 asn_debug.put_line('wip_line_id ' || v_trans_tab(j).wip_line_id);
8333 asn_debug.put_line('shipment_num ' || v_trans_tab(j).shipment_num);
8334 asn_debug.put_line('source_doc_quantity ' || v_trans_tab(j).source_doc_quantity);
8335 asn_debug.put_line('from_locator_id ' || v_trans_tab(j).from_locator_id);
8336 asn_debug.put_line('oe_order_header_id ' || v_trans_tab(j).oe_order_header_id);
8337 asn_debug.put_line('oe_order_line_id ' || v_trans_tab(j).oe_order_line_id);
8338 asn_debug.put_line('customer_id ' || v_trans_tab(j).customer_id);
8339 asn_debug.put_line('customer_site_id ' || v_trans_tab(j).customer_site_id);
8340 asn_debug.put_line('lpn_id ' || v_trans_tab(j).lpn_id);
8341 asn_debug.put_line('transfer_lpn_id ' || v_trans_tab(j).transfer_lpn_id);
8342 asn_debug.put_line('lpn_group_id ' || v_trans_tab(j).lpn_group_id);
8343 asn_debug.put_line('project_id ' || v_trans_tab(j).project_id);
8344 asn_debug.put_line('task_id ' || v_trans_tab(j).task_id);
8345 asn_debug.put_line('timecard_id ' ||
8346 v_trans_tab(j).timecard_id);
8347 asn_debug.put_line('timecard_ovn ' ||
8348 v_trans_tab(j).timecard_ovn);
8349 asn_debug.put_line('org_id ' || v_trans_tab(j).org_id); --<R12 MOAC>
8350
8351 asn_debug.put_line('matching_basis ' ||
8352 v_trans_tab(j).matching_basis);
8353 asn_debug.put_line('amount_shipped ' ||
8354 v_trans_tab(j).amount_shipped);
8355 asn_debug.put_line('requested_amount ' ||
8356 v_trans_tab(j).requested_amount);
8357 asn_debug.put_line('material_stored_amount ' ||
8358 v_trans_tab(j).material_stored_amount);
8359 asn_debug.put_line('replenish_order_line_id' ||
8360 v_trans_tab(j).replenish_order_line_id);
8361 asn_debug.put_line('lcm_shipment_line_id' || v_trans_tab(j).lcm_shipment_line_id);
8362 asn_debug.put_line('unit_landed_cost' || v_trans_tab(j).unit_landed_cost);
8363
8364 END IF;
8365
8366 rcv_asn_interface_trx_ins_pkg.insert_row(v_trans_tab(j).row_id,
8367 v_trans_tab(j).interface_transaction_id,
8368 v_trans_tab(j).GROUP_ID,
8369 v_trans_tab(j).last_update_date,
8370 v_trans_tab(j).last_updated_by,
8371 v_trans_tab(j).creation_date,
8372 v_trans_tab(j).created_by,
8373 v_trans_tab(j).last_update_login,
8374 v_trans_tab(j).request_id,
8375 v_trans_tab(j).program_application_id,
8376 v_trans_tab(j).program_id,
8377 v_trans_tab(j).program_update_date,
8378 v_trans_tab(j).transaction_type,
8379 v_trans_tab(j).transaction_date,
8380 v_trans_tab(j).processing_status_code,
8381 v_trans_tab(j).processing_mode_code,
8382 v_trans_tab(j).processing_request_id,
8383 v_trans_tab(j).transaction_status_code,
8384 v_trans_tab(j).category_id,
8385 v_trans_tab(j).quantity,
8386 v_trans_tab(j).unit_of_measure,
8387 v_trans_tab(j).interface_source_code,
8388 v_trans_tab(j).interface_source_line_id,
8389 v_trans_tab(j).inv_transaction_id,
8390 v_trans_tab(j).item_id,
8391 v_trans_tab(j).item_description,
8392 v_trans_tab(j).item_revision,
8393 v_trans_tab(j).uom_code,
8394 v_trans_tab(j).employee_id,
8395 v_trans_tab(j).auto_transact_code,
8396 NVL(v_trans_tab(j).shipment_header_id, v_header_record.header_record.receipt_header_id),
8397 v_trans_tab(j).shipment_line_id,
8398 v_trans_tab(j).ship_to_location_id,
8399 v_trans_tab(j).primary_quantity,
8400 v_trans_tab(j).primary_unit_of_measure,
8401 v_trans_tab(j).receipt_source_code,
8402 v_trans_tab(j).vendor_id,
8403 v_trans_tab(j).vendor_site_id,
8404 v_trans_tab(j).from_organization_id,
8405 v_trans_tab(j).from_subinventory,
8406 v_trans_tab(j).to_organization_id,
8407 v_trans_tab(j).intransit_owning_org_id,
8408 v_trans_tab(j).routing_header_id,
8409 v_trans_tab(j).routing_step_id,
8410 v_trans_tab(j).source_document_code,
8411 v_trans_tab(j).parent_transaction_id,
8412 v_trans_tab(j).po_header_id,
8413 v_trans_tab(j).po_revision_num,
8414 v_trans_tab(j).po_release_id,
8415 v_trans_tab(j).po_line_id,
8416 v_trans_tab(j).po_line_location_id,
8417 v_trans_tab(j).po_unit_price,
8418 v_trans_tab(j).currency_code,
8419 v_trans_tab(j).currency_conversion_type,
8420 v_trans_tab(j).currency_conversion_rate,
8421 v_trans_tab(j).currency_conversion_date,
8422 v_trans_tab(j).po_distribution_id,
8423 v_trans_tab(j).requisition_line_id,
8424 v_trans_tab(j).req_distribution_id,
8425 v_trans_tab(j).charge_account_id,
8426 v_trans_tab(j).substitute_unordered_code,
8427 v_trans_tab(j).receipt_exception_flag,
8428 v_trans_tab(j).accrual_status_code,
8429 v_trans_tab(j).inspection_status_code,
8430 v_trans_tab(j).inspection_quality_code,
8431 v_trans_tab(j).destination_type_code,
8432 v_trans_tab(j).deliver_to_person_id,
8433 v_trans_tab(j).location_id,
8434 v_trans_tab(j).deliver_to_location_id,
8435 v_trans_tab(j).subinventory,
8436 v_trans_tab(j).locator_id,
8437 v_trans_tab(j).wip_entity_id,
8438 v_trans_tab(j).wip_line_id,
8439 v_trans_tab(j).department_code,
8440 v_trans_tab(j).wip_repetitive_schedule_id,
8441 v_trans_tab(j).wip_operation_seq_num,
8442 v_trans_tab(j).wip_resource_seq_num,
8443 v_trans_tab(j).bom_resource_id,
8444 v_trans_tab(j).shipment_num,
8445 v_trans_tab(j).freight_carrier_code,
8446 v_trans_tab(j).bill_of_lading,
8447 v_trans_tab(j).packing_slip,
8448 v_trans_tab(j).shipped_date,
8449 v_trans_tab(j).expected_receipt_date,
8450 v_trans_tab(j).actual_cost,
8451 v_trans_tab(j).transfer_cost,
8452 v_trans_tab(j).transportation_cost,
8453 v_trans_tab(j).transportation_account_id,
8454 v_trans_tab(j).num_of_containers,
8455 v_trans_tab(j).waybill_airbill_num,
8456 v_trans_tab(j).vendor_item_num,
8457 v_trans_tab(j).vendor_lot_num,
8458 v_trans_tab(j).rma_reference,
8459 v_trans_tab(j).comments,
8460 v_trans_tab(j).attribute_category,
8461 v_trans_tab(j).attribute1,
8462 v_trans_tab(j).attribute2,
8463 v_trans_tab(j).attribute3,
8464 v_trans_tab(j).attribute4,
8465 v_trans_tab(j).attribute5,
8466 v_trans_tab(j).attribute6,
8467 v_trans_tab(j).attribute7,
8468 v_trans_tab(j).attribute8,
8469 v_trans_tab(j).attribute9,
8470 v_trans_tab(j).attribute10,
8471 v_trans_tab(j).attribute11,
8472 v_trans_tab(j).attribute12,
8473 v_trans_tab(j).attribute13,
8474 v_trans_tab(j).attribute14,
8475 v_trans_tab(j).attribute15,
8476 v_trans_tab(j).ship_head_attribute_category,
8477 v_trans_tab(j).ship_head_attribute1,
8478 v_trans_tab(j).ship_head_attribute2,
8479 v_trans_tab(j).ship_head_attribute3,
8480 v_trans_tab(j).ship_head_attribute4,
8481 v_trans_tab(j).ship_head_attribute5,
8482 v_trans_tab(j).ship_head_attribute6,
8483 v_trans_tab(j).ship_head_attribute7,
8484 v_trans_tab(j).ship_head_attribute8,
8485 v_trans_tab(j).ship_head_attribute9,
8486 v_trans_tab(j).ship_head_attribute10,
8487 v_trans_tab(j).ship_head_attribute11,
8488 v_trans_tab(j).ship_head_attribute12,
8489 v_trans_tab(j).ship_head_attribute13,
8490 v_trans_tab(j).ship_head_attribute14,
8491 v_trans_tab(j).ship_head_attribute15,
8492 v_trans_tab(j).ship_line_attribute_category,
8493 v_trans_tab(j).ship_line_attribute1,
8494 v_trans_tab(j).ship_line_attribute2,
8495 v_trans_tab(j).ship_line_attribute3,
8496 v_trans_tab(j).ship_line_attribute4,
8497 v_trans_tab(j).ship_line_attribute5,
8498 v_trans_tab(j).ship_line_attribute6,
8499 v_trans_tab(j).ship_line_attribute7,
8500 v_trans_tab(j).ship_line_attribute8,
8501 v_trans_tab(j).ship_line_attribute9,
8502 v_trans_tab(j).ship_line_attribute10,
8503 v_trans_tab(j).ship_line_attribute11,
8504 v_trans_tab(j).ship_line_attribute12,
8505 v_trans_tab(j).ship_line_attribute13,
8506 v_trans_tab(j).ship_line_attribute14,
8507 v_trans_tab(j).ship_line_attribute15,
8508 v_trans_tab(j).ussgl_transaction_code,
8509 v_trans_tab(j).government_context,
8510 v_trans_tab(j).reason_id,
8511 v_trans_tab(j).destination_context,
8512 v_trans_tab(j).source_doc_quantity,
8513 v_trans_tab(j).source_doc_unit_of_measure,
8514 v_trans_tab(j).movement_id,
8515 v_trans_tab(j).header_interface_id,
8516 v_trans_tab(j).vendor_cum_shipped_qty,
8517 v_trans_tab(j).item_num,
8518 v_trans_tab(j).document_num,
8519 v_trans_tab(j).document_line_num,
8520 v_trans_tab(j).truck_num,
8521 v_trans_tab(j).ship_to_location_code,
8522 v_trans_tab(j).container_num,
8523 v_trans_tab(j).substitute_item_num,
8524 v_trans_tab(j).notice_unit_price,
8525 v_trans_tab(j).item_category,
8526 v_trans_tab(j).location_code,
8527 v_trans_tab(j).vendor_name,
8528 v_trans_tab(j).vendor_num,
8529 v_trans_tab(j).vendor_site_code,
8530 v_trans_tab(j).from_organization_code,
8531 v_trans_tab(j).to_organization_code,
8532 v_trans_tab(j).intransit_owning_org_code,
8533 v_trans_tab(j).routing_code,
8534 v_trans_tab(j).routing_step,
8535 v_trans_tab(j).release_num,
8536 v_trans_tab(j).document_shipment_line_num,
8537 v_trans_tab(j).document_distribution_num,
8538 v_trans_tab(j).deliver_to_person_name,
8539 v_trans_tab(j).deliver_to_location_code,
8540 v_trans_tab(j).use_mtl_lot,
8541 v_trans_tab(j).use_mtl_serial,
8542 v_trans_tab(j).LOCATOR,
8543 v_trans_tab(j).reason_name,
8544 v_trans_tab(j).validation_flag,
8545 v_trans_tab(j).substitute_item_id,
8546 v_trans_tab(j).quantity_shipped,
8547 v_trans_tab(j).quantity_invoiced,
8548 v_trans_tab(j).tax_name,
8549 v_trans_tab(j).tax_amount,
8550 v_trans_tab(j).req_num,
8551 v_trans_tab(j).req_line_num,
8552 v_trans_tab(j).req_distribution_num,
8553 v_trans_tab(j).wip_entity_name,
8554 v_trans_tab(j).wip_line_code,
8555 v_trans_tab(j).resource_code,
8556 v_trans_tab(j).shipment_line_status_code,
8557 v_trans_tab(j).barcode_label,
8558 v_trans_tab(j).country_of_origin_code,
8559 v_trans_tab(j).from_locator_id, --WMS Change
8560 v_trans_tab(j).qa_collection_id,
8561 v_trans_tab(j).oe_order_header_id,
8562 v_trans_tab(j).oe_order_line_id,
8563 v_trans_tab(j).customer_id,
8564 v_trans_tab(j).customer_site_id,
8565 v_trans_tab(j).customer_item_num,
8566 v_trans_tab(j).create_debit_memo_flag,
8567 v_trans_tab(j).put_away_rule_id,
8568 v_trans_tab(j).put_away_strategy_id,
8569 v_trans_tab(j).lpn_id,
8570 v_trans_tab(j).transfer_lpn_id,
8571 v_trans_tab(j).cost_group_id,
8572 v_trans_tab(j).mobile_txn,
8573 v_trans_tab(j).mmtt_temp_id,
8574 v_trans_tab(j).transfer_cost_group_id,
8575 v_trans_tab(j).secondary_quantity,
8576 v_trans_tab(j).secondary_unit_of_measure,
8577 v_trans_tab(j).secondary_uom_code,
8578 v_trans_tab(j).qc_grade,
8579 v_trans_tab(j).oe_order_num,
8580 v_trans_tab(j).oe_order_line_num,
8581 v_trans_tab(j).customer_account_number,
8582 v_trans_tab(j).customer_party_name,
8583 v_trans_tab(j).source_transaction_num,
8584 v_trans_tab(j).parent_source_transaction_num,
8585 v_trans_tab(j).parent_interface_txn_id,
8586 v_trans_tab(j).customer_item_id,
8587 v_trans_tab(j).interface_available_qty,
8588 v_trans_tab(j).interface_transaction_qty,
8589 v_trans_tab(j).from_locator,
8590 v_trans_tab(j).lpn_group_id,
8591 v_trans_tab(j).order_transaction_id,
8592 v_trans_tab(j).license_plate_number,
8593 v_trans_tab(j).transfer_license_plate_number,
8594 v_trans_tab(j).amount,
8595 v_trans_tab(j).job_id,
8596 v_trans_tab(j).project_id,
8597 v_trans_tab(j).task_id,
8598 v_trans_tab(j).asn_attach_id,
8599 v_trans_tab(j).timecard_id,
8600 v_trans_tab(j).timecard_ovn,
8601 v_trans_tab(j).interface_available_amt,
8602 v_trans_tab(j).interface_transaction_amt,
8603 v_trans_tab(j).org_id, --<R12 MOAC>
8604 v_trans_tab(j).matching_basis,
8605 v_trans_tab(j).amount_shipped,
8606 v_trans_tab(j).requested_amount,
8607 v_trans_tab(j).material_stored_amount,
8608 v_trans_tab(j).replenish_order_line_id,
8609 NULL,
8610 v_trans_tab(j).lcm_shipment_line_id, -- lcm changes
8611 v_trans_tab(j).unit_landed_cost -- lcm changes
8612 );
8613 asn_debug.put_line('RowId ' || v_trans_tab(j).row_id);
8614 asn_debug.put_line('Interface Id ' || TO_CHAR(v_trans_tab(j).interface_transaction_id));
8615 v_prior_interface_id := v_current_interface_id;
8616 v_trans_tab.DELETE(j);
8617 ELSE
8618 asn_debug.put_line('insert into rcv_transactions_interface with new id ');
8619 /* Since we are inserting 1-> many rows need to generate a new interface id */
8620 v_trans_tab(j).interface_transaction_id := NULL;
8621 x_rowid := NULL;
8622
8623 /* FPJ WMS.
8624 * lpn_group_id should not be null if there is lpn info. But
8625 * since this is a split line coming from the original rti line,
8626 * this has to have the same lpn group id.
8627 */
8628 IF ( ( v_trans_tab(j).lpn_id IS NOT NULL
8629 OR v_trans_tab(j).transfer_lpn_id IS NOT NULL
8630 OR v_trans_tab(j).license_plate_number IS NOT NULL
8631 OR v_trans_tab(j).transfer_license_plate_number IS NOT NULL)
8632 AND v_trans_tab(j).lpn_group_id IS NULL
8633 ) THEN
8634 SELECT rcv_interface_groups_s.CURRVAL
8635 INTO v_trans_tab(j).lpn_group_id
8636 FROM DUAL;
8637 END IF;
8638
8639 IF (g_asn_debug = 'Y') THEN
8640 asn_debug.put_line('category_id ' || v_trans_tab(j).category_id);
8641 asn_debug.put_line('quantity ' || v_trans_tab(j).quantity);
8642 asn_debug.put_line('amount ' || v_trans_tab(j).amount);
8643 asn_debug.put_line('unit_of_measure ' || v_trans_tab(j).unit_of_measure);
8644 asn_debug.put_line('interface_source_code ' || v_trans_tab(j).interface_source_code);
8645 asn_debug.put_line('interface_source_line_id ' || v_trans_tab(j).interface_source_line_id);
8646 asn_debug.put_line('inv_transaction_id ' || v_trans_tab(j).inv_transaction_id);
8647 asn_debug.put_line('item_id ' || v_trans_tab(j).item_id);
8648 asn_debug.put_line('item_description ' || v_trans_tab(j).item_description);
8649 asn_debug.put_line('item_revision ' || v_trans_tab(j).item_revision);
8650 asn_debug.put_line('uom_code ' || v_trans_tab(j).uom_code);
8651 asn_debug.put_line('employee_id ' || v_trans_tab(j).employee_id);
8652 asn_debug.put_line('auto_transact_code ' || v_trans_tab(j).auto_transact_code);
8653 asn_debug.put_line('shipment_header_id ' || v_trans_tab(j).shipment_header_id);
8654 asn_debug.put_line('shipment_header_id ' || v_header_record.header_record.receipt_header_id);
8655 asn_debug.put_line('shipment_line_id ' || v_trans_tab(j).shipment_line_id);
8656 asn_debug.put_line('ship_to_location_id ' || v_trans_tab(j).ship_to_location_id);
8657 asn_debug.put_line('primary_quantity ' || v_trans_tab(j).primary_quantity);
8658 asn_debug.put_line('primary_unit_of_measure ' || v_trans_tab(j).primary_unit_of_measure);
8659 asn_debug.put_line('receipt_source_code ' || v_trans_tab(j).receipt_source_code);
8660 asn_debug.put_line('vendor_id ' || v_trans_tab(j).vendor_id);
8661 asn_debug.put_line('vendor_site_id ' || v_trans_tab(j).vendor_site_id);
8662 asn_debug.put_line('from_organization_id ' || v_trans_tab(j).from_organization_id);
8663 asn_debug.put_line('from_subinventory ' || v_trans_tab(j).from_subinventory);
8664 asn_debug.put_line('to_organization_id ' || v_trans_tab(j).to_organization_id);
8665 asn_debug.put_line('intransit_owning_org_id ' || v_trans_tab(j).intransit_owning_org_id);
8666 asn_debug.put_line('routing_header_id ' || v_trans_tab(j).routing_header_id);
8667 asn_debug.put_line('routing_step_id ' || v_trans_tab(j).routing_step_id);
8668 asn_debug.put_line('source_document_code ' || v_trans_tab(j).source_document_code);
8669 asn_debug.put_line('parent_transaction_id ' || v_trans_tab(j).parent_transaction_id);
8670 asn_debug.put_line('po_header_id ' || v_trans_tab(j).po_header_id);
8671 asn_debug.put_line('po_revision_num ' || v_trans_tab(j).po_revision_num);
8672 asn_debug.put_line('po_line_id ' || v_trans_tab(j).po_line_id);
8673 asn_debug.put_line('po_line_location_id ' || v_trans_tab(j).po_line_location_id);
8674 asn_debug.put_line('po_unit_price ' || v_trans_tab(j).po_unit_price);
8675 asn_debug.put_line('currency_code ' || v_trans_tab(j).currency_code);
8676 asn_debug.put_line('currency_conversion_type ' || v_trans_tab(j).currency_conversion_type);
8677 asn_debug.put_line('currency_conversion_rate ' || v_trans_tab(j).currency_conversion_rate);
8678 asn_debug.put_line('currency_conversion_date ' || TO_CHAR(v_trans_tab(j).currency_conversion_date, 'DD-MON-YYYY HH24:MI:SS'));
8679 asn_debug.put_line('po_distribution_id ' || v_trans_tab(j).po_distribution_id);
8680 asn_debug.put_line('requisition_line_id ' || v_trans_tab(j).requisition_line_id);
8681 asn_debug.put_line('req_distribution_id ' || v_trans_tab(j).req_distribution_id);
8682 asn_debug.put_line('charge_account_id ' || v_trans_tab(j).charge_account_id);
8683 asn_debug.put_line('substitute_unordered_code ' || v_trans_tab(j).substitute_unordered_code);
8684 asn_debug.put_line('receipt_exception_flag ' || v_trans_tab(j).receipt_exception_flag);
8685 asn_debug.put_line('accrual_status_code ' || v_trans_tab(j).accrual_status_code);
8686 asn_debug.put_line('inspection_status_code ' || v_trans_tab(j).inspection_status_code);
8687 asn_debug.put_line('inspection_quality_code ' || v_trans_tab(j).inspection_quality_code);
8688 asn_debug.put_line('destination_type_code ' || v_trans_tab(j).destination_type_code);
8689 asn_debug.put_line('deliver_to_person_id ' || v_trans_tab(j).deliver_to_person_id);
8690 asn_debug.put_line('location_id ' || v_trans_tab(j).location_id);
8691 asn_debug.put_line('deliver_to_location_id ' || v_trans_tab(j).deliver_to_location_id);
8692 asn_debug.put_line('subinventory ' || v_trans_tab(j).subinventory);
8693 asn_debug.put_line('locator_id ' || v_trans_tab(j).locator_id);
8694 asn_debug.put_line('wip_entity_id ' || v_trans_tab(j).wip_entity_id);
8695 asn_debug.put_line('wip_line_id ' || v_trans_tab(j).wip_line_id);
8696 asn_debug.put_line('shipment_num ' || v_trans_tab(j).shipment_num);
8697 asn_debug.put_line('source_doc_quantity ' || v_trans_tab(j).source_doc_quantity);
8698 asn_debug.put_line('from_locator_id ' || v_trans_tab(j).from_locator_id);
8699 asn_debug.put_line('oe_order_header_id ' || v_trans_tab(j).oe_order_header_id);
8700 asn_debug.put_line('oe_order_line_id ' || v_trans_tab(j).oe_order_line_id);
8701 asn_debug.put_line('customer_id ' || v_trans_tab(j).customer_id);
8702 asn_debug.put_line('customer_site_id ' || v_trans_tab(j).customer_site_id);
8703 asn_debug.put_line('lpn_id ' || v_trans_tab(j).lpn_id);
8704 asn_debug.put_line('transfer_lpn_id ' || v_trans_tab(j).transfer_lpn_id);
8705 asn_debug.put_line('lpn_group_id ' || v_trans_tab(j).lpn_group_id);
8706 asn_debug.put_line('project_id ' || v_trans_tab(j).project_id);
8707 asn_debug.put_line('task_id ' || v_trans_tab(j).task_id);
8708 asn_debug.put_line('timecard_id ' || v_trans_tab(j).timecard_id);
8709 asn_debug.put_line('timecard_ovn ' || v_trans_tab(j).timecard_ovn);
8710 asn_debug.put_line('org_id ' || v_trans_tab(j).org_id); --<R12 MOAC>
8711 asn_debug.put_line('matching_basis ' ||
8712 v_trans_tab(j).matching_basis);
8713 asn_debug.put_line('amount_shipped ' ||
8714 v_trans_tab(j).amount_shipped);
8715 asn_debug.put_line('requested_amount ' ||
8716 v_trans_tab(j).requested_amount);
8717 asn_debug.put_line('material_stored_amount ' ||
8718 v_trans_tab(j).material_stored_amount);
8719 asn_debug.put_line('replenish_order_line_id' ||
8720 v_trans_tab(j).replenish_order_line_id);
8721 END IF;
8722
8723 rcv_asn_interface_trx_ins_pkg.insert_row(v_trans_tab(j).row_id,
8724 v_trans_tab(j).interface_transaction_id,
8725 v_trans_tab(j).GROUP_ID,
8726 v_trans_tab(j).last_update_date,
8727 v_trans_tab(j).last_updated_by,
8728 v_trans_tab(j).creation_date,
8729 v_trans_tab(j).created_by,
8730 v_trans_tab(j).last_update_login,
8731 v_trans_tab(j).request_id,
8732 v_trans_tab(j).program_application_id,
8733 v_trans_tab(j).program_id,
8734 v_trans_tab(j).program_update_date,
8735 v_trans_tab(j).transaction_type,
8736 v_trans_tab(j).transaction_date,
8737 v_trans_tab(j).processing_status_code,
8738 v_trans_tab(j).processing_mode_code,
8739 v_trans_tab(j).processing_request_id,
8740 v_trans_tab(j).transaction_status_code,
8741 v_trans_tab(j).category_id,
8742 v_trans_tab(j).quantity,
8743 v_trans_tab(j).unit_of_measure,
8744 v_trans_tab(j).interface_source_code,
8745 v_trans_tab(j).interface_source_line_id,
8746 v_trans_tab(j).inv_transaction_id,
8747 v_trans_tab(j).item_id,
8748 v_trans_tab(j).item_description,
8749 v_trans_tab(j).item_revision,
8750 v_trans_tab(j).uom_code,
8751 v_trans_tab(j).employee_id,
8752 v_trans_tab(j).auto_transact_code,
8753 NVL(v_trans_tab(j).shipment_header_id, v_header_record.header_record.receipt_header_id),
8754 v_trans_tab(j).shipment_line_id,
8755 v_trans_tab(j).ship_to_location_id,
8756 v_trans_tab(j).primary_quantity,
8757 v_trans_tab(j).primary_unit_of_measure,
8758 v_trans_tab(j).receipt_source_code,
8759 v_trans_tab(j).vendor_id,
8760 v_trans_tab(j).vendor_site_id,
8761 v_trans_tab(j).from_organization_id,
8762 v_trans_tab(j).from_subinventory,
8763 v_trans_tab(j).to_organization_id,
8764 v_trans_tab(j).intransit_owning_org_id,
8765 v_trans_tab(j).routing_header_id,
8766 v_trans_tab(j).routing_step_id,
8767 v_trans_tab(j).source_document_code,
8768 v_trans_tab(j).parent_transaction_id,
8769 v_trans_tab(j).po_header_id,
8770 v_trans_tab(j).po_revision_num,
8771 v_trans_tab(j).po_release_id,
8772 v_trans_tab(j).po_line_id,
8773 v_trans_tab(j).po_line_location_id,
8774 v_trans_tab(j).po_unit_price,
8775 v_trans_tab(j).currency_code,
8776 v_trans_tab(j).currency_conversion_type,
8777 v_trans_tab(j).currency_conversion_rate,
8778 v_trans_tab(j).currency_conversion_date,
8779 v_trans_tab(j).po_distribution_id,
8780 v_trans_tab(j).requisition_line_id,
8781 v_trans_tab(j).req_distribution_id,
8782 v_trans_tab(j).charge_account_id,
8783 v_trans_tab(j).substitute_unordered_code,
8784 v_trans_tab(j).receipt_exception_flag,
8785 v_trans_tab(j).accrual_status_code,
8786 v_trans_tab(j).inspection_status_code,
8787 v_trans_tab(j).inspection_quality_code,
8788 v_trans_tab(j).destination_type_code,
8789 v_trans_tab(j).deliver_to_person_id,
8790 v_trans_tab(j).location_id,
8791 v_trans_tab(j).deliver_to_location_id,
8792 v_trans_tab(j).subinventory,
8793 v_trans_tab(j).locator_id,
8794 v_trans_tab(j).wip_entity_id,
8795 v_trans_tab(j).wip_line_id,
8796 v_trans_tab(j).department_code,
8797 v_trans_tab(j).wip_repetitive_schedule_id,
8798 v_trans_tab(j).wip_operation_seq_num,
8799 v_trans_tab(j).wip_resource_seq_num,
8800 v_trans_tab(j).bom_resource_id,
8801 v_trans_tab(j).shipment_num,
8802 v_trans_tab(j).freight_carrier_code,
8803 v_trans_tab(j).bill_of_lading,
8804 v_trans_tab(j).packing_slip,
8805 v_trans_tab(j).shipped_date,
8806 v_trans_tab(j).expected_receipt_date,
8807 v_trans_tab(j).actual_cost,
8808 v_trans_tab(j).transfer_cost,
8809 v_trans_tab(j).transportation_cost,
8810 v_trans_tab(j).transportation_account_id,
8811 v_trans_tab(j).num_of_containers,
8812 v_trans_tab(j).waybill_airbill_num,
8813 v_trans_tab(j).vendor_item_num,
8814 v_trans_tab(j).vendor_lot_num,
8815 v_trans_tab(j).rma_reference,
8816 v_trans_tab(j).comments,
8817 v_trans_tab(j).attribute_category,
8818 v_trans_tab(j).attribute1,
8819 v_trans_tab(j).attribute2,
8820 v_trans_tab(j).attribute3,
8821 v_trans_tab(j).attribute4,
8822 v_trans_tab(j).attribute5,
8823 v_trans_tab(j).attribute6,
8824 v_trans_tab(j).attribute7,
8825 v_trans_tab(j).attribute8,
8826 v_trans_tab(j).attribute9,
8827 v_trans_tab(j).attribute10,
8828 v_trans_tab(j).attribute11,
8829 v_trans_tab(j).attribute12,
8830 v_trans_tab(j).attribute13,
8831 v_trans_tab(j).attribute14,
8832 v_trans_tab(j).attribute15,
8833 v_trans_tab(j).ship_head_attribute_category,
8834 v_trans_tab(j).ship_head_attribute1,
8835 v_trans_tab(j).ship_head_attribute2,
8836 v_trans_tab(j).ship_head_attribute3,
8837 v_trans_tab(j).ship_head_attribute4,
8838 v_trans_tab(j).ship_head_attribute5,
8839 v_trans_tab(j).ship_head_attribute6,
8840 v_trans_tab(j).ship_head_attribute7,
8841 v_trans_tab(j).ship_head_attribute8,
8842 v_trans_tab(j).ship_head_attribute9,
8843 v_trans_tab(j).ship_head_attribute10,
8844 v_trans_tab(j).ship_head_attribute11,
8845 v_trans_tab(j).ship_head_attribute12,
8846 v_trans_tab(j).ship_head_attribute13,
8847 v_trans_tab(j).ship_head_attribute14,
8848 v_trans_tab(j).ship_head_attribute15,
8849 v_trans_tab(j).ship_line_attribute_category,
8850 v_trans_tab(j).ship_line_attribute1,
8851 v_trans_tab(j).ship_line_attribute2,
8852 v_trans_tab(j).ship_line_attribute3,
8853 v_trans_tab(j).ship_line_attribute4,
8854 v_trans_tab(j).ship_line_attribute5,
8855 v_trans_tab(j).ship_line_attribute6,
8856 v_trans_tab(j).ship_line_attribute7,
8857 v_trans_tab(j).ship_line_attribute8,
8858 v_trans_tab(j).ship_line_attribute9,
8859 v_trans_tab(j).ship_line_attribute10,
8860 v_trans_tab(j).ship_line_attribute11,
8861 v_trans_tab(j).ship_line_attribute12,
8862 v_trans_tab(j).ship_line_attribute13,
8863 v_trans_tab(j).ship_line_attribute14,
8864 v_trans_tab(j).ship_line_attribute15,
8865 v_trans_tab(j).ussgl_transaction_code,
8866 v_trans_tab(j).government_context,
8867 v_trans_tab(j).reason_id,
8868 v_trans_tab(j).destination_context,
8869 v_trans_tab(j).source_doc_quantity,
8870 v_trans_tab(j).source_doc_unit_of_measure,
8871 v_trans_tab(j).movement_id,
8872 v_trans_tab(j).header_interface_id,
8873 v_trans_tab(j).vendor_cum_shipped_qty,
8874 v_trans_tab(j).item_num,
8875 v_trans_tab(j).document_num,
8876 v_trans_tab(j).document_line_num,
8877 v_trans_tab(j).truck_num,
8878 v_trans_tab(j).ship_to_location_code,
8879 v_trans_tab(j).container_num,
8880 v_trans_tab(j).substitute_item_num,
8881 v_trans_tab(j).notice_unit_price,
8882 v_trans_tab(j).item_category,
8883 v_trans_tab(j).location_code,
8884 v_trans_tab(j).vendor_name,
8885 v_trans_tab(j).vendor_num,
8886 v_trans_tab(j).vendor_site_code,
8887 v_trans_tab(j).from_organization_code,
8888 v_trans_tab(j).to_organization_code,
8889 v_trans_tab(j).intransit_owning_org_code,
8890 v_trans_tab(j).routing_code,
8891 v_trans_tab(j).routing_step,
8892 v_trans_tab(j).release_num,
8893 v_trans_tab(j).document_shipment_line_num,
8894 v_trans_tab(j).document_distribution_num,
8895 v_trans_tab(j).deliver_to_person_name,
8896 v_trans_tab(j).deliver_to_location_code,
8897 v_trans_tab(j).use_mtl_lot,
8898 v_trans_tab(j).use_mtl_serial,
8899 v_trans_tab(j).LOCATOR,
8900 v_trans_tab(j).reason_name,
8901 v_trans_tab(j).validation_flag,
8902 v_trans_tab(j).substitute_item_id,
8903 v_trans_tab(j).quantity_shipped,
8904 v_trans_tab(j).quantity_invoiced,
8905 v_trans_tab(j).tax_name,
8906 v_trans_tab(j).tax_amount,
8907 v_trans_tab(j).req_num,
8908 v_trans_tab(j).req_line_num,
8909 v_trans_tab(j).req_distribution_num,
8910 v_trans_tab(j).wip_entity_name,
8911 v_trans_tab(j).wip_line_code,
8912 v_trans_tab(j).resource_code,
8913 v_trans_tab(j).shipment_line_status_code,
8914 v_trans_tab(j).barcode_label,
8915 v_trans_tab(j).country_of_origin_code,
8916 v_trans_tab(j).from_locator_id, --WMS Change
8917 v_trans_tab(j).qa_collection_id,
8918 v_trans_tab(j).oe_order_header_id,
8919 v_trans_tab(j).oe_order_line_id,
8920 v_trans_tab(j).customer_id,
8921 v_trans_tab(j).customer_site_id,
8922 v_trans_tab(j).customer_item_num,
8923 v_trans_tab(j).create_debit_memo_flag,
8924 v_trans_tab(j).put_away_rule_id,
8925 v_trans_tab(j).put_away_strategy_id,
8926 v_trans_tab(j).lpn_id,
8927 v_trans_tab(j).transfer_lpn_id,
8928 v_trans_tab(j).cost_group_id,
8929 v_trans_tab(j).mobile_txn,
8930 v_trans_tab(j).mmtt_temp_id,
8931 v_trans_tab(j).transfer_cost_group_id,
8932 v_trans_tab(j).secondary_quantity,
8933 v_trans_tab(j).secondary_unit_of_measure,
8934 v_trans_tab(j).secondary_uom_code,
8935 v_trans_tab(j).qc_grade,
8936 v_trans_tab(j).oe_order_num,
8937 v_trans_tab(j).oe_order_line_num,
8938 v_trans_tab(j).customer_account_number,
8939 v_trans_tab(j).customer_party_name,
8940 v_trans_tab(j).source_transaction_num,
8941 v_trans_tab(j).parent_source_transaction_num,
8942 v_trans_tab(j).parent_interface_txn_id,
8943 v_trans_tab(j).customer_item_id,
8944 v_trans_tab(j).interface_available_qty,
8945 v_trans_tab(j).interface_transaction_qty,
8946 v_trans_tab(j).from_locator,
8947 v_trans_tab(j).lpn_group_id,
8948 v_trans_tab(j).order_transaction_id,
8949 v_trans_tab(j).license_plate_number,
8950 v_trans_tab(j).transfer_license_plate_number,
8951 v_trans_tab(j).amount,
8952 v_trans_tab(j).job_id,
8953 v_trans_tab(j).project_id,
8954 v_trans_tab(j).task_id,
8955 v_trans_tab(j).asn_attach_id,
8956 v_trans_tab(j).timecard_id,
8957 v_trans_tab(j).timecard_ovn,
8958 v_trans_tab(j).interface_available_amt,
8959 v_trans_tab(j).interface_transaction_amt,
8960 v_trans_tab(j).org_id, --<R12 MOAC>
8961 v_trans_tab(j).matching_basis,
8962 v_trans_tab(j).amount_shipped,
8963 v_trans_tab(j).requested_amount,
8964 v_trans_tab(j).material_stored_amount,
8965 v_trans_tab(j).replenish_order_line_id
8966 );
8967 asn_debug.put_line('RowId ' || v_trans_tab(j).row_id);
8968 asn_debug.put_line('Interface Id ' || TO_CHAR(v_trans_tab(j).interface_transaction_id));
8969 asn_debug.put_line('matching_basis=' || v_trans_tab(j).matching_basis);
8970
8971 IF v_trans_tab(j).matching_basis <> 'AMOUNT' THEN
8972 l_ls_table(l_ls_table_idx).orig_interface_trx_id := l_orig_trx_id;
8973 l_ls_table(l_ls_table_idx).new_interface_trx_id := v_trans_tab(j).interface_transaction_id;
8974 l_ls_table(l_ls_table_idx).quantity := v_trans_tab(j).quantity;
8975 END IF;
8976
8977 v_trans_tab.DELETE(j);
8978 END IF;
8979
8980 /* Checking if WMS is intalled before calling WMS_ASN_INTERFACE_PROCESS
8981 for Bug 2110031 */
8982 IF (wms_install.check_install(l_wms_return_status,
8983 l_wms_msg_count,
8984 l_wms_msg_data,
8985 lorgid
8986 )) THEN
8987 BEGIN
8988 wms_asn_interface.process(l_wms_return_status,
8989 l_wms_msg_count,
8990 l_wms_msg_data,
8991 v_current_interface_id
8992 );
8993 EXCEPTION
8994 WHEN OTHERS THEN
8995 NULL;
8996 END;
8997 END IF;
8998 END LOOP;
8999
9000 /* FPJ WMS Change. Call WMS api to split lot and serial rows in
9001 * mtl_transaction_lots_interface and mtl_serial_numbers_interface
9002 * tables. This needs to be called for each split rti row with both
9003 * the original rti row interface_id since the interface rows are
9004 * still linked to rti with the interface_transaction_id. This api
9005 * will split the mtli and msni rows similar to rti rows and will
9006 * link with the correct ids.
9007 */
9008 IF (g_asn_debug = 'Y') THEN
9009 asn_debug.put_line('l_ls_table.COUNT: ' || l_ls_table.COUNT);
9010 END IF;
9011
9012 IF l_ls_table.COUNT > 0 THEN --{
9013 IF (g_asn_debug = 'Y') THEN
9014 asn_debug.put_line('Calling split_lot_serial');
9015 END IF;
9016
9017 l_return := inv_rcv_integration_apis.split_lot_serial(p_api_version => l_api_version,
9018 p_init_msg_lst => fnd_api.g_false,
9019 x_return_status => l_return_status,
9020 x_msg_count => l_msg_count,
9021 x_msg_data => l_msg_data,
9022 p_new_rti_info => l_ls_table
9023 );
9024
9025 IF (g_asn_debug = 'Y') THEN
9026 asn_debug.put_line('After split_lot_serial Api');
9027 END IF;
9028
9029 -- if lot serial validation failed, then fail all these split rows
9030 IF ( (NOT l_return)
9031 OR (l_return_status <> fnd_api.g_ret_sts_success)) THEN --{
9032 IF (g_asn_debug = 'Y') THEN
9033 asn_debug.put_line('split_lot_serial Api has errors');
9034
9035 IF l_return THEN
9036 asn_debug.put_line('return value: true');
9037 ELSE
9038 asn_debug.put_line('return value: false');
9039 END IF;
9040
9041 asn_debug.put_line('x_return_status: ' || l_return_status);
9042 asn_debug.put_line('x_msg_count: ' || l_msg_count);
9043 asn_debug.put_line('x_msg_data: ' || l_msg_data);
9044 END IF;
9045
9046 l_message := fnd_msg_pub.get(p_msg_index => fnd_msg_pub.g_last, p_encoded => fnd_api.g_false);
9047
9048 FOR k IN l_ls_table.FIRST .. e_o_t LOOP
9049 /* We error out the rti row here.
9050 * Erroring out the other lpm_group rows
9051 * or ASN rows are taken care in RCVPREPB.pls.
9052 */
9053 UPDATE rcv_transactions_interface
9054 SET processing_status_code = 'ERROR'
9055 WHERE interface_transaction_id = l_ls_table(k).new_interface_trx_id;
9056
9057 SELECT GROUP_ID,
9058 header_interface_id,
9059 interface_transaction_id
9060 INTO l_group_id,
9061 l_header_interface_id,
9062 l_interface_transaction_id
9063 FROM rcv_transactions_interface
9064 WHERE interface_transaction_id = l_ls_table(k).new_interface_trx_id;
9065
9066 IF (l_message IS NOT NULL) THEN
9067 rcv_error_pkg.log_interface_error_message(l_message);
9068 ELSE
9069 rcv_error_pkg.set_error_message('RCV_SPLIT_LOT_SERIAL_ERROR');
9070 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
9071 END IF;
9072 END LOOP;
9073 END IF; --} if split_lot_serial failed
9074 END IF; --} if l_ls_table.count > 0
9075 END IF; --} if v_trans_tab.count > 0
9076
9077 IF (g_asn_debug = 'Y') THEN
9078 asn_debug.put_line('Exit handle_rcv_asn_transactions');
9079 END IF;
9080 END handle_rcv_asn_transactions;
9081
9082 PROCEDURE derive_vendor_trans_del(
9083 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9084 n IN OUT NOCOPY BINARY_INTEGER,
9085 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9086 x_header_record IN rcv_roi_preprocessor.header_rec_type
9087 ) IS
9088 test NUMBER;
9089 BEGIN
9090 IF (g_asn_debug = 'Y') THEN
9091 asn_debug.put_line('enter derive_vendor_trans_del ');
9092 END IF;
9093
9094
9095 /* Derive the to_org_id */
9096 derive_ship_to_org_info(x_cascaded_table,
9097 n,
9098 x_header_record
9099 );
9100
9101 IF (x_cascaded_table(n).unit_of_measure IS NOT NULL) THEN
9102 IF (g_asn_debug = 'Y') THEN
9103 asn_debug.put_line('X_progress ' || x_progress);
9104 END IF;
9105
9106 SELECT muom.uom_code
9107 INTO x_cascaded_table(n).uom_code
9108 FROM mtl_units_of_measure muom
9109 WHERE muom.unit_of_measure = x_cascaded_table(n).unit_of_measure;
9110 ELSE
9111 IF (g_asn_debug = 'Y') THEN
9112 asn_debug.put_line('uom_code not derived as unit_of_measure is null');
9113 END IF;
9114 END IF;
9115
9116 x_progress := '026';
9117
9118 /* Locator info derivation is done for the Receiving locators FPJ
9119 * project. Need to verify this with karun to see whether this is
9120 * needed for Transfer also.
9121 */
9122 IF (x_cascaded_table(n).transaction_type = 'TRANSFER') THEN
9123 derive_location_info(x_cascaded_table, n);
9124 derive_from_locator_id(x_cascaded_table, n); -- WMS Change
9125 derive_to_locator_id(x_cascaded_table, n); -- WMS Change
9126 END IF;
9127
9128 x_progress := '091';
9129 derive_reason_info(x_cascaded_table, n);
9130 /* Auto_transact_code is null for all these transaction types */
9131 x_cascaded_table(n).auto_transact_code := NULL;
9132 derive_trans_del_line_quantity(x_cascaded_table,
9133 n,
9134 temp_cascaded_table
9135 );
9136 END derive_vendor_trans_del;
9137
9138 PROCEDURE derive_parent_id(
9139 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9140 n IN OUT NOCOPY BINARY_INTEGER
9141 ) IS
9142 derive_values_from_plsql_table BOOLEAN := FALSE;
9143 cascaded_table_index NUMBER;
9144 derive_values_from_rti BOOLEAN := FALSE;
9145 l_processing_status_code rcv_transactions_interface.processing_status_code%TYPE;
9146 x_error_status VARCHAR2(1);
9147 e_unexpected_error EXCEPTION;
9148 BEGIN
9149 x_error_status := rcv_error_pkg.g_ret_sts_error;
9150
9151 /* We need to derive parent_trx_id if we can. Else if it is
9152 * a child of a parent in this same run, we can get all the values
9153 * from rti since we would have already derived for that or
9154 * from the pl/sql table if we have not posted it back to rti.
9155 * Parent-Child relationship
9156 */
9157
9158
9159 /* This can be a third party which means we will have
9160 * parent_source_transaction_num populated or it is a child of
9161 * some other transaction.
9162 */
9163 IF (g_asn_debug = 'Y') THEN
9164 asn_debug.put_line('Enter Derive_parent_id');
9165 END IF;
9166
9167 IF (x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN --{
9168 /* Check whether it is still in cascaded table */
9169 FOR i IN 1 ..(n - 1) LOOP
9170 IF (x_cascaded_table(i).interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id) THEN
9171 derive_values_from_plsql_table := TRUE;
9172 cascaded_table_index := i;
9173
9174 IF (g_asn_debug = 'Y') THEN
9175 asn_debug.put_line('set derive_values_from_plsql_table true ' || cascaded_table_index);
9176 END IF;
9177
9178 x_cascaded_table(n).derive := 'Y';
9179 x_cascaded_table(n).derive_index := cascaded_table_index;
9180 EXIT;
9181 END IF;
9182 END LOOP;
9183
9184 /* Derive the values from RTI if already posted */
9185 IF (NOT derive_values_from_plsql_table) THEN --{
9186 derive_values_from_rti := TRUE;
9187 x_cascaded_table(n).derive := 'Y';
9188
9189 IF (g_asn_debug = 'Y') THEN
9190 asn_debug.put_line('set derive_values_from_rti true ' || x_cascaded_table(n).derive_index);
9191 END IF;
9192 END IF; /*if (not derived_values_from_table) then */ --}
9193 END IF; --}
9194
9195 IF ( (x_cascaded_table(n).parent_interface_txn_id IS NULL)
9196 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN --{
9197 /* did not find Parent_txn_id in rti but
9198 * parent_source_transaction_num is not null.
9199 * Hence a child transaction.
9200 */
9201 IF (g_asn_debug = 'Y') THEN
9202 asn_debug.put_line('parent_interface_txn_id is null but parent_source_transaction_num is not null');
9203 END IF;
9204
9205 IF x_cascaded_table(n).parent_transaction_id IS NULL THEN --{
9206 /* Check whether it is still in cascaded table */
9207 FOR i IN 1 ..(n - 1) LOOP
9208 IF (x_cascaded_table(i).source_transaction_num = x_cascaded_table(n).parent_source_transaction_num) THEN
9209 x_cascaded_table(n).parent_interface_txn_id := x_cascaded_table(i).interface_transaction_id;
9210 derive_values_from_plsql_table := TRUE;
9211 cascaded_table_index := i;
9212 x_cascaded_table(n).derive := 'Y';
9213 x_cascaded_table(n).derive_index := cascaded_table_index;
9214 EXIT;
9215 END IF;
9216 END LOOP;
9217
9218 /* Derive the values from RTI if already posted */
9219 IF (NOT derive_values_from_plsql_table) THEN --{
9220 IF (g_asn_debug = 'Y') THEN
9221 asn_debug.put_line('derive_values_from_plsql_table is not set');
9222 END IF;
9223
9224 BEGIN
9225 SELECT interface_transaction_id
9226 INTO x_cascaded_table(n).parent_interface_txn_id
9227 FROM rcv_transactions_interface
9228 WHERE GROUP_ID = x_cascaded_table(n).GROUP_ID
9229 AND source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
9230 EXCEPTION
9231 WHEN NO_DATA_FOUND THEN
9232 IF (g_asn_debug = 'Y') THEN
9233 asn_debug.put_line('Exception in rti with source_transaction_num ');
9234 END IF;
9235
9236 x_cascaded_table(n).parent_interface_txn_id := NULL;
9237 END;
9238
9239 derive_values_from_rti := TRUE;
9240 x_cascaded_table(n).derive := 'Y';
9241
9242 IF (g_asn_debug = 'Y') THEN
9243 asn_debug.put_line('derive_values_from_rti is true');
9244 END IF;
9245 END IF; /*if (not derived_values_from_table) then */ --}
9246 END IF; /* if x_cascaded_table(n).parent_transaction_id is
9247 * null then*/ --}
9248 END IF; /*already_derived is false and parent_interface_transact
9249 * is null and parent_source_transaction_num is not null*/ --}
9250
9251 IF ( x_cascaded_table(n).parent_interface_txn_id IS NULL
9252 AND x_cascaded_table(n).parent_transaction_id IS NULL) THEN --{
9253 /* This is an error. It will come here when the user has
9254 * provided parent_source_transaction_num but that did not match with
9255 * with any parent in rcv_transactions or with any
9256 * row in rti or the pl/sql table. Hence need to insert
9257 * into po_interface_errors saying that this is a child
9258 * without any parent in rti or rt.
9259 */
9260 IF (g_asn_debug = 'Y') THEN
9261 asn_debug.put_line('NO PARENT');
9262 END IF;
9263
9264 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION');
9265 RAISE e_validation_error;
9266 ELSIF(x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN --}{
9267 IF (NOT derive_values_from_plsql_table) THEN --{
9268 BEGIN
9269 SELECT processing_status_code
9270 INTO l_processing_status_code
9271 FROM rcv_transactions_interface
9272 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
9273 EXCEPTION
9274 WHEN OTHERS THEN
9275 IF (g_asn_debug = 'Y') THEN
9276 asn_debug.put_line('Exception in rti with parent_interface_txn_id ');
9277 END IF;
9278
9279 RAISE e_unexpected_error;
9280 END;
9281
9282 IF (g_asn_debug = 'Y') THEN
9283 asn_debug.put_line('l_processing_status_code from rti ' || l_processing_status_code);
9284 END IF;
9285
9286 IF (l_processing_status_code = 'ERROR') THEN
9287 rcv_error_pkg.set_error_message('RCV_PARENT_RECORD_ERRORED');
9288 RAISE e_validation_error;
9289 END IF;
9290 ELSE --}{
9291 IF (x_cascaded_table(cascaded_table_index).processing_status_code = 'ERROR') THEN
9292 rcv_error_pkg.set_error_message('RCV_PARENT_RECORD_ERRORED');
9293 RAISE e_validation_error;
9294 END IF;
9295 END IF; --}
9296 END IF; /* Insert error if parent_interface_txn_id is null*/ --}
9297 EXCEPTION
9298 WHEN e_validation_error THEN
9299 x_cascaded_table(n).error_status := x_error_status;
9300 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
9301
9302 -- This case statement assigns the appropriate tokens
9303 -- all error messages must be found in the case statement
9304 -- if the error message has no token then use a null statement
9305 IF x_cascaded_table(n).error_message = 'RCV_NO_PARENT_TRANSACTION' THEN
9306 NULL;
9307 ELSIF x_cascaded_table(n).error_message = 'RCV_PARENT_RECORD_ERRORED' THEN
9308 NULL;
9309 END IF;
9310
9311 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
9312 WHEN e_unexpected_error THEN
9313 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
9314 rcv_error_pkg.set_sql_error_message('derive_parent_id', '000');
9315 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
9316 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
9317 END derive_parent_id;
9318
9319 PROCEDURE derive_trans_del_line_quantity(
9320 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
9321 n IN OUT NOCOPY BINARY_INTEGER,
9322 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type
9323 ) IS
9324 x_include_closed_po VARCHAR2(1); -- Bug 1887728
9325 /*
9326 ** Might be a compatibility issue between the two record definitions
9327 */
9328 x_record_count NUMBER;
9329 x_remaining_quantity NUMBER := 0;
9330 x_remaining_qty_po_uom NUMBER := 0;
9331 x_bkp_qty NUMBER := 0;
9332 x_progress VARCHAR2(3);
9333 x_to_organization_code VARCHAR2(5);
9334 x_converted_trx_qty NUMBER := 0;
9335 transaction_ok BOOLEAN := FALSE;
9336 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
9337 high_range_date DATE;
9338 low_range_date DATE;
9339 rows_fetched NUMBER := 0;
9340 x_tolerable_qty NUMBER := 0;
9341 x_first_trans BOOLEAN := TRUE;
9342 x_sysdate DATE := SYSDATE;
9343 current_n BINARY_INTEGER := 0;
9344 insert_into_table BOOLEAN := FALSE;
9345 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
9346 tax_amount_factor NUMBER;
9347 lastrecord BOOLEAN := FALSE;
9348 po_asn_uom_qty NUMBER;
9349 po_primary_uom_qty NUMBER;
9350 already_allocated_qty NUMBER := 0;
9351 x_item_id NUMBER;
9352 x_approved_flag VARCHAR(1);
9353 x_cancel_flag VARCHAR(1);
9354 x_closed_code VARCHAR(25);
9355 x_shipment_type VARCHAR(25);
9356 x_ship_to_organization_id NUMBER;
9357 x_ship_to_location_id NUMBER;
9358 /* temp_ship_to_location_id number;
9359 temp_mirror_ship_to_loc_id number ;
9360 temp_enf_ship_to_loc_code varchar(25) ; */
9361 /* The above 3 variables added for bug 1898283 */
9362 x_vendor_product_num VARCHAR(25);
9363 x_temp_count NUMBER;
9364 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
9365 /* 1887728 -Added the following variables */
9366 profile_user_id NUMBER := -1;
9367 profile_appl_id NUMBER := -1;
9368 profile_resp_id NUMBER := -1;
9369 defined BOOLEAN;
9370 /* 1845702 */
9371 x_sob_id NUMBER := NULL;
9372 x_rate NUMBER;
9373 x_allow_rate_override VARCHAR2(1);
9374 /* Bug# 1548597 */
9375 x_secondary_available_qty NUMBER := 0;
9376 firstrecord BOOLEAN := TRUE;
9377
9378 /********************************************************************/
9379 /* Bug 3356796. Changed destination_subinventory from 0 to '' as
9380 * it is a varchar column.
9381 */
9382 CURSOR po_transfer(
9383 v_parent_trx_id NUMBER,
9384 v_to_organization_id NUMBER
9385 ) IS
9386 SELECT rsup.po_line_location_id,
9387 rsup.po_header_id po_head_id,
9388 rsup.po_line_id line_id,
9389 rsup.rcv_transaction_id rcv_transaction_id,
9390 poh.segment1 document_num,
9391 pol.line_num line_number,
9392 rt.transaction_date transaction_date,
9393 rt.transaction_type,
9394 rt.unit_of_measure unit_of_meas,
9395 rt.primary_unit_of_measure,
9396 rt.primary_quantity,
9397 rsup.to_organization_id,
9398 rt.po_unit_price unit_price,
9399 rsl.category_id,
9400 rsl.item_description,
9401 rsup.po_line_id,
9402 rt.location_id,
9403 rsup.item_id,
9404 0 deliver_to_person_id,
9405 0 deliver_to_location_id,
9406 '' destination_subinventory,
9407 0 po_distribution_id,
9408 rsup.destination_type_code,
9409 0 code_combination_id,
9410 0 req_distribution_id,
9411 0 destination_organization_id,
9412 0 wip_entity_id,
9413 0 wip_operation_seq_num,
9414 0 wip_resource_seq_num,
9415 0 wip_repetitive_schedule_id,
9416 0 wip_line_id,
9417 0 bom_resource_id,
9418 0 ussgl_transaction_code,
9419 rt.quantity qty,
9420 0 interface_available_qty
9421 FROM rcv_supply rsup,
9422 rcv_transactions rt,
9423 rcv_shipment_lines rsl,
9424 po_headers poh,
9425 po_lines pol
9426 WHERE rt.transaction_id = v_parent_trx_id
9427 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
9428 AND rsup.supply_type_code = 'RECEIVING'
9429 AND poh.po_header_id = rsup.po_header_id
9430 AND pol.po_line_id = rsup.po_line_id
9431 AND pol.po_header_id = poh.po_header_id
9432 AND rsl.shipment_line_id = rsup.shipment_line_id
9433 AND rt.transaction_id = rsup.rcv_transaction_id
9434 AND rt.transaction_type <> 'UNORDERED'
9435 ORDER BY transaction_date DESC,
9436 document_num,
9437 line_number;
9438
9439 CURSOR po_transfer_rti(
9440 v_parent_inter_trx_id NUMBER
9441 ) IS
9442 SELECT rti.po_line_location_id,
9443 rti.po_header_id po_head_id,
9444 rti.po_line_id line_id,
9445 rti.interface_transaction_id rcv_transaction_id,
9446 rti.document_num,
9447 rti.document_line_num line_number,
9448 rti.transaction_date transaction_date,
9449 rti.transaction_type,
9450 rti.unit_of_measure unit_of_meas,
9451 rti.primary_unit_of_measure,
9452 rti.primary_quantity,
9453 rti.to_organization_id,
9454 rti.po_unit_price unit_price,
9455 rti.category_id,
9456 rti.item_description,
9457 rti.po_line_id,
9458 rti.location_id,
9459 rti.item_id,
9460 0 deliver_to_person_id,
9461 0 deliver_to_location_id,
9462 '' destination_subinventory,
9463 0 po_distribution_id,
9464 rti.destination_type_code,
9465 0 code_combination_id,
9466 0 req_distribution_id,
9467 0 destination_organization_id,
9468 0 wip_entity_id,
9469 0 wip_operation_seq_num,
9470 0 wip_resource_seq_num,
9471 0 wip_repetitive_schedule_id,
9472 0 wip_line_id,
9473 0 bom_resource_id,
9474 0 ussgl_transaction_code,
9475 rti.quantity qty,
9476 rti.interface_available_qty
9477 FROM rcv_transactions_interface rti
9478 WHERE interface_transaction_id = v_parent_inter_trx_id;
9479
9480 /* Bug 3292329.
9481 We used to use the same cursor for single deliver and
9482 Transfers, inspections etc. Because of this we had the
9483 the join to po_distributions table. For transfers of
9484 a received shipment line against a PO shipment with multiple
9485 distribution, this results in multiple rows which is incorrect.
9486 So declared a new cursor for single deliver which is the same
9487 as that of tranfer cursor but with distribution info.
9488 */
9489 CURSOR po_single_deliver(
9490 v_parent_trx_id NUMBER,
9491 v_to_organization_id NUMBER
9492 ) IS
9493 SELECT rsup.po_line_location_id,
9494 rsup.po_header_id po_head_id,
9495 rsup.po_line_id line_id,
9496 rsup.rcv_transaction_id rcv_transaction_id,
9497 poh.segment1 document_num,
9498 pol.line_num line_number,
9499 rt.transaction_date transaction_date,
9500 rt.transaction_type,
9501 rt.unit_of_measure unit_of_meas,
9502 rt.primary_unit_of_measure,
9503 rt.primary_quantity,
9504 rsup.to_organization_id,
9505 rt.po_unit_price unit_price,
9506 rsl.category_id,
9507 rsl.item_description,
9508 rsup.po_line_id,
9509 rt.location_id,
9510 rsup.item_id,
9511 pod.deliver_to_person_id,
9512 pod.deliver_to_location_id,
9513 pod.destination_subinventory,
9514 pod.po_distribution_id,
9515 pod.destination_type_code,
9516 pod.code_combination_id,
9517 pod.req_distribution_id,
9518 pod.destination_organization_id,
9519 pod.wip_entity_id,
9520 pod.wip_operation_seq_num,
9521 pod.wip_resource_seq_num,
9522 pod.wip_repetitive_schedule_id,
9523 pod.wip_line_id,
9524 pod.bom_resource_id,
9525 pod.ussgl_transaction_code,
9526 rt.quantity qty,
9527 0 interface_available_qty
9528 FROM rcv_supply rsup,
9529 rcv_transactions rt,
9530 rcv_shipment_lines rsl,
9531 po_headers poh,
9532 po_lines pol,
9533 po_distributions pod
9534 WHERE rt.transaction_id = v_parent_trx_id
9535 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
9536 AND rsup.supply_type_code = 'RECEIVING'
9537 AND poh.po_header_id = rsup.po_header_id
9538 AND pol.po_line_id = rsup.po_line_id
9539 AND pol.po_header_id = poh.po_header_id
9540 AND rsl.shipment_line_id = rsup.shipment_line_id
9541 AND rt.transaction_id = rsup.rcv_transaction_id
9542 AND rt.transaction_type <> 'UNORDERED'
9543 AND rt.po_header_id = pod.po_header_id
9544 AND pod.po_line_id = pol.po_line_id
9545 AND rt.po_line_location_id = pod.line_location_id
9546 AND ( pod.po_line_id IS NOT NULL
9547 AND pod.line_location_id IS NOT NULL)
9548 ORDER BY transaction_date DESC,
9549 document_num,
9550 line_number;
9551
9552 /* Bug 5354379:
9553 Added the condition pod.line_location_id = rti.po_line_location_id to
9554 get the correct pod.po_distribution_id for the po_line_location_id
9555 populated in the RTI. */
9556
9557 CURSOR po_single_deliver_rti(
9558 v_parent_inter_trx_id NUMBER
9559 ) IS
9560 SELECT rti.po_line_location_id,
9561 rti.po_header_id po_head_id,
9562 rti.po_line_id line_id,
9563 rti.interface_transaction_id rcv_transaction_id,
9564 rti.document_num,
9565 rti.document_line_num line_number,
9566 rti.transaction_date transaction_date,
9567 rti.transaction_type,
9568 rti.unit_of_measure unit_of_meas,
9569 rti.primary_unit_of_measure,
9570 rti.primary_quantity,
9571 rti.to_organization_id,
9572 rti.po_unit_price unit_price,
9573 rti.category_id,
9574 rti.item_description,
9575 rti.po_line_id,
9576 rti.location_id,
9577 rti.item_id,
9578 pod.deliver_to_person_id,
9579 pod.deliver_to_location_id,
9580 pod.destination_subinventory,
9581 pod.po_distribution_id,
9582 pod.destination_type_code,
9583 pod.code_combination_id,
9584 pod.req_distribution_id,
9585 pod.destination_organization_id,
9586 pod.wip_entity_id,
9587 pod.wip_operation_seq_num,
9588 pod.wip_resource_seq_num,
9589 pod.wip_repetitive_schedule_id,
9590 pod.wip_line_id,
9591 pod.bom_resource_id,
9592 pod.ussgl_transaction_code,
9593 rti.quantity qty,
9594 rti.interface_available_qty
9595 FROM rcv_transactions_interface rti,
9596 po_distributions pod
9597 WHERE interface_transaction_id = v_parent_inter_trx_id
9598 AND pod.line_location_id = rti.po_line_location_id --Bug:5354379
9599 AND pod.po_header_id = rti.po_header_id
9600 AND ( pod.po_line_id IS NOT NULL
9601 AND pod.line_location_id IS NOT NULL);
9602
9603 CURSOR po_deliver(
9604 v_parent_trx_id NUMBER,
9605 v_to_organization_id NUMBER,
9606 x_dist_num NUMBER
9607 ) IS
9608 SELECT rsup.po_line_location_id,
9609 rsup.po_header_id po_head_id,
9610 rsup.po_line_id line_id,
9611 rsup.rcv_transaction_id rcv_transaction_id,
9612 poh.segment1 document_num,
9613 pol.line_num line_number,
9614 rt.transaction_date transaction_date,
9615 rt.transaction_type,
9616 rt.unit_of_measure unit_of_meas,
9617 rt.primary_unit_of_measure,
9618 rt.primary_quantity,
9619 rsup.to_organization_id,
9620 rt.po_unit_price unit_price,
9621 rsl.category_id,
9622 rsl.item_description,
9623 rsup.po_line_id,
9624 rt.location_id,
9625 rsup.item_id,
9626 pod.deliver_to_person_id,
9627 pod.deliver_to_location_id,
9628 pod.destination_subinventory,
9629 pod.po_distribution_id,
9630 pod.destination_type_code,
9631 pod.code_combination_id,
9632 pod.req_distribution_id,
9633 pod.destination_organization_id,
9634 pod.wip_entity_id,
9635 pod.wip_operation_seq_num,
9636 pod.wip_resource_seq_num,
9637 pod.wip_repetitive_schedule_id,
9638 pod.wip_line_id,
9639 pod.bom_resource_id,
9640 pod.ussgl_transaction_code,
9641 rt.quantity qty,
9642 0 interface_available_qty
9643 FROM rcv_supply rsup,
9644 rcv_transactions rt,
9645 rcv_shipment_lines rsl,
9646 po_headers poh,
9647 po_lines pol,
9648 po_distributions pod
9649 WHERE rt.transaction_id = v_parent_trx_id
9650 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
9651 AND rsup.supply_type_code = 'RECEIVING'
9652 AND poh.po_header_id = rsup.po_header_id
9653 AND pol.po_line_id = rsup.po_line_id
9654 AND pol.po_header_id = poh.po_header_id
9655 AND rsl.shipment_line_id = rsup.shipment_line_id
9656 AND rt.transaction_id = rsup.rcv_transaction_id
9657 AND rt.transaction_type <> 'UNORDERED'
9658 AND rt.po_line_location_id = pod.line_location_id
9659 AND pod.distribution_num = x_dist_num
9660 AND ( pod.po_line_id IS NOT NULL
9661 AND pod.line_location_id IS NOT NULL)
9662 ORDER BY pod.po_distribution_id;
9663
9664 CURSOR po_deliver_rti(
9665 v_parent_inter_trx_id NUMBER,
9666 x_dist_num NUMBER
9667 ) IS
9668 SELECT rti.po_line_location_id,
9669 rti.po_header_id po_head_id,
9670 rti.po_line_id line_id,
9671 rti.interface_transaction_id rcv_transaction_id,
9672 rti.document_num,
9673 rti.document_line_num line_number,
9674 rti.transaction_date transaction_date,
9675 rti.transaction_type,
9676 rti.unit_of_measure unit_of_meas,
9677 rti.primary_unit_of_measure,
9678 rti.primary_quantity,
9679 rti.to_organization_id,
9680 rti.po_unit_price unit_price,
9681 rti.category_id,
9682 rti.item_description,
9683 rti.po_line_id,
9684 rti.location_id,
9685 rti.item_id,
9686 pod.deliver_to_person_id,
9687 pod.deliver_to_location_id,
9688 pod.destination_subinventory,
9689 pod.po_distribution_id,
9690 pod.destination_type_code,
9691 pod.code_combination_id,
9692 pod.req_distribution_id,
9693 pod.destination_organization_id,
9694 pod.wip_entity_id,
9695 pod.wip_operation_seq_num,
9696 pod.wip_resource_seq_num,
9697 pod.wip_repetitive_schedule_id,
9698 pod.wip_line_id,
9699 pod.bom_resource_id,
9700 pod.ussgl_transaction_code,
9701 rti.quantity qty,
9702 rti.interface_available_qty
9703 FROM rcv_transactions_interface rti,
9704 po_distributions pod
9705 WHERE interface_transaction_id = v_parent_inter_trx_id
9706 AND pod.distribution_num = x_dist_num
9707 AND pod.po_header_id = rti.po_header_id
9708 AND pod.line_location_id = rti.po_line_location_id --Bug:5354379
9709 AND ( pod.po_line_id IS NOT NULL
9710 AND pod.line_location_id IS NOT NULL);
9711
9712 CURSOR cust_transfer(
9713 v_parent_trx_id NUMBER,
9714 v_to_organization_id NUMBER
9715 ) IS
9716 SELECT rsup.po_line_location_id,
9717 rsup.po_header_id po_head_id,
9718 rsup.po_line_id line_id,
9719 rsup.rcv_transaction_id rcv_transaction_id,
9720 poh.segment1 document_num,
9721 pol.line_num line_number,
9722 rt.transaction_date transaction_date,
9723 rt.transaction_type,
9724 rt.unit_of_measure unit_of_meas,
9725 rt.primary_unit_of_measure,
9726 rt.primary_quantity,
9727 rsup.to_organization_id,
9728 rt.po_unit_price unit_price,
9729 rsl.category_id,
9730 rsl.item_description,
9731 rsup.po_line_id,
9732 rt.location_id,
9733 rsup.item_id,
9734 pod.deliver_to_person_id,
9735 pod.deliver_to_location_id,
9736 pod.destination_subinventory,
9737 pod.po_distribution_id,
9738 pod.destination_type_code,
9739 pod.code_combination_id,
9740 pod.req_distribution_id,
9741 pod.destination_organization_id,
9742 pod.wip_entity_id,
9743 pod.wip_operation_seq_num,
9744 pod.wip_resource_seq_num,
9745 pod.wip_repetitive_schedule_id,
9746 pod.wip_line_id,
9747 pod.bom_resource_id,
9748 pod.ussgl_transaction_code,
9749 rt.quantity qty,
9750 0 interface_available_qty
9751 FROM rcv_supply rsup,
9752 rcv_transactions rt,
9753 rcv_shipment_lines rsl,
9754 po_headers poh,
9755 po_lines pol,
9756 po_distributions pod
9757 WHERE rt.transaction_id = v_parent_trx_id
9758 AND rsup.to_organization_id = NVL(v_to_organization_id, rsup.to_organization_id)
9759 AND rsup.supply_type_code = 'RECEIVING'
9760 AND poh.po_header_id = rsup.po_header_id
9761 AND pol.po_line_id = rsup.po_line_id
9762 AND pol.po_header_id = poh.po_header_id
9763 AND rsl.shipment_line_id = rsup.shipment_line_id
9764 AND rt.transaction_id = rsup.rcv_transaction_id
9765 AND rt.transaction_type <> 'UNORDERED'
9766 AND rt.po_header_id = pod.po_header_id
9767 AND ( pod.po_line_id IS NOT NULL
9768 AND pod.line_location_id IS NOT NULL);
9769
9770 /* Bug 3356796. Changed x_po_transferrec to po_deliver%ROWTYPE
9771 * from po_transfer%ROWTYPE since po_deliver has all the columns
9772 * that are required for deliver and using po_transfer gives
9773 * PL/SQL conversion error.
9774 */
9775 x_po_transferrec po_deliver%ROWTYPE;
9776 x_temp_parent_trx_qty NUMBER := 0;
9777 x_converted_parent_trx_qty NUMBER := 0;
9778 x_temp_convert_parent_trx_qty NUMBER := 0;
9779 x_remaining_qty_parent_uom NUMBER := 0;
9780 l_to_organization_id NUMBER := 0;
9781 x_temp_already_allocated_qty NUMBER := 0;
9782 derive_values_from_table BOOLEAN := FALSE;
9783 derive_values_from_rti BOOLEAN := FALSE;
9784 already_derived BOOLEAN := FALSE;
9785 cascaded_table_index NUMBER;
9786 l_num_of_distributions NUMBER;
9787 temp_index NUMBER;
9788 l_supply_code rcv_supply.supply_type_code%TYPE;
9789 l_transaction_type rcv_transactions.transaction_type%TYPE;
9790 /* FPJ SERVICES */
9791 l_value_basis po_lines.order_type_lookup_code%TYPE;
9792 l_purchase_basis po_lines.purchase_basis%TYPE;
9793 l_matching_basis po_lines.matching_basis%TYPE;
9794 l_service_po_line_id po_lines.po_line_id%TYPE;
9795 l_total_rec_quantity NUMBER;
9796 l_converted_distribution_qty NUMBER;
9797 l_distribution_qty NUMBER;
9798 l_converted_transaction_qty NUMBER;
9799 l_ship_unit po_line_locations.unit_meas_lookup_code%TYPE;
9800 l_po_header_id po_headers_all.po_header_id%type;
9801 l_return_status VARCHAR2(1) :='S';
9802 l_complex_flag varchar2(1);
9803
9804 /* Bug 5354379 */
9805 l_po_deliver_rti_cursor_opened NUMBER := 0;
9806 l_fetch_mtl_supply VARCHAR2(2) := 'S'; --'S' fetched mtl_supply successfully or 'E' error
9807 l_interface_txn_id NUMBER := -1;
9808 l_transaction_id NUMBER := -1;
9809 l_loop_exit_status VARCHAR2(2) := 'S'; --'S' loop exited successfully by fetching RECEIVE txnid from RT or 'E' error
9810 l_exit VARCHAR2(2) := 'N';-- 'Y' exit loop, 'N' dont exit the loop
9811 l_parent_interface_txn_id NUMBER := -1;
9812 l_parent_transaction_id NUMBER := -1;
9813 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
9814 l_total_receiving_quantity NUMBER := 0; --Sum of received qty of preprocessed RECEIVE txn in RTI with same group_id
9815 l_total_deliver_quantity NUMBER := 0;--Sum of delivered qty of preprocessed DELIVER txn(excluding current DELIVER txn) in RTI with same group_id
9816 l_deliver_quantity NUMBER := 0; --Deliver qty for the current deliver txn
9817 l_receive_quantity NUMBER := 0;
9818 /* Bug 5354379 */
9819
9820 /* Bug 5354379 */
9821 /** Bug:6030094
9822 * PO number can be alpha numeric. So changing the
9823 * l_po_num definition from NUMBER to po_headers_all.segment1%type
9824 */
9825 l_po_num po_headers_all.segment1%type := null;
9826 l_po_line_num NUMBER := 0;
9827 l_po_line_loc_num NUMBER := 0;
9828 l_po_dist_num NUMBER := 0;
9829 /* Bug 5354379 */
9830 l_po_rel_num NUMBER := -1; --5439085
9831 BEGIN
9832 IF (g_asn_debug = 'Y') THEN
9833 asn_debug.put_line('enter derive_quantity ' || x_cascaded_table(n).parent_transaction_id);
9834 END IF;
9835
9836 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
9837 SELECT po_header_id
9838 INTO x_cascaded_table(n).po_header_id
9839 FROM rcv_transactions
9840 WHERE transaction_id = x_cascaded_table(n).parent_transaction_id;
9841
9842 SELECT COUNT(*)
9843 INTO l_num_of_distributions
9844 FROM po_distributions pod,
9845 rcv_supply rs
9846 WHERE pod.line_location_id = rs.po_line_location_id
9847 AND rs.rcv_transaction_id = x_cascaded_table(n).parent_transaction_id;
9848
9849 IF (l_num_of_distributions = 0) then
9850 /* FP for Bug 4654553.(fixed as a part of bug 5354379)Most probably this is due to non availability
9851 of receiving supply in rcv_supply.Either the items are fully
9852 delivered to inventory or returned back to supplier.
9853 In such a case raise an error and fail the transaction.
9854 */
9855
9856 IF (g_asn_debug = 'Y') THEN
9857 asn_debug.put_line('l_num_of_distributions is 0');
9858 END IF;
9859
9860 x_cascaded_table(n).error_status := 'F';
9861 rcv_error_pkg.set_error_message('RCV_NO_RECEIVE_SUPPLY', x_cascaded_table(n).error_message);
9862 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
9863 return;
9864
9865 END IF; /* End of FP for bug 4654553 */
9866 IF ( (x_cascaded_table(n).transaction_type = 'DELIVER')
9867 AND (l_num_of_distributions > 1)) THEN --{
9868 IF (g_asn_debug = 'Y') THEN
9869 asn_debug.put_line(' open po_deliver table ' || x_cascaded_table(n).parent_transaction_id);
9870 END IF;
9871
9872 /* Bug3553796 - Deriving Distribution number when Distribution
9873 id is available. */
9874
9875 /* Bug3553796 - START */
9876 IF ( x_cascaded_table(n).po_distribution_id IS NOT NULL
9877 AND (x_cascaded_table(n).document_distribution_num IS NULL)) THEN
9878 BEGIN
9879 IF (g_asn_debug = 'Y') THEN
9880 asn_debug.put_line('Deriving Distribution Number from Distribution Id:' || x_cascaded_table(n).po_distribution_id);
9881 END IF;
9882
9883 SELECT distribution_num
9884 INTO x_cascaded_table(n).document_distribution_num
9885 FROM po_distributions
9886 WHERE po_distribution_id = x_cascaded_table(n).po_distribution_id;
9887
9888 IF (g_asn_debug = 'Y') THEN
9889 asn_debug.put_line('Derived Distribution Number:' || x_cascaded_table(n).document_distribution_num);
9890 END IF;
9891 EXCEPTION
9892 WHEN OTHERS THEN
9893 IF (g_asn_debug = 'Y') THEN
9894 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
9895 END IF;
9896 END;
9897 END IF;
9898
9899 /* Bug3553796 - END */
9900 IF (x_cascaded_table(n).document_distribution_num IS NULL) THEN --{
9901 IF (g_asn_debug = 'Y') THEN
9902 asn_debug.put_line('Distribution num is required for delivering multi distribution Po');
9903 END IF;
9904
9905 x_cascaded_table(n).error_status := 'F';
9906 rcv_error_pkg.set_error_message('RCV_DIST_NUM_REQ', x_cascaded_table(n).error_message);
9907 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
9908 END IF; --}
9909
9910 OPEN po_deliver(x_cascaded_table(n).parent_transaction_id,
9911 x_cascaded_table(n).to_organization_id,
9912 x_cascaded_table(n).document_distribution_num
9913 );
9914 already_derived := TRUE;
9915 ELSE --}{ /* Transfer, accept, reject and deliver with only one distribution */
9916 -- end if;
9917 already_derived := TRUE;
9918 END IF; --}
9919 END IF; --}
9920
9921 IF ( NOT already_derived
9922 AND (x_cascaded_table(n).parent_interface_txn_id IS NULL)
9923 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN --{
9924 /* This means that there can be a row in RT with src_txn_id
9925 * populated or it can be a child.
9926 */
9927 BEGIN
9928 SELECT transaction_id
9929 INTO x_cascaded_table(n).parent_transaction_id
9930 FROM rcv_transactions
9931 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
9932
9933 already_derived := TRUE;
9934 EXCEPTION
9935 WHEN NO_DATA_FOUND THEN
9936 -- this is fine since this could be a child.
9937 NULL;
9938 END;
9939 END IF; --}
9940
9941 IF (g_asn_debug = 'Y') THEN
9942 asn_debug.put_line('l_num_of_distributions ' || l_num_of_distributions);
9943 END IF;
9944
9945 IF already_derived THEN --{
9946 IF ( (x_cascaded_table(n).transaction_type = 'DELIVER')
9947 AND (l_num_of_distributions = 1)) THEN --{
9948 IF (g_asn_debug = 'Y') THEN
9949 asn_debug.put_line(' open po_single_deliver table ' || x_cascaded_table(n).parent_transaction_id);
9950 END IF;
9951
9952 OPEN po_single_deliver(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
9953 ELSIF(x_cascaded_table(n).transaction_type <> 'DELIVER') THEN --}{
9954 /* For transfers, accept and reject */
9955 IF (g_asn_debug = 'Y') THEN
9956 asn_debug.put_line(' open po_transfer table ' || x_cascaded_table(n).parent_transaction_id);
9957 END IF;
9958
9959 OPEN po_transfer(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
9960 END IF; --}
9961 END IF; ---}
9962
9963 IF (NOT already_derived) THEN --{
9964 derive_parent_id(x_cascaded_table, n);
9965
9966 /* This means that there was no error in
9967 * derive_parent_id which means that the
9968 * this is a child and need to get the values
9969 * from the rti and not from the plsql table.
9970 */
9971 IF ( (x_cascaded_table(n).error_status <> 'E')
9972 AND ( x_cascaded_table(n).derive = 'Y'
9973 AND x_cascaded_table(n).derive_index = 0)) THEN --{
9974 /* if derive_values_from_table is true, then we
9975 * derive the values from the pl/sql tables later
9976 * at the time when we try to see which cursor is open.
9977 * We will have x_cascaded_table(n).
9978 * parent_interface_txn_id) populated with teh
9979 * correct value.
9980 */
9981 SELECT COUNT(*)
9982 INTO l_num_of_distributions
9983 FROM po_distributions
9984 WHERE line_location_id = (SELECT po_line_location_id
9985 FROM rcv_transactions_interface
9986 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id);
9987
9988 IF (g_asn_debug = 'Y') THEN
9989 asn_debug.put_line('l_num_of_distributions ' || l_num_of_distributions);
9990 END IF;
9991
9992 IF ( (x_cascaded_table(n).transaction_type = 'DELIVER')
9993 AND (l_num_of_distributions = 1)) THEN --{
9994 IF (g_asn_debug = 'Y') THEN
9995 asn_debug.put_line(' open Single deliver cursor from rti');
9996 END IF;
9997
9998 OPEN po_single_deliver_rti(x_cascaded_table(n).parent_interface_txn_id);
9999 ELSIF( (x_cascaded_table(n).transaction_type = 'DELIVER')
10000 AND (l_num_of_distributions > 1)) THEN --}{
10001
10002 /* Bug 5354379: {
10003 If the po_distribution_id is populated in RTI, then derive the
10004 distribution number from po_distributions_all table */
10005
10006 IF ( x_cascaded_table(n).po_distribution_id IS NOT NULL
10007 AND (x_cascaded_table(n).document_distribution_num IS NULL)) THEN
10008
10009 BEGIN
10010 IF (g_asn_debug = 'Y') THEN
10011 asn_debug.put_line('Deriving Distribution Number from Distribution Id:' || x_cascaded_table(n).po_distribution_id);
10012 END IF;
10013
10014 SELECT distribution_num
10015 INTO x_cascaded_table(n).document_distribution_num
10016 FROM po_distributions
10017 WHERE po_distribution_id = x_cascaded_table(n).po_distribution_id;
10018
10019 IF (g_asn_debug = 'Y') THEN
10020 asn_debug.put_line('Derived Distribution Number:' || x_cascaded_table(n).document_distribution_num);
10021 END IF;
10022
10023 EXCEPTION
10024 WHEN OTHERS THEN
10025 IF (g_asn_debug = 'Y') THEN
10026 asn_debug.put_line('wrong po_distribution_id entered in rcv_transactions_interface');
10027 END IF;
10028 END;
10029 END IF;
10030 -- } bug 5354379
10031
10032 IF (x_cascaded_table(n).document_distribution_num IS NULL) THEN --{
10033 IF (g_asn_debug = 'Y') THEN
10034 asn_debug.put_line('Distribution num is required for delivering multi distribution Po');
10035 END IF;
10036
10037 x_cascaded_table(n).error_status := 'F';
10038 rcv_error_pkg.set_error_message('RCV_DIST_NUM_REQ', x_cascaded_table(n).error_message);
10039 rcv_error_pkg.log_interface_error('INTERFACE_TRANSACTION_ID', FALSE);
10040 END IF; --}
10041
10042 IF (g_asn_debug = 'Y') THEN
10043 asn_debug.put_line(' open Multi deliver cursor from rti');
10044 END IF;
10045
10046 OPEN po_deliver_rti(x_cascaded_table(n).parent_interface_txn_id, x_cascaded_table(n).document_distribution_num);
10047 l_po_deliver_rti_cursor_opened := 1;--Bug 5354379
10048 ELSE --}{
10049 IF (g_asn_debug = 'Y') THEN
10050 asn_debug.put_line(' open transfer cursor from rti');
10051 END IF;
10052
10053 OPEN po_transfer_rti(x_cascaded_table(n).parent_interface_txn_id);
10054 END IF; --}
10055 END IF; --}
10056 END IF; --}
10057
10058 /******************************************************************/
10059 --check line quanity > 0
10060 x_progress := '097';
10061
10062 IF (g_asn_debug = 'Y') THEN
10063 asn_debug.put_line('X_progress ' || x_progress);
10064 END IF;
10065
10066 IF x_cascaded_table(n).error_status IN('S', 'W')
10067 AND x_cascaded_table(n).quantity <= 0 THEN --{
10068 IF (g_asn_debug = 'Y') THEN
10069 asn_debug.put_line('Quantity is <= zero. Cascade will fail');
10070 END IF;
10071
10072 x_cascaded_table(n).error_status := 'F';
10073 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
10074 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
10075 END IF; --} end qty > 0 check
10076
10077 -- the following steps will create a set of rows linking the line_record with
10078 -- its corresponding po_line_location rows until the quantity value from
10079 -- the asn is consumed. (Cascade)
10080
10081 /* 2119137 : If the user populates rcv_transactions_interface
10082 with po_line_id, then ROI errors out with
10083 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
10084 is not provided for one time items. Modified the "if" criteria in
10085 such a way that the ROI validation does'nt error out when
10086 po_line_id is populated for one time items. */
10087 x_progress := '098';
10088
10089 IF (g_asn_debug = 'Y') THEN
10090 asn_debug.put_line('X_progress ' || x_progress);
10091 END IF;
10092
10093 IF ( ( x_cascaded_table(n).parent_transaction_id IS NOT NULL
10094 OR x_cascaded_table(n).parent_interface_txn_id IS NOT NULL)
10095 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
10096
10097 -- Copy record from main table to temp table
10098 IF (g_asn_debug = 'Y') THEN
10099 asn_debug.put_line('Copy record from main table to temp table');
10100 END IF;
10101
10102 current_n := 1;
10103 temp_cascaded_table(current_n) := x_cascaded_table(n);
10104
10105 -- Get all rows which meet this condition
10106 IF (g_asn_debug = 'Y') THEN
10107 asn_debug.put_line('Get all rows which meet this condition');
10108 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
10109 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
10110 END IF;
10111
10112 -- Assign shipped quantity to remaining quantity
10113 IF (g_asn_debug = 'Y') THEN
10114 asn_debug.put_line('Assign populated quantity to remaining quantity ' || temp_cascaded_table(current_n).quantity);
10115 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
10116 END IF;
10117
10118 x_remaining_quantity := temp_cascaded_table(current_n).quantity;
10119 x_bkp_qty := x_remaining_quantity; -- used for decrementing cum qty for first record
10120 x_remaining_qty_po_uom := 0;
10121
10122 IF (g_asn_debug = 'Y') THEN
10123 asn_debug.put_line('Have assigned the quantity ' || x_remaining_quantity);
10124 END IF;
10125
10126 -- Calculate tax_amount_factor for calculating tax_amount for
10127 -- each cascaded line
10128
10129 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
10130 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_quantity;
10131 ELSE
10132 tax_amount_factor := 0;
10133 END IF;
10134
10135 IF (g_asn_debug = 'Y') THEN
10136 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
10137 asn_debug.put_line('Shipped Quantity : ' || TO_CHAR(x_remaining_quantity));
10138 END IF;
10139
10140 x_first_trans := TRUE;
10141 transaction_ok := FALSE;
10142
10143 IF (g_asn_debug = 'Y') THEN
10144 asn_debug.put_line('Before starting Cascade');
10145 END IF;
10146
10147 IF (g_asn_debug = 'Y') THEN
10148 asn_debug.put_line('Record Count = ' || x_record_count);
10149 END IF;
10150
10151 LOOP --{
10152 IF (g_asn_debug = 'Y') THEN
10153 asn_debug.put_line('Backup Qty ' || TO_CHAR(x_bkp_qty));
10154 asn_debug.put_line('Remaining Quantity ASN UOM ' || TO_CHAR(x_remaining_quantity));
10155 END IF;
10156
10157 /*
10158 ** Fetch the appropriate record
10159 */
10160 IF (g_asn_debug = 'Y') THEN
10161 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
10162 END IF;
10163
10164 IF (po_transfer%ISOPEN) THEN --{
10165 IF (g_asn_debug = 'Y') THEN
10166 asn_debug.put_line(' fetch po_transfer');
10167 END IF;
10168
10169 FETCH po_transfer INTO x_po_transferrec;
10170
10171 IF (po_transfer%NOTFOUND) THEN
10172 lastrecord := TRUE;
10173 END IF;
10174
10175 rows_fetched := po_transfer%ROWCOUNT;
10176 ELSIF(po_single_deliver%ISOPEN) THEN --}{
10177 IF (g_asn_debug = 'Y') THEN
10178 asn_debug.put_line(' fetch po_single_deliver');
10179 END IF;
10180
10181 FETCH po_single_deliver INTO x_po_transferrec;
10182
10183 IF (po_single_deliver%NOTFOUND) THEN
10184 IF (g_asn_debug = 'Y') THEN
10185 asn_debug.put_line('Single Deliver last row');
10186 END IF;
10187
10188 lastrecord := TRUE;
10189 END IF;
10190
10191 rows_fetched := po_single_deliver%ROWCOUNT;
10192 ELSIF(po_transfer_rti%ISOPEN) THEN --}{
10193 IF (g_asn_debug = 'Y') THEN
10194 asn_debug.put_line(' fetch po_transfer_rti');
10195 END IF;
10196
10197 FETCH po_transfer_rti INTO x_po_transferrec;
10198
10199 IF (po_transfer_rti%NOTFOUND) THEN
10200 IF (g_asn_debug = 'Y') THEN
10201 asn_debug.put_line('transfer last row');
10202 END IF;
10203
10204 lastrecord := TRUE;
10205 END IF;
10206
10207 rows_fetched := po_transfer_rti%ROWCOUNT;
10208 ELSIF(po_single_deliver_rti%ISOPEN) THEN --}{
10209 IF (g_asn_debug = 'Y') THEN
10210 asn_debug.put_line(' fetch po_single_deliver_rti');
10211 END IF;
10212
10213 FETCH po_single_deliver_rti INTO x_po_transferrec;
10214
10215 IF (po_single_deliver_rti%NOTFOUND) THEN
10216 IF (g_asn_debug = 'Y') THEN
10217 asn_debug.put_line('single_deliver_rti last row');
10218 END IF;
10219
10220 lastrecord := TRUE;
10221 END IF;
10222
10223 rows_fetched := po_single_deliver_rti%ROWCOUNT;
10224 ELSIF( po_deliver%ISOPEN
10225 AND x_cascaded_table(n).document_distribution_num IS NOT NULL) THEN --}{
10226 IF (g_asn_debug = 'Y') THEN
10227 asn_debug.put_line(' fetch po_deliver');
10228 END IF;
10229
10230 FETCH po_deliver INTO x_po_transferrec;
10231
10232 IF (po_deliver%NOTFOUND) THEN
10233 lastrecord := TRUE;
10234 END IF;
10235
10236 IF (firstrecord) THEN
10237 IF (g_asn_debug = 'Y') THEN
10238 asn_debug.put_line('first record for multi distributions');
10239 END IF;
10240
10241 firstrecord := FALSE;
10242
10243 SELECT quantity
10244 INTO l_total_rec_quantity
10245 FROM rcv_supply
10246 WHERE rcv_transaction_id = x_po_transferrec.rcv_transaction_id
10247 AND supply_type_code = 'RECEIVING';
10248 END IF;
10249
10250 IF (g_asn_debug = 'Y') THEN
10251 asn_debug.put_line(' l_total_rec_quantity ' || l_total_rec_quantity);
10252 END IF;
10253
10254 rows_fetched := po_deliver%ROWCOUNT;
10255 ELSIF(po_deliver_rti%ISOPEN) THEN --}{
10256 IF (g_asn_debug = 'Y') THEN
10257 asn_debug.put_line(' fetch po_deliver_rti');
10258 END IF;
10259
10260 FETCH po_deliver_rti INTO x_po_transferrec;
10261
10262 IF (po_deliver_rti%NOTFOUND) THEN
10263 IF (g_asn_debug = 'Y') THEN
10264 asn_debug.put_line('deliver_rti last row');
10265 END IF;
10266
10267 lastrecord := TRUE;
10268 END IF;
10269
10270 l_total_rec_quantity := x_po_transferrec.qty;
10271
10272 IF (g_asn_debug = 'Y') THEN
10273 asn_debug.put_line(' l_total_rec_quantity if multi distribution from rti ' || x_po_transferrec.qty);
10274 END IF;
10275
10276 rows_fetched := po_deliver_rti%ROWCOUNT;
10277 ELSIF(temp_cascaded_table(current_n).derive = 'Y') THEN --}{
10278 /* GET VALUES FROM THE PLSQL TABLE */
10279 /* Populate x_po_transferrec with these values since
10280 * we are using x_po_transferrec later.
10281 * We have temp_cascaded_table(current_n).
10282 * parent_interface_txn_id) populated with
10283 * with the correct value. Also we have cascaded_table_index
10284 * with the correct pl/sql table index number;
10285 */
10286 IF (g_asn_debug = 'Y') THEN
10287 asn_debug.put_line(' fetch pl/sql table');
10288 END IF;
10289
10290 temp_index := temp_cascaded_table(current_n).derive_index;
10291 x_po_transferrec.po_line_location_id := x_cascaded_table(temp_index).po_line_location_id;
10292 x_po_transferrec.po_head_id := x_cascaded_table(temp_index).po_header_id;
10293 x_po_transferrec.line_id := x_cascaded_table(temp_index).po_line_id;
10294 x_po_transferrec.unit_of_meas := x_cascaded_table(temp_index).unit_of_measure;
10295 x_po_transferrec.document_num := x_cascaded_table(temp_index).document_num;
10296 x_po_transferrec.line_number := x_cascaded_table(temp_index).document_line_num;
10297 x_po_transferrec.transaction_date := x_cascaded_table(temp_index).transaction_date;
10298 x_po_transferrec.transaction_type := x_cascaded_table(temp_index).transaction_type;
10299 x_po_transferrec.primary_unit_of_measure := x_cascaded_table(temp_index).primary_unit_of_measure;
10300 x_po_transferrec.primary_quantity := x_cascaded_table(temp_index).primary_quantity;
10301 x_po_transferrec.to_organization_id := x_cascaded_table(temp_index).to_organization_id;
10302 x_po_transferrec.unit_price := x_cascaded_table(temp_index).po_unit_price;
10303 x_po_transferrec.category_id := x_cascaded_table(temp_index).category_id;
10304 x_po_transferrec.item_description := x_cascaded_table(temp_index).item_description;
10305 x_po_transferrec.location_id := x_cascaded_table(temp_index).location_id;
10306 x_po_transferrec.item_id := x_cascaded_table(temp_index).item_id;
10307 x_po_transferrec.deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
10308 x_po_transferrec.deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
10309 x_po_transferrec.destination_subinventory := x_cascaded_table(temp_index).subinventory;
10310 x_po_transferrec.po_distribution_id := x_cascaded_table(temp_index).po_distribution_id;
10311 x_po_transferrec.destination_type_code := x_cascaded_table(temp_index).destination_type_code;
10312 x_po_transferrec.code_combination_id := x_cascaded_table(temp_index).charge_account_id;
10313 x_po_transferrec.req_distribution_id := x_cascaded_table(temp_index).req_distribution_id;
10314 x_po_transferrec.wip_entity_id := x_cascaded_table(temp_index).wip_entity_id;
10315 x_po_transferrec.wip_operation_seq_num := x_cascaded_table(temp_index).wip_operation_seq_num;
10316 x_po_transferrec.wip_resource_seq_num := x_cascaded_table(temp_index).wip_resource_seq_num;
10317 x_po_transferrec.wip_repetitive_schedule_id := x_cascaded_table(temp_index).wip_repetitive_schedule_id;
10318 x_po_transferrec.wip_line_id := x_cascaded_table(temp_index).wip_line_id;
10319 x_po_transferrec.bom_resource_id := x_cascaded_table(temp_index).bom_resource_id;
10320 x_po_transferrec.ussgl_transaction_code := x_cascaded_table(temp_index).ussgl_transaction_code;
10321 x_po_transferrec.qty := x_cascaded_table(temp_index).quantity;
10322 rows_fetched := 1;
10323 lastrecord := TRUE;
10324 END IF; --}
10325
10326
10327 --x_remaining_quantity:= temp_cascaded_table(current_n).quantity;
10328
10329 IF (g_asn_debug = 'Y') THEN
10330 asn_debug.put_line('Transfer Rows fetched ' || TO_CHAR(rows_fetched));
10331 asn_debug.put_line('po_line_id ' || TO_CHAR(x_po_transferrec.po_line_id));
10332 asn_debug.put_line('po_dist ' || TO_CHAR(x_po_transferrec.po_distribution_id));
10333 asn_debug.put_line('Transfer remainaing qty ' || x_remaining_quantity);
10334 END IF;
10335
10336 /* { Bug 5354379: To log meaningful error message with the PO number, PO line number
10337 PO line location number and distribution number and transaction qty.
10338 Using the message RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO instead of
10339 RCV_TRX_QTY_EXCEEDS_AVAILABLE */
10340 BEGIN
10341 select segment1
10342 into l_po_num
10343 from po_headers_all
10344 where po_header_id = x_po_transferrec.po_head_id;
10345
10346 select line_num
10347 into l_po_line_num
10348 from po_lines_all
10349 where po_line_id = x_po_transferrec.po_line_id;
10350
10351 select shipment_num
10352 into l_po_line_loc_num
10353 from po_line_locations_all
10354 where line_location_id = x_po_transferrec.po_line_location_id;
10355
10356 select distribution_num
10357 into l_po_dist_num
10358 from po_distributions_all
10359 where po_distribution_id = x_po_transferrec.po_distribution_id;
10360
10361 if x_cascaded_table(n).po_release_id is not null then --5439085
10362 select release_num
10363 into l_po_rel_num
10364 from po_releases_all
10365 where po_release_id = x_cascaded_table(n).po_release_id;
10366 end if;
10367 EXCEPTION
10368 WHEN NO_DATA_FOUND THEN
10369 IF (g_asn_debug = 'Y') THEN
10370 asn_debug.put_line('No data found exception while getting document info for PO');
10371 END IF;
10372 END;
10373 -- } Bug 5354379
10374
10375 /* FPJ SERVICES START.
10376 * We do not support Transfer/Deliver/Inspect transaction for a
10377 * Serive based PO.
10378 */
10379 /* R12 Complex work.
10380 * We do not support any other receiving transactions other
10381 * than direct receipt. Error out if it is complex work PO.
10382 */
10383 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
10384 IF (g_asn_debug = 'Y') THEN
10385 asn_debug.put_line('Parent_txn_id ' || x_cascaded_table(n).parent_transaction_id);
10386 END IF;
10387
10388 SELECT po_line_id,po_header_id
10389 INTO l_service_po_line_id,l_po_header_id
10390 FROM rcv_transactions
10391 WHERE transaction_id = x_cascaded_table(n).parent_transaction_id;
10392 ELSIF(x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
10393 IF (g_asn_debug = 'Y') THEN
10394 asn_debug.put_line('parent_interface_txn_id ' || x_cascaded_table(n).parent_interface_txn_id);
10395 END IF;
10396
10397 SELECT po_line_id,po_header_id
10398 INTO l_service_po_line_id,l_po_header_id
10399 FROM rcv_transactions_interface
10400 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
10401 END IF;
10402
10403 IF (g_asn_debug = 'Y') THEN
10404 asn_debug.put_line('l_service_po_line_id ' || l_service_po_line_id);
10405 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
10406 END IF;
10407
10408 IF l_service_po_line_id IS NOT NULL THEN --{
10409 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
10410 NVL(purchase_basis, 'GOODS'),
10411 NVL(matching_basis, 'QUANTITY')
10412 INTO l_value_basis,
10413 l_purchase_basis,
10414 l_matching_basis
10415 FROM po_lines
10416 WHERE po_line_id = l_service_po_line_id;
10417
10418 IF (l_matching_basis = 'AMOUNT') THEN
10419 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
10420 rcv_error_pkg.set_error_message('RCV_NO_SERVICE_SUPPORT_TRX', x_cascaded_table(n).error_message);
10421 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
10422 END IF;
10423 END IF; --}
10424
10425 /* FPJ SERVICES END. */
10426
10427 /* R12 Complex work.
10428 * We do not support any other receiving transactions other
10429 * than direct receipt. Error out if it is complex work PO.
10430 */
10431
10432 PO_COMPLEX_WORK_GRP.is_complex_work_po(
10433 1.0,
10434 l_po_header_id,
10435 l_return_status,
10436 l_complex_flag);
10437 IF (l_return_status IS NOT NULL AND
10438 l_return_status = FND_API.g_ret_sts_success) THEN
10439 IF( g_asn_debug = 'Y' ) THEN
10440 asn_debug.put_line('l_return_status ' || l_return_status);
10441 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
10442 END IF;
10443 ELSE
10444 IF( g_asn_debug = 'Y') THEN
10445 asn_debug.put_line('l_return_status ' || l_return_status);
10446 END IF;
10447 END IF;
10448
10449 IF (l_complex_flag = 'Y') THEN
10450 asn_debug.put_line('We do not support transaction type ' || x_cascaded_table(n).transaction_type || ' for complex work POs');
10451 rcv_error_pkg.set_error_message('RCV_INVALID_TRANSACTION_TYPE');
10452 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
10453 End if;
10454
10455
10456
10457
10458
10459 IF ( lastrecord
10460 OR x_remaining_quantity <= 0) THEN --{
10461 IF (g_asn_debug = 'Y') THEN
10462 asn_debug.put_line('Hit exit condition');
10463 END IF;
10464
10465 IF NOT x_first_trans THEN
10466 -- x_first_trans has been reset which means some cascade has
10467 -- happened. Otherwise current_n = 1
10468 IF (g_asn_debug = 'Y') THEN
10469 asn_debug.put_line('current_n before is ' || current_n);
10470 END IF;
10471
10472 current_n := current_n - 1;
10473 END IF;
10474
10475 -- do the tolerance act here
10476 IF (g_asn_debug = 'Y') THEN
10477 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
10478 asn_debug.put_line('Check which condition has occured');
10479 END IF;
10480
10481 -- lastrecord...we have run out of rows and we still have quantity to allocate
10482 IF x_remaining_quantity > 0 THEN --{
10483 IF (g_asn_debug = 'Y') THEN
10484 asn_debug.put_line('There is quantity remaining');
10485 asn_debug.put_line('Need to check qty tolerances');
10486 END IF;
10487
10488 IF rows_fetched > 0
10489 AND NOT x_first_trans THEN --{
10490 NULL;
10491
10492 /* for transfer,accept an reject type we dont have the
10493 * tolerance check. Hence error out.
10494 * We cannot transfer quantities more than that was received.
10495 */
10496 IF (g_asn_debug = 'Y') THEN
10497 asn_debug.put_line(' in transfer Extra ASN UOM Quantity ' || TO_CHAR(x_remaining_quantity));
10498 asn_debug.put_line('Extra PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
10499 END IF;
10500
10501 IF (g_asn_debug = 'Y') THEN
10502 asn_debug.put_line('delete the temp table ');
10503 END IF;
10504
10505 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
10506 IF l_po_rel_num = -1 THEN--Bug 5439085
10507 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
10508 ELSE
10509 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
10510 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
10511 END IF;
10512 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
10513 rcv_error_pkg.set_token('AVLQTY',x_cascaded_table(n).quantity - x_remaining_quantity);
10514 rcv_error_pkg.set_token('PONUM', l_po_num );
10515 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
10516 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
10517 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
10518 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
10519
10520 IF temp_cascaded_table.COUNT > 0 THEN
10521 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
10522 temp_cascaded_table.DELETE(i);
10523 END LOOP;
10524 END IF;
10525
10526 IF (g_asn_debug = 'Y') THEN
10527 asn_debug.put_line('mark the actual table with error status');
10528 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
10529 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
10530 END IF;
10531
10532 IF (g_asn_debug = 'Y') THEN
10533 asn_debug.put_line('Need to insert a row into po_interface_errors for transfer');
10534 END IF;
10535 ELSE --}{ else for rows fetched = 0 OR x_first_trans = true
10536 IF rows_fetched = 0 THEN
10537 IF (g_asn_debug = 'Y') THEN
10538 asn_debug.put_line('No rows were retrieved from cursor.');
10539 END IF;
10540 ELSIF x_first_trans THEN
10541 IF (g_asn_debug = 'Y') THEN
10542 asn_debug.put_line('No rows were cascaded');
10543 END IF;
10544 END IF;
10545
10546 x_temp_count := 1;
10547 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
10548
10549 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
10550
10551 SELECT transaction_type
10552 INTO l_transaction_type
10553 FROM rcv_transactions
10554 WHERE transaction_id = temp_cascaded_table(current_n).parent_transaction_id;
10555
10556 IF l_transaction_type = 'UNORDERED' THEN
10557 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
10558 rcv_error_pkg.set_error_message('RCV_INVALID_PARENT_TRX_TYPE', x_cascaded_table(n).error_message);
10559 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
10560 ELSE -- all other cases can be categorized as no receive supply
10561 rcv_error_pkg.set_error_message('RCV_NO_RECEIVE_SUPPLY', x_cascaded_table(n).error_message);
10562 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
10563 END IF;
10564 END IF; --}
10565
10566 -- Delete the temp_cascaded_table just to be sure
10567
10568 IF temp_cascaded_table.COUNT > 0 THEN
10569 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
10570 temp_cascaded_table.DELETE(i);
10571 END LOOP;
10572 END IF;
10573 END IF; --} end else for rows fetched = 0 OR x_first_trans = true
10574 -- end x_remaining_qty > 0 => this is the last record
10575 ELSE -- }{
10576 IF (g_asn_debug = 'Y') THEN
10577 asn_debug.put_line('Remaining UOM quantity is zero ' || TO_CHAR(x_remaining_quantity));
10578 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
10579 END IF;
10580 END IF; --} ends the check for whether last record has been reached
10581
10582 -- close cursors
10583
10584 IF (g_asn_debug = 'Y') THEN
10585 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions ' || current_n);
10586 END IF;
10587
10588 IF po_transfer%ISOPEN THEN
10589 CLOSE po_transfer;
10590 END IF;
10591
10592 IF po_transfer_rti%ISOPEN THEN
10593 CLOSE po_transfer_rti;
10594 END IF;
10595
10596 IF po_single_deliver%ISOPEN THEN
10597 CLOSE po_single_deliver;
10598 END IF;
10599
10600 IF po_single_deliver_rti%ISOPEN THEN
10601 CLOSE po_single_deliver_rti;
10602 END IF;
10603
10604 IF po_deliver%ISOPEN THEN
10605 CLOSE po_deliver;
10606 END IF;
10607
10608 IF (g_asn_debug = 'Y') THEN
10609 asn_debug.put_line('before exit current_n is ' || current_n);
10610 END IF;
10611
10612 EXIT;
10613 END IF; --} matches lastrecord or x_remaining_quantity <= 0
10614
10615 -- eliminate the row if it fails the date check
10616
10617 IF (g_asn_debug = 'Y') THEN
10618 asn_debug.put_line(' Entering qty calculateion for transfer');
10619 END IF;
10620
10621 IF (x_first_trans)
10622 AND temp_cascaded_table(current_n).item_id IS NULL THEN
10623 temp_cascaded_table(current_n).item_id := x_po_transferrec.item_id;
10624 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_transferrec.primary_unit_of_measure;
10625 END IF;
10626
10627 insert_into_table := FALSE;
10628 already_allocated_qty := 0;
10629 get_interface_available_qty(temp_cascaded_table,
10630 current_n,
10631 x_converted_parent_trx_qty
10632 );
10633
10634 IF (g_asn_debug = 'Y') THEN
10635 asn_debug.put_line('trans_del interface qty ' || x_converted_parent_trx_qty);
10636 END IF;
10637
10638 /* If this is a deliver for a multi distribution PO shipment
10639 * line and if its parent is in rti, then x_converted_parent_trx_qty
10640 * will not be 0 and l_num_of_distributions will be > 1. In this
10641 * case we need to make sure that the transaction qty is less than
10642 * or equal to the available qty in rti and also less than or
10643 * equal to the qty in po_distributions.
10644 */
10645 IF ( (temp_cascaded_table(1).transaction_type = 'DELIVER')
10646 AND (l_num_of_distributions > 1)) THEN --{
10647 IF (g_asn_debug = 'Y') THEN
10648 asn_debug.put_line('before getting available qty for standard multi distributions deliver ');
10649 END IF;
10650
10651 /* Bug 5354379:
10652 We should not compare the transaction quantity with the po_distributions_all.ordered_quantity,
10653 because we won't be able to do DELIVER txn for the RECEIVE txns with overreceipt made.
10654 If the RECEIVE txn for that DELIVER txns lies in RT, we have to make use of mtl_supply
10655 to get the AVAILABLE quantity for DELIVER txn.
10656 If the RECEIVE txn for that DELIVER txns lies in RTI, there is no mtl_supply or rcv_supply.
10657 So, get the available qty from RTI for that DELIVER txn
10658 */
10659
10660 IF l_po_deliver_rti_cursor_opened = 1 THEN --{ l_po_deliver_rti_cursor_opened = 1
10661 IF (g_asn_debug = 'Y') THEN
10662 asn_debug.put_line('In l_po_deliver_rti_cursor_opened...');
10663 END IF;
10664 l_interface_txn_id := x_cascaded_table(n).interface_transaction_id;
10665
10666 --In the following 2 loops, trying to get the RECEIVE txn id for the current DELIVER txn.
10667 --Once the controll comes out of the LOOP successfully,
10668 --If the "RECEIVE txn for the current DELIVER txn is available in RT,
10669 --RECEIVE txn id is fetched from RT and it will be available in the variable l_parent_transaction_id
10670
10671 --If the "RECEIVE txn for the current DELIVER txn is available in RTI,
10672 --RECEIVE interface txn id is fetched from RTI and it will be available in the variable l_parent_interface_txn_id
10673
10674 LOOP --{ loop1
10675 IF (g_asn_debug = 'Y') THEN
10676 asn_debug.put_line('Inside LOOP1 to fetch RECEIVE txn_id....');
10677 asn_debug.put_line('Fetching record from RTI, l_interface_txn_id'||l_interface_txn_id);
10678 END IF;
10679
10680 BEGIN --{
10681 SELECT parent_interface_txn_id,
10682 parent_transaction_id,
10683 transaction_type
10684 INTO l_parent_interface_txn_id,
10685 l_parent_transaction_id,
10686 l_transaction_type
10687 FROM rcv_transactions_interface
10688 WHERE interface_transaction_id = l_interface_txn_id;
10689
10690 IF l_parent_transaction_id IS NOT NULL THEN--{
10691 --parent txn is available in rcv_transactions table
10692 l_transaction_id := l_parent_transaction_id;
10693 LOOP --{ loop2
10694 --Fetch the record from rcv_transactions table
10695 IF (g_asn_debug = 'Y') THEN
10696 asn_debug.put_line('Inside LOOP2 to fetch RECEIVE txn_id....');
10697 asn_debug.put_line('Fetching record from RT, l_transaction_id'||l_transaction_id);
10698 END IF;
10699
10700 SELECT transaction_type,
10701 parent_transaction_id
10702 INTO l_transaction_type,
10703 l_parent_transaction_id
10704 FROM rcv_transactions
10705 WHERE transaction_id = l_transaction_id;
10706
10707 IF l_transaction_type = 'RECEIVE' THEN --{
10708 --exit loop1 and loop2
10709 --return l_transaction_id
10710 l_parent_transaction_id := l_transaction_id;
10711 IF (g_asn_debug = 'Y') THEN
10712 asn_debug.put_line('Fetched RECEIVE txn_id from RT....'||l_parent_transaction_id);
10713 END IF;
10714 l_exit := 'Y';
10715 EXIT; --exit loop2
10716 ELSIF l_parent_transaction_id IS NOT NULL THEN
10717 --continue LOOP2, till you fetch RECEIVE txnid
10718 l_transaction_id := l_parent_transaction_id;
10719 ELSE
10720 --Error condition
10721 l_exit := 'Y';
10722 l_loop_exit_status := 'E';
10723 IF (g_asn_debug = 'Y') THEN
10724 asn_debug.put_line('Error condition..parent_txn_id is null, not able to fetch RECEIVE txn_id');
10725 END IF;
10726 EXIT; --exit loop2
10727 END IF; --} l_transaction_type = 'RECEIVE'
10728 END LOOP; --{ loop2
10729
10730 ELSIF l_parent_interface_txn_id IS NOT NULL THEN --{ l_parent_interface_txn_id IS NOT NULL
10731 --parent txn is available in rcv_transactions_intreface table
10732 --continue LOOP1, till you fetch RECEIVE txnid
10733 l_interface_txn_id := l_parent_interface_txn_id;
10734 --}l_parent_interface_txn_id IS NOT NULL
10735 ELSE --{
10736 --Check whether, the RECEIVE txn for this DELIVER is in RTI
10737 --Then we have to get AVAILABLE qty from RTI, as there is no RS or MS
10738 --For the RECEIVE txn only RHI will be there, there won't be no parent_txn_id or
10739 --parent_interface_txn_id
10740 IF l_transaction_type = 'RECEIVE' THEN --{
10741 --exit loop1 and return l_interface_txn_id
10742 --This is the RECEIVE txn in RTI
10743 l_parent_interface_txn_id := l_interface_txn_id;
10744 l_parent_receive_txn_in_rt := 'N';
10745 l_loop_exit_status := 'S';
10746 IF (g_asn_debug = 'Y') THEN
10747 asn_debug.put_line('Fetched RECEIVE interface txn_id from RTI....'||l_parent_interface_txn_id);
10748 END IF;
10749 ELSE
10750 --Error condtion
10751 l_loop_exit_status := 'E';
10752 IF (g_asn_debug = 'Y') THEN
10753 asn_debug.put_line('Error condition..parent_interface_txn_id is null, not able to fetch RECEIVE txn_id');
10754 END IF;
10755 END IF;
10756 l_exit := 'Y';
10757 EXIT; --exit loop1
10758 --}
10759 END IF;--} l_parent_transaction_id is not null
10760 EXCEPTION
10761 WHEN NO_DATA_FOUND then
10762 l_exit := 'Y';
10763 l_loop_exit_status := 'E';
10764 IF (g_asn_debug = 'Y') THEN
10765 asn_debug.put_line('No data found exception occured in Fetching RECEIVE txn_id');
10766 END IF;
10767 END;--} BEGIN ends
10768
10769 --Check Exit condition met
10770 IF l_exit = 'Y' THEN
10771 IF (g_asn_debug = 'Y') THEN
10772 asn_debug.put_line('Exiting the loop to Fetch RECEIVE txn_id....');
10773 END IF;
10774 EXIT;--exit loop1
10775 END IF;
10776 END LOOP; --}loop1
10777
10778 --Check Loop exited successfuly by fetching the RECEIVE txn id
10779 IF l_loop_exit_status = 'E' THEN --{
10780 --Error out this DELIVER txn and set RTI record status to 'E'
10781 IF (g_asn_debug = 'Y') THEN
10782 asn_debug.put_line('Error out this DELIVER txn and set RTI record status to Error, as not able get RECEIVE txn_id....');
10783 END IF;
10784 x_cascaded_table(n).error_status := 'E';
10785 ELSIF l_loop_exit_status = 'S' THEN --{ l_loop_exit_status = 'S'
10786 --Check where to get the AVAILABLE qty for this DELIVER txn
10787 -- if l_parent_receive_txn_in_rt is 'Y', Fetch the AVAILABLE qty from mtl_supply
10788 -- if l_parent_receive_txn_in_rt is 'N', Fetch the AVAILABLE qty from rcv_transactions_interface
10789 IF l_parent_receive_txn_in_rt = 'Y' THEN--{ l_parent_receive_txn_in_rt = 'Y'
10790 --Fetch AVAILABLE qty from mtl_supply using l_parent_transaction_id
10791 BEGIN --{
10792 IF (g_asn_debug = 'Y') THEN
10793 asn_debug.put_line('Fetching mtl_supply, from the fetched RECEIVE txn_id....'||l_parent_transaction_id);
10794 asn_debug.put_line('PO distribution id....'||x_po_transferrec.po_distribution_id);
10795 END IF;
10796 /*Fetch the available qty for DELIVER txn based on the shipment line from mtl_supply.
10797 Reason: When RECEIPT txn is performed through forms, we won't get distribution details.
10798 For eg: Assume PO with 1 line(qty15) 1shipment(15) and
10799 2distributions(1st distribution qty:10 and 2nd distribution qty:5)
10800 Through forms perform ACCEPT txn for qty 15 and perform delivery on
10801 ditribution1 for qty:15. Transaction is allowed.
10802 We should have same behavoiur, when it is done through ROI also.
10803 Another case, When user peforms Overreceipt for the similar PO(mentioned above)through
10804 forms for qty 30. As per Cascading logic, in mtl_supply we are having qty:10 for distribution1
10805 and qty:20 in case of distribution2. But user is not aware of this cascading done in mtl_supply.
10806 So, we have to allow over delivery on the specified distribution, if it is with in the
10807 received qty for that shipment line.
10808 So, modifying the following sql to get Available qty based on shipment_line*/
10809 -- x_cascaded_table(n) is holding current DELIVER txn record
10810 SELECT nvl(sum(quantity),0)
10811 INTO l_distribution_qty
10812 FROM mtl_supply
10813 WHERE supply_source_id = l_parent_transaction_id
10814 AND po_line_location_id = x_cascaded_table(n).po_line_location_id
10815 AND supply_type_code = 'RECEIVING';
10816
10817 SELECT unit_meas_lookup_code
10818 INTO l_ship_unit
10819 FROM po_line_locations
10820 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
10821
10822 EXCEPTION
10823 WHEN NO_DATA_FOUND THEN
10824 --Error out DELIVER txn and set RTI status to 'E'
10825 l_fetch_mtl_supply := 'E';
10826 IF (g_asn_debug = 'Y') THEN
10827 asn_debug.put_line('No data found exception in fetching mtl_supply');
10828 END IF;
10829 END; --} Begin ends
10830
10831 IF l_fetch_mtl_supply = 'E' THEN
10832 --Error out this DELIVER txn and set RTI record status to 'E'
10833 IF (g_asn_debug = 'Y') THEN
10834 asn_debug.put_line('mtl_supply doesnot exist. error out the DELIVER txn...');
10835 END IF;
10836 x_cascaded_table(n).error_status := 'E';
10837 IF l_po_rel_num = -1 THEN--Bug 5439085
10838 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
10839 ELSE
10840 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
10841 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
10842 END IF;
10843 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
10844 rcv_error_pkg.set_token('AVLQTY',0);
10845 rcv_error_pkg.set_token('PONUM', l_po_num );
10846 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
10847 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
10848 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
10849 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
10850 END IF;
10851
10852 IF (g_asn_debug = 'Y') THEN
10853 asn_debug.put_line('l_distribution_qty:'||l_distribution_qty);
10854 asn_debug.put_line('Check whether l_distribution_qty is already consumed by other DELIVER txn submitted with same group_id');
10855 END IF;
10856
10857 --Fetch sum of quantity of only pre processed 'DELIVER' txns in RTI for that group_id
10858 --and po_shipment_line, to get total_deliver_qty for that po_shipment_line
10859 --( by this filter interface_transaction_id < x_po_transferrec.interface_transaction_id,
10860 -- only fetching preprocessed deliver txn)
10861 --Removing the condition on po_distribution_id, as we are honouring the DELIVER txn
10862 --based on the shipment_level quantity available in mtl_supply
10863 BEGIN--{
10864 SELECT nvl(sum(quantity),0)
10865 INTO l_total_deliver_quantity
10866 FROM rcv_transactions_interface
10867 WHERE (transaction_status_code = 'PENDING'
10868 AND processing_status_code <> 'ERROR')
10869 AND transaction_type = 'DELIVER'
10870 AND group_id = x_cascaded_table(n).group_id
10871 AND po_line_location_id = x_po_transferrec.po_line_location_id
10872 AND interface_transaction_id < x_cascaded_table(n).interface_transaction_id;
10873 EXCEPTION
10874 WHEN NO_DATA_FOUND then
10875 IF (g_asn_debug = 'Y') THEN
10876 asn_debug.put_line('No data found exception while fetching sum of delivered qty..');
10877 END IF;
10878 l_total_deliver_quantity := 0;
10879 END;--} Begin ends
10880
10881 IF (g_asn_debug = 'Y') THEN
10882 asn_debug.put_line('Sum of delivered qty for preprocessed DELIVERED txns..'||l_total_deliver_quantity);
10883 END IF;
10884
10885 --x_cascaded_table(n).quantity -> transaction qty of current Deliver txn
10886 -- l_distribution_qty -> qty available in mtl_supply
10887 -- l_total_deliver_quantity -> Quantity already consumed by the DELIVER txns(only precprocessed RTI record) submitted with the same group_id
10888 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)
10889 --Error out this DELIVERY txn, as it results in Over delivery on that distribution
10890 IF (g_asn_debug = 'Y') THEN
10891 asn_debug.put_line('Error out this DELIVERY txn, as it results in Over delivery on that distribution'||x_po_transferrec.po_distribution_id);
10892 END IF;
10893 x_cascaded_table(n).error_status := 'E';
10894 IF l_po_rel_num = -1 THEN--Bug 5439085
10895 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
10896 ELSE
10897 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
10898 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
10899 END IF;
10900 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
10901 rcv_error_pkg.set_token('AVLQTY',l_distribution_qty - l_total_deliver_quantity);
10902 rcv_error_pkg.set_token('PONUM', l_po_num );
10903 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
10904 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
10905 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
10906 rcv_error_pkg.log_interface_error('QUANTITY',FALSE);
10907 END IF;--} x_cascaded_table(n).quantity > (l_distribution_qty - l_total_deliver_quantity)
10908 --} l_parent_receive_txn_in_rt = 'Y'
10909 ELSIF l_parent_receive_txn_in_rt = 'N' THEN--{ l_parent_receive_txn_in_rt = 'N'
10910 --Fetch the AVAILABLE qty from rcv_transactions_interface using l_parent_interface_txn_id
10911 IF (g_asn_debug = 'Y') THEN
10912 asn_debug.put_line('Fetching AVAILABLE qty from fetched RECEIVE interface_txn_id....');
10913 END IF;
10914
10915 --Fetch sum of quantity of all preprocessed 'RECEIVE' txns loaded in RTI for that group_id
10916 --and po_line_location_id, to get total_receive_qty for that po_line_location_id
10917 --( by this filter interface_transaction_id < x_po_transferrec.interface_transaction_id,
10918 -- only fetching preprocessed RECEIVE txn)
10919 --x_po_transferrec.interface_transaction_id is holding 'DELIVER' txn id
10920 IF (g_asn_debug = 'Y') THEN
10921 asn_debug.put_line('Fetching sum of received qty for preprocessed RECEIVE txns....');
10922 END IF;
10923
10924 BEGIN --{
10925 SELECT nvl(sum(quantity),0)
10926 INTO l_total_receiving_quantity
10927 FROM rcv_transactions_interface
10928 WHERE (transaction_status_code = 'PENDING'
10929 AND processing_status_code <> 'ERROR')
10930 AND transaction_type = 'RECEIVE'
10931 AND auto_transact_code <> 'DELIVER'
10932 AND group_id = x_cascaded_table(n).group_id
10933 AND po_line_location_id = x_po_transferrec.po_line_location_id
10934 AND interface_transaction_id < x_cascaded_table(n).interface_transaction_id;
10935 EXCEPTION
10936 WHEN NO_DATA_FOUND then
10937 IF (g_asn_debug = 'Y') THEN
10938 asn_debug.put_line('No data found exception while fetching sum of received qty..');
10939 END IF;
10940 l_total_receiving_quantity := 0;
10941 END;--} Begin ends
10942
10943 IF (g_asn_debug = 'Y') THEN
10944 asn_debug.put_line('Sum of received qty for preprocessed RECEIVE txns..'||l_total_receiving_quantity);
10945 asn_debug.put_line('Fetching sum of Delivered qty for preprocessed DELIVER txns, excluding current deliver txn...');
10946 END IF;
10947
10948 --Fetch sum of quantity of only pre processed 'DELIVER' txns in RTI for that group_id
10949 --and po_line_location_id, to get total_deliver_qty for that po_distribution_id
10950 --( by this filter interface_transaction_id < x_po_transferrec.interface_transaction_id,
10951 -- only fetching preprocessed deliver txn)
10952
10953 BEGIN
10954 SELECT nvl(sum(quantity),0)
10955 INTO l_total_deliver_quantity
10956 FROM rcv_transactions_interface
10957 WHERE (transaction_status_code = 'PENDING'
10958 AND processing_status_code <> 'ERROR')
10959 AND transaction_type = 'DELIVER'
10960 AND group_id = x_cascaded_table(n).group_id
10961 AND po_line_location_id = x_po_transferrec.po_line_location_id
10962 AND interface_transaction_id < x_cascaded_table(n).interface_transaction_id;
10963 EXCEPTION
10964 WHEN NO_DATA_FOUND then
10965 IF (g_asn_debug = 'Y') THEN
10966 asn_debug.put_line('No data found exception while fetching sum of delivered qty..');
10967 END IF;
10968 l_total_deliver_quantity := 0;
10969 END;
10970
10971 IF (g_asn_debug = 'Y') THEN
10972 asn_debug.put_line('Sum of delivered qty for preprocessed DELIVERED txns..'||l_total_deliver_quantity);
10973 asn_debug.put_line('Fetching receive qty for RECEIVE txn...');
10974 END IF;
10975
10976 --Fetch the receive quantity for the 'RECEIVE'txn of the current DELIVER txn
10977 SELECT quantity
10978 INTO l_receive_quantity
10979 FROM rcv_transactions_interface
10980 WHERE interface_transaction_id = l_parent_interface_txn_id;
10981
10982 IF (g_asn_debug = 'Y') THEN
10983 asn_debug.put_line('Receive qty for RECEIVE txn...'||l_receive_quantity);
10984 asn_debug.put_line('Fetching deliver qty for DELIVER txn...');
10985 END IF;
10986 --Fetch the deliver quantity for the current 'DELIVER'txn
10987 SELECT quantity
10988 INTO l_deliver_quantity
10989 FROM rcv_transactions_interface
10990 WHERE interface_transaction_id = x_cascaded_table(n).interface_transaction_id;
10991
10992 IF (g_asn_debug = 'Y') THEN
10993 asn_debug.put_line('Deliver qty for DELIVER txn...'||l_deliver_quantity);
10994 END IF;
10995
10996 IF (l_total_deliver_quantity + l_deliver_quantity) <= l_total_receiving_quantity THEN --{ (l_total_deliver_quantity + l_deliver_quantity) <= l_total_receiving_quantity
10997 --Not over delivery txn
10998 --Check whether Receive txn line_location-id and deliver_txn line_location_id are same
10999 --and validate delivery qty is within the received qty
11000 IF (g_asn_debug = 'Y') THEN
11001 asn_debug.put_line('Not Over Delivery txn...');
11002 END IF;
11003 IF l_deliver_quantity <= l_receive_quantity THEN
11004 --Allow this deliver transaction
11005 IF (g_asn_debug = 'Y') THEN
11006 asn_debug.put_line('Delivery qty <= received qty...');
11007 END IF;
11008 l_distribution_qty := l_receive_quantity;
11009 ELSE
11010 --Over delivery for that Receive txn on the spefied distribution, error out this deliver txn
11011 IF (g_asn_debug = 'Y') THEN
11012 asn_debug.put_line('deliver qty > received qty.');
11013 END IF;
11014 x_cascaded_table(n).error_status := 'E';
11015 IF l_po_rel_num = -1 THEN--Bug 5439085
11016 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
11017 ELSE
11018 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
11019 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
11020 END IF;
11021 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
11022 rcv_error_pkg.set_token('AVLQTY',l_receive_quantity);
11023 rcv_error_pkg.set_token('PONUM', l_po_num );
11024 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
11025 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
11026 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
11027 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
11028 END IF;
11029 ELSE
11030 --Over delivery for that Receive txn on the spefied distribution, error out this deliver txn
11031 IF (g_asn_debug = 'Y') THEN
11032 asn_debug.put_line('Trying to perform over Delivery txn, on the specified distribution...Error out this Deliver txn..');
11033 END IF;
11034 x_cascaded_table(n).error_status := 'E';
11035 IF l_po_rel_num = -1 THEN--Bug 5439085
11036 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEEDS_AVL_QTY_PO', x_cascaded_table(n).error_message);
11037 ELSE
11038 rcv_error_pkg.set_error_message('RCV_TRX_QTY_EXCEED_AVL_QTY_PO', x_cascaded_table(n).error_message);
11039 rcv_error_pkg.set_token('RELNUM',l_po_rel_num);
11040 END IF;
11041 rcv_error_pkg.set_token('TXNQTY',x_cascaded_table(n).quantity);
11042 rcv_error_pkg.set_token('AVLQTY',l_total_receiving_quantity);
11043 rcv_error_pkg.set_token('PONUM', l_po_num );
11044 rcv_error_pkg.set_token('LINENUM',l_po_line_num );
11045 rcv_error_pkg.set_token('SHIPNUM',l_po_line_loc_num);
11046 rcv_error_pkg.set_token('DISTNUM',l_po_dist_num);
11047 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
11048 END IF;--} (l_total_deliver_quantity + l_deliver_quantity) <= l_total_receiving_quantity
11049 --} l_parent_receive_txn_in_rt = 'N'
11050 END IF;--} l_parent_receive_txn_in_rt = 'Y'
11051 --} l_loop_exit_status = 'S'
11052 END IF; --} l_loop_exit_status = 'E
11053 --}l_po_deliver_rti_cursor_opened = 1
11054 ELSE--{ l_po_deliver_rti_cursor_opened != 1
11055 SELECT ms.quantity,
11056 poll.unit_meas_lookup_code
11057 INTO l_distribution_qty,
11058 l_ship_unit
11059 FROM mtl_supply ms,
11060 po_line_locations poll
11061 WHERE ms.supply_source_id = x_po_transferrec.rcv_transaction_id
11062 AND ms.po_distribution_id = x_po_transferrec.po_distribution_id
11063 AND poll.line_location_id = ms.po_line_location_id
11064 AND ms.supply_type_code = 'RECEIVING';
11065 --} l_po_deliver_rti_cursor_opened != 1
11066 END IF; ----}l_po_deliver_rti_cursor_opened = 1
11067 -- } bugfix 5354379
11068
11069
11070 /* Convert ordered_qty in po_distributions to
11071 * the parent's uom */
11072 l_converted_distribution_qty := convert_into_correct_qty(l_distribution_qty,
11073 l_ship_unit,
11074 temp_cascaded_table(current_n).item_id,
11075 x_po_transferrec.unit_of_meas
11076 ); -- in parents uom
11077 /* Convert transaction_uom in rti to the parent's uom */
11078 l_converted_transaction_qty := convert_into_correct_qty(temp_cascaded_table(current_n).quantity,
11079 temp_cascaded_table(current_n).unit_of_measure,
11080 temp_cascaded_table(current_n).item_id,
11081 x_po_transferrec.unit_of_meas
11082 ); -- in parents uom
11083
11084 IF (g_asn_debug = 'Y') THEN
11085 asn_debug.put_line('l_total_rec_quantity ' || l_total_rec_quantity);
11086 asn_debug.put_line('l_converted_transaction_qty ' || l_converted_transaction_qty);
11087 asn_debug.put_line('l_converted_distribution_qty ' || l_converted_distribution_qty);
11088 END IF;
11089
11090 IF ( (l_converted_transaction_qty <= l_total_rec_quantity)
11091 AND (l_converted_transaction_qty <= l_converted_distribution_qty)) THEN
11092 x_converted_parent_trx_qty := l_total_rec_quantity;
11093 ELSE
11094 x_converted_parent_trx_qty := 0;
11095 END IF;
11096
11097 IF (g_asn_debug = 'Y') THEN
11098 asn_debug.put_line('Available qty for standard multiple distributions deliver ' || x_converted_parent_trx_qty);
11099 asn_debug.put_line('l_converted_distribution_qty ' || l_converted_distribution_qty);
11100 asn_debug.put_line('l_converted_transaction_qty ' || l_converted_transaction_qty);
11101 END IF;
11102 END IF; --}
11103
11104 IF ( (x_converted_parent_trx_qty = 0)
11105 AND ( (temp_cascaded_table(1).transaction_type <> 'DELIVER')
11106 OR ( temp_cascaded_table(1).transaction_type = 'DELIVER'
11107 AND l_num_of_distributions = 1))) THEN --{
11108 IF (g_asn_debug = 'Y') THEN
11109 asn_debug.put_line('calling transfer get_available_qty ');
11110 END IF;
11111
11112 rcv_quantities_s.get_available_quantity('TRANSFER',
11113 x_po_transferrec.rcv_transaction_id,
11114 'VENDOR',
11115 NULL,
11116 x_po_transferrec.rcv_transaction_id,
11117 NULL,
11118 x_converted_parent_trx_qty,
11119 x_tolerable_qty,
11120 x_po_transferrec.unit_of_meas,
11121 /*Bug# 1548597 */
11122 x_secondary_available_qty
11123 );
11124 END IF; --}
11125
11126 IF (g_asn_debug = 'Y') THEN
11127 asn_debug.put_line('qty from GET_AVAILABLE_QUANTITY for transfer is ' || x_converted_parent_trx_qty);
11128 END IF;
11129
11130 x_remaining_qty_parent_uom := convert_into_correct_qty(x_remaining_quantity,
11131 temp_cascaded_table(1).unit_of_measure,
11132 temp_cascaded_table(1).item_id,
11133 x_po_transferrec.unit_of_meas
11134 );
11135
11136 IF (x_remaining_qty_parent_uom = 0) THEN
11137 IF (g_asn_debug = 'Y') THEN
11138 asn_debug.put_line(' Transfer Need an error message in the interface tables');
11139 END IF;
11140 ELSE
11141 /* Converted qty successfully and we have some quantity on which we can act */
11142 IF (g_asn_debug = 'Y') THEN
11143 asn_debug.put_line('Converted trx qty that is available ' || x_converted_parent_trx_qty);
11144 asn_debug.put_line('Remaining qty in parents uom that is available ' || x_remaining_qty_parent_uom);
11145 END IF;
11146
11147 IF (x_converted_parent_trx_qty > 0) THEN --{
11148 IF (x_converted_parent_trx_qty < x_remaining_qty_parent_uom) THEN --{
11149 /* Total quantity available to transfer is less than the qty
11150 * that the user wants to transfer. Hence we would error out but
11151 * to keep the old code we will get the remaining code here and
11152 * error out later.
11153 */
11154 x_remaining_qty_parent_uom := x_remaining_qty_parent_uom - x_converted_parent_trx_qty;
11155
11156 IF (temp_cascaded_table(current_n).unit_of_measure <> x_po_transferrec.unit_of_meas) THEN
11157 x_remaining_quantity := convert_into_correct_qty(x_remaining_qty_parent_uom,
11158 x_po_transferrec.unit_of_meas,
11159 temp_cascaded_table(1).item_id,
11160 temp_cascaded_table(1).unit_of_measure
11161 );
11162 ELSE
11163 x_remaining_quantity := x_remaining_qty_parent_uom;
11164 END IF;
11165
11166 insert_into_table := TRUE;
11167 ELSE --}{
11168 IF (g_asn_debug = 'Y') THEN
11169 asn_debug.put_line('We are in >= Qty branch ');
11170 END IF;
11171
11172 x_converted_parent_trx_qty := x_remaining_qty_parent_uom;
11173 insert_into_table := TRUE;
11174 x_remaining_qty_parent_uom := 0;
11175 x_remaining_quantity := 0;
11176 END IF; --} /* if (x_converted_parent_trx_qty < x_remaining_qty_parent_uom) then */
11177 ELSE /* x_converted_parent_trx_qty >0 */ --}{
11178 IF rows_fetched = x_record_count THEN -- { last row needs to be inserted anyway
11179 -- so that the row can be used based on qty tolerance
11180 -- checks
11181 IF (g_asn_debug = 'Y') THEN
11182 asn_debug.put_line('Quantity is less then 0 but last record');
11183 END IF;
11184
11185 insert_into_table := TRUE;
11186 x_converted_trx_qty := 0;
11187 ELSE --}{
11188 IF (g_asn_debug = 'Y') THEN
11189 asn_debug.put_line('<= 0 Quantity but more records in cursor');
11190 END IF;
11191
11192 x_remaining_qty_po_uom := 0; -- we may have a diff uom on the next iteration
11193
11194 IF (g_asn_debug = 'Y') THEN
11195 asn_debug.put_line('We have to deal with remaining_qty > 0 and x_converted_trx_qty -ve');
11196 END IF;
11197
11198 insert_into_table := FALSE;
11199 END IF; --}
11200 END IF; /*x_converted_parent_trx_qty >0 */ --}
11201 END IF;
11202
11203 /* Converted qty successfully and we have some quantity on which we can act */
11204 IF (g_asn_debug = 'Y') THEN
11205 asn_debug.put_line('Transaction qty in terms of the parents uom is ' || x_converted_parent_trx_qty);
11206 END IF;
11207
11208 IF insert_into_table THEN --{ --start
11209 IF (x_first_trans) THEN --{
11210 IF (g_asn_debug = 'Y') THEN
11211 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
11212 END IF;
11213
11214 x_first_trans := FALSE;
11215 ELSE --}{
11216 IF (g_asn_debug = 'Y') THEN
11217 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
11218 END IF;
11219
11220 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
11221 END IF; --}
11222
11223 temp_cascaded_table(current_n).po_header_id := x_po_transferrec.po_head_id;
11224 temp_cascaded_table(current_n).po_line_id := x_po_transferrec.line_id;
11225 temp_cascaded_table(current_n).po_line_location_id := x_po_transferrec.po_line_location_id;
11226 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_transferrec.primary_unit_of_measure;
11227
11228 IF (temp_cascaded_table(current_n).unit_of_measure <> x_po_transferrec.unit_of_meas) THEN
11229 temp_cascaded_table(current_n).quantity := convert_into_correct_qty(x_converted_parent_trx_qty,
11230 x_po_transferrec.unit_of_meas,
11231 temp_cascaded_table(current_n).item_id,
11232 temp_cascaded_table(current_n).unit_of_measure
11233 ); -- in asn uom
11234
11235 IF (g_asn_debug = 'Y') THEN
11236 asn_debug.put_line('Transaction qty in terms of the transaction uom is ' || temp_cascaded_table(current_n).quantity);
11237 END IF;
11238 ELSE
11239 temp_cascaded_table(current_n).quantity := x_converted_parent_trx_qty;
11240 END IF;
11241
11242 IF (temp_cascaded_table(current_n).primary_unit_of_measure <> x_po_transferrec.unit_of_meas) THEN
11243 temp_cascaded_table(current_n).primary_quantity := convert_into_correct_qty(x_converted_parent_trx_qty,
11244 x_po_transferrec.unit_of_meas,
11245 temp_cascaded_table(current_n).item_id,
11246 temp_cascaded_table(current_n).primary_unit_of_measure
11247 );
11248 ELSE
11249 temp_cascaded_table(current_n).primary_quantity := x_converted_parent_trx_qty;
11250 END IF;
11251
11252 IF (g_asn_debug = 'Y') THEN
11253 asn_debug.put_line('Transaction qty in terms of the primary uom is ' || temp_cascaded_table(current_n).primary_quantity);
11254 END IF;
11255
11256 IF (NVL(x_cascaded_table(n).transaction_type, 'RECEIVE') = 'DELIVER') THEN --{
11257 temp_cascaded_table(current_n).po_distribution_id := x_po_transferrec.po_distribution_id;
11258 temp_cascaded_table(current_n).charge_account_id := x_po_transferrec.code_combination_id;
11259 temp_cascaded_table(current_n).req_distribution_id := x_po_transferrec.req_distribution_id;
11260 -- temp_cascaded_table(current_n).currency_conversion_date := x_po_transferrec.rate_date;
11261 -- temp_cascaded_table(current_n).currency_conversion_rate := x_po_transferrec.rate;
11262 temp_cascaded_table(current_n).destination_type_code := x_po_transferrec.destination_type_code;
11263 temp_cascaded_table(current_n).destination_context := x_po_transferrec.destination_type_code;
11264
11265 IF (g_asn_debug = 'Y') THEN
11266 asn_debug.put_line(' po_dist ' || temp_cascaded_table(current_n).po_distribution_id);
11267 END IF;
11268
11269 IF (NVL(temp_cascaded_table(current_n).deliver_to_location_id, 0) = 0) THEN
11270 temp_cascaded_table(current_n).deliver_to_location_id := x_po_transferrec.deliver_to_location_id;
11271 END IF;
11272
11273 IF (g_asn_debug = 'Y') THEN
11274 asn_debug.put_line(' deliver_to_person_id ' || temp_cascaded_table(current_n).deliver_to_person_id);
11275 END IF;
11276
11277 /* Bug 2392074 - If the deliver_to_person mentioned in the po_distributions is
11278 invalid or inactive at the time of Receipt we need to clear the deliver to person,
11279 as this is an optional field. */
11280 IF (NVL(temp_cascaded_table(current_n).deliver_to_person_id, 0) = 0) THEN --{
11281 temp_cascaded_table(current_n).deliver_to_person_id := x_po_transferrec.deliver_to_person_id;
11282
11283 IF (temp_cascaded_table(current_n).deliver_to_person_id IS NOT NULL) THEN --{
11284 BEGIN
11285 SELECT NVL(MAX(hre.full_name), 'notfound')
11286 INTO x_full_name
11287 FROM hr_employees_current_v hre
11288 WHERE ( hre.inactive_date IS NULL
11289 OR hre.inactive_date > SYSDATE)
11290 AND hre.employee_id = temp_cascaded_table(current_n).deliver_to_person_id;
11291
11292 IF (x_full_name = 'notfound') THEN
11293 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
11294 END IF;
11295 EXCEPTION
11296 WHEN NO_DATA_FOUND THEN
11297 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
11298
11299 IF (g_asn_debug = 'Y') THEN
11300 asn_debug.put_line('The deliver to person entered in PO is currently inactive');
11301 asn_debug.put_line(' So it is cleared off');
11302 END IF;
11303 WHEN OTHERS THEN
11304 temp_cascaded_table(current_n).deliver_to_person_id := NULL;
11305
11306 IF (g_asn_debug = 'Y') THEN
11307 asn_debug.put_line('Some exception has occured');
11308 asn_debug.put_line('This exception is due to the PO deliver to person');
11309 asn_debug.put_line('The deliver to person is optional');
11310 asn_debug.put_line('So cleared off the deliver to person');
11311 END IF;
11312 END;
11313 END IF; --}
11314 END IF; --}
11315
11316 IF (g_asn_debug = 'Y') THEN
11317 asn_debug.put_line(' subinventory ' || temp_cascaded_table(current_n).subinventory);
11318 END IF;
11319
11320 IF (temp_cascaded_table(current_n).subinventory IS NULL) THEN
11321 temp_cascaded_table(current_n).subinventory := x_po_transferrec.destination_subinventory;
11322 END IF;
11323
11324 IF (g_asn_debug = 'Y') THEN
11325 asn_debug.put_line(' wip_entity_id ' || temp_cascaded_table(current_n).wip_entity_id);
11326 END IF;
11327
11328 temp_cascaded_table(current_n).wip_entity_id := x_po_transferrec.wip_entity_id;
11329 temp_cascaded_table(current_n).wip_operation_seq_num := x_po_transferrec.wip_operation_seq_num;
11330 temp_cascaded_table(current_n).wip_resource_seq_num := x_po_transferrec.wip_resource_seq_num;
11331 temp_cascaded_table(current_n).wip_repetitive_schedule_id := x_po_transferrec.wip_repetitive_schedule_id;
11332 temp_cascaded_table(current_n).wip_line_id := x_po_transferrec.wip_line_id;
11333 temp_cascaded_table(current_n).bom_resource_id := x_po_transferrec.bom_resource_id;
11334
11335 IF (g_asn_debug = 'Y') THEN
11336 asn_debug.put_line(' ussgl_transaction_code ' || temp_cascaded_table(current_n).ussgl_transaction_code);
11337 END IF;
11338
11339 -- bug 1361786
11340 IF (temp_cascaded_table(current_n).ussgl_transaction_code IS NULL) THEN
11341 temp_cascaded_table(current_n).ussgl_transaction_code := x_po_transferrec.ussgl_transaction_code;
11342 END IF;
11343 END IF; --}
11344
11345 current_n := current_n + 1;
11346
11347 IF (g_asn_debug = 'Y') THEN
11348 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
11349 END IF;
11350 END IF; --}
11351 /* Get the available qty in PRIMARY UOM */
11352 /*
11353 PO_UOM_S.UOM_CONVERT (x_converted_trx_qty,
11354 l_uom,
11355 x_item_id,
11356 x_primary_uom,
11357 l_primary_available_qty );
11358 */
11359 END LOOP; --}
11360 ELSE --} {
11361 -- error_status and error_message are set after validate_quantity_shipped
11362 IF (g_asn_debug = 'Y') THEN
11363 asn_debug.put_line('No parent_transaction_id or parent_interface_transaction_id ');
11364 END IF;
11365
11366 IF (g_asn_debug = 'Y') THEN
11367 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
11368 END IF;
11369
11370 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
11371 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
11372
11373 IF (x_cascaded_table(n).error_message IS NULL) THEN
11374 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION', x_cascaded_table(n).error_message);
11375 END IF;
11376
11377 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
11378 END IF; --}
11379 END IF; -- } of (asn quantity_shipped was valid)
11380
11381 IF (g_asn_debug = 'Y') THEN
11382 asn_debug.put_line('before closing cursors current_n is ' || temp_cascaded_table.COUNT);
11383 END IF;
11384
11385 IF po_transfer%ISOPEN THEN
11386 CLOSE po_transfer;
11387 END IF;
11388
11389 IF po_transfer_rti%ISOPEN THEN
11390 CLOSE po_transfer_rti;
11391 END IF;
11392
11393 IF po_single_deliver%ISOPEN THEN
11394 CLOSE po_single_deliver;
11395 END IF;
11396
11397 IF po_single_deliver_rti%ISOPEN THEN
11398 CLOSE po_single_deliver_rti;
11399 END IF;
11400
11401 IF po_deliver%ISOPEN THEN
11402 CLOSE po_deliver;
11403 END IF;
11404
11405 IF (g_asn_debug = 'Y') THEN
11406 asn_debug.put_line('Exit explode_line_quantity');
11407 END IF;
11408 EXCEPTION
11409 WHEN OTHERS THEN
11410 IF (g_asn_debug = 'Y') THEN
11411 asn_debug.put_line('Exception in derive_trans_del_quantity ');
11412 END IF;
11413
11414 IF po_transfer%ISOPEN THEN
11415 CLOSE po_transfer;
11416 END IF;
11417
11418 IF po_transfer_rti%ISOPEN THEN
11419 CLOSE po_transfer_rti;
11420 END IF;
11421
11422 IF po_single_deliver%ISOPEN THEN
11423 CLOSE po_single_deliver;
11424 END IF;
11425
11426 IF po_single_deliver_rti%ISOPEN THEN
11427 CLOSE po_single_deliver_rti;
11428 END IF;
11429
11430 IF po_deliver%ISOPEN THEN
11431 CLOSE po_deliver;
11432 END IF;
11433
11434 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
11435 rcv_error_pkg.set_sql_error_message('derive_trans_del_line_quantity', x_progress);
11436 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
11437 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
11438
11439 IF (g_asn_debug = 'Y') THEN
11440 asn_debug.put_line(TO_CHAR(n));
11441 asn_debug.put_line(SQLERRM);
11442 asn_debug.put_line('error ' || x_progress);
11443 END IF;
11444 END derive_trans_del_line_quantity;
11445
11446 /*
11447 * Default information from parent transaction for transfer and deliver
11448 * This procedure was originally written for vendor source transactions
11449 * but since the code is the same for RMAs, the cursor has been expanded
11450 * to include RMA information as well and the procedure reused for RMAs.
11451 */
11452 PROCEDURE default_vendor_trans_del(
11453 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
11454 n IN BINARY_INTEGER
11455 ) IS
11456 p_trx_record rcv_roi_header_common.common_default_record_type;
11457
11458 CURSOR po_transfer(
11459 v_parent_trx_id NUMBER
11460 ) IS
11461 SELECT rt.po_revision_num,
11462 rsl.item_description,
11463 rsup.po_release_id,
11464 rt.location_id loc_id,
11465 rt.organization_id,
11466 rt.inspection_status_code,
11467 rt.routing_header_id,
11468 rt.currency_code,
11469 rt.currency_conversion_rate,
11470 rt.currency_conversion_type,
11471 rt.currency_conversion_date,
11472 rt.location_id,
11473 rsup.shipment_header_id,
11474 rsup.shipment_line_id,
11475 rsl.category_id,
11476 rt.vendor_id,
11477 rt.vendor_site_id,
11478 rt.po_unit_price,
11479 rt.movement_id,
11480 rt.deliver_to_person_id,
11481 rt.deliver_to_location_id,
11482 rt.subinventory,
11483 rt.transfer_lpn_id,
11484 rt.oe_order_header_id,
11485 rt.oe_order_line_id,
11486 rt.customer_id,
11487 rt.customer_site_id,
11488 rt.source_document_code
11489 FROM rcv_transactions rt,
11490 rcv_shipment_lines rsl,
11491 rcv_supply rsup
11492 WHERE rt.transaction_id = v_parent_trx_id
11493 AND rt.transaction_id = rsup.rcv_transaction_id
11494 AND rsup.supply_type_code = 'RECEIVING'
11495 AND rsl.shipment_line_id = rsup.shipment_line_id
11496 AND rt.transaction_id = rsup.rcv_transaction_id
11497 AND rt.transaction_type <> 'UNORDERED';
11498
11499 CURSOR po_transfer_rti(
11500 v_parent_inter_trx_id NUMBER
11501 ) IS
11502 SELECT rti.po_revision_num,
11503 rti.item_description,
11504 rti.po_release_id,
11505 rti.location_id loc_id,
11506 rti.to_organization_id organization_id,
11507 rti.inspection_status_code,
11508 rti.routing_header_id,
11509 rti.currency_code,
11510 rti.currency_conversion_rate,
11511 rti.currency_conversion_type,
11512 rti.currency_conversion_date,
11513 rti.location_id,
11514 rti.shipment_header_id,
11515 rti.shipment_line_id,
11516 rti.category_id,
11517 rti.vendor_id,
11518 rti.vendor_site_id,
11519 rti.po_unit_price,
11520 rti.movement_id,
11521 rti.deliver_to_person_id,
11522 rti.deliver_to_location_id,
11523 rti.subinventory,
11524 rti.transfer_lpn_id,
11525 rti.oe_order_header_id,
11526 rti.oe_order_line_id,
11527 rti.customer_id,
11528 rti.customer_site_id,
11529 rti.source_document_code
11530 FROM rcv_transactions_interface rti
11531 WHERE interface_transaction_id = v_parent_inter_trx_id;
11532
11533 default_po_transfer_info po_transfer%ROWTYPE;
11534 x_progress VARCHAR2(3);
11535 x_locator_control NUMBER;
11536 x_default_subinventory VARCHAR2(10);
11537 x_default_locator_id NUMBER;
11538 x_success BOOLEAN;
11539 x_tax_name VARCHAR2(50); -- Bug 6331613
11540 x_vendor_site_id NUMBER;
11541 x_vendor_site_code VARCHAR2(20);
11542 /* default variables */
11543 l_project_id NUMBER;
11544 l_task_id NUMBER;
11545 l_locator_id NUMBER;
11546 temp_index NUMBER;
11547 /* pjiang debug */
11548 err_num NUMBER;
11549 err_msg VARCHAR2(100);
11550 BEGIN
11551 -- default the fields that are covered in the common defaulting logic
11552 p_trx_record.destination_type_code := x_cascaded_table(n).destination_type_code;
11553 p_trx_record.transaction_type := x_cascaded_table(n).transaction_type;
11554 p_trx_record.processing_mode_code := x_cascaded_table(n).processing_mode_code;
11555 p_trx_record.processing_status_code := x_cascaded_table(n).processing_status_code;
11556 p_trx_record.transaction_status_code := x_cascaded_table(n).transaction_status_code;
11557 p_trx_record.auto_transact_code := x_cascaded_table(n).auto_transact_code;
11558 rcv_roi_header_common.commondefaultcode(p_trx_record);
11559 x_cascaded_table(n).destination_type_code := p_trx_record.destination_type_code;
11560 x_cascaded_table(n).transaction_type := p_trx_record.transaction_type;
11561 x_cascaded_table(n).processing_mode_code := p_trx_record.processing_mode_code;
11562 x_cascaded_table(n).processing_status_code := p_trx_record.processing_status_code;
11563 x_cascaded_table(n).transaction_status_code := p_trx_record.transaction_status_code;
11564 x_cascaded_table(n).auto_transact_code := p_trx_record.auto_transact_code;
11565
11566 IF (g_asn_debug = 'Y') THEN
11567 asn_debug.put_line('Enter Default');
11568 END IF;
11569
11570 IF x_cascaded_table(n).source_document_code IS NULL THEN
11571 IF x_cascaded_table(n).receipt_source_code = 'CUSTOMER' THEN
11572 x_cascaded_table(n).source_document_code := 'RMA';
11573 ELSE
11574 x_cascaded_table(n).source_document_code := 'PO';
11575 END IF;
11576
11577 IF (g_asn_debug = 'Y') THEN
11578 asn_debug.put_line('Defaulting SOURCE_DOCUMENT_CODE ' || x_cascaded_table(n).source_document_code);
11579 END IF;
11580 END IF;
11581
11582 IF (x_cascaded_table(n).derive = 'Y') THEN --{
11583 IF (x_cascaded_table(n).derive_index <> 0) THEN --{
11584 NULL;
11585 /* Get the values from pl/sql table */
11586 temp_index := x_cascaded_table(n).derive_index;
11587 x_cascaded_table(n).po_revision_num := x_cascaded_table(temp_index).po_revision_num;
11588 x_cascaded_table(n).item_description := x_cascaded_table(temp_index).item_description;
11589 x_cascaded_table(n).po_release_id := x_cascaded_table(temp_index).po_release_id;
11590 x_cascaded_table(n).to_organization_id := x_cascaded_table(temp_index).to_organization_id;
11591 x_cascaded_table(n).inspection_status_code := x_cascaded_table(temp_index).inspection_status_code;
11592 x_cascaded_table(n).routing_header_id := x_cascaded_table(temp_index).routing_header_id;
11593 x_cascaded_table(n).currency_code := x_cascaded_table(temp_index).currency_code;
11594 x_cascaded_table(n).currency_conversion_rate := x_cascaded_table(temp_index).currency_conversion_rate;
11595 x_cascaded_table(n).currency_conversion_type := x_cascaded_table(temp_index).currency_conversion_type;
11596 x_cascaded_table(n).currency_conversion_date := x_cascaded_table(temp_index).currency_conversion_date;
11597 x_cascaded_table(n).shipment_header_id := x_cascaded_table(temp_index).shipment_header_id;
11598 x_cascaded_table(n).shipment_line_id := x_cascaded_table(temp_index).shipment_line_id;
11599 x_cascaded_table(n).category_id := x_cascaded_table(temp_index).category_id;
11600 x_cascaded_table(n).vendor_id := x_cascaded_table(temp_index).vendor_id;
11601 x_cascaded_table(n).vendor_site_id := x_cascaded_table(temp_index).vendor_site_id;
11602 x_cascaded_table(n).po_unit_price := x_cascaded_table(temp_index).po_unit_price;
11603
11604 -- default the parent's to_lpn into the child's from_lpn
11605 /* Bug 3444284.
11606 * We dont need to default lpn_ids. WMS will take care of
11607 * populating these columns. So this case of giving a warning
11608 * will not arise as it will be defaulted by them
11609 */
11610 IF (x_cascaded_table(n).location_id IS NULL) THEN
11611 x_cascaded_table(n).location_id := x_cascaded_table(temp_index).location_id;
11612 END IF;
11613
11614 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN --{
11615 IF (NVL(x_cascaded_table(n).deliver_to_person_id, 0) = 0) THEN
11616 x_cascaded_table(n).deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
11617 END IF;
11618
11619 IF (NVL(x_cascaded_table(n).deliver_to_location_id, 0) = 0) THEN
11620 x_cascaded_table(n).deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
11621 END IF;
11622
11623 IF (x_cascaded_table(n).subinventory IS NULL) THEN
11624 x_cascaded_table(n).subinventory := x_cascaded_table(temp_index).subinventory;
11625 END IF;
11626 END IF; --}
11627 ELSE --} {
11628 IF (g_asn_debug = 'Y') THEN
11629 asn_debug.put_line('open cursor Default RTI');
11630 END IF;
11631
11632 OPEN po_transfer_rti(x_cascaded_table(n).parent_interface_txn_id);
11633 END IF; --}
11634 ELSE -- } {
11635 OPEN po_transfer(x_cascaded_table(n).parent_transaction_id);
11636 END IF; --}
11637
11638 IF (po_transfer%ISOPEN) THEN
11639 IF (g_asn_debug = 'Y') THEN
11640 asn_debug.put_line('fetch cursor Default');
11641 END IF;
11642
11643 FETCH po_transfer INTO default_po_transfer_info;
11644 ELSIF(po_transfer_rti%ISOPEN) THEN
11645 FETCH po_transfer_rti INTO default_po_transfer_info;
11646 END IF;
11647
11648 IF ( ( po_transfer%ISOPEN
11649 AND po_transfer%FOUND)
11650 OR ( po_transfer_rti%ISOPEN
11651 AND po_transfer_rti%FOUND)) THEN --{
11652 IF (g_asn_debug = 'Y') THEN --{
11653 asn_debug.put_line('Defaulting Transfer po_revision_num' || default_po_transfer_info.po_revision_num);
11654 asn_debug.put_line('Defaulting Transfer item_description' || default_po_transfer_info.item_description);
11655 asn_debug.put_line('Defaulting Transfer po_release_id' || default_po_transfer_info.po_release_id);
11656 asn_debug.put_line('Defaulting Transfer location_id' || default_po_transfer_info.loc_id);
11657 asn_debug.put_line('Defaulting Transfer organization_id' || default_po_transfer_info.organization_id);
11658 asn_debug.put_line('Defaulting Transfer routing_header_id' || default_po_transfer_info.routing_header_id);
11659 asn_debug.put_line('Defaulting Transfer currency_code' || default_po_transfer_info.currency_code);
11660 asn_debug.put_line('Defaulting Transfer currency_conversion_rate' || default_po_transfer_info.currency_conversion_rate);
11661 asn_debug.put_line('Defaulting Transfer currency_conversion_type' || default_po_transfer_info.currency_conversion_type);
11662 asn_debug.put_line('Defaulting Transfer currency_conversion_date' || default_po_transfer_info.currency_conversion_date);
11663 asn_debug.put_line('Defaulting Transfer shipment_header_id' || default_po_transfer_info.shipment_header_id);
11664 asn_debug.put_line('Defaulting Transfer shipment_line_id' || default_po_transfer_info.shipment_line_id);
11665 asn_debug.put_line('Defaulting Transfer category_id' || default_po_transfer_info.category_id);
11666 asn_debug.put_line('Defaulting Transfer vendor_id' || default_po_transfer_info.vendor_id);
11667 asn_debug.put_line('Defaulting Transfer vendor_site_id' || default_po_transfer_info.vendor_site_id);
11668 asn_debug.put_line('Defaulting Transfer DELIVER_TO_PERSON_ID' || default_po_transfer_info.deliver_to_person_id);
11669 asn_debug.put_line('Defaulting Transfer DELIVER_TO_LOCATION_ID' || default_po_transfer_info.deliver_to_location_id);
11670 asn_debug.put_line('Defaulting Transfer SUBINVENTORY' || default_po_transfer_info.subinventory);
11671 asn_debug.put_line('Defaulting Transfer CUSTOMER_ID' || default_po_transfer_info.customer_id);
11672 asn_debug.put_line('Defaulting Transfer CUSTOMER_SITE_ID' || default_po_transfer_info.customer_site_id);
11673 END IF; --}
11674
11675 IF x_cascaded_table(n).oe_order_header_id IS NULL
11676 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
11677 x_cascaded_table(n).oe_order_header_id := default_po_transfer_info.oe_order_header_id;
11678
11679 IF (g_asn_debug = 'Y') THEN
11680 asn_debug.put_line('Defaulting Transfer oe_order_header_id ' || x_cascaded_table(n).oe_order_header_id);
11681 END IF;
11682 END IF;
11683
11684 IF x_cascaded_table(n).oe_order_line_id IS NULL
11685 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
11686 x_cascaded_table(n).oe_order_line_id := default_po_transfer_info.oe_order_line_id;
11687
11688 IF (g_asn_debug = 'Y') THEN
11689 asn_debug.put_line('Defaulting Transfer oe_order_line_id ' || x_cascaded_table(n).oe_order_line_id);
11690 END IF;
11691 END IF;
11692
11693 x_cascaded_table(n).po_revision_num := default_po_transfer_info.po_revision_num;
11694 x_cascaded_table(n).item_description := default_po_transfer_info.item_description;
11695 x_cascaded_table(n).po_release_id := default_po_transfer_info.po_release_id;
11696 x_cascaded_table(n).to_organization_id := default_po_transfer_info.organization_id;
11697 x_cascaded_table(n).inspection_status_code := default_po_transfer_info.inspection_status_code;
11698 x_cascaded_table(n).routing_header_id := default_po_transfer_info.routing_header_id;
11699 x_cascaded_table(n).currency_code := default_po_transfer_info.currency_code;
11700 x_cascaded_table(n).currency_conversion_rate := default_po_transfer_info.currency_conversion_rate;
11701 x_cascaded_table(n).currency_conversion_type := default_po_transfer_info.currency_conversion_type;
11702 x_cascaded_table(n).currency_conversion_date := default_po_transfer_info.currency_conversion_date;
11703 x_cascaded_table(n).shipment_header_id := default_po_transfer_info.shipment_header_id;
11704 x_cascaded_table(n).shipment_line_id := default_po_transfer_info.shipment_line_id;
11705 x_cascaded_table(n).category_id := default_po_transfer_info.category_id;
11706 x_cascaded_table(n).vendor_id := default_po_transfer_info.vendor_id;
11707 x_cascaded_table(n).vendor_site_id := default_po_transfer_info.vendor_site_id;
11708
11709 /* We used to get the unit_price from the cursor where it picks
11710 * up from the parent. But since PO unit_price can be change
11711 * retroactively, we need to pick up the unit_price from PO
11712 * directly. Since we would have derived line_location_id
11713 * and po_line_id at this point, use the values here. Since
11714 * we come here for defaulting RMA also, we need to do this
11715 * only when receipt_source_code is VENDOR.
11716 * x_cascaded_table(n).po_unit_price :=
11717 DEFAULT_Po_transfer_info.po_unit_price;
11718 */
11719 IF (x_cascaded_table(n).receipt_source_code = 'VENDOR') THEN --{
11720 SELECT NVL(pll.price_override, pl.unit_price)
11721 INTO x_cascaded_table(n).po_unit_price
11722 FROM po_line_locations pll,
11723 po_lines pl
11724 WHERE pll.line_location_id = x_cascaded_table(n).po_line_location_id
11725 AND pl.po_line_id = x_cascaded_table(n).po_line_id
11726 AND pl.po_line_id = pll.po_line_id;
11727
11728 IF (g_asn_debug = 'Y') THEN
11729 asn_debug.put_line('Defaulting Transfer po_unit_price' || x_cascaded_table(n).po_unit_price);
11730 END IF;
11731 END IF; --}
11732
11733 x_cascaded_table(n).customer_id := default_po_transfer_info.customer_id;
11734 x_cascaded_table(n).customer_site_id := default_po_transfer_info.customer_site_id;
11735
11736 -- default the parent's to_lpn into the child's from_lpn
11737 /* Bug 3444284.
11738 * We dont need to default lpn_ids. WMS will take care of
11739 * populating these columns. So this case of giving a warning
11740 * will not arise as it will be defaulted by them
11741
11742 */
11743 IF (x_cascaded_table(n).location_id IS NULL) THEN
11744 x_cascaded_table(n).location_id := default_po_transfer_info.loc_id;
11745 END IF;
11746
11747 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN --{
11748 IF (NVL(x_cascaded_table(n).deliver_to_person_id, 0) = 0) THEN
11749 x_cascaded_table(n).deliver_to_person_id := default_po_transfer_info.deliver_to_person_id;
11750 END IF;
11751
11752 IF (NVL(x_cascaded_table(n).deliver_to_location_id, 0) = 0) THEN
11753 x_cascaded_table(n).deliver_to_location_id := default_po_transfer_info.deliver_to_location_id;
11754 END IF;
11755
11756 IF (x_cascaded_table(n).subinventory IS NULL) THEN
11757 x_cascaded_table(n).subinventory := default_po_transfer_info.subinventory;
11758 END IF;
11759 END IF; --}
11760 END IF; -- if po_transfer%found is true }
11761
11762 /* The following code will be common for all the transactions not just for transfer to
11763 * get the use_mtl_lot and use_mtl_serial.
11764 */
11765 /*
11766 BEGIN Comment: Bug: 4735484
11767 IF x_cascaded_table(n).item_id IS NOT NULL THEN
11768 SELECT NVL(x_cascaded_table(n).use_mtl_lot, lot_control_code),
11769 NVL(x_cascaded_table(n).use_mtl_serial, serial_number_control_code)
11770 INTO x_cascaded_table(n).use_mtl_lot,
11771 x_cascaded_table(n).use_mtl_serial
11772 FROM mtl_system_items
11773 WHERE mtl_system_items.inventory_item_id = NVL(x_cascaded_table(n).item_id, 0)
11774 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
11775 END IF;
11776 END Comment: Bug: 4735484
11777 */
11778 x_cascaded_table(n).interface_source_code := 'RCV';
11779
11780 IF (x_cascaded_table(n).transaction_type = 'ACCEPT') THEN
11781 x_cascaded_table(n).inspection_status_code := 'ACCEPTED';
11782 x_cascaded_table(n).destination_context := 'RECEIVING';
11783 ELSIF(x_cascaded_table(n).transaction_type = 'REJECT') THEN
11784 x_cascaded_table(n).inspection_status_code := 'REJECTED';
11785 x_cascaded_table(n).destination_context := 'RECEIVING';
11786 END IF;
11787
11788 /* Only for deliver, to_subinventory is a required field. If the user
11789 * has not provided then we will not default for the other transactions.
11790 * from_subinventory will be the to_sub of the parent .
11791 */
11792 ---WMS Changes
11793 default_from_subloc_info(x_cascaded_table, n);
11794
11795 /* Bug 3557343.
11796 * We need to default to_sub/to_loc for other transactions also. We
11797 * used to do it only for deliver transactions. Now do it for
11798 * ACCEPT/REJECT transactions also.
11799 */
11800 IF (x_cascaded_table(n).transaction_type IN('DELIVER', 'ACCEPT', 'REJECT')) THEN
11801 default_to_subloc_info(x_cascaded_table, n);
11802 END IF;
11803
11804 /*
11805 ** Make sure to set the location_id properly
11806 */
11807 IF (x_cascaded_table(n).transaction_type = 'DELIVER') THEN
11808 x_cascaded_table(n).location_id := x_cascaded_table(n).deliver_to_location_id;
11809 END IF;
11810
11811 IF (g_asn_debug = 'Y') THEN
11812 asn_debug.put_line('Set Location_id = ' || TO_CHAR(x_cascaded_table(n).location_id));
11813 END IF;
11814
11815 IF (g_asn_debug = 'Y') THEN
11816 asn_debug.put_line('Exit default_vendor_trans_del');
11817 END IF;
11818
11819 IF po_transfer%ISOPEN THEN
11820 CLOSE po_transfer;
11821 END IF;
11822
11823 IF po_transfer_rti%ISOPEN THEN
11824 CLOSE po_transfer_rti;
11825 END IF;
11826 EXCEPTION
11827 WHEN OTHERS THEN
11828 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
11829 rcv_error_pkg.set_sql_error_message('default_vendor_trans_del', '000');
11830 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
11831 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
11832 END default_vendor_trans_del;
11833
11834
11835 PROCEDURE derive_correction_line(
11836 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
11837 n IN OUT NOCOPY BINARY_INTEGER,
11838 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
11839 x_header_record IN rcv_roi_preprocessor.header_rec_type
11840 ) IS
11841 l_po_header_id po_headers_all.po_header_id%type;
11842 l_return_status VARCHAR2(1) :='S';
11843 l_complex_flag varchar2(1);
11844
11845 BEGIN
11846 IF (g_asn_debug = 'Y') THEN
11847 asn_debug.put_line('enter derive_correction_line ');
11848 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
11849 END IF;
11850
11851 /* Derive the to_org_id */
11852 derive_ship_to_org_info(x_cascaded_table,
11853 n,
11854 x_header_record
11855 );
11856
11857 IF (x_cascaded_table(n).unit_of_measure IS NOT NULL) THEN
11858 IF (g_asn_debug = 'Y') THEN
11859 asn_debug.put_line('X_progress ' || x_progress);
11860 END IF;
11861
11862 SELECT muom.uom_code
11863 INTO x_cascaded_table(n).uom_code
11864 FROM mtl_units_of_measure muom
11865 WHERE muom.unit_of_measure = x_cascaded_table(n).unit_of_measure;
11866 ELSE
11867 IF (g_asn_debug = 'Y') THEN
11868 asn_debug.put_line('uom_code not derived as unit_of_measure is null');
11869 END IF;
11870 END IF;
11871
11872 x_progress := '091';
11873 derive_reason_info(x_cascaded_table, n);
11874 /* Auto_transact_code is null for all these transaction types */
11875 x_cascaded_table(n).auto_transact_code := NULL;
11876
11877 -- Determine whether this is a services line type
11878 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
11879 IF (g_asn_debug = 'Y') THEN
11880 asn_debug.put_line('parent_transaction_id ' || x_cascaded_table(n).parent_transaction_id);
11881 END IF;
11882
11883 SELECT po_line_id,po_header_id
11884 INTO x_cascaded_table(n).po_line_id,l_po_header_id
11885 FROM rcv_transactions
11886 WHERE transaction_id = x_cascaded_table(n).parent_transaction_id;
11887 ELSIF(x_cascaded_table(n).parent_interface_txn_id IS NOT NULL) THEN
11888 IF (g_asn_debug = 'Y') THEN
11889 asn_debug.put_line('parent_interface_txn_id ' || x_cascaded_table(n).parent_interface_txn_id);
11890 END IF;
11891
11892 SELECT po_line_id,po_header_id
11893 INTO x_cascaded_table(n).po_line_id,l_po_header_id
11894 FROM rcv_transactions_interface
11895 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
11896 END IF;
11897
11898 IF (g_asn_debug = 'Y') THEN
11899 asn_debug.put_line('po_line_id ' || x_cascaded_table(n).po_line_id);
11900 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
11901 END IF;
11902
11903 /* R12 Complex work.
11904 * We do not support any other receiving transactions other
11905 * than direct receipt. Error out if it is complex work PO.
11906 */
11907
11908 PO_COMPLEX_WORK_GRP.is_complex_work_po(
11909 1.0,
11910 l_po_header_id,
11911 l_return_status,
11912 l_complex_flag);
11913 IF (l_return_status IS NOT NULL AND
11914 l_return_status = FND_API.g_ret_sts_success) THEN
11915 IF( g_asn_debug = 'Y' ) THEN
11916 asn_debug.put_line('l_return_status ' || l_return_status);
11917 asn_debug.put_line('l_po_header_id ' || l_po_header_id);
11918 END IF;
11919 ELSE
11920 IF( g_asn_debug = 'Y') THEN
11921 asn_debug.put_line('l_return_status ' || l_return_status);
11922 END IF;
11923 END IF;
11924
11925 IF (l_complex_flag = 'Y') THEN
11926 asn_debug.put_line('We do not support transaction type ' || x_cascaded_table(n).transaction_type || ' for complex work POs');
11927 rcv_error_pkg.set_error_message('RCV_INVALID_TRANSACTION_TYPE');
11928 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE');
11929 End if;
11930
11931
11932 IF x_cascaded_table(n).po_line_id IS NOT NULL THEN
11933 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
11934 NVL(purchase_basis, 'GOODS'),
11935 NVL(matching_basis, 'QUANTITY')
11936 INTO x_cascaded_table(n).value_basis,
11937 x_cascaded_table(n).purchase_basis,
11938 x_cascaded_table(n).matching_basis
11939 FROM po_lines
11940 WHERE po_line_id = x_cascaded_table(n).po_line_id;
11941 ELSE
11942 -- we require line info for receiving against services lines
11943 x_cascaded_table(n).matching_basis := 'QUANTITY';
11944 x_cascaded_table(n).purchase_basis := 'GOODS';
11945 END IF;
11946
11947 IF (g_asn_debug = 'Y') THEN
11948 asn_debug.put_line('matching_basis ' || x_cascaded_table(n).matching_basis);
11949 END IF;
11950
11951 IF (x_cascaded_table(n).matching_basis = 'AMOUNT') THEN
11952 derive_correction_line_amt(x_cascaded_table,
11953 n,
11954 temp_cascaded_table
11955 );
11956 ELSE
11957 derive_correction_line_qty(x_cascaded_table,
11958 n,
11959 temp_cascaded_table
11960 );
11961 END IF;
11962
11963 IF (g_asn_debug = 'Y') THEN
11964 asn_debug.put_line('exit derive_correction_line');
11965 asn_debug.put_line('quantity ' || temp_cascaded_table(n).quantity);
11966 END IF;
11967 EXCEPTION
11968 WHEN OTHERS THEN
11969 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
11970 rcv_error_pkg.set_sql_error_message('derive_correction_line', '000');
11971 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
11972 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
11973 END derive_correction_line;
11974
11975 PROCEDURE derive_correction_line_qty(
11976 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
11977 n IN OUT NOCOPY BINARY_INTEGER,
11978 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type
11979 ) IS
11980 x_include_closed_po VARCHAR2(1); -- Bug 1887728
11981 /*
11982 ** Might be a compatibility issue between the two record definitions
11983 */
11984 x_record_count NUMBER;
11985 x_remaining_quantity NUMBER := 0;
11986 x_remaining_qty_po_uom NUMBER := 0;
11987 x_bkp_qty NUMBER := 0;
11988 x_progress VARCHAR2(3);
11989 x_to_organization_code VARCHAR2(5);
11990 x_converted_trx_qty NUMBER := 0;
11991 transaction_ok BOOLEAN := FALSE;
11992 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
11993 high_range_date DATE;
11994 low_range_date DATE;
11995 rows_fetched NUMBER := 0;
11996 x_tolerable_qty NUMBER := 0;
11997 x_first_trans BOOLEAN := TRUE;
11998 x_sysdate DATE := SYSDATE;
11999 current_n BINARY_INTEGER := 0;
12000 insert_into_table BOOLEAN := FALSE;
12001 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
12002 tax_amount_factor NUMBER;
12003 lastrecord BOOLEAN := FALSE;
12004 po_asn_uom_qty NUMBER;
12005 po_primary_uom_qty NUMBER;
12006 already_allocated_qty NUMBER := 0;
12007 x_item_id NUMBER;
12008 x_approved_flag VARCHAR(1);
12009 x_cancel_flag VARCHAR(1);
12010 x_closed_code VARCHAR(25);
12011 x_shipment_type VARCHAR(25);
12012 x_ship_to_organization_id NUMBER;
12013 x_ship_to_location_id NUMBER;
12014 /* temp_ship_to_location_id number;
12015 temp_mirror_ship_to_loc_id number ;
12016 temp_enf_ship_to_loc_code varchar(25) ; */
12017 /* The above 3 variables added for bug 1898283 */
12018 x_vendor_product_num VARCHAR(25);
12019 x_temp_count NUMBER;
12020 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
12021 /* 1887728 -Added the following variables */
12022 profile_user_id NUMBER := -1;
12023 profile_appl_id NUMBER := -1;
12024 profile_resp_id NUMBER := -1;
12025 defined BOOLEAN;
12026 /* 1845702 */
12027 x_sob_id NUMBER := NULL;
12028 x_rate NUMBER;
12029 x_allow_rate_override VARCHAR2(1);
12030 /* Bug# 1548597 */
12031 x_secondary_available_qty NUMBER := 0;
12032
12033 /********************************************************************/
12034 CURSOR po_correct(
12035 v_parent_trx_id NUMBER,
12036 v_to_organization_id NUMBER
12037 ) IS
12038 SELECT rt.po_line_location_id,
12039 rt.po_header_id po_head_id,
12040 rt.po_line_id line_id,
12041 rt.transaction_id rcv_transaction_id,
12042 rt.parent_transaction_id grand_parent_txn_id,
12043 poh.segment1 document_num,
12044 pol.line_num line_number,
12045 rt.transaction_date transaction_date,
12046 rt.transaction_type parent_transaction_type,
12047 rt.quantity qty,
12048 rt.unit_of_measure unit_of_meas,
12049 rt.primary_unit_of_measure,
12050 rt.primary_quantity,
12051 rt.organization_id,
12052 rt.po_unit_price unit_price,
12053 rsl.category_id,
12054 rsl.item_description,
12055 rt.po_line_id,
12056 rt.location_id,
12057 rsl.item_id,
12058 rt.deliver_to_person_id,
12059 rt.deliver_to_location_id,
12060 rt.subinventory destination_subinventory,
12061 rt.po_distribution_id,
12062 rt.destination_type_code,
12063 rt.wip_entity_id,
12064 rt.wip_operation_seq_num,
12065 rt.wip_resource_seq_num,
12066 rt.wip_repetitive_schedule_id,
12067 rt.wip_line_id,
12068 rt.bom_resource_id,
12069 rsl.ussgl_transaction_code
12070 FROM rcv_transactions rt,
12071 rcv_shipment_lines rsl,
12072 po_headers poh,
12073 po_lines pol
12074 WHERE rt.transaction_id = v_parent_trx_id
12075 AND rt.organization_id = NVL(v_to_organization_id, rt.organization_id)
12076 AND ( rt.transaction_type IN('RECEIVE', 'TRANSFER', 'ACCEPT', 'REJECT', 'MATCH')
12077 OR ( rt.transaction_type IN('RETURN TO VENDOR', 'RETURN TO CUSTOMER')
12078 AND NOT EXISTS(SELECT 'rtv to processed matched unordered receipt'
12079 FROM rcv_transactions rt2,
12080 rcv_transactions rt3
12081 WHERE rt2.transaction_id = rt.parent_transaction_id
12082 AND rt2.transaction_type = 'UNORDERED'
12083 AND rt3.transaction_type = 'MATCH'
12084 AND rt3.parent_transaction_id = rt2.transaction_id)
12085 AND NOT EXISTS(SELECT 'rtv to unprocessed matched unordered receipt'
12086 FROM rcv_transactions rt2,
12087 rcv_transactions_interface rti
12088 WHERE rt2.transaction_id = rt.parent_transaction_id
12089 AND rt2.transaction_type = 'UNORDERED'
12090 AND rti.transaction_type = 'MATCH'
12091 AND rti.parent_transaction_id = rt2.transaction_id)
12092 )
12093 OR ( rt.transaction_type = 'DELIVER'
12094 AND NOT( rt.destination_type_code = 'INVENTORY'
12095 AND rt.source_document_code IN('REQ', 'INVENTORY', 'RMA')))
12096 OR ( rt.transaction_type = 'UNORDERED'
12097 AND NOT EXISTS(SELECT 'processed matched rows'
12098 FROM rcv_transactions rt2
12099 WHERE rt2.parent_transaction_id = rt.transaction_id
12100 AND rt2.transaction_type = 'MATCH')
12101 AND NOT EXISTS(SELECT 'unprocessed matched rows'
12102 FROM rcv_transactions_interface rti
12103 WHERE rti.parent_transaction_id = rt.transaction_id
12104 AND rti.transaction_type = 'MATCH')
12105 )
12106 )
12107 AND NOT EXISTS(SELECT 'purchase order shipment cancelled or fc'
12108 FROM po_line_locations pll
12109 WHERE pll.line_location_id = rt.po_line_location_id
12110 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
12111 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED'))
12112 AND (rt.shipment_line_id = rsl.shipment_line_id)
12113 AND (poh.po_header_id = rt.po_header_id)
12114 AND (pol.po_line_id = rt.po_line_id)
12115 AND ( rt.dropship_type_code = 3
12116 OR rt.dropship_type_code IS NULL)
12117 ORDER BY rt.transaction_id;
12118
12119 CURSOR po_correct_rti(
12120 v_parent_interface_txn_id NUMBER
12121 ) IS
12122 SELECT rti.po_line_location_id,
12123 rti.po_header_id po_head_id,
12124 rti.po_line_id line_id,
12125 rti.interface_transaction_id rcv_transaction_id,
12126 rti.parent_transaction_id grand_parent_txn_id,
12127 rti.document_num,
12128 rti.document_line_num line_number,
12129 rti.transaction_date transaction_date,
12130 rti.transaction_type parent_transaction_type,
12131 rti.quantity qty,
12132 rti.unit_of_measure unit_of_meas,
12133 rti.primary_unit_of_measure,
12134 rti.primary_quantity,
12135 rti.to_organization_id organization_id,
12136 rti.po_unit_price unit_price,
12137 rti.category_id,
12138 rti.item_description,
12139 rti.po_line_id,
12140 rti.location_id,
12141 rti.item_id,
12142 rti.deliver_to_person_id,
12143 rti.deliver_to_location_id,
12144 rti.subinventory destination_subinventory,
12145 rti.po_distribution_id,
12146 rti.destination_type_code,
12147 rti.wip_entity_id,
12148 rti.wip_operation_seq_num,
12149 rti.wip_resource_seq_num,
12150 rti.wip_repetitive_schedule_id,
12151 rti.wip_line_id,
12152 rti.bom_resource_id,
12153 rti.ussgl_transaction_code
12154 FROM rcv_transactions_interface rti
12155 WHERE interface_transaction_id = v_parent_interface_txn_id;
12156
12157 x_po_correctrec po_correct%ROWTYPE;
12158 x_temp_parent_trx_qty NUMBER := 0;
12159 x_converted_parent_trx_qty NUMBER := 0;
12160 x_temp_convert_parent_trx_qty NUMBER := 0;
12161 x_remaining_qty_parent_uom NUMBER := 0;
12162 l_to_organization_id NUMBER := 0;
12163 l_transaction_type rcv_transactions.transaction_type%TYPE;
12164 x_temp_already_allocated_qty NUMBER := 0;
12165 derive_values_from_table BOOLEAN := FALSE;
12166 derive_values_from_rti BOOLEAN := FALSE;
12167 already_derived BOOLEAN := FALSE;
12168 cascaded_table_index NUMBER;
12169 l_grand_parent_trx_id rcv_transactions.parent_transaction_id%TYPE;
12170 temp_index NUMBER;
12171 l_line_loc_id po_line_locations.line_location_id%TYPE;
12172 l_exist VARCHAR2(30);
12173 l_exist1 VARCHAR2(30);
12174 l_exist2 VARCHAR2(30);
12175 l_destination_type_code rcv_transactions.destination_type_code%TYPE;
12176 l_source_document_code rcv_transactions.source_document_code%TYPE;
12177 /* Bug#5369121 */
12178 l_primary_uom rcv_transactions_interface.unit_of_measure%TYPE;
12179 l_transaction_uom rcv_transactions.unit_of_measure%TYPE;
12180 l_interface_quantity NUMBER;
12181 l_interface_qty_in_trx_uom NUMBER;
12182 l_item_id NUMBER;
12183 /* Bug#5369121 */
12184 BEGIN
12185 IF (g_asn_debug = 'Y') THEN
12186 asn_debug.put_line('enter derive_quantity ' || x_cascaded_table(n).parent_transaction_id);
12187 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
12188 END IF;
12189
12190 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
12191 already_derived := TRUE;
12192 END IF; --}
12193
12194 IF ( NOT already_derived
12195 AND (x_cascaded_table(n).parent_interface_txn_id IS NULL)
12196 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN --{
12197 /* This means that there can be a row in RT with src_txn_id
12198 * populated or it can be a child.
12199 */
12200 BEGIN
12201 SELECT transaction_id
12202 INTO x_cascaded_table(n).parent_transaction_id
12203 FROM rcv_transactions
12204 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
12205
12206 already_derived := TRUE;
12207 EXCEPTION
12208 WHEN NO_DATA_FOUND THEN
12209 -- this is fine since this could be a child.
12210 NULL;
12211 END;
12212 END IF; --}
12213
12214 IF already_derived THEN --{
12215 IF (g_asn_debug = 'Y') THEN
12216 asn_debug.put_line(' open po_correct table ' || x_cascaded_table(n).parent_transaction_id);
12217 END IF;
12218
12219 OPEN po_correct(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
12220 END IF; ---}
12221
12222 IF (NOT already_derived) THEN --{
12223 derive_parent_id(x_cascaded_table, n);
12224
12225 /* This means that there was no error in
12226 * derive_parent_id which means that the
12227 * this is a child and need to get the values
12228 * from the rti and not from the plsql table.
12229 */
12230 IF ( (x_cascaded_table(n).error_status <> 'E')
12231 AND ( x_cascaded_table(n).derive = 'Y'
12232 AND x_cascaded_table(n).derive_index = 0)) THEN
12233 /* if derive_values_from_table is true, then we
12234 * derive the values from the pl/sql tables later
12235 * at the time when we try to see which cursor is open.
12236 * We will have x_cascaded_table(n).
12237 * parent_interface_txn_id) populated with teh
12238 * correct value.
12239 */
12240 IF (g_asn_debug = 'Y') THEN
12241 asn_debug.put_line(' open correct cursor from rti');
12242 END IF;
12243
12244 OPEN po_correct_rti(x_cascaded_table(n).parent_interface_txn_id);
12245 END IF;
12246 END IF; --}
12247
12248 /******************************************************************/
12249 --check line quanity > 0
12250 x_progress := '097';
12251
12252 IF (g_asn_debug = 'Y') THEN
12253 asn_debug.put_line('X_progress ' || x_progress);
12254 END IF;
12255
12256 IF x_cascaded_table(n).error_status IN('S', 'W')
12257 AND x_cascaded_table(n).quantity = 0 THEN --{
12258 IF (g_asn_debug = 'Y') THEN
12259 asn_debug.put_line('Quantity is <= zero. Cascade will fail');
12260 END IF;
12261
12262 x_cascaded_table(n).error_status := 'F';
12263 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
12264 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
12265 END IF; --} end qty > 0 check
12266
12267 -- the following steps will create a set of rows linking the line_record with
12268 -- its corresponding po_line_location rows until the quantity value from
12269 -- the asn is consumed. (Cascade)
12270
12271 /* 2119137 : If the user populates rcv_transactions_interface
12272 with po_line_id, then ROI errors out with
12273 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
12274 is not provided for one time items. Modified the "if" criteria in
12275 such a way that the ROI validation does'nt error out when
12276 po_line_id is populated for one time items. */
12277 x_progress := '098';
12278
12279 IF (g_asn_debug = 'Y') THEN
12280 asn_debug.put_line('X_progress ' || x_progress);
12281 END IF;
12282
12283 IF ( ( x_cascaded_table(n).parent_transaction_id IS NOT NULL
12284 OR x_cascaded_table(n).parent_interface_txn_id IS NOT NULL)
12285 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
12286
12287 -- Copy record from main table to temp table
12288 IF (g_asn_debug = 'Y') THEN
12289 asn_debug.put_line('Copy record from main table to temp table');
12290 END IF;
12291
12292 current_n := 1;
12293 temp_cascaded_table(current_n) := x_cascaded_table(n);
12294
12295 -- Get all rows which meet this condition
12296 IF (g_asn_debug = 'Y') THEN
12297 asn_debug.put_line('Get all rows which meet this condition');
12298 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
12299 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
12300 END IF;
12301
12302 -- Assign shipped quantity to remaining quantity
12303 IF (g_asn_debug = 'Y') THEN
12304 asn_debug.put_line('Assign populated quantity to remaining quantity');
12305 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
12306 END IF;
12307
12308 x_remaining_quantity := temp_cascaded_table(current_n).quantity;
12309 x_bkp_qty := x_remaining_quantity; -- used for decrementing cum qty for first record
12310 x_remaining_qty_po_uom := 0;
12311
12312 IF (g_asn_debug = 'Y') THEN
12313 asn_debug.put_line('Have assigned the quantity');
12314 END IF;
12315
12316 -- Calculate tax_amount_factor for calculating tax_amount for
12317 -- each cascaded line
12318
12319 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
12320 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_quantity;
12321 ELSE
12322 tax_amount_factor := 0;
12323 END IF;
12324
12325 IF (g_asn_debug = 'Y') THEN
12326 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
12327 asn_debug.put_line('transaction Quantity : ' || TO_CHAR(x_remaining_quantity));
12328 END IF;
12329
12330 x_first_trans := TRUE;
12331 transaction_ok := FALSE;
12332
12333 IF (g_asn_debug = 'Y') THEN
12334 asn_debug.put_line('Before starting Cascade');
12335 END IF;
12336
12337 IF (g_asn_debug = 'Y') THEN
12338 asn_debug.put_line('Record Count = ' || x_record_count);
12339 END IF;
12340
12341 LOOP --{
12342 IF (g_asn_debug = 'Y') THEN
12343 asn_debug.put_line('Backup Qty ' || TO_CHAR(x_bkp_qty));
12344 asn_debug.put_line('Remaining Quantity ' || TO_CHAR(x_remaining_quantity));
12345 END IF;
12346
12347 /*
12348 ** Fetch the appropriate record
12349 */
12350 IF (g_asn_debug = 'Y') THEN
12351 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
12352 END IF;
12353
12354 IF (po_correct%ISOPEN) THEN --{
12355 IF (g_asn_debug = 'Y') THEN
12356 asn_debug.put_line(' fetch po_correct');
12357 END IF;
12358
12359 FETCH po_correct INTO x_po_correctrec;
12360
12361 IF (po_correct%NOTFOUND) THEN
12362 lastrecord := TRUE;
12363 END IF;
12364
12365 rows_fetched := po_correct%ROWCOUNT;
12366 ELSIF(po_correct_rti%ISOPEN) THEN --}{
12367 IF (g_asn_debug = 'Y') THEN
12368 asn_debug.put_line(' fetch po_correct_rti');
12369 END IF;
12370
12371 FETCH po_correct_rti INTO x_po_correctrec;
12372
12373 IF (po_correct_rti%NOTFOUND) THEN
12374 IF (g_asn_debug = 'Y') THEN
12375 asn_debug.put_line('correct last row');
12376 END IF;
12377
12378 lastrecord := TRUE;
12379 END IF;
12380
12381 rows_fetched := po_correct_rti%ROWCOUNT;
12382 ELSIF(temp_cascaded_table(current_n).derive = 'Y') THEN --}{
12383 /* GET VALUES FROM THE PLSQL TABLE */
12384 /* Populate x_po_correctrec with these values since
12385 * we are using x_po_correctrec later.
12386 * We have temp_cascaded_table(current_n).
12387 * parent_interface_txn_id) populated with
12388 * with the correct value. Also we have cascaded_table_index
12389 * with the correct pl/sql table index number;
12390 */
12391 IF (g_asn_debug = 'Y') THEN
12392 asn_debug.put_line(' fetch pl/sql table');
12393 END IF;
12394
12395 temp_index := temp_cascaded_table(current_n).derive_index;
12396 x_po_correctrec.po_line_location_id := x_cascaded_table(temp_index).po_line_location_id;
12397 x_po_correctrec.po_head_id := x_cascaded_table(temp_index).po_header_id;
12398 x_po_correctrec.line_id := x_cascaded_table(temp_index).po_line_id;
12399 x_po_correctrec.unit_of_meas := x_cascaded_table(temp_index).unit_of_measure;
12400 x_po_correctrec.grand_parent_txn_id := x_cascaded_table(temp_index).parent_transaction_id;
12401 x_po_correctrec.document_num := x_cascaded_table(temp_index).document_num;
12402 x_po_correctrec.line_number := x_cascaded_table(temp_index).document_line_num;
12403 x_po_correctrec.transaction_date := x_cascaded_table(temp_index).transaction_date;
12404 x_po_correctrec.parent_transaction_type := x_cascaded_table(temp_index).transaction_type;
12405 x_po_correctrec.qty := x_cascaded_table(temp_index).quantity;
12406 x_po_correctrec.primary_unit_of_measure := x_cascaded_table(temp_index).primary_unit_of_measure;
12407 x_po_correctrec.primary_quantity := x_cascaded_table(temp_index).primary_quantity;
12408 x_po_correctrec.organization_id := x_cascaded_table(temp_index).to_organization_id;
12409 x_po_correctrec.unit_price := x_cascaded_table(temp_index).po_unit_price;
12410 x_po_correctrec.category_id := x_cascaded_table(temp_index).category_id;
12411 x_po_correctrec.item_description := x_cascaded_table(temp_index).item_description;
12412 x_po_correctrec.location_id := x_cascaded_table(temp_index).location_id;
12413 x_po_correctrec.item_id := x_cascaded_table(temp_index).item_id;
12414 x_po_correctrec.deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
12415 x_po_correctrec.deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
12416 x_po_correctrec.destination_subinventory := x_cascaded_table(temp_index).subinventory;
12417 x_po_correctrec.po_distribution_id := x_cascaded_table(temp_index).po_distribution_id;
12418 x_po_correctrec.destination_type_code := x_cascaded_table(temp_index).destination_type_code;
12419 x_po_correctrec.wip_entity_id := x_cascaded_table(temp_index).wip_entity_id;
12420 x_po_correctrec.wip_operation_seq_num := x_cascaded_table(temp_index).wip_operation_seq_num;
12421 x_po_correctrec.wip_resource_seq_num := x_cascaded_table(temp_index).wip_resource_seq_num;
12422 x_po_correctrec.wip_repetitive_schedule_id := x_cascaded_table(temp_index).wip_repetitive_schedule_id;
12423 x_po_correctrec.wip_line_id := x_cascaded_table(temp_index).wip_line_id;
12424 x_po_correctrec.bom_resource_id := x_cascaded_table(temp_index).bom_resource_id;
12425 x_po_correctrec.ussgl_transaction_code := x_cascaded_table(temp_index).ussgl_transaction_code;
12426 /* Also fetch parent transaction type and grand parent trx id into
12427 * the correct variables.
12428 */
12429 rows_fetched := 1;
12430 lastrecord := TRUE;
12431 END IF; --}
12432 --x_remaining_quantity:= temp_cascaded_table(current_n).quantity;
12433
12434 IF (g_asn_debug = 'Y') THEN
12435 asn_debug.put_line('Correct Rows fetched ' || TO_CHAR(rows_fetched));
12436 asn_debug.put_line('po_line_id ' || TO_CHAR(x_po_correctrec.po_line_id));
12437 asn_debug.put_line('po_dist ' || TO_CHAR(x_po_correctrec.po_distribution_id));
12438 asn_debug.put_line('correct remainaing qty ' || x_remaining_quantity);
12439 END IF;
12440
12441 IF (lastrecord) THEN --{
12442 IF (g_asn_debug = 'Y') THEN
12443 asn_debug.put_line('Hit exit condition');
12444 END IF;
12445
12446 IF NOT x_first_trans THEN
12447 -- x_first_trans has been reset which means some cascade has
12448 -- happened. Otherwise current_n = 1
12449 IF (g_asn_debug = 'Y') THEN
12450 asn_debug.put_line('current_n before is ' || current_n);
12451 END IF;
12452
12453 current_n := current_n - 1;
12454 END IF;
12455
12456 -- do the tolerance act here
12457 IF (g_asn_debug = 'Y') THEN
12458 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
12459 asn_debug.put_line('Check which condition has occured');
12460 END IF;
12461
12462 -- lastrecord...we have run out of rows and we still have quantity to allocate
12463 /* Do abs(x_remaining_quantity) since it can be a negative
12464 * or positive correction.
12465 */
12466 IF ABS(x_remaining_quantity) > 0 THEN --{
12467 IF (g_asn_debug = 'Y') THEN
12468 asn_debug.put_line('There is quantity remaining ');
12469 asn_debug.put_line('tolerable quantity now in plsql table ' || temp_cascaded_table(current_n).quantity);
12470 asn_debug.put_line('rows_fetched ' || rows_fetched);
12471 END IF;
12472
12473 IF NOT x_first_trans THEN
12474 IF (g_asn_debug = 'Y') THEN
12475 asn_debug.put_line('not fisrt txn');
12476 END IF;
12477 END IF;
12478
12479 IF rows_fetched > 0
12480 AND NOT x_first_trans THEN --{
12481 IF (g_asn_debug = 'Y') THEN
12482 asn_debug.put_line(' inside transaction_type ' || x_po_correctrec.parent_transaction_type);
12483 END IF;
12484
12485 IF (SIGN(x_cascaded_table(current_n).quantity) = 1) THEN --{
12486 IF (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH')) THEN --{
12487 IF (g_asn_debug = 'Y') THEN
12488 asn_debug.put_line('Need to check qty tolerances');
12489 END IF;
12490
12491 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
12492 INTO x_qty_rcv_exception_code
12493 FROM po_line_locations
12494 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
12495
12496 IF (g_asn_debug = 'Y') THEN
12497 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
12498 END IF;
12499
12500 IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
12501 /* Bug# 1807842 */
12502 IF (temp_cascaded_table(current_n).quantity <= x_converted_parent_trx_qty) THEN --{
12503 IF (g_asn_debug = 'Y') THEN
12504 asn_debug.put_line('Tolerable quantity ' || TO_CHAR(x_converted_parent_trx_qty));
12505 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
12506 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
12507 asn_debug.put_line('Assign remaining ASN UOM qty ' || TO_CHAR(x_remaining_quantity) || ' to last record');
12508 asn_debug.put_line('Assign remaining PO UOM qty ' || TO_CHAR(x_remaining_qty_po_uom) || ' to last record');
12509 END IF;
12510
12511 temp_cascaded_table(current_n).quantity := temp_cascaded_table(current_n).quantity + x_remaining_quantity;
12512 temp_cascaded_table(current_n).primary_quantity := temp_cascaded_table(current_n).primary_quantity
12513 + rcv_transactions_interface_sv.convert_into_correct_qty(x_remaining_quantity,
12514 temp_cascaded_table(1).unit_of_measure,
12515 temp_cascaded_table(1).item_id,
12516 temp_cascaded_table(1).primary_unit_of_measure
12517 );
12518 END IF; /* Bug# 1807842 */ --}
12519
12520 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).quantity * tax_amount_factor, 6);
12521
12522 IF (g_asn_debug = 'Y') THEN
12523 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
12524 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
12525 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
12526 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
12527 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
12528 END IF;
12529
12530 IF x_qty_rcv_exception_code = 'WARNING' THEN --{
12531 IF (g_asn_debug = 'Y') THEN
12532 asn_debug.put_line('IN WARNING');
12533 END IF;
12534
12535 temp_cascaded_table(current_n).error_status := 'W';
12536 temp_cascaded_table(current_n).error_message := 'RCV_ALL_QTY_OVER_TOLERANCE';
12537
12538 IF (g_asn_debug = 'Y') THEN
12539 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
12540 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
12541 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
12542 END IF;
12543
12544 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
12545 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
12546 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
12547 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
12548 rcv_error_pkg.log_interface_warning('QUANTITY');
12549
12550 IF (g_asn_debug = 'Y') THEN
12551 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
12552 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
12553 asn_debug.put_line('Need to insert into po_interface_errors');
12554 END IF;
12555 END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
12556
12557 IF (g_asn_debug = 'Y') THEN
12558 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity));
12559 asn_debug.put_line('Current shipped quantity ' || TO_CHAR(temp_cascaded_table(current_n).quantity_shipped));
12560 asn_debug.put_line('Current source document quantity ' || TO_CHAR(temp_cascaded_table(current_n).source_doc_quantity));
12561 asn_debug.put_line('Current primary quantity ' || TO_CHAR(temp_cascaded_table(current_n).primary_quantity));
12562 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
12563 END IF;
12564 END IF; --}
12565 END IF; --}
12566
12567 IF ( ( (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH'))
12568 AND x_qty_rcv_exception_code = 'REJECT')
12569 OR (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH'))) THEN --{
12570 IF (g_asn_debug = 'Y') THEN
12571 asn_debug.put_line('Extra ASN UOM Quantity ' || TO_CHAR(x_remaining_quantity));
12572 asn_debug.put_line('Extra PO UOM Quantity ' || TO_CHAR(x_remaining_qty_po_uom));
12573 END IF;
12574
12575 IF (g_asn_debug = 'Y') THEN
12576 asn_debug.put_line('delete the temp table ');
12577 END IF;
12578
12579 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12580 rcv_error_pkg.set_error_message('RCV_CORRECT_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
12581 rcv_error_pkg.set_token('QTY_A', temp_cascaded_table(current_n).quantity);
12582 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity - x_remaining_quantity);
12583 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
12584
12585 IF temp_cascaded_table.COUNT > 0 THEN
12586 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
12587 temp_cascaded_table.DELETE(i);
12588 END LOOP;
12589 END IF;
12590
12591 IF (g_asn_debug = 'Y') THEN
12592 asn_debug.put_line('mark the actual table with error status');
12593 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
12594 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
12595 END IF;
12596
12597 IF (g_asn_debug = 'Y') THEN
12598 asn_debug.put_line('Need to insert a row into po_interface_errors');
12599 END IF;
12600 END IF; --} matches if(none/warning) and elseif(reject)
12601 END IF; --}
12602
12603 IF (SIGN(x_cascaded_table(current_n).quantity) = -1) THEN --{
12604 /* for correct,accept an reject type we dont have the
12605 * tolerance check. Hence error out.
12606 * We cannot correct quantities more than that was received.
12607 */
12608 IF (g_asn_debug = 'Y') THEN
12609 asn_debug.put_line(' in correct extra Quantity ' || TO_CHAR(x_remaining_quantity));
12610 END IF;
12611
12612 IF (g_asn_debug = 'Y') THEN
12613 asn_debug.put_line('delete the temp table ');
12614 END IF;
12615 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12616 rcv_error_pkg.set_error_message('RCV_CORRECT_QTY_OVER_TOLERANCE', x_cascaded_table(n).error_message);
12617 rcv_error_pkg.set_token('QTY_A', x_cascaded_table(current_n).quantity);
12618 rcv_error_pkg.set_token('QTY_B', temp_cascaded_table(current_n).quantity);
12619 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
12620
12621 IF temp_cascaded_table.COUNT > 0 THEN
12622 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
12623 temp_cascaded_table.DELETE(i);
12624 END LOOP;
12625 END IF;
12626
12627 IF (g_asn_debug = 'Y') THEN
12628 asn_debug.put_line('mark the actual table with error status');
12629 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
12630 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
12631 END IF;
12632
12633 IF (g_asn_debug = 'Y') THEN
12634 asn_debug.put_line('Need to insert a row into po_interface_errors for correct');
12635 END IF;
12636 END IF; --}
12637 ELSE --}{ else for rows fetched = 0 OR x_first_trans = true
12638 IF rows_fetched = 0 THEN
12639 IF (g_asn_debug = 'Y') THEN
12640 asn_debug.put_line('No rows were retrieved from cursor.');
12641 END IF;
12642 ELSIF x_first_trans THEN
12643 IF (g_asn_debug = 'Y') THEN
12644 asn_debug.put_line('No rows were cascaded');
12645 END IF;
12646 END IF;
12647
12648 x_temp_count := 1;
12649 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12650
12651 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
12652 /* Give an error just like it is done for the
12653 * the receipt transaction;
12654 */
12655 SELECT parent_transaction_id,
12656 transaction_type,
12657 po_line_location_id,
12658 destination_type_code,
12659 source_document_code
12660 INTO l_grand_parent_trx_id,
12661 l_transaction_type,
12662 l_line_loc_id,
12663 l_destination_type_code,
12664 l_source_document_code
12665 FROM rcv_transactions rt
12666 WHERE rt.transaction_id = temp_cascaded_table(current_n).parent_transaction_id;
12667
12668 IF (l_transaction_type = 'DELIVER') THEN --{
12669 IF ( l_destination_type_code = 'INVENTORY'
12670 OR l_source_document_code IN('REQ', 'INVENTORY', 'RMA')) THEN
12671 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12672 rcv_error_pkg.set_error_message('RCV_INVAL_SOURCE_DOC_FOR_DEL', x_cascaded_table(n).error_message);
12673 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12674 END IF;
12675 END IF; --}
12676
12677 IF (l_transaction_type = 'UNORDERED') THEN --{
12678 SELECT MAX('record_exist')
12679 INTO l_exist
12680 FROM rcv_transactions rt2
12681 WHERE rt2.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
12682 AND rt2.transaction_type = 'MATCH';
12683
12684 SELECT MAX('record_exist')
12685 INTO l_exist1
12686 FROM rcv_transactions_interface rti
12687 WHERE rti.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
12688 AND rti.transaction_type = 'MATCH';
12689
12690 IF l_exist = 'record_exist' THEN --{
12691 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12692 rcv_error_pkg.set_error_message('RCV_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
12693 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12694 END IF; --}
12695
12696 IF l_exist1 = 'record_exist' THEN --{
12697 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12698 rcv_error_pkg.set_error_message('RCV_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
12699 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12700 END IF; --}
12701 END IF; --}
12702
12703 IF (l_transaction_type = 'RETURN TO VENDOR') THEN --{
12704 SELECT MAX('record_exist')
12705 INTO l_exist
12706 FROM rcv_transactions rt2,
12707 rcv_transactions rt3
12708 WHERE rt2.transaction_id = l_grand_parent_trx_id
12709 AND rt2.transaction_type = 'UNORDERED'
12710 AND rt3.transaction_type = 'MATCH'
12711 AND rt3.parent_transaction_id = rt2.transaction_id;
12712
12713 SELECT MAX('record_exist')
12714 INTO l_exist1
12715 FROM rcv_transactions rt2,
12716 rcv_transactions_interface rti
12717 WHERE rt2.transaction_id = l_grand_parent_trx_id
12718 AND rt2.transaction_type = 'UNORDERED'
12719 AND rti.transaction_type = 'MATCH'
12720 AND rti.parent_transaction_id = rt2.transaction_id;
12721
12722 IF l_exist = 'record_exist' THEN --{
12723 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12724 rcv_error_pkg.set_error_message('RCV_RET_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
12725 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12726 END IF; --}
12727
12728 IF l_exist1 = 'record_exist' THEN --{
12729 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12730 rcv_error_pkg.set_error_message('RCV_RET_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
12731 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12732 END IF; --}
12733 END IF; --}
12734
12735 SELECT MAX('record_exist')
12736 INTO l_exist2
12737 FROM po_line_locations pll
12738 WHERE pll.line_location_id = l_line_loc_id
12739 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
12740 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED');
12741
12742 IF l_exist2 = 'record_exist' THEN
12743 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
12744 rcv_error_pkg.set_error_message('RCV_PO_SHIPMENT_CANCELLED', x_cascaded_table(n).error_message);
12745 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
12746 END IF;
12747 END IF; --}
12748
12749 -- Delete the temp_cascaded_table just to be sure
12750
12751 IF temp_cascaded_table.COUNT > 0 THEN
12752 FOR i IN 1 .. temp_cascaded_table.COUNT LOOP
12753 temp_cascaded_table.DELETE(i);
12754 END LOOP;
12755 END IF;
12756 END IF; --}
12757 ELSE -- }{
12758 IF (g_asn_debug = 'Y') THEN
12759 asn_debug.put_line('Remaining UOM quantity is zero ' || TO_CHAR(x_remaining_quantity));
12760 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
12761 END IF;
12762 END IF; --} ends the check for whether last record has been reached
12763
12764 -- close cursors
12765
12766 IF (g_asn_debug = 'Y') THEN
12767 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions ' || current_n);
12768 END IF;
12769
12770 IF po_correct%ISOPEN THEN
12771 CLOSE po_correct;
12772 END IF;
12773
12774 IF po_correct_rti%ISOPEN THEN
12775 CLOSE po_correct_rti;
12776 END IF;
12777
12778 IF (g_asn_debug = 'Y') THEN
12779 asn_debug.put_line('before exit current_n is ' || current_n);
12780 END IF;
12781
12782 EXIT;
12783 END IF; --} matches lastrecord or x_remaining_quantity <= 0
12784
12785 -- bug fix 5269121 :it is wrong to
12786 --copy the parents unit of measure into the childs unit of measure, as this will be the one
12787 --which will be finally populated into RT for the child record (correction record).
12788 --temp_cascaded_table(current_n).unit_of_measure := x_po_correctrec.unit_of_meas;
12789
12790 IF (g_asn_debug = 'Y') THEN
12791 asn_debug.put_line(' Entering qty calculation for correct');
12792 END IF;
12793
12794 IF (x_first_trans)
12795 AND temp_cascaded_table(current_n).item_id IS NULL THEN
12796 temp_cascaded_table(current_n).item_id := x_po_correctrec.item_id;
12797 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_correctrec.primary_unit_of_measure;
12798 END IF;
12799
12800 insert_into_table := FALSE;
12801 already_allocated_qty := 0;
12802
12803 IF (g_asn_debug = 'Y') THEN
12804 asn_debug.put_line('calling Correct get_available_qty ' || x_po_correctrec.parent_transaction_type);
12805 END IF;
12806
12807 get_interface_available_qty(temp_cascaded_table,
12808 current_n,
12809 x_converted_parent_trx_qty
12810 );
12811
12812 IF (g_asn_debug = 'Y') THEN
12813 asn_debug.put_line('correct interface_available_qty ' || x_converted_parent_trx_qty);
12814 END IF;
12815
12816 /* x_converted_parent_trx_qty will be 0 when this is not a child
12817 * transaction to any rti row. Also for correct, grand parent
12818 * may already be processed and for positive correction we
12819 * might need to get the quantity from the grand parent.
12820 */
12821 IF (x_converted_parent_trx_qty = 0) THEN --{
12822 IF (g_asn_debug = 'Y') THEN
12823 asn_debug.put_line('interface qty is 0');
12824 END IF;
12825
12826 IF (SIGN(temp_cascaded_table(current_n).quantity) = -1) THEN --{
12827 rcv_quantities_s.get_available_quantity('CORRECT',
12828 x_po_correctrec.rcv_transaction_id,
12829 'VENDOR',
12830 x_po_correctrec.parent_transaction_type,
12831 NULL,
12832 'NEGATIVE',
12833 x_converted_parent_trx_qty,
12834 x_tolerable_qty,
12835 x_po_correctrec.unit_of_meas,
12836 x_secondary_available_qty
12837 );
12838
12839 /* Bug#5369121 - START */
12840 IF (g_asn_debug = 'Y') THEN
12841 asn_debug.put_line('x_converted_parent_trx_qty:' || x_converted_parent_trx_qty);
12842 asn_debug.put_line('transaction_quantity:' || temp_cascaded_table(current_n).quantity);
12843 END IF;
12844
12845 IF (x_converted_parent_trx_qty < ABS(temp_cascaded_table(current_n).quantity)) THEN
12846
12847 SELECT rt.unit_of_measure,
12848 rsl.item_id,
12849 rt.primary_unit_of_measure
12850 INTO l_transaction_uom,
12851 l_item_id,
12852 l_primary_uom
12853 FROM rcv_transactions rt,
12854 rcv_shipment_lines rsl
12855 WHERE rsl.shipment_line_id = rt.shipment_line_id
12856 AND rt.transaction_id = x_po_correctrec.rcv_transaction_id;
12857
12858 SELECT NVL(SUM(interface_transaction_qty),0)
12859 INTO l_interface_quantity
12860 FROM rcv_transactions_interface
12861 WHERE (transaction_status_code = 'PENDING'
12862 AND processing_status_code <> 'ERROR')
12863 AND group_id = temp_cascaded_table(current_n).group_id
12864 AND transaction_type = 'CORRECT'
12865 AND parent_transaction_id IN ( SELECT transaction_id
12866 FROM rcv_transactions
12867 WHERE parent_transaction_id = x_po_correctrec.rcv_transaction_id);
12868
12869 IF (l_interface_quantity = 0) THEN
12870
12871 /*
12872 ** There is no unprocessed quantity. Simply set the
12873 ** x_interface_qty_in_trx_uom to 0. There is no need for uom
12874 ** conversion.
12875 */
12876
12877 l_interface_qty_in_trx_uom := 0;
12878
12879 ELSE
12880
12881 /*
12882 ** There is unprocessed quantity. Convert it to the transaction uom
12883 ** so that the available quantity can be calculated in the trx uom
12884 */
12885 IF (g_asn_debug = 'Y') THEN
12886 asn_debug.put_line('Before uom_convert:');
12887 asn_debug.put_line('l_interface_quantity' || l_interface_quantity);
12888 asn_debug.put_line('l_primary_uom' || l_primary_uom);
12889 asn_debug.put_line('l_transaction_uom' || l_transaction_uom);
12890 asn_debug.put_line('l_item_id' || l_item_id);
12891 END IF;
12892
12893 po_uom_s.uom_convert(l_interface_quantity, l_primary_uom, l_item_id,
12894 l_transaction_uom, l_interface_qty_in_trx_uom);
12895
12896 END IF;
12897
12898 x_converted_parent_trx_qty := x_converted_parent_trx_qty - l_interface_qty_in_trx_uom;
12899
12900 IF (g_asn_debug = 'Y') THEN
12901 asn_debug.put_line('x_converted_parent_trx_qty:' || x_converted_parent_trx_qty);
12902 END IF;
12903
12904 END IF;
12905 /* Bug#5369121 - END */
12906 ELSE --}{
12907 IF (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH', 'UNORDERED')) THEN
12908 l_grand_parent_trx_id := x_po_correctrec.grand_parent_txn_id;
12909 ELSIF(x_po_correctrec.parent_transaction_type IN('MATCH', 'RECEIVE')) THEN
12910 IF (temp_cascaded_table(current_n).parent_transaction_id IS NOT NULL) THEN
12911 l_grand_parent_trx_id := x_po_correctrec.po_line_location_id;
12912 ELSIF(temp_cascaded_table(current_n).parent_interface_txn_id IS NOT NULL) THEN
12913 /* We would have the value derived in the x_cascaded_table
12914 * but not have inserted it back into rti.
12915 */
12916 l_grand_parent_trx_id := temp_cascaded_table(current_n).po_line_location_id;
12917 END IF;
12918 ELSIF(x_po_correctrec.parent_transaction_type = 'UNORDERED') THEN
12919 l_grand_parent_trx_id := x_po_correctrec.rcv_transaction_id;
12920 END IF;
12921
12922 IF (l_grand_parent_trx_id IS NOT NULL) THEN
12923 rcv_quantities_s.get_available_quantity('CORRECT',
12924 x_po_correctrec.rcv_transaction_id,
12925 'VENDOR',
12926 x_po_correctrec.parent_transaction_type,
12927 l_grand_parent_trx_id,
12928 'POSITIVE',
12929 x_converted_parent_trx_qty,
12930 x_tolerable_qty,
12931 x_po_correctrec.unit_of_meas,
12932 x_secondary_available_qty
12933 );
12934 END IF;
12935 END IF; --}
12936 END IF; --} -- interface_available_qty is 0.
12937
12938 IF (g_asn_debug = 'Y') THEN
12939 asn_debug.put_line('qty from GET_AVAILABLE_QUANTITY for correct is ' || x_converted_parent_trx_qty);
12940 asn_debug.put_line('tolerable qty from GET_AVAILABLE_QUANTITY for correct is ' || x_tolerable_qty);
12941 END IF;
12942
12943 IF (x_remaining_quantity = 0) THEN
12944 IF (g_asn_debug = 'Y') THEN
12945 asn_debug.put_line(' correct Need an error message in the interface tables');
12946 END IF;
12947 ELSE
12948 /* Converted successfully and have some quantity on which we can act */
12949 IF (g_asn_debug = 'Y') THEN
12950 asn_debug.put_line('Converted trx qty that is available ' || x_converted_parent_trx_qty);
12951 asn_debug.put_line('Remaining qty in parents uom that is available ' || x_remaining_quantity);
12952 END IF;
12953
12954 /* x_tolerable_quantity will be > 0 only for correction
12955 * against a receive transcation.
12956 */
12957 IF ( (SIGN(temp_cascaded_table(current_n).quantity) = 1)
12958 AND (x_tolerable_qty > 0)) THEN --{
12959 x_converted_parent_trx_qty := x_tolerable_qty;
12960
12961 IF (g_asn_debug = 'Y') THEN
12962 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_parent_trx_qty));
12963 END IF;
12964 END IF; --}
12965
12966 IF (g_asn_debug = 'Y') THEN
12967 asn_debug.put_line('x_converted_parent_trx_qty : ' || TO_CHAR(x_converted_parent_trx_qty));
12968 END IF;
12969
12970 IF (x_converted_parent_trx_qty > 0) THEN --{
12971 /* Compare with abs(x_remaining_qty) here since we want
12972 * to make sure that the qty we have is greater than
12973 * the available qty irrespective of whether this is
12974 * positive or negative correction.
12975 */
12976 IF (x_converted_parent_trx_qty < ABS(x_remaining_quantity)) THEN --{
12977 /* Total quantity available to correct is less than the qty
12978 * that the user wants to correct. Hence we would error out but
12979 * to keep the old code we will get the remaining code here and
12980 * error out later.
12981 */
12982 x_remaining_quantity := x_remaining_quantity - SIGN(temp_cascaded_table(current_n).quantity) * x_converted_parent_trx_qty;
12983 x_converted_parent_trx_qty := SIGN(temp_cascaded_table(current_n).quantity) * x_converted_parent_trx_qty;
12984
12985 IF (g_asn_debug = 'Y') THEN
12986 asn_debug.put_line('remaning qty after allocation is : ' || TO_CHAR(x_remaining_quantity));
12987 END IF;
12988
12989 insert_into_table := TRUE;
12990 ELSE --}{
12991 IF (g_asn_debug = 'Y') THEN
12992 asn_debug.put_line('We are in >= Qty branch ');
12993 END IF;
12994
12995 x_converted_parent_trx_qty := x_remaining_quantity;
12996 insert_into_table := TRUE;
12997 x_remaining_quantity := 0;
12998 END IF; --} /* if (x_converted_parent_trx_qty < x_remaining_quantity) then */
12999 ELSE /* x_converted_parent_trx_qty >0 */ --}{
13000
13001 -- so that the row can be used based on qty tolerance
13002 -- checks
13003 IF (g_asn_debug = 'Y') THEN
13004 asn_debug.put_line('Quantity is less then 0 but last record');
13005 END IF;
13006
13007 insert_into_table := TRUE;
13008 x_converted_parent_trx_qty := 0;
13009 END IF; /*x_converted_parent_trx_qty >0 */ --}
13010 END IF; --} just added this
13011
13012 /* Converted qty successfully and we have some quantity on which we can act */
13013 IF (g_asn_debug = 'Y') THEN
13014 asn_debug.put_line('Transaction qty in terms of the parents uom is ' || x_converted_parent_trx_qty);
13015 END IF;
13016
13017 IF insert_into_table THEN --{
13018 IF (x_first_trans) THEN --{
13019 IF (g_asn_debug = 'Y') THEN
13020 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
13021 END IF;
13022
13023 x_first_trans := FALSE;
13024 ELSE --}{
13025 IF (g_asn_debug = 'Y') THEN
13026 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
13027 END IF;
13028
13029 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
13030 END IF; --}
13031
13032 temp_cascaded_table(current_n).po_header_id := x_po_correctrec.po_head_id;
13033 temp_cascaded_table(current_n).po_line_id := x_po_correctrec.line_id;
13034 temp_cascaded_table(current_n).po_line_location_id := x_po_correctrec.po_line_location_id;
13035 temp_cascaded_table(current_n).po_distribution_id := x_po_correctrec.po_distribution_id;
13036 temp_cascaded_table(current_n).primary_unit_of_measure := x_po_correctrec.primary_unit_of_measure;
13037 temp_cascaded_table(current_n).quantity := x_converted_parent_trx_qty;
13038
13039 IF (temp_cascaded_table(current_n).primary_unit_of_measure <> x_po_correctrec.unit_of_meas) THEN
13040 temp_cascaded_table(current_n).primary_quantity := convert_into_correct_qty(x_converted_parent_trx_qty,
13041 x_po_correctrec.unit_of_meas,
13042 temp_cascaded_table(current_n).item_id,
13043 temp_cascaded_table(current_n).primary_unit_of_measure
13044 );
13045 ELSE
13046 temp_cascaded_table(current_n).primary_quantity := x_converted_parent_trx_qty;
13047 END IF;
13048
13049 IF (g_asn_debug = 'Y') THEN
13050 asn_debug.put_line('Transaction qty in terms of the primary uom is ' || temp_cascaded_table(current_n).primary_quantity);
13051 END IF;
13052
13053 current_n := current_n + 1;
13054
13055 IF (g_asn_debug = 'Y') THEN
13056 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
13057 END IF;
13058 END IF; --}
13059 /* Get the available qty in PRIMARY UOM */
13060 /*
13061 PO_UOM_S.UOM_CONVERT (x_converted_trx_qty,
13062 l_uom,
13063 x_item_id,
13064 x_primary_uom,
13065 l_primary_available_qty );
13066 */
13067 END LOOP; --}
13068 ELSE --} {
13069 -- error_status and error_message are set after validate_quantity_shipped
13070 IF (g_asn_debug = 'Y') THEN
13071 asn_debug.put_line('No po_header_id/item_id ');
13072 END IF;
13073
13074 IF (g_asn_debug = 'Y') THEN
13075 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
13076 END IF;
13077
13078 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
13079 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13080
13081 IF (x_cascaded_table(n).error_message IS NULL) THEN
13082 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION', x_cascaded_table(n).error_message);
13083 END IF;
13084
13085 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID');
13086 END IF; --}
13087
13088 RETURN;
13089 END IF; -- } of (asn quantity_shipped was valid)
13090
13091 IF (g_asn_debug = 'Y') THEN
13092 asn_debug.put_line('before closing cursors current_n is ' || temp_cascaded_table.COUNT);
13093 END IF;
13094
13095 IF po_correct%ISOPEN THEN
13096 CLOSE po_correct;
13097 END IF;
13098
13099 IF po_correct_rti%ISOPEN THEN
13100 CLOSE po_correct_rti;
13101 END IF;
13102
13103 IF (g_asn_debug = 'Y') THEN
13104 asn_debug.put_line('Exit explode_line_quantity');
13105 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
13106 END IF;
13107 EXCEPTION
13108 WHEN OTHERS THEN
13109 IF (g_asn_debug = 'Y') THEN
13110 asn_debug.put_line('Exception in derive_correction_line_quantity ');
13111 END IF;
13112
13113 IF po_correct%ISOPEN THEN
13114 CLOSE po_correct;
13115 END IF;
13116
13117 IF po_correct_rti%ISOPEN THEN
13118 CLOSE po_correct_rti;
13119 END IF;
13120
13121 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
13122 rcv_error_pkg.set_sql_error_message('derive_correction_line_qty', x_progress);
13123 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
13124 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
13125
13126 IF (g_asn_debug = 'Y') THEN
13127 asn_debug.put_line(TO_CHAR(n));
13128 asn_debug.put_line(SQLERRM);
13129 asn_debug.put_line('error ' || x_progress);
13130 END IF;
13131 END derive_correction_line_qty;
13132
13133 PROCEDURE derive_correction_line_amt(
13134 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
13135 n IN OUT NOCOPY BINARY_INTEGER,
13136 temp_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type
13137 ) IS
13138 x_include_closed_po VARCHAR2(1); -- Bug 1887728
13139 /*
13140 ** Might be a compatibility issue between the two record definitions
13141 */
13142 x_record_count NUMBER;
13143 x_remaining_amount NUMBER := 0;
13144 x_progress VARCHAR2(3);
13145 x_to_organization_code VARCHAR2(5);
13146 x_converted_trx_amt NUMBER := 0;
13147 transaction_ok BOOLEAN := FALSE;
13148 x_expected_date rcv_transactions_interface.expected_receipt_date%TYPE;
13149 high_range_date DATE;
13150 low_range_date DATE;
13151 rows_fetched NUMBER := 0;
13152 x_tolerable_amt NUMBER := 0;
13153 x_first_trans BOOLEAN := TRUE;
13154 x_sysdate DATE := SYSDATE;
13155 current_n BINARY_INTEGER := 0;
13156 insert_into_table BOOLEAN := FALSE;
13157 x_qty_rcv_exception_code po_line_locations.qty_rcv_exception_code%TYPE;
13158 tax_amount_factor NUMBER;
13159 lastrecord BOOLEAN := FALSE;
13160 already_allocated_amt NUMBER := 0;
13161 x_item_id NUMBER;
13162 x_approved_flag VARCHAR(1);
13163 x_cancel_flag VARCHAR(1);
13164 x_closed_code VARCHAR(25);
13165 x_shipment_type VARCHAR(25);
13166 x_temp_count NUMBER;
13167 x_full_name VARCHAR2(240) := NULL; -- Bug 2392074
13168 profile_user_id NUMBER := -1;
13169 profile_appl_id NUMBER := -1;
13170 profile_resp_id NUMBER := -1;
13171 defined BOOLEAN;
13172 x_sob_id NUMBER := NULL;
13173 x_rate NUMBER;
13174 x_allow_rate_override VARCHAR2(1);
13175
13176 /********************************************************************/
13177 CURSOR po_correct(
13178 v_parent_trx_id NUMBER,
13179 v_to_organization_id NUMBER
13180 ) IS
13181 SELECT rt.po_line_location_id,
13182 rt.po_header_id,
13183 rt.po_line_id,
13184 rt.transaction_id rcv_transaction_id,
13185 rt.parent_transaction_id grand_parent_txn_id,
13186 poh.segment1 document_num,
13187 pol.line_num line_number,
13188 rt.transaction_date transaction_date,
13189 rt.transaction_type parent_transaction_type,
13190 rt.amount,
13191 rt.organization_id,
13192 rt.location_id,
13193 rsl.job_id,
13194 rt.deliver_to_person_id,
13195 rt.deliver_to_location_id,
13196 rt.po_distribution_id,
13197 rt.destination_type_code,
13198 rsl.ussgl_transaction_code
13199 FROM rcv_transactions rt,
13200 rcv_shipment_lines rsl,
13201 po_headers poh,
13202 po_lines pol
13203 WHERE rt.transaction_id = v_parent_trx_id
13204 AND rt.organization_id = NVL(v_to_organization_id, rt.organization_id)
13205 AND ( rt.transaction_type IN('RECEIVE', 'TRANSFER', 'ACCEPT', 'REJECT', 'MATCH')
13206 OR ( rt.transaction_type IN('RETURN TO VENDOR', 'RETURN TO CUSTOMER')
13207 AND NOT EXISTS(SELECT 'rtv to processed matched unordered receipt'
13208 FROM rcv_transactions rt2,
13209 rcv_transactions rt3
13210 WHERE rt2.transaction_id = rt.parent_transaction_id
13211 AND rt2.transaction_type = 'UNORDERED'
13212 AND rt3.transaction_type = 'MATCH'
13213 AND rt3.parent_transaction_id = rt2.transaction_id)
13214 AND NOT EXISTS(SELECT 'rtv to unprocessed matched unordered receipt'
13215 FROM rcv_transactions rt2,
13216 rcv_transactions_interface rti
13217 WHERE rt2.transaction_id = rt.parent_transaction_id
13218 AND rt2.transaction_type = 'UNORDERED'
13219 AND rti.transaction_type = 'MATCH'
13220 AND rti.parent_transaction_id = rt2.transaction_id)
13221 )
13222 OR ( rt.transaction_type = 'DELIVER'
13223 AND NOT( rt.destination_type_code = 'INVENTORY'
13224 AND rt.source_document_code IN('REQ', 'INVENTORY', 'RMA')))
13225 OR ( rt.transaction_type = 'UNORDERED'
13226 AND NOT EXISTS(SELECT 'processed matched rows'
13227 FROM rcv_transactions rt2
13228 WHERE rt2.parent_transaction_id = rt.transaction_id
13229 AND rt2.transaction_type = 'MATCH')
13230 AND NOT EXISTS(SELECT 'unprocessed matched rows'
13231 FROM rcv_transactions_interface rti
13232 WHERE rti.parent_transaction_id = rt.transaction_id
13233 AND rti.transaction_type = 'MATCH')
13234 )
13235 )
13236 AND NOT EXISTS(SELECT 'purchase order shipment cancelled or fc'
13237 FROM po_line_locations pll
13238 WHERE pll.line_location_id = rt.po_line_location_id
13239 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
13240 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED'))
13241 AND (rt.shipment_line_id = rsl.shipment_line_id)
13242 AND (poh.po_header_id = rt.po_header_id)
13243 AND (pol.po_line_id = rt.po_line_id)
13244 ORDER BY rt.transaction_id;
13245
13246 CURSOR po_correct_rti(
13247 v_parent_interface_txn_id NUMBER
13248 ) IS
13249 SELECT rti.po_line_location_id,
13250 rti.po_header_id,
13251 rti.po_line_id,
13252 rti.interface_transaction_id rcv_transaction_id,
13253 rti.parent_transaction_id grand_parent_txn_id,
13254 rti.document_num,
13255 rti.document_line_num line_number,
13256 rti.transaction_date transaction_date,
13257 rti.transaction_type parent_transaction_type,
13258 rti.amount,
13259 rti.to_organization_id organization_id,
13260 rti.location_id,
13261 rti.job_id,
13262 rti.deliver_to_person_id,
13263 rti.deliver_to_location_id,
13264 rti.po_distribution_id,
13265 rti.destination_type_code,
13266 rti.ussgl_transaction_code
13267 FROM rcv_transactions_interface rti
13268 WHERE interface_transaction_id = v_parent_interface_txn_id;
13269
13270 x_po_correctrec po_correct%ROWTYPE;
13271 x_temp_parent_trx_amt NUMBER := 0;
13272 x_converted_parent_trx_amt NUMBER := 0;
13273 x_temp_convert_parent_trx_amt NUMBER := 0;
13274 l_to_organization_id NUMBER := 0;
13275 l_transaction_type rcv_transactions.transaction_type%TYPE;
13276 x_temp_already_allocated_qty NUMBER := 0;
13277 derive_values_from_table BOOLEAN := FALSE;
13278 derive_values_from_rti BOOLEAN := FALSE;
13279 already_derived BOOLEAN := FALSE;
13280 cascaded_table_index NUMBER;
13281 l_grand_parent_trx_id rcv_transactions.parent_transaction_id%TYPE;
13282 temp_index NUMBER;
13283 l_line_loc_id po_line_locations.line_location_id%TYPE;
13284 l_exist VARCHAR2(30);
13285 l_exist1 VARCHAR2(30);
13286 l_exist2 VARCHAR2(30);
13287 l_destination_type_code rcv_transactions.destination_type_code%TYPE;
13288 l_source_document_code rcv_transactions.source_document_code%TYPE;
13289 l_time_count NUMBER;
13290 BEGIN
13291 IF (g_asn_debug = 'Y') THEN
13292 asn_debug.put_line('enter derive_amount ' || x_cascaded_table(n).parent_transaction_id);
13293 END IF;
13294
13295 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
13296 already_derived := TRUE;
13297 END IF; --}
13298
13299 IF ( NOT already_derived
13300 AND (x_cascaded_table(n).parent_interface_txn_id IS NULL)
13301 AND (x_cascaded_table(n).parent_source_transaction_num IS NOT NULL)) THEN --{
13302 /* This means that there can be a row in RT with src_txn_id
13303 * populated or it can be a child.
13304 */
13305 BEGIN
13306 SELECT transaction_id
13307 INTO x_cascaded_table(n).parent_transaction_id
13308 FROM rcv_transactions
13309 WHERE source_transaction_num = x_cascaded_table(n).parent_source_transaction_num;
13310
13311 already_derived := TRUE;
13312 EXCEPTION
13313 WHEN NO_DATA_FOUND THEN
13314 -- this is fine since this could be a child.
13315 NULL;
13316 END;
13317 END IF; --}
13318
13319 IF already_derived THEN --{
13320 IF (g_asn_debug = 'Y') THEN
13321 asn_debug.put_line(' open po_correct table ' || x_cascaded_table(n).parent_transaction_id);
13322 END IF;
13323
13324 OPEN po_correct(x_cascaded_table(n).parent_transaction_id, x_cascaded_table(n).to_organization_id);
13325 END IF; ---}
13326
13327 IF (NOT already_derived) THEN --{
13328 derive_parent_id(x_cascaded_table, n);
13329
13330 /* This means that there was no error in
13331 * derive_parent_id which means that the
13332 * this is a child and need to get the values
13333 * from the rti and not from the plsql table.
13334 */
13335 IF ( (x_cascaded_table(n).error_status <> 'E')
13336 AND ( x_cascaded_table(n).derive = 'Y'
13337 AND x_cascaded_table(n).derive_index = 0)) THEN
13338 /* if derive_values_from_table is true, then we
13339 * derive the values from the pl/sql tables later
13340 * at the time when we try to see which cursor is open.
13341 * We will have x_cascaded_table(n).
13342 * parent_interface_txn_id) populated with teh
13343 * correct value.
13344 */
13345 IF (g_asn_debug = 'Y') THEN
13346 asn_debug.put_line(' open correct cursor from rti');
13347 END IF;
13348
13349 OPEN po_correct_rti(x_cascaded_table(n).parent_interface_txn_id);
13350 END IF;
13351 END IF; --}
13352
13353 /******************************************************************/
13354 --check line amount > 0
13355 x_progress := '097';
13356
13357 IF (g_asn_debug = 'Y') THEN
13358 asn_debug.put_line('X_progress ' || x_progress);
13359 END IF;
13360 /* Bug 6610047.
13361 * To allow corrections to timecards with zero amounts.
13362 * Commented the validation which checks for zero amount on the correction.
13363
13364 /* IF x_cascaded_table(n).error_status IN('S', 'W')
13365 AND x_cascaded_table(n).amount = 0 THEN --{
13366 IF (g_asn_debug = 'Y') THEN
13367 asn_debug.put_line('Amount is <= zero. Cascade will fail');
13368 END IF;
13369
13370 x_cascaded_table(n).error_status := 'F';
13371 rcv_error_pkg.set_error_message('RCV_ENTER_QTY_GT_ZERO', x_cascaded_table(n).error_message);
13372 rcv_error_pkg.log_interface_error('QUANTITY', FALSE);
13373 END IF; --} end qty > 0 check
13374 */
13375 -- the following steps will create a set of rows linking the line_record with
13376 -- its corresponding po_line_location rows until the quantity value from
13377 -- the asn is consumed. (Cascade)
13378
13379 /* 2119137 : If the user populates rcv_transactions_interface
13380 with po_line_id, then ROI errors out with
13381 RCV_ASN_NO_PO_LINE_LOCATION_ID when the docment_line_num
13382 is not provided for one time items. Modified the "if" criteria in
13383 such a way that the ROI validation does'nt error out when
13384 po_line_id is populated for one time items. */
13385 x_progress := '098';
13386
13387 IF (g_asn_debug = 'Y') THEN
13388 asn_debug.put_line('X_progress ' || x_progress);
13389 END IF;
13390
13391 IF ( ( x_cascaded_table(n).parent_transaction_id IS NOT NULL
13392 OR x_cascaded_table(n).parent_interface_txn_id IS NOT NULL)
13393 AND x_cascaded_table(n).error_status IN('S', 'W')) THEN --{
13394
13395 -- Copy record from main table to temp table
13396 IF (g_asn_debug = 'Y') THEN
13397 asn_debug.put_line('Copy record from main table to temp table');
13398 END IF;
13399
13400 current_n := 1;
13401 temp_cascaded_table(current_n) := x_cascaded_table(n);
13402
13403 -- Get all rows which meet this condition
13404 IF (g_asn_debug = 'Y') THEN
13405 asn_debug.put_line('Get all rows which meet this condition');
13406 asn_debug.put_line('Transaction Type = ' || x_cascaded_table(n).transaction_type);
13407 asn_debug.put_line('Auto Transact Code = ' || x_cascaded_table(n).auto_transact_code);
13408 END IF;
13409
13410 -- Assign shipped amount to remaining amount
13411 IF (g_asn_debug = 'Y') THEN
13412 asn_debug.put_line('Assign populated amount to remaining amount');
13413 asn_debug.put_line('Pointer in temp_cascade ' || TO_CHAR(current_n));
13414 END IF;
13415
13416 x_remaining_amount := temp_cascaded_table(current_n).amount;
13417
13418 IF (g_asn_debug = 'Y') THEN
13419 asn_debug.put_line('Have assigned the amount');
13420 END IF;
13421
13422 -- Calculate tax_amount_factor for calculating tax_amount for
13423 -- each cascaded line
13424
13425 IF NVL(temp_cascaded_table(current_n).tax_amount, 0) <> 0 THEN
13426 tax_amount_factor := temp_cascaded_table(current_n).tax_amount / x_remaining_amount;
13427 ELSE
13428 tax_amount_factor := 0;
13429 END IF;
13430
13431 IF (g_asn_debug = 'Y') THEN
13432 asn_debug.put_line('Tax Factor ' || TO_CHAR(tax_amount_factor));
13433 asn_debug.put_line('transaction amount : ' || TO_CHAR(x_remaining_amount));
13434 END IF;
13435
13436 x_first_trans := TRUE;
13437 transaction_ok := FALSE;
13438
13439 IF (g_asn_debug = 'Y') THEN
13440 asn_debug.put_line('Before starting Cascade');
13441 END IF;
13442
13443 IF (g_asn_debug = 'Y') THEN
13444 asn_debug.put_line('Record Count = ' || x_record_count);
13445 END IF;
13446
13447 LOOP --{
13448 IF (g_asn_debug = 'Y') THEN
13449 asn_debug.put_line('Remaining Quantity ' || TO_CHAR(x_remaining_amount));
13450 END IF;
13451
13452 /*
13453 ** Fetch the appropriate record
13454 */
13455 IF (g_asn_debug = 'Y') THEN
13456 asn_debug.put_line('DEBUG: transaction_type = ' || x_cascaded_table(n).transaction_type);
13457 END IF;
13458
13459 IF (po_correct%ISOPEN) THEN --{
13460 IF (g_asn_debug = 'Y') THEN
13461 asn_debug.put_line(' fetch po_correct');
13462 END IF;
13463
13464 FETCH po_correct INTO x_po_correctrec;
13465
13466 IF (po_correct%NOTFOUND) THEN
13467 lastrecord := TRUE;
13468 END IF;
13469
13470 rows_fetched := po_correct%ROWCOUNT;
13471 ELSIF(po_correct_rti%ISOPEN) THEN --}{
13472 IF (g_asn_debug = 'Y') THEN
13473 asn_debug.put_line(' fetch po_correct_rti');
13474 END IF;
13475
13476 FETCH po_correct_rti INTO x_po_correctrec;
13477
13478 IF (po_correct_rti%NOTFOUND) THEN
13479 IF (g_asn_debug = 'Y') THEN
13480 asn_debug.put_line('correct last row');
13481 END IF;
13482
13483 lastrecord := TRUE;
13484 END IF;
13485
13486 rows_fetched := po_correct_rti%ROWCOUNT;
13487 ELSIF(temp_cascaded_table(current_n).derive = 'Y') THEN --}{
13488 /* GET VALUES FROM THE PLSQL TABLE */
13489 /* Populate x_po_correctrec with these values since
13490 * we are using x_po_correctrec later.
13491 * We have temp_cascaded_table(current_n).
13492 * parent_interface_txn_id) populated with
13493 * with the correct value. Also we have cascaded_table_index
13494 * with the correct pl/sql table index number;
13495 */
13496 IF (g_asn_debug = 'Y') THEN
13497 asn_debug.put_line(' fetch pl/sql table');
13498 END IF;
13499
13500 temp_index := temp_cascaded_table(current_n).derive_index;
13501 x_po_correctrec.po_line_location_id := x_cascaded_table(temp_index).po_line_location_id;
13502 x_po_correctrec.po_header_id := x_cascaded_table(temp_index).po_header_id;
13503 x_po_correctrec.po_line_id := x_cascaded_table(temp_index).po_line_id;
13504 x_po_correctrec.grand_parent_txn_id := x_cascaded_table(temp_index).parent_transaction_id;
13505 x_po_correctrec.document_num := x_cascaded_table(temp_index).document_num;
13506 x_po_correctrec.line_number := x_cascaded_table(temp_index).document_line_num;
13507 x_po_correctrec.transaction_date := x_cascaded_table(temp_index).transaction_date;
13508 x_po_correctrec.parent_transaction_type := x_cascaded_table(temp_index).transaction_type;
13509 x_po_correctrec.amount := x_cascaded_table(temp_index).amount;
13510 x_po_correctrec.organization_id := x_cascaded_table(temp_index).to_organization_id;
13511 x_po_correctrec.location_id := x_cascaded_table(temp_index).location_id;
13512 x_po_correctrec.job_id := x_cascaded_table(temp_index).job_id;
13513 x_po_correctrec.deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
13514 x_po_correctrec.deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
13515 x_po_correctrec.po_distribution_id := x_cascaded_table(temp_index).po_distribution_id;
13516 x_po_correctrec.destination_type_code := x_cascaded_table(temp_index).destination_type_code;
13517 x_po_correctrec.ussgl_transaction_code := x_cascaded_table(temp_index).ussgl_transaction_code;
13518 /* Also fetch parent transaction type and grand parent trx id into
13519 * the correct variables.
13520 */
13521 rows_fetched := 1;
13522 lastrecord := TRUE;
13523 END IF; --}
13524
13525 IF (g_asn_debug = 'Y') THEN
13526 asn_debug.put_line('Correct Rows fetched ' || TO_CHAR(rows_fetched));
13527 asn_debug.put_line('po_line_id ' || TO_CHAR(x_po_correctrec.po_line_id));
13528 asn_debug.put_line('po_dist ' || TO_CHAR(x_po_correctrec.po_distribution_id));
13529 asn_debug.put_line('correct remainaing amount ' || x_remaining_amount);
13530 END IF;
13531
13532 /* Support for RATE based from OTL */
13533 IF ( x_cascaded_table(n).value_basis = 'RATE'
13534 AND x_cascaded_table(n).purchase_basis = 'TEMP LABOR') THEN --{
13535 IF (g_asn_debug = 'Y') THEN
13536 asn_debug.put_line('Rate/Temp Labor');
13537 END IF;
13538
13539 /* Bug 3648861.
13540 * The where condition has
13541 * and pol.po_line_id=po_line_id.
13542 * It should be
13543 * and pol.po_line_id=x_cascaded_table(n).po_line_id
13544 * Changed the condition.
13545 */
13546 SELECT COUNT(*)
13547 INTO l_time_count
13548 FROM hxc_time_building_blocks bb,
13549 po_lines pol
13550 WHERE bb.time_building_block_id = x_cascaded_table(n).timecard_id
13551 AND bb.object_version_number = x_cascaded_table(n).timecard_ovn
13552 AND bb.SCOPE = 'TIMECARD'
13553 AND bb.resource_type = 'PERSON'
13554 AND bb.resource_id IN(SELECT person_id
13555 FROM per_all_assignments_f
13556 WHERE assignment_type = 'C')
13557 AND pol.po_line_id = x_cascaded_table(n).po_line_id
13558 AND pol.order_type_lookup_code = 'RATE'
13559 AND pol.purchase_basis = 'TEMP LABOR';
13560
13561 IF (g_asn_debug = 'Y') THEN
13562 asn_debug.put_line('count ' || l_time_count);
13563 END IF;
13564
13565 IF (l_time_count = 0) THEN --{
13566 IF (g_asn_debug = 'Y') THEN
13567 asn_debug.put_line('We do not support RATE/TEMP LABOR through ROI unless it comes through OTL');
13568 END IF;
13569
13570 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13571 rcv_error_pkg.set_error_message('RCV_NO_RATE_UNLESS_OTL', x_cascaded_table(n).error_message);
13572 rcv_error_pkg.log_interface_error('TRANSACTION_TYPE', FALSE);
13573 END IF; --}
13574 END IF; --}
13575
13576 IF (lastrecord) THEN --{
13577 IF (g_asn_debug = 'Y') THEN
13578 asn_debug.put_line('Hit exit condition');
13579 END IF;
13580
13581 IF NOT x_first_trans THEN
13582 -- x_first_trans has been reset which means some cascade has
13583 -- happened. Otherwise current_n = 1
13584 IF (g_asn_debug = 'Y') THEN
13585 asn_debug.put_line('current_n before is ' || current_n);
13586 END IF;
13587
13588 current_n := current_n - 1;
13589 END IF;
13590
13591 -- do the tolerance act here
13592 IF (g_asn_debug = 'Y') THEN
13593 asn_debug.put_line('Temp table pointer ' || TO_CHAR(current_n));
13594 asn_debug.put_line('Check which condition has occured');
13595 END IF;
13596
13597 -- lastrecord...we have run out of rows and we still have quantity to allocate
13598 /* Do abs(x_remaining_quantity) since it can be a negative
13599 * or positive correction.
13600 */
13601 IF ABS(x_remaining_amount) > 0 THEN --{
13602 IF (g_asn_debug = 'Y') THEN
13603 asn_debug.put_line('There is amount remaining ');
13604 asn_debug.put_line('tolerable amount now in plsql table ' || temp_cascaded_table(current_n).amount);
13605 asn_debug.put_line('rows_fetched ' || rows_fetched);
13606 END IF;
13607
13608 IF NOT x_first_trans THEN
13609 IF (g_asn_debug = 'Y') THEN
13610 asn_debug.put_line('not fisrt txn');
13611 END IF;
13612 END IF;
13613
13614 IF rows_fetched > 0
13615 AND NOT x_first_trans THEN --{
13616 IF (g_asn_debug = 'Y') THEN
13617 asn_debug.put_line(' inside transaction_type ' || x_po_correctrec.parent_transaction_type);
13618 END IF;
13619
13620 IF (SIGN(x_cascaded_table(current_n).amount) = 1) THEN --{
13621 IF (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH')) THEN --{
13622 IF (g_asn_debug = 'Y') THEN
13623 asn_debug.put_line('Need to check amount tolerances');
13624 END IF;
13625
13626 SELECT NVL(po_line_locations.qty_rcv_exception_code, 'NONE')
13627 INTO x_qty_rcv_exception_code
13628 FROM po_line_locations
13629 WHERE line_location_id = temp_cascaded_table(current_n).po_line_location_id;
13630
13631 IF (g_asn_debug = 'Y') THEN
13632 asn_debug.put_line('Qty tolerance exception code ' || NVL(x_qty_rcv_exception_code, 'NONE1'));
13633 END IF;
13634
13635 IF x_qty_rcv_exception_code IN('NONE', 'WARNING') THEN --{
13636 /* Bug# 1807842 */
13637 IF (temp_cascaded_table(current_n).amount <= x_converted_trx_amt) THEN --{
13638 IF (g_asn_debug = 'Y') THEN
13639 asn_debug.put_line('Tolerable quantity ' || TO_CHAR(x_converted_trx_amt));
13640 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).amount));
13641 asn_debug.put_line('Assign remaining amount ' || TO_CHAR(x_remaining_amount) || ' to last record');
13642 END IF;
13643
13644 temp_cascaded_table(current_n).amount := temp_cascaded_table(current_n).amount + x_remaining_amount;
13645 END IF; /* Bug# 1807842 */ --}
13646
13647 temp_cascaded_table(current_n).tax_amount := ROUND(temp_cascaded_table(current_n).amount * tax_amount_factor, 6);
13648
13649 IF (g_asn_debug = 'Y') THEN
13650 asn_debug.put_line('Current amount ' || TO_CHAR(temp_cascaded_table(current_n).amount));
13651 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
13652 END IF;
13653
13654 IF x_qty_rcv_exception_code = 'WARNING' THEN --{
13655 IF (g_asn_debug = 'Y') THEN
13656 asn_debug.put_line('IN WARNING');
13657 END IF;
13658
13659 temp_cascaded_table(current_n).error_status := 'W';
13660 temp_cascaded_table(current_n).error_message := 'RCV_ALL_AMT_OVER_TOLERANCE';
13661
13662 IF (g_asn_debug = 'Y') THEN
13663 asn_debug.put_line('Group Id ' || TO_CHAR(temp_cascaded_table(current_n).GROUP_ID));
13664 asn_debug.put_line('Header Interface Id ' || TO_CHAR(temp_cascaded_table(current_n).header_interface_id));
13665 asn_debug.put_line('IN Trans Id ' || TO_CHAR(temp_cascaded_table(current_n).interface_transaction_id));
13666 END IF;
13667
13668 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_warning;
13669 rcv_error_pkg.set_error_message('RCV_ALL_AMT_OVER_TOLERANCE', x_cascaded_table(n).error_message);
13670 rcv_error_pkg.set_token('AMT_A', temp_cascaded_table(current_n).amount);
13671 rcv_error_pkg.set_token('AMT_B', temp_cascaded_table(current_n).amount - x_remaining_amount);
13672 rcv_error_pkg.log_interface_warning('AMOUNT');
13673
13674 IF (g_asn_debug = 'Y') THEN
13675 asn_debug.put_line('Error Status ' || temp_cascaded_table(current_n).error_status);
13676 asn_debug.put_line('Error message ' || temp_cascaded_table(current_n).error_message);
13677 asn_debug.put_line('Need to insert into po_interface_errors');
13678 END IF;
13679 END IF; --} matches x_qty_rcv_exception_code = 'WARNING'
13680
13681 IF (g_asn_debug = 'Y') THEN
13682 asn_debug.put_line('Current quantity ' || TO_CHAR(temp_cascaded_table(current_n).amount));
13683 asn_debug.put_line('Current Tax Amount ' || TO_CHAR(temp_cascaded_table(current_n).tax_amount));
13684 END IF;
13685 END IF; --}
13686 END IF; --}
13687
13688 IF ( ( (x_po_correctrec.parent_transaction_type IN('RECEIVE', 'MATCH'))
13689 AND x_qty_rcv_exception_code = 'REJECT')
13690 OR (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH'))) THEN --{
13691 IF (g_asn_debug = 'Y') THEN
13692 asn_debug.put_line('Extra amount ' || TO_CHAR(x_remaining_amount));
13693 END IF;
13694
13695 IF (g_asn_debug = 'Y') THEN
13696 asn_debug.put_line('delete the temp table ');
13697 END IF;
13698
13699 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13700 rcv_error_pkg.set_error_message('RCV_CORRECT_AMT_OVER_TOLERANCE', x_cascaded_table(n).error_message);
13701 rcv_error_pkg.set_token('AMT_A', temp_cascaded_table(current_n).amount);
13702 rcv_error_pkg.set_token('AMT_B', temp_cascaded_table(current_n).amount - x_remaining_amount);
13703 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
13704 temp_cascaded_table.DELETE;
13705
13706 IF (g_asn_debug = 'Y') THEN
13707 asn_debug.put_line('mark the actual table with error status');
13708 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
13709 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
13710 END IF;
13711
13712 IF (g_asn_debug = 'Y') THEN
13713 asn_debug.put_line('Need to insert a row into po_interface_errors');
13714 END IF;
13715 END IF; --} matches if(none/warning) and elseif(reject)
13716 END IF; --}
13717
13718 IF (SIGN(x_cascaded_table(current_n).amount) = -1) THEN --{
13719 /* for correct,accept an reject type we dont have the
13720 * tolerance check. Hence error out.
13721 * We cannot correct quantities more than that was received.
13722 */
13723 IF (g_asn_debug = 'Y') THEN
13724 asn_debug.put_line(' in correct extra amount ' || TO_CHAR(x_remaining_amount));
13725 asn_debug.put_line('delete the temp table ');
13726 END IF;
13727
13728 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13729 rcv_error_pkg.set_error_message('RCV_CORRECT_AMT_OVER_TOLERANCE', x_cascaded_table(n).error_message);
13730 rcv_error_pkg.set_token('AMT_A', temp_cascaded_table(current_n).amount);
13731 rcv_error_pkg.set_token('AMT_B', temp_cascaded_table(current_n).amount - x_remaining_amount);
13732 rcv_error_pkg.log_interface_error('AMOUNT', FALSE);
13733 temp_cascaded_table.DELETE;
13734
13735 IF (g_asn_debug = 'Y') THEN
13736 asn_debug.put_line('mark the actual table with error status');
13737 asn_debug.put_line('Error Status ' || x_cascaded_table(n).error_status);
13738 asn_debug.put_line('Error message ' || x_cascaded_table(n).error_message);
13739 asn_debug.put_line('Need to insert a row into po_interface_errors for correct');
13740 END IF;
13741 END IF; --}
13742 ELSE --}{ else for rows fetched = 0 OR x_first_trans = true
13743 IF rows_fetched = 0 THEN
13744 IF (g_asn_debug = 'Y') THEN
13745 asn_debug.put_line('No rows were retrieved from cursor.');
13746 END IF;
13747 ELSIF x_first_trans THEN
13748 IF (g_asn_debug = 'Y') THEN
13749 asn_debug.put_line('No rows were cascaded');
13750 END IF;
13751 END IF;
13752
13753 x_temp_count := 1;
13754 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13755
13756 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN --{
13757 /* Give an error just like it is done for the
13758 * the receipt transaction;
13759 */
13760 SELECT parent_transaction_id,
13761 transaction_type,
13762 po_line_location_id,
13763 destination_type_code,
13764 source_document_code
13765 INTO l_grand_parent_trx_id,
13766 l_transaction_type,
13767 l_line_loc_id,
13768 l_destination_type_code,
13769 l_source_document_code
13770 FROM rcv_transactions rt
13771 WHERE rt.transaction_id = temp_cascaded_table(current_n).parent_transaction_id;
13772
13773 IF (l_transaction_type = 'DELIVER') THEN --{
13774 IF ( l_destination_type_code = 'INVENTORY'
13775 OR l_source_document_code IN('REQ', 'INVENTORY', 'RMA')) THEN
13776 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13777 rcv_error_pkg.set_error_message('RCV_INVAL_SOURCE_DOC_FOR_DEL', x_cascaded_table(n).error_message);
13778 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13779 END IF;
13780 END IF; --}
13781
13782 IF (l_transaction_type = 'UNORDERED') THEN --{
13783 SELECT MAX('record_exist')
13784 INTO l_exist
13785 FROM rcv_transactions rt2
13786 WHERE rt2.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
13787 AND rt2.transaction_type = 'MATCH';
13788
13789 SELECT MAX('record_exist')
13790 INTO l_exist1
13791 FROM rcv_transactions_interface rti
13792 WHERE rti.parent_transaction_id = temp_cascaded_table(current_n).parent_transaction_id
13793 AND rti.transaction_type = 'MATCH';
13794
13795 IF l_exist = 'record_exist' THEN --{
13796 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13797 rcv_error_pkg.set_error_message('RCV_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
13798 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13799 END IF; --}
13800
13801 IF l_exist1 = 'record_exist' THEN --{
13802 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13803 rcv_error_pkg.set_error_message('RCV_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
13804 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13805 END IF; --}
13806 END IF; --}
13807
13808 IF (l_transaction_type = 'RETURN TO VENDOR') THEN --{
13809 SELECT MAX('record_exist')
13810 INTO l_exist
13811 FROM rcv_transactions rt2,
13812 rcv_transactions rt3
13813 WHERE rt2.transaction_id = l_grand_parent_trx_id
13814 AND rt2.transaction_type = 'UNORDERED'
13815 AND rt3.transaction_type = 'MATCH'
13816 AND rt3.parent_transaction_id = rt2.transaction_id;
13817
13818 SELECT MAX('record_exist')
13819 INTO l_exist1
13820 FROM rcv_transactions rt2,
13821 rcv_transactions_interface rti
13822 WHERE rt2.transaction_id = l_grand_parent_trx_id
13823 AND rt2.transaction_type = 'UNORDERED'
13824 AND rti.transaction_type = 'MATCH'
13825 AND rti.parent_transaction_id = rt2.transaction_id;
13826
13827 IF l_exist = 'record_exist' THEN --{
13828 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13829 rcv_error_pkg.set_error_message('RCV_RET_PROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
13830 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13831 END IF; --}
13832
13833 IF l_exist1 = 'record_exist' THEN --{
13834 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13835 rcv_error_pkg.set_error_message('RCV_RET_UNPROC_MATCH_UNORDER', x_cascaded_table(n).error_message);
13836 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13837 END IF; --}
13838 END IF; --}
13839
13840 SELECT MAX('record_exist')
13841 INTO l_exist2
13842 FROM po_line_locations pll
13843 WHERE pll.line_location_id = l_line_loc_id
13844 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
13845 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED');
13846
13847 IF l_exist2 = 'record_exist' THEN
13848 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
13849 rcv_error_pkg.set_error_message('RCV_PO_SHIPMENT_CANCELLED', x_cascaded_table(n).error_message);
13850 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID', FALSE);
13851 END IF;
13852 END IF; --}
13853
13854 -- Delete the temp_cascaded_table just to be sure
13855
13856 temp_cascaded_table.DELETE;
13857 END IF; --}
13858 ELSE -- }{
13859 IF (g_asn_debug = 'Y') THEN
13860 asn_debug.put_line('Remaining amount is zero ' || TO_CHAR(x_remaining_amount));
13861 asn_debug.put_line('Return the cascaded rows back to the calling procedure');
13862 END IF;
13863 END IF; --} ends the check for whether last record has been reached
13864
13865 -- close cursors
13866
13867 IF (g_asn_debug = 'Y') THEN
13868 asn_debug.put_line('Close cursors shipments, count_shipments, distributions, count_disributions ' || current_n);
13869 END IF;
13870
13871 IF po_correct%ISOPEN THEN
13872 CLOSE po_correct;
13873 END IF;
13874
13875 IF po_correct_rti%ISOPEN THEN
13876 CLOSE po_correct_rti;
13877 END IF;
13878
13879 IF (g_asn_debug = 'Y') THEN
13880 asn_debug.put_line('before exit current_n is ' || current_n);
13881 END IF;
13882
13883 EXIT;
13884 END IF; --} matches lastrecord or x_remaining_quantity <= 0
13885
13886 IF (g_asn_debug = 'Y') THEN
13887 asn_debug.put_line(' Entering amount calculation for correct');
13888 END IF;
13889
13890 /* If destination_type_code is inventory then we need to make
13891 * sure that we can correct this qty since it might have been
13892 * already reserved in inventory.
13893 */
13894 IF (x_cascaded_table(n).destination_type_code = 'INVENTORY') THEN --{
13895 rcv_roi_return.derive_inv_qty(x_cascaded_table, n);
13896
13897 IF (x_cascaded_table(n).error_status = 'E') THEN
13898 /* Exit from loop */
13899 EXIT;
13900 END IF;
13901 END IF; --}
13902
13903 insert_into_table := FALSE;
13904 already_allocated_amt := 0;
13905
13906 IF (g_asn_debug = 'Y') THEN
13907 asn_debug.put_line('calling Correct get_available_amount ' || x_po_correctrec.parent_transaction_type);
13908 END IF;
13909
13910 get_interface_available_amt(temp_cascaded_table,
13911 current_n,
13912 x_converted_parent_trx_amt
13913 );
13914
13915 IF (g_asn_debug = 'Y') THEN
13916 asn_debug.put_line('correct interface_available_amt ' || x_converted_parent_trx_amt);
13917 END IF;
13918
13919 /* x_converted_parent_trx_qty will be 0 when this is not a child
13920 * transaction to any rti row. Also for correct, grand parent
13921 * may already be processed and for positive correction we
13922 * might need to get the quantity from the grand parent.
13923 */
13924 IF (x_converted_parent_trx_amt = 0) THEN --{
13925 IF (g_asn_debug = 'Y') THEN
13926 asn_debug.put_line('interface amount is 0');
13927 END IF;
13928
13929 IF (SIGN(temp_cascaded_table(current_n).amount) = -1) THEN --{
13930 asn_debug.put_line('Before call to get_available_amt for negative correction');
13931 rcv_quantities_s.get_available_amount('CORRECT',
13932 x_po_correctrec.rcv_transaction_id,
13933 'VENDOR',
13934 x_po_correctrec.parent_transaction_type,
13935 NULL,
13936 'NEGATIVE',
13937 x_converted_parent_trx_amt,
13938 x_tolerable_amt
13939 );
13940 ELSE --}{
13941 IF (x_po_correctrec.parent_transaction_type NOT IN('RECEIVE', 'MATCH', 'UNORDERED')) THEN
13942 l_grand_parent_trx_id := x_po_correctrec.grand_parent_txn_id;
13943 asn_debug.put_line('Parent_trx not in receive and gp is ' || l_grand_parent_trx_id);
13944 ELSIF(x_po_correctrec.parent_transaction_type IN('MATCH', 'RECEIVE')) THEN
13945 IF (temp_cascaded_table(current_n).parent_transaction_id IS NOT NULL) THEN
13946 l_grand_parent_trx_id := x_po_correctrec.po_line_location_id;
13947 asn_debug.put_line('Parent_trx in receive and parent_trx_id not null gp is ' || l_grand_parent_trx_id);
13948 ELSIF(temp_cascaded_table(current_n).parent_interface_txn_id IS NOT NULL) THEN
13949 /* We would have the value derived in the x_cascaded_table
13950 * but not have inserted it back into rti.
13951 */
13952 l_grand_parent_trx_id := temp_cascaded_table(current_n).po_line_location_id;
13953 asn_debug.put_line('Parent_trx in receive and parent_inter_trx_id not null gp is ' || l_grand_parent_trx_id);
13954 END IF;
13955 ELSIF(x_po_correctrec.parent_transaction_type = 'UNORDERED') THEN
13956 l_grand_parent_trx_id := x_po_correctrec.rcv_transaction_id;
13957 END IF;
13958
13959 IF (l_grand_parent_trx_id IS NOT NULL) THEN
13960 asn_debug.put_line('gp before get_avail_amt for +ve corr' || l_grand_parent_trx_id);
13961 rcv_quantities_s.get_available_amount('CORRECT',
13962 x_po_correctrec.rcv_transaction_id,
13963 'VENDOR',
13964 x_po_correctrec.parent_transaction_type,
13965 l_grand_parent_trx_id,
13966 'POSITIVE',
13967 x_converted_parent_trx_amt,
13968 x_tolerable_amt
13969 );
13970 END IF;
13971 END IF; --}
13972 END IF; --} -- interface_available_qty is 0.
13973
13974 IF (g_asn_debug = 'Y') THEN
13975 asn_debug.put_line('amount from GET_AVAILABLE_AMOUNT for correct is ' || x_converted_parent_trx_amt);
13976 END IF;
13977
13978 IF (x_remaining_amount = 0) THEN
13979 IF (g_asn_debug = 'Y') THEN
13980 asn_debug.put_line(' correct Need an error message in the interface tables');
13981 END IF;
13982 ELSE
13983 /* Converted successfully and have some quantity on which we can act */
13984 IF (g_asn_debug = 'Y') THEN
13985 asn_debug.put_line('Converted trx amt that is available ' || x_converted_parent_trx_amt);
13986 asn_debug.put_line('Remaining amt that is available ' || x_remaining_amount);
13987 END IF;
13988
13989 IF ( (rows_fetched = x_record_count)
13990 AND (SIGN(temp_cascaded_table(current_n).amount) = 1)) THEN --{
13991 x_converted_trx_amt := x_tolerable_amt;
13992
13993 IF (g_asn_debug = 'Y') THEN
13994 asn_debug.put_line('Last Row : ' || TO_CHAR(x_converted_trx_amt));
13995 END IF;
13996 END IF; --}
13997
13998 IF (x_converted_parent_trx_amt > 0) THEN --{
13999 /* Compare with abs(x_remaining_qty) here since we want
14000 * to make sure that the qty we have is greater than
14001 * the available qty irrespective of whether this is
14002 * positive or negative correction.
14003 */
14004 IF (x_converted_parent_trx_amt < ABS(x_remaining_amount)) THEN --{
14005 /* Total quantity available to correct is less than the qty
14006 * that the user wants to correct. Hence we would error out but
14007 * to keep the old code we will get the remaining code here and
14008 * error out later.
14009 */
14010 x_remaining_amount := x_remaining_amount - SIGN(temp_cascaded_table(current_n).amount) * x_converted_parent_trx_amt;
14011 x_converted_parent_trx_amt := SIGN(temp_cascaded_table(current_n).amount) * x_converted_parent_trx_amt;
14012
14013 IF (g_asn_debug = 'Y') THEN
14014 asn_debug.put_line('remaning amt after allocation is : ' || TO_CHAR(x_remaining_amount));
14015 END IF;
14016
14017 insert_into_table := TRUE;
14018 ELSE --}{
14019 IF (g_asn_debug = 'Y') THEN
14020 asn_debug.put_line('We are in >= amount branch ');
14021 END IF;
14022
14023 x_converted_parent_trx_amt := x_remaining_amount;
14024 insert_into_table := TRUE;
14025 x_remaining_amount := 0;
14026 END IF; --} /* if (x_converted_parent_trx_qty < x_remaining_quantity) then */
14027 ELSE /* x_converted_parent_trx_qty >0 */ --}{
14028
14029 -- so that the row can be used based on qty tolerance
14030 -- checks
14031 IF (g_asn_debug = 'Y') THEN
14032 asn_debug.put_line('amount is less then 0 but last record');
14033 END IF;
14034
14035 insert_into_table := TRUE;
14036 x_converted_trx_amt := 0;
14037 END IF; /*x_converted_parent_trx_qty >0 */ --}
14038 END IF; --} just added this
14039
14040 /* Converted amt successfully and we have some amount on which we can act */
14041 IF (g_asn_debug = 'Y') THEN
14042 asn_debug.put_line('Transaction amt is ' || x_converted_parent_trx_amt);
14043 END IF;
14044
14045 IF insert_into_table THEN --{
14046 IF (x_first_trans) THEN --{
14047 IF (g_asn_debug = 'Y') THEN
14048 asn_debug.put_line('First Time ' || TO_CHAR(current_n));
14049 END IF;
14050
14051 x_first_trans := FALSE;
14052 ELSE --}{
14053 IF (g_asn_debug = 'Y') THEN
14054 asn_debug.put_line('Next Time ' || TO_CHAR(current_n));
14055 END IF;
14056
14057 temp_cascaded_table(current_n) := temp_cascaded_table(current_n - 1);
14058 END IF; --}
14059
14060 temp_cascaded_table(current_n).po_header_id := x_po_correctrec.po_header_id;
14061 temp_cascaded_table(current_n).po_line_id := x_po_correctrec.po_line_id;
14062 temp_cascaded_table(current_n).po_line_location_id := x_po_correctrec.po_line_location_id;
14063 temp_cascaded_table(current_n).po_distribution_id := x_po_correctrec.po_distribution_id;
14064 temp_cascaded_table(current_n).amount := x_converted_parent_trx_amt;
14065
14066 IF (g_asn_debug = 'Y') THEN
14067 asn_debug.put_line('Transaction amt ' || temp_cascaded_table(current_n).amount);
14068 END IF;
14069
14070 current_n := current_n + 1;
14071
14072 IF (g_asn_debug = 'Y') THEN
14073 asn_debug.put_line('Increment pointer by 1 ' || TO_CHAR(current_n));
14074 END IF;
14075 END IF; --}
14076 END LOOP; --}
14077 ELSE --} {
14078 -- error_status and error_message are set after validate_quantity_shipped
14079 IF (g_asn_debug = 'Y') THEN
14080 asn_debug.put_line('No po_header_id/item_id ');
14081 END IF;
14082
14083 IF (g_asn_debug = 'Y') THEN
14084 asn_debug.put_line('Status = ' || x_cascaded_table(n).error_status);
14085 END IF;
14086
14087 IF x_cascaded_table(n).error_status IN('S', 'W', 'F') THEN --{
14088 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_error;
14089
14090 IF (x_cascaded_table(n).error_message IS NULL) THEN
14091 rcv_error_pkg.set_error_message('RCV_NO_PARENT_TRANSACTION', x_cascaded_table(n).error_message);
14092 END IF;
14093
14094 rcv_error_pkg.log_interface_error('PARENT_TRANSACTION_ID');
14095 END IF; --}
14096
14097 RETURN;
14098 END IF; -- } of (asn quantity_shipped was valid)
14099
14100 IF (g_asn_debug = 'Y') THEN
14101 asn_debug.put_line('before closing cursors current_n is ' || temp_cascaded_table.COUNT);
14102 END IF;
14103
14104 IF po_correct%ISOPEN THEN
14105 CLOSE po_correct;
14106 END IF;
14107
14108 IF po_correct_rti%ISOPEN THEN
14109 CLOSE po_correct_rti;
14110 END IF;
14111
14112 IF (g_asn_debug = 'Y') THEN
14113 asn_debug.put_line('Exit derive_correction_line_amt');
14114 END IF;
14115 EXCEPTION
14116 WHEN OTHERS THEN
14117 IF (g_asn_debug = 'Y') THEN
14118 asn_debug.put_line('Exception in derive_correction_line_amt ');
14119 END IF;
14120
14121 IF po_correct%ISOPEN THEN
14122 CLOSE po_correct;
14123 END IF;
14124
14125 IF po_correct_rti%ISOPEN THEN
14126 CLOSE po_correct_rti;
14127 END IF;
14128
14129 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14130 rcv_error_pkg.set_sql_error_message('derive_correction_line_amt', x_progress);
14131 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14132 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14133
14134 IF (g_asn_debug = 'Y') THEN
14135 asn_debug.put_line(TO_CHAR(n));
14136 asn_debug.put_line(SQLERRM);
14137 asn_debug.put_line('error ' || x_progress);
14138 END IF;
14139 END derive_correction_line_amt;
14140
14141 PROCEDURE default_vendor_correct(
14142 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14143 n IN BINARY_INTEGER
14144 ) IS
14145 p_trx_record rcv_roi_header_common.common_default_record_type;
14146
14147 CURSOR po_correct(
14148 v_parent_trx_id NUMBER
14149 ) IS
14150 SELECT rt.po_revision_num,
14151 rsl.item_description,
14152 rt.po_release_id,
14153 rt.location_id loc_id,
14154 rt.organization_id,
14155 rt.routing_header_id,
14156 rt.destination_type_code,
14157 rt.destination_context,
14158 rt.inspection_status_code,
14159 rt.currency_code,
14160 rt.currency_conversion_rate,
14161 rt.currency_conversion_type,
14162 rt.currency_conversion_date,
14163 rt.location_id,
14164 rt.shipment_header_id,
14165 rt.shipment_line_id,
14166 rsl.category_id,
14167 rt.vendor_id,
14168 rt.vendor_site_id,
14169 rt.po_unit_price,
14170 rt.movement_id,
14171 rt.deliver_to_person_id,
14172 rt.deliver_to_location_id,
14173 rt.subinventory,
14174 rt.lpn_id,
14175 rt.transfer_lpn_id,
14176 rt.oe_order_header_id,
14177 rt.oe_order_line_id,
14178 rt.customer_id,
14179 rt.customer_site_id,
14180 rt.source_document_code,
14181 rt.job_id
14182 FROM rcv_transactions rt,
14183 rcv_shipment_lines rsl
14184 WHERE rt.transaction_id = v_parent_trx_id
14185 AND ( rt.transaction_type IN('RECEIVE', 'TRANSFER', 'ACCEPT', 'REJECT', 'MATCH')
14186 OR ( rt.transaction_type IN('RETURN TO VENDOR', 'RETURN TO CUSTOMER')
14187 AND NOT EXISTS(SELECT 'rtv to processed matched unordered receipt'
14188 FROM rcv_transactions rt2,
14189 rcv_transactions rt3
14190 WHERE rt2.transaction_id = rt.parent_transaction_id
14191 AND rt2.transaction_type = 'UNORDERED'
14192 AND rt3.transaction_type = 'MATCH'
14193 AND rt3.parent_transaction_id = rt2.transaction_id)
14194 AND NOT EXISTS(SELECT 'rtv to unprocessed matched unordered receipt'
14195 FROM rcv_transactions rt2,
14196 rcv_transactions_interface rti
14197 WHERE rt2.transaction_id = rt.parent_transaction_id
14198 AND rt2.transaction_type = 'UNORDERED'
14199 AND rti.transaction_type = 'MATCH'
14200 AND rti.parent_transaction_id = rt2.transaction_id)
14201 )
14202 OR ( rt.transaction_type = 'DELIVER'
14203 AND NOT( rt.destination_type_code = 'INVENTORY'
14204 AND rt.source_document_code IN('REQ', 'INVENTORY')))
14205 OR ( rt.transaction_type = 'UNORDERED'
14206 AND NOT EXISTS(SELECT 'processed matched rows'
14207 FROM rcv_transactions rt2
14208 WHERE rt2.parent_transaction_id = rt.transaction_id
14209 AND rt2.transaction_type = 'MATCH')
14210 AND NOT EXISTS(SELECT 'unprocessed matched rows'
14211 FROM rcv_transactions_interface rti
14212 WHERE rti.parent_transaction_id = rt.transaction_id
14213 AND rti.transaction_type = 'MATCH')
14214 )
14215 )
14216 AND NOT EXISTS(SELECT 'purchase order shipment cancelled or fc'
14217 FROM po_line_locations pll
14218 WHERE pll.line_location_id = rt.po_line_location_id
14219 AND ( NVL(pll.cancel_flag, 'N') = 'Y'
14220 OR NVL(pll.closed_code, 'OPEN') = 'FINALLY CLOSED'))
14221 AND (rt.shipment_line_id = rsl.shipment_line_id)
14222 ORDER BY rt.transaction_id;
14223
14224 CURSOR po_correct_rti(
14225 v_parent_inter_trx_id NUMBER
14226 ) IS
14227 SELECT rti.po_revision_num,
14228 rti.item_description,
14229 rti.po_release_id,
14230 rti.location_id loc_id,
14231 rti.to_organization_id organization_id,
14232 rti.routing_header_id,
14233 rti.destination_type_code,
14234 rti.destination_context,
14235 rti.inspection_status_code,
14236 rti.currency_code,
14237 rti.currency_conversion_rate,
14238 rti.currency_conversion_type,
14239 rti.currency_conversion_date,
14240 rti.location_id,
14241 rti.shipment_header_id,
14242 rti.shipment_line_id,
14243 rti.category_id,
14244 rti.vendor_id,
14245 rti.vendor_site_id,
14246 rti.po_unit_price,
14247 rti.movement_id,
14248 rti.deliver_to_person_id,
14249 rti.deliver_to_location_id,
14250 rti.subinventory,
14251 rti.lpn_id,
14252 rti.transfer_lpn_id,
14253 rti.oe_order_header_id,
14254 rti.oe_order_line_id,
14255 rti.customer_id,
14256 rti.customer_site_id,
14257 rti.source_document_code,
14258 rti.job_id
14259 FROM rcv_transactions_interface rti
14260 WHERE interface_transaction_id = v_parent_inter_trx_id;
14261
14262 default_po_correct_info po_correct%ROWTYPE;
14263 x_progress VARCHAR2(3);
14264 x_locator_control NUMBER;
14265 x_default_subinventory VARCHAR2(10);
14266 x_default_locator_id NUMBER;
14267 x_success BOOLEAN;
14268 x_tax_name VARCHAR2(50); -- Bug 6331613
14269 x_vendor_site_id NUMBER;
14270 x_vendor_site_code VARCHAR2(20);
14271 l_project_id NUMBER;
14272 l_task_id NUMBER;
14273 l_locator_id NUMBER;
14274 temp_index NUMBER;
14275 lpn_error NUMBER := 0;
14276 BEGIN
14277 p_trx_record.destination_type_code := x_cascaded_table(n).destination_type_code;
14278 p_trx_record.transaction_type := x_cascaded_table(n).transaction_type;
14279 p_trx_record.processing_mode_code := x_cascaded_table(n).processing_mode_code;
14280 p_trx_record.processing_status_code := x_cascaded_table(n).processing_status_code;
14281 p_trx_record.transaction_status_code := x_cascaded_table(n).transaction_status_code;
14282 p_trx_record.auto_transact_code := x_cascaded_table(n).auto_transact_code;
14283 rcv_roi_header_common.commondefaultcode(p_trx_record);
14284 x_cascaded_table(n).destination_type_code := p_trx_record.destination_type_code;
14285 x_cascaded_table(n).transaction_type := p_trx_record.transaction_type;
14286 x_cascaded_table(n).processing_mode_code := p_trx_record.processing_mode_code;
14287 x_cascaded_table(n).processing_status_code := p_trx_record.processing_status_code;
14288 x_cascaded_table(n).transaction_status_code := p_trx_record.transaction_status_code;
14289 x_cascaded_table(n).auto_transact_code := p_trx_record.auto_transact_code;
14290
14291 IF (g_asn_debug = 'Y') THEN
14292 asn_debug.put_line('Enter Default for Correct transaction');
14293 asn_debug.put_line('quantity ' || x_cascaded_table(n).quantity);
14294 END IF;
14295
14296 IF x_cascaded_table(n).source_document_code IS NULL THEN
14297 IF x_cascaded_table(n).receipt_source_code = 'CUSTOMER' THEN
14298 x_cascaded_table(n).source_document_code := 'RMA';
14299 ELSE
14300 x_cascaded_table(n).source_document_code := 'PO';
14301 END IF;
14302
14303 IF (g_asn_debug = 'Y') THEN
14304 asn_debug.put_line('Defaulting SOURCE_DOCUMENT_CODE ' || x_cascaded_table(n).source_document_code);
14305 END IF;
14306 END IF;
14307
14308 IF (x_cascaded_table(n).derive = 'Y') THEN --{
14309 IF (x_cascaded_table(n).derive_index <> 0) THEN --{
14310 NULL;
14311 /* Get the values from pl/sql table */
14312 temp_index := x_cascaded_table(n).derive_index;
14313 x_cascaded_table(n).po_revision_num := x_cascaded_table(temp_index).po_revision_num;
14314 x_cascaded_table(n).item_description := x_cascaded_table(temp_index).item_description;
14315 x_cascaded_table(n).destination_type_code := x_cascaded_table(temp_index).destination_type_code;
14316 x_cascaded_table(n).destination_context := x_cascaded_table(temp_index).destination_context;
14317 x_cascaded_table(n).inspection_status_code := x_cascaded_table(temp_index).inspection_status_code;
14318 x_cascaded_table(n).po_release_id := x_cascaded_table(temp_index).po_release_id;
14319 x_cascaded_table(n).to_organization_id := x_cascaded_table(temp_index).to_organization_id;
14320 x_cascaded_table(n).from_organization_id := x_cascaded_table(temp_index).from_organization_id;
14321 x_cascaded_table(n).routing_header_id := x_cascaded_table(temp_index).routing_header_id;
14322 x_cascaded_table(n).currency_code := x_cascaded_table(temp_index).currency_code;
14323 x_cascaded_table(n).currency_conversion_rate := x_cascaded_table(temp_index).currency_conversion_rate;
14324 x_cascaded_table(n).currency_conversion_type := x_cascaded_table(temp_index).currency_conversion_type;
14325 x_cascaded_table(n).currency_conversion_date := x_cascaded_table(temp_index).currency_conversion_date;
14326 x_cascaded_table(n).shipment_header_id := x_cascaded_table(temp_index).shipment_header_id;
14327 x_cascaded_table(n).shipment_line_id := x_cascaded_table(temp_index).shipment_line_id;
14328 x_cascaded_table(n).category_id := x_cascaded_table(temp_index).category_id;
14329 x_cascaded_table(n).vendor_id := x_cascaded_table(temp_index).vendor_id;
14330 x_cascaded_table(n).vendor_site_id := x_cascaded_table(temp_index).vendor_site_id;
14331 x_cascaded_table(n).po_unit_price := x_cascaded_table(temp_index).po_unit_price;
14332 x_cascaded_table(n).location_id := x_cascaded_table(temp_index).location_id;
14333 x_cascaded_table(n).deliver_to_person_id := x_cascaded_table(temp_index).deliver_to_person_id;
14334 x_cascaded_table(n).deliver_to_location_id := x_cascaded_table(temp_index).deliver_to_location_id;
14335 x_cascaded_table(n).subinventory := x_cascaded_table(temp_index).subinventory;
14336 x_cascaded_table(n).job_id := x_cascaded_table(temp_index).job_id;
14337 -- LPN defaulting
14338 /* Bug 3444284.
14339 * We dont need to default lpn_ids. WMS will take care of
14340 * populating these columns. So this case of giving a warning
14341 * will not arise as it will be defaulted by them
14342 */
14343 ELSE --} {
14344 IF (g_asn_debug = 'Y') THEN
14345 asn_debug.put_line('open cursor Default RTI');
14346 END IF;
14347
14348 OPEN po_correct_rti(x_cascaded_table(n).parent_interface_txn_id);
14349 END IF; --}
14350 ELSE -- } {
14351 OPEN po_correct(x_cascaded_table(n).parent_transaction_id);
14352 END IF; --}
14353
14354 IF (po_correct%ISOPEN) THEN
14355 IF (g_asn_debug = 'Y') THEN
14356 asn_debug.put_line('fetch cursor Default ' || x_cascaded_table(n).parent_transaction_id);
14357 END IF;
14358
14359 FETCH po_correct INTO default_po_correct_info;
14360 ELSIF(po_correct_rti%ISOPEN) THEN
14361 FETCH po_correct_rti INTO default_po_correct_info;
14362 END IF;
14363
14364 IF ( ( po_correct%ISOPEN
14365 AND po_correct%FOUND)
14366 OR ( po_correct_rti%ISOPEN
14367 AND po_correct_rti%FOUND)) THEN --{
14368 IF (g_asn_debug = 'Y') THEN --{
14369 asn_debug.put_line('Defaulting Correct po_revision_num' || default_po_correct_info.po_revision_num);
14370 asn_debug.put_line('Defaulting Correct item_description' || default_po_correct_info.item_description);
14371 asn_debug.put_line('Defaulting Correct po_release_id' || default_po_correct_info.po_release_id);
14372 asn_debug.put_line('Defaulting Correct location_id' || default_po_correct_info.loc_id);
14373 asn_debug.put_line('Defaulting Correct organization_id' || default_po_correct_info.organization_id);
14374 asn_debug.put_line('Defaulting Correct routing_header_id' || default_po_correct_info.routing_header_id);
14375 asn_debug.put_line('Defaulting Correct currency_code' || default_po_correct_info.currency_code);
14376 asn_debug.put_line('Defaulting Correct currency_conversion_rate' || default_po_correct_info.currency_conversion_rate);
14377 asn_debug.put_line('Defaulting Correct currency_conversion_type' || default_po_correct_info.currency_conversion_type);
14378 asn_debug.put_line('Defaulting Correct currency_conversion_date' || default_po_correct_info.currency_conversion_date);
14379 asn_debug.put_line('Defaulting Correct shipment_header_id' || default_po_correct_info.shipment_header_id);
14380 asn_debug.put_line('Defaulting Correct shipment_line_id' || default_po_correct_info.shipment_line_id);
14381 asn_debug.put_line('Defaulting Correct category_id' || default_po_correct_info.category_id);
14382 asn_debug.put_line('Defaulting Correct vendor_id' || default_po_correct_info.vendor_id);
14383 asn_debug.put_line('Defaulting Correct vendor_site_id' || default_po_correct_info.vendor_site_id);
14384 asn_debug.put_line('Defaulting Correct po_unit_price' || default_po_correct_info.po_unit_price);
14385 asn_debug.put_line('Defaulting Correct DELIVER_TO_PERSON_ID' || default_po_correct_info.deliver_to_person_id);
14386 asn_debug.put_line('Defaulting Correct DELIVER_TO_LOCATION_ID' || default_po_correct_info.deliver_to_location_id);
14387 asn_debug.put_line('Defaulting Correct SUBINVENTORY' || default_po_correct_info.subinventory);
14388 asn_debug.put_line('Defaulting Correct CUSTOMER_ID' || default_po_correct_info.customer_id);
14389 asn_debug.put_line('Defaulting Correct CUSTOMER_SITE_ID' || default_po_correct_info.customer_site_id);
14390 asn_debug.put_line('Defaulting Correct job_id' || default_po_correct_info.job_id);
14391 END IF; --}
14392
14393 IF x_cascaded_table(n).oe_order_header_id IS NULL
14394 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
14395 x_cascaded_table(n).oe_order_header_id := default_po_correct_info.oe_order_header_id;
14396
14397 IF (g_asn_debug = 'Y') THEN
14398 asn_debug.put_line('Defaulting Transfer oe_order_header_id ' || x_cascaded_table(n).oe_order_header_id);
14399 END IF;
14400 END IF;
14401
14402 IF x_cascaded_table(n).oe_order_line_id IS NULL
14403 AND x_cascaded_table(n).source_document_code = 'RMA' THEN
14404 x_cascaded_table(n).oe_order_line_id := default_po_correct_info.oe_order_line_id;
14405
14406 IF (g_asn_debug = 'Y') THEN
14407 asn_debug.put_line('Defaulting Transfer oe_order_line_id ' || x_cascaded_table(n).oe_order_line_id);
14408 END IF;
14409 END IF;
14410
14411 x_cascaded_table(n).po_revision_num := default_po_correct_info.po_revision_num;
14412 x_cascaded_table(n).item_description := default_po_correct_info.item_description;
14413 x_cascaded_table(n).destination_type_code := default_po_correct_info.destination_type_code;
14414 x_cascaded_table(n).destination_context := default_po_correct_info.destination_context;
14415 x_cascaded_table(n).inspection_status_code := default_po_correct_info.inspection_status_code;
14416 x_cascaded_table(n).po_release_id := default_po_correct_info.po_release_id;
14417 x_cascaded_table(n).to_organization_id := default_po_correct_info.organization_id;
14418 x_cascaded_table(n).from_organization_id := default_po_correct_info.organization_id;
14419 x_cascaded_table(n).routing_header_id := default_po_correct_info.routing_header_id;
14420 x_cascaded_table(n).currency_code := default_po_correct_info.currency_code;
14421 x_cascaded_table(n).currency_conversion_rate := default_po_correct_info.currency_conversion_rate;
14422 x_cascaded_table(n).currency_conversion_type := default_po_correct_info.currency_conversion_type;
14423 x_cascaded_table(n).currency_conversion_date := default_po_correct_info.currency_conversion_date;
14424 x_cascaded_table(n).shipment_header_id := default_po_correct_info.shipment_header_id;
14425 x_cascaded_table(n).shipment_line_id := default_po_correct_info.shipment_line_id;
14426 x_cascaded_table(n).category_id := default_po_correct_info.category_id;
14427 x_cascaded_table(n).vendor_id := default_po_correct_info.vendor_id;
14428 x_cascaded_table(n).vendor_site_id := default_po_correct_info.vendor_site_id;
14429 x_cascaded_table(n).job_id := default_po_correct_info.job_id;
14430
14431 /* We used to get the unit_price from the cursor where it picks
14432 * up from the parent. But since PO unit_price can be change
14433 * retroactively, we need to pick up the unit_price from PO
14434 * directly. Since we would have derived line_location_id
14435 * and po_line_id at this point, use the values here. Since
14436 * we come here for defaulting RMA also, we need to do this
14437 * only when receipt_source_code is VENDOR.
14438 * x_cascaded_table(n).po_unit_price :=
14439 default_po_correct_info.po_unit_price;
14440 */
14441 IF (x_cascaded_table(n).receipt_source_code = 'VENDOR') THEN --{
14442 SELECT NVL(pll.price_override, pl.unit_price)
14443 INTO x_cascaded_table(n).po_unit_price
14444 FROM po_line_locations pll,
14445 po_lines pl
14446 WHERE pll.line_location_id = x_cascaded_table(n).po_line_location_id
14447 AND pl.po_line_id = x_cascaded_table(n).po_line_id
14448 AND pl.po_line_id = pll.po_line_id;
14449
14450 IF (g_asn_debug = 'Y') THEN
14451 asn_debug.put_line('Defaulting Correct po_unit_price' || x_cascaded_table(n).po_unit_price);
14452 END IF;
14453 END IF; --}
14454
14455 x_cascaded_table(n).location_id := default_po_correct_info.loc_id;
14456 x_cascaded_table(n).deliver_to_person_id := default_po_correct_info.deliver_to_person_id;
14457 x_cascaded_table(n).deliver_to_location_id := default_po_correct_info.deliver_to_location_id;
14458 x_cascaded_table(n).subinventory := default_po_correct_info.subinventory;
14459 -- LPN defaulting
14460 asn_debug.put_line(' defaulting lpn_id and transfer_lpn_id for int org cor');
14461 /* Bug 3444284.
14462 * We dont need to default lpn_ids. WMS will take care of
14463 * populating these columns. So this case of giving a warning
14464 * will not arise as it will be defaulted by them
14465 */
14466 END IF; -- if po_transfer%found is true }
14467
14468 /* Default the from and to subinventory and locator_id */
14469 ----WMS Changes
14470 IF x_cascaded_table(n).matching_basis <> 'AMOUNT' THEN
14471 default_from_subloc_info(x_cascaded_table, n);
14472 default_to_subloc_info(x_cascaded_table, n);
14473
14474 /* The following code will be common for all the transactions not just for transfer to
14475 * get the use_mtl_lot and use_mtl_serial.
14476 */
14477 /* Bug 5076685: For one time items, item_id won't be available. We need to
14478 have a check for item_id not null, before hitting the
14479 mtl_system_items table.Added the IF - END IF statement. */
14480 /*
14481 BEGIN Comment: Bug: 4735484
14482 IF x_cascaded_table(n).item_id IS NOT NULL THEN
14483 SELECT NVL(x_cascaded_table(n).use_mtl_lot, lot_control_code),
14484 NVL(x_cascaded_table(n).use_mtl_serial, serial_number_control_code)
14485 INTO x_cascaded_table(n).use_mtl_lot,
14486 x_cascaded_table(n).use_mtl_serial
14487 FROM mtl_system_items
14488 WHERE mtl_system_items.inventory_item_id = x_cascaded_table(n).item_id
14489 AND mtl_system_items.organization_id = x_cascaded_table(n).to_organization_id;
14490 END IF;
14491 END Comment: Bug: 4735484
14492 */
14493 END IF;
14494
14495 IF (g_asn_debug = 'Y') THEN
14496 asn_debug.put_line('Set Location_id = ' || TO_CHAR(x_cascaded_table(n).location_id));
14497 asn_debug.put_line(' quantity ' || x_cascaded_table(n).quantity);
14498 END IF;
14499
14500 IF (g_asn_debug = 'Y') THEN
14501 asn_debug.put_line('Exit default_vendor_correct');
14502 END IF;
14503
14504 IF po_correct%ISOPEN THEN
14505 CLOSE po_correct;
14506 END IF;
14507
14508 IF po_correct_rti%ISOPEN THEN
14509 CLOSE po_correct_rti;
14510 END IF;
14511 EXCEPTION
14512 WHEN OTHERS THEN
14513 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14514 rcv_error_pkg.set_sql_error_message('default_vendor_correct', x_progress);
14515 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14516 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14517 END default_vendor_correct;
14518
14519 FUNCTION convert_into_correct_qty(
14520 source_qty IN NUMBER,
14521 source_uom IN VARCHAR2,
14522 item_id IN NUMBER,
14523 dest_uom IN VARCHAR2
14524 )
14525 RETURN NUMBER IS
14526 correct_qty NUMBER;
14527 BEGIN
14528 IF source_uom <> dest_uom THEN
14529 po_uom_s.uom_convert(source_qty,
14530 source_uom,
14531 item_id,
14532 dest_uom,
14533 correct_qty
14534 );
14535 ELSE
14536 correct_qty := source_qty;
14537 END IF;
14538
14539 RETURN(correct_qty);
14540 EXCEPTION
14541 WHEN OTHERS THEN
14542 IF (g_asn_debug = 'Y') THEN
14543 asn_debug.put_line('Could not convert between UOMs');
14544 asn_debug.put_line('Will return 0');
14545 END IF;
14546
14547 correct_qty := 0;
14548 RETURN(correct_qty);
14549 END;
14550
14551 PROCEDURE validate_source_type(
14552 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14553 n IN BINARY_INTEGER
14554 ) IS
14555 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
14556 BEGIN
14557 /*
14558 ** Validate Source Type. This value is always required
14559 */
14560 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
14561 RETURN;
14562 END IF;
14563
14564 IF (x_cascaded_table(n).transaction_type <> 'RECEIVE') THEN --{
14565 IF (x_cascaded_table(n).source_document_code = 'PO') THEN --{
14566 SELECT type_lookup_code
14567 INTO po_lookup_code_record.lookup_code
14568 FROM po_headers
14569 WHERE po_header_id = x_cascaded_table(n).po_header_id;
14570
14571 po_lookup_code_record.lookup_type := 'PO TYPE';
14572 ELSE --}{
14573 po_lookup_code_record.lookup_code := x_cascaded_table(n).receipt_source_code;
14574 po_lookup_code_record.lookup_type := 'SHIPMENT SOURCE TYPE';
14575 END IF; --}
14576
14577 po_lookup_code_record.error_record.error_status := 'S';
14578 po_lookup_code_record.error_record.error_message := NULL;
14579
14580 IF (g_asn_debug = 'Y') THEN
14581 asn_debug.put_line('Validating Source Type Code');
14582 END IF;
14583
14584 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
14585 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
14586 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
14587 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
14588 'SOURCE_TYPE_CODE',
14589 FALSE
14590 );
14591 END IF;
14592 EXCEPTION
14593 WHEN OTHERS THEN
14594 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14595 rcv_error_pkg.set_sql_error_message('validate_source_type', '000');
14596 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14597 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14598 END validate_source_type;
14599
14600 PROCEDURE validate_transaction_type(
14601 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14602 n IN BINARY_INTEGER
14603 ) IS
14604 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
14605 BEGIN
14606 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
14607 RETURN;
14608 END IF;
14609
14610 IF (x_cascaded_table(n).transaction_type <> 'RECEIVE') THEN --{
14611 po_lookup_code_record.lookup_code := x_cascaded_table(n).transaction_type;
14612 po_lookup_code_record.lookup_type := 'RCV TRANSACTION TYPE';
14613 po_lookup_code_record.error_record.error_status := 'S';
14614 po_lookup_code_record.error_record.error_message := NULL;
14615
14616 IF (g_asn_debug = 'Y') THEN
14617 asn_debug.put_line('Validating Destination Type Code');
14618 END IF;
14619
14620 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
14621 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
14622 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
14623 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
14624 'TRANSACTION_TYPE_CODE',
14625 FALSE
14626 );
14627 END IF; --}
14628 EXCEPTION
14629 WHEN OTHERS THEN
14630 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14631 rcv_error_pkg.set_sql_error_message('validate_transaction_type', '000');
14632 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14633 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14634 END validate_transaction_type;
14635
14636 PROCEDURE validate_inspection_status(
14637 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14638 n IN BINARY_INTEGER
14639 ) IS
14640 po_lookup_code_record rcv_shipment_line_sv.po_lookup_code_record_type;
14641 BEGIN
14642 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
14643 RETURN;
14644 END IF;
14645
14646 IF (x_cascaded_table(n).inspection_status_code IS NOT NULL) THEN --{
14647 po_lookup_code_record.lookup_code := x_cascaded_table(n).inspection_status_code;
14648 po_lookup_code_record.lookup_type := 'INSPECTION STATUS';
14649 po_lookup_code_record.error_record.error_status := 'S';
14650 po_lookup_code_record.error_record.error_message := NULL;
14651
14652 IF (g_asn_debug = 'Y') THEN
14653 asn_debug.put_line('Validating INSPECTION STATUS ');
14654 END IF;
14655
14656 rcv_transactions_interface_sv1.validate_po_lookup_code(po_lookup_code_record);
14657 x_cascaded_table(n).error_status := po_lookup_code_record.error_record.error_status;
14658 x_cascaded_table(n).error_message := po_lookup_code_record.error_record.error_message;
14659 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,
14660 'INSPECTION_STATUS_CODE',
14661 FALSE
14662 );
14663 END IF; --}
14664 EXCEPTION
14665 WHEN OTHERS THEN
14666 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14667 rcv_error_pkg.set_sql_error_message('validate_inspection_status', '000');
14668 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14669 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14670 END validate_inspection_status;
14671
14672 /** OPM change Bug# 3061052**/
14673 -- added validate_opm_attributes to validate OPM specific columns.
14674
14675 PROCEDURE validate_opm_attributes(
14676 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14677 n IN BINARY_INTEGER
14678 ) IS
14679 /*INVCONV, gml_opm_roi_grp.opm_record_type to be removed , Punit Kumar */
14680 --l_opm_record_type gml_opm_roi_grp.opm_record_type;
14681
14682 l_att_rec RCV_TRANSACTIONS_INTERFACE_SV1.attributes_record_type;
14683 l_column_name VARCHAR2(50);
14684 l_tokenname1 VARCHAR2(30);
14685 l_tokenvalue1 VARCHAR2(1800);
14686 l_quantity_shipped NUMBER;
14687 l_secondary_quantity_shipped NUMBER;
14688
14689 /*INVCONV*/
14690 l_return_status VARCHAR2(1) := NULL;
14691 x_return_status VARCHAR2(1) :='S';
14692 l_msg_count NUMBER;
14693 l_msg_data VARCHAR2(100);
14694 /*end , INVCONV*/
14695
14696 BEGIN
14697
14698 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
14699 RETURN;
14700 END IF;
14701
14702 /*INVCONV , It checks for OPM insatallation. This needs to be removed , Punit Kumar*/
14703 /*
14704 IF ( gml_process_flags.opm_installed = 1
14705 AND x_cascaded_table(n).item_id IS NOT NULL
14706 AND gml_process_flags.check_process_orgn(p_organization_id => x_cascaded_table(n).to_organization_id) = 1 ) THEN
14707 IF (g_asn_debug = 'Y') THEN
14708 asn_debug.put_line('In validate opm attributes');
14709 END IF;
14710 */
14711
14712 IF (g_asn_debug = 'Y') THEN
14713 asn_debug.put_line('In validate opm attributes');
14714 END IF;
14715
14716
14717 -- if receiving full qty against an ASN/Internal Order , default the secondary qty from shipment line
14718 -- if there is no secondary qty specified on the reciept line.
14719 /*INVCONV, added INVENTORY to account for Inter Org Transfers. Punit Kumar*/
14720 IF x_cascaded_table(n).receipt_source_code IN('VENDOR', 'INTERNAL ORDER' , 'INVENTORY')
14721 /*end , INVCONV*/
14722 AND x_cascaded_table(n).shipment_header_id IS NOT NULL
14723 AND x_cascaded_table(n).shipment_line_id IS NOT NULL
14724 AND x_cascaded_table(n).secondary_quantity IS NULL THEN
14725 BEGIN
14726 SELECT quantity_shipped,
14727 secondary_quantity_shipped
14728 INTO l_quantity_shipped,
14729 l_secondary_quantity_shipped
14730 FROM rcv_shipment_lines
14731 WHERE shipment_header_id = x_cascaded_table(n).shipment_header_id
14732 AND shipment_line_id = x_cascaded_table(n).shipment_line_id;
14733 EXCEPTION
14734 WHEN OTHERS THEN
14735 NULL;
14736 END;
14737
14738 IF (g_asn_debug = 'Y') THEN
14739 asn_debug.put_line('quantity shipped = ' || l_quantity_shipped);
14740 asn_debug.put_line('secondary qty shipped = ' || l_secondary_quantity_shipped);
14741 END IF;
14742
14743 IF l_quantity_shipped = x_cascaded_table(n).quantity THEN
14744 x_cascaded_table(n).secondary_quantity := l_secondary_quantity_shipped;
14745 END IF;
14746 ELSIF x_cascaded_table(n).receipt_source_code = 'VENDOR'
14747 AND x_cascaded_table(n).shipment_header_id IS NULL
14748 AND x_cascaded_table(n).secondary_quantity IS NULL THEN
14749 -- if the receipt line qty is same as po shipment qty
14750 -- default the po shipment secondary qty to receipt line secondary qty.
14751
14752 BEGIN
14753 SELECT quantity,
14754 secondary_quantity
14755 INTO l_quantity_shipped,
14756 l_secondary_quantity_shipped
14757 FROM po_line_locations
14758 WHERE line_location_id = x_cascaded_table(n).po_line_location_id;
14759 EXCEPTION
14760 WHEN OTHERS THEN
14761 NULL;
14762 END;
14763
14764 IF (g_asn_debug = 'Y') THEN
14765 asn_debug.put_line('po shipment qty = ' || l_quantity_shipped);
14766 asn_debug.put_line('po shipment secondary qty = ' || l_secondary_quantity_shipped);
14767 END IF;
14768
14769 IF l_quantity_shipped = x_cascaded_table(n).quantity THEN
14770 x_cascaded_table(n).secondary_quantity := l_secondary_quantity_shipped;
14771 END IF;
14772 END IF;
14773
14774 /*INVCONV, Remove the population of l_opm_record_type and populate l_att_rec. Punit Kumar*/
14775
14776 /*
14777 l_opm_record_type.receipt_source_code := x_cascaded_table(n).receipt_source_code;
14778 l_opm_record_type.to_organization_id := x_cascaded_table(n).to_organization_id;
14779 l_opm_record_type.item_num := x_cascaded_table(n).item_num;
14780 l_opm_record_type.item_id := x_cascaded_table(n).item_id;
14781 l_opm_record_type.unit_of_measure := x_cascaded_table(n).unit_of_measure;
14782 l_opm_record_type.secondary_unit_of_measure := x_cascaded_table(n).secondary_unit_of_measure;
14783 l_opm_record_type.secondary_uom_code := x_cascaded_table(n).secondary_uom_code;
14784 l_opm_record_type.quantity := x_cascaded_table(n).quantity;
14785 l_opm_record_type.secondary_quantity := x_cascaded_table(n).secondary_quantity;
14786 l_opm_record_type.qc_grade := x_cascaded_table(n).qc_grade;
14787 l_opm_record_type.rti_id := x_cascaded_table(n).interface_transaction_id;
14788 -- bug# 3664014
14789 -- added some more parameters. validate_opm_parameters API reads these parameters from
14790 -- rcv_transactions_interface table which does hold the latest data. All the latest data
14791 -- are in the cascaded table.
14792
14793 l_opm_record_type.transaction_type := x_cascaded_table(n).transaction_type;
14794 l_opm_record_type.destination_type_code := x_cascaded_table(n).destination_type_code;
14795 l_opm_record_type.locator_id := x_cascaded_table(n).locator_id;
14796 l_opm_record_type.header_interface_id := x_cascaded_table(n).header_interface_id;
14797 l_opm_record_type.GROUP_ID := x_cascaded_table(n).GROUP_ID;
14798 l_opm_record_type.primary_quantity := x_cascaded_table(n).primary_quantity;
14799 l_opm_record_type.from_locator_id := x_cascaded_table(n).from_locator_id;
14800
14801 IF (g_asn_debug = 'Y') THEN
14802 asn_debug.put_line('unit_of_measure = ' || l_opm_record_type.unit_of_measure);
14803 asn_debug.put_line('secondary unit_of_measure = ' || l_opm_record_type.secondary_unit_of_measure);
14804 asn_debug.put_line('Quantity = ' || l_opm_record_type.quantity);
14805 asn_debug.put_line('Secondary Quantity = ' || l_opm_record_type.secondary_quantity);
14806 asn_debug.put_line('Item Id = ' || l_opm_record_type.item_id);
14807 END IF;
14808
14809 l_opm_record_type.error_record.error_status := 'S';
14810 l_opm_record_type.error_record.error_message := NULL;
14811
14812 */
14813
14814 l_att_rec.inventory_item_id := x_cascaded_table(n).item_id ; /*RTI.item_id */
14815 l_att_rec.transaction_quantity := x_cascaded_table(n).quantity; /*RTI.quantity(transaction quantity)*/
14816 l_att_rec.transaction_unit_of_measure := x_cascaded_table(n).unit_of_measure; /*RTI.UNIT_OF_MEASURE -(transaction unit_of_measure) */
14817 l_att_rec.secondary_quantity := x_cascaded_table(n).secondary_quantity; /*RTI.secondary_quantity */
14818 l_att_rec.secondary_unit_of_measure := x_cascaded_table(n).secondary_unit_of_measure; /*RTI.Secondary_UNIT_OF_MEASURE*/
14819 l_att_rec.secondary_uom_code := x_cascaded_table(n).secondary_uom_code; /*RTI.secondary_uom_code*/
14820 l_att_rec.to_organization_id := x_cascaded_table(n).to_organization_id; /*RTI.to_organization_id*/
14821 ---error handling
14822 l_att_rec.error_record.error_status := 'S';
14823 l_att_rec.error_record.error_message := NULL;
14824
14825
14826 IF (g_asn_debug = 'Y') THEN
14827 asn_debug.put_line('printing the values before calling RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
14828 asn_debug.put_line('unit_of_measure = ' || l_att_rec.transaction_unit_of_measure);
14829 asn_debug.put_line('secondary unit_of_measure = ' || l_att_rec.secondary_unit_of_measure);
14830 asn_debug.put_line('Quantity = ' || l_att_rec.transaction_quantity);
14831 asn_debug.put_line('Secondary Quantity = ' || l_att_rec.secondary_quantity);
14832 asn_debug.put_line('Item Id = ' || l_att_rec.inventory_item_id);
14833 asn_debug.put_line('Secondary_uom_code = ' || l_att_rec.secondary_uom_code);
14834 asn_debug.put_line('to organization id = ' || l_att_rec.to_organization_id);
14835 END IF;
14836
14837 /*INVCONV ,validate_opm_parameters procedure is being called to validate the OPM
14838 specific parameters.Now it shall be replaced with a new routine which shall
14839 validate these parameters for discrete items also.Remove the call to
14840 gml_opm_roi_grp.validate_opm_parameters(l_att_rec) , Punit Kumar
14841 */
14842 /*
14843 gml_opm_roi_grp.validate_opm_parameters(l_opm_record_type);
14844 x_cascaded_table(n).error_status := l_opm_record_type.error_record.error_status;
14845 x_cascaded_table(n).error_message := l_opm_record_type.error_record.error_message;
14846
14847 IF (g_asn_debug = 'Y') THEN
14848 asn_debug.put_line('OPM Error Status = ' || l_opm_record_type.error_record.error_status);
14849 asn_debug.put_line('OPM Error Msg = ' || l_opm_record_type.error_record.error_message);
14850 END IF;
14851 */
14852
14853 IF x_cascaded_table(n).item_id IS NOT NULL THEN
14854
14855 IF (g_asn_debug = 'Y') THEN
14856 asn_debug.put_line('Before calling new API RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
14857 END IF;
14858
14859
14860 RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS (
14861 1.0,
14862 'F',
14863 x_att_rec =>l_att_rec,
14864 x_return_status =>l_return_status,
14865 x_msg_count =>l_msg_count,
14866 x_msg_data =>l_msg_data
14867 );
14868 END IF;
14869
14870 /* INVCONV , remove the following error handling.Introduced new error handling below*/
14871 /*
14872 IF x_cascaded_table(n).error_status NOT IN('S', 'W') THEN
14873 rcv_error_pkg.set_error_message(x_cascaded_table(n).error_message);
14874
14875 IF (x_cascaded_table(n).error_message = 'PO_PDOI_INVALID_UOM_CODE') THEN
14876 rcv_error_pkg.set_token('VALUE', x_cascaded_table(n).secondary_uom_code);
14877 END IF;
14878 END IF;
14879
14880 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status, 'SECONDARY_UOM_CODE');
14881
14882 */
14883 /* error handling , INVCONV*/
14884 x_cascaded_table(n).error_status := l_att_rec.error_record.error_status;
14885 x_cascaded_table(n).error_message := l_att_rec.error_record.error_message;
14886
14887 IF (g_asn_debug = 'Y') THEN
14888 asn_debug.put_line('After calling new API RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
14889 asn_debug.put_line('return status of RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS = ' || x_cascaded_table(n).error_status);
14890 asn_debug.put_line('return message of RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS = ' || x_cascaded_table(n).error_message);
14891 END IF;
14892
14893
14894 /*If call fails*/
14895 IF x_cascaded_table(n).error_status IN ('U' ,'E') THEN
14896 IF (g_asn_debug = 'Y') THEN
14897 asn_debug.put_line('RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS call failed');
14898 END IF;
14899
14900 /*log error in po_interface_errors*/
14901 rcv_error_pkg.log_interface_message(
14902 x_cascaded_table(n).error_status,
14903 'Secondary Parameter',
14904 FALSE
14905 );
14906 RETURN;
14907 END IF;
14908
14909 /*On successful call populate the following*/
14910 x_cascaded_table(n).secondary_unit_of_measure := l_att_rec.secondary_unit_of_measure;
14911 x_cascaded_table(n).secondary_uom_code := l_att_rec.secondary_uom_code;
14912 x_cascaded_table(n).secondary_quantity := l_att_rec.secondary_quantity;
14913
14914 IF (g_asn_debug = 'Y') THEN
14915 asn_debug.put_line('populating the return values from RCV_TRANSACTIONS_INTERFACE_SV1.VALIDATE_SECONDARY_PARAMETERS');
14916 asn_debug.put_line('secondary unit_of_measure = ' || x_cascaded_table(n).secondary_unit_of_measure);
14917 asn_debug.put_line('Secondary Quantity = ' ||x_cascaded_table(n).secondary_quantity );
14918 asn_debug.put_line('Secondary_uom_code = ' ||x_cascaded_table(n).secondary_uom_code);
14919 END IF;
14920
14921
14922 /* INVCONV ,qc_grade not handled here */
14923 /* x_cascaded_table(n).qc_grade := l_opm_record_type.qc_grade;
14924 */
14925
14926 /* INVCONV, opm installation check no more required */
14927 /*
14928 ELSE --GML_PROCESS_FLAGS.opm_installed <> 1
14929 x_cascaded_table(n).secondary_uom_code := NULL;
14930 x_cascaded_table(n).secondary_unit_of_measure := NULL;
14931 x_cascaded_table(n).secondary_quantity := NULL;
14932 x_cascaded_table(n).qc_grade := NULL;
14933 END IF; -- IF (GML_PROCESS_FLAGS.opm_installed = 1
14934
14935 end , INVCONV */
14936
14937
14938 EXCEPTION
14939 WHEN rcv_error_pkg.e_fatal_error THEN
14940 NULL;
14941 WHEN OTHERS THEN
14942 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
14943 rcv_error_pkg.set_sql_error_message('log_interface_error', '000');
14944 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
14945 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
14946 END validate_opm_attributes;
14947
14948
14949 PROCEDURE get_interface_available_qty(
14950 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
14951 n IN BINARY_INTEGER,
14952 x_interface_qty OUT NOCOPY NUMBER
14953 ) IS
14954 l_grandparent_interface_trx_id NUMBER;
14955 l_interface_qty NUMBER;
14956 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
14957 l_parent_uom rcv_transactions_interface.unit_of_measure%TYPE;
14958 l_grandparent_uom rcv_transactions_interface.unit_of_measure%TYPE;
14959 test NUMBER;
14960 BEGIN
14961 x_interface_qty := 0; --Initialise
14962
14963 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
14964 RETURN;
14965 END IF;
14966
14967 BEGIN
14968 SELECT parent_interface_txn_id,
14969 transaction_type,
14970 unit_of_measure,
14971 interface_available_qty
14972 INTO l_grandparent_interface_trx_id,
14973 l_parent_trx_type,
14974 l_parent_uom,
14975 l_interface_qty
14976 FROM rcv_transactions_interface
14977 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
14978 EXCEPTION
14979 /* For a receive transaction, both parent_trx_id and
14980 * interface_parent_trx_id will be null.
14981 */
14982 WHEN NO_DATA_FOUND THEN
14983 l_interface_qty := 0;
14984 END;
14985
14986 IF (g_asn_debug = 'Y') THEN
14987 asn_debug.put_line('get_interface_qty l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
14988 asn_debug.put_line('get_interface_qty l_parent_trx_type ' || l_parent_trx_type);
14989 asn_debug.put_line('get_interface_qty l_parent_uom ' || l_parent_uom);
14990 asn_debug.put_line('get_interface_qty l_interface_qty ' || l_interface_qty);
14991 END IF;
14992
14993 IF ( x_cascaded_table(n).transaction_type = 'CORRECT'
14994 AND SIGN(x_cascaded_table(n).quantity) = 1) THEN --{
14995 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN --{
14996 BEGIN
14997 SELECT interface_available_qty,
14998 unit_of_measure
14999 INTO l_interface_qty,
15000 l_grandparent_uom
15001 FROM rcv_transactions_interface
15002 WHERE interface_transaction_id = l_grandparent_interface_trx_id;
15003
15004 /* Should be in terms of parent transaction uom */
15005 x_interface_qty := convert_into_correct_qty(l_interface_qty,
15006 l_grandparent_uom,
15007 x_cascaded_table(n).item_id,
15008 l_parent_uom
15009 );
15010 EXCEPTION
15011 WHEN NO_DATA_FOUND THEN
15012 x_interface_qty := 0;
15013 END;
15014 END IF; --}
15015 ELSE --}{
15016 x_interface_qty := l_interface_qty;
15017 END IF; --}
15018
15019 IF (g_asn_debug = 'Y') THEN
15020 asn_debug.put_line('get_interface_qty x_interface_qty ' || x_interface_qty);
15021 END IF;
15022
15023 x_interface_qty := NVL(x_interface_qty, 0);
15024 EXCEPTION
15025 WHEN OTHERS THEN
15026 x_interface_qty := 0;
15027 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
15028 rcv_error_pkg.set_sql_error_message('get_interface_available_qty', '000');
15029 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
15030 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15031 END get_interface_available_qty;
15032
15033 PROCEDURE get_interface_available_amt(
15034 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15035 n IN BINARY_INTEGER,
15036 x_interface_amt OUT NOCOPY NUMBER
15037 ) IS
15038 l_grandparent_interface_trx_id NUMBER;
15039 l_interface_amt NUMBER;
15040 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
15041 test NUMBER;
15042 BEGIN
15043 x_interface_amt := 0; --Initialise
15044
15045 IF (x_cascaded_table(n).parent_transaction_id IS NOT NULL) THEN
15046 RETURN;
15047 END IF;
15048
15049 BEGIN
15050 SELECT parent_interface_txn_id,
15051 transaction_type,
15052 interface_available_amt
15053 INTO l_grandparent_interface_trx_id,
15054 l_parent_trx_type,
15055 l_interface_amt
15056 FROM rcv_transactions_interface
15057 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15058 EXCEPTION
15059 /* For a receive transaction, both parent_trx_id and
15060 * interface_parent_trx_id will be null.
15061 */
15062 WHEN NO_DATA_FOUND THEN
15063 l_interface_amt := 0;
15064 END;
15065
15066 IF (g_asn_debug = 'Y') THEN
15067 asn_debug.put_line('get_interface_qty l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
15068 asn_debug.put_line('get_interface_qty l_parent_trx_type ' || l_parent_trx_type);
15069 asn_debug.put_line('get_interface_amt l_interface_amt ' || l_interface_amt);
15070 END IF;
15071
15072 IF ( x_cascaded_table(n).transaction_type = 'CORRECT'
15073 AND SIGN(x_cascaded_table(n).amount) = 1) THEN --{
15074 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN --{
15075 BEGIN
15076 SELECT interface_available_amt
15077 INTO x_interface_amt
15078 FROM rcv_transactions_interface
15079 WHERE interface_transaction_id = l_grandparent_interface_trx_id;
15080 EXCEPTION
15081 WHEN NO_DATA_FOUND THEN
15082 x_interface_amt := 0;
15083 END;
15084 END IF; --}
15085 ELSE --}{
15086 x_interface_amt := l_interface_amt;
15087 END IF; --}
15088
15089 IF (g_asn_debug = 'Y') THEN
15090 asn_debug.put_line('get_interface_amt x_interface_amt ' || x_interface_amt);
15091 END IF;
15092
15093 x_interface_amt := NVL(x_interface_amt, 0);
15094 EXCEPTION
15095 WHEN OTHERS THEN
15096 x_interface_amt := 0;
15097 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
15098 rcv_error_pkg.set_sql_error_message('get_interface_available_amt', '000');
15099 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
15100 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15101 END get_interface_available_amt;
15102
15103 PROCEDURE update_interface_available_qty(
15104 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15105 n IN BINARY_INTEGER
15106 ) IS
15107 l_grandparent_interface_trx_id NUMBER;
15108 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
15109 l_interface_transaction_qty rcv_transactions_interface.interface_transaction_qty%TYPE := 0;
15110 BEGIN
15111 /* Update interface_available_qty for the current rti row. */
15112 x_cascaded_table(n).interface_available_qty := x_cascaded_table(n).quantity;
15113
15114 IF (g_asn_debug = 'Y') THEN
15115 asn_debug.put_line('update_interace_qty x_interface_qty ' || x_cascaded_table(n).interface_available_qty);
15116 END IF;
15117
15118 /* Update interface_available_qty in the parent rti row */
15119 BEGIN
15120 SELECT parent_interface_txn_id,
15121 transaction_type
15122 INTO l_grandparent_interface_trx_id,
15123 l_parent_trx_type
15124 FROM rcv_transactions_interface
15125 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15126 EXCEPTION
15127 WHEN NO_DATA_FOUND THEN
15128 /* For an rti of receive or an rti row with parent in RT, select
15129 * will not result any rows.
15130 */
15131 NULL;
15132 END;
15133
15134 IF (g_asn_debug = 'Y') THEN
15135 asn_debug.put_line('update_interace_qty l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
15136 asn_debug.put_line('update_interace_qty l_parent_trx_type ' || l_parent_trx_type);
15137 END IF;
15138
15139 IF (x_cascaded_table(n).transaction_type = 'CORRECT') THEN --{
15140 UPDATE rcv_transactions_interface rti
15141 SET rti.interface_available_qty = rti.interface_available_qty + x_cascaded_table(n).quantity
15142 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15143
15144 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN
15145 UPDATE rcv_transactions_interface rti
15146 SET rti.interface_available_qty = rti.interface_available_qty - x_cascaded_table(n).quantity
15147 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
15148 END IF;
15149 ELSE --}{
15150 UPDATE rcv_transactions_interface rti
15151 SET rti.interface_available_qty = rti.interface_available_qty - x_cascaded_table(n).quantity
15152 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15153
15154 IF ( x_cascaded_table(n).transaction_type = 'RETURN TO RECEIVING'
15155 AND l_grandparent_interface_trx_id IS NOT NULL) THEN
15156 UPDATE rcv_transactions_interface rti
15157 SET rti.interface_available_qty = rti.interface_available_qty + x_cascaded_table(n).quantity
15158 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
15159 END IF;
15160 END IF; --}
15161
15162 IF (g_asn_debug = 'Y') THEN
15163 asn_debug.put_line('update_interace_qty calling update_total_transaction_qty ');
15164 END IF;
15165
15166 /* Update temp table with the correct quantity*/
15167 update_total_transaction_qty(x_cascaded_table(n).interface_transaction_id,
15168 x_cascaded_table(n).parent_transaction_id,
15169 x_cascaded_table(n).parent_interface_txn_id,
15170 x_cascaded_table(n).primary_quantity,
15171 x_cascaded_table(n).transaction_type,
15172 l_interface_transaction_qty
15173 );
15174
15175 IF (l_interface_transaction_qty <> 0) THEN
15176 x_cascaded_table(n).interface_transaction_qty := l_interface_transaction_qty;
15177 END IF;
15178 EXCEPTION
15179 WHEN OTHERS THEN
15180 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
15181 rcv_error_pkg.set_sql_error_message('update_interface_available_qty', '000');
15182 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
15183 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15184 END update_interface_available_qty;
15185
15186 PROCEDURE update_interface_available_amt(
15187 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15188 n IN BINARY_INTEGER
15189 ) IS
15190 l_grandparent_interface_trx_id NUMBER;
15191 l_parent_trx_type rcv_transactions_interface.transaction_type%TYPE;
15192 l_interface_transaction_amt rcv_transactions_interface.interface_transaction_amt%TYPE := 0;
15193 BEGIN
15194 /* Update interface_available_qty for the current rti row. */
15195 x_cascaded_table(n).interface_available_amt := x_cascaded_table(n).amount;
15196
15197 IF (g_asn_debug = 'Y') THEN
15198 asn_debug.put_line('update_interace_qty x_interface_amt ' || x_cascaded_table(n).interface_available_amt);
15199 END IF;
15200
15201 /* Update interface_available_qty in the parent rti row */
15202 BEGIN
15203 SELECT parent_interface_txn_id,
15204 transaction_type
15205 INTO l_grandparent_interface_trx_id,
15206 l_parent_trx_type
15207 FROM rcv_transactions_interface
15208 WHERE interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15209 EXCEPTION
15210 WHEN NO_DATA_FOUND THEN
15211 /* For an rti of receive or an rti row with parent in RT, select
15212 * will not result any rows.
15213 */
15214 NULL;
15215 END;
15216
15217 IF (g_asn_debug = 'Y') THEN
15218 asn_debug.put_line('update_interface_amt l_grandparent_interface_trx_id ' || l_grandparent_interface_trx_id);
15219 asn_debug.put_line('update_interface_amt l_parent_trx_type ' || l_parent_trx_type);
15220 END IF;
15221
15222 IF (x_cascaded_table(n).transaction_type = 'CORRECT') THEN --{
15223 UPDATE rcv_transactions_interface rti
15224 SET rti.interface_available_amt = rti.interface_available_amt + x_cascaded_table(n).amount
15225 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15226
15227 IF (l_grandparent_interface_trx_id IS NOT NULL) THEN
15228 UPDATE rcv_transactions_interface rti
15229 SET rti.interface_available_amt = rti.interface_available_amt - x_cascaded_table(n).amount
15230 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
15231 END IF;
15232 ELSE --}{
15233 UPDATE rcv_transactions_interface rti
15234 SET rti.interface_available_amt = rti.interface_available_amt - x_cascaded_table(n).amount
15235 WHERE rti.interface_transaction_id = x_cascaded_table(n).parent_interface_txn_id;
15236
15237 IF ( x_cascaded_table(n).transaction_type = 'RETURN TO RECEIVING'
15238 AND l_grandparent_interface_trx_id IS NOT NULL) THEN
15239 UPDATE rcv_transactions_interface rti
15240 SET rti.interface_available_amt = rti.interface_available_amt + x_cascaded_table(n).amount
15241 WHERE rti.interface_transaction_id = l_grandparent_interface_trx_id;
15242 END IF;
15243 END IF; --}
15244
15245 IF (g_asn_debug = 'Y') THEN
15246 asn_debug.put_line('update_interface_amt calling update_total_transaction_amt ');
15247 END IF;
15248
15249 /* Update temp table with the correct quantity */
15250 update_total_transaction_amt(x_cascaded_table(n).interface_transaction_id,
15251 x_cascaded_table(n).parent_transaction_id,
15252 x_cascaded_table(n).parent_interface_txn_id,
15253 x_cascaded_table(n).amount,
15254 x_cascaded_table(n).transaction_type,
15255 l_interface_transaction_amt
15256 );
15257
15258 IF (l_interface_transaction_amt <> 0) THEN
15259 x_cascaded_table(n).interface_transaction_amt := l_interface_transaction_amt;
15260 END IF;
15261 EXCEPTION
15262 WHEN OTHERS THEN
15263 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
15264 rcv_error_pkg.set_sql_error_message('update_interface_available_amt', '000');
15265 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
15266 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15267 END update_interface_available_amt;
15268
15269 PROCEDURE update_total_transaction_qty(
15270 p_interface_transaction_id IN rcv_transactions_interface.interface_transaction_id%TYPE,
15271 p_parent_transaction_id IN rcv_transactions_interface.parent_transaction_id%TYPE,
15272 p_parent_interface_txn_id IN rcv_transactions_interface.parent_interface_txn_id%TYPE,
15273 p_primary_quantity IN rcv_transactions_interface.quantity%TYPE,
15274 p_transaction_type IN rcv_transactions_interface.transaction_type%TYPE,
15275 x_interface_transaction_qty OUT NOCOPY rcv_transactions_interface.interface_transaction_qty%TYPE
15276 ) IS
15277 l_child_count NUMBER;
15278 l_grand_parent_id NUMBER;
15279 BEGIN
15280 x_interface_transaction_qty := 0;
15281
15282 /* Insert into temp table since we need to update this value
15283 * when we process children.
15284 */
15285 IF (g_asn_debug = 'Y') THEN
15286 asn_debug.put_line('update_total_transaction_qty p_parent_transaction_id ' || p_parent_transaction_id);
15287 asn_debug.put_line('update_total_transaction_qty child count ' || l_child_count);
15288 asn_debug.put_line('update_total_transaction_qty p_primary_quantity ' || p_primary_quantity);
15289 END IF;
15290
15291 /* Bug 3459152.
15292 * We need to update interface_transaction_qty for SHIP transaction
15293 * also. Otherwise we will be able to create 2 asn shipment lines
15294 * for the same shipment if they are run in the same group.
15295 */
15296 IF ( ( p_parent_transaction_id IS NULL
15297 AND p_transaction_type IN('RECEIVE', 'SHIP'))
15298 OR (p_parent_transaction_id IS NOT NULL)) THEN --{
15299 IF (g_asn_debug = 'Y') THEN
15300 asn_debug.put_line('update_total_transaction_qty updating rti row with parent' || p_interface_transaction_id || ',quantity ' || p_primary_quantity);
15301 END IF;
15302
15303 x_interface_transaction_qty := p_primary_quantity;
15304 RETURN;
15305 END IF; --}
15306
15307 IF (p_parent_interface_txn_id IS NOT NULL) THEN --{
15308 IF (g_asn_debug = 'Y') THEN
15309 asn_debug.put_line('update_total_transaction_qty parent_interface_txn_id is not null ');
15310 asn_debug.put_line('update_total_transaction_qty p_primary_quantity ' || p_primary_quantity);
15311 END IF;
15312
15313 SELECT parent_transaction_id
15314 INTO l_grand_parent_id
15315 FROM rcv_transactions_interface
15316 WHERE interface_transaction_id = p_parent_interface_txn_id;
15317
15318 IF (g_asn_debug = 'Y') THEN
15319 asn_debug.put_line('update_total_transaction_qty l_grand_parent_id ' || l_grand_parent_id);
15320 END IF;
15321
15322 IF ( (l_grand_parent_id IS NOT NULL)
15323 AND (p_transaction_type = 'CORRECT')) THEN
15324 UPDATE rcv_transactions_interface rti
15325 SET rti.interface_transaction_qty = rti.interface_transaction_qty + p_primary_quantity
15326 WHERE interface_transaction_id = p_parent_interface_txn_id;
15327 END IF;
15328
15329 IF ( (l_grand_parent_id IS NOT NULL)
15330 AND (p_transaction_type = 'RETURN TO RECEIVING')) THEN
15331 UPDATE rcv_transactions_interface rti
15332 SET rti.interface_transaction_qty = rti.interface_transaction_qty - p_primary_quantity
15333 WHERE interface_transaction_id = p_parent_interface_txn_id;
15334 END IF;
15335 END IF; --}
15336 EXCEPTION
15337 WHEN OTHERS THEN
15338 rcv_error_pkg.set_sql_error_message('update_total_transaction_qty', '000');
15339 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15340 RAISE;
15341 END update_total_transaction_qty;
15342
15343 PROCEDURE update_total_transaction_amt(
15344 p_interface_transaction_id IN rcv_transactions_interface.interface_transaction_id%TYPE,
15345 p_parent_transaction_id IN rcv_transactions_interface.parent_transaction_id%TYPE,
15346 p_parent_interface_txn_id IN rcv_transactions_interface.parent_interface_txn_id%TYPE,
15347 p_amount IN rcv_transactions_interface.amount%TYPE,
15348 p_transaction_type IN rcv_transactions_interface.transaction_type%TYPE,
15349 x_interface_transaction_amt OUT NOCOPY rcv_transactions_interface.interface_transaction_amt%TYPE
15350 ) IS
15351 l_child_count NUMBER;
15352 l_grand_parent_id NUMBER;
15353 BEGIN
15354 x_interface_transaction_amt := 0;
15355
15356 /* Insert into temp table since we need to update this value
15357 * when we process children.
15358 */
15359 IF (g_asn_debug = 'Y') THEN
15360 asn_debug.put_line('update_total_transaction_amt p_parent_transaction_id ' || p_parent_transaction_id);
15361 asn_debug.put_line('update_total_transaction_amt child count ' || l_child_count);
15362 asn_debug.put_line('update_total_transaction_amt p_primary_quantity ' || p_amount);
15363 END IF;
15364
15365 IF ( ( p_parent_transaction_id IS NULL
15366 AND p_transaction_type IN('RECEIVE', 'SHIP'))
15367 OR (p_parent_transaction_id IS NOT NULL)) THEN --{
15368 IF (g_asn_debug = 'Y') THEN
15369 asn_debug.put_line('update_total_transaction_amt updating rti row with parent' || p_interface_transaction_id || ',amount ' || p_amount);
15370 END IF;
15371
15372 x_interface_transaction_amt := p_amount;
15373 RETURN;
15374 END IF; --}
15375
15376 IF (p_parent_interface_txn_id IS NOT NULL) THEN --{
15377 IF (g_asn_debug = 'Y') THEN
15378 asn_debug.put_line('update_total_transaction_amt parent_interface_txn_id is not null ');
15379 asn_debug.put_line('update_total_transaction_amt p_amount ' || p_amount);
15380 END IF;
15381
15382 SELECT parent_transaction_id
15383 INTO l_grand_parent_id
15384 FROM rcv_transactions_interface
15385 WHERE interface_transaction_id = p_parent_interface_txn_id;
15386
15387 IF (g_asn_debug = 'Y') THEN
15388 asn_debug.put_line('update_total_transaction_amt l_grand_parent_id ' || l_grand_parent_id);
15389 END IF;
15390
15391 IF ( (l_grand_parent_id IS NOT NULL)
15392 AND (p_transaction_type = 'CORRECT')) THEN
15393 UPDATE rcv_transactions_interface rti
15394 SET rti.interface_transaction_amt = rti.interface_transaction_amt + p_amount
15395 WHERE interface_transaction_id = p_parent_interface_txn_id;
15396 END IF;
15397
15398 IF ( (l_grand_parent_id IS NOT NULL)
15399 AND (p_transaction_type = 'RETURN TO RECEIVING')) THEN
15400 UPDATE rcv_transactions_interface rti
15401 SET rti.interface_transaction_amt = rti.interface_transaction_amt - p_amount
15402 WHERE interface_transaction_id = p_parent_interface_txn_id;
15403 END IF;
15404 END IF; --}
15405 EXCEPTION
15406 WHEN OTHERS THEN
15407 rcv_error_pkg.set_sql_error_message('update_total_transaction_amt', '000');
15408 rcv_error_pkg.log_interface_error('TRANSACTIONS_INTERFACE_ID', FALSE);
15409 RAISE;
15410 END update_total_transaction_amt;
15411
15412 PROCEDURE derive_matching_basis(
15413 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15414 n IN BINARY_INTEGER
15415 ) IS
15416 x_progress varchar2(3);
15417 begin
15418 x_progress := '000';
15419
15420 /* Complex Work Start.
15421 * Only for Complex Work POs we can have mixed
15422 * Service and quantity shipments. And for this
15423 * PO we will always have the line and shipment
15424 * information provided. So first get the
15425 * matching_basis from po_line_locations. For
15426 * non complex work POs, all the shipment will
15427 * have the same matching_basis as that of the
15428 * line and hence there wont be a problem if
15429 * the shipment number is given for a service or
15430 * quantity based POs. We will have po_line_id at
15431 * this point since we would have derived it in
15432 * derive_po_line_info.
15433 */
15434 IF (g_asn_debug = 'Y') THEN
15435 asn_debug.put_line('po_line_id '
15436 ||x_cascaded_table(n).po_line_id);
15437 asn_debug.put_line('po_line_location_id '
15438 ||x_cascaded_table(n).po_line_location_id);
15439 asn_debug.put_line('shipment_num '
15440 ||x_cascaded_table(n).document_shipment_line_num);
15441 END IF;
15442
15443 IF(x_cascaded_table(n).po_line_id IS NOT NULL)
15444 AND
15445 (x_cascaded_table(n).po_line_location_id is not null) THEN--{
15446 begin
15447
15448 SELECT NVL(pll.value_basis, 'QUANTITY'),
15449 NVL(pll.matching_basis, 'QUANTITY'),
15450 NVL(pl.purchase_basis,'GOODS')
15451 INTO x_cascaded_table(n).value_basis,
15452 x_cascaded_table(n).matching_basis,
15453 x_cascaded_table(n).purchase_basis
15454 FROM po_line_locations_all pll,
15455 po_lines_all pl
15456 WHERE pl.po_line_id = x_cascaded_table(n).po_line_id
15457 and pl.po_line_id = pll.po_line_id
15458 and pll.line_location_id =x_cascaded_table(n).po_line_location_id;
15459 exception
15460 when no_data_found then
15461 IF (g_asn_debug = 'Y') THEN
15462 asn_debug.put_line('NO data found in derive_match_basis '
15463 ||'for PO shipments with line and line_loc_id info');
15464 END IF;
15465 x_cascaded_table(n).error_status :=
15466 rcv_error_pkg.g_ret_sts_unexp_error;
15467 rcv_error_pkg.set_sql_error_message(
15468 ' when no data in derive_matching_basis '||
15469 'line and line_loc_id info' ,
15470 x_progress);
15471 x_cascaded_table(n).error_message :=
15472 rcv_error_pkg.get_last_message;
15473 when others then
15474 IF (g_asn_debug = 'Y') THEN
15475 asn_debug.put_line('when others in derive_match_basis '
15476 ||'for PO shipments with line and line_loc_id info');
15477 END IF;
15478 x_cascaded_table(n).error_status :=
15479 rcv_error_pkg.g_ret_sts_unexp_error;
15480 rcv_error_pkg.set_sql_error_message(
15481 'when others in derive_matching_basis with '||
15482 'line and line_loc_id info',
15483 x_progress);
15484 x_cascaded_table(n).error_message :=
15485 rcv_error_pkg.get_last_message;
15486 end;
15487 ELSIF((x_cascaded_table(n).po_line_id IS NOT NULL)
15488 AND
15489 (x_cascaded_table(n).document_shipment_line_num is not null)) THEN--}{
15490 begin
15491 SELECT NVL(pll.value_basis, 'QUANTITY'),
15492 NVL(pll.matching_basis, 'QUANTITY'),
15493 NVL(pl.purchase_basis,'GOODS')
15494 INTO x_cascaded_table(n).value_basis,
15495 x_cascaded_table(n).matching_basis,
15496 x_cascaded_table(n).purchase_basis
15497 FROM po_line_locations_all pll,
15498 po_lines_all pl
15499 WHERE pl.po_line_id = x_cascaded_table(n).po_line_id
15500 and pl.po_line_id = pll.po_line_id
15501 and pll.shipment_num =
15502 x_cascaded_table(n).document_shipment_line_num;
15503 exception
15504 when too_many_rows then
15505 IF (g_asn_debug = 'Y') THEN
15506 asn_debug.put_line('too many rows in derive_match_basis ' ||'for PO shipments with line and ship info');
15507 END IF;
15508 x_cascaded_table(n).error_status :=
15509 rcv_error_pkg.g_ret_sts_unexp_error;
15510 rcv_error_pkg.set_sql_error_message(
15511 ' too many rows in derive_matching_basis '||
15512 'line and ship info' ,
15513 x_progress);
15514 x_cascaded_table(n).error_message :=
15515 rcv_error_pkg.get_last_message;
15516 when no_data_found then
15517 IF (g_asn_debug = 'Y') THEN
15518 asn_debug.put_line('NO data found in derive_match_basis ' ||'for PO shipments with line and ship info');
15519 END IF;
15520 x_cascaded_table(n).error_status :=
15521 rcv_error_pkg.g_ret_sts_unexp_error;
15522 rcv_error_pkg.set_sql_error_message(
15523 ' when no data in derive_matching_basis '||
15524 'line and ship info' ,
15525 x_progress);
15526 x_cascaded_table(n).error_message :=
15527 rcv_error_pkg.get_last_message;
15528 when others then
15529 IF (g_asn_debug = 'Y') THEN
15530 asn_debug.put_line('when others in derive_match_basis '
15531 ||'for PO shipments with line and ship info');
15532 END IF;
15533 x_cascaded_table(n).error_status :=
15534 rcv_error_pkg.g_ret_sts_unexp_error;
15535 rcv_error_pkg.set_sql_error_message(
15536 'when others in derive_matching_basis with '||
15537 'line and ship info',
15538 x_progress);
15539 x_cascaded_table(n).error_message :=
15540 rcv_error_pkg.get_last_message;
15541 end;
15542 ELSIF x_cascaded_table(n).po_line_id IS NOT NULL THEN --}{
15543 begin
15544 SELECT NVL(order_type_lookup_code, 'QUANTITY'),
15545 NVL(purchase_basis, 'GOODS'),
15546 NVL(matching_basis, 'QUANTITY')
15547 INTO x_cascaded_table(n).value_basis,
15548 x_cascaded_table(n).purchase_basis,
15549 x_cascaded_table(n).matching_basis
15550 FROM po_lines_all
15551 WHERE po_line_id = x_cascaded_table(n).po_line_id;
15552 exception
15553 when no_data_found then
15554 IF (g_asn_debug = 'Y') THEN
15555 asn_debug.put_line('NO data found in derive_match_basis '
15556 ||'for PO shipments with line info');
15557 END IF;
15558 x_cascaded_table(n).error_status :=
15559 rcv_error_pkg.g_ret_sts_unexp_error;
15560 rcv_error_pkg.set_sql_error_message(
15561 ' when no data in derive_matching_basis with '||
15562 'line info ',
15563 x_progress);
15564 x_cascaded_table(n).error_message :=
15565 rcv_error_pkg.get_last_message;
15566 when others then
15567 IF (g_asn_debug = 'Y') THEN
15568 asn_debug.put_line('when others in derive_match_basis '
15569 ||'for PO shipments with line info');
15570 END IF;
15571 x_cascaded_table(n).error_status :=
15572 rcv_error_pkg.g_ret_sts_unexp_error;
15573 rcv_error_pkg.set_sql_error_message(
15574 'when others in derive_matching_basis with '||
15575 'line info',
15576 x_progress);
15577 x_cascaded_table(n).error_message :=
15578 rcv_error_pkg.get_last_message;
15579 end;
15580 ELSE --}{
15581 -- we require line info for receiving against services lines
15582 x_cascaded_table(n).matching_basis := 'QUANTITY';
15583 x_cascaded_table(n).purchase_basis := 'GOODS';
15584 END IF;
15585
15586 IF (g_asn_debug = 'Y') THEN
15587 asn_debug.put_line('matching_basis ' ||
15588 x_cascaded_table(n).matching_basis);
15589 END IF;
15590 EXCEPTION
15591 WHEN OTHERS THEN
15592 rcv_error_pkg.set_sql_error_message(
15593 'update_total_transaction_amt',
15594 '000');
15595 rcv_error_pkg.log_interface_error(
15596 'TRANSACTIONS_INTERFACE_ID',
15597 FALSE);
15598 RAISE;
15599 END derive_matching_basis;
15600
15601 /* Procedure get_deliver_to_person_from_po() is added as part of Bug#6375015 fix.
15602 get_deliver_to_person_from_po() is called from validate_vendor_rcv_line().
15603 At that point of time, all the defaulting and derivation would have happened,
15604 so po_line_location_id or po_distribution_id would be available.
15605 This procedure tries to default the deliver_to_person_id mentioned in the pod of
15606 Purchase order. If po_distribution_id is not known, it will try to get the
15607 value based on po_line_location only if the poll has got single distribution.
15608 */
15609 PROCEDURE get_deliver_to_person_from_po(
15610 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15611 n IN BINARY_INTEGER
15612 ) IS
15613 l_deliver_to_person_id NUMBER;
15614 l_distribution_count NUMBER;
15615 BEGIN
15616 --At this point po_distribution_id or po_line_location_id would have been derived or defaulted.
15617 IF (g_asn_debug = 'Y') THEN
15618 asn_debug.put_line('Inside get_deliver_to_person_from_po...');
15619 END IF;
15620 IF (x_cascaded_table(n).po_distribution_id is not null) THEN
15621 IF (g_asn_debug = 'Y') THEN
15622 asn_debug.put_line('Inside pod is not null..pod value :'||x_cascaded_table(n).po_distribution_id);
15623 END IF;
15624
15625 BEGIN
15626 select deliver_to_person_id
15627 into l_deliver_to_person_id
15628 from po_distributions_all
15629 where po_distribution_id = x_cascaded_table(n).po_distribution_id;
15630
15631 x_cascaded_table(n).deliver_to_person_id := l_deliver_to_person_id;
15632 IF (g_asn_debug = 'Y') THEN
15633 asn_debug.put_line('defaulted deliver_to_person_id as:'||l_deliver_to_person_id);
15634 END IF;
15635 EXCEPTION
15636 WHEN OTHERS then
15637 IF (g_asn_debug = 'Y') THEN
15638 asn_debug.put_line('Exception occured while getting deliver_to_person_id thru pod');
15639 END IF;
15640 END;
15641 ELSIF (x_cascaded_table(n).po_line_location_id is not null) THEN
15642 IF (g_asn_debug = 'Y') THEN
15643 asn_debug.put_line('Inside poll not null..poll value :'||x_cascaded_table(n).po_line_location_id);
15644 END IF;
15645
15646 BEGIN
15647 select count(po_distribution_id)
15648 into l_distribution_count
15649 from po_distributions_all
15650 where line_location_id = x_cascaded_table(n).po_line_location_id;
15651
15652 IF (g_asn_debug = 'Y') THEN
15653 asn_debug.put_line('Inside poll not null..l_distribution_count:'||l_distribution_count);
15654 END IF;
15655
15656 IF l_distribution_count = 1 THEN
15657 select deliver_to_person_id
15658 into l_deliver_to_person_id
15659 from po_distributions_all
15660 where line_location_id = x_cascaded_table(n).po_line_location_id;
15661
15662 x_cascaded_table(n).deliver_to_person_id := l_deliver_to_person_id;
15663 IF (g_asn_debug = 'Y') THEN
15664 asn_debug.put_line('defaulted deliver_to_person_id as:'||l_deliver_to_person_id);
15665 END IF;
15666 ELSE--l_distribution_count = 1
15667 IF (g_asn_debug = 'Y') THEN
15668 asn_debug.put_line('deliver_to_person_id not defalued as poll has multiple distributions');
15669 END IF;
15670 END IF;--l_distribution_count = 1
15671 EXCEPTION
15672 WHEN OTHERS then
15673 IF (g_asn_debug = 'Y') THEN
15674 asn_debug.put_line('Exception occured while getting deliver_to_person_id thru poll');
15675 END IF;
15676 END;
15677 END IF;--(x_cascaded_table(n).po_distribution_id is not null)
15678 END get_deliver_to_person_from_po;
15679
15680 /* Function get_deliver_to_person_from_rt() is added as part of Bug#6375015 fix.
15681 This function is called from validate_vendor_rcv_line() and it tries to default
15682 the deliver_to_person_id mentioned in the parent transaction(i.e from rcv_transactions).
15683 */
15684 FUNCTION get_deliver_to_person_from_rt(
15685 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15686 n IN BINARY_INTEGER
15687 ) RETURN NUMBER IS
15688 l_parent_deliver_to_person_id NUMBER := null;
15689 BEGIN
15690 select deliver_to_person_id
15691 into l_parent_deliver_to_person_id
15692 from rcv_transactions
15693 where transaction_id = x_cascaded_table(n).parent_transaction_id;
15694
15695 IF (g_asn_debug = 'Y') THEN
15696 asn_debug.put_line('Got deliver_to_person_id of parent txn as:'||l_parent_deliver_to_person_id);
15697 END IF;
15698 return l_parent_deliver_to_person_id;
15699 EXCEPTION
15700 WHEN OTHERS then
15701 IF (g_asn_debug = 'Y') THEN
15702 asn_debug.put_line('Exception occured in get_deliver_to_person_from_rt');
15703 END IF;
15704 return null;
15705 END get_deliver_to_person_from_rt;
15706
15707 /* Function get_deliver_to_person_from_rti() is added as part of Bug#6375015 fix.
15708 This function is called from validate_vendor_rcv_line() and it tries to default
15709 the deliver_to_person_id mentioned in the parent transaction(i.e from rcv_transactions_interface).
15710 */
15711
15712 FUNCTION get_deliver_to_person_from_rti(
15713 x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15714 n IN BINARY_INTEGER
15715 ) RETURN NUMBER IS
15716 l_parent_deliver_to_person_id NUMBER := null;
15717 BEGIN
15718 select deliver_to_person_id
15719 into l_parent_deliver_to_person_id
15720 from rcv_transactions_interface
15721 where interface_transaction_id = x_cascaded_table(n).parent_transaction_id;
15722
15723 IF (g_asn_debug = 'Y') THEN
15724 asn_debug.put_line('Got deliver_to_person_id of parent txn as:'||l_parent_deliver_to_person_id);
15725 END IF;
15726 return l_parent_deliver_to_person_id;
15727 EXCEPTION
15728 WHEN OTHERS then
15729 IF (g_asn_debug = 'Y') THEN
15730 asn_debug.put_line('Exception occured in get_deliver_to_person_from_rti');
15731 END IF;
15732 return null;
15733 END get_deliver_to_person_from_rti;
15734
15735 PROCEDURE validate_lcm_line
15736 ( x_cascaded_table IN OUT NOCOPY rcv_roi_preprocessor.cascaded_trans_tab_type,
15737 n IN binary_integer,
15738 x_asn_type IN rcv_headers_interface.asn_type%type,
15739 x_header_record IN rcv_roi_preprocessor.header_rec_type
15740 ) IS
15741
15742 l_pre_rcv_flag VARCHAR2(1);
15743 l_lcm_shipment_flag VARCHAR2(1);
15744 l_lsl_exists NUMBER := 0;
15745 l_rsl_qty NUMBER;
15746 l_rsl_uom rcv_shipment_lines.unit_of_measure%type;
15747 -- Bug 7607281
15748 l_po_currency po_headers_all.currency_code%type;
15749 l_po_rate_type po_headers_all.rate_type%type;
15750 l_po_rate_date po_headers_all.rate_date%type;
15751 l_sec_rsl_qty NUMBER;
15752 l_sec_rsl_uom rcv_shipment_lines.secondary_unit_of_measure%type;
15753 l_lsl_id NUMBER;
15754 l_rate NUMBER;
15755 l_po_rate NUMBER;
15756 v_sobid NUMBER;
15757 l_lcm_date rcv_shipment_headers.conversion_date%type;
15758 l_rate_override VARCHAR2(1);
15759 p_api_version NUMBER := 1.0;
15760 p_init_msg_list VARCHAR2(1);
15761 p_commit VARCHAR2(1);
15762 x_return_status VARCHAR2(1);
15763 x_msg_count NUMBER;
15764 x_msg_data VARCHAR2(2000);
15765 x_currency_code rcv_transactions.currency_code%type;
15766 x_currency_conversion_type rcv_transactions.currency_conversion_type%type;
15767 x_currency_conversion_rate NUMBER;
15768
15769 BEGIN
15770 IF (g_asn_debug = 'Y') THEN
15771 asn_debug.put_line('In validate_lcm_line');
15772 asn_debug.put_line('x_cascaded_table(n).error_status ' || x_cascaded_table(n).error_status);
15773 asn_debug.put_line('x_cascaded_table(n).transaction_type ' || x_cascaded_table(n).transaction_type);
15774 END IF;
15775
15776 IF (x_cascaded_table(n).error_status NOT IN('S', 'W')) THEN
15777 RETURN;
15778 END IF;
15779
15780 l_pre_rcv_flag := rcv_table_functions.is_pre_rcv_org(x_cascaded_table(n).to_organization_id);
15781 l_lcm_shipment_flag := rcv_table_functions.is_lcm_shipment (x_cascaded_table(n).po_line_location_id);
15782
15783 IF (g_asn_debug = 'Y') THEN
15784 asn_debug.put_line('x_cascaded_table(n).to_organization_id ' || x_cascaded_table(n).to_organization_id);
15785 asn_debug.put_line('l_pre_rcv_flag => ' || l_pre_rcv_flag);
15786 asn_debug.put_line('x_cascaded_table(n).po_line_location_id ' || x_cascaded_table(n).po_line_location_id);
15787 asn_debug.put_line('l_lcm_shipment_flag => ' || l_lcm_shipment_flag);
15788 asn_debug.put_line('x_asn_type => ' || x_asn_type);
15789 END IF;
15790
15791 IF (l_lcm_shipment_flag = 'Y') THEN
15792
15793 IF (x_cascaded_table(n).transaction_type not in ('SHIP','RECEIVE')) THEN
15794 IF (x_cascaded_table(n).lcm_shipment_line_id IS NULL) THEN
15795 --
15796 asn_debug.put_line('Error: lcm_shipment_line_id should not be null ');
15797 x_cascaded_table(n).error_status := 'E';
15798 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NOT_NULL', x_cascaded_table(n).error_message);
15799 rcv_error_pkg.set_token('COLUMN_NAME', 'LCM_SHIPMENT_LINE_ID');
15800 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
15801 --
15802 END IF;
15803 RETURN;
15804 END IF;
15805 IF (l_pre_rcv_flag = 'Y') THEN
15806 IF (x_asn_type = 'ASN') THEN
15807 --
15808 asn_debug.put_line('Error: ' || x_asn_type || ' is not supported as the org is pre-receive enabled ');
15809 x_cascaded_table(n).error_status := 'E';
15810 rcv_error_pkg.set_error_message('RCV_ASN_IMPORT_NOT_ALLOWED', x_cascaded_table(n).error_message);
15811 rcv_error_pkg.set_token('ASN_TYPE',x_asn_type);
15812 rcv_error_pkg.set_token('ORG_ID',x_cascaded_table(n).to_organization_id);
15813 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'ASN_TYPE',FALSE);
15814 RETURN;
15815 --
15816 END IF;
15817 IF (x_cascaded_table(n).lcm_shipment_line_id IS NULL) THEN
15818 --
15819 asn_debug.put_line('Error: lcm_shipment_line_id should not be null ');
15820 x_cascaded_table(n).error_status := 'E';
15821 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NOT_NULL', x_cascaded_table(n).error_message);
15822 rcv_error_pkg.set_token('COLUMN_NAME', 'LCM_SHIPMENT_LINE_ID');
15823 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
15824 RETURN;
15825 --
15826 END IF;
15827 IF (g_asn_debug = 'Y') THEN
15828 asn_debug.put_line('x_cascaded_table(n).lcm_shipment_line_id => ' || x_cascaded_table(n).lcm_shipment_line_id);
15829 END IF;
15830 IF (x_cascaded_table(n).unit_landed_cost IS NULL) THEN
15831 --
15832 asn_debug.put_line('Error: unit_landed_cost should not be null ');
15833 x_cascaded_table(n).error_status := 'E';
15834 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NOT_NULL', x_cascaded_table(n).error_message);
15835 rcv_error_pkg.set_token('COLUMN_NAME', 'UNIT_LANDED_COST');
15836 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'UNIT_LANDED_COST',FALSE);
15837 RETURN;
15838 --
15839 END IF;
15840 IF (g_asn_debug = 'Y') THEN
15841 asn_debug.put_line('x_cascaded_table(n).unit_landed_cost => ' || x_cascaded_table(n).unit_landed_cost);
15842 END IF;
15843 IF (x_asn_type = 'LCM') THEN /* LCM import */
15844 --
15845 SELECT count(1)
15846 INTO l_lsl_exists
15847 FROM rcv_shipment_lines
15848 WHERE lcm_shipment_line_id is not null
15849 AND lcm_shipment_line_id = x_cascaded_table(n).lcm_shipment_line_id;
15850
15851 asn_debug.put_line('Checking RSL: l_lsl_exists => ' || l_lsl_exists, null, 14);
15852
15853 IF (l_lsl_exists = 0) THEN
15854 SELECT count(1)
15855 INTO l_lsl_exists
15856 FROM rcv_transactions_interface
15857 WHERE lcm_shipment_line_id is not null
15858 AND lcm_shipment_line_id = x_cascaded_table(n).lcm_shipment_line_id
15859 AND processing_status_code = 'RUNNING'
15860 AND interface_transaction_id <> x_cascaded_table(n).interface_transaction_id;
15861
15862 asn_debug.put_line('Checking RTI: l_lsl_exists => ' || l_lsl_exists, null, 14);
15863 END IF;
15864
15865 IF (l_lsl_exists > 0) THEN
15866 --
15867 asn_debug.put_line('Error: Duplicate lcm_shipment_line_id');
15868 x_cascaded_table(n).error_status := 'E';
15869 rcv_error_pkg.set_error_message('RCV_DUP_LCM_SHIPMENT_LINE', x_cascaded_table(n).error_message);
15870 rcv_error_pkg.set_token('VALUE', x_cascaded_table(n).lcm_shipment_line_id);
15871 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
15872 RETURN;
15873 --
15874 END IF;
15875 --
15876 END IF;
15877 IF (x_cascaded_table(n).transaction_type = 'RECEIVE' AND
15878 x_cascaded_table(n).shipment_line_id IS NOT NULL) THEN
15879 -- We need to restrict partial receipts of LCM shipment.
15880 SELECT rsl.quantity_shipped,
15881 rsl.unit_of_measure,
15882 rsl.secondary_quantity_shipped,
15883 rsl.secondary_unit_of_measure,
15884 rsl.lcm_shipment_line_id
15885 INTO l_rsl_qty, l_rsl_uom, l_sec_rsl_qty, l_sec_rsl_uom, l_lsl_id
15886 FROM rcv_shipment_lines rsl
15887 WHERE rsl.shipment_line_id = x_cascaded_table(n).shipment_line_id;
15888 --
15889 IF (l_rsl_qty <> x_cascaded_table(n).quantity) THEN
15890 --
15891 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
15892 asn_debug.put_line('l_rsl_qty => ' || l_rsl_qty, null, 14);
15893 asn_debug.put_line('x_cascaded_table(n).quantity => ' || x_cascaded_table(n).quantity, null, 14);
15894 asn_debug.put_line('Error: Partial receipt not allowed');
15895 x_cascaded_table(n).error_status := 'E';
15896 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
15897 rcv_error_pkg.set_token('COLUMN', 'QUANTITY');
15898 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).quantity);
15899 rcv_error_pkg.set_token('SYS_VALUE', l_rsl_qty);
15900 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'QUANTITY',FALSE);
15901 RETURN;
15902 --
15903 END IF;
15904 IF (l_rsl_uom <> x_cascaded_table(n).unit_of_measure) THEN
15905 --
15906 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
15907 asn_debug.put_line('l_rsl_uom => ' || l_rsl_uom, null, 14);
15908 asn_debug.put_line('x_cascaded_table(n).unit_of_measure => ' || x_cascaded_table(n).unit_of_measure, null, 14);
15909 asn_debug.put_line('Error: Partial receipt not allowed');
15910 x_cascaded_table(n).error_status := 'E';
15911 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
15912 rcv_error_pkg.set_token('COLUMN', 'UNIT_OF_MEASURE');
15913 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).unit_of_measure);
15914 rcv_error_pkg.set_token('SYS_VALUE', l_rsl_uom);
15915 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'UNIT_OF_MEASURE',FALSE);
15916 RETURN;
15917 --
15918 END IF;
15919 -- Bug 7607281
15920 IF (nvl (l_sec_rsl_qty, -99) <> nvl(x_cascaded_table(n).secondary_quantity,-99)) THEN
15921 --
15922 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
15923 asn_debug.put_line('l_sec_rsl_qty => ' || l_sec_rsl_qty, null, 14);
15924 asn_debug.put_line('x_cascaded_table(n).secondary_quantity => ' || x_cascaded_table(n).secondary_quantity, null, 14);
15925 asn_debug.put_line('Error: Partial receipt not allowed');
15926 x_cascaded_table(n).error_status := 'E';
15927 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
15928 rcv_error_pkg.set_token('COLUMN', 'SECONDARY_QUANTITY');
15929 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).secondary_quantity);
15930 rcv_error_pkg.set_token('SYS_VALUE', l_sec_rsl_qty);
15931 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_QUANTITY',FALSE);
15932 RETURN;
15933 --
15934 END IF;
15935 --
15936 IF (nvl(l_sec_rsl_uom,'-99') <> nvl(x_cascaded_table(n).secondary_unit_of_measure,'-99')) THEN
15937 --
15938 asn_debug.put_line('x_cascaded_table(n).shipment_line_id => ' || x_cascaded_table(n).shipment_line_id, null, 14);
15939 asn_debug.put_line('l_sec_rsl_uom => ' || l_sec_rsl_uom, null, 14);
15940 asn_debug.put_line('x_cascaded_table(n).secondary_unit_of_measure => ' || x_cascaded_table(n).secondary_unit_of_measure, null, 14);
15941 asn_debug.put_line('Error: Partial receipt not allowed');
15942 x_cascaded_table(n).error_status := 'E';
15943 rcv_error_pkg.set_error_message('RCV_INVALID_ROI_VALUE', x_cascaded_table(n).error_message);
15944 rcv_error_pkg.set_token('COLUMN', 'SECONDARY_UNIT_OF_MEASURE');
15945 rcv_error_pkg.set_token('ROI_VALUE', x_cascaded_table(n).secondary_unit_of_measure);
15946 rcv_error_pkg.set_token('SYS_VALUE', l_sec_rsl_uom);
15947 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
15948 RETURN;
15949 --
15950 END IF;
15951 -- Bug 7607281
15952 SELECT currency_code, rate_type, rate_date, rate
15953 INTO l_po_currency, l_po_rate_type, l_po_rate_date, l_po_rate
15954 FROM po_headers_all
15955 WHERE po_header_id = x_cascaded_table(n).po_header_id;
15956
15957 IF (g_asn_debug = 'Y') THEN
15958 asn_debug.put_line('l_po_currency : ' || l_po_currency);
15959 asn_debug.put_line('l_po_rate_type: ' || l_po_rate_type);
15960 asn_debug.put_line('l_po_rate_date: ' || l_po_rate_date);
15961 asn_debug.put_line('l_po_rate : ' || l_po_rate);
15962 END IF;
15963
15964 x_cascaded_table(n).currency_code := l_po_currency;
15965 x_cascaded_table(n).currency_conversion_type := l_po_rate_type;
15966
15967 IF (l_po_rate_type IS NULL or l_po_rate_type <> 'User') THEN
15968
15969 inl_integration_grp.Get_CurrencyInfo
15970 ( p_api_version => p_api_version,
15971 p_init_msg_list => p_init_msg_list,
15972 p_commit => p_commit,
15973 p_ship_line_id => l_lsl_id,
15974 x_return_status => x_return_status,
15975 x_msg_count => x_msg_count,
15976 x_msg_data => x_msg_data,
15977 x_currency_code => x_currency_code,
15978 x_currency_conversion_type => x_currency_conversion_type,
15979 x_currency_conversion_date => l_lcm_date,
15980 x_currency_conversion_rate => x_currency_conversion_rate );
15981
15982 IF (l_lcm_date IS NULL) Then
15983 x_cascaded_table(n).error_status := 'E';
15984 rcv_error_pkg.set_error_message('RCV_LCM_CURRENCY_DATE_NULL', x_cascaded_table(n).error_message);
15985 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'SECONDARY_UNIT_OF_MEASURE',FALSE);
15986 RETURN;
15987 END IF;
15988
15989 asn_debug.put_line('x_cascaded_table(n).currency_conversion_date : ' || x_cascaded_table(n).currency_conversion_date);
15990 asn_debug.put_line('l_lcm_date returned by INL API : ' || l_lcm_date);
15991 x_cascaded_table(n).currency_conversion_date := l_lcm_date;
15992
15993 IF (l_po_rate_type IS NOT NULL) THEN
15994
15995 SELECT set_of_books_id
15996 into v_sobid
15997 FROM financials_system_params_all
15998 WHERE org_id = (SELECT org_id FROM po_line_locations_all
15999 WHERE line_location_id = x_cascaded_table(n).po_line_location_id);
16000
16001 l_rate := gl_currency_api.get_rate(v_sobid, l_po_currency, l_lcm_date, l_po_rate_type);
16002
16003 asn_debug.put_line('x_cascaded_table(n).currency_conversion_rate : ' || x_cascaded_table(n).currency_conversion_rate);
16004 asn_debug.put_line('l_rate calculated : ' || l_rate);
16005
16006 x_cascaded_table(n).currency_conversion_rate := l_rate;
16007 END IF;
16008 ELSE
16009 x_cascaded_table(n).currency_conversion_date := l_po_rate_date;
16010
16011 l_rate_override := NVL(fnd_profile.value('ALLOW_RATE_OVERRIDE_FOR_USER_RATE_TYPE'), 'N');
16012 asn_debug.put_line('l_rate_override => ' || l_rate_override, null, 14);
16013
16014 IF (l_rate_override = 'N' OR x_cascaded_table(n).currency_conversion_rate IS NULL) THEN
16015 x_cascaded_table(n).currency_conversion_rate := l_po_rate;
16016 END IF;
16017
16018 END IF;
16019
16020 END IF;
16021 END IF;
16022 ELSE
16023 IF (x_asn_type = 'LCM') THEN
16024 --
16025 asn_debug.put_line('Error: Non-lcm shipment line cannot be attached to an LCM shipment');
16026 x_cascaded_table(n).error_status := 'E';
16027 rcv_error_pkg.set_error_message('RCV_INVALID_LCM_SHIPMENT', x_cascaded_table(n).error_message);
16028 rcv_error_pkg.set_token('SHIPMENT', x_header_record.header_record.shipment_num);
16029 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'PO_LINE_LOCATION_ID',FALSE);
16030 RETURN;
16031 --
16032 END IF;
16033 IF (x_cascaded_table(n).lcm_shipment_line_id IS NOT NULL) THEN
16034 --
16035 asn_debug.put_line('Error: lcm_shipment_line_id should be null for a non-lcm shipment');
16036 x_cascaded_table(n).error_status := 'E';
16037 rcv_error_pkg.set_error_message('PO_PDOI_COLUMN_NULL', x_cascaded_table(n).error_message);
16038 rcv_error_pkg.set_token('COLUMN_NAME', 'LCM_SHIPMENT_LINE_ID');
16039 rcv_error_pkg.set_token('VALUE', x_cascaded_table(n).lcm_shipment_line_id);
16040 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
16041 RETURN;
16042 --
16043 END IF;
16044
16045 END IF;
16046
16047 IF (g_asn_debug = 'Y') THEN
16048 asn_debug.put_line('Exitting validate_lcm_line');
16049 END IF;
16050
16051 EXCEPTION
16052 WHEN OTHERS THEN
16053 x_cascaded_table(n).error_status := rcv_error_pkg.g_ret_sts_unexp_error;
16054 rcv_error_pkg.set_sql_error_message('validate_lcm_line' , '000');
16055 x_cascaded_table(n).error_message := rcv_error_pkg.get_last_message;
16056 rcv_error_pkg.log_interface_message(x_cascaded_table(n).error_status,'LCM_SHIPMENT_LINE_ID',FALSE);
16057
16058 IF (g_asn_debug = 'Y') THEN
16059 asn_debug.put_line('Unexpected exception in validate_lcm_line: ' || SQLERRM);
16060 END IF;
16061
16062 END validate_lcm_line;
16063
16064 END rcv_roi_transaction;