[Home] [Help]
PACKAGE BODY: APPS.CSI_ORDER_SHIP_PUB
Source
1 PACKAGE BODY csi_order_ship_pub AS
2 /* $Header: csipiosb.pls 120.34.12010000.2 2008/10/01 17:54:03 rsinn ship $ */
3
4
5 PROCEDURE debug(
6 p_message IN varchar2)
7 IS
8 BEGIN
9 IF csi_t_gen_utility_pvt.g_debug_level > 0 THEN
10 csi_t_gen_utility_pvt.add(p_message);
11 END IF;
12 END debug;
13
14 PROCEDURE api_log(
15 p_api_name IN varchar2)
16 IS
17 BEGIN
18
19 g_api_name := 'csi_order_ship_pub.'||p_api_name;
20
21 csi_t_gen_utility_pvt.dump_api_info(
22 p_api_name => p_api_name,
23 p_pkg_name => 'csi_order_ship_pub');
24
25 END api_log;
26
27 PROCEDURE process_ato_options(
28 p_order_line_rec IN order_line_rec,
29 x_return_status OUT NOCOPY varchar2)
30 IS
31 CURSOR ato_option_cur(p_ato_line_id in number) IS
32 SELECT oel.line_id
33 FROM mtl_system_items msi,
34 oe_order_lines_all oel
35 WHERE oel.ato_line_id = p_ato_line_id
36 AND oel.item_type_code = 'OPTION'
37 AND nvl(oel.cancelled_flag,'N') <> 'Y'
38 AND msi.inventory_item_id = oel.inventory_item_id
39 AND msi.organization_id = p_order_line_rec.om_vld_org_id
40 AND nvl(msi.comms_nl_trackable_flag, 'N') = 'Y'
41 AND nvl(msi.shippable_item_flag, 'N') = 'Y';
42
43 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
44 l_error_message varchar2(2000);
45 l_already_interfaced varchar2(1);
46 l_bypass varchar2(1);
47
48 l_error_code number;
49 l_message_id number;
50 l_error_rec csi_datastructures_pub.transaction_error_rec;
51
52 BEGIN
53
54 api_log('process_ato_options');
55
56 x_return_status := fnd_api.g_ret_sts_success;
57
58 IF nvl(p_order_line_rec.ato_line_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
59 THEN
60
61 l_bypass := nvl(fnd_profile.value('CSE_BYPASS_EVENT_QUEUE'), 'N');
62
63 FOR ato_option_rec IN ato_option_cur(p_order_line_rec.ato_line_id)
64 LOOP
65
66 IF l_bypass = 'N' THEN
67
68 debug(' Publishing CSISOFUL for option line :'||ato_option_rec.line_id);
69
70 XNP_CSISOFUL_U.publish(
71 xnp$order_line_id => ato_option_rec.line_id,
72 x_message_id => l_message_id,
73 x_error_code => l_error_code,
74 x_error_message => l_error_message);
75 ELSE
76
77 debug(' Invoking CSISOFUL for option line :'||ato_option_rec.line_id);
78
79 l_error_rec.source_id := ato_option_rec.line_id;
80 l_error_rec.source_type := 'CSISOFUL';
81 l_error_rec.transaction_type_id := 51;
82
83 csi_inv_txnstub_pkg.execute_trx_dpl(
84 p_transaction_type => 'CSISOFUL',
85 p_transaction_id => ato_option_rec.line_id,
86 x_trx_return_status => l_return_status,
87 x_trx_error_rec => l_error_rec);
88
89 IF l_return_status <> fnd_api.g_ret_sts_success THEN
90 csi_inv_trxs_pkg.log_csi_error(l_error_rec);
91 l_return_status := fnd_api.g_ret_sts_success;
92 END IF;
93
94 END IF;
95
96 csi_t_gen_utility_pvt.build_file_name(
97 p_file_segment1 => 'csisoshp',
98 p_file_segment2 => p_order_line_rec.inv_mtl_transaction_id);
99
100 END LOOP;
101 END IF;
102
103 EXCEPTION
104 WHEN fnd_api.g_exc_error THEN
105 x_return_status := fnd_api.g_ret_sts_error;
106 END process_ato_options;
107
108 PROCEDURE create_dflt_td_from_ship(
109 p_serial_code IN number,
110 p_order_line_rec IN order_line_rec,
111 p_trackable_parent IN boolean,
112 px_order_shipment_tbl IN OUT NOCOPY order_shipment_tbl,
113 x_transaction_line_id OUT NOCOPY number,
114 x_return_status OUT NOCOPY varchar2)
115 IS
116
117 l_ship_tbl order_shipment_tbl;
118
119 l_c_ind binary_integer := 0;
120 l_c_tl_rec csi_t_datastructures_grp.txn_line_rec ;
121 l_c_tld_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
122 l_c_t_pty_tbl csi_t_datastructures_grp.txn_party_detail_tbl ;
123 l_c_t_pty_acct_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
124 l_c_t_oa_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
125 l_c_t_ea_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
126 l_c_t_sys_tbl csi_t_datastructures_grp.txn_systems_tbl;
127 l_c_t_iir_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
128
129 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
130
131 l_msg_count number;
132 l_msg_data varchar2(2000);
133 l_instance_party_id number;
134 l_ip_account_id number;
135 l_end_loop number;
136 l_quantity number;
137 l_parent_ord_qty number;
138 l_total_qty number := 0;
139
140 l_satisfied boolean := FALSE;
141
142 BEGIN
143
144 x_return_status := fnd_api.g_ret_sts_success;
145
146 api_log('create_dflt_td_from_ship');
147
148 l_ship_tbl := px_order_shipment_tbl;
149
150 /* Initialize the pl/sql tables */
151 l_c_tld_tbl.delete;
152 l_c_t_pty_tbl.delete;
153 l_c_t_pty_acct_tbl.delete;
154 l_c_t_oa_tbl.delete;
155 l_c_t_ea_tbl.delete;
156 l_c_t_sys_tbl.delete;
157 l_c_t_iir_tbl.delete;
158
159 -- assign values for the columns in Txn_line_rec
160 l_c_tl_rec.transaction_line_id := fnd_api.g_miss_num;
161 l_c_tl_rec.source_transaction_id := p_order_line_rec.order_line_id;
162 l_c_tl_rec.source_transaction_type_id := g_txn_type_id;
163 l_c_tl_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
164 l_c_tl_rec.processing_status := 'IN_PROCESS';
165 l_c_tl_rec.object_version_number := 1;
166
167 BEGIN
168 SELECT transaction_line_id
169 INTO l_c_tl_rec.transaction_line_id
170 FROM csi_t_transaction_lines
171 WHERE source_transaction_table = l_c_tl_rec.source_transaction_table
172 AND source_transaction_id = l_c_tl_rec.source_transaction_id
173 AND source_transaction_type_id = l_c_tl_rec.source_transaction_type_id;
174 EXCEPTION
175 WHEN no_data_found THEN
176 null;
177 END;
178
179 IF l_ship_tbl.count > 0 THEN
180
181 FOR s_ind in l_ship_tbl.FIRST .. l_ship_tbl.LAST
182 LOOP
183
184 IF p_serial_code <> 1 OR p_trackable_parent THEN
185 l_end_loop := l_ship_tbl(s_ind).shipped_quantity;
186 l_quantity := 1;
187 ELSE
188
189 IF nvl(p_order_line_rec.link_to_line_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
190
191 -- create tld records with respect to the parent/child ratio
192 SELECT ordered_quantity
193 INTO l_parent_ord_qty
194 FROM oe_order_lines_all
195 WHERE line_id = p_order_line_rec.link_to_line_id;
196
197 l_end_loop := l_parent_ord_qty;
198 l_quantity := p_order_line_rec.ordered_quantity/l_parent_ord_qty;
199
200 ELSE
201 l_end_loop := 1;
202 l_quantity := l_ship_tbl(s_ind).shipped_quantity;
203 END IF;
204
205 END IF;
206
207 SELECT instance_party_id
208 INTO l_instance_party_id
209 FROM csi_i_parties
210 WHERE instance_id = l_ship_tbl(s_ind).instance_id
211 AND relationship_type_code = 'OWNER';
212
213 BEGIN
214 SELECT ip_account_id
215 INTO l_ip_account_id
216 FROM csi_ip_accounts
217 WHERE instance_party_id = l_instance_party_id
218 AND relationship_type_code = 'OWNER';
219 EXCEPTION
220 WHEN no_data_found THEN
221 l_ip_account_id := fnd_api.g_miss_num;
222 END;
223
224 l_satisfied := FALSE;
225
226 FOR q_ind IN 1..l_end_loop
227 LOOP
228
229 IF p_serial_code = 1 AND NOT(p_trackable_parent)
230 AND
231 nvl(p_order_line_rec.link_to_line_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num
232 THEN
233 l_total_qty := l_total_qty + l_quantity;
234
235 IF l_total_qty = l_ship_tbl(s_ind).shipped_quantity THEN
236 l_satisfied := TRUE;
237 ELSIF l_total_qty > l_ship_tbl(s_ind).shipped_quantity THEN
238 l_quantity := l_ship_tbl(s_ind).shipped_quantity - (l_quantity*(q_ind-1));
239 l_satisfied := TRUE;
240 END IF;
241 END IF;
242
243 l_c_ind := l_c_ind + 1;
244
245 -- assign values for the columns in txn_line_details_tbl
246 l_c_tld_tbl(l_c_ind).instance_id := l_ship_tbl(s_ind).instance_id;
247 l_c_tld_tbl(l_c_ind).instance_exists_flag := 'Y';
248 l_c_tld_tbl(l_c_ind).source_transaction_flag := 'Y';
249 l_c_tld_tbl(l_c_ind).sub_type_id := g_dflt_sub_type_id ;
250 l_c_tld_tbl(l_c_ind).inventory_item_id := l_ship_tbl(s_ind).inventory_item_id;
251 l_c_tld_tbl(l_c_ind).inv_organization_id := l_ship_tbl(s_ind).organization_id;
252 l_c_tld_tbl(l_c_ind).inventory_revision := l_ship_tbl(s_ind).revision;
253 l_c_tld_tbl(l_c_ind).item_condition_id := fnd_api.g_miss_num;
254 l_c_tld_tbl(l_c_ind).instance_type_code := fnd_api.g_miss_char;
255 l_c_tld_tbl(l_c_ind).unit_of_measure := l_ship_tbl(s_ind).transaction_uom;
256 l_c_tld_tbl(l_c_ind).serial_number := l_ship_tbl(s_ind).serial_number;
257 l_c_tld_tbl(l_c_ind).quantity := l_quantity;
258 l_c_tld_tbl(l_c_ind).lot_number := l_ship_tbl(s_ind).lot_number;
259 l_c_tld_tbl(l_c_ind).location_type_code := 'HZ_PARTY_SITES';
260 l_c_tld_tbl(l_c_ind).location_id := p_order_line_rec.ship_to_party_site_id;
261 l_c_tld_tbl(l_c_ind).sellable_flag := 'Y';
262 l_c_tld_tbl(l_c_ind).active_start_date := sysdate;
263 l_c_tld_tbl(l_c_ind).object_version_number := 1;
264 l_c_tld_tbl(l_c_ind).preserve_detail_flag := 'Y';
265 l_c_tld_tbl(l_c_ind).processing_status := 'IN_PROCESS';
266
267 IF p_serial_code <> 1 THEN
268 l_c_tld_tbl(l_c_ind).mfg_serial_number_flag := 'Y';
269 ELSE
270 l_c_tld_tbl(l_c_ind).mfg_serial_number_flag := 'N';
271 END IF;
272
273 -- assign party record values
274 l_c_t_pty_tbl(l_c_ind).instance_party_id := l_instance_party_id;
275 l_c_t_pty_tbl(l_c_ind).party_source_id := l_ship_tbl(s_ind).party_id;
276 l_c_t_pty_tbl(l_c_ind).party_source_table := 'HZ_PARTIES';
277 l_c_t_pty_tbl(l_c_ind).relationship_type_code := 'OWNER';
278 l_c_t_pty_tbl(l_c_ind).contact_flag := 'N';
279 l_c_t_pty_tbl(l_c_ind).active_start_date := sysdate;
280 l_c_t_pty_tbl(l_c_ind).preserve_detail_flag := 'Y';
281 l_c_t_pty_tbl(l_c_ind).object_version_number := 1;
282 l_c_t_pty_tbl(l_c_ind).txn_line_details_index := l_c_ind;
283
284 -- assign party account values
285 l_c_t_pty_acct_tbl(l_c_ind).ip_account_id := l_ip_account_id;
286 l_c_t_pty_acct_tbl(l_c_ind).account_id := l_ship_tbl(s_ind).party_account_id;
287 l_c_t_pty_acct_tbl(l_c_ind).bill_to_address_id := l_ship_tbl(s_ind).invoice_to_org_id;
288 l_c_t_pty_acct_tbl(l_c_ind).ship_to_address_id := l_ship_tbl(s_ind).ship_to_org_id;
289 l_c_t_pty_acct_tbl(l_c_ind).relationship_type_code := 'OWNER';
290 l_c_t_pty_acct_tbl(l_c_ind).active_start_date := sysdate;
291 l_c_t_pty_acct_tbl(l_c_ind).preserve_detail_flag := 'Y';
292 l_c_t_pty_acct_tbl(l_c_ind).object_version_number := 1;
293 l_c_t_pty_acct_tbl(l_c_ind).txn_party_details_index := l_c_ind;
294
295 -- assign org assignment values
296 IF nvl(l_ship_tbl(s_ind).sold_from_org_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num
297 THEN
298
299 l_c_t_oa_tbl(l_c_ind).txn_operating_unit_id := fnd_api.g_miss_num;
300 l_c_t_oa_tbl(l_c_ind).txn_line_detail_id := fnd_api.g_miss_num;
301 l_c_t_oa_tbl(l_c_ind).instance_ou_id := fnd_api.g_miss_num;
302 l_c_t_oa_tbl(l_c_ind).operating_unit_id := l_ship_tbl(s_ind).sold_from_org_id;
303 l_c_t_oa_tbl(l_c_ind).relationship_type_code := 'SOLD_FROM';
304 l_c_t_oa_tbl(l_c_ind).active_start_date := sysdate;
305 l_c_t_oa_tbl(l_c_ind).preserve_detail_flag := 'Y';
306 l_c_t_oa_tbl(l_c_ind).txn_line_details_index := l_c_ind;
307 l_c_t_oa_tbl(l_c_ind).object_version_number := 1;
308 END IF;
309
310 -- assign the txn details in the shipping pl/sql table
311 l_ship_tbl(s_ind).txn_dtls_qty := l_c_tld_tbl(l_c_ind).quantity;
312 l_ship_tbl(s_ind).instance_match := 'Y';
313 l_ship_tbl(s_ind).quantity_match := 'Y';
314
315 IF l_satisfied THEN
316 exit;
317 END IF;
318
319 END LOOP;
320 END LOOP;
321
322 debug(' l_c_tld_tbl.count :'||l_c_tld_tbl.count);
323 debug(' l_c_t_pty_tbl.count :'||l_c_t_pty_tbl.count);
324 debug(' l_c_t_pty_acct_tbl.count :'||l_c_t_pty_acct_tbl.count);
325 debug(' l_c_t_iir_tbl.count :'||l_c_t_iir_tbl.count);
326 debug(' l_c_t_oa_tbl.count :'||l_c_t_oa_tbl.count);
327 debug(' l_c_t_ea_tbl.count :'||l_c_t_ea_tbl.count);
328 debug(' l_c_t_sys_tbl.count :'||l_c_t_sys_tbl.count);
329
330 csi_t_txn_details_grp.create_transaction_dtls(
331 p_api_version => 1.0,
332 p_commit => fnd_api.g_false,
333 p_init_msg_list => fnd_api.g_true,
334 p_validation_level => fnd_api.g_valid_level_none,
335 px_txn_line_rec => l_c_tl_rec,
336 px_txn_line_detail_tbl => l_c_tld_tbl,
337 px_txn_party_detail_tbl => l_c_t_pty_tbl,
338 px_txn_pty_acct_detail_tbl => l_c_t_pty_acct_tbl,
339 px_txn_ii_rltns_tbl => l_c_t_iir_tbl,
340 px_txn_org_assgn_tbl => l_c_t_oa_tbl,
341 px_txn_ext_attrib_vals_tbl => l_c_t_ea_tbl,
342 px_txn_systems_tbl => l_c_t_sys_tbl,
343 x_return_status => l_return_status,
344 x_msg_count => l_msg_count,
345 x_msg_data => l_msg_data);
346
347 IF l_return_status <> fnd_api.g_ret_sts_success THEN
348 RAISE fnd_api.g_exc_error;
349 END IF;
350
351 x_transaction_line_id := l_c_tl_rec.transaction_line_id;
352
353 END IF;
354
355 EXCEPTION
356 WHEN fnd_api.g_exc_error THEN
357 x_return_status := fnd_api.g_ret_sts_error;
358 END create_dflt_td_from_ship;
359
360
361 /* sync tld quantities with sales order quantity */
362 PROCEDURE sync_tld_and_order(
363 p_order_line_rec IN order_line_rec,
364 x_return_status OUT NOCOPY varchar2)
365 IS
366 l_transaction_line_id number;
367 l_total_tld_quantity number;
368 l_diff_quantity number;
369
370 l_src_change_owner_to_code varchar2(1);
371 l_src_change_owner varchar2(1);
372
373 l_c_tld_rec csi_t_datastructures_grp.txn_line_detail_rec ;
374 l_c_tpd_tbl csi_t_datastructures_grp.txn_party_detail_tbl ;
375 l_c_tpad_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
376 l_c_toa_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
377 l_c_teav_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
378 l_c_ts_tbl csi_t_datastructures_grp.txn_systems_tbl;
379 l_c_tiir_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
380
381 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
382 l_msg_count number;
383 l_msg_data varchar2(2000);
384
385 BEGIN
386
387 x_return_status := fnd_api.g_ret_sts_success;
388
389 BEGIN
390
391 SELECT transaction_line_id
392 INTO l_transaction_line_id
393 FROM csi_t_transaction_lines
394 WHERE source_transaction_table = 'OE_ORDER_LINES_ALL'
395 AND source_transaction_id = p_order_line_rec.order_line_id;
396
397 SELECT sum(abs(quantity))
398 INTO l_total_tld_quantity
399 FROM csi_t_txn_line_details
400 WHERE transaction_line_id = l_transaction_line_id
401 AND source_transaction_flag = 'Y';
402
403 IF l_total_tld_quantity < p_order_line_rec.ordered_quantity THEN
404
405 -- now sync the dif
406 l_diff_quantity := p_order_line_rec.ordered_quantity - l_total_tld_quantity;
407 debug('diff quantity :'|| l_diff_quantity);
408
409 l_c_tld_rec.source_transaction_flag := 'Y';
410 l_c_tld_rec.instance_exists_flag := 'N';
411 l_c_tld_rec.sub_type_id := g_dflt_sub_type_id;
412 l_c_tld_rec.transaction_line_id := l_transaction_line_id;
413 l_c_tld_rec.txn_line_detail_id := fnd_api.g_miss_num;
414 l_c_tld_rec.inventory_item_id := p_order_line_rec.inv_item_id;
415 l_c_tld_rec.inv_organization_id := p_order_line_rec.inv_org_id;
416 l_c_tld_rec.quantity := l_diff_quantity;
417 l_c_tld_rec.unit_of_measure := p_order_line_rec.order_quantity_uom;
418 l_c_tld_rec.object_version_number := 1;
419 l_c_tld_rec.processing_status := 'SUBMIT';
420
421 SELECT src_change_owner,
422 src_change_owner_to_code
423 INTO l_src_change_owner,
424 l_src_change_owner_to_code
425 FROM csi_ib_txn_types
426 WHERE sub_type_id = l_c_tld_rec.sub_type_id;
427
428 IF l_src_change_owner = 'Y' AND l_src_change_owner_to_code = 'E' THEN
429
430 l_c_tpd_tbl(1).txn_party_detail_id := fnd_api.g_miss_num;
431
432 SELECT party_id
433 INTO l_c_tpd_tbl(1).party_source_id
434 FROM hz_cust_accounts
435 WHERE cust_account_id = p_order_line_rec.customer_id;
436
437 l_c_tpd_tbl(1).party_source_table := 'HZ_PARTIES';
438 l_c_tpd_tbl(1).relationship_type_code := 'OWNER';
439 l_c_tpd_tbl(1).contact_flag := 'N';
440 l_c_tpd_tbl(1).active_start_date := sysdate;
441 l_c_tpd_tbl(1).object_version_number := 1;
442 l_c_tpd_tbl(1).txn_line_details_index := 1;
443
444
445 l_c_tpad_tbl(1).txn_account_detail_id := fnd_api.g_miss_num;
446 l_c_tpad_tbl(1).account_id := p_order_line_rec.customer_id;
447 l_c_tpad_tbl(1).relationship_type_code := 'OWNER';
448 l_c_tpad_tbl(1).active_start_date := sysdate;
449 l_c_tpad_tbl(1).object_version_number := 1;
450 l_c_tpad_tbl(1).txn_party_details_index := 1;
451
452 END IF;
453
454 -- call api to create the transaction line details
455 csi_t_txn_line_dtls_pvt.create_txn_line_dtls(
456 p_api_version => 1.0 ,
457 p_commit => fnd_api.g_false,
458 p_init_msg_list => fnd_api.g_true,
459 p_validation_level => fnd_api.g_valid_level_none,
460 p_txn_line_dtl_index => 1,
461 p_txn_line_dtl_rec => l_c_tld_rec,
462 px_txn_party_dtl_tbl => l_c_tpd_tbl,
463 px_txn_pty_acct_detail_tbl => l_c_tpad_tbl,
464 px_txn_ii_rltns_tbl => l_c_tiir_tbl,
465 px_txn_org_assgn_tbl => l_c_toa_tbl,
466 px_txn_ext_attrib_vals_tbl => l_c_teav_tbl,
467 x_return_status => l_return_status,
468 x_msg_count => l_msg_count,
469 x_msg_data => l_msg_data);
470
471 IF l_return_status <> fnd_api.g_ret_sts_success THEN
472 RAISE fnd_api.g_exc_error;
473 END IF;
474
475 END IF;
476
477 EXCEPTION
478 WHEN no_data_found THEN
479 null;
480 END;
481
482 EXCEPTION
483 WHEN fnd_api.g_exc_error THEN
484 x_return_status := fnd_api.g_ret_sts_error;
485 END sync_tld_and_order;
486
487 /*--------------------------------------------------------------------*/
488 /* This is the main procedure to interface the order and installation */
489 /* details info in to oracle Install Base */
490 /*--------------------------------------------------------------------*/
491 PROCEDURE order_shipment(
492 p_mtl_transaction_id IN number,
493 p_message_id IN number,
494 x_return_status OUT NOCOPY varchar2,
495 px_trx_error_rec IN OUT NOCOPY csi_datastructures_pub.transaction_error_rec)
496 IS
497
498 l_trx_detail_exist boolean := FALSE;
499 l_copy_trx_detail_exist boolean := FALSE;
500
501 l_partial_ship boolean := FALSE;
502 l_qty_ratio number;
503 l_split_ord_line_id number;
504 l_trx_type_id number;
505 l_internal_party_id number;
506 l_trx_line_id number;
507 x_msg_count number;
508 x_msg_data varchar2(2000);
509
510 x_order_shipment_tbl order_shipment_tbl;
511 x_txn_line_query_rec csi_t_datastructures_grp.txn_line_query_rec ;
512 x_pricing_attb_tbl csi_datastructures_pub.pricing_attribs_tbl;
513
514 l_txn_line_query_rec csi_t_datastructures_grp.txn_line_query_rec;
515 l_txn_line_dtl_query_rec csi_t_datastructures_grp.txn_line_detail_query_rec;
516 l_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
517 l_transaction_line_rec csi_t_datastructures_grp.txn_line_rec;
518 l_tmp_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
519 l_order_line_rec order_line_rec;
520 l_trk_oe_line_tbl oe_order_pub.line_tbl_type;
521 l_trackable_parent boolean := FALSE;
522
523 l_txn_line_detail_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
524 l_txn_party_detail_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
525 l_txn_pty_acct_dtl_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
526 l_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
527 l_txn_ext_attrib_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
528 l_csi_ext_attribs_tbl csi_t_datastructures_grp.csi_ext_attribs_tbl;
529 l_csi_iea_values_tbl csi_t_datastructures_grp.csi_ext_attrib_vals_tbl;
530 l_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl ;
531 l_txn_systems_tbl csi_t_datastructures_grp.txn_systems_tbl;
532
533 l_src_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
534 l_new_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
535 l_trx_rec csi_datastructures_pub.transaction_rec;
536
537 l_copy_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
538
539 x_trx_sub_type_rec txn_sub_type_rec;
540 x_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
541 x_model_inst_tbl model_inst_tbl;
542
543 l_item_control_rec csi_order_ship_pub.item_control_rec;
544 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
545 l_msg_count number;
546 l_msg_data varchar2(2000);
547 l_temp_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
548 l_t_ii_indx NUMBER := 0;
549
550 l_error_rec csi_datastructures_pub.transaction_error_rec;
551 l_parent_line_qty NUMBER := fnd_api.g_miss_num;
552 l_literal1 VARCHAR2(30) ;
553 l_literal2 VARCHAR2(30) ;
554 l_source_header_rec csi_interface_pkg.source_header_rec;
555 l_source_line_rec csi_interface_pkg.source_line_rec;
556 l_conv_to_prim_uom_req VARCHAR2(1) := 'Y';
557 --Added for bug 5194812--
558 l_om_session_key csi_utility_grp.config_session_key;
559 l_macd_processing BOOLEAN := FALSE;
560
561
562 BEGIN
563
564 /* Standard Start of API savepoint */
565 savepoint order_shipment;
566
567 /* Initialize API return status to success */
568 x_return_status := fnd_api.g_ret_sts_success;
569 l_error_rec := px_trx_error_rec;
570
571 csi_t_gen_utility_pvt.build_file_name (
572 p_file_segment1 => 'csisoshp',
573 p_file_segment2 => p_mtl_transaction_id);
574
575 api_log('order_shipment');
576
577 debug(' Transaction Time : '||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
578 debug(' Transaction Type : Sales Order Shipment');
579 debug(' Transaction ID : '||p_mtl_transaction_id);
580
581 l_error_rec.source_id := p_mtl_transaction_id;
582
583 /* this routine checks if ib is active */
584 csi_utility_grp.check_ib_active;
585
586 /* get internal party id */
587 csi_utl_pkg.get_int_party(
588 x_int_party_id => l_internal_party_id,
589 x_return_status => l_return_status);
590
591 IF l_return_status <> fnd_api.g_ret_sts_success THEN
592 raise fnd_api.g_exc_error;
593 END IF;
594
595 -- Get the order line details
596 csi_utl_pkg.get_order_line_dtls(
597 p_mtl_transaction_id => p_mtl_transaction_id,
598 x_order_line_rec => l_order_line_rec,
599 x_return_status => l_return_status);
600
601 IF l_return_status <> fnd_api.g_ret_sts_success THEN
602 raise fnd_api.g_exc_error;
603 END IF;
604
605 --Code start for bug 5194812--
606 l_om_session_key.session_hdr_id := l_order_line_rec.config_header_id;
607 l_om_session_key.session_rev_num := l_order_line_rec.config_rev_nbr;
608 l_om_session_key.session_item_id := l_order_line_rec.configuration_id;
609 --
610 l_macd_processing := csi_interface_pkg.check_macd_processing
611 ( p_config_session_key => l_om_session_key,
612 x_return_status => l_return_status
613 );
614 --Code end for bug5194812--
615
616 IF l_order_line_rec.mtl_action_id = 1 and l_order_line_rec.mtl_src_type_id = 8 THEN
617 g_txn_type_id := 126;
618 ELSE
619 --- Added for bug 5194812
620 IF l_macd_processing THEN
621 g_txn_type_id := 401;
622 ELSE
623 g_txn_type_id := 51;
624 END IF;
625 --- Code end for bug 5194812
626 END IF;
627
628
629 dbms_application_info.set_client_info(l_order_line_rec.org_id);
630
631 csi_utl_pkg.get_item_control_rec(
632 p_mtl_txn_id => p_mtl_transaction_id,
633 x_item_control_rec => l_item_control_rec,
634 x_return_status => l_return_status);
635
636 IF l_return_status <> fnd_api.g_ret_sts_success THEN
637 RAISE fnd_api.g_exc_error;
638 END IF;
639
640 -- assign the values to l_order_line_rec
641 l_order_line_rec.inv_mtl_transaction_id := p_mtl_transaction_id;
642 l_order_line_rec.internal_party_id := l_internal_party_id;
643 l_order_line_rec.serial_code := l_item_control_rec.serial_control_code;
644 l_order_line_rec.reservable_type := l_item_control_rec.reservable_type;
645 l_order_line_rec.negative_balances_code := l_item_control_rec.negative_balances_code;
646 l_order_line_rec.bom_item_type := l_item_control_rec.bom_item_type;
647 l_order_line_rec.primary_uom := l_item_control_rec.primary_uom_code;
648
649 l_error_rec.source_header_ref := l_order_line_rec.order_number;
650 l_error_rec.source_header_ref_id := l_order_line_rec.header_id;
651 l_error_rec.source_line_ref := l_order_line_rec.line_number;
652 l_error_rec.source_line_ref_id := l_order_line_rec.order_line_id;
653 l_error_rec.inventory_item_id := l_item_control_rec.inventory_item_id;
654 l_error_rec.src_serial_num_ctrl_code := l_item_control_rec.serial_control_code;
655 l_error_rec.src_lot_ctrl_code := l_item_control_rec.lot_control_code;
656 l_error_rec.src_location_ctrl_code := l_item_control_rec.locator_control_code;
657 l_error_rec.src_rev_qty_ctrl_code := l_item_control_rec.revision_control_code;
658 l_error_rec.comms_nl_trackable_flag := l_item_control_rec.ib_trackable_flag;
659
660 IF NVL(l_order_line_rec.link_to_line_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
661
662 csi_utl_pkg.get_link_to_line_id (
663 x_link_to_line_id => l_order_line_rec.link_to_line_id,
664 x_return_status => l_return_status );
665
666 IF l_return_status <> fnd_api.g_ret_sts_success THEN
667 raise fnd_api.g_exc_error;
668 END IF;
669
670 END IF;
671
672 -- check if there is any ib trackable children for the current order line
673 csi_utl_pkg.get_ib_trackable_children(
674 p_order_line_rec => l_order_line_rec,
675 x_trackable_line_tbl => l_trk_oe_line_tbl,
676 x_return_status => l_return_status);
677
678 IF l_return_status <> fnd_api.g_ret_sts_success THEN
679 RAISE fnd_api.g_exc_error;
680 END IF;
681
682 IF l_trk_oe_line_tbl.COUNT > 0 THEN
683 l_trackable_parent := TRUE;
684 END IF;
685
686 /* getting the default sub type id */
687 csi_utl_pkg.get_dflt_sub_type_id(
688 p_transaction_type_id => g_txn_type_id,
689 x_sub_type_id => g_dflt_sub_type_id,
690 x_return_status => l_return_status);
691
692 IF l_return_status <> fnd_api.g_ret_sts_success THEN
693 raise fnd_api.g_exc_error;
694 END IF;
695
696 csi_utl_pkg.get_sub_type_rec(
697 p_sub_type_id => g_dflt_sub_type_id,
698 p_trx_type_id => g_txn_type_id,
699 x_trx_sub_type_rec => x_trx_sub_type_rec,
700 x_return_status => l_return_status) ;
701
702 IF l_return_status <> fnd_api.g_ret_sts_success THEN
703 raise fnd_api.g_exc_error;
704 END IF;
705
706 debug(' transaction_type_id: '||x_trx_sub_type_rec.trx_type_id );
707 debug(' default sub_type_id: '||x_trx_sub_type_rec.sub_type_id );
708
709 /* assign the parameter for txn_line_rec */
710 l_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
711 l_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
712
713 -- Check if txn details exist
714 l_trx_detail_exist := csi_t_txn_details_grp.check_txn_details_exist(
715 p_txn_line_rec => l_txn_line_rec );
716
717 IF l_trx_detail_exist THEN
718
719 debug('user entered installation details found.' );
720
721 --sync source tld quantites with order line quantity
722 sync_tld_and_order(
723 p_order_line_rec => l_order_line_rec,
724 x_return_status => l_return_status);
725
726 IF l_return_status <> fnd_api.g_ret_sts_success THEN
727 RAISE fnd_api.g_exc_error;
728 END IF;
729
730 /*------------------------------------------------*/
731 /* If the order line has a parent then create txn */
732 /* line dtls in the parent/child order qty ratio */
733 /* -----------------------------------------------*/
734
735 IF NVL(l_order_line_rec.link_to_line_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
736
737 debug('This is a child order line. Check model and cascade installation details.');
738
739 csi_utl_pkg.get_qty_ratio(
740 p_order_line_qty => l_order_line_rec.ordered_quantity,
741 p_order_item_id => l_order_line_rec.inv_item_id,
742 p_model_remnant_flag => l_order_line_rec.model_remnant_flag, --added for bug5096435
743 p_link_to_line_id => l_order_line_rec.link_to_line_id,
744 x_qty_ratio => l_qty_ratio ,
745 x_return_status => l_return_status );
746
747 IF x_return_status <> fnd_api.g_ret_sts_success THEN
748 raise fnd_api.g_exc_error;
749 END IF;
750
751 csi_utl_pkg.cascade_txn_dtls(
752 p_source_trx_id => l_order_line_rec.order_line_id,
753 p_source_trx_table => 'OE_ORDER_LINES_ALL',
754 p_ratio => l_qty_ratio,
755 x_return_status => x_return_status);
756
757 IF x_return_status <> fnd_api.g_ret_sts_success THEN
758 raise fnd_api.g_exc_error;
759 END IF;
760
761 END IF;
762
763
764 l_copy_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
765 l_copy_txn_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
766
767 debug('Concurrency check - Is installation details copied already?' );
768
769 -- Check if txn details exist
770 l_copy_trx_detail_exist := csi_t_txn_details_grp.check_txn_details_exist(
771 p_txn_line_rec => l_copy_txn_line_rec );
772
773 IF l_copy_trx_detail_exist THEN
774
775 debug(' Yes it is.' );
776
777 BEGIN
778 SELECT transaction_line_id
779 INTO l_trx_line_id
780 FROM csi_t_transaction_lines
781 WHERE source_transaction_id = l_copy_txn_line_rec.source_transaction_id
782 AND source_transaction_table = l_copy_txn_line_rec.source_transaction_table;
783
784 EXCEPTION
785 WHEN no_data_found THEN
786 fnd_message.set_name('CSI','CSI_INT_TRX_LINE_MISSING');
787 fnd_message.set_token('SOURCE_TRANSACTION_ID', l_copy_txn_line_rec.SOURCE_TRANSACTION_ID);
788 fnd_message.set_token('SOURCE_TRANSACTION_TABLE',l_copy_txn_line_rec.SOURCE_TRANSACTION_TABLE);
789 fnd_msg_pub.add;
790 raise fnd_api.g_exc_error;
791 END;
792
793 ELSE
794
795 debug(' No it is not. Copying installation details as WSH_DELIVERY_DETAILS.');
796
797 --Parameters for the source order line
798 l_src_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
799 l_src_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
800
801 --Parameters for the new source trx rec
802 l_new_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
803 l_new_txn_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
804 l_new_txn_line_rec.source_transaction_type_id := g_txn_type_id;
805
806
807 ---Added (Start) for m-to-m enhancements
808 l_new_txn_line_rec.source_txn_header_id := l_order_line_rec.header_id ;
809 ---Added (End) for m-to-m enhancements
810
811 csi_t_txn_details_pvt.copy_transaction_dtls(
812 p_api_version => 1.0,
813 p_commit => fnd_api.g_false,
814 p_init_msg_list => fnd_api.g_true,
815 p_validation_level => fnd_api.g_valid_level_none,
816 p_src_txn_line_rec => l_src_txn_line_rec,
817 px_new_txn_line_rec => l_new_txn_line_rec,
818 p_copy_parties_flag => fnd_api.g_true,
819 p_copy_pty_accts_flag => fnd_api.g_true,
820 p_copy_ii_rltns_flag => fnd_api.g_true,
821 p_copy_org_assgn_flag => fnd_api.g_true,
822 p_copy_ext_attribs_flag => fnd_api.g_true,
823 p_copy_txn_systems_flag => fnd_api.g_true,
824 x_return_status => x_return_status,
825 x_msg_count => x_msg_count,
826 x_msg_data => x_msg_data);
827
828 IF x_return_status <> fnd_api.g_ret_sts_success THEN
829 g_api_name := 'csi_t_txn_details_pvt.copy_transaction_dtls';
830 raise fnd_api.g_exc_error;
831 END IF;
832
833 l_trx_line_id := l_new_txn_line_rec.transaction_line_id;
834
835 ---Added (Start) for m-to-m enhancements
836 ---Now split the copied TLD's to one each.
837 IF l_item_control_rec.serial_control_code <> 1 OR l_trackable_parent THEN
838
839 debug('splitting the WSH txn details in to one each.' );
840
841 -- shegde 2769321 oe_orderlines_all changed to wsh_delivery_details
842 csi_utl_pkg.create_txn_dtls(
843 p_source_trx_id => l_order_line_rec.order_line_id,
844 p_source_trx_table => 'WSH_DELIVERY_DETAILS',
845 x_return_status => x_return_status );
846
847 IF x_return_status <> fnd_api.g_ret_sts_success THEN
848 raise fnd_api.g_exc_error;
849 END IF;
850
851 END IF;
852 ---Added (End) for m-to-m enhancements
853
854 END IF;
855
856 ELSE -- installation details not entered
857
858 debug('user entered installation details not found');
859
860 /*----------------------------------------------------------------*/
861 /* In case of option and config items, call cascade_model that */
862 /* will cascade the txn_line_details to option/ config lines */
863 /* from the txn line details entered for the top model */
864 /*----------------------------------------------------------------*/
865
866 IF NVL(l_order_line_rec.top_model_line_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
867
868 debug('component of a pto/ato model. cascade installation details from top model.');
869
870 csi_t_utilities_pvt.cascade_model(
871 p_model_line_id => l_order_line_rec.top_model_line_id,
872 x_return_status => l_return_status );
873
874 IF l_return_status <> fnd_api.g_ret_sts_success THEN
875 raise fnd_api.g_exc_error;
876 END IF;
877
878 l_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
879 l_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
880
881 debug('check if installation details are cascaded from the model ?');
882
883 -- Check if txn details exist
884 l_trx_detail_exist := csi_t_txn_details_grp.check_txn_details_exist(
885 p_txn_line_rec => l_txn_line_rec );
886
887 IF l_trx_detail_exist THEN
888
889 debug(' yes. cascaded from top model.');
890
891 /*------------------------------------------------*/
892 /* If the order line has a parent then create txn */
893 /* line dtls in the parent/child order qty ratio */
894 /* -----------------------------------------------*/
895
896 IF NVL(l_order_line_rec.link_to_line_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
897
898 csi_utl_pkg.get_qty_ratio(
899 p_order_line_qty => l_order_line_rec.ordered_quantity,
900 p_order_item_id => l_order_line_rec.inv_item_id,
901 p_model_remnant_flag => l_order_line_rec.model_remnant_flag, --added for bug5096435
902 p_link_to_line_id => l_order_line_rec.link_to_line_id,
903 x_qty_ratio => l_qty_ratio ,
904 x_return_status => l_return_status );
905
906 IF l_return_status <> fnd_api.g_ret_sts_success THEN
907 raise fnd_api.g_exc_error;
908 END IF;
909
910 csi_utl_pkg.cascade_txn_dtls(
911 p_source_trx_id => l_order_line_rec.order_line_id,
912 p_source_trx_table => 'OE_ORDER_LINES_ALL',
913 p_ratio => l_qty_ratio ,
914 x_return_status => l_return_status );
915
916 IF l_return_status <> fnd_api.g_ret_sts_success THEN
917 raise fnd_api.g_exc_error;
918 END IF;
919
920 END IF;--link_to_line_id <>fnd_api.g_miss_num
921
922 /* assign the parameter for txn_line_rec */
923 l_copy_txn_line_rec.SOURCE_TRANSACTION_ID := l_order_line_rec.order_line_id;
924 l_copy_txn_line_rec.SOURCE_TRANSACTION_TABLE := 'WSH_DELIVERY_DETAILS';
925
926 debug('concurrency check - is installation details copied already?' );
927
928 -- Check if txn details exist
929 l_copy_trx_detail_exist := csi_t_txn_details_grp.check_txn_details_exist(
930 p_txn_line_rec => l_copy_txn_line_rec );
931
932 IF l_copy_trx_detail_exist THEN
933 debug(' Yes it is.');
934 BEGIN
935 SELECT transaction_line_id
936 INTO l_trx_line_id
937 FROM csi_t_transaction_lines
938 WHERE source_transaction_id = l_copy_txn_line_rec.source_transaction_id
939 AND source_transaction_table = l_copy_txn_line_rec.source_transaction_table;
940 EXCEPTION
941 WHEN no_data_found THEN
942 fnd_message.set_name('CSI','CSI_INT_TRX_LINE_MISSING');
943 fnd_message.set_token('SOURCE_TRANSACTION_ID',
944 l_copy_txn_line_rec.SOURCE_TRANSACTION_ID);
945 fnd_message.set_token('SOURCE_TRANSACTION_TABLE',
946 l_copy_txn_line_rec.SOURCE_TRANSACTION_TABLE);
947 fnd_msg_pub.add;
948 raise fnd_api.g_exc_error;
949 END;
950 ELSE
951
952 debug(' No it is not. Copying installation details as WSH_DELIVERY_DETAILS.');
953
954 --Parameters for the source order line
955 l_src_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
956 l_src_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
957
958 --Parameters for the new source trx rec
959 l_new_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
960 l_new_txn_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
961 l_new_txn_line_rec.source_transaction_type_id := g_txn_type_id;
962
963 csi_t_txn_details_pvt.copy_transaction_dtls(
964 p_api_version => 1.0,
965 p_commit => fnd_api.g_false,
966 p_init_msg_list => fnd_api.g_true,
967 p_validation_level => fnd_api.g_valid_level_none,
968 p_src_txn_line_rec => l_src_txn_line_rec,
969 px_new_txn_line_rec => l_new_txn_line_rec,
970 p_copy_parties_flag => fnd_api.g_true,
971 p_copy_pty_accts_flag => fnd_api.g_true,
972 p_copy_ii_rltns_flag => fnd_api.g_true,
973 p_copy_org_assgn_flag => fnd_api.g_true,
974 p_copy_ext_attribs_flag => fnd_api.g_true,
975 p_copy_txn_systems_flag => fnd_api.g_true,
976 x_return_status => l_return_status,
977 x_msg_count => l_msg_count,
978 x_msg_data => l_msg_data);
979
980 IF l_return_status <> fnd_api.g_ret_sts_success THEN
981 g_api_name := 'csi_t_txn_details_pvt.copy_transaction_dtls';
982 raise fnd_api.g_exc_error;
983 END IF;
984
985 l_trx_line_id := l_new_txn_line_rec.transaction_line_id;
986
987 /* Copied the following code from IF condition above as part of fix for bug 3555078 */
988 ---Added (Start) for m-to-m enhancements
989 ---Now split the copied TLD's to one each.
990 IF l_item_control_rec.serial_control_code <> 1 OR l_trackable_parent THEN
991
992 debug('splitting the WSH txn details in to one each' );
993 -- shegde 2769321 oe_orderlines_all changed to wsh_delivery_details
994 csi_utl_pkg.create_txn_dtls(
995 p_source_trx_id => l_order_line_rec.order_line_id,
996 p_source_trx_table => 'WSH_DELIVERY_DETAILS',
997 x_return_status => l_return_status );
998
999 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1000 raise fnd_api.g_exc_error;
1001 END IF;
1002 END IF;
1003 ---Added (End) for m-to-m enhancements
1004 /* Copied the above code from IF condition above as part of fix for bug 3555078 */
1005
1006 END IF ; -- if NOT(l_copy_trx_detail_exist)
1007 END IF; -- if l_trx_detail_exist for option and model
1008 END IF; -- if item_type_code in (config,option)
1009 END IF; -- installation details entered check
1010
1011 /* get the splitted order line for partial shipment */
1012 IF l_trx_detail_exist then
1013
1014 debug('check if this is a partial shipment case.');
1015
1016 csi_utl_pkg.get_split_order_line(
1017 l_order_line_rec.order_line_id,
1018 l_order_line_rec.header_id,
1019 l_split_ord_line_id,
1020 l_return_status);
1021
1022 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1023 raise fnd_api.g_exc_error;
1024 END IF;
1025
1026 IF l_split_ord_line_id is not null THEN
1027
1028 l_partial_ship := TRUE;
1029
1030 debug(' Yes. split_order_line_id :'||l_split_ord_line_id);
1031
1032 l_order_line_rec.split_ord_line_id := l_split_ord_line_id;
1033
1034 /* assign the parameter for txn_line_rec */
1035 l_copy_txn_line_rec.source_transaction_id := l_split_ord_line_id;
1036 l_copy_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
1037
1038 debug('Check if copied installation details exist for the split order line?' );
1039
1040 l_copy_trx_detail_exist := csi_t_txn_details_grp.check_txn_details_exist(
1041 p_txn_line_rec => l_copy_txn_line_rec );
1042
1043 IF NOT(l_copy_trx_detail_exist) THEN
1044
1045 /*------------------------------------------------------------------------*/
1046 /* Copy the txn details with the same source for the splitted order line */
1047 /*------------------------------------------------------------------------*/
1048
1049 --Parameters for the source transaction
1050 l_src_txn_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
1051 l_src_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
1052
1053 --Parameters for the destination trx rec
1054 l_new_txn_line_rec.source_transaction_id := l_split_ord_line_id;
1055 l_new_txn_line_rec.source_transaction_table := 'OE_ORDER_LINES_ALL';
1056 l_new_txn_line_rec.source_transaction_type_id := g_txn_type_id;
1057 l_new_txn_line_rec.transaction_line_id := fnd_api.g_miss_num;
1058
1059 debug(' No. So copying installation details for the split order line.' );
1060
1061 csi_t_txn_details_pvt.copy_transaction_dtls(
1062 p_api_version => 1.0,
1063 p_commit => fnd_api.g_false,
1064 p_init_msg_list => fnd_api.g_true,
1065 p_validation_level => fnd_api.g_valid_level_none,
1066 p_src_txn_line_rec => l_src_txn_line_rec,
1067 px_new_txn_line_rec => l_new_txn_line_rec,
1068 p_copy_parties_flag => fnd_api.g_true,
1069 p_copy_pty_accts_flag => fnd_api.g_true,
1070 p_copy_ii_rltns_flag => fnd_api.g_true,
1071 p_copy_org_assgn_flag => fnd_api.g_true,
1072 p_copy_ext_attribs_flag => fnd_api.g_true,
1073 p_copy_txn_systems_flag => fnd_api.g_true,
1074 x_return_status => l_return_status,
1075 x_msg_count => l_msg_count,
1076 x_msg_data => l_msg_data);
1077
1078 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1079 g_api_name := 'csi_t_txn_details_pvt.copy_transaction_dtls';
1080 raise fnd_api.g_exc_error;
1081 END IF;
1082
1083 END IF; -- installation details check
1084 ELSE
1085 l_partial_ship := FALSE;
1086 debug(' No.');
1087 END IF; -- split line id check
1088 END IF; -- end if l_trx_line_detail_exists
1089
1090 l_order_line_rec.trx_line_id := l_trx_line_id;
1091
1092 --assign the values for the trx_rec
1093 l_trx_rec.source_header_ref_id := l_order_line_rec.header_id;
1094 l_trx_rec.source_header_ref := l_order_line_rec.order_number;
1095 l_trx_rec.source_line_ref_id := l_order_line_rec.order_line_id;
1096 l_trx_rec.source_line_ref := l_order_line_rec.line_number;
1097 l_trx_rec.inv_material_transaction_id := p_mtl_transaction_id;
1098 l_trx_rec.transaction_type_id := g_txn_type_id ;
1099 l_trx_rec.transaction_date := l_order_line_rec.transaction_date ;
1100 l_trx_rec.source_transaction_date := l_order_line_rec.transaction_date ;
1101 l_trx_rec.transaction_status_code := 'PENDING';
1102
1103 /* Create csi transaction and use this trx_rec for all ib transactions */
1104 csi_transactions_pvt.create_transaction(
1105 p_api_version => 1.0,
1106 p_commit => fnd_api.g_false,
1107 p_init_msg_list => fnd_api.g_true,
1108 p_validation_level => fnd_api.g_valid_level_full,
1109 p_success_if_exists_flag => 'Y',
1110 p_transaction_rec => l_trx_rec,
1111 x_return_status => l_return_status,
1112 x_msg_count => l_msg_count,
1113 x_msg_data => l_msg_data);
1114
1115 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1116 g_api_name := 'csi_transactions_pvt.create_transaction';
1117 raise fnd_api.g_exc_error;
1118 END IF;
1119
1120 debug('csi transaction_id :'||l_trx_rec.transaction_id);
1121
1122 /* -------------------------------------------------*/
1123 /* Match the txn details with shipment and */
1124 /* build the relationship for Component OF */
1125 /*--------------------------------------------------*/
1126
1127 -- Included Transaction rec as part of fix for Bug 2767338
1128 build_shtd_table(
1129 p_mtl_transaction_id => p_mtl_transaction_id,
1130 p_order_line_rec => l_order_line_rec,
1131 p_txn_sub_type_rec => x_trx_sub_type_rec,
1132 p_trx_detail_exist => l_trx_detail_exist,
1133 p_transaction_rec => l_trx_rec,
1134 p_trackable_parent => l_trackable_parent,
1135 x_order_shipment_tbl => x_order_shipment_tbl,
1136 px_error_rec => l_error_rec,
1137 x_return_status => l_return_status);
1138
1139 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1140 raise fnd_api.g_exc_error;
1141 END IF;
1142
1143 /* switch the non source transaction details to the IN_PROCESS status */
1144 --Assign the literals.. bug 4311676
1145 l_literal1 := 'PROCESSED';
1146 l_literal2 := 'WSH_DELIVERY_DETAILS';
1147
1148 UPDATE csi_t_txn_line_details
1149 SET processing_status = 'IN_PROCESS'
1150 WHERE transaction_line_id IN (
1151 SELECT transaction_line_id
1152 FROM csi_t_transaction_lines
1153 WHERE source_transaction_table = l_literal2
1154 AND source_transaction_id = l_order_line_rec.order_line_id)
1155 AND source_transaction_flag = 'N'
1156 AND processing_status <> l_literal1;
1157 --
1158 l_txn_line_query_rec.SOURCE_TRANSACTION_ID := l_order_line_rec.order_line_id;
1159 l_txn_line_query_rec.SOURCE_TRANSACTION_TABLE := 'WSH_DELIVERY_DETAILS';
1160 l_txn_line_dtl_query_rec.PROCESSING_STATUS := 'IN_PROCESS';
1161
1162 /* read all the matched txn line dtls and all the child tables for final processing */
1163
1164 debug('Installation details for the final process - Update Install Base.' );
1165
1166 csi_t_txn_details_grp.get_transaction_details (
1167 p_api_version => 1.0,
1168 p_commit => fnd_api.g_false,
1169 p_init_msg_list => fnd_api.g_true,
1170 p_validation_level => fnd_api.g_valid_level_full,
1171 p_txn_line_query_rec => l_txn_line_query_rec,
1172 p_txn_line_detail_query_rec => l_txn_line_dtl_query_rec,
1173 x_txn_line_detail_tbl => l_txn_line_detail_tbl,
1174 p_get_parties_flag => fnd_api.g_true,
1175 x_txn_party_detail_tbl => l_txn_party_detail_tbl,
1176 p_get_pty_accts_flag => fnd_api.g_true,
1177 x_txn_pty_acct_detail_tbl => l_txn_pty_acct_dtl_tbl,
1178 ---Added (Start) for m-to-m enhancements
1179 -- Let us not get relations here.
1180 -- get_ii_relations_tbl will get the relations at later stage
1181 p_get_ii_rltns_flag => fnd_api.g_false,
1182 ---Added (End) for m-to-m enhancements
1183 x_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
1184 p_get_org_assgns_flag => fnd_api.g_true,
1185 x_txn_org_assgn_tbl => l_txn_org_assgn_tbl,
1186 p_get_ext_attrib_vals_flag => fnd_api.g_true,
1187 x_txn_ext_attrib_vals_tbl => l_txn_ext_attrib_vals_tbl,
1188 p_get_csi_attribs_flag => fnd_api.g_false,
1189 x_csi_ext_attribs_tbl => l_csi_ext_attribs_tbl,
1190 p_get_csi_iea_values_flag => fnd_api.g_false,
1191 x_csi_iea_values_tbl => l_csi_iea_values_tbl,
1192 p_get_txn_systems_flag => fnd_api.g_true,
1193 x_txn_systems_tbl => l_txn_systems_tbl,
1194 x_return_status => l_return_status,
1195 x_msg_count => l_msg_count,
1196 x_msg_data => l_msg_data);
1197
1198 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1199 g_api_name := 'csi_t_txn_details_grp.get_transaction_details';
1200 raise fnd_api.g_exc_error;
1201 END IF;
1202
1203 debug(' txn_line_detail_tbl.count :'|| l_txn_line_detail_tbl.count );
1204 debug(' txn_party_detail_tbl.count :'|| l_txn_party_detail_tbl.count );
1205 debug(' txn_pty_acct_dtl_tbl.count :'|| l_txn_pty_acct_dtl_tbl.count );
1206 debug(' txn_org_assgn_tbl.count :'|| l_txn_org_assgn_tbl.count );
1207 debug(' txn_systems_tbl.count :'|| l_txn_systems_tbl.count );
1208 debug(' txn_ii_rltns_tbl.count :'|| l_txn_ii_rltns_tbl.count );
1209 debug(' txn_eav_tbl.count :'|| l_txn_ext_attrib_vals_tbl.count );
1210
1211 /*---------------------------------------------------*/
1212 /* Get the pricing attributes for the order line and */
1213 /* pass it to update_install_base */
1214 /*---------------------------------------------------*/
1215
1216 csi_utl_pkg.Get_Pricing_Attribs(
1217 p_line_id => l_order_line_rec.order_line_id,
1218 x_pricing_attb_tbl => x_pricing_attb_tbl,
1219 x_return_status => x_return_status );
1220
1221 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
1222 raise fnd_api.g_exc_error;
1223 END IF;
1224
1225 debug(' pricing_attb_tbl.count :'||x_pricing_attb_tbl.count ) ;
1226
1227 -- Added for bug 5101635
1228 l_conv_to_prim_uom_req := 'Y';
1229 IF l_txn_line_detail_tbl.count > 0 THEN
1230 FOR u in l_txn_line_detail_tbl.FIRST..l_txn_line_detail_tbl.LAST
1231 LOOP
1232 IF NVL(l_txn_line_detail_tbl(u).serial_number,fnd_api.g_miss_char) <> fnd_api.g_miss_char AND
1233 NVL(l_txn_line_detail_tbl(u).quantity,fnd_api.g_miss_num) = 1 THEN
1234 l_conv_to_prim_uom_req := 'N'; -- No UOM Conversion Required
1235 Exit;
1236 END IF;
1237 END LOOP;
1238 END IF;
1239 -- End bug 5101635
1240
1241 IF l_conv_to_prim_uom_req = 'Y' THEN -- Added for bug 5101635
1242 csi_utl_pkg.conv_to_prim_uom(
1243 p_inv_organization_id => l_order_line_rec.inv_org_id,
1244 p_inventory_item_id => l_order_line_rec.inv_item_id,
1245 p_uom => l_order_line_rec.order_quantity_uom,
1246 x_txn_line_dtl_tbl => l_txn_line_detail_tbl,
1247 x_return_status => x_return_status);
1248
1249 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
1250 raise fnd_api.g_exc_error;
1251 END IF;
1252 END IF;
1253
1254 --
1255 -- srramakr TSO with Equipment.
1256 -- If this is a MACD order line then we need to merge the Transaction details written by CZ and WSH
1257 -- For this, we call CSI_INTERFACE_PKG.Get_CZ_Relations.
1258 -- macd_order_line flag is set by Build_Shtd_Table routine.
1259 --
1260 IF l_order_line_rec.macd_order_line = FND_API.G_TRUE THEN
1261 l_source_line_rec.source_line_id := l_order_line_rec.order_line_id;
1262 --
1263 Csi_Interface_Pkg.Get_CZ_Relations
1264 ( p_source_header_rec => l_source_header_rec,
1265 p_source_line_rec => l_source_line_rec,
1266 px_txn_line_rec => l_transaction_line_rec,
1267 px_txn_line_dtl_tbl => l_txn_line_detail_tbl,
1268 x_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
1269 x_txn_eav_tbl => l_txn_ext_attrib_vals_tbl,
1270 x_return_status => x_return_status
1271 );
1272 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
1273 raise fnd_api.g_exc_error;
1274 END IF;
1275 END IF;
1276 --
1277 --
1278 l_transaction_line_rec := l_tmp_txn_line_rec;
1279 --
1280 l_transaction_line_rec.transaction_line_id := l_order_line_rec.trx_line_id;
1281 l_transaction_line_rec.source_transaction_id := l_order_line_rec.order_line_id;
1282 l_transaction_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
1283 l_transaction_line_rec.source_transaction_type_id := g_txn_type_id ;
1284
1285 /*--------------------------------------------------------*/
1286 /* Once the txn details are matched and COMPONENT-OF */
1287 /* relationships are build then Update instance in IB */
1288 /*--------------------------------------------------------*/
1289
1290 update_install_base(
1291 p_api_version => 1.0,
1292 p_commit => fnd_api.g_false,
1293 p_init_msg_list => fnd_api.g_true,
1294 p_validation_level => fnd_api.g_valid_level_full,
1295 p_txn_line_rec => l_transaction_line_rec,
1296 p_txn_line_detail_tbl => l_txn_line_detail_tbl,
1297 p_txn_party_detail_tbl => l_txn_party_detail_tbl,
1298 p_txn_pty_acct_dtl_tbl => l_txn_pty_acct_dtl_tbl,
1299 p_txn_org_assgn_tbl => l_txn_org_assgn_tbl,
1300 p_txn_ext_attrib_vals_tbl => l_txn_ext_attrib_vals_tbl,
1301 p_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
1302 p_txn_systems_tbl => l_txn_systems_tbl,
1303 p_pricing_attribs_tbl => x_pricing_attb_tbl,
1304 p_order_line_rec => l_order_line_rec,
1305 p_trx_rec => l_trx_rec,
1306 p_source => 'SHIPMENT',
1307 p_validate_only => 'N',
1308 px_error_rec => l_error_rec,
1309 x_return_status => x_return_status,
1310 x_msg_count => x_msg_count,
1311 x_msg_data => x_msg_data);
1312
1313 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
1314 raise fnd_api.g_exc_error;
1315 END IF;
1316
1317 debug('end: csi_order_ship_pub.order_shipment. status: successful');
1318 debug(' timestamp : '||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1319
1320 EXCEPTION
1321 WHEN fnd_api.g_exc_error THEN
1322 rollback to order_shipment;
1323 x_return_status := fnd_api.g_ret_sts_error;
1324 l_error_rec.error_text := csi_t_gen_utility_pvt.dump_error_stack;
1325 px_trx_error_rec := l_error_rec;
1326 debug('Error(E) :'||l_error_rec.error_text);
1327 WHEN fnd_api.g_exc_unexpected_error THEN
1328 rollback to order_shipment;
1329 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1330 l_error_rec.error_text := csi_t_gen_utility_pvt.dump_error_stack;
1331 px_trx_error_rec := l_error_rec;
1332 debug('Error(U) :'||l_error_rec.error_text);
1333 WHEN others THEN
1334 rollback to order_shipment;
1335 x_return_status := fnd_api.g_ret_sts_unexp_error;
1336 l_error_rec.error_text := substr(sqlerrm, 1, 540);
1337 px_trx_error_rec := l_error_rec;
1338 debug('Error(O) :'||l_error_rec.error_text);
1339 END order_shipment;
1340
1341 PROCEDURE process_non_source(
1342 p_txn_line_detail_rec IN csi_t_datastructures_grp.txn_line_detail_rec,
1343 p_call_contracts IN varchar2 := fnd_api.g_true,
1344 p_trx_rec IN csi_datastructures_pub.transaction_rec,
1345 x_return_status OUT NOCOPY varchar2)
1346 IS
1347
1348 l_trx_rec csi_datastructures_pub.transaction_rec;
1349
1350 l_ns_instance_rec csi_datastructures_pub.instance_rec;
1351 l_ns_party_tbl csi_datastructures_pub.party_tbl;
1352 l_ns_party_acct_tbl csi_datastructures_pub.party_account_tbl;
1353 l_ns_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
1354 l_ns_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
1355 l_ns_org_units_tbl csi_datastructures_pub.organization_units_tbl;
1356 l_ns_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
1357 l_ns_inst_id_lst csi_datastructures_pub.id_tbl;
1358
1359 l_ii_relation_code varchar2(30);
1360 l_location_code varchar2(30);
1361 l_serial_number varchar2(80);
1362 l_active_end_date date;
1363 l_exp_instance_id_lst csi_datastructures_pub.id_tbl;
1364 l_exp_instance_rec csi_datastructures_pub.instance_rec;
1365
1366 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
1367 l_msg_count number;
1368 l_msg_data varchar2(2000);
1369
1370 -- Added this parameter as part of fix for Bug 3145503.
1371 l_upd_ns_inst varchar2(1) := 'Y';
1372
1373 CURSOR comp_of_cur(p_tl_id IN number, p_tld_id IN number) IS
1374 SELECT txn_relationship_id
1375 FROM csi_t_ii_relationships
1376 WHERE transaction_line_id = p_tl_id
1377 AND (subject_id = p_tld_id
1378 OR
1379 object_id = p_tld_id)
1380 AND relationship_type_code = 'COMPONENT-OF';
1381
1382 l_comp_of_tld boolean := FALSE;
1383
1384 CURSOR other_nsrc_cur(p_tl_id IN number, p_tld_id IN number) IS
1385 SELECT sub_tld.instance_id sub_instance_id,
1386 obj_tld.instance_id obj_instance_id
1387 FROM csi_t_ii_relationships iir,
1388 csi_t_txn_line_details sub_tld,
1389 csi_t_txn_line_details obj_tld
1390 WHERE iir.transaction_line_id = p_tl_id
1391 AND (iir.subject_id = p_tld_id
1392 OR
1393 iir.object_id = p_tld_id)
1394 AND iir.relationship_type_code <> 'COMPONENT-OF'
1395 AND sub_tld.transaction_line_id = iir.transaction_line_id
1396 AND sub_tld.txn_line_detail_id = iir.subject_id
1397 AND obj_tld.transaction_line_id = iir.transaction_line_id
1398 AND obj_tld.txn_line_detail_id = iir.object_id;
1399
1400 l_skip_reason varchar2(80);
1401 skip_non_source exception ;
1402
1403 BEGIN
1404
1405 api_log('process_non_source');
1406
1407 x_return_status := fnd_api.g_ret_sts_success;
1408 l_trx_rec := p_trx_rec;
1409
1410 l_comp_of_tld := FALSE;
1411
1412 FOR comp_of_rec IN comp_of_cur(
1413 p_txn_line_detail_rec.transaction_line_id,
1414 p_txn_line_detail_rec.txn_line_detail_id)
1415 LOOP
1416 l_comp_of_tld := TRUE;
1417 END LOOP;
1418
1419 IF NOT(l_comp_of_tld) THEN
1420
1421 -- check if the source and the non source points to the same instance
1422 FOR other_nsrc_rec IN other_nsrc_cur(
1423 p_txn_line_detail_rec.transaction_line_id,
1424 p_txn_line_detail_rec.txn_line_detail_id)
1425 LOOP
1426 IF other_nsrc_rec.sub_instance_id = other_nsrc_rec.obj_instance_id THEN
1427 l_skip_reason := 'source and non source instances are the same.';
1428 RAISE skip_non_source;
1429 END IF;
1430 END LOOP;
1431
1432 l_ns_instance_rec.instance_id := p_txn_line_detail_rec.instance_id;
1433
1434 BEGIN
1435 SELECT non_src_status_id
1436 INTO l_ns_instance_rec.instance_status_id
1437 FROM csi_txn_sub_types
1438 WHERE transaction_type_id = p_trx_rec.transaction_type_id
1439 AND sub_type_id = p_txn_line_detail_rec.sub_type_id;
1440 EXCEPTION
1441 WHEN no_data_found THEN
1442 null;
1443 END;
1444
1445 l_trx_rec.txn_sub_type_id := p_txn_line_detail_rec.sub_type_id;
1446
1447 -- added this IF as part of fix for bug 3145503.
1448 IF l_location_code <> 'INVENTORY'
1449 THEN
1450 l_ns_instance_rec.active_end_date :=
1451 nvl(p_txn_line_detail_rec.active_end_date,fnd_api.g_miss_date);
1452 l_ns_instance_rec.return_by_date := p_txn_line_detail_rec.return_by_date;
1453 END IF;
1454
1455 l_ns_instance_rec.call_contracts := p_call_contracts;
1456
1457 BEGIN
1458
1459 SELECT object_version_number,
1460 location_type_code,
1461 serial_number,
1462 active_end_date
1463 INTO l_ns_instance_rec.object_version_number,
1464 l_location_code,
1465 l_serial_number,
1466 l_active_end_date
1467 FROM csi_item_instances
1468 WHERE instance_id = p_txn_line_detail_rec.instance_id;
1469
1470 debug(' TXN Line Dtl ID :'||p_txn_line_detail_rec.txn_line_detail_id);
1471 debug(' Instance ID :'||l_ns_instance_rec.instance_id );
1472 debug(' Status ID :'||l_ns_instance_rec.instance_status_id);
1473 debug(' location Code :'||l_location_code);
1474 debug(' Active end date :'||l_active_end_date);
1475
1476 -- IF l_location_code <> 'INVENTORY'
1477 -- AND
1478 -- Commented the above condition as part of fix for bug 3145503.
1479 IF l_ns_instance_rec.instance_status_id IS NOT NULL
1480 THEN
1481
1482 -- check for terminable status bug 2272771
1483 IF csi_item_instance_vld_pvt.val_inst_ter_flag(
1484 p_status_id => l_ns_instance_rec.instance_status_id)
1485 THEN
1486
1487 -- Added the fillowing If condition as part of fix for Bug 3145503.
1488 IF l_location_code = 'INVENTORY' Then
1489 debug('Instance Status is TERMINABLE so cannot update the instance status');
1490 l_upd_ns_inst := 'N';
1491 ELSE
1492 -- End code for Bug 3145503.
1493 debug(' Instance Status is defined as TERMINABLE.');
1494 IF nvl(l_ns_instance_rec.active_end_date, fnd_api.g_miss_date) = fnd_api.g_miss_date
1495 THEN
1496 --bug 4026148
1497 --l_ns_instance_rec.active_end_date := sysdate;
1498 l_ns_instance_rec.active_end_date := l_trx_rec.source_transaction_date;
1499 --bug 4026148
1500 END IF;
1501 END IF; -- End if for Bug 3145503.
1502 END IF;
1503
1504 IF l_upd_ns_inst = 'Y' -- Added as fix for Bug 3145503.
1505 THEN
1506 l_ns_instance_rec.last_oe_order_line_id := l_trx_rec.source_line_ref_id;
1507 -- we should be stamping the replaced instance also with the
1508 --order information. not sure why it wasn't done ... shegde. bug 3692473
1509 --code modification start for 3681856--
1510 IF (l_active_end_date is NOT NULL) AND (l_active_end_date <= sysdate)
1511 THEN -- we will expire the instance back. Contracts shouldn't be called while unexpiring
1512 l_ns_instance_rec.call_contracts := fnd_api.g_false;
1513 END IF;
1514 --code modification end for 3681856--
1515
1516 csi_t_gen_utility_pvt.dump_api_info(
1517 p_pkg_name => 'csi_item_instance_pub',
1518 p_api_name => 'update_item_instance');
1519
1520 csi_t_gen_utility_pvt.dump_csi_instance_rec(
1521 p_csi_instance_rec => l_ns_instance_rec);
1522
1523 /* non source status update call. */
1524 csi_item_instance_pub.update_item_instance(
1525 p_api_version => 1.0,
1526 p_commit => fnd_api.g_false,
1527 p_init_msg_list => fnd_api.g_true,
1528 p_validation_level => fnd_api.g_valid_level_full,
1529 p_instance_rec => l_ns_instance_rec,
1530 p_ext_attrib_values_tbl => l_ns_ext_attrib_val_tbl,
1531 p_party_tbl => l_ns_party_tbl,
1532 p_account_tbl => l_ns_party_acct_tbl,
1533 p_pricing_attrib_tbl => l_ns_pricing_attribs_tbl,
1534 p_org_assignments_tbl => l_ns_org_units_tbl,
1535 p_txn_rec => l_trx_rec,
1536 p_asset_assignment_tbl => l_ns_inst_asset_tbl,
1537 x_instance_id_lst => l_ns_inst_id_lst,
1538 x_return_status => l_return_status,
1539 x_msg_count => l_msg_count,
1540 x_msg_data => l_msg_data );
1541
1542 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
1543 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
1544 RAISE fnd_api.g_exc_error;
1545 END IF;
1546
1547 IF (l_active_end_date is NOT NULL) AND (l_active_end_date <= sysdate)
1548 THEN
1549 -- expiring the instance back. Added this IF for Bug 3039821
1550
1551 SELECT object_version_number
1552 INTO l_exp_instance_rec.object_version_number
1553 FROM csi_item_instances
1554 WHERE instance_id = p_txn_line_detail_rec.instance_id;
1555
1556 l_exp_instance_rec.instance_id := p_txn_line_detail_rec.instance_id;
1557
1558 --code modification start for 3681856--
1559 --l_exp_instance_rec.call_contracts := p_call_contracts;
1560 l_exp_instance_rec.call_contracts := fnd_api.g_false;
1561 --code modification end for 3681856--
1562
1563 l_trx_rec.transaction_id := fnd_api.g_miss_num;
1564
1565 csi_t_gen_utility_pvt.dump_api_info(
1566 p_api_name => 'expire_item_instance',
1567 p_pkg_name => 'csi_item_instance_pub');
1568
1569 csi_item_instance_pub.expire_item_instance(
1570 p_api_version => 1.0,
1571 p_commit => fnd_api.g_false,
1572 p_init_msg_list => fnd_api.g_true,
1573 p_validation_level => fnd_api.g_valid_level_full,
1574 p_instance_rec => l_exp_instance_rec,
1575 p_expire_children => fnd_api.g_true,
1576 p_txn_rec => l_trx_rec,
1577 x_instance_id_lst => l_exp_instance_id_lst,
1578 x_return_status => l_return_status,
1579 x_msg_count => l_msg_count,
1580 x_msg_data => l_msg_data);
1581
1582 IF NOT(l_return_status = fnd_api.g_ret_sts_success) THEN
1583 g_api_name := 'csi_item_instance_pub.expire_item_instance';
1584 raise fnd_api.g_exc_error;
1585 END IF;
1586 END IF;
1587
1588 l_trx_rec.source_group_ref_id := l_ns_instance_rec.instance_id;
1589 l_trx_rec.source_group_ref := l_serial_number;
1590
1591 SELECT object_version_number
1592 INTO l_trx_rec.object_version_number
1593 FROM csi_transactions
1594 WHERE transaction_id = l_trx_rec.transaction_id;
1595
1596 csi_transactions_pvt.update_transactions(
1597 p_api_version => 1.0,
1598 p_init_msg_list => fnd_api.g_false,
1599 p_commit => fnd_api.g_false,
1600 p_validation_level => fnd_api.g_valid_level_full,
1601 p_transaction_rec => l_trx_rec,
1602 x_return_status => l_return_status,
1603 x_msg_count => l_msg_count,
1604 x_msg_data => l_msg_data);
1605 END IF; -- Added as fix for Bug 3145503.
1606 END IF;
1607 EXCEPTION
1608 WHEN no_data_found THEN
1609 debug('Could not find the non source instance.');
1610 END;
1611 ELSE
1612 debug('Non Source record built by interface. Do not process.');
1613 END IF;
1614
1615 EXCEPTION
1616 WHEN skip_non_source THEN
1617 debug(' skip non source processing :'||l_skip_reason);
1618 x_return_status := fnd_api.g_ret_sts_success;
1619 WHEN fnd_api.g_exc_error THEN
1620 x_return_status := fnd_api.g_ret_sts_error;
1621 END process_non_source;
1622
1623 /* ********************************************************************** */
1624 /* Procedure name: get_order_shipment_rec */
1625 /* Description : Procedure that identifies the the instance shipped and */
1626 /* build the Shipment record for all the delivery lines */
1627 /* for that material transaction id */
1628 /* ********************************************************************** */
1629
1630 -- Included Transaction rec as part of fix for Bug 2767338
1631 PROCEDURE get_order_shipment_rec(
1632 p_mtl_transaction_id IN NUMBER,
1633 p_order_line_rec IN order_line_rec,
1634 p_txn_sub_type_rec IN txn_sub_type_rec,
1635 p_transaction_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
1636 x_order_shipment_tbl OUT NOCOPY order_shipment_tbl,
1637 px_error_rec IN OUT NOCOPY csi_datastructures_pub.transaction_error_rec,
1638 x_return_status OUT NOCOPY varchar2)
1639 IS
1640
1641 l_party_tbl csi_datastructures_pub.party_tbl;
1642 l_party_account_tbl csi_datastructures_pub.party_account_tbl;
1643 l_party_query_rec csi_datastructures_pub.party_query_rec;
1644 l_pty_acct_query_rec csi_datastructures_pub.party_account_query_rec;
1645 l_instance_header_tbl csi_datastructures_pub.instance_header_tbl;
1646 l_ext_attrib_val_tabl csi_datastructures_pub.extend_attrib_values_tbl;
1647 l_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
1648 l_org_units_tbl csi_datastructures_pub.organization_units_tbl;
1649 l_inst_query_rec csi_datastructures_pub.instance_query_rec;
1650
1651 -- Added a column reservable_type from mtl_systems_items for negative quantity check.
1652 l_cre_instance_rec csi_datastructures_pub.instance_rec;
1653 l_cre_party_tbl csi_datastructures_pub.party_tbl;
1654 l_cre_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
1655 l_cre_party_acct_tbl csi_datastructures_pub.party_account_tbl;
1656 l_cre_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
1657 l_cre_org_units_tbl csi_datastructures_pub.organization_units_tbl;
1658 l_cre_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
1659 l_trx_rec csi_datastructures_pub.transaction_rec;
1660
1661 -- Added for updating instance to ZERO
1662 l_zero_instance_rec csi_datastructures_pub.instance_rec;
1663 l_zero_parties_tbl csi_datastructures_pub.party_tbl;
1664 l_zero_pty_accts_tbl csi_datastructures_pub.party_account_tbl;
1665 l_zero_org_units_tbl csi_datastructures_pub.organization_units_tbl;
1666 l_zero_ea_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
1667 l_zero_pricing_tbl csi_datastructures_pub.pricing_attribs_tbl;
1668 l_zero_assets_tbl csi_datastructures_pub.instance_asset_tbl;
1669 l_inst_id_lst csi_datastructures_pub.id_tbl;
1670
1671 x_msg_count NUMBER;
1672 x_msg_data varchar2(2000);
1673 l_party_id NUMBER;
1674 l_uom_rate NUMBER;
1675 l_shipped_qty NUMBER;
1676 l_count NUMBER := 0;
1677 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
1678 l_active_instances_only varchar2(1);
1679
1680 -- Included Transaction rec as part of fix for Bug 2767338
1681 CURSOR mmt_cur(p_trx_id IN NUMBER) IS
1682 SELECT ool.line_id,
1683 ool.header_id,
1684 ool.item_type_code,
1685 ool.cust_po_number,
1686 ool.ato_line_id,
1687 ool.top_model_line_id,
1688 ool.link_to_line_id,
1689 NVL(ool.invoice_to_contact_id ,ooh.invoice_to_contact_id ) invoice_to_contact_id ,
1690 ool.line_type_id,
1691 ool.ordered_quantity,
1692 ool.shipped_quantity ord_line_shipped_qty,
1693 NVL(ool.ship_to_contact_id, ooh.ship_to_contact_id) ship_to_contact_id,
1694 NVL(ool.ship_from_org_id, ooh.ship_from_org_id) ship_from_org_id ,
1695 NVL(ool.sold_to_org_id, ooh.sold_to_org_id) sold_to_org_id ,
1696 NVL(ool.sold_from_org_id, ooh.sold_from_org_id) sold_from_org_id ,
1697 NVL(ool.ship_to_org_id, ooh.ship_to_org_id) ship_to_org_id ,
1698 NVL(ool.invoice_to_org_id, ooh.invoice_to_org_id) invoice_to_org_id ,
1699 NVL(ool.deliver_to_org_id, ooh.deliver_to_org_id) deliver_to_org_id ,
1700 ool.order_quantity_uom,
1701 mmt.inventory_item_id inventory_item_id,
1702 mmt.organization_id inv_organization_id,
1703 mmt.revision revision,
1704 mmt.subinventory_code subinventory,
1705 mmt.locator_id locator_id,
1706 null lot_number,
1707 mut.serial_number serial_number,
1708 abs(mmt.transaction_quantity) shipped_quantity,
1709 mmt.transaction_uom,
1710 mmt.transaction_date,
1711 msi.lot_control_code,
1712 msi.serial_number_control_code,
1713 msi.reservable_type,
1714 haou.location_id hr_location_id,
1715 msei.location_id subinv_location_id,
1716 to_char(null) ib_owner,
1717 to_number(null) end_customer_id,
1718 to_char(null) ib_install_loc,
1719 to_number(null) ib_install_loc_id,
1720 to_char(null) ib_current_loc,
1721 to_number(null) ib_current_loc_id,
1722 ooh.order_source_id order_source_id -- Added for Siebel Genesis Project
1723 FROM oe_order_headers_all ooh,
1724 oe_order_lines_all ool,
1725 mtl_system_items msi,
1726 mtl_unit_transactions mut,
1727 mtl_material_transactions mmt,
1728 mtl_secondary_inventories msei,
1729 hr_all_organization_units haou
1730 WHERE mmt.transaction_id = p_trx_id
1731 AND mmt.transaction_id = mut.transaction_id(+)
1732 AND msi.organization_id = mmt.organization_id
1733 AND msi.inventory_item_id = mmt.inventory_item_id
1734 AND msi.lot_control_code = 1 -- no lot case
1735 AND mmt.organization_id = haou.organization_id(+)
1736 AND mmt.subinventory_code = msei.secondary_inventory_name(+)
1737 AND mmt.organization_id = msei.organization_id(+)
1738 AND ool.line_id = mmt.trx_source_line_id
1739 AND ooh.header_id = ool.header_id
1740 UNION
1741 SELECT ool.line_id,
1742 ool.header_id,
1743 ool.item_type_code,
1744 ool.cust_po_number,
1745 ool.ato_line_id,
1746 ool.top_model_line_id,
1747 ool.link_to_line_id,
1748 NVL(ool.invoice_to_contact_id, ooh.invoice_to_contact_id ) invoice_to_contact_id ,
1749 ool.line_type_id,
1750 ool.ordered_quantity,
1751 ool.shipped_quantity ord_line_shipped_qty,
1752 NVL(ool.ship_to_contact_id, ooh.ship_to_contact_id) ship_to_contact_id,
1753 NVL(ool.ship_from_org_id , ooh.ship_from_org_id) ship_from_org_id ,
1754 NVL(ool.sold_to_org_id , ooh.sold_to_org_id) sold_to_org_id ,
1755 NVL(ool.sold_from_org_id, ooh.sold_from_org_id) sold_from_org_id ,
1756 NVL(ool.ship_to_org_id , ooh.ship_to_org_id) ship_to_org_id ,
1757 NVL(ool.invoice_to_org_id, ooh.invoice_to_org_id) invoice_to_org_id ,
1758 NVL(ool.deliver_to_org_id, ooh.deliver_to_org_id) deliver_to_org_id ,
1759 ool.order_quantity_uom ,
1760 mmt.inventory_item_id inventory_item_id,
1761 mmt.organization_id inv_organization_id,
1762 mmt.revision revision,
1763 mmt.subinventory_code subinventory,
1764 mmt.locator_id locator_id,
1765 mtln.lot_number lot_number,
1766 mut.serial_number serial_number,
1767 abs(mtln.transaction_quantity) shipped_quantity,
1768 mmt.transaction_uom,
1769 mmt.transaction_date,
1770 msi.lot_control_code,
1771 msi.serial_number_control_code,
1772 msi.reservable_type,
1773 haou.location_id hr_location_id,
1774 msei.location_id subinv_location_id,
1775 to_char(null) ib_owner,
1776 to_number(null) end_customer_id,
1777 to_char(null) ib_install_loc,
1778 to_number(null) ib_install_loc_id,
1779 to_char(null) ib_current_loc,
1780 to_number(null) ib_current_loc_id,
1781 ooh.order_source_id order_source_id -- Added for Siebel Genesis Project
1782 FROM oe_order_headers_all ooh,
1783 oe_order_lines_all ool,
1784 mtl_system_items msi,
1785 mtl_unit_transactions mut,
1786 mtl_transaction_lot_numbers mtln,
1787 mtl_material_transactions mmt,
1788 mtl_secondary_inventories msei,
1789 hr_all_organization_units haou
1790 WHERE mmt.transaction_id = p_trx_id
1791 AND mmt.transaction_id = mtln.transaction_id(+)
1792 AND mtln.serial_transaction_id = mut.transaction_id(+)
1793 AND msi.organization_id = mmt.organization_id
1794 AND msi.inventory_item_id = mmt.inventory_item_id
1795 AND msi.lot_control_code = 2 -- lot control case
1796 AND mmt.organization_id = haou.organization_id(+)
1797 AND mmt.subinventory_code = msei.secondary_inventory_name(+)
1798 AND mmt.organization_id = msei.organization_id(+)
1799 AND mmt.trx_source_line_id = ool.line_id
1800 AND ool.header_id = ooh.header_id;
1801
1802 -- For partner prdering
1803 l_partner_rec oe_install_base_util.partner_order_rec;
1804 l_partner_owner_id NUMBER;
1805 l_partner_owner_acct_id NUMBER;
1806
1807 BEGIN
1808
1809 x_return_status := fnd_api.g_ret_sts_success;
1810
1811 -- Included Transaction rec as part of fix for Bug 2767338
1812 l_trx_rec := p_transaction_rec;
1813
1814 api_log('get_order_shipment_rec');
1815
1816 /* Get the shipment record and assign to PL/SQL table */
1817 FOR mmt_rec IN mmt_cur(p_mtl_transaction_id) LOOP
1818
1819 px_error_rec.serial_number := mmt_rec.serial_number;
1820 px_error_rec.lot_number := mmt_rec.lot_number;
1821
1822 l_count := l_count + 1;
1823
1824 -- for partner ordering
1825 OE_INSTALL_BASE_UTIL.get_partner_ord_rec(p_order_line_id => mmt_rec.line_id,
1826 x_partner_order_rec => l_partner_rec);
1827
1828 IF l_partner_rec.IB_OWNER = 'END_CUSTOMER'
1829 THEN
1830 IF l_partner_rec.END_CUSTOMER_ID is null Then
1831 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1832 fnd_msg_pub.add;
1833 raise fnd_api.g_exc_error;
1834 ELSE
1835 mmt_rec.ib_owner := l_partner_rec.ib_owner;
1836 mmt_rec.end_customer_id := l_partner_rec.end_customer_id;
1837 END IF;
1838 ELSIF l_partner_rec.IB_OWNER = 'INSTALL_BASE'
1839 THEN
1840 mmt_rec.ib_owner := l_partner_rec.ib_owner;
1841 mmt_rec.end_customer_id := fnd_api.g_miss_num;
1842 ELSE
1843 mmt_rec.end_customer_id := mmt_rec.sold_to_org_id;
1844 END IF;
1845
1846 IF l_partner_rec.IB_INSTALLED_AT_LOCATION is not null
1847 THEN
1848 mmt_rec.ib_install_loc := l_partner_rec.IB_INSTALLED_AT_LOCATION;
1849 IF mmt_rec.ib_install_loc = 'END_CUSTOMER'
1850 THEN
1851 IF l_partner_rec.end_customer_site_use_id is null
1852 THEN
1853 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1854 fnd_msg_pub.add;
1855 raise fnd_api.g_exc_error;
1856 ELSE
1857 mmt_rec.ib_install_loc_id := l_partner_rec.end_customer_site_use_id;
1858 END IF;
1859 ELSIF mmt_rec.ib_install_loc = 'SHIP_TO'
1860 THEN
1861 IF mmt_rec.ship_to_org_id is null
1862 THEN
1863 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1864 fnd_msg_pub.add;
1865 raise fnd_api.g_exc_error;
1866 ELSE
1867 mmt_rec.ib_install_loc_id := mmt_rec.ship_to_org_id;
1868 END IF;
1869 ELSIF mmt_rec.ib_install_loc = 'SOLD_TO'
1870 THEN
1871 IF l_partner_rec.SOLD_TO_SITE_USE_ID is null -- 3412544 mmt_rec.sold_to_org_id is null
1872 THEN
1873 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1874 fnd_msg_pub.add;
1875 raise fnd_api.g_exc_error;
1876 ELSE
1877 mmt_rec.ib_install_loc_id := l_partner_rec.SOLD_TO_SITE_USE_ID; -- 3412544 mmt_rec.sold_to_org_id;
1878 END IF;
1879 ELSIF mmt_rec.ib_install_loc = 'DELIVER_TO'
1880 THEN
1881 IF mmt_rec.deliver_to_org_id is null
1882 THEN
1883 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1884 fnd_msg_pub.add;
1885 raise fnd_api.g_exc_error;
1886 ELSE
1887 mmt_rec.ib_install_loc_id := mmt_rec.deliver_to_org_id;
1888 END IF;
1889 ELSIF mmt_rec.ib_install_loc = 'BILL_TO'
1890 THEN
1891 IF mmt_rec.invoice_to_org_id is null
1892 THEN
1893 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1894 fnd_msg_pub.add;
1895 raise fnd_api.g_exc_error;
1896 ELSE
1897 mmt_rec.ib_install_loc_id := mmt_rec.invoice_to_org_id;
1898 END IF;
1899 ELSIF mmt_rec.ib_install_loc = 'INSTALL_BASE'
1900 THEN
1901 mmt_rec.ib_install_loc_id := fnd_api.g_miss_num;
1902 END IF;
1903 ELSE
1904 mmt_rec.ib_install_loc_id := mmt_rec.ship_to_org_id;
1905 END IF;
1906
1907 IF l_partner_rec.IB_CURRENT_LOCATION is not null
1908 THEN
1909 mmt_rec.ib_current_loc := l_partner_rec.IB_CURRENT_LOCATION;
1910 IF mmt_rec.ib_current_loc = 'END_CUSTOMER'
1911 THEN
1912 IF l_partner_rec.end_customer_site_use_id is null
1913 THEN
1914 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1915 fnd_msg_pub.add;
1916 raise fnd_api.g_exc_error;
1917 ELSE
1918 mmt_rec.ib_current_loc_id := l_partner_rec.end_customer_site_use_id;
1919 END IF;
1920 ELSIF mmt_rec.ib_current_loc = 'SHIP_TO'
1921 THEN
1922 IF mmt_rec.ship_to_org_id is null
1923 THEN
1924 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1925 fnd_msg_pub.add;
1926 raise fnd_api.g_exc_error;
1927 ELSE
1928 mmt_rec.ib_current_loc_id := mmt_rec.ship_to_org_id;
1929 END IF;
1930 ELSIF mmt_rec.ib_current_loc = 'SOLD_TO'
1931 THEN
1932 IF l_partner_rec.SOLD_TO_SITE_USE_ID is null -- 3412544 mmt_rec.sold_to_org_id is null
1933 THEN
1934 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1935 fnd_msg_pub.add;
1936 raise fnd_api.g_exc_error;
1937 ELSE
1938 mmt_rec.ib_current_loc_id := l_partner_rec.SOLD_TO_SITE_USE_ID; -- 3412544 mmt_rec.sold_to_org_id;
1939 END IF;
1940 ELSIF mmt_rec.ib_current_loc = 'DELIVER_TO'
1941 THEN
1942 IF mmt_rec.deliver_to_org_id is null
1943 THEN
1944 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1945 fnd_msg_pub.add;
1946 raise fnd_api.g_exc_error;
1947 ELSE
1948 mmt_rec.ib_current_loc_id := mmt_rec.deliver_to_org_id;
1949 END IF;
1950 ELSIF mmt_rec.ib_current_loc = 'BILL_TO'
1951 THEN
1952 IF mmt_rec.invoice_to_org_id is null
1953 THEN
1954 fnd_message.set_name('CSI','CSI_PARTNER_VAL_MISSING');
1955 fnd_msg_pub.add;
1956 raise fnd_api.g_exc_error;
1957 ELSE
1958 mmt_rec.ib_current_loc_id := mmt_rec.invoice_to_org_id;
1959 END IF;
1960 ELSIF mmt_rec.ib_current_loc = 'INSTALL_BASE'
1961 THEN
1962 mmt_rec.ib_current_loc_id := fnd_api.g_miss_num;
1963 END IF;
1964 ELSE
1965 mmt_rec.ib_current_loc_id := mmt_rec.ship_to_org_id;
1966 END IF;
1967
1968
1969 /* Derive the party_id from hz_cust_accounts table */
1970
1971 csi_utl_pkg.get_party_id(
1972 p_cust_acct_id => mmt_rec.end_customer_id, --mmt_rec.sold_to_org_id,
1973 x_party_id => l_party_id,
1974 x_return_status => l_return_status);
1975
1976 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1977 raise fnd_api.g_exc_error;
1978 END IF;
1979
1980 IF l_party_id = -1 THEN
1981 raise fnd_api.g_exc_error;
1982 END IF;
1983
1984 /* Convert the shipped qty to UOM in OM */
1985 inv_convert.inv_um_conversion (
1986 from_unit => mmt_rec.transaction_uom,
1987 to_unit => mmt_rec.order_quantity_uom,
1988 item_id => mmt_rec.inventory_item_id,
1989 uom_rate => l_uom_rate );
1990
1991 debug('UOM Conv Factor :'||l_uom_rate);
1992
1993 IF l_uom_rate = -99999 THEN
1994 debug('inv_convert.inv_um_conversion failed ');
1995 raise fnd_api.g_exc_error;
1996 END IF;
1997
1998 l_shipped_qty := (l_uom_rate * mmt_rec.shipped_quantity);
1999
2000 l_inst_query_rec.location_type_code := 'INVENTORY';
2001 l_inst_query_rec.instance_usage_code := 'IN_INVENTORY';
2002
2003 IF mmt_rec.serial_number_control_code in (1,6) THEN
2004 l_inst_query_rec.inventory_item_id := mmt_rec.inventory_item_id;
2005 l_inst_query_rec.inv_organization_id := mmt_rec.inv_organization_id;
2006 l_inst_query_rec.inventory_revision := mmt_rec.revision;
2007 l_inst_query_rec.inv_subinventory_name := mmt_rec.subinventory;
2008 l_inst_query_rec.inv_locator_id := mmt_rec.locator_id;
2009 l_inst_query_rec.serial_number := NULL; -- Bug 3056511
2010 ELSE
2011 l_inst_query_rec.inventory_item_id := mmt_rec.inventory_item_id;
2012 l_inst_query_rec.inv_organization_id := mmt_rec.inv_organization_id;
2013 l_inst_query_rec.inv_subinventory_name := mmt_rec.subinventory;
2014 l_inst_query_rec.serial_number := mmt_rec.serial_number;
2015 END IF;
2016
2017 IF mmt_rec.lot_control_code = 2 THEN
2018 l_inst_query_rec.lot_number := mmt_rec.lot_number;
2019 END IF;
2020
2021 debug('query criteria to identify inventory source instance' );
2022 debug('----------------------------------------------------' );
2023 debug('inventory_item_id :'||l_inst_query_rec.inventory_item_id);
2024 debug('inv_organization_id :'||l_inst_query_rec.inv_organization_id);
2025 debug('location_type_code :'||l_inst_query_rec.location_type_code);
2026 debug('instance_usage_code :'||l_inst_query_rec.instance_usage_code);
2027 debug('inventory_revision :'||l_inst_query_rec.inventory_revision);
2028 debug('inv_subinv_name :'||l_inst_query_rec.inv_subinventory_name);
2029 debug('inv_locator_id :'||l_inst_query_rec.inv_locator_id);
2030 debug('lot_number :'||l_inst_query_rec.lot_number);
2031 debug('serial_number :'||l_inst_query_rec.serial_number);
2032 debug('----------------------------------------------------' );
2033
2034 csi_t_gen_utility_pvt.dump_api_info(
2035 p_pkg_name => 'csi_item_instance_pub',
2036 p_api_name => 'get_item_instances');
2037
2038 -- As part of fix for Bug 2985193 this call even brings the expired Inv. Instances.
2039 -- To achieve this p_active_instances_only should have a value of false.
2040
2041 IF mmt_rec.reservable_type = 2
2042 THEN
2043 l_active_instances_only := fnd_api.g_false;
2044 ELSE
2045 l_active_instances_only := fnd_api.g_true;
2046 END IF;
2047
2048 csi_item_instance_pub.get_item_instances(
2049 p_api_version => 1.0,
2050 p_commit => fnd_api.g_false,
2051 p_init_msg_list => fnd_api.g_true,
2052 p_validation_level => fnd_api.g_valid_level_full,
2053 p_instance_query_rec => l_inst_query_rec,
2054 p_party_query_rec => l_party_query_rec,
2055 p_account_query_rec => l_pty_acct_query_rec,
2056 p_transaction_id => null,
2057 p_resolve_id_columns => fnd_api.g_false,
2058 p_active_instance_only => l_active_instances_only,-- fnd_api.g_false, --fnd_api.g_true,
2059 x_instance_header_tbl => l_instance_header_tbl,
2060 x_return_status => x_return_status,
2061 x_msg_count => x_msg_count,
2062 x_msg_data => x_msg_data);
2063
2064 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
2065 raise fnd_api.g_exc_error;
2066 END IF;
2067
2068 debug('Instance(s) Count :'||l_instance_header_tbl.count);
2069
2070 IF l_instance_header_tbl.count < 1 THEN
2071
2072 -- Bug 2767338
2073 -- Begin Code for negative quantity option set at Org Level
2074
2075 IF p_order_line_rec.negative_balances_code= 1
2076 AND
2077 mmt_rec.reservable_type = 2
2078 AND
2079 mmt_rec.serial_number_control_code in (1,6)
2080 THEN
2081
2082 debug(' Negative Quantity allowed for this Org so Building Instance Rec');
2083
2084 -- Create a Instance with missing Quantity
2085 -- Building Instance Rec
2086 l_cre_instance_rec.inventory_item_id := l_inst_query_rec.inventory_item_id;
2087 l_cre_instance_rec.inv_organization_id := l_inst_query_rec.inv_organization_id;
2088 l_cre_instance_rec.vld_organization_id := l_inst_query_rec.inv_organization_id;
2089 l_cre_instance_rec.location_type_code := l_inst_query_rec.location_type_code;
2090 l_cre_instance_rec.instance_usage_code := l_inst_query_rec.instance_usage_code;
2091 l_cre_instance_rec.inventory_revision := l_inst_query_rec.inventory_revision;
2092 l_cre_instance_rec.inv_subinventory_name := l_inst_query_rec.inv_subinventory_name;
2093 l_cre_instance_rec.inv_locator_id := l_inst_query_rec.inv_locator_id;
2094 l_cre_instance_rec.lot_number := l_inst_query_rec.lot_number;
2095 l_cre_instance_rec.serial_number := l_inst_query_rec.serial_number;
2096 l_cre_instance_rec.quantity := 1; --mmt_rec.shipped_quantity;
2097 l_cre_instance_rec.unit_of_measure := mmt_rec.transaction_uom;
2098 l_cre_instance_rec.location_id := nvl(mmt_rec.subinv_location_id,mmt_rec.hr_location_id);
2099 l_cre_instance_rec.operational_status_code := 'NOT_USED';
2100 -- Begin Add Code for Siebel Genesis Project
2101 IF (mmt_rec.order_source_id = '28' OR mmt_rec.order_source_id = '29')
2102 THEN
2103 l_cre_instance_rec.source_code := 'SIEBEL';
2104 END IF;
2105 -- End Add Code for Siebel Genesis Project
2106
2107 IF nvl(l_inst_query_rec.serial_number,fnd_api.g_miss_char) = fnd_api.g_miss_char THEN
2108 l_cre_instance_rec.mfg_serial_number_flag := 'N';
2109 ELSE
2110 l_cre_instance_rec.mfg_serial_number_flag := 'Y';
2111 END IF;
2112
2113 -- Building Party Rec for creating Instance with missing Quantity
2114 l_cre_party_tbl(1).party_id := csi_datastructures_pub.g_install_param_rec.internal_party_id;
2115
2116 l_cre_party_tbl(1).party_source_table := 'HZ_PARTIES';
2117 l_cre_party_tbl(1).relationship_type_code := 'OWNER';
2118 l_cre_party_tbl(1).contact_flag := 'N';
2119
2120 debug('Creating an inventory instance in the staging area for non reservable item.');
2121 csi_t_gen_utility_pvt.dump_api_info(
2122 p_api_name => 'create_item_instance',
2123 p_pkg_name => 'csi_item_instance_pub');
2124
2125 /* Creation of instance with the Shippable Quantity for Negative Quantities */
2126
2127 debug('Creating an instance with quantity 1 for Non-Reservable Item');
2128 csi_item_instance_pub.create_item_instance(
2129 p_api_version => 1.0,
2130 p_commit => fnd_api.g_false,
2131 p_init_msg_list => fnd_api.g_true,
2132 p_validation_level => fnd_api.g_valid_level_full,
2133 p_instance_rec => l_cre_instance_rec,
2134 p_ext_attrib_values_tbl => l_cre_ext_attrib_val_tbl,
2135 p_party_tbl => l_cre_party_tbl,
2136 p_account_tbl => l_cre_party_acct_tbl,
2137 p_pricing_attrib_tbl => l_cre_pricing_attribs_tbl,
2138 p_org_assignments_tbl => l_cre_org_units_tbl,
2139 p_asset_assignment_tbl => l_cre_inst_asset_tbl,
2140 p_txn_rec => l_trx_rec,
2141 x_return_status => x_return_status,
2142 x_msg_count => x_msg_count,
2143 x_msg_data => x_msg_data );
2144
2145 -- For Bug 4057183
2146 -- IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
2147 IF NOT(x_return_status in (fnd_api.g_ret_sts_success,'W')) THEN
2148 g_api_name := 'csi_item_instance_pub.create_item_instance';
2149 raise fnd_api.g_exc_error;
2150 END IF;
2151
2152 l_zero_instance_rec.instance_id := l_cre_instance_rec.instance_id;
2153 l_zero_instance_rec.quantity := 0;
2154
2155 -- debug('After Create OBJECT_VERSION_NUMBER '||l_cre_instance_rec.object_version_number);
2156 Select object_version_number
2157 Into l_zero_instance_rec.object_version_number
2158 From csi_item_instances
2159 Where instance_id = l_cre_instance_rec.instance_id;
2160
2161 -- debug('Before calling update OBJECT_VERSION_NUMBER '||l_zero_instance_rec.object_version_number);
2162
2163 debug('Updating Created Instance to zero Quantity');
2164
2165 csi_t_gen_utility_pvt.dump_api_info(
2166 p_pkg_name => 'csi_item_instance_pub',
2167 p_api_name => 'update_item_instance');
2168
2169 csi_item_instance_pub.update_item_instance(
2170 p_api_version => 1.0,
2171 p_commit => fnd_api.g_false,
2172 p_init_msg_list => fnd_api.g_true,
2173 p_validation_level => fnd_api.g_valid_level_full,
2174 p_instance_rec => l_zero_instance_rec,
2175 p_party_tbl => l_zero_parties_tbl,
2176 p_account_tbl => l_zero_pty_accts_tbl,
2177 p_org_assignments_tbl => l_zero_org_units_tbl,
2178 p_ext_attrib_values_tbl => l_zero_ea_values_tbl,
2179 p_pricing_attrib_tbl => l_zero_pricing_tbl,
2180 p_asset_assignment_tbl => l_zero_assets_tbl,
2181 p_txn_rec => l_trx_rec,
2182 x_instance_id_lst => l_inst_id_lst,
2183 x_return_status => l_return_status,
2184 x_msg_count => x_msg_count,
2185 x_msg_data => x_msg_data);
2186
2187 -- For Bug 4057183
2188 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
2189 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
2190 RAISE fnd_api.g_exc_error;
2191 END IF;
2192
2193 debug('Instance ('||l_zero_instance_rec.instance_id||') created and updated with zero quantity successfully.');
2194 l_instance_header_tbl(1).instance_id := l_zero_instance_rec.instance_id;
2195 l_instance_header_tbl(1).quantity := l_zero_instance_rec.quantity;
2196 -- l_instance_header_tbl(1).object_version_number := l_cre_instance_rec.object_version_number;
2197
2198 Select object_version_number
2199 Into l_instance_header_tbl(1).object_version_number
2200 From csi_item_instances
2201 Where instance_id = l_zero_instance_rec.instance_id;
2202
2203 px_error_rec.instance_id := l_zero_instance_rec.instance_id;
2204
2205 ELSE
2206 fnd_message.SET_NAME('CSI','CSI_INT_NO_INST_FOUND');
2207 fnd_msg_pub.add;
2208 raise fnd_api.g_exc_error;
2209 END IF;
2210 END IF;
2211 -- Bug 2767338
2212 -- End Fix for negative quantity option set at Org Level
2213
2214 IF l_instance_header_tbl.count > 1 THEN
2215 fnd_message.SET_NAME('CSI','CSI_INT_MANY_INST_FOUND');
2216 fnd_msg_pub.add;
2217 raise fnd_api.g_exc_error;
2218 END IF;
2219
2220 debug('Unique inventory instance found.....!');
2221 px_error_rec.instance_id := l_instance_header_tbl(1).instance_id;
2222
2223 debug(' Inventory Instance_ID :'||l_instance_header_tbl(1).instance_id);
2224 debug(' Instance Quantity :'||l_instance_header_tbl(1).quantity );
2225
2226 x_order_shipment_tbl(l_count).line_id := mmt_rec.line_id ;
2227 x_order_shipment_tbl(l_count).header_id := mmt_rec.header_id;
2228 x_order_shipment_tbl(l_count).instance_id := l_instance_header_tbl(1).instance_id;
2229 x_order_shipment_tbl(l_count).instance_qty := l_instance_header_tbl(1).quantity;
2230 x_order_shipment_tbl(l_count).party_id := l_party_id;
2231 x_order_shipment_tbl(l_count).party_source_table := 'HZ_PARTIES';
2232 x_order_shipment_tbl(l_count).party_account_id := mmt_rec.end_customer_id; -- mmt_rec.sold_to_org_id;
2233 x_order_shipment_tbl(l_count).inventory_item_id := mmt_rec.inventory_item_id ;
2234 x_order_shipment_tbl(l_count).organization_id := mmt_rec.inv_organization_id ;
2235 x_order_shipment_tbl(l_count).revision := mmt_rec.revision;
2236 x_order_shipment_tbl(l_count).subinventory := mmt_rec.subinventory ;
2237 x_order_shipment_tbl(l_count).locator_id := mmt_rec.locator_id ;
2238 x_order_shipment_tbl(l_count).lot_number := mmt_rec.lot_number ;
2239 x_order_shipment_tbl(l_count).serial_number := mmt_rec.serial_number ;
2240 x_order_shipment_tbl(l_count).transaction_uom := mmt_rec.transaction_uom ;
2241 x_order_shipment_tbl(l_count).order_quantity_uom := mmt_rec.order_quantity_uom ;
2242 x_order_shipment_tbl(l_count).invoice_to_org_id := mmt_rec.invoice_to_org_id;
2243 x_order_shipment_tbl(l_count).line_type_id := mmt_rec.line_type_id ;
2244 x_order_shipment_tbl(l_count).ordered_quantity := mmt_rec.ordered_quantity;
2245 x_order_shipment_tbl(l_count).ship_to_contact_id := mmt_rec.ship_to_contact_id;
2246 x_order_shipment_tbl(l_count).ship_to_org_id := mmt_rec.ship_to_org_id ;
2247 x_order_shipment_tbl(l_count).ship_from_org_id := mmt_rec.ship_from_org_id ;
2248 x_order_shipment_tbl(l_count).sold_to_org_id := mmt_rec.sold_to_org_id ;
2249 x_order_shipment_tbl(l_count).sold_from_org_id := mmt_rec.sold_from_org_id ;
2250
2251 /* added this if condition for the bug 2356340 */
2252 /* Added 2 and 5 as part of fix for Bug 3089110 */
2253
2254 IF mmt_rec.serial_number_control_code in (2,5,6) THEN
2255 x_order_shipment_tbl(l_count).shipped_quantity := 1;
2256 ELSE
2257 x_order_shipment_tbl(l_count).shipped_quantity := l_shipped_qty;
2258 END IF;
2259
2260 x_order_shipment_tbl(l_count).customer_id := mmt_rec.end_customer_id; -- mmt_rec.sold_to_org_id ;
2261 x_order_shipment_tbl(l_count).transaction_date := mmt_rec.transaction_date ;
2262 x_order_shipment_tbl(l_count).item_type_code := mmt_rec.item_type_code ;
2263 x_order_shipment_tbl(l_count).cust_po_number := mmt_rec.cust_po_number ;
2264 x_order_shipment_tbl(l_count).ato_line_id := mmt_rec.ato_line_id ;
2265 x_order_shipment_tbl(l_count).top_model_line_id := mmt_rec.top_model_line_id ;
2266 x_order_shipment_tbl(l_count).link_to_line_id := mmt_rec.link_to_line_id ;
2267 x_order_shipment_tbl(l_count).instance_match := 'N' ;
2268 x_order_shipment_tbl(l_count).quantity_match := 'N' ;
2269 -- Added lot_match for bug 3384668
2270 x_order_shipment_tbl(l_count).lot_match := 'N' ;
2271 x_order_shipment_tbl(l_count).invoice_to_contact_id := mmt_rec.invoice_to_contact_id ;
2272 x_order_shipment_tbl(l_count).ord_line_shipped_qty := mmt_rec.ord_line_shipped_qty;
2273 x_order_shipment_tbl(l_count).inst_obj_version_number := l_instance_header_tbl(1).object_version_number;
2274 -- Added for Partner Ordering.
2275 x_order_shipment_tbl(l_count).ib_install_loc_id := mmt_rec.ib_install_loc_id;
2276 x_order_shipment_tbl(l_count).ib_current_loc_id := mmt_rec.ib_current_loc_id;
2277 x_order_shipment_tbl(l_count).ib_install_loc := mmt_rec.ib_install_loc;
2278 x_order_shipment_tbl(l_count).ib_current_loc := mmt_rec.ib_current_loc;
2279 -- Begin Fix for Bug 3361434
2280 x_order_shipment_tbl(l_count).end_customer_id := mmt_rec.end_customer_id;
2281 -- End Fix for Bug 3361434
2282 -- Begin Add Code for Siebel Genesis Project
2283 IF (mmt_rec.order_source_id = '28' OR mmt_rec.order_source_id = '29')
2284 THEN
2285 x_order_shipment_tbl(l_count).source_code := 'SIEBEL';
2286 END IF;
2287 -- End Add Code for Siebel Genesis Project
2288 END LOOP;
2289
2290 EXCEPTION
2291 WHEN fnd_api.g_exc_error THEN
2292 x_return_status := fnd_api.g_ret_sts_error;
2293 WHEN fnd_api.g_exc_unexpected_error THEN
2294 x_return_status := fnd_api.g_ret_sts_unexp_error;
2295 END get_order_shipment_rec;
2296
2297 /* To build the matched txn line details if entered for order line . */
2298 /* If txn line details does not exist then it creates one from the */
2299 /* shipment details. Also it builds the COMPONENT-OF relationship if */
2300 /* there is a top model for that order line */
2301
2302 PROCEDURE build_shtd_table(
2303 p_mtl_transaction_id IN number,
2304 p_order_line_rec IN OUT NOCOPY order_line_rec,
2305 p_txn_sub_type_rec IN txn_sub_type_rec,
2306 p_trx_detail_exist IN boolean,
2307 p_trackable_parent IN boolean,
2308 p_transaction_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
2309 x_order_shipment_tbl OUT NOCOPY order_shipment_tbl,
2310 px_error_rec IN OUT NOCOPY csi_datastructures_pub.transaction_error_rec,
2311 x_return_status OUT NOCOPY varchar2)
2312 IS
2313 x_msg_count number;
2314 x_msg_data varchar2(2000);
2315 x_trx_line_id number;
2316
2317 l_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
2318 l_txn_line_query_rec csi_t_datastructures_grp.txn_line_query_rec;
2319 l_txn_line_dtl_query_rec csi_t_datastructures_grp.txn_line_detail_query_rec;
2320
2321 l_txn_line_detail_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
2322 l_txn_party_detail_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
2323 l_txn_pty_acct_detail_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
2324 l_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
2325 l_txn_ext_attrib_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
2326 l_csi_ext_attribs_tbl csi_t_datastructures_grp.csi_ext_attribs_tbl;
2327 l_extend_attrib_values_tbl csi_t_datastructures_grp.csi_ext_attrib_vals_tbl;
2328 l_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl ;
2329 l_txn_systems_tbl csi_t_datastructures_grp.txn_systems_tbl;
2330
2331 l_upd_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
2332 l_upd_txn_line_dtl_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
2333 l_upd_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
2334 l_upd_txn_party_detail_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
2335 l_upd_txn_pty_acct_dtl_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
2336 l_upd_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
2337 l_upd_txn_ext_attr_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
2338
2339 x_model_inst_tbl model_inst_tbl;
2340 l_qty_ratio number;
2341 l_model_exist boolean := FALSE;
2342
2343 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
2344 l_msg_count number;
2345 l_msg_data varchar2(2000);
2346
2347 -- Included Transaction rec as part of fix for Bug 2767338
2348 l_trx_rec csi_datastructures_pub.transaction_rec;
2349
2350 ---Added (Start) for m-to-m enhancements
2351 l_temp_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
2352 ---Added (End) for m-to-m enhancements
2353
2354 l_parent_line_qty NUMBER := fnd_api.g_miss_num;
2355 --
2356 -- srramakr Added for TSO With Equipment
2357 l_om_session_key csi_utility_grp.config_session_key;
2358 l_macd_processing BOOLEAN := FALSE;
2359
2360 BEGIN
2361
2362 x_return_status := fnd_api.g_ret_sts_success;
2363 -- Included Transaction rec as part of fix for Bug 2767338
2364 l_trx_rec := p_transaction_rec;
2365
2366 api_log('build_shtd_table');
2367
2368 /* Build the Shipment table for the mtl_trx_id */
2369 -- Included Transaction rec as part of fix for Bug 2767338
2370 get_order_shipment_rec(
2371 p_mtl_transaction_id => p_mtl_transaction_id,
2372 p_order_line_rec => p_order_line_rec,
2373 p_txn_sub_type_rec => p_txn_sub_type_rec,
2374 p_transaction_rec => l_trx_rec,
2375 x_order_shipment_tbl => x_order_shipment_tbl,
2376 px_error_rec => px_error_rec,
2377 x_return_status => l_return_status );
2378
2379 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2380 raise fnd_api.g_exc_error;
2381 END IF;
2382
2383 debug(' order_shipment_tbl.count :'||x_order_shipment_tbl.count);
2384
2385 /* Get the instances for the option class/model line_id (ATO/PTO) */
2386 IF NVL(p_order_line_rec.link_to_line_id ,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
2387
2388 x_model_inst_tbl.delete;
2389 --
2390 -- srramakr Added for TSO with Equipment
2391 l_om_session_key.session_hdr_id := p_order_line_rec.config_header_id;
2392 l_om_session_key.session_rev_num := p_order_line_rec.config_rev_nbr;
2393 l_om_session_key.session_item_id := p_order_line_rec.configuration_id;
2394 --
2395 l_macd_processing := csi_interface_pkg.check_macd_processing
2396 ( p_config_session_key => l_om_session_key,
2397 x_return_status => l_return_status
2398 );
2399 --
2400 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2401 RAISE fnd_api.g_exc_error;
2402 END IF;
2403 --
2404 IF NOT l_macd_processing THEN
2405 csi_utl_pkg.get_model_inst_lst(
2406 p_parent_line_id => p_order_line_rec.link_to_line_id,
2407 x_model_inst_tbl => x_model_inst_tbl,
2408 x_return_status => l_return_status);
2409
2410 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2411 raise fnd_api.g_exc_error;
2412 END IF;
2413 ELSE -- MACD Order Line
2414 p_order_line_rec.macd_order_line := FND_API.G_TRUE;
2415 END IF; -- MACD Processing check
2416 -- srramakr End of TSO with Equipment
2417 --
2418 debug(' model_inst_tbl.count :'||x_model_inst_tbl.count);
2419
2420 IF x_model_inst_tbl.COUNT > 0 THEN
2421 l_model_exist := TRUE;
2422 ELSE
2423 l_model_exist := FALSE;
2424 END IF;
2425
2426 END IF;
2427
2428 /* ---------------------------------------------------*/
2429 /* The following scenarios are handled */
2430 /* 1.Transaction line Details does not exist */
2431 /* 1.1 Partial */
2432 /* 1.2 Full */
2433 /* 1.3 Config (ATO) */
2434 /* 1.4 Option items (PTO) */
2435 /* 2.Transaction line details exist */
2436 /* 1.1 Partial */
2437 /* 1.2 Full */
2438 /* --------------------------------------------------*/
2439 IF NOT(p_trx_detail_exist ) THEN
2440 /* Txn details does not exist for the order line*/
2441 IF p_order_line_rec.item_type_code = 'CONFIG' THEN
2442
2443 create_dflt_td_from_ship(
2444 p_serial_code => p_order_line_rec.serial_code,
2445 p_order_line_rec => p_order_line_rec,
2446 p_trackable_parent => TRUE,
2447 px_order_shipment_tbl => x_order_shipment_tbl,
2448 x_transaction_line_id => x_trx_line_id,
2449 x_return_status => l_return_status);
2450
2451 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2452 raise fnd_api.g_exc_error;
2453 END IF;
2454
2455 ELSIF p_order_line_rec.item_type_code = 'OPTION' THEN
2456
2457 process_option_item(
2458 p_serial_code => p_order_line_rec.serial_code,
2459 p_txn_sub_type_rec => p_txn_sub_type_rec,
2460 p_order_line_rec => p_order_line_rec,
2461 p_trackable_parent => p_trackable_parent,
2462 x_order_shipment_tbl => x_order_shipment_tbl,
2463 x_model_inst_tbl => x_model_inst_tbl,
2464 x_trx_line_id => x_trx_line_id,
2465 x_return_status => l_return_status);
2466
2467 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2468 raise fnd_api.g_exc_error;
2469 END IF;
2470
2471 ELSE
2472
2473 IF l_model_exist THEN
2474
2475 process_option_item(
2476 p_serial_code => p_order_line_rec.serial_code,
2477 p_txn_sub_type_rec => p_txn_sub_type_rec,
2478 p_order_line_rec => p_order_line_rec,
2479 p_trackable_parent => p_trackable_parent,
2480 x_order_shipment_tbl => x_order_shipment_tbl,
2481 x_model_inst_tbl => x_model_inst_tbl,
2482 x_trx_line_id => x_trx_line_id,
2483 x_return_status => l_return_status );
2484
2485 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2486 raise fnd_api.g_exc_error;
2487 END IF;
2488
2489 ELSE -- create transaction details
2490
2491 create_dflt_td_from_ship(
2492 p_serial_code => p_order_line_rec.serial_code,
2493 p_order_line_rec => p_order_line_rec,
2494 p_trackable_parent => p_trackable_parent,
2495 px_order_shipment_tbl => x_order_shipment_tbl,
2496 x_transaction_line_id => x_trx_line_id,
2497 x_return_status => l_return_status);
2498
2499 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2500 raise fnd_api.g_exc_error;
2501 END IF;
2502
2503 END IF;
2504
2505 END IF;
2506
2507 p_order_line_rec.trx_line_id := x_trx_line_id ;
2508
2509 ELSE
2510
2511 /*--------------------------------------------*/
2512 /* If txn details exist then Get txn details */
2513 /* and match it with shipment table */
2514 /*--------------------------------------------*/
2515
2516 x_trx_line_id := p_order_line_rec.trx_line_id;
2517 l_txn_line_query_rec.source_transaction_id := p_order_line_rec.order_line_id;
2518 l_txn_line_query_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
2519 l_txn_line_dtl_query_rec.processing_status := 'UNPROCESSED';
2520
2521 debug('Getting installation details for matching with material transaction info.' );
2522
2523 csi_t_txn_details_grp.get_transaction_details(
2524 p_api_version => 1.0,
2525 p_commit => fnd_api.g_false,
2526 p_init_msg_list => fnd_api.g_true,
2527 p_validation_level => fnd_api.g_valid_level_full,
2528 p_txn_line_query_rec => l_txn_line_query_rec,
2529 p_txn_line_detail_query_rec => l_txn_line_dtl_query_rec,
2530 x_txn_line_detail_tbl => l_txn_line_detail_tbl,
2531 p_get_parties_flag => fnd_api.g_false,
2532 x_txn_party_detail_tbl => l_txn_party_detail_tbl,
2533 p_get_pty_accts_flag => fnd_api.g_false,
2534 x_txn_pty_acct_detail_tbl => l_txn_pty_acct_detail_tbl,
2535 p_get_ii_rltns_flag => fnd_api.g_true,
2536 x_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
2537 p_get_org_assgns_flag => fnd_api.g_false,
2538 x_txn_org_assgn_tbl => l_txn_org_assgn_tbl,
2539 p_get_ext_attrib_vals_flag => fnd_api.g_false,
2540 x_txn_ext_attrib_vals_tbl => l_txn_ext_attrib_vals_tbl,
2541 p_get_csi_attribs_flag => fnd_api.g_false,
2542 x_csi_ext_attribs_tbl => l_csi_ext_attribs_tbl,
2543 p_get_csi_iea_values_flag => fnd_api.g_false,
2544 x_csi_iea_values_tbl => l_extend_attrib_values_tbl,
2545 p_get_txn_systems_flag => fnd_api.g_false,
2546 x_txn_systems_tbl => l_txn_systems_tbl,
2547 x_return_status => l_return_status,
2548 x_msg_count => l_msg_count,
2549 x_msg_data => l_msg_data);
2550
2551 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2552 raise fnd_api.g_exc_error;
2553 END IF;
2554
2555 debug(' txn_line_detail_tbl.count :'||l_txn_line_detail_tbl.count );
2556 debug(' txn_ii_rltns_tbl.count :'||l_txn_ii_rltns_tbl.count );
2557
2558 IF l_txn_line_detail_tbl.COUNT > 0 THEN
2559
2560 construct_for_txn_exists(
2561 p_txn_sub_type_rec => p_txn_sub_type_rec,
2562 p_order_line_rec => p_order_line_rec,
2563 x_txn_line_detail_tbl => l_txn_line_detail_tbl,
2564 x_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
2565 x_order_shipment_tbl => x_order_shipment_tbl,
2566 x_return_status => l_return_status );
2567
2568 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2569 raise fnd_api.g_exc_error;
2570 END IF;
2571
2572 --Added (Start) for m-to-m enhancements
2573 --05/20 For each TLD in ,l_txn_line_detail_tbl
2574 --get the relations and append these relations to l_txn_ii_rltns_tbl.
2575
2576 csi_utl_pkg.build_txn_relations(
2577 l_txn_line_detail_tbl,
2578 l_temp_txn_ii_rltns_tbl,
2579 l_return_status);
2580
2581 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2582 raise fnd_api.g_exc_error;
2583 END IF;
2584
2585 --Create these relations in csi_t_ii_relationships table
2586
2587 IF l_temp_txn_ii_rltns_tbl.count > 0 THEN
2588 csi_t_txn_rltnshps_grp.create_txn_ii_rltns_dtls(
2589 p_api_version => 1.0,
2590 p_commit => fnd_api.g_false,
2591 p_init_msg_list => fnd_api.g_true,
2592 p_validation_level => fnd_api.g_valid_level_full,
2593 px_txn_ii_rltns_tbl => l_temp_txn_ii_rltns_tbl,
2594 x_return_status => l_return_status,
2595 x_msg_count => x_msg_count,
2596 x_msg_data => x_msg_data);
2597
2598 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2599 raise fnd_api.g_exc_error;
2600 END IF;
2601 END IF ; ---l_temp_txn_ii_rltns_tbl.count>0
2602 --added (end) for m-to-m enhancements
2603 ELSE
2604
2605 IF p_order_line_rec.item_type_code = 'CONFIG' THEN
2606
2607 create_dflt_td_from_ship(
2608 p_serial_code => p_order_line_rec.serial_code,
2609 p_order_line_rec => p_order_line_rec,
2610 p_trackable_parent => TRUE ,
2611 px_order_shipment_tbl => x_order_shipment_tbl,
2612 x_transaction_line_id => x_trx_line_id,
2613 x_return_status => l_return_status);
2614
2615 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2616 raise fnd_api.g_exc_error;
2617 END IF;
2618
2619 ELSIF p_order_line_rec.item_type_code = 'OPTION' THEN
2620
2621 process_option_item(
2622 p_serial_code => p_order_line_rec.serial_code,
2623 p_txn_sub_type_rec => p_txn_sub_type_rec,
2624 p_order_line_rec => p_order_line_rec,
2625 p_trackable_parent => p_trackable_parent,
2626 x_order_shipment_tbl => x_order_shipment_tbl,
2627 x_model_inst_tbl => x_model_inst_tbl,
2628 x_trx_line_id => x_trx_line_id,
2629 x_return_status => l_return_status);
2630
2631 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2632 raise fnd_api.g_exc_error;
2633 END IF;
2634
2635 ELSE
2636
2637 create_dflt_td_from_ship(
2638 p_serial_code => p_order_line_rec.serial_code,
2639 p_order_line_rec => p_order_line_rec,
2640 p_trackable_parent => p_trackable_parent,
2641 px_order_shipment_tbl => x_order_shipment_tbl,
2642 x_transaction_line_id => x_trx_line_id,
2643 x_return_status => l_return_status);
2644
2645 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2646 raise fnd_api.g_exc_error;
2647 END IF;
2648
2649 END IF;
2650 END IF;
2651 END IF;
2652
2653 /*-----------------------------------------------*/
2654 /* If top model exists for that order line */
2655 /* then build the component-of relationship table*/
2656 /*-----------------------------------------------*/
2657
2658 IF x_model_inst_tbl.count > 0 THEN
2659
2660 debug('Instance exists for option class/Model, so building relation' );
2661
2662 l_txn_line_query_rec.source_transaction_id := p_order_line_rec.order_line_id;
2663 l_txn_line_query_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
2664 l_txn_line_dtl_query_rec.processing_status := 'IN_PROCESS';
2665 l_txn_line_dtl_query_rec.source_transaction_flag := 'Y';
2666
2667 debug('Getting only matched txn line dtls ' );
2668
2669 csi_t_txn_details_grp.get_transaction_details(
2670 p_api_version => 1.0
2671 ,p_commit => fnd_api.g_false
2672 ,p_init_msg_list => fnd_api.g_true
2673 ,p_validation_level => fnd_api.g_valid_level_full
2674 ,p_txn_line_query_rec => l_txn_line_query_rec
2675 ,p_txn_line_detail_query_rec => l_txn_line_dtl_query_rec
2676 ,x_txn_line_detail_tbl => l_txn_line_detail_tbl
2677 ,p_get_parties_flag => fnd_api.g_false
2678 ,x_txn_party_detail_tbl => l_txn_party_detail_tbl
2679 ,p_get_pty_accts_flag => fnd_api.g_false
2680 ,x_txn_pty_acct_detail_tbl => l_txn_pty_acct_detail_tbl
2681 ---Added (Start) for m-to-m enhancements
2682 -- Now get the relations
2683 ,p_get_ii_rltns_flag => fnd_api.g_true
2684 ---Added (End) for m-to-m enhancements
2685 ,x_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl
2686 ,p_get_org_assgns_flag => fnd_api.g_false
2687 ,x_txn_org_assgn_tbl => l_txn_org_assgn_tbl
2688 ,p_get_ext_attrib_vals_flag => fnd_api.g_false
2689 ,x_txn_ext_attrib_vals_tbl => l_txn_ext_attrib_vals_tbl
2690 ,p_get_csi_attribs_flag => fnd_api.g_false
2691 ,x_csi_ext_attribs_tbl => l_csi_ext_attribs_tbl
2692 ,p_get_csi_iea_values_flag => fnd_api.g_false
2693 ,x_csi_iea_values_tbl => l_extend_attrib_values_tbl
2694 ,p_get_txn_systems_flag => fnd_api.g_false
2695 ,x_txn_systems_tbl => l_txn_systems_tbl
2696 ,x_return_status => x_return_status
2697 ,x_msg_count => x_msg_count
2698 ,x_msg_data => x_msg_data );
2699
2700 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
2701 raise fnd_api.g_exc_error;
2702 END IF;
2703
2704 debug('l_txn_line_detail_tbl.count ='||l_txn_line_detail_tbl.count );
2705
2706 csi_utl_pkg.get_qty_ratio(
2707 p_order_line_qty => p_order_line_rec.ordered_quantity,
2708 p_link_to_line_id => p_order_line_rec.link_to_line_id,
2709 p_order_item_id => p_order_line_rec.inv_item_id,
2710 p_model_remnant_flag => p_order_line_rec.model_remnant_flag, --added for bug5096435
2711 x_qty_ratio => l_qty_ratio ,
2712 x_return_status => l_return_status );
2713
2714 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
2715 raise fnd_api.g_exc_error;
2716 END IF;
2717
2718 debug('l_qty_ratio = '||l_qty_ratio );
2719
2720 IF x_model_inst_tbl.count > 0 THEN
2721 FOR i in x_model_inst_tbl.first..x_model_inst_tbl.last
2722 LOOP
2723 x_model_inst_tbl(i).rem_qty := l_qty_ratio;
2724 x_model_inst_tbl(i).process_flag := 'N';
2725 END LOOP;
2726 END IF;
2727
2728 csi_utl_pkg.build_parent_relation(
2729 p_order_line_rec => p_order_line_rec,
2730 x_model_inst_tbl => x_model_inst_tbl,
2731 x_txn_line_dtl_tbl => l_txn_line_detail_tbl,
2732 x_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
2733 x_return_status => x_return_status );
2734
2735 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
2736 raise fnd_api.g_exc_error;
2737 END IF;
2738
2739 csi_t_txn_rltnshps_grp.create_txn_ii_rltns_dtls(
2740 p_api_version => 1.0,
2741 p_commit => fnd_api.g_false,
2742 p_init_msg_list => fnd_api.g_true,
2743 p_validation_level => fnd_api.g_valid_level_full,
2744 px_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
2745 x_return_status => x_return_status,
2746 x_msg_count => x_msg_count,
2747 x_msg_data => x_msg_data);
2748
2749 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
2750 g_api_name := 'csi_t_txn_rltnshps_grp.create_txn_ii_rltns_dtls';
2751 raise fnd_api.g_exc_error;
2752 END IF;
2753
2754 END IF;
2755
2756 l_txn_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
2757 l_txn_line_rec.source_transaction_id := p_order_line_rec.order_line_id;
2758 BEGIN
2759 SELECT transaction_line_id
2760 INTO l_txn_line_rec.transaction_line_id
2761 FROM csi_t_transaction_lines
2762 WHERE source_transaction_id = l_txn_line_rec.source_transaction_id
2763 AND source_transaction_table = l_txn_line_rec.source_transaction_table;
2764 EXCEPTION
2765 WHEN no_data_found THEN
2766 null;
2767 END;
2768
2769 IF NVL(p_order_line_rec.model_remnant_flag,'N') <> 'Y' THEN
2770 csi_utl_pkg.build_child_relation(
2771 p_order_line_rec => p_order_line_rec,
2772 p_model_txn_line_rec => l_txn_line_rec,
2773 px_csi_txn_rec => l_trx_rec,
2774 x_return_status => l_return_status);
2775
2776 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2777 RAISE fnd_api.g_exc_error;
2778 END IF;
2779
2780 END IF;
2781 EXCEPTION
2782 WHEN FND_API.G_EXC_ERROR THEN
2783 x_return_status := FND_API.G_RET_STS_ERROR ;
2784 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2785 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2786 END build_shtd_table;
2787
2788
2789 PROCEDURE check_return_processing(
2790 px_txn_line_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
2791 x_return_status OUT NOCOPY varchar2)
2792 IS
2793 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
2794 l_instance_usage_code varchar2(30) := 'NULL';
2795 BEGIN
2796
2797 x_return_status := fnd_api.g_ret_sts_success;
2798
2799 api_log('check_return_processing');
2800
2801 IF px_txn_line_detail_tbl.COUNT > 0 THEN
2802 FOR l_ind IN px_txn_line_detail_tbl.FIRST .. px_txn_line_detail_tbl.LAST
2803 LOOP
2804 IF px_txn_line_detail_tbl(l_ind).source_transaction_flag = 'Y'
2805 AND
2806 nvl(px_txn_line_detail_tbl(l_ind).instance_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
2807 THEN
2808
2809 debug(' referred instance id :'||px_txn_line_detail_tbl(l_ind).instance_id);
2810
2811 BEGIN
2812 SELECT instance_usage_code
2813 INTO l_instance_usage_code
2814 FROM csi_item_instances
2815 WHERE instance_id = px_txn_line_detail_tbl(l_ind).instance_id;
2816 EXCEPTION
2817 WHEN no_data_found THEN
2818 l_instance_usage_code := 'NULL';
2819 END;
2820
2821 debug(' instance usage code :'||l_instance_usage_code);
2822
2823 IF l_instance_usage_code = 'RETURNED' THEN
2824 px_txn_line_detail_tbl(l_ind).changed_instance_id :=
2825 px_txn_line_detail_tbl(l_ind).instance_id ;
2826 px_txn_line_detail_tbl(l_ind).instance_id := null;
2827 END IF;
2828 END IF;
2829 END LOOP;
2830 END IF;
2831 EXCEPTION
2832 WHEN fnd_api.g_exc_error THEN
2833 x_return_status := fnd_api.g_ret_sts_error;
2834 WHEN fnd_api.g_exc_unexpected_error THEN
2835 x_return_status := fnd_api.g_ret_sts_unexp_error;
2836 END check_return_processing;
2837
2838 /*---------------------------------------------------------------*/
2839 /* Procedure does matching of txn line details with the shipment */
2840 /*---------------------------------------------------------------*/
2841 PROCEDURE construct_for_txn_exists(
2842 p_txn_sub_type_rec IN txn_sub_type_rec,
2843 p_order_line_rec IN order_line_rec,
2844 x_order_shipment_tbl IN OUT NOCOPY order_shipment_tbl,
2845 x_txn_ii_rltns_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_ii_rltns_tbl,
2846 x_txn_line_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
2847 x_return_status OUT NOCOPY varchar2)
2848 IS
2849 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
2850 BEGIN
2851
2852 /* Initialize API return status to success */
2853 x_return_status := fnd_api.g_ret_sts_success;
2854
2855 api_log('construct_for_txn_exists');
2856
2857 /* brmanesh - hooking this procedure to check if the instance referenced is a
2858 returned configured non serial instance . If yes then save this instance id in
2859 the changed_instance_id column in installation details and mark the record for
2860 return processing
2861 */
2862 check_return_processing(
2863 px_txn_line_detail_tbl => x_txn_line_detail_tbl,
2864 x_return_status => l_return_status);
2865
2866 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2867 RAISE fnd_api.g_exc_error;
2868 END IF;
2869
2870 match_txn_with_ship(
2871 p_serial_code => p_order_line_rec.serial_code,
2872 x_txn_line_detail_tbl => x_txn_line_detail_tbl,
2873 x_order_shipment_tbl => x_order_shipment_tbl,
2874 x_return_status => l_return_status );
2875
2876 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2877 raise fnd_api.g_exc_error;
2878 END IF;
2879
2880 process_txn_dtl(
2881 p_serial_code => p_order_line_rec.serial_code,
2882 p_txn_sub_type_rec => p_txn_sub_type_rec,
2883 p_order_line_rec => p_order_line_rec,
2884 x_txn_line_detail_tbl => x_txn_line_detail_tbl,
2885 x_txn_ii_rltns_tbl => x_txn_ii_rltns_tbl,
2886 x_order_shipment_tbl => x_order_shipment_tbl,
2887 x_return_status => l_return_status );
2888
2889 IF l_return_status <> fnd_api.g_ret_sts_success THEN
2890 raise fnd_api.g_exc_error;
2891 END IF;
2892
2893 EXCEPTION
2894 WHEN FND_API.G_EXC_ERROR THEN
2895 x_return_status := FND_API.G_RET_STS_ERROR ;
2896 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2897 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2898 END construct_for_txn_exists;
2899
2900 /* ------------------------------------------------------------------------*/
2901 /* procedure compare if the inventory instance and the qty on the shipment */
2902 /* material transaction matches with the installation details and marks */
2903 /* ------------------------------------------------------------------------*/
2904
2905 PROCEDURE match_txn_with_ship(
2906 p_serial_code IN number,
2907 x_txn_line_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
2908 x_order_shipment_tbl IN OUT NOCOPY order_shipment_tbl,
2909 x_return_status OUT NOCOPY varchar2)
2910 IS
2911 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
2912 BEGIN
2913
2914 x_return_status := fnd_api.g_ret_sts_success;
2915
2916 api_log('match_txn_with_ship');
2917 debug(' order_shipment_tbl.count :'||x_order_shipment_tbl.count );
2918 debug(' txn_line_detail_tbl.count :'||x_txn_line_detail_tbl.count);
2919
2920 debug('Trying to match with the instance id.' );
2921
2922 IF x_order_shipment_tbl.count > 0 THEN
2923 FOR i IN x_order_shipment_tbl.FIRST..x_order_shipment_tbl.LAST LOOP
2924
2925 IF x_txn_line_detail_tbl.count > 0 THEN
2926 FOR j IN x_txn_line_detail_tbl.FIRST..x_txn_line_detail_tbl.LAST LOOP
2927
2928 IF x_txn_line_detail_tbl(j).source_transaction_flag = 'Y'
2929 AND
2930 x_txn_line_detail_tbl(j).processing_status in ('SUBMIT','ERROR')
2931 THEN
2932
2933 debug(' td line_detail_id :'||x_txn_line_detail_tbl(j).txn_line_detail_id);
2934 debug(' td instance_id :'||x_txn_line_detail_tbl(j).instance_id);
2935 debug(' td quantity :'||x_txn_line_detail_tbl(j).quantity);
2936
2937 IF x_order_shipment_tbl(i).instance_id =
2938 NVL(x_txn_line_detail_tbl(j).instance_id,-1)
2939 THEN
2940
2941 IF x_order_shipment_tbl(i).shipped_quantity =
2942 x_txn_line_detail_tbl(j).quantity
2943 THEN
2944 x_txn_line_detail_tbl(j).processing_status := 'MATCH' ;
2945 x_order_shipment_tbl(i).instance_match := 'Y';
2946 x_order_shipment_tbl(i).quantity_match := 'Y';
2947 -- Added lot_match for Bug 3384668
2948 x_order_shipment_tbl(i).lot_match := 'N';
2949 x_order_shipment_tbl(i).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
2950 debug('INSTANCE AND QTY MATCH');
2951 exit;
2952 ELSE
2953 x_order_shipment_tbl(i).instance_match := 'Y';
2954 x_order_shipment_tbl(i).quantity_match := 'N';
2955 -- Added lot_match for Bug 3384668
2956 x_order_shipment_tbl(i).lot_match := 'N';
2957 x_txn_line_detail_tbl(j).processing_status := 'INST_MATCH' ;
2958 x_order_shipment_tbl(i).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
2959 debug('INSTANCE MATCH');
2960 END IF;
2961 END IF;
2962 END IF; -- processing status <> 'in_process'
2963 END LOOP; -- end of processing txn table
2964 END IF;
2965 END LOOP; -- end loop processing shipment table
2966 END IF; -- end if shipment table
2967
2968 -- Begin fix for BUg 3384668
2969 debug('Trying to match with Lot Number ');
2970 IF x_order_shipment_tbl.count > 0
2971 THEN
2972 FOR i IN x_order_shipment_tbl.FIRST..x_order_shipment_tbl.LAST
2973 LOOP
2974 IF x_order_shipment_tbl(i).instance_match = 'N'
2975 AND
2976 x_order_shipment_tbl(i).quantity_match = 'N'
2977 AND
2978 x_order_shipment_tbl(i).lot_match = 'N'
2979 THEN
2980 IF x_txn_line_detail_tbl.count > 0
2981 THEN
2982 FOR j IN x_txn_line_detail_tbl.FIRST..x_txn_line_detail_tbl.LAST
2983 LOOP
2984 IF (x_txn_line_detail_tbl(j).source_transaction_flag = 'Y')
2985 AND
2986 (x_txn_line_detail_tbl(j).processing_status in ('ERROR','NO_MATCH','SUBMIT'))
2987 THEN
2988 IF x_order_shipment_tbl(i).lot_number = NVL(x_txn_line_detail_tbl(j).lot_number,-1)
2989 THEN
2990 debug('LOT MATCH for :'||x_txn_line_detail_tbl(j).lot_number);
2991 debug('td line_detail_id :'||x_txn_line_detail_tbl(j).txn_line_detail_id);
2992 debug('td instance_id :'||x_txn_line_detail_tbl(j).instance_id);
2993 debug('td quantity :'||x_txn_line_detail_tbl(j).quantity);
2994
2995 IF x_order_shipment_tbl(i).shipped_quantity = x_txn_line_detail_tbl(j).quantity
2996 THEN
2997 x_order_shipment_tbl(i).instance_match := 'N';
2998 x_order_shipment_tbl(i).lot_match := 'Y';
2999 x_order_shipment_tbl(i).quantity_match := 'Y';
3000 x_txn_line_detail_tbl(j).processing_status := 'MATCH' ;
3001 x_order_shipment_tbl(i).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3002 debug('LOT and QUANTITY Match');
3003 exit;
3004 ELSE
3005 x_order_shipment_tbl(i).instance_match := 'N';
3006 x_order_shipment_tbl(i).lot_match := 'Y';
3007 x_order_shipment_tbl(i).quantity_match := 'N';
3008 x_txn_line_detail_tbl(j).processing_status := 'LOT_MATCH' ;
3009 x_order_shipment_tbl(i).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3010 debug('LOT Match');
3011 END IF;
3012 END IF;
3013 END IF;
3014 END LOOP;
3015 END IF;
3016 END IF;
3017 END LOOP;
3018 END IF;
3019 -- End fix for BUg 3384668
3020
3021 debug('Trying to match with the quantity.' );
3022
3023 IF x_order_shipment_tbl.count > 0 THEN
3024 FOR i IN x_order_shipment_tbl.FIRST..x_order_shipment_tbl.LAST LOOP
3025
3026 IF x_order_shipment_tbl(i).instance_match = 'N'
3027 and
3028 x_order_shipment_tbl(i).quantity_match = 'N'
3029 -- Added the followinh and condition for Bug 3384668
3030 and
3031 x_order_shipment_tbl(i).lot_match = 'N'
3032 THEN
3033
3034 IF x_txn_line_detail_tbl.count > 0 THEN
3035 FOR j IN x_txn_line_detail_tbl.FIRST..x_txn_line_detail_tbl.LAST LOOP
3036
3037 IF (x_txn_line_detail_tbl(j).source_transaction_flag = 'Y')
3038 AND
3039 (x_txn_line_detail_tbl(j).processing_status in ('ERROR','NO_MATCH','SUBMIT'))
3040 THEN
3041
3042 debug(' td line_detail_id :'||x_txn_line_detail_tbl(j).txn_line_detail_id);
3043 debug(' td instance_id :'||x_txn_line_detail_tbl(j).instance_id);
3044 debug(' td quantity :'||x_txn_line_detail_tbl(j).quantity);
3045
3046 IF x_order_shipment_tbl(i).instance_id <> NVL(x_txn_line_detail_tbl(j).instance_id,-1)
3047 -- added the following and condition for bug 3384668
3048 and
3049 -- added nvl for Bug 3523567
3050 nvl(x_order_shipment_tbl(i).lot_number,'@#$') <> nvl(x_txn_line_detail_tbl(j).lot_number,'$#@')
3051 THEN
3052 IF x_order_shipment_tbl(i).shipped_quantity = x_txn_line_detail_tbl(j).quantity
3053 THEN
3054
3055 x_order_shipment_tbl(i).instance_match := 'N';
3056 x_order_shipment_tbl(i).quantity_match := 'Y';
3057 -- Added lot_match for Bug 3384668
3058 x_order_shipment_tbl(i).lot_match := 'N';
3059 x_txn_line_detail_tbl(j).processing_status := 'QTY_MATCH' ;
3060 x_order_shipment_tbl(i).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3061 debug('QTY MATCH');
3062 exit;
3063 ELSE
3064 x_order_shipment_tbl(i).instance_match := 'N';
3065 x_order_shipment_tbl(i).quantity_match := 'N';
3066 -- Added lot_match for Bug 3384668
3067 x_order_shipment_tbl(i).lot_match := 'N';
3068 x_txn_line_detail_tbl(j).processing_status := 'NO_MATCH' ;
3069 debug('NEITHER INSTANCE, LOT NUMBER OR QTY MATCH ');
3070 END IF;
3071 END IF;
3072 END IF; -- processing status <> 'in_process'
3073 END LOOP; -- end of processing txn table
3074 END IF;
3075 END IF; -- end if inst_match = N and qty_match = N
3076 END LOOP; -- end of processing shipment table
3077 END IF;
3078 EXCEPTION
3079 WHEN FND_API.G_EXC_ERROR THEN
3080 x_return_status := FND_API.G_RET_STS_ERROR ;
3081 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3082 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3083 END match_txn_with_ship;
3084
3085 /*----------------------------------------------------------*/
3086 /* Description : Procedure that matches the unresolved */
3087 /* the txn line details and updates the txn line dtls */
3088 /* with the processing_status as "IN_PROCESS" */
3089 /*----------------------------------------------------------*/
3090
3091 PROCEDURE process_txn_dtl(
3092 p_serial_code IN NUMBER,
3093 p_txn_sub_type_rec IN txn_sub_type_rec,
3094 p_order_line_rec IN order_line_rec,
3095 x_txn_line_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
3096 x_txn_ii_rltns_tbl IN csi_t_datastructures_grp.txn_ii_rltns_tbl,
3097 x_order_shipment_tbl IN OUT NOCOPY order_shipment_tbl,
3098 x_return_status OUT NOCOPY varchar2)
3099 IS
3100
3101 x_msg_count number ;
3102 x_msg_data varchar2(2000);
3103 l_upd number := 1;
3104 l_exit_flag boolean := FALSE;
3105 l_config_exists boolean := FALSE;
3106 l_tmp number;
3107 l_proc_qty number;
3108 l_total_proc_qty number;
3109 l_rem_qty number; --fix for bug 4354267
3110
3111 l_upd_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
3112 l_upd_txn_line_dtl_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
3113 l_upd_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
3114 l_upd_txn_party_detail_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
3115 l_upd_txn_pty_acct_dtl_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
3116 l_upd_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
3117 l_upd_txn_ext_attr_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
3118
3119 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
3120 l_msg_count number;
3121 l_msg_data varchar2(2000);
3122
3123 BEGIN
3124
3125 /* Initialize API return status to success */
3126 x_return_status := fnd_api.g_ret_sts_success;
3127
3128 api_log('process_txn_dtl');
3129
3130 /* assign values for the columns in l_upd_txn_line_rec */
3131 l_upd_txn_line_rec.transaction_line_id := p_order_line_rec.trx_line_id;
3132 l_upd_txn_line_rec.source_transaction_id := p_order_line_rec.order_line_id;
3133 l_upd_txn_line_rec.source_transaction_type_id := g_txn_type_id;
3134 l_upd_txn_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
3135
3136 /* Initialize the pl/sql tables used for processing */
3137 l_upd_txn_line_dtl_tbl.delete;
3138 l_upd_txn_ii_rltns_tbl.delete;
3139 l_upd_txn_party_detail_tbl.delete;
3140 l_upd_txn_pty_acct_dtl_tbl.delete ;
3141 l_upd_txn_org_assgn_tbl.delete;
3142 l_upd_txn_ext_attr_vals_tbl.delete;
3143
3144 debug(' order_shipment_tbl.count :'||x_order_shipment_tbl.count);
3145 debug(' txn_line_detail_tbl.count :'||x_txn_line_detail_tbl.count);
3146
3147 IF x_order_shipment_tbl.count > 0 THEN
3148 FOR i IN x_order_shipment_tbl.FIRST..x_order_shipment_tbl.LAST
3149 LOOP
3150
3151 IF ( x_order_shipment_tbl(i).instance_match = 'Y'
3152 -- Added the or condition for bug 3384668
3153 OR
3154 x_order_shipment_tbl(i).lot_match = 'Y'
3155 )
3156 AND
3157 ( x_order_shipment_tbl(i).quantity_match = 'N' )
3158 THEN
3159
3160 debug('INSTANCE/LOT MATCH BUT QTY DOES NOT MATCH');
3161
3162 IF x_txn_line_detail_tbl.count > 0 THEN
3163 FOR j in x_txn_line_detail_tbl.first..x_txn_line_detail_tbl.last
3164 LOOP
3165
3166 IF x_txn_line_detail_tbl(j).source_transaction_flag = 'Y' AND
3167 x_txn_line_detail_tbl(j).processing_status <> 'IN_PROCESS' THEN
3168
3169 IF (x_txn_line_detail_tbl(j).txn_line_detail_id = x_order_shipment_tbl(i).txn_line_detail_id)
3170 AND
3171 (x_txn_line_detail_tbl(j).processing_status = 'INST_MATCH'
3172 -- Added the or condition for bug 3384668
3173 OR
3174 x_txn_line_detail_tbl(j).processing_status = 'LOT_MATCH'
3175 )
3176 THEN
3177
3178 debug('Checking if Config exists.. ');
3179
3180 l_config_exists := csi_utl_pkg.Check_config_exists(
3181 x_txn_ii_rltns_tbl,
3182 x_txn_line_detail_tbl(j).txn_line_detail_id);
3183
3184 IF l_config_exists AND
3185 x_txn_line_detail_tbl(j).preserve_detail_flag = 'N' THEN
3186
3187 debug('Config exists so ignoring txn_dtls and creating one ');
3188
3189 /* update the txn_line_detail as ERROR and create new txn_line_dtls*/
3190
3191 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3192 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'ERROR';
3193
3194 csi_utl_pkg.create_txn_details(
3195 x_txn_line_dtl_rec => x_txn_line_detail_tbl(j),
3196 p_txn_sub_type_rec => p_txn_sub_type_rec,
3197 p_order_shipment_rec => x_order_shipment_tbl(i),
3198 p_order_line_rec => p_order_line_rec,
3199 x_return_status => x_return_status);
3200
3201 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3202 raise fnd_api.g_exc_error;
3203 END IF;
3204
3205 l_upd := l_upd +1;
3206
3207 x_order_shipment_tbl(i).quantity_match := 'Y';
3208 -- Added the IF/ELSE for 3384668
3209 -- x_order_shipment_tbl(i).instance_match := 'Y';
3210 IF x_order_shipment_tbl(i).instance_match = 'Y'
3211 THEN
3212 x_order_shipment_tbl(i).instance_match := 'Y';
3213 ELSE
3214 x_order_shipment_tbl(i).lot_match := 'Y';
3215 END IF;
3216
3217 x_txn_line_detail_tbl(j).processing_status := 'IN_PROCESS';
3218 exit;
3219 ELSE
3220
3221 IF x_order_shipment_tbl(i).shipped_quantity > x_txn_line_detail_tbl(j).quantity THEN
3222
3223 debug('shipped_qty > txn_dtl_qty ');
3224
3225 /*---------------------------------------------------------*/
3226 /* Process the txn_line_dtl and check if there are other */
3227 /* txn_line_dtls with the same instance. Else create a */
3228 /* txn_line_dtl with the shipment details for remaining qty*/
3229 /*---------------------------------------------------------*/
3230
3231 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3232 l_upd_txn_line_dtl_tbl(l_upd).preserve_detail_flag := 'Y';
3233 l_upd_txn_line_dtl_tbl(l_upd).serial_number := x_order_shipment_tbl(i).serial_number;
3234 l_upd_txn_line_dtl_tbl(l_upd).lot_number := x_order_shipment_tbl(i).lot_number;
3235 l_upd_txn_line_dtl_tbl(l_upd).inv_organization_id := x_order_shipment_tbl(i).organization_id;
3236 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'IN_PROCESS';
3237 l_upd_txn_line_dtl_tbl(l_upd).changed_instance_id := x_txn_line_detail_tbl(j).changed_instance_id;
3238
3239 -- Begin fix for Bug 3384668
3240 l_upd_txn_line_dtl_tbl(l_upd).inventory_item_id := x_order_shipment_tbl(i).inventory_item_id;
3241 l_upd_txn_line_dtl_tbl(l_upd).instance_id := x_order_shipment_tbl(i).instance_id;
3242 -- End fix for Bug 3384668
3243
3244 /* Begin fix for Bug 2972082 cascade owner flag */
3245 l_upd_txn_line_dtl_tbl(l_upd).cascade_owner_flag := x_txn_line_detail_tbl(j).cascade_owner_flag;
3246 /* end fix for Bug 2972082 cascade owner flag */
3247
3248 l_proc_qty := x_order_shipment_tbl(i).shipped_quantity - x_txn_line_detail_tbl(j).quantity;
3249 x_txn_line_detail_tbl(j).processing_status := 'IN_PROCESS';
3250
3251 debug('Remaining qty to process ='||l_proc_qty);
3252
3253 csi_utl_pkg.split_ship_rec(
3254 x_upd_txn_line_dtl_tbl => l_upd_txn_line_dtl_tbl,
3255 x_txn_line_detail_tbl => x_txn_line_detail_tbl,
3256 x_txn_line_detail_rec => x_txn_line_detail_tbl(j),
3257 p_txn_sub_type_rec => p_txn_sub_type_rec,
3258 p_order_shipment_rec => x_order_shipment_tbl(i),
3259 p_order_line_rec => p_order_line_rec,
3260 p_proc_qty => l_proc_qty,
3261 x_return_status => x_return_status );
3262
3263 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3264 raise fnd_api.g_exc_error;
3265 END IF;
3266
3267 debug('After split_ship_rec ');
3268 debug(' upd_txn_line_dtl_tbl.count : '||l_upd_txn_line_dtl_tbl.count);
3269 debug(' txn_line_detail_tbl.count : '||x_txn_line_detail_tbl.count);
3270
3271 x_order_shipment_tbl(i).quantity_match := 'Y';
3272 -- Added the IF/ELSE for 3384668
3273 -- x_order_shipment_tbl(i).instance_match := 'Y';
3274 IF x_order_shipment_tbl(i).instance_match = 'Y'
3275 THEN
3276 x_order_shipment_tbl(i).instance_match := 'Y';
3277 ELSE
3278 x_order_shipment_tbl(i).lot_match := 'Y';
3279 END IF;
3280
3281 l_upd := l_upd +1;
3282
3283 exit;
3284
3285 ELSIF x_txn_line_detail_tbl(j).quantity > x_order_shipment_tbl(i).shipped_quantity THEN
3286
3287 debug('shipped_qty < txn_dtl_qty ');
3288
3289 /* update the txn_detail with the qty of difference between txn_line_dtls and shipment*/
3290
3291 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3292 -- Begin change for Bug 3384668
3293 -- l_upd_txn_line_dtl_tbl(l_upd).quantity
3294 -- := x_txn_line_detail_tbl(j).quantity - x_order_shipment_tbl(i).shipped_quantity;
3295 l_upd_txn_line_dtl_tbl(l_upd).quantity := x_order_shipment_tbl(i).shipped_quantity;
3296 -- End change for Bug 3384668
3297 l_upd_txn_line_dtl_tbl(l_upd).inv_organization_id := x_order_shipment_tbl(i).organization_id;
3298 l_upd_txn_line_dtl_tbl(l_upd).serial_number := x_order_shipment_tbl(i).serial_number;
3299 l_upd_txn_line_dtl_tbl(l_upd).lot_number := x_order_shipment_tbl(i).lot_number;
3300 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'IN_PROCESS';
3301 l_upd_txn_line_dtl_tbl(l_upd).preserve_detail_flag := 'Y';
3302 l_upd_txn_line_dtl_tbl(l_upd).changed_instance_id :=
3303 x_txn_line_detail_tbl(j).changed_instance_id;
3304
3305 -- Begin fix for Bug 3384668
3306 l_upd_txn_line_dtl_tbl(l_upd).inventory_item_id := x_order_shipment_tbl(i).inventory_item_id;
3307 l_upd_txn_line_dtl_tbl(l_upd).instance_id := x_order_shipment_tbl(i).instance_id;
3308 -- End fix for Bug 3384668
3309
3310 /* Begin fix for Bug 2972082 cascade owner flag */
3311 l_upd_txn_line_dtl_tbl(l_upd).cascade_owner_flag := x_txn_line_detail_tbl(j).cascade_owner_flag;
3312 /* end fix for Bug 2972082 cascade owner flag */
3313
3314 debug('shipped_qty ='||x_order_shipment_tbl(i).shipped_quantity);
3315 debug('txn_qty ='||x_txn_line_detail_tbl(j).quantity);
3316
3317 /* create_txn_line_dtls with the shipped qty */
3318 csi_utl_pkg.create_txn_details(
3319 x_txn_line_dtl_rec => x_txn_line_detail_tbl(j),
3320 p_txn_sub_type_rec => p_txn_sub_type_rec,
3321 p_order_shipment_rec => x_order_shipment_tbl(i),
3322 p_order_line_rec => p_order_line_rec,
3323 x_return_status => x_return_status );
3324
3325 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3326 raise fnd_api.g_exc_error;
3327 END IF;
3328
3329 UPDATE csi_t_txn_line_details
3330 SET processing_status = 'SUBMIT'
3331 WHERE txn_line_detail_id = x_txn_line_detail_tbl(j).txn_line_detail_id;
3332
3333 l_upd := l_upd +1;
3334
3335 x_order_shipment_tbl(i).quantity_match := 'Y';
3336 -- Added the IF/ELSE for 3384668
3337 -- x_order_shipment_tbl(i).instance_match := 'Y';
3338 IF x_order_shipment_tbl(i).instance_match = 'Y'
3339 THEN
3340 x_order_shipment_tbl(i).instance_match := 'Y';
3341 ELSE
3342 x_order_shipment_tbl(i).lot_match := 'Y';
3343 END IF;
3344 x_txn_line_detail_tbl(j).processing_status := 'IN_PROCESS';
3345
3346 exit;
3347 END IF;
3348 END IF;
3349 END IF;
3350 END IF;
3351 END LOOP;
3352 END IF;
3353 ELSIF ( x_order_shipment_tbl(i).instance_match = 'Y'
3354 -- added the or condition for bug 3384668
3355 OR
3356 x_order_shipment_tbl(i).lot_match = 'Y'
3357 )
3358 AND
3359 ( x_order_shipment_tbl(i).quantity_match = 'Y' )
3360 THEN
3361
3362 debug('BOTH INSTANCE/LOT AND QTY MATCH ');
3363
3364 IF x_txn_line_detail_tbl.count > 0 THEN
3365 FOR j in x_txn_line_detail_tbl.first..x_txn_line_detail_tbl.last LOOP
3366
3367 -- debug('txn_line_detail_id ='||x_txn_line_detail_tbl(j).txn_line_detail_id);
3368
3369 IF x_txn_line_detail_tbl(j).source_transaction_flag = 'Y' AND
3370 x_txn_line_detail_tbl(j).processing_status <> 'IN_PROCESS' THEN
3371
3372 IF (x_txn_line_detail_tbl(j).txn_line_detail_id = x_order_shipment_tbl(i).txn_line_detail_id ) AND
3373 (x_txn_line_detail_tbl(j).processing_status = 'MATCH' ) THEN
3374
3375 /* Process the txn_line_dtls as both instance and qty matches */
3376
3377 debug('Processing the txn_dtl ');
3378
3379 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3380 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'IN_PROCESS' ;
3381 l_upd_txn_line_dtl_tbl(l_upd).preserve_detail_flag := 'Y';
3382 l_upd_txn_line_dtl_tbl(l_upd).serial_number := x_order_shipment_tbl(i).serial_number;
3383 l_upd_txn_line_dtl_tbl(l_upd).lot_number := x_order_shipment_tbl(i).lot_number;
3384 l_upd_txn_line_dtl_tbl(l_upd).inv_organization_id := x_order_shipment_tbl(i).organization_id;
3385
3386 -- Begin fix for Bug 3384668
3387 l_upd_txn_line_dtl_tbl(l_upd).inventory_item_id := x_order_shipment_tbl(i).inventory_item_id;
3388 l_upd_txn_line_dtl_tbl(l_upd).instance_id := x_order_shipment_tbl(i).instance_id;
3389 l_upd_txn_line_dtl_tbl(l_upd).changed_instance_id := x_txn_line_detail_tbl(j).changed_instance_id;
3390 -- End fix for Bug 3384668
3391
3392 /* Begin fix for Bug 2972082 cascade owner flag */
3393 l_upd_txn_line_dtl_tbl(l_upd).cascade_owner_flag := x_txn_line_detail_tbl(j).cascade_owner_flag;
3394 /* end fix for Bug 2972082 cascade owner flag */
3395
3396 l_upd := l_upd +1;
3397
3398 x_txn_line_detail_tbl(j).processing_status := 'IN_PROCESS';
3399 x_order_shipment_tbl(i).quantity_match := 'Y';
3400
3401 -- Begin fix for Bug 3384668
3402 IF x_order_shipment_tbl(i).lot_match = 'Y'
3403 THEN
3404 x_order_shipment_tbl(i).lot_match := 'Y';
3405 ELSE
3406 -- End fix for Bug 3384668
3407 x_order_shipment_tbl(i).instance_match := 'Y';
3408 END IF;
3409 exit;
3410 END IF;
3411 END IF;
3412
3413 END LOOP;
3414 END IF;
3415
3416 ELSIF (x_order_shipment_tbl(i).instance_match = 'N' )
3417 -- added the lot_match and condition for Bug 3384668
3418 AND
3419 (x_order_shipment_tbl(i).lot_match = 'N' )
3420 AND
3421 (x_order_shipment_tbl(i).quantity_match = 'Y' )
3422 THEN
3423
3424 debug('QTY MATCH BUT INSTANCE/LOT DOES NOT MATCH ');
3425
3426 IF x_txn_line_detail_tbl.count > 0 THEN
3427 FOR j in x_txn_line_detail_tbl.first..x_txn_line_detail_tbl.last LOOP
3428
3429 IF x_txn_line_detail_tbl(j).source_transaction_flag = 'Y'
3430 AND
3431 x_txn_line_detail_tbl(j).processing_status <> 'IN_PROCESS'
3432 THEN
3433
3434 IF x_txn_line_detail_tbl(j).txn_line_detail_id = x_order_shipment_tbl(i).txn_line_detail_id
3435 AND
3436 x_txn_line_detail_tbl(j).processing_status = 'QTY_MATCH'
3437 THEN
3438
3439 IF (x_txn_line_detail_tbl(j).instance_exists_flag = 'N' ) THEN
3440
3441 debug('No instance reference exists,so processing the txn line ');
3442
3443 /* update the txn_detail with the instance in shipping record */
3444 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id :=
3445 x_txn_line_detail_tbl(j).txn_line_detail_id;
3446 l_upd_txn_line_dtl_tbl(l_upd).instance_id :=
3447 x_order_shipment_tbl(i).instance_id;
3448 l_upd_txn_line_dtl_tbl(l_upd).instance_exists_flag := 'Y';
3449 l_upd_txn_line_dtl_tbl(l_upd).quantity :=
3450 x_order_shipment_tbl(i).shipped_quantity;
3451 l_upd_txn_line_dtl_tbl(l_upd).preserve_detail_flag := 'Y';
3452 l_upd_txn_line_dtl_tbl(l_upd).serial_number :=
3453 x_order_shipment_tbl(i).serial_number;
3454 l_upd_txn_line_dtl_tbl(l_upd).lot_number :=
3455 x_order_shipment_tbl(i).lot_number;
3456 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'IN_PROCESS';
3457 l_upd_txn_line_dtl_tbl(l_upd).inv_organization_id :=
3458 x_order_shipment_tbl(i).organization_id;
3459 l_upd_txn_line_dtl_tbl(l_upd).inventory_item_id :=
3460 x_order_shipment_tbl(i).inventory_item_id;
3461 l_upd_txn_line_dtl_tbl(l_upd).changed_instance_id :=
3462 x_txn_line_detail_tbl(j).changed_instance_id;
3463 /* Begin fix for Bug 2972082 cascade owner flag */
3464 l_upd_txn_line_dtl_tbl(l_upd).cascade_owner_flag :=
3465 x_txn_line_detail_tbl(j).cascade_owner_flag;
3466 /* end fix for Bug 2972082 cascade owner flag */
3467 l_upd := l_upd +1;
3468 exit;
3469 ELSE
3470
3471 debug('Checking if config exists ');
3472
3473 l_config_exists := csi_utl_pkg.Check_config_exists(
3474 x_txn_ii_rltns_tbl,
3475 x_txn_line_detail_tbl(j).txn_line_detail_id);
3476 IF l_config_exists
3477 AND
3478 x_txn_line_detail_tbl(j).preserve_detail_flag = 'N'
3479 THEN
3480
3481 /* update the txn_dtls as errored and create txn_dtls from shipping rec */
3482
3483 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3484 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'ERROR' ;
3485 l_upd := l_upd +1;
3486
3487 debug('Config exists so ignoring the txn_line_dtl and creating one');
3488
3489 csi_utl_pkg.create_txn_details(
3490 x_txn_line_dtl_rec => x_txn_line_detail_tbl(j),
3491 p_txn_sub_type_rec => p_txn_sub_type_rec,
3492 p_order_shipment_rec => x_order_shipment_tbl(i),
3493 p_order_line_rec => p_order_line_rec,
3494 x_return_status => x_return_status );
3495
3496 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3497 raise fnd_api.g_exc_error;
3498 END IF;
3499
3500 x_order_shipment_tbl(i).quantity_match := 'Y';
3501 x_order_shipment_tbl(i).instance_match := 'Y';
3502 x_txn_line_detail_tbl(j).processing_status := 'MATCH';
3503 exit;
3504 ELSE
3505
3506 /*update the txn_detail with the instance in shipping record */
3507
3508 debug('Config does not exists, so processing the txn line dtls ');
3509
3510 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id :=
3511 x_txn_line_detail_tbl(j).txn_line_detail_id;
3512 l_upd_txn_line_dtl_tbl(l_upd).instance_id :=
3513 x_order_shipment_tbl(i).instance_id;
3514 l_upd_txn_line_dtl_tbl(l_upd).instance_exists_flag := 'Y';
3515 l_upd_txn_line_dtl_tbl(l_upd).quantity :=
3516 x_order_shipment_tbl(i).shipped_quantity;
3517 l_upd_txn_line_dtl_tbl(l_upd).preserve_detail_flag := 'Y';
3518 l_upd_txn_line_dtl_tbl(l_upd).serial_number :=
3519 x_order_shipment_tbl(i).serial_number;
3520 l_upd_txn_line_dtl_tbl(l_upd).lot_number :=
3521 x_order_shipment_tbl(i).lot_number;
3522 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'IN_PROCESS';
3523 l_upd_txn_line_dtl_tbl(l_upd).inv_organization_id :=
3524 x_order_shipment_tbl(i).organization_id;
3525 l_upd_txn_line_dtl_tbl(l_upd).changed_instance_id :=
3526 x_txn_line_detail_tbl(j).changed_instance_id;
3527 /* Added the item id assignment for bug 3734427 */
3528 l_upd_txn_line_dtl_tbl(l_upd).inventory_item_id :=
3529 x_order_shipment_tbl(i).inventory_item_id;
3530 /* Begin fix for Bug 2972082 cascade owner flag */
3531 l_upd_txn_line_dtl_tbl(l_upd).cascade_owner_flag :=
3532 x_txn_line_detail_tbl(j).cascade_owner_flag;
3533 /* end fix for Bug 2972082 cascade owner flag */
3534
3535 l_upd := l_upd +1;
3536
3537 x_order_shipment_tbl(i).quantity_match := 'Y';
3538 x_order_shipment_tbl(i).instance_match := 'Y';
3539 x_txn_line_detail_tbl(j).processing_status := 'MATCH';
3540 exit;
3541 END IF;
3542 END IF;
3543 END IF;
3544 END IF;
3545 END LOOP;
3546 END IF;
3547 ELSIF ( x_order_shipment_tbl(i).instance_match = 'N' )
3548 AND
3549 ( x_order_shipment_tbl(i).quantity_match = 'N' )
3550 -- added the and condition for bug 3384668
3551 AND
3552 ( x_order_shipment_tbl(i).lot_match = 'N' )
3553 THEN
3554
3555 debug('NEITHER INSTANCE, LOT OR QTY MATCH ');
3556 l_total_proc_qty := x_order_shipment_tbl(i).shipped_quantity;
3557
3558 debug('total_proc_qty :' ||l_total_proc_qty);
3559
3560 IF x_txn_line_detail_tbl.count > 0 THEN
3561 FOR j in x_txn_line_detail_tbl.first..x_txn_line_detail_tbl.last LOOP
3562
3563 IF x_txn_line_detail_tbl(j).source_transaction_flag = 'Y' AND
3564 x_txn_line_detail_tbl(j).processing_status <> 'IN_PROCESS' THEN
3565
3566 IF x_txn_line_detail_tbl(j).instance_exists_flag = 'N' THEN
3567
3568 debug('Checking if config exists ');
3569
3570 l_config_exists := csi_utl_pkg.Check_config_exists
3571 (x_txn_ii_rltns_tbl,
3572 x_txn_line_detail_tbl(j).txn_line_detail_id);
3573 IF l_config_exists AND
3574 x_txn_line_detail_tbl(j).preserve_detail_flag = 'N' THEN
3575
3576 debug('Config exists so ignoring the txn_line_dtl and creating one');
3577
3578 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3579 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'ERROR' ;
3580
3581 x_order_shipment_tbl(i).quantity_match := 'Y';
3582 x_order_shipment_tbl(i).instance_match := 'Y';
3583 x_txn_line_detail_tbl(j).processing_status := 'ERROR';
3584
3585 csi_utl_pkg.create_txn_details
3586 (x_txn_line_dtl_rec => x_txn_line_detail_tbl(j)
3587 ,p_txn_sub_type_rec => p_txn_sub_type_rec
3588 ,p_order_shipment_rec => x_order_shipment_tbl(i)
3589 ,p_order_line_rec => p_order_line_rec
3590 ,x_return_status => x_return_status );
3591
3592 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3593 raise fnd_api.g_exc_error;
3594 END IF;
3595
3596 l_upd := l_upd +1;
3597
3598 exit;
3599 ELSE
3600
3601 debug('Config does not exist so processing the txn_line_dtl ');
3602
3603 /* update txn_detail with the instance from shipping record */
3604 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3605 l_upd_txn_line_dtl_tbl(l_upd).instance_id := x_order_shipment_tbl(i).instance_id;
3606 l_upd_txn_line_dtl_tbl(l_upd).serial_number := x_order_shipment_tbl(i).serial_number;
3607 IF nvl(x_order_shipment_tbl(i).serial_number, fnd_api.g_miss_char) <> fnd_api.g_miss_char THEN
3608 l_upd_txn_line_dtl_tbl(l_upd).mfg_serial_number_flag := 'Y';
3609 END IF;
3610 debug('Serial Number :'||l_upd_txn_line_dtl_tbl(l_upd).serial_number);
3611 l_upd_txn_line_dtl_tbl(l_upd).lot_number := x_order_shipment_tbl(i).lot_number;
3612 l_upd_txn_line_dtl_tbl(l_upd).preserve_detail_flag := 'Y';
3613 l_upd_txn_line_dtl_tbl(l_upd).instance_exists_flag := 'Y';
3614 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'IN_PROCESS';
3615 l_upd_txn_line_dtl_tbl(l_upd).inv_organization_id := x_order_shipment_tbl(i).organization_id;
3616 /* Added the item id assignment for bug 3734427 */
3617 l_upd_txn_line_dtl_tbl(l_upd).inventory_item_id := x_order_shipment_tbl(i).inventory_item_id;
3618
3619 /* Begin fix for Bug 2972082 cascade owner flag */
3620 l_upd_txn_line_dtl_tbl(l_upd).cascade_owner_flag := x_txn_line_detail_tbl(j).cascade_owner_flag;
3621 /* end fix for Bug 2972082 cascade owner flag */
3622
3623 IF l_total_proc_qty > x_txn_line_detail_tbl(j).quantity THEN
3624 l_total_proc_qty := l_total_proc_qty - x_txn_line_detail_tbl(j).quantity;
3625 --Start of fix for bug 4354267
3626 ELSIF l_total_proc_qty < x_txn_line_detail_tbl(j).quantity THEN
3627 l_upd_txn_line_dtl_tbl(l_upd).quantity := l_total_proc_qty;
3628 l_rem_qty := x_txn_line_detail_tbl(j).quantity - l_total_proc_qty;
3629 debug('Installation line detail quantity > mtl transaction quantity,so split line dtls');
3630 csi_utl_pkg.split_txn_dtls_with_qty(
3631 split_txn_dtl_id => x_txn_line_detail_tbl(j).txn_line_detail_id,
3632 p_split_qty => l_rem_qty,
3633 x_return_status => l_return_status );
3634 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3635 raise fnd_api.g_exc_error;
3636 END IF;
3637 exit;
3638 --End of fix for bug 4354267
3639 ELSE
3640 l_upd_txn_line_dtl_tbl(l_upd).quantity := l_total_proc_qty;
3641 exit;
3642 END IF;
3643
3644 x_order_shipment_tbl(i).quantity_match := 'Y';
3645 x_order_shipment_tbl(i).instance_match := 'Y';
3646 x_txn_line_detail_tbl(j).processing_status := 'IN_PROCESS';
3647 l_upd := l_upd +1;
3648
3649 IF x_order_shipment_tbl.count > 1 THEN
3650 exit;
3651 END IF;
3652
3653 END IF;
3654 ELSE
3655
3656 debug('Instance reference exists so ignoring the txn_line_dtls and creating one ');
3657
3658 l_upd_txn_line_dtl_tbl(l_upd).txn_line_detail_id := x_txn_line_detail_tbl(j).txn_line_detail_id;
3659 l_upd_txn_line_dtl_tbl(l_upd).processing_status := 'ERROR' ;
3660
3661 csi_utl_pkg.create_txn_details
3662 (x_txn_line_dtl_rec => x_txn_line_detail_tbl(j)
3663 ,p_txn_sub_type_rec => p_txn_sub_type_rec
3664 ,p_order_shipment_rec => x_order_shipment_tbl(i)
3665 ,p_order_line_rec => p_order_line_rec
3666 ,x_return_status => x_return_status );
3667
3668 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3669 raise fnd_api.g_exc_error;
3670 END IF;
3671
3672 l_upd := l_upd +1;
3673
3674 x_txn_line_detail_tbl(j).processing_status := 'IN_PROCESS';
3675 x_order_shipment_tbl(i).quantity_match := 'Y';
3676 x_order_shipment_tbl(i).instance_match := 'Y';
3677 exit;
3678
3679 END IF;
3680 END IF;
3681
3682 END LOOP;
3683 END IF;
3684 END IF;
3685
3686 END LOOP;
3687 END IF;
3688
3689 debug('Stamping the transaction details with the material transaction info.');
3690 debug(' upd_txn_line_dtl_tbl.count :'||l_upd_txn_line_dtl_tbl.count);
3691
3692 IF l_upd_txn_line_dtl_tbl.count > 0 then
3693
3694 /* update the txn dtls with the processing status */
3695
3696 csi_t_txn_details_grp.update_txn_line_dtls(
3697 p_api_version => 1.0,
3698 p_commit => fnd_api.g_false,
3699 p_init_msg_list => fnd_api.g_true,
3700 p_validation_level => fnd_api.g_valid_level_none,
3701 p_txn_line_rec => l_upd_txn_line_rec,
3702 p_txn_line_detail_tbl => l_upd_txn_line_dtl_tbl,
3703 px_txn_ii_rltns_tbl => l_upd_txn_ii_rltns_tbl,
3704 px_txn_party_detail_tbl => l_upd_txn_party_detail_tbl,
3705 px_txn_pty_acct_detail_tbl => l_upd_txn_pty_acct_dtl_tbl,
3706 px_txn_org_assgn_tbl => l_upd_txn_org_assgn_tbl,
3707 px_txn_ext_attrib_vals_tbl => l_upd_txn_ext_attr_vals_tbl,
3708 x_return_status => x_return_status,
3709 x_msg_count => x_msg_count,
3710 x_msg_data => x_msg_data);
3711
3712 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
3713 g_api_name := 'csi_t_txn_details_grp.update_txn_line_dtls';
3714 raise fnd_api.g_exc_error;
3715 END IF;
3716
3717 debug('update_txn_line_dtls completed successfully');
3718
3719 END IF;
3720
3721 EXCEPTION
3722 WHEN FND_API.G_EXC_ERROR THEN
3723 x_return_status := FND_API.G_RET_STS_ERROR ;
3724 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3725 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3726 END process_txn_dtl;
3727
3728 PROCEDURE decrement_source_instance(
3729 p_instance_id in number,
3730 p_quantity in number,
3731 p_trx_rec in OUT NOCOPY csi_datastructures_pub.transaction_rec,
3732 x_return_status OUT NOCOPY varchar2)
3733 IS
3734
3735 l_instance_rec csi_datastructures_pub.instance_rec;
3736 l_party_tbl csi_datastructures_pub.party_tbl;
3737 l_party_acct_tbl csi_datastructures_pub.party_account_tbl;
3738 l_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
3739 l_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
3740 l_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
3741 l_org_units_tbl csi_datastructures_pub.organization_units_tbl;
3742 l_inst_id_lst csi_datastructures_pub.id_tbl;
3743
3744 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
3745 l_msg_count number;
3746 l_msg_data varchar2(2000);
3747
3748 BEGIN
3749
3750 x_return_status := fnd_api.g_ret_sts_success;
3751
3752 api_log('decrement_source_instance');
3753
3754
3755 l_instance_rec.instance_id := p_instance_id;
3756
3757 SELECT object_version_number,
3758 quantity - p_quantity
3759 INTO l_instance_rec.object_version_number,
3760 l_instance_rec.quantity
3761 FROM csi_item_instances
3762 WHERE instance_id = l_instance_rec.instance_id;
3763
3764 csi_t_gen_utility_pvt.dump_api_info(
3765 p_api_name => 'update_item_instance',
3766 p_pkg_name => 'csi_item_instance_pub');
3767
3768 csi_t_gen_utility_pvt.dump_csi_instance_rec(
3769 p_csi_instance_rec => l_instance_rec);
3770
3771 /* decrement the inventory source instance */
3772
3773 csi_item_instance_pub.update_item_instance(
3774 p_api_version => 1.0,
3775 p_commit => fnd_api.g_false,
3776 p_init_msg_list => fnd_api.g_true,
3777 p_validation_level => fnd_api.g_valid_level_full,
3778 p_instance_rec => l_instance_rec,
3779 p_ext_attrib_values_tbl => l_ext_attrib_val_tbl,
3780 p_party_tbl => l_party_tbl,
3781 p_account_tbl => l_party_acct_tbl,
3782 p_pricing_attrib_tbl => l_pricing_attribs_tbl,
3783 p_org_assignments_tbl => l_org_units_tbl,
3784 p_txn_rec => p_trx_rec,
3785 p_asset_assignment_tbl => l_inst_asset_tbl,
3786 x_instance_id_lst => l_inst_id_lst,
3787 x_return_status => l_return_status,
3788 x_msg_count => l_msg_count,
3789 x_msg_data => l_msg_data);
3790
3791 -- For Bug 4057183
3792 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
3793 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
3794 g_api_name := 'csi_item_instance_pub.update_item_instance';
3795 raise fnd_api.g_exc_error;
3796 END IF;
3797
3798 EXCEPTION
3799
3800 WHEN fnd_api.g_exc_error THEN
3801 x_return_status := fnd_api.g_ret_sts_error;
3802
3803 END decrement_source_instance;
3804
3805 PROCEDURE dump_customer_products(
3806 p_cps_tbl IN customer_products_tbl)
3807 IS
3808 l_rec customer_product_rec;
3809 BEGIN
3810 IF p_cps_tbl.COUNT > 0 THEN
3811
3812 debug('InstID Quantity LineID TLDID CSITxnID Serial Lot ');
3813 debug('---------- ---------- ---------- ---------- ---------- --------------- ---------------');
3814
3815 FOR l_ind IN p_cps_tbl.FIRST .. p_cps_tbl.LAST
3816 LOOP
3817
3818 l_rec := p_cps_tbl(l_ind);
3819
3820 debug(rpad(to_char(l_rec.instance_id), 11, ' ')||
3821 rpad(to_char(l_rec.quantity), 11, ' ')||
3822 rpad(to_char(l_rec.line_id), 11, ' ')||
3823 rpad(to_char(l_rec.txn_line_detail_id), 11, ' ')||
3824 rpad(to_char(l_rec.transaction_id), 11, ' ')||
3825 rpad(l_rec.serial_number, 16, ' ')||
3826 rpad(l_rec.lot_number, 16, ' '));
3827
3828 END LOOP;
3829
3830 END IF;
3831
3832 END dump_customer_products;
3833
3834 PROCEDURE make_non_hdr_rec(
3835 p_instance_hdr_rec IN csi_datastructures_pub.instance_header_rec,
3836 x_instance_rec OUT NOCOPY csi_datastructures_pub.instance_rec,
3837 x_return_status OUT NOCOPY varchar2)
3838 IS
3839
3840 l_instance_hdr_tbl csi_datastructures_pub.instance_header_tbl;
3841 l_instance_tbl csi_datastructures_pub.instance_tbl;
3842
3843 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
3844
3845 BEGIN
3846
3847 x_return_status := l_return_status;
3848
3849 api_log('make_non_hdr_rec');
3850
3851
3852 l_instance_hdr_tbl(1) := p_instance_hdr_rec;
3853
3854 csi_utl_pkg.make_non_header_tbl(
3855 p_instance_header_tbl => l_instance_hdr_tbl,
3856 x_instance_tbl => l_instance_tbl,
3857 x_return_status => l_return_status);
3858
3859 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3860 RAISE fnd_api.g_exc_error;
3861 END IF;
3862
3863 x_instance_rec := l_instance_tbl(1);
3864
3865 EXCEPTION
3866 WHEN fnd_api.g_exc_error THEN
3867 x_return_status := fnd_api.g_ret_sts_error;
3868 END make_non_hdr_rec;
3869
3870 PROCEDURE split_instance_using_ratio(
3871 p_instance_id IN number,
3872 p_qty_ratio IN number,
3873 p_qty_completed IN number,
3874 p_organization_id IN number,
3875 px_csi_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
3876 x_splitted_instances OUT NOCOPY csi_datastructures_pub.instance_tbl,
3877 x_return_status OUT NOCOPY varchar2)
3878 IS
3879
3880 l_qty_remaining number;
3881
3882 l_init_instance_rec csi_datastructures_pub.instance_rec;
3883
3884 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
3885 l_msg_data varchar2(2000);
3886 l_msg_count number;
3887
3888 l_split_flag boolean := FALSE;
3889
3890 l_splitted_instances csi_datastructures_pub.instance_tbl;
3891 l_s_ind binary_integer;
3892
3893 -- get_item_instance_details variables
3894 l_g_instance_rec csi_datastructures_pub.instance_header_rec;
3895 l_g_ph_tbl csi_datastructures_pub.party_header_tbl;
3896 l_g_pah_tbl csi_datastructures_pub.party_account_header_tbl;
3897 l_g_ouh_tbl csi_datastructures_pub.org_units_header_tbl;
3898 l_g_pa_tbl csi_datastructures_pub.pricing_attribs_tbl;
3899 l_g_eav_tbl csi_datastructures_pub.extend_attrib_values_tbl;
3900 l_g_ea_tbl csi_datastructures_pub.extend_attrib_tbl;
3901 l_g_iah_tbl csi_datastructures_pub.instance_asset_header_tbl;
3902 l_g_time_stamp date;
3903
3904 -- make_non_hdr variables
3905 l_instance_rec csi_datastructures_pub.instance_rec;
3906
3907 -- update_item_instance variables
3908 l_u_instance_rec csi_datastructures_pub.instance_rec;
3909 l_u_parties_tbl csi_datastructures_pub.party_tbl;
3910 l_u_pty_accts_tbl csi_datastructures_pub.party_account_tbl;
3911 l_u_org_units_tbl csi_datastructures_pub.organization_units_tbl;
3912 l_u_ea_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
3913 l_u_pricing_tbl csi_datastructures_pub.pricing_attribs_tbl;
3914 l_u_assets_tbl csi_datastructures_pub.instance_asset_tbl;
3915 l_u_instance_ids_list csi_datastructures_pub.id_tbl;
3916
3917 -- create_item_instance varaibles
3918 l_c_instance_rec csi_datastructures_pub.instance_rec;
3919 l_c_parties_tbl csi_datastructures_pub.party_tbl;
3920 l_c_pty_accts_tbl csi_datastructures_pub.party_account_tbl;
3921 l_c_org_units_tbl csi_datastructures_pub.organization_units_tbl;
3922 l_c_ea_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
3923 l_c_pricing_tbl csi_datastructures_pub.pricing_attribs_tbl;
3924 l_c_assets_tbl csi_datastructures_pub.instance_asset_tbl;
3925 c_pa_ind binary_integer;
3926
3927 BEGIN
3928
3929 x_return_status := fnd_api.g_ret_sts_success;
3930
3931 api_log('split_instance_using_ratio');
3932
3933 l_s_ind := 0;
3934
3935 l_g_instance_rec.instance_id := p_instance_id;
3936
3937 -- get the instance party and party account info
3938 csi_item_instance_pub.get_item_instance_details(
3939 p_api_version => 1.0,
3940 p_commit => fnd_api.g_false,
3941 p_init_msg_list => fnd_api.g_true,
3942 p_validation_level => fnd_api.g_valid_level_full,
3943 p_instance_rec => l_g_instance_rec,
3944 p_get_parties => fnd_api.g_true,
3945 p_party_header_tbl => l_g_ph_tbl,
3946 p_get_accounts => fnd_api.g_true,
3947 p_account_header_tbl => l_g_pah_tbl,
3948 p_get_org_assignments => fnd_api.g_false,
3949 p_org_header_tbl => l_g_ouh_tbl,
3950 p_get_pricing_attribs => fnd_api.g_false,
3951 p_pricing_attrib_tbl => l_g_pa_tbl,
3952 p_get_ext_attribs => fnd_api.g_false,
3953 p_ext_attrib_tbl => l_g_eav_tbl,
3954 p_ext_attrib_def_tbl => l_g_ea_tbl,
3955 p_get_asset_assignments => fnd_api.g_false,
3956 p_asset_header_tbl => l_g_iah_tbl,
3957 p_time_stamp => l_g_time_stamp,
3958 x_return_status => l_return_status,
3959 x_msg_count => l_msg_count,
3960 x_msg_data => l_msg_data);
3961
3962 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3963 RAISE fnd_api.g_exc_error;
3964 END IF;
3965
3966 make_non_hdr_rec(
3967 p_instance_hdr_rec => l_g_instance_rec,
3968 x_instance_rec => l_instance_rec,
3969 x_return_status => l_return_status);
3970
3971 debug(' Component Instance ID :'||l_instance_rec.instance_id);
3972 debug(' Component Quantity :'||l_instance_rec.quantity);
3973
3974 l_qty_remaining := l_g_instance_rec.quantity;
3975
3976 FOR ind IN 1 .. p_qty_completed
3977 LOOP
3978
3979 IF l_qty_remaining > p_qty_ratio THEN
3980
3981 l_split_flag := TRUE;
3982
3983 -- initialize the record structure
3984 l_c_instance_rec := l_init_instance_rec;
3985 l_u_instance_rec := l_init_instance_rec;
3986
3987 l_qty_remaining := l_qty_remaining - p_qty_ratio;
3988
3989 debug(' Allocated Qty(NEW) :'||p_qty_ratio);
3990 debug(' Remaining Qty(UPD) :'||l_qty_remaining );
3991
3992 l_c_instance_rec := l_instance_rec;
3993
3994 -- substitute create specific attributes
3995 l_c_instance_rec.instance_id := fnd_api.g_miss_num;
3996 l_c_instance_rec.instance_number := fnd_api.g_miss_char;
3997 l_c_instance_rec.object_version_number := 1.0;
3998 l_c_instance_rec.vld_organization_id := p_organization_id;
3999 l_c_instance_rec.quantity := p_qty_ratio;
4000 l_c_instance_rec.operational_status_code:= 'NOT_USED';
4001
4002 -- build party
4003 l_c_parties_tbl.DELETE;
4004 l_c_pty_accts_tbl.DELETE;
4005 c_pa_ind := 0;
4006
4007 IF l_g_ph_tbl.COUNT > 0 THEN
4008
4009 FOR l_pt_ind IN l_g_ph_tbl.FIRST ..l_g_ph_tbl.LAST
4010 LOOP
4011 l_c_parties_tbl(l_pt_ind).instance_party_id := fnd_api.g_miss_num;
4012 l_c_parties_tbl(l_pt_ind).instance_id := fnd_api.g_miss_num;
4013 l_c_parties_tbl(l_pt_ind).party_id :=
4014 l_g_ph_tbl(l_pt_ind).party_id;
4015 l_c_parties_tbl(l_pt_ind).party_source_table :=
4016 l_g_ph_tbl(l_pt_ind).party_source_table;
4017 l_c_parties_tbl(l_pt_ind).relationship_type_code :=
4018 l_g_ph_tbl(l_pt_ind).relationship_type_code;
4019 l_c_parties_tbl(l_pt_ind).contact_flag := 'N';
4020
4021 -- build party account
4022 IF l_g_pah_tbl.COUNT > 0 THEN
4023 FOR l_pa_ind IN l_g_pah_tbl.FIRST..l_g_pah_tbl.LAST
4024 LOOP
4025 IF l_g_pah_tbl(l_pa_ind).instance_party_id = l_g_ph_tbl(l_pt_ind).instance_party_id
4026 THEN
4027 c_pa_ind := c_pa_ind + 1;
4028 l_c_pty_accts_tbl(c_pa_ind).parent_tbl_index := l_pt_ind;
4029 l_c_pty_accts_tbl(c_pa_ind).ip_account_id := fnd_api.g_miss_num;
4030 l_c_pty_accts_tbl(c_pa_ind).instance_party_id := fnd_api.g_miss_num;
4031 l_c_pty_accts_tbl(c_pa_ind).party_account_id :=
4032 l_g_pah_tbl(l_pa_ind).party_account_id;
4033 l_c_pty_accts_tbl(c_pa_ind).relationship_type_code :=
4034 l_g_pah_tbl(l_pa_ind).relationship_type_code;
4035 END IF;
4036 END LOOP;
4037 END IF;
4038
4039 END LOOP;
4040 END IF;
4041
4042 -- create a new instance for the decremented qty
4043
4044 csi_item_instance_pub.create_item_instance(
4045 p_api_version => 1.0,
4046 p_commit => fnd_api.g_false,
4047 p_init_msg_list => fnd_api.g_true,
4048 p_validation_level => fnd_api.g_valid_level_full,
4049 p_instance_rec => l_c_instance_rec,
4050 p_party_tbl => l_c_parties_tbl,
4051 p_account_tbl => l_c_pty_accts_tbl,
4052 p_org_assignments_tbl => l_c_org_units_tbl,
4053 p_ext_attrib_values_tbl => l_c_ea_values_tbl,
4054 p_pricing_attrib_tbl => l_c_pricing_tbl,
4055 p_asset_assignment_tbl => l_c_assets_tbl,
4056 p_txn_rec => px_csi_txn_rec,
4057 x_return_status => l_return_status,
4058 x_msg_count => l_msg_count,
4059 x_msg_data => l_msg_data );
4060
4061 -- For Bug 4057183
4062 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
4063 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
4064 RAISE fnd_api.g_exc_error;
4065 END IF;
4066
4067 debug(' New Instance ID :'||l_c_instance_rec.instance_id);
4068
4069 l_s_ind := l_s_ind + 1;
4070 l_splitted_instances(l_s_ind) := l_c_instance_rec;
4071
4072 -- decrementing the existing wip instance with the remaining quantity
4073 l_u_instance_rec.instance_id := p_instance_id;
4074 l_u_instance_rec.quantity := l_qty_remaining;
4075 l_u_instance_rec.vld_organization_id := p_organization_id;
4076
4077 SELECT object_version_number
4078 INTO l_u_instance_rec.object_version_number
4079 FROM csi_item_instances
4080 WHERE instance_id = l_u_instance_rec.instance_id;
4081
4082 csi_item_instance_pub.update_item_instance(
4083 p_api_version => 1.0,
4084 p_commit => fnd_api.g_false,
4085 p_init_msg_list => fnd_api.g_true,
4086 p_validation_level => fnd_api.g_valid_level_full,
4087 p_instance_rec => l_u_instance_rec,
4088 p_party_tbl => l_u_parties_tbl,
4089 p_account_tbl => l_u_pty_accts_tbl,
4090 p_org_assignments_tbl => l_u_org_units_tbl,
4091 p_ext_attrib_values_tbl => l_u_ea_values_tbl,
4092 p_pricing_attrib_tbl => l_u_pricing_tbl,
4093 p_asset_assignment_tbl => l_u_assets_tbl,
4094 p_txn_rec => px_csi_txn_rec,
4095 x_instance_id_lst => l_u_instance_ids_list,
4096 x_return_status => l_return_status,
4097 x_msg_count => l_msg_count,
4098 x_msg_data => l_msg_data);
4099
4100 -- For Bug 4057183
4101 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
4102 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
4103 RAISE fnd_api.g_exc_error;
4104 END IF;
4105
4106 ELSE
4107
4108 -- we get two cases here < and =
4109 -- when the remaining qty is < ratio do not allocate it to an assy instance
4110 -- making sure that assy instances are always getting the full ratio. this
4111 -- simplifies the process of elliminating assy instances when further partial
4112 -- issues are done. otherwise it is difficult to get the partially allocated
4113 -- component instance and update it with the remaining ratio qty blah blah blah
4114 --(just simplifying my coding)
4115
4116 IF l_qty_remaining < p_qty_ratio THEN
4117 NULL;
4118 ELSE
4119
4120 l_s_ind := l_s_ind + 1;
4121
4122 IF l_split_flag THEN
4123 l_splitted_instances(l_s_ind) := l_u_instance_rec;
4124 ELSE
4125 l_splitted_instances(l_s_ind) := l_instance_rec;
4126 END IF;
4127
4128 END IF;
4129
4130 EXIT;
4131
4132 END IF;
4133
4134 END LOOP;
4135
4136 x_splitted_instances := l_splitted_instances;
4137
4138 EXCEPTION
4139 WHEN fnd_api.g_exc_error THEN
4140 x_return_status := fnd_api.g_ret_sts_error;
4141 END split_instance_using_ratio;
4142
4143 PROCEDURE convert_wip_instance_to_cp(
4144 p_instance_id IN number,
4145 p_line_id IN number,
4146 p_csi_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
4147 x_return_status OUT NOCOPY varchar2)
4148 IS
4149
4150 l_party_site_id number;
4151 l_owner_party_id number;
4152 l_owner_account_id number;
4153
4154 l_order_line_rec oe_order_lines_all%rowtype;
4155 l_order_header_rec oe_order_headers_all%rowtype;
4156
4157 l_location_type_code varchar2(80);
4158 l_inst_object_ver_num number;
4159
4160 l_u_instance_rec csi_datastructures_pub.instance_rec;
4161 l_u_party_tbl csi_datastructures_pub.party_tbl;
4162 l_u_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4163 l_u_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
4164 l_u_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4165 l_u_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4166 l_u_org_units_tbl csi_datastructures_pub.organization_units_tbl;
4167 l_u_inst_id_lst csi_datastructures_pub.id_tbl;
4168
4169 l_instance_party_id number;
4170 l_pty_object_ver_num number;
4171 l_pa_object_ver_num number;
4172
4173 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
4174 l_msg_count number;
4175 l_msg_data varchar2(2000);
4176
4177 BEGIN
4178
4179 x_return_status := fnd_api.g_ret_sts_success;
4180 api_log('convert_wip_instance_to_cp');
4181
4182 -- check if the instance is in WIP
4183 SELECT object_version_number,
4184 location_type_code
4185 INTO l_inst_object_ver_num,
4186 l_location_type_code
4187 FROM csi_item_instances
4188 WHERE instance_id = p_instance_id;
4189
4190 SELECT * INTO l_order_line_rec
4191 FROM oe_order_lines_all
4192 WHERE line_id = p_line_id;
4193
4194 SELECT * INTO l_order_header_rec
4195 FROM oe_order_headers_all
4196 WHERE header_id = l_order_line_rec.header_id;
4197
4198 -- derive location
4199
4200 IF l_order_line_rec.ship_to_org_id is null THEN
4201 l_order_line_rec.ship_to_org_id := l_order_header_rec.ship_to_org_id;
4202 END IF;
4203
4204 IF l_order_line_rec.sold_from_org_id is null THEN
4205 l_order_line_rec.sold_from_org_id := l_order_header_rec.sold_from_org_id;
4206 END IF;
4207
4208 IF l_order_line_rec.sold_to_org_id is null THEN
4209 l_order_line_rec.sold_to_org_id := l_order_header_rec.sold_to_org_id;
4210 END IF;
4211
4212 IF l_order_line_rec.agreement_id is null THEN
4213 l_order_line_rec.agreement_id := l_order_header_rec.agreement_id;
4214 END IF;
4215
4216 IF l_order_line_rec.ship_to_org_id is not null THEN
4217
4218 BEGIN
4219
4220 SELECT HCAS.party_site_id
4221 INTO l_party_site_id
4222 FROM hz_cust_site_uses_all HCSU,
4223 hz_cust_acct_sites_all HCAS
4224 WHERE HCSU.site_use_id = l_order_line_rec.ship_to_org_id
4225 AND HCAS.cust_acct_site_id = HCSU.cust_acct_site_id;
4226
4227 EXCEPTION
4228 WHEN no_data_found THEN
4229
4230 fnd_message.set_name('CSI','CSI_TXN_SITE_USE_INVALID');
4231 fnd_message.set_token('SITE_USE_ID',l_order_line_rec.ship_to_org_id);
4232 fnd_message.set_token('SITE_USE_CODE','SHIP_TO');
4233 fnd_msg_pub.add;
4234 raise fnd_api.g_exc_error;
4235 END;
4236
4237 END IF;
4238
4239 -- update the instance to make it a cp
4240 l_u_instance_rec.instance_id := p_instance_id ;
4241 l_u_instance_rec.vld_organization_id := l_order_line_rec.ship_from_org_id;
4242 l_u_instance_rec.location_type_code := 'HZ_PARTY_SITES';
4243 l_u_instance_rec.location_id := l_party_site_id;
4244 l_u_instance_rec.install_location_type_code := 'HZ_PARTY_SITES';
4245 l_u_instance_rec.install_location_id := l_party_site_id;
4246 l_u_instance_rec.accounting_class_code := 'CUST_PROD';
4247 l_u_instance_rec.active_end_date := null;
4248 l_u_instance_rec.instance_usage_code := 'OUT_OF_ENTERPRISE';
4249 l_u_instance_rec.object_version_number := l_inst_object_ver_num;
4250
4251 -- build owner party
4252
4253 SELECT party_id
4254 INTO l_owner_party_id
4255 FROM hz_cust_accounts
4256 WHERE cust_account_id = l_order_line_rec.sold_to_org_id;
4257
4258 SELECT instance_party_id,
4259 object_version_number
4260 INTO l_instance_party_id,
4261 l_pty_object_ver_num
4262 FROM csi_i_parties
4263 WHERE instance_id = p_instance_id;
4264
4265 l_u_party_tbl(1).instance_party_id := l_instance_party_id;
4266 l_u_party_tbl(1).instance_id := p_instance_id;
4267 l_u_party_tbl(1).party_id := l_owner_party_id;
4268 l_u_party_tbl(1).party_source_table := 'HZ_PARTIES';
4269 l_u_party_tbl(1).relationship_type_code := 'OWNER';
4270 l_u_party_tbl(1).contact_flag := 'N';
4271 l_u_party_tbl(1).object_version_number := l_pty_object_ver_num;
4272
4273 -- build owner account
4274 l_owner_account_id := l_order_line_rec.sold_to_org_id;
4275
4276 l_u_party_acct_tbl(1).ip_account_id := fnd_api.g_miss_num;
4277 l_u_party_acct_tbl(1).party_account_id := l_owner_account_id;
4278 l_u_party_acct_tbl(1).relationship_type_code := 'OWNER';
4279 l_u_party_acct_tbl(1).bill_to_address := fnd_api.g_miss_num;
4280 l_u_party_acct_tbl(1).ship_to_address := fnd_api.g_miss_num;
4281 l_u_party_acct_tbl(1).instance_party_id := l_instance_party_id;
4282 l_u_party_acct_tbl(1).parent_tbl_index := 1;
4283
4284 csi_t_gen_utility_pvt.dump_api_info(
4285 p_api_name => 'update_item_instance',
4286 p_pkg_name => 'csi_item_instance_pub');
4287
4288 csi_item_instance_pub.update_item_instance(
4289 p_api_version => 1.0,
4290 p_commit => fnd_api.g_false,
4291 p_init_msg_list => fnd_api.g_true,
4292 p_validation_level => fnd_api.g_valid_level_full,
4293 p_instance_rec => l_u_instance_rec,
4294 p_ext_attrib_values_tbl => l_u_ext_attrib_val_tbl,
4295 p_party_tbl => l_u_party_tbl,
4296 p_account_tbl => l_u_party_acct_tbl,
4297 p_pricing_attrib_tbl => l_u_pricing_attribs_tbl,
4298 p_org_assignments_tbl => l_u_org_units_tbl,
4299 p_txn_rec => p_csi_txn_rec,
4300 p_asset_assignment_tbl => l_u_inst_asset_tbl,
4301 x_instance_id_lst => l_u_inst_id_lst,
4302 x_return_status => l_return_status,
4303 x_msg_count => l_msg_count,
4304 x_msg_data => l_msg_data);
4305
4306 -- For Bug 4057183
4307 -- IF NOT(l_return_status = fnd_api.g_ret_sts_success) THEN
4308 IF NOT(l_return_status in (fnd_api.g_ret_sts_success,'W')) THEN
4309 raise fnd_api.g_exc_error;
4310 END IF;
4311
4312 debug('WIP instance is successfully converted to a CP.');
4313
4314 EXCEPTION
4315 WHEN fnd_api.g_exc_error THEN
4316 x_return_status := fnd_api.g_ret_sts_error;
4317 END convert_wip_instance_to_cp;
4318
4319 PROCEDURE get_single_qty_instances(
4320 p_all_cps_tbl IN customer_products_tbl,
4321 x_single_cps_tbl OUT nocopy customer_products_tbl)
4322 IS
4323 l_cps_tbl customer_products_tbl;
4324 l_ind binary_integer := 0;
4325 BEGIN
4326 IF p_all_cps_tbl.COUNT > 0 THEN
4327 FOR p_ind IN p_all_cps_tbl.FIRST .. p_all_cps_tbl.LAST
4328 LOOP
4329 IF p_all_cps_tbl(p_ind).quantity = 1 THEN
4330 l_ind := l_ind + 1;
4331 l_cps_tbl(l_ind) := p_all_cps_tbl(p_ind);
4332 END IF;
4333 END LOOP;
4334 END IF;
4335 x_single_cps_tbl := l_cps_tbl;
4336 END get_single_qty_instances;
4337
4338 PROCEDURE get_comp_instances_from_wip(
4339 p_wip_entity_id IN number,
4340 p_organization_id IN number,
4341 p_cps_tbl IN customer_products_tbl,
4342 px_csi_txn_rec IN OUT nocopy csi_datastructures_pub.transaction_rec,
4343 x_iir_tbl OUT nocopy csi_datastructures_pub.ii_relationship_tbl,
4344 x_return_status OUT nocopy varchar2)
4345 IS
4346
4347 l_cps_tbl customer_products_tbl;
4348 l_qty_per_assy number := 0;
4349 l_iir_ind binary_integer := 0;
4350 l_iir_tbl csi_datastructures_pub.ii_relationship_tbl;
4351 l_serial_code number;
4352
4353 l_splitted_instances csi_datastructures_pub.instance_tbl;
4354 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
4355
4356 CURSOR req_cur IS
4357 SELECT wip.inventory_item_id,
4358 sum(required_quantity) qty_required,
4359 sum(quantity_issued) qty_issued,
4360 sum(quantity_per_assembly) qty_per_assy
4361 FROM wip_requirement_operations wip,
4362 mtl_system_items msi
4363 WHERE wip_entity_id = p_wip_entity_id
4364 AND wip.organization_id = p_organization_id
4365 AND wip.inventory_item_id = msi.inventory_item_id
4366 AND wip.organization_id = msi.organization_id
4367 AND nvl(msi.comms_nl_trackable_flag, 'N') = 'Y'
4368 AND nvl(quantity_issued,0) > 0
4369 GROUP BY wip.inventory_item_id;
4370
4371 CURSOR wip_nsrl_cur(p_item_id IN number) IS
4372 SELECT instance_id,
4373 quantity,
4374 serial_number
4375 FROM csi_item_instances
4376 WHERE inventory_item_id = p_item_id
4377 AND location_type_code = 'WIP'
4378 AND wip_job_id = p_wip_entity_id;
4379
4380 CURSOR wip_inst_cur(p_item_id IN number, p_qty_per_assy IN number) IS
4381 SELECT instance_id,
4382 quantity,
4383 serial_number
4384 FROM csi_item_instances
4385 WHERE inventory_item_id = p_item_id
4386 AND location_type_code = 'WIP'
4387 AND wip_job_id = p_wip_entity_id
4388 AND quantity <= p_qty_per_assy;
4389
4390 FUNCTION already_allocated(
4391 p_subject_id IN number,
4392 p_iir_tbl IN csi_datastructures_pub.ii_relationship_tbl)
4393 RETURN BOOLEAN
4394 IS
4395 l_allocated boolean := FALSE;
4396 BEGIN
4397 IF p_iir_tbl.COUNT > 0 THEN
4398 FOR l_ind IN p_iir_tbl.FIRST .. p_iir_tbl.LAST
4399 LOOP
4400 IF p_iir_tbl(l_ind).subject_id = p_subject_id THEN
4401 l_allocated := TRUE;
4402 exit;
4403 END IF;
4404 END LOOP;
4405 END IF;
4406 RETURN l_allocated;
4407 END already_allocated;
4408
4409 BEGIN
4410
4411 x_return_status := fnd_api.g_ret_sts_success;
4412 api_log('get_comp_instances_from_wip');
4413
4414 l_cps_tbl := p_cps_tbl;
4415
4416 FOR req_rec IN req_cur
4417 LOOP
4418
4419 IF req_rec.qty_per_assy > 0 THEN
4420
4421 SELECT serial_number_control_code
4422 INTO l_serial_code
4423 FROM mtl_system_items
4424 WHERE inventory_item_id = req_rec.inventory_item_id
4425 AND organization_id = p_organization_id;
4426
4427 IF l_serial_code in (2, 5) THEN
4428 IF l_cps_tbl.count > 0 THEN
4429 FOR l_cp_ind IN l_cps_tbl.FIRST .. l_cps_tbl.LAST
4430 LOOP
4431 l_qty_per_assy := req_rec.qty_per_assy;
4432 FOR wip_inst_rec IN wip_inst_cur(req_rec.inventory_item_id, req_rec.qty_per_assy)
4433 LOOP
4434 IF l_qty_per_assy > 0 THEN
4435 -- check in iir as subject and skip
4436 IF NOT already_allocated(wip_inst_rec.instance_id, l_iir_tbl) THEN
4437 l_iir_ind := l_iir_ind + 1;
4438 l_iir_tbl(l_iir_ind).subject_id := wip_inst_rec.instance_id;
4439 l_iir_tbl(l_iir_ind).object_id := l_cps_tbl(l_cp_ind).instance_id;
4440 l_iir_tbl(l_iir_ind).relationship_type_code := 'COMPONENT-OF';
4441 l_qty_per_assy := l_qty_per_assy - 1;
4442 END IF;
4443 END IF;
4444 END LOOP;
4445 END LOOP;
4446 END IF;
4447
4448 ELSIF l_serial_code in (1, 6) THEN
4449
4450 -- split_instance_by_ratio
4451 FOR wip_nsrl_rec IN wip_nsrl_cur(req_rec.inventory_item_id)
4452 LOOP
4453
4454 split_instance_using_ratio(
4455 p_instance_id => wip_nsrl_rec.instance_id,
4456 p_qty_ratio => req_rec.qty_per_assy,
4457 p_qty_completed => p_cps_tbl.count,
4458 p_organization_id => p_organization_id,
4459 px_csi_txn_rec => px_csi_txn_rec,
4460 x_splitted_instances => l_splitted_instances,
4461 x_return_status => l_return_status);
4462
4463 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4464 RAISE fnd_api.g_exc_error;
4465 END IF;
4466
4467 END LOOP;
4468
4469 IF l_cps_tbl.count > 0 THEN
4470 FOR l_cp_ind IN l_cps_tbl.FIRST .. l_cps_tbl.LAST
4471 LOOP
4472 FOR wip_inst_rec IN wip_inst_cur(req_rec.inventory_item_id, req_rec.qty_per_assy)
4473 LOOP
4474 -- check in iir as subject and skip
4475 IF NOT already_allocated(wip_inst_rec.instance_id, l_iir_tbl) THEN
4476 l_iir_ind := l_iir_ind + 1;
4477 l_iir_tbl(l_iir_ind).subject_id := wip_inst_rec.instance_id;
4478 l_iir_tbl(l_iir_ind).object_id := l_cps_tbl(l_cp_ind).instance_id;
4479 l_iir_tbl(l_iir_ind).relationship_type_code := 'COMPONENT-OF';
4480 exit;
4481 END IF;
4482 END LOOP;
4483 END LOOP;
4484 END IF;
4485 END IF;
4486
4487 END IF;
4488
4489 END LOOP;
4490
4491 x_iir_tbl := l_iir_tbl;
4492
4493 EXCEPTION
4494 WHEN fnd_api.g_exc_error THEN
4495 x_return_status := fnd_api.g_ret_sts_error;
4496 END get_comp_instances_from_wip;
4497
4498 PROCEDURE get_tld_set(
4499 px_tld_rec IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_rec,
4500 px_tld_party_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
4501 px_tld_account_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
4502 px_tld_oa_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_org_assgn_tbl,
4503 px_tld_ea_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_ext_attrib_vals_tbl,
4504 -- out set
4505 x_tld_party_tbl OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
4506 x_tld_account_tbl OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
4507 x_tld_oa_tbl OUT NOCOPY csi_t_datastructures_grp.txn_org_assgn_tbl,
4508 x_tld_ea_tbl OUT NOCOPY csi_t_datastructures_grp.txn_ext_attrib_vals_tbl,
4509 x_return_status OUT NOCOPY varchar2)
4510 IS
4511
4512 l_create_flag varchar2(1) := 'N';
4513
4514 l_tld_party_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
4515 l_tld_account_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
4516 l_tld_oa_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
4517 l_tld_ea_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
4518
4519 l_p_ind binary_integer := 0;
4520 l_a_ind binary_integer := 0;
4521 l_oa_ind binary_integer := 0;
4522 l_ea_ind binary_integer := 0;
4523 l_iir_ind binary_integer := 0;
4524 l_pa_ind binary_integer := 0;
4525
4526 p_ind binary_integer := 0;
4527 a_ind binary_integer := 0;
4528 oa_ind binary_integer := 0;
4529 ea_ind binary_integer := 0;
4530 iir_ind binary_integer := 0;
4531 pa_ind binary_integer := 0;
4532
4533 BEGIN
4534
4535 api_Log('get_tld_set');
4536
4537 x_return_status := fnd_api.g_ret_sts_success;
4538
4539 IF nvl(px_tld_rec.instance_id, fnd_api.g_miss_num) = fnd_api.g_miss_num THEN
4540 l_create_flag := 'Y';
4541 ELSE
4542 l_create_flag := 'N';
4543 END IF;
4544
4545 IF px_tld_party_tbl.COUNT > 0 THEN
4546 p_ind := 0;
4547 LOOP
4548 p_ind := px_tld_party_tbl.NEXT(p_ind);
4549 EXIT when p_ind is null;
4550 IF px_tld_party_tbl(p_ind).txn_line_detail_id = px_tld_rec.txn_line_detail_id THEN
4551 l_p_ind := l_p_ind + 1;
4552 l_tld_party_tbl(l_p_ind) := px_tld_party_tbl(p_ind);
4553
4554 IF px_tld_account_tbl.COUNT > 0 THEN
4555 a_ind := 0;
4556 LOOP
4557 a_ind := px_tld_account_tbl.NEXT(a_ind);
4558 exit when a_ind is null;
4559 IF px_tld_account_tbl(a_ind).txn_party_detail_id =
4560 px_tld_party_tbl(p_ind).txn_party_detail_id
4561 THEN
4562 l_a_ind := l_a_ind + 1;
4563 l_tld_account_tbl(l_a_ind) := px_tld_account_tbl(a_ind);
4564 px_tld_account_tbl.delete(a_ind);
4565 END IF;
4566 END LOOP;
4567 END IF;
4568 px_tld_party_tbl.DELETE(p_ind);
4569 END IF;
4570 END LOOP;
4571 END IF;
4572
4573 IF px_tld_oa_tbl.COUNT > 0 THEN
4574 oa_ind := 0;
4575 LOOP
4576 oa_ind := px_tld_oa_tbl.NEXT(oa_ind);
4577 exit when oa_ind is null;
4578 IF px_tld_oa_tbl(oa_ind).txn_line_detail_id = px_tld_rec.txn_line_detail_id THEN
4579 l_oa_ind := l_oa_ind + 1;
4580 l_tld_oa_tbl(l_oa_ind) := px_tld_oa_tbl(oa_ind);
4581 px_tld_oa_tbl.delete(oa_ind);
4582 END IF;
4583 END LOOP;
4584 END IF;
4585
4586 IF px_tld_ea_tbl.COUNT > 0 THEN
4587 ea_ind := 0;
4588 LOOP
4589 ea_ind := px_tld_ea_tbl.NEXT(ea_ind);
4590 exit when ea_ind is null;
4591 IF px_tld_ea_tbl(ea_ind).txn_line_detail_id = px_tld_rec.txn_line_detail_id THEN
4592 l_ea_ind := l_ea_ind + 1;
4593 l_tld_ea_tbl(l_ea_ind) := px_tld_ea_tbl(ea_ind);
4594 px_tld_ea_tbl.delete(ea_ind);
4595 END IF;
4596 END LOOP;
4597 END IF;
4598
4599 debug('TLD set counts:');
4600 debug(' l_tld_party_tbl :'||l_tld_party_tbl.COUNT);
4601 debug(' l_tld_account_tbl :'||l_tld_account_tbl.COUNT);
4602 debug(' l_tld_oa_tbl :'||l_tld_oa_tbl.COUNT);
4603 debug(' l_tld_ea_tbl :'||l_tld_ea_tbl.COUNT);
4604
4605 x_tld_party_tbl := l_tld_party_tbl;
4606 x_tld_account_tbl := l_tld_account_tbl;
4607 x_tld_oa_tbl := l_tld_oa_tbl;
4608 x_tld_ea_tbl := l_tld_ea_tbl;
4609
4610 EXCEPTION
4611 WHEN fnd_api.g_exc_error THEN
4612 x_return_status := fnd_api.g_ret_sts_error;
4613 END get_tld_set;
4614
4615
4616 -- convert txn_systems in to csi_systems
4617 PROCEDURE create_csi_systems(
4618 px_csi_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
4619 px_txn_systems_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_systems_tbl,
4620 px_tld_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
4621 x_return_status OUT NOCOPY varchar2)
4622 IS
4623 l_system_exist boolean := FALSE;
4624 l_system_rec csi_datastructures_pub.system_rec;
4625 l_system_id number;
4626
4627 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
4628 l_msg_count number;
4629 l_msg_data varchar2(2000);
4630 BEGIN
4631
4632 x_return_status := fnd_api.g_ret_sts_success;
4633 api_log('create_csi_systems');
4634
4635 IF px_txn_systems_tbl.count > 0 THEN
4636
4637 FOR ind in px_txn_systems_tbl.FIRST..px_txn_systems_tbl.LAST
4638 LOOP
4639
4640 BEGIN
4641 SELECT system_id
4642 INTO l_system_id
4643 FROM csi_systems_vl
4644 WHERE system_type_code = px_txn_systems_tbl(ind).system_type_code
4645 AND name = px_txn_systems_tbl(ind).system_name
4646 AND customer_id = px_txn_systems_tbl(ind).customer_id;
4647
4648 debug(' CSI System ID :'||l_system_id);
4649
4650 l_system_exist := TRUE;
4651
4652 EXCEPTION
4653 WHEN no_data_found THEN
4654 l_system_exist := FALSE;
4655 WHEN too_many_rows THEN
4656 fnd_message.set_name('CSI','CSI_INT_MUL_SYS_FOUND');
4657 fnd_message.set_token('SYSTEM_NUMBER',px_txn_systems_tbl(ind).system_number);
4658 fnd_msg_pub.add;
4659 RAISE fnd_api.g_exc_error;
4660 END;
4661
4662 IF NOT(l_system_exist) THEN
4663 csi_utl_pkg.get_system_tbl(
4664 p_txn_systems_rec => px_txn_systems_tbl(ind),
4665 x_cre_systems_rec => l_system_rec );
4666
4667 csi_t_gen_utility_pvt.dump_api_info(
4668 p_pkg_name => 'csi_systems_pub',
4669 p_api_name => 'create_system');
4670
4671 csi_systems_pub.create_system(
4672 p_api_version => 1.0,
4673 p_commit => fnd_api.g_false,
4674 p_init_msg_list => fnd_api.g_true,
4675 p_validation_level => fnd_api.g_valid_level_full,
4676 p_system_rec => l_system_rec,
4677 p_txn_rec => px_csi_txn_rec,
4678 x_system_id => l_system_id,
4679 x_return_status => l_return_status,
4680 x_msg_count => l_msg_count,
4681 x_msg_data => l_msg_data);
4682
4683 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4684 RAISE fnd_api.g_exc_error;
4685 END IF;
4686
4687 debug(' CSI System Created Successfully. System ID :'||l_system_id);
4688 END IF;
4689
4690 IF px_tld_tbl.count > 0 THEN
4691 FOR tld_ind IN px_tld_tbl.FIRST .. px_tld_tbl.LAST
4692 LOOP
4693 IF px_tld_tbl(tld_ind).transaction_system_id =
4694 px_txn_systems_tbl(ind).transaction_system_id
4695 THEN
4696 px_tld_tbl(tld_ind).csi_system_id := l_system_id;
4697 END IF;
4698 END LOOP;
4699 END IF;
4700
4701 END LOOP; -- txn systems loop
4702 END IF; -- end if for system table count > 0
4703 EXCEPTION
4704 WHEN fnd_api.g_exc_error THEN
4705 x_return_status := fnd_api.g_ret_sts_error;
4706 END create_csi_systems;
4707
4708
4709 PROCEDURE proc_for_last_mtl_trx(
4710 p_source IN varchar2,
4711 p_transaction_line_id IN number,
4712 p_order_line_rec IN order_line_rec,
4713 x_return_status OUT NOCOPY VARCHAR2)
4714 IS
4715 l_order_quantity number;
4716 l_total_qty number := 0;
4717 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
4718 l_literal1 VARCHAR2(30) := 'PROCESSED' ;
4719 l_literal2 VARCHAR2(30) := 'OE_ORDER_LINES_ALL' ;
4720 BEGIN
4721
4722 x_return_status := fnd_api.g_ret_sts_success;
4723 api_log('proc_for_last_mtl_trx');
4724
4725 IF p_source = 'FULFILLMENT' THEN
4726 l_order_quantity := p_order_line_rec.fulfilled_quantity;
4727 ELSIF p_source = 'SHIPMENT' THEN
4728 l_order_quantity := p_order_line_rec.shipped_quantity;
4729 END IF;
4730
4731 BEGIN
4732 SELECT sum(quantity)
4733 INTO l_total_qty
4734 FROM csi_item_instances
4735 WHERE last_oe_order_line_id = p_order_line_rec.order_line_id
4736 AND inventory_item_id = p_order_line_rec.inv_item_id;
4737 EXCEPTION
4738 WHEN others then
4739 l_total_qty := 0;
4740 END;
4741
4742 debug(' order_quantity : '||l_order_quantity);
4743 debug(' total_inst_qty_for_line : '||l_total_qty);
4744
4745 IF l_total_qty >= l_order_quantity THEN
4746
4747 debug(' last transaction for this order line...!');
4748
4749 UPDATE csi_t_txn_line_details a
4750 SET error_code = NULL,
4751 error_explanation = NULL ,
4752 processing_status = 'PROCESSED'
4753 WHERE a.processing_status <> l_literal1
4754 AND a.source_transaction_flag = 'Y'
4755 AND a.inventory_item_id = p_order_line_rec.inv_item_id
4756 AND a.transaction_line_id in (SELECT transaction_line_id
4757 FROM csi_t_transaction_lines b
4758 WHERE -- a.transaction_line_id = b.transaction_line_id AND -- Commented for Perf Bug bug 4311676
4759 b.source_transaction_id = p_order_line_rec.order_line_id
4760 AND b.source_transaction_table = l_literal2 );
4761
4762 UPDATE csi_t_transaction_lines
4763 SET processing_status = 'PROCESSED'
4764 WHERE source_transaction_id = p_order_line_rec.order_line_id;
4765
4766 DELETE FROM csi_t_txn_line_details
4767 WHERE transaction_line_id = p_transaction_line_id
4768 AND source_transaction_flag = 'Y'
4769 AND processing_status <> l_literal1;
4770
4771 -- R12 changes because ATO Option funcillment will happen from the OM Code.
4772 /*
4773 IF p_source = 'SHIPMENT' AND p_order_line_rec.item_type_code = 'CONFIG' THEN
4774 debug(' ato config shipment. spawn shippable option lines for fulfillment.');
4775 process_ato_options(
4776 p_order_line_rec => p_order_line_rec,
4777 x_return_status => l_return_status);
4778 IF l_return_status <> fnd_api.g_ret_sts_success THEN
4779 RAISE fnd_api.g_exc_error;
4780 END IF;
4781 END IF;
4782 */
4783
4784 END IF;
4785
4786 EXCEPTION
4787 WHEN fnd_api.g_exc_error THEN
4788 x_return_status := fnd_api.g_ret_sts_error ;
4789 WHEN fnd_api.g_exc_unexpected_error THEN
4790 x_return_status := fnd_api.g_ret_sts_unexp_error ;
4791 END proc_for_last_mtl_trx ;
4792
4793 PROCEDURE auto_split_instances(
4794 p_instance_rec IN csi_datastructures_pub.instance_rec,
4795 px_txn_rec IN OUT nocopy csi_datastructures_pub.transaction_rec,
4796 x_instance_tbl OUT nocopy csi_datastructures_pub.instance_tbl,
4797 x_return_status OUT nocopy varchar2)
4798 IS
4799 l_src_instance_rec csi_datastructures_pub.instance_rec;
4800 l_instance_tbl csi_datastructures_pub.instance_tbl;
4801 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
4802 l_msg_count number;
4803 l_msg_data varchar2(2000);
4804 BEGIN
4805
4806 x_return_status := fnd_api.g_ret_sts_success;
4807
4808 api_log('auto_split_instances');
4809
4810 l_src_instance_rec.instance_id := p_instance_rec.instance_id ;
4811 l_src_instance_rec.vld_organization_id := p_instance_rec.vld_organization_id;
4812 l_src_instance_rec.location_type_code := p_instance_rec.location_type_code;
4813 l_src_instance_rec.location_id := p_instance_rec.location_id;
4814 l_src_instance_rec.install_location_type_code := p_instance_rec.install_location_type_code;
4815 l_src_instance_rec.install_location_id := p_instance_rec.install_location_id;
4816 l_src_instance_rec.instance_usage_code := p_instance_rec.instance_usage_code;
4817 -- START changes for bug 4050897
4818 l_src_instance_rec.version_label := p_instance_rec.version_label;
4819 l_src_instance_rec.instance_type_code := p_instance_rec.instance_type_code;
4820 l_src_instance_rec.instance_condition_id := p_instance_rec.instance_condition_id;
4821 l_src_instance_rec.return_by_date := p_instance_rec.return_by_date;
4822 -- END changes for bug 4050897
4823 l_src_instance_rec.inv_organization_id := null;
4824 l_src_instance_rec.inv_subinventory_name := null;
4825 l_src_instance_rec.inv_locator_id := null;
4826 l_src_instance_rec.pa_project_id := null;
4827 l_src_instance_rec.pa_project_task_id := null;
4828 l_src_instance_rec.wip_job_id := null;
4829 l_src_instance_rec.po_order_line_id := null;
4830
4831 csi_t_gen_utility_pvt.dump_api_info(
4832 p_pkg_name => 'csi_item_instance_pvt',
4833 p_api_name => 'split_item_instance_lines');
4834
4835 csi_item_instance_pvt.split_item_instance_lines(
4836 p_api_version => 1.0,
4837 p_commit => fnd_api.g_false,
4838 p_init_msg_list => fnd_api.g_true,
4839 p_validation_level => fnd_api.g_valid_level_full,
4840 p_source_instance_rec => l_src_instance_rec,
4841 p_copy_ext_attribs => fnd_api.g_true,
4842 p_copy_org_assignments => fnd_api.g_true,
4843 p_copy_parties => fnd_api.g_true,
4844 p_copy_accounts => fnd_api.g_true,
4845 p_copy_asset_assignments => fnd_api.g_true,
4846 p_copy_pricing_attribs => fnd_api.g_true,
4847 p_txn_rec => px_txn_rec,
4848 x_new_instance_tbl => l_instance_tbl,
4849 x_return_status => l_return_status,
4850 x_msg_count => l_msg_count,
4851 x_msg_data => l_msg_data);
4852
4853 IF l_return_status not in (fnd_api.g_ret_sts_success, 'W') THEN
4854 RAISE fnd_api.g_exc_error;
4855 END IF;
4856
4857 x_instance_tbl := l_instance_tbl;
4858
4859 EXCEPTION
4860 WHEN fnd_api.g_exc_error THEN
4861 x_return_status := fnd_api.g_ret_sts_error;
4862 END auto_split_instances;
4863
4864 PROCEDURE update_install_base(
4865 p_api_version IN number,
4866 p_commit IN varchar2 := fnd_api.g_false,
4867 p_init_msg_list IN varchar2 := fnd_api.g_false,
4868 p_validation_level IN number := fnd_api.g_valid_level_full,
4869 p_txn_line_rec IN OUT NOCOPY csi_t_datastructures_grp.txn_line_rec,
4870 p_txn_line_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
4871 p_txn_party_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
4872 p_txn_pty_acct_dtl_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
4873 p_txn_org_assgn_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_org_assgn_tbl,
4874 p_txn_ext_attrib_vals_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_ext_attrib_vals_tbl,
4875 p_txn_ii_rltns_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_ii_rltns_tbl,
4876 p_txn_systems_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_systems_tbl,
4877 p_pricing_attribs_tbl IN OUT NOCOPY csi_datastructures_pub.pricing_attribs_tbl,
4878 p_order_line_rec IN order_line_rec,
4879 p_trx_rec IN csi_datastructures_pub.transaction_rec,
4880 p_source IN varchar2,
4881 p_validate_only IN varchar2,
4882 px_error_rec IN OUT NOCOPY csi_datastructures_pub.transaction_error_rec,
4883 x_return_status OUT NOCOPY varchar2,
4884 x_msg_count OUT NOCOPY number,
4885 x_msg_data OUT NOCOPY varchar2)
4886 IS
4887
4888 l_api_name CONSTANT varchar2(30) := 'update_install_base';
4889 l_api_version CONSTANT NUMBER := 1.0;
4890 l_csi_debug_level varchar2(1);
4891
4892 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
4893 l_msg_count number;
4894 l_msg_data varchar2(2000);
4895
4896 l_order_line_rec order_line_rec;
4897 l_item_control_rec item_control_rec;
4898
4899 x_trx_sub_type_rec txn_sub_type_rec;
4900 l_tmp_instance_rec csi_datastructures_pub.instance_rec;
4901 l_upd_instance_rec csi_datastructures_pub.instance_rec;
4902 l_upd_txn_rec csi_datastructures_pub.transaction_rec;
4903 l_upd_party_tbl csi_datastructures_pub.party_tbl;
4904 l_upd_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4905 l_upd_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
4906 l_upd_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4907 l_upd_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4908 l_upd_org_units_tbl csi_datastructures_pub.organization_units_tbl;
4909 l_inst_id_lst csi_datastructures_pub.id_tbl;
4910 l_upd_ii_rltns_tbl csi_datastructures_pub.ii_relationship_tbl;
4911
4912 l_upd_so_instance_rec csi_datastructures_pub.instance_rec;
4913 l_upd_so_party_tbl csi_datastructures_pub.party_tbl;
4914 l_upd_so_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4915 l_upd_so_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
4916 l_upd_so_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4917 l_upd_so_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4918 l_upd_so_org_units_tbl csi_datastructures_pub.organization_units_tbl;
4919
4920 l_cre_instance_rec csi_datastructures_pub.instance_rec;
4921 l_cre_txn_rec csi_datastructures_pub.transaction_rec;
4922 l_cre_party_tbl csi_datastructures_pub.party_tbl;
4923 l_cre_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4924 l_cre_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
4925 l_cre_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4926 l_cre_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4927 l_cre_org_units_tbl csi_datastructures_pub.organization_units_tbl;
4928 l_cre_ii_rltns_tbl csi_datastructures_pub.ii_relationship_tbl;
4929 l_cre_systems_rec csi_datastructures_pub.system_rec;
4930
4931 l_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
4932 l_txn_line_query_rec csi_t_datastructures_grp.txn_line_query_rec;
4933 l_txn_line_detail_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
4934 l_txn_party_detail_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
4935 l_txn_pty_acct_detail_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
4936 l_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
4937 l_txn_ext_attrib_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
4938 l_csi_ext_attribs_tbl csi_t_datastructures_grp.csi_ext_attribs_tbl;
4939 l_csi_iea_values_tbl csi_t_datastructures_grp.csi_ext_attrib_vals_tbl;
4940 l_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl ;
4941 l_txn_systems_tbl csi_t_datastructures_grp.txn_systems_tbl;
4942
4943 l_upd_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
4944 l_upd_txn_party_detail_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
4945 l_upd_txn_pty_acct_dtl_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
4946 l_upd_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
4947 l_upd_txn_ext_attr_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
4948
4949 /* Pricing Attributes variables */
4950 l_old_index NUMBER := 0;
4951 l_new_index NUMBER := 0;
4952 l_old_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4953 l_new_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4954
4955 /* Extended Attributes variables */
4956 l_ext_old_index NUMBER := 0;
4957 l_ext_new_index NUMBER := 0;
4958 l_old_extended_attribs_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4959 l_new_extended_attribs_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4960
4961 /* Decrement and Increment Logic variables */
4962 l_un_exp_instance_rec csi_datastructures_pub.instance_rec;
4963 l_un_exp_party_tbl csi_datastructures_pub.party_tbl;
4964 l_un_exp_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4965 l_un_exp_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
4966 l_un_exp_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4967 l_un_exp_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4968 l_un_exp_org_units_tbl csi_datastructures_pub.organization_units_tbl;
4969 l_un_exp_ii_rltns_tbl csi_datastructures_pub.ii_relationship_tbl;
4970 l_un_exp_systems_rec csi_datastructures_pub.system_rec;
4971
4972 l_trx_rec csi_datastructures_pub.transaction_rec;
4973 l_auto_split_instances csi_datastructures_pub.instance_tbl;
4974
4975 l_split_src_inst_rec csi_datastructures_pub.instance_rec;
4976 l_split_src_trx_rec csi_datastructures_pub.transaction_rec;
4977 l_split_new_inst_rec csi_datastructures_pub.instance_rec;
4978 l_sys_query_rec csi_datastructures_pub.system_query_rec;
4979 x_systems_tbl csi_datastructures_pub.systems_tbl;
4980
4981 /* expire item instance variables */
4982 l_exp_instance_rec csi_datastructures_pub.instance_rec;
4983 l_exp_instance_id_lst csi_datastructures_pub.id_tbl;
4984 l_expire_flag BOOLEAN := FALSE;
4985
4986 /* non source processing variables */
4987 l_ns_instance_rec csi_datastructures_pub.instance_rec;
4988 l_ns_party_tbl csi_datastructures_pub.party_tbl;
4989 l_ns_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4990 l_ns_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
4991 l_ns_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4992 l_ns_org_units_tbl csi_datastructures_pub.organization_units_tbl;
4993 l_ns_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
4994 l_ns_inst_id_lst csi_datastructures_pub.id_tbl;
4995
4996 l_chg_instance_rec csi_datastructures_pub.instance_rec;
4997 l_chg_party_tbl csi_datastructures_pub.party_tbl;
4998 l_chg_party_acct_tbl csi_datastructures_pub.party_account_tbl;
4999 l_chg_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
5000 l_chg_ext_attrib_val_tbl csi_datastructures_pub.extend_attrib_values_tbl;
5001 l_chg_org_units_tbl csi_datastructures_pub.organization_units_tbl;
5002 l_chg_inst_asset_tbl csi_datastructures_pub.instance_asset_tbl;
5003 l_chg_inst_id_lst csi_datastructures_pub.id_tbl;
5004 l_chg_txn_rec csi_datastructures_pub.transaction_rec;
5005
5006 l_all_tld_party_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
5007 l_all_tld_account_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
5008 l_all_tld_oa_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
5009 l_all_tld_ea_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
5010
5011 l_tld_rec csi_t_datastructures_grp.txn_line_detail_rec;
5012 l_tld_party_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
5013 l_tld_account_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
5014 l_tld_oa_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
5015 l_tld_ea_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
5016
5017 l_quantity1 NUMBER;
5018 l_quantity2 NUMBER;
5019 x_system_id NUMBER;
5020 l_model_inst_id NUMBER := -1;
5021 l_option_inst_id NUMBER := -1;
5022 x_master_org_id NUMBER ;
5023 l_object_inst_id NUMBER;
5024 l_trx_type_id NUMBER;
5025 l_subject_inst_id NUMBER;
5026 l_rel_exist BOOLEAN := TRUE;
5027 l_end NUMBER := 1;
5028 l_split_flag varchar2(10);
5029 l_found BOOLEAN := FALSE;
5030 l_ii_rel_id NUMBER;
5031 l_curr_object_id NUMBER;
5032 l_curr_subject_id NUMBER;
5033 l_date DATE := fnd_api.g_miss_date;
5034 l_debug_level NUMBER;
5035 l_inst_status_id NUMBER;
5036 l_inst_obj_ver_num NUMBER;
5037 l_pty_changed BOOLEAN := FALSE;
5038 l_curr_pty_id NUMBER;
5039 l_instance_id NUMBER;
5040 l_curr_instance_qty NUMBER;
5041 l_instance_party_id NUMBER;
5042 l_int_pty_obj_ver_num NUMBER;
5043 l_ip_account_id NUMBER;
5044 l_pty_acct_obj_ver_num NUMBER;
5045 l_instance_ou_id NUMBER;
5046 l_ou_obj_ver_num NUMBER;
5047 l_attrib_value_id NUMBER;
5048 l_av_obj_ver_num NUMBER;
5049 l_party_id NUMBER;
5050 l_party_acct_id NUMBER;
5051 l_start NUMBER;
5052 l_bom_explode_flag BOOLEAN := FALSE;
5053 l_party_site_id NUMBER;
5054 l_total_qty_processed NUMBER := 0;
5055 l_system_id NUMBER;
5056 l_system_exist BOOLEAN := FALSE;
5057 l_parent_tbl_index NUMBER;
5058 l_process_acct_flag BOOLEAN := TRUE;
5059 l_explosion_level NUMBER := 0;
5060 l_so_qty NUMBER;
5061 l_so_instance_id NUMBER;
5062 l_so_obj_ver_num NUMBER;
5063 is_instance_rma BOOLEAN := FALSE;
5064 l_relationship_id NUMBER;
5065 l_ii_rel_obj_ver_num NUMBER;
5066 l_instance_pty_id NUMBER;
5067 l_exp_ii_relationship_rec csi_datastructures_pub.ii_relationship_rec;
5068 l_exp_instance_id_tbl csi_datastructures_pub.id_tbl;
5069
5070 l_dflt_inst_status_id NUMBER;
5071 l_owner_party_id NUMBER;
5072 l_internal_party_id NUMBER;
5073 l_ownership_flag VARCHAR2(1);
5074
5075 -- explode_bom variables
5076 l_bom_ind binary_integer := 0;
5077 l_bom_std_item_rec csi_datastructures_pub.instance_rec;
5078 l_bom_std_item_tbl csi_datastructures_pub.instance_tbl;
5079
5080 l_comp_instance_tbl csi_datastructures_pub.instance_tbl;
5081 l_comp_relation_tbl csi_datastructures_pub.ii_relationship_tbl;
5082
5083 l_active_end_date date := fnd_api.g_miss_date;
5084 l_call_contracts varchar2(1) := fnd_api.g_true;
5085
5086 -- profile value checking
5087 l_default_install_date VARCHAR2(1);
5088
5089 l_install_party_site_id NUMBER;
5090
5091 -- Partner Order changes
5092 l_upd_party_site_id number;
5093 l_cre_party_site_id number;
5094
5095 l_owner_pty_rec csi_datastructures_pub.party_rec;
5096 l_owner_acct_rec csi_datastructures_pub.party_account_rec;
5097
5098 --brmanesh 01-DEC-2003
5099 l_wip_job_id number;
5100 l_wip_iir_tbl csi_datastructures_pub.ii_relationship_tbl;
5101 l_cps_tbl customer_products_tbl;
5102 l_cp_ind binary_integer := 0;
5103 l_all_cps_tbl customer_products_tbl;
5104 l_single_cps_tbl customer_products_tbl;
5105 l_acp_ind binary_integer := 0;
5106 -- Added this for unlock_item_instances
5107 l_config_tbl csi_cz_int.config_tbl;
5108 l_cia_found varchar2(1);
5109
5110 BEGIN
5111
5112 /* Standard Start of API savepoint */
5113 SAVEPOINT update_install_base;
5114
5115 api_log('update_install_base');
5116
5117 /* Initialize message list if p_init_msg_list is set to TRUE. */
5118 IF FND_API.to_Boolean( p_init_msg_list ) THEN
5119 fnd_msg_pub.initialize;
5120 END IF;
5121
5122 /* Initialize API return status to success */
5123 x_return_status := fnd_api.g_ret_sts_success;
5124
5125 debug(' txn_line_detail_tbl.count :'||p_txn_line_detail_tbl.count );
5126 debug(' txn_party_detail_tbl.count :'||p_txn_party_detail_tbl.count );
5127 debug(' txn_pty_acct_dtl_tbl.count :'||p_txn_pty_acct_dtl_tbl.count);
5128 debug(' txn_org_assgn_tbl.count :'||p_txn_org_assgn_tbl.count);
5129 debug(' txn_ii_rltns_tbl.count :'||p_txn_ii_rltns_tbl.count);
5130 debug(' txn_ext_attrib_vals_tbl.count :'||p_txn_ext_attrib_vals_tbl.count);
5131 debug(' pricing_attribs_tbl.count :'||p_pricing_attribs_tbl.count);
5132 debug(' txn_systems_tbl.count :'||p_txn_systems_tbl.count);
5133
5134 IF p_txn_line_detail_tbl.count <= 0
5135 THEN
5136 fnd_message.set_name('CSI', 'CSI_CANNOT_UPDATE');
5137 fnd_message.set_token('OBJECT_ID','');
5138 fnd_message.set_token('RELATIONSHIP_TYPE_CODE','');
5139 fnd_msg_pub.add;
5140 Raise fnd_api.g_exc_error;
5141 END IF;
5142
5143 /* get the profile value for CSI default install date */
5144 BEGIN
5145 SELECT nvl(fnd_profile.value('CSI_DEF_INST_DATE'),'N')
5146 INTO l_default_install_date
5147 FROM dual;
5148 EXCEPTION
5149 WHEN OTHERS THEN
5150 NULL;
5151 END;
5152
5153 /* assign the trx_rec that will be used for all trx's in IB*/
5154 l_trx_rec := p_trx_rec;
5155
5156 /* get the debug level from the profile */
5157 l_debug_level := csi_t_gen_utility_pvt.g_debug_level;
5158
5159 l_order_line_rec := p_order_line_rec;
5160
5161 /* validate the txn table and its child tables */
5162 validate_txn_tbl(
5163 p_txn_line_rec => p_txn_line_rec,
5164 p_txn_line_detail_tbl => p_txn_line_detail_tbl,
5165 p_txn_party_detail_tbl => p_txn_party_detail_tbl,
5166 p_txn_pty_acct_dtl_tbl => p_txn_pty_acct_dtl_tbl,
5167 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
5168 p_txn_org_assgn_tbl => p_txn_org_assgn_tbl,
5169 p_order_line_rec => l_order_line_rec,
5170 p_source => p_source,
5171 x_return_status => x_return_status);
5172
5173 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5174 raise fnd_api.g_exc_error;
5175 END IF;
5176
5177 l_all_tld_party_tbl := p_txn_party_detail_tbl;
5178 l_all_tld_account_tbl := p_txn_pty_acct_dtl_tbl;
5179 l_all_tld_oa_tbl := p_txn_org_assgn_tbl;
5180 l_all_tld_ea_tbl := p_txn_ext_attrib_vals_tbl;
5181
5182 /* Process the txn details only if p_validate_only is 'N' */
5183 IF p_validate_only = 'N' THEN
5184
5185 /*-----------------------------------------------*/
5186 /* Check if the systems exists,if found */
5187 /* then use the system else create a new system */
5188 /*-----------------------------------------------*/
5189 IF p_txn_systems_tbl.count > 0 THEN
5190 create_csi_systems(
5191 px_csi_txn_rec => l_trx_rec,
5192 px_txn_systems_tbl => p_txn_systems_tbl,
5193 px_tld_tbl => p_txn_line_detail_tbl,
5194 x_return_status => l_return_status);
5195
5196 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5197 RAISE fnd_api.g_exc_error;
5198 END IF;
5199 END IF; -- end if for system table count > 0
5200
5201 csi_utl_pkg.get_dflt_inst_status_id(
5202 x_instance_status_id => l_dflt_inst_status_id,
5203 x_return_status => l_return_status);
5204
5205 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5206 RAISE fnd_api.g_exc_error;
5207 END IF;
5208
5209 l_split_flag := nvl(fnd_profile.value('CSI_AUTO_SPLIT_INSTANCE' ),'N');
5210
5211 debug(' profile_auto_split : '||l_split_flag);
5212
5213
5214 /* Process the txn details and the child tables */
5215
5216 IF p_txn_line_detail_tbl.count > 0 THEN
5217
5218 debug ('Processing the txn line dtl and child tables.' );
5219
5220 FOR i IN p_txn_line_detail_tbl.FIRST..p_txn_line_detail_tbl.LAST
5221 LOOP
5222
5223 l_tld_rec := p_txn_line_detail_tbl(i);
5224
5225 debug('processing tld record # '||i||' source_flag : '||l_tld_rec.source_transaction_flag);
5226
5227 l_cp_ind := 0;
5228 l_cps_tbl.delete;
5229
5230 /* Process only txn details that have the source_trx_flag = 'Y' */
5231 IF l_debug_level > 1 THEN
5232 csi_t_gen_utility_pvt.dump_line_detail_rec(l_tld_rec);
5233 END IF;
5234
5235 get_tld_set(
5236 px_tld_rec => l_tld_rec,
5237 px_tld_party_tbl => l_all_tld_party_tbl,
5238 px_tld_account_tbl => l_all_tld_account_tbl,
5239 px_tld_oa_tbl => l_all_tld_oa_tbl,
5240 px_tld_ea_tbl => l_all_tld_ea_tbl,
5241 -- out set
5242 x_tld_party_tbl => l_tld_party_tbl,
5243 x_tld_account_tbl => l_tld_account_tbl,
5244 x_tld_oa_tbl => l_tld_oa_tbl,
5245 x_tld_ea_tbl => l_tld_ea_tbl,
5246 x_return_status => l_return_status);
5247
5248 IF (l_tld_rec.source_transaction_flag = 'Y') AND
5249 (l_tld_rec.processing_status = 'IN_PROCESS') THEN
5250
5251 px_error_rec.serial_number := l_tld_rec.serial_number;
5252 px_error_rec.lot_number := l_tld_rec.lot_number;
5253 px_error_rec.instance_id := l_tld_rec.instance_id;
5254
5255 /* Initialize the pl/sql table for each txn_line_dtls*/
5256 l_cre_party_tbl.delete;
5257 l_upd_party_tbl.delete;
5258 l_cre_party_acct_tbl.delete;
5259 l_upd_party_acct_tbl.delete;
5260 l_cre_org_units_tbl.delete;
5261 l_upd_org_units_tbl.delete;
5262 l_cre_ext_attrib_val_tbl.delete;
5263 l_upd_ext_attrib_val_tbl.delete;
5264 l_cre_pricing_attribs_tbl.delete;
5265
5266 /* Keep the txn_line_dtl qty processed */
5267 l_total_qty_processed := l_total_qty_processed + l_tld_rec.quantity;
5268
5269 /* Get the sub_type_rec from the txn line_dtls */
5270
5271 csi_utl_pkg.get_sub_type_rec(
5272 p_sub_type_id => l_tld_rec.sub_type_id,
5273 p_trx_type_id => p_txn_line_rec.source_transaction_type_id,
5274 x_trx_sub_type_rec => x_trx_sub_type_rec,
5275 x_return_status => x_return_status) ;
5276
5277 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5278 raise fnd_api.g_exc_error;
5279 END IF;
5280
5281 csi_utl_pkg.get_org_assignment_tbl(
5282 p_txn_line_detail_rec => l_tld_rec,
5283 p_txn_org_assgn_tbl => l_tld_oa_tbl,
5284 x_cre_org_units_tbl => l_cre_org_units_tbl,
5285 x_upd_org_units_tbl => l_upd_org_units_tbl,
5286 x_return_status => x_return_status);
5287
5288 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5289 raise fnd_api.g_exc_error;
5290 END IF;
5291
5292 csi_utl_pkg.get_ext_attribs_tbl(
5293 p_txn_line_detail_rec => l_tld_rec,
5294 p_txn_ext_attrib_vals_tbl => l_tld_ea_tbl,
5295 x_cre_ext_attrib_val_tbl => l_cre_ext_attrib_val_tbl,
5296 x_upd_ext_attrib_val_tbl => l_upd_ext_attrib_val_tbl,
5297 x_return_status => x_return_status );
5298
5299 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5300 raise fnd_api.g_exc_error;
5301 END IF;
5302
5303 csi_utl_pkg.get_party_owner(
5304 p_txn_line_detail_rec => l_tld_rec,
5305 p_txn_party_detail_tbl => l_tld_party_tbl,
5306 p_txn_pty_acct_dtl_tbl => l_tld_account_tbl,
5307 x_trx_sub_type_rec => x_trx_sub_type_rec,
5308 p_order_line_rec => p_order_line_rec,
5309 x_upd_party_tbl => l_upd_party_tbl,
5310 x_upd_party_acct_tbl => l_upd_party_acct_tbl,
5311 x_cre_party_tbl => l_cre_party_tbl,
5312 x_cre_party_acct_tbl => l_cre_party_acct_tbl,
5313 x_return_status => x_return_status );
5314
5315 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5316 raise fnd_api.g_exc_error;
5317 END IF;
5318
5319
5320 IF p_source = 'SHIPMENT' THEN
5321 IF l_upd_party_acct_tbl.COUNT = 0 THEN
5322 l_upd_party_acct_tbl := l_cre_party_acct_tbl;
5323 l_cre_party_acct_tbl.delete;
5324 END IF;
5325 ELSIF p_source = 'FULFILLMENT' THEN
5326 -- Bug 4996316, these are demo conversion shipments and have a need to convert
5327 -- an externally located but internally owned item instance to CP
5328 -- current check for it is simple and additional checks may be added in here...
5329 IF nvl(l_tld_rec.instance_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num
5330 THEN
5331 IF l_upd_party_acct_tbl.COUNT = 0 THEN
5332 l_upd_party_acct_tbl := l_cre_party_acct_tbl;
5333 l_cre_party_acct_tbl.delete;
5334 END IF;
5335 END IF;
5336 END IF;
5337
5338 debug('After building all the pl/sql tables');
5339 debug(' upd_party_tbl.count :'||l_upd_party_tbl.count);
5340 debug(' upd_party_acct_tbl.count :'||l_upd_party_acct_tbl.count);
5341 debug(' upd_org_units_tbl.count :'||l_upd_org_units_tbl.count);
5342 debug(' upd_inst_asset_tbl.count :'||l_upd_inst_asset_tbl.count);
5343 debug(' upd_ext_attrib_val_tbl.count :'||l_upd_ext_attrib_val_tbl.count);
5344 debug(' upd_pricing_attribs_tbl.count :'||l_upd_pricing_attribs_tbl.count);
5345 debug(' cre_party_tbl.count :'||l_cre_party_tbl.count);
5346 debug(' cre_party_acct_tbl.count :'||l_cre_party_acct_tbl.count);
5347 debug(' cre_org_units_tbl.count :'||l_cre_org_units_tbl.count);
5348 debug(' cre_inst_asset_tbl.count :'||l_cre_inst_asset_tbl.count);
5349 debug(' cre_ext_attrib_val_tbl.count :'||l_cre_ext_attrib_val_tbl.count);
5350 debug(' cre_pricing_attribs_tbl.count :'||l_cre_pricing_attribs_tbl.count);
5351
5352 -- Forward Port bug 7420858 for base bug 7312328
5353 IF NVL(l_tld_rec.location_id, fnd_api.g_miss_num) = fnd_api.g_miss_num AND
5354 p_order_line_rec.ib_current_loc_id IS NOT NULL -- added for bug 5069906
5355 THEN
5356
5357 BEGIN
5358
5359 SELECT party_site_id
5360 INTO l_party_site_id
5361 FROM hz_cust_acct_sites_all c,
5362 hz_cust_site_uses_all u
5363 WHERE c.cust_acct_site_id = u.cust_acct_site_id
5364 AND u.site_use_id = p_order_line_rec.ib_current_loc_id; -- ship_to_org_id;
5365
5366 EXCEPTION
5367 WHEN no_data_found then
5368 fnd_message.set_name('CSI','CSI_INT_PTY_SITE_MISSING');
5369 fnd_message.set_token('LOCATION_ID', l_tld_rec.location_id);
5370 fnd_msg_pub.add;
5371 raise fnd_api.g_exc_error;
5372 WHEN too_many_rows then
5373 debug('Many Party sites found');
5374 raise fnd_api.g_exc_error;
5375 END;
5376
5377 l_tld_rec.location_id := l_party_site_id;
5378 l_tld_rec.location_type_code := 'HZ_PARTY_SITES';
5379
5380 END IF;
5381
5382 -- Forward Port bug 7420858 for base bug 7312328
5383 IF NVL(l_tld_rec.install_location_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
5384 AND p_order_line_rec.ib_install_loc_id IS NOT NULL THEN --5147603
5385 BEGIN
5386
5387 SELECT party_site_id
5388 INTO l_install_party_site_id
5389 FROM hz_cust_acct_sites_all c,
5390 hz_cust_site_uses_all u
5391 WHERE c.cust_acct_site_id = u.cust_acct_site_id
5392 AND u.site_use_id = p_order_line_rec.ib_install_loc_id; -- ship_to_org_id;
5393
5394 EXCEPTION
5395 WHEN no_data_found then
5396 fnd_message.set_name('CSI','CSI_INT_PTY_SITE_MISSING');
5397 fnd_message.set_token('LOCATION_ID',p_order_line_rec.ib_install_loc_id);--5147603
5398 fnd_msg_pub.add;
5399 raise fnd_api.g_exc_error;
5400 WHEN too_many_rows then
5401 debug('Many Party sites found');
5402 raise fnd_api.g_exc_error;
5403 END;
5404
5405 l_tld_rec.install_location_id := l_install_party_site_id;
5406 l_tld_rec.install_location_type_code := 'HZ_PARTY_SITES';
5407
5408 END IF;
5409
5410 /* If the instance reference exists then call update instance api else */
5411 /* call create instance api .Also check if the split instance profile */
5412 /* is on then split it into so many number of instances */
5413
5414 IF NVL(l_tld_rec.instance_id,fnd_api.g_miss_num ) <> fnd_api.g_miss_num THEN
5415
5416 l_upd_instance_rec := l_tmp_instance_rec;
5417
5418 csi_utl_pkg.get_instance(
5419 p_instance_id => l_tld_rec.instance_id,
5420 x_obj_version_number => l_inst_obj_ver_num,
5421 x_inst_qty => l_curr_instance_qty,
5422 x_return_status => x_return_status);
5423
5424 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5425 raise fnd_api.g_exc_error;
5426 END IF;
5427
5428 debug('Referenced Instance ID :'||l_tld_rec.instance_id);
5429 debug(' object_ver_num :'||l_inst_obj_ver_num);
5430 debug(' quantitity :'||l_curr_instance_qty);
5431 debug(' returned instance id :'||l_tld_rec.changed_instance_id);
5432
5433 l_instance_id := l_tld_rec.instance_id;
5434
5435 IF p_order_line_rec.serial_code = 6 THEN
5436
5437 /*--------------------------------------------------------------------*/
5438 /* Check if the instance exists with shipped serial number then it is */
5439 /* a shipping of returned instance So decrement the source instance */
5440 /* and update the destination instance to make it a cp */
5441 /*--------------------------------------------------------------------*/
5442
5443 BEGIN
5444
5445 SELECT instance_id,
5446 quantity,
5447 object_version_number
5448 INTO l_so_instance_id,
5449 l_so_qty,
5450 l_so_obj_ver_num
5451 FROM csi_item_instances
5452 WHERE serial_number = l_tld_rec.serial_number
5453 AND inventory_item_id = l_tld_rec.inventory_item_id
5454 AND (instance_usage_code = 'RETURNED' --added the outer braces for bug6310708
5455 --Start of code for 6188180
5456 OR (instance_usage_code = 'IN_TRANSIT'
5457 AND
5458 active_end_date IS NOT NULL));
5459 --End of code for 6188180
5460
5461 debug('Returned instance found. Instance ID :'||l_so_instance_id);
5462
5463 decrement_source_instance(
5464 p_instance_id => l_tld_rec.instance_id,
5465 p_quantity => 1,
5466 p_trx_rec => l_trx_rec,
5467 x_return_status => l_return_status);
5468
5469 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5470 RAISE fnd_api.g_exc_error;
5471 END IF;
5472
5473 debug('Rebuilding the TD tables for the returned instance.');
5474
5475 l_curr_instance_qty := l_so_qty ;
5476 l_inst_obj_ver_num := l_so_obj_ver_num;
5477 l_instance_id := l_so_instance_id;
5478
5479 csi_utl_pkg.rebuild_tbls(
5480 p_new_instance_id => l_so_instance_id,
5481 x_upd_party_tbl => l_upd_party_tbl,
5482 x_upd_party_acct_tbl => l_upd_party_acct_tbl,
5483 x_upd_org_units_tbl => l_upd_org_units_tbl,
5484 x_upd_ext_attrib_val_tbl => l_upd_ext_attrib_val_tbl,
5485 x_cre_org_units_tbl => l_cre_org_units_tbl,
5486 x_cre_ext_attrib_val_tbl => l_cre_ext_attrib_val_tbl,
5487 x_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
5488 x_txn_line_detail_rec => l_tld_rec,
5489 x_return_status => x_return_status);
5490
5491 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5492 raise fnd_api.g_exc_error;
5493 END IF;
5494
5495 -- Mark the instance as RMA so that it is not eligible for split
5496 is_instance_rma := TRUE;
5497
5498 EXCEPTION
5499 WHEN no_data_found THEN
5500 is_instance_rma := FALSE;
5501 debug('Returned Instance not found for the serial number.');
5502 END;
5503 END IF;
5504
5505 /* this code is exclusively for re-shipping a returned non serial config */
5506 /* instance. ATO non serial config assembly for xerox bug 2304221 */
5507 IF nvl(l_tld_rec.changed_instance_id, fnd_api.g_miss_num) <>
5508 fnd_api.g_miss_num
5509 AND p_order_line_rec.serial_code = 1 -- Added for Bug 3008953
5510 THEN
5511 debug('re-shipping of a returned configuration.');
5512 -- a returned instance reference specified.
5513
5514 is_instance_rma := TRUE;
5515
5516 decrement_source_instance(
5517 p_instance_id => l_tld_rec.instance_id,
5518 p_quantity => 1,
5519 p_trx_rec => l_trx_rec,
5520 x_return_status => l_return_status);
5521
5522 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5523 RAISE fnd_api.g_exc_error;
5524 END IF;
5525
5526 debug('Rebuilding the TD tables for the returned config instance.');
5527
5528 l_curr_instance_qty := 1 ;
5529 l_instance_id := l_tld_rec.changed_instance_id;
5530
5531 SELECT object_version_number
5532 INTO l_inst_obj_ver_num
5533 FROM csi_item_instances
5534 WHERE instance_id = l_tld_rec.changed_instance_id;
5535
5536 csi_utl_pkg.rebuild_tbls(
5537 p_new_instance_id => l_instance_id,
5538 x_upd_party_tbl => l_upd_party_tbl,
5539 x_upd_party_acct_tbl => l_upd_party_acct_tbl,
5540 x_upd_org_units_tbl => l_upd_org_units_tbl,
5541 x_upd_ext_attrib_val_tbl => l_upd_ext_attrib_val_tbl,
5542 x_cre_org_units_tbl => l_cre_org_units_tbl,
5543 x_cre_ext_attrib_val_tbl => l_cre_ext_attrib_val_tbl,
5544 x_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
5545 x_txn_line_detail_rec => l_tld_rec,
5546 x_return_status => x_return_status);
5547
5548 IF l_return_status <> fnd_api.g_ret_sts_success THEN
5549 raise fnd_api.g_exc_error;
5550 END IF;
5551
5552 END IF;
5553
5554 IF (p_order_line_rec.serial_code in (1,6))
5555 AND
5556 (NOT(is_instance_rma))
5557 -- Commented as part of fix for Bug 2985193
5558 -- AND
5559 -- (l_curr_instance_qty > l_tld_rec.quantity )
5560 -- Begin code fix for Bug 2985193
5561 THEN
5562 IF (l_curr_instance_qty > l_tld_rec.quantity )
5563 THEN
5564 /* Split the instance if the inst_qty > shipped_qty */
5565 /* update the existing instance with the qty equal to (inst_qty - shipped_qty) */
5566 /* and create a new instance with qty equal to txn qty */
5567 l_quantity1 := (l_curr_instance_qty - l_tld_rec.quantity );
5568 l_quantity2 := l_tld_rec.quantity ;
5569 ELSIF ( l_curr_instance_qty - l_tld_rec.quantity ) < 0
5570 THEN
5571 IF p_order_line_rec.negative_balances_code = 1
5572 THEN
5573 IF l_curr_instance_qty = 0
5574 AND p_order_line_rec.reservable_type = 2
5575 THEN
5576
5577 /*
5578 debug('Non reservable Item and is expired so unexpiring first');
5579
5580 -- Calling update_item_instance to unexpire the source instance
5581 l_un_exp_instance_rec.instance_id := l_tld_rec.instance_id;
5582 l_un_exp_instance_rec.active_end_date := null;
5583 l_un_exp_instance_rec.object_version_number := l_inst_obj_ver_num;
5584
5585 csi_t_gen_utility_pvt.dump_api_info(
5586 p_pkg_name => 'csi_item_instance_pub',
5587 p_api_name => 'update_item_instance');
5588
5589 csi_item_instance_pub.update_item_instance(
5590 p_api_version => 1.0,
5591 p_commit => fnd_api.g_false,
5592 p_init_msg_list => fnd_api.g_true,
5593 p_validation_level => fnd_api.g_valid_level_full,
5594 p_instance_rec => l_un_exp_instance_rec,
5595 p_ext_attrib_values_tbl => l_un_exp_ext_attrib_val_tbl,
5596 p_party_tbl => l_un_exp_party_tbl,
5597 p_account_tbl => l_un_exp_party_acct_tbl,
5598 p_pricing_attrib_tbl => l_un_exp_pricing_attribs_tbl,
5599 p_org_assignments_tbl => l_un_exp_org_units_tbl,
5600 p_txn_rec => l_trx_rec,
5601 p_asset_assignment_tbl => l_un_exp_inst_asset_tbl,
5602 x_instance_id_lst => l_chg_inst_id_lst,
5603 x_return_status => l_return_status,
5604 x_msg_count => l_msg_count,
5605 x_msg_data => l_msg_data );
5606
5607 -- For Bug 4057183
5608 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
5609 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
5610 RAISE fnd_api.g_exc_error;
5611 END IF;
5612 debug('After Non reservable Item instance is unexpired');
5613 */
5614 -- instead of an unexpiry I am passing the end date of the source instance
5615 -- for the split as null and passing created as the instance status.
5616
5617 l_split_src_inst_rec.active_end_date := null;
5618 l_split_src_inst_rec.instance_status_id := 510;
5619 END IF;
5620 l_quantity1 := (l_curr_instance_qty - l_tld_rec.quantity );
5621 l_quantity2 := l_tld_rec.quantity ;
5622 ELSE
5623 fnd_message.set_name('CSI', 'CSI_ORG_NO_NEG_QTY');
5624 fnd_message.set_token('ORG_ID',l_tld_rec.inv_organization_id);
5625 fnd_msg_pub.add;
5626 Raise fnd_api.g_exc_error;
5627 END IF;
5628 ELSE
5629 l_quantity1 := (l_curr_instance_qty - l_tld_rec.quantity );
5630 l_quantity2 := l_tld_rec.quantity ;
5631 END IF;
5632 -- END IF; -- Commented as part of Bug 3033092
5633 -- End code fix for Bug 2985193
5634
5635 l_split_src_inst_rec.instance_id := l_tld_rec.instance_id;
5636 l_split_src_inst_rec.vld_organization_id := l_tld_rec.inv_organization_id;
5637 l_split_src_inst_rec.location_type_code := l_tld_rec.location_type_code;
5638 l_split_src_inst_rec.location_id := l_tld_rec.location_id;
5639 -- Added for partner ordering
5640 l_split_src_inst_rec.install_location_type_code := l_tld_rec.install_location_type_code;
5641 l_split_src_inst_rec.install_location_id := l_tld_rec.install_location_id;
5642 -- Added for partner ordering
5643 l_split_src_inst_rec.inv_organization_id := null;
5644 l_split_src_inst_rec.inv_subinventory_name := null;
5645 l_split_src_inst_rec.inv_locator_id := null;
5646 l_split_src_inst_rec.pa_project_id := null;
5647 l_split_src_inst_rec.pa_project_task_id := null;
5648 l_split_src_inst_rec.wip_job_id := null;
5649 l_split_src_inst_rec.po_order_line_id := null;
5650 l_split_src_inst_rec.version_label := nvl(l_tld_rec.version_label,fnd_api.g_miss_char);--bug 5112946
5651 l_split_src_trx_rec := p_trx_rec;
5652
5653 csi_t_gen_utility_pvt.dump_api_info(
5654 p_pkg_name => 'csi_item_instance_pvt',
5655 p_api_name => 'split_item_instance');
5656
5657 /* split the inventory staging instance when the instance qty > ship qty */
5658 /* the owner party is still internal */
5659 csi_item_instance_pvt.split_item_instance (
5660 p_api_version => 1.0,
5661 p_commit => fnd_api.g_false,
5662 p_init_msg_list => fnd_api.g_true,
5663 p_validation_level => fnd_api.g_valid_level_full,
5664 p_source_instance_rec => l_split_src_inst_rec,
5665 p_quantity1 => l_quantity1,
5666 p_quantity2 => l_quantity2,
5667 p_copy_ext_attribs => fnd_api.g_true,
5668 p_copy_org_assignments => fnd_api.g_true,
5669 p_copy_parties => fnd_api.g_true,
5670 p_copy_accounts => fnd_api.g_true,
5671 p_copy_asset_assignments => fnd_api.g_true,
5672 p_copy_pricing_attribs => fnd_api.g_true,
5673 p_txn_rec => l_split_src_trx_rec,
5674 x_new_instance_rec => l_split_new_inst_rec,
5675 x_return_status => x_return_status,
5676 x_msg_count => x_msg_count,
5677 x_msg_data => x_msg_data);
5678
5679 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5680 g_api_name := 'csi_item_instance_pvt.split_item_instance';
5681 raise fnd_api.g_exc_error;
5682 END IF;
5683
5684 l_instance_id := l_split_new_inst_rec.instance_id ;
5685 l_inst_obj_ver_num := l_split_new_inst_rec.object_version_number;
5686
5687 debug(' Old Instance_ID :' ||l_tld_rec.instance_id );
5688 debug(' New Instance_ID :' ||l_split_new_inst_rec.instance_id );
5689
5690 debug('Rebuilding the TD tables for the newly created instance.');
5691
5692 csi_utl_pkg.rebuild_tbls(
5693 p_new_instance_id => l_instance_id,
5694 x_upd_party_tbl => l_upd_party_tbl,
5695 x_upd_party_acct_tbl => l_upd_party_acct_tbl,
5696 x_upd_org_units_tbl => l_upd_org_units_tbl,
5697 x_upd_ext_attrib_val_tbl => l_upd_ext_attrib_val_tbl,
5698 x_cre_org_units_tbl => l_cre_org_units_tbl,
5699 x_cre_ext_attrib_val_tbl => l_cre_ext_attrib_val_tbl,
5700 x_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
5701 x_txn_line_detail_rec => l_tld_rec,
5702 x_return_status => x_return_status );
5703
5704 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5705 raise fnd_api.g_exc_error;
5706 END IF;
5707
5708 END IF; -- end of split_item_instances
5709 -- Uncommented the end if as part of fix for Bug 3033092
5710 -- Commented the END IF and moved it to before even building the split record
5711 -- as part of fix for Bug 2985193
5712
5713 IF NVL(x_trx_sub_type_rec.src_status_id,fnd_api.g_miss_num) = fnd_api.g_miss_num THEN
5714
5715 l_inst_status_id := l_dflt_inst_status_id;
5716
5717 l_upd_instance_rec.instance_status_id := l_inst_status_id;
5718 ELSE
5719 l_upd_instance_rec.instance_status_id := x_trx_sub_type_rec.src_status_id;
5720 END IF;
5721
5722 l_trx_rec.txn_sub_type_id := l_tld_rec.sub_type_id;
5723
5724 /* Assign the values for update_instance_rec */
5725
5726 l_upd_instance_rec.instance_id := l_instance_id ;
5727 l_upd_instance_rec.vld_organization_id := l_tld_rec.inv_organization_id;
5728
5729 -- Partner Ordering Code change
5730 -- l_upd_instance_rec.location_type_code := l_tld_rec.location_type_code;
5731 -- l_upd_instance_rec.location_id := l_tld_rec.location_id;
5732 -- Added the nvl to l_ltd_rec optional columns for Bug 3818547
5733 l_upd_instance_rec.install_location_type_code := nvl(l_tld_rec.install_location_type_code,fnd_api.g_miss_char);
5734 IF p_order_line_rec.ib_install_loc is not null
5735 AND
5736 p_order_line_rec.ib_install_loc <> fnd_api.g_miss_char
5737 THEN
5738 BEGIN
5739 SELECT HCAS.party_site_id
5740 INTO l_upd_party_site_id
5741 FROM hz_cust_site_uses_all HCSU,
5742 hz_cust_acct_sites_all HCAS
5743 WHERE HCSU.site_use_id = p_order_line_rec.ib_install_loc_id
5744 AND HCAS.cust_acct_site_id = HCSU.cust_acct_site_id;
5745
5746 EXCEPTION
5747 WHEN others THEN
5748 NULL;
5749 END;
5750
5751 IF l_upd_party_site_id <> l_tld_rec.install_location_id
5752 THEN
5753 l_upd_instance_rec.install_location_id := l_upd_party_site_id;
5754 -- Added else as part of fix for Bug 3419098
5755 ELSE
5756 l_upd_instance_rec.install_location_id := nvl(l_tld_rec.install_location_id,fnd_api.g_miss_num);
5757 END IF;
5758 ELSE
5759 l_upd_instance_rec.install_location_id := nvl(l_tld_rec.install_location_id,fnd_api.g_miss_num);
5760 END IF;
5761 l_upd_instance_rec.location_type_code := nvl(l_tld_rec.location_type_code,l_tld_rec.install_location_type_code);
5762 l_upd_instance_rec.location_id := nvl(l_tld_rec.location_id,l_upd_instance_rec.install_location_id);
5763 -- Partner Ordering code change
5764
5765 l_upd_instance_rec.external_reference := nvl(l_tld_rec.external_reference,fnd_api.g_miss_char);
5766 l_upd_instance_rec.system_id := nvl(l_tld_rec.csi_system_id,fnd_api.g_miss_num);
5767 -- l_upd_instance_rec.accounting_class_code := 'CUST_PROD';
5768
5769 IF nvl(l_tld_rec.installation_date,fnd_api.g_miss_date) = fnd_api.g_miss_date THEN
5770 IF l_default_install_date = 'Y' THEN
5771 IF p_source = 'SHIPMENT' THEN
5772 l_upd_instance_rec.install_date := p_order_line_rec.actual_shipment_date;
5773 ELSIF p_source = 'FULFILLMENT' THEN
5774 l_upd_instance_rec.install_date := nvl(p_order_line_rec.fulfillment_date,sysdate);
5775 END IF;
5776 END IF;
5777 ELSE
5778 /* Begin code change for 3254347 Install_Date and Start_Date changes */
5779 IF p_source = 'SHIPMENT' THEN
5780 l_upd_instance_rec.install_date := GREATEST(l_tld_rec.installation_date,p_order_line_rec.actual_shipment_date);
5781 ELSIF p_source = 'FULFILLMENT' THEN
5782 IF p_order_line_rec.fulfillment_date is NOT NULL
5783 AND
5784 p_order_line_rec.fulfillment_date <> fnd_api.g_miss_date
5785 THEN
5786 l_upd_instance_rec.install_date := GREATEST(l_tld_rec.installation_date,p_order_line_rec.fulfillment_date);
5787 ELSE
5788 l_upd_instance_rec.install_date := GREATEST(l_tld_rec.installation_date,sysdate);
5789 END IF;
5790 END IF;
5791 --l_upd_instance_rec.install_date := l_tld_rec.installation_date;
5792 /* End code change for 3254347 Install_Date and Start_Date changes */
5793 END IF;
5794
5795 l_upd_instance_rec.instance_type_code := nvl(l_tld_rec.instance_type_code,fnd_api.g_miss_char);
5796 l_upd_instance_rec.instance_condition_id := nvl(l_tld_rec.item_condition_id,fnd_api.g_miss_num);
5797 l_upd_instance_rec.quantity := l_tld_rec.quantity;
5798 l_upd_instance_rec.unit_of_measure := l_tld_rec.unit_of_measure;
5799 l_upd_instance_rec.sellable_flag := nvl(l_tld_rec.sellable_flag,fnd_api.g_miss_char);
5800 l_upd_instance_rec.last_oe_order_line_id := p_order_line_rec.order_line_id ;
5801 l_upd_instance_rec.last_txn_line_detail_id := l_tld_rec.txn_line_detail_id ;
5802 l_upd_instance_rec.return_by_date := nvl(l_tld_rec.return_by_date,fnd_api.g_miss_date);
5803 --l_upd_instance_rec.active_end_date := nvl(l_tld_rec.active_end_date,fnd_api.g_miss_date);--Bug3964060
5804 l_upd_instance_rec.active_end_date := l_tld_rec.active_end_date;
5805 --Added IF condition for bug 5112946--
5806 IF (p_order_line_rec.serial_code in (2,5)) OR
5807 (p_order_line_rec.serial_code =6 AND is_instance_rma) THEN
5808 l_upd_instance_rec.version_label := nvl(l_tld_rec.version_label,fnd_api.g_miss_char);
5809 END IF;
5810 l_upd_instance_rec.lot_number := nvl(l_tld_rec.lot_number,fnd_api.g_miss_char);
5811 l_upd_instance_rec.instance_usage_code := 'OUT_OF_ENTERPRISE';
5812 l_upd_instance_rec.last_oe_agreement_id := p_order_line_rec.agreement_id;
5813 l_upd_instance_rec.actual_return_date := null;
5814
5815 l_upd_instance_rec.object_version_number := l_inst_obj_ver_num;
5816 l_upd_instance_rec.source_code := p_order_line_rec.source_code; -- Added for Siebel Genesis Project
5817
5818 -- Added this as part of fix for Bug 2972082
5819 l_upd_instance_rec.cascade_ownership_flag := l_tld_rec.cascade_owner_flag;
5820 -- End fix for Bug 2972082
5821
5822 IF p_order_line_rec.serial_code = 6 THEN
5823 l_upd_instance_rec.serial_number := l_tld_rec.serial_number ;
5824 l_upd_instance_rec.mfg_serial_number_flag := 'Y';
5825 END IF;
5826
5827 /* Null the inventory location attributes */
5828 l_upd_instance_rec.inv_organization_id := NULL;
5829 l_upd_instance_rec.inv_subinventory_name := NULL;
5830 l_upd_instance_rec.inv_locator_id := NULL;
5831 l_upd_instance_rec.pa_project_id := NULL;
5832 l_upd_instance_rec.pa_project_task_id := NULL;
5833 l_upd_instance_rec.wip_job_id := NULL;
5834 l_upd_instance_rec.po_order_line_id := NULL;
5835
5836 l_expire_flag := FALSE;
5837
5838 IF nvl(l_upd_instance_rec.active_end_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date
5839 AND (l_upd_instance_rec.active_end_date) <= SYSDATE
5840 THEN
5841
5842 l_upd_ext_attrib_val_tbl.DELETE;
5843 l_upd_party_tbl.DELETE;
5844 l_upd_party_acct_tbl.DELETE;
5845 l_upd_pricing_attribs_tbl.DELETE;
5846 l_upd_org_units_tbl.DELETE;
5847 l_upd_inst_asset_tbl.DELETE;
5848
5849 l_upd_instance_rec.active_end_date := fnd_api.g_miss_date;
5850
5851 l_expire_flag := TRUE;
5852
5853 END IF;
5854
5855
5856 /* check if this is a replacement instnace. If this is replacement
5857 then pass the call_contracts flag as false . bug 2298453*/
5858 csi_utl_pkg.call_contracts_chk(
5859 p_txn_line_detail_id => l_tld_rec.txn_line_detail_id,
5860 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
5861 x_call_contracts => l_call_contracts,
5862 x_return_status => l_return_status);
5863
5864 -- set the call contracts
5865 l_upd_instance_rec.call_contracts := l_call_contracts;
5866
5867 -- set the flag in party record also for the owner
5868 IF l_upd_party_tbl.count > 0 THEN
5869 FOR l_upa_ind IN l_upd_party_tbl.FIRST .. l_upd_party_tbl.LAST
5870 LOOP
5871 IF l_upd_party_tbl(l_upa_ind).relationship_type_code = 'OWNER' THEN
5872 l_upd_party_tbl(l_upa_ind).call_contracts := l_call_contracts;
5873 END IF;
5874 END LOOP;
5875 END IF;
5876
5877 -- set the flag in party account record also for the owner
5878 IF l_upd_party_acct_tbl.count > 0 THEN
5879 FOR l_upa_ind IN l_upd_party_acct_tbl.FIRST .. l_upd_party_acct_tbl.LAST
5880 LOOP
5881 IF l_upd_party_acct_tbl(l_upa_ind).relationship_type_code = 'OWNER' THEN
5882 l_upd_party_acct_tbl(l_upa_ind).call_contracts := l_call_contracts;
5883 END IF;
5884 END LOOP;
5885 END IF;
5886
5887 /* Code fix as part of ER 2581101 */
5888
5889 IF x_trx_sub_type_rec.src_change_owner = 'Y' THEN
5890
5891 IF l_upd_party_acct_tbl.COUNT > 0 THEN
5892
5893 l_chg_instance_rec.instance_id := l_upd_instance_rec.instance_id;
5894 l_chg_instance_rec.active_end_date := null;
5895
5896 SELECT owner_party_id,
5897 object_version_number
5898 INTO l_owner_party_id,
5899 l_chg_instance_rec.object_version_number
5900 FROM CSI_ITEM_INSTANCES
5901 WHERE instance_id = l_upd_party_tbl(1).instance_id;
5902
5903 IF l_owner_party_id <> p_order_line_rec.internal_party_id
5904 AND
5905 l_owner_party_id <> l_upd_party_tbl(1).party_id
5906 THEN
5907
5908 l_ownership_flag:=
5909 NVL(csi_datastructures_pub.g_install_param_rec.ownership_override_at_txn,'N');
5910
5911 IF l_ownership_flag = 'N' Then
5912 fnd_message.set_name('CSI','CSI_SHIP_OWNER_MISMATCH');
5913 fnd_message.set_token('OLD_PARTY_ID',l_owner_party_id);
5914 fnd_message.set_token('NEW_PARTY_ID',l_upd_party_tbl(1).party_id);
5915 fnd_message.set_token('INSTANCE_ID',l_upd_party_tbl(1).instance_id);
5916 fnd_msg_pub.add;
5917 raise fnd_api.g_exc_error;
5918 Else
5919
5920 /* Changing the Owner to Internal Before shipping to New Customer */
5921 l_chg_party_tbl(1).instance_id := l_upd_party_tbl(1).instance_id;
5922 l_chg_party_tbl(1).instance_party_id := l_upd_party_tbl(1).instance_party_id;
5923 l_chg_party_tbl(1).object_version_number:= l_upd_party_tbl(1).object_version_number;
5924 l_chg_party_tbl(1).party_source_table := 'HZ_PARTIES';
5925 l_chg_party_tbl(1).relationship_type_code := 'OWNER';
5926 l_chg_party_tbl(1).contact_flag := 'N';
5927 l_chg_party_tbl(1).party_id := p_order_line_rec.internal_party_id;
5928
5929 debug('change owner to internal to terminate contracts.');
5930
5931 csi_t_gen_utility_pvt.dump_api_info(
5932 p_pkg_name => 'csi_item_instance_pub',
5933 p_api_name => 'update_item_instance');
5934
5935 -- owner change to internal
5936 csi_item_instance_pub.update_item_instance(
5937 p_api_version => 1.0,
5938 p_commit => fnd_api.g_false,
5939 p_init_msg_list => fnd_api.g_true,
5940 p_validation_level => fnd_api.g_valid_level_full,
5941 p_instance_rec => l_chg_instance_rec,
5942 p_ext_attrib_values_tbl => l_chg_ext_attrib_val_tbl,
5943 p_party_tbl => l_chg_party_tbl,
5944 p_account_tbl => l_chg_party_acct_tbl,
5945 p_pricing_attrib_tbl => l_chg_pricing_attribs_tbl,
5946 p_org_assignments_tbl => l_chg_org_units_tbl,
5947 p_txn_rec => l_trx_rec,
5948 p_asset_assignment_tbl => l_chg_inst_asset_tbl,
5949 x_instance_id_lst => l_chg_inst_id_lst,
5950 x_return_status => l_return_status,
5951 x_msg_count => l_msg_count,
5952 x_msg_data => l_msg_data );
5953
5954 -- For Bug 4057183
5955 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
5956 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
5957 RAISE fnd_api.g_exc_error;
5958 END IF;
5959
5960 l_upd_party_tbl(1).instance_party_id := l_chg_party_tbl(1).instance_party_id;
5961 /* Fixed for Bug 2728984 */
5962 BEGIN
5963 SELECT object_version_number
5964 INTO l_upd_instance_rec.object_version_number
5965 FROM CSI_ITEM_INSTANCES
5966 WHERE instance_id = l_upd_instance_rec.instance_id;
5967 END;
5968
5969 BEGIN
5970 SELECT object_version_number
5971 INTO l_upd_party_tbl(1).object_version_number
5972 FROM CSI_I_PARTIES
5973 WHERE instance_party_id = l_upd_party_tbl(1).instance_party_id;
5974 END;
5975 /* End Of fix for Bug 2728984 */
5976 END IF;
5977 END IF;
5978 END IF;
5979 /* Fixed for Bug 2714715 */
5980
5981 l_owner_pty_rec := l_upd_party_tbl(1);
5982 l_owner_acct_rec := l_upd_party_acct_tbl(1);
5983
5984 ELSIF NVL(x_trx_sub_type_rec.src_change_owner,'N') = 'N' THEN
5985 l_upd_party_tbl.delete;
5986 l_upd_party_acct_tbl.delete;
5987 l_owner_pty_rec := null;
5988 l_owner_acct_rec := null;
5989
5990 BEGIN
5991 SELECT 'Y' INTO l_cia_found
5992 FROM sys.dual
5993 WHERE exists (
5994 SELECT '1' FROM csi_i_assets
5995 WHERE instance_id = l_upd_instance_rec.instance_id
5996 AND sysdate between nvl(active_start_date, sysdate-1) and nvl(active_end_date, sysdate+1));
5997 l_upd_instance_rec.operational_status_code := 'IN_SERVICE';
5998 EXCEPTION
5999 WHEN no_data_found THEN
6000 null;
6001 END;
6002
6003 END IF;
6004 /* End Of Code fix as part of ER 2581101 */
6005
6006 csi_utl_pkg.get_parties_and_accounts(
6007 p_instance_id => l_upd_instance_rec.instance_id,
6008 p_tld_rec => l_tld_rec,
6009 p_t_pty_tbl => l_tld_party_tbl,
6010 p_t_pty_acct_tbl => l_tld_account_tbl,
6011 p_owner_pty_rec => l_owner_pty_rec,
6012 p_owner_acct_rec => l_owner_acct_rec,
6013 p_order_line_rec => p_order_line_rec,
6014 x_i_pty_tbl => l_upd_party_tbl,
6015 x_i_pty_acct_tbl => l_upd_party_acct_tbl,
6016 x_return_status => l_return_status);
6017
6018 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6019 RAISE fnd_api.g_exc_error;
6020 END IF;
6021
6022 -- srramakr TSO with Equipment
6023 -- Need to pass the config keys to the Update_Item_Instance API.
6024 l_upd_instance_rec.config_inst_hdr_id := l_tld_rec.config_inst_hdr_id;
6025 l_upd_instance_rec.config_inst_rev_num := l_tld_rec.config_inst_rev_num;
6026 l_upd_instance_rec.config_inst_item_id := l_tld_rec.config_inst_item_id;
6027 --
6028
6029 l_upd_instance_rec.sales_currency_code := l_order_line_rec.currency_code;
6030
6031 IF l_order_line_rec.primary_uom <> l_order_line_rec.order_quantity_uom THEN
6032
6033 l_item_control_rec.inventory_item_id := l_order_line_rec.inv_item_id;
6034 l_item_control_rec.organization_id := l_order_line_rec.inv_org_id;
6035 l_item_control_rec.primary_uom_code := l_order_line_rec.primary_uom;
6036
6037 csi_utl_pkg.get_unit_price_in_primary_uom(
6038 p_unit_price => l_order_line_rec.unit_price,
6039 p_unit_price_uom => l_order_line_rec.order_quantity_uom,
6040 px_item_control_rec => l_item_control_rec,
6041 x_unit_price_in_primary_uom => l_upd_instance_rec.sales_unit_price,
6042 x_return_status => l_return_status);
6043
6044 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6045 RAISE fnd_api.g_exc_error;
6046 END IF;
6047
6048 ELSE
6049 l_upd_instance_rec.sales_unit_price := l_order_line_rec.unit_price;
6050 END IF;
6051
6052 debug(' upd_party_tbl.count :'||l_upd_party_tbl.count);
6053 debug(' upd_party_acct_tbl.count :'||l_upd_party_acct_tbl.count);
6054 debug(' upd_org_units_tbl.count :'||l_upd_org_units_tbl.count);
6055 debug(' upd_inst_asset_tbl.count :'||l_upd_inst_asset_tbl.count);
6056 debug(' upd_ext_attrib_val_tbl.count :'||l_upd_ext_attrib_val_tbl.count);
6057 debug(' upd_pricing_attribs_tbl.count :'||l_upd_pricing_attribs_tbl.count);
6058
6059 IF l_debug_level > 1 THEN
6060 csi_t_gen_utility_pvt.dump_csi_instance_rec(l_upd_instance_rec);
6061 END IF;
6062
6063 csi_t_gen_utility_pvt.dump_api_info(
6064 p_api_name => 'update_item_instance',
6065 p_pkg_name => 'csi_item_instance_pub');
6066
6067 debug('Converting the instance into a customer product....!');
6068
6069 /* this is the call that makes the instance as customer product */
6070 csi_item_instance_pub.update_item_instance(
6071 p_api_version => 1.0,
6072 p_commit => fnd_api.g_false,
6073 p_init_msg_list => fnd_api.g_true,
6074 p_validation_level => fnd_api.g_valid_level_full,
6075 p_instance_rec => l_upd_instance_rec,
6076 p_ext_attrib_values_tbl => l_upd_ext_attrib_val_tbl,
6077 p_party_tbl => l_upd_party_tbl,
6078 p_account_tbl => l_upd_party_acct_tbl,
6079 p_pricing_attrib_tbl => l_upd_pricing_attribs_tbl,
6080 p_org_assignments_tbl => l_upd_org_units_tbl,
6081 p_txn_rec => l_trx_rec,
6082 p_asset_assignment_tbl => l_upd_inst_asset_tbl,
6083 x_instance_id_lst => l_inst_id_lst,
6084 x_return_status => l_return_status,
6085 x_msg_count => x_msg_count,
6086 x_msg_data => x_msg_data);
6087
6088 -- For Bug 4057183
6089 -- IF l_return_status <> fnd_api.g_ret_sts_success THEN
6090 IF l_return_status not in (fnd_api.g_ret_sts_success,'W') THEN
6091 g_api_name := 'csi_item_instance_pub.update_item_instance';
6092 raise fnd_api.g_exc_error;
6093 END IF;
6094
6095 IF l_expire_flag THEN
6096
6097 l_exp_instance_rec.instance_id := l_upd_instance_rec.instance_id;
6098 l_exp_instance_rec.object_version_number := l_inst_obj_ver_num + 1;
6099
6100 l_trx_rec.transaction_id := fnd_api.g_miss_num;
6101
6102 csi_t_gen_utility_pvt.dump_api_info(
6103 p_api_name => 'expire_item_instance',
6104 p_pkg_name => 'csi_item_instance_pub');
6105
6106 csi_item_instance_pub.expire_item_instance(
6107 p_api_version => 1.0,
6108 p_commit => fnd_api.g_false,
6109 p_init_msg_list => fnd_api.g_true,
6110 p_validation_level => fnd_api.g_valid_level_full,
6111 p_instance_rec => l_exp_instance_rec,
6112 p_expire_children => fnd_api.g_true,
6113 p_txn_rec => l_trx_rec,
6114 x_instance_id_lst => l_exp_instance_id_lst,
6115 x_return_status => l_return_status,
6116 x_msg_count => x_msg_count,
6117 x_msg_data => x_msg_data);
6118
6119 IF NOT(l_return_status = fnd_api.g_ret_sts_success) THEN
6120 g_api_name := 'csi_item_instance_pub.expire_item_instance';
6121 raise fnd_api.g_exc_error;
6122 END IF;
6123
6124 END IF;
6125
6126 l_instance_id := l_upd_instance_rec.instance_id ;
6127
6128 l_tld_rec.changed_instance_id := l_upd_instance_rec.instance_id;
6129 l_tld_rec.inv_mtl_transaction_id := p_order_line_rec.inv_mtl_transaction_id;
6130
6131 debug('Customer Product ID :'||l_upd_instance_rec.instance_id);
6132
6133 l_cp_ind := l_cp_ind + 1;
6134 l_cps_tbl(l_cp_ind).instance_id := l_upd_instance_rec.instance_id;
6135 l_cps_tbl(l_cp_ind).quantity := l_upd_instance_rec.quantity;
6136 l_cps_tbl(l_cp_ind).txn_line_detail_id := l_upd_instance_rec.last_txn_line_detail_id;
6137 l_cps_tbl(l_cp_ind).line_id := l_upd_instance_rec.last_oe_order_line_id;
6138 l_cps_tbl(l_cp_ind).transaction_id := l_trx_rec.transaction_id;
6139 l_cps_tbl(l_cp_ind).serial_number := l_tld_rec.serial_number;
6140 l_cps_tbl(l_cp_ind).lot_number := l_upd_instance_rec.lot_number;
6141
6142 IF NOT (l_expire_flag) THEN
6143
6144 /* create pricing attributes */
6145
6146 IF p_pricing_attribs_tbl.count > 0 THEN
6147 --Changes for bug 3901064 Start
6148 l_new_pricing_attribs_tbl.delete;
6149 l_old_pricing_attribs_tbl.delete;
6150 l_old_index := 0;
6151 l_new_index := 0;
6152 --Changes for bug 3901064 End
6153 FOR l_index in p_pricing_attribs_tbl.first..p_pricing_attribs_tbl.last LOOP
6154 p_pricing_attribs_tbl(l_index).instance_id := l_upd_instance_rec.instance_id ;
6155 END LOOP;
6156 END IF;
6157
6158 -- BEGIN MRK CODE FOR UPDATE PRICING ATTRIBUTE
6159
6160 IF p_pricing_attribs_tbl.count > 0 THEN
6161 For i in p_pricing_attribs_tbl.first..p_pricing_attribs_tbl.last LOOP
6162 BEGIN
6163 SELECT pricing_attribute_id,
6164 object_version_number
6165 INTO p_pricing_attribs_tbl(i).pricing_attribute_id,
6166 p_pricing_attribs_tbl(i).object_version_number
6167 FROM csi_i_pricing_attribs
6168 WHERE instance_id = p_pricing_attribs_tbl(i).instance_id
6169 AND pricing_context = p_pricing_attribs_tbl(i).pricing_context;
6170
6171 EXCEPTION
6172 WHEN NO_DATA_FOUND THEN
6173 Null;
6174 END;
6175 IF ( p_pricing_attribs_tbl(i).pricing_attribute_id is not null
6176 AND
6177 p_pricing_attribs_tbl(i).pricing_attribute_id <> fnd_api.g_miss_num
6178 )
6179 THEN
6180 l_old_index := l_old_index + 1;
6181 l_old_pricing_attribs_tbl(l_old_index) := p_pricing_attribs_tbl(i);
6182 l_old_pricing_attribs_tbl(l_old_index).active_end_date := null;
6183 ELSE
6184 l_new_index := l_new_index + 1;
6185 l_new_pricing_attribs_tbl(l_new_index) := p_pricing_attribs_tbl(i);
6186 END IF;
6187 END LOOP;
6188 END IF;
6189
6190 IF l_old_pricing_attribs_tbl.count > 0 THEN
6191 debug('Update Pricing_Attributes Count '||l_old_pricing_attribs_tbl.count);
6192
6193 csi_t_gen_utility_pvt.dump_api_info(
6194 p_api_name => 'update_pricing_attribs',
6195 p_pkg_name => 'csi_pricing_attribs_pub');
6196
6197 csi_pricing_attribs_pub.update_pricing_attribs(
6198 p_api_version => 1.0,
6199 p_commit => fnd_api.g_false,
6200 p_init_msg_list => fnd_api.g_true,
6201 p_validation_level => fnd_api.g_valid_level_full,
6202 p_pricing_attribs_tbl => l_old_pricing_attribs_tbl,
6203 p_txn_rec => l_trx_rec,
6204 x_return_status => x_return_status,
6205 x_msg_count => x_msg_count,
6206 x_msg_data => x_msg_data);
6207
6208 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6209 g_api_name := 'csi_pricing_attribs_pub.update_pricing_attribs';
6210 raise fnd_api.g_exc_error;
6211 END IF;
6212 debug('Pricing Attributes updated successfully.');
6213 END IF;
6214
6215 -- IF p_pricing_attribs_tbl.count > 0 THEN
6216 -- END MRK CODE FOR UPDATE PRICING ATTRIBUTE
6217
6218 IF l_new_pricing_attribs_tbl.count > 0 THEN
6219 debug('Creating Pricing_Attributes Count '||l_new_pricing_attribs_tbl.count);
6220
6221 csi_t_gen_utility_pvt.dump_api_info(
6222 p_api_name => 'create_pricing_attribs',
6223 p_pkg_name => 'csi_pricing_attribs_pub');
6224
6225 csi_pricing_attribs_pub.create_pricing_attribs(
6226 p_api_version => 1.0,
6227 p_commit => fnd_api.g_false,
6228 p_init_msg_list => fnd_api.g_true,
6229 p_validation_level => fnd_api.g_valid_level_full,
6230 p_pricing_attribs_tbl => l_new_pricing_attribs_tbl, --p_pricing_attribs_tbl,
6231 p_txn_rec => l_trx_rec,
6232 x_return_status => x_return_status,
6233 x_msg_count => x_msg_count,
6234 x_msg_data => x_msg_data);
6235
6236 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6237 g_api_name := 'csi_pricing_attribs_pub.create_pricing_attribs';
6238 raise fnd_api.g_exc_error;
6239 END IF;
6240
6241 debug('Pricing Attributes created successfully.');
6242
6243 END IF;
6244
6245 /*
6246 csi_utl_pkg.create_party_and_acct(
6247 p_instance_id => l_instance_id,
6248 p_txn_line_detail_rec => l_tld_rec,
6249 p_txn_party_detail_tbl => l_tld_party_tbl,
6250 p_txn_pty_acct_dtl_tbl => l_tld_account_tbl,
6251 p_order_line_rec => l_order_line_rec,
6252 p_trx_rec => l_trx_rec,
6253 x_return_status => x_return_status);
6254
6255 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6256 raise fnd_api.g_exc_error;
6257 END IF;
6258 */
6259
6260 debug('Party and Account created successfully.');
6261
6262 IF l_cre_org_units_tbl.count > 0 THEN
6263
6264 csi_t_gen_utility_pvt.dump_api_info(
6265 p_api_name => 'create_organization_unit',
6266 p_pkg_name => 'csi_organization_unit_pub');
6267
6268 csi_organization_unit_pub.create_organization_unit(
6269 p_api_version => 1.0,
6270 p_commit => fnd_api.g_false,
6271 p_init_msg_list => fnd_api.g_true,
6272 p_validation_level => fnd_api.g_valid_level_full,
6273 p_org_unit_tbl => l_cre_org_units_tbl,
6274 p_txn_rec => l_trx_rec,
6275 x_return_status => x_return_status,
6276 x_msg_count => x_msg_count,
6277 x_msg_data => x_msg_data);
6278
6279 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6280 g_api_name := 'csi_organization_unit_pub.create_organization_unit';
6281 raise fnd_api.g_exc_error;
6282 END IF;
6283
6284 debug('Org Assignment created successfully.');
6285 END IF;
6286
6287 -- BEGIN MRK CODE FOR UPDATE EXTENDED ATTRIBUTE
6288
6289 IF l_cre_ext_attrib_val_tbl.count > 0 THEN
6290
6291 --Changes for bug 3901064 Start
6292 l_old_extended_attribs_tbl.delete;
6293 l_new_extended_attribs_tbl.delete;
6294 l_ext_old_index := 0;
6295 l_ext_new_index := 0;
6296 --Changes for bug 3901064 End
6297
6298 FOR i in l_cre_ext_attrib_val_tbl.first..l_cre_ext_attrib_val_tbl.last LOOP
6299 BEGIN
6300 SELECT attribute_value_id,
6301 object_version_number
6302 INTO l_cre_ext_attrib_val_tbl(i).attribute_value_id,
6303 l_cre_ext_attrib_val_tbl(i).object_version_number
6304 FROM csi_iea_values
6305 WHERE instance_id = l_cre_ext_attrib_val_tbl(i).instance_id
6306 AND attribute_id = l_cre_ext_attrib_val_tbl(i).attribute_id;
6307
6308 EXCEPTION
6309 WHEN NO_DATA_FOUND THEN
6310 Null;
6311 END;
6312 IF ( l_cre_ext_attrib_val_tbl(i).attribute_value_id is not null
6313 AND
6314 l_cre_ext_attrib_val_tbl(i).attribute_value_id <> fnd_api.g_miss_num
6315 )
6316 THEN
6317 l_old_extended_attribs_tbl(l_ext_old_index) := l_cre_ext_attrib_val_tbl(i);
6318 l_ext_old_index := l_ext_old_index + 1;
6319 ELSE
6320 l_new_extended_attribs_tbl(l_ext_new_index) := l_cre_ext_attrib_val_tbl(i);
6321 l_ext_new_index := l_ext_new_index + 1;
6322 END IF;
6323 END LOOP;
6324 END IF;
6325
6326 IF l_old_extended_attribs_tbl.count > 0 THEN
6327 debug('Update Extended_Attributes Count '||l_old_extended_attribs_tbl.count);
6328
6329 csi_t_gen_utility_pvt.dump_api_info(
6330 p_api_name => 'update_extended_attrib_values',
6331 p_pkg_name => 'csi_item_instance_pub');
6332
6333 csi_item_instance_pub.update_extended_attrib_values(
6334 p_api_version => 1.0,
6335 p_commit => fnd_api.g_false,
6336 p_init_msg_list => fnd_api.g_true,
6337 p_validation_level => fnd_api.g_valid_level_full,
6338 p_ext_attrib_tbl => l_old_extended_attribs_tbl,
6339 p_txn_rec => l_trx_rec,
6340 x_return_status => x_return_status,
6341 x_msg_count => x_msg_count,
6342 x_msg_data => x_msg_data);
6343
6344 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6345 g_api_name := 'csi_item_instance_pub.update_extended_attrib_values';
6346 raise fnd_api.g_exc_error;
6347 END IF;
6348
6349 debug('Extended Attributed updated successfully.');
6350 END IF;
6351
6352 --IF l_cre_ext_attrib_val_tbl.count > 0 THEN
6353 IF l_new_extended_attribs_tbl.count > 0 THEN
6354 debug('Create Extended_Attributes Count '||l_new_extended_attribs_tbl.count);
6355
6356 -- END MRK CODE FOR UPDATE EXTENDED ATTRIBUTE
6357
6358 csi_t_gen_utility_pvt.dump_api_info(
6359 p_api_name => 'create_extended_attrib_values',
6360 p_pkg_name => 'csi_item_instance_pub');
6361
6362 csi_item_instance_pub.create_extended_attrib_values(
6363 p_api_version => 1.0,
6364 p_commit => fnd_api.g_false,
6365 p_init_msg_list => fnd_api.g_true,
6366 p_validation_level => fnd_api.g_valid_level_full,
6367 p_ext_attrib_tbl => l_new_extended_attribs_tbl, --l_cre_ext_attrib_val_tbl
6368 p_txn_rec => l_trx_rec,
6369 x_return_status => x_return_status,
6370 x_msg_count => x_msg_count,
6371 x_msg_data => x_msg_data);
6372
6373 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6374 g_api_name := 'csi_item_instance_pub.create_extended_attrib_values';
6375 raise fnd_api.g_exc_error;
6376 END IF;
6377
6378 debug('Extended Attributed created successfully.');
6379
6380 END IF;
6381 END IF;
6382
6383 IF p_source = 'FULFILLMENT'
6384 AND
6385 (NVL(l_tld_rec.active_end_date,l_date) <> l_date)
6386 THEN
6387
6388 /*-----------------------------------------------------*/
6389 /* If instance is expired then check if there is any */
6390 /* relationships in csi_ii_relationship. If exist then */
6391 /* expire the instance-to-instance relationships also */
6392 /*-----------------------------------------------------*/
6393
6394 BEGIN
6395
6396 SELECT relationship_id,
6397 object_version_number
6398 INTO l_relationship_id,
6399 l_ii_rel_obj_ver_num
6400 FROM csi_ii_relationships
6401 WHERE subject_id = l_tld_rec.instance_id
6402 AND (active_end_date is null OR active_end_date >= sysdate);
6403
6404 l_exp_ii_relationship_rec.relationship_id := l_relationship_id;
6405 l_exp_ii_relationship_rec.object_version_number := l_ii_rel_obj_ver_num;
6406
6407 csi_t_gen_utility_pvt.dump_api_info(
6408 p_api_name => 'expire_relationship',
6409 p_pkg_name => 'csi_ii_relationships_pub');
6410
6411 csi_ii_relationships_pub.expire_relationship(
6412 p_api_version => 1.0,
6413 p_commit => fnd_api.g_false,
6414 p_init_msg_list => fnd_api.g_true,
6415 p_validation_level => fnd_api.g_valid_level_full,
6416 p_relationship_rec => l_exp_ii_relationship_rec,
6417 p_txn_rec => l_trx_rec,
6418 x_instance_id_lst => l_exp_instance_id_tbl,
6419 x_return_status => x_return_status,
6420 x_msg_count => x_msg_count,
6421 x_msg_data => x_msg_data);
6422
6423 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6424 g_api_name := 'csi_ii_relationship_pub.expire_relationship';
6425 raise fnd_api.g_exc_error;
6426 END IF;
6427
6428 EXCEPTION
6429 WHEN OTHERS THEN
6430 NULL;
6431 END;
6432
6433 END IF; --l_tld_rec.active_end_date,l_date
6434
6435 IF (p_order_line_rec.serial_code = 1)
6436 AND
6437 (l_split_flag = 'Y' )
6438 AND
6439 (l_upd_instance_rec.quantity > 1)
6440 THEN
6441
6442 l_auto_split_instances.delete;
6443 --Added for bug 5112946--
6444 l_upd_instance_rec.version_label := nvl(l_tld_rec.version_label,fnd_api.g_miss_char);
6445
6446 auto_split_instances(
6447 p_instance_rec => l_upd_instance_rec,
6448 px_txn_rec => l_trx_rec,
6449 x_instance_tbl => l_auto_split_instances,
6450 x_return_status => l_return_status);
6451
6452 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6453 RAISE fnd_api.g_exc_error;
6454 END IF;
6455
6456 IF l_auto_split_instances.count > 0 THEN
6457 l_cp_ind := 0;
6458 l_cps_tbl.delete;
6459 FOR nis_ind in l_auto_split_instances.FIRST .. l_auto_split_instances.LAST
6460 LOOP
6461 debug(' Instance ID :'||l_auto_split_instances(nis_ind).instance_id);
6462
6463 l_cp_ind := l_cp_ind + 1;
6464 l_cps_tbl(l_cp_ind).instance_id := l_auto_split_instances(nis_ind).instance_id;
6465 l_cps_tbl(l_cp_ind).quantity := 1;
6466 l_cps_tbl(l_cp_ind).txn_line_detail_id := l_upd_instance_rec.last_txn_line_detail_id;
6467 l_cps_tbl(l_cp_ind).line_id := l_upd_instance_rec.last_oe_order_line_id;
6468 l_cps_tbl(l_cp_ind).transaction_id := l_trx_rec.transaction_id;
6469
6470 END LOOP;
6471 END IF;
6472
6473 IF p_txn_ii_rltns_tbl.count > 0 THEN
6474
6475 csi_utl_pkg.build_inst_ii_tbl(
6476 p_orig_inst_id => l_upd_instance_rec.instance_id,
6477 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl ,
6478 p_new_instance_tbl => l_auto_split_instances,
6479 x_return_status => x_return_status );
6480
6481 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6482 raise fnd_api.g_exc_error;
6483 END IF;
6484
6485 END IF; -- p_txn_ii_rltns_tbl.count > 0
6486 END IF; -- l_split_flag = 'Y'
6487
6488 ELSE /* Instance reference does not exist so create instance */
6489
6490 l_cre_instance_rec := l_tmp_instance_rec;
6491
6492 /* get the master organization */
6493 csi_utl_pkg.get_master_organization(
6494 p_organization_id => l_tld_rec.inv_organization_id,
6495 p_master_organization_id => x_master_org_id,
6496 x_return_status => x_return_status);
6497
6498 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6499 raise fnd_api.g_exc_error;
6500 END IF;
6501
6502 debug('Instance reference does not exist, So calling create API');
6503
6504 IF NVL(x_trx_sub_type_rec.src_status_id ,fnd_api.g_miss_num) = fnd_api.g_miss_num THEN
6505
6506 l_inst_status_id := l_dflt_inst_status_id;
6507
6508 l_cre_instance_rec.instance_status_id := l_inst_status_id;
6509 ELSE
6510 l_cre_instance_rec.instance_status_id := x_trx_sub_type_rec.src_status_id;
6511 END IF;
6512
6513 l_trx_rec.txn_sub_type_id := l_tld_rec.sub_type_id;
6514
6515 /* If the instance reference does not exist then create an instance */
6516
6517 l_cre_instance_rec.instance_id := fnd_api.g_miss_num;
6518 l_cre_instance_rec.instance_number := fnd_api.g_miss_char;
6519 l_cre_instance_rec.external_reference := l_tld_rec.external_reference ;
6520 l_cre_instance_rec.inventory_item_id := l_tld_rec.inventory_item_id;
6521 l_cre_instance_rec.inventory_revision := l_tld_rec.inventory_revision;
6522 l_cre_instance_rec.inv_master_organization_id := x_master_org_id;
6523 l_cre_instance_rec.serial_number := l_tld_rec.serial_number;
6524 l_cre_instance_rec.mfg_serial_number_flag := l_tld_rec.mfg_serial_number_flag;
6525 l_cre_instance_rec.lot_number := l_tld_rec.lot_number;
6526 l_cre_instance_rec.quantity := l_tld_rec.quantity;
6527 l_cre_instance_rec.unit_of_measure := l_tld_rec.unit_of_measure;
6528 -- l_cre_instance_rec.accounting_class_code := 'CUST_PROD' ;
6529 l_cre_instance_rec.instance_condition_id := l_tld_rec.item_condition_id;
6530 l_cre_instance_rec.customer_view_flag := 'Y';
6531 l_cre_instance_rec.merchant_view_flag := 'Y';
6532 l_cre_instance_rec.sellable_flag := l_tld_rec.sellable_flag;
6533 l_cre_instance_rec.system_id := l_tld_rec.csi_system_id;
6534 l_cre_instance_rec.instance_type_code := l_tld_rec.instance_type_code;
6535 -- l_cre_instance_rec.active_start_date := l_tld_rec.active_start_date;
6536 l_cre_instance_rec.active_end_date := l_tld_rec.active_end_date;
6537 l_cre_instance_rec.location_type_code := l_tld_rec.location_type_code;
6538 l_cre_instance_rec.location_id := l_tld_rec.location_id;
6539 -- Changed for Partner ordering
6540 l_cre_instance_rec.install_location_type_code := l_tld_rec.install_location_type_code;
6541 l_cre_instance_rec.source_code := p_order_line_rec.source_code; -- Added for Siebel Genesis Project
6542 IF p_order_line_rec.ib_install_loc is not null
6543 AND
6544 p_order_line_rec.ib_install_loc <> fnd_api.g_miss_char
6545 THEN
6546 BEGIN
6547 SELECT HCAS.party_site_id
6548 INTO l_cre_party_site_id
6549 FROM hz_cust_site_uses_all HCSU,
6550 hz_cust_acct_sites_all HCAS
6551 WHERE HCSU.site_use_id = p_order_line_rec.ib_install_loc_id
6552 AND HCAS.cust_acct_site_id = HCSU.cust_acct_site_id;
6553
6554 EXCEPTION
6555 WHEN others THEN
6556 NULL;
6557 END;
6558
6559 IF l_cre_party_site_id <> l_tld_rec.install_location_id
6560 THEN
6561 l_cre_instance_rec.install_location_id := l_cre_party_site_id;
6562 -- Added the else for Bug 3419098
6563 ELSE
6564 l_cre_instance_rec.install_location_id := l_tld_rec.install_location_id;
6565 END IF;
6566 ELSE
6567 l_cre_instance_rec.install_location_id := l_tld_rec.install_location_id;
6568 END IF;
6569 -- Changed for Partner ordering
6570 l_cre_instance_rec.vld_organization_id := l_tld_rec.inv_organization_id;
6571 l_cre_instance_rec.last_oe_order_line_id := p_order_line_rec.order_line_id ;
6572 l_cre_instance_rec.last_txn_line_detail_id := l_tld_rec.txn_line_detail_id ;
6573
6574 /* Begin fix for Bug 3254347 Install_Date and Start_Date changes */
6575 IF l_tld_rec.active_start_date IS NOT NULL
6576 AND
6577 l_tld_rec.active_start_date <> fnd_api.g_miss_date
6578 THEN
6579 IF p_source = 'FULFILLMENT'
6580 THEN
6581 --l_cre_instance_rec.active_start_date := p_order_line_rec.fulfillment_date; Bug 3807619
6582 l_cre_instance_rec.active_start_date := nvl(p_order_line_rec.fulfillment_date,sysdate);
6583 ELSIF p_source = 'SHIPMENT'
6584 THEN
6585 l_cre_instance_rec.active_start_date := p_order_line_rec.transaction_date;
6586 END IF;
6587 END IF;
6588 /* End fix for Bug 3254347 Install_Date and Start_Date changes */
6589
6590 /* Fix for Bug 3578671 */
6591 debug(' Default Install Date Profile Value '||l_default_install_date);
6592
6593 IF nvl(l_tld_rec.installation_date,fnd_api.g_miss_date) = fnd_api.g_miss_date THEN
6594 IF l_default_install_date = 'Y' THEN
6595 IF p_source = 'SHIPMENT' THEN
6596 -- For Bug 3578671
6597 IF nvl(p_order_line_rec.actual_shipment_date,fnd_api.g_miss_date) = fnd_api.g_miss_date THEN
6598 l_cre_instance_rec.install_date := l_trx_rec.source_transaction_date;
6599 ELSE
6600 l_cre_instance_rec.install_date := p_order_line_rec.actual_shipment_date;
6601 END IF;
6602 ELSIF p_source = 'FULFILLMENT' THEN
6603 -- For Bug 3578671
6604 IF nvl(p_order_line_rec.fulfillment_date,fnd_api.g_miss_date) = fnd_api.g_miss_date THEN
6605 l_cre_instance_rec.install_date := sysdate;
6606 ELSE
6607 l_cre_instance_rec.install_date := p_order_line_rec.fulfillment_date;
6608 END IF;
6609 END IF;
6610 END IF;
6611 ELSE
6612 /* Begin fix for Bug 3254347 Install_Date and Start_Date changes */
6613 IF p_source = 'SHIPMENT' THEN
6614 l_cre_instance_rec.install_date :=
6615 GREATEST(l_tld_rec.installation_date,p_order_line_rec.actual_shipment_date);
6616 ELSIF p_source = 'FULFILLMENT' THEN
6617 IF p_order_line_rec.fulfillment_date is NOT NULL
6618 AND
6619 p_order_line_rec.fulfillment_date <> fnd_api.g_miss_date
6620 THEN
6621 l_cre_instance_rec.install_date := GREATEST(l_tld_rec.installation_date,p_order_line_rec.fulfillment_date);
6622 ELSE
6623 l_cre_instance_rec.install_date := GREATEST(l_tld_rec.installation_date,sysdate);
6624 END IF;
6625 END IF;
6626 /* End fix for Bug 3254347 Install_Date and Start_Date changes */
6627 END IF;
6628
6629 l_cre_instance_rec.manually_created_flag := 'N';
6630 l_cre_instance_rec.return_by_date := l_tld_rec.return_by_date;
6631 l_cre_instance_rec.creation_complete_flag := fnd_api.g_miss_char;
6632 l_cre_instance_rec.completeness_flag := fnd_api.g_miss_char;
6633 l_cre_instance_rec.instance_usage_code := 'OUT_OF_ENTERPRISE';
6634 l_cre_instance_rec.last_oe_agreement_id := p_order_line_rec.agreement_id;
6635 -- Included for Bug 2962072.
6636 l_cre_instance_rec.version_label := l_tld_rec.version_label;
6637 l_cre_instance_rec.operational_status_code := 'NOT_USED';
6638
6639 /* Fix for Bug 2668504 */
6640 l_cre_pricing_attribs_tbl := p_pricing_attribs_tbl;
6641
6642 l_owner_pty_rec := l_cre_party_tbl(1);
6643 l_owner_acct_rec := l_cre_party_acct_tbl(1);
6644
6645 csi_utl_pkg.get_parties_and_accounts(
6646 p_instance_id => l_cre_instance_rec.instance_id,
6647 p_tld_rec => l_tld_rec,
6648 p_t_pty_tbl => l_tld_party_tbl,
6649 p_t_pty_acct_tbl => l_tld_account_tbl,
6650 p_owner_pty_rec => l_owner_pty_rec,
6651 p_owner_acct_rec => l_owner_acct_rec,
6652 p_order_line_rec => p_order_line_rec,
6653 x_i_pty_tbl => l_cre_party_tbl,
6654 x_i_pty_acct_tbl => l_cre_party_acct_tbl,
6655 x_return_status => l_return_status);
6656
6657 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6658 RAISE fnd_api.g_exc_error;
6659 END IF;
6660 --
6661 -- srramakr TSO with Equipment
6662 -- Serialized instance gets created as a part of shipment for Items with srl ctl 6 (AT SO Issue)
6663 -- Hence assigning the config keys during create.
6664 --
6665 IF p_order_line_rec.serial_code = 6 THEN
6666 l_cre_instance_rec.CONFIG_INST_HDR_ID := l_tld_rec.CONFIG_INST_HDR_ID;
6667 l_cre_instance_rec.CONFIG_INST_REV_NUM := l_tld_rec.CONFIG_INST_REV_NUM;
6668 l_cre_instance_rec.CONFIG_INST_ITEM_ID := l_tld_rec.CONFIG_INST_ITEM_ID;
6669 END IF;
6670 --
6671
6672 l_cre_instance_rec.sales_currency_code := l_order_line_rec.currency_code;
6673
6674 IF l_order_line_rec.primary_uom <> l_order_line_rec.order_quantity_uom THEN
6675
6676 l_item_control_rec.inventory_item_id := l_order_line_rec.inv_item_id;
6677 l_item_control_rec.organization_id := l_order_line_rec.inv_org_id;
6678 l_item_control_rec.primary_uom_code := l_order_line_rec.primary_uom;
6679
6680 csi_utl_pkg.get_unit_price_in_primary_uom(
6681 p_unit_price => l_order_line_rec.unit_price,
6682 p_unit_price_uom => l_order_line_rec.order_quantity_uom,
6683 px_item_control_rec => l_item_control_rec,
6684 x_unit_price_in_primary_uom => l_cre_instance_rec.sales_unit_price,
6685 x_return_status => l_return_status);
6686
6687 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6688 RAISE fnd_api.g_exc_error;
6689 END IF;
6690
6691 ELSE
6692 l_cre_instance_rec.sales_unit_price := l_order_line_rec.unit_price;
6693 END IF;
6694
6695 debug(' party_tbl.count :'||l_cre_party_tbl.count);
6696 debug(' party_acct_tbl.count :'||l_cre_party_acct_tbl.count);
6697 debug(' org_units_tbl.count :'||l_cre_org_units_tbl.count);
6698 debug(' inst_asset_tbl.count :'||l_cre_inst_asset_tbl.count);
6699 debug(' pricing_attribs_tbl.count :'||l_cre_pricing_attribs_tbl.count);
6700 debug(' ext_attrib_val_tbl.count :'||l_cre_ext_attrib_val_tbl.count);
6701
6702 csi_t_gen_utility_pvt.dump_api_info(
6703 p_api_name => 'create_item_instance',
6704 p_pkg_name => 'csi_item_instance_pub');
6705
6706 IF l_debug_level > 1 THEN
6707 csi_t_gen_utility_pvt.dump_csi_instance_rec(l_cre_instance_rec);
6708 END IF;
6709
6710 /* for order fulfillment instance ref is not there so create an instance */
6711 csi_item_instance_pub.create_item_instance(
6712 p_api_version => 1.0,
6713 p_commit => fnd_api.g_false,
6714 p_init_msg_list => fnd_api.g_true,
6715 p_validation_level => fnd_api.g_valid_level_full,
6716 p_instance_rec => l_cre_instance_rec,
6717 p_ext_attrib_values_tbl => l_cre_ext_attrib_val_tbl,
6718 p_party_tbl => l_cre_party_tbl,
6719 p_account_tbl => l_cre_party_acct_tbl,
6720 p_pricing_attrib_tbl => l_cre_pricing_attribs_tbl,
6721 p_org_assignments_tbl => l_cre_org_units_tbl,
6722 p_asset_assignment_tbl => l_cre_inst_asset_tbl,
6723 p_txn_rec => l_trx_rec,
6724 x_return_status => x_return_status,
6725 x_msg_count => x_msg_count,
6726 x_msg_data => x_msg_data );
6727
6728 -- For Bug 4057183
6729 -- IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6730 IF NOT(x_return_status in(fnd_api.g_ret_sts_success,'W')) THEN
6731 g_api_name := 'csi_item_instance_pub.create_item_instance';
6732 raise fnd_api.g_exc_error;
6733 END IF;
6734
6735 l_cp_ind := l_cp_ind + 1;
6736
6737 l_cps_tbl(l_cp_ind).instance_id := l_cre_instance_rec.instance_id;
6738 l_cps_tbl(l_cp_ind).quantity := l_cre_instance_rec.quantity;
6739 l_cps_tbl(l_cp_ind).txn_line_detail_id := l_cre_instance_rec.last_txn_line_detail_id;
6740 l_cps_tbl(l_cp_ind).line_id := l_cre_instance_rec.last_oe_order_line_id;
6741 l_cps_tbl(l_cp_ind).transaction_id := l_trx_rec.transaction_id;
6742 l_cps_tbl(l_cp_ind).serial_number := l_cre_instance_rec.serial_number;
6743 l_cps_tbl(l_cp_ind).lot_number := l_cre_instance_rec.lot_number;
6744
6745 debug('Instance created successfully. Instance ID :'||l_cre_instance_rec.instance_id);
6746
6747 l_tld_rec.changed_instance_id := l_cre_instance_rec.instance_id;
6748
6749 /* After instance is created assign the instance_id for the subject and object id */
6750
6751 l_tld_rec.instance_id := l_cre_instance_rec.instance_id;
6752 l_tld_rec.instance_exists_flag := 'Y';
6753
6754 debug(' txn_party_detail_tbl.count :'||p_txn_party_detail_tbl.count);
6755 debug(' txn_pty_acct_dtl_tbl.count :'||p_txn_pty_acct_dtl_tbl.count);
6756
6757 /*
6758 csi_utl_pkg.create_party_and_acct(
6759 p_instance_id => l_cre_instance_rec.instance_id,
6760 p_txn_line_detail_rec => l_tld_rec ,
6761 p_txn_party_detail_tbl => p_txn_party_detail_tbl ,
6762 p_txn_pty_acct_dtl_tbl => p_txn_pty_acct_dtl_tbl,
6763 p_order_line_rec => p_order_line_rec,
6764 p_trx_rec => l_trx_rec,
6765 x_return_status => x_return_status );
6766
6767 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6768 RAISE fnd_api.g_exc_error;
6769 END IF;
6770 */
6771
6772 IF l_cre_instance_rec.quantity > 1
6773 AND
6774 l_split_flag = 'Y'
6775 AND
6776 p_order_line_rec.serial_code = 1
6777 THEN
6778
6779 l_auto_split_instances.delete;
6780
6781 auto_split_instances(
6782 p_instance_rec => l_cre_instance_rec,
6783 px_txn_rec => l_trx_rec,
6784 x_instance_tbl => l_auto_split_instances,
6785 x_return_status => l_return_status);
6786
6787 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6788 RAISE fnd_api.g_exc_error;
6789 END IF;
6790
6791
6792 IF l_auto_split_instances.count > 0 THEN
6793 l_cp_ind := 0;
6794 l_cps_tbl.delete;
6795 FOR nis_ind in l_auto_split_instances.FIRST .. l_auto_split_instances.LAST
6796 LOOP
6797
6798 l_cp_ind := l_cp_ind + 1;
6799 l_cps_tbl(l_cp_ind).instance_id := l_auto_split_instances(nis_ind).instance_id;
6800 l_cps_tbl(l_cp_ind).quantity := 1;
6801 l_cps_tbl(l_cp_ind).txn_line_detail_id :=
6802 l_cre_instance_rec.last_txn_line_detail_id;
6803 l_cps_tbl(l_cp_ind).line_id :=
6804 l_cre_instance_rec.last_oe_order_line_id;
6805 l_cps_tbl(l_cp_ind).transaction_id := l_trx_rec.transaction_id;
6806
6807 END LOOP;
6808 END IF;
6809
6810 IF p_txn_ii_rltns_tbl.count > 0 THEN
6811
6812 csi_utl_pkg.build_inst_ii_tbl(
6813 p_orig_inst_id => l_cre_instance_rec.instance_id,
6814 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
6815 p_new_instance_tbl => l_auto_split_instances,
6816 x_return_status => x_return_status);
6817
6818 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6819 raise fnd_api.g_exc_error;
6820 END IF;
6821
6822 debug('build_inst_ii_tbl completed successfully ');
6823 END IF; -- p_txn_ii_rltns_tbl.count > 0
6824 END IF; -- l_split_flag = 'Y'
6825 END IF; -- end if for instance_exists_flag = 'Y'
6826
6827 /* Update the txn_line_detail to processed after updating IB successfully */
6828
6829 l_tld_rec.processing_status := 'PROCESSED';
6830 l_tld_rec.error_code := NULL;
6831 l_tld_rec.error_explanation := NULL;
6832 l_tld_rec.csi_transaction_id := p_trx_rec.transaction_id;
6833
6834 END IF; -- end if for source_trx_flag = 'Y' -- bug 3692473.The child item instances for a Non-sourced item instance gets updated in a replacement scenario. This need to happen after the get_ii_realtion_tbl routine.
6835
6836 IF l_cps_tbl.COUNT > 0 THEN
6837 FOR r_cp_ind IN l_cps_tbl.FIRST .. l_cps_tbl.LAST
6838 LOOP
6839 l_acp_ind := l_acp_ind + 1;
6840 l_all_cps_tbl(l_acp_ind) := l_cps_tbl(r_cp_ind);
6841 END LOOP;
6842 END IF;
6843
6844 p_txn_line_detail_tbl(i) := l_tld_rec;
6845
6846 END LOOP; -- end of for loop for p_txn_detail_tbl
6847
6848 debug('customer products :'||l_all_cps_tbl.COUNT);
6849
6850 -- added for bug
6851 dump_customer_products(l_all_cps_tbl);
6852
6853 get_single_qty_instances(
6854 p_all_cps_tbl => l_all_cps_tbl,
6855 x_single_cps_tbl => l_single_cps_tbl);
6856
6857 IF l_single_cps_tbl.count > 0 THEN
6858
6859 l_bom_explode_flag := csi_utl_pkg.check_standard_bom(
6860 p_order_line_rec => l_order_line_rec);
6861
6862 IF l_bom_explode_flag THEN
6863
6864 FOR l_scp_ind IN l_single_cps_tbl.FIRST .. l_single_cps_tbl.LAST
6865 LOOP
6866
6867 IF NOT(csi_utl_pkg.wip_config_exists(l_single_cps_tbl(l_scp_ind).instance_id)) THEN
6868
6869 l_bom_std_item_rec.instance_id := l_single_cps_tbl(l_scp_ind).instance_id ;
6870 l_bom_std_item_rec.inventory_item_id := l_order_line_rec.inv_item_id ;
6871 l_bom_std_item_rec.vld_organization_id := l_order_line_rec.inv_org_id ;
6872 l_bom_std_item_rec.quantity := 1;
6873
6874 l_bom_ind := l_bom_ind + 1;
6875 l_bom_std_item_tbl(l_bom_ind) := l_bom_std_item_rec;
6876
6877 END IF;
6878 END LOOP;
6879
6880 IF l_bom_std_item_tbl.COUNT > 0 THEN
6881 debug('explode bom start time :'||to_char(sysdate, 'hh24:mi:ss'));
6882
6883 csi_t_gen_utility_pvt.dump_api_info(
6884 p_pkg_name => 'csi_item_instance_grp',
6885 p_api_name => 'explode_bom');
6886
6887 csi_item_instance_grp.explode_bom( -- changes done to call the Group API for performance issues, bug3722382
6888 p_api_version => 1.0,
6889 p_commit => fnd_api.g_false,
6890 p_init_msg_list => fnd_api.g_true,
6891 p_validation_level => fnd_api.g_valid_level_full,
6892 p_source_instance_tbl => l_bom_std_item_tbl,
6893 p_explosion_level => fnd_api.g_miss_num,
6894 p_txn_rec => l_trx_rec,
6895 x_return_status => l_return_status,
6896 x_msg_count => l_msg_count,
6897 x_msg_data => l_msg_data);
6898
6899 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6900 RAISE fnd_api.g_exc_error;
6901 END IF;
6902
6903 debug('explode bom end time :'||to_char(sysdate, 'hh24:mi:ss'));
6904 END IF;
6905 ELSE
6906
6907 IF l_order_line_rec.item_type_code = 'STANDARD'
6908 AND
6909 l_order_line_rec.order_line_id = l_order_line_rec.ato_line_id
6910 AND
6911 nvl(l_order_line_rec.top_model_line_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
6912 AND
6913 l_order_line_rec.serial_code in (1, 6)
6914 THEN
6915
6916 BEGIN
6917
6918 SELECT wip_entity_id
6919 INTO l_wip_job_id
6920 FROM wip_discrete_jobs
6921 WHERE primary_item_id = l_order_line_rec.inv_item_id
6922 AND organization_id = l_order_line_rec.inv_org_id
6923 AND source_line_id = l_order_line_rec.order_line_id
6924 AND status_type <> 7; -- excluding the cancelled wip jobs
6925
6926 get_comp_instances_from_wip(
6927 p_wip_entity_id => l_wip_job_id,
6928 p_organization_id => l_order_line_rec.inv_org_id,
6929 p_cps_tbl => l_single_cps_tbl,
6930 px_csi_txn_rec => l_trx_rec,
6931 x_iir_tbl => l_wip_iir_tbl,
6932 x_return_status => l_return_status);
6933
6934 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6935 RAISE fnd_api.g_exc_error;
6936 END IF;
6937
6938 IF l_wip_iir_tbl.COUNT > 0 THEN
6939 FOR l_w_ind IN l_wip_iir_tbl.FIRST .. l_wip_iir_tbl.LAST
6940 LOOP
6941
6942 debug('object_id :'||l_wip_iir_tbl(l_w_ind).object_id||
6943 'subject_id :'||l_wip_iir_tbl(l_w_ind).subject_id);
6944
6945 convert_wip_instance_to_cp(
6946 p_instance_id => l_wip_iir_tbl(l_w_ind).subject_id,
6947 p_line_id => l_order_line_rec.order_line_id,
6948 p_csi_txn_rec => l_trx_rec,
6949 x_return_status => l_return_status);
6950
6951 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6952 RAISE fnd_api.g_exc_error;
6953 END IF;
6954
6955 END LOOP;
6956
6957 csi_t_gen_utility_pvt.dump_api_info(
6958 p_api_name => 'create_relationship',
6959 p_pkg_name => 'csi_ii_relationships_pub');
6960
6961 csi_ii_relationships_pub.create_relationship(
6962 p_api_version => 1.0,
6963 p_commit => fnd_api.g_false,
6964 p_init_msg_list => fnd_api.g_true,
6965 p_validation_level => fnd_api.g_valid_level_full,
6966 p_relationship_tbl => l_wip_iir_tbl,
6967 p_txn_rec => l_trx_rec,
6968 x_return_status => l_return_status,
6969 x_msg_count => l_msg_count,
6970 x_msg_data => l_msg_data);
6971
6972 IF l_return_status <> fnd_api.g_ret_sts_success THEN
6973 RAISE fnd_api.g_exc_error;
6974 END IF;
6975 END IF;
6976
6977 EXCEPTION
6978 WHEN no_data_found THEN
6979 null;
6980 WHEN too_many_rows THEN
6981 null;
6982 END;
6983
6984 END IF;
6985
6986 END IF; -- bom explode flag
6987 END IF;
6988
6989 -- changes for 3692473. moved the entire code unconditionally to process relationships
6990 -- (get_ii_relation_tbl) before the non-source txn details updates.
6991
6992 -- initialize the pl/sql table
6993 l_upd_ii_rltns_tbl.delete;
6994 l_cre_ii_rltns_tbl.delete;
6995
6996 -- srramakr TSO with Equipment changes.
6997 -- For a Tangible line under a MACD order, we need to build the relationships using the
6998 -- relationship records written by Configurator. p_txn_ii_rltns_tbl contains this info.
6999 -- We will fork the code based on MACD order line flag in l_order_line_rec
7000 --
7001 IF l_order_line_rec.macd_order_line = FND_API.G_TRUE THEN
7002 csi_interface_pkg.build_relationship_tbl(
7003 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
7004 p_txn_line_dtl_tbl => p_txn_line_detail_tbl,
7005 x_c_ii_rltns_tbl => l_cre_ii_rltns_tbl,
7006 x_u_ii_rltns_tbl => l_upd_ii_rltns_tbl,
7007 x_return_status => x_return_status );
7008
7009 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7010 raise fnd_api.g_exc_error;
7011 END IF;
7012 ELSE
7013 /* Added p_trx_rec for ER 2581101 */
7014
7015 csi_utl_pkg.get_ii_relation_tbl(
7016 p_txn_line_detail_tbl => p_txn_line_detail_tbl,
7017 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl ,
7018 p_trx_rec => l_trx_rec,
7019 p_order_line_rec => l_order_line_rec,
7020 x_cre_ii_rltns_tbl => l_cre_ii_rltns_tbl ,
7021 x_upd_ii_rltns_tbl => l_upd_ii_rltns_tbl ,
7022 x_return_status => x_return_status );
7023
7024 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7025 raise fnd_api.g_exc_error;
7026 END IF;
7027 END IF; -- MACD Order Check
7028
7029 debug('upd_txn_ii_rltns_tbl.count :'||l_upd_ii_rltns_tbl.count );
7030 debug('cre_txn_ii_rltns_tbl.count :'||l_cre_ii_rltns_tbl.count );
7031
7032 /* update instance relationship in IB */
7033 IF l_upd_ii_rltns_tbl.count > 0 THEN
7034
7035 csi_t_gen_utility_pvt.dump_api_info(
7036 p_api_name => 'update_relationship',
7037 p_pkg_name => 'csi_ii_relationships_pub');
7038
7039 csi_ii_relationships_pub.update_relationship(
7040 p_api_version => 1.0,
7041 p_commit => fnd_api.g_false,
7042 p_init_msg_list => fnd_api.g_true,
7043 p_validation_level => fnd_api.g_valid_level_full,
7044 p_relationship_tbl => l_upd_ii_rltns_tbl,
7045 p_txn_rec => l_trx_rec,
7046 x_return_status => x_return_status,
7047 x_msg_count => x_msg_count,
7048 x_msg_data => x_msg_data );
7049
7050 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7051 raise fnd_api.g_exc_error;
7052 END IF;
7053 debug('update_relationship completed successfully');
7054 END IF;
7055
7056 /* Create instance relationships in IB */
7057 IF l_cre_ii_rltns_tbl.count > 0 THEN
7058
7059 csi_t_gen_utility_pvt.dump_api_info(
7060 p_api_name => 'create_relationship',
7061 p_pkg_name => 'csi_ii_relationships_pub');
7062
7063 csi_ii_relationships_pub.create_relationship(
7064 p_api_version => 1.0,
7065 p_commit => fnd_api.g_false,
7066 p_init_msg_list => fnd_api.g_true,
7067 p_validation_level => fnd_api.g_valid_level_full,
7068 p_relationship_tbl => l_cre_ii_rltns_tbl,
7069 p_txn_rec => l_trx_rec,
7070 x_return_status => x_return_status,
7071 x_msg_count => x_msg_count,
7072 x_msg_data => x_msg_data );
7073
7074 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7075 raise fnd_api.g_exc_error;
7076 END IF;
7077
7078 debug('create_relationship completed sucessfully');
7079 END IF; -- end if for l_cre_txn_ii_rltns_tbl.count > 0
7080
7081 -- relooping for non-source. bug 3692473
7082
7083 FOR i IN p_txn_line_detail_tbl.FIRST..p_txn_line_detail_tbl.LAST
7084 LOOP
7085
7086 l_tld_rec := p_txn_line_detail_tbl(i);
7087
7088 IF l_tld_rec.source_transaction_flag = 'N' THEN
7089
7090 debug('processing tld record # '||i||' source_transaction_flag : '||
7091 l_tld_rec.source_transaction_flag);
7092 IF nvl(l_tld_rec.instance_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num then
7093
7094 /* check if this is a replacement instnace. If this is replacement
7095 then pass the call_contracts flag as false . bug 2298453*/
7096 l_call_contracts := fnd_api.g_true;
7097
7098 csi_utl_pkg.call_contracts_chk(
7099 p_txn_line_detail_id => l_tld_rec.txn_line_detail_id,
7100 p_txn_ii_rltns_tbl => p_txn_ii_rltns_tbl,
7101 x_call_contracts => l_call_contracts,
7102 x_return_status => l_return_status);
7103
7104 process_non_source(
7105 p_txn_line_detail_rec => l_tld_rec,
7106 p_call_contracts => l_call_contracts,
7107 p_trx_rec => l_trx_rec,
7108 x_return_status => l_return_status);
7109
7110 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7111 raise fnd_api.g_exc_error;
7112 END IF;
7113
7114 /* bug 2351217 non source not stamping the status */
7115 l_tld_rec.processing_status := 'PROCESSED';
7116 l_tld_rec.error_code := NULL;
7117 l_tld_rec.error_explanation := NULL;
7118 l_tld_rec.csi_transaction_id := p_trx_rec.transaction_id;
7119
7120 p_txn_line_detail_tbl(i) := l_tld_rec;
7121
7122 END IF;
7123
7124 END IF; -- end if for source_trx_flag = 'N'
7125 END LOOP; -- end of for loop for p_txn_detail_tbl
7126 END IF; -- end if for p_txn_detail_tbl.count > 0
7127
7128 IF p_source in ('SHIPMENT','FULFILLMENT') THEN
7129
7130 IF p_txn_line_detail_tbl.count > 0 THEN
7131
7132 debug('Updating the Transaction Details to reflect the processing status.' );
7133
7134 csi_t_txn_details_grp.update_txn_line_dtls(
7135 p_api_version => 1.0,
7136 p_commit => fnd_api.g_false,
7137 p_init_msg_list => fnd_api.g_true,
7138 p_validation_level => fnd_api.g_valid_level_full,
7139 p_txn_line_rec => p_txn_line_rec,
7140 p_txn_line_detail_tbl => p_txn_line_detail_tbl,
7141 px_txn_ii_rltns_tbl => l_upd_txn_ii_rltns_tbl,
7142 px_txn_party_detail_tbl => l_upd_txn_party_detail_tbl,
7143 px_txn_pty_acct_detail_tbl => l_upd_txn_pty_acct_dtl_tbl,
7144 px_txn_org_assgn_tbl => l_upd_txn_org_assgn_tbl,
7145 px_txn_ext_attrib_vals_tbl => l_upd_txn_ext_attr_vals_tbl,
7146 x_return_status => x_return_status,
7147 x_msg_count => x_msg_count,
7148 x_msg_data => x_msg_data);
7149
7150 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7151 g_api_name := 'csi_t_txn_details_grp.update_txn_line_dtls';
7152 raise fnd_api.g_exc_error;
7153 END IF;
7154
7155 END IF;
7156 END IF; -- end of p_source
7157 -- check if the shipment/fulfillment is the last txn for final update
7158 -- and spawning ato fulfillments.
7159
7160 proc_for_last_mtl_trx(
7161 p_source => p_source,
7162 p_transaction_line_id => p_txn_line_rec.transaction_line_id,
7163 p_order_line_rec => l_order_line_rec,
7164 x_return_status => l_return_status );
7165
7166 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7167 RAISE fnd_api.g_exc_error;
7168 END IF;
7169 --
7170 -- srramakr TSO With Equipment
7171 -- Need to update the Processing status of Configurator written Txn Line and Details.
7172 -- This status will be used by Filter_Relations while processing the fulfillable line.
7173 --
7174 IF l_order_line_rec.macd_order_line = FND_API.G_TRUE THEN
7175 IF p_txn_line_detail_tbl.count > 0 THEN
7176 FOR J IN p_txn_line_detail_tbl.FIRST .. p_txn_line_detail_tbl.LAST LOOP
7177 IF p_txn_line_detail_tbl.EXISTS(J) THEN
7178 IF p_txn_line_detail_tbl(J).source_transaction_flag = 'Y' AND
7179 p_txn_line_detail_tbl(J).config_inst_hdr_id IS NOT NULL AND
7180 p_txn_line_detail_tbl(J).config_inst_rev_num IS NOT NULL AND
7181 p_txn_line_detail_tbl(J).config_inst_item_id IS NOT NULL THEN
7182 --
7183 -- Unlocking the Tangible Item
7184 l_config_tbl(1).source_application_id := 542;
7185 l_config_tbl(1).config_inst_hdr_id := p_txn_line_detail_tbl(J).config_inst_hdr_id;
7186 l_config_tbl(1).config_inst_item_id := p_txn_line_detail_tbl(J).config_inst_item_id;
7187 l_config_tbl(1).config_inst_rev_num := p_txn_line_detail_tbl(J).config_inst_rev_num;
7188 l_config_tbl(1).source_txn_header_ref := l_order_line_rec.header_id;
7189 l_config_tbl(1).source_txn_line_ref1 := l_order_line_rec.order_line_id;
7190 --
7191 debug('Calling csi_cz_int.unlock_item_instances...');
7192 csi_cz_int.unlock_item_instances(
7193 p_api_version => 1.0,
7194 p_init_msg_list => fnd_api.g_true,
7195 p_commit => fnd_api.g_false,
7196 p_validation_level => fnd_api.g_valid_level_full,
7197 p_config_tbl => l_config_tbl,
7198 x_return_status => x_return_status,
7199 x_msg_count => x_msg_count,
7200 x_msg_data => x_msg_data);
7201
7202 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7203 RAISE fnd_api.g_exc_error;
7204 END IF;
7205 --
7206 debug('Updating CONFIGURATOR Created Transaction Details...');
7207 --
7208 UPDATE CSI_T_TRANSACTION_LINES
7209 set PROCESSING_STATUS = 'PROCESSED'
7210 where transaction_line_id in
7211 ( select transaction_line_id
7212 from CSI_T_TXN_LINE_DETAILS
7213 where config_inst_hdr_id = p_txn_line_detail_tbl(J).config_inst_hdr_id
7214 and config_inst_rev_num = p_txn_line_detail_tbl(J).config_inst_rev_num
7215 and config_inst_item_id = p_txn_line_detail_tbl(J).config_inst_item_id
7216 )
7217 and processing_status = 'SUBMIT';
7218 --
7219 UPDATE CSI_T_TXN_LINE_DETAILS
7220 set PROCESSING_STATUS = 'PROCESSED'
7221 where config_inst_hdr_id = p_txn_line_detail_tbl(J).config_inst_hdr_id
7222 and config_inst_rev_num = p_txn_line_detail_tbl(J).config_inst_rev_num
7223 and config_inst_item_id = p_txn_line_detail_tbl(J).config_inst_item_id
7224 and source_transaction_flag = 'Y'
7225 and processing_status = 'SUBMIT';
7226 END IF;
7227 END IF;
7228 END LOOP;
7229 END IF;
7230 END IF;
7231 END IF; -- end if for p_validate_flag = 'N'
7232
7233 -- Standard check of p_commit.
7234 IF FND_API.To_Boolean(p_commit) THEN
7235 COMMIT WORK;
7236 END IF;
7237
7238 fnd_msg_pub.count_and_get(
7239 p_count => x_msg_count ,
7240 p_data => x_msg_data );
7241
7242 EXCEPTION
7243 WHEN FND_API.G_EXC_ERROR THEN
7244 ROLLBACK TO update_install_base;
7245 x_return_status := FND_API.G_RET_STS_ERROR ;
7246 fnd_msg_pub.count_and_get(
7247 p_count => x_msg_count,
7248 p_data => x_msg_data );
7249 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7250 ROLLBACK TO update_install_base;
7251 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7252 fnd_msg_pub.count_and_get(
7253 p_count => x_msg_count,
7254 p_data => x_msg_data );
7255 WHEN others THEN
7256
7257 fnd_message.set_name('FND', 'FND_GENERIC_MESSAGE');
7258 fnd_message.set_token('MESSAGE', substr(sqlerrm, 1, 240));
7259 fnd_msg_pub.add;
7260
7261 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7262
7263 fnd_msg_pub.count_and_get(
7264 p_count => x_msg_count,
7265 p_data => x_msg_data );
7266
7267 END update_install_base;
7268
7269 /*----------------------------------------------------------*/
7270 /* Procedure name: validate_txn_tbl */
7271 /* Description : Procedure that validates the */
7272 /* txn line details and the child tables */
7273 /*----------------------------------------------------------*/
7274
7275 PROCEDURE validate_txn_tbl(
7276 p_txn_line_rec IN OUT NOCOPY csi_t_datastructures_grp.txn_line_rec,
7277 p_txn_line_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl,
7278 p_txn_party_detail_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
7279 p_txn_pty_acct_dtl_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
7280 p_txn_ii_rltns_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_ii_rltns_tbl,
7281 p_txn_org_assgn_tbl IN OUT NOCOPY csi_t_datastructures_grp.txn_org_assgn_tbl,
7282 p_order_line_rec IN OUT NOCOPY order_line_rec,
7283 p_source IN varchar2,
7284 x_return_status OUT NOCOPY varchar2)
7285 IS
7286
7287 x_txn_sub_type_rec txn_sub_type_rec;
7288 l_found BOOLEAN := FALSE;
7289 l_owner_count NUMBER;
7290 l_ii_rel_id NUMBER;
7291 l_curr_object_id NUMBER;
7292 l_curr_subject_id NUMBER;
7293 l_object_inst_id NUMBER;
7294 l_trx_type_id NUMBER;
7295 l_org_assign BOOLEAN := FALSE;
7296 l_ind_org NUMBER;
7297 l_party_id NUMBER;
7298 l_pty NUMBER := 0;
7299 l_acct NUMBER := 0;
7300 l_txn_party_detail_id NUMBER;
7301 l_sold_to_pty BOOLEAN := TRUE;
7302 l_sold_to_acct BOOLEAN := TRUE;
7303 l_acct_owner_count NUMBER;
7304 l_sold_from_org_found varchar2(1);
7305 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
7306
7307 -- Partner ordering
7308 l_owner_party NUMBER;
7309
7310 -- Porting 11.5.9 changes for Bug 3625218
7311 l_owner_txn_pty_dtl_id NUMBER := 0;
7312 l_owner_pty_accounts varchar2(1) := 'N';
7313 l_owner_pty_contacts varchar2(1) := 'N';
7314
7315 BEGIN
7316
7317 -- Initialize API return status to success
7318 x_return_status := fnd_api.g_ret_sts_success;
7319
7320 api_log('validate_txn_tbl');
7321
7322 IF p_txn_line_detail_tbl.count > 0 THEN
7323 FOR i IN p_txn_line_detail_tbl.FIRST..p_txn_line_detail_tbl.LAST LOOP
7324
7325 debug(' txn_line_detail_id :'||p_txn_line_detail_tbl(i).txn_line_detail_id);
7326 debug(' source_transaction_flag :'||p_txn_line_detail_tbl(i).source_transaction_flag);
7327 debug(' instance_exists_flag :'||p_txn_line_detail_tbl(i).instance_exists_flag);
7328 debug(' instance_id :'||p_txn_line_detail_tbl(i).instance_id);
7329 debug(' quantity :'||p_txn_line_detail_tbl(i).quantity);
7330
7331 /* Derive the trx_sub_type from the txn details */
7332 csi_utl_pkg.get_sub_type_rec(
7333 p_sub_type_id => p_txn_line_detail_tbl(i).sub_type_id,
7334 p_trx_type_id => p_txn_line_rec.source_transaction_type_id,
7335 x_trx_sub_type_rec => x_txn_sub_type_rec,
7336 x_return_status => x_return_status) ;
7337
7338 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7339 raise fnd_api.g_exc_error;
7340 END IF;
7341
7342 /*-----------------------------------------------------------------*/
7343 /* If Org assignment with 'SOLD_FROM' relationship_type_code */
7344 /* does not exist then 'SOLD_FROM' create an org assignments */
7345 /*-----------------------------------------------------------------*/
7346
7347 IF nvl(p_order_line_rec.sold_from_org_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num
7348 THEN
7349 IF p_txn_org_assgn_tbl.count > 0 THEN
7350 FOR l_org in p_txn_org_assgn_tbl.first..p_txn_org_assgn_tbl.last
7351 LOOP
7352 IF p_txn_org_assgn_tbl(l_org).txn_line_detail_id = p_txn_line_detail_tbl(i).txn_line_detail_id
7353 AND
7354 p_txn_org_assgn_tbl(l_org).relationship_type_code='SOLD_FROM'
7355 THEN
7356 l_org_assign := TRUE;
7357 END IF;
7358 END LOOP;
7359 END IF;
7360
7361 IF NOT(l_org_assign) THEN
7362 /* also check if the instance reference already has a SOLD_FROM relation */
7363 IF nvl(p_txn_line_detail_tbl(i).instance_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
7364 BEGIN
7365 SELECT 'X'
7366 INTO l_sold_from_org_found
7367 FROM csi_i_org_assignments
7368 WHERE instance_id = p_txn_line_detail_tbl(i).instance_id
7369 AND operating_unit_id = p_order_line_rec.sold_from_org_id
7370 AND relationship_type_code = 'SOLD_FROM'
7371 AND nvl (active_end_date, sysdate+1) > sysdate;
7372
7373
7374
7375 l_org_assign := TRUE;
7376
7377 EXCEPTION
7378 WHEN no_data_found THEN
7379 l_org_assign := FALSE;
7380 WHEN too_many_rows THEN
7381 l_org_assign := TRUE;
7382 END;
7383 END IF;
7384 END IF;
7385
7386 IF NOT(l_org_assign) THEN
7387 l_ind_org := p_txn_org_assgn_tbl.count + 1;
7388
7389 debug('Building the SOLD_FROM org assignment.. ' );
7390
7391 p_txn_org_assgn_tbl(l_ind_org).txn_operating_unit_id := fnd_api.g_miss_num;
7392 p_txn_org_assgn_tbl(l_ind_org).txn_line_detail_id := p_txn_line_detail_tbl(i).txn_line_detail_id;
7393 p_txn_org_assgn_tbl(l_ind_org).instance_ou_id := fnd_api.g_miss_num;
7394 p_txn_org_assgn_tbl(l_ind_org).operating_unit_id := p_order_line_rec.sold_from_org_id;
7395 p_txn_org_assgn_tbl(l_ind_org).relationship_type_code := 'SOLD_FROM';
7396 p_txn_org_assgn_tbl(l_ind_org).active_start_date := sysdate;
7397 p_txn_org_assgn_tbl(l_ind_org).active_end_date := p_txn_line_detail_tbl(i).active_end_date; -- fix for 4293723
7398 p_txn_org_assgn_tbl(l_ind_org).preserve_detail_flag := 'Y';
7399 p_txn_org_assgn_tbl(l_ind_org).txn_line_details_index := i;
7400 p_txn_org_assgn_tbl(l_ind_org).object_version_number := 1;
7401
7402 END IF;
7403 END IF;
7404 -- Begin porting of fix for Bug 3625218 -- To get party detail for OWNER party
7405 IF p_txn_party_detail_tbl.count > 0 THEN
7406 FOR j in p_txn_party_detail_tbl.FIRST..p_txn_party_detail_tbl.LAST LOOP
7407 IF p_txn_party_detail_tbl(j).relationship_type_code = 'OWNER'
7408 AND
7409 p_txn_party_detail_tbl(j).contact_flag = 'N'
7410 AND
7411 p_txn_party_detail_tbl(j).txn_line_detail_id = p_txn_line_detail_tbl(i).txn_line_detail_id
7412 THEN
7413 l_owner_txn_pty_dtl_id := p_txn_party_detail_tbl(j).txn_party_detail_id;
7414 exit;
7415 END IF;
7416 END LOOP;
7417 END IF;
7418 -- End porting of fix for Bug 3625218
7419 /* sub type validation for source transactions */
7420
7421 IF p_txn_line_detail_tbl(i).source_transaction_flag = 'Y' THEN
7422
7423 l_owner_count := 0;
7424 l_acct_owner_count := 0;
7425
7426 /*---------------------------------------*/
7427 /* Validate the following things if */
7428 /* 1. there is owner party */
7429 /* 2. there is an owner party account */
7430 /* 2. the sold_to party is passed */
7431 /* 3. the sold_to account is passed */
7432 /*---------------------------------------*/
7433
7434 IF p_txn_party_detail_tbl.COUNT > 0 THEN
7435 FOR l_index IN p_txn_party_detail_tbl.FIRST .. p_txn_party_detail_tbl.LAST
7436 LOOP
7437
7438 IF p_txn_party_detail_tbl(l_index).txn_line_detail_id =
7439 p_txn_line_detail_tbl(i).txn_line_detail_id
7440 THEN
7441
7442 IF p_txn_party_detail_tbl(l_index).relationship_type_code = 'OWNER' THEN
7443 l_owner_count := l_owner_count + 1;
7444 END IF;
7445
7446 IF p_txn_party_detail_tbl(l_index).relationship_type_code = 'SOLD_TO' THEN
7447 l_sold_to_pty := FALSE;
7448 END IF;
7449 -- Begin porting for 11.5.9 3625218: Check for additional contacts that exists for OWNER party
7450 IF p_txn_party_detail_tbl(l_index).contact_party_id = l_owner_txn_pty_dtl_id
7451 AND
7452 p_txn_party_detail_tbl(l_index).contact_flag = 'Y'
7453 THEN
7454 l_owner_pty_contacts := 'Y';
7455 END IF;
7456 -- End porting for 11.5.9 3625218
7457 IF p_txn_pty_acct_dtl_tbl.count > 0 THEN
7458 FOR l_ind_acct in p_txn_pty_acct_dtl_tbl.first..p_txn_pty_acct_dtl_tbl.last
7459 LOOP
7460 IF p_txn_pty_acct_dtl_tbl(l_ind_acct).txn_party_detail_id =
7461 p_txn_party_detail_tbl(l_index).txn_party_detail_id
7462 THEN
7463 -- Begin porting for 3625218: Check for additional accounts that exists for OWNER party
7464 IF p_txn_party_detail_tbl(l_index).relationship_type_code = 'OWNER'
7465 AND
7466 p_txn_pty_acct_dtl_tbl(l_ind_acct).relationship_type_code <> 'OWNER' THEN
7467 l_owner_pty_accounts := 'Y';
7468 END IF;
7469 -- End porting for 3625218
7470 IF p_txn_pty_acct_dtl_tbl(l_ind_acct).relationship_type_code = 'OWNER' THEN
7471 l_acct_owner_count := l_acct_owner_count + 1;
7472 END IF;
7473
7474 IF p_txn_pty_acct_dtl_tbl(l_ind_acct).relationship_type_code = 'SOLD_TO' THEN
7475 l_sold_to_acct := FALSE;
7476 END IF;
7477 END IF;
7478 END LOOP;
7479 END IF ; --p_txn_pty_acct_dtl_tbl.count > 0
7480 END IF;
7481 END LOOP;
7482 END IF;--p_txn_party_detail_tbl.COUNT > 0
7483
7484 /* If multiple owner exists then raise error */
7485 IF (l_owner_count > 1) THEN
7486 fnd_message.set_name('CSI','CSI_INT_MULTIPLE_OWNER');
7487 fnd_message.set_token('TXN_LINE_DETAIL_ID', p_txn_line_detail_tbl(i).txn_line_detail_id);
7488 fnd_msg_pub.add;
7489 raise fnd_api.g_exc_error;
7490 END IF;
7491
7492 /* If src_change_owner = Y and owner party does not exist then raise error */
7493 IF x_txn_sub_type_rec.src_change_owner = 'Y' THEN
7494 IF (l_owner_count = 0) THEN
7495 fnd_message.set_name('CSI','CSI_INT_PTY_OWNER_MISSING');
7496 fnd_message.set_token('TXN_LINE_DETAIL_ID', p_txn_line_detail_tbl(i).txn_line_detail_id);
7497 fnd_msg_pub.add;
7498 raise fnd_api.g_exc_error;
7499 END IF;
7500 END IF;
7501
7502 IF nvl(x_txn_sub_type_rec.src_change_owner, 'N') = 'N' THEN
7503 p_order_line_rec.ship_to_contact_id := fnd_api.g_miss_num;
7504 p_order_line_rec.invoice_to_contact_id := fnd_api.g_miss_num;
7505 END IF;
7506
7507 /* If multiple owner exists then raise error */
7508 IF (l_acct_owner_count > 1) THEN
7509 fnd_message.set_name('CSI','CSI_INT_MULTI_ACCT_OWNER');
7510 fnd_message.set_token('TXN_LINE_DETAIL_ID', p_txn_line_detail_tbl(i).txn_line_detail_id);
7511 fnd_msg_pub.add;
7512 raise fnd_api.g_exc_error;
7513 END IF;
7514
7515 /* If src_change_owner = Y and owner party does not exist then raise error */
7516 IF x_txn_sub_type_rec.src_change_owner = 'Y' THEN
7517 IF (l_acct_owner_count = 0) THEN
7518 fnd_message.set_name('CSI','CSI_INT_ACCT_OWNER_MISSING');
7519 fnd_message.set_token('TXN_LINE_DETAIL_ID', p_txn_line_detail_tbl(i).txn_line_detail_id);
7520 fnd_msg_pub.add;
7521 raise fnd_api.g_exc_error;
7522 END IF;
7523 END IF;
7524
7525 /*---------------------------------------------------------*/
7526 /* Check if the OWNER party passed matches with the */
7527 /* Shipped OWNER party . If it does not match then update*/
7528 /* update the party with the Shipped OWNER Party . */
7529 /* Also create another party rec with the 'SOLD_TO' */
7530 /* relationship */
7531 /*---------------------------------------------------------*/
7532
7533 l_pty := p_txn_party_detail_tbl.count + 1;
7534 l_acct := p_txn_pty_acct_dtl_tbl.count + 1;
7535
7536 IF p_txn_party_detail_tbl.COUNT > 0 THEN
7537 FOR l_txn_pty in p_txn_party_detail_tbl.first..p_txn_party_detail_tbl.last
7538 LOOP
7539 IF p_txn_party_detail_tbl(l_txn_pty).txn_line_detail_id =
7540 p_txn_line_detail_tbl(i).txn_line_detail_id
7541 AND
7542 p_txn_party_detail_tbl(l_txn_pty).relationship_type_code = 'OWNER'
7543 AND
7544 l_sold_to_pty
7545 THEN
7546
7547 debug('Building the SOLD_TO Party record.');
7548
7549 BEGIN
7550 SELECT csi_t_party_details_s.nextval
7551 INTO l_txn_party_detail_id
7552 FROM sys.dual;
7553 EXCEPTION
7554 WHEN others THEN
7555 debug('Sequence csi_t_party_details_s is missing');
7556 raise fnd_api.g_exc_error;
7557 END;
7558
7559 p_txn_party_detail_tbl(l_pty) := p_txn_party_detail_tbl(l_txn_pty);
7560 p_txn_party_detail_tbl(l_pty).instance_party_id := fnd_api.g_miss_num;
7561 p_txn_party_detail_tbl(l_pty).txn_party_detail_id := l_txn_party_detail_id;
7562 p_txn_party_detail_tbl(l_pty).relationship_type_code := 'SOLD_TO';
7563
7564 csi_utl_pkg.get_party_id(
7565 p_cust_acct_id => p_order_line_rec.sold_to_org_id,
7566 x_party_id => l_party_id,
7567 x_return_status => l_return_status);
7568
7569 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7570 RAISE fnd_api.g_exc_error;
7571 END IF;
7572
7573 p_txn_party_detail_tbl(l_pty).party_source_id := l_party_id;
7574
7575 csi_utl_pkg.get_party_id(
7576 p_cust_acct_id => p_order_line_rec.end_customer_id,
7577 x_party_id => l_owner_party,
7578 x_return_status => l_return_status);
7579
7580 IF l_return_status <> fnd_api.g_ret_sts_success THEN
7581 RAISE fnd_api.g_exc_error;
7582 END IF;
7583 --Added clause to if condition for bug 5897123 (FP 5764676)
7584 IF p_txn_party_detail_tbl(l_txn_pty).party_source_id <> l_owner_party AND x_txn_sub_type_rec.src_change_owner = 'Y' THEN
7585 -- Begin porting for 3625218: If owner party mismatch occurs then Erroring out if
7586 -- additional contacts/accounts exists for OWNER party.:w!
7587 IF l_owner_pty_accounts = 'Y'
7588 OR
7589 l_owner_pty_contacts = 'Y'
7590 THEN
7591 fnd_message.set_name('CSI','CSI_OWNER_PARTY_MISMATCH');
7592 fnd_msg_pub.add;
7593 RAISE fnd_api.g_exc_error;
7594 END IF;
7595 -- End porting for 3625218
7596 debug('Party_id on txn_dtls is not same as Shipment Party_id ');
7597 p_txn_party_detail_tbl(l_txn_pty).party_source_id := l_owner_party ;
7598 -- Added this for Bug 3757156
7599 p_txn_party_detail_tbl(l_pty).party_source_id := l_party_id;
7600 -- End fix for Bug 3757156
7601 END IF;
7602
7603 IF p_txn_pty_acct_dtl_tbl.count > 0 THEN
7604 FOR l_txn_acct in p_txn_pty_acct_dtl_tbl.first..p_txn_pty_acct_dtl_tbl.last
7605 LOOP
7606 IF p_txn_pty_acct_dtl_tbl(l_txn_acct).txn_party_detail_id =
7607 p_txn_party_detail_tbl(l_txn_pty).txn_party_detail_id
7608 AND
7609 p_txn_pty_acct_dtl_tbl(l_txn_acct).relationship_type_code = 'OWNER'
7610 AND
7611 l_sold_to_acct
7612 THEN
7613
7614 debug('Building the SOLD_TO Account record. ');
7615 p_txn_pty_acct_dtl_tbl(l_acct) := p_txn_pty_acct_dtl_tbl(l_txn_acct);
7616 p_txn_pty_acct_dtl_tbl(l_acct).ip_account_id := fnd_api.g_miss_num;
7617 p_txn_pty_acct_dtl_tbl(l_acct).txn_party_detail_id := l_txn_party_detail_id;
7618 p_txn_pty_acct_dtl_tbl(l_acct).relationship_type_code := 'SOLD_TO';
7619 p_txn_pty_acct_dtl_tbl(l_acct).account_id := p_order_line_rec.sold_to_org_id;
7620
7621 -- Begin fix for Bug 3757156
7622 p_txn_pty_acct_dtl_tbl(l_acct).bill_to_address_id :=
7623 p_order_line_rec.invoice_to_org_id;
7624 p_txn_pty_acct_dtl_tbl(l_acct).ship_to_address_id :=
7625 p_order_line_rec.ship_to_org_id;
7626 -- End Fix for Bug 3757156
7627
7628 -- Fix for Bug 2666489
7629 IF p_txn_pty_acct_dtl_tbl(l_txn_acct).account_id <> p_order_line_rec.end_customer_id
7630 OR p_txn_pty_acct_dtl_tbl(l_txn_acct).bill_to_address_id <> -- added for bug 5075764
7631 p_order_line_rec.invoice_to_org_id
7632 OR p_txn_pty_acct_dtl_tbl(l_txn_acct).ship_to_address_id <> -- added for bug 5075764
7633 p_order_line_rec.ship_to_org_id
7634 THEN
7635 debug('Party_Account_id on txn_dtls is not same as Shipment Party_Account_id ');
7636 p_txn_pty_acct_dtl_tbl(l_txn_acct).account_id := p_order_line_rec.end_customer_id; -- p_order_line_rec.sold_to_org_id;
7637 p_txn_pty_acct_dtl_tbl(l_txn_acct).bill_to_address_id := p_order_line_rec.invoice_to_org_id;
7638 p_txn_pty_acct_dtl_tbl(l_txn_acct).ship_to_address_id := p_order_line_rec.ship_to_org_id;
7639 END IF;
7640 -- End of fix for Bug 2666489.
7641 END IF;
7642 END LOOP;
7643 END IF; -- p_txn_pty_acct_dtl_tbl.count > 0
7644 END IF; -- end if for the match txn_party_detail_id
7645 END LOOP;
7646 END IF; -- p_txn_party_detail_tbl.COUNT > 0
7647
7648 /* If the src_reference_reqd = "Y" then check if the instance is referenced */
7649 IF x_txn_sub_type_rec.src_reference_reqd = 'Y'
7650 AND
7651 NVL(p_txn_line_detail_tbl(i).instance_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
7652 THEN
7653 fnd_message.set_name('CSI','CSI_INT_INST_REF_MISSING');
7654 fnd_message.set_token('TXN_LINE_DETAIL_ID', p_txn_line_detail_tbl(i).txn_line_detail_id);
7655 fnd_msg_pub.add;
7656 raise fnd_api.g_exc_error;
7657 END IF;
7658
7659 /* If the src_return_reqd = "Y" then check if the return_by_date is not null */
7660 IF x_txn_sub_type_rec.src_return_reqd = 'Y'
7661 AND
7662 NVL(p_txn_line_detail_tbl(i).return_by_date, FND_API.G_MISS_DATE) = FND_API.G_MISS_DATE
7663 THEN
7664 fnd_message.set_name('CSI','CSI_INT_RET_DATE_MISSING');
7665 fnd_message.set_token('TXN_LINE_DETAIL_ID', p_txn_line_detail_tbl(i).txn_line_detail_id);
7666 fnd_msg_pub.add;
7667 raise fnd_api.g_exc_error;
7668 END IF;
7669
7670 IF p_txn_party_detail_tbl.count > 0 THEN
7671 FOR j in p_txn_party_detail_tbl.first..p_txn_party_detail_tbl.last LOOP
7672 IF p_txn_party_detail_tbl(j).txn_line_detail_id = p_txn_line_detail_tbl(i).txn_line_detail_id THEN
7673
7674 IF NVL(p_txn_line_detail_tbl(i).instance_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num AND
7675 NVL(p_txn_party_detail_tbl(j).instance_party_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
7676
7677 /* validate if the instance_party_id is for that instance_id */
7678 l_found := csi_utl_pkg.validate_inst_party
7679 (p_txn_line_detail_tbl(i).instance_id,
7680 p_txn_party_detail_tbl(j).instance_party_id,
7681 p_txn_party_detail_tbl(j).relationship_type_code);
7682
7683 IF NOT(l_found) THEN
7684 fnd_message.set_name('CSI','CSI_INT_INV_INST_PTY_ID');
7685 fnd_message.set_token('INSTANCE_ID',p_txn_line_detail_tbl(i).instance_id);
7686 fnd_message.set_token('INSTANCE_PARTY_ID',p_txn_party_detail_tbl(j).instance_party_id);
7687 fnd_message.set_token('RELATIONSHIP_TYPE_CODE',p_txn_party_detail_tbl(j).relationship_type_code);
7688 fnd_msg_pub.add;
7689 raise fnd_api.g_exc_error;
7690 END IF;
7691 END IF;
7692
7693 IF (p_txn_party_detail_tbl(j).relationship_type_code = 'OWNER') THEN
7694 IF (x_txn_sub_type_rec.src_change_owner = 'Y') THEN
7695
7696 IF NVL(p_txn_line_detail_tbl(i).instance_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
7697 IF x_txn_sub_type_rec.src_chg_owner_code = 'E' THEN
7698
7699 /* if change_owner = Y and chg_owner_code = E then party id should
7700 be external party id */
7701 IF p_txn_party_detail_tbl(j).party_source_id = p_order_line_rec.internal_party_id THEN
7702 fnd_message.set_name('CSI','CSI_INT_INV_PTY_ID');
7703 fnd_message.set_token('PARTY_ID',p_txn_party_detail_tbl(j).party_source_id);
7704 fnd_message.set_token('INTERNAL_PARTY_ID',p_order_line_rec.internal_party_id);
7705 fnd_msg_pub.add;
7706 raise fnd_api.g_exc_error;
7707 END IF;
7708 ELSE
7709 /* if change_owner = N and chg_owner_code <> E then party id should
7710 be external party id */
7711 IF p_txn_party_detail_tbl(j).party_source_id <> p_order_line_rec.internal_party_id THEN
7712 fnd_message.set_name('CSI','CSI_INT_INV_PTY_ID');
7713 fnd_message.set_token('PARTY_ID',p_txn_party_detail_tbl(j).party_source_id);
7714 fnd_message.set_token('INTERNAL_PARTY_ID',p_order_line_rec.internal_party_id);
7715 fnd_msg_pub.add;
7716 raise fnd_api.g_exc_error;
7717 END IF;
7718 END IF;
7719 END IF;
7720 END IF;
7721 END IF;
7722 END IF;
7723 END LOOP;
7724 END IF;
7725 ELSIF p_txn_line_detail_tbl(i).source_transaction_flag = 'N' THEN
7726 /* sub type validation for non-source transactions */
7727
7728 /* If the src_reference_reqd = "Y" then check if the instance is referenced */
7729 IF x_txn_sub_type_rec.nsrc_reference_reqd = 'Y'
7730 AND
7731 NVL(p_txn_line_detail_tbl(i).instance_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
7732 THEN
7733 fnd_message.set_name('CSI','CSI_INT_INST_REF_MISSING');
7734 fnd_msg_pub.add;
7735 raise fnd_api.g_exc_error;
7736 END IF;
7737
7738 /* If the src_return_reqd = "Y" then check if the return_by_date is not null */
7739
7740 IF x_txn_sub_type_rec.nsrc_return_reqd = 'Y'
7741 AND
7742 NVL(p_txn_line_detail_tbl(i).return_by_date, FND_API.G_MISS_DATE) = FND_API.G_MISS_DATE
7743 THEN
7744 fnd_message.set_name('CSI','CSI_INT_RET_DATE_MISSING');
7745 fnd_msg_pub.add;
7746 raise fnd_api.g_exc_error;
7747 END IF;
7748
7749 /* If src_reference_reqd = 'Y' then the relationship should be defined in the txn_ii_rltns_tbl */
7750
7751 IF x_txn_sub_type_rec.src_reference_reqd = 'Y'
7752 AND
7753 NOT(csi_utl_pkg.check_relation_exists(
7754 p_txn_ii_rltns_tbl,
7755 p_txn_line_detail_tbl(i).txn_line_detail_id))
7756 THEN
7757 fnd_message.set_name('CSI','CSI_INT_NSRC_REL_MISSING');
7758 fnd_message.set_token('TXN_LINE_DETAIL_ID',p_txn_line_detail_tbl(i).txn_line_detail_id );
7759 fnd_msg_pub.add;
7760 raise fnd_api.g_exc_error;
7761 END IF;
7762
7763 IF p_txn_party_detail_tbl.count > 0 THEN
7764 FOR j in p_txn_party_detail_tbl.first..p_txn_party_detail_tbl.last LOOP
7765 IF p_txn_party_detail_tbl(j).txn_line_detail_id = p_txn_line_detail_tbl(i).txn_line_detail_id THEN
7766
7767 IF NVL(p_txn_line_detail_tbl(i).instance_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num AND
7768 NVL(p_txn_party_detail_tbl(j).instance_party_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
7769
7770 /* validate if the instance_party_id is for that instance_id */
7771
7772 l_found := csi_utl_pkg.validate_inst_party
7773 (p_txn_line_detail_tbl(i).instance_id,
7774 p_txn_party_detail_tbl(j).instance_party_id,
7775 p_txn_party_detail_tbl(j).relationship_type_code);
7776 IF NOT(l_found) THEN
7777 fnd_message.set_name('CSI','CSI_INT_INV_INST_PTY_ID');
7778 fnd_message.set_token('INSTANCE_ID',p_txn_line_detail_tbl(i).instance_id);
7779 fnd_message.set_token('INSTANCE_PARTY_ID',p_txn_party_detail_tbl(j).instance_party_id);
7780 fnd_message.set_token('RELATIONSHIP_TYPE_CODE',p_txn_party_detail_tbl(j).relationship_type_code);
7781 fnd_msg_pub.add;
7782 raise fnd_api.g_exc_error;
7783 END IF;
7784 END IF;
7785
7786 IF (p_txn_party_detail_tbl(j).relationship_type_code = 'OWNER') THEN
7787 IF (x_txn_sub_type_rec.nsrc_change_owner = 'Y') THEN
7788
7789 IF x_txn_sub_type_rec.nsrc_chg_owner_code = 'E' THEN
7790
7791 /* if change_owner = Y and chg_owner_code = E then party id should
7792 be external party id */
7793 IF p_txn_party_detail_tbl(j).party_source_id = p_order_line_rec.internal_party_id THEN
7794 fnd_message.set_name('CSI','CSI_INT_INV_PTY_ID');
7795 fnd_message.set_token('PARTY_ID',p_txn_party_detail_tbl(j).party_source_id);
7796 fnd_message.set_token('INSTANCE_PARTY_ID',p_order_line_rec.internal_party_id);
7797 fnd_msg_pub.add;
7798 raise fnd_api.g_exc_error;
7799 END IF;
7800 ELSE
7801
7802 /* if change_owner = N and chg_owner_code <> E then party id should
7803 be external party id */
7804
7805 IF p_txn_party_detail_tbl(j).party_source_id <> p_order_line_rec.internal_party_id THEN
7806 fnd_message.set_name('CSI','CSI_INT_INV_PTY_ID');
7807 fnd_message.set_token('PARTY_ID',p_txn_party_detail_tbl(j).party_source_id);
7808 fnd_message.set_token('INSTANCE_PARTY_ID',p_order_line_rec.internal_party_id);
7809 fnd_msg_pub.add;
7810 raise fnd_api.g_exc_error;
7811 END IF;
7812 END IF;
7813 END IF;
7814 END IF;
7815 END IF;
7816 END LOOP;
7817 END IF;
7818 END IF;
7819 END LOOP;
7820 END IF;
7821
7822 /* validating the relationships */
7823
7824 IF p_txn_ii_rltns_tbl.count > 0 THEN
7825 FOR j in p_txn_ii_rltns_tbl.first..p_txn_ii_rltns_tbl.last LOOP
7826
7827 debug('Validating ii_relationships .. ' );
7828
7829 IF NVL(p_txn_ii_rltns_tbl(j).csi_inst_relationship_id, fnd_api.g_miss_num) <> fnd_api.g_miss_num THEN
7830
7831 csi_utl_pkg.get_inst_relation(
7832 p_ii_relationship_id => p_txn_ii_rltns_tbl(j).csi_inst_relationship_id,
7833 x_object_id => l_curr_object_id,
7834 x_subject_id => l_curr_subject_id,
7835 x_return_status => x_return_status);
7836
7837 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7838 fnd_message.set_name('CSI','CSI_INT_II_REL_MISSING');
7839 fnd_message.set_token('II_RELATIONSHIP_ID',p_txn_ii_rltns_tbl(j).csi_inst_relationship_id);
7840 fnd_msg_pub.add;
7841 raise fnd_api.g_exc_error;
7842 END IF;
7843
7844 IF p_txn_line_detail_tbl.count > 0 THEN
7845 FOR i IN p_txn_line_detail_tbl.FIRST..p_txn_line_detail_tbl.LAST LOOP
7846 IF p_txn_line_detail_tbl(i).txn_line_detail_id = p_txn_ii_rltns_tbl(j).object_id then
7847 l_object_inst_id := p_txn_line_detail_tbl(i).instance_id;
7848 exit;
7849 END IF;
7850 END LOOP;
7851 END IF;
7852
7853 /* Check if the object id is being updated, if so raise error */
7854
7855 IF l_curr_object_id <> l_object_inst_id THEN
7856 fnd_message.set_name('CSI','CSI_INT_OBJ_ID_NOT_ALLOW_UPD');
7857 fnd_message.set_token('OBJECT_ID',l_object_inst_id);
7858 fnd_msg_pub.add;
7859 raise fnd_api.g_exc_error;
7860 END IF;
7861
7862 END IF;
7863
7864 ---Added (Start) for m-to-m enhancements
7865 -- IF p_txn_ii_rltns_tbl(j).relationship_type_code <> 'COMPONENT-OF' THEN
7866 -- debug('Only Component of relationship is allowed');
7867 -- END IF;
7868 ---Added (End) for m-to-m enhancements
7869
7870 END LOOP;
7871 END IF; -- end of relationship validation
7872
7873 EXCEPTION
7874 WHEN FND_API.G_EXC_ERROR THEN
7875 x_return_status := FND_API.G_RET_STS_ERROR ;
7876 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7877 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7878 END validate_txn_tbl;
7879
7880 /*----------------------------------------------------------*/
7881 /* Procedure name: process_option_item */
7882 /* Description : Procedure used to create the txn line */
7883 /* details if the txn line dtls have to be splitted in qty */
7884 /* ratio and txn details does not exist */
7885 /*----------------------------------------------------------*/
7886
7887 PROCEDURE process_option_item(
7888 p_serial_code IN NUMBER,
7889 p_order_line_rec IN order_line_rec,
7890 p_txn_sub_type_rec IN txn_sub_type_rec,
7891 p_trackable_parent IN BOOLEAN,
7892 x_order_shipment_tbl IN OUT NOCOPY order_shipment_tbl,
7893 x_model_inst_tbl IN OUT NOCOPY model_inst_tbl,
7894 x_trx_line_id OUT NOCOPY NUMBER,
7895 x_return_status OUT NOCOPY varchar2)
7896 IS
7897
7898 l_qty_ratio NUMBER;
7899 l_instance_id NUMBER;
7900 l_inst_party_id NUMBER;
7901 l_ip_account_id NUMBER;
7902 l_txn_ii NUMBER := 1;
7903 l_index NUMBER;
7904 x_msg_count NUMBER;
7905 x_msg_data varchar2(2000);
7906 l_party_site_id NUMBER;
7907 l_trx_line_id NUMBER;
7908
7909 x_cre_txn_line_rec csi_t_datastructures_grp.txn_line_rec ;
7910 x_txn_line_dtl_rec csi_t_datastructures_grp.txn_line_detail_rec;
7911 x_cre_txn_line_dtls_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
7912 x_cre_txn_party_dtls_tbl csi_t_datastructures_grp.txn_party_detail_tbl ;
7913 x_cre_txn_pty_acct_dtls_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
7914 x_cre_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
7915 x_cre_txn_ext_attb_vals_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
7916 x_cre_txn_systems_tbl csi_t_datastructures_grp.txn_systems_tbl;
7917 x_cre_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
7918
7919 l_install_party_site_id NUMBER;
7920 l_parent_line_qty NUMBER := fnd_api.g_miss_num;
7921 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
7922
7923 BEGIN
7924
7925 -- Initialize API return status to success
7926 x_return_status := fnd_api.g_ret_sts_success;
7927
7928 api_log('process_option_item');
7929
7930 /* Initialize the pl/sql tables */
7931 x_cre_txn_line_dtls_tbl.delete;
7932 x_cre_txn_party_dtls_tbl.delete;
7933 x_cre_txn_pty_acct_dtls_tbl.delete;
7934 x_cre_txn_org_assgn_tbl.delete;
7935 x_cre_txn_ext_attb_vals_tbl.delete;
7936 x_cre_txn_systems_tbl.delete;
7937 x_cre_txn_ii_rltns_tbl.delete;
7938
7939 -- assign values for the columns in Txn_line_rec
7940 x_cre_txn_line_rec.transaction_line_id := fnd_api.g_miss_num;
7941 x_cre_txn_line_rec.source_transaction_id := p_order_line_rec.order_line_id;
7942 x_cre_txn_line_rec.source_transaction_type_id := g_txn_type_id;
7943 x_cre_txn_line_rec.source_transaction_table := 'WSH_DELIVERY_DETAILS';
7944 x_cre_txn_line_rec.processing_status := 'IN_PROCESS';
7945 x_cre_txn_line_rec.object_version_number := 1;
7946
7947 --Code added for bug5194812--
7948 IF x_cre_txn_line_rec.source_transaction_type_id = 401 THEN
7949 x_cre_txn_line_rec.config_session_hdr_id := p_order_line_rec.config_header_id;
7950 x_cre_txn_line_rec.config_session_rev_num := p_order_line_rec.config_rev_nbr;
7951 x_cre_txn_line_rec.config_session_item_id := p_order_line_rec.configuration_id;
7952 x_cre_txn_line_rec.api_caller_identity := 'CONFIG';
7953 END IF;
7954 --Code end for bug5194812--
7955
7956 BEGIN
7957
7958 SELECT transaction_line_id
7959 INTO l_trx_line_id
7960 FROM csi_t_transaction_lines
7961 WHERE source_transaction_id = x_cre_txn_line_rec.source_transaction_id
7962 and source_transaction_table = x_cre_txn_line_rec.source_transaction_table
7963 and source_transaction_type_id = x_cre_txn_line_rec.source_transaction_type_id;
7964
7965 debug(' transaction_line_id : '||l_trx_line_id);
7966 EXCEPTION
7967 WHEN no_data_found THEN
7968 csi_t_txn_details_grp.create_transaction_dtls(
7969 p_api_version => 1.0,
7970 p_commit => fnd_api.g_false,
7971 p_init_msg_list => fnd_api.g_true,
7972 p_validation_level => fnd_api.g_valid_level_none,
7973 px_txn_line_rec => x_cre_txn_line_rec,
7974 px_txn_line_detail_tbl => x_cre_txn_line_dtls_tbl,
7975 px_txn_party_detail_tbl => x_cre_txn_party_dtls_tbl,
7976 px_txn_pty_acct_detail_tbl => x_cre_txn_pty_acct_dtls_tbl,
7977 px_txn_ii_rltns_tbl => x_cre_txn_ii_rltns_tbl,
7978 px_txn_org_assgn_tbl => x_cre_txn_org_assgn_tbl,
7979 px_txn_ext_attrib_vals_tbl => x_cre_txn_ext_attb_vals_tbl,
7980 px_txn_systems_tbl => x_cre_txn_systems_tbl,
7981 x_return_status => x_return_status,
7982 x_msg_count => x_msg_count,
7983 x_msg_data => x_msg_data);
7984
7985 l_trx_line_id := x_cre_txn_line_rec.transaction_line_id;
7986
7987 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7988 raise fnd_api.g_exc_error;
7989 END IF;
7990
7991 END ;
7992
7993 x_trx_line_id := l_trx_line_id;
7994
7995 csi_utl_pkg.get_qty_ratio(
7996 p_order_line_qty => p_order_line_rec.ordered_quantity,
7997 p_order_item_id => p_order_line_rec.inv_item_id,
7998 p_model_remnant_flag => p_order_line_rec.model_remnant_flag, --added for bug5096435
7999 p_link_to_line_id => p_order_line_rec.link_to_line_id,
8000 x_qty_ratio => l_qty_ratio ,
8001 x_return_status => l_return_status );
8002
8003 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
8004 raise fnd_api.g_exc_error;
8005 END IF;
8006
8007 rebuild_shipping_tbl(
8008 p_qty_ratio => l_qty_ratio
8009 ,x_order_shipment_tbl => x_order_shipment_tbl
8010 ,x_return_status => x_return_status );
8011
8012 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
8013 debug('rebuild_shipping_tbl failed ');
8014 raise fnd_api.g_exc_error;
8015 END IF;
8016
8017
8018
8019 IF x_order_shipment_tbl.count > 0 THEN
8020 FOR i in x_order_shipment_tbl.first..x_order_shipment_tbl.last LOOP
8021
8022 l_instance_id := x_order_shipment_tbl(i).instance_id ;
8023
8024 BEGIN
8025 SELECT party_site_id
8026 INTO l_party_site_id
8027 FROM hz_cust_acct_sites_all c,
8028 hz_cust_site_uses_all u
8029 WHERE c.cust_acct_site_id = u.cust_acct_site_id
8030 AND u.site_use_id = x_order_shipment_tbl(i).ib_current_loc_id; -- ship_to_org_id;
8031 Exception
8032 When no_data_found then
8033 fnd_message.set_name('CSI','CSI_INT_PTY_SITE_MISSING');
8034 fnd_message.set_token('LOCATION_ID', x_order_shipment_tbl(i).ib_current_loc_id); -- ship_to_org_id);
8035 fnd_msg_pub.add;
8036 debug('Party_site_id not found');
8037 raise fnd_api.g_exc_error;
8038 when too_many_rows then
8039 fnd_message.set_name('CSI','CSI_INT_MANY_PTY_SITE_FOUND');
8040 fnd_message.set_token('LOCATION_ID', x_order_shipment_tbl(i).ib_current_loc_id); -- ship_to_org_id);
8041 fnd_msg_pub.add;
8042 debug('Party_site_id not found');
8043 raise fnd_api.g_exc_error;
8044 END ;
8045
8046 IF x_order_shipment_tbl(i).ib_install_loc is not null
8047 AND
8048 x_order_shipment_tbl(i).ib_install_loc_id is not null
8049 AND
8050 x_order_shipment_tbl(i).ib_install_loc_id <> fnd_api.g_miss_num
8051 Then
8052 BEGIN
8053 SELECT party_site_id
8054 INTO l_install_party_site_id
8055 FROM hz_cust_acct_sites_all c,
8056 hz_cust_site_uses_all u
8057 WHERE c.cust_acct_site_id = u.cust_acct_site_id
8058 AND u.site_use_id = x_order_shipment_tbl(i).ib_install_loc_id; -- ship_to_org_id;
8059 Exception
8060 When no_data_found then
8061 fnd_message.set_name('CSI','CSI_INT_PTY_SITE_MISSING');
8062 fnd_message.set_token('LOCATION_ID', x_order_shipment_tbl(i).ib_install_loc_id); -- ship_to_org_id);
8063 fnd_msg_pub.add;
8064 debug('Party_site_id not found');
8065 raise fnd_api.g_exc_error;
8066 when too_many_rows then
8067 fnd_message.set_name('CSI','CSI_INT_MANY_PTY_SITE_FOUND');
8068 fnd_message.set_token('LOCATION_ID', x_order_shipment_tbl(i).ib_install_loc_id); -- ship_to_org_id);
8069 fnd_msg_pub.add;
8070 debug('Party_site_id not found');
8071 raise fnd_api.g_exc_error;
8072 end ;
8073 END IF;
8074
8075
8076 -- assign values for the columns in Txn_line_details_tbl
8077 x_cre_txn_line_dtls_tbl(i).instance_id := l_instance_id;
8078 x_cre_txn_line_dtls_tbl(i).sub_type_id := g_dflt_sub_type_id;
8079 x_cre_txn_line_dtls_tbl(i).instance_exists_flag := 'Y';
8080 x_cre_txn_line_dtls_tbl(i).source_transaction_flag := 'Y';
8081 x_cre_txn_line_dtls_tbl(i).inventory_item_id := x_order_shipment_tbl(i).inventory_item_id ;
8082 x_cre_txn_line_dtls_tbl(i).inv_organization_id := x_order_shipment_tbl(i).organization_id ;
8083 x_cre_txn_line_dtls_tbl(i).inventory_revision := x_order_shipment_tbl(i).revision ;
8084 x_cre_txn_line_dtls_tbl(i).item_condition_id := fnd_api.g_miss_num;
8085 x_cre_txn_line_dtls_tbl(i).instance_type_code := fnd_api.g_miss_char;
8086 x_cre_txn_line_dtls_tbl(i).quantity := x_order_shipment_tbl(i).shipped_quantity ;
8087 x_cre_txn_line_dtls_tbl(i).unit_of_measure := x_order_shipment_tbl(i).transaction_uom ;
8088 x_cre_txn_line_dtls_tbl(i).serial_number := x_order_shipment_tbl(i).serial_number;
8089 x_cre_txn_line_dtls_tbl(i).lot_number := x_order_shipment_tbl(i).lot_number;
8090 x_cre_txn_line_dtls_tbl(i).location_type_code := 'HZ_PARTY_SITES';
8091 x_cre_txn_line_dtls_tbl(i).location_id := l_party_site_id;
8092 -- Added for partner ordering
8093 x_cre_txn_line_dtls_tbl(i).install_location_type_code := x_cre_txn_line_dtls_tbl(i).location_type_code;
8094 x_cre_txn_line_dtls_tbl(i).install_location_id := l_install_party_site_id;
8095 -- End for Partner Ordering
8096 x_cre_txn_line_dtls_tbl(i).sellable_flag := 'Y';
8097 x_cre_txn_line_dtls_tbl(i).active_start_date := sysdate;
8098 x_cre_txn_line_dtls_tbl(i).object_version_number := 1 ;
8099 x_cre_txn_line_dtls_tbl(i).preserve_detail_flag := 'Y';
8100 x_cre_txn_line_dtls_tbl(i).processing_status := 'IN_PROCESS';
8101
8102 IF p_order_line_rec.serial_code <> 1 Then
8103 x_cre_txn_line_dtls_tbl(i).mfg_serial_number_flag := 'Y';
8104 ELSE
8105 x_cre_txn_line_dtls_tbl(i).mfg_serial_number_flag := 'N';
8106 END IF;
8107
8108 l_inst_party_id := csi_utl_pkg.get_instance_party_id(l_instance_id);
8109
8110 IF l_inst_party_id = -1 THEN
8111 raise fnd_api.g_exc_error;
8112 END IF;
8113
8114 -- assign values for the columns in txn_party_detail_tbl
8115 x_cre_txn_party_dtls_tbl(i).instance_party_id := l_inst_party_id;
8116 x_cre_txn_party_dtls_tbl(i).party_source_id := x_order_shipment_tbl(i).party_id;
8117 x_cre_txn_party_dtls_tbl(i).party_source_table := 'HZ_PARTIES';
8118 x_cre_txn_party_dtls_tbl(i).relationship_type_code := 'OWNER';
8119 x_cre_txn_party_dtls_tbl(i).contact_flag := 'N';
8120 x_cre_txn_party_dtls_tbl(i).active_start_date := sysdate;
8121 x_cre_txn_party_dtls_tbl(i).preserve_detail_flag := 'Y';
8122 x_cre_txn_party_dtls_tbl(i).object_version_number := 1;
8123 x_cre_txn_party_dtls_tbl(i).txn_line_details_index := i;
8124
8125 /* get ip_account_id only if instance_party_id does not exist */
8126
8127 IF l_inst_party_id is not null THEN
8128 l_ip_account_id := csi_utl_pkg.get_ip_account_id(l_inst_party_id);
8129 END IF;
8130
8131 /* If ip_account_id is -1 then account does not exist in IB */
8132
8133 IF l_ip_account_id = -1 THEN
8134 l_ip_account_id := NULL;
8135 END IF;
8136
8137 /* assign values for the columns in txn_pty_acct_dtl_tbl */
8138 x_cre_txn_pty_acct_dtls_tbl(i).ip_account_id := l_ip_account_id;
8139 x_cre_txn_pty_acct_dtls_tbl(i).account_id := x_order_shipment_tbl(i).end_customer_id; -- x_order_shipment_tbl(i).sold_to_org_id;
8140 x_cre_txn_pty_acct_dtls_tbl(i).bill_to_address_id := x_order_shipment_tbl(i).invoice_to_org_id;
8141 x_cre_txn_pty_acct_dtls_tbl(i).ship_to_address_id := x_order_shipment_tbl(i).ship_to_org_id;
8142 x_cre_txn_pty_acct_dtls_tbl(i).relationship_type_code := 'OWNER';
8143 x_cre_txn_pty_acct_dtls_tbl(i).active_start_date := sysdate;
8144 x_cre_txn_pty_acct_dtls_tbl(i).preserve_detail_flag := 'Y';
8145 x_cre_txn_pty_acct_dtls_tbl(i).object_version_number := 1;
8146 x_cre_txn_pty_acct_dtls_tbl(i).txn_party_details_index := i;
8147
8148 /*assign values for the columns in x_txn_org_assgn_tbl */
8149 IF nvl(x_order_shipment_tbl(i).sold_from_org_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
8150 THEN
8151 x_cre_txn_org_assgn_tbl(i).txn_operating_unit_id := fnd_api.g_miss_num;
8152 x_cre_txn_org_assgn_tbl(i).txn_line_detail_id := fnd_api.g_miss_num;
8153 x_cre_txn_org_assgn_tbl(i).instance_ou_id := fnd_api.g_miss_num;
8154 x_cre_txn_org_assgn_tbl(i).operating_unit_id := x_order_shipment_tbl(i).sold_from_org_id;
8155 x_cre_txn_org_assgn_tbl(i).relationship_type_code := 'SOLD_FROM';
8156 x_cre_txn_org_assgn_tbl(i).active_start_date := sysdate;
8157 x_cre_txn_org_assgn_tbl(i).preserve_detail_flag := 'Y';
8158 x_cre_txn_org_assgn_tbl(i).txn_line_details_index := i;
8159 x_cre_txn_org_assgn_tbl(i).object_version_number := 1;
8160 END IF;
8161
8162 l_index := i;
8163 x_txn_line_dtl_rec := x_cre_txn_line_dtls_tbl(i);
8164 x_txn_line_dtl_rec.transaction_line_id := l_trx_line_id;
8165
8166 debug(' cre_txn_line_dtls_tbl.count : '||x_cre_txn_line_dtls_tbl.count );
8167 debug(' cre_txn_party_dtls_tbl.count : '||x_cre_txn_party_dtls_tbl.count );
8168 debug(' cre_txn_pty_acct_dtls_tbl.count : '||x_cre_txn_pty_acct_dtls_tbl.count);
8169 debug(' cre_txn_ii_rltns_tbl.count : '||x_cre_txn_ii_rltns_tbl.count);
8170 debug(' cre_txn_org_assgn_tbl.count : '||x_cre_txn_org_assgn_tbl.count);
8171 debug(' cre_txn_ext_attb_vals_tbl.count : '||x_cre_txn_ext_attb_vals_tbl.count);
8172 debug(' cre_txn_systems_tbl.count : '||x_cre_txn_systems_tbl.count);
8173
8174 -- call api to create the transaction line details
8175 csi_t_txn_line_dtls_pvt.create_txn_line_dtls(
8176 p_api_version => 1.0 ,
8177 p_commit => fnd_api.g_false,
8178 p_init_msg_list => fnd_api.g_true,
8179 p_validation_level => fnd_api.g_valid_level_none,
8180 p_txn_line_dtl_index => l_index,
8181 p_txn_line_dtl_rec => x_txn_line_dtl_rec,
8182 px_txn_party_dtl_tbl => x_cre_txn_party_dtls_tbl,
8183 px_txn_pty_acct_detail_tbl => x_cre_txn_pty_acct_dtls_tbl,
8184 px_txn_ii_rltns_tbl => x_cre_txn_ii_rltns_tbl,
8185 px_txn_org_assgn_tbl => x_cre_txn_org_assgn_tbl,
8186 px_txn_ext_attrib_vals_tbl => x_cre_txn_ext_attb_vals_tbl,
8187 x_return_status => x_return_status,
8188 x_msg_count => x_msg_count,
8189 x_msg_data => x_msg_data);
8190
8191 IF x_return_status <> fnd_api.g_ret_sts_success THEN
8192 raise fnd_api.g_exc_error;
8193 END IF;
8194
8195 -- assign the txn details in the shipping pl/sql table
8196 x_order_shipment_tbl(i).txn_dtls_qty := x_order_shipment_tbl(i).shipped_quantity ;
8197 x_order_shipment_tbl(i).instance_match := 'Y';
8198 x_order_shipment_tbl(i).quantity_match := 'Y';
8199
8200 END LOOP;
8201
8202 --4483052
8203 IF p_trackable_parent
8204 THEN
8205 debug('Splitting the created installation details in to one each if it is a parent' );
8206 csi_utl_pkg.create_txn_dtls(
8207 p_source_trx_id => p_order_line_rec.order_line_id,
8208 p_source_trx_table => 'WSH_DELIVERY_DETAILS',
8209 x_return_status => l_return_status );
8210 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8211 raise fnd_api.g_exc_error;
8212 END IF;
8213 END IF;
8214
8215
8216 END IF;
8217
8218 EXCEPTION
8219 WHEN FND_API.G_EXC_ERROR THEN
8220 x_return_status := FND_API.G_RET_STS_ERROR ;
8221 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8222 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8223 END process_option_item;
8224
8225 /*----------------------------------------------------------*/
8226 /* Procedure name: rebuild_shipping_tbl */
8227 /* Description : Procedure that splits the shipment into */
8228 /* quantity of one if the item type code is config */
8229 /*----------------------------------------------------------*/
8230
8231 PROCEDURE rebuild_shipping_tbl(
8232 p_qty_ratio IN NUMBER
8233 ,x_order_shipment_tbl IN OUT NOCOPY order_shipment_tbl
8234 ,x_return_status OUT NOCOPY varchar2)
8235 IS
8236
8237 l_split_flag BOOLEAN := FALSE;
8238 l_instance_id NUMBER;
8239 l_ship_quantity NUMBER;
8240 x_msg_count NUMBER;
8241 x_msg_data varchar2(2000);
8242 l_count NUMBER := 1;
8243 l_rem_qty NUMBER ;
8244
8245 l_order_shipment_tbl order_shipment_tbl;
8246
8247 BEGIN
8248
8249 -- Initialize API return status to success
8250 x_return_status := fnd_api.g_ret_sts_success;
8251
8252 api_log('rebuild_shipping_tbl');
8253
8254 l_order_shipment_tbl.delete;
8255
8256 IF x_order_shipment_tbl.count > 0 THEN
8257 FOR i in x_order_shipment_tbl.first..x_order_shipment_tbl.last LOOP
8258
8259 IF x_order_shipment_tbl(i).shipped_quantity > p_qty_ratio THEN
8260
8261 l_rem_qty := x_order_shipment_tbl(i).shipped_quantity;
8262 x_order_shipment_tbl(i).shipped_quantity := p_qty_ratio;
8263 l_instance_id := x_order_shipment_tbl(i).instance_id;
8264 l_split_flag := TRUE;
8265
8266 WHILE l_split_flag LOOP
8267
8268 l_rem_qty := l_rem_qty - p_qty_ratio;
8269
8270 IF l_rem_qty > p_qty_ratio THEN
8271 l_split_flag := TRUE;
8272 l_ship_quantity := p_qty_ratio;
8273 ELSE
8274 l_split_flag := FALSE;
8275 l_ship_quantity := l_rem_qty ;
8276 END IF;
8277
8278 l_order_shipment_tbl(l_count).line_id := x_order_shipment_tbl(i).line_id ;
8279 l_order_shipment_tbl(l_count).header_id := x_order_shipment_tbl(i).header_id;
8280 l_order_shipment_tbl(l_count).instance_id := l_instance_id;
8281 l_order_shipment_tbl(l_count).party_id := x_order_shipment_tbl(i).party_id;
8282 l_order_shipment_tbl(l_count).party_source_table := 'HZ_PARTIES';
8283 l_order_shipment_tbl(l_count).party_account_id := x_order_shipment_tbl(i).end_customer_id; -- x_order_shipment_tbl(i).sold_to_org_id;
8284 l_order_shipment_tbl(l_count).inst_obj_version_number := x_order_shipment_tbl(i).inst_obj_version_number;
8285 l_order_shipment_tbl(l_count).inventory_item_id := x_order_shipment_tbl(i).inventory_item_id ;
8286 l_order_shipment_tbl(l_count).organization_id := x_order_shipment_tbl(i).organization_id ;
8287 l_order_shipment_tbl(l_count).revision := x_order_shipment_tbl(i).revision;
8288 l_order_shipment_tbl(l_count).subinventory := x_order_shipment_tbl(i).subinventory ;
8289 l_order_shipment_tbl(l_count).locator_id := x_order_shipment_tbl(i).locator_id ;
8290 l_order_shipment_tbl(l_count).lot_number := x_order_shipment_tbl(i).lot_number ;
8291 l_order_shipment_tbl(l_count).serial_number := x_order_shipment_tbl(i).serial_number ;
8292 l_order_shipment_tbl(l_count).transaction_uom := x_order_shipment_tbl(i).transaction_uom ;
8293 l_order_shipment_tbl(l_count).order_quantity_uom := x_order_shipment_tbl(i).order_quantity_uom ;
8294 l_order_shipment_tbl(l_count).invoice_to_contact_id := x_order_shipment_tbl(i).invoice_to_contact_id ;
8295 l_order_shipment_tbl(l_count).invoice_to_org_id := x_order_shipment_tbl(i).invoice_to_org_id;
8296 l_order_shipment_tbl(l_count).line_type_id := x_order_shipment_tbl(i).line_type_id ;
8297 l_order_shipment_tbl(l_count).ordered_quantity := x_order_shipment_tbl(i).ordered_quantity;
8298 l_order_shipment_tbl(l_count).ord_line_shipped_qty := x_order_shipment_tbl(i).ord_line_shipped_qty;
8299 l_order_shipment_tbl(l_count).ship_to_contact_id := x_order_shipment_tbl(i).ship_to_contact_id;
8300 l_order_shipment_tbl(l_count).ship_to_org_id := x_order_shipment_tbl(i).ship_to_org_id ;
8301 l_order_shipment_tbl(l_count).ship_from_org_id := x_order_shipment_tbl(i).ship_from_org_id ;
8302 l_order_shipment_tbl(l_count).sold_to_org_id := x_order_shipment_tbl(i).sold_to_org_id ;
8303 l_order_shipment_tbl(l_count).sold_from_org_id := x_order_shipment_tbl(i).sold_from_org_id ;
8304 l_order_shipment_tbl(l_count).source_line_id := x_order_shipment_tbl(i).source_line_id ;
8305 l_order_shipment_tbl(l_count).transaction_type_id := x_order_shipment_tbl(i).transaction_type_id ;
8306 l_order_shipment_tbl(l_count).customer_id := x_order_shipment_tbl(i).end_customer_id; -- x_order_shipment_tbl(i).customer_id ;
8307 l_order_shipment_tbl(l_count).transaction_date := x_order_shipment_tbl(i).transaction_date ;
8308 l_order_shipment_tbl(l_count).item_type_code := x_order_shipment_tbl(i).item_type_code ;
8309 l_order_shipment_tbl(l_count).cust_po_number := x_order_shipment_tbl(i).cust_po_number ;
8310 l_order_shipment_tbl(l_count).ato_line_id := x_order_shipment_tbl(i).ato_line_id ;
8311 l_order_shipment_tbl(l_count).top_model_line_id := x_order_shipment_tbl(i).top_model_line_id ;
8312 l_order_shipment_tbl(l_count).link_to_line_id := x_order_shipment_tbl(i).link_to_line_id ;
8313 l_order_shipment_tbl(l_count).shipped_quantity := l_ship_quantity ;
8314 -- Added for partner ordering
8315 l_order_shipment_tbl(l_count).ib_install_loc := x_order_shipment_tbl(i).ib_install_loc;
8316 l_order_shipment_tbl(l_count).ib_install_loc_id := x_order_shipment_tbl(i).ib_install_loc_id;
8317 l_order_shipment_tbl(l_count).ib_current_loc := x_order_shipment_tbl(i).ib_current_loc;
8318 l_order_shipment_tbl(l_count).ib_current_loc_id := x_order_shipment_tbl(i).ib_current_loc_id;
8319 -- Begin fix for Bug 3435269
8320 l_order_shipment_tbl(l_count).end_customer_id := x_order_shipment_tbl(i).end_customer_id;
8321 -- End fix for 3435269
8322 -- End for partner ordering
8323 l_count := l_count +1 ;
8324
8325 END LOOP; -- end of while loop
8326
8327 END IF;
8328 END LOOP; -- end of for loop
8329 END IF; -- end if for x_order_shipment_tbl > 0
8330
8331 debug('l_order_shipment_tbl.count ='||l_order_shipment_tbl.count );
8332
8333 IF l_order_shipment_tbl.count > 0 THEN
8334 FOR i in l_order_shipment_tbl.first..l_order_shipment_tbl.last LOOP
8335 x_order_shipment_tbl(x_order_shipment_tbl.count + 1) := l_order_shipment_tbl(i);
8336 END LOOP;
8337 END IF;
8338
8339 debug('x_order_shipment_tbl.count ='||x_order_shipment_tbl.count );
8340
8341 EXCEPTION
8342 WHEN FND_API.G_EXC_ERROR THEN
8343 x_return_status := FND_API.G_RET_STS_ERROR ;
8344 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8345 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
8346 END rebuild_shipping_tbl;
8347
8348 /*----------------------------------------------------------*/
8349 /* Procedure name :DECODE_MESSAGE */
8350 /* Description :Procedure used to decode the messages */
8351 /*----------------------------------------------------------*/
8352
8353 PROCEDURE decode_message(
8354 p_msg_header IN XNP_MESSAGE.MSG_HEADER_REC_TYPE,
8355 p_msg_text IN varchar2,
8356 x_return_status OUT NOCOPY varchar2,
8357 x_error_message OUT NOCOPY varchar2,
8358 x_mtl_trx_rec OUT NOCOPY MTL_TXN_REC)
8359 IS
8360
8361 l_api_name varchar2(100) := 'csi_order_ship_pub.decode_message';
8362 l_fnd_unexpected varchar2(1) := fnd_api.g_ret_sts_unexp_error;
8363 l_mtl_txn_id number;
8364 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
8365
8366 BEGIN
8367
8368 -- Initialize API return status to success
8369 x_return_status := fnd_api.g_ret_sts_success;
8370
8371 api_log('decode_message');
8372
8373 xnp_xml_utils.decode(P_Msg_Text, 'MTL_TRANSACTION_ID', l_mtl_txn_id);
8374
8375 IF (l_mtl_txn_id is NULL) or
8376 (l_mtl_txn_id = fnd_api.g_miss_num) THEN
8377 raise fnd_api.g_exc_error;
8378 END IF;
8379
8380 csi_utl_pkg.get_source_trx_dtls(
8381 p_mtl_transaction_id => l_mtl_txn_id,
8382 x_mtl_txn_rec => X_MTL_TRX_REC,
8383 x_error_message => x_error_message,
8384 x_return_status => l_return_status);
8385
8386 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8387 raise fnd_api.g_exc_error;
8388 END IF;
8389
8390 EXCEPTION
8391 WHEN fnd_api.g_exc_error THEN
8392 fnd_message.set_name('CSI','CSI_DECODE_MGS_ERROR');
8393 fnd_message.set_token('message_id',p_msg_header.message_id);
8394 fnd_message.set_token('MESSAGE_CODE',p_msg_header.message_code);
8395 fnd_msg_pub.add;
8396 x_error_message := fnd_msg_pub.get;
8397 x_return_status := l_fnd_unexpected;
8398
8399 WHEN others THEN
8400 fnd_message.set_name('CSI','CSI_UNEXP_SQL_ERROR');
8401 fnd_message.set_token('API_NAME',l_api_name);
8402 fnd_message.set_token('SQL_ERROR',SQLERRM);
8403 fnd_msg_pub.add;
8404 x_error_message := fnd_msg_pub.get;
8405 x_return_status := l_fnd_unexpected;
8406 END decode_message;
8407
8408 PROCEDURE oke_shipment(
8409 p_mtl_txn_id IN number,
8410 x_return_status OUT NOCOPY varchar2,
8411 px_trx_error_rec IN OUT NOCOPY csi_datastructures_pub.transaction_error_rec)
8412 IS
8413
8414 l_oke_source_table varchar2(30) := csi_interface_pkg.g_oke_source_table;
8415
8416 l_inventory_item_id number;
8417 l_organization_id number;
8418 l_source_line_id number;
8419 l_source_quantity number;
8420 l_mtl_txn_tbl csi_interface_pkg.mtl_txn_tbl;
8421 l_item_attrib_rec csi_interface_pkg.item_attributes_rec;
8422
8423 l_source_header_rec csi_interface_pkg.source_header_rec;
8424 l_source_line_rec csi_interface_pkg.source_line_rec;
8425
8426 l_csi_txn_rec csi_datastructures_pub.transaction_rec;
8427
8428 l_txn_line_rec csi_t_datastructures_grp.txn_line_rec;
8429 l_txn_line_detail_tbl csi_t_datastructures_grp.txn_line_detail_tbl;
8430 l_txn_party_tbl csi_t_datastructures_grp.txn_party_detail_tbl;
8431 l_txn_party_acct_tbl csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
8432 l_txn_org_assgn_tbl csi_t_datastructures_grp.txn_org_assgn_tbl;
8433 l_txn_ii_rltns_tbl csi_t_datastructures_grp.txn_ii_rltns_tbl;
8434 l_txn_eav_tbl csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
8435 l_txn_systems_tbl csi_t_datastructures_grp.txn_systems_tbl;
8436
8437 l_pricing_attribs_tbl csi_datastructures_pub.pricing_attribs_tbl;
8438
8439 l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
8440 l_return_message varchar2(2000);
8441 l_msg_count number;
8442 l_msg_data varchar2(2000);
8443
8444 l_error_rec csi_datastructures_pub.transaction_error_rec;
8445
8446 BEGIN
8447
8448 savepoint oke_shipment;
8449
8450 x_return_status := fnd_api.g_ret_sts_success;
8451 l_error_rec := px_trx_error_rec;
8452
8453 /* builds the debug file name */
8454 csi_t_gen_utility_pvt.build_file_name (
8455 p_file_segment1 => 'csiokshp',
8456 p_file_segment2 => p_mtl_txn_id);
8457
8458 api_log('oke_shipment');
8459
8460 debug(' Transaction Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
8461 debug(' Transaction Type :Sales Order Shipment');
8462 debug(' Transaction ID :'||p_mtl_txn_id);
8463
8464 l_error_rec.source_id := p_mtl_txn_id;
8465
8466 /* this routine checks if ib is active */
8467 csi_utility_grp.check_ib_active;
8468
8469 SELECT inventory_item_id,
8470 organization_id,
8471 picking_line_id,
8472 abs(primary_quantity)
8473 INTO l_inventory_item_id,
8474 l_organization_id,
8475 l_source_line_id,
8476 l_source_quantity
8477 FROM mtl_material_transactions
8478 WHERE transaction_id = p_mtl_txn_id;
8479
8480 csi_interface_pkg.get_source_info(
8481 p_source_table => l_oke_source_table,
8482 p_source_id => l_source_line_id,
8483 x_source_header_rec => l_source_header_rec,
8484 x_source_line_rec => l_source_line_rec,
8485 x_return_status => l_return_status);
8486
8487 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8488 RAISE fnd_api.g_exc_error;
8489 END IF;
8490
8491 l_error_rec.source_header_ref := l_source_header_rec.source_header_ref;
8492 l_error_rec.source_header_ref_id := l_source_header_rec.source_header_id;
8493 l_error_rec.source_line_ref := l_source_line_rec.source_line_ref;
8494 l_error_rec.source_line_ref_id := l_source_line_rec.source_line_id;
8495
8496 l_source_line_rec.source_quantity := l_source_quantity;
8497 l_source_line_rec.shipped_quantity := l_source_quantity;
8498
8499 csi_interface_pkg.get_item_attributes(
8500 p_inventory_item_id => l_inventory_item_id,
8501 p_organization_id => l_organization_id,
8502 x_item_attrib_rec => l_item_attrib_rec,
8503 x_return_status => l_return_status);
8504
8505 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8506 RAISE fnd_api.g_exc_error;
8507 END IF;
8508
8509 l_error_rec.inventory_item_id := l_inventory_item_id;
8510 l_error_rec.src_serial_num_ctrl_code := l_item_attrib_rec.serial_control_code;
8511 l_error_rec.src_lot_ctrl_code := l_item_attrib_rec.lot_control_code;
8512 l_error_rec.src_location_ctrl_code := l_item_attrib_rec.locator_control_code;
8513 l_error_rec.src_rev_qty_ctrl_code := l_item_attrib_rec.revision_control_code;
8514 l_error_rec.comms_nl_trackable_flag := l_item_attrib_rec.ib_trackable_flag;
8515
8516 l_source_line_rec.uom_code := l_item_attrib_rec.primary_uom_code;
8517
8518 csi_interface_pkg.get_mtl_txn_tbl(
8519 p_mtl_txn_id => p_mtl_txn_id,
8520 x_mtl_txn_tbl => l_mtl_txn_tbl,
8521 x_return_status => l_return_status);
8522
8523 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8524 RAISE fnd_api.g_exc_error;
8525 END IF;
8526
8527 IF l_mtl_txn_tbl.count > 0 THEN
8528
8529 -- create csi_txn_rec
8530
8531 l_csi_txn_rec.transaction_id := fnd_api.g_miss_num;
8532 l_csi_txn_rec.source_header_ref_id := l_source_header_rec.source_header_id;
8533 l_csi_txn_rec.source_header_ref := l_source_header_rec.source_header_ref;
8534 l_csi_txn_rec.source_line_ref_id := l_source_line_rec.source_line_id;
8535 l_csi_txn_rec.source_line_ref := l_source_line_rec.source_line_ref;
8536 l_csi_txn_rec.inv_material_transaction_id := p_mtl_txn_id;
8537 l_csi_txn_rec.transaction_type_id := 326;
8538 l_csi_txn_rec.transaction_date := sysdate;
8539 l_csi_txn_rec.source_transaction_date := l_mtl_txn_tbl(1).transaction_date;
8540 l_csi_txn_rec.transaction_quantity := l_source_line_rec.shipped_quantity;
8541 l_csi_txn_rec.transaction_status_code := 'PENDING';
8542
8543 csi_transactions_pvt.create_transaction(
8544 p_api_version => 1.0,
8545 p_commit => fnd_api.g_false,
8546 p_init_msg_list => fnd_api.g_true,
8547 p_validation_level => fnd_api.g_valid_level_full,
8548 p_success_if_exists_flag => 'Y',
8549 p_transaction_rec => l_csi_txn_rec,
8550 x_return_status => l_return_status,
8551 x_msg_count => l_msg_count,
8552 x_msg_data => l_msg_data);
8553
8554 csi_interface_pkg.pre_process_mtl_txn_tbl(
8555 p_item_attrib_rec => l_item_attrib_rec,
8556 px_mtl_txn_tbl => l_mtl_txn_tbl,
8557 x_return_status => l_return_status);
8558
8559 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8560 RAISE fnd_api.g_exc_error;
8561 END IF;
8562
8563 csi_interface_pkg.get_inventory_instances(
8564 p_item_attrib_rec => l_item_attrib_rec,
8565 px_mtl_txn_tbl => l_mtl_txn_tbl,
8566 x_return_status => l_return_status);
8567
8568 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8569 RAISE fnd_api.g_exc_error;
8570 END IF;
8571
8572 -- decrement source instances
8573 csi_interface_pkg.decrement_inventory_instances(
8574 p_item_attrib_rec => l_item_attrib_rec,
8575 p_mtl_txn_tbl => l_mtl_txn_tbl,
8576 px_txn_rec => l_csi_txn_rec,
8577 x_return_status => l_return_status);
8578
8579 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8580 RAISE fnd_api.g_exc_error;
8581 END IF;
8582
8583 IF l_item_attrib_rec.serial_control_code = 6 THEN
8584 IF l_mtl_txn_tbl.count > 0 THEN
8585 FOR ret_ind IN l_mtl_txn_tbl.FIRST .. l_mtl_txn_tbl.LAST
8586 LOOP
8587 BEGIN
8588 SELECT instance_id
8589 INTO l_mtl_txn_tbl(ret_ind).instance_id
8590 FROM csi_item_instances
8591 WHERE inventory_item_id = l_mtl_txn_tbl(ret_ind).inventory_item_id
8592 AND serial_number = l_mtl_txn_tbl(ret_ind).serial_number
8593 AND instance_usage_code = 'RETURNED';
8594 EXCEPTION
8595 WHEN no_data_found THEN
8596 l_mtl_txn_tbl(ret_ind).instance_id := fnd_api.g_miss_num;
8597 END;
8598 END LOOP;
8599 END IF;
8600 END IF;
8601
8602 csi_interface_pkg.build_default_txn_detail(
8603 p_source_table => l_oke_source_table,
8604 p_source_id => l_source_line_id,
8605 p_source_header_rec => l_source_header_rec,
8606 p_source_line_rec => l_source_line_rec,
8607 p_csi_txn_rec => l_csi_txn_rec,
8608 px_txn_line_rec => l_txn_line_rec,--Modified to IN OUT param for bug 5194812
8609 x_txn_line_detail_tbl => l_txn_line_detail_tbl,
8610 x_txn_party_tbl => l_txn_party_tbl,
8611 x_txn_party_acct_tbl => l_txn_party_acct_tbl,
8612 x_txn_org_assgn_tbl => l_txn_org_assgn_tbl,
8613 x_pricing_attribs_tbl => l_pricing_attribs_tbl,
8614 x_return_status => l_return_status);
8615
8616 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8617 RAISE fnd_api.g_exc_error;
8618 END IF;
8619
8620 -- match transaction detail with material transaction
8621 csi_interface_pkg.sync_txn_dtl_and_mtl_txn(
8622 p_mtl_txn_tbl => l_mtl_txn_tbl,
8623 p_item_attrib_rec => l_item_attrib_rec,
8624 px_txn_line_dtl_tbl => l_txn_line_detail_tbl,
8625 px_txn_party_dtl_tbl => l_txn_party_tbl,
8626 px_txn_party_acct_tbl => l_txn_party_acct_tbl,
8627 px_txn_org_assgn_tbl => l_txn_org_assgn_tbl,
8628 px_txn_eav_tbl => l_txn_eav_tbl,
8629 px_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
8630 x_return_status => l_return_status);
8631
8632 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8633 RAISE fnd_api.g_exc_error;
8634 END IF;
8635
8636 -- ##**##-- comment this line later.
8637 l_source_line_rec.fulfilled_date := sysdate;
8638
8639 csi_interface_pkg.interface_ib(
8640 p_source_header_rec => l_source_header_rec,
8641 p_source_line_rec => l_source_line_rec,
8642 px_csi_txn_rec => l_csi_txn_rec,
8643 px_txn_line_rec => l_txn_line_rec,
8644 px_txn_line_dtl_tbl => l_txn_line_detail_tbl,
8645 px_txn_party_tbl => l_txn_party_tbl,
8646 px_txn_party_acct_tbl => l_txn_party_acct_tbl,
8647 px_txn_org_assgn_tbl => l_txn_org_assgn_tbl,
8648 px_txn_eav_tbl => l_txn_eav_tbl,
8649 px_txn_ii_rltns_tbl => l_txn_ii_rltns_tbl,
8650 px_pricing_attribs_tbl => l_pricing_attribs_tbl,
8651 x_return_status => l_return_status,
8652 x_return_message => l_return_message);
8653
8654 IF l_return_status <> fnd_api.g_ret_sts_success THEN
8655 RAISE fnd_api.g_exc_error;
8656 END IF;
8657
8658 ELSE
8659 null;
8660 -- no material transaction records. error to be set
8661 END IF;
8662
8663 EXCEPTION
8664 WHEN fnd_api.g_exc_error THEN
8665 rollback to oke_shipment;
8666 x_return_status := fnd_api.g_ret_sts_error;
8667 l_error_rec.error_text := csi_t_gen_utility_pvt.dump_error_stack;
8668 px_trx_error_rec := l_error_rec;
8669 debug('Error(E) :'||l_error_rec.error_text);
8670 WHEN others THEN
8671 rollback to oke_shipment;
8672 fnd_message.set_name ('FND', 'FND_GENERIC_MESSAGE');
8673 fnd_message.set_token('MESSAGE', 'OTHERS Error :'||substr(sqlerrm, 1, 540));
8674 fnd_msg_pub.add;
8675 x_return_status := fnd_api.g_ret_sts_error;
8676 l_error_rec.error_text := csi_t_gen_utility_pvt.dump_error_stack;
8677 px_trx_error_rec := l_error_rec;
8678 debug('Error(O) :'||l_error_rec.error_text);
8679 END oke_shipment;
8680
8681 END csi_order_ship_pub ;