1 PACKAGE BODY cs_chmc_pkg as
2 /*$Header: csxchmcb.pls 115.3.1158.2 2003/03/13 02:56:36 aseethep ship $*/
3
4 PROCEDURE convert_amount(
5 p_from_currency IN varchar2,
6 p_amount IN number,
7 p_conversion_date IN date,
8 p_conversion_type IN varchar2,
9 p_user_rate IN number,
10 x_converted_amount OUT number) IS
11 p_set_of_books_id number;
12 s_to_currency varchar2(30);
13 s_conversion_date date;
14 s_conversion_type varchar2(30);
15 f_currency_code varchar2(30);
16 result number;
17 x_to_currency varchar2(30);
18 INVALID_USER_CURRENCY_CODE exception;
19 INVALID_MC_CONVERSION_TYPE exception;
20 NO_RATE exception;
21 INVALID_CURRENCY exception;
22 INVALID_USER_RATE exception;
23
24 BEGIN
25
26 -- get the set_of_books_id
27
28 p_set_of_books_id := fnd_profile.value('GL_SET_OF_BKS_ID');
29
30 -- Get functional currency using the set of books id.
31
32 SELECT currency_code
33 INTO f_currency_code
34 FROM GL_SETS_OF_BOOKS
35 WHERE set_of_books_id = p_set_of_books_id;
36
37 IF f_currency_code is NULL THEN
38 RAISE INVALID_USER_CURRENCY_CODE;
39 ELSE
40 s_to_currency := f_currency_code;
41 END IF;
42
43 IF p_from_currency = s_to_currency THEN
44 x_converted_amount:=p_amount;
45 x_to_currency :=s_to_currency;
46 return;
47 END IF;
48
49 IF p_conversion_date IS NULL THEN
50 s_conversion_date := sysdate;
51 ELSE
52 s_conversion_date := p_conversion_date;
53 END IF;
54
55 IF p_conversion_type IS NULL THEN
56 s_conversion_type:=fnd_profile.value('CS_MC_CONVERSION_TYPE');
57 IF s_conversion_type IS NULL THEN
58 RAISE INVALID_MC_CONVERSION_TYPE;
59 END IF;
60 ELSE
61 s_conversion_type := p_conversion_type;
62 END IF;
63
64 IF s_conversion_type = 'User' THEN
65 IF p_user_rate IS NULL THEN
66 RAISE INVALID_USER_RATE;
67 END IF;
68 END IF;
69
70 -- call the gl package to convert the amount
71
72 result := gl_currency_api.convert_closest_amount_sql
73 (p_from_currency,s_to_currency,s_conversion_date,s_conversion_type,
74 p_user_rate,p_amount,30);
75
76 IF result = -1 THEN
77 RAISE NO_RATE;
78 ELSIF result = -2 THEN
79 RAISE INVALID_CURRENCY;
80 END IF;
81
82 x_converted_amount := result;
83 x_to_currency:=s_to_currency;
84
85 EXCEPTION WHEN INVALID_USER_CURRENCY_CODE THEN
86 fnd_message.set_name('CS','CS_INVALID_USER_CURRENCY_CODE');
87 app_exception.raise_exception;
88 WHEN INVALID_MC_CONVERSION_TYPE THEN
89 fnd_message.set_name('CS','CS_INVALID_MC_CONVERSION_TYPE');
90 app_exception.raise_exception;
91 WHEN NO_RATE THEN
92 fnd_message.set_name('CS','CS_NO_RATE');
93 fnd_message.set_token('CODE1',p_from_currency);
94 fnd_message.set_token('CODE2',s_to_currency);
95 fnd_message.set_token('DATE',s_conversion_date);
96 fnd_message.set_token('TYPE',s_conversion_type);
97 app_exception.raise_exception;
98 WHEN INVALID_CURRENCY THEN
99 fnd_message.set_name('CS','CS_INVALID_CURRENCY');
100 fnd_message.set_token('CODE1',p_from_currency);
101 fnd_message.set_token('CODE2',s_to_currency);
102 app_exception.raise_exception;
103 WHEN INVALID_USER_RATE THEN
104 fnd_message.set_name('CS','CS_INVALID_USER_RATE');
105 app_exception.raise_exception;
106
107 END convert_amount;
108
109 END cs_chmc_pkg;