DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_WHATIF_DEPRN_PKG

Source


1 PACKAGE BODY FA_WHATIF_DEPRN_PKG as
2 /* $Header: FAWDPRB.pls 120.21.12010000.1 2008/07/28 13:19:28 appldev ship $ */
3 
4 function whatif_deprn_asset (
5 	X_asset_id	in number,
6 	X_mode		in varchar2,
7 	X_book		in varchar2,
8 	X_start_per	in varchar2,
9 	X_num_pers	in number,
10 	X_dpis		in date default null,
11 	X_prorate_date  in date default null,
12 	X_prorate_conv  in varchar2 default null,
13 	X_deprn_start_date  in date default null,
14 	X_ceiling_name	in varchar2 default null,
15 	X_bonus_rule	in varchar2 default null,
16 	X_method_code	in varchar2 default null,
17 	X_cost		in number default null,
18 	X_old_cost	in number default null,
19 	X_adj_cost	in number default null,
20 	X_rec_cost	in number default null,
21 	X_raf		in number default null,
22 	X_adj_rate	in number default null,
23 	X_reval_amo_basis  in number default null,
24 	X_capacity	in number default null,
25 	X_adj_capacity	in number default null,
26 	X_life		in number default null,
27 	X_adj_rec_cost	in number default null,
28 	X_salvage_value	in number default null,
29 	X_salvage_pct	in number default null,
30 	X_category_id	in number default null,
31 	X_deprn_rnd_flag  in varchar2 default null,
32 	X_calendar_type in varchar2 default null,
33 	X_prior_fy_exp	in number default null,
34 	X_deprn_rsv	in number default null,
35 	X_reval_rsv	in number default null,
36 	X_ytd_deprn	in number default null,
37 	X_ltd_prod	in number default null,
38 	retcode	 out nocopy number,
39 	errbuf	 out nocopy varchar2)
40 return boolean is
41 
42 --	Implementation overview:
43 --	If mode <> HYPOTHETICAL, then asset exists in system and we should
44 --	select its current state.  Load this state directly into a
45 --	dpr_in structure.  We will use this structure as a repository
46 --	for this information throughout this function.
47 --	If mode = HYPOTHETICAL, then the "current state" had to be passed
48 --	into this function.  Load dpr_in with these parameters.
49 --
50 --	Then, if mode = EXPENSED or AMORTIZED, load a fin_info structure.
51 --	This is done as follows: for each parameter, check if it's not null
52 --	and differs from the current state.  If so, load fin_info with
53 --	that parameter, otherwise just copy the corresponding dpr_in element.
54 --	Then call the adjustment module.  Copy the adjustment module's
55 --	output into dpr_in, then run query_balances, then run the engine.
56 --
57 --	If mode = NORMAL,HYPOTHETICAL, then go directly to running
58 --	query-balances and calling the engine.
59 --
60 --	Copy engine's output into global array G_deprn.  (To be committed
61 --	to interface table later.)
62 
63 
64   ret boolean;
65   dpr_in  fa_std_types.dpr_struct;
66   dpr_out fa_std_types.dpr_out_struct;
67   dpr_arr fa_std_types.dpr_arr_type;
68 
69   dpr_row fa_std_types.fa_deprn_row_struct;
70 
71   fin_info fa_std_types.fin_info_struct;
72 
73   h_dpr_date	date;
74   h_calendar_type varchar2(30);
75   h_fy_name     varchar2(30);
76   h_prorate_fy  number;
77   h_cur_per_num number;
78   h_num_per_fy  number;
79   h_cur_fy      number;
80 
81   h_prorate_conv varchar2(10);
82 
83   h_count       number;
84   h_start_per_num   number;
85   h_start_per_fy    number;
86 
87   h_start_index     number;
88   h_end_index       number;
89 
90   h_chrono_start_per  number;
91   h_chrono_cur_per    number;
92 
93   h_current_time	date;
94   h_current_cost	number;
95 
96   h_new_adj_cost	number;
97   h_adj_deprn_exp	number;
98   h_adj_prev_deprn_exp	number;
99   h_adj_bonus_deprn_exp number;
100   h_adj_prev_bonus_deprn_exp number;
101   h_new_raf		number;
102   h_new_formula_factor  number := 1;
103   h_new_salvage_value	number;
104   h_new_adj_capacity	number;
105   h_new_reval_amo_basis number;
106   h_deprn_exp           number;
107   h_bonus_deprn_exp     number;
108   h_deprn_rsv		number; -- df
109 
110   mesg_count number;
111   mesg1 varchar2(280);
112   mesg2 varchar2(280);
113   mesg3 varchar2(280);
114   mesg4 varchar2(280);
115   mesg5 varchar2(280);
116   mesg6 varchar2(280);
117   mesg7 varchar2(280);
118   mesg8 varchar2(280);
119   mesg9 varchar2(280);
120   mesg10 varchar2(280);
121   mesg_more  boolean;
122 
123 
124   h_mesg_name  varchar2(30);
125   h_mesg_str   varchar2(2000);
126 
127   h_arc_change_flag   boolean;
128   h_allowed_deprn_limit     number;
129   h_allowed_deprn_limit_amt number;
130   h_adjusted_rec_cost       number;
131   h_use_deprn_limits_flag   varchar2(3);
132 
133   h_deprn_basis_rule	 varchar2(5);
134 
135   h_itc_amount_id	number;
136   h_itc_basis		number;
137   h_ceiling_type	varchar2(50);
138 
139   l_cp_start_date       date;
140   l_adjustment_required_status varchar2(10);
141 
142   --
143   -- Get all possible period information that the group asset needs
144   --
145   l_st_period_counter  NUMBER(15);
146   l_ed_period_counter  NUMBER(15);
147 
148   CURSOR c_get_period_rec IS
149     select cp.period_name period_name
150          , cp.period_num period_num
151          , fy.fiscal_year fiscal_year
152     from   fa_fiscal_year fy
153          , fa_calendar_periods cp
154     where  fy.fiscal_year_name = fa_cache_pkg.fazcbc_record.fiscal_year_name
155     and    cp.calendar_type = fa_cache_pkg.fazcbc_record.deprn_calendar
156     and    cp.start_date between fy.start_date and fy.end_date
157     and    l_st_period_counter <= fy.fiscal_year * fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR + cp.PERIOD_NUM
158     and l_ed_period_counter >= fy.fiscal_year * fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR + cp.PERIOD_NUM
159     order by fiscal_year, period_num;
160 
161   cache_err             exception;
162   h_deprn_run		varchar2(1);
163 begin
164 
165    --fa_rx_conc_mesg_pkg.log('Hello World');
166 
167    ret := TRUE;
168    h_arc_change_flag := FALSE;
169 
170    h_adj_deprn_exp := 0;
171    h_adj_bonus_deprn_exp := 0;
172 --tk_util.debug('Begin: '||X_mode);
173       select sysdate into h_current_time from dual;
174 
175       if X_mode <> 'HYPOTHETICAL' then
176 
177             -- FOR ALL MODES EXCEPT HYPOTHETICAL, THE ASSET EXISTS IN THE
178             -- DATABASE, SO SELECT ITS BOOK INFO.
179             -- SELECTING INTO DPR_IN, WHICH WE'LL USE AS A REPOSITORY
180             -- FOR THESE VALUES THROUGHOUT THIS FUNCTION.
181 
182             h_mesg_name := 'FA_WHATIF_ASSET_BOOKS';
183 
184             -- bug32118506
185             if (FARX_C_WD.mrc_sob_type in ('P','N')) then -- Enhancement Bug 3037321
186 
187                SELECT decode (mt.rate_source_rule,
188                                     'CALCULATED', bk.prorate_date,
189                                     'FORMULA',    bk.prorate_date,
190                                     'TABLE',      bk.deprn_start_date,
191                                     'FLAT',       decode (mt.deprn_basis_rule,
192                                                             'COST',  bk.prorate_date,
193                                                              'NBV',  bk.deprn_start_date),
194                                     'PROD',       bk.date_placed_in_service),
195                       to_number (to_char (bk.prorate_date, 'J')),
196                       to_number (to_char (bk.date_placed_in_service, 'J')),
197                       to_number (to_char (bk.deprn_start_date, 'J')),
198                       decode(mt.rate_source_rule, 'FLAT', bk.life_in_months,
199                                                           nvl(bk.life_in_months, 0)),
200                       bk.recoverable_cost,
201                       bk.adjusted_cost,
202                       bk.cost,
203                       nvl(bk.reval_amortization_basis, 0),
204                       bk.rate_adjustment_factor,
205                       nvl(bk.adjusted_rate, 0),
206                       bk.ceiling_name,
207                       bk.bonus_rule,
208                       nvl (bk.production_capacity, 0),
209                       nvl (bk.adjusted_capacity, 0),
210                       mt.method_code,
211                       ad.asset_number,
212                       nvl (bk.adjusted_recoverable_cost, bk.recoverable_cost),
213                       bk.salvage_value,
214                       bk.period_counter_life_complete,
215                       bk.adjustment_required_status,
216                       bk.annual_deprn_rounding_flag,
217                       bk.itc_amount_id,
218                       bk.itc_basis,
219                       ceilt.ceiling_type,
220                       nvl(bk.formula_factor, 1),
221                       nvl(bk.short_fiscal_year_flag, 'NO'),
222                       bk.conversion_date,
223                       bk.original_deprn_start_date,
224                       bk.prorate_date
225                     , ad.asset_type
226                INTO   h_dpr_date,
227                       dpr_in.prorate_jdate,
228                       dpr_in.jdate_in_service,
229                       dpr_in.deprn_start_jdate,
230                       dpr_in.life,
231                       dpr_in.rec_cost,
232                       dpr_in.adj_cost,
233                       h_current_cost,
234                       dpr_in.reval_amo_basis,
235                       dpr_in.rate_adj_factor,
236                       dpr_in.adj_rate,
237                       dpr_in.ceil_name,
238                       dpr_in.bonus_rule,
239                       dpr_in.capacity,
240                       dpr_in.adj_capacity,
241                       dpr_in.method_code,
242                       dpr_in.asset_num,
243                       dpr_in.adj_rec_cost,
244                       dpr_in.salvage_value,
245                       dpr_in.pc_life_end,
246                       l_adjustment_required_status,
247                       dpr_in.deprn_rounding_flag,
248                       h_itc_amount_id,
249                       h_itc_basis,
250                       h_ceiling_Type,
251                       dpr_in.formula_factor,
252                       dpr_in.short_fiscal_year_flag,
253                       dpr_in.conversion_date,
254                       dpr_in.orig_deprn_start_date,
255                       dpr_in.prorate_date
256                     , dpr_in.asset_type
257                FROM   fa_ceiling_types ceilt,
258                       fa_methods mt,
259                       fa_category_books cb,
260                       fa_books bk,
261                       fa_additions_b ad
262                WHERE  cb.book_type_code = X_book
263                AND    ad.asset_category_id = cb.category_id
264                AND    ceilt.ceiling_name(+) = bk.ceiling_name
265                AND    mt.method_code = bk.deprn_method_code
266                AND    bk.book_type_code = X_book
267                AND    bk.asset_id = X_asset_id
268                AND    bk.transaction_header_id_out is null
269                AND    nvl (mt.life_in_months, -9999) = nvl (bk.life_in_months, -9999)
270                AND    ad.asset_id = bk.asset_id;
271 
272             else
273 
274                SELECT decode (mt.rate_source_rule,
275                                     'CALCULATED', bk.prorate_date,
276                                     'FORMULA',    bk.prorate_date,
277                                     'TABLE',      bk.deprn_start_date,
278                                     'FLAT',       decode (mt.deprn_basis_rule,
279                                                             'COST',  bk.prorate_date,
280                                                              'NBV',  bk.deprn_start_date),
281                                     'PROD',       bk.date_placed_in_service),
282                       to_number (to_char (bk.prorate_date, 'J')),
283                       to_number (to_char (bk.date_placed_in_service, 'J')),
284                       to_number (to_char (bk.deprn_start_date, 'J')),
285                       decode(mt.rate_source_rule, 'FLAT', bk.life_in_months,
286                                                           nvl(bk.life_in_months, 0)),
287                       bk.recoverable_cost,
288                       bk.adjusted_cost,
289                       bk.cost,
290                       nvl(bk.reval_amortization_basis, 0),
291                       bk.rate_adjustment_factor,
292                       nvl(bk.adjusted_rate, 0),
293                       bk.ceiling_name,
294                       bk.bonus_rule,
295                       nvl (bk.production_capacity, 0),
296                       nvl (bk.adjusted_capacity, 0),
297                       mt.method_code,
298                       ad.asset_number,
299                       nvl (bk.adjusted_recoverable_cost, bk.recoverable_cost),
300                       bk.salvage_value,
301                       bk.period_counter_life_complete,
302                       bk.adjustment_required_status,
303                       bk.annual_deprn_rounding_flag,
304                       bk.itc_amount_id,
305                       bk.itc_basis,
306                       ceilt.ceiling_type,
307                       nvl(bk.formula_factor, 1),
308                       nvl(bk.short_fiscal_year_flag, 'NO'),
309                       bk.conversion_date,
310                       bk.original_deprn_start_date,
311                       bk.prorate_date
312                     , ad.asset_type
313                INTO   h_dpr_date,
314                       dpr_in.prorate_jdate,
315                       dpr_in.jdate_in_service,
316                       dpr_in.deprn_start_jdate,
317                       dpr_in.life,
318                       dpr_in.rec_cost,
319                       dpr_in.adj_cost,
320                       h_current_cost,
321                       dpr_in.reval_amo_basis,
322                       dpr_in.rate_adj_factor,
323                       dpr_in.adj_rate,
324                       dpr_in.ceil_name,
325                       dpr_in.bonus_rule,
326                       dpr_in.capacity,
327                       dpr_in.adj_capacity,
328                       dpr_in.method_code,
329                       dpr_in.asset_num,
330                       dpr_in.adj_rec_cost,
331                       dpr_in.salvage_value,
332                       dpr_in.pc_life_end,
333                       l_adjustment_required_status,
334                       dpr_in.deprn_rounding_flag,
335                       h_itc_amount_id,
336                       h_itc_basis,
337                       h_ceiling_Type,
338                       dpr_in.formula_factor,
339                       dpr_in.short_fiscal_year_flag,
340                       dpr_in.conversion_date,
341                       dpr_in.orig_deprn_start_date,
342                       dpr_in.prorate_date
343                     , dpr_in.asset_type
344                FROM   fa_ceiling_types ceilt,
345                       fa_methods mt,
346                       fa_category_books cb,
347                       fa_books_mrc_v bk,
348                       fa_additions_b ad
349                WHERE  cb.book_type_code = X_book
350                AND    ad.asset_category_id = cb.category_id
351                AND    ceilt.ceiling_name(+) = bk.ceiling_name
352                AND    mt.method_code = bk.deprn_method_code
353                AND    bk.book_type_code = X_book
354                AND    bk.asset_id = X_asset_id
355                AND    bk.transaction_header_id_out is null
356                AND    nvl (mt.life_in_months, -9999) = nvl (bk.life_in_months, -9999)
357                AND    ad.asset_id = bk.asset_id;
358 
359             end if;
360 
361             dpr_in.formula_factor := 1;
362 
363       else  -- HYPOTHETICAL
364 
365          --fa_rx_conc_mesg_pkg.log('step 1');
366 
367          -- RUNNING IN HYPOTHETICAL MODE.  ASSET DOESN'T EXIST,
368          -- SO ALL BOOKS INFO HAD TO BE PASSED INTO THIS FUNCTION.
369 
370          h_mesg_name := 'FA_AMT_BD_DPR_STRUCT';
371 
372          --fa_rx_conc_mesg_pkg.log('step 1.1');
373          SELECT cbd.life_in_months,
374       	     cbd.deprn_method,
375       	     cbd.prorate_convention_code,
376       	     cbd.adjusted_rate,
377                 cbd.bonus_rule,
378       	     cbd.ceiling_name
379          INTO   dpr_in.life,
380                 dpr_in.method_code,
381                 h_prorate_conv,
382                 dpr_in.adj_rate,
383                 dpr_in.bonus_rule,
384                 dpr_in.ceil_name
385          FROM   FA_CATEGORY_BOOK_DEFAULTS cbd
386          WHERE  cbd.book_type_code = X_book
387          AND    cbd.category_id = X_category_id
388          AND    X_dpis BETWEEN CBD.START_DPIS AND
389                                NVL(CBD.END_DPIS,TO_DATE('31-12-4712','DD-MM-YYYY'));
390 
391          --fa_rx_conc_mesg_pkg.log('step 1.2');
392          --fa_rx_conc_mesg_pkg.log(h_prorate_conv);
393 
394          if X_prorate_conv is not null then
395             h_prorate_conv := X_prorate_conv;
396          end if;
397 
398          -- Get prorate date
399          SELECT to_number(to_char(conv.prorate_date,'J'))
400          INTO   dpr_in.prorate_jdate
401          FROM   fa_conventions conv
402          WHERE  conv.prorate_convention_code = h_prorate_conv
403          AND    X_dpis between conv.start_date and conv.end_date;
404 
405          --fa_rx_conc_mesg_pkg.log('step 1.3');
406          if (X_prorate_date is not null) then
407       	 dpr_in.prorate_jdate := to_number(to_char(X_prorate_date,'J'));
408          end if;
409 
410          -- X_dpis can not be null
411          dpr_in.jdate_in_service := to_number(to_char(X_dpis, 'J'));
412 
413          -- deprn start date
414          dpr_in.deprn_start_jdate := dpr_in.prorate_jdate;
415 
416          if (X_life is not null) then
417             dpr_in.life := X_life;
418          end if;
419 
420          if (X_salvage_pct is not null) then
421             dpr_in.salvage_value := X_cost * (X_salvage_pct / 100);
422          end if;
423 
424          if (X_salvage_value is not null) then
425             dpr_in.salvage_value := X_salvage_value;
426          end if;
427 
428          dpr_in.salvage_value := nvl(dpr_in.salvage_value, 0);
429 
430          dpr_in.rec_cost := X_cost - nvl(dpr_in.salvage_value,0);
431          dpr_in.adj_cost := dpr_in.rec_cost;
432 
433          --fa_rx_conc_mesg_pkg.log('step 1.4');
434          if (X_rec_cost is not null) then
435             dpr_in.rec_cost := X_rec_cost;
436          end if;
437 
438 
439          if (X_adj_cost is not null) then
440             dpr_in.adj_cost := X_adj_cost;
441          end if;
442 
443 
444          --fa_rx_conc_mesg_pkg.log('step 1.5');
445 
446          dpr_in.reval_amo_basis := NULL;
447          dpr_in.rate_adj_factor := 1;
448 
449          --fa_rx_conc_mesg_pkg.log('step 1.6');
450 
451          if (X_adj_rate is not null) then
452             dpr_in.adj_rate := X_adj_rate;
453             dpr_in.life := NULL;
454          end if;
455 
456          if (X_ceiling_name is not null) then
457             dpr_in.ceil_name := X_ceiling_name;
458          end if;
459 
460          if (X_bonus_rule is not null) then
461             dpr_in.bonus_rule := X_bonus_rule;
462          end if;
463 
464          dpr_in.capacity := NULL;
465          dpr_in.adj_capacity := NULL;
466 
467          --fa_rx_conc_mesg_pkg.log('step 1.7');
468          if (X_method_code is not null) then
469       	 dpr_in.method_code := X_method_code;
470          end if;
471 
472          dpr_in.asset_num := to_char(X_asset_id);
473          dpr_in.adj_rec_cost := dpr_in.rec_cost;
474 
475          dpr_in.formula_factor := 1;
476 
477          --fa_rx_conc_mesg_pkg.log('step 1.8');
478          dpr_in.pc_life_end := NULL;
479          dpr_in.deprn_rounding_flag := NULL;
480          h_current_cost := X_cost;
481       end if; --X_mode <> 'HYPOTHETICAL' then
482 
483        -- GET PERIOD_NUM AND FISCAL_YEAR FOR WHICH TO START DEPRN.
484        -- ALWAYS START DEPRN IN CURRENT OPEN PERIOD.
485 
486 
487        h_mesg_name := 'FA_DEPRN_CURRENT_PERIOD';
488 
489        --
490        -- Bug3330163: Replacing with cache call.
491        --
492        if not fa_cache_pkg.fazcdp(x_book_type_code => X_book,
493                                  x_period_counter => null,
494                                  x_effective_date => null) then
495           raise cache_err;
496        end if;
497 
498        dpr_row.period_ctr := fa_cache_pkg.fazcdp_record.period_counter;
499        dpr_in.p_cl_begin := fa_cache_pkg.fazcdp_record.period_num;
500        dpr_in.y_begin := fa_cache_pkg.fazcdp_record.fiscal_year;
501        h_deprn_run	:= fa_cache_pkg.fazcdp_record.deprn_run;
502 
503        --fa_rx_conc_mesg_pkg.log('step 2111');
504 
505        if X_mode in ('EXPENSED','AMORTIZED') then
506 
507           -- IF WE'RE DOING ADJUSTMENT, NEED TO LOAD A FIN_INFO
508           -- STRUCTURE AND CALL APPROPRIATE ADJUSTMENT MODULE.
509           -- IF A FIN_INFO PARAMETER TO THIS FUNCTION IS NOT NULL,
510           -- THEN ASSUME IT REPRESENTS A CHANGE FROM THE ASSET'S CURRENT
511           -- STATE; LOAD IT INTO FIN_INFO.  IF A PARAM IS NULL, THEN
512           -- LOAD CURRENT STATE INTO FIN_INFO.
513           -- FOR EACH PARAM, MAKE SURE DPR_IN VALUE IS CORRECT.
514 
515           h_mesg_name := 'FA_AMT_GET_CATE_ID';
516 
517           select category_id, units, asset_type
518           into fin_info.category_id, fin_info.units, fin_info.asset_type
519           from fa_asset_history
520           where asset_id = X_asset_id and date_ineffective is null;
521 
522           -- MOST FIN_INFO ELEMENTS ARE LOADED THIS WAY:
523           -- IF INCOMING PARAMETER IS NOT NULL AND DIFFERENT FROM ASSET'S
524           -- CURRENT STATE, COPY IT INTO FIN_INFO.  OTHERWISE, COPY FROM
525           -- DPR_IN.
526 
527           h_mesg_name := 'FA_MASSCHG_LOAD_FININFO';
528 
529           fin_info.current_time := h_current_time;
530           fin_info.asset_number := dpr_in.asset_num;
531           fin_info.asset_id := X_asset_id;
532           fin_info.old_cost := h_current_cost;
533           fin_info.book := X_book;
534 
535           if (X_cost is not null) then
536    	  fin_info.cost := X_cost;
537    	  h_arc_change_flag := TRUE;
538           else
539              fin_info.cost := h_current_cost;
540           end if;
541 
542 
543           -- IF X_SALVAGE_VALUE IS NOT NULL, COPY IT TO FIN_INFO.
544           -- IF X_SALVAGE_PCT IS NOT NULL, CALCULATE SALVAGE USING
545           -- *CURRENT* COST.
546 
547           if (X_salvage_value is not null) then
548              fin_info.salvage_value := X_salvage_value;
549              dpr_in.salvage_value := X_salvage_value;
550              h_arc_change_flag := TRUE;
551           elsif (X_salvage_pct is not null) then
552              fin_info.salvage_value :=
553           nvl(X_cost,h_current_cost) * (X_salvage_pct / 100);
554              dpr_in.salvage_value := fin_info.salvage_value;
555              h_arc_change_flag := TRUE;
556           else
557              fin_info.salvage_value := dpr_in.salvage_value;
558           end if;
559 
560 
561           if (X_salvage_value is not null OR X_salvage_pct is not null) then
562             fin_info.rec_cost := fin_info.cost - fin_info.salvage_value;
563             dpr_in.rec_cost := fin_info.rec_cost;
564           else
565             if (X_rec_cost is not null) then
566               fin_info.rec_cost := X_rec_cost;
567               dpr_in.rec_cost := X_rec_cost;
568             else fin_info.rec_cost := dpr_in.rec_cost;
569             end if;
570           end if;
571 
572 
573           -- Method, Life, Rate require special treatment.  First check if
574           -- method is life- or rate-based.  Then ensure we've only one of Life
575           -- and Rate populated according to the method.
576 
577           if (X_method_code is not null) then
578    	  fin_info.method_code := X_method_code;
579    	  dpr_in.method_code := X_method_code;
580 
581              select count(*) into h_count from fa_methods
582              where method_code = X_method_code
583              and rate_source_rule in ('TABLE','CALCULATED','FORMULA')
584              and rownum < 2;
585 
586              if h_count > 0 then   -- life-based
587 
588    	     if (X_life is not null) then
589    	        fin_info.life := X_life;
590    	        dpr_in.life := X_life;
591    	     end if;
592 
593    	     fin_info.adj_rate := null;
594    	     dpr_in.adj_rate := null;
595 
596              else    -- rate-based
597    	     if (X_adj_rate is not null) then
598    	        fin_info.adj_rate := X_adj_rate;
599    	        dpr_in.adj_rate := X_adj_rate;
600    	     end if;
601 
602    	     fin_info.life := null;
603    	     dpr_in.life := null;
604 
605              end if;
606 
607           else    -- X_method_code not populated .. just propagate asset's current
608              -- state to fin_info
609              --fa_rx_conc_mesg_pkg.log('step 2');
610 
611              fin_info.method_code := dpr_in.method_code;
612              fin_info.life := dpr_in.life;
613              fin_info.adj_rate := dpr_in.adj_rate;
614 
615           end if; -- (X_method_code is not null)
616 
617           --fa_rx_conc_mesg_pkg.log('step 3');
618 
619           if (X_ceiling_name is not null) then
620              fin_info.ceiling_name := X_ceiling_name;
621              dpr_in.ceil_name := X_ceiling_name;
622           else
623              fin_info.ceiling_name := dpr_in.ceil_name;
624           end if;
625 
626           if (X_bonus_rule is not null) then
627              fin_info.bonus_rule := X_bonus_rule;
628              dpr_in.bonus_rule := X_bonus_rule;
629           else
630              fin_info.bonus_rule := dpr_in.bonus_rule;
631           end if;
632 
633           fin_info.transaction_id := 0;
634 
635 
636           if (X_dpis is not null) then
637              fin_info.date_placed_in_svc := X_dpis;
638              dpr_in.jdate_in_service := to_number(to_char(X_dpis,'J'));
639              h_arc_change_flag := TRUE;
640           else
641              fin_info.date_placed_in_svc := to_date(to_char(dpr_in.jdate_in_service),'J');
642           end if;
643 
644           fin_info.jdate_in_svc :=
645           to_number(to_char(fin_info.date_placed_in_svc,'J'));
646 
647           if (X_prorate_date is not null) then
648              fin_info.prorate_date := X_prorate_date;
649              dpr_in.prorate_jdate := to_number(to_char(X_prorate_date,'J'));
650           else
651              fin_info.prorate_date := to_date(to_char(dpr_in.prorate_jdate),'J');
652           end if;
653 
654           if (X_prorate_conv is not null) then
655              select prorate_date into fin_info.prorate_date
656              from fa_conventions
657              where prorate_convention_code = X_prorate_conv
658              and fin_info.date_placed_in_svc between start_date and end_date;
659 
660              dpr_in.prorate_jdate := to_number(to_char(fin_info.prorate_date,'J'));
661           end if;
662 
663           if (X_deprn_start_date is not null) then
664              fin_info.deprn_start_date := X_deprn_start_date;
665              dpr_in.deprn_start_jdate := to_number(to_char(X_deprn_start_date,'J'));
666           else
667              fin_info.deprn_start_date := to_date(to_char(dpr_in.deprn_start_jdate),'J');
668           end if;
669 
670           fin_info.dep_flag := TRUE;
671 
672           if (X_raf is not null) then
673              fin_info.rate_adj_factor := X_raf;
674              dpr_in.rate_adj_factor := X_raf;
675           else
676              fin_info.rate_adj_factor := dpr_in.rate_adj_factor;
677           end if;
678 
679           if (X_reval_amo_basis is not null) then
680              fin_info.reval_amo_basis := X_reval_amo_basis;
681              dpr_in.reval_amo_basis := X_reval_amo_basis;
682           else
683              fin_info.reval_amo_basis := dpr_in.reval_amo_basis;
684           end if;
685 
686           if (X_capacity is not null) then
687              fin_info.capacity := X_capacity;
688              dpr_in.capacity := X_capacity;
689           else
690              fin_info.capacity := dpr_in.capacity;
691           end if;
692 
693           fin_info.adj_capacity := fin_info.capacity;
694           fin_info.period_ctr := dpr_row.period_ctr;
695           fin_info.deprn_rounding_flag := 'ADJ';
696 
697           dpr_row.asset_id := X_asset_id;
698           dpr_row.book := X_book;
699           dpr_row.dist_id := 0;
700           --dpr_row.mrc_sob_type_code := 'P';
701           dpr_row.mrc_sob_type_code := FARX_C_WD.mrc_sob_type; -- Enhancement Bug 3037321
702 
703           --fa_rx_conc_mesg_pkg.log('step 4');
704 
705           if not fa_cache_pkg.fazcbc_clr(X_BOOK => X_BOOK) then
706              return (FALSE);
707           end if;
708 
709           if not fa_cache_pkg.fazcbc(X_BOOK => X_BOOK) then
710              return (FALSE);
711           end if;
712 
713           if not fa_cache_pkg.fazcct(fa_cache_pkg.fazcbc_record.deprn_calendar) then
714               return (FALSE);
715           end if;
716 
717           -- CALL QUERY BALANCES.
718 
719           h_mesg_name := 'FA_WHATIF_ASSET_QUERY_BAL';
720 
721 --tk_util.debug('1 dpr_row.period_ctr: '||to_char(dpr_row.period_ctr));
722           fa_query_balances_pkg.query_balances_int (
723                       X_dpr_row => dpr_row,
724                       X_run_mode => 'STANDARD',
725                       X_debug => FALSE,
726                       X_success => ret,
727                       X_calling_fn => 'whatif_deprn_asset',
728                       X_transaction_header_id => -1);
729 
730           if (ret = FALSE) then
731              fa_srvr_msg.add_message (calling_fn => 'fa_exp_pkg.fauexp');
732 
733              fa_srvr_msg.get_message(mesg_count,mesg1,mesg2,mesg3,mesg4,
734        		mesg5,mesg6,mesg7);
735 
736        	  fa_rx_conc_mesg_pkg.log(mesg1);
737        	  fa_rx_conc_mesg_pkg.log(mesg2);
738        	  fa_rx_conc_mesg_pkg.log(mesg3);
739        	  fa_rx_conc_mesg_pkg.log(mesg4);
740        	  fa_rx_conc_mesg_pkg.log(mesg5);
741        	  fa_rx_conc_mesg_pkg.log(mesg6);
742        	  fa_rx_conc_mesg_pkg.log(mesg7);
743 
744 
745        	  retcode := 2;
746              return (FALSE);
747           end if;
748 
749           --fa_rx_conc_mesg_pkg.log('step 5');
750 
751           -- Recoverable cost requires special treatment if there's a ceiling and/or
752           -- ITC amount.
753 
754           h_mesg_name := 'FA_FE_CANT_GEN_RECOV_COST';
755 
756           if (h_itc_amount_id is null AND h_ceiling_type = 'RECOVERABLE COST CEILING') then
757              select least(fin_info.cost - fin_info.salvage_value,
758                           nvl(ce.limit, fin_info.cost - fin_info.salvage_value))
759              into   fin_info.rec_cost
760              from   fa_ceilings ce
761              where  ce.ceiling_name = fin_info.ceiling_name
762              and    fin_info.date_placed_in_svc
763                             between ce.start_date
764                                 and nvl(ce.end_date, fin_info.date_placed_in_svc);
765 
766           elsif (h_itc_amount_id is not null AND
767                  h_ceiling_type = 'RECOVERABLE COST CEILING') then
768              select least(fin_info.cost - fin_info.salvage_value -
769                         h_itc_basis * ir.basis_reduction_rate,
770                         nvl(ce.limit, fin_info.cost - fin_info.salvage_value -
771                                       h_itc_basis * ir.basis_reduction_rate))
772              into   fin_info.rec_cost
773              from   fa_ceilings ce, fa_itc_rates ir
774              where  ir.itc_amount_id = h_itc_amount_id
775              and    ce.ceiling_name = fin_info.ceiling_name
776              and    fin_info.date_placed_in_svc
777                             between ce.start_date
778                                 and nvl(ce.end_date, fin_info.date_placed_in_svc);
779 
780           elsif (h_itc_amount_id is not null and
781        	      nvl(h_ceiling_type,'X') <> 'RECOVERABLE COST CEILING') then
782              select fin_info.cost - fin_info.salvage_value -
783                                      h_itc_basis * ir.basis_reduction_rate
784              into   fin_info.rec_cost
785              from   fa_itc_rates ir
786              where  ir.itc_amount_id = h_itc_amount_id;
787 
788           end if;
789 
790           --fa_rx_conc_mesg_pkg.log('step 6');
791 
792           h_mesg_name := 'FA_WHATIF_NO_METHOD';
793 
794           --
795           -- Replace sql with cache call.
796           --
797           if (not fa_cache_pkg.fazccmt(fin_info.method_code,
798                                        fin_info.life)) then
799              raise cache_err;
800           end if;
801 
802           h_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
803 
804           fin_info.adj_cost := fin_info.rec_cost;
805 
806           -- ADJ_REC_COST DEPENDENT ON WHETHER WE'RE USING DEPRN_LIMITS
807           h_mesg_name := 'FA_MAP_SV_DL_ERROR';
808 
809           --fa_rx_conc_mesg_pkg.log('step 7');
810 
811           SELECT CBD.USE_DEPRN_LIMITS_FLAG
812                , CBD.ALLOWED_DEPRN_LIMIT
813                , CBD.SPECIAL_DEPRN_LIMIT_AMOUNT
814           INTO   h_use_deprn_limits_flag
815                , h_allowed_deprn_limit
816                , h_allowed_deprn_limit_amt
817           FROM   FA_ADDITIONS_B FAD
818                , FA_CATEGORY_BOOK_DEFAULTS CBD
819           WHERE  FAD.ASSET_ID = fin_info.asset_id
820           AND    CBD.CATEGORY_ID = FAD.ASSET_CATEGORY_ID
821           AND    CBD.BOOK_TYPE_CODE = fin_info.book
822           AND    fin_info.date_placed_in_svc
823                              BETWEEN CBD.START_DPIS
824                                  AND NVL(CBD.END_DPIS,TO_DATE('31-12-4712','DD-MM-YYYY'));
825 
826           if (h_use_deprn_limits_flag = 'YES') then
827              if (h_allowed_deprn_limit is null) then
828                 if (fin_info.cost > 0) then
829                    h_adjusted_rec_cost := fin_info.cost - h_allowed_deprn_limit_amt;
830                 elsif (fin_info.cost < 0) then
831                    h_adjusted_rec_cost := fin_info.cost + h_allowed_deprn_limit_amt;
832                 else
833                    h_adjusted_rec_cost := 0;
834                 end if;
835              elsif (h_allowed_deprn_limit_amt is null) then
836                 h_adjusted_rec_cost := fin_info.cost * h_allowed_deprn_limit;
837                 fa_round_pkg.fa_floor(h_adjusted_rec_cost, fin_info.book);
838              end if;
839           else
840              h_adjusted_rec_cost := fin_info.rec_cost;
841           end if; -- (h_use_deprn_limits_flag = 'YES')
842 
843           dpr_in.adj_rec_cost := h_adjusted_rec_cost;
844           fin_info.adj_rec_cost := h_adjusted_rec_cost;
845 
846           --fa_rx_conc_mesg_pkg.log('step 7');
847 
848           if fnd_profile.value('PRINT_DEBUG') = 'Y' then
849              fa_rx_conc_mesg_pkg.log('FIN_INFO STRUCT:');
850              fa_rx_conc_mesg_pkg.log('asset_id: ' || fin_info.asset_id);
851              fa_rx_conc_mesg_pkg.log('category_id: ' || fin_info.category_id);
852              fa_rx_conc_mesg_pkg.log('transaction_id: ' || fin_info.transaction_id);
853              fa_rx_conc_mesg_pkg.log('jdate_in_svc: ' || fin_info.jdate_in_svc);
854              fa_rx_conc_mesg_pkg.log('period_ctr: ' || fin_info.period_ctr);
855              fa_rx_conc_mesg_pkg.log('book: ' || fin_info.book);
856              fa_rx_conc_mesg_pkg.log('asset_number: ' || fin_info.asset_number);
857              fa_rx_conc_mesg_pkg.log('asset_Type: ' || fin_info.asset_type);
858              fa_rx_conc_mesg_pkg.log('date_placed_in_svc: ' ||
859                                       to_char(fin_info.date_placed_in_svc,'DD-MM-YYYY'));
860              fa_rx_conc_mesg_pkg.log('prorate_date: ' ||
861                                       to_char(fin_info.prorate_date,'DD-MM-YYYY'));
862              fa_rx_conc_mesg_pkg.log('deprn_start_date: ' ||
863                                       to_char(fin_info.deprn_start_date,'DD-MM-YYYY'));
864              fa_rx_conc_mesg_pkg.log('ceiling_name: ' || fin_info.ceiling_name);
865              fa_rx_conc_mesg_pkg.log('bonus_rule: ' || fin_info.bonus_rule);
866              fa_rx_conc_mesg_pkg.log('current_time: ' ||
867                                      to_char(fin_info.current_time,'DD-MM-YYYY'));
868              fa_rx_conc_mesg_pkg.log('method_code: ' || fin_info.method_code);
869              fa_rx_conc_mesg_pkg.log('cost: ' || fin_info.cost);
870              fa_rx_conc_mesg_pkg.log('old_cost: ' || fin_info.old_cost);
871              fa_rx_conc_mesg_pkg.log('rec_cost: ' || fin_info.rec_cost);
872              fa_rx_conc_mesg_pkg.log('adj_cost: ' || fin_info.adj_cost);
873              fa_rx_conc_mesg_pkg.log('rate_adj_factor: ' || fin_info.rate_adj_Factor);
874              fa_rx_conc_mesg_pkg.log('adj_rate: ' || fin_info.adj_Rate);
875              fa_rx_conc_mesg_pkg.log('units: ' || fin_info.units);
876              fa_rx_conc_mesg_pkg.log('reval_amo_basis: ' || fin_info.reval_amo_basis);
877              fa_rx_conc_mesg_pkg.log('capacity: ' || fin_info.capacity);
878              fa_rx_conc_mesg_pkg.log('adj_capacity: ' || fin_info.adj_capacity);
879              fa_rx_conc_mesg_pkg.log('life: ' || fin_info.life);
880              fa_rx_conc_mesg_pkg.log('adj_rec_cost: ' || fin_info.adj_rec_cost);
881              fa_rx_conc_mesg_pkg.log('salvage_value: ' || fin_info.salvage_value);
882              fa_rx_conc_mesg_pkg.log('deprn_rounding_flag: '||fin_info.deprn_rounding_flag);
883           end if;
884 
885           -- Fix for Bug #1259562.  Default formula_factor to 1.
886           if (fin_info.formula_factor is null) then
887              fin_info.formula_factor := 1;
888           end if;
889 
890           fin_info.running_mode:= fa_std_types.FA_DPR_PROJECT;
891 
892 
893           if (X_mode = 'EXPENSED') then
894 
895 
896       	 h_mesg_name := 'FA_WHATIF_ASSET_EXPENSE_ERR';
897              -- bonus: should be ok for faxexp.
898 
899     	 if not fa_exp_pkg.faxexp (fin_info,
900                                        h_new_adj_cost, 0,
901                                        h_current_time,
902                                        0,
903                                        0,
904                                        FALSE,
905                                        'P',  -- mrc sob type
906                                        h_adj_deprn_exp,
907                                        h_adj_bonus_deprn_exp,
908                                        h_new_formula_factor) then
909 
910                 fa_srvr_msg.add_message (calling_fn => 'fa_exp_pkg.fauexp');
911 
912                 fa_srvr_msg.get_message(mesg_count,mesg1,mesg2,mesg3,mesg4,
913                                         mesg5,mesg6,mesg7);
914 
915                 fa_rx_conc_mesg_pkg.log(mesg1);
916                 fa_rx_conc_mesg_pkg.log(mesg2);
917                 fa_rx_conc_mesg_pkg.log(mesg3);
918                 fa_rx_conc_mesg_pkg.log(mesg4);
919                 fa_rx_conc_mesg_pkg.log(mesg5);
920                 fa_rx_conc_mesg_pkg.log(mesg6);
921                 fa_rx_conc_mesg_pkg.log(mesg7);
922 
923                 retcode := 2;
924                 return (FALSE);
925     	 end if;
926 
927     	 dpr_in.adj_cost := h_new_adj_cost;
928 
929 
930           else
931 
932              h_new_raf := dpr_in.rate_adj_factor;
933              h_new_salvage_value := dpr_in.salvage_value;
934              h_new_adj_capacity := dpr_in.adj_capacity;
935              h_new_adj_cost := dpr_in.adj_cost;
936              h_new_reval_amo_basis := dpr_in.reval_amo_basis;
937 
938     	  h_mesg_name := 'FA_WHATIF_ASSET_AMORTIZE_ERR';
939 
940 
941              if fnd_profile.value('PRINT_DEBUG') = 'Y' then
942     	    fa_rx_conc_mesg_pkg.log('old adj_cost: ' || to_char(dpr_in.adj_cost));
943     	    fa_rx_conc_mesg_pkg.log('old raf: ' || to_char(dpr_in.rate_adj_factor));
944              end if;
945 
946              if not fa_amort_pkg.faxama (fin_info,
947     		h_new_raf, h_new_adj_cost, h_new_adj_capacity,
948     		h_new_reval_amo_basis, h_new_salvage_value, h_new_formula_factor,0,
949     		FALSE, 'P', h_deprn_exp,h_bonus_deprn_exp,h_current_time,0,0)  then
950             	fa_srvr_msg.add_message (calling_fn => 'fa_exp_pkg.fauama');
951 
952                 fa_srvr_msg.get_message(mesg_count,mesg1,mesg2,mesg3,mesg4,
953                                         mesg5,mesg6,mesg7);
954 
955                 fa_rx_conc_mesg_pkg.log(mesg1);
956                 fa_rx_conc_mesg_pkg.log(mesg2);
957                 fa_rx_conc_mesg_pkg.log(mesg3);
958                 fa_rx_conc_mesg_pkg.log(mesg4);
959                 fa_rx_conc_mesg_pkg.log(mesg5);
960                 fa_rx_conc_mesg_pkg.log(mesg6);
961                 fa_rx_conc_mesg_pkg.log(mesg7);
962 
963                 retcode := 2;
964                 return (FALSE);
965              end if;
966 
967              dpr_in.salvage_value := h_new_salvage_value;
968              dpr_in.rate_adj_factor := h_new_raf;
969              dpr_in.adj_cost := h_new_adj_cost;
970              dpr_in.adj_capacity := h_new_adj_capacity;
971              dpr_in.reval_amo_basis := h_new_reval_amo_basis;
972 
973              if fnd_profile.value('PRINT_DEBUG') = 'Y' then
974                 fa_rx_conc_mesg_pkg.log('new adj_cost: ' || to_char(dpr_in.adj_cost));
975                 fa_rx_conc_mesg_pkg.log('new adj_rec_cost: '||to_char(dpr_in.adj_rec_cost));
976                 fa_rx_conc_mesg_pkg.log('new rec_cost: ' || to_char(dpr_in.rec_cost));
977                 fa_rx_conc_mesg_pkg.log('new salvage_val: '||to_char(dpr_in.salvage_value));
978                 fa_rx_conc_mesg_pkg.log('new raf: ' || to_char(dpr_in.rate_adj_factor));
979              end if;
980           end if; -- (X_mode = 'EXPENSED')
981        end if; -- X_mode in ('EXPENSED','AMORTIZED')
982 
983 
984        -- LOAD DPR_IN STRUCT... MAKE SURE TO ADD ADJUSTMENTS TO EXPENSE TO BALANCES HERE.
985 
986        --fa_rx_conc_mesg_pkg.log('step 811');
987 
988        -- HAVEN'T CALLED QUERY BALANCES FOR NORMAL MODE YET
989        if (X_Mode not in ('EXPENSED','AMORTIZED')) then
990           --fa_rx_conc_mesg_pkg.log('step 8');
991 
992           h_mesg_name := 'FA_WHATIF_ASSET_QUERY_BAL';
993 
994           dpr_row.asset_id := X_asset_id;
995           dpr_row.book := X_book;
996           dpr_row.dist_id := 0;
997           --dpr_row.mrc_sob_type_code := 'P';
998           dpr_row.mrc_sob_type_code := FARX_C_WD.mrc_sob_type; -- Enhancement Bug 3037321
999 
1000           if not fa_cache_pkg.fazcbc_clr(X_BOOK => X_BOOK) then
1001              return (FALSE);
1002           end if;
1003 
1004           if not fa_cache_pkg.fazcbc(X_BOOK => X_BOOK) then
1005              return (FALSE);
1006           end if;
1007 -- dpr_in.y_begin = 2002
1008 -- dpr_in.p_cl_begin   = 2
1009           fa_query_balances_pkg.query_balances_int (
1010                                       X_dpr_row => dpr_row,
1011                                       X_run_mode => 'STANDARD',
1012                                       X_Debug => FALSE,
1013                                       X_success => ret,
1014                                       X_calling_fn => 'whatif_deprn_asset',
1015                                       X_transaction_header_id => -1);
1016        end if; -- (X_Mode not in ('EXPENSED','AMORTIZED'))
1017 
1018        --  Get adjustments to deprn expense already taken this period.
1019        -- fa_rx_conc_mesg_pkg.log('step 8');
1020        h_mesg_name := 'FA_REC_SQL_GET_ADJ';
1021 
1022        --
1023        -- SQL to get expenses from fa_adjustments have been removed becuase
1024        -- the result were not used after the fix for bug227327
1025        --
1026 
1027        h_mesg_name := 'FA_AMT_BD_DPR_STRUCT';
1028 
1029        dpr_in.reval_rsv := dpr_row.reval_rsv;
1030        dpr_in.prior_fy_exp := dpr_row.prior_fy_exp;
1031        dpr_in.ytd_deprn := dpr_row.ytd_deprn + h_adj_deprn_exp;
1032        dpr_in.deprn_rsv := dpr_row.deprn_rsv + h_adj_deprn_exp;
1033        dpr_in.ltd_prod := dpr_row.ltd_prod;
1034 --tk_util.debug('dpr_in.deprn_rsv: '||to_char(dpr_in.deprn_rsv));
1035 
1036        -- bonus: h_adj_bonus_deprn_exp is obtained from faxexp above.
1037        --        New parameter was added to faxexp due to the need.
1038 
1039        dpr_in.bonus_ytd_deprn := dpr_row.bonus_ytd_deprn + h_adj_bonus_deprn_exp;
1040        dpr_in.bonus_deprn_rsv := dpr_row.bonus_deprn_rsv + h_adj_bonus_deprn_exp;
1041 
1042        dpr_in.asset_id := X_asset_id;
1043        dpr_in.book := X_book;
1044 
1045        dpr_in.jdate_retired := 0;
1046        dpr_in.ret_prorate_jdate := 0;
1047        dpr_in.rsv_known_flag := TRUE;
1048 
1049 
1050        --fa_rx_conc_mesg_pkg.log('step 9');
1051 
1052        -- GET CALENDAR INFO: TYPE, FY_NAME, NUM_PER_FISCAL_YEAR
1053 
1054        h_mesg_name := 'FA_DEPRN_SQL_SNFY';
1055 
1056        --
1057        -- Modified to use cache
1058        --
1059        if not fa_cache_pkg.fazcct(fa_cache_pkg.fazcbc_record.deprn_calendar) then
1060           raise cache_err;
1061        end if;
1062 
1063        h_calendar_type := fa_cache_pkg.fazcbc_record.deprn_calendar;
1064        h_fy_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
1065        h_num_per_fy := fa_cache_pkg.fazcct_record.number_per_fiscal_year;
1066 
1067        dpr_in.calendar_type := h_calendar_type;
1068 
1069 
1070        -- FIGURE OUT THE LAST PERIOD_NUM/FISCAL_YEAR FOR WHICH TO DEPRECIATE,
1071        -- GIVEN X_START_PER AND X_NUM_PERS.  KEEP IN MIND THAT WE MUST START
1072        -- DEPRN IN CURRENT OPEN PERIOD, BUT X_START_PER MAY BE EARLIER OR LATER.
1073 
1074 
1075        h_mesg_name := 'FA_AMT_SEL_CALENDARS_1';
1076 
1077 
1078        select cp.period_num
1079             , fy.fiscal_year
1080             , cp.start_date
1081        into   h_start_per_num
1082             , h_start_per_fy
1083             , l_cp_start_date
1084        from fa_calendar_periods cp, fa_fiscal_year fy
1085        where cp.period_name = X_start_per
1086        and cp.calendar_type = h_calendar_type
1087        and cp.start_date >= fy.start_date
1088        and cp.end_date <= fy.end_date
1089        and fy.fiscal_year_name = h_fy_name;
1090 
1091        h_mesg_name := 'FA_WHATIF_START_END_PERIODS';
1092 
1093        dpr_in.y_end := h_start_per_fy +
1094    	floor( (h_start_per_num + X_num_pers - 1) / h_num_per_fy);
1095        dpr_in.p_cl_end := mod( (h_start_per_num + X_num_pers - 1) , h_num_per_fy);
1096 
1097        --
1098        -- Set annual deprn rounding flag to RES to avoid subtraction method to
1099        -- to find expense for last period of fy because ytd is not correct if
1100        -- whatif doesn't start from current period.
1101        -- I THINK THIS IS NOT TRUE BECAUSE WHATIF RUNS FROM CURRENT PERIOD
1102        -- ANYWAY TO CALCULATE CORRECT EXPENSE IN FUTURE
1103        --if (not((dpr_in.y_begin = h_start_per_fy) and
1104        --        (dpr_in.p_cl_begin = h_start_per_num))) then
1105        --   dpr_in.deprn_rounding_flag := fa_std_types.FA_DPR_ROUND_RES;
1106        --end if;
1107        if (to_number(to_char(fa_cache_pkg.fazcdp_record.calendar_period_open_date, 'J')) >
1108            dpr_in.jdate_in_service) and
1109           (l_adjustment_required_status = 'ADD') then
1110           dpr_in.deprn_rounding_flag := fa_std_types.FA_DPR_ROUND_ADJ;
1111        end if;
1112 
1113   /*bug fix 3735661 Added this check to avoid calculation in last period*/
1114        if ( (X_mode ='HYPOTHETICAL')
1115              and
1116             (to_number(to_char(l_cp_start_date, 'J')) > dpr_in.jdate_in_service)
1117           ) then
1118               dpr_in.deprn_rounding_flag := fa_std_types.FA_DPR_ROUND_RES;
1119        end if;
1120 
1121        -- Call deprn engine.
1122 
1123        --fa_rx_conc_mesg_pkg.log('step 10');
1124 
1125        if X_mode in ('EXPENSED','AMORTIZED') then
1126           dpr_in.deprn_rounding_flag := 'ADJ';
1127        end if;
1128 
1129 
1130 
1131        if fnd_profile.value('PRINT_DEBUG') = 'Y' then
1132 
1133    	fa_rx_conc_mesg_pkg.log('DPR_IN STRUCT:');
1134    	fa_rx_conc_mesg_pkg.log('Contents of dpr_struct for asset_id  '||dpr_in.asset_id);
1135    	fa_rx_conc_mesg_pkg.log('asset_num   '||dpr_in.asset_num);
1136    	fa_rx_conc_mesg_pkg.log('book   '||dpr_in.book);
1137    	fa_rx_conc_mesg_pkg.log('calendar_type   '||dpr_in.calendar_type);
1138    	fa_rx_conc_mesg_pkg.log('ceil_name   '||dpr_in.ceil_name);
1139    	fa_rx_conc_mesg_pkg.log('bonus_rule   '||dpr_in.bonus_rule);
1140    	fa_rx_conc_mesg_pkg.log('method_code   '||dpr_in.method_code);
1141    	fa_rx_conc_mesg_pkg.log('adj_cost   '||dpr_in.adj_cost);
1142    	fa_rx_conc_mesg_pkg.log('rec_cost   '||dpr_in.rec_cost);
1143    	fa_rx_conc_mesg_pkg.log('reval_amo_basis   '||dpr_in.reval_amo_basis);
1144    	fa_rx_conc_mesg_pkg.log('deprn_rsv   '||dpr_in.deprn_rsv);
1145    	fa_rx_conc_mesg_pkg.log('reval_rsv   '||dpr_in.reval_rsv);
1146    -- bonus
1147    	fa_rx_conc_mesg_pkg.log('bonus_deprn_rsv ' || dpr_in.bonus_deprn_rsv);
1148    	fa_rx_conc_mesg_pkg.log('adj_rate   '||dpr_in.adj_rate);
1149    	fa_rx_conc_mesg_pkg.log('rate_adj_factor   '||dpr_in.rate_adj_factor);
1150    	fa_rx_conc_mesg_pkg.log('capacity   '||dpr_in.capacity);
1151    	fa_rx_conc_mesg_pkg.log('adj_capacity   '||dpr_in.adj_capacity);
1152    	fa_rx_conc_mesg_pkg.log('ltd_prod   '||dpr_in.ltd_prod);
1153    	fa_rx_conc_mesg_pkg.log('adj_rec_cost   '||dpr_in.adj_rec_cost);
1154    	fa_rx_conc_mesg_pkg.log('salvage_value   '||dpr_in.salvage_value);
1155    	fa_rx_conc_mesg_pkg.log('prior_fy_exp   '||dpr_in.prior_fy_exp);
1156    	fa_rx_conc_mesg_pkg.log('ytd_deprn   '||dpr_in.ytd_deprn);
1157    	fa_rx_conc_mesg_pkg.log('asset_id   '||dpr_in.asset_id);
1158    	fa_rx_conc_mesg_pkg.log('jdate_in_service   '||dpr_in.jdate_in_service);
1159    	fa_rx_conc_mesg_pkg.log('prorate_jdate   '||dpr_in.prorate_jdate);
1160    	fa_rx_conc_mesg_pkg.log('deprn_start_jdate   '||dpr_in.deprn_start_jdate);
1161    	fa_rx_conc_mesg_pkg.log('jdate_retired   '||dpr_in.jdate_retired);
1162    	fa_rx_conc_mesg_pkg.log('ret_prorate_jdate   '||dpr_in.ret_prorate_jdate);
1163    	fa_rx_conc_mesg_pkg.log('life   '||dpr_in.life);
1164    	fa_rx_conc_mesg_pkg.log('prorate_year_pcal_begin   '||dpr_in.y_begin);
1165    	fa_rx_conc_mesg_pkg.log('y_end   '||dpr_in.y_end);
1166    	fa_rx_conc_mesg_pkg.log('p_cl_begin   '||dpr_in.p_cl_begin);
1167    	fa_rx_conc_mesg_pkg.log('p_cl_end   '||dpr_in.p_cl_end);
1168    	fa_rx_conc_mesg_pkg.log('pc_life_end   '||dpr_in.pc_life_end);
1169 
1170    	if (dpr_in.rsv_known_flag) then
1171            	fa_rx_conc_mesg_pkg.log('rsv_known_flag   '||'TRUE');
1172    	else
1173            	fa_rx_conc_mesg_pkg.log('rsv_known_flag   '||'FALSE');
1174            end if;
1175 
1176    	fa_rx_conc_mesg_pkg.log('deprn_rounding_flag   '||dpr_in.deprn_rounding_flag);
1177        end if;
1178 
1179        -- override
1180        dpr_in.used_by_adjustment:= FALSE;
1181        dpr_in.deprn_override_flag := fa_std_types.FA_NO_OVERRIDE;
1182 
1183        h_mesg_name := 'FA_WHATIF_ASSET_DEPRN_ERR';
1184        -- bonus logic already in faxcde. dpr_arr extended with bonus_value.
1185 
1186        -- Polish code
1187        FA_POLISH_PVT.calling_mode := 'WHATIF';
1188 
1189 --tk_util.debug('call faxcde');
1190 
1191 
1192 --- bug 4133347 to back out deprn amount if deprn been run without closing the period.
1193        if h_deprn_run = 'Y' then
1194 	dpr_in.deprn_rsv := dpr_in.deprn_rsv - dpr_row.deprn_exp;
1195 	dpr_in.ytd_deprn := dpr_in.ytd_deprn - dpr_row.deprn_exp;
1196        end if;
1197 
1198        ret := fa_cde_pkg.faxcde(dpr_in => dpr_in,
1199                                 dpr_arr => dpr_arr,
1200                                 dpr_out => dpr_out,
1201                                 fmode => fa_std_types.FA_DPR_PROJECT);
1202 --tk_util.debug('after faxcde');
1203        if (ret = FALSE) then
1204 --tk_util.debug('faxcde returned false');
1205           fa_srvr_msg.get_message(mesg_count,mesg1,mesg2,mesg3,mesg4,
1206    		mesg5,mesg6,mesg7);
1207 
1208           fa_rx_conc_mesg_pkg.log(mesg1);
1209           fa_rx_conc_mesg_pkg.log(mesg2);
1210           fa_rx_conc_mesg_pkg.log(mesg3);
1211           fa_rx_conc_mesg_pkg.log(mesg4);
1212           fa_rx_conc_mesg_pkg.log(mesg5);
1213           fa_rx_conc_mesg_pkg.log(mesg6);
1214           fa_rx_conc_mesg_pkg.log(mesg7);
1215 
1216 
1217           retcode := 2;
1218           return (FALSE);
1219        end if;
1220 
1221        -- FIGURE OUT WHICH PERIODS' RESULTS WE ARE INTERESTED IN SHOWING
1222        -- TO THE USER.  IF USER'S START PERIOD IS IN THE FUTURE, DON'T
1223        -- SHOW RESULTS FROM BEFORE START PERIOD.
1224 
1225        h_mesg_name := 'FA_WHATIF_ASSET_DEPRN_EXP_ERR';
1226 
1227        h_start_index := 0;
1228        h_end_index := X_num_pers - 1;
1229 
1230        h_chrono_cur_per := dpr_in.y_begin * h_num_per_fy + dpr_in.p_cl_begin;
1231        h_chrono_start_per := h_start_per_fy * h_num_per_fy + h_start_per_num;
1232 
1233        if h_chrono_start_per < h_chrono_cur_per then
1234           h_end_index := h_end_index + h_chrono_start_per - h_chrono_cur_per;
1235        elsif h_chrono_start_per > h_chrono_cur_per then
1236           h_end_index := h_end_index + h_chrono_start_per - h_chrono_cur_per;
1237           h_start_index := h_chrono_start_per - h_chrono_cur_per;
1238        end if;
1239 
1240        h_deprn_rsv := nvl(X_deprn_rsv,0);
1241 
1242 
1243 -- fa_rx_conc_mesg_pkg.log('orig.fiscal_year: ' || dpr_arr(0).fiscal_year);
1244 -- fa_rx_conc_mesg_pkg.log('new.fiscal_year: ' || h_start_per_fy);
1245 -- fa_rx_conc_mesg_pkg.log('num per fy: ' || fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR);
1246 -- fa_rx_conc_mesg_pkg.log('h_start_per_num: ' || h_start_per_num );
1247 
1248        l_st_period_counter := h_start_per_fy *
1249                            fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR +
1250 				h_start_per_num;
1251 
1252 fa_rx_conc_mesg_pkg.log('l_st_period_counter: ' || l_st_period_counter);
1253 
1254 -- dpr_arr(0).period_num is wrong as start period, it will only
1255 --  cause current open period to be used.
1256 
1257        l_ed_period_counter := l_st_period_counter + h_end_index;
1258 --tk_util.debug('before fetching periods');
1259        if (nvl(tb_period_name.last, 0) = 0) then
1260           OPEN c_get_period_rec;
1261           FETCH c_get_period_rec BULK COLLECT INTO tb_period_name,
1262                                                    tb_period_num,
1263                                                    tb_fiscal_year;
1264           CLOSE c_get_period_rec;
1265        end if;
1266 
1267 -- fa_rx_conc_mesg_pkg.log('before loop');
1268 -- fa_rx_conc_mesg_pkg.log('start pc' || l_st_period_counter);
1269 -- fa_rx_conc_mesg_pkg.log('end pc' || l_ed_period_counter);
1270 -- fa_rx_conc_mesg_pkg.log('last: '||to_char(tb_period_name.last));
1271 -- fa_rx_conc_mesg_pkg.log('X_mode: '||X_mode);
1272 -- fa_rx_conc_mesg_pkg.log('h_adj_prev_deprn_exp: '||to_char(h_adj_prev_deprn_exp));
1273 
1274     for h_count in h_start_index .. h_end_index loop
1275        if (X_mode in ('NORMAL','HYPOTHETICAL')) then
1276           --fa_rx_conc_mesg_pkg.log('step 11');
1277 
1278           -- POPULATE DEPRECIATION COLUMN, SELECTING PERIOD_NAME IN
1279           -- LIEU OF NUMBER/YEAR
1280 
1281           G_deprn(h_count - h_start_index).deprn := dpr_arr(h_count).value;
1282           G_deprn(h_count - h_start_index).fiscal_year :=
1283                                               dpr_arr(h_count).fiscal_year;
1284           h_deprn_rsv := h_deprn_rsv + dpr_arr(h_count).value; -- df
1285           G_deprn(h_count - h_start_index).new_rsv := h_deprn_rsv; -- df
1286           -- bonus
1287           G_deprn(h_count - h_start_index).bonus_deprn := dpr_arr(h_count).bonus_value;
1288 
1289           G_deprn(h_count - h_start_index).period_name :=
1290                                 tb_period_name(h_count - h_start_index + 1);
1291           G_deprn(h_count - h_start_index).period_num :=
1292                                 tb_period_num(h_count - h_start_index + 1);
1293 --tk_util.debug('period_anme: '||tb_period_name(h_count - h_start_index + 1));
1294 
1295           --
1296           -- Populate these in case there is no adj criteria entered so this function
1297           -- will not be called for expense/amortize mode
1298           --
1299           G_deprn(h_count - h_start_index).new_deprn := G_deprn(h_count - h_start_index).deprn;
1300           -- bonus
1301           G_deprn(h_count - h_start_index).new_bonus_deprn :=
1302                                                      G_deprn(h_count - h_start_index).bonus_deprn;
1303 
1304        else   -- WE DID ADJUSTMENT, SO POPULATE NEW_DEPRECIATION
1305 
1306           -- Commenting this code for bug fix 2273276
1307           -- Discussed this bug with Gary and Decided not to add the
1308           -- catchup to the New Depreciation*/
1309 
1310 ----          -- IF THIS IS PERIOD OF ADJUSTMENT, ADD EXPENSE ADJUSTMENT
1311 ----          -- TO THE PERIOD'S DEPRN EXPENSE
1312 ----
1313 ----          if (h_count = h_start_index and h_start_index = 0) then
1314 ----             G_deprn(h_count - h_start_index).new_deprn :=
1315 ----                   h_adj_deprn_exp + h_adj_prev_deprn_exp + dpr_arr(h_count).value;
1316 ----             --  bonus
1317 ----             G_deprn(h_count - h_start_index).new_bonus_deprn :=
1318 ----                   h_adj_bonus_deprn_exp + h_adj_prev_bonus_deprn_exp +
1319 ----                   dpr_arr(h_count).bonus_value;
1320 ----          else
1321 ----             G_deprn(h_count - h_start_index).new_deprn := dpr_arr(h_count).value;
1322 ----             -- bonus
1323 ----             G_deprn(h_count - h_start_index).new_bonus_deprn :=
1324 ----                           dpr_arr(h_count).bonus_value;
1325 ----          end if;
1326 
1327           -- Adding this for bug fix 2273276
1328           -- Here New Depreciation is calculated without adding the catchup
1329 --tk_util.debug('h_count:h_start_index: '||to_char(h_count)||':'||to_char(h_start_index));
1330           G_deprn(h_count - h_start_index).new_deprn := dpr_arr(h_count).value;
1331           -- bonus
1332           G_deprn(h_count - h_start_index).new_bonus_deprn :=
1333                               dpr_arr(h_count).bonus_value;
1334 
1335        end if;
1336 
1337     end loop;
1338 
1339     -- clear dpr_arr tables
1340 
1341     dpr_arr.delete;
1342 
1343     errbuf := '';
1344 --tk_util.debug('end of whatif calc');
1345     return ret;
1346 
1347 exception
1348    when cache_err then
1349 --tk_util.debug('cache_err: '||sqlerrm);
1350       retcode := 2;
1351 
1352       if SQLCODE <> 0 then
1353          fa_Rx_conc_mesg_pkg.log(SQLERRM);
1354       end if;
1355 
1356       g_deprn.delete;
1357       fnd_message.set_name('OFA',h_mesg_name);
1358       if h_mesg_name like 'FA_WHATIF_ASSET%' then
1359          fnd_message.set_token('ASSET_ID',X_asset_id,FALSE);
1360       end if;
1361       h_mesg_str := fnd_message.get;
1362       fa_rx_conc_mesg_pkg.log(h_mesg_str);
1363 
1364       return FALSE;
1365 
1366    when others then
1367 --tk_util.debug('others: '||sqlerrm);
1368       retcode := 2;
1369 
1370       if SQLCODE <> 0 then
1371          fa_Rx_conc_mesg_pkg.log(SQLERRM);
1372       end if;
1373 
1374       g_deprn.delete;
1375       fnd_message.set_name('OFA',h_mesg_name);
1376       if h_mesg_name like 'FA_WHATIF_ASSET%' then
1377          fnd_message.set_token('ASSET_ID',X_asset_id,FALSE);
1378       end if;
1379       h_mesg_str := fnd_message.get;
1380       fa_rx_conc_mesg_pkg.log(h_mesg_str);
1381 
1382       return FALSE;
1383 
1384 
1385 end whatif_deprn_asset;
1386 
1387 
1388 
1389 function whatif_insert_itf (
1390 	X_asset_id	in number,
1391 	X_book		in varchar2,
1392 	X_request_id	in number,
1393 	X_num_pers	in number,
1394 	X_acct_struct   in number,
1395 	X_key_struct	in number,
1396 	X_cat_struct	in number,
1397 	X_loc_struct	in number,
1398 	X_precision	in number,
1399 	X_user_id	in number,
1400 	X_login_id	in number,
1401         X_last_asset    in boolean default false,
1402 	retcode	 out nocopy number,
1403 	errbuf	 out nocopy varchar2) return boolean is
1404 
1405 h_dist_book		fa_book_controls.distribution_source_book%TYPE;
1406 h_asset_number		varchar2(15);
1407 h_description		varchar2(80);
1408 h_tag_number		varchar2(15);
1409 h_serial_number		varchar2(35);
1410 h_total_units		number;
1411 h_dist_units		number;
1412 h_dist_deprn		number;
1413 h_dist_new_deprn	number;
1414 h_dist_new_rsv          number;
1415 
1416 -- bonus
1417 h_dist_bonus_deprn	number;
1418 h_dist_new_bonus_deprn	number;
1419 
1420 h_ccid			number;
1421 h_concat_acct		varchar2(500);
1422 h_segs			fa_rx_shared_pkg.Seg_Array;
1423 
1424 h_category_id		number;
1425 h_concat_cat		varchar2(500);
1426 
1427 h_asset_key_id		number;
1428 h_concat_key		varchar2(500);
1429 
1430 h_location_id		number;
1431 h_concat_loc		varchar2(500);
1432 
1433 h_employee_number	varchar2(30);
1434 h_employee_name		varchar2(240);
1435 
1436 h_current_cost		number;
1437 h_current_prorate_conv  varchar2(15);
1438 h_current_method	varchar2(15);
1439 h_current_life		number;
1440 h_current_basic_rate	number;
1441 h_current_adjusted_rate number;
1442 h_current_salvage_value number;
1443 h_current_bonus_rule  	varchar2(30);
1444 h_current_dpis          date;
1445 
1446 h_dist_cost		number;
1447 h_count			number;
1448 
1449   h_mesg_name  varchar2(30);
1450   h_mesg_str   varchar2(2000);
1451   h_flex_error varchar2(5);
1452   h_ccid_error number;
1453   h_currency   varchar2(15);
1454 
1455 ret			boolean;
1456 
1457 -- SELECTS DIST INFO FOR A GIVEN ASSET
1458 
1459   cursor dist_book is
1460   Select distribution_source_book
1461   From fa_book_controls
1462   Where book_type_code = X_book;
1463 
1464 
1465   cursor dist_lines is
1466    select dh.units_assigned, dh.code_combination_id, dh.location_id,
1467    emp.employee_number, emp.full_name
1468    from fa_distribution_history dh, per_all_people_f emp
1469    where emp.person_id (+) = dh.assigned_to
1470    and  trunc(sysdate) between emp.effective_start_date(+) and emp.effective_end_date(+)
1471    and dh.book_type_code = h_dist_book
1472    and dh.asset_id = X_asset_id
1473    and dh.date_ineffective is null;
1474 
1475   i BINARY_INTEGER;
1476   old_i BINARY_INTEGER;
1477   l_limit  BINARY_INTEGER := nvl(fa_cache_pkg.fa_batch_size, 500);
1478 
1479 begin
1480 
1481 ret := TRUE;
1482 
1483  -- SELECT ASSET-LEVEL INFO USER MAY BE INTERESTED IN
1484 
1485   h_mesg_name := 'FA_WHATIF_ASSET_INFO';
1486 
1487   select description, tag_number, serial_number, asset_number,
1488 	asset_key_ccid, current_units, asset_category_id
1489   into h_description, h_tag_number, h_serial_number, h_asset_number,
1490 	h_asset_key_id, h_total_units, h_category_id
1491   from fa_additions
1492   where asset_id = X_asset_id;
1493 
1494  -- SELECT CURRENT (BEFORE ADJUSTMENT) BOOK-LEVEL INFO
1495 
1496   h_mesg_name := 'FA_WHATIF_ASSET_DEPRN_INFO';
1497 -- bug32118506
1498   if(FARX_C_WD.mrc_sob_type in ('P','N')) then -- Enhancement Bug 3037321
1499 
1500      select cost, prorate_convention_code, deprn_method_code,
1501    	life_in_months, basic_rate, adjusted_rate, salvage_value, bonus_rule,
1502            date_placed_in_service
1503      into h_current_cost, h_current_prorate_conv, h_current_method,
1504    	h_current_life, h_current_basic_rate, h_current_adjusted_rate,
1505    	h_current_salvage_value, h_current_bonus_rule,
1506            h_current_dpis
1507      from fa_books
1508      where asset_id = X_asset_id
1509      and book_type_code = X_book
1510      and transaction_header_id_out is null;
1511 
1512   else
1513 
1514      select cost, prorate_convention_code, deprn_method_code,
1515            life_in_months, basic_rate, adjusted_rate, salvage_value, bonus_rule,
1516            date_placed_in_service
1517      into h_current_cost, h_current_prorate_conv, h_current_method,
1518            h_current_life, h_current_basic_rate, h_current_adjusted_rate,
1519            h_current_salvage_value, h_current_bonus_rule,
1520            h_current_dpis
1521      from fa_books_mrc_v
1522      where asset_id = X_asset_id
1523      and book_type_code = X_book
1524      and transaction_header_id_out is null;
1525 
1526   end if;
1527 
1528 if (h_asset_key_id is not null) then
1529 
1530 
1531 
1532    h_mesg_name := 'FA_RX_CONCAT_SEGS';
1533    h_flex_error := 'KEY#';
1534    h_ccid_error := h_asset_key_id;
1535 
1536   fa_rx_shared_pkg.concat_asset_key (
1537 	struct_id => X_key_struct,
1538 	ccid => h_asset_key_id,
1539 	concat_string => h_concat_key,
1540 	segarray => h_segs);
1541 end if;
1542 
1543    h_flex_error := 'CAT#';
1544    h_ccid_error := h_category_id;
1545 
1546   fa_rx_shared_pkg.concat_category (
1547 	struct_id => X_cat_struct,
1548 	ccid => h_category_id,
1549 	concat_string => h_concat_cat,
1550 	segarray => h_segs);
1551 
1552 
1553 
1554   h_mesg_name := 'FA_WHATIF_ASSET_DIST_INFO';
1555 
1556 
1557   --
1558   -- Replace using cache.
1559   --
1560   --Open dist_book;
1561   --fetch dist_book into h_dist_book;
1562   --close dist_book;
1563 
1564   h_dist_book := fa_cache_pkg.fazcbc_record.distribution_source_book;
1565 
1566 --tk_util.debug('t_ind1: '||to_char(t_ind));
1567   old_i := t_ind;
1568   i := t_ind;
1569 
1570   open dist_lines;
1571   loop   -- for each distribution
1572 
1573 
1574     fetch dist_lines into
1575 	h_dist_units,
1576 	h_ccid,
1577 	h_location_id,
1578 	h_employee_number,
1579 	h_employee_name;
1580 
1581 
1582 
1583     if (dist_lines%NOTFOUND) then exit;   end if;
1584 
1585 
1586   -- FOR EACH DIST, WE:
1587   -- 1. GET ACCT AND LOC FLEX.
1588   -- 2. ALLOCATE EXPENSE AND COST EVENLY.
1589 
1590 
1591    h_mesg_name := 'FA_RX_CONCAT_SEGS';
1592    h_flex_error := 'GL#';
1593    h_ccid_error := h_ccid;
1594 
1595 
1596     fa_rx_shared_pkg.concat_acct (
1597 	struct_id => X_acct_struct,
1598 	ccid => h_ccid,
1599 	concat_string => h_concat_acct,
1600 	segarray => h_segs);
1601 
1602 
1603 
1604       h_dist_cost := round(h_current_cost * h_dist_units / h_total_units,
1605 				X_precision);
1606 
1607 
1608    h_flex_error := 'LOC#';
1609    h_ccid_error := h_location_id;
1610 
1611      fa_rx_shared_pkg.concat_location (
1612 	struct_id => X_loc_struct,
1613 	ccid => h_location_id,
1614 	concat_string => h_concat_loc,
1615 	segarray => h_segs);
1616 
1617       -- Enhancement bug 3037321
1618       select currency_code
1619       into h_currency
1620       from gl_sets_of_books
1621       where set_of_books_id = FARX_C_WD.sob_id;
1622 
1623     h_count := 0;
1624     loop  -- for each period
1625 
1626       if h_count >= X_num_pers then
1627          exit;
1628       end if;
1629 
1630        i := i + 1;
1631 
1632       h_mesg_name := 'FA_WHATIF_ASSET_NEW_DEPRN';
1633 
1634       if (g_deprn(h_count).deprn is not null) then
1635         h_dist_deprn :=
1636 	  round(g_deprn(h_count).deprn *
1637 		h_dist_units / h_total_units,
1638 		X_precision);
1639 
1640       else h_dist_deprn := null;
1641       end if;
1642 
1643 
1644       if (g_deprn(h_count).new_deprn is not null) then
1645          h_dist_new_deprn := round(g_deprn(h_count).new_deprn
1646 				*h_dist_units / h_total_units, X_precision);
1647 
1648       else h_dist_new_deprn := null;
1649       end if;
1650 
1651       if (g_deprn(h_count).new_rsv is not null) then
1652          h_dist_new_rsv := round(g_deprn(h_count).new_rsv
1653                                 *h_dist_units / h_total_units, X_precision);
1654 
1655       else h_dist_new_rsv := null;
1656       end if;
1657 
1658       -- bonus
1659       if (g_deprn(h_count).bonus_deprn is not null) then
1660         h_dist_bonus_deprn :=
1661 	  round(g_deprn(h_count).bonus_deprn *
1662 		h_dist_units / h_total_units,
1663 		X_precision);
1664 
1665       else h_dist_bonus_deprn := null;
1666       end if;
1667 
1668       if (g_deprn(h_count).new_bonus_deprn is not null) then
1669          h_dist_new_bonus_deprn := round(g_deprn(h_count).new_bonus_deprn
1670 				*h_dist_units / h_total_units, X_precision);
1671 
1672       else h_dist_new_bonus_deprn := null;
1673       end if;
1674 
1675       -- end bonus
1676 
1677       h_mesg_name := 'FA_SHARED_INSERT_FAIL';
1678 
1679       t_request_id(i)             := X_request_id;
1680       t_book_type_code(i)         := X_book;
1681       t_asset_id(i)               := X_asset_id;
1682       t_asset_number(i)           := h_asset_number;
1683       t_description(i)            := h_description;
1684       t_tag_number(i)             := h_tag_number;
1685       t_serial_number(i)          := h_serial_number;
1686       t_period_name(i)            := g_deprn(h_count).period_name;
1687       t_fiscal_year(i)            := g_deprn(h_count).fiscal_year;
1688       t_expense_acct(i)           := h_concat_acct;
1689       t_location(i)               := h_concat_loc;
1690       t_units(i)                  := h_dist_units;
1691       t_employee_name(i)          := h_employee_name;
1692       t_employee_number(i)        := h_employee_number;
1693       t_asset_key(i)              := h_concat_key;
1694       t_current_cost(i)           := h_dist_cost;
1695       t_current_prorate_conv(i)   := h_current_prorate_conv;
1696       t_current_method(i)         := h_current_method;
1697       t_current_life(i)           := h_current_life;
1698       t_current_basic_rate(i)     := h_current_basic_rate;
1699       t_current_adjusted_rate(i)  := h_current_adjusted_rate;
1700       t_current_salvage_value(i)  := h_current_salvage_value;
1701       t_depreciation(i)           := h_dist_deprn;
1702       t_new_depreciation(i)       := h_dist_new_deprn;
1703       t_created_by(i)             := X_user_id;
1704       t_creation_date(i)          := sysdate;
1705       t_last_update_date(i)       := sysdate;
1706       t_last_updated_by(i)        := X_user_id;
1707       t_last_update_login(i)      := X_login_id;
1708       t_date_placed_in_service(i) := h_current_dpis;
1709       t_category(i)               := h_concat_cat;
1710       t_accumulated_deprn(i)      := h_dist_new_rsv;
1711       t_bonus_depreciation(i)     := h_dist_bonus_deprn;
1712       t_new_bonus_depreciation(i) := h_dist_new_bonus_deprn;
1713       t_current_bonus_rule(i)     := h_current_bonus_rule;
1714       t_period_num(i)             := g_deprn(h_count).period_num;
1715       t_currency_code(i)          := h_currency;
1716 
1717       h_count := h_count + 1;
1718 
1719      h_mesg_name := 'FA_WHATIF_ASSET_DIST_INFO';
1720 
1721     end loop;
1722   end loop;
1723 
1724   close dist_lines;
1725 
1726 
1727 --tk_util.debug('t_ind2: '||to_char(t_ind));
1728 --tk_util.debug('i: '||to_char(i));
1729 
1730 
1731    t_ind := i;
1732 
1733   if (t_ind >= l_limit) or (X_last_asset) then
1734      FORALL j in t_request_id.FIRST..t_request_id.LAST
1735      INSERT INTO FA_WHATIF_ITF(
1736                    request_id
1737                  , book_type_code
1738                  , asset_id
1739                  , asset_number
1740                  , description
1741                  , tag_number
1742                  , serial_number
1743                  , period_name
1744                  , fiscal_year
1745                  , expense_acct
1746                  , location
1747                  , units
1748                  , employee_name
1749                  , employee_number
1750                  , asset_key
1751                  , current_cost
1752                  , current_prorate_conv
1753                  , current_method
1754                  , current_life
1755                  , current_basic_rate
1756                  , current_adjusted_rate
1757                  , current_salvage_value
1758                  , depreciation
1759                  , new_depreciation
1760                  , created_by
1761                  , creation_date
1762                  , last_update_date
1763                  , last_updated_by
1764                  , last_update_login
1765                  , date_placed_in_service
1766                  , category
1767                  , accumulated_deprn
1768                  , bonus_depreciation
1769                  , new_bonus_depreciation
1770                  , current_bonus_rule
1771                  , period_num
1772                  , currency_code)
1773           VALUES(  t_request_id(j)
1774                  , t_book_type_code(j)
1775                  , t_asset_id(j)
1776                  , t_asset_number(j)
1777                  , t_description(j)
1778                  , t_tag_number(j)
1779                  , t_serial_number(j)
1780                  , t_period_name(j)
1781                  , t_fiscal_year(j)
1782                  , t_expense_acct(j)
1783                  , t_location(j)
1784                  , t_units(j)
1785                  , t_employee_name(j)
1786                  , t_employee_number(j)
1787                  , t_asset_key(j)
1788                  , t_current_cost(j)
1789                  , t_current_prorate_conv(j)
1790                  , t_current_method(j)
1791                  , t_current_life(j)
1792                  , t_current_basic_rate(j)
1793                  , t_current_adjusted_rate(j)
1794                  , t_current_salvage_value(j)
1795                  , t_depreciation(j)
1796                  , t_new_depreciation(j)
1797                  , t_created_by(j)
1798                  , t_creation_date(j)
1799                  , t_last_update_date(j)
1800                  , t_last_updated_by(j)
1801                  , t_last_update_login(j)
1802                  , t_date_placed_in_service(j)
1803                  , t_category(j)
1804                  , t_accumulated_deprn(j)
1805                  , t_bonus_depreciation(j)
1806                  , t_new_bonus_depreciation(j)
1807                  , t_current_bonus_rule(j)
1808                  , t_period_num(j)
1809                  , t_currency_code(j));
1810 
1811      t_ind := 0;
1812      t_request_id.delete;
1813      t_book_type_code.delete;
1814      t_asset_id.delete;
1815      t_asset_number.delete;
1816      t_description.delete;
1817      t_tag_number.delete;
1818      t_serial_number.delete;
1819      t_period_name.delete;
1820      t_fiscal_year.delete;
1821      t_expense_acct.delete;
1822      t_location.delete;
1823      t_units.delete;
1824      t_employee_name.delete;
1825      t_employee_number.delete;
1826      t_asset_key.delete;
1827      t_current_cost.delete;
1828      t_current_prorate_conv.delete;
1829      t_current_method.delete;
1830      t_current_life.delete;
1831      t_current_basic_rate.delete;
1832      t_current_adjusted_rate.delete;
1833      t_current_salvage_value.delete;
1834      t_depreciation.delete;
1835      t_new_depreciation.delete;
1836      t_created_by.delete;
1837      t_creation_date.delete;
1838      t_last_update_date.delete;
1839      t_last_updated_by.delete;
1840      t_last_update_login.delete;
1841      t_date_placed_in_service.delete;
1842      t_category.delete;
1843      t_accumulated_deprn.delete;
1844      t_bonus_depreciation.delete;
1845      t_new_bonus_depreciation.delete;
1846      t_current_bonus_rule.delete;
1847      t_period_num.delete;
1848      t_currency_code.delete;
1849 
1850 commit;
1851   end if;
1852 
1853 
1854   errbuf := '';
1855   return ret;
1856 
1857 exception
1858 
1859   when others then
1860 
1861 
1862      if SQLCODE <> 0 then
1863        fa_Rx_conc_mesg_pkg.log(SQLERRM);
1864      end if;
1865 
1866      if (dist_lines%ISOPEN) then
1867         close dist_lines;
1868      end if;
1869 
1870 	g_deprn.delete;
1871 	fnd_message.set_name('OFA',h_mesg_name);
1872 	if h_mesg_name = 'FA_SHARED_INSERT_FAIL' then
1873           fnd_message.set_token('TABLE','FA_WHATIF_ITF',FALSE);
1874 	end if;
1875 	if h_mesg_name like 'FA_WHATIF_ASSET%' then
1876 	  fnd_message.set_token('ASSET_ID',X_asset_id,FALSE);
1877 	end if;
1878 	if h_mesg_name = 'FA_RX_CONCAT_SEGS' then
1879 	  fnd_message.set_token('CCID',h_ccid_error,FALSE);
1880 	  fnd_message.set_token('FLEX_CODE',h_flex_error,FALSE);
1881 	end if;
1882 	h_mesg_str := fnd_message.get;
1883 	fa_rx_conc_mesg_pkg.log(h_mesg_str);
1884 
1885 	retcode := 2;
1886 	return FALSE;
1887 
1888 
1889 end whatif_insert_itf;
1890 
1891 END FA_WHATIF_DEPRN_PKG;