[Home] [Help]
PACKAGE BODY: APPS.FA_CIP_PVT
Source
1 PACKAGE BODY FA_CIP_PVT as
2 /* $Header: FAVCIPB.pls 120.30.12020000.2 2012/11/30 13:42:38 spooyath ship $ */
3
4 g_cap_event_id number;
5 g_cap_thid number;
6 g_event_status varchar2(1);
7
8 g_release number := fa_cache_pkg.fazarel_release;
9
10 FUNCTION do_validation
11 (p_trans_rec IN FA_API_TYPES.trans_rec_type,
12 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
13 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type
14 , p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN;
15
16 FUNCTION do_cap_rev
17 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
18 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
19 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
20 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
21 px_asset_type_rec IN OUT NOCOPY FA_API_TYPES.asset_type_rec_type,
22 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
23 px_asset_fin_rec IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
24 p_period_rec IN FA_API_TYPES.period_rec_type,
25 p_mrc_sob_type_code IN VARCHAR2
26 , p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
27
28 l_asset_type_rec FA_API_TYPES.asset_type_rec_type;
29 l_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type;
30 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
31 l_asset_fin_rec_new FA_API_TYPES.asset_fin_rec_type;
32 l_asset_deprn_rec_old FA_API_TYPES.asset_deprn_rec_type;
33 l_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type;
34 l_asset_deprn_rec_new FA_API_TYPES.asset_deprn_rec_type;
35 l_inv_trans_rec FA_API_TYPES.inv_trans_rec_type;
36
37 l_old_transaction_type_code varchar2(30);
38 l_group_reclass_options_rec FA_API_TYPES.group_reclass_options_rec_type;
39
40 l_rowid rowid;
41 l_status boolean;
42 l_ret_status varchar2(1);
43 l_calling_fn varchar2(30) := 'fa_cip_pvt.do_cap_rev';
44 l_amount_inserted number;
45
46 l_adj fa_adjust_type_pkg.fa_adj_row_struct;
47 l_clear_adj fa_adjust_type_pkg.fa_adj_row_struct;
48
49 -- Japan Tax CIP Enhancement 6688475
50 l_method_type number := 0;
51 l_success integer;
52 l_rate_in_use number;
53
54 cap_rev_err exception;
55
56 l_adj_row_rec FA_ADJUSTMENTS%rowtype;
57 --Secondary Changes
58 l_secondary_cap_event_id number;
59 l_secondary_cap_thid number;
60 l_secondary_event_status varchar2(1);
61 l_secondary_trans_rec FA_API_TYPES.trans_rec_type;
62 l_secondary_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type;
63 l_secondary_sob_id number;
64
65 CURSOR c_mrc_adjustments (p_thid number) IS
66 SELECT code_combination_id ,
67 distribution_id ,
68 debit_credit_flag ,
69 adjustment_amount ,
70 adjustment_type
71 FROM fa_mc_adjustments
72 WHERE transaction_header_id = p_thid
73 AND set_of_books_id = p_asset_hdr_rec.set_of_books_id;
74
75 CURSOR c_adjustments (p_thid number) IS
76 SELECT code_combination_id ,
77 distribution_id ,
78 debit_credit_flag ,
79 adjustment_amount ,
80 adjustment_type
81 FROM fa_adjustments
82 WHERE transaction_header_id = p_thid;
83
84 BEGIN
85
86 if (p_log_level_rec.statement_level) then
87 fa_debug_pkg.add(l_calling_fn,
88 'calling do val', '', p_log_level_rec => p_log_level_rec);
89 end if;
90
91 -- do validation is this is the primary book
92 if (p_mrc_sob_type_code <> 'R') then
93 if not do_validation
94 (p_trans_rec => px_trans_rec,
95 p_asset_hdr_rec => p_asset_hdr_rec,
96 p_asset_fin_rec => px_asset_fin_rec,
97 p_log_level_rec => p_log_level_rec) then
98 raise cap_rev_err;
99 end if;
100 end if;
101
102 -- SLA uptake
103 -- need the thid before calc engine
104 if (p_mrc_sob_type_code <> 'R') then
105 select fa_transaction_headers_s.nextval
106 into px_trans_rec.transaction_header_id
107 from dual;
108
109 -- Bug 15877517 : Reinitialize who_info as well
110 px_trans_rec.who_info.creation_date := sysdate;
111 px_trans_rec.who_info.last_update_date := sysdate;
112
113 end if;
114
115 if (p_log_level_rec.statement_level) then
116 fa_debug_pkg.add(l_calling_fn,
117 'calling get_fin_info', '', p_log_level_rec => p_log_level_rec);
118 end if;
119
120 -- for reverse, set the new fin info = the old
121 -- for capitalizing, call calculation engine which will handle differences
122 -- in redefaults due to reverse/cap (i.e. ccbd/salvage)
123 -- including the life derivation for child assets
124 -- (baiscally reversals are untouched caps are recalculated)
125 --
126 -- period of addition has been set using absolute mode
127 -- meaning is this the period in which asset was first added
128
129 if (p_log_level_rec.statement_level) then
130 fa_debug_pkg.add(l_calling_fn,
131 'calling calc engine', '', p_log_level_rec => p_log_level_rec);
132 end if;
133
134 l_asset_fin_rec_old := p_asset_fin_rec_old;
135
136 if (px_trans_rec.transaction_type_code = 'ADDITION') then
137
138 -- the calculation engine needs info in the adj struct (esp for additions)
139 -- initialize only the not derived values
140
141 l_asset_fin_rec_adj.date_placed_in_service := px_asset_fin_rec.date_placed_in_service;
142 -- BUG 4553782
143 l_asset_fin_rec_adj.deprn_method_code := px_asset_fin_rec.deprn_method_code;
144 l_asset_fin_rec_adj.life_in_months := px_asset_fin_rec.life_in_months;
145 l_asset_fin_rec_adj.basic_rate := px_asset_fin_rec.basic_rate;
146 l_asset_fin_rec_adj.adjusted_rate := px_asset_fin_rec.adjusted_rate;
147 l_asset_fin_rec_adj.prorate_convention_code := px_asset_fin_rec.prorate_convention_code;
148 l_asset_fin_rec_adj.depreciate_flag := px_asset_fin_rec.depreciate_flag;
149 l_asset_fin_rec_adj.bonus_rule := px_asset_fin_rec.bonus_rule;
150 l_asset_fin_rec_adj.ceiling_name := px_asset_fin_rec.ceiling_name;
151 -- l_asset_fin_rec_adj.production_capacity := px_asset_fin_rec.production_capacity; -- bug8247611
152 l_asset_fin_rec_adj.unit_of_measure := px_asset_fin_rec.unit_of_measure;
153 -- END BUG
154
155 -- null out the old struct before calc call
156 -- defaulting within calc engine has been removed for group
157 -- values are passed to adj_struct in public api
158 --
159 -- l_asset_fin_rec_old := NULL;
160
161 -- SLA Uptake
162 -- as with FAPADDB.pls, we need to insure prior fy expense is 0
163 -- not null to get catchup
164
165 -- should be ok with following:
166 -- l_asset_deprn_rec_old.prior_fy_expense := 0;
167
168 if not FA_UTIL_PVT.get_asset_deprn_rec
169 (p_asset_hdr_rec => p_asset_hdr_rec ,
170 px_asset_deprn_rec => l_asset_deprn_rec_old,
171 p_period_counter => NULL,
172 p_mrc_sob_type_code => p_mrc_sob_type_code
173 ,p_log_level_rec => p_log_level_rec) then raise cap_rev_err;
174 end if;
175
176
177 -- SLA Uptake - sense new asset type to calc engine to
178 -- force catchup from faxexp
179
180 l_asset_type_rec.asset_type := 'CAPITALIZED';
181
182 if (p_log_level_rec.statement_level) then
183
184 fa_debug_pkg.add(l_calling_fn,
185 'before calc_fin_info adj life', l_asset_fin_rec_adj.life_in_months, p_log_level_rec => p_log_level_rec);
186 end if;
187
188
189 if not FA_ASSET_CALC_PVT.calc_fin_info
190 (px_trans_rec => px_trans_rec,
191 p_inv_trans_rec => l_inv_trans_rec,
192 p_asset_hdr_rec => p_asset_hdr_rec ,
193 p_asset_desc_rec => p_asset_desc_rec,
194 p_asset_type_rec => l_asset_type_rec,
195 p_asset_cat_rec => p_asset_cat_rec,
196 p_asset_fin_rec_old => l_asset_fin_rec_old,
197 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
198 px_asset_fin_rec_new => l_asset_fin_rec_new,
199 p_asset_deprn_rec_old => l_asset_deprn_rec_old,
200 p_asset_deprn_rec_adj => l_asset_deprn_rec_adj,
201 px_asset_deprn_rec_new => l_asset_deprn_rec_new,
202 p_period_rec => p_period_rec,
203 p_mrc_sob_type_code => p_mrc_sob_type_code,
204 p_group_reclass_options_rec => l_group_reclass_options_rec,
205 p_calling_fn => l_calling_fn
206 , p_log_level_rec => p_log_level_rec) then raise cap_rev_err;
207 end if;
208
209 if (p_log_level_rec.statement_level) then
210 fa_debug_pkg.add(l_calling_fn,
211 'after calc_fin_info', l_asset_fin_rec_new.life_in_months, p_log_level_rec => p_log_level_rec);
212
213 fa_debug_pkg.add(l_calling_fn,
214 'after calc_engine, cost', l_asset_fin_rec_new.cost, p_log_level_rec => p_log_level_rec);
215 end if;
216
217 -- insure original cost is reset
218 l_asset_fin_rec_new.original_cost := l_asset_fin_rec_new.cost;
219 l_asset_fin_rec_new.period_counter_capitalized := p_period_rec.period_counter;
220
221 /*
222 --Bug 7300699:
223 --Ensure subcomponent life is correctly derived.
224 --fazccbd should have been called in the public api.
225 --Contrary to comments above, child life is not derived in calc_fin_info
226 --and it does not make sense to do it there for this purpose anyway.
227 */
228 if (nvl(fa_cache_pkg.fazccbd_record.subcomponent_life_rule, 'NULL') <> 'NULL' and
229 nvl(p_asset_desc_rec.parent_asset_id, -99) <> -99) then
230
231 if not FA_ASSET_CALC_PVT.calc_subcomp_life
232 (p_trans_rec => px_trans_rec,
233 p_asset_hdr_rec => p_asset_hdr_rec,
234 p_asset_cat_rec => p_asset_cat_rec,
235 p_asset_desc_rec => p_asset_desc_rec,
236 p_period_rec => p_period_rec,
237 px_asset_fin_rec => l_asset_fin_rec_new,
238 p_calling_fn => l_calling_fn
239 , p_log_level_rec => p_log_level_rec) then
240 raise cap_rev_err;
241 end if;
242 end if; -- (nvl(fa_cache_pkg.fazccbd_recor ...
243
244 if (p_log_level_rec.statement_level) then
245 fa_debug_pkg.add(l_calling_fn, 'after calc_subcomp_life', l_asset_fin_rec_new.life_in_months, p_log_level_rec => p_log_level_rec);
246 end if;
247
248 else -- reverse
249
250 l_asset_fin_rec_new := l_asset_fin_rec_old;
251 l_asset_fin_rec_new.annual_deprn_rounding_flag := NULL;
252 l_asset_fin_rec_new.period_counter_capitalized := NULL;
253
254 end if;
255
256 if (p_log_level_rec.statement_level) then
257 fa_debug_pkg.add(l_calling_fn,
258 'period_of_addition', p_asset_hdr_rec.period_of_addition , p_log_level_rec => p_log_level_rec);
259 end if;
260
261 if (p_asset_hdr_rec.period_of_addition = 'Y' and
262 G_release = 11) then
263
264 -- use table handler due to mrc!!!!!
265
266 if (p_log_level_rec.statement_level) then
267 fa_debug_pkg.add(l_calling_fn,
268 'calling book update_row','', p_log_level_rec => p_log_level_rec);
269 end if;
270
271 -- Bug4483408: Recoverable_cost was passed as X_Adjusted_Cost and now it
272 -- uses adjusted_cost returned from calc_fin_info.
273
274 FA_BOOKS_PKG.Update_Row(
275 X_book_type_code => p_asset_hdr_rec.book_type_code,
276 X_asset_id => p_asset_hdr_rec.asset_id,
277 X_Date_Placed_In_Service => l_asset_fin_rec_new.date_placed_in_service,
278 X_Deprn_Start_Date => l_asset_fin_rec_new.deprn_start_date,
279 X_Deprn_Method_Code => l_asset_fin_rec_new.deprn_method_code,
280 X_Life_In_Months => nvl(l_asset_fin_rec_new.life_in_months,FND_API.G_MISS_NUM), --bug7416326
281 X_Adjusted_Cost => l_asset_fin_rec_new.adjusted_cost,
282 X_Original_Cost => l_asset_fin_rec_new.original_cost,
283 X_Salvage_Value => l_asset_fin_rec_new.salvage_value,
284 X_Prorate_Convention_Code => l_asset_fin_rec_new.prorate_convention_code, -- same in both???
285 X_Prorate_Date => l_asset_fin_rec_new.prorate_date,
286 X_Cost_Change_Flag => l_asset_fin_rec_new.cost_change_flag,
287 X_Adjustment_Required_Status => l_asset_fin_rec_new.adjustment_required_status,
288 X_Capitalize_Flag => l_asset_fin_rec_new.capitalize_flag,
289 X_Depreciate_Flag => l_asset_fin_rec_new.depreciate_flag,
290 X_Disabled_Flag => l_asset_fin_rec_new.disabled_flag,--HH
291 X_Basic_Rate => l_asset_fin_rec_new.basic_rate,
292 X_Adjusted_Rate => l_asset_fin_rec_new.adjusted_rate,
293 X_Bonus_Rule => l_asset_fin_rec_new.bonus_rule,
294 X_Ceiling_Name => l_asset_fin_rec_new.ceiling_name,
295 X_Recoverable_Cost => l_asset_fin_rec_new.recoverable_cost,
296 X_Adjusted_Capacity => l_asset_fin_rec_new.production_capacity,
297 X_Period_Counter_Capitalized => l_asset_fin_rec_new.period_counter_capitalized,
298 X_Production_Capacity => l_asset_fin_rec_new.production_capacity,
299 X_Unit_Of_Measure => l_asset_fin_rec_new.unit_of_measure,
300 X_Annual_Deprn_Rounding_Flag => l_asset_fin_rec_new.annual_deprn_rounding_flag,
301 X_Percent_Salvage_Value => l_asset_fin_rec_new.percent_salvage_value,
302 X_Allowed_Deprn_Limit => l_asset_fin_rec_new.allowed_deprn_limit,
303 X_Allowed_Deprn_Limit_Amount => l_asset_fin_rec_new.allowed_deprn_limit_amount,
304 X_Adjusted_Recoverable_Cost => l_asset_fin_rec_new.adjusted_recoverable_cost,
305 X_Group_Asset_ID => l_asset_fin_rec_new.group_asset_id,
306 X_mrc_sob_type_code => p_mrc_sob_type_code,
307 X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
308 X_Calling_Fn => l_calling_fn,
309 p_log_level_rec => p_log_level_rec);
310
311 -- Japan Tax CIP Enhancement 6688475 (Start)
312 if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES'
313 and (px_trans_rec.transaction_type_code <> 'CIP REVERSE') then
314
315 FA_CDE_PKG.faxgfr (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
316 X_Asset_Id => p_asset_hdr_rec.asset_id,
317 X_Short_Fiscal_Year_Flag => l_asset_fin_rec_new.short_fiscal_year_flag,
318 X_Conversion_Date => l_asset_fin_rec_new.conversion_date,
319 X_Prorate_Date => l_asset_fin_rec_new.prorate_date,
320 X_Orig_Deprn_Start_Date => l_asset_fin_rec_new.orig_deprn_start_date,
321 C_Prorate_Date => NULL,
322 C_Conversion_Date => NULL,
323 C_Orig_Deprn_Start_Date => NULL,
324 X_Method_Code => l_asset_fin_rec_new.deprn_method_code,
325 X_Life_In_Months => l_asset_fin_rec_new.life_in_months,
326 X_Fiscal_Year => -99,
327 X_Current_Period => l_asset_fin_rec_new.period_counter_capitalized,
328 X_calling_interface => 'ADDITION',
329 X_Rate => l_rate_in_use,
330 X_Method_Type => l_method_type,
331 X_Success => l_success, p_log_level_rec => p_log_level_rec);
332
333 if (l_success <= 0) then
334 fa_srvr_msg.add_message(calling_fn => 'fa_cip_pvt.do_cap_rev', p_log_level_rec => p_log_level_rec);
335 raise cap_rev_err;
336 end if;
337
338 UPDATE FA_BOOKS
339 SET rate_in_use = l_rate_in_use
340 WHERE book_type_code = p_asset_hdr_rec.book_type_code
341 AND asset_id = p_asset_hdr_rec.asset_id
342 AND date_ineffective is null;
343
344 end if;
345 -- Japan Tax CIP Enhancement 6688475 (End)
346
347 -- use table handler!!!!
348 if (p_mrc_sob_type_code <> 'R') then
349
350 if (p_log_level_rec.statement_level) then
351 fa_debug_pkg.add(l_calling_fn,
352 'setting trx info','', p_log_level_rec => p_log_level_rec);
353 end if;
354
355
356 if (px_trans_rec.transaction_type_code = 'ADDITION') then
357 px_trans_rec.transaction_date_entered := px_asset_fin_rec.date_placed_in_service;
358 end if;
359
360 if (px_trans_rec.transaction_type_code = 'CIP REVERSE') then
361 px_trans_rec.transaction_type_code := 'CIP ADDITION';
362 l_old_transaction_type_code := 'ADDITION';
363 px_asset_type_rec.asset_type := 'CIP';
364 else
365 px_trans_rec.transaction_type_code := 'ADDITION';
366 l_old_transaction_type_code := 'CIP ADDITION';
367 px_asset_type_rec.asset_type := 'CAPITALIZED';
368 end if;
369
370 if (p_log_level_rec.statement_level) then
371 fa_debug_pkg.add(l_calling_fn,
372 'calling trx update_row','', p_log_level_rec => p_log_level_rec);
373 end if;
374
375 -- fix for 4541467
376 select rowid
377 into l_rowid
378 from fa_transaction_headers
379 where asset_id = p_asset_hdr_rec.asset_id
380 and book_type_code = p_asset_hdr_rec.book_type_code
381 and transaction_type_code = l_old_transaction_type_code;
382
383 if (p_log_level_rec.statement_level) then
384 fa_debug_pkg.add(l_calling_fn,
385 'got rowid before trx update_row','', p_log_level_rec => p_log_level_rec);
386 end if;
387
388
389 FA_TRANSACTION_HEADERS_PKG.Update_row
390 (X_Rowid => l_rowid,
391 X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
392 X_Asset_Id => p_asset_hdr_rec.asset_id,
393 X_Transaction_Type_Code => px_trans_rec.transaction_type_code,
394 X_Transaction_Date_Entered => px_asset_fin_rec.date_placed_in_service,
395 X_Calling_Fn => l_calling_fn
396 , p_log_level_rec => p_log_level_rec);
397
398 if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then
399
400 if (p_log_level_rec.statement_level) then
401 fa_debug_pkg.add(l_calling_fn,
402 'calling book ah update_row','', p_log_level_rec => p_log_level_rec);
403 end if;
404
405 fa_asset_history_pkg.update_row
406 (X_asset_id => p_asset_hdr_rec.asset_id,
407 X_asset_type => px_asset_type_rec.asset_type,
408 X_last_update_date => px_trans_rec.who_info.last_update_date,
409 X_last_updated_by => px_trans_rec.who_info.last_updated_by,
410 X_Return_Status => l_status,
411 X_calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
412
413 if (p_log_level_rec.statement_level) then
414 fa_debug_pkg.add(l_calling_fn,
415 'calling book ad update_row','', p_log_level_rec => p_log_level_rec);
416 end if;
417
418 fa_additions_pkg.update_row
419 (X_asset_id => p_asset_hdr_rec.asset_id,
420 X_asset_type => px_asset_type_rec.asset_type,
421 X_last_update_date => px_trans_rec.who_info.last_update_date,
422 X_last_updated_by => px_trans_rec.who_info.last_updated_by,
423 X_last_update_login => px_trans_rec.who_info.last_update_login,
424 X_return_status => l_status,
425 X_calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
426
427 -- Added update for bug 4541467
428 update fa_transaction_headers
429 set transaction_date_entered = px_asset_fin_rec.date_placed_in_service
430 where asset_id = p_asset_hdr_rec.asset_id
431 and book_type_code = p_asset_hdr_rec.book_type_code
432 and transaction_type_code = 'TRANSFER IN';
433
434 end if;
435
436 end if;
437
438 else -- asset originally added in prior period
439
440 if (p_log_level_rec.statement_level) then
441 fa_debug_pkg.add(l_calling_fn,
442 'in prior period logic','', p_log_level_rec => p_log_level_rec);
443 end if;
444
445 if (p_mrc_sob_type_code <> 'R') then
446
447 -- trx_types are already set correctly
448 if (px_trans_rec.transaction_type_code = 'CIP REVERSE') then
449 px_asset_type_rec.asset_type := 'CIP';
450 else
451 px_asset_type_rec.asset_type := 'CAPITALIZED';
452 px_trans_rec.transaction_date_entered := px_asset_fin_rec.date_placed_in_service;
453 end if;
454
455 if (px_trans_rec.transaction_type_code = 'CIP REVERSE' and
456 G_release <> 11) then
457
458 if (p_log_level_rec.statement_level) then
459 fa_debug_pkg.add(l_calling_fn,
460 'checking','event status'
461 ,p_log_level_rec => p_log_level_rec);
462 end if;
463
464 select event_id,
465 transaction_header_id
466 into g_cap_event_id,
467 g_cap_thid
468 from fa_transaction_headers
469 where asset_id = p_asset_hdr_rec.asset_id
470 and book_type_code = p_asset_hdr_rec.book_type_code
471 and transaction_type_code = 'ADDITION';
472
473 if (g_cap_event_id is not null) then
474
475 if not fa_xla_events_pvt.get_trx_event_status
476 (p_set_of_books_id => p_asset_hdr_rec.set_of_books_id
477 ,p_transaction_header_id => g_cap_thid
478 ,p_event_id => g_cap_event_id
479 ,p_book_type_code => p_asset_hdr_rec.book_type_code
480 ,x_event_status => g_event_status
481 ,p_log_level_rec => p_log_level_rec) then
482 raise cap_rev_err;
483 end if;
484
485 if (p_log_level_rec.statement_level) then
486 fa_debug_pkg.add(l_calling_fn, 'event status ', g_event_status
487 ,p_log_level_rec => p_log_level_rec);
488 end if;
489
490 end if;
491
492 end if;
493
494
495 -- SLA UPTAKE
496 -- assign an event for the transaction
497 -- always for cap, only if not deleting for rev
498
499 if ((px_trans_rec.transaction_type_code = 'CIP REVERSE' and
500 g_event_status = FA_XLA_EVENTS_PVT.C_EVENT_PROCESSED) OR
501 px_trans_rec.transaction_type_code <> 'CIP REVERSE') then
502
503 if not fa_xla_events_pvt.create_transaction_event
504 (p_asset_hdr_rec => p_asset_hdr_rec,
505 p_asset_type_rec=> px_asset_type_rec,
506 px_trans_rec => px_trans_rec,
507 p_event_status => NULL,
508 p_calling_fn => l_calling_fn
509 ,p_log_level_rec => p_log_level_rec) then
510 raise cap_rev_err;
511 end if;
512
513 elsif (px_trans_rec.transaction_type_code = 'CIP REVERSE' and
514 g_event_status <> FA_XLA_EVENTS_PVT.C_EVENT_PROCESSED) then
515
516 if (p_log_level_rec.statement_level) then
517 fa_debug_pkg.add(l_calling_fn,
518 'deleting capitalization event',
519 g_cap_thid
520 ,p_log_level_rec => p_log_level_rec);
521 end if;
522
523 -- now handle event impacts
524 -- create the event for the transaction
525
526 if not fa_xla_events_pvt.delete_transaction_event
527 (p_ledger_id => fa_cache_pkg.fazcbc_record.set_of_books_id,
528 p_transaction_header_id => g_cap_thid,
529 p_book_type_code => p_asset_hdr_rec.book_type_code,
530 p_asset_type => px_asset_type_rec.asset_type, --bug 8630242/8678674
531 p_calling_fn => l_calling_fn
532 ,p_log_level_rec => p_log_level_rec) then
533 raise cap_rev_err;
534 end if;
535
536 if (p_log_level_rec.statement_level) then
537 fa_debug_pkg.add(l_calling_fn,
538 'deleting accounting impacts for cap thid',
539 g_cap_thid
540 ,p_log_level_rec => p_log_level_rec);
541 end if;
542
543 update fa_transaction_headers
544 set event_id = NULL
545 where transaction_header_id = g_cap_thid;
546
547 end if;
548
549 if (p_log_level_rec.statement_level) then
550 fa_debug_pkg.add(l_calling_fn,
551 'calling trx insert_row','', p_log_level_rec => p_log_level_rec);
552 end if;
553
554 FA_TRANSACTION_HEADERS_PKG.Insert_Row
555 (X_Rowid => l_rowid,
556 X_Transaction_Header_Id => px_trans_rec.transaction_header_id,
557 X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
558 X_Asset_Id => p_asset_hdr_rec.asset_id,
559 X_Transaction_Type_Code => px_trans_rec.transaction_type_code,
560 X_Transaction_Date_Entered => px_trans_rec.transaction_date_entered,
561 X_Date_Effective => px_trans_rec.who_info.creation_date,
562 X_Last_Update_Date => px_trans_rec.who_info.last_update_date,
563 X_Last_Updated_By => px_trans_rec.who_info.last_updated_by,
564 X_Transaction_Name => px_trans_rec.transaction_name,
565 X_Invoice_Transaction_Id => null,
566 X_Source_Transaction_Header_Id => px_trans_rec.Source_Transaction_Header_Id,
567 X_Mass_Reference_Id => px_trans_rec.mass_reference_id,
568 X_Last_Update_Login => px_trans_rec.who_info.last_update_login,
569 X_Transaction_Subtype => null,
570 X_Attribute1 => px_trans_rec.desc_flex.attribute1,
571 X_Attribute2 => px_trans_rec.desc_flex.attribute2,
572 X_Attribute3 => px_trans_rec.desc_flex.attribute3,
573 X_Attribute4 => px_trans_rec.desc_flex.attribute4,
574 X_Attribute5 => px_trans_rec.desc_flex.attribute5,
575 X_Attribute6 => px_trans_rec.desc_flex.attribute6,
576 X_Attribute7 => px_trans_rec.desc_flex.attribute7,
577 X_Attribute8 => px_trans_rec.desc_flex.attribute8,
578 X_Attribute9 => px_trans_rec.desc_flex.attribute9,
579 X_Attribute10 => px_trans_rec.desc_flex.attribute10,
580 X_Attribute11 => px_trans_rec.desc_flex.attribute11,
581 X_Attribute12 => px_trans_rec.desc_flex.attribute12,
582 X_Attribute13 => px_trans_rec.desc_flex.attribute13,
583 X_Attribute14 => px_trans_rec.desc_flex.attribute14,
584 X_Attribute15 => px_trans_rec.desc_flex.attribute15,
585 X_Attribute_Category_Code => px_trans_rec.desc_flex.attribute_category_code,
586 X_Transaction_Key => null,
587 X_Amortization_Start_Date => null,
588 X_Calling_Interface => px_trans_rec.calling_interface,
589 X_Mass_Transaction_ID => px_trans_rec.mass_transaction_id,
590 X_Trx_Reference_Id => px_trans_rec.trx_reference_id,
591 X_Event_Id => px_trans_rec.event_id,
592 X_Return_Status => l_status,
593 X_Calling_Fn => l_calling_fn
594 , p_log_level_rec => p_log_level_rec);
595
596 if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then
597
598 if (p_log_level_rec.statement_level) then
599 fa_debug_pkg.add(l_calling_fn,
600 'calling ah update_row, thid out',px_trans_rec.transaction_header_id, p_log_level_rec => p_log_level_rec);
601 end if;
602
603 fa_asset_history_pkg.update_row
604 (X_asset_id => p_asset_hdr_rec.asset_id,
605 X_transaction_header_id_out => px_trans_rec.transaction_header_id,
606 X_date_ineffective => px_trans_rec.who_info.last_update_date,
607 X_last_update_date => px_trans_rec.who_info.last_update_date,
608 X_last_updated_by => px_trans_rec.who_info.last_updated_by,
609 X_Return_Status => l_status,
610 X_calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
611
612 if (p_log_level_rec.statement_level) then
613 fa_debug_pkg.add(l_calling_fn,
614 'calling ah insert_row','', p_log_level_rec => p_log_level_rec);
615 end if;
616
617 fa_asset_history_pkg.insert_row(
618 X_Rowid => l_rowid,
619 X_Asset_Id => p_asset_hdr_rec.asset_id,
620 X_Category_Id => p_asset_cat_rec.category_id,
621 X_Asset_Type => px_asset_type_rec.asset_type,
622 X_Units => p_asset_desc_rec.current_units,
623 X_Date_Effective => px_trans_rec.who_info.last_update_date,
624 X_Date_Ineffective => null,
625 X_Transaction_Header_Id_In => px_trans_rec.transaction_header_id,
626 X_Transaction_Header_Id_Out => null,
627 X_Last_Update_Date => px_trans_rec.who_info.last_update_date,
628 X_Last_Updated_By => px_trans_rec.who_info.last_updated_by,
629 X_Last_Update_Login => px_trans_rec.who_info.last_update_login,
630 X_Return_Status => l_status,
631 X_Calling_Fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
632
633 end if;
634 end if;
635
636 if (p_log_level_rec.statement_level) then
637 fa_debug_pkg.add(l_calling_fn,
638 'calling bk deactivate_row','', p_log_level_rec => p_log_level_rec);
639 end if;
640
641 -- use table handler for mrc
642 fa_books_pkg.deactivate_row
643 (X_asset_id => p_asset_hdr_rec.asset_id,
644 X_book_type_code => p_asset_hdr_rec.book_type_code,
645 X_transaction_header_id_out => px_trans_rec.transaction_header_id,
646 X_date_ineffective => px_trans_rec.who_info.last_update_date,
647 X_mrc_sob_type_code => p_mrc_sob_type_code,
648 X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
649 X_Calling_Fn => l_calling_fn
650 , p_log_level_rec => p_log_level_rec);
651
652 if (p_log_level_rec.statement_level) then
653 fa_debug_pkg.add(l_calling_fn,
654 'calling bk insert_row','', p_log_level_rec => p_log_level_rec);
655 end if;
656
657 fa_books_pkg.insert_row
658 (X_Rowid => l_rowid,
659 X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
660 X_Asset_Id => p_asset_hdr_rec.asset_id,
661 X_Date_Placed_In_Service => l_asset_fin_rec_new.date_placed_in_service,
662 X_Date_Effective => px_trans_rec.who_info.last_update_date,
663 X_Deprn_Start_Date => l_asset_fin_rec_new.deprn_start_date,
664 X_Deprn_Method_Code => l_asset_fin_rec_new.deprn_method_code,
665 X_Life_In_Months => l_asset_fin_rec_new.life_in_months,
666 X_Rate_Adjustment_Factor => l_asset_fin_rec_new.rate_adjustment_factor,
667 X_Adjusted_Cost => l_asset_fin_rec_new.adjusted_cost,
668 X_Cost => l_asset_fin_rec_new.cost,
669 X_Original_Cost => l_asset_fin_rec_new.original_cost,
670 X_Salvage_Value => l_asset_fin_rec_new.salvage_value,
671 X_Prorate_Convention_Code => l_asset_fin_rec_new.prorate_convention_code,
672 X_Prorate_Date => l_asset_fin_rec_new.prorate_date,
673 X_Cost_Change_Flag => l_asset_fin_rec_new.cost_change_flag,
674 X_Adjustment_Required_Status => l_asset_fin_rec_new.adjustment_required_status,
675 X_Capitalize_Flag => l_asset_fin_rec_new.capitalize_flag,
676 X_Retirement_Pending_Flag => l_asset_fin_rec_new.retirement_pending_flag,
677 X_Depreciate_Flag => l_asset_fin_rec_new.depreciate_flag,
678 X_Disabled_Flag => l_asset_fin_rec_new.disabled_flag,--HH
679 X_Last_Update_Date => px_trans_rec.who_info.last_update_date,
680 X_Last_Updated_By => px_trans_rec.who_info.last_updated_by,
681 X_Date_Ineffective => NULL,
682 X_Transaction_Header_Id_In => px_trans_rec.transaction_header_id,
683 X_Transaction_Header_Id_Out => NULL,
684 X_Itc_Amount_Id => l_asset_fin_rec_new.itc_amount_id,
685 X_Itc_Amount => l_asset_fin_rec_new.itc_amount,
686 X_Retirement_Id => l_asset_fin_rec_new.retirement_id,
687 X_Tax_Request_Id => l_asset_fin_rec_new.tax_request_id,
688 X_Itc_Basis => l_asset_fin_rec_new.itc_basis,
689 X_Basic_Rate => l_asset_fin_rec_new.basic_rate,
690 X_Adjusted_Rate => l_asset_fin_rec_new.adjusted_rate,
691 X_Bonus_Rule => l_asset_fin_rec_new.bonus_rule,
692 X_Ceiling_Name => l_asset_fin_rec_new.ceiling_name,
693 X_Recoverable_Cost => l_asset_fin_rec_new.recoverable_cost,
694 X_Last_Update_Login => px_trans_rec.who_info.last_update_login,
695 X_Adjusted_Capacity => l_asset_fin_rec_new.adjusted_capacity,
696 X_Fully_Rsvd_Revals_Counter => l_asset_fin_rec_new.fully_rsvd_revals_counter,
697 X_Idled_Flag => l_asset_fin_rec_new.idled_flag,
698 X_Period_Counter_Capitalized => l_asset_fin_rec_new.period_counter_capitalized,
699 X_PC_Fully_Reserved => l_asset_fin_rec_new.period_counter_fully_reserved,
700 X_Period_Counter_Fully_Retired => l_asset_fin_rec_new.period_counter_fully_retired,
701 X_Production_Capacity => l_asset_fin_rec_new.production_capacity,
702 X_Reval_Amortization_Basis => l_asset_fin_rec_new.reval_amortization_basis,
703 X_Reval_Ceiling => l_asset_fin_rec_new.reval_ceiling,
704 X_Unit_Of_Measure => l_asset_fin_rec_new.unit_of_measure,
705 X_Unrevalued_Cost => l_asset_fin_rec_new.unrevalued_cost,
706 X_Annual_Deprn_Rounding_Flag => l_asset_fin_rec_new.annual_deprn_rounding_flag,
707 X_Percent_Salvage_Value => l_asset_fin_rec_new.percent_salvage_value,
708 X_Allowed_Deprn_Limit => l_asset_fin_rec_new.allowed_deprn_limit,
709 X_Allowed_Deprn_Limit_Amount => l_asset_fin_rec_new.allowed_deprn_limit_amount,
710 X_Period_Counter_Life_Complete => l_asset_fin_rec_new.period_counter_life_complete,
711 X_Adjusted_Recoverable_Cost => l_asset_fin_rec_new.adjusted_recoverable_cost,
712 X_Short_Fiscal_Year_Flag => l_asset_fin_rec_new.short_fiscal_year_flag,
713 X_Conversion_Date => l_asset_fin_rec_new.conversion_date,
714 X_Orig_Deprn_Start_Date => l_asset_fin_rec_new.orig_deprn_start_date,
715 X_Remaining_Life1 => l_asset_fin_rec_new.remaining_life1,
716 X_Remaining_Life2 => l_asset_fin_rec_new.remaining_life2,
717 X_Old_Adj_Cost => l_asset_fin_rec_new.old_adjusted_cost,
718 X_Formula_Factor => l_asset_fin_rec_new.formula_factor,
719 X_gf_Attribute1 => l_asset_fin_rec_new.global_attribute1,
720 X_gf_Attribute2 => l_asset_fin_rec_new.global_attribute2,
721 X_gf_Attribute3 => l_asset_fin_rec_new.global_attribute3,
722 X_gf_Attribute4 => l_asset_fin_rec_new.global_attribute4,
723 X_gf_Attribute5 => l_asset_fin_rec_new.global_attribute5,
724 X_gf_Attribute6 => l_asset_fin_rec_new.global_attribute6,
725 X_gf_Attribute7 => l_asset_fin_rec_new.global_attribute7,
726 X_gf_Attribute8 => l_asset_fin_rec_new.global_attribute8,
727 X_gf_Attribute9 => l_asset_fin_rec_new.global_attribute9,
728 X_gf_Attribute10 => l_asset_fin_rec_new.global_attribute10,
729 X_gf_Attribute11 => l_asset_fin_rec_new.global_attribute11,
730 X_gf_Attribute12 => l_asset_fin_rec_new.global_attribute12,
731 X_gf_Attribute13 => l_asset_fin_rec_new.global_attribute13,
732 X_gf_Attribute14 => l_asset_fin_rec_new.global_attribute14,
733 X_gf_Attribute15 => l_asset_fin_rec_new.global_attribute15,
734 X_gf_Attribute16 => l_asset_fin_rec_new.global_attribute16,
735 X_gf_Attribute17 => l_asset_fin_rec_new.global_attribute17,
736 X_gf_Attribute18 => l_asset_fin_rec_new.global_attribute18,
737 X_gf_Attribute19 => l_asset_fin_rec_new.global_attribute19,
738 X_gf_Attribute20 => l_asset_fin_rec_new.global_attribute20,
739 X_global_attribute_category => l_asset_fin_rec_new.global_attribute_category,
740 X_group_asset_id => l_asset_fin_rec_new.group_asset_id,
741 X_salvage_type => l_asset_fin_rec_new.salvage_type,
742 X_deprn_limit_type => l_asset_fin_rec_new.deprn_limit_type,
743 X_over_depreciate_option => l_asset_fin_rec_new.over_depreciate_option,
744 X_super_group_id => l_asset_fin_rec_new.super_group_id,
745 X_reduction_rate => L_asset_fin_rec_new.reduction_rate,
746 X_reduce_addition_flag => l_asset_fin_rec_new.reduce_addition_flag,
747 X_reduce_adjustment_flag => l_asset_fin_rec_new.reduce_adjustment_flag,
748 X_reduce_retirement_flag => l_asset_fin_rec_new.reduce_retirement_flag,
749 X_recognize_gain_loss => l_asset_fin_rec_new.recognize_gain_loss,
750 X_recapture_reserve_flag => l_asset_fin_rec_new.recapture_reserve_flag,
751 X_limit_proceeds_flag => l_asset_fin_rec_new.limit_proceeds_flag,
752 X_terminal_gain_loss => l_asset_fin_rec_new.terminal_gain_loss,
753 X_tracking_method => l_asset_fin_rec_new.tracking_method,
754 X_allocate_to_fully_rsv_flag => l_asset_fin_rec_new.allocate_to_fully_rsv_flag,
755 X_allocate_to_fully_ret_flag => l_asset_fin_rec_new.allocate_to_fully_ret_flag,
756 X_exclude_fully_rsv_flag => l_asset_fin_rec_new.exclude_fully_rsv_flag,
757 X_excess_allocation_option => l_asset_fin_rec_new.excess_allocation_option,
758 X_depreciation_option => l_asset_fin_rec_new.depreciation_option,
759 X_member_rollup_flag => l_asset_fin_rec_new.member_rollup_flag,
760 X_ytd_proceeds => l_asset_fin_rec_new.ytd_proceeds,
761 X_ltd_proceeds => l_asset_fin_rec_new.ltd_proceeds,
762 X_eofy_reserve => l_asset_fin_rec_new.eofy_reserve,
763 X_cip_cost => l_asset_fin_rec_new.cip_cost,
764 X_terminal_gain_loss_amount => l_asset_fin_rec_new.terminal_gain_loss_amount,
765 X_ltd_cost_of_removal => l_asset_fin_rec_new.ltd_cost_of_removal,
766 X_cash_generating_unit_id =>
767 l_asset_fin_rec_new.cash_generating_unit_id,
768 X_mrc_sob_type_code => p_mrc_sob_type_code,
769 X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
770 X_Return_Status => l_status,
771 X_Calling_Fn => l_calling_fn
772 , p_log_level_rec => p_log_level_rec);
773
774 -- Japan Tax CIP Enhancement 6688475 (Start)
775 if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES'
776 and (px_trans_rec.transaction_type_code <> 'CIP REVERSE') then
777
778 FA_CDE_PKG.faxgfr (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
779 X_Asset_Id => p_asset_hdr_rec.asset_id,
780 X_Short_Fiscal_Year_Flag => l_asset_fin_rec_new.short_fiscal_year_flag,
781 X_Conversion_Date => l_asset_fin_rec_new.conversion_date,
782 X_Prorate_Date => l_asset_fin_rec_new.prorate_date,
783 X_Orig_Deprn_Start_Date => l_asset_fin_rec_new.orig_deprn_start_date,
784 C_Prorate_Date => NULL,
785 C_Conversion_Date => NULL,
786 C_Orig_Deprn_Start_Date => NULL,
787 X_Method_Code => l_asset_fin_rec_new.deprn_method_code,
788 X_Life_In_Months => l_asset_fin_rec_new.life_in_months,
789 X_Fiscal_Year => -99,
790 X_Current_Period => l_asset_fin_rec_new.period_counter_capitalized,
791 X_calling_interface => 'ADDITION',
792 X_Rate => l_rate_in_use,
793 X_Method_Type => l_method_type,
794 X_Success => l_success, p_log_level_rec => p_log_level_rec);
795
796 if (l_success <= 0) then
797 fa_srvr_msg.add_message(calling_fn => 'fa_cip_pvt.do_cap_rev', p_log_level_rec => p_log_level_rec);
798 raise cap_rev_err;
799 end if;
800
801 UPDATE FA_BOOKS
802 SET rate_in_use = l_rate_in_use
803 WHERE book_type_code = p_asset_hdr_rec.book_type_code
804 AND asset_id = p_asset_hdr_rec.asset_id
805 AND date_ineffective is null;
806
807 end if;
808 -- Japan Tax CIP Enhancement 6688475 (End)
809
810 --Code added for 6748832
811
812 if (p_log_level_rec.statement_level) then
813 fa_debug_pkg.add(l_calling_fn,'calling deprn summary update_row',''
814 ,p_log_level_rec => p_log_level_rec);
815 end if;
816
817
818 if (p_asset_hdr_rec.period_of_addition = 'Y') then
819
820 FA_DEPRN_SUMMARY_PKG.Update_Row
821 (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
822 X_Asset_Id => p_asset_hdr_rec.asset_id,
823 X_Deprn_Run_Date => px_trans_rec.who_info.last_update_date,
824 X_Adjusted_Cost => l_asset_fin_rec_new.adjusted_cost,
825 X_Period_Counter => p_period_rec.period_counter-1,
826 X_mrc_sob_type_code => p_mrc_sob_type_code,
827 X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
828 X_Calling_Fn => l_calling_fn
829 ,p_log_level_rec => p_log_level_rec);
830 end if;
831
832
833 if (p_mrc_sob_type_code <> 'R') then
834
835 if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then
836
837 if (p_log_level_rec.statement_level) then
838 fa_debug_pkg.add(l_calling_fn,
839 'calling ad update_row','', p_log_level_rec => p_log_level_rec);
840 end if;
841
842 fa_additions_pkg.update_row
843 (X_asset_id => p_asset_hdr_rec.asset_id,
844 X_asset_type => px_asset_type_rec.asset_type,
845 X_last_update_date => px_trans_rec.who_info.last_update_date,
846 X_last_updated_by => px_trans_rec.who_info.last_updated_by,
847 X_last_update_login => px_trans_rec.who_info.last_update_login,
848 X_Return_Status => l_status,
849 X_Calling_Fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
850
851 end if; -- corp
852 end if; -- primary
853 /*=================================================================
854 Secondary Changes Start
855 If primary and secondary sob_id is different then we need to
856 create/update/delete event for secondary ledger*/
857 l_secondary_sob_id := FA_XLA_EVENTS_PVT.get_secondary_sob_id(p_asset_hdr_rec.book_type_code);
858
859 if (l_secondary_sob_id is not null) and ( p_asset_hdr_rec.set_of_books_id = l_secondary_sob_id) then
860
861 if (px_trans_rec.transaction_type_code = 'CIP REVERSE') then
862 px_asset_type_rec.asset_type := 'CIP';
863 else
864 px_asset_type_rec.asset_type := 'CAPITALIZED';
865 px_trans_rec.transaction_date_entered := px_asset_fin_rec.date_placed_in_service;
866 end if;
867 if (px_trans_rec.transaction_type_code = 'CIP REVERSE' and
868 G_release <> 11) then
869
870 if (p_log_level_rec.statement_level) then
871 fa_debug_pkg.add(l_calling_fn,
872 'checking cap thid ',g_cap_thid
873 ,p_log_level_rec => p_log_level_rec);
874 end if;
875 l_secondary_cap_event_id := FA_XLA_EVENTS_PVT.get_secondary_event_id(p_asset_hdr_rec.book_type_code, l_secondary_sob_id, g_cap_thid);
876
877 if (l_secondary_cap_event_id is not null) then
878
879 if not fa_xla_events_pvt.get_trx_event_status
880 (p_set_of_books_id => l_secondary_sob_id
881 ,p_transaction_header_id => g_cap_thid
882 ,p_event_id => l_secondary_cap_event_id
883 ,p_book_type_code => p_asset_hdr_rec.book_type_code
884 ,x_event_status => l_secondary_event_status
885 ,p_log_level_rec => p_log_level_rec) then
886 raise cap_rev_err;
887 end if;
888
889 if (p_log_level_rec.statement_level) then
890 fa_debug_pkg.add(l_calling_fn, 'event status ', g_event_status
891 ,p_log_level_rec => p_log_level_rec);
892 end if;
893
894 end if;
895 end if;
896
897 l_secondary_trans_rec := px_trans_rec;
898 l_secondary_asset_hdr_rec := p_asset_hdr_rec;
899 l_secondary_asset_hdr_rec.set_of_books_id := l_secondary_sob_id;
900 if ((l_secondary_trans_rec.transaction_type_code = 'CIP REVERSE' and
901 l_secondary_event_status = FA_XLA_EVENTS_PVT.C_EVENT_PROCESSED) OR
902 l_secondary_trans_rec.transaction_type_code <> 'CIP REVERSE') then
903
904
905 if not fa_xla_events_pvt.create_transaction_event
906 (p_asset_hdr_rec => l_secondary_asset_hdr_rec,
907 p_asset_type_rec=> px_asset_type_rec,
908 px_trans_rec => l_secondary_trans_rec,
909 p_event_status => NULL,
910 p_calling_fn => l_calling_fn
911 ,p_log_level_rec => p_log_level_rec) then
912 raise cap_rev_err;
913 end if;
914
915 elsif (l_secondary_trans_rec.transaction_type_code = 'CIP REVERSE' and
916 l_secondary_event_status <> FA_XLA_EVENTS_PVT.C_EVENT_PROCESSED) then
917
918 if (p_log_level_rec.statement_level) then
919 fa_debug_pkg.add(l_calling_fn,
920 'deleting capitalization event',
921 g_cap_thid
922 ,p_log_level_rec => p_log_level_rec);
923 end if;
924
925 -- now handle event impacts
926 -- create the event for the transaction
927
928 if not fa_xla_events_pvt.delete_transaction_event
929 (p_ledger_id => l_secondary_sob_id,
930 p_transaction_header_id => g_cap_thid,
931 p_book_type_code => p_asset_hdr_rec.book_type_code,
932 p_asset_type => px_asset_type_rec.asset_type, --bug 8630242/8678674
933 p_secondary_sob_id => l_secondary_sob_id,
934 p_calling_fn => 'fa_cip_pvt.do_cap_rev.secondary'
935 ,p_log_level_rec => p_log_level_rec) then
936 raise cap_rev_err;
937 end if;
938
939 if (p_log_level_rec.statement_level) then
940 fa_debug_pkg.add(l_calling_fn,
941 'deleting accounting impacts for cap thid',
942 g_cap_thid
943 ,p_log_level_rec => p_log_level_rec);
944 end if;
945 end if;
946 /*Secondary Changes End
947 ==================================================================*/
948
949 end if;
950 if (px_trans_rec.transaction_type_code = 'CIP REVERSE') then
951
952 if (p_mrc_sob_type_code <> 'R') then
953 if (p_log_level_rec.statement_level) then
954 fa_debug_pkg.add(l_calling_fn,
955 'calling th update trx type','', p_log_level_rec => p_log_level_rec);
956 end if;
957
958 FA_TRANSACTION_HEADERS_PKG.Update_Trx_Type
959 (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
960 X_Asset_Id => p_asset_hdr_rec.asset_id,
961 X_Transaction_Type_Code => 'ADDITION',
962 X_New_Transaction_Type => 'ADDITION/VOID',
963 X_Return_Status => l_status,
964 X_Calling_Fn => l_calling_fn
965 , p_log_level_rec => p_log_level_rec);
966 end if;
967
968 if (G_release <> 11 and
969 g_event_status = FA_XLA_EVENTS_PVT.C_EVENT_PROCESSED) then
970
971 if (p_log_level_rec.statement_level) then
972 fa_debug_pkg.add(l_calling_fn,
973 'reversing accounting impacts for cap',
974 'from fa_adjustments'
975 ,p_log_level_rec => p_log_level_rec);
976 end if;
977
978 if (p_mrc_sob_type_code = 'R') then
979 open c_mrc_adjustments(p_thid => g_cap_thid);
980 else
981 open c_adjustments(p_thid => g_cap_thid);
982 end if;
983
984 loop
985 if (p_mrc_sob_type_code = 'R') then
986 fetch c_mrc_adjustments
987 into l_adj_row_rec.code_combination_id ,
988 l_adj_row_rec.distribution_id ,
989 l_adj_row_rec.debit_credit_flag ,
990 l_adj_row_rec.adjustment_amount ,
991 l_adj_row_rec.adjustment_type;
992 else
993 fetch c_adjustments
994 into l_adj_row_rec.code_combination_id ,
995 l_adj_row_rec.distribution_id ,
996 l_adj_row_rec.debit_credit_flag ,
997 l_adj_row_rec.adjustment_amount ,
998 l_adj_row_rec.adjustment_type;
999 end if;
1000
1001 if (p_mrc_sob_type_code = 'R') then
1002 EXIT WHEN c_mrc_adjustments%NOTFOUND;
1003 else
1004 EXIT WHEN c_adjustments%NOTFOUND;
1005 end if;
1006
1007
1008 l_adj.transaction_header_id := px_trans_rec.transaction_header_id;
1009 l_adj.asset_id := p_asset_hdr_rec.asset_id;
1010 l_adj.book_type_code := p_asset_hdr_rec.book_type_code;
1011 l_adj.period_counter_created := p_period_rec.period_counter;
1012 l_adj.period_counter_adjusted := p_period_rec.period_counter;
1013 l_adj.current_units := p_asset_desc_rec.current_units
1014 ;
1015 l_adj.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_SINGLE;
1016 l_adj.selection_thid := 0;
1017 l_adj.selection_retid := 0;
1018 l_adj.leveling_flag := FALSE;
1019 l_adj.last_update_date := px_trans_rec.who_info.last_update_date;
1020
1021 l_adj.gen_ccid_flag := FALSE;
1022 l_adj.annualized_adjustment := 0;
1023 l_adj.asset_invoice_id := 0;
1024 l_adj.code_combination_id := l_adj_row_rec.code_combination_id;
1025 l_adj.distribution_id := l_adj_row_rec.distribution_id;
1026
1027 l_adj.adjustment_amount := l_adj_row_rec.adjustment_amount;
1028 l_adj.flush_adj_flag := FALSE;
1029 l_adj.adjustment_type := l_adj_row_rec.adjustment_type;
1030
1031 if (l_adj_row_rec.debit_credit_flag = 'DR') then
1032 l_adj.debit_credit_flag := 'CR';
1033 else
1034 l_adj.debit_credit_flag := 'DR';
1035 end if;
1036
1037 l_adj.account := NULL;
1038
1039 if (l_adj_row_rec.adjustment_type = 'COST') then
1040 l_adj.account_type := 'ASSET_COST_ACCT';
1041 l_adj.source_type_code := 'ADDITION';
1042 elsif (l_adj_row_rec.adjustment_type = 'CIP COST') then
1043 l_adj.account_type := 'CIP_COST_ACCT';
1044 l_adj.source_type_code := 'ADDITION';
1045 elsif (l_adj_row_rec.adjustment_type = 'EXPENSE') then
1046 l_adj.account_type := 'DEPRN_EXPENSE_ACCT';
1047 l_adj.source_type_code := 'DEPRECIATION';
1048 -- Bug:6404609
1049 elsif (l_adj_row_rec.adjustment_type = 'COST CLEARING') then
1050 l_adj.adjustment_type := 'CIP COST';
1051 l_adj.account_type := 'CIP_COST_ACCT';
1052 l_adj.source_type_code := 'CIP ADDITION';
1053 else
1054 l_adj.account_type := 'BONUS_DEPRN_EXPENSE_ACCT';
1055 l_adj.source_type_code := 'DEPRECIATION';
1056 end if;
1057
1058 l_adj.mrc_sob_type_code := p_mrc_sob_type_code;
1059 l_adj.set_of_books_id := p_asset_hdr_rec.set_of_books_id;
1060
1061 if not FA_INS_ADJUST_PKG.faxinaj
1062 (l_adj,
1063 px_trans_rec.who_info.last_update_date,
1064 px_trans_rec.who_info.last_updated_by,
1065 px_trans_rec.who_info.last_update_login
1066 ,p_log_level_rec => p_log_level_rec) then
1067 raise cap_rev_err;
1068 end if;
1069
1070 end loop;
1071
1072 -- now flush the rows to db
1073 l_adj.transaction_header_id := 0;
1074 l_adj.flush_adj_flag := TRUE;
1075 l_adj.leveling_flag := TRUE;
1076
1077 if not FA_INS_ADJUST_PKG.faxinaj
1078 (l_adj,
1079 px_trans_rec.who_info.last_update_date,
1080 px_trans_rec.who_info.last_updated_by,
1081 px_trans_rec.who_info.last_update_login
1082 ,p_log_level_rec => p_log_level_rec) then
1083 raise cap_rev_err;
1084 end if;
1085
1086 if (p_mrc_sob_type_code = 'R') then
1087 close c_mrc_adjustments;
1088 else
1089 close c_adjustments;
1090 end if;
1091
1092 else
1093
1094 if (p_mrc_sob_type_code <> 'R') then
1095
1096 delete from fa_adjustments
1097 where transaction_header_id = g_cap_thid;
1098
1099 else
1100
1101 delete from fa_mc_adjustments
1102 where transaction_header_id = g_cap_thid
1103 and set_of_books_id = p_asset_hdr_rec.set_of_books_id;
1104 end if;
1105
1106 end if;
1107
1108 else -- capitalizing
1109
1110 -- now insert adjustments via faxinaj (when outside period of add)
1111 -- period of add flag has been set in absolute mode
1112
1113 -- converted to use faxinaj instead of faxinadj for mrc
1114
1115 if (p_log_level_rec.statement_level) then
1116 fa_debug_pkg.add(l_calling_fn,
1117 'calling faxinaj','', p_log_level_rec => p_log_level_rec);
1118 fa_debug_pkg.add(l_calling_fn,
1119 'calling faxinaj - adj_amount', l_asset_fin_rec_new.cost, p_log_level_rec => p_log_level_rec);
1120 end if;
1121
1122 l_adj.transaction_header_id := px_trans_rec.transaction_header_id;
1123 l_adj.asset_id := p_asset_hdr_rec.asset_id;
1124 l_adj.book_type_code := p_asset_hdr_rec.book_type_code;
1125 l_adj.period_counter_created := p_period_rec.period_counter;
1126 l_adj.period_counter_adjusted := p_period_rec.period_counter;
1127 l_adj.current_units := p_asset_desc_rec.current_units ;
1128 l_adj.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE;
1129 l_adj.selection_thid := 0;
1130 l_adj.selection_retid := 0;
1131 l_adj.leveling_flag := FALSE;
1132 l_adj.last_update_date := px_trans_rec.who_info.last_update_date;
1133
1134 l_adj.gen_ccid_flag := TRUE;
1135 l_adj.annualized_adjustment := 0;
1136 l_adj.asset_invoice_id := 0;
1137 l_adj.code_combination_id := 0;
1138 l_adj.distribution_id := 0;
1139
1140 l_adj.adjustment_amount := l_asset_fin_rec_new.cost;
1141 l_adj.source_type_code := 'ADDITION';
1142
1143
1144 -- cost first
1145 l_adj.flush_adj_flag := TRUE; -- ??
1146 l_adj.adjustment_type := 'COST';
1147 l_adj.debit_credit_flag := 'DR';
1148 l_adj.account := fa_cache_pkg.fazccb_record.asset_cost_acct;
1149 l_adj.account_type := 'ASSET_COST_ACCT';
1150 l_adj.mrc_sob_type_code := p_mrc_sob_type_code;
1151 l_adj.set_of_books_id := p_asset_hdr_rec.set_of_books_id;
1152
1153 if not FA_INS_ADJUST_PKG.faxinaj
1154 (l_adj,
1155 px_trans_rec.who_info.last_update_date,
1156 px_trans_rec.who_info.last_updated_by,
1157 px_trans_rec.who_info.last_update_login, p_log_level_rec => p_log_level_rec) then
1158 raise cap_rev_err;
1159 end if;
1160
1161 -- cip cost next
1162 l_adj.flush_adj_flag := TRUE;
1163 l_adj.adjustment_type := 'CIP COST';
1164 l_adj.debit_credit_flag := 'CR';
1165 l_adj.account := fa_cache_pkg.fazccb_record.cip_cost_acct;
1166 l_adj.account_type := 'CIP_COST_ACCT';
1167
1168 if not FA_INS_ADJUST_PKG.faxinaj
1169 (l_adj,
1170 px_trans_rec.who_info.last_update_date,
1171 px_trans_rec.who_info.last_updated_by,
1172 px_trans_rec.who_info.last_update_login, p_log_level_rec => p_log_level_rec) then
1173 raise cap_rev_err;
1174 end if;
1175
1176 end if; -- reverse/cap
1177
1178 end if; -- current/prior period
1179
1180 -- return the full fin struct back to public api for mrc rate insertion
1181 px_asset_fin_rec := l_asset_fin_rec_new;
1182
1183
1184 return TRUE; -- all good
1185
1186 exception
1187 when cap_rev_err then
1188 fa_srvr_msg.add_message(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1189 return false;
1190
1191 when others then
1192 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1193 return false;
1194
1195
1196 end do_cap_rev;
1197
1198 -------------------------------------------------------------------------
1199
1200 function do_validation
1201 (p_trans_rec IN FA_API_TYPES.trans_rec_type,
1202 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
1203 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type
1204 , p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean is
1205
1206 l_count number;
1207 l_period_of_addition varchar2(1);
1208 l_calling_fn varchar2(30) := 'fa_cip_pvt.do_validation';
1209 val_err exception;
1210
1211 begin
1212
1213 if (p_log_level_rec.statement_level) then
1214 fa_debug_pkg.add(l_calling_fn,
1215 'cap trans type code ', p_trans_rec.transaction_type_code , p_log_level_rec => p_log_level_rec);
1216 end if;
1217
1218
1219 if (p_trans_rec.transaction_type_code = 'ADDITION') then
1220
1221 -- validate dpis
1222 if not fa_asset_val_pvt.validate_dpis
1223 (p_transaction_type_code => p_trans_rec.transaction_type_code,
1224 p_book_type_code => p_asset_hdr_rec.book_type_code,
1225 p_date_placed_in_service =>
1226 p_asset_fin_rec.date_placed_in_service,
1227 p_prorate_convention_code =>
1228 p_asset_fin_rec.prorate_convention_code,
1229 p_calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec) then
1230 raise val_err;
1231 end if;
1232
1233 else
1234
1235 -- check addition (don't allow after period of capitalization)
1236 if not fa_asset_val_pvt.validate_period_of_addition
1237 (p_asset_id => p_asset_hdr_rec.asset_id,
1238 p_book => p_asset_hdr_rec.book_type_code,
1239 p_mode => 'CAPITALIZED',
1240 px_period_of_addition => l_period_of_addition, p_log_level_rec => p_log_level_rec) then
1241 raise val_err;
1242 end if;
1243
1244 if (p_log_level_rec.statement_level) then
1245 fa_debug_pkg.add(l_calling_fn,
1246 'cap period_of_addition', l_period_of_addition , p_log_level_rec => p_log_level_rec);
1247 end if;
1248
1249 if (l_period_of_addition = 'N') then
1250 fa_srvr_msg.add_message
1251 (calling_fn => l_calling_fn,
1252 name => 'FA_CWA_NOT_ADDED_THIS_PERIOD', p_log_level_rec => p_log_level_rec);
1253 raise val_err;
1254 end if;
1255
1256 -- chk trx after add (don't allow if any trx after capitalization)
1257 if (p_log_level_rec.statement_level) then
1258 fa_debug_pkg.add(l_calling_fn,
1259 'checking subsequent trxs', '' , p_log_level_rec => p_log_level_rec);
1260 end if;
1261
1262 select count(*)
1263 into l_count
1264 from fa_transaction_headers th_add,
1265 fa_transaction_headers th_other
1266 where th_add.asset_id = p_asset_hdr_rec.asset_id
1267 and th_add.book_type_code = p_asset_hdr_rec.book_type_code
1268 and th_add.transaction_type_code = 'ADDITION'
1269 and th_other.asset_id = p_asset_hdr_rec.asset_id
1270 and th_other.book_type_code = p_asset_hdr_rec.book_type_code
1271 and th_other.date_effective > th_add.date_effective;
1272
1273 if (l_count <> 0) then
1274 fa_srvr_msg.add_message
1275 (calling_fn => l_calling_fn,
1276 name => 'FA_CWA_TRX_AFTER_ADDITION', p_log_level_rec => p_log_level_rec);
1277 raise val_err;
1278 end if;
1279
1280
1281 -- BUG# 4609532
1282 -- removing the following validation due to the fact that
1283 -- we now allow cip revaluations
1284 -- check invoices cost for corp only
1285
1286 end if; -- capitalize / reverse
1287
1288
1289 -- check retirements (pending / full)
1290
1291 if (p_log_level_rec.statement_level) then
1292 fa_debug_pkg.add(l_calling_fn,
1293 'checking fully ret', '' , p_log_level_rec => p_log_level_rec);
1294 end if;
1295
1296 if fa_asset_val_pvt.validate_fully_retired
1297 (p_asset_id => p_asset_hdr_rec.asset_id,
1298 p_book => p_asset_hdr_rec.book_type_code, p_log_level_rec => p_log_level_rec) then
1299 fa_srvr_msg.add_message
1300 (name => 'FA_REC_RETIRED',
1301 calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1302 raise val_err;
1303 end if;
1304
1305 if (p_log_level_rec.statement_level) then
1306 fa_debug_pkg.add(l_calling_fn,
1307 'checking ret pending', '' , p_log_level_rec => p_log_level_rec);
1308 end if;
1309
1310 if fa_asset_val_pvt.validate_ret_rst_pending
1311 (p_asset_id => p_asset_hdr_rec.asset_id,
1312 p_book => p_asset_hdr_rec.book_type_code, p_log_level_rec => p_log_level_rec) then
1313 raise val_err;
1314 end if;
1315
1316 return true;
1317
1318 exception
1319 when val_err then
1320 fa_srvr_msg.add_message(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1321 return false;
1322
1323 when others then
1324 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1325 return false;
1326
1327 end do_validation;
1328
1329 ------------------------------------------------------------------------
1330
1331 END FA_CIP_PVT;