DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSD_PROCESS_UTIL

Source


1 PACKAGE BODY CSD_PROCESS_UTIL as
2 /* $Header: csdvutlb.pls 120.48.12020000.6 2013/03/15 00:42:19 takwong ship $ */
3 
4 G_PKG_NAME    CONSTANT VARCHAR2(30) := 'CSD_PROCESS_UTIL';
5 G_FILE_NAME   CONSTANT VARCHAR2(12) := 'csdvutlb.pls';
6 g_debug NUMBER := csd_gen_utility_pvt.g_debug_level;
7 -- bug#7355526, nnadig.
8 -- cache for maintaining the inventory parameters for negative inventory.
9 type negative_inventory is table of NUMBER index by pls_integer;
10 type override_negative_qty is table of number index by pls_integer;
11 g_negative_inventory negative_inventory;
12 g_override_negative_qty override_negative_qty;
13 -- end bug#7355526, nnadig.
14 
15 
16 /*
17 -- bug fix for 4108369, Begin
18 FUNCTION Get_Sr_add_to_order (
19 	 p_repair_line_Id IN NUMBER,
20 	 p_action_type IN VARCHAR2
21     ) RETURN NUMBER;
22 -- bug fix for 4108369, End
23 */
24 PROCEDURE Check_Reqd_Param (
25   p_param_value	    IN	NUMBER,
26   p_param_name		IN	VARCHAR2,
27   p_api_name		IN	VARCHAR2
28   )
29 IS
30 
31 BEGIN
32 
33   IF (NVL(p_param_value,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) THEN
34     FND_MESSAGE.SET_NAME('CSD','CSD_API_MISSING_PARAM');
35     FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
36     FND_MESSAGE.SET_TOKEN('MISSING_PARAM',p_param_name);
37     FND_MSG_PUB.Add;
38     RAISE FND_API.G_EXC_ERROR;
39   END IF;
40 
41 END Check_Reqd_Param;
42 
43 PROCEDURE Check_Reqd_Param (
44   p_param_value	    IN	VARCHAR2,
45   p_param_name		IN	VARCHAR2,
46   p_api_name		IN	VARCHAR2
47   )
48 IS
49 
50 BEGIN
51 
52   IF (NVL(p_param_value,FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR) THEN
53     FND_MESSAGE.SET_NAME('CSD','CSD_API_MISSING_PARAM');
54     FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
55     FND_MESSAGE.SET_TOKEN('MISSING_PARAM',p_param_name);
56     FND_MSG_PUB.Add;
57     RAISE FND_API.G_EXC_ERROR;
58   END IF;
59 
60 END Check_Reqd_Param;
61 
62 PROCEDURE Check_Reqd_Param (
63   p_param_value	    IN	DATE,
64   p_param_name		IN	VARCHAR2,
65   p_api_name		IN	VARCHAR2
66   )
67 IS
68 
69 BEGIN
70 
71   IF (NVL(p_param_value,FND_API.G_MISS_DATE) = FND_API.G_MISS_DATE) THEN
72     FND_MESSAGE.SET_NAME('CSD','CSD_API_MISSING_PARAM');
73     FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
74     FND_MESSAGE.SET_TOKEN('MISSING_PARAM',p_param_name);
75     FND_MSG_PUB.Add;
76     RAISE FND_API.G_EXC_ERROR;
77   END IF;
78 
79 END Check_Reqd_Param;
80 
81 FUNCTION Get_No_Chg_Flag
82 ( p_txn_billing_type_id   IN	NUMBER
83  ) RETURN VARCHAR2
84  IS
85    l_no_chg_flag varchar2(1);
86 BEGIN
87   Begin
88     Select Nvl(ctt.no_charge_flag,'N')
89     into l_no_chg_flag
90     from cs_txn_billing_types ctbt,
91 	    cs_transaction_types ctt
92     where ctbt.transaction_type_id = ctt.transaction_type_id
93     and   ctbt.txn_billing_type_id = p_txn_billing_type_id;
94     Return l_no_chg_flag;
95   Exception
96     When No_data_found then
97       FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_TXN_BILL_TYPE_ID');
98       FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID',p_txn_billing_type_id);
99       FND_MSG_PUB.Add;
100       RAISE FND_API.G_EXC_ERROR;
101     When Others then
102       FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_TXN_BILL_TYPE_ID');
103       FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID',p_txn_billing_type_id);
104       FND_MSG_PUB.Add;
105       RAISE FND_API.G_EXC_ERROR;
106   End;
107 END Get_No_Chg_Flag;
108 
109 
110 FUNCTION Validate_action
111 (
112   p_action        IN	VARCHAR2,
113   p_api_name	  IN	VARCHAR2
114  ) RETURN BOOLEAN
115 IS
116 
117 BEGIN
118 
119   IF (p_api_name = 'PROCESS_CHARGE_LINES') THEN
120    IF (p_action not in ('CREATE','UPDATE','DELETE')) THEN
121     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ACTION');
122     FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
123     FND_MESSAGE.SET_TOKEN('ACTION',p_action);
124     FND_MSG_PUB.Add;
125     RETURN FALSE;
126    ELSE
127     RETURN TRUE;
128    END IF;
129 
130   ELSIF  (p_api_name = 'PROCESS_SALES_ORDER') THEN
131    IF (p_action not in ('CREATE','BOOK','PICK-RELEASE','SHIP')) THEN
132     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ACTION');
133     FND_MESSAGE.SET_TOKEN('API_NAME',p_api_name);
134     FND_MESSAGE.SET_TOKEN('ACTION',p_action);
135     FND_MSG_PUB.Add;
136     RETURN FALSE;
137    ELSE
138     RETURN TRUE;
139    END IF;
140 
141   END IF;
142 
143 END Validate_action;
144 
145 FUNCTION Validate_incident_id
146 (
147   p_incident_id	  IN	NUMBER
148  ) RETURN BOOLEAN
149  IS
150 
151 l_dummy   VARCHAR2(1);
152 
153 BEGIN
154 
155  select 'X'
156  into l_dummy
157  from cs_incidents_all_b
158  where incident_id = p_incident_id;
159  -- swai: bug 7273784 - start_date_active and end_date_active
160  -- are obsoleted by service team
161  -- and   sysdate between nvl(start_date_active,sysdate)
162  -- and nvl(end_date_active, sysdate);
163 
164  RETURN TRUE;
165 EXCEPTION
166 When NO_DATA_FOUND then
167     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_SR_ID');
168     FND_MESSAGE.SET_TOKEN('INCIDENT_ID',p_incident_id);
169     FND_MSG_PUB.Add;
170     RETURN FALSE;
171 END Validate_incident_id;
172 
173 FUNCTION Validate_repair_type_id
174 (
175   p_repair_type_id	  IN	NUMBER
176  ) RETURN BOOLEAN
177  IS
178 
179 l_dummy   VARCHAR2(1);
180 
181 BEGIN
182 
183  select 'X'
184  into l_dummy
185  from csd_repair_types_vl
186  where repair_type_id = p_repair_type_id
187  and   sysdate between nvl(start_date_active,sysdate)
188  and nvl(end_date_active, sysdate);
189 
190  RETURN TRUE;
191 EXCEPTION
192 When NO_DATA_FOUND then
193     FND_MESSAGE.SET_NAME('CSD','CSD_API_REPAIR_TYPE_ID');
194     FND_MESSAGE.SET_TOKEN('REPAIR_TYPE_ID',p_repair_type_id);
195     FND_MSG_PUB.Add;
196     RETURN FALSE;
197 END Validate_repair_type_id;
198 
199 FUNCTION Validate_wip_entity_id
200 (
201   p_wip_entity_id	  IN	NUMBER
202  ) RETURN BOOLEAN
203  IS
204 
205 l_dummy   VARCHAR2(1);
206 
207 BEGIN
208 
209  select 'X'
210  into l_dummy
211  from wip_discrete_jobs
212  where wip_entity_id = p_wip_entity_id;
213 
214  RETURN TRUE;
215 EXCEPTION
216 When NO_DATA_FOUND then
217     FND_MESSAGE.SET_NAME('CSD','CSD_API_WIP_ENTITY_ID');
218     FND_MESSAGE.SET_TOKEN('WIP_ENTITY_ID',p_wip_entity_id);
219     FND_MSG_PUB.Add;
220     RETURN FALSE;
221 END Validate_wip_entity_id;
222 
223 FUNCTION Validate_repair_group_id
224 (
225   p_repair_group_id	  IN	NUMBER
226  ) RETURN BOOLEAN
227  IS
228 
229 l_dummy   VARCHAR2(1);
230 
231 BEGIN
232 
233  select 'X'
234  into l_dummy
235  from csd_repair_order_groups
236  where repair_group_id = p_repair_group_id;
237 
238  RETURN TRUE;
239 EXCEPTION
240 When NO_DATA_FOUND then
241     FND_MESSAGE.SET_NAME('CSD','CSD_API_REPAIR_GROUP_ID');
242     FND_MESSAGE.SET_TOKEN('REPAIR_GROUP_ID',p_repair_group_id);
243     FND_MSG_PUB.Add;
244     RETURN FALSE;
245 END Validate_repair_group_id;
246 
247 FUNCTION Validate_ro_job_date
248 (
249   p_date  IN  DATE
250  ) RETURN BOOLEAN
251  IS
252 
253 l_dummy   VARCHAR2(1);
254 
255 BEGIN
256 
257  select 'x'
258  into l_dummy
259  from  bom_calendar_dates
260  where calendar_date = p_date;
261 
262  RETURN TRUE;
263 EXCEPTION
264 When NO_DATA_FOUND then
265     FND_MESSAGE.SET_NAME('CSD','CSD_API_NOT_BOM_DATE');
266     FND_MESSAGE.SET_TOKEN('DATE',p_date);
267     FND_MSG_PUB.Add;
268     RETURN FALSE;
269 When TOO_MANY_ROWS then
270     RETURN TRUE;
271 END Validate_ro_job_date;
272 
273 FUNCTION Validate_Inventory_item_id
274 (
275   p_inventory_item_id	  IN	NUMBER
276  ) RETURN BOOLEAN
277  IS
278 
279 l_dummy   VARCHAR2(1);
280 l_org_id  NUMBER;
281 
282 BEGIN
283 
284  l_org_id := cs_std.get_item_valdn_orgzn_id;
285 
286  select 'X'
287  into l_dummy
288  from  mtl_system_items
289  where inventory_item_id = p_inventory_item_id
290  and   organization_id   = l_org_id
291  and   sysdate between nvl(start_date_active,sysdate)
292  and nvl(end_date_active, sysdate);
293 
294  RETURN TRUE;
295 EXCEPTION
296 When NO_DATA_FOUND then
297     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ITEM_ID');
298     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID',p_inventory_item_id);
299     FND_MSG_PUB.Add;
300     RETURN FALSE;
301 END Validate_inventory_item_id;
302 
303 FUNCTION Validate_Unit_of_measure
304 (
305   p_unit_of_measure	  IN	VARCHAR2
306  ) RETURN BOOLEAN
307  IS
308 
309 l_dummy   VARCHAR2(1);
310 
311 BEGIN
312 
313 
314  select 'X'
315  into l_dummy
316  from  mtl_units_of_measure_vl
317  where uom_code = p_unit_of_measure
318  and   sysdate between nvl(creation_date,sysdate)
319  and nvl(disable_date, sysdate);
320 
321  RETURN TRUE;
322 EXCEPTION
323 When NO_DATA_FOUND then
324     FND_MESSAGE.SET_NAME('CSD','CSD_API_UOM');
325     FND_MESSAGE.SET_TOKEN('UNIT_OF_MEASURE',p_unit_of_measure);
326     FND_MSG_PUB.Add;
327 END Validate_Unit_of_measure;
328 
329 
330 PROCEDURE Convert_Est_to_Chg_rec
331 (
332   p_estimate_line_rec  IN	CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_REC,
333   x_charges_rec        OUT NOCOPY	CS_CHARGE_DETAILS_PUB.CHARGES_REC_TYPE,
334   x_return_status      OUT NOCOPY	VARCHAR2
335  ) IS
336 
337 BEGIN
338 
339  x_return_status := FND_API.G_RET_STS_SUCCESS;
340 
341 
342  x_charges_rec.estimate_detail_id          := p_estimate_line_rec.estimate_detail_id;
343  x_charges_rec.incident_id                 := p_estimate_line_rec.incident_id;
344  x_charges_rec.original_source_id          := p_estimate_line_rec.repair_line_id;
345  x_charges_rec.original_source_code        := 'DR' ;
346  x_charges_rec.source_id                   := p_estimate_line_rec.repair_line_id;
347  x_charges_rec.source_code                 := 'DR' ;
348  x_charges_rec.LINE_TYPE_ID                := p_estimate_line_rec.LINE_TYPE_ID;
349  x_charges_rec.txn_billing_type_id         := p_estimate_line_rec.txn_billing_type_id;
350  x_charges_rec.business_process_id         := p_estimate_line_rec.business_process_id;
351  x_charges_rec.inventory_item_id_in        := p_estimate_line_rec.inventory_item_id;
352  x_charges_rec.price_list_id               := p_estimate_line_rec.price_list_id;
353  x_charges_rec.currency_code               := p_estimate_line_rec.currency_code;
354  x_charges_rec.quantity_required           := p_estimate_line_rec.estimate_quantity;
355  x_charges_rec.unit_of_measure_code        := p_estimate_line_rec.unit_of_measure_code;
356  x_charges_rec.customer_product_id         := p_estimate_line_rec.customer_product_id;
357  x_charges_rec.reference_number            := p_estimate_line_rec.reference_number;
358  x_charges_rec.interface_to_oe_flag        := p_estimate_line_rec.interface_to_om_flag;
359  x_charges_rec.no_charge_flag              := p_estimate_line_rec.no_charge_flag;
360  x_charges_rec.add_to_order_flag           := p_estimate_line_rec.add_to_order_flag;
361  x_charges_rec.rollup_flag                 := FND_API.G_MISS_CHAR;
362  x_charges_rec.LINE_CATEGORY_CODE          := p_estimate_line_rec.LINE_CATEGORY_CODE;
363  x_charges_rec.RETURN_REASON_CODE          := p_estimate_line_rec.RETURN_REASON;
364  x_charges_rec.contract_id                 := p_estimate_line_rec.contract_id;
365  --R12 contracts changes
366  x_charges_rec.contract_line_id            := p_estimate_line_rec.contract_line_id;
367  x_charges_rec.coverage_id                 := p_estimate_line_rec.coverage_id;
368  x_charges_rec.coverage_txn_group_id       := p_estimate_line_rec.coverage_txn_group_id;
369  x_charges_rec.coverage_bill_rate_id       := p_estimate_line_rec.coverage_bill_rate_id;
370  x_charges_rec.invoice_to_org_id           := p_estimate_line_rec.invoice_to_org_id;
371  x_charges_rec.ship_to_org_id              := p_estimate_line_rec.ship_to_org_id;
372  x_charges_rec.item_revision			      := p_estimate_line_rec.item_revision;
373  x_charges_rec.after_warranty_cost         := p_estimate_line_rec.after_warranty_cost;
374  x_charges_rec.serial_number               := p_estimate_line_rec.serial_number;
375  x_charges_rec.original_source_number      := p_estimate_line_rec.original_source_number;
376  x_charges_rec.purchase_order_num          := p_estimate_line_rec.purchase_order_num;
377  x_charges_rec.source_number               := p_estimate_line_rec.source_number;
378  x_charges_rec.inventory_item_id_out       := FND_API.G_MISS_NUM;
379  x_charges_rec.serial_number_out           := p_estimate_line_rec.serial_number;
380  x_charges_rec.order_header_id             := p_estimate_line_rec.order_header_id;
381  x_charges_rec.order_line_id               := p_estimate_line_rec.order_line_id;
382  x_charges_rec.original_system_reference   := p_estimate_line_rec.original_system_reference;
383  x_charges_rec.selling_price               := p_estimate_line_rec.selling_price;
384  x_charges_rec.EXCEPTION_COVERAGE_USED     := FND_API.G_MISS_CHAR;
385  --x_charges_rec.organization_id             := FND_API.G_MISS_NUM;
386  --x_charges_rec.customer_id                 := FND_API.G_MISS_NUM;
387  -- travi new
388  -- EST_TAX_AMOUNT was giving error
389  -- x_charges_rec.EST_TAX_AMOUNT              := FND_API.G_MISS_NUM;
390  x_charges_rec.charge_line_type            := p_estimate_line_rec.charge_line_type;
391  x_charges_rec.apply_contract_discount     := p_estimate_line_rec.apply_contract_discount;
392  x_charges_rec.coverage_id                 := p_estimate_line_rec.coverage_id;
393  x_charges_rec.coverage_txn_group_id       := p_estimate_line_rec.coverage_txn_group_id;
394  x_charges_rec.transaction_type_id         := p_estimate_line_rec.transaction_type_id;
395  -- swai bug fix 3099740
396  -- add contract discount amount to pass to charges
397  x_charges_rec.contract_discount_amount    := p_estimate_line_rec.contract_discount_amount;
398  -- end swai bug fix 3099740
399 
400  x_charges_rec.pricing_context             := p_estimate_line_rec.pricing_context;
401  x_charges_rec.pricing_attribute1          := p_estimate_line_rec.pricing_attribute1;
402  x_charges_rec.pricing_attribute2          := p_estimate_line_rec.pricing_attribute2;
403  x_charges_rec.pricing_attribute3          := p_estimate_line_rec.pricing_attribute3;
404  x_charges_rec.pricing_attribute4          := p_estimate_line_rec.pricing_attribute4;
405  x_charges_rec.pricing_attribute5          := p_estimate_line_rec.pricing_attribute5;
406  x_charges_rec.pricing_attribute6          := p_estimate_line_rec.pricing_attribute6;
407  x_charges_rec.pricing_attribute7          := p_estimate_line_rec.pricing_attribute7;
408  x_charges_rec.pricing_attribute8          := p_estimate_line_rec.pricing_attribute8;
409  x_charges_rec.pricing_attribute9          := p_estimate_line_rec.pricing_attribute9;
410  x_charges_rec.pricing_attribute10         := p_estimate_line_rec.pricing_attribute10;
411  x_charges_rec.pricing_attribute11         := p_estimate_line_rec.pricing_attribute11;
412  x_charges_rec.pricing_attribute12         := p_estimate_line_rec.pricing_attribute12;
413  x_charges_rec.pricing_attribute13         := p_estimate_line_rec.pricing_attribute13;
414  x_charges_rec.pricing_attribute14         := p_estimate_line_rec.pricing_attribute14;
415  x_charges_rec.pricing_attribute15         := p_estimate_line_rec.pricing_attribute15;
416  x_charges_rec.pricing_attribute16         := p_estimate_line_rec.pricing_attribute16;
417  x_charges_rec.pricing_attribute17         := p_estimate_line_rec.pricing_attribute17;
418  x_charges_rec.pricing_attribute18         := p_estimate_line_rec.pricing_attribute18;
419  x_charges_rec.pricing_attribute19         := p_estimate_line_rec.pricing_attribute19;
420  x_charges_rec.pricing_attribute20         := p_estimate_line_rec.pricing_attribute20;
421  x_charges_rec.pricing_attribute21         := p_estimate_line_rec.pricing_attribute21;
422  x_charges_rec.pricing_attribute22          := p_estimate_line_rec.pricing_attribute22;
423  x_charges_rec.pricing_attribute23          := p_estimate_line_rec.pricing_attribute23;
424  x_charges_rec.pricing_attribute24          := p_estimate_line_rec.pricing_attribute24;
425  x_charges_rec.pricing_attribute25          := p_estimate_line_rec.pricing_attribute25;
426  x_charges_rec.pricing_attribute26          := p_estimate_line_rec.pricing_attribute26;
427  x_charges_rec.pricing_attribute27          := p_estimate_line_rec.pricing_attribute27;
428  x_charges_rec.pricing_attribute28          := p_estimate_line_rec.pricing_attribute28;
429  x_charges_rec.pricing_attribute29          := p_estimate_line_rec.pricing_attribute29;
430  x_charges_rec.pricing_attribute30          := p_estimate_line_rec.pricing_attribute30;
431  x_charges_rec.pricing_attribute31          := p_estimate_line_rec.pricing_attribute31;
432  x_charges_rec.pricing_attribute32          := p_estimate_line_rec.pricing_attribute32;
433  x_charges_rec.pricing_attribute33          := p_estimate_line_rec.pricing_attribute33;
434  x_charges_rec.pricing_attribute34          := p_estimate_line_rec.pricing_attribute34;
435  x_charges_rec.pricing_attribute35          := p_estimate_line_rec.pricing_attribute35;
436  x_charges_rec.pricing_attribute36          := p_estimate_line_rec.pricing_attribute36;
437  x_charges_rec.pricing_attribute37          := p_estimate_line_rec.pricing_attribute37;
438  x_charges_rec.pricing_attribute38          := p_estimate_line_rec.pricing_attribute38;
439  x_charges_rec.pricing_attribute39          := p_estimate_line_rec.pricing_attribute39;
440  x_charges_rec.pricing_attribute40          := p_estimate_line_rec.pricing_attribute40;
441  x_charges_rec.pricing_attribute41          := p_estimate_line_rec.pricing_attribute41;
442  x_charges_rec.pricing_attribute42          := p_estimate_line_rec.pricing_attribute42;
443  x_charges_rec.pricing_attribute43          := p_estimate_line_rec.pricing_attribute43;
444  x_charges_rec.pricing_attribute44          := p_estimate_line_rec.pricing_attribute44;
445  x_charges_rec.pricing_attribute45          := p_estimate_line_rec.pricing_attribute45;
446  x_charges_rec.pricing_attribute46          := p_estimate_line_rec.pricing_attribute46;
447  x_charges_rec.pricing_attribute47          := p_estimate_line_rec.pricing_attribute47;
448  x_charges_rec.pricing_attribute48          := p_estimate_line_rec.pricing_attribute48;
449  x_charges_rec.pricing_attribute49          := p_estimate_line_rec.pricing_attribute49;
450  x_charges_rec.pricing_attribute50          := p_estimate_line_rec.pricing_attribute50;
451  x_charges_rec.pricing_attribute51          := p_estimate_line_rec.pricing_attribute51;
452  x_charges_rec.pricing_attribute52          := p_estimate_line_rec.pricing_attribute52;
453  x_charges_rec.pricing_attribute53          := p_estimate_line_rec.pricing_attribute53;
454  x_charges_rec.pricing_attribute54          := p_estimate_line_rec.pricing_attribute54;
455  x_charges_rec.pricing_attribute55          := p_estimate_line_rec.pricing_attribute55;
456  x_charges_rec.pricing_attribute56          := p_estimate_line_rec.pricing_attribute56;
457  x_charges_rec.pricing_attribute57          := p_estimate_line_rec.pricing_attribute57;
458  x_charges_rec.pricing_attribute58          := p_estimate_line_rec.pricing_attribute58;
459  x_charges_rec.pricing_attribute59          := p_estimate_line_rec.pricing_attribute59;
460  x_charges_rec.pricing_attribute60          := p_estimate_line_rec.pricing_attribute60;
461  x_charges_rec.pricing_attribute61          := p_estimate_line_rec.pricing_attribute61;
462  x_charges_rec.pricing_attribute62          := p_estimate_line_rec.pricing_attribute62;
463  x_charges_rec.pricing_attribute63          := p_estimate_line_rec.pricing_attribute63;
464  x_charges_rec.pricing_attribute64          := p_estimate_line_rec.pricing_attribute64;
465  x_charges_rec.pricing_attribute65          := p_estimate_line_rec.pricing_attribute65;
466  x_charges_rec.pricing_attribute66          := p_estimate_line_rec.pricing_attribute66;
467  x_charges_rec.pricing_attribute67          := p_estimate_line_rec.pricing_attribute67;
468  x_charges_rec.pricing_attribute68          := p_estimate_line_rec.pricing_attribute68;
469  x_charges_rec.pricing_attribute69          := p_estimate_line_rec.pricing_attribute69;
470  x_charges_rec.pricing_attribute70          := p_estimate_line_rec.pricing_attribute70;
471  x_charges_rec.pricing_attribute71          := p_estimate_line_rec.pricing_attribute71;
472  x_charges_rec.pricing_attribute72          := p_estimate_line_rec.pricing_attribute72;
473  x_charges_rec.pricing_attribute73          := p_estimate_line_rec.pricing_attribute73;
474  x_charges_rec.pricing_attribute74          := p_estimate_line_rec.pricing_attribute74;
475  x_charges_rec.pricing_attribute75          := p_estimate_line_rec.pricing_attribute75;
476  x_charges_rec.pricing_attribute76          := p_estimate_line_rec.pricing_attribute76;
477  x_charges_rec.pricing_attribute77          := p_estimate_line_rec.pricing_attribute77;
478  x_charges_rec.pricing_attribute78          := p_estimate_line_rec.pricing_attribute78;
479  x_charges_rec.pricing_attribute79          := p_estimate_line_rec.pricing_attribute79;
480  x_charges_rec.pricing_attribute80          := p_estimate_line_rec.pricing_attribute80;
481  x_charges_rec.pricing_attribute81          := p_estimate_line_rec.pricing_attribute81;
482  x_charges_rec.pricing_attribute82          := p_estimate_line_rec.pricing_attribute82;
483  x_charges_rec.pricing_attribute83          := p_estimate_line_rec.pricing_attribute83;
484  x_charges_rec.pricing_attribute84          := p_estimate_line_rec.pricing_attribute84;
485  x_charges_rec.pricing_attribute85          := p_estimate_line_rec.pricing_attribute85;
486  x_charges_rec.pricing_attribute86          := p_estimate_line_rec.pricing_attribute86;
487  x_charges_rec.pricing_attribute87          := p_estimate_line_rec.pricing_attribute87;
488  x_charges_rec.pricing_attribute88          := p_estimate_line_rec.pricing_attribute88;
489  x_charges_rec.pricing_attribute89          := p_estimate_line_rec.pricing_attribute89;
490  x_charges_rec.pricing_attribute90          := p_estimate_line_rec.pricing_attribute90;
491  x_charges_rec.pricing_attribute91          := p_estimate_line_rec.pricing_attribute91;
492  x_charges_rec.pricing_attribute92          := p_estimate_line_rec.pricing_attribute92;
493  x_charges_rec.pricing_attribute93          := p_estimate_line_rec.pricing_attribute93;
494  x_charges_rec.pricing_attribute94          := p_estimate_line_rec.pricing_attribute94;
495  x_charges_rec.pricing_attribute95          := p_estimate_line_rec.pricing_attribute95;
496  x_charges_rec.pricing_attribute96          := p_estimate_line_rec.pricing_attribute96;
497  x_charges_rec.pricing_attribute97          := p_estimate_line_rec.pricing_attribute97;
498  x_charges_rec.pricing_attribute98          := p_estimate_line_rec.pricing_attribute98;
499  x_charges_rec.pricing_attribute99          := p_estimate_line_rec.pricing_attribute99;
500  x_charges_rec.pricing_attribute100         := p_estimate_line_rec.pricing_attribute100;
501 
502 EXCEPTION
503     WHEN FND_API.G_EXC_ERROR THEN
504           x_return_status := FND_API.G_RET_STS_ERROR ;
505     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
506           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
507     WHEN OTHERS THEN
508           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
509 END Convert_Est_to_Chg_rec;
510 
511 PROCEDURE get_incident_id
512 (
513   p_repair_line_id     IN	NUMBER,
514   x_incident_id        OUT NOCOPY	NUMBER,
515   x_return_status      OUT NOCOPY	VARCHAR2
516 ) IS
517 
518 BEGIN
519 
520  x_return_status := FND_API.G_RET_STS_SUCCESS ;
521 
522 select
523   incident_id
524 into x_incident_id
525 from csd_repairs
526 where repair_line_id = p_repair_line_id
527  and  ((date_closed is null) OR (date_closed > sysdate));
528 EXCEPTION
529  WHEN NO_DATA_FOUND THEN
530     x_return_status :=  FND_API.G_RET_STS_ERROR ;
531     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_REP_LINE_ID');
532     FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
533     FND_MSG_PUB.Add;
534  WHEN OTHERS THEN
535     x_return_status :=  FND_API.G_RET_STS_ERROR ;
536     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_REP_LINE_ID');
537     FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
538     FND_MSG_PUB.Add;
539 END get_incident_id;
540 
541 
542 -- ***************************************************************************************
543 -- Fixed for bug#5190905
544 --
545 -- Procedure name: csd_get_txn_billing_type
546 -- description :   Ideally, the RT setup should capture SACs 'RMA'/'Ship' only (not SAC-BT) and select
547 --                 billing type based on the item attribute at the time of default prod txn creation.
548 --                 This API return the correct txn_billing_type_id based on Item billing type and service
549 --                 activity (Transaction_type_id).
550 --                 If transaction_type_id is not passed to this API then it derive the transaction_type_id
551 --                 using parameter p_txn_billing_type_id and then it derive the correct txn_billing_type_id
552 --                 for transaction.
553 -- Called from   : WVI trigger of rcv_ship.TRANSACTION_TYPE and CSD_PROCESS_UTIL.build_prodtxn_tbl_int
554 -- Input Parm    : p_api_version         NUMBER      Api Version number
555 --                 p_init_msg_list       VARCHAR2    Initializes message stack if fnd_api.g_true,
556 --                                                   default value is fnd_api.g_false
557 --		   p_incident_id         NUMBER      incident id of service request
558 --                 p_inventory_item_id   NUMBER
559 --                 p_transaction_type_id NUMBER
560 --                 p_txn_billing_type_id NUMBER      txn_billing_type_id (Service activity billing type SAC-BT)
561 --                                                   selected by user in RO type setup form. This can be pre/post
562 --                                                   repair RMA service activity or pre/post SHIP repair Service activity
563 -- Output Parm   :
564 --                 x_txn_billing_type_id NUMBER      New Txn_billing_type_Id based on transaction
565 --                                                   type and billing type of Item
566 --                 x_return_status       VARCHAR2    Return status after the call. The status can be
567 --                                                   fnd_api.g_ret_sts_success (success)
568 --                                                   fnd_api.g_ret_sts_error (error)
569 --                                                   fnd_api.g_ret_sts_unexp_error (unexpected)
570 --                 x_msg_count           NUMBER      Number of messages in the message stack
571 --                 x_msg_data            VARCHAR2    Message text if x_msg_count >= 1
572 -- **************************************************************************************
573 
574 Procedure csd_get_txn_billing_type (
575               p_api_version                 IN   NUMBER,
576               p_init_msg_list               IN   VARCHAR2,
577               p_incident_id                 IN   NUMBER,
578               p_inventory_item_id           IN   NUMBER,
579               P_transaction_type_id         IN   NUMBER,
580               p_txn_billing_type_id         IN   NUMBER,
581               x_txn_billing_type_id     OUT NOCOPY NUMBER,
582               x_return_status           OUT NOCOPY VARCHAR2 ,
583               x_msg_count               OUT NOCOPY NUMBER,
584               x_msg_data                OUT NOCOPY VARCHAR2
585               )
586 Is
587   l_api_name                    CONSTANT VARCHAR2(30) := 'CSD_GET_TXN_BILLING_TYPE';
588   l_api_version                 CONSTANT NUMBER := 1.0;
589   l_transaction_type_id         number;
590   l_txn_billing_type_id         number;
591   l_org_id                      NUMBER;
592   l_billing_type                VARCHAR2(30);
593   l_operating_unit              NUMBER;
594   l_profile                     varchar2(1);
595 
596 cursor valid_txn_billing_type is
597      select tbt.txn_billing_type_id
598      from cs_transaction_types_b tt,
599           cs_txn_billing_types tbt,
600           cs_billing_type_categories cbtc,
601           cs_txn_billing_oetxn_all tb,
602           oe_transaction_types_vl oeh,
603           oe_transaction_types_vl oel
604      where
605          tt.transaction_type_id = l_transaction_type_id
606      and nvl(tt.depot_repair_flag,'N')='Y'
607      and tt.transaction_type_id=tbt.transaction_type_id
608      and tbt.billing_type = l_billing_type
609      and tbt.txn_billing_type_id=tb.txn_billing_type_id
610 	and  tb.org_id = l_operating_unit  /*Operating unit */
611      and tb.order_type_id=oeh.transaction_type_id
612      and tb.line_type_id=oel.transaction_type_id
613      and sysdate between nvl(cbtc.start_date_active, sysdate) and nvl(cbtc.end_date_active,sysdate)
614      and (sysdate) between nvl(tt.start_date_active,(sysdate)) and nvl(tt.end_date_active,(sysdate))
615      and cbtc.billing_type = tbt.billing_type
616      and nvl(cbtc.billing_category, '-999') ='M';
617 
618 begin
619     csd_gen_utility_pvt.add('At the Begin in ');
620 
621     csd_gen_utility_pvt.dump_api_info ( p_pkg_name  => G_PKG_NAME,
622                                         p_api_name  => l_api_name );
623 
624     csd_gen_utility_pvt.add('P_incident_id         ='||P_incident_id);
625     csd_gen_utility_pvt.add('p_inventory_item_id   ='||p_inventory_item_id );
626     csd_gen_utility_pvt.add('P_transaction_type_id ='||P_transaction_type_id);
627     csd_gen_utility_pvt.add('p_txn_billing_type_id ='||p_txn_billing_type_id);
628 
629     /*Initialize message list if p_init_msg_list is set to TRUE.*/
630     IF FND_API.to_Boolean(p_init_msg_list) THEN
631        FND_MSG_PUB.initialize;
632     END IF;
633 
634     /*Initialize API return status to success*/
635     x_return_status := FND_API.G_RET_STS_SUCCESS;
636 
637     l_org_id := cs_std.get_item_valdn_orgzn_id;
638 
639     /*Derive the operating unit */
640     IF csd_process_util.is_multiorg_enabled THEN
641        CS_MultiOrg_Pub.Get_OrgId(
642 	      P_API_VERSION    => 1.0,
643 		 P_INIT_MSG_LIST  => 'F',
644 		 P_COMMIT         => 'F',
645 		 P_VALIDATION_LEVEL => 100,
646 		 P_INCIDENT_ID    => P_incident_id,
647 		 X_RETURN_STATUS  => x_return_status,
648 		 X_MSG_COUNT      => x_msg_count,
649 		 X_MSG_DATA       => x_msg_data,
650 		 X_ORG_ID         => l_operating_unit,
651 		 X_PROFILE        => l_profile);
652 	  IF (x_return_status <> CSD_PROCESS_UTIL.G_RET_STS_SUCCESS) THEN
653 	     csd_gen_utility_pvt.ADD('Error in Deriving the Operating Unit ');
654 	  END IF;
655     ELSE
656       Fnd_Profile.Get('ORG_ID',l_operating_unit);
657     END IF;
658 
659     csd_gen_utility_pvt.add('l_operating_unit  ='||l_operating_unit);
660 
661     begin
662      select MATERIAL_BILLABLE_FLAG
663      into   l_billing_type
664      from  mtl_system_items_B
665      where inventory_item_id = p_inventory_item_id
666      and   organization_id   = l_org_id
667      and   sysdate between nvl(start_date_active,sysdate)
668      and nvl(end_date_active, sysdate);
669     EXCEPTION
670     When NO_DATA_FOUND then
671         FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ITEM_ID');
672         FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID',p_inventory_item_id);
673         FND_MSG_PUB.Add;
674         RAISE FND_API.G_EXC_ERROR;
675     End;
676 
677     csd_gen_utility_pvt.add('Item billing type is     ='||l_billing_type);
678 
679 
680    l_transaction_type_id:= P_transaction_type_id;
681 
682    If l_transaction_type_id IS NULL then /*Derive Txn type id only if it is null */
683 
684      /*Derive Service activity from SAC-BT combination*/
685      begin
686      select tbt.transaction_type_id
687      into   l_transaction_type_id
688      from   cs_txn_billing_types tbt
689      where txn_billing_type_id = p_txn_billing_type_id;
690 /* Fixed for bug#5662028
691      and  (sysdate) between nvl(tbt.start_date_active,(sysdate))
692                             and nvl(tbt.end_date_active,(sysdate));
693 */
694      exception
695       When No_data_found then
696         csd_gen_utility_pvt.add('No record found for p_txn_billing_type_id='||p_txn_billing_type_id);
697         FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_TXN_BILL_TYPE_ID');
698         FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID',p_txn_billing_type_id);
699         FND_MSG_PUB.Add;
700         RAISE FND_API.G_EXC_ERROR;
701       When Others then
702         FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_TXN_BILL_TYPE_ID');
703         FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID',p_txn_billing_type_id);
704         FND_MSG_PUB.Add;
705         RAISE FND_API.G_EXC_ERROR;
706      end;
707     END IF; /*end if l_transaction_type_id */
708 
709   open valid_txn_billing_type;
710   Fetch valid_txn_billing_type
711   into  l_txn_billing_type_id;
712 
713   IF valid_txn_billing_type%isopen then
714     CLOSE valid_txn_billing_type;
715   END IF;
716 
717   If l_txn_billing_type_id is not null then
718      x_txn_billing_type_id:= l_txn_billing_type_id;
719   else
720      FND_MESSAGE.SET_NAME('CSD','CSD_INV_SERVICE_BILLING_TYPE');
721      FND_MSG_PUB.Add;
722      RAISE FND_API.G_EXC_ERROR;
723   end if;
724 
725 Exception
726    WHEN FND_API.G_EXC_ERROR THEN
727       x_return_status := FND_API.G_RET_STS_ERROR ;
728       FND_MSG_PUB.Count_And_Get (p_count  =>  x_msg_count,
729                                  p_data   =>  x_msg_data);
730    when others then
731       x_return_status := FND_API.G_RET_STS_ERROR ;
732       FND_MSG_PUB.Count_And_Get (p_count  =>  x_msg_count,
733                                  p_data   =>  x_msg_data);
734 end csd_get_txn_billing_type;
735 
736 
737 
738 /**********************
739 This proc is changed to be an internal proc with more params.
740 The private api build_prod_txn_tbl is changed to call this.
741 *****************************************/
742 PROCEDURE build_prodtxn_tbl_int
743 ( p_repair_line_id     IN	NUMBER,
744   p_quantity           IN   NUMBER,
745   p_Serial_number      IN   VARCHAR2,
746   p_instance_id        IN   NUMBER,
747   p_create_thirdpty_line IN VARCHAR2 := fnd_api.g_false,
748   p_return_reason_code IN VARCHAR2   := NULL,
749   p_invoice_to_org_id  IN NUMBER     := NULL,
750   p_ship_to_org_id     IN NUMBER     := NULL,
751   x_prod_txn_tbl       OUT NOCOPY	csd_process_pvt.product_txn_tbl,
752   x_return_status      OUT NOCOPY	VARCHAR2
753  ) IS
754 -- bug fix for 4108369, Begin
755   l_sr_add_to_order_flag  VARCHAR2(10);
756   l_add_rma_to_id       NUMBER;
757   l_add_ship_to_id      NUMBER;
758 -- bug fix for 4108369, End
759  l_repair_type_ref          VARCHAR2(3) := '';
760  l_auto_process_rma         VARCHAR2(1) := '';
761  l_inv_item_id              NUMBER  := NULL;
762  l_inv_revision             VARCHAR2(3)  := '';
763  l_contract_id              NUMBER  := NULL;
764  -- R12 contract changes
765  -- fix made because of charges API problem. earlier contract_line was
766  -- accepted in contract_id column, now charges api expects contract_id
767  -- in contract_id, contract_line_id in contract_line_id columns
768  l_contract_line_id              NUMBER  := NULL;
769 
770  l_unit_of_measure          VARCHAR2(30) := '';
771  l_price_list_id            NUMBER  := NULL;
772  l_price_list               VARCHAR2(30) := '';
773  l_return_reason            VARCHAR2(30) := '';
774  l_org_id                   NUMBER  := NULL;
775  l_incident_id              NUMBER  := NULL;
776  l_inv_org_id	            NUMBER := NULL;
777  l_revision                 VARCHAR2(30) := '';
778  l_bus_process_id           NUMBER  := NULL;
779  l_price_list_header_id     NUMBER  := NULL;
780  l_cps_txn_billing_type_id  NUMBER := NULL;
781  l_cpr_txn_billing_type_id  NUMBER := NULL;
782  l_ls_txn_billing_type_id   NUMBER := NULL;
783  l_lr_txn_billing_type_id   NUMBER := NULL;
784  l_ib_flag                  VARCHAR2(1);
785  l_serial_num_control_code  NUMBER;
786  C_Replacement              Varchar2(30):= 'REPLACEMENT' ;
787  l_po_number                VARCHAR2(50);  -- swai bug fix 4535829
788  l_interface_to_om_flag     VARCHAR2(1) :='';
789  l_book_sales_order_flag    VARCHAR2(1) :='';
790 
791  l_third_rma_txn_b_type_id   NUMBER := NULL;
792  l_third_ship_txn_b_type_id   NUMBER := NULL;
793  l_third_party_flag          VARCHAR2(1) :='';
794  l_index         NUMBER := 1;
795 
796 
797  l_project_id               NUMBER := null;
798  l_task_id                  NUMBER := null;
799  l_unit_number              VARCHAR2(30) :='';
800 
801 --Get Pricing variables
802  /* bug#3875036 */
803  l_selling_price		NUMBER := FND_API.G_MISS_NUM;
804  l_account_id			NUMBER := null;
805  l_currency_code        varchar(15);
806  l_return_status        VARCHAR2(1);
807  l_msg_count            NUMBER;
808  l_msg_data             VARCHAR2(2000);
809  l_pricing_rec			csd_process_util.pricing_attr_rec := csd_process_util.ui_pricing_attr_rec;
810  l_enable_advanced_pricing	VARCHAR2(1);
811 
812 
813  /*Bug#5190905 added below variables*/
814  l_txn_billing_type_id      number:=NULL;
815  x_msg_count                number;
816  x_msg_data                 VARCHAR2(2000);
817  /*Bug#5190905 end*/
818 
819  l_src_return_reqd           varchar2(1);  /*Fixed for FP bug#5408047*/
820  l_non_src_return_reqd       varchar2(1);  /*Fixed for FP bug#5408047*/
821  l_return_days               number;       /*Fixed for FP bug#5408047*/
822 
823  /*Fixed for FP bug#5408047*/
824    cursor c2(p_txn_billing_type_id NUMBER) is
825    select src_return_reqd
826          ,non_src_return_reqd
827    from csi_ib_txn_types a,
828         cs_txn_billing_types b
829    where a.cs_transaction_type_id = b.transaction_type_id
830    and  b.txn_billing_type_id = p_txn_billing_type_id;
831 
832   CURSOR repair_line_dtls(p_rep_line_id IN NUMBER) IS
833   SELECT
834     crt.repair_type_ref,
835     cr.auto_process_rma,
836     crt.interface_to_om_flag,
837     crt.book_sales_order_flag,
838     cr.inventory_item_id,
839     cr.item_revision,
840     cr.contract_line_id,
841     cr.unit_of_measure,
842     crt.cps_txn_billing_type_id ,
843     crt.cpr_txn_billing_type_id ,
844     crt.ls_txn_billing_type_id  ,
845     crt.lr_txn_billing_type_id  ,
846     cr.price_list_header_id    ,
847     crt.business_process_id,
848     cr.incident_id,
849     cr.default_po_num,   -- swai bug fix 4535829
850     cr.inventory_org_id, -- inv_org_change Vijay, 3/20/06
851     cr.project_id,
852     cr.task_id,
853     cr.unit_number,
854     crt.third_rma_txn_billing_type_id,
855     crt.third_ship_txn_billing_type_id,
856     crt.third_party_flag
857   FROM csd_repairs cr,
858        csd_repair_types_vl crt
859   where cr.repair_type_id = crt.repair_type_id
860   and   cr.repair_line_id = p_rep_line_id;
861 
862   CURSOR get_revision(p_inv_item_id IN NUMBER,
863                       p_org_id      IN NUMBER) IS
864   SELECT
865     revision
866   FROM mtl_item_revisions
867   where inventory_item_id  = p_inv_item_id
868   and  organization_id    = p_org_id;
869 
870   -- Fix for bug#3549430
871   CURSOR get_item_attributes(p_inv_item_id IN NUMBER,
872                              p_org_id      IN NUMBER) IS
873   Select
874     serial_number_control_code,
875     comms_nl_trackable_flag
876   from mtl_system_items_kfv
877   where inventory_item_id = p_inv_item_id
878   and organization_id     = p_org_id;
879 
880   --picking_rule_changes for R12
881   l_picking_rule_id  NUMBER;
882 
883 
884   --R12 contracts changes
885   cursor cur_contract_det(p_contract_line_id NUMBER) is
886   select chr_id from okc_k_lines_b
887   where id = p_contract_line_id;
888 
889   -- swai: bug 6936769
890   CURSOR c_primary_account_address(p_party_id NUMBER, p_account_id NUMBER, p_org_id NUMBER, p_site_use_type VARCHAR2)
891   IS
892     select distinct
893            hp.party_site_id
894       from hz_party_sites_v hp,
895            hz_parties hz,
896            hz_cust_acct_sites_all hca,
897            hz_cust_site_uses_all hcsu
898      where hcsu.site_use_code = p_site_use_type
899       and  hp.status = 'A'
900       and  hcsu.status = 'A'
901       and  hp.party_id = hz.party_id
902       and  hp.party_id = p_party_id
903       and  hca.party_site_id = hp.party_site_id
904       and  hca.cust_account_id = p_account_id
905       and  hcsu.cust_acct_site_id = hca.cust_acct_site_id
906       and  hca.org_id = p_org_id
907       and  hcsu.primary_flag = 'Y'
908       and rownum = 1;
909 
910   --Bug fix 5494219 Begin
911   l_sub_inv MTL_SECONDARY_INVENTORIES.SECONDARY_INVENTORY_NAME%type ;
912   --Bug fix 5494219 End
913 
914 
915   --default rule
916   l_rule_input_rec CSD_RULES_ENGINE_PVT.CSD_RULE_INPUT_REC_TYPE;
917   l_attr_type VARCHAR2(25);
918   l_attr_code VARCHAR2(25);
919   l_default_val_num  NUMBER;
920   l_default_val_char VARCHAR2(240);
921   l_default_rule_id  NUMBER;    -- swai: 12.1.1 ER 7233924
922 
923 --bug#11769559
924   l_default_logistics_warehouse VARCHAR2(1) := '';
925 --bug#11769559
926 
927 
928   l_lot_number  VARCHAR2(80);  -- yvchen: bug#13582572
929 
930   -- yvchen: bug#13582572
931   CURSOR get_lot_number(p_repair_line_id IN NUMBER) IS
932      SELECT lot_number
933      FROM csd_repairs_v
934      WHERE repair_line_id  = p_repair_line_id;
935 
936 
937 BEGIN
938 
939   x_return_status := FND_API.G_RET_STS_SUCCESS;
940 
941   -- Initialize the table
942   x_prod_txn_tbl.delete;
943 
944   IF (g_debug > 0 ) THEN
945     csd_gen_utility_pvt.add('At the Begin in build_prod_txn_tbl');
946   END IF;
947 
948   IF (g_debug > 0 ) THEN
949     csd_gen_utility_pvt.add('p_repair_line_id ='||p_repair_line_id);
950   END IF;
951 
952 
953   IF NVL(p_repair_line_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN
954 
955     OPEN  repair_line_dtls(p_repair_line_id);
956 
957     FETCH repair_line_dtls INTO
958        l_repair_type_ref,
959        l_auto_process_rma,
960        l_interface_to_om_flag,
961        l_book_sales_order_flag,
962        l_inv_item_id,
963        l_inv_revision,
964        --l_contract_id,
965        -- R12 contract changes
966        l_contract_line_id,
967        l_unit_of_measure,
968        l_cps_txn_billing_type_id,
969        l_cpr_txn_billing_type_id,
970        l_ls_txn_billing_type_id,
971        l_lr_txn_billing_type_id,
972        l_price_list_header_id,
973        l_bus_process_id,
974        l_incident_id,
975        l_po_number,  -- swai bug fix 4535829
976 	    l_inv_org_id, -- inv_org_change vijay, 3/20/06
977        l_project_id,
978        l_task_id,
979        l_unit_number,
980        l_third_rma_txn_b_type_id,
981        l_third_ship_txn_b_type_id,
982        l_third_party_flag;
983 
984 
985     IF repair_line_dtls%notfound then
986       FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_REP_LINE_ID');
987       FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
988       FND_MSG_PUB.ADD;
989       IF (g_debug > 0 ) THEN
990         csd_gen_utility_pvt.ADD('repair line Id does not exist');
991       END IF;
992 
993       RAISE FND_API.G_EXC_ERROR;
994     END IF;
995 
996     IF repair_line_dtls%isopen then
997       CLOSE repair_line_dtls;
998     END IF;
999 
1000 
1001   END IF;
1002 
1003   -- R12 contract changes
1004   IF(l_contract_line_id is not null) then
1005 
1006   	open cur_contract_det(l_contract_line_id);
1007 	fetch cur_contract_det
1008 	into
1009 	l_contract_id;
1010 
1011      IF cur_contract_det%notfound then
1012       FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_REP_LINE_ID');
1013       FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
1014       FND_MSG_PUB.ADD;
1015       RAISE FND_API.G_EXC_ERROR;
1016     END IF;
1017 
1018     IF cur_contract_det%isopen then
1019       CLOSE cur_contract_det;
1020     END IF;
1021   END IF;
1022 
1023 
1024   IF (g_debug > 0 ) THEN
1025     csd_gen_utility_pvt.add('l_repair_type_ref ='||l_repair_type_ref);
1026   END IF;
1027 
1028   IF (g_debug > 0 ) THEN
1029     csd_gen_utility_pvt.add('l_auto_process_rma='||l_auto_process_rma);
1030   END IF;
1031 
1032 
1033   -- Get the price_list
1034   l_price_list_id := NVL(l_price_list_header_id,FND_PROFILE.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
1035 
1036   -- Get the return reason
1037   -- modified by subhat to get the value from procedure param if passed.
1038   IF p_return_reason_code IS NULL
1039   THEN
1040     l_return_reason := FND_PROFILE.value('CSD_DEF_RMA_RETURN_REASON');
1041   ELSE
1042     l_return_reason := p_return_reason_code;
1043   END IF;
1044 
1045   IF (g_debug > 0 ) THEN
1046     csd_gen_utility_pvt.add('l_price list_id        ='||l_price_list_id);
1047   END IF;
1048 
1049   IF (g_debug > 0 ) THEN
1050     csd_gen_utility_pvt.add('l_return_reason        ='||l_return_reason);
1051   END IF;
1052 
1053   IF (g_debug > 0 ) THEN
1054     csd_gen_utility_pvt.add('l_cps_txn_billing_type_id='||l_cps_txn_billing_type_id  );
1055   END IF;
1056 
1057   IF (g_debug > 0 ) THEN
1058     csd_gen_utility_pvt.add('l_cpr_txn_billing_type_id='||l_cpr_txn_billing_type_id );
1059   END IF;
1060 
1061   IF (g_debug > 0 ) THEN
1062     csd_gen_utility_pvt.add('l_ls_txn_billing_type_id ='||l_ls_txn_billing_type_id );
1063   END IF;
1064 
1065   IF (g_debug > 0 ) THEN
1066     csd_gen_utility_pvt.add('l_lr_txn_billing_type_id ='||l_lr_txn_billing_type_id );
1067   END IF;
1068 
1069 
1070   /*Bug#5190905
1071   added code to derive the correct service activity billing type based on
1072   service activity and item billing type.
1073   */
1074   If l_cpr_txn_billing_type_id is not null then
1075     l_txn_billing_type_id:=null;
1076     csd_get_txn_billing_type (
1077               p_api_version            => 1.0,
1078               p_init_msg_list          => 'F',
1079               p_incident_id            => l_incident_id,
1080               p_inventory_item_id      => l_inv_item_id,
1081               P_transaction_type_id    => NULL,
1082               p_txn_billing_type_id    => l_cpr_txn_billing_type_id,
1083               x_txn_billing_type_id    => l_txn_billing_type_id,
1084               x_return_status          => x_return_status,
1085               x_msg_count              => x_msg_count,
1086               x_msg_data               => x_msg_data
1087               );
1088           If (x_return_status = FND_API.G_RET_STS_SUCCESS ) then
1089             l_cpr_txn_billing_type_id :=l_txn_billing_type_id;
1090           else
1091             RAISE FND_API.G_EXC_ERROR;
1092          end if;
1093   end if;
1094 
1095   If l_cps_txn_billing_type_id is not null then
1096     l_txn_billing_type_id:=null;
1097     csd_get_txn_billing_type (
1098               p_api_version            => 1.0,
1099               p_init_msg_list          => 'F',
1100               p_incident_id            => l_incident_id,
1101               p_inventory_item_id      => l_inv_item_id,
1102               P_transaction_type_id    => NULL,
1103               p_txn_billing_type_id    => l_cps_txn_billing_type_id,
1104               x_txn_billing_type_id    => l_txn_billing_type_id,
1105               x_return_status          => x_return_status,
1106               x_msg_count              => x_msg_count,
1107               x_msg_data               => x_msg_data
1108               );
1109           If (x_return_status = FND_API.G_RET_STS_SUCCESS ) then
1110             l_cps_txn_billing_type_id :=l_txn_billing_type_id;
1111           else
1112             RAISE FND_API.G_EXC_ERROR;
1113          end if;
1114   end if;
1115 
1116   If l_ls_txn_billing_type_id is not null then
1117     l_txn_billing_type_id:=null;
1118     csd_get_txn_billing_type (
1119               p_api_version            => 1.0,
1120               p_init_msg_list          => 'F',
1121               p_incident_id            => l_incident_id,
1122               p_inventory_item_id      => l_inv_item_id,
1123               P_transaction_type_id    => NULL,
1124               p_txn_billing_type_id    => l_ls_txn_billing_type_id,
1125               x_txn_billing_type_id    => l_txn_billing_type_id,
1126               x_return_status          => x_return_status,
1127               x_msg_count              => x_msg_count,
1128               x_msg_data               => x_msg_data
1129               );
1130           If (x_return_status = FND_API.G_RET_STS_SUCCESS ) then
1131             l_ls_txn_billing_type_id :=l_txn_billing_type_id;
1132           else
1133             RAISE FND_API.G_EXC_ERROR;
1134          end if;
1135   end if;
1136 
1137   If l_lr_txn_billing_type_id is not null then
1138     l_txn_billing_type_id:=null;
1139     csd_get_txn_billing_type (
1140               p_api_version            => 1.0,
1141               p_init_msg_list          => 'F',
1142               p_incident_id            => l_incident_id,
1143               p_inventory_item_id      => l_inv_item_id,
1144               P_transaction_type_id    => NULL,
1145               p_txn_billing_type_id    => l_lr_txn_billing_type_id,
1146               x_txn_billing_type_id    => l_txn_billing_type_id,
1147               x_return_status          => x_return_status,
1148               x_msg_count              => x_msg_count,
1149               x_msg_data               => x_msg_data
1150               );
1151           If (x_return_status = FND_API.G_RET_STS_SUCCESS ) then
1152             l_lr_txn_billing_type_id :=l_txn_billing_type_id;
1153           else
1154             RAISE FND_API.G_EXC_ERROR;
1155          end if;
1156   end if;
1157 
1158 
1159     IF (NVL(l_third_party_flag, 'N') = 'Y' or (p_create_thirdpty_line = 'T')) THEN
1160 
1161           If l_third_rma_txn_b_type_id is not null then
1162             l_txn_billing_type_id:=null;
1163             csd_get_txn_billing_type (
1164                       p_api_version            => 1.0,
1165                       p_init_msg_list          => 'F',
1166                       p_incident_id            => l_incident_id,
1167                       p_inventory_item_id      => l_inv_item_id,
1168                       P_transaction_type_id    => NULL,
1169                       p_txn_billing_type_id    => l_third_rma_txn_b_type_id,
1170                       x_txn_billing_type_id    => l_txn_billing_type_id,
1171                       x_return_status          => x_return_status,
1172                       x_msg_count              => x_msg_count,
1173                       x_msg_data               => x_msg_data
1174                       );
1175                   If (x_return_status = FND_API.G_RET_STS_SUCCESS ) then
1176                     l_third_rma_txn_b_type_id :=l_txn_billing_type_id;
1177                   else
1178                     RAISE FND_API.G_EXC_ERROR;
1179                  end if;
1180           end if;
1181 
1182 
1183           If l_third_ship_txn_b_type_id is not null then
1184             l_txn_billing_type_id:=null;
1185             csd_get_txn_billing_type (
1186                       p_api_version            => 1.0,
1187                       p_init_msg_list          => 'F',
1188                       p_incident_id            => l_incident_id,
1189                       p_inventory_item_id      => l_inv_item_id,
1190                       P_transaction_type_id    => NULL,
1191                       p_txn_billing_type_id    => l_third_ship_txn_b_type_id,
1192                       x_txn_billing_type_id    => l_txn_billing_type_id,
1193                       x_return_status          => x_return_status,
1194                       x_msg_count              => x_msg_count,
1195                       x_msg_data               => x_msg_data
1196                       );
1197                   If (x_return_status = FND_API.G_RET_STS_SUCCESS ) then
1198                     l_third_ship_txn_b_type_id :=l_txn_billing_type_id;
1199                   else
1200                     RAISE FND_API.G_EXC_ERROR;
1201                  end if;
1202           end if;
1203     end if;
1204 
1205   IF (g_debug > 0 ) THEN
1206     csd_gen_utility_pvt.add('After calling csd_get_txn_billing_type ');
1207     csd_gen_utility_pvt.add('l_cps_txn_billing_type_id='||l_cps_txn_billing_type_id  );
1208     csd_gen_utility_pvt.add('l_cpr_txn_billing_type_id='||l_cpr_txn_billing_type_id );
1209     csd_gen_utility_pvt.add('l_ls_txn_billing_type_id ='||l_ls_txn_billing_type_id );
1210     csd_gen_utility_pvt.add('l_lr_txn_billing_type_id ='||l_lr_txn_billing_type_id );
1211   END IF;
1212 
1213 
1214   l_org_id := csd_process_util.get_org_id(l_incident_id);
1215   -- Inv_org Change, Vijay , 20/3/2006
1216   -- taken from the repair_order record.
1217   --l_inv_org_id := csd_process_util.get_inv_org_id;
1218 
1219   IF (g_debug > 0 ) THEN
1220 
1221     csd_gen_utility_pvt.add('l_incident_id   ='||l_incident_id);
1222     csd_gen_utility_pvt.add('l_org_id        ='||l_org_id);
1223     csd_gen_utility_pvt.add('l_inv_org_id    ='||l_inv_org_id);
1224 
1225   END IF;
1226 
1227   l_revision := l_inv_revision;
1228 
1229   -- Fix for bug# 3549430
1230   OPEN  get_item_attributes(l_inv_item_id,l_inv_org_id);
1231 
1232   FETCH get_item_attributes INTO
1233     l_serial_num_control_code,
1234     l_ib_flag;
1235 
1236   IF get_item_attributes%isopen then
1237     CLOSE get_item_attributes;
1238   END IF;
1239 
1240 
1241   -- yvchen: bug#13582572
1242   OPEN  get_lot_number(p_repair_line_id);
1243 
1244   FETCH get_lot_number INTO
1245     l_lot_number;
1246 
1247   IF get_lot_number%isopen then
1248     CLOSE get_lot_number;
1249   END IF;
1250 
1251 
1252 -- bug fix for 4108369, Begin
1253   l_sr_add_to_order_flag := fnd_profile.value('CSD_ADD_TO_SO_WITHIN_SR');
1254   l_sr_add_to_order_flag := nvl(l_sr_Add_to_order_flag, 'N');
1255 
1256   if(l_sr_add_to_order_flag = 'Y') THEN
1257   	l_add_rma_to_id := get_sr_add_to_order(p_repair_line_Id, 'RMA');
1258   	l_add_ship_to_id := get_sr_add_to_order(p_repair_line_Id, 'SHIP');
1259   END IF;
1260 -- bug fix for 4108369, End
1261 
1262   l_return_days := nvl(FND_PROFILE.value('CSD_PRODUCT_RETURN_DAYS'),0); /*Fixed for FP bug#5408047*/
1263   --Bug fix 5494219 Begin
1264      l_sub_inv := FND_PROFILE.value('CSD_DEF_RMA_SUBINV');
1265   --Bug fix 5494219 End
1266 
1267 
1268 /* bug#3875036 --begin here--*/
1269 
1270   l_enable_advanced_pricing	:= FND_PROFILE.VALUE('CSD_ENABLE_ADVANCED_PRICING');
1271   l_enable_advanced_pricing := nvl(l_enable_advanced_pricing, 'N');
1272   IF(l_enable_advanced_pricing ='Y') THEN
1273 	  l_account_id := CSD_CHARGE_LINE_UTIL.Get_SR_AccountId(p_repair_line_id);
1274 	  l_currency_code := GET_PL_CURRENCY_CODE(l_price_list_id);
1275 	  get_charge_selling_price(
1276 						  p_inventory_item_id    => l_inv_item_id,
1277 						  p_price_list_header_id => l_price_list_id,
1278 						  p_unit_of_measure_code => l_unit_of_measure,
1279 						  p_currency_code        => l_currency_code,
1280 						  p_quantity_required    => p_quantity,
1281 						  p_account_id			 => l_account_id,
1282 						  p_org_id				 => l_org_id,
1283 						  p_pricing_rec          => l_pricing_rec,
1284 						  x_selling_price        => l_selling_price,
1285 						  x_return_status        => l_return_status,
1286 						  x_msg_count            => l_msg_count,
1287 						  x_msg_data             => l_msg_data);
1288 
1289   END IF;
1290 
1291 /* bug#3875036 --end here--*/
1292 
1293   --bug#11769559
1294   l_default_logistics_warehouse := nvl(FND_PROFILE.value('CSD_DEFAULT_LOGISTICS_WAREHOUSE'), 'Y');
1295   --bug#11769559
1296 
1297   --defaulting rule value
1298   l_attr_type := 'CSD_DEF_ENTITY_ATTR_RO';
1299   l_rule_input_rec.REPAIR_LINE_ID := p_repair_line_Id;
1300 
1301 
1302   IF l_repair_type_ref = 'R' and (p_create_thirdpty_line = 'F') THEN
1303     -- in 11.5.10 we have place holder for non source item attributes
1304     -- like non_source_serial_number non_source_instance_id etc
1305     -- Shipping customer product txn line
1306 
1307     l_index := 1;
1308     if (l_cps_txn_billing_type_id is not null) then
1309 
1310         x_prod_txn_tbl(l_index).po_number                   := l_po_number;  -- swai bug fix 4535829
1311         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
1312         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
1313         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
1314         x_prod_txn_tbl(l_index).action_type                 := 'SHIP'            ;
1315 
1316         --bug#3875036 bug 8694111
1317 	  IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
1318             x_prod_txn_tbl(l_index).after_warranty_cost     := l_selling_price;
1319 	  End if;
1320 
1321         --x_prod_txn_tbl(l_index).action_code               := 'CUST_PROD'       ;
1322         -- In 11.5.10 we have defined a new action code replacement : saupadhy : 3431371
1323         x_prod_txn_tbl(l_index).action_code                 := c_Replacement  ;
1324         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
1325         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
1326         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cps_txn_billing_type_id;
1327         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id;
1328         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
1329         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
1330         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
1331         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
1332         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
1333      -- x_prod_txn_tbl(l_index).serial_number               := FND_API.G_MISS_CHAR;--l_serial_number   ; 11.5.9
1334         if ( l_ib_flag = 'Y' ) then
1335           x_prod_txn_tbl(l_index).non_source_serial_number    := p_serial_number   ; -- 11.5.10
1336         else
1337           x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR   ; -- 11.5.10
1338         end if;
1339         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number;  -- yvchen: bug#13582572
1340      -- x_prod_txn_tbl(l_index).instance_id                 := l_instance_id; -- 11.5.9
1341         x_prod_txn_tbl(l_index).non_source_instance_id      := p_instance_id; -- 11.5.10
1342         x_prod_txn_tbl(l_index).source_serial_number        := FND_API.G_MISS_CHAR;
1343         x_prod_txn_tbl(l_index).source_instance_id          := FND_API.G_MISS_NUM;
1344         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id  ;
1345         x_prod_txn_tbl(l_index).contract_id               := l_contract_id    ;
1346      -- R12 contract changes
1347         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
1348 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
1349 
1350 		l_attr_code := 'SHIP_FROM_SUBINV';
1351         l_default_val_char := null;
1352         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1353           p_api_version_number    => 1.0,
1354           p_init_msg_list         => FND_API.G_TRUE,
1355           p_commit                => FND_API.G_FALSE, --bug#12588243
1356           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1357           p_entity_attribute_type => l_attr_type,
1358           p_entity_attribute_code => l_attr_code,
1359           p_rule_input_rec        => l_rule_input_rec,
1360           x_default_value         => l_default_val_char,
1361           x_rule_id               => l_default_rule_id,   -- swai: 12.1.1 ER 7233924
1362           x_return_status         => l_return_status,
1363           x_msg_count             => l_msg_count,
1364           x_msg_data              => l_msg_data
1365         );
1366         if (l_default_val_char is not null) then
1367             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
1368         else
1369             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
1370         end if;
1371 
1372 
1373         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cps_txn_billing_type_id);
1374         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
1375         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
1376 
1377 
1378         IF NVL(l_interface_to_om_flag, 'N') = 'Y' THEN
1379           x_prod_txn_tbl(l_index).process_txn_flag           := 'Y';
1380           if NVL(l_book_sales_order_flag, 'N') = 'Y' THEN
1381              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
1382              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'Y';
1383           else
1384              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
1385              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'N';
1386           end if;
1387 
1388   	      if(l_add_ship_to_id is null) THEN
1389 	         x_prod_txn_tbl(l_index).new_order_flag := 'Y';
1390 	      ELSE
1391 		     x_prod_txn_tbl(l_index).new_order_flag := 'N';
1392 		     x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
1393 		     x_prod_txn_tbl(l_index).add_to_order_id := l_add_ship_to_id;
1394 	      END IF;
1395         Else
1396            x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
1397            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
1398            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
1399         End if;
1400 
1401         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
1402         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
1403         /* Fixed for FP bug#5408047
1404            For SHIP line if either of 'source return is required'
1405            or 'non-source return required' is checked then only default
1406            the return by date. This date will be passed to charges in
1407            Installed_cp_return_by_date or in New_cp_return_by_date
1408            based on source or non-source setup in procedure Convert_to_Chg_rec
1409         */
1410         l_src_return_reqd     :='N';
1411         l_non_src_return_reqd :='N';
1412         open c2( l_cps_txn_billing_type_id );
1413         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
1414         If (c2%ISOPEN) then
1415          Close c2;
1416         end if;
1417 
1418         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
1419            x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
1420         else
1421            x_prod_txn_tbl(l_index).return_by_date              := NULL;
1422         end if;
1423 
1424         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
1425         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
1426         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
1427         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
1428         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
1429         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
1430         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
1431         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
1432         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
1433         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
1434         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
1435         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
1436         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
1437         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
1438         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
1439         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
1440         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
1441         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
1442         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
1443         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
1444         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
1445         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
1446         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
1447         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
1448         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
1449         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
1450         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
1451 
1452         -- picking rule changes for R12
1453         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
1454         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
1455         --------------------------------
1456 
1457 		--bug#11769559
1458 		If (l_default_logistics_warehouse = 'Y') Then
1459 
1460 			l_attr_code := 'SHIP_FROM_ORG';
1461 			l_default_val_num := null;
1462 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1463 			  p_api_version_number    => 1.0,
1464 			  p_init_msg_list         => FND_API.G_TRUE,
1465 			  p_commit                => FND_API.G_FALSE, --bug#12588243
1466 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1467 			  p_entity_attribute_type => l_attr_type,
1468 			  p_entity_attribute_code => l_attr_code,
1469 			  p_rule_input_rec        => l_rule_input_rec,
1470 			  x_default_value         => l_default_val_num,
1471 			  x_rule_id               => l_default_rule_id,   -- swai: 12.1.1 ER 7233924
1472 			  x_return_status         => l_return_status,
1473 			  x_msg_count             => l_msg_count,
1474 			  x_msg_data              => l_msg_data
1475 			);
1476 
1477 			if (l_default_val_num is not null) then
1478 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
1479 			else
1480 				-- Inv_org Change, Vijay , 20/3/2006
1481 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
1482 			end if;
1483 		end if;
1484 		--bug#11769559
1485         ---------------------------------------
1486 
1487         l_index := l_index + 1;
1488 
1489     end if;
1490 
1491   ELSIF l_repair_type_ref in ('RR','WR','E' ) and (p_create_thirdpty_line = 'F') THEN
1492 
1493     l_index := 1;
1494 
1495     if (l_cpr_txn_billing_type_id is not null) then
1496 
1497         -- receive customer product txn line
1498         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
1499         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
1500         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
1501         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
1502         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cpr_txn_billing_type_id;
1503         x_prod_txn_tbl(l_index).po_number                   := l_po_number;  -- swai bug fix 4535829
1504        IF l_repair_type_ref = 'E' THEN
1505 	    -- saupady prefers this to be CUST_PROD instead of EXCHANGE
1506          x_prod_txn_tbl(l_index).action_code                 := 'EXCHANGE' ;
1507        ELSE
1508          x_prod_txn_tbl(l_index).action_code                 := 'CUST_PROD';
1509        END IF;
1510 
1511        IF l_repair_type_ref = 'WR' THEN
1512          x_prod_txn_tbl(l_index).action_type                 := 'WALK_IN_RECEIPT' ;
1513        ELSE
1514          x_prod_txn_tbl(l_index).action_type                 := 'RMA'             ;
1515        END IF;
1516 
1517         --bug#3875036 Bug 8694111
1518 	 IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
1519             x_prod_txn_tbl(l_index).after_warranty_cost	     := -l_selling_price;
1520 	 End If;
1521 
1522         -- x_prod_txn_tbl(l_index).serial_number            := l_serial_number   ;
1523         -- x_prod_txn_tbl(l_index).instance_id              := l_instance_id     ;
1524         x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number   ;
1525         x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id     ;
1526         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
1527         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
1528         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
1529         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
1530         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
1531         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
1532         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
1533         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
1534         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
1535         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
1536         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
1537         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
1538      -- R12 contract changes
1539         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
1540         x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
1541         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cpr_txn_billing_type_id) ;
1542         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N' ;
1543         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N' ;
1544 
1545         -- auto process the RMA for the customer
1546         -- product txn line only
1547         -- Following line commented by vkjain to fix 3353445
1548         -- It adds support of 'Auto Enter and Book' RMA.
1549         -- IF x_prod_txn_tbl(l_index).action_code = 'CUST_PROD' and
1550         IF NVL(l_auto_process_rma, 'N') = 'Y' THEN
1551            x_prod_txn_tbl(l_index).process_txn_flag            := 'Y' ;
1552            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'Y' ;
1553            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'Y' ;
1554            -- bug fix for 4108369, Begin
1555            if(l_add_rma_to_id is null) THEN
1556              x_prod_txn_tbl(l_index).new_order_flag := 'Y';
1557            ELSE
1558              x_prod_txn_tbl(l_index).new_order_flag := 'N';
1559              x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
1560              x_prod_txn_tbl(l_index).add_to_order_id := l_add_rma_to_id;
1561            END IF;
1562            -- bug fix for 4108369, End
1563         ELSE
1564            x_prod_txn_tbl(l_index).process_txn_flag            := 'N' ;
1565            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N' ;
1566            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N' ;
1567         END IF;
1568 
1569         x_prod_txn_tbl(l_index).return_reason               := l_return_reason  ;
1570         -- x_prod_txn_tbl(l_index).return_by_date           := sysdate          ;
1571         /* Fixed for FP bug#5408047
1572           For RMA line if source return is required then only
1573           default the return by date. This date will be passed to
1574           charges in Installed_cp_return_by_date.
1575         */
1576         l_src_return_reqd      :='N';
1577         l_non_src_return_reqd  :='N';
1578         open c2( l_cpr_txn_billing_type_id );
1579         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
1580         If (c2%ISOPEN) then
1581           Close c2;
1582         END IF;
1583         If l_src_return_reqd ='Y' then
1584           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
1585         ELSE
1586            x_prod_txn_tbl(l_index).return_by_date              := NULL          ;
1587         END IF;
1588 
1589         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
1590         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
1591         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
1592         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
1593         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
1594         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
1595         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
1596         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
1597         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
1598         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
1599         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
1600         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
1601         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
1602         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
1603         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
1604         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
1605         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
1606         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
1607         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
1608         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
1609         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
1610         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
1611         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
1612         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
1613         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
1614         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
1615         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
1616 
1617 
1618 		--bug#11769559
1619 		If (l_default_logistics_warehouse = 'Y') Then
1620 
1621 			l_attr_code := 'RMA_RCV_ORG';
1622 			l_default_val_num := null;
1623 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1624 			  p_api_version_number    => 1.0,
1625 			  p_init_msg_list         => FND_API.G_TRUE,
1626 			  p_commit                => FND_API.G_FALSE, --bug#12588243
1627 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1628 			  p_entity_attribute_type => l_attr_type,
1629 			  p_entity_attribute_code => l_attr_code,
1630 			  p_rule_input_rec        => l_rule_input_rec,
1631 			  x_default_value         => l_default_val_num,
1632 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
1633 			  x_return_status         => l_return_status,
1634 			  x_msg_count             => l_msg_count,
1635 			  x_msg_data              => l_msg_data
1636 			);
1637 
1638 			if (l_default_val_num is not null) then
1639 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
1640 			else
1641 				-- Inv_org Change, Vijay , 20/3/2006
1642 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
1643 			end if;
1644 		end if;
1645 		--bug#11769559
1646 
1647  		l_attr_code := 'RMA_RCV_SUBINV';
1648         l_default_val_char := null;
1649         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1650           p_api_version_number    => 1.0,
1651           p_init_msg_list         => FND_API.G_TRUE,
1652           p_commit                => FND_API.G_FALSE, --bug#12588243
1653           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1654           p_entity_attribute_type => l_attr_type,
1655           p_entity_attribute_code => l_attr_code,
1656           p_rule_input_rec        => l_rule_input_rec,
1657           x_default_value         => l_default_val_char,
1658           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
1659           x_return_status         => l_return_status,
1660           x_msg_count             => l_msg_count,
1661           x_msg_data              => l_msg_data
1662         );
1663         if (l_default_val_char is not null) then
1664             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
1665         else
1666             x_prod_txn_tbl(l_index).sub_inventory  := l_sub_inv;
1667         end if;
1668 
1669         IF p_invoice_to_org_id IS NOT NULL
1670         THEN
1671             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
1672         END IF;
1673 
1674         IF p_ship_to_org_id IS NOT NULL
1675         THEN
1676             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
1677         END IF;
1678 
1679         l_index := l_index + 1;
1680     end if;
1681 
1682     if (l_cps_txn_billing_type_id is not null) then
1683         -- Shipping customer product txn line
1684         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
1685         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
1686         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
1687         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
1688         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cps_txn_billing_type_id;
1689         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
1690 
1691        IF l_repair_type_ref = 'E' THEN
1692          x_prod_txn_tbl(l_index).action_code                := 'EXCHANGE' ;
1693          x_prod_txn_tbl(l_index).non_source_instance_id     := p_instance_id;
1694          if ( l_ib_flag = 'Y' ) then
1695            x_prod_txn_tbl(l_index).non_source_serial_number   := p_serial_number;
1696          else
1697            x_prod_txn_tbl(l_index).non_source_serial_number   := FND_API.G_MISS_CHAR;
1698          end if;
1699          x_prod_txn_tbl(l_index).source_instance_id         := FND_API.G_MISS_NUM;
1700          x_prod_txn_tbl(l_index).source_serial_number       := FND_API.G_MISS_CHAR;
1701        ELSE
1702          x_prod_txn_tbl(l_index).action_code                := 'CUST_PROD';
1703          x_prod_txn_tbl(l_index).non_source_instance_id     := FND_API.G_MISS_NUM;
1704          x_prod_txn_tbl(l_index).non_source_serial_number   := FND_API.G_MISS_CHAR;
1705 
1706          -- Fix for bug# 3549430
1707          if (l_serial_num_control_code = 1 and l_ib_flag = 'Y') then
1708            x_prod_txn_tbl(l_index).source_instance_id         := FND_API.G_MISS_NUM;
1709            x_prod_txn_tbl(l_index).source_serial_number       := FND_API.G_MISS_CHAR;
1710          else
1711            x_prod_txn_tbl(l_index).source_instance_id         := p_instance_id;
1712            x_prod_txn_tbl(l_index).source_serial_number       := p_serial_number;
1713          end if;
1714        END IF;
1715 
1716        IF l_repair_type_ref = 'WR' THEN
1717         x_prod_txn_tbl(l_index).action_type                 := 'WALK_IN_ISSUE'  ;
1718        ELSE
1719         x_prod_txn_tbl(l_index).action_type                 := 'SHIP'           ;
1720        END IF;
1721 
1722     --bug#3875036 Bug 8694111
1723 	IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
1724            x_prod_txn_tbl(l_index).after_warranty_cost      := l_selling_price;
1725 	End if;
1726 
1727         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
1728         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
1729         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
1730         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
1731         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
1732         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
1733         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
1734         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
1735         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
1736      -- R12 contract changes
1737         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
1738         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
1739 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
1740 		l_attr_code := 'SHIP_FROM_SUBINV';
1741         l_default_val_char := null;
1742         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1743           p_api_version_number    => 1.0,
1744           p_init_msg_list         => FND_API.G_TRUE,
1745           p_commit                => FND_API.G_FALSE, --bug#12588243
1746           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1747           p_entity_attribute_type => l_attr_type,
1748           p_entity_attribute_code => l_attr_code,
1749           p_rule_input_rec        => l_rule_input_rec,
1750           x_default_value         => l_default_val_char,
1751           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
1752           x_return_status         => l_return_status,
1753           x_msg_count             => l_msg_count,
1754           x_msg_data              => l_msg_data
1755         );
1756         if (l_default_val_char is not null) then
1757             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
1758         else
1759             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
1760         end if;
1761 
1762         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cps_txn_billing_type_id);
1763         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
1764         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
1765 
1766 
1767         IF NVL(l_interface_to_om_flag, 'N') = 'Y' THEN
1768           x_prod_txn_tbl(l_index).process_txn_flag           := 'Y';
1769           if NVL(l_book_sales_order_flag, 'N') = 'Y' THEN
1770              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
1771              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'Y';
1772           else
1773              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
1774              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'N';
1775           end if;
1776 
1777   	      if(l_add_ship_to_id is null) THEN
1778 	         x_prod_txn_tbl(l_index).new_order_flag := 'Y';
1779 	      ELSE
1780 		     x_prod_txn_tbl(l_index).new_order_flag := 'N';
1781 		     x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
1782 		     x_prod_txn_tbl(l_index).add_to_order_id := l_add_ship_to_id;
1783 	      END IF;
1784         Else
1785            x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
1786            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
1787            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
1788         End if;
1789 
1790         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
1791         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
1792         /* Fixed for FP bug#5408047
1793            For SHIP line if either of 'source return is required'
1794            or 'non-source return required' is checked then only default
1795            the return by date. This date will be passed to charges in
1796            Installed_cp_return_by_date or in New_cp_return_by_date
1797            based on source or non-source setup in procedure Convert_to_Chg_rec
1798          */
1799         l_src_return_reqd:='N';
1800         l_non_src_return_reqd:='N';
1801         open c2( l_cps_txn_billing_type_id );
1802         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
1803         If (c2%ISOPEN) then
1804           Close c2;
1805         END IF;
1806 
1807         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
1808           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
1809         ELSE
1810           x_prod_txn_tbl(l_index).return_by_date              := NULL;
1811         END IF;
1812         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
1813         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
1814         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
1815         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
1816         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
1817         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
1818         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
1819         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
1820         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
1821         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
1822         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
1823         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
1824         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
1825         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
1826         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
1827         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
1828         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
1829         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
1830         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
1831         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
1832         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
1833         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
1834         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
1835         x_prod_txn_tbl(l_index).prod_txn_code               := 'POST';
1836         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
1837         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
1838         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
1839 
1840         -- picking rule changes for R12
1841         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
1842         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
1843         --------------------------------
1844 		--bug#11769559
1845 		If (l_default_logistics_warehouse = 'Y') Then
1846 
1847 			l_attr_code := 'SHIP_FROM_ORG';
1848 			l_default_val_num := null;
1849 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1850 			  p_api_version_number    => 1.0,
1851 			  p_init_msg_list         => FND_API.G_TRUE,
1852 			  p_commit                => FND_API.G_FALSE, --bug#12588243
1853 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1854 			  p_entity_attribute_type => l_attr_type,
1855 			  p_entity_attribute_code => l_attr_code,
1856 			  p_rule_input_rec        => l_rule_input_rec,
1857 			  x_default_value         => l_default_val_num,
1858 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
1859 			  x_return_status         => l_return_status,
1860 			  x_msg_count             => l_msg_count,
1861 			  x_msg_data              => l_msg_data
1862 			);
1863 
1864 			if (l_default_val_num is not null) then
1865 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
1866 			else
1867 				-- Inv_org Change, Vijay , 20/3/2006
1868 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
1869 			end if;
1870 		end if;
1871 		--bug#11769559
1872 
1873         IF p_invoice_to_org_id IS NOT NULL
1874         THEN
1875             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
1876         END IF;
1877 
1878         IF p_ship_to_org_id IS NOT NULL
1879         THEN
1880             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
1881         END IF;
1882         l_index := l_index + 1;
1883 
1884     end if;
1885 
1886 
1887   ELSIF (l_repair_type_ref = 'AL') and (p_create_thirdpty_line = 'F') THEN
1888     l_index := 1;
1889 
1890     if (l_ls_txn_billing_type_id is not null) then
1891 
1892          -- Ship loaner product txn line
1893         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
1894         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
1895         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
1896         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
1897         x_prod_txn_tbl(l_index).action_code                 := 'LOANER'          ;
1898         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_ls_txn_billing_type_id;
1899         x_prod_txn_tbl(l_index).action_type                 := 'SHIP'             ;
1900 
1901         --bug#3875036 Bug 8694111
1902 	IF((l_enable_advanced_pricing ='Y')and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
1903           x_prod_txn_tbl(l_index).after_warranty_cost	    := l_selling_price;
1904 	End If;
1905 
1906         x_prod_txn_tbl(l_index).source_serial_number        := FND_API.G_MISS_CHAR;
1907         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
1908         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
1909         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
1910         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
1911         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
1912         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
1913         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
1914         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
1915         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
1916         x_prod_txn_tbl(l_index).source_instance_id          := FND_API.G_MISS_NUM;
1917         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
1918         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
1919      -- R12 contract changes
1920         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
1921         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
1922 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
1923 		l_attr_code := 'SHIP_FROM_SUBINV';
1924         l_default_val_char := null;
1925         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
1926           p_api_version_number    => 1.0,
1927           p_init_msg_list         => FND_API.G_TRUE,
1928           p_commit                => FND_API.G_FALSE, --bug#12588243
1929           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
1930           p_entity_attribute_type => l_attr_type,
1931           p_entity_attribute_code => l_attr_code,
1932           p_rule_input_rec        => l_rule_input_rec,
1933           x_default_value         => l_default_val_char,
1934           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
1935           x_return_status         => l_return_status,
1936           x_msg_count             => l_msg_count,
1937           x_msg_data              => l_msg_data
1938         );
1939         if (l_default_val_char is not null) then
1940             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
1941         else
1942             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
1943         end if;
1944 
1945         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_ls_txn_billing_type_id ) ;
1946         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N' ;
1947         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N' ;
1948 
1949         IF NVL(l_interface_to_om_flag, 'N') = 'Y' THEN
1950           x_prod_txn_tbl(l_index).process_txn_flag           := 'Y';
1951           if NVL(l_book_sales_order_flag, 'N') = 'Y' THEN
1952              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
1953              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'Y';
1954           else
1955              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
1956              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'N';
1957           end if;
1958 
1959   	      if(l_add_ship_to_id is null) THEN
1960 	         x_prod_txn_tbl(l_index).new_order_flag := 'Y';
1961 	      ELSE
1962 		     x_prod_txn_tbl(l_index).new_order_flag := 'N';
1963 		     x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
1964 		     x_prod_txn_tbl(l_index).add_to_order_id := l_add_ship_to_id;
1965 	      END IF;
1966 
1967         Else
1968            x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
1969            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
1970            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
1971         End if;
1972 
1973         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
1974         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
1975         /* Fixed for FP bug#5408047
1976            For SHIP line if either of 'source return is required'
1977            or 'non-source return required' is checked then only default
1978            the return by date. This date will be passed to charges in
1979            Installed_cp_return_by_date or in New_cp_return_by_date
1980            based on source or non-source setup in procedure Convert_to_Chg_rec
1981          */
1982         l_src_return_reqd     :='N';
1983         l_non_src_return_reqd :='N';
1984         open c2( l_ls_txn_billing_type_id );
1985         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
1986         If (c2%ISOPEN) then
1987           Close c2;
1988         END IF;
1989         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
1990           x_prod_txn_tbl(l_index).return_by_date            := sysdate+l_return_days;
1991         else
1992           x_prod_txn_tbl(l_index).return_by_date            := NULL;
1993         END IF;
1994         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
1995         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
1996         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
1997         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
1998         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
1999         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
2000         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
2001         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
2002         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
2003         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
2004         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
2005         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
2006         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
2007         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
2008         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
2009         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
2010         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
2011         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
2012         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
2013         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
2014         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
2015         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
2016         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
2017         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
2018         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
2019         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
2020         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
2021         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
2022 
2023         -- picking rule changes for R12
2024         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
2025         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
2026         --------------------------------
2027 
2028 		--bug#11769559
2029 		If (l_default_logistics_warehouse = 'Y') Then
2030 
2031 			l_attr_code := 'SHIP_FROM_ORG';
2032 			l_default_val_num := null;
2033 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2034 			  p_api_version_number    => 1.0,
2035 			  p_init_msg_list         => FND_API.G_TRUE,
2036 			  p_commit                => FND_API.G_FALSE, --bug#12588243
2037 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2038 			  p_entity_attribute_type => l_attr_type,
2039 			  p_entity_attribute_code => l_attr_code,
2040 			  p_rule_input_rec        => l_rule_input_rec,
2041 			  x_default_value         => l_default_val_num,
2042 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2043 			  x_return_status         => l_return_status,
2044 			  x_msg_count             => l_msg_count,
2045 			  x_msg_data              => l_msg_data
2046 			);
2047 
2048 			if (l_default_val_num is not null) then
2049 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
2050 			else
2051 				-- Inv_org Change, Vijay , 20/3/2006
2052 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
2053 			end if;
2054 		end if;
2055 		--bug#11769559
2056 
2057         ---------------------------------------
2058         IF p_invoice_to_org_id IS NOT NULL
2059         THEN
2060             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
2061         END IF;
2062 
2063         IF p_ship_to_org_id IS NOT NULL
2064         THEN
2065             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
2066         END IF;
2067         l_index := l_index + 1;
2068 
2069     end if;
2070 
2071     if (l_lr_txn_billing_type_id is not null) then
2072         -- Receive Loaner product txn line
2073         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
2074         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
2075         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
2076         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
2077         x_prod_txn_tbl(l_index).action_code                 := 'LOANER'       ;
2078         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_lr_txn_billing_type_id;
2079         x_prod_txn_tbl(l_index).action_type                 := 'RMA'            ;
2080 
2081         --bug#3875036 Bug 8694111
2082 	IF((l_enable_advanced_pricing ='Y')and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
2083    	  x_prod_txn_tbl(l_index).after_warranty_cost	    := -l_selling_price;
2084 	End if;
2085 
2086         x_prod_txn_tbl(l_index).po_number                   := l_po_number;  -- swai bug fix 4535829
2087         -- Fix for bug#3704155
2088         --x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number;
2089         x_prod_txn_tbl(l_index).source_serial_number        := FND_API.G_MISS_CHAR;
2090         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
2091         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
2092         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
2093         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
2094         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
2095         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
2096         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
2097         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
2098         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
2099         -- Fix for bug#3704155
2100         --x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id     ;
2101         x_prod_txn_tbl(l_index).source_instance_id          := FND_API.G_MISS_NUM;
2102         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
2103         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
2104      -- R12 contract changes
2105         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
2106         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
2107         x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
2108         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_lr_txn_billing_type_id) ;
2109         x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
2110         x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
2111         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
2112         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
2113         x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
2114         IF NVL(l_auto_process_rma, 'N') = 'Y' THEN
2115             x_prod_txn_tbl(l_index).process_txn_flag            := 'Y'           ;
2116             x_prod_txn_tbl(l_index).interface_to_om_flag        := 'Y'           ;
2117             x_prod_txn_tbl(l_index).book_sales_order_flag       := 'Y'           ;
2118          -- bug fix for 4108369, Begin
2119             if(l_add_rma_to_id is null) THEN
2120         	    x_prod_txn_tbl(l_index).new_order_flag := 'Y';
2121             ELSE
2122         	    x_prod_txn_tbl(l_index).new_order_flag := 'N';
2123         	    x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
2124         	    x_prod_txn_tbl(l_index).add_to_order_id := l_add_rma_to_id;
2125             END IF;
2126          -- bug fix for 4108369, End
2127         END IF;
2128 
2129         x_prod_txn_tbl(l_index).return_reason               := l_return_reason  ;
2130         -- x_prod_txn_tbl(l_index).return_by_date           := sysdate          ;
2131         /* Fixed for FP bug#5408047
2132            For RMA line if source return is required then only
2133            default the return by date. This date will be passed to
2134            charges in Installed_cp_return_by_date.
2135         */
2136         l_src_return_reqd     :='N';
2137         l_non_src_return_reqd :='N';
2138         open c2( l_lr_txn_billing_type_id );
2139         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
2140         If (c2%ISOPEN) then
2141            Close c2;
2142         END IF;
2143         If l_src_return_reqd ='Y' then
2144            x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
2145         ELSE
2146            x_prod_txn_tbl(l_index).return_by_date              := NULL          ;
2147         END IF;
2148 
2149         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
2150         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
2151         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
2152         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
2153         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
2154         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
2155         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
2156         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
2157         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
2158         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
2159         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
2160         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
2161         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
2162         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
2163         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
2164         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
2165         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
2166         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
2167         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
2168         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
2169         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
2170         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
2171         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
2172         x_prod_txn_tbl(l_index).prod_txn_code               := 'POST';
2173         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
2174         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
2175         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
2176 
2177 		--bug#11769559
2178 		If (l_default_logistics_warehouse = 'Y') Then
2179 
2180 			l_attr_code := 'RMA_RCV_ORG';
2181 			l_default_val_num := null;
2182 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2183 			  p_api_version_number    => 1.0,
2184 			  p_init_msg_list         => FND_API.G_TRUE,
2185 			  p_commit                => FND_API.G_FALSE, --bug#12588243
2186 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2187 			  p_entity_attribute_type => l_attr_type,
2188 			  p_entity_attribute_code => l_attr_code,
2189 			  p_rule_input_rec        => l_rule_input_rec,
2190 			  x_default_value         => l_default_val_num,
2191 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2192 			  x_return_status         => l_return_status,
2193 			  x_msg_count             => l_msg_count,
2194 			  x_msg_data              => l_msg_data
2195 			);
2196 
2197 			if (l_default_val_num is not null) then
2198 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
2199 			else
2200 				-- Inv_org Change, Vijay , 20/3/2006
2201 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
2202 			end if;
2203 		end if;
2204 		--bug#11769559
2205 
2206         ---------------------------------------
2207         --Bug fix 5494219 Begin
2208 		l_attr_code := 'RMA_RCV_SUBINV';
2209         l_default_val_char := null;
2210         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2211           p_api_version_number    => 1.0,
2212           p_init_msg_list         => FND_API.G_TRUE,
2213           p_commit                => FND_API.G_FALSE, --bug#12588243
2214           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2215           p_entity_attribute_type => l_attr_type,
2216           p_entity_attribute_code => l_attr_code,
2217           p_rule_input_rec        => l_rule_input_rec,
2218           x_default_value         => l_default_val_char,
2219           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2220           x_return_status         => l_return_status,
2221           x_msg_count             => l_msg_count,
2222           x_msg_data              => l_msg_data
2223         );
2224         if (l_default_val_char is not null) then
2225             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
2226         else
2227             x_prod_txn_tbl(l_index).sub_inventory  := l_sub_inv;
2228         end if;
2229 
2230         IF p_invoice_to_org_id IS NOT NULL
2231         THEN
2232             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
2233         END IF;
2234 
2235         IF p_ship_to_org_id IS NOT NULL
2236         THEN
2237             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
2238         END IF;
2239 
2240         l_index := l_index + 1;
2241 
2242     end if;
2243 
2244   ELSIF ( l_repair_type_ref = 'AE' ) and (p_create_thirdpty_line = 'F')  THEN
2245 
2246     l_index := 1;
2247 
2248     if (l_cps_txn_billing_type_id is not null) then
2249 
2250          -- Ship Customer product txn line
2251         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
2252         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
2253         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
2254         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
2255         x_prod_txn_tbl(l_index).action_code                 := 'EXCHANGE'        ;
2256         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cps_txn_billing_type_id;
2257         x_prod_txn_tbl(l_index).action_type                 := 'SHIP'             ;
2258 
2259         --bug#3875036 Bug 8694111
2260         IF((l_enable_advanced_pricing ='Y')and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
2261           x_prod_txn_tbl(l_index).after_warranty_cost	    := l_selling_price;
2262 	End if;
2263 
2264         x_prod_txn_tbl(l_index).source_serial_number        := FND_API.G_MISS_CHAR;
2265         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
2266         if ( l_ib_flag = 'Y' ) then
2267           x_prod_txn_tbl(l_index).non_source_serial_number    := p_serial_number ;
2268         else
2269           x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
2270         end if;
2271         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
2272         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
2273         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
2274         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
2275         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
2276         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
2277         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
2278         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
2279         x_prod_txn_tbl(l_index).source_instance_id          := FND_API.G_MISS_NUM;
2280         x_prod_txn_tbl(l_index).non_source_instance_id      := p_instance_id     ;
2281         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
2282      -- R12 contract changes
2283         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
2284         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
2285 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
2286 		l_attr_code := 'SHIP_FROM_SUBINV';
2287         l_default_val_char := null;
2288         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2289           p_api_version_number    => 1.0,
2290           p_init_msg_list         => FND_API.G_TRUE,
2291           p_commit                => FND_API.G_FALSE, --bug#12588243
2292           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2293           p_entity_attribute_type => l_attr_type,
2294           p_entity_attribute_code => l_attr_code,
2295           p_rule_input_rec        => l_rule_input_rec,
2296           x_default_value         => l_default_val_char,
2297           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2298           x_return_status         => l_return_status,
2299           x_msg_count             => l_msg_count,
2300           x_msg_data              => l_msg_data
2301         );
2302         if (l_default_val_char is not null) then
2303             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
2304         else
2305             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
2306         end if;
2307 
2308         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cps_txn_billing_type_id) ;
2309         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N' ;
2310         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N' ;
2311 
2312         IF NVL(l_interface_to_om_flag, 'N') = 'Y' THEN
2313           x_prod_txn_tbl(l_index).process_txn_flag           := 'Y';
2314           if NVL(l_book_sales_order_flag, 'N') = 'Y' THEN
2315              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
2316              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'Y';
2317           else
2318              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
2319              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'N';
2320           end if;
2321 
2322   	      if(l_add_ship_to_id is null) THEN
2323 	         x_prod_txn_tbl(l_index).new_order_flag := 'Y';
2324 	      ELSE
2325 		     x_prod_txn_tbl(l_index).new_order_flag := 'N';
2326 		     x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
2327 		     x_prod_txn_tbl(l_index).add_to_order_id := l_add_ship_to_id;
2328 	      END IF;
2329 
2330         Else
2331            x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
2332            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
2333            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
2334         End if;
2335 
2336         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
2337         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
2338        /* Fixed for FP bug#5408047
2339           For SHIP line if either of 'source return is required'
2340           or 'non-source return required' is checked then only default
2341           the return by date. This date will be passed to charges in
2342           Installed_cp_return_by_date or in New_cp_return_by_date
2343           based on source or non-source setup in procedure Convert_to_Chg_rec
2344         */
2345         l_src_return_reqd     :='N';
2346         l_non_src_return_reqd :='N';
2347         open c2( l_cps_txn_billing_type_id );
2348         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
2349         If (c2%ISOPEN) then
2350           Close c2;
2351         END IF;
2352         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
2353           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
2354         else
2355           x_prod_txn_tbl(l_index).return_by_date              := NULL;
2356         END IF;
2357 
2358         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
2359         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
2360         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
2361         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
2362         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
2363         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
2364         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
2365         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
2366         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
2367         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
2368         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
2369         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
2370         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
2371         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
2372         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
2373         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
2374         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
2375         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
2376         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
2377         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
2378         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
2379         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
2380         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
2381         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
2382         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
2383         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
2384         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
2385 
2386         -- picking rule changes for R12
2387         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
2388         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
2389         --------------------------------
2390 
2391 		--bug#11769559
2392 		If (l_default_logistics_warehouse = 'Y') Then
2393 			l_attr_code := 'SHIP_FROM_ORG';
2394 			l_default_val_num := null;
2395 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2396 			  p_api_version_number    => 1.0,
2397 			  p_init_msg_list         => FND_API.G_TRUE,
2398 			  p_commit                => FND_API.G_FALSE, --bug#12588243
2399 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2400 			  p_entity_attribute_type => l_attr_type,
2401 			  p_entity_attribute_code => l_attr_code,
2402 			  p_rule_input_rec        => l_rule_input_rec,
2403 			  x_default_value         => l_default_val_num,
2404 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2405 			  x_return_status         => l_return_status,
2406 			  x_msg_count             => l_msg_count,
2407 			  x_msg_data              => l_msg_data
2408 			);
2409 
2410 			if (l_default_val_num is not null) then
2411 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
2412 			else
2413 				-- Inv_org Change, Vijay , 20/3/2006
2414 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
2415 			end if;
2416 		end if;
2417 		--bug#11769559
2418         IF p_invoice_to_org_id IS NOT NULL
2419         THEN
2420             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
2421         END IF;
2422 
2423         IF p_ship_to_org_id IS NOT NULL
2424         THEN
2425             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
2426         END IF;
2427 
2428         l_index := l_index + 1;
2429 
2430     end if;
2431 
2432     if (l_cpr_txn_billing_type_id is not null) then
2433 
2434         -- Receive Loaner product txn line
2435         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
2436         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
2437         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
2438         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
2439         x_prod_txn_tbl(l_index).action_code                 := 'EXCHANGE'       ;
2440         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cpr_txn_billing_type_id;
2441         x_prod_txn_tbl(l_index).action_type                 := 'RMA'            ;
2442 
2443         --bug#3875036 Bug 8694111
2444 	IF((l_enable_advanced_pricing ='Y')and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
2445            x_prod_txn_tbl(l_index).after_warranty_cost      := -l_selling_price;
2446 	End If;
2447 
2448 
2449         x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number  ;
2450         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
2451         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
2452         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
2453         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
2454         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
2455         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
2456         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
2457         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
2458         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
2459         x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id     ;
2460         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
2461         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
2462      -- R12 contract changes
2463         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
2464         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
2465         x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
2466         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cpr_txn_billing_type_id);
2467         x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
2468         x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
2469         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
2470         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
2471         x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
2472         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
2473         IF NVL(l_auto_process_rma, 'N') = 'Y' THEN
2474             x_prod_txn_tbl(l_index).process_txn_flag            := 'Y'           ;
2475             x_prod_txn_tbl(l_index).interface_to_om_flag        := 'Y'           ;
2476             x_prod_txn_tbl(l_index).book_sales_order_flag       := 'Y'           ;
2477          -- bug fix for 4108369, Begin
2478            if(l_add_rma_to_id is null) THEN
2479              x_prod_txn_tbl(l_index).new_order_flag := 'Y';
2480            ELSE
2481              x_prod_txn_tbl(l_index).new_order_flag := 'N';
2482              x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
2483              x_prod_txn_tbl(l_index).add_to_order_id := l_add_rma_to_id;
2484            END IF;
2485         -- bug fix for 4108369, End
2486         END IF;
2487 
2488         x_prod_txn_tbl(l_index).return_reason               := l_return_reason  ;
2489         -- x_prod_txn_tbl(l_index).return_by_date           := sysdate          ;
2490         /* Fixed for FP bug#5408047
2491            For RMA line if source return is required then only
2492            default the return by date. This date will be passed to
2493            charges in Installed_cp_return_by_date.
2494          */
2495         l_src_return_reqd     :='N';
2496         l_non_src_return_reqd :='N';
2497         open c2( l_cpr_txn_billing_type_id );
2498         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
2499         If (c2%ISOPEN) then
2500            Close c2;
2501         END IF;
2502         If l_src_return_reqd ='Y' then
2503            x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
2504         else
2505             x_prod_txn_tbl(l_index).return_by_date              := NULL          ;
2506         end if;
2507         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
2508         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
2509         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
2510         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
2511         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
2512         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
2513         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
2514         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
2515         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
2516         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
2517         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
2518         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
2519         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
2520         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
2521         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
2522         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
2523         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
2524         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
2525         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
2526         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
2527         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
2528         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
2529         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
2530         x_prod_txn_tbl(l_index).prod_txn_code               := 'POST';
2531         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
2532         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
2533         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
2534 
2535 		--bug#11769559
2536 		If (l_default_logistics_warehouse = 'Y') Then
2537 
2538 			l_attr_code := 'RMA_RCV_ORG';
2539 			l_default_val_num := null;
2540 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2541 			  p_api_version_number    => 1.0,
2542 			  p_init_msg_list         => FND_API.G_TRUE,
2543 			  p_commit                => FND_API.G_FALSE, --bug#12588243
2544 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2545 			  p_entity_attribute_type => l_attr_type,
2546 			  p_entity_attribute_code => l_attr_code,
2547 			  p_rule_input_rec        => l_rule_input_rec,
2548 			  x_default_value         => l_default_val_num,
2549 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2550 			  x_return_status         => l_return_status,
2551 			  x_msg_count             => l_msg_count,
2552 			  x_msg_data              => l_msg_data
2553 			);
2554 			if (l_default_val_num is not null) then
2555 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
2556 			else
2557 				-- Inv_org Change, Vijay , 20/3/2006
2558 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
2559 			end if;
2560 		end if;
2561 		--bug#11769559
2562 
2563         ---------------------------------------
2564         --Bug fix 5494219 Begin
2565 		l_attr_code := 'RMA_RCV_SUBINV';
2566         l_default_val_char := null;
2567         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2568           p_api_version_number    => 1.0,
2569           p_init_msg_list         => FND_API.G_TRUE,
2570           p_commit                => FND_API.G_FALSE, --bug#12588243
2571           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2572           p_entity_attribute_type => l_attr_type,
2573           p_entity_attribute_code => l_attr_code,
2574           p_rule_input_rec        => l_rule_input_rec,
2575           x_default_value         => l_default_val_char,
2576           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2577           x_return_status         => l_return_status,
2578           x_msg_count             => l_msg_count,
2579           x_msg_data              => l_msg_data
2580         );
2581         if (l_default_val_char is not null) then
2582             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
2583         else
2584             x_prod_txn_tbl(l_index).sub_inventory  := l_sub_inv;
2585         end if;
2586 
2587         IF p_invoice_to_org_id IS NOT NULL
2588         THEN
2589             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
2590         END IF;
2591 
2592         IF p_ship_to_org_id IS NOT NULL
2593         THEN
2594             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
2595         END IF;
2596 
2597         l_index := l_index + 1;
2598 
2599     end if;
2600 
2601   ELSIF l_repair_type_ref in ('ARR','WRL') and (p_create_thirdpty_line = 'F') THEN
2602     l_index := 1;
2603 
2604     if (l_ls_txn_billing_type_id is not null) then
2605         -- Shipping loaner product txn line
2606         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
2607         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
2608         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
2609         x_prod_txn_tbl(l_index).action_code                 := 'LOANER'          ;
2610         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
2611         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_ls_txn_billing_type_id;
2612         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
2613 
2614        IF l_repair_type_ref = 'WRL' THEN
2615          x_prod_txn_tbl(l_index).action_type                 := 'WALK_IN_ISSUE'   ;
2616        ELSE
2617          x_prod_txn_tbl(l_index).action_type                 := 'SHIP'            ;
2618        END IF;
2619 
2620         --bug#3875036 Bug 8694111
2621 	IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
2622            x_prod_txn_tbl(l_index).after_warranty_cost	     := l_selling_price;
2623         End if;
2624 
2625 
2626         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
2627         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
2628         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
2629         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
2630         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
2631         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
2632         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
2633         x_prod_txn_tbl(l_index).source_serial_number        := FND_API.G_MISS_CHAR;
2634         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
2635         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
2636         x_prod_txn_tbl(l_index).source_instance_id          := FND_API.G_MISS_NUM;
2637         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
2638         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id  ;
2639      -- R12 contract changes
2640         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
2641         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id    ;
2642 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
2643 		l_attr_code := 'SHIP_FROM_SUBINV';
2644         l_default_val_char := null;
2645         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2646           p_api_version_number    => 1.0,
2647           p_init_msg_list         => FND_API.G_TRUE,
2648           p_commit                => FND_API.G_FALSE, --bug#12588243
2649           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2650           p_entity_attribute_type => l_attr_type,
2651           p_entity_attribute_code => l_attr_code,
2652           p_rule_input_rec        => l_rule_input_rec,
2653           x_default_value         => l_default_val_char,
2654           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2655           x_return_status         => l_return_status,
2656           x_msg_count             => l_msg_count,
2657           x_msg_data              => l_msg_data
2658         );
2659         if (l_default_val_char is not null) then
2660             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
2661         else
2662             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
2663         end if;
2664 
2665         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_ls_txn_billing_type_id);
2666         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
2667         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
2668 
2669         IF NVL(l_interface_to_om_flag, 'N') = 'Y' and l_repair_type_ref = 'ARR' THEN
2670           x_prod_txn_tbl(l_index).process_txn_flag           := 'Y';
2671           if NVL(l_book_sales_order_flag, 'N') = 'Y' THEN
2672              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
2673              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'Y';
2674           else
2675              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
2676              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'N';
2677           end if;
2678 
2679   	      if(l_add_ship_to_id is null) THEN
2680 	         x_prod_txn_tbl(l_index).new_order_flag := 'Y';
2681 	      ELSE
2682 		     x_prod_txn_tbl(l_index).new_order_flag := 'N';
2683 		     x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
2684 		     x_prod_txn_tbl(l_index).add_to_order_id := l_add_ship_to_id;
2685 	      END IF;
2686 
2687         Else
2688            x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
2689            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
2690            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
2691         End if;
2692 
2693         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
2694         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
2695         /* Fixed for FP bug#5408047
2696            For SHIP line if either of 'source return is required'
2697            or 'non-source return required' is checked then only default
2698            the return by date. This date will be passed to charges in
2699            Installed_cp_return_by_date or in New_cp_return_by_date
2700            based on source or non-source setup in procedure Convert_to_Chg_rec
2701         */
2702         l_src_return_reqd     :='N';
2703         l_non_src_return_reqd :='N';
2704         open c2( l_ls_txn_billing_type_id );
2705         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
2706         If (c2%ISOPEN) then
2707            Close c2;
2708         END IF;
2709         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
2710           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
2711         else
2712           x_prod_txn_tbl(l_index).return_by_date              := NULL;
2713         end if;
2714 
2715         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
2716         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
2717         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
2718         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
2719         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
2720         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
2721         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
2722         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
2723         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
2724         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
2725         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
2726         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
2727         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
2728         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
2729         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
2730         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
2731         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
2732         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
2733         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
2734         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
2735         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
2736         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
2737         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
2738         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
2739         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
2740         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
2741         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
2742 
2743 
2744         -- picking rule changes for R12
2745         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
2746         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
2747         --------------------------------
2748 
2749 		--bug#11769559
2750 		If (l_default_logistics_warehouse = 'Y') Then
2751 
2752 			l_attr_code := 'SHIP_FROM_ORG';
2753 			l_default_val_num := null;
2754 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2755 			  p_api_version_number    => 1.0,
2756 			  p_init_msg_list         => FND_API.G_TRUE,
2757 			  p_commit                => FND_API.G_FALSE, --bug#12588243
2758 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2759 			  p_entity_attribute_type => l_attr_type,
2760 			  p_entity_attribute_code => l_attr_code,
2761 			  p_rule_input_rec        => l_rule_input_rec,
2762 			  x_default_value         => l_default_val_num,
2763 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2764 			  x_return_status         => l_return_status,
2765 			  x_msg_count             => l_msg_count,
2766 			  x_msg_data              => l_msg_data
2767 			);
2768 			if (l_default_val_num is not null) then
2769 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
2770 			else
2771 				-- Inv_org Change, Vijay , 20/3/2006
2772 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
2773 			end if;
2774 		end if;
2775 		--bug#11769559
2776 
2777         IF p_invoice_to_org_id IS NOT NULL
2778         THEN
2779             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
2780         END IF;
2781 
2782         IF p_ship_to_org_id IS NOT NULL
2783         THEN
2784             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
2785         END IF;
2786 
2787         l_index := l_index + 1;
2788     end if;
2789 
2790     if (l_cpr_txn_billing_type_id is not null) then
2791 
2792         -- Receive customer product txn line
2793         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
2794         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
2795         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
2796         x_prod_txn_tbl(l_index).action_code                 := 'CUST_PROD'        ;
2797         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
2798         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cpr_txn_billing_type_id;
2799         x_prod_txn_tbl(l_index).po_number                   := l_po_number;  -- swai bug fix 4535829
2800 
2801        IF l_repair_type_ref = 'WRL' THEN
2802          x_prod_txn_tbl(l_index).action_type                 := 'WALK_IN_RECEIPT' ;
2803        ELSE
2804          x_prod_txn_tbl(l_index).action_type                 := 'RMA'             ;
2805        END IF;
2806 
2807         --bug#3875036 Bug 8694111
2808 	IF((l_enable_advanced_pricing ='Y')and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
2809            x_prod_txn_tbl(l_index).after_warranty_cost	     := -l_selling_price;
2810         End if;
2811 
2812         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
2813         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id  ;
2814         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
2815         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
2816         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
2817         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
2818         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
2819         x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number;
2820         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
2821         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
2822         x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id     ;
2823         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
2824         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
2825      -- R12 contract changes
2826         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
2827         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
2828         x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
2829         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cpr_txn_billing_type_id);
2830         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
2831         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
2832 
2833         IF NVL(l_auto_process_rma, 'N') = 'Y' THEN
2834            x_prod_txn_tbl(l_index).process_txn_flag            := 'Y' ;
2835            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'Y' ;
2836            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'Y' ;
2837     -- bug fix for 4108369, Begin
2838            if(l_add_rma_to_id is null) THEN
2839              x_prod_txn_tbl(l_index).new_order_flag := 'Y';
2840            ELSE
2841              x_prod_txn_tbl(l_index).new_order_flag := 'N';
2842              x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
2843              x_prod_txn_tbl(l_index).add_to_order_id := l_add_rma_to_id;
2844            END IF;
2845     -- bug fix for 4108369, End
2846         ELSE
2847            x_prod_txn_tbl(l_index).process_txn_flag            := 'N' ;
2848            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N' ;
2849            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N' ;
2850         END IF;
2851 
2852         x_prod_txn_tbl(l_index).return_reason               := l_return_reason  ;
2853         -- x_prod_txn_tbl(l_index).return_by_date           := sysdate          ;
2854         /* Fixed for FP bug#5408047
2855            For RMA line if source return is required then only
2856            default the return by date. This date will be passed to
2857            charges in Installed_cp_return_by_date.
2858         */
2859         l_src_return_reqd     :='N';
2860         l_non_src_return_reqd :='N';
2861         open c2( l_cpr_txn_billing_type_id );
2862         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
2863         If (c2%ISOPEN) then
2864            Close c2;
2865         END IF;
2866         If l_src_return_reqd ='Y' then
2867            x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
2868         else
2869            x_prod_txn_tbl(l_index).return_by_date              := NULL         ;
2870         end IF;
2871 
2872         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
2873         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
2874         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
2875         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
2876         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
2877         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
2878         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
2879         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
2880         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
2881         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
2882         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
2883         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
2884         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
2885         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
2886         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
2887         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
2888         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
2889         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
2890         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
2891         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
2892         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
2893         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
2894         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
2895         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
2896         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
2897         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
2898         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
2899 
2900 		--bug#11769559
2901 		If (l_default_logistics_warehouse = 'Y') Then
2902 
2903 			l_attr_code := 'RMA_RCV_ORG';
2904 			l_default_val_num := null;
2905 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2906 			  p_api_version_number    => 1.0,
2907 			  p_init_msg_list         => FND_API.G_TRUE,
2908 			  p_commit                => FND_API.G_FALSE, --bug#12588243
2909 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2910 			  p_entity_attribute_type => l_attr_type,
2911 			  p_entity_attribute_code => l_attr_code,
2912 			  p_rule_input_rec        => l_rule_input_rec,
2913 			  x_default_value         => l_default_val_num,
2914 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2915 			  x_return_status         => l_return_status,
2916 			  x_msg_count             => l_msg_count,
2917 			  x_msg_data              => l_msg_data
2918 			);
2919 			if (l_default_val_num is not null) then
2920 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
2921 			else
2922 				-- Inv_org Change, Vijay , 20/3/2006
2923 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
2924 			end if;
2925 		end if;
2926 		--bug#11769559
2927 
2928         ---------------------------------------
2929         --Bug fix 5494219 Begin
2930   		l_attr_code := 'RMA_RCV_SUBINV';
2931         l_default_val_char := null;
2932         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
2933           p_api_version_number    => 1.0,
2934           p_init_msg_list         => FND_API.G_TRUE,
2935           p_commit                => FND_API.G_FALSE, --bug#12588243
2936           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
2937           p_entity_attribute_type => l_attr_type,
2938           p_entity_attribute_code => l_attr_code,
2939           p_rule_input_rec        => l_rule_input_rec,
2940           x_default_value         => l_default_val_char,
2941           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
2942           x_return_status         => l_return_status,
2943           x_msg_count             => l_msg_count,
2944           x_msg_data              => l_msg_data
2945         );
2946         if (l_default_val_char is not null) then
2947             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
2948         else
2949             x_prod_txn_tbl(l_index).sub_inventory  := l_sub_inv;
2950         end if;
2951 
2952         IF p_invoice_to_org_id IS NOT NULL
2953         THEN
2954             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
2955         END IF;
2956 
2957         IF p_ship_to_org_id IS NOT NULL
2958         THEN
2959             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
2960         END IF;
2961 
2962         l_index := l_index + 1;
2963 
2964     end if;
2965 
2966 
2967     if (l_cps_txn_billing_type_id is not null) then
2968 
2969         -- ship customer product txn line
2970         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
2971         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
2972         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
2973         x_prod_txn_tbl(l_index).action_code                 := 'CUST_PROD'       ;
2974         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
2975         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_cps_txn_billing_type_id;
2976         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
2977 
2978        IF l_repair_type_ref = 'WRL' THEN
2979         x_prod_txn_tbl(l_index).action_type                 := 'WALK_IN_ISSUE' ;
2980        ELSE
2981         x_prod_txn_tbl(l_index).action_type                 := 'SHIP'             ;
2982        END IF;
2983 
2984         --bug#3875036 Bug 8694111
2985 	IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
2986            x_prod_txn_tbl(l_index).after_warranty_cost	    := l_selling_price;
2987         End if;
2988 
2989         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
2990         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id;
2991         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
2992         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
2993         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
2994         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
2995         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
2996         -- x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number ;
2997         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
2998         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
2999 
3000         -- Fix for bug# 3549430
3001         if (l_serial_num_control_code = 1 and l_ib_flag = 'Y') then
3002           x_prod_txn_tbl(l_index).source_instance_id         := FND_API.G_MISS_NUM;
3003           x_prod_txn_tbl(l_index).source_serial_number       := FND_API.G_MISS_CHAR;
3004         else
3005           x_prod_txn_tbl(l_index).source_instance_id         := p_instance_id;
3006           x_prod_txn_tbl(l_index).source_serial_number       := p_serial_number;
3007         end if;
3008 
3009         -- x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id ;
3010         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
3011         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
3012      -- R12 contract changes
3013         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
3014         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
3015 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
3016 		l_attr_code := 'SHIP_FROM_SUBINV';
3017         l_default_val_char := null;
3018         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3019           p_api_version_number    => 1.0,
3020           p_init_msg_list         => FND_API.G_TRUE,
3021           p_commit                => FND_API.G_FALSE, --bug#12588243
3022           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3023           p_entity_attribute_type => l_attr_type,
3024           p_entity_attribute_code => l_attr_code,
3025           p_rule_input_rec        => l_rule_input_rec,
3026           x_default_value         => l_default_val_char,
3027           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3028           x_return_status         => l_return_status,
3029           x_msg_count             => l_msg_count,
3030           x_msg_data              => l_msg_data
3031         );
3032         if (l_default_val_char is not null) then
3033             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
3034         else
3035             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
3036         end if;
3037 
3038         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_cps_txn_billing_type_id) ;
3039         x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
3040         x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
3041         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
3042         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
3043         x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
3044         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
3045         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
3046         /* Fixed for FP bug#5408047
3047            For SHIP line if either of 'source return is required'
3048            or 'non-source return required' is checked then only default
3049            the return by date. This date will be passed to charges in
3050            Installed_cp_return_by_date or in New_cp_return_by_date
3051            based on source or non-source setup in procedure Convert_to_Chg_rec
3052          */
3053         l_src_return_reqd     :='N';
3054         l_non_src_return_reqd :='N';
3055         open c2( l_cps_txn_billing_type_id );
3056         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
3057         If (c2%ISOPEN) then
3058           Close c2;
3059         END IF;
3060         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
3061           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
3062         else
3063           x_prod_txn_tbl(l_index).return_by_date              := NULL;
3064         end if;
3065 
3066         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
3067         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
3068         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
3069         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
3070         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
3071         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
3072         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
3073         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
3074         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
3075         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
3076         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
3077         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
3078         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
3079         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
3080         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
3081         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
3082         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
3083         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
3084         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
3085         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
3086         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
3087         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
3088         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
3089         x_prod_txn_tbl(l_index).prod_txn_code               := 'POST';
3090         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
3091         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
3092         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
3093 
3094         -- picking rule changes for R12
3095         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
3096         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
3097         --------------------------------
3098 
3099 		--bug#11769559
3100 		If (l_default_logistics_warehouse = 'Y') Then
3101 
3102 			l_attr_code := 'SHIP_FROM_ORG';
3103 			l_default_val_num := null;
3104 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3105 			  p_api_version_number    => 1.0,
3106 			  p_init_msg_list         => FND_API.G_TRUE,
3107 			  p_commit                => FND_API.G_FALSE, --bug#12588243
3108 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3109 			  p_entity_attribute_type => l_attr_type,
3110 			  p_entity_attribute_code => l_attr_code,
3111 			  p_rule_input_rec        => l_rule_input_rec,
3112 			  x_default_value         => l_default_val_num,
3113 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3114 			  x_return_status         => l_return_status,
3115 			  x_msg_count             => l_msg_count,
3116 			  x_msg_data              => l_msg_data
3117 			);
3118 			if (l_default_val_num is not null) then
3119 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
3120 			else
3121 				-- Inv_org Change, Vijay , 20/3/2006
3122 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
3123 			end if;
3124 		end if;
3125 		--bug#11769559
3126 
3127         IF p_invoice_to_org_id IS NOT NULL
3128         THEN
3129             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
3130         END IF;
3131 
3132         IF p_ship_to_org_id IS NOT NULL
3133         THEN
3134             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
3135         END IF;
3136 
3137         l_index := l_index + 1;
3138 
3139     end if;
3140 
3141     if (l_lr_txn_billing_type_id is not null) then
3142 
3143         -- Receive loaner product txn line
3144         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
3145         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
3146         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
3147         x_prod_txn_tbl(l_index).action_code                 := 'LOANER'          ;
3148         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
3149         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_lr_txn_billing_type_id;
3150         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
3151        IF l_repair_type_ref = 'WRL' THEN
3152         x_prod_txn_tbl(l_index).action_type                 := 'WALK_IN_RECEIPT'   ;
3153        ELSE
3154         x_prod_txn_tbl(l_index).action_type                 := 'RMA'            ;
3155        END IF;
3156 
3157         --bug#3875036 Bug 8694111
3158         IF((l_enable_advanced_pricing ='Y')and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
3159            x_prod_txn_tbl(l_index).after_warranty_cost	    := -l_selling_price;
3160         End if;
3161 
3162 
3163         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
3164         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
3165         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
3166         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
3167         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id    ;
3168         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
3169         x_prod_txn_tbl(l_index).quantity                    := p_quantity       ;
3170         -- Fix for bug#3704155
3171         --x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number;
3172         x_prod_txn_tbl(l_index).source_serial_number        := FND_API.G_MISS_CHAR;
3173         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
3174         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number       ;  -- yvchen: bug#13582572
3175         -- Fix for bug#3704155
3176         --x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id    ;
3177         x_prod_txn_tbl(l_index).source_instance_id          := FND_API.G_MISS_NUM;
3178         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
3179         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id  ;
3180      -- R12 contract changes
3181         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
3182         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id    ;
3183         x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
3184         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_lr_txn_billing_type_id);
3185         x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
3186         x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
3187         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
3188         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
3189         x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
3190         x_prod_txn_tbl(l_index).return_reason               := l_return_reason;
3191         -- x_prod_txn_tbl(l_index).return_by_date           := sysdate          ;
3192         /* Fixed for FP bug#5408047
3193            For RMA line if source return is required then only
3194            default the return by date. This date will be passed to
3195            charges in Installed_cp_return_by_date.
3196          */
3197         l_src_return_reqd     :='N';
3198         l_non_src_return_reqd :='N';
3199         open c2( l_lr_txn_billing_type_id );
3200         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
3201         If (c2%ISOPEN) then
3202           Close c2;
3203         END IF;
3204         If l_src_return_reqd ='Y' then
3205           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
3206         else
3207           x_prod_txn_tbl(l_index).return_by_date              := NULL         ;
3208         end if;
3209 
3210         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
3211         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
3212         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
3213         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
3214         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
3215         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
3216         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
3217         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
3218         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
3219         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
3220         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
3221         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
3222         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
3223         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
3224         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
3225         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
3226         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
3227         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
3228         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
3229         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
3230         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
3231         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
3232         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
3233         x_prod_txn_tbl(l_index).prod_txn_code               := 'POST';
3234         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
3235         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
3236         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
3237 
3238 		--bug#11769559
3239 		If (l_default_logistics_warehouse = 'Y') Then
3240 
3241 			l_attr_code := 'RMA_RCV_ORG';
3242 			l_default_val_num := null;
3243 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3244 			  p_api_version_number    => 1.0,
3245 			  p_init_msg_list         => FND_API.G_TRUE,
3246 			  p_commit                => FND_API.G_FALSE, --bug#12588243
3247 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3248 			  p_entity_attribute_type => l_attr_type,
3249 			  p_entity_attribute_code => l_attr_code,
3250 			  p_rule_input_rec        => l_rule_input_rec,
3251 			  x_default_value         => l_default_val_num,
3252 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3253 			  x_return_status         => l_return_status,
3254 			  x_msg_count             => l_msg_count,
3255 			  x_msg_data              => l_msg_data
3256 			);
3257 			if (l_default_val_num is not null) then
3258 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
3259 			else
3260 				-- Inv_org Change, Vijay , 20/3/2006
3261 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
3262 			end if;
3263 		end if;
3264 		--bug#11769559
3265 
3266         ---------------------------------------
3267         --Bug fix 5494219 Begin
3268   		l_attr_code := 'RMA_RCV_SUBINV';
3269         l_default_val_char := null;
3270         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3271           p_api_version_number    => 1.0,
3272           p_init_msg_list         => FND_API.G_TRUE,
3273           p_commit                => FND_API.G_FALSE, --bug#12588243
3274           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3275           p_entity_attribute_type => l_attr_type,
3276           p_entity_attribute_code => l_attr_code,
3277           p_rule_input_rec        => l_rule_input_rec,
3278           x_default_value         => l_default_val_char,
3279           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3280           x_return_status         => l_return_status,
3281           x_msg_count             => l_msg_count,
3282           x_msg_data              => l_msg_data
3283         );
3284         if (l_default_val_char is not null) then
3285             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
3286         else
3287             x_prod_txn_tbl(l_index).sub_inventory  := l_sub_inv;
3288         end if;
3289 
3290         IF p_invoice_to_org_id IS NOT NULL
3291         THEN
3292             x_prod_txn_tbl(l_index).invoice_to_org_id := p_invoice_to_org_id;
3293         END IF;
3294 
3295         IF p_ship_to_org_id IS NOT NULL
3296         THEN
3297             x_prod_txn_tbl(l_index).ship_to_org_id    := p_ship_to_org_id;
3298         END IF;
3299 
3300         l_index := l_index + 1;
3301 
3302     end if;
3303 
3304   END IF;
3305 
3306 
3307   IF NVL(l_third_party_flag, 'N') = 'Y' or (p_create_thirdpty_line = 'T') THEN
3308 
3309     if (l_third_ship_txn_b_type_id is not null) then
3310 
3311         -- Shipping customer product txn line
3312         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
3313         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
3314         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
3315         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
3316         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_third_ship_txn_b_type_id;
3317         x_prod_txn_tbl(l_index).po_number                   := l_po_number; -- swai bug fix 4535829
3318 
3319         x_prod_txn_tbl(l_index).action_code                := 'CUST_PROD';
3320         x_prod_txn_tbl(l_index).non_source_instance_id     := FND_API.G_MISS_NUM;
3321         x_prod_txn_tbl(l_index).non_source_serial_number   := FND_API.G_MISS_CHAR;
3322 
3323         -- Fix for bug# 3549430
3324         if (l_serial_num_control_code = 1 and l_ib_flag = 'Y') then
3325             x_prod_txn_tbl(l_index).source_instance_id         := FND_API.G_MISS_NUM;
3326             x_prod_txn_tbl(l_index).source_serial_number       := FND_API.G_MISS_CHAR;
3327         else
3328             x_prod_txn_tbl(l_index).source_instance_id         := p_instance_id;
3329             x_prod_txn_tbl(l_index).source_serial_number       := p_serial_number;
3330         end if;
3331 
3332         x_prod_txn_tbl(l_index).action_type                 := 'SHIP_THIRD_PTY'           ;
3333 
3334         --bug#3875036 bug 8694111
3335 	IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
3336           x_prod_txn_tbl(l_index).after_warranty_cost	    := l_selling_price;
3337 	End if;
3338 
3339         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
3340         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
3341         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
3342         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
3343         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
3344         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
3345         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
3346         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
3347         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
3348      -- R12 contract changes
3349         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
3350         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
3351 --        x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
3352 		l_attr_code := 'SHIP_FROM_SUBINV';
3353         l_default_val_char := null;
3354         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3355           p_api_version_number    => 1.0,
3356           p_init_msg_list         => FND_API.G_TRUE,
3357           p_commit                => FND_API.G_FALSE, --bug#12588243
3358           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3359           p_entity_attribute_type => l_attr_type,
3360           p_entity_attribute_code => l_attr_code,
3361           p_rule_input_rec        => l_rule_input_rec,
3362           x_default_value         => l_default_val_char,
3363           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3364           x_return_status         => l_return_status,
3365           x_msg_count             => l_msg_count,
3366           x_msg_data              => l_msg_data
3367         );
3368         if (l_default_val_char is not null) then
3369             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
3370         else
3371             x_prod_txn_tbl(l_index).sub_inventory  := FND_API.G_MISS_CHAR;
3372         end if;
3373 
3374         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_third_ship_txn_b_type_id);
3375         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N'               ;
3376         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N'               ;
3377 
3378 --bug#12888392  --14120502
3379 /*
3380         IF NVL(l_interface_to_om_flag, 'N') = 'Y' THEN
3381           x_prod_txn_tbl(l_index).process_txn_flag           := 'Y';
3382           if NVL(l_book_sales_order_flag, 'N') = 'Y' THEN
3383              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
3384              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'Y';
3385           else
3386              x_prod_txn_tbl(l_index).interface_to_om_flag    := 'Y';
3387              x_prod_txn_tbl(l_index).book_sales_order_flag   := 'N';
3388           end if;
3389 
3390   	      if(l_add_ship_to_id is null) THEN
3391 	         x_prod_txn_tbl(l_index).new_order_flag := 'Y';
3392 	      ELSE
3393 		     x_prod_txn_tbl(l_index).new_order_flag := 'N';
3394 		     x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
3395 		     x_prod_txn_tbl(l_index).add_to_order_id := l_add_ship_to_id;
3396 	      END IF;
3397         Else
3398            x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
3399            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
3400            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
3401         End if;
3402   */
3403   --bug#12888392 --14120502
3404 
3405 		   x_prod_txn_tbl(l_index).process_txn_flag            := 'N'               ;
3406 		   x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N'               ;
3407 		   x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N'               ;
3408   --bug#12888392 --14120502
3409 
3410         x_prod_txn_tbl(l_index).return_reason               := FND_API.G_MISS_CHAR;
3411         -- x_prod_txn_tbl(l_index).return_by_date           := FND_API.G_MISS_DATE;
3412         /* Fixed for FP bug#5408047
3413            For SHIP line if either of 'source return is required'
3414            or 'non-source return required' is checked then only default
3415            the return by date. This date will be passed to charges in
3416            Installed_cp_return_by_date or in New_cp_return_by_date
3417            based on source or non-source setup in procedure Convert_to_Chg_rec
3418          */
3419         l_src_return_reqd:='N';
3420         l_non_src_return_reqd:='N';
3421         open c2( l_third_ship_txn_b_type_id );
3422         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
3423         If (c2%ISOPEN) then
3424           Close c2;
3425         END IF;
3426 
3427         If l_src_return_reqd ='Y' or l_non_src_return_reqd ='Y' then
3428           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
3429         ELSE
3430           x_prod_txn_tbl(l_index).return_by_date              := NULL;
3431         END IF;
3432         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
3433         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
3434         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
3435         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
3436         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
3437         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
3438         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
3439         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
3440         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
3441         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
3442         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
3443         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
3444         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
3445         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
3446         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
3447         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
3448         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
3449         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
3450         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
3451         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
3452         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
3453         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
3454         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
3455         x_prod_txn_tbl(l_index).prod_txn_code               := 'POST';
3456         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
3457         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
3458         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
3459 
3460         -- picking rule changes for R12
3461         Fnd_Profile.Get('CSD_DEF_PICK_RELEASE_RULE',l_picking_rule_id);
3462         x_prod_txn_tbl(l_index).picking_rule_id  := l_picking_rule_id;
3463         --------------------------------
3464 
3465 		--bug#11769559
3466 		If (l_default_logistics_warehouse = 'Y') Then
3467 
3468 			l_attr_code := 'SHIP_FROM_ORG';
3469 			l_default_val_num := null;
3470 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3471 			  p_api_version_number    => 1.0,
3472 			  p_init_msg_list         => FND_API.G_TRUE,
3473 			  p_commit                => FND_API.G_FALSE, --bug#12588243
3474 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3475 			  p_entity_attribute_type => l_attr_type,
3476 			  p_entity_attribute_code => l_attr_code,
3477 			  p_rule_input_rec        => l_rule_input_rec,
3478 			  x_default_value         => l_default_val_num,
3479 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3480 			  x_return_status         => l_return_status,
3481 			  x_msg_count             => l_msg_count,
3482 			  x_msg_data              => l_msg_data
3483 			);
3484 			if (l_default_val_num is not null) then
3485 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
3486 			else
3487 				-- Inv_org Change, Vijay , 20/3/2006
3488 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
3489 			end if;
3490 		end if;
3491 		--bug#11769559
3492 
3493 		l_attr_code := 'VENDOR_ACCOUNT';
3494         l_default_val_num := null;
3495         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3496           p_api_version_number    => 1.0,
3497           p_init_msg_list         => FND_API.G_TRUE,
3498           p_commit                => FND_API.G_FALSE, --bug#12588243
3499           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3500           p_entity_attribute_type => l_attr_type,
3501           p_entity_attribute_code => l_attr_code,
3502           p_rule_input_rec        => l_rule_input_rec,
3503           x_default_value         => l_default_val_num,
3504           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3505           x_return_status         => l_return_status,
3506           x_msg_count             => l_msg_count,
3507           x_msg_data              => l_msg_data
3508         );
3509         if (l_default_val_num is not null) then
3510             x_prod_txn_tbl(l_index).bill_to_account_id  := l_default_val_num;
3511             select party_id
3512             into x_prod_txn_tbl(l_index).bill_to_party_id
3513             from hz_cust_accounts
3514             where cust_account_id = l_default_val_num;
3515 
3516             -- swai: bug 6936769
3517             -- default account primary bill-to
3518             OPEN c_primary_account_address (x_prod_txn_tbl(l_index).bill_to_party_id,
3519                             x_prod_txn_tbl(l_index).bill_to_account_id,
3520                             x_prod_txn_tbl(l_index).organization_id,
3521                             'BILL_TO');
3522             FETCH c_primary_account_address INTO x_prod_txn_tbl(l_index).invoice_to_org_id;
3523             IF c_primary_account_address%ISOPEN THEN
3524                 CLOSE c_primary_account_address;
3525             END IF;
3526 
3527             -- default account primary ship-to
3528             OPEN c_primary_account_address (x_prod_txn_tbl(l_index).bill_to_party_id,
3529                             x_prod_txn_tbl(l_index).bill_to_account_id,
3530                             x_prod_txn_tbl(l_index).organization_id,
3531                             'SHIP_TO');
3532             FETCH c_primary_account_address INTO x_prod_txn_tbl(l_index).ship_to_org_id;
3533             IF c_primary_account_address%ISOPEN THEN
3534                 CLOSE c_primary_account_address;
3535             END IF;
3536             -- end swai: bug 6936769
3537         end if;
3538 
3539         ---------------------------------------
3540         l_index:= l_index + 1;
3541     end if;
3542 
3543     if (l_third_rma_txn_b_type_id is not null) then
3544 
3545         -- receive customer product txn line
3546         x_prod_txn_tbl(l_index).product_transaction_id      := FND_API.G_MISS_NUM;
3547         x_prod_txn_tbl(l_index).repair_line_id              := p_repair_line_id  ;
3548         x_prod_txn_tbl(l_index).estimate_detail_id          := FND_API.G_MISS_NUM;
3549         x_prod_txn_tbl(l_index).line_category_code          := FND_API.G_MISS_CHAR;
3550         x_prod_txn_tbl(l_index).txn_billing_type_id         := l_third_rma_txn_b_type_id;
3551         x_prod_txn_tbl(l_index).po_number                   := l_po_number;  -- swai bug fix 4535829
3552 
3553          x_prod_txn_tbl(l_index).action_code                 := 'CUST_PROD';
3554          x_prod_txn_tbl(l_index).action_type                 := 'RMA_THIRD_PTY'             ;
3555 
3556         --bug#3875036 Bug 8694111
3557 	IF((l_enable_advanced_pricing ='Y') and (x_prod_txn_tbl(l_index).no_charge_flag ='N')) THEN
3558           x_prod_txn_tbl(l_index).after_warranty_cost	     := -l_selling_price;
3559 	End If;
3560 
3561         -- x_prod_txn_tbl(l_index).serial_number            := l_serial_number   ;
3562         -- x_prod_txn_tbl(l_index).instance_id              := l_instance_id     ;
3563         x_prod_txn_tbl(l_index).source_serial_number        := p_serial_number   ;
3564         x_prod_txn_tbl(l_index).source_instance_id          := p_instance_id     ;
3565         x_prod_txn_tbl(l_index).non_source_serial_number    := FND_API.G_MISS_CHAR;
3566         x_prod_txn_tbl(l_index).non_source_instance_id      := FND_API.G_MISS_NUM;
3567         x_prod_txn_tbl(l_index).organization_id             := l_org_id          ;
3568         x_prod_txn_tbl(l_index).business_process_id         := l_bus_process_id ;
3569         x_prod_txn_tbl(l_index).order_number                := FND_API.G_MISS_CHAR;
3570         x_prod_txn_tbl(l_index).status                      := FND_API.G_MISS_CHAR;
3571         x_prod_txn_tbl(l_index).inventory_item_id           := l_inv_item_id     ;
3572         x_prod_txn_tbl(l_index).unit_of_measure_code        := l_unit_of_measure ;
3573         x_prod_txn_tbl(l_index).quantity                    := p_quantity        ;
3574         x_prod_txn_tbl(l_index).lot_number                  := l_lot_number      ;  -- yvchen: bug#13582572
3575         x_prod_txn_tbl(l_index).price_list_id               := l_price_list_id   ;
3576         x_prod_txn_tbl(l_index).contract_id                 := l_contract_id     ;
3577      -- R12 contract changes
3578         x_prod_txn_tbl(l_index).contract_line_id            := l_contract_line_id    ;
3579         x_prod_txn_tbl(l_index).sub_inventory               := FND_API.G_MISS_CHAR;
3580         x_prod_txn_tbl(l_index).no_charge_flag              := csd_process_util.get_no_chg_flag(l_third_rma_txn_b_type_id) ;
3581         x_prod_txn_tbl(l_index).release_sales_order_flag    := 'N' ;
3582         x_prod_txn_tbl(l_index).ship_sales_order_flag       := 'N' ;
3583 
3584         -- auto process the RMA for the customer
3585         -- product txn line only
3586         -- Following line commented by vkjain to fix 3353445
3587         -- It adds support of 'Auto Enter and Book' RMA.
3588         -- IF x_prod_txn_tbl(l_index).action_code = 'CUST_PROD' and
3589 
3590 --bug#12888392   --bug#14120502
3591 /*
3592         IF NVL(l_auto_process_rma, 'N') = 'Y' THEN
3593            x_prod_txn_tbl(l_index).process_txn_flag            := 'Y' ;
3594            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'Y' ;
3595            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'Y' ;
3596            -- bug fix for 4108369, Begin
3597            if(l_add_rma_to_id is null) THEN
3598              x_prod_txn_tbl(l_index).new_order_flag := 'Y';
3599            ELSE
3600              x_prod_txn_tbl(l_index).new_order_flag := 'N';
3601              x_prod_txn_tbl(l_index).add_to_order_flag := 'Y';
3602              x_prod_txn_tbl(l_index).add_to_order_id := l_add_rma_to_id;
3603            END IF;
3604            -- bug fix for 4108369, End
3605         ELSE
3606            x_prod_txn_tbl(l_index).process_txn_flag            := 'N' ;
3607            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N' ;
3608            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N' ;
3609         END IF;
3610 */
3611 --bug#12888392  --bug#14120502
3612 
3613            x_prod_txn_tbl(l_index).process_txn_flag            := 'N' ;
3614            x_prod_txn_tbl(l_index).interface_to_om_flag        := 'N' ;
3615            x_prod_txn_tbl(l_index).book_sales_order_flag       := 'N' ;
3616 
3617 --bug#12888392   --bug#14120502
3618 
3619 
3620         x_prod_txn_tbl(l_index).return_reason               := l_return_reason  ;
3621         -- x_prod_txn_tbl(l_index).return_by_date           := sysdate          ;
3622         /* Fixed for FP bug#5408047
3623           For RMA line if source return is required then only
3624           default the return by date. This date will be passed to
3625           charges in Installed_cp_return_by_date.
3626         */
3627         l_src_return_reqd      :='N';
3628         l_non_src_return_reqd  :='N';
3629         open c2( l_third_rma_txn_b_type_id );
3630         fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
3631         If (c2%ISOPEN) then
3632           Close c2;
3633         END IF;
3634         If l_src_return_reqd ='Y' then
3635           x_prod_txn_tbl(l_index).return_by_date              := sysdate+l_return_days;
3636         ELSE
3637            x_prod_txn_tbl(l_index).return_by_date              := NULL          ;
3638         END IF;
3639 
3640         x_prod_txn_tbl(l_index).revision                    := l_revision       ;
3641         x_prod_txn_tbl(l_index).last_update_date            := sysdate          ;
3642         x_prod_txn_tbl(l_index).creation_date               := sysdate          ;
3643         x_prod_txn_tbl(l_index).last_updated_by             := FND_GLOBAL.USER_ID;
3644         x_prod_txn_tbl(l_index).created_by                  := FND_GLOBAL.USER_ID;
3645         x_prod_txn_tbl(l_index).last_update_login           := FND_GLOBAL.USER_ID;
3646         x_prod_txn_tbl(l_index).attribute1                  := FND_API.G_MISS_CHAR;
3647         x_prod_txn_tbl(l_index).attribute2                  := FND_API.G_MISS_CHAR;
3648         x_prod_txn_tbl(l_index).attribute3                  := FND_API.G_MISS_CHAR;
3649         x_prod_txn_tbl(l_index).attribute4                  := FND_API.G_MISS_CHAR;
3650         x_prod_txn_tbl(l_index).attribute5                  := FND_API.G_MISS_CHAR;
3651         x_prod_txn_tbl(l_index).attribute6                  := FND_API.G_MISS_CHAR;
3652         x_prod_txn_tbl(l_index).attribute7                  := FND_API.G_MISS_CHAR;
3653         x_prod_txn_tbl(l_index).attribute8                  := FND_API.G_MISS_CHAR;
3654         x_prod_txn_tbl(l_index).attribute9                  := FND_API.G_MISS_CHAR;
3655         x_prod_txn_tbl(l_index).attribute10                 := FND_API.G_MISS_CHAR;
3656         x_prod_txn_tbl(l_index).attribute11                 := FND_API.G_MISS_CHAR;
3657         x_prod_txn_tbl(l_index).attribute12                 := FND_API.G_MISS_CHAR;
3658         x_prod_txn_tbl(l_index).attribute13                 := FND_API.G_MISS_CHAR;
3659         x_prod_txn_tbl(l_index).attribute14                 := FND_API.G_MISS_CHAR;
3660         x_prod_txn_tbl(l_index).attribute15                 := FND_API.G_MISS_CHAR;
3661         x_prod_txn_tbl(l_index).context                     := FND_API.G_MISS_CHAR;
3662         x_prod_txn_tbl(l_index).prod_txn_status             := 'ENTERED';
3663         x_prod_txn_tbl(l_index).prod_txn_code               := 'PRE';
3664         x_prod_txn_tbl(l_index).project_id                  := l_project_id;
3665         x_prod_txn_tbl(l_index).task_id                     := l_task_id;
3666         x_prod_txn_tbl(l_index).unit_number                 := l_unit_number;
3667 
3668 		--bug#11769559
3669 		If (l_default_logistics_warehouse = 'Y') Then
3670 
3671 			l_attr_code := 'RMA_RCV_ORG';
3672 			l_default_val_num := null;
3673 			CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3674 			  p_api_version_number    => 1.0,
3675 			  p_init_msg_list         => FND_API.G_TRUE,
3676 			  p_commit                => FND_API.G_FALSE, --bug#12588243
3677 			  p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3678 			  p_entity_attribute_type => l_attr_type,
3679 			  p_entity_attribute_code => l_attr_code,
3680 			  p_rule_input_rec        => l_rule_input_rec,
3681 			  x_default_value         => l_default_val_num,
3682 			  x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3683 			  x_return_status         => l_return_status,
3684 			  x_msg_count             => l_msg_count,
3685 			  x_msg_data              => l_msg_data
3686 			);
3687 			if (l_default_val_num is not null) then
3688 				x_prod_txn_tbl(l_index).inventory_org_id  := l_default_val_num;
3689 			else
3690 				-- Inv_org Change, Vijay , 20/3/2006
3691 				x_prod_txn_tbl(l_index).inventory_org_id  := l_inv_org_id;
3692 			end if;
3693 		end if;
3694 		--bug#11769559
3695 
3696         ---------------------------------------
3697         --Bug fix 5494219 Begin
3698 		l_attr_code := 'RMA_RCV_SUBINV';
3699         l_default_val_char := null;
3700         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3701           p_api_version_number    => 1.0,
3702           p_init_msg_list         => FND_API.G_TRUE,
3703           p_commit                => FND_API.G_FALSE, --bug#12588243
3704           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3705           p_entity_attribute_type => l_attr_type,
3706           p_entity_attribute_code => l_attr_code,
3707           p_rule_input_rec        => l_rule_input_rec,
3708           x_default_value         => l_default_val_char,
3709           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3710           x_return_status         => l_return_status,
3711           x_msg_count             => l_msg_count,
3712           x_msg_data              => l_msg_data
3713         );
3714         if (l_default_val_char is not null) then
3715             x_prod_txn_tbl(l_index).sub_inventory  := l_default_val_char;
3716         else
3717             x_prod_txn_tbl(l_index).sub_inventory  := l_sub_inv;
3718         end if;
3719 
3720 
3721 		l_attr_code := 'VENDOR_ACCOUNT';
3722         l_default_val_num := null;
3723         CSD_RULES_ENGINE_PVT.GET_DEFAULT_VALUE_FROM_RULE (
3724           p_api_version_number    => 1.0,
3725           p_init_msg_list         => FND_API.G_TRUE,
3726           p_commit                => FND_API.G_FALSE, --bug#12588243
3727           p_validation_level      => FND_API.G_VALID_LEVEL_FULL,
3728           p_entity_attribute_type => l_attr_type,
3729           p_entity_attribute_code => l_attr_code,
3730           p_rule_input_rec        => l_rule_input_rec,
3731           x_default_value         => l_default_val_num,
3732           x_rule_id               => l_default_rule_id, -- swai: 12.1.1 ER 7233924
3733           x_return_status         => l_return_status,
3734           x_msg_count             => l_msg_count,
3735           x_msg_data              => l_msg_data
3736         );
3737         if (l_default_val_num is not null) then
3738             x_prod_txn_tbl(l_index).bill_to_account_id  := l_default_val_num;
3739             select party_id
3740             into x_prod_txn_tbl(l_index).bill_to_party_id
3741             from hz_cust_accounts
3742             where cust_account_id = l_default_val_num;
3743 
3744             -- swai: bug 6936769
3745             -- default account primary bill-to
3746             OPEN c_primary_account_address (x_prod_txn_tbl(l_index).bill_to_party_id,
3747                             x_prod_txn_tbl(l_index).bill_to_account_id,
3748                             x_prod_txn_tbl(l_index).organization_id,
3749                             'BILL_TO');
3750             FETCH c_primary_account_address INTO x_prod_txn_tbl(l_index).invoice_to_org_id;
3751             IF c_primary_account_address%ISOPEN THEN
3752                 CLOSE c_primary_account_address;
3753             END IF;
3754 
3755             -- default account primary ship-to
3756             OPEN c_primary_account_address (x_prod_txn_tbl(l_index).bill_to_party_id,
3757                             x_prod_txn_tbl(l_index).bill_to_account_id,
3758                             x_prod_txn_tbl(l_index).organization_id,
3759                             'SHIP_TO');
3760             FETCH c_primary_account_address INTO x_prod_txn_tbl(l_index).ship_to_org_id;
3761             IF c_primary_account_address%ISOPEN THEN
3762                 CLOSE c_primary_account_address;
3763             END IF;
3764             -- end swai: bug 6936769
3765         end if;
3766 
3767     end if;
3768 
3769   end if;  --end l_third_party_flag
3770 
3771 
3772 EXCEPTION
3773     WHEN FND_API.G_EXC_ERROR THEN
3774           x_return_status := FND_API.G_RET_STS_ERROR ;
3775     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3776           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3777     WHEN OTHERS THEN
3778           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3779 END build_prodtxn_tbl_int;
3780 
3781 /**************************************
3782 This procedure calls the internal api to build the product txn table.
3783 ***************************************/
3784 PROCEDURE build_prod_txn_tbl
3785 ( p_repair_line_id     IN	NUMBER,
3786   p_create_thirdpty_line IN VARCHAR2 := fnd_api.g_false,
3787   p_return_reason_code IN VARCHAR2   := NULL,
3788   p_invoice_to_org_id  IN NUMBER     := NULL,
3789   p_ship_to_org_id     IN NUMBER     := NULL,
3790   x_prod_txn_tbl       OUT NOCOPY	csd_process_pvt.product_txn_tbl,
3791   x_return_status      OUT NOCOPY	VARCHAR2
3792  ) IS
3793   CURSOR cur_Srl_num_Dtls (p_rep_line_id IN NUMBER) IS
3794   SELECT
3795     quantity,
3796     customer_product_id,
3797     serial_number
3798   FROM csd_repairs
3799   where repair_line_id = p_rep_line_id;
3800  BEGIN
3801 
3802       FOR l_srl_num_rec in  cur_srl_num_dtls(p_Repair_line_id) LOOP
3803           build_prodtxn_tbl_int(p_Repair_line_id => p_repair_line_id,
3804                                 p_quantity       => l_Srl_num_rec.quantity,
3805                                 p_serial_number  => l_Srl_num_rec.serial_number,
3806                                 p_instance_id    => l_srl_num_rec.customer_product_id,
3807 								p_create_thirdpty_line => p_create_thirdpty_line,
3808                                 x_prod_txn_tbl   => x_prod_txn_tbl,
3809                                 x_return_status  => x_return_status,
3810                                 p_return_reason_code => p_return_reason_code,
3811                                 p_invoice_to_org_id => p_invoice_to_org_id,
3812                                 p_ship_to_org_id    => p_ship_to_org_id);
3813       END LOOP;
3814 
3815 
3816  END build_prod_txn_tbl;
3817 
3818 
3819 
3820 FUNCTION validate_rep_line_id
3821 ( p_repair_line_id  IN	NUMBER
3822  ) RETURN BOOLEAN
3823 
3824  IS
3825 
3826 l_dummy VARCHAR2(1);
3827 
3828 BEGIN
3829 
3830  select 'X'
3831  into l_dummy
3832  from csd_repairs
3833  where repair_line_id = p_repair_line_id;
3834 --bug#6681781, this is not valid validation for repair line id, don't need the last condition
3835 -- and   ((date_closed is null) or (trunc(date_closed) >= trunc(sysdate)));
3836 
3837  RETURN TRUE;
3838 
3839 EXCEPTION
3840 When NO_DATA_FOUND then
3841     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_REP_LINE_ID');
3842     FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
3843     FND_MSG_PUB.Add;
3844     RETURN FALSE;
3845 END Validate_rep_line_id;
3846 
3847 FUNCTION validate_estimate_id
3848 ( p_estimate_id  IN	NUMBER
3849  ) RETURN BOOLEAN
3850 
3851  IS
3852 
3853 l_dummy VARCHAR2(1);
3854 
3855 BEGIN
3856 
3857  select 'X'
3858  into l_dummy
3859  from csd_repair_estimate
3860  where repair_estimate_id = p_estimate_id;
3861 
3862  RETURN TRUE;
3863 
3864 EXCEPTION
3865 When NO_DATA_FOUND then
3866     FND_MESSAGE.SET_NAME('CSD','CSD_INV_ESTIMATE_ID');
3867     FND_MESSAGE.SET_TOKEN('REPAIR_ESTIMATE_ID',p_estimate_id);
3868     FND_MSG_PUB.Add;
3869     RETURN FALSE;
3870 END Validate_estimate_id;
3871 
3872 FUNCTION validate_estimate_line_id
3873 ( p_estimate_line_id  IN	NUMBER
3874  ) RETURN BOOLEAN
3875 
3876  IS
3877 
3878 l_dummy VARCHAR2(1);
3879 
3880 BEGIN
3881 
3882  select 'X'
3883  into l_dummy
3884  from csd_repair_estimate_lines
3885  where repair_estimate_line_id = p_estimate_line_id;
3886 
3887  RETURN TRUE;
3888 
3889 EXCEPTION
3890 When NO_DATA_FOUND then
3891     FND_MESSAGE.SET_NAME('CSD','CSD_INV_ESTIMATE_ID');
3892     FND_MESSAGE.SET_TOKEN('REPAIR_ESTIMATE_LINE_ID',p_estimate_line_id);
3893     FND_MSG_PUB.Add;
3894     RETURN FALSE;
3895 END Validate_estimate_line_id;
3896 
3897 FUNCTION Validate_action_type
3898 ( p_action_type     IN VARCHAR2
3899  ) RETURN BOOLEAN
3900  IS
3901   l_dummy VARCHAR2(1);
3902 BEGIN
3903  select 'X'
3904  into l_dummy
3905  from  fnd_lookups
3906  where lookup_type = 'CSD_PROD_ACTION_TYPE'
3907   and  lookup_code = p_action_type;
3908  RETURN TRUE;
3909 EXCEPTION
3910 When NO_DATA_FOUND then
3911     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ACTION_TYPE');
3912     FND_MESSAGE.SET_TOKEN('ACTION_TYPE',p_action_type);
3913     FND_MSG_PUB.Add;
3914     RETURN FALSE;
3915 END Validate_action_type;
3916 
3917 
3918 FUNCTION Validate_action_code
3919 ( p_action_code     IN VARCHAR2
3920  ) RETURN BOOLEAN
3921  IS
3922  l_dummy VARCHAR2(1);
3923 BEGIN
3924  select 'X'
3925  into l_dummy
3926  from  fnd_lookups
3927  where lookup_type = 'CSD_PRODUCT_ACTION_CODE'
3928   and  lookup_code = p_action_code;
3929  RETURN TRUE;
3930 EXCEPTION
3931 When NO_DATA_FOUND then
3932     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ACTION_CODE');
3933     FND_MESSAGE.SET_TOKEN('ACTION_CODE',p_action_code);
3934     FND_MSG_PUB.Add;
3935     RETURN FALSE;
3936 END Validate_action_code;
3937 
3938 --Sangita changes - shirkol
3939 FUNCTION get_inv_org_id RETURN NUMBER
3940  IS
3941    l_inv_org_id   NUMBER;
3942    BEGIN
3943 
3944 	l_inv_org_id := cs_std.get_item_valdn_orgzn_id;
3945 
3946 	  RETURN l_inv_org_id;
3947 
3948 	  END;
3949 
3950 --sangita Chanegs shirkol
3951 /*
3952 
3953 FUNCTION get_org_id
3954 ( p_repair_line_id  IN	NUMBER
3955  ) RETURN NUMBER
3956  IS
3957   l_org_id NUMBER;
3958 BEGIN
3959 
3960  select b.org_id
3961  into l_org_id
3962  from csd_repairs a,
3963       cs_incidents_all_b b
3964  where a.incident_id    = b.incident_id
3965   and  a.repair_line_id = p_repair_line_id;
3966 
3967  RETURN l_org_id;
3968 EXCEPTION
3969 When NO_DATA_FOUND then
3970     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_REP_LINE_ID');
3971     FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
3972     FND_MSG_PUB.Add;
3973     RETURN -1;
3974 END get_org_id;
3975 */
3976 
3977 --sangita chanegs shirkol
3978 FUNCTION get_org_id
3979 ( p_incident_id  IN NUMBER
3980  ) RETURN NUMBER
3981   IS
3982 
3983    l_org_id         NUMBER;
3984     l_return_status  VARCHAR2(1);
3985 	l_msg_count      NUMBER;
3986 	 l_msg_data       VARCHAR2(2000);
3987 	  l_profile        VARCHAR2(3);
3988 
3989 	  BEGIN
3990 
3991 	   IF Is_MultiOrg_Enabled THEN
3992 
3993 		 CS_MultiOrg_Pub.Get_OrgId(  -- swai change to use pub instead of pvt
3994 			 p_api_version   => 1.0, -- swai change to version 1.0
3995 			 p_init_msg_list => 'F',
3996              p_commit           => FND_API.G_FALSE,  -- swai added
3997              p_validation_level => null,             -- swai added
3998 			 x_return_status => l_return_status,
3999  			 x_msg_count     => l_msg_count,
4000 			 x_msg_data      => l_msg_data,
4001              p_incident_id   => p_incident_id,
4002 			 x_org_id        => l_org_id,
4003 			 x_profile       => l_profile);
4004 
4005 			if( l_return_status <> csd_process_util.g_ret_sts_success) then
4006 				csd_gen_utility_pvt.add('Error in deriving the Org id ');
4007 		   end if;
4008 
4009 			 ELSE
4010 			 ------------------------------------------------------
4011 			  -- If not Multiorg derive org from MO operating Unit
4012 			------------------------------------------------------
4013 
4014 				  FND_PROFILE.Get('ORG_ID', l_org_id);
4015 
4016 			   END IF;
4017 			 RETURN l_org_id;
4018 
4019 			 EXCEPTION
4020 			   When NO_DATA_FOUND then
4021 
4022 				 FND_MESSAGE.SET_NAME('CSD','CSD_INVALID_INCIDENT_ID');
4023 				 FND_MSG_PUB.Add;
4024 	    			RETURN -1;
4025  END get_org_id;
4026 
4027 
4028 FUNCTION get_estimate
4029 (
4030   p_repair_line_id IN	NUMBER,
4031   p_code           IN    VARCHAR2
4032  ) RETURN NUMBER
4033 
4034  IS
4035 
4036   l_amount NUMBER := 0;
4037 
4038 BEGIN
4039 
4040 IF p_code = 'M' then
4041 
4042 Select
4043      sum(ced.after_warranty_cost)
4044 into l_amount
4045 from csd_repair_estimate cre,
4046 	csd_repair_estimate_lines crel,
4047 	cs_estimate_details ced,
4048 	cs_txn_billing_types ctbt
4049 where cre.repair_estimate_id = crel.repair_estimate_id
4050   and crel.estimate_detail_id = ced.estimate_detail_id
4051   and ced.txn_billing_type_id = ctbt.txn_billing_type_id
4052   and cre.repair_line_id     = p_repair_line_id
4053   and ctbt.billing_type      = 'M';
4054 
4055 ELSIF p_code = 'L' then
4056 
4057 Select
4058      sum(ced.after_warranty_cost)
4059 into l_amount
4060 from csd_repair_estimate cre,
4061 	csd_repair_estimate_lines crel,
4062 	cs_estimate_details ced,
4063 	cs_txn_billing_types ctbt
4064 where cre.repair_estimate_id = crel.repair_estimate_id
4065   and crel.estimate_detail_id = ced.estimate_detail_id
4066   and ced.txn_billing_type_id = ctbt.txn_billing_type_id
4067   and cre.repair_line_id     = p_repair_line_id
4068   and ctbt.billing_type      = 'L';
4069 
4070 ELSIF p_code = 'E' then
4071 
4072 Select
4073      sum(ced.after_warranty_cost)
4074 into l_amount
4075 from csd_repair_estimate cre,
4076 	csd_repair_estimate_lines crel,
4077 	cs_estimate_details ced,
4078 	cs_txn_billing_types ctbt
4079 where cre.repair_estimate_id = crel.repair_estimate_id
4080   and crel.estimate_detail_id = ced.estimate_detail_id
4081   and ced.txn_billing_type_id = ctbt.txn_billing_type_id
4082   and cre.repair_line_id     = p_repair_line_id
4083   and ctbt.billing_type      = 'E';
4084 
4085 ELSIF p_code = 'T' then
4086 
4087 Select
4088      sum(ced.after_warranty_cost)
4089 into l_amount
4090 from csd_repair_estimate cre,
4091 	csd_repair_estimate_lines crel,
4092 	cs_estimate_details ced
4093 where cre.repair_estimate_id = crel.repair_estimate_id
4094   and crel.estimate_detail_id = ced.estimate_detail_id
4095   and cre.repair_line_id     = p_repair_line_id ;
4096 
4097 END IF;
4098 
4099  RETURN l_amount;
4100 
4101 EXCEPTION
4102  When NO_DATA_FOUND then
4103     RETURN l_amount;
4104 END get_estimate;
4105 
4106 FUNCTION get_bus_process
4107 (
4108   p_repair_line_id IN	NUMBER
4109  ) RETURN NUMBER
4110 
4111  IS
4112   l_bus_process_id NUMBER := null;
4113 
4114 BEGIN
4115 
4116 -- Forward port bug# 2756313
4117 /* select b.business_process_id
4118  into l_bus_process_id
4119  from cs_incidents_all_b a,
4120       cs_incident_types_b b
4121  where a.incident_type_id = b.incident_type_id
4122   and  a.incident_id      = p_incident_id;
4123 */
4124 
4125  select t.business_process_id
4126  into l_bus_process_id
4127  from csd_repairs r,
4128       csd_repair_types_b t
4129  where r.repair_line_id = p_repair_line_id
4130  and   r.repair_type_id = t.repair_type_id;
4131 
4132  IF l_bus_process_id is null then
4133     raise no_data_found ;
4134  else
4135   RETURN l_bus_process_id;
4136  END IF;
4137 
4138 EXCEPTION
4139 When NO_DATA_FOUND then
4140     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_BUS_PROCESS');
4141     FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
4142     FND_MSG_PUB.Add;
4143     RETURN -1;
4144 END get_bus_process;
4145 
4146 PROCEDURE Convert_to_Chg_rec
4147 (
4148   p_prod_txn_rec       IN	CSD_PROCESS_PVT.PRODUCT_TXN_REC,
4149   x_charges_rec        OUT NOCOPY	CS_CHARGE_DETAILS_PUB.CHARGES_REC_TYPE,
4150   x_return_status      OUT NOCOPY	VARCHAR2
4151 ) IS
4152 
4153   /*Fixed for FP bug#5408047*/
4154   cursor c2(p_txn_billing_type_id NUMBER) is
4155   select SRC_RETURN_REQD
4156         ,NON_SRC_RETURN_REQD
4157   from csi_ib_txn_types a,
4158        cs_txn_billing_types b
4159   where a.cs_transaction_type_id = b.transaction_type_id
4160   and  b.txn_billing_type_id = p_txn_billing_type_id;
4161 
4162   l_src_return_reqd           varchar2(1);  /*Fixed for FP bug#5408047*/
4163   l_non_src_return_reqd       varchar2(1);  /*Fixed for FP bug#5408047*/
4164 
4165 BEGIN
4166 
4167  x_return_status := FND_API.G_RET_STS_SUCCESS;
4168 
4169  x_charges_rec.estimate_detail_id          := p_prod_txn_rec.estimate_detail_id;
4170  x_charges_rec.incident_id                 := p_prod_txn_rec.incident_id;
4171  x_charges_rec.original_source_id          := p_prod_txn_rec.repair_line_id;
4172  x_charges_rec.original_source_code        := 'DR' ;
4173  x_charges_rec.source_id                   := p_prod_txn_rec.repair_line_id;
4174  x_charges_rec.source_code                 := 'DR' ;
4175  x_charges_rec.line_type_id                := p_prod_txn_rec.line_type_id;
4176  x_charges_rec.txn_billing_type_id         := p_prod_txn_rec.txn_billing_type_id;
4177  x_charges_rec.business_process_id         := p_prod_txn_rec.business_process_id;
4178  x_charges_rec.inventory_item_id_in        := p_prod_txn_rec.inventory_item_id;
4179  x_charges_rec.price_list_id               := p_prod_txn_rec.price_list_id;
4180  x_charges_rec.currency_code               := p_prod_txn_rec.currency_code;
4181  x_charges_rec.quantity_required           := p_prod_txn_rec.quantity;
4182  x_charges_rec.unit_of_measure_code        := p_prod_txn_rec.unit_of_measure_code;
4183  -- swai: 12.0.2 3rd party logistics
4184  -- instance and reference number should be set to the source id for
4185  -- RMA and RMA_THIRD_PTY only.  SHIP_THIRD_PTY will be handled like SHIP,
4186  -- but non-source will always be blank for SHIP_THIRD_PTY.
4187  If p_prod_txn_rec.action_type in ('SHIP','WALK_IN_ISSUE', 'SHIP_THIRD_PTY') Then
4188     x_charges_rec.customer_product_id := p_prod_txn_rec.non_source_instance_id;
4189 --bug#13366828: since instance id is passed, doesn't need to pass instance number
4190 --x_charges_rec.reference_number is defined as number, not char.
4191 --    x_charges_rec.reference_number    := p_prod_txn_rec.non_source_instance_number; --bug#13366828
4192  elsif p_prod_txn_rec.action_type in ('RMA','RMA_THIRD_PTY') Then
4193     x_charges_rec.customer_product_id := p_prod_txn_rec.source_instance_id;
4194 --bug#13366828: since instance id is passed, doesn't need to pass instance number
4195 --x_charges_rec.reference_number is defined as number, not char.
4196 --    x_charges_rec.reference_number   := p_prod_txn_rec.source_instance_number;  --bug#13366828
4197  end if;
4198  x_charges_rec.interface_to_oe_flag        := p_prod_txn_rec.interface_to_om_flag;
4199  x_charges_rec.no_charge_flag              := p_prod_txn_rec.no_charge_flag;
4200  x_charges_rec.after_warranty_cost         := p_prod_txn_rec.after_warranty_cost;
4201  x_charges_rec.add_to_order_flag           := p_prod_txn_rec.add_to_order_flag;
4202  x_charges_rec.rollup_flag                 := 'N';
4203  x_charges_rec.line_category_code          := p_prod_txn_rec.line_category_code;
4204 
4205  /*Fixed for FP bug#5408047
4206    assign the return by date value to appropriate field
4207  */
4208  l_src_return_reqd     :='N';
4209  l_non_src_return_reqd :='N';
4210  open c2( p_prod_txn_rec.txn_billing_type_id );
4211  fetch c2 into l_src_return_reqd,l_non_src_return_reqd ;
4212  If (c2%ISOPEN) then
4213    Close c2;
4214  End if;
4215 
4216  -- Modified for the bug 3523019
4217  If p_prod_txn_rec.line_category_code = 'RETURN' THEN
4218     x_charges_rec.installed_cp_return_by_date := p_prod_txn_rec.return_by_date;
4219  Else
4220 
4221    /*Fixed for FP bug#5408047
4222      assign the return by date value to appropriate field
4223    */
4224    If l_SRC_RETURN_REQD ='Y' then
4225      x_charges_rec.new_cp_return_by_date :=  p_prod_txn_rec.return_by_date;
4226    END IF;
4227 
4228    If l_NON_SRC_RETURN_REQD ='Y' then
4229      x_charges_rec.installed_cp_return_by_date := p_prod_txn_rec.return_by_date;
4230    END IF;
4231 
4232    If l_SRC_RETURN_REQD ='N' and l_NON_SRC_RETURN_REQD= 'N' then
4233      IF  p_prod_txn_rec.non_source_instance_id is not null then
4234        x_charges_rec.installed_cp_return_by_date := p_prod_txn_rec.return_by_date;
4235      ELSE
4236        x_charges_rec.new_cp_return_by_date :=  p_prod_txn_rec.return_by_date;
4237      END IF;
4238    END IF;
4239 
4240  End If;
4241 
4242  x_charges_rec.return_reason_code          := p_prod_txn_rec.return_reason;
4243  x_charges_rec.contract_id                 := p_prod_txn_rec.contract_id;
4244  --R12 contracts changes..
4245  x_charges_rec.contract_line_id            := p_prod_txn_rec.contract_line_id;
4246  x_charges_rec.invoice_to_org_id           := p_prod_txn_rec.invoice_to_org_id;
4247  x_charges_rec.ship_to_org_id              := p_prod_txn_rec.ship_to_org_id;
4248  x_charges_rec.item_revision			   := p_prod_txn_rec.revision;
4249  x_charges_rec.serial_number               := p_prod_txn_rec.source_serial_number;
4250  x_charges_rec.original_source_number      := to_char(p_prod_txn_rec.repair_line_id);
4251  x_charges_rec.source_number               := to_char(p_prod_txn_rec.repair_line_id);
4252  x_charges_rec.purchase_order_num          := p_prod_txn_rec.po_number;
4253  x_charges_rec.inventory_item_id_out       := FND_API.G_MISS_NUM;
4254  x_charges_rec.serial_number_out           := FND_API.G_MISS_CHAR;
4255  x_charges_rec.order_header_id             := p_prod_txn_rec.order_header_id;
4256  x_charges_rec.order_line_id               := FND_API.G_MISS_NUM;
4257  x_charges_rec.original_system_reference   := FND_API.G_MISS_CHAR;
4258  x_charges_rec.selling_price               := FND_API.G_MISS_NUM;
4259  x_charges_rec.transaction_type_id         := p_prod_txn_rec.transaction_type_id;
4260  --x_charges_rec.organization_id             := FND_API.G_MISS_NUM;
4261  --x_to_charges_rec.customer_id              := FND_API.G_MISS_NUM;
4262  -- Inv_org Change, Vijay , 20/3/2006
4263  x_charges_rec.transaction_inventory_org         := p_prod_txn_rec.inventory_org_id;
4264 
4265  -- swai: bug 5931926 - 3rd party logistics for 12.0.2
4266  x_charges_rec.bill_to_party_id            := p_prod_txn_rec.bill_to_party_id;
4267  x_charges_rec.bill_to_account_id          := p_prod_txn_rec.bill_to_account_id;
4268  x_charges_rec.ship_to_party_id            := p_prod_txn_rec.ship_to_party_id;
4269  x_charges_rec.ship_to_account_id          := p_prod_txn_rec.ship_to_account_id;
4270 
4271  -- bug#8416835, FP of bug#8288715 subhat.
4272  -- the ship to contact id and bill to contact id is not passed to OM when these
4273  -- values are captured on SR.
4274  if p_prod_txn_rec.action_type <> 'SHIP_THIRD_PTY' and
4275      p_prod_txn_rec.action_type <> 'RMA_THIRD_PTY' then
4276       begin
4277           select decode(bill_to_site_id, p_prod_txn_rec.invoice_to_org_id,bill_to_contact_id),
4278                   decode(ship_to_site_id,p_prod_txn_rec.ship_to_org_id,ship_to_contact_id)
4279           into
4280                x_charges_rec.bill_to_contact_id,
4281                x_charges_rec.ship_to_contact_id
4282           from   cs_incidents_all_b
4283           where  incident_id = decode(p_prod_txn_rec.incident_id,FND_API.G_MISS_NUM,
4284                                    (select incident_id from csd_repairs where repair_line_id = p_prod_txn_rec.repair_line_id),
4285                                    p_prod_txn_rec.incident_id );
4286       exception
4287           when no_data_found then
4288                null;
4289       end;
4290   end if;
4291   -- end bug#8416835, subhat.
4292 
4293 
4294 EXCEPTION
4295     WHEN FND_API.G_EXC_ERROR THEN
4296           x_return_status := FND_API.G_RET_STS_ERROR ;
4297     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4298           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4299     WHEN OTHERS THEN
4300           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4301 END Convert_to_Chg_rec;
4302 
4303 PROCEDURE get_line_type
4304 ( p_txn_billing_type_id IN	NUMBER,
4305   p_org_id              IN  NUMBER,
4306   x_line_type_id        OUT NOCOPY	NUMBER,
4307   x_line_category_code  OUT NOCOPY VARCHAR2,
4308   x_return_status       OUT NOCOPY	VARCHAR2
4309  ) IS
4310 
4311 BEGIN
4312 
4313 x_return_status := FND_API.G_RET_STS_SUCCESS;
4314 
4315 select b.line_type_id,
4316        c.line_order_category_code
4317  into  x_line_type_id,
4318        x_line_category_code
4319 from cs_txn_billing_types a,
4320      CS_TXN_BILLING_OETXN_ALL b,
4321      cs_transaction_types_vl c
4322 where a.txn_billing_type_id = b.txn_billing_type_id
4323  and  a.transaction_type_id = c.transaction_type_id
4324  and  a.txn_billing_type_id = p_txn_billing_type_id
4325  and  b.org_id              = p_org_id;
4326 
4327 EXCEPTION
4328 When NO_DATA_FOUND then
4329     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_TXN_BILL_TYPE_ID');
4330     FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID',p_txn_billing_type_id);
4331     FND_MSG_PUB.Add;
4332     x_return_status := FND_API.G_RET_STS_ERROR ;
4333 When OTHERS then
4334     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_TXN_BILL_TYPE_ID');
4335     FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID',p_txn_billing_type_id);
4336     FND_MSG_PUB.Add;
4337     x_return_status := FND_API.G_RET_STS_ERROR ;
4338 END get_line_type;
4339 
4340 
4341 FUNCTION Get_group_rejected_quantity
4342 (
4343   p_repair_group_id IN Number
4344  ) RETURN NUMBER
4345 IS
4346 
4347 l_rejected_quantity  Number := 0;
4348 
4349 BEGIN
4350 
4351   Select count(*)
4352   into l_rejected_quantity
4353   from csd_repairs
4354   where upper(approval_status) = 'R'
4355   and repair_group_id = p_repair_group_id;
4356 
4357   RETURN l_rejected_quantity;
4358 
4359 EXCEPTION
4360 WHEN OTHERS THEN
4361  null;
4362 END Get_group_rejected_quantity;
4363 
4364 FUNCTION Validate_prod_txn_id
4365 (
4366   p_prod_txn_id	  IN	NUMBER
4367  ) RETURN BOOLEAN
4368  IS
4369 
4370 l_dummy   VARCHAR2(1);
4371 
4372 BEGIN
4373 
4374  select 'X'
4375  into l_dummy
4376  from csd_product_transactions
4377  where product_transaction_id = p_prod_txn_id;
4378 RETURN TRUE;
4379 EXCEPTION
4380 When NO_DATA_FOUND then
4381     FND_MESSAGE.SET_NAME('CSD','CSD_INV_PROD_TXN_ID');
4382     FND_MESSAGE.SET_TOKEN('PRODUCT_TXN_ID',p_prod_txn_id);
4383     FND_MSG_PUB.Add;
4384     RETURN FALSE;
4385 END Validate_prod_txn_id;
4386 
4387 PROCEDURE Validate_wip_task
4388 ( p_prod_txn_id    IN	NUMBER,
4389   x_return_status  OUT NOCOPY	VARCHAR2
4390  )IS
4391 
4392 l_repair_mode     varchar2(30) := '';
4393 l_repair_type_id  number := null;
4394 l_repair_line_id  number := null;
4395 l_qty_completed   number := null;
4396 l_prod_txn_qty    number := null;
4397 l_dummy           varchar2(1) := '';
4398 l_count           number;
4399 
4400 CURSOR cur_repln_dtls IS
4401 SELECT
4402   a.repair_mode,
4403   a.repair_type_id,
4404   b.repair_line_id,
4405   c.quantity_required
4406 FROM csd_repairs a,
4407      csd_product_transactions b,
4408      cs_estimate_details c
4409 where a.repair_line_id = b.repair_line_id
4410  and  b.estimate_detail_id = c.estimate_detail_id
4411  and  b.product_transaction_id = p_prod_txn_id;
4412 
4413 BEGIN
4414 
4415   x_return_status := FND_API.G_RET_STS_SUCCESS;
4416 
4417   IF NVL(p_prod_txn_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN
4418 
4419     IF cur_repln_dtls%isopen then
4420       CLOSE cur_repln_dtls;
4421     END IF;
4422 /**********
4423     OPEN  cur_repln_dtls;
4424     FETCH cur_repln_dtls INTO l_repair_mode,
4425                                 l_repair_type_id,
4426                                 l_repair_line_id,
4427                                 l_prod_txn_qty;
4428     IF cur_repln_dtls%notfound then
4429 *********/
4430 	BEGIN
4431 	SELECT a.repair_mode,
4432 	       a.repair_type_id,
4433   		   b.repair_line_id,
4434            c.quantity_required
4435 	INTO l_repair_mode,
4436 	     l_repair_type_id,
4437 		 l_repair_line_id,
4438 		 l_prod_txn_qty
4439 	FROM csd_repairs a,
4440      csd_product_transactions b,
4441      cs_estimate_details c
4442     where a.repair_line_id = b.repair_line_id
4443        and  b.estimate_detail_id = c.estimate_detail_id
4444        and  b.product_transaction_id = p_prod_txn_id ;
4445 
4446 	 EXCEPTION
4447 	   WHEN NO_DATA_FOUND THEN
4448 	      FND_MESSAGE.SET_NAME('CSD','CSD_API_INV2_PROD_TXN_ID');
4449 	      FND_MESSAGE.SET_TOKEN('PRODUCT_TXN_ID',p_prod_txn_id);
4450 	      FND_MSG_PUB.ADD;
4451 	      RAISE FND_API.G_EXC_ERROR;
4452 	END;
4453 /*
4454     END IF;
4455 */
4456 
4457     IF cur_repln_dtls%isopen then
4458       CLOSE cur_repln_dtls;
4459     END IF;
4460 
4461   END IF;
4462 
4463 IF (g_debug > 0 ) THEN
4464   csd_gen_utility_pvt.add('l_repair_line_id ='||l_repair_line_id);
4465 END IF;
4466 
4467 IF (g_debug > 0 ) THEN
4468   csd_gen_utility_pvt.add('l_repair_mode ='||l_repair_mode);
4469 END IF;
4470 
4471 
4472    IF l_repair_mode = 'WIP' then
4473 
4474     BEGIN
4475      select sum(quantity_completed)
4476       into  l_qty_completed
4477       from csd_repair_job_xref
4478      where repair_line_id = l_repair_line_id;
4479     EXCEPTION
4480     WHEN OTHERS THEN
4481       RAISE FND_API.G_EXC_ERROR;
4482 IF (g_debug > 0 ) THEN
4483       csd_gen_utility_pvt.add('repair line Id not found');
4484 END IF;
4485 
4486     END;
4487 
4488 IF (g_debug > 0 ) THEN
4489    csd_gen_utility_pvt.add('l_qty_completed ='||l_qty_completed);
4490 END IF;
4491 
4492 IF (g_debug > 0 ) THEN
4493    csd_gen_utility_pvt.add('l_prod_txn_qty  ='||l_prod_txn_qty);
4494 END IF;
4495 
4496     /************* travi comment on 030703 for Bug # 2830828 **************
4497     If nvl(l_qty_completed,0) < l_prod_txn_qty then
4498       FND_MESSAGE.SET_NAME('CSD','CSD_API_PROCESS_NOT_ALLOWED');
4499       FND_MESSAGE.SET_TOKEN('QTY_COMPLETED',l_qty_completed);
4500       FND_MSG_PUB.ADD;
4501       IF (g_debug > 0 ) THEN
4502             csd_gen_utility_pvt.ADD('Prod txn qty is more than qty completed :'||l_qty_completed);
4503       END IF;
4504 
4505       RAISE FND_API.G_EXC_ERROR;
4506     end if;
4507     **********************************************************************/
4508 
4509   ELSIF l_repair_mode = 'TASK' then
4510 
4511       Select count(*)
4512        into l_count
4513       from jtf_tasks_vl
4514       where source_object_type_code = 'DR'
4515        and  source_object_id = l_repair_line_id
4516        and  task_status_id not in (7,8,9,11);
4517 
4518 IF (g_debug > 0 ) THEN
4519      csd_gen_utility_pvt.ADD('l_count= '||l_count);
4520 END IF;
4521 
4522     IF l_count > 0 then
4523       FND_MESSAGE.SET_NAME('CSD','CSD_API_TASK_NOT_COMPLETE');
4524       FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',l_repair_line_id);
4525       FND_MSG_PUB.ADD;
4526 
4527       IF (g_debug > 0 ) THEN
4528         csd_gen_utility_pvt.ADD('One or more of the tasks for repair line : '||l_repair_line_id||' :is not completed');
4529       END IF;
4530     End If;
4531 
4532   END IF;
4533 
4534 EXCEPTION
4535     WHEN FND_API.G_EXC_ERROR THEN
4536           x_return_status := FND_API.G_RET_STS_ERROR ;
4537     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4538           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4539     WHEN OTHERS THEN
4540           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4541 END Validate_wip_task;
4542 
4543 
4544 PROCEDURE Validate_quantity
4545 (
4546   p_action_type	   IN	VARCHAR2,
4547   p_repair_line_id IN   VARCHAR2,
4548   p_prod_txn_qty   IN   NUMBER,
4549   x_return_status  OUT NOCOPY	VARCHAR2
4550  ) IS
4551 
4552 CURSOR qty_by_type  IS
4553 SELECT
4554   abs(sum(b.quantity_required))
4555 FROM csd_product_transactions a,
4556      cs_estimate_details b
4557 where a.estimate_detail_id = b.estimate_detail_id
4558  and  a.action_code    = 'CUST_PROD'
4559  and a.prod_txn_status <> 'CANCELLED'
4560  and  a.action_type    = p_action_type
4561  and  a.repair_line_id = p_repair_line_id;
4562 
4563 CURSOR repair_qty IS
4564 SELECT
4565       quantity
4566 FROM  csd_repairs
4567 WHERE repair_line_id = p_repair_line_id;
4568 
4569 l_qty_by_type NUMBER := NULL;
4570 l_repair_qty  NUMBER := NULL;
4571 l_prod_txn_qty NUMBER := NULL;
4572 
4573 BEGIN
4574   x_return_status := FND_API.G_RET_STS_SUCCESS;
4575 
4576 --bug#15851904 remove this validation per bug#15851904
4577 --For bug#15969462
4578   return;
4579 /*
4580   OPEN qty_by_type ;
4581   FETCH qty_by_type into l_qty_by_type;
4582   CLOSE qty_by_type;
4583 
4584   OPEN repair_qty;
4585   FETCH repair_qty into l_repair_qty;
4586   CLOSE repair_qty;
4587 
4588   IF NVL(p_prod_txn_qty,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM THEN
4589      l_prod_txn_qty := NULL;
4590   Else
4591      l_prod_txn_qty := p_prod_txn_qty;
4592   END IF;
4593 
4594 IF (g_debug > 0 ) THEN
4595   csd_gen_utility_pvt.add('l_qty_by_type  ='||l_qty_by_type);
4596 END IF;
4597 
4598 IF (g_debug > 0 ) THEN
4599   csd_gen_utility_pvt.add('l_prod_txn_qty ='||l_prod_txn_qty);
4600 END IF;
4601 
4602 IF (g_debug > 0 ) THEN
4603   csd_gen_utility_pvt.add('l_repair_qty   ='||l_repair_qty);
4604 END IF;
4605 
4606 
4607   IF (NVL(l_qty_by_type,0) + NVL(l_prod_txn_qty,0)) > NVL(l_repair_qty,0) THEN
4608       FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_QUANTITY');
4609       FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
4610       FND_MSG_PUB.ADD;
4611 IF (g_debug > 0 ) THEN
4612       csd_gen_utility_pvt.ADD('Prod txn qty is more than qty in repair Line :'||p_repair_line_id);
4613 END IF;
4614 
4615       RAISE FND_API.G_EXC_ERROR;
4616   END IF;
4617 
4618 */
4619 --bug#15851904 remove this validation per bug#15851904
4620 --For bug#15969462
4621 
4622 EXCEPTION
4623     WHEN FND_API.G_EXC_ERROR THEN
4624           x_return_status := FND_API.G_RET_STS_ERROR ;
4625     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4626           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4627     WHEN OTHERS THEN
4628           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
4629 END Validate_quantity;
4630 
4631 
4632 FUNCTION Is_item_serialized
4633 (
4634   p_inv_item_id	  IN	NUMBER
4635  ) RETURN BOOLEAN
4636  IS
4637 
4638  l_serial_code   NUMBER := null;
4639 BEGIN
4640 
4641  select serial_number_control_code
4642  into l_serial_code
4643  from mtl_system_items
4644  where inventory_item_id = p_inv_item_id
4645  and   organization_id   = cs_std.get_item_valdn_orgzn_id;
4646 
4647  IF l_serial_code = 1 then
4648    RETURN FALSE;
4649  Else
4650    RETURN TRUE;
4651  End if;
4652 EXCEPTION
4653 When NO_DATA_FOUND then
4654     FND_MESSAGE.SET_NAME('CSD','CSD_API_INV_ITEM_ID');
4655     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID',p_inv_item_id);
4656     FND_MSG_PUB.Add;
4657     RAISE FND_API.G_EXC_ERROR;
4658 END Is_item_serialized;
4659 
4660 FUNCTION g_miss_num RETURN number
4661 IS
4662 BEGIN
4663   RETURN fnd_api.g_miss_num;
4664 END g_miss_num;
4665 
4666 FUNCTION g_miss_char RETURN varchar2
4667 IS
4668 BEGIN
4669   RETURN fnd_api.g_miss_char ;
4670 END g_miss_char;
4671 
4672 FUNCTION g_miss_date RETURN date
4673 IS
4674 BEGIN
4675   RETURN fnd_api.g_miss_date ;
4676 END g_miss_date ;
4677 
4678 FUNCTION g_valid_level(p_level varchar2) RETURN number
4679 IS
4680 BEGIN
4681   IF p_level = 'NONE' then
4682     RETURN fnd_api.g_valid_level_none;
4683   ELSIF p_level = 'FULL' then
4684     RETURN fnd_api.g_valid_level_full;
4685   ELSE
4686     fnd_msg_pub.add_exc_msg(
4687       p_pkg_name       => G_PKG_NAME ,
4688       p_procedure_name => 'G_VALID_LEVEL',
4689       p_error_text     => 'Unrecognized Value: '||p_level);
4690 
4691     RAISE fnd_api.g_exc_unexpected_error;
4692   END IF;
4693 END g_valid_level ;
4694 
4695 FUNCTION g_boolean(p_FLAG varchar2) RETURN varchar2
4696 IS
4697 BEGIN
4698   if p_flag = 'TRUE' then
4699     return FND_API.G_TRUE ;
4700   elsif p_flag = 'FALSE' then
4701     return FND_API.G_FALSE ;
4702   else
4703     fnd_msg_pub.add_exc_msg(
4704       p_pkg_name       => G_PKG_NAME,
4705       p_procedure_name => 'G_BOOLEAN',
4706       p_error_text     => 'Unrecognized Value: '||p_flag);
4707     RAISE fnd_api.g_exc_unexpected_error;
4708   END if;
4709 END g_boolean;
4710 
4711 FUNCTION get_error_constant(err_msg varchar2) RETURN varchar2
4712 IS
4713 BEGIN
4714 
4715   IF err_msg = 'G_RET_STS_ERROR' THEN
4716      RETURN fnd_api.g_ret_sts_error;
4717   ELSIF err_msg = 'G_RET_STS_UNEXP_ERROR' THEN
4718      RETURN fnd_api.g_ret_sts_unexp_error;
4719   ELSIF err_msg = 'G_RET_STS_SUCCESS' THEN
4720      RETURN fnd_api.g_ret_sts_success;
4721   END IF;
4722 
4723 END get_error_constant;
4724 
4725 FUNCTION ui_prod_txn_rec RETURN csd_process_pvt.product_txn_rec
4726 IS
4727   l_prod_txn_rec csd_process_pvt.product_txn_rec;
4728 BEGIN
4729   RETURN l_prod_txn_rec;
4730 END ui_prod_txn_rec;
4731 
4732 FUNCTION sr_rec RETURN csd_process_pvt.service_request_rec
4733 IS
4734   l_sr_rec csd_process_pvt.service_request_rec;
4735 BEGIN
4736   RETURN l_sr_rec;
4737 END sr_rec;
4738 
4739 FUNCTION repair_order_rec RETURN csd_repairs_pub.repln_rec_type
4740 IS
4741   l_ro_rec csd_repairs_pub.repln_rec_type;
4742 BEGIN
4743   RETURN l_ro_rec;
4744 END repair_order_rec;
4745 
4746 FUNCTION ui_estimate_rec RETURN csd_repair_estimate_pvt.repair_estimate_rec
4747 IS
4748   l_est_rec csd_repair_estimate_pvt.repair_estimate_rec;
4749 BEGIN
4750   RETURN l_est_rec;
4751 END ui_estimate_rec ;
4752 
4753 FUNCTION ui_job_parameter_rec RETURN csd_group_job_pvt.job_parameter_rec
4754 IS
4755   l_job_param_rec csd_group_job_pvt.job_parameter_rec;
4756 BEGIN
4757   RETURN l_job_param_rec;
4758 END ui_job_parameter_rec ;
4759 
4760 
4761 FUNCTION ui_estimate_line_rec RETURN csd_repair_estimate_pvt.repair_estimate_line_rec
4762 IS
4763   l_est_line_rec csd_repair_estimate_pvt.repair_estimate_line_rec;
4764 BEGIN
4765   RETURN l_est_line_rec;
4766 END ui_estimate_line_rec ;
4767 
4768 FUNCTION ui_pricing_attr_rec RETURN csd_process_util.pricing_attr_rec
4769 IS
4770   l_pric_att_rec csd_process_util.pricing_attr_rec ;
4771 BEGIN
4772   RETURN l_pric_att_rec;
4773 END ui_pricing_attr_rec ;
4774 
4775 
4776 FUNCTION ui_instance_rec RETURN csi_datastructures_pub.instance_rec
4777 IS
4778   l_inst_rec csi_datastructures_pub.instance_rec;
4779 BEGIN
4780   RETURN l_inst_rec;
4781 END ui_instance_rec ;
4782 
4783 FUNCTION ui_party_tbl RETURN csi_datastructures_pub.party_tbl
4784 IS
4785   l_pty_tbl csi_datastructures_pub.party_tbl;
4786 BEGIN
4787   RETURN l_pty_tbl;
4788 END ui_party_tbl ;
4789 
4790 FUNCTION ui_party_account_tbl RETURN csi_datastructures_pub.party_account_tbl
4791 IS
4792   l_pty_acct_tbl csi_datastructures_pub.party_account_tbl;
4793 BEGIN
4794   RETURN l_pty_acct_tbl;
4795 END ui_party_account_tbl ;
4796 
4797 FUNCTION ui_organization_units_tbl RETURN csi_datastructures_pub.organization_units_tbl
4798 IS
4799   l_org_tbl csi_datastructures_pub.organization_units_tbl;
4800 BEGIN
4801   RETURN l_org_tbl;
4802 END ui_organization_units_tbl ;
4803 
4804 FUNCTION ui_extend_attrib_values_tbl RETURN csi_datastructures_pub.extend_attrib_values_tbl
4805 IS
4806   l_eav_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4807 BEGIN
4808   RETURN l_eav_tbl;
4809 END ui_extend_attrib_values_tbl ;
4810 
4811 FUNCTION ui_pricing_attribs_tbl RETURN csi_datastructures_pub.pricing_attribs_tbl
4812 IS
4813   l_pric_att_tbl csi_datastructures_pub.pricing_attribs_tbl;
4814 BEGIN
4815   RETURN l_pric_att_tbl;
4816 END ui_pricing_attribs_tbl ;
4817 
4818 FUNCTION ui_instance_asset_tbl RETURN csi_datastructures_pub.instance_asset_tbl
4819 IS
4820   l_ins_ass_tbl csi_datastructures_pub.instance_asset_tbl;
4821 BEGIN
4822   RETURN l_ins_ass_tbl;
4823 END ui_instance_asset_tbl ;
4824 
4825 FUNCTION ui_transaction_rec RETURN csi_datastructures_pub.transaction_rec
4826 IS
4827   l_txn_rec csi_datastructures_pub.transaction_rec;
4828 BEGIN
4829   RETURN l_txn_rec;
4830 END ui_transaction_rec ;
4831 
4832 FUNCTION ui_actual_lines_rec RETURN CSD_REPAIR_ACTUAL_LINES_PVT.CSD_ACTUAL_LINES_REC_TYPE
4833 IS
4834   l_act_lines_rec CSD_REPAIR_ACTUAL_LINES_PVT.CSD_ACTUAL_LINES_REC_TYPE;
4835   BEGIN
4836     RETURN l_act_lines_rec;
4837 END ui_actual_lines_rec;
4838 
4839 
4840 FUNCTION ui_charge_lines_rec RETURN CS_CHARGE_DETAILS_PUB.CHARGES_REC_TYPE
4841 IS
4842   l_charge_lines_rec CS_CHARGE_DETAILS_PUB.CHARGES_REC_TYPE;
4843 BEGIN
4844     RETURN l_charge_lines_rec;
4845 END ui_charge_lines_rec;
4846 
4847 
4848 FUNCTION ui_actuals_rec RETURN CSD_REPAIR_ACTUALS_PVT.CSD_REPAIR_ACTUALS_REC_TYPE
4849 IS
4850   l_actuals_rec CSD_REPAIR_ACTUALS_PVT.CSD_REPAIR_ACTUALS_REC_TYPE;
4851 BEGIN
4852     RETURN l_actuals_rec;
4853 END ui_actuals_rec;
4854 
4855 ----------- travi changes----------
4856 
4857 PROCEDURE COMMIT_ROLLBACK(
4858 	    COM_ROLL       IN   VARCHAR2 := 'ROLL')
4859 IS
4860 BEGIN
4861    if ( COM_ROLL = 'COMMIT' ) then
4862 	 commit;
4863    else
4864 	 rollback;
4865    end if;
4866 END;
4867 
4868 FUNCTION G_RET_STS_SUCCESS RETURN VARCHAR2 IS
4869 BEGIN
4870    RETURN FND_API.G_RET_STS_SUCCESS ;
4871 END G_RET_STS_SUCCESS ;
4872 
4873 
4874 FUNCTION G_RET_STS_ERROR RETURN VARCHAR2 IS
4875 BEGIN
4876    RETURN FND_API.G_RET_STS_ERROR ;
4877 END G_RET_STS_ERROR ;
4878 
4879 
4880 FUNCTION G_RET_STS_UNEXP_ERROR RETURN VARCHAR2 IS
4881 BEGIN
4882    RETURN FND_API.G_RET_STS_UNEXP_ERROR ;
4883 END G_RET_STS_UNEXP_ERROR ;
4884 
4885 
4886 FUNCTION G_VALID_LEVEL_NONE RETURN NUMBER IS
4887 BEGIN
4888    RETURN FND_API.G_VALID_LEVEL_NONE ;
4889 END;
4890 
4891 
4892 FUNCTION G_VALID_LEVEL_FULL RETURN NUMBER IS
4893 BEGIN
4894    RETURN FND_API.G_VALID_LEVEL_FULL ;
4895 END;
4896 
4897 
4898 FUNCTION G_VALID_LEVEL_INT RETURN NUMBER IS
4899 BEGIN
4900    RETURN CS_INTERACTION_PVT.G_VALID_LEVEL_INT ;
4901 END;
4902 
4903 
4904 FUNCTION G_TRUE RETURN VARCHAR2 IS
4905 BEGIN
4906    return FND_API.G_TRUE ;
4907 END;
4908 
4909 
4910 FUNCTION G_FALSE RETURN VARCHAR2 IS
4911 BEGIN
4912    return FND_API.G_FALSE ;
4913 END;
4914 
4915 
4916 FUNCTION get_res_name (p_object_type_code IN VARCHAR2,
4917                        p_object_id        IN NUMBER)
4918       RETURN VARCHAR2
4919    IS
4920 
4921 	 l_object_type_code Varchar2(30);
4922 	 l_code             Varchar2(30);
4923 
4924       CURSOR c_references(l_object_type_code varchar2)
4925       IS
4926          SELECT select_id, select_name, from_table, where_clause
4927            FROM jtf_objects_b
4928           WHERE object_code = l_object_type_code;
4929 
4930       l_id_column      jtf_objects_b.select_id%TYPE;
4931       l_name_column    jtf_objects_b.select_name%TYPE;
4932       l_from_clause    jtf_objects_b.from_table%TYPE;
4933       l_where_clause   jtf_objects_b.where_clause%TYPE;
4934       l_object_code    jtf_tasks_b.source_object_type_code%TYPE
4935                := p_object_type_code;
4936       l_object_name    jtf_tasks_b.source_object_name%TYPE;
4937       l_object_id      jtf_tasks_b.source_object_id%TYPE
4938                := p_object_id;
4939       is_null          BOOLEAN                                  :=
4940 FALSE;
4941       is_not_null      BOOLEAN                                  :=
4942 FALSE;
4943       sql_stmt         VARCHAR2(2000);
4944    BEGIN
4945 
4946 	 -- travi for returning a resourse name even if object_type_code it does not have RS_
4947 	 if (p_object_type_code is not null) then
4948 
4949 		select substr(p_object_type_code,1,3)
4950             into l_code
4951 		  from sys.dual;
4952 
4953           if(l_code = 'RS_') then
4954 		   l_object_type_code := p_object_type_code;
4955 IF (g_debug > 0 ) THEN
4956 		   csd_gen_utility_pvt.add('p_object_type_code  ='||p_object_type_code);
4957 END IF;
4958 
4959           else
4960 		   l_object_type_code := 'RS_'||p_object_type_code;
4961 IF (g_debug > 0 ) THEN
4962 		   csd_gen_utility_pvt.add('In else p_object_type_code  ='||p_object_type_code);
4963 END IF;
4964 
4965 		end if;
4966       end if;
4967 
4968 
4969       OPEN c_references(l_object_type_code);
4970       FETCH c_references INTO l_id_column,
4971                               l_name_column,
4972                               l_from_clause,
4973                               l_where_clause;
4974 
4975       IF c_references%NOTFOUND
4976       THEN
4977 IF (g_debug > 0 ) THEN
4978 		csd_gen_utility_pvt.add('No data found for l_object_type_code  ='||l_object_type_code);
4979 END IF;
4980 
4981           -- NULL;
4982       END IF;
4983 
4984       SELECT DECODE (l_where_clause, NULL, '  ', l_where_clause || ' AND
4985 ')
4986         INTO
4987              l_where_clause
4988         FROM dual;
4989       sql_stmt := ' SELECT ' ||
4990                   l_name_column ||
4991                   ' from ' ||
4992                   l_from_clause ||
4993                   '  where ' ||
4994                   l_where_clause ||
4995                   l_id_column ||
4996                   ' = :object_id ';
4997       EXECUTE IMMEDIATE sql_stmt
4998          INTO l_object_name
4999          USING p_object_id;
5000       RETURN l_object_name;
5001 
5002    EXCEPTION
5003       WHEN fnd_api.g_exc_unexpected_error
5004       THEN
5005          RETURN NULL;
5006       WHEN NO_DATA_FOUND
5007       THEN
5008          RETURN NULL;
5009       WHEN OTHERS
5010       THEN
5011          RETURN NULL;
5012 END get_res_name;
5013 
5014 --------gilam changes---------
5015 -- bug 3044659--
5016 /*----------------------------------------------------------------*/
5017 /* procedure name: GET_RO_DEFAULT_CURR_PL                         */
5018 /* description  : Gets the price list from contract (default      */
5019 /*                contract if null), if not, default price list   */
5020 /*                from profile option.                            */
5021 /*                                                                */
5022 /* p_api_version                Standard IN param                 */
5023 /* p_init_msg_list              Standard IN param                 */
5024 /* p_incident_id                Service Request ID                */
5025 /* p_repair_type_id             Repair Type ID                    */
5026 /* p_ro_contract_line_id        RO Contract Line ID               */
5027 /* x_contract_pl_id    		Contract Price List		  */
5028 /* x_profile_pl_id		Profile Option Price List         */
5029 /* x_currency_code              RO Currency                       */
5030 /* x_return_status              Standard OUT param                */
5031 /* x_msg_count                  Standard OUT param                */
5032 /* x_msg_data                   Standard OUT param                */
5033 /*                                                                */
5034 /*----------------------------------------------------------------*/
5035 PROCEDURE GET_RO_DEFAULT_CURR_PL
5036 (
5037   p_api_version        		IN  NUMBER,
5038   p_init_msg_list      		IN  VARCHAR2,
5039   p_incident_id 	    	IN  NUMBER,
5040   p_repair_type_id	    	IN  NUMBER,
5041   p_ro_contract_line_id    	IN  NUMBER,
5042   x_contract_pl_id    		OUT NOCOPY NUMBER,
5043   x_profile_pl_id    		OUT NOCOPY NUMBER,
5044   x_currency_code	        OUT NOCOPY VARCHAR2,
5045   x_return_status      		OUT NOCOPY VARCHAR2,
5046   x_msg_count          		OUT NOCOPY NUMBER,
5047   x_msg_data           		OUT NOCOPY VARCHAR2
5048 )
5049 
5050 IS
5051   l_api_name                	CONSTANT VARCHAR2(30) := 'GET_RO_DEFAULT_CURR_PL';
5052   l_api_version	            	CONSTANT NUMBER := 1.0;
5053 
5054   l_bus_process_id 		NUMBER := NULL;
5055 
5056   -- gilam: bug 3512619 - commented out sr contract and added flags for checking contract and its bp price list
5057   --l_sr_contract_line_id	NUMBER := NULL;
5058   l_use_contract_bp_pl		BOOLEAN;
5059   --
5060 
5061   l_contract_line_id		NUMBER := NULL;
5062   l_billing_pl_id		NUMBER := NULL;
5063   l_profile_pl_id		NUMBER := fnd_profile.value('CSD_DEFAULT_PRICE_LIST');
5064   l_use_pl			BOOLEAN;
5065   l_date			DATE := sysdate;
5066   l_pl_out_tbl			OKS_CON_COVERAGE_PUB.pricing_tbl_type;
5067   i				NUMBER := 1;
5068 
5069   -- gilam: bug 3479944 - get price list from repair type
5070   CURSOR c_rt_pl_id(p_repair_type_id number) IS
5071         SELECT price_list_header_id
5072           FROM csd_repair_types_b
5073          WHERE repair_type_id = p_repair_type_id;
5074   -- gilam: bug 3479944
5075 
5076 BEGIN
5077 
5078   --debug msg
5079   IF (g_debug > 0 ) THEN
5080     csd_gen_utility_pvt.ADD ('GET_RO_DEFAULT_CURR_PL Begins');
5081   END IF;
5082 
5083   -- Standard Start of API savepoint
5084   SAVEPOINT GET_RO_DEFAULT_CURR_PL;
5085 
5086   -- Standard call to check for call compatibility.
5087   IF NOT FND_API.Compatible_API_Call (l_api_version,
5088                                       p_api_version,
5089                                       l_api_name,
5090                                       G_PKG_NAME)
5091   THEN
5092     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5093   END IF;
5094 
5095   -- Initialize message list if p_init_msg_list is set to TRUE.
5096   IF FND_API.to_Boolean(p_init_msg_list) THEN
5097     FND_MSG_PUB.initialize;
5098   END IF;
5099 
5100   -- Initialize API return status to success
5101   x_return_status := FND_API.G_RET_STS_SUCCESS;
5102 
5103   --
5104   -- Begin API Body
5105   --
5106 
5107   IF (g_debug > 0 ) THEN
5108     csd_gen_utility_pvt.dump_api_info ( p_pkg_name  => G_PKG_NAME,
5109     				      p_api_name  => l_api_name );
5110   END IF;
5111 
5112   --debug msg
5113   IF (g_debug > 0 ) THEN
5114      csd_gen_utility_pvt.ADD ('Check required parameters and validate them');
5115   END IF;
5116 
5117   -- Check the required parameters
5118   CSD_PROCESS_UTIL.Check_Reqd_Param
5119   ( p_param_value	=> p_repair_type_id,
5120     p_param_name	=> 'REPAIR_TYPE_ID',
5121     p_api_name	  	=> l_api_name);
5122 
5123   -- Validate the repair type ID
5124   IF NOT( CSD_PROCESS_UTIL.Validate_repair_type_id ( p_repair_type_id  => p_repair_type_id )) THEN
5125     RAISE FND_API.G_EXC_ERROR;
5126   END IF;
5127 
5128   -- Validate the incident ID
5129   IF (p_incident_id IS NOT NULL) THEN
5130     IF NOT( CSD_PROCESS_UTIL.Validate_incident_id ( p_incident_id  => p_incident_id )) THEN
5131       RAISE FND_API.G_EXC_ERROR;
5132     END IF;
5133   END IF;
5134 
5135   --debug msg
5136   IF (g_debug > 0 ) THEN
5137      csd_gen_utility_pvt.ADD ('Check required parameters and validation complete');
5138   END IF;
5139 
5140 
5141   --debug msg
5142   IF (g_debug > 0 ) THEN
5143      csd_gen_utility_pvt.ADD ('Get business process');
5144   END IF;
5145 
5146   BEGIN
5147 
5148      SELECT business_process_id
5149      INTO l_bus_process_id
5150      FROM csd_repair_types_b
5151      WHERE repair_type_id = p_repair_type_id;
5152 
5153   EXCEPTION
5154 
5155      WHEN others THEN
5156        FND_MESSAGE.SET_NAME('CSD','CSD_API_RO_CURR_AND_PL');
5157        FND_MESSAGE.SET_TOKEN('REPAIR_TYPE_ID', p_repair_type_id);
5158        FND_MSG_PUB.Add;
5159        RAISE FND_API.G_EXC_ERROR;
5160 
5161   END;
5162 
5163   /* gilam: bug 3512619 - logic changed, no longer checking for sr contract
5164   -- If sr is passed, get sr contract
5165   -- If there is a sr contract, get price list from sr contract and derive currency
5166   -- If there is no sr contract, look at ro
5167   -- If ro contract is passed in, get price list from ro contract and derive currency
5168   -- If contract does not have price list, get default price list set in profile option and derive currency
5169   -- If user did not set default price list, null will be returned
5170 
5171   --debug msg
5172   IF (g_debug > 0 ) THEN
5173      csd_gen_utility_pvt.ADD ('Get SR contract');
5174   END IF;
5175 
5176   -- Incident ID is passed in, get SR contract
5177   IF (p_incident_id IS NOT NULL) THEN
5178 
5179 
5180    BEGIN
5181 
5182     -- get SR contract using incident id
5183     SELECT contract_service_id
5184     INTO l_sr_contract_line_id
5185     FROM cs_incidents
5186     WHERE incident_id = p_incident_id;
5187 
5188    EXCEPTION
5189 
5190     WHEN no_data_found THEN
5191       FND_MESSAGE.SET_NAME('CSD','CSD_API_RO_CURR_AND_PL');
5192       FND_MESSAGE.SET_TOKEN('INCIDENT_ID',p_incident_id);
5193       FND_MSG_PUB.Add;
5194       RAISE FND_API.G_EXC_ERROR;
5195 
5196     WHEN too_many_rows THEN
5197       FND_MESSAGE.SET_NAME('CSD','CSD_API_RO_CURR_AND_PL');
5198       FND_MESSAGE.SET_TOKEN('INCIDENT_ID',p_incident_id);
5199       FND_MSG_PUB.Add;
5200       RAISE FND_API.G_EXC_ERROR;
5201 
5202      WHEN others THEN
5203       FND_MESSAGE.SET_NAME('CSD','CSD_API_RO_CURR_AND_PL');
5204       FND_MESSAGE.SET_TOKEN('INCIDENT_ID',p_incident_id);
5205       FND_MSG_PUB.Add;
5206       RAISE FND_API.G_EXC_ERROR;
5207 
5208    END;
5209 
5210   END IF;
5211 
5212    -- RO contract is same as that of SR
5213    IF ((l_sr_contract_line_id IS NOT NULL) and (p_ro_contract_line_id IS NOT NULL)
5214    and (l_sr_contract_line_id = p_ro_contract_line_id)) THEN
5215 
5216      l_contract_line_id := l_sr_contract_line_id;
5217 
5218    -- RO contract is different from that of SR
5219    ELSIF ((l_sr_contract_line_id IS NOT NULL) and (p_ro_contract_line_id IS NOT NULL)
5220    and (l_sr_contract_line_id <> p_ro_contract_line_id)) THEN
5221 
5222      l_contract_line_id := p_ro_contract_line_id;
5223 
5224    -- SR has contract, but RO does not
5225    ELSIF ((l_sr_contract_line_id IS NOT NULL) and (p_ro_contract_line_id IS NULL)) THEN
5226 
5227      l_contract_line_id := l_sr_contract_line_id;
5228 
5229    -- SR does not have a contract, but RO does
5230    ELSIF ((l_sr_contract_line_id IS NULL) and (p_ro_contract_line_id IS NOT NULL)) THEN
5231 
5232      l_contract_line_id := p_ro_contract_line_id;
5233 
5234    END IF;
5235 
5236    IF ((l_sr_contract_line_id IS NOT NULL) or (p_ro_contract_line_id IS NOT NULL)) THEN
5237    */
5238 
5239    -- gilam: bug 3512619 - changed IF condition, added no data found error handling, and changed PL derivation
5240    -- If ro contract is passed in, get bp price list from contract and derive currency
5241    -- If contract does not have bp price list, get contract price list and derive currency (only if
5242    -- if the profile CSD PL Derivation Exclude Contract Header set to 'No' -- see bug#7140580.
5243    -- If the profile CSD PL Derivation Exclude Contract Header set to 'Yes', it will not get
5244    -- the default price list from the Contract header.
5245    -- If there is no price list on the contract or if there is an error, get default price list set in profile option and derive currency
5246    -- gilam: bug 3479944 - added repair type price list default option
5247    -- If user did not set default price list, get repair type price list and derive currency
5248    -- If repair type price list is not set, null will be returned
5249 
5250    IF (p_ro_contract_line_id IS NOT NULL) THEN
5251 
5252     --debug msg
5253     IF (g_debug > 0 ) THEN
5254       csd_gen_utility_pvt.ADD ('Call OKS_Con_Coverage_PUB.Get_BP_PriceList API: ro contract ='|| p_ro_contract_line_id);
5255     END IF;
5256 
5257     BEGIN
5258 
5259       -- Call OKS_Con_Coverage_PUB.Get_BP_PriceList API
5260       OKS_CON_COVERAGE_PUB.GET_BP_PRICELIST
5261       (
5262     	p_api_version       	=> l_api_version,
5263 	p_init_msg_list     	=> 'T',
5264     	p_contract_line_id  	=> p_ro_contract_line_id,
5265         p_business_process_id   => l_bus_process_id,
5266         p_request_date		=> l_date,
5267         x_return_status 	=> x_return_status,
5268         x_msg_count     	=> x_msg_count,
5269         x_msg_data      	=> x_msg_data,
5270         x_pricing_tbl		=> l_pl_out_tbl
5271       );
5272 
5273       --debug msg
5274       IF (g_debug > 0 ) THEN
5275         csd_gen_utility_pvt.ADD ('Call OKS API to get price list: return status ='|| x_return_status);
5276         csd_gen_utility_pvt.ADD ('l_pl_out_tbl(i).bp_price_list_id: '|| l_pl_out_tbl(i).bp_price_list_id);
5277       END IF;
5278 
5279     EXCEPTION
5280 
5281       WHEN no_data_found THEN
5282 
5283         l_use_contract_bp_pl := FALSE;
5284 
5285     END;
5286 
5287     IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5288 
5289       -- only 1 row should be returned
5290       IF (l_pl_out_tbl.COUNT = 1) THEN
5291 
5292         -- contract has bp price list
5293         IF (l_pl_out_tbl(i).bp_price_list_id IS NOT NULL) THEN
5294 
5295             l_use_contract_bp_pl := TRUE;
5296 
5297         -- contract does not have bp price list
5298         ELSE
5299 
5300             l_use_contract_bp_pl := FALSE;
5301 
5302             IF (l_pl_out_tbl(i).contract_price_list_id IS NOT NULL) THEN
5303 
5304                l_billing_pl_id := l_pl_out_tbl(i).contract_price_list_id;
5305 
5306             END IF;
5307 
5308         END IF;
5309 
5310       ELSE
5311 
5312         -- contract does not have any price list or has errors, set flag to false
5313         l_use_contract_bp_pl := FALSE;
5314 
5315       END IF;
5316 
5317     ELSIF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
5318 
5319       -- contract has errors, set flag to false
5320       l_use_contract_bp_pl := FALSE;
5321 
5322     END IF;
5323 
5324    /* gilam - bug 3512619 - no need to check for SR contract
5325    -- both SR and RO do not have a contract
5326    --sangigup 3361671
5327    -- ELSIF ((p_incident_id IS NULL) and (p_ro_contract_line_id IS NULL)) THEN
5328    ELSIF ((l_sr_contract_line_id is null ) and (p_ro_contract_line_id IS NULL)) THEN
5329    --sangigup 3361671
5330    */
5331 
5332   -- no contract has passed in
5333   ELSE
5334 
5335      l_use_contract_bp_pl := FALSE;
5336 
5337   END IF;
5338 
5339   -- 1) if contract business process price list should be used
5340   IF (l_use_contract_bp_pl) THEN
5341 
5342       x_contract_pl_id := l_pl_out_tbl(i).bp_price_list_id;
5343       x_currency_code := CSD_CHARGE_LINE_UTIL.Get_PLCurrCode(x_contract_pl_id);
5344       x_profile_pl_id := NULL;
5345 
5346   ELSE
5347 
5348 
5349       -- 2) else if contract price list exists
5350         --bug#7140580 if the profile CSD PL_Derivation Exclude Contract Header
5351         --set to 'Yes', then we will not get the default price list from
5352         --the contract header.
5353           --bug#7140580
5354       IF (l_billing_pl_id IS NOT NULL) and ((nvl(FND_PROFILE.VALUE('CSD_PL_DR_EXCLUDE_CONTRACT_H'), 'N')) = 'N') then
5355 
5356         x_contract_pl_id := l_billing_pl_id;
5357         x_currency_code := CSD_CHARGE_LINE_UTIL.Get_PLCurrCode(x_contract_pl_id);
5358         x_profile_pl_id := NULL;
5359 
5360       -- 3) else get price list from profile option
5361       ELSE
5362 
5363         x_contract_pl_id := null;
5364 
5365         -- if profile option is set
5366         IF (l_profile_pl_id IS NOT NULL) THEN
5367 
5368           x_profile_pl_id := l_profile_pl_id;
5369           x_currency_code := CSD_CHARGE_LINE_UTIL.Get_PLCurrCode(l_profile_pl_id);
5370 
5371         -- gilam: bug 3479944 - added repair type price list default option
5372         -- 4) else get repair type price list
5373         ELSE
5374 
5375           open c_rt_pl_id(p_repair_type_id);
5376           fetch c_rt_pl_id into l_profile_pl_id;
5377 
5378             -- if repair type price list is set
5379             IF(c_rt_pl_id%FOUND) THEN
5380 
5381                x_profile_pl_id := l_profile_pl_id;
5382                x_currency_code := CSD_CHARGE_LINE_UTIL.Get_PLCurrCode(l_profile_pl_id);
5383 
5384             -- 5) else return nothing
5385             ELSE
5386 
5387                x_profile_pl_id := NULL;
5388                x_currency_code := NULL;
5389 
5390             END IF;
5391 
5392             close c_rt_pl_id;
5393 
5394         -- gilam; end bug 3479944
5395         END IF;
5396 
5397       END IF;
5398 
5399    END IF;
5400 
5401  -- gilam: end bug 3512619
5402 
5403  --debug msg
5404  IF (g_debug > 0 ) THEN
5405    csd_gen_utility_pvt.ADD ('GET_RO_DEFAULT_CURR_PL Ends');
5406  END IF;
5407 
5408  -- API body ends here
5409 
5410  EXCEPTION
5411 
5412    WHEN FND_API.G_EXC_ERROR THEN
5413      ROLLBACK TO GET_RO_DEFAULT_CURR_PL;
5414      x_return_status := FND_API.G_RET_STS_ERROR ;
5415      FND_MSG_PUB.Count_And_Get (p_count  =>  x_msg_count,
5416                                 p_data   =>  x_msg_data);
5417 
5418    WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5419      ROLLBACK TO GET_RO_DEFAULT_CURR_PL;
5420      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5421      FND_MSG_PUB.Count_And_Get (p_count  =>  x_msg_count,
5422                                 p_data   =>  x_msg_data );
5423 
5424    WHEN OTHERS THEN
5425      ROLLBACK TO GET_RO_DEFAULT_CURR_PL;
5426      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5427      IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5428        FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME ,
5429                                 l_api_name  );
5430      END IF;
5431      FND_MSG_PUB.Count_And_Get (p_count  =>  x_msg_count,
5432                                 p_data   =>  x_msg_data );
5433 
5434 
5435 END GET_RO_DEFAULT_CURR_PL;
5436 ----------gilam changes------
5437 
5438 
5439 ----------travi changes------
5440 
5441 --bug#3875036
5442 
5443 PROCEDURE GET_CHARGE_SELLING_PRICE
5444               (p_inventory_item_id    in  NUMBER,
5445 			p_price_list_header_id in  NUMBER,
5446 			p_unit_of_measure_code in  VARCHAR2,
5447 			p_currency_code        in  VARCHAR2,
5448 			p_quantity_required    in  NUMBER,
5449 			p_account_id		   in  NUMBER DEFAULT null,			--bug#3875036
5450 			p_org_id               in  NUMBER, -- added for R12
5451                   p_pricing_rec          in  CSD_PROCESS_UTIL.PRICING_ATTR_REC,
5452 			x_selling_price        OUT NOCOPY NUMBER,
5453 			x_return_status        OUT NOCOPY VARCHAR2,
5454                   x_msg_count            OUT NOCOPY NUMBER,
5455                   x_msg_data             OUT NOCOPY VARCHAR2)
5456 IS
5457 
5458     -- swai: bug 11730709  (FP of bug#11720454)
5459     l_pricelist_comment VARCHAR2(1);
5460     l_dynamic_formula   VARCHAR2(1);
5461     --check if the price list has comments end with 999..
5462     --this is coments define for ISC customer.
5463     --It is special char define for the pricelist
5464     --if customer wants to call order Capture price API
5465     CURSOR get_pricelist_comment(p_list_header_id NUMBER)
5466     IS
5467         SELECT 'Y' FROM QP_LIST_HEADERS_B
5468         WHERE LIST_HEADER_ID = p_list_header_id
5469              AND COMMENTS LIKE '%999';
5470 
5471     --check if this pricelist has any dynamic formula
5472     --attached to it.
5473     CURSOR has_dynamic_formula(p_list_header_id NUMBER)
5474     IS
5475         SELECT 'Y' FROM QP_LIST_LINES_V
5476         WHERE LIST_HEADER_ID =p_list_header_id
5477         AND PRICE_BY_FORMULA_ID IS NOT NULL AND ROWNUM < 2;
5478     -- end swai: bug 11730709  (FP of bug#11720454)
5479 
5480 BEGIN
5481 
5482 -- old  x_return_status := 'S';
5483   -- Initialize API return status to success
5484   x_return_status := FND_API.G_RET_STS_SUCCESS;
5485 
5486    -- swai: bug 11730709  (FP of bug#11720454)
5487    --this check if the only the both of the profile set to YES.
5488    --the pricelist has comments end of '999',
5489    --and the pricelist has any dynmaic formula attached to it.
5490    --then, we will call Charge/Order Capture pricing API
5491   IF ((NVL(FND_PROFILE.VALUE('CSD_ENABLE_ADVANCED_PRICING'), 'N')='Y')
5492     and (NVL(FND_PROFILE.VALUE('CSD_ENABLE_DYNAMIC_FORMULA'), 'N')='Y'))  THEN
5493 
5494         open get_pricelist_comment(p_price_list_header_id);
5495         fetch get_pricelist_comment into l_pricelist_comment;
5496         close get_pricelist_comment;
5497 
5498         if (NVL(l_pricelist_comment, 'N') = 'Y') then
5499             open has_dynamic_formula(p_price_list_header_id);
5500             fetch has_dynamic_formula into l_dynamic_formula;
5501             close has_dynamic_formula;
5502         end if;
5503   END IF;
5504   -- end swai: bug 11730709  (FP of bug#11720454)
5505 
5506 --bug#3875036
5507   IF((NVL(FND_PROFILE.VALUE('CSD_ENABLE_ADVANCED_PRICING'), 'N')='N') or (NVL(l_dynamic_formula, 'N') = 'Y'))  THEN   -- swai: bug 11730709  (FP of bug#11720454)
5508 
5509 	  Cs_Pricing_Item_Pkg.Call_Pricing_Item
5510 		   (p_inventory_item_id     => p_inventory_item_id,
5511 		  p_price_list_id         => p_price_list_header_id,
5512 		  p_uom_code              => p_unit_of_measure_code,
5513 		  p_currency_code         => p_currency_code,
5514 		  p_quantity              => p_quantity_required,
5515 		  p_org_id	            => p_org_id, -- Aded for R12
5516 			-- Pricing attributes
5517 		  p_pricing_context       => p_pricing_rec.pricing_context,
5518 		  p_pricing_attribute1    => p_pricing_rec.pricing_attribute1,
5519 		  p_pricing_attribute2    => p_pricing_rec.pricing_attribute2,
5520 		  p_pricing_attribute3    => p_pricing_rec.pricing_attribute3,
5521 		  p_pricing_attribute4    => p_pricing_rec.pricing_attribute4,
5522 		  p_pricing_attribute5    => p_pricing_rec.pricing_attribute5,
5523 		  p_pricing_attribute6    => p_pricing_rec.pricing_attribute6,
5524 		  p_pricing_attribute7    => p_pricing_rec.pricing_attribute7,
5525 		  p_pricing_attribute8    => p_pricing_rec.pricing_attribute8,
5526 		  p_pricing_attribute9    => p_pricing_rec.pricing_attribute9,
5527 		  p_pricing_attribute10   => p_pricing_rec.pricing_attribute10,
5528 		  p_pricing_attribute11   => p_pricing_rec.pricing_attribute11,
5529 		  p_pricing_attribute12   => p_pricing_rec.pricing_attribute12,
5530 		  p_pricing_attribute13   => p_pricing_rec.pricing_attribute13,
5531 		  p_pricing_attribute14   => p_pricing_rec.pricing_attribute14,
5532 		  p_pricing_attribute15   => p_pricing_rec.pricing_attribute15,
5533 		  p_pricing_attribute16   => p_pricing_rec.pricing_attribute16,
5534 		  p_pricing_attribute17   => p_pricing_rec.pricing_attribute17,
5535 		  p_pricing_attribute18   => p_pricing_rec.pricing_attribute18,
5536 		  p_pricing_attribute19   => p_pricing_rec.pricing_attribute19,
5537 		  p_pricing_attribute20   => p_pricing_rec.pricing_attribute20,
5538 		  p_pricing_attribute21   => p_pricing_rec.pricing_attribute21,
5539 		  p_pricing_attribute22   => p_pricing_rec.pricing_attribute22,
5540 		  p_pricing_attribute23   => p_pricing_rec.pricing_attribute23,
5541 		  p_pricing_attribute24   => p_pricing_rec.pricing_attribute24,
5542 		  p_pricing_attribute25   => p_pricing_rec.pricing_attribute25,
5543 		  p_pricing_attribute26   => p_pricing_rec.pricing_attribute26,
5544 		  p_pricing_attribute27   => p_pricing_rec.pricing_attribute27,
5545 		  p_pricing_attribute28   => p_pricing_rec.pricing_attribute28,
5546 		  p_pricing_attribute29   => p_pricing_rec.pricing_attribute29,
5547 		  p_pricing_attribute30   => p_pricing_rec.pricing_attribute30,
5548 		  p_pricing_attribute31   => p_pricing_rec.pricing_attribute31,
5549 		  p_pricing_attribute32   => p_pricing_rec.pricing_attribute32,
5550 		  p_pricing_attribute33   => p_pricing_rec.pricing_attribute33,
5551 		  p_pricing_attribute34   => p_pricing_rec.pricing_attribute34,
5552 		  p_pricing_attribute35   => p_pricing_rec.pricing_attribute35,
5553 		  p_pricing_attribute36   => p_pricing_rec.pricing_attribute36,
5554 		  p_pricing_attribute37   => p_pricing_rec.pricing_attribute37,
5555 		  p_pricing_attribute38   => p_pricing_rec.pricing_attribute38,
5556 		  p_pricing_attribute39   => p_pricing_rec.pricing_attribute39,
5557 		  p_pricing_attribute40   => p_pricing_rec.pricing_attribute40,
5558 		  p_pricing_attribute41   => p_pricing_rec.pricing_attribute41,
5559 		  p_pricing_attribute42   => p_pricing_rec.pricing_attribute42,
5560 		  p_pricing_attribute43   => p_pricing_rec.pricing_attribute43,
5561 		  p_pricing_attribute44   => p_pricing_rec.pricing_attribute44,
5562 		  p_pricing_attribute45   => p_pricing_rec.pricing_attribute45,
5563 		  p_pricing_attribute46   => p_pricing_rec.pricing_attribute46,
5564 		  p_pricing_attribute47   => p_pricing_rec.pricing_attribute47,
5565 		  p_pricing_attribute48   => p_pricing_rec.pricing_attribute48,
5566 		  p_pricing_attribute49   => p_pricing_rec.pricing_attribute49,
5567 		  p_pricing_attribute50   => p_pricing_rec.pricing_attribute50,
5568 		  p_pricing_attribute51   => p_pricing_rec.pricing_attribute51,
5569 		  p_pricing_attribute52   => p_pricing_rec.pricing_attribute52,
5570 		  p_pricing_attribute53   => p_pricing_rec.pricing_attribute53,
5571 		  p_pricing_attribute54   => p_pricing_rec.pricing_attribute54,
5572 		  p_pricing_attribute55   => p_pricing_rec.pricing_attribute55,
5573 		  p_pricing_attribute56   => p_pricing_rec.pricing_attribute56,
5574 		  p_pricing_attribute57   => p_pricing_rec.pricing_attribute57,
5575 		  p_pricing_attribute58   => p_pricing_rec.pricing_attribute58,
5576 		  p_pricing_attribute59   => p_pricing_rec.pricing_attribute59,
5577 		  p_pricing_attribute60   => p_pricing_rec.pricing_attribute60,
5578 		  p_pricing_attribute61   => p_pricing_rec.pricing_attribute61,
5579 		  p_pricing_attribute62   => p_pricing_rec.pricing_attribute62,
5580 		  p_pricing_attribute63   => p_pricing_rec.pricing_attribute63,
5581 		  p_pricing_attribute64   => p_pricing_rec.pricing_attribute64,
5582 		  p_pricing_attribute65   => p_pricing_rec.pricing_attribute65,
5583 		  p_pricing_attribute66   => p_pricing_rec.pricing_attribute66,
5584 		  p_pricing_attribute67   => p_pricing_rec.pricing_attribute67,
5585 		  p_pricing_attribute68   => p_pricing_rec.pricing_attribute68,
5586 		  p_pricing_attribute69   => p_pricing_rec.pricing_attribute69,
5587 		  p_pricing_attribute70   => p_pricing_rec.pricing_attribute70,
5588 		  p_pricing_attribute71   => p_pricing_rec.pricing_attribute71,
5589 		  p_pricing_attribute72   => p_pricing_rec.pricing_attribute72,
5590 		  p_pricing_attribute73   => p_pricing_rec.pricing_attribute73,
5591 		  p_pricing_attribute74   => p_pricing_rec.pricing_attribute74,
5592 		  p_pricing_attribute75   => p_pricing_rec.pricing_attribute75,
5593 		  p_pricing_attribute76   => p_pricing_rec.pricing_attribute76,
5594 		  p_pricing_attribute77   => p_pricing_rec.pricing_attribute77,
5595 		  p_pricing_attribute78   => p_pricing_rec.pricing_attribute78,
5596 		  p_pricing_attribute79   => p_pricing_rec.pricing_attribute79,
5597 		  p_pricing_attribute80   => p_pricing_rec.pricing_attribute80,
5598 		  p_pricing_attribute81   => p_pricing_rec.pricing_attribute81,
5599 		  p_pricing_attribute82   => p_pricing_rec.pricing_attribute82,
5600 		  p_pricing_attribute83   => p_pricing_rec.pricing_attribute83,
5601 		  p_pricing_attribute84   => p_pricing_rec.pricing_attribute84,
5602 		  p_pricing_attribute85   => p_pricing_rec.pricing_attribute85,
5603 		  p_pricing_attribute86   => p_pricing_rec.pricing_attribute86,
5604 		  p_pricing_attribute87   => p_pricing_rec.pricing_attribute87,
5605 		  p_pricing_attribute88   => p_pricing_rec.pricing_attribute88,
5606 		  p_pricing_attribute89   => p_pricing_rec.pricing_attribute89,
5607 		  p_pricing_attribute90   => p_pricing_rec.pricing_attribute90,
5608 		  p_pricing_attribute91   => p_pricing_rec.pricing_attribute91,
5609 		  p_pricing_attribute92   => p_pricing_rec.pricing_attribute92,
5610 		  p_pricing_attribute93   => p_pricing_rec.pricing_attribute93,
5611 		  p_pricing_attribute94   => p_pricing_rec.pricing_attribute94,
5612 		  p_pricing_attribute95   => p_pricing_rec.pricing_attribute95,
5613 		  p_pricing_attribute96   => p_pricing_rec.pricing_attribute96,
5614 		  p_pricing_attribute97   => p_pricing_rec.pricing_attribute97,
5615 		  p_pricing_attribute98   => p_pricing_rec.pricing_attribute98,
5616 		  p_pricing_attribute99   => p_pricing_rec.pricing_attribute99,
5617 		  p_pricing_attribute100  => p_pricing_rec.pricing_attribute100,
5618 		  x_list_price            => x_selling_price,
5619 			x_return_status         => x_return_status,
5620 			x_msg_count             => x_msg_count,
5621 			x_msg_data              => x_msg_data);
5622 
5623 		   IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5624 			   IF (g_debug > 0 ) THEN
5625 				   csd_gen_utility_pvt.ADD('Cs_Pricing_Item_Pkg.Call_Pricing_Item failed');
5626 			   END IF;
5627 			   -- Shiv Ragunathan, 2/26/04, While fixing FP bug 3449351, noticed
5628 			 -- that this exception gets raised and is not handled in the API,
5629 			 -- Since the error status is being returned, no need to raise the
5630 			 -- exception, hence commenting it out
5631 			   -- RAISE FND_API.G_EXC_ERROR;
5632 		   END IF;
5633 
5634 		ELSE
5635 	/* bug#3875036 */
5636 			PRICE_REQUEST(
5637 				p_inventory_item_id		=>	p_inventory_item_id,
5638 				p_price_list_header_id	=>	p_price_list_header_id,
5639 				p_unit_of_measure_code	=>	p_unit_of_measure_code,
5640 				p_currency_code			=>	p_currency_code,
5641 				p_quantity_required		=>	p_quantity_required,
5642 				p_account_id			=>	p_account_id,
5643 				p_pricing_rec			=>	p_pricing_rec,
5644 				x_selling_price			=>	x_selling_price,
5645 				x_return_status			=>	x_return_status,
5646 				x_msg_count				=>	x_msg_count,
5647 				x_msg_data				=>	x_msg_data);
5648 
5649 				IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5650 				   IF (g_debug > 0 ) THEN
5651 					   csd_gen_utility_pvt.ADD('CSD_PROCESS_UTIL.PRICE_REQUEST failed');
5652 				   END IF;
5653 				END IF;
5654 
5655 		END IF;
5656 
5657 
5658       -- Standard call to get message count and IF count is  get message info.
5659       FND_MSG_PUB.Count_And_Get
5660            (p_count  =>  x_msg_count,
5661             p_data   =>  x_msg_data );
5662 
5663 END GET_CHARGE_SELLING_PRICE;
5664 
5665 /* bug#3875036 */
5666 PROCEDURE PRICE_REQUEST
5667            (p_inventory_item_id    in  NUMBER,
5668 			p_price_list_header_id in  NUMBER,
5669 			p_unit_of_measure_code in  VARCHAR2,
5670 			p_currency_code        in  VARCHAR2,
5671 			p_quantity_required    in  NUMBER,
5672 			p_account_id		   in  NUMBER DEFAULT null,
5673             p_pricing_rec          in  CSD_PROCESS_UTIL.PRICING_ATTR_REC,
5674 			x_selling_price        OUT NOCOPY NUMBER,
5675 			x_return_status        OUT NOCOPY VARCHAR2,
5676             x_msg_count            OUT NOCOPY NUMBER,
5677             x_msg_data             OUT NOCOPY VARCHAR2)
5678 IS
5679  p_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE;
5680  p_qual_tbl                  QP_PREQ_GRP.QUAL_TBL_TYPE;
5681  p_line_attr_tbl             QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
5682  p_LINE_DETAIL_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
5683  p_LINE_DETAIL_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
5684  p_LINE_DETAIL_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
5685  p_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
5686  p_control_rec               QP_PREQ_GRP.CONTROL_RECORD_TYPE;
5687  x_line_tbl                  QP_PREQ_GRP.LINE_TBL_TYPE;
5688  x_line_qual                 QP_PREQ_GRP.QUAL_TBL_TYPE;
5689  x_line_attr_tbl             QP_PREQ_GRP.LINE_ATTR_TBL_TYPE;
5690  x_line_detail_tbl           QP_PREQ_GRP.LINE_DETAIL_TBL_TYPE;
5691  x_line_detail_qual_tbl      QP_PREQ_GRP.LINE_DETAIL_QUAL_TBL_TYPE;
5692  x_line_detail_attr_tbl      QP_PREQ_GRP.LINE_DETAIL_ATTR_TBL_TYPE;
5693  x_related_lines_tbl         QP_PREQ_GRP.RELATED_LINES_TBL_TYPE;
5694 -- x_return_status             VARCHAR2(240);
5695  x_return_status_text        VARCHAR2(240);
5696  qual_rec                    QP_PREQ_GRP.QUAL_REC_TYPE;
5697  line_attr_rec               QP_PREQ_GRP.LINE_ATTR_REC_TYPE;
5698  line_rec                    QP_PREQ_GRP.LINE_REC_TYPE;
5699  rltd_rec                    QP_PREQ_GRP.RELATED_LINES_REC_TYPE;
5700 
5701 
5702  I BINARY_INTEGER;
5703  l_version VARCHAR2(240);
5704 
5705 
5706  l_Price_attr_tbl  			ASO_QUOTE_PUB.Price_Attributes_Tbl_Type := ASO_QUOTE_PUB.G_Miss_Price_Attributes_Tbl;
5707 
5708   -- swai: bugs 12326261,11696607,11739294,11730709
5709   -- These are FPs of bugs 7284767, 10259354, 11739278, 11720454
5710   ln_category_id number;
5711 
5712   CURSOR get_category(p_item_id NUMBER)
5713   IS
5714   SELECT MIC.CATEGORY_ID
5715   FROM  MTL_DEFAULT_CATEGORY_SETS MDCS,
5716               mtl_item_categories MIC
5717   WHERE   MDCS.FUNCTIONAL_AREA_ID=7
5718     AND MDCS.CATEGORY_SET_ID=MIC.CATEGORY_SET_ID
5719     AND MIC.INVENTORY_ITEM_ID=p_item_id
5720     and MIC.organization_id = cs_std.get_item_valdn_orgzn_Id;
5721 
5722   --end swai: bugs 12326261,11696607,11739294,bug#11730709
5723 
5724 BEGIN
5725 
5726 -- The statments below help the user in turning debug on
5727 -- The user needs to set the oe_debug_pub.G_DIR value.
5728 -- This value can be found by executing the following statement
5729 --     select value
5730 --     from   v$parameter
5731 --     where name like 'utl_file_dir%';
5732 -- This might return multiple values , and any one of the values can be taken
5733 -- Make sure that the value of the directory specified , actually exists
5734 
5735 	-- Initialize API return status to success
5736 	x_return_status := FND_API.G_RET_STS_SUCCESS;
5737 
5738 --dbms_output.put_line ('Start time: ' || TO_CHAR(SYSDATE, 'HH24:MI:SSSSS'));
5739 
5740 --oe_debug_pub.SetDebugLevel(10);
5741 	oe_debug_pub.Initialize;
5742 --oe_debug_pub.debug_on;
5743 
5744 -- Passing Information to the Pricing Engine
5745 
5746 
5747   -- Initialize the values of the Pricing line table. Since we are passing
5748    -- one line at a time from the form we hard the line_index to 1
5749    l_price_attr_tbl(1).flex_title           :=  'QP_ATTR_DEFNS_PRICING';
5750    l_Price_Attr_tbl(1).pricing_context	    :=	p_pricing_rec.pricing_context;
5751    l_Price_Attr_tbl(1).pricing_attribute1	:=	p_pricing_rec.pricing_attribute1;
5752    l_Price_Attr_tbl(1).pricing_attribute2	:=	p_pricing_rec.pricing_attribute2;
5753    l_Price_Attr_tbl(1).pricing_attribute3	:=	p_pricing_rec.pricing_attribute3;
5754    l_Price_Attr_tbl(1).pricing_attribute4	:=	p_pricing_rec.pricing_attribute4;
5755    l_Price_Attr_tbl(1).pricing_attribute5	:=	p_pricing_rec.pricing_attribute5;
5756    l_Price_Attr_tbl(1).pricing_attribute6	:=	p_pricing_rec.pricing_attribute6;
5757    l_Price_Attr_tbl(1).pricing_attribute7	:=	p_pricing_rec.pricing_attribute7;
5758    l_Price_Attr_tbl(1).pricing_attribute8	:=	p_pricing_rec.pricing_attribute8;
5759    l_Price_Attr_tbl(1).pricing_attribute9	:=	p_pricing_rec.pricing_attribute9;
5760    l_Price_Attr_tbl(1).pricing_attribute10	:=	p_pricing_rec.pricing_attribute10;
5761    l_Price_Attr_tbl(1).pricing_attribute11	:=	p_pricing_rec.pricing_attribute11;
5762    l_Price_Attr_tbl(1).pricing_attribute12	:=	p_pricing_rec.pricing_attribute12;
5763    l_Price_Attr_tbl(1).pricing_attribute13	:=	p_pricing_rec.pricing_attribute13;
5764    l_Price_Attr_tbl(1).pricing_attribute14	:=	p_pricing_rec.pricing_attribute14;
5765    l_Price_Attr_tbl(1).pricing_attribute15	:=	p_pricing_rec.pricing_attribute15;
5766    l_Price_Attr_tbl(1).pricing_attribute16	:=	p_pricing_rec.pricing_attribute16;
5767    l_Price_Attr_tbl(1).pricing_attribute17  :=	p_pricing_rec.pricing_attribute17;
5768    l_Price_Attr_tbl(1).pricing_attribute18	:=	p_pricing_rec.pricing_attribute18;
5769    l_Price_Attr_tbl(1).pricing_attribute19	:=	p_pricing_rec.pricing_attribute19;
5770    l_Price_Attr_tbl(1).pricing_attribute20	:=	p_pricing_rec.pricing_attribute20;
5771    l_Price_Attr_tbl(1).pricing_attribute21	:=	p_pricing_rec.pricing_attribute21;
5772    l_Price_Attr_tbl(1).pricing_attribute22	:=	p_pricing_rec.pricing_attribute22;
5773    l_Price_Attr_tbl(1).pricing_attribute23	:=	p_pricing_rec.pricing_attribute23;
5774    l_Price_Attr_tbl(1).pricing_attribute24	:=	p_pricing_rec.pricing_attribute24;
5775    l_Price_Attr_tbl(1).pricing_attribute25	:=	p_pricing_rec.pricing_attribute25;
5776    l_Price_Attr_tbl(1).pricing_attribute26	:=	p_pricing_rec.pricing_attribute26;
5777    l_Price_Attr_tbl(1).pricing_attribute27	:=	p_pricing_rec.pricing_attribute27;
5778    l_Price_Attr_tbl(1).pricing_attribute28	:=	p_pricing_rec.pricing_attribute28;
5779    l_Price_Attr_tbl(1).pricing_attribute29	:=	p_pricing_rec.pricing_attribute29;
5780    l_Price_Attr_tbl(1).pricing_attribute30	:=	p_pricing_rec.pricing_attribute30;
5781    l_Price_Attr_tbl(1).pricing_attribute31	:=	p_pricing_rec.pricing_attribute31;
5782    l_Price_Attr_tbl(1).pricing_attribute32	:=	p_pricing_rec.pricing_attribute32;
5783    l_Price_Attr_tbl(1).pricing_attribute33	:=	p_pricing_rec.pricing_attribute33;
5784    l_Price_Attr_tbl(1).pricing_attribute34	:=	p_pricing_rec.pricing_attribute34;
5785    l_Price_Attr_tbl(1).pricing_attribute35  :=	p_pricing_rec.pricing_attribute35;
5786    l_Price_Attr_tbl(1).pricing_attribute36	:=	p_pricing_rec.pricing_attribute36;
5787    l_Price_Attr_tbl(1).pricing_attribute37	:=	p_pricing_rec.pricing_attribute37;
5788    l_Price_Attr_tbl(1).pricing_attribute38	:=	p_pricing_rec.pricing_attribute38;
5789    l_Price_Attr_tbl(1).pricing_attribute39	:=	p_pricing_rec.pricing_attribute39;
5790    l_Price_Attr_tbl(1).pricing_attribute40	:=	p_pricing_rec.pricing_attribute40;
5791    l_Price_Attr_tbl(1).pricing_attribute41	:=	p_pricing_rec.pricing_attribute41;
5792    l_Price_Attr_tbl(1).pricing_attribute42	:=	p_pricing_rec.pricing_attribute42;
5793    l_Price_Attr_tbl(1).pricing_attribute43	:=	p_pricing_rec.pricing_attribute43;
5794    l_Price_Attr_tbl(1).pricing_attribute44	:=	p_pricing_rec.pricing_attribute44;
5795    l_Price_Attr_tbl(1).pricing_attribute45	:=	p_pricing_rec.pricing_attribute45;
5796    l_Price_Attr_tbl(1).pricing_attribute46	:=	p_pricing_rec.pricing_attribute46;
5797    l_Price_Attr_tbl(1).pricing_attribute47	:=	p_pricing_rec.pricing_attribute47;
5798    l_Price_Attr_tbl(1).pricing_attribute48	:=	p_pricing_rec.pricing_attribute48;
5799    l_Price_Attr_tbl(1).pricing_attribute49	:=	p_pricing_rec.pricing_attribute49;
5800    l_Price_Attr_tbl(1).pricing_attribute50	:=	p_pricing_rec.pricing_attribute50;
5801    l_Price_Attr_tbl(1).pricing_attribute51	:=	p_pricing_rec.pricing_attribute51;
5802    l_Price_Attr_tbl(1).pricing_attribute52	:=	p_pricing_rec.pricing_attribute52;
5803    l_Price_Attr_tbl(1).pricing_attribute53  :=	p_pricing_rec.pricing_attribute53;
5804    l_Price_Attr_tbl(1).pricing_attribute54	:=	p_pricing_rec.pricing_attribute54;
5805    l_Price_Attr_tbl(1).pricing_attribute55	:=	p_pricing_rec.pricing_attribute55;
5806    l_Price_Attr_tbl(1).pricing_attribute56	:=	p_pricing_rec.pricing_attribute56;
5807    l_Price_Attr_tbl(1).pricing_attribute57	:=	p_pricing_rec.pricing_attribute57;
5808    l_Price_Attr_tbl(1).pricing_attribute58	:=	p_pricing_rec.pricing_attribute58;
5809    l_Price_Attr_tbl(1).pricing_attribute59	:=	p_pricing_rec.pricing_attribute59;
5810    l_Price_Attr_tbl(1).pricing_attribute60	:=	p_pricing_rec.pricing_attribute60;
5811    l_Price_Attr_tbl(1).pricing_attribute61	:=	p_pricing_rec.pricing_attribute61;
5812    l_Price_Attr_tbl(1).pricing_attribute62	:=	p_pricing_rec.pricing_attribute62;
5813    l_Price_Attr_tbl(1).pricing_attribute63	:=	p_pricing_rec.pricing_attribute63;
5814    l_Price_Attr_tbl(1).pricing_attribute64	:=	p_pricing_rec.pricing_attribute64;
5815    l_Price_Attr_tbl(1).pricing_attribute65	:=	p_pricing_rec.pricing_attribute65;
5816    l_Price_Attr_tbl(1).pricing_attribute66	:=	p_pricing_rec.pricing_attribute66;
5817    l_Price_Attr_tbl(1).pricing_attribute67	:=	p_pricing_rec.pricing_attribute67;
5818    l_Price_Attr_tbl(1).pricing_attribute68	:=	p_pricing_rec.pricing_attribute68;
5819    l_Price_Attr_tbl(1).pricing_attribute69	:=	p_pricing_rec.pricing_attribute69;
5820    l_Price_Attr_tbl(1).pricing_attribute70	:=	p_pricing_rec.pricing_attribute70;
5821    l_Price_Attr_tbl(1).pricing_attribute71  :=	p_pricing_rec.pricing_attribute71;
5822    l_Price_Attr_tbl(1).pricing_attribute72	:=	p_pricing_rec.pricing_attribute72;
5823    l_Price_Attr_tbl(1).pricing_attribute73	:=	p_pricing_rec.pricing_attribute73;
5824    l_Price_Attr_tbl(1).pricing_attribute74	:=	p_pricing_rec.pricing_attribute74;
5825    l_Price_Attr_tbl(1).pricing_attribute75	:=	p_pricing_rec.pricing_attribute75;
5826    l_Price_Attr_tbl(1).pricing_attribute76	:=	p_pricing_rec.pricing_attribute76;
5827    l_Price_Attr_tbl(1).pricing_attribute77	:=	p_pricing_rec.pricing_attribute77;
5828    l_Price_Attr_tbl(1).pricing_attribute78	:=	p_pricing_rec.pricing_attribute78;
5829    l_Price_Attr_tbl(1).pricing_attribute79	:=	p_pricing_rec.pricing_attribute79;
5830    l_Price_Attr_tbl(1).pricing_attribute80	:=	p_pricing_rec.pricing_attribute80;
5831    l_Price_Attr_tbl(1).pricing_attribute81	:=	p_pricing_rec.pricing_attribute81;
5832    l_Price_Attr_tbl(1).pricing_attribute82	:=	p_pricing_rec.pricing_attribute82;
5833    l_Price_Attr_tbl(1).pricing_attribute83	:=	p_pricing_rec.pricing_attribute83;
5834    l_Price_Attr_tbl(1).pricing_attribute84  :=	p_pricing_rec.pricing_attribute84;
5835    l_Price_Attr_tbl(1).pricing_attribute85	:=	p_pricing_rec.pricing_attribute85;
5836    l_Price_Attr_tbl(1).pricing_attribute86	:=	p_pricing_rec.pricing_attribute86;
5837    l_Price_Attr_tbl(1).pricing_attribute87	:=	p_pricing_rec.pricing_attribute87;
5838    l_Price_Attr_tbl(1).pricing_attribute88	:=	p_pricing_rec.pricing_attribute88;
5839    l_Price_Attr_tbl(1).pricing_attribute89	:=	p_pricing_rec.pricing_attribute89;
5840    l_Price_Attr_tbl(1).pricing_attribute90	:=	p_pricing_rec.pricing_attribute90;
5841    l_Price_Attr_tbl(1).pricing_attribute91	:=	p_pricing_rec.pricing_attribute91;
5842    l_Price_Attr_tbl(1).pricing_attribute92	:=	p_pricing_rec.pricing_attribute92;
5843    l_Price_Attr_tbl(1).pricing_attribute93	:=	p_pricing_rec.pricing_attribute93;
5844    l_Price_Attr_tbl(1).pricing_attribute94	:=	p_pricing_rec.pricing_attribute94;
5845    l_Price_Attr_tbl(1).pricing_attribute95	:=	p_pricing_rec.pricing_attribute95;
5846    l_Price_Attr_tbl(1).pricing_attribute96	:=	p_pricing_rec.pricing_attribute96;
5847    l_Price_Attr_tbl(1).pricing_attribute97	:=	p_pricing_rec.pricing_attribute97;
5848    l_Price_Attr_tbl(1).pricing_attribute98	:=	p_pricing_rec.pricing_attribute98;
5849    l_Price_Attr_tbl(1).pricing_attribute99	:=	p_pricing_rec.pricing_attribute99;
5850    l_Price_Attr_tbl(1).pricing_attribute100 :=	p_pricing_rec.pricing_attribute100;
5851 
5852 
5853    ASO_PRICING_CALLBACK_PVT.Append_asked_for(
5854 	 p_line_index         => 1,
5855 	 p_pricing_attr_tbl   => l_Price_Attr_tbl,
5856 	 px_Req_line_attr_tbl => p_line_attr_tbl,
5857 	 px_Req_qual_tbl      => p_qual_tbl);
5858 
5859 
5860 -- Setting up the control record variables
5861 -- Please refer documentation for explanation of each of these settings
5862 
5863 	p_control_rec.pricing_event := 'LINE';
5864 	p_control_rec.calculate_flag := 'Y';
5865 	p_control_rec.simulation_flag := 'N';
5866 
5867 -- Request Line (Order Line) Information
5868 	--line_rec.request_type_code :='ONT';
5869 	line_rec.request_type_code :='ASO';
5870 	line_rec.line_Index :='1';									-- Request Line Index
5871 	line_rec.line_type_code := 'LINE';							-- LINE or ORDER(Summary Line)
5872 	line_rec.pricing_effective_date := sysdate;					-- Pricing as of what date ?
5873 	line_rec.active_date_first := sysdate;						-- Can be Ordered Date or Ship Date
5874 	line_rec.active_date_second := sysdate;						-- Can be Ordered Date or Ship Date
5875 	line_rec.active_date_first_type := 'NO TYPE';				-- ORD/SHIP
5876 	line_rec.active_date_second_type :='NO TYPE';				-- ORD/SHIP
5877 	line_rec.line_quantity := p_quantity_required;				-- Ordered Quantity
5878 	line_rec.line_uom_code := p_unit_of_measure_code;           -- Ordered UOM Code
5879 	line_rec.currency_code := p_currency_code;		            -- Currency Code
5880 	line_rec.price_flag := 'Y';									-- Price Flag can have 'Y' , 'N'(No pricing) , 'P'(Phase)
5881 	p_line_tbl(1) := line_rec;
5882 
5883 -- If u need to get the price for multiple order lines , please fill the above information for each line
5884 -- and add to the p_line_tbl
5885 
5886 -- Pricing Attributes Passed In
5887 -- Please refer documentation for explanation of each of these settings
5888 	line_attr_rec.LINE_INDEX := 1; -- Attributes for the above line. Attributes are attached with the line index
5889 	line_attr_rec.PRICING_CONTEXT :='ITEM';
5890 	line_attr_rec.PRICING_ATTRIBUTE :='PRICING_ATTRIBUTE1';
5891 	line_attr_rec.PRICING_ATTR_VALUE_FROM  := p_inventory_item_id;	--Inventory Item Id
5892 	line_attr_rec.VALIDATED_FLAG :='N';
5893 	p_line_attr_tbl(1):= line_attr_rec;
5894 
5895     --swai: bug 12326261 (FP of bug#7284767 to support item category)
5896     open get_category(p_inventory_item_id);
5897     fetch get_category into ln_category_id;
5898     close get_category;
5899 
5900     --dbms_output.put_line('ln_category_id:'||ln_category_id);
5901 
5902     if ln_category_id is not null then
5903         line_attr_rec.LINE_INDEX                := 1;
5904         line_attr_rec.PRICING_CONTEXT           :='ITEM'; --
5905         line_attr_rec.PRICING_ATTRIBUTE         :='PRICING_ATTRIBUTE2';
5906         line_attr_rec.PRICING_ATTR_VALUE_FROM   :=ln_category_id;--'2210';                 -- Category ID
5907         line_attr_rec.VALIDATED_FLAG            :='N';
5908         p_line_attr_tbl(2)                      := line_attr_rec;
5909     end if;
5910     --end swai: bug 12326261 (FP of bug#7284767 to support item category)
5911 
5912 
5913 -- If u need to add multiple attributes , please fill the above information for each attribute
5914 -- and add to the p_line_attr_tbl
5915 -- Make sure that u are adding the attribute to the right line index
5916 
5917 -- Qualifiers Passed In
5918 -- Please refer documentation for explanation of each of these settings
5919 
5920 	qual_rec.LINE_INDEX := 1; -- Attributes for the above line. Attributes are attached with the line index
5921 	qual_rec.QUALIFIER_CONTEXT :='MODLIST';
5922 	qual_rec.QUALIFIER_ATTRIBUTE :='QUALIFIER_ATTRIBUTE4';
5923 	qual_rec.QUALIFIER_ATTR_VALUE_FROM :=p_price_list_header_id; -- Price List Id  1000
5924 	qual_rec.COMPARISON_OPERATOR_CODE := '=';
5925 	qual_rec.VALIDATED_FLAG :='Y';
5926 	p_qual_tbl(1):= qual_rec;
5927 
5928 	qual_rec.LINE_INDEX := 1;
5929 	qual_rec.QUALIFIER_CONTEXT :='CUSTOMER';
5930 	qual_rec.QUALIFIER_ATTRIBUTE :='QUALIFIER_ATTRIBUTE2';
5931 	qual_rec.QUALIFIER_ATTR_VALUE_FROM := p_account_id;
5932 	qual_rec.COMPARISON_OPERATOR_CODE := '=';
5933 	qual_rec.VALIDATED_FLAG :='N';
5934 	p_qual_tbl(1+1):= qual_rec;
5935 
5936 
5937 -- This statement prints out the version of the QP_PREQ_PUB API(QPXPPREB.pls).Information only
5938 l_version :=  QP_PREQ_GRP.GET_VERSION;
5939 --DBMS_OUTPUT.PUT_LINE('Testing version '||l_version);
5940 
5941 
5942 -- Actual Call to the Pricing Engine
5943 	QP_PREQ_PUB.PRICE_REQUEST
5944 	   (p_line_tbl				=>	p_line_tbl,
5945 		p_qual_tbl				=>	p_qual_tbl,
5946 		p_line_attr_tbl			=>	p_line_attr_tbl,
5947 		p_line_detail_tbl		=>	p_line_detail_tbl,
5948 		p_line_detail_qual_tbl	=>	p_line_detail_qual_tbl,
5949 		p_line_detail_attr_tbl	=>	p_line_detail_attr_tbl,
5950 		p_related_lines_tbl		=>	p_related_lines_tbl,
5951 		p_control_rec			=>	p_control_rec,
5952 		x_line_tbl				=>	x_line_tbl,
5953 		x_line_qual				=>	x_line_qual,
5954 		x_line_attr_tbl			=>	x_line_attr_tbl,
5955 		x_line_detail_tbl		=>	x_line_detail_tbl,
5956 		x_line_detail_qual_tbl	=>	x_line_detail_qual_tbl,
5957 		x_line_detail_attr_tbl	=>	x_line_detail_attr_tbl,
5958 		x_related_lines_tbl		=>	x_related_lines_tbl,
5959 		x_return_status			=>	x_return_status,
5960 		x_return_status_text	=>	x_return_status_text);
5961 
5962 -- Interpreting Information From the Pricing Engine . Output statements commented. Please uncomment for debugging
5963 
5964 -- Return Status Information ..
5965 --DBMS_OUTPUT.PUT_LINE('Return Status text '||  x_return_status_text);
5966 --DBMS_OUTPUT.PUT_LINE('Return Status  '||  x_return_status);
5967 --DBMS_OUTPUT.PUT_LINE('+---------Information Returned to Caller---------------------+ ');
5968 --DBMS_OUTPUT.PUT_LINE('-------------Request Line Information-------------------');
5969 
5970 	I := x_line_tbl.FIRST;
5971 	IF I IS NOT NULL THEN
5972 	--  DBMS_OUTPUT.PUT_LINE('Line Index: '||x_line_tbl(I).line_index);
5973 	--  DBMS_OUTPUT.PUT_LINE('Unit_price: '||x_line_tbl(I).unit_price);
5974 	--  DBMS_OUTPUT.PUT_LINE('Percent price: '||x_line_tbl(I).percent_price);
5975 	--  DBMS_OUTPUT.PUT_LINE('Adjusted Unit Price: '||x_line_tbl(I).adjusted_unit_price);
5976 	--  DBMS_OUTPUT.PUT_LINE('Pricing status code: '||x_line_tbl(I).status_code);
5977 	--  DBMS_OUTPUT.PUT_LINE('Pricing status text: '||x_line_tbl(I).status_text);
5978 		x_selling_price :=  x_line_tbl(I).adjusted_unit_price;
5979 	--  EXIT WHEN I = x_line_tbl.LAST;
5980 	--  I := x_line_tbl.NEXT(I);
5981 	END IF;
5982 
5983 	IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5984 	   IF (g_debug > 0 ) THEN
5985 		   csd_gen_utility_pvt.ADD('QP_PREQ_PUB.PRICE_REQUEST failed');
5986 	   END IF;
5987 	END IF;
5988 
5989 END PRICE_REQUEST;
5990 
5991 
5992 FUNCTION Is_MultiOrg_Enabled RETURN BOOLEAN IS
5993 
5994   l_multiorg_enabled varchar2(1);
5995 
5996 BEGIN
5997 
5998   Select multi_org_flag
5999   into l_multiorg_enabled
6000   from FND_PRODUCT_GROUPS;
6001 
6002   IF l_multiorg_enabled = 'Y' THEN
6003     RETURN TRUE;
6004   ELSE
6005     RETURN FALSE;
6006   END IF;
6007 
6008 EXCEPTION
6009   WHEN NO_DATA_FOUND THEN
6010     RETURN FALSE;
6011 END Is_MultiOrg_Enabled;
6012 
6013 
6014 
6015 --   *******************************************************
6016 --    Start of Comments
6017 --   *******************************************************
6018 --   API Name    : Get_GLCurrencyCode
6019 --   Type        :  Private Function
6020 --   Pre-Req     :  None
6021 --   Function    :  Returns CURRENCY CODE for the org id passed. If no currency
6022 --                  code exists for the org, returns null.
6023 --   Return Type : Varchar2
6024 --
6025 --   End of Comments
6026 --
6027 
6028 
6029    FUNCTION Get_GLCurrencyCode (
6030 	 p_org_id IN NUMBER
6031     ) RETURN VARCHAR2
6032     IS
6033       l_currency_code VARCHAR2(15);
6034 
6035     BEGIN
6036 	  SELECT gl.currency_code
6037 	  INTO l_currency_code
6038 	  FROM gl_sets_of_books gl, hr_operating_units hr
6039 	  WHERE hr.set_of_books_id = gl.set_of_books_id
6040 	  AND hr.organization_id= p_org_id;
6041 
6042 	  return l_currency_code;
6043 
6044 EXCEPTION
6045   WHEN NO_DATA_FOUND THEN
6046   FND_MESSAGE.SET_NAME('CSD','CSD_MISSING_CURR_CODE');
6047 --  FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID',p_inv_item_id);
6048   FND_MSG_PUB.Add;
6049   RAISE FND_API.G_EXC_ERROR;
6050   RETURN NULL;
6051 
6052   WHEN TOO_MANY_ROWS THEN
6053   FND_MESSAGE.SET_NAME('CSD','CSD_MISSING_CURR_CODE');
6054   FND_MSG_PUB.Add;
6055   RAISE FND_API.G_EXC_ERROR;
6056   RETURN NULL;
6057 
6058   WHEN OTHERS THEN
6059 	 RETURN NULL;
6060 
6061    END Get_GLCurrencyCode;
6062 
6063 
6064 /* bug#3875036 */
6065 FUNCTION GET_PL_CURRENCY_CODE(p_price_list_id   IN   NUMBER) RETURN VARCHAR2
6066  IS
6067 
6068    l_pl_curr_code 	VARCHAR2(15) := NULL;
6069 
6070 BEGIN
6071 
6072   SELECT currency_code
6073   INTO l_pl_curr_code
6074   FROM qp_list_headers_b
6075   WHERE list_header_id = p_price_list_id;
6076 
6077     return l_pl_curr_code;
6078 
6079 exception
6080     when no_data_found then
6081         return null;
6082     when others then
6083         return null;
6084 END GET_PL_CURRENCY_CODE;
6085 
6086 
6087 -- bug fix for 4108369, begin
6088 --   *******************************************************
6089 --    Start of Comments
6090 --   *******************************************************
6091 --   API Name    : get_sr_add_to_order
6092 --   Type        :  Private Function
6093 --   Pre-Req     :  None
6094 --   Function    :  Returns existing order for the SR.
6095 --   Return Type : Varchar2
6096 --
6097 --   End of Comments
6098 --
6099 
6100    FUNCTION Get_Sr_add_to_order (
6101 	 p_repair_line_Id IN NUMBER,
6102 	 p_action_type IN VARCHAR2
6103     ) RETURN NUMBER
6104     IS
6105     l_add_to_order_id NUMBER;
6106     BEGIN
6107 
6108       -- swai: bug 5931926 -  3rd party logistics for 12.0.2
6109       -- when getting the highest order number for add to order,
6110       -- ensure that the order number is for the appropriate account
6111       -- since there may be 3rd party orders for the RO
6112       If(p_Action_type = 'RMA') then
6113         begin
6114           Select max(ced.order_header_id)
6115           into  l_add_to_order_id
6116           from  csd_repairs dr,
6117                 cs_estimate_details ced,
6118                 oe_order_headers_all ooh,
6119                 oe_order_types_v oot,
6120                 cs_incidents_all_b sr               -- swai: bug 5931926
6121           where dr.repair_line_id = p_repair_line_id
6122           and  ced.incident_id = dr.incident_id
6123           and  ced.order_header_id is not null
6124           and  ooh.open_flag = 'Y'
6125           and  nvl(ooh.cancelled_flag,'N') = 'N'
6126           and  ooh.header_id = ced.order_header_id
6127           and  ooh.transactional_curr_code = dr.currency_code
6128           and  (ooh.cust_po_number = nvl(dr.default_po_num,ooh.cust_po_number)
6129                or ooh.cust_po_number is null)
6130           and  oot.order_type_id = ooh.order_type_id
6131           and  oot.order_category_code in ('MIXED','RETURN')
6132           and  ced.interface_to_oe_flag = 'Y'
6133           and  ooh.sold_to_org_id = sr.account_id  -- swai: bug 5931926
6134           and  sr.incident_id = dr.incident_id;    -- swai: bug 5931926
6135 
6136         exception
6137         when no_data_found then
6138           l_add_to_order_id := null;
6139         end;
6140 
6141     -- swai: bug fix 6078829
6142     -- DOES NOT ADD TO SAME ORDER WITHIN SERVICE REQUEST AND REPAIR ORDER.
6143     -- Now that we allow auto-book of ship lines, uncommented SHIP code
6144     -- and updated query.
6145     ELSIF ( p_action_type = 'SHIP') THEN
6146 
6147         begin
6148 
6149           Select max(ced.order_header_id)
6150           into  l_add_to_order_id
6151           from  csd_repairs dr,
6152                 cs_estimate_details ced,
6153                 oe_order_headers_all ooh,
6154                 oe_order_types_v oot,
6155                 cs_incidents_all_b sr               -- swai: bug 5931926
6156           where dr.repair_line_id = p_repair_line_id
6157           and  ced.incident_id = dr.incident_id
6158           and  ced.order_header_id is not null
6159           and  ooh.open_flag = 'Y'
6160           and  nvl(ooh.cancelled_flag,'N') = 'N'
6161           and  ooh.header_id = ced.order_header_id
6162           and  ooh.transactional_curr_code = dr.currency_code
6163           and  (ooh.cust_po_number = nvl(dr.default_po_num,ooh.cust_po_number)
6164                or ooh.cust_po_number is null)
6165           and  oot.order_type_id = ooh.order_type_id
6166           and  oot.order_category_code in ('MIXED','ORDER')
6167           and  ced.interface_to_oe_flag = 'Y'
6168           and  ooh.sold_to_org_id = sr.account_id  -- swai: bug 5931926
6169           and  sr.incident_id = dr.incident_id;    -- swai: bug 5931926
6170         exception
6171         when no_data_found then
6172           l_add_to_order_id := null;
6173         end;
6174 
6175     END IF;
6176 
6177 	  return l_add_to_order_id;
6178 
6179    END Get_sr_add_to_order;
6180 
6181 -- bug fix for 4108369, End
6182 
6183 
6184 --bug#7355526, nnadig changes
6185 -- New function to validate the subinventory on the ship line.
6186 -- The function will see if negative inventory is allowed, if yes, then
6187 -- it will check for the availability of item/serial number in the inventory.
6188 
6189 FUNCTION validate_subinventory_ship
6190    (
6191       p_org_id            IN NUMBER,
6192       p_sub_inv           IN VARCHAR2,
6193       p_inventory_item_id IN NUMBER,
6194       p_serial_number     IN VARCHAR2 )
6195    RETURN BOOLEAN
6196 IS
6197    l_negative_inv_allowed  NUMBER;
6198    l_override_negative_qty NUMBER;
6199    l_exists                VARCHAR2(3) := 'Y';
6200    l_current_runtime_level NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
6201    l_proc_level            NUMBER := FND_LOG.LEVEL_PROCEDURE;
6202    lc_mod_name             VARCHAR2(240) := 'csd.plsql.csd_process_util.validate_subinventory_ship';
6203 
6204 --bug#13498183
6205    l_serial_control_Code NUMBER ;
6206 --bug#13498183
6207 
6208 BEGIN
6209   IF ( l_proc_level >= l_current_runtime_level ) then
6210      FND_LOG.STRING(l_proc_level,lc_mod_name||'begin',
6211                         'Entering validate_subinventory_ship');
6212      FND_LOG.STRING(l_proc_level,lc_mod_name||'parameters',
6213                       p_org_id||'-'||p_sub_inv||'-'||p_inventory_item_id||'-'||p_serial_number);
6214 
6215   END IF;
6216 -- check for the inventory parameters in cache first.
6217    if g_negative_inventory.exists(p_org_id) then
6218       l_negative_inv_allowed  := g_negative_inventory(p_org_id);
6219    end if;
6220    if g_override_negative_qty.exists(p_org_id) then
6221       l_override_negative_qty := g_override_negative_qty(p_org_id);
6222    end if;
6223 -- if its not found in cache, then find out these values and add it to
6224 -- cache.
6225    IF l_negative_inv_allowed IS NULL THEN
6226       BEGIN
6227          SELECT negative_inv_receipt_code
6228          INTO l_negative_inv_allowed
6229          FROM mtl_parameters
6230          WHERE organization_id = p_org_id;
6231 
6232       EXCEPTION
6233       WHEN NO_DATA_FOUND THEN
6234          RAISE;
6235       END;
6236       g_negative_inventory(p_org_id) := l_negative_inv_allowed;
6237    END IF;
6238    IF l_override_negative_qty IS NULL THEN
6239       l_override_negative_qty := fnd_profile.value('INV_OVERRIDE_NEG_FOR_BACKFLUSH');
6240       g_override_negative_qty(p_org_id) := l_override_negative_qty ;
6241    END IF;
6242 
6243 --bug#13498183
6244 	SELECT SERIAL_NUMBER_CONTROL_CODE
6245 	INTO l_SERIAL_CONTROL_CODE
6246 	from MTL_SYSTEM_ITEMS_B
6247 	WHERE INVENTORY_ITEM_ID = p_inventory_item_id AND ORGANIZATION_ID = p_org_id;
6248 --bug#13498183
6249 
6250 -- if negative inventory is not allowed and the subinv is specified in the
6251 -- product transaction, validate if the item is available in the subinv.
6252 -- if subinv is null then default subinv is used as in shipping parameters.
6253    IF l_negative_inv_allowed = 2 AND l_override_negative_qty = 2 AND
6254       p_sub_inv IS NOT NULL THEN
6255       -- check if the item(serial_number) exist in the subinventory.
6256       -- if the item is serial controlled, then check for the availability of serial number.  -----bug#13498183
6257       IF p_serial_number IS NULL OR p_serial_number = FND_API.G_MISS_CHAR OR l_serial_control_Code = 6 THEN
6258          BEGIN
6259             SELECT 'Y'
6260             INTO l_exists
6261             FROM mtl_onhand_quantities_detail
6262             WHERE subinventory_code = p_sub_inv
6263             AND inventory_item_id   = p_inventory_item_id
6264             AND organization_id     = p_org_id
6265             AND rownum = 1;
6266 
6267          EXCEPTION
6268          WHEN no_data_found THEN
6269             l_exists := 'N';
6270          END;
6271       ELSE
6272          BEGIN
6273             SELECT 'Y'
6274             INTO l_exists
6275             FROM mtl_serial_numbers
6276             WHERE inventory_item_id       = p_inventory_item_id
6277             AND serial_number             = p_serial_number
6278             AND current_subinventory_code = p_sub_inv
6279             AND current_organization_id   = p_org_id;
6280 
6281          EXCEPTION
6282          WHEN no_data_found THEN
6283             l_exists := 'N';
6284          END;
6285       END IF;
6286    END IF;
6287    IF l_exists = 'Y' THEN
6288       RETURN true;
6289    ELSE
6290       RETURN false;
6291    END IF;
6292 END validate_subinventory_ship;
6293 
6294 
6295 -- bug#7355526, nnadig
6296 -- new function to validate the order, order line for OM holds.
6297 -- Parameters.
6298 -- @p_action_type in Type of line (RMA OR SHIP)
6299 -- @p_order_header_id in order header id for the line.
6300 -- @p_order_line_id  in order line id for the line default is null.-- @x_entity_on_hold out Tells entity on hold H = header L = line.
6301 
6302 FUNCTION validate_order_for_holds
6303               ( p_action_type     IN VARCHAR2,
6304                 p_order_header_id IN NUMBER,
6305                 p_order_line_id   IN NUMBER DEFAULT NULL)
6306                 --x_entity_on_hold  OUT NOCOPY VARCHAR2 )
6307       RETURN BOOLEAN
6308 IS
6309 l_order_hold VARCHAR2(3) := 'N';
6310 l_mod_name    VARCHAR2(2000) := 'csd.plsql.csd_process_pvt.update_product_txn';
6311 l_statement_level  NUMBER := Fnd_Log.LEVEL_STATEMENT;
6312 begin
6313 
6314   if p_action_type = 'RMA' then
6315 -- if action type is RMA, then if the order header is on hold, booking
6316 -- cannot happen, and hence autoreceiving will fail.
6317    BEGIN
6318       SELECT 'Y'
6319       INTO l_order_hold
6320       FROM    oe_order_headers_all oh
6321       WHERE   oh.header_id = p_order_header_id
6322       AND NVL(oh.booked_flag,'N') = 'N'
6323       AND  EXISTS
6324         (
6325                 SELECT 'x'
6326                 FROM    oe_order_holds_all oeh ,
6327                         oe_hold_sources_all ohs,
6328                         oe_hold_definitions od
6329                 WHERE   oeh.header_id      = oh.header_id
6330                     AND NVL(oeh.released_flag,'N') <> 'Y'
6331                     AND oeh.line_id IS NULL
6332                     AND oeh.hold_source_id = ohs.hold_source_id
6333                     AND ohs.hold_id        = od.hold_id
6334                     AND od.activity_name IS NULL
6335         );
6336     EXCEPTION
6337        WHEN NO_DATA_FOUND THEN
6338             NULL;
6339     END;
6340 
6341 -- if order header or order line is on hold, shipping will fail.
6342 elsif p_action_type = 'SHIP' then
6343 begin
6344       SELECT holdexists
6345       INTO l_order_hold
6346       FROM (
6347       SELECT 'Y' holdexists
6348       FROM    oe_order_headers_all oh
6349       WHERE   oh.header_id = p_order_header_id
6350       AND  EXISTS
6351         (
6352                 SELECT 'x'
6353                 FROM    oe_order_holds_all oeh ,
6354                         oe_hold_sources_all ohs,
6355                         oe_hold_definitions od
6356                 WHERE   oeh.header_id      = oh.header_id
6357                     AND NVL(oeh.released_flag,'N') <> 'Y'
6358                     AND oeh.line_id IS NULL
6359                     AND oeh.hold_source_id = ohs.hold_source_id
6360                     AND ohs.hold_id        = od.hold_id
6361                     AND od.activity_name IS NULL
6362         )
6363 
6364  union all
6365 
6366       SELECT 'Y' holdexists
6367       FROM    oe_order_headers_all oh
6368       WHERE   oh.header_id = p_order_header_id
6369       AND  EXISTS
6370         (
6371                 SELECT 'x'
6372                 FROM    oe_order_holds_all oeh ,
6373                         oe_hold_sources_all ohs,
6374                         oe_hold_definitions od
6375                 WHERE   oeh.header_id      = oh.header_id
6376                     AND NVL(oeh.released_flag,'N') <> 'Y'
6377                     AND oeh.line_id = p_order_line_id
6378                     AND oeh.hold_source_id = ohs.hold_source_id
6379                     AND ohs.hold_id        = od.hold_id
6380                     AND od.activity_name IS NULL
6381         ) ) where rownum = 1;
6382  exception
6383   when no_data_found then
6384     null;
6385  end;
6386 
6387  end if;
6388 
6389 if l_order_hold = 'Y' then
6390       return true;
6391 else
6392       return false;
6393 end if;
6394 
6395 end validate_order_for_holds;
6396 -- end bug#7355526, nnadig
6397 
6398 END CSD_PROCESS_UTIL;