[Home] [Help]
PACKAGE BODY: APPS.FA_DEPRN_ROLLBACK_PVT
Source
1 PACKAGE BODY FA_DEPRN_ROLLBACK_PVT AS
2 /* $Header: FAVDRBB.pls 120.27.12020000.5 2012/11/30 11:28:16 spooyath ship $ */
3
4 g_print_debug boolean := fa_cache_pkg.fa_print_debug;
5 g_l_thid NUMBER; /* Bug#9018861 - For reporting currecny */
6 g_pdr_thid NUMBER;
7 g_pdr_found BOOLEAN := FALSE;
8
9 function do_rollback (
10 p_asset_hdr_rec IN fa_api_types.asset_hdr_rec_type,
11 p_period_rec IN fa_api_types.period_rec_type,
12 p_deprn_run_id IN NUMBER,
13 p_reversal_event_id IN NUMBER,
14 p_reversal_date IN DATE,
15 p_deprn_exists_count IN NUMBER,
16 p_mrc_sob_type_code IN VARCHAR2,
17 p_calling_fn IN VARCHAR2,
18 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) return boolean as
19
20 CURSOR c_get_thid IS
21 select transaction_header_id
22 , event_id
23 from fa_transaction_headers
24 where asset_id = p_asset_hdr_rec.asset_id
25 and book_type_code = p_asset_hdr_rec.book_type_code
26 and date_effective between p_period_rec.period_open_date
27 and nvl(p_period_rec.period_close_date, sysdate)
28 and calling_interface = 'FADEPR'
29 and transaction_key = 'TG';
30
31 CURSOR c_get_new_thid IS
32 select transaction_header_id
33 , date_effective
34 from fa_transaction_headers
35 where asset_id = p_asset_hdr_rec.asset_id
36 and book_type_code = p_asset_hdr_rec.book_type_code
37 and date_effective between p_period_rec.period_open_date
38 and nvl(p_period_rec.period_close_date, sysdate)
39 and calling_interface = 'FAXDRB'
40 and transaction_key = 'TG'
41 order by transaction_header_id desc;
42 --Secondary Changes
43 CURSOR c_get_sec_event_id(c_thid number) is
44 select event_id
45 from xla_events xeve,
46 xla_transaction_entities partition (ofa) xent
47 where xeve.application_id = 140
48 and xeve.event_type_code = '%TERMINAL_GAIN_LOSS%'
49 and xent.application_id = xeve.application_id
50 and source_id_char_1 =p_asset_hdr_rec.book_type_code
51 and source_id_int_1 = c_thid
52 and xeve.entity_id = xent.entity_id;
53 l_deprn_run_date DATE;
54
55 -- Terminal Gain/Loss
56 l_thid NUMBER;
57 l_event_id NUMBER;
58 l_event_status VARCHAR2(1);
59 l_deprn_source_info XLA_EVENTS_PUB_PKG.t_event_source_info;
60 l_security_context XLA_EVENTS_PUB_PKG.t_security;
61 l_trans_rec FA_API_TYPES.trans_rec_type;
62 l_asset_type_rec FA_API_TYPES.asset_type_rec_type;
63 l_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
64 l_status boolean;
65 l_bks_rowid ROWID;
66 pers_per_yr NUMBER; -- Bug:5701095
67
68 --Secondary Changes
69 l_secondary_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
70 l_secondary_trans_rec FA_API_TYPES.trans_rec_type;
71 l_secondary_event_status VARCHAR2(1);
72 l_secondary_event_id number;
73
74 l_calling_fn varchar2(40) := 'fa_deprn_rollback_pvt.do_rollback';
75
76 rb_error exception;
77
78 -- Bug:6665510:Japan Tax Reform Project
79 TYPE tab_rowid_type is table of rowid index by binary_integer;
80 TYPE tab_number_type is table of number index by binary_integer;
81 TYPE tab_varchar_type2 is table of varchar2(150) index by binary_integer;
82
83 l_bks_rowid_tbl2 tab_rowid_type;
84 l_asset_id_tbl2 tab_number_type;
85 l_method_code_tbl2 tab_varchar_type2;
86 l_life_in_months_tbl2 tab_number_type;
87 l_rate_in_use_tbl tab_number_type;
88
89 l_method_type number := 0;
90 l_success integer;
91 l_rate_in_use number;
92
93 -- used for bulk fetching
94 l_batch_size NUMBER;
95 l_rows_processed NUMBER;
96 l_result integer;
97
98 -- Bug:6665510:Japan Tax Reform Project
99 cursor c_rate_in_use
100 Is
101 select bks.rowid,
102 bks.asset_id,
103 bks.deprn_method_code,
104 bks.life_in_months
105 from fa_books bks,
106 fa_methods mt
107 where bks.asset_id = p_asset_hdr_rec.asset_id
108 and bks.book_type_code = p_asset_hdr_rec.book_type_code
109 and bks.transaction_header_id_out is null
110 and bks.deprn_method_code = mt.method_code
111 and nvl(bks.life_in_months, -99) = nvl(mt.life_in_months, -99)
112 and nvl(mt.guarantee_rate_method_flag, 'NO') = 'YES';
113
114 -- Bug:6665510:Japan Tax Reform Project
115 cursor c_mc_rate_in_use
116 Is
117 select bks.rowid,
118 bks.asset_id,
119 bks.deprn_method_code,
120 bks.life_in_months
121 from fa_mc_books bks,
122 fa_methods mt
123 where bks.asset_id = p_asset_hdr_rec.asset_id
124 and bks.book_type_code = p_asset_hdr_rec.book_type_code
125 and bks.transaction_header_id_out is null
126 and bks.deprn_method_code = mt.method_code
127 and nvl(bks.life_in_months, -99) = nvl(mt.life_in_months, -99)
128 and nvl(mt.guarantee_rate_method_flag, 'NO') = 'YES'
129 and bks.set_of_books_id = p_asset_hdr_rec.set_of_books_id;
130
131 -- ER 14644811 : Get the period end revaluation th_id
132 cursor c_get_pdr_thid
133 is
134 select transaction_header_id
135 , event_id
136 from fa_transaction_headers th
137 where th.asset_id = p_asset_hdr_rec.asset_id
138 and th.book_type_code = p_asset_hdr_rec.book_type_code
139 and th.date_effective between p_period_rec.period_open_date
140 and nvl(p_period_rec.period_close_date, sysdate)
141 and th.transaction_type_code = 'REVALUATION'
142 and th.transaction_key = 'PR'
143 and exists (select 'not rollbacked'
144 from fa_books bk
145 where bk.book_type_code = p_asset_hdr_rec.book_type_code
146 and bk.asset_id = p_asset_hdr_rec.asset_id
147 and bk.transaction_header_id_in = th.transaction_header_id
148 and bk.transaction_header_id_out is null)
149 order by th.transaction_header_id desc;
150
151 l_pdr_event_id NUMBER;
152
153 begin
154
155
156 -- SLA UPTAKE
157 -- backup the data delete or reverse the event
158
159 if (p_reversal_event_id is not null) then
160
161 if (p_mrc_sob_type_code = 'R') then
162
163 insert into fa_mc_deprn_summary_h
164 (SET_OF_BOOKS_ID ,
165 BOOK_TYPE_CODE ,
166 ASSET_ID ,
167 DEPRN_RUN_DATE ,
168 DEPRN_AMOUNT ,
169 YTD_DEPRN ,
170 DEPRN_RESERVE ,
171 DEPRN_SOURCE_CODE ,
172 ADJUSTED_COST ,
173 BONUS_RATE ,
174 LTD_PRODUCTION ,
175 PERIOD_COUNTER ,
176 PRODUCTION ,
177 REVAL_AMORTIZATION ,
178 REVAL_AMORTIZATION_BASIS ,
179 REVAL_DEPRN_EXPENSE ,
180 REVAL_RESERVE ,
181 YTD_PRODUCTION ,
182 YTD_REVAL_DEPRN_EXPENSE ,
183 PRIOR_FY_EXPENSE ,
184 BONUS_DEPRN_AMOUNT ,
185 BONUS_YTD_DEPRN ,
186 BONUS_DEPRN_RESERVE ,
187 PRIOR_FY_BONUS_EXPENSE ,
188 DEPRN_OVERRIDE_FLAG ,
189 SYSTEM_DEPRN_AMOUNT ,
190 SYSTEM_BONUS_DEPRN_AMOUNT ,
191 IMPAIRMENT_AMOUNT ,
192 YTD_IMPAIRMENT ,
193 IMPAIRMENT_RESERVE ,
194 CAPITAL_ADJUSTMENT ,
195 GENERAL_FUND ,
196 REVAL_LOSS_BALANCE ,
197 EVENT_ID ,
198 DEPRN_RUN_ID ,
199 REVERSAL_EVENT_ID ,
200 REVERSAL_DATE )
201 select SET_OF_BOOKS_ID ,
202 BOOK_TYPE_CODE ,
203 ASSET_ID ,
204 DEPRN_RUN_DATE ,
205 DEPRN_AMOUNT ,
206 YTD_DEPRN ,
207 DEPRN_RESERVE ,
208 DEPRN_SOURCE_CODE ,
209 ADJUSTED_COST ,
210 BONUS_RATE ,
211 LTD_PRODUCTION ,
212 PERIOD_COUNTER ,
213 PRODUCTION ,
214 REVAL_AMORTIZATION ,
215 REVAL_AMORTIZATION_BASIS ,
216 REVAL_DEPRN_EXPENSE ,
217 REVAL_RESERVE ,
218 YTD_PRODUCTION ,
219 YTD_REVAL_DEPRN_EXPENSE ,
220 PRIOR_FY_EXPENSE ,
221 BONUS_DEPRN_AMOUNT ,
222 BONUS_YTD_DEPRN ,
223 BONUS_DEPRN_RESERVE ,
224 PRIOR_FY_BONUS_EXPENSE ,
225 DEPRN_OVERRIDE_FLAG ,
226 SYSTEM_DEPRN_AMOUNT ,
227 SYSTEM_BONUS_DEPRN_AMOUNT ,
228 IMPAIRMENT_AMOUNT ,
229 YTD_IMPAIRMENT ,
230 IMPAIRMENT_RESERVE ,
231 CAPITAL_ADJUSTMENT ,
232 GENERAL_FUND ,
233 REVAL_LOSS_BALANCE ,
234 EVENT_ID ,
235 DEPRN_RUN_ID ,
236 P_REVERSAL_EVENT_ID ,
237 P_REVERSAL_DATE
238 from fa_mc_deprn_summary ds
239 where ds.book_type_code = p_asset_hdr_rec.book_type_code
240 and ds.asset_id = p_asset_hdr_rec.asset_id
241 and ds.period_counter = p_period_rec.period_counter
242 and ds.deprn_source_code in ('DEPRN','TRACK')
243 and ds.set_of_books_id = p_asset_hdr_rec.set_of_books_id;
244
245 insert into fa_mc_deprn_detail_h
246 (SET_OF_BOOKS_ID ,
247 BOOK_TYPE_CODE ,
248 ASSET_ID ,
249 PERIOD_COUNTER ,
250 DISTRIBUTION_ID ,
251 DEPRN_SOURCE_CODE ,
252 DEPRN_RUN_DATE ,
253 DEPRN_AMOUNT ,
254 YTD_DEPRN ,
255 DEPRN_RESERVE ,
256 ADDITION_COST_TO_CLEAR ,
257 COST ,
258 DEPRN_ADJUSTMENT_AMOUNT ,
259 REVAL_AMORTIZATION ,
260 REVAL_DEPRN_EXPENSE ,
261 REVAL_RESERVE ,
262 YTD_REVAL_DEPRN_EXPENSE ,
263 BONUS_DEPRN_AMOUNT ,
264 BONUS_YTD_DEPRN ,
265 BONUS_DEPRN_RESERVE ,
266 BONUS_DEPRN_ADJUSTMENT_AMOUNT ,
267 IMPAIRMENT_AMOUNT ,
268 YTD_IMPAIRMENT ,
269 IMPAIRMENT_RESERVE ,
270 CAPITAL_ADJUSTMENT ,
271 GENERAL_FUND ,
272 EVENT_ID ,
273 DEPRN_RUN_ID ,
274 REVERSAL_EVENT_ID ,
275 REVERSAL_DATE )
276 select SET_OF_BOOKS_ID ,
277 BOOK_TYPE_CODE ,
278 ASSET_ID ,
279 PERIOD_COUNTER ,
280 DISTRIBUTION_ID ,
281 DEPRN_SOURCE_CODE ,
282 DEPRN_RUN_DATE ,
283 DEPRN_AMOUNT ,
284 YTD_DEPRN ,
285 DEPRN_RESERVE ,
286 ADDITION_COST_TO_CLEAR ,
287 COST ,
288 DEPRN_ADJUSTMENT_AMOUNT ,
289 REVAL_AMORTIZATION ,
290 REVAL_DEPRN_EXPENSE ,
291 REVAL_RESERVE ,
292 YTD_REVAL_DEPRN_EXPENSE ,
293 BONUS_DEPRN_AMOUNT ,
294 BONUS_YTD_DEPRN ,
295 BONUS_DEPRN_RESERVE ,
296 BONUS_DEPRN_ADJUSTMENT_AMOUNT ,
297 IMPAIRMENT_AMOUNT ,
298 YTD_IMPAIRMENT ,
299 IMPAIRMENT_RESERVE ,
300 CAPITAL_ADJUSTMENT ,
301 GENERAL_FUND ,
302 EVENT_ID ,
303 DEPRN_RUN_ID ,
304 P_REVERSAL_EVENT_ID ,
305 P_REVERSAL_DATE
306 from fa_mc_deprn_detail ds
307 where ds.book_type_code = p_asset_hdr_rec.book_type_code
308 and ds.asset_id = p_asset_hdr_rec.asset_id
309 and ds.period_counter = p_period_rec.period_counter
310 and ds.deprn_source_code in ('D','T')
311 and ds.set_of_books_id = p_asset_hdr_rec.set_of_books_id;
312
313 else
314
315 -- archive the prior info into the backup table
316 insert into fa_deprn_summary_h
317 (BOOK_TYPE_CODE ,
318 ASSET_ID ,
319 DEPRN_RUN_DATE ,
320 DEPRN_AMOUNT ,
321 YTD_DEPRN ,
322 DEPRN_RESERVE ,
323 DEPRN_SOURCE_CODE ,
324 ADJUSTED_COST ,
325 BONUS_RATE ,
326 LTD_PRODUCTION ,
327 PERIOD_COUNTER ,
328 PRODUCTION ,
329 REVAL_AMORTIZATION ,
330 REVAL_AMORTIZATION_BASIS ,
331 REVAL_DEPRN_EXPENSE ,
332 REVAL_RESERVE ,
333 YTD_PRODUCTION ,
334 YTD_REVAL_DEPRN_EXPENSE ,
335 PRIOR_FY_EXPENSE ,
336 BONUS_DEPRN_AMOUNT ,
337 BONUS_YTD_DEPRN ,
338 BONUS_DEPRN_RESERVE ,
339 PRIOR_FY_BONUS_EXPENSE ,
340 DEPRN_OVERRIDE_FLAG ,
341 SYSTEM_DEPRN_AMOUNT ,
342 SYSTEM_BONUS_DEPRN_AMOUNT ,
343 IMPAIRMENT_AMOUNT ,
344 YTD_IMPAIRMENT ,
345 IMPAIRMENT_RESERVE ,
346 CAPITAL_ADJUSTMENT ,
347 GENERAL_FUND ,
348 REVAL_LOSS_BALANCE ,
349 EVENT_ID ,
350 DEPRN_RUN_ID ,
351 REVERSAL_EVENT_ID ,
352 REVERSAL_DATE )
353 select BOOK_TYPE_CODE ,
354 ASSET_ID ,
355 DEPRN_RUN_DATE ,
356 DEPRN_AMOUNT ,
357 YTD_DEPRN ,
358 DEPRN_RESERVE ,
359 DEPRN_SOURCE_CODE ,
360 ADJUSTED_COST ,
361 BONUS_RATE ,
362 LTD_PRODUCTION ,
363 PERIOD_COUNTER ,
364 PRODUCTION ,
365 REVAL_AMORTIZATION ,
366 REVAL_AMORTIZATION_BASIS ,
367 REVAL_DEPRN_EXPENSE ,
368 REVAL_RESERVE ,
369 YTD_PRODUCTION ,
370 YTD_REVAL_DEPRN_EXPENSE ,
371 PRIOR_FY_EXPENSE ,
372 BONUS_DEPRN_AMOUNT ,
373 BONUS_YTD_DEPRN ,
374 BONUS_DEPRN_RESERVE ,
375 PRIOR_FY_BONUS_EXPENSE ,
376 DEPRN_OVERRIDE_FLAG ,
377 SYSTEM_DEPRN_AMOUNT ,
378 SYSTEM_BONUS_DEPRN_AMOUNT ,
379 IMPAIRMENT_AMOUNT ,
380 YTD_IMPAIRMENT ,
381 IMPAIRMENT_RESERVE ,
382 CAPITAL_ADJUSTMENT ,
383 GENERAL_FUND ,
384 REVAL_LOSS_BALANCE ,
385 EVENT_ID ,
386 DEPRN_RUN_ID ,
387 P_REVERSAL_EVENT_ID ,
388 P_REVERSAL_DATE
389 from fa_deprn_summary ds
390 where ds.book_type_code = p_asset_hdr_rec.book_type_code
391 and ds.asset_id = p_asset_hdr_rec.asset_id
392 and ds.period_counter = p_period_rec.period_counter
393 and ds.deprn_source_code in ('DEPRN','TRACK');
394
395 insert into fa_deprn_detail_h
396 (BOOK_TYPE_CODE ,
397 ASSET_ID ,
398 PERIOD_COUNTER ,
399 DISTRIBUTION_ID ,
400 DEPRN_SOURCE_CODE ,
401 DEPRN_RUN_DATE ,
402 DEPRN_AMOUNT ,
403 YTD_DEPRN ,
404 DEPRN_RESERVE ,
405 ADDITION_COST_TO_CLEAR ,
406 COST ,
407 DEPRN_ADJUSTMENT_AMOUNT ,
408 REVAL_AMORTIZATION ,
409 REVAL_DEPRN_EXPENSE ,
410 REVAL_RESERVE ,
411 YTD_REVAL_DEPRN_EXPENSE ,
412 BONUS_DEPRN_AMOUNT ,
413 BONUS_YTD_DEPRN ,
414 BONUS_DEPRN_RESERVE ,
415 BONUS_DEPRN_ADJUSTMENT_AMOUNT ,
416 IMPAIRMENT_AMOUNT ,
417 YTD_IMPAIRMENT ,
418 IMPAIRMENT_RESERVE ,
419 CAPITAL_ADJUSTMENT ,
420 GENERAL_FUND ,
421 EVENT_ID ,
422 DEPRN_RUN_ID ,
423 REVERSAL_EVENT_ID ,
424 REVERSAL_DATE )
425 select BOOK_TYPE_CODE ,
426 ASSET_ID ,
427 PERIOD_COUNTER ,
428 DISTRIBUTION_ID ,
429 DEPRN_SOURCE_CODE ,
430 DEPRN_RUN_DATE ,
431 DEPRN_AMOUNT ,
432 YTD_DEPRN ,
433 DEPRN_RESERVE ,
434 ADDITION_COST_TO_CLEAR ,
435 COST ,
436 DEPRN_ADJUSTMENT_AMOUNT ,
437 REVAL_AMORTIZATION ,
438 REVAL_DEPRN_EXPENSE ,
439 REVAL_RESERVE ,
440 YTD_REVAL_DEPRN_EXPENSE ,
441 BONUS_DEPRN_AMOUNT ,
442 BONUS_YTD_DEPRN ,
443 BONUS_DEPRN_RESERVE ,
444 BONUS_DEPRN_ADJUSTMENT_AMOUNT ,
445 IMPAIRMENT_AMOUNT ,
446 YTD_IMPAIRMENT ,
447 IMPAIRMENT_RESERVE ,
448 CAPITAL_ADJUSTMENT ,
449 GENERAL_FUND ,
450 EVENT_ID ,
451 DEPRN_RUN_ID ,
452 P_REVERSAL_EVENT_ID ,
453 P_REVERSAL_DATE
454 from fa_deprn_detail ds
455 where ds.book_type_code = p_asset_hdr_rec.book_type_code
456 and ds.asset_id = p_asset_hdr_rec.asset_id
457 and ds.period_counter = p_period_rec.period_counter
458 and ds.deprn_source_code in ('D','T');
459
460 -- flag the header table too
461 update fa_deprn_events
462 set reversal_event_id = P_REVERSAL_EVENT_ID,
463 reversal_date = p_reversal_date
464 where asset_id = p_asset_hdr_rec.asset_id
465 and book_type_code = p_asset_hdr_rec.book_type_code
466 and period_counter = p_period_rec.period_counter
467 and deprn_run_id = p_deprn_run_id;
468
469 end if;
470 else -- event was not final -0 need to delete the dpern event
471 delete from fa_deprn_events
472 where asset_id = p_asset_hdr_rec.asset_id
473 and book_type_code = p_asset_hdr_rec.book_type_code
474 and period_counter = p_period_rec.period_counter
475 and reversal_event_id is null;
476 end if;
477
478 -- now continue with main processing
479
480
481 if not fa_cache_pkg.fazcct(X_calendar => fa_cache_pkg.fazcbc_record.deprn_calendar
482 ,p_log_level_rec => p_log_level_rec) then
483 raise rb_error;
484 end if;
485
486 -- Bug:5701095
487 pers_per_yr := fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR;
488
489 -- Bug:6665510:Japan Tax Reform Project
490 l_batch_size := nvl(fa_cache_pkg.fa_batch_size, 200);
491
492 -- Bug# 3798413: Reset adjusted_cost back to the original adjusted_cost
493 -- for the addition transaction.
494 -- For period of addition transaction, we are getting the value
495 -- from fa_deprn_summary's BOOKS row
496 -- since Adj API also sets adjusted_cost in BOOKS' row to the latest value
497 -- before depreciation correctly.
498 --
499 -- BUG# 4094166
500 -- also update eofy_reserve and limit update to make
501 -- sure this is period of addition only
502
503 if (p_mrc_sob_type_code = 'R') then
504
505 -- Bug:5701095
506 update fa_mc_books bk
507 set (adjusted_cost, eofy_reserve, formula_factor, adjusted_capacity) =
508 (Select Decode(p_period_rec.period_num - pers_per_yr,
509 0, decode(bk2.eofy_adj_cost,
510 null, decode(bk2.eop_adj_cost,
511 null, decode(ds1.asset_id,
512 null, bk2.adjusted_cost,
513 ds1.adjusted_cost),
514 bk2.eop_adj_cost),
515 bk2.eofy_adj_cost),
516 decode(bk2.eop_adj_cost,
517 null, decode(ds1.asset_id,
518 null, bk2.adjusted_cost,
519 ds1.adjusted_cost),
520 Decode(ds1.deprn_source_code,
521 'DEPRN', bk2.eop_adj_cost,
522 decode(ds1.asset_id,
523 null, bk2.adjusted_cost,
524 ds1.adjusted_cost)))
525 ),
526 Decode(ds2.deprn_source_code,
527 'BOOKS', nvl(bk2.prior_eofy_reserve, bk2.eofy_reserve),
528 decode(p_period_rec.period_num - pers_per_yr,
529 0, decode(bk2.prior_eofy_reserve,
530 null, bk2.eofy_reserve,
531 bk2.prior_eofy_reserve),
532 bk2.eofy_reserve)),
533 Decode(p_period_rec.period_num - pers_per_yr,
534 0, decode(bk2.eofy_adj_cost,
535 null, decode(bk2.eop_adj_cost,
536 null, bk2.formula_factor,
537 bk2.eop_formula_factor),
538 bk2.eofy_formula_factor),
539 decode(bk2.eop_adj_cost,
540 null, bk2.formula_factor,
541 bk2.eop_formula_factor)),
542 Decode(bk2.eop_adj_cost,
543 null, bk2.adjusted_capacity,
544 bk2.old_adjusted_capacity)
545 From fa_mc_deprn_summary ds2, fa_mc_deprn_summary ds1, fa_mc_books bk2
546 where bk2.transaction_header_id_in = bk.transaction_header_id_in
547 and bk2.set_of_books_id = p_asset_hdr_rec.set_of_books_id
548 and ds2.asset_id(+) = bk2.asset_id
549 and ds2.book_type_code(+) = bk2.book_type_code
550 and ds2.period_counter(+) = (p_period_rec.period_counter - 1)
551 and ds2.set_of_books_id(+) = p_asset_hdr_rec.set_of_books_id
552 and ds1.asset_id (+) = bk2.asset_id
553 and ds1.book_type_code (+) = bk2.book_type_code
554 and ds1.period_counter (+) = (p_period_rec.period_counter)
555 and ds1.set_of_books_id (+) = p_asset_hdr_rec.set_of_books_id
556 ),
557 eop_adj_cost = NULL,
558 eop_formula_factor = NULL,
559 eofy_adj_cost = Decode(p_period_rec.period_num - pers_per_yr,
560 0, NULL,
561 eofy_adj_cost),
562 eofy_formula_factor = Decode(p_period_rec.period_num - pers_per_yr,
563 0, NULL,
564 eofy_formula_factor),
565 prior_eofy_reserve = Decode(p_period_rec.period_num - pers_per_yr,
566 0, NULL,
567 prior_eofy_reserve),
568 period_counter_fully_reserved = Decode(period_counter_fully_reserved,
569 p_period_rec.period_counter,
570 Null,
571 period_counter_fully_reserved),
572 period_counter_life_complete = Decode(period_counter_life_complete,
573 p_period_rec.period_counter,
574 Null,
575 period_counter_life_complete)
576 where asset_id = p_asset_hdr_rec.asset_id -- Bug:6778581
577 and book_type_code = p_asset_hdr_rec.book_type_code
578 and transaction_header_id_out is null
579 and set_of_books_id = p_asset_hdr_rec.set_of_books_id
580 ;
581
582 else -- if (p_mrc_sob_type_code = 'R') then
583
584 -- Bug:5701095
585 update fa_books bk
586 set (adjusted_cost, eofy_reserve, formula_factor, adjusted_capacity) =
587 (Select Decode(p_period_rec.period_num - pers_per_yr,
588 0, decode(bk2.eofy_adj_cost,
589 null, decode(bk2.eop_adj_cost,
590 null, decode(ds1.asset_id,
591 null, bk2.adjusted_cost,
592 ds1.adjusted_cost),
593 bk2.eop_adj_cost),
594 bk2.eofy_adj_cost),
595 decode(bk2.eop_adj_cost,
596 null, decode(ds1.asset_id,
597 null, bk2.adjusted_cost,
598 ds1.adjusted_cost),
599 decode(ds1.deprn_source_code,
600 'DEPRN', bk2.eop_adj_cost,
601 decode(ds1.asset_id,
602 null, bk2.adjusted_cost,
603 ds1.adjusted_cost)))
604 ),
605 Decode(ds2.deprn_source_code,
606 'BOOKS', nvl(bk2.prior_eofy_reserve, bk2.eofy_reserve),
607 decode(p_period_rec.period_num - pers_per_yr,
608 0, decode(bk2.prior_eofy_reserve,
609 null, bk2.eofy_reserve,
610 bk2.prior_eofy_reserve),
611 bk2.eofy_reserve)),
612 Decode(p_period_rec.period_num - pers_per_yr,
613 0, decode(bk2.eofy_adj_cost,
614 null, decode(bk2.eop_adj_cost,
615 null, bk2.formula_factor,
616 bk2.eop_formula_factor),
617 bk2.eofy_formula_factor),
618 decode(bk2.eop_adj_cost,
619 null, bk2.formula_factor,
620 bk2.eop_formula_factor)),
621 Decode(bk2.eop_adj_cost,
622 null, bk2.adjusted_capacity,
623 bk2.old_adjusted_capacity)
624 From fa_deprn_summary ds2, fa_deprn_summary ds1, fa_books bk2
625 where bk2.transaction_header_id_in = bk.transaction_header_id_in
626 and ds2.asset_id(+) = bk2.asset_id
627 and ds2.book_type_code(+) = bk2.book_type_code
628 and ds2.period_counter(+) = (p_period_rec.period_counter - 1)
629 and ds1.asset_id (+) = bk2.asset_id
630 and ds1.book_type_code (+) = bk2.book_type_code
631 and ds1.period_counter (+) = (p_period_rec.period_counter)),
632 eop_adj_cost = NULL,
633 eop_formula_factor = NULL,
634 eofy_adj_cost = Decode(p_period_rec.period_num - pers_per_yr,
635 0, NULL,
636 eofy_adj_cost),
637 eofy_formula_factor = Decode(p_period_rec.period_num - pers_per_yr,
638 0, NULL,
639 eofy_formula_factor),
640 prior_eofy_reserve = Decode(p_period_rec.period_num - pers_per_yr,
641 0, NULL,
642 prior_eofy_reserve),
643 period_counter_fully_reserved = Decode(period_counter_fully_reserved,
644 p_period_rec.period_counter,
645 Null,
646 period_counter_fully_reserved),
647 period_counter_life_complete = Decode(period_counter_life_complete,
648 p_period_rec.period_counter,
649 Null,
650 period_counter_life_complete),
651 period_counter_fully_extended = Decode(period_counter_fully_extended, -- Bug:13711833
652 p_period_rec.period_counter,
653 Null,
654 period_counter_fully_extended)
655 where asset_id = p_asset_hdr_rec.asset_id -- Bug:6778581
656 and book_type_code = p_asset_hdr_rec.book_type_code
657 and transaction_header_id_out is null;
658 end if; -- if (p_mrc_sob_type_code = 'R') then
659
660 -- delete from DS
661
662 if (p_mrc_sob_type_code = 'R') then
663 delete
664 from fa_mc_deprn_summary ds
665 where ds.asset_id = p_asset_hdr_rec.asset_id
666 and ds.book_type_code = p_asset_hdr_rec.book_type_code
667 and ds.period_counter = p_period_rec.period_counter
668 and ds.deprn_source_code in ('DEPRN','TRACK')
669 and ds.set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
670 else
671 delete
672 from fa_deprn_summary ds
673 where ds.asset_id = p_asset_hdr_rec.asset_id
674 and ds.book_type_code = p_asset_hdr_rec.book_type_code
675 and ds.period_counter = p_period_rec.period_counter
676 and ds.deprn_source_code in ('DEPRN','TRACK');
677 end if;
678
679
680 -- delete from DD
681
682 if (p_mrc_sob_type_code = 'R') then
683 delete
684 from fa_mc_deprn_detail dd
685 where dd.asset_id = p_asset_hdr_rec.asset_id
686 and dd.book_type_code = p_asset_hdr_rec.book_type_code
687 and dd.period_counter = p_period_rec.period_counter
688 and dd.deprn_source_code in ('D','T')
689 and dd.set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
690 else
691 delete
692 from fa_deprn_detail dd
693 where dd.asset_id = p_asset_hdr_rec.asset_id
694 and dd.book_type_code = p_asset_hdr_rec.book_type_code
695 and dd.period_counter = p_period_rec.period_counter
696 and dd.deprn_source_code in ('D','T');
697 end if;
698
699 -- Delete from FA_BOOKS_SUMMARY
700
701 if (p_log_level_rec.statement_level) then
702 fa_debug_pkg.add(l_calling_fn,
703 'Deleting FA_BOOKS_SUMMARY rows, next period ctr',
704 p_period_rec.period_counter + 1
705 ,p_log_level_rec => p_log_level_rec);
706 end if;
707
708 if (p_mrc_sob_type_code = 'R') then
709
710 delete from fa_mc_books_summary bs
711 where bs.asset_id = p_asset_hdr_rec.asset_id
712 and bs.book_type_code = p_asset_hdr_rec.book_type_code
713 and bs.period_counter = p_period_rec.period_counter + 1
714 and bs.set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
715
716 update fa_mc_books_summary bs
717 set deprn_amount = expense_adjustment_amount,
718 ytd_deprn = ytd_deprn - nvl(deprn_amount,0) + nvl(expense_adjustment_amount,0), --Bug8244128
719 deprn_reserve = deprn_reserve - nvl(deprn_amount,0) + nvl(expense_adjustment_amount,0), --Bug8244128
720 bonus_deprn_amount = 0,
721 bonus_ytd_deprn = bonus_ytd_deprn - bonus_deprn_amount,
722 bonus_deprn_reserve = bonus_deprn_reserve - bonus_deprn_amount,
723 bonus_rate = 0,
724 ltd_production = ltd_production - production,
725 ytd_production = ytd_production - production,
726 production = 0,
727 reval_deprn_expense = 0,
728 reval_reserve = reval_reserve - reval_deprn_expense,
729 ytd_reval_deprn_expense = ytd_reval_deprn_expense - reval_deprn_expense
730 where bs.asset_id = p_asset_hdr_rec.asset_id
731 and bs.book_type_code = p_asset_hdr_rec.book_type_code
732 and bs.period_counter = p_period_rec.period_counter
733 and bs.set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
734
735 else
736
737 delete from fa_books_summary bs
738 where bs.asset_id = p_asset_hdr_rec.asset_id
739 and bs.book_type_code = p_asset_hdr_rec.book_type_code
740 and bs.period_counter = p_period_rec.period_counter + 1;
741
742 update fa_books_summary bs
743 set deprn_amount = expense_adjustment_amount,
744 ytd_deprn = ytd_deprn - nvl(deprn_amount,0) + nvl(expense_adjustment_amount,0), --Bug8244128
745 deprn_reserve = deprn_reserve - nvl(deprn_amount,0) + nvl(expense_adjustment_amount,0), --Bug8244128
746 bonus_deprn_amount = 0,
747 bonus_ytd_deprn = bonus_ytd_deprn - bonus_deprn_amount,
748 bonus_deprn_reserve = bonus_deprn_reserve - bonus_deprn_amount,
749 bonus_rate = 0,
750 ltd_production = ltd_production - production,
751 ytd_production = ytd_production - production,
752 production = 0,
753 reval_deprn_expense = 0,
754 reval_reserve = reval_reserve - reval_deprn_expense,
755 ytd_reval_deprn_expense = ytd_reval_deprn_expense - reval_deprn_expense
756 where bs.asset_id = p_asset_hdr_rec.asset_id
757 and bs.book_type_code = p_asset_hdr_rec.book_type_code
758 and bs.period_counter = p_period_rec.period_counter;
759
760 end if;
761
762 -- rollback/reverse terminal gain loss
763 -- pending new api / logic
764
765 if (p_log_level_rec.statement_level) then
766 fa_debug_pkg.add(l_calling_fn, 'BEGIN', 'Processing terminal gain loss'
767 ,p_log_level_rec => p_log_level_rec);
768 end if;
769
770 open c_get_thid;
771 fetch c_get_thid into l_thid, l_event_id;
772 close c_get_thid;
773
774 if (p_log_level_rec.statement_level) then
775 fa_debug_pkg.add(l_calling_fn, 'THID of TGL', l_thid
776 ,p_log_level_rec => p_log_level_rec);
777 end if;
778 /* Bug#9018861 - set global variable for reporting currency */
779 if p_mrc_sob_type_code <> 'R' then
780 g_l_thid := l_thid;
781 else
782 l_thid := g_l_thid;
783 end if;
784 if (l_thid is not null ) then
785 if (p_log_level_rec.statement_level) then
786 fa_debug_pkg.add(l_calling_fn, 'event id', l_event_id
787 ,p_log_level_rec => p_log_level_rec);
788 fa_debug_pkg.add(l_calling_fn, 'sob type code', p_mrc_sob_type_code
789 ,p_log_level_rec => p_log_level_rec);
790 end if;
791 /*=================================================================
792 Secondary Changes Start
793 If primary and secondary sob_id is different then we need to
794 create/update/delete event for secondary ledger*/
795 if p_mrc_sob_type_code = 'R' then
796 open c_get_sec_event_id(l_thid);
797 fetch c_get_sec_event_id into l_secondary_event_id;
798 close c_get_sec_event_id ;
799
800 if(l_secondary_event_id is not null)then
801
802 if (p_log_level_rec.statement_level) then
803 fa_debug_pkg.add(l_calling_fn, 'calling get event status for event ', l_event_id
804 ,p_log_level_rec => p_log_level_rec);
805 end if;
806
807 l_deprn_source_info.application_id := 140;
808 l_deprn_source_info.ledger_id := p_asset_hdr_rec.set_of_books_id;
809
810 --
811 -- Old thid or new thid?
812 --
813 l_deprn_source_info.source_id_int_1 := l_thid;
814 l_deprn_source_info.entity_type_code := 'TRANSACTIONS';
815 l_deprn_source_info.transaction_number := to_char(l_thid);
816 l_deprn_source_info.source_id_char_1 := p_asset_hdr_rec.book_type_code;
817
818 -- check the event status
819 l_secondary_event_status := XLA_EVENTS_PUB_PKG.get_event_status
820 (p_event_source_info => l_deprn_source_info,
821 p_event_id => l_secondary_event_id,
822 p_valuation_method => p_asset_hdr_rec.book_type_code,
823 p_security_context => l_security_context);
824
825 if (p_log_level_rec.statement_level) then
826 fa_debug_pkg.add(l_calling_fn, 'event status ', l_secondary_event_status
827 ,p_log_level_rec => p_log_level_rec);
828 end if;
829
830 if (l_secondary_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_PROCESSED) then
831
832 open c_get_new_thid;
833 fetch c_get_new_thid into l_secondary_trans_rec.transaction_header_id
834 , l_secondary_trans_rec.who_info.last_update_date;
835 close c_get_new_thid;
836 l_secondary_trans_rec.transaction_subtype := 'AMORTIZED';
837 l_secondary_trans_rec.transaction_type_code := 'ADJUSTMENT';
838 l_secondary_trans_rec.transaction_key := 'TG';
839 l_secondary_trans_rec.transaction_date_entered := greatest(p_period_rec.calendar_period_open_date,
840 least(sysdate,p_period_rec.calendar_period_close_date));
841 l_secondary_trans_rec.amortization_start_date := l_trans_rec.transaction_date_entered;
842 l_secondary_trans_rec.calling_interface := 'FAXDRB';
843
844 l_asset_type_rec.asset_type := 'GROUP';
845
846 if not FA_XLA_EVENTS_PVT.create_transaction_event(
847 p_asset_hdr_rec => p_asset_hdr_rec,
848 p_asset_type_rec => l_asset_type_rec,
849 px_trans_rec => l_secondary_trans_rec,
850 p_event_status => NULL,
851 p_calling_fn => l_calling_fn
852 ,p_log_level_rec => p_log_level_rec) then
853 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling create_transaction_event'
854 ,p_log_level_rec => p_log_level_rec);
855 raise rb_error;
856 end if;
857 elsif (l_secondary_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED) then
858 XLA_EVENTS_PUB_PKG.delete_event
859 (p_event_source_info => l_deprn_source_info,
860 p_event_id => l_secondary_event_id,
861 p_valuation_method => p_asset_hdr_rec.book_type_code,
862 p_security_context => l_security_context);
863
864 --6702657
865 BEGIN
866 l_result := XLA_EVENTS_PUB_PKG.delete_entity
867 (p_source_info => l_deprn_source_info,
868 p_valuation_method => p_asset_hdr_rec.book_type_code,
869 p_security_context => l_security_context);
870
871 EXCEPTION
872 WHEN OTHERS THEN
873 l_result := 1;
874 fa_debug_pkg.add(l_calling_fn, 'Unable to delete entity for rb event',
875 l_event_id, p_log_level_rec => p_log_level_rec);
876 fa_debug_pkg.add(l_calling_fn, 'l_result', l_result, p_log_level_rec => p_log_level_rec);
877 END; --annonymous
878 end if;
879 end if;
880 end if;
881 /*Secondary Changes End
882 ==================================================================*/
883 if (l_event_id is not null) then
884 if (p_log_level_rec.statement_level) then
885 fa_debug_pkg.add(l_calling_fn, 'calling get event status for event ', l_event_id
886 ,p_log_level_rec => p_log_level_rec);
887 end if;
888
889 l_deprn_source_info.application_id := 140;
890 l_deprn_source_info.ledger_id := p_asset_hdr_rec.set_of_books_id;
891
892 --
893 -- Old thid or new thid?
894 --
895 l_deprn_source_info.source_id_int_1 := l_thid;
896 l_deprn_source_info.entity_type_code := 'TRANSACTIONS';
897 l_deprn_source_info.transaction_number := to_char(l_thid);
898 l_deprn_source_info.source_id_char_1 := p_asset_hdr_rec.book_type_code;
899
900 -- check the event status
901 l_event_status := XLA_EVENTS_PUB_PKG.get_event_status
902 (p_event_source_info => l_deprn_source_info,
903 p_event_id => l_event_id,
904 p_valuation_method => p_asset_hdr_rec.book_type_code,
905 p_security_context => l_security_context);
906
907 if (p_log_level_rec.statement_level) then
908 fa_debug_pkg.add(l_calling_fn, 'event status ', l_event_status
909 ,p_log_level_rec => p_log_level_rec);
910 end if;
911
912 end if;
913
914 if (l_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_PROCESSED) then
915 -- Reverse Terminal Gain Loss
916
917 if (p_mrc_sob_type_code <> 'R') then
918 SELECT fa_transaction_headers_s.nextval
919 INTO l_trans_rec.transaction_header_id
920 FROM DUAL;
921
922 --
923 -- Populating for calling FA_XLA_EVENTS_PVT.create_transaction_event
924 --
925 l_trans_rec.transaction_subtype := 'AMORTIZED';
926 l_trans_rec.transaction_type_code := 'ADJUSTMENT';
927 l_trans_rec.transaction_key := 'TG';
928 l_trans_rec.transaction_date_entered := greatest(p_period_rec.calendar_period_open_date,
929 least(sysdate,p_period_rec.calendar_period_close_date));
930 l_trans_rec.amortization_start_date := l_trans_rec.transaction_date_entered;
931 l_trans_rec.calling_interface := 'FAXDRB';
932
933 l_asset_type_rec.asset_type := 'GROUP';
934
935 if not FA_XLA_EVENTS_PVT.create_transaction_event(
936 p_asset_hdr_rec => p_asset_hdr_rec,
937 p_asset_type_rec => l_asset_type_rec,
938 px_trans_rec => l_trans_rec,
939 p_event_status => NULL,
940 p_calling_fn => l_calling_fn
941 ,p_log_level_rec => p_log_level_rec) then
942 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling create_transaction_event'
943 ,p_log_level_rec => p_log_level_rec);
944 raise rb_error;
945 end if;
946
947 INSERT INTO FA_TRANSACTION_HEADERS(
948 TRANSACTION_HEADER_ID
949 , BOOK_TYPE_CODE
950 , ASSET_ID
951 , TRANSACTION_TYPE_CODE
952 , TRANSACTION_DATE_ENTERED
953 , DATE_EFFECTIVE
954 , LAST_UPDATE_DATE
955 , LAST_UPDATED_BY
956 , TRANSACTION_NAME
957 , INVOICE_TRANSACTION_ID
958 , SOURCE_TRANSACTION_HEADER_ID
959 , MASS_REFERENCE_ID
960 , LAST_UPDATE_LOGIN
961 , TRANSACTION_SUBTYPE
962 , ATTRIBUTE1
963 , ATTRIBUTE2
964 , ATTRIBUTE3
965 , ATTRIBUTE4
966 , ATTRIBUTE5
967 , ATTRIBUTE6
968 , ATTRIBUTE7
969 , ATTRIBUTE8
970 , ATTRIBUTE9
971 , ATTRIBUTE10
972 , ATTRIBUTE11
973 , ATTRIBUTE12
974 , ATTRIBUTE13
975 , ATTRIBUTE14
976 , ATTRIBUTE15
977 , ATTRIBUTE_CATEGORY_CODE
978 , TRANSACTION_KEY
979 , AMORTIZATION_START_DATE
980 , CALLING_INTERFACE
981 , MASS_TRANSACTION_ID
982 , MEMBER_TRANSACTION_HEADER_ID
983 , TRX_REFERENCE_ID
984 , EVENT_ID
985 ) select
986 l_trans_rec.transaction_header_id --TRANSACTION_HEADER_ID
987 , BOOK_TYPE_CODE
988 , ASSET_ID
989 , TRANSACTION_TYPE_CODE
990 , TRANSACTION_DATE_ENTERED
991 , p_reversal_date -- DATE_EFFECTIVE
992 , p_reversal_date -- LAST_UPDATE_DATE
993 , l_trans_rec.who_info.last_updated_by
994 , TRANSACTION_NAME
995 , INVOICE_TRANSACTION_ID
996 , SOURCE_TRANSACTION_HEADER_ID
997 , MASS_REFERENCE_ID
998 , LAST_UPDATE_LOGIN
999 , TRANSACTION_SUBTYPE
1000 , ATTRIBUTE1
1001 , ATTRIBUTE2
1002 , ATTRIBUTE3
1003 , ATTRIBUTE4
1004 , ATTRIBUTE5
1005 , ATTRIBUTE6
1006 , ATTRIBUTE7
1007 , ATTRIBUTE8
1008 , ATTRIBUTE9
1009 , ATTRIBUTE10
1010 , ATTRIBUTE11
1011 , ATTRIBUTE12
1012 , ATTRIBUTE13
1013 , ATTRIBUTE14
1014 , ATTRIBUTE15
1015 , ATTRIBUTE_CATEGORY_CODE
1016 , TRANSACTION_KEY
1017 , AMORTIZATION_START_DATE
1018 , 'FAXDRB' -- CALLING_INTERFACE
1019 , MASS_TRANSACTION_ID
1020 , MEMBER_TRANSACTION_HEADER_ID
1021 , TRX_REFERENCE_ID
1022 , l_trans_rec.event_id -- EVENT_ID
1023 from fa_transaction_headers
1024 where asset_id = p_asset_hdr_rec.asset_id
1025 and book_type_code = p_asset_hdr_rec.book_type_code
1026 and transaction_header_id = l_thid
1027 ;
1028
1029 INSERT INTO FA_ADJUSTMENTS(
1030 TRANSACTION_HEADER_ID
1031 , SOURCE_TYPE_CODE
1032 , ADJUSTMENT_TYPE
1033 , DEBIT_CREDIT_FLAG
1034 , CODE_COMBINATION_ID
1035 , BOOK_TYPE_CODE
1036 , ASSET_ID
1037 , ADJUSTMENT_AMOUNT
1038 , DISTRIBUTION_ID
1039 , LAST_UPDATE_DATE
1040 , LAST_UPDATED_BY
1041 , LAST_UPDATE_LOGIN
1042 , ANNUALIZED_ADJUSTMENT
1043 , PERIOD_COUNTER_ADJUSTED
1044 , PERIOD_COUNTER_CREATED
1045 , ASSET_INVOICE_ID
1046 , GLOBAL_ATTRIBUTE1
1047 , GLOBAL_ATTRIBUTE2
1048 , GLOBAL_ATTRIBUTE3
1049 , GLOBAL_ATTRIBUTE4
1050 , GLOBAL_ATTRIBUTE5
1051 , GLOBAL_ATTRIBUTE6
1052 , GLOBAL_ATTRIBUTE7
1053 , GLOBAL_ATTRIBUTE8
1054 , GLOBAL_ATTRIBUTE9
1055 , GLOBAL_ATTRIBUTE10
1056 , GLOBAL_ATTRIBUTE11
1057 , GLOBAL_ATTRIBUTE12
1058 , GLOBAL_ATTRIBUTE13
1059 , GLOBAL_ATTRIBUTE14
1060 , GLOBAL_ATTRIBUTE15
1061 , GLOBAL_ATTRIBUTE16
1062 , GLOBAL_ATTRIBUTE17
1063 , GLOBAL_ATTRIBUTE18
1064 , GLOBAL_ATTRIBUTE19
1065 , GLOBAL_ATTRIBUTE20
1066 , GLOBAL_ATTRIBUTE_CATEGORY
1067 , DEPRN_OVERRIDE_FLAG
1068 , TRACK_MEMBER_FLAG
1069 , ADJUSTMENT_LINE_ID
1070 , SOURCE_LINE_ID
1071 , SOURCE_DEST_CODE
1072 ) select
1073 l_trans_rec.transaction_header_id -- TRANSACTION_HEADER_ID
1074 , SOURCE_TYPE_CODE
1075 , ADJUSTMENT_TYPE
1076 , decode(debit_credit_flag, 'DR', 'CR', 'DR') --DEBIT_CREDIT_FLAG
1077 , CODE_COMBINATION_ID
1078 , BOOK_TYPE_CODE
1079 , ASSET_ID
1080 , ADJUSTMENT_AMOUNT
1081 , DISTRIBUTION_ID
1082 , p_reversal_date --LAST_UPDATE_DATE
1083 , l_trans_rec.who_info.last_updated_by --LAST_UPDATED_BY
1084 , l_trans_rec.who_info.last_update_login --LAST_UPDATE_LOGIN
1085 , ANNUALIZED_ADJUSTMENT
1086 , PERIOD_COUNTER_ADJUSTED
1087 , PERIOD_COUNTER_CREATED
1088 , ASSET_INVOICE_ID
1089 , GLOBAL_ATTRIBUTE1
1090 , GLOBAL_ATTRIBUTE2
1091 , GLOBAL_ATTRIBUTE3
1092 , GLOBAL_ATTRIBUTE4
1093 , GLOBAL_ATTRIBUTE5
1094 , GLOBAL_ATTRIBUTE6
1095 , GLOBAL_ATTRIBUTE7
1096 , GLOBAL_ATTRIBUTE8
1097 , GLOBAL_ATTRIBUTE9
1098 , GLOBAL_ATTRIBUTE10
1099 , GLOBAL_ATTRIBUTE11
1100 , GLOBAL_ATTRIBUTE12
1101 , GLOBAL_ATTRIBUTE13
1102 , GLOBAL_ATTRIBUTE14
1103 , GLOBAL_ATTRIBUTE15
1104 , GLOBAL_ATTRIBUTE16
1105 , GLOBAL_ATTRIBUTE17
1106 , GLOBAL_ATTRIBUTE18
1107 , GLOBAL_ATTRIBUTE19
1108 , GLOBAL_ATTRIBUTE20
1109 , GLOBAL_ATTRIBUTE_CATEGORY
1110 , DEPRN_OVERRIDE_FLAG
1111 , TRACK_MEMBER_FLAG
1112 , fa_adjustments_s.nextval -- ADJUSTMENT_LINE_ID
1113 , SOURCE_LINE_ID
1114 , SOURCE_DEST_CODE
1115 from fa_adjustments
1116 where asset_id = p_asset_hdr_rec.asset_id
1117 and book_type_code = p_asset_hdr_rec.book_type_code
1118 and transaction_header_id = l_thid
1119 ;
1120
1121 else -- Reporting book
1122 open c_get_new_thid;
1123 fetch c_get_new_thid into l_trans_rec.transaction_header_id
1124 , l_trans_rec.who_info.last_update_date;
1125 close c_get_new_thid;
1126
1127 INSERT INTO FA_MC_ADJUSTMENTS(
1128 SET_OF_BOOKS_ID
1129 , TRANSACTION_HEADER_ID
1130 , SOURCE_TYPE_CODE
1131 , ADJUSTMENT_TYPE
1132 , DEBIT_CREDIT_FLAG
1133 , CODE_COMBINATION_ID
1134 , BOOK_TYPE_CODE
1135 , ASSET_ID
1136 , ADJUSTMENT_AMOUNT
1137 , DISTRIBUTION_ID
1138 , LAST_UPDATE_DATE
1139 , LAST_UPDATED_BY
1140 , LAST_UPDATE_LOGIN
1141 , ANNUALIZED_ADJUSTMENT
1142 , PERIOD_COUNTER_ADJUSTED
1143 , PERIOD_COUNTER_CREATED
1144 , ASSET_INVOICE_ID
1145 , GLOBAL_ATTRIBUTE1
1146 , GLOBAL_ATTRIBUTE2
1147 , GLOBAL_ATTRIBUTE3
1148 , GLOBAL_ATTRIBUTE4
1149 , GLOBAL_ATTRIBUTE5
1150 , GLOBAL_ATTRIBUTE6
1151 , GLOBAL_ATTRIBUTE7
1152 , GLOBAL_ATTRIBUTE8
1153 , GLOBAL_ATTRIBUTE9
1154 , GLOBAL_ATTRIBUTE10
1155 , GLOBAL_ATTRIBUTE11
1156 , GLOBAL_ATTRIBUTE12
1157 , GLOBAL_ATTRIBUTE13
1158 , GLOBAL_ATTRIBUTE14
1159 , GLOBAL_ATTRIBUTE15
1160 , GLOBAL_ATTRIBUTE16
1161 , GLOBAL_ATTRIBUTE17
1162 , GLOBAL_ATTRIBUTE18
1163 , GLOBAL_ATTRIBUTE19
1164 , GLOBAL_ATTRIBUTE20
1165 , GLOBAL_ATTRIBUTE_CATEGORY
1166 , DEPRN_OVERRIDE_FLAG
1167 , TRACK_MEMBER_FLAG
1168 , ADJUSTMENT_LINE_ID
1169 , SOURCE_LINE_ID
1170 , SOURCE_DEST_CODE
1171 ) select
1172 SET_OF_BOOKS_ID
1173 , l_trans_rec.transaction_header_id -- TRANSACTION_HEADER_ID
1174 , SOURCE_TYPE_CODE
1175 , ADJUSTMENT_TYPE
1176 , decode(debit_credit_flag, 'DR', 'CR', 'DR') --DEBIT_CREDIT_FLAG
1177 , CODE_COMBINATION_ID
1178 , BOOK_TYPE_CODE
1179 , ASSET_ID
1180 , ADJUSTMENT_AMOUNT
1181 , DISTRIBUTION_ID
1182 , l_trans_rec.who_info.last_update_date --LAST_UPDATE_DATE
1183 , l_trans_rec.who_info.last_updated_by --LAST_UPDATED_BY
1184 , l_trans_rec.who_info.last_update_login --LAST_UPDATE_LOGIN
1185 , ANNUALIZED_ADJUSTMENT
1186 , PERIOD_COUNTER_ADJUSTED
1187 , PERIOD_COUNTER_CREATED
1188 , ASSET_INVOICE_ID
1189 , GLOBAL_ATTRIBUTE1
1190 , GLOBAL_ATTRIBUTE2
1191 , GLOBAL_ATTRIBUTE3
1192 , GLOBAL_ATTRIBUTE4
1193 , GLOBAL_ATTRIBUTE5
1194 , GLOBAL_ATTRIBUTE6
1195 , GLOBAL_ATTRIBUTE7
1196 , GLOBAL_ATTRIBUTE8
1197 , GLOBAL_ATTRIBUTE9
1198 , GLOBAL_ATTRIBUTE10
1199 , GLOBAL_ATTRIBUTE11
1200 , GLOBAL_ATTRIBUTE12
1201 , GLOBAL_ATTRIBUTE13
1202 , GLOBAL_ATTRIBUTE14
1203 , GLOBAL_ATTRIBUTE15
1204 , GLOBAL_ATTRIBUTE16
1205 , GLOBAL_ATTRIBUTE17
1206 , GLOBAL_ATTRIBUTE18
1207 , GLOBAL_ATTRIBUTE19
1208 , GLOBAL_ATTRIBUTE20
1209 , GLOBAL_ATTRIBUTE_CATEGORY
1210 , DEPRN_OVERRIDE_FLAG
1211 , TRACK_MEMBER_FLAG
1212 , fa_adjustments_s.nextval -- ADJUSTMENT_LINE_ID
1213 , SOURCE_LINE_ID
1214 , SOURCE_DEST_CODE
1215 from fa_mc_adjustments
1216 where asset_id = p_asset_hdr_rec.asset_id
1217 and book_type_code = p_asset_hdr_rec.book_type_code
1218 and transaction_header_id = l_thid
1219 and set_of_books_id = p_asset_hdr_rec.set_of_books_id
1220 ;
1221
1222 end if; -- (p_mrc_sob_type_code <> 'R')
1223
1224 fa_books_pkg.deactivate_row
1225 (X_asset_id => p_asset_hdr_rec.asset_id,
1226 X_book_type_code => p_asset_hdr_rec.book_type_code,
1227 X_transaction_header_id_out => l_trans_rec.transaction_header_id,
1228 X_date_ineffective => l_trans_rec.who_info.last_update_date,
1229 X_mrc_sob_type_code => p_mrc_sob_type_code,
1230 X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
1231 X_Calling_Fn => l_calling_fn
1232 ,p_log_level_rec => p_log_level_rec);
1233
1234 fa_books_pkg.insert_row
1235 (X_Rowid => l_bks_rowid,
1236 X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
1237 X_Asset_Id => p_asset_hdr_rec.asset_id,
1238 X_Date_Placed_In_Service => l_asset_fin_rec.date_placed_in_service,
1239 X_Date_Effective => l_trans_rec.who_info.last_update_date,
1240 X_Deprn_Start_Date => l_asset_fin_rec.deprn_start_date,
1241 X_Deprn_Method_Code => l_asset_fin_rec.deprn_method_code,
1242 X_Life_In_Months => l_asset_fin_rec.life_in_months,
1243 X_Rate_Adjustment_Factor => l_asset_fin_rec.rate_adjustment_factor,
1244 X_Adjusted_Cost => l_asset_fin_rec.adjusted_cost,
1245 X_Cost => l_asset_fin_rec.cost,
1246 X_Original_Cost => l_asset_fin_rec.original_cost,
1247 X_Salvage_Value => l_asset_fin_rec.salvage_value,
1248 X_Prorate_Convention_Code => l_asset_fin_rec.prorate_convention_code,
1249 X_Prorate_Date => l_asset_fin_rec.prorate_date,
1250 X_Cost_Change_Flag => l_asset_fin_rec.cost_change_flag,
1251 X_Adjustment_Required_Status => l_asset_fin_rec.adjustment_required_status,
1252 X_Capitalize_Flag => l_asset_fin_rec.capitalize_flag,
1253 X_Retirement_Pending_Flag => l_asset_fin_rec.retirement_pending_flag,
1254 X_Depreciate_Flag => l_asset_fin_rec.depreciate_flag,
1255 X_Disabled_Flag => l_asset_fin_rec.disabled_flag, --HH
1256 X_Last_Update_Date => l_trans_rec.who_info.last_update_date,
1257 X_Last_Updated_By => l_trans_rec.who_info.last_updated_by,
1258 X_Date_Ineffective => NULL,
1259 X_Transaction_Header_Id_In => l_trans_rec.transaction_header_id,
1260 X_Transaction_Header_Id_Out => NULL,
1261 X_Itc_Amount_Id => l_asset_fin_rec.itc_amount_id,
1262 X_Itc_Amount => l_asset_fin_rec.itc_amount,
1263 X_Retirement_Id => l_asset_fin_rec.retirement_id,
1264 X_Tax_Request_Id => l_asset_fin_rec.tax_request_id,
1265 X_Itc_Basis => l_asset_fin_rec.itc_basis,
1266 X_Basic_Rate => l_asset_fin_rec.basic_rate,
1267 X_Adjusted_Rate => l_asset_fin_rec.adjusted_rate,
1268 X_Bonus_Rule => l_asset_fin_rec.bonus_rule,
1269 X_Ceiling_Name => l_asset_fin_rec.ceiling_name,
1270 X_Recoverable_Cost => l_asset_fin_rec.recoverable_cost,
1271 X_Last_Update_Login => l_trans_rec.who_info.last_update_login,
1272 X_Adjusted_Capacity => l_asset_fin_rec.adjusted_capacity,
1273 X_Fully_Rsvd_Revals_Counter => l_asset_fin_rec.fully_rsvd_revals_counter,
1274 X_Idled_Flag => l_asset_fin_rec.idled_flag,
1275 X_Period_Counter_Capitalized => l_asset_fin_rec.period_counter_capitalized,
1276 X_PC_Fully_Reserved => l_asset_fin_rec.period_counter_fully_reserved,
1277 X_Period_Counter_Fully_Retired => l_asset_fin_rec.period_counter_fully_retired,
1278 X_Production_Capacity => l_asset_fin_rec.production_capacity,
1279 X_Reval_Amortization_Basis => l_asset_fin_rec.reval_amortization_basis,
1280 X_Reval_Ceiling => l_asset_fin_rec.reval_ceiling,
1281 X_Unit_Of_Measure => l_asset_fin_rec.unit_of_measure,
1282 X_Unrevalued_Cost => l_asset_fin_rec.unrevalued_cost,
1283 X_Annual_Deprn_Rounding_Flag => l_asset_fin_rec.annual_deprn_rounding_flag,
1284 X_Percent_Salvage_Value => l_asset_fin_rec.percent_salvage_value,
1285 X_Allowed_Deprn_Limit => l_asset_fin_rec.allowed_deprn_limit,
1286 X_Allowed_Deprn_Limit_Amount => l_asset_fin_rec.allowed_deprn_limit_amount,
1287 X_Period_Counter_Life_Complete => l_asset_fin_rec.period_counter_life_complete,
1288 X_Adjusted_Recoverable_Cost => l_asset_fin_rec.adjusted_recoverable_cost,
1289 X_Short_Fiscal_Year_Flag => l_asset_fin_rec.short_fiscal_year_flag,
1290 X_Conversion_Date => l_asset_fin_rec.conversion_date,
1291 X_Orig_Deprn_Start_Date => l_asset_fin_rec.orig_deprn_start_date,
1292 X_Remaining_Life1 => l_asset_fin_rec.remaining_life1,
1293 X_Remaining_Life2 => l_asset_fin_rec.remaining_life2,
1294 X_Old_Adj_Cost => l_asset_fin_rec.old_adjusted_cost,
1295 X_Formula_Factor => l_asset_fin_rec.formula_factor,
1296 X_gf_Attribute1 => l_asset_fin_rec.global_attribute1,
1297 X_gf_Attribute2 => l_asset_fin_rec.global_attribute2,
1298 X_gf_Attribute3 => l_asset_fin_rec.global_attribute3,
1299 X_gf_Attribute4 => l_asset_fin_rec.global_attribute4,
1300 X_gf_Attribute5 => l_asset_fin_rec.global_attribute5,
1301 X_gf_Attribute6 => l_asset_fin_rec.global_attribute6,
1302 X_gf_Attribute7 => l_asset_fin_rec.global_attribute7,
1303 X_gf_Attribute8 => l_asset_fin_rec.global_attribute8,
1304 X_gf_Attribute9 => l_asset_fin_rec.global_attribute9,
1305 X_gf_Attribute10 => l_asset_fin_rec.global_attribute10,
1306 X_gf_Attribute11 => l_asset_fin_rec.global_attribute11,
1307 X_gf_Attribute12 => l_asset_fin_rec.global_attribute12,
1308 X_gf_Attribute13 => l_asset_fin_rec.global_attribute13,
1309 X_gf_Attribute14 => l_asset_fin_rec.global_attribute14,
1310 X_gf_Attribute15 => l_asset_fin_rec.global_attribute15,
1311 X_gf_Attribute16 => l_asset_fin_rec.global_attribute16,
1312 X_gf_Attribute17 => l_asset_fin_rec.global_attribute17,
1313 X_gf_Attribute18 => l_asset_fin_rec.global_attribute18,
1314 X_gf_Attribute19 => l_asset_fin_rec.global_attribute19,
1315 X_gf_Attribute20 => l_asset_fin_rec.global_attribute20,
1316 X_global_attribute_category => l_asset_fin_rec.global_attribute_category,
1317 X_group_asset_id => l_asset_fin_rec.group_asset_id,
1318 X_salvage_type => l_asset_fin_rec.salvage_type,
1319 X_deprn_limit_type => l_asset_fin_rec.deprn_limit_type,
1320 X_over_depreciate_option => l_asset_fin_rec.over_depreciate_option,
1321 X_super_group_id => l_asset_fin_rec.super_group_id,
1322 X_reduction_rate => l_asset_fin_rec.reduction_rate,
1323 X_reduce_addition_flag => l_asset_fin_rec.reduce_addition_flag,
1324 X_reduce_adjustment_flag => l_asset_fin_rec.reduce_adjustment_flag,
1325 X_reduce_retirement_flag => l_asset_fin_rec.reduce_retirement_flag,
1326 X_recognize_gain_loss => l_asset_fin_rec.recognize_gain_loss,
1327 X_recapture_reserve_flag => l_asset_fin_rec.recapture_reserve_flag,
1328 X_limit_proceeds_flag => l_asset_fin_rec.limit_proceeds_flag,
1329 X_terminal_gain_loss => l_asset_fin_rec.terminal_gain_loss,
1330 X_exclude_proceeds_from_basis => l_asset_fin_rec.exclude_proceeds_from_basis,
1331 X_retirement_deprn_option => l_asset_fin_rec.retirement_deprn_option,
1332 X_tracking_method => l_asset_fin_rec.tracking_method,
1333 X_allocate_to_fully_rsv_flag => l_asset_fin_rec.allocate_to_fully_rsv_flag,
1334 X_allocate_to_fully_ret_flag => l_asset_fin_rec.allocate_to_fully_ret_flag,
1335 X_exclude_fully_rsv_flag => l_asset_fin_rec.exclude_fully_rsv_flag,
1336 X_excess_allocation_option => l_asset_fin_rec.excess_allocation_option,
1337 X_depreciation_option => l_asset_fin_rec.depreciation_option,
1338 X_member_rollup_flag => l_asset_fin_rec.member_rollup_flag,
1339 X_ytd_proceeds => l_asset_fin_rec.ytd_proceeds,
1340 X_ltd_proceeds => l_asset_fin_rec.ltd_proceeds,
1341 X_eofy_reserve => l_asset_fin_rec.eofy_reserve,
1342 X_cip_cost => l_asset_fin_rec.cip_cost,
1343 X_terminal_gain_loss_amount => null,
1344 X_terminal_gain_loss_flag => 'Y',
1345 X_ltd_cost_of_removal => l_asset_fin_rec.ltd_cost_of_removal,
1346 X_mrc_sob_type_code => p_mrc_sob_type_code,
1347 X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
1348 X_Return_Status => l_status,
1349 X_Calling_Fn => l_calling_fn
1350 ,p_log_level_rec => p_log_level_rec);
1351
1352 if not l_status then
1353 fa_debug_pkg.add(l_calling_fn, 'Failed to insert ', 'FA_BOOKS'
1354 ,p_log_level_rec => p_log_level_rec);
1355 raise rb_error;
1356 end if;
1357 /* Bug#9018861 - Modified condition for reporting currency */
1358 elsif (l_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED OR p_mrc_sob_type_code = 'R' ) then
1359
1360 if (p_log_level_rec.statement_level) then
1361 fa_debug_pkg.add(l_calling_fn, 'deleting event', l_event_id
1362 ,p_log_level_rec => p_log_level_rec);
1363 end if;
1364 /* Bug#9018861 - Null means already deleted for primary book */
1365 if p_mrc_sob_type_code <> 'R' then
1366 XLA_EVENTS_PUB_PKG.delete_event
1367 (p_event_source_info => l_deprn_source_info,
1368 p_event_id => l_event_id,
1369 p_valuation_method => p_asset_hdr_rec.book_type_code,
1370 p_security_context => l_security_context);
1371
1372 --6702657
1373 BEGIN
1374 l_result := XLA_EVENTS_PUB_PKG.delete_entity
1375 (p_source_info => l_deprn_source_info,
1376 p_valuation_method => p_asset_hdr_rec.book_type_code,
1377 p_security_context => l_security_context);
1378
1379 EXCEPTION
1380 WHEN OTHERS THEN
1381 l_result := 1;
1382 fa_debug_pkg.add(l_calling_fn, 'Unable to delete entity for rb event',
1383 l_event_id, p_log_level_rec => p_log_level_rec);
1384 fa_debug_pkg.add(l_calling_fn, 'l_result', l_result, p_log_level_rec => p_log_level_rec);
1385 END; --annonymous
1386 end if;
1387 -- Rollback Terminal Gain Loss
1388 if (p_mrc_sob_type_code <> 'R') then
1389 delete from fa_transaction_headers
1390 where transaction_header_id = l_thid;
1391
1392 delete from fa_adjustments
1393 where asset_id = p_asset_hdr_rec.asset_id
1394 and book_type_code = p_asset_hdr_rec.book_type_code
1395 and transaction_header_id = l_thid;
1396
1397 delete from fa_books
1398 where asset_id = p_asset_hdr_rec.asset_id
1399 and book_type_code = p_asset_hdr_rec.book_type_code
1400 and transaction_header_id_in = l_thid;
1401
1402 update fa_books
1403 set transaction_header_id_out = null,
1404 date_ineffective = null
1405 where asset_id = p_asset_hdr_rec.asset_id
1406 and book_type_code = p_asset_hdr_rec.book_type_code
1407 and transaction_header_id_out = l_thid;
1408
1409 else
1410
1411 delete from fa_mc_adjustments
1412 where asset_id = p_asset_hdr_rec.asset_id
1413 and book_type_code = p_asset_hdr_rec.book_type_code
1414 and transaction_header_id = g_l_thid
1415 and set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
1416
1417 delete from fa_mc_books
1418 where asset_id = p_asset_hdr_rec.asset_id
1419 and book_type_code = p_asset_hdr_rec.book_type_code
1420 and transaction_header_id_in = g_l_thid
1421 and set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
1422
1423 update fa_mc_books
1424 set transaction_header_id_out = null,
1425 date_ineffective = null
1426 where asset_id = p_asset_hdr_rec.asset_id
1427 and book_type_code = p_asset_hdr_rec.book_type_code
1428 and transaction_header_id_out = g_l_thid
1429 and set_of_books_id = p_asset_hdr_rec.set_of_books_id ;
1430
1431 end if; -- (p_mrc_sob_type_code <> 'R')
1432
1433 else
1434 raise rb_error;
1435 end if; -- (l_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_PROCESSED)
1436
1437 -- Common for both situations (reverse, delete)
1438 if (p_mrc_sob_type_code <> 'R') then
1439 update fa_books_summary
1440 set terminal_gain_loss_flag = 'Y',
1441 terminal_gain_loss_amount = null,
1442 reserve_adjustment_amount = reserve_adjustment_amount - terminal_gain_loss_amount,
1443 deprn_reserve = deprn_reserve - terminal_gain_loss_amount,
1444 last_update_date = l_trans_rec.who_info.last_update_date,
1445 last_update_login = l_trans_rec.who_info.last_update_login,
1446 last_updated_by = l_trans_rec.who_info.last_updated_by
1447 where book_type_code = p_asset_hdr_rec.book_type_code
1448 and asset_id = p_asset_hdr_rec.asset_id
1449 and period_counter = p_period_rec.period_counter;
1450 else
1451 update fa_mc_books_summary
1452 set terminal_gain_loss_flag = 'Y',
1453 terminal_gain_loss_amount = null,
1454 reserve_adjustment_amount = reserve_adjustment_amount - terminal_gain_loss_amount,
1455 deprn_reserve = deprn_reserve - terminal_gain_loss_amount,
1456 last_update_date = l_trans_rec.who_info.last_update_date,
1457 last_update_login = l_trans_rec.who_info.last_update_login,
1458 last_updated_by = l_trans_rec.who_info.last_updated_by
1459 where book_type_code = p_asset_hdr_rec.book_type_code
1460 and asset_id = p_asset_hdr_rec.asset_id
1461 and period_counter = p_period_rec.period_counter
1462 and set_of_books_id = p_asset_hdr_rec.set_of_books_id;
1463 end if;
1464
1465 end if; -- l_thid is not null)
1466
1467 -- End of terminal gain loss
1468
1469 -- Bug:6665510:Japan Tax Reform Project
1470 if (p_log_level_rec.statement_level) then
1471 fa_debug_pkg.add('FAVDRBB', 'guarantee_flag', fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag);
1472 fa_debug_pkg.add('FAVDRBB', 'period_num', p_period_rec.period_num);
1473 fa_debug_pkg.add('FAVDRBB', 'pers_per_yr', pers_per_yr);
1474 end if;
1475
1476 if ((p_period_rec.period_num - pers_per_yr) = 0) and
1477 (nvl(fnd_profile.value('FA_JAPAN_TAX_REFORMS'),'N') = 'Y') then
1478
1479 if (p_log_level_rec.statement_level) then
1480 fa_debug_pkg.add('Updating rate_in_use', 'EOFY', 'YES');
1481 end if;
1482
1483 if (p_mrc_sob_type_code = 'R') then
1484 Null;
1485 else
1486 open c_rate_in_use;
1487 end if;
1488
1489 loop
1490 if (p_mrc_sob_type_code = 'R') then
1491 exit; -- Bug 9012515
1492 else
1493
1494 fetch c_rate_in_use bulk collect
1495 into l_bks_rowid_tbl2,
1496 l_asset_id_tbl2,
1497 l_method_code_tbl2,
1498 l_life_in_months_tbl2
1499 LIMIT l_batch_size;
1500
1501 l_rows_processed := l_bks_rowid_tbl2.count;
1502
1503 if l_rows_processed = 0 then
1504 exit;
1505 end if;
1506
1507 if (p_log_level_rec.statement_level) then
1508 fa_debug_pkg.add('FAVDRBB', 'l_bks_rowid_tbl2.count', l_bks_rowid_tbl2.count);
1509 end if;
1510
1511 for i in 1..l_bks_rowid_tbl2.count loop
1512
1513 if (p_log_level_rec.statement_level) then
1514 fa_debug_pkg.add('FAVDRBB', 'l_asset_id_tbl2(i)', l_asset_id_tbl2(i));
1515 fa_debug_pkg.add('FAVDRBB', 'l_method_code_tbl2(i)', l_method_code_tbl2(i));
1516 end if;
1517
1518 FA_CDE_PKG.faxgfr (X_Book_Type_Code => p_asset_hdr_rec.book_type_code,
1519 X_Asset_Id => l_asset_id_tbl2(i),
1520 X_Short_Fiscal_Year_Flag => NULL,
1521 X_Conversion_Date => NULL,
1522 X_Prorate_Date => NULL,
1523 X_Orig_Deprn_Start_Date => NULL,
1524 C_Prorate_Date => NULL,
1525 C_Conversion_Date => NULL,
1526 C_Orig_Deprn_Start_Date => NULL,
1527 X_Method_Code => l_method_code_tbl2(i),
1528 X_Life_In_Months => l_life_in_months_tbl2(i),
1529 X_Fiscal_Year => -99,
1530 X_Current_Period => -99,
1531 X_calling_interface => 'ROLLBACK_DEPRN',
1532 X_Rate => l_rate_in_use_tbl(i),
1533 X_Method_Type => l_method_type,
1534 X_Success => l_success);
1535
1536 if (l_success <= 0) then
1537 fa_srvr_msg.add_message(calling_fn => 'FA_DEPRN_ROLLBACK_PKG.do_rollback');
1538 raise rb_error;
1539 end if;
1540 end loop;
1541
1542 fa_debug_pkg.add('FAVDRBB', 'update fa_books.rate_in_use', l_bks_rowid_tbl2.count);
1543
1544 forall i IN 1..l_bks_rowid_tbl2.count
1545 update fa_books
1546 set rate_in_use = l_rate_in_use_tbl(i)
1547 where rowid = l_bks_rowid_tbl2(i);
1548 end if;
1549 end loop;
1550
1551 if (p_mrc_sob_type_code = 'R') then
1552 Null;
1553 else
1554 close c_rate_in_use;
1555 end if;
1556 end if;
1557 -- Bug:6665510:Japan Tax Reform Project (End)
1558
1559 -- updates to adj_req_status should be obseolete at this point
1560 -- since deprn will not catchup
1561
1562 -- BUG# 2238090
1563 -- reset the periodic production amounts for primary only
1564 -- bridgway 02/25/02
1565
1566 if (p_mrc_sob_type_code <> 'R') then
1567
1568 update fa_periodic_production pp
1569 set used_flag = 'NO'
1570 where pp.asset_id = p_asset_hdr_rec.asset_id
1571 and pp.book_type_code = p_asset_hdr_rec.book_type_code
1572 and pp.start_date >= p_period_rec.calendar_period_open_date
1573 and pp.end_date <= p_period_rec.calendar_period_close_date;
1574
1575 -- Manual Override
1576
1577 fa_std_types.deprn_override_trigger_enabled:= FALSE;
1578
1579 update FA_DEPRN_OVERRIDE do
1580 set status = 'POST'
1581 where do.asset_id = p_asset_hdr_rec.asset_id
1582 and do.book_type_code = p_asset_hdr_rec.book_type_code
1583 and do.period_name = p_period_rec.period_name
1584 and do.used_by = 'DEPRECIATION'
1585 and do.status = 'POSTED';
1586
1587 fa_std_types.deprn_override_trigger_enabled:= TRUE;
1588
1589 -- End of Manual Override
1590
1591 end if;
1592
1593 -- ER 14644811: Check for any Period End Revaluation
1594 if (p_mrc_sob_type_code <> 'R') then
1595
1596 -- We need only the latest PDR as others would already have been rolled back
1597 open c_get_pdr_thid;
1598 fetch c_get_pdr_thid into g_pdr_thid, l_pdr_event_id;
1599 g_pdr_found := c_get_pdr_thid%FOUND;
1600 close c_get_pdr_thid;
1601
1602 end if;
1603
1604 if ((g_pdr_found) and (g_pdr_thid is not null)) then
1605 -- Call the rollback reval engine
1606 if not fa_revaluation_pvt.rollback_reval (p_asset_hdr_rec,
1607 g_pdr_thid,
1608 l_pdr_event_id,
1609 p_mrc_sob_type_code,
1610 l_calling_fn,
1611 p_log_level_rec) then
1612 raise rb_error;
1613 end if;
1614 end if;
1615 -- ER 14644811 End
1616
1617 return TRUE;
1618
1619 EXCEPTION
1620 when rb_error then
1621 fa_srvr_msg.add_message(calling_fn => l_calling_fn
1622 ,p_log_level_rec => p_log_level_rec);
1623 return FALSE;
1624
1625 when others then
1626 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
1627 ,p_log_level_rec => p_log_level_rec);
1628 return FALSE;
1629
1630 end do_rollback;
1631
1632 END FA_DEPRN_ROLLBACK_PVT;