[Home] [Help]
PACKAGE BODY: APPS.IGI_IAC_REVAL_ACCOUNTING
Source
1 PACKAGE BODY IGI_IAC_REVAL_ACCOUNTING AS
2 -- $Header: igiiarab.pls 120.10.12000000.2 2007/10/16 14:22:33 sharoy ship $
3
4
5 --===========================FND_LOG.START=====================================
6
7 g_state_level NUMBER;
8 g_proc_level NUMBER;
9 g_event_level NUMBER;
10 g_excep_level NUMBER;
11 g_error_level NUMBER;
12 g_unexp_level NUMBER;
13 g_path VARCHAR2(100);
14
15 --===========================FND_LOG.END=======================================
16
17 l_rec igi_iac_revaluation_rates%rowtype; -- create this for quicker access via sql navigator
18
19 procedure create_acctg_entry ( p_dr_ccid in number
20 , p_cr_ccid in number
21 , p_amount in number
22 , p_dr_adjust_type in varchar2
23 , p_cr_adjust_type in varchar2
24 , p_set_of_books_id in number
25 , p_det_balances in igi_iac_det_balances%rowtype
26 , p_transfer_to_gl_flag in varchar2
27 , p_event_id in number --R12 uptake
28 )
29 is
30 l_rowid varchar2(30);
31 l_units_assigned number;
32 l_dr_ccid number;
33 l_cr_ccid number;
34 l_cr_report_ccid number;
35 l_dr_report_ccid number;
36 l_amount number;
37 l_dr_adjust_type varchar2(50);
38 l_cr_adjust_type varchar2(50);
39
40 l_path varchar2(100);
41 begin
42 l_rowid := null;
43 l_dr_ccid := p_dr_ccid;
44 l_cr_ccid := p_cr_ccid;
45 l_cr_report_ccid := Null;
46 l_dr_report_ccid := Null;
47 l_amount := p_amount;
48 l_dr_adjust_type := p_dr_adjust_type;
49 l_cr_adjust_type := p_cr_adjust_type;
50 l_path := g_path||'create_acctg_entry';
51
52 if p_amount = 0 then
53 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+amount is 0, accounting entries skipped');
54 return;
55 end if;
56
57 select units_assigned
58 into l_units_assigned
59 from fa_distribution_history
60 where book_type_code = p_det_balances.book_type_code
61 and asset_id = p_det_balances.asset_id
62 and distribution_id = p_det_balances.distribution_id
63 ;
64
65 /* begin bug 2448787 */
66 if p_amount < 0 then
67 l_dr_ccid := p_cr_ccid;
68 l_cr_ccid := p_dr_ccid;
69 l_amount := abs(p_amount);
70 l_dr_adjust_type := p_cr_adjust_type;
71 l_cr_adjust_type := p_dr_adjust_type;
72 else
73 l_dr_ccid := p_dr_ccid;
74 l_cr_ccid := p_cr_ccid;
75 l_amount := p_amount;
76 l_dr_adjust_type := p_dr_adjust_type;
77 l_cr_adjust_type := p_cr_adjust_type;
78 end if;
79 /* end bug 2448787 */
80
81 If (l_dr_adjust_type='REVAL RESERVE' OR l_dr_adjust_type='OP EXPENSE') THEN
82 l_cr_report_ccid := l_dr_ccid;
83 l_dr_report_ccid := Null;
84 Elsif (l_cr_adjust_type='REVAL RESERVE' OR l_cr_adjust_type='OP EXPENSE') THEN
85 l_cr_report_ccid := Null;
86 l_dr_report_ccid := l_cr_ccid;
87 Else
88 l_cr_report_ccid := Null;
89 l_dr_report_ccid := Null;
90 End if;
91
92
93 IGI_IAC_ADJUSTMENTS_PKG.insert_row (
94 x_rowid => l_rowid,
95 x_adjustment_id => p_det_balances.adjustment_id,
96 x_book_type_code => p_det_balances.book_type_code,
97 x_code_combination_id => l_dr_ccid,
98 x_set_of_books_id => p_set_of_books_id,
99 x_dr_cr_flag => 'DR',
100 x_amount => l_amount,
101 x_adjustment_type => l_dr_adjust_type,
102 x_transfer_to_gl_flag => p_transfer_to_gl_flag,
103 x_units_assigned => l_units_assigned,
104 x_asset_id => p_det_balances.asset_id,
105 x_distribution_id => p_det_balances.distribution_id,
106 x_period_counter => p_det_balances.period_counter,
107 X_adjustment_offset_type => l_cr_adjust_type,
108 X_report_ccid => l_cr_ccid,
109 x_mode => 'R',
110 x_event_id => p_event_id
111 ) ;
112
113 IGI_IAC_ADJUSTMENTS_PKG.insert_row (
114 x_rowid => l_rowid,
115 x_adjustment_id => p_det_balances.adjustment_id,
116 x_book_type_code => p_det_balances.book_type_code,
117 x_code_combination_id => l_cr_ccid,
118 x_set_of_books_id => p_set_of_books_id,
119 x_dr_cr_flag => 'CR',
120 x_amount => l_amount,
121 x_adjustment_type => l_cr_adjust_type,
122 x_transfer_to_gl_flag => p_transfer_to_gl_flag,
123 x_units_assigned => l_units_assigned,
124 x_asset_id => p_det_balances.asset_id,
125 x_distribution_id => p_det_balances.distribution_id,
126 x_period_counter => p_det_balances.period_counter,
127 X_adjustment_offset_type => l_dr_adjust_type,
128 X_report_ccid => l_dr_ccid,
129 x_mode => 'R',
130 x_event_id => p_event_id
131 ) ;
132
133 end;
134
135 function create_iac_acctg
136 ( fp_det_balances in IGI_IAC_DET_BALANCES%ROWTYPE
137 , fp_create_acctg_flag in boolean
138 , p_event_id in number --R12 uptake
139 )
140 return boolean is
141 l_rowid rowid;
142 l_sob_id number;
143 l_coa_id number;
144 l_currency varchar2(30);
145 l_precision number;
146 l_dr_ccid gl_code_combinations.code_combination_id%type;
147 l_cr_ccid gl_code_combinations.code_combination_id%type;
148 l_revl_rsv_ccid gl_code_combinations.code_combination_id%type;
149 l_blog_rsv_ccid gl_code_combinations.code_combination_id%TYPE;
150 l_op_exp_ccid gl_code_combinations.code_combination_id%TYPE;
151 l_gen_fund_ccid gl_code_combinations.code_combination_id%TYPE;
152 l_asset_cost_ccid gl_code_combinations.code_combination_id%TYPE;
153 l_deprn_rsv_ccid gl_code_combinations.code_combination_id%TYPE;
154 l_deprn_exp_ccid gl_code_combinations.code_combination_id%TYPE;
155 l_transfer_to_gl_flag varchar2(1);
156 l_create_extra_entry varchar2(1);
157 l_ignore_expense_entry varchar2(1);
158
159 l_path varchar2(100);
160
161 procedure check_ccid ( p_ccid_desc in varchar2) is
162 l_path varchar2(100);
163 begin
164 l_path := g_path||'creck_ccid';
165 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation for '||p_ccid_desc||' failed');
166 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'error create_iac_acctg');
167 end;
168 begin
169 l_create_extra_entry := 'N';
170 l_ignore_expense_entry := 'N';
171
172 l_path := g_path||'create_iac_acctg';
173
174 declare
175 cursor c_txn_type is
176 select transaction_type_code
177 from igi_iac_transaction_headers
178 where adjustment_id = fp_det_balances.adjustment_id
179 ;
180 begin
181 for l_type in c_txn_type loop
182 if l_type.transaction_type_code in ( 'ADDITION','RECLASS') then
183 l_transfer_to_gl_flag := 'Y';
184 l_create_extra_entry := 'Y';
185 if l_type.transaction_type_code = 'RECLASS'
186 and nvl(fp_det_balances.active_flag,'Y') = 'N'
187 then
188 l_ignore_expense_entry := 'Y';
189 else
190 l_ignore_expense_entry := 'N';
191 end if;
192 else
193 l_create_extra_entry := 'N';
194 l_transfer_to_gl_flag := 'N';
195 l_ignore_expense_entry := 'N';
196 end if;
197 end loop;
198 exception when others then
199 l_transfer_to_gl_flag := 'N';
200 end;
201 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'begin create_iac_acctg');
202 if not fp_create_acctg_flag then
203 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation not allowed');
204 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'end create_iac_acctg');
205 return true;
206 end if;
207 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation get gl information');
208 if not IGI_IAC_COMMON_UTILS.GET_BOOK_GL_INFO
209 ( X_BOOK_TYPE_CODE => fp_det_balances.book_type_code
210 , SET_OF_BOOKS_ID => l_sob_id
211 , CHART_OF_ACCOUNTS_ID => l_coa_id
212 , CURRENCY => l_currency
213 , PRECISION => l_precision
214 )
215 then
216 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation unable to get gl info');
217 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'end create_iac_acctg');
218 return false;
219 end if;
220 --
221 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation get all accounts');
222 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+distribution id '|| fp_det_balances.distribution_id);
223 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
224 ( X_book_type_code => fp_det_balances.book_type_code
225 , X_asset_id => fp_det_balances.asset_id
226 , X_distribution_id => fp_det_balances.distribution_id
227 , X_account_type => 'REVAL_RESERVE_ACCT'
228 , account_ccid => l_revl_rsv_ccid
229 )
230 THEN
231 check_ccid ( 'reval reserve');
232 return false;
233 END IF;
234 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
235 ( X_book_type_code => fp_det_balances.book_type_code
236 , X_asset_id => fp_det_balances.asset_id
237 , X_distribution_id => fp_det_balances.distribution_id
238 , X_account_type => 'BACKLOG_DEPRN_RSV_ACCT'
239 , account_ccid => l_blog_rsv_ccid
240 )
241 THEN
242 check_ccid ( 'backlog deprn reserve');
243 return false;
244 END IF;
245 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
246 ( X_book_type_code => fp_det_balances.book_type_code
247 , X_asset_id => fp_det_balances.asset_id
248 , X_distribution_id => fp_det_balances.distribution_id
249 , X_account_type => 'OPERATING_EXPENSE_ACCT'
250 , account_ccid => l_op_exp_ccid
251 )
252 THEN
253 check_ccid ( 'operating account');
254 return false;
255 END IF;
256 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
257 ( X_book_type_code => fp_det_balances.book_type_code
258 , X_asset_id => fp_det_balances.asset_id
259 , X_distribution_id => fp_det_balances.distribution_id
260 , X_account_type => 'GENERAL_FUND_ACCT'
261 , account_ccid => l_gen_fund_ccid
262 )
263 THEN
264 check_ccid ( 'general fund account');
265 return false;
266 END IF;
267 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
268 ( X_book_type_code => fp_det_balances.book_type_code
269 , X_asset_id => fp_det_balances.asset_id
270 , X_distribution_id => fp_det_balances.distribution_id
271 , X_account_type => 'ASSET_COST_ACCT'
272 , account_ccid => l_asset_cost_ccid
273 )
274 THEN
275 check_ccid ( 'asset cost account');
276 return false;
277 END IF;
278 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
279 ( X_book_type_code => fp_det_balances.book_type_code
280 , X_asset_id => fp_det_balances.asset_id
281 , X_distribution_id => fp_det_balances.distribution_id
282 , X_account_type => 'DEPRN_RESERVE_ACCT'
283 , account_ccid => l_deprn_rsv_ccid
284 )
285 THEN
286 check_ccid ( 'deprn reserve account');
287 return false;
288 END IF;
289 IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
290 ( X_book_type_code => fp_det_balances.book_type_code
291 , X_asset_id => fp_det_balances.asset_id
292 , X_distribution_id => fp_det_balances.distribution_id
293 , X_account_type => 'DEPRN_EXPENSE_ACCT'
294 , account_ccid => l_deprn_exp_ccid
295 )
296 THEN
297 check_ccid ( 'deprn reserve account');
298 return false;
299 END IF;
300
301 begin
302 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation cost vs reval reserve');
303 create_acctg_entry ( p_dr_ccid => l_asset_cost_ccid
304 , p_cr_ccid => l_revl_rsv_ccid
305 , p_amount => fp_det_balances.reval_reserve_cost
306 , p_dr_adjust_type => 'COST'
307 , p_cr_adjust_type => 'REVAL RESERVE'
308 , p_set_of_books_id => l_sob_id
309 , p_det_balances => fp_det_balances
310 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
311 , p_event_id => p_event_id
312 );
313 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation reval reserve vs backlog reserve');
314 create_acctg_entry ( p_dr_ccid => l_revl_rsv_ccid
315 , p_cr_ccid => l_blog_rsv_ccid
316 , p_amount => fp_det_balances.reval_reserve_backlog
317 , p_dr_adjust_type => 'REVAL RESERVE'
318 , p_cr_adjust_type => 'BL RESERVE'
319 , p_set_of_books_id => l_sob_id
320 , p_det_balances => fp_det_balances
321 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
322 , p_event_id => p_event_id
323 );
324 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation reval reserve vs gen fund');
325 create_acctg_entry ( p_dr_ccid => l_revl_rsv_ccid
326 , p_cr_ccid => l_gen_fund_ccid
327 , p_amount => fp_det_balances.reval_reserve_gen_fund
328 , p_dr_adjust_type => 'REVAL RESERVE'
329 , p_cr_adjust_type => 'GENERAL FUND'
330 , p_set_of_books_id => l_sob_id
331 , p_det_balances => fp_det_balances
332 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
333 , p_event_id => p_event_id
334 );
335 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation op expense vs cost :neg figures');
336 create_acctg_entry ( p_cr_ccid => l_op_exp_ccid
337 , p_dr_ccid => l_asset_cost_ccid
338 , p_amount => fp_det_balances.operating_acct_cost
339 , p_cr_adjust_type => 'OP EXPENSE'
340 , p_dr_adjust_type => 'COST'
341 , p_set_of_books_id => l_sob_id
342 , p_det_balances => fp_det_balances
343 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
344 , p_event_id => p_event_id
345 );
346 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation backlog vs op expense :neg figures');
347 create_acctg_entry ( p_cr_ccid => l_blog_rsv_ccid
348 , p_dr_ccid => l_op_exp_ccid
349 , p_amount => fp_det_balances.operating_acct_backlog
350 , p_cr_adjust_type => 'BL RESERVE'
351 , p_dr_adjust_type => 'OP EXPENSE'
352 , p_set_of_books_id => l_sob_id
353 , p_det_balances => fp_det_balances
354 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
355 , p_event_id => p_event_id
356 );
357 /* If reclass and old dist, supress the ytd deprn creation */
358 if l_ignore_expense_entry = 'Y' then
359 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'end acctg creation');
360 return true;
361 end if;
362 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation deprn reserve vs deprn expense');
363 create_acctg_entry ( p_cr_ccid => l_deprn_rsv_ccid
364 , p_dr_ccid => l_deprn_exp_ccid
365 , p_amount => fp_det_balances.deprn_ytd
366 , p_dr_adjust_type => 'EXPENSE'
367 , p_cr_adjust_type => 'RESERVE'
368 , p_set_of_books_id => l_sob_id
369 , p_det_balances => fp_det_balances
370 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
371 , p_event_id => p_event_id
372 );
373 if l_create_extra_entry = 'Y' then
374 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'+acctg creation (catchup) deprn reserve vs deprn expense');
375 create_acctg_entry ( p_cr_ccid => l_deprn_rsv_ccid
376 , p_dr_ccid => l_deprn_exp_ccid
377 , p_amount => fp_det_balances.deprn_reserve - fp_det_balances.deprn_ytd
378 , p_dr_adjust_type => 'EXPENSE'
379 , p_cr_adjust_type => 'RESERVE'
380 , p_set_of_books_id => l_sob_id
381 , p_det_balances => fp_det_balances
382 , p_transfer_to_gl_flag => l_transfer_to_gl_flag
383 , p_event_id => p_event_id
384 );
385 end if;
386 end;
387 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'end acctg creation');
388 return true;
389 end;
390 BEGIN
391 --===========================FND_LOG.START=====================================
392 g_state_level := FND_LOG.LEVEL_STATEMENT;
393 g_proc_level := FND_LOG.LEVEL_PROCEDURE;
394 g_event_level := FND_LOG.LEVEL_EVENT;
395 g_excep_level := FND_LOG.LEVEL_EXCEPTION;
396 g_error_level := FND_LOG.LEVEL_ERROR;
397 g_unexp_level := FND_LOG.LEVEL_UNEXPECTED;
398 g_path := 'IGI.PLSQL.igiiarab.IGI_IAC_REVAL_ACCOUNTING.';
399 --===========================FND_LOG.END=======================================
400
401 END;