[Home] [Help]
PACKAGE BODY: APPS.FA_AMORT_PVT
Source
1 PACKAGE BODY FA_AMORT_PVT as
2 /* $Header: FAVAMRTB.pls 120.204.12010000.6 2008/10/10 22:27:12 tkawamur ship $ */
3
4 /* Global temporary variables */
5 g_temp_date1 date;
6 g_temp_date2 date;
7 g_temp_integer BINARY_INTEGER;
8 g_temp_number number;
9 g_temp_char30 varchar2(30);
10
11 /* Global constant variables */
12
13 G_ASSET_TYPE_GROUP varchar2(5) := 'GROUP';
14 G_TRX_TYPE_TFR_OUT varchar2(30) := 'TRANSFER OUT';
15 G_TRX_TYPE_TFR_IN varchar2(30) := 'TRANSFER IN';
16 G_TRX_TYPE_TFR varchar2(30) := 'TRANSFER';
17 G_TRX_TYPE_TFR_VOID varchar2(30) := 'TRANSFER IN/VOID';
18 G_TRX_TYPE_REI varchar2(30) := 'REINSTATEMENT';
19 G_TRX_TYPE_FUL_RET varchar2(30) := 'FULL RETIREMENT';
20 G_TRX_TYPE_PAR_RET varchar2(30) := 'PARTIAL RETIREMENT';
21 G_TRX_TYPE_GRP_CHG varchar2(30) := 'GROUP CHANGE';
22 G_TRX_TYPE_REC varchar2(30) := 'RECLASS';
23 G_TRX_TYPE_UNIT_ADJ varchar2(30) := 'UNIT ADJUSTMENT';
24 G_TRX_TYPE_REV varchar2(30) := 'REVALUATION';
25 G_TRX_TYPE_TAX varchar2(30) := 'TAX';
26 G_TRX_TYPE_ADD_VOID varchar2(30) := 'ADDITION/VOID'; -- Bug#5074327
27 G_TRX_TYPE_CIP_ADJ varchar2(30) := 'CIP ADJUSTMENT'; -- Bug#5191200
28 G_TRX_TYPE_ADD varchar2(30) := 'ADDITION';
29 G_TRX_TYPE_CIP_ADD varchar2(30) := 'CIP ADDITION'; -- Bug 7389010
30
31
32 /* Global temporary variables for member asset */
33 g_mem_deprn_reserve NUMBER;
34 g_mem_eofy_reserve NUMBER;
35 g_mem_ytd_deprn NUMBER;
36 g_mem_bonus_ytd_deprn NUMBER;
37 g_mem_bonus_deprn_reserve NUMBER;
38
39 --Bug 5149789
40 FUNCTION check_member_existence (
41 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type
42 , p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
43 RETURN BOOLEAN;
44
45 --Bug4938977: Adding a private function.
46 FUNCTION check_dpis_change (
47 p_book_type_code VARCHAR2,
48 p_transaction_header_id NUMBER,
49 p_group_asset_id NUMBER,
50 x_asset_fin_rec OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
51 x_period_counter_out OUT NOCOPY NUMBER,
52 p_mrc_sob_type_code VARCHAR2,
53 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
54 RETURN BOOLEAN;
55
56 PROCEDURE printBooksSummary(p_asset_id number,
57 p_book_type_code varchar2,
58 p_period_counter number default 0,
59 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) IS
60
61 CURSOR c_get_books_summary IS
62 select period_counter
63 , cost
64 -- , salvage_value
65 , member_salvage_value
66 , allowed_deprn_limit_amount
67 , adjusted_rate
68 , rate_adjustment_factor
69 , deprn_adjustment_amount
70 , deprn_amount
71 , ytd_deprn
72 , reserve_adjustment_amount
73 , deprn_reserve
74 from fa_books_summary
75 where asset_id = p_asset_id
76 and book_type_code = p_book_type_code
77 and period_counter >= nvl(p_period_counter, 1);
78
79 BEGIN
80
81 --tk_util.debug('period#: cost: sal: art: raf: eaj: exp: ytd: rsvadj: rsv');
82 /*
83 for r_bs in c_get_books_summary loop
84 --tk_util.debug(rpad(to_char(r_bs.period_counter), 7, ' ')||':'||
85 lpad(to_char(r_bs.cost), 10, ' ')||':'||
86 lpad(to_char(r_bs.member_salvage_value), 9, ' ')||':'||
87 lpad(nvl(to_char(r_bs.allowed_deprn_limit_amount), 'null'), 9, ' ')||':'||
88 lpad(to_char(r_bs.adjusted_rate), 9, ' ')||':'||
89 lpad(substrb(to_char(r_bs.rate_adjustment_factor), 1, 10), 10, ' ')||':'||
90 lpad(to_char(r_bs.deprn_adjustment_amount), 9, ' ')||':'||
91 lpad(to_char(r_bs.deprn_amount), 9, ' ')||':'||
92 lpad(to_char(r_bs.ytd_deprn), 10, ' ')||':'||
93 lpad(to_char(r_bs.reserve_adjustment_amount), 10, ' ')||':'||
94 lpad(to_char(r_bs.deprn_reserve), 10, ' ')
95 );
96 end loop;
97 */
98 null;
99 END printBooksSummary;
100
101 --+==============================================================================
102 -- Function: GetPeriodInfo
103 --
104 -- This function return period information.
105 -- The function should be called when period information is not available in
106 -- fa_deprn_periods, for all other cases, should call fazcdp to obtain period
107 -- information.
108 --+==============================================================================
109 FUNCTION GetPeriodInfo(
110 p_jdate NUMBER,
111 p_book_type_code VARCHAR2,
112 p_mrc_sob_type_code VARCHAR2,
113 x_period_rec OUT NOCOPY FA_API_TYPES.period_rec_type,
114 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return BOOLEAN IS
115
116 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.GetPeriodInfo';
117 get_err EXCEPTION;
118
119 CURSOR c_get_deprn_period_info IS
120 select period_counter
121 , period_name
122 , period_open_date
123 , period_close_date
124 , calendar_period_open_date
125 , calendar_period_close_date
126 , fiscal_year
127 , period_num
128 from fa_deprn_periods
129 where book_type_code = p_book_type_code
130 and to_date (to_char (p_jdate), 'J') between calendar_period_open_date
131 and calendar_period_close_date;
132
133 CURSOR c_get_mc_deprn_period_info IS
134 select period_counter
135 , period_name
136 , period_open_date
137 , period_close_date
138 , calendar_period_open_date
139 , calendar_period_close_date
140 , fiscal_year
141 , period_num
142 from fa_deprn_periods_mrc_v
143 where book_type_code = p_book_type_code
144 and to_date (to_char (p_jdate), 'J') between calendar_period_open_date
145 and calendar_period_close_date;
146
147 CURSOR c_get_period_info IS
148 select start_date
149 , end_date
150 from fa_calendar_periods
151 where calendar_type = fa_cache_pkg.fazcbc_record.deprn_calendar
152 and to_date (to_char (p_jdate), 'J') between start_date
153 and end_date;
154
155 BEGIN
156 if (p_log_level_rec.statement_level) then
157 fa_debug_pkg.add(l_calling_fn, 'Begin', p_jdate
158 ,p_log_level_rec => p_log_level_rec);
159 end if;
160
161 if p_mrc_sob_type_code = 'R' then
162 OPEN c_get_mc_deprn_period_info;
163 FETCH c_get_mc_deprn_period_info INTO x_period_rec.period_counter
164 , x_period_rec.period_name
165 , x_period_rec.period_open_date
166 , x_period_rec.period_close_date
167 , x_period_rec.calendar_period_open_date
168 , x_period_rec.calendar_period_close_date
169 , x_period_rec.fiscal_year
170 , x_period_rec.period_num;
171
172 if (c_get_mc_deprn_period_info%NOTFOUND) then
173
174 if not fa_cache_pkg.fazcct(fa_cache_pkg.fazcbc_record.deprn_calendar) then
175 raise get_err;
176 end if;
177
178 if not fa_cache_pkg.fazccp(fa_cache_pkg.fazcbc_record.deprn_calendar,
179 fa_cache_pkg.fazcbc_record.fiscal_year_name,
180 p_jdate,
181 x_period_rec.period_num,
182 x_period_rec.fiscal_year,
183 g_temp_number
184 ,p_log_level_rec => p_log_level_rec) then
185 raise get_err;
186 end if;
187
188 x_period_rec.period_counter := x_period_rec.fiscal_year *
189 fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR +
190 x_period_rec.period_num;
191
192 OPEN c_get_period_info;
193 FETCH c_get_period_info INTO x_period_rec.calendar_period_open_date,
194 x_period_rec.calendar_period_close_date;
195 CLOSE c_get_period_info;
196
197 end if;
198
199 CLOSE c_get_mc_deprn_period_info;
200
201 else -- Primary book
202
203 OPEN c_get_deprn_period_info;
204 FETCH c_get_deprn_period_info INTO x_period_rec.period_counter
205 , x_period_rec.period_name
206 , x_period_rec.period_open_date
207 , x_period_rec.period_close_date
208 , x_period_rec.calendar_period_open_date
209 , x_period_rec.calendar_period_close_date
210 , x_period_rec.fiscal_year
211 , x_period_rec.period_num;
212
213 if (c_get_deprn_period_info%NOTFOUND) then
214
215 if not fa_cache_pkg.fazcct(fa_cache_pkg.fazcbc_record.deprn_calendar) then
216 raise get_err;
217 end if;
218
219 if not fa_cache_pkg.fazccp(fa_cache_pkg.fazcbc_record.deprn_calendar,
220 fa_cache_pkg.fazcbc_record.fiscal_year_name,
221 p_jdate,
222 x_period_rec.period_num,
223 x_period_rec.fiscal_year,
224 g_temp_number
225 ,p_log_level_rec => p_log_level_rec) then
226 raise get_err;
227 end if;
228
229 x_period_rec.period_counter := x_period_rec.fiscal_year *
230 fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR +
231 x_period_rec.period_num;
232
233 OPEN c_get_period_info;
234 FETCH c_get_period_info INTO x_period_rec.calendar_period_open_date,
235 x_period_rec.calendar_period_close_date;
236 CLOSE c_get_period_info;
237
238 end if;
239
240 CLOSE c_get_deprn_period_info;
241
242 end if;
243
244 if (p_log_level_rec.statement_level) then
245 fa_debug_pkg.add(l_calling_fn, 'End', x_period_rec.period_counter||':'||
246 x_period_rec.fiscal_year||':'||
247 x_period_rec.period_num||':'||
248 to_char(x_period_rec.calendar_period_open_date, 'DD-MON-YYYY')||':'||
249 to_char(x_period_rec.calendar_period_close_date, 'DD-MON-YYYY'));
250 end if;
251
252 return TRUE;
253
254 EXCEPTION
255 WHEN get_err THEN
256 if (p_log_level_rec.statement_level) then
257 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'get_err'
258 ,p_log_level_rec => p_log_level_rec);
259 end if;
260
261 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
262 ,p_log_level_rec => p_log_level_rec);
263 return false;
264
265 WHEN others THEN
266 if (p_log_level_rec.statement_level) then
267 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
268 ,p_log_level_rec => p_log_level_rec);
269 end if;
270
271 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
272 ,p_log_level_rec => p_log_level_rec);
273 return false;
274
275 END GetPeriodInfo;
276
277
278 --+==============================================================================
279 -- Function catchupBooksSummary
280 --
281 -- This function will create missing records from period where last record
282 -- exists up to current period.
283 --+==============================================================================
284 FUNCTION catchupBooksSummary (
285 p_trans_rec FA_API_TYPES.trans_rec_type,
286 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
287 p_period_rec FA_API_TYPES.period_rec_type,
288 p_asset_fin_rec_new FA_API_TYPES.asset_fin_rec_type,
289 p_depreciate_flag_change BOOLEAN,
290 p_disabled_flag_change BOOLEAN,
291 p_mrc_sob_type_code VARCHAR2,
292 p_calling_fn VARCHAR,
293 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
294
295 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.catchupBooksSummary';
296
297 CURSOR c_get_mc_last_period_counter IS
298 select bs.period_counter
299 , bs.calendar_period_close_date
300 , bs.fiscal_year
301 , bs.period_num
302 from fa_books_summary_mrc_v bs
303 where bs.asset_id = p_asset_hdr_rec.asset_id
304 and bs.book_type_code = p_asset_hdr_rec.book_type_code
305 order by period_counter desc;
306
307 CURSOR c_get_last_period_counter IS
308 select bs.period_counter
309 , bs.calendar_period_close_date
310 , bs.fiscal_year
311 , bs.period_num
312 from fa_books_summary bs
313 where bs.asset_id = p_asset_hdr_rec.asset_id
314 and bs.book_type_code = p_asset_hdr_rec.book_type_code
315 order by period_counter desc;
316
317 --
318 -- Get all possible period information that the group asset needs
319 --
320 CURSOR c_get_period_rec (c_start_date date) IS
321 select fy.fiscal_year * ct.NUMBER_PER_FISCAL_YEAR + cp.PERIOD_NUM period_counter
322 , cp.start_date calendar_period_open_date
323 , cp.end_date calendar_period_close_date
324 , cp.period_num period_num
325 , fy.fiscal_year fiscal_year
326 , 'N'
327 from fa_book_controls bc
328 , fa_fiscal_year fy
329 , fa_calendar_types ct
330 , fa_calendar_periods cp
331 where bc.book_type_code = p_asset_hdr_rec.book_type_code
332 and bc.deprn_calendar = ct.calendar_type
333 and bc.fiscal_year_name = fy.fiscal_year_name
334 and ct.fiscal_year_name = bc.fiscal_year_name
335 and ct.calendar_type = cp.calendar_type
336 and cp.start_date between fy.start_date and fy.end_date
337 and bc.last_period_counter + 1 >= fy.fiscal_year * ct.NUMBER_PER_FISCAL_YEAR + cp.PERIOD_NUM
338 and cp.end_date >= c_start_date
339 order by period_counter;
340
341 tbs_period_counter tab_num15_type;
342 tbs_calendar_period_open_date tab_date_type;
343 tbs_calendar_period_close_date tab_date_type;
344 tbs_period_num tab_num15_type;
345 tbs_fiscal_year tab_num15_type;
346 tbs_reset_adjusted_cost_flag tab_char1_type;
347
348 tbs_adjusted_cost tab_num_type;
349 tbs_eofy_adj_cost tab_num_type;
350 tbs_eofy_formula_factor tab_num_type;
351 tbs_eofy_reserve tab_num_type;
352 tbs_eop_adj_cost tab_num_type;
356 tbs_formula_factor tab_num_type;
353 tbs_eop_formula_factor tab_num_type;
354 tbs_depreciate_flag tab_char1_type;
355 tbs_disabled_flag tab_char1_type;
357
358 tbs_ytd_deprn tab_num_type;
359 tbs_bonus_ytd_deprn tab_num_type;
360 tbs_ytd_production tab_num_type;
361 tbs_ytd_reval_deprn_expense tab_num_type;
362 tbs_ytd_proceeds_of_sale tab_num_type;
363 tbs_ytd_cost_of_removal tab_num_type;
364
365 l_last_period_counter NUMBER(15);
366 l_last_period_close_date DATE;
367 l_last_fiscal_year NUMBER(15);
368 l_last_period_num NUMBER(15);
369
370 l_ind BINARY_INTEGER;
371
372 --
373 -- Think about unplan, reserve tr, and ret adj against asset not depreciating
374 --
375
376 BEGIN
377 if (p_log_level_rec.statement_level) then
378 fa_debug_pkg.add(l_calling_fn||'()+', 'asset_id', p_asset_hdr_rec.asset_id);
379 end if;
380
381 if p_mrc_sob_type_code = 'R' then
382
383 OPEN c_get_mc_last_period_counter;
384 FETCH c_get_mc_last_period_counter INTO l_last_period_counter
385 , l_last_period_close_date
386 , l_last_fiscal_year
387 , l_last_period_num;
388 CLOSE c_get_mc_last_period_counter;
389 else
390 OPEN c_get_last_period_counter;
391 FETCH c_get_last_period_counter INTO l_last_period_counter
392 , l_last_period_close_date
393 , l_last_fiscal_year
394 , l_last_period_num;
395 CLOSE c_get_last_period_counter;
396 end if;
397
398 if (p_log_level_rec.statement_level) then
399 fa_debug_pkg.add(l_calling_fn, 'l_last_period_counter', l_last_period_counter
400 ,p_log_level_rec => p_log_level_rec);
401 fa_debug_pkg.add(l_calling_fn, 'l_last_period_close_date', l_last_period_close_date
402 ,p_log_level_rec => p_log_level_rec);
403 end if;
404
405 if (p_period_rec.period_counter = l_last_period_counter) then
406 if (p_log_level_rec.statement_level) then
407 fa_debug_pkg.add(l_calling_fn, 'This asset has record up to current period',l_last_period_counter
408 ,p_log_level_rec => p_log_level_rec);
409 fa_debug_pkg.add(l_calling_fn||'()-', 'asset_id', p_asset_hdr_rec.asset_id);
410 end if;
411
412 return TRUE;
413
414 end if;
415
416 --
417 -- This asset needs records up to current period
418 --
419 OPEN c_get_period_rec ((l_last_period_close_date + 1));
420 FETCH c_get_period_rec BULK COLLECT INTO tbs_period_counter
421 , tbs_calendar_period_open_date
422 , tbs_calendar_period_close_date
423 , tbs_period_num
424 , tbs_fiscal_year
425 , tbs_reset_adjusted_cost_flag
426 ;
427 CLOSE c_get_period_rec;
428
429 if (p_log_level_rec.statement_level) then
430 fa_debug_pkg.add(l_calling_fn, '# of record creating', tbs_period_counter.COUNT
431 ,p_log_level_rec => p_log_level_rec);
432 end if;
433
434 l_ind := p_period_rec.period_counter - l_last_period_counter;
435 FOR i in 1..l_ind LOOP
436 --
437 -- If anything requires table value manipulation for each period
438 -- this is the place. So far, it's been absorved in insert statement.
439 null;
440
441 END LOOP; -- i in 1..(p_period_rec.period_counter - l_last_period_counter)
442
443
444 if (p_log_level_rec.statement_level) then
445 fa_debug_pkg.add(l_calling_fn, 'Insert into', 'FA_BOOKS_SUMMARY'
446 ,p_log_level_rec => p_log_level_rec);
447 end if;
448 --
449 -- Insert all necessary records from period where DPIS falls into
450 --
451 if p_mrc_sob_type_code = 'R' then
452 FORALL i in tbs_period_counter.FIRST..tbs_period_counter.LAST
453 INSERT INTO FA_BOOKS_SUMMARY_MRC_V(
454 ASSET_ID
455 , BOOK_TYPE_CODE
456 , PERIOD_COUNTER
457 , FISCAL_YEAR
458 , PERIOD_NUM
459 , CALENDAR_PERIOD_OPEN_DATE
460 , CALENDAR_PERIOD_CLOSE_DATE
461 , RESET_ADJUSTED_COST_FLAG
462 , CHANGE_IN_COST
463 , CHANGE_IN_ADDITIONS_COST
464 , CHANGE_IN_ADJUSTMENTS_COST
465 , CHANGE_IN_RETIREMENTS_COST
466 , CHANGE_IN_CIP_COST
467 , COST
468 , CIP_COST
469 , SALVAGE_TYPE
470 , PERCENT_SALVAGE_VALUE
471 , SALVAGE_VALUE
472 , MEMBER_SALVAGE_VALUE
473 , RECOVERABLE_COST
474 , DEPRN_LIMIT_TYPE
475 , ALLOWED_DEPRN_LIMIT
476 , ALLOWED_DEPRN_LIMIT_AMOUNT
477 , MEMBER_DEPRN_LIMIT_AMOUNT
481 , DISABLED_FLAG
478 , ADJUSTED_RECOVERABLE_COST
479 , ADJUSTED_COST
480 , DEPRECIATE_FLAG
482 , DATE_PLACED_IN_SERVICE
483 , DEPRN_METHOD_CODE
484 , LIFE_IN_MONTHS
485 , RATE_ADJUSTMENT_FACTOR
486 , ADJUSTED_RATE
487 , FORMULA_FACTOR
488 , BONUS_RULE
489 , ADJUSTED_CAPACITY
490 , PRODUCTION_CAPACITY
491 , UNIT_OF_MEASURE
492 , REMAINING_LIFE1
493 , REMAINING_LIFE2
494 , UNREVALUED_COST
495 , REVAL_CEILING
496 , CEILING_NAME
497 , REVAL_AMORTIZATION_BASIS
498 , EOFY_ADJ_COST
499 , EOFY_FORMULA_FACTOR
500 , EOFY_RESERVE
501 , EOP_ADJ_COST
502 , EOP_FORMULA_FACTOR
503 , SHORT_FISCAL_YEAR_FLAG
504 , GROUP_ASSET_ID
505 , SUPER_GROUP_ID
506 , OVER_DEPRECIATE_OPTION
507 , TERMINAL_GAIN_LOSS_AMOUNT
508 , TERMINAL_GAIN_LOSS_FLAG
509 , DEPRN_AMOUNT
510 , YTD_DEPRN
511 , DEPRN_RESERVE
512 , BONUS_DEPRN_AMOUNT
513 , BONUS_YTD_DEPRN
514 , BONUS_DEPRN_RESERVE
515 , LTD_PRODUCTION
516 , YTD_PRODUCTION
517 , PRODUCTION
518 , REVAL_AMORTIZATION
519 , REVAL_DEPRN_EXPENSE
520 , REVAL_RESERVE
521 , YTD_REVAL_DEPRN_EXPENSE
522 , DEPRN_OVERRIDE_FLAG
523 , SYSTEM_DEPRN_AMOUNT
524 , YTD_PROCEEDS_OF_SALE
525 , LTD_PROCEEDS_OF_SALE
526 , YTD_COST_OF_REMOVAL
527 , LTD_COST_OF_REMOVAL
528 , DEPRN_ADJUSTMENT_AMOUNT
529 , EXPENSE_ADJUSTMENT_AMOUNT
530 , UNPLANNED_AMOUNT
531 , RESERVE_ADJUSTMENT_AMOUNT
532 , CREATION_DATE
533 , CREATED_BY
534 , LAST_UPDATE_DATE
535 , LAST_UPDATED_BY
536 )
537 SELECT p_asset_hdr_rec.asset_id
538 , p_asset_hdr_rec.book_type_code
539 , tbs_period_counter(i)
540 , tbs_fiscal_year(i)
541 , tbs_period_num(i)
542 , tbs_calendar_period_open_date(i)
543 , tbs_calendar_period_close_date(i)
544 , tbs_reset_adjusted_cost_flag(i)
545 , 0 --CHANGE_IN_COST
546 , 0 --CHANGE_IN_ADDITIONS_COST
547 , 0 --CHANGE_IN_ADJUSTMENTS_COST
548 , 0 --CHANGE_IN_RETIREMENTS_COST
549 , 0 --CHANGE_IN_CIP_COST
550 , BS.COST
551 , BS.CIP_COST
552 , BS.SALVAGE_TYPE
553 , BS.PERCENT_SALVAGE_VALUE
554 , BS.SALVAGE_VALUE
555 , BS.MEMBER_SALVAGE_VALUE
556 , BS.RECOVERABLE_COST
557 , BS.DEPRN_LIMIT_TYPE
558 , BS.ALLOWED_DEPRN_LIMIT
559 , BS.ALLOWED_DEPRN_LIMIT_AMOUNT
560 , BS.MEMBER_DEPRN_LIMIT_AMOUNT
561 , BS.ADJUSTED_RECOVERABLE_COST
562 , BS.ADJUSTED_COST
563 , BS.DEPRECIATE_FLAG
564 , BS.DISABLED_FLAG
565 , BS.DATE_PLACED_IN_SERVICE
566 , BS.DEPRN_METHOD_CODE
567 , BS.LIFE_IN_MONTHS
568 , BS.RATE_ADJUSTMENT_FACTOR
569 , BS.ADJUSTED_RATE
570 , BS.FORMULA_FACTOR
571 , BS.BONUS_RULE
572 , BS.ADJUSTED_CAPACITY
573 , BS.PRODUCTION_CAPACITY
574 , BS.UNIT_OF_MEASURE
575 , BS.REMAINING_LIFE1
576 , BS.REMAINING_LIFE2
577 , BS.UNREVALUED_COST
578 , BS.REVAL_CEILING
579 , BS.CEILING_NAME
580 , BS.REVAL_AMORTIZATION_BASIS
581 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.EOFY_ADJ_COST, BS.ADJUSTED_COST) --EOFY_ADJ_COST
582 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.EOFY_FORMULA_FACTOR, BS.FORMULA_FACTOR) --EOFY_FORMULA_FACTOR
583 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.EOFY_RESERVE,
584 tbs_fiscal_year(i) - 1, BS.DEPRN_RESERVE, 0) --EOFY_RESERVE
585 , BS.ADJUSTED_COST --EOP_ADJ_COST
586 , BS.FORMULA_FACTOR --EOP_FORMULA_FACTOR
587 , BS.SHORT_FISCAL_YEAR_FLAG
588 , BS.GROUP_ASSET_ID
589 , BS.SUPER_GROUP_ID
590 , BS.OVER_DEPRECIATE_OPTION
591 , 0 --TERMINAL_GAIN_LOSS_AMOUNT
592 , 'N' --TERMINAL_GAIN_LOSS_FLAG
593 , 0 --DEPRN_AMOUNT
594 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_DEPRN, 0) --YTD_DEPRN
598 , BS.BONUS_DEPRN_RESERVE
595 , BS.DEPRN_RESERVE
596 , 0 --BONUS_DEPRN_AMOUNT
597 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.BONUS_YTD_DEPRN, 0) --BONUS_YTD_DEPRN
599 , BS.LTD_PRODUCTION
600 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_PRODUCTION, 0) --YTD_PRODUCTION
601 , null --PRODUCTION
602 , 0 --REVAL_AMORTIZATION
603 , 0 --REVAL_DEPRN_EXPENSE
604 , BS.REVAL_RESERVE
605 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_REVAL_DEPRN_EXPENSE, 0) --YTD_REVAL_DEPRN_EXPENSE
606 , 'N' --DEPRN_OVERRIDE_FLAG
607 , 0 --SYSTEM_DEPRN_AMOUNT
608 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_PROCEEDS_OF_SALE, 0) --YTD_PROCEEDS_OF_SALE
609 , BS.LTD_PROCEEDS_OF_SALE
610 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_COST_OF_REMOVAL, 0) --YTD_COST_OF_REMOVAL
611 , BS.LTD_COST_OF_REMOVAL
612 , 0 --DEPRN_ADJUSTMENT_AMOUNT
613 , 0 --EXPENSE_ADJUSTMENT_AMOUNT
614 , 0 --UNPLANNED_AMOUNT
615 , 0 --RESERVE_ADJUSTMENT_AMOUNT
616 , p_trans_rec.who_info.creation_date
617 , p_trans_rec.who_info.created_by
618 , p_trans_rec.who_info.last_update_date
619 , p_trans_rec.who_info.last_updated_by
620 FROM FA_BOOKS_SUMMARY_MRC_V BS
621 WHERE BS.ASSET_ID = p_asset_hdr_rec.asset_id
622 AND BS.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
623 AND BS.period_counter = l_last_period_counter;
624
625 else
626 FORALL i in tbs_period_counter.FIRST..tbs_period_counter.LAST
627 INSERT INTO FA_BOOKS_SUMMARY(
628 ASSET_ID
629 , BOOK_TYPE_CODE
630 , PERIOD_COUNTER
631 , FISCAL_YEAR
632 , PERIOD_NUM
633 , CALENDAR_PERIOD_OPEN_DATE
634 , CALENDAR_PERIOD_CLOSE_DATE
635 , RESET_ADJUSTED_COST_FLAG
636 , CHANGE_IN_COST
637 , CHANGE_IN_ADDITIONS_COST
638 , CHANGE_IN_ADJUSTMENTS_COST
639 , CHANGE_IN_RETIREMENTS_COST
640 , CHANGE_IN_CIP_COST
641 , COST
642 , CIP_COST
643 , SALVAGE_TYPE
644 , PERCENT_SALVAGE_VALUE
645 , SALVAGE_VALUE
646 , MEMBER_SALVAGE_VALUE
647 , RECOVERABLE_COST
648 , DEPRN_LIMIT_TYPE
649 , ALLOWED_DEPRN_LIMIT
650 , ALLOWED_DEPRN_LIMIT_AMOUNT
651 , MEMBER_DEPRN_LIMIT_AMOUNT
652 , ADJUSTED_RECOVERABLE_COST
653 , ADJUSTED_COST
654 , DEPRECIATE_FLAG
655 , DISABLED_FLAG
656 , DATE_PLACED_IN_SERVICE
657 , DEPRN_METHOD_CODE
658 , LIFE_IN_MONTHS
659 , RATE_ADJUSTMENT_FACTOR
660 , ADJUSTED_RATE
661 , FORMULA_FACTOR
662 , BONUS_RULE
663 , ADJUSTED_CAPACITY
664 , PRODUCTION_CAPACITY
665 , UNIT_OF_MEASURE
666 , REMAINING_LIFE1
667 , REMAINING_LIFE2
668 , UNREVALUED_COST
669 , REVAL_CEILING
670 , CEILING_NAME
671 , REVAL_AMORTIZATION_BASIS
672 , EOFY_ADJ_COST
673 , EOFY_FORMULA_FACTOR
674 , EOFY_RESERVE
675 , EOP_ADJ_COST
676 , EOP_FORMULA_FACTOR
677 , SHORT_FISCAL_YEAR_FLAG
678 , GROUP_ASSET_ID
679 , SUPER_GROUP_ID
680 , OVER_DEPRECIATE_OPTION
681 , TERMINAL_GAIN_LOSS_AMOUNT
682 , TERMINAL_GAIN_LOSS_FLAG
683 , DEPRN_AMOUNT
684 , YTD_DEPRN
685 , DEPRN_RESERVE
686 , BONUS_DEPRN_AMOUNT
687 , BONUS_YTD_DEPRN
688 , BONUS_DEPRN_RESERVE
689 , LTD_PRODUCTION
690 , YTD_PRODUCTION
691 , PRODUCTION
692 , REVAL_AMORTIZATION
693 , REVAL_DEPRN_EXPENSE
694 , REVAL_RESERVE
695 , YTD_REVAL_DEPRN_EXPENSE
696 , DEPRN_OVERRIDE_FLAG
697 , SYSTEM_DEPRN_AMOUNT
698 , YTD_PROCEEDS_OF_SALE
699 , LTD_PROCEEDS_OF_SALE
700 , YTD_COST_OF_REMOVAL
701 , LTD_COST_OF_REMOVAL
702 , DEPRN_ADJUSTMENT_AMOUNT
703 , EXPENSE_ADJUSTMENT_AMOUNT
704 , UNPLANNED_AMOUNT
705 , RESERVE_ADJUSTMENT_AMOUNT
706 , CREATION_DATE
707 , CREATED_BY
708 , LAST_UPDATE_DATE
709 , LAST_UPDATED_BY
713 , tbs_period_counter(i)
710 )
711 SELECT p_asset_hdr_rec.asset_id
712 , p_asset_hdr_rec.book_type_code
714 , tbs_fiscal_year(i)
715 , tbs_period_num(i)
716 , tbs_calendar_period_open_date(i)
717 , tbs_calendar_period_close_date(i)
718 , tbs_reset_adjusted_cost_flag(i)
719 , 0 --CHANGE_IN_COST
720 , 0 --CHANGE_IN_ADDITIONS_COST
721 , 0 --CHANGE_IN_ADJUSTMENTS_COST
722 , 0 --CHANGE_IN_RETIREMENTS_COST
723 , 0 --CHANGE_IN_CIP_COST
724 , BS.COST
725 , BS.CIP_COST
726 , BS.SALVAGE_TYPE
727 , BS.PERCENT_SALVAGE_VALUE
728 , BS.SALVAGE_VALUE
729 , BS.MEMBER_SALVAGE_VALUE
730 , BS.RECOVERABLE_COST
731 , BS.DEPRN_LIMIT_TYPE
732 , BS.ALLOWED_DEPRN_LIMIT
733 , BS.ALLOWED_DEPRN_LIMIT_AMOUNT
734 , BS.MEMBER_DEPRN_LIMIT_AMOUNT
735 , BS.ADJUSTED_RECOVERABLE_COST
736 , BS.ADJUSTED_COST
737 , BS.DEPRECIATE_FLAG
738 , BS.DISABLED_FLAG
739 , BS.DATE_PLACED_IN_SERVICE
740 , BS.DEPRN_METHOD_CODE
741 , BS.LIFE_IN_MONTHS
742 , BS.RATE_ADJUSTMENT_FACTOR
743 , BS.ADJUSTED_RATE
744 , BS.FORMULA_FACTOR
745 , BS.BONUS_RULE
746 , BS.ADJUSTED_CAPACITY
747 , BS.PRODUCTION_CAPACITY
748 , BS.UNIT_OF_MEASURE
749 , BS.REMAINING_LIFE1
750 , BS.REMAINING_LIFE2
751 , BS.UNREVALUED_COST
752 , BS.REVAL_CEILING
753 , BS.CEILING_NAME
754 , BS.REVAL_AMORTIZATION_BASIS
755 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.EOFY_ADJ_COST, BS.ADJUSTED_COST) --EOFY_ADJ_COST
756 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.EOFY_FORMULA_FACTOR, BS.FORMULA_FACTOR) --EOFY_FORMULA_FACTOR
757 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.EOFY_RESERVE,
758 tbs_fiscal_year(i) - 1, BS.DEPRN_RESERVE, 0) --EOFY_RESERVE
759 , BS.ADJUSTED_COST --EOP_ADJ_COST
760 , BS.FORMULA_FACTOR --EOP_FORMULA_FACTOR
761 , BS.SHORT_FISCAL_YEAR_FLAG
762 , BS.GROUP_ASSET_ID
763 , BS.SUPER_GROUP_ID
764 , BS.OVER_DEPRECIATE_OPTION
765 , 0 --TERMINAL_GAIN_LOSS_AMOUNT
766 , 'N' --TERMINAL_GAIN_LOSS_FLAG
767 , 0 --DEPRN_AMOUNT
768 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_DEPRN, 0) --YTD_DEPRN
769 , BS.DEPRN_RESERVE
770 , 0 --BONUS_DEPRN_AMOUNT
771 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.BONUS_YTD_DEPRN, 0) --BONUS_YTD_DEPRN
772 , BS.BONUS_DEPRN_RESERVE
773 , BS.LTD_PRODUCTION
774 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_PRODUCTION, 0) --YTD_PRODUCTION
775 , null --PRODUCTION
776 , 0 --REVAL_AMORTIZATION
777 , 0 --REVAL_DEPRN_EXPENSE
778 , BS.REVAL_RESERVE
779 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_REVAL_DEPRN_EXPENSE, 0) --YTD_REVAL_DEPRN_EXPENSE
780 , 'N' --DEPRN_OVERRIDE_FLAG
781 , 0 --SYSTEM_DEPRN_AMOUNT
782 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_PROCEEDS_OF_SALE, 0) --YTD_PROCEEDS_OF_SALE
783 , BS.LTD_PROCEEDS_OF_SALE
784 , DECODE(BS.FISCAL_YEAR, tbs_fiscal_year(i), BS.YTD_COST_OF_REMOVAL, 0) --YTD_COST_OF_REMOVAL
785 , BS.LTD_COST_OF_REMOVAL
786 , 0 --DEPRN_ADJUSTMENT_AMOUNT
787 , 0 --EXPENSE_ADJUSTMENT_AMOUNT
788 , 0 --UNPLANNED_AMOUNT
789 , 0 --RESERVE_ADJUSTMENT_AMOUNT
790 , p_trans_rec.who_info.creation_date
791 , p_trans_rec.who_info.created_by
792 , p_trans_rec.who_info.last_update_date
793 , p_trans_rec.who_info.last_updated_by
794 FROM FA_BOOKS_SUMMARY BS
795 WHERE BS.ASSET_ID = p_asset_hdr_rec.asset_id
796 AND BS.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
797 AND BS.period_counter = l_last_period_counter;
798 end if; --p_mrc_sob_type_code = 'R'
799
800 if p_depreciate_flag_change then
801
802 if p_mrc_sob_type_code = 'R' then
803 UPDATE FA_BOOKS_SUMMARY_MRC_V
804 SET DEPRECIATE_FLAG = p_asset_fin_rec_new.depreciate_flag
805 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
806 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code;
807 else
808 UPDATE FA_BOOKS_SUMMARY
809 SET DEPRECIATE_FLAG = p_asset_fin_rec_new.depreciate_flag
810 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
811 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code;
815
812 end if;
813
814 elsif p_disabled_flag_change then
816 if p_mrc_sob_type_code = 'R' then
817 UPDATE FA_BOOKS_SUMMARY_MRC_V
818 SET DISABLED_FLAG = p_asset_fin_rec_new.depreciate_flag
819 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
820 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code;
821 else
822 UPDATE FA_BOOKS_SUMMARY
823 SET DISABLED_FLAG = p_asset_fin_rec_new.depreciate_flag
824 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
825 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code;
826 end if;
827
828 end if;
829
830 if (p_log_level_rec.statement_level) then
831 fa_debug_pkg.add(l_calling_fn||'()-', '# of records inserted', tbs_period_counter.COUNT);
832 end if;
833
834 return true;
835
836 EXCEPTION
837 WHEN OTHERS THEN
838 if (p_log_level_rec.statement_level) then
839 fa_debug_pkg.add(l_calling_fn||'(OTHERS)-', 'sqlcode', sqlcode);
840 end if;
841
842 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
843 ,p_log_level_rec => p_log_level_rec);
844
845 return false;
846
847 END catchupBooksSummary;
848
849
850
851 --+==============================================================================
852 -- Procedure initMemberTable
853 --
854 -- Initialize global variables defined in specification.
855 --+==============================================================================
856 PROCEDURE initMemberTable(p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) IS
857 BEGIN
858
859 --
860 -- Initialize global variables
861 --
862 fa_amort_pvt.tmd_period_counter.delete;
863 fa_amort_pvt.tmd_cost.delete;
864 fa_amort_pvt.tm_cost.delete;
865 fa_amort_pvt.tmd_cip_cost.delete;
866 fa_amort_pvt.tm_cip_cost.delete;
867 fa_amort_pvt.tmd_salvage_value.delete;
868 fa_amort_pvt.tm_salvage_value.delete;
869 fa_amort_pvt.tmd_deprn_limit_amount.delete;
870 fa_amort_pvt.tm_deprn_limit_amount.delete;
871
872 END initMemberTable;
873
874 --+==============================================================================
875 -- Procedure InitGlobeVariables
876 --
877 -- Initialize global variables defined in specification.
878 --+==============================================================================
879 PROCEDURE InitGlobeVariables (p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) IS
880 BEGIN
881
882 --
883 -- Initialize global variables
884 --
885 fa_amort_pvt.t_period_counter.delete;
886 fa_amort_pvt.t_fiscal_year.delete;
887 fa_amort_pvt.t_period_num.delete;
888 fa_amort_pvt.t_calendar_period_open_date.delete;
889 fa_amort_pvt.t_calendar_period_close_date.delete;
890 fa_amort_pvt.t_reset_adjusted_cost_flag.delete;
891 fa_amort_pvt.t_change_in_cost.delete;
892 fa_amort_pvt.t_cost.delete;
893 fa_amort_pvt.t_cip_cost.delete;
894 fa_amort_pvt.t_salvage_type.delete;
895 fa_amort_pvt.t_percent_salvage_value.delete;
896 fa_amort_pvt.t_salvage_value.delete;
897 fa_amort_pvt.t_member_salvage_value.delete;
898 fa_amort_pvt.t_recoverable_cost.delete;
899 fa_amort_pvt.t_deprn_limit_type.delete;
900 fa_amort_pvt.t_allowed_deprn_limit.delete;
901 fa_amort_pvt.t_allowed_deprn_limit_amount.delete;
902 fa_amort_pvt.t_member_deprn_limit_amount.delete;
903 fa_amort_pvt.t_adjusted_recoverable_cost.delete;
904 fa_amort_pvt.t_adjusted_cost.delete;
905 fa_amort_pvt.t_depreciate_flag.delete;
906 fa_amort_pvt.t_date_placed_in_service.delete;
907 fa_amort_pvt.t_deprn_method_code.delete;
908 fa_amort_pvt.t_life_in_months.delete;
909 fa_amort_pvt.t_rate_adjustment_factor.delete;
910 fa_amort_pvt.t_adjusted_rate.delete;
911 fa_amort_pvt.t_bonus_rule.delete;
912 fa_amort_pvt.t_adjusted_capacity.delete;
913 fa_amort_pvt.t_production_capacity.delete;
914 fa_amort_pvt.t_unit_of_measure.delete;
915 fa_amort_pvt.t_remaining_life1.delete;
916 fa_amort_pvt.t_remaining_life2.delete;
917 fa_amort_pvt.t_formula_factor.delete;
918 fa_amort_pvt.t_unrevalued_cost.delete;
919 fa_amort_pvt.t_reval_amortization_basis.delete;
920 fa_amort_pvt.t_reval_ceiling.delete;
921 fa_amort_pvt.t_ceiling_name.delete;
922 fa_amort_pvt.t_eofy_adj_cost.delete;
923 fa_amort_pvt.t_eofy_formula_factor.delete;
924 fa_amort_pvt.t_eofy_reserve.delete;
925 fa_amort_pvt.t_eop_adj_cost.delete;
926 fa_amort_pvt.t_eop_formula_factor.delete;
927 fa_amort_pvt.t_short_fiscal_year_flag.delete;
928 fa_amort_pvt.t_group_asset_id.delete;
929 fa_amort_pvt.t_super_group_id.delete;
930 fa_amort_pvt.t_over_depreciate_option.delete;
931 fa_amort_pvt.t_deprn_amount.delete;
932 fa_amort_pvt.t_ytd_deprn.delete;
933 fa_amort_pvt.t_deprn_reserve.delete;
934 fa_amort_pvt.t_bonus_deprn_amount.delete;
935 fa_amort_pvt.t_bonus_ytd_deprn.delete;
936 fa_amort_pvt.t_bonus_deprn_reserve.delete;
937 fa_amort_pvt.t_bonus_rate.delete;
938 fa_amort_pvt.t_ltd_production.delete;
939 fa_amort_pvt.t_ytd_production.delete;
940 fa_amort_pvt.t_production.delete;
941 fa_amort_pvt.t_reval_amortization.delete;
942 fa_amort_pvt.t_reval_deprn_expense.delete;
943 fa_amort_pvt.t_reval_reserve.delete;
947 fa_amort_pvt.t_system_bonus_deprn_amount.delete;
944 fa_amort_pvt.t_ytd_reval_deprn_expense.delete;
945 fa_amort_pvt.t_deprn_override_flag.delete;
946 fa_amort_pvt.t_system_deprn_amount.delete;
948 fa_amort_pvt.t_ytd_proceeds_of_sale.delete;
949 fa_amort_pvt.t_ltd_proceeds_of_sale.delete;
950 fa_amort_pvt.t_ytd_cost_of_removal.delete;
951 fa_amort_pvt.t_ltd_cost_of_removal.delete;
952 fa_amort_pvt.t_deprn_adjustment_amount.delete;
953 fa_amort_pvt.t_expense_adjustment_amount.delete;
954 fa_amort_pvt.t_reserve_adjustment_amount.delete;
955
956 END InitGlobeVariables;
957
958 --+==============================================================================
959 -- Function: createGroup
960 --
961 -- Description:
962 -- This function should be called to maintain group asset that has not
963 -- depreciated or a member asset has not assigned.
964 -- What this function does is to recreate records in FA_BOOKS_SUMAMRY by
965 -- deleting all of them and reinsert all of them.
966 --
967 --+==============================================================================
968 FUNCTION createGroup(
969 p_trans_rec FA_API_TYPES.trans_rec_type,
970 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
971 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
972 p_period_rec FA_API_TYPES.period_rec_type,
973 p_asset_fin_rec FA_API_TYPES.asset_fin_rec_type,
974 p_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type,
975 p_mrc_sob_type_code VARCHAR2,
976 p_calling_fn VARCHAR,
977 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return BOOLEAN IS
978
979 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.createGroup';
980
981 --
982 -- Get all possible period information that the group asset needs
983 --
984 CURSOR c_get_period_rec IS
985 select fy.fiscal_year * ct.NUMBER_PER_FISCAL_YEAR + cp.PERIOD_NUM period_counter
986 , cp.start_date calendar_period_open_date
987 , cp.end_date calendar_period_close_date
988 , cp.period_num period_num
989 , fy.fiscal_year fiscal_year
990 , 'N'
991 from fa_fiscal_year fy
992 , fa_calendar_types ct
993 , fa_calendar_periods cp
994 where ct.calendar_type = fa_cache_pkg.fazcbc_record.deprn_calendar
995 and fy.fiscal_year_name = fa_cache_pkg.fazcbc_record.fiscal_year_name
996 and ct.fiscal_year_name = fa_cache_pkg.fazcbc_record.fiscal_year_name
997 and ct.calendar_type = cp.calendar_type
998 and cp.start_date between fy.start_date and fy.end_date
999 and fa_cache_pkg.fazcbc_record.last_period_counter + 1 >=
1000 fy.fiscal_year * ct.NUMBER_PER_FISCAL_YEAR + cp.PERIOD_NUM
1001 and cp.end_date >= p_asset_fin_rec.date_placed_in_service
1002 order by period_counter;
1003
1004 tbs_period_counter tab_num15_type;
1005 tbs_calendar_period_open_date tab_date_type;
1006 tbs_calendar_period_close_date tab_date_type;
1007 tbs_period_num tab_num15_type;
1008 tbs_fiscal_year tab_num15_type;
1009 tbs_reset_adjusted_cost_flag tab_char1_type;
1010
1011 BEGIN
1012
1013 if (p_log_level_rec.statement_level) then
1014 fa_debug_pkg.add(l_calling_fn||'()+', 'asset_id', p_asset_hdr_rec.asset_id);
1015 end if;
1016
1017 --
1018 -- Delete all records for this group asset to recreate them
1019 --
1020 if p_mrc_sob_type_code = 'R' then
1021 DELETE FROM FA_BOOKS_SUMMARY_MRC_V
1022 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
1023 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code;
1024 else
1025 DELETE FROM FA_BOOKS_SUMMARY
1026 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
1027 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code;
1028 end if;
1029
1030 if (p_log_level_rec.statement_level) then
1031 fa_debug_pkg.add(l_calling_fn, 'Construct Period information', '.'
1032 ,p_log_level_rec => p_log_level_rec);
1033 end if;
1034
1035 --
1036 -- Construct period information part for FA_BOOKS_SUMAMRY
1037 --
1038 OPEN c_get_period_rec;
1039 FETCH c_get_period_rec BULK COLLECT INTO tbs_period_counter
1040 , tbs_calendar_period_open_date
1041 , tbs_calendar_period_close_date
1042 , tbs_period_num
1043 , tbs_fiscal_year
1044 , tbs_reset_adjusted_cost_flag
1045 ;
1046 CLOSE c_get_period_rec;
1047
1048 if (p_log_level_rec.statement_level) then
1049 fa_debug_pkg.add(l_calling_fn||'()-', '# of records will be inserted',
1050 tbs_period_counter.COUNT);
1051 end if;
1052
1053 if (tbs_period_counter.COUNT = 0) then
1054 tbs_period_counter(1) := p_period_rec.period_counter;
1055 tbs_calendar_period_open_date(1) := p_period_rec.calendar_period_open_date;
1056 tbs_calendar_period_close_date(1) := p_period_rec.calendar_period_close_date;
1057 tbs_period_num(1) := p_period_rec.period_num;
1058 tbs_fiscal_year(1) := p_period_rec.fiscal_year;
1059 tbs_reset_adjusted_cost_flag(1) := 'Y';
1060 end if;
1061 --
1065
1062 -- First record always get adjusted cost reset
1063 --
1064 tbs_reset_adjusted_cost_flag(1) := 'Y';
1066 if (p_log_level_rec.statement_level) then
1067 fa_debug_pkg.add(l_calling_fn, 'Insert into', 'FA_BOOKS_SUMMARY'
1068 ,p_log_level_rec => p_log_level_rec);
1069 end if;
1070 --
1071 -- Insert all necessary records from period where DPIS falls into
1072 --
1073 if p_mrc_sob_type_code = 'R' then
1074 FORALL i in tbs_period_counter.FIRST..tbs_period_counter.LAST
1075 INSERT INTO FA_BOOKS_SUMMARY_MRC_V(
1076 ASSET_ID
1077 , BOOK_TYPE_CODE
1078 , PERIOD_COUNTER
1079 , FISCAL_YEAR
1080 , PERIOD_NUM
1081 , CALENDAR_PERIOD_OPEN_DATE
1082 , CALENDAR_PERIOD_CLOSE_DATE
1083 , RESET_ADJUSTED_COST_FLAG
1084 , CHANGE_IN_COST
1085 , CHANGE_IN_ADDITIONS_COST
1086 , CHANGE_IN_ADJUSTMENTS_COST
1087 , CHANGE_IN_RETIREMENTS_COST
1088 , CHANGE_IN_CIP_COST
1089 , COST
1090 , CIP_COST
1091 , SALVAGE_TYPE
1092 , PERCENT_SALVAGE_VALUE
1093 , SALVAGE_VALUE
1094 , MEMBER_SALVAGE_VALUE
1095 , RECOVERABLE_COST
1096 , DEPRN_LIMIT_TYPE
1097 , ALLOWED_DEPRN_LIMIT
1098 , ALLOWED_DEPRN_LIMIT_AMOUNT
1099 , MEMBER_DEPRN_LIMIT_AMOUNT
1100 , ADJUSTED_RECOVERABLE_COST
1101 , ADJUSTED_COST
1102 , DEPRECIATE_FLAG
1103 , DISABLED_FLAG
1104 , DATE_PLACED_IN_SERVICE
1105 , DEPRN_METHOD_CODE
1106 , LIFE_IN_MONTHS
1107 , RATE_ADJUSTMENT_FACTOR
1108 , ADJUSTED_RATE
1109 , FORMULA_FACTOR
1110 , BONUS_RULE
1111 , ADJUSTED_CAPACITY
1112 , PRODUCTION_CAPACITY
1113 , UNIT_OF_MEASURE
1114 , REMAINING_LIFE1
1115 , REMAINING_LIFE2
1116 , UNREVALUED_COST
1117 , REVAL_CEILING
1118 , CEILING_NAME
1119 , REVAL_AMORTIZATION_BASIS
1120 , EOFY_ADJ_COST
1121 , EOFY_FORMULA_FACTOR
1122 , EOFY_RESERVE
1123 , EOP_ADJ_COST
1124 , EOP_FORMULA_FACTOR
1125 , SHORT_FISCAL_YEAR_FLAG
1126 , GROUP_ASSET_ID
1127 , SUPER_GROUP_ID
1128 , OVER_DEPRECIATE_OPTION
1129 , TERMINAL_GAIN_LOSS_AMOUNT
1130 , TERMINAL_GAIN_LOSS_FLAG
1131 , DEPRN_AMOUNT
1132 , YTD_DEPRN
1133 , DEPRN_RESERVE
1134 , BONUS_DEPRN_AMOUNT
1135 , BONUS_YTD_DEPRN
1136 , BONUS_DEPRN_RESERVE
1137 , LTD_PRODUCTION
1138 , YTD_PRODUCTION
1139 , PRODUCTION
1140 , REVAL_AMORTIZATION
1141 , REVAL_DEPRN_EXPENSE
1142 , REVAL_RESERVE
1143 , YTD_REVAL_DEPRN_EXPENSE
1144 , DEPRN_OVERRIDE_FLAG
1145 , SYSTEM_DEPRN_AMOUNT
1146 , YTD_PROCEEDS_OF_SALE
1147 , LTD_PROCEEDS_OF_SALE
1148 , YTD_COST_OF_REMOVAL
1149 , LTD_COST_OF_REMOVAL
1150 , DEPRN_ADJUSTMENT_AMOUNT
1151 , EXPENSE_ADJUSTMENT_AMOUNT
1152 , UNPLANNED_AMOUNT
1153 , RESERVE_ADJUSTMENT_AMOUNT
1154 , CREATION_DATE
1155 , CREATED_BY
1156 , LAST_UPDATE_DATE
1157 , LAST_UPDATED_BY
1158 )
1159 VALUES( p_asset_hdr_rec.asset_id
1160 , p_asset_hdr_rec.book_type_code
1161 , tbs_period_counter(i)
1162 , tbs_fiscal_year(i)
1163 , tbs_period_num(i)
1164 , tbs_calendar_period_open_date(i)
1165 , tbs_calendar_period_close_date(i)
1166 , tbs_reset_adjusted_cost_flag(i)
1167 , 0 --CHANGE_IN_COST
1168 , 0 --CHANGE_IN_ADDITIONS_COST
1169 , 0 --CHANGE_IN_ADJUSTMENTS_COST
1170 , 0 --CHANGE_IN_RETIREMENTS_COST
1171 , 0 --CHANGE_IN_CIP_COST
1172 , 0 --COST
1173 , 0 --CIP_COST
1174 , p_asset_fin_rec.salvage_type --SALVAGE_TYPE
1175 , p_asset_fin_rec.percent_salvage_value --PERCENT_SALVAGE_VALUE
1176 , 0 --SALVAGE_VALUE
1177 , 0 --MEMBER_SALVAGE_VALUE
1178 , 0 --RECOVERABLE_COST
1179 , p_asset_fin_rec.deprn_limit_type --DEPRN_LIMIT_TYPE
1180 , p_asset_fin_rec.allowed_deprn_limit --ALLOWED_DEPRN_LIMIT
1181 , 0 --ALLOWED_DEPRN_LIMIT_AMOUNT
1182 , 0 --MEMBER_DEPRN_LIMIT_AMOUNT
1183 , 0 --ADJUSTED_RECOVERABLE_COST
1187 , p_asset_fin_rec.date_placed_in_service --DATE_PLACED_IN_SERVICE
1184 , 0 --ADJUSTED_COST
1185 , p_asset_fin_rec.depreciate_flag --DEPRECIATE_FLAG
1186 , p_asset_fin_rec.disabled_flag --DISABLED_FLAG
1188 , p_asset_fin_rec.deprn_method_code --DEPRN_METHOD_CODE
1189 , p_asset_fin_rec.life_in_months --LIFE_IN_MONTHS
1190 , 1 --RATE_ADJUSTMENT_FACTOR
1191 , p_asset_fin_rec.adjusted_rate --ADJUSTED_RATE
1192 , 1 --FORMULA_FACTOR
1193 , p_asset_fin_rec.bonus_rule --BONUS_RULE
1194 , p_asset_fin_rec.adjusted_capacity --ADJUSTED_CAPACITY
1195 , p_asset_fin_rec.production_capacity --PRODUCTION_CAPACITY
1196 , p_asset_fin_rec.unit_of_measure --UNIT_OF_MEASURE
1197 , p_asset_fin_rec.remaining_life1 --REMAINING_LIFE1
1198 , p_asset_fin_rec.remaining_life2 --REMAINING_LIFE2
1199 , 0 --UNREVALUED_COST
1200 , p_asset_fin_rec.reval_ceiling --REVAL_CEILING
1201 , p_asset_fin_rec.ceiling_name --CEILING_NAME
1202 , 0 --REVAL_AMORTIZATION_BASIS
1203 , 0 --EOFY_ADJ_COST
1204 , 1 --EOFY_FORMULA_FACTOR
1205 , 0 --EOFY_RESERVE
1206 , 0 --EOP_ADJ_COST
1207 , 1 --EOP_FORMULA_FACTOR
1208 , 'NO' --SHORT_FISCAL_YEAR_FLAG
1209 , null --GROUP_ASSET_ID
1210 , p_asset_fin_rec.super_group_id --SUPER_GROUP_ID
1211 , p_asset_fin_rec.over_depreciate_option --OVER_DEPRECIATE_OPTION
1212 , 0 --TERMINAL_GAIN_LOSS_AMOUNT
1213 , 'N' --TERMINAL_GAIN_LOSS_FLAG
1214 , 0 --DEPRN_AMOUNT
1215 , 0 --YTD_DEPRN
1216 , 0 --DEPRN_RESERVE
1217 , 0 --BONUS_DEPRN_AMOUNT
1218 , 0 --BONUS_YTD_DEPRN
1219 , 0 --BONUS_DEPRN_RESERVE
1220 , null --LTD_PRODUCTION
1221 , null --YTD_PRODUCTION
1222 , null --PRODUCTION
1223 , 0 --REVAL_AMORTIZATION
1224 , 0 --REVAL_DEPRN_EXPENSE
1225 , 0 --REVAL_RESERVE
1226 , 0 --YTD_REVAL_DEPRN_EXPENSE
1227 , 'N' --DEPRN_OVERRIDE_FLAG
1228 , 0 --SYSTEM_DEPRN_AMOUNT
1229 , 0 --YTD_PROCEEDS_OF_SALE
1230 , 0 --LTD_PROCEEDS_OF_SALE
1231 , 0 --YTD_COST_OF_REMOVAL
1232 , 0 --LTD_COST_OF_REMOVAL
1233 , 0 --DEPRN_ADJUSTMENT_AMOUNT
1234 , 0 --EXPENSE_ADJUSTMENT_AMOUNT
1235 , 0 --UNPLANNED_AMOUNT
1236 , 0 --RESERVE_ADJUSTMENT_AMOUNT
1237 , p_trans_rec.who_info.creation_date
1238 , p_trans_rec.who_info.created_by
1239 , p_trans_rec.who_info.last_update_date
1240 , p_trans_rec.who_info.last_updated_by
1241 );
1242
1243 else
1244
1245 FORALL i in tbs_period_counter.FIRST..tbs_period_counter.LAST
1246 INSERT INTO FA_BOOKS_SUMMARY(
1247 ASSET_ID
1248 , BOOK_TYPE_CODE
1249 , PERIOD_COUNTER
1250 , FISCAL_YEAR
1251 , PERIOD_NUM
1252 , CALENDAR_PERIOD_OPEN_DATE
1253 , CALENDAR_PERIOD_CLOSE_DATE
1254 , RESET_ADJUSTED_COST_FLAG
1255 , CHANGE_IN_COST
1256 , CHANGE_IN_ADDITIONS_COST
1257 , CHANGE_IN_ADJUSTMENTS_COST
1258 , CHANGE_IN_RETIREMENTS_COST
1259 , CHANGE_IN_CIP_COST
1260 , COST
1261 , CIP_COST
1262 , SALVAGE_TYPE
1263 , PERCENT_SALVAGE_VALUE
1264 , SALVAGE_VALUE
1265 , MEMBER_SALVAGE_VALUE
1266 , RECOVERABLE_COST
1267 , DEPRN_LIMIT_TYPE
1268 , ALLOWED_DEPRN_LIMIT
1269 , ALLOWED_DEPRN_LIMIT_AMOUNT
1270 , MEMBER_DEPRN_LIMIT_AMOUNT
1271 , ADJUSTED_RECOVERABLE_COST
1272 , ADJUSTED_COST
1273 , DEPRECIATE_FLAG
1274 , DISABLED_FLAG
1275 , DATE_PLACED_IN_SERVICE
1276 , DEPRN_METHOD_CODE
1277 , LIFE_IN_MONTHS
1278 , RATE_ADJUSTMENT_FACTOR
1279 , ADJUSTED_RATE
1280 , FORMULA_FACTOR
1281 , BONUS_RULE
1282 , ADJUSTED_CAPACITY
1283 , PRODUCTION_CAPACITY
1284 , UNIT_OF_MEASURE
1285 , REMAINING_LIFE1
1286 , REMAINING_LIFE2
1287 , UNREVALUED_COST
1288 , REVAL_CEILING
1289 , CEILING_NAME
1290 , REVAL_AMORTIZATION_BASIS
1291 , EOFY_ADJ_COST
1292 , EOFY_FORMULA_FACTOR
1293 , EOFY_RESERVE
1297 , GROUP_ASSET_ID
1294 , EOP_ADJ_COST
1295 , EOP_FORMULA_FACTOR
1296 , SHORT_FISCAL_YEAR_FLAG
1298 , SUPER_GROUP_ID
1299 , OVER_DEPRECIATE_OPTION
1300 , TERMINAL_GAIN_LOSS_AMOUNT
1301 , TERMINAL_GAIN_LOSS_FLAG
1302 , DEPRN_AMOUNT
1303 , YTD_DEPRN
1304 , DEPRN_RESERVE
1305 , BONUS_DEPRN_AMOUNT
1306 , BONUS_YTD_DEPRN
1307 , BONUS_DEPRN_RESERVE
1308 , LTD_PRODUCTION
1309 , YTD_PRODUCTION
1310 , PRODUCTION
1311 , REVAL_AMORTIZATION
1312 , REVAL_DEPRN_EXPENSE
1313 , REVAL_RESERVE
1314 , YTD_REVAL_DEPRN_EXPENSE
1315 , DEPRN_OVERRIDE_FLAG
1316 , SYSTEM_DEPRN_AMOUNT
1317 , YTD_PROCEEDS_OF_SALE
1318 , LTD_PROCEEDS_OF_SALE
1319 , YTD_COST_OF_REMOVAL
1320 , LTD_COST_OF_REMOVAL
1321 , DEPRN_ADJUSTMENT_AMOUNT
1322 , EXPENSE_ADJUSTMENT_AMOUNT
1323 , UNPLANNED_AMOUNT
1324 , RESERVE_ADJUSTMENT_AMOUNT
1325 , CREATION_DATE
1326 , CREATED_BY
1327 , LAST_UPDATE_DATE
1328 , LAST_UPDATED_BY
1329 )
1330 VALUES( p_asset_hdr_rec.asset_id
1331 , p_asset_hdr_rec.book_type_code
1332 , tbs_period_counter(i)
1333 , tbs_fiscal_year(i)
1334 , tbs_period_num(i)
1335 , tbs_calendar_period_open_date(i)
1336 , tbs_calendar_period_close_date(i)
1337 , tbs_reset_adjusted_cost_flag(i)
1338 , 0 --CHANGE_IN_COST
1339 , 0 --CHANGE_IN_ADDITIONS_COST
1340 , 0 --CHANGE_IN_ADJUSTMENTS_COST
1341 , 0 --CHANGE_IN_RETIREMENTS_COST
1342 , 0 --CHANGE_IN_CIP_COST
1343 , 0 --COST
1344 , 0 --CIP_COST
1345 , p_asset_fin_rec.salvage_type --SALVAGE_TYPE
1346 , p_asset_fin_rec.percent_salvage_value --PERCENT_SALVAGE_VALUE
1347 , 0 --SALVAGE_VALUE
1348 , 0 --MEMBER_SALVAGE_VALUE
1349 , 0 --RECOVERABLE_COST
1350 , p_asset_fin_rec.deprn_limit_type --DEPRN_LIMIT_TYPE
1351 , p_asset_fin_rec.allowed_deprn_limit --ALLOWED_DEPRN_LIMIT
1352 , 0 --ALLOWED_DEPRN_LIMIT_AMOUNT
1353 , 0 --MEMBER_DEPRN_LIMIT_AMOUNT
1354 , 0 --ADJUSTED_RECOVERABLE_COST
1355 , 0 --ADJUSTED_COST
1356 , p_asset_fin_rec.depreciate_flag --DEPRECIATE_FLAG
1357 , p_asset_fin_rec.disabled_flag --DISABLED_FLAG
1358 , p_asset_fin_rec.date_placed_in_service --DATE_PLACED_IN_SERVICE
1359 , p_asset_fin_rec.deprn_method_code --DEPRN_METHOD_CODE
1360 , p_asset_fin_rec.life_in_months --LIFE_IN_MONTHS
1361 , 1 --RATE_ADJUSTMENT_FACTOR
1362 , p_asset_fin_rec.adjusted_rate --ADJUSTED_RATE
1363 , 1 --FORMULA_FACTOR
1364 , p_asset_fin_rec.bonus_rule --BONUS_RULE
1365 , p_asset_fin_rec.adjusted_capacity --ADJUSTED_CAPACITY
1366 , p_asset_fin_rec.production_capacity --PRODUCTION_CAPACITY
1367 , p_asset_fin_rec.unit_of_measure --UNIT_OF_MEASURE
1368 , p_asset_fin_rec.remaining_life1 --REMAINING_LIFE1
1369 , p_asset_fin_rec.remaining_life2 --REMAINING_LIFE2
1370 , 0 --UNREVALUED_COST
1371 , p_asset_fin_rec.reval_ceiling --REVAL_CEILING
1372 , p_asset_fin_rec.ceiling_name --CEILING_NAME
1373 , 0 --REVAL_AMORTIZATION_BASIS
1374 , 0 --EOFY_ADJ_COST
1375 , 1 --EOFY_FORMULA_FACTOR
1376 , 0 --EOFY_RESERVE
1377 , 0 --EOP_ADJ_COST
1378 , 1 --EOP_FORMULA_FACTOR
1379 , 'NO' --SHORT_FISCAL_YEAR_FLAG
1380 , null --GROUP_ASSET_ID
1381 , p_asset_fin_rec.super_group_id --SUPER_GROUP_ID
1382 , p_asset_fin_rec.over_depreciate_option --OVER_DEPRECIATE_OPTION
1383 , 0 --TERMINAL_GAIN_LOSS_AMOUNT
1384 , 'N' --TERMINAL_GAIN_LOSS_FLAG
1385 , 0 --DEPRN_AMOUNT
1386 , 0 --YTD_DEPRN
1387 , 0 --DEPRN_RESERVE
1388 , 0 --BONUS_DEPRN_AMOUNT
1389 , 0 --BONUS_YTD_DEPRN
1390 , 0 --BONUS_DEPRN_RESERVE
1391 , null --LTD_PRODUCTION
1392 , null --YTD_PRODUCTION
1393 , null --PRODUCTION
1394 , 0 --REVAL_AMORTIZATION
1395 , 0 --REVAL_DEPRN_EXPENSE
1396 , 0 --REVAL_RESERVE
1397 , 0 --YTD_REVAL_DEPRN_EXPENSE
1401 , 0 --LTD_PROCEEDS_OF_SALE
1398 , 'N' --DEPRN_OVERRIDE_FLAG
1399 , 0 --SYSTEM_DEPRN_AMOUNT
1400 , 0 --YTD_PROCEEDS_OF_SALE
1402 , 0 --YTD_COST_OF_REMOVAL
1403 , 0 --LTD_COST_OF_REMOVAL
1404 , 0 --DEPRN_ADJUSTMENT_AMOUNT
1405 , 0 --EXPENSE_ADJUSTMENT_AMOUNT
1406 , 0 --UNPLANNED_AMOUNT
1407 , 0 --RESERVE_ADJUSTMENT_AMOUNT
1408 , p_trans_rec.who_info.creation_date
1409 , p_trans_rec.who_info.created_by
1410 , p_trans_rec.who_info.last_update_date
1411 , p_trans_rec.who_info.last_updated_by
1412 );
1413 end if; --p_mrc_sob_type_code = 'R'
1414
1415 printBooksSummary(p_asset_id => p_asset_hdr_rec.asset_id,
1416 p_book_type_code => p_asset_hdr_rec.book_type_code,
1417 p_period_counter => tbs_period_counter(1));
1418
1419 if (p_log_level_rec.statement_level) then
1420 fa_debug_pkg.add(l_calling_fn||'()-', '# of records inserted', tbs_period_counter.COUNT);
1421 end if;
1422
1423 return true;
1424
1425 EXCEPTION
1426 WHEN OTHERS THEN
1427 if (p_log_level_rec.statement_level) then
1428 fa_debug_pkg.add(l_calling_fn||'(OTHERS)-', 'sqlcode', sqlcode);
1429 end if;
1430
1431 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
1432 ,p_log_level_rec => p_log_level_rec);
1433
1434 return false;
1435 END createGroup;
1436
1437 --+==============================================================================
1438 -- Function: buildMemberTable
1439 --
1440 --+==============================================================================
1441 FUNCTION buildMemberTable(
1442 p_trans_rec FA_API_TYPES.trans_rec_type,
1443 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
1444 p_period_rec FA_API_TYPES.period_rec_type,
1445 p_date_placed_in_service DATE,
1446 p_group_asset_id NUMBER,
1447 p_reclass_multiplier NUMBER,
1448 p_reclass_src_dest VARCHAR2,
1449 p_salvage_limit_type VARCHAR2,
1450 x_td_period_counter OUT NOCOPY fa_amort_pvt.tab_num15_type,
1451 x_td_cost OUT NOCOPY fa_amort_pvt.tab_num_type,
1452 x_td_cip_cost OUT NOCOPY fa_amort_pvt.tab_num_type,
1453 x_td_salvage_value OUT NOCOPY fa_amort_pvt.tab_num_type,
1454 x_td_deprn_limit_amount OUT NOCOPY fa_amort_pvt.tab_num_type,
1455 x_asset_fin_rec OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
1456 x_asset_fin_rec_reclass OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
1457 p_mrc_sob_type_code VARCHAR2,
1458 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)return BOOLEAN IS
1459
1460 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.buildMemberTable';
1461
1462 --
1463 -- Get Period and 0s for cost, cip_cost, salvage value,
1464 -- deprn limit amount, percent_salvage_value, and allowed_deprn_limit
1465 -- and nulls for salvage_type and deprn_limit_type for building
1466 -- tables
1467 CURSOR c_get_period_counters (c_date date,
1468 c_group_asset_id number) IS
1469 select period_counter,
1470 0, 0, 0, 0, 0, null, 0, null, 0, 0, 0
1471 from fa_books_summary
1472 where asset_id = c_group_asset_id
1473 and book_type_code = p_asset_hdr_rec.book_type_code
1474 and calendar_period_close_date >= c_date
1475 order by period_counter;
1476
1477
1478 CURSOR c_get_member_trx IS
1479 select th.transaction_header_id
1480 , th.transaction_type_code
1481 , th.transaction_subtype
1482 , th.transaction_key
1483 , bs.period_counter
1484 from fa_transaction_headers th
1485 , fa_books_summary bs
1486 , fa_transaction_headers mth
1487 , fa_books bk
1488 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
1489 and th.asset_id = mth.asset_id
1490 and th.book_type_code = p_asset_hdr_rec.book_type_code
1491 and bs.asset_id = p_group_asset_id
1492 and bs.book_type_code = p_asset_hdr_rec.book_type_code
1493 and bk.transaction_header_id_in = th.transaction_header_id
1494 and decode(th.transaction_subtype,
1495 'EXPENSED', greatest(decode(bk.group_asset_id,
1496 null,p_date_placed_in_service,
1497 nvl(th.amortization_start_date,
1498 th.transaction_date_entered)), p_date_placed_in_service),
1499 greatest(nvl(th.amortization_start_date,
1500 th.transaction_date_entered), p_date_placed_in_service))
1501 between bs.calendar_period_open_date
1502 and bs.calendar_period_close_date
1503 and (th.transaction_type_code not in ('TRANSFER OUT', 'TRANSFER IN',
1504 'TRANSFER', 'TRANSFER IN/VOID',
1505 'RECLASS', 'UNIT ADJUSTMENT',
1506 'REINSTATEMENT')
1510 -- Bug5149789
1507 or (th.transaction_type_code = 'REINSTATEMENT' and
1508 th.transaction_header_id = p_trans_rec.member_transaction_header_id));
1509
1511 CURSOR c_get_member_trx_single IS
1512 select mth.transaction_header_id
1513 , mth.transaction_type_code
1514 , mth.transaction_subtype
1515 , mth.transaction_key
1516 , bs.period_counter
1517 from fa_books_summary bs
1518 , fa_transaction_headers mth
1519 , fa_books bk
1520 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
1521 and bs.asset_id = p_group_asset_id
1522 and bs.book_type_code = p_asset_hdr_rec.book_type_code
1523 and bk.transaction_header_id_in = mth.transaction_header_id
1524 and decode(mth.transaction_subtype,
1525 'EXPENSED', greatest(decode(bk.group_asset_id,
1526 null,p_date_placed_in_service,
1527 nvl(mth.amortization_start_date,
1528 mth.transaction_date_entered)), p_date_placed_in_service),
1529 greatest(nvl(mth.amortization_start_date,
1530 mth.transaction_date_entered), p_date_placed_in_service))
1531 between bs.calendar_period_open_date
1532 and bs.calendar_period_close_date
1533 and (mth.transaction_type_code not in ('TRANSFER OUT', 'TRANSFER IN',
1534 'TRANSFER', 'TRANSFER IN/VOID',
1535 'RECLASS', 'UNIT ADJUSTMENT',
1536 'REINSTATEMENT')
1537 or (mth.transaction_type_code = 'REINSTATEMENT' and
1538 mth.transaction_header_id = p_trans_rec.member_transaction_header_id));
1539
1540 --
1541 -- Cursor to get retirement information using retirement
1542 -- transaction_header_id
1543 --
1544 CURSOR c_get_ret_info (c_transaction_header_id number) IS
1545 select ret.date_retired
1546 , ret.cost_retired
1547 , nvl(ret.reserve_retired, 0)
1548 , ret.proceeds_of_sale
1549 , ret.cost_of_removal
1550 from fa_retirements ret
1551 where ret.transaction_header_id_in = c_transaction_header_id
1552 and ret.transaction_header_id_out is null;
1553
1554 CURSOR c_get_mc_ret_info (c_transaction_header_id number) IS
1555 select ret.date_retired
1556 , ret.cost_retired
1557 , nvl(ret.reserve_retired, 0)
1558 , ret.proceeds_of_sale
1559 , ret.cost_of_removal
1560 from fa_retirements_mrc_v ret
1561 where ret.transaction_header_id_in = c_transaction_header_id
1562 and ret.transaction_header_id_out is null;
1563
1564
1565 --
1566 -- Cursor to get delta information in cost for a given transaction
1567 -- p_reclass_multiplier will be -1 if this is source group asset process.
1568 -- it wil be 1 for all other cases.
1569 --
1570 CURSOR c_get_deltas ( c_transaction_header_id number) IS
1571 select p_reclass_multiplier * (inbk.cost - nvl(outbk.cost, 0))
1572 , p_reclass_multiplier * (nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0))
1573 , p_reclass_multiplier * (decode(inbk.salvage_type,
1574 outbk.salvage_type,
1575 inbk.salvage_value - nvl(outbk.salvage_value, 0),
1576 inbk.salvage_value))
1577 , p_reclass_multiplier *
1578 (decode(inbk.deprn_limit_type,
1579 outbk.deprn_limit_type,
1580 nvl(decode(inbk.deprn_limit_type, 'NONE', inbk.salvage_value,
1581 inbk.allowed_deprn_limit_amount), 0) -
1582 nvl(decode(outbk.deprn_limit_type, 'NONE', outbk.salvage_value,
1583 outbk.allowed_deprn_limit_amount), 0),
1584 nvl(decode(inbk.deprn_limit_type, 'NONE', inbk.salvage_value,
1585 inbk.allowed_deprn_limit_amount), 0)))
1586 , inbk.salvage_type
1587 , outbk.salvage_type
1588 , inbk.percent_salvage_value
1589 , outbk.percent_salvage_value
1590 , inbk.deprn_limit_type
1591 , outbk.deprn_limit_type
1592 , inbk.allowed_deprn_limit
1593 , outbk.allowed_deprn_limit
1594 from fa_books inbk,
1595 fa_books outbk
1596 , fa_transaction_headers mth
1597 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
1598 and inbk.asset_id = mth.asset_id
1599 and outbk.asset_id(+) = inbk.asset_id
1600 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
1601 and outbk.book_type_code(+) = inbk.book_type_code
1602 and inbk.transaction_header_id_in = c_transaction_header_id
1603 and outbk.transaction_header_id_out(+) = inbk.transaction_header_id_in;
1604
1605 CURSOR c_get_mc_deltas ( c_transaction_header_id number) IS
1606 select p_reclass_multiplier * (inbk.cost - nvl(outbk.cost, 0))
1607 , p_reclass_multiplier * (nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0))
1608 , p_reclass_multiplier * (decode(inbk.salvage_type,
1612 , p_reclass_multiplier *
1609 outbk.salvage_type,
1610 inbk.salvage_value - nvl(outbk.salvage_value, 0),
1611 inbk.salvage_value))
1613 (decode(inbk.deprn_limit_type,
1614 outbk.deprn_limit_type,
1615 nvl(decode(inbk.deprn_limit_type, 'NONE', inbk.salvage_value,
1616 inbk.allowed_deprn_limit_amount), 0) -
1617 nvl(decode(outbk.deprn_limit_type, 'NONE', outbk.salvage_value,
1618 outbk.allowed_deprn_limit_amount), 0),
1619 nvl(decode(inbk.deprn_limit_type, 'NONE', inbk.salvage_value,
1620 inbk.allowed_deprn_limit_amount), 0)))
1621 , inbk.salvage_type
1622 , outbk.salvage_type
1623 , inbk.percent_salvage_value
1624 , outbk.percent_salvage_value
1625 , inbk.deprn_limit_type
1626 , outbk.deprn_limit_type
1627 , inbk.allowed_deprn_limit
1628 , outbk.allowed_deprn_limit
1629 from fa_books_mrc_v inbk,
1630 fa_books_mrc_v outbk
1631 , fa_transaction_headers mth
1632 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
1633 and inbk.asset_id = mth.asset_id
1634 and outbk.asset_id(+) = inbk.asset_id
1635 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
1636 and outbk.book_type_code(+) = inbk.book_type_code
1637 and inbk.transaction_header_id_in = c_transaction_header_id
1638 and outbk.transaction_header_id_out(+) = inbk.transaction_header_id_in;
1639
1640 --
1641 -- Tables to store member information
1642 --
1643 t_transaction_header_id fa_amort_pvt.tab_num15_type;
1644
1645 l_dpis_pc NUMBER(15); -- Period counter where member's dpis falls in
1646
1647 tr_transaction_header_id fa_amort_pvt.tab_num15_type;
1648 tr_transaction_type_code fa_amort_pvt.tab_char30_type;
1649 tr_transaction_subtype fa_amort_pvt.tab_char30_type;
1650 tr_transaction_key fa_amort_pvt.tab_char3_type;
1651 tr_period_counter fa_amort_pvt.tab_num15_type;
1652
1653 l_date_retired DATE;
1654 l_cost_retired NUMBER;
1655 l_reserve_retired NUMBER;
1656 l_proceeds_of_sale NUMBER;
1657 l_cost_of_removal NUMBER;
1658
1659 l_cost NUMBER;
1660 l_cip_cost NUMBER;
1661 l_salvage_value NUMBER;
1662 l_deprn_limit_amount NUMBER;
1663 l_salvage_type VARCHAR2(30);
1664 l_old_salvage_type VARCHAR2(30);
1665 l_percent_salvage_value NUMBER;
1666 l_old_percent_salvage_value NUMBER;
1667 l_deprn_limit_type VARCHAR2(30);
1668 l_old_deprn_limit_type VARCHAR2(30);
1669 l_allowed_deprn_limit NUMBER;
1670 l_old_allowed_deprn_limit NUMBER;
1671
1672 t_period_counter fa_amort_pvt.tab_num15_type;
1673 t_cost fa_amort_pvt.tab_num_type;
1674 t_cip_cost fa_amort_pvt.tab_num_type;
1675 t_salvage_type fa_amort_pvt.tab_char30_type;
1676 t_percent_salvage_value fa_amort_pvt.tab_num_type;
1677 t_salvage_value fa_amort_pvt.tab_num_type;
1678 t_deprn_limit_type fa_amort_pvt.tab_char30_type;
1679 t_allowed_deprn_limit fa_amort_pvt.tab_num_type;
1680 t_deprn_limit_amount fa_amort_pvt.tab_num_type;
1681 t_sal_thid fa_amort_pvt.tab_num15_type;
1682 t_limit_thid fa_amort_pvt.tab_num15_type;
1683
1684
1685 l_sal_thid NUMBER(15) := 0;
1686 l_limit_thid NUMBER(15) := 0;
1687
1688 -- Bug4958977: Adding following 4 new variables
1689 l_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
1690 l_period_counter NUMBER;
1691 bld_err EXCEPTION;
1692 l_cur_trx_period_counter NUMBER;
1693
1694 l_ind BINARY_INTEGER; -- Index variable
1695 l_temp_num NUMBER; -- used for calling fa_round_pkg
1696 ld_ind BINARY_INTEGER := 0;
1697
1698 l_reinstated BOOLEAN;
1699
1700 BEGIN
1701
1702 if (p_log_level_rec.statement_level) then
1703 fa_debug_pkg.add(l_calling_fn||'()+', 'asset_id', p_asset_hdr_rec.asset_id, p_log_level_rec);
1704 fa_debug_pkg.add(l_calling_fn, 'group_asset_id', p_group_asset_id, p_log_level_rec);
1705 end if;
1706 --tk_util.debug('p_reclass_multiplier: '||to_char(p_reclass_multiplier));
1707
1708 if (p_reclass_src_dest = 'DESTINATION') and
1709 (fa_amort_pvt.tmd_period_counter.COUNT > 0) then
1710 l_ind := p_period_rec.period_counter - (fa_amort_pvt.tmd_period_counter(1) - 1);
1711
1712 FOR i in l_ind..fa_amort_pvt.tmd_period_counter.COUNT LOOP
1713 --tk_util.debug('i: '||to_char(i));
1714 ld_ind := ld_ind + 1;
1715 x_td_period_counter(ld_ind) := fa_amort_pvt.tmd_period_counter(i);
1716 x_td_cost(ld_ind) := -1 * fa_amort_pvt.tmd_cost(i);
1717 x_td_cip_cost(ld_ind) := -1 * fa_amort_pvt.tmd_cip_cost(i);
1721 --tk_util.debug('fa_amort_pvt.tm_cost(i): '||to_char(fa_amort_pvt.tm_cost(i)));
1718 x_td_salvage_value(ld_ind) := -1 * fa_amort_pvt.tmd_salvage_value(i);
1719 x_td_deprn_limit_amount(ld_ind) := -1 * fa_amort_pvt.tmd_deprn_limit_amount(i);
1720 --tk_util.debug('fa_amort_pvt.tmd_period_counter(i): '||to_char(fa_amort_pvt.tmd_period_counter(i)));
1722 --tk_util.debug('fa_amort_pvt.tmd_cost(i): '||to_char(fa_amort_pvt.tmd_cost(i)));
1723 --tk_util.debug('x_td_cost(ld_ind): '||to_char(x_td_cost(ld_ind)));
1724 END LOOP;
1725 --tk_util.debug('Post loop');
1726 x_asset_fin_rec_reclass.cost := -1 * fa_amort_pvt.tm_cost(l_ind);
1727 --tk_util.debug('x_asset_fin_rec_reclass.cost: '||to_char(x_asset_fin_rec_reclass.cost));
1728 x_asset_fin_rec_reclass.cip_cost := -1 * fa_amort_pvt.tm_cip_cost(l_ind);
1729 x_asset_fin_rec_reclass.salvage_value := -1 * fa_amort_pvt.tm_salvage_value(l_ind);
1730 x_asset_fin_rec_reclass.allowed_deprn_limit_amount :=
1731 -1 * fa_amort_pvt.tm_deprn_limit_amount(l_ind);
1732
1733 if (p_log_level_rec.statement_level) then
1734 fa_debug_pkg.add(l_calling_fn||'()-', '# of rows in delta tables', x_td_cost.COUNT, p_log_level_rec);
1735 end if;
1736
1737 return TRUE;
1738
1739 end if;
1740 --
1741 -- Construct member asset table using group's data in FA_BOOKS_SUMMARY
1742 --
1743 --tk_util.debug('c_date: '||to_char(p_date_placed_in_service, 'DD-MON-YYYY'));
1744 OPEN c_get_period_counters (p_date_placed_in_service,
1745 p_group_asset_id);
1746
1747 FETCH c_get_period_counters BULK COLLECT INTO t_period_counter
1748 , t_transaction_header_id
1749 , fa_amort_pvt.tmd_cost
1750 , fa_amort_pvt.tmd_cip_cost
1751 , fa_amort_pvt.tmd_salvage_value
1752 , fa_amort_pvt.tmd_deprn_limit_amount
1753 , t_salvage_type
1754 , t_percent_salvage_value
1755 , t_deprn_limit_type
1756 , t_allowed_deprn_limit
1757 , t_sal_thid
1758 , t_limit_thid;
1759 CLOSE c_get_period_counters;
1760
1761 if (p_log_level_rec.statement_level) then
1762 fa_debug_pkg.add(l_calling_fn, 'Finish Constructing Memebr Table',
1763 t_period_counter.COUNT, p_log_level_rec);
1764 fa_debug_pkg.add(l_calling_fn, 'p_trans_rec.transaction_key',
1765 p_trans_rec.transaction_key, p_log_level_rec);
1766 fa_debug_pkg.add(l_calling_fn, 'p_salvage_limit_type',
1767 p_salvage_limit_type, p_log_level_rec);
1768 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id',
1769 p_asset_hdr_rec.asset_id, p_log_level_rec);
1770 fa_debug_pkg.add(l_calling_fn, 'p_date_placed_in_service',
1771 p_date_placed_in_service, p_log_level_rec);
1772 fa_debug_pkg.add(l_calling_fn, 'p_group_asset_id',
1773 p_group_asset_id, p_log_level_rec);
1774 end if;
1775
1776 l_dpis_pc := t_period_counter(1);
1777
1778 --
1779 -- Get member asset's transactions
1780 --
1781 -- bug5149789: if we can prevent salvage_type or deprn_limit_type
1782 -- change once the member is added, then we can check against
1783 -- trx key. Otherwise we need to go with type now.
1784 if (p_trans_rec.transaction_key = 'GC') or (p_salvage_limit_type = 'SUM') then
1785 OPEN c_get_member_trx;
1786 FETCH c_get_member_trx BULK COLLECT INTO tr_transaction_header_id
1787 , tr_transaction_type_code
1788 , tr_transaction_subtype
1789 , tr_transaction_key
1790 , tr_period_counter
1791 ;
1792 CLOSE c_get_member_trx;
1793 else -- bug5149789
1794 --
1795 -- bug5149789
1796 -- Even thought following cursor is using bulk, it should only return
1797 -- one row. It is using pl/sql table of columns to be consistent.
1798 OPEN c_get_member_trx_single;
1799 FETCH c_get_member_trx_single BULK COLLECT INTO tr_transaction_header_id
1800 , tr_transaction_type_code
1801 , tr_transaction_subtype
1802 , tr_transaction_key
1803 , tr_period_counter
1804 ;
1805 CLOSE c_get_member_trx_single;
1806
1807 end if; -- bug5149789
1808
1809
1810 if (p_log_level_rec.statement_level) then
1811 fa_debug_pkg.add(l_calling_fn, 'Finish Getting Memebr Trxs',
1812 tr_transaction_header_id.COUNT, p_log_level_rec);
1813 end if;
1814
1815 --
1816 -- Get Delta information for each transaction and populate delta information.
1817 --
1818 FOR i in 1..tr_transaction_header_id.COUNT LOOP
1819
1820 -- Bug4766103: Need to initialize l_reinstated
1821 l_reinstated := FALSE;
1822
1823 if (p_mrc_sob_type_code = 'R') then
1827 , l_cost_retired
1824 if (tr_transaction_key(i) = 'R') then
1825 OPEN c_get_mc_ret_info(tr_transaction_header_id(i));
1826 FETCH c_get_mc_ret_info INTO l_date_retired
1828 , l_reserve_retired
1829 , l_proceeds_of_sale
1830 , l_cost_of_removal;
1831
1832 if c_get_mc_ret_info%NOTFOUND then
1833 l_reinstated := TRUE;
1834 end if;
1835
1836 CLOSE c_get_mc_ret_info;
1837
1838 end if;
1839 else
1840 if (tr_transaction_key(i) = 'R') then
1841 OPEN c_get_ret_info(tr_transaction_header_id(i));
1842 FETCH c_get_ret_info INTO l_date_retired
1843 , l_cost_retired
1844 , l_reserve_retired
1845 , l_proceeds_of_sale
1846 , l_cost_of_removal;
1847
1848 if c_get_ret_info%NOTFOUND then
1849 l_reinstated := TRUE;
1850 end if;
1851
1852 CLOSE c_get_ret_info;
1853
1854 end if;
1855 end if;
1856
1857 if (not l_reinstated) or
1858 ((l_reinstated) and
1859 (tr_transaction_header_id(i) =
1860 p_trans_rec.member_transaction_header_id)) then
1861
1862 if (p_mrc_sob_type_code = 'R') then
1863 OPEN c_get_mc_deltas(tr_transaction_header_id(i));
1864 FETCH c_get_mc_deltas INTO l_cost
1865 , l_cip_cost
1866 , l_salvage_value
1867 , l_deprn_limit_amount
1868 , l_salvage_type
1869 , l_old_salvage_type
1870 , l_percent_salvage_value
1871 , l_old_percent_salvage_value
1872 , l_deprn_limit_type
1873 , l_old_deprn_limit_type
1874 , l_allowed_deprn_limit
1875 , l_old_allowed_deprn_limit;
1876 CLOSE c_get_mc_deltas;
1877 else
1878 OPEN c_get_deltas(tr_transaction_header_id(i));
1879 FETCH c_get_deltas INTO l_cost
1880 , l_cip_cost
1881 , l_salvage_value
1882 , l_deprn_limit_amount
1883 , l_salvage_type
1884 , l_old_salvage_type
1885 , l_percent_salvage_value
1886 , l_old_percent_salvage_value
1887 , l_deprn_limit_type
1888 , l_old_deprn_limit_type
1889 , l_allowed_deprn_limit
1890 , l_old_allowed_deprn_limit;
1891 CLOSE c_get_deltas;
1892 end if;
1893 /*
1894 --tk_util.debug('thid:cost:sal:dl: '||to_char(tr_transaction_header_id(i))||':'||
1895 to_char(l_cost)||':'||
1896 to_char(l_salvage_value)||':'||
1897 to_char(l_deprn_limit_amount));
1898 */
1899
1900 if (tr_transaction_header_id(i) <>
1901 p_trans_rec.member_transaction_header_id) then
1902
1903 -- Fix for 4713623
1904 -- this case happens when dpis of member is changed after ADDITION
1905 -- for example from jan to mar and bs table is only from march
1906 -- In such cases l_ind using tr_period_counter(i) - l_dpis_pc + 1
1907 -- can be negative.
1908 -- the fix handles that any transaction before current dpis
1909 -- is made to look from current dpis period
1910
1911 if (tr_period_counter(i) < l_dpis_pc) then
1912 l_ind := 1;
1913 else
1914 l_ind := tr_period_counter(i) - l_dpis_pc + 1;
1915 end if;
1916
1917 fa_amort_pvt.tmd_cost(l_ind) :=
1918 fa_amort_pvt.tmd_cost(l_ind) + l_cost;
1919 fa_amort_pvt.tmd_cip_cost(l_ind) :=
1920 fa_amort_pvt.tmd_cip_cost(l_ind) + l_cip_cost;
1921 fa_amort_pvt.tmd_salvage_value(l_ind) :=
1922 fa_amort_pvt.tmd_salvage_value(l_ind) +
1923 l_salvage_value;
1924 fa_amort_pvt.tmd_deprn_limit_amount(l_ind) :=
1925 fa_amort_pvt.tmd_deprn_limit_amount(l_ind) +
1926 l_deprn_limit_amount;
1927
1928 --
1929 -- Following line may be removed. This is not necessary
1930 -- since introduction of t_sal(limit)_thids.
1931 t_transaction_header_id(l_ind) := tr_transaction_header_id(i);
1932
1933 --
1934 -- Subsequent retroactive salvage/deprn limit change may override
1935 -- previously entered information. So copy only qualified salvage/
1936 -- deprn limit changes.
1937 --
1938 --tk_util.debug('t_sal_thid(l_ind): '||to_char(t_sal_thid(l_ind)));
1942 --tk_util.debug('l_salvage_type: '||l_salvage_type);
1939 --tk_util.debug('tr_transaction_header_id(i): '||to_char(tr_transaction_header_id(i)));
1940 --tk_util.debug('l_percent_salvage_value: '||to_char(l_percent_salvage_value));
1941 --tk_util.debug('l_old_percent_salvage_value: '||to_char(l_old_percent_salvage_value));
1943 --tk_util.debug('l_salvage_value: '||to_char(l_salvage_value));
1944
1945 if (t_sal_thid(l_ind) < tr_transaction_header_id(i)) and
1946 ((l_salvage_type <> l_old_salvage_type) or
1947 (nvl(l_percent_salvage_value, 0) <> nvl(l_old_percent_salvage_value, 0)) or
1948 (l_salvage_type = 'AMT' and l_salvage_value <> 0)) then
1949
1950 t_sal_thid(l_ind) := tr_transaction_header_id(i);
1951 t_salvage_type(l_ind) := l_salvage_type;
1952 t_percent_salvage_value(l_ind) := l_percent_salvage_value;
1953
1954 if (p_log_level_rec.statement_level) then
1955 fa_debug_pkg.add(l_calling_fn, 'Check',
1956 'Types', p_log_level_rec);
1957 fa_debug_pkg.add(l_calling_fn, 't_salvage_type('||to_char(l_ind)||')',
1958 t_salvage_type(l_ind), p_log_level_rec);
1959 end if;
1960
1961 end if;
1962
1963 if (t_limit_thid(l_ind) < tr_transaction_header_id(i)) and
1964 ((l_deprn_limit_type <> nvl(l_old_deprn_limit_type, l_deprn_limit_type)) or
1965 (nvl(l_allowed_deprn_limit, 0) <> nvl(l_old_allowed_deprn_limit,0)) or
1966 (l_deprn_limit_type = 'AMT' and l_deprn_limit_amount <> 0)) then
1967
1968 t_limit_thid(l_ind) := tr_transaction_header_id(i);
1969 t_deprn_limit_type(l_ind) := l_deprn_limit_type;
1970 t_allowed_deprn_limit(l_ind) := l_allowed_deprn_limit;
1971
1972 if (p_log_level_rec.statement_level) then
1973 fa_debug_pkg.add(l_calling_fn, 'Check',
1974 'Types', p_log_level_rec);
1975 fa_debug_pkg.add(l_calling_fn, 't_deprn_limit_type('||to_char(l_ind)||')',
1976 t_deprn_limit_type(l_ind), p_log_level_rec);
1977 end if;
1978 end if;
1979
1980
1981 else
1982 l_cur_trx_period_counter := tr_period_counter(i); -- Bug4958977
1983 x_asset_fin_rec.cost := l_cost;
1984 x_asset_fin_rec.cip_cost := l_cip_cost;
1985 x_asset_fin_rec.salvage_value := l_salvage_value;
1986 x_asset_fin_rec.allowed_deprn_limit_amount := l_deprn_limit_amount;
1987 x_asset_fin_rec.salvage_type := l_salvage_type;
1988 x_asset_fin_rec.percent_salvage_value := l_percent_salvage_value;
1989 x_asset_fin_rec.deprn_limit_type := l_deprn_limit_type;
1990 x_asset_fin_rec.allowed_deprn_limit := l_allowed_deprn_limit;
1991
1992 -- Bug4958977: Adding following if statements
1993 if (nvl(l_cost, 0) = 0) and
1994 (nvl(l_cip_cost, 0) = 0) and
1995 (nvl(l_salvage_value, 0) = 0) and
1996 (nvl(l_deprn_limit_amount, 0) = 0) then
1997
1998 if (p_log_level_rec.statement_level) then
1999 fa_debug_pkg.add(l_calling_fn, 'calling', 'check_dpis_change', p_log_level_rec);
2000 end if;
2001
2002 if not check_dpis_change (
2003 p_book_type_code => p_asset_hdr_rec.book_type_code
2004 , p_transaction_header_id => tr_transaction_header_id(i)
2005 , p_group_asset_id => p_group_asset_id
2006 , x_asset_fin_rec => l_asset_fin_rec
2007 , x_period_counter_out => l_period_counter
2008 , p_mrc_sob_type_code => p_mrc_sob_type_code
2009 , p_log_level_rec => p_log_level_rec) then
2010 if (p_log_level_rec.statement_level) then
2011 fa_debug_pkg.add(l_calling_fn, 'error calling', 'check_dpis_change', p_log_level_rec);
2012 end if;
2013 raise bld_err;
2014 end if;
2015
2016 if (l_period_counter is not null) then
2017 x_asset_fin_rec.cost := l_asset_fin_rec.cost;
2018 x_asset_fin_rec.cip_cost := l_asset_fin_rec.cip_cost;
2019 x_asset_fin_rec.salvage_value := l_asset_fin_rec.salvage_value;
2020 x_asset_fin_rec.allowed_deprn_limit_amount := l_asset_fin_rec.allowed_deprn_limit_amount;
2021 end if;
2022 end if; -- (nvl(l_cost, 0) = 0) and
2023
2024 if (p_log_level_rec.statement_level) then
2025 fa_debug_pkg.add(l_calling_fn, 'cost', x_asset_fin_rec.cost, p_log_level_rec);
2026 fa_debug_pkg.add(l_calling_fn, 'cip_cost', x_asset_fin_rec.cip_cost, p_log_level_rec);
2027 fa_debug_pkg.add(l_calling_fn, 'salvage_value',
2028 x_asset_fin_rec.salvage_value, p_log_level_rec);
2029 fa_debug_pkg.add(l_calling_fn, 'allowed_deprn_limit_amount',
2030 x_asset_fin_rec.allowed_deprn_limit_amount, p_log_level_rec);
2031 fa_debug_pkg.add(l_calling_fn, 'salvage_type',
2035 fa_debug_pkg.add(l_calling_fn, 'deprn_limit_type',
2032 x_asset_fin_rec.salvage_type, p_log_level_rec);
2033 fa_debug_pkg.add(l_calling_fn, 'percent_salvage_value',
2034 x_asset_fin_rec.percent_salvage_value, p_log_level_rec);
2036 x_asset_fin_rec.deprn_limit_type, p_log_level_rec);
2037 fa_debug_pkg.add(l_calling_fn, 'allowed_deprn_limit',
2038 x_asset_fin_rec.allowed_deprn_limit, p_log_level_rec);
2039 end if;
2040
2041 end if; -- (tr_transaction_header_id(i) <>
2042
2043 end if; -- (not l_reinstated)
2044
2045 END LOOP;
2046
2047 if (p_log_level_rec.statement_level) then
2048 fa_debug_pkg.add(l_calling_fn||'()+', 'Finish Getting Deltas for Each Trx',
2049 tr_transaction_header_id.COUNT, p_log_level_rec);
2050 end if;
2051
2052 --
2053 -- if this is not reclass, return delta
2054 -- if this is reclass, return member's from dpis no matter
2055 -- what is reclass date is.
2056 -- if reclass date is not dpis, update won't include upto that period.
2057 -- adjust foall update statement to update necessary period
2058 -- note: in that case, first period for the reclass got some hit
2059 -- of cost, reserve from dpis to the period
2060 --
2061
2062 if (p_reclass_src_dest is not null) then
2063 l_sal_thid := t_transaction_header_id(1);
2064 l_limit_thid := t_transaction_header_id(1);
2065
2066 fa_amort_pvt.tmd_period_counter(1) := t_period_counter(1);
2067
2068 x_td_cost(1) := fa_amort_pvt.tmd_cost(1);
2069 t_cost(1) := fa_amort_pvt.tmd_cost(1);
2070 fa_amort_pvt.tm_cost(1) := fa_amort_pvt.tmd_cost(1);
2071 x_td_cip_cost(1) := fa_amort_pvt.tmd_cip_cost(1);
2072 t_cip_cost(1) := fa_amort_pvt.tmd_cip_cost(1);
2073 fa_amort_pvt.tm_cip_cost(1) := fa_amort_pvt.tmd_cip_cost(1);
2074
2075 --tk_util.debug('fa_amort_pvt.tmd_period_counter(1): '||to_char(fa_amort_pvt.tmd_period_counter(1)));
2076 --tk_util.debug('fa_amort_pvt.tmd_cost(1): '||to_char(fa_amort_pvt.tmd_cost(1)));
2077 --tk_util.debug('fa_amort_pvt.tmd_cip_cost(1): '||to_char(fa_amort_pvt.tmd_cip_cost(1)));
2078 --tk_util.debug('fa_amort_pvt.tmd_salvage_value(1): '||to_char(fa_amort_pvt.tmd_salvage_value(1)));
2079
2080 if (t_salvage_type(1) = 'PCT') then
2081 l_temp_num := t_cost(1) * t_percent_salvage_value(1);
2082 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
2083 ,p_log_level_rec => p_log_level_rec);
2084 x_td_salvage_value(1) := l_temp_num;
2085 t_salvage_value(1) := l_temp_num;
2086 fa_amort_pvt.tmd_salvage_value(1) := l_temp_num;
2087 fa_amort_pvt.tm_salvage_value(1) := l_temp_num;
2088 else
2089 x_td_salvage_value(1) := fa_amort_pvt.tmd_salvage_value(1);
2090 t_salvage_value(1) := fa_amort_pvt.tmd_salvage_value(1);
2091 fa_amort_pvt.tmd_salvage_value(1) := fa_amort_pvt.tmd_salvage_value(1);
2092 fa_amort_pvt.tm_salvage_value(1) := fa_amort_pvt.tmd_salvage_value(1);
2093 end if;
2094 --tk_util.debug('x_td_salvage_value(1): '||to_char(x_td_salvage_value(1)));
2095
2096 if (t_deprn_limit_type(1) = 'PCT') then
2097 l_temp_num := t_cost(1) * (1 - t_allowed_deprn_limit(1));
2098 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
2099 ,p_log_level_rec => p_log_level_rec);
2100 x_td_deprn_limit_amount(1) := l_temp_num;
2101 t_deprn_limit_amount(1) := l_temp_num;
2102 fa_amort_pvt.tmd_deprn_limit_amount(1) := l_temp_num;
2103 fa_amort_pvt.tm_deprn_limit_amount(1) := l_temp_num;
2104 elsif (t_deprn_limit_type(1) = 'NONE') then
2105 x_td_deprn_limit_amount(1) := x_td_salvage_value(1);
2106 t_deprn_limit_amount(1) := x_td_salvage_value(1);
2107 fa_amort_pvt.tmd_deprn_limit_amount(1) := x_td_salvage_value(1);
2108 fa_amort_pvt.tm_deprn_limit_amount(1) := x_td_salvage_value(1);
2109 else
2110 x_td_deprn_limit_amount(1) := fa_amort_pvt.tmd_deprn_limit_amount(1);
2111 t_deprn_limit_amount(1) := fa_amort_pvt.tmd_deprn_limit_amount(1);
2112 fa_amort_pvt.tmd_deprn_limit_amount(1) := fa_amort_pvt.tmd_deprn_limit_amount(1);
2113 fa_amort_pvt.tm_deprn_limit_amount(1) := fa_amort_pvt.tmd_deprn_limit_amount(1);
2114 end if;
2115
2116 if (p_log_level_rec.statement_level) then
2117 fa_debug_pkg.add(l_calling_fn, 'Finish Populating First Record',
2118 x_td_cost(1), p_log_level_rec);
2119 end if;
2120
2121 FOR i in 2..t_period_counter.COUNT LOOP
2122
2123 fa_amort_pvt.tmd_period_counter(i) := t_period_counter(i);
2124 x_td_cost(i) := fa_amort_pvt.tmd_cost(i);
2125 t_cost(i) := fa_amort_pvt.tmd_cost(i) + t_cost(i - 1);
2126 fa_amort_pvt.tm_cost(i) := fa_amort_pvt.tmd_cost(i) + t_cost(i - 1);
2127 x_td_cip_cost(i) := fa_amort_pvt.tmd_cip_cost(i);
2128 t_cip_cost(i) := fa_amort_pvt.tmd_cip_cost(i) + t_cip_cost(i - 1);
2129 fa_amort_pvt.tm_cip_cost(i) := fa_amort_pvt.tmd_cip_cost(i) + t_cip_cost(i - 1);
2130 --tk_util.debug('fa_amort_pvt.tmd_period_counter(i): '||to_char(fa_amort_pvt.tmd_period_counter(i)));
2131 --tk_util.debug('fa_amort_pvt.tm_cost(i): '||to_char(fa_amort_pvt.tm_cost(i)));
2132 --tk_util.debug('fa_amort_pvt.tmd_cost(i): '||to_char(fa_amort_pvt.tmd_cost(i)));
2133 --tk_util.debug('x_td_cost(i): '||to_char(x_td_cost(i)));
2137 if (t_sal_thid(i) = 0) or
2134 --tk_util.debug('fa_amort_pvt.tmd_cip_cost(i): '||to_char(fa_amort_pvt.tmd_cip_cost(i)));
2135 --tk_util.debug('fa_amort_pvt.tmd_salvage_value(i): '||to_char(fa_amort_pvt.tmd_salvage_value(i)));
2136
2138 (l_sal_thid >= t_sal_thid(i)) then
2139 t_salvage_type(i) := t_salvage_type(i - 1);
2140 t_percent_salvage_value(i) := t_percent_salvage_value(i - 1);
2141 end if;
2142
2143 if (t_limit_thid(i) = 0) or
2144 (l_limit_thid >= t_limit_thid(i)) then
2145 t_deprn_limit_type(i) := t_deprn_limit_type(i - 1);
2146 t_allowed_deprn_limit(i) := t_allowed_deprn_limit(i - 1);
2147 end if;
2148
2149 if (t_salvage_type(i) = 'PCT') then
2150 l_temp_num := t_cost(i) * t_percent_salvage_value(i);
2151 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
2152 ,p_log_level_rec => p_log_level_rec);
2153 x_td_salvage_value(i) := l_temp_num;
2154 t_salvage_value(i) := l_temp_num - x_td_salvage_value(i - 1);
2155 fa_amort_pvt.tmd_salvage_value(i) := l_temp_num - fa_amort_pvt.tm_salvage_value(i - 1);
2156 fa_amort_pvt.tm_salvage_value(i) := l_temp_num;
2157 else
2158 x_td_salvage_value(i) := fa_amort_pvt.tmd_salvage_value(i) +
2159 x_td_salvage_value(i - 1);
2160 t_salvage_value(i) := fa_amort_pvt.tmd_salvage_value(i);
2161 fa_amort_pvt.tm_salvage_value(i) := fa_amort_pvt.tmd_salvage_value(i) +
2162 t_salvage_value(i - 1);
2163 end if;
2164 --tk_util.debug('x_td_salvage_value(i): '||to_char(x_td_salvage_value(i)));
2165
2166 if (t_deprn_limit_type(i) = 'PCT') then
2167 l_temp_num := t_cost(i) * (1 - t_allowed_deprn_limit(i));
2168 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
2169 ,p_log_level_rec => p_log_level_rec);
2170 t_deprn_limit_amount(i) := l_temp_num;
2171 x_td_deprn_limit_amount(i) := l_temp_num - t_deprn_limit_amount(i - 1);
2172 fa_amort_pvt.tmd_deprn_limit_amount(i) := l_temp_num -
2173 fa_amort_pvt.tm_deprn_limit_amount(i - 1);
2174 fa_amort_pvt.tm_deprn_limit_amount(i) := l_temp_num;
2175 elsif (t_deprn_limit_type(i) = 'NONE') then
2176 t_deprn_limit_amount(i) := x_td_salvage_value(i);
2177 x_td_deprn_limit_amount(i) := t_salvage_value(i) - t_deprn_limit_amount(i - 1);
2178 fa_amort_pvt.tmd_deprn_limit_amount(i) := fa_amort_pvt.tm_salvage_value(i) -
2179 fa_amort_pvt.tm_deprn_limit_amount(i - 1);
2180 fa_amort_pvt.tm_deprn_limit_amount(i) := x_td_salvage_value(i);
2181 else
2182 t_deprn_limit_amount(i) := fa_amort_pvt.tmd_deprn_limit_amount(i);
2183 x_td_deprn_limit_amount(i) := fa_amort_pvt.tmd_deprn_limit_amount(i) +
2184 x_td_deprn_limit_amount(i - 1);
2185 fa_amort_pvt.tm_deprn_limit_amount(i) := fa_amort_pvt.tmd_deprn_limit_amount(i) +
2186 x_td_deprn_limit_amount(i - 1);
2187 end if;
2188 --tk_util.debug('bottom of loop');
2189 END LOOP; -- i in 2..t_period_counter.COUNT
2190 --tk_util.debug('End Loop');
2191
2192 l_ind := p_period_rec.period_counter - t_period_counter(1) + 1;
2193 --tk_util.debug('l_ind: '||to_char(l_ind));
2194
2195 x_asset_fin_rec_reclass.cost := t_cost(l_ind);
2196 x_asset_fin_rec_reclass.cip_cost := t_cip_cost(l_ind);
2197 x_asset_fin_rec_reclass.salvage_value := x_td_salvage_value(l_ind);
2198 x_asset_fin_rec_reclass.allowed_deprn_limit_amount := x_td_deprn_limit_amount(l_ind);
2199
2200 else
2201
2202 --
2203 -- Prepare delta for non-group reclass adjustments
2204 --
2205
2206 l_sal_thid := t_transaction_header_id(1);
2207 l_limit_thid := t_transaction_header_id(1);
2208 t_cost(1) := fa_amort_pvt.tmd_cost(1);
2209 t_cip_cost(1) := fa_amort_pvt.tmd_cip_cost(1);
2210
2211 if (t_salvage_type(1) = 'PCT') then
2212 l_temp_num := t_cost(1) * t_percent_salvage_value(1);
2213 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
2214 ,p_log_level_rec => p_log_level_rec);
2215 t_salvage_value(1) := l_temp_num;
2216 else
2217 t_salvage_value(1) := fa_amort_pvt.tmd_salvage_value(1);
2218 end if;
2219
2220 if (p_log_level_rec.statement_level) then
2221 fa_debug_pkg.add(l_calling_fn, 't_salvage_type(1)',
2222 t_salvage_type(1), p_log_level_rec);
2223 fa_debug_pkg.add(l_calling_fn, 't_percent_salvage_value',
2224 t_percent_salvage_value(1), p_log_level_rec);
2225 fa_debug_pkg.add(l_calling_fn, 't_salvage_value',
2226 t_salvage_value(1), p_log_level_rec);
2227 fa_debug_pkg.add(l_calling_fn, 't_deprn_limit_type(1)',
2228 t_deprn_limit_type(1), p_log_level_rec);
2229
2230 end if;
2231
2232
2233 if (t_deprn_limit_type(1) = 'PCT') then
2234 l_temp_num := t_cost(1) * (1 - t_allowed_deprn_limit(1));
2235 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
2236 ,p_log_level_rec => p_log_level_rec);
2240 else
2237 t_deprn_limit_amount(1) := l_temp_num;
2238 elsif (t_deprn_limit_type(1) = 'NONE') then
2239 t_deprn_limit_amount(1) := t_salvage_value(1);
2241 t_deprn_limit_amount(1) := fa_amort_pvt.tmd_deprn_limit_amount(1);
2242 end if;
2243
2244 if (p_log_level_rec.statement_level) then
2245 fa_debug_pkg.add(l_calling_fn, 'Finish Populating First Record',
2246 t_cost(1), p_log_level_rec);
2247 end if;
2248
2249 FOR i in 2..t_period_counter.COUNT LOOP
2250
2251 if (p_log_level_rec.statement_level) then
2252 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.tmd_cost('||to_char(i)||')',
2253 fa_amort_pvt.tmd_cost(i), p_log_level_rec);
2254 fa_debug_pkg.add(l_calling_fn, 't_cost('||to_char(i-1)||')',
2255 t_cost(i - 1), p_log_level_rec);
2256 end if;
2257
2258 t_cost(i) := fa_amort_pvt.tmd_cost(i) + t_cost(i - 1);
2259 t_cip_cost(i) := fa_amort_pvt.tmd_cip_cost(i) + t_cip_cost(i - 1);
2260
2261 if (t_sal_thid(i) = 0) or
2262 (l_sal_thid >= t_sal_thid(i)) then
2263 t_salvage_type(i) := t_salvage_type(i - 1);
2264 t_percent_salvage_value(i) := t_percent_salvage_value(i - 1);
2265 end if;
2266
2267 if (t_limit_thid(i) = 0) or
2268 (l_limit_thid >= t_limit_thid(i)) then
2269 t_deprn_limit_type(i) := t_deprn_limit_type(i - 1);
2270 t_allowed_deprn_limit(i) := t_allowed_deprn_limit(i - 1);
2271 end if;
2272
2273 if (p_log_level_rec.statement_level) then
2274 fa_debug_pkg.add(l_calling_fn, 't_salvage_type('||to_char(i)||')',
2275 t_salvage_type(i), p_log_level_rec);
2276 fa_debug_pkg.add(l_calling_fn, 't_deprn_limit_type('||to_char(i)||')',
2277 t_deprn_limit_type(i), p_log_level_rec);
2278 end if;
2279
2280
2281 if (t_salvage_type(i) = 'PCT') then
2282 l_temp_num := t_cost(i) * t_percent_salvage_value(i);
2283 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
2284 ,p_log_level_rec => p_log_level_rec);
2285 t_salvage_value(i) := l_temp_num;
2286 else
2287 t_salvage_value(i) := fa_amort_pvt.tmd_salvage_value(i) +
2288 t_salvage_value(i - 1);
2289 end if;
2290
2291 if (p_log_level_rec.statement_level) then
2292 fa_debug_pkg.add(l_calling_fn, 't_percent_salvage_value',
2293 t_percent_salvage_value(i), p_log_level_rec);
2294 fa_debug_pkg.add(l_calling_fn, 't_salvage_value',
2295 t_salvage_value(i), p_log_level_rec);
2296 end if;
2297
2298
2299 if (t_deprn_limit_type(i) = 'PCT') then
2300 l_temp_num := t_cost(i) * (1 - t_allowed_deprn_limit(i));
2301 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
2302 ,p_log_level_rec => p_log_level_rec);
2303 t_deprn_limit_amount(i) := l_temp_num;
2304 elsif (t_deprn_limit_type(i) = 'NONE') then
2305 t_deprn_limit_amount(i) := t_salvage_value(i);
2306 else
2307 t_deprn_limit_amount(i) := fa_amort_pvt.tmd_deprn_limit_amount(i) +
2308 t_deprn_limit_amount(i - 1);
2309 end if;
2310
2311 if (p_log_level_rec.statement_level) then
2312 fa_debug_pkg.add(l_calling_fn, 't_deprn_limit_amount',
2313 t_deprn_limit_amount(i), p_log_level_rec);
2314 end if;
2315
2316
2317 END LOOP; -- i in 2..t_period_counter.COUNT
2318
2319 if (p_log_level_rec.statement_level) then
2320 fa_debug_pkg.add(l_calling_fn, 'Finish Populating All Records',
2321 t_cost(t_period_counter.COUNT), p_log_level_rec);
2322 end if;
2323
2324 l_ind := p_period_rec.period_counter - t_period_counter(1) + 1;
2325
2326 --tk_util.debug('x_td_cost(1): '||to_char(x_asset_fin_rec.cost));
2327 --tk_util.debug('l_ind: '||to_char(l_ind));
2328
2329 --
2330 -- Now Construct delta table to be applied against group table
2331 --
2332 -- Bug4958977: Replacing with following if statement.
2333 -- Original lines are executed if first condition is met
2334
2335 x_td_period_counter(1) := t_period_counter(l_ind);
2336 if (l_cur_trx_period_counter = x_td_period_counter(1)) then
2337 x_td_cost(1) := x_asset_fin_rec.cost;
2338 x_td_cip_cost(1) := x_asset_fin_rec.cip_cost;
2339 elsif (l_period_counter = x_td_period_counter(1)) then
2340 x_td_cost(1) := (-1 * l_asset_fin_rec.cost);
2341 x_td_cip_cost(1) := (-1 * l_asset_fin_rec.cip_cost);
2342 else
2343 x_td_cost(1) := 0;
2344 x_td_cip_cost(1) := 0;
2345 end if;
2346
2347 if (p_log_level_rec.statement_level) then
2348 fa_debug_pkg.add(l_calling_fn, 't_cost('||to_char(l_ind)||')',
2349 t_cost(l_ind), p_log_level_rec);
2350 fa_debug_pkg.add(l_calling_fn, 'x_td_cost('||to_char(1)||')',
2351 x_td_cost(1), p_log_level_rec);
2352 end if;
2353
2354
2358
2355 -- Bug4958977: Use x_td_xxxx instead of x_asset_fin_rec
2356 t_cost(l_ind) := t_cost(l_ind) + x_td_cost(1);
2357 t_cip_cost(l_ind) := t_cip_cost(l_ind) + x_td_cip_cost(1);
2359 --tk_util.debug('x_td_period_counter(1): '|| to_char(x_td_period_counter(1)));
2360 --tk_util.debug('x_td_cost(1): '|| to_char(x_td_cost(1)));
2361 --tk_util.debug('t_cost('||to_char(l_ind)||'): '|| to_char(t_cost(l_ind)));
2362 --tk_util.debug('t_salvage_type('||to_char(l_ind)||'): '|| t_salvage_type(l_ind));
2363 --tk_util.debug('x_asset_fin_rec.percent_salvage_value: '|| to_char(x_asset_fin_rec.percent_salvage_value));
2364 --tk_util.debug('fa_amort_pvt.tmd_salvage_value('||to_char(l_ind)||'): '||to_char(fa_amort_pvt.tmd_salvage_value(l_ind)));
2365 --tk_util.debug('t_salvage_value('||to_char(l_ind)||'): '|| to_char(t_salvage_value(l_ind)));
2366
2367 if (t_salvage_type(l_ind) = 'PCT') then
2368 -- l_temp_num := t_cost(l_ind) * t_percent_salvage_value(l_ind);
2369 l_temp_num := t_cost(l_ind) * x_asset_fin_rec.percent_salvage_value;
2370 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
2371 ,p_log_level_rec => p_log_level_rec);
2372
2373 x_td_salvage_value(1) := l_temp_num - t_salvage_value(l_ind);
2374 t_salvage_value(l_ind) := l_temp_num;
2375 else
2376 x_td_salvage_value(1) := x_asset_fin_rec.salvage_value;
2377 t_salvage_value(l_ind) := t_salvage_value(l_ind) + x_asset_fin_rec.salvage_value;
2378 end if;
2379
2380 if (t_deprn_limit_type(l_ind) = 'PCT') then
2381 -- l_temp_num := t_cost(l_ind) * (1 - t_allowed_deprn_limit(l_ind));
2382 l_temp_num := t_cost(l_ind) * (1 - x_asset_fin_rec.allowed_deprn_limit);
2383 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
2384 ,p_log_level_rec => p_log_level_rec);
2385 x_td_deprn_limit_amount(1) := l_temp_num - t_deprn_limit_amount(l_ind);
2386
2387 t_deprn_limit_amount(l_ind) := l_temp_num;
2388 else
2389 x_td_deprn_limit_amount(1) := x_asset_fin_rec.allowed_deprn_limit_amount;
2390 t_deprn_limit_amount(l_ind) := t_deprn_limit_amount(l_ind) +
2391 x_asset_fin_rec.allowed_deprn_limit_amount;
2392 end if;
2393 --tk_util.debug('x_td_salvage_value(1): '||to_char(x_td_salvage_value(1)));
2394 --tk_util.debug('x_td_deprn_limit_amount(1): '||to_char(x_td_deprn_limit_amount(1)));
2395
2396
2397 FOR i in 2..(t_period_counter.LAST - l_ind + 1) LOOP
2398 l_ind := l_ind + 1;
2399
2400 --Bug4958977: Conditionally populate x_td_cost(cip_cost) instead of populating
2401 -- 0 all the time. Modified until next debug statement
2402 x_td_period_counter(i) := t_period_counter(l_ind);
2403
2404 if (p_log_level_rec.statement_level) then
2405 fa_debug_pkg.add(l_calling_fn, 'x_td_period_counter('||to_char(i)||')',
2406 x_td_period_counter(i), p_log_level_rec);
2407 fa_debug_pkg.add(l_calling_fn, 'x_asset_fin_rec.cost',
2408 x_asset_fin_rec.cost, p_log_level_rec);
2409 fa_debug_pkg.add(l_calling_fn, 't_cost('||to_char(l_ind)||')',
2410 t_cost(l_ind), p_log_level_rec);
2411 end if;
2412
2413
2414 if (l_cur_trx_period_counter = x_td_period_counter(i)) then
2415 x_td_cost(i) := x_asset_fin_rec.cost;
2416 x_td_cip_cost(i) := x_asset_fin_rec.cip_cost;
2417 t_cost(l_ind) := t_cost(l_ind) + x_td_cost(i);
2418 t_cip_cost(l_ind) := t_cip_cost(l_ind) + x_td_cip_cost(i);
2419 elsif (l_period_counter = x_td_period_counter(i)) then
2420 x_td_cost(i) := (-1 * l_asset_fin_rec.cost);
2421 x_td_cip_cost(i) := (-1 * l_asset_fin_rec.cip_cost);
2422 t_cost(l_ind) := t_cost(l_ind) + x_td_cost(i);
2423 t_cip_cost(l_ind) := t_cip_cost(l_ind) + x_td_cip_cost(i);
2424 else
2425 x_td_cost(i) := 0;
2426 x_td_cip_cost(i) := 0;
2427 -- t_cost(l_ind) := t_cost(l_ind) + t_cost(l_ind - 1);
2428 -- t_cip_cost(l_ind) := t_cip_cost(l_ind) + t_cip_cost(l_ind - 1);
2429 t_cost(l_ind) := t_cost(l_ind) + x_asset_fin_rec.cost;
2430 t_cip_cost(l_ind) := t_cip_cost(l_ind) + x_asset_fin_rec.cip_cost;
2431 end if;
2432
2433 if (p_log_level_rec.statement_level) then
2434 fa_debug_pkg.add(l_calling_fn, 'i', i, p_log_level_rec);
2435 fa_debug_pkg.add(l_calling_fn, 'x_td_period_counter(i)',
2436 x_td_period_counter(i), p_log_level_rec);
2437 fa_debug_pkg.add(l_calling_fn, 't_cost('||to_char(l_ind)||')',
2438 t_cost(l_ind), p_log_level_rec);
2439 fa_debug_pkg.add(l_calling_fn, 'x_td_cost('||to_char(i)||')',
2440 x_td_cost(i), p_log_level_rec);
2441 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.tmd_salvage_value',
2442 fa_amort_pvt.tmd_salvage_value(l_ind), p_log_level_rec);
2443 fa_debug_pkg.add(l_calling_fn, 't_salvage_type(l_ind)',
2444 t_salvage_type(l_ind), p_log_level_rec);
2445 fa_debug_pkg.add(l_calling_fn, 't_salvage_value',
2446 t_salvage_value(l_ind), p_log_level_rec);
2447 end if;
2448
2449 if (t_salvage_type(l_ind) = 'PCT') then
2450 l_temp_num := t_cost(l_ind) * x_asset_fin_rec.percent_salvage_value;
2451
2455
2452 if (p_log_level_rec.statement_level) then
2453 fa_debug_pkg.add(l_calling_fn, 'l_temp_num', l_temp_num, p_log_level_rec);
2454 end if;
2456 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
2457 ,p_log_level_rec => p_log_level_rec);
2458
2459 x_td_salvage_value(i) := l_temp_num - t_salvage_value(l_ind);
2460
2461 t_salvage_value(l_ind) := l_temp_num;
2462 else
2463 x_td_salvage_value(i) := t_salvage_value(l_ind - 1) - t_salvage_value(l_ind);
2464
2465 t_salvage_value(i) := t_salvage_value(l_ind) + t_salvage_value(l_ind - 1);
2466 end if;
2467
2468 if (p_log_level_rec.statement_level) then
2469 fa_debug_pkg.add(l_calling_fn, 'x_td_salvage_value('||to_char(i)||')'
2470 , x_td_salvage_value(i), p_log_level_rec);
2471 fa_debug_pkg.add(l_calling_fn, 't_deprn_limit_amount('||to_char(l_ind)||')'
2472 , t_deprn_limit_amount(l_ind), p_log_level_rec);
2473 fa_debug_pkg.add(l_calling_fn, 'x_asset_fin_rec.allowed_deprn_limit'
2474 , x_asset_fin_rec.allowed_deprn_limit, p_log_level_rec);
2475 end if;
2476
2477 if (t_deprn_limit_type(i) = 'PCT') then
2478 -- l_temp_num := t_cost(l_ind) * (1 - t_allowed_deprn_limit(l_ind));
2479 l_temp_num := t_cost(l_ind) * (1 - x_asset_fin_rec.allowed_deprn_limit);
2480
2481 if (p_log_level_rec.statement_level) then
2482 fa_debug_pkg.add(l_calling_fn, 'l_temp_num'
2483 , l_temp_num, p_log_level_rec);
2484 fa_debug_pkg.add(l_calling_fn, 't_cost('||to_char(l_ind)||')'
2485 , t_cost(l_ind), p_log_level_rec);
2486 fa_debug_pkg.add(l_calling_fn, 'x_asset_fin_rec.allowed_deprn_limit'
2487 , x_asset_fin_rec.allowed_deprn_limit, p_log_level_rec);
2488 end if;
2489
2490 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
2491 ,p_log_level_rec => p_log_level_rec);
2492
2493 x_td_deprn_limit_amount(i) := l_temp_num - t_deprn_limit_amount(l_ind);
2494
2495 t_deprn_limit_amount(l_ind) := l_temp_num;
2496 else
2497 x_td_deprn_limit_amount(i) := t_deprn_limit_amount(l_ind - 1) -
2498 t_deprn_limit_amount(l_ind);
2499
2500 t_deprn_limit_amount(l_ind) := t_deprn_limit_amount(l_ind) +
2501 t_deprn_limit_amount(l_ind - 1);
2502 end if;
2503
2504 if (p_log_level_rec.statement_level) then
2505 fa_debug_pkg.add(l_calling_fn, 'x_td_deprn_limit_amount('||to_char(i)||')'
2506 , x_td_deprn_limit_amount(i), p_log_level_rec);
2507 fa_debug_pkg.add(l_calling_fn, 't_deprn_limit_amount('||to_char(l_ind)||')'
2508 , t_deprn_limit_amount(l_ind), p_log_level_rec);
2509 end if;
2510
2511
2512
2513 END LOOP; -- i in 2..t_cost.COUNT
2514
2515 end if; -- (p_reclass_src_dest is null)
2516
2517 if (p_log_level_rec.statement_level) then
2518 fa_debug_pkg.add(l_calling_fn||'()-', '# of rows in delta tables',
2519 x_td_cost.COUNT, p_log_level_rec);
2520 end if;
2521
2522 return TRUE;
2523
2524 EXCEPTION
2525 WHEN bld_err THEN
2526 if (p_log_level_rec.statement_level) then
2527 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'bld_err', p_log_level_rec);
2528 end if;
2529
2530 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn);
2531 return false;
2532
2533 WHEN OTHERS THEN
2534 if (p_log_level_rec.statement_level) then
2535 fa_debug_pkg.add(l_calling_fn||'(OTHERS)-', 'sqlcode', sqlcode, p_log_level_rec);
2536 end if;
2537
2538 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
2539 ,p_log_level_rec => p_log_level_rec);
2540 return false;
2541
2542 END buildMemberTable;
2543
2544 --+==============================================================================
2545 -- Function: CurrentPeriodAdj
2546 --
2547 --
2548 --
2549 --
2550 --
2551 --+==============================================================================
2552 FUNCTION CurrentPeriodAdj(
2553 p_trans_rec FA_API_TYPES.trans_rec_type,
2554 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
2555 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
2556 p_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type,
2557 p_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type default null,
2558 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
2559 p_period_rec FA_API_TYPES.period_rec_type,
2560 p_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type default null,
2561 p_proceeds_of_sale NUMBER default 0,
2562 p_cost_of_removal NUMBER default 0,
2563 p_calling_fn VARCHAR2,
2564 p_mrc_sob_type_code VARCHAR2,
2565 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
2566 return BOOLEAN is
2567
2568 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.CurrentPeriodAdj';
2569
2570 CURSOR c_get_deltas IS
2574 from fa_books inbk,
2571 select inbk.salvage_value - nvl(outbk.salvage_value, 0)
2572 , nvl(inbk.allowed_deprn_limit_amount, 0) -
2573 nvl(outbk.allowed_deprn_limit_amount, 0)
2575 fa_books outbk
2576 where outbk.asset_id(+) = inbk.asset_id
2577 and outbk.book_type_code(+) = inbk.book_type_code
2578 and inbk.transaction_header_id_in = p_trans_rec.member_transaction_header_id
2579 and outbk.transaction_header_id_out(+) = inbk.transaction_header_id_in;
2580
2581 CURSOR c_get_mc_deltas IS
2582 select inbk.salvage_value - nvl(outbk.salvage_value, 0)
2583 , nvl(inbk.allowed_deprn_limit_amount, 0) -
2584 nvl(outbk.allowed_deprn_limit_amount, 0)
2585 from fa_books_mrc_v inbk,
2586 fa_books_mrc_v outbk
2587 where outbk.asset_id(+) = inbk.asset_id
2588 and outbk.book_type_code(+) = inbk.book_type_code
2589 and inbk.transaction_header_id_in = p_trans_rec.member_transaction_header_id
2590 and outbk.transaction_header_id_out(+) = inbk.transaction_header_id_in;
2591
2592 --
2593 -- Cursor to get retirement information using retirement
2594 -- transaction_header_id
2595 --
2596 CURSOR c_get_ret_info (c_transaction_header_id number) IS
2597 select ret.proceeds_of_sale
2598 , ret.cost_of_removal
2599 , -1 * nvl(ret.reserve_retired, 0)
2600 , -1 * nbv_retired
2601 from fa_retirements ret
2602 where ret.transaction_header_id_in = c_transaction_header_id
2603 and ret.transaction_header_id_out is null;
2604
2605 CURSOR c_get_mc_ret_info (c_transaction_header_id number) IS
2606 select ret.proceeds_of_sale
2607 , ret.cost_of_removal
2608 , -1 * nvl(ret.reserve_retired, 0)
2609 , -1 * nbv_retired
2610 from fa_retirements_mrc_v ret
2611 where ret.transaction_header_id_in = c_transaction_header_id
2612 and ret.transaction_header_id_out is null;
2613
2614 --
2615 -- Cursor to get retirement information using reinsatement
2616 -- transaction_header_id
2617 --
2618 CURSOR c_get_rein_info (c_transaction_header_id number) IS
2619 select -1 * ret.proceeds_of_sale
2620 , -1 * ret.cost_of_removal
2621 , nvl(ret.reserve_retired, 0)
2622 , nbv_retired
2623 from fa_retirements ret
2624 , fa_transaction_headers mth
2625 where mth.transaction_header_id = c_transaction_header_id
2626 and mth.asset_id = ret.asset_id
2627 and mth.book_type_code = p_asset_hdr_rec.book_type_code
2628 and ret.book_type_code = p_asset_hdr_rec.book_type_code
2629 and ret.transaction_header_id_out = c_transaction_header_id;
2630
2631 CURSOR c_get_mc_rein_info (c_transaction_header_id number) IS
2632 select -1 * ret.proceeds_of_sale
2633 , -1 * ret.cost_of_removal
2634 , nvl(ret.reserve_retired, 0)
2635 , nbv_retired
2636 from fa_retirements_mrc_v ret
2637 , fa_transaction_headers mth
2638 where mth.transaction_header_id = c_transaction_header_id
2639 and mth.asset_id = ret.asset_id
2640 and mth.book_type_code = p_asset_hdr_rec.book_type_code
2641 and ret.book_type_code = p_asset_hdr_rec.book_type_code
2642 and ret.transaction_header_id_out = c_transaction_header_id;
2643
2644 CURSOR c_check_record_exists IS
2645 select bs.period_counter
2646 from fa_books_summary bs
2647 where bs.asset_id = p_asset_hdr_rec.asset_id
2648 and bs.book_type_code = p_asset_hdr_rec.book_type_code
2649 and bs.period_counter = p_period_rec.period_counter;
2650
2651 CURSOR c_check_mc_record_exists IS
2652 select bs.period_counter
2653 from fa_books_summary_mrc_v bs
2654 where bs.asset_id = p_asset_hdr_rec.asset_id
2655 and bs.book_type_code = p_asset_hdr_rec.book_type_code
2656 and bs.period_counter = p_period_rec.period_counter;
2657
2658
2659 l_asset_id NUMBER(15);
2660 l_delta_salvage_value NUMBER;
2661 l_delta_deprn_limit_amount NUMBER;
2662 l_expense_amount NUMBER;
2663 l_reserve_amount NUMBER;
2664 l_unplanned_amount NUMBER := 0;
2665
2666 l_proceeds_of_sale NUMBER;
2667 l_cost_of_removal NUMBER;
2668 l_reserve_retired NUMBER;
2669 l_nbv_retired NUMBER;
2670
2671 l_depreciate_flag_change BOOLEAN := FALSE;
2672 l_disabled_flag_change BOOLEAN := FALSE;
2673
2674 l_temp_num NUMBER; -- temporary numbers for calculation
2675 l_valid_type_change BOOLEAN := TRUE;
2676
2677 adj_err EXCEPTION;
2678
2679 BEGIN
2680
2681 if (p_log_level_rec.statement_level) then
2682 fa_debug_pkg.add(l_calling_fn||'()+', 'asset type',
2683 p_asset_type_rec.asset_type, p_log_level_rec);
2684 fa_debug_pkg.add(l_calling_fn, 'member trx id',
2685 p_trans_rec.member_transaction_header_id,
2686 p_log_level_rec);
2687 fa_debug_pkg.add(l_calling_fn, 'trx key',
2688 p_trans_rec.transaction_key,
2689 p_log_level_rec);
2690 end if;
2691
2692 -- Bug5149789: checking whether member exists or not
2693 -- Call function check_member_existence if either of
2694 -- salvage or deprn limit type is being changed and there is 0 group cost
2698 ((px_asset_fin_rec_new.deprn_limit_type = 'SUM') and
2695 if (((px_asset_fin_rec_new.salvage_type = 'SUM') and
2696 (px_asset_fin_rec_new.salvage_type <> nvl(p_asset_fin_rec_old.salvage_type,
2697 px_asset_fin_rec_new.salvage_type))) or
2699 (px_asset_fin_rec_new.deprn_limit_type <> nvl(p_asset_fin_rec_old.deprn_limit_type,
2700 px_asset_fin_rec_new.deprn_limit_type)))) then
2701
2702 if (px_asset_fin_rec_new.cost = 0) then
2703
2704 if not check_member_existence (p_asset_hdr_rec => p_asset_hdr_rec) then
2705 if (p_log_level_rec.statement_level) then
2706 fa_debug_pkg.add(l_calling_fn, 'calling check_member_existence',
2707 'FAILED', p_log_level_rec);
2708 end if;
2709
2710 l_valid_type_change := FALSE;
2711
2712 end if;
2713
2714 else
2715 if (p_log_level_rec.statement_level) then
2716 fa_debug_pkg.add(l_calling_fn, 'Method.deprn_limit type change'
2717 , 'FAILED', p_log_level_rec);
2718 fa_debug_pkg.add(l_calling_fn, 'cost',
2719 px_asset_fin_rec_new.cost, p_log_level_rec);
2720 end if;
2721
2722 l_valid_type_change := FALSE;
2723
2724 end if;
2725
2726 if (not l_valid_type_change) then
2727 if (px_asset_fin_rec_new.salvage_type = 'SUM') then
2728 fa_srvr_msg.add_message(
2729 calling_fn => l_calling_fn,
2730 name => 'FA_INVALID_PARAMETER',
2731 token1 => 'VALUE',
2732 value1 => px_asset_fin_rec_new.salvage_type,
2733 token2 => 'PARAM',
2734 value2 => 'SALVAGE_TYPE',
2735 p_log_level_rec => p_log_level_rec);
2736
2737 else
2738 fa_srvr_msg.add_message(
2739 calling_fn => l_calling_fn,
2740 name => 'FA_INVALID_PARAMETER',
2741 token1 => 'VALUE',
2742 value1 => px_asset_fin_rec_new.deprn_limit_type,
2743 token2 => 'PARAM',
2744 value2 => 'DEPRN_LIMIT_TYPE',
2745 p_log_level_rec => p_log_level_rec);
2746 end if;
2747
2748 return false;
2749 end if;
2750
2751 end if; -- (((px_asset_fin_rec_new.salvage_type = 'SUM') and
2752
2753 if (p_asset_fin_rec_old.depreciate_flag = 'NO') or
2754 (nvl(p_asset_fin_rec_old.disabled_flag, 'N') = 'Y') then
2755
2756 l_depreciate_flag_change := (p_asset_fin_rec_old.depreciate_flag <>
2757 px_asset_fin_rec_new.depreciate_flag);
2758
2759 l_disabled_flag_change := (nvl(p_asset_fin_rec_old.disabled_flag, 'N') <>
2760 nvl(px_asset_fin_rec_new.disabled_flag, 'N'));
2761
2762 if (not catchupBooksSummary (
2763 p_trans_rec => p_trans_rec,
2764 p_asset_hdr_rec => p_asset_hdr_rec,
2765 p_period_rec => p_period_rec,
2766 p_asset_fin_rec_new => px_asset_fin_rec_new,
2767 p_depreciate_flag_change => l_depreciate_flag_change,
2768 p_disabled_flag_change => l_disabled_flag_change,
2769 p_mrc_sob_type_code => p_mrc_sob_type_code,
2770 p_calling_fn => l_calling_fn
2771 ,p_log_level_rec => p_log_level_rec)) then
2772
2773 if (p_log_level_rec.statement_level) then
2774 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'catchupBooksSummary'
2775 ,p_log_level_rec => p_log_level_rec);
2776 end if;
2777
2778 raise adj_err;
2779
2780 end if;
2781 elsif (p_asset_fin_rec_old.period_counter_fully_reserved is not null) or
2782 (p_asset_fin_rec_old.period_counter_life_complete is not null) then
2783 l_temp_num := null;
2784
2785 if (p_mrc_sob_type_code = 'R') then
2786 OPEN c_check_mc_record_exists;
2787 FETCH c_check_mc_record_exists INTO l_temp_num;
2788 CLOSE c_check_mc_record_exists;
2789 else
2790 OPEN c_check_record_exists;
2791 FETCH c_check_record_exists INTO l_temp_num;
2792 CLOSE c_check_record_exists;
2793 end if;
2794
2795 if l_temp_num is null then
2796 if (not catchupBooksSummary (
2797 p_trans_rec => p_trans_rec,
2798 p_asset_hdr_rec => p_asset_hdr_rec,
2799 p_period_rec => p_period_rec,
2800 p_asset_fin_rec_new => px_asset_fin_rec_new,
2801 p_depreciate_flag_change => l_depreciate_flag_change,
2802 p_disabled_flag_change => l_disabled_flag_change,
2803 p_mrc_sob_type_code => p_mrc_sob_type_code,
2804 p_calling_fn => l_calling_fn
2805 ,p_log_level_rec => p_log_level_rec)) then
2806
2807 if (p_log_level_rec.statement_level) then
2808 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'catchupBooksSummary'
2809 ,p_log_level_rec => p_log_level_rec);
2810 end if;
2811
2812 raise adj_err;
2813
2814 end if;
2818 /*
2815 end if;
2816 end if;
2817
2819 --
2820 -- Unplanned Depreciation
2821 --
2822 if (p_trans_rec.transaction_key in ('UA', 'UE')) then
2823 -- Expecting unplanned amount stored in p_asset_deprn_rec_adj.deprn_amount
2824 l_expense_amount := p_asset_deprn_rec_adj.deprn_amount;
2825 l_unplanned_amount := p_asset_deprn_rec_adj.deprn_amount;
2826 elsif (p_trans_rec.transaction_key in ('GV', 'GR')) then
2827 l_reserve_amount := p_asset_deprn_rec_adj.deprn_reserve;
2828 end if;
2829 */
2830 l_expense_amount := nvl(p_asset_deprn_rec_adj.deprn_amount, 0);
2831 l_unplanned_amount := nvl(p_asset_deprn_rec_adj.deprn_amount, 0);
2832 l_reserve_amount := nvl(p_asset_deprn_rec_adj.deprn_reserve, 0);
2833
2834 --tk_util.debug('p_asset_fin_rec_old.adjusted_capacity: '||to_char(p_asset_fin_rec_old.adjusted_capacity));
2835 --tk_util.debug('p_asset_fin_rec_adj.adjusted_capacity: '||to_char(p_asset_fin_rec_adj.adjusted_capacity));
2836
2837 /*
2838 if (nvl(px_asset_fin_rec_new.tracking_method, 'NO TRACK') = 'ALLOCATE') and -- ENERGY
2839 (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') and -- ENERGY
2840 (fa_cache_pkg.fazccmt_record.rate_source_rule = FA_STD_TYPES.FAD_RSR_PROD) then
2841 px_asset_fin_rec_new.adjusted_capacity := nvl(px_asset_fin_rec_new.production_capacity, 0) +
2842 nvl(p_asset_fin_rec_adj.adjusted_capacity, 0);
2843 end if;
2844 */
2845
2846 if (p_trans_rec.member_transaction_header_id is null) then
2847
2848 --tk_util.debug('p_asset_fin_rec_adj.cost: '||to_char(p_asset_fin_rec_adj.cost));
2849 --tk_util.debug('p_asset_fin_rec_adj.cip_cost: '||to_char(p_asset_fin_rec_adj.cip_cost));
2850 --tk_util.debug('l_delta_salvage_value: '||to_char(l_delta_salvage_value));
2851 --tk_util.debug('l_delta_deprn_limit_amount: '||to_char(l_delta_deprn_limit_amount));
2852 --tk_util.debug('p_proceeds_of_sale: '||to_char(p_proceeds_of_sale));
2853 --tk_util.debug('p_cost_of_removal: '||to_char(p_cost_of_removal));
2854 --tk_util.debug('l_unplanned_amount: '||to_char(l_unplanned_amount));
2855 --tk_util.debug('l_expense_amount: '||to_char(l_expense_amount));
2856 --tk_util.debug('l_reserve_amount: '||to_char(l_reserve_amount));
2857
2858 if (p_mrc_sob_type_code = 'R') then
2859
2860 UPDATE FA_BOOKS_SUMMARY_MRC_V
2861 SET RESET_ADJUSTED_COST_FLAG = 'Y'
2862 , SALVAGE_TYPE = px_asset_fin_rec_new.salvage_type
2863 , PERCENT_SALVAGE_VALUE = px_asset_fin_rec_new.percent_salvage_value
2864 , SALVAGE_VALUE = px_asset_fin_rec_new.salvage_value
2865 , RECOVERABLE_COST = px_asset_fin_rec_new.recoverable_cost
2866 , DEPRN_LIMIT_TYPE = px_asset_fin_rec_new.deprn_limit_type
2867 , ALLOWED_DEPRN_LIMIT = px_asset_fin_rec_new.allowed_deprn_limit
2868 , ALLOWED_DEPRN_LIMIT_AMOUNT = px_asset_fin_rec_new.allowed_deprn_limit_amount
2869 , ADJUSTED_RECOVERABLE_COST = px_asset_fin_rec_new.adjusted_recoverable_cost
2870 , ADJUSTED_COST = px_asset_fin_rec_new.adjusted_cost
2871 , DEPRECIATE_FLAG = px_asset_fin_rec_new.depreciate_flag
2872 , DISABLED_FLAG = px_asset_fin_rec_new.disabled_flag
2873 , DEPRN_METHOD_CODE = px_asset_fin_rec_new.deprn_method_code
2874 , LIFE_IN_MONTHS = px_asset_fin_rec_new.life_in_months
2875 , RATE_ADJUSTMENT_FACTOR = px_asset_fin_rec_new.rate_adjustment_factor
2876 , ADJUSTED_RATE = px_asset_fin_rec_new.adjusted_rate
2877 , BONUS_RULE = px_asset_fin_rec_new.bonus_rule
2878 , ADJUSTED_CAPACITY = px_asset_fin_rec_new.adjusted_capacity
2879 , PRODUCTION_CAPACITY = px_asset_fin_rec_new.production_capacity
2880 , UNIT_OF_MEASURE = px_asset_fin_rec_new.unit_of_measure
2881 , REMAINING_LIFE1 = px_asset_fin_rec_new.remaining_life1
2882 , REMAINING_LIFE2 = px_asset_fin_rec_new.remaining_life2
2883 , FORMULA_FACTOR = px_asset_fin_rec_new.formula_factor
2884 , CEILING_NAME = px_asset_fin_rec_new.ceiling_name
2885 , SHORT_FISCAL_YEAR_FLAG = px_asset_fin_rec_new.short_fiscal_year_flag
2886 , SUPER_GROUP_ID = px_asset_fin_rec_new.super_group_id
2887 , OVER_DEPRECIATE_OPTION = px_asset_fin_rec_new.over_depreciate_option
2888 , DEPRN_AMOUNT = DEPRN_AMOUNT + l_expense_amount
2889 , YTD_DEPRN = YTD_DEPRN + l_expense_amount
2890 , DEPRN_RESERVE = DEPRN_RESERVE + l_expense_amount + l_reserve_amount
2891 , YTD_PROCEEDS_OF_SALE = nvl(YTD_PROCEEDS_OF_SALE, 0) + p_proceeds_of_sale
2892 , LTD_PROCEEDS_OF_SALE = nvl(LTD_PROCEEDS_OF_SALE, 0) + p_proceeds_of_sale
2893 , YTD_COST_OF_REMOVAL = nvl(YTD_COST_OF_REMOVAL, 0) + p_cost_of_removal
2894 , LTD_COST_OF_REMOVAL = nvl(LTD_COST_OF_REMOVAL, 0) + p_cost_of_removal
2895 , UNPLANNED_AMOUNT = UNPLANNED_AMOUNT + l_unplanned_amount
2896 , EXPENSE_ADJUSTMENT_AMOUNT = EXPENSE_ADJUSTMENT_AMOUNT + l_expense_amount
2897 , RESERVE_ADJUSTMENT_AMOUNT = RESERVE_ADJUSTMENT_AMOUNT + l_reserve_amount
2898 , LAST_UPDATE_DATE = p_trans_rec.who_info.last_update_date
2899 , LAST_UPDATED_BY = p_trans_rec.who_info.last_updated_by
2900 , LAST_UPDATE_LOGIN = p_trans_rec.who_info.last_update_login
2904
2901 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
2902 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
2903 AND PERIOD_COUNTER = p_period_rec.period_counter;
2905 else
2906
2907 UPDATE FA_BOOKS_SUMMARY
2908 SET RESET_ADJUSTED_COST_FLAG = 'Y'
2909 , SALVAGE_TYPE = px_asset_fin_rec_new.salvage_type
2910 , PERCENT_SALVAGE_VALUE = px_asset_fin_rec_new.percent_salvage_value
2911 , SALVAGE_VALUE = px_asset_fin_rec_new.salvage_value
2912 , RECOVERABLE_COST = px_asset_fin_rec_new.recoverable_cost
2913 , DEPRN_LIMIT_TYPE = px_asset_fin_rec_new.deprn_limit_type
2914 , ALLOWED_DEPRN_LIMIT = px_asset_fin_rec_new.allowed_deprn_limit
2915 , ALLOWED_DEPRN_LIMIT_AMOUNT = px_asset_fin_rec_new.allowed_deprn_limit_amount
2916 , ADJUSTED_RECOVERABLE_COST = px_asset_fin_rec_new.adjusted_recoverable_cost
2917 , ADJUSTED_COST = px_asset_fin_rec_new.adjusted_cost
2918 , DEPRECIATE_FLAG = px_asset_fin_rec_new.depreciate_flag
2919 , DISABLED_FLAG = px_asset_fin_rec_new.disabled_flag
2920 , DEPRN_METHOD_CODE = px_asset_fin_rec_new.deprn_method_code
2921 , LIFE_IN_MONTHS = px_asset_fin_rec_new.life_in_months
2922 , RATE_ADJUSTMENT_FACTOR = px_asset_fin_rec_new.rate_adjustment_factor
2923 , ADJUSTED_RATE = px_asset_fin_rec_new.adjusted_rate
2924 , BONUS_RULE = px_asset_fin_rec_new.bonus_rule
2925 , ADJUSTED_CAPACITY = px_asset_fin_rec_new.adjusted_capacity
2926 , PRODUCTION_CAPACITY = px_asset_fin_rec_new.production_capacity
2927 , UNIT_OF_MEASURE = px_asset_fin_rec_new.unit_of_measure
2928 , REMAINING_LIFE1 = px_asset_fin_rec_new.remaining_life1
2929 , REMAINING_LIFE2 = px_asset_fin_rec_new.remaining_life2
2930 , FORMULA_FACTOR = px_asset_fin_rec_new.formula_factor
2931 , CEILING_NAME = px_asset_fin_rec_new.ceiling_name
2932 , SHORT_FISCAL_YEAR_FLAG = px_asset_fin_rec_new.short_fiscal_year_flag
2933 , SUPER_GROUP_ID = px_asset_fin_rec_new.super_group_id
2934 , OVER_DEPRECIATE_OPTION = px_asset_fin_rec_new.over_depreciate_option
2935 , DEPRN_AMOUNT = DEPRN_AMOUNT + l_expense_amount
2936 , YTD_DEPRN = YTD_DEPRN + l_expense_amount
2937 , DEPRN_RESERVE = DEPRN_RESERVE + l_expense_amount + l_reserve_amount
2938 , YTD_PROCEEDS_OF_SALE = nvl(YTD_PROCEEDS_OF_SALE, 0) + p_proceeds_of_sale
2939 , LTD_PROCEEDS_OF_SALE = nvl(LTD_PROCEEDS_OF_SALE, 0) + p_proceeds_of_sale
2940 , YTD_COST_OF_REMOVAL = nvl(YTD_COST_OF_REMOVAL, 0) + p_cost_of_removal
2941 , LTD_COST_OF_REMOVAL = nvl(LTD_COST_OF_REMOVAL, 0) + p_cost_of_removal
2942 , UNPLANNED_AMOUNT = UNPLANNED_AMOUNT + l_unplanned_amount
2943 , EXPENSE_ADJUSTMENT_AMOUNT = EXPENSE_ADJUSTMENT_AMOUNT + l_expense_amount
2944 , RESERVE_ADJUSTMENT_AMOUNT = RESERVE_ADJUSTMENT_AMOUNT + l_reserve_amount
2945 , LAST_UPDATE_DATE = p_trans_rec.who_info.last_update_date
2946 , LAST_UPDATED_BY = p_trans_rec.who_info.last_updated_by
2947 , LAST_UPDATE_LOGIN = p_trans_rec.who_info.last_update_login
2948 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
2949 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
2950 AND PERIOD_COUNTER = p_period_rec.period_counter;
2951
2952 end if;
2953
2954 else
2955
2956 if (p_mrc_sob_type_code = 'R') then
2957 OPEN c_get_mc_deltas;
2958 FETCH c_get_mc_deltas INTO l_delta_salvage_value
2959 , l_delta_deprn_limit_amount;
2960 CLOSE c_get_mc_deltas;
2961 else
2962 OPEN c_get_deltas;
2963 FETCH c_get_deltas INTO l_delta_salvage_value
2964 , l_delta_deprn_limit_amount;
2965 CLOSE c_get_deltas;
2966 end if;
2967
2968 --
2969 -- Get Retirement information
2970 --
2971 if (p_trans_rec.transaction_key = 'MR') then
2972 if (p_mrc_sob_type_code = 'R') then
2973 OPEN c_get_mc_ret_info(p_trans_rec.member_transaction_header_id);
2974 FETCH c_get_mc_ret_info INTO l_proceeds_of_sale
2975 , l_cost_of_removal
2976 , l_reserve_retired
2977 , l_nbv_retired;
2978 CLOSE c_get_mc_ret_info;
2979 else
2980 OPEN c_get_ret_info(p_trans_rec.member_transaction_header_id);
2981 FETCH c_get_ret_info INTO l_proceeds_of_sale
2982 , l_cost_of_removal
2983 , l_reserve_retired
2984 , l_nbv_retired;
2985 CLOSE c_get_ret_info;
2986 end if;
2987 elsif (p_trans_rec.transaction_key = 'MS') then
2988 if (p_mrc_sob_type_code = 'R') then
2989 OPEN c_get_mc_rein_info(p_trans_rec.member_transaction_header_id);
2990 FETCH c_get_mc_rein_info INTO l_proceeds_of_sale
2991 , l_cost_of_removal
2992 , l_reserve_retired
2993 , l_nbv_retired;
2997 FETCH c_get_rein_info INTO l_proceeds_of_sale
2994 CLOSE c_get_mc_rein_info;
2995 else
2996 OPEN c_get_rein_info(p_trans_rec.member_transaction_header_id);
2998 , l_cost_of_removal
2999 , l_reserve_retired
3000 , l_nbv_retired;
3001 CLOSE c_get_rein_info;
3002 end if;
3003
3004 l_reserve_amount := l_reserve_retired;
3005 else
3006 l_proceeds_of_sale := 0;
3007 l_cost_of_removal := 0;
3008 l_reserve_retired := 0;
3009 l_nbv_retired := 0;
3010 end if;
3011
3012 --tk_util.debug('p_asset_fin_rec_adj.cost: '||to_char(p_asset_fin_rec_adj.cost));
3013 --tk_util.debug('p_asset_fin_rec_adj.cip_cost: '||to_char(p_asset_fin_rec_adj.cip_cost));
3014 --tk_util.debug('l_delta_salvage_value: '||to_char(l_delta_salvage_value));
3015 --tk_util.debug('l_delta_deprn_limit_amount: '||to_char(l_delta_deprn_limit_amount));
3016 --tk_util.debug('p_proceeds_of_sale: '||to_char(l_proceeds_of_sale));
3017 --tk_util.debug('p_cost_of_removal: '||to_char(l_cost_of_removal));
3018 --tk_util.debug('l_unplanned_amount: '||to_char(l_unplanned_amount));
3019 --tk_util.debug('l_expense_amount: '||to_char(l_expense_amount));
3020 --tk_util.debug('l_reserve_amount: '||to_char(l_reserve_amount));
3021
3022 if (p_mrc_sob_type_code = 'R') then
3023
3024 UPDATE FA_BOOKS_SUMMARY_MRC_V
3025 SET RESET_ADJUSTED_COST_FLAG = 'Y'
3026 , CHANGE_IN_COST = CHANGE_IN_COST + nvl(p_asset_fin_rec_adj.cost, 0)
3027 , CHANGE_IN_CIP_COST = CHANGE_IN_CIP_COST + nvl(p_asset_fin_rec_adj.cip_cost, 0)
3028 , COST = px_asset_fin_rec_new.cost
3029 , CIP_COST = px_asset_fin_rec_new.cip_cost
3030 , SALVAGE_VALUE = px_asset_fin_rec_new.salvage_value
3031 , MEMBER_SALVAGE_VALUE = MEMBER_SALVAGE_VALUE + nvl(l_delta_salvage_value, 0)
3032 , RECOVERABLE_COST = px_asset_fin_rec_new.recoverable_cost
3033 , ALLOWED_DEPRN_LIMIT_AMOUNT = px_asset_fin_rec_new.allowed_deprn_limit_amount
3034 , MEMBER_DEPRN_LIMIT_AMOUNT = MEMBER_DEPRN_LIMIT_AMOUNT +
3035 nvl(l_delta_deprn_limit_amount,
3036 decode(MEMBER_DEPRN_LIMIT_AMOUNT, NULL, NUll, 0))
3037 , ADJUSTED_RECOVERABLE_COST = px_asset_fin_rec_new.adjusted_recoverable_cost
3038 , ADJUSTED_COST = px_asset_fin_rec_new.ADJUSTED_COST
3039 , UNREVALUED_COST = px_asset_fin_rec_new.UNREVALUED_COST
3040 , REVAL_AMORTIZATION_BASIS = px_asset_fin_rec_new.REVAL_AMORTIZATION_BASIS
3041 , DEPRN_AMOUNT = DEPRN_AMOUNT + l_expense_amount
3042 , YTD_DEPRN = YTD_DEPRN + l_expense_amount
3043 , DEPRN_RESERVE = DEPRN_RESERVE + l_expense_amount + l_reserve_amount
3044 , YTD_PROCEEDS_OF_SALE = nvl(YTD_PROCEEDS_OF_SALE, 0) + l_proceeds_of_sale
3045 , LTD_PROCEEDS_OF_SALE = nvl(LTD_PROCEEDS_OF_SALE, 0) + l_proceeds_of_sale
3046 , YTD_COST_OF_REMOVAL = nvl(YTD_COST_OF_REMOVAL, 0) + l_cost_of_removal
3047 , LTD_COST_OF_REMOVAL = nvl(LTD_COST_OF_REMOVAL, 0) + l_cost_of_removal
3048 , UNPLANNED_AMOUNT = UNPLANNED_AMOUNT + l_unplanned_amount
3049 , EXPENSE_ADJUSTMENT_AMOUNT = EXPENSE_ADJUSTMENT_AMOUNT + l_expense_amount
3050 , RESERVE_ADJUSTMENT_AMOUNT = RESERVE_ADJUSTMENT_AMOUNT + l_reserve_amount
3051 , LAST_UPDATE_DATE = p_trans_rec.who_info.last_update_date
3052 , LAST_UPDATED_BY = p_trans_rec.who_info.last_updated_by
3053 , LAST_UPDATE_LOGIN = p_trans_rec.who_info.last_update_login
3054 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
3055 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
3056 AND PERIOD_COUNTER = p_period_rec.period_counter;
3057
3058 else
3059
3060 UPDATE FA_BOOKS_SUMMARY
3061 SET RESET_ADJUSTED_COST_FLAG = 'Y'
3062 , CHANGE_IN_COST = CHANGE_IN_COST + nvl(p_asset_fin_rec_adj.cost, 0)
3063 , CHANGE_IN_CIP_COST = CHANGE_IN_CIP_COST + nvl(p_asset_fin_rec_adj.cip_cost, 0)
3064 , COST = COST + nvl(p_asset_fin_rec_adj.cost, 0)
3065 , CIP_COST = CIP_COST + nvl(p_asset_fin_rec_adj.cip_cost, 0)
3066 , SALVAGE_VALUE = px_asset_fin_rec_new.salvage_value
3067 , MEMBER_SALVAGE_VALUE = MEMBER_SALVAGE_VALUE + nvl(l_delta_salvage_value, 0)
3068 , RECOVERABLE_COST = px_asset_fin_rec_new.recoverable_cost
3069 , ALLOWED_DEPRN_LIMIT_AMOUNT = px_asset_fin_rec_new.allowed_deprn_limit_amount
3070 , MEMBER_DEPRN_LIMIT_AMOUNT = MEMBER_DEPRN_LIMIT_AMOUNT +
3071 nvl(l_delta_deprn_limit_amount,
3072 decode(MEMBER_DEPRN_LIMIT_AMOUNT, NULL, NUll, 0))
3073 , ADJUSTED_RECOVERABLE_COST = px_asset_fin_rec_new.adjusted_recoverable_cost
3074 , ADJUSTED_COST = px_asset_fin_rec_new.ADJUSTED_COST
3075 , UNREVALUED_COST = px_asset_fin_rec_new.UNREVALUED_COST
3076 , REVAL_AMORTIZATION_BASIS = px_asset_fin_rec_new.REVAL_AMORTIZATION_BASIS
3077 , DEPRN_AMOUNT = DEPRN_AMOUNT + l_expense_amount
3078 , YTD_DEPRN = YTD_DEPRN + l_expense_amount
3079 , DEPRN_RESERVE = DEPRN_RESERVE + l_expense_amount + l_reserve_amount
3083 , LTD_COST_OF_REMOVAL = nvl(LTD_COST_OF_REMOVAL, 0) + l_cost_of_removal
3080 , YTD_PROCEEDS_OF_SALE = nvl(YTD_PROCEEDS_OF_SALE, 0) + l_proceeds_of_sale
3081 , LTD_PROCEEDS_OF_SALE = nvl(LTD_PROCEEDS_OF_SALE, 0) + l_proceeds_of_sale
3082 , YTD_COST_OF_REMOVAL = nvl(YTD_COST_OF_REMOVAL, 0) + l_cost_of_removal
3084 , UNPLANNED_AMOUNT = UNPLANNED_AMOUNT + l_unplanned_amount
3085 , EXPENSE_ADJUSTMENT_AMOUNT = EXPENSE_ADJUSTMENT_AMOUNT + l_expense_amount
3086 , RESERVE_ADJUSTMENT_AMOUNT = RESERVE_ADJUSTMENT_AMOUNT + l_reserve_amount
3087 , LAST_UPDATE_DATE = p_trans_rec.who_info.last_update_date
3088 , LAST_UPDATED_BY = p_trans_rec.who_info.last_updated_by
3089 , LAST_UPDATE_LOGIN = p_trans_rec.who_info.last_update_login
3090 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
3091 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
3092 AND PERIOD_COUNTER = p_period_rec.period_counter;
3093
3094 end if;
3095
3096 end if;
3097
3098 printBooksSummary(p_asset_id => p_asset_hdr_rec.asset_id,
3099 p_book_type_code => p_asset_hdr_rec.book_type_code
3100 ,p_log_level_rec => p_log_level_rec);
3101 -- p_period_counter => p_period_rec.period_counter);
3102
3103 if (p_log_level_rec.statement_level) then
3104 fa_debug_pkg.add(l_calling_fn||'()-', 'asset id', p_asset_hdr_rec.asset_id);
3105 end if;
3106
3107 return TRUE;
3108
3109 EXCEPTION
3110 WHEN adj_err THEN
3111 if (p_log_level_rec.statement_level) then
3112 fa_debug_pkg.add(l_calling_fn||'(adj_err)-', 'sqlcode', sqlcode);
3113 end if;
3114
3115 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
3116 ,p_log_level_rec => p_log_level_rec);
3117 return false;
3118
3119 WHEN OTHERS THEN
3120
3121 if (p_log_level_rec.statement_level) then
3122 fa_debug_pkg.add(l_calling_fn||'(OTHERS)-', 'sqlcode', sqlcode);
3123 end if;
3124
3125 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
3126 ,p_log_level_rec => p_log_level_rec);
3127 return false;
3128
3129 END CurrentPeriodAdj;
3130
3131 --+==============================================================================
3132 -- Function: bsRecalculate
3133 --
3134 -- This function calculate catch-up amounts due to backdated
3135 -- amortization transactions.
3136
3137 -- 3.2: Call faxcde to get reserve for adjusted_cost, raf and formula_factor
3138 -- 3.3: Call Deprn Basis function to get new adjusted_cost, raf and formula_factor.
3139 -- 4: Return catch-up amount.
3140 --+==============================================================================
3141 FUNCTION bsRecalculate(
3142 p_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
3143 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
3144 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
3145 p_asset_desc_rec FA_API_TYPES.asset_desc_rec_type,
3146 p_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type,
3147 p_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type default null,
3148 p_period_rec FA_API_TYPES.period_rec_type,
3149 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
3150 p_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type,
3151 p_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type default null,
3152 x_deprn_expense OUT NOCOPY NUMBER,
3153 x_bonus_expense OUT NOCOPY NUMBER,
3154 x_deprn_reserve OUT NOCOPY NUMBER,
3155 p_running_mode IN NUMBER,
3156 p_used_by_revaluation IN NUMBER,
3157 p_reclassed_asset_id NUMBER,
3158 p_reclass_src_dest VARCHAR2,
3159 p_group_reclass_type VARCHAR2, -- Bug : 6792185
3160 p_reclassed_asset_dpis DATE,
3161 p_update_books_summary BOOLEAN default FALSE,
3162 p_mrc_sob_type_code VARCHAR2,
3163 p_calling_fn VARCHAR2,
3164 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
3165
3166 l_calling_fn VARCHAR2(100) := 'FA_AMORT_PVT.bsRecalculate';
3167
3168 --
3169 -- This is to get date placed in service using transaction header id
3170 -- Bug4958977: Needed to modify to use older dpis
3171 CURSOR c_get_dpis (c_thid number) IS
3172 select least(inbk.date_placed_in_service, nvl(outbk.date_placed_in_service, inbk.date_placed_in_service))
3173 from fa_books inbk
3174 , fa_books outbk
3175 where inbk.transaction_header_id_in = c_thid
3176 and outbk.transaction_header_id_out(+) = inbk.transaction_header_id_in
3177 and outbk.asset_id(+) = inbk.asset_id
3178 and outbk.book_type_code(+) = inbk.book_type_code;
3179
3180 --
3181 -- This is to get period counter using FA_BOOKS_SUMMARY table
3182 --
3183 CURSOR c_get_books_summary(c_period_counter number) IS
3184 select
3185 bs.period_counter
3186 , bs.fiscal_year
3187 , bs.period_num
3188 , bs.calendar_period_open_date
3189 , bs.calendar_period_close_date
3190 , bs.reset_adjusted_cost_flag
3191 , bs.change_in_cost
3192 , bs.change_in_cip_cost
3196 , bs.percent_salvage_value
3193 , bs.cost
3194 , bs.cip_cost
3195 , bs.salvage_type
3197 , bs.salvage_value
3198 , bs.member_salvage_value
3199 , bs.recoverable_cost
3200 , bs.deprn_limit_type
3201 , bs.allowed_deprn_limit
3202 , bs.allowed_deprn_limit_amount
3203 , bs.member_deprn_limit_amount
3204 , bs.adjusted_recoverable_cost
3205 , bs.adjusted_cost
3206 , bs.depreciate_flag
3207 , bs.date_placed_in_service
3208 , bs.deprn_method_code
3209 , bs.life_in_months
3210 , bs.rate_adjustment_factor
3211 , bs.adjusted_rate
3212 , bs.bonus_rule
3213 , bs.adjusted_capacity
3214 , bs.production_capacity
3215 , bs.unit_of_measure
3216 , bs.remaining_life1
3217 , bs.remaining_life2
3218 , bs.formula_factor
3219 , bs.unrevalued_cost
3220 , bs.reval_amortization_basis
3221 , bs.reval_ceiling
3222 , bs.ceiling_name
3223 , bs.eofy_adj_cost
3224 , bs.eofy_formula_factor
3225 , bs.eofy_reserve
3226 , bs.eop_adj_cost
3227 , bs.eop_formula_factor
3228 , bs.short_fiscal_year_flag
3229 , bs.group_asset_id
3230 , bs.super_group_id
3231 , bs.over_depreciate_option
3232 , bs.deprn_amount
3233 , bs.ytd_deprn
3234 , bs.deprn_reserve
3235 , bs.bonus_deprn_amount
3236 , bs.bonus_ytd_deprn
3237 , bs.bonus_deprn_reserve
3238 , bs.bonus_rate
3239 , bs.ltd_production
3240 , bs.ytd_production
3241 , bs.production
3242 , bs.reval_amortization
3243 , bs.reval_deprn_expense
3244 , bs.reval_reserve
3245 , bs.ytd_reval_deprn_expense
3246 , bs.deprn_override_flag
3247 , bs.system_deprn_amount
3248 , bs.system_bonus_deprn_amount
3249 , bs.ytd_proceeds_of_sale
3250 , bs.ltd_proceeds_of_sale
3251 , bs.ytd_cost_of_removal
3252 , bs.ltd_cost_of_removal
3253 , bs.deprn_adjustment_amount
3254 , bs.expense_adjustment_amount
3255 , bs.reserve_adjustment_amount
3256 , bs.change_in_eofy_reserve
3257 from fa_books_summary bs
3258 where bs.asset_id = p_asset_hdr_rec.asset_id
3259 and bs.book_type_code = p_asset_hdr_rec.book_type_code
3260 and bs.period_counter >= c_period_counter
3261 order by bs.period_counter;
3262
3263 CURSOR c_get_mc_books_summary(c_period_counter number) IS
3264 select
3265 bs.period_counter
3266 , bs.fiscal_year
3267 , bs.period_num
3268 , bs.calendar_period_open_date
3269 , bs.calendar_period_close_date
3270 , bs.reset_adjusted_cost_flag
3271 , bs.change_in_cost
3272 , bs.change_in_cip_cost
3273 , bs.cost
3274 , bs.cip_cost
3275 , bs.salvage_type
3276 , bs.percent_salvage_value
3277 , bs.salvage_value
3278 , bs.member_salvage_value
3279 , bs.recoverable_cost
3280 , bs.deprn_limit_type
3281 , bs.allowed_deprn_limit
3282 , bs.allowed_deprn_limit_amount
3283 , bs.member_deprn_limit_amount
3284 , bs.adjusted_recoverable_cost
3285 , bs.adjusted_cost
3286 , bs.depreciate_flag
3287 , bs.date_placed_in_service
3288 , bs.deprn_method_code
3289 , bs.life_in_months
3290 , bs.rate_adjustment_factor
3291 , bs.adjusted_rate
3292 , bs.bonus_rule
3293 , bs.adjusted_capacity
3294 , bs.production_capacity
3295 , bs.unit_of_measure
3296 , bs.remaining_life1
3297 , bs.remaining_life2
3298 , bs.formula_factor
3299 , bs.unrevalued_cost
3300 , bs.reval_amortization_basis
3301 , bs.reval_ceiling
3302 , bs.ceiling_name
3303 , bs.eofy_adj_cost
3304 , bs.eofy_formula_factor
3305 , bs.eofy_reserve
3306 , bs.eop_adj_cost
3307 , bs.eop_formula_factor
3308 , bs.short_fiscal_year_flag
3309 , bs.group_asset_id
3310 , bs.super_group_id
3311 , bs.over_depreciate_option
3312 , bs.deprn_amount
3313 , bs.ytd_deprn
3314 , bs.deprn_reserve
3315 , bs.bonus_deprn_amount
3316 , bs.bonus_ytd_deprn
3317 , bs.bonus_deprn_reserve
3318 , bs.bonus_rate
3319 , bs.ltd_production
3320 , bs.ytd_production
3321 , bs.production
3322 , bs.reval_amortization
3323 , bs.reval_deprn_expense
3324 , bs.reval_reserve
3325 , bs.ytd_reval_deprn_expense
3326 , bs.deprn_override_flag
3327 , bs.system_deprn_amount
3328 , bs.system_bonus_deprn_amount
3329 , bs.ytd_proceeds_of_sale
3330 , bs.ltd_proceeds_of_sale
3331 , bs.ytd_cost_of_removal
3332 , bs.ltd_cost_of_removal
3333 , deprn_adjustment_amount
3334 , bs.expense_adjustment_amount
3335 , bs.reserve_adjustment_amount
3339 and bs.book_type_code = p_asset_hdr_rec.book_type_code
3336 , bs.change_in_eofy_reserve
3337 from fa_books_summary_mrc_v bs
3338 where bs.asset_id = p_asset_hdr_rec.asset_id
3340 and bs.period_counter >= c_period_counter
3341 order by bs.period_counter;
3342
3343
3344 CURSOR c_get_eofy_amts(c_period_counter number) IS
3345 select recoverable_cost
3346 , salvage_value
3347 , deprn_reserve
3348 from fa_books_summary
3349 where asset_id = p_asset_hdr_rec.asset_id
3350 and book_type_code = p_asset_hdr_rec.book_type_code
3351 and period_counter = c_period_counter;
3352
3353 CURSOR c_get_mc_eofy_amts(c_period_counter number) IS
3354 select recoverable_cost
3355 , salvage_value
3356 , deprn_reserve
3357 from fa_books_summary_mrc_v
3358 where asset_id = p_asset_hdr_rec.asset_id
3359 and book_type_code = p_asset_hdr_rec.book_type_code
3360 and period_counter = c_period_counter;
3361
3362 --
3363 -- Cursor to get retirement information using reinsatement
3364 -- transaction_header_id
3365 --
3366 CURSOR c_get_rein_info IS
3367 select -1 * ret.proceeds_of_sale
3368 , -1 * ret.cost_of_removal
3369 , ret.reserve_retired
3370 , nbv_retired
3371 from fa_retirements ret
3372 , fa_transaction_headers mth
3373 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
3374 and mth.asset_id = ret.asset_id
3375 and mth.book_type_code = p_asset_hdr_rec.book_type_code
3376 and ret.book_type_code = p_asset_hdr_rec.book_type_code
3377 and ret.transaction_header_id_out = p_trans_rec.member_transaction_header_id;
3378
3379 CURSOR c_get_mc_rein_info IS
3380 select -1 * ret.proceeds_of_sale
3381 , -1 * ret.cost_of_removal
3382 , nvl(ret.reserve_retired, 0)
3383 , nbv_retired
3384 from fa_retirements_mrc_v ret
3385 , fa_transaction_headers mth
3386 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
3387 and mth.asset_id = ret.asset_id
3388 and mth.book_type_code = p_asset_hdr_rec.book_type_code
3389 and ret.book_type_code = p_asset_hdr_rec.book_type_code
3390 and ret.transaction_header_id_out = p_trans_rec.member_transaction_header_id;
3391
3392 CURSOR c_check_record_exists IS
3393 select bs.period_counter
3394 from fa_books_summary bs
3395 where bs.asset_id = p_asset_hdr_rec.asset_id
3396 and bs.book_type_code = p_asset_hdr_rec.book_type_code
3397 and bs.period_counter = p_period_rec.period_counter;
3398
3399 CURSOR c_check_mc_record_exists IS
3400 select bs.period_counter
3401 from fa_books_summary_mrc_v bs
3402 where bs.asset_id = p_asset_hdr_rec.asset_id
3403 and bs.book_type_code = p_asset_hdr_rec.book_type_code
3404 and bs.period_counter = p_period_rec.period_counter;
3405
3406 /* Following cursor is added by HHIRAGA for tracking */
3407 CURSOR c_get_current_period IS
3408 select dp.period_counter
3409 from fa_deprn_periods dp
3410 where dp.book_type_code = p_asset_hdr_rec.book_type_code
3411 and dp.period_close_date is null;
3412
3413 CURSOR c_get_current_period_mrc IS
3414 select dp.period_counter
3415 from fa_deprn_periods_mrc_v dp
3416 where dp.book_type_code = p_asset_hdr_rec.book_type_code
3417 and dp.period_close_date is null;
3418
3419
3420 l_mem_trx BOOLEAN := FALSE; -- FALSE if this is group trx
3421 l_temp_num NUMBER; -- temporary numbers for calculation
3422
3423 l_period_rec FA_API_TYPES.period_rec_type; -- Store period information of
3424 -- the period where trx date
3425 -- falls into
3426 -- the period where trx date
3427 -- falls into, then
3428 -- store period info for
3429 -- each period processed.
3430 l_trx_period_rec FA_API_TYPES.period_rec_type; -- Store period information of
3431 -- the period where trx date
3432 -- falls into
3433
3434 l_ind BINARY_INTEGER; -- Used to find delta amounts for each period
3435 l_temp_ind BINARY_INTEGER; -- Indicate where to start updating FA_BOOKS_SUMMARY
3436 l_old_reserve NUMBER;
3437
3438 --
3439 -- Tables to store member delta information
3440 --
3441 td_period_counter fa_amort_pvt.tab_num15_type; -- not used
3442 td_cost fa_amort_pvt.tab_num_type; -- not used
3443 td_cip_cost fa_amort_pvt.tab_num_type; -- not used
3444 td_salvage_value fa_amort_pvt.tab_num_type;
3445 td_deprn_limit_amount fa_amort_pvt.tab_num_type;
3446
3447
3448 l_transaction_date_entered date; -- This is used as parameter for c_get_books_summary
3449 l_period_counter NUMBER(15);
3450
3451 l_bs_ind BINARY_INTEGER := 1;
3455
3452 d BINARY_INTEGER := 0; -- index for delta tables
3453 e BINARY_INTEGER := 0; -- index for delta tables to look for
3454 -- next period to maintain books summary
3456
3457 --
3458 -- Used to populate dpr_in
3459 --
3460 l_fiscal_year NUMBER(15);
3461 l_period_num NUMBER(15);
3462 l_adjusted_ind BINARY_INTEGER;
3463 l_count BINARY_INTEGER := 0; -- Stores count of tbs tables
3464
3465 --+++++ Store data related to each transactions +++++
3466 l_trans_rec FA_API_TYPES.trans_rec_type; -- Not used
3467 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type; -- For Deprn Basis
3468 l_asset_deprn_rec_raf FA_API_TYPES.asset_deprn_rec_type; -- For Deprn Basis
3469 l_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type; -- For Deprn Basis
3470 l_asset_fin_rec_new FA_API_TYPES.asset_fin_rec_type;
3471
3472 --+++++ Variables for calling buildMemberTable function +++++
3473 l_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type; -- Store member info
3474 t_period_counter fa_amort_pvt.tab_num15_type;
3475 t_delta_cost fa_amort_pvt.tab_num_type;
3476 t_delta_cip_cost fa_amort_pvt.tab_num_type;
3477 t_delta_salvage_value fa_amort_pvt.tab_num_type;
3478 t_delta_deprn_limit_amount fa_amort_pvt.tab_num_type;
3479 l_member_dpis DATE;
3480 l_multiplier NUMBER := 1;
3481 l_m_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type; -- member's delta info
3482 l_asset_fin_rec_reclass FA_API_TYPES.asset_fin_rec_type; -- correct fin rec adj for
3483 -- reclass
3484 l_salvage_limit_type VARCHAR2(30);
3485
3486 --+++++ Variables for CURSOR c_get_rein_info +++++
3487 l_nbv_retired NUMBER := 0;
3488 l_reserve_retired NUMBER;
3489 l_proceeds_of_sale NUMBER := 0;
3490 l_cost_of_removal NUMBER := 0;
3491
3492
3493 --+++++++++++++++ For calling faxcde +++++++++++++++
3494 l_dpr_in FA_STD_TYPES.dpr_struct;
3495 l_dpr_out FA_STD_TYPES.dpr_out_struct;
3496 l_dpr_arr FA_STD_TYPES.dpr_arr_type;
3497 l_running_mode NUMBER;
3498
3499 --
3500 -- These are used to store return values from faxcde which
3501 -- may not be used.
3502 --
3503 l_out_deprn_exp NUMBER;
3504 l_out_reval_exp NUMBER;
3505 l_out_reval_amo NUMBER;
3506 l_out_prod NUMBER;
3507 l_out_ann_adj_exp NUMBER;
3508 l_out_ann_adj_reval_exp NUMBER;
3509 l_out_ann_adj_reval_amo NUMBER;
3510 l_out_bonus_rate_used NUMBER;
3511 l_out_full_rsv_flag BOOLEAN;
3512 l_out_life_comp_flag BOOLEAN;
3513 l_out_deprn_override_flag VARCHAR2(1);
3514
3515
3516
3517 --+++++++ variables for old information +++++++
3518 l_eofy_rec_cost NUMBER; -- This needs to be populated from tbs
3519 l_eofy_sal_val NUMBER; -- This needs to be populated from tbs
3520 l_eop_rec_cost NUMBER; -- This needs to be populated from tbs
3521 l_eop_sal_val NUMBER; -- This needs to be populated from tbs
3522 l_eofy_reserve NUMBER;
3523
3524
3525 --++++++++ variables for manual override ++++++++
3526 l_rate_source_rule VARCHAR2(25);
3527 l_deprn_basis_rule VARCHAR2(25);
3528
3529 --++++++++ variables for calling catchupBooksSummary ++++++++
3530 l_depreciate_flag_change BOOLEAN := FALSE;
3531 l_disabled_flag_change BOOLEAN := FALSE;
3532
3533 l_gr_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type; -- For Reclass
3534 l_gr_ind BINARY_INTEGER;
3535
3536 --+ HHIRAGA added on Oct/Nov in 2003
3537 --++++++++ variables for Trackking Member Feature ++++++++
3538 l_processed_flag BOOLEAN := FALSE;
3539 l_backup_processed_flag BOOLEAN := FALSE;
3540 l_raf_processed_flag BOOLEAN := FALSE;
3541 l_first_process BOOLEAN := TRUE;
3542 l_current_period_counter NUMBER;
3543 l_mem_period_counter NUMBER;
3544
3545 l_mem_deprn_reserve NUMBER;
3546 l_mem_eofy_reserve NUMBER;
3547 l_mem_loop_first BOOLEAN := TRUE;
3548
3549 l_mem_ytd_deprn_addition NUMBER;
3550 l_mem_deprn_reserve_addition NUMBER;
3551
3552 l_recalc_start_fy NUMBER;
3553 l_recalc_start_period_num NUMBER;
3554 l_recalc_start_period_counter NUMBER;
3555 l_old_recalc_start_fy NUMBER;
3556 l_old_recalc_start_period_num NUMBER;
3557 l_old_recalc_end_fy NUMBER;
3558 l_old_recalc_end_period_num NUMBER;
3559 l_no_allocation_for_last VARCHAR2(1);
3560 l_chk_bs_row_exists VARCHAR2(1);
3561
3562 CURSOR c_chk_bs_row_exists IS
3563 select 'Y'
3564 from fa_books_summary
3565 where book_type_code = p_asset_hdr_rec.book_type_code
3566 and group_asset_id = p_asset_hdr_rec.asset_id
3567 and asset_id <> group_asset_id
3568 and period_counter = l_recalc_start_period_counter - 1;
3569
3573 where book_type_code = p_asset_hdr_rec.book_type_code
3570 CURSOR c_get_mem_bs_row IS
3571 select ytd_deprn,deprn_reserve,bonus_ytd_deprn,bonus_deprn_reserve,eofy_reserve
3572 from fa_books_summary
3574 and asset_id = p_reclassed_asset_id
3575 and group_asset_id = p_asset_hdr_rec.asset_id
3576 and period_counter = l_trx_period_rec.period_counter - 1;
3577
3578 CURSOR c_get_ytd_deprn IS
3579 select ytd_deprn,deprn_reserve
3580 from fa_deprn_summary
3581 where book_type_code = p_asset_hdr_rec.book_type_code
3582 and asset_id = p_reclassed_asset_id
3583 and period_counter = l_mem_period_counter
3584 and deprn_source_code = 'BOOKS';
3585
3586 --+ MRCsupport
3587 CURSOR c_chk_bs_row_exists_mrc IS
3588 select 'Y'
3589 from fa_books_summary_mrc_v
3590 where book_type_code = p_asset_hdr_rec.book_type_code
3591 and group_asset_id = p_asset_hdr_rec.asset_id
3592 and asset_id <> group_asset_id
3593 and period_counter = l_recalc_start_period_counter - 1;
3594
3595 CURSOR c_get_mem_bs_row_mrc IS
3596 select ytd_deprn,deprn_reserve,bonus_ytd_deprn,bonus_deprn_reserve,eofy_reserve
3597 from fa_books_summary_mrc_v
3598 where book_type_code = p_asset_hdr_rec.book_type_code
3599 and asset_id = p_reclassed_asset_id
3600 and group_asset_id = p_asset_hdr_rec.asset_id
3601 and period_counter = l_trx_period_rec.period_counter - 1;
3602
3603 CURSOR c_get_ytd_deprn_mrc IS
3604 select ytd_deprn,deprn_reserve
3605 from fa_deprn_summary_mrc_v
3606 where book_type_code = p_asset_hdr_rec.book_type_code
3607 and asset_id = p_reclassed_asset_id
3608 and period_counter = l_mem_period_counter
3609 and deprn_source_code = 'BOOKS';
3610
3611
3612 --+++++++++++++++++ Exceptions ++++++++++++++++++++++
3613 invalid_trx_to_overlap EXCEPTION; --This is currently not used but there is a
3614 --section in exception handling for future use.
3615 calc_failed EXCEPTION;
3616 l_adj_amt number; ----- bug# 5768759
3617 l_change_in_cost number; ----- bug# 5768759
3618 l_change_in_cip_cost number; ----- bug# 5768759
3619
3620 BEGIN
3621
3622 if (p_log_level_rec.statement_level) then
3623 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_type_rec.asset_type||
3624 ':'||p_asset_hdr_rec.asset_id
3625 ,p_log_level_rec => p_log_level_rec);
3626 fa_debug_pkg.add(l_calling_fn, 'Reclass values', p_reclass_src_dest||
3627 ':'||to_char(p_reclassed_asset_id)||':'||
3628 to_char(p_reclassed_asset_dpis, 'DD-MON-RR'));
3629 end if;
3630
3631 if (p_asset_fin_rec_old.depreciate_flag = 'NO') or
3632 (nvl(p_asset_fin_rec_old.disabled_flag, 'N') = 'Y') then
3633
3634 l_depreciate_flag_change := (p_asset_fin_rec_old.depreciate_flag <>
3635 px_asset_fin_rec_new.depreciate_flag);
3636
3637 l_disabled_flag_change := (nvl(p_asset_fin_rec_old.disabled_flag, 'N') <>
3638 nvl(px_asset_fin_rec_new.disabled_flag, 'N'));
3639
3640 if (not catchupBooksSummary (
3641 p_trans_rec => p_trans_rec,
3642 p_asset_hdr_rec => p_asset_hdr_rec,
3643 p_period_rec => p_period_rec,
3644 p_asset_fin_rec_new => px_asset_fin_rec_new,
3645 p_depreciate_flag_change => l_depreciate_flag_change,
3646 p_disabled_flag_change => l_disabled_flag_change,
3647 p_mrc_sob_type_code => p_mrc_sob_type_code,
3648 p_calling_fn => l_calling_fn
3649 ,p_log_level_rec => p_log_level_rec)) then
3650
3651 if (p_log_level_rec.statement_level) then
3652 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'catchupBooksSummary'
3653 ,p_log_level_rec => p_log_level_rec);
3654 end if;
3655
3656 raise calc_failed;
3657
3658 end if;
3659 elsif (p_asset_fin_rec_old.period_counter_fully_reserved is not null) or
3660 (p_asset_fin_rec_old.period_counter_life_complete is not null) then
3661 l_temp_num := null;
3662
3663 if (p_mrc_sob_type_code = 'R') then
3664 OPEN c_check_mc_record_exists;
3665 FETCH c_check_mc_record_exists INTO l_temp_num;
3666 CLOSE c_check_mc_record_exists;
3667 else
3668 OPEN c_check_record_exists;
3669 FETCH c_check_record_exists INTO l_temp_num;
3670 CLOSE c_check_record_exists;
3671 end if;
3672
3673 if l_temp_num is null then
3674 if (not catchupBooksSummary (
3675 p_trans_rec => p_trans_rec,
3676 p_asset_hdr_rec => p_asset_hdr_rec,
3677 p_period_rec => p_period_rec,
3678 p_asset_fin_rec_new => px_asset_fin_rec_new,
3679 p_depreciate_flag_change => l_depreciate_flag_change,
3680 p_disabled_flag_change => l_disabled_flag_change,
3684
3681 p_mrc_sob_type_code => p_mrc_sob_type_code,
3682 p_calling_fn => l_calling_fn
3683 ,p_log_level_rec => p_log_level_rec)) then
3685 if (p_log_level_rec.statement_level) then
3686 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'catchupBooksSummary'
3687 ,p_log_level_rec => p_log_level_rec);
3688 end if;
3689
3690 raise calc_failed;
3691
3692 end if;
3693 end if;
3694 end if;
3695
3696
3697 --
3698 -- Initialize global variables
3699 --
3700 InitGlobeVariables;
3701
3702 x_deprn_reserve := 0;
3703
3704 l_mem_trx := (p_trans_rec.member_transaction_header_id is not null);
3705
3706 l_transaction_date_entered := nvl(p_trans_rec.amortization_start_date,
3707 p_trans_rec.transaction_date_entered);
3708
3709 --
3710 -- Get period information of the period where transaction date falls into.
3711 --
3712 if not GetPeriodInfo(to_number(to_char(l_transaction_date_entered, 'J')),
3713 p_asset_hdr_rec.book_type_code,
3714 p_mrc_sob_type_code,
3715 l_period_rec) then
3716
3717 if (p_log_level_rec.statement_level) then
3718 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'GetPeriodInfo'
3719 ,p_log_level_rec => p_log_level_rec);
3720 end if;
3721
3722 raise calc_failed;
3723
3724 end if;
3725
3726 l_trx_period_rec := l_period_rec;
3727
3728 if not fa_cache_pkg.fazcct(fa_cache_pkg.fazcbc_record.deprn_calendar) then
3729
3730 if (p_log_level_rec.statement_level) then
3731 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'fa_cache_pkg.fazcct'
3732 ,p_log_level_rec => p_log_level_rec);
3733 end if;
3734
3735 raise calc_failed;
3736
3737 end if;
3738
3739 if (l_mem_trx) then
3740
3741 --
3742 -- Find member's date placed in service
3743 --
3744 if (p_trans_rec.transaction_key = 'GC') then
3745 l_member_dpis := p_reclassed_asset_dpis;
3746 else
3747 OPEN c_get_dpis(p_trans_rec.member_transaction_header_id);
3748 FETCH c_get_dpis INTO l_member_dpis;
3749 CLOSE c_get_dpis;
3750 end if;
3751
3752 -- Bug4958977: Adding following entire if statement
3753 if (p_trans_rec.transaction_key not in ('MR', 'MS', 'GC') and
3754 nvl(p_asset_fin_rec_adj.cost, 0) = 0 and
3755 nvl(p_asset_fin_rec_adj.cip_cost, 0) = 0 and
3756 nvl(p_asset_fin_rec_adj.salvage_value, 0) = 0 and
3757 nvl(p_asset_fin_rec_adj.allowed_deprn_limit_amount, 0) = 0) then
3758
3759
3760 --
3761 -- Get period information of the period where transaction date falls into.
3762 --
3763 if not GetPeriodInfo(to_number(to_char(l_member_dpis, 'J')),
3764 p_asset_hdr_rec.book_type_code,
3765 p_mrc_sob_type_code,
3766 l_period_rec) then
3767
3768 if (p_log_level_rec.statement_level) then
3769 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'GetPeriodInfo', p_log_level_rec);
3770 end if;
3771
3772 raise calc_failed;
3773
3774 end if;
3775
3776 l_trx_period_rec := l_period_rec;
3777
3778 end if;
3779
3780 l_asset_hdr_rec := p_asset_hdr_rec;
3781 l_asset_hdr_rec.asset_id := p_reclassed_asset_id;
3782
3783 if (p_reclass_src_dest = 'SOURCE') then
3784 l_multiplier := -1;
3785 end if;
3786
3787 --
3788 -- bug5149789: Need to pass this new variable to see if
3789 -- we need to track sum of member salvage value or not.
3790 --
3791 if (px_asset_fin_rec_new.salvage_type = 'SUM' or
3792 px_asset_fin_rec_new.deprn_limit_type = 'SUM') then
3793 l_salvage_limit_type := 'SUM';
3794 else
3795 l_salvage_limit_type := 'PCT';
3796 end if;
3797
3798 if not buildMemberTable(
3799 p_trans_rec => p_trans_rec,
3800 p_asset_hdr_rec => l_asset_hdr_rec,
3801 p_period_rec => l_period_rec,
3802 p_date_placed_in_service => l_member_dpis,
3803 p_group_asset_id => p_asset_hdr_rec.asset_id,
3804 p_reclass_multiplier => l_multiplier,
3805 p_reclass_src_dest => p_reclass_src_dest,
3806 p_salvage_limit_type => l_salvage_limit_type,
3807 x_td_period_counter => td_period_counter,
3808 x_td_cost => td_cost,
3809 x_td_cip_cost => td_cip_cost,
3810 x_td_salvage_value => td_salvage_value,
3811 x_td_deprn_limit_amount => td_deprn_limit_amount,
3812 x_asset_fin_rec => l_m_asset_fin_rec_adj,
3813 x_asset_fin_rec_reclass => l_asset_fin_rec_reclass,
3814 p_mrc_sob_type_code => p_mrc_sob_type_code
3815 ,p_log_level_rec => p_log_level_rec) then
3816
3820 end if;
3817 if (p_log_level_rec.statement_level) then
3818 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'buildMemberTable'
3819 ,p_log_level_rec => p_log_level_rec);
3821
3822 raise calc_failed;
3823 end if;
3824
3825 if (p_log_level_rec.statement_level) then
3826 fa_debug_pkg.add(l_calling_fn, '# of rows in delta talbe', td_cost.COUNT
3827 ,p_log_level_rec => p_log_level_rec);
3828 end if;
3829
3830 else
3831 if (p_log_level_rec.statement_level) then
3832 fa_debug_pkg.add(l_calling_fn, 'Group Transaction', p_trans_rec.transaction_key
3833 ,p_log_level_rec => p_log_level_rec);
3834 end if;
3835 end if; -- (l_mem_trx)
3836
3837 -- NOTE:
3838 -- if reclass NOT from DPIS
3839 -- then create one record to find cost, sal, etc... as of the date.
3840 -- for rest of period, apply delta directly.
3841 -- This means that if reclass from dpis, apply delta directly.
3842 -- if it is from current, use member's latest info.
3843 -- if it is from between dpis and current, then build first row
3844 -- and apply it and then apply rest of records.
3845
3846 -- HHIRAGA
3847 -- In case this is DESTINATION, group_asset_id in FA_BOOKS_SUMMARY must be updated before starting to
3848 -- processing
3849
3850 if (p_reclass_src_dest = 'DESTINATION') and
3851 nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'ALLOCATE' then
3852
3853 begin
3854
3855 l_mem_period_counter := l_trx_period_rec.period_counter - 1;
3856
3857 if (p_log_level_rec.statement_level) then
3858 fa_debug_pkg.add(l_calling_fn, 'Insert new row for proceessing','Start'
3859 ,p_log_level_rec => p_log_level_rec);
3860 fa_debug_pkg.add(l_calling_fn, 'Insert row',
3861 l_asset_hdr_rec.book_type_code||':'||p_reclassed_asset_id||':'||p_asset_hdr_rec.asset_id
3862 ,p_log_level_rec => p_log_level_rec);
3863 fa_debug_pkg.add(l_calling_fn, 'Insert row',
3864 l_mem_period_counter||':'||g_mem_ytd_deprn||':'||g_mem_deprn_reserve
3865 ,p_log_level_rec => p_log_level_rec);
3866 fa_debug_pkg.add(l_calling_fn, 'Insert row',
3867 g_mem_bonus_ytd_deprn||':'||g_mem_bonus_deprn_reserve||':'||g_mem_eofy_reserve
3868 ,p_log_level_rec => p_log_level_rec);
3869 end if;
3870
3871 -- Query YTD and Reserve from FA_DEPRN_SUMMARY for addition
3872 if p_mrc_sob_type_Code <> 'R' then
3873
3874 update fa_books_summary
3875 set group_Asset_id = p_asset_hdr_rec.asset_id
3876 where asset_id=p_reclassed_asset_id
3877 and period_counter >= l_trx_period_rec.period_counter;
3878
3879 open c_get_ytd_deprn;
3880 fetch c_get_ytd_deprn into l_mem_ytd_deprn_addition,l_mem_deprn_reserve_addition;
3881 close c_get_ytd_deprn;
3882
3883 if nvl(g_mem_ytd_deprn,0) = 0 and l_mem_ytd_deprn_addition is not null then
3884 g_mem_ytd_deprn := nvl(l_mem_ytd_deprn_addition,0);
3885 end if;
3886
3887 if nvl(g_mem_deprn_reserve,0) = 0 and l_mem_deprn_reserve_addition is not null then
3888 g_mem_deprn_reserve := nvl(l_mem_deprn_reserve_addition,0);
3889 g_mem_eofy_reserve := g_mem_deprn_reserve - g_mem_ytd_deprn;
3890 end if;
3891
3892 insert into fa_books_summary(book_type_code,
3893 asset_id,
3894 group_asset_id,
3895 period_counter,
3896 cost,
3897 salvage_value,
3898 recoverable_cost,
3899 adjusted_cost,
3900 adjusted_recoverable_cost,
3901 deprn_amount,
3902 ytd_deprn,
3903 deprn_reserve,
3904 bonus_ytd_deprn,
3905 bonus_deprn_reserve,
3906 eofy_reserve,
3907 creation_date,
3908 created_by,
3909 last_update_date,
3910 last_updated_by)
3911 values (l_asset_hdr_rec.book_type_code,
3912 p_reclassed_asset_id,
3913 p_asset_hdr_rec.asset_id,
3914 l_mem_period_counter,
3915 0,0,0,0,0,0,
3916 nvl(g_mem_ytd_deprn,0),
3917 nvl(g_mem_deprn_reserve,0),
3918 nvl(g_mem_bonus_ytd_deprn,0),
3919 nvl(g_mem_bonus_deprn_reserve,0),
3920 nvl(g_mem_eofy_reserve,0),
3921 p_trans_rec.who_info.creation_date,
3922 p_trans_rec.who_info.created_by,
3923 p_trans_rec.who_info.last_update_date,
3924 p_trans_rec.who_info.last_updated_by);
3925 else -- Reporting
3926
3927 update fa_books_summary_mrc_v
3928 set group_Asset_id = p_asset_hdr_rec.asset_id
3929 where asset_id=p_reclassed_asset_id
3933 fetch c_get_ytd_deprn_mrc into l_mem_ytd_deprn_addition,l_mem_deprn_reserve_addition;
3930 and period_counter >= l_trx_period_rec.period_counter;
3931
3932 open c_get_ytd_deprn_mrc;
3934 close c_get_ytd_deprn_mrc;
3935
3936 if nvl(g_mem_ytd_deprn,0) = 0 and l_mem_ytd_deprn_addition is not null then
3937 g_mem_ytd_deprn := nvl(l_mem_ytd_deprn_addition,0);
3938 end if;
3939
3940 if nvl(g_mem_deprn_reserve,0) = 0 and l_mem_deprn_reserve_addition is not null then
3941 g_mem_deprn_reserve := nvl(l_mem_deprn_reserve_addition,0);
3942 g_mem_eofy_reserve := g_mem_deprn_reserve - g_mem_ytd_deprn;
3943 end if;
3944
3945 insert into fa_books_summary_mrc_v(book_type_code,
3946 asset_id,
3947 group_asset_id,
3948 period_counter,
3949 cost,
3950 salvage_value,
3951 recoverable_cost,
3952 adjusted_cost,
3953 adjusted_recoverable_cost,
3954 deprn_amount,
3955 ytd_deprn,
3956 deprn_reserve,
3957 bonus_ytd_deprn,
3958 bonus_deprn_reserve,
3959 eofy_reserve,
3960 creation_date,
3961 created_by,
3962 last_update_date,
3963 last_updated_by)
3964 values (l_asset_hdr_rec.book_type_code,
3965 p_reclassed_asset_id,
3966 p_asset_hdr_rec.asset_id,
3967 l_mem_period_counter,
3968 0,0,0,0,0,0,
3969 nvl(g_mem_ytd_deprn,0),
3970 nvl(g_mem_deprn_reserve,0),
3971 nvl(g_mem_bonus_ytd_deprn,0),
3972 nvl(g_mem_bonus_deprn_reserve,0),
3973 nvl(g_mem_eofy_reserve,0),
3974 p_trans_rec.who_info.creation_date,
3975 p_trans_rec.who_info.created_by,
3976 p_trans_rec.who_info.last_update_date,
3977 p_trans_rec.who_info.last_updated_by);
3978
3979 end if;
3980
3981 if (p_log_level_rec.statement_level) then
3982 fa_debug_pkg.add(l_calling_fn, 'Inserted rows','Without Error'
3983 ,p_log_level_rec => p_log_level_rec);
3984 end if;
3985
3986 exception
3987 when others then
3988 if (p_log_level_rec.statement_level) then
3989 fa_debug_pkg.add(l_calling_fn, 'Insert new row for proceessing','Error'
3990 ,p_log_level_rec => p_log_level_rec);
3991 end if;
3992 null;
3993 end;
3994 end if;
3995
3996 if (p_reclass_src_dest = 'SOURCE') then
3997
3998 --+ HHIRAGA added on Oct/Nov in 2003
3999 --
4000 -- If this processing is for Group Asset whose tracking method is
4001 -- setup and user specified reclassification date (amort date) is
4002 -- in the current open period, system don't need to recalculate from
4003 -- DPIS of the member asset to reclassify but jut get stored reserve,
4004 -- YTD Depreciation and EOFY Reserve from table using populate_member_reserve function
4005 -- defined in FA_TRACK_MEMBER_PVT.
4006 --
4007 -- Initialize global variables
4008 g_mem_ytd_deprn := 0;
4009 g_mem_deprn_reserve := 0;
4010 g_mem_bonus_ytd_deprn := 0;
4011 g_mem_bonus_deprn_reserve := 0;
4012 g_mem_eofy_reserve := 0;
4013
4014 -- Query current open period counter
4015 if p_mrc_sob_type_code <> 'R' then
4016 open c_get_current_period;
4017 fetch c_get_current_period into l_current_period_counter;
4018 close c_get_current_period;
4019
4020 if nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'ALLOCATE' then
4021 if (p_log_level_rec.statement_level) then
4022 fa_debug_pkg.add(l_calling_fn, 'l_trx_period_rec.period_counter', l_trx_period_rec.period_counter
4023 ,p_log_level_rec => p_log_level_rec);
4024 fa_debug_pkg.add(l_calling_fn, 'p_Asset_hdr_rec.book_type_code', p_Asset_hdr_rec.book_type_code
4025 ,p_log_level_rec => p_log_level_rec);
4026 fa_debug_pkg.add(l_calling_fn, 'p_reclassed_asset_id', p_reclassed_asset_id
4027 ,p_log_level_rec => p_log_level_rec);
4028 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id
4029 ,p_log_level_rec => p_log_level_rec);
4030 end if;
4031 open c_get_mem_bs_row;
4032 fetch c_get_mem_bs_row into g_mem_ytd_deprn,g_mem_deprn_reserve,
4033 g_mem_bonus_ytd_deprn,g_mem_bonus_deprn_reserve,g_mem_eofy_reserve;
4034 close c_get_mem_bs_row;
4035 end if;
4036 else
4037 open c_get_current_period_mrc;
4041 if nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'ALLOCATE' then
4038 fetch c_get_current_period_mrc into l_current_period_counter;
4039 close c_get_current_period_mrc;
4040
4042 if (p_log_level_rec.statement_level) then
4043 fa_debug_pkg.add(l_calling_fn, 'l_trx_period_rec.period_counter', l_trx_period_rec.period_counter
4044 ,p_log_level_rec => p_log_level_rec);
4045 fa_debug_pkg.add(l_calling_fn, 'p_Asset_hdr_rec.book_type_code', p_Asset_hdr_rec.book_type_code
4046 ,p_log_level_rec => p_log_level_rec);
4047 fa_debug_pkg.add(l_calling_fn, 'p_reclassed_asset_id', p_reclassed_asset_id
4048 ,p_log_level_rec => p_log_level_rec);
4049 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id
4050 ,p_log_level_rec => p_log_level_rec);
4051 end if;
4052 open c_get_mem_bs_row_mrc;
4053 fetch c_get_mem_bs_row_mrc into g_mem_ytd_deprn,g_mem_deprn_reserve,
4054 g_mem_bonus_ytd_deprn,g_mem_bonus_deprn_reserve,g_mem_eofy_reserve;
4055 close c_get_mem_bs_row_mrc;
4056 end if;
4057 end if;
4058
4059 if nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'CALCULATE' and
4060 l_trx_period_rec.period_counter = l_current_period_counter then
4061
4062 -- Call populate_member_reserve
4063 if not FA_TRACK_MEMBER_PVT.populate_member_reserve
4064 (p_trans_rec => p_trans_rec,
4065 p_asset_hdr_rec => p_asset_hdr_rec,
4066 p_asset_fin_rec_new => px_asset_fin_rec_new,
4067 p_mrc_sob_type_code => p_mrc_sob_type_code,
4068 x_deprn_reserve => l_mem_deprn_reserve,
4069 x_eofy_reserve => l_mem_eofy_reserve
4070 ,p_log_level_rec => p_log_level_rec) then
4071 if (p_log_level_rec.statement_level) then
4072 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'populate_member_reserve'
4073 ,p_log_level_rec => p_log_level_rec);
4074 end if;
4075
4076 raise calc_failed;
4077 end if;
4078
4079 if (p_log_level_rec.statement_level) then
4080 fa_debug_pkg.add(l_calling_fn, '++ This is after POPULATE_MEMBER_RESERVE ++', '+++++'
4081 ,p_log_level_rec => p_log_level_rec);
4082 fa_debug_pkg.add(l_calling_fn, 'x_deprn_reserve', l_mem_deprn_reserve
4083 ,p_log_level_rec => p_log_level_rec);
4084 fa_debug_pkg.add(l_calling_fn, 'x_eofy_reserve', l_mem_eofy_reserve
4085 ,p_log_level_rec => p_log_level_rec);
4086 end if;
4087
4088 --
4089 -- Get period information of the period from member dpis
4090 --
4091 if not GetPeriodInfo(to_number(to_char(l_transaction_date_entered, 'J')),
4092 p_asset_hdr_rec.book_type_code,
4093 p_mrc_sob_type_code,
4094 l_period_rec) then
4095
4096 if (p_log_level_rec.statement_level) then
4097 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'GetPeriodInfo'
4098 ,p_log_level_rec => p_log_level_rec);
4099 end if;
4100
4101 raise calc_failed;
4102
4103 end if;
4104
4105 elsif nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'ALLOCATE' and
4106 g_mem_deprn_reserve is not null then
4107
4108 l_mem_deprn_reserve := g_mem_deprn_reserve;
4109 l_mem_eofy_reserve := nvl(g_mem_eofy_reserve,0);
4110
4111 l_mem_loop_first := TRUE;
4112
4113 If (p_log_level_rec.statement_level) then
4114 fa_debug_pkg.add(l_calling_fn, '++ This is a case for ALLOCATE and reclass in source group ++', '+++++'
4115 ,p_log_level_rec => p_log_level_rec);
4116 fa_debug_pkg.add(l_calling_fn, 'x_deprn_reserve', g_mem_deprn_reserve
4117 ,p_log_level_rec => p_log_level_rec);
4118 fa_debug_pkg.add(l_calling_fn, 'x_eofy_reserve', g_mem_eofy_reserve
4119 ,p_log_level_rec => p_log_level_rec);
4120 end if;
4121
4122 else -- Tracking is not used or period is not current period
4123
4124 -- If this reclass is for source, group's books summary needs
4125 -- to be adjusted previously added period.
4126 -- If this is first time reclass out, it needs to be adjusted
4127 -- from dpis of the member asset. If not, period which this member
4128 -- became member needs to be addjusted until now.
4129 -- In here, the date needs to be determined.
4130 -- If this is for dest, trx date is the date that this member
4131 -- becomes the dest group's member.
4132 --
4133 -- Get period information of the period from member dpis
4134 --
4135 if not GetPeriodInfo(to_number(to_char(p_reclassed_asset_dpis, 'J')),
4136 p_asset_hdr_rec.book_type_code,
4137 p_mrc_sob_type_code,
4138 l_period_rec) then
4139
4140 if (p_log_level_rec.statement_level) then
4141 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'GetPeriodInfo'
4142 ,p_log_level_rec => p_log_level_rec);
4143 end if;
4144
4148
4145 raise calc_failed;
4146
4147 end if;
4149 if (p_log_level_rec.statement_level) then
4150 fa_debug_pkg.add(l_calling_fn, 'l_transaction_date_entered', l_transaction_date_entered
4151 , p_log_level_rec => p_log_level_rec);
4152 fa_debug_pkg.add(l_calling_fn, 'p_group_reclass_type', p_group_reclass_type
4153 , p_log_level_rec => p_log_level_rec);
4154 end if;
4155
4156 -- Bug 6792185
4157 if (nvl(p_group_reclass_type, 'NULL') = 'MANUAL') then
4158 null;
4159 else
4160 l_transaction_date_entered := p_reclassed_asset_dpis;
4161 end if;
4162
4163 end if; -- HHIRAGA if-statement
4164
4165 end if;
4166
4167 /*****************
4168 This part of code will be removed by adding new column change_in_eofy_reserve
4169 *****************
4170 --
4171 -- Setting period counter which is used to determine from which period
4172 -- is fa_books_summary records needed to be updated.
4173 -- If there is eofy_reserve in fin_rec_adj, need to get record from
4174 -- previous eofy record to reflect the amount and recalculate.
4175 --
4176 --tk_util.debug('p_asset_fin_rec_adj.eofy_reserve: '||to_char(p_asset_fin_rec_adj.eofy_reserve));
4177
4178 if (nvl(p_asset_fin_rec_adj.eofy_reserve, 0) <> 0) then
4179 --
4180 -- In case of trx w/ some eofy_reserve
4181 -- Update reserve_adjustment_amount by adj.eofy_reserve and reserve of the last eofy record,
4182 -- Update current fiscal years records' eofy_reserve
4183 -- Update current period's reserve_adjustment_amount with adj.reserve - adj.eofy_reserve
4184 -- This is why it needs to get extra periods(records before amortization start date) records
4185
4186 l_period_counter := (l_period_rec.period_counter - l_period_rec.period_num);
4187 else
4188 l_period_counter := l_period_rec.period_counter - 1;
4189 end if; -- (p_asset_fin_rec_adj.eofy_reserve is not null)
4190 */
4191
4192 l_period_counter := l_period_rec.period_counter - 1;
4193
4194 if (p_log_level_rec.statement_level) then
4195 fa_debug_pkg.add(l_calling_fn, 'Starting Period',
4196 l_period_counter
4197 ,p_log_level_rec => p_log_level_rec);
4198 end if;
4199
4200 if (p_mrc_sob_type_code = 'R') then
4201
4202 OPEN c_get_mc_books_summary (l_period_counter);
4203 FETCH c_get_mc_books_summary BULK COLLECT INTO
4204 fa_amort_pvt.t_period_counter
4205 , fa_amort_pvt.t_fiscal_year
4206 , fa_amort_pvt.t_period_num
4207 , fa_amort_pvt.t_calendar_period_open_date
4208 , fa_amort_pvt.t_calendar_period_close_date
4209 , fa_amort_pvt.t_reset_adjusted_cost_flag
4210 , fa_amort_pvt.t_change_in_cost
4211 , fa_amort_pvt.t_change_in_cip_cost
4212 , fa_amort_pvt.t_cost
4213 , fa_amort_pvt.t_cip_cost
4214 , fa_amort_pvt.t_salvage_type
4215 , fa_amort_pvt.t_percent_salvage_value
4216 , fa_amort_pvt.t_salvage_value
4217 , fa_amort_pvt.t_member_salvage_value
4218 , fa_amort_pvt.t_recoverable_cost
4219 , fa_amort_pvt.t_deprn_limit_type
4220 , fa_amort_pvt.t_allowed_deprn_limit
4221 , fa_amort_pvt.t_allowed_deprn_limit_amount
4222 , fa_amort_pvt.t_member_deprn_limit_amount
4223 , fa_amort_pvt.t_adjusted_recoverable_cost
4224 , fa_amort_pvt.t_adjusted_cost
4225 , fa_amort_pvt.t_depreciate_flag
4226 , fa_amort_pvt.t_date_placed_in_service
4227 , fa_amort_pvt.t_deprn_method_code
4228 , fa_amort_pvt.t_life_in_months
4229 , fa_amort_pvt.t_rate_adjustment_factor
4230 , fa_amort_pvt.t_adjusted_rate
4231 , fa_amort_pvt.t_bonus_rule
4232 , fa_amort_pvt.t_adjusted_capacity
4233 , fa_amort_pvt.t_production_capacity
4234 , fa_amort_pvt.t_unit_of_measure
4235 , fa_amort_pvt.t_remaining_life1
4236 , fa_amort_pvt.t_remaining_life2
4237 , fa_amort_pvt.t_formula_factor
4238 , fa_amort_pvt.t_unrevalued_cost
4239 , fa_amort_pvt.t_reval_amortization_basis
4240 , fa_amort_pvt.t_reval_ceiling
4241 , fa_amort_pvt.t_ceiling_name
4242 , fa_amort_pvt.t_eofy_adj_cost
4243 , fa_amort_pvt.t_eofy_formula_factor
4244 , fa_amort_pvt.t_eofy_reserve
4245 , fa_amort_pvt.t_eop_adj_cost
4246 , fa_amort_pvt.t_eop_formula_factor
4247 , fa_amort_pvt.t_short_fiscal_year_flag
4248 , fa_amort_pvt.t_group_asset_id
4249 , fa_amort_pvt.t_super_group_id
4250 , fa_amort_pvt.t_over_depreciate_option
4251 , fa_amort_pvt.t_deprn_amount
4252 , fa_amort_pvt.t_ytd_deprn
4253 , fa_amort_pvt.t_deprn_reserve
4254 , fa_amort_pvt.t_bonus_deprn_amount
4255 , fa_amort_pvt.t_bonus_ytd_deprn
4256 , fa_amort_pvt.t_bonus_deprn_reserve
4257 , fa_amort_pvt.t_bonus_rate
4258 , fa_amort_pvt.t_ltd_production
4259 , fa_amort_pvt.t_ytd_production
4260 , fa_amort_pvt.t_production
4261 , fa_amort_pvt.t_reval_amortization
4262 , fa_amort_pvt.t_reval_deprn_expense
4266 , fa_amort_pvt.t_system_deprn_amount
4263 , fa_amort_pvt.t_reval_reserve
4264 , fa_amort_pvt.t_ytd_reval_deprn_expense
4265 , fa_amort_pvt.t_deprn_override_flag
4267 , fa_amort_pvt.t_system_bonus_deprn_amount
4268 , fa_amort_pvt.t_ytd_proceeds_of_sale
4269 , fa_amort_pvt.t_ltd_proceeds_of_sale
4270 , fa_amort_pvt.t_ytd_cost_of_removal
4271 , fa_amort_pvt.t_ltd_cost_of_removal
4272 , fa_amort_pvt.t_deprn_adjustment_amount
4273 , fa_amort_pvt.t_expense_adjustment_amount
4274 , fa_amort_pvt.t_reserve_adjustment_amount
4275 , fa_amort_pvt.t_change_in_eofy_reserve
4276 ;
4277
4278 CLOSE c_get_mc_books_summary;
4279
4280 else
4281
4282 OPEN c_get_books_summary (l_period_counter);
4283 FETCH c_get_books_summary BULK COLLECT INTO
4284 fa_amort_pvt.t_period_counter
4285 , fa_amort_pvt.t_fiscal_year
4286 , fa_amort_pvt.t_period_num
4287 , fa_amort_pvt.t_calendar_period_open_date
4288 , fa_amort_pvt.t_calendar_period_close_date
4289 , fa_amort_pvt.t_reset_adjusted_cost_flag
4290 , fa_amort_pvt.t_change_in_cost
4291 , fa_amort_pvt.t_change_in_cip_cost
4292 , fa_amort_pvt.t_cost
4293 , fa_amort_pvt.t_cip_cost
4294 , fa_amort_pvt.t_salvage_type
4295 , fa_amort_pvt.t_percent_salvage_value
4296 , fa_amort_pvt.t_salvage_value
4297 , fa_amort_pvt.t_member_salvage_value
4298 , fa_amort_pvt.t_recoverable_cost
4299 , fa_amort_pvt.t_deprn_limit_type
4300 , fa_amort_pvt.t_allowed_deprn_limit
4301 , fa_amort_pvt.t_allowed_deprn_limit_amount
4302 , fa_amort_pvt.t_member_deprn_limit_amount
4303 , fa_amort_pvt.t_adjusted_recoverable_cost
4304 , fa_amort_pvt.t_adjusted_cost
4305 , fa_amort_pvt.t_depreciate_flag
4306 , fa_amort_pvt.t_date_placed_in_service
4307 , fa_amort_pvt.t_deprn_method_code
4308 , fa_amort_pvt.t_life_in_months
4309 , fa_amort_pvt.t_rate_adjustment_factor
4310 , fa_amort_pvt.t_adjusted_rate
4311 , fa_amort_pvt.t_bonus_rule
4312 , fa_amort_pvt.t_adjusted_capacity
4313 , fa_amort_pvt.t_production_capacity
4314 , fa_amort_pvt.t_unit_of_measure
4315 , fa_amort_pvt.t_remaining_life1
4316 , fa_amort_pvt.t_remaining_life2
4317 , fa_amort_pvt.t_formula_factor
4318 , fa_amort_pvt.t_unrevalued_cost
4319 , fa_amort_pvt.t_reval_amortization_basis
4320 , fa_amort_pvt.t_reval_ceiling
4321 , fa_amort_pvt.t_ceiling_name
4322 , fa_amort_pvt.t_eofy_adj_cost
4323 , fa_amort_pvt.t_eofy_formula_factor
4324 , fa_amort_pvt.t_eofy_reserve
4325 , fa_amort_pvt.t_eop_adj_cost
4326 , fa_amort_pvt.t_eop_formula_factor
4327 , fa_amort_pvt.t_short_fiscal_year_flag
4328 , fa_amort_pvt.t_group_asset_id
4329 , fa_amort_pvt.t_super_group_id
4330 , fa_amort_pvt.t_over_depreciate_option
4331 , fa_amort_pvt.t_deprn_amount
4332 , fa_amort_pvt.t_ytd_deprn
4333 , fa_amort_pvt.t_deprn_reserve
4334 , fa_amort_pvt.t_bonus_deprn_amount
4335 , fa_amort_pvt.t_bonus_ytd_deprn
4336 , fa_amort_pvt.t_bonus_deprn_reserve
4337 , fa_amort_pvt.t_bonus_rate
4338 , fa_amort_pvt.t_ltd_production
4339 , fa_amort_pvt.t_ytd_production
4340 , fa_amort_pvt.t_production
4341 , fa_amort_pvt.t_reval_amortization
4342 , fa_amort_pvt.t_reval_deprn_expense
4343 , fa_amort_pvt.t_reval_reserve
4344 , fa_amort_pvt.t_ytd_reval_deprn_expense
4345 , fa_amort_pvt.t_deprn_override_flag
4346 , fa_amort_pvt.t_system_deprn_amount
4347 , fa_amort_pvt.t_system_bonus_deprn_amount
4348 , fa_amort_pvt.t_ytd_proceeds_of_sale
4349 , fa_amort_pvt.t_ltd_proceeds_of_sale
4350 , fa_amort_pvt.t_ytd_cost_of_removal
4351 , fa_amort_pvt.t_ltd_cost_of_removal
4352 , fa_amort_pvt.t_deprn_adjustment_amount
4353 , fa_amort_pvt.t_expense_adjustment_amount
4354 , fa_amort_pvt.t_reserve_adjustment_amount
4355 , fa_amort_pvt.t_change_in_eofy_reserve
4356 ;
4357
4358 CLOSE c_get_books_summary;
4359
4360 end if;
4361
4362 --tk_util.debug('period# : cost: adjcost: exp: eofy: rsvaj: rsv: dlmt: arec');
4363 /*
4364 for i in fa_amort_pvt.t_cost.FIRST..fa_amort_pvt.t_cost.LAST loop
4365 --tk_util.debug(rpad(to_char(fa_amort_pvt.t_period_counter(i)), 8, ' ')||':'||
4366 lpad(to_char(fa_amort_pvt.t_cost(i)), 10, ' ')||':'||
4367 lpad(to_char(fa_amort_pvt.t_adjusted_cost(i)), 10, ' ')||':'||
4368 lpad(to_char(fa_amort_pvt.t_deprn_amount(i)), 10, ' ')||':'||
4369 lpad(to_char(fa_amort_pvt.t_eofy_reserve(i)), 10, ' ')||':'||
4370 lpad(to_char(fa_amort_pvt.t_reserve_adjustment_amount(i)), 10, ' ')||':'||
4371 lpad(to_char(fa_amort_pvt.t_deprn_reserve(i)), 10, ' ')||':'||
4375 end loop;
4372 lpad(nvl(to_char(fa_amort_pvt.t_allowed_deprn_limit_amount(i)), 'null'), 5, ' ')||':'||
4373 lpad(to_char(fa_amort_pvt.t_adjusted_recoverable_cost(i)), 10, ' ')
4374 );
4376 */
4377 l_count := fa_amort_pvt.t_period_counter.COUNT;
4378
4379 --tk_util.debug('really: '||to_char(p_asset_fin_rec_adj.eofy_reserve));
4380 if (p_log_level_rec.statement_level) then
4381 fa_debug_pkg.add(l_calling_fn, 'Number of period fetched', l_count
4382 ,p_log_level_rec => p_log_level_rec);
4383 end if;
4384
4385 if (l_count = 1) then
4386 --
4387 -- Get eofy information from fa_books_summary_table
4388 --
4389 if (p_mrc_sob_type_code = 'R') then
4390 OPEN c_get_mc_eofy_amts(fa_amort_pvt.t_period_counter(1) - fa_amort_pvt.t_period_num(1));
4391 FETCH c_get_mc_eofy_amts INTO l_eofy_rec_cost
4392 , l_eofy_sal_val
4393 , l_eofy_reserve;
4394 if c_get_mc_eofy_amts%NOTFOUND then
4395 CLOSE c_get_mc_eofy_amts;
4396 l_eofy_rec_cost := 0;
4397 l_eofy_sal_val := 0;
4398 l_eofy_reserve := 0;
4399 else
4400 CLOSE c_get_mc_eofy_amts;
4401 end if;
4402 else
4403 OPEN c_get_eofy_amts(fa_amort_pvt.t_period_counter(1) - fa_amort_pvt.t_period_num(1));
4404 FETCH c_get_eofy_amts INTO l_eofy_rec_cost
4405 , l_eofy_sal_val
4406 , l_eofy_reserve;
4407 if c_get_eofy_amts%NOTFOUND then
4408 CLOSE c_get_eofy_amts;
4409 l_eofy_rec_cost := 0;
4410 l_eofy_sal_val := 0;
4411 l_eofy_reserve := 0;
4412 else
4413 CLOSE c_get_eofy_amts;
4414 end if;
4415 end if;
4416
4417 else
4418 --
4419 -- Get eofy information from fa_books_summary_table
4420 --
4421 if (p_mrc_sob_type_code = 'R') then
4422 OPEN c_get_mc_eofy_amts(fa_amort_pvt.t_period_counter(2) - fa_amort_pvt.t_period_num(2));
4423 FETCH c_get_mc_eofy_amts INTO l_eofy_rec_cost
4424 , l_eofy_sal_val
4425 , l_eofy_reserve;
4426 if c_get_mc_eofy_amts%NOTFOUND then
4427 CLOSE c_get_mc_eofy_amts;
4428 l_eofy_rec_cost := 0;
4429 l_eofy_sal_val := 0;
4430 l_eofy_reserve := 0;
4431 else
4432 CLOSE c_get_mc_eofy_amts;
4433 end if;
4434 else
4435 OPEN c_get_eofy_amts(fa_amort_pvt.t_period_counter(2) - fa_amort_pvt.t_period_num(2));
4436 FETCH c_get_eofy_amts INTO l_eofy_rec_cost
4437 , l_eofy_sal_val
4438 , l_eofy_reserve;
4439 if c_get_eofy_amts%NOTFOUND then
4440 CLOSE c_get_eofy_amts;
4441 l_eofy_rec_cost := 0;
4442 l_eofy_sal_val := 0;
4443 l_eofy_reserve := 0;
4444 else
4445 CLOSE c_get_eofy_amts;
4446 end if;
4447 end if;
4448
4449 end if; -- (l_count = 1)
4450
4451 if (p_log_level_rec.statement_level) then
4452 fa_debug_pkg.add(l_calling_fn, 'l_eofy_reserve', l_eofy_reserve
4453 ,p_log_level_rec => p_log_level_rec);
4454 end if;
4455
4456 /*** REMOVED
4457 end if;
4458 ***/
4459
4460 --
4461 -- At this point, l_bs_ind holds indicator for previous period of the period
4462 -- where amortization start date falls in.
4463 --
4464 --tk_util.debug('l_transaction_date_entered: '||to_char(l_transaction_date_entered, 'DD-MON-YYYY'));
4465 --tk_util.debug('close date: '||to_char(fa_amort_pvt.t_calendar_period_close_date(l_bs_ind), 'DD-MON-YYYY'));
4466 --tk_util.debug('count: '||to_char(fa_amort_pvt.t_period_counter.COUNT));
4467
4468 if (fa_amort_pvt.t_period_counter.COUNT > 1) and
4469 (l_transaction_date_entered >
4470 fa_amort_pvt.t_calendar_period_close_date(l_bs_ind))then
4471 -- Bug 6792185
4472 if (nvl(p_group_reclass_type, 'NULL') = 'MANUAL') then
4473 for j in l_bs_ind ..fa_amort_pvt.t_period_counter.COUNT loop
4474 if (l_transaction_date_entered between fa_amort_pvt.t_calendar_period_open_date(j)
4475 and fa_amort_pvt.t_calendar_period_close_date(j)) then
4476 l_bs_ind := j;
4477 end if;
4478 end loop;
4479 else
4480 l_bs_ind := l_bs_ind + 1;
4481 end if;
4482 end if;
4483
4484 if (p_log_level_rec.statement_level) then
4485 fa_debug_pkg.add(l_calling_fn, 'l_bs_ind', l_bs_ind
4486 , p_log_level_rec => p_log_level_rec);
4487 fa_debug_pkg.add(l_calling_fn, 'Populating local fin_rec_old',
4488 fa_amort_pvt.t_cost(l_bs_ind));
4489 end if;
4490
4491 l_asset_fin_rec_old.cost := fa_amort_pvt.t_cost(l_bs_ind);
4492 l_asset_fin_rec_old.formula_factor := fa_amort_pvt.t_formula_factor(l_bs_ind);
4493
4494 l_asset_fin_rec_old.rate_adjustment_factor := fa_amort_pvt.t_rate_adjustment_factor(l_bs_ind);
4495 l_asset_fin_rec_old.adjusted_cost := fa_amort_pvt.t_adjusted_cost(l_bs_ind);
4496 l_asset_fin_rec_old.salvage_value := fa_amort_pvt.t_salvage_value(l_bs_ind);
4500 l_asset_fin_rec_old.deprn_method_code := fa_amort_pvt.t_deprn_method_code(l_bs_ind);
4497 l_asset_fin_rec_old.recoverable_cost := fa_amort_pvt.t_recoverable_cost(l_bs_ind);
4498
4499
4501 l_asset_fin_rec_old.life_in_months := fa_amort_pvt.t_life_in_months(l_bs_ind);
4502 l_asset_fin_rec_old.group_asset_id := fa_amort_pvt.t_group_asset_id(l_bs_ind);
4503 l_asset_fin_rec_old.depreciate_flag := fa_amort_pvt.t_depreciate_flag(l_bs_ind);
4504 l_asset_fin_rec_old.recognize_gain_loss := px_asset_fin_rec_new.recognize_gain_loss;
4505 l_asset_fin_rec_old.tracking_method := px_asset_fin_rec_new.tracking_method;
4506
4507 l_asset_fin_rec_old.allocate_to_fully_rsv_flag := px_asset_fin_rec_new.allocate_to_fully_rsv_flag;
4508 l_asset_fin_rec_old.allocate_to_fully_ret_flag := px_asset_fin_rec_new.allocate_to_fully_ret_flag;
4509 l_asset_fin_rec_old.excess_allocation_option := px_asset_fin_rec_new.excess_allocation_option;
4510 l_asset_fin_rec_old.depreciation_option := px_asset_fin_rec_new.depreciation_option;
4511 l_asset_fin_rec_old.member_rollup_flag := px_asset_fin_rec_new.member_rollup_flag;
4512
4513 l_asset_fin_rec_new.reduction_rate := px_asset_fin_rec_new.reduction_rate;
4514 l_asset_fin_rec_new.recognize_gain_loss := l_asset_fin_rec_old.recognize_gain_loss;
4515 l_asset_fin_rec_new.tracking_method := l_asset_fin_rec_old.tracking_method;
4516 l_asset_fin_rec_new.allocate_to_fully_rsv_flag := l_asset_fin_rec_old.allocate_to_fully_rsv_flag;
4517 l_asset_fin_rec_new.allocate_to_fully_ret_flag := l_asset_fin_rec_old.allocate_to_fully_ret_flag;
4518 l_asset_fin_rec_new.excess_allocation_option := l_asset_fin_rec_old.excess_allocation_option;
4519 l_asset_fin_rec_new.depreciation_option := l_asset_fin_rec_old.depreciation_option;
4520 l_asset_fin_rec_new.member_rollup_flag := l_asset_fin_rec_old.member_rollup_flag;
4521 --Bug3286560: This will be old adj cost in deprn basis function
4522 l_asset_fin_rec_new.adjusted_cost := fa_amort_pvt.t_adjusted_cost(l_bs_ind);
4523 -- Bug 4700524: first time in loop fin_rec_old.cost needs to be old cost
4524 l_asset_fin_rec_new.cost := fa_amort_pvt.t_cost(l_bs_ind);
4525
4526
4527 --
4528 -- Setting reset_adjusted_cost_flag
4529 -- If this is source group, it is not always first period of recalculation because
4530 -- pl/sql table always has data from member's dpis
4531 -- Also find value for l_temp_ind and it will be used to update table at the end.
4532 --
4533 if (p_reclass_src_dest = 'SOURCE') then
4534
4535 l_temp_ind := l_bs_ind + l_trx_period_rec.period_counter - fa_amort_pvt.t_period_counter(l_bs_ind);
4536 fa_amort_pvt.t_reset_adjusted_cost_flag(l_temp_ind) := 'Y';
4537
4538 --tk_util.debug('l_temp_ind: '||to_char(l_temp_ind));
4539 --tk_util.debug('period counter: '||to_char(fa_amort_pvt.t_period_counter(l_temp_ind)));
4540
4541 --
4542 -- Store old reserve so that it can be used to determine how much reserve needs to be
4543 -- taken out from srouce group at reclassed period.
4544 --
4545 if (l_temp_ind = 1) then
4546 l_old_reserve := 0;
4547 else
4548 --Bug# 7215625 Commented following code to calculate right value for l_old_reserve
4549 l_old_reserve := fa_amort_pvt.t_deprn_reserve(l_temp_ind - 1);
4550 -- Bug# 7215626 end.
4551 end if;
4552
4553 else
4554 l_temp_ind := l_bs_ind;
4555
4556 if (p_reclass_src_dest is not null) then
4557 fa_amort_pvt.t_reset_adjusted_cost_flag(l_bs_ind) := 'Y';
4558 end if;
4559
4560 -- else
4561 -- fa_amort_pvt.t_reset_adjusted_cost_flag(l_bs_ind) := 'Y';
4562 -- l_temp_ind := l_bs_ind;
4563 end if;
4564
4565 /* if (fa_cache_pkg.fazcdbr_record.rule_name = 'uNERGY PERIOD END BALANCE') and
4566 (p_asset_fin_rec_old.tracking_method = 'ALLOCATE') then
4567 l_energy_member := TRUE;
4568 end if;
4569 */
4570 if (p_trans_rec.transaction_key = 'MS') then
4571 if (p_mrc_sob_type_code = 'R') then
4572 OPEN c_get_mc_rein_info;
4573 FETCH c_get_mc_rein_info INTO l_proceeds_of_sale
4574 , l_cost_of_removal
4575 , l_reserve_retired
4576 , l_nbv_retired;
4577 CLOSE c_get_mc_rein_info;
4578 else
4579 OPEN c_get_rein_info;
4580 FETCH c_get_rein_info INTO l_proceeds_of_sale
4581 , l_cost_of_removal
4582 , l_reserve_retired
4583 , l_nbv_retired;
4584 CLOSE c_get_rein_info;
4585 end if;
4586
4587 if (l_reserve_retired is null) and
4588 (px_asset_fin_rec_new.recognize_gain_loss = 'NO') then
4589 l_reserve_retired := px_asset_fin_rec_new.cost - p_asset_fin_rec_old.cost;
4590 end if;
4591
4592 if (fa_cache_pkg.fazcdbr_record.rule_name = 'ENERGY PERIOD END BALANCE') and
4593 (p_asset_fin_rec_old.tracking_method = 'ALLOCATE') then
4594 -- l_proceeds_of_sale and l_cost_of_removal has -1 multiplied in cursor c_get_rein_info
4595 -- so that it can be added whether the trx is ret or rein later when maintaining
4596 -- ytd and ltd for books summary table.
4597 l_reserve_retired := p_asset_fin_rec_adj.cost + l_proceeds_of_sale - l_cost_of_removal;
4598 end if;
4599
4600 if (p_log_level_rec.statement_level) then
4601 fa_debug_pkg.add(l_calling_fn, 'This is Reinstatement', l_reserve_retired
4605 else
4602 ,p_log_level_rec => p_log_level_rec);
4603 end if;
4604
4606 l_reserve_retired := 0;
4607 end if;
4608
4609
4610 --
4611 -- Need to find out how unplanned expense is passed to here
4612 --
4613 fa_amort_pvt.t_expense_adjustment_amount(l_bs_ind) :=
4614 fa_amort_pvt.t_expense_adjustment_amount(l_bs_ind) +
4615 nvl(p_asset_deprn_rec_adj.deprn_amount, 0);
4616
4617 fa_amort_pvt.t_reserve_adjustment_amount(l_bs_ind) :=
4618 fa_amort_pvt.t_reserve_adjustment_amount(l_bs_ind) +
4619 nvl(p_asset_deprn_rec_adj.deprn_reserve, 0) + l_reserve_retired;
4620 -- nvl(p_asset_deprn_rec_adj.deprn_reserve, 0);
4621 -- (nvl(p_asset_deprn_rec_adj.deprn_reserve, 0) -
4622 -- nvl(p_asset_fin_rec_adj.eofy_reserve, 0)) +
4623
4624
4625
4626 fa_amort_pvt.t_change_in_eofy_reserve(l_bs_ind) :=
4627 nvl(fa_amort_pvt.t_change_in_eofy_reserve(l_bs_ind), 0) +
4628 nvl(p_asset_fin_rec_adj.eofy_reserve, 0);
4629
4630
4631 if (p_reclass_src_dest = 'SOURCE') then
4632 if (l_trx_period_rec.period_counter > fa_amort_pvt.t_period_counter(1)) and
4633 (l_trx_period_rec.period_counter >= fa_amort_pvt.t_period_counter(l_bs_ind)) and
4634 (fa_amort_pvt.t_period_counter.COUNT > 2) then
4635
4636 --tk_util.debug('last period counter: '||to_char(fa_amort_pvt.t_period_counter(fa_amort_pvt.t_period_counter.LAST)));
4637 --tk_util.debug('l_trx_period_rec.period_counter: '||to_char(l_trx_period_rec.period_counter));
4638
4639 l_gr_ind := fa_amort_pvt.t_period_counter.COUNT -
4640 (fa_amort_pvt.t_period_counter(fa_amort_pvt.t_period_counter.LAST) -
4641 (l_trx_period_rec.period_counter - 1));
4642
4643 --tk_util.debug('l_gr_ind: '||to_char(l_gr_ind));
4644 --tk_util.debug('ytd: '||to_char(fa_amort_pvt.t_ytd_deprn(l_gr_ind)));
4645
4646 l_gr_asset_deprn_rec.deprn_amount := fa_amort_pvt.t_deprn_amount(l_gr_ind);
4647 l_gr_asset_deprn_rec.ytd_deprn := fa_amort_pvt.t_ytd_deprn(l_gr_ind);
4648 l_gr_asset_deprn_rec.deprn_reserve := fa_amort_pvt.t_deprn_reserve(l_gr_ind);
4649 l_gr_asset_deprn_rec.bonus_deprn_amount := fa_amort_pvt.t_bonus_deprn_amount(l_gr_ind);
4650 l_gr_asset_deprn_rec.bonus_ytd_deprn := fa_amort_pvt.t_bonus_ytd_deprn(l_gr_ind);
4651 l_gr_asset_deprn_rec.bonus_deprn_reserve := fa_amort_pvt.t_bonus_deprn_reserve(l_gr_ind);
4652 l_gr_asset_deprn_rec.ltd_production := fa_amort_pvt.t_ltd_production(l_gr_ind);
4653 l_gr_asset_deprn_rec.ytd_production := fa_amort_pvt.t_ytd_production(l_gr_ind);
4654 l_gr_asset_deprn_rec.production := fa_amort_pvt.t_production(l_gr_ind);
4655 l_gr_asset_deprn_rec.reval_amortization := fa_amort_pvt.t_reval_amortization(l_gr_ind);
4656 l_gr_asset_deprn_rec.reval_deprn_expense := fa_amort_pvt.t_reval_deprn_expense(l_gr_ind);
4657 l_gr_asset_deprn_rec.reval_deprn_reserve := fa_amort_pvt.t_reval_reserve(l_gr_ind);
4658 l_gr_asset_deprn_rec.reval_ytd_deprn := fa_amort_pvt.t_ytd_reval_deprn_expense(l_gr_ind);
4659 else
4660 l_gr_asset_deprn_rec.deprn_amount := 0;
4661 l_gr_asset_deprn_rec.ytd_deprn := 0;
4662 l_gr_asset_deprn_rec.deprn_reserve := 0;
4663 l_gr_asset_deprn_rec.bonus_deprn_amount := 0;
4664 l_gr_asset_deprn_rec.bonus_ytd_deprn := 0;
4665 l_gr_asset_deprn_rec.bonus_deprn_reserve := 0;
4666 l_gr_asset_deprn_rec.ltd_production := 0;
4667 l_gr_asset_deprn_rec.ytd_production := 0;
4668 l_gr_asset_deprn_rec.production := 0;
4669 l_gr_asset_deprn_rec.reval_amortization := 0;
4670 l_gr_asset_deprn_rec.reval_deprn_expense := 0;
4671 l_gr_asset_deprn_rec.reval_deprn_reserve := 0;
4672 l_gr_asset_deprn_rec.reval_ytd_deprn := 0;
4673 end if;
4674 end if;
4675
4676
4677 d := 0;
4678
4679 --tk_util.debug('period# : cost: adjcost: exp: eofy: rsvaj: rsv: dlmt: arec');
4680 /*
4681 for i in fa_amort_pvt.t_cost.FIRST..fa_amort_pvt.t_cost.LAST loop
4682 --tk_util.debug(rpad(to_char(fa_amort_pvt.t_period_counter(i)), 8, ' ')||':'||
4683 lpad(to_char(fa_amort_pvt.t_cost(i)), 10, ' ')||':'||
4684 lpad(to_char(fa_amort_pvt.t_adjusted_cost(i)), 10, ' ')||':'||
4685 lpad(to_char(fa_amort_pvt.t_deprn_amount(i)), 10, ' ')||':'||
4686 lpad(to_char(fa_amort_pvt.t_eofy_reserve(i)), 10, ' ')||':'||
4687 lpad(to_char(fa_amort_pvt.t_reserve_adjustment_amount(i)), 10, ' ')||':'||
4688 lpad(to_char(fa_amort_pvt.t_deprn_reserve(i)), 10, ' ')||':'||
4689 lpad(nvl(to_char(fa_amort_pvt.t_allowed_deprn_limit_amount(i)), 'null'), 5, ' ')||':'||
4690 lpad(to_char(fa_amort_pvt.t_adjusted_recoverable_cost(i)), 10, ' ')
4691 );
4692 end loop;
4693 */
4694 --
4695 -- Update FA_BOOKS_SUMMARY
4696 --
4697
4698 -- *********************** --
4699 -- Main Loop Starts Here --
4700 -- *********************** --
4701 FOR i IN l_bs_ind..l_count LOOP
4702 d := d + 1;
4703
4704 if (p_log_level_rec.statement_level) then
4705 fa_debug_pkg.add(l_calling_fn, 'Processing period',
4709 if i <> 1 then
4706 fa_amort_pvt.t_period_counter(i));
4707 end if;
4708
4710 l_asset_fin_rec_old := l_asset_fin_rec_new;
4711 end if;
4712
4713 --
4714 -- Populate l_period_rec for deprn basis
4715 --
4716 l_period_rec.period_counter := fa_amort_pvt.t_period_counter(i);
4717 l_period_rec.fiscal_year := fa_amort_pvt.t_fiscal_year(i);
4718 l_period_rec.period_num := fa_amort_pvt.t_period_num(i);
4719
4720 --tk_util.debug('fa_amort_pvt.t_cost: '||to_char(fa_amort_pvt.t_cost(i)));
4721
4722 if (l_mem_trx) then
4723
4724 --tk_util.debug('td_cost('||to_char(d)||'): '||to_char(td_cost(d)));
4725 --tk_util.debug('l_trx_period_rec.period_counter: '||to_char(l_trx_period_rec.period_counter));
4726
4727 if (p_reclass_src_dest = 'DESTINATION') and
4728 (l_trx_period_rec.period_counter = fa_amort_pvt.t_period_counter(i)) then
4729
4730 --tk_util.debug('GROUP RECLASS: '||to_char(fa_amort_pvt.t_period_counter(i)));
4731
4732 fa_amort_pvt.t_change_in_cost(i) := fa_amort_pvt.t_change_in_cost(i) + l_asset_fin_rec_reclass.cost;
4733 fa_amort_pvt.t_change_in_cip_cost(i) := fa_amort_pvt.t_change_in_cip_cost(i) +
4734 l_asset_fin_rec_reclass.cip_cost;
4735 else
4736
4737 --tk_util.debug('fa_amort_pvt.t_change_in_cost('||to_char(d)||'): '|| to_char(fa_amort_pvt.t_change_in_cost(i)));
4738 -- Bug#7215625 start - commented the code done for fix 5768759
4739 fa_amort_pvt.t_change_in_cost(i) := fa_amort_pvt.t_change_in_cost(i) +
4740 td_cost(d);
4741 fa_amort_pvt.t_change_in_cip_cost(i) := fa_amort_pvt.t_change_in_cip_cost(i) +
4742 td_cip_cost(d);
4743 -- Bug#7215625 end - commented the code done for fix 5768759
4744 end if;
4745
4746 --tk_util.debug('fa_amort_pvt.t_change_in_cost('||to_char(i)||'): '|| to_char(fa_amort_pvt.t_change_in_cost(i)));
4747 --tk_util.debug('td_salvage_value('||to_char(d)||'): '|| to_char(td_salvage_value(d)));
4748
4749 if (i = 1) then
4750 fa_amort_pvt.t_cost(i) := fa_amort_pvt.t_change_in_cost(i);
4751 fa_amort_pvt.t_cip_cost(i) := fa_amort_pvt.t_change_in_cip_cost(i);
4752
4753 if (p_reclass_src_dest is not null) and
4754 (l_trx_period_rec.period_counter = fa_amort_pvt.t_period_counter(i)) then
4755 fa_amort_pvt.t_member_salvage_value(i) := fa_amort_pvt.t_member_salvage_value(i) +
4756 l_asset_fin_rec_reclass.salvage_value;
4757 fa_amort_pvt.t_member_deprn_limit_amount(i) := fa_amort_pvt.t_member_deprn_limit_amount(i) +
4758 l_asset_fin_rec_reclass.allowed_deprn_limit_amount;
4759 else
4760 fa_amort_pvt.t_member_salvage_value(i) := fa_amort_pvt.t_member_salvage_value(i) +
4761 td_salvage_value(d);
4762 fa_amort_pvt.t_member_deprn_limit_amount(i) := fa_amort_pvt.t_member_deprn_limit_amount(i) +
4763 td_deprn_limit_amount(d);
4764 end if;
4765
4766 fa_amort_pvt.t_rate_adjustment_factor(i) := 1;
4767 else
4768 fa_amort_pvt.t_cost(i) := fa_amort_pvt.t_cost(i - 1) + fa_amort_pvt.t_change_in_cost(i);
4769 fa_amort_pvt.t_cip_cost(i) := fa_amort_pvt.t_cip_cost(i - 1) +
4770 fa_amort_pvt.t_change_in_cip_cost(i);
4771
4772
4773 if (p_reclass_src_dest is not null) and
4774 (l_trx_period_rec.period_counter = fa_amort_pvt.t_period_counter(i)) then
4775 fa_amort_pvt.t_member_salvage_value(i) := fa_amort_pvt.t_member_salvage_value(i) +
4776 l_asset_fin_rec_reclass.salvage_value;
4777 fa_amort_pvt.t_member_deprn_limit_amount(i) := fa_amort_pvt.t_member_deprn_limit_amount(i) +
4778 l_asset_fin_rec_reclass.allowed_deprn_limit_amount;
4779 else
4780 fa_amort_pvt.t_member_salvage_value(i) := fa_amort_pvt.t_member_salvage_value(i) +
4781 td_salvage_value(d);
4782 fa_amort_pvt.t_member_deprn_limit_amount(i) := fa_amort_pvt.t_member_deprn_limit_amount(i) +
4783 td_deprn_limit_amount(d);
4784 end if;
4785
4786 fa_amort_pvt.t_rate_adjustment_factor(i) := fa_amort_pvt.t_rate_adjustment_factor(i - 1);
4787 end if;
4788
4789 if (p_log_level_rec.statement_level) then
4790 fa_debug_pkg.add(l_calling_fn, 't_member_salvage_value('||to_char(i)||')' ,
4791 fa_amort_pvt.t_member_salvage_value(i), p_log_level_rec);
4792 fa_debug_pkg.add(l_calling_fn, 'td_salvage_value('||to_char(d)||')' ,
4793 td_salvage_value(d), p_log_level_rec);
4794 fa_debug_pkg.add(l_calling_fn, 't_member_deprn_limit_amount('||to_char(i)||')' ,
4795 fa_amort_pvt.t_member_deprn_limit_amount(i), p_log_level_rec);
4796 fa_debug_pkg.add(l_calling_fn, 'td_deprn_limit_amount('||to_char(d)||')' ,
4797 td_deprn_limit_amount(d), p_log_level_rec);
4798 end if;
4799
4800
4801
4802 if (p_reclass_src_dest = 'SOURCE') and
4806 (l_asset_fin_rec_reclass.cost - td_cost(d));
4803 (l_trx_period_rec.period_counter = fa_amort_pvt.t_period_counter(i)) then
4804
4805 fa_amort_pvt.t_change_in_cost(i) := fa_amort_pvt.t_change_in_cost(i) +
4807 fa_amort_pvt.t_change_in_cip_cost(i) := fa_amort_pvt.t_change_in_cip_cost(i) +
4808 (l_asset_fin_rec_reclass.cip_cost - td_cip_cost(d));
4809 --tk_util.debug('Synchronizing change_in_cost: '||to_char(fa_amort_pvt.t_change_in_cost(i)));
4810 end if;
4811 end if;
4812
4813 --tk_util.debug('fa_amort_pvt.t_member_salvage_value('||to_char(i)||'): '|| to_char(fa_amort_pvt.t_member_salvage_value(i)));
4814 --tk_util.debug('fa_amort_pvt.t_cost('||to_char(d)||'): '|| to_char(fa_amort_pvt.t_cost(i)));
4815
4816 --
4817 -- Apply delta to books sumamry global variables
4818 --
4819 fa_amort_pvt.t_salvage_type(i) := nvl(p_asset_fin_rec_adj.salvage_type,
4820 fa_amort_pvt.t_salvage_type(i));
4821 fa_amort_pvt.t_deprn_limit_type(i) := nvl(p_asset_fin_rec_adj.deprn_limit_type,
4822 fa_amort_pvt.t_deprn_limit_type(i));
4823
4824 if (px_asset_fin_rec_new.depreciate_flag <>
4825 p_asset_fin_rec_old.depreciate_flag) then
4826 fa_amort_pvt.t_depreciate_flag(i) := px_asset_fin_rec_new.depreciate_flag;
4827 end if;
4828
4829 if (nvl(p_asset_fin_rec_old.deprn_method_code,
4830 px_asset_fin_rec_new.deprn_method_code) <> px_asset_fin_rec_new.deprn_method_code) then
4831 fa_amort_pvt.t_deprn_method_code(i) := px_asset_fin_rec_new.deprn_method_code;
4832 fa_amort_pvt.t_life_in_months(i) := px_asset_fin_rec_new.life_in_months;
4833 fa_amort_pvt.t_adjusted_rate(i) := px_asset_fin_rec_new.adjusted_rate;
4834 --tk_util.debug('1 adjusted_rate: '||to_char(fa_amort_pvt.t_adjusted_rate(i)));
4835 else
4836 fa_amort_pvt.t_life_in_months(i) := nvl(p_asset_fin_rec_adj.life_in_months,
4837 fa_amort_pvt.t_life_in_months(i));
4838 fa_amort_pvt.t_adjusted_rate(i) := nvl(p_asset_fin_rec_adj.adjusted_rate,
4839 fa_amort_pvt.t_adjusted_rate(i));
4840 --tk_util.debug('adj adjusted_rate: '||to_char(p_asset_fin_rec_adj.adjusted_rate));
4841 --tk_util.debug('2 adjusted_rate: '||to_char(fa_amort_pvt.t_adjusted_rate(i)));
4842 end if;
4843
4844 fa_amort_pvt.t_bonus_rule(i) := nvl(p_asset_fin_rec_adj.bonus_rule,
4845 fa_amort_pvt.t_bonus_rule(i));
4846 -- fa_amort_pvt.t_adjusted_capacity(i) :=
4847 fa_amort_pvt.t_production_capacity(i) := nvl(fa_amort_pvt.t_production_capacity(i), 0) +
4848 nvl(p_asset_fin_rec_adj.production_capacity, 0);
4849 fa_amort_pvt.t_unit_of_measure(i) := nvl(p_asset_fin_rec_adj.unit_of_measure,
4850 fa_amort_pvt.t_unit_of_measure(i));
4851 --
4852 -- I don't know what to store in these columns
4853 --
4854 -- fa_amort_pvt.t_remaining_life1(i) :=
4855 -- fa_amort_pvt.t_remaining_life2(i) :=
4856
4857 fa_amort_pvt.t_ceiling_name(i) := nvl(p_asset_fin_rec_adj.ceiling_name,
4858 fa_amort_pvt.t_ceiling_name(i));
4859
4860 if (p_asset_fin_rec_old.group_asset_id = px_asset_fin_rec_new.group_asset_id) then
4861 null;
4862 else
4863 fa_amort_pvt.t_group_asset_id(i) := px_asset_fin_rec_new.group_asset_id;
4864 end if;
4865
4866 if (nvl(p_asset_fin_rec_old.super_group_id, 0) = nvl(px_asset_fin_rec_new.super_group_id, 0)) then
4867 null;
4868 else
4869 fa_amort_pvt.t_super_group_id(i) := px_asset_fin_rec_new.super_group_id;
4870 end if;
4871
4872 fa_amort_pvt.t_over_depreciate_option(i) := nvl(p_asset_fin_rec_adj.over_depreciate_option,
4873 fa_amort_pvt.t_over_depreciate_option(i));
4874
4875 if (nvl(p_asset_fin_rec_old.salvage_type,
4876 px_asset_fin_rec_new.salvage_type) = px_asset_fin_rec_new.salvage_type) then
4877 fa_amort_pvt.t_percent_salvage_value(i) := fa_amort_pvt.t_percent_salvage_value(i) +
4878 nvl(p_asset_fin_rec_adj.percent_salvage_value, 0);
4879 else
4880 fa_amort_pvt.t_percent_salvage_value(i) := nvl(px_asset_fin_rec_new.percent_salvage_value, 0);
4881 end if;
4882
4883 if (nvl(p_asset_fin_rec_old.deprn_limit_type,
4884 px_asset_fin_rec_new.deprn_limit_type) = px_asset_fin_rec_new.deprn_limit_type) then
4885 fa_amort_pvt.t_allowed_deprn_limit(i) := fa_amort_pvt.t_allowed_deprn_limit(i) +
4886 nvl(p_asset_fin_rec_adj.allowed_deprn_limit, 0);
4887 else
4888 fa_amort_pvt.t_allowed_deprn_limit(i) := nvl(px_asset_fin_rec_new.allowed_deprn_limit, 0);
4889 end if;
4890
4891 if (fa_amort_pvt.t_salvage_type(i) = 'PCT') then
4892 l_temp_num := fa_amort_pvt.t_cost(i) * fa_amort_pvt.t_percent_salvage_value(i);
4893 fa_round_pkg.fa_ceil(l_temp_num, p_asset_hdr_rec.book_type_code
4894 ,p_log_level_rec => p_log_level_rec);
4895 fa_amort_pvt.t_salvage_value(i) := l_temp_num;
4896 else -- case of SUM
4897 fa_amort_pvt.t_salvage_value(i) := fa_amort_pvt.t_member_salvage_value(i);
4898 end if;
4899
4903 ,p_log_level_rec => p_log_level_rec);
4900 if (fa_amort_pvt.t_deprn_limit_type(i) = 'PCT') then
4901 l_temp_num := fa_amort_pvt.t_cost(i) * (1 - fa_amort_pvt.t_allowed_deprn_limit(i));
4902 fa_round_pkg.fa_floor(l_temp_num, p_asset_hdr_rec.book_type_code
4904 fa_amort_pvt.t_allowed_deprn_limit_amount(i) := l_temp_num;
4905 elsif(fa_amort_pvt.t_deprn_limit_type(i) = 'SUM') then
4906 fa_amort_pvt.t_allowed_deprn_limit_amount(i) := fa_amort_pvt.t_member_deprn_limit_amount(i);
4907 else -- case of 'NONE'
4908 fa_amort_pvt.t_allowed_deprn_limit_amount(i) := null;
4909 end if;
4910
4911 if (p_log_level_rec.statement_level) then
4912 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_salvage_type('||to_char(i)||')',
4913 fa_amort_pvt.t_salvage_type(i));
4914 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_percent_salvage_value('||to_char(i)||')',
4915 fa_amort_pvt.t_percent_salvage_value(i));
4916 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_salvage_value('||to_char(i)||')',
4917 fa_amort_pvt.t_salvage_value(i));
4918 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_member_salvage_value('||to_char(i)||')',
4919 fa_amort_pvt.t_member_salvage_value(i));
4920 fa_debug_pkg.add(l_calling_fn,
4921 'fa_amort_pvt.t_deprn_limit_type('||to_char(i)||')',
4922 fa_amort_pvt.t_deprn_limit_type(i));
4923 fa_debug_pkg.add(l_calling_fn,
4924 'fa_amort_pvt.t_allowed_deprn_limit('||to_char(i)||')',
4925 fa_amort_pvt.t_allowed_deprn_limit(i));
4926 fa_debug_pkg.add(l_calling_fn,
4927 'fa_amort_pvt.t_allowed_deprn_limit_amount('||to_char(i)||')',
4928 fa_amort_pvt.t_allowed_deprn_limit_amount(i));
4929 fa_debug_pkg.add(l_calling_fn,
4930 'fa_amort_pvt.t_member_deprn_limit_amount('||to_char(i)||')',
4931 fa_amort_pvt.t_member_deprn_limit_amount(i));
4932 end if;
4933
4934
4935 --
4936 -- At this point, all attributes to determine whether resetting adjusted cost is necessary
4937 -- or not. Here is the list of the attributes
4938 -- change_in_cost, change_in_cip_cost, member_salvage_value, member_deprn_limit_amount,
4939 -- percent_salvage_value, allowed_deprn_limit, salvage_value, allowed_deprn_limit_amount
4940 -- deprn_method_code, adjusted_rate, bonus_rule
4941 -- If this is destination asset for reclass transaction, this place is too late to
4942 -- set reset_adjusted_cost_flag
4943 if (i = 1) or
4944 (fa_amort_pvt.t_change_in_cost(i) <> 0) or
4945 (fa_amort_pvt.t_change_in_cip_cost(i) <> 0) then
4946 fa_amort_pvt.t_reset_adjusted_cost_flag(i) := 'Y';
4947 elsif (nvl(fa_amort_pvt.t_percent_salvage_value(i), 0) <> nvl(fa_amort_pvt.t_percent_salvage_value(i-1),0)) or
4948 (nvl(fa_amort_pvt.t_allowed_deprn_limit(i), 0) <> nvl(fa_amort_pvt.t_allowed_deprn_limit(i-1), 0)) or
4949 (fa_amort_pvt.t_salvage_value(i) <> fa_amort_pvt.t_salvage_value(i-1)) or
4950 (nvl(fa_amort_pvt.t_allowed_deprn_limit_amount(i), 0) <>
4951 nvl(fa_amort_pvt.t_allowed_deprn_limit_amount(i-1), 0)) or
4952 (fa_amort_pvt.t_deprn_method_code(i) <> fa_amort_pvt.t_deprn_method_code(i-1)) or
4953 (nvl(fa_amort_pvt.t_adjusted_rate(i), 0) <> nvl(fa_amort_pvt.t_adjusted_rate(i-1), 0)) or
4954 (nvl(fa_amort_pvt.t_bonus_rule(i), 'NULL') <> nvl(fa_amort_pvt.t_bonus_rule(i-1), 'NULL') or
4955 (fa_amort_pvt.t_expense_adjustment_amount(i) <> 0) or
4956 (fa_amort_pvt.t_reserve_adjustment_amount(i) <> 0)) then
4957 fa_amort_pvt.t_reset_adjusted_cost_flag(i) := 'Y';
4958 if (p_log_level_rec.statement_level) then
4959 fa_debug_pkg.add('tk','1',fa_amort_pvt.t_member_salvage_value(i-1));
4960 fa_debug_pkg.add('tk','2', fa_amort_pvt.t_member_deprn_limit_amount(i-1));
4961 fa_debug_pkg.add('tk','3', fa_amort_pvt.t_percent_salvage_value(i-1));
4962 fa_debug_pkg.add('tk','4', fa_amort_pvt.t_allowed_deprn_limit(i-1));
4963 fa_debug_pkg.add('tk','5', fa_amort_pvt.t_salvage_value(i-1));
4964 fa_debug_pkg.add('tk','6', fa_amort_pvt.t_allowed_deprn_limit_amount(i-1));
4965 fa_debug_pkg.add('tk','7', fa_amort_pvt.t_deprn_method_code(i-1));
4966 fa_debug_pkg.add('tk','8', fa_amort_pvt.t_adjusted_rate(i-1));
4967 fa_debug_pkg.add('tk','9', fa_amort_pvt.t_bonus_rule(i-1));
4968 fa_debug_pkg.add('tk','0', fa_amort_pvt.t_expense_adjustment_amount(i-1));
4969 fa_debug_pkg.add('tk','1', fa_amort_pvt.t_reserve_adjustment_amount(i-1));
4970 end if;
4971 --bug3872075: Need group's change_in_cost etc instead of delta
4972 elsif ((p_reclass_src_dest is not null) and
4973 ((nvl(fa_amort_pvt.t_change_in_cost(i), 0) <> 0) or
4974 (nvl(fa_amort_pvt.t_change_in_cip_cost(i), 0) <> 0))) then
4975
4976 fa_amort_pvt.t_reset_adjusted_cost_flag(i) := 'Y';
4977 if (p_log_level_rec.statement_level) then
4978 fa_debug_pkg.add(l_calling_fn, 'Reclass trx and still change in', 'COST');
4979 end if;
4980 else
4981 fa_amort_pvt.t_reset_adjusted_cost_flag(i) := 'N';
4982
4983 if (i = 2) then
4984 if (fa_amort_pvt.t_period_num(i) = 1 and
4985 nvl(fa_cache_pkg.fazcdrd_record.period_update_flag,'N') = 'Y') or
4989
4986 (nvl(fa_cache_pkg.fazcdrd_record.use_eofy_reserve_flag, 'N') = 'Y') or
4987 ((nvl(fa_amort_pvt.t_change_in_cost(i), 0) <> 0) or
4988 (nvl(fa_amort_pvt.t_change_in_cip_cost(i), 0) <> 0)) then
4990 fa_amort_pvt.t_reset_adjusted_cost_flag(i) := 'Y';
4991 else
4992 fa_amort_pvt.t_adjusted_cost(i) := fa_amort_pvt.t_adjusted_cost(i-1);
4993 -- Bug 5741720: Adding following to reflect adjusted_cost
4994 l_asset_fin_rec_new.adjusted_cost := fa_amort_pvt.t_adjusted_cost(i);
4995
4996 if (p_log_level_rec.statement_level) then
4997 fa_debug_pkg.add(l_calling_fn, 'Inheriting adj cost from', 'Previous Period');
4998 end if;
4999
5000 end if;
5001 elsif (i = 1) then
5002 fa_amort_pvt.t_adjusted_cost(i) := 0;
5003 -- Bug 5741720: Adding following to reflect adjusted_cost
5004 l_asset_fin_rec_new.adjusted_cost := fa_amort_pvt.t_adjusted_cost(i);
5005
5006 if (p_log_level_rec.statement_level) then
5007 fa_debug_pkg.add(l_calling_fn, 'Resetting adjusted cost with ', '0');
5008 end if;
5009
5010 end if;
5011
5012 if (p_log_level_rec.statement_level) then
5013 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_adjusted_cost('||to_char(i)||')', fa_amort_pvt.t_adjusted_cost(i));
5014 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_cost', l_asset_fin_rec_new.adjusted_cost);
5015 end if;
5016 end if;
5017
5018
5019 fa_amort_pvt.t_recoverable_cost(i) := fa_amort_pvt.t_cost(i) - fa_amort_pvt.t_salvage_value(i);
5020 fa_amort_pvt.t_adjusted_recoverable_cost(i) := fa_amort_pvt.t_cost(i) -
5021 nvl(fa_amort_pvt.t_allowed_deprn_limit_amount(i),
5022 fa_amort_pvt.t_salvage_value(i));
5023
5024 fa_amort_pvt.t_date_placed_in_service(i) := nvl(p_asset_fin_rec_adj.date_placed_in_service,
5025 fa_amort_pvt.t_date_placed_in_service(i));
5026
5027
5028 fa_amort_pvt.t_ytd_proceeds_of_sale(i) := fa_amort_pvt.t_ytd_proceeds_of_sale(i) +
5029 nvl(p_asset_fin_rec_adj.ytd_proceeds, 0) +
5030 l_proceeds_of_sale;
5031
5032 fa_amort_pvt.t_ltd_proceeds_of_sale(i) := fa_amort_pvt.t_ltd_proceeds_of_sale(i) +
5033 nvl(p_asset_fin_rec_adj.ltd_proceeds, 0) +
5034 l_proceeds_of_sale;
5035
5036 --
5037 -- Not Yet Implemented
5038 --
5039 fa_amort_pvt.t_ytd_cost_of_removal(i) := fa_amort_pvt.t_ytd_cost_of_removal(i) +
5040 nvl(p_asset_fin_rec_adj.ltd_cost_of_removal , 0) +
5041 l_cost_of_removal;
5042
5043 fa_amort_pvt.t_ltd_cost_of_removal(i) := fa_amort_pvt.t_ltd_cost_of_removal(i) +
5044 nvl(p_asset_fin_rec_adj.ltd_cost_of_removal , 0) +
5045 l_cost_of_removal;
5046
5047
5048 fa_amort_pvt.t_unrevalued_cost(i) := fa_amort_pvt.t_unrevalued_cost(i) +
5049 nvl(p_asset_fin_rec_adj.unrevalued_cost, 0);
5050
5051 fa_amort_pvt.t_reval_amortization_basis(i) := fa_amort_pvt.t_reval_amortization_basis(i) +
5052 nvl(p_asset_fin_rec_adj.reval_amortization_basis, 0);
5053
5054
5055 if (p_log_level_rec.statement_level) then
5056 fa_debug_pkg.add(l_calling_fn, 'Finish Populating Global Variables', ' '
5057 ,p_log_level_rec => p_log_level_rec);
5058 end if;
5059
5060 -- fa_amort_pvt.t_reval_ceiling(i) :=
5061
5062 -- fa_amort_pvt.t_eofy_adj_cost(i) -- Unchanged
5063 -- fa_amort_pvt.t_eofy_formula_factor(i) Unchanged
5064 -- fa_amort_pvt.t_eofy_reserve(i) Unchanged
5065 if (i = 1) then
5066 fa_amort_pvt.t_eop_adj_cost(i) := 0;
5067 fa_amort_pvt.t_eop_formula_factor(i) := 1;
5068
5069 fa_amort_pvt.t_eofy_adj_cost(i) := 0;
5070 fa_amort_pvt.t_eofy_formula_factor(i) := 1;
5071 fa_amort_pvt.t_eofy_reserve (i) := nvl(fa_amort_pvt.t_change_in_eofy_reserve(i), 0);
5072
5073 else
5074 fa_amort_pvt.t_eop_adj_cost(i) := fa_amort_pvt.t_adjusted_cost(i - 1);
5075 fa_amort_pvt.t_eop_formula_factor(i) := fa_amort_pvt.t_formula_factor(i - 1);
5076
5077 if (fa_amort_pvt.t_period_num(i) = 1) then
5078 fa_amort_pvt.t_eofy_adj_cost(i) := fa_amort_pvt.t_adjusted_cost(i - 1);
5079 fa_amort_pvt.t_eofy_formula_factor(i) := fa_amort_pvt.t_formula_factor(i - 1);
5080 fa_amort_pvt.t_eofy_reserve (i) := fa_amort_pvt.t_deprn_reserve(i - 1) +
5081 nvl(fa_amort_pvt.t_change_in_eofy_reserve(i), 0);
5082 else
5083 fa_amort_pvt.t_eofy_adj_cost(i) := fa_amort_pvt.t_eofy_adj_cost(i - 1);
5084 fa_amort_pvt.t_eofy_formula_factor(i) := fa_amort_pvt.t_eofy_formula_factor(i - 1);
5085 fa_amort_pvt.t_eofy_reserve (i) := fa_amort_pvt.t_eofy_reserve(i - 1) +
5086 nvl(fa_amort_pvt.t_change_in_eofy_reserve(i), 0);
5087 end if;
5088
5089 end if;
5090
5094 --
5091
5092 --tk_util.debug('l_bs_ind: '||to_char(l_bs_ind));
5093 --tk_util.debug('l_asset_deprn_rec.deprn_reserve: '||to_char(l_asset_deprn_rec.deprn_reserve));
5095 -- Proceed if the period being processed is not current period and depreciation
5096 -- has not been recalculated yet, or
5097 -- This is current period but has some transaction entered and requires to recalculate
5098 -- adjusted_cost.
5099 --
5100 if ((l_bs_ind <= i) and
5101 (fa_amort_pvt.t_period_counter(i) < p_period_rec.period_counter)) or
5102 ((fa_amort_pvt.t_period_counter(i) = p_period_rec.period_counter) and
5103 (fa_amort_pvt.t_reset_adjusted_cost_flag(i) = 'Y')) then
5104
5105 fa_amort_pvt.t_deprn_amount(i) := fa_amort_pvt.t_expense_adjustment_amount(i);
5106 --tk_util.debug('l_trx_period_rec.period_counter: '||to_char(l_trx_period_rec.period_counter));
5107 --tk_util.debug('fa_amort_pvt.t_period_counter(i): '||to_char(fa_amort_pvt.t_period_counter(i)));
5108
5109 if (p_reclass_src_dest = 'SOURCE') and
5110 (l_trx_period_rec.period_counter = fa_amort_pvt.t_period_counter(i)) then
5111 if (i = 1) then
5112 null;
5113 else
5114
5115 -- HHIRAGA Added code for current period reclass under tracking
5116 if (p_log_level_rec.statement_level) then
5117 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: tracking_method', px_asset_fin_rec_new.tracking_method
5118 ,p_log_level_rec => p_log_level_rec);
5119 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: l_trx_period_rec.period_counter', l_trx_period_rec.period_counter
5120 ,p_log_level_rec => p_log_level_rec);
5121 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: l_current_period_counter', l_current_period_counter
5122 ,p_log_level_rec => p_log_level_rec);
5123 end if;
5124
5125 if nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'CALCULATE' and
5126 l_trx_period_rec.period_counter = l_current_period_counter then
5127
5128 x_deprn_reserve := (-1)*l_mem_deprn_reserve;
5129 fa_amort_pvt.t_reserve_adjustment_amount(i) :=
5130 fa_amort_pvt.t_reserve_adjustment_amount(i) + x_deprn_reserve;
5131
5132 fa_amort_pvt.t_eofy_reserve(i) := fa_amort_pvt.t_eofy_reserve(i) - l_mem_eofy_reserve;
5133 fa_amort_pvt.t_change_in_eofy_reserve(i) := (-1)* l_mem_eofy_reserve;
5134
5135 if (p_log_level_rec.statement_level) then
5136 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: x_deprn_reserve', x_deprn_reserve
5137 ,p_log_level_rec => p_log_level_rec);
5138 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: reserve_adjustment_amount',
5139 fa_amort_pvt.t_reserve_adjustment_amount(i));
5140 end if;
5141
5142 elsif nvl(px_asset_fin_rec_new.tracking_method,'NULL') = 'ALLOCATE' and
5143 (l_mem_loop_first) then
5144
5145 x_deprn_reserve := (-1)*l_mem_deprn_reserve;
5146 fa_amort_pvt.t_reserve_adjustment_amount(i) :=
5147 fa_amort_pvt.t_reserve_adjustment_amount(i) + x_deprn_reserve;
5148
5149 fa_amort_pvt.t_eofy_reserve(i) := fa_amort_pvt.t_eofy_reserve(i) - l_mem_eofy_reserve;
5150 fa_amort_pvt.t_change_in_eofy_reserve(i) := (-1)* l_mem_eofy_reserve;
5151 l_mem_loop_first := FALSE;
5152
5153 if (p_log_level_rec.statement_level) then
5154 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: x_deprn_reserve', x_deprn_reserve
5155 ,p_log_level_rec => p_log_level_rec);
5156 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: reserve_adjustment_amount',
5157 fa_amort_pvt.t_reserve_adjustment_amount(i));
5158 fa_debug_pkg.add(l_calling_fn, 'HHIRAGA Debug: eofy_reserve',
5159 fa_amort_pvt.t_eofy_reserve(i));
5160 end if;
5161
5162 else
5163
5164 /* commented due to bug#5601379\
5165 fa_amort_pvt.t_reserve_adjustment_amount(i) :=
5166 fa_amort_pvt.t_reserve_adjustment_amount(i) +
5167 (fa_amort_pvt.t_deprn_reserve(i - 1) - l_old_reserve); */
5168 --tk_util.debug('l_old_reserve: '||to_char(l_old_reserve));
5169 --tk_util.debug('t_deprn_reserve: '||to_char(fa_amort_pvt.t_deprn_reserve(i - 1)));
5170 x_deprn_reserve := (fa_amort_pvt.t_deprn_reserve(i - 1) - l_old_reserve);
5171
5172 end if; -- End of HHIRAGA if-statement
5173
5174 --
5175 -- Bug3537474: Don't need to reset previous deprn info because this reclass is
5176 -- happens in period of member addition
5177 --
5178 -- Bug4328772:
5179 -- Commenting out following condition and replacing with a condition with the line below
5180 -- if (p_reclassed_asset_dpis < fa_amort_pvt.t_calendar_period_open_date(l_count)) then
5181 if (l_trx_period_rec.period_counter < fa_amort_pvt.t_period_counter(l_count)) then
5182 fa_amort_pvt.t_ytd_deprn(i - 1) := l_gr_asset_deprn_rec.ytd_deprn;
5183 fa_amort_pvt.t_deprn_reserve(i - 1) := l_gr_asset_deprn_rec.deprn_reserve;
5184 fa_amort_pvt.t_bonus_ytd_deprn(i - 1) := l_gr_asset_deprn_rec.bonus_ytd_deprn;
5185 fa_amort_pvt.t_bonus_deprn_reserve(i - 1) := l_gr_asset_deprn_rec.bonus_deprn_reserve;
5189 fa_amort_pvt.t_reval_reserve(i - 1) := l_gr_asset_deprn_rec.reval_deprn_reserve;
5186 fa_amort_pvt.t_ltd_production(i - 1) := l_gr_asset_deprn_rec.ltd_production;
5187 fa_amort_pvt.t_ytd_production(i - 1) := l_gr_asset_deprn_rec.ytd_production;
5188 fa_amort_pvt.t_ytd_reval_deprn_expense(i - 1) := l_gr_asset_deprn_rec.reval_ytd_deprn;
5190 end if;
5191 end if; -- (i = 1)
5192 end if; -- (p_reclass_src_dest = 'SOURCE') and
5193
5194 if (i = 1) then
5195 l_eop_rec_cost := 0;
5196 l_eop_sal_val := 0;
5197 fa_amort_pvt.t_ytd_deprn(i) := fa_amort_pvt.t_deprn_amount(i);
5198 fa_amort_pvt.t_deprn_reserve(i) := fa_amort_pvt.t_deprn_amount(i) +
5199 fa_amort_pvt.t_reserve_adjustment_amount(i);
5200 fa_amort_pvt.t_bonus_ytd_deprn(i) := 0;
5201 fa_amort_pvt.t_bonus_deprn_reserve(i) := 0;
5202 fa_amort_pvt.t_ltd_production(i) := 0;
5203 fa_amort_pvt.t_ytd_production(i) := 0;
5204 fa_amort_pvt.t_ytd_reval_deprn_expense(i) := 0;
5205 fa_amort_pvt.t_reval_reserve(i) := 0;
5206 else
5207 l_eop_rec_cost := fa_amort_pvt.t_recoverable_cost(i - 1);
5208 l_eop_sal_val := fa_amort_pvt.t_salvage_value(i - 1);
5209 if (fa_amort_pvt.t_period_num(i) = 1) then
5210 fa_amort_pvt.t_ytd_deprn(i) := fa_amort_pvt.t_deprn_amount(i);
5211 fa_amort_pvt.t_bonus_ytd_deprn(i) := 0;
5212 fa_amort_pvt.t_ytd_production(i) := 0;
5213 fa_amort_pvt.t_ytd_reval_deprn_expense(i) := 0;
5214 else
5215 fa_amort_pvt.t_ytd_deprn(i) := fa_amort_pvt.t_deprn_amount(i) +
5216 fa_amort_pvt.t_ytd_deprn(i - 1);
5217 fa_amort_pvt.t_bonus_ytd_deprn(i) := fa_amort_pvt.t_bonus_ytd_deprn(i - 1);
5218 fa_amort_pvt.t_ytd_production(i) := fa_amort_pvt.t_ltd_production(i - 1);
5219 fa_amort_pvt.t_ytd_reval_deprn_expense(i) := fa_amort_pvt.t_ytd_reval_deprn_expense(i - 1);
5220
5221 end if;
5222 --tk_util.debug('fa_amort_pvt.t_deprn_reserve(i - 1): '||to_char(fa_amort_pvt.t_deprn_reserve(i - 1)));
5223 fa_amort_pvt.t_deprn_reserve(i) := fa_amort_pvt.t_deprn_amount(i) +
5224 fa_amort_pvt.t_reserve_adjustment_amount(i) +
5225 fa_amort_pvt.t_deprn_reserve(i - 1);
5226 fa_amort_pvt.t_bonus_deprn_reserve(i) := fa_amort_pvt.t_bonus_deprn_reserve(i - 1);
5227 fa_amort_pvt.t_ltd_production(i) := fa_amort_pvt.t_ltd_production(i - 1);
5228 fa_amort_pvt.t_reval_reserve(i) := fa_amort_pvt.t_reval_reserve(i - 1);
5229
5230 end if;
5231
5232 /* TEST BY HH */
5233 if (p_log_level_rec.statement_level) then
5234 fa_debug_pkg.add(l_calling_fn, 'HH CHECK i =',
5235 i || 'at Line Number from 4555'
5236 ,p_log_level_rec => p_log_level_rec);
5237 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_deprn_amount(i)',
5238 fa_amort_pvt.t_deprn_amount(i));
5239 if (i > 1) then
5240 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_deprn_reserve(i - 1)',
5241 fa_amort_pvt.t_deprn_reserve(i - 1));
5242 end if;
5243 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_reserve_adjustment_amount(i)',
5244 fa_amort_pvt.t_reserve_adjustment_amount(i));
5245 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_deprn_reserve(i)',
5246 fa_amort_pvt.t_deprn_reserve(i));
5247
5248 end if;
5249 /* End of TEST BY HH */
5250
5251
5252 --
5253 -- Populate l_asset_deprn_rec with previous period information
5254 --
5255 -- l_asset_deprn_rec := p_asset_deprn_rec;
5256
5257 if (i = 1) then
5258 l_asset_deprn_rec.deprn_amount := 0;
5259 l_asset_deprn_rec.ytd_deprn := 0;
5260 l_asset_deprn_rec.deprn_reserve := fa_amort_pvt.t_reserve_adjustment_amount(i);
5261 l_asset_deprn_rec.bonus_deprn_amount := 0;
5262 l_asset_deprn_rec.bonus_ytd_deprn := 0;
5263 l_asset_deprn_rec.bonus_deprn_reserve := 0;
5264 l_asset_deprn_rec.ltd_production := 0;
5265 l_asset_deprn_rec.ytd_production := 0;
5266 l_asset_deprn_rec.production := 0;
5267 l_asset_deprn_rec.reval_amortization := 0;
5268 l_asset_deprn_rec.reval_deprn_expense := 0;
5269 l_asset_deprn_rec.reval_deprn_reserve := 0;
5270 l_asset_deprn_rec.reval_ytd_deprn := 0;
5271 else
5272 l_asset_deprn_rec.deprn_amount := fa_amort_pvt.t_deprn_amount(i);
5273 l_asset_deprn_rec.ytd_deprn := fa_amort_pvt.t_ytd_deprn(i);
5274 l_asset_deprn_rec.deprn_reserve := fa_amort_pvt.t_deprn_reserve(i);
5275 l_asset_deprn_rec.bonus_deprn_amount := fa_amort_pvt.t_bonus_deprn_amount(i);
5276 l_asset_deprn_rec.bonus_ytd_deprn := fa_amort_pvt.t_bonus_ytd_deprn(i);
5277 l_asset_deprn_rec.bonus_deprn_reserve := fa_amort_pvt.t_bonus_deprn_reserve(i);
5281 l_asset_deprn_rec.reval_amortization := fa_amort_pvt.t_reval_amortization(i);
5278 l_asset_deprn_rec.ltd_production := fa_amort_pvt.t_ltd_production(i);
5279 l_asset_deprn_rec.ytd_production := fa_amort_pvt.t_ytd_production(i);
5280 l_asset_deprn_rec.production := fa_amort_pvt.t_production(i);
5282 l_asset_deprn_rec.reval_deprn_expense := fa_amort_pvt.t_reval_deprn_expense(i);
5283 l_asset_deprn_rec.reval_deprn_reserve := fa_amort_pvt.t_reval_reserve(i);
5284 l_asset_deprn_rec.reval_ytd_deprn := fa_amort_pvt.t_ytd_reval_deprn_expense(i);
5285 end if;
5286
5287 --
5288 -- Populate l_asset_fin_rec_new
5289 --
5290 l_asset_fin_rec_new.cost := fa_amort_pvt.t_cost(i);
5291 l_asset_fin_rec_new.salvage_value := fa_amort_pvt.t_salvage_value(i);
5292 l_asset_fin_rec_new.recoverable_cost := fa_amort_pvt.t_recoverable_cost(i);
5293 l_asset_fin_rec_new.deprn_method_code := fa_amort_pvt.t_deprn_method_code(i);
5294 l_asset_fin_rec_new.life_in_months := fa_amort_pvt.t_life_in_months(i);
5295 l_asset_fin_rec_new.group_asset_id := fa_amort_pvt.t_group_asset_id(i);
5296 l_asset_fin_rec_new.depreciate_flag := fa_amort_pvt.t_depreciate_flag(i);
5297 l_asset_fin_rec_new.eofy_reserve := fa_amort_pvt.t_eofy_reserve(i);
5298 l_asset_fin_rec_new.rate_adjustment_factor := fa_amort_pvt.t_rate_adjustment_factor(i);
5299 l_asset_fin_rec_new.formula_factor := fa_amort_pvt.t_formula_factor(i);
5300 l_asset_fin_rec_new.super_group_id := fa_amort_pvt.t_super_group_id(i);
5301
5302 l_dpr_in.asset_num := p_asset_desc_rec.asset_number;
5303 l_dpr_in.calendar_type := fa_cache_pkg.fazcbc_record.deprn_calendar;
5304 l_dpr_in.book := p_asset_hdr_rec.book_type_code;
5305 l_dpr_in.asset_id := p_asset_hdr_rec.asset_id;
5306
5307 l_dpr_in.adj_cost := fa_amort_pvt.t_recoverable_cost(i);
5308 l_dpr_in.rec_cost := fa_amort_pvt.t_recoverable_cost(i);
5309 l_dpr_in.reval_amo_basis := fa_amort_pvt.t_reval_amortization_basis(i);
5310 l_dpr_in.adj_rate := fa_amort_pvt.t_adjusted_rate(i);
5311 l_dpr_in.rate_adj_factor := 1;
5312 l_dpr_in.capacity := fa_amort_pvt.t_production_capacity(i);
5313 l_dpr_in.adj_capacity := fa_amort_pvt.t_adjusted_capacity(i);
5314 l_dpr_in.ltd_prod := 0;
5315 l_dpr_in.ytd_deprn := 0; -- This needs to be 0 for this faxcde call
5316 l_dpr_in.deprn_rsv := 0;
5317 l_dpr_in.reval_rsv := l_asset_deprn_rec.reval_deprn_reserve;
5318 l_dpr_in.bonus_deprn_exp := l_asset_deprn_rec.bonus_deprn_amount;
5319 l_dpr_in.bonus_ytd_deprn := l_asset_deprn_rec.bonus_ytd_deprn;
5320 l_dpr_in.bonus_deprn_rsv := l_asset_deprn_rec.bonus_deprn_reserve;
5321 l_dpr_in.prior_fy_bonus_exp := l_asset_deprn_rec.prior_fy_bonus_expense;
5322
5323 l_dpr_in.ceil_name := fa_amort_pvt.t_ceiling_name(i);
5324 l_dpr_in.bonus_rule := fa_amort_pvt.t_bonus_rule(i);
5325 l_dpr_in.method_code := fa_amort_pvt.t_deprn_method_code(i);
5326 l_dpr_in.jdate_in_service :=
5327 to_number(to_char(fa_amort_pvt.t_date_placed_in_service(i), 'J'));
5328 --
5329 -- Use dpis as prorate and deprn start date
5330 -- This is ok since this code is only for group now
5331 -- Need to pass actual prorate/deprn start date if this code is open for standalone assets
5332 --
5333 l_dpr_in.prorate_jdate := to_number(to_char(fa_amort_pvt.t_date_placed_in_service(i), 'J'));
5334 l_dpr_in.deprn_start_jdate :=
5335 to_number(to_char(fa_amort_pvt.t_date_placed_in_service(i), 'J'));
5336 l_dpr_in.prorate_date := fa_amort_pvt.t_date_placed_in_service(i);
5337 l_dpr_in.orig_deprn_start_date := fa_amort_pvt.t_date_placed_in_service(i);
5338
5339
5340 l_dpr_in.jdate_retired := 0; -- don't know this is correct or not
5341 l_dpr_in.ret_prorate_jdate := 0; -- don't know this is correct or not
5342 l_dpr_in.life := fa_amort_pvt.t_life_in_months(i);
5343
5344 l_dpr_in.rsv_known_flag := TRUE;
5345 l_dpr_in.salvage_value := fa_amort_pvt.t_salvage_value(i);
5346
5347 l_dpr_in.adj_rec_cost := fa_amort_pvt.t_adjusted_recoverable_cost(i);
5348 l_dpr_in.prior_fy_exp := 0; -- This needs to be 0 for this faxcde call
5349
5350 l_dpr_in.short_fiscal_year_flag := fa_amort_pvt.t_short_fiscal_year_flag(i);
5351
5352 l_dpr_in.old_adj_cost := fa_amort_pvt.t_adjusted_cost(i);
5353 l_dpr_in.formula_factor := fa_amort_pvt.t_formula_factor(i);
5354
5355 l_dpr_in.super_group_id := fa_amort_pvt.t_super_group_id(i);
5356 l_dpr_in.over_depreciate_option := fa_amort_pvt.t_over_depreciate_option(i);
5357
5358 --
5359 -- These values are not stored in Books_Summary since these value won't be
5360 -- Changed over periods.
5361 --
5362 l_dpr_in.tracking_method := px_asset_fin_rec_new.tracking_method;
5363 l_dpr_in.allocate_to_fully_ret_flag := px_asset_fin_rec_new.allocate_to_fully_ret_flag;
5364 l_dpr_in.allocate_to_fully_rsv_flag := px_asset_fin_rec_new.allocate_to_fully_rsv_flag;
5365 l_dpr_in.excess_allocation_option := px_asset_fin_rec_new.excess_allocation_option;
5366 l_dpr_in.depreciation_option := px_asset_fin_rec_new.depreciation_option;
5367 l_dpr_in.member_rollup_flag := px_asset_fin_rec_new.member_rollup_flag;
5368 l_dpr_in.mrc_sob_type_code := p_mrc_sob_type_code;
5372 -- There is no plane to store following variables in books summary now
5369
5370
5371 --
5373 -- so copy value from fin_rec_new
5374 l_dpr_in.pc_life_end := px_asset_fin_rec_new.period_counter_life_complete;
5375 l_dpr_in.conversion_date := px_asset_fin_rec_new.conversion_date;
5376
5377
5378 --
5379 -- Following may needed to be added and implemented in Books Summary
5380 -- 'ADJ' for now
5381 --
5382 l_dpr_in.deprn_rounding_flag := 'ADJ';
5383
5384
5385 l_dpr_in.deprn_override_flag := p_trans_rec.deprn_override_flag;
5386 l_dpr_in.used_by_adjustment := TRUE;
5387
5388
5389 --
5390 -- Not for what-if yet
5391 --
5392 l_running_mode := fa_std_types.FA_DPR_NORMAL;
5393
5394
5395 if (not fa_cache_pkg.fazccmt(
5396 fa_amort_pvt.t_deprn_method_code(i),
5397 fa_amort_pvt.t_life_in_months(i))) then
5398 if (p_log_level_rec.statement_level) then
5399 fa_debug_pkg.add(l_calling_fn, 'Error calling',
5400 'fa_cache_pkg.fazccmt'
5401 ,p_log_level_rec => p_log_level_rec);
5402 end if;
5403
5404 raise calc_failed;
5405 end if;
5406
5407 if i = 1 then
5408 if not fa_cache_pkg.fazccp(fa_cache_pkg.fazcbc_record.prorate_calendar,
5409 fa_cache_pkg.fazcbc_record.fiscal_year_name,
5410 l_dpr_in.prorate_jdate,
5411 g_temp_number,
5412 l_dpr_in.y_begin,
5413 g_temp_integer
5414 ,p_log_level_rec => p_log_level_rec) then
5415 if (p_log_level_rec.statement_level) then
5416 fa_debug_pkg.add(l_calling_fn, 'Error calling',
5417 'fa_cache_pkg.fazccp'
5418 ,p_log_level_rec => p_log_level_rec);
5419 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.prorate_calendar',
5420 fa_cache_pkg.fazcbc_record.prorate_calendar
5421 ,p_log_level_rec => p_log_level_rec);
5422 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.fiscal_year_name',
5423 fa_cache_pkg.fazcbc_record.fiscal_year_name
5424 ,p_log_level_rec => p_log_level_rec);
5425
5426 end if;
5427
5428 raise calc_failed;
5429 end if;
5430 end if;
5431
5432
5433 if (p_log_level_rec.statement_level) then
5434 fa_debug_pkg.add(l_calling_fn, 'Japan Tax: l_trans_rec.transaction_key',
5435 l_trans_rec.transaction_key);
5436 end if;
5437
5438 --
5439 -- Skip faxcde call for raf
5440 -- If rate source rule is FLAT and depreciable basis is Cost
5441 -- Bug4778244 Added the NVL to avoid condition if(not(null or false)) which will
5442 -- always return NULL in place of FALSE, which is incorrect
5443 if (not(((nvl(fa_cache_pkg.fazccmt_record.rate_source_rule, ' ') = fa_std_types.FAD_RSR_FLAT) and
5444 (nvl(fa_cache_pkg.fazccmt_record.deprn_basis_rule, ' ') = fa_std_types.FAD_DBR_COST) and
5445 (nvl(fa_cache_pkg.fazcdbr_record.rule_name, ' ') in ('PERIOD END BALANCE',
5446 'PERIOD END AVERAGE',
5447 'USE RECOVERABLE COST',
5448 'BEGINNING PERIOD'))) or
5449 (nvl(l_trans_rec.transaction_key,'X') = 'ES') -- Japan Tax Phase3
5450 )) then
5451
5452 if not fa_cache_pkg.fazccp(fa_cache_pkg.fazcbc_record.prorate_calendar,
5453 fa_cache_pkg.fazcbc_record.fiscal_year_name,
5454 l_dpr_in.prorate_jdate,
5455 g_temp_number,
5456 l_dpr_in.y_begin,
5457 g_temp_integer
5458 ,p_log_level_rec => p_log_level_rec) then
5459 if (p_log_level_rec.statement_level) then
5460 fa_debug_pkg.add(l_calling_fn, 'Error calling',
5461 'fa_cache_pkg.fazccp'
5462 ,p_log_level_rec => p_log_level_rec);
5463 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.prorate_calendar',
5464 fa_cache_pkg.fazcbc_record.prorate_calendar
5465 ,p_log_level_rec => p_log_level_rec);
5466 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.fiscal_year_name',
5467 fa_cache_pkg.fazcbc_record.fiscal_year_name
5468 ,p_log_level_rec => p_log_level_rec);
5469
5470 end if;
5471
5472 raise calc_failed;
5473 end if;
5474
5475 l_dpr_in.p_cl_begin := 1;
5476
5477 if (fa_amort_pvt.t_period_num(i) = 1) then
5478 l_dpr_in.y_end := fa_amort_pvt.t_fiscal_year(i) - 1;
5482 l_dpr_in.p_cl_end := fa_amort_pvt.t_period_num(i) - 1;
5479 l_dpr_in.p_cl_end := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
5480 else
5481 l_dpr_in.y_end := fa_amort_pvt.t_fiscal_year(i);
5483 end if;
5484
5485 l_dpr_in.rate_adj_factor := 1;
5486
5487 -- manual override
5488 if fa_cache_pkg.fa_deprn_override_enabled then
5489
5490 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
5491 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
5492
5493 -- update override status only if satisfies condintion,
5494 -- otherwise do not update status when calculating RAF
5495 -- 1. formula; or
5496 -- 2. (calc or table) and cost
5497
5498 l_dpr_in.update_override_status :=
5499 ((l_rate_source_rule = fa_std_types.FAD_RSR_FORMULA)
5500 OR (((l_rate_source_rule = fa_std_types.FAD_RSR_CALC)
5501 OR (l_rate_source_rule = fa_std_types.FAD_RSR_TABLE))
5502 AND (l_deprn_basis_rule = fa_std_types.FAD_DBR_COST)));
5503 end if;
5504
5505 --* HHIRAGA modified on Oct/Nov in 2003.
5506 -- Changed parameter to period counter when the recalculation of
5507 -- RAF needs.
5508 -- This function will populates all member assets to be used to
5509 -- hypothetical allocation internally.
5510 --
5511 --+++++++ Call Tracking Function to populate Member in case ALLOCATE ++++++
5512 if p_asset_type_rec.asset_type = 'GROUP' and
5513 nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
5514
5515 l_raf_processed_flag := TRUE;
5516 l_dpr_in.tracking_method := NULL;
5517
5518 /*
5519 if not FA_TRACK_MEMBER_PVT.get_member_at_start(
5520 p_period_rec => l_period_rec,
5521 p_trans_rec => p_trans_rec,
5522 p_asset_hdr_rec => p_asset_hdr_rec,
5523 p_asset_fin_rec => px_asset_fin_rec_new,
5524 p_dpr_in => l_dpr_in,
5525 p_mrc_sob_type_code => p_mrc_sob_type_code
5526 ,p_log_level_rec => p_log_level_rec) then
5527 if (p_log_level_rec.statement_level) then
5528 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'FA_TRACK_MEMBER_PVT.get_member_at_start'
5529 ,p_log_level_rec => p_log_level_rec);
5530 end if;
5531
5532 raise calc_failed;
5533
5534 end if;
5535 */
5536 end if; -- nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE'
5537
5538 if (p_log_level_rec.statement_level) then
5539 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
5540 ,p_log_level_rec => p_log_level_rec);
5541 fa_debug_pkg.add(l_calling_fn, ' Call ', 'FA_CDE_PKG.faxcde'
5542 ,p_log_level_rec => p_log_level_rec);
5543 end if;
5544
5545 --+++++++ Call Depreciation engine for rate adjustment factor +++++++
5546 if not FA_CDE_PKG.faxcde(l_dpr_in,
5547 l_dpr_arr,
5548 l_dpr_out,
5549 l_running_mode
5550 ,p_log_level_rec => p_log_level_rec) then
5551 if (p_log_level_rec.statement_level) then
5552 fa_debug_pkg.add(l_calling_fn, 'Error calling',
5553 'FA_CDE_PKG.faxcde'
5554 ,p_log_level_rec => p_log_level_rec);
5555 end if;
5556
5557 raise calc_failed;
5558 end if;
5559
5560 if (p_log_level_rec.statement_level) then
5561 fa_debug_pkg.add(l_calling_fn, 'l_dpr_out.new_deprn_rsv',
5562 l_dpr_out.new_deprn_rsv
5563 ,p_log_level_rec => p_log_level_rec);
5564 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
5565 ,p_log_level_rec => p_log_level_rec);
5566 end if;
5567
5568 -- manual override
5569 if fa_cache_pkg.fa_deprn_override_enabled then
5570 if l_dpr_in.update_override_status then
5571 p_trans_rec.deprn_override_flag := l_dpr_out.deprn_override_flag;
5572 else
5573 p_trans_rec.deprn_override_flag := fa_std_types.FA_NO_OVERRIDE;
5574 end if;
5575 end if;
5576
5577 l_asset_fin_rec_new.adjusted_cost := l_dpr_out.new_adj_cost;
5578 l_asset_fin_rec_new.reval_amortization_basis := l_dpr_out.new_reval_amo_basis;
5579 l_asset_deprn_rec_raf.deprn_reserve := l_dpr_out.new_deprn_rsv;
5580 l_asset_deprn_rec_raf.reval_deprn_reserve := l_dpr_out.new_reval_rsv;
5581 l_asset_fin_rec_new.adjusted_capacity := l_asset_fin_rec_new.production_capacity -
5582 l_dpr_out.new_ltd_prod;
5583 l_asset_deprn_rec_raf.ltd_production := l_dpr_out.new_ltd_prod;
5584 l_asset_deprn_rec_raf.prior_fy_expense := l_dpr_out.new_prior_fy_exp;
5588
5585 l_asset_deprn_rec_raf.bonus_deprn_amount := l_dpr_out.bonus_deprn_exp;
5586 l_asset_deprn_rec_raf.bonus_deprn_reserve := l_dpr_out.new_bonus_deprn_rsv;
5587 l_asset_deprn_rec_raf.prior_fy_bonus_expense := l_dpr_out.new_prior_fy_bonus_exp;
5589 -- HHIRAGA
5590 --++++++++ Tracking=ALLOCATE case ++++++++++++++
5591 if (l_raf_processed_flag) then
5592 l_dpr_in.tracking_method := 'ALLOCATE';
5593 l_raf_processed_flag := FALSE;
5594 end if;
5595
5596 if nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
5597
5598 fa_track_member_pvt.p_track_member_table.delete;
5599
5600 if (p_log_level_rec.statement_level) then
5601 fa_debug_pkg.add(l_calling_fn, 'fa_track_member_pvt.p_track_member_table',
5602 'deleted'
5603 ,p_log_level_rec => p_log_level_rec);
5604 end if;
5605 end if;
5606
5607 else
5608 l_asset_fin_rec_new.adjusted_cost := l_asset_fin_rec_new.recoverable_cost;
5609 end if; ---- skip faxcde call for raf
5610
5611
5612 if (p_log_level_rec.statement_level) then
5613 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
5614 ,p_log_level_rec => p_log_level_rec);
5615 fa_debug_pkg.add(l_calling_fn, ' Call ',
5616 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
5617 ,p_log_level_rec => p_log_level_rec);
5618 fa_debug_pkg.add(l_calling_fn, 'p_trans_rec.transaction_type_code',
5619 p_trans_rec.transaction_type_code
5620 ,p_log_level_rec => p_log_level_rec);
5621 fa_debug_pkg.add(l_calling_fn, 'l_trans_rec.transaction_type_code',
5622 l_trans_rec.transaction_type_code
5623 ,p_log_level_rec => p_log_level_rec);
5624 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.eofy_reserve',
5625 l_asset_fin_rec_new.eofy_reserve
5626 ,p_log_level_rec => p_log_level_rec);
5627 fa_debug_pkg.add(l_calling_fn, 'l_asset_deprn_rec.deprn_reserve',
5628 l_asset_deprn_rec.deprn_reserve
5629 ,p_log_level_rec => p_log_level_rec);
5630 fa_debug_pkg.add(l_calling_fn, 'l_asset_deprn_rec.bonus_deprn_reserve',
5631 l_asset_deprn_rec.bonus_deprn_reserve
5632 ,p_log_level_rec => p_log_level_rec);
5633 end if;
5634
5635 --* HHIRAGA modified on OCT/NOV in 2003
5636 -- Prepare memory table to be able to process depreciation recalculation
5637 -- This function should be called only when memory table has not been populated.
5638 -- if l_processed_flag is FALSE, process this preparation function
5639 if p_asset_type_rec.asset_type = 'GROUP' and
5640 nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
5641
5642 l_no_allocation_for_last := 'Y';
5643 if (fa_amort_pvt.t_reset_adjusted_cost_flag(i) = 'Y') and
5644 (not (l_first_process)
5645 and p_trans_rec.transaction_type_code = 'GROUP ADDITION') then
5646
5647 l_no_allocation_for_last := 'N';
5648 if fa_amort_pvt.t_period_num(i) = 1 then
5649 l_recalc_start_fy := fa_amort_pvt.t_fiscal_year(i) - 1;
5650 l_recalc_start_period_num := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
5651 else
5652 l_recalc_start_fy := fa_amort_pvt.t_fiscal_year(i);
5653 l_recalc_start_period_num := fa_amort_pvt.t_period_num(i) - 1;
5654 end if;
5655
5656 if (p_log_level_rec.statement_level) then
5657 fa_debug_pkg.add(l_calling_fn, '++++ Call ++++', 'FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE'
5658 ,p_log_level_rec => p_log_level_rec);
5659 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_reset_adjusted_cost_flag(i)',
5660 fa_amort_pvt.t_reset_adjusted_cost_flag(i));
5661 fa_debug_pkg.add(l_calling_fn, 'l_recalc_start_fy', l_recalc_start_fy
5662 ,p_log_level_rec => p_log_level_rec);
5663 fa_debug_pkg.add(l_calling_fn, 'l_recalc_start_period_num', l_recalc_start_period_num
5664 ,p_log_level_rec => p_log_level_rec);
5665 fa_debug_pkg.add(l_calling_fn, 'l_old_recalc_end_fy', l_old_recalc_end_fy
5666 ,p_log_level_rec => p_log_level_rec);
5667 fa_debug_pkg.add(l_calling_fn, 'l_old_recalc_end_period_num', l_old_recalc_end_period_num
5668 ,p_log_level_rec => p_log_level_rec);
5669 end if;
5670
5671 if (nvl(l_old_recalc_end_fy,l_recalc_start_fy) = l_recalc_start_fy and
5672 nvl(l_old_recalc_end_period_num,l_recalc_start_period_num+1) <> l_recalc_start_period_num) then
5673 l_backup_processed_flag := FALSE;
5674 elsif (l_backup_processed_flag) then
5675 l_recalc_start_fy := fa_amort_pvt.t_fiscal_year(i);
5676 l_recalc_start_period_num := fa_amort_pvt.t_period_num(i);
5677 end if;
5678
5679 else
5680
5684 l_processed_flag := TRUE;
5681 l_recalc_start_fy := fa_amort_pvt.t_fiscal_year(i);
5682 l_recalc_start_period_num := fa_amort_pvt.t_period_num(i);
5683
5685 fa_track_member_pvt.l_process_deprn_for_member := 'NO';
5686 /*
5687 l_asset_fin_rec_new.tracking_method := NULL;
5688 l_asset_fin_rec_old.tracking_method := NULL;
5689 */
5690
5691 if (p_log_level_rec.statement_level) then
5692 fa_debug_pkg.add(l_calling_fn, '++++ Call ++++', 'FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE'
5693 ,p_log_level_rec => p_log_level_rec);
5694 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_reset_adjusted_cost_flag(i)',
5695 fa_amort_pvt.t_reset_adjusted_cost_flag(i));
5696 fa_debug_pkg.add(l_calling_fn, 'l_recalc_start_fy', l_recalc_start_fy
5697 ,p_log_level_rec => p_log_level_rec);
5698 fa_debug_pkg.add(l_calling_fn, 'l_recalc_start_period_num', l_recalc_start_period_num
5699 ,p_log_level_rec => p_log_level_rec);
5700 fa_debug_pkg.add(l_calling_fn, 'l_old_recalc_end_fy', l_old_recalc_end_fy
5701 ,p_log_level_rec => p_log_level_rec);
5702 fa_debug_pkg.add(l_calling_fn, 'l_old_recalc_end_period_num', l_old_recalc_end_period_num
5703 ,p_log_level_rec => p_log_level_rec);
5704 end if;
5705
5706 if l_old_recalc_end_fy is not NULL and l_old_recalc_end_period_num is not NULL then
5707 if l_old_recalc_end_period_num = fa_cache_pkg.fazcct_record.number_per_fiscal_year then
5708 l_old_recalc_end_fy := l_old_recalc_end_fy + 1;
5709 l_old_recalc_end_period_num := 1;
5710 else
5711 l_old_recalc_end_period_num := l_old_recalc_end_period_num + 1;
5712 end if;
5713 end if;
5714
5715 if (nvl(l_old_recalc_end_fy,l_recalc_start_fy) = l_recalc_start_fy and
5716 nvl(l_old_recalc_end_period_num,l_recalc_start_period_num+1) <> l_recalc_start_period_num) then
5717 l_backup_processed_flag := FALSE;
5718 end if;
5719
5720 end if;
5721
5722 --* Calcualte recalc_start_period_counter
5723 if (l_first_process) then
5724 l_recalc_start_period_counter := l_recalc_start_fy*(fa_cache_pkg.fazcct_record.number_per_fiscal_year)
5725 + l_recalc_start_period_num;
5726
5727 if p_mrc_sob_type_code <> 'R' then
5728 open c_chk_bs_row_exists;
5729 fetch c_chk_bs_row_exists into l_chk_bs_row_exists;
5730 if c_chk_bs_row_exists%FOUND then
5731 if not FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE
5732 (p_asset_hdr_rec => p_asset_hdr_rec,
5733 p_asset_fin_rec_new => px_asset_fin_rec_new,
5734 p_populate_for_recalc_period => 'T',
5735 p_amort_start_date => l_transaction_date_entered,
5736 p_recalc_start_fy => l_recalc_start_fy,
5737 p_recalc_start_period_num => l_recalc_start_period_num,
5738 p_no_allocation_for_last => l_no_allocation_for_last,
5739 p_mrc_sob_type_code => p_mrc_sob_type_code
5740 ,p_log_level_rec => p_log_level_rec) then
5741 if (p_log_level_rec.statement_level) then
5742 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'POPULATE_MEMBER_ASSETS_TABLE'
5743 ,p_log_level_rec => p_log_level_rec);
5744 end if;
5745 raise calc_failed;
5746 end if;
5747 else
5748 if not FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE
5749 (p_asset_hdr_rec => p_asset_hdr_rec,
5750 p_asset_fin_rec_new => px_asset_fin_rec_new,
5751 p_amort_start_date => l_transaction_date_entered,
5752 p_recalc_start_fy => l_recalc_start_fy,
5753 p_recalc_start_period_num => l_recalc_start_period_num,
5754 p_no_allocation_for_last => l_no_allocation_for_last,
5755 p_mrc_sob_type_code => p_mrc_sob_type_code
5756 ,p_log_level_rec => p_log_level_rec) then
5757 if (p_log_level_rec.statement_level) then
5758 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'POPULATE_MEMBER_ASSETS_TABLE'
5759 ,p_log_level_rec => p_log_level_rec);
5760 end if;
5761 raise calc_failed;
5762 end if;
5763 end if;
5764 close c_chk_bs_row_exists;
5765
5766 else -- MRC
5767
5768 open c_chk_bs_row_exists_mrc;
5772 (p_asset_hdr_rec => p_asset_hdr_rec,
5769 fetch c_chk_bs_row_exists_mrc into l_chk_bs_row_exists;
5770 if c_chk_bs_row_exists_mrc%FOUND then
5771 if not FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE
5773 p_asset_fin_rec_new => px_asset_fin_rec_new,
5774 p_populate_for_recalc_period => 'T',
5775 p_amort_start_date => l_transaction_date_entered,
5776 p_recalc_start_fy => l_recalc_start_fy,
5777 p_recalc_start_period_num => l_recalc_start_period_num,
5778 p_no_allocation_for_last => l_no_allocation_for_last,
5779 p_mrc_sob_type_code => p_mrc_sob_type_code
5780 ,p_log_level_rec => p_log_level_rec) then
5781 if (p_log_level_rec.statement_level) then
5782 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'POPULATE_MEMBER_ASSETS_TABLE'
5783 ,p_log_level_rec => p_log_level_rec);
5784 end if;
5785 raise calc_failed;
5786 end if;
5787 else
5788 if not FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE
5789 (p_asset_hdr_rec => p_asset_hdr_rec,
5790 p_asset_fin_rec_new => px_asset_fin_rec_new,
5791 p_amort_start_date => l_transaction_date_entered,
5792 p_recalc_start_fy => l_recalc_start_fy,
5793 p_recalc_start_period_num => l_recalc_start_period_num,
5794 p_no_allocation_for_last => l_no_allocation_for_last,
5795 p_mrc_sob_type_code => p_mrc_sob_type_code
5796 ,p_log_level_rec => p_log_level_rec) then
5797 if (p_log_level_rec.statement_level) then
5798 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'POPULATE_MEMBER_ASSETS_TABLE'
5799 ,p_log_level_rec => p_log_level_rec);
5800 end if;
5801 raise calc_failed;
5802 end if;
5803 end if;
5804 close c_chk_bs_row_exists_mrc;
5805 end if; -- MRC or Primary
5806 l_old_recalc_start_fy := l_recalc_start_fy;
5807 l_old_recalc_start_period_num := l_recalc_start_period_num;
5808
5809 else
5810
5811 l_old_recalc_start_fy := l_recalc_start_fy;
5812 l_old_recalc_start_period_num := l_recalc_start_period_num;
5813
5814 if not (l_backup_processed_flag) then
5815 if not FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE
5816 (p_asset_hdr_rec => p_asset_hdr_rec,
5817 p_asset_fin_rec_new => px_asset_fin_rec_new,
5818 p_amort_start_date => l_transaction_date_entered,
5819 p_recalc_start_fy => l_recalc_start_fy,
5820 p_recalc_start_period_num => l_recalc_start_period_num,
5821 p_no_allocation_for_last => l_no_allocation_for_last,
5822 p_mrc_sob_type_code => p_mrc_sob_type_code
5823 ,p_log_level_rec => p_log_level_rec) then
5824 if (p_log_level_rec.statement_level) then
5825 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'POPULATE_MEMBER_ASSETS_TABLE'
5826 ,p_log_level_rec => p_log_level_rec);
5827 end if;
5828 raise calc_failed;
5829 end if;
5830
5831 else
5832
5833 fa_debug_pkg.add(l_calling_fn, '##### bakcup table counter #####',
5834 fa_track_member_pvt.p_track_member_table_for_deprn.COUNT
5835 ,p_log_level_rec => p_log_level_rec);
5836
5837 if not FA_TRACK_MEMBER_PVT.copy_member_table(p_backup_restore => 'RESTORE'
5838 ,p_log_level_rec => p_log_level_rec) then
5839 if (p_log_level_rec.statement_level) then
5840 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'COPY_MEMBER_TABLE'
5841 ,p_log_level_rec => p_log_level_rec);
5842 end if;
5843 raise calc_failed;
5844 end if;
5845
5846 --* Calculate only for this period
5847 if not FA_TRACK_MEMBER_PVT.POPULATE_MEMBER_ASSETS_TABLE
5848 (p_asset_hdr_rec => p_asset_hdr_rec,
5849 p_asset_fin_rec_new => px_asset_fin_rec_new,
5850 p_populate_for_recalc_period => 'Y',
5851 p_amort_start_date => l_transaction_date_entered,
5852 p_recalc_start_fy => l_recalc_start_fy,
5853 p_recalc_start_period_num => l_recalc_start_period_num,
5857 if (p_log_level_rec.statement_level) then
5854 p_no_allocation_for_last => 'Y',
5855 p_mrc_sob_type_code => p_mrc_sob_type_code
5856 ,p_log_level_rec => p_log_level_rec) then
5858 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'POPULATE_MEMBER_ASSETS_TABLE'
5859 ,p_log_level_rec => p_log_level_rec);
5860 end if;
5861 raise calc_failed;
5862 end if;
5863
5864 l_processed_flag := TRUE;
5865 fa_track_member_pvt.l_process_deprn_for_member := 'NO';
5866
5867 end if; -- IF not (l_backup_processed_flag)
5868
5869 end if; -- l_first_process_flag
5870
5871 if (l_first_process) then
5872 l_first_process := FALSE;
5873 end if;
5874
5875
5876 end if; -- HHIRAGA if-statement
5877
5878 --
5879 -- From old fin rec followings are necessary
5880 -- formula_factor
5881 -- rate_adjustment_factor
5882 -- adjusted_cost
5883 -- cost
5884 --
5885 -- From new fin rec followings are necessary
5886 -- Method
5887 -- life
5888 -- group asset id
5889 -- depreciate_flag
5890 -- cost
5891 -- salvage_value
5892 -- recoverable_cost
5893 -- reduction_rate
5894 -- eofy_reserve
5895 -- recognize_gain_loss
5896 -- tracking_method
5897 -- allocate_to_fully_rsv_flag
5898 -- allocate_to_fully_ret_flag
5899 -- excess_allocation_option
5900 -- depreciation_option
5901 -- member_rollup_flag
5902
5903 if (fa_cache_pkg.fazcdbr_record.rule_name = 'ENERGY PERIOD END BALANCE') and
5904 (p_asset_fin_rec_old.tracking_method = 'ALLOCATE') and
5905 (p_trans_rec.transaction_key = 'MS') then
5906 l_reserve_retired := 0;
5907 end if;
5908
5909 --
5910 -- reset_adjusted_cost_flag can be no or null in case
5911 -- this is reclass source group.
5912 -- otherwise, deprn basis rule function gets called all the time
5913 -- if process reaches here.
5914 --
5915 if (fa_amort_pvt.t_reset_adjusted_cost_flag(i) = 'Y') then
5916 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
5917 (p_event_type => 'AMORT_ADJ',
5918 p_asset_fin_rec_new => l_asset_fin_rec_new,
5919 p_asset_fin_rec_old => l_asset_fin_rec_old,
5920 p_asset_hdr_rec => p_asset_hdr_rec,
5921 p_asset_type_rec => p_asset_type_rec,
5922 p_asset_deprn_rec => l_asset_deprn_rec,
5923 p_trans_rec => p_trans_rec,
5924 p_trans_rec_adj => l_trans_rec,
5925 p_period_rec => l_period_rec,
5926 p_current_total_rsv => l_asset_deprn_rec.deprn_reserve,
5927 p_current_rsv => l_asset_deprn_rec.deprn_reserve -
5928 nvl(l_asset_deprn_rec.bonus_deprn_reserve, 0),
5929 p_current_total_ytd => l_asset_deprn_rec.ytd_deprn,
5930 p_adj_reserve => p_asset_deprn_rec_adj.deprn_reserve,
5931 p_reserve_retired => l_reserve_retired,
5932 p_hyp_basis => l_asset_fin_rec_new.adjusted_cost,
5933 p_hyp_total_rsv => l_asset_deprn_rec_raf.deprn_reserve,
5934 p_hyp_rsv => l_asset_deprn_rec_raf.deprn_reserve -
5935 nvl(l_asset_deprn_rec_raf.bonus_deprn_reserve, 0),
5936 p_eofy_recoverable_cost => l_eofy_rec_cost,
5937 p_eop_recoverable_cost => l_eop_rec_cost,
5938 p_eofy_salvage_value => l_eofy_sal_val,
5939 p_eop_salvage_value => l_eop_sal_val,
5940 p_mrc_sob_type_code => p_mrc_sob_type_code,
5941 p_used_by_adjustment => 'ADJUSTMENT',
5942 px_new_adjusted_cost => l_asset_fin_rec_new.adjusted_cost,
5943 px_new_raf => l_asset_fin_rec_new.rate_adjustment_factor,
5944 px_new_formula_factor => l_asset_fin_rec_new.formula_factor,
5945 p_log_level_rec => p_log_level_rec)) then
5946 if (p_log_level_rec.statement_level) then
5947 fa_debug_pkg.add(l_calling_fn, 'Error calling',
5948 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
5949 ,p_log_level_rec => p_log_level_rec);
5950 end if;
5951
5952 raise calc_failed;
5953 end if;
5954
5955 fa_amort_pvt.t_adjusted_cost(i) := l_asset_fin_rec_new.adjusted_cost;
5956 fa_amort_pvt.t_rate_adjustment_factor(i) := l_asset_fin_rec_new.rate_adjustment_factor;
5957 fa_amort_pvt.t_formula_factor(i) := l_asset_fin_rec_new.formula_factor;
5958
5962 ,p_log_level_rec => p_log_level_rec);
5959 if (p_log_level_rec.statement_level) then
5960 fa_debug_pkg.add(l_calling_fn, 'Returned values from ',
5961 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
5963 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_cost',
5964 l_asset_fin_rec_new.adjusted_cost
5965 ,p_log_level_rec => p_log_level_rec);
5966 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.rate_adjustment_factor',
5967 l_asset_fin_rec_new.rate_adjustment_factor
5968 ,p_log_level_rec => p_log_level_rec);
5969 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.formula_factor',
5970 l_asset_fin_rec_new.formula_factor
5971 ,p_log_level_rec => p_log_level_rec);
5972 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
5973 ,p_log_level_rec => p_log_level_rec);
5974 end if;
5975 else
5976 --
5977 -- Adjusted_cost and formula_factor are setup in last faxcde call so skipping
5978 -- deprn basis call should require no action
5979 --
5980 fa_amort_pvt.t_rate_adjustment_factor(i) := fa_amort_pvt.t_rate_adjustment_factor(i-1);
5981 end if;
5982
5983 --* HHIRAGA - Tracking Test
5984
5985 if (l_processed_flag) then
5986 fa_track_member_pvt.l_process_deprn_for_member := 'YES';
5987 l_processed_flag := FALSE;
5988 end if;
5989
5990 -- bug #5768759 changes start here
5991 -- bug #7268720 To avoid extra row in fa_adjustments while reclass from grp to grp.
5992 /*if (p_trans_rec.transaction_key = 'GC') and
5993 (l_current_period_counter = l_trx_period_rec.period_counter)and
5994 (p_reclass_src_dest ='SOURCE') and
5995 (i=l_count) then
5996
5997 fa_amort_pvt.t_change_in_cost(i) := fa_amort_pvt.t_change_in_cost(i) - l_change_in_cost;
5998
5999 end if; */
6000
6001 -- bug #5768759 changes end here
6002
6003 --
6004 -- Now this is current period, so don't need to run depreciation
6005 --
6006 --tk_util.debug('l_count - l_bs_ind + 1: '||to_char(l_count - l_bs_ind + 1)||':'||to_char(i));
6007
6008 if (fa_amort_pvt.t_period_counter(i) = p_period_rec.period_counter) then
6009
6010 --tk_util.debug('Exit');
6011 EXIT;
6012 end if;
6013
6014 --
6015 -- Run Depreciation if:
6016 -- - next available transaction (in table) is NOT the same period
6017 -- - This is the last transaction to recalculate which is not in
6018 -- current period.
6019 -- - This is the last trnsaction because of the limit specified
6020 -- at BULK fetch above. (Inside of following if clause, try to get
6021 -- next transaction from database and determine if depreciation needs
6022 -- to be called or not.
6023 --
6024 --tk_util.debug('l_period_rec.period_counter: '||to_char(l_period_rec.period_counter));
6025 --tk_util.debug('fa_amort_pvt.t_period_counter: '||to_char(fa_amort_pvt.t_period_counter(i)));
6026
6027 -- if (p_period_rec.period_counter <> fa_amort_pvt.t_period_counter(i)) or
6028 -- (px_asset_fin_rec_new.depreciate_flag = 'NO' or
6029 -- px_asset_fin_rec_new.disabled_flag = 'Y') then
6030
6031 if (p_period_rec.period_counter <> fa_amort_pvt.t_period_counter(i)) and
6032 (not (fa_amort_pvt.t_depreciate_flag(i) = 'NO' or
6033 nvl(px_asset_fin_rec_new.disabled_flag, 'N') = 'Y')) then
6034
6035 if (p_log_level_rec.statement_level) then
6036 fa_debug_pkg.add(l_calling_fn, 'Run Depreciation ', i
6037 ,p_log_level_rec => p_log_level_rec);
6038 fa_debug_pkg.add(l_calling_fn, 'l_period_rec.period_counter',
6039 l_period_rec.period_counter
6040 ,p_log_level_rec => p_log_level_rec);
6041 fa_debug_pkg.add(l_calling_fn, 'p_period_rec.period_counter',
6042 p_period_rec.period_counter
6043 ,p_log_level_rec => p_log_level_rec);
6044 end if;
6045
6046 -- look for next period which requires adjusted_cost reset.
6047 -- Find out the period and run depreciation a period before the
6048 -- found period. If there isn't one, run depreciation until the end
6049 l_adjusted_ind := 0;
6050
6051 --tk_util.debug('i and count: '||to_char(i)||':'||to_char(l_count));
6052
6053 --
6054 -- In case of destination asset for reclass transaction, this loop needs to find
6055 -- the period which will have t_reset_adjusted_cost_flag = 'Y' but not reflected
6056 -- yet.
6057 e := d;
6058 if (p_reclass_src_dest = 'DESTINATION') then
6059 FOR j in (i + 1)..(l_count) LOOP
6060 l_adjusted_ind := l_adjusted_ind + 1;
6061 e := e + 1;
6062
6063 --tk_util.debug('reset_adjusted_cost_flag: '||fa_amort_pvt.t_reset_adjusted_cost_flag(j));
6064 --tk_util.debug('cost(e):salvage_value(e):cip_cost(e):deprn_limit_amount(e):'||to_char(td_cost(e))||':'||to_char(td_salvage_value(e))||':'||to_char(td_cip_cost(e))||':'||to_char(td_deprn_limit_amount(e)));
6065
6066 --
6070 --
6067 -- Needed to use (e - 1) for sal and limit because delta table
6068 -- contains actual amounts for these values since there is no chagne
6069 -- in columns for these values.
6071 if (fa_amort_pvt.t_reset_adjusted_cost_flag(j) = 'Y') or
6072 (j = (l_count)) or
6073 (td_cost(e) <> 0) or
6074 ((td_salvage_value(e) - td_salvage_value(e - 1)) <> 0) or
6075 (td_cip_cost(e) <> 0) or
6076 ((td_deprn_limit_amount(e) - td_deprn_limit_amount(e - 1)) <> 0) then
6077
6078 if (fa_amort_pvt.t_period_num(j) = 1) then
6079 l_fiscal_year := fa_amort_pvt.t_fiscal_year(j) - 1;
6080 l_period_num := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
6081 else
6082 l_fiscal_year := fa_amort_pvt.t_fiscal_year(j);
6083 l_period_num := fa_amort_pvt.t_period_num(j) - 1;
6084 end if;
6085
6086 l_period_counter := fa_amort_pvt.t_period_counter(j) - 1;
6087 EXIT;
6088 end if;
6089
6090 END LOOP;
6091 else
6092 FOR j in (i + 1)..(l_count) LOOP
6093 l_adjusted_ind := l_adjusted_ind + 1;
6094
6095 --tk_util.debug('reset_adjusted_cost_flag: '||fa_amort_pvt.t_reset_adjusted_cost_flag(j));
6096
6097 if (fa_amort_pvt.t_reset_adjusted_cost_flag(j) = 'Y') or
6098 (j = (l_count)) then
6099 if (fa_amort_pvt.t_period_num(j) = 1) then
6100 l_fiscal_year := fa_amort_pvt.t_fiscal_year(j) - 1;
6101 l_period_num := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
6102 else
6103 l_fiscal_year := fa_amort_pvt.t_fiscal_year(j);
6104 l_period_num := fa_amort_pvt.t_period_num(j) - 1;
6105 end if;
6106
6107 l_period_counter := fa_amort_pvt.t_period_counter(j) - 1;
6108 EXIT;
6109 end if;
6110
6111 END LOOP;
6112 end if;
6113 --tk_util.debug('fy:pn: '||to_char(l_fiscal_year)||':'||to_char(l_period_num));
6114
6115 --
6116 -- Prepare Running Depreciation
6117 --
6118 l_dpr_in.y_begin := fa_amort_pvt.t_fiscal_year(i);
6119 l_dpr_in.p_cl_begin := fa_amort_pvt.t_period_num(i);
6120 l_dpr_in.y_end := l_fiscal_year;
6121 l_dpr_in.p_cl_end := l_period_num;
6122
6123 -- HHIRAGA set loop ended period
6124 l_old_recalc_end_fy := l_dpr_in.y_end;
6125 l_old_recalc_end_period_num := l_dpr_in.p_cl_end;
6126 --
6127
6128 if (p_log_level_rec.statement_level) then
6129 fa_debug_pkg.add(l_calling_fn, 'Depreciation starts from period of ', l_dpr_in.p_cl_begin
6130 ,p_log_level_rec => p_log_level_rec);
6131 fa_debug_pkg.add(l_calling_fn, 'and year of ', l_dpr_in.y_begin
6132 ,p_log_level_rec => p_log_level_rec);
6133 fa_debug_pkg.add(l_calling_fn, 'Depreciation will end at period of ', l_dpr_in.p_cl_end
6134 ,p_log_level_rec => p_log_level_rec);
6135 fa_debug_pkg.add(l_calling_fn, 'and year of ', l_dpr_in.y_end
6136 ,p_log_level_rec => p_log_level_rec);
6137 end if;
6138
6139 if (fa_amort_pvt.t_period_num(i) <> 1) then
6140 l_dpr_in.deprn_rounding_flag := 'ADJ';
6141 end if;
6142
6143 l_dpr_in.prior_fy_exp := l_asset_deprn_rec.prior_fy_expense;
6144 l_dpr_in.ytd_deprn := l_asset_deprn_rec.ytd_deprn;
6145 l_dpr_in.deprn_rsv := l_asset_deprn_rec.deprn_reserve;
6146 l_dpr_in.adj_cost := l_asset_fin_rec_new.adjusted_cost;
6147 l_dpr_in.eofy_reserve := l_asset_fin_rec_new.eofy_reserve;
6148 l_dpr_in.rate_adj_factor := l_asset_fin_rec_new.rate_adjustment_factor;
6149 l_dpr_in.formula_factor := l_asset_fin_rec_new.formula_factor;
6150 l_dpr_in.super_group_id := l_asset_fin_rec_new.super_group_id;
6151 --tk_util.debug('l_dpr_in.super_group_id: '||to_char(l_dpr_in.super_group_id));
6152 l_dpr_in.cost := l_asset_fin_rec_new.cost;
6153
6154 -- manual override
6155 if fa_cache_pkg.fa_deprn_override_enabled then
6156 l_dpr_in.update_override_status := TRUE;
6157 end if;
6158
6159 --
6160 -- Running Depreciation
6161 --
6162 --tk_util.debug('i: '||to_char(i));
6163
6164 if not FA_CDE_PKG.faxcde(l_dpr_in,
6165 l_dpr_arr,
6166 l_dpr_out,
6167 l_running_mode,
6168 i
6169 ,p_log_level_rec => p_log_level_rec) then
6170 if (p_log_level_rec.statement_level) then
6171 fa_debug_pkg.add(l_calling_fn, 'Error calling',
6172 'FA_CDE_PKG.faxcde'
6173 ,p_log_level_rec => p_log_level_rec);
6174 end if;
6175
6176 raise calc_failed;
6177 end if;
6178
6179 if (p_log_level_rec.statement_level) then
6183 fa_debug_pkg.add(l_calling_fn, 'l_dpr_out.new_deprn_rsv',
6180 fa_debug_pkg.add(l_calling_fn, 'l_dpr_out.new_ytd_deprn',
6181 l_dpr_out.new_ytd_deprn
6182 ,p_log_level_rec => p_log_level_rec);
6184 l_dpr_out.new_deprn_rsv
6185 ,p_log_level_rec => p_log_level_rec);
6186 end if;
6187
6188 -- manual override
6189 if fa_cache_pkg.fa_deprn_override_enabled then
6190 p_trans_rec.deprn_override_flag := l_dpr_out.deprn_override_flag;
6191 end if;
6192
6193 if (l_asset_fin_rec_new.adjusted_cost <> 0) or
6194 (l_dpr_out.new_adj_cost <> 0) then
6195 l_asset_fin_rec_new.reval_amortization_basis := l_dpr_out.new_reval_amo_basis;
6196 l_asset_deprn_rec.deprn_reserve := l_dpr_out.new_deprn_rsv;
6197 l_asset_deprn_rec.ytd_deprn := l_dpr_out.new_ytd_deprn;
6198 l_asset_deprn_rec.reval_deprn_reserve := l_dpr_out.new_reval_rsv;
6199 l_asset_fin_rec_new.adjusted_capacity := l_dpr_out.new_adj_capacity;
6200 l_asset_deprn_rec.ltd_production := l_dpr_out.new_ltd_prod;
6201 l_asset_fin_rec_new.eofy_reserve := l_dpr_out.new_eofy_reserve;
6202
6203 l_asset_deprn_rec.prior_fy_expense := l_dpr_out.new_prior_fy_exp;
6204 l_asset_deprn_rec.bonus_deprn_amount := l_dpr_out.bonus_deprn_exp;
6205 l_asset_deprn_rec.bonus_deprn_reserve := l_dpr_out.new_bonus_deprn_rsv;
6206 l_asset_deprn_rec.prior_fy_bonus_expense := l_dpr_out.new_prior_fy_bonus_exp;
6207 end if;
6208
6209 --++++++ Put adjusted cost back ++++++
6210 l_asset_fin_rec_new.adjusted_cost := l_dpr_out.new_adj_cost;
6211 l_asset_fin_rec_new.adjusted_cost := l_dpr_out.new_adj_cost;
6212
6213 l_out_deprn_exp := l_dpr_out.deprn_exp;
6214 l_out_reval_exp := l_dpr_out.reval_exp;
6215 l_out_reval_amo := l_dpr_out.reval_amo;
6216 l_out_prod := l_dpr_out.prod;
6217 l_out_ann_adj_exp := l_dpr_out.ann_adj_exp;
6218 l_out_ann_adj_reval_exp := l_dpr_out.ann_adj_reval_exp;
6219 l_out_ann_adj_reval_amo := l_dpr_out.ann_adj_reval_amo;
6220 l_out_bonus_rate_used := l_dpr_out.bonus_rate_used;
6221 l_out_full_rsv_flag := l_dpr_out.full_rsv_flag;
6222 l_out_life_comp_flag := l_dpr_out.life_comp_flag;
6223 l_out_deprn_override_flag := l_dpr_out.deprn_override_flag;
6224
6225 l_eop_rec_cost := l_asset_fin_rec_new.recoverable_cost;
6226 l_eop_sal_val := l_asset_fin_rec_new.salvage_value;
6227
6228 -- HHIRAGA
6229 --+++++++++ Call member level maintenance for tracking +++++++
6230 if nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' then
6231
6232 if not FA_TRACK_MEMBER_PVT.member_eofy_rsv(p_asset_hdr_rec => p_asset_hdr_rec,
6233 p_dpr_in => l_dpr_in,
6234 p_mrc_sob_type_code => p_mrc_sob_type_code
6235 ,p_log_level_rec => p_log_level_rec) then
6236 if (p_log_level_rec.statement_level) then
6237 fa_debug_pkg.add(l_calling_fn, 'Error calling',
6238 'FA_TRACK_MEMBER_PVT.member_eofy_rsv'
6239 ,p_log_level_rec => p_log_level_rec);
6240 end if;
6241
6242 raise calc_failed;
6243
6244 end if;
6245
6246 if (p_log_level_rec.statement_level) then
6247 fa_debug_pkg.add(l_calling_fn, '###### Copy to backup #######',
6248 fa_track_member_pvt.p_track_member_table.COUNT
6249 ,p_log_level_rec => p_log_level_rec);
6250 end if;
6251
6252 fa_debug_pkg.add(l_calling_fn, '##### bakcup table counter #####',
6253 fa_track_member_pvt.p_track_member_table_for_deprn.COUNT
6254 ,p_log_level_rec => p_log_level_rec);
6255
6256 if not FA_TRACK_MEMBER_PVT.copy_member_table(p_backup_restore => 'BACKUP',
6257 p_current_fiscal_year => l_dpr_in.y_begin,
6258 p_current_period_num => l_dpr_in.p_cl_begin
6259 ,p_log_level_rec => p_log_level_rec) then
6260 if (p_log_level_rec.statement_level) then
6261 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'COPY_MEMBER_TABLE'
6262 ,p_log_level_rec => p_log_level_rec);
6263 end if;
6264 raise calc_failed;
6265 end if;
6266 l_backup_processed_flag := TRUE;
6267
6268 if (p_log_level_rec.statement_level) then
6269 fa_debug_pkg.add(l_calling_fn, '++++ FA_TRACK_MEMBER_PVT.MEMBER_EOFY_RSV +++', '++++'
6270 ,p_log_level_rec => p_log_level_rec);
6271 fa_debug_pkg.add(l_calling_fn, 'Copied p_track_member_table to bakcup area', '++++'
6272 ,p_log_level_rec => p_log_level_rec);
6273 end if;
6274
6275 end if; -- nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE'
6276 -- End of HHIRAGA
6277
6281 fa_debug_pkg.add(' '||l_calling_fn, 'deprn_reserve', l_asset_deprn_rec.deprn_reserve
6278 if (p_log_level_rec.statement_level) then
6279 fa_debug_pkg.add(' '||l_calling_fn, 'ytd_deprn', l_asset_deprn_rec.ytd_deprn
6280 ,p_log_level_rec => p_log_level_rec);
6282 ,p_log_level_rec => p_log_level_rec);
6283 end if;
6284
6285 --tk_util.debug('l_adjusted_ind: '||to_char(l_adjusted_ind));
6286 l_bs_ind := l_bs_ind + l_adjusted_ind;
6287
6288 else
6289
6290 l_asset_deprn_rec.ytd_deprn := fa_amort_pvt.t_ytd_deprn(i);
6291 l_asset_deprn_rec.deprn_reserve := fa_amort_pvt.t_deprn_reserve(i);
6292 l_asset_deprn_rec.bonus_ytd_deprn := fa_amort_pvt.t_bonus_ytd_deprn(i);
6293 l_asset_deprn_rec.bonus_deprn_reserve := fa_amort_pvt.t_bonus_deprn_reserve(i);
6294
6295 if (p_log_level_rec.statement_level) then
6296 fa_debug_pkg.add(' '||l_calling_fn, 'Depreciation is ', 'SKIPPED'
6297 ,p_log_level_rec => p_log_level_rec);
6298 end if;
6299
6300 end if; -- (l_period_rec.period_counter <> fa_amort_pvt.t_period_counter(i)) or
6301
6302 else
6303 if (i = 1) then
6304 fa_amort_pvt.t_ytd_deprn(i) := fa_amort_pvt.t_deprn_amount(i);
6305 fa_amort_pvt.t_deprn_reserve(i) := fa_amort_pvt.t_deprn_amount(i) +
6306 fa_amort_pvt.t_reserve_adjustment_amount(i);
6307 fa_amort_pvt.t_bonus_ytd_deprn(i) := 0;
6308 fa_amort_pvt.t_bonus_deprn_reserve(i) := 0;
6309 fa_amort_pvt.t_ltd_production(i) := 0;
6310 fa_amort_pvt.t_ytd_production(i) := 0;
6311 fa_amort_pvt.t_ytd_reval_deprn_expense(i) := 0;
6312 fa_amort_pvt.t_reval_reserve(i) := 0;
6313 else
6314 if (fa_amort_pvt.t_period_num(i) = 1) then
6315 fa_amort_pvt.t_ytd_deprn(i) := fa_amort_pvt.t_deprn_amount(i);
6316 fa_amort_pvt.t_bonus_ytd_deprn(i) := 0;
6317 fa_amort_pvt.t_ytd_production(i) := 0;
6318 fa_amort_pvt.t_ytd_reval_deprn_expense(i) := 0;
6319 else
6320 fa_amort_pvt.t_ytd_deprn(i) := fa_amort_pvt.t_deprn_amount(i) +
6321 fa_amort_pvt.t_ytd_deprn(i - 1);
6322 fa_amort_pvt.t_bonus_ytd_deprn(i) := fa_amort_pvt.t_bonus_ytd_deprn(i - 1);
6323 fa_amort_pvt.t_ytd_production(i) := fa_amort_pvt.t_ltd_production(i - 1);
6324 fa_amort_pvt.t_ytd_reval_deprn_expense(i) := fa_amort_pvt.t_ytd_reval_deprn_expense(i - 1);
6325
6326 end if;
6327 --tk_util.debug('fa_amort_pvt.t_deprn_reserve(i - 1): '||to_char(fa_amort_pvt.t_deprn_reserve(i - 1)));
6328 fa_amort_pvt.t_deprn_reserve(i) := fa_amort_pvt.t_deprn_amount(i) +
6329 fa_amort_pvt.t_reserve_adjustment_amount(i) +
6330 fa_amort_pvt.t_deprn_reserve(i - 1);
6331 fa_amort_pvt.t_bonus_deprn_reserve(i) := fa_amort_pvt.t_bonus_deprn_reserve(i - 1);
6332 fa_amort_pvt.t_ltd_production(i) := fa_amort_pvt.t_ltd_production(i - 1);
6333 fa_amort_pvt.t_reval_reserve(i) := fa_amort_pvt.t_reval_reserve(i - 1);
6334
6335 end if;
6336
6337 --
6338 -- This is necessary to call FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS.
6339 --
6340 l_asset_fin_rec_new.cost := fa_amort_pvt.t_cost(i);
6341 l_asset_fin_rec_new.salvage_value := fa_amort_pvt.t_salvage_value(i);
6342 l_asset_fin_rec_new.recoverable_cost := fa_amort_pvt.t_recoverable_cost(i);
6343 l_asset_fin_rec_new.deprn_method_code := fa_amort_pvt.t_deprn_method_code(i);
6344 l_asset_fin_rec_new.life_in_months := fa_amort_pvt.t_life_in_months(i);
6345 l_asset_fin_rec_new.group_asset_id := fa_amort_pvt.t_group_asset_id(i);
6346 l_asset_fin_rec_new.depreciate_flag := fa_amort_pvt.t_depreciate_flag(i);
6347 l_asset_fin_rec_new.eofy_reserve := fa_amort_pvt.t_eofy_reserve(i);
6348 l_asset_fin_rec_new.rate_adjustment_factor := fa_amort_pvt.t_rate_adjustment_factor(i);
6349 l_asset_fin_rec_new.formula_factor := fa_amort_pvt.t_formula_factor(i);
6350 l_asset_fin_rec_new.super_group_id := fa_amort_pvt.t_super_group_id(i);
6351
6352 end if; -- (l_bs_ind <= i)
6353
6354 END LOOP; -- FOR i IN 1..l_count LOOP
6355
6356 --
6357 -- Need to reset eofy and eop rec cost and salvage value
6358 -- for deprn basis call
6359 --
6360 if (l_count > fa_cache_pkg.fazcct_record.number_per_fiscal_year) then
6361 l_eofy_rec_cost := fa_amort_pvt.t_recoverable_cost(l_count - fa_amort_pvt.t_period_num(l_count));
6362 l_eofy_sal_val := fa_amort_pvt.t_salvage_value(l_count - fa_amort_pvt.t_period_num(l_count));
6363
6364 if (l_count > 1) then
6365 l_eop_rec_cost := fa_amort_pvt.t_recoverable_cost(l_count - 1);
6366 l_eop_sal_val := fa_amort_pvt.t_salvage_value(l_count - 1);
6367 end if;
6368 end if;
6369
6370 -- Call Depreciable Basis Rule for Formula/NBV Basis
6371 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
6372 (p_event_type => 'AMORT_ADJ3',
6373 p_asset_fin_rec_new => l_asset_fin_rec_new,
6374 p_asset_fin_rec_old => l_asset_fin_rec_new,
6378 p_trans_rec => p_trans_rec,
6375 p_asset_hdr_rec => p_asset_hdr_rec,
6376 p_asset_type_rec => p_asset_type_rec,
6377 p_asset_deprn_rec => l_asset_deprn_rec,
6379 p_period_rec => l_period_rec,
6380 p_adjusted_cost => l_asset_fin_rec_new.adjusted_cost,
6381 p_current_total_rsv => l_asset_deprn_rec.deprn_reserve,
6382 p_adj_reserve => p_asset_deprn_rec_adj.deprn_reserve,
6383 p_current_rsv => l_asset_deprn_rec.deprn_reserve -
6384 l_asset_deprn_rec.bonus_deprn_reserve,
6385 p_current_total_ytd => l_asset_deprn_rec.ytd_deprn,
6386 p_hyp_basis => l_asset_fin_rec_new.adjusted_cost,
6387 p_hyp_total_rsv => l_asset_deprn_rec_raf.deprn_reserve,
6388 p_hyp_rsv => l_asset_deprn_rec_raf.deprn_reserve -
6389 l_asset_deprn_rec_raf.bonus_deprn_reserve,
6390 p_eofy_recoverable_cost => l_eofy_rec_cost,
6391 p_eop_recoverable_cost => l_eop_rec_cost,
6392 p_eofy_salvage_value => l_eofy_sal_val,
6393 p_eop_salvage_value => l_eop_sal_val,
6394 p_mrc_sob_type_code => p_mrc_sob_type_code,
6395 p_used_by_adjustment => 'ADJUSTMENT',
6396 px_new_adjusted_cost => l_asset_fin_rec_new.adjusted_cost,
6397 px_new_raf => l_asset_fin_rec_new.rate_adjustment_factor,
6398 px_new_formula_factor => l_asset_fin_rec_new.formula_factor
6399 ,p_log_level_rec => p_log_level_rec)) then
6400 if (p_log_level_rec.statement_level) then
6401 fa_debug_pkg.add(l_calling_fn, 'Error calling',
6402 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
6403 ,p_log_level_rec => p_log_level_rec);
6404 end if;
6405
6406 raise calc_failed;
6407 end if; -- (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
6408
6409 if (p_log_level_rec.statement_level) then
6410 fa_debug_pkg.add(l_calling_fn, 'Returned values from ',
6411 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS AMORT_ADJ3'
6412 ,p_log_level_rec => p_log_level_rec);
6413 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_cost',
6414 l_asset_fin_rec_new.adjusted_cost
6415 ,p_log_level_rec => p_log_level_rec);
6416 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.rate_adjustment_factor',
6417 l_asset_fin_rec_new.rate_adjustment_factor
6418 ,p_log_level_rec => p_log_level_rec);
6419 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.formula_factor',
6420 l_asset_fin_rec_new.formula_factor
6421 ,p_log_level_rec => p_log_level_rec);
6422 end if;
6423
6424 px_asset_fin_rec_new.cost := fa_amort_pvt.t_cost(l_count);
6425 px_asset_fin_rec_new.recoverable_cost:= fa_amort_pvt.t_recoverable_cost(l_count);
6426 px_asset_fin_rec_new.adjusted_recoverable_cost:=
6427 fa_amort_pvt.t_adjusted_recoverable_cost(l_count);
6428 px_asset_fin_rec_new.salvage_value := fa_amort_pvt.t_salvage_value(l_count);
6429 px_asset_fin_rec_new.allowed_deprn_limit_amount :=
6430 fa_amort_pvt.t_allowed_deprn_limit_amount(l_count);
6431 px_asset_fin_rec_new.percent_salvage_value := fa_amort_pvt.t_percent_salvage_value(l_count);
6432 px_asset_fin_rec_new.allowed_deprn_limit := fa_amort_pvt.t_allowed_deprn_limit(l_count);
6433
6434 -- For now, this won't be touched.
6435 -- px_asset_fin_rec_new.unrevalued_cost := fa_amort_pvt.t_unrevalued_cost(l_count);
6436
6437 px_asset_fin_rec_new.production_capacity := fa_amort_pvt.t_production_capacity(l_count);
6438 px_asset_fin_rec_new.reval_ceiling := fa_amort_pvt.t_reval_ceiling(l_count);
6439 -- px_asset_fin_rec_new.adjusted_cost := fa_amort_pvt.t_adjusted_cost(l_count);
6440 px_asset_fin_rec_new.adjusted_cost := l_asset_fin_rec_new.adjusted_cost;
6441 -- px_asset_fin_rec_new.rate_adjustment_factor := fa_amort_pvt.t_rate_adjustment_factor(l_count);
6442 px_asset_fin_rec_new.rate_adjustment_factor := l_asset_fin_rec_new.rate_adjustment_factor;
6443 px_asset_fin_rec_new.reval_amortization_basis :=
6444 fa_amort_pvt.t_reval_amortization_basis(l_count);
6445 px_asset_fin_rec_new.adjusted_capacity := fa_amort_pvt.t_adjusted_capacity(l_count);
6446 -- px_asset_fin_rec_new.formula_factor := fa_amort_pvt.t_formula_factor(l_count);
6447 px_asset_fin_rec_new.formula_factor := l_asset_fin_rec_new.formula_factor;
6448 px_asset_fin_rec_new.eofy_reserve := fa_amort_pvt.t_eofy_reserve(l_count);
6449
6450 --
6451 -- When returning catch up expenses, amounts in p_asset_deprn_rec_adj need to be
6452 -- excluded because it was included at beginning to find correct catchup but
6453 -- these amounts cannot be expensed in this period.
6454 --
6455 -- if (px_asset_fin_rec_new.depreciate_flag = 'NO') or
6456 -- (px_asset_fin_rec_new.disabled_flag = 'Y') then
6457 if (px_asset_fin_rec_new.disabled_flag = 'Y') then
6458 x_deprn_expense := 0;
6459 x_bonus_expense := 0;
6460 else
6461
6462 if --(p_reclass_src_dest = 'DESTINATION') and
6466 else
6463 (l_asset_deprn_rec.deprn_reserve = p_asset_deprn_rec.deprn_reserve) then
6464 x_deprn_expense := l_asset_deprn_rec.deprn_reserve -
6465 p_asset_deprn_rec.deprn_reserve;
6467 x_deprn_expense := l_asset_deprn_rec.deprn_reserve -
6468 --fa_amort_pvt.t_deprn_reserve(fa_amort_pvt.t_cost.LAST) -
6469 p_asset_deprn_rec.deprn_reserve -
6470 nvl(p_asset_deprn_rec_adj.deprn_reserve, 0) - x_deprn_reserve;
6471 end if;
6472
6473 x_bonus_expense := l_asset_deprn_rec.bonus_deprn_reserve -
6474 p_asset_deprn_rec.bonus_deprn_reserve -
6475 nvl(p_asset_deprn_rec_adj.bonus_deprn_reserve, 0);
6476 end if;
6477
6478 if (p_log_level_rec.statement_level) then
6479 fa_debug_pkg.add(l_calling_fn, 'x_deprn_reserve', x_deprn_reserve
6480 ,p_log_level_rec => p_log_level_rec);
6481 fa_debug_pkg.add(l_calling_fn, 'l_asset_deprn_rec.deprn_reserve', l_asset_deprn_rec.deprn_reserve
6482 ,p_log_level_rec => p_log_level_rec);
6483 fa_debug_pkg.add(l_calling_fn, 'p_asset_deprn_rec.deprn_reserve', p_asset_deprn_rec.deprn_reserve
6484 ,p_log_level_rec => p_log_level_rec);
6485 fa_debug_pkg.add(l_calling_fn, 'p_asset_deprn_rec_adj.deprn_reserve', p_asset_deprn_rec_adj.deprn_reserve
6486 ,p_log_level_rec => p_log_level_rec);
6487 fa_debug_pkg.add(l_calling_fn, 'fa_amort_pvt.t_deprn_reserve('||to_char(l_count)||')',
6488 fa_amort_pvt.t_deprn_reserve(l_count));
6489 end if;
6490
6491 -- HHIRAGA
6492 --+++++++++ Call member level maintenance for tracking +++++++
6493 if nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' then
6494
6495 if not FA_TRACK_MEMBER_PVT.update_member_books(p_trans_rec=> p_trans_rec,
6496 p_asset_hdr_rec => p_asset_hdr_rec,
6497 p_dpr_in => l_dpr_in,
6498 p_mrc_sob_type_code => p_mrc_sob_type_code
6499 ,p_log_level_rec => p_log_level_rec) then
6500 if (p_log_level_rec.statement_level) then
6501 fa_debug_pkg.add(l_calling_fn, 'Error calling',
6502 'FA_TRACK_MEMBER_PVT.update_member_books'
6503 ,p_log_level_rec => p_log_level_rec);
6504 end if;
6505
6506 raise calc_failed;
6507 end if;
6508
6509 fa_track_member_pvt.p_track_member_eofy_table.delete;
6510
6511 if (p_log_level_rec.statement_level) then
6512 fa_debug_pkg.add(l_calling_fn, 'fa_track_member_pvt.p_track_member_eofy_table',
6513 'deleted'
6514 ,p_log_level_rec => p_log_level_rec);
6515 end if;
6516 -- HHIRAGA debug
6517 for i in 1.. fa_track_member_pvt.p_track_member_table.count loop
6518 fa_debug_pkg.add('HH DEBUG**', 'all records in p_track_member_table', i
6519 ,p_log_level_rec => p_log_level_rec);
6520 if not fa_track_member_pvt.display_debug_message2(i, 'HH DEBUG**') then
6521 null;
6522 end if;
6523 end loop;
6524
6525 end if; -- nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE'
6526 -- End of HHIRAGA
6527 -- HHIRAGA
6528 --+++++++++ Call member level maintenance for tracking +++++++
6529 if nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' then
6530
6531 if not FA_TRACK_MEMBER_PVT.create_update_bs_table(p_trans_rec => p_trans_rec,
6532 p_book_type_code => p_asset_hdr_rec.book_type_code,
6533 p_group_asset_id => p_asset_hdr_rec.asset_id,
6534 p_calling_fn => l_calling_fn
6535 ,p_log_level_rec => p_log_level_rec) then
6536 if (p_log_level_rec.statement_level) then
6537 fa_debug_pkg.add(l_calling_fn, 'Error calling',
6538 'FA_TRACK_MEMBER_PVT.create_update_bs_table'
6539 ,p_log_level_rec => p_log_level_rec);
6540 end if;
6541
6542 raise calc_failed;
6543 end if;
6544
6545 end if; -- nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE'
6546 -- End of HHIRAGA
6547
6548 if (p_update_books_summary) then
6549 --
6550 -- Update FA_BOOKS_SUMMARY
6551 --
6552 --tk_util.debug('period# : cost: chcost: msal: exp: ytd: rsv: rsv');
6553 --tk_util.debug('period# : cost: adjcost: exp: eofy: rsvaj: rsv: dlmt: arec');
6554 /*
6555 for i in fa_amort_pvt.t_cost.FIRST..fa_amort_pvt.t_cost.LAST loop
6556 --tk_util.debug(rpad(to_char(fa_amort_pvt.t_period_counter(i)), 8, ' ')||':'||
6557 lpad(to_char(fa_amort_pvt.t_cost(i)), 10, ' ')||':'||
6558 -- lpad(substrb(to_char(fa_amort_pvt.t_rate_adjustment_factor(i)), 1, 10), 10, ' ')||':'||
6559 -- fa_amort_pvt.t_reset_adjusted_cost_flag(i)||':'||
6560 -- lpad(to_char(fa_amort_pvt.t_change_in_cost(i)), 10, ' ')||':'||
6561 lpad(to_char(fa_amort_pvt.t_adjusted_cost(i)), 10, ' ')||':'||
6562 -- lpad(to_char(fa_amort_pvt.t_salvage_value(i)), 10, ' ')||':'||
6563 -- lpad(to_char(fa_amort_pvt.t_member_salvage_value(i)), 10, ' ')||':'||
6564 -- lpad(to_char(fa_amort_pvt.t_deprn_adjustment_amount(i)), 10, ' ')||':'||
6565 lpad(to_char(fa_amort_pvt.t_deprn_amount(i)), 10, ' ')||':'||
6569 lpad(to_char(fa_amort_pvt.t_deprn_reserve(i)), 10, ' ')||':'||
6566 lpad(to_char(fa_amort_pvt.t_ytd_deprn(i)), 10, ' ')||':'||
6567 -- lpad(to_char(fa_amort_pvt.t_eofy_reserve(i)), 10, ' ')||':'||
6568 lpad(to_char(fa_amort_pvt.t_reserve_adjustment_amount(i)), 10, ' ')||':'||
6570 -- lpad(nvl(to_char(fa_amort_pvt.t_allowed_deprn_limit_amount(i)), 'null'), 5, ' ')||':'||
6571 lpad(to_char(fa_amort_pvt.t_adjusted_recoverable_cost(i)), 10, ' ')
6572 );
6573 end loop;
6574 */
6575 if (p_mrc_sob_type_code = 'R') then
6576 FORALL i in l_temp_ind..fa_amort_pvt.t_cost.LAST
6577 UPDATE FA_BOOKS_SUMMARY_MRC_V
6578 SET RESET_ADJUSTED_COST_FLAG = fa_amort_pvt.t_reset_adjusted_cost_flag(i)
6579 , CHANGE_IN_COST = fa_amort_pvt.t_change_in_cost(i)
6580 , CHANGE_IN_CIP_COST = fa_amort_pvt.t_change_in_cip_cost(i)
6581 , COST = fa_amort_pvt.t_cost(i)
6582 , CIP_COST = fa_amort_pvt.t_cip_cost(i)
6583 , SALVAGE_TYPE = fa_amort_pvt.t_salvage_type(i)
6584 , PERCENT_SALVAGE_VALUE = fa_amort_pvt.t_percent_salvage_value(i)
6585 , SALVAGE_VALUE = fa_amort_pvt.t_salvage_value(i)
6586 , MEMBER_SALVAGE_VALUE = fa_amort_pvt.t_member_salvage_value(i)
6587 , RECOVERABLE_COST = fa_amort_pvt.t_recoverable_cost(i)
6588 , DEPRN_LIMIT_TYPE = fa_amort_pvt.t_deprn_limit_type(i)
6589 , ALLOWED_DEPRN_LIMIT = fa_amort_pvt.t_allowed_deprn_limit(i)
6590 , ALLOWED_DEPRN_LIMIT_AMOUNT = fa_amort_pvt.t_allowed_deprn_limit_amount(i)
6591 , MEMBER_DEPRN_LIMIT_AMOUNT = fa_amort_pvt.t_member_deprn_limit_amount(i)
6592 , ADJUSTED_RECOVERABLE_COST = fa_amort_pvt.t_adjusted_recoverable_cost(i)
6593 , ADJUSTED_COST = fa_amort_pvt.t_adjusted_cost(i)
6594 , DEPRECIATE_FLAG = fa_amort_pvt.t_depreciate_flag(i)
6595 , DEPRN_METHOD_CODE = fa_amort_pvt.t_deprn_method_code(i)
6596 , LIFE_IN_MONTHS = fa_amort_pvt.t_life_in_months(i)
6597 , RATE_ADJUSTMENT_FACTOR = fa_amort_pvt.t_rate_adjustment_factor(i)
6598 , ADJUSTED_RATE = fa_amort_pvt.t_adjusted_rate(i)
6599 , BONUS_RULE = fa_amort_pvt.t_bonus_rule(i)
6600 , ADJUSTED_CAPACITY = fa_amort_pvt.t_adjusted_capacity(i)
6601 , PRODUCTION_CAPACITY = fa_amort_pvt.t_production_capacity(i)
6602 , UNIT_OF_MEASURE = fa_amort_pvt.t_unit_of_measure(i)
6603 , REMAINING_LIFE1 = fa_amort_pvt.t_remaining_life1(i)
6604 , REMAINING_LIFE2 = fa_amort_pvt.t_remaining_life2(i)
6605 , FORMULA_FACTOR = fa_amort_pvt.t_formula_factor(i)
6606 , UNREVALUED_COST = fa_amort_pvt.t_unrevalued_cost(i)
6607 , REVAL_AMORTIZATION_BASIS = fa_amort_pvt.t_reval_amortization_basis(i)
6608 , REVAL_CEILING = fa_amort_pvt.t_reval_ceiling(i)
6609 , CEILING_NAME = fa_amort_pvt.t_ceiling_name(i)
6610 , EOFY_ADJ_COST = fa_amort_pvt.t_eofy_adj_cost(i)
6611 , EOFY_FORMULA_FACTOR = fa_amort_pvt.t_eofy_formula_factor(i)
6612 , EOFY_RESERVE = fa_amort_pvt.t_eofy_reserve(i)
6613 , EOP_ADJ_COST = fa_amort_pvt.t_eop_adj_cost(i)
6614 , EOP_FORMULA_FACTOR = fa_amort_pvt.t_eop_formula_factor(i)
6615 , SHORT_FISCAL_YEAR_FLAG = fa_amort_pvt.t_short_fiscal_year_flag(i)
6616 , GROUP_ASSET_ID = fa_amort_pvt.t_group_asset_id(i)
6617 , SUPER_GROUP_ID = fa_amort_pvt.t_super_group_id(i)
6618 , OVER_DEPRECIATE_OPTION = fa_amort_pvt.t_over_depreciate_option(i)
6619 , DEPRN_AMOUNT = fa_amort_pvt.t_deprn_amount(i)
6620 , YTD_DEPRN = fa_amort_pvt.t_ytd_deprn(i)
6621 , DEPRN_RESERVE = fa_amort_pvt.t_deprn_reserve(i)
6622 , BONUS_DEPRN_AMOUNT = fa_amort_pvt.t_bonus_deprn_amount(i)
6623 , BONUS_YTD_DEPRN = fa_amort_pvt.t_bonus_ytd_deprn(i)
6624 , BONUS_DEPRN_RESERVE = fa_amort_pvt.t_bonus_deprn_reserve(i)
6625 , BONUS_RATE = fa_amort_pvt.t_bonus_rate(i)
6626 , LTD_PRODUCTION = fa_amort_pvt.t_ltd_production(i)
6627 , YTD_PRODUCTION = fa_amort_pvt.t_ytd_production(i)
6628 , PRODUCTION = fa_amort_pvt.t_production(i)
6629 , REVAL_AMORTIZATION = fa_amort_pvt.t_reval_amortization(i)
6630 , REVAL_DEPRN_EXPENSE = fa_amort_pvt.t_reval_deprn_expense(i)
6631 , REVAL_RESERVE = fa_amort_pvt.t_reval_reserve(i)
6632 , YTD_REVAL_DEPRN_EXPENSE = fa_amort_pvt.t_ytd_reval_deprn_expense(i)
6633 , DEPRN_OVERRIDE_FLAG = fa_amort_pvt.t_deprn_override_flag(i)
6634 , SYSTEM_DEPRN_AMOUNT = fa_amort_pvt.t_system_deprn_amount(i)
6635 , SYSTEM_BONUS_DEPRN_AMOUNT = fa_amort_pvt.t_system_bonus_deprn_amount(i)
6636 , YTD_PROCEEDS_OF_SALE = fa_amort_pvt.t_ytd_proceeds_of_sale(i)
6637 , LTD_PROCEEDS_OF_SALE = fa_amort_pvt.t_ltd_proceeds_of_sale(i)
6641 , EXPENSE_ADJUSTMENT_AMOUNT = fa_amort_pvt.t_expense_adjustment_amount(i)
6638 , YTD_COST_OF_REMOVAL = fa_amort_pvt.t_ytd_cost_of_removal(i)
6639 , LTD_COST_OF_REMOVAL = fa_amort_pvt.t_ltd_cost_of_removal(i)
6640 , DEPRN_ADJUSTMENT_AMOUNT = fa_amort_pvt.t_deprn_adjustment_amount(i)
6642 , RESERVE_ADJUSTMENT_AMOUNT = fa_amort_pvt.t_reserve_adjustment_amount(i)
6643 , CHANGE_IN_EOFY_RESERVE = fa_amort_pvt.t_change_in_eofy_reserve(i)
6644 , LAST_UPDATE_DATE = p_trans_rec.who_info.last_update_date
6645 , LAST_UPDATED_BY = p_trans_rec.who_info.last_updated_by
6646 , LAST_UPDATE_LOGIN = p_trans_rec.who_info.last_update_login
6647 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
6648 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
6649 AND PERIOD_COUNTER = fa_amort_pvt.t_period_counter(i);
6650
6651 else
6652 FORALL i in l_temp_ind..fa_amort_pvt.t_cost.LAST
6653 UPDATE FA_BOOKS_SUMMARY
6654 SET RESET_ADJUSTED_COST_FLAG = fa_amort_pvt.t_reset_adjusted_cost_flag(i)
6655 , CHANGE_IN_COST = fa_amort_pvt.t_change_in_cost(i)
6656 , CHANGE_IN_CIP_COST = fa_amort_pvt.t_change_in_cip_cost(i)
6657 , COST = fa_amort_pvt.t_cost(i)
6658 , CIP_COST = fa_amort_pvt.t_cip_cost(i)
6659 , SALVAGE_TYPE = fa_amort_pvt.t_salvage_type(i)
6660 , PERCENT_SALVAGE_VALUE = fa_amort_pvt.t_percent_salvage_value(i)
6661 , SALVAGE_VALUE = fa_amort_pvt.t_salvage_value(i)
6662 , MEMBER_SALVAGE_VALUE = fa_amort_pvt.t_member_salvage_value(i)
6663 , RECOVERABLE_COST = fa_amort_pvt.t_recoverable_cost(i)
6664 , DEPRN_LIMIT_TYPE = fa_amort_pvt.t_deprn_limit_type(i)
6665 , ALLOWED_DEPRN_LIMIT = fa_amort_pvt.t_allowed_deprn_limit(i)
6666 , ALLOWED_DEPRN_LIMIT_AMOUNT = fa_amort_pvt.t_allowed_deprn_limit_amount(i)
6667 , MEMBER_DEPRN_LIMIT_AMOUNT = fa_amort_pvt.t_member_deprn_limit_amount(i)
6668 , ADJUSTED_RECOVERABLE_COST = fa_amort_pvt.t_adjusted_recoverable_cost(i)
6669 , ADJUSTED_COST = fa_amort_pvt.t_adjusted_cost(i)
6670 , DEPRECIATE_FLAG = fa_amort_pvt.t_depreciate_flag(i)
6671 , DEPRN_METHOD_CODE = fa_amort_pvt.t_deprn_method_code(i)
6672 , LIFE_IN_MONTHS = fa_amort_pvt.t_life_in_months(i)
6673 , RATE_ADJUSTMENT_FACTOR = fa_amort_pvt.t_rate_adjustment_factor(i)
6674 , ADJUSTED_RATE = fa_amort_pvt.t_adjusted_rate(i)
6675 , BONUS_RULE = fa_amort_pvt.t_bonus_rule(i)
6676 , ADJUSTED_CAPACITY = fa_amort_pvt.t_adjusted_capacity(i)
6677 , PRODUCTION_CAPACITY = fa_amort_pvt.t_production_capacity(i)
6678 , UNIT_OF_MEASURE = fa_amort_pvt.t_unit_of_measure(i)
6679 , REMAINING_LIFE1 = fa_amort_pvt.t_remaining_life1(i)
6680 , REMAINING_LIFE2 = fa_amort_pvt.t_remaining_life2(i)
6681 , FORMULA_FACTOR = fa_amort_pvt.t_formula_factor(i)
6682 , UNREVALUED_COST = fa_amort_pvt.t_unrevalued_cost(i)
6683 , REVAL_AMORTIZATION_BASIS = fa_amort_pvt.t_reval_amortization_basis(i)
6684 , REVAL_CEILING = fa_amort_pvt.t_reval_ceiling(i)
6685 , CEILING_NAME = fa_amort_pvt.t_ceiling_name(i)
6686 , EOFY_ADJ_COST = fa_amort_pvt.t_eofy_adj_cost(i)
6687 , EOFY_FORMULA_FACTOR = fa_amort_pvt.t_eofy_formula_factor(i)
6688 , EOFY_RESERVE = fa_amort_pvt.t_eofy_reserve(i)
6689 , EOP_ADJ_COST = fa_amort_pvt.t_eop_adj_cost(i)
6690 , EOP_FORMULA_FACTOR = fa_amort_pvt.t_eop_formula_factor(i)
6691 , SHORT_FISCAL_YEAR_FLAG = fa_amort_pvt.t_short_fiscal_year_flag(i)
6692 , GROUP_ASSET_ID = fa_amort_pvt.t_group_asset_id(i)
6693 , SUPER_GROUP_ID = fa_amort_pvt.t_super_group_id(i)
6694 , OVER_DEPRECIATE_OPTION = fa_amort_pvt.t_over_depreciate_option(i)
6695 , DEPRN_AMOUNT = fa_amort_pvt.t_deprn_amount(i)
6696 , YTD_DEPRN = fa_amort_pvt.t_ytd_deprn(i)
6697 , DEPRN_RESERVE = fa_amort_pvt.t_deprn_reserve(i)
6698 , BONUS_DEPRN_AMOUNT = fa_amort_pvt.t_bonus_deprn_amount(i)
6699 , BONUS_YTD_DEPRN = fa_amort_pvt.t_bonus_ytd_deprn(i)
6700 , BONUS_DEPRN_RESERVE = fa_amort_pvt.t_bonus_deprn_reserve(i)
6701 , BONUS_RATE = fa_amort_pvt.t_bonus_rate(i)
6702 , LTD_PRODUCTION = fa_amort_pvt.t_ltd_production(i)
6703 , YTD_PRODUCTION = fa_amort_pvt.t_ytd_production(i)
6704 , PRODUCTION = fa_amort_pvt.t_production(i)
6705 , REVAL_AMORTIZATION = fa_amort_pvt.t_reval_amortization(i)
6706 , REVAL_DEPRN_EXPENSE = fa_amort_pvt.t_reval_deprn_expense(i)
6707 , REVAL_RESERVE = fa_amort_pvt.t_reval_reserve(i)
6711 , SYSTEM_BONUS_DEPRN_AMOUNT = fa_amort_pvt.t_system_bonus_deprn_amount(i)
6708 , YTD_REVAL_DEPRN_EXPENSE = fa_amort_pvt.t_ytd_reval_deprn_expense(i)
6709 , DEPRN_OVERRIDE_FLAG = fa_amort_pvt.t_deprn_override_flag(i)
6710 , SYSTEM_DEPRN_AMOUNT = fa_amort_pvt.t_system_deprn_amount(i)
6712 , YTD_PROCEEDS_OF_SALE = fa_amort_pvt.t_ytd_proceeds_of_sale(i)
6713 , LTD_PROCEEDS_OF_SALE = fa_amort_pvt.t_ltd_proceeds_of_sale(i)
6714 , YTD_COST_OF_REMOVAL = fa_amort_pvt.t_ytd_cost_of_removal(i)
6715 , LTD_COST_OF_REMOVAL = fa_amort_pvt.t_ltd_cost_of_removal(i)
6716 , DEPRN_ADJUSTMENT_AMOUNT = fa_amort_pvt.t_deprn_adjustment_amount(i)
6717 , EXPENSE_ADJUSTMENT_AMOUNT = fa_amort_pvt.t_expense_adjustment_amount(i)
6718 , RESERVE_ADJUSTMENT_AMOUNT = fa_amort_pvt.t_reserve_adjustment_amount(i)
6719 , CHANGE_IN_EOFY_RESERVE = fa_amort_pvt.t_change_in_eofy_reserve(i)
6720 , LAST_UPDATE_DATE = p_trans_rec.who_info.last_update_date
6721 , LAST_UPDATED_BY = p_trans_rec.who_info.last_updated_by
6722 , LAST_UPDATE_LOGIN = p_trans_rec.who_info.last_update_login
6723 WHERE ASSET_ID = p_asset_hdr_rec.asset_id
6724 AND BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
6725 AND PERIOD_COUNTER = fa_amort_pvt.t_period_counter(i);
6726 end if;
6727
6728 end if; -- (p_update_books_summary)
6729
6730 --
6731 -- Initialize global variables
6732 --
6733 InitGlobeVariables;
6734
6735 if (p_log_level_rec.statement_level) then
6736 fa_debug_pkg.add(l_calling_fn, 'End',
6737 x_deprn_expense||':'||x_bonus_expense||':'||x_deprn_reserve
6738 ,p_log_level_rec => p_log_level_rec);
6739 end if;
6740
6741 return true;
6742
6743 EXCEPTION
6744 WHEN invalid_trx_to_overlap THEN
6745 --
6746 -- Initialize global variables
6747 --
6748 InitGlobeVariables;
6749
6750 if (p_log_level_rec.statement_level) then
6751 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'invalid_trx_to_overlap'
6752 ,p_log_level_rec => p_log_level_rec);
6753 end if;
6754
6755 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6756 name => 'FA_INVALID_TRX_TO_OVERLAP'
6757 ,p_log_level_rec => p_log_level_rec);
6758 return false;
6759 WHEN calc_failed THEN
6760 --
6761 -- Initialize global variables
6762 --
6763 InitGlobeVariables;
6764
6765 if (p_log_level_rec.statement_level) then
6766 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'calc_failed'
6767 ,p_log_level_rec => p_log_level_rec);
6768 end if;
6769
6770 fa_srvr_msg.add_message(calling_fn => l_calling_fn
6771 ,p_log_level_rec => p_log_level_rec);
6772 return false;
6773
6774 WHEN OTHERS THEN
6775 --
6776 -- Initialize global variables
6777 --
6778 InitGlobeVariables;
6779
6780 if (p_log_level_rec.statement_level) then
6781 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
6782 ,p_log_level_rec => p_log_level_rec);
6783 end if;
6784
6785 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
6786 ,p_log_level_rec => p_log_level_rec);
6787 raise;
6788 END bsRecalculate;
6789
6790 --+==============================================================================
6791 -- Procedure: populate_fin_rec
6792 --
6793 -- This procedure popualte asset_fin_rec_adj in case it is not provided.
6794 --
6795 --+==============================================================================
6796 PROCEDURE populate_fin_rec(
6797 p_trans_rec FA_API_TYPES.trans_rec_type,
6798 p_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type,
6799 p_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type default null,
6800 p_asset_fin_rec_new FA_API_TYPES.asset_fin_rec_type,
6801 x_asset_fin_rec_adj OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
6802 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) IS
6803
6804 BEGIN
6805 /*
6806 if (nvl(p_asset_fin_rec_old.cost, 0) = nvl(p_asset_fin_rec_new.cost, 0) and
6807 p_asset_fin_rec_adj.cost is null) and
6808 (nvl(p_asset_fin_rec_old.cip_cost, 0) = nvl(p_asset_fin_rec_new.cip_cost, 0) and
6809 p_asset_fin_rec_adj.cip_cost is null) and
6810 (nvl(p_asset_fin_rec_old.salvage_type, 'NULL') = nvl(p_asset_fin_rec_new.salvage_type, 'NULL') and
6811 p_asset_fin_rec_adj.salvage_type is NULL) and
6812 (p_asset_fin_rec_adj.percent_salvage_value is null) and
6813 (nvl(p_asset_fin_rec_old.salvage_value, 0) = nvl(p_asset_fin_rec_new.salvage_value, 0) and
6814 p_asset_fin_rec_adj.salvage_value is null) and
6815 (p_asset_fin_rec_adj.recoverable_cost is null) and
6816 (p_asset_fin_rec_adj.adjusted_recoverable_cost is null) and
6817 (nvl(p_asset_fin_rec_old.deprn_limit_type, 'NULL') = nvl(p_asset_fin_rec_new.deprn_limit_type, 'NULL') and
6818 p_asset_fin_rec_adj.deprn_limit_type is null) and
6819 (p_asset_fin_rec_adj.allowed_deprn_limit is null) and
6823 (p_asset_fin_rec_adj.reval_ceiling is null) and
6820 (nvl(p_asset_fin_rec_old.allowed_deprn_limit_amount, 0) = nvl(p_asset_fin_rec_new.allowed_deprn_limit_amount, 0) and
6821 p_asset_fin_rec_adj.allowed_deprn_limit_amount is null) and
6822 (p_asset_fin_rec_adj.production_capacity is null) and
6824 (p_asset_fin_rec_adj.unrevalued_cost is null) and
6825 (p_asset_fin_rec_adj.deprn_method_code is null) and
6826 (p_asset_fin_rec_adj.basic_rate is null) and
6827 (p_asset_fin_rec_adj.adjusted_rate is null) and
6828 (p_asset_fin_rec_adj.life_in_months is null) and
6829 (p_asset_fin_rec_adj.date_placed_in_service is null) and
6830 (p_asset_fin_rec_adj.prorate_date is null) and
6831 (p_asset_fin_rec_adj.bonus_rule is null) then
6832 */
6833 if (p_asset_fin_rec_adj.cost is null) and
6834 (p_asset_fin_rec_adj.cip_cost is null) and
6835 (p_asset_fin_rec_adj.salvage_type is null) and
6836 (p_asset_fin_rec_adj.percent_salvage_value is null) and
6837 (p_asset_fin_rec_adj.salvage_value is null) and
6838 (p_asset_fin_rec_adj.recoverable_cost is null) and
6839 (p_asset_fin_rec_adj.adjusted_recoverable_cost is null) and
6840 (p_asset_fin_rec_adj.deprn_limit_type is null) and
6841 (p_asset_fin_rec_adj.allowed_deprn_limit is null) and
6842 (p_asset_fin_rec_adj.allowed_deprn_limit_amount is null) and
6843 (p_asset_fin_rec_adj.production_capacity is null) and
6844 (p_asset_fin_rec_adj.reval_ceiling is null) and
6845 (p_asset_fin_rec_adj.unrevalued_cost is null) and
6846 (p_asset_fin_rec_adj.deprn_method_code is null) and
6847 (p_asset_fin_rec_adj.basic_rate is null) and
6848 (p_asset_fin_rec_adj.adjusted_rate is null) and
6849 (p_asset_fin_rec_adj.life_in_months is null) and
6850 (p_asset_fin_rec_adj.date_placed_in_service is null) and
6851 (p_asset_fin_rec_adj.prorate_date is null) and
6852 (p_asset_fin_rec_adj.bonus_rule is null) then
6853 --tk_util.debug('Fin Adj is NULL!!!!!!');
6854 x_asset_fin_rec_adj := p_asset_fin_rec_new;
6855
6856 if p_trans_rec.transaction_type_code <> 'ADDITION' then
6857
6858 if (p_asset_fin_rec_adj.cost is not null) then
6859 x_asset_fin_rec_adj.cost :=p_asset_fin_rec_adj.cost;
6860 else
6861 x_asset_fin_rec_adj.cost := nvl(p_asset_fin_rec_new.cost, 0) -
6862 nvl(p_asset_fin_rec_old.cost, 0);
6863 end if;
6864
6865 if (p_asset_fin_rec_adj.cip_cost is not null) then
6866 x_asset_fin_rec_adj.cip_cost := p_asset_fin_rec_adj.cip_cost;
6867 elsif (p_asset_fin_rec_new.cip_cost is not null) then
6868 x_asset_fin_rec_adj.cip_cost := nvl(p_asset_fin_rec_new.cip_cost, 0) -
6869 nvl(p_asset_fin_rec_old.cip_cost, 0);
6870 end if;
6871
6872 if (p_asset_fin_rec_adj.salvage_value is not null) then
6873 x_asset_fin_rec_adj.salvage_value := p_asset_fin_rec_adj.salvage_value;
6874 elsif (p_asset_fin_rec_new.salvage_value is not null) then
6875 x_asset_fin_rec_adj.salvage_value := nvl(p_asset_fin_rec_new.salvage_value, 0) -
6876 nvl(p_asset_fin_rec_old.salvage_value, 0);
6877 end if;
6878
6879 if (p_asset_fin_rec_adj.recoverable_cost is not null) then
6880 x_asset_fin_rec_adj.recoverable_cost :=
6881 p_asset_fin_rec_adj.recoverable_cost;
6882 elsif (p_asset_fin_rec_new.recoverable_cost is not null) then
6883 x_asset_fin_rec_adj.recoverable_cost :=
6884 nvl(p_asset_fin_rec_new.recoverable_cost, 0) -
6885 nvl(p_asset_fin_rec_old.recoverable_cost, 0);
6886 end if;
6887
6888 if (p_asset_fin_rec_adj.adjusted_recoverable_cost is not null) then
6889 x_asset_fin_rec_adj.adjusted_recoverable_cost :=
6890 p_asset_fin_rec_adj.adjusted_recoverable_cost;
6891 elsif (p_asset_fin_rec_new.adjusted_recoverable_cost is not null) then
6892 x_asset_fin_rec_adj.adjusted_recoverable_cost :=
6893 nvl(p_asset_fin_rec_new.adjusted_recoverable_cost, 0) -
6894 nvl(p_asset_fin_rec_old.adjusted_recoverable_cost, 0);
6895 end if;
6896
6897 if (p_asset_fin_rec_adj.original_cost is not null) then
6898 x_asset_fin_rec_adj.original_cost := p_asset_fin_rec_adj.original_cost;
6899 elsif (p_asset_fin_rec_new.original_cost is not null) then
6900 x_asset_fin_rec_adj.original_cost := nvl(p_asset_fin_rec_new.original_cost, 0) -
6901 nvl(p_asset_fin_rec_old.original_cost, 0);
6902 end if;
6903
6904 if (p_asset_fin_rec_adj.production_capacity is not null) then
6905 x_asset_fin_rec_adj.production_capacity :=
6906 p_asset_fin_rec_adj.production_capacity;
6907 elsif (p_asset_fin_rec_new.production_capacity is not null) then
6908 x_asset_fin_rec_adj.production_capacity :=
6909 nvl(p_asset_fin_rec_new.production_capacity, 0) -
6910 nvl(p_asset_fin_rec_old.production_capacity, 0);
6911 end if;
6912
6913 if (p_asset_fin_rec_adj.reval_ceiling is not null) then
6914 x_asset_fin_rec_adj.reval_ceiling :=
6915 p_asset_fin_rec_adj.reval_ceiling;
6916 elsif (p_asset_fin_rec_new.reval_ceiling is not null) then
6920 end if;
6917 x_asset_fin_rec_adj.reval_ceiling :=
6918 nvl(p_asset_fin_rec_new.reval_ceiling, 0) -
6919 nvl(p_asset_fin_rec_old.reval_ceiling, 0);
6921
6922
6923 if (p_asset_fin_rec_adj.unrevalued_cost is not null) then
6924 x_asset_fin_rec_adj.unrevalued_cost :=
6925 p_asset_fin_rec_adj.unrevalued_cost;
6926 elsif (p_asset_fin_rec_new.unrevalued_cost is not null) then
6927 x_asset_fin_rec_adj.unrevalued_cost :=
6928 nvl(p_asset_fin_rec_new.unrevalued_cost, 0) -
6929 nvl(p_asset_fin_rec_old.unrevalued_cost, 0);
6930 end if;
6931
6932 if (p_asset_fin_rec_new.salvage_type = 'PCT') then
6933 x_asset_fin_rec_adj.percent_salvage_value := nvl(p_asset_fin_rec_new.percent_salvage_value, 0) -
6934 nvl(p_asset_fin_rec_old.percent_salvage_value, 0);
6935 else
6936 x_asset_fin_rec_adj.percent_salvage_value := to_number(null);
6937 end if;
6938
6939 if (x_asset_fin_rec_adj.deprn_limit_type = 'NONE') then
6940 x_asset_fin_rec_adj.deprn_limit_type := 'NONE';
6941 x_asset_fin_rec_adj.allowed_deprn_limit := to_number(null);
6942 x_asset_fin_rec_adj.allowed_deprn_limit_amount := to_number(null);
6943 elsif (p_asset_fin_rec_new.deprn_limit_type <>
6944 p_asset_fin_rec_old.deprn_limit_type) then
6945 x_asset_fin_rec_adj.deprn_limit_type := p_asset_fin_rec_new.deprn_limit_type;
6946 x_asset_fin_rec_adj.allowed_deprn_limit := p_asset_fin_rec_new.allowed_deprn_limit;
6947 x_asset_fin_rec_adj.allowed_deprn_limit_amount :=
6948 p_asset_fin_rec_new.allowed_deprn_limit_amount;
6949 else
6950 x_asset_fin_rec_adj.allowed_deprn_limit := p_asset_fin_rec_new.allowed_deprn_limit -
6951 p_asset_fin_rec_old.allowed_deprn_limit;
6952 x_asset_fin_rec_adj.allowed_deprn_limit_amount :=
6953 p_asset_fin_rec_new.allowed_deprn_limit_amount -
6954 p_asset_fin_rec_old.allowed_deprn_limit_amount;
6955 end if;
6956
6957 end if;
6958
6959 x_asset_fin_rec_adj.eofy_reserve := null;
6960
6961 if p_asset_fin_rec_old.deprn_method_code = p_asset_fin_rec_new.deprn_method_code and
6962 nvl(p_asset_fin_rec_old.life_in_months, 0) =
6963 nvl(p_asset_fin_rec_new.life_in_months, 0) and
6964 nvl(p_asset_fin_rec_old.basic_rate, 0) =
6965 nvl(p_asset_fin_rec_new.basic_rate, 0) and
6966 nvl(p_asset_fin_rec_old.adjusted_rate, 0) =
6967 nvl(p_asset_fin_rec_new.adjusted_rate, 0) and
6968 nvl(p_asset_fin_rec_old.production_capacity, 0) =
6969 nvl(p_asset_fin_rec_new.production_capacity, 0) and
6970 p_trans_rec.transaction_type_code <> 'ADDITION' then
6971
6972 x_asset_fin_rec_adj.deprn_method_code := null;
6973 x_asset_fin_rec_adj.life_in_months := to_number(null);
6974 x_asset_fin_rec_adj.basic_rate := to_number(null);
6975 x_asset_fin_rec_adj.adjusted_rate := to_number(null);
6976 x_asset_fin_rec_adj.production_capacity := to_number(null);
6977 end if;
6978
6979 else
6980 --tk_util.debug('Fin Adj is NOT null');
6981 x_asset_fin_rec_adj := p_asset_fin_rec_adj;
6982
6983 -- Bug3041716
6984 -- New faxama is expecting delta information so method information only needs to
6985 -- be populated only if there is a change in method related values
6986 --
6987 if p_asset_fin_rec_old.deprn_method_code = p_asset_fin_rec_new.deprn_method_code and
6988 nvl(p_asset_fin_rec_old.life_in_months, 0) =
6989 nvl(p_asset_fin_rec_new.life_in_months, 0) and
6990 nvl(p_asset_fin_rec_old.basic_rate, 0) =
6991 nvl(p_asset_fin_rec_new.basic_rate, 0) and
6992 nvl(p_asset_fin_rec_old.adjusted_rate, 0) =
6993 nvl(p_asset_fin_rec_new.adjusted_rate, 0) and
6994 nvl(p_asset_fin_rec_old.production_capacity, 0) =
6995 nvl(p_asset_fin_rec_new.production_capacity, 0) then
6996
6997 x_asset_fin_rec_adj.deprn_method_code := null;
6998 x_asset_fin_rec_adj.life_in_months := to_number(null);
6999 x_asset_fin_rec_adj.basic_rate := to_number(null);
7000 x_asset_fin_rec_adj.adjusted_rate := to_number(null);
7001 x_asset_fin_rec_adj.production_capacity := to_number(null);
7002 end if;
7003
7004 end if;
7005
7006
7007
7008 END populate_fin_rec;
7009
7010 ---------------------------------------------------------------------------
7011
7012 FUNCTION faxama
7013 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
7014 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
7015 p_asset_desc_rec FA_API_TYPES.asset_desc_rec_type,
7016 p_asset_cat_rec FA_API_TYPES.asset_cat_rec_type,
7017 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
7018 p_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type,
7019 p_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type default null,
7020 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
7024 p_mrc_sob_type_code VARCHAR2,
7021 p_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type,
7022 p_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type default null,
7023 p_period_rec FA_API_TYPES.period_rec_type,
7025 p_running_mode NUMBER,
7026 p_used_by_revaluation NUMBER,
7027 p_reclassed_asset_id NUMBER default null,
7028 p_reclass_src_dest VARCHAR2 default null,
7029 p_group_reclass_type VARCHAR2 default null, -- Bug : 6792185
7030 p_reclassed_asset_dpis DATE default null,
7031 p_update_books_summary BOOLEAN default FALSE,
7032 p_proceeds_of_sale NUMBER default 0,
7033 p_cost_of_removal NUMBER default 0,
7034 x_deprn_exp OUT NOCOPY NUMBER,
7035 x_bonus_deprn_exp OUT NOCOPY NUMBER,
7036 x_deprn_rsv OUT NOCOPY NUMBER,
7037 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return boolean IS
7038
7039 l_calling_fn varchar2(50) := 'newFA_AMORT_PVT.faxama';
7040 l_reval_deprn_rsv_adj number :=0;
7041 l_afn_zero number:=0;
7042
7043 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
7044
7045 -- Bug4958977: Adding following cursor and 2 new variables
7046 CURSOR c_check_dpis_change is
7047 select inbk.transaction_header_id_in
7048 from fa_books inbk
7049 , fa_books outbk
7050 where inbk.transaction_header_id_in = px_trans_rec.member_transaction_header_id
7051 and outbk.asset_id = inbk.asset_id
7052 and outbk.book_type_code = p_asset_hdr_rec.book_type_code
7053 and outbk.transaction_header_id_out = px_trans_rec.member_transaction_header_id
7054 and inbk.cost = outbk.cost
7055 and nvl(inbk.salvage_value, 0) = nvl(outbk.salvage_value, 0)
7056 and nvl(inbk.allowed_deprn_limit_amount, 0) = nvl(outbk.allowed_deprn_limit_amount, 0)
7057 and inbk.date_placed_in_service <> outbk.date_placed_in_service;
7058
7059 l_temp_thid NUMBER;
7060 l_call_bs BOOLEAN := FALSE;
7061
7062 l_valid_type_change BOOLEAN := TRUE; -- bug5149789
7063
7064 calc_err EXCEPTION;
7065
7066 /*
7067 err number;
7068
7069 cursor c_get_profiler is
7070 select runid,
7071 run_date,
7072 run_comment
7073 from plsql_profiler_runs;
7074 */
7075
7076 begin <<faxama>>
7077 --tk_util.debug('-');
7078 --tk_util.debug('-');
7079 --tk_util.debug('-');
7080 --tk_util.debug('-+++++-');
7081 if (p_log_level_rec.statement_level) then
7082 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_type_rec.asset_type||':'||
7083 p_asset_hdr_rec.asset_id||':'||
7084 to_char(px_trans_rec.transaction_header_id));
7085
7086 end if;
7087
7088
7089 -- err:=DBMS_PROFILER.START_PROFILER ('faxama:'||to_char(sysdate,'dd-Mon-YYYY hh:mi:ss'));
7090
7091 X_deprn_exp := 0;
7092 X_bonus_deprn_exp := 0;
7093
7094 if (p_asset_type_rec.asset_type='CIP') then
7095 FA_SRVR_MSG.ADD_MESSAGE
7096 (CALLING_FN => 'FA_AMORT_PKG.faxama',
7097 NAME => 'FA_AMT_CIP_NOT_ALLOWED',
7098 TOKEN1 => 'TYPE',
7099 VALUE1 => 'Amortized',
7100 p_log_level_rec => p_log_level_rec);
7101 return FALSE;
7102 end if;
7103
7104 --tk_util.DumpTrxRec(px_trans_rec, 'px_trans_rec');
7105 --tk_util.DumpFinRec(p_asset_fin_rec_old, 'old fin_rec');
7106 --tk_util.DumpFinRec(p_asset_fin_rec_adj, 'adj fin_rec');
7107 --tk_util.DumpFinRec(px_asset_fin_rec_new, 'new_fin_rec');
7108 --tk_util.DumpDeprnRec(p_asset_deprn_rec, 'old deprn');
7109 --tk_util.DumpDeprnRec(p_asset_deprn_rec_adj, 'adj deprn');
7110
7111 -- Bug5149789: checking whether member exists or not
7112 -- Call function check_member_existence if either of
7113 -- salvage or deprn limit type is being changed and there is 0 group cost
7114 if (((px_asset_fin_rec_new.salvage_type = 'SUM') and
7115 (px_asset_fin_rec_new.salvage_type <> nvl(p_asset_fin_rec_old.salvage_type,
7116 px_asset_fin_rec_new.salvage_type))) or
7117 ((px_asset_fin_rec_new.deprn_limit_type = 'SUM') and
7118 (px_asset_fin_rec_new.deprn_limit_type <> nvl(p_asset_fin_rec_old.deprn_limit_type,
7119 px_asset_fin_rec_new.deprn_limit_type)))) then
7120
7121 if (px_asset_fin_rec_new.cost = 0) then
7122
7123 if not check_member_existence (p_asset_hdr_rec => p_asset_hdr_rec) then
7124 if (p_log_level_rec.statement_level) then
7125 fa_debug_pkg.add(l_calling_fn, 'calling check_member_existence',
7126 'FAILED', p_log_level_rec);
7127 end if;
7128
7129 l_valid_type_change := FALSE;
7130
7131 end if;
7132
7133 else
7134 if (p_log_level_rec.statement_level) then
7135 fa_debug_pkg.add(l_calling_fn, 'Method.deprn_limit type change',
7136 'FAILED', p_log_level_rec);
7140
7137 fa_debug_pkg.add(l_calling_fn, 'cost',
7138 px_asset_fin_rec_new.cost, p_log_level_rec);
7139 end if;
7141 l_valid_type_change := FALSE;
7142
7143 end if;
7144
7145 if (not l_valid_type_change) then
7146 if (px_asset_fin_rec_new.salvage_type = 'SUM') then
7147 fa_srvr_msg.add_message(
7148 calling_fn => l_calling_fn,
7149 name => 'FA_INVALID_PARAMETER',
7150 token1 => 'VALUE',
7151 value1 => px_asset_fin_rec_new.salvage_type,
7152 token2 => 'PARAM',
7153 value2 => 'SALVAGE_TYPE',
7154 p_log_level_rec => p_log_level_rec);
7155
7156 else
7157 fa_srvr_msg.add_message(
7158 calling_fn => l_calling_fn,
7159 name => 'FA_INVALID_PARAMETER',
7160 token1 => 'VALUE',
7161 value1 => px_asset_fin_rec_new.deprn_limit_type,
7162 token2 => 'PARAM',
7163 value2 => 'DEPRN_LIMIT_TYPE',
7164 p_log_level_rec => p_log_level_rec);
7165 end if;
7166
7167 return false;
7168 end if;
7169
7170 end if; -- (((px_asset_fin_rec_new.salvage_type = 'SUM') and
7171
7172 if ((px_trans_rec.transaction_type_code = 'GROUP ADDITION' and
7173 nvl(p_asset_deprn_rec.deprn_reserve, 0) = 0) and
7174 (px_trans_rec.transaction_key not in( 'MA','MJ','MC','MV','MD','MN'))
7175 and (px_asset_fin_rec_new.cost = 0 and px_asset_fin_rec_new.cip_cost = 0) -- Necessary??
7176 -- Bug 5501090: Need to call createGroup for dpis change also.
7177 or ( px_trans_rec.transaction_type_code = 'GROUP ADJUSTMENT' and
7178 px_trans_rec.transaction_key = 'GJ' and
7179 p_asset_fin_rec_old.date_placed_in_service <> px_asset_fin_rec_new.date_placed_in_service))
7180 then
7181 -- Group Addition or adjustment in period of group addition before
7182 -- depreciation run or first member addition
7183
7184 if not createGroup(
7185 p_trans_rec => px_trans_rec,
7186 p_asset_hdr_rec => p_asset_hdr_rec,
7187 p_asset_type_rec => p_asset_type_rec,
7188 p_period_rec => p_period_rec,
7189 p_asset_fin_rec => px_asset_fin_rec_new,
7190 p_asset_deprn_rec => p_asset_deprn_rec_adj,
7191 p_mrc_sob_type_code => p_mrc_sob_type_code,
7192 p_calling_fn => l_calling_fn
7193 ,p_log_level_rec => p_log_level_rec) then
7194
7195 if (p_log_level_rec.statement_level) then
7196 fa_debug_pkg.add('calc_fin_info', 'calling FA_AMORT_PVT.createGroup', 'FAILED'
7197 ,p_log_level_rec => p_log_level_rec);
7198 end if;
7199
7200 return (FALSE);
7201
7202 end if;
7203
7204 return true;
7205 elsif (px_trans_rec.transaction_type_code = 'ADDITION' or
7206 px_trans_rec.transaction_type_code = 'CIP ADDITION' or
7207 px_trans_rec.transaction_type_code = 'ADJUSTMENT' or
7208 px_trans_rec.transaction_type_code = 'CIP ADJUSTMENT') and
7209 (p_asset_fin_rec_old.group_asset_id is not null or
7210 px_asset_fin_rec_new.group_asset_id is not null)
7211 and (nvl(px_trans_rec.amortization_start_date,
7212 px_trans_rec.transaction_date_entered) <
7213 p_period_rec.calendar_period_open_date)
7214 then
7215 -- Member addition and adjustment that has impact to the group
7216
7217 if (p_log_level_rec.statement_level) then
7218 fa_debug_pkg.add('calc_fin_info', 'calling FA_AMORT_PVT.maintainGroup', 'FAILED'
7219 ,p_log_level_rec => p_log_level_rec);
7220 end if;
7221
7222 end if;
7223
7224
7225 populate_fin_rec(
7226 p_trans_rec => px_trans_rec,
7227 p_asset_fin_rec_old => p_asset_fin_rec_old,
7228 p_asset_fin_rec_adj => p_asset_fin_rec_adj,
7229 p_asset_fin_rec_new => px_asset_fin_rec_new,
7230 x_asset_fin_rec_adj => l_asset_fin_rec_adj
7231 ,p_log_level_rec => p_log_level_rec);
7232
7233 -- Bug4958977: Adding following entire if statement
7234 -- trx could be dpis change if following conditions are met
7235 -- even though trx date is in current period
7236 --tk_util.DumpFinRec(p_asset_fin_rec_adj, 'adj fin_rec');
7237 if (px_trans_rec.transaction_key = 'MJ' and
7238 nvl(p_asset_fin_rec_adj.cost, 0) = 0 and
7239 nvl(p_asset_fin_rec_adj.cip_cost, 0) = 0 and
7240 nvl(p_asset_fin_rec_adj.salvage_value, 0) = 0 and
7241 nvl(p_asset_fin_rec_adj.allowed_deprn_limit_amount, 0) = 0) and
7242 (nvl(px_trans_rec.amortization_start_date,
7243 px_trans_rec.transaction_date_entered) >=
7244 p_period_rec.calendar_period_open_date) then
7245
7246 if (p_log_level_rec.statement_level) then
7247 fa_debug_pkg.add(l_calling_fn, 'could be dpis change', 'cont', p_log_level_rec);
7248 end if;
7249
7250 OPEN c_check_dpis_change;
7251 FETCH c_check_dpis_change INTO l_temp_thid;
7252 CLOSE c_check_dpis_change;
7253
7254 if (p_log_level_rec.statement_level) then
7255 fa_debug_pkg.add(l_calling_fn, 'temp_thid', l_temp_thid, p_log_level_rec);
7256 end if;
7260 else
7257
7258 if (l_temp_thid is not null) then
7259 l_call_bs := TRUE;
7261 l_call_bs := FALSE;
7262 end if;
7263 end if;
7264
7265 -- Bug4037112: Change for ATT 0 cost change
7266 X_deprn_rsv := 0;
7267
7268 if (not l_call_bs) and
7269 (px_trans_rec.transaction_type_code = 'GROUP ADJUSTMENT') and
7270 (nvl(px_asset_fin_rec_new.tracking_method, 'NULL') <> 'CALCULATE') and
7271 (nvl(l_asset_fin_rec_adj.cost, 0) = 0) and
7272 ((px_trans_rec.transaction_key = 'MA')
7273 or
7274 (px_trans_rec.transaction_key = 'MJ' and
7275 (px_asset_fin_rec_new.salvage_type not in ('SUM', 'AMT')) and
7276 (px_asset_fin_rec_new.deprn_limit_type not in ('SUM', 'AMT')))
7277 ) then
7278
7279 -- Bug4958977: Need to check possibility of dpis change.
7280 -- This time, possible that dpis is changed from current to old
7281 -- date.
7282 if (p_log_level_rec.statement_level) then
7283 fa_debug_pkg.add(l_calling_fn, 'could be dpis change(cur to old)', 'cont', p_log_level_rec);
7284 end if;
7285
7286 OPEN c_check_dpis_change;
7287 FETCH c_check_dpis_change INTO l_temp_thid;
7288 CLOSE c_check_dpis_change;
7289
7290 if (p_log_level_rec.statement_level) then
7291 fa_debug_pkg.add(l_calling_fn, 'temp_thid', l_temp_thid, p_log_level_rec);
7292 end if;
7293
7294 if (l_temp_thid is not null) then
7295 l_call_bs := TRUE;
7296 else
7297 l_call_bs := FALSE;
7298 end if;
7299
7300 if (not l_call_bs) then
7301 -- No Need to Maintain FA_BOOKS_SUMMARY Table
7302 return true;
7303 end if;
7304 end if;
7305
7306
7307 if (p_asset_type_rec.asset_type = 'GROUP') then
7308 if (nvl(px_trans_rec.amortization_start_date,
7309 px_trans_rec.transaction_date_entered) >=
7310 p_period_rec.calendar_period_open_date) and
7311 (px_trans_rec.transaction_key not in ('MR', 'MS', 'GC')) and (not l_call_bs) then
7312
7313 if (not CurrentPeriodAdj(
7314 p_trans_rec => px_trans_rec,
7315 p_asset_hdr_rec => p_asset_hdr_rec,
7316 p_asset_type_rec => p_asset_type_rec,
7317 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
7318 p_asset_fin_rec_old => p_asset_fin_rec_old,
7319 px_asset_fin_rec_new => px_asset_fin_rec_new,
7320 p_period_rec => p_period_rec,
7321 p_asset_deprn_rec_adj => p_asset_deprn_rec_adj,
7322 p_proceeds_of_sale => nvl(p_proceeds_of_sale, 0),
7323 p_cost_of_removal => nvl(p_cost_of_removal, 0),
7324 p_calling_fn => l_calling_fn,
7325 p_mrc_sob_type_code => p_mrc_sob_type_code)) then
7326 raise calc_err;
7327 end if;
7328
7329 else
7330
7331 if (l_asset_fin_rec_adj.eofy_reserve is null) and
7332 (p_asset_deprn_rec_adj.deprn_reserve is not null) and
7333 (p_asset_deprn_rec_adj.ytd_deprn is not null) then
7334 l_asset_fin_rec_adj.eofy_reserve :=
7335 p_asset_deprn_rec_adj.deprn_reserve - p_asset_deprn_rec_adj.ytd_deprn;
7336 end if;
7337
7338
7339 if (not bsRecalculate(
7340 p_trans_rec => px_trans_rec,
7341 p_asset_hdr_rec => p_asset_hdr_rec,
7342 p_asset_type_rec => p_asset_type_rec,
7343 p_asset_desc_rec => p_asset_desc_rec,
7344 p_asset_fin_rec_old => p_asset_fin_rec_old,
7345 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
7346 p_period_rec => p_period_rec,
7347 px_asset_fin_rec_new => px_asset_fin_rec_new,
7348 p_asset_deprn_rec => p_asset_deprn_rec,
7349 p_asset_deprn_rec_adj => p_asset_deprn_rec_adj,
7350 x_deprn_expense => x_deprn_exp,
7351 x_bonus_expense => x_bonus_deprn_exp,
7352 x_deprn_reserve => x_deprn_rsv,
7353 p_running_mode => p_running_mode,
7354 p_used_by_revaluation => p_used_by_revaluation,
7355 p_reclassed_asset_id => p_reclassed_asset_id,
7356 p_reclass_src_dest => p_reclass_src_dest,
7357 p_group_reclass_type => p_group_reclass_type, -- Bug : 6792185
7358 p_reclassed_asset_dpis => p_reclassed_asset_dpis,
7359 p_update_books_summary => p_update_books_summary,
7360 p_mrc_sob_type_code => p_mrc_sob_type_code,
7361 p_calling_fn => l_calling_fn
7362 ,p_log_level_rec => p_log_level_rec)) then
7363 raise calc_err;
7364 end if;
7365 end if; -- (nvl(px_trans_rec.amortization_start_date,
7366 end if; -- (p_asset_type_rec.asset_type = 'GROUP')
7367
7368 --tk_util.DumpFinRec(px_asset_fin_rec_new, 'Nfaxama');
7369
7370 if (p_log_level_rec.statement_level) then
7371 fa_debug_pkg.add(l_calling_fn, 'End', p_asset_type_rec.asset_type||':'||p_asset_hdr_rec.asset_id
7372 ,p_log_level_rec => p_log_level_rec);
7373 end if;
7374 --tk_util.debug('-+++++-');
7375 --tk_util.debug('-');
7379 --tk_util.debug('-');
7376 --tk_util.debug('-');
7377 --tk_util.debug('-');
7378 --tk_util.debug('-');
7380
7381 -- err:=DBMS_PROFILER.STOP_PROFILER;
7382
7383 /*
7384 for r_get_profiler in c_get_profiler loop
7385 null;
7386 --tk_util.debug('runid: '||to_char(r_get_profiler.runid));
7387 --tk_util.debug('run_date: '||to_char(r_get_profiler.run_date, 'DD-MON-YYYY HH24:MI:SS'));
7388 --tk_util.debug('run_comment: '||r_get_profiler.run_comment);
7389 end loop;
7390 */
7391
7392 return TRUE;
7393
7394 exception
7395 when calc_err then
7396 if (p_log_level_rec.statement_level) then
7397 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'calc_err'
7398 ,p_log_level_rec => p_log_level_rec);
7399 end if;
7400
7401 FA_SRVR_MSG.ADD_SQL_ERROR(CALLING_FN => l_calling_fn
7402 ,p_log_level_rec => p_log_level_rec);
7403 return false;
7404
7405 when others then
7406 if (p_log_level_rec.statement_level) then
7407 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
7408 ,p_log_level_rec => p_log_level_rec);
7409 end if;
7410
7411 FA_SRVR_MSG.ADD_SQL_ERROR(CALLING_FN => l_calling_fn
7412 ,p_log_level_rec => p_log_level_rec);
7413 return FALSE;
7414 end faxama;
7415
7416
7417 --+==============================================================================
7418 -- Function: GetExpRsv
7419 --
7420 -- This function return expense or reserve amounts incurred due to some
7421 -- transaction such as unplanned, reserve transfer and retirement adjustment.
7422 --
7423 -- Transaction Transaction_Key
7424 -- ---------------------- ---------------
7425 -- Retirement Adjustment GR
7426 -- Reserve Transfer GV
7427 -- Unplanned Depreciation UA or UE
7428 --
7429 --+==============================================================================
7430 FUNCTION GetExpRsv(
7431 p_trans_rec FA_API_TYPES.trans_rec_type,
7432 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
7433 p_period_rec FA_API_TYPES.period_rec_type,
7434 p_mrc_sob_type_code VARCHAR2,
7435 x_exp_rsv_amount OUT NOCOPY NUMBER,
7436 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return BOOLEAN IS
7437
7438 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.GetExpRsv';
7439
7440 --
7441 -- This cursor doesn't include period counter created as condition
7442 -- because it is not certain that prior period unplanned is allowed
7443 -- and if it is allowed, whether fa_adjsutments stores period_counter
7444 -- created as the period of amortization start date or not.
7445 -- If period counter created is the period of amortization start date,
7446 -- then period counter can be used as a one of condition.
7447 --
7448 CURSOR c_get_exp_amount IS
7449 select
7450 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7451 'EXPENSE',
7452 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7453 'DR', ADJ.ADJUSTMENT_AMOUNT,
7454 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7455 0)
7456 from fa_adjustments adj
7457 where adj.transaction_header_id = p_trans_rec.transaction_header_id
7458 and adj.asset_id = p_asset_hdr_rec.asset_id
7459 and adj.book_type_code = p_asset_hdr_rec.book_type_code;
7460
7461 CURSOR c_get_mc_exp_amount IS
7462 select
7463 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7464 'EXPENSE',
7465 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7466 'DR', ADJ.ADJUSTMENT_AMOUNT,
7467 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7468 0)
7469 from fa_adjustments_mrc_v adj
7470 where adj.transaction_header_id = p_trans_rec.transaction_header_id
7471 and adj.asset_id = p_asset_hdr_rec.asset_id
7472 and adj.book_type_code = p_asset_hdr_rec.book_type_code;
7473
7474
7475 BEGIN
7476
7477 --
7478 -- Case of Unplanned Depreciation
7479 --
7480 if (p_mrc_sob_type_code = 'R') then
7481 OPEN c_get_mc_exp_amount;
7482 FETCH c_get_mc_exp_amount INTO x_exp_rsv_amount;
7483 CLOSE c_get_mc_exp_amount;
7484 else
7485 OPEN c_get_exp_amount;
7486 FETCH c_get_exp_amount INTO x_exp_rsv_amount;
7487 CLOSE c_get_exp_amount;
7488 end if;
7489
7490 if (p_log_level_rec.statement_level) then
7491 fa_debug_pkg.add(l_calling_fn, 'Found Expense:'||p_trans_rec.transaction_key, x_exp_rsv_amount
7492 ,p_log_level_rec => p_log_level_rec);
7493 end if;
7494
7495
7496 return true;
7497
7498 EXCEPTION
7499 WHEN others THEN
7500 if (p_log_level_rec.statement_level) then
7501 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
7502 ,p_log_level_rec => p_log_level_rec);
7503 end if;
7504
7505 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
7506 ,p_log_level_rec => p_log_level_rec);
7507 return false;
7508
7509 END GetExpRsv;
7510
7511 --+==============================================================================
7512 -- Function: GetDeprnRec
7513 --
7517 --+==============================================================================
7514 -- The function returns FA_API_TYPES.asset_deprn_rec_type.
7515 -- This will be the starting point for recalculating depreciation.
7516 --
7518 FUNCTION GetDeprnRec (
7519 p_trans_rec FA_API_TYPES.trans_rec_type,
7520 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
7521 p_period_rec FA_API_TYPES.period_rec_type,
7522 p_incoming_trx_type_code VARCHAR2 default 'NULL',
7523 x_asset_deprn_rec OUT NOCOPY FA_API_TYPES.asset_deprn_rec_type,
7524 p_mrc_sob_type_code VARCHAR2,
7525 p_unplanned_exp IN OUT NOCOPY NUMBER,
7526 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
7527
7528 CURSOR c_check_period IS
7529 select 'Y'
7530 from fa_deprn_summary
7531 where asset_id = p_asset_hdr_rec.asset_id
7532 and book_type_code = p_asset_hdr_rec.book_type_code
7533 and period_counter <= p_period_rec.period_counter;
7534 /*
7535 from fa_deprn_periods
7536 where book_type_code = p_asset_hdr_rec.book_type_code
7537 and period_counter = p_period_rec.period_counter;
7538 */
7539
7540 -- Return values if year of first transaction is the same year as addition happened.
7541 CURSOR c_get_eofy_rsv IS
7542 select ds.deprn_reserve - ds.ytd_deprn
7543 , ds.bonus_deprn_reserve - ds.bonus_ytd_deprn
7544 , ds.ltd_production - ds.ytd_production
7545 , ds.reval_reserve - ds.ytd_reval_deprn_expense
7546 from fa_fiscal_year fy
7547 , fa_deprn_summary ds
7548 , fa_deprn_periods dp
7549 where ds.asset_id = p_asset_hdr_rec.asset_id
7550 and ds.book_type_code = p_asset_hdr_rec.book_type_code
7551 and ds.deprn_source_code = 'BOOKS'
7552 and dp.book_type_code = p_asset_hdr_rec.book_type_code
7553 and dp.period_counter = ds.period_counter
7554 and fy.fiscal_year_name = fa_cache_pkg.fazcbc_record.fiscal_year_name
7555 and fy.fiscal_year = (dp.period_counter - dp.period_num)/fa_cache_pkg.fazcct_record.number_per_fiscal_year
7556 and fy.fiscal_year = (p_period_rec.period_counter + 1 - p_period_rec.period_num)/
7557 fa_cache_pkg.fazcct_record.number_per_fiscal_year;
7558
7559 CURSOR c_get_adjs IS
7560 SELECT NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7561 'RESERVE',
7562 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7563 'DR', ADJ.ADJUSTMENT_AMOUNT,
7564 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7565 0),
7566 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7567 'EXPENSE',
7568 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7569 'DR', ADJ.ADJUSTMENT_AMOUNT,
7570 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7571 0),
7572 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7573 'BONUS RESERVE',
7574 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7575 'DR', ADJ.ADJUSTMENT_AMOUNT,
7576 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7577 0),
7578 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7579 'BONUS EXPENSE',
7580 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7581 'DR', ADJ.ADJUSTMENT_AMOUNT,
7582 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7583 0),
7584 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7585 'DEPRN ADJUST',
7586 DECODE(fa_cache_pkg.fazcbc_record.book_class,'TAX',
7587 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7588 'DR', ADJ.ADJUSTMENT_AMOUNT,
7589 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT)))),
7590 0),
7591 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7592 'REVAL EXPENSE',
7593 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7594 'DR', ADJ.ADJUSTMENT_AMOUNT,
7595 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7596 0),
7597 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7598 'REVAL AMORT',
7599 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7600 'DR', ADJ.ADJUSTMENT_AMOUNT,
7601 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7602 0),
7603 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7604 'REVAL RESERVE',
7605 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7606 'DR', ADJ.ADJUSTMENT_AMOUNT,
7607 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7608 0),
7609 NVL(SUM(DECODE(ADJ.SOURCE_TYPE_CODE,
7610 'REVALUATION',
7611 DECODE(ADJ.ADJUSTMENT_TYPE,
7612 'EXPENSE',
7613 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7614 'DR', ADJ.ADJUSTMENT_AMOUNT,
7615 'CR', -1*ADJ.ADJUSTMENT_AMOUNT)))), 0),
7619 'DR', ADJ.ADJUSTMENT_AMOUNT,
7616 NVL(SUM(DECODE(TH.TRANSACTION_KEY,
7617 'UE',
7618 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7620 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT),
7621 'UA',
7622 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7623 'DR', ADJ.ADJUSTMENT_AMOUNT,
7624 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT)
7625 )),
7626 0)
7627 FROM FA_ADJUSTMENTS ADJ,
7628 FA_TRANSACTION_HEADERS TH
7629 WHERE TH.ASSET_ID = p_asset_hdr_rec.asset_id
7630 AND TH.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
7631 AND TH.TRANSACTION_HEADER_ID <> p_trans_rec.transaction_header_id
7632 AND TH.TRANSACTION_DATE_ENTERED <= p_trans_rec.transaction_date_entered
7633 AND TH.DATE_EFFECTIVE < p_trans_rec.who_info.creation_date
7634 AND TH.DATE_EFFECTIVE BETWEEN nvl(p_period_rec.period_open_date, TH.DATE_EFFECTIVE)
7635 AND nvl(p_period_rec.period_close_date, TH.DATE_EFFECTIVE)
7636 AND TH.TRANSACTION_KEY not in ('UE','UA') -- bug 5585000
7637 AND TH.TRANSACTION_HEADER_ID = ADJ.TRANSACTION_HEADER_ID
7638 AND ADJ.ASSET_ID = p_asset_hdr_rec.asset_id
7639 AND ADJ.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
7640 --
7641 -- Bug3387996: next condition is nevessary to get adj amount only for this period
7642 --
7643 AND ADJ.PERIOD_COUNTER_CREATED = p_period_rec.period_counter
7644 AND ADJ.ADJUSTMENT_TYPE in ('RESERVE', 'EXPENSE');
7645
7646 CURSOR c_get_mc_adjs IS
7647 SELECT NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7648 'RESERVE',
7649 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7650 'DR', ADJ.ADJUSTMENT_AMOUNT,
7651 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7652 0),
7653 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7654 'EXPENSE',
7655 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7656 'DR', ADJ.ADJUSTMENT_AMOUNT,
7657 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7658 0),
7659 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7660 'BONUS RESERVE',
7661 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7662 'DR', ADJ.ADJUSTMENT_AMOUNT,
7663 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7664 0),
7665 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7666 'BONUS EXPENSE',
7667 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7668 'DR', ADJ.ADJUSTMENT_AMOUNT,
7669 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7670 0),
7671 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7672 'DEPRN ADJUST',
7673 DECODE(fa_cache_pkg.fazcbc_record.book_class,'TAX',
7674 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7675 'DR', ADJ.ADJUSTMENT_AMOUNT,
7676 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT)))),
7677 0),
7678 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7679 'REVAL EXPENSE',
7680 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7681 'DR', ADJ.ADJUSTMENT_AMOUNT,
7682 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7683 0),
7684 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7685 'REVAL AMORT',
7686 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7687 'DR', ADJ.ADJUSTMENT_AMOUNT,
7688 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7689 0),
7690 NVL(SUM(DECODE(ADJ.ADJUSTMENT_TYPE,
7691 'REVAL RESERVE',
7692 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7693 'DR', ADJ.ADJUSTMENT_AMOUNT,
7694 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT))),
7695 0),
7696 NVL(SUM(DECODE(ADJ.SOURCE_TYPE_CODE,
7697 'REVALUATION',
7698 DECODE(ADJ.ADJUSTMENT_TYPE,
7699 'EXPENSE',
7700 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7701 'DR', ADJ.ADJUSTMENT_AMOUNT,
7702 'CR', -1*ADJ.ADJUSTMENT_AMOUNT)))), 0),
7703 NVL(SUM(DECODE(TH.TRANSACTION_KEY,
7704 'UE',
7705 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7706 'DR', ADJ.ADJUSTMENT_AMOUNT,
7707 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT),
7708 'UA',
7709 DECODE(ADJ.DEBIT_CREDIT_FLAG,
7710 'DR', ADJ.ADJUSTMENT_AMOUNT,
7711 'CR', -1 * ADJ.ADJUSTMENT_AMOUNT)
7712 )),
7713 0)
7714 FROM FA_ADJUSTMENTS_MRC_V ADJ,
7715 FA_TRANSACTION_HEADERS TH
7719 AND TH.TRANSACTION_DATE_ENTERED <= p_trans_rec.transaction_date_entered
7716 WHERE TH.ASSET_ID = p_asset_hdr_rec.asset_id
7717 AND TH.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
7718 AND TH.TRANSACTION_HEADER_ID <> p_trans_rec.transaction_header_id
7720 AND TH.DATE_EFFECTIVE < p_trans_rec.who_info.creation_date
7721 AND TH.DATE_EFFECTIVE BETWEEN nvl(p_period_rec.period_open_date, TH.DATE_EFFECTIVE)
7722 AND nvl(p_period_rec.period_close_date, TH.DATE_EFFECTIVE)
7723 AND TH.TRANSACTION_KEY not in ('UE','UA') -- bug 5585000
7724 AND TH.TRANSACTION_HEADER_ID = ADJ.TRANSACTION_HEADER_ID
7725 AND ADJ.ASSET_ID = p_asset_hdr_rec.asset_id
7726 AND ADJ.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
7727 --
7728 -- Bug3387996: next condition is nevessary to get adj amount only for this period
7729 --
7730 AND ADJ.PERIOD_COUNTER_CREATED = p_period_rec.period_counter
7731 AND ADJ.ADJUSTMENT_TYPE in ('RESERVE', 'EXPENSE');
7732
7733
7734 l_calling_fn VARCHAR2(100) := 'FA_AMORT_PVT.GetDeprnRec';
7735 l_dpr FA_STD_TYPES.FA_DEPRN_ROW_STRUCT;
7736 l_run_mode VARCHAR2(20) := 'TRANSACTION';
7737 l_status BOOLEAN;
7738
7739 l_deprn_rsv number;
7740 l_deprn_exp number;
7741 l_bonus_deprn_rsv number;
7742 l_bonus_deprn_amount number;
7743 l_deprn_adjust_exp number;
7744 l_reval_deprn_exp number;
7745 l_reval_amo number;
7746 l_reval_rsv number;
7747 l_reval_exp number;
7748
7749 l_unplanned_exp number;
7750 l_period_exists VARCHAR2(1) := 'N';
7751 l_find_eofy_reserve VARCHAR2(1) := 'Y';
7752 error_found EXCEPTION;
7753
7754 BEGIN
7755 if (p_log_level_rec.statement_level) then
7756 fa_debug_pkg.add(l_calling_fn, 'Begin', p_trans_rec.transaction_type_code||':'||
7757 p_period_rec.period_counter
7758 ,p_log_level_rec => p_log_level_rec);
7759 end if;
7760
7761 OPEN c_check_period;
7762 FETCH c_check_period INTO l_period_exists;
7763
7764 if (c_check_period%NOTFOUND) then
7765 l_period_exists := 'N';
7766 end if;
7767
7768 CLOSE c_check_period;
7769
7770 --tk_util.debug('l_period_exists: '||l_period_exists);
7771
7772 if (l_period_exists = 'Y') and (p_incoming_trx_type_code not like '%ADDITION') then
7773
7774 l_dpr.asset_id := p_asset_hdr_rec.asset_id;
7775 l_dpr.book := p_asset_hdr_rec.book_type_code;
7776 l_dpr.period_ctr := p_period_rec.period_counter;
7777 l_dpr.dist_id := 0;
7778 l_dpr.mrc_sob_type_code := p_mrc_sob_type_code;
7779
7780 l_run_mode := 'STANDARD';
7781
7782 fa_query_balances_pkg.query_balances_int(
7783 X_DPR_ROW => l_dpr,
7784 X_RUN_MODE => l_run_mode,
7785 X_DEBUG => FALSE,
7786 X_SUCCESS => l_status,
7787 X_CALLING_FN => l_calling_fn,
7788 X_TRANSACTION_HEADER_ID => -1
7789 ,p_log_level_rec => p_log_level_rec);
7790
7791 if (NOT l_status) then
7792
7793 if (p_log_level_rec.statement_level) then
7794 fa_debug_pkg.add(l_calling_fn, 'ERROR',
7795 'Calling fa_query_balances_pkg.query_balances_int'
7796 ,p_log_level_rec => p_log_level_rec);
7797 end if;
7798
7799 raise error_found;
7800 end if;
7801
7802 -- x_asset_deprn_rec.deprn_amount := l_dpr.deprn_exp;
7803 x_asset_deprn_rec.deprn_amount := 0; -- This needs to be 0 because this should only include
7804 -- current period(period that starts recalculate) amounts
7805 x_asset_deprn_rec.ytd_deprn := l_dpr.ytd_deprn;
7806 x_asset_deprn_rec.deprn_reserve := l_dpr.deprn_rsv;
7807 x_asset_deprn_rec.prior_fy_expense := l_dpr.prior_fy_exp;
7808 -- x_asset_deprn_rec.bonus_deprn_amount := l_dpr.bonus_deprn_amount;
7809 x_asset_deprn_rec.bonus_deprn_amount := 0; -- This needs to be 0 because this should only include
7810 -- current period(period that starts recalculate) amounts
7811 x_asset_deprn_rec.bonus_ytd_deprn := l_dpr.bonus_ytd_deprn;
7812 x_asset_deprn_rec.bonus_deprn_reserve := l_dpr.bonus_deprn_rsv;
7813 x_asset_deprn_rec.prior_fy_bonus_expense := l_dpr.prior_fy_bonus_exp;
7814 x_asset_deprn_rec.reval_amortization := l_dpr.reval_amo;
7815 x_asset_deprn_rec.reval_amortization_basis := l_dpr.reval_amo_basis;
7816 x_asset_deprn_rec.reval_deprn_expense := l_dpr.reval_deprn_exp;
7817 x_asset_deprn_rec.reval_ytd_deprn := l_dpr.ytd_reval_deprn_exp;
7818 x_asset_deprn_rec.reval_deprn_reserve := l_dpr.reval_rsv;
7819 x_asset_deprn_rec.production := l_dpr.prod;
7820 x_asset_deprn_rec.ytd_production := l_dpr.ytd_prod;
7821 x_asset_deprn_rec.ltd_production := l_dpr.ltd_prod;
7822
7823 else
7824 --tk_util.debug('No deprn info in db');
7825 if (p_incoming_trx_type_code like '%ADDITION') then
7826
7830 x_asset_deprn_rec.reval_deprn_reserve := 0;
7827 x_asset_deprn_rec.deprn_reserve := 0;
7828 x_asset_deprn_rec.bonus_deprn_reserve := 0;
7829 x_asset_deprn_rec.ltd_production := 0;
7831
7832 else
7833 --tk_util.debug('Get deprn info from BOOKS row');
7834 OPEN c_get_eofy_rsv;
7835 FETCH c_get_eofy_rsv INTO x_asset_deprn_rec.deprn_reserve
7836 , x_asset_deprn_rec.bonus_deprn_reserve
7837 , x_asset_deprn_rec.ltd_production
7838 , x_asset_deprn_rec.reval_deprn_reserve;
7839
7840 if (c_get_eofy_rsv%NOTFOUND) then
7841 x_asset_deprn_rec.deprn_reserve := 0;
7842 x_asset_deprn_rec.bonus_deprn_reserve := 0;
7843 x_asset_deprn_rec.ltd_production := 0;
7844 x_asset_deprn_rec.reval_deprn_reserve := 0;
7845 end if;
7846
7847 CLOSE c_get_eofy_rsv;
7848 end if;
7849
7850 x_asset_deprn_rec.deprn_amount := 0;
7851 x_asset_deprn_rec.ytd_deprn := 0;
7852 x_asset_deprn_rec.prior_fy_expense := 0;
7853 x_asset_deprn_rec.bonus_deprn_amount := 0;
7854 x_asset_deprn_rec.bonus_ytd_deprn := 0;
7855 x_asset_deprn_rec.prior_fy_bonus_expense := 0;
7856 x_asset_deprn_rec.reval_amortization := 0;
7857 x_asset_deprn_rec.reval_amortization_basis := 0;
7858 x_asset_deprn_rec.reval_ytd_deprn := 0;
7859 x_asset_deprn_rec.reval_deprn_reserve := 0;
7860 x_asset_deprn_rec.production := 0;
7861 x_asset_deprn_rec.ytd_production := 0;
7862
7863
7864 end if;
7865 --tk_util.DumpDeprnRec(x_asset_deprn_rec, 'GDS');
7866
7867 if (p_mrc_sob_type_code = 'R') then
7868 OPEN c_get_mc_adjs;
7869 FETCH c_get_mc_adjs INTO l_deprn_rsv,
7870 l_deprn_exp,
7871 l_bonus_deprn_rsv,
7872 l_bonus_deprn_amount,
7873 l_deprn_adjust_exp,
7874 l_reval_deprn_exp,
7875 l_reval_amo,
7876 l_reval_rsv,
7877 l_reval_exp,
7878 l_unplanned_exp;
7879 CLOSE c_get_mc_adjs;
7880 else
7881 OPEN c_get_adjs;
7882 FETCH c_get_adjs INTO l_deprn_rsv,
7883 l_deprn_exp,
7884 l_bonus_deprn_rsv,
7885 l_bonus_deprn_amount,
7886 l_deprn_adjust_exp,
7887 l_reval_deprn_exp,
7888 l_reval_amo,
7889 l_reval_rsv,
7890 l_reval_exp,
7891 l_unplanned_exp;
7892 CLOSE c_get_adjs;
7893 end if;
7894
7895 if (l_deprn_exp <> 0) then
7896 x_asset_deprn_rec.deprn_amount := x_asset_deprn_rec.deprn_amount + l_deprn_exp;
7897 x_asset_deprn_rec.ytd_deprn := x_asset_deprn_rec.ytd_deprn + l_deprn_exp;
7898 x_asset_deprn_rec.deprn_reserve := x_asset_deprn_rec.deprn_reserve + l_deprn_exp -
7899 l_reval_exp;
7900 end if;
7901
7902 if (l_bonus_deprn_amount <> 0) then
7903 x_asset_deprn_rec.bonus_deprn_amount := x_asset_deprn_rec.bonus_deprn_amount +
7904 l_bonus_deprn_amount;
7905 x_asset_deprn_rec.bonus_ytd_deprn := x_asset_deprn_rec.bonus_ytd_deprn +
7906 l_bonus_deprn_amount;
7907 x_asset_deprn_rec.bonus_deprn_reserve := x_asset_deprn_rec.bonus_deprn_reserve +
7908 l_bonus_deprn_amount;
7909 end if;
7910
7911 if (l_deprn_rsv <> 0) then
7912 x_asset_deprn_rec.deprn_reserve := x_asset_deprn_rec.deprn_reserve - l_deprn_rsv;
7913 end if;
7914
7915 --tk_util.DumpDeprnRec(x_asset_deprn_rec, 'GDA');
7916
7917 p_unplanned_exp := l_unplanned_exp;
7918
7919 if (p_log_level_rec.statement_level) then
7920 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_deprn_rec.deprn_reserve
7921 ,p_log_level_rec => p_log_level_rec);
7922 end if;
7923
7924 return true;
7925
7926 EXCEPTION
7927 when error_found then
7928 if (p_log_level_rec.statement_level) then
7929 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'error_found'
7930 ,p_log_level_rec => p_log_level_rec);
7931 end if;
7932
7933 fa_srvr_msg.add_message(calling_fn => l_calling_fn
7934 ,p_log_level_rec => p_log_level_rec);
7935 return false;
7936
7937 when others then
7938 if (p_log_level_rec.statement_level) then
7939 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
7940 ,p_log_level_rec => p_log_level_rec);
7941 end if;
7942
7943 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
7944 ,p_log_level_rec => p_log_level_rec);
7945 return false;
7946
7947 END GetDeprnRec;
7948
7949 --+==============================================================================
7950 -- Function: GetEofyReserve
7951 --
7952 --+==============================================================================
7953 FUNCTION GetEofyReserve(
7957 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
7954 p_trans_rec FA_API_TYPES.trans_rec_type,
7955 p_trans_rec_cur FA_API_TYPES.trans_rec_type,
7956 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
7958 p_period_rec FA_API_TYPES.period_rec_type,
7959 x_eofy_reserve OUT NOCOPY NUMBER,
7960 x_transaction_header_id OUT NOCOPY NUMBER,
7961 x_transaction_date_entered OUT NOCOPY DATE,
7962 x_date_effective OUT NOCOPY DATE,
7963 x_transaction_type_code OUT NOCOPY VARCHAR2,
7964 p_mrc_sob_type_code VARCHAR2,
7965 p_calling_fn VARCHAR2,
7966 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return BOOLEAN IS
7967
7968 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.GetEofyReserve';
7969 get_err EXCEPTION;
7970
7971 --
7972 -- Find transaction which is
7973 -- Entered in the same fiscal year as given transaction date
7974 -- The transaction has transaction_date ealier than the fiscal year start date
7975 -- In this case, Recalculation needs to go back more to recalculate because
7976 -- it is impossible to find eofy_reserve from fa_deprn_summary
7977 CURSOR c_get_other_trx IS
7978 select th.transaction_header_id transaction_header_id,
7979 nvl(th.amortization_start_date, th.transaction_date_entered) transaction_date_entered,
7980 th.date_effective date_effective,
7981 th.transaction_type_code transaction_type_code
7982 from
7983 fa_transaction_headers th,
7984 fa_deprn_periods dp,
7985 fa_book_controls bc,
7986 fa_fiscal_year fy
7987 where th.asset_id = p_asset_hdr_rec.asset_id
7988 and th.book_type_code = p_asset_hdr_rec.book_type_code
7989 and bc.book_type_code = p_asset_hdr_rec.book_type_code
7990 and bc.fiscal_year_name = fy.fiscal_year_name
7991 and dp.book_type_code = p_asset_hdr_rec.book_type_code
7992 and dp.fiscal_year = fy.fiscal_year
7993 and dp.calendar_period_open_date = fy.start_date
7994 and p_trans_rec.transaction_date_entered
7995 between fy.start_date and end_date
7996 and th.date_effective >= dp.period_open_date
7997 and th.transaction_date_entered < dp.calendar_period_open_date
7998 and th.transaction_header_id < p_trans_rec.transaction_header_id
7999 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
8000 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
8001 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
8002 G_TRX_TYPE_TFR_VOID)
8003 and not exists (select 1
8004 from fa_deprn_summary ds
8005 , fa_deprn_periods dp2
8006 where ds.asset_id = p_asset_hdr_rec.asset_id
8007 and ds.book_type_code = p_asset_hdr_rec.book_type_code
8008 and dp.book_type_code = p_asset_hdr_rec.book_type_code
8009 and dp.fiscal_year = fy.fiscal_year
8010 and ds.period_counter = dp2.period_counter -1
8011 and ds.deprn_source_code = 'BOOKS'
8012 and ds.deprn_reserve <> 0
8013 and th.date_effective between dp2.period_open_date and dp2.period_close_date
8014 and th.transaction_type_code = G_TRX_TYPE_ADD)
8015 ;
8016
8017
8018 CURSOR c_get_ret_trx IS
8019 select nvl(sum(ret.reserve_retired), 0),
8020 nvl(sum(ret.eofy_reserve), 0)
8021 from fa_retirements ret,
8022 fa_transaction_headers mth,
8023 fa_transaction_headers gth,
8024 fa_book_controls bc,
8025 fa_fiscal_year fy
8026 where gth.asset_id = p_asset_hdr_rec.asset_id
8027 and gth.book_type_code = p_asset_hdr_rec.book_type_code
8028 and bc.book_type_code = p_asset_hdr_rec.book_type_code
8029 and bc.fiscal_year_name = fy.fiscal_year_name
8030 and ret.date_retired between fy.start_date
8031 and p_trans_rec.transaction_date_entered
8032 and gth.member_transaction_header_id = mth.transaction_header_id
8033 and mth.book_type_code = p_asset_hdr_rec.book_type_code
8034 and mth.transaction_header_id = ret.transaction_header_id_in
8035 and mth.asset_id = ret.asset_id
8036 and gth.member_transaction_header_id = ret.transaction_header_id_in
8037 and ret.book_type_code = p_asset_hdr_rec.book_type_code
8038 and ret.transaction_header_id_out is null
8039 and fy.start_date =
8040 (select fy.start_date
8041 from fa_fiscal_year fy,
8042 fa_book_controls bc
8043 where bc.book_type_code = p_asset_hdr_rec.book_type_code
8044 and bc.fiscal_year_name = fy.fiscal_year_name
8045 and fy.start_date <= p_trans_rec.transaction_date_entered
8046 and fy.end_date >= p_trans_rec.transaction_date_entered
8047 );
8048
8049 CURSOR c_get_mc_ret_trx IS
8050 select nvl(sum(ret.reserve_retired), 0),
8051 nvl(sum(ret.eofy_reserve), 0)
8052 from fa_retirements_mrc_v ret,
8053 fa_transaction_headers mth,
8057 where gth.asset_id = p_asset_hdr_rec.asset_id
8054 fa_transaction_headers gth,
8055 fa_book_controls_mrc_v bc,
8056 fa_fiscal_year fy
8058 and gth.book_type_code = p_asset_hdr_rec.book_type_code
8059 and bc.book_type_code = p_asset_hdr_rec.book_type_code
8060 and bc.fiscal_year_name = fy.fiscal_year_name
8061 and ret.date_retired between fy.start_date
8062 and p_trans_rec.transaction_date_entered
8063 and gth.member_transaction_header_id = mth.transaction_header_id
8064 and mth.book_type_code = p_asset_hdr_rec.book_type_code
8065 and mth.transaction_header_id = ret.transaction_header_id_in
8066 and mth.asset_id = ret.asset_id
8067 and gth.member_transaction_header_id = ret.transaction_header_id_in
8068 and ret.book_type_code = p_asset_hdr_rec.book_type_code
8069 and ret.transaction_header_id_out is null
8070 and fy.start_date =
8071 (select fy.start_date
8072 from fa_fiscal_year fy,
8073 fa_book_controls_mrc_v bc
8074 where bc.book_type_code = p_asset_hdr_rec.book_type_code
8075 and bc.fiscal_year_name = fy.fiscal_year_name
8076 and fy.start_date <= p_trans_rec.transaction_date_entered
8077 and fy.end_date >= p_trans_rec.transaction_date_entered
8078 );
8079
8080 CURSOR c_get_ret_trx2 IS
8081 select nvl(sum(ret.reserve_retired), 0),
8082 nvl(sum(ret.eofy_reserve), 0)
8083 from fa_retirements ret,
8084 fa_transaction_headers th,
8085 fa_book_controls bc,
8086 fa_fiscal_year fy
8087 where th.asset_id = p_asset_hdr_rec.asset_id
8088 and th.book_type_code = p_asset_hdr_rec.book_type_code
8089 and bc.book_type_code = p_asset_hdr_rec.book_type_code
8090 and bc.fiscal_year_name = fy.fiscal_year_name
8091 and ret.date_retired between fy.start_date
8092 and p_trans_rec.transaction_date_entered
8093 and th.transaction_header_id = ret.transaction_header_id_in
8094 and th.asset_id = ret.asset_id
8095 and ret.book_type_code = p_asset_hdr_rec.book_type_code
8096 and ret.transaction_header_id_out is null;
8097
8098 -- CURSOR c_get_mc_ret_trx2 IS
8099
8100 CURSOR c_get_deprn_period IS
8101 select period_counter - 1
8102 , period_open_date
8103 , period_close_date
8104 , period_num
8105 from fa_deprn_periods
8106 where book_type_code = p_asset_hdr_rec.book_type_code
8107 and p_trans_rec.transaction_date_entered between
8108 calendar_period_open_date and calendar_period_close_date;
8109
8110 -- Get the transaction before the member addition's transaction which member is reclassed
8111 -- on same fiscal year.
8112
8113 CURSOR c_get_other_trx2 IS
8114 select th.transaction_header_id transaction_header_id,
8115 nvl(th.amortization_start_date, th.transaction_date_entered) transaction_date_entered,
8116 th.date_effective date_effective,
8117 th.transaction_type_code transaction_type_code
8118 from fa_transaction_headers th
8119 where th.asset_id = p_asset_hdr_rec.asset_id
8120 and th.book_type_code = p_asset_hdr_rec.book_type_code
8121 and th.transaction_header_id =
8122 -- Get the latest trasnaction of reclassed member asset on group asset
8123 (select max(th.transaction_header_id)
8124 from fa_transaction_headers th
8125 where th.asset_id =p_asset_hdr_rec.asset_id
8126 and th.book_type_code = p_asset_hdr_rec.book_type_code
8127 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
8128 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
8129 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
8130 G_TRX_TYPE_TFR_VOID)
8131 and th.transaction_header_id <
8132 -- Get first transaction of reclassed member asset on group asset
8133 (select min(th.transaction_header_id)
8134 from fa_transaction_headers th
8135 where th.book_type_code = p_asset_hdr_rec.book_type_code
8136 and th.asset_id = p_asset_hdr_rec.asset_id
8137 and th.member_transaction_header_id in
8138 -- Get reclassed member's all transaction headers
8139 (select th.transaction_header_id
8140 from fa_transaction_headers th
8141 where th.book_type_code = p_asset_hdr_rec.book_type_code
8142 and th.asset_id in
8143 -- Get reclassed member's asset_id
8144 (select th.asset_id
8145 from fa_transaction_headers th
8146 where th.book_type_code = p_asset_hdr_rec.book_type_code
8147 and transaction_header_id in
8148 -- Get reclassed transaction after this transaction's fiscal year
8149 (select th.member_transaction_header_id
8150 from fa_transaction_headers th,
8151 fa_deprn_periods dp,
8152 fa_fiscal_year fy,
8153 fa_book_controls bc
8157 and dp.book_type_code = bc.book_type_code
8154 where th.asset_id = p_asset_hdr_rec.asset_id
8155 and th.book_type_code = p_asset_hdr_rec.book_type_code
8156 and dp.book_type_code = p_asset_hdr_rec.book_type_code
8158 and bc.fiscal_year_name = fy.fiscal_year_name
8159 and p_trans_rec.transaction_date_entered
8160 between fy.start_date and fy.end_date
8161 and dp.fiscal_year= fy.fiscal_year
8162 and dp.period_num =1
8163 and th.date_effective >= dp.period_open_date
8164 and th.trx_reference_id is not null
8165 and th.member_transaction_header_id is not null
8166 and th.transaction_header_id < p_trans_rec.transaction_header_id
8167
8168 )))));
8169
8170
8171 CURSOR c_cur_eofy_reserve IS
8172 select nvl(bk.eofy_reserve,0)
8173 from FA_BOOKS bk
8174 where asset_id = p_asset_hdr_rec.asset_id
8175 and book_type_code = p_asset_hdr_rec.book_type_code
8176 and transaction_header_id_out is null;
8177
8178
8179 l_transaction_header_id NUMBER;
8180 l_transaction_date_entered DATE;
8181 l_date_effective DATE;
8182 l_transaction_type_code VARCHAR2(30);
8183
8184 l_period_rec FA_API_TYPES.period_rec_type;
8185 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
8186
8187 l_unplanned_exp NUMBER := 0;
8188 l_reserve_retired NUMBER := 0;
8189 l_eofy_reserve_retired NUMBER := 0;
8190
8191 BEGIN
8192
8193 if (p_log_level_rec.statement_level) then
8194 fa_debug_pkg.add('====='||l_calling_fn||'=====', 'Begin', to_char(p_trans_rec.transaction_header_id)||'=====');
8195 end if;
8196
8197 if p_trans_rec_cur.transaction_header_id = p_trans_rec.transaction_header_id
8198 and p_trans_rec.transaction_date_entered between
8199 p_period_rec.calendar_period_open_date and p_period_rec.calendar_period_close_date
8200 then
8201 -- At current open period's transaction, get eofy_reserve from FA_BOOKS.
8202
8203 x_transaction_header_id := to_number(null);
8204 x_transaction_date_entered := null;
8205 x_date_effective := null;
8206
8207 OPEN c_cur_eofy_reserve;
8208 FETCH c_cur_eofy_reserve into x_eofy_reserve;
8209 CLOSE c_cur_eofy_reserve;
8210
8211 if (p_log_level_rec.statement_level) then
8212 fa_debug_pkg.add(l_calling_fn, 'Can determine current eofy reserve from db ', x_eofy_reserve
8213 ,p_log_level_rec => p_log_level_rec);
8214 end if;
8215
8216 else
8217
8218 OPEN c_get_other_trx;
8219 FETCH c_get_other_trx INTO l_transaction_header_id, l_transaction_date_entered,
8220 l_date_effective, l_transaction_type_code;
8221 --tk_util.debug('l_transaction_header_id: '||to_char(l_transaction_header_id));
8222
8223 if (c_get_other_trx%NOTFOUND) then
8224 --tk_util.debug('c_get_other_trx not found');
8225 OPEN c_get_other_trx2;
8226 FETCH c_get_other_trx2 INTO l_transaction_header_id, l_transaction_date_entered,
8227 l_date_effective, l_transaction_type_code;
8228 end if;
8229
8230 if (c_get_other_trx%NOTFOUND and c_get_other_trx2%NOTFOUND) then
8231
8232 x_transaction_header_id := to_number(null);
8233 x_transaction_date_entered := null;
8234 x_date_effective := null;
8235
8236
8237 OPEN c_get_deprn_period;
8238 FETCH c_get_deprn_period INTO l_period_rec.period_counter,
8239 l_period_rec.period_open_date,
8240 l_period_rec.period_close_date,
8241 l_period_rec.period_num;
8242
8243 if (c_get_deprn_period%NOTFOUND) then
8244 CLOSE c_get_deprn_period;
8245
8246 x_eofy_reserve := 0;
8247
8248 if (p_log_level_rec.statement_level) then
8249 fa_debug_pkg.add(l_calling_fn, 'This must be addition so eofy reserve ', x_eofy_reserve
8250 ,p_log_level_rec => p_log_level_rec);
8251 end if;
8252 else
8253 CLOSE c_get_deprn_period;
8254
8255 if not GetDeprnRec (
8256 p_trans_rec => p_trans_rec,
8257 p_asset_hdr_rec => p_asset_hdr_rec,
8258 p_period_rec => l_period_rec,
8259 x_asset_deprn_rec => l_asset_deprn_rec,
8260 p_mrc_sob_type_code => p_mrc_sob_type_code,
8261 p_unplanned_exp => l_unplanned_exp
8262 ,p_log_level_rec => p_log_level_rec) then
8263
8264 if (p_log_level_rec.statement_level) then
8265 fa_debug_pkg.add(l_calling_fn, 'Error calling',
8266 'GetDeprnRec'
8267 ,p_log_level_rec => p_log_level_rec);
8268 end if;
8269
8270 raise get_err;
8271 end if;
8272
8273 if (p_mrc_sob_type_code = 'R') then
8274 OPEN c_get_mc_ret_trx;
8278 OPEN c_get_ret_trx;
8275 FETCH c_get_mc_ret_trx INTO l_reserve_retired, l_eofy_reserve_retired;
8276 CLOSE c_get_mc_ret_trx;
8277 else
8279 FETCH c_get_ret_trx INTO l_reserve_retired, l_eofy_reserve_retired;
8280 CLOSE c_get_ret_trx;
8281 end if;
8282
8283 if (p_log_level_rec.statement_level) then
8284 fa_debug_pkg.add(l_calling_fn, 'Sum of Reserve Retired',
8285 l_reserve_retired
8286 ,p_log_level_rec => p_log_level_rec);
8287 fa_debug_pkg.add(l_calling_fn, 'Sum of Eofy Reserve Retired',
8288 l_eofy_reserve_retired
8289 ,p_log_level_rec => p_log_level_rec);
8290 end if;
8291
8292 if (l_period_rec.period_num = 1) then
8293 x_eofy_reserve := l_asset_deprn_rec.deprn_reserve
8294 + l_reserve_retired
8295 - l_eofy_reserve_retired
8296 - l_unplanned_exp;
8297 else
8298 x_eofy_reserve := l_asset_deprn_rec.deprn_reserve
8299 + l_reserve_retired
8300 - l_asset_deprn_rec.ytd_deprn
8301 - l_eofy_reserve_retired
8302 - l_unplanned_exp;
8303 end if;
8304
8305 if (p_log_level_rec.statement_level) then
8306 fa_debug_pkg.add(l_calling_fn, 'Can determine eofy reserve from db ', x_eofy_reserve
8307 ,p_log_level_rec => p_log_level_rec);
8308 end if;
8309
8310 end if;
8311
8312 else -- c_get_other_trx/2 FOUND
8313
8314 x_eofy_reserve := to_number(null);
8315 x_transaction_header_id := l_transaction_header_id;
8316 x_transaction_date_entered := l_transaction_date_entered;
8317 x_date_effective := l_date_effective;
8318 x_transaction_type_code := l_transaction_type_code;
8319
8320 if (p_log_level_rec.statement_level) then
8321 fa_debug_pkg.add(l_calling_fn, 'Need to go earlier trx',
8322 to_char(x_transaction_header_id)||':'||
8323 to_char(x_transaction_date_entered, 'DD-MON-RR HH24:MI:SS')||':'||
8324 to_char(x_date_effective, 'DD-MON-RR HH24:MI:SS'));
8325 end if;
8326
8327 end if; -- End of c_get_other_trx/2 NOTFOUND
8328
8329 CLOSE c_get_other_trx;
8330 IF c_get_other_trx2%ISOPEN then
8331 CLOSE c_get_other_trx2;
8332 end if;
8333
8334 end if; -- End of current period transaction or not
8335
8336 fa_debug_pkg.add('====='||l_calling_fn||'=====', 'End', '====='
8337 ,p_log_level_rec => p_log_level_rec);
8338
8339 return TRUE;
8340
8341 EXCEPTION
8342 WHEN get_err THEN
8343 if (p_log_level_rec.statement_level) then
8344 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'get_err'
8345 ,p_log_level_rec => p_log_level_rec);
8346 end if;
8347
8348 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
8349 ,p_log_level_rec => p_log_level_rec);
8350 return false;
8351
8352 WHEN others THEN
8353 if (p_log_level_rec.statement_level) then
8354 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
8355 ,p_log_level_rec => p_log_level_rec);
8356 end if;
8357
8358 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
8359 ,p_log_level_rec => p_log_level_rec);
8360 return false;
8361
8362 END GetEofyReserve;
8363
8364 --+==============================================================================
8365 -- Function: GetFinAdjRec
8366 --
8367 --
8368 --
8369 --
8370 --
8371 --+==============================================================================
8372 FUNCTION GetFinAdjRec(
8373 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
8374 p_reclass_src_dest VARCHAR2,
8375 p_transaction_date_entered DATE,
8376 x_asset_fin_rec_adj OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
8377 p_mrc_sob_type_code VARCHAR2,
8378 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
8379 return BOOLEAN is
8380
8381 l_calling_fn VARCHAR2(50) := 'FA_AMORT_PVT.GetFinAdjRec';
8382 get_err EXCEPTION;
8383
8384 CURSOR c_get_fin_adj_rec IS
8385 select decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(inbk.cost - nvl(outbk.cost, 0))
8386 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(inbk.salvage_value - nvl(outbk.salvage_value, 0))
8387 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(decode(inbk.production_capacity,
8388 null, decode(outbk.production_capacity,
8389 null, null,
8390 outbk.production_capacity),
8391 nvl(inbk.production_capacity, 0) -
8392 nvl(outbk.production_capacity, 0)))
8393 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(decode(inbk.reval_amortization_basis,
8394 null, decode(outbk.reval_amortization_basis,
8395 null, null,
8396 outbk.reval_amortization_basis),
8400 null, decode(outbk.reval_ceiling,
8397 nvl(inbk.reval_amortization_basis, 0) -
8398 nvl(outbk.reval_amortization_basis, 0)))
8399 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(decode(inbk.reval_ceiling,
8401 null, null,
8402 outbk.reval_ceiling),
8403 nvl(inbk.reval_ceiling, 0) - nvl(outbk.reval_ceiling, 0)))
8404 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(inbk.unrevalued_cost - nvl(outbk.unrevalued_cost, 0))
8405 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(nvl(inbk.allowed_deprn_limit_amount, 0) -
8406 nvl(outbk.allowed_deprn_limit_amount, 0))
8407 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0))
8408 from fa_transaction_headers th,
8409 fa_books inbk,
8410 fa_books outbk
8411 where inbk.asset_id = p_asset_hdr_rec.asset_id
8412 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
8413 and outbk.asset_id(+) = p_asset_hdr_rec.asset_id
8414 and outbk.book_type_code(+) = p_asset_hdr_rec.book_type_code
8415 and inbk.transaction_header_id_in = th.transaction_header_id
8416 and outbk.transaction_header_id_out(+) = th.transaction_header_id
8417 and th.asset_id = p_asset_hdr_rec.asset_id
8418 and th.book_type_code = p_asset_hdr_rec.book_type_code
8419 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
8420 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
8421 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
8422 G_TRX_TYPE_TFR_VOID)
8423 and nvl(th.amortization_start_date,
8424 th.transaction_date_entered) <= p_transaction_date_entered
8425 and not exists(select 'Exclude This Retirement'
8426 from fa_retirements ret,
8427 fa_transaction_headers reith
8428 where ret.transaction_header_id_in = th.transaction_header_id
8429 and ret.transaction_header_id_out = reith.transaction_header_id
8430 and nvl(reith.amortization_start_date,
8431 reith.transaction_date_entered) <= p_transaction_date_entered)
8432 order by transaction_date_entered;
8433
8434 CURSOR c_get_mc_fin_adj_rec IS
8435 select decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(inbk.cost - nvl(outbk.cost, 0))
8436 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(inbk.salvage_value - nvl(outbk.salvage_value, 0))
8437 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(decode(inbk.production_capacity,
8438 null, decode(outbk.production_capacity,
8439 null, null,
8440 outbk.production_capacity),
8441 nvl(inbk.production_capacity, 0) -
8442 nvl(outbk.production_capacity, 0)))
8443 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(decode(inbk.reval_amortization_basis,
8444 null, decode(outbk.reval_amortization_basis,
8445 null, null,
8446 outbk.reval_amortization_basis),
8447 nvl(inbk.reval_amortization_basis, 0) -
8448 nvl(outbk.reval_amortization_basis, 0)))
8449 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(decode(inbk.reval_ceiling,
8450 null, decode(outbk.reval_ceiling,
8451 null, null,
8452 outbk.reval_ceiling),
8453 nvl(inbk.reval_ceiling, 0) - nvl(outbk.reval_ceiling, 0)))
8454 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(inbk.unrevalued_cost - nvl(outbk.unrevalued_cost, 0))
8455 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(nvl(inbk.allowed_deprn_limit_amount, 0) -
8456 nvl(outbk.allowed_deprn_limit_amount, 0))
8457 , decode(p_reclass_src_dest, 'SOURCE', -1, 1) * sum(nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0))
8458 from fa_transaction_headers th,
8459 fa_books_mrc_v inbk,
8460 fa_books_mrc_v outbk
8461 where inbk.asset_id = p_asset_hdr_rec.asset_id
8462 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
8463 and outbk.asset_id(+) = p_asset_hdr_rec.asset_id
8464 and outbk.book_type_code(+) = p_asset_hdr_rec.book_type_code
8465 and inbk.transaction_header_id_in = th.transaction_header_id
8466 and outbk.transaction_header_id_out(+) = th.transaction_header_id
8467 and th.asset_id = p_asset_hdr_rec.asset_id
8468 and th.book_type_code = p_asset_hdr_rec.book_type_code
8469 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
8470 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
8471 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
8472 G_TRX_TYPE_TFR_VOID)
8473 and nvl(th.amortization_start_date,
8474 th.transaction_date_entered) <= p_transaction_date_entered
8475 and not exists(select 'Exclude This Retirement'
8476 from fa_retirements_mrc_v ret,
8477 fa_transaction_headers reith
8478 where ret.transaction_header_id_in = th.transaction_header_id
8479 and ret.transaction_header_id_out = reith.transaction_header_id
8480 and nvl(reith.amortization_start_date,
8484
8481 reith.transaction_date_entered) <= p_transaction_date_entered)
8482 order by transaction_date_entered;
8483
8485 BEGIN
8486
8487 if (p_log_level_rec.statement_level) then
8488 fa_debug_pkg.add(l_calling_fn, 'Begin',
8489 to_char(p_asset_hdr_rec.asset_id)||':'||
8490 to_char(p_transaction_date_entered, 'DD-MON-YYYY'));
8491 end if;
8492
8493 if (p_mrc_sob_type_code = 'R') then
8494 OPEN c_get_mc_fin_adj_rec;
8495 FETCH c_get_mc_fin_adj_rec INTO x_asset_fin_rec_adj.cost
8496 , x_asset_fin_rec_adj.salvage_value
8497 , x_asset_fin_rec_adj.production_capacity
8498 , x_asset_fin_rec_adj.reval_amortization_basis
8499 , x_asset_fin_rec_adj.reval_ceiling
8500 , x_asset_fin_rec_adj.unrevalued_cost
8501 , x_asset_fin_rec_adj.allowed_deprn_limit_amount
8502 , x_asset_fin_rec_adj.cip_cost;
8503 CLOSE c_get_mc_fin_adj_rec;
8504 else
8505 OPEN c_get_fin_adj_rec;
8506 FETCH c_get_fin_adj_rec INTO x_asset_fin_rec_adj.cost
8507 , x_asset_fin_rec_adj.salvage_value
8508 , x_asset_fin_rec_adj.production_capacity
8509 , x_asset_fin_rec_adj.reval_amortization_basis
8510 , x_asset_fin_rec_adj.reval_ceiling
8511 , x_asset_fin_rec_adj.unrevalued_cost
8512 , x_asset_fin_rec_adj.allowed_deprn_limit_amount
8513 , x_asset_fin_rec_adj.cip_cost;
8514 CLOSE c_get_fin_adj_rec;
8515 end if;
8516
8517 if (p_log_level_rec.statement_level) then
8518 fa_debug_pkg.add(l_calling_fn, 'End',
8519 to_char(x_asset_fin_rec_adj.cost)||':'||
8520 to_char(x_asset_fin_rec_adj.salvage_value)||':'||
8521 to_char(x_asset_fin_rec_adj.production_capacity)||':'||
8522 to_char(x_asset_fin_rec_adj.reval_amortization_basis)||':'||
8523 to_char(x_asset_fin_rec_adj.reval_ceiling)||':'||
8524 to_char(x_asset_fin_rec_adj.unrevalued_cost)||':'||
8525 to_char(x_asset_fin_rec_adj.allowed_deprn_limit_amount)||':'||
8526 to_char(x_asset_fin_rec_adj.cip_cost));
8527 end if;
8528
8529 return true;
8530
8531 EXCEPTION
8532 WHEN get_err THEN
8533 if (p_log_level_rec.statement_level) then
8534 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'get_err'
8535 ,p_log_level_rec => p_log_level_rec);
8536 end if;
8537
8538 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
8539 ,p_log_level_rec => p_log_level_rec);
8540 return false;
8541
8542 WHEN others THEN
8543 if (p_log_level_rec.statement_level) then
8544 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
8545 ,p_log_level_rec => p_log_level_rec);
8546 end if;
8547
8548 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
8549 ,p_log_level_rec => p_log_level_rec);
8550 return false;
8551 END GetFinAdjRec;
8552
8553 --+==============================================================================
8554 -- Function: GetFinRec
8555 --
8556 --
8557 --
8558 --
8559 --
8560 --+==============================================================================
8561 FUNCTION GetFinRec(
8562 p_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
8563 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
8564 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
8565 px_asset_fin_rec IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
8566 p_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type,
8567 p_asset_fin_rec_new FA_API_TYPES.asset_fin_rec_type,
8568 x_asset_fin_rec_new OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
8569 p_init_transaction_header_id FA_TRANSACTION_HEADERS.TRANSACTION_HEADER_ID%TYPE,
8570 p_use_fin_rec_adj BOOLEAN,
8571 p_use_new_deprn_rule BOOLEAN,
8572 p_process_this_trx BOOLEAN,
8573 x_dpis_change OUT NOCOPY BOOLEAN,
8574 p_mrc_sob_type_code VARCHAR2,
8575 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return BOOLEAN IS
8576
8577 Cursor c_get_init_bk IS
8578 select date_placed_in_service
8579 , deprn_start_date
8580 , deprn_method_code
8581 , life_in_months
8582 , rate_adjustment_factor
8583 , adjusted_cost
8584 , cost
8585 , original_cost
8586 , salvage_value
8587 , prorate_convention_code
8588 , prorate_date
8589 , cost_change_flag
8590 , adjustment_required_status
8591 , capitalize_flag
8592 , retirement_pending_flag
8593 , depreciate_flag
8594 , itc_amount_id
8595 , itc_amount
8596 , retirement_id
8597 , tax_request_id
8601 , bonus_rule
8598 , itc_basis
8599 , basic_rate
8600 , adjusted_rate
8602 , ceiling_name
8603 , recoverable_cost
8604 , adjusted_capacity
8605 , fully_rsvd_revals_counter
8606 , idled_flag
8607 , period_counter_capitalized
8608 , period_counter_fully_reserved
8609 , period_counter_fully_retired
8610 , production_capacity
8611 , reval_amortization_basis
8612 , reval_ceiling
8613 , unit_of_measure
8614 , unrevalued_cost
8615 , annual_deprn_rounding_flag
8616 , percent_salvage_value
8617 , allowed_deprn_limit
8618 , allowed_deprn_limit_amount
8619 , period_counter_life_complete
8620 , adjusted_recoverable_cost
8621 , annual_rounding_flag
8622 , eofy_adj_cost
8623 , eofy_formula_factor
8624 , short_fiscal_year_flag
8625 , conversion_date
8626 , ORIGINAL_DEPRN_START_DATE
8627 , remaining_life1
8628 , remaining_life2
8629 , group_asset_id
8630 , old_adjusted_cost
8631 , formula_factor
8632 , salvage_type
8633 , deprn_limit_type
8634 , over_depreciate_option
8635 , super_group_id
8636 , reduction_rate
8637 , reduce_addition_flag
8638 , reduce_adjustment_flag
8639 , reduce_retirement_flag
8640 , recognize_gain_loss
8641 , recapture_reserve_flag
8642 , limit_proceeds_flag
8643 , terminal_gain_loss
8644 , tracking_method
8645 , exclude_fully_rsv_flag
8646 , excess_allocation_option
8647 , depreciation_option
8648 , member_rollup_flag
8649 , ytd_proceeds
8650 , ltd_proceeds
8651 , allocate_to_fully_rsv_flag
8652 , allocate_to_fully_ret_flag
8653 , cip_cost
8654 , terminal_gain_loss_amount
8655 , ltd_cost_of_removal
8656 , prior_eofy_reserve
8657 , eofy_reserve
8658 , eop_adj_cost
8659 , eop_formula_factor
8660 , global_attribute1
8661 , global_attribute2
8662 , global_attribute3
8663 , global_attribute4
8664 , global_attribute5
8665 , global_attribute6
8666 , global_attribute7
8667 , global_attribute8
8668 , global_attribute9
8669 , global_attribute10
8670 , global_attribute11
8671 , global_attribute12
8672 , global_attribute13
8673 , global_attribute14
8674 , global_attribute15
8675 , global_attribute16
8676 , global_attribute17
8677 , global_attribute18
8678 , global_attribute19
8679 , global_attribute20
8680 , global_attribute_category
8681 from fa_books
8682 where asset_id = p_asset_hdr_rec.asset_id
8683 and book_type_code = p_asset_hdr_rec.book_type_code
8684 and (transaction_header_id_out = p_trans_rec.transaction_header_id
8685 or (transaction_header_id_in < p_trans_rec.transaction_header_id and
8686 transaction_header_id_out is null))
8687 order by transaction_header_id_in desc;
8688
8689
8690 Cursor c_get_init_bk_winit IS
8691 select date_placed_in_service
8692 , deprn_start_date
8693 , deprn_method_code
8694 , life_in_months
8695 , rate_adjustment_factor
8696 , adjusted_cost
8697 , cost
8698 , original_cost
8699 , salvage_value
8700 , prorate_convention_code
8701 , prorate_date
8702 , cost_change_flag
8703 , adjustment_required_status
8704 , capitalize_flag
8705 , retirement_pending_flag
8706 , depreciate_flag
8707 , itc_amount_id
8708 , itc_amount
8709 , retirement_id
8710 , tax_request_id
8711 , itc_basis
8712 , basic_rate
8713 , adjusted_rate
8714 , bonus_rule
8715 , ceiling_name
8716 , recoverable_cost
8717 , adjusted_capacity
8718 , fully_rsvd_revals_counter
8719 , idled_flag
8720 , period_counter_capitalized
8721 , period_counter_fully_reserved
8722 , period_counter_fully_retired
8723 , production_capacity
8724 , reval_amortization_basis
8725 , reval_ceiling
8726 , unit_of_measure
8727 , unrevalued_cost
8728 , annual_deprn_rounding_flag
8729 , percent_salvage_value
8730 , allowed_deprn_limit
8731 , allowed_deprn_limit_amount
8732 , period_counter_life_complete
8733 , adjusted_recoverable_cost
8734 , annual_rounding_flag
8735 , eofy_adj_cost
8736 , eofy_formula_factor
8737 , short_fiscal_year_flag
8738 , conversion_date
8739 , ORIGINAL_DEPRN_START_DATE
8740 , remaining_life1
8741 , remaining_life2
8742 , group_asset_id
8743 , old_adjusted_cost
8744 , formula_factor
8745 , salvage_type
8749 , reduction_rate
8746 , deprn_limit_type
8747 , over_depreciate_option
8748 , super_group_id
8750 , reduce_addition_flag
8751 , reduce_adjustment_flag
8752 , reduce_retirement_flag
8753 , recognize_gain_loss
8754 , recapture_reserve_flag
8755 , limit_proceeds_flag
8756 , terminal_gain_loss
8757 , tracking_method
8758 , exclude_fully_rsv_flag
8759 , excess_allocation_option
8760 , depreciation_option
8761 , member_rollup_flag
8762 , ytd_proceeds
8763 , ltd_proceeds
8764 , allocate_to_fully_rsv_flag
8765 , allocate_to_fully_ret_flag
8766 , cip_cost
8767 , terminal_gain_loss_amount
8768 , ltd_cost_of_removal
8769 , prior_eofy_reserve
8770 , eofy_reserve
8771 , eop_adj_cost
8772 , eop_formula_factor
8773 , global_attribute1
8774 , global_attribute2
8775 , global_attribute3
8776 , global_attribute4
8777 , global_attribute5
8778 , global_attribute6
8779 , global_attribute7
8780 , global_attribute8
8781 , global_attribute9
8782 , global_attribute10
8783 , global_attribute11
8784 , global_attribute12
8785 , global_attribute13
8786 , global_attribute14
8787 , global_attribute15
8788 , global_attribute16
8789 , global_attribute17
8790 , global_attribute18
8791 , global_attribute19
8792 , global_attribute20
8793 , global_attribute_category
8794 from fa_books
8795 where asset_id = p_asset_hdr_rec.asset_id
8796 and book_type_code = p_asset_hdr_rec.book_type_code
8797 and (transaction_header_id_out = p_init_transaction_header_id
8798 or (p_init_transaction_header_id > transaction_header_id_in and
8799 transaction_header_id_in < p_trans_rec.transaction_header_id and
8800 transaction_header_id_out is null))
8801 order by transaction_header_id_in desc;
8802
8803 Cursor c_get_init_mcbk IS
8804 select date_placed_in_service
8805 , deprn_start_date
8806 , deprn_method_code
8807 , life_in_months
8808 , rate_adjustment_factor
8809 , adjusted_cost
8810 , cost
8811 , original_cost
8812 , salvage_value
8813 , prorate_convention_code
8814 , prorate_date
8815 , cost_change_flag
8816 , adjustment_required_status
8817 , capitalize_flag
8818 , retirement_pending_flag
8819 , depreciate_flag
8820 , itc_amount_id
8821 , itc_amount
8822 , retirement_id
8823 , tax_request_id
8824 , itc_basis
8825 , basic_rate
8826 , adjusted_rate
8827 , bonus_rule
8828 , ceiling_name
8829 , recoverable_cost
8830 , adjusted_capacity
8831 , fully_rsvd_revals_counter
8832 , idled_flag
8833 , period_counter_capitalized
8834 , period_counter_fully_reserved
8835 , period_counter_fully_retired
8836 , production_capacity
8837 , reval_amortization_basis
8838 , reval_ceiling
8839 , unit_of_measure
8840 , unrevalued_cost
8841 , annual_deprn_rounding_flag
8842 , percent_salvage_value
8843 , allowed_deprn_limit
8844 , allowed_deprn_limit_amount
8845 , period_counter_life_complete
8846 , adjusted_recoverable_cost
8847 , annual_rounding_flag
8848 , eofy_adj_cost
8849 , eofy_formula_factor
8850 , short_fiscal_year_flag
8851 , conversion_date
8852 , ORIGINAL_DEPRN_START_DATE
8853 , remaining_life1
8854 , remaining_life2
8855 , group_asset_id
8856 , old_adjusted_cost
8857 , formula_factor
8858 , salvage_type
8859 , deprn_limit_type
8860 , over_depreciate_option
8861 , super_group_id
8862 , reduction_rate
8863 , reduce_addition_flag
8864 , reduce_adjustment_flag
8865 , reduce_retirement_flag
8866 , recognize_gain_loss
8867 , recapture_reserve_flag
8868 , limit_proceeds_flag
8869 , terminal_gain_loss
8870 , tracking_method
8871 , exclude_fully_rsv_flag
8872 , excess_allocation_option
8873 , depreciation_option
8874 , member_rollup_flag
8875 , ytd_proceeds
8876 , ltd_proceeds
8877 , allocate_to_fully_rsv_flag
8878 , allocate_to_fully_ret_flag
8879 , cip_cost
8880 , terminal_gain_loss_amount
8881 , ltd_cost_of_removal
8882 , prior_eofy_reserve
8883 , eofy_reserve
8884 , eop_adj_cost
8885 , eop_formula_factor
8886 , global_attribute1
8887 , global_attribute2
8888 , global_attribute3
8889 , global_attribute4
8890 , global_attribute5
8891 , global_attribute6
8892 , global_attribute7
8893 , global_attribute8
8894 , global_attribute9
8898 , global_attribute13
8895 , global_attribute10
8896 , global_attribute11
8897 , global_attribute12
8899 , global_attribute14
8900 , global_attribute15
8901 , global_attribute16
8902 , global_attribute17
8903 , global_attribute18
8904 , global_attribute19
8905 , global_attribute20
8906 , global_attribute_category
8907 from fa_books_mrc_v
8908 where asset_id = p_asset_hdr_rec.asset_id
8909 and book_type_code = p_asset_hdr_rec.book_type_code
8910 and (transaction_header_id_out = p_trans_rec.transaction_header_id
8911 or (transaction_header_id_in < p_trans_rec.transaction_header_id and
8912 transaction_header_id_out is null))
8913 order by transaction_header_id_in desc;
8914
8915 Cursor c_get_init_mcbk_winit IS
8916 select date_placed_in_service
8917 , deprn_start_date
8918 , deprn_method_code
8919 , life_in_months
8920 , rate_adjustment_factor
8921 , adjusted_cost
8922 , cost
8923 , original_cost
8924 , salvage_value
8925 , prorate_convention_code
8926 , prorate_date
8927 , cost_change_flag
8928 , adjustment_required_status
8929 , capitalize_flag
8930 , retirement_pending_flag
8931 , depreciate_flag
8932 , itc_amount_id
8933 , itc_amount
8934 , retirement_id
8935 , tax_request_id
8936 , itc_basis
8937 , basic_rate
8938 , adjusted_rate
8939 , bonus_rule
8940 , ceiling_name
8941 , recoverable_cost
8942 , adjusted_capacity
8943 , fully_rsvd_revals_counter
8944 , idled_flag
8945 , period_counter_capitalized
8946 , period_counter_fully_reserved
8947 , period_counter_fully_retired
8948 , production_capacity
8949 , reval_amortization_basis
8950 , reval_ceiling
8951 , unit_of_measure
8952 , unrevalued_cost
8953 , annual_deprn_rounding_flag
8954 , percent_salvage_value
8955 , allowed_deprn_limit
8956 , allowed_deprn_limit_amount
8957 , period_counter_life_complete
8958 , adjusted_recoverable_cost
8959 , annual_rounding_flag
8960 , eofy_adj_cost
8961 , eofy_formula_factor
8962 , short_fiscal_year_flag
8963 , conversion_date
8964 , ORIGINAL_DEPRN_START_DATE
8965 , remaining_life1
8966 , remaining_life2
8967 , group_asset_id
8968 , old_adjusted_cost
8969 , formula_factor
8970 , salvage_type
8971 , deprn_limit_type
8972 , over_depreciate_option
8973 , super_group_id
8974 , reduction_rate
8975 , reduce_addition_flag
8976 , reduce_adjustment_flag
8977 , reduce_retirement_flag
8978 , recognize_gain_loss
8979 , recapture_reserve_flag
8980 , limit_proceeds_flag
8981 , terminal_gain_loss
8982 , tracking_method
8983 , exclude_fully_rsv_flag
8984 , excess_allocation_option
8985 , depreciation_option
8986 , member_rollup_flag
8987 , ytd_proceeds
8988 , ltd_proceeds
8989 , allocate_to_fully_rsv_flag
8990 , allocate_to_fully_ret_flag
8991 , cip_cost
8992 , terminal_gain_loss_amount
8993 , ltd_cost_of_removal
8994 , prior_eofy_reserve
8995 , eofy_reserve
8996 , eop_adj_cost
8997 , eop_formula_factor
8998 , global_attribute1
8999 , global_attribute2
9000 , global_attribute3
9001 , global_attribute4
9002 , global_attribute5
9003 , global_attribute6
9004 , global_attribute7
9005 , global_attribute8
9006 , global_attribute9
9007 , global_attribute10
9008 , global_attribute11
9009 , global_attribute12
9010 , global_attribute13
9011 , global_attribute14
9012 , global_attribute15
9013 , global_attribute16
9014 , global_attribute17
9015 , global_attribute18
9016 , global_attribute19
9017 , global_attribute20
9018 , global_attribute_category
9019 from fa_books_mrc_v
9020 where asset_id = p_asset_hdr_rec.asset_id
9021 and book_type_code = p_asset_hdr_rec.book_type_code
9022 and (transaction_header_id_out = p_init_transaction_header_id
9023 or (p_init_transaction_header_id > transaction_header_id_in and
9024 transaction_header_id_in < p_trans_rec.transaction_header_id and
9025 transaction_header_id_out is null))
9026 order by transaction_header_id_in desc;
9027
9028 /* Bug 4043619 : Modified the cursor for salvage_value, allow_deprn_limit and allow_deprn_limit_adjusted. */
9029 /* Bug 5386577 : Modified the cursor so that it returns the deprn_method_code correctly for assets
9030 using depreciation method 'Units of production in hours' */
9031
9032 Cursor c_get_bk (c_asset_id number,
9033 c_transaction_header_id number) IS
9037 outbk.deprn_method_code,
9034 select inbk.date_placed_in_service
9035 , inbk.deprn_start_date
9036 , decode(inbk.deprn_method_code,
9038 decode(inbk.life_in_months,
9039 outbk.life_in_months,
9040 decode(inbk.basic_rate,
9041 outbk.basic_rate,
9042 decode(inbk.adjusted_rate,
9043 outbk.adjusted_rate,
9044 decode(inbk.production_capacity,
9045 outbk.production_capacity,
9046 null,
9047 inbk.deprn_method_code),
9048 inbk.deprn_method_code),
9049 inbk.deprn_method_code),
9050 inbk.deprn_method_code),
9051 inbk.deprn_method_code)
9052 , decode(inbk.deprn_method_code,
9053 outbk.deprn_method_code,
9054 decode(inbk.life_in_months,
9055 outbk.life_in_months, null,
9056 inbk.life_in_months),
9057 inbk.life_in_months)
9058 , inbk.rate_adjustment_factor
9059 , inbk.adjusted_cost
9060 , inbk.cost - nvl(outbk.cost, 0)
9061 , inbk.original_cost
9062 , decode(inbk.salvage_type,
9063 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9064 'PCT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9065 'AMT',nvl(inbk.salvage_value, 0)),
9066 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9067 'AMT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9068 'PCT',nvl(inbk.salvage_value, 0)))
9069 , inbk.prorate_convention_code
9070 , inbk.prorate_date
9071 , inbk.cost_change_flag
9072 , inbk.adjustment_required_status
9073 , inbk.capitalize_flag
9074 , inbk.retirement_pending_flag
9075 , inbk.depreciate_flag
9076 , inbk.itc_amount_id
9077 , inbk.itc_amount
9078 , inbk.retirement_id
9079 , inbk.tax_request_id
9080 , inbk.itc_basis
9081 -- Bug:5844121
9082 , decode(inbk.deprn_method_code,
9083 outbk.deprn_method_code,
9084 decode(inbk.basic_rate,
9085 outbk.basic_rate, decode(inbk.adjusted_rate,
9086 outbk.adjusted_rate, null,
9087 inbk.basic_rate),
9088 inbk.basic_rate),
9089 inbk.basic_rate)
9090 , decode(inbk.deprn_method_code,
9091 outbk.deprn_method_code,
9092 decode(inbk.adjusted_rate,
9093 outbk.adjusted_rate, decode(inbk.basic_rate,
9094 outbk.basic_rate, null,
9095 inbk.adjusted_rate),
9096 inbk.adjusted_rate),
9097 inbk.adjusted_rate)
9098 , inbk.bonus_rule
9099 , inbk.ceiling_name
9100 , inbk.recoverable_cost
9101 , inbk.adjusted_capacity
9102 , decode(inbk.fully_rsvd_revals_counter,
9103 null, decode(outbk.fully_rsvd_revals_counter,
9104 null, null,
9105 outbk.fully_rsvd_revals_counter),
9106 nvl(inbk.fully_rsvd_revals_counter, 0) -
9107 nvl(outbk.fully_rsvd_revals_counter, 0))
9108 , inbk.idled_flag
9109 , inbk.period_counter_capitalized
9110 , inbk.period_counter_fully_reserved
9111 , inbk.period_counter_fully_retired
9112 , decode(inbk.production_capacity,
9113 null, decode(outbk.production_capacity,
9114 null, null,
9115 outbk.production_capacity),
9116 nvl(inbk.production_capacity, 0) - nvl(outbk.production_capacity, 0))
9117 , decode(inbk.reval_amortization_basis,
9118 null, decode(outbk.reval_amortization_basis,
9119 null, null,
9120 outbk.reval_amortization_basis),
9121 nvl(inbk.reval_amortization_basis, 0) -
9122 nvl(outbk.reval_amortization_basis, 0))
9123 , decode(inbk.reval_ceiling,
9124 null, decode(outbk.reval_ceiling,
9125 null, null,
9126 outbk.reval_ceiling),
9127 nvl(inbk.reval_ceiling, 0) - nvl(outbk.reval_ceiling, 0))
9131 , decode(inbk.salvage_type,
9128 , inbk.unit_of_measure
9129 , inbk.unrevalued_cost - nvl(outbk.unrevalued_cost, 0)
9130 , inbk.annual_deprn_rounding_flag
9132 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9133 'PCT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9134 'AMT',nvl(inbk.percent_salvage_value, 0)),
9135 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9136 'AMT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9137 'PCT',nvl(inbk.percent_salvage_value, 0)))
9138 , decode(inbk.deprn_limit_type,
9139 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9140 'PCT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9141 'AMT',nvl(inbk.allowed_deprn_limit, 0)),
9142 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9143 'AMT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9144 'PCT',nvl(inbk.allowed_deprn_limit, 0)))
9145 , decode(inbk.deprn_limit_type,
9146 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9147 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9148 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0)),
9149 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9150 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9151 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0)))
9152 , inbk.period_counter_life_complete
9153 , inbk.adjusted_recoverable_cost
9154 , inbk.annual_rounding_flag
9155 , inbk.eofy_adj_cost
9156 , inbk.eofy_formula_factor
9157 , inbk.short_fiscal_year_flag
9158 , inbk.conversion_date
9159 , inbk.ORIGINAL_DEPRN_START_DATE
9160 , inbk.remaining_life1
9161 , inbk.remaining_life2
9162 , inbk.group_asset_id
9163 , inbk.old_adjusted_cost
9164 , inbk.formula_factor
9165 , inbk.salvage_type
9166 , inbk.deprn_limit_type
9167 , inbk.over_depreciate_option
9168 , decode(inbk.super_group_id, outbk.super_group_id, null, inbk.super_group_id)
9169 , decode(inbk.reduction_rate,
9170 null, decode(outbk.reduction_rate,
9171 null, null,
9172 outbk.reduction_rate),
9173 nvl(inbk.reduction_rate, 0) - nvl(outbk.reduction_rate, 0))
9174 , inbk.reduce_addition_flag
9175 , inbk.reduce_adjustment_flag
9176 , inbk.reduce_retirement_flag
9177 , inbk.recognize_gain_loss
9178 , inbk.recapture_reserve_flag
9179 , inbk.limit_proceeds_flag
9180 , inbk.terminal_gain_loss
9181 , inbk.tracking_method
9182 , inbk.exclude_fully_rsv_flag
9183 , inbk.excess_allocation_option
9184 , inbk.depreciation_option
9185 , inbk.member_rollup_flag
9186 , inbk.ytd_proceeds
9187 , inbk.ltd_proceeds
9188 , inbk.allocate_to_fully_rsv_flag
9189 , inbk.allocate_to_fully_ret_flag
9190 , nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0)
9191 , inbk.terminal_gain_loss_amount
9192 , inbk.ltd_cost_of_removal
9193 , inbk.prior_eofy_reserve
9194 , nvl(inbk.eofy_reserve, 0) - nvl(outbk.eofy_reserve, 0)
9195 , inbk.eop_adj_cost
9196 , inbk.eop_formula_factor
9197 , inbk.global_attribute1
9198 , inbk.global_attribute2
9199 , inbk.global_attribute3
9200 , inbk.global_attribute4
9201 , inbk.global_attribute5
9202 , inbk.global_attribute6
9203 , inbk.global_attribute7
9204 , inbk.global_attribute8
9205 , inbk.global_attribute9
9206 , inbk.global_attribute10
9207 , inbk.global_attribute11
9208 , inbk.global_attribute12
9209 , inbk.global_attribute13
9210 , inbk.global_attribute14
9211 , inbk.global_attribute15
9212 , inbk.global_attribute16
9213 , inbk.global_attribute17
9214 , inbk.global_attribute18
9215 , inbk.global_attribute19
9216 , inbk.global_attribute20
9217 , inbk.global_attribute_category
9218 from fa_books inbk,
9219 fa_books outbk
9220 where inbk.asset_id = c_asset_id
9221 and inbk.asset_id = outbk.asset_id(+)
9222 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
9223 and inbk.book_type_code = outbk.book_type_code(+)
9224 and inbk.transaction_header_id_in = c_transaction_header_id
9225 and inbk.transaction_header_id_in = outbk.transaction_header_id_out(+);
9226
9227 /* Bug 4043619 : Modified the mrc cursor for salvage_value, allow_deprn_limit and allow_deprn_limit_adjusted. */
9228 /* Bug 5386577 : Modified the mrc cursor so that it returns the deprn_method_code correctly for assets
9229 using depreciation method 'Units of production in hours' */
9230
9231 Cursor c_get_mcbk (c_asset_id number,
9232 c_transaction_header_id number) IS
9236 outbk.deprn_method_code,
9233 select inbk.date_placed_in_service
9234 , inbk.deprn_start_date
9235 , decode(inbk.deprn_method_code,
9237 decode(inbk.life_in_months,
9238 outbk.life_in_months,
9239 decode(inbk.basic_rate,
9240 outbk.basic_rate,
9241 decode(inbk.adjusted_rate,
9242 outbk.adjusted_rate,
9243 decode(inbk.production_capacity,
9244 outbk.production_capacity,
9245 null,
9246 inbk.deprn_method_code),
9247 inbk.deprn_method_code),
9248 inbk.deprn_method_code),
9249 inbk.deprn_method_code),
9250 inbk.deprn_method_code)
9251 , decode(inbk.deprn_method_code,
9252 outbk.deprn_method_code, decode(inbk.life_in_months,
9253 outbk.life_in_months, null,
9254 inbk.life_in_months),
9255 inbk.life_in_months)
9256 , inbk.rate_adjustment_factor
9257 , inbk.adjusted_cost
9258 , inbk.cost - nvl(outbk.cost, 0)
9259 , inbk.original_cost
9260 , decode(inbk.salvage_type,
9261 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9262 'PCT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9263 'AMT',nvl(inbk.salvage_value, 0)),
9264 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9265 'AMT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9266 'PCT',nvl(inbk.salvage_value, 0)))
9267 , inbk.prorate_convention_code
9268 , inbk.prorate_date
9269 , inbk.cost_change_flag
9270 , inbk.adjustment_required_status
9271 , inbk.capitalize_flag
9272 , inbk.retirement_pending_flag
9273 , inbk.depreciate_flag
9274 , inbk.itc_amount_id
9275 , inbk.itc_amount
9276 , inbk.retirement_id
9277 , inbk.tax_request_id
9278 , inbk.itc_basis
9279 -- Bug:5844121
9280 , decode(inbk.deprn_method_code,
9281 outbk.deprn_method_code, decode(inbk.basic_rate,
9282 outbk.basic_rate, decode(inbk.adjusted_rate,
9283 outbk.adjusted_rate, null,
9284 inbk.basic_rate),
9285 inbk.basic_rate),
9286 inbk.basic_rate)
9287 , decode(inbk.deprn_method_code,
9288 outbk.deprn_method_code, decode(inbk.adjusted_rate,
9289 outbk.adjusted_rate, decode(inbk.basic_rate,
9290 outbk.basic_rate, null,
9291 inbk.adjusted_rate),
9292 inbk.adjusted_rate),
9293 inbk.adjusted_rate)
9294 , inbk.bonus_rule
9295 , inbk.ceiling_name
9296 , inbk.recoverable_cost
9297 , inbk.adjusted_capacity
9298 , decode(inbk.fully_rsvd_revals_counter,
9299 null, decode(outbk.fully_rsvd_revals_counter,
9300 null, null,
9301 outbk.fully_rsvd_revals_counter),
9302 nvl(inbk.fully_rsvd_revals_counter, 0) -
9303 nvl(outbk.fully_rsvd_revals_counter, 0))
9304 , inbk.idled_flag
9305 , inbk.period_counter_capitalized
9306 , inbk.period_counter_fully_reserved
9307 , inbk.period_counter_fully_retired
9308 , decode(inbk.production_capacity,
9309 null, decode(outbk.production_capacity,
9310 null, null,
9311 outbk.production_capacity),
9312 nvl(inbk.production_capacity, 0) - nvl(outbk.production_capacity, 0))
9313 , decode(inbk.reval_amortization_basis,
9314 null, decode(outbk.reval_amortization_basis,
9315 null, null,
9316 outbk.reval_amortization_basis),
9317 nvl(inbk.reval_amortization_basis, 0) -
9318 nvl(outbk.reval_amortization_basis, 0))
9319 , decode(inbk.reval_ceiling,
9320 null, decode(outbk.reval_ceiling,
9321 null, null,
9322 outbk.reval_ceiling),
9323 nvl(inbk.reval_ceiling, 0) - nvl(outbk.reval_ceiling, 0))
9327 , decode(inbk.salvage_type,
9324 , inbk.unit_of_measure
9325 , inbk.unrevalued_cost - nvl(outbk.unrevalued_cost, 0)
9326 , inbk.annual_deprn_rounding_flag
9328 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9329 'PCT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9330 'AMT',nvl(inbk.percent_salvage_value, 0)),
9331 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9332 'AMT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9333 'PCT',nvl(inbk.percent_salvage_value, 0)))
9334 , decode(inbk.deprn_limit_type,
9335 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9336 'PCT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9337 'AMT',nvl(inbk.allowed_deprn_limit, 0)),
9338 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9339 'AMT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9340 'PCT',nvl(inbk.allowed_deprn_limit, 0)))
9341 , decode(inbk.deprn_limit_type,
9342 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9343 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9344 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0)),
9345 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9346 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9347 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0)))
9348 , inbk.period_counter_life_complete
9349 , inbk.adjusted_recoverable_cost
9350 , inbk.annual_rounding_flag
9351 , inbk.eofy_adj_cost
9352 , inbk.eofy_formula_factor
9353 , inbk.short_fiscal_year_flag
9354 , inbk.conversion_date
9355 , inbk.ORIGINAL_DEPRN_START_DATE
9356 , inbk.remaining_life1
9357 , inbk.remaining_life2
9358 , inbk.group_asset_id
9359 , inbk.old_adjusted_cost
9360 , inbk.formula_factor
9361 , inbk.salvage_type
9362 , inbk.deprn_limit_type
9363 , inbk.over_depreciate_option
9364 , decode(inbk.super_group_id, outbk.super_group_id, null, inbk.super_group_id)
9365 , decode(inbk.reduction_rate,
9366 null, decode(outbk.reduction_rate,
9367 null, null,
9368 outbk.reduction_rate),
9369 nvl(inbk.reduction_rate, 0) - nvl(outbk.reduction_rate, 0))
9370 , inbk.reduce_addition_flag
9371 , inbk.reduce_adjustment_flag
9372 , inbk.reduce_retirement_flag
9373 , inbk.recognize_gain_loss
9374 , inbk.recapture_reserve_flag
9375 , inbk.limit_proceeds_flag
9376 , inbk.terminal_gain_loss
9377 , inbk.tracking_method
9378 , inbk.exclude_fully_rsv_flag
9379 , inbk.excess_allocation_option
9380 , inbk.depreciation_option
9381 , inbk.member_rollup_flag
9382 , inbk.ytd_proceeds
9383 , inbk.ltd_proceeds
9384 , inbk.allocate_to_fully_rsv_flag
9385 , inbk.allocate_to_fully_ret_flag
9386 , nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0)
9387 , inbk.terminal_gain_loss_amount
9388 , inbk.ltd_cost_of_removal
9389 , inbk.prior_eofy_reserve
9390 , nvl(inbk.eofy_reserve, 0) - nvl(outbk.eofy_reserve, 0)
9391 , inbk.eop_adj_cost
9392 , inbk.eop_formula_factor
9393 , inbk.global_attribute1
9394 , inbk.global_attribute2
9395 , inbk.global_attribute3
9396 , inbk.global_attribute4
9397 , inbk.global_attribute5
9398 , inbk.global_attribute6
9399 , inbk.global_attribute7
9400 , inbk.global_attribute8
9401 , inbk.global_attribute9
9402 , inbk.global_attribute10
9403 , inbk.global_attribute11
9404 , inbk.global_attribute12
9405 , inbk.global_attribute13
9406 , inbk.global_attribute14
9407 , inbk.global_attribute15
9408 , inbk.global_attribute16
9409 , inbk.global_attribute17
9410 , inbk.global_attribute18
9411 , inbk.global_attribute19
9412 , inbk.global_attribute20
9413 , inbk.global_attribute_category
9414 from fa_books_mrc_v inbk,
9415 fa_books_mrc_v outbk
9416 where inbk.asset_id = c_asset_id
9417 and inbk.asset_id = outbk.asset_id(+)
9418 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
9419 and inbk.book_type_code = outbk.book_type_code(+)
9420 and inbk.transaction_header_id_in = c_transaction_header_id
9421 and inbk.transaction_header_id_in = outbk.transaction_header_id_out(+);
9422
9423 /* Bug 4043619 : Modified the cursor for salvage_value, allow_deprn_limit and allow_deprn_limit_adjusted. */
9424
9425 -- In case px_asset_fin_rec is null
9426 Cursor c_get_bk2 (c_asset_id number,
9427 c_transaction_header_id number) IS
9428 select inbk.date_placed_in_service
9432 , inbk.rate_adjustment_factor
9429 , inbk.deprn_start_date
9430 , inbk.deprn_method_code
9431 , inbk.life_in_months
9433 , inbk.adjusted_cost
9434 , inbk.cost - nvl(outbk.cost, 0)
9435 , inbk.original_cost
9436 , decode(inbk.salvage_type,
9437 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9438 'PCT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9439 'AMT',nvl(inbk.salvage_value, 0)),
9440 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9441 'AMT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9442 'PCT',nvl(inbk.salvage_value, 0)))
9443 , inbk.prorate_convention_code
9444 , inbk.prorate_date
9445 , inbk.cost_change_flag
9446 , inbk.adjustment_required_status
9447 , inbk.capitalize_flag
9448 , inbk.retirement_pending_flag
9449 , inbk.depreciate_flag
9450 , inbk.itc_amount_id
9451 , inbk.itc_amount
9452 , inbk.retirement_id
9453 , inbk.tax_request_id
9454 , inbk.itc_basis
9455 , inbk.basic_rate
9456 , inbk.adjusted_rate
9457 , inbk.bonus_rule
9458 , inbk.ceiling_name
9459 , inbk.recoverable_cost
9460 , inbk.adjusted_capacity
9461 , decode(inbk.fully_rsvd_revals_counter,
9462 null, decode(outbk.fully_rsvd_revals_counter,
9463 null, null,
9464 outbk.fully_rsvd_revals_counter),
9465 nvl(inbk.fully_rsvd_revals_counter, 0) -
9466 nvl(outbk.fully_rsvd_revals_counter, 0))
9467 , inbk.idled_flag
9468 , inbk.period_counter_capitalized
9469 , inbk.period_counter_fully_reserved
9470 , inbk.period_counter_fully_retired
9471 , decode(inbk.production_capacity,
9472 null, decode(outbk.production_capacity,
9473 null, null,
9474 outbk.production_capacity),
9475 nvl(inbk.production_capacity, 0) - nvl(outbk.production_capacity, 0))
9476 , decode(inbk.reval_amortization_basis,
9477 null, decode(outbk.reval_amortization_basis,
9478 null, null,
9479 outbk.reval_amortization_basis),
9480 nvl(inbk.reval_amortization_basis, 0) -
9481 nvl(outbk.reval_amortization_basis, 0))
9482 , decode(inbk.reval_ceiling,
9483 null, decode(outbk.reval_ceiling,
9484 null, null,
9485 outbk.reval_ceiling),
9486 nvl(inbk.reval_ceiling, 0) - nvl(outbk.reval_ceiling, 0))
9487 , inbk.unit_of_measure
9488 , inbk.unrevalued_cost - nvl(outbk.unrevalued_cost, 0)
9489 , inbk.annual_deprn_rounding_flag
9490 , decode(inbk.salvage_type,
9491 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9492 'PCT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9493 'AMT',nvl(inbk.percent_salvage_value, 0)),
9494 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9495 'AMT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9496 'PCT',nvl(inbk.percent_salvage_value, 0)))
9497 , decode(inbk.deprn_limit_type,
9498 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9499 'PCT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9500 'AMT',nvl(inbk.allowed_deprn_limit, 0)),
9501 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9502 'AMT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9503 'PCT',nvl(inbk.allowed_deprn_limit, 0)))
9504 , decode(inbk.deprn_limit_type,
9505 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9506 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9507 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0)),
9508 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9509 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9510 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0)))
9511 , inbk.period_counter_life_complete
9512 , inbk.adjusted_recoverable_cost
9513 , inbk.annual_rounding_flag
9514 , inbk.eofy_adj_cost
9515 , inbk.eofy_formula_factor
9516 , inbk.short_fiscal_year_flag
9517 , inbk.conversion_date
9518 , inbk.ORIGINAL_DEPRN_START_DATE
9519 , inbk.remaining_life1
9520 , inbk.remaining_life2
9521 , inbk.group_asset_id
9522 , inbk.old_adjusted_cost
9523 , inbk.formula_factor
9524 , inbk.salvage_type
9525 , inbk.deprn_limit_type
9526 , inbk.over_depreciate_option
9527 , decode(inbk.super_group_id, outbk.super_group_id, null, inbk.super_group_id)
9528 , decode(inbk.reduction_rate,
9532 nvl(inbk.reduction_rate, 0) - nvl(outbk.reduction_rate, 0))
9529 null, decode(outbk.reduction_rate,
9530 null, null,
9531 outbk.reduction_rate),
9533 , inbk.reduce_addition_flag
9534 , inbk.reduce_adjustment_flag
9535 , inbk.reduce_retirement_flag
9536 , inbk.recognize_gain_loss
9537 , inbk.recapture_reserve_flag
9538 , inbk.limit_proceeds_flag
9539 , inbk.terminal_gain_loss
9540 , inbk.tracking_method
9541 , inbk.exclude_fully_rsv_flag
9542 , inbk.excess_allocation_option
9543 , inbk.depreciation_option
9544 , inbk.member_rollup_flag
9545 , inbk.ytd_proceeds
9546 , inbk.ltd_proceeds
9547 , inbk.allocate_to_fully_rsv_flag
9548 , inbk.allocate_to_fully_ret_flag
9549 , nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0)
9550 , inbk.terminal_gain_loss_amount
9551 , inbk.ltd_cost_of_removal
9552 , inbk.prior_eofy_reserve
9553 , nvl(inbk.eofy_reserve, 0) - nvl(outbk.eofy_reserve, 0)
9554 , inbk.eop_adj_cost
9555 , inbk.eop_formula_factor
9556 , inbk.global_attribute1
9557 , inbk.global_attribute2
9558 , inbk.global_attribute3
9559 , inbk.global_attribute4
9560 , inbk.global_attribute5
9561 , inbk.global_attribute6
9562 , inbk.global_attribute7
9563 , inbk.global_attribute8
9564 , inbk.global_attribute9
9565 , inbk.global_attribute10
9566 , inbk.global_attribute11
9567 , inbk.global_attribute12
9568 , inbk.global_attribute13
9569 , inbk.global_attribute14
9570 , inbk.global_attribute15
9571 , inbk.global_attribute16
9572 , inbk.global_attribute17
9573 , inbk.global_attribute18
9574 , inbk.global_attribute19
9575 , inbk.global_attribute20
9576 , inbk.global_attribute_category
9577 from fa_books inbk,
9578 fa_books outbk
9579 where inbk.asset_id = c_asset_id
9580 and inbk.asset_id = outbk.asset_id(+)
9581 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
9582 and inbk.book_type_code = outbk.book_type_code(+)
9583 and inbk.transaction_header_id_in = c_transaction_header_id
9584 and inbk.transaction_header_id_in = outbk.transaction_header_id_out(+);
9585
9586
9587 /* Bug 4043619 : Modified the mrc cursor for salvage_value, allow_deprn_limit and allow_deprn_limit_adjusted. */
9588
9589 -- In case px_asset_fin_rec is null
9590 Cursor c_get_mcbk2 (c_asset_id number,
9591 c_transaction_header_id number) IS
9592 select inbk.date_placed_in_service
9593 , inbk.deprn_start_date
9594 , inbk.deprn_method_code
9595 , inbk.life_in_months
9596 , inbk.rate_adjustment_factor
9597 , inbk.adjusted_cost
9598 , inbk.cost - nvl(outbk.cost, 0)
9599 , inbk.original_cost
9600 , decode(inbk.salvage_type,
9601 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9602 'PCT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9603 'AMT',nvl(inbk.salvage_value, 0)),
9604 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9605 'AMT',inbk.salvage_value - nvl(outbk.salvage_value, 0),
9606 'PCT',nvl(inbk.salvage_value, 0)))
9607 , inbk.prorate_convention_code
9608 , inbk.prorate_date
9609 , inbk.cost_change_flag
9610 , inbk.adjustment_required_status
9611 , inbk.capitalize_flag
9612 , inbk.retirement_pending_flag
9613 , inbk.depreciate_flag
9614 , inbk.itc_amount_id
9615 , inbk.itc_amount
9616 , inbk.retirement_id
9617 , inbk.tax_request_id
9618 , inbk.itc_basis
9619 , inbk.basic_rate
9620 , inbk.adjusted_rate
9621 , inbk.bonus_rule
9622 , inbk.ceiling_name
9623 , inbk.recoverable_cost
9624 , inbk.adjusted_capacity
9625 , decode(inbk.fully_rsvd_revals_counter,
9626 null, decode(outbk.fully_rsvd_revals_counter,
9627 null, null,
9628 outbk.fully_rsvd_revals_counter),
9629 nvl(inbk.fully_rsvd_revals_counter, 0) -
9630 nvl(outbk.fully_rsvd_revals_counter, 0))
9631 , inbk.idled_flag
9632 , inbk.period_counter_capitalized
9633 , inbk.period_counter_fully_reserved
9634 , inbk.period_counter_fully_retired
9635 , decode(inbk.production_capacity,
9636 null, decode(outbk.production_capacity,
9637 null, null,
9638 outbk.production_capacity),
9639 nvl(inbk.production_capacity, 0) - nvl(outbk.production_capacity, 0))
9640 , decode(inbk.reval_amortization_basis,
9641 null, decode(outbk.reval_amortization_basis,
9642 null, null,
9643 outbk.reval_amortization_basis),
9644 nvl(inbk.reval_amortization_basis, 0) -
9645 nvl(outbk.reval_amortization_basis, 0))
9649 outbk.reval_ceiling),
9646 , decode(inbk.reval_ceiling,
9647 null, decode(outbk.reval_ceiling,
9648 null, null,
9650 nvl(inbk.reval_ceiling, 0) - nvl(outbk.reval_ceiling, 0))
9651 , inbk.unit_of_measure
9652 , inbk.unrevalued_cost - nvl(outbk.unrevalued_cost, 0)
9653 , inbk.annual_deprn_rounding_flag
9654 , decode(inbk.salvage_type,
9655 'PCT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9656 'PCT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9657 'AMT',nvl(inbk.percent_salvage_value, 0)),
9658 'AMT', decode(nvl(outbk.salvage_type, inbk.salvage_type),
9659 'AMT',nvl(inbk.percent_salvage_value, 0) - nvl(outbk.percent_salvage_value, 0),
9660 'PCT',nvl(inbk.percent_salvage_value, 0)))
9661 , decode(inbk.deprn_limit_type,
9662 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9663 'PCT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9664 'AMT',nvl(inbk.allowed_deprn_limit, 0)),
9665 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9666 'AMT',nvl(inbk.allowed_deprn_limit, 0) - nvl(outbk.allowed_deprn_limit, 0),
9667 'PCT',nvl(inbk.allowed_deprn_limit, 0)))
9668 , decode(inbk.deprn_limit_type,
9669 'PCT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9670 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9671 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0)),
9672 'AMT', decode(nvl(outbk.deprn_limit_type, inbk.deprn_limit_type),
9673 'AMT',nvl(inbk.allowed_deprn_limit_amount, 0) - nvl(outbk.allowed_deprn_limit_amount, 0),
9674 'PCT',nvl(inbk.allowed_deprn_limit_amount, 0)))
9675 , inbk.period_counter_life_complete
9676 , inbk.adjusted_recoverable_cost
9677 , inbk.annual_rounding_flag
9678 , inbk.eofy_adj_cost
9679 , inbk.eofy_formula_factor
9680 , inbk.short_fiscal_year_flag
9681 , inbk.conversion_date
9682 , inbk.ORIGINAL_DEPRN_START_DATE
9683 , inbk.remaining_life1
9684 , inbk.remaining_life2
9685 , inbk.group_asset_id
9686 , inbk.old_adjusted_cost
9687 , inbk.formula_factor
9688 , inbk.salvage_type
9689 , inbk.deprn_limit_type
9690 , inbk.over_depreciate_option
9691 , decode(inbk.super_group_id, outbk.super_group_id, null, inbk.super_group_id)
9692 , decode(inbk.reduction_rate,
9693 null, decode(outbk.reduction_rate,
9694 null, null,
9695 outbk.reduction_rate),
9696 nvl(inbk.reduction_rate, 0) - nvl(outbk.reduction_rate, 0))
9697 , inbk.reduce_addition_flag
9698 , inbk.reduce_adjustment_flag
9699 , inbk.reduce_retirement_flag
9700 , inbk.recognize_gain_loss
9701 , inbk.recapture_reserve_flag
9702 , inbk.limit_proceeds_flag
9703 , inbk.terminal_gain_loss
9704 , inbk.tracking_method
9705 , inbk.exclude_fully_rsv_flag
9706 , inbk.excess_allocation_option
9707 , inbk.depreciation_option
9708 , inbk.member_rollup_flag
9709 , inbk.ytd_proceeds
9710 , inbk.ltd_proceeds
9711 , inbk.allocate_to_fully_rsv_flag
9712 , inbk.allocate_to_fully_ret_flag
9713 , nvl(inbk.cip_cost, 0) - nvl(outbk.cip_cost, 0)
9714 , inbk.terminal_gain_loss_amount
9715 , inbk.ltd_cost_of_removal
9716 , inbk.prior_eofy_reserve
9717 , nvl(inbk.eofy_reserve, 0) - nvl(outbk.eofy_reserve, 0)
9718 , inbk.eop_adj_cost
9719 , inbk.eop_formula_factor
9720 , inbk.global_attribute1
9721 , inbk.global_attribute2
9722 , inbk.global_attribute3
9723 , inbk.global_attribute4
9724 , inbk.global_attribute5
9725 , inbk.global_attribute6
9726 , inbk.global_attribute7
9727 , inbk.global_attribute8
9728 , inbk.global_attribute9
9729 , inbk.global_attribute10
9730 , inbk.global_attribute11
9731 , inbk.global_attribute12
9732 , inbk.global_attribute13
9733 , inbk.global_attribute14
9734 , inbk.global_attribute15
9735 , inbk.global_attribute16
9736 , inbk.global_attribute17
9737 , inbk.global_attribute18
9738 , inbk.global_attribute19
9739 , inbk.global_attribute20
9740 , inbk.global_attribute_category
9741 from fa_books_mrc_v inbk,
9742 fa_books_mrc_v outbk
9743 where inbk.asset_id = c_asset_id
9744 and inbk.asset_id = outbk.asset_id(+)
9745 and inbk.book_type_code = p_asset_hdr_rec.book_type_code
9746 and inbk.book_type_code = outbk.book_type_code(+)
9747 and inbk.transaction_header_id_in = c_transaction_header_id
9748 and inbk.transaction_header_id_in = outbk.transaction_header_id_out(+);
9749
9750
9751 CURSOR c_get_member_asset_id IS
9755
9752 select asset_id
9753 from fa_transaction_headers
9754 where transaction_header_id = p_trans_rec.member_transaction_header_id;
9756 l_calling_fn VARCHAR2(100) := 'FA_AMORT_PVT.GetFinRec';
9757 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
9758 l_asset_desc_rec FA_API_TYPES.asset_desc_rec_type;
9759 l_asset_cat_rec FA_API_TYPES.asset_cat_rec_type;
9760 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
9761 l_period_rec FA_API_TYPES.period_rec_type;
9762
9763 l_is_member_trx_for_group BOOLEAN := FALSE;
9764 l_asset_id NUMBER;
9765 l_transaction_header_id NUMBER;
9766
9767 l_tmp_cost NUMBER;
9768 l_tmp_percent_salvage_value NUMBER;
9769 l_tmp_salvage_value NUMBER;
9770 l_tmp_allowed_deprn_limit NUMBER;
9771 l_tmp_allowed_deprn_limit_amt NUMBER;
9772 l_tmp_production_capacity NUMBER;
9773 l_tmp_fully_rsv_revals_counter NUMBER;
9774 l_tmp_reval_amortization_basis NUMBER;
9775 l_tmp_reval_ceiling NUMBER;
9776 l_tmp_unrevalued_cost NUMBER;
9777 l_tmp_eofy_reserve NUMBER;
9778
9779 l_adj_found BOOLEAN := FALSE;
9780 l_reclass_trx BOOLEAN := FALSE;
9781
9782 calc_failed EXCEPTION;
9783
9784 BEGIN
9785
9786 if (p_log_level_rec.statement_level) then
9787 fa_debug_pkg.add(l_calling_fn, 'Begin', px_asset_fin_rec.date_placed_in_service||':'||
9788 p_init_transaction_header_id
9789 ,p_log_level_rec => p_log_level_rec);
9790 end if;
9791
9792 x_dpis_change := FALSE;
9793
9794 if (p_trans_rec.transaction_header_id is null and
9795 p_trans_rec.member_transaction_header_id is not null) then
9796 l_is_member_trx_for_group := TRUE;
9797
9798 OPEN c_get_member_asset_id;
9799 FETCH c_get_member_asset_id INTO l_asset_id;
9800 CLOSE c_get_member_asset_id;
9801
9802 l_transaction_header_id := p_trans_rec.member_transaction_header_id;
9803
9804 if (p_log_level_rec.statement_level) then
9805 fa_debug_pkg.add(l_calling_fn, 'Need to get Delta from member', l_asset_id
9806 ,p_log_level_rec => p_log_level_rec);
9807 end if;
9808
9809 else
9810 l_asset_id := p_asset_hdr_rec.asset_id;
9811 l_transaction_header_id := p_trans_rec.transaction_header_id;
9812 end if;
9813
9814 --tk_util.DumpFinRec(px_asset_fin_rec, 'GO1');
9815
9816 if (nvl(p_mrc_sob_type_code, 'P') = 'R') then
9817 if (px_asset_fin_rec.date_placed_in_service is null) then
9818
9819 if p_init_transaction_header_id is null then
9820 OPEN c_get_init_mcbk;
9821 FETCH c_get_init_mcbk INTO px_asset_fin_rec.date_placed_in_service
9822 , px_asset_fin_rec.deprn_start_date
9823 , px_asset_fin_rec.deprn_method_code
9824 , px_asset_fin_rec.life_in_months
9825 , px_asset_fin_rec.rate_adjustment_factor
9826 , px_asset_fin_rec.adjusted_cost
9827 , px_asset_fin_rec.cost
9828 , px_asset_fin_rec.original_cost
9829 , px_asset_fin_rec.salvage_value
9830 , px_asset_fin_rec.prorate_convention_code
9831 , px_asset_fin_rec.prorate_date
9832 , px_asset_fin_rec.cost_change_flag
9833 , px_asset_fin_rec.adjustment_required_status
9834 , px_asset_fin_rec.capitalize_flag
9835 , px_asset_fin_rec.retirement_pending_flag
9836 , px_asset_fin_rec.depreciate_flag
9837 , px_asset_fin_rec.itc_amount_id
9838 , px_asset_fin_rec.itc_amount
9839 , px_asset_fin_rec.retirement_id
9840 , px_asset_fin_rec.tax_request_id
9841 , px_asset_fin_rec.itc_basis
9842 , px_asset_fin_rec.basic_rate
9843 , px_asset_fin_rec.adjusted_rate
9844 , px_asset_fin_rec.bonus_rule
9845 , px_asset_fin_rec.ceiling_name
9846 , px_asset_fin_rec.recoverable_cost
9847 , px_asset_fin_rec.adjusted_capacity
9848 , px_asset_fin_rec.fully_rsvd_revals_counter
9849 , px_asset_fin_rec.idled_flag
9850 , px_asset_fin_rec.period_counter_capitalized
9851 , px_asset_fin_rec.period_counter_fully_reserved
9852 , px_asset_fin_rec.period_counter_fully_retired
9853 , px_asset_fin_rec.production_capacity
9854 , px_asset_fin_rec.reval_amortization_basis
9855 , px_asset_fin_rec.reval_ceiling
9856 , px_asset_fin_rec.unit_of_measure
9857 , px_asset_fin_rec.unrevalued_cost
9858 , px_asset_fin_rec.annual_deprn_rounding_flag
9859 , px_asset_fin_rec.percent_salvage_value
9860 , px_asset_fin_rec.allowed_deprn_limit
9864 , px_asset_fin_rec.annual_rounding_flag
9861 , px_asset_fin_rec.allowed_deprn_limit_amount
9862 , px_asset_fin_rec.period_counter_life_complete
9863 , px_asset_fin_rec.adjusted_recoverable_cost
9865 , px_asset_fin_rec.eofy_adj_cost
9866 , px_asset_fin_rec.eofy_formula_factor
9867 , px_asset_fin_rec.short_fiscal_year_flag
9868 , px_asset_fin_rec.conversion_date
9869 , px_asset_fin_rec.orig_deprn_start_date
9870 , px_asset_fin_rec.remaining_life1
9871 , px_asset_fin_rec.remaining_life2
9872 , px_asset_fin_rec.group_asset_id
9873 , px_asset_fin_rec.old_adjusted_cost
9874 , px_asset_fin_rec.formula_factor
9875 , px_asset_fin_rec.salvage_type
9876 , px_asset_fin_rec.deprn_limit_type
9877 , px_asset_fin_rec.over_depreciate_option
9878 , px_asset_fin_rec.super_group_id
9879 , px_asset_fin_rec.reduction_rate
9880 , px_asset_fin_rec.reduce_addition_flag
9881 , px_asset_fin_rec.reduce_adjustment_flag
9882 , px_asset_fin_rec.reduce_retirement_flag
9883 , px_asset_fin_rec.recognize_gain_loss
9884 , px_asset_fin_rec.recapture_reserve_flag
9885 , px_asset_fin_rec.limit_proceeds_flag
9886 , px_asset_fin_rec.terminal_gain_loss
9887 , px_asset_fin_rec.tracking_method
9888 , px_asset_fin_rec.exclude_fully_rsv_flag
9889 , px_asset_fin_rec.excess_allocation_option
9890 , px_asset_fin_rec.depreciation_option
9891 , px_asset_fin_rec.member_rollup_flag
9892 , px_asset_fin_rec.ytd_proceeds
9893 , px_asset_fin_rec.ltd_proceeds
9894 , px_asset_fin_rec.allocate_to_fully_rsv_flag
9895 , px_asset_fin_rec.allocate_to_fully_ret_flag
9896 , px_asset_fin_rec.cip_cost
9897 , px_asset_fin_rec.terminal_gain_loss_amount
9898 , px_asset_fin_rec.ltd_cost_of_removal
9899 , px_asset_fin_rec.prior_eofy_reserve
9900 , px_asset_fin_rec.eofy_reserve
9901 , px_asset_fin_rec.eop_adj_cost
9902 , px_asset_fin_rec.eop_formula_factor
9903 , px_asset_fin_rec.global_attribute1
9904 , px_asset_fin_rec.global_attribute2
9905 , px_asset_fin_rec.global_attribute3
9906 , px_asset_fin_rec.global_attribute4
9907 , px_asset_fin_rec.global_attribute5
9908 , px_asset_fin_rec.global_attribute6
9909 , px_asset_fin_rec.global_attribute7
9910 , px_asset_fin_rec.global_attribute8
9911 , px_asset_fin_rec.global_attribute9
9912 , px_asset_fin_rec.global_attribute10
9913 , px_asset_fin_rec.global_attribute11
9914 , px_asset_fin_rec.global_attribute12
9915 , px_asset_fin_rec.global_attribute13
9916 , px_asset_fin_rec.global_attribute14
9917 , px_asset_fin_rec.global_attribute15
9918 , px_asset_fin_rec.global_attribute16
9919 , px_asset_fin_rec.global_attribute17
9920 , px_asset_fin_rec.global_attribute18
9921 , px_asset_fin_rec.global_attribute19
9922 , px_asset_fin_rec.global_attribute20
9923 , px_asset_fin_rec.global_attribute_category;
9924 CLOSE c_get_init_mcbk;
9925 else
9926 OPEN c_get_init_mcbk_winit;
9927 FETCH c_get_init_mcbk_winit INTO px_asset_fin_rec.date_placed_in_service
9928 , px_asset_fin_rec.deprn_start_date
9929 , px_asset_fin_rec.deprn_method_code
9930 , px_asset_fin_rec.life_in_months
9931 , px_asset_fin_rec.rate_adjustment_factor
9932 , px_asset_fin_rec.adjusted_cost
9933 , px_asset_fin_rec.cost
9934 , px_asset_fin_rec.original_cost
9935 , px_asset_fin_rec.salvage_value
9936 , px_asset_fin_rec.prorate_convention_code
9937 , px_asset_fin_rec.prorate_date
9938 , px_asset_fin_rec.cost_change_flag
9939 , px_asset_fin_rec.adjustment_required_status
9940 , px_asset_fin_rec.capitalize_flag
9941 , px_asset_fin_rec.retirement_pending_flag
9945 , px_asset_fin_rec.retirement_id
9942 , px_asset_fin_rec.depreciate_flag
9943 , px_asset_fin_rec.itc_amount_id
9944 , px_asset_fin_rec.itc_amount
9946 , px_asset_fin_rec.tax_request_id
9947 , px_asset_fin_rec.itc_basis
9948 , px_asset_fin_rec.basic_rate
9949 , px_asset_fin_rec.adjusted_rate
9950 , px_asset_fin_rec.bonus_rule
9951 , px_asset_fin_rec.ceiling_name
9952 , px_asset_fin_rec.recoverable_cost
9953 , px_asset_fin_rec.adjusted_capacity
9954 , px_asset_fin_rec.fully_rsvd_revals_counter
9955 , px_asset_fin_rec.idled_flag
9956 , px_asset_fin_rec.period_counter_capitalized
9957 , px_asset_fin_rec.period_counter_fully_reserved
9958 , px_asset_fin_rec.period_counter_fully_retired
9959 , px_asset_fin_rec.production_capacity
9960 , px_asset_fin_rec.reval_amortization_basis
9961 , px_asset_fin_rec.reval_ceiling
9962 , px_asset_fin_rec.unit_of_measure
9963 , px_asset_fin_rec.unrevalued_cost
9964 , px_asset_fin_rec.annual_deprn_rounding_flag
9965 , px_asset_fin_rec.percent_salvage_value
9966 , px_asset_fin_rec.allowed_deprn_limit
9967 , px_asset_fin_rec.allowed_deprn_limit_amount
9968 , px_asset_fin_rec.period_counter_life_complete
9969 , px_asset_fin_rec.adjusted_recoverable_cost
9970 , px_asset_fin_rec.annual_rounding_flag
9971 , px_asset_fin_rec.eofy_adj_cost
9972 , px_asset_fin_rec.eofy_formula_factor
9973 , px_asset_fin_rec.short_fiscal_year_flag
9974 , px_asset_fin_rec.conversion_date
9975 , px_asset_fin_rec.orig_deprn_start_date
9976 , px_asset_fin_rec.remaining_life1
9977 , px_asset_fin_rec.remaining_life2
9978 , px_asset_fin_rec.group_asset_id
9979 , px_asset_fin_rec.old_adjusted_cost
9980 , px_asset_fin_rec.formula_factor
9981 , px_asset_fin_rec.salvage_type
9982 , px_asset_fin_rec.deprn_limit_type
9983 , px_asset_fin_rec.over_depreciate_option
9984 , px_asset_fin_rec.super_group_id
9985 , px_asset_fin_rec.reduction_rate
9986 , px_asset_fin_rec.reduce_addition_flag
9987 , px_asset_fin_rec.reduce_adjustment_flag
9988 , px_asset_fin_rec.reduce_retirement_flag
9989 , px_asset_fin_rec.recognize_gain_loss
9990 , px_asset_fin_rec.recapture_reserve_flag
9991 , px_asset_fin_rec.limit_proceeds_flag
9992 , px_asset_fin_rec.terminal_gain_loss
9993 , px_asset_fin_rec.tracking_method
9994 , px_asset_fin_rec.exclude_fully_rsv_flag
9995 , px_asset_fin_rec.excess_allocation_option
9996 , px_asset_fin_rec.depreciation_option
9997 , px_asset_fin_rec.member_rollup_flag
9998 , px_asset_fin_rec.ytd_proceeds
9999 , px_asset_fin_rec.ltd_proceeds
10000 , px_asset_fin_rec.allocate_to_fully_rsv_flag
10001 , px_asset_fin_rec.allocate_to_fully_ret_flag
10002 , px_asset_fin_rec.cip_cost
10003 , px_asset_fin_rec.terminal_gain_loss_amount
10004 , px_asset_fin_rec.ltd_cost_of_removal
10005 , px_asset_fin_rec.prior_eofy_reserve
10006 , px_asset_fin_rec.eofy_reserve
10007 , px_asset_fin_rec.eop_adj_cost
10008 , px_asset_fin_rec.eop_formula_factor
10009 , px_asset_fin_rec.global_attribute1
10010 , px_asset_fin_rec.global_attribute2
10011 , px_asset_fin_rec.global_attribute3
10012 , px_asset_fin_rec.global_attribute4
10013 , px_asset_fin_rec.global_attribute5
10014 , px_asset_fin_rec.global_attribute6
10015 , px_asset_fin_rec.global_attribute7
10016 , px_asset_fin_rec.global_attribute8
10017 , px_asset_fin_rec.global_attribute9
10018 , px_asset_fin_rec.global_attribute10
10019 , px_asset_fin_rec.global_attribute11
10023 , px_asset_fin_rec.global_attribute15
10020 , px_asset_fin_rec.global_attribute12
10021 , px_asset_fin_rec.global_attribute13
10022 , px_asset_fin_rec.global_attribute14
10024 , px_asset_fin_rec.global_attribute16
10025 , px_asset_fin_rec.global_attribute17
10026 , px_asset_fin_rec.global_attribute18
10027 , px_asset_fin_rec.global_attribute19
10028 , px_asset_fin_rec.global_attribute20
10029 , px_asset_fin_rec.global_attribute_category;
10030 CLOSE c_get_init_mcbk_winit;
10031
10032 end if;
10033
10034 if (p_log_level_rec.statement_level) then
10035 fa_debug_pkg.add(l_calling_fn, 'Found initial fin_rec from db',
10036 px_asset_fin_rec.cost
10037 ,p_log_level_rec => p_log_level_rec);
10038 end if;
10039
10040 /*
10041 if p_trans_rec.transaction_type_code in
10042 (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET) and
10043 not (p_use_fin_rec_adj) then
10044 x_asset_fin_rec_new := px_asset_fin_rec;
10045
10046 --tk_util.DumpFinRec(px_asset_fin_rec, 'GO2');
10047 --tk_util.DumpFinRec(x_asset_fin_rec_new, 'GN');
10048
10049 if (p_log_level_rec.statement_level) then
10050 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_fin_rec_new.cost
10051 ,p_log_level_rec => p_log_level_rec);
10052 end if;
10053
10054 return TRUE;
10055 end if;
10056 */
10057
10058 -- els -- BUG# 3947146
10059
10060 if not (p_process_this_trx) then
10061 x_asset_fin_rec_new := px_asset_fin_rec;
10062 if (p_log_level_rec.statement_level) then
10063 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_fin_rec_new.cost
10064 ,p_log_level_rec => p_log_level_rec);
10065 end if;
10066
10067 return TRUE;
10068
10069 end if;
10070
10071 end if;
10072
10073 if (px_asset_fin_rec.deprn_method_code is null) then
10074 OPEN c_get_mcbk2(l_asset_id, l_transaction_header_id);
10075 FETCH c_get_mcbk2 INTO l_asset_fin_rec_adj.date_placed_in_service
10076 , l_asset_fin_rec_adj.deprn_start_date
10077 , l_asset_fin_rec_adj.deprn_method_code
10078 , l_asset_fin_rec_adj.life_in_months
10079 , l_asset_fin_rec_adj.rate_adjustment_factor
10080 , l_asset_fin_rec_adj.adjusted_cost
10081 , l_asset_fin_rec_adj.cost
10082 , l_asset_fin_rec_adj.original_cost
10083 , l_asset_fin_rec_adj.salvage_value
10084 , l_asset_fin_rec_adj.prorate_convention_code
10085 , l_asset_fin_rec_adj.prorate_date
10086 , l_asset_fin_rec_adj.cost_change_flag
10087 , l_asset_fin_rec_adj.adjustment_required_status
10088 , l_asset_fin_rec_adj.capitalize_flag
10089 , l_asset_fin_rec_adj.retirement_pending_flag
10090 , l_asset_fin_rec_adj.depreciate_flag
10091 , l_asset_fin_rec_adj.itc_amount_id
10092 , l_asset_fin_rec_adj.itc_amount
10093 , l_asset_fin_rec_adj.retirement_id
10094 , l_asset_fin_rec_adj.tax_request_id
10095 , l_asset_fin_rec_adj.itc_basis
10096 , l_asset_fin_rec_adj.basic_rate
10097 , l_asset_fin_rec_adj.adjusted_rate
10098 , l_asset_fin_rec_adj.bonus_rule
10099 , l_asset_fin_rec_adj.ceiling_name
10100 , l_asset_fin_rec_adj.recoverable_cost
10101 , l_asset_fin_rec_adj.adjusted_capacity
10102 , l_asset_fin_rec_adj.fully_rsvd_revals_counter
10103 , l_asset_fin_rec_adj.idled_flag
10104 , l_asset_fin_rec_adj.period_counter_capitalized
10105 , l_asset_fin_rec_adj.period_counter_fully_reserved
10106 , l_asset_fin_rec_adj.period_counter_fully_retired
10107 , l_asset_fin_rec_adj.production_capacity
10108 , l_asset_fin_rec_adj.reval_amortization_basis
10109 , l_asset_fin_rec_adj.reval_ceiling
10110 , l_asset_fin_rec_adj.unit_of_measure
10111 , l_asset_fin_rec_adj.unrevalued_cost
10112 , l_asset_fin_rec_adj.annual_deprn_rounding_flag
10113 , l_asset_fin_rec_adj.percent_salvage_value
10114 , l_asset_fin_rec_adj.allowed_deprn_limit
10115 , l_asset_fin_rec_adj.allowed_deprn_limit_amount
10116 , l_asset_fin_rec_adj.period_counter_life_complete
10117 , l_asset_fin_rec_adj.adjusted_recoverable_cost
10118 , l_asset_fin_rec_adj.annual_rounding_flag
10119 , l_asset_fin_rec_adj.eofy_adj_cost
10120 , l_asset_fin_rec_adj.eofy_formula_factor
10121 , l_asset_fin_rec_adj.short_fiscal_year_flag
10125 , l_asset_fin_rec_adj.remaining_life2
10122 , l_asset_fin_rec_adj.conversion_date
10123 , l_asset_fin_rec_adj.orig_deprn_start_date
10124 , l_asset_fin_rec_adj.remaining_life1
10126 , l_asset_fin_rec_adj.group_asset_id
10127 , l_asset_fin_rec_adj.old_adjusted_cost
10128 , l_asset_fin_rec_adj.formula_factor
10129 , l_asset_fin_rec_adj.salvage_type
10130 , l_asset_fin_rec_adj.deprn_limit_type
10131 , l_asset_fin_rec_adj.over_depreciate_option
10132 , l_asset_fin_rec_adj.super_group_id
10133 , l_asset_fin_rec_adj.reduction_rate
10134 , l_asset_fin_rec_adj.reduce_addition_flag
10135 , l_asset_fin_rec_adj.reduce_adjustment_flag
10136 , l_asset_fin_rec_adj.reduce_retirement_flag
10137 , l_asset_fin_rec_adj.recognize_gain_loss
10138 , l_asset_fin_rec_adj.recapture_reserve_flag
10139 , l_asset_fin_rec_adj.limit_proceeds_flag
10140 , l_asset_fin_rec_adj.terminal_gain_loss
10141 , l_asset_fin_rec_adj.tracking_method
10142 , l_asset_fin_rec_adj.exclude_fully_rsv_flag
10143 , l_asset_fin_rec_adj.excess_allocation_option
10144 , l_asset_fin_rec_adj.depreciation_option
10145 , l_asset_fin_rec_adj.member_rollup_flag
10146 , l_asset_fin_rec_adj.ytd_proceeds
10147 , l_asset_fin_rec_adj.ltd_proceeds
10148 , l_asset_fin_rec_adj.allocate_to_fully_rsv_flag
10149 , l_asset_fin_rec_adj.allocate_to_fully_ret_flag
10150 , l_asset_fin_rec_adj.cip_cost
10151 , l_asset_fin_rec_adj.terminal_gain_loss_amount
10152 , l_asset_fin_rec_adj.ltd_cost_of_removal
10153 , l_asset_fin_rec_adj.prior_eofy_reserve
10154 , l_asset_fin_rec_adj.eofy_reserve
10155 , l_asset_fin_rec_adj.eop_adj_cost
10156 , l_asset_fin_rec_adj.eop_formula_factor
10157 , l_asset_fin_rec_adj.global_attribute1
10158 , l_asset_fin_rec_adj.global_attribute2
10159 , l_asset_fin_rec_adj.global_attribute3
10160 , l_asset_fin_rec_adj.global_attribute4
10161 , l_asset_fin_rec_adj.global_attribute5
10162 , l_asset_fin_rec_adj.global_attribute6
10163 , l_asset_fin_rec_adj.global_attribute7
10164 , l_asset_fin_rec_adj.global_attribute8
10165 , l_asset_fin_rec_adj.global_attribute9
10166 , l_asset_fin_rec_adj.global_attribute10
10167 , l_asset_fin_rec_adj.global_attribute11
10168 , l_asset_fin_rec_adj.global_attribute12
10169 , l_asset_fin_rec_adj.global_attribute13
10170 , l_asset_fin_rec_adj.global_attribute14
10171 , l_asset_fin_rec_adj.global_attribute15
10172 , l_asset_fin_rec_adj.global_attribute16
10173 , l_asset_fin_rec_adj.global_attribute17
10174 , l_asset_fin_rec_adj.global_attribute18
10175 , l_asset_fin_rec_adj.global_attribute19
10176 , l_asset_fin_rec_adj.global_attribute20
10177 , l_asset_fin_rec_adj.global_attribute_category;
10178 l_adj_found := c_get_mcbk2%FOUND;
10179 CLOSE c_get_mcbk2;
10180
10181 else
10182 OPEN c_get_mcbk(l_asset_id, l_transaction_header_id);
10183 FETCH c_get_mcbk INTO l_asset_fin_rec_adj.date_placed_in_service
10184 , l_asset_fin_rec_adj.deprn_start_date
10185 , l_asset_fin_rec_adj.deprn_method_code
10186 , l_asset_fin_rec_adj.life_in_months
10187 , l_asset_fin_rec_adj.rate_adjustment_factor
10188 , l_asset_fin_rec_adj.adjusted_cost
10189 , l_asset_fin_rec_adj.cost
10190 , l_asset_fin_rec_adj.original_cost
10191 , l_asset_fin_rec_adj.salvage_value
10192 , l_asset_fin_rec_adj.prorate_convention_code
10193 , l_asset_fin_rec_adj.prorate_date
10194 , l_asset_fin_rec_adj.cost_change_flag
10195 , l_asset_fin_rec_adj.adjustment_required_status
10196 , l_asset_fin_rec_adj.capitalize_flag
10197 , l_asset_fin_rec_adj.retirement_pending_flag
10198 , l_asset_fin_rec_adj.depreciate_flag
10199 , l_asset_fin_rec_adj.itc_amount_id
10200 , l_asset_fin_rec_adj.itc_amount
10201 , l_asset_fin_rec_adj.retirement_id
10202 , l_asset_fin_rec_adj.tax_request_id
10203 , l_asset_fin_rec_adj.itc_basis
10204 , l_asset_fin_rec_adj.basic_rate
10205 , l_asset_fin_rec_adj.adjusted_rate
10206 , l_asset_fin_rec_adj.bonus_rule
10207 , l_asset_fin_rec_adj.ceiling_name
10208 , l_asset_fin_rec_adj.recoverable_cost
10209 , l_asset_fin_rec_adj.adjusted_capacity
10213 , l_asset_fin_rec_adj.period_counter_fully_reserved
10210 , l_asset_fin_rec_adj.fully_rsvd_revals_counter
10211 , l_asset_fin_rec_adj.idled_flag
10212 , l_asset_fin_rec_adj.period_counter_capitalized
10214 , l_asset_fin_rec_adj.period_counter_fully_retired
10215 , l_asset_fin_rec_adj.production_capacity
10216 , l_asset_fin_rec_adj.reval_amortization_basis
10217 , l_asset_fin_rec_adj.reval_ceiling
10218 , l_asset_fin_rec_adj.unit_of_measure
10219 , l_asset_fin_rec_adj.unrevalued_cost
10220 , l_asset_fin_rec_adj.annual_deprn_rounding_flag
10221 , l_asset_fin_rec_adj.percent_salvage_value
10222 , l_asset_fin_rec_adj.allowed_deprn_limit
10223 , l_asset_fin_rec_adj.allowed_deprn_limit_amount
10224 , l_asset_fin_rec_adj.period_counter_life_complete
10225 , l_asset_fin_rec_adj.adjusted_recoverable_cost
10226 , l_asset_fin_rec_adj.annual_rounding_flag
10227 , l_asset_fin_rec_adj.eofy_adj_cost
10228 , l_asset_fin_rec_adj.eofy_formula_factor
10229 , l_asset_fin_rec_adj.short_fiscal_year_flag
10230 , l_asset_fin_rec_adj.conversion_date
10231 , l_asset_fin_rec_adj.orig_deprn_start_date
10232 , l_asset_fin_rec_adj.remaining_life1
10233 , l_asset_fin_rec_adj.remaining_life2
10234 , l_asset_fin_rec_adj.group_asset_id
10235 , l_asset_fin_rec_adj.old_adjusted_cost
10236 , l_asset_fin_rec_adj.formula_factor
10237 , l_asset_fin_rec_adj.salvage_type
10238 , l_asset_fin_rec_adj.deprn_limit_type
10239 , l_asset_fin_rec_adj.over_depreciate_option
10240 , l_asset_fin_rec_adj.super_group_id
10241 , l_asset_fin_rec_adj.reduction_rate
10242 , l_asset_fin_rec_adj.reduce_addition_flag
10243 , l_asset_fin_rec_adj.reduce_adjustment_flag
10244 , l_asset_fin_rec_adj.reduce_retirement_flag
10245 , l_asset_fin_rec_adj.recognize_gain_loss
10246 , l_asset_fin_rec_adj.recapture_reserve_flag
10247 , l_asset_fin_rec_adj.limit_proceeds_flag
10248 , l_asset_fin_rec_adj.terminal_gain_loss
10249 , l_asset_fin_rec_adj.tracking_method
10250 , l_asset_fin_rec_adj.exclude_fully_rsv_flag
10251 , l_asset_fin_rec_adj.excess_allocation_option
10252 , l_asset_fin_rec_adj.depreciation_option
10253 , l_asset_fin_rec_adj.member_rollup_flag
10254 , l_asset_fin_rec_adj.ytd_proceeds
10255 , l_asset_fin_rec_adj.ltd_proceeds
10256 , l_asset_fin_rec_adj.allocate_to_fully_rsv_flag
10257 , l_asset_fin_rec_adj.allocate_to_fully_ret_flag
10258 , l_asset_fin_rec_adj.cip_cost
10259 , l_asset_fin_rec_adj.terminal_gain_loss_amount
10260 , l_asset_fin_rec_adj.ltd_cost_of_removal
10261 , l_asset_fin_rec_adj.prior_eofy_reserve
10262 , l_asset_fin_rec_adj.eofy_reserve
10263 , l_asset_fin_rec_adj.eop_adj_cost
10264 , l_asset_fin_rec_adj.eop_formula_factor
10265 , l_asset_fin_rec_adj.global_attribute1
10266 , l_asset_fin_rec_adj.global_attribute2
10267 , l_asset_fin_rec_adj.global_attribute3
10268 , l_asset_fin_rec_adj.global_attribute4
10269 , l_asset_fin_rec_adj.global_attribute5
10270 , l_asset_fin_rec_adj.global_attribute6
10271 , l_asset_fin_rec_adj.global_attribute7
10272 , l_asset_fin_rec_adj.global_attribute8
10273 , l_asset_fin_rec_adj.global_attribute9
10274 , l_asset_fin_rec_adj.global_attribute10
10275 , l_asset_fin_rec_adj.global_attribute11
10276 , l_asset_fin_rec_adj.global_attribute12
10277 , l_asset_fin_rec_adj.global_attribute13
10278 , l_asset_fin_rec_adj.global_attribute14
10279 , l_asset_fin_rec_adj.global_attribute15
10280 , l_asset_fin_rec_adj.global_attribute16
10281 , l_asset_fin_rec_adj.global_attribute17
10282 , l_asset_fin_rec_adj.global_attribute18
10283 , l_asset_fin_rec_adj.global_attribute19
10284 , l_asset_fin_rec_adj.global_attribute20
10285 , l_asset_fin_rec_adj.global_attribute_category;
10286 l_adj_found := c_get_mcbk%FOUND;
10287 CLOSE c_get_mcbk;
10288
10289 end if; -- (px_asset_fin_rec.deprn_method_code is null)
10290
10291 if (p_log_level_rec.statement_level) then
10292 fa_debug_pkg.add(l_calling_fn, 'Got bk to find delta from db',
10293 l_asset_fin_rec_adj.cost
10294 ,p_log_level_rec => p_log_level_rec);
10295 end if;
10296
10297 else
10298 if (px_asset_fin_rec.date_placed_in_service is null) then
10302 FETCH c_get_init_bk INTO px_asset_fin_rec.date_placed_in_service
10299
10300 if p_init_transaction_header_id is null then
10301 OPEN c_get_init_bk;
10303 , px_asset_fin_rec.deprn_start_date
10304 , px_asset_fin_rec.deprn_method_code
10305 , px_asset_fin_rec.life_in_months
10306 , px_asset_fin_rec.rate_adjustment_factor
10307 , px_asset_fin_rec.adjusted_cost
10308 , px_asset_fin_rec.cost
10309 , px_asset_fin_rec.original_cost
10310 , px_asset_fin_rec.salvage_value
10311 , px_asset_fin_rec.prorate_convention_code
10312 , px_asset_fin_rec.prorate_date
10313 , px_asset_fin_rec.cost_change_flag
10314 , px_asset_fin_rec.adjustment_required_status
10315 , px_asset_fin_rec.capitalize_flag
10316 , px_asset_fin_rec.retirement_pending_flag
10317 , px_asset_fin_rec.depreciate_flag
10318 , px_asset_fin_rec.itc_amount_id
10319 , px_asset_fin_rec.itc_amount
10320 , px_asset_fin_rec.retirement_id
10321 , px_asset_fin_rec.tax_request_id
10322 , px_asset_fin_rec.itc_basis
10323 , px_asset_fin_rec.basic_rate
10324 , px_asset_fin_rec.adjusted_rate
10325 , px_asset_fin_rec.bonus_rule
10326 , px_asset_fin_rec.ceiling_name
10327 , px_asset_fin_rec.recoverable_cost
10328 , px_asset_fin_rec.adjusted_capacity
10329 , px_asset_fin_rec.fully_rsvd_revals_counter
10330 , px_asset_fin_rec.idled_flag
10331 , px_asset_fin_rec.period_counter_capitalized
10332 , px_asset_fin_rec.period_counter_fully_reserved
10333 , px_asset_fin_rec.period_counter_fully_retired
10334 , px_asset_fin_rec.production_capacity
10335 , px_asset_fin_rec.reval_amortization_basis
10336 , px_asset_fin_rec.reval_ceiling
10337 , px_asset_fin_rec.unit_of_measure
10338 , px_asset_fin_rec.unrevalued_cost
10339 , px_asset_fin_rec.annual_deprn_rounding_flag
10340 , px_asset_fin_rec.percent_salvage_value
10341 , px_asset_fin_rec.allowed_deprn_limit
10342 , px_asset_fin_rec.allowed_deprn_limit_amount
10343 , px_asset_fin_rec.period_counter_life_complete
10344 , px_asset_fin_rec.adjusted_recoverable_cost
10345 , px_asset_fin_rec.annual_rounding_flag
10346 , px_asset_fin_rec.eofy_adj_cost
10347 , px_asset_fin_rec.eofy_formula_factor
10348 , px_asset_fin_rec.short_fiscal_year_flag
10349 , px_asset_fin_rec.conversion_date
10350 , px_asset_fin_rec.orig_deprn_start_date
10351 , px_asset_fin_rec.remaining_life1
10352 , px_asset_fin_rec.remaining_life2
10353 , px_asset_fin_rec.group_asset_id
10354 , px_asset_fin_rec.old_adjusted_cost
10355 , px_asset_fin_rec.formula_factor
10356 , px_asset_fin_rec.salvage_type
10357 , px_asset_fin_rec.deprn_limit_type
10358 , px_asset_fin_rec.over_depreciate_option
10359 , px_asset_fin_rec.super_group_id
10360 , px_asset_fin_rec.reduction_rate
10361 , px_asset_fin_rec.reduce_addition_flag
10362 , px_asset_fin_rec.reduce_adjustment_flag
10363 , px_asset_fin_rec.reduce_retirement_flag
10364 , px_asset_fin_rec.recognize_gain_loss
10365 , px_asset_fin_rec.recapture_reserve_flag
10366 , px_asset_fin_rec.limit_proceeds_flag
10367 , px_asset_fin_rec.terminal_gain_loss
10368 , px_asset_fin_rec.tracking_method
10369 , px_asset_fin_rec.exclude_fully_rsv_flag
10370 , px_asset_fin_rec.excess_allocation_option
10371 , px_asset_fin_rec.depreciation_option
10372 , px_asset_fin_rec.member_rollup_flag
10373 , px_asset_fin_rec.ytd_proceeds
10374 , px_asset_fin_rec.ltd_proceeds
10375 , px_asset_fin_rec.allocate_to_fully_rsv_flag
10376 , px_asset_fin_rec.allocate_to_fully_ret_flag
10377 , px_asset_fin_rec.cip_cost
10378 , px_asset_fin_rec.terminal_gain_loss_amount
10379 , px_asset_fin_rec.ltd_cost_of_removal
10380 , px_asset_fin_rec.prior_eofy_reserve
10381 , px_asset_fin_rec.eofy_reserve
10382 , px_asset_fin_rec.eop_adj_cost
10383 , px_asset_fin_rec.eop_formula_factor
10387 , px_asset_fin_rec.global_attribute4
10384 , px_asset_fin_rec.global_attribute1
10385 , px_asset_fin_rec.global_attribute2
10386 , px_asset_fin_rec.global_attribute3
10388 , px_asset_fin_rec.global_attribute5
10389 , px_asset_fin_rec.global_attribute6
10390 , px_asset_fin_rec.global_attribute7
10391 , px_asset_fin_rec.global_attribute8
10392 , px_asset_fin_rec.global_attribute9
10393 , px_asset_fin_rec.global_attribute10
10394 , px_asset_fin_rec.global_attribute11
10395 , px_asset_fin_rec.global_attribute12
10396 , px_asset_fin_rec.global_attribute13
10397 , px_asset_fin_rec.global_attribute14
10398 , px_asset_fin_rec.global_attribute15
10399 , px_asset_fin_rec.global_attribute16
10400 , px_asset_fin_rec.global_attribute17
10401 , px_asset_fin_rec.global_attribute18
10402 , px_asset_fin_rec.global_attribute19
10403 , px_asset_fin_rec.global_attribute20
10404 , px_asset_fin_rec.global_attribute_category;
10405 CLOSE c_get_init_bk;
10406 else
10407 OPEN c_get_init_bk_winit;
10408 FETCH c_get_init_bk_winit INTO px_asset_fin_rec.date_placed_in_service
10409 , px_asset_fin_rec.deprn_start_date
10410 , px_asset_fin_rec.deprn_method_code
10411 , px_asset_fin_rec.life_in_months
10412 , px_asset_fin_rec.rate_adjustment_factor
10413 , px_asset_fin_rec.adjusted_cost
10414 , px_asset_fin_rec.cost
10415 , px_asset_fin_rec.original_cost
10416 , px_asset_fin_rec.salvage_value
10417 , px_asset_fin_rec.prorate_convention_code
10418 , px_asset_fin_rec.prorate_date
10419 , px_asset_fin_rec.cost_change_flag
10420 , px_asset_fin_rec.adjustment_required_status
10421 , px_asset_fin_rec.capitalize_flag
10422 , px_asset_fin_rec.retirement_pending_flag
10423 , px_asset_fin_rec.depreciate_flag
10424 , px_asset_fin_rec.itc_amount_id
10425 , px_asset_fin_rec.itc_amount
10426 , px_asset_fin_rec.retirement_id
10427 , px_asset_fin_rec.tax_request_id
10428 , px_asset_fin_rec.itc_basis
10429 , px_asset_fin_rec.basic_rate
10430 , px_asset_fin_rec.adjusted_rate
10431 , px_asset_fin_rec.bonus_rule
10432 , px_asset_fin_rec.ceiling_name
10433 , px_asset_fin_rec.recoverable_cost
10434 , px_asset_fin_rec.adjusted_capacity
10435 , px_asset_fin_rec.fully_rsvd_revals_counter
10436 , px_asset_fin_rec.idled_flag
10437 , px_asset_fin_rec.period_counter_capitalized
10438 , px_asset_fin_rec.period_counter_fully_reserved
10439 , px_asset_fin_rec.period_counter_fully_retired
10440 , px_asset_fin_rec.production_capacity
10441 , px_asset_fin_rec.reval_amortization_basis
10442 , px_asset_fin_rec.reval_ceiling
10443 , px_asset_fin_rec.unit_of_measure
10444 , px_asset_fin_rec.unrevalued_cost
10445 , px_asset_fin_rec.annual_deprn_rounding_flag
10446 , px_asset_fin_rec.percent_salvage_value
10447 , px_asset_fin_rec.allowed_deprn_limit
10448 , px_asset_fin_rec.allowed_deprn_limit_amount
10449 , px_asset_fin_rec.period_counter_life_complete
10450 , px_asset_fin_rec.adjusted_recoverable_cost
10451 , px_asset_fin_rec.annual_rounding_flag
10452 , px_asset_fin_rec.eofy_adj_cost
10453 , px_asset_fin_rec.eofy_formula_factor
10454 , px_asset_fin_rec.short_fiscal_year_flag
10455 , px_asset_fin_rec.conversion_date
10456 , px_asset_fin_rec.orig_deprn_start_date
10457 , px_asset_fin_rec.remaining_life1
10458 , px_asset_fin_rec.remaining_life2
10459 , px_asset_fin_rec.group_asset_id
10460 , px_asset_fin_rec.old_adjusted_cost
10461 , px_asset_fin_rec.formula_factor
10462 , px_asset_fin_rec.salvage_type
10463 , px_asset_fin_rec.deprn_limit_type
10464 , px_asset_fin_rec.over_depreciate_option
10465 , px_asset_fin_rec.super_group_id
10466 , px_asset_fin_rec.reduction_rate
10467 , px_asset_fin_rec.reduce_addition_flag
10468 , px_asset_fin_rec.reduce_adjustment_flag
10472 , px_asset_fin_rec.limit_proceeds_flag
10469 , px_asset_fin_rec.reduce_retirement_flag
10470 , px_asset_fin_rec.recognize_gain_loss
10471 , px_asset_fin_rec.recapture_reserve_flag
10473 , px_asset_fin_rec.terminal_gain_loss
10474 , px_asset_fin_rec.tracking_method
10475 , px_asset_fin_rec.exclude_fully_rsv_flag
10476 , px_asset_fin_rec.excess_allocation_option
10477 , px_asset_fin_rec.depreciation_option
10478 , px_asset_fin_rec.member_rollup_flag
10479 , px_asset_fin_rec.ytd_proceeds
10480 , px_asset_fin_rec.ltd_proceeds
10481 , px_asset_fin_rec.allocate_to_fully_rsv_flag
10482 , px_asset_fin_rec.allocate_to_fully_ret_flag
10483 , px_asset_fin_rec.cip_cost
10484 , px_asset_fin_rec.terminal_gain_loss_amount
10485 , px_asset_fin_rec.ltd_cost_of_removal
10486 , px_asset_fin_rec.prior_eofy_reserve
10487 , px_asset_fin_rec.eofy_reserve
10488 , px_asset_fin_rec.eop_adj_cost
10489 , px_asset_fin_rec.eop_formula_factor
10490 , px_asset_fin_rec.global_attribute1
10491 , px_asset_fin_rec.global_attribute2
10492 , px_asset_fin_rec.global_attribute3
10493 , px_asset_fin_rec.global_attribute4
10494 , px_asset_fin_rec.global_attribute5
10495 , px_asset_fin_rec.global_attribute6
10496 , px_asset_fin_rec.global_attribute7
10497 , px_asset_fin_rec.global_attribute8
10498 , px_asset_fin_rec.global_attribute9
10499 , px_asset_fin_rec.global_attribute10
10500 , px_asset_fin_rec.global_attribute11
10501 , px_asset_fin_rec.global_attribute12
10502 , px_asset_fin_rec.global_attribute13
10503 , px_asset_fin_rec.global_attribute14
10504 , px_asset_fin_rec.global_attribute15
10505 , px_asset_fin_rec.global_attribute16
10506 , px_asset_fin_rec.global_attribute17
10507 , px_asset_fin_rec.global_attribute18
10508 , px_asset_fin_rec.global_attribute19
10509 , px_asset_fin_rec.global_attribute20
10510 , px_asset_fin_rec.global_attribute_category;
10511 CLOSE c_get_init_bk_winit;
10512
10513 end if;
10514
10515 if (p_log_level_rec.statement_level) then
10516 fa_debug_pkg.add(l_calling_fn, 'Found initial fin_rec from db',
10517 px_asset_fin_rec.cost
10518 ,p_log_level_rec => p_log_level_rec);
10519 end if;
10520 /*
10521 if p_trans_rec.transaction_type_code in
10522 (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET) and
10523 not (p_use_fin_rec_adj) then
10524
10525 x_asset_fin_rec_new := px_asset_fin_rec;
10526
10527 --tk_util.DumpFinRec(px_asset_fin_rec, 'GO2');
10528 --tk_util.DumpFinRec(x_asset_fin_rec_new, 'GN');
10529
10530 if (p_log_level_rec.statement_level) then
10531 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_fin_rec_new.cost
10532 ,p_log_level_rec => p_log_level_rec);
10533 end if;
10534
10535 return TRUE;
10536
10537 els*/if not (p_process_this_trx) then
10538 x_asset_fin_rec_new := px_asset_fin_rec;
10539 if (p_log_level_rec.statement_level) then
10540 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_fin_rec_new.cost
10541 ,p_log_level_rec => p_log_level_rec);
10542 end if;
10543
10544 return TRUE;
10545 end if;
10546
10547 end if;
10548
10549 if (px_asset_fin_rec.deprn_method_code is null) then
10550 OPEN c_get_bk2(l_asset_id, l_transaction_header_id);
10551 FETCH c_get_bk2 INTO l_asset_fin_rec_adj.date_placed_in_service
10552 , l_asset_fin_rec_adj.deprn_start_date
10553 , l_asset_fin_rec_adj.deprn_method_code
10554 , l_asset_fin_rec_adj.life_in_months
10555 , l_asset_fin_rec_adj.rate_adjustment_factor
10556 , l_asset_fin_rec_adj.adjusted_cost
10557 , l_asset_fin_rec_adj.cost
10558 , l_asset_fin_rec_adj.original_cost
10559 , l_asset_fin_rec_adj.salvage_value
10560 , l_asset_fin_rec_adj.prorate_convention_code
10561 , l_asset_fin_rec_adj.prorate_date
10562 , l_asset_fin_rec_adj.cost_change_flag
10563 , l_asset_fin_rec_adj.adjustment_required_status
10564 , l_asset_fin_rec_adj.capitalize_flag
10565 , l_asset_fin_rec_adj.retirement_pending_flag
10566 , l_asset_fin_rec_adj.depreciate_flag
10567 , l_asset_fin_rec_adj.itc_amount_id
10568 , l_asset_fin_rec_adj.itc_amount
10572 , l_asset_fin_rec_adj.basic_rate
10569 , l_asset_fin_rec_adj.retirement_id
10570 , l_asset_fin_rec_adj.tax_request_id
10571 , l_asset_fin_rec_adj.itc_basis
10573 , l_asset_fin_rec_adj.adjusted_rate
10574 , l_asset_fin_rec_adj.bonus_rule
10575 , l_asset_fin_rec_adj.ceiling_name
10576 , l_asset_fin_rec_adj.recoverable_cost
10577 , l_asset_fin_rec_adj.adjusted_capacity
10578 , l_asset_fin_rec_adj.fully_rsvd_revals_counter
10579 , l_asset_fin_rec_adj.idled_flag
10580 , l_asset_fin_rec_adj.period_counter_capitalized
10581 , l_asset_fin_rec_adj.period_counter_fully_reserved
10582 , l_asset_fin_rec_adj.period_counter_fully_retired
10583 , l_asset_fin_rec_adj.production_capacity
10584 , l_asset_fin_rec_adj.reval_amortization_basis
10585 , l_asset_fin_rec_adj.reval_ceiling
10586 , l_asset_fin_rec_adj.unit_of_measure
10587 , l_asset_fin_rec_adj.unrevalued_cost
10588 , l_asset_fin_rec_adj.annual_deprn_rounding_flag
10589 , l_asset_fin_rec_adj.percent_salvage_value
10590 , l_asset_fin_rec_adj.allowed_deprn_limit
10591 , l_asset_fin_rec_adj.allowed_deprn_limit_amount
10592 , l_asset_fin_rec_adj.period_counter_life_complete
10593 , l_asset_fin_rec_adj.adjusted_recoverable_cost
10594 , l_asset_fin_rec_adj.annual_rounding_flag
10595 , l_asset_fin_rec_adj.eofy_adj_cost
10596 , l_asset_fin_rec_adj.eofy_formula_factor
10597 , l_asset_fin_rec_adj.short_fiscal_year_flag
10598 , l_asset_fin_rec_adj.conversion_date
10599 , l_asset_fin_rec_adj.orig_deprn_start_date
10600 , l_asset_fin_rec_adj.remaining_life1
10601 , l_asset_fin_rec_adj.remaining_life2
10602 , l_asset_fin_rec_adj.group_asset_id
10603 , l_asset_fin_rec_adj.old_adjusted_cost
10604 , l_asset_fin_rec_adj.formula_factor
10605 , l_asset_fin_rec_adj.salvage_type
10606 , l_asset_fin_rec_adj.deprn_limit_type
10607 , l_asset_fin_rec_adj.over_depreciate_option
10608 , l_asset_fin_rec_adj.super_group_id
10609 , l_asset_fin_rec_adj.reduction_rate
10610 , l_asset_fin_rec_adj.reduce_addition_flag
10611 , l_asset_fin_rec_adj.reduce_adjustment_flag
10612 , l_asset_fin_rec_adj.reduce_retirement_flag
10613 , l_asset_fin_rec_adj.recognize_gain_loss
10614 , l_asset_fin_rec_adj.recapture_reserve_flag
10615 , l_asset_fin_rec_adj.limit_proceeds_flag
10616 , l_asset_fin_rec_adj.terminal_gain_loss
10617 , l_asset_fin_rec_adj.tracking_method
10618 , l_asset_fin_rec_adj.exclude_fully_rsv_flag
10619 , l_asset_fin_rec_adj.excess_allocation_option
10620 , l_asset_fin_rec_adj.depreciation_option
10621 , l_asset_fin_rec_adj.member_rollup_flag
10622 , l_asset_fin_rec_adj.ytd_proceeds
10623 , l_asset_fin_rec_adj.ltd_proceeds
10624 , l_asset_fin_rec_adj.allocate_to_fully_rsv_flag
10625 , l_asset_fin_rec_adj.allocate_to_fully_ret_flag
10626 , l_asset_fin_rec_adj.cip_cost
10627 , l_asset_fin_rec_adj.terminal_gain_loss_amount
10628 , l_asset_fin_rec_adj.ltd_cost_of_removal
10629 , l_asset_fin_rec_adj.prior_eofy_reserve
10630 , l_asset_fin_rec_adj.eofy_reserve
10631 , l_asset_fin_rec_adj.eop_adj_cost
10632 , l_asset_fin_rec_adj.eop_formula_factor
10633 , l_asset_fin_rec_adj.global_attribute1
10634 , l_asset_fin_rec_adj.global_attribute2
10635 , l_asset_fin_rec_adj.global_attribute3
10636 , l_asset_fin_rec_adj.global_attribute4
10637 , l_asset_fin_rec_adj.global_attribute5
10638 , l_asset_fin_rec_adj.global_attribute6
10639 , l_asset_fin_rec_adj.global_attribute7
10640 , l_asset_fin_rec_adj.global_attribute8
10641 , l_asset_fin_rec_adj.global_attribute9
10642 , l_asset_fin_rec_adj.global_attribute10
10643 , l_asset_fin_rec_adj.global_attribute11
10644 , l_asset_fin_rec_adj.global_attribute12
10645 , l_asset_fin_rec_adj.global_attribute13
10646 , l_asset_fin_rec_adj.global_attribute14
10647 , l_asset_fin_rec_adj.global_attribute15
10648 , l_asset_fin_rec_adj.global_attribute16
10649 , l_asset_fin_rec_adj.global_attribute17
10650 , l_asset_fin_rec_adj.global_attribute18
10651 , l_asset_fin_rec_adj.global_attribute19
10652 , l_asset_fin_rec_adj.global_attribute20
10653 , l_asset_fin_rec_adj.global_attribute_category;
10657 --tk_util.DumpFinRec(l_asset_fin_rec_adj, 'GO2.5');
10654 l_adj_found := c_get_bk2%FOUND;
10655 CLOSE c_get_bk2;
10656
10658 else
10659 OPEN c_get_bk(l_asset_id, l_transaction_header_id);
10660 FETCH c_get_bk INTO l_asset_fin_rec_adj.date_placed_in_service
10661 , l_asset_fin_rec_adj.deprn_start_date
10662 , l_asset_fin_rec_adj.deprn_method_code
10663 , l_asset_fin_rec_adj.life_in_months
10664 , l_asset_fin_rec_adj.rate_adjustment_factor
10665 , l_asset_fin_rec_adj.adjusted_cost
10666 , l_asset_fin_rec_adj.cost
10667 , l_asset_fin_rec_adj.original_cost
10668 , l_asset_fin_rec_adj.salvage_value
10669 , l_asset_fin_rec_adj.prorate_convention_code
10670 , l_asset_fin_rec_adj.prorate_date
10671 , l_asset_fin_rec_adj.cost_change_flag
10672 , l_asset_fin_rec_adj.adjustment_required_status
10673 , l_asset_fin_rec_adj.capitalize_flag
10674 , l_asset_fin_rec_adj.retirement_pending_flag
10675 , l_asset_fin_rec_adj.depreciate_flag
10676 , l_asset_fin_rec_adj.itc_amount_id
10677 , l_asset_fin_rec_adj.itc_amount
10678 , l_asset_fin_rec_adj.retirement_id
10679 , l_asset_fin_rec_adj.tax_request_id
10680 , l_asset_fin_rec_adj.itc_basis
10681 , l_asset_fin_rec_adj.basic_rate
10682 , l_asset_fin_rec_adj.adjusted_rate
10683 , l_asset_fin_rec_adj.bonus_rule
10684 , l_asset_fin_rec_adj.ceiling_name
10685 , l_asset_fin_rec_adj.recoverable_cost
10686 , l_asset_fin_rec_adj.adjusted_capacity
10687 , l_asset_fin_rec_adj.fully_rsvd_revals_counter
10688 , l_asset_fin_rec_adj.idled_flag
10689 , l_asset_fin_rec_adj.period_counter_capitalized
10690 , l_asset_fin_rec_adj.period_counter_fully_reserved
10691 , l_asset_fin_rec_adj.period_counter_fully_retired
10692 , l_asset_fin_rec_adj.production_capacity
10693 , l_asset_fin_rec_adj.reval_amortization_basis
10694 , l_asset_fin_rec_adj.reval_ceiling
10695 , l_asset_fin_rec_adj.unit_of_measure
10696 , l_asset_fin_rec_adj.unrevalued_cost
10697 , l_asset_fin_rec_adj.annual_deprn_rounding_flag
10698 , l_asset_fin_rec_adj.percent_salvage_value
10699 , l_asset_fin_rec_adj.allowed_deprn_limit
10700 , l_asset_fin_rec_adj.allowed_deprn_limit_amount
10701 , l_asset_fin_rec_adj.period_counter_life_complete
10702 , l_asset_fin_rec_adj.adjusted_recoverable_cost
10703 , l_asset_fin_rec_adj.annual_rounding_flag
10704 , l_asset_fin_rec_adj.eofy_adj_cost
10705 , l_asset_fin_rec_adj.eofy_formula_factor
10706 , l_asset_fin_rec_adj.short_fiscal_year_flag
10707 , l_asset_fin_rec_adj.conversion_date
10708 , l_asset_fin_rec_adj.orig_deprn_start_date
10709 , l_asset_fin_rec_adj.remaining_life1
10710 , l_asset_fin_rec_adj.remaining_life2
10711 , l_asset_fin_rec_adj.group_asset_id
10712 , l_asset_fin_rec_adj.old_adjusted_cost
10713 , l_asset_fin_rec_adj.formula_factor
10714 , l_asset_fin_rec_adj.salvage_type
10715 , l_asset_fin_rec_adj.deprn_limit_type
10716 , l_asset_fin_rec_adj.over_depreciate_option
10717 , l_asset_fin_rec_adj.super_group_id
10718 , l_asset_fin_rec_adj.reduction_rate
10719 , l_asset_fin_rec_adj.reduce_addition_flag
10720 , l_asset_fin_rec_adj.reduce_adjustment_flag
10721 , l_asset_fin_rec_adj.reduce_retirement_flag
10722 , l_asset_fin_rec_adj.recognize_gain_loss
10723 , l_asset_fin_rec_adj.recapture_reserve_flag
10724 , l_asset_fin_rec_adj.limit_proceeds_flag
10725 , l_asset_fin_rec_adj.terminal_gain_loss
10726 , l_asset_fin_rec_adj.tracking_method
10727 , l_asset_fin_rec_adj.exclude_fully_rsv_flag
10728 , l_asset_fin_rec_adj.excess_allocation_option
10729 , l_asset_fin_rec_adj.depreciation_option
10730 , l_asset_fin_rec_adj.member_rollup_flag
10731 , l_asset_fin_rec_adj.ytd_proceeds
10732 , l_asset_fin_rec_adj.ltd_proceeds
10733 , l_asset_fin_rec_adj.allocate_to_fully_rsv_flag
10734 , l_asset_fin_rec_adj.allocate_to_fully_ret_flag
10735 , l_asset_fin_rec_adj.cip_cost
10736 , l_asset_fin_rec_adj.terminal_gain_loss_amount
10737 , l_asset_fin_rec_adj.ltd_cost_of_removal
10738 , l_asset_fin_rec_adj.prior_eofy_reserve
10739 , l_asset_fin_rec_adj.eofy_reserve
10740 , l_asset_fin_rec_adj.eop_adj_cost
10741 , l_asset_fin_rec_adj.eop_formula_factor
10745 , l_asset_fin_rec_adj.global_attribute4
10742 , l_asset_fin_rec_adj.global_attribute1
10743 , l_asset_fin_rec_adj.global_attribute2
10744 , l_asset_fin_rec_adj.global_attribute3
10746 , l_asset_fin_rec_adj.global_attribute5
10747 , l_asset_fin_rec_adj.global_attribute6
10748 , l_asset_fin_rec_adj.global_attribute7
10749 , l_asset_fin_rec_adj.global_attribute8
10750 , l_asset_fin_rec_adj.global_attribute9
10751 , l_asset_fin_rec_adj.global_attribute10
10752 , l_asset_fin_rec_adj.global_attribute11
10753 , l_asset_fin_rec_adj.global_attribute12
10754 , l_asset_fin_rec_adj.global_attribute13
10755 , l_asset_fin_rec_adj.global_attribute14
10756 , l_asset_fin_rec_adj.global_attribute15
10757 , l_asset_fin_rec_adj.global_attribute16
10758 , l_asset_fin_rec_adj.global_attribute17
10759 , l_asset_fin_rec_adj.global_attribute18
10760 , l_asset_fin_rec_adj.global_attribute19
10761 , l_asset_fin_rec_adj.global_attribute20
10762 , l_asset_fin_rec_adj.global_attribute_category;
10763 l_adj_found := c_get_bk%FOUND;
10764 CLOSE c_get_bk;
10765 end if; -- (px_asset_fin_rec.deprn_method_code is null)
10766
10767 if (p_log_level_rec.statement_level) then
10768 fa_debug_pkg.add(l_calling_fn, 'Got bk to find delta from db',
10769 l_asset_fin_rec_adj.cost
10770 ,p_log_level_rec => p_log_level_rec);
10771 end if;
10772
10773
10774 end if; -- (nvl(p_mrc_sob_type_code, 'P') = 'R')
10775
10776 --tk_util.DumpFinRec(px_asset_fin_rec, 'GO2');
10777
10778 l_reclass_trx := (nvl(px_asset_fin_rec.group_asset_id, 0) <>
10779 nvl(l_asset_fin_rec_adj.group_asset_id, px_asset_fin_rec.group_asset_id)); -- bug# 5383699
10780
10781 if (p_log_level_rec.statement_level) then
10782 fa_debug_pkg.add(l_calling_fn, 'p_use_fin_rec_adj', p_use_fin_rec_adj
10783 ,p_log_level_rec => p_log_level_rec);
10784 end if;
10785
10786 if ((not(p_use_fin_rec_adj)) and
10787 (p_use_new_deprn_rule)) or
10788 (l_is_member_trx_for_group) then
10789 --
10790 -- Process transaction from db but use current rules in the case this transaction
10791 -- happened after current transaction
10792 --
10793 l_tmp_cost := l_asset_fin_rec_adj.cost;
10794 l_tmp_percent_salvage_value := l_asset_fin_rec_adj.percent_salvage_value;
10795 l_tmp_salvage_value := l_asset_fin_rec_adj.salvage_value;
10796 l_tmp_allowed_deprn_limit := l_asset_fin_rec_adj.allowed_deprn_limit;
10797 l_tmp_allowed_deprn_limit_amt := l_asset_fin_rec_adj.allowed_deprn_limit_amount;
10798 l_tmp_production_capacity := l_asset_fin_rec_adj.production_capacity;
10799 l_tmp_fully_rsv_revals_counter := l_asset_fin_rec_adj.fully_rsvd_revals_counter;
10800 l_tmp_reval_amortization_basis := l_asset_fin_rec_adj.reval_amortization_basis;
10801 l_tmp_reval_ceiling := l_asset_fin_rec_adj.reval_ceiling;
10802 l_tmp_unrevalued_cost := l_asset_fin_rec_adj.unrevalued_cost;
10803 l_tmp_eofy_reserve := l_asset_fin_rec_adj.eofy_reserve;
10804
10805 l_asset_fin_rec_adj := p_asset_fin_rec_new;
10806
10807 l_asset_fin_rec_adj.cost := l_tmp_cost;
10808 l_asset_fin_rec_adj.percent_salvage_value := l_tmp_percent_salvage_value;
10809 l_asset_fin_rec_adj.salvage_value := l_tmp_salvage_value;
10810 l_asset_fin_rec_adj.allowed_deprn_limit := l_tmp_allowed_deprn_limit;
10811 l_asset_fin_rec_adj.allowed_deprn_limit_amount := l_tmp_allowed_deprn_limit_amt;
10812 l_asset_fin_rec_adj.production_capacity :=l_tmp_production_capacity;
10813 l_asset_fin_rec_adj.fully_rsvd_revals_counter := l_tmp_fully_rsv_revals_counter;
10814 l_asset_fin_rec_adj.reval_amortization_basis := l_tmp_reval_amortization_basis;
10815 l_asset_fin_rec_adj.reval_ceiling := l_tmp_reval_ceiling;
10816 l_asset_fin_rec_adj.unrevalued_cost := l_tmp_unrevalued_cost;
10817 l_asset_fin_rec_adj.eofy_reserve := l_tmp_eofy_reserve;
10818
10819 if (p_log_level_rec.statement_level) then
10820 fa_debug_pkg.add(l_calling_fn, 'Need to use latest values except amounts',
10821 l_asset_fin_rec_adj.cost
10822 ,p_log_level_rec => p_log_level_rec);
10823 end if;
10824
10825 elsif ((p_use_fin_rec_adj) or
10826 (l_asset_fin_rec_adj.date_placed_in_service is null)) and
10827 ((not (l_adj_found)) or (l_reclass_trx)) then
10828 --
10829 -- Process current transaction
10830 --
10831 l_asset_fin_rec_adj := p_asset_fin_rec_adj;
10832 if (p_log_level_rec.statement_level) then
10833 fa_debug_pkg.add(l_calling_fn, 'This is the transaction user entered',
10834 l_asset_fin_rec_adj.cost
10835 ,p_log_level_rec => p_log_level_rec);
10836 end if;
10837
10838 else
10839 -- Process transaction from db. Current transaction has date later than this.
10840 if (p_log_level_rec.statement_level) then
10841 fa_debug_pkg.add(l_calling_fn, 'Delta comes from db', l_asset_fin_rec_adj.cost
10845
10842 ,p_log_level_rec => p_log_level_rec);
10843 end if;
10844 end if;
10846 --tk_util.DumpFinRec(l_asset_fin_rec_adj, 'GA');
10847
10848 if (instrb(p_trans_rec.transaction_type_code, 'ADDITION') <> 0) and
10849 (px_asset_fin_rec.date_placed_in_service is not null) then
10850 x_asset_fin_rec_new := px_asset_fin_rec;
10851 else
10852 x_asset_fin_rec_new := l_asset_fin_rec_adj;
10853 end if;
10854
10855 --
10856 -- Defaulting Values
10857 --
10858 x_asset_fin_rec_new.prorate_convention_code :=
10859 nvl(l_asset_fin_rec_adj.prorate_convention_code,
10860 nvl(px_asset_fin_rec.prorate_convention_code,
10861 fa_cache_pkg.fazccbd_record.prorate_convention_code));
10862
10863 x_asset_fin_rec_new.depreciate_flag :=
10864 nvl(l_asset_fin_rec_adj.depreciate_flag,
10865 nvl(px_asset_fin_rec.depreciate_flag,
10866 fa_cache_pkg.fazccbd_record.depreciate_flag));
10867
10868 FA_UTIL_PVT.load_char_value
10869 (p_char_old => px_asset_fin_rec.bonus_rule,
10870 p_char_adj => l_asset_fin_rec_adj.bonus_rule,
10871 x_char_new => x_asset_fin_rec_new.bonus_rule
10872 ,p_log_level_rec => p_log_level_rec);
10873
10874 FA_UTIL_PVT.load_char_value
10875 (p_char_old => px_asset_fin_rec.ceiling_name,
10876 p_char_adj => l_asset_fin_rec_adj.ceiling_name,
10877 x_char_new => x_asset_fin_rec_new.ceiling_name
10878 ,p_log_level_rec => p_log_level_rec);
10879
10880 -- This is for FLAT RATE EXTENSION deprn basis rule
10881 FA_UTIL_PVT.load_char_value
10882 (p_char_old => px_asset_fin_rec.exclude_fully_rsv_flag,
10883 p_char_adj => l_asset_fin_rec_adj.exclude_fully_rsv_flag,
10884 x_char_new => x_asset_fin_rec_new.exclude_fully_rsv_flag
10885 ,p_log_level_rec => p_log_level_rec);
10886
10887 x_asset_fin_rec_new.recognize_gain_loss :=
10888 p_asset_fin_rec_new.recognize_gain_loss;
10889
10890 x_asset_fin_rec_new.recapture_reserve_flag :=
10891 p_asset_fin_rec_new.recapture_reserve_flag;
10892
10893 x_asset_fin_rec_new.limit_proceeds_flag :=
10894 p_asset_fin_rec_new.limit_proceeds_flag;
10895
10896 x_asset_fin_rec_new.terminal_gain_loss :=
10897 p_asset_fin_rec_new.terminal_gain_loss;
10898
10899 x_asset_fin_rec_new.exclude_proceeds_from_basis :=
10900 p_asset_fin_rec_new.exclude_proceeds_from_basis;
10901
10902 x_asset_fin_rec_new.retirement_deprn_option :=
10903 p_asset_fin_rec_new.retirement_deprn_option;
10904
10905 x_asset_fin_rec_new.tracking_method :=
10906 p_asset_fin_rec_new.tracking_method;
10907
10908 x_asset_fin_rec_new.allocate_to_fully_rsv_flag :=
10909 p_asset_fin_rec_new.allocate_to_fully_rsv_flag;
10910
10911 x_asset_fin_rec_new.allocate_to_fully_ret_flag :=
10912 p_asset_fin_rec_new.allocate_to_fully_ret_flag;
10913
10914 x_asset_fin_rec_new.excess_allocation_option :=
10915 p_asset_fin_rec_new.excess_allocation_option;
10916
10917 x_asset_fin_rec_new.depreciation_option :=
10918 p_asset_fin_rec_new.depreciation_option;
10919
10920 x_asset_fin_rec_new.member_rollup_flag :=
10921 p_asset_fin_rec_new.member_rollup_flag;
10922
10923 if not FA_ASSET_CALC_PVT.calc_new_amounts(
10924 px_trans_rec => p_trans_rec,
10925 p_asset_hdr_rec => p_asset_hdr_rec,
10926 p_asset_desc_rec => l_asset_desc_rec,
10927 p_asset_type_rec => p_asset_type_rec,
10928 p_asset_cat_rec => l_asset_cat_rec,
10929 p_asset_fin_rec_old => px_asset_fin_rec,
10930 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
10931 px_asset_fin_rec_new => x_asset_fin_rec_new,
10932 p_asset_deprn_rec_old => l_asset_deprn_rec,
10933 p_asset_deprn_rec_adj => l_asset_deprn_rec,
10934 px_asset_deprn_rec_new => l_asset_deprn_rec,
10935 p_mrc_sob_type_code => p_mrc_sob_type_code
10936 ,p_log_level_rec => p_log_level_rec) then
10937
10938 if (p_log_level_rec.statement_level) then
10939 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
10940 'FA_ASSET_CALC_PVT.calc_new_amounts'
10941 ,p_log_level_rec => p_log_level_rec);
10942 end if;
10943
10944 raise calc_failed;
10945 end if;
10946
10947 x_asset_fin_rec_new.eofy_reserve := nvl(l_asset_fin_rec_adj.eofy_reserve, 0) +
10948 nvl(px_asset_fin_rec.eofy_reserve, 0);
10949
10950 if not FA_UTILS_PKG.faxrnd(x_asset_fin_rec_new.eofy_reserve,
10951 p_asset_hdr_rec.book_type_code
10952 ,p_log_level_rec => p_log_level_rec) then
10953 raise calc_failed;
10954 end if;
10955
10956 if not FA_ASSET_CALC_PVT.calc_prorate_date
10957 (p_asset_hdr_rec => p_asset_hdr_rec,
10958 p_asset_type_rec => p_asset_type_rec,
10959 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
10960 px_asset_fin_rec_new => x_asset_fin_rec_new,
10961 p_period_rec => l_period_rec
10965 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
10962 ,p_log_level_rec => p_log_level_rec) then
10963
10964 if (p_log_level_rec.statement_level) then
10966 'FA_ASSET_CALC_PVT.calc_prorate_date'
10967 ,p_log_level_rec => p_log_level_rec);
10968 end if;
10969
10970 raise calc_failed;
10971 end if;
10972
10973 if not FA_ASSET_CALC_PVT.calc_deprn_info
10974 (p_trans_rec => p_trans_rec,
10975 p_asset_hdr_rec => p_asset_hdr_rec,
10976 p_asset_desc_rec => l_asset_desc_rec,
10977 p_asset_cat_rec => l_asset_cat_rec,
10978 p_asset_type_rec => p_asset_type_rec,
10979 p_asset_fin_rec_old => px_asset_fin_rec,
10980 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
10981 px_asset_fin_rec_new => x_asset_fin_rec_new,
10982 p_asset_deprn_rec_adj => l_asset_deprn_rec,
10983 p_asset_deprn_rec_new => l_asset_deprn_rec,
10984 p_period_rec => l_period_rec
10985 ,p_log_level_rec => p_log_level_rec) then
10986
10987 if (p_log_level_rec.statement_level) then
10988 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
10989 'FA_ASSET_CALC_PVT.calc_deprn_info'
10990 ,p_log_level_rec => p_log_level_rec);
10991 end if;
10992
10993 raise calc_failed;
10994 end if;
10995
10996 if not FA_ASSET_CALC_PVT.calc_deprn_start_date(
10997 p_asset_hdr_rec => p_asset_hdr_rec,
10998 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
10999 px_asset_fin_rec_new => x_asset_fin_rec_new
11000 ,p_log_level_rec => p_log_level_rec) then
11001
11002 if (p_log_level_rec.statement_level) then
11003 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
11004 'FA_ASSET_CALC_PVT.calc_deprn_start_date'
11005 ,p_log_level_rec => p_log_level_rec);
11006 end if;
11007
11008 raise calc_failed;
11009 end if;
11010
11011 if not FA_ASSET_CALC_PVT.calc_salvage_value(
11012 p_trans_rec => p_trans_rec,
11013 p_asset_hdr_rec => p_asset_hdr_rec,
11014 p_asset_type_rec => p_asset_type_rec,
11015 p_asset_fin_rec_old => px_asset_fin_rec,
11016 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
11017 px_asset_fin_rec_new => x_asset_fin_rec_new,
11018 p_mrc_sob_type_code => p_mrc_sob_type_code
11019 ,p_log_level_rec => p_log_level_rec) then
11020
11021 if (p_log_level_rec.statement_level) then
11022 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
11023 'FA_ASSET_CALC_PVT.calc_salvage_value'
11024 ,p_log_level_rec => p_log_level_rec);
11025 end if;
11026
11027 raise calc_failed;
11028 end if;
11029
11030 if not FA_ASSET_CALC_PVT.calc_rec_cost
11031 (p_asset_hdr_rec => p_asset_hdr_rec,
11032 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
11033 px_asset_fin_rec_new => x_asset_fin_rec_new
11034 ,p_log_level_rec => p_log_level_rec) then
11035
11036 if (p_log_level_rec.statement_level) then
11037 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
11038 'FA_ASSET_CALC_PVT.calc_rec_cost'
11039 ,p_log_level_rec => p_log_level_rec);
11040 end if;
11041
11042 raise calc_failed;
11043 end if;
11044
11045 if not FA_ASSET_CALC_PVT.calc_deprn_limit_adj_rec_cost
11046 (p_asset_hdr_rec => p_asset_hdr_rec,
11047 p_asset_type_rec => p_asset_type_rec,
11048 p_asset_fin_rec_old => px_asset_fin_rec,
11049 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
11050 px_asset_fin_rec_new => x_asset_fin_rec_new,
11051 p_mrc_sob_type_code => p_mrc_sob_type_code
11052 ,p_log_level_rec => p_log_level_rec) then
11053
11054 if (p_log_level_rec.statement_level) then
11055 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
11056 'FA_ASSET_CALC_PVT.calc_deprn_limit_adj_rec_cost'
11057 ,p_log_level_rec => p_log_level_rec);
11058 end if;
11059
11060 raise calc_failed;
11061 end if;
11062 --tk_util.debug('adj_rec_cost: '|| to_char(x_asset_fin_rec_new.adjusted_recoverable_cost));
11063
11064
11065 if (fa_cache_pkg.fazcbc_record.book_class = 'TAX' and
11066 x_asset_fin_rec_new.itc_amount_id is not null) then
11067 if not FA_ASSET_CALC_PVT.calc_itc_info
11068 (p_asset_hdr_rec => p_asset_hdr_rec,
11069 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
11070 px_asset_fin_rec_new => x_asset_fin_rec_new
11071 ,p_log_level_rec => p_log_level_rec) then
11072
11073 if (p_log_level_rec.statement_level) then
11074 fa_debug_pkg.add(l_calling_fn, 'Falied calling',
11075 'FA_ASSET_CALC_PVT.calc_itc_info'
11076 ,p_log_level_rec => p_log_level_rec);
11077 end if;
11078
11079 raise calc_failed;
11080 end if;
11084 x_dpis_change := (px_asset_fin_rec.date_placed_in_service <> l_asset_fin_rec_adj.date_placed_in_service);
11081
11082 end if;
11083
11085
11086 --tk_util.DumpFinRec(x_asset_fin_rec_new, 'GN');
11087
11088 if (p_log_level_rec.statement_level) then
11089 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_fin_rec_new.cost
11090 ,p_log_level_rec => p_log_level_rec);
11091 end if;
11092
11093 return TRUE;
11094 EXCEPTION
11095 WHEN calc_failed THEN
11096 if (p_log_level_rec.statement_level) then
11097 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'calc_failed'
11098 ,p_log_level_rec => p_log_level_rec);
11099 end if;
11100
11101 if c_get_init_mcbk%ISOPEN then
11102 CLOSE c_get_init_mcbk;
11103 end if;
11104
11105 if c_get_init_bk%ISOPEN then
11106 CLOSE c_get_init_bk;
11107 end if;
11108
11109 if c_get_mcbk%ISOPEN then
11110 CLOSE c_get_mcbk;
11111 end if;
11112
11113 if c_get_bk%ISOPEN then
11114 CLOSE c_get_bk;
11115 end if;
11116
11117 fa_srvr_msg.add_message(calling_fn => l_calling_fn
11118 ,p_log_level_rec => p_log_level_rec);
11119 return false;
11120
11121 WHEN OTHERS THEN
11122 if (p_log_level_rec.statement_level) then
11123 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
11124 ,p_log_level_rec => p_log_level_rec);
11125 end if;
11126
11127 if c_get_init_mcbk%ISOPEN then
11128 CLOSE c_get_init_mcbk;
11129 end if;
11130
11131 if c_get_init_bk%ISOPEN then
11132 CLOSE c_get_init_bk;
11133 end if;
11134
11135 if c_get_mcbk%ISOPEN then
11136 CLOSE c_get_mcbk;
11137 end if;
11138
11139 if c_get_bk%ISOPEN then
11140 CLOSE c_get_bk;
11141 end if;
11142
11143 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
11144 ,p_log_level_rec => p_log_level_rec);
11145 return false;
11146
11147 END GetFinRec;
11148
11149 --+==============================================================================
11150 -- Function: Recalculate
11151 --
11152 -- This function calculate catch-up amounts due to backdated
11153 -- amortization transactions.
11154
11155 -- 1: Find transaction to start recalculation.
11156 -- 2: Get initial asset_fin_rec, and asset_deprn_rec. Values in these rec will
11157 -- be chagned as recalculation proceeds.
11158 -- 3: Process all transaction dated after transaction found at first step.
11159 -- xxx All trx except Revaluation, Tax Reserve Adjustment, Reinstatement,
11160 -- Unit Adjustment, Transfer, and Reclass.
11161 -- 3.1: Fetch one transaction
11162 -- 3.2: Call faxcde to get reserve for adjusted_cost, raf and formula_factor
11163 -- 3.3: Call Deprn Basis function to get new adjusted_cost, raf and formula_factor.
11164 -- 3.4: If there is no transaction in this period, call faxcde until next trx
11165 -- to process (If there is no next trx, depreciate until current period).
11166 -- NOTE: Retirement which has been reinstated will not be processed at all.
11167 -- 4: Return catch-up amount.
11168 --+==============================================================================
11169 FUNCTION Recalculate(
11170 p_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
11171 p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
11172 p_asset_type_rec FA_API_TYPES.asset_type_rec_type,
11173 p_asset_desc_rec FA_API_TYPES.asset_desc_rec_type,
11174 p_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type,
11175 p_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type default null,
11176 p_period_rec FA_API_TYPES.period_rec_type,
11177 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
11178 p_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type,
11179 p_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type default null,
11180 x_deprn_expense OUT NOCOPY FA_DEPRN_SUMMARY.DEPRN_AMOUNT%TYPE,
11181 x_bonus_expense OUT NOCOPY FA_DEPRN_SUMMARY.BONUS_DEPRN_AMOUNT%TYPE,
11182 p_running_mode IN NUMBER,
11183 p_used_by_revaluation IN NUMBER,
11184 p_reclassed_asset_id NUMBER,
11185 p_reclass_src_dest VARCHAR2,
11186 p_reclassed_asset_dpis DATE,
11187 p_mrc_sob_type_code VARCHAR2,
11188 p_calling_fn VARCHAR2,
11189 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
11190
11191 l_calling_fn VARCHAR2(100) := 'FA_AMORT_CALC_PVT.Recalculate';
11192
11193 --Bug3696765
11194 l_process_addition BINARY_INTEGER := 1; -- 1: process (amort nbv) addition,
11195 -- 0: do not process (amort nbv) addition
11196
11197 l_depreciate_flag VARCHAR2(3); -- Bug 5726160
11198 l_entered_reserve NUMBER; -- Bug 5443855
11199 l_entered_ytd NUMBER;
11200
11201 CURSOR c_get_deprn_period_date IS
11202 select dp.calendar_period_open_date
11203 from fa_deprn_summary ds
11204 , fa_deprn_periods dp
11205 where dp.book_type_code = p_asset_hdr_rec.book_type_code
11206 and ds.book_type_code = p_asset_hdr_rec.book_type_code
11210
11207 and ds.asset_id = p_asset_hdr_rec.asset_id
11208 and ds.deprn_source_code = 'BOOKS'
11209 and dp.period_counter = ds.period_counter + 1;
11211 CURSOR c_get_first_trx IS
11212 select th.transaction_header_id
11213 , nvl(th.amortization_start_date, th.transaction_date_entered)
11214 , th.date_effective
11215 from fa_transaction_headers th
11216 where th.asset_id = p_asset_hdr_rec.asset_id
11217 and th.book_type_code = p_asset_hdr_rec.book_type_code
11218 and th.transaction_header_id = (select min(th2.transaction_header_id)
11219 from fa_transaction_headers th2
11220 where th2.asset_id = p_asset_hdr_rec.asset_id
11221 and th2.book_type_code = p_asset_hdr_rec.book_type_code);
11222
11223 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11224 -- This is the cursor to find a transaction which has older
11225 -- transaction_date_entered but newer calendar_period_close_open_date
11226 -- than given transaction_date_entered.
11227 -- 1st select returns transaction like mention above.
11228 --
11229 -- 2nd select returns reinstatement transactioin for core asset as
11230 -- dated transaction back to retirement date so if given
11231 -- transaction_date_entered is between retirement and reinstatement,
11232 -- this program makes sure to start recalculate at least before
11233 -- the retirement.
11234 --
11235 -- 3rd select returns reinstatement transactioin of member for group
11236 -- as dated transaction back to retirement date so if given
11237 -- transaction_date_entered is between retirement and reinstatement,
11238 -- this program makes sure to start recalculate at least before
11239 -- the retirement.
11240 --
11241 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11242 -- Bug3797105: 1st part of following cursor was returning trx which
11243 -- has performed in the same period as the period that passed date
11244 -- falls in.
11245 CURSOR c_check_overlap (c_transaction_date_entered date,
11246 c_transaction_header_id number,
11247 c_date_effective date) IS
11248 select th.transaction_header_id transaction_header_id,
11249 decode(l_process_addition,
11250 1, decode(th.transaction_subtype,
11251 'EXPENSED', px_asset_fin_rec_new.date_placed_in_service,
11252 decode(th.transaction_type_code,
11253 'ADDITION', th.transaction_date_entered,
11254 'ADDITION/VOID', th.transaction_date_entered,
11255 nvl(th.amortization_start_date,th.transaction_date_entered)),
11256 nvl(th.amortization_start_date,th.transaction_date_entered),
11257 nvl(th.amortization_start_date,th.transaction_date_entered)
11258 ),
11259 nvl(th.amortization_start_date,th.transaction_date_entered)
11260 ) transaction_date_entered,
11261 th.date_effective date_effective,
11262 th.transaction_type_code transaction_type_code
11263 from fa_transaction_headers th
11264 , fa_deprn_periods dp
11265 where th.asset_id = p_asset_hdr_rec.asset_id
11266 and th.book_type_code = p_asset_hdr_rec.book_type_code
11267 and dp.book_type_code = p_asset_hdr_rec.book_type_code
11268 -- and th.date_effective between dp.period_open_date
11269 -- and nvl(dp.period_close_date, sysdate)
11270 and c_transaction_date_entered between dp.calendar_period_open_date
11271 and dp.calendar_period_close_date
11272 and (th.date_effective > nvl(dp.period_close_date, sysdate))
11273 and ( nvl(th.amortization_start_date,
11274 decode(th.transaction_subtype,
11275 'EXPENSED', px_asset_fin_rec_new.date_placed_in_service,
11276 th.transaction_date_entered
11277 )
11278 ) <= c_transaction_date_entered
11279 and th.date_effective < c_date_effective)
11280 and c_transaction_date_entered <= dp.calendar_period_close_date
11281 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
11282 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
11283 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
11284 G_TRX_TYPE_TFR_VOID)
11285 union all
11286 select ret.transaction_header_id transaction_header_id,
11287 ret.transaction_date_entered transaction_date_entered,
11288 ret.date_effective date_effective,
11289 ret.transaction_type_code transaction_type_code
11290 from fa_transaction_headers ret,
11291 fa_transaction_headers rei,
11292 fa_retirements faret
11293 where ret.asset_id = p_asset_hdr_rec.asset_id
11294 and rei.asset_id = p_asset_hdr_rec.asset_id
11295 and ret.book_type_code = p_asset_hdr_rec.book_type_code
11296 and rei.book_type_code = p_asset_hdr_rec.book_type_code
11297 and ret.transaction_header_id = faret.transaction_header_id_in
11298 and rei.transaction_header_id = faret.transaction_header_id_out
11299 and c_transaction_date_entered between
11300 ret.transaction_date_entered and rei.transaction_date_entered
11301 and ret.date_effective < c_date_effective
11305 order by transaction_header_id;
11302 and ret.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET)
11303 and rei.transaction_type_code = G_TRX_TYPE_REI
11304 and ret.transaction_header_id <> c_transaction_header_id
11306
11307 CURSOR c_check_overlap2 is
11308 select th.transaction_header_id transaction_header_id,
11309 decode(th.transaction_subtype,
11310 'EXPENSED', px_asset_fin_rec_new.date_placed_in_service,
11311 nvl(th.amortization_start_date,th.transaction_date_entered)
11312 ) transaction_date_entered,
11313 th.date_effective date_effective,
11314 th.transaction_type_code transaction_type_code
11315 from fa_transaction_headers th
11316 where th.asset_id = p_asset_hdr_rec.asset_id
11317 and th.book_type_code = p_asset_hdr_rec.book_type_code
11318 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
11319 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
11320 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
11321 G_TRX_TYPE_TFR_VOID, G_TRX_TYPE_ADD_VOID,
11322 G_TRX_TYPE_ADD)
11323 and decode(th.transaction_subtype, null, px_asset_fin_rec_new.date_placed_in_service,
11324 th.amortization_start_date) <
11325 nvl(p_trans_rec.amortization_start_date, p_trans_rec.transaction_date_entered);
11326
11327
11328 l_incoming_thid number(15);
11329
11330 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11331 -- This cursor gets all transaction needs to be reprocessed in
11332 -- order of transaction_date_entered.
11333 -- 1st select gets all (group) asset transactions except followings
11334 -- 1. Transaction Type Code of TRANSFER OUT(IN), TRANSFER, TRANSFER IN/VOID,
11335 -- RECLASS, UNIT ADJUSTMENT, and REINSTATEMENT.
11336 -- 2. Transaction of group if there is a member transaction associated with
11337 -- this transaction and the member is not currently this group's member
11338 -- 3. Transaction of group reclass
11339 -- 2nd select gets all member transactions which has no group associated
11340 -- group transaction or there is a group transaction associated to the transaction
11341 -- but the group is not the same as current group asset.
11342 -- 3rd select returns current transaction. This doesn't return anything
11343 -- if it is not member of this processed group asset or transaction type
11344 -- code is one of mentioned above.
11345 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11346 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11347 -- This is basically the same as c_get_ths_gadj but non-group asset
11348 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11349 CURSOR c_get_ths_adj (c_transaction_date_entered date,
11350 c_date_effective date,
11351 c_transaction_header_id number,
11352 c_retirement_flag varchar2) IS
11353 select th.transaction_header_id transaction_header_id,
11354 th.transaction_type_code transaction_type_code,
11355 decode(l_process_addition,
11356 1, decode(th.transaction_type_code,
11357 'ADDITION', th.transaction_date_entered,
11358 'ADDITION/VOID', th.transaction_date_entered,
11359 /* Japan Tax phase3 */ decode(th.transaction_key, 'ES', (select calendar_period_open_date
11360 from fa_deprn_periods
11361 where book_type_code = p_asset_hdr_rec.book_type_code
11362 and period_counter = bk.extended_depreciation_period),
11363 nvl(th.amortization_start_date,
11364 decode(th.transaction_subtype,
11365 'EXPENSED', decode(outbk.depreciate_flag,
11366 'NO', decode(bk.depreciate_flag,
11367 'YES', decode(ds.deprn_reserve,
11368 0, bk.date_placed_in_service,
11369 th.transaction_date_entered),
11370 --Bug6190904: Replacing a line above with this could be an option. bk.date_placed_in_service),
11371
11372 -- Bug#4699743 th.transaction_date_entered),
11373 bk.date_placed_in_service),
11374 -- Bug# 4049799 bk.date_placed_in_service),
11375 px_asset_fin_rec_new.date_placed_in_service),
11376 th.transaction_date_entered)))),
11377 /* Japan Tax phase3 */decode(th.transaction_key, 'ES', (select calendar_period_open_date
11378 from fa_deprn_periods
11379 where book_type_code = p_asset_hdr_rec.book_type_code
11380 and period_counter = bk.extended_depreciation_period),
11384 'NO', decode(bk.depreciate_flag,
11381 nvl(th.amortization_start_date,
11382 decode(th.transaction_subtype,
11383 'EXPENSED', decode(outbk.depreciate_flag,
11385 'YES', decode(ds.deprn_reserve,
11386 0, bk.date_placed_in_service,
11387 th.transaction_date_entered),
11388 th.transaction_date_entered),
11389 -- Bug# 4049799 bk.date_placed_in_service),
11390 px_asset_fin_rec_new.date_placed_in_service),
11391 th.transaction_date_entered)))) transaction_date_entered,
11392 th.date_effective date_effective,
11393 th.transaction_name transaction_name,
11394 th.source_transaction_header_id source_transaction_header_id,
11395 th.mass_reference_id mass_reference_id,
11396 th.transaction_subtype transaction_subtype,
11397 th.transaction_key transaction_key,
11398 th.amortization_start_date amortization_start_date,
11399 th.calling_interface calling_interface,
11400 th.mass_transaction_id mass_transaction_id,
11401 fa_std_types.FA_NO_OVERRIDE deprn_override_flag,
11402 th.member_transaction_header_id member_transaction_header_id,
11403 th.trx_reference_id trx_reference_id,
11404 th.invoice_transaction_id,
11405 '1st SELECT in c_get_ths_adj'
11406 from fa_transaction_headers th,
11407 fa_books bk
11408 , fa_books outbk
11409 , fa_deprn_summary ds
11410 where th.asset_id = p_asset_hdr_rec.asset_id
11411 and th.book_type_code = p_asset_hdr_rec.book_type_code
11412 and bk.asset_id = p_asset_hdr_rec.asset_id
11413 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11414 and bk.transaction_header_id_in = th.transaction_header_id
11415 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
11416 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
11417 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
11418 G_TRX_TYPE_TFR_VOID, G_TRX_TYPE_REI,
11419 G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET,
11420 G_TRX_TYPE_ADD_VOID, G_TRX_TYPE_CIP_ADJ,
11421 G_TRX_TYPE_CIP_ADD ) -- Bug# 5074327, 5191200, 7389010
11422 and (th.transaction_header_id >= c_transaction_header_id
11423 or th.transaction_header_id < c_transaction_header_id
11424 and th.date_effective <= c_date_effective --Bug6654152
11425 and decode(th.transaction_subtype, NULL,
11426 decode(th.transaction_type_code,
11427 'ADDITION/VOID', px_asset_fin_rec_new.date_placed_in_service,
11428 'CIP ADDITION/VOID', px_asset_fin_rec_new.date_placed_in_service,
11429 th.transaction_date_entered),
11430 th.transaction_date_entered) > c_transaction_date_entered)
11431 and th.transaction_header_id <> l_incoming_thid
11432 and not exists (select 'Exclude reclass trx'
11433 from fa_trx_references tr
11434 where tr.member_asset_id = th.asset_id
11435 and tr.member_transaction_header_id = th.transaction_header_id
11436 and tr.book_type_code = p_asset_hdr_rec.book_type_code
11437 and tr.transaction_type = G_TRX_TYPE_GRP_CHG)
11438 and ds.asset_id(+) = p_asset_hdr_rec.asset_id
11439 and ds.book_type_code(+) = p_asset_hdr_rec.book_type_code
11440 and ds.deprn_source_code(+) = 'BOOKS'
11441 and outbk.asset_id(+) = p_asset_hdr_rec.asset_id
11442 and outbk.book_type_code(+) = p_asset_hdr_rec.book_type_code
11443 and outbk.transaction_header_id_out(+) = bk.transaction_header_id_in
11444 --
11445 -- Bug3421263: Added following select to takes care retirement
11446 -- prorate date as retirement trx date.
11447 --
11448 union all
11449 select th.transaction_header_id transaction_header_id,
11450 th.transaction_type_code transaction_type_code,
11451 decode(sign(con.prorate_date - cptrx.start_date),
11452 1, decode(sign(con.prorate_date - cptrx.end_date),
11453 -1, ret.date_retired,
11454 0, ret.date_retired,
11455 con.prorate_date),
11456 0, decode(sign(con.prorate_date - cptrx.end_date),
11457 -1, ret.date_retired,
11458 0, ret.date_retired,
11459 con.prorate_date),
11460 con.prorate_date) transaction_date_entered,
11461 th.date_effective date_effective,
11462 th.transaction_name transaction_name,
11463 th.source_transaction_header_id source_transaction_header_id,
11464 th.mass_reference_id mass_reference_id,
11465 th.transaction_subtype transaction_subtype,
11469 th.mass_transaction_id mass_transaction_id,
11466 th.transaction_key transaction_key,
11467 th.amortization_start_date amortization_start_date,
11468 th.calling_interface calling_interface,
11470 fa_std_types.FA_NO_OVERRIDE deprn_override_flag,
11471 th.member_transaction_header_id member_transaction_header_id,
11472 th.trx_reference_id trx_reference_id,
11473 th.invoice_transaction_id,
11474 '2nd SELECT in c_get_ths_adj'
11475 from fa_transaction_headers th,
11476 fa_retirements ret,
11477 fa_conventions con,
11478 fa_calendar_periods cp,
11479 fa_calendar_periods cptrx
11480 where th.asset_id = p_asset_hdr_rec.asset_id
11481 and th.book_type_code = p_asset_hdr_rec.book_type_code
11482 and ret.asset_id = p_asset_hdr_rec.asset_id
11483 and ret.book_type_code = p_asset_hdr_rec.book_type_code
11484 -- and (ret.transaction_header_id_out is null or
11485 -- ret.transaction_header_id_out = l_incoming_thid)
11486 and ret.RETIREMENT_PRORATE_CONVENTION = con.PRORATE_CONVENTION_CODE
11487 and ret.date_retired between con.start_date and con.end_date
11488 and cp.calendar_type = fa_cache_pkg.fazcbc_record.prorate_calendar
11489 and con.prorate_date between cp.start_date and cp.end_date
11490 and th.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET)
11491 -- and th.transaction_header_id >= c_transaction_header_id
11492 and th.transaction_header_id <> l_incoming_thid
11493 and cptrx.calendar_type = fa_cache_pkg.fazcbc_record.deprn_calendar
11494 and ret.date_retired between cptrx.start_date and cptrx.end_date
11495 and th.transaction_header_id = ret.transaction_header_id_in
11496 --bug4363712
11497 -- and con.prorate_date >= c_transaction_date_entered
11498 --bug fix 4547599
11499 and ( (con.prorate_date > c_transaction_date_entered)
11500 or
11501 --Bug4622110: Modified to handle ret trx date is later than its prorate date.
11502 -- Bug 6997902
11503 (decode(c_retirement_flag, 'Y',th.transaction_date_entered, con.prorate_date)<= c_transaction_date_entered and
11504 th.date_effective >= c_date_effective)
11505 )
11506 --
11507 --
11508 union all select
11509 l_incoming_thid transaction_header_id,
11510 p_trans_rec.transaction_type_code transaction_type_code,
11511 nvl(p_trans_rec.amortization_start_date,
11512 p_trans_rec.transaction_date_entered) transaction_date_entered,
11513 p_trans_rec.who_info.creation_date date_effective,
11514 p_trans_rec.transaction_name transaction_name,
11515 p_trans_rec.source_transaction_header_id source_transaction_header_id,
11516 p_trans_rec.mass_reference_id mass_reference_id,
11517 p_trans_rec.transaction_subtype transaction_subtype,
11518 p_trans_rec.transaction_key transaction_key,
11519 p_trans_rec.amortization_start_date amortization_start_date,
11520 p_trans_rec.calling_interface calling_interface,
11521 p_trans_rec.mass_transaction_id mass_transaction_id,
11522 p_trans_rec.deprn_override_flag deprn_override_flag,
11523 p_trans_rec.member_transaction_header_id member_transaction_header_id,
11524 p_trans_rec.trx_reference_id trx_reference_id,
11525 to_number(null), -- invoice_transaction_id
11526 '3nd SELECT in c_get_ths_adj'
11527 from fa_books bk
11528 where bk.asset_id = p_asset_hdr_rec.asset_id
11529 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11530 and bk.transaction_header_id_out is null
11531 and p_trans_rec.transaction_type_code
11532 not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
11533 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
11534 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
11535 G_TRX_TYPE_TFR_VOID, G_TRX_TYPE_REI)
11536 order by transaction_date_entered, 4; -- 4 is date_effective
11537
11538
11539 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11540 -- This cursor fetchs next transaction information.
11541 -- Since main cursor to get transactions only fetchs 100 records at once,
11542 -- this is necessary to fetch 101th record if tehre is any.
11543 -- This is similar to main cursor. Second union fetchs entered transaction
11544 -- which has not yet sotred in db.
11545 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11546 CURSOR c_get_next_ths (c_transaction_date_entered date,
11547 c_date_effective date) IS
11548 select th.transaction_date_entered transaction_date_entered,
11549 th.date_effective date_effective
11550 from fa_transaction_headers th
11551 where th.asset_id = p_asset_hdr_rec.asset_id
11552 and th.book_type_code = p_asset_hdr_rec.book_type_code
11553 and th.transaction_date_entered >= c_transaction_date_entered
11554 and th.date_effective > c_date_effective
11555 and (p_asset_type_rec.asset_type <> G_ASSET_TYPE_GROUP or
11556 not exists (select 'Y'
11557 from fa_transaction_headers mth,
11558 fa_books bk
11559 where mth.transaction_header_id = th.member_transaction_header_id
11560 and mth.book_type_code = p_asset_hdr_rec.book_type_code
11561 and bk.asset_id = mth.asset_id
11562 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11566 bk.group_asset_id <> p_asset_hdr_rec.asset_id)
11563 and bk.transaction_header_id_out is null
11564 and ((bk.asset_id <> nvl(p_reclassed_asset_id, 0) and
11565 bk.group_asset_id is null) or
11567 )
11568 )
11569 union all select
11570 p_trans_rec.transaction_date_entered transaction_date_entered,
11571 p_trans_rec.who_info.creation_date date_effective
11572 from dual
11573 where p_reclass_src_dest is null
11574 and p_trans_rec.transaction_date_entered >= c_transaction_date_entered
11575 and p_trans_rec.who_info.creation_date = c_date_effective
11576 and (p_asset_type_rec.asset_type <> G_ASSET_TYPE_GROUP or
11577 not exists (select 'Y'
11578 from fa_transaction_headers mth,
11579 fa_books bk
11580 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
11581 and mth.book_type_code = p_asset_hdr_rec.book_type_code
11582 and bk.asset_id = mth.asset_id
11583 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11584 and bk.transaction_header_id_out is null
11585 and ((bk.asset_id <> nvl(p_reclassed_asset_id, 0) and
11586 bk.group_asset_id is null) or
11587 bk.group_asset_id <> p_asset_hdr_rec.asset_id)
11588 )
11589 )
11590 order by transaction_date_entered, date_effective;
11591
11592 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11593 -- This cursor gets retirement information for given transaction_header_id
11594 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11595 CURSOR c_get_retirement (c_transaction_header_id number) IS
11596 select retirement_id,
11597 cost_retired,
11598 cost_of_removal,
11599 proceeds_of_sale,
11600 nvl(reserve_retired, 0),
11601 nvl(eofy_reserve, 0),
11602 reval_reserve_retired,
11603 unrevalued_cost_retired,
11604 bonus_reserve_retired,
11605 null -- recognize_gain_loss
11606 from fa_retirements
11607 where transaction_header_id_in = c_transaction_header_id
11608 and transaction_header_id_out is null;
11609
11610 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11611 -- For MRC
11612 -- This cursor gets retirement information for given transaction_header_id
11613 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11614 CURSOR c_get_mc_retirement (c_transaction_header_id number) IS
11615 select retirement_id,
11616 cost_retired,
11617 cost_of_removal,
11618 proceeds_of_sale,
11619 nvl(reserve_retired, 0),
11620 nvl(eofy_reserve, 0),
11621 reval_reserve_retired,
11622 unrevalued_cost_retired,
11623 bonus_reserve_retired,
11624 null -- recognize_gain_loss
11625 from fa_retirements_mrc_v
11626 where transaction_header_id_in = c_transaction_header_id
11627 and transaction_header_id_out is null;
11628
11629 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11630 -- gets reserve retired amounts if FA_RETIREMENTS doesn't store it
11631 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11632 CURSOR c_get_rsv_retired (c_transaction_header_id number) IS
11633 select sum(decode(debit_credit_flag, 'CR', -1 * adjustment_amount,
11634 adjustment_amount))
11635 from fa_adjustments
11636 where source_type_code = 'RETIREMENT'
11637 and adjustment_type = 'RESERVE'
11638 and asset_id = p_asset_hdr_rec.asset_id
11639 and book_type_code = p_asset_hdr_rec.book_type_code
11640 and transaction_header_id = c_transaction_header_id;
11641
11642 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11643 -- For MRC
11644 -- gets reserve retired amounts if FA_RETIREMENTS doesn't store it
11645 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11646 CURSOR c_get_mc_rsv_retired (c_transaction_header_id number) IS
11647 select sum(decode(debit_credit_flag, 'CR', -1 * adjustment_amount,
11648 adjustment_amount))
11649 from fa_adjustments_mrc_v
11650 where source_type_code = 'RETIREMENT'
11651 and adjustment_type = 'RESERVE'
11652 and asset_id = p_asset_hdr_rec.asset_id
11653 and book_type_code = p_asset_hdr_rec.book_type_code
11654 and transaction_header_id = c_transaction_header_id;
11655
11656 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11657 -- gets reval reserve amount
11658 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11659 CURSOR c_get_reval_rsv (c_transaction_header_id number) IS
11660 select sum(decode(debit_credit_flag, 'DR', -1 * adjustment_amount,
11661 adjustment_amount))
11662 from fa_adjustments
11663 where source_type_code = 'REVALUATION'
11664 and adjustment_type = 'RESERVE'
11665 and asset_id = p_asset_hdr_rec.asset_id
11666 and book_type_code = p_asset_hdr_rec.book_type_code
11667 and transaction_header_id = c_transaction_header_id;
11668
11672 CURSOR c_get_mc_reval_rsv (c_transaction_header_id number) IS
11669 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11670 -- For MRC: gets reval reserve amount
11671 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11673 select sum(decode(debit_credit_flag, 'DR', -1 * adjustment_amount,
11674 adjustment_amount))
11675 from fa_adjustments_mrc_v
11676 where source_type_code = 'REVALUATION'
11677 and adjustment_type = 'RESERVE'
11678 and asset_id = p_asset_hdr_rec.asset_id
11679 and book_type_code = p_asset_hdr_rec.book_type_code
11680 and transaction_header_id = c_transaction_header_id;
11681
11682 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11683 -- gets reval reserve amount
11684 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11685 CURSOR c_get_bonus_reval_rsv (c_transaction_header_id number) IS
11686 select sum(decode(debit_credit_flag, 'DR', -1 * adjustment_amount,
11687 adjustment_amount))
11688 from fa_adjustments
11689 where source_type_code = 'REVALUATION'
11690 and adjustment_type = 'BONUS_RESERVE'
11691 and asset_id = p_asset_hdr_rec.asset_id
11692 and book_type_code = p_asset_hdr_rec.book_type_code
11693 and transaction_header_id = c_transaction_header_id;
11694
11695 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11696 -- For MRC: gets reval reserve amount
11697 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11698 CURSOR c_get_mc_bonus_reval_rsv (c_transaction_header_id number) IS
11699 select sum(decode(debit_credit_flag, 'DR', -1 * adjustment_amount,
11700 adjustment_amount))
11701 from fa_adjustments_mrc_v
11702 where source_type_code = 'REVALUATION'
11703 and adjustment_type = 'BONUS RESERVE'
11704 and asset_id = p_asset_hdr_rec.asset_id
11705 and book_type_code = p_asset_hdr_rec.book_type_code
11706 and transaction_header_id = c_transaction_header_id;
11707
11708 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11709 -- This cursor gets group asset's transaction_header_id which was
11710 -- created for member addition. The reason why is because Recalculation
11711 -- needs to start before this transaction in case reclass is backdated
11712 -- to member's dpis.
11713 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11714 CURSOR c_get_init_thid IS
11715 select gth.transaction_header_id
11716 from fa_transaction_headers gth
11717 where gth.asset_id = p_asset_hdr_rec.asset_id
11718 and gth.book_type_code = p_asset_hdr_rec.book_type_code
11719 and gth.member_transaction_header_id =
11720 (select min(mth.transaction_header_id)
11721 from fa_transaction_headers mth
11722 where mth.asset_id = p_reclassed_asset_id
11723 and mth.book_type_code = p_asset_hdr_rec.book_type_code);
11724
11725 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11726 -- This cursor returns latest transaction of group
11727 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11728 CURSOR c_get_group_trx IS
11729 select th.transaction_header_id transaction_header_id,
11730 nvl(th.amortization_start_date,
11731 th.transaction_date_entered) transaction_date_entered,
11732 th.date_effective date_effective,
11733 th.transaction_type_code transaction_type_code
11734 from fa_transaction_headers th
11735 where asset_id = p_asset_hdr_rec.asset_id
11736 and book_type_code = p_asset_hdr_rec.book_type_code
11737 and not exists (select 'Y'
11738 from fa_transaction_headers mth,
11739 fa_books bk
11740 where mth.transaction_header_id = th.member_transaction_header_id
11741 and mth.book_type_code = p_asset_hdr_rec.book_type_code
11742 and bk.asset_id = mth.asset_id
11743 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11744 and bk.transaction_header_id_out is null
11745 and ((bk.asset_id <> nvl(p_reclassed_asset_id, 0) and
11746 bk.group_asset_id is null) or
11747 bk.group_asset_id <> p_asset_hdr_rec.asset_id)
11748 )
11749 union all
11750 select p_trans_rec.transaction_header_id transaction_header_id,
11751 nvl(p_trans_rec.amortization_start_date,
11752 p_trans_rec.transaction_date_entered) transaction_date_entered,
11753 p_trans_rec.who_info.creation_date date_effective,
11754 p_trans_rec.transaction_type_code transaction_type_code
11755 from dual
11756 where not exists (select 'Y'
11757 from fa_transaction_headers mth,
11758 fa_books bk
11759 where mth.transaction_header_id = p_trans_rec.member_transaction_header_id
11760 and mth.book_type_code = p_asset_hdr_rec.book_type_code
11761 and bk.asset_id = mth.asset_id
11762 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11763 and bk.transaction_header_id_out is null
11764 and ((bk.asset_id <> nvl(p_reclassed_asset_id, 0) and
11768 order by transaction_header_id desc;
11765 bk.group_asset_id is null) or
11766 bk.group_asset_id <> p_asset_hdr_rec.asset_id)
11767 )
11769
11770 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11771 -- This cursor returns maximum group transaction header id which is
11772 -- not a group transaction of non-member asset before give transaction
11773 -- header id to get correct initial books row.
11774 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11775 CURSOR c_get_init_trx2 (c_transaction_header_id number) IS
11776 select outgth.transaction_header_id
11777 from fa_transaction_headers outgth,
11778 fa_transaction_headers ingth,
11779 fa_books gbk
11780 where outgth.asset_id = p_asset_hdr_rec.asset_id
11781 and outgth.book_type_code = p_asset_hdr_rec.book_type_code
11782 and outgth.transaction_header_id <= c_transaction_header_id
11783 and ingth.asset_id = p_asset_hdr_rec.asset_id
11784 and ingth.book_type_code = p_asset_hdr_rec.book_type_code
11785 and gbk.transaction_header_id_out = outgth.transaction_header_id
11786 and gbk.transaction_header_id_in = ingth.transaction_header_id
11787 and not exists (select 1
11788 from fa_transaction_headers mth,
11789 fa_books bk
11790 where mth.transaction_header_id = ingth.member_transaction_header_id
11791 and mth.asset_id = bk.asset_id
11792 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11793 and bk.transaction_header_id_out is null
11794 and (bk.asset_id <> p_reclassed_asset_id
11795 and nvl(bk.group_asset_id, 0) <> p_asset_hdr_rec.asset_id))
11796 order by outgth.transaction_header_id desc;
11797
11798 -- bug 4428646, changed deprn_source_code to 'BOOKS, was 'B'.
11799 CURSOR c_get_brow IS
11800 select ytd_deprn, deprn_reserve
11801 from fa_deprn_summary
11802 where asset_id = p_asset_hdr_rec.asset_id
11803 and book_type_code = p_asset_hdr_rec.book_type_code
11804 and deprn_source_code = 'BOOKS';
11805
11806 CURSOR c_get_mc_brow IS
11807 select ytd_deprn, deprn_reserve
11808 from fa_deprn_summary_mrc_v
11809 where asset_id = p_asset_hdr_rec.asset_id
11810 and book_type_code = p_asset_hdr_rec.book_type_code
11811 and deprn_source_code = 'BOOKS';
11812
11813 -- code fix for bug no.4016503
11814 -- Get previous trx with given thid
11815 --Added conditions to where clause for bug 4168841
11816 CURSOR c_get_prev_trx (c_thid number) IS
11817 select th.transaction_header_id
11818 , th.transaction_date_entered
11819 , th.date_effective
11820 , th.transaction_type_code
11821 from fa_transaction_headers th
11822 , fa_books bk
11823 where bk.transaction_header_id_out < c_thid
11824 and bk.book_type_code = p_asset_hdr_rec.book_type_code
11825 and th.book_type_code = p_asset_hdr_rec.book_type_code
11826 and th.asset_id = p_asset_hdr_rec.asset_id
11827 and bk.asset_id = p_asset_hdr_rec.asset_id
11828 and bk.transaction_header_id_in = th.transaction_header_id
11829 and th.transaction_type_code not in (G_TRX_TYPE_TFR_OUT, G_TRX_TYPE_TFR_IN,
11830 G_TRX_TYPE_TFR, G_TRX_TYPE_TFR_VOID,
11831 G_TRX_TYPE_REC, G_TRX_TYPE_UNIT_ADJ,
11832 G_TRX_TYPE_TFR_VOID ,G_TRX_TYPE_REI)
11833 order by transaction_header_id desc;
11834
11835 -- Bug6190904: Need following cursor to store prorate period info
11836 -- to find out whether adjustment date (amortized) may need the info
11837 -- if the date falls in the prorate period and impact the catch-up.
11838 CURSOR c_get_prorate_date (c_date_placed_in_service date
11839 , c_prorate_convention_code varchar2) is
11840 select prorate_date, start_date, end_date
11841 from fa_conventions
11842 where prorate_convention_code = c_prorate_convention_code
11843 and c_date_placed_in_service between start_date and end_date;
11844
11845 -- Bug6190904: Used with above cursor.
11846 l_prorate_date date;
11847 l_start_date date;
11848 l_end_date date;
11849
11850 --++++++++++++++++++ Table types ++++++++++++++++++
11851 TYPE tab_date_type IS TABLE OF DATE INDEX BY BINARY_INTEGER;
11852 TYPE tab_num_type IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
11853 TYPE tab_num15_type IS TABLE OF NUMBER(15) INDEX BY BINARY_INTEGER;
11854 TYPE tab_char1_type IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
11855 TYPE tab_char15_type IS TABLE OF VARCHAR2(15) INDEX BY BINARY_INTEGER;
11856 TYPE tab_char30_type IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
11857 TYPE tab_char150_type IS TABLE OF VARCHAR2(150) INDEX BY BINARY_INTEGER;
11858
11859 -- table to store returned values from c_check_overlap2
11860 t_co_thid tab_num15_type;
11861 t_co_date_effective tab_date_type;
11862 t_co_trx_date tab_date_type;
11863 t_co_trx_type_code tab_char30_type;
11864
11865 --+++ Table variables to for main transaction cursor +++
11866 t_transaction_header_id tab_num15_type;
11867 t_transaction_type_code tab_char30_type;
11868 t_transaction_date_entered tab_date_type;
11872 t_mass_reference_id tab_num15_type;
11869 t_date_effective tab_date_type;
11870 t_transaction_name tab_char30_type;
11871 t_source_transaction_header_id tab_num15_type;
11873 t_transaction_subtype tab_char30_type;
11874 t_transaction_key tab_char30_type;
11875 t_amortization_start_date tab_date_type;
11876 t_calling_interface tab_char30_type;
11877 t_mass_transaction_id tab_num15_type;
11878 t_deprn_override_flag tab_char1_type;
11879 t_member_transaction_header_id tab_num15_type;
11880 t_trx_reference_id tab_num15_type;
11881 t_invoice_transaction_id tab_num15_type;
11882 t_which_select tab_char30_type;
11883
11884
11885 l_row_count NUMBER := 0;
11886
11887 --+++++ Store data related to each transactions +++++
11888 l_trans_rec FA_API_TYPES.trans_rec_type;
11889 l_invoice_transaction_id NUMBER;
11890 l_period_rec FA_API_TYPES.period_rec_type;
11891 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
11892 l_asset_deprn_rec_raf FA_API_TYPES.asset_deprn_rec_type;
11893 l_asset_fin_rec_old FA_API_TYPES.asset_fin_rec_type;
11894 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
11895 l_asset_fin_rec_new FA_API_TYPES.asset_fin_rec_type;
11896 l_asset_retire_rec FA_API_TYPES.asset_retire_rec_type;
11897
11898 l_least_thid number(15); -- Stored least transaction_header_id
11899 -- to find starting fa_books record
11900 l_member_asset_id number(15) := to_number(null); -- Store member asset id
11901 l_member_trx_key varchar2(2); -- member transaction key
11902 l_member_hdr_rec FA_API_TYPES.asset_hdr_rec_type;
11903 l_next_period_rec FA_API_TYPES.period_rec_type;
11904 l_transaction_type_code varchar2(30); -- Used to find reinstatement
11905
11906 l_temp_period_counter number(15); -- This is to store period counter because GetDeprnRec needs
11907 -- period counter = period_counter - 1
11908
11909 l_use_new_deprn_rule BOOLEAN := FALSE; -- True: if it needs to inherit passed
11910 -- asset_fin_rec values except amounts.
11911 l_use_fin_rec_adj BOOLEAN := FALSE; -- True: if it is processing passed transaction
11912
11913 l_limit CONSTANT BINARY_INTEGER := 1800; -- main transaction_cursor limit constant;
11914
11915 --+++++++++++++++ For calling faxcde +++++++++++++++
11916 l_dpr_in FA_STD_TYPES.dpr_struct;
11917 l_dpr_out FA_STD_TYPES.dpr_out_struct;
11918 l_dpr_arr FA_STD_TYPES.dpr_arr_type;
11919 l_running_mode NUMBER;
11920
11921 --++++++++++ For storing retirement values ++++++++++
11922 l_retirement_id NUMBER(15);
11923 l_cost_of_removal NUMBER;
11924 l_proceeds_of_sales NUMBER;
11925 l_reserve_retired NUMBER;
11926 l_eofy_reserve_retired NUMBER;
11927 l_reval_reserve_retired NUMBER;
11928 l_unrevalued_cost_retired NUMBER;
11929 l_bonus_reserve_retired NUMBER;
11930 l_recognize_gain_loss VARCHAR2(30);
11931 l_cost_retired NUMBER;
11932
11933 --++++++++++ For storing revaluation values ++++++++++
11934 l_reval_reserve NUMBER;
11935 l_reval_bonus_reserve NUMBER;
11936
11937 l_process_this_trx BOOLEAN := TRUE; -- False: if this transaction is retirement and
11938 -- reinstatement exists for this retirement.
11939 -- If this is false, it won't process this transaction.
11940
11941 --
11942 -- These are used to store return values from faxcde which
11943 -- may not be used.
11944 --
11945 l_out_deprn_exp NUMBER;
11946 l_out_reval_exp NUMBER;
11947 l_out_reval_amo NUMBER;
11948 l_out_prod NUMBER;
11949 l_out_ann_adj_exp NUMBER;
11950 l_out_ann_adj_reval_exp NUMBER;
11951 l_out_ann_adj_reval_amo NUMBER;
11952 l_out_bonus_rate_used NUMBER;
11953 l_out_full_rsv_flag BOOLEAN;
11954 l_out_life_comp_flag BOOLEAN;
11955 l_out_deprn_override_flag VARCHAR2(1);
11956
11957 --+++++++ variables for cursor c_get_next_ths +++++++
11958 l_next_trx_period_counter NUMBER(15);
11959 l_next_trx_fiscal_year NUMBER(15);
11960 l_next_trx_period_num NUMBER(15);
11961 l_next_trx_trx_date_entered DATE;
11962 l_next_trx_date_effective DATE;
11963
11964 --+++++++ variables for cursor c_get_init_thid ++++++
11965 l_member_init_thid NUMBER;
11966
11967 --+++++++ variables FA_CALC_DEPRN_BASIS1_PKG.GET_EOFY_EOP +++++++
11968 l_eofy_rec_cost NUMBER;
11969 l_eofy_sal_val NUMBER;
11970 l_eop_rec_cost NUMBER;
11971 l_eop_sal_val NUMBER;
11972
11973 l_eofy_fy NUMBER; -- Fiscal year which is used to get
11974 -- end of fiscal year recoverable cost and
11975 -- salvage value
11976
11980 l_eofy_thid NUMBER(15);
11977 l_period_counter NUMBER(15);
11978
11979 --++++++++ variables for calling GetEofyReserve ++++++++
11981 l_eofy_trx_date_entered DATE;
11982 l_eofy_date_effective DATE;
11983 l_eofy_reserve NUMBER;
11984 l_eofy_trx_type_code VARCHAR2(30);
11985
11986 --++++++++ variables for cursor c_get_deprn_period_date +++++++
11987 l_calendar_period_start_date date;
11988 --++++++++ variables for manual override ++++++++
11989 l_rate_source_rule VARCHAR2(25);
11990 l_deprn_basis_rule VARCHAR2(25);
11991
11992 --++++++++ variables for cursor c_get_reclass_reserve +++++++++
11993 l_src_asset_id NUMBER(15);
11994 l_dest_asset_id NUMBER(15);
11995 l_reclassed_reserve NUMBER;
11996 l_reclass_src_dest VARCHAR2(12);
11997
11998 --++++++++ Other Variables +++++++
11999 l_calc_deprn_flag BOOLEAN := FALSE;
12000 l_temp_adjusted_cost NUMBER;
12001 l_reserve_adj NUMBER;
12002
12003 --+++++++++++++++++ Exceptions ++++++++++++++++++++++
12004 invalid_trx_to_overlap EXCEPTION;
12005 calc_failed EXCEPTION;
12006 l_check_overlap_found BOOLEAN := FALSE;
12007
12008 l_temp_cnt binary_integer := 0;
12009
12010 --bug3548724
12011 l_is_this_void BOOLEAN := FALSE;
12012 l_adj_processed BOOLEAN := FALSE;
12013 l_add_processed BOOLEAN := FALSE;
12014 l_add_void_exist BOOLEAN := FALSE;
12015 l_add_exist BOOLEAN := FALSE;
12016
12017 --Bug3724207
12018 l_dpis_change BOOLEAN := FALSE;
12019 l_dbr_event_type VARCHAR2(30);
12020 l_brow_ytd_deprn NUMBER;
12021 l_brow_deprn_reserve NUMBER;
12022
12023 l_energy_member BOOLEAN := FALSE; -- ENERGY
12024 l_retirement_flag VARCHAR2(1) := 'N'; --Bug4622110
12025
12026 l_unplanned_exp NUMBER;
12027 l_start_from_first BOOLEAN := TRUE;
12028
12029 -- Bug PKO
12030 l_retirement_thid NUMBER := -1;
12031 l_catchup_begin_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
12032 l_temp_reserve NUMBER;
12033
12034 l_cost_frac NUMBER; -- Bug 5948890
12035
12036 l_old_pc_reserved NUMBER; -- Japan Tax phase3
12037 l_new_pc_reserved NUMBER; -- Japan Tax phase3
12038
12039 --Bug6631377 begins
12040 CURSOR c_prd_addition is
12041 select th.transaction_header_id,
12042 th.transaction_date_entered,
12043 th.date_effective,
12044 th.transaction_type_code
12045 from fa_transaction_headers th,
12046 fa_deprn_periods fdp
12047 where th.asset_id = p_asset_hdr_rec.asset_id
12048 and th.book_type_code = p_asset_hdr_rec.book_type_code
12049 and fdp.book_type_code = p_asset_hdr_rec.book_type_code
12050 and th.date_effective between fdp.period_open_date and nvl(fdp.period_close_date,sysdate)
12051 and l_trans_rec.transaction_date_entered between fdp.calendar_period_open_date
12052 and fdp.calendar_period_close_date
12053 and th.transaction_type_code = 'ADDITION';
12054
12055 l_temp_id number;
12056 l_temp_date1 date;
12057 l_temp_date2 date;
12058 l_temp_code varchar2(30);
12059 --bug 6631377 ends
12060
12061 BEGIN
12062
12063 if (p_log_level_rec.statement_level) then
12064 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_type_rec.asset_type||
12065 ':'||p_asset_hdr_rec.asset_id, p_log_level_rec);
12066 fa_debug_pkg.add(l_calling_fn, 'Reclass values', p_reclass_src_dest||
12067 ':'||to_char(p_reclassed_asset_id)||':'||
12068 to_char(p_reclassed_asset_dpis, 'DD-MON-RR'), p_log_level_rec);
12069 end if;
12070
12071 l_asset_deprn_rec := p_asset_deprn_rec;
12072 l_asset_fin_rec_adj := p_asset_fin_rec_adj;
12073
12074 l_incoming_thid := nvl(p_trans_rec.transaction_header_id, 999999999999);
12075 l_trans_rec.transaction_type_code := p_trans_rec.transaction_type_code;
12076 l_trans_rec.transaction_header_id := l_incoming_thid;
12077 l_trans_rec.transaction_date_entered := nvl(p_trans_rec.amortization_start_date,
12078 p_trans_rec.transaction_date_entered);
12079 l_trans_rec.who_info.last_update_date := nvl(p_trans_rec.who_info.last_update_date, sysdate);
12080
12081 if ((px_asset_fin_rec_new.group_asset_id is null) and
12082 (p_asset_fin_rec_old.group_asset_id is not null)) or
12083 ((px_asset_fin_rec_new.group_asset_id is not null) and
12084 (p_asset_fin_rec_old.group_asset_id is null)) and
12085 (p_asset_type_rec.asset_type = 'CAPITALIZED') then
12086 l_calc_deprn_flag := TRUE;
12087 end if;
12088
12089 --
12090 -- Bug3696765:
12091 -- Due to necessity of using user entered reserve occasionally (only if user backdated
12092 -- to 1st peirod of fiscal, this check is necessary and the return value will be
12093 -- used in check_overlap cursor and main cursor.
12094 --
12095 if (p_log_level_rec.statement_level) then
12096 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 1.0 ==========','', p_log_level_rec);
12100 fa_debug_pkg.add(l_calling_fn, '++ p_trans_rec.transaction_type_code',
12097 fa_debug_pkg.add(l_calling_fn, '++ p_trans_rec.transaction_header_id',
12098 p_trans_rec.transaction_header_id, p_log_level_rec);
12099 fa_debug_pkg.add(l_calling_fn, '++ l_incoming_thid', l_incoming_thid, p_log_level_rec);
12101 p_trans_rec.transaction_type_code, p_log_level_rec);
12102 fa_debug_pkg.add(l_calling_fn, '++ p_trans_rec.transaction_date_entered',
12103 p_trans_rec.transaction_date_entered, p_log_level_rec);
12104 end if;
12105
12106 if (p_trans_rec.transaction_type_code not like '%ADDITION') and
12107 (p_trans_rec.amortization_start_date is not null) then
12108 if not GetPeriodInfo(to_number(to_char(p_trans_rec.amortization_start_date, 'J')),
12109 p_asset_hdr_rec.book_type_code,
12110 p_mrc_sob_type_code,
12111 l_period_rec) then
12112 if (p_log_level_rec.statement_level) then
12113 fa_debug_pkg.add(l_calling_fn, 'Error calling',
12114 'GetPeriodInfo'
12115 ,p_log_level_rec => p_log_level_rec);
12116 end if;
12117
12118 raise calc_failed;
12119 end if;
12120
12121 -- Bug 6950629 Added and condition to process addition transaction if firstperiod equal to dpis.
12122 if l_period_rec.period_num = 1 and
12123 (px_asset_fin_rec_new.date_placed_in_service <> p_trans_rec.amortization_start_date) then
12124 l_process_addition := 0;
12125 else
12126 l_process_addition := 1;
12127 end if;
12128 end if;
12129
12130 -- Bug 5726160
12131 if p_running_mode = fa_std_types.FA_DPR_CATCHUP then
12132
12133 if p_trans_rec.transaction_type_code = 'REINSTATEMENT' then
12134
12135 begin
12136 select transaction_header_id_in
12137 into l_retirement_thid -- retirement thid
12138 from fa_retirements
12139 where asset_id = p_asset_hdr_rec.asset_id
12140 and book_type_code = p_asset_hdr_rec.book_type_code
12141 and transaction_header_id_out = l_incoming_thid;
12142 exception when others then null;
12143 end;
12144
12145 end if;
12146
12147 end if;
12148
12149 if (p_log_level_rec.statement_level) then
12150 fa_debug_pkg.add(l_calling_fn, 'Checking overlapped trxs',
12151 p_asset_type_rec.asset_type||':'||p_asset_hdr_rec.asset_id
12152 ,p_log_level_rec => p_log_level_rec);
12153 end if;
12154
12155 OPEN c_get_deprn_period_date;
12156 FETCH c_get_deprn_period_date INTO l_calendar_period_start_date;
12157 CLOSE c_get_deprn_period_date;
12158
12159 if (p_log_level_rec.statement_level) then
12160 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 1.9 ==========','', p_log_level_rec);
12161 fa_debug_pkg.add(l_calling_fn, '++ l_calendar_period_start_date',
12162 l_calendar_period_start_date, p_log_level_rec);
12163 end if;
12164
12165
12166 LOOP
12167 if (p_log_level_rec.statement_level) then
12168 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 2.0 ==========','', p_log_level_rec);
12169 fa_debug_pkg.add(l_calling_fn, '++ IN 1st LOOP: l_trans_rec.transaction_header_id',
12170 l_trans_rec.transaction_header_id, p_log_level_rec);
12171 fa_debug_pkg.add(l_calling_fn,
12172 '++ Checking overlapped trxs with l_trans_rec.transaction_date_entered',
12173 to_char(l_trans_rec.transaction_date_entered, 'MM/DD/YYYY HH24:MI:SS'),
12174 p_log_level_rec);
12175 fa_debug_pkg.add(l_calling_fn, 'l_process_addition', l_process_addition, p_log_level_rec);
12176 end if;
12177
12178 if (l_calendar_period_start_date >l_trans_rec.transaction_date_entered) then
12179
12180 --
12181 -- There is a case that we don't want to recalculate from addition if entered trx
12182 -- is back dated to first period of fy and user provided ytd and deprn reserve at the time
12183 -- of addition
12184 --
12185 if l_process_addition = 0 then
12186 --
12187 -- If entered trx is back dated to period 1 then look for a trx prevent recalculation
12188 -- from the period 1 such as other trx back dated beyond the period.
12189 -- if there is no such trx exists then we can recalculate from the period 1 using
12190 -- user entered ytd and deprn reserve at the time of addition. so skip c_check_overlap
12191 --
12192 --toru
12193 OPEN c_check_overlap2;
12194 FETCH c_check_overlap2 BULK COLLECT INTO t_co_thid,
12195 t_co_date_effective,
12196 t_co_trx_date,
12197 t_co_trx_type_code;
12198
12199 CLOSE c_check_overlap2;
12200
12201 if (p_log_level_rec.statement_level) then
12202 fa_debug_pkg.add(l_calling_fn, 't_co_thid.count', t_co_thid.count, p_log_level_rec);
12203 end if;
12204
12205 l_start_from_first := FALSE;
12206
12207 for i in 1..t_co_thid.count loop
12208 if (p_log_level_rec.statement_level) then
12212 if (t_co_trx_date(i) < l_period_rec.calendar_period_open_date) then
12209 fa_debug_pkg.add(l_calling_fn, 't_co_trx_date', t_co_trx_date(i), p_log_level_rec);
12210 end if;
12211
12213 if (p_log_level_rec.statement_level) then
12214 fa_debug_pkg.add(l_calling_fn, 'l_start_from_first', 'TRUE', p_log_level_rec);
12215 end if;
12216 l_start_from_first := TRUE;
12217 EXIT;
12218 elsif (t_co_trx_date(i) < nvl(l_trans_rec.transaction_date_entered,
12219 nvl(p_trans_rec.amortization_start_date,
12220 p_trans_rec.transaction_date_entered))) then
12221 l_trans_rec.transaction_header_id := t_co_thid(i);
12222 l_trans_rec.transaction_date_entered := t_co_trx_date(i);
12223 l_trans_rec.who_info.creation_date := t_co_date_effective(i);
12224 l_trans_rec.transaction_type_code := t_co_trx_type_code(i);
12225 end if;
12226 end loop;
12227
12228 if (p_log_level_rec.statement_level) then
12229 fa_debug_pkg.add(l_calling_fn, 'End of for loop', 'end', p_log_level_rec);
12230 end if;
12231
12232 else
12233 l_start_from_first := TRUE;
12234 end if;
12235
12236
12237 if (l_start_from_first) then
12238 OPEN c_get_first_trx;
12239 FETCH c_get_first_trx INTO l_trans_rec.transaction_header_id,
12240 l_trans_rec.transaction_date_entered,
12241 l_trans_rec.who_info.creation_date;
12242 CLOSE c_get_first_trx;
12243
12244 if (p_log_level_rec.statement_level) then
12245 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 2.1 ==========','',
12246 p_log_level_rec);
12247 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.transaction_header_id',
12248 l_trans_rec.transaction_header_id, p_log_level_rec);
12249 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.transaction_date_entered',
12250 l_trans_rec.transaction_date_entered, p_log_level_rec);
12251 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.who_info.creation_date',
12252 l_trans_rec.who_info.creation_date, p_log_level_rec);
12253 end if;
12254
12255 end if; -- (l_start_from_first)
12256
12257 EXIT;
12258
12259 end if;
12260
12261 OPEN c_check_overlap(l_trans_rec.transaction_date_entered,
12262 l_trans_rec.transaction_header_id,
12263 l_trans_rec.who_info.creation_date);
12264 FETCH c_check_overlap INTO g_temp_number,
12265 g_temp_date1,
12266 g_temp_date2,
12267 g_temp_char30;
12268
12269 --tk_util.debug('transaction_header_id: '||to_char(g_temp_number));
12270 --tk_util.debug('creation_date: '||to_char(g_temp_date2, 'DD-MON-RR HH24:MI:SS'));
12271 --tk_util.debug('l_trans_rec.transaction_type_code: '||g_temp_char30);
12272
12273 if (p_log_level_rec.statement_level) then
12274 fa_debug_pkg.add(l_calling_fn,
12275 '========== Recalc Step 2.2 : IN c_check_overlap ==========','',
12276 p_log_level_rec);
12277 fa_debug_pkg.add(l_calling_fn, '++ INPUT: l_trans_rec.transaction_header_id',
12278 l_trans_rec.transaction_header_id, p_log_level_rec);
12279 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.transaction_date_entered',
12280 to_char(l_trans_rec.transaction_date_entered,'MM/DD/YYYY'),
12281 p_log_level_rec);
12282 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.who_info.creation_date',
12283 to_char(l_trans_rec.who_info.creation_date,'MM/DD/YYYY HH24:MI:SS'),
12284 p_log_level_rec);
12285 fa_debug_pkg.add(l_calling_fn, '++ OUTPUT: g_temp_number: THID', g_temp_number,
12286 p_log_level_rec);
12287 fa_debug_pkg.add(l_calling_fn, '++ g_temp_date1: Trx Date', g_temp_date1,
12288 p_log_level_rec);
12289 fa_debug_pkg.add(l_calling_fn, '++ g_temp_date2: Effective_Date', g_temp_date2,
12290 p_log_level_rec);
12291 fa_debug_pkg.add(l_calling_fn, '++ g_temp_char30: Trx Type Code', g_temp_char30,
12292 p_log_level_rec);
12293 end if;
12294
12295
12296 -- Bug#4049799: Replaced this with the following: l_check_overlap_found := c_check_overlap%FOUND; */
12297 if c_check_overlap%NOTFOUND then
12298 l_check_overlap_found := FALSE;
12299 else
12300 l_check_overlap_found := TRUE;
12301 end if;
12302
12303 CLOSE c_check_overlap;
12304
12305
12306 if (p_log_level_rec.statement_level) then
12307 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.0 ==========','', p_log_level_rec);
12308 if (l_check_overlap_found) then
12309 fa_debug_pkg.add(l_calling_fn, '++ l_check_overlap_found', 'TRUE', p_log_level_rec);
12310 else
12314
12311 fa_debug_pkg.add(l_calling_fn, '++ l_check_overlap_found', 'FALSE', p_log_level_rec);
12312 end if;
12313 end if;
12315 if (l_check_overlap_found) then
12316
12317 if (p_log_level_rec.statement_level) then
12318 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.1 ==========','', p_log_level_rec);
12319 end if;
12320
12321 l_trans_rec.transaction_header_id := g_temp_number;
12322 l_trans_rec.transaction_date_entered := g_temp_date1;
12323 l_trans_rec.who_info.creation_date := g_temp_date2;
12324 l_trans_rec.transaction_type_code := g_temp_char30;
12325
12326 --
12327 -- Bug3696765:
12328 -- Due to necessity of using user entered reserve occasionally (only if user backdated
12329 -- to 1st peirod of fiscal, this check is necessary and the return value will be
12330 -- used in check_overlap cursor and main cursor.
12331 --
12332 if (l_trans_rec.transaction_type_code not like '%ADDITION') then
12333 if not GetPeriodInfo(to_number(to_char(l_trans_rec.transaction_date_entered, 'J')),
12334 p_asset_hdr_rec.book_type_code,
12335 p_mrc_sob_type_code,
12336 l_period_rec) then
12337 if (p_log_level_rec.statement_level) then
12338 fa_debug_pkg.add(l_calling_fn, 'Error calling',
12339 'GetPeriodInfo'
12340 ,p_log_level_rec => p_log_level_rec);
12341 end if;
12342
12343 raise calc_failed;
12344 end if;
12345
12346 -- Bug 5443855 if l_period_rec.period_num = 1 then
12347 if l_period_rec.period_num = 1 or l_entered_reserve <> 0 then
12348 l_process_addition := 0;
12349 else
12350 l_process_addition := 1;
12351 end if;
12352 end if;
12353
12354 else
12355
12356 if (p_log_level_rec.statement_level) then
12357 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.2 ==========','', p_log_level_rec);
12358 end if;
12359
12360 --
12361 -- If the member asset is currently a member or will be a member
12362 -- do not call GetEofyReserve since it could require to go back
12363 -- to addition to recalcualte without letting user know which is not
12364 -- good especially if this asset has added with reserve which will be
12365 -- wiped out during recalculation.
12366 --
12367 if ((p_asset_fin_rec_old.group_asset_id is null and
12368 px_asset_fin_rec_new.group_asset_id is null)) or
12369 (l_trans_rec.transaction_type_code like '%RETIREMENT') then -- ENERGY
12370
12371 if (fa_cache_pkg.fazcdrd_record.use_eofy_reserve_flag = 'Y') /*and
12372 (p_asset_fin_rec_old.group_asset_id is null and -- ENERGY
12373 px_asset_fin_rec_new.group_asset_id is null) */ then -- ENERGY
12374 if not GetEofyReserve(
12375 p_trans_rec => l_trans_rec,
12376 p_trans_rec_cur => p_trans_rec,
12377 p_asset_hdr_rec => p_asset_hdr_rec,
12378 p_asset_type_rec => p_asset_type_rec,
12379 p_period_rec => p_period_rec,
12380 x_eofy_reserve => l_eofy_reserve,
12381 x_transaction_header_id => l_eofy_thid,
12382 x_transaction_date_entered => l_eofy_trx_date_entered,
12383 x_date_effective => l_eofy_date_effective,
12384 x_transaction_type_code => l_eofy_trx_type_code,
12385 p_mrc_sob_type_code => p_mrc_sob_type_code,
12386 p_calling_fn => l_calling_fn
12387 ,p_log_level_rec => p_log_level_rec) then
12388 if (p_log_level_rec.statement_level) then
12389 fa_debug_pkg.add(l_calling_fn, 'Error calling',
12390 'GetEofyReserve'
12391 ,p_log_level_rec => p_log_level_rec);
12392 end if;
12393
12394 raise calc_failed;
12395
12396 end if;
12397 end if;
12398
12399 if (p_log_level_rec.statement_level) then
12400 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.3 ==========','', p_log_level_rec);
12401 end if;
12402
12403
12404 if (nvl(fa_cache_pkg.fazcdrd_record.use_eofy_reserve_flag, 'N') = 'N') or
12405 (l_eofy_reserve is not null) then
12406 --adding the following code for bug no.4016503
12407 --the retirement transaction is ignored during recalculate
12408 -- if it is reinstated by any following transaction.
12409
12410 if (l_trans_rec.transaction_type_code like '%RETIREMENT') then
12411 --bug6631377 begins
12412 open c_prd_addition;
12413 fetch c_prd_addition into
12414 l_temp_id,
12415 l_temp_date1,
12416 l_temp_date2,
12420 l_trans_rec.transaction_date_entered := l_temp_date1;
12417 l_temp_code;
12418 if c_prd_addition%FOUND then
12419 l_trans_rec.transaction_header_id := l_temp_id;
12421 l_trans_rec.who_info.creation_date := l_temp_date2;
12422 l_trans_rec.transaction_type_code := l_temp_code;
12423 exit;
12424 else
12425 l_retirement_id := null;
12426 l_cost_retired := null;
12427 l_cost_of_removal := null;
12428 l_proceeds_of_sales := null;
12429 l_reserve_retired := null;
12430 l_eofy_reserve_retired := null;
12431 l_reval_reserve_retired := null;
12432 l_unrevalued_cost_retired := null;
12433 l_bonus_reserve_retired := null;
12434 l_recognize_gain_loss := null;
12435
12436 if (p_log_level_rec.statement_level) then
12437 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.3.1 ==========','', p_log_level_rec);
12438 end if;
12439
12440 OPEN c_get_retirement(l_trans_rec.transaction_header_id);
12441 FETCH c_get_retirement INTO l_retirement_id,
12442 l_cost_retired,
12443 l_cost_of_removal,
12444 l_proceeds_of_sales,
12445 l_reserve_retired,
12446 l_eofy_reserve_retired,
12447 l_reval_reserve_retired,
12448 l_unrevalued_cost_retired,
12449 l_bonus_reserve_retired,
12450 l_recognize_gain_loss;
12451
12452 if c_get_retirement%NOTFOUND then
12453 if (p_log_level_rec.statement_level) then
12454 fa_debug_pkg.add(l_calling_fn, 'Check Overlap', 'Serach previous trx'
12455 ,p_log_level_rec => p_log_level_rec);
12456 end if;
12457
12458 CLOSE c_get_retirement;
12459
12460 --find a trx before this retirement
12461 OPEN c_get_prev_trx (l_trans_rec.transaction_header_id);
12462 FETCH c_get_prev_trx INTO l_trans_rec.transaction_header_id
12463 , l_trans_rec.transaction_date_entered
12464 , l_trans_rec.who_info.creation_date
12465 , l_trans_rec.transaction_type_code;
12466 /*Added for bug 4168841*/
12467 if c_get_prev_trx%NOTFOUND then
12468 CLOSE c_get_prev_trx;
12469 exit;
12470 end if;
12471
12472 if (p_log_level_rec.statement_level) then
12473 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.3.2.1 ==========','', p_log_level_rec);
12474 end if;
12475
12476
12477 CLOSE c_get_prev_trx;
12478 else
12479 -- This retirement has not reinstated yet so ok to proceed
12480 CLOSE c_get_retirement;
12481
12482 if (p_log_level_rec.statement_level) then
12483 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.3.3 ==========','', p_log_level_rec);
12484 end if;
12485
12486 exit;
12487 end if; -- c_get_retirement%NOTFOUND
12488 end if; --c_prd_addition%FOUND
12489 close c_prd_addition;
12490 --bug6631377 ends
12491 else
12492 if (p_log_level_rec.statement_level) then
12493 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.3.9 ==========','', p_log_level_rec);
12494 end if;
12495
12496 exit;
12497 end if; -- l_trans_rec.transaction_type_code like '%RETIREMENT
12498
12499 else
12500 if (p_log_level_rec.statement_level) then
12501 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.4.1 ==========','', p_log_level_rec);
12502 end if;
12503
12504 l_trans_rec.transaction_header_id := l_eofy_thid;
12505 l_trans_rec.transaction_date_entered := l_eofy_trx_date_entered;
12506 l_trans_rec.who_info.creation_date := l_eofy_date_effective;
12507 end if;
12508 else
12509 if (p_log_level_rec.statement_level) then
12510 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 3.5 ==========','', p_log_level_rec);
12511 end if;
12512
12513 -- Will find eofy_reserve from old books row.
12514 exit;
12515 end if; -- (p_asset_fin_rec_old.group_asset_id is null and
12516 end if;
12517
12518 l_period_rec := null;
12519
12520 --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12521 -- temporary code to prevent infinite loop
12522 --
12523 l_temp_cnt := l_temp_cnt + 1;
12524
12525 if (l_temp_cnt > 200) then
12526
12527 if (p_log_level_rec.statement_level) then
12528 fa_debug_pkg.add(l_calling_fn, 'Checking overlapped trxs with ',
12529 l_trans_rec.transaction_date_entered
12530 ,p_log_level_rec => p_log_level_rec);
12531 end if;
12532
12533 raise calc_failed;
12534 end if;
12535 --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12536 --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12537
12538 END LOOP;
12539
12540
12541 if (p_log_level_rec.statement_level) then
12542 fa_debug_pkg.add(l_calling_fn, '+++ FETCHING TRANSACTIONS AFTER',
12546
12543 l_trans_rec.transaction_date_entered||':'||
12544 to_char(l_trans_rec.who_info.creation_date, 'MM/DD/YYYY HH24:MI:SS'), p_log_level_rec);
12545 end if;
12547 --Bug4622110
12548 if l_trans_rec.transaction_type_code like '%RETIREMENT' then
12549 l_retirement_flag := 'Y';
12550 end if;
12551
12552 if (p_log_level_rec.statement_level) then
12553 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 4 : BEFORE LOOP FOR CURSOR c_get_ths_adj ==========','', p_log_level_rec);
12554 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.transaction_date_entered', l_trans_rec.transaction_date_entered, p_log_level_rec);
12555 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.who_info.creation_date', l_trans_rec.who_info.creation_date, p_log_level_rec);
12556 fa_debug_pkg.add(l_calling_fn, '++ l_trans_rec.transaction_header_id', l_trans_rec.transaction_header_id, p_log_level_rec);
12557 fa_debug_pkg.add(l_calling_fn, '++ l_retirement_flag', l_retirement_flag, p_log_level_rec);
12558 end if;
12559
12560 OPEN c_get_ths_adj(l_trans_rec.transaction_date_entered,
12561 l_trans_rec.who_info.creation_date,
12562 l_trans_rec.transaction_header_id,
12563 l_retirement_flag); --Bug4622110
12564
12565 LOOP -- Main loop for all transactions
12566
12567
12568 FETCH c_get_ths_adj BULK COLLECT INTO t_transaction_header_id,
12569 t_transaction_type_code,
12570 t_transaction_date_entered,
12571 t_date_effective,
12572 t_transaction_name,
12573 t_source_transaction_header_id,
12574 t_mass_reference_id,
12575 t_transaction_subtype,
12576 t_transaction_key,
12577 t_amortization_start_date,
12578 t_calling_interface,
12579 t_mass_transaction_id,
12580 t_deprn_override_flag,
12581 t_member_transaction_header_id,
12582 t_trx_reference_id,
12583 t_invoice_transaction_id,
12584 t_which_select
12585 LIMIT l_limit;
12586
12587 if (p_log_level_rec.statement_level) then
12588 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 4.1 IN Fetch c_get_ths_adj ==========','', p_log_level_rec);
12589 fa_debug_pkg.add(l_calling_fn, 'Number of rows fetched',
12590 t_transaction_header_id.COUNT, p_log_level_rec);
12591 end if;
12592
12593 if (p_log_level_rec.statement_level) then
12594 fa_debug_pkg.add(l_calling_fn, 'Number of rows fetched',
12595 t_transaction_header_id.COUNT
12596 ,p_log_level_rec => p_log_level_rec);
12597 end if;
12598
12599 -- Store total row count
12600 l_row_count := c_get_ths_adj%ROWCOUNT;
12601
12602 EXIT WHEN t_transaction_header_id.COUNT = 0;
12603
12604 FOR i IN 1..t_transaction_header_id.COUNT LOOP -- for every 100 transactions
12605 if (t_transaction_type_code(i) = 'TAX') then
12606 raise invalid_trx_to_overlap;
12607 end if;
12608
12609 l_dbr_event_type := 'AMORT_ADJ';
12610
12611 if (p_log_level_rec.statement_level) then
12612 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 4.1.1 IN For-Loop of c_get_ths_adj ==========','', p_log_level_rec);
12613 fa_debug_pkg.add(l_calling_fn, '++ IN c_get_ths_adj: t_which_select('||to_char(i)||')',t_which_select(i), p_log_level_rec);
12614 fa_debug_pkg.add(l_calling_fn, '++ t_transaction_header_id('||to_char(i)||')',t_transaction_header_id(i), p_log_level_rec);
12615 fa_debug_pkg.add(l_calling_fn, '++ t_transaction_type_code('||to_char(i)||')',t_transaction_type_code(i), p_log_level_rec);
12616 fa_debug_pkg.add(l_calling_fn, '++ t_transaction_date_entered('||to_char(i)||')',t_transaction_date_entered(i), p_log_level_rec);
12617 fa_debug_pkg.add(l_calling_fn, '++ t_amortization_start_date('||to_char(i)||')',t_amortization_start_date(i), p_log_level_rec);
12618 fa_debug_pkg.add(l_calling_fn, '++ t_transaction_subtype('||to_char(i)||')',t_transaction_subtype(i), p_log_level_rec);
12619 fa_debug_pkg.add(l_calling_fn, '++ l_dbr_event_type',l_dbr_event_type, p_log_level_rec);
12620 end if;
12621
12622 --
12623 -- don't want to process addition after any trx.
12624 --
12625 -- Bug4490414: Add CIP ADDITION(/VOID)
12626 if (not(l_adj_processed)) and
12627 (t_transaction_type_code(i) not in ('ADDITION', 'ADDITION/VOID',
12628 'CIP ADIITION', 'CIP ADDITION/VOID')) then
12629 l_adj_processed := TRUE;
12630 --tk_util.debug('1tk');
12631 elsif (l_adj_processed) and
12632 (t_transaction_type_code(i) like '%ADDITION%') then
12633 l_process_this_trx := FALSE;
12634 --tk_util.debug('2tk');
12635 end if;
12636
12637 --
12638 -- don't want to process addition/void after addition
12639 --
12643 (t_transaction_type_code(i) = 'ADDITION') then
12640 -- Bug4490414: Add CIP ADDITION/VOID
12641 -- Also elsif should only be true if addition has been processed.
12642 if (not(l_add_processed)) and
12644 l_add_processed := TRUE;
12645 --tk_util.debug('3tk');
12646 elsif (l_add_processed) and
12647 (p_trans_rec.transaction_type_code <> 'ADDITION/VOID') and
12648 (t_transaction_type_code(i) in ('ADDITION/VOID', 'CIP ADDITION/VOID')) then
12649 l_process_this_trx := FALSE;
12650 --tk_util.debug('4tk');
12651 end if;
12652
12653 l_is_this_void := FALSE;
12654
12655 if (not(l_adj_processed)) and
12656 (not(l_add_processed)) then
12657 l_is_this_void := TRUE;
12658 --tk_util.debug('5tk');
12659 end if;
12660
12661
12662 l_asset_fin_rec_old := l_asset_fin_rec_new;
12663
12664 l_trans_rec := null;
12665 l_next_period_rec := null;
12666 l_member_asset_id := null;
12667 l_member_trx_key := null;
12668
12669 l_trans_rec.transaction_header_id := t_transaction_header_id(i);
12670 l_trans_rec.transaction_type_code := t_transaction_type_code(i);
12671 l_trans_rec.transaction_date_entered := t_transaction_date_entered(i);
12672 l_trans_rec.who_info.creation_date := t_date_effective(i);
12673 l_trans_rec.transaction_name := t_transaction_name(i);
12674 l_trans_rec.source_transaction_header_id := t_source_transaction_header_id(i);
12675 l_trans_rec.mass_reference_id := t_mass_reference_id(i);
12676 l_trans_rec.transaction_subtype := t_transaction_subtype(i);
12677 l_trans_rec.transaction_key := t_transaction_key(i);
12678 l_trans_rec.amortization_start_date := t_amortization_start_date(i);
12679 l_trans_rec.calling_interface := t_calling_interface(i);
12680 l_trans_rec.mass_transaction_id := t_mass_transaction_id(i);
12681 l_trans_rec.deprn_override_flag := t_deprn_override_flag(i);
12682 l_trans_rec.member_transaction_header_id := t_member_transaction_header_id(i);
12683 l_trans_rec.trx_reference_id := t_trx_reference_id(i);
12684 l_invoice_transaction_id := t_invoice_transaction_id(i);
12685
12686 --tk_util.DumpTrxRec(l_trans_rec, to_char(i));
12687
12688 if (i=1) or
12689 (l_trans_rec.transaction_date_entered > l_period_rec.calendar_period_close_date) then
12690
12691 -- Bug6190904: Need to determine correct date to find out from which period catch-up
12692 -- needs to be calculated. This is true even for the adjustment.
12693 if (i=1) then
12694
12695 OPEN
12696 c_get_prorate_date(px_asset_fin_rec_new.date_placed_in_service
12697 ,
12698 px_asset_fin_rec_new.prorate_convention_code);
12699 FETCH c_get_prorate_date INTO l_prorate_date, l_start_date,
12700 l_end_date;
12701 CLOSE c_get_prorate_date;
12702
12703 end if;
12704
12705 if
12706 (nvl(l_trans_rec.amortization_start_date,l_trans_rec.transaction_date_entered) >
12707 l_end_date) then
12708 l_prorate_date :=
12709 nvl(l_trans_rec.amortization_start_date,l_trans_rec.transaction_date_entered);
12710 end if;
12711 -- End of Bug6190904
12712
12713 -- Bug6190904: use date determined by above logic instead of
12714 -- transaction_date_entered
12715 if not GetPeriodInfo(to_number(to_char(l_trans_rec.transaction_date_entered, 'J')),
12716 p_asset_hdr_rec.book_type_code,
12717 p_mrc_sob_type_code,
12718 l_period_rec) then
12719 if (p_log_level_rec.statement_level) then
12720 fa_debug_pkg.add(l_calling_fn, 'Error calling',
12721 'GetPeriodInfo'
12722 ,p_log_level_rec => p_log_level_rec);
12723 end if;
12724
12725 raise calc_failed;
12726 end if;
12727
12728 end if;
12729
12730 --tk_util.DumpPerRec(l_period_rec, to_char(i));
12731
12732 --
12733 -- Special processes for first transaction only
12734 --
12735 if (i = 1) and (l_row_count <= l_limit) then
12736
12737 -- Find least transaction header id
12738 FOR j IN 1..t_transaction_header_id.COUNT LOOP
12739
12740 --tk_util.debug('l_incoming_thid: '||to_char(l_incoming_thid));
12741 --tk_util.debug('t_transaction_header_id(j): '||to_char(t_transaction_header_id(j)));
12742 --tk_util.debug('t_transaction_type_code(j): '||t_transaction_type_code(j));
12743
12744 if (t_transaction_type_code(i) = 'ADDITION') then
12745 l_add_exist := TRUE;
12746 elsif (t_transaction_type_code(j) = 'ADDITION') then
12747 l_add_exist := TRUE;
12748 elsif (t_transaction_type_code(j) = 'ADDITION/VOID') then
12749 l_add_void_exist := TRUE;
12750 end if;
12751
12752 if (nvl(l_least_thid, l_incoming_thid) <> t_transaction_header_id(j)) and
12753 (nvl(l_least_thid, l_incoming_thid) > t_transaction_header_id(j)) and
12757
12754 (((p_asset_type_rec.asset_type = G_ASSET_TYPE_GROUP) and
12755 (t_transaction_header_id(j) is not null)) or
12756 (p_asset_type_rec.asset_type <> G_ASSET_TYPE_GROUP)) then
12758 --
12759 -- Cannot process addition after adjustment??? not sure this will work
12760 -- Also, do not process addition void after addition
12761 --
12762 -- Bug4490414: Commenting out part of the following if condition
12763 -- 2nd part of if (after or) does not have to check the 1st
12764 -- trx type code. Commenting out "t_transaction_type_code(i) = 'ADDITION' and"
12765 -- from 2nd part of if below.
12766
12767 if (t_transaction_type_code(i) <> 'ADDITION' and
12768 t_transaction_type_code(j) = 'ADDITION' ) or
12769 (t_transaction_type_code(j) like '%ADDITION/VOID') then
12770 null;
12771 else
12772 l_least_thid := t_transaction_header_id(j);
12773 end if;
12774 end if;
12775
12776 END LOOP;
12777
12778 if (p_log_level_rec.statement_level) then
12779 fa_debug_pkg.add(l_calling_fn, 'Least transaction header id',
12780 l_least_thid
12781 ,p_log_level_rec => p_log_level_rec);
12782 end if;
12783
12784
12785 l_temp_period_counter := l_period_rec.period_counter;
12786 l_period_rec.period_counter := l_period_rec.period_counter -1;
12787
12788 if not GetDeprnRec (
12789 p_trans_rec => l_trans_rec,
12790 p_asset_hdr_rec => p_asset_hdr_rec,
12791 p_period_rec => l_period_rec,
12792 p_incoming_trx_type_code => p_trans_rec.transaction_type_code,
12793 x_asset_deprn_rec => l_asset_deprn_rec,
12794 p_mrc_sob_type_code =>p_mrc_sob_type_code,
12795 p_unplanned_exp => l_unplanned_exp
12796 ,p_log_level_rec => p_log_level_rec) then
12797
12798 if (p_log_level_rec.statement_level) then
12799 fa_debug_pkg.add(l_calling_fn, 'Error calling',
12800 'GetDeprnRec'
12801 ,p_log_level_rec => p_log_level_rec);
12802 end if;
12803
12804 raise calc_failed;
12805 end if;
12806
12807 l_period_rec.period_counter := l_temp_period_counter;
12808
12809 --tk_util.DumpDeprnRec(l_asset_deprn_rec, 'GD');
12810
12811 l_dpr_in.asset_num := p_asset_desc_rec.asset_number;
12812 l_dpr_in.calendar_type := fa_cache_pkg.fazcbc_record.deprn_calendar;
12813 l_dpr_in.book := p_asset_hdr_rec.book_type_code;
12814 l_dpr_in.asset_id := p_asset_hdr_rec.asset_id;
12815
12816 --
12817 -- Need to reset ytd amounts for first period of the fiscal year
12818 --
12819 if (l_period_rec.period_num = 1) then
12820 l_asset_deprn_rec.ytd_deprn := l_asset_deprn_rec.deprn_amount;
12821 l_asset_deprn_rec.bonus_ytd_deprn := l_asset_deprn_rec.bonus_deprn_amount;
12822 end if;
12823 end if; -- End of Special processes for first transaction
12824
12825
12826 if (l_add_void_exist) and (not(l_add_exist)) and
12827 (t_transaction_type_code(i) = 'ADDITION/VOID') and
12828 (not(l_process_this_trx)) then
12829 --tk_util.debug('Process ADDITION VOID Transaction');
12830 l_process_this_trx := TRUE;
12831 l_is_this_void := FALSE;
12832 end if;
12833
12834
12835 if (l_asset_fin_rec_old.recoverable_cost is null) then
12836 -- This means this is the first time coming through in this main loop
12837
12838 if (not FA_CALC_DEPRN_BASIS1_PKG.GET_EOFY_EOP (
12839 p_asset_id => p_asset_hdr_rec.asset_id,
12840 p_book_type_code => p_asset_hdr_rec.book_type_code,
12841 p_fiscal_year => l_period_rec.fiscal_year,
12842 p_asset_type => p_asset_type_rec.asset_type,
12843 p_period_num => l_period_rec.period_num,
12844 p_mrc_sob_type_code => p_mrc_sob_type_code,
12845 x_eofy_recoverable_cost => l_eofy_rec_cost,
12846 x_eofy_salvage_value => l_eofy_sal_val,
12847 x_eop_recoverable_cost => l_eop_rec_cost,
12848 x_eop_salvage_value => l_eop_sal_val
12849 ,p_log_level_rec => p_log_level_rec)) then
12850 if (p_log_level_rec.statement_level) then
12851 fa_debug_pkg.add(l_calling_fn, 'Error calling',
12852 'FA_CALC_DEPRN_BASIS1_PKG.GET_EOFY_EOP'
12853 ,p_log_level_rec => p_log_level_rec);
12854 end if;
12855
12856 raise calc_failed;
12857
12858 end if;
12859
12860 if (l_eofy_rec_cost is null) then
12861 l_eofy_rec_cost := 0;
12862 l_eofy_sal_val := 0;
12863 end if;
12864
12868 l_eop_rec_cost := 0;
12865 l_eofy_fy := l_period_rec.fiscal_year;
12866
12867 if (l_eop_rec_cost is null) then
12869 l_eop_sal_val := 0;
12870 end if;
12871
12872 elsif (l_eofy_fy < l_period_rec.fiscal_year) then
12873 -- set new end of fiscal year new recoverable cost, salvage
12874 -- value and previous fiscal year.
12875
12876 l_eofy_rec_cost := l_asset_fin_rec_old.recoverable_cost;
12877 l_eofy_sal_val := l_asset_fin_rec_old.salvage_value;
12878 l_eofy_fy := l_period_rec.fiscal_year;
12879
12880 end if;
12881
12882 if (p_log_level_rec.statement_level) then
12883 fa_debug_pkg.add(l_calling_fn, 'l_eofy_fy', l_eofy_fy
12884 ,p_log_level_rec => p_log_level_rec);
12885 fa_debug_pkg.add(l_calling_fn, 'l_eofy_rec_cost', l_eofy_rec_cost
12886 ,p_log_level_rec => p_log_level_rec);
12887 fa_debug_pkg.add(l_calling_fn, 'l_eofy_sal_val', l_eofy_sal_val
12888 ,p_log_level_rec => p_log_level_rec);
12889 fa_debug_pkg.add(l_calling_fn, 'l_eop_rec_cost', l_eop_rec_cost
12890 ,p_log_level_rec => p_log_level_rec);
12891 fa_debug_pkg.add(l_calling_fn, 'l_eop_sal_val', l_eop_sal_val
12892 ,p_log_level_rec => p_log_level_rec);
12893 end if;
12894
12895 if (l_trans_rec.transaction_header_id = l_incoming_thid) then
12896
12897 if (p_log_level_rec.statement_level) then
12898 fa_debug_pkg.add(l_calling_fn, 'Entered Transaction', 'TRUE'
12899 ,p_log_level_rec => p_log_level_rec);
12900 end if;
12901
12902 l_asset_deprn_rec.deprn_reserve := l_asset_deprn_rec.deprn_reserve +
12903 nvl(p_asset_deprn_rec_adj.deprn_reserve, 0);
12904 l_asset_deprn_rec.reval_deprn_reserve :=
12905 l_asset_deprn_rec.reval_deprn_reserve +
12906 nvl(p_asset_deprn_rec_adj.reval_deprn_reserve, 0);
12907 l_asset_deprn_rec.bonus_deprn_reserve :=
12908 l_asset_deprn_rec.bonus_deprn_reserve +
12909 nvl(p_asset_deprn_rec_adj.bonus_deprn_reserve, 0);
12910
12911 l_use_fin_rec_adj := TRUE;
12912 l_use_new_deprn_rule := TRUE;
12913
12914 --+++++++ Setting this flag to resume depreciation calculation +++++
12915 if (l_calc_deprn_flag) then
12916 l_calc_deprn_flag := FALSE;
12917 end if;
12918 else
12919 if (p_log_level_rec.statement_level) then
12920 fa_debug_pkg.add(l_calling_fn, 'Entered Transaction', 'FALSE'
12921 ,p_log_level_rec => p_log_level_rec);
12922 end if;
12923
12924 l_use_fin_rec_adj := FALSE;
12925 end if;
12926
12927 if l_trans_rec.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET) then
12928
12929 l_reserve_retired := null;
12930
12931 if (p_mrc_sob_type_code = 'R') then
12932
12933 OPEN c_get_mc_retirement(nvl(l_trans_rec.member_transaction_header_id,
12934 l_trans_rec.transaction_header_id));
12935 FETCH c_get_mc_retirement INTO l_retirement_id,
12936 l_cost_retired,
12937 l_cost_of_removal,
12938 l_proceeds_of_sales,
12939 l_reserve_retired,
12940 l_eofy_reserve_retired,
12941 l_reval_reserve_retired,
12942 l_unrevalued_cost_retired,
12943 l_bonus_reserve_retired,
12944 l_recognize_gain_loss;
12945
12946 if c_get_mc_retirement%NOTFOUND then
12947 if (p_log_level_rec.statement_level) then
12948 fa_debug_pkg.add(l_calling_fn, 'Process this transaction', 'FALSE'
12949 ,p_log_level_rec => p_log_level_rec);
12950 end if;
12951
12952 l_process_this_trx := FALSE;
12953 else
12954 if (l_reserve_retired = 0) then
12955 OPEN c_get_mc_rsv_retired (nvl(l_trans_rec.member_transaction_header_id,
12956 l_trans_rec.transaction_header_id));
12957 FETCH c_get_mc_rsv_retired INTO l_reserve_retired;
12958 CLOSE c_get_mc_rsv_retired;
12959 end if;
12960
12961 if (p_log_level_rec.statement_level) then
12962 fa_debug_pkg.add(l_calling_fn, 'Process this '||
12963 l_trans_rec.transaction_type_code, 'TRUE'
12964 ,p_log_level_rec => p_log_level_rec);
12965 end if;
12966 end if; -- c_get_mc_retirement%NOTFOUND
12967
12968 CLOSE c_get_mc_retirement;
12969 else
12970 --tk_util.debug('thid: '||to_char(nvl(l_trans_rec.member_transaction_header_id, l_trans_rec.transaction_header_id)));
12974 l_cost_retired,
12971 OPEN c_get_retirement(nvl(l_trans_rec.member_transaction_header_id,
12972 l_trans_rec.transaction_header_id));
12973 FETCH c_get_retirement INTO l_retirement_id,
12975 l_cost_of_removal,
12976 l_proceeds_of_sales,
12977 l_reserve_retired,
12978 l_eofy_reserve_retired,
12979 l_reval_reserve_retired,
12980 l_unrevalued_cost_retired,
12981 l_bonus_reserve_retired,
12982 l_recognize_gain_loss;
12983
12984 if c_get_retirement%NOTFOUND then
12985 if (p_log_level_rec.statement_level) then
12986 fa_debug_pkg.add(l_calling_fn, 'Process this transaction', 'FALSE'
12987 ,p_log_level_rec => p_log_level_rec);
12988 end if;
12989
12990 l_process_this_trx := FALSE;
12991 else
12992
12993 if (l_reserve_retired = 0) then
12994 OPEN c_get_rsv_retired (nvl(l_trans_rec.member_transaction_header_id,
12995 l_trans_rec.transaction_header_id));
12996 FETCH c_get_rsv_retired INTO l_reserve_retired;
12997 CLOSE c_get_rsv_retired;
12998 end if;
12999
13000 if (p_log_level_rec.statement_level) then
13001 fa_debug_pkg.add(l_calling_fn, 'Process this '||
13002 l_trans_rec.transaction_type_code, 'TRUE'
13003 ,p_log_level_rec => p_log_level_rec);
13004 end if;
13005
13006 end if; -- c_get_retirement%NOTFOUND
13007
13008 CLOSE c_get_retirement;
13009
13010 end if; -- (p_mrc_sob_type_code = 'R')
13011
13012 if (p_log_level_rec.statement_level) then
13013 fa_debug_pkg.add(l_calling_fn, 'Retirement Id',
13014 l_retirement_id
13015 ,p_log_level_rec => p_log_level_rec);
13016 fa_debug_pkg.add(l_calling_fn, 'Retired Reserve',
13017 l_reserve_retired
13018 ,p_log_level_rec => p_log_level_rec);
13019 end if;
13020
13021 elsif l_trans_rec.transaction_type_code = G_TRX_TYPE_REV then
13022
13023 if (p_mrc_sob_type_code = 'R') then
13024 OPEN c_get_mc_reval_rsv(nvl(l_trans_rec.member_transaction_header_id,
13025 l_trans_rec.transaction_header_id));
13026 FETCH c_get_mc_reval_rsv INTO l_reval_reserve;
13027 CLOSE c_get_mc_reval_rsv;
13028
13029 OPEN c_get_mc_bonus_reval_rsv(nvl(l_trans_rec.member_transaction_header_id,
13030 l_trans_rec.transaction_header_id));
13031 FETCH c_get_mc_bonus_reval_rsv INTO l_reval_bonus_reserve;
13032 CLOSE c_get_mc_bonus_reval_rsv;
13033 else
13034 OPEN c_get_reval_rsv(nvl(l_trans_rec.member_transaction_header_id,
13035 l_trans_rec.transaction_header_id));
13036 FETCH c_get_reval_rsv INTO l_reval_reserve;
13037 CLOSE c_get_reval_rsv;
13038
13039 OPEN c_get_bonus_reval_rsv(nvl(l_trans_rec.member_transaction_header_id,
13040 l_trans_rec.transaction_header_id));
13041 FETCH c_get_bonus_reval_rsv INTO l_reval_bonus_reserve;
13042 CLOSE c_get_bonus_reval_rsv;
13043 end if;
13044
13045
13046 if (p_log_level_rec.statement_level) then
13047 fa_debug_pkg.add(l_calling_fn, 'Revaluation Reserve',
13048 l_reval_reserve
13049 ,p_log_level_rec => p_log_level_rec);
13050 fa_debug_pkg.add(l_calling_fn, 'Revaluation Reserve',
13051 l_reval_bonus_reserve
13052 ,p_log_level_rec => p_log_level_rec);
13053 end if;
13054 end if; -- l_trans_rec.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET)
13055
13056 --
13057 -- Construct new fa_books row.
13058 -- For first transaction, also get initial fa_books row.
13059 if (l_process_this_trx) or
13060 ((i = 1) and (l_row_count < l_limit)) then
13061
13062 if not GetFinRec(p_trans_rec => l_trans_rec,
13063 p_asset_hdr_rec => p_asset_hdr_rec,
13064 p_asset_type_rec => p_asset_type_rec,
13065 px_asset_fin_rec => l_asset_fin_rec_old,
13066 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
13067 p_asset_fin_rec_new => px_asset_fin_rec_new,
13068 x_asset_fin_rec_new => l_asset_fin_rec_new,
13069 p_init_transaction_header_id => l_least_thid,
13070 p_use_fin_rec_adj => l_use_fin_rec_adj,
13074 p_mrc_sob_type_code => p_mrc_sob_type_code) then
13071 p_use_new_deprn_rule => l_use_new_deprn_rule,
13072 p_process_this_trx => (l_process_this_trx or l_is_this_void),
13073 x_dpis_change => l_dpis_change,
13075 if (p_log_level_rec.statement_level) then
13076 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13077 'GetFinRec'
13078 ,p_log_level_rec => p_log_level_rec);
13079 end if;
13080
13081 raise calc_failed;
13082 end if;
13083
13084 --
13085 -- This portion of codes are relocated from before GetFinRec because it sometime
13086 -- requires to find old cost(new cost - cost retired).
13087 --
13088 if (l_trans_rec.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET)) then
13089 if (l_reserve_retired <> 0) then
13090 l_reserve_retired := l_asset_deprn_rec.deprn_reserve *
13091 (l_cost_retired /nvl(l_asset_fin_rec_old.cost,l_asset_fin_rec_new.cost - l_cost_retired));
13092 if not FA_UTILS_PKG.faxrnd(l_reserve_retired, p_asset_hdr_rec.book_type_code) then
13093 fa_debug_pkg.add(l_calling_fn, 'calling FA_UTILS_PKG.faxrnd', 'FAILED'
13094 ,p_log_level_rec => p_log_level_rec);
13095 raise calc_failed;
13096 end if;
13097 end if;
13098
13099 if (p_log_level_rec.statement_level) then
13100 fa_debug_pkg.add(l_calling_fn, 'Recalculated Reserve Retired',
13101 l_reserve_retired
13102 ,p_log_level_rec => p_log_level_rec);
13103 end if;
13104
13105 -- Populate local retire rec for depreciable basis to bahave like retirement
13106 l_asset_retire_rec.cost_retired := l_cost_retired;
13107 l_asset_retire_rec.proceeds_of_sale := l_proceeds_of_sales;
13108 l_asset_retire_rec.cost_of_removal := l_cost_of_removal;
13109 l_asset_retire_rec.detail_info.nbv_retired := l_cost_retired - l_reserve_retired;
13110
13111 l_dbr_event_type := 'RETIREMENT';
13112
13113 end if; -- l_trans_rec.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET)
13114
13115 if (l_dpis_change) then
13116 if (p_mrc_sob_type_code = 'R') then
13117 OPEN c_get_mc_brow;
13118 FETCH c_get_mc_brow INTO l_brow_ytd_deprn, l_brow_deprn_reserve;
13119 CLOSE c_get_mc_brow;
13120 else
13121 OPEN c_get_brow;
13122 FETCH c_get_brow INTO l_brow_ytd_deprn, l_brow_deprn_reserve;
13123 CLOSE c_get_brow;
13124 end if;
13125 --tk_util.debug('check: '||to_char(l_brow_ytd_deprn)||':'||to_char(l_brow_deprn_reserve));
13126 --
13127 -- need to initialize l_asset_deprn_rec with B row.
13128 l_asset_deprn_rec.deprn_amount := 0;
13129 l_asset_deprn_rec.ytd_deprn := nvl(l_brow_ytd_deprn, 0);
13130 l_asset_deprn_rec.deprn_reserve := nvl(l_brow_deprn_reserve, 0);
13131 l_asset_deprn_rec.prior_fy_expense := 0;
13132 l_asset_deprn_rec.bonus_deprn_amount := 0;
13133 l_asset_deprn_rec.bonus_ytd_deprn := 0;
13134 l_asset_deprn_rec.bonus_deprn_reserve := 0;
13135 l_asset_deprn_rec.prior_fy_bonus_expense := 0;
13136 l_asset_deprn_rec.reval_amortization := 0;
13137 l_asset_deprn_rec.reval_amortization_basis := 0;
13138 l_asset_deprn_rec.reval_deprn_expense := 0;
13139 l_asset_deprn_rec.reval_ytd_deprn := 0;
13140 l_asset_deprn_rec.reval_deprn_reserve := 0;
13141 l_asset_deprn_rec.production := 0;
13142 l_asset_deprn_rec.ytd_production := 0;
13143 l_asset_deprn_rec.ltd_production := 0;
13144
13145 if (l_trans_rec.transaction_subtype = 'EXPENSED') then
13146 --Bug#4049799 l_dbr_event_type := 'EXPENSED_ADJ';
13147 l_dbr_event_type := 'AMORT_ADJ';
13148 end if;
13149
13150 if (p_log_level_rec.statement_level) then
13151 fa_debug_pkg.add(l_calling_fn, 'DPIS Change', l_dbr_event_type
13152 ,p_log_level_rec => p_log_level_rec);
13153 fa_debug_pkg.add(l_calling_fn, 'new ytd_deprn', l_asset_deprn_rec.ytd_deprn
13154 ,p_log_level_rec => p_log_level_rec);
13155 fa_debug_pkg.add(l_calling_fn, 'new deprn_reserve', l_asset_deprn_rec.deprn_reserve
13156 ,p_log_level_rec => p_log_level_rec);
13157 end if;
13158 end if;
13159 --tk_util.debug('1 rec_cost: '||to_char(px_asset_fin_rec_new.recoverable_cost));
13160
13161 if l_trans_rec.transaction_type_code not in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET) then
13162 if ((i = 1) and not(l_start_from_first) and (l_process_addition = 0)) then
13166 l_asset_fin_rec_new.eofy_reserve := l_asset_deprn_rec.deprn_reserve;
13163 if (p_log_level_rec.statement_level) then
13164 fa_debug_pkg.add(l_calling_fn, 'deprn_reserve', l_asset_deprn_rec.deprn_reserve, p_log_level_rec);
13165 end if;
13167
13168 elsif ((i = 1) and (l_row_count < l_limit)) then
13169 --
13170 -- if this is member or will be a member, l_eofy_reserve may not be populated
13171 -- in GetFinRec so use the one returned by GetEofyReserve function.
13172 --
13173 if (p_asset_fin_rec_old.group_asset_id is null and
13174 px_asset_fin_rec_new.group_asset_id is null) then
13175 l_asset_fin_rec_new.eofy_reserve := l_eofy_reserve;
13176 end if;
13177 else
13178 l_asset_fin_rec_new.eofy_reserve := l_asset_fin_rec_old.eofy_reserve;
13179 end if;
13180 end if;
13181
13182 else
13183 l_asset_fin_rec_new := l_asset_fin_rec_old;
13184 end if; -- (l_process_this_trx)
13185
13186 --tk_util.debug('1eofy rsv: '||to_char(l_asset_fin_rec_new.eofy_reserve));
13187
13188 l_dpr_in.adj_cost := l_asset_fin_rec_new.recoverable_cost;
13189 l_dpr_in.rec_cost := l_asset_fin_rec_new.recoverable_cost;
13190 l_dpr_in.reval_amo_basis := l_asset_fin_rec_new.reval_amortization_basis;
13191 l_dpr_in.deprn_rsv := 0;
13192 l_dpr_in.reval_rsv := l_asset_deprn_rec.reval_deprn_reserve;
13193 l_dpr_in.adj_rate := l_asset_fin_rec_new.adjusted_rate;
13194 l_dpr_in.rate_adj_factor := l_asset_fin_rec_new.rate_adjustment_factor;
13195 l_dpr_in.capacity := l_asset_fin_rec_new.production_capacity;
13196 l_dpr_in.adj_capacity := l_asset_fin_rec_new.adjusted_capacity;
13197 l_dpr_in.ltd_prod := 0;
13198
13199 l_dpr_in.ceil_name := l_asset_fin_rec_new.ceiling_name;
13200 l_dpr_in.bonus_rule := l_asset_fin_rec_new.bonus_rule;
13201 l_dpr_in.method_code := l_asset_fin_rec_new.deprn_method_code;
13202 l_dpr_in.jdate_in_service :=
13203 to_number(to_char(l_asset_fin_rec_new.date_placed_in_service, 'J'));
13204 l_dpr_in.prorate_jdate := to_number(to_char(l_asset_fin_rec_new.prorate_date, 'J'));
13205 l_dpr_in.deprn_start_jdate :=
13206 to_number(to_char(l_asset_fin_rec_new.deprn_start_date, 'J'));
13207 l_dpr_in.jdate_retired := 0; -- don't know this is correct or not
13208 l_dpr_in.ret_prorate_jdate := 0; -- don't know this is correct or not
13209 l_dpr_in.life := l_asset_fin_rec_new.life_in_months;
13210
13211 l_dpr_in.rsv_known_flag := TRUE;
13212 l_dpr_in.salvage_value := l_asset_fin_rec_new.salvage_value;
13213 l_dpr_in.pc_life_end := l_asset_fin_rec_new.period_counter_life_complete;
13214 l_dpr_in.adj_rec_cost := l_asset_fin_rec_new.adjusted_recoverable_cost;
13215 l_dpr_in.prior_fy_exp := 0; -- This needs to be 0 for this faxcde call
13216
13217 -- Bug:5612206
13218 l_dpr_in.deprn_rounding_flag := null;
13219
13220 l_dpr_in.deprn_override_flag := p_trans_rec.deprn_override_flag;
13221 l_dpr_in.used_by_adjustment := TRUE;
13222 l_dpr_in.ytd_deprn := 0; -- This needs to be 0 for this faxcde call
13223 l_dpr_in.short_fiscal_year_flag := l_asset_fin_rec_new.short_fiscal_year_flag;
13224 l_dpr_in.conversion_date := l_asset_fin_rec_new.conversion_date;
13225 l_dpr_in.prorate_date := l_asset_fin_rec_new.prorate_date;
13226 l_dpr_in.orig_deprn_start_date := l_asset_fin_rec_new.orig_deprn_start_date;
13227 l_dpr_in.old_adj_cost := l_asset_fin_rec_new.old_adjusted_cost;
13228 l_dpr_in.formula_factor := nvl(l_asset_fin_rec_new.formula_factor,
13229 l_asset_fin_rec_old.formula_factor);
13230 l_dpr_in.bonus_deprn_exp := l_asset_deprn_rec.bonus_deprn_amount;
13231 l_dpr_in.bonus_ytd_deprn := l_asset_deprn_rec.bonus_ytd_deprn;
13232 l_dpr_in.bonus_deprn_rsv := l_asset_deprn_rec.bonus_deprn_reserve;
13233 l_dpr_in.prior_fy_bonus_exp := l_asset_deprn_rec.prior_fy_bonus_expense;
13234
13235 l_dpr_in.tracking_method := l_asset_fin_rec_new.tracking_method;
13236 l_dpr_in.allocate_to_fully_ret_flag := l_asset_fin_rec_new.allocate_to_fully_ret_flag;
13237 l_dpr_in.allocate_to_fully_rsv_flag := l_asset_fin_rec_new.allocate_to_fully_rsv_flag;
13238 l_dpr_in.excess_allocation_option := l_asset_fin_rec_new.excess_allocation_option;
13239 l_dpr_in.depreciation_option := l_asset_fin_rec_new.depreciation_option;
13240 l_dpr_in.member_rollup_flag := l_asset_fin_rec_new.member_rollup_flag;
13241 l_dpr_in.mrc_sob_type_code := p_mrc_sob_type_code;
13242 l_dpr_in.super_group_id := l_asset_fin_rec_new.super_group_id;
13243 l_dpr_in.over_depreciate_option := l_asset_fin_rec_new.over_depreciate_option;
13244
13245 --
13246 -- Not for what-if yet
13247 --
13248 l_running_mode := fa_std_types.FA_DPR_NORMAL;
13249 --tk_util.debug('2 rec_cost: '||to_char(px_asset_fin_rec_new.recoverable_cost));
13250
13251 if (l_process_this_trx) then
13252
13253 if (not fa_cache_pkg.fazccmt(
13254 l_asset_fin_rec_new.deprn_method_code,
13255 l_asset_fin_rec_new.life_in_months
13259 'fa_cache_pkg.fazccmt'
13256 ,p_log_level_rec => p_log_level_rec)) then
13257 if (p_log_level_rec.statement_level) then
13258 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13260 ,p_log_level_rec => p_log_level_rec);
13261 end if;
13262
13263 raise calc_failed;
13264 end if;
13265
13266 l_energy_member := FALSE;
13267 --tk_util.debug('fa_cache_pkg.fazcdbr_record.rule_name: ' ||fa_cache_pkg.fazcdbr_record.rule_name);
13268 --tk_util.debug('p_asset_fin_rec_old.tracking_method: '||p_asset_fin_rec_old.tracking_method);
13269 --
13270 -- Set l_energy_member to skip periodic depreciation call in this functioin
13271 --
13272 if (fa_cache_pkg.fazcdbr_record.rule_name = 'ENERGY PERIOD END BALANCE') and
13273 (p_asset_fin_rec_old.tracking_method = 'ALLOCATE') then
13274 l_energy_member := TRUE;
13275 end if;
13276
13277 -- skip faxcde call for raf
13278 -- Bug4778244 Added the NVL to avoid condition if(not(null or false)) which will
13279 -- always return NULL in place of FALSE, which is incorrect
13280 if (not(((nvl(fa_cache_pkg.fazccmt_record.rate_source_rule, ' ') = fa_std_types.FAD_RSR_FLAT) and
13281 (nvl(fa_cache_pkg.fazccmt_record.deprn_basis_rule, ' ') = fa_std_types.FAD_DBR_COST) and
13282 (nvl(fa_cache_pkg.fazcdbr_record.rule_name, ' ') in ('PERIOD END BALANCE',
13283 'PERIOD END AVERAGE',
13284 'USE RECOVERABLE COST',
13285 'BEGINNING PERIOD'))) or
13286 ((nvl(fa_cache_pkg.fazcdbr_record.rule_name, ' ') = 'ENERGY PERIOD END BALANCE') and
13287 (nvl(p_asset_fin_rec_old.tracking_method, ' ') = 'ALLOCATE')))) then
13288 if not fa_cache_pkg.fazccp(fa_cache_pkg.fazcbc_record.prorate_calendar,
13289 fa_cache_pkg.fazcbc_record.fiscal_year_name,
13290 l_dpr_in.prorate_jdate,
13291 g_temp_number,
13292 l_dpr_in.y_begin,
13293 g_temp_integer
13294 ,p_log_level_rec => p_log_level_rec) then
13295 if (p_log_level_rec.statement_level) then
13296 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13297 'fa_cache_pkg.fazccp'
13298 ,p_log_level_rec => p_log_level_rec);
13299 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.prorate_calendar',
13300 fa_cache_pkg.fazcbc_record.prorate_calendar
13301 ,p_log_level_rec => p_log_level_rec);
13302 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.fiscal_year_name',
13303 fa_cache_pkg.fazcbc_record.fiscal_year_name
13304 ,p_log_level_rec => p_log_level_rec);
13305
13306 end if;
13307
13308 raise calc_failed;
13309 end if;
13310
13311 if not fa_cache_pkg.fazcct(fa_cache_pkg.fazcbc_record.deprn_calendar) then
13312 raise calc_failed;
13313 end if;
13314
13315 l_dpr_in.p_cl_begin := 1;
13316
13317 if (l_period_rec.period_num = 1) then
13318 l_dpr_in.y_end := l_period_rec.fiscal_year - 1;
13319 l_dpr_in.p_cl_end := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
13320 else
13321 l_dpr_in.y_end := l_period_rec.fiscal_year;
13322 l_dpr_in.p_cl_end := l_period_rec.period_num - 1;
13323 end if;
13324
13325 l_dpr_in.rate_adj_factor := 1;
13326 l_dpr_in.eofy_reserve := 0;
13327
13328 -- manual override
13329 if fa_cache_pkg.fa_deprn_override_enabled then
13330
13331 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
13332 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
13333
13334 -- update override status only if satisfies condintion,
13335 -- otherwise do not update status when calculating RAF
13336 -- 1. formula; or
13337 -- 2. (calc or table) and cost
13338
13339 l_dpr_in.update_override_status :=
13340 ((l_rate_source_rule = fa_std_types.FAD_RSR_FORMULA)
13341 OR (((l_rate_source_rule = fa_std_types.FAD_RSR_CALC)
13342 OR (l_rate_source_rule = fa_std_types.FAD_RSR_TABLE))
13343 AND (l_deprn_basis_rule = fa_std_types.FAD_DBR_COST)));
13344 end if;
13345
13346 --+++++++ Call Tracking Function to populate Member in case ALLOCATE ++++++
13347 if nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
13348 /*
13349 if not FA_TRACK_MEMBER_PVT.get_member_at_start(
13350 p_trans_rec => l_trans_rec,
13351 p_asset_hdr_rec => p_asset_hdr_rec,
13352 p_dpr_in => l_dpr_in,
13356 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13353 p_mrc_sob_type_code => p_mrc_sob_type_code
13354 ,p_log_level_rec => p_log_level_rec) then
13355 if (p_log_level_rec.statement_level) then
13357 'FA_TRACK_MEMBER_PVT.get_member_at_start'
13358 ,p_log_level_rec => p_log_level_rec);
13359 end if;
13360
13361 raise calc_failed;
13362
13363 end if;
13364 */null;
13365 end if; -- nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE'
13366
13367 l_dpr_in.cost_frac := null; -- Bug 5948890
13368
13369 if (p_log_level_rec.statement_level) then
13370 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
13371 ,p_log_level_rec => p_log_level_rec);
13372 fa_debug_pkg.add(l_calling_fn, ' Call ', 'FA_CDE_PKG.faxcde'
13373 ,p_log_level_rec => p_log_level_rec);
13374 end if;
13375
13376 --+++++++ Call Depreciation engine for rate adjustment factor +++++++
13377 if not FA_CDE_PKG.faxcde(l_dpr_in,
13378 l_dpr_arr,
13379 l_dpr_out,
13380 l_running_mode
13381 ,p_log_level_rec => p_log_level_rec) then
13382 if (p_log_level_rec.statement_level) then
13383 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13384 'FA_CDE_PKG.faxcde'
13385 ,p_log_level_rec => p_log_level_rec);
13386 end if;
13387
13388 raise calc_failed;
13389 end if;
13390
13391 if (p_log_level_rec.statement_level) then
13392 fa_debug_pkg.add(l_calling_fn, 'l_dpr_out.new_deprn_rsv',
13393 l_dpr_out.new_deprn_rsv
13394 ,p_log_level_rec => p_log_level_rec);
13395 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
13396 ,p_log_level_rec => p_log_level_rec);
13397 end if;
13398
13399 -- manual override
13400 if fa_cache_pkg.fa_deprn_override_enabled then
13401 if l_dpr_in.update_override_status then
13402 p_trans_rec.deprn_override_flag := l_dpr_out.deprn_override_flag;
13403 else
13404 p_trans_rec.deprn_override_flag := fa_std_types.FA_NO_OVERRIDE;
13405 end if;
13406 end if;
13407
13408 l_asset_fin_rec_new.adjusted_cost := l_dpr_out.new_adj_cost;
13409 l_asset_fin_rec_new.reval_amortization_basis := l_dpr_out.new_reval_amo_basis;
13410 l_asset_deprn_rec_raf.deprn_reserve := l_dpr_out.new_deprn_rsv;
13411 l_asset_deprn_rec_raf.reval_deprn_reserve := l_dpr_out.new_reval_rsv;
13412 l_asset_fin_rec_new.adjusted_capacity := l_asset_fin_rec_new.production_capacity -
13413 l_dpr_out.new_ltd_prod;
13414 l_asset_deprn_rec_raf.ltd_production := l_dpr_out.new_ltd_prod;
13415 l_asset_deprn_rec_raf.prior_fy_expense := l_dpr_out.new_prior_fy_exp;
13416 l_asset_deprn_rec_raf.bonus_deprn_amount := l_dpr_out.bonus_deprn_exp;
13417 l_asset_deprn_rec_raf.bonus_deprn_reserve := l_dpr_out.new_bonus_deprn_rsv;
13418 l_asset_deprn_rec_raf.prior_fy_bonus_expense := l_dpr_out.new_prior_fy_bonus_exp;
13419
13420 --++++++++ Tracking=ALLOCATE case ++++++++++++++
13421 if nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
13422
13423 fa_track_member_pvt.p_track_member_table.delete;
13424
13425 if (p_log_level_rec.statement_level) then
13426 fa_debug_pkg.add(l_calling_fn, 'fa_track_member_pvt.p_track_member_table',
13427 'deleted'
13428 ,p_log_level_rec => p_log_level_rec);
13429 end if;
13430 end if;
13431
13432 else
13433 l_asset_fin_rec_new.adjusted_cost := l_asset_fin_rec_new.recoverable_cost;
13434 end if; ---- skip faxcde call for raf
13435 --tk_util.debug('2eofy rsv: '||to_char(l_asset_fin_rec_new.eofy_reserve));
13436
13437 --++++ Eofy Reserve in case of reclass ++++
13438 if l_trans_rec.transaction_type_code <> 'GROUP ADDITION' then
13439 l_asset_fin_rec_new.eofy_reserve := l_asset_fin_rec_new.eofy_reserve +
13440 nvl(p_asset_fin_rec_adj.eofy_reserve,0);
13441 end if;
13442
13443 if l_trans_rec.transaction_type_code in (G_TRX_TYPE_FUL_RET, G_TRX_TYPE_PAR_RET) then
13444 l_asset_fin_rec_new.eofy_reserve := l_asset_fin_rec_new.eofy_reserve -
13445 l_eofy_reserve_retired;
13446
13447 --++++ Skip followings because these values are already take care
13448 --++++ by using asset_deprn_rec_adj
13449 if (l_trans_rec.transaction_header_id <> p_trans_rec.transaction_header_id) then
13453 l_reval_reserve_retired;
13450 l_asset_deprn_rec.deprn_reserve := l_asset_deprn_rec.deprn_reserve -
13451 l_reserve_retired;
13452 l_asset_deprn_rec.reval_deprn_reserve := l_asset_deprn_rec.reval_deprn_reserve -
13454 l_asset_deprn_rec.bonus_deprn_reserve := l_asset_deprn_rec.bonus_deprn_reserve -
13455 l_bonus_reserve_retired;
13456 end if;
13457 elsif l_trans_rec.transaction_type_code = G_TRX_TYPE_REV then
13458 if (l_trans_rec.transaction_header_id <> p_trans_rec.transaction_header_id) then
13459 l_asset_deprn_rec.deprn_reserve := l_asset_deprn_rec.deprn_reserve +
13460 nvl(l_reval_reserve, 0);
13461 l_asset_deprn_rec.reval_deprn_reserve := l_asset_deprn_rec.reval_deprn_reserve +
13462 nvl(l_reval_reserve, 0);
13463 l_asset_deprn_rec.bonus_deprn_reserve := l_asset_deprn_rec.bonus_deprn_reserve +
13464 nvl(l_reval_bonus_reserve, 0);
13465 end if;
13466 end if;
13467
13468 --tk_util.debug('3 rec_cost: '||to_char(px_asset_fin_rec_new.recoverable_cost));
13469
13470 -- Get Unplanned amount
13471 if (l_trans_rec.transaction_key in ('UE', 'UA')) then
13472
13473 if (not GetExpRsv(p_trans_rec => l_trans_rec,
13474 p_asset_hdr_rec => p_asset_hdr_rec,
13475 p_period_rec => l_period_rec,
13476 p_mrc_sob_type_code => p_mrc_sob_type_code,
13477 x_exp_rsv_amount => l_reserve_adj
13478 ,p_log_level_rec => p_log_level_rec)) then
13479
13480 if (p_log_level_rec.statement_level) then
13481 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13482 'GetExpRsv'
13483 ,p_log_level_rec => p_log_level_rec);
13484 end if;
13485
13486 raise calc_failed;
13487 end if;
13488
13489 l_asset_deprn_rec.deprn_reserve := l_asset_deprn_rec.deprn_reserve + l_reserve_adj;
13490
13491 if (l_trans_rec.transaction_key in ('UE', 'UA')) then
13492 l_asset_deprn_rec.ytd_deprn := l_asset_deprn_rec.ytd_deprn + l_reserve_adj;
13493 end if;
13494
13495 end if;
13496
13497 --tk_util.debug('3eofy rsv: '||to_char(l_asset_fin_rec_new.eofy_reserve));
13498 if (p_log_level_rec.statement_level) then
13499 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
13500 ,p_log_level_rec => p_log_level_rec);
13501 fa_debug_pkg.add(l_calling_fn, ' Call ',
13502 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
13503 ,p_log_level_rec => p_log_level_rec);
13504 fa_debug_pkg.add(l_calling_fn, 'p_trans_rec.transaction_type_code',
13505 p_trans_rec.transaction_type_code
13506 ,p_log_level_rec => p_log_level_rec);
13507 fa_debug_pkg.add(l_calling_fn, 'l_trans_rec.transaction_type_code',
13508 l_trans_rec.transaction_type_code
13509 ,p_log_level_rec => p_log_level_rec);
13510 fa_debug_pkg.add(l_calling_fn, 'l_eofy_reserve_retired',
13511 l_eofy_reserve_retired
13512 ,p_log_level_rec => p_log_level_rec);
13513 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_adj.eofy_reserve',
13514 l_asset_fin_rec_adj.eofy_reserve
13515 ,p_log_level_rec => p_log_level_rec);
13516 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.eofy_reserve',
13517 l_asset_fin_rec_new.eofy_reserve
13518 ,p_log_level_rec => p_log_level_rec);
13519 fa_debug_pkg.add(l_calling_fn, 'l_asset_deprn_rec.deprn_reserve',
13520 l_asset_deprn_rec.deprn_reserve
13521 ,p_log_level_rec => p_log_level_rec);
13522 end if;
13523
13524 --tk_util.debug('4 rec_cost: '||to_char(px_asset_fin_rec_new.recoverable_cost));
13525 --
13526 -- if this is source line trx and there is no cost impact,
13527 -- do not call deprn basis function
13528 --
13529 if (not (l_invoice_transaction_id is not null and
13530 nvl(l_asset_fin_rec_old.cost, 0) = l_asset_fin_rec_new.cost)) then
13531
13532 -- Bug 6945270: Populate the transaction_key for Extended method
13533 if (l_asset_fin_rec_new.deprn_method_code = 'JP-STL-EXTND') then
13534 l_trans_rec.transaction_key := 'ES';
13535 end if;
13536
13537 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
13538 (p_event_type => l_dbr_event_type,
13539 p_asset_fin_rec_new => l_asset_fin_rec_new,
13540 p_asset_fin_rec_old => l_asset_fin_rec_old,
13541 p_asset_hdr_rec => p_asset_hdr_rec,
13542 p_asset_type_rec => p_asset_type_rec,
13546 p_trans_rec_adj => l_trans_rec,
13543 p_asset_deprn_rec => l_asset_deprn_rec,
13544 p_asset_retire_rec => l_asset_retire_rec,
13545 p_trans_rec => p_trans_rec,
13547 p_period_rec => l_period_rec,
13548 p_recoverable_cost => px_asset_fin_rec_new.recoverable_cost,
13549 p_current_total_rsv => l_asset_deprn_rec.deprn_reserve,
13550 p_current_rsv => l_asset_deprn_rec.deprn_reserve -
13551 l_asset_deprn_rec.bonus_deprn_reserve,
13552 p_current_total_ytd => l_asset_deprn_rec.ytd_deprn,
13553 p_adj_reserve => p_asset_deprn_rec_adj.deprn_reserve,
13554 p_reserve_retired => l_reserve_retired,
13555 p_hyp_basis => l_asset_fin_rec_new.adjusted_cost,
13556 p_hyp_total_rsv => l_asset_deprn_rec_raf.deprn_reserve,
13557 p_hyp_rsv => l_asset_deprn_rec_raf.deprn_reserve -
13558 l_asset_deprn_rec_raf.bonus_deprn_reserve,
13559 p_eofy_recoverable_cost => l_eofy_rec_cost,
13560 p_eop_recoverable_cost => l_eop_rec_cost,
13561 p_eofy_salvage_value => l_eofy_sal_val,
13562 p_eop_salvage_value => l_eop_sal_val,
13563 p_mrc_sob_type_code => p_mrc_sob_type_code,
13564 p_used_by_adjustment => 'ADJUSTMENT',
13565 px_new_adjusted_cost => l_asset_fin_rec_new.adjusted_cost,
13566 px_new_raf => l_asset_fin_rec_new.rate_adjustment_factor,
13567 px_new_formula_factor => l_asset_fin_rec_new.formula_factor
13568 ,p_log_level_rec => p_log_level_rec)) then
13569 if (p_log_level_rec.statement_level) then
13570 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13571 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
13572 ,p_log_level_rec => p_log_level_rec);
13573 end if;
13574
13575 raise calc_failed;
13576 end if;
13577
13578 else
13579 l_asset_fin_rec_new.adjusted_cost := l_asset_fin_rec_old.adjusted_cost;
13580 l_asset_fin_rec_new.rate_adjustment_factor := l_asset_fin_rec_old.rate_adjustment_factor;
13581 l_asset_fin_rec_new.formula_factor := l_asset_fin_rec_old.formula_factor;
13582 end if;
13583
13584 --tk_util.debug('l_asset_fin_rec_new.cost: '||to_char(l_asset_fin_rec_new.cost));
13585 if (p_log_level_rec.statement_level) then
13586 fa_debug_pkg.add(l_calling_fn, 'Returned values from ',
13587 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
13588 ,p_log_level_rec => p_log_level_rec);
13589 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_cost',
13590 l_asset_fin_rec_new.adjusted_cost
13591 ,p_log_level_rec => p_log_level_rec);
13592 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.rate_adjustment_factor',
13593 l_asset_fin_rec_new.rate_adjustment_factor
13594 ,p_log_level_rec => p_log_level_rec);
13595 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.formula_factor',
13596 l_asset_fin_rec_new.formula_factor
13597 ,p_log_level_rec => p_log_level_rec);
13598 fa_debug_pkg.add(l_calling_fn, '====== ', '=============================='
13599 ,p_log_level_rec => p_log_level_rec);
13600 end if;
13601
13602 end if; -- (l_process_this_trx)
13603
13604 --++++++ Don't want to calculate depreciation this period +++++++
13605 if (l_calc_deprn_flag) then
13606 l_temp_adjusted_cost := l_asset_fin_rec_new.adjusted_cost;
13607 l_asset_fin_rec_new.adjusted_cost := 0;
13608 end if;
13609
13610 --
13611 -- Run Depreciation if:
13612 -- - next available transaction (in table) is NOT the same period
13613 -- - This is the last transaction to recalculate which is not in
13614 -- current period.
13615 -- - This is the last trnsaction because of the limit specified
13616 -- at BULK fetch above. (Inside of following if clause, try to get
13617 -- next transaction from database and determine if depreciation needs
13618 -- to be called or not.
13619 --
13620 if (p_log_level_rec.statement_level) then
13621 fa_debug_pkg.add(l_calling_fn, 'Run Depreciation ', i
13622 ,p_log_level_rec => p_log_level_rec);
13623 fa_debug_pkg.add(l_calling_fn, 't_transaction_header_id.COUNT',
13624 t_transaction_header_id.COUNT
13625 ,p_log_level_rec => p_log_level_rec);
13626 fa_debug_pkg.add(l_calling_fn, 'l_period_rec.period_counter',
13627 l_period_rec.period_counter
13631 ,p_log_level_rec => p_log_level_rec);
13628 ,p_log_level_rec => p_log_level_rec);
13629 fa_debug_pkg.add(l_calling_fn, 'p_period_rec.period_counter',
13630 p_period_rec.period_counter
13632 end if;
13633
13634 if (i < t_transaction_header_id.COUNT) then
13635
13636 --
13637 -- Get period informatioin for next period
13638 -- If the next transaction is not in the current period, call cache.
13639 -- Otherwise, copy current one to next period info local variable.
13640 --
13641 -- Bug6190904: there is a case that following amortized adjustment
13642 -- needs to be processed
13643 -- before moving on to the next period depending on
13644 -- prorate convention setting.
13645 -- l_end_date stores end date of prorate period where
13646 -- dpis falls in and if
13647 -- subsequent trx's amort date is before that, we want
13648 -- to process the trx
13649 -- before moving on to the next period.
13650 if (t_transaction_date_entered(i+1) > l_period_rec.calendar_period_close_date) and
13651 (t_transaction_date_entered(i+1) > l_end_date) then
13652
13653 if not GetPeriodInfo(to_number(to_char(t_transaction_date_entered(i+1), 'J')),
13654 p_asset_hdr_rec.book_type_code,
13655 p_mrc_sob_type_code,
13656 l_next_period_rec) then
13657 if (p_log_level_rec.statement_level) then
13658 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13659 'GetPeriodInfo'
13660 ,p_log_level_rec => p_log_level_rec);
13661 end if;
13662
13663 raise calc_failed;
13664 end if;
13665
13666 else
13667 l_next_period_rec := l_period_rec;
13668 end if; -- (t_transaction_date_entered(i+1) > l_period_rec.calendar_period_close_date)
13669
13670 --tk_util.DumpPerRec(l_next_period_rec, to_char(i));
13671
13672 end if; -- (i < t_transaction_header_id.COUNT)
13673
13674 if (p_log_level_rec.statement_level) then
13675 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 8.0 : Checking whether to run Deprn ==========','', p_log_level_rec);
13676 fa_debug_pkg.add(l_calling_fn, '++ i', i, p_log_level_rec);
13677 fa_debug_pkg.add(l_calling_fn, '++ l_period_rec.period_counter', l_period_rec.period_counter, p_log_level_rec);
13678 fa_debug_pkg.add(l_calling_fn, '++ l_next_period_rec.period_counter', l_next_period_rec.period_counter, p_log_level_rec);
13679 fa_debug_pkg.add(l_calling_fn, '++ l_next_trx_trx_date_entered', to_char(l_next_trx_trx_date_entered,'MM/DD/YYYY'), p_log_level_rec);
13680 fa_debug_pkg.add(l_calling_fn, '++ l_limit', l_limit, p_log_level_rec);
13681 end if;
13682
13683
13684 if ((i < t_transaction_header_id.COUNT) and
13685 (l_period_rec.period_counter < l_next_period_rec.period_counter)) or
13686 ((i = t_transaction_header_id.COUNT) and
13687 (i < l_limit) and
13688 (l_period_rec.period_counter < p_period_rec.period_counter)) or
13689 (i = l_limit) then
13690 --
13691 -- Find out from db that next transaction is in the same period or not.
13692 --
13693 if (i = l_limit) then
13694 OPEN c_get_next_ths (t_transaction_date_entered(i), t_date_effective(i));
13695 FETCH c_get_next_ths INTO l_next_trx_trx_date_entered,
13696 l_next_trx_date_effective;
13697 CLOSE c_get_next_ths;
13698
13699 if (l_next_trx_trx_date_entered is not null) then
13700 if not GetPeriodInfo(to_number(to_char(l_next_trx_trx_date_entered, 'J')),
13701 p_asset_hdr_rec.book_type_code,
13702 p_mrc_sob_type_code,
13703 l_next_period_rec) then
13704 if (p_log_level_rec.statement_level) then
13705 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13706 'GetPeriodInfo'
13707 ,p_log_level_rec => p_log_level_rec);
13708 end if;
13709
13710 raise calc_failed;
13711 end if;
13712 end if;
13713
13714 if (p_log_level_rec.statement_level) then
13715 fa_debug_pkg.add(l_calling_fn, 'Fetched next transaction information ', l_limit
13716 ,p_log_level_rec => p_log_level_rec);
13717 end if;
13718
13719 end if; -- (i = l_limit)
13720
13721 --
13722 -- If there is no subsequent transaction or next transaction
13723 -- is in different period, complete runnning depreciation to close
13724 -- previous period or perivious period of the period that next transaction
13725 -- exists.
13726 --
13727 -- Bug3548724: Added l_is_this_void. Skip faxcde call if current trx is void.
13731 if (p_trans_rec.transaction_type_code like '%RETIREMENT') then
13728 --
13729
13730 -- Fix for Bug #6190904.
13732
13733 -- Bug 5726160
13734 declare
13735 cursor c_depreciate_flag is
13736 select bk.depreciate_flag
13737 from fa_books bk
13738 ,fa_deprn_periods dp
13739 where bk.asset_id = p_asset_hdr_rec.asset_id
13740 and bk.book_type_code = p_asset_hdr_rec.book_type_code
13741 and bk.date_effective <= nvl(dp.period_close_date, sysdate)
13742 and dp.book_type_code = p_asset_hdr_rec.book_type_code
13743 and dp.period_counter = l_period_rec.period_counter
13744 order by bk.date_effective desc;
13745 begin
13746 open c_depreciate_flag;
13747 fetch c_depreciate_flag into l_depreciate_flag;
13748 if (c_depreciate_flag%notfound) then
13749 if (l_asset_fin_rec_new.depreciate_flag = 'YES') then
13750 l_depreciate_flag := 'YES';
13751 else
13752 l_depreciate_flag := 'NO';
13753 end if;
13754 end if;
13755 close c_depreciate_flag;
13756 exception when others then null;
13757 end;
13758 else
13759 l_depreciate_flag := l_asset_fin_rec_new.depreciate_flag;
13760 end if;
13761
13762 if (p_log_level_rec.statement_level) then
13763 fa_debug_pkg.add(l_calling_fn, '========== Recalc Step 8.5 :Checking whether to run Deprn ==========','', p_log_level_rec);
13764 fa_debug_pkg.add(l_calling_fn, '++ l_next_trx_trx_date_entered', to_char(l_next_trx_trx_date_entered,'MM/DD/YYYY'), p_log_level_rec);
13765 fa_debug_pkg.add(l_calling_fn, '++ l_next_period_rec.period_counter', l_next_period_rec.period_counter, p_log_level_rec);
13766 fa_debug_pkg.add(l_calling_fn, '++ l_period_rec.period_counter', l_period_rec.period_counter, p_log_level_rec);
13767 end if;
13768
13769 if (l_next_trx_trx_date_entered is null or
13770 l_next_period_rec.period_counter > l_period_rec.period_counter) and
13771 (not(l_is_this_void))
13772 and (not(l_energy_member))
13773 -- and (l_depreciate_flag='YES') -- Bug 5726160
13774 -- Bug6190904 for case5: Need to replace a line above
13775 and (px_asset_fin_rec_new.depreciate_flag = 'YES')
13776 then
13777
13778 l_dpr_in.y_begin := l_period_rec.fiscal_year;
13779 l_dpr_in.p_cl_begin := l_period_rec.period_num;
13780
13781 if (p_log_level_rec.statement_level) then
13782 fa_debug_pkg.add(l_calling_fn, 'Depreciation starts from period of ', l_dpr_in.p_cl_begin
13783 ,p_log_level_rec => p_log_level_rec);
13784 fa_debug_pkg.add(l_calling_fn, 'and year of ', l_dpr_in.y_begin
13785 ,p_log_level_rec => p_log_level_rec);
13786 end if;
13787
13788 if (i < t_transaction_header_id.COUNT) or (i = l_limit) then
13789 if (p_log_level_rec.statement_level) then
13790 fa_debug_pkg.add(l_calling_fn, 'Depreciate until ', 'Next Transaction'
13791 ,p_log_level_rec => p_log_level_rec);
13792 end if;
13793 --
13794 -- Find how many periods to depreciate until next transaction headers
13795 -- Set FA_STD_TYPES.dpr_struct for depreciation(faxcde) call.
13796 --
13797 if (nvl(l_next_period_rec.period_counter, p_period_rec.period_counter) = 1) then
13798 l_dpr_in.y_end := nvl(l_next_period_rec.fiscal_year, p_period_rec.fiscal_year) - 1;
13799 l_dpr_in.p_cl_end := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
13800 else
13801 l_dpr_in.y_end := nvl(l_next_period_rec.fiscal_year, p_period_rec.fiscal_year);
13802 l_dpr_in.p_cl_end := nvl(l_next_period_rec.period_num, p_period_rec.period_num) - 1;
13803 end if;
13804
13805 elsif (i = t_transaction_header_id.COUNT) then
13806 if (p_log_level_rec.statement_level) then
13807 fa_debug_pkg.add(l_calling_fn, 'Depreciate until ', 'Current period'
13808 ,p_log_level_rec => p_log_level_rec);
13809 end if;
13810 --
13811 -- This is the last transaction to process. So depreciate
13812 -- until last period.
13813 --
13814 if (p_period_rec.period_num = 1) then
13815 l_dpr_in.y_end := p_period_rec.fiscal_year - 1;
13816 l_dpr_in.p_cl_end := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
13817 else
13818 l_dpr_in.y_end := p_period_rec.fiscal_year;
13819 l_dpr_in.p_cl_end := p_period_rec.period_num - 1;
13820 end if;
13821
13822 end if; -- (i < t_transaction_header_id.COUNT) or (i = l_limit)
13823
13824 if (p_log_level_rec.statement_level) then
13828 ,p_log_level_rec => p_log_level_rec);
13825 fa_debug_pkg.add(l_calling_fn, 'Depreciation will end at period of ', l_dpr_in.p_cl_end
13826 ,p_log_level_rec => p_log_level_rec);
13827 fa_debug_pkg.add(l_calling_fn, 'and year of ', l_dpr_in.y_end
13829 end if;
13830
13831 if (l_period_rec.period_num <> 1) then
13832 l_dpr_in.deprn_rounding_flag := 'ADJ';
13833 end if;
13834
13835 l_dpr_in.prior_fy_exp := l_asset_deprn_rec.prior_fy_expense;
13836 l_dpr_in.ytd_deprn := l_asset_deprn_rec.ytd_deprn;
13837 l_dpr_in.deprn_rsv := l_asset_deprn_rec.deprn_reserve;
13838 l_dpr_in.adj_cost := l_asset_fin_rec_new.adjusted_cost;
13839 l_dpr_in.eofy_reserve := l_asset_fin_rec_new.eofy_reserve;
13840 l_dpr_in.rate_adj_factor := l_asset_fin_rec_new.rate_adjustment_factor;
13841 l_dpr_in.formula_factor := l_asset_fin_rec_new.formula_factor;
13842 l_dpr_in.super_group_id := l_asset_fin_rec_new.super_group_id;
13843 l_dpr_in.cost := l_asset_fin_rec_new.cost;
13844
13845 -- manual override
13846 if fa_cache_pkg.fa_deprn_override_enabled then
13847 l_dpr_in.update_override_status := TRUE;
13848 end if;
13849
13850 -- Bug fix 5948890
13851 if l_trans_rec.transaction_type_code = G_TRX_TYPE_PAR_RET then
13852 if (p_asset_fin_rec_old.cost is null or p_asset_fin_rec_old.cost = 0) then
13853 l_cost_frac := null;
13854 else
13855 l_cost_frac := l_cost_retired / px_asset_fin_rec_new.cost;
13856 end if;
13857 else
13858 l_cost_frac := null;
13859 end if;
13860
13861 l_dpr_in.cost_frac := l_cost_frac;
13862
13863 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.cost_frac', l_dpr_in.cost_frac);
13864 -- End of bug fix 5948890
13865
13866 if (p_log_level_rec.statement_level) then
13867 fa_debug_pkg.add(l_calling_fn, '========== Recalc Before Calling faxcde 2 ==========','', p_log_level_rec);
13868 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.cost',l_dpr_in.cost, p_log_level_rec);
13869 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.adj_cost',l_dpr_in.adj_cost, p_log_level_rec);
13870 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.rate_adj_factor',l_dpr_in.rate_adj_factor, p_log_level_rec);
13871 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.prior_fy_exp',l_dpr_in.prior_fy_exp, p_log_level_rec);
13872 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.eofy_reserve',l_dpr_in.eofy_reserve, p_log_level_rec);
13873 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_in.deprn_rsv',l_dpr_in.deprn_rsv, p_log_level_rec);
13874 end if;
13875
13876 --
13877 -- +++++ faxcde will not be called if adjusted_cost is 0.
13878 --
13879 if not FA_CDE_PKG.faxcde(l_dpr_in,
13880 l_dpr_arr,
13881 l_dpr_out,
13882 l_running_mode
13883 ,p_log_level_rec => p_log_level_rec) then
13884 if (p_log_level_rec.statement_level) then
13885 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13886 'FA_CDE_PKG.faxcde'
13887 ,p_log_level_rec => p_log_level_rec);
13888 end if;
13889
13890 raise calc_failed;
13891 end if;
13892
13893 if (p_log_level_rec.statement_level) then
13894 fa_debug_pkg.add(l_calling_fn, '========== Recalc After Calling faxcde 2 ==========','', p_log_level_rec);
13895 fa_debug_pkg.add(l_calling_fn, '++ Depreciation started from YEAR : PERIOD ', l_dpr_in.y_begin ||' : '|| l_dpr_in.p_cl_begin, p_log_level_rec);
13896 fa_debug_pkg.add(l_calling_fn, '++ Depreciation ended at YEAR : PERIOD ', l_dpr_in.y_end ||' : '|| l_dpr_in.p_cl_end, p_log_level_rec);
13897 fa_debug_pkg.add(l_calling_fn, '++ l_dpr_out.new_adj_cost', l_dpr_out.new_adj_cost, p_log_level_rec);
13898 fa_debug_pkg.add(l_calling_fn, 'l_dpr_out.new_ytd_deprn', l_dpr_out.new_ytd_deprn, p_log_level_rec);
13899 fa_debug_pkg.add(l_calling_fn, 'l_dpr_out.new_deprn_rsv', l_dpr_out.new_deprn_rsv, p_log_level_rec);
13900 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_cost',l_asset_fin_rec_new.adjusted_cost, p_log_level_rec);
13901 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_recoverable_cost',l_asset_fin_rec_new.adjusted_recoverable_cost, p_log_level_rec);
13902 end if;
13903
13904
13905 -- manual override
13906 if fa_cache_pkg.fa_deprn_override_enabled then
13907 p_trans_rec.deprn_override_flag := l_dpr_out.deprn_override_flag;
13908 end if;
13909
13910 if (l_asset_fin_rec_new.adjusted_cost <> 0)or
13911 --bug fix 4731687 added for the case when due to deprn limit adj_rec_cost is <>0 and adj_cost is 0
13912 (l_asset_fin_rec_new.adjusted_recoverable_cost <> 0) then
13913 l_asset_fin_rec_new.reval_amortization_basis := l_dpr_out.new_reval_amo_basis;
13914 l_asset_deprn_rec.deprn_reserve := l_dpr_out.new_deprn_rsv;
13918 -- l_asset_fin_rec_new.adjusted_capacity := l_dpr_out.new_adj_capacity;
13915 l_asset_deprn_rec.ytd_deprn := l_dpr_out.new_ytd_deprn;
13916 l_asset_deprn_rec.reval_deprn_reserve := l_dpr_out.new_reval_rsv;
13917 -- bug 5336669
13919 --
13920 l_asset_deprn_rec.ltd_production := l_dpr_out.new_ltd_prod;
13921 l_asset_fin_rec_new.eofy_reserve := l_dpr_out.new_eofy_reserve;
13922
13923 l_asset_deprn_rec.prior_fy_expense := l_dpr_out.new_prior_fy_exp;
13924 l_asset_deprn_rec.bonus_deprn_amount := l_dpr_out.bonus_deprn_exp;
13925 l_asset_deprn_rec.bonus_deprn_reserve := l_dpr_out.new_bonus_deprn_rsv;
13926 l_asset_deprn_rec.prior_fy_bonus_expense := l_dpr_out.new_prior_fy_bonus_exp;
13927 end if;
13928
13929 --++++++ Put adjusted cost back ++++++
13930 l_asset_fin_rec_new.adjusted_cost := l_dpr_out.new_adj_cost;
13931 l_asset_fin_rec_new.adjusted_cost := l_dpr_out.new_adj_cost;
13932
13933 l_out_deprn_exp := l_dpr_out.deprn_exp;
13934 l_out_reval_exp := l_dpr_out.reval_exp;
13935 l_out_reval_amo := l_dpr_out.reval_amo;
13936 l_out_prod := l_dpr_out.prod;
13937 l_out_ann_adj_exp := l_dpr_out.ann_adj_exp;
13938 l_out_ann_adj_reval_exp := l_dpr_out.ann_adj_reval_exp;
13939 l_out_ann_adj_reval_amo := l_dpr_out.ann_adj_reval_amo;
13940 l_out_bonus_rate_used := l_dpr_out.bonus_rate_used;
13941 l_out_full_rsv_flag := l_dpr_out.full_rsv_flag;
13942 l_out_life_comp_flag := l_dpr_out.life_comp_flag;
13943 l_out_deprn_override_flag := l_dpr_out.deprn_override_flag;
13944
13945 l_eop_rec_cost := l_asset_fin_rec_new.recoverable_cost;
13946 l_eop_sal_val := l_asset_fin_rec_new.salvage_value;
13947
13948 --+++++++++ Call member level maintenance for tracking +++++++
13949 if nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' then
13950
13951 if not FA_TRACK_MEMBER_PVT.member_eofy_rsv(p_asset_hdr_rec => p_asset_hdr_rec,
13952 p_dpr_in => l_dpr_in,
13953 p_mrc_sob_type_code => p_mrc_sob_type_code
13954 ,p_log_level_rec => p_log_level_rec) then
13955 if (p_log_level_rec.statement_level) then
13956 fa_debug_pkg.add(l_calling_fn, 'Error calling',
13957 'FA_TRACK_MEMBER_PVT.member_eofy_rsv'
13958 ,p_log_level_rec => p_log_level_rec);
13959 end if;
13960
13961 raise calc_failed;
13962
13963 end if;
13964
13965 end if; -- nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE'
13966
13967 elsif (l_energy_member) then
13968 if (p_log_level_rec.statement_level) then
13969 fa_debug_pkg.add(l_calling_fn, 'This is energy member ',
13970 'No member level deprn calculation'
13971 ,p_log_level_rec => p_log_level_rec);
13972 end if;
13973
13974
13975
13976 else
13977 if (p_log_level_rec.statement_level) then
13978 fa_debug_pkg.add(l_calling_fn, 'There is another transactions to process this period',
13979 'or this is current period'
13980 ,p_log_level_rec => p_log_level_rec);
13981 end if;
13982
13983 end if; -- (l_next_trx_period_counter is null or
13984
13985 end if; -- (not ((i < l_limit) and
13986
13987 if (l_calc_deprn_flag) then
13988 l_asset_fin_rec_new.adjusted_cost := l_temp_adjusted_cost;
13989 end if;
13990
13991 l_process_this_trx := TRUE;
13992
13993
13994 if (p_log_level_rec.statement_level) then
13995 fa_debug_pkg.add(l_calling_fn, '++ calc_catchup:
13996 p_trans_rec.transaction_type_code', p_trans_rec.transaction_type_code);
13997 end if;
13998
13999 -- Bug 5726160
14000 if p_running_mode = fa_std_types.FA_DPR_CATCHUP then
14001
14002 if p_trans_rec.transaction_type_code = 'REINSTATEMENT' then
14003
14004 if l_retirement_thid = l_trans_rec.transaction_header_id then
14005
14006 l_catchup_begin_deprn_rec.deprn_reserve :=
14007 l_asset_deprn_rec.deprn_reserve;
14008 l_catchup_begin_deprn_rec.bonus_deprn_reserve :=
14009 l_asset_deprn_rec.bonus_deprn_reserve;
14010 l_catchup_begin_deprn_rec.impairment_reserve :=
14011 l_asset_deprn_rec.impairment_reserve;
14012
14013 if (p_log_level_rec.statement_level) then
14014 fa_debug_pkg.add(' '||l_calling_fn, 'SETTING
14015 l_catchup_begin_deprn_rec.deprn_reserve (+ +)',
14016 l_catchup_begin_deprn_rec.deprn_reserve);
14017 end if;
14018
14019 end if;
14020
14021 elsif p_trans_rec.transaction_type_code like '%RETIREMENT' then
14022
14023 if (p_log_level_rec.statement_level) then
14024 fa_debug_pkg.add(' '||l_calling_fn, '++ calc_catchup:
14028 end if;
14025 l_trans_rec.transaction_type_code 1...', l_trans_rec.transaction_type_code);
14026 fa_debug_pkg.add(' '||l_calling_fn, '++ calc_catchup:
14027 l_entered_reserve 1...', l_entered_reserve);
14029
14030 if l_trans_rec.transaction_type_code = 'ADDITION' and
14031 l_entered_reserve <> 0 then
14032
14033 -- reset deprn_reserve to the deprn_reserve in fa_deprn_summary
14034 select deprn_reserve
14035 into l_temp_reserve
14036 from fa_deprn_summary ds1
14037 where ds1.asset_id = p_asset_hdr_rec.asset_id
14038 and ds1.book_type_code = p_asset_hdr_rec.book_type_code
14039 and ds1.period_counter =
14040 (select ds2.period_counter + 1
14041 from fa_deprn_summary ds2
14042 where ds2.asset_id = p_asset_hdr_rec.asset_id
14043 and ds2.book_type_code =
14044 p_asset_hdr_rec.book_type_code
14045 and ds2.deprn_source_code = 'BOOKS');
14046
14047 l_asset_deprn_rec.deprn_reserve := l_temp_reserve;
14048
14049 if (p_log_level_rec.statement_level) then
14050 fa_debug_pkg.add(' '||l_calling_fn, '++ RESETTING
14051 l_asset_deprn_rec.deprn_reserve (+ +) ...', l_asset_deprn_rec.deprn_reserve);
14052 end if;
14053
14054 end if;
14055
14056 end if;
14057
14058 end if;
14059
14060 if (p_log_level_rec.statement_level) then
14061 fa_debug_pkg.add(' '||l_calling_fn, 'ytd_deprn', l_asset_deprn_rec.ytd_deprn
14062 ,p_log_level_rec => p_log_level_rec);
14063 fa_debug_pkg.add(' '||l_calling_fn, 'deprn_reserve', l_asset_deprn_rec.deprn_reserve
14064 ,p_log_level_rec => p_log_level_rec);
14065 end if;
14066
14067 END LOOP; -- FOR i IN 1..t_transaction_header_id.COUNT LOOP
14068
14069 EXIT WHEN c_get_ths_adj%NOTFOUND;
14070
14071 END LOOP; -- for transactions
14072
14073 CLOSE c_get_ths_adj;
14074
14075 if (p_log_level_rec.statement_level) then
14076 fa_debug_pkg.add(l_calling_fn, '++ Recalc Step 9 : End of c_get_ths_adj LOOP ------------------------------------------------','', p_log_level_rec);
14077 end if;
14078
14079 if (p_log_level_rec.statement_level) then
14080 fa_debug_pkg.add(l_calling_fn, '+++++++++++ Recalc Step 9 : BEFORE calling CALL_DEPRN_BASIS ++++++++++','', p_log_level_rec);
14081 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.cost',l_asset_fin_rec_new.cost, p_log_level_rec);
14082 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.adjusted_cost',l_asset_fin_rec_new.adjusted_cost, p_log_level_rec);
14083 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.rate_adjustment_factor',l_asset_fin_rec_new.rate_adjustment_factor, p_log_level_rec);
14084 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.formula_factor',l_asset_fin_rec_new.formula_factor, p_log_level_rec);
14085 end if;
14086
14087 -- Call Depreciable Basis Rule for Formula/NBV Basis
14088 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
14089 (p_event_type => 'AMORT_ADJ3',
14090 p_asset_fin_rec_new => l_asset_fin_rec_new,
14091 p_asset_fin_rec_old => l_asset_fin_rec_new,
14092 p_asset_hdr_rec => p_asset_hdr_rec,
14093 p_asset_type_rec => p_asset_type_rec,
14094 p_asset_deprn_rec => l_asset_deprn_rec,
14095 p_trans_rec => p_trans_rec,
14096 p_period_rec => l_period_rec,
14097 p_adjusted_cost => l_asset_fin_rec_new.adjusted_cost,
14098 p_current_total_rsv => l_asset_deprn_rec.deprn_reserve,
14099 p_current_rsv => l_asset_deprn_rec.deprn_reserve -
14100 l_asset_deprn_rec.bonus_deprn_reserve,
14101 p_current_total_ytd => l_asset_deprn_rec.ytd_deprn,
14102 p_hyp_basis => l_asset_fin_rec_new.adjusted_cost,
14103 p_hyp_total_rsv => l_asset_deprn_rec_raf.deprn_reserve,
14104 p_hyp_rsv => l_asset_deprn_rec_raf.deprn_reserve -
14105 l_asset_deprn_rec_raf.bonus_deprn_reserve,
14106 p_eofy_recoverable_cost => l_eofy_rec_cost,
14107 p_eop_recoverable_cost => l_eop_rec_cost,
14108 p_eofy_salvage_value => l_eofy_sal_val,
14109 p_eop_salvage_value => l_eop_sal_val,
14110 p_mrc_sob_type_code => p_mrc_sob_type_code,
14111 p_used_by_adjustment => 'ADJUSTMENT',
14112 px_new_adjusted_cost => l_asset_fin_rec_new.adjusted_cost,
14113 px_new_raf => l_asset_fin_rec_new.rate_adjustment_factor,
14114 px_new_formula_factor => l_asset_fin_rec_new.formula_factor
14115 ,p_log_level_rec => p_log_level_rec)) then
14116 if (p_log_level_rec.statement_level) then
14117 fa_debug_pkg.add(l_calling_fn, 'Error calling',
14118 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS'
14119 ,p_log_level_rec => p_log_level_rec);
14120 end if;
14121
14122 raise calc_failed;
14126 fa_debug_pkg.add(l_calling_fn, '++ Recalc Step 10 : AFTER calling CALL_DEPRN_BASIS ------------------------------------------------','', p_log_level_rec);
14123 end if; -- (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
14124
14125 if (p_log_level_rec.statement_level) then
14127 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.cost',l_asset_fin_rec_new.cost, p_log_level_rec);
14128 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.adjusted_cost',l_asset_fin_rec_new.adjusted_cost, p_log_level_rec);
14129 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.rate_adjustment_factor',l_asset_fin_rec_new.rate_adjustment_factor, p_log_level_rec);
14130 fa_debug_pkg.add(l_calling_fn, '++ l_asset_fin_rec_new.formula_factor',l_asset_fin_rec_new.formula_factor, p_log_level_rec);
14131 end if;
14132
14133 if (p_log_level_rec.statement_level) then
14134 fa_debug_pkg.add(l_calling_fn, 'Returned values from ',
14135 'FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS AMORT_ADJ3'
14136 ,p_log_level_rec => p_log_level_rec);
14137 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.adjusted_cost',
14138 l_asset_fin_rec_new.adjusted_cost
14139 ,p_log_level_rec => p_log_level_rec);
14140 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.rate_adjustment_factor',
14141 l_asset_fin_rec_new.rate_adjustment_factor
14142 ,p_log_level_rec => p_log_level_rec);
14143 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_new.formula_factor',
14144 l_asset_fin_rec_new.formula_factor
14145 ,p_log_level_rec => p_log_level_rec);
14146 end if;
14147
14148 px_asset_fin_rec_new.cost := l_asset_fin_rec_new.cost;
14149 px_asset_fin_rec_new.recoverable_cost:= l_asset_fin_rec_new.recoverable_cost;
14150 px_asset_fin_rec_new.adjusted_recoverable_cost:= l_asset_fin_rec_new.adjusted_recoverable_cost;
14151 px_asset_fin_rec_new.salvage_value := l_asset_fin_rec_new.salvage_value;
14152 px_asset_fin_rec_new.allowed_deprn_limit_amount := l_asset_fin_rec_new.allowed_deprn_limit_amount;
14153 px_asset_fin_rec_new.percent_salvage_value := l_asset_fin_rec_new.percent_salvage_value;
14154 px_asset_fin_rec_new.allowed_deprn_limit := l_asset_fin_rec_new.allowed_deprn_limit;
14155 px_asset_fin_rec_new.unrevalued_cost := l_asset_fin_rec_new.unrevalued_cost;
14156 px_asset_fin_rec_new.production_capacity := l_asset_fin_rec_new.production_capacity;
14157 px_asset_fin_rec_new.reval_ceiling := l_asset_fin_rec_new.reval_ceiling;
14158 px_asset_fin_rec_new.adjusted_cost := l_asset_fin_rec_new.adjusted_cost;
14159 px_asset_fin_rec_new.rate_adjustment_factor := l_asset_fin_rec_new.rate_adjustment_factor;
14160 px_asset_fin_rec_new.reval_amortization_basis := l_asset_fin_rec_new.reval_amortization_basis;
14161 px_asset_fin_rec_new.adjusted_capacity := l_asset_fin_rec_new.adjusted_capacity;
14162 px_asset_fin_rec_new.formula_factor := l_asset_fin_rec_new.formula_factor;
14163 px_asset_fin_rec_new.eofy_reserve := l_asset_fin_rec_new.eofy_reserve;
14164
14165 --
14166 -- When returning catch up expenses, amounts in p_asset_deprn_rec_adj need to be
14167 -- excluded because it was included at beginning to find correct catchup but
14168 -- these amounts cannot be expensed in this period.
14169 --
14170 -- Bug3548724:if this is addition, there is no need to back out adj reserve
14171 -- because it is reserve from previous period
14172 --
14173
14174 -- Japan Tax phase3 use period_counter_fully_extended for assets which
14175 -- have extended_deprn_flag set.
14176 begin
14177 select decode(nvl(p_asset_fin_rec_old.extended_deprn_flag,'N'),
14178 'Y', p_asset_fin_rec_old.period_counter_fully_extended,
14179 p_asset_fin_rec_old.period_counter_fully_reserved),
14180 decode(nvl(l_asset_fin_rec_new.extended_deprn_flag,'N'),
14181 'Y', l_asset_fin_rec_new.period_counter_fully_extended,
14182 l_asset_fin_rec_new.period_counter_fully_reserved)
14183 into l_old_pc_reserved,
14184 l_new_pc_reserved
14185 from dual;
14186 end;
14187
14188 -- bug 5383699 nvl clause added
14189 if (l_old_pc_reserved is not null
14190 and l_new_pc_reserved is not null) then
14191
14192 -- Fix for Bug #6403182/6415763. If the period you are backdating the
14193 -- retirement to is before the period that the retirement occurs in, then
14194 -- you need to backout some reserve.
14195 if (nvl(l_period_rec.period_counter, 9999999) <= l_old_pc_reserved) then
14196
14197 x_deprn_expense := nvl(l_asset_deprn_rec.deprn_reserve, 0) -
14198 nvl(p_asset_deprn_rec.deprn_reserve, 0);
14199 x_bonus_expense := nvl(l_asset_deprn_rec.bonus_deprn_reserve, 0) -
14200 nvl(p_asset_deprn_rec.bonus_deprn_reserve, 0);
14201 else
14202 -- Bug 5377543
14203 x_deprn_expense := 0;
14204 x_bonus_expense := 0;
14205 end if;
14206
14207 elsif (p_trans_rec.transaction_type_code = 'ADDITION') then
14208 x_deprn_expense := nvl(l_asset_deprn_rec.deprn_reserve, 0) -
14209 nvl(p_asset_deprn_rec.deprn_reserve, 0);
14210 x_bonus_expense := nvl(l_asset_deprn_rec.bonus_deprn_reserve, 0) -
14211 nvl(p_asset_deprn_rec.bonus_deprn_reserve, 0);
14212
14213 elsif (p_trans_rec.transaction_type_code = 'REINSTATEMENT') then
14214 -- Bug 5726160
14218 x_bonus_expense := nvl(l_asset_deprn_rec.bonus_deprn_reserve, 0) -
14215 if p_running_mode = fa_std_types.FA_DPR_CATCHUP then
14216 x_deprn_expense := nvl(l_asset_deprn_rec.deprn_reserve, 0) -
14217 nvl(l_catchup_begin_deprn_rec.deprn_reserve, 0);
14219 nvl(l_catchup_begin_deprn_rec.bonus_deprn_reserve, 0);
14220 else
14221 x_deprn_expense := nvl(l_asset_deprn_rec.deprn_reserve, 0) -
14222 nvl(p_asset_deprn_rec.deprn_reserve, 0);
14223 x_bonus_expense := nvl(l_asset_deprn_rec.bonus_deprn_reserve, 0) -
14224 nvl(p_asset_deprn_rec.bonus_deprn_reserve, 0);
14225 end if;
14226 else
14227 x_deprn_expense := nvl(l_asset_deprn_rec.deprn_reserve, 0) -
14228 nvl(p_asset_deprn_rec.deprn_reserve, 0) -
14229 nvl(p_asset_deprn_rec_adj.deprn_reserve, 0);
14230 x_bonus_expense := nvl(l_asset_deprn_rec.bonus_deprn_reserve, 0) -
14231 nvl(p_asset_deprn_rec.bonus_deprn_reserve, 0) -
14232 nvl(p_asset_deprn_rec_adj.bonus_deprn_reserve, 0);
14233 end if;
14234
14235 --+++++++++ Call member level maintenance for tracking +++++++
14236 if nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' then
14237
14238 if not FA_TRACK_MEMBER_PVT.update_member_books(p_trans_rec=> p_trans_rec,
14239 p_asset_hdr_rec => p_asset_hdr_rec,
14240 p_dpr_in => l_dpr_in,
14241 p_mrc_sob_type_code => p_mrc_sob_type_code
14242 ,p_log_level_rec => p_log_level_rec) then
14243 if (p_log_level_rec.statement_level) then
14244 fa_debug_pkg.add(l_calling_fn, 'Error calling',
14245 'FA_TRACK_MEMBER_PVT.update_member_books'
14246 ,p_log_level_rec => p_log_level_rec);
14247 end if;
14248
14249 raise calc_failed;
14250 end if;
14251
14252 fa_track_member_pvt.p_track_member_eofy_table.delete;
14253
14254 if (p_log_level_rec.statement_level) then
14255 fa_debug_pkg.add(l_calling_fn, 'fa_track_member_pvt.p_track_member_eofy_table',
14256 'deleted'
14257 ,p_log_level_rec => p_log_level_rec);
14258 end if;
14259
14260 end if; -- nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE'
14261
14262 if (p_log_level_rec.statement_level) then
14263 fa_debug_pkg.add(l_calling_fn, 'End',
14264 x_deprn_expense||':'||x_bonus_expense
14265 ,p_log_level_rec => p_log_level_rec);
14266 end if;
14267
14268 return true;
14269
14270 EXCEPTION
14271 WHEN invalid_trx_to_overlap THEN
14272 if (p_log_level_rec.statement_level) then
14273 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'invalid_trx_to_overlap'
14274 ,p_log_level_rec => p_log_level_rec);
14275 end if;
14276
14277 if c_get_ths_adj%ISOPEN then
14278 CLOSE c_get_ths_adj;
14279 end if;
14280
14281 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
14282 name => 'FA_INVALID_TRX_TO_OVERLAP'
14283 ,p_log_level_rec => p_log_level_rec);
14284 return false;
14285 WHEN calc_failed THEN
14286 if (p_log_level_rec.statement_level) then
14287 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'calc_failed'
14288 ,p_log_level_rec => p_log_level_rec);
14289 end if;
14290
14291 if c_get_ths_adj%ISOPEN then
14292 CLOSE c_get_ths_adj;
14293 end if;
14294
14295 fa_srvr_msg.add_message(calling_fn => l_calling_fn
14296 ,p_log_level_rec => p_log_level_rec);
14297 return false;
14298
14299 WHEN OTHERS THEN
14300 if (p_log_level_rec.statement_level) then
14301 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
14302 ,p_log_level_rec => p_log_level_rec);
14303 end if;
14304
14305 if c_check_overlap%ISOPEN then
14306 CLOSE c_check_overlap;
14307 end if;
14308
14309 if c_get_ths_adj%ISOPEN then
14310 CLOSE c_get_ths_adj;
14311 end if;
14312
14313 if c_get_next_ths%ISOPEN then
14314 CLOSE c_get_next_ths;
14315 end if;
14316
14317 if c_get_retirement%ISOPEN then
14318 CLOSE c_get_retirement;
14319 end if;
14320
14321 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
14322 ,p_log_level_rec => p_log_level_rec);
14323 raise;
14324 END Recalculate;
14325
14326 ---------------------------------------------------------------------------
14327
14328 FUNCTION faxama
14329 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
14330 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
14331 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
14332 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
14333 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
14334 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
14335 p_asset_fin_rec_adj IN FA_API_TYPES.asset_fin_rec_type default null,
14336 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
14340 p_mrc_sob_type_code IN VARCHAR2,
14337 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type,
14338 p_asset_deprn_rec_adj IN FA_API_TYPES.asset_deprn_rec_type default null,
14339 p_period_rec IN FA_API_TYPES.period_rec_type,
14341 p_running_mode IN NUMBER,
14342 p_used_by_revaluation IN NUMBER,
14343 p_reclassed_asset_id NUMBER default null,
14344 p_reclass_src_dest VARCHAR2 default null,
14345 p_reclassed_asset_dpis DATE default null,
14346 x_deprn_exp OUT NOCOPY NUMBER,
14347 x_bonus_deprn_exp OUT NOCOPY NUMBER,
14348 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return boolean IS
14349
14350 l_calling_fn varchar2(50) := 'FA_AMORT_PVT.faxama';
14351 l_reval_deprn_rsv_adj number :=0;
14352 l_afn_zero number:=0;
14353
14354 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
14355 l_asset_deprn_rec_new FA_API_TYPES.asset_deprn_rec_type; -- Added to call calc_raf_adj
14356
14357 calc_err EXCEPTION;
14358
14359 /*
14360 err number;
14361
14362 cursor c_get_profiler is
14363 select runid,
14364 run_date,
14365 run_comment
14366 from plsql_profiler_runs;
14367 */
14368
14369 begin <<faxama>>
14370 --tk_util.debug('-');
14371 --tk_util.debug('-');
14372 --tk_util.debug('-');
14373 --tk_util.debug('-');
14374 --tk_util.debug('-');
14375 --tk_util.debug('-+++++-');
14376 if (p_log_level_rec.statement_level) then
14377 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_type_rec.asset_type||':'||p_asset_hdr_rec.asset_id
14378 ,p_log_level_rec => p_log_level_rec);
14379 end if;
14380
14381
14382 -- err:=DBMS_PROFILER.START_PROFILER ('faxama:'||to_char(sysdate,'dd-Mon-YYYY hh:mi:ss'));
14383
14384 X_deprn_exp := 0;
14385 X_bonus_deprn_exp := 0;
14386
14387 if (p_asset_type_rec.asset_type='CIP') then
14388 if (p_log_level_rec.statement_level) then
14389 fa_debug_pkg.add(l_calling_fn, 'Nothing to calculate with CIP asset',' '
14390 ,p_log_level_rec => p_log_level_rec);
14391 fa_debug_pkg.add(l_calling_fn, 'Exiting faxama immediately',
14392 p_asset_type_rec.asset_type||':'||p_asset_hdr_rec.asset_id
14393 ,p_log_level_rec => p_log_level_rec);
14394 end if;
14395 return true;
14396
14397 --FA_SRVR_MSG.ADD_MESSAGE
14398 -- (CALLING_FN => 'FA_AMORT_PKG.faxama',
14399 -- NAME => 'FA_AMT_CIP_NOT_ALLOWED',
14400 -- TOKEN1 => 'TYPE',
14401 -- VALUE1 => 'Amortized');
14402 --return FALSE;
14403 end if;
14404
14405 if (p_log_level_rec.statement_level) then
14406 FA_DEBUG_PKG.ADD
14407 (fname => 'FA_AMORT_PKG.faxama',
14408 element => 'First asset_type',
14409 value => p_asset_type_rec.asset_type
14410 ,p_log_level_rec => p_log_level_rec);
14411 end if;
14412
14413 --
14414 -- Function call faxraf may be removed.
14415 --
14416 -- if (not faxraf
14417 -- (px_trans_rec => px_trans_rec,
14418 -- p_asset_hdr_rec => p_asset_hdr_rec,
14419 -- p_asset_desc_rec => p_asset_desc_rec,
14420 -- p_asset_cat_rec => p_asset_cat_rec,
14421 -- p_asset_type_rec => p_asset_type_rec,
14422 -- p_asset_fin_rec_old => p_asset_fin_rec_old,
14423 -- px_asset_fin_rec_new => px_asset_fin_rec_new,
14424 -- p_asset_deprn_rec => p_asset_deprn_rec,
14425 -- p_period_rec => p_period_rec,
14426 -- px_deprn_exp => x_deprn_exp,
14427 -- px_bonus_deprn_exp => x_bonus_deprn_exp,
14428 -- px_reval_deprn_rsv_adj => l_reval_deprn_rsv_adj,
14429 -- p_mrc_sob_type_code => p_mrc_sob_type_code,
14430 -- p_running_mode => p_running_mode,
14431 -- p_used_by_revaluation => p_used_by_revaluation)) then
14432 -- raise calc_err;
14433 -- end if;
14434
14435 --tk_util.DumpTrxRec(px_trans_rec, 'px_trans_rec');
14436 --tk_util.DumpFinRec(p_asset_fin_rec_old, 'old fin_rec');
14437 --tk_util.DumpFinRec(p_asset_fin_rec_adj, 'adj fin_rec');
14438 --tk_util.DumpFinRec(px_asset_fin_rec_new, 'new_fin_rec');
14439 --tk_util.DumpDeprnRec(p_asset_deprn_rec, 'old deprn');
14440 --tk_util.DumpDeprnRec(p_asset_deprn_rec_adj, 'adj deprn');
14441
14442 -- Bug 6665510: FP: Japan Tax Reform Project
14443 if (px_trans_rec.transaction_type_code = 'REINSTATEMENT') then
14444 --Bug6401301
14445 px_asset_fin_rec_new := p_asset_fin_rec_old;
14446 end if;
14447
14448 --
14449 -- Energy: Need to reinstate member reserve entry cre
14450 if (nvl(p_asset_fin_rec_old.tracking_method, 'NO TRACK') = 'ALLOCATE') and -- ENERGY
14451 (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') and -- ENERGY
14452 (px_trans_rec.transaction_type_code = 'REINSTATEMENT') then -- ENERGY
14453 if (p_log_level_rec.statement_level) then
14454 fa_debug_pkg.add(l_calling_fn, 'calling function ',
14455 'FA_AMORT_PVT.calc_raf_adj_cost'
14456 ,p_log_level_rec => p_log_level_rec);
14457 end if;
14461 -- px_asset_fin_rec_new := p_asset_fin_rec_old;
14458
14459 l_asset_deprn_rec_new := p_asset_deprn_rec;
14460 --Bug6401301 commented this code ass it has already been written before the if condition
14462 px_asset_fin_rec_new.cost := p_asset_fin_rec_old.cost + nvl(p_asset_fin_rec_adj.cost, 0);
14463 px_asset_fin_rec_new.salvage_value := px_asset_fin_rec_new.cost * .1;
14464 px_asset_fin_rec_new.recoverable_cost := px_asset_fin_rec_new.cost - px_asset_fin_rec_new.salvage_value;
14465 px_asset_fin_rec_new.adjusted_recoverable_cost := px_asset_fin_rec_new.recoverable_cost;
14466
14467 if not FA_AMORT_PVT.calc_raf_adj_cost
14468 (p_trans_rec => px_trans_rec,
14469 p_asset_hdr_rec => p_asset_hdr_rec,
14470 p_asset_desc_rec => p_asset_desc_rec,
14471 p_asset_type_rec => p_asset_type_rec,
14472 p_asset_fin_rec_old => p_asset_fin_rec_old,
14473 px_asset_fin_rec_new => px_asset_fin_rec_new,
14474 p_asset_deprn_rec_adj => p_asset_deprn_rec_adj,
14475 p_asset_deprn_rec_new => l_asset_deprn_rec_new,
14476 p_period_rec => p_period_rec,
14477 -- p_group_reclass_options_rec => p_group_reclass_options_rec,
14478 p_mrc_sob_type_code => p_mrc_sob_type_code
14479 ,p_log_level_rec => p_log_level_rec) then
14480 raise calc_err;
14481 end if;
14482 else
14483 populate_fin_rec(
14484 p_trans_rec => px_trans_rec,
14485 p_asset_fin_rec_old => p_asset_fin_rec_old,
14486 p_asset_fin_rec_adj => p_asset_fin_rec_adj,
14487 p_asset_fin_rec_new => px_asset_fin_rec_new,
14488 x_asset_fin_rec_adj => l_asset_fin_rec_adj
14489 ,p_log_level_rec => p_log_level_rec);
14490
14491 if (not Recalculate(
14492 p_trans_rec => px_trans_rec,
14493 p_asset_hdr_rec => p_asset_hdr_rec,
14494 p_asset_type_rec => p_asset_type_rec,
14495 p_asset_desc_rec => p_asset_desc_rec,
14496 p_asset_fin_rec_old => p_asset_fin_rec_old,
14497 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
14498 p_period_rec => p_period_rec,
14499 px_asset_fin_rec_new => px_asset_fin_rec_new,
14500 p_asset_deprn_rec => p_asset_deprn_rec,
14501 p_asset_deprn_rec_adj => p_asset_deprn_rec_adj,
14502 x_deprn_expense => x_deprn_exp,
14503 x_bonus_expense => x_bonus_deprn_exp,
14504 p_running_mode => p_running_mode,
14505 p_used_by_revaluation => p_used_by_revaluation,
14506 p_reclassed_asset_id => p_reclassed_asset_id,
14507 p_reclass_src_dest => p_reclass_src_dest,
14508 p_reclassed_asset_dpis => p_reclassed_asset_dpis,
14509 p_mrc_sob_type_code => p_mrc_sob_type_code,
14510 p_calling_fn => l_calling_fn
14511 ,p_log_level_rec => p_log_level_rec)) then
14512 raise calc_err;
14513 end if;
14514
14515 end if;
14516 --tk_util.DumpFinRec(px_asset_fin_rec_new, 'Nfaxama');
14517
14518 if (p_log_level_rec.statement_level) then
14519 fa_debug_pkg.add(l_calling_fn, 'End', p_asset_type_rec.asset_type||':'||p_asset_hdr_rec.asset_id
14520 ,p_log_level_rec => p_log_level_rec);
14521 end if;
14522 --tk_util.debug('-+++++-');
14523 --tk_util.debug('-');
14524 --tk_util.debug('-');
14525 --tk_util.debug('-');
14526 --tk_util.debug('-');
14527 --tk_util.debug('-');
14528
14529 -- err:=DBMS_PROFILER.STOP_PROFILER;
14530
14531 /*
14532 for r_get_profiler in c_get_profiler loop
14533 null;
14534 --tk_util.debug('runid: '||to_char(r_get_profiler.runid));
14535 --tk_util.debug('run_date: '||to_char(r_get_profiler.run_date, 'DD-MON-YYYY HH24:MI:SS'));
14536 --tk_util.debug('run_comment: '||r_get_profiler.run_comment);
14537 end loop;
14538 */
14539
14540 return TRUE;
14541
14542 exception
14543 when calc_err then
14544 if (p_log_level_rec.statement_level) then
14545 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'calc_err'
14546 ,p_log_level_rec => p_log_level_rec);
14547 end if;
14548
14549 FA_SRVR_MSG.ADD_SQL_ERROR(CALLING_FN => l_calling_fn
14550 ,p_log_level_rec => p_log_level_rec);
14551 return false;
14552
14553 when others then
14554 if (p_log_level_rec.statement_level) then
14555 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION', 'others: '||sqlerrm
14556 ,p_log_level_rec => p_log_level_rec);
14557 end if;
14558
14559 FA_SRVR_MSG.ADD_SQL_ERROR(CALLING_FN => l_calling_fn
14560 ,p_log_level_rec => p_log_level_rec);
14561 return FALSE;
14562 end faxama;
14563
14564 ----------------------------------------------------------------------------
14565
14566 -- backdate amortization enhancement - begin
14567 -- this function will get books row of addition transaction
14568 -- and call faxcde to calculate what the actual reserve is from the
14569 -- prorate period upto right before the amortization period
14570
14574 px_asset_fin_rec in out nocopy FA_API_TYPES.asset_fin_rec_type,
14571 FUNCTION get_reserve(px_trans_rec in out nocopy FA_API_TYPES.trans_rec_type,
14572 p_asset_hdr_rec in FA_API_TYPES.asset_hdr_rec_type,
14573 p_asset_desc_rec in FA_API_TYPES.asset_desc_rec_type,
14575 p_add_txn_id in number,
14576 p_amortize_fy in integer,
14577 p_amortize_per_num in integer,
14578 p_pers_per_yr in integer,
14579 p_mrc_sob_type_code in varchar2,
14580 x_deprn_rsv out nocopy number,
14581 x_bonus_deprn_rsv out nocopy number,
14582 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
14583 return boolean is
14584
14585 l_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
14586 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
14587
14588 l_dpr_row FA_STD_TYPES.dpr_struct;
14589 l_dpr_arr FA_STD_TYPES.dpr_arr_type;
14590 l_dpr_out FA_STD_TYPES.dpr_out_struct;
14591
14592 l_cur_deprn_rsv number;
14593 l_cur_bonus_deprn_rsv number;
14594
14595 dummy_var varchar2(15);
14596 dummy_num number;
14597
14598 begin
14599
14600 l_asset_fin_rec := px_asset_fin_rec;
14601
14602 if p_mrc_sob_type_code = 'R' then
14603 select adjusted_cost,
14604 recoverable_cost,
14605 reval_amortization_basis,
14606 adjusted_rate,
14607 production_capacity,
14608 adjusted_capacity,
14609 adjusted_recoverable_cost,
14610 salvage_value,
14611 deprn_method_code,
14612 life_in_months,
14613 ceiling_name,
14614 bonus_rule,
14615 annual_deprn_rounding_flag,
14616 rate_adjustment_factor,
14617 prorate_date,
14618 deprn_start_date,
14619 date_placed_in_service
14620 into l_asset_fin_rec.adjusted_cost,
14621 l_asset_fin_rec.recoverable_cost,
14622 l_asset_fin_rec.reval_amortization_basis,
14623 l_asset_fin_rec.adjusted_rate,
14624 l_asset_fin_rec.production_capacity,
14625 l_asset_fin_rec.adjusted_capacity,
14626 l_asset_fin_rec.adjusted_recoverable_cost,
14627 l_asset_fin_rec.salvage_value,
14628 l_asset_fin_rec.deprn_method_code,
14629 l_asset_fin_rec.life_in_months,
14630 l_asset_fin_rec.ceiling_name,
14631 l_asset_fin_rec.bonus_rule,
14632 l_asset_fin_rec.annual_deprn_rounding_flag,
14633 l_asset_fin_rec.rate_adjustment_factor,
14634 l_asset_fin_rec.prorate_date,
14635 l_asset_fin_rec.deprn_start_date,
14636 l_asset_fin_rec.date_placed_in_service
14637 from fa_books_mrc_v bk
14638 where bk.book_type_code = p_asset_hdr_rec.book_type_code
14639 and bk.asset_id = p_asset_hdr_rec.asset_id
14640 and bk.transaction_header_id_in = p_add_txn_id;
14641 else
14642 select adjusted_cost,
14643 recoverable_cost,
14644 reval_amortization_basis,
14645 adjusted_rate,
14646 production_capacity,
14647 adjusted_capacity,
14648 adjusted_recoverable_cost,
14649 salvage_value,
14650 deprn_method_code,
14651 life_in_months,
14652 ceiling_name,
14653 bonus_rule,
14654 annual_deprn_rounding_flag,
14655 rate_adjustment_factor,
14656 prorate_date,
14657 deprn_start_date,
14658 date_placed_in_service
14659 into l_asset_fin_rec.adjusted_cost,
14660 l_asset_fin_rec.recoverable_cost,
14661 l_asset_fin_rec.reval_amortization_basis,
14662 l_asset_fin_rec.adjusted_rate,
14663 l_asset_fin_rec.production_capacity,
14664 l_asset_fin_rec.adjusted_capacity,
14665 l_asset_fin_rec.adjusted_recoverable_cost,
14666 l_asset_fin_rec.salvage_value,
14667 l_asset_fin_rec.deprn_method_code,
14668 l_asset_fin_rec.life_in_months,
14669 l_asset_fin_rec.ceiling_name,
14670 l_asset_fin_rec.bonus_rule,
14671 l_asset_fin_rec.annual_deprn_rounding_flag,
14672 l_asset_fin_rec.rate_adjustment_factor,
14673 l_asset_fin_rec.prorate_date,
14674 l_asset_fin_rec.deprn_start_date,
14675 l_asset_fin_rec.date_placed_in_service
14676 from fa_books bk
14677 where bk.book_type_code = p_asset_hdr_rec.book_type_code
14678 and bk.asset_id = p_asset_hdr_rec.asset_id
14679 and bk.transaction_header_id_in = p_add_txn_id;
14680 end if;
14681
14682 if not FA_EXP_PVT.faxbds
14683 (p_asset_hdr_rec => p_asset_hdr_rec,
14684 px_asset_fin_rec_new => l_asset_fin_rec,
14685 p_asset_deprn_rec => l_asset_deprn_rec,
14686 p_asset_desc_rec => p_asset_desc_rec,
14687 X_dpr_ptr => l_dpr_row,
14688 X_deprn_rsv => l_cur_deprn_rsv,
14689 X_bonus_deprn_rsv => l_cur_bonus_deprn_rsv,
14693 fa_srvr_msg.add_message (calling_fn => 'fa_exp_pkg.faxexp'
14690 p_amortized_flag => FALSE,
14691 p_mrc_sob_type_code => p_mrc_sob_type_code
14692 ,p_log_level_rec => p_log_level_rec) then
14694 ,p_log_level_rec => p_log_level_rec);
14695 return (FALSE);
14696 end if;
14697
14698 if (p_amortize_per_num = 1) then
14699 l_dpr_row.y_end := p_amortize_fy - 1;
14700 l_dpr_row.p_cl_end := p_pers_per_yr;
14701 else
14702 l_dpr_row.y_end := p_amortize_fy;
14703 l_dpr_row.p_cl_end := p_amortize_per_num - 1;
14704 end if;
14705
14706 l_dpr_row.bonus_rule := '';
14707 l_dpr_row.reval_rsv := 0;
14708 l_dpr_row.prior_fy_exp := 0;
14709 l_dpr_row.ytd_deprn := 0;
14710 l_dpr_row.mrc_sob_type_code := p_mrc_sob_type_code;
14711
14712 if (not FA_CDE_PKG.faxcde(l_dpr_row,
14713 l_dpr_arr,
14714 l_dpr_out,
14715 FA_STD_TYPES.FA_DPR_NORMAL
14716 ,p_log_level_rec => p_log_level_rec)) then
14717 FA_SRVR_MSG.ADD_MESSAGE
14718 (CALLING_FN=>'faxcde3'
14719 ,p_log_level_rec => p_log_level_rec);
14720 FA_SRVR_MSG.ADD_MESSAGE
14721 (CALLING_FN => 'FA_AMORT_PKG.get_reserve',
14722 NAME=>'FA_AMT_CAL_DP_EXP'
14723 ,p_log_level_rec => p_log_level_rec);
14724 return FALSE;
14725 end if;
14726
14727 px_trans_rec.deprn_override_flag := l_dpr_out.deprn_override_flag;
14728 x_deprn_rsv := l_dpr_out.new_deprn_rsv;
14729 x_bonus_deprn_rsv := l_dpr_out.new_bonus_deprn_rsv;
14730
14731 return TRUE;
14732
14733 exception
14734 when others then
14735 FA_SRVR_MSG.ADD_SQL_ERROR
14736 (CALLING_FN => 'FA_AMORT_PKG.get_reserve'
14737 ,p_log_level_rec => p_log_level_rec);
14738 return FALSE;
14739
14740 end get_reserve;
14741
14742 -- backdate amortization enhancement - end
14743
14744 -------------------------------------------------------------------------------
14745
14746 -- New function: faxnac
14747 -- Alternative flat rate depreciation calculation.
14748 -- If deprn_basis_formula = 'STRICT_FLAT', use the new adjustment method.
14749 -- When using a NBV based flat rate method, adjustment base amount will be
14750 -- the NBV of the beginning of the year, and when using a Cost based flat rate
14751 -- method, adjustment base amount will be the recoverable cost.
14752
14753 FUNCTION faxnac (p_method_code in varchar2,
14754 p_life in number,
14755 p_rec_cost in number,
14756 p_prior_fy_exp in number,
14757 p_deprn_rsv in number,
14758 p_ytd_deprn in number,
14759 px_adj_cost in out nocopy number,
14760 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return boolean is
14761
14762 l_deprn_basis_formula varchar2(30);
14763 l_rate_source_rule varchar2(10);
14764 l_deprn_basis_rule varchar2(4);
14765 l_dummy_bool boolean;
14766 l_dummy_int integer;
14767
14768 begin
14769
14770 if px_adj_cost is null then
14771 fa_srvr_msg.add_message(name => '***ADJ_COST_NULL***',
14772 calling_fn => 'FA_AMORT_PKG.faxnac'
14773 ,p_log_level_rec => p_log_level_rec);
14774 return false;
14775 end if;
14776
14777 if (not fa_cache_pkg.fazccmt(p_method_code,
14778 p_life
14779 ,p_log_level_rec => p_log_level_rec)) then
14780 fa_srvr_msg.add_message(calling_fn => 'FA_AMORT_PKG.faxnac'
14781 ,p_log_level_rec => p_log_level_rec);
14782 return false;
14783 end if;
14784
14785 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule_id;
14786
14787 if l_deprn_basis_formula is null then
14788 return true;
14789 end if;
14790
14791 -- if l_deprn_basis_formula = fa_std_types.FAD_DBF_FLAT then
14792 if l_deprn_basis_formula = 'STRICT_FLAT' then
14793 if (not fa_cache_pkg.fazccmt(p_method_code,
14794 p_life
14795 ,p_log_level_rec => p_log_level_rec)) then
14796 fa_srvr_msg.add_message(calling_fn => 'FA_AMORT_PKG.faxnac'
14797 ,p_log_level_rec => p_log_level_rec);
14798 return false;
14799 end if;
14800
14801 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
14802 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
14803
14804 if l_rate_source_rule = FA_STD_TYPES.FAD_RSR_FLAT and
14805 l_deprn_basis_rule = FA_STD_TYPES.FAD_DBR_COST then
14806 if p_rec_cost is null then
14807 fa_srvr_msg.add_message(calling_fn => 'FA_AMORT_PKG.faxnac'
14808 ,p_log_level_rec => p_log_level_rec);
14809 return false;
14810 end if;
14811 px_adj_cost := p_rec_cost;
14812 elsif l_rate_source_rule = FA_STD_TYPES.FAD_RSR_FLAT and
14813 l_deprn_basis_rule = FA_STD_TYPES.FAD_DBR_NBV then
14814 if p_rec_cost is null or
14815 not ((p_prior_fy_exp is not null) or
14816 (p_deprn_rsv is not null and p_ytd_deprn is not null)) then
14820 end if;
14817 fa_srvr_msg.add_message(calling_fn => 'FA_AMORT_PKG.faxnac'
14818 ,p_log_level_rec => p_log_level_rec);
14819 return false;
14821
14822 if p_prior_fy_exp is null then
14823 px_adj_cost := p_rec_cost - p_deprn_rsv + p_ytd_deprn;
14824 else
14825 px_adj_cost := p_rec_cost - p_prior_fy_exp;
14826 end if;
14827 end if;
14828 end if;
14829 return true;
14830
14831 end faxnac;
14832
14833 FUNCTION faxraf
14834 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
14835 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
14836 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
14837 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
14838 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
14839 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
14840 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
14841 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type,
14842 p_period_rec IN FA_API_TYPES.period_rec_type,
14843 px_deprn_exp IN OUT NOCOPY number,
14844 px_bonus_deprn_exp IN OUT NOCOPY number,
14845 px_reval_deprn_rsv_adj IN out NOCOPY number,
14846 p_mrc_sob_type_code IN VARCHAR2,
14847 p_running_mode IN NUMBER,
14848 p_used_by_revaluation IN NUMBER,
14849 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return boolean IS
14850
14851 l_dpr_row FA_STD_TYPES.dpr_struct;
14852 l_dpr_out FA_STD_TYPES.dpr_out_struct;
14853 l_dpr_arr FA_STD_TYPES.dpr_arr_type;
14854 l_add_txn_id number;
14855 l_deprn_basis_rule varchar2(25);
14856 l_rate_source_rule varchar2(25);
14857 l_excl_salvage_val_flag boolean;
14858 l_deprn_last_year_flag boolean;
14859 l_method_id integer;
14860 l_cur_rsv number;
14861 l_cur_bonus_rsv number;
14862 l_cur_ytd number;
14863 l_deprn_rsv number;
14864 l_temp number;
14865 l_err_string varchar2(500);
14866
14867 -- Added for Dated Adjustment
14868 l_fy_name varchar2(45);
14869 l_amortize_per_num integer;
14870 l_amortize_fy integer;
14871 l_start_jdate integer;
14872 l_pers_per_yr integer;
14873 l_amortization_start_jdate integer;
14874 l_cur_fy integer;
14875 l_cur_per_num integer;
14876 l_last_per_ctr integer;
14877 l_amortize_per_ctr integer;
14878 l_adjustment_amount number;
14879 l_rsv_amount number;
14880 l_deprn_summary fa_std_types.fa_deprn_row_struct;
14881 l_dummy_bool boolean; --Used to call QUERY_BALANCES_INT
14882
14883 l_temp_deprn_rsv number; -- reserve at the beginning of fy
14884 l_cur_total_rsv number;
14885
14886 -- Added for bonus rule
14887 l_bonus_rule FA_BONUS_RULES.Bonus_Rule%TYPE;
14888 l_bonus_deprn_rsv number;
14889
14890 -- Manual Override
14891 l_use_override boolean;
14892 l_running_mode number;
14893 l_used_by_revaluation number;
14894
14895 -- Depreciable Basis Rule
14896 l_deprn_used_by_adjustment varchar2(10):= null;
14897
14898 -- multiple backdate amortization enhancement - begin LSON
14899 cursor amort_date_before_add is
14900 select th.transaction_header_id
14901 from fa_transaction_headers th,
14902 fa_deprn_periods dp
14903 where th.book_type_code = p_asset_hdr_rec.book_type_code
14904 and th.asset_id = p_asset_hdr_rec.asset_id
14905 and th.transaction_type_code = 'ADDITION'
14906 and th.book_type_code = dp.book_type_code
14907 and th.date_effective between dp.period_open_date and
14908 nvl(dp.period_close_date,sysdate)
14909 and px_trans_rec.amortization_start_date < dp.calendar_period_open_date;
14910
14911 begin <<faxraf>>
14912
14913 -- override
14914 if p_running_mode = fa_std_types.FA_DPR_PROJECT then
14915 l_running_mode:= fa_std_types.FA_DPR_PROJECT;
14916 else
14917 l_running_mode:= fa_std_types.FA_DPR_NORMAL;
14918 end if;
14919 -- End of Manual Override
14920
14921 if (p_log_level_rec.statement_level) then
14922 FA_DEBUG_PKG.ADD
14923 (fname => 'FA_AMORT_PKG.faxraf',
14924 element => 'method code',
14925 value => px_asset_fin_rec_new.deprn_method_code
14926 ,p_log_level_rec => p_log_level_rec);
14927 FA_DEBUG_PKG.ADD
14928 (fname => 'FA_AMORT_PKG.faxraf',
14929 element => 'life',
14930 value => px_asset_fin_rec_new.life_in_months
14931 ,p_log_level_rec => p_log_level_rec);
14932 end if;
14933
14934 if (not FA_CACHE_PKG.fazccmt
14935 (px_asset_fin_rec_new.deprn_method_code,
14936 px_asset_fin_rec_new.life_in_months
14937 ,p_log_level_rec => p_log_level_rec)) then
14938 FA_SRVR_MSG.ADD_MESSAGE(CALLING_FN => 'FA_AMORT_PKG.faxraf'
14942
14939 ,p_log_level_rec => p_log_level_rec);
14940 return FALSE;
14941 end if;
14943 l_method_id := fa_cache_pkg.fazccmt_record.method_id;
14944 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
14945 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
14946
14947 if fa_cache_pkg.fazccmt_record.exclude_salvage_value_flag = 'YES' then
14948 l_excl_salvage_val_flag := TRUE;
14949 else
14950 l_excl_salvage_val_flag := FALSE;
14951 end if;
14952
14953 if fa_cache_pkg.fazccmt_record.depreciate_lastyear_flag = 'YES' then
14954 l_deprn_last_year_flag := TRUE;
14955 else
14956 l_deprn_last_year_flag := FALSE;
14957 end if;
14958
14959 if (p_log_level_rec.statement_level) then
14960 FA_DEBUG_PKG.ADD
14961 (fname => 'FA_AMORT_PKG.faxraf',
14962 element => 'After fazccmt',
14963 value => 2
14964 ,p_log_level_rec => p_log_level_rec);
14965 end if;
14966
14967 l_err_string := 'FA_AMT_BD_DPR_STRUCT';
14968
14969 if (p_log_level_rec.statement_level)then
14970 FA_DEBUG_PKG.ADD
14971 (fname =>' FA_AMORT_PKG.faxraf',
14972 element => 'deprn_rounding_flag- before faxbds',
14973 value => px_asset_fin_rec_new.annual_deprn_rounding_flag
14974 ,p_log_level_rec => p_log_level_rec);
14975 FA_DEBUG_PKG.ADD
14976 (fname => 'FA_AMORT_PKG.faxraf',
14977 element => 'FA_STD TYPE deprn_rnd- before faxbds',
14978 value => FA_STD_TYPES.FA_DPR_ROUND_ADJ
14979 ,p_log_level_rec => p_log_level_rec);
14980 end if;
14981
14982 if not FA_EXP_PVT.faxbds
14983 (p_asset_hdr_rec => p_asset_hdr_rec,
14984 px_asset_fin_rec_new => px_asset_fin_rec_new,
14985 p_asset_deprn_rec => p_asset_deprn_rec,
14986 p_asset_desc_rec => p_asset_desc_rec,
14987 X_dpr_ptr => l_dpr_row,
14988 X_deprn_rsv => l_cur_rsv,
14989 X_bonus_deprn_rsv => l_cur_bonus_rsv,
14990 p_amortized_flag => TRUE,
14991 p_mrc_sob_type_code => p_mrc_sob_type_code
14992 ,p_log_level_rec => p_log_level_rec) then
14993 fa_srvr_msg.add_message (calling_fn => 'fa_amort_pkg.faxraf'
14994 ,p_log_level_rec => p_log_level_rec);
14995 return (FALSE);
14996 end if;
14997
14998 l_cur_rsv := l_cur_rsv + px_reval_deprn_rsv_adj;
14999 l_cur_ytd := l_dpr_row.ytd_deprn;
15000
15001 -- override
15002 l_dpr_row.used_by_adjustment := TRUE;
15003 l_dpr_row.deprn_override_flag := fa_std_types.FA_NO_OVERRIDE;
15004
15005 -- l_err_string := 'FA_AMT_CAL_DP_EXP';
15006 if (p_log_level_rec.statement_level) then
15007 FA_DEBUG_PKG.ADD
15008 (fname => 'FA_AMORT_PKG.faxraf',
15009 element => 'Before faxcde',
15010 value => 3
15011 ,p_log_level_rec => p_log_level_rec);
15012 FA_DEBUG_PKG.ADD
15013 (fname => 'FA_AMORT_PKG.faxraf',
15014 element => 'l_dpr_row.deprn_rounding_flag ',
15015 value => l_dpr_row.deprn_rounding_flag
15016 ,p_log_level_rec => p_log_level_rec);
15017 end if;
15018
15019 -- Added for Dated Adjustment
15020 if (px_trans_rec.amortization_start_date is not null) then
15021
15022 if not fa_cache_pkg.fazcbc(p_asset_hdr_rec.book_type_code) then
15023 fa_srvr_msg.add_message (calling_fn => 'FA_AMORT_PKG.faxraf'
15024 ,p_log_level_rec => p_log_level_rec);
15025 return (FALSE);
15026 end if;
15027
15028 l_last_per_ctr := fa_cache_pkg.fazcbc_record.last_period_counter;
15029 l_cur_fy := fa_cache_pkg.fazcbc_record.current_fiscal_year;
15030 l_cur_per_num := mod((l_last_per_ctr+1),l_cur_fy);
15031 l_fy_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
15032 l_amortization_start_jdate := to_number(to_char(px_trans_rec.amortization_start_date, 'J')); --BMR
15033
15034 if not fa_cache_pkg.fazccp(
15035 l_dpr_row.calendar_type,
15036 l_fy_name,
15037 l_amortization_start_jdate,
15038 l_amortize_per_num,
15039 l_amortize_fy,
15040 l_start_jdate
15041 ,p_log_level_rec => p_log_level_rec) then
15042 fa_srvr_msg.add_message (calling_fn => 'FA_AMORT_PKG.faxraf'
15043 ,p_log_level_rec => p_log_level_rec);
15044 return (FALSE);
15045 end if;
15046
15047 if (not((l_cur_fy = l_amortize_fy) and
15048 (l_cur_per_num = l_amortize_per_num))) then
15049 if not fa_cache_pkg.fazcct (l_dpr_row.calendar_type) then
15050 fa_srvr_msg.add_message (calling_fn => 'FA_AMORT_PKG.faxraf'
15051 ,p_log_level_rec => p_log_level_rec);
15052 return (FALSE);
15053 end if;
15054
15055 -- if this transaction is not at current period, set ADJUSTMENT mode
15056 -- on Depreciable basis rule
15057 l_deprn_used_by_adjustment := 'ADJUSTMENT';
15058
15059 l_pers_per_yr := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
15060
15061 if (l_amortize_per_num = 1) then
15062 l_dpr_row.y_end := l_amortize_fy - 1;
15063 else
15067 if (l_amortize_per_num = 1) then
15064 l_dpr_row.y_end := l_amortize_fy;
15065 end if;
15066
15068 l_dpr_row.p_cl_end := l_pers_per_yr;
15069 else
15070 l_dpr_row.p_cl_end := l_amortize_per_num - 1;
15071 end if;
15072 end if; --if (not((l_cur_fy = l_amortize_fy) and (l_cur_per_num = l_amortize_per_num)))
15073 end if; --if (px_trans_rec.amortization_start_date is not null)
15074
15075 -- End Added for Dated Adjustment
15076
15077 -- bonus: We need to exclude bonus amounts when calculating raf.
15078 -- proved that bonus_rule is excluded, if exist for asset.
15079 l_bonus_rule := l_dpr_row.bonus_rule;
15080 l_dpr_row.bonus_rule := '';
15081
15082 -- row below may not be needed.
15083 -- l_bonus_deprn_rsv := l_dpr_row.bonus_deprn_rsv;
15084 -- l_dpr_row.deprn_rsv is not used.
15085 -- l_deprn_total_rsv := l_dpr_row.deprn_rsv;
15086 -- l_dpr_row.deprn_rsv := l_dpr_row.deprn_rsv - l_dpr_row.bonus_deprn_rsv;
15087 l_cur_total_rsv := l_cur_rsv;
15088 l_cur_rsv := l_cur_rsv - nvl(l_dpr_row.bonus_deprn_rsv,0);
15089
15090 l_used_by_revaluation:= 0;
15091
15092 if p_used_by_revaluation = 1 then
15093 l_used_by_revaluation:= 1;
15094 end if;
15095
15096 l_use_override := ((l_rate_source_rule = FA_STD_TYPES.FAD_RSR_FORMULA) or
15097 (((l_rate_source_rule = FA_STD_TYPES.FAD_RSR_CALC) or
15098 (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_TABLE)) and
15099 (l_deprn_basis_rule = FA_STD_TYPES.FAD_DBR_COST)));
15100
15101 -- Set Tracking related variables
15102 l_dpr_row.tracking_method := p_asset_fin_rec_old.tracking_method;
15103 l_dpr_row.allocate_to_fully_ret_flag := p_asset_fin_rec_old.allocate_to_fully_ret_flag;
15104 l_dpr_row.allocate_to_fully_rsv_flag := p_asset_fin_rec_old.allocate_to_fully_rsv_flag;
15105 l_dpr_row.excess_allocation_option := p_asset_fin_rec_old.excess_allocation_option;
15106 l_dpr_row.depreciation_option := p_asset_fin_rec_old.depreciation_option;
15107 l_dpr_row.member_rollup_flag := p_asset_fin_rec_old.member_rollup_flag;
15108 l_dpr_row.mrc_sob_type_code := p_mrc_sob_type_code;
15109
15110 if (p_log_level_rec.statement_level) then
15111 FA_DEBUG_PKG.ADD(fname => 'FA_AMORT_PKG.faxraf',
15112 element => 'Before call to faxcde regular case',
15113 value => l_dpr_row.bonus_rule
15114 ,p_log_level_rec => p_log_level_rec);
15115 end if;
15116
15117 if (not FA_CDE_PKG.faxcde
15118 (l_dpr_row,
15119 l_dpr_arr,
15120 l_dpr_out,
15121 FA_STD_TYPES.FA_DPR_NORMAL
15122 ,p_log_level_rec => p_log_level_rec)) then
15123 FA_SRVR_MSG.ADD_MESSAGE
15124 (CALLING_FN => 'FA_AMORT_PKG.faxraf',
15125 NAME=>'FA_AMT_CAL_DP_EXP'
15126 ,p_log_level_rec => p_log_level_rec);
15127 if (p_log_level_rec.statement_level) then
15128 FA_DEBUG_PKG.ADD
15129 (fname => 'FA_AMORT_PKG.faxraf',
15130 element => 'After faxcde',
15131 value => 'False'
15132 ,p_log_level_rec => p_log_level_rec);
15133 FA_DEBUG_PKG.ADD
15134 (fname => 'FA_AMORT_PKG.faxraf',
15135 element => 'l_dpr_out.rate_adj_factor',
15136 value => l_dpr_row.rate_adj_factor
15137 ,p_log_level_rec => p_log_level_rec);
15138 FA_DEBUG_PKG.ADD
15139 (fname => 'FA_AMORT_PKG.faxraf',
15140 element => 'l_dpr_out.adj_capacity',
15141 value => l_dpr_row.adj_capacity
15142 ,p_log_level_rec => p_log_level_rec);
15143 FA_DEBUG_PKG.ADD
15144 (fname => 'FA_AMORT_PKG.faxraf',
15145 element => 'l_dpr_out.capacity',
15146 value => l_dpr_row.capacity
15147 ,p_log_level_rec => p_log_level_rec);
15148 end if;
15149 return FALSE;
15150 end if;
15151
15152 -- Override
15153 fa_std_types.deprn_override_trigger_enabled:= FALSE;
15154 if l_use_override then -- pass deprn_override_flag to faxiat
15155 px_trans_rec.deprn_override_flag:= l_dpr_out.deprn_override_flag;
15156 if (p_log_level_rec.statement_level) then
15157 FA_DEBUG_PKG.ADD(fname=>'FA_AMORT_PKG.faxraf',
15158 element=>'deprn_override_flag1',
15159 value=>l_dpr_out.deprn_override_flag
15160 ,p_log_level_rec => p_log_level_rec);
15161 end if;
15162 else
15163 -- pass fa_no_override to faxiat
15164 px_trans_rec.deprn_override_flag := fa_std_types.FA_NO_OVERRIDE;
15165 -- update the status fa_deprn_override from 'SELECTED' to 'POST'
15166 UPDATE FA_DEPRN_OVERRIDE
15167 SET status = 'POST'
15168 WHERE used_by = 'ADJUSTMENT'
15169 AND status = 'SELECTED'
15170 AND transaction_header_id is null;
15171 end if;
15172
15173 fa_std_types.deprn_override_trigger_enabled:= TRUE;
15174
15175 --
15176 -- In most cases, New Adjusted_Cost = New Net Book Value;
15177 -- New Rate_Adjustment_Factor = New Net Book Value / New Deprn_Reserve
15178 -- New Reval_Amortization_Basis = (dpr) Reval_Reserve
15179
15180 -- bonus between here and next, include bonus amounts.
15184 -- Cost - Regular Reserve (without bonus deprn res) for cost assets
15181 -- bonus: modified according to decision from domain experts:
15182 -- now using Cost - Total Reserve
15183 -- when calculating adjusted_cost for nbv assets and
15185
15186 -- new_raval_amo_basis and Production rate source rule are
15187 -- not calculated on Depreciable Basis Formula
15188
15189 px_asset_fin_rec_new.reval_amortization_basis := l_dpr_row.reval_rsv;
15190
15191 if (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_PROD) then
15192 px_asset_fin_rec_new.rate_adjustment_factor := 1;
15193 px_asset_fin_rec_new.adjusted_capacity
15194 := px_asset_fin_rec_new.production_capacity -
15195 l_dpr_out.new_ltd_prod;
15196 px_asset_fin_rec_new.formula_factor := 1;
15197 end if;
15198
15199 ----------------------------------------------
15200 -- Call Depreciable Basis Rule
15201 -- for Amortized Adjustment of current period
15202 ----------------------------------------------
15203 if (not l_rate_source_rule = FA_STD_TYPES.FAD_RSR_CALC) then
15204 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS (
15205 p_event_type => 'AMORT_ADJ',
15206 p_asset_fin_rec_new => px_asset_fin_rec_new,
15207 p_asset_fin_rec_old => p_asset_fin_rec_old,
15208 p_asset_hdr_rec => p_asset_hdr_rec,
15209 p_asset_type_rec => p_asset_type_rec,
15210 p_asset_deprn_rec => p_asset_deprn_rec,
15211 p_trans_rec => px_trans_rec,
15212 p_period_rec => p_period_rec,
15213 p_current_total_rsv => l_cur_total_rsv,
15214 p_current_rsv => l_cur_rsv,
15215 p_current_total_ytd => l_cur_ytd,
15216 p_hyp_basis => l_dpr_out.new_adj_cost,
15217 p_hyp_total_rsv => l_dpr_out.new_deprn_rsv,
15218 p_hyp_rsv => l_dpr_out.new_deprn_rsv -
15219 l_dpr_out.new_bonus_deprn_rsv,
15220 p_mrc_sob_type_code => p_mrc_sob_type_code,
15221 p_used_by_adjustment => l_deprn_used_by_adjustment,
15222 px_new_adjusted_cost => px_asset_fin_rec_new.adjusted_cost,
15223 px_new_raf => px_asset_fin_rec_new.rate_adjustment_factor,
15224 px_new_formula_factor => px_asset_fin_rec_new.formula_factor
15225 ,p_log_level_rec => p_log_level_rec)) then
15226
15227 FA_SRVR_MSG.ADD_MESSAGE
15228 (CALLING_FN=>'CALL_DEPRN_BASIS'
15229 ,p_log_level_rec => p_log_level_rec);
15230 FA_SRVR_MSG.ADD_MESSAGE
15231 (CALLING_FN=>'FA_AMORT_PKG.faxraf',
15232 NAME=>'FA_AMT_CAL_DP_EXP'
15233 ,p_log_level_rec => p_log_level_rec);
15234 return false;
15235
15236 end if;
15237 else
15238 px_asset_fin_rec_new.adjusted_cost :=
15239 px_asset_fin_rec_new.recoverable_cost - l_cur_rsv;
15240 if (sign(px_asset_fin_rec_new.recoverable_cost)<>0)
15241 then
15242 l_temp := px_asset_fin_rec_new.recoverable_cost -
15243 l_dpr_out.new_deprn_rsv;
15244 px_asset_fin_rec_new.rate_adjustment_factor :=
15245 l_temp / px_asset_fin_rec_new.recoverable_cost;
15246 px_asset_fin_rec_new.formula_factor := 1;
15247 else
15248 px_asset_fin_rec_new.rate_adjustment_factor :=1;
15249 px_asset_fin_rec_new.formula_factor := 1;
15250 end if;
15251 end if;
15252
15253
15254 -- bonus: assigning bonus rule value back.
15255 l_dpr_row.bonus_rule := l_bonus_rule;
15256 -- not yet needed.
15257 -- l_deprn_row.bonus_deprn_rsv := l_bonus_deprn_rsv;
15258 -- l_dpr_row.deprn_rsv is not used.
15259 -- l_dpr_row.deprn_rsv := l_deprn_total_rsv;
15260
15261 l_cur_rsv := l_cur_total_rsv;
15262
15263 if (px_asset_fin_rec_new.rate_adjustment_factor < 0 OR
15264 px_asset_fin_rec_new.rate_adjustment_factor > 1)then
15265 FA_SRVR_MSG.ADD_MESSAGE
15266 (CALLING_FN => 'FA_AMORT_PKG.faxraf',
15267 NAME=>'FA_AMT_RAF_OUT_OF_RANGE'
15268 ,p_log_level_rec => p_log_level_rec);
15269 return FALSE;
15270 end if;
15271
15272 -- Added for Dated Adjustment
15273 px_deprn_exp := 0;
15274
15275 if (px_trans_rec.amortization_start_date is not null) then
15276 if (not((l_cur_fy = l_amortize_fy) and
15277 (l_cur_per_num = l_amortize_per_num))) then
15278 l_dpr_row.y_begin := l_amortize_fy;
15279 l_dpr_row.p_cl_begin := l_amortize_per_num;
15280
15281 if (l_cur_per_num = 1) then
15282 l_dpr_row.y_end := l_cur_fy - 1;
15283 else
15284 l_dpr_row.y_end := l_cur_fy;
15285 end if;
15286
15287 if (l_cur_per_num = 1) then
15288 l_dpr_row.p_cl_end := l_pers_per_yr;
15289 else
15290 l_dpr_row.p_cl_end := l_cur_per_num - 1;
15291 end if;
15292
15293 l_dpr_row.rate_adj_factor := px_asset_fin_rec_new.rate_adjustment_factor;
15294
15295 if (l_cur_fy = l_amortize_fy) then
15296 l_amortize_per_ctr := (l_last_per_ctr + 1) -
15297 (l_cur_per_num - l_amortize_per_num);
15301 (l_pers_per_yr - l_amortize_per_num + l_cur_per_num));
15298 else
15299 l_amortize_per_ctr := (l_last_per_ctr + 1) -
15300 ((l_cur_fy - l_amortize_fy -1) * l_pers_per_yr +
15302 end if;
15303
15304 l_deprn_summary.asset_id := p_asset_hdr_rec.asset_id;
15305 l_deprn_summary.book := p_asset_hdr_rec.book_type_code;
15306 l_deprn_summary.period_ctr := l_amortize_per_ctr - 1;
15307 l_deprn_summary.dist_id := 0;
15308
15309 -- Enhancement for BT. YYOON - Start
15310 -- BUG#1148053: Ability to add assets with reserve
15311 -- and amortize over remaining useful life
15312
15313 if (p_asset_hdr_rec.period_of_addition = 'Y') then
15314 -- bonus added.
15315 if p_mrc_sob_type_code = 'R' then
15316 select deprn_reserve,
15317 bonus_deprn_reserve,
15318 ytd_deprn
15319 into l_deprn_summary.deprn_rsv,
15320 l_deprn_summary.bonus_deprn_rsv,
15321 l_deprn_summary.ytd_deprn
15322 from fa_deprn_summary_mrc_v
15323 where asset_id = p_asset_hdr_rec.asset_id
15324 and book_type_code = p_asset_hdr_rec.book_type_code
15325 and deprn_source_code = 'BOOKS';
15326 else
15327 select deprn_reserve,
15328 bonus_deprn_reserve,
15329 ytd_deprn
15330 into l_deprn_summary.deprn_rsv,
15331 l_deprn_summary.bonus_deprn_rsv,
15332 l_deprn_summary.ytd_deprn
15333 from fa_deprn_summary
15334 where asset_id = p_asset_hdr_rec.asset_id
15335 and book_type_code = p_asset_hdr_rec.book_type_code
15336 and deprn_source_code = 'BOOKS';
15337 end if;
15338 else
15339 -- backdate amortization enhancement - begin
15340 l_add_txn_id := 0;
15341 if px_trans_rec.amortization_start_date is not null then
15342 open amort_date_before_add;
15343 fetch amort_date_before_add
15344 into l_add_txn_id;
15345 close amort_date_before_add;
15346
15347 -- when amortization start date is before the addition date
15348 -- call get_reserve to get the actual reserve from the prorate period to before the
15349 -- amortization period
15350 if (l_add_txn_id > 0) then
15351 if not (get_reserve
15352 (px_trans_rec,
15353 p_asset_hdr_rec,
15354 p_asset_desc_rec,
15355 px_asset_fin_rec_new,
15356 l_add_txn_id,
15357 l_amortize_fy,
15358 l_amortize_per_num,
15359 l_pers_per_yr,
15360 p_mrc_sob_type_code,
15361 l_deprn_rsv,
15362 l_bonus_deprn_rsv
15363 ,p_log_level_rec => p_log_level_rec)) then
15364 fa_srvr_msg.add_message (calling_fn => 'FA_AMORT_PKG.faxraf'
15365 ,p_log_level_rec => p_log_level_rec);
15366 return FALSE;
15367 end if;
15368 l_deprn_summary.deprn_rsv := l_deprn_rsv;
15369 l_deprn_summary.bonus_deprn_rsv := l_bonus_deprn_rsv;
15370 end if;
15371 end if;
15372
15373 if (px_trans_rec.amortization_start_date is null or l_add_txn_id = 0) then
15374 -- backdate amortization enhacement - end
15375 FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT (
15376 l_deprn_summary,
15377 'STANDARD',
15378 FALSE,
15379 l_dummy_bool,
15380 'FA_AMORT_PKG.faxraf',
15381 -1
15382 ,p_log_level_rec => p_log_level_rec);
15383
15384 if not (l_dummy_bool) then
15385 fa_srvr_msg.add_message (calling_fn => 'FA_AMORT_PKG.faxraf'
15386 ,p_log_level_rec => p_log_level_rec);
15387 return (FALSE);
15388 end if;
15389 end if;
15390 end if;
15391
15392 /**** Enhancement for BT. YYOON - End */
15393
15394 if p_mrc_sob_type_code = 'R' then
15395 SELECT NVL(SUM(DECODE(ADJUSTMENT_TYPE,
15396 'EXPENSE',
15397 DECODE(DEBIT_CREDIT_FLAG,
15398 'DR', ADJUSTMENT_AMOUNT,
15399 'CR', -1 * ADJUSTMENT_AMOUNT))),0),
15400 -- backdate amortization enhancement - begin
15401 NVL(SUM(DECODE(ADJUSTMENT_TYPE,
15402 'RESERVE',
15403 DECODE(DEBIT_CREDIT_FLAG,
15404 'DR', ADJUSTMENT_AMOUNT,
15405 'CR', -1 * ADJUSTMENT_AMOUNT))),0)
15406 -- backdate amortization enhancement - end
15407 INTO l_adjustment_amount,
15411 AND book_type_code = p_asset_hdr_rec.book_type_code
15408 l_rsv_amount
15409 FROM FA_ADJUSTMENTS_MRC_V
15410 WHERE asset_id = p_asset_hdr_rec.asset_id
15412 AND period_counter_adjusted = l_amortize_per_ctr;
15413 else
15414 SELECT NVL(SUM(DECODE(ADJUSTMENT_TYPE,
15415 'EXPENSE',
15416 DECODE(DEBIT_CREDIT_FLAG,
15417 'DR', ADJUSTMENT_AMOUNT,
15418 'CR', -1 * ADJUSTMENT_AMOUNT))),0),
15419 -- backdate amortization enhancement - begin
15420 NVL(SUM(DECODE(ADJUSTMENT_TYPE,
15421 'RESERVE',
15422 DECODE(DEBIT_CREDIT_FLAG,
15423 'DR', ADJUSTMENT_AMOUNT,
15424 'CR', -1 * ADJUSTMENT_AMOUNT))),0)
15425 -- backdate amortization enhancement - end
15426 INTO l_adjustment_amount,
15427 l_rsv_amount
15428 FROM FA_ADJUSTMENTS
15429 WHERE asset_id = p_asset_hdr_rec.asset_id
15430 AND book_type_code = p_asset_hdr_rec.book_type_code
15431 AND period_counter_adjusted = l_amortize_per_ctr;
15432 end if;
15433
15434 l_temp_deprn_rsv := l_deprn_summary.deprn_rsv - l_deprn_summary.bonus_deprn_rsv;
15435
15436 -- bonus
15437 l_deprn_summary.deprn_rsv := l_deprn_summary.deprn_rsv +
15438 l_adjustment_amount -
15439 l_rsv_amount;
15440
15441 -- alternative flat rate depreciation calculation
15442 if l_amortize_per_num = 1 then
15443 l_deprn_summary.ytd_deprn := l_adjustment_amount;
15444 else
15445 l_deprn_summary.ytd_deprn := l_deprn_summary.ytd_deprn + l_adjustment_amount;
15446 end if;
15447
15448 -- Add for the Depreciable Basis Formula.
15449
15450 ----------------------------------------------
15451 -- Call Depreciable Basis Rule
15452 -- for Amortized Adjustment with back dated.
15453 -- Before faxcde calling
15454 ----------------------------------------------
15455
15456 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS (
15457 p_event_type => 'AMORT_ADJ2',
15458 p_asset_fin_rec_new => px_asset_fin_rec_new,
15459 p_asset_fin_rec_old => p_asset_fin_rec_old,
15460 p_asset_hdr_rec => p_asset_hdr_rec,
15461 p_asset_type_rec => p_asset_type_rec,
15462 p_asset_deprn_rec => p_asset_deprn_rec,
15463 p_trans_rec => px_trans_rec,
15464 p_period_rec => p_period_rec,
15465 p_adjusted_cost => l_dpr_row.adj_cost,
15466 p_current_total_rsv => l_deprn_summary.deprn_rsv,
15467 p_current_rsv => l_deprn_summary.deprn_rsv -
15468 l_deprn_summary.bonus_deprn_rsv,
15469 p_current_total_ytd => l_deprn_summary.ytd_deprn,
15470 p_hyp_basis => l_dpr_out.new_adj_cost,
15471 p_hyp_total_rsv => l_dpr_out.new_deprn_rsv,
15472 p_hyp_rsv => l_dpr_out.new_deprn_rsv -
15473 l_dpr_out.new_bonus_deprn_rsv,
15474 p_mrc_sob_type_code => p_mrc_sob_type_code,
15475 p_used_by_adjustment => 'ADJUSTMENT',
15476 px_new_adjusted_cost => l_dpr_row.adj_cost,
15477 px_new_raf => px_asset_fin_rec_new.rate_adjustment_factor,
15478 px_new_formula_factor => px_asset_fin_rec_new.formula_factor
15479 ,p_log_level_rec => p_log_level_rec)) then
15480 FA_SRVR_MSG.ADD_MESSAGE
15481 (CALLING_FN=>'CALL_DEPRN_BASIS'
15482 ,p_log_level_rec => p_log_level_rec);
15483 FA_SRVR_MSG.ADD_MESSAGE
15484 (CALLING_FN=>'FA_AMORT_PKG.faxraf',
15485 NAME=>'FA_AMT_CAL_DP_EXP'
15486 ,p_log_level_rec => p_log_level_rec);
15487 return false;
15488
15489 end if;
15490
15491 --fix for 2197401. error out if new nbv result in
15492 -- opposite sign of new recoverable cost
15493 if (sign(px_asset_fin_rec_new.recoverable_cost)<>sign(l_dpr_row.adj_cost)) then
15494 FA_SRVR_MSG.ADD_MESSAGE
15495 (CALLING_FN => 'FA_AMORT_PKG.faxraf',
15496 NAME=>'FA_WRONG_REC_COST'
15497 ,p_log_level_rec => p_log_level_rec);
15498 return FALSE;
15499 end if;
15500
15501 l_dpr_row.deprn_rsv := l_deprn_summary.deprn_rsv;
15502 l_dpr_row.adj_capacity := px_asset_fin_rec_new.adjusted_capacity;
15503
15504 -- Bonus: called when amortization_start_date is not null i.e. backdated
15505 -- adjustment.
15506 -- We probably need to modify to exclude bonus amounts.
15507 l_bonus_rule := l_dpr_row.bonus_rule;
15508
15509 l_cur_total_rsv := l_cur_rsv;
15513 if (not FA_CDE_PKG.faxcde
15510 l_cur_rsv := l_cur_rsv - nvl(l_dpr_row.bonus_deprn_rsv,0);
15511 l_dpr_row.mrc_sob_type_code := p_mrc_sob_type_code;
15512
15514 (l_dpr_row,
15515 l_dpr_arr,
15516 l_dpr_out,
15517 FA_STD_TYPES.FA_DPR_NORMAL
15518 ,p_log_level_rec => p_log_level_rec)) then
15519 FA_SRVR_MSG.ADD_MESSAGE
15520 (CALLING_FN=>'faxcde2'
15521 ,p_log_level_rec => p_log_level_rec);
15522 FA_SRVR_MSG.ADD_MESSAGE
15523 (CALLING_FN => 'FA_AMORT_PKG.faxraf',
15524 NAME => 'FA_AMT_CAL_DP_EXP'
15525 ,p_log_level_rec => p_log_level_rec);
15526 return FALSE;
15527 end if;
15528
15529 -- Override
15530 if (p_log_level_rec.statement_level) then
15531 FA_DEBUG_PKG.ADD
15532 (fname => 'FA_AMORT_PKG.faxraf',
15533 element => 'deprn_override_flag2',
15534 value => l_dpr_out.deprn_override_flag
15535 ,p_log_level_rec => p_log_level_rec);
15536 end if;
15537
15538 px_trans_rec.deprn_override_flag:= l_dpr_out.deprn_override_flag;
15539
15540 -- Added for Depreciable Basis Formula.
15541
15542 ----------------------------------------------
15543 -- Call Depreciable Basis Rule
15544 -- for Amortized Adjustment with back dated.
15545 -- After faxcde calling
15546 ----------------------------------------------
15547
15548 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS (
15549 p_event_type => 'AMORT_ADJ3',
15550 p_asset_fin_rec_new => px_asset_fin_rec_new,
15551 p_asset_fin_rec_old => p_asset_fin_rec_old,
15552 p_asset_hdr_rec => p_asset_hdr_rec,
15553 p_asset_type_rec => p_asset_type_rec,
15554 p_asset_deprn_rec => p_asset_deprn_rec,
15555 p_trans_rec => px_trans_rec,
15556 p_period_rec => p_period_rec,
15557 p_adjusted_cost => l_dpr_row.adj_cost,
15558 p_current_rsv => l_temp_deprn_rsv,
15559 p_current_total_ytd => l_deprn_summary.ytd_deprn,
15560 p_hyp_basis => l_dpr_out.new_adj_cost,
15561 p_hyp_total_rsv => l_dpr_out.new_deprn_rsv,
15562 p_hyp_rsv => l_dpr_out.new_deprn_rsv
15563 - l_dpr_out.new_bonus_deprn_rsv,
15564 p_mrc_sob_type_code => p_mrc_sob_type_code,
15565 p_used_by_adjustment => 'ADJUSTMENT',
15566 px_new_adjusted_cost => px_asset_fin_rec_new.adjusted_cost,
15567 px_new_raf => px_asset_fin_rec_new.rate_adjustment_factor,
15568 px_new_formula_factor => px_asset_fin_rec_new.formula_factor
15569 ,p_log_level_rec => p_log_level_rec)) then
15570 FA_SRVR_MSG.ADD_MESSAGE
15571 (CALLING_FN=>'CALL_DEPRN_BASIS'
15572 ,p_log_level_rec => p_log_level_rec);
15573 FA_SRVR_MSG.ADD_MESSAGE
15574 (CALLING_FN=>'FA_AMORT_PKG.faxraf',
15575 NAME=>'FA_AMT_CAL_DP_EXP'
15576 ,p_log_level_rec => p_log_level_rec);
15577 return false;
15578
15579 end if;
15580
15581 -- bonus, added l_dpr_row.bonus_deprn_rsv field to calculation.
15582 px_deprn_exp := (l_dpr_out.new_deprn_rsv - l_deprn_summary.deprn_rsv) -
15583 (l_cur_rsv - l_deprn_summary.deprn_rsv) -
15584 nvl(l_dpr_row.bonus_deprn_rsv,0);
15585
15586 -- bonus
15587 -- l_dpr_row.bonus_deprn_rsv arrives with value added for bonus_deprn_rsv.
15588 -- the new_bonus_deprn_rsv amount is not vanilla therefore the *2.
15589 -- if it turns out to be wrong calculation, it should be investigated
15590 -- why bonus_deprn_rsv doesn't arrive as expected.
15591 if (l_dpr_row.bonus_rule is not null) then
15592 px_bonus_deprn_exp :=
15593 (l_dpr_out.new_bonus_deprn_rsv -
15594 l_deprn_summary.bonus_deprn_rsv) -
15595 ( (l_dpr_row.bonus_deprn_rsv * 2) - l_deprn_summary.bonus_deprn_rsv);
15596
15597 if (p_log_level_rec.statement_level) then
15598 FA_DEBUG_PKG.ADD (fname=>'FA_AMORT_PKG.faxraf',
15599 element=>'px_bonus_deprn_exp ',
15600 value=>px_bonus_deprn_exp
15601 ,p_log_level_rec => p_log_level_rec);
15602 FA_DEBUG_PKG.ADD (fname=>'FA_AMORT_PKG.faxraf',
15603 element=>'l_dpr_out.new_bonus_deprn_rsv ',
15604 value=>l_dpr_out.new_bonus_deprn_rsv
15605 ,p_log_level_rec => p_log_level_rec);
15606 FA_DEBUG_PKG.ADD (fname=>'FA_AMORT_PKG.faxraf',
15607 element=>'l_dpr_row.bonus_deprn_rsv',
15608 value=>l_dpr_row.bonus_deprn_rsv
15609 ,p_log_level_rec => p_log_level_rec);
15613 ,p_log_level_rec => p_log_level_rec);
15610 FA_DEBUG_PKG.ADD (fname=>'FA_AMORT_PKG.faxraf',
15611 element=>'l_dpr_row.bonus_deprn_rsv',
15612 value=>l_deprn_summary.bonus_deprn_rsv
15614 end if;
15615 end if;
15616
15617 -- bonus: assigning bonus rule value back.
15618 l_dpr_row.bonus_rule := l_bonus_rule;
15619 l_cur_rsv := l_cur_total_rsv;
15620
15621 end if; --if (not((l_cur_fy = l_amortize_fy) and (l_cur_per_num = l_amortize_per_num)))
15622 end if; --if (px_trans_rec.amortization_start_date is not null)
15623
15624 return TRUE;
15625
15626 exception
15627 when others then
15628 FA_SRVR_MSG.ADD_SQL_ERROR
15629 (CALLING_FN => 'FA_AMORT_PKG.faxraf'
15630 ,p_log_level_rec => p_log_level_rec);
15631 return FALSE;
15632 end faxraf;
15633
15634 FUNCTION calc_raf_adj_cost
15635 (p_trans_rec IN FA_API_TYPES.trans_rec_type,
15636 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
15637 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
15638 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
15639 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
15640 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
15641 p_asset_deprn_rec_adj IN FA_API_TYPES.asset_deprn_rec_type,
15642 p_asset_deprn_rec_new IN FA_API_TYPES.asset_deprn_rec_type,
15643 p_period_rec IN FA_API_TYPES.period_rec_type,
15644 p_group_reclass_options_rec IN FA_API_TYPES.group_reclass_options_rec_type default null,
15645 p_mrc_sob_type_code IN VARCHAR2,
15646 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
15647
15648
15649 l_calling_fn VARCHAR2(50) := 'fa_amort_pvt.calc_raf_adj_cost';
15650
15651 --+++++++ variables for Eofy Recoverable Cost/Salvage Value +++++++
15652 l_eofy_rec_cost NUMBER;
15653 l_eofy_sal_val NUMBER;
15654
15655 --++++++++ variables for EOP Recoverable Cost/Salvage Value ++++++++
15656 l_eop_rec_cost NUMBER;
15657 l_eop_sal_val NUMBER;
15658
15659 --++++++++ variables for manual override ++++++++
15660 l_rate_source_rule VARCHAR2(25);
15661 l_deprn_basis_rule VARCHAR2(25);
15662
15663 --+++++++++++++++ For calling faxcde +++++++++++++++
15664 l_dpr_in FA_STD_TYPES.dpr_struct;
15665 l_dpr_out FA_STD_TYPES.dpr_out_struct;
15666 l_dpr_arr FA_STD_TYPES.dpr_arr_type;
15667 l_running_mode NUMBER;
15668
15669 l_deprn_reserve NUMBER;
15670 l_temp_integer BINARY_INTEGER;
15671 l_temp_number number;
15672
15673 --+ HHIRAGA added on Oct/Nov in 2003
15674 --++++++++ variables for Trackking Member Feature ++++++++
15675 l_processed_flag BOOLEAN := FALSE;
15676 l_raf_processed_flag BOOLEAN := FALSE;
15677 l_current_period_counter NUMBER;
15678 l_mem_deprn_reserve NUMBER;
15679 l_mem_eofy_reserve NUMBER;
15680
15681 l_recalc_start_fy NUMBER;
15682 l_recalc_start_period_num NUMBER;
15683 l_recalc_start_period_counter NUMBER;
15684 l_no_allocation_for_last VARCHAR2(1);
15685 l_chk_bs_row_exists VARCHAR2(1);
15686
15687 CURSOR c_chk_bs_row_exists IS
15688 select 'Y'
15689 from fa_books_summary
15690 where book_type_code = p_asset_hdr_rec.book_type_code
15691 and group_asset_id = p_asset_hdr_rec.asset_id
15692 and asset_id <> group_asset_id
15693 and period_counter = l_recalc_start_period_counter - 1;
15694
15695 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
15696
15697 calc_err EXCEPTION;
15698
15699 BEGIN
15700
15701 if (p_log_level_rec.statement_level) then
15702 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_hdr_rec.asset_id
15703 ,p_log_level_rec => p_log_level_rec);
15704 end if;
15705
15706 -- Skipping call to the function because it is not necessary for straight line
15707 -- or flat-cost with period end balance and use recoverable cost basis rules
15708 -- There are more cases which calling this function unnecessary but not include for this time.
15709 if (not( (fa_cache_pkg.fazccmt_record.rate_source_rule = fa_std_types.FAD_RSR_CALC)
15710 or ((fa_cache_pkg.fazccmt_record.rate_source_rule = fa_std_types.FAD_RSR_FLAT) and
15711 (fa_cache_pkg.fazccmt_record.deprn_basis_rule = fa_std_types.FAD_DBR_COST) and
15712 (fa_cache_pkg.fazcdbr_record.rule_name in ('PERIOD END BALANCE','USE RECOVERABLE COST'))))) then
15713
15714 -- Get Eofy/Eop Recovearble Cost and Salvage Value
15715 if (not FA_CALC_DEPRN_BASIS1_PKG.GET_EOFY_EOP (
15716 p_asset_id => p_asset_hdr_rec.asset_id,
15717 p_book_type_code => p_asset_hdr_rec.book_type_code,
15718 p_fiscal_year => p_period_rec.fiscal_year,
15719 p_asset_type => p_asset_type_rec.asset_type,
15720 p_period_num => p_period_rec.period_num,
15724 x_eop_recoverable_cost => l_eop_rec_cost,
15721 p_mrc_sob_type_code => p_mrc_sob_type_code,
15722 x_eofy_recoverable_cost => l_eofy_rec_cost,
15723 x_eofy_salvage_value => l_eofy_sal_val,
15725 x_eop_salvage_value => l_eop_sal_val
15726 ,p_log_level_rec => p_log_level_rec)) then
15727 if (p_log_level_rec.statement_level) then
15728 fa_debug_pkg.add(l_calling_fn, 'Error calling',
15729 'FA_CALC_DEPRN_BASIS1_PKG.GET_EOFY_EOP'
15730 ,p_log_level_rec => p_log_level_rec);
15731 end if;
15732
15733 raise calc_err;
15734
15735 end if;
15736 end if;
15737
15738 if (l_eofy_rec_cost is null) then
15739 l_eofy_rec_cost := 0;
15740 l_eofy_sal_val := 0;
15741 end if;
15742
15743 if (l_eop_rec_cost is null) then
15744 l_eop_rec_cost := 0;
15745 l_eop_sal_val := 0;
15746 end if;
15747
15748 -- Skipping call to faxcde because it is unnecessary for flat-cost with period end balance,
15749 -- use recoverable cost, period average, and beginning balance basis rules
15750 -- There are more cases which calling this function unnecessary but not include for this time.
15751 if (not(((fa_cache_pkg.fazccmt_record.rate_source_rule = fa_std_types.FAD_RSR_FLAT) and
15752 (fa_cache_pkg.fazccmt_record.deprn_basis_rule = fa_std_types.FAD_DBR_COST) and
15753 (fa_cache_pkg.fazcdbr_record.rule_name in ('PERIOD END BALANCE', 'PERIOD END AVERAGE',
15754 'USE RECOVERABLE COST', 'BEGINNING PERIOD')) or
15755 fa_cache_pkg.fazccmt_record.rate_source_rule = fa_std_types.FAD_RSR_PROD))) then
15756
15757 l_dpr_in.asset_num := p_asset_desc_rec.asset_number;
15758 l_dpr_in.calendar_type := fa_cache_pkg.fazcbc_record.deprn_calendar;
15759 l_dpr_in.book := p_asset_hdr_rec.book_type_code;
15760 l_dpr_in.asset_id := p_asset_hdr_rec.asset_id;
15761 l_dpr_in.adj_cost := px_asset_fin_rec_new.recoverable_cost;
15762 l_dpr_in.rec_cost := px_asset_fin_rec_new.recoverable_cost;
15763 l_dpr_in.reval_amo_basis := px_asset_fin_rec_new.reval_amortization_basis;
15764 l_dpr_in.deprn_rsv := 0;
15765 l_dpr_in.reval_rsv := p_asset_deprn_rec_new.reval_deprn_reserve;
15766 l_dpr_in.adj_rate := px_asset_fin_rec_new.adjusted_rate;
15767 l_dpr_in.rate_adj_factor := px_asset_fin_rec_new.rate_adjustment_factor;
15768 l_dpr_in.capacity := px_asset_fin_rec_new.production_capacity;
15769 l_dpr_in.adj_capacity := px_asset_fin_rec_new.adjusted_capacity;
15770 l_dpr_in.ltd_prod := 0;
15771
15772 l_dpr_in.ceil_name := px_asset_fin_rec_new.ceiling_name;
15773 l_dpr_in.bonus_rule := px_asset_fin_rec_new.bonus_rule;
15774 l_dpr_in.method_code := px_asset_fin_rec_new.deprn_method_code;
15775 l_dpr_in.jdate_in_service :=
15776 to_number(to_char(px_asset_fin_rec_new.date_placed_in_service, 'J'));
15777 l_dpr_in.prorate_jdate := to_number(to_char(px_asset_fin_rec_new.prorate_date, 'J'));
15778 l_dpr_in.deprn_start_jdate := to_number(to_char(px_asset_fin_rec_new.deprn_start_date, 'J'));
15779 l_dpr_in.jdate_retired := 0; -- don't know this is correct or not
15780 l_dpr_in.ret_prorate_jdate := 0; -- don't know this is correct or not
15781 l_dpr_in.life := px_asset_fin_rec_new.life_in_months;
15782
15783 l_dpr_in.rsv_known_flag := TRUE;
15784 l_dpr_in.salvage_value := px_asset_fin_rec_new.salvage_value;
15785 l_dpr_in.pc_life_end := px_asset_fin_rec_new.period_counter_life_complete;
15786 l_dpr_in.adj_rec_cost := px_asset_fin_rec_new.adjusted_recoverable_cost;
15787 l_dpr_in.prior_fy_exp := p_asset_deprn_rec_new.prior_fy_expense;
15788
15789 -- Bug:5612206
15790 l_dpr_in.deprn_rounding_flag := null;
15791
15792 l_dpr_in.deprn_override_flag := p_trans_rec.deprn_override_flag;
15793 l_dpr_in.used_by_adjustment := TRUE;
15794 l_dpr_in.ytd_deprn := p_asset_deprn_rec_new.ytd_deprn;
15795 l_dpr_in.short_fiscal_year_flag := px_asset_fin_rec_new.short_fiscal_year_flag;
15796 l_dpr_in.conversion_date := px_asset_fin_rec_new.conversion_date;
15797 l_dpr_in.prorate_date := px_asset_fin_rec_new.prorate_date;
15798 l_dpr_in.orig_deprn_start_date := px_asset_fin_rec_new.orig_deprn_start_date;
15799 l_dpr_in.old_adj_cost := px_asset_fin_rec_new.old_adjusted_cost;
15800 l_dpr_in.formula_factor := nvl(px_asset_fin_rec_new.formula_factor,
15801 p_asset_fin_rec_old.formula_factor);
15802 l_dpr_in.bonus_deprn_exp := p_asset_deprn_rec_new.bonus_deprn_amount;
15803 l_dpr_in.bonus_ytd_deprn := p_asset_deprn_rec_new.bonus_ytd_deprn;
15804 l_dpr_in.bonus_deprn_rsv := p_asset_deprn_rec_new.bonus_deprn_reserve;
15805 l_dpr_in.prior_fy_bonus_exp := p_asset_deprn_rec_new.prior_fy_bonus_expense;
15806
15807 l_dpr_in.tracking_method := px_asset_fin_rec_new.tracking_method;
15808 l_dpr_in.allocate_to_fully_ret_flag := px_asset_fin_rec_new.allocate_to_fully_ret_flag;
15809 l_dpr_in.allocate_to_fully_rsv_flag := px_asset_fin_rec_new.allocate_to_fully_rsv_flag;
15810 l_dpr_in.excess_allocation_option := px_asset_fin_rec_new.excess_allocation_option;
15811 l_dpr_in.depreciation_option := px_asset_fin_rec_new.depreciation_option;
15812 l_dpr_in.member_rollup_flag := px_asset_fin_rec_new.member_rollup_flag;
15813 l_dpr_in.over_depreciate_option := px_asset_fin_rec_new.over_depreciate_option;
15814 l_dpr_in.mrc_sob_type_code := p_mrc_sob_type_code;
15815
15816 --
15817 -- Not for what-if yet
15818 --
15822 fa_cache_pkg.fazcbc_record.fiscal_year_name,
15819 l_running_mode := fa_std_types.FA_DPR_NORMAL;
15820
15821 if not fa_cache_pkg.fazccp(fa_cache_pkg.fazcbc_record.prorate_calendar,
15823 l_dpr_in.prorate_jdate,
15824 l_temp_number,
15825 l_dpr_in.y_begin,
15826 l_temp_integer
15827 ,p_log_level_rec => p_log_level_rec) then
15828 if (p_log_level_rec.statement_level) then
15829 fa_debug_pkg.add(l_calling_fn, 'Error calling',
15830 'fa_cache_pkg.fazccp'
15831 ,p_log_level_rec => p_log_level_rec);
15832 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.prorate_calendar',
15833 fa_cache_pkg.fazcbc_record.prorate_calendar
15834 ,p_log_level_rec => p_log_level_rec);
15835 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.fiscal_year_name',
15836 fa_cache_pkg.fazcbc_record.fiscal_year_name
15837 ,p_log_level_rec => p_log_level_rec);
15838 end if;
15839
15840 raise calc_err;
15841 end if;
15842
15843
15844 l_dpr_in.p_cl_begin := 1;
15845
15846 if (p_period_rec.period_num = 1) then
15847 l_dpr_in.y_end := p_period_rec.fiscal_year - 1;
15848 l_dpr_in.p_cl_end := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
15849 else
15850 l_dpr_in.y_end := p_period_rec.fiscal_year;
15851 l_dpr_in.p_cl_end := p_period_rec.period_num - 1;
15852 end if;
15853
15854 l_dpr_in.rate_adj_factor := 1;
15855
15856 -- manual override
15857 if fa_cache_pkg.fa_deprn_override_enabled then
15858 if (not fa_cache_pkg.fazccmt(
15859 px_asset_fin_rec_new.deprn_method_code,
15860 px_asset_fin_rec_new.life_in_months
15861 ,p_log_level_rec => p_log_level_rec)) then
15862 if (p_log_level_rec.statement_level) then
15863 fa_debug_pkg.add(l_calling_fn, 'Error calling',
15864 'fa_cache_pkg.fazccmt'
15865 ,p_log_level_rec => p_log_level_rec);
15866 end if;
15867
15868 raise calc_err;
15869 end if;
15870
15871 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
15872 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
15873
15874 -- update override status only if satisfies condintion,
15875 -- otherwise do not update status when calculating RAF
15876 -- 1. formula; or
15877 -- 2. (calc or table) and cost
15878
15879 l_dpr_in.update_override_status :=
15880 ((l_rate_source_rule = fa_std_types.FAD_RSR_FORMULA)
15881 OR (((l_rate_source_rule = fa_std_types.FAD_RSR_CALC)
15882 OR (l_rate_source_rule = fa_std_types.FAD_RSR_TABLE))
15883 AND (l_deprn_basis_rule = fa_std_types.FAD_DBR_COST)));
15884 end if;
15885
15886 --* HHIRAGA modified on Oct/Nov in 2003.
15887 -- Changed parameter to period counter when the recalculation of
15888 -- RAF needs.
15889 -- This function will populates all member assets to be used to
15890 -- hypothetical allocation internally.
15891 --
15892 --+++++++ Call Tracking Function to populate Member in case ALLOCATE ++++++
15893 if p_asset_type_rec.asset_type = 'GROUP' and
15894 nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
15895
15896 l_raf_processed_flag := TRUE;
15897 l_dpr_in.tracking_method := NULL;
15898
15899 /*
15900 if not FA_TRACK_MEMBER_PVT.get_member_at_start(
15901 p_period_rec => l_period_rec,
15902 p_trans_rec => p_trans_rec,
15903 p_asset_hdr_rec => p_asset_hdr_rec,
15904 p_asset_fin_rec => px_asset_fin_rec_new,
15905 p_dpr_in => l_dpr_in,
15906 p_mrc_sob_type_code => p_mrc_sob_type_code
15907 ,p_log_level_rec => p_log_level_rec) then
15908 if (p_log_level_rec.statement_level) then
15909 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'FA_TRACK_MEMBER_PVT.get_member_at_start'
15910 ,p_log_level_rec => p_log_level_rec);
15911 end if;
15912
15913 raise calc_failed;
15914
15915 end if;
15916 */
15917 end if; -- nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE'
15918 -- End of HHIRAGA
15919
15920 --+++++++ Call Depreciation engine for rate adjustment factor +++++++
15921 if not FA_CDE_PKG.faxcde(l_dpr_in,
15922 l_dpr_arr,
15923 l_dpr_out,
15924 l_running_mode
15925 ,p_log_level_rec => p_log_level_rec) then
15926 if (p_log_level_rec.statement_level) then
15927 fa_debug_pkg.add(l_calling_fn, 'Error calling',
15928 'FA_CDE_PKG.faxcde'
15929 ,p_log_level_rec => p_log_level_rec);
15933 end if;
15930 end if;
15931
15932 raise calc_err;
15934
15935 -- Bug 4129984.
15936
15937 if ((fa_cache_pkg.fazcbc_record.AMORTIZE_REVAL_RESERVE_FLAG='YES') and
15938 (px_asset_fin_rec_new.Reval_Amortization_Basis is not null) and
15939 (p_asset_type_rec.asset_type = 'CAPITALIZED') and
15940 (px_asset_fin_rec_new.group_asset_id is null)) then
15941
15942 px_asset_fin_rec_new.reval_amortization_basis := p_asset_deprn_rec_new.reval_deprn_reserve;
15943 end if;
15944
15945 else -- in the case of skipping faxcde call
15946 l_dpr_out.new_adj_cost := px_asset_fin_rec_new.recoverable_cost;
15947 l_dpr_out.new_deprn_rsv := p_asset_deprn_rec_new.deprn_reserve;
15948 l_dpr_out.new_bonus_deprn_rsv := p_asset_deprn_rec_new.bonus_deprn_reserve;
15949 end if;
15950
15951
15952 --
15953 -- Bug4213715: new reserve has already include adj_reserve in case of group
15954 -- reclass with enter option.
15955 --
15956 if (p_asset_type_rec.asset_type = 'GROUP') and
15957 (p_trans_rec.transaction_key = 'GC') then
15958 -- reclass w/ enter option at group level
15959
15960 l_deprn_reserve := nvl(p_asset_deprn_rec_new.deprn_reserve, 0);
15961
15962 elsif (p_asset_type_rec.asset_type <> 'GROUP') and
15963 (nvl(p_asset_fin_rec_old.group_asset_id, 0) <>
15964 nvl(px_asset_fin_rec_new.group_asset_id, 0)) then
15965
15966 l_deprn_reserve := nvl(p_asset_deprn_rec_new.deprn_reserve, 0);
15967
15968 -- Bug 6803812: In case of Period of addition, p_asset_deprn_rec_new
15969 -- contains the new reserve
15970 elsif ( p_asset_hdr_rec.period_of_addition = 'Y') then
15971 l_deprn_reserve := nvl(p_asset_deprn_rec_new.deprn_reserve, 0);
15972 else
15973 -- Ordinary behavior
15974 l_deprn_reserve := p_asset_deprn_rec_new.deprn_reserve +
15975 nvl(p_asset_deprn_rec_adj.deprn_reserve, 0);
15976 end if;
15977
15978
15979 /*code fix for bug no.3630495. added the following line to calculate the adjusted capacity*/
15980 if (nvl(px_asset_fin_rec_new.tracking_method, 'NO TRACK') = 'ALLOCATE') and -- ENERGY
15981 (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') then -- ENERGY
15982 null;
15983 else
15984 px_asset_fin_rec_new.adjusted_capacity:=px_asset_fin_rec_new.production_capacity- nvl(l_dpr_out.new_ltd_prod, 0);
15985 end if;
15986
15987 if (p_asset_hdr_rec.period_of_addition = 'Y') and
15988 (p_asset_type_rec.asset_type = 'GROUP') then
15989 px_asset_fin_rec_new.eofy_reserve := nvl(px_asset_fin_rec_new.eofy_reserve,
15990 p_asset_deprn_rec_new.deprn_reserve -
15991 p_asset_deprn_rec_new.ytd_deprn);
15992 else
15993
15994 /* Fix for Bug#4541399: We have to activate this code
15995 only when px_asset_fin_rec_new.eofy_reserve is NULL */
15996 if (px_asset_fin_rec_new.eofy_reserve is null) then
15997 px_asset_fin_rec_new.eofy_reserve := p_asset_deprn_rec_new.deprn_reserve -
15998 p_asset_deprn_rec_new.ytd_deprn;
15999 end if;
16000
16001 end if;
16002
16003 -- HHIRAGA
16004 --+++++++ Call Tracking Function to populate Member in case ALLOCATE ++++++
16005 if (l_raf_processed_flag) then
16006 l_dpr_in.tracking_method := 'ALLOCATE';
16007 l_raf_processed_flag := FALSE;
16008 end if;
16009
16010 -- HHIRAGA
16011 --+++++++ Call Populate_member_assets_table function
16012 if nvl(l_dpr_in.tracking_method,'OTHER') = 'ALLOCATE' then
16013 fa_track_member_pvt.p_track_member_table.delete;
16014 if (p_log_level_rec.statement_level) then
16015 fa_debug_pkg.add(l_calling_fn, 'Delete p_track_member_table', '+++'
16016 ,p_log_level_rec => p_log_level_rec);
16017 end if;
16018 end if;
16019
16020 if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
16021 (p_event_type => 'AMORT_ADJ',
16022 p_asset_fin_rec_new => px_asset_fin_rec_new,
16023 p_asset_fin_rec_old => p_asset_fin_rec_old,
16024 p_asset_hdr_rec => p_asset_hdr_rec,
16025 p_asset_type_rec => p_asset_type_rec,
16026 p_asset_deprn_rec => p_asset_deprn_rec_new,
16027 p_trans_rec => p_trans_rec,
16028 p_period_rec => p_period_rec,
16029 p_current_total_rsv => l_deprn_reserve,
16030 p_current_rsv => l_deprn_reserve -
16031 p_asset_deprn_rec_new.bonus_deprn_reserve,
16032 p_current_total_ytd => p_asset_deprn_rec_new.ytd_deprn,
16033 p_adj_reserve => p_asset_deprn_rec_adj.deprn_reserve,
16034 p_hyp_basis => l_dpr_out.new_adj_cost,
16035 p_hyp_total_rsv => l_dpr_out.new_deprn_rsv,
16036 p_hyp_rsv => l_dpr_out.new_deprn_rsv -
16037 l_dpr_out.new_bonus_deprn_rsv,
16038 p_eofy_recoverable_cost => l_eofy_rec_cost,
16039 p_eop_recoverable_cost => l_eop_rec_cost,
16043 p_used_by_adjustment => 'ADJUSTMENT',
16040 p_eofy_salvage_value => l_eofy_sal_val,
16041 p_eop_salvage_value => l_eop_sal_val,
16042 p_mrc_sob_type_code => p_mrc_sob_type_code,
16044 px_new_adjusted_cost => px_asset_fin_rec_new.adjusted_cost,
16045 px_new_raf => px_asset_fin_rec_new.rate_adjustment_factor,
16046 px_new_formula_factor => px_asset_fin_rec_new.formula_factor
16047 ,p_log_level_rec => p_log_level_rec)) then
16048 raise calc_err;
16049 end if;
16050 --Bug6770599
16051 if (p_trans_rec.transaction_subtype = 'AMORTIZED') and
16052 (p_trans_rec.transaction_type_code = 'GROUP ADDITION' )
16053 and p_asset_fin_rec_old.date_placed_in_service > px_asset_fin_rec_new.date_placed_in_service
16054 then
16055
16056 if not createGroup(
16057 p_trans_rec => p_trans_rec,
16058 p_asset_hdr_rec => p_asset_hdr_rec,
16059 p_asset_type_rec => p_asset_type_rec,
16060 p_period_rec => p_period_rec,
16061 p_asset_fin_rec => px_asset_fin_rec_new,
16062 p_asset_deprn_rec => p_asset_deprn_rec_adj,
16063 p_mrc_sob_type_code => p_mrc_sob_type_code,
16064 p_calling_fn => l_calling_fn) then
16065
16066 if (p_log_level_rec.statement_level) then
16067 fa_debug_pkg.add(l_calling_fn, 'calling FA_AMORT_PVT.createGroup', 'FAILED',
16068 p_log_level_rec => p_log_level_rec);
16069 end if;
16070
16071 return (FALSE);
16072
16073 end if;
16074
16075 end if;
16076 --++ HHIRAGA
16077 --++++++++ tracking is allocate case, create bs table
16078 if nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' then
16079
16080 if not FA_TRACK_MEMBER_PVT.update_member_books(p_trans_rec => p_trans_rec,
16081 p_asset_hdr_rec => p_asset_hdr_rec,
16082 p_dpr_in => l_dpr_in,
16083 p_mrc_sob_type_code => p_mrc_sob_type_code
16084 ,p_log_level_rec => p_log_level_rec) then
16085 if (p_log_level_rec.statement_level) then
16086 fa_debug_pkg.add(l_calling_fn, 'Error calling',
16087 'FA_TRACK_MEMBER_PVT.update_member_books'
16088 ,p_log_level_rec => p_log_level_rec);
16089 end if;
16090
16091 raise calc_err;
16092 end if;
16093
16094 if (p_log_level_rec.statement_level) then
16095 fa_debug_pkg.add(l_calling_fn, 'fa_track_member_pvt.create_update_bs_table',
16096 'called'
16097 ,p_log_level_rec => p_log_level_rec);
16098 end if;
16099
16100 if not FA_TRACK_MEMBER_PVT.create_update_bs_table(p_trans_rec => p_trans_rec,
16101 p_book_type_code => p_asset_hdr_rec.book_type_code,
16102 p_group_asset_id => p_asset_hdr_rec.asset_id,
16103 p_calling_fn => l_calling_fn
16104 ,p_log_level_rec => p_log_level_rec) then
16108 ,p_log_level_rec => p_log_level_rec);
16105 if (p_log_level_rec.statement_level) then
16106 fa_debug_pkg.add(l_calling_fn, 'Error calling',
16107 'FA_TRACK_MEMBER_PVT.create_update_bs_table'
16109 end if;
16110
16111 raise calc_err;
16112 end if;
16113
16114 fa_track_member_pvt.p_track_member_eofy_table.delete;
16115 fa_track_member_pvt.p_track_member_table.delete;
16116
16117 if (p_log_level_rec.statement_level) then
16118 fa_debug_pkg.add(l_calling_fn, 'fa_track_member_pvt.p_track_member_eofy_table/member_table',
16119 'deleted'
16120 ,p_log_level_rec => p_log_level_rec);
16121 end if;
16122
16123 end if; -- nvl(px_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE'
16124 -- End of HHIRAGA
16125
16126 -- Bug7446301: Redoing fix for bug7209655. Removed tracking method condition so that process
16127 -- will satisfy following if condition even if the asset type is not GROUP
16128 if (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') and -- ENERGY
16129 (fa_cache_pkg.fazccmt_record.rate_source_rule = FA_STD_TYPES.FAD_RSR_PROD) then
16130 px_asset_fin_rec_new.adjusted_capacity := nvl(px_asset_fin_rec_new.production_capacity, 0) -
16131 nvl(p_asset_deprn_rec_new.ltd_production, 0);
16132 end if;
16133
16134 --
16135 -- Purpose of calling CurrentPeriodAdj is to reflect the trx to
16136 -- FA_BOOKS_SUMMARY. Not for calculating a catch-up.
16137 -- Call CurrentPeriodAdj if:
16138 -- This is group asset.
16139 -- This is current period trx
16140 -- This is not member ret/rein, group reclass or group reclas with enter.
16141 --
16142 if (p_asset_type_rec.asset_type = 'GROUP') and
16143 (nvl(p_trans_rec.amortization_start_date,
16144 p_trans_rec.transaction_date_entered) >=
16145 p_period_rec.calendar_period_open_date) and
16146 (p_trans_rec.transaction_key not in ('MR', 'MS', 'GC') or
16147 ((p_trans_rec.transaction_key = 'GC' and
16148 nvl(p_group_reclass_options_rec.group_reclass_type, 'NULL') = 'MANUAL'))) then
16149
16150 --tk_util.DumpTrxRec(p_trans_rec, 'p_trans_rec');
16151 --tk_util.DumpFinRec(p_asset_fin_rec_old, 'old fin_rec');
16152 --tk_util.DumpFinRec(px_asset_fin_rec_new, 'new_fin_rec');
16153 --tk_util.DumpDeprnRec(p_asset_deprn_rec_adj, 'adj deprn');
16154
16155 populate_fin_rec(
16156 p_trans_rec => p_trans_rec,
16157 p_asset_fin_rec_old => p_asset_fin_rec_old,
16158 p_asset_fin_rec_new => px_asset_fin_rec_new,
16159 x_asset_fin_rec_adj => l_asset_fin_rec_adj
16160 ,p_log_level_rec => p_log_level_rec);
16161
16162 if (not CurrentPeriodAdj(
16163 p_trans_rec => p_trans_rec,
16164 p_asset_hdr_rec => p_asset_hdr_rec,
16165 p_asset_type_rec => p_asset_type_rec,
16166 p_asset_fin_rec_adj => l_asset_fin_rec_adj,
16167 p_asset_fin_rec_old => p_asset_fin_rec_old,
16168 px_asset_fin_rec_new => px_asset_fin_rec_new,
16169 p_period_rec => p_period_rec,
16170 p_asset_deprn_rec_adj => p_asset_deprn_rec_adj,
16171 p_proceeds_of_sale => 0,
16172 p_cost_of_removal => 0,
16173 p_calling_fn => l_calling_fn,
16174 p_mrc_sob_type_code => p_mrc_sob_type_code
16175 ,p_log_level_rec => p_log_level_rec)) then
16176 raise calc_err;
16177 end if;
16178
16179 end if; -- (p_asset_type_rec.asset_type = 'GROUP')
16180
16181 if (p_log_level_rec.statement_level) then
16182 fa_debug_pkg.add(l_calling_fn, 'End', px_asset_fin_rec_new.adjusted_cost
16183 ,p_log_level_rec => p_log_level_rec);
16184 end if;
16185
16186 return true;
16187
16188 EXCEPTION
16189 when calc_err then
16190 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
16191 ,p_log_level_rec => p_log_level_rec);
16192 return false;
16193
16197 return false;
16194 when others then
16195 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
16196 ,p_log_level_rec => p_log_level_rec);
16198
16199 END calc_raf_adj_cost;
16200
16201 FUNCTION check_dpis_change (
16202 p_book_type_code VARCHAR2,
16203 p_transaction_header_id NUMBER,
16204 p_group_asset_id NUMBER,
16205 x_asset_fin_rec OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
16206 x_period_counter_out OUT NOCOPY NUMBER,
16207 p_mrc_sob_type_code VARCHAR2,
16208 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
16209 RETURN BOOLEAN is
16210
16211 l_calling_fn varchar2(100) := 'FA_AMORT_PVT.check_dpis_change';
16212
16213 CURSOR c_check_dpis_change is
16214 select inbk.cost
16215 , inbk.cip_cost
16216 , inbk.salvage_value
16217 , inbk.allowed_deprn_limit_amount
16218 , bs.period_counter
16219 from fa_books inbk
16220 , fa_books outbk
16221 , fa_transaction_headers inth
16222 , fa_transaction_headers outth
16223 , fa_books_summary bs
16224 where inbk.transaction_header_id_in = p_transaction_header_id
16225 and outbk.asset_id = inbk.asset_id
16226 and outbk.book_type_code = p_book_type_code
16227 and outbk.transaction_header_id_out = p_transaction_header_id
16228 and outbk.transaction_header_id_in = outth.transaction_header_id
16229 and bs.asset_id = p_group_asset_id
16230 and bs.book_type_code = p_book_type_code
16231 and nvl(outth.amortization_start_date,
16232 outth.transaction_date_entered) between bs.calendar_period_open_date
16233 and bs.calendar_period_close_date
16234 and inbk.cost = outbk.cost
16235 and nvl(inbk.salvage_value, 0) = nvl(outbk.salvage_value, 0)
16236 and nvl(inbk.allowed_deprn_limit_amount, 0) = nvl(outbk.allowed_deprn_limit_amount, 0)
16237 and inbk.date_placed_in_service <> outbk.date_placed_in_service
16238 ;
16239 chk_err exception;
16240
16241 BEGIN
16242 if (p_log_level_rec.statement_level) then
16243 fa_debug_pkg.add(l_calling_fn, 'Begin', p_transaction_header_id, p_log_level_rec);
16244 end if;
16245
16246 OPEN c_check_dpis_change;
16247 FETCH c_check_dpis_change into x_asset_fin_rec.cost
16248 , x_asset_fin_rec.cip_cost
16249 , x_asset_fin_rec.salvage_value
16250 , x_asset_fin_rec.allowed_deprn_limit_amount
16251 , x_period_counter_out;
16252
16253 CLOSE c_check_dpis_change;
16254
16255 if (p_log_level_rec.statement_level) then
16256 fa_debug_pkg.add(l_calling_fn, 'x_period_counter_out', x_period_counter_out, p_log_level_rec);
16257 fa_debug_pkg.add(l_calling_fn, 'x_asset_fin_rec.cost', x_asset_fin_rec.cost, p_log_level_rec);
16258 fa_debug_pkg.add(l_calling_fn, 'End', x_asset_fin_rec.cost, p_log_level_rec);
16259 end if;
16260
16261 return true;
16262
16263 EXCEPTION
16264 when chk_err then
16265 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn,
16266 p_log_level_rec => p_log_level_rec);
16267 return false;
16268
16269 when others then
16270 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn,
16271 p_log_level_rec => p_log_level_rec);
16272 return false;
16273
16274 END check_dpis_change;
16275
16276 --Bug 5149789
16277 FUNCTION check_member_existence (
16278 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type
16279 , p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
16280 RETURN BOOLEAN is
16281
16282 l_calling_fn varchar2(100) := 'FA_AMORT_PVT.check_member_existence';
16283
16284 CURSOR c_mem_exists IS
16285 select transaction_header_id_in
16286 from fa_books
16287 where group_asset_id = p_asset_hdr_rec.asset_id
16288 and book_type_code = p_asset_hdr_rec.book_type_code
16289 and transaction_header_id_out is null;
16290
16291 l_temp_thid NUMBER;
16292
16293 BEGIN
16294 if (p_log_level_rec.statement_level) then
16295 fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_hdr_rec.asset_id, p_log_level_rec);
16296 end if;
16297
16298 OPEN c_mem_exists;
16299 FETCH c_mem_exists INTO l_temp_thid;
16300
16301 if (p_log_level_rec.statement_level) then
16302 fa_debug_pkg.add(l_calling_fn, 'Begin', c_mem_exists%notfound, p_log_level_rec);
16303 end if;
16304
16305 if (c_mem_exists%notfound) then
16306 CLOSE c_mem_exists;
16307 return true;
16308 else
16309 CLOSE c_mem_exists;
16310 return false;
16311 end if;
16312
16313 EXCEPTION
16314 when others then
16315 if (p_log_level_rec.statement_level) then
16316 fa_debug_pkg.add(l_calling_fn, 'Error', sqlerrm, p_log_level_rec);
16317 end if;
16318
16319 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
16320 return false;
16321
16322 END check_member_existence;
16323
16324 END FA_AMORT_PVT;