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