[Home] [Help]
PACKAGE BODY: APPS.GL_ADI_ACCT_TYPE_CONV_PKG
Source
1 PACKAGE BODY GL_ADI_ACCT_TYPE_CONV_PKG as
2 /* $Header: gluadicb.pls 120.5 2005/05/05 01:34:42 kvora ship $ */
3
4 ---
5 --- PUBLIC FUNCTIONS
6 ---
7
8 --
9 -- Procedure
10 -- get_accounted_amount
11 -- Purpose
12 -- Get accounted amount after applying account type specific conversion.
13 -- This program assumes that currencies with an EMU fixed rate will not
14 -- be passed as parameters. ADI will call a different API in that case.
15 -- The accounted amount is returned with the correct precision and mau.
16 -- If the p_conversion_type is passed, the program attempts to find the
17 -- conversion rate. If p_conversion_type is User, the passed p_conversion_
18 -- rate is used to calculate the accounted amount.
19 -- History
20 -- 19-APR-2000 K Vora Created
21 -- Arguments
22 -- p_ledger_id Ledger Id
23 -- p_reporting_ledger_id Preferred Reporting Ledger Id
24 -- p_functional_currency Functional Currency
25 -- p_journal_currency Entered Currency
26 -- p_conversion_type Currency Conversion Type (Optional)
27 -- p_bs_conversion_type Balance Sheet or User Conversion Type
28 -- p_is_conversion_type Income Statement Account Conversion Type
29 -- p_conversion_date Currency Conversion Date
30 -- p_conversion_rate Currency Conversion Rate (Optional)
31 -- p_source_name Journal Source
32 -- p_category_name Journal Category
33 -- p_max_roll_days Rollback Days from Profile Option
34 -- p_code_combination_id Code Combination Id
35 -- p_entered_amount Entered Amount
36 -- p_accounted_amount Returns - Accounted Amount
37 -- p_error_msg Returns - Error Message, 240 chars max
38 --
39 -- Example
40 -- gl_adi_acct_type_conv_pkg.get_accounted_amount(101, 102, 'USD', 'ITL',
41 -- '', '1205', '1204', to_date('31-MAR-1999', 'DD-MON-YYYY'),
42 -- '', 'Payables', 'Other', 31, 34567, 100.00, NULL, NULL),
43
44 PROCEDURE get_accounted_amount(
45 p_ledger_id NUMBER,
46 p_reporting_ledger_id NUMBER,
47 p_functional_currency VARCHAR2,
48 p_journal_currency VARCHAR2,
49 p_conversion_type VARCHAR2,
50 p_bs_conversion_type VARCHAR2,
51 p_is_conversion_type VARCHAR2,
52 p_conversion_date DATE,
53 p_conversion_rate NUMBER,
54 p_source_name VARCHAR2,
55 p_category_name VARCHAR2,
56 p_max_roll_days NUMBER,
57 p_code_combination_id NUMBER,
58 p_entered_amount NUMBER,
59 p_accounted_amount OUT NOCOPY NUMBER,
60 p_error_msg OUT NOCOPY VARCHAR2) IS
61
62 l_conversion_type VARCHAR2(30);
63 l_account_type VARCHAR2(1);
64 l_other_source VARCHAR2(1);
65 l_other_category VARCHAR2(1);
66 l_conv_rate_denom NUMBER;
67 l_conv_rate_numer NUMBER;
68 l_max_roll_days NUMBER;
69 i NUMBER;
70
71 CURSOR get_rollback_days_c IS
72 SELECT decode(lrl.alc_no_rate_action_code,
73 'REPORT_ERROR', 0, p_max_roll_days)
74 FROM gl_ledger_relationships lrl,
75 gl_je_inclusion_rules inc
76 WHERE lrl.source_ledger_id = p_ledger_id
77 AND lrl.target_ledger_id = p_reporting_ledger_id
78 AND lrl.target_ledger_category_code = 'ALC'
79 AND lrl.relationship_type_code in ('ADJUST', 'JOURNAL', 'SUBLEDGER')
80 AND lrl.application_id = 101
81 AND lrl.relationship_enabled_flag = 'Y'
82 AND inc.je_rule_set_id = lrl.gl_je_conversion_set_id
83 AND inc.include_flag = 'Y'
84 AND ((inc.je_source_name = p_source_name AND
85 inc.je_category_name = p_category_name)
86 OR (inc.je_source_name = p_source_name AND
87 inc.je_category_name = 'Other')
88 OR (inc.je_source_name = 'Other' AND
89 inc.je_category_name = p_category_name)
90 OR (inc.je_source_name = 'Other' AND
91 inc.je_category_name = 'Other'))
92 ORDER BY decode(inc.je_source_name, 'Other', 2, 0)
93 + decode(inc.je_category_name, 'Other', 1, 0);
94
95 BEGIN
96
97 IF (p_conversion_type IS NULL) THEN
98 SELECT account_type
99 INTO l_account_type
100 FROM gl_code_combinations
101 WHERE code_combination_id = p_code_combination_id;
102
103 IF ((l_account_type = 'R') OR
104 (l_account_type = 'E')) THEN
105 l_conversion_type := p_is_conversion_type;
106 ELSE
107 l_conversion_type := p_bs_conversion_type;
108 END IF;
109 ELSE
110 l_conversion_type := p_conversion_type;
111 END IF;
112
113 IF (l_conversion_type <> 'User') THEN
114 l_max_roll_days := -1;
115
116 OPEN get_rollback_days_c;
117 WHILE (l_max_roll_days = -1) LOOP
118 FETCH get_rollback_days_c INTO l_max_roll_days;
119 IF (get_rollback_days_c%NOTFOUND) THEN
120 IF (l_max_roll_days IS NULL) THEN
121 l_max_roll_days := -1;
122 END IF;
123 CLOSE get_rollback_days_c;
124 EXIT;
125 END IF;
126 END LOOP;
127
128 IF (l_max_roll_days = -1) THEN
129 l_max_roll_days := 0;
130 END IF;
131
132 l_conv_rate_numer := gl_currency_api.get_closest_rate_numerator_sql(
133 p_journal_currency,
134 p_functional_currency,
135 p_conversion_date,
136 l_conversion_type,
137 l_max_roll_days);
138
139 l_conv_rate_denom := gl_currency_api.get_closest_rate_denom_sql(
140 p_journal_currency,
141 p_functional_currency,
142 p_conversion_date,
143 l_conversion_type,
144 l_max_roll_days);
145
146 ELSE -- Conversion Type is User
147 l_conv_rate_numer := p_conversion_rate;
148 l_conv_rate_denom := 1;
149 END IF;
150
151 IF ((l_conv_rate_numer > 0) AND
152 (l_conv_rate_denom > 0)) THEN
153
154 SELECT round((p_entered_amount * l_conv_rate_numer
155 / l_conv_rate_denom)
156 / nvl(curr.minimum_accountable_unit, power(10, -curr.precision)))
157 * nvl(curr.minimum_accountable_unit, power(10, -curr.precision))
158 INTO p_accounted_amount
159 FROM fnd_currencies curr
160 WHERE curr.currency_code = p_functional_currency;
161 ELSE
162 p_error_msg := FND_MESSAGE.get_string('SQLGL', 'R_PPOS0056');
163 p_accounted_amount := NULL;
164 END IF;
165
166 EXCEPTION WHEN OTHERS THEN
167 i := SQLCODE;
168 p_error_msg := substrb(SQLERRM, 1, 150);
169
170 END get_accounted_amount;
171
172 END GL_ADI_ACCT_TYPE_CONV_PKG;