DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_REVALUATION_PVT

Source


1 PACKAGE BODY FA_REVALUATION_PVT as
2 /* $Header: FAVRVLB.pls 120.7.12010000.1 2008/07/28 13:19:01 appldev ship $   */
3 
4 
5 FUNCTION do_reval
6    (px_trans_rec              IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
7     px_asset_hdr_rec          IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
8     p_asset_desc_rec          IN     FA_API_TYPES.asset_desc_rec_type,
9     p_asset_type_rec          IN     FA_API_TYPES.asset_type_rec_type,
10     p_asset_cat_rec           IN     FA_API_TYPES.asset_cat_rec_type,
11     p_asset_fin_rec_old       IN     FA_API_TYPES.asset_fin_rec_type,
12     p_asset_deprn_rec_old     IN     FA_API_TYPES.asset_deprn_rec_type,
13     p_period_rec              IN     FA_API_TYPES.period_rec_type,
14     p_mrc_sob_type_code       IN     VARCHAR2,
15     p_reval_options_rec       IN     FA_API_TYPES.reval_options_rec_type,
16     p_calling_fn              IN     VARCHAR2,
17     p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
18 
19    l_th_rowid                        varchar2(30);
20    l_bks_rowid                       varchar2(30);
21    l_status                          boolean;
22 
23    l_asset_fin_rec_new               FA_API_TYPES.asset_fin_rec_type;
24    l_asset_deprn_rec_new             FA_API_TYPES.asset_deprn_rec_type;
25 
26    l_reval_out_rec                   FA_STD_TYPES.reval_out_struct;
27 
28    -- rx columns
29    l_concat_cat          VARCHAR2(220);
30    l_cat_segs            FA_RX_SHARED_PKG.Seg_Array;
31    l_override_defaults   varchar2(80);
32    l_reval_fully_rsvd    varchar2(80);
33    l_revalue_cip_assets  varchar2(80);
34 
35    CURSOR yes_no_meaning (p_lookup_code varchar2)  IS
36    SELECT nvl(meaning, p_lookup_code)
37      FROM fa_lookups
38     WHERE lookup_code = p_lookup_code
39       AND lookup_type = 'YESNO';
40 
41    l_calling_fn                      varchar2(35) := 'fa_reval_pvt.do_reval';
42    reval_err                         EXCEPTION;
43 
44    -- Bug6917615
45    l_method_type                  NUMBER := 0;
46    l_success                      INTEGER;
47    l_rate_in_use                  NUMBER;
48 
49 BEGIN
50 
51    --set up transaction types for adjustments vs. addition voids
52    -- reval is currently not allowed in period of addition
53    px_trans_rec.transaction_type_code := 'REVALUATION';
54 
55    if (p_reval_options_rec.run_mode = 'RUN') then
56       -- insert transaction headers
57       if (p_mrc_sob_type_code <> 'R') then
58          -- we need the thid first before reval engine or do we
59          select fa_transaction_headers_s.nextval
60            into px_trans_rec.transaction_header_id
61           from dual;
62       end if;
63    end if;
64 
65    -- load the structs needed by reval engine
66    -- this may come later inside fareven, thus passing the
67    -- common api structs to that routine
68 
69    -- copy current old recs to new and reval engine will overlay them
70    -- with the new values where appropriate
71 
72    l_asset_fin_rec_new   := p_asset_fin_rec_old;
73    l_asset_deprn_rec_new := p_asset_deprn_rec_old;
74 
75    -- call the revaluation engine
76 
77    if not fareven
78                  (px_trans_rec                => px_trans_rec,
79                   p_asset_hdr_rec             => px_asset_hdr_rec ,
80                   p_asset_desc_rec            => p_asset_desc_rec,
81                   p_asset_type_rec            => p_asset_type_rec,
82                   p_asset_cat_rec             => p_asset_cat_rec,
83                   p_asset_fin_rec_old         => p_asset_fin_rec_old,
84                   px_asset_fin_rec_new        => l_asset_fin_rec_new,
85                   p_asset_deprn_rec_old       => p_asset_deprn_rec_old,
86                   px_asset_deprn_rec_new      => l_asset_deprn_rec_new,
87                   p_period_rec                => p_period_rec,
88                   p_mrc_sob_type_code         => p_mrc_sob_type_code,
89 		  p_reval_options_rec         => p_reval_options_rec,
90                   x_reval_out                 => l_reval_out_rec
91                   ,p_log_level_rec => p_log_level_rec) then raise reval_err;
92    end if;
93 
94    if (p_log_level_rec.statement_level) then
95          fa_debug_pkg.add
96                (l_calling_fn,
97                 'after call to fareven run_mode',
98                 p_reval_options_rec.run_mode
99                 ,p_log_level_rec => p_log_level_rec);
100          fa_debug_pkg.add
101                (l_calling_fn,
102                 'after call to fareven insert_txn_flag',
103                 l_reval_out_rec.insert_txn_flag
104                 ,p_log_level_rec => p_log_level_rec);
105    end if;
106 
107    -- if run_mode = RUN, then call the table handlers to process
108    -- the revaluation else insert into the temp table for preview report
109 
110    if (p_reval_options_rec.run_mode = 'RUN' and
111        l_reval_out_rec.insert_txn_flag) then
112 
113       -- insert transaction headers
114       if (p_mrc_sob_type_code <> 'R') then
115          if (p_log_level_rec.statement_level) then
116             fa_debug_pkg.add
117                (l_calling_fn,
118                 'trx_date before insert',
119                 px_trans_rec.transaction_date_entered
120                 ,p_log_level_rec => p_log_level_rec);
121          end if;
122 
123          -- SLA UPTAKE
124          -- assign an event for the transaction
125          -- at this point key info asset/book/trx info is known from above code
126          --   *** but trx_date_entered may not be correct! - revisit ***
127 
128          if not fa_xla_events_pvt.create_transaction_event
129               (p_asset_hdr_rec => px_asset_hdr_rec,
130                p_asset_type_rec=> p_asset_type_rec,
131                px_trans_rec    => px_trans_rec,
132                p_event_status  => NULL,
133                p_calling_fn    => l_calling_fn
134                ,p_log_level_rec => p_log_level_rec) then
135             raise reval_err;
136          end if;
137 
138 
139          FA_TRANSACTION_HEADERS_PKG.Insert_Row
140                       (X_Rowid                          => l_th_rowid,
141                        X_Transaction_Header_Id          => px_trans_rec.transaction_header_id,
142                        X_Book_Type_Code                 => px_asset_hdr_rec.book_type_code,
143                        X_Asset_Id                       => px_asset_hdr_rec.asset_id,
144                        X_Transaction_Type_Code          => px_trans_rec.transaction_type_code,
145                        X_Transaction_Date_Entered       => px_trans_rec.transaction_date_entered,
146                        X_Date_Effective                 => px_trans_rec.who_info.creation_date,
147                        X_Last_Update_Date               => px_trans_rec.who_info.last_update_date,
148                        X_Last_Updated_By                => px_trans_rec.who_info.last_updated_by,
149                        X_Transaction_Name               => px_trans_rec.transaction_name,
150                        X_Invoice_Transaction_Id         => NULL,
151                        X_Source_Transaction_Header_Id   => px_trans_rec.Source_Transaction_Header_Id,
152                        X_Mass_Reference_Id              => px_trans_rec.mass_reference_id,
153                        X_Last_Update_Login              => px_trans_rec.who_info.last_update_login,
154                        X_Transaction_Subtype            => px_trans_rec.transaction_subtype,
155                        X_Attribute1                     => px_trans_rec.desc_flex.attribute1,
156                        X_Attribute2                     => px_trans_rec.desc_flex.attribute2,
157                        X_Attribute3                     => px_trans_rec.desc_flex.attribute3,
158                        X_Attribute4                     => px_trans_rec.desc_flex.attribute4,
159                        X_Attribute5                     => px_trans_rec.desc_flex.attribute5,
160                        X_Attribute6                     => px_trans_rec.desc_flex.attribute6,
161                        X_Attribute7                     => px_trans_rec.desc_flex.attribute7,
162                        X_Attribute8                     => px_trans_rec.desc_flex.attribute8,
163                        X_Attribute9                     => px_trans_rec.desc_flex.attribute9,
164                        X_Attribute10                    => px_trans_rec.desc_flex.attribute10,
165                        X_Attribute11                    => px_trans_rec.desc_flex.attribute11,
166                        X_Attribute12                    => px_trans_rec.desc_flex.attribute12,
167                        X_Attribute13                    => px_trans_rec.desc_flex.attribute13,
168                        X_Attribute14                    => px_trans_rec.desc_flex.attribute14,
169                        X_Attribute15                    => px_trans_rec.desc_flex.attribute15,
170                        X_Attribute_Category_Code        => px_trans_rec.desc_flex.attribute_category_code,
171                        X_Transaction_Key                => px_trans_rec.transaction_key,
172                        X_Amortization_Start_Date        => px_trans_rec.amortization_start_date,
173                        X_Calling_Interface              => px_trans_rec.calling_interface,
174                        X_Mass_Transaction_ID            => px_trans_rec.mass_transaction_id,
175                        X_Member_Transaction_Header_Id   => px_trans_rec.member_transaction_header_id,
176                        X_Trx_Reference_Id               => px_trans_rec.trx_reference_id,
177                        X_event_Id                       => px_trans_rec.event_id,
178                        X_Return_Status                  => l_status,
179                        X_Calling_Fn                     => l_calling_fn
180                        ,p_log_level_rec => p_log_level_rec);
181          if not l_status then
182             raise reval_err;
183          end if;
184 
185       end if;  -- primary / reporting
186 
187 
188       -- terminate the active row
189       fa_books_pkg.deactivate_row
190         (X_asset_id                  => px_asset_hdr_rec.asset_id,
191          X_book_type_code            => px_asset_hdr_rec.book_type_code,
192          X_transaction_header_id_out => px_trans_rec.transaction_header_id,
193          X_date_ineffective          => px_trans_rec.who_info.last_update_date,
194          X_mrc_sob_type_code         => p_mrc_sob_type_code,
195          X_Calling_Fn                => l_calling_fn
196          ,p_log_level_rec => p_log_level_rec);
197 
198         if (p_log_level_rec.statement_level) then
199             fa_debug_pkg.add
200                (l_calling_fn,
201                 'after fa_books_pkg.deactivate_row',
202                 1
203                 ,p_log_level_rec => p_log_level_rec);
204          end if;
205 
206       -- fa books
207       fa_books_pkg.insert_row
208          (X_Rowid                        => l_bks_rowid,
209           X_Book_Type_Code               => px_asset_hdr_rec.book_type_code,
210           X_Asset_Id                     => px_asset_hdr_rec.asset_id,
211           X_Date_Placed_In_Service       => l_asset_fin_rec_new.date_placed_in_service,
212           X_Date_Effective               => px_trans_rec.who_info.last_update_date,
213           X_Deprn_Start_Date             => l_asset_fin_rec_new.deprn_start_date,
214           X_Deprn_Method_Code            => l_asset_fin_rec_new.deprn_method_code,
215           X_Life_In_Months               => l_asset_fin_rec_new.life_in_months,
216           X_Rate_Adjustment_Factor       => l_asset_fin_rec_new.rate_adjustment_factor,
217           X_Adjusted_Cost                => l_asset_fin_rec_new.adjusted_cost,
218           X_Cost                         => l_asset_fin_rec_new.cost,
219           X_Original_Cost                => l_asset_fin_rec_new.original_cost,
220           X_Salvage_Value                => l_asset_fin_rec_new.salvage_value,
221           X_Prorate_Convention_Code      => l_asset_fin_rec_new.prorate_convention_code,
222           X_Prorate_Date                 => l_asset_fin_rec_new.prorate_date,
223           X_Cost_Change_Flag             => l_asset_fin_rec_new.cost_change_flag,
224           X_Adjustment_Required_Status   => l_asset_fin_rec_new.adjustment_required_status,
225           X_Capitalize_Flag              => l_asset_fin_rec_new.capitalize_flag,
226           X_Retirement_Pending_Flag      => l_asset_fin_rec_new.retirement_pending_flag,
227           X_Depreciate_Flag              => l_asset_fin_rec_new.depreciate_flag,
228           X_Disabled_Flag                => l_asset_fin_rec_new.disabled_flag, --HH
229           X_Last_Update_Date             => px_trans_rec.who_info.last_update_date,
230           X_Last_Updated_By              => px_trans_rec.who_info.last_updated_by,
231           X_Date_Ineffective             => NULL,
232           X_Transaction_Header_Id_In     => px_trans_rec.transaction_header_id,
233           X_Transaction_Header_Id_Out    => NULL,
234           X_Itc_Amount_Id                => l_asset_fin_rec_new.itc_amount_id,
235           X_Itc_Amount                   => l_asset_fin_rec_new.itc_amount,
236           X_Retirement_Id                => l_asset_fin_rec_new.retirement_id,
237           X_Tax_Request_Id               => l_asset_fin_rec_new.tax_request_id,
238           X_Itc_Basis                    => l_asset_fin_rec_new.itc_basis,
239           X_Basic_Rate                   => l_asset_fin_rec_new.basic_rate,
240           X_Adjusted_Rate                => l_asset_fin_rec_new.adjusted_rate,
241           X_Bonus_Rule                   => l_asset_fin_rec_new.bonus_rule,
242           X_Ceiling_Name                 => l_asset_fin_rec_new.ceiling_name,
243           X_Recoverable_Cost             => l_asset_fin_rec_new.recoverable_cost,
244           X_Last_Update_Login            => px_trans_rec.who_info.last_update_login,
245           X_Adjusted_Capacity            => l_asset_fin_rec_new.adjusted_capacity,
246           X_Fully_Rsvd_Revals_Counter    => l_asset_fin_rec_new.fully_rsvd_revals_counter,
247           X_Idled_Flag                   => l_asset_fin_rec_new.idled_flag,
248           X_Period_Counter_Capitalized   => l_asset_fin_rec_new.period_counter_capitalized,
249           X_PC_Fully_Reserved            => l_asset_fin_rec_new.period_counter_fully_reserved,
250           X_Period_Counter_Fully_Retired => l_asset_fin_rec_new.period_counter_fully_retired,
251           X_Production_Capacity          => l_asset_fin_rec_new.production_capacity,
252           X_Reval_Amortization_Basis     => l_asset_fin_rec_new.reval_amortization_basis,
253           X_Reval_Ceiling                => l_asset_fin_rec_new.reval_ceiling,
254           X_Unit_Of_Measure              => l_asset_fin_rec_new.unit_of_measure,
255           X_Unrevalued_Cost              => l_asset_fin_rec_new.unrevalued_cost,
256           X_Annual_Deprn_Rounding_Flag   => l_asset_fin_rec_new.annual_deprn_rounding_flag,
257           X_Percent_Salvage_Value        => l_asset_fin_rec_new.percent_salvage_value,
258           X_Allowed_Deprn_Limit          => l_asset_fin_rec_new.allowed_deprn_limit,
259           X_Allowed_Deprn_Limit_Amount   => l_asset_fin_rec_new.allowed_deprn_limit_amount,
260           X_Period_Counter_Life_Complete => l_asset_fin_rec_new.period_counter_life_complete,
261           X_Adjusted_Recoverable_Cost    => l_asset_fin_rec_new.adjusted_recoverable_cost,
262           X_Short_Fiscal_Year_Flag       => l_asset_fin_rec_new.short_fiscal_year_flag,
263           X_Conversion_Date              => l_asset_fin_rec_new.conversion_date,
264           X_Orig_Deprn_Start_Date        => l_asset_fin_rec_new.orig_deprn_start_date,
265           X_Remaining_Life1              => l_asset_fin_rec_new.remaining_life1,
266           X_Remaining_Life2              => l_asset_fin_rec_new.remaining_life2,
267           X_Old_Adj_Cost                 => l_asset_fin_rec_new.old_adjusted_cost,
268           X_Formula_Factor               => l_asset_fin_rec_new.formula_factor,
269           X_gf_Attribute1                => l_asset_fin_rec_new.global_attribute1,
270           X_gf_Attribute2                => l_asset_fin_rec_new.global_attribute2,
271           X_gf_Attribute3                => l_asset_fin_rec_new.global_attribute3,
272           X_gf_Attribute4                => l_asset_fin_rec_new.global_attribute4,
273           X_gf_Attribute5                => l_asset_fin_rec_new.global_attribute5,
274           X_gf_Attribute6                => l_asset_fin_rec_new.global_attribute6,
275           X_gf_Attribute7                => l_asset_fin_rec_new.global_attribute7,
276           X_gf_Attribute8                => l_asset_fin_rec_new.global_attribute8,
277           X_gf_Attribute9                => l_asset_fin_rec_new.global_attribute9,
278           X_gf_Attribute10               => l_asset_fin_rec_new.global_attribute10,
279           X_gf_Attribute11               => l_asset_fin_rec_new.global_attribute11,
280           X_gf_Attribute12               => l_asset_fin_rec_new.global_attribute12,
281           X_gf_Attribute13               => l_asset_fin_rec_new.global_attribute13,
282           X_gf_Attribute14               => l_asset_fin_rec_new.global_attribute14,
283           X_gf_Attribute15               => l_asset_fin_rec_new.global_attribute15,
284           X_gf_Attribute16               => l_asset_fin_rec_new.global_attribute16,
285           X_gf_Attribute17               => l_asset_fin_rec_new.global_attribute17,
286           X_gf_Attribute18               => l_asset_fin_rec_new.global_attribute18,
287           X_gf_Attribute19               => l_asset_fin_rec_new.global_attribute19,
288           X_gf_Attribute20               => l_asset_fin_rec_new.global_attribute20,
289           X_global_attribute_category    => l_asset_fin_rec_new.global_attribute_category,
290           X_group_asset_id               => l_asset_fin_rec_new.group_asset_id,
291           X_salvage_type                 => l_asset_fin_rec_new.salvage_type,
292           X_deprn_limit_type             => l_asset_fin_rec_new.deprn_limit_type,
293           X_over_depreciate_option       => l_asset_fin_rec_new.over_depreciate_option,
294           X_super_group_id               => l_asset_fin_rec_new.super_group_id,
295           X_reduction_rate               => l_asset_fin_rec_new.reduction_rate,
296           X_reduce_addition_flag         => l_asset_fin_rec_new.reduce_addition_flag,
297           X_reduce_adjustment_flag       => l_asset_fin_rec_new.reduce_adjustment_flag,
298           X_reduce_retirement_flag       => l_asset_fin_rec_new.reduce_retirement_flag,
299           X_recognize_gain_loss          => l_asset_fin_rec_new.recognize_gain_loss,
300           X_recapture_reserve_flag       => l_asset_fin_rec_new.recapture_reserve_flag,
301           X_limit_proceeds_flag          => l_asset_fin_rec_new.limit_proceeds_flag,
302           X_terminal_gain_loss           => l_asset_fin_rec_new.terminal_gain_loss,
303           X_exclude_proceeds_from_basis  => l_asset_fin_rec_new.exclude_proceeds_from_basis,
304           X_retirement_deprn_option      => l_asset_fin_rec_new.retirement_deprn_option,
305           X_tracking_method              => l_asset_fin_rec_new.tracking_method,
306           X_allocate_to_fully_rsv_flag   => l_asset_fin_rec_new.allocate_to_fully_rsv_flag,
307           X_allocate_to_fully_ret_flag   => l_asset_fin_rec_new.allocate_to_fully_ret_flag,
308           X_exclude_fully_rsv_flag       => l_asset_fin_rec_new.exclude_fully_rsv_flag,
309           X_excess_allocation_option     => l_asset_fin_rec_new.excess_allocation_option,
310           X_depreciation_option          => l_asset_fin_rec_new.depreciation_option,
311           X_member_rollup_flag           => l_asset_fin_rec_new.member_rollup_flag,
312           X_ytd_proceeds                 => l_asset_fin_rec_new.ytd_proceeds,
313           X_ltd_proceeds                 => l_asset_fin_rec_new.ltd_proceeds,
314           X_eofy_reserve                 => l_asset_fin_rec_new.eofy_reserve,
315           X_cip_cost                     => l_asset_fin_rec_new.cip_cost,
316           X_terminal_gain_loss_amount    => l_asset_fin_rec_new.terminal_gain_loss_amount,
317           X_ltd_cost_of_removal          => l_asset_fin_rec_new.ltd_cost_of_removal,
318           X_mrc_sob_type_code            => p_mrc_sob_type_code,
319           X_Return_Status                => l_status,
320           X_Calling_Fn                   => l_calling_fn
321           ,p_log_level_rec => p_log_level_rec);
322 
323       if not l_status then
324          raise reval_err;
325       end if;
326 
327         if (p_log_level_rec.statement_level) then
328             fa_debug_pkg.add
329                (l_calling_fn,
330                 'after books insert',
331                 1
332                 ,p_log_level_rec => p_log_level_rec);
333          end if;
334 
335        --bug6917615
336        --Added the following code to populate the rat_in_use column during revaluation
337         if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES' then
338 
339             FA_CDE_PKG.faxgfr (X_Book_Type_Code   => px_asset_hdr_rec.book_type_code,
340                          X_Asset_Id               => px_asset_hdr_rec.asset_id,
341                          X_Short_Fiscal_Year_Flag => NULL,
342                          X_Conversion_Date        => NULL,
343                          X_Prorate_Date           => NULL,
344                          X_Orig_Deprn_Start_Date  => NULL,
345                          C_Prorate_Date           => NULL,
346                          C_Conversion_Date        => NULL,
347                          C_Orig_Deprn_Start_Date  => NULL,
348                          X_Method_Code            => l_asset_fin_rec_new.deprn_method_code,
349                          X_Life_In_Months         => l_asset_fin_rec_new.life_in_months,
350                          X_Fiscal_Year            => -99,
351                          X_Current_Period         => -99,
352                          X_calling_interface      => 'AFTER_REV',
353                          X_Rate                   => l_rate_in_use,
354                          X_Method_Type            => l_method_type,
355                          X_Success                => l_success);
356 
357         if (l_success <= 0) then
358             fa_srvr_msg.add_message(calling_fn => l_calling_fn);
359             raise reval_err;
360         end if;
361 
362         UPDATE FA_BOOKS
363         SET rate_in_use = l_rate_in_use
364         WHERE book_type_code = px_asset_hdr_rec.book_type_code
365         AND asset_id = px_asset_hdr_rec.asset_id
366         AND date_ineffective is null;
367 
368      end if;
369    elsif (p_reval_options_rec.run_mode = 'PREVIEW') then -- run_mode is preview
370 
371       -- insert into temp report table (ITF?)
372       -- we could also build an array here and insert in bulk periodically (as we do in faxinaj)
373 
374       -- Get the category in concatenated string for the asset's current category.
375 
376       if not fa_cache_pkg.fazsys then
377         raise reval_err;
378       end if;
379 
380       if p_log_level_rec.statement_level then
381          fa_debug_pkg.add
382              (l_calling_fn,
383               'calling concat_category with cat struct: ',
384               fa_cache_pkg.fazsys_record.category_flex_structure
385               ,p_log_level_rec => p_log_level_rec);
386          fa_debug_pkg.add
387              (l_calling_fn,
388               'calling concat_category with cat id: ',
389               p_asset_cat_rec.category_id
390               ,p_log_level_rec => p_log_level_rec);
391       end if;
392 
393       FA_RX_SHARED_PKG.Concat_Category(
394         struct_id       => fa_cache_pkg.fazsys_record.category_flex_structure,
395         ccid            => p_asset_cat_rec.category_id,
396         concat_string   => l_concat_cat,
397         segarray        => l_cat_segs);
398 
399       -- need to reset the flags to YES/NO here
400       if (nvl(p_reval_options_rec.override_defaults_flag, 'N') = 'Y') then
401          l_override_defaults := 'YES';
402       else
403          l_override_defaults := 'NO';
404       end if;
405 
406       if (nvl(p_reval_options_rec.reval_fully_rsvd_flag, 'N') = 'Y') then
407          l_reval_fully_rsvd := 'YES';
408       else
409          l_reval_fully_rsvd := 'NO';
410       end if;
411 
412       -- get translated values for YESNO flags
413       OPEN  yes_no_meaning (l_override_defaults);
414       FETCH yes_no_meaning INTO l_override_defaults;
415       CLOSE yes_no_meaning;
416 
417       OPEN  yes_no_meaning (l_reval_fully_rsvd);
418       FETCH yes_no_meaning INTO l_reval_fully_rsvd;
419       CLOSE yes_no_meaning;
420 
421       if p_log_level_rec.statement_level then
422          fa_debug_pkg.add
423              (l_calling_fn,
424               'inserting into: ',
425               'fa_mass_reval_rep_itf'
426               ,p_log_level_rec => p_log_level_rec);
427       end if;
428 
429 
430       insert into fa_mass_reval_rep_itf
431         (REQUEST_ID                      ,
432          MASS_REVAL_ID                   ,
433          BOOK_TYPE_CODE                  ,
434          TRANSACTION_DATE_ENTERED        ,
435          ASSET_ID                        ,
436          ASSET_NUMBER                    ,
437          DESCRIPTION                     ,
438          ASSET_TYPE                      ,
439          ASSET_CATEGORY_ID               ,
440          CATEGORY                        ,
441          OLD_LIFE                        ,
442          NEW_LIFE                        ,
443          OLD_COST                        ,
444          NEW_COST                        ,
445          OLD_DEPRN_RESERVE               ,
446          NEW_DEPRN_RESERVE               ,
447          OLD_REVAL_RESERVE               ,
448          NEW_REVAL_RESERVE               ,
449          REVAL_CEILING                   ,
450          REVAL_PERCENT                   ,
451          OVERRIDE_DEFAULTS               ,
452          REVAL_FULLY_RSVD                ,
453          LIFE_EXTENSION_FACTOR           ,
454          LIFE_EXTENSION_CEILING          ,
455          MAX_FULLY_RSVD_REVALS           ,
456          LAST_UPDATE_DATE                ,
457          LAST_UPDATED_BY                 ,
458          CREATED_BY                      ,
459          CREATION_DATE                   ,
460          LAST_UPDATE_LOGIN               )
461       values
462         (px_trans_rec.mass_reference_id              ,
463          px_trans_rec.mass_transaction_id            ,
464          px_asset_hdr_rec.book_type_code             ,
465          px_trans_rec.transaction_date_entered       ,
466          px_asset_hdr_rec.asset_id                   ,
467          p_asset_desc_rec.asset_number               ,
468          p_asset_desc_rec.description                ,
469          p_asset_type_rec.asset_type                 ,
470          p_asset_cat_rec.category_id                 ,
471          l_concat_cat                                ,
472          p_asset_fin_rec_old.life_in_months          ,
473          l_asset_fin_rec_new.life_in_months          ,
474          p_asset_fin_rec_old.cost                    ,
475          l_asset_fin_rec_new.cost                    ,
476          p_asset_deprn_rec_old.deprn_reserve         ,
477          l_asset_deprn_rec_new.deprn_reserve         ,
478          p_asset_deprn_rec_old.reval_deprn_reserve   ,
479          l_asset_deprn_rec_new.reval_deprn_reserve   ,
480          l_asset_fin_rec_new.reval_ceiling           ,
481          p_reval_options_rec.reval_percent           ,
482          l_override_defaults                         ,
483          l_reval_fully_rsvd                          ,
484          p_reval_options_rec.life_extension_factor   ,
485          p_reval_options_rec.life_extension_ceiling  ,
486          p_reval_options_rec.max_fully_rsvd_revals   ,
487          px_trans_rec.who_info.last_update_date      ,
488          px_trans_rec.who_info.last_updated_by       ,
489          px_trans_rec.who_info.last_updated_by       ,
490          px_trans_rec.who_info.last_update_date      ,
491          px_trans_rec.who_info.last_update_login
492         );
493 
494       if p_log_level_rec.statement_level then
495          fa_debug_pkg.add
496              (l_calling_fn,
497               'after inserting into: ',
498               'fa_mass_reval_rep_itf'
499               ,p_log_level_rec => p_log_level_rec);
500       end if;
501 
502 
503    end if; -- run_mode
504 
505    return true;
506 
507 EXCEPTION
508 
509    when reval_err then
510       fa_srvr_msg.add_message(calling_fn => l_calling_fn
511             ,p_log_level_rec => p_log_level_rec);
512       return false;
513 
514    when others then
515       fa_srvr_msg.add_sql_error
516           (calling_fn => l_calling_fn
517                     ,p_log_level_rec => p_log_level_rec);
518       return false;
519 
520 END do_reval;
521 
522 
523 
524 -----------------------------------------------------------------------------
525 
526 -- this function contains validation for reval on an asset
527 
528 FUNCTION validate_reval
529    (p_trans_rec               IN     FA_API_TYPES.trans_rec_type,
530     p_asset_hdr_rec           IN     FA_API_TYPES.asset_hdr_rec_type,
531     p_asset_desc_rec          IN     FA_API_TYPES.asset_desc_rec_type,
532     p_asset_type_rec          IN     FA_API_TYPES.asset_type_rec_type,
533     p_asset_cat_rec           IN     FA_API_TYPES.asset_cat_rec_type,
534     p_asset_fin_rec_old       IN     FA_API_TYPES.asset_fin_rec_type,
535     p_asset_deprn_rec_old     IN     FA_API_TYPES.asset_deprn_rec_type,
536     p_reval_options_rec       IN     FA_API_TYPES.reval_options_rec_type,
537     p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
538 
539    l_calling_fn               varchar2(35)  := 'do_adjustment_pvt.validate_adj';
540 
541 BEGIN
542 
543    return true;
544 
545 EXCEPTION
546 
547    when others then
548       fa_srvr_msg.add_sql_error
549           (calling_fn => l_calling_fn
550                     ,p_log_level_rec => p_log_level_rec);
551       return false;
552 
553 END validate_reval;
554 
555 FUNCTION fareven
556    (px_trans_rec              IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
557     p_asset_hdr_rec           IN     FA_API_TYPES.asset_hdr_rec_type,
558     p_asset_desc_rec          IN     FA_API_TYPES.asset_desc_rec_type,
559     p_asset_type_rec          IN     FA_API_TYPES.asset_type_rec_type,
560     p_asset_cat_rec           IN     FA_API_TYPES.asset_cat_rec_type,
561     p_asset_fin_rec_old       IN     FA_API_TYPES.asset_fin_rec_type,
562     px_asset_fin_rec_new      IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
563     p_asset_deprn_rec_old     IN     FA_API_TYPES.asset_deprn_rec_type,
564     px_asset_deprn_rec_new    IN OUT NOCOPY FA_API_TYPES.asset_deprn_rec_type,
565     p_period_rec              IN     FA_API_TYPES.period_rec_type,
566     p_mrc_sob_type_code       IN     VARCHAR2,
567     p_reval_options_rec       IN     FA_API_TYPES.reval_options_rec_type,
568     x_reval_out               OUT NOCOPY FA_STD_TYPES.reval_out_struct,
569     p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null)
570                                      RETURN BOOLEAN IS
571 
572     l_asset_fin_rec_adj         FA_API_TYPES.asset_fin_rec_type;
573 
574     l_reval_rate                number;
575     l_life_extension_factor     number;
576     l_life_extension_ceiling    number;
577 
578     l_method_id                 number;
579     l_depr_last_year_flag       boolean;
580     l_rate_source_rule          varchar2(25);
581     l_deprn_basis_rule          varchar2(25);
582 
583     l_recalc_life               number;
584     l_life_ceiling              number;
585 
586     l_reval_ceiling_flag        boolean;
587     l_fully_rsvd_flag           boolean;
588 
589     l_dpr_in                    FA_STD_TYPES.dpr_struct;
590     l_dpr_out                   FA_STD_TYPES.dpr_out_struct;
591     l_dpr_arr                   FA_STD_TYPES.dpr_arr_type;
592     l_running_mode              NUMBER := fa_std_types.FA_DPR_NORMAL;
593 
594     l_reval_amo_basis           number;
595     l_bonus_deprn_exp           number;
596     l_deprn_exp                 number;
597     l_salvage_value             number;
598 
599     l_adj_in                    fa_adjust_type_pkg.fa_adj_row_struct;
600 
601     l_cost_acct                 varchar2(25);
602     l_cip_cost_acct             varchar2(25);
603     l_reval_rsv_acct            varchar2(25);
604     l_deprn_rsv_acct            varchar2(25);
605     l_deprn_exp_acct            varchar2(25);
606 
607     -- GBertot: enabled revaluation of YTD deprn.
608     l_ytd_deprn_acct            varchar2(25);
609 
610     -- Bonus Deprn YYOON
611     l_bonus_deprn_exp_acct      varchar2(25);
612     l_bonus_deprn_rsv_acct      varchar2(25);
613     -- End of Bonus Deprn Change
614 
615     l_reval_dep_rsv_flag        varchar2(5);
616     l_amor_reval_rsv_flag       varchar2(5);
617     -- GBertot: enabled revaluation of YTD Deprn.
618     l_reval_ytd_deprn_flag      varchar2(5);
619 
620     l_deprn_calendar            varchar2(30);
621     l_fy_name                   varchar2(30);
622     l_last_period_counter       number;
623     l_fy                        number;
624     l_period_num                number;
625     l_polish_rule               number;
626 
627     l_skip_asset                boolean;
628 
629     l_calling_fn              varchar2(40) := 'FA_REVALUATION_PVT.fareven';
630     fareven_err			exception;
631 
632 begin
633 
634     if (p_log_level_rec.statement_level) then
635        fa_debug_pkg.add('fareven', 'begin', 1
636               ,p_log_level_rec => p_log_level_rec);
637     end if;
638 
639     -- validations come here
640     if (p_asset_fin_rec_old.reval_ceiling is null) then
641         l_reval_ceiling_flag := FALSE;
642     else l_reval_ceiling_flag := TRUE;
643     end if;
644 
645     if (p_reval_options_rec.run_mode = 'RUN') then
646        x_reval_out.insert_txn_flag := TRUE;
647     end if;
648 
649     if (abs(p_asset_fin_rec_old.recoverable_cost) <=
650         abs(p_asset_deprn_rec_old.deprn_reserve)) then
651        l_fully_rsvd_flag := TRUE;
652     else
653        l_fully_rsvd_flag := FALSE;
654     end if;
655 
656     if (p_asset_fin_rec_old.production_capacity is not null and
657        l_fully_rsvd_flag) then
658        x_reval_out.insert_txn_flag := FALSE;
659        goto fareven_exit_noerr;
660     end if;
661 
662     if not fa_cache_pkg.fazccmt
663               (X_method        => p_asset_fin_rec_old.deprn_method_code,
664                X_life          => p_asset_fin_rec_old.life_in_months
665                ,p_log_level_rec => p_log_level_rec) then
666          raise fareven_err;
667     end if;
668 
669     if (fa_cache_pkg.fazccmt_record.rate_source_rule =
670                                FA_STD_TYPES.FAD_RSR_FLAT AND
671        l_fully_rsvd_flag) then
672        x_reval_out.insert_txn_flag := FALSE;
673        goto fareven_exit_noerr;
674     end if;
675 
676     if (fa_cache_pkg.fazccmt_record.deprn_basis_rule_id is not null) then
677       l_polish_rule := fa_cache_pkg.fazcdbr_record.polish_rule;
678     end if;
679 
680     if (nvl(l_polish_rule, FA_STD_TYPES.FAD_DBR_POLISH_NONE) in (
681                           FA_STD_TYPES.FAD_DBR_POLISH_1,
682                           FA_STD_TYPES.FAD_DBR_POLISH_2,
683                           FA_STD_TYPES.FAD_DBR_POLISH_3,
684                           FA_STD_TYPES.FAD_DBR_POLISH_4,
685                           FA_STD_TYPES.FAD_DBR_POLISH_5)) then
686        x_reval_out.insert_txn_flag := FALSE;
687        goto fareven_exit_noerr;
688     end if;
689 
690     l_reval_rate := p_reval_options_rec.reval_percent / 100;
691     l_life_extension_factor := p_reval_options_rec.life_extension_factor;
692     l_life_extension_ceiling := p_reval_options_rec.life_extension_ceiling;
693 
694     -- Get Book Based Revaluation Rules from Book Controls Cache
695     -- Get some more information from the Book Controls Cache
696 
697     l_reval_dep_rsv_flag := fa_cache_pkg.fazcbc_record.reval_deprn_reserve_flag;    l_reval_ytd_deprn_flag := fa_cache_pkg.fazcbc_record.reval_ytd_deprn_flag;
698     l_amor_reval_rsv_flag :=
699                 fa_cache_pkg.fazcbc_record.amortize_reval_reserve_flag;
700 
701     l_last_period_counter := fa_cache_pkg.fazcbc_record.last_period_counter;
702     l_deprn_calendar := fa_cache_pkg.fazcbc_record.deprn_calendar;
703     l_fy_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
704 
705     if (p_log_level_rec.statement_level) then
706        fa_debug_pkg.add('fareven', 'step', 2
707               ,p_log_level_rec => p_log_level_rec);
708     end if;
709 
710 
711     -- Find the Depreciation Basis Rule and Rate Source Rule
712     -- for this depreciation method
713 
714     if not fa_cache_pkg.fazccmt
715               (X_method        => p_asset_fin_rec_old.deprn_method_code,
716                X_life          => p_asset_fin_rec_old.life_in_months
717                ,p_log_level_rec => p_log_level_rec) then
718          raise fareven_err;
719     end if;
720 
721     l_method_id        := fa_cache_pkg.fazccmt_record.method_id;
722     if fa_cache_pkg.fazccmt_record.depreciate_lastyear_flag = 'YES' then
723       l_depr_last_year_flag := TRUE;
724     else
725       l_depr_last_year_flag := FALSE;
726     end if;
727     l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
728     l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
729 
730     if (p_log_level_rec.statement_level) then
731        fa_debug_pkg.add('fareven', '3', 3
732               ,p_log_level_rec => p_log_level_rec);
733     end if;
734 
735     --if there is a revaluation ceiling recalculate the revaluation rate
736     --if necessary
737 
738     if (l_reval_ceiling_flag) then
739        if ((p_asset_fin_rec_old.cost * (1 + l_reval_rate))
740                         > p_asset_fin_rec_old.reval_ceiling) then
741            l_reval_rate := (p_asset_fin_rec_old.reval_ceiling / p_asset_fin_rec_old.cost)
742                            - 1;
743        end if;
744     end if;
745 
746     if (p_log_level_rec.statement_level) then
747        fa_debug_pkg.add('fareven', 'l_reval_rate', l_reval_rate
748               ,p_log_level_rec => p_log_level_rec);
749     end if;
750 
751     --Calculate adjustment to asset cost
752 
753     x_reval_out.cost_adj := p_asset_fin_rec_old.cost * l_reval_rate;
754 
755     -- Round to correct precision
756 
757     if not FA_UTILS_PKG.faxrnd(x_reval_out.cost_adj,
758                               p_asset_hdr_rec.book_type_code
759                               ,p_log_level_rec => p_log_level_rec) then
760       raise fareven_err;
761     end if;
762 
763     px_asset_fin_rec_new.cost := p_asset_fin_rec_old.cost + x_reval_out.cost_adj;
764     l_recalc_life := p_asset_fin_rec_old.life_in_months;
765 
766     if (p_log_level_rec.statement_level) then
767        fa_debug_pkg.add('fareven', 'old cost',
768                          p_asset_fin_rec_old.cost
769                          ,p_log_level_rec => p_log_level_rec);
770        fa_debug_pkg.add('fareven', 'x_reval_out.cost_adj',
771                          x_reval_out.cost_adj
772                          ,p_log_level_rec => p_log_level_rec);
773        fa_debug_pkg.add('fareven', 'new cost',
774                          px_asset_fin_rec_new.cost
775                          ,p_log_level_rec => p_log_level_rec);
776     end if;
777 
778     -- call fazccbd to initialize cat book defaults which is called in
779     -- calc_salvage_value
780 
781     if not fa_cache_pkg.fazccbd
782               (X_book            => p_asset_hdr_rec.book_type_code,
783                X_cat_id          => p_asset_cat_rec.category_id,
784                X_jdpis           =>
785        to_number(to_char(p_asset_fin_rec_old.date_placed_in_service, 'J')) ) then
786          raise fareven_err;
787     end if;
788 
789     px_asset_fin_rec_new.annual_deprn_rounding_flag := 'REV';
790 
791     --If the asset is not fully reserved
792     if (not l_fully_rsvd_flag) then
793        if (p_log_level_rec.statement_level) then
794           fa_debug_pkg.add('fareven', 'not fully reserved',
795                          1
796                          ,p_log_level_rec => p_log_level_rec);
797        end if;
798 
799         -- Compute Adjustment to Depreciation Reserve
800         --  if  Depreciation Reserve is to be revalued
801 
802         if l_reval_dep_rsv_flag = 'YES' then
803 
804             if (p_log_level_rec.statement_level) then
805                fa_debug_pkg.add('fareven', 'reval_dep_rsv_flag is YES',1
806                               ,p_log_level_rec => p_log_level_rec);
807             end if;
808 
809             x_reval_out.deprn_rsv_adj := p_asset_deprn_rec_old.deprn_reserve *
810                                          l_reval_rate;
811 
812             -- Round to correct precision
813 
814             if not FA_UTILS_PKG.faxrnd(x_reval_out.deprn_rsv_adj,
815                               p_asset_hdr_rec.book_type_code
816                               ,p_log_level_rec => p_log_level_rec) then
817                raise fareven_err;
818             end if;
819 
820             -- Bonus Deprn  YYOON
821             x_reval_out.bonus_deprn_rsv_adj := p_asset_deprn_rec_old.bonus_deprn_reserve *                                         l_reval_rate;
822 
823             -- Round to correct precision
824 
825             if not FA_UTILS_PKG.faxrnd(x_reval_out.bonus_deprn_rsv_adj,
826                               p_asset_hdr_rec.book_type_code
827                               ,p_log_level_rec => p_log_level_rec) then
828                raise fareven_err;
829             end if;
830 
831         else --if Depreciation Reserve is not to be revalued
832 
833             if (p_log_level_rec.statement_level) then
834                fa_debug_pkg.add('fareven', 'reval_dep_rsv_flag is NO',1
835                               ,p_log_level_rec => p_log_level_rec);
836             end if;
837 
838             x_reval_out.deprn_rsv_adj := -p_asset_deprn_rec_old.deprn_reserve;
839             x_reval_out.bonus_deprn_rsv_adj := -p_asset_deprn_rec_old.bonus_deprn_reserve;
840         end if;
841 
842         if (p_log_level_rec.statement_level) then
843            fa_debug_pkg.add('fareven', 'x_reval_out.deprn_rsv_adj',
844                          x_reval_out.deprn_rsv_adj
845                          ,p_log_level_rec => p_log_level_rec);
846            fa_debug_pkg.add('fareven', 'x_reval_out.bonus_deprn_rsv_adj',
847                          x_reval_out.bonus_deprn_rsv_adj
848                          ,p_log_level_rec => p_log_level_rec);
849         end if;
850 
851         -- GBertot: compute adjustment to YTD deprn. if it is to be revalued
852 
853         if l_reval_ytd_deprn_flag = 'YES' then
854 
855            if (p_log_level_rec.statement_level) then
856                fa_debug_pkg.add('fareven', 'reval_ytd_deprn_flag is YES',1
857                               ,p_log_level_rec => p_log_level_rec);
858            end if;
859 
860            x_reval_out.ytd_deprn_adj := p_asset_deprn_rec_old.ytd_deprn * l_reval_rate;
861            --round to correct precision
862            if not FA_UTILS_PKG.faxrnd(x_reval_out.ytd_deprn_adj,
863                               p_asset_hdr_rec.book_type_code
864                               ,p_log_level_rec => p_log_level_rec) then
865               raise fareven_err;
866            end if;
867 
868            --  Bonus Deprn  YYOON
869            x_reval_out.bonus_ytd_deprn_adj := p_asset_deprn_rec_old.bonus_ytd_deprn
870                                                 * l_reval_rate;
871            --round to correct precision
872            if not FA_UTILS_PKG.faxrnd(x_reval_out.bonus_ytd_deprn_adj,
873                               p_asset_hdr_rec.book_type_code
874                               ,p_log_level_rec => p_log_level_rec) then
875               raise fareven_err;
876            end if;
877         else -- if YTD deprn. is not to be revalued
878             if (p_log_level_rec.statement_level) then
879                fa_debug_pkg.add('fareven', 'reval_ytd_deprn_flag is NO',1
880                               ,p_log_level_rec => p_log_level_rec);
881             end if;
882 
883             x_reval_out.ytd_deprn_adj := 0;
884             x_reval_out.bonus_ytd_deprn_adj := 0;
885         end if;
886 
887         -- Bonus Deprn - YYOON:
888         --   Here in the following calculation of revaluation reserve amount,
889         --   the revalued bonus_ytd_adj amount doesn't need to be
890         -- involved in the calculation
891         --because the ytd_deprn_adj has already included the bonus ytd amount.
892         -- Compute Adjustment to Revaluation Reserve
893 
894         x_reval_out.reval_rsv_adj := x_reval_out.cost_adj -
895                                      x_reval_out.deprn_rsv_adj;
896 
897         -- GBertot: Compute adjustment to revaluation reserve due to YTD deprn.
898         x_reval_out.reval_rsv_adj := x_reval_out.reval_rsv_adj +
899                                      x_reval_out.ytd_deprn_adj;
900 
901         if (p_log_level_rec.statement_level) then
902            fa_debug_pkg.add('fareven', 'x_reval_out.reval_rsv_adj',
903                          x_reval_out.reval_rsv_adj
904                          ,p_log_level_rec => p_log_level_rec);
905         end if;
906 
907         x_reval_out.new_life := p_asset_fin_rec_old.life_in_months;
908         x_reval_out.new_fully_rsvd_revals_ctr :=
909                                    p_asset_fin_rec_old.fully_rsvd_revals_counter;
910 
911         -- Compute Recoverable Cost
912         if not fa_asset_calc_pvt.calc_salvage_value
913           (p_trans_rec               => px_trans_rec,
914            p_asset_hdr_rec           => p_asset_hdr_rec,
915            p_asset_type_rec          => p_asset_type_rec,
916            p_asset_fin_rec_old       => p_asset_fin_rec_old,
917            p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
918            px_asset_fin_rec_new      => px_asset_fin_rec_new,
919            p_mrc_sob_type_code       => p_mrc_sob_type_code
920            ,p_log_level_rec => p_log_level_rec) then
921            raise fareven_err;
922         end if;
923         x_reval_out.new_salvage_value := px_asset_fin_rec_new.salvage_value;
924 
925         if not fa_asset_calc_pvt.calc_rec_cost
926           (p_asset_hdr_rec           => p_asset_hdr_rec,
927            p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
928            px_asset_fin_rec_new      => px_asset_fin_rec_new
929            ,p_log_level_rec => p_log_level_rec) then
930           raise fareven_err;
931         end if;
932 
933         px_asset_fin_rec_new.adjusted_cost :=
934                                  px_asset_fin_rec_new.recoverable_cost;
935 
936         if not fa_asset_calc_pvt.calc_deprn_limit_adj_rec_cost
937           (p_asset_hdr_rec           => p_asset_hdr_rec,
938            p_asset_type_rec          => p_asset_type_rec,
939            p_asset_fin_rec_old       => p_asset_fin_rec_old,
940            p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
941            px_asset_fin_rec_new      => px_asset_fin_rec_new,
942            p_mrc_sob_type_code       => p_mrc_sob_type_code
943            ,p_log_level_rec => p_log_level_rec) then
944            raise fareven_err;
945         end if;
946 
947         if (p_log_level_rec.statement_level) then
948 
949            fa_debug_pkg.add('fareven', 'after calc_salvage_value SV',
950                          px_asset_fin_rec_new.salvage_value
951                          ,p_log_level_rec => p_log_level_rec);
952            fa_debug_pkg.add('fareven', 'after calc_rec_cost rec cost',
953                          px_asset_fin_rec_new.recoverable_cost
954                          ,p_log_level_rec => p_log_level_rec);
955            fa_debug_pkg.add('fareven',
956                          'after calc_adj_rec_cost adj_rec_cost',
957                          px_asset_fin_rec_new.adjusted_recoverable_cost
958                          ,p_log_level_rec => p_log_level_rec);
959         end if;
960 
961         if not FA_AMORT_PVT.faxraf(
962           px_trans_rec            => px_trans_rec,
963           p_asset_hdr_rec         => p_asset_hdr_rec,
964           p_asset_desc_rec        => p_asset_desc_rec,
965           p_asset_cat_rec         => p_asset_cat_rec,
966           p_asset_type_rec        => p_asset_type_rec,
967           p_asset_fin_rec_old     => p_asset_fin_rec_old,
968           px_asset_fin_rec_new    => px_asset_fin_rec_new,
969           p_asset_deprn_rec       => p_asset_deprn_rec_old,
970           p_period_rec            => p_period_rec,
971           px_deprn_exp            => l_deprn_exp,
972           px_bonus_deprn_exp      => l_bonus_deprn_exp,
973           px_reval_deprn_rsv_adj  => x_reval_out.deprn_rsv_adj,
974           p_mrc_sob_type_code     => p_mrc_sob_type_code,
975           p_running_mode          => fa_std_types.FA_DPR_NORMAL,
976           p_used_by_revaluation   => 1
977           ,p_log_level_rec => p_log_level_rec) then
978           raise fareven_err;
979         end if;
980 
981     end if;  -- If the asset is not fully reserved
982 
983 
984     --If the asset is fully reserved
985     if (l_fully_rsvd_flag) then
986         if (p_log_level_rec.statement_level) then
987           fa_debug_pkg.add('fareven', 'REVALUE FULLY RESERVED ASSET',
988                            p_reval_options_rec.reval_fully_rsvd_flag
989                            ,p_log_level_rec => p_log_level_rec);
990         end if;
991 
992         if ((nvl(p_reval_options_rec.reval_fully_rsvd_flag,'N') = 'N') OR
993              ((p_asset_fin_rec_old.fully_rsvd_revals_counter >=
994                p_reval_options_rec.max_fully_rsvd_revals) AND
995              (p_reval_options_rec.max_fully_rsvd_revals <> -1))) then
996             x_reval_out.cost_adj := 0;
997             x_reval_out.deprn_rsv_adj := 0;
998             x_reval_out.reval_rsv_adj := 0;
999             x_reval_out.ytd_deprn_adj := 0;
1000             x_reval_out.bonus_ytd_deprn_adj := 0;
1001             x_reval_out.bonus_deprn_rsv_adj := 0;
1002 
1003             x_reval_out.new_life := p_asset_fin_rec_old.life_in_months;
1004             x_reval_out.new_fully_rsvd_revals_ctr :=
1005                                p_asset_fin_rec_old.fully_rsvd_revals_counter;
1006             x_reval_out.new_adj_cost := p_asset_fin_rec_old.adjusted_cost;
1007             x_reval_out.new_adj_capacity := p_asset_fin_rec_old.adjusted_capacity;
1008             x_reval_out.new_rec_cost := p_asset_fin_rec_old.recoverable_cost;
1009             x_reval_out.new_raf := p_asset_fin_rec_old.rate_adjustment_factor;
1010             px_asset_fin_rec_new := p_asset_fin_rec_old;
1011             px_asset_deprn_rec_new := p_asset_deprn_rec_old;
1012             x_reval_out.insert_txn_flag := FALSE;
1013 
1014         else
1015 
1016             -- If life extension factor is not specified as a part
1017             -- of revaluation rules it is an error condition
1018 
1019             if (p_log_level_rec.statement_level) then
1020                fa_debug_pkg.add('fareven', 'l_life_extension_factor',
1021                          l_life_extension_factor
1022                          ,p_log_level_rec => p_log_level_rec);
1023             end if;
1024 
1025             if (l_life_extension_factor = -1) then
1026                raise fareven_err;
1027             end if;
1028 
1029             -- Compute Recoverable Cost
1030 
1031             if not fa_asset_calc_pvt.calc_salvage_value
1032                (p_trans_rec               => px_trans_rec,
1033                 p_asset_hdr_rec           => p_asset_hdr_rec,
1034                 p_asset_type_rec          => p_asset_type_rec,
1035                 p_asset_fin_rec_old       => p_asset_fin_rec_old,
1036                 p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
1037                 px_asset_fin_rec_new      => px_asset_fin_rec_new,
1038                 p_mrc_sob_type_code       => p_mrc_sob_type_code
1039                 ,p_log_level_rec => p_log_level_rec) then
1040                raise fareven_err;
1041             end if;
1042 
1043             if not fa_asset_calc_pvt.calc_rec_cost
1044                (p_asset_hdr_rec           => p_asset_hdr_rec,
1045                 p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
1046                 px_asset_fin_rec_new      => px_asset_fin_rec_new
1047                 ,p_log_level_rec => p_log_level_rec) then
1048                raise fareven_err;
1049             end if;
1050 
1051             if not fa_asset_calc_pvt.calc_deprn_limit_adj_rec_cost
1052               (p_asset_hdr_rec           => p_asset_hdr_rec,
1053                p_asset_type_rec          => p_asset_type_rec,
1054                p_asset_fin_rec_old       => p_asset_fin_rec_old,
1055                p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
1056                px_asset_fin_rec_new      => px_asset_fin_rec_new,
1057                p_mrc_sob_type_code       => p_mrc_sob_type_code
1058                ,p_log_level_rec => p_log_level_rec) then
1059               raise fareven_err;
1060             end if;
1061 
1062             if (p_log_level_rec.statement_level) then
1063 
1064                fa_debug_pkg.add('fareven', 'after calc_salvage_value SV',
1065                          px_asset_fin_rec_new.salvage_value
1066                          ,p_log_level_rec => p_log_level_rec);
1067                fa_debug_pkg.add('fareven', 'after calc_rec_cost rec cost',
1068                          px_asset_fin_rec_new.recoverable_cost
1069                          ,p_log_level_rec => p_log_level_rec);
1070                fa_debug_pkg.add('fareven',
1071                          'after calc_adj_rec_cost adj_rec_cost',
1072                          px_asset_fin_rec_new.adjusted_recoverable_cost
1073                          ,p_log_level_rec => p_log_level_rec);
1074             end if;
1075             x_reval_out.new_rec_cost := px_asset_fin_rec_new.recoverable_cost;
1076             x_reval_out.new_salvage_value :=
1077                              px_asset_fin_rec_new.salvage_value;
1078 
1079             if (l_reval_dep_rsv_flag = 'YES') then
1080                 -- If Depreciation Reserve is to be revalued
1081                 if (p_log_level_rec.statement_level) then
1082                    fa_debug_pkg.add('fareven', 'reval_dep_rsv_flag is YES',1
1083                                       ,p_log_level_rec => p_log_level_rec);
1084                 end if;
1085 
1086                 -- Extend Life by the life extension factor limited by
1087                 -- life extension ceiling (if specified) to compute Catchup
1088                 -- Depreciation
1089                 l_recalc_life := trunc(p_asset_fin_rec_old.life_in_months *
1090                                  l_life_extension_factor);
1091 
1092                 if (p_log_level_rec.statement_level) then
1093                    fa_debug_pkg.add('fareven', 'RECALC LIFE1',1
1094                                       ,p_log_level_rec => p_log_level_rec);
1095                    fa_debug_pkg.add('fareven', 'l_recalc_life1.1',
1096                                     l_recalc_life
1097                                     ,p_log_level_rec => p_log_level_rec);
1098                 end if;
1099 
1100                 if (l_life_extension_ceiling <> -1) then
1101                    l_life_ceiling := trunc(p_asset_fin_rec_old.life_in_months *
1102                                      l_life_extension_ceiling);
1103                    if (l_recalc_life > l_life_ceiling) then
1104                       l_recalc_life := l_life_ceiling;
1105                    end if;
1106                 end if;
1107 
1108                 if (p_log_level_rec.statement_level) then
1109                    fa_debug_pkg.add('fareven', 'l_recalc_life1.2',
1110                                     l_recalc_life
1111                                     ,p_log_level_rec => p_log_level_rec);
1112                 end if;
1113 
1114                 -- Find if the Depreciation Method for this
1115                 -- calculated life exists
1116                 if ((l_rate_source_rule = FA_STD_TYPES.FAD_RSR_CALC) OR
1117                     (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_TABLE) OR
1118                     (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_FORMULA)) then
1119                     if not fa_cache_pkg.fazccmt
1120                        (X_method        => p_asset_fin_rec_old.deprn_method_code,
1121                         X_life          => l_recalc_life
1122                         ,p_log_level_rec => p_log_level_rec) then
1123 
1124                        if (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_CALC) then
1125                           if (p_log_level_rec.statement_level) then
1126                            fa_debug_pkg.add('fareven', 'calling',
1127                                    'validate_life'
1128                                    ,p_log_level_rec => p_log_level_rec);
1129                            fa_debug_pkg.add('fareven', 'p_deprn_method',
1130                                     px_asset_fin_rec_new.deprn_method_code
1131                                     ,p_log_level_rec => p_log_level_rec);
1132                            fa_debug_pkg.add('fareven', 'l_recalc_life',
1133                                     l_recalc_life
1134                                     ,p_log_level_rec => p_log_level_rec);
1135                           end if;
1136                           if not fa_asset_val_pvt.validate_life
1137                              (p_deprn_method      => p_asset_fin_rec_old.deprn_method_code,
1138                               p_rate_source_rule  => l_rate_source_rule,
1139                               p_life_in_months    => l_recalc_life,
1140                               p_lim               => l_recalc_life,
1141                               p_user_id           =>
1142                                        px_trans_rec.who_info.last_updated_by,
1143                               p_curr_date         =>
1144                                           px_trans_rec.who_info.last_update_date,
1145                               px_new_life         => l_recalc_life,
1146                               p_calling_fn        => 'fareven'
1147                               ,p_log_level_rec => p_log_level_rec) then
1148                              raise fareven_err;
1149                           end if;
1150                        else
1151                            if (p_reval_options_rec.run_mode = 'PREVIEW') then
1152                               x_reval_out.life_notdef := l_recalc_life;
1153                               x_reval_out.new_life := l_recalc_life;
1154                               goto fareven_exit_noerr;
1155                            else
1156                                raise fareven_err;
1157                            end if; -- ins_txn_flag = FALSE
1158                        end if; -- l_rate_source_rule = FAD_RSR_CALC
1159                      end if;  -- end if for not fazccmt
1160                 end if; -- CALC or TABLE or FORMULA
1161 
1162                 -- Assign all values to the depreciation engine to compute the
1163                 -- total depreciation on the asset that would have accrued till
1164                 -- this point if the life of the asset had been 'recalc life'
1165                 -- and cost had been new_rec_cost
1166 
1167                 l_dpr_in.adj_cost := x_reval_out.new_rec_cost;
1168                 l_dpr_in.rec_cost := x_reval_out.new_rec_cost;
1169                 l_dpr_in.reval_amo_basis := 0;
1170                 l_dpr_in.deprn_rsv := 0;
1171                 l_dpr_in.reval_rsv := 0;
1172 
1173                 -- Bonus Deprn  YYOON
1174                 l_dpr_in.bonus_deprn_rsv := 0;
1175 
1176                 -- End of Bonus Deprn Change
1177                 l_dpr_in.adj_rate := p_asset_fin_rec_old.adjusted_rate;
1178                 l_dpr_in.rate_adj_factor := 1;
1179                 -- Fix For Bug #2018862.  Set formula factor to 1
1180                 l_dpr_in.formula_factor := 1;
1181                 l_dpr_in.capacity := p_asset_fin_rec_old.production_capacity;
1182                 l_dpr_in.adj_capacity := p_asset_fin_rec_old.production_capacity;
1183                 l_dpr_in.ltd_prod := 0;
1184                 l_dpr_in.asset_num := p_asset_desc_rec.asset_number;
1185                 l_dpr_in.calendar_type := l_deprn_calendar;
1186                 l_dpr_in.ceil_name := p_asset_fin_rec_old.ceiling_name;
1187                 l_dpr_in.bonus_rule := p_asset_fin_rec_old.bonus_rule;
1188                 l_dpr_in.book := p_asset_hdr_rec.book_type_code;
1189                 l_dpr_in.method_code := p_asset_fin_rec_old.deprn_method_code;
1190                 l_dpr_in.asset_id := p_asset_hdr_rec.asset_id;
1191                 l_dpr_in.jdate_in_service :=
1192                   to_number(to_char(
1193                             p_asset_fin_rec_old.date_placed_in_service, 'J'));
1194                 l_dpr_in.prorate_jdate :=
1195                   to_number(to_char(p_asset_fin_rec_old.prorate_date, 'J'));
1196                 l_dpr_in.deprn_start_jdate :=
1197                   to_number(to_char(p_asset_fin_rec_old.deprn_start_date, 'J'));
1198                 l_dpr_in.jdate_retired := 0;
1199                 l_dpr_in.ret_prorate_jdate := 0;
1200                 l_dpr_in.life := l_recalc_life;
1201                 l_dpr_in.rsv_known_flag := TRUE;
1202 
1203                 -- copy adjusted recoverable cost to l_dpr_in to
1204                 -- make it compatible with faxcde() which supports
1205                 -- asset with depreciation limit
1206 
1207                 -- **************************************************
1208                 -- Assign adj_rec_cost calculated in faucrc to
1209                 -- l_dpr_in.adj_rec_cost. For fully reserved assets that
1210                 -- should still be fully reserved after life extension
1211                 -- factor, will not calculate new reserve correctly if
1212                 -- recalculated adj_rec_cost is not passed to faxcde
1213                 -- Fix for 1229608 SNARAYAN
1214                 -- ***************************************************
1215 
1216                 l_dpr_in.adj_rec_cost :=
1217                      px_asset_fin_rec_new.adjusted_recoverable_cost;
1218 
1219                 --fix for 1666248 - assign new salvage value which was
1220                 --calculated based on the percent specified in category
1221 
1222                 l_dpr_in.salvage_value := x_reval_out.new_salvage_value;
1223                 l_dpr_in.salvage_value :=
1224                      px_asset_fin_rec_new.salvage_value;
1225 
1226                 l_dpr_in.deprn_rounding_flag := 'REV';
1227 
1228                 -- Copy prior_fy_exp from reval_in_struct to
1229                 -- deprn_struct.
1230                 l_dpr_in.prior_fy_exp := p_asset_deprn_rec_old.prior_fy_expense;
1231                 l_dpr_in.ytd_deprn := p_asset_deprn_rec_old.ytd_deprn;
1232 
1233                 -- Bonus Deprn  YYOON
1234                 l_dpr_in.prior_fy_bonus_exp :=
1235                                   p_asset_deprn_rec_old.prior_fy_bonus_expense;
1236                 l_dpr_in.bonus_ytd_deprn := p_asset_deprn_rec_old.bonus_ytd_deprn;
1237                 -- End of Bonus Deprn Change
1238 
1239                 l_fy := -1;
1240                 l_period_num := -1;
1241 
1242 
1243                 SELECT      FY.FISCAL_YEAR, CP.PERIOD_NUM
1244                 INTO        l_fy, l_period_num
1245                 FROM        FA_FISCAL_YEAR FY,
1246                             FA_CALENDAR_PERIODS CP
1247                 WHERE       FY.FISCAL_YEAR_NAME = l_fy_name
1248                 AND         CP.CALENDAR_TYPE = l_deprn_calendar
1249                 AND         p_asset_fin_rec_old.prorate_date BETWEEN
1250                                     CP.START_DATE AND CP.END_DATE
1251                 AND         p_asset_fin_rec_old.prorate_date BETWEEN
1252                                         FY.START_DATE AND FY.END_DATE;
1253                 l_dpr_in.y_begin := l_fy;
1254                 l_dpr_in.p_cl_begin := 1;
1255 
1256                 l_fy := -1;
1257                 l_period_num := -1;
1258 
1259                 SELECT      DP.FISCAL_YEAR, DP.PERIOD_NUM
1260                 INTO        l_fy, l_period_num
1261                 FROM        FA_DEPRN_PERIODS DP
1262                 WHERE       DP.BOOK_TYPE_CODE = p_asset_hdr_rec.book_type_code
1263                 AND         DP.PERIOD_COUNTER = l_last_period_counter;
1264 
1265                 l_dpr_in.y_end := l_fy;
1266                 l_dpr_in.p_cl_end := l_period_num;
1267 
1268                 -- Added for code from fa.m
1269                 l_dpr_in.mrc_sob_type_code := p_mrc_sob_type_code;
1270                 l_dpr_in.tracking_method := p_asset_fin_rec_old.tracking_method;                l_dpr_in.allocate_to_fully_ret_flag :=
1271                           p_asset_fin_rec_old.allocate_to_fully_ret_flag;
1272                 l_dpr_in.allocate_to_fully_rsv_flag :=
1273                           p_asset_fin_rec_old.allocate_to_fully_rsv_flag;
1274                 l_dpr_in.excess_allocation_option :=
1275                           p_asset_fin_rec_old.excess_allocation_option;
1276                 l_dpr_in.depreciation_option :=
1277                           p_asset_fin_rec_old.depreciation_option;
1278                 l_dpr_in.member_rollup_flag :=
1279                           p_asset_fin_rec_old.member_rollup_flag;
1280                 l_dpr_in.eofy_reserve := p_asset_fin_rec_old.eofy_reserve;
1281                 l_dpr_in.update_override_status := FALSE;
1282                 l_dpr_in.over_depreciate_option :=
1283                           p_asset_fin_rec_old.over_depreciate_option;
1284                 l_dpr_in.super_group_id := p_asset_fin_rec_old.super_group_id;
1285                 l_dpr_in.cost := px_asset_fin_rec_new.cost;
1286                 --l_dpr_in.asset_type := p_asset_type_rec.asset_type;
1287 
1288                 if (p_log_level_rec.statement_level) then
1289                    fa_debug_pkg.add('fareven', 'CALLING FAXCDE FROM FAREVEN',
1290                                     1
1291                                     ,p_log_level_rec => p_log_level_rec);
1292                 end if;
1293 
1294                 if (not FA_CDE_PKG.faxcde(
1295                            l_dpr_in,
1296                            l_dpr_arr,
1297                            l_dpr_out,
1298                            l_running_mode
1299                            ,p_log_level_rec => p_log_level_rec)) then
1300                    raise fareven_err;
1301                 end if;
1302 
1303                 --Compute Adjustment to Depreciation Reserve
1304 
1305                 x_reval_out.deprn_rsv_adj := l_dpr_out.new_deprn_rsv -
1306                                              p_asset_deprn_rec_old.deprn_reserve;
1307 
1308                 -- Bonus Deprn YYOON
1309                 x_reval_out.bonus_deprn_rsv_adj :=
1310                                 l_dpr_out.new_bonus_deprn_rsv -
1311                                 p_asset_deprn_rec_old.bonus_deprn_reserve;
1312 
1313                 -- End of Bonus Deprn Change
1314 
1315             else  -- If Depreciation Reserve is to be revalued.
1316 
1317                 --Compute Adjustment to Depreciation Reserve
1318 
1319                 x_reval_out.deprn_rsv_adj :=
1320                                     -p_asset_deprn_rec_old.deprn_reserve;
1321 
1322                 -- Bonus Deprn YYOON
1323                 x_reval_out.bonus_deprn_rsv_adj :=
1324                                -p_asset_deprn_rec_old.bonus_deprn_reserve;
1325                 -- End of Bonus Deprn Change
1326             end if; --If Depreciation Reserve is to be revalued.
1327 
1328             --GBertot: compute adjustment to YTD deprn.
1329             -- if it is to be revalued
1330 
1331             if (l_reval_ytd_deprn_flag = 'YES') then
1332                x_reval_out.ytd_deprn_adj := p_asset_deprn_rec_old.ytd_deprn *
1333                                             l_reval_rate;
1334                -- round to correct precision
1335                if not FA_UTILS_PKG.faxrnd(x_reval_out.ytd_deprn_adj,
1336                               p_asset_hdr_rec.book_type_code
1337                               ,p_log_level_rec => p_log_level_rec) then
1338                   raise fareven_err;
1339                end if;
1340 
1341                -- Bonus Deprn  YYOON
1342                x_reval_out.bonus_ytd_deprn_adj :=
1343                                      p_asset_deprn_rec_old.bonus_ytd_deprn *
1344                                      l_reval_rate;
1345 
1346                if not FA_UTILS_PKG.faxrnd(x_reval_out.bonus_ytd_deprn_adj,
1347                               p_asset_hdr_rec.book_type_code
1348                               ,p_log_level_rec => p_log_level_rec) then
1349                   raise fareven_err;
1350 
1351                end if;
1352 
1353                -- End of Bonus Deprn Change
1354 
1355             else -- if YTD deprn. is not to be revalued
1356 
1357                x_reval_out.ytd_deprn_adj := 0;
1358                -- Bonus Deprn  YYOON
1359                x_reval_out.bonus_ytd_deprn_adj := 0;
1360                --End of Bonus Deprn Change
1361 
1362             end if; -- if YTD deprn. is not to be revalued
1363 
1364             -- Compute Adjustment to Revaluation Reserve
1365 
1366             x_reval_out.reval_rsv_adj := x_reval_out.cost_adj -
1367                                          x_reval_out.deprn_rsv_adj;
1368 
1369             -- GBertot: Compute adjustment to revaluation reserve due
1370             -- to YTD deprn.
1371             x_reval_out.reval_rsv_adj := x_reval_out.reval_rsv_adj +
1372                                          x_reval_out.ytd_deprn_adj;
1373 
1374             -- Compute new life using life extension factor
1375             -- regardless of
1376             -- life extension ceiling
1377 
1378             l_recalc_life := p_asset_fin_rec_old.life_in_months * l_life_extension_factor;
1379             l_recalc_life := trunc(l_recalc_life);
1380 
1381             if (p_log_level_rec.statement_level) then
1382                fa_debug_pkg.add('fareven', 'RECALC LIFE2',1
1383                               ,p_log_level_rec => p_log_level_rec);
1384                fa_debug_pkg.add('fareven', 'l_recalc_life2.1',
1385                                 l_recalc_life
1386                                 ,p_log_level_rec => p_log_level_rec);
1387             end if;
1388 
1389             -- Find if the Depreciation Method for this
1390             -- calculated life exists
1391 
1392             if ((l_rate_source_rule = FA_STD_TYPES.FAD_RSR_CALC) OR
1393                 (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_TABLE) OR
1394                 (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_FORMULA))  then
1395                 if not fa_cache_pkg.fazccmt
1396                    (X_method        => p_asset_fin_rec_old.deprn_method_code,
1397                     X_life          => l_recalc_life
1398                     ,p_log_level_rec => p_log_level_rec) then
1399                    if (p_log_level_rec.statement_level) then
1400                        fa_debug_pkg.add('fareven', 'fazccmt false',1
1401                                               ,p_log_level_rec => p_log_level_rec);
1402                    end if;
1403                    if (l_rate_source_rule = FA_STD_TYPES.FAD_RSR_CALC) then
1404                        if (p_log_level_rec.statement_level) then
1405                            fa_debug_pkg.add('fareven',
1406                                             'calling validate_life' ,1
1407 					,p_log_level_rec => p_log_level_rec);
1408                        end if;
1409                       if not fa_asset_val_pvt.validate_life
1410                              (p_deprn_method      => p_asset_fin_rec_old.deprn_method_code,
1411                               p_rate_source_rule  => l_rate_source_rule,
1412                               p_life_in_months    => l_recalc_life,
1413                               p_lim               => l_recalc_life,
1414                               p_user_id           =>
1415                                        px_trans_rec.who_info.last_updated_by,
1416                               p_curr_date         =>
1417                                        px_trans_rec.who_info.last_update_date,
1418                               px_new_life         => l_recalc_life,
1419                               p_calling_fn        => 'fareven'
1420                               ,p_log_level_rec => p_log_level_rec) then
1421                              raise fareven_err;
1422                       end if;
1423                    else
1424                       if (p_reval_options_rec.run_mode = 'PREVIEW') then
1425                         x_reval_out.life_notdef := l_recalc_life;
1426                         x_reval_out.new_life := l_recalc_life;
1427                         goto fareven_exit_noerr;
1428                       else
1429                          -- Display method/life combination that doesn't
1430                          -- exist, and that the program can't create
1431                          raise fareven_err;
1432                       end if;
1433                    end if;
1434                 end if;
1435             end if;
1436             x_reval_out.new_life := l_recalc_life;
1437 
1438             px_asset_fin_rec_new.adjusted_cost :=
1439                                  px_asset_fin_rec_new.recoverable_cost;
1440 
1441             -- Fix for Bug #5880371.  Need to set new life to what is based
1442             -- from the life extension factor.
1443             px_asset_fin_rec_new.life_in_months := l_recalc_life;
1444 
1445             if not FA_AMORT_PVT.faxraf(
1446                px_trans_rec            => px_trans_rec,
1447                p_asset_hdr_rec         => p_asset_hdr_rec,
1448                p_asset_desc_rec        => p_asset_desc_rec,
1449                p_asset_cat_rec         => p_asset_cat_rec,
1450                p_asset_type_rec        => p_asset_type_rec,
1451                p_asset_fin_rec_old     => p_asset_fin_rec_old,
1452                px_asset_fin_rec_new    => px_asset_fin_rec_new,
1453                p_asset_deprn_rec       => p_asset_deprn_rec_old,
1454                p_period_rec            => p_period_rec,
1455                px_deprn_exp            => l_deprn_exp,
1456                px_bonus_deprn_exp      => l_bonus_deprn_exp,
1457                px_reval_deprn_rsv_adj  => x_reval_out.deprn_rsv_adj,
1458                p_mrc_sob_type_code     => p_mrc_sob_type_code,
1459                p_running_mode          => fa_std_types.FA_DPR_NORMAL,
1460                p_used_by_revaluation   => 1
1461                ,p_log_level_rec => p_log_level_rec) then
1462                raise fareven_err;
1463             end if;
1464 
1465             x_reval_out.new_fully_rsvd_revals_ctr :=
1466                 p_asset_fin_rec_old.fully_rsvd_revals_counter + 1;
1467 
1468         end if;
1469           --If fully reserved assets are to be revalued and fully
1470           --reserved reval count is < max fully reserved revaluations
1471     end if; -- If the asset is fully reserved
1472 
1473     -- populate px_asset_fin_rec_new and px_asset_deprn_rec_new
1474     if (p_asset_type_rec.asset_type = 'CIP') then
1475        px_asset_fin_rec_new.rate_adjustment_factor := 1;
1476     end if;
1477     px_asset_fin_rec_new.life_in_months := l_recalc_life;
1478     px_asset_fin_rec_new.fully_rsvd_revals_counter :=
1479                              x_reval_out.new_fully_rsvd_revals_ctr;
1480 
1481     px_asset_deprn_rec_new.deprn_reserve :=
1482                      p_asset_deprn_rec_old.deprn_reserve +
1483                      x_reval_out.deprn_rsv_adj;
1484     px_asset_deprn_rec_new.reval_deprn_reserve :=
1485                      p_asset_deprn_rec_old.reval_deprn_reserve +
1486                      x_reval_out.reval_rsv_adj;
1487     px_asset_deprn_rec_new.bonus_deprn_reserve :=
1488                      p_asset_deprn_rec_old.bonus_deprn_reserve +
1489                      x_reval_out.bonus_deprn_rsv_adj;
1490 /*  commenting out - this is a duplicate
1491     px_asset_deprn_rec_new.reval_deprn_reserve :=
1492                      p_asset_deprn_rec_old.reval_deprn_reserve +
1493                      x_reval_out.reval_rsv_adj; */
1494 
1495 --  populate new reval_amort basis here
1496     px_asset_fin_rec_new.reval_amortization_basis := px_asset_deprn_rec_new.reval_deprn_reserve;
1497 
1498     -- If cost adjustment is not 0 or the new life is not the
1499     -- same as old life and INSERT TRANSACTION_FLAG is TRUE then
1500     -- insert rows in FA_ADJUSTMENTS
1501 
1502     if (p_reval_options_rec.run_mode = 'RUN') then
1503        if (x_reval_out.cost_adj <> 0 OR
1504             p_asset_fin_rec_old.life_in_months <> x_reval_out.new_life) then
1505             if ((p_asset_deprn_rec_old.deprn_reserve +
1506                  x_reval_out.deprn_rsv_adj) =
1507                  px_asset_fin_rec_new.recoverable_cost) then
1508                 px_trans_rec.transaction_subtype := 'FULL RSV';
1509                 x_reval_out.pc_fully_res := l_last_period_counter + 1;
1510             else
1511                 px_trans_rec.transaction_subtype := 'STANDARD';
1512                 x_reval_out.pc_fully_res := NULL;
1513             end if;
1514 
1515             px_asset_fin_rec_new.period_counter_fully_reserved :=
1516                                          x_reval_out.pc_fully_res;
1517             px_asset_fin_rec_new.period_counter_life_complete :=
1518                                          x_reval_out.pc_fully_res;
1519 
1520             -- Load Adjustment structure for inserting into table
1521             -- FA_ADJUSTMENTS
1522 
1523             -- Get Asset Cost Account, Revaluation Reserve Account,
1524             -- Depreciation Reserve Account
1525             -- and Bonus Deprn Reserve Account
1526             --  from Category Books Cache
1527 
1528             if (not fa_cache_pkg.fazccb
1529                  (X_book   => p_asset_hdr_rec.book_type_code,
1530                   X_cat_id => p_asset_cat_rec.category_id
1531                   ,p_log_level_rec => p_log_level_rec)) then
1532                raise fareven_err;
1533             end if;
1534             l_cost_acct := fa_cache_pkg.fazccb_record.ASSET_COST_ACCT;
1535             l_cip_cost_acct := fa_cache_pkg.fazccb_record.CIP_COST_ACCT;
1536             l_reval_rsv_acct := fa_cache_pkg.fazccb_record.REVAL_RESERVE_ACCT;
1537             l_deprn_rsv_acct := fa_cache_pkg.fazccb_record.DEPRN_RESERVE_ACCT;
1538             l_deprn_exp_acct := fa_cache_pkg.fazccb_record.DEPRN_EXPENSE_ACCT;
1539 
1540             -- Bonus Deprn - YYOON
1541             --   Getting the bonus deprn expense
1542             --   and the bonus deprn reserve account
1543             --   from asset category
1544             l_adj_in.account :=
1545                      fa_cache_pkg.fazccb_record.BONUS_DEPRN_EXPENSE_ACCT;
1546             l_adj_in.account :=
1547                      fa_cache_pkg.fazccb_record.BONUS_DEPRN_RESERVE_ACCT;
1548             --End of Bonus Deprn Change
1549 
1550             l_adj_in.transaction_header_id := px_trans_rec.transaction_header_id;
1551             l_adj_in.asset_invoice_id := 0;
1552             l_adj_in.source_type_code := 'REVALUATION';
1553             if (p_asset_type_rec.asset_type = 'CIP') then
1554                 l_adj_in.adjustment_type := 'CIP COST';
1555              else
1556                 l_adj_in.adjustment_type := 'COST';
1557             end if;
1558 
1559             if (x_reval_out.cost_adj > 0) then
1560                 l_adj_in.debit_credit_flag := 'DR';
1561             else
1562                 l_adj_in.debit_credit_flag := 'CR';
1563             end if;
1564             l_adj_in.code_combination_id := 0;
1565             l_adj_in.book_type_code := p_asset_hdr_rec.book_type_code;
1566             l_adj_in.period_counter_created := l_last_period_counter + 1;
1567             l_adj_in.asset_id := p_asset_hdr_rec.asset_id;
1568             l_adj_in.adjustment_amount := abs(x_reval_out.cost_adj);
1569             l_adj_in.period_counter_adjusted := l_last_period_counter + 1;
1570             l_adj_in.distribution_id := 0;
1571             l_adj_in.annualized_adjustment := 0;
1572             l_adj_in.last_update_date := px_trans_rec.who_info.last_update_date;
1573 
1574             if (p_asset_type_rec.asset_type = 'CIP')  then
1575                 l_adj_in.account := l_cip_cost_acct;
1576                 l_adj_in.account_type := 'CIP_COST_ACCT';
1577             else
1578                 l_adj_in.account:= l_cost_acct;
1579                 l_adj_in.account_type := 'ASSET_COST_ACCT';
1580             end if;
1581             l_adj_in.current_units := p_asset_desc_rec.current_units;
1582             l_adj_in.selection_mode := fa_adjust_type_pkg.FA_AJ_ACTIVE;
1583             l_adj_in.selection_thid := 0;
1584             l_adj_in.selection_retid := 0;
1585             l_adj_in.flush_adj_flag := FALSE;
1586             l_adj_in.gen_ccid_flag := TRUE;
1587 
1588             l_adj_in.mrc_sob_type_code := p_mrc_sob_type_code;
1589 
1590             if (NOT fa_ins_adjust_pkg.faxinaj(l_adj_in,
1591                                   px_trans_rec.who_info.last_update_date,
1592                                   px_trans_rec.who_info.last_updated_by,
1593                                   px_trans_rec.who_info.last_update_login
1594                                   ,p_log_level_rec => p_log_level_rec)) then               if (p_log_level_rec.statement_level) then
1595                   null;
1596                end if;
1597                raise fareven_err;
1598             end if;
1599 
1600             l_adj_in.leveling_flag := FALSE;
1601 
1602             -- GBertot: Code added to include the depreciation expense
1603             -- account in the revaluation JE
1604 
1605             l_adj_in.adjustment_type := 'EXPENSE';
1606 
1607             if (x_reval_out.ytd_deprn_adj > 0) then
1608                 l_adj_in.debit_credit_flag := 'DR';
1609             else
1610                 l_adj_in.debit_credit_flag := 'CR';
1611             end if;
1612             l_adj_in.code_combination_id := 0;
1613             l_adj_in.book_type_code :=  p_asset_hdr_rec.book_type_code;
1614             l_adj_in.period_counter_created := l_last_period_counter + 1;
1615             l_adj_in.asset_id := p_asset_hdr_rec.asset_id;
1616 
1617             l_adj_in.adjustment_amount :=
1618                            abs(x_reval_out.ytd_deprn_adj);
1619 
1620             l_adj_in.period_counter_adjusted := l_last_period_counter + 1;
1621             l_adj_in.distribution_id := 0;
1622             l_adj_in.annualized_adjustment := 0;
1623             l_adj_in.last_update_date := px_trans_rec.who_info.last_update_date;
1624 
1625             -- BUG# 2150841
1626             -- allow for generating the deprn expense acct
1627             -- via workflow rules
1628             -- bridgway
1629             l_adj_in.account :=  l_deprn_exp_acct;
1630             l_adj_in.account_type := 'DEPRN_EXPENSE_ACCT';
1631             l_adj_in.current_units := p_asset_desc_rec.current_units;
1632 
1633             l_adj_in.selection_mode := fa_adjust_type_pkg.FA_AJ_ACTIVE;
1634             l_adj_in.selection_thid := 0;
1635             l_adj_in.selection_retid := 0;
1636             l_adj_in.flush_adj_flag := FALSE;
1637             l_adj_in.gen_ccid_flag := TRUE;
1638 
1639             if (NOT fa_ins_adjust_pkg.faxinaj(l_adj_in,
1640                                   px_trans_rec.who_info.last_update_date,
1641                                   px_trans_rec.who_info.last_updated_by,
1642                                   px_trans_rec.who_info.last_update_login
1643                                   ,p_log_level_rec => p_log_level_rec)) then               if (p_log_level_rec.statement_level) then
1644                   null;
1645                end if;
1646                raise fareven_err;
1647             end if;
1648 
1649             l_adj_in.gen_ccid_flag := TRUE;
1650             -- GBertot: End of depreciation expense account coding
1651 
1652             -- Bonus Deprn YYOON
1653             if (x_reval_out.bonus_ytd_deprn_adj <> 0) then
1654               l_adj_in.adjustment_type := 'BONUS EXPENSE';
1655               if (x_reval_out.bonus_ytd_deprn_adj > 0) then
1656                   l_adj_in.debit_credit_flag := 'DR';
1657               else
1658                   l_adj_in.debit_credit_flag := 'CR';
1659               end if;
1660               l_adj_in.code_combination_id := 0;
1661               l_adj_in.book_type_code:= p_asset_hdr_rec.book_type_code;
1662               l_adj_in.period_counter_created := l_last_period_counter + 1;
1663               l_adj_in.asset_id := p_asset_hdr_rec.asset_id;
1664 
1665               l_adj_in.adjustment_amount :=
1666                          abs(x_reval_out.bonus_ytd_deprn_adj);
1667 
1668               l_adj_in.period_counter_adjusted := l_last_period_counter + 1;
1669               l_adj_in.distribution_id := 0;
1670               l_adj_in.annualized_adjustment := 0;
1671               l_adj_in.last_update_date := px_trans_rec.who_info.last_update_date;
1672               l_adj_in.account := l_bonus_deprn_exp_acct;
1673               l_adj_in.account_type := 'BONUS_DEPRN_RESERVE_ACCT';
1674               l_adj_in.current_units := p_asset_desc_rec.current_units;
1675               l_adj_in.selection_mode := fa_adjust_type_pkg.FA_AJ_ACTIVE;
1676               l_adj_in.selection_thid := 0;
1677               l_adj_in.selection_retid := 0;
1678               l_adj_in.flush_adj_flag := FALSE;
1679               -- The CCID of BONUS EXPENSE row will be generated
1680               --   through the workflow  YYOON
1681               l_adj_in.gen_ccid_flag := TRUE;
1682 
1683               if (NOT fa_ins_adjust_pkg.faxinaj(l_adj_in,
1684                                   px_trans_rec.who_info.last_update_date,
1685                                   px_trans_rec.who_info.last_updated_by,
1686                                   px_trans_rec.who_info.last_update_login
1687                                   ,p_log_level_rec => p_log_level_rec)) then                 if (p_log_level_rec.statement_level) then
1688                     null;
1689                  end if;
1690                  raise fareven_err;
1691               end if;
1692               l_adj_in.gen_ccid_flag := TRUE;
1693             end if;
1694             -- End of Bonus Deprn Change
1695 
1696             l_adj_in.adjustment_type := 'REVAL RESERVE';
1697             if (x_reval_out.reval_rsv_adj > 0) then
1698                l_adj_in.debit_credit_flag := 'CR';
1699             else
1700                l_adj_in.debit_credit_flag := 'DR';
1701             end if;
1702             l_adj_in.adjustment_amount :=
1703                                abs(x_reval_out.reval_rsv_adj);
1704             l_adj_in.account := l_reval_rsv_acct;
1705 
1706             -- Added a new mode to differentiate the reval reserve
1707             -- value going
1708             -- from reval engine to fa_adjustments table vs.
1709             -- the reval reserve
1710             -- value going from depreciation engine to fa_deprn_detail
1711             -- table for bug 628863.  aling
1712 
1713             l_adj_in.selection_mode := fa_adjust_type_pkg.FA_AJ_ACTIVE_REVAL;
1714 
1715             l_adj_in.account_type := 'REVAL_RESERVE_ACCT';
1716 
1717             if (x_reval_out.reval_rsv_adj <> 0) then
1718                 if (NOT fa_ins_adjust_pkg.faxinaj(l_adj_in,
1719                                   px_trans_rec.who_info.last_update_date,
1720                                   px_trans_rec.who_info.last_updated_by,
1721                                   px_trans_rec.who_info.last_update_login
1722                                   ,p_log_level_rec => p_log_level_rec)) then                  if (p_log_level_rec.statement_level) then
1723                      null;
1724                   end if;
1725                   raise fareven_err;
1726                 end if;
1727             end if;
1728 
1729             -- Reset the selection mode back to the original
1730 
1731             l_adj_in.selection_mode := fa_adjust_type_pkg.FA_AJ_ACTIVE;
1732             l_adj_in.adjustment_type := 'RESERVE';
1733             if (x_reval_out.deprn_rsv_adj > 0) then
1734                l_adj_in.debit_credit_flag := 'CR';
1735             else
1736                l_adj_in.debit_credit_flag := 'DR';
1737             end if;
1738             l_adj_in.adjustment_amount :=
1739                              abs(x_reval_out.deprn_rsv_adj);
1740             l_adj_in.account := l_deprn_rsv_acct;
1741             l_adj_in.account_type := 'DEPRN_RESERVE_ACCT';
1742             l_adj_in.flush_adj_flag := TRUE;
1743 
1744             if (NOT fa_ins_adjust_pkg.faxinaj(l_adj_in,
1745                                   px_trans_rec.who_info.last_update_date,
1746                                   px_trans_rec.who_info.last_updated_by,
1747                                   px_trans_rec.who_info.last_update_login
1748                                   ,p_log_level_rec => p_log_level_rec)) then               if (p_log_level_rec.statement_level) then
1749                   null;
1750                end if;
1751                raise fareven_err;
1752             end if;
1753 
1754             -- Bonus Deprn  YYOON
1755             if (x_reval_out.bonus_deprn_rsv_adj <> 0) then
1756               l_adj_in.selection_mode := fa_adjust_type_pkg.FA_AJ_ACTIVE;
1757               l_adj_in.adjustment_type := 'BONUS RESERVE';
1758               if (x_reval_out.bonus_deprn_rsv_adj > 0) then
1759                  l_adj_in.debit_credit_flag := 'CR';
1760               else
1761                  l_adj_in.debit_credit_flag := 'DR';
1762               end if;
1763               l_adj_in.adjustment_amount :=
1764                         abs(x_reval_out.bonus_deprn_rsv_adj);
1765 
1766               l_adj_in.account := l_bonus_deprn_rsv_acct;
1767               l_adj_in.account_type := 'BONUS_DEPRN_RESERVE_ACCT';
1768               l_adj_in.flush_adj_flag := TRUE;
1769               -- The CCID of BONUS EXPENSE row will be generated
1770               -- through the workflow YYOON
1771               l_adj_in.gen_ccid_flag := TRUE;
1772 
1773               if (NOT fa_ins_adjust_pkg.faxinaj(l_adj_in,
1774                                   px_trans_rec.who_info.last_update_date,
1775                                   px_trans_rec.who_info.last_updated_by,
1776                                   px_trans_rec.who_info.last_update_login
1777                                   ,p_log_level_rec => p_log_level_rec)) then                 if (p_log_level_rec.statement_level) then
1778                     null;
1779                  end if;
1780                  raise fareven_err;
1781               end if;
1782 
1783             end if;
1784             -- End of Bonus Deprn Change
1785        end if; -- If Cost Adjustment != 0 or new life != old life
1786     end if; -- If Insert Transaction Flag = TRUE
1787 
1788 <<fareven_exit_noerr>>
1789     null;
1790 
1791     return(TRUE);
1792 
1793 exception
1794    when fareven_err then
1795       fa_srvr_msg.add_message(calling_fn => l_calling_fn
1796             ,p_log_level_rec => p_log_level_rec);
1797       return false;
1798    when others then
1799       FA_SRVR_MSG.ADD_SQL_ERROR(CALLING_FN => l_calling_fn
1800             ,p_log_level_rec => p_log_level_rec);
1801       return FALSE;
1802 
1803 end fareven;
1804 
1805 END FA_REVALUATION_PVT;