DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_TXRSV_PKG

Source


1 PACKAGE BODY FA_TXRSV_PKG as
2 /* $Header: FATXRSVB.pls 120.7 2005/03/17 00:19:49 lson ship $ */
3    /*
4     * A parameter X_deprn_basis_formula may store value 'STRICT_FLAT'.
5     * This is added for bug fix 2033291.   The value comes from Tax workbench
6     * Reserve Adjustment window "Strict Calculation Method" checkbox.
7     * If it is checked, then the form pass 'STRICT_FLAT' using the new parameter
8     * to faxtxa.   Then pass to fautxa.
9     * In fautxa, when calling fautubk, pass the value and if it has value of
10     * 'STRICT_FLAT', then take existing FA_BOOKS.ANNUAL_DEPRN_ROUNDING_FLAG
11     * value, otherwise set it 'ADJ'.
12     * After comes back from fautubk, if the variable has value of 'STRICT_FLAT',
13     * then add ytd deprn amount back and subtract difference from new adjusted
14     * cost to find adjusted cost as of beginning of current fiscal year.
15     */
16 Function fautca
17      (
18      X_asset_id            fa_books.asset_id%type
19      ,X_book               fa_book_controls.book_type_code%type
20      ,X_period_counter     integer
21      ,X_is_amortized       out nocopy boolean
22      )
23    return boolean is
24 
25    Cursor c_amort is
26    SELECT 1
27    FROM FA_TRANSACTION_HEADERS TH, FA_DEPRN_PERIODS DP
28    WHERE TH.ASSET_ID = X_asset_id AND
29    TH.BOOK_TYPE_CODE = X_book AND
30    TH.TRANSACTION_SUBTYPE = 'AMORTIZED'AND
31    DP.PERIOD_COUNTER = X_period_counter AND
32    DP.BOOK_TYPE_CODE = X_book AND
33    DP.PERIOD_CLOSE_DATE < TH.DATE_EFFECTIVE;
34 
35    h_temp number := 0;
36 begin <<FAUTCA>>
37 
38 
39    open c_amort;
40    fetch c_amort into h_temp;
41    close c_amort;
42 
43    if h_temp = 1 then
44      X_is_amortized := TRUE;
45    else
46      X_is_amortized := FALSE;
47    end if;
48 
49    return (TRUE);
50 
51 exception
52      when no_data_found then
53           X_is_amortized := FALSE;
54           return (TRUE);
55 
56      when others then
57           fa_srvr_msg.add_sql_error (
58                calling_fn => 'fa_txrsv_pkg.fautca');
59           return (FALSE);
60 
61 end FAUTCA;
62 
63 Function fautubk
64      (
65      X_book               fa_book_controls.book_type_code%type
66      ,X_asset_id          fa_books.asset_id%type
67      ,X_sysdate          date
68      ,X_user_id          integer
69      ,X_login_id          integer
70      ,X_th_id          integer
71      ,X_new_raf          number
72      ,X_new_adj_cost          number
73      ,X_nbv_flag          boolean
74      ,X_rsv_flag          boolean
75      ,X_mrc_sob_type_code varchar2
76      ,X_deprn_basis_formula varchar2 default null
77      )
78 return boolean is
79 
80    h_rsv_flag integer;
81    h_nbv_flag integer;
82 
83 begin <<FAUTUBK>>
84 
85    if (X_nbv_flag) then
86      h_nbv_flag := 1;
87    else
88      h_nbv_flag := 0;
89    end if;
90 
91    if (X_rsv_flag) then
92      h_rsv_flag := 1;
93    else
94      h_rsv_flag := 0;
95    end if;
96 
97 
98    /*
99     * Following 9 columns have been missing from insert statements below.
100     *        ANNUAL_DEPRN_ROUNDING_FLAG,
101     *        PERCENT_SALVAGE_VALUE,            ALLOWED_DEPRN_LIMIT,
102     *        ALLOWED_DEPRN_LIMIT_AMOUNT,       PERIOD_COUNTER_LIFE_COMPLETE,
103     *        ADJUSTED_RECOVERABLE_COST,        EOFY_ADJ_COST,
104     *        EOFY_FORMULA_FACTOR,              GROUP_ASSET_ID,
105     * These are added at the same time fixing bug 2033291 but nothing to
106     * do with the problem except ANNUAL_DEPRN_ROUNDING_FLAG.
107     */
108    if (X_mrc_sob_type_code = 'R') then
109 
110       UPDATE FA_BOOKS_MRC_V
111          SET DATE_INEFFECTIVE = X_sysdate,
112              TRANSACTION_HEADER_ID_OUT = X_th_id,
113              LAST_UPDATE_DATE = X_sysdate,
114              LAST_UPDATED_BY = NVL (X_user_id, -1),
115              LAST_UPDATE_LOGIN = X_login_id
116        WHERE ASSET_ID = X_asset_id
117          AND BOOK_TYPE_CODE = X_book
118          AND DATE_INEFFECTIVE IS NULL;
119 
120       INSERT INTO FA_BOOKS_MRC_V (
121              BOOK_TYPE_CODE,                   ASSET_ID,
122              DATE_PLACED_IN_SERVICE,           DATE_EFFECTIVE,
123              DEPRN_START_DATE,                 DEPRN_METHOD_CODE,
124              LIFE_IN_MONTHS,                   RATE_ADJUSTMENT_FACTOR,
125              ADJUSTED_COST,                    COST,
126              ORIGINAL_COST,                    SALVAGE_VALUE,
127              PRORATE_CONVENTION_CODE,          PRORATE_DATE,
128              COST_CHANGE_FLAG,                 ADJUSTMENT_REQUIRED_STATUS,
129              CAPITALIZE_FLAG,                  RETIREMENT_PENDING_FLAG,
130              DEPRECIATE_FLAG,                  LAST_UPDATE_DATE,
131              LAST_UPDATED_BY,                  DATE_INEFFECTIVE,
132              TRANSACTION_HEADER_ID_IN,         TRANSACTION_HEADER_ID_OUT,
133              ITC_AMOUNT_ID,                    ITC_AMOUNT,
134              RETIREMENT_ID,                    TAX_REQUEST_ID,
135              ITC_BASIS,                        BASIC_RATE,
136              ADJUSTED_RATE,                    BONUS_RULE,
137              CEILING_NAME,                     RECOVERABLE_COST,
138              LAST_UPDATE_LOGIN,                FULLY_RSVD_REVALS_COUNTER,
139              IDLED_FLAG,                       PERIOD_COUNTER_CAPITALIZED,
140              PERIOD_COUNTER_FULLY_RESERVED,    PERIOD_COUNTER_FULLY_RETIRED,
141              PRODUCTION_CAPACITY,              REVAL_AMORTIZATION_BASIS,
142              REVAL_CEILING,                    UNIT_OF_MEASURE,
143              UNREVALUED_COST,
144              ANNUAL_DEPRN_ROUNDING_FLAG,
145              PERCENT_SALVAGE_VALUE,            ALLOWED_DEPRN_LIMIT,
146              ALLOWED_DEPRN_LIMIT_AMOUNT,       PERIOD_COUNTER_LIFE_COMPLETE,
147              ADJUSTED_RECOVERABLE_COST,        EOFY_ADJ_COST,
148              EOFY_FORMULA_FACTOR,              GROUP_ASSET_ID,
149              SHORT_FISCAL_YEAR_FLAG,           CONVERSION_DATE,
150              ORIGINAL_DEPRN_START_DATE,
151              REMAINING_LIFE1,                  REMAINING_LIFE2,
152              OLD_ADJUSTED_COST,                FORMULA_FACTOR,
153              SALVAGE_TYPE,                     DEPRN_LIMIT_TYPE)
154       SELECT BOOK_TYPE_CODE,                   ASSET_ID,
155              DATE_PLACED_IN_SERVICE,           X_sysdate,
156              DEPRN_START_DATE,                 DEPRN_METHOD_CODE,
157              LIFE_IN_MONTHS,
158              decode(h_nbv_flag, 1,
159                     X_new_raf, RATE_ADJUSTMENT_FACTOR),
160                   decode(h_nbv_flag, 1, X_new_adj_cost, ADJUSTED_COST),
161              COST,
162              ORIGINAL_COST,                    SALVAGE_VALUE,
163              PRORATE_CONVENTION_CODE,          PRORATE_DATE,
164              COST_CHANGE_FLAG,                 ADJUSTMENT_REQUIRED_STATUS,
165              CAPITALIZE_FLAG,                  RETIREMENT_PENDING_FLAG,
166              DEPRECIATE_FLAG,                  X_sysdate,
167              NVL (X_user_id, -1),              NULL,
168              X_th_id,                          NULL,
169              ITC_AMOUNT_ID,                    ITC_AMOUNT,
170              RETIREMENT_ID,                    TAX_REQUEST_ID,
171              ITC_BASIS,                        BASIC_RATE,
172              ADJUSTED_RATE,                    BONUS_RULE,
173              CEILING_NAME,                     RECOVERABLE_COST,
174              LAST_UPDATE_LOGIN,                FULLY_RSVD_REVALS_COUNTER,
175              IDLED_FLAG,                       PERIOD_COUNTER_CAPITALIZED,
176              decode(h_rsv_flag, 1, NULL, PERIOD_COUNTER_FULLY_RESERVED),
177              PERIOD_COUNTER_FULLY_RETIRED,
178              PRODUCTION_CAPACITY,              REVAL_AMORTIZATION_BASIS,
179              REVAL_CEILING,                    UNIT_OF_MEASURE,
180              UNREVALUED_COST,
181              decode(X_deprn_basis_formula, 'STRICT_FLAT', ANNUAL_DEPRN_ROUNDING_FLAG,
182                                                           'ADJ'), -- ANNUAL_DEPRN_ROUNDING_FLAG,
183              PERCENT_SALVAGE_VALUE,            ALLOWED_DEPRN_LIMIT,
184              ALLOWED_DEPRN_LIMIT_AMOUNT,
185              decode(h_rsv_flag, 1, NULL,PERIOD_COUNTER_LIFE_COMPLETE),
186              ADJUSTED_RECOVERABLE_COST,        EOFY_ADJ_COST,
187              EOFY_FORMULA_FACTOR,              GROUP_ASSET_ID,
188              SHORT_FISCAL_YEAR_FLAG,           CONVERSION_DATE,
189              ORIGINAL_DEPRN_START_DATE,
190              REMAINING_LIFE1,                  REMAINING_LIFE2,
191              OLD_ADJUSTED_COST,                FORMULA_FACTOR,
192              SALVAGE_TYPE,                     DEPRN_LIMIT_TYPE
193         FROM FA_BOOKS BKS
194        WHERE ASSET_ID = X_asset_id
195          AND BOOK_TYPE_CODE = X_book
196          AND TRANSACTION_HEADER_ID_OUT = X_th_id;
197 
198    else
199 
200       UPDATE FA_BOOKS
201          SET DATE_INEFFECTIVE = X_sysdate,
202              TRANSACTION_HEADER_ID_OUT = X_th_id,
203              LAST_UPDATE_DATE = X_sysdate,
204              LAST_UPDATED_BY = NVL (X_user_id, -1),
205              LAST_UPDATE_LOGIN = X_login_id
206        WHERE ASSET_ID = X_asset_id
207          AND BOOK_TYPE_CODE = X_book
208          AND DATE_INEFFECTIVE IS NULL;
209 
210       INSERT INTO FA_BOOKS (
211              BOOK_TYPE_CODE,                   ASSET_ID,
212              DATE_PLACED_IN_SERVICE,           DATE_EFFECTIVE,
213              DEPRN_START_DATE,                 DEPRN_METHOD_CODE,
214              LIFE_IN_MONTHS,                   RATE_ADJUSTMENT_FACTOR,
215              ADJUSTED_COST,                    COST,
216              ORIGINAL_COST,                    SALVAGE_VALUE,
217              PRORATE_CONVENTION_CODE,          PRORATE_DATE,
218              COST_CHANGE_FLAG,                 ADJUSTMENT_REQUIRED_STATUS,
219              CAPITALIZE_FLAG,                  RETIREMENT_PENDING_FLAG,
220              DEPRECIATE_FLAG,                  LAST_UPDATE_DATE,
221              LAST_UPDATED_BY,                  DATE_INEFFECTIVE,
222              TRANSACTION_HEADER_ID_IN,         TRANSACTION_HEADER_ID_OUT,
223              ITC_AMOUNT_ID,                    ITC_AMOUNT,
224              RETIREMENT_ID,                    TAX_REQUEST_ID,
225              ITC_BASIS,                        BASIC_RATE,
226              ADJUSTED_RATE,                    BONUS_RULE,
227              CEILING_NAME,                     RECOVERABLE_COST,
228              LAST_UPDATE_LOGIN,                FULLY_RSVD_REVALS_COUNTER,
229              IDLED_FLAG,                       PERIOD_COUNTER_CAPITALIZED,
230              PERIOD_COUNTER_FULLY_RESERVED,    PERIOD_COUNTER_FULLY_RETIRED,
231              PRODUCTION_CAPACITY,              REVAL_AMORTIZATION_BASIS,
232              REVAL_CEILING,                    UNIT_OF_MEASURE,
233              UNREVALUED_COST,
234              ANNUAL_DEPRN_ROUNDING_FLAG,
235              PERCENT_SALVAGE_VALUE,            ALLOWED_DEPRN_LIMIT,
236              ALLOWED_DEPRN_LIMIT_AMOUNT,       PERIOD_COUNTER_LIFE_COMPLETE,
237              ADJUSTED_RECOVERABLE_COST,        EOFY_ADJ_COST,
238              EOFY_FORMULA_FACTOR,              GROUP_ASSET_ID,
239              SHORT_FISCAL_YEAR_FLAG,           CONVERSION_DATE,
240              ORIGINAL_DEPRN_START_DATE,
241              REMAINING_LIFE1,                  REMAINING_LIFE2,
242              OLD_ADJUSTED_COST,                FORMULA_FACTOR,
243              SALVAGE_TYPE,                     DEPRN_LIMIT_TYPE)
244       SELECT BOOK_TYPE_CODE,                   ASSET_ID,
245              DATE_PLACED_IN_SERVICE,           X_sysdate,
246              DEPRN_START_DATE,                 DEPRN_METHOD_CODE,
247              LIFE_IN_MONTHS,
248               decode(h_nbv_flag, 1,
249                     X_new_raf, RATE_ADJUSTMENT_FACTOR),
250                   decode(h_nbv_flag, 1, X_new_adj_cost, ADJUSTED_COST),
251              COST,
252              ORIGINAL_COST,                    SALVAGE_VALUE,
253              PRORATE_CONVENTION_CODE,          PRORATE_DATE,
254              COST_CHANGE_FLAG,                 ADJUSTMENT_REQUIRED_STATUS,
255              CAPITALIZE_FLAG,                  RETIREMENT_PENDING_FLAG,
256              DEPRECIATE_FLAG,                  X_sysdate,
257              NVL (X_user_id, -1),              NULL,
258              X_th_id,                          NULL,
259              ITC_AMOUNT_ID,                    ITC_AMOUNT,
260              RETIREMENT_ID,                    TAX_REQUEST_ID,
261              ITC_BASIS,                        BASIC_RATE,
262              ADJUSTED_RATE,                    BONUS_RULE,
263              CEILING_NAME,                     RECOVERABLE_COST,
264              LAST_UPDATE_LOGIN,                FULLY_RSVD_REVALS_COUNTER,
265              IDLED_FLAG,                       PERIOD_COUNTER_CAPITALIZED,
266              decode(h_rsv_flag, 1, NULL, PERIOD_COUNTER_FULLY_RESERVED),
267              PERIOD_COUNTER_FULLY_RETIRED,
268              PRODUCTION_CAPACITY,              REVAL_AMORTIZATION_BASIS,
269              REVAL_CEILING,                    UNIT_OF_MEASURE,
270              UNREVALUED_COST,
271              decode(X_deprn_basis_formula, 'STRICT_FLAT', ANNUAL_DEPRN_ROUNDING_FLAG,
272                                                           'ADJ'), -- ANNUAL_DEPRN_ROUNDING_FLAG,
273              PERCENT_SALVAGE_VALUE,            ALLOWED_DEPRN_LIMIT,
274              ALLOWED_DEPRN_LIMIT_AMOUNT,
275              decode(h_rsv_flag, 1, NULL,PERIOD_COUNTER_LIFE_COMPLETE),
276              ADJUSTED_RECOVERABLE_COST,        EOFY_ADJ_COST,
277              EOFY_FORMULA_FACTOR,              GROUP_ASSET_ID,
278              SHORT_FISCAL_YEAR_FLAG,           CONVERSION_DATE,
279              ORIGINAL_DEPRN_START_DATE,
280              REMAINING_LIFE1,                  REMAINING_LIFE2,
281              OLD_ADJUSTED_COST,                FORMULA_FACTOR,
282              SALVAGE_TYPE,                     DEPRN_LIMIT_TYPE
283         FROM FA_BOOKS BKS
284        WHERE ASSET_ID = X_asset_id
285          AND BOOK_TYPE_CODE = X_book
286          AND TRANSACTION_HEADER_ID_OUT = X_th_id;
287 
288    end if;  /* end primary or reporting */
289 
290    return (TRUE);
291 
292 exception
293      when others then
294           fa_srvr_msg.add_sql_error (
295                calling_fn => 'fa_txrsv_pkg.fautubk');
296           return (FALSE);
297 end FAUTUBK;
298 
299 Function fautgpr
300      (
301      X_old_deprn_rsv_taken     OUT NOCOPY number
302      ,X_old_adj_cost          OUT NOCOPY number
303      ,X_asset_id          fa_books.asset_id%type
304      ,X_book               fa_book_controls.book_type_code%type
305      ,X_period_ctr          integer
306      ,X_mrc_sob_type_code   varchar2
307      )
308 return boolean is
309 
310    h_dpr fa_std_types.fa_deprn_row_struct;
311    h_dummy_bool boolean;
312    begin <<FAUTGPR>>
313 
314    h_dpr.asset_id := X_asset_id;
315    h_dpr.book := X_book;
316    h_dpr.dist_id := 0;
317    h_dpr.period_ctr := X_period_ctr;
318    h_dpr.mrc_sob_type_code := X_mrc_sob_type_code;
319 
320    /*
321     * Use the Query Fin Info function to get the reserve as of
322     * this period.
323    */
324    FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT (
325         h_dpr,
326         'STANDARD',
327         FALSE,
328         h_dummy_bool,
329         'fa_txrsv_pkg.fautgpr',
330         -1);
331 
332    if not (h_dummy_bool) then
333         fa_srvr_msg.add_message (calling_fn => 'fa_txrsv_pkg.fautgpr');
334         return (FALSE);
335    end if;
336 
337    X_old_deprn_rsv_taken := h_dpr.deprn_rsv;
338    X_old_adj_cost := h_dpr.adj_cost;
339 
340    return (TRUE);
341 
342 exception
343      when others then
344           fa_srvr_msg.add_sql_error (
345                calling_fn => 'fa_txrsv_pkg.fautgpr');
346           return (FALSE);
347 end FAUTGPR;
348 
349 Function fautxa
350      (
351      X_fin_info_ptr               IN OUT NOCOPY fa_std_types.fin_info_struct,
352      X_old_ytd_deprn_rsv          number,
353      X_new_ytd_deprn_rsv          number,
354      X_fiscal_year                integer,
355      X_new_raf_out                OUT NOCOPY number,
356      X_new_adj_cost_out           OUT NOCOPY number,
357      X_was_fully_rsv              boolean,
358      X_fail_okay                  IN OUT NOCOPY number,
359      X_mrc_sob_type_code          varchar2,
360      X_deprn_basis_formula        varchar2 default null
361      )
362 return boolean is
363 
364    CURSOR fiscal_year_cr is
365      SELECT   DP.FISCAL_YEAR, MAX(DP.PERIOD_NUM),MAX(DP.PERIOD_COUNTER)
366      FROM     FA_DEPRN_PERIODS DP
367      WHERE    DP.BOOK_TYPE_CODE = X_fin_info_ptr.book
368      AND      DP.FISCAL_YEAR > X_fiscal_year
369      AND      DP.PERIOD_CLOSE_DATE IS NOT NULL
370      GROUP BY DP.FISCAL_YEAR
371      ORDER BY MIN(DP.PERIOD_OPEN_DATE);
372 
373    -- Local variables
374    dpr fa_std_types.dpr_struct;
375    dpr_out fa_std_types.dpr_out_struct;
376    dpr_row fa_std_types.fa_deprn_row_struct;
377    -- TOBEDONE - change this to point to fa_std_types
378    -- adj fa_std_types.fa_adj_row_struct;
379    adj FA_ADJUST_TYPE_PKG.fa_adj_row_struct;
380 
381    new_deprn_rsv number;        -- new ltd deprn reserve at end of fy
382    old_deprn_rsv_taken number;  -- the reserve previously calculated
383    last_years_old_deprn number; -- last fiscal yr's old_deprn_rsv_taken
384    new_adj_cost number;         -- new adjusted cost for the fy
385    old_adj_cost number;         -- old adjusted cost for the fy
386    new_rate_adj_factor number;  -- new raf calculated by deprn
387    adj_amount number;           -- the amount to adjust by for a fy
388    total_adjs number;           -- sum of all adj_amounts for all fys
389    new_ann_adj_exp number;      -- annualized expense after adjustment
390    cur_rsv number;              -- open period reserve
391    is_amort_flag boolean;       -- TRUE if amort adj done on asset
392    rsv_flag boolean := FALSE;   -- 1 if asset is no longer fully rsv'd
393    pers_per_yr integer;         -- the number of periods per fiscal year
394    deprn_basis_rule varchar2(40);    -- Depreciation basis rule
395    user_id integer;             -- foundation userid
396    login_id integer;            -- login id
397    mesg_name varchar2(24);      -- NLS message name
398    period_ctr_adjusted integer;
399    ret_val varchar(128);        -- temp value for cache call
400    cur_fiscal_yr integer;       -- the current fiscal year
401    last_updated_by integer;
402    last_update_login integer;
403    h_fiscal_year integer;
404    h_period_counter integer;
405    h_p_cl_end integer;
406    rsv_acct varchar2(30);       -- Deprn_Reserve_Acct
407    exp_acct varchar(30);        -- Deprn_Expense_Acct
408    adj_acct varchar(30);        -- Deprn_Adjustment_Acct
409 
410    h_dummy_int integer;
411    h_dummy_varch varchar2(124);
412    h_dummy_bool boolean;
413    h_dummy_dpr_arr fa_std_types.dpr_arr_type;
414 
415    l_signed_adj_amount   NUMBER;   -- Added for bug 3045324.
416 
417    fautxa_error exception;
418 
419 begin <<FAUTXA>>
420 
421 
422    -- CIP assets should not have reserve adjustments
423    if X_fin_info_ptr.asset_type = 'CIP' then
424         X_fail_okay := X_fail_okay + 1;
425         mesg_name := 'FA_TAX_ASSET_IS_CIP';
426         raise fautxa_error;
427    end if;
428 
429    if not fa_cache_pkg.fazcbc (X_fin_info_ptr.book) then
430         raise fautxa_error;
431    end if;
432 
433    if fa_cache_pkg.fazcbc_record.allow_deprn_adjustments = 'NO' then
434         mesg_name := 'FA_ADJ_RSV_ADJ_NOT_ALLOWED';
435         raise fautxa_error;
436    end if;
437 
438    -- Find the first period adjusted
439    SELECT MAX(DP.PERIOD_COUNTER)
440    INTO period_ctr_adjusted
441    FROM FA_DEPRN_PERIODS DP
442    WHERE DP.BOOK_TYPE_CODE = X_fin_info_ptr.book
443    AND DP.FISCAL_YEAR = X_fiscal_year;
444 
445 
446    /*
447     * Check if an amortized cost change was done
448     * between the period adjusted and the current open period;
449     * if so, return error
450    */
451    if not fautca
452         (
453         X_fin_info_ptr.asset_id,
454         X_fin_info_ptr.book,
455         period_ctr_adjusted,
456         is_amort_flag
457         ) then
458         raise fautxa_error;
459    end if;
460 
461    if (is_amort_flag) then
462         X_fail_okay := X_fail_okay + 1;
463         mesg_name := 'FA_TAX_NO_AMT_COST';
464         raise fautxa_error;
465    end if;
466 
467 
468    -- Initialize variables
469    new_deprn_rsv := 0;
470    old_deprn_rsv_taken := 0;
471    last_years_old_deprn := 0;
472    new_adj_cost := 0;
473    new_rate_adj_factor := 0;
474    adj_amount := 0;
475    total_adjs := 0;
476    new_ann_adj_exp := 0;
477    X_fin_info_ptr.adj_capacity := 0;
478 
479 
480    -- Build the depreciation structure
481    if not fa_exp_pkg.faxbds
482         (
483         X_fin_info_ptr,
484         dpr,
485         h_dummy_varch,
486         new_deprn_rsv,
487         FALSE,
488         X_mrc_sob_type_code
489         ) then
490         raise fautxa_error;
491    end if;
492 
493 
494    -- Get calendar period information from cache
495    if not fa_cache_pkg.fazcct (dpr.calendar_type) then
496         raise fautxa_error;
497    end if;
498    pers_per_yr := fa_cache_pkg.fazcct_record.NUMBER_PER_FISCAL_YEAR;
499 
500    -- Get current fiscal year and Deprn_Adjustment_Acct from FA_BOOK_CONTROLS
501    if not fa_cache_pkg.fazcbc(X_fin_info_ptr.book) then
502         raise fautxa_error;
503    end if;
504    cur_fiscal_yr := fa_cache_pkg.fazcbc_record.CURRENT_FISCAL_YEAR;
505    adj_acct := fa_cache_pkg.fazcbc_record.DEPRN_ADJUSTMENT_ACCT;
506 
507    -- Get the Deprn Accounts for insertion into FA_ADJ.
508    if not fa_cache_pkg.fazccb (
509         X_fin_info_ptr.book,
510         X_fin_info_ptr.category_id
511         ) then
512         raise fautxa_error;
513    end if;
514    rsv_acct := fa_cache_pkg.fazccb_record.DEPRN_RESERVE_ACCT;
515    exp_acct := fa_cache_pkg.fazccb_record.DEPRN_EXPENSE_ACCT;
516 
517 
518    -- Get the deprn basis rule
519    if not fa_cache_pkg.fazccmt (
520         dpr.method_code,
521         dpr.life
522         ) then
523         raise fautxa_error;
524    end if;
525 
526 
527    deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
528 
529 
530    -- Calculate the LTD deprn_rsv
531    dpr_row.asset_id := X_fin_info_ptr.asset_id;
532    dpr_row.book := X_fin_info_ptr.book;
533    dpr_row.dist_id := 0;
534    dpr_row.period_ctr := 0;
535    dpr_row.mrc_sob_type_code := X_mrc_sob_type_code;
536 
537 
538    -- TOBEDONE - Check this section out
539    FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT (
540         dpr_row,
541         'ADJUSTED',
542         FALSE,
543         h_dummy_bool,
544         'fa_txrsv_pkg.fautgpr',
545         -1);
546 
547 
548 
549    if not (h_dummy_bool) then
550         raise fautxa_error;
551    elsif (dpr_row.period_ctr <> 0) then
552         cur_rsv := dpr_row.deprn_rsv;
553    else
554         raise fautxa_error;
555    end if;
556 
557 
558    dpr_row.asset_id := X_fin_info_ptr.asset_id;
559    dpr_row.book := X_fin_info_ptr.book;
560    dpr_row.dist_id := 0;
561    dpr_row.period_ctr := period_ctr_adjusted;
562    dpr_row.mrc_sob_type_code := X_mrc_sob_type_code;
563 
564 
565    FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT (
566         dpr_row,
567         'ADJUSTED',
568         FALSE,
569         h_dummy_bool,
570         'fa_txrsv_pkg.fautgpr',
571         -1);
572 
573    if not (h_dummy_bool) then
574         raise fautxa_error;
575    elsif (dpr_row.period_ctr <> 0) then
576         old_deprn_rsv_taken := dpr_row.deprn_rsv;
577    else
578         raise fautxa_error;
579    end if;
580 
581    -- Initialize variables for loop
582    adj_amount := X_new_ytd_deprn_rsv - X_old_ytd_deprn_rsv;
583    new_deprn_rsv := old_deprn_rsv_taken + adj_amount;
584    new_rate_adj_factor := X_fin_info_ptr.rate_adj_factor;
585    new_adj_cost := X_fin_info_ptr.rec_cost - new_deprn_rsv;
586    total_adjs := adj_amount;
587 
588    -- Make sure the reserve doesn't exceed recoverable cost
589 
590    -- For NBV check for current open period. Also check end of fy since
591    -- following fy's will be checked by deprn engine calls
592    if (deprn_basis_rule = fa_std_types.FAD_DBR_COST) then
593         if  (X_fin_info_ptr.rec_cost > 0 and
594              X_fin_info_ptr.rec_cost < (cur_rsv + adj_amount)) or
595              (X_fin_info_ptr.rec_cost < 0 and
596              X_fin_info_ptr.rec_cost > (cur_rsv + adj_amount)) then
597              adj_amount := X_fin_info_ptr.rec_cost;
598         end if;
599    else
600         if  (X_fin_info_ptr.rec_cost > 0 and
601              X_fin_info_ptr.rec_cost < new_deprn_rsv) or
602              (X_fin_info_ptr.rec_cost < 0 and
603              X_fin_info_ptr.rec_cost > new_deprn_rsv) then
604              adj_amount := X_fin_info_ptr.rec_cost;
605         end if;
606    end if;
607 
608 
609    /*
610     * Insert the adjustment row for the first fiscal year adjusted
611     * using the Insert into FA_ADJUSTMENTS function
612     */
613    adj.transaction_header_id := X_fin_info_ptr.transaction_id;
614    adj.source_type_code := 'TAX';
615    adj.code_combination_id := 0;
616    adj.book_type_code := X_fin_info_ptr.book;
617    adj.period_counter_created := X_fin_info_ptr.period_ctr;
618    adj.asset_id := X_fin_info_ptr.asset_id;
619    adj.adjustment_amount := abs(adj_amount);
620    adj.annualized_adjustment := 0;
621    adj.period_counter_adjusted := period_ctr_adjusted;
622    adj.distribution_id := 0;
623    adj.last_update_date := X_fin_info_ptr.current_time;
624    adj.current_units := X_fin_info_ptr.units;
625    adj.selection_mode := fa_std_types.FA_AJ_ACTIVE;
626    adj.flush_adj_flag := TRUE;
627    adj.gen_ccid_flag := TRUE;
628    adj.leveling_flag := TRUE;
629    adj.asset_invoice_id := 0;
630    adj.account_type := 'DEPRN_RESERVE_ACCT';
631    adj.adjustment_type := 'RESERVE';
632    adj.account := rsv_acct;
633    if (adj_amount < 0) then
634         adj.debit_credit_flag := 'DR';
635    else
636         adj.debit_credit_flag := 'CR';
637    end if;
638 
639    adj.mrc_sob_type_code := X_mrc_sob_type_code;
640 
641    if not FA_INS_ADJUST_PKG.faxinaj
642               (adj_ptr_passed => adj) then
643         raise fautxa_error;
644    end if;
645 
646    adj.account_type := 'DEPRN_ADJUSTMENT_ACCT';
647    adj.adjustment_type := 'DEPRN ADJUST';
648    adj.account := adj_acct;
649    if (adj_amount < 0) then
650         adj.debit_credit_flag := 'CR';
651    else
652         adj.debit_credit_flag := 'DR';
653    end if;
654 
655    adj.mrc_sob_type_code := X_mrc_sob_type_code;
656 
657    if not FA_INS_ADJUST_PKG.faxinaj
658               (adj_ptr_passed => adj) then
659         raise fautxa_error;
660    end if;
661 
662 
663    /*
664     * We're done if deprn method is not based on the net book value;
665     * (We don't want to insert any more FA_ADJUSTMENTS rows, and
666     * don't want to terminate and insert FA_BOOKS rows, for non NBV-based
667     * assets unless asset is no longer fully reserved.
668     */
669    if deprn_basis_rule = fa_std_types.FAD_DBR_COST then
670         if (X_was_fully_rsv and new_deprn_rsv < X_fin_info_ptr.rec_cost) then
671              if not fautubk (
672                   X_fin_info_ptr.book,
673                   X_fin_info_ptr.asset_id,
674                   X_fin_info_ptr.current_time,
675                   user_id,
676                   login_id,
677                   X_fin_info_ptr.transaction_id,
678                   new_rate_adj_factor,
679                   new_adj_cost,
680                   FALSE,
681                   TRUE,
682                   X_mrc_sob_type_code,
683                   X_deprn_basis_formula
684                   ) then
685                   raise fautxa_error;
686              end if;
687         end if;
688         X_new_raf_out := new_rate_adj_factor;
689         X_new_adj_cost_out := new_adj_cost;
690         return (TRUE);
691    end if;
692 
693 
694    /*
695     * Main driving loop for this program. Loop for each fiscal year after
696     * the adjustment; recalculate reserve up until the last closed period
697     */
698    open fiscal_year_cr;
699    loop
700         fetch fiscal_year_cr into h_fiscal_year,h_p_cl_end,h_period_counter;
701         exit when fiscal_year_cr%notfound;
702 
703         -- Set the deprn struct parms to calculate deprn reserve
704         dpr.y_begin := h_fiscal_year;
705         dpr.y_end := h_fiscal_year;
706         dpr.p_cl_begin := 1;
707         dpr.p_cl_end := h_p_cl_end;
708         dpr.deprn_rsv := new_deprn_rsv;
709         dpr.adj_cost := new_adj_cost;
710 		dpr.mrc_sob_type_code := X_mrc_sob_type_code;
711 
712         -- Call deprn engine to calc new reserve
713         if not fa_cde_pkg.faxcde (
714              dpr,
715              h_dummy_dpr_arr,
716              dpr_out,
717              fa_std_types.FA_DPR_NORMAL
718              ) then
719              raise fautxa_error;
720         end if;
721 
722 
723         -- Set the new_adj_cost and new_deprn_rsv to the value
724         -- recalculated by deprn
725         new_adj_cost := dpr_out.new_adj_cost;
726         new_deprn_rsv := dpr_out.new_deprn_rsv;
727 
728         -- Get the adjusted cost and the reserve previously taken as of
729         -- the end of the fiscal year, or the last closed deprn period
730         last_years_old_deprn := old_deprn_rsv_taken;
731 
732         if not fautgpr (
733              old_deprn_rsv_taken,
734              old_adj_cost,
735              X_fin_info_ptr.asset_id,
736              X_fin_info_ptr.book,
737              h_period_counter,
738              X_mrc_sob_type_code ) then
739              raise fautxa_error;
740         end if;
741 
742         -- Calculate the adjustment amount:
743         -- adj_amount = new_deprn_rsv - (old_deprn_rsv_taken + total_adjs)
744         adj_amount := new_deprn_rsv - (old_deprn_rsv_taken + total_adjs);
745 
746         -- Calculate the new adjusted cost
747         -- new_adj_cost = X_fin_info_ptr.rec_cost - new_deprn_rsv
748         new_adj_cost := X_fin_info_ptr.rec_cost - new_deprn_rsv;
749 
750         -- Increment the total adjustments so far
751         -- total_adjs += adj_amount
752         total_adjs := total_adjs + adj_amount;
753 
754 
755         -- Process the adjustment rows for this fiscal year
756         /*
757          * Call the Insert into FA_ADJUSTMENTS function
758          * for EXPENSE adjustment; use the CCID from FA_DISTRIBUTION_HISTORY,
759          * so set adj.ccid = 0 and gen_ccid_flag = FALSE
760          */
761         adj.transaction_header_id := X_fin_info_ptr.transaction_id;
762         adj.source_type_code := 'TAX';
763         adj.adjustment_type := 'EXPENSE';
764         adj.code_combination_id := 0;
765         adj.book_type_code := X_fin_info_ptr.book;
766         adj.period_counter_created := X_fin_info_ptr.period_ctr;
767         adj.asset_id := X_fin_info_ptr.asset_id;
768         adj.adjustment_amount := abs(adj_amount);
769         adj.period_counter_adjusted := h_period_counter;
770         adj.distribution_id := 0;
771 
772         /*
773          * If this is the current fiscal year, then annualized adjustment
774          * is the difference between the new annualized expense and
775          * the extrapolated pre-tax-adjustment annualized expense amounts.
776          */
777         if cur_fiscal_yr = h_fiscal_year then
778              new_ann_adj_exp := dpr_out.ann_adj_exp;
779              -- reset deprn struct parms to calculate what the
780              -- annulalized expense would have been
781              dpr.p_cl_end := pers_per_yr;
782              dpr.deprn_rsv := last_years_old_deprn;
783              dpr.adj_cost := old_adj_cost;
784 			 dpr.mrc_sob_type_code := X_mrc_sob_type_code;
785 
786              -- Call deprn engine to calc expense
787              if not fa_cde_pkg.faxcde (
788                   dpr, h_dummy_dpr_arr, dpr_out, fa_std_types.FA_DPR_NORMAL
789                   ) then
790                   raise fautxa_error;
791              end if;
792 
793              adj.annualized_adjustment := new_ann_adj_exp - dpr_out.ann_adj_exp;
794         else
795              adj.annualized_adjustment := 0;
796         end if;
797 
798 
799         adj.last_update_date := X_fin_info_ptr.current_time;
800         adj.current_units := X_fin_info_ptr.units;
801         adj.selection_mode := fa_std_types.FA_AJ_ACTIVE;
802         adj.flush_adj_flag := TRUE;
803         adj.gen_ccid_flag := TRUE;
804         adj.asset_invoice_id := 0;
805         adj.leveling_flag := TRUE;
806         adj.account_type := 'DEPRN_EXPENSE_ACCT';
807         adj.account := exp_acct;
808         if (adj_amount < 0) then
809              adj.debit_credit_flag := 'CR';
810         else
811              adj.debit_credit_flag := 'DR';
812         end if;
813 
814         adj.mrc_sob_type_code := X_mrc_sob_type_code;
815 
816         if not FA_INS_ADJUST_PKG.faxinaj
817               (adj_ptr_passed => adj) then
818              raise fautxa_error;
819         end if;
820 
821 
822    end loop;
823 
824 
825    close fiscal_year_cr;
826 
827    /*
828     * This is like Strict Calculation Basis
829     * If user choose to do this, then reset adjusted cost to
830     * the adjusted cost as of beggining of current fiscal year
831     */
832    -- Bug 3045324 : Added the if ..else stmt.
833 
834    if (adj.debit_credit_flag = 'DR') then
835       l_signed_adj_amount := -1 * nvl(adj.adjustment_amount, 0);
836    else
837       l_signed_adj_amount := nvl(adj.adjustment_amount, 0);
838    end if;
839 
840    /* Bug 3523326 : Added condition dpr.ytd_deprn <> 0 */
841 
842    if (X_deprn_basis_formula = 'STRICT_FLAT') and
843        nvl(dpr.ytd_deprn, 0) <> 0 then
844      new_adj_cost := new_adj_cost + nvl(dpr.ytd_deprn, 0) - nvl(l_signed_adj_amount, 0);
845    end if;
846 
847    /*
848     * terminate the current FA_BOOKS row; and insert a new one, with
849     * the updated adjusted cost and rate adjustment factor
850     * we only do this for assets with an NBV-based deprn method
851     * and if this is not the year of adjustment
852     */
853    if new_deprn_rsv < X_fin_info_ptr.rec_cost then
854         rsv_flag := TRUE;
855    end if;
856 
857    if not fautubk (
858         X_fin_info_ptr.book,
859         X_fin_info_ptr.asset_id,
860         X_fin_info_ptr.current_time,
861         user_id,
862         login_id,
863         X_fin_info_ptr.transaction_id,
864         new_rate_adj_factor,
865         new_adj_cost, TRUE, rsv_flag,
866         X_mrc_sob_type_code,
867         X_deprn_basis_formula
868         ) then
869         raise fautxa_error;
870    end if;
871 
872 
873    return (TRUE);
874 
875    exception
876         when fautxa_error then
877              if (X_fail_okay > 0) then
878                   fa_srvr_msg.add_message (
879                        calling_fn => 'fa_txrsv_pkg.fautxa',
880                        name => 'FA_TAX_ASSET_WARN',
881                        token1 => 'VARIABLE',
882                        value1 => 'ASSET',
883                        token2 => 'VALUE',
884                        value2 => X_fin_info_ptr.asset_number,
885                        translate => FALSE
886                        );
887              else
888                   fa_srvr_msg.add_message (
889                        calling_fn => 'fa_txrsv_pkg.fautxa',
890                        name => 'FA_TAX_ASSET_FAIL',
891                        token1 => 'VARIABLE',
892                        value1 => 'ASSET',
893                        token2 => 'VALUE',
894                        value2 => X_fin_info_ptr.asset_number,
895                        translate => FALSE
896                        );
897              end if;
898 
899              fa_srvr_msg.add_message (
900                   calling_fn => 'fa_txrsv_pkg.fautxa',
901                   name        => mesg_name);
902 
903              fa_srvr_msg.add_sql_error (
904                   calling_fn => 'fa_txrsv_pkg.fautxa');
905 
906              return (FALSE);
907         when others then
908              fa_srvr_msg.add_sql_error (
909                   calling_fn => 'fa_txrsv_pkg.fautxa');
910              return (FALSE);
911 end FAUTXA;
912 
913 Function faxtxa
914      (
915          X_asset_number fa_additions.asset_number%type
916         ,X_asset_id fa_additions.asset_id%type
917         ,X_current_units fa_additions.current_units%type
918         ,X_asset_category_id fa_additions.asset_category_id%type
919         ,X_asset_type fa_additions.asset_type%type
920         ,X_new_cost number
921         ,X_salvage_value fa_books.salvage_value%type
922         ,X_new_recoverable_cost number
923         ,X_recoverable_cost fa_books.recoverable_cost%type
924         ,X_adjusted_rate fa_books.adjusted_rate%type
925         ,X_ceiling_name fa_books.ceiling_name%type
926         ,X_bonus_rule fa_books.bonus_rule%type
927         ,X_deprn_method_code fa_books.deprn_method_code%type
928         ,X_life_in_months fa_books.life_in_months%type
929         ,X_date_placed_in_service fa_books.date_placed_in_service%type
930         ,X_prorate_date fa_books.prorate_date%type
931         ,X_deprn_start_date fa_books.deprn_start_date%type
932         ,X_depreciate_flag fa_books.depreciate_flag%type
933         ,X_production_capacity fa_books.production_capacity%type
934         ,X_book_type_code fa_books.book_type_code%type
935         ,X_transaction_header_id fa_transaction_headers.transaction_header_id%type
936         ,X_rate_adjustment_factor fa_books.rate_adjustment_factor%type
937         ,X_reval_amortization_basis fa_books.reval_amortization_basis%type
938         ,X_old_deprn_rsv number
939         ,X_new_deprn_rsv number
940         ,X_fiscal_year integer
941         ,X_period_counter_rsv integer
942         ,X_sysdate_val date
943         ,X_last_updated_by number DEFAULT -1
944         ,X_last_update_login number DEFAULT -1
945         ,X_init_message_flag varchar2 default 'NO'
946         ,X_deprn_basis_formula varchar2 default null
947         ) return boolean is
948 
949    h_new_raf           number := 0;
950    h_new_adj_cost      number := 0;
951    fin_info            fa_std_types.fin_info_struct;
952    h_was_fully_rsv     boolean;
953    h_dummy_int         integer;
954 
955    /* added for mrc */
956    l_mrc_sob_type_code varchar2(1);
957    l_primary_sob_id  number;
958    l_profile_sob_id  number;
959    l_currency_context varchar2(64);
960 
961    CURSOR n_sob_id (p_psob_id IN NUMBER,
962                     p_book_type_code IN VARCHAR2) is
963    SELECT p_psob_id AS sob_id,
964           1 AS index_id
965      FROM dual
966     UNION
967    SELECT set_of_books_id AS sob_id,
968           2 AS index_id
969      FROM fa_mc_book_controls
970     WHERE book_type_code = p_book_type_code
971       AND primary_set_of_books_id = p_psob_id
972       AND enabled_flag = 'Y'
973     ORDER BY 2;
974 
975 
976    /* local for calculating mrc financial amounts */
977 
978    l_avg_exchange_rate         number;
979    l_old_deprn_rsv             number;
980    l_new_deprn_rsv             number;
981 
982    faxtxa_err                  EXCEPTION;
983 
984 begin <<FAXTXA>>
985 
986    if (X_init_message_flag = 'YES') then
987        -- initialize Message and Debug stacks
988        FA_SRVR_MSG.Init_Server_Message;
989        FA_DEBUG_PKG.Initialize;
990    end if;
991 
992    -- get the current values for sob for later use
993    fnd_profile.get('GL_SET_OF_BKS_ID', l_profile_sob_id);
994    l_currency_context := SUBSTRB(USERENV('CLIENT_INFO'),45,10);
995 
996    -- Begin substitute code for faxgtv (asset level)
997    fin_info.current_time  := X_sysdate_val;
998    fin_info.asset_number  := X_asset_number;
999    fin_info.asset_id      := X_asset_id;
1000    fin_info.units         := X_current_units;
1001    fin_info.category_id   := X_asset_category_id;
1002    fin_info.asset_type    := X_asset_type;
1003 
1004    -- Begin substitution code for faxgtv (book level but constant)
1005    fin_info.adj_rate           := X_adjusted_rate;
1006    fin_info.ceiling_name       := X_ceiling_name;
1007    fin_info.bonus_rule         := X_bonus_rule;
1008    fin_info.book               := X_book_type_code;
1009    fin_info.transaction_id     := X_transaction_header_id;
1010    fin_info.method_code        := X_deprn_method_code;
1011    fin_info.life               := X_life_in_months;
1012    fin_info.date_placed_in_svc := X_date_placed_in_service;
1013    fin_info.jdate_in_svc       := to_number(to_char(X_date_placed_in_service,'J'));
1014    fin_info.prorate_date       := X_prorate_date;
1015    fin_info.deprn_start_date   := X_deprn_start_date;
1016    fin_info.capacity           := X_production_capacity;
1017    fin_info.adj_capacity       := fin_info.capacity;
1018    fin_info.deprn_rounding_flag := fa_std_types.FA_DPR_ROUND_ADJ;
1019 
1020    if (X_depreciate_flag = 'YES') then
1021         fin_info.dep_flag := TRUE;
1022    else
1023         fin_info.dep_flag := FALSE;
1024    end if;
1025 
1026    if X_period_counter_rsv > 0 then
1027        h_was_fully_rsv := TRUE;
1028    else
1029        h_was_fully_rsv := FALSE;
1030    end if;
1031 
1032 
1033    if not fa_cache_pkg.fazcbc(fin_info.book) then
1034         fa_srvr_msg.add_message (calling_fn => 'fa_txrsv_pkg.faxtxa');
1035         return (FALSE);
1036    end if;
1037 
1038    fin_info.period_ctr := fa_cache_pkg.fazcbc_record.last_period_counter + 1;
1039    l_primary_sob_id    := fa_cache_pkg.fazcbc_record.set_of_books_id;
1040 
1041    -- loop through primary and reporting books here
1042 
1043    for c_rec in n_sob_id (p_psob_id        => l_primary_sob_id,
1044                           p_book_type_code => X_book_type_code) loop
1045 
1046       if c_rec.index_id = 1 then
1047          l_mrc_sob_type_code := 'P';
1048       else
1049          l_mrc_sob_type_code := 'R';
1050       end if;
1051 
1052       -- set the profile and currency context for each iteration
1053       fnd_profile.put('GL_SET_OF_BKS_ID', c_rec.sob_id);
1054       fnd_client_info.set_currency_context (c_rec.sob_id);
1055 
1056       -- calculate /populate amounts based on whether this is reporting or primary
1057       if (c_rec.index_id = 1) then
1058 
1059          fin_info.cost            := X_new_cost;
1060          fin_info.salvage_value   := X_salvage_value;
1061 
1062          if (X_new_recoverable_cost is not null) then
1063             fin_info.rec_cost     := X_new_recoverable_cost;
1064          else
1065             fin_info.rec_cost     := X_recoverable_cost;
1066          end if;
1067 
1068          fin_info.adj_cost        := fin_info.rec_cost;
1069 
1070          fin_info.rate_adj_factor := X_rate_adjustment_factor;
1071          fin_info.reval_amo_basis := X_reval_amortization_basis;
1072          l_old_deprn_rsv          := X_old_deprn_rsv;
1073          l_new_deprn_rsv          := X_new_deprn_rsv;
1074 
1075 
1076          select  bk.cost, decode(bk.allowed_deprn_limit,NULL,
1077                  (decode(bk.allowed_deprn_limit_amount,NULL,fin_info.rec_cost,
1078                  fin_info.cost - bk.allowed_deprn_limit_amount)),
1079                  fin_info.cost * bk.allowed_deprn_limit),
1080                  bk.formula_factor
1081          into    fin_info.old_cost, fin_info.adj_rec_cost, fin_info.formula_factor
1082          from    fa_books bk
1083          where   bk.asset_id = fin_info.asset_id
1084          and     bk.book_type_code = fin_info.book
1085          and     bk.date_ineffective is NULL;
1086 
1087       else
1088 
1089          -- get the average rate
1090          select avg_exchange_rate
1091            into l_avg_exchange_rate
1092            from fa_mc_books_rates
1093           where asset_id               = X_asset_id
1094             and book_type_code         = X_book_type_code
1095             and set_of_books_id        = c_rec.sob_id
1096             and transaction_header_id  =
1097                 (select max(transaction_header_id)
1098                    from fa_mc_books_rates
1099                   where asset_id        = X_asset_id
1100                     and book_type_code  = X_book_type_code
1101                     and set_of_books_id = c_rec.sob_id);
1102 
1103          -- calculate reporting amounts useing average rate
1104 
1105          fin_info.cost            := X_new_cost * l_avg_exchange_rate;
1106          fin_info.salvage_value   := X_salvage_value * l_avg_exchange_rate;
1107 
1108          if (X_new_recoverable_cost is not null) then
1109             fin_info.rec_cost     := X_new_recoverable_cost * l_avg_exchange_rate;
1110          else
1111             fin_info.rec_cost     := X_recoverable_cost * l_avg_exchange_rate;
1112          end if;
1113 
1114          fin_info.adj_cost        := fin_info.rec_cost;
1115 
1116          fin_info.rate_adj_factor := X_rate_adjustment_factor * l_avg_exchange_rate;
1117          fin_info.reval_amo_basis := X_reval_amortization_basis * l_avg_exchange_rate;
1118          l_old_deprn_rsv          := X_old_deprn_rsv * l_avg_exchange_rate;
1119          l_new_deprn_rsv          := X_new_deprn_rsv * l_avg_exchange_rate;
1120 
1121 
1122          -- round the values to correct precision
1123          if not FA_UTILS_PKG.faxrnd(fin_info.cost,            X_book_type_code) then
1124             raise faxtxa_err;
1125          end if;
1126          if not FA_UTILS_PKG.faxrnd(fin_info.salvage_value,   X_book_type_code) then
1127             raise faxtxa_err;
1128          end if;
1129          if not FA_UTILS_PKG.faxrnd(fin_info.rec_cost,        X_book_type_code) then
1130             raise faxtxa_err;
1131          end if;
1132          if not FA_UTILS_PKG.faxrnd(fin_info.adj_cost,        X_book_type_code) then
1133             raise faxtxa_err;
1134          end if;
1135          if not FA_UTILS_PKG.faxrnd(fin_info.rate_adj_factor, X_book_type_code) then
1136             raise faxtxa_err;
1137          end if;
1138          if not FA_UTILS_PKG.faxrnd(fin_info.reval_amo_basis, X_book_type_code) then
1139             raise faxtxa_err;
1140          end if;
1141 
1142          select  bk.cost, decode(bk.allowed_deprn_limit,NULL,
1143                  (decode(bk.allowed_deprn_limit_amount,NULL,fin_info.rec_cost,
1144                  fin_info.cost - bk.allowed_deprn_limit_amount)),
1145                  fin_info.cost * bk.allowed_deprn_limit),
1146                  bk.formula_factor
1147          into    fin_info.old_cost, fin_info.adj_rec_cost, fin_info.formula_factor
1148          from    fa_books_mrc_v bk
1149          where   bk.asset_id = fin_info.asset_id
1150          and     bk.book_type_code = fin_info.book
1151          and     bk.date_ineffective is NULL;
1152 
1153       end if;
1154 
1155       h_dummy_int := 0;
1156       if not fa_txrsv_pkg.fautxa (
1157            fin_info,
1158            l_old_deprn_rsv,
1159            l_new_deprn_rsv,
1160            X_fiscal_year,
1161            h_new_raf,
1162            h_new_adj_cost,
1163            h_was_fully_rsv,
1164            h_dummy_int,
1165            l_mrc_sob_type_code,
1166            X_deprn_basis_formula
1167            ) then
1168                 fa_srvr_msg.add_message (
1169                      calling_fn => 'fa_txrsv_pkg.faxtxa');
1170                      return (FALSE);
1171       end if;
1172 
1173    END LOOP; -- end primary reporting loop
1174 
1175 
1176    -- reset the sob to original values
1177    fnd_profile.put('GL_SET_OF_BKS_ID', l_profile_sob_id);
1178    fnd_client_info.set_currency_context (l_currency_context);
1179 
1180 return (TRUE);
1181 
1182 exception
1183         when faxtxa_err then
1184           -- reset the sob to original values
1185           fnd_profile.put('GL_SET_OF_BKS_ID',   l_profile_sob_id);
1186           fnd_client_info.set_currency_context (l_currency_context);
1187 
1188           fa_srvr_msg.add_sql_error (
1189                calling_fn => 'fa_txrsv_pkg.faxtxa');
1190                return (FALSE);
1191 
1192         when others then
1193           -- reset the sob to original values
1194           fnd_profile.put('GL_SET_OF_BKS_ID',   l_profile_sob_id);
1195           fnd_client_info.set_currency_context (l_currency_context);
1196 
1197           fa_srvr_msg.add_sql_error (
1198                calling_fn => 'fa_txrsv_pkg.faxtxa');
1199                return (FALSE);
1200 end FAXTXA;
1201 
1202 END FA_TXRSV_PKG;