DBA Data[Home] [Help]

PACKAGE BODY: APPS.IGC_CC_MC_MAIN_HST_PVT

Source


1 PACKAGE BODY IGC_CC_MC_MAIN_HST_PVT as
2 /* $Header: IGCCMMHB.pls 120.3.12000000.4 2007/10/19 06:19:35 smannava ship $  */
3 
4  G_PKG_NAME CONSTANT VARCHAR2(30):= 'IGC_CC_MC_MAIN_HST_PVT';
5  g_debug_flag        VARCHAR2(1) := 'N' ;
6 
7 /* ================================================================================
8                          PROCEDURE Insert_Row => IGC_CC_MC_HEADER_HISTORY
9    ===============================================================================*/
10 
11 PROCEDURE get_rsobs_Headers(
12    p_api_version               IN       NUMBER,
13    p_init_msg_list             IN       VARCHAR2 := FND_API.G_FALSE,
14    p_commit                    IN       VARCHAR2 := FND_API.G_FALSE,
15    p_validation_level          IN       NUMBER := FND_API.G_VALID_LEVEL_FULL,
16    X_return_status             OUT NOCOPY      VARCHAR2,
17    x_msg_count                 OUT NOCOPY      NUMBER,
18    x_msg_data                  OUT NOCOPY      VARCHAR2,
19    p_CC_Header_Id              IN       NUMBER,
20    p_Set_Of_Books_Id           IN       NUMBER,
21    l_Application_Id            IN       NUMBER,
22    p_org_id                    IN       NUMBER,
23    l_Conversion_Date           IN       DATE,
24    p_CC_Version_num            IN       NUMBER,
25    p_CC_Version_Action         IN       VARCHAR2
26 ) IS
27 
28    l_sob_list            gl_mc_info.r_sob_list := gl_mc_info.r_sob_list();
29    l_row_count           NUMBER;
30    l_FROM_CURR           varchar2(10);
31    l_TO_CURR             varchar2(10);
32    l_Conversion_Rate     Number;
33    l_Conversion_Type     VARCHAR2(30);
34    l_rsob_id             GL_ALC_LEDGER_RSHIPS_V.LEDGER_ID%TYPE;
35    l_rate_exists         VARCHAR2(1);
36    l_api_version         NUMBER := 1.0;
37    l_api_name            VARCHAR2(30) := 'GET_RSOBS_HEADERS';
38    l_return_status       VARCHAR2(1);
39    l_row_id              VARCHAR2(18);
40 
41    /* Commented below query and added one below during r12 MRC uptake for bug#6341012*/
42   /* CURSOR c_conversion_type IS
43      SELECT conversion_type
44        FROM gl_mc_reporting_options
45       WHERE primary_set_of_books_id   = p_Set_Of_Books_Id
46         AND reporting_set_of_books_id = l_rsob_id
47         AND ORG_ID                    = p_Org_Id
48         AND application_id            = l_Application_Id; */
49  CURSOR c_conversion_type IS
50      SELECT ALC_DEFAULT_CONV_RATE_TYPE
51        FROM GL_ALC_LEDGER_RSHIPS_V
52       WHERE primary_ledger_id   = p_Set_Of_Books_Id
53         AND ledger_id = l_rsob_id
54        -- AND ORG_ID                    = p_Org_Id
55         AND application_id            = l_Application_Id;
56 BEGIN
57 
58    SAVEPOINT get_rsobs_Headers_PT;
59 
60    IF NOT FND_API.COMPATIBLE_API_CALL ( l_api_version,
61                                         p_api_version,
62                                         l_api_name,
63                                         G_PKG_NAME) THEN
64       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
65    END IF;
66 
67    IF FND_API.to_Boolean (p_init_msg_list) THEN
68       FND_MSG_PUB.initialize;
69    END IF;
70 
71    X_return_status := FND_API.G_RET_STS_SUCCESS;
72 
73 -- -------------------------------------------------------------------------
74 -- Obtain all sets of books associated to the Primary set of books ID
75 -- received from the caller.
76 -- -------------------------------------------------------------------------
77    gl_mc_info.get_associated_sobs ( p_Set_Of_Books_Id,
78                                     l_Application_Id,
79                                     p_org_id,
80                                     NULL,
81                                     l_sob_list);
82 
83    l_row_count := l_sob_list.count;
84 
85 -- -------------------------------------------------------------------------
86 -- Loop through all sets of books retrived and determine what the Primary
87 -- set of books currency has been defined to be.
88 -- -------------------------------------------------------------------------
89    FOR Rec in 1..l_row_count LOOP
90 
91       IF l_sob_list(Rec).r_sob_type = 'P' then
92          l_FROM_CURR :=  l_sob_list(Rec).r_sob_curr;
93       END IF;
94 
95    END LOOP;
96 
97 -- -------------------------------------------------------------------------
98 -- Loop through all the set of books retrieved if there were any defined.
99 -- -------------------------------------------------------------------------
100    FOR Rec1 in 1..l_row_count LOOP
101 
102 -- -------------------------------------------------------------------------
103 -- Check to make sure that the Reporting set of books is being checked and
104 -- not the Primary set of books.
105 -- -------------------------------------------------------------------------
106       IF (l_sob_list(rec1).r_sob_type = 'R') THEN
107 
108          l_rsob_id := l_sob_list(rec1).r_sob_id;
109          l_TO_CURR := l_sob_list(rec1).r_sob_curr;
110 
111 -- -------------------------------------------------------------------------
112 -- Obtain the conversion type for the reporting set of books.
113 -- -------------------------------------------------------------------------
114          OPEN c_conversion_type;
115          FETCH c_conversion_type
116           INTO l_Conversion_Type;
117          CLOSE c_conversion_type;
118 
119 -- -------------------------------------------------------------------------
120 -- Check to see if the conversion rate exists or not.
121 -- -------------------------------------------------------------------------
122          l_rate_exists := gl_currency_api.rate_exists ( l_FROM_CURR,
123                                                         l_TO_CURR,
124                                                         l_Conversion_Date,
125                                                         l_Conversion_Type
126                                                       );
127 
128 -- ------------------------------------------------------------------------
129 -- If the rate exists then obtain the rate to be inserted for the
130 -- reporting set of books.
131 -- ------------------------------------------------------------------------
132          IF (l_rate_exists = 'Y') THEN
133             l_Conversion_Rate := GL_CURRENCY_API.GET_RATE (l_FROM_CURR,
134                                                            l_TO_CURR,
135                                                            l_Conversion_Date,
136                                                            l_Conversion_Type
137                                                           );
138 
139 -- -----------------------------------------------------------------------
140 -- insert the MRC History record for the appropriate MRC record
141 -- for the reporting set of books.
142 -- -----------------------------------------------------------------------
143             IGC_CC_MC_HEADER_HST_PKG.Insert_Row (
144                              l_api_version,
145                              FND_API.G_FALSE,
146                              FND_API.G_FALSE,
147                              FND_API.G_VALID_LEVEL_FULL,
148                              l_return_status,
149                              X_msg_count,
150                              X_msg_data,
151                              l_row_id,
152                              p_CC_Header_Id,
153                              l_sob_list(rec1).r_sob_id,
154                              p_CC_Version_num,
155                              p_CC_Version_Action,
156                              l_Conversion_Type,
157                              l_Conversion_Date,
158                              l_conversion_Rate
159                             );
160 
161 -- ------------------------------------------------------------------
162 -- Make sure that the insertion was a success
163 -- ------------------------------------------------------------------
164             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
165                RAISE FND_API.G_EXC_ERROR;
166             END IF;
167 
168          END IF;  -- Rate exists
169 
170       END IF;  -- Reporting set of books
171 
172    END LOOP;  -- Loop for associated sets of books
173 
174 -- ------------------------------------------------------------------------
175 -- Only commit the information if the caller has requested it to be.
176 -- ------------------------------------------------------------------------
177    IF FND_API.To_Boolean ( p_commit ) THEN
178       COMMIT WORK;
179    END IF;
180 
181 -- ------------------------------------------------------------------------
182 -- Make sure that the cursor used is closed upon exit
183 -- ------------------------------------------------------------------------
184    IF (c_conversion_type%ISOPEN) THEN
185       CLOSE c_conversion_type;
186    END IF;
187 
188    FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
189                               p_data  => X_msg_data);
190 
191    RETURN;
192 
193 EXCEPTION
194 
195     WHEN FND_API.G_EXC_ERROR THEN
196 
197        ROLLBACK TO get_rsobs_Headers_PT;
198        X_return_status := FND_API.G_RET_STS_ERROR;
199        IF (c_conversion_type%ISOPEN) THEN
200           CLOSE c_conversion_type;
201        END IF;
202        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
203                                   p_data  => X_msg_data);
204 
205     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
206 
207        ROLLBACK TO get_rsobs_Headers_PT;
208        X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
209        IF (c_conversion_type%ISOPEN) THEN
210           CLOSE c_conversion_type;
211        END IF;
212        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
213                                   p_data  => X_msg_data);
214 
215     WHEN OTHERS THEN
216 
217        ROLLBACK TO get_rsobs_Headers_PT;
218        X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
219        IF (c_conversion_type%ISOPEN) THEN
220           CLOSE c_conversion_type;
221        END IF;
222 
223        IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
224           FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,
225                                    l_api_name);
226        END if;
227 
228        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
229                                   p_data  => X_msg_data);
230 
231 END get_rsobs_Headers;
232 
233 
234 /* ================================================================================
235                          PROCEDURE Insert_Row => IGC_CC_MC_ACCT_LINE_HISTORY
236    ===============================================================================*/
237 
238 PROCEDURE get_rsobs_Acct_Lines(
239    p_api_version               IN       NUMBER,
240    p_init_msg_list             IN       VARCHAR2 := FND_API.G_FALSE,
241    p_commit                    IN       VARCHAR2 := FND_API.G_FALSE,
242    p_validation_level          IN       NUMBER := FND_API.G_VALID_LEVEL_FULL,
243    X_return_status             OUT NOCOPY      VARCHAR2,
244    x_msg_count                 OUT NOCOPY      NUMBER,
245    x_msg_data                  OUT NOCOPY      VARCHAR2,
246    p_CC_Acct_Line_Id           IN       NUMBER,
247    p_Set_Of_Books_Id           IN       NUMBER,
248    l_Application_Id            IN       NUMBER,
249    p_org_id                    IN       NUMBER,
250    l_Conversion_Date           IN       DATE,
251    p_CC_Acct_Func_Amt          IN       NUMBER,
252    p_CC_Acct_Encmbrnc_Amt      IN       NUMBER,
253    p_CC_Acct_Version_Num       IN       NUMBER,
254    p_CC_Acct_Version_Action    IN       VARCHAR2,
255    p_cc_func_withheld_amt      IN       NUMBER
256 ) IS
257 
258    l_sob_list             gl_mc_info.r_sob_list := gl_mc_info.r_sob_list();
259    l_row_count            NUMBER;
260    l_FROM_CURR            varchar2(10);
261    l_TO_CURR              varchar2(10);
262    l_Conversion_Rate      Number;
263    l_Conversion_Type      VARCHAR2(30);
264    l_CC_Acct_Func_Amt     NUMBER;
265    l_CC_Acct_Encmbrnc_Amt NUMBER;
266    l_CC_Func_Withheld_Amt NUMBER;
267    l_rsob_id             GL_ALC_LEDGER_RSHIPS_V.LEDGER_ID%TYPE;
268    l_rate_exists          VARCHAR2(1);
269    l_api_version          CONSTANT NUMBER   :=  1.0;
270    l_api_name             VARCHAR2(30)      := 'GET_RSOBS_ACCT_LINES';
271    l_return_status        VARCHAR2(1);
272    l_row_id               VARCHAR2(18);
273 
274 /* Commented below query and added one below during r12 MRC uptake for bug#6341012*/
275 
276      /* CURSOR c_conversion_type IS
277      SELECT conversion_type
278        FROM gl_mc_reporting_options
279       WHERE primary_set_of_books_id   = p_Set_Of_Books_Id
280         AND reporting_set_of_books_id = l_rsob_id
281         AND ORG_ID                    = p_Org_Id
282         AND application_id            = l_Application_Id; */
283  CURSOR c_conversion_type IS
284      SELECT ALC_DEFAULT_CONV_RATE_TYPE
285        FROM GL_ALC_LEDGER_RSHIPS_V
286       WHERE primary_ledger_id   = p_Set_Of_Books_Id
287         AND ledger_id = l_rsob_id
288         --AND ORG_ID                    = p_Org_Id
289         AND application_id            = l_Application_Id;
290 BEGIN
291 
292    SAVEPOINT get_rsobs_Acct_Lines_PT;
293 
294    IF NOT FND_API.COMPATIBLE_API_CALL ( l_api_version,
295                                         p_api_version,
296                                         l_api_name,
297                                         G_PKG_NAME) THEN
298       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
299    END IF;
300 
301    IF FND_API.to_Boolean (p_init_msg_list) THEN
302       FND_MSG_PUB.initialize;
303    END IF;
304 
305    X_return_status := FND_API.G_RET_STS_SUCCESS;
306 
307 -- -------------------------------------------------------------------------
308 -- Obtain all sets of books associated to the Primary set of books ID
309 -- received from the caller.
310 -- -------------------------------------------------------------------------
311    gl_mc_info.get_associated_sobs ( p_Set_Of_Books_Id,
312                                     l_Application_Id,
313                                     p_org_id,
314                                     NULL,
315                                     l_sob_list);
316 
317    l_row_count := l_sob_list.count;
318 
319 -- -------------------------------------------------------------------------
320 -- Loop through all sets of books retrived and determine what the Primary
321 -- set of books currency has been defined to be.
322 -- -------------------------------------------------------------------------
323    FOR Rec in 1..l_row_count LOOP
324 
325       IF (l_sob_list(Rec).r_sob_type = 'P') THEN
326          l_FROM_CURR :=  l_sob_list(Rec).r_sob_curr;
327       END IF;
328 
329    END LOOP;
330 
331 -- -------------------------------------------------------------------------
332 -- Loop through all the set of books retrieved if there were any defined.
333 -- -------------------------------------------------------------------------
334    FOR Rec1 in 1..l_row_count LOOP
335 
336 -- -------------------------------------------------------------------------
337 -- Check to make sure that the Reporting set of books is being checked and
338 -- not the Primary set of books.
339 -- -------------------------------------------------------------------------
340       IF (l_sob_list(rec1).r_sob_type = 'R') THEN
341 
342          l_rsob_id := l_sob_list(rec1).r_sob_id;
343          l_TO_CURR := l_sob_list(rec1).r_sob_curr;
344 
345 -- -------------------------------------------------------------------------
346 -- Obtain the conversion type for the reporting set of books.
347 -- -------------------------------------------------------------------------
348          OPEN c_conversion_type;
349          FETCH c_conversion_type
350           INTO l_Conversion_Type;
351          CLOSE c_conversion_type;
352 
353 -- -------------------------------------------------------------------------
354 -- Check to see if the conversion rate exists or not.
355 -- -------------------------------------------------------------------------
356          l_rate_exists := gl_currency_api.rate_exists ( l_FROM_CURR,
357                                                         l_TO_CURR,
358                                                         l_Conversion_Date,
359                                                         l_Conversion_Type
360                                                       );
361 
362 -- ------------------------------------------------------------------------
363 -- If the rate exists then obtain the rate to be inserted for the
364 -- reporting set of books.
365 -- ------------------------------------------------------------------------
366          IF (l_rate_exists = 'Y') THEN
367 
368             l_Conversion_Rate :=  GL_CURRENCY_API.GET_RATE (l_FROM_CURR,
369                                                             l_TO_CURR,
370                                                             l_Conversion_Date,
371                                                             l_Conversion_Type
372                                                            );
373 
374 
375             l_CC_Acct_Func_Amt  :=  GL_CURRENCY_API.CONVERT_AMOUNT (l_FROM_CURR,
376                                                                     l_TO_CURR,
377                                                                     l_CONVERSION_DATE,
378                                                                     l_CONVERSION_TYPE,
379                                                                     p_CC_Acct_Func_Amt
380                                                                    );
381 
382             l_CC_Acct_Encmbrnc_Amt := GL_CURRENCY_API.CONVERT_AMOUNT (l_FROM_CURR,
383                                                                       l_TO_CURR,
384                                                                       l_CONVERSION_DATE,
385                                                                       l_CONVERSION_TYPE,
386                                                                       p_CC_Acct_Encmbrnc_Amt
387                                                                      );
388 
389             l_CC_Func_Withheld_Amt := GL_CURRENCY_API.CONVERT_AMOUNT (l_FROM_CURR,
390                                                                       l_TO_CURR,
391                                                                       l_CONVERSION_DATE,
392                                                                       l_CONVERSION_TYPE,
393                                                                       p_CC_Func_Withheld_Amt
394                                                                      );
395 
396 -- -----------------------------------------------------------------------
397 -- Insert the appropriate MRC history record for the reporting set of
398 -- books being processed.
399 -- -----------------------------------------------------------------------
400             IGC_CC_MC_ACCT_LINE_HST_PKG.Insert_Row (
401                              l_api_version,
402                              FND_API.G_FALSE,
403                              FND_API.G_FALSE,
404                              FND_API.G_VALID_LEVEL_FULL,
405                              l_return_status,
406                              X_msg_count,
407                              X_msg_data,
408                              l_row_id,
409                              p_CC_Acct_Line_Id,
410                              l_sob_list(rec1).r_sob_id,
411                              l_CC_Acct_Func_Amt,
412                              l_CC_Acct_Encmbrnc_Amt,
413                              p_CC_Acct_Version_Num,
414                              p_CC_Acct_Version_Action,
415                              l_Conversion_Type,
416                              l_Conversion_Date,
417                              l_conversion_Rate,
418                              l_cc_func_withheld_amt
419                             );
420 
421 -- ------------------------------------------------------------------
422 -- Make sure that the insertion was a success
423 -- ------------------------------------------------------------------
424             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
425                RAISE FND_API.G_EXC_ERROR;
426             END IF;
427 
428          END IF;  -- Rate exists
429 
430       END IF;  -- Reporting set of books
431 
432    END LOOP;  -- Loop for all associated sets of books.
433 
434 -- ------------------------------------------------------------------------
435 -- Only commit the information if the caller has requested it to be.
436 -- ------------------------------------------------------------------------
437    IF FND_API.To_Boolean ( p_commit ) THEN
438       COMMIT WORK;
439    END IF;
440 
441 -- ------------------------------------------------------------------------
442 -- Make sure that the cursor used is closed upon exit
443 -- ------------------------------------------------------------------------
444    IF (c_conversion_type%ISOPEN) THEN
445       CLOSE c_conversion_type;
446    END IF;
447 
448    FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
449                               p_data  => X_msg_data);
450 
451    RETURN;
452 
453 EXCEPTION
454 
455     WHEN FND_API.G_EXC_ERROR THEN
456 
457        ROLLBACK TO get_rsobs_Acct_Lines_PT;
458        X_return_status := FND_API.G_RET_STS_ERROR;
459        IF (c_conversion_type%ISOPEN) THEN
460           CLOSE c_conversion_type;
461        END IF;
462        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
463                                   p_data  => X_msg_data);
464 
465     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
466 
467        ROLLBACK TO get_rsobs_Acct_Lines_PT;
468        X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
469        IF (c_conversion_type%ISOPEN) THEN
470           CLOSE c_conversion_type;
471        END IF;
472        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
473                                   p_data  => X_msg_data);
474 
475     WHEN OTHERS THEN
476 
477        ROLLBACK TO get_rsobs_Acct_Lines_PT;
478        X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
479        IF (c_conversion_type%ISOPEN) THEN
480           CLOSE c_conversion_type;
481        END IF;
482 
483        IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
484           FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,
485                                    l_api_name);
486        END if;
487 
488        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
489                                   p_data  => X_msg_data);
490 
491 END get_rsobs_Acct_Lines;
492 
493 
494 /* ================================================================================
495                          PROCEDURE Insert_Row => IGC_CC_MC_DET_PF_HISTORY
496    ===============================================================================*/
497 
498 PROCEDURE get_rsobs_DET_PF (
499    p_api_version               IN       NUMBER,
500    p_init_msg_list             IN       VARCHAR2 := FND_API.G_FALSE,
501    p_commit                    IN       VARCHAR2 := FND_API.G_FALSE,
502    p_validation_level          IN       NUMBER := FND_API.G_VALID_LEVEL_FULL,
503    X_return_status             OUT NOCOPY      VARCHAR2,
504    x_msg_count                 OUT NOCOPY      NUMBER,
505    x_msg_data                  OUT NOCOPY      VARCHAR2,
506    p_CC_DET_PF_Line_Id         IN       NUMBER,
507    p_Set_Of_Books_Id           IN       NUMBER,
508    l_Application_Id            IN       NUMBER,
509    p_org_id                    IN       NUMBER,
510    l_Conversion_Date           IN       DATE,
511    p_CC_Det_Pf_Func_Amt        IN       NUMBER,
512    p_CC_Det_Pf_ENCMBRNC_AMT    IN       NUMBER,
513    p_Det_PF_Version_Num        IN       NUMBER,
514    p_Det_PF_Version_Action     IN       VARCHAR2
515 ) IS
516 
517    l_sob_list                   gl_mc_info.r_sob_list := gl_mc_info.r_sob_list();
518    l_row_count                  NUMBER;
519    l_FROM_CURR                  varchar2(10);
520    l_TO_CURR                    varchar2(10);
521    l_Conversion_Rate            Number;
522    l_Conversion_Type            VARCHAR2(30);
523    l_CC_DET_PF_Func_Amt         NUMBER;
524    l_CC_DET_PF_ENCMBRNC_AMT     NUMBER;
525    l_rsob_id                   GL_ALC_LEDGER_RSHIPS_V.LEDGER_ID%TYPE;
526    l_rate_exists                VARCHAR2(1);
527    l_api_name                   VARCHAR2(30) := 'GET_RSOBS_DET_PF';
528    l_api_version                CONSTANT NUMBER         :=  1.0;
529    l_return_status              VARCHAR2(1);
530    l_row_id                     VARCHAR2(18);
531 /* Commented below query and added one below during r12 MRC uptake for bug#6341012*/
532      /* CURSOR c_conversion_type IS
533      SELECT conversion_type
534        FROM gl_mc_reporting_options
535       WHERE primary_set_of_books_id   = p_Set_Of_Books_Id
536         AND reporting_set_of_books_id = l_rsob_id
537         AND ORG_ID                    = p_Org_Id
538         AND application_id            = l_Application_Id; */
539  CURSOR c_conversion_type IS
540      SELECT ALC_DEFAULT_CONV_RATE_TYPE
541        FROM GL_ALC_LEDGER_RSHIPS_V
542       WHERE primary_ledger_id   = p_Set_Of_Books_Id
543         AND ledger_id = l_rsob_id
544        -- AND ORG_ID                    = p_Org_Id
545         AND application_id            = l_Application_Id;
546 BEGIN
547 
548    SAVEPOINT get_rsobs_DET_PF_PT;
549 
550    IF NOT FND_API.COMPATIBLE_API_CALL ( l_api_version,
551                                         p_api_version,
552                                         l_api_name,
553                                         G_PKG_NAME) THEN
554       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
555    END IF;
556 
557    IF FND_API.to_Boolean (p_init_msg_list) THEN
558       FND_MSG_PUB.initialize;
559    END IF;
560 
561    X_return_status := FND_API.G_RET_STS_SUCCESS;
562 
563 -- -------------------------------------------------------------------------
564 -- Obtain all sets of books associated to the Primary set of books ID
565 -- received from the caller.
566 -- -------------------------------------------------------------------------
567    gl_mc_info.get_associated_sobs ( p_Set_Of_Books_Id,
568                                     l_Application_Id,
569                                     p_org_id,
570                                     NULL,
571                                     l_sob_list);
572 
573    l_row_count := l_sob_list.count;
574 
575 -- -------------------------------------------------------------------------
576 -- Loop through all sets of books retrived and determine what the Primary
577 -- set of books currency has been defined to be.
578 -- -------------------------------------------------------------------------
579    FOR Rec in 1..l_row_count LOOP
580 
581       IF (l_sob_list(Rec).r_sob_type = 'P') THEN
582          l_FROM_CURR :=  l_sob_list(Rec).r_sob_curr;
583       END IF;
584 
585    END LOOP;
586 
587 -- -------------------------------------------------------------------------
588 -- Loop through all the set of books retrieved if there were any defined.
589 -- -------------------------------------------------------------------------
590    FOR Rec1 in 1..l_row_count LOOP
591 
592       IF (l_sob_list(rec1).r_sob_type = 'R') THEN
593          l_rsob_id := l_sob_list(rec1).r_sob_id;
594          l_TO_CURR := l_sob_list(rec1).r_sob_curr;
595 
596 -- -------------------------------------------------------------------------
597 -- Obtain the conversion type for the reporting set of books.
598 -- -------------------------------------------------------------------------
599          OPEN c_conversion_type;
600          FETCH c_conversion_type
601           INTO l_Conversion_Type;
602          CLOSE c_conversion_type;
603 
604 -- -------------------------------------------------------------------------
605 -- Check to see if the conversion rate exists or not.
606 -- -------------------------------------------------------------------------
607          l_rate_exists := gl_currency_api.rate_exists (l_FROM_CURR,
608                                                        l_TO_CURR,
609                                                        l_Conversion_Date,
610                                                        l_Conversion_Type
611                                                       );
612 
613 -- ------------------------------------------------------------------------
614 -- If the rate exists then obtain the rate to be inserted for the
615 -- reporting set of books.
616 -- ------------------------------------------------------------------------
617          IF (l_rate_exists = 'Y') THEN
618 
619             l_Conversion_Rate := GL_CURRENCY_API.GET_RATE (l_FROM_CURR,
620                                                            l_TO_CURR,
621                                                            l_Conversion_Date,
622                                                            l_Conversion_Type
623                                                           );
624 
625             l_CC_DET_PF_Func_Amt := GL_CURRENCY_API.CONVERT_AMOUNT (l_FROM_CURR,
626                                                                     l_TO_CURR,
627                                                                     l_CONVERSION_DATE,
628                                                                     l_CONVERSION_TYPE,
629                                                                     p_CC_DET_PF_Func_AMT
630                                                                    );
631 
632             l_CC_DET_PF_ENCMBRNC_AMT := GL_CURRENCY_API.CONVERT_AMOUNT (l_FROM_CURR,
633                                                                         l_TO_CURR,
634                                                                         l_CONVERSION_DATE,
635                                                                         l_CONVERSION_TYPE,
636                                                                         p_CC_DET_PF_ENCMBRNC_AMT
637                                                                        );
638 
639 -- -----------------------------------------------------------------------
640 -- Insert the appropriate MRC history record for the reporting set
641 -- of books being processed.
642 -- -----------------------------------------------------------------------
643             IGC_CC_MC_DET_PF_HST_PKG.Insert_Row (
644                              l_api_version,
645                              FND_API.G_FALSE,
646                              FND_API.G_FALSE,
647                              FND_API.G_VALID_LEVEL_FULL,
648                              l_return_status,
649                              X_msg_count,
650                              X_msg_data,
651                              l_row_id,
652                              p_CC_DET_PF_Line_Id,
653                              l_sob_list(rec1).r_sob_id,
654                              l_CC_DET_PF_Func_Amt,
655                              l_CC_DET_PF_ENCMBRNC_AMT,
656                              p_Det_PF_Version_Num,
657                              p_Det_PF_Version_Action,
658                              l_Conversion_Type,
659                              l_Conversion_Date,
660                              l_conversion_Rate
661                             );
662 
663 -- ------------------------------------------------------------------
664 -- Make sure that the insertion was a success
665 -- ------------------------------------------------------------------
666             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
667                RAISE FND_API.G_EXC_ERROR;
668             END IF;
669 
670          END IF;  -- Rate exists
671 
672       END IF;  -- Reporting set of books
673 
674    END LOOP;  -- Loop for all associated sets of books
675 
676 -- ------------------------------------------------------------------------
677 -- Only commit the information if the caller has requested it to be.
678 -- ------------------------------------------------------------------------
679    IF FND_API.To_Boolean ( p_commit ) THEN
680       COMMIT WORK;
681    END iF;
682 
683 -- ------------------------------------------------------------------------
684 -- Make sure that the cursor used is closed upon exit
685 -- ------------------------------------------------------------------------
686    IF (c_conversion_type%ISOPEN) THEN
687       CLOSE c_conversion_type;
688    END IF;
689 
690    FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
691                               p_data  => X_msg_data);
692 
693    RETURN;
694 
695 EXCEPTION
696 
697     WHEN FND_API.G_EXC_ERROR THEN
698        ROLLBACK TO SAVEPOINT get_rsobs_DET_PF_PT;
699        X_return_status := FND_API.G_RET_STS_ERROR;
700        IF (c_conversion_type%ISOPEN) THEN
701           CLOSE c_conversion_type;
702        END IF;
703        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
704                                   p_data  => X_msg_data);
705 
706     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
707        ROLLBACK TO SAVEPOINT get_rsobs_DET_PF_PT;
708        X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
709        IF (c_conversion_type%ISOPEN) THEN
710           CLOSE c_conversion_type;
711        END IF;
712        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
713                                   p_data  => X_msg_data);
714 
715     WHEN OTHERS THEN
716        ROLLBACK TO SAVEPOINT get_rsobs_DET_PF_PT;
717        X_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
718        IF (c_conversion_type%ISOPEN) THEN
719           CLOSE c_conversion_type;
720        END IF;
721 
722        IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
723           FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,
724                                    l_api_name);
725        END if;
726 
727        FND_MSG_PUB.Count_And_Get (p_count => X_msg_count,
728                                   p_data  => X_msg_data);
729 
730 END get_rsobs_DET_PF;
731 
732 END IGC_CC_MC_MAIN_HST_PVT;