DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSD_REPAIR_ESTIMATE_PVT

Source


1 Package BODY Csd_Repair_Estimate_Pvt AS
2     /* $Header: csdvestb.pls 120.13.12010000.2 2008/09/04 10:00:34 subhat ship $ */
3 
4     -- ---------------------------------------------------------
5     -- Define global variables
6     -- ---------------------------------------------------------
7 
8     G_PKG_NAME  CONSTANT VARCHAR2(30) := 'CSD_REPAIR_ESTIMATE_PVT';
9     G_FILE_NAME CONSTANT VARCHAR2(12) := 'csdvestb.pls';
10     g_debug NUMBER := Csd_Gen_Utility_Pvt.g_debug_level;
11     ----Begin change for 3931317, wrpper aPI forward port
12 
13     C_EST_STATUS_ACCEPTED CONSTANT VARCHAR2(30) := 'ACCEPTED';
14     C_EST_STATUS_REJECTED CONSTANT VARCHAR2(30) := 'REJECTED';
15     C_EST_STATUS_NEW      CONSTANT VARCHAR2(30) := 'NEW';
16     C_REP_STATUS_APPROVED CONSTANT VARCHAR2(30) := 'A';
17     C_REP_STATUS_REJECTED CONSTANT VARCHAR2(30) := 'R';
18     G_DEBUG_LEVEL         CONSTANT NUMBER := TO_NUMBER(NVL(Fnd_Profile.value('CSD_DEBUG_LEVEL'),
19                                                            '0'));
20     ----End change for 3931317, wrpper aPI forward port
21 
22 
23     /*--------------------------------------------------*/
24     /* swai: 12.1 Service costing (bug 6960295)         */
25     /* procedure name: process_estimate_lines           */
26     /* description   : procedure used to create/update  */
27     /*                 delete charge lines. This        */
28     /*                 procedure allows the overriding  */
29     /*                 of the create/update/delete cost */
30     /*                 flag introduced in the Charges   */
31     /*                 API for 12.1 release             */
32     /*--------------------------------------------------*/
33 
34     PROCEDURE PROCESS_ESTIMATE_LINES(p_api_version      IN NUMBER,
35                                      p_commit           IN VARCHAR2 := Fnd_Api.g_false,
36                                      p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
37                                      p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
38                                      p_action           IN VARCHAR2,
39                                      p_cs_cost_flag     IN VARCHAR2 := 'Y',
40                                      x_Charges_Rec      IN OUT NOCOPY Cs_Charge_Details_Pub.Charges_Rec_Type,
41                                      x_return_status    OUT NOCOPY VARCHAR2,
42                                      x_msg_count        OUT NOCOPY NUMBER,
43                                      x_msg_data         OUT NOCOPY VARCHAR2) IS
44         l_api_name    CONSTANT VARCHAR2(30) := 'PROCESS_ESTIMATE_LINES';
45         l_api_version CONSTANT NUMBER := 1.0;
46         l_msg_count             NUMBER;
47         l_msg_data              VARCHAR2(100);
48         l_msg_index             NUMBER;
49         l_estimate_detail_id    NUMBER;
50         x_object_version_number NUMBER;
51         x_line_number           NUMBER;
52         x_cost_id               NUMBER; -- swai: 12.1 Service costing uptake bug 6960295
53 
54     BEGIN
55         -- Standard Start of API savepoint
56         SAVEPOINT process_estimate_lines;
57 
58         -- Standard call to check for call compatibility.
59         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
60                                            p_api_version,
61                                            l_api_name,
62                                            G_PKG_NAME)
63         THEN
64             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
65         END IF;
66 
67         -- Initialize message list if p_init_msg_list is set to TRUE.
68         IF Fnd_Api.to_Boolean(p_init_msg_list)
69         THEN
70             Fnd_Msg_Pub.initialize;
71         END IF;
72 
73         -- Initialize API return status to success
74         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
75 
76         -- Api body starts
77         IF (g_debug > 0)
78         THEN
79             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
80                                               p_api_name => l_api_name);
81         END IF;
82         IF (g_debug > 0)
83         THEN
84             Csd_Gen_Utility_Pvt.ADD('p_action =' || p_action);
85         END IF;
86 
87         -- Based on the action, call the respective charges public api to
88         -- to create/update/delete the charge lines.
89         IF p_action = 'CREATE'
90         THEN
91 
92             IF (g_debug > 0)
93             THEN
94                 Csd_Gen_Utility_Pvt.ADD('Creating the charge lines ');
95             END IF;
96 
97             Cs_Charge_Details_Pub.Create_Charge_Details(p_api_version           => p_api_version,
98                                                         p_init_msg_list         => p_init_msg_list,
99                                                         p_commit                => p_commit,
100                                                         p_validation_level      => p_validation_level,
101                                                         p_transaction_control   => Fnd_Api.G_TRUE,
102                                                         p_Charges_Rec           => x_charges_rec,
103                                                         p_create_cost_detail    => p_cs_cost_flag,  -- swai: 12.1 service costing uptake bug 6960295
104                                                         x_object_version_number => x_object_version_number,
105                                                         x_estimate_detail_id    => l_estimate_detail_id,
106                                                         x_line_number           => x_line_number,
107                                                         x_return_status         => x_return_status,
108                                                         x_msg_count             => x_msg_count,
109                                                         x_msg_data              => x_msg_data,
110                                                         x_cost_id               => x_cost_id);  -- swai: 12.1 service costing uptake bug 6960295
111 
112             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
113             THEN
114                 IF (g_debug > 0)
115                 THEN
116                     Csd_Gen_Utility_Pvt.ADD('Create_Charge_Details failed ');
117                 END IF;
118 
119                 RAISE Fnd_Api.G_EXC_ERROR;
120             END IF;
121 
122             x_charges_rec.estimate_detail_id := l_estimate_detail_id;
123 
124         ELSIF p_action = 'UPDATE'
125         THEN
126 
127             IF (g_debug > 0)
128             THEN
129                 Csd_Gen_Utility_Pvt.ADD('l_Charges_Rec.estimate_detail_id =' ||
130                                         x_Charges_Rec.estimate_detail_id);
131             END IF;
132 
133             IF (g_debug > 0)
134             THEN
135                 Csd_Gen_Utility_Pvt.ADD('Updating the charge lines ');
136             END IF;
137 
138             IF (g_debug > 0)
139             THEN
140                 Csd_Gen_Utility_Pvt.ADD('Estimate Detail Id = ' ||
141                                         x_Charges_Rec.estimate_detail_id);
142                 Csd_Gen_Utility_Pvt.ADD('x_Charges_Rec.business_process_id=' ||
143                                         x_Charges_Rec.business_process_id);
144             END IF;
145 
146             IF ((NVL(x_Charges_Rec.business_process_id, Fnd_Api.G_MISS_NUM) =
147                Fnd_Api.G_MISS_NUM) AND
148                x_Charges_Rec.estimate_detail_id IS NOT NULL)
149             THEN
150                 BEGIN
151                     SELECT business_process_id
152                       INTO x_Charges_Rec.business_process_id
153                       FROM cs_estimate_details
154                      WHERE estimate_detail_id =
155                            x_Charges_Rec.estimate_detail_id;
156                 EXCEPTION
157                     WHEN NO_DATA_FOUND THEN
158                         IF (g_debug > 0)
159                         THEN
160                             Csd_Gen_Utility_Pvt.ADD('No Business business_process_id');
161                         END IF;
162                         RAISE Fnd_Api.G_EXC_ERROR;
163                     WHEN TOO_MANY_ROWS THEN
164                         IF (g_debug > 0)
165                         THEN
166                             Csd_Gen_Utility_Pvt.ADD('Too many business_process_id');
167                         END IF;
168                         RAISE Fnd_Api.G_EXC_ERROR;
169                 END;
170             END IF;
171 
172             IF (g_debug > 0)
173             THEN
174                 Csd_Gen_Utility_Pvt.ADD('x_Charges_Rec.business_process_id=' ||
175                                         x_Charges_Rec.business_process_id);
176             END IF;
177 
178             Cs_Charge_Details_Pub.Update_Charge_Details(p_api_version           => p_api_version,
179                                                         p_init_msg_list         => p_init_msg_list,
180                                                         p_commit                => p_commit,
181                                                         p_validation_level      => p_validation_level,
182                                                         p_transaction_control   => Fnd_Api.G_TRUE,
183                                                         p_Charges_Rec           => x_Charges_Rec,
184                                                         p_update_cost_detail    => p_cs_cost_flag,  -- swai: 12.1 service costing uptake bug 6960295
185                                                         x_object_version_number => x_object_version_number,
186                                                         x_return_status         => x_return_status,
187                                                         x_msg_count             => x_msg_count,
188                                                         x_msg_data              => x_msg_data);
189 
190             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
191             THEN
192                 IF (g_debug > 0)
193                 THEN
194                     Csd_Gen_Utility_Pvt.ADD('update_charge_details failed');
195                 END IF;
196 
197                 RAISE Fnd_Api.G_EXC_ERROR;
198             END IF;
199 
200         ELSIF p_action = 'DELETE'
201         THEN
202 
203             IF (g_debug > 0)
204             THEN
205                 Csd_Gen_Utility_Pvt.ADD('l_estimate_detail_id =' ||
206                                         l_estimate_detail_id);
207             END IF;
208 
209             IF (g_debug > 0)
210             THEN
211                 Csd_Gen_Utility_Pvt.ADD('Deleting the charge lines ');
212             END IF;
213 
214             l_estimate_detail_id := x_charges_rec.estimate_detail_id;
215 
216             Cs_Charge_Details_Pub.Delete_Charge_Details(p_api_version         => p_api_version,
217                                                         p_init_msg_list       => p_init_msg_list,
218                                                         p_commit              => p_commit,
219                                                         p_validation_level    => p_validation_level,
220                                                         p_transaction_control => Fnd_Api.G_TRUE,
221                                                         p_estimate_detail_id  => l_estimate_detail_id,
222                                                         p_delete_cost_detail  => p_cs_cost_flag,  -- swai: 12.1 service costing uptake bug 6960295
223                                                         x_return_status       => x_return_status,
224                                                         x_msg_count           => x_msg_count,
225                                                         x_msg_data            => x_msg_data);
226 
227             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
228             THEN
229                 IF (g_debug > 0)
230                 THEN
231                     Csd_Gen_Utility_Pvt.ADD('Delete_Charge_Details failed ');
232                 END IF;
233 
234                 RAISE Fnd_Api.G_EXC_ERROR;
235             END IF;
236 
237         ELSE
238             IF (g_debug > 0)
239             THEN
240                 Csd_Gen_Utility_Pvt.ADD('Invalid action is passed ');
241             END IF;
242 
243             Fnd_Message.SET_NAME('CSD', 'CSD_INVALID_ACTION');
244             Fnd_Message.SET_TOKEN('ACTION', p_action);
245             Fnd_Msg_Pub.ADD;
246             RAISE Fnd_Api.G_EXC_ERROR;
247 
248         END IF;
249 
250         -- Api body ends here
251         -- Standard check of p_commit.
252         IF Fnd_Api.To_Boolean(p_commit)
253         THEN
254             COMMIT WORK;
255         END IF;
256 
257         -- Standard call to get message count and IF count is  get message info.
258         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
259                                   p_data  => x_msg_data);
260     EXCEPTION
261         WHEN Fnd_Api.G_EXC_ERROR THEN
262             ROLLBACK TO process_estimate_lines;
263             x_return_status := Fnd_Api.G_RET_STS_ERROR;
264             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
265                                       p_data  => x_msg_data);
266         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
267             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
268             ROLLBACK TO process_estimate_lines;
269             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
270                                       p_data  => x_msg_data);
271         WHEN OTHERS THEN
272             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
273             ROLLBACK TO process_estimate_lines;
274             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
275             THEN
276                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
277             END IF;
278             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
279                                       p_data  => x_msg_data);
280     END process_estimate_lines;
281 
282     /*--------------------------------------------------*/
283     /* procedure name: update_ro_group_estimate         */
284     /* description   : procedure used to update         */
285     /*                 repair group for estimate changes*/
286     /*--------------------------------------------------*/
287     PROCEDURE UPDATE_RO_GROUP_ESTIMATE(p_api_version           IN NUMBER,
288                                        p_commit                IN VARCHAR2 := Fnd_Api.g_false,
289                                        p_init_msg_list         IN VARCHAR2 := Fnd_Api.g_false,
290                                        p_validation_level      IN NUMBER := Fnd_Api.g_valid_level_full,
291                                        p_repair_line_id        IN NUMBER,
292                                        x_object_version_number OUT NOCOPY NUMBER,
293                                        x_return_status         OUT NOCOPY VARCHAR2,
294                                        x_msg_count             OUT NOCOPY NUMBER,
295                                        x_msg_data              OUT NOCOPY VARCHAR2) IS
296         l_api_name    CONSTANT VARCHAR2(30) := 'UPDATE_RO_GROUP_ESTIMATE';
297         l_api_version CONSTANT NUMBER := 1.0;
298         l_msg_index       NUMBER;
299         l_return_status   VARCHAR2(10);
300         l_msg_count       NUMBER;
301         l_msg_data        VARCHAR2(2000);
302         l_group_quantity  NUMBER;
303         l_group_ovn       NUMBER;
304         l_repair_group_id NUMBER;
305         l_count           NUMBER;
306         l_tot_approved    NUMBER;
307         l_tot_no_approval NUMBER;
308         l_tot_rejected    NUMBER;
309         l_rep_group_rec   Csd_Repair_Groups_Pvt.REPAIR_ORDER_GROUP_REC;
310 
311     BEGIN
312 
313         IF (g_debug > 0)
314         THEN
315             Csd_Gen_Utility_Pvt.ADD('Inside UPDATE_RO_GROUP_ESTIMATE Procedure p_repair_line_id =' ||
316                                     p_repair_line_id);
317         END IF;
318 
319         -- Standard Start of API savepoint
320         SAVEPOINT UPDATE_RO_GROUP_ESTIMATE;
321 
322         -- Standard call to check for call compatibility.
323         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
324                                            p_api_version,
325                                            l_api_name,
326                                            G_PKG_NAME)
327         THEN
328             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
329         END IF;
330 
331         -- Initialize message list if p_init_msg_list is set to TRUE.
332         IF Fnd_Api.to_Boolean(p_init_msg_list)
333         THEN
334             Fnd_Msg_Pub.initialize;
335         END IF;
336 
337         -- Initialize API return status to success
338         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
339 
340         -- Api body starts
341         IF (g_debug > 0)
342         THEN
343             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
344                                               p_api_name => l_api_name);
345         END IF;
346         -- Check the required parameter
347         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_repair_line_id,
348                                           p_param_name  => 'REPAIR_LINE_ID',
349                                           p_api_name    => l_api_name);
350 
351         IF (g_debug > 0)
352         THEN
353             Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
354         END IF;
355 
356         -- Validate the repair line ID
357         IF NOT
358             (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => p_repair_line_id))
359         THEN
360             RAISE Fnd_Api.G_EXC_ERROR;
361         END IF;
362 
363         BEGIN
364             SELECT grp.repair_group_id,
365                    grp.group_quantity,
366                    grp.object_version_number
367               INTO l_repair_group_id, l_group_quantity, l_group_ovn
368               FROM CSD_REPAIR_ORDER_GROUPS grp
369              WHERE EXISTS
370              (SELECT 'x'
371                       FROM CSD_REPAIRS rep
372                      WHERE rep.repair_group_id = grp.repair_group_id
373                        AND rep.repair_line_id = p_repair_line_id);
374 
375         EXCEPTION
376             WHEN NO_DATA_FOUND THEN
377                 NULL;
378                 -- FND_MESSAGE.SET_NAME('CSD','CSD_API_RO_GRP_UPD_NO_DATA');
379             -- FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
380             -- FND_MSG_PUB.ADD;
381             -- RAISE FND_API.G_EXC_ERROR;
382             WHEN OTHERS THEN
383                 NULL;
384                 -- FND_MESSAGE.SET_NAME('CSD','CSD_API_RO_GRP_UPD_OTHERS');
385             -- FND_MESSAGE.SET_TOKEN('REPAIR_LINE_ID',p_repair_line_id);
386             -- FND_MSG_PUB.ADD;
387             -- RAISE FND_API.G_EXC_ERROR;
388         END;
389 
390         IF (l_repair_group_id IS NOT NULL)
391         THEN
392 
393             l_count           := 0;
394             l_tot_approved    := 0;
395             l_tot_rejected    := 0;
396             l_tot_no_approval := 0;
397 
398             BEGIN
399                 SELECT COUNT(*)
400                   INTO l_tot_approved
401                   FROM CSD_REPAIRS
402                  WHERE repair_group_id = l_repair_group_id
403                    AND approval_status = 'A'
404                    AND approval_required_flag = 'Y';
405             EXCEPTION
406                 WHEN OTHERS THEN
407                     IF (g_debug > 0)
408                     THEN
409                         Csd_Gen_Utility_Pvt.ADD(' OTHERS l_tot_approved =' ||
410                                                 l_tot_approved);
411                     END IF;
412 
413             END;
414 
415             BEGIN
416                 SELECT COUNT(*)
417                   INTO l_tot_rejected
418                   FROM CSD_REPAIRS
419                  WHERE repair_group_id = l_repair_group_id
420                    AND approval_status = 'R'
421                    AND approval_required_flag = 'Y';
422             EXCEPTION
423                 WHEN OTHERS THEN
424                     IF (g_debug > 0)
425                     THEN
426                         Csd_Gen_Utility_Pvt.ADD(' OTHERS l_tot_rejected =' ||
427                                                 l_tot_rejected);
428                     END IF;
429 
430             END;
431 
432             BEGIN
433                 SELECT COUNT(*)
434                   INTO l_tot_no_approval
435                   FROM CSD_REPAIRS
436                  WHERE repair_group_id = l_repair_group_id
437                    AND approval_required_flag = 'N';
438             EXCEPTION
439                 WHEN OTHERS THEN
440                     IF (g_debug > 0)
441                     THEN
442                         Csd_Gen_Utility_Pvt.ADD(' OTHERS l_tot_no_approval =' ||
443                                                 l_tot_no_approval);
444                     END IF;
445 
446             END;
447 
448             IF (g_debug > 0)
449             THEN
450                 Csd_Gen_Utility_Pvt.ADD('l_tot_approved =' ||
451                                         l_tot_approved);
452             END IF;
453 
454             IF (g_debug > 0)
455             THEN
456                 Csd_Gen_Utility_Pvt.ADD('l_tot_rejected =' ||
457                                         l_tot_rejected);
458             END IF;
459 
460             IF (g_debug > 0)
461             THEN
462                 Csd_Gen_Utility_Pvt.ADD('l_tot_no_approval =' ||
463                                         l_tot_no_approval);
464             END IF;
465 
466             -- total of approved/rejected repairs with approval required = Y and approval required = N
467             -- Assumption no approval are not allowed to be rejected
468             l_count                               := NVL(l_tot_approved, 0) +
469                                                      NVL(l_tot_rejected, 0) +
470                                                      NVL(l_tot_no_approval,
471                                                          0);
472             l_rep_group_rec.repair_group_id       := l_repair_group_id;
473             l_rep_group_rec.object_version_number := l_group_ovn;
474 
475             -- check if all group qty have been approved/rejected
476             IF (NVL(l_group_quantity, 0) = NVL(l_tot_no_approval, 0))
477             THEN
478                 IF (g_debug > 0)
479                 THEN
480                     Csd_Gen_Utility_Pvt.ADD('EST_NOT_REQD ');
481                 END IF;
482 
483                 l_rep_group_rec.group_approval_status := 'EST_NOT_REQD';
484                 l_rep_group_rec.approved_quantity     := NVL(l_tot_no_approval,
485                                                              0);
486             ELSIF (l_group_quantity > l_count)
487             THEN
488                 IF (g_debug > 0)
489                 THEN
490                     Csd_Gen_Utility_Pvt.ADD('PARTIAL_APPRD ');
491                 END IF;
492 
493                 l_rep_group_rec.group_approval_status := 'PARTIAL_APPRD';
494                 l_rep_group_rec.approved_quantity     := NVL(l_tot_approved,
495                                                              0) +
496                                                          NVL(l_tot_no_approval,
497                                                              0);
498             ELSIF (l_group_quantity =
499                   NVL(l_tot_approved, 0) + NVL(l_tot_no_approval, 0))
500             THEN
501                 IF (g_debug > 0)
502                 THEN
503                     Csd_Gen_Utility_Pvt.ADD('APPROVED ');
504                 END IF;
505 
506                 l_rep_group_rec.group_approval_status := 'APPROVED';
507                 l_rep_group_rec.approved_quantity     := NVL(l_tot_approved,
508                                                              0) +
509                                                          NVL(l_tot_no_approval,
510                                                              0);
511             ELSIF (l_group_quantity = NVL(l_tot_rejected, 0))
512             THEN
513                 IF (g_debug > 0)
514                 THEN
515                     Csd_Gen_Utility_Pvt.ADD('REJECTED ');
516                 END IF;
517 
518                 l_rep_group_rec.group_approval_status := 'REJECTED';
519                 l_rep_group_rec.approved_quantity     := 0;
520             END IF;
521 
522             IF (g_debug > 0)
523             THEN
524                 Csd_Gen_Utility_Pvt.ADD('CSD_REPAIR_ESTIMATE_PVT.UPDATE_RO_GROUP_ESTIMATE Update Group RO call');
525             END IF;
526 
527             Csd_Repair_Groups_Pvt.UPDATE_REPAIR_GROUPS(p_api_version            => 1.0,
528                                                        p_commit                 => 'F',
529                                                        p_init_msg_list          => 'T',
530                                                        p_validation_level       => Fnd_Api.g_valid_level_full,
531                                                        x_repair_order_group_rec => l_rep_group_rec,
532                                                        x_return_status          => l_return_status,
533                                                        x_msg_count              => l_msg_count,
534                                                        x_msg_data               => l_msg_data);
535 
536             IF (g_debug > 0)
537             THEN
538                 Csd_Gen_Utility_Pvt.ADD('CSD_REPAIR_ESTIMATE_PVT.UPDATE_RO_GROUP_ESTIMATE UPDATE_REPAIR_GROUPS :' ||
539                                         x_return_status);
540             END IF;
541 
542             IF l_return_status <> 'S'
543             THEN
544                 x_return_status := Fnd_Api.G_RET_STS_ERROR;
545                 Fnd_Message.SET_NAME('CSD', 'CSD_API_RO_GROUP_EST_FAIL');
546                 Fnd_Msg_Pub.ADD;
547                 RAISE Fnd_Api.G_EXC_ERROR;
548             ELSIF l_return_status = 'S'
549             THEN
550                 x_object_version_number := l_rep_group_rec.object_version_number;
551             END IF;
552 
553             -- Api body ends here
554 
555             -- Standard check of p_commit.
556             IF Fnd_Api.To_Boolean(p_commit)
557             THEN
558                 COMMIT WORK;
559             END IF;
560 
561             -- Standard call to get message count and IF count is  get message info.
562             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
563                                       p_data  => x_msg_data);
564 
565         END IF;
566 
567     EXCEPTION
568         WHEN Fnd_Api.G_EXC_ERROR THEN
569             ROLLBACK TO UPDATE_RO_GROUP_ESTIMATE;
570             x_return_status := Fnd_Api.G_RET_STS_ERROR;
571             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
572                                       p_data  => x_msg_data);
573         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
574             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
575             ROLLBACK TO UPDATE_RO_GROUP_ESTIMATE;
576             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
577                                       p_data  => x_msg_data);
578         WHEN OTHERS THEN
579             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
580             ROLLBACK TO UPDATE_RO_GROUP_ESTIMATE;
581             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
582             THEN
583                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
584             END IF;
585             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
586                                       p_data  => x_msg_data);
587 
588     END UPDATE_RO_GROUP_ESTIMATE;
589 
590     /*--------------------------------------------------*/
591     /* procedure name: create_repair_estimate           */
592     /* description   : procedure used to create         */
593     /*                 repair estimate headers          */
594     /*--------------------------------------------------*/
595 
596     PROCEDURE CREATE_REPAIR_ESTIMATE(p_api_version      IN NUMBER,
597                                      p_commit           IN VARCHAR2 := Fnd_Api.g_false,
598                                      p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
599                                      p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
600                                      x_estimate_rec     IN OUT NOCOPY REPAIR_ESTIMATE_REC,
601                                      x_estimate_id      OUT NOCOPY NUMBER,
602                                      x_return_status    OUT NOCOPY VARCHAR2,
603                                      x_msg_count        OUT NOCOPY NUMBER,
604                                      x_msg_data         OUT NOCOPY VARCHAR2) IS
605 
606         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_REPAIR_ESTIMATE';
607         l_api_version CONSTANT NUMBER := 1.0;
608         l_msg_count         NUMBER;
609         l_msg_data          VARCHAR2(100);
610         l_msg_index         NUMBER;
611         l_dummy             VARCHAR2(1);
612         l_incident_id       NUMBER := NULL;
613         l_est_count         NUMBER := 0;
614         l_est_status_code   VARCHAR2(30);
615         l_api_return_status VARCHAR2(3);
616         l_group_obj_ver_num NUMBER;
617 
618     BEGIN
619         -- Standard Start of API savepoint
620         SAVEPOINT create_repair_estimate;
621 
622         -- Standard call to check for call compatibility.
623         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
624                                            p_api_version,
625                                            l_api_name,
626                                            G_PKG_NAME)
627         THEN
628             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
629         END IF;
630 
631         -- Initialize message list if p_init_msg_list is set to TRUE.
632         IF Fnd_Api.to_Boolean(p_init_msg_list)
633         THEN
634             Fnd_Msg_Pub.initialize;
635         END IF;
636 
637         -- Initialize API return status to success
638         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
639 
640         -- Api body starts
641         IF (g_debug > 0)
642         THEN
643             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
644                                               p_api_name => l_api_name);
645         END IF;
646         -- Dump the in parameters in the log file
647         -- if the debug level > 5
648         -- If fnd_profile.value('CSD_DEBUG_LEVEL') > 5 then
649 --        IF (g_debug > 5)
650 --        THEN
651 --            Csd_Gen_Utility_Pvt.dump_estimate_rec(p_estimate_rec => x_estimate_rec);
652 --        END IF;
653 
654         IF (g_debug > 0)
655         THEN
656             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter');
657         END IF;
658 
659         -- Check the required parameter
660         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_rec.repair_line_id,
661                                           p_param_name  => 'REPAIR_LINE_ID',
662                                           p_api_name    => l_api_name);
663 
664         -- swai 11.5.10
665         -- remove validation since these are not required anymore
666         /*
667          -- Check the required parameter
668          CSD_PROCESS_UTIL.Check_Reqd_Param
669          ( p_param_value    => x_estimate_rec.work_summary,
670            p_param_name     => 'WORK_SUMMARY',
671            p_api_name       => l_api_name);
672 
673          -- Check the required parameter
674          CSD_PROCESS_UTIL.Check_Reqd_Param
675          ( p_param_value    => x_estimate_rec.lead_time,
676            p_param_name     => 'LEAD_TIME',
677            p_api_name       => l_api_name);
678 
679          -- Check the required parameter
680          CSD_PROCESS_UTIL.Check_Reqd_Param
681          ( p_param_value    => x_estimate_rec.lead_time_uom,
682            p_param_name     => 'LEAD_TIME_UOM',
683            p_api_name       => l_api_name);
684         */
685 
686         -- Check the required parameter
687         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_rec.estimate_status,
688                                           p_param_name  => 'ESTIMATE_STATUS',
689                                           p_api_name    => l_api_name);
690 
691         IF (g_debug > 0)
692         THEN
693             Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
694         END IF;
695 
696         -- Validate the repair line ID
697         IF NOT
698             (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => x_estimate_rec.repair_line_id))
699         THEN
700             RAISE Fnd_Api.G_EXC_ERROR;
701         END IF;
702 
703         IF (g_debug > 0)
704         THEN
705             Csd_Gen_Utility_Pvt.ADD('Check if there is only one estimate per repair order');
706         END IF;
707 
708         BEGIN
709             SELECT COUNT(*)
710               INTO l_est_count
711               FROM CSD_REPAIR_ESTIMATE
712              WHERE repair_line_id = x_estimate_rec.repair_line_id;
713         EXCEPTION
714             WHEN OTHERS THEN
715                 NULL;
716         END;
717 
718         IF l_est_count > 0
719         THEN
720             IF (g_debug > 0)
721             THEN
722                 Csd_Gen_Utility_Pvt.ADD('Estimate already exists for the repair line Id: ' ||
723                                         x_estimate_rec.repair_line_id);
724             END IF;
725 
726             Fnd_Message.SET_NAME('CSD', 'CSD_API_ESTIMATE_EXISTS');
727             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
728                                   x_estimate_rec.repair_line_id);
729             Fnd_Msg_Pub.ADD;
730             RAISE Fnd_Api.G_EXC_ERROR;
731         END IF;
732 
733         IF (g_debug > 0)
734         THEN
735             Csd_Gen_Utility_Pvt.ADD('Validate the estimate status');
736         END IF;
737 
738         BEGIN
739             SELECT lookup_code
740               INTO l_est_status_code
741               FROM fnd_lookups
742              WHERE lookup_type = 'CSD_ESTIMATE_STATUS'
743                AND lookup_code = x_estimate_rec.estimate_status;
744         EXCEPTION
745             WHEN NO_DATA_FOUND THEN
746                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_STATUS_MISSING');
747                 Fnd_Message.SET_TOKEN('ESTIMATE_STATUS',
748                                       x_estimate_rec.estimate_status);
749                 Fnd_Msg_Pub.ADD;
750                 RAISE Fnd_Api.G_EXC_ERROR;
751         END;
752         /*
753                IF l_est_status_code in ('ACCEPTED','REJECTED') then
754 
755                 IF x_estimate_rec.estimate_reason_code is null then
756 
757                  FND_MESSAGE.SET_NAME('CSD','CSD_EST_REASON_CODE__MISSING');
758                    FND_MESSAGE.SET_TOKEN('REPAIR_ESTIMATE_ID',x_estimate_rec.repair_estimate_id);
759                    FND_MSG_PUB.ADD;
760                    RAISE FND_API.G_EXC_ERROR;
761 
762                 END IF;
763 
764               END IF;
765         */
766 
767         -- Assigning object version number
768         x_estimate_rec.object_version_number := 1;
769 
770         Csd_Repair_Estimate_Pkg.Insert_Row(px_REPAIR_ESTIMATE_ID   => x_estimate_rec.repair_estimate_id,
771                                            p_REPAIR_LINE_ID        => x_estimate_rec.repair_line_id,
772                                            p_ESTIMATE_STATUS       => x_estimate_rec.estimate_status,
773                                            p_ESTIMATE_DATE         => x_estimate_rec.estimate_date,
774                                            p_WORK_SUMMARY          => x_estimate_rec.work_summary,
775                                            p_PO_NUMBER             => x_estimate_rec.po_number,
776                                            p_LEAD_TIME             => x_estimate_rec.lead_time,
777                                            p_LEAD_TIME_UOM         => x_estimate_rec.lead_time_uom,
778                                            p_ESTIMATE_FREEZE_FLAG  => x_estimate_rec.estimate_freeze_flag,
779                                            p_ESTIMATE_REASON_CODE  => x_estimate_rec.estimate_reason_code,
780                                            p_NOT_TO_EXCEED         => x_estimate_rec.not_to_exceed,
781                                            p_LAST_UPDATE_DATE      => SYSDATE,
782                                            p_CREATION_DATE         => SYSDATE,
783                                            p_LAST_UPDATED_BY       => Fnd_Global.USER_ID,
784                                            p_CREATED_BY            => Fnd_Global.USER_ID,
785                                            p_LAST_UPDATE_LOGIN     => Fnd_Global.LOGIN_ID,
786                                            p_ATTRIBUTE1            => x_estimate_rec.ATTRIBUTE1,
787                                            p_ATTRIBUTE2            => x_estimate_rec.ATTRIBUTE2,
788                                            p_ATTRIBUTE3            => x_estimate_rec.ATTRIBUTE3,
789                                            p_ATTRIBUTE4            => x_estimate_rec.ATTRIBUTE4,
790                                            p_ATTRIBUTE5            => x_estimate_rec.ATTRIBUTE5,
791                                            p_ATTRIBUTE6            => x_estimate_rec.ATTRIBUTE6,
792                                            p_ATTRIBUTE7            => x_estimate_rec.ATTRIBUTE7,
793                                            p_ATTRIBUTE8            => x_estimate_rec.ATTRIBUTE8,
794                                            p_ATTRIBUTE9            => x_estimate_rec.ATTRIBUTE9,
795                                            p_ATTRIBUTE10           => x_estimate_rec.ATTRIBUTE10,
796                                            p_ATTRIBUTE11           => x_estimate_rec.ATTRIBUTE11,
797                                            p_ATTRIBUTE12           => x_estimate_rec.ATTRIBUTE12,
798                                            p_ATTRIBUTE13           => x_estimate_rec.ATTRIBUTE13,
799                                            p_ATTRIBUTE14           => x_estimate_rec.ATTRIBUTE14,
800                                            p_ATTRIBUTE15           => x_estimate_rec.ATTRIBUTE15,
801                                            p_CONTEXT               => x_estimate_rec.CONTEXT,
802                                            p_OBJECT_VERSION_NUMBER => 1);
803 
804         -- Api body ends here
805 
806         -- travi 052002 code
807         -- Call to update group estimate status and approved quantity
808         IF (x_estimate_rec.estimate_status IN ('ACCEPTED', 'REJECTED'))
809         THEN
810 
811             UPDATE_RO_GROUP_ESTIMATE(p_api_version           => 1.0,
812                                      p_commit                => Fnd_Api.g_false,
813                                      p_init_msg_list         => Fnd_Api.g_true,
814                                      p_validation_level      => Fnd_Api.g_valid_level_full,
815                                      p_repair_line_id        => x_estimate_rec.repair_line_id,
816                                      x_object_version_number => l_group_obj_ver_num,
817                                      x_return_status         => l_api_return_status,
818                                      x_msg_count             => x_msg_count,
819                                      x_msg_data              => x_msg_data);
820 
821             IF (l_api_return_status <> 'S')
822             THEN
823                 RAISE Fnd_Api.G_EXC_ERROR;
824             END IF;
825 
826         END IF;
827 
828         -- Standard check of p_commit.
829         IF Fnd_Api.To_Boolean(p_commit)
830         THEN
831             COMMIT WORK;
832         END IF;
833 
834         -- Standard call to get message count and IF count is  get message info.
835         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
836                                   p_data  => x_msg_data);
837     EXCEPTION
838         WHEN Fnd_Api.G_EXC_ERROR THEN
839             x_return_status := Fnd_Api.G_RET_STS_ERROR;
840             ROLLBACK TO create_repair_estimate;
841             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
842                                       p_data  => x_msg_data);
843         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
844             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
845             ROLLBACK TO create_repair_estimate;
846             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
847                                       p_data  => x_msg_data);
848         WHEN OTHERS THEN
849             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
850             ROLLBACK TO create_repair_estimate;
851             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
852             THEN
853                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
854             END IF;
855             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
856                                       p_data  => x_msg_data);
857     END create_repair_estimate;
858 
859     /*--------------------------------------------------*/
860     /* procedure name: update_repair_estimate           */
861     /* description   : procedure used to update         */
862     /*                 repair estimate lines            */
863     /*                                                  */
864     /*--------------------------------------------------*/
865 
866     PROCEDURE UPDATE_REPAIR_ESTIMATE(p_api_version      IN NUMBER,
867                                      p_commit           IN VARCHAR2 := Fnd_Api.g_false,
868                                      p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
869                                      p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
870                                      x_estimate_rec     IN OUT NOCOPY REPAIR_ESTIMATE_REC,
871                                      x_return_status    OUT NOCOPY VARCHAR2,
872                                      x_msg_count        OUT NOCOPY NUMBER,
873                                      x_msg_data         OUT NOCOPY VARCHAR2) IS
874 
875         l_api_name    CONSTANT VARCHAR2(30) := 'UPDATE_REPAIR_ESTIMATE';
876         l_api_version CONSTANT NUMBER := 1.0;
877         l_msg_count         NUMBER;
878         l_msg_data          VARCHAR2(100);
879         l_msg_index         NUMBER;
880         l_upd_estimate_flag VARCHAR2(1) := '';
881         l_approval_status   VARCHAR2(1);
882         l_estimate_id       NUMBER;
883         l_obj_ver_num       NUMBER;
884         l_est_status_code   VARCHAR2(30);
885         l_api_return_status VARCHAR2(3);
886         l_group_obj_ver_num NUMBER;
887 
888         CURSOR repair_estimate(p_est_id IN NUMBER) IS
889             SELECT a.repair_estimate_id,
890                    a.object_version_number,
891                    b.approval_status
892               FROM CSD_REPAIR_ESTIMATE a, CSD_REPAIRS b
893              WHERE a.repair_line_id = b.repair_line_id
894                AND a.repair_estimate_id = p_est_id;
895 
896     BEGIN
897         -- Standard Start of API savepoint
898         SAVEPOINT update_repair_estimate;
899 
900         -- Standard call to check for call compatibility.
901         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
902                                            p_api_version,
903                                            l_api_name,
904                                            G_PKG_NAME)
905         THEN
906             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
907         END IF;
908 
909         -- Initialize message list if p_init_msg_list is set to TRUE.
910         IF Fnd_Api.to_Boolean(p_init_msg_list)
911         THEN
912             Fnd_Msg_Pub.initialize;
913         END IF;
914 
915         -- Initialize API return status to success
916         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
917 
918         -- Api body starts
919         IF (g_debug > 0)
920         THEN
921             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
922                                               p_api_name => l_api_name);
923         END IF;
924         -- Dump the in parameters in the log file
925         -- if the debug level > 5
926         --If fnd_profile.value('CSD_DEBUG_LEVEL') > 5 then
927 --        IF (g_debug > 5)
928 --        THEN
929 --            Csd_Gen_Utility_Pvt.dump_estimate_rec(p_estimate_rec => x_estimate_rec);
930 --        END IF;
931 
932         IF (g_debug > 0)
933         THEN
934             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter: Repair Estimate Id');
935         END IF;
936 
937         IF (g_debug > 0)
938         THEN
939             Csd_Gen_Utility_Pvt.ADD('Repair Estimate Id =' ||
940                                     x_estimate_rec.repair_estimate_id);
941         END IF;
942 
943         -- Check the required parameter
944         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_rec.repair_estimate_id,
945                                           p_param_name  => 'REPAIR_ESTIMATE_ID',
946                                           p_api_name    => l_api_name);
947 
948         IF NVL(x_estimate_rec.repair_estimate_id, Fnd_Api.G_MISS_NUM) <>
949            Fnd_Api.G_MISS_NUM
950         THEN
951 
952             OPEN repair_estimate(x_estimate_rec.repair_estimate_id);
953             FETCH repair_estimate
954                 INTO l_estimate_id, l_obj_ver_num, l_approval_status;
955 
956             IF repair_estimate%NOTFOUND
957             THEN
958                 Fnd_Message.SET_NAME('CSD', 'CSD_API_ESTIMATE_MISSING');
959                 Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_ID', l_estimate_id);
960                 Fnd_Msg_Pub.ADD;
961                 RAISE Fnd_Api.G_EXC_ERROR;
962             END IF;
963 
964             IF repair_estimate%ISOPEN
965             THEN
966                 CLOSE repair_estimate;
967             END IF;
968 
969         END IF;
970 
971         IF NVL(x_estimate_rec.object_version_number, Fnd_Api.G_MISS_NUM) <>
972            l_obj_ver_num
973         THEN
974             IF (g_debug > 0)
975             THEN
976                 Csd_Gen_Utility_Pvt.ADD('object version number does not match');
977             END IF;
978 
979             Fnd_Message.SET_NAME('CSD', 'CSD_OBJ_VER_MISMATCH');
980             Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_ID', l_estimate_id);
981             Fnd_Msg_Pub.ADD;
982             RAISE Fnd_Api.G_EXC_ERROR;
983         END IF;
984 
985         IF (g_debug > 0)
986         THEN
987             Csd_Gen_Utility_Pvt.ADD('Validate the estimate status');
988         END IF;
989 
990         BEGIN
991             SELECT lookup_code
992               INTO l_est_status_code
993               FROM fnd_lookups
994              WHERE lookup_type = 'CSD_ESTIMATE_STATUS'
995                AND lookup_code = x_estimate_rec.estimate_status;
996         EXCEPTION
997             WHEN NO_DATA_FOUND THEN
998                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_STATUS_MISSING');
999                 Fnd_Message.SET_TOKEN('ESTIMATE_STATUS',
1000                                       x_estimate_rec.estimate_status);
1001                 Fnd_Msg_Pub.ADD;
1002                 RAISE Fnd_Api.G_EXC_ERROR;
1003         END;
1004         /*
1005                IF l_est_status_code in ('ACCEPTED','REJECTED') then
1006 
1007                 IF x_estimate_rec.estimate_reason_code is null then
1008 
1009                  FND_MESSAGE.SET_NAME('CSD','CSD_EST_REASON_CODE__MISSING');
1010                    FND_MESSAGE.SET_TOKEN('REPAIR_ESTIMATE_ID',x_estimate_rec.repair_estimate_id);
1011                    FND_MSG_PUB.ADD;
1012                    RAISE FND_API.G_EXC_ERROR;
1013 
1014                 END IF;
1015               END IF;
1016         */
1017 
1018         IF (g_debug > 0)
1019         THEN
1020             Csd_Gen_Utility_Pvt.ADD('l_approval_status =' ||
1021                                     l_approval_status);
1022         END IF;
1023 
1024         -- Estimate lines are allowed to update only
1025         -- if it is not frozen
1026 
1027         -- IF NVL(l_approval_status,'Z') <> 'A' THEN
1028 
1029         IF (g_debug > 0)
1030         THEN
1031             Csd_Gen_Utility_Pvt.ADD('Calling CSD_REPAIR_ESTIMATE_PKG.Update_Row');
1032         END IF;
1033 
1034         Csd_Repair_Estimate_Pkg.Update_Row(p_REPAIR_ESTIMATE_ID    => x_estimate_rec.repair_estimate_id,
1035                                            p_REPAIR_LINE_ID        => x_estimate_rec.repair_line_id,
1036                                            p_ESTIMATE_STATUS       => x_estimate_rec.estimate_status,
1037                                            p_ESTIMATE_DATE         => x_estimate_rec.estimate_date,
1038                                            p_WORK_SUMMARY          => x_estimate_rec.work_summary,
1039                                            p_PO_NUMBER             => x_estimate_rec.po_number,
1040                                            p_LEAD_TIME             => x_estimate_rec.lead_time,
1041                                            p_LEAD_TIME_UOM         => x_estimate_rec.lead_time_uom,
1042                                            p_ESTIMATE_FREEZE_FLAG  => x_estimate_rec.estimate_freeze_flag,
1043                                            p_ESTIMATE_REASON_CODE  => x_estimate_rec.estimate_reason_code,
1044                                            p_NOT_TO_EXCEED         => x_estimate_rec.not_to_exceed,
1045                                            p_LAST_UPDATE_DATE      => SYSDATE,
1046                                            p_CREATION_DATE         => SYSDATE,
1047                                            p_LAST_UPDATED_BY       => Fnd_Global.USER_ID,
1048                                            p_CREATED_BY            => Fnd_Global.USER_ID,
1049                                            p_LAST_UPDATE_LOGIN     => Fnd_Global.LOGIN_ID,
1050                                            p_ATTRIBUTE1            => x_estimate_rec.ATTRIBUTE1,
1051                                            p_ATTRIBUTE2            => x_estimate_rec.ATTRIBUTE2,
1052                                            p_ATTRIBUTE3            => x_estimate_rec.ATTRIBUTE3,
1053                                            p_ATTRIBUTE4            => x_estimate_rec.ATTRIBUTE4,
1054                                            p_ATTRIBUTE5            => x_estimate_rec.ATTRIBUTE5,
1055                                            p_ATTRIBUTE6            => x_estimate_rec.ATTRIBUTE6,
1056                                            p_ATTRIBUTE7            => x_estimate_rec.ATTRIBUTE7,
1057                                            p_ATTRIBUTE8            => x_estimate_rec.ATTRIBUTE8,
1058                                            p_ATTRIBUTE9            => x_estimate_rec.ATTRIBUTE9,
1059                                            p_ATTRIBUTE10           => x_estimate_rec.ATTRIBUTE10,
1060                                            p_ATTRIBUTE11           => x_estimate_rec.ATTRIBUTE11,
1061                                            p_ATTRIBUTE12           => x_estimate_rec.ATTRIBUTE12,
1062                                            p_ATTRIBUTE13           => x_estimate_rec.ATTRIBUTE13,
1063                                            p_ATTRIBUTE14           => x_estimate_rec.ATTRIBUTE14,
1064                                            p_ATTRIBUTE15           => x_estimate_rec.ATTRIBUTE15,
1065                                            p_CONTEXT               => x_estimate_rec.CONTEXT,
1066                                            p_OBJECT_VERSION_NUMBER => l_obj_ver_num + 1);
1067 
1068         x_estimate_rec.object_version_number := l_obj_ver_num + 1;
1069 
1070         -- END IF; -- end of update estimate
1071 
1072         -- Api body ends here
1073         -- travi 052002 code
1074         -- Call to update group estimate status and approved quantity
1075         IF (x_estimate_rec.estimate_status IN ('ACCEPTED', 'REJECTED'))
1076         THEN
1077 
1078             UPDATE_RO_GROUP_ESTIMATE(p_api_version           => 1.0,
1079                                      p_commit                => Fnd_Api.g_false,
1080                                      p_init_msg_list         => Fnd_Api.g_true,
1081                                      p_validation_level      => Fnd_Api.g_valid_level_full,
1082                                      p_repair_line_id        => x_estimate_rec.repair_line_id,
1083                                      x_object_version_number => l_group_obj_ver_num,
1084                                      x_return_status         => l_api_return_status,
1085                                      x_msg_count             => x_msg_count,
1086                                      x_msg_data              => x_msg_data);
1087 
1088             IF (l_api_return_status <> 'S')
1089             THEN
1090                 RAISE Fnd_Api.G_EXC_ERROR;
1091             END IF;
1092 
1093         END IF;
1094 
1095         -- Standard check of p_commit.
1096         IF Fnd_Api.To_Boolean(p_commit)
1097         THEN
1098             COMMIT WORK;
1099         END IF;
1100 
1101         -- Standard call to get message count and IF count is  get message info.
1102         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1103                                   p_data  => x_msg_data);
1104     EXCEPTION
1105         WHEN Fnd_Api.G_EXC_ERROR THEN
1106             x_return_status := Fnd_Api.G_RET_STS_ERROR;
1107             ROLLBACK TO update_repair_estimate;
1108             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1109                                       p_data  => x_msg_data);
1110         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1111             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1112             ROLLBACK TO update_repair_estimate;
1113             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1114                                       p_data  => x_msg_data);
1115         WHEN OTHERS THEN
1116             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1117             ROLLBACK TO update_repair_estimate;
1118             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
1119             THEN
1120                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1121             END IF;
1122             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1123                                       p_data  => x_msg_data);
1124     END update_repair_estimate;
1125 
1126     /*--------------------------------------------------*/
1127     /* procedure name: delete_repair_estimate           */
1128     /* description   : procedure used to delete         */
1129     /*                 repair estimate header           */
1130     /*                                                  */
1131     /*--------------------------------------------------*/
1132 
1133     PROCEDURE DELETE_REPAIR_ESTIMATE(p_api_version      IN NUMBER,
1134                                      p_commit           IN VARCHAR2 := Fnd_Api.g_false,
1135                                      p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
1136                                      p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
1137                                      p_estimate_id      IN NUMBER,
1138                                      x_return_status    OUT NOCOPY VARCHAR2,
1139                                      x_msg_count        OUT NOCOPY NUMBER,
1140                                      x_msg_data         OUT NOCOPY VARCHAR2) IS
1141         l_api_name    CONSTANT VARCHAR2(30) := 'DELETE_REPAIR_ESTIMATE';
1142         l_api_version CONSTANT NUMBER := 1.0;
1143         l_msg_count          NUMBER;
1144         l_msg_data           VARCHAR2(100);
1145         l_msg_index          NUMBER;
1146         l_Charges_Rec        Cs_Charge_Details_Pub.charges_rec_type;
1147         x_estimate_detail_id NUMBER;
1148         l_est_detail_id      NUMBER;
1149         l_delete_allow       VARCHAR2(1);
1150         l_approval_status    VARCHAR2(1);
1151         l_est_line_count     NUMBER;
1152 
1153     BEGIN
1154         -- Standard Start of API savepoint
1155         SAVEPOINT delete_repair_estimate;
1156 
1157         -- Standard call to check for call compatibility.
1158         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
1159                                            p_api_version,
1160                                            l_api_name,
1161                                            G_PKG_NAME)
1162         THEN
1163             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1164         END IF;
1165 
1166         -- Initialize message list if p_init_msg_list is set to TRUE.
1167         IF Fnd_Api.to_Boolean(p_init_msg_list)
1168         THEN
1169             Fnd_Msg_Pub.initialize;
1170         END IF;
1171 
1172         -- Initialize API return status to success
1173         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1174 
1175         -- Api body starts
1176         IF (g_debug > 0)
1177         THEN
1178             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
1179                                               p_api_name => l_api_name);
1180         END IF;
1181         IF (g_debug > 0)
1182         THEN
1183             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter: Estimate Id ');
1184         END IF;
1185 
1186         IF (g_debug > 0)
1187         THEN
1188             Csd_Gen_Utility_Pvt.ADD('Repair Estimate Id  =' ||
1189                                     p_estimate_id);
1190         END IF;
1191 
1192         -- Check the required parameter
1193         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_estimate_id,
1194                                           p_param_name  => 'REPAIR_ESTIMATE_ID',
1195                                           p_api_name    => l_api_name);
1196 
1197         IF (g_debug > 0)
1198         THEN
1199             Csd_Gen_Utility_Pvt.ADD('Validate repair estimate id');
1200         END IF;
1201 
1202         -- Validate the repair line ID
1203         IF NOT
1204             (Csd_Process_Util.Validate_estimate_id(p_estimate_id => p_estimate_id))
1205         THEN
1206             RAISE Fnd_Api.G_EXC_ERROR;
1207         END IF;
1208 
1209         BEGIN
1210             SELECT b.approval_status
1211               INTO l_approval_status
1212               FROM CSD_REPAIR_ESTIMATE a, CSD_REPAIRS b
1213              WHERE a.repair_line_id = b.repair_line_id
1214                AND a.repair_estimate_id = p_estimate_id;
1215         EXCEPTION
1216             WHEN NO_DATA_FOUND THEN
1217                 IF (g_debug > 0)
1218                 THEN
1219                     Csd_Gen_Utility_Pvt.ADD('Estimate ID missing');
1220                 END IF;
1221 
1222                 Fnd_Message.SET_NAME('CSD', 'CSD_API_ESTIMATE_MISSING');
1223                 Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_ID', p_estimate_id);
1224                 Fnd_Msg_Pub.ADD;
1225                 RAISE Fnd_Api.G_EXC_ERROR;
1226         END;
1227 
1228         BEGIN
1229             SELECT COUNT(*)
1230               INTO l_est_line_count
1231               FROM CSD_REPAIR_ESTIMATE_LINES
1232              WHERE repair_estimate_id = p_estimate_id;
1233         EXCEPTION
1234             WHEN OTHERS THEN
1235                 NULL;
1236         END;
1237 
1238         IF l_est_line_count > 0
1239         THEN
1240             IF (g_debug > 0)
1241             THEN
1242                 Csd_Gen_Utility_Pvt.ADD('Estimate Lines exists for this estimate');
1243             END IF;
1244 
1245             Fnd_Message.SET_NAME('CSD', 'CSD_ESTIMATE_LINE_EXISTS');
1246             Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_ID', p_estimate_id);
1247             Fnd_Msg_Pub.ADD;
1248             RAISE Fnd_Api.G_EXC_ERROR;
1249         END IF;
1250 
1251         IF NVL(l_approval_status, 'Z') <> 'A'
1252         THEN
1253             IF (g_debug > 0)
1254             THEN
1255                 Csd_Gen_Utility_Pvt.ADD('Call CSD_REPAIR_ESTIMATE_PKG.Delete_Row');
1256             END IF;
1257 
1258             Csd_Repair_Estimate_Pkg.Delete_Row(p_REPAIR_ESTIMATE_ID => p_estimate_id);
1259         ELSE
1260             Fnd_Message.SET_NAME('CSD', 'CSD_EST_DELETE_NOT_ALLOWED');
1261             Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_ID', p_estimate_id);
1262             Fnd_Msg_Pub.ADD;
1263             RAISE Fnd_Api.G_EXC_ERROR;
1264         END IF;
1265 
1266         -- Api body ends here
1267         -- Standard check of p_commit.
1268         IF Fnd_Api.To_Boolean(p_commit)
1269         THEN
1270             COMMIT WORK;
1271         END IF;
1272 
1273         -- Standard call to get message count and IF count is  get message info.
1274         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1275                                   p_data  => x_msg_data);
1276     EXCEPTION
1277         WHEN Fnd_Api.G_EXC_ERROR THEN
1278             x_return_status := Fnd_Api.G_RET_STS_ERROR;
1279             ROLLBACK TO delete_repair_estimate;
1280             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1281                                       p_data  => x_msg_data);
1282         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1283             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1284             ROLLBACK TO delete_repair_estimate;
1285             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1286                                       p_data  => x_msg_data);
1287         WHEN OTHERS THEN
1288             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1289             ROLLBACK TO delete_repair_estimate;
1290             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
1291             THEN
1292                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1293             END IF;
1294             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1295                                       p_data  => x_msg_data);
1296     END delete_repair_estimate;
1297 
1298     /*--------------------------------------------------*/
1299     /* procedure name: lock_repair_estimate             */
1300     /* description   : procedure used to create         */
1301     /*                 repair estimate headers          */
1302     /*--------------------------------------------------*/
1303 
1304     PROCEDURE lock_repair_estimate(p_api_version      IN NUMBER,
1305                                    p_commit           IN VARCHAR2 := Fnd_Api.g_false,
1306                                    p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
1307                                    p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
1308                                    p_estimate_rec     IN REPAIR_ESTIMATE_REC,
1309                                    x_return_status    OUT NOCOPY VARCHAR2,
1310                                    x_msg_count        OUT NOCOPY NUMBER,
1311                                    x_msg_data         OUT NOCOPY VARCHAR2) IS
1312 
1313         l_api_name    CONSTANT VARCHAR2(30) := 'LOCK_REPAIR_ESTIMATE';
1314         l_api_version CONSTANT NUMBER := 1.0;
1315         l_msg_count NUMBER;
1316         l_msg_data  VARCHAR2(100);
1317         l_msg_index NUMBER;
1318 
1319     BEGIN
1320         -- Standard Start of API savepoint
1321         SAVEPOINT lock_repair_estimate;
1322 
1323         -- Standard call to check for call compatibility.
1324         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
1325                                            p_api_version,
1326                                            l_api_name,
1327                                            G_PKG_NAME)
1328         THEN
1329             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1330         END IF;
1331 
1332         -- Initialize message list if p_init_msg_list is set to TRUE.
1333         IF Fnd_Api.to_Boolean(p_init_msg_list)
1334         THEN
1335             Fnd_Msg_Pub.initialize;
1336         END IF;
1337 
1338         -- Initialize API return status to success
1339         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1340 
1341         Csd_Repair_Estimate_Pkg.Lock_Row(p_REPAIR_ESTIMATE_ID    => p_estimate_rec.repair_estimate_id,
1342                                          p_OBJECT_VERSION_NUMBER => p_estimate_rec.OBJECT_VERSION_NUMBER);
1343 
1344         -- Standard check of p_commit.
1345         IF Fnd_Api.To_Boolean(p_commit)
1346         THEN
1347             COMMIT WORK;
1348         END IF;
1349 
1350         -- Standard call to get message count and IF count is  get message info.
1351         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1352                                   p_data  => x_msg_data);
1353     EXCEPTION
1354         WHEN Fnd_Api.G_EXC_ERROR THEN
1355             x_return_status := Fnd_Api.G_RET_STS_ERROR;
1356             ROLLBACK TO lock_repair_estimate;
1357             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1358                                       p_data  => x_msg_data);
1359         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1360             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1361             ROLLBACK TO lock_repair_estimate;
1362             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1363                                       p_data  => x_msg_data);
1364         WHEN OTHERS THEN
1365             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1366             ROLLBACK TO lock_repair_estimate;
1367             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
1368             THEN
1369                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1370             END IF;
1371             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1372                                       p_data  => x_msg_data);
1373     END lock_repair_estimate;
1374 
1375     /*--------------------------------------------------*/
1376     /* procedure name: create_repair_estimate_lines     */
1377     /* description   : procedure used to create         */
1378     /*                 repair estimate lines            */
1379     /*--------------------------------------------------*/
1380 
1381     PROCEDURE CREATE_REPAIR_ESTIMATE_LINES(p_api_version       IN NUMBER,
1382                                            p_commit            IN VARCHAR2 := Fnd_Api.g_false,
1383                                            p_init_msg_list     IN VARCHAR2 := Fnd_Api.g_false,
1384                                            p_validation_level  IN NUMBER := Fnd_Api.g_valid_level_full,
1385                                            x_estimate_line_rec IN OUT NOCOPY CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_REC,
1386                                            x_estimate_line_id  OUT NOCOPY NUMBER,
1387                                            x_return_status     OUT NOCOPY VARCHAR2,
1388                                            x_msg_count         OUT NOCOPY NUMBER,
1389                                            x_msg_data          OUT NOCOPY VARCHAR2) IS
1390 
1391         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_REPAIR_ESTIMATE_LINES';
1392         l_api_version CONSTANT NUMBER := 1.0;
1393         l_msg_count           NUMBER;
1394         l_msg_data            VARCHAR2(100);
1395         l_msg_index           NUMBER;
1396         l_serial_flag         BOOLEAN := FALSE;
1397         l_dummy               VARCHAR2(1);
1398         l_Charges_Rec         Cs_Charge_Details_Pub.Charges_Rec_Type;
1399         x_estimate_detail_id  NUMBER := NULL;
1400         l_incident_id         NUMBER := NULL;
1401         l_reference_number    VARCHAR2(30) := '';
1402         l_contract_number     VARCHAR2(120) := '';
1403         l_bus_process_id      NUMBER := NULL;
1404         l_repair_type_ref     VARCHAR2(3) := '';
1405         l_line_type_id        NUMBER := NULL;
1406         l_txn_billing_type_id NUMBER := NULL;
1407         l_party_id            NUMBER := NULL;
1408         l_account_id          NUMBER := NULL;
1409         l_order_header_id     NUMBER := NULL;
1410         l_release_status      VARCHAR2(10) := '';
1411         l_curr_code           VARCHAR2(10) := '';
1412         l_line_category_code  VARCHAR2(30) := '';
1413         l_ship_from_org_id    NUMBER := NULL;
1414         l_order_line_id       NUMBER := NULL;
1415         -- passing in from form
1416         -- l_coverage_id            NUMBER := NULL;
1417         -- l_coverage_name          VARCHAR2(30) := '';
1418         -- l_txn_group_id           NUMBER := NULL;
1419         --
1420         l_unit_selling_price NUMBER := NULL;
1421         l_item_cost          NUMBER := NULL;
1422 
1423         CURSOR order_rec(p_incident_id IN NUMBER) IS
1424             SELECT customer_id, account_id
1425               FROM cs_incidents_all_b
1426              WHERE incident_id = p_incident_id;
1427 
1428     BEGIN
1429         -- Standard Start of API savepoint
1430         SAVEPOINT create_repair_estimate_lines;
1431 
1432         -- Standard call to check for call compatibility.
1433         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
1434                                            p_api_version,
1435                                            l_api_name,
1436                                            G_PKG_NAME)
1437         THEN
1438             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1439         END IF;
1440 
1441         -- Initialize message list if p_init_msg_list is set to TRUE.
1442         IF Fnd_Api.to_Boolean(p_init_msg_list)
1443         THEN
1444             Fnd_Msg_Pub.initialize;
1445         END IF;
1446 
1447         -- Initialize API return status to success
1448         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
1449 
1450         -- Api body starts
1451         IF (g_debug > 0)
1452         THEN
1453             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
1454                                               p_api_name => l_api_name);
1455         END IF;
1456         -- Dump the in parameters in the log file
1457         -- if the debug level > 5
1458         -- If fnd_profile.value('CSD_DEBUG_LEVEL') > 5 then
1459 --        IF (g_debug > 5)
1460 --        THEN
1461 --            Csd_Gen_Utility_Pvt.dump_estimate_line_rec(p_estimate_line_rec => x_estimate_line_rec);
1462 --        END IF;
1463 
1464         IF (g_debug > 0)
1465         THEN
1466             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter');
1467         END IF;
1468 
1469         IF (g_debug > 0)
1470         THEN
1471             Csd_Gen_Utility_Pvt.ADD('Repair Line ID =' ||
1472                                     x_estimate_line_rec.repair_line_id);
1473         END IF;
1474 
1475         IF (g_debug > 0)
1476         THEN
1477             Csd_Gen_Utility_Pvt.ADD('txn_billing_type_id =' ||
1478                                     x_estimate_line_rec.txn_billing_type_id);
1479         END IF;
1480 
1481         -- Check the required parameter
1482         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.repair_line_id,
1483                                           p_param_name  => 'REPAIR_LINE_ID',
1484                                           p_api_name    => l_api_name);
1485 
1486         -- Check the required parameter
1487         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.txn_billing_type_id,
1488                                           p_param_name  => 'TXN_BILLING_TYPE_ID',
1489                                           p_api_name    => l_api_name);
1490 
1491         -- Check the required parameter
1492         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.inventory_item_id,
1493                                           p_param_name  => 'INVENTORY_ITEM_ID',
1494                                           p_api_name    => l_api_name);
1495 
1496         -- Check the required parameter
1497         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.unit_of_measure_code,
1498                                           p_param_name  => 'UNIT_OF_MEASURE_CODE',
1499                                           p_api_name    => l_api_name);
1500 
1501         -- Check the required parameter
1502         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.estimate_quantity,
1503                                           p_param_name  => 'ESTIMATE_QUANTITY',
1504                                           p_api_name    => l_api_name);
1505 
1506         -- Check the required parameter
1507         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.price_list_id,
1508                                           p_param_name  => 'PRICE_LIST_ID',
1509                                           p_api_name    => l_api_name);
1510 
1511         IF (g_debug > 0)
1512         THEN
1513             Csd_Gen_Utility_Pvt.ADD('Validate repair estimate id');
1514         END IF;
1515 
1516         -- Validate the repair line ID
1517         IF NOT
1518             (Csd_Process_Util.Validate_estimate_id(p_estimate_id => x_estimate_line_rec.repair_estimate_id))
1519         THEN
1520             RAISE Fnd_Api.G_EXC_ERROR;
1521         END IF;
1522 
1523         IF (g_debug > 0)
1524         THEN
1525             Csd_Gen_Utility_Pvt.ADD('Validate repair line id');
1526         END IF;
1527 
1528         -- Validate the repair line ID
1529         IF NOT
1530             (Csd_Process_Util.Validate_rep_line_id(p_repair_line_id => x_estimate_line_rec.repair_line_id))
1531         THEN
1532             RAISE Fnd_Api.G_EXC_ERROR;
1533         END IF;
1534 
1535         -- Get the service request
1536         BEGIN
1537             SELECT incident_id
1538               INTO l_incident_id
1539               FROM CSD_REPAIRS
1540              WHERE repair_line_id = x_estimate_line_rec.repair_line_id;
1541         EXCEPTION
1542             WHEN NO_DATA_FOUND THEN
1543                 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
1544                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID',
1545                                       x_estimate_line_rec.repair_line_id);
1546                 Fnd_Msg_Pub.ADD;
1547                 RAISE Fnd_Api.G_EXC_ERROR;
1548         END;
1549 
1550         IF (g_debug > 0)
1551         THEN
1552             Csd_Gen_Utility_Pvt.ADD('l_incident_id  =' || l_incident_id);
1553         END IF;
1554 
1555         -- Get the business process id
1556         -- Forward port bug fix# 2756313
1557         --      l_bus_process_id := CSD_PROCESS_UTIL.GET_BUS_PROCESS(l_incident_id);
1558 
1559         l_bus_process_id := Csd_Process_Util.GET_BUS_PROCESS(x_estimate_line_rec.repair_line_id);
1560 
1561         IF (g_debug > 0)
1562         THEN
1563             Csd_Gen_Utility_Pvt.ADD('l_bus_process_id =' ||
1564                                     l_bus_process_id);
1565         END IF;
1566 
1567         IF l_bus_process_id < 0
1568         THEN
1569             IF NVL(x_estimate_line_rec.business_process_id,
1570                    Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM
1571             THEN
1572                 l_bus_process_id := x_estimate_line_rec.business_process_id;
1573             ELSE
1574                 IF (g_debug > 0)
1575                 THEN
1576                     Csd_Gen_Utility_Pvt.ADD('Business process does not exist ');
1577                 END IF;
1578 
1579                 RAISE Fnd_Api.G_EXC_ERROR;
1580             END IF;
1581         END IF;
1582 
1583         /* contract information passed from form
1584         IF (g_debug > 0 ) THEN
1585               csd_gen_utility_pvt.ADD('Getting the Coverage and txn Group Id');
1586         END IF;
1587 
1588         IF (g_debug > 0 ) THEN
1589               csd_gen_utility_pvt.ADD('contract_line_id ='||x_estimate_line_rec.contract_id);
1590         END IF;
1591 
1592 
1593               IF NVL(x_estimate_line_rec.contract_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN
1594 
1595                 Begin
1596                  SELECT cov.actual_coverage_id ,
1597                         cov.coverage_name,
1598                         ent.txn_group_id
1599                  INTO   l_coverage_id,
1600                         l_coverage_name,
1601                         l_txn_group_id
1602                  FROM   oks_ent_coverages_v cov,
1603                         oks_ent_txn_groups_v ent
1604                  WHERE  cov.contract_number = x_estimate_line_rec.contract_number -- travi change
1605                   AND   cov.actual_coverage_id = ent.coverage_id
1606                   AND   ent.business_process_id = l_bus_process_id;
1607 
1608         -- travi comment
1609         --         WHERE  cov.contract_line_id = x_estimate_line_rec.contract_id
1610 
1611                 Exception
1612                  When no_data_found then
1613                   FND_MESSAGE.SET_NAME('CSD','CSD_API_CONTRACT_MISSING');
1614                   FND_MESSAGE.SET_TOKEN('CONTRACT_LINE_ID',x_estimate_line_rec.contract_id);
1615                   FND_MSG_PUB.ADD;
1616         IF (g_debug > 0 ) THEN
1617                   csd_gen_utility_pvt.ADD('Contract Line Id missing');
1618         END IF;
1619 
1620                   RAISE FND_API.G_EXC_ERROR;
1621                 End;
1622 
1623                  x_estimate_line_rec.coverage_id := l_coverage_id;
1624                  x_estimate_line_rec.coverage_txn_group_id := l_txn_group_id;
1625 
1626         IF (g_debug > 0 ) THEN
1627                 csd_gen_utility_pvt.ADD('l_coverage_id  ='||l_coverage_id);
1628         END IF;
1629 
1630         IF (g_debug > 0 ) THEN
1631                 csd_gen_utility_pvt.ADD('l_txn_group_id ='||l_txn_group_id);
1632         END IF;
1633 
1634 
1635               End If;
1636         */
1637 
1638         IF l_incident_id IS NOT NULL
1639         THEN
1640             OPEN order_rec(l_incident_id);
1641             FETCH order_rec
1642                 INTO l_party_id, l_account_id;
1643 
1644             IF order_rec%NOTFOUND OR l_party_id IS NULL
1645             THEN
1646                 Fnd_Message.SET_NAME('CSD', 'CSD_API_PARTY_MISSING');
1647                 Fnd_Message.SET_TOKEN('INCIDENT_ID', l_incident_id);
1648                 Fnd_Msg_Pub.ADD;
1649                 RAISE Fnd_Api.G_EXC_ERROR;
1650             END IF;
1651 
1652             IF order_rec%ISOPEN
1653             THEN
1654                 CLOSE order_rec;
1655             END IF;
1656 
1657         END IF;
1658 
1659         IF (g_debug > 0)
1660         THEN
1661             Csd_Gen_Utility_Pvt.ADD('l_party_id   =' || l_party_id);
1662         END IF;
1663 
1664         IF (g_debug > 0)
1665         THEN
1666             Csd_Gen_Utility_Pvt.ADD('l_account_id =' || l_account_id);
1667         END IF;
1668 
1669         IF (g_debug > 0)
1670         THEN
1671             Csd_Gen_Utility_Pvt.ADD('x_estimate_line_rec.txn_billing_type_id =' ||
1672                                     x_estimate_line_rec.txn_billing_type_id);
1673         END IF;
1674 
1675         IF (g_debug > 0)
1676         THEN
1677             Csd_Gen_Utility_Pvt.ADD('x_estimate_line_rec.organization_id     =' ||
1678                                     x_estimate_line_rec.organization_id);
1679         END IF;
1680 
1681         -- Derive the txn_billing type and line category code
1682         -- from the transaction type
1683         Csd_Process_Util.GET_LINE_TYPE(p_txn_billing_type_id => x_estimate_line_rec.txn_billing_type_id,
1684                                        -- Following line commented (and substituted) for the bug 3337344.
1685                                        -- p_org_id              => x_estimate_line_rec.organization_id,
1686                                        -- Organization_id passed could really be Service Validation Org, whereas
1687                                        -- it should really be Operating Unit. CSD_PROCESS_UTIL.get_org_id procedure
1688                                        -- ensures that the OU is passed.
1689                                        p_org_id             => Csd_Process_Util.get_org_id(x_estimate_line_rec.incident_id),
1690                                        x_line_type_id       => l_line_type_id,
1691                                        x_line_category_code => l_line_category_code,
1692                                        x_return_status      => x_return_status);
1693 
1694         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1695         THEN
1696             RAISE Fnd_Api.G_EXC_ERROR;
1697         END IF;
1698 
1699         IF (g_debug > 0)
1700         THEN
1701             Csd_Gen_Utility_Pvt.ADD('l_line_type_id        =' ||
1702                                     l_line_type_id);
1703         END IF;
1704 
1705         IF (g_debug > 0)
1706         THEN
1707             Csd_Gen_Utility_Pvt.ADD('l_line_category_code  =' ||
1708                                     l_line_category_code);
1709         END IF;
1710 
1711         IF (g_debug > 0)
1712         THEN
1713             Csd_Gen_Utility_Pvt.ADD('x_estimate_line_rec.price_list_id =' ||
1714                                     x_estimate_line_rec.price_list_id);
1715         END IF;
1716 
1717         -- If line_type_id Or line_category_code is null
1718         -- then raise error
1719         IF l_line_type_id IS NULL OR l_line_category_code IS NULL
1720         THEN
1721             Fnd_Message.SET_NAME('CSD', 'CSD_API_LINE_TYPE_MISSING');
1722             Fnd_Message.SET_TOKEN('TXN_BILLING_TYPE_ID',
1723                                   x_estimate_line_rec.txn_billing_type_id);
1724             Fnd_Msg_Pub.ADD;
1725             RAISE Fnd_Api.G_EXC_ERROR;
1726         END IF;
1727 
1728         -- Get the currency code
1729         IF NVL(x_estimate_line_rec.price_list_id, Fnd_Api.G_MISS_NUM) <>
1730            Fnd_Api.G_MISS_NUM
1731         THEN
1732             BEGIN
1733                 SELECT currency_code
1734                   INTO l_curr_code
1735                   FROM oe_price_lists
1736                  WHERE price_list_id = x_estimate_line_rec.price_list_id;
1737             EXCEPTION
1738                 WHEN NO_DATA_FOUND THEN
1739                     Fnd_Message.SET_NAME('CSD',
1740                                          'CSD_API_INV_PRICE_LIST_ID');
1741                     Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
1742                                           x_estimate_line_rec.price_list_id);
1743                     Fnd_Msg_Pub.ADD;
1744                     RAISE Fnd_Api.G_EXC_ERROR;
1745             END;
1746         END IF;
1747 
1748         IF (g_debug > 0)
1749         THEN
1750             Csd_Gen_Utility_Pvt.ADD('l_curr_code     =' || l_curr_code);
1751         END IF;
1752 
1753         -- If l_curr_code is null then raise error
1754         IF l_curr_code IS NULL
1755         THEN
1756             Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_CURR_CODE');
1757             Fnd_Message.SET_TOKEN('PRICE_LIST_ID',
1758                                   x_estimate_line_rec.price_list_id);
1759             Fnd_Msg_Pub.ADD;
1760             RAISE Fnd_Api.G_EXC_ERROR;
1761         END IF;
1762 
1763         --
1764         -- Commented for bug# 2857134 (forward port bugfix from 11.5.8)
1765         --
1766         --       IF NVL(x_estimate_line_rec.item_cost,FND_API.G_MISS_NUM)= FND_API.G_MISS_NUM THEN
1767         --IF (g_debug > 0 ) THEN
1768         --         csd_gen_utility_pvt.ADD('Get item cost' );
1769         --END IF;
1770         --
1771         --
1772         --        BEGIN
1773         --           select decode(item_cost,0 ,null,item_cost)
1774         --           into l_item_cost
1775         --           from cst_item_costs
1776         --           where inventory_item_id = x_estimate_line_rec.inventory_item_id
1777         --           and  organization_id   = cs_std.get_item_valdn_orgzn_id
1778         --           and  cost_type_id = 1;
1779         --
1780         --           x_estimate_line_rec.item_cost               := l_item_cost ;
1781         --
1782         --         EXCEPTION
1783         --          WHEN NO_DATA_FOUND THEN
1784         --IF (g_debug > 0 ) THEN
1785         --          csd_gen_utility_pvt.ADD('Could not get item cost' );
1786         --END IF;
1787         --
1788         --           FND_MESSAGE.SET_NAME('CSD','CSD_ITEM_COST_MISSING');
1789         --           FND_MSG_PUB.ADD;
1790         --           RAISE FND_API.G_EXC_ERROR;
1791         --        END;
1792         --      END IF;
1793         --
1794         --
1795 
1796         -- assigning values for the charge record
1797         x_estimate_line_rec.incident_id         := l_incident_id;
1798         x_estimate_line_rec.business_process_id := l_bus_process_id;
1799         x_estimate_line_rec.line_type_id        := l_line_type_id;
1800         x_estimate_line_rec.currency_code       := l_curr_code;
1801         x_estimate_line_rec.line_category_code  := l_line_category_code;
1802 
1803         -- travi new code
1804         --x_estimate_line_rec.charge_line_type        := ;
1805         --x_estimate_line_rec.apply_contract_discount := ;
1806 
1807         IF (g_debug > 0)
1808         THEN
1809             Csd_Gen_Utility_Pvt.ADD('Convert estimate line rec to charges rec');
1810         END IF;
1811 
1812         -- always create estimate lines with interface to OE flag as 'N'
1813         x_estimate_line_rec.interface_to_om_flag := 'N';
1814 
1815         -- Convert the estimate record to
1816         -- charge record
1817         Csd_Process_Util.CONVERT_EST_TO_CHG_REC(p_estimate_line_rec => x_estimate_line_rec,
1818                                                 x_charges_rec       => l_Charges_Rec,
1819                                                 x_return_status     => x_return_status);
1820 
1821         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1822         THEN
1823             RAISE Fnd_Api.G_EXC_ERROR;
1824         END IF;
1825 
1826         IF (g_debug > 0)
1827         THEN
1828             Csd_Gen_Utility_Pvt.ADD('Call process_estimate_lines to create charge lines ');
1829         END IF;
1830 
1831         process_estimate_lines(p_api_version      => 1.0,
1832                                p_commit           => Fnd_Api.g_false,
1833                                p_init_msg_list    => Fnd_Api.g_false, -- swai 11.5.10, set to g_false
1834                                p_validation_level => Fnd_Api.g_valid_level_full,
1835                                p_action           => 'CREATE',
1836                                x_Charges_Rec      => l_Charges_Rec,
1837                                x_return_status    => x_return_status,
1838                                x_msg_count        => x_msg_count,
1839                                x_msg_data         => x_msg_data);
1840 
1841         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
1842         THEN
1843             RAISE Fnd_Api.G_EXC_ERROR;
1844         END IF;
1845 
1846         IF (g_debug > 0)
1847         THEN
1848             Csd_Gen_Utility_Pvt.ADD('NEW ESTIMATE DETAIL ID =' ||
1849                                     l_Charges_Rec.estimate_detail_id);
1850         END IF;
1851 
1852         IF (g_debug > 0)
1853         THEN
1854             Csd_Gen_Utility_Pvt.ADD('Call csd_repair_estimate_lines_pkg.insert_row to create repair estimate lines ');
1855         END IF;
1856 
1857         -- travi forward port Bug # 2789754 fix added override_charge_flag
1858         Csd_Repair_Estimate_Lines_Pkg.Insert_Row(px_REPAIR_ESTIMATE_LINE_ID  => x_estimate_line_rec.repair_estimate_line_id,
1859                                                  p_REPAIR_ESTIMATE_ID        => x_estimate_line_rec.repair_estimate_id,
1860                                                  p_ESTIMATE_DETAIL_ID        => l_Charges_Rec.estimate_detail_id,
1861                                                  p_LAST_UPDATE_DATE          => SYSDATE,
1862                                                  p_CREATION_DATE             => SYSDATE,
1863                                                  p_LAST_UPDATED_BY           => Fnd_Global.USER_ID,
1864                                                  p_CREATED_BY                => Fnd_Global.USER_ID,
1865                                                  p_LAST_UPDATE_LOGIN         => Fnd_Global.LOGIN_ID,
1866                                                  p_ITEM_COST                 => x_estimate_line_rec.item_cost,
1867                                                  p_RESOURCE_ID               => x_estimate_line_rec.resource_id,
1868                                                  p_OVERRIDE_CHARGE_FLAG      => x_estimate_line_rec.override_charge_flag,
1869                                                  p_JUSTIFICATION_NOTES       => x_estimate_line_rec.justification_notes,
1870                                                  p_ATTRIBUTE1                => x_estimate_line_rec.ATTRIBUTE1,
1871                                                  p_ATTRIBUTE2                => x_estimate_line_rec.ATTRIBUTE2,
1872                                                  p_ATTRIBUTE3                => x_estimate_line_rec.ATTRIBUTE3,
1873                                                  p_ATTRIBUTE4                => x_estimate_line_rec.ATTRIBUTE4,
1874                                                  p_ATTRIBUTE5                => x_estimate_line_rec.ATTRIBUTE5,
1875                                                  p_ATTRIBUTE6                => x_estimate_line_rec.ATTRIBUTE6,
1876                                                  p_ATTRIBUTE7                => x_estimate_line_rec.ATTRIBUTE7,
1877                                                  p_ATTRIBUTE8                => x_estimate_line_rec.ATTRIBUTE8,
1878                                                  p_ATTRIBUTE9                => x_estimate_line_rec.ATTRIBUTE9,
1879                                                  p_ATTRIBUTE10               => x_estimate_line_rec.ATTRIBUTE10,
1880                                                  p_ATTRIBUTE11               => x_estimate_line_rec.ATTRIBUTE11,
1881                                                  p_ATTRIBUTE12               => x_estimate_line_rec.ATTRIBUTE12,
1882                                                  p_ATTRIBUTE13               => x_estimate_line_rec.ATTRIBUTE13,
1883                                                  p_ATTRIBUTE14               => x_estimate_line_rec.ATTRIBUTE14,
1884                                                  p_ATTRIBUTE15               => x_estimate_line_rec.ATTRIBUTE15,
1885                                                  p_CONTEXT                   => x_estimate_line_rec.CONTEXT,
1886                                                  p_OBJECT_VERSION_NUMBER     => 1,
1887                                                  p_EST_LINE_SOURCE_TYPE_CODE => x_estimate_line_rec.EST_LINE_SOURCE_TYPE_CODE,
1888                                                  p_EST_LINE_SOURCE_ID1       => x_estimate_line_rec.EST_LINE_SOURCE_ID1,
1889                                                  p_EST_LINE_SOURCE_ID2       => x_estimate_line_rec.EST_LINE_SOURCE_ID2,
1890                                                  p_RO_SERVICE_CODE_ID        => x_estimate_line_rec.RO_SERVICE_CODE_ID);
1891 
1892         x_estimate_line_rec.object_version_number := 1;
1893 
1894         -- Api body ends here
1895 
1896         -- Standard check of p_commit.
1897         IF Fnd_Api.To_Boolean(p_commit)
1898         THEN
1899             COMMIT WORK;
1900         END IF;
1901 
1902         -- Standard call to get message count and IF count is  get message info.
1903         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1904                                   p_data  => x_msg_data);
1905     EXCEPTION
1906         WHEN Fnd_Api.G_EXC_ERROR THEN
1907             x_return_status := Fnd_Api.G_RET_STS_ERROR;
1908             ROLLBACK TO create_repair_estimate_lines;
1909             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1910                                       p_data  => x_msg_data);
1911         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
1912             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1913             ROLLBACK TO create_repair_estimate_lines;
1914             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1915                                       p_data  => x_msg_data);
1916         WHEN OTHERS THEN
1917             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
1918             ROLLBACK TO create_repair_estimate_lines;
1919             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
1920             THEN
1921                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
1922             END IF;
1923             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
1924                                       p_data  => x_msg_data);
1925     END create_repair_estimate_lines;
1926 
1927     /*--------------------------------------------------*/
1928     /* procedure name: update_repair_estimate_lines     */
1929     /* description   : procedure used to update         */
1930     /*                 repair estimate lines            */
1931     /*                                                  */
1932     /*--------------------------------------------------*/
1933 
1934     PROCEDURE UPDATE_REPAIR_ESTIMATE_LINES(p_api_version       IN NUMBER,
1935                                            p_commit            IN VARCHAR2 := Fnd_Api.g_false,
1936                                            p_init_msg_list     IN VARCHAR2 := Fnd_Api.g_false,
1937                                            p_validation_level  IN NUMBER := Fnd_Api.g_valid_level_full,
1938                                            x_estimate_line_rec IN OUT NOCOPY CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_REC,
1939                                            x_return_status     OUT NOCOPY VARCHAR2,
1940                                            x_msg_count         OUT NOCOPY NUMBER,
1941                                            x_msg_data          OUT NOCOPY VARCHAR2) IS
1942 
1943         l_api_name    CONSTANT VARCHAR2(30) := 'UPDATE_REPAIR_ESTIMATE_LINES';
1944         l_api_version CONSTANT NUMBER := 1.0;
1945         l_msg_count          NUMBER;
1946         l_msg_data           VARCHAR2(100);
1947         l_msg_index          NUMBER;
1948         l_upd_charge_flag    VARCHAR2(1) := '';
1949         l_dummy              VARCHAR2(1);
1950         l_Charges_Rec        Cs_Charge_Details_Pub.charges_rec_type;
1951         x_estimate_detail_id NUMBER := NULL;
1952         l_incident_id        NUMBER := NULL;
1953         l_party_id           NUMBER := NULL;
1954         l_account_id         NUMBER := NULL;
1955         l_order_header_id    NUMBER := NULL;
1956         l_curr_code          VARCHAR2(10) := '';
1957         l_picking_rule_id    NUMBER := NULL;
1958         l_est_detail_id      NUMBER := NULL;
1959         l_repair_line_id     NUMBER := NULL;
1960         l_booked_flag        VARCHAR2(1) := '';
1961         l_allow_ship         VARCHAR2(1) := '';
1962         l_obj_ver_num        NUMBER := NULL;
1963         l_ship_from_org_id   NUMBER := NULL;
1964         l_order_line_id      NUMBER := NULL;
1965         l_coverage_id        NUMBER := NULL;
1966         -- Bugfix 3617932, vkjain.
1967         -- Increasing the column length to 150
1968         -- l_coverage_name          VARCHAR2(150) := '';
1969         l_txn_group_id       NUMBER := NULL;
1970         l_bus_process_id     NUMBER := NULL;
1971         l_unit_selling_price NUMBER := NULL;
1972         l_serial_flag        BOOLEAN := FALSE;
1973 
1974         CURSOR estimate_line(p_est_line_id IN NUMBER) IS
1975             SELECT estimate_detail_id, object_version_number
1976               FROM CSD_REPAIR_ESTIMATE_LINES
1977              WHERE repair_estimate_line_id = p_est_line_id;
1978 
1979     BEGIN
1980         -- Standard Start of API savepoint
1981         SAVEPOINT update_repair_estimate_lines;
1982 
1983         -- Standard call to check for call compatibility.
1984         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
1985                                            p_api_version,
1986                                            l_api_name,
1987                                            G_PKG_NAME)
1988         THEN
1989             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
1990         END IF;
1991 
1992         -- Initialize message list if p_init_msg_list is set to TRUE.
1993         IF Fnd_Api.to_Boolean(p_init_msg_list)
1994         THEN
1995             Fnd_Msg_Pub.initialize;
1996         END IF;
1997 
1998         -- Initialize API return status to success
1999         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2000 
2001         -- Api body starts
2002         IF (g_debug > 0)
2003         THEN
2004             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
2005                                               p_api_name => l_api_name);
2006         END IF;
2007         -- Dump the in parameters in the log file
2008         -- if the debug level > 5
2009         -- If fnd_profile.value('CSD_DEBUG_LEVEL') > 5 then
2010 --        IF (g_debug > 5)
2011 --        THEN
2012 --            Csd_Gen_Utility_Pvt.dump_estimate_line_rec(p_estimate_line_rec => x_estimate_line_rec);
2013 --        END IF;
2014 
2015         IF (g_debug > 0)
2016         THEN
2017             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter: Repair Estimate Line id');
2018         END IF;
2019 
2020         IF (g_debug > 0)
2021         THEN
2022             Csd_Gen_Utility_Pvt.ADD('Repair Estimate Line Id =' ||
2023                                     x_estimate_line_rec.repair_estimate_line_id);
2024         END IF;
2025 
2026         -- Check the required parameter
2027         Csd_Process_Util.Check_Reqd_Param(p_param_value => x_estimate_line_rec.repair_estimate_line_id,
2028                                           p_param_name  => 'ESTIMATE_LINE_ID',
2029                                           p_api_name    => l_api_name);
2030 
2031         IF (g_debug > 0)
2032         THEN
2033             Csd_Gen_Utility_Pvt.ADD('Validate Estimate Line Id');
2034         END IF;
2035 
2036         -- Validate the repair line ID
2037         IF NOT
2038             (Csd_Process_Util.Validate_estimate_line_id(p_estimate_line_id => x_estimate_line_rec.repair_estimate_line_id))
2039         THEN
2040             RAISE Fnd_Api.G_EXC_ERROR;
2041         END IF;
2042 
2043         IF NVL(x_estimate_line_rec.repair_estimate_line_id,
2044                Fnd_Api.G_MISS_NUM) <> Fnd_Api.G_MISS_NUM
2045         THEN
2046 
2047             OPEN estimate_line(x_estimate_line_rec.repair_estimate_line_id);
2048             FETCH estimate_line
2049                 INTO l_est_detail_id, l_obj_ver_num;
2050             CLOSE estimate_line;
2051         END IF;
2052 
2053         IF NVL(x_estimate_line_rec.object_version_number,
2054                Fnd_Api.G_MISS_NUM) <> l_obj_ver_num
2055         THEN
2056             IF (g_debug > 0)
2057             THEN
2058                 Csd_Gen_Utility_Pvt.ADD('object version number does not match');
2059             END IF;
2060 
2061             Fnd_Message.SET_NAME('CSD', 'CSD_OBJ_VER_MISMATCH');
2062             Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_LINE_ID',
2063                                   x_estimate_line_rec.repair_estimate_line_id);
2064             Fnd_Msg_Pub.ADD;
2065             RAISE Fnd_Api.G_EXC_ERROR;
2066         END IF;
2067 
2068         IF NVL(x_estimate_line_rec.estimate_detail_id, Fnd_Api.G_MISS_NUM) <>
2069            Fnd_Api.G_MISS_NUM
2070         THEN
2071             IF x_estimate_line_rec.estimate_detail_id <> l_est_detail_id
2072             THEN
2073                 IF (g_debug > 0)
2074                 THEN
2075                     Csd_Gen_Utility_Pvt.ADD('The estimate detail id cannot to changed');
2076                 END IF;
2077 
2078                 RAISE Fnd_Api.G_EXC_ERROR;
2079             END IF;
2080         ELSE
2081             x_estimate_line_rec.estimate_detail_id := l_est_detail_id;
2082         END IF;
2083 
2084         IF NVL(x_estimate_line_rec.repair_line_id, Fnd_Api.G_MISS_NUM) <>
2085            Fnd_Api.G_MISS_NUM
2086         THEN
2087             IF x_estimate_line_rec.repair_line_id <> l_repair_line_id
2088             THEN
2089                 IF (g_debug > 0)
2090                 THEN
2091                     Csd_Gen_Utility_Pvt.ADD('The repair line id cannot to changed');
2092                 END IF;
2093 
2094                 RAISE Fnd_Api.G_EXC_ERROR;
2095             END IF;
2096         ELSE
2097             x_estimate_line_rec.repair_line_id := l_repair_line_id;
2098         END IF;
2099 
2100         BEGIN
2101             SELECT business_process_id
2102               INTO l_bus_process_id
2103               FROM cs_estimate_details
2104              WHERE estimate_detail_id = l_est_detail_id
2105                AND order_header_id IS NULL;
2106             l_upd_charge_flag := 'Y';
2107         EXCEPTION
2108             WHEN NO_DATA_FOUND THEN
2109                 l_upd_charge_flag := 'N';
2110         END;
2111 
2112         /* contract information passed from form
2113               IF NVL(x_estimate_line_rec.contract_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN
2114 
2115         IF (g_debug > 0 ) THEN
2116                csd_gen_utility_pvt.ADD('Getting the Coverage and txn Group Id');
2117         END IF;
2118 
2119         IF (g_debug > 0 ) THEN
2120                csd_gen_utility_pvt.ADD('contract_line_id ='||x_estimate_line_rec.contract_id);
2121         END IF;
2122 
2123         IF (g_debug > 0 ) THEN
2124                csd_gen_utility_pvt.ADD('l_bus_process_id ='||l_bus_process_id);
2125         END IF;
2126 
2127 
2128                 Begin
2129                  SELECT cov.actual_coverage_id ,
2130                         -- cov.coverage_name, -- Commented for bugfix 3617932
2131                         ent.txn_group_id
2132                  into   l_coverage_id,
2133                         -- l_coverage_name, -- Commented for bugfix 3617932
2134                         l_txn_group_id
2135                  FROM   oks_ent_coverages_v cov,
2136                         oks_ent_txn_groups_v ent
2137                  WHERE cov.contract_number = x_estimate_line_rec.contract_number -- takwong, fixed bug#2510068
2138                -- cov.contract_line_id = x_estimate_line_rec.contract_id
2139                   AND    cov.actual_coverage_id = ent.coverage_id
2140                   AND    ent.business_process_id = l_bus_process_id;
2141                 Exception
2142                  When no_data_found then
2143                   FND_MESSAGE.SET_NAME('CSD','CSD_API_CONTRACT_MISSING');
2144                   FND_MESSAGE.SET_TOKEN('CONTRACT_LINE_ID',x_estimate_line_rec.contract_id);
2145                   FND_MSG_PUB.ADD;
2146         IF (g_debug > 0 ) THEN
2147                   csd_gen_utility_pvt.ADD('Contract Line Id missing');
2148         END IF;
2149 
2150                   RAISE FND_API.G_EXC_ERROR;
2151                 End;
2152 
2153                  x_estimate_line_rec.coverage_id := l_coverage_id;
2154                  x_estimate_line_rec.coverage_txn_group_id := l_txn_group_id;
2155         IF (g_debug > 0 ) THEN
2156                  csd_gen_utility_pvt.ADD('l_coverage_id  ='||l_coverage_id);
2157         END IF;
2158 
2159         IF (g_debug > 0 ) THEN
2160                  csd_gen_utility_pvt.ADD('l_txn_group_id ='||l_txn_group_id);
2161         END IF;
2162 
2163 
2164               End If;
2165         */
2166 
2167         IF (g_debug > 0)
2168         THEN
2169             Csd_Gen_Utility_Pvt.ADD('l_upd_charge_flag =' ||
2170                                     l_upd_charge_flag);
2171         END IF;
2172 
2173         IF x_estimate_line_rec.item_cost = 0
2174         THEN
2175             IF (g_debug > 0)
2176             THEN
2177                 Csd_Gen_Utility_Pvt.ADD('item cost is zero');
2178             END IF;
2179 
2180             x_estimate_line_rec.item_cost := NULL;
2181         END IF;
2182 
2183         -- Charge lines are allowed to update only
2184         -- if it is not interfaced to OM
2185 
2186         IF l_upd_charge_flag = 'Y'
2187         THEN
2188 
2189             IF (g_debug > 0)
2190             THEN
2191                 Csd_Gen_Utility_Pvt.ADD('Convert estimate to charges rec');
2192             END IF;
2193 
2194             Csd_Process_Util.CONVERT_EST_TO_CHG_REC(p_estimate_line_rec => x_estimate_line_rec,
2195                                                     x_charges_rec       => l_Charges_Rec,
2196                                                     x_return_status     => x_return_status);
2197 
2198             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2199             THEN
2200                 IF (g_debug > 0)
2201                 THEN
2202                     Csd_Gen_Utility_Pvt.ADD('csd_process_util.convert_to_chg_rec failed');
2203                 END IF;
2204 
2205                 RAISE Fnd_Api.G_EXC_ERROR;
2206             END IF;
2207 
2208             l_Charges_Rec.estimate_detail_id := l_est_detail_id;
2209 
2210             IF (g_debug > 0)
2211             THEN
2212                 Csd_Gen_Utility_Pvt.ADD('Call process_estimate_lines to update charge lines ');
2213             END IF;
2214 
2215             IF (g_debug > 0)
2216             THEN
2217                 Csd_Gen_Utility_Pvt.ADD('Estimate Detail Id = ' ||
2218                                         l_Charges_Rec.estimate_detail_id);
2219             END IF;
2220 
2221             process_estimate_lines(p_api_version      => 1.0,
2222                                    p_commit           => Fnd_Api.g_false,
2223                                    p_init_msg_list    => Fnd_Api.g_true,
2224                                    p_validation_level => Fnd_Api.g_valid_level_full,
2225                                    p_action           => 'UPDATE',
2226                                    x_Charges_Rec      => l_Charges_Rec,
2227                                    x_return_status    => x_return_status,
2228                                    x_msg_count        => x_msg_count,
2229                                    x_msg_data         => x_msg_data);
2230 
2231             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2232             THEN
2233                 IF (g_debug > 0)
2234                 THEN
2235                     Csd_Gen_Utility_Pvt.ADD('process_estimate_lines failed ');
2236                 END IF;
2237 
2238                 RAISE Fnd_Api.G_EXC_ERROR;
2239             END IF;
2240 
2241         END IF; -- end of update charge line
2242 
2243         IF (g_debug > 0)
2244         THEN
2245             Csd_Gen_Utility_Pvt.ADD('Call csd_repair_estimate_line_pkg.update_row to update the repair estimate');
2246         END IF;
2247 
2248         IF (g_debug > 0)
2249         THEN
2250             Csd_Gen_Utility_Pvt.ADD('x_estimate_line_rec.repair_estimate_line_id =' ||
2251                                     x_estimate_line_rec.repair_estimate_line_id);
2252         END IF;
2253 
2254         -- travi forward port Bug # 2789754 fix added override_charge_flag
2255         Csd_Repair_Estimate_Lines_Pkg.Update_Row(p_REPAIR_ESTIMATE_LINE_ID   => x_estimate_line_rec.repair_estimate_line_id,
2256                                                  p_REPAIR_ESTIMATE_ID        => x_estimate_line_rec.repair_estimate_id,
2257                                                  p_ESTIMATE_DETAIL_ID        => x_estimate_line_rec.estimate_detail_id,
2258                                                  p_LAST_UPDATE_DATE          => SYSDATE,
2259                                                  p_CREATION_DATE             => SYSDATE,
2260                                                  p_LAST_UPDATED_BY           => Fnd_Global.USER_ID,
2261                                                  p_CREATED_BY                => Fnd_Global.USER_ID,
2262                                                  p_LAST_UPDATE_LOGIN         => Fnd_Global.USER_ID,
2263                                                  p_ITEM_COST                 => x_estimate_line_rec.item_cost,
2264                                                  p_RESOURCE_ID               => x_estimate_line_rec.resource_id,
2265                                                  p_OVERRIDE_CHARGE_FLAG      => x_estimate_line_rec.override_charge_flag,
2266                                                  p_JUSTIFICATION_NOTES       => x_estimate_line_rec.justification_notes,
2267                                                  p_ATTRIBUTE1                => x_estimate_line_rec.ATTRIBUTE1,
2268                                                  p_ATTRIBUTE2                => x_estimate_line_rec.ATTRIBUTE2,
2269                                                  p_ATTRIBUTE3                => x_estimate_line_rec.ATTRIBUTE3,
2270                                                  p_ATTRIBUTE4                => x_estimate_line_rec.ATTRIBUTE4,
2271                                                  p_ATTRIBUTE5                => x_estimate_line_rec.ATTRIBUTE5,
2272                                                  p_ATTRIBUTE6                => x_estimate_line_rec.ATTRIBUTE6,
2273                                                  p_ATTRIBUTE7                => x_estimate_line_rec.ATTRIBUTE7,
2274                                                  p_ATTRIBUTE8                => x_estimate_line_rec.ATTRIBUTE8,
2275                                                  p_ATTRIBUTE9                => x_estimate_line_rec.ATTRIBUTE9,
2276                                                  p_ATTRIBUTE10               => x_estimate_line_rec.ATTRIBUTE10,
2277                                                  p_ATTRIBUTE11               => x_estimate_line_rec.ATTRIBUTE11,
2278                                                  p_ATTRIBUTE12               => x_estimate_line_rec.ATTRIBUTE12,
2279                                                  p_ATTRIBUTE13               => x_estimate_line_rec.ATTRIBUTE13,
2280                                                  p_ATTRIBUTE14               => x_estimate_line_rec.ATTRIBUTE14,
2281                                                  p_ATTRIBUTE15               => x_estimate_line_rec.ATTRIBUTE15,
2282                                                  p_CONTEXT                   => x_estimate_line_rec.CONTEXT,
2283                                                  p_OBJECT_VERSION_NUMBER     => l_obj_ver_num + 1,
2284                                                  p_EST_LINE_SOURCE_TYPE_CODE => x_estimate_line_rec.EST_LINE_SOURCE_TYPE_CODE,
2285                                                  p_EST_LINE_SOURCE_ID1       => x_estimate_line_rec.EST_LINE_SOURCE_ID1,
2286                                                  p_EST_LINE_SOURCE_ID2       => x_estimate_line_rec.EST_LINE_SOURCE_ID2,
2287                                                  p_RO_SERVICE_CODE_ID        => x_estimate_line_rec.RO_SERVICE_CODE_ID);
2288 
2289         x_estimate_line_rec.object_version_number := l_obj_ver_num + 1;
2290 
2291         -- Api body ends here
2292 
2293         -- Standard check of p_commit.
2294         IF Fnd_Api.To_Boolean(p_commit)
2295         THEN
2296             COMMIT WORK;
2297         END IF;
2298 
2299         -- Standard call to get message count and IF count is  get message info.
2300         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2301                                   p_data  => x_msg_data);
2302     EXCEPTION
2303         WHEN Fnd_Api.G_EXC_ERROR THEN
2304             x_return_status := Fnd_Api.G_RET_STS_ERROR;
2305             ROLLBACK TO update_repair_estimate_lines;
2306             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2307                                       p_data  => x_msg_data);
2308         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
2309             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2310             ROLLBACK TO update_repair_estimate_lines;
2311             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2312                                       p_data  => x_msg_data);
2313         WHEN OTHERS THEN
2314             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2315             ROLLBACK TO update_repair_estimate_lines;
2316             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
2317             THEN
2318                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2319             END IF;
2320             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2321                                       p_data  => x_msg_data);
2322     END update_repair_estimate_lines;
2323 
2324     /*--------------------------------------------------*/
2325     /* procedure name: delete_repair_estimate_lines     */
2326     /* description   : procedure used to delete         */
2327     /*                 repair estimate lines            */
2328     /*                                                  */
2329     /*--------------------------------------------------*/
2330 
2331     PROCEDURE DELETE_REPAIR_ESTIMATE_LINES(p_api_version      IN NUMBER,
2332                                            p_commit           IN VARCHAR2 := Fnd_Api.g_false,
2333                                            p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
2334                                            p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
2335                                            p_estimate_line_id IN NUMBER,
2336                                            x_return_status    OUT NOCOPY VARCHAR2,
2337                                            x_msg_count        OUT NOCOPY NUMBER,
2338                                            x_msg_data         OUT NOCOPY VARCHAR2) IS
2339         l_api_name    CONSTANT VARCHAR2(30) := 'DELETE_REPAIR_ESTIMATE_LINES';
2340         l_api_version CONSTANT NUMBER := 1.0;
2341         l_msg_count          NUMBER;
2342         l_msg_data           VARCHAR2(100);
2343         l_msg_index          NUMBER;
2344         l_Charges_Rec        Cs_Charge_Details_Pub.charges_rec_type;
2345         x_estimate_detail_id NUMBER;
2346         l_est_detail_id      NUMBER;
2347         l_delete_allow       VARCHAR2(1);
2348 
2349     BEGIN
2350         -- Standard Start of API savepoint
2351         SAVEPOINT delete_repair_estimate_lines;
2352 
2353         -- Standard call to check for call compatibility.
2354         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
2355                                            p_api_version,
2356                                            l_api_name,
2357                                            G_PKG_NAME)
2358         THEN
2359             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2360         END IF;
2361 
2362         -- Initialize message list if p_init_msg_list is set to TRUE.
2363         IF Fnd_Api.to_Boolean(p_init_msg_list)
2364         THEN
2365             Fnd_Msg_Pub.initialize;
2366         END IF;
2367 
2368         -- Initialize API return status to success
2369         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2370 
2371         -- Api body starts
2372         IF (g_debug > 0)
2373         THEN
2374             Csd_Gen_Utility_Pvt.dump_api_info(p_pkg_name => G_PKG_NAME,
2375                                               p_api_name => l_api_name);
2376         END IF;
2377         IF (g_debug > 0)
2378         THEN
2379             Csd_Gen_Utility_Pvt.ADD('Check reqd parameter: Estimate Line Id ');
2380         END IF;
2381 
2382         IF (g_debug > 0)
2383         THEN
2384             Csd_Gen_Utility_Pvt.ADD('Repair Estimate Line Id  =' ||
2385                                     p_estimate_line_id);
2386         END IF;
2387 
2388         -- Check the required parameter
2389         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_estimate_line_id,
2390                                           p_param_name  => 'REPAIR_ESTIMATE_LINE_ID',
2391                                           p_api_name    => l_api_name);
2392 
2393         IF (g_debug > 0)
2394         THEN
2395             Csd_Gen_Utility_Pvt.ADD('Validate repair estimate line id');
2396         END IF;
2397 
2398         -- Validate the repair line ID
2399         IF NOT
2400             (Csd_Process_Util.Validate_estimate_line_id(p_estimate_line_id => p_estimate_line_id))
2401         THEN
2402             RAISE Fnd_Api.G_EXC_ERROR;
2403         END IF;
2404 
2405         IF (g_debug > 0)
2406         THEN
2407             Csd_Gen_Utility_Pvt.ADD('check if rocord is allowed to delete');
2408         END IF;
2409 
2410         -- The estimate line is allowed to delete
2411         -- only if it is not interfaced
2412         BEGIN
2413             SELECT a.estimate_detail_id
2414               INTO l_est_detail_id
2415               FROM CSD_REPAIR_ESTIMATE_LINES a, cs_estimate_details b
2416              WHERE a.estimate_detail_id = b.estimate_detail_id
2417                AND a.repair_estimate_line_id = p_estimate_line_id
2418                AND b.order_header_id IS NULL;
2419             l_delete_allow := 'Y';
2420         EXCEPTION
2421             WHEN NO_DATA_FOUND THEN
2422                 l_delete_allow := 'N';
2423                 IF (g_debug > 0)
2424                 THEN
2425                     Csd_Gen_Utility_Pvt.ADD('Estimate Line is interfaced,so it cannot be deleted');
2426                 END IF;
2427 
2428                 Fnd_Message.SET_NAME('CSD', 'CSD_API_DELETE_NOT_ALLOWED');
2429                 Fnd_Message.SET_TOKEN('REPAIR_ESTIMATE_LINE_ID',
2430                                       p_estimate_line_id);
2431                 Fnd_Msg_Pub.ADD;
2432                 RAISE Fnd_Api.G_EXC_ERROR;
2433         END;
2434 
2435         IF (g_debug > 0)
2436         THEN
2437             Csd_Gen_Utility_Pvt.ADD('l_delete_allow     =' ||
2438                                     l_delete_allow);
2439         END IF;
2440 
2441         IF (g_debug > 0)
2442         THEN
2443             Csd_Gen_Utility_Pvt.ADD('Estimate Detail Id =' ||
2444                                     l_est_detail_id);
2445         END IF;
2446 
2447         IF l_delete_allow = 'Y'
2448         THEN
2449 
2450             l_Charges_Rec.estimate_detail_id := l_est_detail_id;
2451 
2452             IF (g_debug > 0)
2453             THEN
2454                 Csd_Gen_Utility_Pvt.ADD('Call process_estimate_lines to delete');
2455             END IF;
2456 
2457             process_estimate_lines(p_api_version      => 1.0,
2458                                    p_commit           => Fnd_Api.g_false,
2459                                    p_init_msg_list    => Fnd_Api.g_true,
2460                                    p_validation_level => Fnd_Api.g_valid_level_full,
2461                                    p_action           => 'DELETE',
2462                                    x_Charges_Rec      => l_Charges_Rec,
2463                                    x_return_status    => x_return_status,
2464                                    x_msg_count        => x_msg_count,
2465                                    x_msg_data         => x_msg_data);
2466 
2467             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2468             THEN
2469                 RAISE Fnd_Api.G_EXC_ERROR;
2470             END IF;
2471 
2472             IF (g_debug > 0)
2473             THEN
2474                 Csd_Gen_Utility_Pvt.ADD('Call csd_product_transactions_pkg.Delete_Row');
2475             END IF;
2476 
2477             Csd_Repair_Estimate_Lines_Pkg.Delete_Row(p_REPAIR_ESTIMATE_LINE_ID => p_estimate_line_id);
2478 
2479         END IF; --end of delete
2480 
2481         -- Api body ends here
2482 
2483         -- Standard check of p_commit.
2484         IF Fnd_Api.To_Boolean(p_commit)
2485         THEN
2486             COMMIT WORK;
2487         END IF;
2488 
2489         -- Standard call to get message count and IF count is  get message info.
2490         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2491                                   p_data  => x_msg_data);
2492     EXCEPTION
2493         WHEN Fnd_Api.G_EXC_ERROR THEN
2494             x_return_status := Fnd_Api.G_RET_STS_ERROR;
2495             ROLLBACK TO delete_repair_estimate_lines;
2496             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2497                                       p_data  => x_msg_data);
2498         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
2499             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2500             ROLLBACK TO delete_repair_estimate_lines;
2501             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2502                                       p_data  => x_msg_data);
2503         WHEN OTHERS THEN
2504             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2505             ROLLBACK TO delete_repair_estimate_lines;
2506             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
2507             THEN
2508                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2509             END IF;
2510             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2511                                       p_data  => x_msg_data);
2512     END delete_repair_estimate_lines;
2513 
2514     /*--------------------------------------------------*/
2515     /* procedure name: lock_repair_estimate_lines       */
2516     /* description   : procedure used to create         */
2517     /*                 repair estimate lines            */
2518     /*--------------------------------------------------*/
2519 
2520     PROCEDURE LOCK_REPAIR_ESTIMATE_LINES(p_api_version       IN NUMBER,
2521                                          p_commit            IN VARCHAR2 := Fnd_Api.g_false,
2522                                          p_init_msg_list     IN VARCHAR2 := Fnd_Api.g_false,
2523                                          p_validation_level  IN NUMBER := Fnd_Api.g_valid_level_full,
2524                                          p_estimate_line_rec IN REPAIR_ESTIMATE_LINE_REC,
2525                                          x_return_status     OUT NOCOPY VARCHAR2,
2526                                          x_msg_count         OUT NOCOPY NUMBER,
2527                                          x_msg_data          OUT NOCOPY VARCHAR2) IS
2528 
2529         l_api_name    CONSTANT VARCHAR2(30) := 'LOCK_REPAIR_ESTIMATE_LINES';
2530         l_api_version CONSTANT NUMBER := 1.0;
2531         l_msg_count NUMBER;
2532         l_msg_data  VARCHAR2(100);
2533         l_msg_index NUMBER;
2534 
2535     BEGIN
2536         -- Standard Start of API savepoint
2537         SAVEPOINT lock_repair_estimate_lines;
2538 
2539         -- Standard call to check for call compatibility.
2540         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
2541                                            p_api_version,
2542                                            l_api_name,
2543                                            G_PKG_NAME)
2544         THEN
2545             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2546         END IF;
2547 
2548         -- Initialize message list if p_init_msg_list is set to TRUE.
2549         IF Fnd_Api.to_Boolean(p_init_msg_list)
2550         THEN
2551             Fnd_Msg_Pub.initialize;
2552         END IF;
2553 
2554         -- Initialize API return status to success
2555         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2556 
2557         Csd_Repair_Estimate_Lines_Pkg.Lock_Row(p_REPAIR_ESTIMATE_LINE_ID => p_estimate_line_rec.repair_estimate_line_id,
2558                                                p_OBJECT_VERSION_NUMBER   => p_estimate_line_rec.object_version_number);
2559 
2560         -- Standard check of p_commit.
2561         IF Fnd_Api.To_Boolean(p_commit)
2562         THEN
2563             COMMIT WORK;
2564         END IF;
2565 
2566         -- Standard call to get message count and IF count is  get message info.
2567         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2568                                   p_data  => x_msg_data);
2569     EXCEPTION
2570         WHEN Fnd_Api.G_EXC_ERROR THEN
2571             x_return_status := Fnd_Api.G_RET_STS_ERROR;
2572             ROLLBACK TO lock_repair_estimate_lines;
2573             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2574                                       p_data  => x_msg_data);
2575         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
2576             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2577             ROLLBACK TO lock_repair_estimate_lines;
2578             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2579                                       p_data  => x_msg_data);
2580         WHEN OTHERS THEN
2581             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2582             ROLLBACK TO lock_repair_estimate_lines;
2583             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
2584             THEN
2585                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2586             END IF;
2587             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2588                                       p_data  => x_msg_data);
2589     END lock_repair_estimate_lines;
2590 
2591     PROCEDURE REPAIR_ESTIMATE_PRINT(p_api_version      IN NUMBER,
2592                                     p_commit           IN VARCHAR2 := Fnd_Api.g_false,
2593                                     p_init_msg_list    IN VARCHAR2 := Fnd_Api.g_false,
2594                                     p_validation_level IN NUMBER := Fnd_Api.g_valid_level_full,
2595                                     p_repair_line_id   IN NUMBER,
2596                                     x_request_id       OUT NOCOPY NUMBER,
2597                                     x_return_status    OUT NOCOPY VARCHAR2,
2598                                     x_msg_count        OUT NOCOPY NUMBER,
2599                                     x_msg_data         OUT NOCOPY VARCHAR2) IS
2600         l_api_name    CONSTANT VARCHAR2(30) := 'REPAIR_ESTIMATE_PRINT';
2601         l_api_version CONSTANT NUMBER := 1.0;
2602         l_msg_count      NUMBER;
2603         l_msg_data       VARCHAR2(200);
2604         l_msg_index      NUMBER;
2605         l_est_count      NUMBER := 0;
2606         l_request_id     NUMBER := 0;  -- valase :6499519
2607         l_submit_Status  BOOLEAN;
2608         l_printer_name   VARCHAR2(80);
2609         l_print_required VARCHAR2(10);
2610         -- valase: 6499519  below
2611         l_layout_status  BOOLEAN;
2612         l_print_mode     VARCHAR2(30);
2613         l_xdo_conc_name  VARCHAR(30);
2614         l_template_code  VARCHAR(80);
2615         l_language       VARCHAR(2);
2616         l_territory      VARCHAR(2);
2617         CURSOR get_default_template_name(p_xdo_conc_name IN VARCHAR) IS
2618             SELECT template_code
2619               FROM fnd_concurrent_programs
2620              WHERE concurrent_program_name = p_xdo_conc_name; -- case sensitive
2621 		                                                    -- user must input con code with exactly as defined
2622         CURSOR get_lang_terr IS
2623             SELECT lower(iso_language), iso_territory
2624               FROM fnd_languages
2625              WHERE language_code = userenv('LANG');
2626         -- valase:6499519 , above
2627     BEGIN
2628         -- Standard Start of API savepoint
2629         SAVEPOINT estimate_print;
2630         -- Standard call to check for call compatibility.
2631         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
2632                                            p_api_version,
2633                                            l_api_name,
2634                                            G_PKG_NAME)
2635         THEN
2636             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2637         END IF;
2638         -- Initialize message list if p_init_msg_list is set to TRUE.
2639         IF Fnd_Api.to_Boolean(p_init_msg_list)
2640         THEN
2641             Fnd_Msg_Pub.initialize;
2642         END IF;
2643         -- Initialize API return status to success
2644         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2645         -- start of the concurrent submission
2646         l_printer_name := Fnd_Profile.value('CSD_PRINTER_NAME');
2647         IF (g_debug > 0)
2648         THEN
2649             Csd_Gen_Utility_Pvt.ADD('l_printer_name =' || l_printer_name);
2650         END IF;
2651         -- Check if the printer setup is required
2652         -- l_print_required := fnd_profile.value('CSD_EST_PRINTER_REQ');
2653         -- For bugfix 3398079. vkjain.
2654         -- The profile name was misspelt.
2655         l_print_required := Fnd_Profile.value('CSD_PRINTER_REQ');
2656         IF (g_debug > 0)
2657         THEN
2658             Csd_Gen_Utility_Pvt.ADD('l_print_required =' ||
2659                                     l_print_required);
2660         END IF;
2661         -- Check for the printer setup
2662         IF l_printer_name IS NOT NULL
2663         THEN
2664             l_submit_status := Fnd_Request.set_print_options(printer        => l_printer_name,
2665                                                              style          => 'PORTRAIT',
2666                                                              copies         => 1,
2667                                                              save_output    => TRUE,
2668                                                              print_together => 'N');
2669             IF l_submit_status
2670             THEN
2671                 IF (g_debug > 0)
2672                 THEN
2673                     Csd_Gen_Utility_Pvt.ADD('Set Print Option successfull');
2674                 END IF;
2675             ELSE
2676                 IF (g_debug > 0)
2677                 THEN
2678                     Csd_Gen_Utility_Pvt.ADD('Set Print Option Failed');
2679                 END IF;
2680                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_PRINT_OPTION_ERROR');
2681                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', p_repair_line_id);
2682                 Fnd_Msg_Pub.ADD;
2683             END IF;
2684         ELSIF (l_print_required = 'Y')
2685         THEN
2686             Fnd_Message.SET_NAME('CSD', 'CSD_EST_NOPRINTER_SETUP');
2687             Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', p_repair_line_id);
2688             Fnd_Msg_Pub.ADD;
2689         END IF;
2690         -- valase:6499519, rfieldma: 6532016  below
2691         -- get print mode
2692         l_print_mode := FND_PROFILE.value('CSD_ESTRT_PRINT_MODE');
2693 
2694         IF (l_print_mode is not null and l_print_mode <> 'ORAPT' ) THEN -- one of the XDO output types
2695             --get concurrent name
2696             l_xdo_conc_name :=FND_PROFILE.value('CSD_CUST_ESTRT_CON_NAME');
2697             IF l_xdo_conc_name is null THEN
2698                 l_xdo_conc_name := 'CSDERT';
2699             END IF;
2700             -- get default template code
2701             OPEN get_default_template_name(l_xdo_conc_name);
2702             FETCH get_default_template_name
2703              INTO l_template_code;
2704             CLOSE get_default_template_name;
2705             -- no default tempalte defined, raise error
2706             IF (l_template_code is null) THEN
2707                 Fnd_Message.SET_NAME('CSD', 'CSD_XDO_ESTRT_NO_TEMPLATE');
2708                 Fnd_Message.SET_TOKEN('PROF_NAME', csd_repairs_util.get_user_profile_option_name('CSD_CUST_ESTRT_CON_NAME'));
2709                 x_request_id := l_request_id;
2710                 Fnd_Msg_Pub.ADD;
2711                 RAISE Fnd_Api.G_EXC_ERROR;
2712             END IF;
2713             -- get current session language and territory
2714             OPEN get_lang_terr;
2715             FETCH get_lang_terr
2716              INTO l_language, l_territory;
2717             CLOSE get_lang_terr;
2718 
2719             -- XML publisher report
2720             -- set layout
2721             l_layout_status := Fnd_Request.add_layout('CSD', --template_appl_name
2722                                                        l_template_code, --'CSD_XDOESTRT_RTF', --template_code
2723                                                        l_language, --'en', 'ja',  --template_language
2724                                                        l_territory, --'US', 'JP' --template_territory
2725                                                        l_print_mode --output_format
2726                                                      );
2727             -- Submit the Concurrent Program
2728             l_request_id := Fnd_Request.submit_request('CSD',
2729                                                         l_xdo_conc_name,
2730                                                        'Depot Repair Estimate Report',
2731                                                         NULL,
2732                                                         FALSE,
2733                                                         p_repair_line_id);
2734         ELSE -- not defined or ORAPT (oracle reports)
2735              -- print in Oracle report format
2736              -- Submit the Concurrent Program
2737             l_request_id := Fnd_Request.submit_request('CSD',
2738                                                        'CSDESTRT',
2739                                                        'Depot Repair Estimate Report',
2740                                                         NULL,
2741                                                         FALSE,
2742                                                         p_repair_line_id);
2743         END IF;
2744         -- valase:6499519  above
2745         IF (g_debug > 0)
2746         THEN
2747             Csd_Gen_Utility_Pvt.ADD('Concurrent request Id =' ||
2748                                     TO_CHAR(l_request_id));
2749         END IF;
2750         IF (l_request_id <> 0)
2751         THEN
2752             COMMIT;
2753         END IF;
2754         x_request_id := l_request_id;
2755         -- Standard check of p_commit.
2756         IF Fnd_Api.To_Boolean(p_commit)
2757         THEN
2758             COMMIT WORK;
2759         END IF;
2760         -- Standard call to get message count and IF count is  get message info.
2761         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2762                                   p_data  => x_msg_data);
2763     EXCEPTION
2764         WHEN Fnd_Api.G_EXC_ERROR THEN
2765             x_return_status := Fnd_Api.G_RET_STS_ERROR;
2766             ROLLBACK TO estimate_print;
2767             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2768                                       p_data  => x_msg_data);
2769         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
2770             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2771             ROLLBACK TO estimate_print;
2772             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2773                                       p_data  => x_msg_data);
2774         WHEN OTHERS THEN
2775             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
2776             ROLLBACK TO estimate_print;
2777             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
2778             THEN
2779                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2780             END IF;
2781             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
2782                                       p_data  => x_msg_data);
2783     END REPAIR_ESTIMATE_PRINT;
2784 
2785     PROCEDURE SUBMIT_REPAIR_ESTIMATE_LINES(p_api_version      IN NUMBER,
2786                                            p_commit           IN VARCHAR2,
2787                                            p_init_msg_list    IN VARCHAR2,
2788                                            p_validation_level IN NUMBER,
2789                                            p_repair_line_id   IN NUMBER,
2790                                            x_return_status    OUT NOCOPY VARCHAR2,
2791                                            x_msg_count        OUT NOCOPY NUMBER,
2792                                            x_msg_data         OUT NOCOPY VARCHAR2) IS
2793 
2794         l_api_name    CONSTANT VARCHAR2(30) := 'SUBMIT_REPAIR_ESTIMATE_LINES';
2795         l_api_version CONSTANT NUMBER := 1.0;
2796         l_estimate_detail_id  NUMBER;
2797         l_order_header_id     NUMBER;
2798         l_msg_count           NUMBER;
2799         l_msg_data            VARCHAR2(200);
2800         l_msg_index           NUMBER;
2801         l_incident_id         NUMBER := NULL;
2802         l_party_id            NUMBER := NULL;
2803         l_order_category_code VARCHAR2(30);
2804         l_account_id          NUMBER := NULL;
2805         l_add_to_same_order   BOOLEAN := TRUE;
2806         l_last_est_detail_id  NUMBER := NULL;
2807         l_order_number        VARCHAR2(30) := '';
2808         l_org_src_ref         VARCHAR2(30) := '';
2809         l_org_src_header_id   NUMBER;
2810         l_orig_po_num         VARCHAR2(50);
2811 
2812         l_est_line_rec Cs_Charge_Details_Pub.Charges_Rec_Type;
2813 
2814         CURSOR ESTIMATE(p_rep_line_id IN NUMBER) IS
2815             SELECT ced.estimate_detail_id, ced.purchase_order_num
2816               FROM CSD_REPAIR_ESTIMATE       cre,
2817                    CSD_REPAIR_ESTIMATE_LINES crel,
2818                    cs_estimate_details       ced
2819              WHERE cre.repair_line_id = p_rep_line_id
2820                AND cre.repair_estimate_id = crel.repair_estimate_id
2821                AND crel.estimate_detail_id = ced.estimate_detail_id
2822                AND ced.order_header_id IS NULL
2823                AND ced.interface_to_oe_flag = 'N';
2824 
2825     BEGIN
2826 
2827         -- Standard Start of API savepoint
2828         SAVEPOINT submit_estimate_lines;
2829 
2830         -- Standard call to check for call compatibility.
2831         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
2832                                            p_api_version,
2833                                            l_api_name,
2834                                            G_PKG_NAME)
2835         THEN
2836             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
2837         END IF;
2838 
2839         -- Initialize message list if p_init_msg_list is set to TRUE.
2840         IF Fnd_Api.to_Boolean(p_init_msg_list)
2841         THEN
2842             Fnd_Msg_Pub.initialize;
2843         END IF;
2844 
2845         -- Initialize API return status to success
2846         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
2847 
2848         BEGIN
2849             SELECT original_source_header_id, original_source_reference
2850               INTO l_org_src_header_id, l_org_src_ref
2851               FROM CSD_REPAIRS
2852              WHERE repair_line_id = p_repair_line_id;
2853         EXCEPTION
2854             WHEN NO_DATA_FOUND THEN
2855                 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
2856                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', p_repair_line_id);
2857                 Fnd_Msg_Pub.ADD;
2858                 RAISE Fnd_Api.G_EXC_ERROR;
2859         END;
2860 
2861         IF l_org_src_ref = 'RMA'
2862         THEN
2863 
2864             BEGIN
2865                 SELECT header_id
2866                   INTO l_order_header_id
2867                   FROM oe_order_headers_all ooh, oe_order_types_v oot
2868                  WHERE ooh.order_type_id = oot.order_type_id
2869                    AND ooh.header_id = l_org_src_header_id
2870                    AND oot.order_category_code IN ('MIXED', 'ORDER');
2871                 l_add_to_same_order := TRUE;
2872             EXCEPTION
2873                 WHEN OTHERS THEN
2874                     l_add_to_same_order := FALSE;
2875                     IF (g_debug > 0)
2876                     THEN
2877                         Csd_Gen_Utility_Pvt.ADD('in others exception ');
2878                     END IF;
2879             END;
2880 
2881         ELSE
2882 
2883             -- Take any sales order of order type either Mixed or order
2884             -- and add to the sales order
2885             BEGIN
2886                 SELECT MAX(ced.order_header_id)
2887                   INTO l_order_header_id
2888                   FROM CSD_PRODUCT_TRANSACTIONS cpt,
2889                        cs_estimate_details      ced,
2890                        oe_order_headers_all     ooh,
2891                        oe_order_types_v         oot
2892                  WHERE ooh.order_type_id = oot.order_type_id
2893                    AND ooh.header_id = ced.order_header_id
2894                    AND oot.order_category_code IN ('MIXED', 'ORDER')
2895                    AND cpt.estimate_detail_id = ced.estimate_detail_id
2896                    AND cpt.repair_line_id = p_repair_line_id
2897                    AND ced.order_header_id IS NOT NULL
2898                    AND ced.interface_to_oe_flag = 'Y';
2899             EXCEPTION
2900                 WHEN OTHERS THEN
2901                     IF (g_debug > 0)
2902                     THEN
2903                         Csd_Gen_Utility_Pvt.ADD('in others exception ');
2904                     END IF;
2905             END;
2906 
2907             IF l_order_header_id = 0
2908             THEN
2909                 l_add_to_same_order := FALSE;
2910             ELSE
2911                 l_add_to_same_order := TRUE;
2912             END IF;
2913 
2914         END IF;
2915 
2916         -- updating the estimate with the interface_to_oe_flag
2917         FOR est IN estimate(p_repair_line_id)
2918         LOOP
2919 
2920             l_est_line_rec.estimate_detail_id   := est.estimate_detail_id;
2921             l_est_line_rec.interface_to_oe_flag := 'Y';
2922             l_last_est_detail_id                := est.estimate_detail_id;
2923 
2924             IF l_add_to_same_order
2925             THEN
2926                 l_est_line_rec.add_to_order_flag := 'Y';
2927                 IF l_org_src_ref = 'RMA'
2928                 THEN
2929                     l_est_line_rec.order_header_id := l_org_src_header_id;
2930                 ELSE
2931                     l_est_line_rec.order_header_id := l_order_header_id;
2932                 END IF;
2933                 --
2934                 --  Fix for forward port bug # 2826897
2935                 --
2936                 IF est.purchase_order_num IS NOT NULL
2937                 THEN
2938                     BEGIN
2939                         SELECT ced.purchase_order_num
2940                           INTO l_orig_po_num
2941                           FROM CSD_PRODUCT_TRANSACTIONS cpt,
2942                                cs_estimate_details      ced
2943                          WHERE cpt.estimate_detail_id =
2944                                ced.estimate_detail_id
2945                            AND cpt.repair_line_id = p_repair_line_id
2946                            AND ced.order_header_id =
2947                                l_est_line_rec.order_header_id
2948                            AND ced.purchase_order_num =
2949                                est.purchase_order_num;
2950                     EXCEPTION
2951                         WHEN NO_DATA_FOUND THEN
2952                             l_est_line_rec.add_to_order_flag := 'F';
2953                             l_est_line_rec.order_header_id   := Fnd_Api.G_MISS_NUM;
2954                         WHEN TOO_MANY_ROWS THEN
2955                             NULL;
2956                     END;
2957                 END IF;
2958             ELSE
2959                 l_est_line_rec.add_to_order_flag := 'F';
2960                 l_est_line_rec.order_header_id   := Fnd_Api.G_MISS_NUM;
2961             END IF;
2962             IF (g_debug > 0)
2963             THEN
2964                 Csd_Gen_Utility_Pvt.ADD('Updating estimate lines  with add to order flag for estimate_detail_id = ' ||
2965                                         est.estimate_detail_id);
2966             END IF;
2967 
2968             Csd_Process_Pvt.PROCESS_CHARGE_LINES(p_api_version        => 1.0,
2969                                                  p_commit             => Fnd_Api.g_false,
2970                                                  p_init_msg_list      => Fnd_Api.g_true,
2971                                                  p_validation_level   => Fnd_Api.g_valid_level_full,
2972                                                  p_action             => 'UPDATE',
2973                                                  p_Charges_Rec        => l_est_line_rec,
2974                                                  x_estimate_detail_id => l_estimate_detail_id,
2975                                                  x_return_status      => x_return_status,
2976                                                  x_msg_count          => x_msg_count,
2977                                                  x_msg_data           => x_msg_data);
2978 
2979             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
2980             THEN
2981                 RAISE Fnd_Api.G_EXC_ERROR;
2982             END IF;
2983 
2984         END LOOP;
2985 
2986         BEGIN
2987             SELECT cia.incident_id, cia.customer_id, cia.account_id
2988               INTO l_incident_id, l_party_id, l_account_id
2989               FROM cs_incidents_all_b cia, CSD_REPAIRS cr
2990              WHERE cia.incident_id = cr.incident_id
2991                AND cr.repair_line_id = p_repair_line_id;
2992         EXCEPTION
2993             WHEN NO_DATA_FOUND THEN
2994                 Fnd_Message.SET_NAME('CSD', 'CSD_API_INV_REP_LINE_ID');
2995                 Fnd_Message.SET_TOKEN('REPAIR_LINE_ID', p_repair_line_id);
2996                 Fnd_Msg_Pub.ADD;
2997                 RAISE Fnd_Api.G_EXC_ERROR;
2998         END;
2999 
3000         IF (g_debug > 0)
3001         THEN
3002             Csd_Gen_Utility_Pvt.ADD('Creating the Sales Order');
3003             Csd_Gen_Utility_Pvt.ADD('l_incident_id    =' || l_incident_id);
3004             Csd_Gen_Utility_Pvt.ADD('l_party_id       =' || l_party_id);
3005             Csd_Gen_Utility_Pvt.ADD('l_account_id     =' || l_account_id);
3006         END IF;
3007 
3008         Cs_Charge_Create_Order_Pub.Submit_Order(p_api_version      => 1.0,
3009                                                 p_init_msg_list    => 'T',
3010                                                 p_commit           => 'F',
3011                                                 p_validation_level => Fnd_Api.g_valid_level_full,
3012                                                 p_incident_id      => l_incident_id,
3013                                                 p_party_id         => l_party_id,
3014                                                 p_account_id       => l_account_id,
3015                                                 p_book_order_flag  => 'N',
3016                                                 x_return_status    => x_return_status,
3017                                                 x_msg_count        => x_msg_count,
3018                                                 x_msg_data         => x_msg_data);
3019 
3020         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3021         THEN
3022             RAISE Fnd_Api.G_EXC_ERROR;
3023         END IF;
3024 
3025         BEGIN
3026             SELECT oe.order_number
3027               INTO l_order_number
3028               FROM oe_order_headers_all oe, cs_estimate_details ced
3029              WHERE oe.header_id = ced.order_header_id
3030                AND ced.estimate_detail_id = l_last_est_detail_id;
3031             Fnd_Message.SET_NAME('CSD', 'CSD_EST_ORDER_NUMBER');
3032             Fnd_Message.SET_TOKEN('ORDER_NUMBER', l_order_number);
3033             Fnd_Msg_Pub.ADD;
3034         EXCEPTION
3035             WHEN NO_DATA_FOUND THEN
3036                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_NOT_INTERFACED');
3037                 Fnd_Msg_Pub.ADD;
3038                 IF (g_debug > 0)
3039                 THEN
3040                     Csd_Gen_Utility_Pvt.ADD('Estimate not interfaced to OM ');
3041                 END IF;
3042         END;
3043 
3044         -- Standard check of p_commit.
3045         IF Fnd_Api.To_Boolean(p_commit)
3046         THEN
3047             COMMIT WORK;
3048         END IF;
3049 
3050         -- Standard call to get message count and IF count is  get message info.
3051         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3052                                   p_data  => x_msg_data);
3053     EXCEPTION
3054         WHEN Fnd_Api.G_EXC_ERROR THEN
3055             x_return_status := Fnd_Api.G_RET_STS_ERROR;
3056             ROLLBACK TO submit_estimate_lines;
3057             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3058                                       p_data  => x_msg_data);
3059         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
3060             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
3061             ROLLBACK TO submit_estimate_lines;
3062             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3063                                       p_data  => x_msg_data);
3064         WHEN OTHERS THEN
3065             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
3066             ROLLBACK TO submit_estimate_lines;
3067             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
3068             THEN
3069                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
3070             END IF;
3071             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3072                                       p_data  => x_msg_data);
3073 
3074     END SUBMIT_REPAIR_ESTIMATE_LINES;
3075 
3076     --
3077     -- swai 11.5.10
3078     -- new apis
3079     --
3080     /*--------------------------------------------------*/
3081     /* procedure name: get_total_estimated_charge       */
3082     /* description   : given a repair line id, returns  */
3083     /*                 the total charge (includes any   */
3084     /*                 contract calculations)  If no    */
3085     /*                 estimate lines for the repair    */
3086     /*                 line, return null.               */
3087     /*--------------------------------------------------*/
3088 
3089     PROCEDURE get_total_estimated_charge(p_repair_line_id   IN NUMBER,
3090                                          x_estimated_charge OUT NOCOPY NUMBER,
3091                                          x_return_status    OUT NOCOPY VARCHAR2) IS
3092         lc_debug_level CONSTANT NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
3093         lc_stat_level  CONSTANT NUMBER := Fnd_Log.LEVEL_STATEMENT;
3094         lc_proc_level  CONSTANT NUMBER := Fnd_Log.LEVEL_PROCEDURE;
3095         lc_event_level CONSTANT NUMBER := Fnd_Log.LEVEL_EVENT;
3096         lc_excep_level CONSTANT NUMBER := Fnd_Log.LEVEL_EXCEPTION;
3097         lc_error_level CONSTANT NUMBER := Fnd_Log.LEVEL_ERROR;
3098         lc_unexp_level CONSTANT NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
3099         lc_mod_name    CONSTANT VARCHAR2(100) := 'csd.plsql.csd_repair_estimate_pvt.get_total_estimated_charge';
3100     BEGIN
3101         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3102         THEN
3103             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3104                            lc_mod_name || '.BEGIN',
3105                            'Entered get_total_estimated_charge');
3106         END IF;
3107 
3108         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3109 
3110         SELECT SUM(NVL(charge, 0))
3111           INTO x_estimated_charge
3112           FROM csd_repair_estimate_lines_v
3113          WHERE repair_line_id = p_repair_line_id
3114            AND billing_type IN ('M', 'L', 'E');
3115 
3116         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3117         THEN
3118             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3119                            lc_mod_name || 'out_parameter',
3120                            'x_estimated_charge: ' || x_estimated_charge);
3121         END IF;
3122         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3123         THEN
3124             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3125                            lc_mod_name || '.END',
3126                            'Leaving get_total_estimated_charge');
3127         END IF;
3128     EXCEPTION
3129         WHEN NO_DATA_FOUND THEN
3130             x_return_status    := Fnd_Api.G_RET_STS_ERROR;
3131             x_estimated_charge := NULL;
3132         WHEN OTHERS THEN
3133             x_return_status    := Fnd_Api.G_RET_STS_ERROR;
3134             x_estimated_charge := NULL;
3135     END; -- PROCEDURE get_total_estimated_charge
3136 
3137     /*--------------------------------------------------*/
3138     /* procedure name: Autocreate_Estimate_Lines        */
3139     /* description   : The main procedure that is       */
3140     /*                 triggered by the click of the    */
3141     /*                 button on the `Estimates' tab.   */
3142     /*                 Creates all the estimate lines   */
3143     /*                 for TASK or BOM.                 */
3144     /*                                                  */
3145     /* x_warning_flag : FND_API.G_TRUE if any non-fatal */
3146     /*                  errors occured. FND_API.G_FALSE */
3147     /*                  if everything was successful.   */
3148     /*                  Note that this value could be   */
3149     /*                  G_TRUE even if x_return_status  */
3150     /*                  is G_RET_STS_SUCCESS            */
3151     /* called from:  Depot Repair UI                    */
3152     /*--------------------------------------------------*/
3153 
3154     PROCEDURE Autocreate_Estimate_Lines(p_api_version         IN NUMBER,
3155                                         p_commit              IN VARCHAR2,
3156                                         p_init_msg_list       IN VARCHAR2,
3157                                         p_validation_level    IN NUMBER,
3158                                         x_return_status       OUT NOCOPY VARCHAR2,
3159                                         x_msg_count           OUT NOCOPY NUMBER,
3160                                         x_msg_data            OUT NOCOPY VARCHAR2,
3161                                         p_repair_line_id      IN NUMBER,
3162                                         p_estimate_id         IN NUMBER, -- required
3163                                         p_repair_type_id      IN NUMBER, -- required
3164                                         p_business_process_id IN NUMBER, -- required
3165                                         p_currency_code       IN VARCHAR2, -- required
3166                                         p_incident_id         IN NUMBER, -- required
3167                                         p_repair_mode         IN VARCHAR2, -- required
3168                                         p_inventory_item_id   IN NUMBER, -- required
3169                                         p_organization_id     IN NUMBER, -- required
3170                                         x_warning_flag        OUT NOCOPY VARCHAR2) IS
3171         -- CONSTANTS --
3172         lc_debug_level CONSTANT NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
3173         lc_stat_level  CONSTANT NUMBER := Fnd_Log.LEVEL_STATEMENT;
3174         lc_proc_level  CONSTANT NUMBER := Fnd_Log.LEVEL_PROCEDURE;
3175         lc_event_level CONSTANT NUMBER := Fnd_Log.LEVEL_EVENT;
3176         lc_excep_level CONSTANT NUMBER := Fnd_Log.LEVEL_EXCEPTION;
3177         lc_error_level CONSTANT NUMBER := Fnd_Log.LEVEL_ERROR;
3178         lc_unexp_level CONSTANT NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
3179         lc_mod_name    CONSTANT VARCHAR2(100) := 'csd.plsql.csd_repair_estimate_pvt.autocreate_estimate_lines';
3180         lc_api_name    CONSTANT VARCHAR2(30) := 'Autocreate_Estimate_Lines';
3181         lc_api_version CONSTANT NUMBER := 1.0;
3182 
3183         -- VARIABLES --
3184         l_default_contract_line_id NUMBER := NULL;
3185         l_default_price_list_id    NUMBER := NULL;
3186         l_num_service_codes        NUMBER := 0;
3187         l_contract_validated       BOOLEAN;
3188         l_est_lines_tbl            CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_TBL;
3189         l_return_status            VARCHAR2(1);
3190         l_msg_count                NUMBER;
3191         l_msg_data                 VARCHAR2(200);
3192         l_estimate_line_id         NUMBER;
3193         l_ro_sc_rec_type           Csd_Ro_Service_Codes_Pvt.RO_SERVICE_CODE_REC_TYPE;
3194         l_obj_ver_number           NUMBER;
3195         l_prev_ro_sc_id            NUMBER;
3196         l_item_name                VARCHAR2(40);
3197         l_warning_flag             VARCHAR2(1) := Fnd_Api.G_FALSE;
3198 
3199         -- EXCEPTIONS --
3200         CSD_EST_SC_NO_APPL EXCEPTION; -- no service codes to apply
3201         CSD_EST_DEF_PL EXCEPTION; -- no default price list
3202         CSD_EST_INAPPL_MODE EXCEPTION; -- cannot apply service code for repair mode
3203 
3204         -- CURSORS --
3205         CURSOR c_ro_sc_obj_version(p_ro_service_code_id NUMBER) IS
3206             SELECT object_version_number
3207               FROM CSD_RO_SERVICE_CODES
3208              WHERE ro_service_code_id = p_ro_service_code_id;
3209 
3210     BEGIN
3211         -- Standard Start of API savepoint
3212         SAVEPOINT Autocreate_Estimate_Lines;
3213 
3214         -- Standard call to check for call compatibility.
3215         IF NOT Fnd_Api.Compatible_API_Call(lc_api_version,
3216                                            p_api_version,
3217                                            lc_api_name,
3218                                            G_PKG_NAME)
3219         THEN
3220             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
3221         END IF;
3222 
3223         -- Initialize message list if p_init_msg_list is set to TRUE.
3224         IF Fnd_Api.to_Boolean(p_init_msg_list)
3225         THEN
3226             Fnd_Msg_Pub.initialize;
3227         END IF;
3228 
3229         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3230         THEN
3231             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3232                            lc_mod_name || '.BEGIN',
3233                            'Entered Autocreate_Estimate_Lines');
3234         END IF;
3235 
3236         -- log parameters
3237         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3238         THEN
3239             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3240                            lc_mod_name || '.parameter_logging',
3241                            'p_api_version: ' || p_api_version);
3242             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3243                            lc_mod_name || '.parameter_logging',
3244                            'p_commit: ' || p_commit);
3245             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3246                            lc_mod_name || '.parameter_logging',
3247                            'p_init_msg_list: ' || p_init_msg_list);
3248             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3249                            lc_mod_name || '.parameter_logging',
3250                            'p_validation_level: ' || p_validation_level);
3251             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3252                            lc_mod_name || '.parameter_logging',
3253                            'p_repair_line_id: ' || p_repair_line_id);
3254             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3255                            lc_mod_name || '.parameter_logging',
3256                            'p_estimate_id: ' || p_estimate_id);
3257             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3258                            lc_mod_name || '.parameter_logging',
3259                            'p_repair_type_id: ' || p_repair_type_id);
3260             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3261                            lc_mod_name || '.parameter_logging',
3262                            'p_business_process_id: ' ||
3263                            p_business_process_id);
3264             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3265                            lc_mod_name || '.parameter_logging',
3266                            'p_currency_code: ' || p_currency_code);
3267             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3268                            lc_mod_name || '.parameter_logging',
3269                            'p_incident_id: ' || p_incident_id);
3270             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3271                            lc_mod_name || '.parameter_logging',
3272                            'p_repair_mode: ' || p_repair_mode);
3273             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3274                            lc_mod_name || '.parameter_logging',
3275                            'p_inventory_item_id: ' || p_inventory_item_id);
3276             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3277                            lc_mod_name || '.parameter_logging',
3278                            'p_organization_id: ' || p_organization_id);
3279         END IF;
3280 
3281         -- Initialize API return status to success
3282         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3283 
3284         --
3285         -- Begin API Body
3286         --
3287 
3288         -- initialize the warning flag
3289         x_warning_flag := Fnd_Api.G_FALSE;
3290 
3291         -- Check the required parameters
3292         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3293         THEN
3294             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3295                            lc_mod_name,
3296                            'Checking required parameters');
3297         END IF;
3298 
3299         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_repair_line_id,
3300                                           p_param_name  => 'REPAIR_LINE_ID',
3301                                           p_api_name    => lc_api_name);
3302 
3303         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_estimate_id,
3304                                           p_param_name  => 'ESTIMATE_ID',
3305                                           p_api_name    => lc_api_name);
3306 
3307         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_repair_type_id,
3308                                           p_param_name  => 'REPAIR_TYPE_ID',
3309                                           p_api_name    => lc_api_name);
3310 
3311         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_business_process_id,
3312                                           p_param_name  => 'BUSINESS_PROCESS_ID',
3313                                           p_api_name    => lc_api_name);
3314 
3315         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_currency_code,
3316                                           p_param_name  => 'CURRENCY_CODE',
3317                                           p_api_name    => lc_api_name);
3318 
3319         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_incident_id,
3320                                           p_param_name  => 'INCIDENT_ID',
3321                                           p_api_name    => lc_api_name);
3322 
3323         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_repair_mode,
3324                                           p_param_name  => 'REPAIR_MODE',
3325                                           p_api_name    => lc_api_name);
3326 
3327         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_inventory_item_id,
3328                                           p_param_name  => 'INVENTORY_ITEM_ID',
3329                                           p_api_name    => lc_api_name);
3330 
3331         Csd_Process_Util.Check_Reqd_Param(p_param_value => p_organization_id,
3332                                           p_param_name  => 'ORGANIZATION_ID',
3333                                           p_api_name    => lc_api_name);
3334 
3335         -- Check number of service codes to get mle lines for
3336         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3337         THEN
3338             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3339                            lc_mod_name,
3340                            'Counting the number of service codes to apply');
3341         END IF;
3342         BEGIN
3343             SELECT COUNT(*)
3344               INTO l_num_service_codes
3345               FROM CSD_RO_SERVICE_CODES
3346              WHERE repair_line_id = p_repair_line_id
3347                AND NVL(applicable_flag, 'N') = 'Y'
3348                AND NVL(applied_to_est_flag, 'N') = 'N';
3349             -- Commented for bugfix 3473869.vkjain.
3350             -- and nvl(applied_to_work_flag, 'N') = 'N';
3351         EXCEPTION
3352             WHEN OTHERS THEN
3353                 l_num_service_codes := 0;
3354         END;
3355 
3356         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3357         THEN
3358             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3359                            lc_mod_name,
3360                            'l_num_service_codes: ' || l_num_service_codes);
3361         END IF;
3362 
3363         -- if no applicable service codes, see if we need to
3364         -- raise an error
3365         IF (l_num_service_codes <= 0)
3366         THEN
3367             -- bug fix 3388891
3368             -- only give an error if it is wip or if
3369             -- in task mode profile option is not set to get tasks from soln
3370             IF (p_repair_mode = 'WIP') OR
3371                (NVL(Fnd_Profile.value('CSD_USE_TASK_FROM_SOLN'), 'N') = 'N')
3372             THEN
3373                 RAISE CSD_EST_SC_NO_APPL;
3374             END IF;
3375         END IF;
3376 
3377         -- Get default Contract.
3378         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3379         THEN
3380             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3381                            lc_mod_name,
3382                            'Calling CSD_CHARGE_LINE_UTIL.Get_DefaultContract');
3383         END IF;
3384 
3385         l_default_contract_line_id := Csd_Charge_Line_Util.Get_DefaultContract(p_repair_line_id);
3386 
3387         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3388         THEN
3389             -- log results from previous call
3390             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3391                            lc_mod_name,
3392                            'Returned from CSD_CHARGE_LINE_UTIL.Get_DefaultContract');
3393             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3394                            lc_mod_name,
3395                            'l_default_contract_line_id = ' ||
3396                            l_default_contract_line_id);
3397             -- log the next call
3398             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3399                            lc_mod_name,
3400                            'calling CSD_CHARGE_LINE_UTIL.Get_RO_PriceList');
3401         END IF;
3402 
3403         l_default_price_list_id := Csd_Charge_Line_Util.Get_RO_PriceList(p_repair_line_id);
3404         IF l_default_price_list_id IS NULL
3405         THEN
3406             RAISE CSD_EST_DEF_PL;
3407         END IF;
3408 
3409         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3410         THEN
3411             -- log results from previous call
3412             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3413                            lc_mod_name,
3414                            'Returned from CSD_CHARGE_LINE_UTIL.Get_RO_PriceList');
3415             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3416                            lc_mod_name,
3417                            'l_default_price_list_id = ' ||
3418                            l_default_price_list_id);
3419             -- log the next call
3420             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3421                            lc_mod_name,
3422                            'Calling CSD_GEN_ERRMSGS_PVT.purge_entity_msgs');
3423         END IF;
3424 
3425         -- initialize local return status before calling procedures
3426         l_return_status := Fnd_Api.G_RET_STS_SUCCESS;
3427 
3428         -- purge any existing messages before processing
3429         -- Module ACT (source entity ESTIMATE).
3430         Csd_Gen_Errmsgs_Pvt.purge_entity_msgs(p_api_version             => 1.0,
3431                                               p_commit                  => Fnd_Api.G_TRUE,
3432                                               p_init_msg_list           => Fnd_Api.G_FALSE,
3433                                               p_validation_level        => Fnd_Api.G_VALID_LEVEL_FULL,
3434                                               p_module_code             => 'EST',
3435                                               p_source_entity_id1       => p_repair_line_id,
3436                                               p_source_entity_type_code => NULL,
3437                                               p_source_entity_id2       => NULL,
3438                                               x_return_status           => l_return_status,
3439                                               x_msg_count               => l_msg_count,
3440                                               x_msg_data                => l_msg_data);
3441         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3442         THEN
3443             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3444                            lc_mod_name,
3445                            'Returned from CSD_GEN_ERRMSGS_PVT.purge_entity_msgs');
3446         END IF;
3447         IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
3448         THEN
3449             RAISE Fnd_Api.G_EXC_ERROR;
3450         END IF;
3451 
3452         -- Now, get info for estimate lines into l_est_lines_tbl
3453         IF p_repair_mode = 'TASK'
3454         THEN
3455             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3456             THEN
3457                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3458                                lc_mod_name,
3459                                'Calling CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_Task');
3460             END IF;
3461             Get_Estimates_From_Task(p_api_version         => 1.0,
3462                                     p_commit              => p_commit,
3463                                     p_init_msg_list       => Fnd_Api.G_FALSE,
3464                                     p_validation_level    => p_validation_level,
3465                                     x_return_status       => l_return_status,
3466                                     x_msg_count           => l_msg_count,
3467                                     x_msg_data            => l_msg_data,
3468                                     p_repair_line_id      => p_repair_line_id,
3469                                     p_estimate_id         => p_estimate_id,
3470                                     p_repair_type_id      => p_repair_type_id,
3471                                     p_business_process_id => p_business_process_id,
3472                                     p_currency_code       => p_currency_code,
3473                                     p_incident_id         => p_incident_id,
3474                                     p_repair_mode         => p_repair_mode,
3475                                     p_inventory_item_id   => p_inventory_item_id,
3476                                     p_organization_id     => p_organization_id,
3477                                     p_price_list_id       => l_default_price_list_id,
3478                                     p_contract_line_id    => l_default_contract_line_id,
3479                                     x_est_lines_tbl       => l_est_lines_tbl,
3480                                     x_warning_flag        => l_warning_flag);
3481             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3482             THEN
3483                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3484                                lc_mod_name,
3485                                'Returned from CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_Task');
3486             END IF;
3487         ELSIF p_repair_mode = 'WIP'
3488         THEN
3489             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3490             THEN
3491                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3492                                lc_mod_name,
3493                                'Calling CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_BOM');
3494             END IF;
3495             Get_Estimates_From_BOM(p_api_version         => 1.0,
3496                                    p_commit              => p_commit,
3497                                    p_init_msg_list       => Fnd_Api.G_FALSE,
3498                                    p_validation_level    => p_validation_level,
3499                                    x_return_status       => l_return_status,
3500                                    x_msg_count           => l_msg_count,
3501                                    x_msg_data            => l_msg_data,
3502                                    p_repair_line_id      => p_repair_line_id,
3503                                    p_estimate_id         => p_estimate_id,
3504                                    p_repair_type_id      => p_repair_type_id,
3505                                    p_business_process_id => p_business_process_id,
3506                                    p_currency_code       => p_currency_code,
3507                                    p_incident_id         => p_incident_id,
3508                                    p_repair_mode         => p_repair_mode,
3509                                    p_inventory_item_id   => p_inventory_item_id,
3510                                    p_organization_id     => p_organization_id,
3511                                    p_price_list_id       => l_default_price_list_id,
3512                                    p_contract_line_id    => l_default_contract_line_id,
3513                                    x_est_lines_tbl       => l_est_lines_tbl,
3514                                    x_warning_flag        => l_warning_flag);
3515             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3516             THEN
3517                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3518                                lc_mod_name,
3519                                'Returned from CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_BOM');
3520             END IF;
3521         ELSE
3522             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3523             THEN
3524                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
3525                                lc_mod_name,
3526                                'Unknown Repair Mode: ' || p_repair_mode);
3527             END IF;
3528             RAISE CSD_EST_INAPPL_MODE;
3529         END IF;
3530 
3531         -- Loop through the estimates table of records and insert into Estimate lines and Charge lines.
3532         IF NOT (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3533         THEN
3534             RAISE Fnd_Api.G_EXC_ERROR;
3535         ELSE
3536             -- if any warnings were raised already, then save them
3537             -- before attempting to create estimate lines
3538             IF (l_warning_flag = Fnd_Api.G_TRUE)
3539             THEN
3540                 x_warning_flag := l_warning_flag;
3541                 IF (Fnd_Log.Level_Procedure >=
3542                    Fnd_Log.G_Current_Runtime_Level)
3543                 THEN
3544                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3545                                    lc_mod_name,
3546                                    'Calling CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
3547                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3548                                    lc_mod_name,
3549                                    'Number of messages in stack: ' ||
3550                                    Fnd_Msg_Pub.count_msg);
3551                 END IF;
3552                 Csd_Gen_Errmsgs_Pvt.Save_Fnd_Msgs(p_api_version             => 1.0,
3553                                                   p_commit                  => Fnd_Api.G_FALSE,
3554                                                   p_init_msg_list           => Fnd_Api.G_FALSE,
3555                                                   p_validation_level        => 0,
3556                                                   p_module_code             => 'EST',
3557                                                   p_source_entity_id1       => p_repair_line_id,
3558                                                   p_source_entity_type_code => 'ESTIMATE',
3559                                                   p_source_entity_id2       => p_estimate_id,
3560                                                   x_return_status           => l_return_status,
3561                                                   x_msg_count               => l_msg_count,
3562                                                   x_msg_data                => l_msg_data);
3563                 IF NOT (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3564                 THEN
3565                     RAISE Fnd_Api.G_EXC_ERROR;
3566                 END IF;
3567                 IF (Fnd_Log.Level_Procedure >=
3568                    Fnd_Log.G_Current_Runtime_Level)
3569                 THEN
3570                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3571                                    lc_mod_name,
3572                                    'Returned from CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
3573                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3574                                    lc_mod_name,
3575                                    'Number of messages in stack: ' ||
3576                                    Fnd_Msg_Pub.count_msg);
3577                 END IF;
3578             END IF;
3579 
3580             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3581             THEN
3582                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
3583                                lc_mod_name,
3584                                'Creating repair estimate lines');
3585             END IF;
3586             FOR i IN 1 .. l_est_lines_tbl.COUNT
3587             LOOP
3588                 BEGIN
3589                     IF (Fnd_Log.Level_Statement >=
3590                        Fnd_Log.G_Current_Runtime_Level)
3591                     THEN
3592                         Fnd_Log.STRING(Fnd_Log.Level_Statement,
3593                                        lc_mod_name,
3594                                        'Calling create_repair_estimate_lines for line ' || i);
3595                     END IF;
3596                     create_repair_estimate_lines(p_api_version       => 1.0,
3597                                                  p_commit            => Fnd_Api.G_FALSE,
3598                                                  p_init_msg_list     => Fnd_Api.G_FALSE,
3599                                                  p_validation_level  => 0,
3600                                                  x_estimate_line_rec => l_est_lines_tbl(i),
3601                                                  x_estimate_line_id  => l_estimate_line_id, -- throw away
3602                                                  x_return_status     => l_return_status,
3603                                                  x_msg_count         => l_msg_count,
3604                                                  x_msg_data          => l_msg_data);
3605                 EXCEPTION
3606                     WHEN Fnd_Api.G_EXC_ERROR THEN
3607                         l_return_status := Fnd_Api.G_RET_STS_ERROR;
3608                     WHEN OTHERS THEN
3609                         l_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
3610                 END;
3611 
3612                 IF (Fnd_Log.Level_Statement >=
3613                    Fnd_Log.G_Current_Runtime_Level)
3614                 THEN
3615                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
3616                                    lc_mod_name,
3617                                    'x_estimate_line_rec = ' ||
3618                                    TO_CHAR(l_est_lines_tbl(i)
3619                                            .repair_estimate_line_id));
3620                     -- FND_LOG.STRING(Fnd_Log.Level_Procedure, lc_mod_name,
3621                     --               'x_return_status = '||l_return_status);
3622                 END IF;
3623 
3624                 -- If SC have been applied to create estimate lines successfully,
3625                 -- make sure to update CSD_RO_SERVICE_CODES table with the value `Y' for the
3626                 -- column that indicates `applied to estimates'.
3627                 IF (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3628                 THEN
3629                     -- if previous ro_sc_id is same as current, no need to update
3630                     -- ro_service_code id, since it should have been done already
3631                     IF (NVL(l_prev_ro_sc_id, -999) <>
3632                        NVL(l_est_lines_tbl(i).RO_SERVICE_CODE_ID, -999)) AND
3633                        (l_est_lines_tbl(i).RO_SERVICE_CODE_ID IS NOT NULL)
3634                     THEN
3635 
3636                         IF (Fnd_Log.Level_Statement >=
3637                            Fnd_Log.G_Current_Runtime_Level)
3638                         THEN
3639                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3640                                            lc_mod_name,
3641                                            'l_prev_ro_sc_id = ' ||
3642                                            TO_CHAR(l_prev_ro_sc_id));
3643                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3644                                            lc_mod_name,
3645                                            'l_est_lines_tbl(i).RO_SERVICE_CODE_ID = ' ||
3646                                            TO_CHAR(l_est_lines_tbl(i)
3647                                                    .RO_SERVICE_CODE_ID));
3648                         END IF;
3649 
3650                         l_ro_sc_rec_type.ro_service_code_id  := l_est_lines_tbl(i)
3651                                                                .RO_SERVICE_CODE_ID;
3652                         l_ro_sc_rec_type.applied_to_est_flag := 'Y';
3653                         OPEN c_ro_sc_obj_version(l_est_lines_tbl(i)
3654                                                  .RO_SERVICE_CODE_ID);
3655                         FETCH c_ro_sc_obj_version
3656                             INTO l_ro_sc_rec_type.object_version_number;
3657                         CLOSE c_ro_sc_obj_version;
3658 
3659                         IF (Fnd_Log.Level_Procedure >=
3660                            Fnd_Log.G_Current_Runtime_Level)
3661                         THEN
3662                             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3663                                            lc_mod_name,
3664                                            'Calling CSD_RO_SERVICE_CODES_PVT.Update_RO_Service_Code');
3665                         END IF;
3666                         Csd_Ro_Service_Codes_Pvt.Update_RO_Service_Code(p_api_version         => 1.0,
3667                                                                         p_commit              => Fnd_Api.G_FALSE,
3668                                                                         p_init_msg_list       => Fnd_Api.G_FALSE,
3669                                                                         p_validation_level    => 0,
3670                                                                         p_ro_service_code_rec => l_ro_sc_rec_type,
3671                                                                         x_obj_ver_number      => l_obj_ver_number,
3672                                                                         x_return_status       => l_return_status,
3673                                                                         x_msg_count           => l_msg_count,
3674                                                                         x_msg_data            => l_msg_data);
3675 
3676                         IF (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3677                         THEN
3678                             l_prev_ro_sc_id := l_est_lines_tbl(i)
3679                                               .RO_SERVICE_CODE_ID;
3680                         ELSE
3681                             -- not able to update csd_ro_service_codes table to set as applied to est
3682                             x_warning_flag := Fnd_Api.G_TRUE;
3683                             IF (Fnd_Log.Level_Statement >=
3684                                Fnd_Log.G_Current_Runtime_Level)
3685                             THEN
3686                                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
3687                                                lc_mod_name,
3688                                                'Adding message CSD_EST_SC_APPLIED_ERR to FND_MSG stack');
3689                             END IF;
3690                             Fnd_Message.SET_NAME('CSD',
3691                                                  'CSD_EST_SC_APPLIED_ERR');
3692                             Fnd_Msg_Pub.ADD;
3693                             IF (Fnd_Log.Level_Procedure >=
3694                                Fnd_Log.G_Current_Runtime_Level)
3695                             THEN
3696                                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3697                                                lc_mod_name,
3698                                                'Calling CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
3699                                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3700                                                lc_mod_name,
3701                                                'Number of messages in stack: ' ||
3702                                                Fnd_Msg_Pub.count_msg);
3703                             END IF;
3704                             Csd_Gen_Errmsgs_Pvt.Save_Fnd_Msgs(p_api_version             => 1.0,
3705                                                               p_commit                  => Fnd_Api.G_FALSE,
3706                                                               p_init_msg_list           => Fnd_Api.G_FALSE,
3707                                                               p_validation_level        => 0,
3708                                                               p_module_code             => 'EST',
3709                                                               p_source_entity_id1       => p_repair_line_id,
3710                                                               p_source_entity_type_code => l_est_lines_tbl(i)
3711                                                                                           .est_line_source_type_code,
3712                                                               p_source_entity_id2       => l_est_lines_tbl(i)
3713                                                                                           .est_line_source_id1,
3714                                                               x_return_status           => l_return_status,
3715                                                               x_msg_count               => l_msg_count,
3716                                                               x_msg_data                => l_msg_data);
3717                             IF NOT
3718                                 (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3719                             THEN
3720                                 RAISE Fnd_Api.G_EXC_ERROR;
3721                             END IF;
3722                             IF (Fnd_Log.Level_Procedure >=
3723                                Fnd_Log.G_Current_Runtime_Level)
3724                             THEN
3725                                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3726                                                lc_mod_name,
3727                                                'Returned from CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
3728                                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3729                                                lc_mod_name,
3730                                                'Number of messages in stack: ' ||
3731                                                Fnd_Msg_Pub.count_msg);
3732                             END IF;
3733                         END IF;
3734                     END IF;
3735                 ELSE
3736                     -- not able to create repair estimate line from record in table
3737                     -- log a warning and save the error messages.
3738                     IF (Fnd_Log.Level_Procedure >=
3739                        Fnd_Log.G_Current_Runtime_Level)
3740                     THEN
3741                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3742                                        lc_mod_name,
3743                                        'Unable to create repair estimate line for index ' || i);
3744                     END IF;
3745 
3746                     x_warning_flag := Fnd_Api.G_TRUE;
3747                     BEGIN
3748                         SELECT concatenated_segments
3749                           INTO l_item_name
3750                           FROM mtl_system_items_kfv
3751                          WHERE inventory_item_id = l_est_lines_tbl(i)
3752                         .inventory_item_id
3753                            AND organization_id = l_est_lines_tbl(i)
3754                         .organization_id;
3755                     EXCEPTION
3756                         WHEN NO_DATA_FOUND THEN
3757                             l_item_name := TO_CHAR(l_est_lines_tbl(i)
3758                                                    .inventory_item_id);
3759                         WHEN OTHERS THEN
3760                             l_item_name := TO_CHAR(l_est_lines_tbl(i)
3761                                                    .inventory_item_id);
3762                     END;
3763 
3764                     IF (Fnd_Log.Level_Statement >=
3765                        Fnd_Log.G_Current_Runtime_Level)
3766                     THEN
3767                         Fnd_Log.STRING(Fnd_Log.Level_Statement,
3768                                        lc_mod_name,
3769                                        'Adding message CSD_EST_LINE_CREATED_ERR to FND_MSG stack');
3770                     END IF;
3771                     Fnd_Message.SET_NAME('CSD', 'CSD_EST_LINE_CREATED_ERR');
3772                     Fnd_Message.SET_TOKEN('ITEM', l_item_name);
3773                     Fnd_Msg_Pub.ADD;
3774                     IF (Fnd_Log.Level_Procedure >=
3775                        Fnd_Log.G_Current_Runtime_Level)
3776                     THEN
3777                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3778                                        lc_mod_name,
3779                                        'Calling CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
3780                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3781                                        lc_mod_name,
3782                                        'Number of messages in stack: ' ||
3783                                        Fnd_Msg_Pub.count_msg);
3784                     END IF;
3785                     Csd_Gen_Errmsgs_Pvt.Save_Fnd_Msgs(p_api_version             => 1.0,
3786                                                       p_commit                  => Fnd_Api.G_FALSE,
3787                                                       p_init_msg_list           => Fnd_Api.G_FALSE,
3788                                                       p_validation_level        => 0,
3789                                                       p_module_code             => 'EST',
3790                                                       p_source_entity_id1       => p_repair_line_id,
3791                                                       p_source_entity_type_code => l_est_lines_tbl(i)
3792                                                                                   .est_line_source_type_code,
3793                                                       p_source_entity_id2       => l_est_lines_tbl(i)
3794                                                                                   .est_line_source_id1,
3795                                                       x_return_status           => l_return_status,
3796                                                       x_msg_count               => l_msg_count,
3797                                                       x_msg_data                => l_msg_data);
3798                     IF NOT (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
3799                     THEN
3800                         RAISE Fnd_Api.G_EXC_ERROR;
3801                     END IF;
3802                     IF (Fnd_Log.Level_Procedure >=
3803                        Fnd_Log.G_Current_Runtime_Level)
3804                     THEN
3805                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3806                                        lc_mod_name,
3807                                        'Returned from CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
3808                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3809                                        lc_mod_name,
3810                                        'Number of messages in stack: ' ||
3811                                        Fnd_Msg_Pub.count_msg);
3812                     END IF;
3813                 END IF;
3814             END LOOP;
3815 
3816         END IF;
3817         --
3818         -- End API Body
3819         --
3820 
3821         -- Standard check of p_commit.
3822         IF Fnd_Api.To_Boolean(p_commit)
3823         THEN
3824             COMMIT WORK;
3825         END IF;
3826 
3827         -- Standard call to get message count and IF count is  get message info.
3828         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3829                                   p_data  => x_msg_data);
3830 
3831         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3832         THEN
3833             Fnd_Log.STRING(Fnd_Log.Level_Statement,
3834                            lc_mod_name || '.out_parameter',
3835                            'x_warning_flag: ' || x_warning_flag);
3836         END IF;
3837 
3838         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
3839         THEN
3840             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
3841                            lc_mod_name || '.END',
3842                            'Leaving Autocreate_Estimate_Lines');
3843         END IF;
3844 
3845     EXCEPTION
3846         WHEN CSD_EST_SC_NO_APPL THEN
3847             ROLLBACK TO Autocreate_Estimate_Lines;
3848             -- No service codes found to apply
3849             x_return_status := Fnd_Api.G_RET_STS_ERROR;
3850             x_warning_flag  := Fnd_Api.G_FALSE;
3851 
3852             -- save message in fnd stack
3853             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3854             THEN
3855                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
3856                                lc_mod_name,
3857                                'Adding message CSD_EST_SC_NO_APPL to FND_MSG stack');
3858             END IF;
3859             Fnd_Message.SET_NAME('CSD', 'CSD_EST_SC_NO_APPL');
3860             Fnd_Msg_Pub.ADD;
3861             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3862                                       p_data  => x_msg_data);
3863 
3864             -- save message in debug log
3865             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
3866             THEN
3867                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
3868                                lc_mod_name,
3869                                'No service codes found to apply');
3870             END IF;
3871         WHEN CSD_EST_DEF_PL THEN
3872             -- Unable to determine default pricelist
3873             ROLLBACK TO Autocreate_Estimate_Lines;
3874             x_return_status := Fnd_Api.G_RET_STS_ERROR;
3875             x_warning_flag  := Fnd_Api.G_FALSE;
3876 
3877             -- save message in fnd stack
3878             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3879             THEN
3880                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
3881                                lc_mod_name,
3882                                'Adding message CSD_EST_NO_DEF_PL to FND_MSG stack');
3883             END IF;
3884             Fnd_Message.SET_NAME('CSD', 'CSD_EST_NO_DEF_PL');
3885             Fnd_Msg_Pub.ADD;
3886             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3887                                       p_data  => x_msg_data);
3888 
3889             -- save message in debug log
3890             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
3891             THEN
3892                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
3893                                lc_mod_name,
3894                                'Unable to determine default pricelist');
3895             END IF;
3896 
3897         WHEN CSD_EST_INAPPL_MODE THEN
3898             -- cannot apply service code for repair mode
3899             ROLLBACK TO Autocreate_Estimate_Lines;
3900             x_return_status := Fnd_Api.G_RET_STS_ERROR;
3901             x_warning_flag  := Fnd_Api.G_FALSE;
3902 
3903             -- save message in fnd stack
3904             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
3905             THEN
3906                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
3907                                lc_mod_name,
3908                                'Adding message CSD_EST_INAPPL_MODE to FND_MSG stack');
3909             END IF;
3910             DECLARE
3911                 l_repair_mode_name VARCHAR2(80) := '';
3912             BEGIN
3913                 SELECT meaning
3914                   INTO l_repair_mode_name
3915                   FROM fnd_lookups
3916                  WHERE lookup_type = 'CSD_REPAIR_MODE'
3917                    AND lookup_code = p_repair_mode;
3918                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_INAPPL_MODE');
3919                 Fnd_Message.SET_TOKEN('MODE', l_repair_mode_name);
3920                 Fnd_Msg_Pub.ADD;
3921             EXCEPTION
3922                 WHEN NO_DATA_FOUND THEN
3923                     l_repair_mode_name := p_repair_mode;
3924             END;
3925             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3926                                       p_data  => x_msg_data);
3927 
3928             -- save message in debug log
3929             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
3930             THEN
3931                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
3932                                lc_mod_name,
3933                                'Cannot apply service code for repair mode');
3934             END IF;
3935         WHEN Fnd_Api.G_EXC_ERROR THEN
3936             ROLLBACK TO Autocreate_Estimate_Lines;
3937             x_return_status := Fnd_Api.G_RET_STS_ERROR;
3938 
3939             /*
3940             -- TO DO: Add seeded err message
3941             -- save message in fnd stack
3942             if (Fnd_Log.Level_Statement>= Fnd_Log.G_Current_Runtime_Level) then
3943                 FND_LOG.STRING(Fnd_Log.Level_Statement, lc_mod_name,
3944                                'Adding message err_name to FND_MSG stack');
3945             end if;
3946             FND_MESSAGE.SET_NAME('CSD','err_name');
3947             FND_MESSAGE.SET_TOKEN('toke_name', 'token_value');
3948             FND_MSG_PUB.ADD;
3949             */
3950             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3951                                       p_data  => x_msg_data);
3952 
3953             -- save message in debug log
3954             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
3955             THEN
3956                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
3957                                lc_mod_name,
3958                                'EXC_ERROR[' || x_msg_data || ']');
3959             END IF;
3960         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
3961             ROLLBACK TO Autocreate_Estimate_Lines;
3962             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
3963 
3964             -- save message in fnd stack
3965             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
3966             THEN
3967                 IF (Fnd_Log.Level_Statement >=
3968                    Fnd_Log.G_Current_Runtime_Level)
3969                 THEN
3970                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
3971                                    lc_mod_name,
3972                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
3973                 END IF;
3974                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
3975             END IF;
3976             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
3977                                       p_data  => x_msg_data);
3978 
3979             -- save message in debug log
3980             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
3981             THEN
3982                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
3983                                lc_mod_name,
3984                                'EXC_UNEXPECTED_ERROR[' || x_msg_data || ']');
3985             END IF;
3986         WHEN OTHERS THEN
3987             ROLLBACK TO Autocreate_Estimate_Lines;
3988             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
3989 
3990             -- save message in fnd stack
3991             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
3992             THEN
3993                 IF (Fnd_Log.Level_Statement >=
3994                    Fnd_Log.G_Current_Runtime_Level)
3995                 THEN
3996                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
3997                                    lc_mod_name,
3998                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
3999                 END IF;
4000                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
4001             END IF;
4002             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
4003                                       p_data  => x_msg_data);
4004 
4005             -- save message in debug log
4006             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
4007             THEN
4008                 -- create a seeded message
4009                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
4010                                lc_mod_name,
4011                                'SQL Message[' || SQLERRM || ']');
4012             END IF;
4013 
4014     END Autocreate_Estimate_Lines;
4015 
4016     /*--------------------------------------------------*/
4017     /* procedure name: Get_Estimates_From_Task          */
4018     /* description   : Fetches ML lines for the tasks   */
4019     /*                 associated via Service Codes and */
4020     /*                 (optionally) Solution.           */
4021     /*                                                  */
4022     /* x_warning_flag : FND_API.G_TRUE if any non-fatal */
4023     /*                  errors occured. FND_API.G_FALSE */
4024     /*                  if everything was successful.   */
4025     /*                  Note that this value could be   */
4026     /*                  G_TRUE even if x_return_status  */
4027     /*                  is G_RET_STS_SUCCESS            */
4028     /* called from:  Autocreate_Estimate_Lines          */
4029     /*--------------------------------------------------*/
4030     PROCEDURE Get_Estimates_From_Task(p_api_version         IN NUMBER,
4031                                       p_commit              IN VARCHAR2,
4032                                       p_init_msg_list       IN VARCHAR2,
4033                                       p_validation_level    IN NUMBER,
4034                                       x_return_status       OUT NOCOPY VARCHAR2,
4035                                       x_msg_count           OUT NOCOPY NUMBER,
4036                                       x_msg_data            OUT NOCOPY VARCHAR2,
4037                                       p_repair_line_id      IN NUMBER,
4038                                       p_estimate_id         IN NUMBER,
4039                                       p_repair_type_id      IN NUMBER,
4040                                       p_business_process_id IN NUMBER,
4041                                       p_currency_code       IN VARCHAR2,
4042                                       p_incident_id         IN NUMBER,
4043                                       p_repair_mode         IN VARCHAR2,
4044                                       p_inventory_item_id   IN NUMBER,
4045                                       p_organization_id     IN NUMBER,
4046                                       p_price_list_id       IN NUMBER,
4047                                       p_contract_line_id    IN NUMBER,
4048                                       x_est_lines_tbl       OUT NOCOPY CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_TBL,
4049                                       x_warning_flag        OUT NOCOPY VARCHAR2) IS
4050         -- CONSTANTS --
4051         lc_debug_level CONSTANT NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
4052         lc_stat_level  CONSTANT NUMBER := Fnd_Log.LEVEL_STATEMENT;
4053         lc_proc_level  CONSTANT NUMBER := Fnd_Log.LEVEL_PROCEDURE;
4054         lc_event_level CONSTANT NUMBER := Fnd_Log.LEVEL_EVENT;
4055         lc_excep_level CONSTANT NUMBER := Fnd_Log.LEVEL_EXCEPTION;
4056         lc_error_level CONSTANT NUMBER := Fnd_Log.LEVEL_ERROR;
4057         lc_unexp_level CONSTANT NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
4058         lc_mod_name    CONSTANT VARCHAR2(100) := 'csd.plsql.csd_repair_estimate_pvt.get_estimates_from_task';
4059         lc_api_name    CONSTANT VARCHAR2(30) := 'Get_Estimates_From_Task';
4060         lc_api_version CONSTANT NUMBER := 1.0;
4061 
4062         -- VARIABLES --
4063         l_use_tasks_from_sol      VARCHAR(1);
4064         l_labor_inventory_item_id NUMBER;
4065         l_materials_from_sc_tbl   MLE_LINES_TBL_TYPE;
4066         l_labor_from_sc_tbl       MLE_LINES_TBL_TYPE;
4067         l_materials_from_sol_tbl  MLE_LINES_TBL_TYPE;
4068         l_labor_from_sol_tbl      MLE_LINES_TBL_TYPE;
4069         l_task_threshold          NUMBER;
4070         l_warning_flag            VARCHAR2(1);
4071         l_return_status           VARCHAR2(1);
4072         l_msg_count               NUMBER;
4073         l_msg_data                VARCHAR2(2000);
4074 
4075         -- bugfix 3543135, vkjain.
4076         l_No_Eligible_Lines BOOLEAN := TRUE;
4077 
4078         -- EXCEPTIONS --
4079         CSD_EST_NO_AUTOGEN EXCEPTION;
4080 
4081         -- CURSORS --
4082 
4083         /* bugfix 3468680. vkjain
4084            The selling price should be derived via API call instead of
4085            selecting from the query.
4086            The cursors are replaced by new ones.
4087            Following changes are made to the existing cursors -
4088            -- Cursors do not accept p_price_list_id as IN parameter anymore.
4089            -- They do not select the list_price from the QP view.
4090            -- The reference to QP view is removed from the FROM part of statements.
4091            -- All joins for the QP view commented in the WHERE clause.
4092            -- The selling price is derived in the Convert_to_est_lines procedure
4093               by calling CSD_PROCESS_UTIL.GET_CHARGE_SELLING_PRICE API.
4094 
4095           -- Cursor gets:
4096           -- Information to create material lines from task groups attached to
4097           -- srvice codes linked to the repair line id.
4098           cursor c_material_lines_from_sc (p_repair_line_id NUMBER,
4099                                           p_price_list_id  NUMBER) is
4100             SELECT b.inventory_item_id,
4101                    b.primary_uom_code uom,
4102                    b.manual_quantity manual_qty,
4103                    ceil(b.rollup_quantity_used/b.rollup_times_used) rollup_qty,
4104                    a.actual_times_used times_used,
4105                    c.list_price selling_price,
4106                    d.concatenated_segments item_name,
4107                    d.comms_nl_trackable_flag,
4108                    f.txn_billing_type_id,
4109                    'SERVICE_CODE' est_line_source_type_code,
4110                    ROSC.Service_code_id est_line_source_id1,
4111                    null est_line_source_id2,
4112                    ROSC.RO_Service_code_id
4113             FROM CSD_RO_SERVICE_CODES ROSC,
4114                  CSD_SERVICE_CODES_VL SC,
4115                  CSD_SC_WORK_ENTITIES WRK,
4116                  CSP_PRODUCT_TASKS a,
4117                  CSP_TASK_PARTS  b,
4118                  QP_PRICE_LIST_LINES_V c,
4119                  MTL_SYSTEM_ITEMS_KFV d,
4120                  CSD_REPAIR_TYPES_SAR e,
4121                  CS_TXN_BILLING_TYPES f,
4122                  JTF_TASK_TEMPLATES_VL g
4123             WHERE ROSC.repair_line_id = p_repair_line_id
4124                 and ROSC.applicable_flag = 'Y'
4125                 -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
4126                 and ROSC.applied_to_est_flag = 'N'
4127                 and WRK.Service_code_id = ROSC.Service_code_id
4128                 and WRK.work_entity_type_code = 'TASK'
4129                 and SC.Service_code_Id = ROSC.Service_code_id
4130                 and nvl(SC.active_from, SYSDATE) <= SYSDATE
4131                 and nvl(SC.active_to, SYSDATE) >= SYSDATE
4132                 and g.task_group_id = WRK.work_entity_id1
4133                 and a.task_template_id = g.task_template_id
4134                 and a.product_id = p_inventory_item_id
4135                 and b.product_task_id = a.product_task_id
4136                 and (b.manual_quantity IS NOT NULL OR
4137                      b.rollup_quantity_used IS NOT NULL)
4138                 and b.substitute_item IS NULL
4139                 and c.price_list_id(+) = p_price_list_id
4140                 and c.inventory_item_id(+) = b.inventory_item_id
4141                 and c.unit_code(+) = b.primary_uom_code
4142                 and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4143                 and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4144                 and d.inventory_item_id = b.inventory_item_id
4145                 and d.organization_id = p_organization_id
4146                 and e.repair_type_id = p_repair_type_id
4147                 and f.txn_billing_type_id = e.txn_billing_type_id(+)
4148                 and f.billing_type = d.material_billable_flag(+)
4149                 and d.material_billable_flag IS NOT NULL;
4150 
4151           -- Cursor gets:
4152           -- Information to create labor lines from task groups attached to
4153           -- service codes linked to the repair line id.
4154           cursor c_labor_lines_from_sc (p_repair_line_id NUMBER,
4155                                         p_price_list_id  NUMBER,
4156                                         p_labor_inventory_item_id NUMBER) is
4157                 SELECT p_labor_inventory_item_id inventory_item_id,
4158                        b.planned_effort_uom uom,
4159                        b.planned_effort quantity,
4160                        c.list_price selling_price,
4161                        d.concatenated_segments item_name,
4162                        d.comms_nl_trackable_flag,
4163                        f.txn_billing_type_id,
4164                        'SERVICE_CODE' est_line_source_type_code,
4165                        ROSC.Service_code_id est_line_source_id1,
4166                        null est_line_source_id2,
4167                        ROSC.RO_Service_code_id
4168                 FROM CSD_RO_SERVICE_CODES ROSC,
4169                      CSD_SERVICE_CODES_VL SC,
4170                      CSD_SC_WORK_ENTITIES WRK,
4171                      JTF_TASK_TEMPLATES_B  b,
4172                      QP_PRICE_LIST_LINES_V c,
4173                      MTL_SYSTEM_ITEMS_KFV d,
4174                      CSD_REPAIR_TYPES_SAR e,
4175                      CS_TXN_BILLING_TYPES f,
4176                      JTF_TASK_TEMPLATES_VL g
4177                 WHERE ROSC.repair_line_id = p_repair_line_id
4178                     and ROSC.applicable_flag = 'Y'
4179                     -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
4180                     and ROSC.applied_to_est_flag = 'N'
4181                     and WRK.Service_code_id = ROSC.Service_code_id
4182                     and WRK.work_entity_type_code = 'TASK'
4183                     and SC.Service_code_Id = ROSC.Service_code_id
4184                     and nvl(SC.active_from, SYSDATE) <= SYSDATE
4185                     and nvl(SC.active_to, SYSDATE) >= SYSDATE
4186                     and g.task_group_id = WRK.work_entity_id1
4187                     and b.task_template_id = g.task_template_id
4188                     and b.planned_effort is NOT NULL
4189                     and b.planned_effort_uom is NOT NULL
4190                     and c.price_list_id(+) = p_price_list_id
4191                     and c.inventory_item_id(+) = p_labor_inventory_item_id
4192                     and c.unit_code(+) = b.planned_effort_uom
4193                     and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4194                     and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4195                     and d.inventory_item_id = p_labor_inventory_item_id
4196                     and d.organization_id = p_organization_id
4197                     and e.repair_type_id = p_repair_type_id
4198                     and f.txn_billing_type_id = e.txn_billing_type_id(+)
4199                     and f.billing_type = d.material_billable_flag(+)
4200                     and d.material_billable_flag IS NOT NULL;
4201 
4202 
4203           -- Cursor gets:
4204           -- Information to create material lines from task groups attached to
4205           -- solutions linked to the repair line id.
4206           cursor c_material_lines_from_sol (p_repair_line_id NUMBER,
4207                                         p_price_list_id  NUMBER,
4208                                         p_inventory_item_id NUMBER,
4209                                         p_organization_id NUMBER,
4210                                         p_repair_type_id NUMBER) is
4211                 SELECT b.inventory_item_id,
4212                        b.primary_uom_code uom,
4213                        b.manual_quantity manual_qty,
4214                        ceil(b.rollup_quantity_used/b.rollup_times_used) rollup_qty,
4215                        a.actual_times_used times_used,
4216                        c.list_price selling_price,
4217                        d.concatenated_segments item_name,
4218                        d.comms_nl_trackable_flag,
4219                        f.txn_billing_type_id,
4220                        'SOLUTION' est_line_source_type_code,
4221                        SetLinkRO.set_id est_line_source_id1,
4222                        null est_line_source_id2,
4223                        null ro_service_code_id
4224                 FROM
4225                      cs_kb_set_links SetLinkTG, --link to task group
4226                      cs_kb_set_links SetLinkRO, -- link to repair order
4227                      cs_kb_sets_vl KBSets,
4228                      jtf_task_temp_groups_vl JtfTaskTempGroupEO,
4229                      csp_product_tasks a,
4230                      csp_task_parts  b,
4231                      qp_price_list_lines_v c,
4232                      mtl_system_items_kfv d,
4233                      csd_repair_types_sar e,
4234                      cs_txn_billing_types f,
4235                      jtf_task_templates_vl g
4236                 WHERE
4237                         g.task_group_id = JtfTaskTempGroupEO.task_template_group_id
4238                     and a.task_template_id = g.task_template_id
4239                     and a.product_id = p_inventory_item_id
4240                     and b.product_task_id = a.product_task_id
4241                     and (b.manual_quantity IS NOT NULL OR
4242                          b.rollup_quantity_used IS NOT NULL)
4243                     and b.substitute_item IS NULL
4244                     and c.price_list_id(+) = p_price_list_id
4245                     and c.inventory_item_id(+) = b.inventory_item_id
4246                     and c.unit_code(+) = b.primary_uom_code
4247                     and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4248                     and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4249                     and d.inventory_item_id = b.inventory_item_id
4250                     and d.material_billable_flag IS NOT NULL
4251                     and d.organization_id = p_organization_id
4252                     and e.repair_type_id = p_repair_type_id
4253                     and f.txn_billing_type_id = e.txn_billing_type_id(+)
4254                     and f.billing_type = d.material_billable_flag(+)
4255                     and SetLinkRO.other_id = p_repair_line_id
4256                     and SetLinkRO.object_code = 'DR'
4257                     and SetLinkRO.link_type = 'S'
4258                     and SetLinkTG.set_id = SetLinkRO.set_id
4259                     and SetLinkTG.other_id = JtfTaskTempGroupEO.task_template_group_id
4260                     and SetLinkTG.object_code = 'CS_KB_TASK_TEMPLATE_GRP'
4261                     and JtfTaskTempGroupEO.application_id = 512  -- depot repair task groups only
4262                     and KBSets.set_id = SetLinkTG.set_id
4263                     and KBSets.status = 'PUB'               -- only published solutions
4264                     and not exists                          -- not already brought in
4265                         ( select 'x'
4266                           from  csd_repair_estimate_lines_v csd
4267                           where csd.repair_line_id = SetLinkRO.other_id
4268                             and csd.est_line_source_type_code = 'SOLUTION'
4269                             and csd.est_line_source_id1 = KBSets.set_id);
4270 
4271           -- Cursor gets:
4272           -- Information to create labor lines from task groups attached to
4273           -- solutions linked to the repair line id.
4274           cursor c_labor_lines_from_sol (p_repair_line_id NUMBER,
4275                                         p_price_list_id  NUMBER,
4276                                         p_labor_inventory_item_id NUMBER,
4277                                         p_organization_id NUMBER,
4278                                         p_repair_type_id NUMBER) is
4279                 SELECT p_labor_inventory_item_id inventory_item_id,
4280                        b.planned_effort_uom uom,
4281                        b.planned_effort quantity,
4282                        c.list_price selling_price,
4283                        d.concatenated_segments item_name,
4284                        d.comms_nl_trackable_flag,
4285                        f.txn_billing_type_id,
4286                        'SOLUTION' est_line_source_type_code,
4287                        SetLinkRO.set_id est_line_source_id1,
4288                        null est_line_source_id2,
4289                        null ro_service_code_id
4290                 FROM
4291                      cs_kb_set_links SetLinkTG, --link to task group
4292                      cs_kb_set_links SetLinkRO, -- link to repair order
4293                      cs_kb_sets_vl KBSets,
4294                      jtf_task_temp_groups_vl JtfTaskTempGroupEO,
4295                      jtf_task_templates_b  b,
4296                      qp_price_list_lines_v c,
4297                      mtl_system_items_kfv d,
4298                      csd_repair_types_sar e,
4299                      cs_txn_billing_types f,
4300                      jtf_task_templates_vl g
4301                 WHERE
4302                         SetLinkRO.other_id = p_repair_line_id
4303                     and SetLinkRO.object_code = 'DR'
4304                     and SetLinkRO.link_type = 'S'
4305                     and SetLinkTG.set_id = SetLinkRO.set_id
4306                     and SetLinkTG.other_id = JtfTaskTempGroupEO.task_template_group_id
4307                     and SetLinkTG.object_code = 'CS_KB_TASK_TEMPLATE_GRP'
4308                     and g.task_group_id = JtfTaskTempGroupEO.task_template_group_id
4309                     and b.task_template_id = g.task_template_id
4310                     and b.planned_effort is NOT NULL
4311                     and b.planned_effort_uom is NOT NULL
4312                     and c.price_list_id(+) = p_price_list_id
4313                     and c.inventory_item_id(+) = p_labor_inventory_item_id
4314                     and c.unit_code(+) = b.planned_effort_uom
4315                     and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4316                     and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4317                     and d.inventory_item_id = p_labor_inventory_item_id
4318                     and d.organization_id = p_organization_id
4319                     and e.repair_type_id = p_repair_type_id
4320                     and f.txn_billing_type_id = e.txn_billing_type_id(+)
4321                     and f.billing_type = d.material_billable_flag(+)
4322                     and d.material_billable_flag IS NOT NULL
4323                     and JtfTaskTempGroupEO.application_id = 512  -- depot repair task groups only
4324                     and KBSets.set_id = SetLinkTG.set_id
4325                     and KBSets.status = 'PUB'               -- only published solutions
4326                     and not exists                          -- not already brought in
4327                         ( select 'x'
4328                           from  csd_repair_estimate_lines_v csd
4329                           where csd.repair_line_id = SetLinkRO.other_id
4330                             and csd.est_line_source_type_code = 'SOLUTION'
4331                             and csd.est_line_source_id1 = KBSets.set_id);
4332         */
4333 
4334         -- Cursor gets:
4335         -- Information to create material lines from task groups attached to
4336         -- srvice codes linked to the repair line id.
4337         CURSOR c_material_lines_from_sc(p_repair_line_id NUMBER) IS
4338         -- p_price_list_id  NUMBER) is , bug 3468680, vkjain
4339             SELECT b.inventory_item_id,
4340                    b.primary_uom_code uom,
4341                    b.manual_quantity manual_qty,
4342                    CEIL(b.rollup_quantity_used / b.rollup_times_used) rollup_qty,
4343                    a.actual_times_used times_used,
4344                    -- c.list_price selling_price,
4345                    d.concatenated_segments item_name,
4346                    d.comms_nl_trackable_flag,
4347                    f.txn_billing_type_id,
4348                    'SERVICE_CODE' est_line_source_type_code,
4349                    ROSC.Service_code_id est_line_source_id1,
4350                    NULL est_line_source_id2,
4351                    ROSC.RO_Service_code_id
4352               FROM CSD_RO_SERVICE_CODES ROSC,
4353                    CSD_SERVICE_CODES_VL SC,
4354                    CSD_SC_WORK_ENTITIES WRK,
4355                    CSP_PRODUCT_TASKS    a,
4356                    CSP_TASK_PARTS       b,
4357                    -- QP_PRICE_LIST_LINES_V c,
4358                    MTL_SYSTEM_ITEMS_KFV  d,
4359                    CSD_REPAIR_TYPES_SAR  e,
4360                    CS_TXN_BILLING_TYPES  f,
4361                    JTF_TASK_TEMPLATES_VL g
4362              WHERE ROSC.repair_line_id = p_repair_line_id
4363                AND ROSC.applicable_flag = 'Y'
4364                   -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
4365                AND ROSC.applied_to_est_flag = 'N'
4366                AND WRK.Service_code_id = ROSC.Service_code_id
4367                AND WRK.work_entity_type_code = 'TASK'
4368                AND SC.Service_code_Id = ROSC.Service_code_id
4369                AND NVL(SC.active_from, SYSDATE) <= SYSDATE
4370                AND NVL(SC.active_to, SYSDATE) >= SYSDATE
4371                AND g.task_group_id = WRK.work_entity_id1
4372                AND a.task_template_id = g.task_template_id
4373                AND a.product_id = p_inventory_item_id
4374                AND b.product_task_id = a.product_task_id
4375                AND (b.manual_quantity IS NOT NULL OR
4376                    b.rollup_quantity_used IS NOT NULL)
4377                AND b.substitute_item IS NULL
4378                   -- Following lines commented by vkjain, bugfix 3468680
4379                   -- and c.price_list_id(+) = p_price_list_id
4380                   -- and c.inventory_item_id(+) = b.inventory_item_id
4381                   -- and c.unit_code(+) = b.primary_uom_code
4382                   -- and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4383                   -- and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4384                AND d.inventory_item_id = b.inventory_item_id
4385                AND d.organization_id = p_organization_id
4386                AND e.repair_type_id = p_repair_type_id
4387                AND f.txn_billing_type_id = e.txn_billing_type_id(+)
4388                AND f.billing_type = d.material_billable_flag(+)
4389                AND d.material_billable_flag IS NOT NULL;
4390 
4391         -- Cursor gets:
4392         -- Information to create labor lines from task groups attached to
4393         -- service codes linked to the repair line id.
4394         CURSOR c_labor_lines_from_sc(p_repair_line_id NUMBER,
4395         -- p_price_list_id  NUMBER, bug 3468680, vkjain
4396         p_labor_inventory_item_id NUMBER) IS
4397             SELECT p_labor_inventory_item_id inventory_item_id,
4398                    b.planned_effort_uom      uom,
4399                    b.planned_effort          quantity,
4400                    -- c.list_price selling_price,
4401                    d.concatenated_segments item_name,
4402                    d.comms_nl_trackable_flag,
4403                    f.txn_billing_type_id,
4404                    'SERVICE_CODE' est_line_source_type_code,
4405                    ROSC.Service_code_id est_line_source_id1,
4406                    NULL est_line_source_id2,
4407                    ROSC.RO_Service_code_id
4408               FROM CSD_RO_SERVICE_CODES ROSC,
4409                    CSD_SERVICE_CODES_VL SC,
4410                    CSD_SC_WORK_ENTITIES WRK,
4411                    JTF_TASK_TEMPLATES_B b,
4412                    -- QP_PRICE_LIST_LINES_V c,
4413                    MTL_SYSTEM_ITEMS_KFV  d,
4414                    CSD_REPAIR_TYPES_SAR  e,
4415                    CS_TXN_BILLING_TYPES  f,
4416                    JTF_TASK_TEMPLATES_VL g
4417              WHERE ROSC.repair_line_id = p_repair_line_id
4418                AND ROSC.applicable_flag = 'Y'
4419                   -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
4420                AND ROSC.applied_to_est_flag = 'N'
4421                AND WRK.Service_code_id = ROSC.Service_code_id
4422                AND WRK.work_entity_type_code = 'TASK'
4423                AND SC.Service_code_Id = ROSC.Service_code_id
4424                AND NVL(SC.active_from, SYSDATE) <= SYSDATE
4425                AND NVL(SC.active_to, SYSDATE) >= SYSDATE
4426                AND g.task_group_id = WRK.work_entity_id1
4427                AND b.task_template_id = g.task_template_id
4428                AND b.planned_effort IS NOT NULL
4429                AND b.planned_effort_uom IS NOT NULL
4430                   -- Following lines commented by vkjain, bugfix 3468680
4431                   -- and c.price_list_id(+) = p_price_list_id
4432                   -- and c.inventory_item_id(+) = p_labor_inventory_item_id
4433                   -- and c.unit_code(+) = b.planned_effort_uom
4434                   -- and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4435                   -- and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4436                AND d.inventory_item_id = p_labor_inventory_item_id
4437                AND d.organization_id = p_organization_id
4438                AND e.repair_type_id = p_repair_type_id
4439                AND f.txn_billing_type_id = e.txn_billing_type_id(+)
4440                AND f.billing_type = d.material_billable_flag(+)
4441                AND d.material_billable_flag IS NOT NULL;
4442 
4443         -- Cursor gets:
4444         -- Information to create material lines from task groups attached to
4445         -- solutions linked to the repair line id.
4446         CURSOR c_material_lines_from_sol(p_repair_line_id NUMBER,
4447         -- p_price_list_id  NUMBER, bug 3468680, vkjain
4448         p_inventory_item_id NUMBER, p_organization_id NUMBER, p_repair_type_id NUMBER) IS
4449             SELECT b.inventory_item_id,
4450                    b.primary_uom_code uom,
4451                    b.manual_quantity manual_qty,
4452                    CEIL(b.rollup_quantity_used / b.rollup_times_used) rollup_qty,
4453                    a.actual_times_used times_used,
4454                    -- c.list_price selling_price,
4455                    d.concatenated_segments item_name,
4456                    d.comms_nl_trackable_flag,
4457                    f.txn_billing_type_id,
4458                    'SOLUTION' est_line_source_type_code,
4459                    SetLinkRO.set_id est_line_source_id1,
4460                    NULL est_line_source_id2,
4461                    NULL ro_service_code_id
4462               FROM cs_kb_set_links         SetLinkTG, --link to task group
4463                    cs_kb_set_links         SetLinkRO, -- link to repair order
4464                    cs_kb_sets_vl           KBSets,
4465                    jtf_task_temp_groups_vl JtfTaskTempGroupEO,
4466                    csp_product_tasks       a,
4467                    csp_task_parts          b,
4468                    -- qp_price_list_lines_v c,
4469                    mtl_system_items_kfv  d,
4470                    CSD_REPAIR_TYPES_SAR  e,
4471                    cs_txn_billing_types  f,
4472                    jtf_task_templates_vl g
4473              WHERE g.task_group_id =
4474                    JtfTaskTempGroupEO.task_template_group_id
4475                AND a.task_template_id = g.task_template_id
4476                AND a.product_id = p_inventory_item_id
4477                AND b.product_task_id = a.product_task_id
4478                AND (b.manual_quantity IS NOT NULL OR
4479                    b.rollup_quantity_used IS NOT NULL)
4480                AND b.substitute_item IS NULL
4481                   -- Following lines commented by vkjain, bugfix 3468680
4482                   -- and c.price_list_id(+) = p_price_list_id
4483                   -- and c.inventory_item_id(+) = b.inventory_item_id
4484                   -- and c.unit_code(+) = b.primary_uom_code
4485                   -- and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4486                   -- and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4487                AND d.inventory_item_id = b.inventory_item_id
4488                AND d.material_billable_flag IS NOT NULL
4489                AND d.organization_id = p_organization_id
4490                AND e.repair_type_id = p_repair_type_id
4491                AND f.txn_billing_type_id = e.txn_billing_type_id(+)
4492                AND f.billing_type = d.material_billable_flag(+)
4493                AND SetLinkRO.other_id = p_repair_line_id
4494                AND SetLinkRO.object_code = 'DR'
4495                AND SetLinkRO.link_type = 'S'
4496                AND SetLinkTG.set_id = SetLinkRO.set_id
4497                AND SetLinkTG.other_id =
4498                    JtfTaskTempGroupEO.task_template_group_id
4499                AND SetLinkTG.object_code = 'CS_KB_TASK_TEMPLATE_GRP'
4500                AND JtfTaskTempGroupEO.application_id = 512 -- depot repair task groups only
4501                AND KBSets.set_id = SetLinkTG.set_id
4502                AND KBSets.status = 'PUB' -- only published solutions
4503                AND NOT EXISTS -- not already brought in
4504              (SELECT 'x'
4505                       FROM csd_repair_estimate_lines_v csd
4506                      WHERE csd.repair_line_id = SetLinkRO.other_id
4507                        AND csd.est_line_source_type_code = 'SOLUTION'
4508                        AND csd.est_line_source_id1 = KBSets.set_id);
4509 
4510         -- Cursor gets:
4511         -- Information to create labor lines from task groups attached to
4512         -- solutions linked to the repair line id.
4513         CURSOR c_labor_lines_from_sol(p_repair_line_id NUMBER,
4514         -- p_price_list_id  NUMBER, bug 3468680, vkjain
4515         p_labor_inventory_item_id NUMBER, p_organization_id NUMBER, p_repair_type_id NUMBER) IS
4516             SELECT p_labor_inventory_item_id inventory_item_id,
4517                    b.planned_effort_uom      uom,
4518                    b.planned_effort          quantity,
4519                    -- c.list_price selling_price,
4520                    d.concatenated_segments item_name,
4521                    d.comms_nl_trackable_flag,
4522                    f.txn_billing_type_id,
4523                    'SOLUTION' est_line_source_type_code,
4524                    SetLinkRO.set_id est_line_source_id1,
4525                    NULL est_line_source_id2,
4526                    NULL ro_service_code_id
4527               FROM cs_kb_set_links         SetLinkTG, --link to task group
4528                    cs_kb_set_links         SetLinkRO, -- link to repair order
4529                    cs_kb_sets_vl           KBSets,
4530                    jtf_task_temp_groups_vl JtfTaskTempGroupEO,
4531                    jtf_task_templates_b    b,
4532                    -- qp_price_list_lines_v c,
4533                    mtl_system_items_kfv  d,
4534                    CSD_REPAIR_TYPES_SAR  e,
4535                    cs_txn_billing_types  f,
4536                    jtf_task_templates_vl g
4537              WHERE SetLinkRO.other_id = p_repair_line_id
4538                AND SetLinkRO.object_code = 'DR'
4539                AND SetLinkRO.link_type = 'S'
4540                AND SetLinkTG.set_id = SetLinkRO.set_id
4541                AND SetLinkTG.other_id =
4542                    JtfTaskTempGroupEO.task_template_group_id
4543                AND SetLinkTG.object_code = 'CS_KB_TASK_TEMPLATE_GRP'
4544                AND g.task_group_id =
4545                    JtfTaskTempGroupEO.task_template_group_id
4546                AND b.task_template_id = g.task_template_id
4547                AND b.planned_effort IS NOT NULL
4548                AND b.planned_effort_uom IS NOT NULL
4549                   -- Following lines commented by vkjain, bugfix 3468680
4550                   -- and c.price_list_id(+) = p_price_list_id
4551                   -- and c.inventory_item_id(+) = p_labor_inventory_item_id
4552                   -- and c.unit_code(+) = b.planned_effort_uom
4553                   -- and nvl(c.start_date_active, SYSDATE) <= SYSDATE  -- swai added
4554                   -- and nvl(c.end_date_active, SYSDATE) >= SYSDATE    -- swai added
4555                AND d.inventory_item_id = p_labor_inventory_item_id
4556                AND d.organization_id = p_organization_id
4557                AND e.repair_type_id = p_repair_type_id
4558                AND f.txn_billing_type_id = e.txn_billing_type_id(+)
4559                AND f.billing_type = d.material_billable_flag(+)
4560                AND d.material_billable_flag IS NOT NULL
4561                AND JtfTaskTempGroupEO.application_id = 512 -- depot repair task groups only
4562                AND KBSets.set_id = SetLinkTG.set_id
4563                AND KBSets.status = 'PUB' -- only published solutions
4564                AND NOT EXISTS -- not already brought in
4565              (SELECT 'x'
4566                       FROM csd_repair_estimate_lines_v csd
4567                      WHERE csd.repair_line_id = SetLinkRO.other_id
4568                        AND csd.est_line_source_type_code = 'SOLUTION'
4569                        AND csd.est_line_source_id1 = KBSets.set_id);
4570 
4571         -- Cursor gets:
4572         -- Tasks template groups associated with solutions for a repair line
4573         -- where the task template groups do not have any task templates
4574         -- defined for the repair line's product
4575         CURSOR c_sol_tasks_no_prod(p_repair_line_id NUMBER) IS
4576             SELECT KBSets.set_id                             solution_id, -- solution id
4577                    JtfTaskTempGroupEO.task_template_group_id task_group_id, -- task template group id
4578                    JtfTaskTempGroupEO.template_group_name    task_group_name -- task template group name
4579               FROM cs_kb_set_links         SetLinkTG, --link to task group
4580                    cs_kb_set_links         SetLinkRO, -- link to repair order
4581                    cs_kb_sets_vl           KBSets,
4582                    jtf_task_temp_groups_vl JtfTaskTempGroupEO,
4583                    CSD_REPAIRS             repairs
4584              WHERE SetLinkRO.other_id = p_repair_line_id
4585                AND SetLinkRO.object_code = 'DR'
4586                AND SetLinkRO.link_type = 'S'
4587                AND SetLinkTG.set_id = SetLinkRO.set_id
4588                AND SetLinkTG.other_id =
4589                    JtfTaskTempGroupEO.task_template_group_id
4590                AND SetLinkTG.object_code = 'CS_KB_TASK_TEMPLATE_GRP'
4591                AND JtfTaskTempGroupEO.application_id = 512 -- depot repair task groups only
4592                AND KBSets.set_id = SetLinkTG.set_id
4593                AND KBSets.status = 'PUB' -- only published solutions
4594                AND repairs.repair_line_id = SetLinkRO.other_id
4595                AND NOT EXISTS -- not already brought in
4596              (SELECT 'x'
4597                       FROM csd_repair_estimate_lines_v csd
4598                      WHERE csd.repair_line_id = SetLinkRO.other_id
4599                        AND csd.est_line_source_type_code = 'SOLUTION'
4600                        AND csd.est_line_source_id1 = KBSets.set_id)
4601                AND NOT EXISTS -- no template for this product
4602              (SELECT 'x'
4603                       FROM csp_product_tasks       x,
4604                            jtf_task_templates_vl   y,
4605                            jtf_task_temp_groups_vl z
4606                      WHERE x.product_id = repairs.inventory_item_id
4607                        AND x.task_template_id = y.task_template_id
4608                        AND y.task_group_id = SetLinkTG.other_id);
4609 
4610     BEGIN
4611         -- Standard Start of API savepoint
4612         SAVEPOINT Get_Estimates_From_Task;
4613 
4614         -- Standard call to check for call compatibility.
4615         IF NOT Fnd_Api.Compatible_API_Call(lc_api_version,
4616                                            p_api_version,
4617                                            lc_api_name,
4618                                            G_PKG_NAME)
4619         THEN
4620             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
4621         END IF;
4622 
4623         -- Initialize message list if p_init_msg_list is set to TRUE.
4624         IF Fnd_Api.to_Boolean(p_init_msg_list)
4625         THEN
4626             Fnd_Msg_Pub.initialize;
4627         END IF;
4628 
4629         -- Initialize API return status to success
4630         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
4631 
4632         -- initialize the warning flag
4633         x_warning_flag := Fnd_Api.G_FALSE;
4634 
4635         --
4636         -- Begin API Body
4637         --
4638         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
4639         THEN
4640             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4641                            lc_mod_name || '.BEGIN',
4642                            'Entering CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_Task');
4643         END IF;
4644         -- log parameters
4645         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
4646         THEN
4647             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4648                            lc_mod_name || '.parameter_logging',
4649                            'p_api_version: ' || p_api_version);
4650             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4651                            lc_mod_name || '.parameter_logging',
4652                            'p_commit: ' || p_commit);
4653             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4654                            lc_mod_name || '.parameter_logging',
4655                            'p_init_msg_list: ' || p_init_msg_list);
4656             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4657                            lc_mod_name || '.parameter_logging',
4658                            'p_validation_level: ' || p_validation_level);
4659             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4660                            lc_mod_name || '.parameter_logging',
4661                            'p_repair_line_id: ' || p_repair_line_id);
4662             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4663                            lc_mod_name || '.parameter_logging',
4664                            'p_estimate_id: ' || p_estimate_id);
4665             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4666                            lc_mod_name || '.parameter_logging',
4667                            'p_repair_type_id: ' || p_repair_type_id);
4668             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4669                            lc_mod_name || '.parameter_logging',
4670                            'p_business_process_id: ' ||
4671                            p_business_process_id);
4672             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4673                            lc_mod_name || '.parameter_logging',
4674                            'p_currency_code: ' || p_currency_code);
4675             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4676                            lc_mod_name || '.parameter_logging',
4677                            'p_incident_id: ' || p_incident_id);
4678             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4679                            lc_mod_name || '.parameter_logging',
4680                            'p_repair_mode: ' || p_repair_mode);
4681             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4682                            lc_mod_name || '.parameter_logging',
4683                            'p_inventory_item_id: ' || p_inventory_item_id);
4684             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4685                            lc_mod_name || '.parameter_logging',
4686                            'p_organization_id: ' || p_organization_id);
4687             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4688                            lc_mod_name || '.parameter_logging',
4689                            'p_price_list_id: ' || p_price_list_id);
4690             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4691                            lc_mod_name || '.parameter_logging',
4692                            'p_contract_line_id: ' || p_contract_line_id);
4693         END IF;
4694 
4695         -- get labor inventory item from profile option
4696         l_labor_inventory_item_id := Fnd_Profile.value('CSD_DEFAULT_EST_LABOR');
4697 
4698         -- get use tasks from solution profile option
4699         l_use_tasks_from_sol := NVL(Fnd_Profile.value('CSD_USE_TASK_FROM_SOLN'),
4700                                     'N');
4701 
4702         -- get threshold for tasks - to be used when determining manual vs rollup qty
4703         l_task_threshold := TO_NUMBER(NVL(Fnd_Profile.value('CSP_PROD_TASK_HIST_RULE'),
4704                                           '0'));
4705 
4706         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
4707         THEN
4708             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4709                            lc_mod_name,
4710                            'l_labor_inventory_item_id = ' ||
4711                            l_labor_inventory_item_id);
4712             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4713                            lc_mod_name,
4714                            'l_use_tasks_from_sol = ' ||
4715                            l_use_tasks_from_sol);
4716             Fnd_Log.STRING(Fnd_Log.Level_Statement,
4717                            lc_mod_name,
4718                            'l_task_threshold = ' || l_task_threshold);
4719         END IF;
4720 
4721         --
4722         -- (1) Material lines from Service Codes
4723         --
4724         DECLARE
4725             l_count NUMBER := 0;
4726         BEGIN
4727             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
4728             THEN
4729                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4730                                lc_mod_name,
4731                                'Getting task material lines from service codes');
4732             END IF;
4733             -- bugfix 3468680, vkjain
4734             -- FOR r1 in c_material_lines_from_sc (p_repair_line_id, p_price_list_id)
4735             FOR r1 IN c_material_lines_from_sc(p_repair_line_id)
4736             LOOP
4737                 IF (r1.manual_qty IS NOT NULL) OR
4738                    (l_task_threshold <= r1.times_used)
4739                 THEN
4740                     l_count := l_count + 1;
4741                     IF (r1.manual_qty IS NOT NULL)
4742                     THEN
4743                         l_materials_from_sc_tbl(l_count).quantity := r1.manual_qty;
4744                     ELSE
4745                         -- if (l_task_threshold <= r1.times_used)
4746                         l_materials_from_sc_tbl(l_count).quantity := r1.rollup_qty;
4747                     END IF;
4748                     l_materials_from_sc_tbl(l_count).inventory_item_id := r1.inventory_item_id;
4749                     l_materials_from_sc_tbl(l_count).uom := r1.uom;
4750                     -- Bugfix 3468680, vkjain
4751                     -- l_materials_from_sc_tbl(l_count).selling_price := r1.selling_price;
4752                     l_materials_from_sc_tbl(l_count).item_name := r1.item_name;
4753                     l_materials_from_sc_tbl(l_count).comms_nl_trackable_flag := r1.comms_nl_trackable_flag;
4754                     l_materials_from_sc_tbl(l_count).txn_billing_type_id := r1.txn_billing_type_id;
4755                     l_materials_from_sc_tbl(l_count).est_line_source_type_code := r1.est_line_source_type_code;
4756                     l_materials_from_sc_tbl(l_count).est_line_source_id1 := r1.est_line_source_id1;
4757                     l_materials_from_sc_tbl(l_count).est_line_source_id2 := r1.est_line_source_id2;
4758                     l_materials_from_sc_tbl(l_count).ro_service_code_id := r1.ro_service_code_id;
4759                 END IF;
4760             END LOOP;
4761         END;
4762 
4763         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
4764         THEN
4765             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4766                            lc_mod_name,
4767                            'material line count = ' ||
4768                            l_materials_from_sc_tbl.COUNT);
4769         END IF;
4770         IF (l_materials_from_sc_tbl.COUNT > 0)
4771         THEN
4772             -- bugfix 3543135, vkjain.
4773             l_No_Eligible_Lines := FALSE;
4774 
4775             Convert_To_Est_Lines(p_api_version         => 1.0,
4776                                  p_commit              => Fnd_Api.G_FALSE,
4777                                  p_init_msg_list       => Fnd_Api.G_FALSE,
4778                                  p_validation_level    => p_validation_level,
4779                                  x_return_status       => x_return_status,
4780                                  x_msg_count           => x_msg_count,
4781                                  x_msg_data            => x_msg_data,
4782                                  p_repair_line_id      => p_repair_line_id,
4783                                  p_estimate_id         => p_estimate_id,
4784                                  p_repair_type_id      => p_repair_type_id,
4785                                  p_business_process_id => p_business_process_id,
4786                                  p_currency_code       => p_currency_code,
4787                                  p_incident_id         => p_incident_id,
4788                                  p_organization_id     => p_organization_id,
4789                                  p_price_list_id       => p_price_list_id,
4790                                  p_contract_line_id    => p_contract_line_id,
4791                                  p_MLE_lines_tbl       => l_materials_from_sc_tbl,
4792                                  x_est_lines_tbl       => x_est_lines_tbl,
4793                                  x_warning_flag        => l_warning_flag);
4794             IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4795             THEN
4796                 x_warning_flag := Fnd_Api.G_TRUE;
4797             END IF;
4798             IF l_warning_flag <> Fnd_Api.G_FALSE
4799             THEN
4800                 x_warning_flag := l_warning_flag;
4801             END IF;
4802         END IF;
4803 
4804         --
4805         -- (2) Labor lines from Service Codes
4806         --
4807         IF (l_labor_inventory_item_id IS NOT NULL)
4808         THEN
4809             DECLARE
4810                 l_count NUMBER := 0;
4811             BEGIN
4812                 IF (Fnd_Log.Level_Procedure >=
4813                    Fnd_Log.G_Current_Runtime_Level)
4814                 THEN
4815                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4816                                    lc_mod_name,
4817                                    'Getting task labor lines from service codes');
4818                 END IF;
4819                 -- bugfix 3468680, vkjain
4820                 -- FOR r1 in c_labor_lines_from_sc (p_repair_line_id, p_price_list_id, l_labor_inventory_item_id)
4821                 FOR r1 IN c_labor_lines_from_sc(p_repair_line_id,
4822                                                 l_labor_inventory_item_id)
4823                 LOOP
4824                     l_count := l_count + 1;
4825                     l_labor_from_sc_tbl(l_count).inventory_item_id := r1.inventory_item_id;
4826                     l_labor_from_sc_tbl(l_count).uom := r1.uom;
4827                     l_labor_from_sc_tbl(l_count).quantity := r1.quantity;
4828                     -- Bugfix 3468680, vkjain
4829                     -- l_labor_from_sc_tbl(l_count).selling_price := r1.selling_price;
4830                     l_labor_from_sc_tbl(l_count).item_name := r1.item_name;
4831                     l_labor_from_sc_tbl(l_count).comms_nl_trackable_flag := r1.comms_nl_trackable_flag;
4832                     l_labor_from_sc_tbl(l_count).txn_billing_type_id := r1.txn_billing_type_id;
4833                     l_labor_from_sc_tbl(l_count).est_line_source_type_code := r1.est_line_source_type_code;
4834                     l_labor_from_sc_tbl(l_count).est_line_source_id1 := r1.est_line_source_id1;
4835                     l_labor_from_sc_tbl(l_count).est_line_source_id2 := r1.est_line_source_id2;
4836                     l_labor_from_sc_tbl(l_count).ro_service_code_id := r1.ro_service_code_id;
4837                 END LOOP;
4838             END;
4839 
4840             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
4841             THEN
4842                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4843                                lc_mod_name,
4844                                'labor line count = ' ||
4845                                l_labor_from_sc_tbl.COUNT);
4846             END IF;
4847             IF (l_labor_from_sc_tbl.COUNT > 0)
4848             THEN
4849                 -- bugfix 3543135, vkjain.
4850                 l_No_Eligible_Lines := FALSE;
4851 
4852                 Convert_To_Est_Lines(p_api_version         => 1.0,
4853                                      p_commit              => Fnd_Api.G_FALSE,
4854                                      p_init_msg_list       => Fnd_Api.G_FALSE,
4855                                      p_validation_level    => p_validation_level,
4856                                      x_return_status       => x_return_status,
4857                                      x_msg_count           => x_msg_count,
4858                                      x_msg_data            => x_msg_data,
4859                                      p_repair_line_id      => p_repair_line_id,
4860                                      p_estimate_id         => p_estimate_id,
4861                                      p_repair_type_id      => p_repair_type_id,
4862                                      p_business_process_id => p_business_process_id,
4863                                      p_currency_code       => p_currency_code,
4864                                      p_incident_id         => p_incident_id,
4865                                      p_organization_id     => p_organization_id,
4866                                      p_price_list_id       => p_price_list_id,
4867                                      p_contract_line_id    => p_contract_line_id,
4868                                      p_MLE_lines_tbl       => l_labor_from_sc_tbl,
4869                                      x_est_lines_tbl       => x_est_lines_tbl,
4870                                      x_warning_flag        => l_warning_flag);
4871                 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4872                 THEN
4873                     x_warning_flag := Fnd_Api.G_TRUE;
4874                 END IF;
4875                 IF l_warning_flag <> Fnd_Api.G_FALSE
4876                 THEN
4877                     x_warning_flag := l_warning_flag;
4878                 END IF;
4879             END IF;
4880         END IF;
4881 
4882         --
4883         -- Use tasks associated with solutions
4884         --
4885         IF (l_use_tasks_from_sol = 'Y')
4886         THEN
4887             --
4888             -- Before getting any material lines from Solutions, check to
4889             -- see if there are any task groups with no task templates for the
4890             -- repair line's product.  Log a warning for each task group.
4891             --
4892             DECLARE
4893                 l_return_status VARCHAR2(1);
4894                 l_msg_count     NUMBER;
4895                 l_msg_data      VARCHAR2(2000);
4896             BEGIN
4897                 IF (Fnd_Log.Level_Procedure >=
4898                    Fnd_Log.G_Current_Runtime_Level)
4899                 THEN
4900                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4901                                    lc_mod_name,
4902                                    'Getting all solution tasks with no product template');
4903                 END IF;
4904                 FOR r1 IN c_sol_tasks_no_prod(p_repair_line_id)
4905                 LOOP
4906                     x_warning_flag := Fnd_Api.G_TRUE;
4907                     IF (Fnd_Log.Level_Statement >=
4908                        Fnd_Log.G_Current_Runtime_Level)
4909                     THEN
4910                         Fnd_Log.STRING(Fnd_Log.Level_Statement,
4911                                        lc_mod_name,
4912                                        'Adding message CSD_EST_SOL_TASK_NO_PROD to FND_MSG stack');
4913                         Fnd_Log.STRING(Fnd_Log.Level_Statement,
4914                                        lc_mod_name,
4915                                        'no task template for task group id ' ||
4916                                        r1.task_group_id);
4917                     END IF;
4918                     Fnd_Message.SET_NAME('CSD', 'CSD_EST_SOL_TASK_NO_PROD');
4919                     Fnd_Message.SET_TOKEN('GROUP_ID', r1.task_group_id);
4920                     Fnd_Message.SET_TOKEN('GROUP_NAME', r1.task_group_name);
4921                     Fnd_Msg_Pub.ADD;
4922                     IF (Fnd_Log.Level_Procedure >=
4923                        Fnd_Log.G_Current_Runtime_Level)
4924                     THEN
4925                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4926                                        lc_mod_name,
4927                                        'Calling CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
4928                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4929                                        lc_mod_name,
4930                                        'Number of messages in stack: ' ||
4931                                        Fnd_Msg_Pub.count_msg);
4932                     END IF;
4933                     Csd_Gen_Errmsgs_Pvt.Save_Fnd_Msgs(p_api_version             => 1.0,
4934                                                       p_commit                  => Fnd_Api.G_FALSE,
4935                                                       p_init_msg_list           => Fnd_Api.G_FALSE,
4936                                                       p_validation_level        => 0,
4937                                                       p_module_code             => 'EST',
4938                                                       p_source_entity_id1       => p_repair_line_id,
4939                                                       p_source_entity_type_code => 'SOLUTION',
4940                                                       p_source_entity_id2       => r1.solution_id,
4941                                                       x_return_status           => l_return_status,
4942                                                       x_msg_count               => l_msg_count,
4943                                                       x_msg_data                => l_msg_data);
4944                     IF NOT (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
4945                     THEN
4946                         RAISE Fnd_Api.G_EXC_ERROR;
4947                     END IF;
4948                     IF (Fnd_Log.Level_Procedure >=
4949                        Fnd_Log.G_Current_Runtime_Level)
4950                     THEN
4951                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4952                                        lc_mod_name,
4953                                        'Returned from CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
4954                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4955                                        lc_mod_name,
4956                                        'Number of messages in stack: ' ||
4957                                        Fnd_Msg_Pub.count_msg);
4958                     END IF;
4959                 END LOOP;
4960             END;
4961 
4962             --
4963             -- (3) Material lines from Solutions
4964             --
4965             DECLARE
4966                 l_count NUMBER := 0;
4967             BEGIN
4968                 IF (Fnd_Log.Level_Procedure >=
4969                    Fnd_Log.G_Current_Runtime_Level)
4970                 THEN
4971                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
4972                                    lc_mod_name,
4973                                    'Getting task material lines from solutions');
4974                 END IF;
4975                 FOR r1 IN c_material_lines_from_sol(p_repair_line_id,
4976                                                     -- p_price_list_id, bugfix 3468680, vkjain
4977                                                     p_inventory_item_id,
4978                                                     p_organization_id,
4979                                                     p_repair_type_id)
4980                 LOOP
4981                     IF (r1.manual_qty IS NOT NULL) OR
4982                        (l_task_threshold <= r1.times_used)
4983                     THEN
4984                         l_count := l_count + 1;
4985                         IF (r1.manual_qty IS NOT NULL)
4986                         THEN
4987                             l_materials_from_sol_tbl(l_count).quantity := r1.manual_qty;
4988                         ELSE
4989                             -- if (l_task_threshold <= r1.times_used)
4990                             l_materials_from_sol_tbl(l_count).quantity := r1.rollup_qty;
4991                         END IF;
4992                         l_materials_from_sol_tbl(l_count).inventory_item_id := r1.inventory_item_id;
4993                         l_materials_from_sol_tbl(l_count).uom := r1.uom;
4994                         -- Bugfix 3468680, vkjain
4995                         -- l_materials_from_sol_tbl(l_count).selling_price := r1.selling_price;
4996                         l_materials_from_sol_tbl(l_count).item_name := r1.item_name;
4997                         l_materials_from_sol_tbl(l_count).comms_nl_trackable_flag := r1.comms_nl_trackable_flag;
4998                         l_materials_from_sol_tbl(l_count).txn_billing_type_id := r1.txn_billing_type_id;
4999                         l_materials_from_sol_tbl(l_count).est_line_source_type_code := r1.est_line_source_type_code;
5000                         l_materials_from_sol_tbl(l_count).est_line_source_id1 := r1.est_line_source_id1;
5001                         l_materials_from_sol_tbl(l_count).est_line_source_id2 := r1.est_line_source_id2;
5002                         l_materials_from_sol_tbl(l_count).ro_service_code_id := r1.ro_service_code_id;
5003                     END IF;
5004                 END LOOP;
5005             END;
5006 
5007             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5008             THEN
5009                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5010                                lc_mod_name,
5011                                'material line count = ' ||
5012                                l_materials_from_sol_tbl.COUNT);
5013             END IF;
5014             IF (l_materials_from_sol_tbl.COUNT > 0)
5015             THEN
5016                 -- bugfix 3543135, vkjain.
5017                 l_No_Eligible_Lines := FALSE;
5018 
5019                 Convert_To_Est_Lines(p_api_version         => 1.0,
5020                                      p_commit              => Fnd_Api.G_FALSE,
5021                                      p_init_msg_list       => Fnd_Api.G_FALSE,
5022                                      p_validation_level    => p_validation_level,
5023                                      x_return_status       => x_return_status,
5024                                      x_msg_count           => x_msg_count,
5025                                      x_msg_data            => x_msg_data,
5026                                      p_repair_line_id      => p_repair_line_id,
5027                                      p_estimate_id         => p_estimate_id,
5028                                      p_repair_type_id      => p_repair_type_id,
5029                                      p_business_process_id => p_business_process_id,
5030                                      p_currency_code       => p_currency_code,
5031                                      p_incident_id         => p_incident_id,
5032                                      p_organization_id     => p_organization_id,
5033                                      p_price_list_id       => p_price_list_id,
5034                                      p_contract_line_id    => p_contract_line_id,
5035                                      p_MLE_lines_tbl       => l_materials_from_sol_tbl,
5036                                      x_est_lines_tbl       => x_est_lines_tbl,
5037                                      x_warning_flag        => l_warning_flag);
5038                 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5039                 THEN
5040                     x_warning_flag := Fnd_Api.G_TRUE;
5041                 END IF;
5042                 IF l_warning_flag <> Fnd_Api.G_FALSE
5043                 THEN
5044                     x_warning_flag := l_warning_flag;
5045                 END IF;
5046             END IF;
5047         END IF;
5048 
5049         --
5050         -- (4) Labor lines from Solutions
5051         --
5052         IF (l_use_tasks_from_sol = 'Y') AND
5053            (l_labor_inventory_item_id IS NOT NULL)
5054         THEN
5055             DECLARE
5056                 l_count NUMBER := 0;
5057             BEGIN
5058                 IF (Fnd_Log.Level_Procedure >=
5059                    Fnd_Log.G_Current_Runtime_Level)
5060                 THEN
5061                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5062                                    lc_mod_name,
5063                                    'Getting task labor lines from solutions');
5064                 END IF;
5065                 FOR r1 IN c_labor_lines_from_sol(p_repair_line_id,
5066                                                  -- p_price_list_id, bugfix 3468680, vkjain
5067                                                  l_labor_inventory_item_id,
5068                                                  p_organization_id,
5069                                                  p_repair_type_id)
5070                 LOOP
5071                     l_count := l_count + 1;
5072                     l_labor_from_sol_tbl(l_count).inventory_item_id := r1.inventory_item_id;
5073                     l_labor_from_sol_tbl(l_count).uom := r1.uom;
5074                     l_labor_from_sol_tbl(l_count).quantity := r1.quantity;
5075                     -- Bugfix 3468680, vkjain
5076                     -- l_labor_from_sol_tbl(l_count).selling_price := r1.selling_price;
5077                     l_labor_from_sol_tbl(l_count).item_name := r1.item_name;
5078                     l_labor_from_sol_tbl(l_count).comms_nl_trackable_flag := r1.comms_nl_trackable_flag;
5079                     l_labor_from_sol_tbl(l_count).txn_billing_type_id := r1.txn_billing_type_id;
5080                     l_labor_from_sol_tbl(l_count).est_line_source_type_code := r1.est_line_source_type_code;
5081                     l_labor_from_sol_tbl(l_count).est_line_source_id1 := r1.est_line_source_id1;
5082                     l_labor_from_sol_tbl(l_count).est_line_source_id2 := r1.est_line_source_id2;
5083                     l_labor_from_sol_tbl(l_count).ro_service_code_id := r1.ro_service_code_id;
5084                 END LOOP;
5085             END;
5086 
5087             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5088             THEN
5089                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5090                                lc_mod_name,
5091                                'labor line count = ' ||
5092                                l_labor_from_sol_tbl.COUNT);
5093                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5094                                lc_mod_name,
5095                                'Calling Convert_To_Est_Lines');
5096             END IF;
5097             IF (l_labor_from_sol_tbl.COUNT > 0)
5098             THEN
5099                 -- bugfix 3543135, vkjain.
5100                 l_No_Eligible_Lines := FALSE;
5101 
5102                 Convert_To_Est_Lines(p_api_version         => 1.0,
5103                                      p_commit              => Fnd_Api.G_FALSE,
5104                                      p_init_msg_list       => Fnd_Api.G_FALSE,
5105                                      p_validation_level    => p_validation_level,
5106                                      x_return_status       => x_return_status,
5107                                      x_msg_count           => x_msg_count,
5108                                      x_msg_data            => x_msg_data,
5109                                      p_repair_line_id      => p_repair_line_id,
5110                                      p_estimate_id         => p_estimate_id,
5111                                      p_repair_type_id      => p_repair_type_id,
5112                                      p_business_process_id => p_business_process_id,
5113                                      p_currency_code       => p_currency_code,
5114                                      p_incident_id         => p_incident_id,
5115                                      p_organization_id     => p_organization_id,
5116                                      p_price_list_id       => p_price_list_id,
5117                                      p_contract_line_id    => p_contract_line_id,
5118                                      p_MLE_lines_tbl       => l_labor_from_sol_tbl,
5119                                      x_est_lines_tbl       => x_est_lines_tbl,
5120                                      x_warning_flag        => l_warning_flag);
5121                 IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5122                 THEN
5123                     x_warning_flag := Fnd_Api.G_TRUE;
5124                 END IF;
5125                 IF l_warning_flag <> Fnd_Api.G_FALSE
5126                 THEN
5127                     x_warning_flag := l_warning_flag;
5128                 END IF;
5129             END IF;
5130         END IF;
5131 
5132         -- bugfix 3543135, vkjain.
5133         -- IF (x_est_lines_tbl.count <= 0) THEN
5134         IF (l_No_Eligible_Lines)
5135         THEN
5136             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5137             THEN
5138                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5139                                lc_mod_name,
5140                                'no estimate lines available to autogenerate from tasks');
5141             END IF;
5142             RAISE CSD_EST_NO_AUTOGEN;
5143         END IF;
5144 
5145         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
5146         THEN
5147             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5148                            lc_mod_name || '.out_parameter',
5149                            'x_warning_flag: ' || x_warning_flag);
5150         END IF;
5151         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5152         THEN
5153             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5154                            lc_mod_name || '.END',
5155                            'Leaving CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_Task');
5156         END IF;
5157         --
5158         -- End API Body
5159         --
5160 
5161         -- Standard check of p_commit.
5162         IF Fnd_Api.To_Boolean(p_commit)
5163         THEN
5164             COMMIT WORK;
5165         END IF;
5166 
5167         -- Standard call to get message count and IF count is  get message info.
5168         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5169                                   p_data  => x_msg_data);
5170     EXCEPTION
5171         WHEN CSD_EST_NO_AUTOGEN THEN
5172             x_warning_flag := Fnd_Api.G_TRUE;
5173 
5174             -- save message in fnd stack
5175             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
5176             THEN
5177                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
5178                                lc_mod_name,
5179                                'Adding message CSD_EST_NO_AUTOGEN to FND_MSG stack');
5180             END IF;
5181             Fnd_Message.SET_NAME('CSD', 'CSD_EST_NO_AUTOGEN');
5182             Fnd_Msg_Pub.ADD;
5183             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5184                                       p_data  => x_msg_data);
5185 
5186             -- save message in debug log
5187             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5188             THEN
5189                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5190                                lc_mod_name,
5191                                'No estimate lines autogenerated');
5192             END IF;
5193 
5194         WHEN Fnd_Api.G_EXC_ERROR THEN
5195             ROLLBACK TO Get_Estimates_From_Task;
5196             x_return_status := Fnd_Api.G_RET_STS_ERROR;
5197 
5198             /*
5199             -- TO DO: Add seeded err message
5200             -- save message in fnd stack
5201             if (Fnd_Log.Level_Statement>= Fnd_Log.G_Current_Runtime_Level) then
5202                 FND_LOG.STRING(Fnd_Log.Level_Statement, lc_mod_name,
5203                                'Adding message ERR_NAME to FND_MSG stack');
5204             end if;
5205             FND_MESSAGE.SET_NAME('CSD','err_name');
5206             FND_MESSAGE.SET_TOKEN('toke_name', 'token_value');
5207             FND_MSG_PUB.ADD;
5208             */
5209             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5210                                       p_data  => x_msg_data);
5211 
5212             -- save message in debug log
5213             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5214             THEN
5215                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5216                                lc_mod_name,
5217                                'EXC_ERROR[' || x_msg_data || ']');
5218             END IF;
5219 
5220         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5221             ROLLBACK TO Get_Estimates_From_Task;
5222             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5223 
5224             -- save message in fnd stack
5225             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5226             THEN
5227                 IF (Fnd_Log.Level_Statement >=
5228                    Fnd_Log.G_Current_Runtime_Level)
5229                 THEN
5230                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
5231                                    lc_mod_name,
5232                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
5233                 END IF;
5234                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
5235             END IF;
5236             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5237                                       p_data  => x_msg_data);
5238 
5239             -- save message in debug log
5240             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5241             THEN
5242                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5243                                lc_mod_name,
5244                                'EXC_UNEXPECTED_ERROR[' || x_msg_data || ']');
5245             END IF;
5246 
5247         WHEN OTHERS THEN
5248             ROLLBACK TO Get_Estimates_From_Task;
5249             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5250 
5251             -- save message in fnd stack
5252             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5253             THEN
5254                 IF (Fnd_Log.Level_Statement >=
5255                    Fnd_Log.G_Current_Runtime_Level)
5256                 THEN
5257                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
5258                                    lc_mod_name,
5259                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
5260                 END IF;
5261                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
5262             END IF;
5263             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5264                                       p_data  => x_msg_data);
5265 
5266             -- save message in debug log
5267             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5268             THEN
5269                 -- create a seeded message
5270                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5271                                lc_mod_name,
5272                                'SQL Message[' || SQLERRM || ']');
5273             END IF;
5274     END Get_Estimates_From_Task;
5275 
5276     /*--------------------------------------------------*/
5277     /* procedure name: Get_Estimates_From_BOM           */
5278     /* description   : Fetches ML lines for the         */
5279     /*                 BOM/Route references associated  */
5280     /*                 via Service Codes.               */
5281     /*                                                  */
5282     /* x_warning_flag : FND_API.G_TRUE if any non-fatal */
5283     /*                  errors occured. FND_API.G_FALSE */
5284     /*                  if everything was successful.   */
5285     /*                  Note that this value could be   */
5286     /*                  G_TRUE even if x_return_status  */
5287     /*                  is G_RET_STS_SUCCESS            */
5288     /* called from:  Autocreate_Estimate_Lines          */
5289     /*--------------------------------------------------*/
5290     PROCEDURE Get_Estimates_From_BOM(p_api_version         IN NUMBER,
5291                                      p_commit              IN VARCHAR2,
5292                                      p_init_msg_list       IN VARCHAR2,
5293                                      p_validation_level    IN NUMBER,
5294                                      x_return_status       OUT NOCOPY VARCHAR2,
5295                                      x_msg_count           OUT NOCOPY NUMBER,
5296                                      x_msg_data            OUT NOCOPY VARCHAR2,
5297                                      p_repair_line_id      IN NUMBER,
5298                                      p_estimate_id         IN NUMBER,
5299                                      p_repair_type_id      IN NUMBER,
5300                                      p_business_process_id IN NUMBER,
5301                                      p_currency_code       IN VARCHAR2,
5302                                      p_incident_id         IN NUMBER,
5303                                      p_repair_mode         IN VARCHAR2,
5304                                      p_inventory_item_id   IN NUMBER,
5305                                      p_organization_id     IN NUMBER,
5306                                      p_price_list_id       IN NUMBER,
5307                                      p_contract_line_id    IN NUMBER,
5308                                      x_est_lines_tbl       OUT NOCOPY CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_TBL,
5309                                      x_warning_flag        OUT NOCOPY VARCHAR2) IS
5310 
5311         -- CONSTANTS --
5312         lc_debug_level CONSTANT NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
5313         lc_stat_level  CONSTANT NUMBER := Fnd_Log.LEVEL_STATEMENT;
5314         lc_proc_level  CONSTANT NUMBER := Fnd_Log.LEVEL_PROCEDURE;
5315         lc_event_level CONSTANT NUMBER := Fnd_Log.LEVEL_EVENT;
5316         lc_excep_level CONSTANT NUMBER := Fnd_Log.LEVEL_EXCEPTION;
5317         lc_error_level CONSTANT NUMBER := Fnd_Log.LEVEL_ERROR;
5318         lc_unexp_level CONSTANT NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
5319         lc_mod_name    CONSTANT VARCHAR2(100) := 'csd.plsql.csd_repair_estimate_pvt.get_estimates_from_bom';
5320         lc_api_name    CONSTANT VARCHAR2(30) := 'Get_Estimates_From_BOM';
5321         lc_api_version CONSTANT NUMBER := 1.0;
5322 
5323         -- VARIABLES --
5324         l_material_lines_tbl MLE_LINES_TBL_TYPE;
5325         l_labor_lines_tbl    MLE_LINES_TBL_TYPE;
5326         l_warning_flag       VARCHAR2(1);
5327 
5328         -- bugfix 3543135, vkjain.
5329         l_No_Eligible_Lines BOOLEAN := TRUE;
5330 
5331         -- EXCEPTIONS --
5332         CSD_EST_NO_AUTOGEN EXCEPTION;
5333 
5334         -- CURSORS --
5335 
5336         /* bugfix 3468680. vkjain
5337           The selling price should be derived via API call instead of
5338           selecting from the query.
5339           The cursors are replaced by new ones.
5340           Following changes are made to the existing cursors -
5341           -- Cursors do not accept p_price_list_id as IN parameter anymore.
5342           -- They do not select the list_price from the QP view.
5343           -- The reference to QP view is removed from the FROM part of statements.
5344           -- All joins for the QP view commented in the WHERE clause.
5345           -- The selling price is derived in the Convert_to_est_lines procedure
5346              by calling CSD_PROCESS_UTIL.GET_CHARGE_SELLING_PRICE API.
5347 
5348         cursor c_material_lines_from_bom (p_repair_line_id NUMBER,
5349                                           p_repair_type_id NUMBER,
5350                                           p_price_list_id  NUMBER) is
5351            SELECT BOM.component_item_id       INVENTORY_ITEM_ID,
5352                   BOM.primary_uom_code        UOM,
5353                   BOM.component_quantity      QUANTITY,
5354                   PRICE.list_price            SELLING_PRICE,
5355                   MTL.concatenated_segments   ITEM_NAME,
5356                   MTL.comms_nl_trackable_flag COMMS_NL_TRACKABLE_FLAG,
5357                   SAR.txn_billing_type_id     TXN_BILLING_TYPE_ID,
5358                   'SERVICE_CODE'              EST_LINE_SOURCE_TYPE_CODE,
5359                   ROSC.Service_Code_id        EST_LINE_SOURCE_ID1,
5360                   null                        EST_LINE_SOURCE_ID2,
5361                   ROSC.RO_Service_Code_id     RO_SERVICE_CODE_ID
5362            FROM CSD_RO_SERVICE_CODES       ROSC,
5363                 CSD_SERVICE_CODES_VL       SC,
5364                 CSD_SC_WORK_ENTITIES       WRK,
5365                 BOM_INVENTORY_COMPONENTS_V BOM,
5366                 QP_PRICE_LIST_LINES_V      PRICE,
5367                 MTL_SYSTEM_ITEMS_KFV       MTL,
5368                 CSD_REPAIR_TYPES_SAR       RTSAR,
5369                 CS_TXN_BILLING_TYPES       SAR
5370            WHERE ROSC.repair_line_id = p_repair_line_id
5371                and ROSC.applicable_flag = 'Y'
5372                -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
5373                and ROSC.applied_to_est_flag = 'N'
5374                and WRK.Service_code_id = ROSC.Service_code_id
5375                and WRK.work_entity_type_code = 'BOM'
5376                and SC.Service_code_Id = ROSC.Service_code_id
5377                and nvl(SC.active_from, SYSDATE) <= SYSDATE
5378                and nvl(SC.active_to, SYSDATE) >= SYSDATE
5379                and WRK.work_entity_id3 = cs_std.get_item_valdn_orgzn_id
5380                -- and WRK.work_entity_id1 IS NOT NULL
5381                and BOM.bill_sequence_id = WRK.work_entity_id1
5382                and nvl(BOM.effectivity_date , SYSDATE) <= SYSDATE -- swai bug 3323274
5383                and nvl(BOM.disable_date , SYSDATE) >= SYSDATE     -- swai bug 3323274
5384                and PRICE.price_list_id(+) = p_price_list_id
5385                and PRICE.inventory_item_id(+) = BOM.component_item_id
5386                and PRICE.unit_code(+) = BOM.primary_uom_code
5387                and nvl(PRICE.start_date_active, SYSDATE) <= SYSDATE  -- swai added
5388                and nvl(PRICE.end_date_active, SYSDATE) >= SYSDATE    -- swai added
5389                and MTL.inventory_item_id = BOM.component_item_id
5390                and MTL.organization_id = WRK.work_entity_id3
5391                and RTSAR.repair_type_id = p_repair_type_id
5392                and SAR.txn_billing_type_id = RTSAR.txn_billing_type_id(+)
5393                and SAR.billing_type = MTL.material_billable_flag(+)
5394                and MTL.material_billable_flag IS NOT NULL;
5395 
5396          cursor c_labor_lines_from_bom (p_repair_line_id NUMBER,
5397                                         p_repair_type_id NUMBER,
5398                                         p_price_list_id  NUMBER) is
5399            SELECT
5400                   RES.billable_item_id        INVENTORY_ITEM_ID,
5401                   RES.unit_of_measure         UOM,
5402                   -- OPRES.assigned_units        QUANTITY, -- Replaced by following line to fix 3365436. vkjain.
5403                   OPRES.usage_rate_or_amount  QUANTITY,
5404                   PRICE.list_price            SELLING_PRICE,
5405                   MTL.concatenated_segments   ITEM_NAME,
5406                   MTL.comms_nl_trackable_flag COMMS_NL_TRACKABLE_FLAG,
5407                   SAR.txn_billing_type_id     TXN_BILLING_TYPE_ID,
5408                   'SERVICE_CODE'              EST_LINE_SOURCE_TYPE_CODE,
5409                   ROSC.Service_Code_id        EST_LINE_SOURCE_ID1,
5410                   null                        EST_LINE_SOURCE_ID2,
5411                   ROSC.RO_Service_Code_id     RO_SERVICE_CODE_ID,
5412                 RES.resource_id             RESOURCE_ID -- vkjain. 3449978
5413            FROM CSD_RO_SERVICE_CODES    ROSC,
5414                 CSD_SC_WORK_ENTITIES    WRK,
5415                 CSD_SERVICE_CODES_VL    SC,
5416                 BOM_OPERATION_SEQUENCES OPSEQ,
5417                 BOM_OPERATION_RESOURCES OPRES,
5418                 QP_PRICE_LIST_LINES_V   PRICE,
5419                 MTL_SYSTEM_ITEMS_KFV    MTL,
5420                 CSD_REPAIR_TYPES_SAR    RTSAR,
5421                 CS_TXN_BILLING_TYPES    SAR,
5422                 BOM_RESOURCES           RES
5423            WHERE ROSC.repair_line_id = p_repair_line_id
5424                and ROSC.applicable_flag = 'Y'
5425                -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
5426                and ROSC.applied_to_est_flag = 'N'
5427                and WRK.Service_code_id = ROSC.Service_code_id
5428                and WRK.work_entity_type_code = 'BOM'
5429                and SC.Service_code_Id = ROSC.Service_code_id
5430                and nvl(SC.active_from, SYSDATE) <= SYSDATE
5431                and nvl(SC.active_to, SYSDATE) >= SYSDATE
5432                and WRK.work_entity_id3 = cs_std.get_item_valdn_orgzn_id
5433                -- and WRK.work_entity_id2 IS NOT NULL
5434                and OPSEQ.ROUTING_SEQUENCE_ID = WRK.work_entity_id2
5435                and nvl(OPSEQ.effectivity_date , SYSDATE) <= SYSDATE -- swai bug 3323274
5436                and nvl(OPSEQ.disable_date , SYSDATE) >= SYSDATE     -- swai bug 3323274
5437                and OPRES.OPERATION_SEQUENCE_ID = OPSEQ.OPERATION_SEQUENCE_ID
5438                and RES.RESOURCE_ID = OPRES.RESOURCE_ID
5439                and PRICE.price_list_id(+) = p_price_list_id
5440                and nvl(PRICE.start_date_active, SYSDATE) <= SYSDATE  -- swai added
5441                and nvl(PRICE.end_date_active, SYSDATE) >= SYSDATE    -- swai added
5442                and PRICE.inventory_item_id(+) = RES.billable_item_id
5443                and PRICE.unit_code(+) = RES.unit_of_measure
5444                and MTL.inventory_item_id = RES.billable_item_id
5445                and MTL.organization_id = WRK.work_entity_id3
5446                and MTL.material_billable_flag IS NOT NULL
5447                and RTSAR.repair_type_id = p_repair_type_id
5448                and SAR.txn_billing_type_id = RTSAR.txn_billing_type_id(+)
5449                and SAR.billing_type = MTL.material_billable_flag(+);
5450               */
5451 
5452         CURSOR c_material_lines_from_bom(p_repair_line_id NUMBER, p_repair_type_id NUMBER) IS
5453         -- p_price_list_id  NUMBER) is, bug 3468680, vkjain
5454             SELECT BOM.component_item_id  INVENTORY_ITEM_ID,
5455                    BOM.primary_uom_code   UOM,
5456                    BOM.component_quantity QUANTITY,
5457                    -- PRICE.list_price            SELLING_PRICE,
5458                    MTL.concatenated_segments ITEM_NAME,
5459                    MTL.comms_nl_trackable_flag COMMS_NL_TRACKABLE_FLAG,
5460                    SAR.txn_billing_type_id TXN_BILLING_TYPE_ID,
5461                    'SERVICE_CODE' EST_LINE_SOURCE_TYPE_CODE,
5462                    ROSC.Service_Code_id EST_LINE_SOURCE_ID1,
5463                    NULL EST_LINE_SOURCE_ID2,
5464                    ROSC.RO_Service_Code_id RO_SERVICE_CODE_ID
5465               FROM CSD_RO_SERVICE_CODES       ROSC,
5466                    CSD_SERVICE_CODES_VL       SC,
5467                    CSD_SC_WORK_ENTITIES       WRK,
5468                    BOM_INVENTORY_COMPONENTS_V BOM,
5469                    -- QP_PRICE_LIST_LINES_V      PRICE,
5470                    MTL_SYSTEM_ITEMS_KFV MTL,
5471                    CSD_REPAIR_TYPES_SAR RTSAR,
5472                    CS_TXN_BILLING_TYPES SAR
5473              WHERE ROSC.repair_line_id = p_repair_line_id
5474                AND ROSC.applicable_flag = 'Y'
5475                   -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
5476                AND ROSC.applied_to_est_flag = 'N'
5477                AND WRK.Service_code_id = ROSC.Service_code_id
5478                AND WRK.work_entity_type_code = 'BOM'
5479                AND SC.Service_code_Id = ROSC.Service_code_id
5480                AND NVL(SC.active_from, SYSDATE) <= SYSDATE
5481                AND NVL(SC.active_to, SYSDATE) >= SYSDATE
5482                AND WRK.work_entity_id3 = Cs_Std.get_item_valdn_orgzn_id
5483                   -- and WRK.work_entity_id1 IS NOT NULL
5484                AND BOM.bill_sequence_id = WRK.work_entity_id1
5485                AND NVL(BOM.effectivity_date, SYSDATE) <= SYSDATE -- swai bug 3323274
5486                AND NVL(BOM.disable_date, SYSDATE) >= SYSDATE -- swai bug 3323274
5487                   -- Following lines commented by vkjain, bugfix 3468680
5488                   -- and PRICE.price_list_id(+) = p_price_list_id
5489                   -- and PRICE.inventory_item_id(+) = BOM.component_item_id
5490                   -- and PRICE.unit_code(+) = BOM.primary_uom_code
5491                   -- and nvl(PRICE.start_date_active, SYSDATE) <= SYSDATE  -- swai added
5492                   -- and nvl(PRICE.end_date_active, SYSDATE) >= SYSDATE    -- swai added
5493                AND MTL.inventory_item_id = BOM.component_item_id
5494                AND MTL.organization_id = WRK.work_entity_id3
5495                AND RTSAR.repair_type_id = p_repair_type_id
5496                AND SAR.txn_billing_type_id = RTSAR.txn_billing_type_id(+)
5497                AND SAR.billing_type = MTL.material_billable_flag(+)
5498                AND MTL.material_billable_flag IS NOT NULL;
5499 
5500         CURSOR c_labor_lines_from_bom(p_repair_line_id NUMBER, p_repair_type_id NUMBER) IS
5501         -- p_price_list_id  NUMBER) is -- bug 3468680, vkjain
5502             SELECT RES.billable_item_id INVENTORY_ITEM_ID,
5503                    RES.unit_of_measure  UOM,
5504                    -- OPRES.assigned_units        QUANTITY, -- Replaced by following line to fix 3365436. vkjain.
5505                    OPRES.usage_rate_or_amount QUANTITY,
5506                    -- PRICE.list_price            SELLING_PRICE,
5507                    MTL.concatenated_segments ITEM_NAME,
5508                    MTL.comms_nl_trackable_flag COMMS_NL_TRACKABLE_FLAG,
5509                    SAR.txn_billing_type_id TXN_BILLING_TYPE_ID,
5510                    'SERVICE_CODE' EST_LINE_SOURCE_TYPE_CODE,
5511                    ROSC.Service_Code_id EST_LINE_SOURCE_ID1,
5512                    NULL EST_LINE_SOURCE_ID2,
5513                    ROSC.RO_Service_Code_id RO_SERVICE_CODE_ID,
5514                    RES.resource_id RESOURCE_ID -- vkjain. 3449978
5515               FROM CSD_RO_SERVICE_CODES    ROSC,
5516                    CSD_SC_WORK_ENTITIES    WRK,
5517                    CSD_SERVICE_CODES_VL    SC,
5518                    BOM_OPERATION_SEQUENCES OPSEQ,
5519                    BOM_OPERATION_RESOURCES OPRES,
5520                    -- QP_PRICE_LIST_LINES_V   PRICE,
5521                    MTL_SYSTEM_ITEMS_KFV MTL,
5522                    CSD_REPAIR_TYPES_SAR RTSAR,
5523                    CS_TXN_BILLING_TYPES SAR,
5524                    BOM_RESOURCES        RES
5525              WHERE ROSC.repair_line_id = p_repair_line_id
5526                AND ROSC.applicable_flag = 'Y'
5527                   -- and ROSC.applied_to_work_flag = 'N' -- bugfix 3473869.vkjain.
5528                AND ROSC.applied_to_est_flag = 'N'
5529                AND WRK.Service_code_id = ROSC.Service_code_id
5530                AND WRK.work_entity_type_code = 'BOM'
5531                AND SC.Service_code_Id = ROSC.Service_code_id
5532                AND NVL(SC.active_from, SYSDATE) <= SYSDATE
5533                AND NVL(SC.active_to, SYSDATE) >= SYSDATE
5534                AND WRK.work_entity_id3 = Cs_Std.get_item_valdn_orgzn_id
5535                   -- and WRK.work_entity_id2 IS NOT NULL
5536                AND OPSEQ.ROUTING_SEQUENCE_ID = WRK.work_entity_id2
5537                AND NVL(OPSEQ.effectivity_date, SYSDATE) <= SYSDATE -- swai bug 3323274
5538                AND NVL(OPSEQ.disable_date, SYSDATE) >= SYSDATE -- swai bug 3323274
5539                AND OPRES.OPERATION_SEQUENCE_ID =
5540                    OPSEQ.OPERATION_SEQUENCE_ID
5541                AND RES.RESOURCE_ID = OPRES.RESOURCE_ID
5542                   -- Following lines commented by vkjain, bugfix 3468680
5543                   -- and PRICE.price_list_id(+) = p_price_list_id
5544                   -- and nvl(PRICE.start_date_active, SYSDATE) <= SYSDATE  -- swai added
5545                   -- and nvl(PRICE.end_date_active, SYSDATE) >= SYSDATE    -- swai added
5546                   -- and PRICE.inventory_item_id(+) = RES.billable_item_id
5547                   -- and PRICE.unit_code(+) = RES.unit_of_measure
5548                AND MTL.inventory_item_id = RES.billable_item_id
5549                AND MTL.organization_id = WRK.work_entity_id3
5550                AND MTL.material_billable_flag IS NOT NULL
5551                AND RTSAR.repair_type_id = p_repair_type_id
5552                AND SAR.txn_billing_type_id = RTSAR.txn_billing_type_id(+)
5553                AND SAR.billing_type = MTL.material_billable_flag(+);
5554 
5555     BEGIN
5556         -- Standard Start of API savepoint
5557         SAVEPOINT Get_Estimates_From_BOM;
5558 
5559         -- Standard call to check for call compatibility.
5560         IF NOT Fnd_Api.Compatible_API_Call(lc_api_version,
5561                                            p_api_version,
5562                                            lc_api_name,
5563                                            G_PKG_NAME)
5564         THEN
5565             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
5566         END IF;
5567 
5568         -- Initialize message list if p_init_msg_list is set to TRUE.
5569         IF Fnd_Api.to_Boolean(p_init_msg_list)
5570         THEN
5571             Fnd_Msg_Pub.initialize;
5572         END IF;
5573 
5574         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5575         THEN
5576             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5577                            lc_mod_name || '.BEGIN',
5578                            'Entering CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_BOM');
5579         END IF;
5580         -- log parameters
5581         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
5582         THEN
5583             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5584                            lc_mod_name || '.parameter_logging',
5585                            'p_api_version: ' || p_api_version);
5586             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5587                            lc_mod_name || '.parameter_logging',
5588                            'p_commit: ' || p_commit);
5589             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5590                            lc_mod_name || '.parameter_logging',
5591                            'p_init_msg_list: ' || p_init_msg_list);
5592             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5593                            lc_mod_name || '.parameter_logging',
5594                            'p_validation_level: ' || p_validation_level);
5595             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5596                            lc_mod_name || '.parameter_logging',
5597                            'p_repair_line_id: ' || p_repair_line_id);
5598             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5599                            lc_mod_name || '.parameter_logging',
5600                            'p_estimate_id: ' || p_estimate_id);
5601             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5602                            lc_mod_name || '.parameter_logging',
5603                            'p_repair_type_id: ' || p_repair_type_id);
5604             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5605                            lc_mod_name || '.parameter_logging',
5606                            'p_business_process_id: ' ||
5607                            p_business_process_id);
5608             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5609                            lc_mod_name || '.parameter_logging',
5610                            'p_currency_code: ' || p_currency_code);
5611             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5612                            lc_mod_name || '.parameter_logging',
5613                            'p_incident_id: ' || p_incident_id);
5614             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5615                            lc_mod_name || '.parameter_logging',
5616                            'p_repair_mode: ' || p_repair_mode);
5617             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5618                            lc_mod_name || '.parameter_logging',
5619                            'p_inventory_item_id: ' || p_inventory_item_id);
5620             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5621                            lc_mod_name || '.parameter_logging',
5622                            'p_organization_id: ' || p_organization_id);
5623             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5624                            lc_mod_name || '.parameter_logging',
5625                            'p_price_list_id: ' || p_price_list_id);
5626             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5627                            lc_mod_name || '.parameter_logging',
5628                            'p_contract_line_id: ' || p_contract_line_id);
5629         END IF;
5630 
5631         -- Initialize API return status to success
5632         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
5633 
5634         -- initialize the warning flag
5635         x_warning_flag := Fnd_Api.G_FALSE;
5636 
5637         --
5638         -- Begin API Body
5639         --
5640 
5641         --
5642         -- Get Material Lines from BOM
5643         --
5644         DECLARE
5645             l_count NUMBER := 0;
5646         BEGIN
5647             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5648             THEN
5649                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5650                                lc_mod_name,
5651                                'Getting BOM material lines from service codes');
5652             END IF;
5653             -- Bugfix 3468680, vkjain
5654             -- FOR r1 in c_material_lines_from_bom (p_repair_line_id, p_repair_type_id, p_price_list_id)
5655             FOR r1 IN c_material_lines_from_bom(p_repair_line_id,
5656                                                 p_repair_type_id)
5657             LOOP
5658                 l_count := l_count + 1;
5659                 l_material_lines_tbl(l_count).inventory_item_id := r1.inventory_item_id;
5660                 l_material_lines_tbl(l_count).uom := r1.uom;
5661                 l_material_lines_tbl(l_count).quantity := r1.quantity;
5662                 -- Bugfix 3468680, vkjain
5663                 -- l_material_lines_tbl(l_count).selling_price := r1.selling_price;
5664                 l_material_lines_tbl(l_count).item_name := r1.item_name;
5665                 l_material_lines_tbl(l_count).comms_nl_trackable_flag := r1.comms_nl_trackable_flag;
5666                 l_material_lines_tbl(l_count).txn_billing_type_id := r1.txn_billing_type_id;
5667                 l_material_lines_tbl(l_count).est_line_source_type_code := r1.est_line_source_type_code;
5668                 l_material_lines_tbl(l_count).est_line_source_id1 := r1.est_line_source_id1;
5669                 l_material_lines_tbl(l_count).est_line_source_id2 := r1.est_line_source_id2;
5670                 l_material_lines_tbl(l_count).ro_service_code_id := r1.ro_service_code_id;
5671             END LOOP;
5672         END;
5673 
5674         -- bugfix 3543135, vkjain.
5675         IF (l_material_lines_tbl.COUNT > 0)
5676         THEN
5677             l_No_Eligible_Lines := FALSE;
5678         END IF;
5679 
5680 --        IF (g_debug >= 5)
5681 --        THEN
5682 --            Csd_Gen_Utility_Pvt.dump_mle_lines_tbl_type(l_material_lines_tbl);
5683 --        END IF;
5684 
5685         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5686         THEN
5687             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5688                            lc_mod_name,
5689                            'material line count = ' ||
5690                            l_material_lines_tbl.COUNT);
5691             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5692                            lc_mod_name,
5693                            'Calling Convert_To_Est_Lines');
5694         END IF;
5695 
5696         Convert_To_Est_Lines(p_api_version         => 1.0,
5697                              p_commit              => Fnd_Api.G_FALSE,
5698                              p_init_msg_list       => Fnd_Api.G_FALSE,
5699                              p_validation_level    => p_validation_level,
5700                              x_return_status       => x_return_status,
5701                              x_msg_count           => x_msg_count,
5702                              x_msg_data            => x_msg_data,
5703                              p_repair_line_id      => p_repair_line_id,
5704                              p_estimate_id         => p_estimate_id,
5705                              p_repair_type_id      => p_repair_type_id,
5706                              p_business_process_id => p_business_process_id,
5707                              p_currency_code       => p_currency_code,
5708                              p_incident_id         => p_incident_id,
5709                              p_organization_id     => p_organization_id,
5710                              p_price_list_id       => p_price_list_id,
5711                              p_contract_line_id    => p_contract_line_id,
5712                              p_MLE_lines_tbl       => l_material_lines_tbl,
5713                              x_est_lines_tbl       => x_est_lines_tbl,
5714                              x_warning_flag        => l_warning_flag);
5715 
5716 --        IF (g_debug >= 5)
5717 --        THEN
5718 --            Csd_Gen_Utility_Pvt.dump_repair_estimate_line_tbl(x_est_lines_tbl);
5719 --        END IF;
5720 
5721         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5722         THEN
5723             RAISE Fnd_Api.G_EXC_ERROR;
5724         END IF;
5725 
5726         IF l_warning_flag <> Fnd_Api.G_FALSE
5727         THEN
5728             x_warning_flag := l_warning_flag;
5729         END IF;
5730         --
5731         -- Get Labor Lines from BOM
5732         --
5733         DECLARE
5734             l_count NUMBER := 0;
5735         BEGIN
5736             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5737             THEN
5738                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5739                                lc_mod_name,
5740                                'Getting BOM labor lines from service codes');
5741             END IF;
5742             -- bugfix 3468680, vkjain
5743             -- FOR r2 in c_labor_lines_from_bom (p_repair_line_id, p_repair_type_id, p_price_list_id)
5744             FOR r2 IN c_labor_lines_from_bom(p_repair_line_id,
5745                                              p_repair_type_id)
5746             LOOP
5747                 l_count := l_count + 1;
5748                 l_labor_lines_tbl(l_count).inventory_item_id := r2.inventory_item_id;
5749                 l_labor_lines_tbl(l_count).uom := r2.uom;
5750                 l_labor_lines_tbl(l_count).quantity := r2.quantity;
5751                 -- Bugfix 3468680, vkjain
5752                 -- l_labor_lines_tbl(l_count).selling_price := r2.selling_price;
5753                 l_labor_lines_tbl(l_count).item_name := r2.item_name;
5754                 l_labor_lines_tbl(l_count).comms_nl_trackable_flag := r2.comms_nl_trackable_flag;
5755                 l_labor_lines_tbl(l_count).txn_billing_type_id := r2.txn_billing_type_id;
5756                 l_labor_lines_tbl(l_count).est_line_source_type_code := r2.est_line_source_type_code;
5757                 l_labor_lines_tbl(l_count).est_line_source_id1 := r2.est_line_source_id1;
5758                 l_labor_lines_tbl(l_count).est_line_source_id2 := r2.est_line_source_id2;
5759                 l_labor_lines_tbl(l_count).ro_service_code_id := r2.ro_service_code_id;
5760                 -- vkjain. Bugfix 3449978.
5761                 l_labor_lines_tbl(l_count).resource_id := r2.resource_id;
5762             END LOOP;
5763         END;
5764 
5765         -- bugfix 3543135, vkjain.
5766         IF (l_labor_lines_tbl.COUNT > 0)
5767         THEN
5768             l_No_Eligible_Lines := FALSE;
5769         END IF;
5770 
5771 --        IF (g_debug >= 5)
5772 --        THEN
5773 --            Csd_Gen_Utility_Pvt.dump_mle_lines_tbl_type(l_labor_lines_tbl);
5774 --        END IF;
5775 
5776         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5777         THEN
5778             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5779                            lc_mod_name,
5780                            'labor line count = ' || l_labor_lines_tbl.COUNT);
5781             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5782                            lc_mod_name,
5783                            'Calling Convert_To_Est_Lines');
5784         END IF;
5785         Convert_To_Est_Lines(p_api_version         => 1.0,
5786                              p_commit              => Fnd_Api.G_FALSE,
5787                              p_init_msg_list       => Fnd_Api.G_FALSE,
5788                              p_validation_level    => p_validation_level,
5789                              x_return_status       => x_return_status,
5790                              x_msg_count           => x_msg_count,
5791                              x_msg_data            => x_msg_data,
5792                              p_repair_line_id      => p_repair_line_id,
5793                              p_estimate_id         => p_estimate_id,
5794                              p_repair_type_id      => p_repair_type_id,
5795                              p_business_process_id => p_business_process_id,
5796                              p_currency_code       => p_currency_code,
5797                              p_incident_id         => p_incident_id,
5798                              p_organization_id     => p_organization_id,
5799                              p_price_list_id       => p_price_list_id,
5800                              p_contract_line_id    => p_contract_line_id,
5801                              p_MLE_lines_tbl       => l_labor_lines_tbl,
5802                              x_est_lines_tbl       => x_est_lines_tbl,
5803                              x_warning_flag        => l_warning_flag);
5804 
5805 --        IF (g_debug >= 5)
5806 --        THEN
5807 --            Csd_Gen_Utility_Pvt.dump_repair_estimate_line_tbl(x_est_lines_tbl);
5808 --        END IF;
5809 
5810         IF NOT (x_return_status = Fnd_Api.G_RET_STS_SUCCESS)
5811         THEN
5812             RAISE Fnd_Api.G_EXC_ERROR;
5813         END IF;
5814         IF l_warning_flag <> Fnd_Api.G_FALSE
5815         THEN
5816             x_warning_flag := l_warning_flag;
5817         END IF;
5818 
5819         -- bugfix 3543135, vkjain.
5820         -- IF (NVL(x_est_lines_tbl.count, 0) <= 0) THEN
5821         IF (l_No_Eligible_Lines)
5822         THEN
5823             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5824             THEN
5825                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5826                                lc_mod_name,
5827                                'no estimate lines available to autogenerate from BOM');
5828             END IF;
5829             RAISE CSD_EST_NO_AUTOGEN;
5830         END IF;
5831 
5832         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
5833         THEN
5834             Fnd_Log.STRING(Fnd_Log.Level_Statement,
5835                            lc_mod_name || '.out_parameter',
5836                            'x_warning_flag: ' || x_warning_flag);
5837         END IF;
5838         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
5839         THEN
5840             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
5841                            lc_mod_name || '.END',
5842                            'Leaving CSD_REPAIR_ESTIMATE_PVT.Get_Estimates_From_BOM');
5843         END IF;
5844 
5845         --
5846         -- End API Body
5847         --
5848 
5849         -- Standard check of p_commit.
5850         IF Fnd_Api.To_Boolean(p_commit)
5851         THEN
5852             COMMIT WORK;
5853         END IF;
5854 
5855         -- Standard call to get message count and IF count is  get message info.
5856         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5857                                   p_data  => x_msg_data);
5858     EXCEPTION
5859         WHEN CSD_EST_NO_AUTOGEN THEN
5860             x_warning_flag := Fnd_Api.G_TRUE;
5861 
5862             -- save message in fnd stack
5863             IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
5864             THEN
5865                 Fnd_Log.STRING(Fnd_Log.Level_Statement,
5866                                lc_mod_name,
5867                                'Adding message CSD_EST_NO_AUTOGEN to FND_MSG stack');
5868             END IF;
5869             Fnd_Message.SET_NAME('CSD', 'CSD_EST_NO_AUTOGEN');
5870             Fnd_Msg_Pub.ADD;
5871             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5872                                       p_data  => x_msg_data);
5873 
5874             -- save message in debug log
5875             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5876             THEN
5877                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5878                                lc_mod_name,
5879                                'No estimate lines autogenerated');
5880             END IF;
5881         WHEN Fnd_Api.G_EXC_ERROR THEN
5882             ROLLBACK TO Get_Estimates_From_BOM;
5883             x_return_status := Fnd_Api.G_RET_STS_ERROR;
5884 
5885             /*
5886             -- TO DO: Add seeded err message
5887             -- save message in fnd stack
5888                 if (Fnd_Log.Level_Statement>= Fnd_Log.G_Current_Runtime_Level) then
5889                     FND_LOG.STRING(Fnd_Log.Level_Statement, lc_mod_name,
5890                                    'Adding message err_name to FND_MSG stack');
5891                 end if;
5892             FND_MESSAGE.SET_NAME('CSD','err_name');
5893             FND_MESSAGE.SET_TOKEN('toke_name', 'token_value');
5894             FND_MSG_PUB.ADD;
5895             */
5896             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5897                                       p_data  => x_msg_data);
5898 
5899             -- save message in debug log
5900             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5901             THEN
5902                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5903                                lc_mod_name,
5904                                'EXC_ERROR[' || x_msg_data || ']');
5905             END IF;
5906 
5907         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
5908             ROLLBACK TO Get_Estimates_From_BOM;
5909             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5910 
5911             -- save message in fnd stack
5912             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5913             THEN
5914                 IF (Fnd_Log.Level_Statement >=
5915                    Fnd_Log.G_Current_Runtime_Level)
5916                 THEN
5917                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
5918                                    lc_mod_name,
5919                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
5920                 END IF;
5921                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
5922             END IF;
5923             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5924                                       p_data  => x_msg_data);
5925 
5926             -- save message in debug log
5927             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5928             THEN
5929                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5930                                lc_mod_name,
5931                                'EXC_UNEXPECTED_ERROR[' || x_msg_data || ']');
5932             END IF;
5933 
5934         WHEN OTHERS THEN
5935             ROLLBACK TO Get_Estimates_From_BOM;
5936             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
5937             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
5938             THEN
5939                 IF (Fnd_Log.Level_Statement >=
5940                    Fnd_Log.G_Current_Runtime_Level)
5941                 THEN
5942                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
5943                                    lc_mod_name,
5944                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
5945                 END IF;
5946                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
5947             END IF;
5948             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
5949                                       p_data  => x_msg_data);
5950 
5951             -- save message in debug log
5952             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
5953             THEN
5954                 -- create a seeded message
5955                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
5956                                lc_mod_name,
5957                                'SQL Message[' || SQLERRM || ']');
5958             END IF;
5959     END Get_Estimates_From_BOM;
5960 
5961     /*--------------------------------------------------*/
5962     /* procedure name: Convert_To_Est_Lines             */
5963     /* description   : The procedure to manipulate      */
5964     /*                 different structures. It converts*/
5965     /*                 data from MLE_LINES_REC_TYPE to  */
5966     /*                 REPAIR_ESTIMATE_LINE_REC. It also*/
5967     /*                 sets the item cost and logs      */
5968     /*                 warnings.                        */
5969     /*                                                  */
5970     /* x_warning_flag : FND_API.G_TRUE if any non-fatal */
5971     /*                  errors occured. FND_API.G_FALSE */
5972     /*                  if everything was successful.   */
5973     /*                  Note that this value could be   */
5974     /*                  G_TRUE even if x_return_status  */
5975     /*                  is G_RET_STS_SUCCESS            */
5976     /* called from:  Get_Estimates_From_BOM             */
5977     /*               Get_Estimates_From_Task            */
5978     /*--------------------------------------------------*/
5979     PROCEDURE Convert_To_Est_Lines(p_api_version         IN NUMBER,
5980                                    p_commit              IN VARCHAR2,
5981                                    p_init_msg_list       IN VARCHAR2,
5982                                    p_validation_level    IN NUMBER,
5983                                    x_return_status       OUT NOCOPY VARCHAR2,
5984                                    x_msg_count           OUT NOCOPY NUMBER,
5985                                    x_msg_data            OUT NOCOPY VARCHAR2,
5986                                    p_repair_line_id      IN NUMBER,
5987                                    p_estimate_id         IN NUMBER,
5988                                    p_repair_type_id      IN NUMBER,
5989                                    p_business_process_id IN NUMBER,
5990                                    p_currency_code       IN VARCHAR2,
5991                                    p_incident_id         IN NUMBER,
5992                                    p_organization_id     IN NUMBER,
5993                                    p_price_list_id       IN NUMBER,
5994                                    p_contract_line_id    IN NUMBER,
5995                                    p_MLE_lines_tbl       IN MLE_LINES_TBL_TYPE,
5996                                    x_est_lines_tbl       IN OUT NOCOPY REPAIR_ESTIMATE_LINE_TBL,
5997                                    x_warning_flag        OUT NOCOPY VARCHAR2) IS
5998         -- CONSTANTS --
5999         lc_debug_level CONSTANT NUMBER := Fnd_Log.G_CURRENT_RUNTIME_LEVEL;
6000         lc_stat_level  CONSTANT NUMBER := Fnd_Log.LEVEL_STATEMENT;
6001         lc_proc_level  CONSTANT NUMBER := Fnd_Log.LEVEL_PROCEDURE;
6002         lc_event_level CONSTANT NUMBER := Fnd_Log.LEVEL_EVENT;
6003         lc_excep_level CONSTANT NUMBER := Fnd_Log.LEVEL_EXCEPTION;
6004         lc_error_level CONSTANT NUMBER := Fnd_Log.LEVEL_ERROR;
6005         lc_unexp_level CONSTANT NUMBER := Fnd_Log.LEVEL_UNEXPECTED;
6006         lc_mod_name    CONSTANT VARCHAR2(100) := 'csd.plsql.csd_repair_estimate_pvt.convert_to_est_lines';
6007         lc_api_name    CONSTANT VARCHAR2(30) := 'Convert_To_Est_Lines';
6008         lc_api_version CONSTANT NUMBER := 1.0;
6009 
6010         -- VARIABLES --
6011         l_error           BOOLEAN;
6012         l_numRows         NUMBER;
6013         l_curRow          NUMBER;
6014         l_price_list_name VARCHAR2(240);
6015         l_num_subtypes    NUMBER;
6016         l_ext_price       NUMBER;
6017         l_selling_price   NUMBER;
6018         l_no_charge_flag  VARCHAR2(1);
6019 
6020         l_return_status VARCHAR2(1);
6021         l_msg_count     NUMBER;
6022         l_msg_data      VARCHAR2(2000);
6023 
6024         -- Pricing attributes
6025         l_pricing_rec Csd_Process_Util.pricing_attr_rec;
6026 		--bug#3875036
6027 		l_account_id						NUMBER        := NULL;
6028 
6029         -- cursors --
6030         /* -- no longer validating this due to performance
6031          cursor count_csi_txn_subtypes (p_txn_billing_type_id NUMBER) is
6032             -- number of txn subtypes for a given txn billing type
6033             SELECT count(*)
6034             FROM   csi_txn_sub_types ib,
6035                    cs_txn_billing_types cs
6036             WHERE  ib.cs_transaction_type_id = cs.transaction_type_id
6037                    and cs.txn_billing_type_id = p_txn_billing_type_id;
6038         */
6039 
6040         CURSOR c_transaction_type(p_txn_billing_type_id NUMBER) IS
6041             SELECT cs.transaction_type_id
6042               FROM cs_txn_billing_types cs
6043              WHERE cs.txn_billing_type_id = p_txn_billing_type_id;
6044 
6045     BEGIN
6046         -- Standard Start of API savepoint
6047         SAVEPOINT Convert_To_Est_Lines;
6048 
6049         -- Standard call to check for call compatibility.
6050         IF NOT Fnd_Api.Compatible_API_Call(lc_api_version,
6051                                            p_api_version,
6052                                            lc_api_name,
6053                                            G_PKG_NAME)
6054         THEN
6055             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6056         END IF;
6057 
6058         -- Initialize message list if p_init_msg_list is set to TRUE.
6059         IF Fnd_Api.to_Boolean(p_init_msg_list)
6060         THEN
6061             Fnd_Msg_Pub.initialize;
6062         END IF;
6063 
6064         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
6065         THEN
6066             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6067                            lc_mod_name || '.BEGIN',
6068                            'Entering CSD_REPAIR_ESTIMATE_PVT.Convert_To_Est_Lines');
6069         END IF;
6070         -- log parameters
6071         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
6072         THEN
6073             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6074                            lc_mod_name || '.parameter_logging',
6075                            'p_api_version: ' || p_api_version);
6076             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6077                            lc_mod_name || '.parameter_logging',
6078                            'p_commit: ' || p_commit);
6079             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6080                            lc_mod_name || '.parameter_logging',
6081                            'p_init_msg_list: ' || p_init_msg_list);
6082             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6083                            lc_mod_name || '.parameter_logging',
6084                            'p_validation_level: ' || p_validation_level);
6085             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6086                            lc_mod_name || '.parameter_logging',
6087                            'p_repair_line_id: ' || p_repair_line_id);
6088             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6089                            lc_mod_name || '.parameter_logging',
6090                            'p_estimate_id: ' || p_estimate_id);
6091             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6092                            lc_mod_name || '.parameter_logging',
6093                            'p_repair_type_id: ' || p_repair_type_id);
6094             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6095                            lc_mod_name || '.parameter_logging',
6096                            'p_business_process_id: ' ||
6097                            p_business_process_id);
6098             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6099                            lc_mod_name || '.parameter_logging',
6100                            'p_currency_code: ' || p_currency_code);
6101             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6102                            lc_mod_name || '.parameter_logging',
6103                            'p_incident_id: ' || p_incident_id);
6104             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6105                            lc_mod_name || '.parameter_logging',
6106                            'p_organization_id: ' || p_organization_id);
6107             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6108                            lc_mod_name || '.parameter_logging',
6109                            'p_price_list_id: ' || p_price_list_id);
6110             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6111                            lc_mod_name || '.parameter_logging',
6112                            'p_contract_line_id: ' || p_contract_line_id);
6113         END IF;
6114 
6115         -- Initialize API return status to success
6116         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6117 
6118         -- initialize the warning flag
6119         x_warning_flag := Fnd_Api.G_FALSE;
6120 
6121 	/* bug#3875036 */
6122 		l_account_id := CSD_CHARGE_LINE_UTIL.Get_SR_AccountId(p_repair_line_id);
6123 
6124         --
6125         -- Begin API Body
6126         --
6127         l_numRows := p_MLE_lines_tbl.COUNT;
6128         FOR i IN 1 .. l_numRows
6129         LOOP
6130             l_error := FALSE;
6131             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
6132             THEN
6133                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6134                                lc_mod_name,
6135                                'Processing MLE line ' || i);
6136             END IF;
6137 
6138             -- Initialize the selling price variable.
6139             -- bugfix 3468680, vkjain.
6140             l_selling_price := NULL;
6141 
6142             -- get the selling price of the item
6143             -- if no selling price, then we cannot determine charge, so
6144             -- log a warning.
6145             BEGIN
6146                 IF (Fnd_Log.Level_Procedure >=
6147                    Fnd_Log.G_Current_Runtime_Level)
6148                 THEN
6149                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6150                                    lc_mod_name,
6151                                    'Calling CSD_PROCESS_UTIL.get_charge_selling_price');
6152                 END IF;
6153 
6154                 Csd_Process_Util.GET_CHARGE_SELLING_PRICE(p_inventory_item_id    => p_MLE_lines_tbl(i)
6155                                                                                    .inventory_item_id,
6156                                                           p_price_list_header_id => p_price_list_id,
6157                                                           p_unit_of_measure_code => p_MLE_lines_tbl(i).uom,
6158                                                           p_currency_code        => p_currency_code,
6159                                                           p_quantity_required    => p_MLE_lines_tbl(i).quantity,
6160 														  p_account_id			  => l_account_id,  /* bug#3875036 */
6161 														  p_org_id => p_organization_id, -- added for R12
6162                                                           p_pricing_rec          => l_pricing_rec,
6163                                                           x_selling_price        => l_selling_price,
6164                                                           x_return_status        => l_return_status,
6165                                                           x_msg_count            => l_msg_count,
6166                                                           x_msg_data             => l_msg_data);
6167                 IF (Fnd_Log.Level_Procedure >=
6168                    Fnd_Log.G_Current_Runtime_Level)
6169                 THEN
6170                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6171                                    lc_mod_name,
6172                                    'Returned from CSD_PROCESS_UTIL.get_charge_selling_price');
6173                 END IF;
6174                 IF (Fnd_Log.Level_Statement >=
6175                    Fnd_Log.G_Current_Runtime_Level)
6176                 THEN
6177                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6178                                    lc_mod_name,
6179                                    'l_selling_price = ' || l_selling_price);
6180                 END IF;
6181             EXCEPTION
6182                 WHEN Fnd_Api.G_EXC_ERROR THEN
6183                     l_return_status := Fnd_Api.G_RET_STS_ERROR;
6184                     IF (Fnd_Log.Level_Procedure >=
6185                        Fnd_Log.G_Current_Runtime_Level)
6186                     THEN
6187                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6188                                        lc_mod_name,
6189                                        'Exception FND_API.G_EXC_ERROR occurred in CSD_PROCESS_UTIL.get_charge_selling_price');
6190                     END IF;
6191                 WHEN OTHERS THEN
6192                     l_return_status := Fnd_Api.G_RET_STS_ERROR;
6193                     IF (Fnd_Log.Level_Procedure >=
6194                        Fnd_Log.G_Current_Runtime_Level)
6195                     THEN
6196                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6197                                        lc_mod_name,
6198                                        'Exception OTHERS occurred in CSD_PROCESS_UTIL.get_charge_selling_price');
6199                     END IF;
6200             END;
6201 
6202             IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS) OR
6203                (l_selling_price IS NULL)
6204             THEN
6205                 IF (Fnd_Log.Level_Statement >=
6206                    Fnd_Log.G_Current_Runtime_Level)
6207                 THEN
6208                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6209                                    lc_mod_name,
6210                                    'Adding message CSD_EST_NOPRICE_ITEM_UOM to FND_MSG stack');
6211                 END IF;
6212                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_NOPRICE_ITEM_UOM');
6213                 BEGIN
6214                     SELECT name
6215                       INTO l_price_list_name
6216                       FROM qp_list_headers_tl
6217                      WHERE list_header_id = p_price_list_id;
6218                 EXCEPTION
6219                     WHEN NO_DATA_FOUND THEN
6220                         l_price_list_name := p_price_list_id;
6221                         IF (Fnd_Log.Level_Procedure >=
6222                            Fnd_Log.G_Current_Runtime_Level)
6223                         THEN
6224                             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6225                                            lc_mod_name,
6226                                            'Exception NO_DATA_FOUND occurred while querying for price list name');
6227                         END IF;
6228                     WHEN OTHERS THEN
6229                         l_price_list_name := p_price_list_id;
6230                         IF (Fnd_Log.Level_Procedure >=
6231                            Fnd_Log.G_Current_Runtime_Level)
6232                         THEN
6233                             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6234                                            lc_mod_name,
6235                                            'Exception OTHERS occurred while querying for price list name');
6236                         END IF;
6237                 END;
6238                 Fnd_Message.SET_TOKEN('ITEM', p_MLE_lines_tbl(i).item_name);
6239                 Fnd_Message.SET_TOKEN('PRICELIST', l_price_list_name);
6240                 Fnd_Message.SET_TOKEN('UOM', p_MLE_lines_tbl(i).uom);
6241                 Fnd_Msg_Pub.ADD;
6242                 l_error := TRUE;
6243                 IF (Fnd_Log.Level_Statement >=
6244                    Fnd_Log.G_Current_Runtime_Level)
6245                 THEN
6246                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6247                                    lc_mod_name,
6248                                    'Unable to get price for item-uom combination in pricelist ' ||
6249                                    p_price_list_id);
6250                 END IF;
6251             END IF;
6252 
6253             -- check txn billing type
6254             IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
6255             THEN
6256                 Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6257                                lc_mod_name,
6258                                'Checking for required txn billing type id');
6259             END IF;
6260             IF (p_MLE_lines_tbl(i).txn_billing_type_id IS NULL)
6261             THEN
6262                 IF (Fnd_Log.Level_Statement >=
6263                    Fnd_Log.G_Current_Runtime_Level)
6264                 THEN
6265                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6266                                    lc_mod_name,
6267                                    'Adding message CSD_EST_NO_ITEM_SAR to FND_MSG stack');
6268                 END IF;
6269                 Fnd_Message.SET_NAME('CSD', 'CSD_EST_NO_ITEM_SAR');
6270                 Fnd_Message.SET_TOKEN('ITEM', p_MLE_lines_tbl(i).item_name);
6271                 Fnd_Msg_Pub.ADD;
6272                 l_error := TRUE;
6273                 IF (Fnd_Log.Level_Statement >=
6274                    Fnd_Log.G_Current_Runtime_Level)
6275                 THEN
6276                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6277                                    lc_mod_name,
6278                                    'Error - txn_billing_type_id is null');
6279                 ELSE
6280                     IF (Fnd_Log.Level_Procedure >=
6281                        Fnd_Log.G_Current_Runtime_Level)
6282                     THEN
6283                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6284                                        lc_mod_name,
6285                                        'Txn billing type id is available');
6286                     END IF;
6287                 END IF;
6288 
6289             END IF;
6290 
6291             IF (l_error = FALSE)
6292             THEN
6293                 l_curRow := x_est_lines_tbl.COUNT + 1;
6294 
6295                 -- default no_charge if it is set up in charges
6296                 -- this is probably a rare case
6297                 IF (Fnd_Log.Level_Procedure >=
6298                    Fnd_Log.G_Current_Runtime_Level)
6299                 THEN
6300                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6301                                    lc_mod_name,
6302                                    'Getting no charge flag to determine extended price');
6303                 END IF;
6304                 l_no_charge_flag := Csd_Process_Util.Get_No_Chg_Flag(p_MLE_lines_tbl(i)
6305                                                                      .txn_billing_type_id);
6306                 IF (NVL(l_no_charge_flag, 'N') = 'Y')
6307                 THEN
6308                     l_ext_price := 0;
6309                 ELSE
6310                     -- l_ext_price := nvl(p_MLE_lines_tbl(i).quantity, 0) * nvl(p_MLE_lines_tbl(i).selling_price,0);
6311                     -- bugfix 3468680 vkjain. Using the price from the Pricing Engine API.
6312                     l_ext_price := NVL(p_MLE_lines_tbl(i).quantity, 0) *
6313                                    l_selling_price;
6314                 END IF;
6315                 IF (Fnd_Log.Level_Statement >=
6316                    Fnd_Log.G_Current_Runtime_Level)
6317                 THEN
6318                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6319                                    lc_mod_name,
6320                                    'l_no_charge_flag = ' ||
6321                                    l_no_charge_flag);
6322                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6323                                    lc_mod_name,
6324                                    'l_ext_price = ' || l_ext_price);
6325                 END IF;
6326 
6327                 --
6328                 -- Derive after waranty cost
6329                 -- note: this portion of code is very similar to
6330                 -- ESTIMATE_UTILS.copy_unitprice_nochg_values in CSDREPLN.pld
6331                 -- consider modularizing code for this
6332                 --
6333                 IF (p_contract_line_id IS NOT NULL) AND
6334                    (p_business_process_id IS NOT NULL) AND
6335                    (NVL(l_no_charge_flag, 'N') = 'N')
6336                 THEN
6337                     BEGIN
6338                         IF (Fnd_Log.Level_Procedure >=
6339                            Fnd_Log.G_Current_Runtime_Level)
6340                         THEN
6341                             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6342                                            lc_mod_name,
6343                                            'Calling CSD_CHARGE_LINE_UTIL.Get_CoverageInfo');
6344                         END IF;
6345                         Csd_Charge_Line_Util.Get_CoverageInfo(p_contract_line_id      => p_contract_line_id,
6346                                                               p_business_process_id   => p_business_process_id,
6347                                                               x_return_status         => x_return_status,
6348                                                               x_msg_count             => x_msg_count,
6349                                                               x_msg_data              => x_msg_data,
6350                                                               x_contract_id           => x_est_lines_tbl(l_curRow)
6351                                                                                         .contract_id,
6352                                                               x_contract_number       => x_est_lines_tbl(l_curRow)
6353                                                                                         .contract_number,
6354                                                               x_coverage_id           => x_est_lines_tbl(l_curRow)
6355                                                                                         .coverage_id,
6356                                                               x_coverage_txn_group_id => x_est_lines_tbl(l_curRow)
6357                                                                                         .coverage_txn_group_id);
6358                         IF (Fnd_Log.Level_Statement >=
6359                            Fnd_Log.G_Current_Runtime_Level)
6360                         THEN
6361                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6362                                            lc_mod_name,
6363                                            'x_contract_id = ' ||
6364                                             x_est_lines_tbl(l_curRow)
6365                                            .contract_id);
6366                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6367                                            lc_mod_name,
6368                                            'x_contract_number = ' ||
6369                                             x_est_lines_tbl(l_curRow)
6370                                            .contract_number);
6371                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6372                                            lc_mod_name,
6373                                            'x_coverage_id = ' ||
6374                                             x_est_lines_tbl(l_curRow)
6375                                            .coverage_id);
6376                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6377                                            lc_mod_name,
6378                                            'x_coverage_txn_group_id = ' ||
6379                                             x_est_lines_tbl(l_curRow)
6380                                            .coverage_txn_group_id);
6381                         END IF;
6382 
6383                     EXCEPTION
6384                         WHEN Fnd_Api.G_EXC_ERROR THEN
6385                             l_return_status := Fnd_Api.G_RET_STS_ERROR;
6386                         WHEN OTHERS THEN
6387                             l_return_status := Fnd_Api.G_RET_STS_ERROR;
6388                     END;
6389 
6390                     IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
6391                     THEN
6392                         l_error := TRUE;
6393                     END IF;
6394 
6395                     BEGIN
6396                         IF (Fnd_Log.Level_Procedure >=
6397                            Fnd_Log.G_Current_Runtime_Level)
6398                         THEN
6399                             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6400                                            lc_mod_name,
6401                                            'Calling CSD_CHARGE_LINE_UTIL.get_discountedprice');
6402                         END IF;
6403                         Csd_Charge_Line_Util.GET_DISCOUNTEDPRICE(p_api_version         => 1.0,
6404                                                                  p_init_msg_list       => Fnd_Api.G_FALSE,
6405                                                                  p_contract_line_id    => p_contract_line_id,
6406                                                                  p_repair_type_id      => p_repair_type_id,
6407                                                                  p_txn_billing_type_id => p_MLE_lines_tbl(i)
6408                                                                                          .txn_billing_type_id,
6409                                                                  p_coverage_txn_grp_id => x_est_lines_tbl(l_curRow)
6410                                                                                          .coverage_txn_group_id,
6411                                                                  p_extended_price      => l_ext_price,
6412                                                                  p_no_charge_flag      => l_no_charge_flag,
6413                                                                  x_discounted_price    => x_est_lines_tbl(l_curRow)
6414                                                                                          .after_warranty_cost,
6415                                                                  x_return_status       => l_return_status,
6416                                                                  x_msg_count           => l_msg_count,
6417                                                                  x_msg_data            => l_msg_data);
6418                         IF (Fnd_Log.Level_Statement >=
6419                            Fnd_Log.G_Current_Runtime_Level)
6420                         THEN
6421                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6422                                            lc_mod_name,
6423                                            'x_discounted_price = ' ||
6424                                             x_est_lines_tbl(l_curRow)
6425                                            .after_warranty_cost);
6426                         END IF;
6427                     EXCEPTION
6428                         WHEN Fnd_Api.G_EXC_ERROR THEN
6429                             l_return_status := Fnd_Api.G_RET_STS_ERROR;
6430                         WHEN OTHERS THEN
6431                             l_return_status := Fnd_Api.G_RET_STS_ERROR;
6432                     END;
6433                     IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
6434                     THEN
6435                         IF (Fnd_Log.Level_Statement >=
6436                            Fnd_Log.G_Current_Runtime_Level)
6437                         THEN
6438                             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6439                                            lc_mod_name,
6440                                            'Adding message CSD_EST_ESTIMATED_CHARGE_ERR to FND_MSG stack');
6441                         END IF;
6442                         Fnd_Message.SET_NAME('CSD',
6443                                              'CSD_EST_ESTIMATED_CHARGE_ERR');
6444                         Fnd_Message.SET_TOKEN('CONTRACT_NUMBER',
6445                                               x_est_lines_tbl(l_curRow)
6446                                               .contract_number);
6447                         Fnd_Msg_Pub.ADD;
6448                         l_error := TRUE;
6449                     END IF;
6450                     -- Bugfix 3843770, vkjain.
6451                     -- The contract discount field is not being populated for AutoCreate
6452                     -- estimate lines.
6453                     x_est_lines_tbl(l_curRow).contract_discount_amount := l_ext_price -
6454                                                                           NVL(x_est_lines_tbl(l_curRow)
6455                                                                               .after_warranty_cost,
6456                                                                               0);
6457                 ELSE
6458                     -- p_contract_line_id is null or p_business_process_id is null
6459                     x_est_lines_tbl(l_curRow).after_warranty_cost := l_ext_price;
6460                 END IF; -- end derive after warranty cost
6461 
6462                 -- Added by vkjain. 3449978.
6463                 x_est_lines_tbl(l_curRow).resource_id := p_MLE_lines_tbl(i)
6464                                                         .resource_id;
6465 
6466                 BEGIN
6467                     IF (Fnd_Log.Level_Procedure >=
6468                        Fnd_Log.G_Current_Runtime_Level)
6469                     THEN
6470                         Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6471                                        lc_mod_name,
6472                                        'Calling CSD_COST_ANALYSIS_PVT.arcs in forms/US/CSDREPLN.fmb
6473 				   ItemCost');
6474                     END IF;
6475 
6476                     -- Bugfix 3449978. vkjain.
6477                     -- We attempt to get the resource_id for labor lines.
6478                     -- The Get_InvItemCost procedure is replaced by
6479                     -- Get_ResItemCost. The Get_ResItemCost procedure
6480                     -- gets the reosurce cost if it exists and otherwise
6481                     -- gets the item cost.
6482                     -- CSD_COST_ANALYSIS_PVT.Get_InvItemCost(
6483                     Csd_Cost_Analysis_Pvt.Get_ResItemCost(
6484                                                           -- p_api_version           =>     1.0,
6485                                                           -- p_commit                =>     fnd_api.g_false,
6486                                                           -- p_init_msg_list         =>     fnd_api.g_false,
6487                                                           -- p_validation_level      =>     fnd_api.g_valid_level_full,
6488                                                           x_return_status     => l_return_status,
6489                                                           x_msg_count         => l_msg_count,
6490                                                           x_msg_data          => l_msg_data,
6491                                                           p_inventory_item_id => p_MLE_lines_tbl(i)
6492                                                                                 .inventory_item_id,
6493                                                           p_organization_id   => p_organization_id,
6494                                                           p_bom_resource_id   => p_MLE_lines_tbl(i)
6495                                                                                 .resource_id,
6496                                                           p_charge_date       => SYSDATE,
6497                                                           p_currency_code     => p_currency_code,
6498                                                           p_chg_line_uom_code => p_MLE_lines_tbl(i).uom, --sangigup 3356020
6499                                                           x_item_cost         => x_est_lines_tbl(l_curRow)
6500                                                                                 .item_cost);
6501                     IF (Fnd_Log.Level_Statement >=
6502                        Fnd_Log.G_Current_Runtime_Level)
6503                     THEN
6504                         Fnd_Log.STRING(Fnd_Log.Level_Statement,
6505                                        lc_mod_name,
6506                                        'x_item_cost = ' ||
6507                                        x_est_lines_tbl(l_curRow).item_cost);
6508                     END IF;
6509                 EXCEPTION
6510                     WHEN Fnd_Api.G_EXC_ERROR THEN
6511                         l_return_status := Fnd_Api.G_RET_STS_ERROR;
6512                     WHEN OTHERS THEN
6513                         l_return_status := Fnd_Api.G_RET_STS_ERROR;
6514                 END;
6515 
6516                 IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
6517                 THEN
6518                     x_est_lines_tbl(l_curRow).item_cost := NULL;
6519                     --
6520                     -- TO DO: give warning message that cost could not be determined?
6521                     -- x_warning_flag  := FND_API.G_TRUE;
6522                     -- x_return_status := FND_API.G_RET_STS_ERROR;
6523                     --    if (Fnd_Log.Level_Statement>= Fnd_Log.G_Current_Runtime_Level) then
6524                     --        FND_LOG.STRING(Fnd_Log.Level_Statement, lc_mod_name,
6525                     --                       'Adding message CSD_EST_ESTIMATED_CHARGE_ERR to FND_MSG stack');
6526                     --    end if;
6527                     -- FND_MESSAGE.SET_NAME('CSD','CSD_EST_ESTIMATED_CHARGE_ERR');
6528                     -- FND_MESSAGE.SET_TOKEN('CONTRACT_NUMBER',x_est_lines_tbl(l_curRow).contract_number);
6529                     -- FND_MSG_PUB.ADD;
6530                     -- l_error := TRUE;
6531                 END IF;
6532 
6533                 -- set transaction type (Material, labor, expense)
6534                 IF (Fnd_Log.Level_Procedure >=
6535                    Fnd_Log.G_Current_Runtime_Level)
6536                 THEN
6537                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6538                                    lc_mod_name,
6539                                    'Getting transaction type id');
6540                 END IF;
6541                 OPEN c_transaction_type(p_MLE_lines_tbl(i)
6542                                         .txn_billing_type_id);
6543                 FETCH c_transaction_type
6544                     INTO x_est_lines_tbl(l_curRow) .transaction_type_id;
6545                 CLOSE c_transaction_type;
6546 
6547                 -- values from individual params
6548                 x_est_lines_tbl(l_curRow).repair_estimate_id := p_estimate_id; -- required param
6549                 x_est_lines_tbl(l_curRow).repair_line_id := p_repair_line_id; -- required param
6550                 x_est_lines_tbl(l_curRow).incident_id := p_incident_id; -- derived value, do we need this?
6551                 x_est_lines_tbl(l_curRow).business_process_id := p_business_process_id; -- optional value?, used if derived value not available
6552                 x_est_lines_tbl(l_curRow).currency_code := p_currency_code; -- derived value, do we need this?
6553                 x_est_lines_tbl(l_curRow).organization_id := p_organization_id; -- required param
6554                 x_est_lines_tbl(l_curRow).price_list_id := p_price_list_id; -- required param
6555 
6556                 -- values from MLE_LINES
6557                 x_est_lines_tbl(l_curRow).txn_billing_type_id := p_MLE_lines_tbl(i)
6558                                                                 .txn_billing_type_id; -- required param
6559                 x_est_lines_tbl(l_curRow).inventory_item_id := p_MLE_lines_tbl(i)
6560                                                               .inventory_item_id; -- required param
6561                 x_est_lines_tbl(l_curRow).unit_of_measure_code := p_MLE_lines_tbl(i).uom; -- required param
6562                 x_est_lines_tbl(l_curRow).estimate_quantity := p_MLE_lines_tbl(i)
6563                                                               .quantity; -- required param
6564                 -- x_est_lines_tbl(l_curRow).selling_price        := p_MLE_lines_tbl(i).selling_price;
6565                 -- bugfix 3468680, vkjain.
6566                 -- Setting the selling price that is from the Pricing Engine.
6567                 x_est_lines_tbl(l_curRow).selling_price := l_selling_price;
6568                 x_est_lines_tbl(l_curRow).est_line_source_type_code := p_MLE_lines_tbl(i)
6569                                                                       .est_line_source_type_code;
6570                 x_est_lines_tbl(l_curRow).est_line_source_id1 := p_MLE_lines_tbl(i)
6571                                                                 .est_line_source_id1;
6572                 x_est_lines_tbl(l_curRow).est_line_source_id2 := p_MLE_lines_tbl(i)
6573                                                                 .est_line_source_id2;
6574                 x_est_lines_tbl(l_curRow).ro_service_code_id := p_MLE_lines_tbl(i)
6575                                                                .ro_service_code_id;
6576                 -- bug#7212629, subhat.
6577                 -- the contract line id information is not passed to
6578                 -- charges API, but the contract id is passed.
6579                 -- we need to pass contract line id, if not
6580                 -- CSD_CHARGE_LINE_UTIL.GET_DISCOUNTEDPRICE will fail in CSDESTIM.pld.
6581 
6582                 x_est_lines_tbl(l_curRow).contract_line_id := p_contract_line_id;
6583                 --end bug#7212629, subhat.
6584 
6585                 -- null items
6586                 x_est_lines_tbl(l_curRow).reference_number := NULL;
6587                 x_est_lines_tbl(l_curRow).order_number := NULL;
6588                 x_est_lines_tbl(l_curRow).source_number := NULL;
6589                 x_est_lines_tbl(l_curRow).original_source_number := NULL;
6590                 x_est_lines_tbl(l_curRow).original_system_reference := NULL;
6591                 x_est_lines_tbl(l_curRow).lot_number := NULL;
6592                 x_est_lines_tbl(l_curRow).instance_id := NULL;
6593                 x_est_lines_tbl(l_curRow).instance_number := NULL;
6594                 x_est_lines_tbl(l_curRow).coverage_bill_rate_id := NULL;
6595                 x_est_lines_tbl(l_curRow).sub_inventory := NULL;
6596                 x_est_lines_tbl(l_curRow).return_reason := NULL;
6597                 x_est_lines_tbl(l_curRow).last_update_date := NULL;
6598                 x_est_lines_tbl(l_curRow).last_updated_by := NULL;
6599                 x_est_lines_tbl(l_curRow).created_by := NULL;
6600                 x_est_lines_tbl(l_curRow).last_update_login := NULL;
6601                 x_est_lines_tbl(l_curRow).security_group_id := NULL;
6602 
6603                 -- non-null items
6604                 x_est_lines_tbl(l_curRow).return_by_date := SYSDATE;
6605                 x_est_lines_tbl(l_curRow).creation_date := SYSDATE;
6606                 x_est_lines_tbl(l_curRow).original_source_code := 'DR'; -- check for constants
6607                 x_est_lines_tbl(l_curRow).source_code := 'DR';
6608                 x_est_lines_tbl(l_curRow).charge_line_type := 'ESTIMATE'; -- check for constants to use
6609                 x_est_lines_tbl(l_curRow).no_charge_flag := l_no_charge_flag;
6610                 x_est_lines_tbl(l_curRow).override_charge_flag := NVL(l_no_charge_flag,
6611                                                                       'N'); -- charge is only overridden if no charge
6612                 x_est_lines_tbl(l_curRow).interface_to_om_flag := 'N';
6613 
6614                 -- TO DO: get default po number from repair estimate
6615                 -- x_est_lines_tbl(l_curRow).purchase_order_num        := name_in('repair_estimate_line_det.po_number');
6616 
6617             END IF; -- end if l_error = FALSE.
6618 
6619             -- Note: Do NOT elsif this statement with the above "if (l_error = FALSE)",
6620             -- since the above section could potentially set l_error=TRUE as well.
6621             IF (l_error = TRUE)
6622             THEN
6623                 x_warning_flag := Fnd_Api.G_TRUE;
6624                 IF (Fnd_Log.Level_Procedure >=
6625                    Fnd_Log.G_Current_Runtime_Level)
6626                 THEN
6627                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6628                                    lc_mod_name,
6629                                    'Calling CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
6630                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6631                                    lc_mod_name,
6632                                    'Number of messages in stack: ' ||
6633                                    Fnd_Msg_Pub.count_msg);
6634                 END IF;
6635                 Csd_Gen_Errmsgs_Pvt.Save_Fnd_Msgs(p_api_version             => 1.0,
6636                                                   p_commit                  => Fnd_Api.G_FALSE,
6637                                                   p_init_msg_list           => Fnd_Api.G_FALSE,
6638                                                   p_validation_level        => 0,
6639                                                   p_module_code             => 'EST',
6640                                                   p_source_entity_id1       => p_repair_line_id,
6641                                                   p_source_entity_type_code => p_MLE_lines_tbl(i)
6642                                                                               .est_line_source_type_code,
6643                                                   p_source_entity_id2       => p_MLE_lines_tbl(i)
6644                                                                               .est_line_source_id1,
6645                                                   x_return_status           => l_return_status,
6646                                                   x_msg_count               => l_msg_count,
6647                                                   x_msg_data                => l_msg_data);
6648                 IF NOT (l_return_status = Fnd_Api.G_RET_STS_SUCCESS)
6649                 THEN
6650                     RAISE Fnd_Api.G_EXC_ERROR;
6651                 END IF;
6652                 IF (Fnd_Log.Level_Procedure >=
6653                    Fnd_Log.G_Current_Runtime_Level)
6654                 THEN
6655                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6656                                    lc_mod_name,
6657                                    'Returned from CSD_GEN_ERRMSGS_PVT.Save_Fnd_Msgs');
6658                     Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6659                                    lc_mod_name,
6660                                    'Number of messages in stack: ' ||
6661                                    Fnd_Msg_Pub.count_msg);
6662                 END IF;
6663             END IF;
6664         END LOOP;
6665 
6666         IF (Fnd_Log.Level_Statement >= Fnd_Log.G_Current_Runtime_Level)
6667         THEN
6668             Fnd_Log.STRING(Fnd_Log.Level_Statement,
6669                            lc_mod_name || '.out_parameter',
6670                            'x_warning_flag: ' || x_warning_flag);
6671         END IF;
6672         IF (Fnd_Log.Level_Procedure >= Fnd_Log.G_Current_Runtime_Level)
6673         THEN
6674             Fnd_Log.STRING(Fnd_Log.Level_Procedure,
6675                            lc_mod_name || '.END',
6676                            'Leaving CSD_REPAIR_ESTIMATE_PVT.Convert_To_Est_Lines');
6677         END IF;
6678 
6679         --
6680         -- End API Body
6681         --
6682 
6683         -- Standard check of p_commit.
6684         IF Fnd_Api.To_Boolean(p_commit)
6685         THEN
6686             COMMIT WORK;
6687         END IF;
6688 
6689         -- Standard call to get message count and IF count is  get message info.
6690         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6691                                   p_data  => x_msg_data);
6692     EXCEPTION
6693         WHEN Fnd_Api.G_EXC_ERROR THEN
6694             ROLLBACK TO Convert_To_Est_Lines;
6695             x_return_status := Fnd_Api.G_RET_STS_ERROR;
6696 
6697             /*
6698             -- TO DO: Add seeded err message
6699             -- save message in fnd stack
6700             if (Fnd_Log.Level_Statement>= Fnd_Log.G_Current_Runtime_Level) then
6701                 FND_LOG.STRING(Fnd_Log.Level_Statement, lc_mod_name,
6702                                'Adding message err_name to FND_MSG stack');
6703             end if;
6704             FND_MESSAGE.SET_NAME('CSD','err_name');
6705             FND_MESSAGE.SET_TOKEN('toke_name', 'token_value');
6706             FND_MSG_PUB.ADD;
6707             */
6708             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6709                                       p_data  => x_msg_data);
6710 
6711             -- save message in debug log
6712             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
6713             THEN
6714                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
6715                                lc_mod_name,
6716                                'EXC_ERROR[' || x_msg_data || ']');
6717             END IF;
6718         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
6719             ROLLBACK TO Convert_To_Est_Lines;
6720             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6721 
6722             -- save message in fnd stack
6723             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6724             THEN
6725                 IF (Fnd_Log.Level_Statement >=
6726                    Fnd_Log.G_Current_Runtime_Level)
6727                 THEN
6728                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6729                                    lc_mod_name,
6730                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
6731                 END IF;
6732                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
6733             END IF;
6734             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6735                                       p_data  => x_msg_data);
6736 
6737             -- save message in debug log
6738             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
6739             THEN
6740                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
6741                                lc_mod_name,
6742                                'EXC_UNEXPECTED_ERROR[' || x_msg_data || ']');
6743             END IF;
6744         WHEN OTHERS THEN
6745             ROLLBACK TO Convert_To_Est_Lines;
6746             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6747 
6748             -- save message in fnd stack
6749             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6750             THEN
6751                 IF (Fnd_Log.Level_Statement >=
6752                    Fnd_Log.G_Current_Runtime_Level)
6753                 THEN
6754                     Fnd_Log.STRING(Fnd_Log.Level_Statement,
6755                                    lc_mod_name,
6756                                    'Adding message using FND_MSG_PUB.Add_Exc_Msg to FND_MSG stack');
6757                 END IF;
6758                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, lc_api_name);
6759             END IF;
6760             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6761                                       p_data  => x_msg_data);
6762 
6763             -- save message in debug log
6764             IF (Fnd_Log.Level_Exception >= Fnd_Log.G_Current_Runtime_Level)
6765             THEN
6766                 -- create a seeded message
6767                 Fnd_Log.STRING(Fnd_Log.Level_Exception,
6768                                lc_mod_name,
6769                                'SQL Message[' || SQLERRM || ']');
6770             END IF;
6771     END Convert_To_Est_Lines;
6772     --
6773     -- end swai 11.5.10
6774     --
6775     ----Begin change for 3931317, wrpper aPI forward port
6776     PROCEDURE debug(msg VARCHAR2) IS
6777     BEGIN
6778         IF (G_DEBUG_LEVEL >= 0)
6779         THEN
6780             Csd_Gen_Utility_Pvt.ADD(msg);
6781             --DBMS_OUTPUT.PUT_LINE(msg);
6782         END IF;
6783     END DEBUG;
6784 
6785     /*----------------------------------------------------------------------------*/
6786     /* procedure name: CREATE_ESTIMATE_HEADER                                     */
6787     /* description   : Wrapper procedure used to create estimate header           */
6788     /*   Updates repair order estimate approved flag and creates Depot estimate   */
6789     /*   header record with information like, summary, lead time etc              */
6790     /*----------------------------------------------------------------------------*/
6791 
6792     PROCEDURE CREATE_ESTIMATE_HEADER(p_api_version      IN NUMBER,
6793                                      p_init_msg_list    IN VARCHAR2,
6794                                      p_commit           IN VARCHAR2,
6795                                      p_validation_level IN NUMBER,
6796                                      x_return_status    OUT NOCOPY VARCHAR2,
6797                                      x_msg_count        OUT NOCOPY NUMBER,
6798                                      x_msg_data         OUT NOCOPY VARCHAR2,
6799                                      p_estimate_hdr_rec IN Csd_Repair_Estimate_Pub.ESTIMATE_HDR_REC,
6800                                      x_estimate_hdr_id      OUT NOCOPY NUMBER ) IS
6801         l_incident_id     NUMBER;
6802         l_tmp_count       NUMBER;
6803         l_repln_obj_Ver   NUMBER;
6804         l_repln_quantity  NUMBER;
6805         l_approval_Status VARCHAR2(30);
6806         l_return_status   VARCHAR2(30);
6807         l_msg_count       NUMBER;
6808         l_msg_Data        VARCHAR2(2000);
6809         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_ESTIMATE_HEADER';
6810         l_api_version CONSTANT NUMBER := 1.0;
6811 
6812         l_estimate_hdr_rec Csd_Repair_Estimate_Pub.ESTIMATE_HDR_REC;
6813         l_est_hdr_pvt_rec     Csd_Repair_Estimate_Pvt.REPAIR_ESTIMATE_REC;
6814     BEGIN
6815 
6816         IF (Fnd_Log.level_procedure >= Fnd_Log.g_current_runtime_level)
6817         THEN
6818             Fnd_Log.STRING(Fnd_Log.level_procedure,
6819                            'csd.plsql.csd_repair_Estimate_pvt.create_estimate_header.begin',
6820                            'Entering create_estimate_header');
6821         END IF;
6822         -- Standard Start of API savepoint
6823         SAVEPOINT CREATE_ESTIMATE_HEADER_PVT;
6824 
6825         -- Standard call to check for call compatibility.
6826         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
6827                                            p_api_version,
6828                                            l_api_name,
6829                                            G_PKG_NAME)
6830         THEN
6831             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
6832         END IF;
6833 
6834         -- Initialize message list if p_init_msg_list is set to TRUE.
6835         IF Fnd_Api.to_Boolean(p_init_msg_list)
6836         THEN
6837             Fnd_Msg_Pub.initialize;
6838         END IF;
6839 
6840         -- Initialize API return status to success
6841         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
6842 
6843         debug('Start of estiamte hdr creation for repair lineid[=' ||
6844               p_estimate_hdr_rec.repair_line_id || ']');
6845 
6846         l_estimate_hdr_rec := p_estimate_hdr_rec;
6847 
6848         csd_estimate_utils_pvt.validate_est_hdr_rec(p_estimate_hdr_rec => l_estimate_hdr_rec,
6849                                                 p_validation_level => p_validation_level);
6850 
6851         csd_estimate_utils_pvt.default_est_hdr_rec(l_estimate_hdr_rec);
6852 
6853         csd_estimate_utils_pvt.validate_defaulted_est_hdr(l_estimate_hdr_rec,
6854                                                       p_validation_level);
6855 
6856         --If the estiamte_status is accepted or rejected then update the
6857         -- repair order status.
6858         IF (l_estimate_hdr_rec.estimate_status = C_EST_STATUS_ACCEPTED)
6859         THEN
6860             l_approval_Status := C_REP_STATUS_APPROVED;
6861         ELSIF (l_estimate_hdr_rec.estimate_status = C_EST_STATUS_REJECTED)
6862         THEN
6863             l_approval_Status := C_REP_STATUS_REJECTED;
6864         END IF;
6865 
6866         IF (l_estimate_hdr_rec.estimate_status = C_EST_STATUS_ACCEPTED OR
6867            l_estimate_hdr_rec.estimate_status = C_EST_STATUS_REJECTED)
6868         THEN
6869 
6870             debug('status is accepted or rejected');
6871 
6872             IF (l_estimate_hdr_rec.estimate_reason_code IS NOT NULL AND NOT
6873                 Csd_Estimate_Utils_Pvt.VALIDATE_REASON(l_estimate_hdr_rec.estimate_reason_code,
6874                                                                                                                 l_estimate_hdr_rec.estimate_status))
6875             THEN
6876                 debug('Invalid estimate_reason_code[' ||
6877                       l_estimate_hdr_rec.estimate_reason_code || ']');
6878                 RAISE Fnd_Api.G_EXC_ERROR;
6879             END IF;
6880 
6881             Csd_Repairs_Grp.UPDATE_APPROVAL_STATUS(p_repair_line_id        => l_estimate_hdr_rec.repair_line_id,
6882                                                    p_new_approval_status   => l_approval_Status,
6883                                                    p_old_approval_status   => NULL,
6884                                                    p_quantity              => l_estimate_hdr_rec.repair_line_quantity,
6885                                                    p_org_contact_id        => NULL,
6886                                                    p_reason                => '',
6887                                                    p_object_version_number => l_estimate_hdr_rec.ro_object_version_number,
6888                                                    x_return_status         => l_return_status,
6889                                                    x_msg_count             => l_msg_count,
6890                                                    x_msg_data              => l_msg_data);
6891             debug('Updated ro status');
6892             IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
6893             THEN
6894                 debug('Updated ro status failed, x_msg_data[' ||
6895                       l_msg_data || ']');
6896                 RAISE Fnd_Api.G_EXC_ERROR;
6897             END IF;
6898 
6899         ELSE
6900             l_estimate_hdr_rec.estimate_reason_code := NULL;
6901         END IF;
6902         debug('creating estimate header');
6903 
6904         csd_estimate_utils_pvt.COPY_TO_EST_HDR_REC(l_estimate_hdr_rec,
6905                                                l_est_hdr_pvt_rec);
6906         Csd_Repair_Estimate_Pvt.create_repair_estimate(p_api_version      => 1.0,
6907                                                        p_commit           => Fnd_Api.G_FALSE,
6908                                                        p_init_msg_list    => Fnd_Api.G_FALSE,
6909                                                        p_validation_level => Fnd_Api.G_VALID_LEVEL_FULL,
6910                                                        x_estimate_rec     => l_est_hdr_pvt_rec,
6911                                                        x_estimate_id      => x_estimate_hdr_id,
6912                                                        x_return_status    => l_return_status,
6913                                                        x_msg_count        => l_msg_count,
6914                                                        x_msg_data         => l_msg_data);
6915 
6916         debug('after creating the estimate header');
6917 
6918         IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
6919         THEN
6920             debug('create estiamte header failed, x_msg_data[' ||
6921                   l_msg_data || ']');
6922             RAISE Fnd_Api.G_EXC_ERROR;
6923         END IF;
6924 
6925         -- Standard check of p_commit.
6926         IF Fnd_Api.To_Boolean(p_commit)
6927         THEN
6928             COMMIT WORK;
6929         END IF;
6930 
6931         IF (Fnd_Log.level_procedure >= Fnd_Log.g_current_runtime_level)
6932         THEN
6933             Fnd_Log.STRING(Fnd_Log.level_procedure,
6934                            'csd.plsql.csd_repair_Estimate_pvt.create_estimate_header.end',
6935                            'Leaving create_estimate_header');
6936         END IF;
6937 
6938         -- Standard call to get message count and IF count is  get message info.
6939         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6940                                   p_data  => x_msg_data);
6941     EXCEPTION
6942         WHEN Fnd_Api.G_EXC_ERROR THEN
6943             x_return_status := Fnd_Api.G_RET_STS_ERROR;
6944             ROLLBACK TO create_estimate_header_pvt;
6945             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6946                                       p_data  => x_msg_data);
6947             IF (Fnd_Log.level_error >= Fnd_Log.g_current_runtime_level)
6948             THEN
6949                 Fnd_Log.STRING(Fnd_Log.level_error,
6950                                'csd.plsql.csd_repair_estimate_pvt.create_estimate_header',
6951                                'EXC_ERROR[' || x_msg_data || ']');
6952             END IF;
6953         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
6954             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6955             ROLLBACK TO create_estimate_header_pvt;
6956             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6957                                       p_data  => x_msg_data);
6958             IF (Fnd_Log.level_exception >= Fnd_Log.g_current_runtime_level)
6959             THEN
6960                 Fnd_Log.STRING(Fnd_Log.level_exception,
6961                                'csd.plsql.csd_repair_estimate_pvt.create_estimate_header',
6962                                'EXC_UNEXP_ERROR[' || x_msg_data || ']');
6963             END IF;
6964         WHEN OTHERS THEN
6965             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
6966             ROLLBACK TO create_estimate_header_pvt;
6967             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
6968             THEN
6969                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
6970             END IF;
6971             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
6972                                       p_data  => x_msg_data);
6973             IF (Fnd_Log.level_exception >= Fnd_Log.g_current_runtime_level)
6974             THEN
6975                 Fnd_Log.STRING(Fnd_Log.level_exception,
6976                                'csd.plsql.csd_repair_estimate_pvt.create_estimate_header',
6977                                'SQL MEssage[' || SQLERRM || ']');
6978             END IF;
6979 
6980     END CREATE_ESTIMATE_HEADER;
6981 
6982     /*----------------------------------------------------------------------------*/
6983     /* procedure name: CREATE_ESTIMATE_LINE                                       */
6984     /* description   : private procedure used to create estimate line             */
6985     /*   Creates Depot estimate line record and submits                           */
6986     /*   based on some validations.                                               */
6987     /*----------------------------------------------------------------------------*/
6988 
6989     PROCEDURE CREATE_ESTIMATE_LINE(p_api_version       IN NUMBER,
6990                                    p_init_msg_list     IN VARCHAR2,
6991                                    p_commit            IN VARCHAR2,
6992 							p_validation_level  IN NUMBER,
6993                                    x_return_status     OUT NOCOPY VARCHAR2,
6994                                    x_msg_count         OUT NOCOPY NUMBER,
6995                                    x_msg_data          OUT NOCOPY VARCHAR2,
6996                                    p_estimate_line_rec IN Csd_Repair_Estimate_Pub.ESTIMATE_LINE_REC,
6997                                    x_estimate_line_id  OUT NOCOPY NUMBER) IS
6998 
6999         l_tmp_count      NUMBER;
7000         l_repair_type_id NUMBER;
7001         l_uom_Code       VARCHAR2(3);
7002         l_return_status  VARCHAR2(30);
7003         l_msg_count      NUMBER;
7004         l_msg_Data       VARCHAR2(2000);
7005         l_api_name    CONSTANT VARCHAR2(30) := 'CREATE_ESTIMATE_LINE';
7006         l_api_version CONSTANT NUMBER := 1.0;
7007         l_no_charge_flag   VARCHAR2(10);
7008         l_contract_line_id NUMBER;
7009 
7010         l_est_pvt_line_rec   CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_LINE_REC;
7011         l_estimate_line_rec Csd_Repair_Estimate_Pub.ESTIMATE_LINE_REC;
7012 
7013     BEGIN
7014 
7015         -- Standard Start of API savepoint
7016         SAVEPOINT CREATE_ESTIMATE_LINE_PVT;
7017 
7018         -- Standard call to check for call compatibility.
7019         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
7020                                            p_api_version,
7021                                            l_api_name,
7022                                            G_PKG_NAME)
7023         THEN
7024             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7025         END IF;
7026 
7027         -- Initialize message list if p_init_msg_list is set to TRUE.
7028         IF Fnd_Api.to_Boolean(p_init_msg_list)
7029         THEN
7030             Fnd_Msg_Pub.initialize;
7031         END IF;
7032 
7033         -- Initialize API return status to success
7034         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
7035 
7036         debug('Start of estimate line creation for estimate id[=' ||
7037               p_estimate_line_rec.repair_estimate_id || ']');
7038 
7039         IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level)
7040         THEN
7041             fnd_log.STRING(fnd_log.level_procedure,
7042                            'csd.plsql.csd_repair_estimate_pvt.create_estimate_line.begin',
7043                            'Entering create_estimate_line');
7044         END IF;
7045 
7046         l_estimate_line_rec := p_estimate_line_rec;
7047 
7048         csd_estimate_utils_pvt.validate_est_LINE_rec(l_estimate_line_rec,
7049                                                  p_validation_level);
7050 
7051         csd_estimate_utils_pvt.default_est_line_rec(l_estimate_line_rec);
7052 
7053         csd_estimate_utils_pvt.validate_defaulted_est_line(l_estimate_line_rec,
7054                                                        p_validation_level);
7055 
7056 --        csd_estimate_utils_pvt.copy_to_est_pvt_line_rec(l_estimate_line_rec,
7057 --                                                    l_est_pvt_line_rec);
7058 
7059         debug('Calling create estimate_lines...');
7060 
7061         create_repair_estimate_lines(p_api_version       => 1.0,
7062                                      p_commit            => Fnd_Api.G_FALSE,
7063                                      p_init_msg_list     => Fnd_Api.G_FALSE,
7064                                      p_validation_level  => Fnd_Api.G_VALID_LEVEL_FULL,
7065                                      x_estimate_line_rec => l_est_pvt_line_rec,
7066                                      x_estimate_line_id  => x_estimate_line_id,
7067                                      x_return_status     => l_return_status,
7068                                      x_msg_count         => l_msg_count,
7069                                      x_msg_data          => l_msg_data);
7070 
7071         IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
7072         THEN
7073             debug('create estimate_lines failed..');
7074             RAISE Fnd_Api.G_EXC_ERROR;
7075         END IF;
7076 
7077         -- Standard check of p_commit.
7078         IF Fnd_Api.To_Boolean(p_commit)
7079         THEN
7080             COMMIT WORK;
7081         END IF;
7082 
7083         -- Standard call to get message count and IF count is  get message info.
7084         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7085                                   p_data  => x_msg_data);
7086 
7087         IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level)
7088         THEN
7089             fnd_log.STRING(fnd_log.level_procedure,
7090                            'csd.plsql.csd_repair_estimate_pvt.create_estimate_line.end',
7091                            'leaving create_estimate_line');
7092         END IF;
7093     EXCEPTION
7094         WHEN Fnd_Api.G_EXC_ERROR THEN
7095             x_return_status := Fnd_Api.G_RET_STS_ERROR;
7096             ROLLBACK TO CREATE_ESTIMATE_LINE_PVT;
7097             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7098                                       p_data  => x_msg_data);
7099             IF (Fnd_Log.level_error >= Fnd_Log.g_current_runtime_level)
7100             THEN
7101                 Fnd_Log.STRING(Fnd_Log.level_error,
7102                                'csd.plsql.csd_repair_estimate_pvt.create_estimate_line',
7103                                'EXC_ERROR[' || x_msg_data || ']');
7104             END IF;
7105 
7106         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7107             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7108             ROLLBACK TO CREATE_ESTIMATE_LINE_PVT;
7109             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7110                                       p_data  => x_msg_data);
7111             IF (Fnd_Log.level_exception >= Fnd_Log.g_current_runtime_level)
7112             THEN
7113                 Fnd_Log.STRING(Fnd_Log.level_exception,
7114                                'csd.plsql.csd_repair_estimate_pvt.create_estimate_line',
7115                                'EXC_UNEXP_ERROR[' || x_msg_data || ']');
7116             END IF;
7117         WHEN OTHERS THEN
7118             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7119             ROLLBACK TO CREATE_ESTIMATE_LINE_PVT;
7120             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
7121             THEN
7122                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
7123             END IF;
7124             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7125                                       p_data  => x_msg_data);
7126             IF (Fnd_Log.level_exception >= Fnd_Log.g_current_runtime_level)
7127             THEN
7128                 Fnd_Log.STRING(Fnd_Log.level_exception,
7129                                'csd.plsql.csd_repair_estimate_pvt.create_estimate_line',
7130                                'SQL MEssage[' || SQLERRM || ']');
7131             END IF;
7132 
7133     END CREATE_ESTIMATE_LINE;
7134 
7135     /*----------------------------------------------------------------------------*/
7136     /* procedure name: UPDATE_ESTIMATE_HEADER                                     */
7137     /* description   : procedure used to update estimate header                  */
7138     /*   Updates repair order estimate approved flag and creates Depot estimate   */
7139     /*   header record with information like, summary, lead time etc              */
7140     /*  Change History  : Created 24-June-2005 by Vijay                          */
7141     /*----------------------------------------------------------------------------*/
7142     PROCEDURE UPDATE_ESTIMATE_HEADER(p_api_version           IN NUMBER,
7143                                      p_init_msg_list         IN VARCHAR2,
7144                                      p_commit                IN VARCHAR2,
7145 							  p_validation_level      IN NUMBER,
7146                                      x_return_status         OUT NOCOPY VARCHAR2,
7147                                      x_msg_count             OUT NOCOPY NUMBER,
7148                                      x_msg_data              OUT NOCOPY VARCHAR2,
7149                                      p_estimate_hdr_rec      IN Csd_Repair_Estimate_Pub.ESTIMATE_HDR_REC,
7150                                      x_object_version_number OUT NOCOPY NUMBER) IS
7151 
7152         l_return_status VARCHAR2(30);
7153         l_approval_Status VARCHAR2(30);
7154         l_msg_count     NUMBER;
7155         l_msg_Data      VARCHAR2(2000);
7156         l_api_name    CONSTANT VARCHAR2(30) := 'UPDATE_ESTIMATE_HEADER';
7157         l_api_version CONSTANT NUMBER := 1.0;
7158 
7159         l_est_pvt_hdr_Rec CSD_REPAIR_ESTIMATE_PVT.REPAIR_ESTIMATE_REC;
7160         l_estimate_hdr_rec Csd_Repair_Estimate_Pub.ESTIMATE_HDR_REC;
7161 
7162         l_est_status_changed BOOLEAN;
7163 	   l_est_hdr_id         NUMBER;
7164 
7165         CURSOR CUR_EST_HDR(p_estimate_header_id NUMBER) IS
7166             SELECT REPAIR_ESTIMATE_ID,
7167                    REPAIR_LINE_ID,
7168                    ESTIMATE_STATUS,
7169                    ESTIMATE_DATE,
7170                    WORK_SUMMARY,
7171                    PO_NUMBER,
7172                    LEAD_TIME,
7173                    LEAD_TIME_UOM,
7174                    CREATION_DATE,
7175                    CREATED_BY,
7176                    LAST_UPDATED_BY,
7177                    LAST_UPDATE_DATE,
7178                    LAST_UPDATE_LOGIN,
7179                    CONTEXT,
7180                    ATTRIBUTE1,
7181                    ATTRIBUTE2,
7182                    ATTRIBUTE3,
7183                    ATTRIBUTE4,
7184                    ATTRIBUTE5,
7185                    ATTRIBUTE6,
7186                    ATTRIBUTE7,
7187                    ATTRIBUTE8,
7188                    ATTRIBUTE9,
7189                    ATTRIBUTE10,
7190                    ATTRIBUTE11,
7191                    ATTRIBUTE12,
7192                    ATTRIBUTE13,
7193                    ATTRIBUTE14,
7194                    ATTRIBUTE15,
7195                    OBJECT_VERSION_NUMBER,
7196                    ESTIMATE_REASON_CODE
7197               FROM CSD_REPAIR_ESTIMATE
7198              WHERE REPAIR_ESTIMATE_ID = p_estimate_header_id;
7199 
7200     BEGIN
7201         -- Standard Start of API savepoint
7202         SAVEPOINT UPDATE_ESTIMATE_HEADER_PVT;
7203 
7204         -- Standard call to check for call compatibility.
7205         IF NOT Fnd_Api.Compatible_API_Call(l_api_version,
7206                                            p_api_version,
7207                                            l_api_name,
7208                                            G_PKG_NAME)
7209         THEN
7210             RAISE Fnd_Api.G_EXC_UNEXPECTED_ERROR;
7211         END IF;
7212 
7213         -- Initialize message list if p_init_msg_list is set to TRUE.
7214         IF Fnd_Api.to_Boolean(p_init_msg_list)
7215         THEN
7216             Fnd_Msg_Pub.initialize;
7217         END IF;
7218 
7219         -- Initialize API return status to success
7220         x_return_status := Fnd_Api.G_RET_STS_SUCCESS;
7221 
7222         debug('Start of update estimate header for estimate id[=' ||
7223               p_estimate_hdr_rec.repair_estimate_id || ']');
7224 
7225         IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level)
7226         THEN
7227             fnd_log.STRING(fnd_log.level_procedure,
7228                            'csd.plsql.csd_repair_estimate_pvt.update_estimate_header.begin',
7229                            'Entering update_estimate_header');
7230         END IF;
7231 
7232         l_estimate_hdr_rec := p_estimate_hdr_rec;
7233 
7234         OPEN CUR_EST_HDR(p_estimate_hdr_rec.repair_estimate_id);
7235         FETCH CUR_EST_HDR
7236             INTO l_est_pvt_hdr_Rec.repair_estimate_id,
7237 		  l_est_pvt_hdr_Rec.repair_line_id,
7238 		  l_est_pvt_hdr_Rec.estimate_status,
7239 		  l_est_pvt_hdr_Rec.estimate_date,
7240 		  l_est_pvt_hdr_Rec.work_summary,
7241 		  l_est_pvt_hdr_Rec.po_number,
7242 		  l_est_pvt_hdr_Rec.lead_time,
7243 		  l_est_pvt_hdr_Rec.lead_time_uom,
7244 		  l_est_pvt_hdr_Rec.creation_date,
7245 		  l_est_pvt_hdr_Rec.created_by,
7246 		  l_est_pvt_hdr_Rec.last_updated_by,
7247 		  l_est_pvt_hdr_Rec.last_update_date,
7248 		  l_est_pvt_hdr_Rec.last_update_login,
7249 		  l_est_pvt_hdr_Rec.context,
7250 		  l_est_pvt_hdr_Rec.attribute1,
7251 		  l_est_pvt_hdr_Rec.attribute2,
7252 		  l_est_pvt_hdr_Rec.attribute3,
7253 		  l_est_pvt_hdr_Rec.attribute4,
7254 		  l_est_pvt_hdr_Rec.attribute5,
7255 		  l_est_pvt_hdr_Rec.attribute6,
7256 		  l_est_pvt_hdr_Rec.attribute7,
7257 		  l_est_pvt_hdr_Rec.attribute8,
7258 		  l_est_pvt_hdr_Rec.attribute9,
7259 		  l_est_pvt_hdr_Rec.attribute10,
7260 		  l_est_pvt_hdr_Rec.attribute11,
7261 		  l_est_pvt_hdr_Rec.attribute12,
7262 		  l_est_pvt_hdr_Rec.attribute13,
7263 		  l_est_pvt_hdr_Rec.attribute14,
7264 		  l_est_pvt_hdr_Rec.attribute15,
7265 		  l_est_pvt_hdr_Rec.object_version_number,
7266 		  l_est_pvt_hdr_Rec.estimate_reason_code;
7267 
7268         IF (CUR_EST_HDR%NOTFOUND)
7269         THEN
7270             Fnd_Message.SET_NAME('CSD', 'CSD_INV_ESTIMATE_HEADER');
7271             Fnd_Msg_Pub.ADD;
7272             RAISE Fnd_Api.G_EXC_ERROR;
7273         END IF;
7274 
7275         IF (l_est_pvt_hdr_Rec.repair_line_id <>
7276            p_Estimate_hdr_Rec.repair_line_id)
7277         THEN
7278             Fnd_Message.SET_NAME('CSD', 'CSD_INV_ESTIMATE_INPUT');
7279             Fnd_Msg_Pub.ADD;
7280             RAISE Fnd_Api.G_EXC_ERROR;
7281         END IF;
7282     CLOSE CUR_EST_HDR;
7283         l_est_status_changed := FALSE;
7284         IF (p_Estimate_hdr_Rec.estimate_status IS NOT NULL AND
7285            p_Estimate_hdr_Rec.estimate_status <>
7286            l_est_pvt_hdr_Rec.estimate_status)
7287         THEN
7288             l_est_status_changed := TRUE;
7289         END IF;
7290 
7291         IF (l_est_status_changed AND
7292            p_estimate_hdr_rec.estimate_status = C_EST_STATUS_ACCEPTED OR
7293            p_estimate_hdr_rec.estimate_status = C_EST_STATUS_REJECTED)
7294         THEN
7295 
7296             debug('status is accepted or rejected');
7297 
7298             IF (l_est_pvt_hdr_rec.estimate_reason_code IS NOT NULL AND NOT
7299                 csd_estimate_utils_pvt.VALIDATE_REASON(l_estimate_hdr_rec.estimate_reason_code,
7300                                                                                                                 l_estimate_hdr_rec.estimate_status))
7301             THEN
7302                 debug('Invalid estimate_reason_code[' ||
7303                       l_estimate_hdr_rec.estimate_reason_code || ']');
7304                 RAISE Fnd_Api.G_EXC_ERROR;
7305             END IF;
7306 
7307             Csd_Repairs_Grp.UPDATE_APPROVAL_STATUS(p_repair_line_id        => l_estimate_hdr_rec.repair_line_id,
7308                                                    p_new_approval_status   => l_approval_Status,
7309                                                    p_old_approval_status   => NULL,
7310                                                    p_quantity              => l_estimate_hdr_rec.repair_line_quantity,
7311                                                    p_org_contact_id        => NULL,
7312                                                    p_reason                => '',
7313                                                    p_object_version_number => l_estimate_hdr_rec.ro_object_version_number,
7314                                                    x_return_status         => l_return_status,
7315                                                    x_msg_count             => l_msg_count,
7316                                                    x_msg_data              => l_msg_data);
7317             debug('Updated ro status');
7318             IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
7319             THEN
7320                 debug('Updated ro status failed, x_msg_data[' ||
7321                       l_msg_data || ']');
7322                 RAISE Fnd_Api.G_EXC_ERROR;
7323             END IF;
7324 
7325         ELSE
7326             l_estimate_hdr_rec.estimate_reason_code := NULL;
7327         END IF;
7328 
7329         csd_estimate_utils_pvt.COPY_TO_EST_HDR_REC_UPD(l_estimate_hdr_rec,
7330                                                    l_est_pvt_hdr_rec);
7331 
7332         Csd_Repair_Estimate_Pvt.update_repair_estimate(p_api_version      => 1.0,
7333                                                        p_commit           => Fnd_Api.G_FALSE,
7334                                                        p_init_msg_list    => Fnd_Api.G_FALSE,
7335                                                        p_validation_level => Fnd_Api.G_VALID_LEVEL_FULL,
7336                                                        x_estimate_rec     => l_est_pvt_hdr_rec,
7337                                                        x_return_status    => l_return_status,
7338                                                        x_msg_count        => l_msg_count,
7339                                                        x_msg_data         => l_msg_data);
7340 
7341         debug('after creating the estimate header');
7342         x_object_version_number := l_estimate_hdr_rec.object_version_number;
7343 
7344         IF (l_return_status <> Fnd_Api.G_RET_STS_SUCCESS)
7345         THEN
7346             debug('update estiamte header failed, x_msg_data[' ||
7347                   l_msg_data || ']');
7348             RAISE Fnd_Api.G_EXC_ERROR;
7349         END IF;
7350 
7351         -- Standard check of p_commit.
7352         IF Fnd_Api.To_Boolean(p_commit)
7353         THEN
7354             COMMIT WORK;
7355         END IF;
7356 
7357         -- Standard call to get message count and IF count is  get message info.
7358         Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7359                                   p_data  => x_msg_data);
7360 
7361         IF (fnd_log.level_procedure >= fnd_log.g_current_runtime_level)
7362         THEN
7363             fnd_log.STRING(fnd_log.level_procedure,
7364                            'csd.plsql.csd_repair_estimate_pvt.update_estimate_header.end',
7365                            'leaving update_estimate_header');
7366         END IF;
7367     EXCEPTION
7368         WHEN Fnd_Api.G_EXC_ERROR THEN
7369             x_return_status := Fnd_Api.G_RET_STS_ERROR;
7370             ROLLBACK TO UPDATE_ESTIMATE_HEADER_PVT;
7371             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7372                                       p_data  => x_msg_data);
7373             IF (Fnd_Log.level_error >= Fnd_Log.g_current_runtime_level)
7374             THEN
7375                 Fnd_Log.STRING(Fnd_Log.level_error,
7376                                'csd.plsql.csd_repair_estimate_pvt.update_estimate_header',
7377                                'EXC_ERROR[' || x_msg_data || ']');
7378             END IF;
7379 
7380         WHEN Fnd_Api.G_EXC_UNEXPECTED_ERROR THEN
7381             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7382             ROLLBACK TO UPDATE_ESTIMATE_HEADER_PVT;
7383             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7384                                       p_data  => x_msg_data);
7385             IF (Fnd_Log.level_exception >= Fnd_Log.g_current_runtime_level)
7386             THEN
7387                 Fnd_Log.STRING(Fnd_Log.level_exception,
7388                                'csd.plsql.csd_repair_estimate_pvt.update_estimate_header',
7389                                'EXC_UNEXP_ERROR[' || x_msg_data || ']');
7390             END IF;
7391         WHEN OTHERS THEN
7392             x_return_status := Fnd_Api.G_RET_STS_UNEXP_ERROR;
7393             Rollback TO UPDATE_ESTIMATE_HEADER_PVT;
7394             IF Fnd_Msg_Pub.Check_Msg_Level(Fnd_Msg_Pub.G_MSG_LVL_UNEXP_ERROR)
7395             THEN
7396                 Fnd_Msg_Pub.Add_Exc_Msg(G_PKG_NAME, l_api_name);
7397             END IF;
7398             Fnd_Msg_Pub.Count_And_Get(p_count => x_msg_count,
7399                                       p_data  => x_msg_data);
7400             IF (Fnd_Log.level_exception >= Fnd_Log.g_current_runtime_level)
7401             THEN
7402                 Fnd_Log.STRING(Fnd_Log.level_exception,
7403                                'csd.plsql.csd_repair_estimate_pvt.update_estimate_header',
7404                                'SQL MEssage[' || SQLERRM || ']');
7405             END IF;
7406 
7407     END UPDATE_ESTIMATE_HEADER;
7408 
7409     /*----------------------------------------------------------------------------*/
7410     /* procedure name: UPDATE_ESTIMATE_LINE                                       */
7411     /* description   :  procedure used to update  estimate line                  */
7412     /*   Updates Depot estimate line record and submits                           */
7413     /*   based on some validations.                                               */
7414     /*  Change History  : Created 24-June-2005 by Vijay                           */
7415     /*----------------------------------------------------------------------------*/
7416 
7417     PROCEDURE UPDATE_ESTIMATE_LINE(p_api_version           IN NUMBER,
7418                                    p_init_msg_list         IN VARCHAR2,
7419                                    p_commit                IN VARCHAR2,
7420                                    p_validation_level      IN NUMBER,
7421                                    x_return_status         OUT NOCOPY VARCHAR2,
7422                                    x_msg_count             OUT NOCOPY NUMBER,
7423                                    x_msg_data              OUT NOCOPY VARCHAR2,
7424                                    p_estimate_line_rec     IN Csd_Repair_Estimate_Pub.ESTIMATE_LINE_REC,
7425                                    x_object_version_number OUT NOCOPY NUMBER) IS
7426     BEGIN
7427         NULL;
7428     END UPDATE_ESTIMATE_LINE;
7429 
7430 END Csd_Repair_Estimate_Pvt;