[Home] [Help]
PACKAGE BODY: APPS.FA_UNPLANNED_PVT
Source
1 PACKAGE BODY FA_UNPLANNED_PVT as
2 /* $Header: FAVUNPLB.pls 120.22.12010000.2 2008/07/31 07:05:26 sbhaskar ship $ */
3
4
5 FUNCTION do_unplanned
6 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
7 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
8 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
9 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
10 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
11 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
12 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type,
13 p_unplanned_deprn_rec IN FA_API_TYPES.unplanned_deprn_rec_type,
14 p_period_rec IN FA_API_TYPES.period_rec_type,
15 p_mrc_sob_type_code IN VARCHAR2,
16 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return boolean is
17
18 -- used for method cache
19 l_deprn_basis_rule VARCHAR2(4);
20 l_rate_source_rule VARCHAR2(10);
21
22 -- used for mrc
23 l_debit_credit_flag VARCHAR2(2);
24 l_unplanned_amount NUMBER;
25 l_amount_inserted NUMBER;
26
27 --
28 -- For calling faxama.
29 --
30 l_deprn_exp NUMBER := 0;
31 l_bonus_deprn_exp NUMBER := 0;
32 l_deprn_rsv NUMBER := 0;
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_group_reclass_options_rec FA_API_TYPES.group_reclass_options_rec_type;
36 l_temp_raf NUMBER;
37
38 l_status boolean;
39 l_rowid rowid;
40
41 l_transaction_subtype VARCHAR2(9);
42 l_transaction_key VARCHAR2(2);
43 l_rounding_flag VARCHAR2(3);
44 l_deprn_adjustment_amount NUMBER := 0; -- Bug:4944700
45
46 l_adj fa_adjust_type_pkg.fa_adj_row_struct;
47
48 -- used for return values
49 l_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
50 l_asset_fin_rec_null FA_API_TYPES.asset_fin_rec_type;
51 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
52
53 deprn_override_flag_default varchar2(1);
54
55 l_deprn_exp_amort_nbv number := 0; -- Bug:4944700
56 l_reserve_adjustment_amount number := 0; -- Bug:4944700
57
58 l_calling_fn VARCHAR2(35) := 'fa_unplanned_pvt.do_unplanned';
59 unp_err EXCEPTION;
60
61 -- Bug:6665510:Japan Tax Reform Project
62 l_method_type number := 0;
63 l_success integer;
64 l_rate_in_use number;
65
66 BEGIN
67
68 if (p_log_level_rec.statement_level) then
69 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_hdr_rec.asset_id
70 ,p_log_level_rec => p_log_level_rec);
71 end if;
72
73 l_asset_fin_rec := p_asset_fin_rec;
74
75 l_unplanned_amount := p_unplanned_deprn_rec.unplanned_amount;
76
77 -- SLA Uptake
78 -- removing period of addition check
79 /*
80 if (p_asset_hdr_rec.period_of_addition = 'Y') then
81 l_rounding_flag := 'RES';
82 l_transaction_key := NULL;
83 l_transaction_subtype := px_trans_rec.transaction_subtype;
84 else
85 */
86
87 l_rounding_flag := 'ADJ';
88 l_transaction_key := px_trans_rec.transaction_key;
89 l_transaction_subtype := p_unplanned_deprn_rec.unplanned_type;
90
91 -- end if;
92
93 deprn_override_flag_default:= fa_std_types.FA_NO_OVERRIDE;
94
95 if not FA_CACHE_PKG.fazccmt(p_asset_fin_rec.deprn_method_code,
96 p_asset_fin_rec.life_in_months
97 ,p_log_level_rec => p_log_level_rec) then
98 raise unp_err;
99 end if;
100
101
102 -- check that method is valid for unplanned - only need to due this for primary
103
104 if (p_mrc_sob_type_code <> 'R') then
105
106 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
107 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
108
109 if (l_rate_source_rule = 'TABLE' or
110 (l_deprn_basis_rule = 'NBV' and
111 l_rate_source_rule <> 'FLAT')) and
112 (not (l_deprn_basis_rule = 'NBV' and
113 l_rate_source_rule = 'PRODUCTION' and
114 fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE')) then
115
116 -- Bug:6665510:Japan Tax Reform Project
117 if not (l_rate_source_rule = 'FORMULA') then
118 fa_srvr_msg.add_message
119 (name => '*** unplanned not allowed ***',
120 calling_fn => l_calling_fn
121 ,p_log_level_rec => p_log_level_rec);
122 raise unp_err;
123 end if;
124 end if;
125
126
127 -- verify amount is less then recoverable cost or reserve
128
129 -- Fix for bug #2897597. If group asset has over depreciate
130 -- option as YES or DEPRN, then allow the unplanned amount to be
131 -- greater than the nbv
132
133 -- BUG# 2898745
134 -- nesting the comparison with reserve back under cost > 0
135 -- also adding checks to prevent negative cost assets
136 -- from over depreciating (previously, no restrictions existed)
137
138 if (p_asset_fin_rec.cost > 0) then
139 if (p_unplanned_deprn_rec.unplanned_amount > 0) then
140 if (p_unplanned_deprn_rec.unplanned_amount >
141 (p_asset_fin_rec.cost - p_asset_deprn_rec.deprn_reserve) and
142 (nvl(p_asset_fin_rec.over_depreciate_option, 'NO') not in
143 ('YES', 'DEPRN'))) then
144
145 fa_srvr_msg.add_message
146 (name => 'FA_UNP_DEP_AMT_1',
147 calling_fn => l_calling_fn
148 ,p_log_level_rec => p_log_level_rec);
149 raise unp_err;
150 end if;
151 elsif (p_unplanned_deprn_rec.unplanned_amount < 0) and
152 (p_asset_type_rec.asset_type <> 'GROUP') then
153 if ((-1) * (p_unplanned_deprn_rec.unplanned_amount) > p_asset_deprn_rec.deprn_reserve) then
154
155 fa_srvr_msg.add_message
156 (name => 'FA_UNP_DEP_AMT_2',
157 calling_fn => l_calling_fn
158 ,p_log_level_rec => p_log_level_rec);
159 raise unp_err;
160 end if;
161 end if;
162 elsif (p_asset_fin_rec.cost < 0) then
163 if (p_unplanned_deprn_rec.unplanned_amount < 0) then
164 if (p_unplanned_deprn_rec.unplanned_amount <
165 (p_asset_fin_rec.cost - p_asset_deprn_rec.deprn_reserve) and
166 (nvl(p_asset_fin_rec.over_depreciate_option, 'NO') not in
167 ('YES', 'DEPRN'))) then
168
169 fa_srvr_msg.add_message
170 (name => 'FA_UNP_DEP_AMT_1',
171 calling_fn => l_calling_fn
172 ,p_log_level_rec => p_log_level_rec);
173 raise unp_err;
174 end if;
175 elsif (p_unplanned_deprn_rec.unplanned_amount > 0) and
176 (p_asset_type_rec.asset_type <> 'GROUP') then
177 if (p_unplanned_deprn_rec.unplanned_amount > (-1 * p_asset_deprn_rec.deprn_reserve)) then
178
179 fa_srvr_msg.add_message
180 (name => 'FA_UNP_DEP_AMT_2',
181 calling_fn => l_calling_fn
182 ,p_log_level_rec => p_log_level_rec);
183 raise unp_err;
184 end if;
185 end if;
186
187 end if;
188
189 -- SLA Uptake
190 -- remocing this as it's treated as standard unplanned now
191
192 /*
193 -- void original addition row in period of addition
194 if (p_asset_hdr_rec.period_of_addition = 'Y') then
195 FA_TRANSACTION_HEADERS_PKG.Update_Trx_Type
196 (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
197 X_Asset_Id => p_asset_hdr_rec.asset_id,
198 X_Transaction_Type_Code => px_trans_rec.transaction_type_code,
199 X_New_Transaction_Type => px_trans_rec.transaction_type_code || '/VOID',
200 X_Return_Status => l_status,
201 X_Calling_Fn => l_calling_fn
202 ,p_log_level_rec => p_log_level_rec);
203 end if;
204
205 if not l_status then
206 raise unp_err;
207 end if;
208
209 */
210 -- SLA UPTAKE
211 -- assign an event for the transaction
212 -- at this point key info asset/book/trx info is known from initialize
213 -- call and the above code (i.e. trx_type, etc)
214
215 select fa_transaction_headers_s.nextval
216 into px_trans_rec.transaction_header_id
217 from dual;
218
219 if not fa_xla_events_pvt.create_transaction_event
220 (p_asset_hdr_rec => p_asset_hdr_rec,
221 p_asset_type_rec=> p_asset_type_rec,
222 px_trans_rec => px_trans_rec,
223 p_event_status => NULL,
224 p_calling_fn => l_calling_fn
225 ,p_log_level_rec => p_log_level_rec) then
226 raise unp_err;
227 end if;
228
229 FA_TRANSACTION_HEADERS_PKG.Insert_Row
230 (X_Rowid => l_rowid,
231 X_Transaction_Header_Id => px_trans_rec.transaction_header_id,
232 X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
233 X_Asset_Id => p_asset_hdr_rec.asset_id,
234 X_Transaction_Type_Code => px_trans_rec.transaction_type_code,
235 X_Transaction_Date_Entered => px_trans_rec.transaction_date_entered,
236 X_Date_Effective => px_trans_rec.who_info.creation_date,
237 X_Last_Update_Date => px_trans_rec.who_info.last_update_date,
238 X_Last_Updated_By => px_trans_rec.who_info.last_updated_by,
239 X_Transaction_Name => px_trans_rec.transaction_name,
240 X_Invoice_Transaction_Id => NULL,
241 X_Source_Transaction_Header_Id => px_trans_rec.source_transaction_header_id,
242 X_Mass_Reference_Id => px_trans_rec.mass_reference_id,
243 X_Last_Update_Login => px_trans_rec.who_info.last_update_login,
244 X_Transaction_Subtype => l_transaction_subtype,
245 X_Attribute1 => px_trans_rec.desc_flex.attribute1,
246 X_Attribute2 => px_trans_rec.desc_flex.attribute2,
247 X_Attribute3 => px_trans_rec.desc_flex.attribute3,
248 X_Attribute4 => px_trans_rec.desc_flex.attribute4,
249 X_Attribute5 => px_trans_rec.desc_flex.attribute5,
250 X_Attribute6 => px_trans_rec.desc_flex.attribute6,
251 X_Attribute7 => px_trans_rec.desc_flex.attribute7,
252 X_Attribute8 => px_trans_rec.desc_flex.attribute8,
253 X_Attribute9 => px_trans_rec.desc_flex.attribute9,
254 X_Attribute10 => px_trans_rec.desc_flex.attribute10,
255 X_Attribute11 => px_trans_rec.desc_flex.attribute11,
256 X_Attribute12 => px_trans_rec.desc_flex.attribute12,
257 X_Attribute13 => px_trans_rec.desc_flex.attribute13,
258 X_Attribute14 => px_trans_rec.desc_flex.attribute14,
259 X_Attribute15 => px_trans_rec.desc_flex.attribute15,
260 X_Attribute_Category_Code => px_trans_rec.desc_flex.attribute_category_code,
261 X_Transaction_Key => l_transaction_key,
262 X_Amortization_Start_Date => NULL,
263 X_Calling_Interface => px_trans_rec.calling_interface,
264 X_Mass_Transaction_ID => px_trans_rec.mass_transaction_id,
265 X_member_transaction_header_id => px_trans_rec.member_transaction_header_id,
266 X_event_id => px_trans_rec.event_id,
267 X_Return_Status => l_status,
268 X_Calling_Fn => l_calling_fn
269 ,p_log_level_rec => p_log_level_rec);
270
271 if not l_status then
272 raise unp_err;
273 end if;
274
275 end if; -- primary book
276
277 -- Bug:4944700
278 -- round the amount to correct precision and use correct sign
279
280 if not FA_UTILS_PKG.faxrnd
281 (X_amount => l_unplanned_amount,
282 X_book => p_asset_hdr_rec.book_type_code
283 ,p_log_level_rec => p_log_level_rec) then
284 raise unp_err;
285 end if;
286
287
288 -- If the processed asset is the member asset whose tracking method is 'ALLOCATE',
289 -- system should not process the amortization for the member level.
290
291 -- Bug 5506943 Allowing for Allocate also.
292
293 if (l_asset_fin_rec.group_asset_id is null) or
294 (l_asset_fin_rec.group_asset_id is not null and
295 nvl(l_asset_fin_rec.tracking_method,'OTHER') <> 'OTHER') then
296
297 -- Bug:4944700
298 l_asset_deprn_rec_adj.deprn_amount := p_unplanned_deprn_rec.unplanned_amount;
299
300 if (px_trans_rec.transaction_subtype = 'AMORTIZED') then
301
302 if (p_log_level_rec.statement_level) then
303 fa_debug_pkg.add(l_calling_fn, 'Calling', 'FA_AMORT_PVT.calc_raf_adj_cost'
304 ,p_log_level_rec => p_log_level_rec);
305 fa_debug_pkg.add(l_calling_fn, 'before adj cap', l_asset_fin_rec.adjusted_capacity
306 ,p_log_level_rec => p_log_level_rec);
307 end if;
308
309 -- Bug:4944700 (removed the faxama call)
310
311 if not FA_AMORT_PVT.calc_raf_adj_cost
312 (p_trans_rec => px_trans_rec,
313 p_asset_hdr_rec => p_asset_hdr_rec,
314 p_asset_desc_rec => p_asset_desc_rec,
315 p_asset_type_rec => p_asset_type_rec,
316 p_asset_fin_rec_old => p_asset_fin_rec,
317 px_asset_fin_rec_new => l_asset_fin_rec,
318 p_asset_deprn_rec_adj => l_asset_deprn_rec_adj,
319 p_asset_deprn_rec_new => p_asset_deprn_rec, -- Bug:4944700
320 p_period_rec => p_period_rec,
321 p_group_reclass_options_rec => l_group_reclass_options_rec,
322 p_mrc_sob_type_code => p_mrc_sob_type_code
323 ,p_log_level_rec => p_log_level_rec) then
324 if (p_log_level_rec.statement_level) then
325 fa_debug_pkg.add(l_calling_fn, 'Failed calling', 'FA_AMORT_PVT.calc_raf_adj_cost'
326 ,p_log_level_rec => p_log_level_rec);
327 end if;
328 raise unp_err;
329 end if;
330
331 if (p_log_level_rec.statement_level) then
332 fa_debug_pkg.add(l_calling_fn, 'after adj cap', l_asset_fin_rec.adjusted_capacity
333 ,p_log_level_rec => p_log_level_rec);
334 fa_debug_pkg.add(l_calling_fn, 'End Calling', 'FA_AMORT_PVT.calc_raf_adj_cost'
335 ,p_log_level_rec => p_log_level_rec);
336 end if;
337
338 -- no need to insert any catchup as we're already inserting
339 -- the value provided... so skipping call to faxiat
340
341 end if; -- end amortize
342
343 l_asset_fin_rec.adjustment_required_status := 'NONE';
344
345 l_temp_raf := l_asset_fin_rec.rate_adjustment_factor;
346
347
348 ----------------------------------------------
349 -- Call Depreciable Basis Rule
350 -- for Unplanned Depreciation
351 ----------------------------------------------
352 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
353 (
354 p_event_type => 'UNPLANNED_ADJ',
355 p_asset_fin_rec_new => p_asset_fin_rec,
356 p_asset_fin_rec_old => p_asset_fin_rec,
357 p_asset_hdr_rec => p_asset_hdr_rec,
358 p_asset_type_rec => p_asset_type_rec,
359 p_asset_deprn_rec => p_asset_deprn_rec,
360 p_trans_rec => px_trans_rec,
361 p_period_rec => p_period_rec,
362 p_unplanned_deprn_rec => p_unplanned_deprn_rec,
363 p_mrc_sob_type_code => p_mrc_sob_type_code,
364 px_new_adjusted_cost => l_asset_fin_rec.adjusted_cost,
365 px_new_raf => l_asset_fin_rec.rate_adjustment_factor,
366 px_new_formula_factor => l_asset_fin_rec.formula_factor
367 ,p_log_level_rec => p_log_level_rec)
368 )
369 then
370 raise unp_err;
371 end if;
372
373 -- Deprn basis function has been called in calc_raf_adj above so
374 -- do not call deprn basis function if it's been called
375 -- In Addition to the above case,
376 -- ENERGY
377 -- Replace raf with the raf returned by faxama call.
378 -- If this asset is:
379 -- 1. Member of Energy Straight line group
380 -- 2. tracking method is calculate
381 -- This is because raf is set in previous faxama call.
382 -- Also, above depreciable basis call was made without hypo amounts that
383 -- is mandatory for raf calculation.
384 if ((l_asset_fin_rec.group_asset_id is null and
385 px_trans_rec.transaction_subtype = 'AMORTIZED' and
386 p_asset_type_rec.asset_type = 'GROUP'))
387 or
388 ((p_asset_type_rec.asset_type <> 'GROUP') and
389 (l_asset_fin_rec.group_asset_id is not null) and
390 (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') and
391 (nvl(l_asset_fin_rec.tracking_method, 'NO TRACK') = 'CALCULATE')) then
392
393 l_asset_fin_rec.rate_adjustment_factor := l_temp_raf;
394
395 end if;
396
397 if (l_unplanned_amount <> 0) then
398 l_asset_fin_rec.period_counter_fully_reserved := NULL;
399 end if;
400
401 l_asset_fin_rec.period_counter_life_complete := l_asset_fin_rec.period_counter_fully_reserved;
402
403 -- terminate the row
404 fa_books_pkg.deactivate_row
405 (X_asset_id => p_asset_hdr_rec.asset_id,
406 X_book_type_code => p_asset_hdr_rec.book_type_code,
407 X_transaction_header_id_out => px_trans_rec.transaction_header_id,
408 X_date_ineffective => px_trans_rec.who_info.last_update_date,
409 X_mrc_sob_type_code => p_mrc_sob_type_code,
410 X_Calling_Fn => l_calling_fn
411 ,p_log_level_rec => p_log_level_rec);
412
413 l_rowid := null;
414
415 -- ENERGY
416 -- This is not only change for energy. Allocation of unplanned amount must be done in
417 -- process group adjustment in case of large number of member assets exist for a group.
418 -- A condition refering 'ENERGY PERIOD END BALANCE' can be removed from rel 12.
419 if (px_trans_rec.calling_interface = 'FAXASSET') and
420 (l_asset_fin_rec.group_asset_id is null and
421 nvl(l_asset_fin_rec.tracking_method, 'NO TRACK') = 'ALLOCATE')
422 and (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE')
423 then
424 l_asset_fin_rec.adjustment_required_status := 'GADJ';
425
426
427 if not fa_xla_events_pvt.update_transaction_event
428 (p_ledger_id => p_asset_hdr_rec.set_of_books_id,
429 p_transaction_header_id => px_trans_rec.transaction_header_id,
430 p_book_type_code => p_asset_hdr_rec.book_type_code,
431 p_event_type_code => 'UNPLANNED_DEPRECIATION',
432 p_event_date => px_trans_rec.transaction_date_entered, --?
433 p_event_status_code => XLA_EVENTS_PUB_PKG.C_EVENT_INCOMPLETE,
434 p_calling_fn => l_calling_fn,
435 p_log_level_rec => p_log_level_rec) then
436 raise unp_err;
437 end if;
438
439 end if;
440
441
442 -- insert the row
443 fa_books_pkg.insert_row
444 (X_Rowid => l_rowid,
445 X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
446 X_Asset_Id => p_asset_hdr_rec.asset_id,
447 X_Date_Placed_In_Service => l_asset_fin_rec.date_placed_in_service,
448 X_Date_Effective => px_trans_rec.who_info.last_update_date,
449 X_Deprn_Start_Date => l_asset_fin_rec.deprn_start_date,
450 X_Deprn_Method_Code => l_asset_fin_rec.deprn_method_code,
451 X_Life_In_Months => l_asset_fin_rec.life_in_months,
452 X_Rate_Adjustment_Factor => l_asset_fin_rec.rate_adjustment_factor,
453 X_Adjusted_Cost => l_asset_fin_rec.adjusted_cost,
454 X_Cost => l_asset_fin_rec.cost,
455 X_Original_Cost => l_asset_fin_rec.original_cost,
456 X_Salvage_Value => l_asset_fin_rec.salvage_value,
457 X_Prorate_Convention_Code => l_asset_fin_rec.prorate_convention_code,
458 X_Prorate_Date => l_asset_fin_rec.prorate_date,
459 X_Cost_Change_Flag => l_asset_fin_rec.cost_change_flag,
460 X_Adjustment_Required_Status => l_asset_fin_rec.adjustment_required_status,
461 X_Capitalize_Flag => l_asset_fin_rec.capitalize_flag,
462 X_Retirement_Pending_Flag => l_asset_fin_rec.retirement_pending_flag,
463 X_Depreciate_Flag => l_asset_fin_rec.depreciate_flag,
464 X_Disabled_Flag => l_asset_fin_rec.disabled_flag, --HH
465 X_Last_Update_Date => px_trans_rec.who_info.last_update_date,
466 X_Last_Updated_By => px_trans_rec.who_info.last_updated_by,
467 X_Date_Ineffective => NULL,
468 X_Transaction_Header_Id_In => px_trans_rec.transaction_header_id,
469 X_Transaction_Header_Id_Out => NULL,
470 X_Itc_Amount_Id => l_asset_fin_rec.itc_amount_id,
471 X_Itc_Amount => l_asset_fin_rec.itc_amount,
472 X_Retirement_Id => l_asset_fin_rec.retirement_id,
473 X_Tax_Request_Id => l_asset_fin_rec.tax_request_id,
474 X_Itc_Basis => l_asset_fin_rec.itc_basis,
475 X_Basic_Rate => l_asset_fin_rec.basic_rate,
476 X_Adjusted_Rate => l_asset_fin_rec.adjusted_rate,
477 X_Bonus_Rule => l_asset_fin_rec.bonus_rule,
478 X_Ceiling_Name => l_asset_fin_rec.ceiling_name,
479 X_Recoverable_Cost => l_asset_fin_rec.recoverable_cost,
480 X_Last_Update_Login => px_trans_rec.who_info.last_update_login,
481 X_Adjusted_Capacity => l_asset_fin_rec.adjusted_capacity,
482 X_Fully_Rsvd_Revals_Counter => l_asset_fin_rec.fully_rsvd_revals_counter,
483 X_Idled_Flag => l_asset_fin_rec.idled_flag,
484 X_Period_Counter_Capitalized => l_asset_fin_rec.period_counter_capitalized,
485 X_PC_Fully_Reserved => l_asset_fin_rec.period_counter_fully_reserved,
486 X_Period_Counter_Fully_Retired => l_asset_fin_rec.period_counter_fully_retired,
487 X_Production_Capacity => l_asset_fin_rec.production_capacity,
488 X_Reval_Amortization_Basis => l_asset_fin_rec.reval_amortization_basis,
489 X_Reval_Ceiling => l_asset_fin_rec.reval_ceiling,
490 X_Unit_Of_Measure => l_asset_fin_rec.unit_of_measure,
491 X_Unrevalued_Cost => l_asset_fin_rec.unrevalued_cost,
492 X_Annual_Deprn_Rounding_Flag => l_rounding_flag,
493 X_Percent_Salvage_Value => l_asset_fin_rec.percent_salvage_value,
494 X_Allowed_Deprn_Limit => l_asset_fin_rec.allowed_deprn_limit,
495 X_Allowed_Deprn_Limit_Amount => l_asset_fin_rec.allowed_deprn_limit_amount,
496 X_Period_Counter_Life_Complete => l_asset_fin_rec.period_counter_life_complete,
497 X_Adjusted_Recoverable_Cost => l_asset_fin_rec.adjusted_recoverable_cost,
498 X_Short_Fiscal_Year_Flag => l_asset_fin_rec.short_fiscal_year_flag,
499 X_Conversion_Date => l_asset_fin_rec.conversion_date,
500 X_Orig_Deprn_Start_Date => l_asset_fin_rec.orig_deprn_start_date,
501 X_Remaining_Life1 => l_asset_fin_rec.remaining_life1,
502 X_Remaining_Life2 => l_asset_fin_rec.remaining_life2,
503 X_Old_Adj_Cost => l_asset_fin_rec.old_adjusted_cost,
504 X_Formula_Factor => l_asset_fin_rec.formula_factor,
505 X_gf_Attribute1 => l_asset_fin_rec.global_attribute1,
506 X_gf_Attribute2 => l_asset_fin_rec.global_attribute2,
507 X_gf_Attribute3 => l_asset_fin_rec.global_attribute3,
508 X_gf_Attribute4 => l_asset_fin_rec.global_attribute4,
509 X_gf_Attribute5 => l_asset_fin_rec.global_attribute5,
510 X_gf_Attribute6 => l_asset_fin_rec.global_attribute6,
511 X_gf_Attribute7 => l_asset_fin_rec.global_attribute7,
512 X_gf_Attribute8 => l_asset_fin_rec.global_attribute8,
513 X_gf_Attribute9 => l_asset_fin_rec.global_attribute9,
514 X_gf_Attribute10 => l_asset_fin_rec.global_attribute10,
515 X_gf_Attribute11 => l_asset_fin_rec.global_attribute11,
516 X_gf_Attribute12 => l_asset_fin_rec.global_attribute12,
517 X_gf_Attribute13 => l_asset_fin_rec.global_attribute13,
518 X_gf_Attribute14 => l_asset_fin_rec.global_attribute14,
519 X_gf_Attribute15 => l_asset_fin_rec.global_attribute15,
520 X_gf_Attribute16 => l_asset_fin_rec.global_attribute16,
521 X_gf_Attribute17 => l_asset_fin_rec.global_attribute17,
522 X_gf_Attribute18 => l_asset_fin_rec.global_attribute18,
523 X_gf_Attribute19 => l_asset_fin_rec.global_attribute19,
524 X_gf_Attribute20 => l_asset_fin_rec.global_attribute20,
525 X_global_attribute_category => l_asset_fin_rec.global_attribute_category,
526 X_group_asset_id => l_asset_fin_rec.group_asset_id,
527 X_salvage_type => l_asset_fin_rec.salvage_type,
528 X_deprn_limit_type => l_asset_fin_rec.deprn_limit_type,
529 X_over_depreciate_option => l_asset_fin_rec.over_depreciate_option,
530 X_super_group_id => l_asset_fin_rec.super_group_id,
531 X_reduction_rate => l_asset_fin_rec.reduction_rate,
532 X_reduce_addition_flag => l_asset_fin_rec.reduce_addition_flag,
533 X_reduce_adjustment_flag => l_asset_fin_rec.reduce_adjustment_flag,
534 X_reduce_retirement_flag => l_asset_fin_rec.reduce_retirement_flag,
535 X_recognize_gain_loss => l_asset_fin_rec.recognize_gain_loss,
536 X_recapture_reserve_flag => l_asset_fin_rec.recapture_reserve_flag,
537 X_limit_proceeds_flag => l_asset_fin_rec.limit_proceeds_flag,
538 X_terminal_gain_loss => l_asset_fin_rec.terminal_gain_loss,
539 X_exclude_proceeds_from_basis => l_asset_fin_rec.exclude_proceeds_from_basis,
540 X_retirement_deprn_option => l_asset_fin_rec.retirement_deprn_option,
541 X_tracking_method => l_asset_fin_rec.tracking_method,
542 X_allocate_to_fully_rsv_flag => l_asset_fin_rec.allocate_to_fully_rsv_flag,
543 X_allocate_to_fully_ret_flag => l_asset_fin_rec.allocate_to_fully_ret_flag,
544 X_exclude_fully_rsv_flag => l_asset_fin_rec.exclude_fully_rsv_flag,
545 X_excess_allocation_option => l_asset_fin_rec.excess_allocation_option,
546 X_depreciation_option => l_asset_fin_rec.depreciation_option,
547 X_member_rollup_flag => l_asset_fin_rec.member_rollup_flag,
548 X_ytd_proceeds => l_asset_fin_rec.ytd_proceeds,
549 X_ltd_proceeds => l_asset_fin_rec.ltd_proceeds,
550 X_eofy_reserve => l_asset_fin_rec.eofy_reserve,
551 X_cip_cost => l_asset_fin_rec.cip_cost,
552 X_terminal_gain_loss_amount => l_asset_fin_rec.terminal_gain_loss_amount,
553 X_ltd_cost_of_removal => l_asset_fin_rec.ltd_cost_of_removal,
554 X_extended_deprn_flag => l_asset_fin_rec.extended_deprn_flag, -- Bug:6665510:Japan Tax Reform Project
555 X_extended_depreciation_period => l_asset_fin_rec.extended_depreciation_period, -- Bug:6665510:Japan Tax Reform Project
556 X_mrc_sob_type_code => p_mrc_sob_type_code,
557 X_Return_Status => l_status,
558 X_Calling_Fn => l_calling_fn
559 ,p_log_level_rec => p_log_level_rec);
560
561 if not l_status then
562 raise unp_err;
563 end if;
564
565 -- Bug:6665510:Japan Tax Reform Project
566 if fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag = 'YES' then
567 if (p_mrc_sob_type_code <> 'R') then
568 FA_CDE_PKG.faxgfr (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
569 X_Asset_Id => p_asset_hdr_rec.asset_id,
570 X_Short_Fiscal_Year_Flag => l_asset_fin_rec.short_fiscal_year_flag,
571 X_Conversion_Date => l_asset_fin_rec.conversion_date,
572 X_Prorate_Date => l_asset_fin_rec.prorate_date,
573 X_Orig_Deprn_Start_Date => l_asset_fin_rec.orig_deprn_start_date,
574 C_Prorate_Date => NULL,
575 C_Conversion_Date => NULL,
576 C_Orig_Deprn_Start_Date => NULL,
577 X_Method_Code => l_asset_fin_rec.deprn_method_code,
578 X_Life_In_Months => l_asset_fin_rec.life_in_months,
579 X_Fiscal_Year => -99,
580 X_Current_Period => p_period_rec.period_counter,
581 X_calling_interface => 'UNPLANNED',
582 X_Rate => l_rate_in_use,
583 X_Method_Type => l_method_type,
584 X_Success => l_success);
585
586 if (l_success <= 0) then
587 fa_srvr_msg.add_message(calling_fn => 'FA_UNPLANNED_PVT.do_unplanned');
588 raise unp_err;
589 end if;
590
591 Update FA_BOOKS
592 Set rate_in_use = l_rate_in_use
593 Where book_type_code = p_asset_hdr_rec.book_type_code
594 And asset_id = p_asset_hdr_rec.asset_id
595 And date_ineffective is null;
596 end if;
597 end if;
598
599 -- ENERGY
600 -- Energy requires to treat unplan in period of addition as performed in
601 -- other period so that group gets expense rows.
602 -- From Rel 12, there will be no difference between behavior of unplan in
603 -- period of addition and other period.
604 --
605 -- SLA Uptake
606 -- removing this check completely, all trxs will be handled same way
607 --
608 -- if (p_asset_hdr_rec.period_of_addition <> 'Y')
609 -- and (nvl(fa_cache_pkg.fazcdrd_record.rule_name, 'NULL') <> 'ENERGY PERIOD END BALANCE') then
610
611 if (l_unplanned_amount > 0) then
612 l_debit_credit_flag := 'DR';
613 l_unplanned_amount := l_unplanned_amount;
614 else
615 l_debit_credit_flag := 'CR';
616 l_unplanned_amount := (-1) * l_unplanned_amount;
617 end if;
618
619 l_adj.transaction_header_id := px_trans_rec.transaction_header_id;
620 l_adj.asset_id := p_asset_hdr_rec.asset_id;
621 l_adj.book_type_code := p_asset_hdr_rec.book_type_code;
622 l_adj.period_counter_created := p_period_rec.period_counter;
623 l_adj.period_counter_adjusted := p_period_rec.period_counter;
624 l_adj.current_units := p_asset_desc_rec.current_units ;
625 l_adj.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE;
626 l_adj.selection_thid := 0;
627 l_adj.selection_retid := 0;
628 l_adj.leveling_flag := FALSE;
629 l_adj.last_update_date := px_trans_rec.who_info.last_update_date;
630
631 l_adj.flush_adj_flag := TRUE;
632 l_adj.gen_ccid_flag := FALSE;
633 l_adj.annualized_adjustment := 0;
634 l_adj.asset_invoice_id := 0;
635 l_adj.code_combination_id := p_unplanned_deprn_rec.code_combination_id;
636 l_adj.distribution_id := 0;
637
638 l_adj.deprn_override_flag:= '';
639
640 l_adj.source_type_code := 'DEPRECIATION';
641 l_adj.adjustment_type := 'EXPENSE';
642 l_adj.account := FA_UNPLANNED_PUB.G_expense_account;
643 l_adj.account_type := 'DEPRN_EXPENSE_ACCT';
644 l_adj.debit_credit_flag := l_debit_credit_flag;
645 l_adj.adjustment_amount := l_unplanned_amount;
646 l_adj.mrc_sob_type_code := p_mrc_sob_type_code;
647
648 if (l_asset_fin_rec.group_asset_id is not null) and
649 (nvl(l_asset_fin_rec.member_rollup_flag, 'N') = 'N') then
650 l_adj.track_member_flag := 'Y';
651 else
652 l_adj.track_member_flag := null;
653 end if;
654
655 if not FA_INS_ADJUST_PKG.faxinaj
656 (l_adj,
657 px_trans_rec.who_info.last_update_date,
658 px_trans_rec.who_info.last_updated_by,
659 px_trans_rec.who_info.last_update_login
660 ,p_log_level_rec => p_log_level_rec) then
661 raise unp_err;
662 end if;
663
664 /*
665 else -- period of addition
666
667 -- get any current deprn adjustment amount balance (not available in query bal)
668 if (p_mrc_sob_type_code = 'R') then
669
670 select sum(nvl(deprn_adjustment_amount, 0))
671 into l_deprn_adjustment_amount
672 from fa_deprn_detail_mrc_v
673 where asset_id = p_asset_hdr_rec.asset_id
674 and book_type_code = p_asset_hdr_rec.book_type_code;
675
676 select nvl(sum(decode(debit_credit_flag,
677 'DR', adjustment_amount,
678 -adjustment_amount)), 0)
679 into l_deprn_exp_amort_nbv
680 from fa_adjustments_mrc_v
681 where book_type_code = p_asset_hdr_rec.book_type_code
682 and asset_id = p_asset_hdr_rec.asset_id
683 and source_type_code = 'DEPRECIATION'
684 and adjustment_type = 'EXPENSE';
685
686 select nvl(sum(decode(debit_credit_flag,
687 'CR', adjustment_amount,
688 -adjustment_amount)), 0)
689 into l_reserve_adjustment_amount
690 from fa_adjustments_mrc_v
691 where book_type_code = p_asset_hdr_rec.book_type_code
692 and asset_id = p_asset_hdr_rec.asset_id
693 and source_type_code = 'ADJUSTMENT'
694 and adjustment_type = 'RESERVE';
695
696 else -- primary
697
698 select sum(nvl(deprn_adjustment_amount, 0))
699 into l_deprn_adjustment_amount
700 from fa_deprn_detail
701 where asset_id = p_asset_hdr_rec.asset_id
702 and book_type_code = p_asset_hdr_rec.book_type_code;
703
704 select nvl(sum(decode(debit_credit_flag,
705 'DR', adjustment_amount,
706 -adjustment_amount)), 0)
707 into l_deprn_exp_amort_nbv
708 from fa_adjustments
709 where book_type_code = p_asset_hdr_rec.book_type_code
710 and asset_id = p_asset_hdr_rec.asset_id
711 and source_type_code = 'DEPRECIATION'
712 and adjustment_type = 'EXPENSE';
713
714 select nvl(sum(decode(debit_credit_flag,
715 'CR', adjustment_amount,
716 -adjustment_amount)), 0)
717 into l_reserve_adjustment_amount
718 from fa_adjustments
719 where book_type_code = p_asset_hdr_rec.book_type_code
720 and asset_id = p_asset_hdr_rec.asset_id
721 and source_type_code = 'ADJUSTMENT'
722 and adjustment_type = 'RESERVE';
723
724 end if;
725
726 -- calculate new value using unplanned amount as delta
727 l_asset_deprn_rec.deprn_reserve := p_unplanned_deprn_rec.unplanned_amount +
728 nvl(l_asset_deprn_rec.deprn_reserve, 0) -
729 l_reserve_adjustment_amount -
730 l_deprn_exp_amort_nbv;
731 l_asset_deprn_rec.ytd_deprn := p_unplanned_deprn_rec.unplanned_amount +
732 nvl(l_asset_deprn_rec.ytd_deprn, 0) -
733 l_deprn_exp_amort_nbv;
734 l_deprn_adjustment_amount := p_unplanned_deprn_rec.unplanned_amount + nvl(l_deprn_adjustment_amount, 0);
735
736
737 FA_DEPRN_SUMMARY_PKG.Update_Row
738 (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
739 X_Asset_Id => p_asset_hdr_rec.asset_id,
740 X_Ytd_Deprn => l_asset_deprn_rec.ytd_deprn,
741 X_Deprn_Reserve => l_asset_deprn_rec.deprn_reserve,
742 X_Period_Counter => FA_CACHE_PKG.fazcbc_record.last_period_counter,
743 X_mrc_sob_type_code => p_mrc_sob_type_code,
744 X_Calling_Fn => l_calling_fn
745 ,p_log_level_rec => p_log_level_rec);
746
747 if not FA_INS_DETAIL_PKG.FAXINDD
748 (X_book_type_code => p_asset_hdr_rec.book_type_code,
749 X_asset_id => p_asset_hdr_rec.asset_id,
750 X_deprn_adjustment_amount => l_deprn_adjustment_amount,
751 X_mrc_sob_type_code => p_mrc_sob_type_code
752 ,p_log_level_rec => p_log_level_rec) then raise unp_err;
753 end if;
754
755 end if; -- end if period of addition
756 */ -- SLA
757
758 end if; -- check if the processed asset is not a member asset with ALLOCATE method
759
760
761 return true;
762
763
764 EXCEPTION
765 when unp_err then
766 fa_srvr_msg.add_message(calling_fn => l_calling_fn
767 ,p_log_level_rec => p_log_level_rec);
768 return false;
769
770 when others then
771 fa_srvr_msg.add_sql_error
772 (calling_fn => l_calling_fn
773 ,p_log_level_rec => p_log_level_rec);
774 return false;
775
776 END do_unplanned;
777
778 END FA_UNPLANNED_PVT;