DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_GAINLOSS_DPR_PKG

Source


1 PACKAGE BODY FA_GAINLOSS_DPR_PKG AS
2 /* $Header: fagdprb.pls 120.14.12010000.1 2008/07/28 13:21:46 appldev ship $*/
3 
4 
5 FUNCTION fagcrsv(dpr            fa_STD_TYPES.dpr_struct,
6                  d_cal          varchar2,
7                  p_cal          varchar2,
8                  x_last_period  out nocopy boolean,
9                  p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) return boolean is
10 
11 l_pds_in_last_yr          integer;
12 l_lst_pd_ctr              integer;
13 l_y_dp_begin              integer;
14 l_rate_pers_per_yr        integer;
15 l_pers_per_yr             number;
16 l_lst_fy                  integer;  -- last fiscal year
17 l_lst_per                 integer;  -- last period of life
18 l_prorate                 integer;
19 dummynum                  number;
20 l_count                   number;
21 l_fy_name                 varchar2(30); -- BUG 5179236
22 l_cur_pdctr               number;
23 
24 fagcrsv_err  exception;
25 
26 begin
27 
28     x_last_period := FALSE;
29     l_cur_pdctr := fa_cache_pkg.fazcdp_record.period_counter;
30 
31     l_fy_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
32     if not fa_cache_pkg.fazccp (p_cal, l_fy_name,
33                 dpr.prorate_jdate, l_prorate, l_y_dp_begin, dummynum) then
34         return (FALSE);
35     end if;
36 
37     if not fa_cache_pkg.fazcct (d_cal) then
38         return (FALSE);
39     end if;
40     l_pers_per_yr := fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR;
41 
42     if not fa_cache_pkg.fazcct (p_cal) then
43         return (FALSE);
44     end if;
45     l_rate_pers_per_yr := fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR;
46 
47     l_lst_per :=  l_prorate - 2 +
48       mod(floor(dpr.life * l_rate_pers_per_yr/12),l_rate_pers_per_yr) +1 ;
49 
50     l_lst_fy := (l_y_dp_begin + floor ((dpr.life - 1) / 12));
51 
52     if l_lst_per <  l_prorate then
53        l_lst_fy := l_lst_fy + 1;
54     end if;
55 
56     l_pds_in_last_yr :=
57         ceil ( l_pers_per_yr * l_lst_per  / l_rate_pers_per_yr );
58     l_lst_pd_ctr :=  l_lst_fy * l_pers_per_yr + l_pds_in_last_yr;
59 
60     if l_lst_pd_ctr = l_cur_pdctr then
61        x_last_period := TRUE;
62     end if;
63 
64     return TRUE;
65 
66 exception
67 when fagcrsv_err then
68      fa_srvr_msg.add_message(
69                calling_fn => 'fa_gainloss_dpr_pkg.fagcrsv');
70       return(FALSE);
71 end;
72 
73 
74 
75 
76 /*============================================================================
77 | NAME		fagcdp						     	     |
78 |									     |
79 | FUNCTION 	Calculates depreciation needed given a range of period       |
80 |									     |
81 | RETURN VALUES	- deprn_rate_ptr    : Depreciation taken per period	     |
82 |									     |
83 | HISTORY	1/12/89		R Rumanang	Created			     |
84 |               6/23/89         R RUmanang      Standarized                  |
85 |               5/1/90          R Rumanang      Fill in dpr->calendar_type   |
86 |		04/12/91	M Chan		Modified for MPL 9           |
87 |		01/04/97	S Behura	Rewrote in PL/SQL	     |
88 |		08/10/97	S Behura	Rewrote in PL/SQL (10.7)     |
89 |============================================================================*/
90 
91 FUNCTION fagcdp (dpr in out nocopy fa_std_types.dpr_struct,
92 		deprn_amt in out nocopy number,
93 		bonus_deprn_amt in out nocopy number,
94 		 reval_deprn_amt in out nocopy number, reval_amort in out number,
95 		 deprn_start_date in out nocopy date, d_cal in out varchar2,
96                  p_cal in out nocopy varchar2, v_start number, v_end number,
97                  prorate_fy number, dsd_fy number, prorate_jdate number,
98 		 deprn_start_jdate number,
99 		 retirement_id number default null,
100 		 p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
101 
102     fagcdp_err		exception;
103 
104     dummy		fa_std_types.dpr_arr_type;
105     dpr_out		fa_std_types.dpr_out_struct;
106     l_last_period       boolean;
107 
108     -- Added for bug 6003600
109     l_life_end_date         date;
110     l_pcal_life_end_date    date;
111     l_pcal_ret_end_date     date;
112     l_pers_per_yr           number;
113     -- End bug fix 6003600
114 	--Bug6679173
115 	l_transaction_header_id_in number;
116 	l_transaction_header_id_out number;
117 
118 	Cursor c_get_trxn_id is
119 	select	transaction_header_id_in,transaction_header_id_out
120 	from	fa_retirements
121 	where	book_type_code=dpr.book
122 	and	asset_id=dpr.asset_id
123 	and	retirement_id=retirement_id;
124 
125 	l_rate_change_flag varchar2(1);
126 
127 	Cursor c_rate_change_flag is
128 	select 'Y'
129 	from	fa_books fbks1,
130 		fa_books fbks2
131 	where	fbks1.book_type_code = dpr.book
132 	and	fbks1.asset_id = dpr.asset_id
133 	and	fbks2.book_type_code = fbks1.book_type_code
134 	and	fbks2.asset_id = fbks2.asset_id
135 	and	fbks1.transaction_header_id_in between l_transaction_header_id_in and nvl(l_transaction_header_id_out,l_transaction_header_id_in)
136 	and	fbks2.transaction_header_id_in between l_transaction_header_id_in and nvl(l_transaction_header_id_out,l_transaction_header_id_in)
137 	and	fbks2.transaction_header_id_in = fbks1.transaction_header_id_out
138 	and	fbks2.adjusted_rate <> fbks1.adjusted_rate ;
139 
140 	l_adjusted_rate1 number;
141 	l_adjusted_rate2 number;
142 	l_deprn_method_code1 varchar2(48);
143 	l_transaction_id1 number;
144 	l_transaction_id2 number;
145 	l_deprn_method_code2 varchar2(48);
146 	Cursor c_rate_details is
147 	select	fbks1.adjusted_rate,fbks1.transaction_header_id_in,fbks1.deprn_method_code,
148 		fbks2.adjusted_rate,fbks2.transaction_header_id_in,fbks2.deprn_method_code
149 	from	fa_books fbks1,
150 		fa_books fbks2
151 	where	fbks1.book_type_code=dpr.book
152 	and	fbks1.asset_id=dpr.asset_id
153 	and	fbks2.book_type_code =fbks1.book_type_code
154 	and	fbks2.asset_id =fbks2.asset_id
155 	and	fbks1.transaction_header_id_in between l_transaction_header_id_in and l_transaction_header_id_out
156 	and	fbks2.transaction_header_id_in between l_transaction_header_id_in and l_transaction_header_id_out
157 	and	fbks2.transaction_header_id_in = fbks1.transaction_header_id_out
158 	and	fbks2.adjusted_rate <> fbks1.adjusted_rate;
159 
160 
161 
162 	l_prd_num number;
163 	l_count number;
164 	l_end_prd_num number;
165 
166 	Cursor c_get_period_details(x_transaction_id number) is
167 	select fdp.period_num
168 	from	fa_transaction_headers fth,
169 		fa_deprn_periods fdp
170 	where	fth.transaction_header_id= x_transaction_id
171 	and	fdp.book_type_code = dpr.book
172 	and	fth.transaction_date_entered
173 		between fdp.calendar_period_open_date and nvl(fdp.calendar_period_close_date,sysdate);
174     BEGIN <<FAGCDP>>
175 
176        dpr.deprn_start_jdate := deprn_start_jdate;
177 
178        if (prorate_fy <> dsd_fy) then
179           dpr.deprn_start_jdate := prorate_jdate;
180        end if;
181 
182        if v_start = 0 then -- If start is zero, calculate the whole deprn
183        	     dpr.p_cl_begin := 1;
184         /* It is O.K. to assign 1 to dpr->p_cl_begin, because the deprn
185            engine is smart enough to skip over periods before the deprn
186            start period */
187        else
188 	     dpr.p_cl_begin := v_start;
189        end if;
190 
191        dpr.p_cl_end := v_end;
192 
193        --Bug6679173
194        --Added the following code
195        if not fa_cache_pkg.fazcct (d_cal) then
196           return (FALSE);
197        end if;
198 
199 	   IF retirement_id is null then
200 		if not FA_CDE_PKG.faxcde(dpr, dummy, dpr_out,
201 		fa_std_types.FA_DPR_NORMAL) then
202 
203 	       fa_srvr_msg.add_message(
204                calling_fn => 'fa_gainloss_dpr_pkg.fagcdp',
205                name       => 'FA_RET_DEPRN_ERROR',
206                token1     => 'MODULE',
207                value1     => 'FAXCDE',
208                p_log_level_rec => p_log_level_rec);
209 
210 		raise fagcdp_err;
211 
212 		end if;
213 		deprn_amt := dpr_out.deprn_exp;
214 		bonus_deprn_amt := dpr_out.bonus_deprn_exp;
215 		reval_deprn_amt := dpr_out.reval_exp;
216 		reval_amort := dpr_out.reval_amo;
217 	   else
218 		   open c_get_trxn_id;
219 		   fetch c_get_trxn_id into l_transaction_header_id_in,l_transaction_header_id_out;
220 			open c_rate_change_flag;
221 			fetch c_rate_change_flag into l_rate_change_flag;
222 			if c_rate_change_flag%NOTFOUND then
223 				l_rate_change_flag := 'N';
224 			end if;
225 			close c_rate_change_flag;
226 			if l_rate_change_flag = 'N' then
227 				if not FA_CDE_PKG.faxcde(dpr, dummy, dpr_out,
228 						fa_std_types.FA_DPR_NORMAL) then
229 
230 					fa_srvr_msg.add_message(
231 				       calling_fn => 'fa_gainloss_dpr_pkg.fagcdp',
232 				       name       => 'FA_RET_DEPRN_ERROR',
233 				       token1     => 'MODULE',
234 				       value1     => 'FAXCDE',
235 				       p_log_level_rec => p_log_level_rec);
236 
237 				     raise fagcdp_err;
238 
239 				end if;
240 				deprn_amt := dpr_out.deprn_exp;
241 				bonus_deprn_amt := dpr_out.bonus_deprn_exp;
242 				reval_deprn_amt := dpr_out.reval_exp;
243 				reval_amort := dpr_out.reval_amo;
244 			else
245 				l_end_prd_num := dpr.p_cl_end;
246 				open c_rate_details;
247 				l_count := 1;
248 				loop
249 					fetch c_rate_details into l_adjusted_rate1,l_transaction_id1,l_deprn_method_code1,
250 					l_adjusted_rate2,l_transaction_id2,l_deprn_method_code2;
251 					exit when c_rate_details%NOTFOUND;
252 					open c_get_period_details(l_transaction_id2);
253 					fetch c_get_period_details into l_prd_num;
254 					if l_count > 1 then
255 						dpr.p_cl_begin := dpr.p_cl_end + 1;
256 						dpr.p_cl_end := l_prd_num - 1;
257 
258 					else
259 						dpr.p_cl_end := l_prd_num - 1;
260 					end if;
261 					dpr.adj_rate := l_adjusted_rate1;
262 					dpr.method_code := l_deprn_method_code1;
263 
264 
265 					if not FA_CDE_PKG.faxcde(dpr, dummy, dpr_out,
266 							fa_std_types.FA_DPR_NORMAL) then
267 
268 						fa_srvr_msg.add_message(
269 					       calling_fn => 'fa_gainloss_dpr_pkg.fagcdp',
270 					       name       => 'FA_RET_DEPRN_ERROR',
271 					       token1     => 'MODULE',
272 					       value1     => 'FAXCDE',
273 					       p_log_level_rec => p_log_level_rec);
274 
275 					     raise fagcdp_err;
276 
277 					end if;
278 					deprn_amt := nvl(deprn_amt,0) + dpr_out.deprn_exp;
279 					bonus_deprn_amt := nvl(bonus_deprn_amt,0) + dpr_out.bonus_deprn_exp;
280 					reval_deprn_amt := nvl(reval_deprn_amt,0) + dpr_out.reval_exp;
281 					reval_amort := nvl(reval_amort,0) + dpr_out.reval_amo;
282 
283 					close c_get_period_details;
284 					l_count := l_count +1;
285 				end loop;
286 				close c_rate_details;
287 				dpr.p_cl_begin := dpr.p_cl_end + 1;
288 				dpr.p_cl_end := l_end_prd_num;
289 				dpr.adj_rate := l_adjusted_rate2;
290 				dpr.method_code := l_deprn_method_code2;
291 
292 				if not FA_CDE_PKG.faxcde(dpr, dummy, dpr_out,
293 							fa_std_types.FA_DPR_NORMAL) then
294 
295 					       fa_srvr_msg.add_message(
296 					       calling_fn => 'fa_gainloss_dpr_pkg.fagcdp',
297 					       name       => 'FA_RET_DEPRN_ERROR',
298 					       token1     => 'MODULE',
299 					       value1     => 'FAXCDE',
300 					       p_log_level_rec => p_log_level_rec);
301 
302 					     raise fagcdp_err;
303 				end if;
304 				deprn_amt := deprn_amt + dpr_out.deprn_exp;
305 				bonus_deprn_amt := bonus_deprn_amt + dpr_out.bonus_deprn_exp;
306 				reval_deprn_amt := reval_deprn_amt + dpr_out.reval_exp;
307 				reval_amort := reval_amort + dpr_out.reval_amo;
308 			end if;
309 		 close c_get_trxn_id;
310 	      end if;
311 	   --Bug6679173 ends
312 
313        if not fa_cache_pkg.fazccmt
314             (X_method                => dpr.method_code,
315              X_life                  => dpr.life
316               ) then
317         raise fagcdp_err;
318        end if;
319 
320        if (fa_cache_pkg.fazccmt_record.rate_source_rule  = 'CALCULATED') then
321           if not fagcrsv(dpr   => dpr,
322                       d_cal => d_cal,
323                       p_cal => p_cal,
324                       x_last_period  => l_last_period) then
325            raise fagcdp_err;
326           end if;
327 
328          -- Bug fix 6003600 (Added code to determine whether retirement is performed in last period
329 	  -- of asset's life as per prorate calendar or not and accordingly calculated deprn_amt for daily prorate calendar)
330 	 if l_last_period then
331 
332             if not fa_cache_pkg.fazcct (p_cal) then
333                return (FALSE);
334             end if;
335 
336 	    l_pers_per_yr := fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR;
337 
338             fa_debug_pkg.add ('FAGDCP', 'l_pers_per_yr', l_pers_per_yr);
339 
340             if l_pers_per_yr <> 365 then
341                deprn_amt := dpr.adj_rec_cost - dpr.deprn_rsv;
342             else
343 	       fa_debug_pkg.add ('FAGDCP', 'deprn_amt', deprn_amt);
344                fa_debug_pkg.add ('FAGDCP', 'dpr.prorate_date', dpr.prorate_date);
345                fa_debug_pkg.add ('FAGDCP', 'dpr.ret_prorate_jdate', dpr.ret_prorate_jdate);
346 
347                l_life_end_date := add_months(dpr.prorate_date,dpr.life);
348 
349                select end_date
350                into l_pcal_life_end_date
351                from fa_calendar_periods
352                where calendar_type = p_cal
353                and l_life_end_date between start_date and end_date;
354 
355                select end_date
356                into l_pcal_ret_end_date
357                from fa_calendar_periods
358                where calendar_type = p_cal
359                and to_date(dpr.ret_prorate_jdate,'j') between start_date and end_date;
360 
361                if (l_pcal_life_end_date <= l_pcal_ret_end_date) then
362                   deprn_amt := dpr.adj_rec_cost - dpr.deprn_rsv;
363 	       end if;  -- if (l_pcal_life_end_date <= l_pcal_ret_end_date) then
364 
365 	       fa_debug_pkg.add ('FAGDCP', 'l_life_end_date', l_life_end_date);
366                fa_debug_pkg.add ('FAGDCP', 'l_pcal_life_end_date', l_pcal_life_end_date);
367                fa_debug_pkg.add ('FAGDCP', 'l_pcal_ret_end_date', l_pcal_ret_end_date);
368 	       fa_debug_pkg.add ('FAGDCP', 'deprn_amt', deprn_amt);
369 
370 	    end if;  -- if p_pers_per_yr <> 365 then
371 
372 	 end if; -- if l_last_period then
373          -- End of bug fix 6003600
374 
375        end if;
376 
377        return(TRUE);
378 
379        EXCEPTION
380 
381           when fagcdp_err then
382 
383              fa_srvr_msg.add_message(
384                calling_fn => 'fa_gainloss_dpr_pkg.fagcdp',
385               	 p_log_level_rec => p_log_level_rec);
386 
387              return(FALSE);
388 
389     END FAGCDP;
390 
391 /*============================================================================
392 | NAME          CALC_CATCHUP                                                 |
393 |                                                                            |
394 | FUNCTION      Calculates depreciation needed given a range of period       |
395 |                                                                            |
396 |                                                                            |
397 |============================================================================*/
398 FUNCTION CALC_CATCHUP(
399    ret                             FA_RET_TYPES.RET_STRUCT,
400    BK                              FA_RET_TYPES.BOOK_STRUCT,
401    DPR                             FA_STD_TYPES.DPR_STRUCT,
402    calc_catchup                    BOOLEAN,
403    x_deprn_exp          OUT NOCOPY NUMBER,
404    x_bonus_deprn_exp    OUT NOCOPY NUMBER,
405    x_asset_fin_rec_new  OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
406    p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
407 
408    l_calling_fn        VARCHAR2(50) := 'FA_GAINLOSS_DPR_PKG.CALC_CATCHUP';
409 
410    CURSOR c_get_rein_thid IS
411       select nvl(transaction_header_id_out, transaction_header_id_in) -- Bug# 5074257
412       from   fa_retirements
413       where  retirement_id = ret.retirement_id;
414 
415 
416    CURSOR c_get_trans_rec(c_thid number) IS
417       select transaction_type_code
418            , transaction_date_entered
419            , transaction_name
420            , source_transaction_header_id
421            , mass_reference_id
422            , transaction_subtype
423            , transaction_key
424            , amortization_start_date
425            , calling_interface
426            , mass_transaction_id
427            , fa_std_types.FA_NO_OVERRIDE
428            , member_transaction_header_id
429            , trx_reference_id
430       from fa_transaction_headers
431       where transaction_header_id = c_thid;
432 
433    CURSOR c_get_ret_amounts IS
434       select outbk.salvage_value - inbk.salvage_value
435            , nvl(outbk.allowed_deprn_limit_amount, 0) -
436              nvl(inbk.allowed_deprn_limit_amount, 0),
437              outbk.unrevalued_cost - inbk.unrevalued_cost
438       from   fa_books inbk
439            , fa_books outbk
440       where  inbk.transaction_header_id_in = ret.th_id_in
441       and    outbk.asset_id = ret.asset_id
442       and    outbk.book_type_code = ret.book
443       and    outbk.transaction_header_id_out = ret.th_id_in;
444 
445    CURSOR c_get_ret_amounts_mrc IS
446       select outbk.salvage_value - inbk.salvage_value
447            , nvl(outbk.allowed_deprn_limit_amount, 0) -
448              nvl(inbk.allowed_deprn_limit_amount, 0),
449              outbk.unrevalued_cost - inbk.unrevalued_cost
450       from   fa_books_mrc_v inbk
451            , fa_books_mrc_v outbk
452       where  inbk.transaction_header_id_in = ret.th_id_in
453       and    outbk.asset_id = ret.asset_id
454       and    outbk.book_type_code = ret.book
455       and    outbk.transaction_header_id_out = ret.th_id_in;
456 
457    CURSOR c_get_rsv_ret IS
458       select sum(decode(debit_credit_flag, 'CR', -1, 1) * adjustment_amount)
459       from   fa_adjustments
460       where  asset_id = ret.asset_id
461       and    book_type_code = ret.book
462       and    source_type_code = 'RETIREMENT'
463       and    adjustment_type = 'RESERVE'
464       and    transaction_header_id = ret.th_id_in;
465 
466    CURSOR c_get_rsv_ret_mrc IS
467       select sum(decode(debit_credit_flag, 'CR', -1, 1) * adjustment_amount)
468       from   fa_adjustments_mrc_v
469       where  asset_id = ret.asset_id
470       and    book_type_code = ret.book
471       and    source_type_code = 'RETIREMENT'
472       and    adjustment_type = 'RESERVE'
473       and    transaction_header_id = ret.th_id_in;
474 
475    -- Bug 5381824 Cursor to get the prorated transaction
476    -- date based on retirement prorate convention
477    CURSOR c_get_retire_prorate (c_thid number,
478                                 c_trx_date date ) IS
479      select con.prorate_date
480      from fa_retirements ret,
481           fa_conventions con
482      where ret.transaction_header_id_in   = c_thid
483      and   con.prorate_convention_code    = ret.RETIREMENT_PRORATE_CONVENTION
484      and   c_trx_date between con.start_date and con.end_date ;
485 
486    CURSOR c_mc_get_retire_prorate (c_thid number,
487                                 c_trx_date date ) IS
488      select con.prorate_date
489      from fa_retirements_mrc_v ret,
490           fa_conventions       con
491      where ret.transaction_header_id_in   = c_thid
492      and   con.prorate_convention_code    = ret.RETIREMENT_PRORATE_CONVENTION
493      and   c_trx_date between con.start_date and con.end_date ;
494 
495    -- Bug 5381824 end
496 
497    l_asset_hdr_rec       FA_API_TYPES.asset_hdr_rec_type;
498    l_asset_desc_rec      FA_API_TYPES.asset_desc_rec_type;
499    l_asset_cat_rec       FA_API_TYPES.asset_cat_rec_type;
500    l_asset_type_rec      FA_API_TYPES.asset_type_rec_type;
501 
502    l_trans_rec           FA_API_TYPES.trans_rec_type;
503    l_asset_fin_rec_old   FA_API_TYPES.asset_fin_rec_type;
504    l_asset_fin_rec_adj   FA_API_TYPES.asset_fin_rec_type;
505    l_asset_deprn_rec     FA_API_TYPES.asset_deprn_rec_type;
506    l_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type;
507    l_period_rec          FA_API_TYPES.period_rec_type;
508 
509    l_mrc_sob_type_code   VARCHAR2(1);
510 
511    l_salvage_value       NUMBER;
512    l_deprn_limit_amount  NUMBER;
513    l_reserve_retired     NUMBER := 0;
514 
515    calc_err              EXCEPTION;
516 BEGIN
517 
518    l_asset_hdr_rec.asset_id := ret.asset_id;
519    l_asset_hdr_rec.book_type_code := ret.book;
520    l_asset_hdr_rec.set_of_books_id := fa_cache_pkg.fazcbc_record.set_of_books_id;
521    l_mrc_sob_type_code := ret.mrc_sob_type_code;
522 
523    OPEN c_get_rein_thid;
524    FETCH c_get_rein_thid INTO l_trans_rec.transaction_header_id;
525    CLOSE c_get_rein_thid;
526 
527    OPEN c_get_trans_rec(l_trans_rec.transaction_header_id);
528    FETCH c_get_trans_rec INTO l_trans_rec.transaction_type_code
529                             , l_trans_rec.transaction_date_entered
530                             , l_trans_rec.transaction_name
531                             , l_trans_rec.source_transaction_header_id
532                             , l_trans_rec.mass_reference_id
533                             , l_trans_rec.transaction_subtype
534                             , l_trans_rec.transaction_key
535                             , l_trans_rec.amortization_start_date
536                             , l_trans_rec.calling_interface
537                             , l_trans_rec.mass_transaction_id
538                             , l_trans_rec.deprn_override_flag
539                             , l_trans_rec.member_transaction_header_id
540                             , l_trans_rec.trx_reference_id;
541    CLOSE c_get_trans_rec;
542 
543    if not FA_UTIL_PVT.get_asset_cat_rec (
544                          p_asset_hdr_rec  => l_asset_hdr_rec,
545                          px_asset_cat_rec => l_asset_cat_rec,
546                          p_date_effective  => NULL,
547               	         p_log_level_rec => p_log_level_rec) then
548       raise calc_err;
549    end if;
550 
551    if not fa_util_pvt.get_asset_desc_rec (
552                 p_asset_hdr_rec         => l_asset_hdr_rec,
553                 px_asset_desc_rec       => l_asset_desc_rec,
554               	p_log_level_rec => p_log_level_rec) then
555       raise calc_err;
556    end if;
557 
558    if not FA_UTIL_PVT.get_asset_type_rec (
559                 p_asset_hdr_rec         => l_asset_hdr_rec,
560                 px_asset_type_rec       => l_asset_type_rec,
561                 p_date_effective        => null,
562              	p_log_level_rec => p_log_level_rec) then
563       raise calc_err;
564    end if;
565 
566    if not fa_util_pvt.get_asset_fin_rec (
567                    p_asset_hdr_rec         => l_asset_hdr_rec,
568                    px_asset_fin_rec        => l_asset_fin_rec_old,
569                    p_mrc_sob_type_code     => l_mrc_sob_type_code,
570               	   p_log_level_rec => p_log_level_rec) then
571       raise calc_err;
572    end if;
573 
574    if (l_mrc_sob_type_code = 'R') then
575       OPEN c_get_ret_amounts_mrc;
576       FETCH c_get_ret_amounts_mrc
577        INTO l_asset_fin_rec_adj.salvage_value,
578             l_asset_fin_rec_adj.allowed_deprn_limit_amount,
579             l_asset_fin_rec_adj.unrevalued_cost;
580       CLOSE c_get_ret_amounts_mrc;
581    else
582       OPEN c_get_ret_amounts;
583       FETCH c_get_ret_amounts
584        INTO l_asset_fin_rec_adj.salvage_value,
585             l_asset_fin_rec_adj.allowed_deprn_limit_amount,
586             l_asset_fin_rec_adj.unrevalued_cost;
587       CLOSE c_get_ret_amounts;
588    end if;
589 
590    x_asset_fin_rec_new      := l_asset_fin_rec_old;
591    l_asset_fin_rec_adj.cost := ret.cost_retired;
592    x_asset_fin_rec_new.cost := x_asset_fin_rec_new.cost  + ret.cost_retired;
593    x_asset_fin_rec_new.unrevalued_cost := x_asset_fin_rec_new.unrevalued_cost + l_asset_fin_rec_adj.unrevalued_cost;
594 
595    -- Bug 5381824 Get the prorated transaction date
596    -- based on retirement prorate convention.
597    if (l_mrc_sob_type_code = 'R') then
598       OPEN c_mc_get_retire_prorate(l_trans_rec.transaction_header_id, l_trans_rec.transaction_date_entered);
599       FETCH c_mc_get_retire_prorate INTO l_trans_rec.transaction_date_entered;
600       CLOSE c_mc_get_retire_prorate;
601    else
602       OPEN c_get_retire_prorate(l_trans_rec.transaction_header_id, l_trans_rec.transaction_date_entered);
603       FETCH c_get_retire_prorate INTO l_trans_rec.transaction_date_entered;
604       CLOSE c_get_retire_prorate;
605    end if;
606 
607    -- BUG# 3371210
608    -- replacing the original code here with calls to common calc apis
609 
610    if not fa_asset_calc_pvt.calc_salvage_value
611             (p_trans_rec               => l_trans_rec,
612              p_asset_hdr_rec           => l_asset_hdr_rec,
613              p_asset_type_rec          => l_asset_type_rec,
614              p_asset_fin_rec_old       => l_asset_fin_rec_old,
615              p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
616              px_asset_fin_rec_new      => x_asset_fin_rec_new,
617              p_mrc_sob_type_code       => l_mrc_sob_type_code,
618              p_log_level_rec => p_log_level_rec) then
619       raise calc_err;
620    end if;
621 
622    x_asset_fin_rec_new.recoverable_cost := x_asset_fin_rec_new.cost - x_asset_fin_rec_new.salvage_value;
623 
624    if not fa_asset_calc_pvt.calc_deprn_limit_adj_rec_cost
625             (p_asset_hdr_rec           => l_asset_hdr_rec,
626              p_asset_type_rec          => l_asset_type_rec,
627              p_asset_fin_rec_old       => l_asset_fin_rec_old,
628              p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
629              px_asset_fin_rec_new      => x_asset_fin_rec_new,
630              p_mrc_sob_type_code       => l_mrc_sob_type_code,
631        	     p_log_level_rec => p_log_level_rec) then
632       raise calc_err;
633    end if;
634 
635    if not fa_util_pvt.get_asset_deprn_rec (
636                    p_asset_hdr_rec         => l_asset_hdr_rec,
637                    px_asset_deprn_rec      => l_asset_deprn_rec,
638                    p_mrc_sob_type_code     => l_mrc_sob_type_code,
639               	   p_log_level_rec => p_log_level_rec) then
640       raise calc_err;
641    end if;
642 
643    if not FA_UTIL_PVT.get_period_rec (
644                    p_book           => l_asset_hdr_rec.book_type_code,
645                    x_period_rec     => l_period_rec,
646               	   p_log_level_rec => p_log_level_rec) then
647       raise calc_err;
648    end if;
649 
650    if (l_mrc_sob_type_code = 'R') then
651       OPEN c_get_rsv_ret_mrc;
652       FETCH c_get_rsv_ret_mrc INTO l_reserve_retired;
653       CLOSE c_get_rsv_ret_mrc;
654    else
655       OPEN c_get_rsv_ret;
656       FETCH c_get_rsv_ret INTO l_reserve_retired;
657       CLOSE c_get_rsv_ret;
658    end if;
659 
660    l_asset_deprn_rec_adj.deprn_reserve := l_reserve_retired;
661 
662 
663    -- BUG# 3371210
664    -- replacing the original code here with calls to common calc apis
665 
666    if not FA_AMORT_PVT.faxama
667                      (px_trans_rec          => l_trans_rec,
668                       p_asset_hdr_rec       => l_asset_hdr_rec,
669                       p_asset_desc_rec      => l_asset_desc_rec,
670                       p_asset_cat_rec       => l_asset_cat_rec,
671                       p_asset_type_rec      => l_asset_type_rec,
672                       p_asset_fin_rec_old   => l_asset_fin_rec_old,
673                       p_asset_fin_rec_adj   => l_asset_fin_rec_adj,
674                       px_asset_fin_rec_new  => x_asset_fin_rec_new,
675                       p_asset_deprn_rec     => l_asset_deprn_rec,
676                       p_asset_deprn_rec_adj => l_asset_deprn_rec_adj,
677                       p_period_rec          => l_period_rec,
678                       p_mrc_sob_type_code   => l_mrc_sob_type_code,
679                       p_running_mode        => fa_std_types.FA_DPR_NORMAL,
680                       p_used_by_revaluation => null,
681                       x_deprn_exp           => x_deprn_exp,
682                       x_bonus_deprn_exp     => x_bonus_deprn_exp,
683 		      p_log_level_rec => p_log_level_rec) then
684       if (p_log_level_rec.statement_level) then
685          fa_debug_pkg.add(l_calling_fn, 'End', 'Success',p_log_level_rec);
686       end if;
687 
688       raise calc_err;
689    end if;
690 
691 
692 
693    return TRUE;
694 
695 EXCEPTION
696    when calc_err then
697       fa_srvr_msg.add_message(calling_fn => 'fa_gainloss_dpr_pkg.CALC_CATCHUP',
698               	 p_log_level_rec => p_log_level_rec);
699       return FALSE;
700 
701    when OTHERS then
702       fa_srvr_msg.add_message(calling_fn => 'fa_gainloss_dpr_pkg.CALC_CATCHUP(OTHERS
703 ,p_log_level_rec => p_log_level_rec)',
704               	 p_log_level_rec => p_log_level_rec);
705       return FALSE;
706 
707 END CALC_CATCHUP;
708 
709 END FA_GAINLOSS_DPR_PKG;    -- End of Package RDPR