DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSD_PROCESS_UTIL

Source


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