DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_ADJUSTMENT_PVT

Source


1 PACKAGE BODY FA_ADJUSTMENT_PVT as
2 /* $Header: FAVADJB.pls 120.68.12020000.5 2013/03/19 18:08:48 dvjoshi ship $   */
3 
4 g_release                  number  := fa_cache_pkg.fazarel_release;
5 
6 FUNCTION do_adjustment
7    (px_trans_rec              IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
8     px_asset_hdr_rec          IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
9     p_asset_desc_rec          IN     FA_API_TYPES.asset_desc_rec_type,
10     p_asset_type_rec          IN     FA_API_TYPES.asset_type_rec_type,
11     p_asset_cat_rec           IN     FA_API_TYPES.asset_cat_rec_type,
12     p_asset_fin_rec_old       IN     FA_API_TYPES.asset_fin_rec_type,
13     p_asset_fin_rec_adj       IN     FA_API_TYPES.asset_fin_rec_type,
14     x_asset_fin_rec_new          OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
15     p_inv_trans_rec           IN     FA_API_TYPES.inv_trans_rec_type,
16     p_asset_deprn_rec_old     IN     FA_API_TYPES.asset_deprn_rec_type,
17     p_asset_deprn_rec_adj     IN     FA_API_TYPES.asset_deprn_rec_type,
18     x_asset_deprn_rec_new        OUT NOCOPY FA_API_TYPES.asset_deprn_rec_type,
19     p_period_rec              IN     FA_API_TYPES.period_rec_type,
20     p_reclassed_asset_id      IN     NUMBER default null,
21     p_reclass_src_dest        IN     VARCHAR2 default null,
22     p_reclassed_asset_dpis    IN     DATE default null,
23     p_mrc_sob_type_code       IN     VARCHAR2,
24     p_group_reclass_options_rec IN OUT NOCOPY FA_API_TYPES.group_reclass_options_rec_type,
25     p_calling_fn              IN     VARCHAR2
26    , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
27 
28    l_th_rowid                        varchar2(30);
29    l_bks_rowid                       varchar2(30);
30 
31    l_status                          boolean;
32    l_ret_status                      varchar2(1);
33 
34    l_old_transaction_type_code       varchar2(30);
35    l_period_counter                  number;
36 
37    l_deprn_exp                       number;
38    l_bonus_deprn_exp                 number;
39    l_impairment_exp                  number;
40    l_deprn_adjustment_amount         number;
41    l_deprn_exp_amort_nbv             number;
42 
43    -- Bug 8533933
44    l_bonus_deprn_exp_adj             number;
45    l_bonus_reserve_adj               number;
46    -- End Bug 8533933
47 
48    --Bug 8297075
49    l_mvmt_deprn_reval_reserve        number;
50    l_open_deprn_reval_reserve        number;
51    --Bug 8297075
52 
53    l_raf                             number;
54 
55    l_calling_fn                      varchar2(35) := 'fa_adjustment_pvt.do_adjustment';
56    deprn_override_flag_default       varchar2(1);
57 
58    l_reserve_adjustment_amount       number;
59    l_asset_fin_rec_null              FA_API_TYPES.asset_fin_rec_type;
60 
61    adj_err                           EXCEPTION;
62 
63    -- Track Member
64    l_ret_code                     number;
65    l_group_level_override         VARCHAR2(1) := 'Y';
66    x_group_deprn_amount           number;
67    x_group_bonus_amount           number;
68 
69    --Bug3548724
70    l_asset_deprn_rec_adj          FA_API_TYPES.asset_deprn_rec_type;
71 
72    -- SLA
73    l_event_status                 varchar2(15);
74    l_event_type_code              varchar2(30);
75 
76    l_cgu_change_flag              VARCHAR2(1) := 'N';
77    l_nbv_at_switch_var            VARCHAR2(1) := 'Y';--bug 7555962
78    -- Bug:5930979:Japan Tax Reform Project
79    l_method_type                  NUMBER := 0;
80    l_success                      INTEGER;
81    l_rate_in_use                  NUMBER;
82 
83    l_original_Rate                NUMBER;
84    l_Revised_Rate                 NUMBER;
85    l_Guaranteed_Rate              NUMBER;
86    l_is_revised_rate              NUMBER;
87    l_comp_val                     NUMBER; --bug 8639894
88     --Secondary changes
89    l_secondary_asset_hdr_rec     fa_api_types.asset_hdr_rec_type;
90    l_secondary_trans_rec         fa_api_types.trans_rec_type;
91    l_secondary_sob_id            NUMBER;
92 BEGIN
93 
94    --set up transaction types for adjustments vs. addition voids
95 
96    if (px_asset_hdr_rec.period_of_addition = 'Y' and
97        G_release = 11) then
98       if (p_asset_type_rec.asset_type = 'CIP') then
99          px_trans_rec.transaction_type_code := 'CIP ADDITION';
100          l_old_transaction_type_code := 'CIP ADDITION';
101       elsif (p_asset_type_rec.asset_type = 'GROUP') then
102          px_trans_rec.transaction_type_code := 'GROUP ADDITION';
103          l_old_transaction_type_code := 'GROUP ADDITION';
104       else
105          px_trans_rec.transaction_type_code := 'ADDITION';
106          l_old_transaction_type_code := 'ADDITION';
107       end if;
108    else
109       if (p_asset_type_rec.asset_type = 'CIP') then
110          px_trans_rec.transaction_type_code := 'CIP ADJUSTMENT';
111          l_old_transaction_type_code := 'CIP ADJUSTMENT';
112       elsif  (p_asset_type_rec.asset_type = 'GROUP') then
113          l_old_transaction_type_code := 'GROUP ADJUSTMENT';
114       else
115          px_trans_rec.transaction_type_code := 'ADJUSTMENT';
116          l_old_transaction_type_code := 'ADJUSTMENT';
117       end if;
118    end if;
119 
120    deprn_override_flag_default:= fa_std_types.FA_NO_OVERRIDE;
121 
122    -- call the calulation engine - see comments below for FA_ADJ
123 
124    if not FA_ASSET_CALC_PVT.calc_fin_info
125                  (px_trans_rec              => px_trans_rec,
126                   p_inv_trans_rec           => p_inv_trans_rec,
127                   p_asset_hdr_rec           => px_asset_hdr_rec ,
128                   p_asset_desc_rec          => p_asset_desc_rec,
129                   p_asset_type_rec          => p_asset_type_rec,
130                   p_asset_cat_rec           => p_asset_cat_rec,
131                   p_asset_fin_rec_old       => p_asset_fin_rec_old,
132                   p_asset_fin_rec_adj       => p_asset_fin_rec_adj,
133                   px_asset_fin_rec_new      => x_asset_fin_rec_new,
134                   p_asset_deprn_rec_old     => p_asset_deprn_rec_old,
135                   p_asset_deprn_rec_adj     => p_asset_deprn_rec_adj,
136                   px_asset_deprn_rec_new    => x_asset_deprn_rec_new,
137                   p_period_rec              => p_period_rec,
138                   p_reclassed_asset_id      => p_reclassed_asset_id,
139                   p_reclass_src_dest        => p_reclass_src_dest,
140                   p_reclassed_asset_dpis    => p_reclassed_asset_dpis,
141                   p_mrc_sob_type_code       => p_mrc_sob_type_code,
142                   p_group_reclass_options_rec => p_group_reclass_options_rec,
143                   p_calling_fn              => l_calling_fn
144                  , p_log_level_rec => p_log_level_rec) then raise adj_err;
145    end if;
146 
147    -- Fix for Bug:5130208
148    if (nvl(p_asset_fin_rec_adj.cash_generating_unit_id,
149            nvl(p_asset_fin_rec_old.cash_generating_unit_id, FND_API.G_MISS_NUM)) <>
150        nvl(p_asset_fin_rec_old.cash_generating_unit_id, FND_API.G_MISS_NUM)) then
151       l_cgu_change_flag := 'Y';
152    else
153       l_cgu_change_flag := 'N';
154    end if;
155 
156    -- call the table handlers to process the adjustment
157 
158    -- transaction headers
159 
160    if (p_mrc_sob_type_code <> 'R') then
161 
162       -- validate call is done from public package now
163 
164       -- do th processing
165       if (px_asset_hdr_rec.period_of_addition = 'Y' and
166           G_release = 11) then
167 
168          FA_TRANSACTION_HEADERS_PKG.Update_Trx_Type
169                        (X_Book_Type_Code                => px_asset_hdr_rec.book_type_code,
170                         X_Asset_Id                      => px_asset_hdr_rec.asset_id,
171                         X_Transaction_Type_Code         => l_old_transaction_type_code,
172                         X_New_Transaction_Type          => l_old_transaction_type_code || '/VOID',
173                         X_Return_Status                 => l_status,
174                         X_Calling_Fn                    => l_calling_fn
175                        , p_log_level_rec => p_log_level_rec);
176 
177          if not l_status then
178             raise adj_err;
179          end if;
180 
181          -- for amortize nbv, these need to be set correctly
182          -- outside the period of addition trx date is already the amort date
183          -- BUG# 2425540 - only set the amort_start_date for amort trxs
184 
185          -- group - this is iffy!!!!  do we want trx_date to be dpis in period of add?
186          -- whole section if iffy - why are we resetting amort start date here???
187          -- should be able to modify reclass engine to redefault the info instead
188            -- of exlcuding it here
189 
190         --Bug6332519
191         --Added the check for amortization_start_date
192          if (px_trans_rec.transaction_subtype = 'AMORTIZED' and
193              p_asset_type_rec.asset_type <> 'GROUP')  and
194              px_trans_rec.amortization_start_date is null then
195             px_trans_rec.amortization_start_date  := px_trans_rec.transaction_date_entered;
196          end if;
197 
198          if (p_asset_type_rec.asset_type <> 'GROUP') then
199             px_trans_rec.transaction_date_entered := x_asset_fin_rec_new.date_placed_in_service;
200          end if;
201 
202       end if;
203 
204       -- SLA UPTAKE
205       -- assign an event for the transaction
206       -- at this point key info asset/book/trx info is known from above code
207       --   *** but trx_date_entered may not be correct! - revisit ***
208       --
209       -- do not assign when this is called from invoice api for like
210       -- asset types - an event is already assigned and do not call
211       -- when this is called for a group asset from the driving member
212 
213       if (nvl(p_inv_trans_rec.transaction_type, 'X') <> 'INVOICE TRANSFER' and
214           p_calling_fn = 'fa_adjustment_pub.do_all_books' and
215           px_trans_rec.member_transaction_header_id is null and
216           G_release <> 11) then
217 
218          if (x_asset_fin_rec_new.adjustment_required_status = 'GADJ') then
219             l_event_status := FA_XLA_EVENTS_PVT.C_EVENT_INCOMPLETE;
220          else
221             l_event_status := null; -- default
222          end if;
223 
224          if not FA_XLA_EVENTS_PVT.create_transaction_event
225                  (p_asset_hdr_rec          => px_asset_hdr_rec,
226                   p_asset_type_rec         => p_asset_type_rec,
227                   px_trans_rec             => px_trans_rec,
228                   p_event_status           => l_event_status,
229                   p_calling_fn             => l_calling_fn
230                   ,p_log_level_rec => p_log_level_rec) then
231             raise adj_err;
232          end if;
233          --Secondary Changes
234          l_secondary_sob_id := FA_XLA_EVENTS_PVT.get_secondary_sob_id(px_asset_hdr_rec.book_type_code);
235 	 if(l_secondary_sob_id is not null) then
236              l_secondary_asset_hdr_rec  := px_asset_hdr_rec;
237              l_secondary_trans_rec         := px_trans_rec;
238              l_secondary_asset_hdr_rec.set_of_books_id := l_secondary_sob_id;
239              if not FA_XLA_EVENTS_PVT.create_transaction_event
240                      (p_asset_hdr_rec          => l_secondary_asset_hdr_rec,
241                       p_asset_type_rec         => p_asset_type_rec,
242                       px_trans_rec             => l_secondary_trans_rec,
243                       p_event_status           => l_event_status,
244                       p_calling_fn             => l_calling_fn
245                       ,p_log_level_rec => p_log_level_rec) then
246                 raise adj_err;
247              end if;
248          end if;
249       elsif (x_asset_fin_rec_new.adjustment_required_status = 'GADJ' and
250              G_release <> 11) then
251          -- enter here if member driven and deferred calculations
252 
253          if not fa_xla_events_pvt.get_event_type
254            (p_event_id              => px_trans_rec.event_id,
255             x_event_type_code       => l_event_type_code,
256             p_log_level_rec         => p_log_level_rec
257            ) then
258            raise adj_err;
259          end if;
260 
261          if (l_event_type_code in ('SOURCE_LINE_TRANSFERS',
262                                    'CIP_SOURCE_LINE_TRANSFERS')) then
263 
264             if not fa_xla_events_pvt.update_inter_transaction_event
265                (p_ledger_id              => px_asset_hdr_rec.set_of_books_id,
266                 p_trx_reference_id       => px_trans_rec.trx_reference_id,
267                 p_book_type_code         => px_asset_hdr_rec.book_type_code,
268                 p_event_type_code        => l_event_type_code,
269                 p_event_date             => px_trans_rec.transaction_date_entered,
270                 p_event_status_code      => FA_XLA_EVENTS_PVT.C_EVENT_INCOMPLETE,
271                 p_calling_fn             => l_calling_fn,
272                 p_log_level_rec          => p_log_level_rec) then
273               raise adj_err;
274             end if;
275             --Secondary changes
276             l_secondary_sob_id := FA_XLA_EVENTS_PVT.get_secondary_sob_id(px_asset_hdr_rec.book_type_code);
277             if(l_secondary_sob_id is not null) then
278                if not fa_xla_events_pvt.update_inter_transaction_event
279                  (p_ledger_id              => l_secondary_sob_id,
280                   p_trx_reference_id       => px_trans_rec.trx_reference_id,
281                   p_book_type_code         => px_asset_hdr_rec.book_type_code,
282                   p_event_type_code        => l_event_type_code,
283                   p_event_date             => px_trans_rec.transaction_date_entered,
284                   p_event_status_code      => FA_XLA_EVENTS_PVT.C_EVENT_INCOMPLETE,
285                   p_calling_fn             => l_calling_fn,
286                   p_log_level_rec          => p_log_level_rec) then
287                   raise adj_err;
288                end if;
289             end if;
290          else -- non inter asset trx
291 
292             if not fa_xla_events_pvt.update_transaction_event
293                (p_ledger_id              => px_asset_hdr_rec.set_of_books_id,
294                 p_transaction_header_id  => px_trans_rec.member_transaction_header_id,
295                 p_book_type_code         => px_asset_hdr_rec.book_type_code,
296                 p_event_type_code        => l_event_type_code,
297                 p_event_date             => px_trans_rec.transaction_date_entered,
298                 p_event_status_code      => FA_XLA_EVENTS_PVT.C_EVENT_INCOMPLETE,
299                 p_calling_fn             => l_calling_fn,
300                 p_log_level_rec          => p_log_level_rec) then
301                raise adj_err;
302             end if;
303             --Secondary changes
304             l_secondary_sob_id := FA_XLA_EVENTS_PVT.get_secondary_sob_id(px_asset_hdr_rec.book_type_code);
305             if(l_secondary_sob_id is not null) then
306                    if not fa_xla_events_pvt.update_transaction_event
307                       (p_ledger_id              => l_secondary_sob_id,
308                        p_transaction_header_id  => px_trans_rec.member_transaction_header_id,
309                        p_book_type_code         => px_asset_hdr_rec.book_type_code,
310                        p_event_type_code        => l_event_type_code,
311                        p_event_date             => px_trans_rec.transaction_date_entered,
312                        p_event_status_code      => FA_XLA_EVENTS_PVT.C_EVENT_INCOMPLETE,
313                        p_secondary_flag               => TRUE,
314                        p_calling_fn             => l_calling_fn,
315                        p_log_level_rec          => p_log_level_rec) then
316                       raise adj_err;
317                    end if;
318                 end if;
319             end if;
320       end if;
321 
322       if (p_log_level_rec.statement_level) then
323         fa_debug_pkg.add('pvt adj api', 'trx_date before insert', px_trans_rec.transaction_date_entered, p_log_level_rec => p_log_level_rec);
324       end if;
325 
326       FA_TRANSACTION_HEADERS_PKG.Insert_Row
327                       (X_Rowid                          => l_th_rowid,
328                        X_Transaction_Header_Id          => px_trans_rec.transaction_header_id,
329                        X_Book_Type_Code                 => px_asset_hdr_rec.book_type_code,
330                        X_Asset_Id                       => px_asset_hdr_rec.asset_id,
331                        X_Transaction_Type_Code          => px_trans_rec.transaction_type_code,
332                        X_Transaction_Date_Entered       => px_trans_rec.transaction_date_entered,
333                        X_Date_Effective                 => px_trans_rec.who_info.creation_date,
334                        X_Last_Update_Date               => px_trans_rec.who_info.last_update_date,
335                        X_Last_Updated_By                => px_trans_rec.who_info.last_updated_by,
336                        X_Transaction_Name               => px_trans_rec.transaction_name,
337                        X_Invoice_Transaction_Id         => p_inv_trans_rec.invoice_transaction_id ,
338                        X_Source_Transaction_Header_Id   => px_trans_rec.Source_Transaction_Header_Id,
339                        X_Mass_Reference_Id              => px_trans_rec.mass_reference_id,
340                        X_Last_Update_Login              => px_trans_rec.who_info.last_update_login,
341                        X_Transaction_Subtype            => px_trans_rec.transaction_subtype,
342                        X_Attribute1                     => px_trans_rec.desc_flex.attribute1,
343                        X_Attribute2                     => px_trans_rec.desc_flex.attribute2,
344                        X_Attribute3                     => px_trans_rec.desc_flex.attribute3,
345                        X_Attribute4                     => px_trans_rec.desc_flex.attribute4,
346                        X_Attribute5                     => px_trans_rec.desc_flex.attribute5,
347                        X_Attribute6                     => px_trans_rec.desc_flex.attribute6,
348                        X_Attribute7                     => px_trans_rec.desc_flex.attribute7,
349                        X_Attribute8                     => px_trans_rec.desc_flex.attribute8,
350                        X_Attribute9                     => px_trans_rec.desc_flex.attribute9,
351                        X_Attribute10                    => px_trans_rec.desc_flex.attribute10,
352                        X_Attribute11                    => px_trans_rec.desc_flex.attribute11,
353                        X_Attribute12                    => px_trans_rec.desc_flex.attribute12,
354                        X_Attribute13                    => px_trans_rec.desc_flex.attribute13,
355                        X_Attribute14                    => px_trans_rec.desc_flex.attribute14,
356                        X_Attribute15                    => px_trans_rec.desc_flex.attribute15,
357                        X_Attribute_Category_Code        => px_trans_rec.desc_flex.attribute_category_code,
358                        X_Transaction_Key                => px_trans_rec.transaction_key,
359                        X_Amortization_Start_Date        => px_trans_rec.amortization_start_date,
360                        X_Calling_Interface              => px_trans_rec.calling_interface,
361                        X_Mass_Transaction_ID            => px_trans_rec.mass_transaction_id,
362                        X_Member_Transaction_Header_Id   => px_trans_rec.member_transaction_header_id,
363                        X_Trx_Reference_Id               => px_trans_rec.trx_reference_id,
364                        X_Event_Id                       => px_trans_rec.event_id,
365 
366                        X_Return_Status                  => l_status,
367                        X_Calling_Fn                     => l_calling_fn
368                       , p_log_level_rec => p_log_level_rec);
369       if not l_status then
370          raise adj_err;
371       end if;
372    end if;
373 
374    -- terminate the active row
375    fa_books_pkg.deactivate_row
376         (X_asset_id                  => px_asset_hdr_rec.asset_id,
377          X_book_type_code            => px_asset_hdr_rec.book_type_code,
378          X_transaction_header_id_out => px_trans_rec.transaction_header_id,
379          X_date_ineffective          => px_trans_rec.who_info.last_update_date,
380          X_mrc_sob_type_code         => p_mrc_sob_type_code,
381          X_set_of_books_id           => px_asset_hdr_rec.set_of_books_id,
382          X_Calling_Fn                => l_calling_fn
383          , p_log_level_rec => p_log_level_rec);
384 
385    -- fa books
386    fa_books_pkg.insert_row
387          (X_Rowid                        => l_bks_rowid,
388           X_Book_Type_Code               => px_asset_hdr_rec.book_type_code,
389           X_Asset_Id                     => px_asset_hdr_rec.asset_id,
390           X_Date_Placed_In_Service       => x_asset_fin_rec_new.date_placed_in_service,
391           X_Date_Effective               => px_trans_rec.who_info.last_update_date,
392           X_Deprn_Start_Date             => x_asset_fin_rec_new.deprn_start_date,
393           X_Deprn_Method_Code            => x_asset_fin_rec_new.deprn_method_code,
394           X_Life_In_Months               => x_asset_fin_rec_new.life_in_months,
395           X_Rate_Adjustment_Factor       => x_asset_fin_rec_new.rate_adjustment_factor,
396           X_Adjusted_Cost                => x_asset_fin_rec_new.adjusted_cost,
397           X_Cost                         => x_asset_fin_rec_new.cost,
398           X_Original_Cost                => x_asset_fin_rec_new.original_cost,
399           X_Salvage_Value                => x_asset_fin_rec_new.salvage_value,
400           X_Prorate_Convention_Code      => x_asset_fin_rec_new.prorate_convention_code,
401           X_Prorate_Date                 => x_asset_fin_rec_new.prorate_date,
402           X_Cost_Change_Flag             => x_asset_fin_rec_new.cost_change_flag,
403           X_Adjustment_Required_Status   => x_asset_fin_rec_new.adjustment_required_status,
404           X_Capitalize_Flag              => x_asset_fin_rec_new.capitalize_flag,
405           X_Retirement_Pending_Flag      => x_asset_fin_rec_new.retirement_pending_flag,
406           X_Depreciate_Flag              => x_asset_fin_rec_new.depreciate_flag,
407           X_Disabled_Flag                => x_asset_fin_rec_new.disabled_flag, --HH
408           X_Last_Update_Date             => px_trans_rec.who_info.last_update_date,
409           X_Last_Updated_By              => px_trans_rec.who_info.last_updated_by,
410           X_Date_Ineffective             => NULL,
411           X_Transaction_Header_Id_In     => px_trans_rec.transaction_header_id,
412           X_Transaction_Header_Id_Out    => NULL,
413           X_Itc_Amount_Id                => x_asset_fin_rec_new.itc_amount_id,
414           X_Itc_Amount                   => x_asset_fin_rec_new.itc_amount,
415           X_Retirement_Id                => x_asset_fin_rec_new.retirement_id,
416           X_Tax_Request_Id               => x_asset_fin_rec_new.tax_request_id,
417           X_Itc_Basis                    => x_asset_fin_rec_new.itc_basis,
418           X_Basic_Rate                   => x_asset_fin_rec_new.basic_rate,
419           X_Adjusted_Rate                => x_asset_fin_rec_new.adjusted_rate,
420           X_Bonus_Rule                   => x_asset_fin_rec_new.bonus_rule,
421           X_Ceiling_Name                 => x_asset_fin_rec_new.ceiling_name,
422           X_Recoverable_Cost             => x_asset_fin_rec_new.recoverable_cost,
423           X_Last_Update_Login            => px_trans_rec.who_info.last_update_login,
424           X_Adjusted_Capacity            => x_asset_fin_rec_new.adjusted_capacity,
425           X_Fully_Rsvd_Revals_Counter    => x_asset_fin_rec_new.fully_rsvd_revals_counter,
426           X_Idled_Flag                   => x_asset_fin_rec_new.idled_flag,
427           X_Period_Counter_Capitalized   => x_asset_fin_rec_new.period_counter_capitalized,
428           X_PC_Fully_Reserved            => x_asset_fin_rec_new.period_counter_fully_reserved,
429           X_Period_Counter_Fully_Retired => x_asset_fin_rec_new.period_counter_fully_retired,
430           X_Production_Capacity          => x_asset_fin_rec_new.production_capacity,
431           X_Reval_Amortization_Basis     => x_asset_fin_rec_new.reval_amortization_basis,
432           X_Reval_Ceiling                => x_asset_fin_rec_new.reval_ceiling,
433           X_Unit_Of_Measure              => x_asset_fin_rec_new.unit_of_measure,
434           X_Unrevalued_Cost              => x_asset_fin_rec_new.unrevalued_cost,
435           X_Annual_Deprn_Rounding_Flag   => x_asset_fin_rec_new.annual_deprn_rounding_flag,
436           X_Percent_Salvage_Value        => x_asset_fin_rec_new.percent_salvage_value,
437           X_Allowed_Deprn_Limit          => x_asset_fin_rec_new.allowed_deprn_limit,
438           X_Allowed_Deprn_Limit_Amount   => x_asset_fin_rec_new.allowed_deprn_limit_amount,
439           X_Period_Counter_Life_Complete => x_asset_fin_rec_new.period_counter_life_complete,
440           X_Adjusted_Recoverable_Cost    => x_asset_fin_rec_new.adjusted_recoverable_cost,
441           X_Short_Fiscal_Year_Flag       => x_asset_fin_rec_new.short_fiscal_year_flag,
442           X_Conversion_Date              => x_asset_fin_rec_new.conversion_date,
443           X_Orig_Deprn_Start_Date        => x_asset_fin_rec_new.orig_deprn_start_date,
444           X_Remaining_Life1              => x_asset_fin_rec_new.remaining_life1,
445           X_Remaining_Life2              => x_asset_fin_rec_new.remaining_life2,
446           X_Old_Adj_Cost                 => x_asset_fin_rec_new.old_adjusted_cost,
447           X_Formula_Factor               => x_asset_fin_rec_new.formula_factor,
448           X_gf_Attribute1                => x_asset_fin_rec_new.global_attribute1,
449           X_gf_Attribute2                => x_asset_fin_rec_new.global_attribute2,
450           X_gf_Attribute3                => x_asset_fin_rec_new.global_attribute3,
451           X_gf_Attribute4                => x_asset_fin_rec_new.global_attribute4,
452           X_gf_Attribute5                => x_asset_fin_rec_new.global_attribute5,
453           X_gf_Attribute6                => x_asset_fin_rec_new.global_attribute6,
454           X_gf_Attribute7                => x_asset_fin_rec_new.global_attribute7,
455           X_gf_Attribute8                => x_asset_fin_rec_new.global_attribute8,
456           X_gf_Attribute9                => x_asset_fin_rec_new.global_attribute9,
457           X_gf_Attribute10               => x_asset_fin_rec_new.global_attribute10,
458           X_gf_Attribute11               => x_asset_fin_rec_new.global_attribute11,
459           X_gf_Attribute12               => x_asset_fin_rec_new.global_attribute12,
460           X_gf_Attribute13               => x_asset_fin_rec_new.global_attribute13,
461           X_gf_Attribute14               => x_asset_fin_rec_new.global_attribute14,
462           X_gf_Attribute15               => x_asset_fin_rec_new.global_attribute15,
463           X_gf_Attribute16               => x_asset_fin_rec_new.global_attribute16,
464           X_gf_Attribute17               => x_asset_fin_rec_new.global_attribute17,
465           X_gf_Attribute18               => x_asset_fin_rec_new.global_attribute18,
466           X_gf_Attribute19               => x_asset_fin_rec_new.global_attribute19,
467           X_gf_Attribute20               => x_asset_fin_rec_new.global_attribute20,
468           X_global_attribute_category    => x_asset_fin_rec_new.global_attribute_category,
469           X_group_asset_id               => x_asset_fin_rec_new.group_asset_id,
470           X_salvage_type                 => x_asset_fin_rec_new.salvage_type,
471           X_deprn_limit_type             => x_asset_fin_rec_new.deprn_limit_type,
472           X_over_depreciate_option       => x_asset_fin_rec_new.over_depreciate_option,
473           X_super_group_id          => x_asset_fin_rec_new.super_group_id,
474           X_reduction_rate               => x_asset_fin_rec_new.reduction_rate,
475           X_reduce_addition_flag         => x_asset_fin_rec_new.reduce_addition_flag,
476           X_reduce_adjustment_flag       => x_asset_fin_rec_new.reduce_adjustment_flag,
477           X_reduce_retirement_flag       => x_asset_fin_rec_new.reduce_retirement_flag,
478           X_recognize_gain_loss          => x_asset_fin_rec_new.recognize_gain_loss,
479           X_recapture_reserve_flag       => x_asset_fin_rec_new.recapture_reserve_flag,
480           X_limit_proceeds_flag          => x_asset_fin_rec_new.limit_proceeds_flag,
481           X_terminal_gain_loss           => x_asset_fin_rec_new.terminal_gain_loss,
482           X_exclude_proceeds_from_basis  => x_asset_fin_rec_new.exclude_proceeds_from_basis,
483           X_retirement_deprn_option      => x_asset_fin_rec_new.retirement_deprn_option,
484           X_tracking_method              => x_asset_fin_rec_new.tracking_method,
485           X_allocate_to_fully_rsv_flag   => x_asset_fin_rec_new.allocate_to_fully_rsv_flag,
486           X_allocate_to_fully_ret_flag   => x_asset_fin_rec_new.allocate_to_fully_ret_flag,
487           X_exclude_fully_rsv_flag       => x_asset_fin_rec_new.exclude_fully_rsv_flag,
488           X_excess_allocation_option     => x_asset_fin_rec_new.excess_allocation_option,
489           X_depreciation_option          => x_asset_fin_rec_new.depreciation_option,
490           X_member_rollup_flag           => x_asset_fin_rec_new.member_rollup_flag,
491           X_ytd_proceeds                 => x_asset_fin_rec_new.ytd_proceeds,
492           X_ltd_proceeds                 => x_asset_fin_rec_new.ltd_proceeds,
493           X_eofy_reserve                 => x_asset_fin_rec_new.eofy_reserve,
494           X_cip_cost                     => x_asset_fin_rec_new.cip_cost,
495           X_terminal_gain_loss_amount    => x_asset_fin_rec_new.terminal_gain_loss_amount,
496           X_ltd_cost_of_removal          => x_asset_fin_rec_new.ltd_cost_of_removal,
497           X_contract_id                  => x_asset_fin_rec_new.contract_id, -- Bug:8240522
498           X_cash_generating_unit_id      => x_asset_fin_rec_new.cash_generating_unit_id,
499           X_extended_deprn_flag            => x_asset_fin_rec_new.extended_deprn_flag,          -- Japan Tax phase3
500           X_extended_depreciation_period   => x_asset_fin_rec_new.extended_depreciation_period, -- Japan Tax phase3
501           X_mrc_sob_type_code              => p_mrc_sob_type_code,
502           X_set_of_books_id                => px_asset_hdr_rec.set_of_books_id,
503           X_Return_Status                  => l_status,
504           X_Calling_Fn                     => l_calling_fn,
505           X_nbv_at_switch                  => x_asset_fin_rec_new.nbv_at_switch,
506           -- Changes made as per the ER No.s 6606548 and 6606552 by Vkukutam Start
507           X_prior_deprn_limit_type         => x_asset_fin_rec_new.prior_deprn_limit_type,
508           X_prior_deprn_limit_amount       => x_asset_fin_rec_new.prior_deprn_limit_amount,
509           X_prior_deprn_limit              => x_asset_fin_rec_new.prior_deprn_limit,
510           X_period_counter_fully_rsrved    => x_asset_fin_rec_new.period_counter_fully_reserved,
511           --X_extended_depreciation_period => x_asset_fin_rec_new.extended_depreciation_period ,
512           X_prior_deprn_method             => x_asset_fin_rec_new.prior_deprn_method,
513           X_prior_life_in_months           => x_asset_fin_rec_new.prior_life_in_months,
514           X_prior_basic_rate               => x_asset_fin_rec_new.prior_basic_rate,
515           X_prior_adjusted_rate            => x_asset_fin_rec_new.prior_adjusted_rate  -- Changes made as per the ER No.s 6606548 and 6606552 by Vkukutam End
516    , p_log_level_rec => p_log_level_rec);
517 
518 
519    if not l_status then
520       raise adj_err;
521    end if;
522 
523    -- Bug:5930979:Japan Tax Reform Project (Start)
524    if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES'
525    then
526       FA_CDE_PKG.faxgfr (X_Book_Type_Code         => px_asset_hdr_rec.book_type_code,
527                          X_Asset_Id               => px_asset_hdr_rec.asset_id,
528                          X_Short_Fiscal_Year_Flag => NULL,
529                          X_Conversion_Date        => NULL,
530                          X_Prorate_Date           => NULL,
531                          X_Orig_Deprn_Start_Date  => NULL,
532                          C_Prorate_Date           => NULL,
533                          C_Conversion_Date        => NULL,
534                          C_Orig_Deprn_Start_Date  => NULL,
535                          X_Method_Code            => fa_cache_pkg.fazccmt_record.method_code,
536                          X_Life_In_Months         => fa_cache_pkg.fazccmt_record.life_in_months,
537                          X_Fiscal_Year            => -99,
538                          X_Current_Period            => -99,
539                          X_calling_interface      => 'AFTER_ADJ',
540                          X_Rate                   => l_rate_in_use,
541                          X_Method_Type            => l_method_type,
542                          X_Success                => l_success, p_log_level_rec => p_log_level_rec);
543 
544       if (l_success <= 0) then
545          fa_srvr_msg.add_message(calling_fn => 'fa_addition_pvt.insert_asset',  p_log_level_rec => p_log_level_rec);
546          raise adj_err;
547       end if;
548 
549       BEGIN
550         SELECT FF.original_rate
551              , FF.revised_rate
552              , FF.guarantee_rate
553         INTO   l_original_Rate
554              , l_Revised_Rate
555              , l_Guaranteed_Rate
556         FROM   FA_FORMULAS FF
557              , FA_METHODS FM
558         WHERE  FF.METHOD_ID = FM.METHOD_ID
559         AND    FM.METHOD_CODE = x_asset_fin_rec_new.deprn_method_code;
560       EXCEPTION
561         WHEN OTHERS THEN
562              l_original_Rate := 0;
563              l_Revised_Rate := 0;
564              l_Guaranteed_Rate := 0;
565              l_is_revised_rate := 0;
566       END;
567 
568       -- bug 7668308:Added the trunc and ytd value to calculate correct
569       -- rate in use.
570       --
571       -- Fix for Bug #8226054.  Need to change original_cost to cost for
572       -- comparison.
573       --Bug 8639894 need to include deprn expense in deprn reserve also
574       -- in case some adjustment is done
575       IF x_asset_fin_rec_new.eofy_reserve = 0 then
576          l_comp_val := x_asset_deprn_rec_new.deprn_reserve - x_asset_deprn_rec_new.ytd_deprn;
577       ELSE
578          l_comp_val := x_asset_fin_rec_new.eofy_reserve;
579       END IF;
580 
581       IF (trunc(x_asset_fin_rec_new.cost * l_Guaranteed_Rate)) >
582          (trunc((x_asset_fin_rec_new.cost - l_comp_val)* l_original_Rate)) THEN
583          l_rate_in_use := l_Revised_Rate;
584       ELSE
585          l_rate_in_use := l_original_Rate;
586       END IF;
587       /*-------------------------------------------------------------------
588        * Bug 7555962
589        * Added the below if condition so that when user modifies the YTD/LTD
590        * in period of addition such that asset comes to original state from
591        * switched state the NBV_AT_SWITCH becomes null.
592        *-------------------------------------------------------------------*/
593       l_nbv_at_switch_var := 'Y';
594       if (l_rate_in_use <> l_Revised_Rate) THEN
595          l_nbv_at_switch_var := 'X';
596       end if;
597 
598       UPDATE FA_BOOKS
599          SET rate_in_use = l_rate_in_use
600              ,nbv_at_switch = Decode(l_nbv_at_switch_var,'X',NULL,nbv_at_switch)
601          WHERE book_type_code = px_asset_hdr_rec.book_type_code
602          AND asset_id = px_asset_hdr_rec.asset_id
603          AND date_ineffective is null;
604 
605    end if;
606    -- Bug:5930979:Japan Tax Reform Project (End)
607 
608    -- update TH/BKS/DS/DD for adjustments in period of addition (i.e. voids)
609 
610    -- Bug7017134: Added condition not to touch B(OOKS) row if group adjustment is pending
611 
612    -- R12 conditional logic
613    -- SLA Uptake
614    -- this section is altered to account for new period of addition
615    -- changes.
616    --
617    -- 1) Since the prior unplanned solution is obsolete, no need to
618    --    track or store deprn_adj_amount
619    -- 2) we will only be tracking updates to YTD in the info for
620    --    DS/DD, reserve remains untouched
621 
622    if (px_asset_hdr_rec.period_of_addition = 'Y') and
623       (l_cgu_change_flag = 'N') and
624       ((p_asset_type_rec.asset_type <> 'GROUP') or
625        (p_asset_type_rec.asset_type = 'GROUP' and
626         (nvl(x_asset_fin_rec_new.member_rollup_flag,'N') <> 'Y' and
627          (not(px_trans_rec.calling_interface = 'FAXASSET' and
628           x_asset_fin_rec_new.adjustment_required_status = 'GADJ'))
629                                                   ))
630                                                       ) then
631 
632       if (p_log_level_rec.statement_level) then
633         fa_debug_pkg.add('pvt adj api', 'logic for update deprn detail/summary', 'Starts', p_log_level_rec => p_log_level_rec);
634       end if;
635 
636       -- we need to account for unplanned in the period of addition
637       --
638       -- also for amort nbv scenarios where we don't want to
639       -- include the catchup in the reserve amount
640 
641       if (nvl(px_trans_rec.transaction_key, 'XX') not in ('UA', 'UE')) then
642 
643       if (p_mrc_sob_type_code <> 'R') then
644          select nvl(sum(deprn_adjustment_amount), 0)
645            into l_deprn_adjustment_amount
646            from fa_deprn_detail
647           where book_type_code = px_asset_hdr_rec.book_type_code
648             and asset_id       = px_asset_hdr_rec.asset_id
649             and deprn_source_code = 'B';
650 
651          select nvl(sum(decode(debit_credit_flag,
652                                'DR', adjustment_amount,
653                                -adjustment_amount)), 0)
654            into l_deprn_exp_amort_nbv
655            from fa_adjustments
656           where book_type_code = px_asset_hdr_rec.book_type_code
657             and asset_id       = px_asset_hdr_rec.asset_id
658             and adjustment_type  = 'EXPENSE';
659 
660          select nvl(sum(decode(debit_credit_flag,
661                                'CR', adjustment_amount,
662                                -adjustment_amount)), 0)
663            into l_reserve_adjustment_amount
664            from fa_adjustments
665           where book_type_code = px_asset_hdr_rec.book_type_code
666             and asset_id       = px_asset_hdr_rec.asset_id
667             and adjustment_type  = 'RESERVE';
668 
669          -- Bug 8533933
670          select nvl(sum(decode(debit_credit_flag,
671                                'DR', adjustment_amount,
672                                -adjustment_amount)), 0)
673            into l_bonus_deprn_exp_adj
674            from fa_adjustments
675           where book_type_code = px_asset_hdr_rec.book_type_code
676             and asset_id       = px_asset_hdr_rec.asset_id
677             and adjustment_type  = 'BONUS EXPENSE';
678 
679          select nvl(sum(decode(debit_credit_flag,
680                                'CR', adjustment_amount,
681                                -adjustment_amount)), 0)
682            into l_bonus_reserve_adj
683            from fa_adjustments
684           where book_type_code = px_asset_hdr_rec.book_type_code
685             and asset_id       = px_asset_hdr_rec.asset_id
686             and adjustment_type  = 'BONUS RESERVE';
687 	 -- End Bug 8533933
688 
689          select nvl(sum(decode(debit_credit_flag,
690                                'CR', adjustment_amount,
691                                -adjustment_amount)), 0)
692            into l_mvmt_deprn_reval_reserve
693            from fa_adjustments
694           where book_type_code = px_asset_hdr_rec.book_type_code
695             and asset_id       = px_asset_hdr_rec.asset_id
696             and adjustment_type  = 'REVAL RESERVE';
697 
698       else
699          select nvl(sum(deprn_adjustment_amount), 0)
700            into l_deprn_adjustment_amount
701            from fa_mc_deprn_detail
702           where book_type_code = px_asset_hdr_rec.book_type_code
703             and asset_id       = px_asset_hdr_rec.asset_id
704             and deprn_source_code = 'B'
705             and set_of_books_id = px_asset_hdr_rec.set_of_books_id;
706 
707          select nvl(sum(decode(debit_credit_flag,
708                                'DR', adjustment_amount,
709                                -adjustment_amount)), 0)
710            into l_deprn_exp_amort_nbv
711            from fa_mc_adjustments
712           where book_type_code = px_asset_hdr_rec.book_type_code
713             and asset_id       = px_asset_hdr_rec.asset_id
714             and adjustment_type  = 'EXPENSE'
715             and set_of_books_id = px_asset_hdr_rec.set_of_books_id;
716 
717          select nvl(sum(decode(debit_credit_flag,
718                                'CR', adjustment_amount,
719                                -adjustment_amount)), 0)
720            into l_reserve_adjustment_amount
721            from fa_mc_adjustments
722           where book_type_code = px_asset_hdr_rec.book_type_code
723             and asset_id       = px_asset_hdr_rec.asset_id
724             and adjustment_type  = 'RESERVE'
725             and set_of_books_id = px_asset_hdr_rec.set_of_books_id;
726 
727          -- Bug 8533933
728          select nvl(sum(decode(debit_credit_flag,
729                                'DR', adjustment_amount,
730                                -adjustment_amount)), 0)
731            into l_bonus_deprn_exp_adj
732            from fa_mc_adjustments
733           where book_type_code = px_asset_hdr_rec.book_type_code
734             and asset_id       = px_asset_hdr_rec.asset_id
735             and adjustment_type  = 'BONUS EXPENSE'
736 	    and set_of_books_id = px_asset_hdr_rec.set_of_books_id;
737 
738          select nvl(sum(decode(debit_credit_flag,
739                                'CR', adjustment_amount,
740                                -adjustment_amount)), 0)
741            into l_bonus_reserve_adj
742            from fa_mc_adjustments
743           where book_type_code = px_asset_hdr_rec.book_type_code
744             and asset_id       = px_asset_hdr_rec.asset_id
745             and adjustment_type  = 'BONUS RESERVE'
746             and set_of_books_id = px_asset_hdr_rec.set_of_books_id;
747 	 -- End Bug 8533933
748 
749          select nvl(sum(decode(debit_credit_flag,
750                                'CR', adjustment_amount,
751                                -adjustment_amount)), 0)
752            into l_mvmt_deprn_reval_reserve
753            from fa_mc_adjustments
754           where book_type_code = px_asset_hdr_rec.book_type_code
755             and asset_id       = px_asset_hdr_rec.asset_id
756             and adjustment_type  = 'REVAL RESERVE';
757 
758       end if;
759 
760       end if; -- unplanne
761 
762       if (p_log_level_rec.statement_level) then
763         fa_debug_pkg.add('pvt adj api', 'l_deprn_adjustment_amount', l_deprn_adjustment_amount, p_log_level_rec => p_log_level_rec);
764         fa_debug_pkg.add('pvt adj api', 'x_asset_deprn_rec_new.deprn_reserve', x_asset_deprn_rec_new.deprn_reserve, p_log_level_rec => p_log_level_rec);
765         fa_debug_pkg.add('pvt adj api', 'l_deprn_exp_amort_nbv', l_deprn_exp_amort_nbv, p_log_level_rec => p_log_level_rec);
766         fa_debug_pkg.add('pvt adj api', 'l_reserve_adjustment_amount', l_reserve_adjustment_amount, p_log_level_rec => p_log_level_rec);
767 	fa_debug_pkg.add('pvt adj api', 'l_bonus_deprn_exp_adj', l_bonus_deprn_exp_adj, p_log_level_rec => p_log_level_rec);  -- Bug 8533933
768 	fa_debug_pkg.add('pvt adj api', 'l_bonus_reserve_adj', l_bonus_reserve_adj, p_log_level_rec => p_log_level_rec);      -- Bug 8533933
769         fa_debug_pkg.add('pvt adj api', 'reval amo', x_asset_deprn_rec_new.reval_amortization, p_log_level_rec => p_log_level_rec);
770  	fa_debug_pkg.add('pvt adj api', 'reval amo basis ',x_asset_deprn_rec_new.reval_amortization_basis, p_log_level_rec => p_log_level_rec);
771  	fa_debug_pkg.add('pvt adj api', 'reval dep expense',x_asset_deprn_rec_new.reval_deprn_expense, p_log_level_rec => p_log_level_rec);
772  	fa_debug_pkg.add('pvt adj api', 'reval dep rsve ',x_asset_deprn_rec_new.reval_deprn_reserve, p_log_level_rec => p_log_level_rec);
773       end if;
774 
775       --bug fix 5672546
776       if p_group_reclass_options_rec.group_reclass_type = 'MANUAL' then
777         /*Bug#7715051 -- Backported following logic from R12 and commented code for bug Bug7017134
778                       -- Incase of group-group reclass for member asset having backdated dpis
779                       -- When manual reserve transfer is done the reserve row in fa_adj is inserted from
780                       -- FAVGRECB.pls after update in deprn summary because of which reserve amount
781                       -- is not considered when calculating l_reserve_adjustment_amount in above select statement
782                       -- causing wrong value of reserve to be updated in 'BOOKS' row of deprn summary and detail.*/
783 
784         if p_asset_type_rec.asset_type = 'GROUP' then
785             if p_reclass_src_dest = 'SOURCE' then
786                l_reserve_adjustment_amount := l_reserve_adjustment_amount -
787                                                  nvl(p_group_reclass_options_rec.reserve_amount,0) ;
788             elsif p_reclass_src_dest = 'DESTINATION' then
789                l_reserve_adjustment_amount := l_reserve_adjustment_amount +
790                                                  nvl(p_group_reclass_options_rec.reserve_amount,0) ;
791             end if;
792          end if;
793       --Bug#7715051 - end
794 
795       elsif p_group_reclass_options_rec.group_reclass_type = 'CALC'  and
796             p_asset_type_rec.asset_type = 'GROUP' and
797             px_trans_rec.calling_interface <> 'FAXASSET' then
798 
799          if p_reclass_src_dest = 'SOURCE' then
800             l_reserve_adjustment_amount := l_reserve_adjustment_amount - nvl(p_group_reclass_options_rec.reserve_amount,0);
801          end if;
802 
803       end if;
804 
805 
806 
807       l_open_deprn_reval_reserve := NVL(x_asset_deprn_rec_new.reval_deprn_reserve,0) - l_mvmt_deprn_reval_reserve;
808       if (p_log_level_rec.statement_level) THEN
809  	    fa_debug_pkg.ADD('pvt adj api', 'reval dep rsve (mvt) ',l_mvmt_deprn_reval_reserve, p_log_level_rec => p_log_level_rec);
810  	    fa_debug_pkg.add('pvt adj api', 'reval dep rsve (opbal) ',l_open_deprn_reval_reserve, p_log_level_rec => p_log_level_rec);
811       end if;
812       FA_DEPRN_SUMMARY_PKG.Update_Row
813                       (X_Book_Type_Code                 => px_asset_hdr_rec.book_type_code,
814                        X_Asset_Id                       => px_asset_hdr_rec.asset_id,
815                        X_Deprn_Run_Date                 => px_trans_rec.who_info.last_update_date,
816                        X_Deprn_Amount                   => x_asset_deprn_rec_new.deprn_amount,
817                        X_Ytd_Deprn                      => x_asset_deprn_rec_new.ytd_deprn -
818                                                            l_deprn_exp_amort_nbv,
819                        X_Deprn_Reserve                  => x_asset_deprn_rec_new.deprn_reserve -
820                                                            l_deprn_exp_amort_nbv -
821                                                            l_reserve_adjustment_amount,
822                        X_Deprn_Source_Code              => 'BOOKS',
823                        X_Adjusted_Cost                  => x_asset_fin_rec_new.adjusted_cost,
824                        X_Bonus_Rate                     => NULL,
825                        X_Ltd_Production                 => NULL,
826                        X_Period_Counter                 => p_period_rec.period_counter - 1,
827                        X_Production                     => NULL,
828                        X_Reval_Amortization             => x_asset_deprn_rec_new.reval_amortization,
829                        X_Reval_Amortization_Basis       => x_asset_deprn_rec_new.reval_amortization_basis,
830                        X_Reval_Deprn_Expense            => x_asset_deprn_rec_new.reval_deprn_expense,
831                        X_Reval_Reserve                  => l_open_deprn_reval_reserve,
832                        X_Ytd_Production                 => NULL,
833                        X_Ytd_Reval_Deprn_Expense        => x_asset_deprn_rec_new.reval_ytd_deprn,
834                        X_Bonus_Deprn_Amount             => x_asset_deprn_rec_new.bonus_deprn_amount,
835                        X_Bonus_Ytd_Deprn                => x_asset_deprn_rec_new.bonus_ytd_deprn -
836 		                                           l_bonus_deprn_exp_adj,                      -- Bug 8533933
837                        X_Bonus_Deprn_Reserve            => x_asset_deprn_rec_new.bonus_deprn_reserve -
838 		                                           l_bonus_deprn_exp_adj -                     -- Bug 8533933
839 							   l_bonus_reserve_adj,                        -- Bug 8533933
840                        X_Impairment_Amount              => x_asset_deprn_rec_new.impairment_amount,
841                        X_Ytd_Impairment                 => x_asset_deprn_rec_new.ytd_impairment,
842                        X_impairment_reserve                 => x_asset_deprn_rec_new.impairment_reserve,
843                        X_mrc_sob_type_code              => p_mrc_sob_type_code,
844                        X_set_of_books_id                => px_asset_hdr_rec.set_of_books_id,
845                        X_Calling_Fn                     => l_calling_fn
846                       , p_log_level_rec => p_log_level_rec);
847 
848        if not FA_INS_DETAIL_PKG.FAXINDD
849                      (X_book_type_code           => px_asset_hdr_rec.book_type_code,
850                       X_asset_id                 => px_asset_hdr_rec.asset_id,
851                       X_deprn_adjustment_amount  => l_deprn_adjustment_amount,
852                       X_mrc_sob_type_code        => p_mrc_sob_type_code,
853                       X_set_of_books_id    => px_asset_hdr_rec.set_of_books_id
854                      , p_log_level_rec => p_log_level_rec) then raise adj_err;
855        end if;
856 
857      -- now perform amortize nbv if applicable
858 
859      if (px_trans_rec.transaction_subtype = 'AMORTIZED' and
860          p_asset_type_rec.asset_type = 'CAPITALIZED' and
861          l_cgu_change_flag = 'N' and
862          x_asset_fin_rec_new.group_asset_id is null and
863          G_release = 11)  then
864 
865         -- excluding group as calc engine should handle all trxs
866         -- (p_asset_type_rec.asset_type = 'GROUP')) and
867         -- (p_calling_fn = 'fa_adjustment_pub.do_all_books') then
868 
869          -- amortization start date was previously validated from calc engine
870 
871          -- Bug3548724
872          -- It is important to pass reserve only amount in deprn_rec_adj for faxama.
873          --
874          l_asset_deprn_rec_adj.ytd_deprn           := x_asset_deprn_rec_new.ytd_deprn -
875                                                       p_asset_deprn_rec_old.deprn_amount;
876          l_asset_deprn_rec_adj.deprn_reserve       := x_asset_deprn_rec_new.deprn_reserve -
877                                                       p_asset_deprn_rec_old.deprn_amount;
878          l_asset_deprn_rec_adj.bonus_ytd_deprn     := x_asset_deprn_rec_new.bonus_ytd_deprn -
879                                                       p_asset_deprn_rec_old.bonus_deprn_amount;
880          l_asset_deprn_rec_adj.bonus_deprn_reserve := x_asset_deprn_rec_new.bonus_deprn_reserve -
881                                                       p_asset_deprn_rec_old.bonus_deprn_amount;
882          l_asset_deprn_rec_adj.ytd_impairment      := nvl(x_asset_deprn_rec_new.ytd_impairment,0) -
883                                                       nvl(p_asset_deprn_rec_old.impairment_amount,0);
884          l_asset_deprn_rec_adj.impairment_reserve      := nvl(x_asset_deprn_rec_new.impairment_reserve,0) -
885                                                       nvl(p_asset_deprn_rec_old.impairment_amount,0);
886 
887 
888          if not FA_AMORT_PVT.faxama
889                   (px_trans_rec          => px_trans_rec,
890                    p_asset_hdr_rec       => px_asset_hdr_rec,
891                    p_asset_desc_rec      => p_asset_desc_rec,
892                    p_asset_cat_rec       => p_asset_cat_rec,
893                    p_asset_type_rec      => p_asset_type_rec,
894                    p_asset_fin_rec_old   => x_asset_fin_rec_new,
895                    p_asset_fin_rec_adj   => l_asset_fin_rec_null,
896                    px_asset_fin_rec_new  => x_asset_fin_rec_new,
897                    p_asset_deprn_rec     => x_asset_deprn_rec_new,
898                    p_asset_deprn_rec_adj => l_asset_deprn_rec_adj,    --bug3548724
899                    p_period_rec          => p_period_rec,
900                    p_mrc_sob_type_code   => p_mrc_sob_type_code,
901                    p_running_mode        => fa_std_types.FA_DPR_NORMAL,
902                    p_used_by_revaluation => null,
903                    x_deprn_exp           => l_deprn_exp,
904                    x_bonus_deprn_exp     => l_bonus_deprn_exp,
905                    x_impairment_exp      => l_impairment_exp
906                   , p_log_level_rec => p_log_level_rec) then raise adj_err;
907          end if;
908 
909 
910          -- insert the deprn amounts
911          if not FA_INS_ADJ_PVT.faxiat
912                      (p_trans_rec       => px_trans_rec,
913                       p_asset_hdr_rec   => px_asset_hdr_rec,
914                       p_asset_desc_rec  => p_asset_desc_rec,
915                       p_asset_cat_rec   => p_asset_cat_rec,
916                       p_asset_type_rec  => p_asset_type_rec,
917                       p_cost            => 0,
918                       p_clearing        => 0,
919                       p_deprn_expense   => l_deprn_exp,
920                       p_bonus_expense   => l_bonus_deprn_exp,
921                       p_impair_expense  => l_impairment_exp,
922                       p_ann_adj_amt     => 0,
923                       p_mrc_sob_type_code => p_mrc_sob_type_code,
924                       p_calling_fn      => l_calling_fn
925                      , p_log_level_rec => p_log_level_rec) then raise adj_err;
926          end if;
927 
928          fa_books_pkg.update_row
929             (X_asset_id                  => px_asset_hdr_rec.asset_id,
930              X_book_type_code            => px_asset_hdr_rec.book_type_code,
931              X_rate_adjustment_factor    => x_asset_fin_rec_new.rate_adjustment_factor,
932              X_reval_amortization_basis  => x_asset_fin_rec_new.reval_amortization_basis,
933              X_adjusted_cost             => x_asset_fin_rec_new.adjusted_cost,
934              X_adjusted_capacity         => x_asset_fin_rec_new.adjusted_capacity,
935              X_formula_factor            => x_asset_fin_rec_new.formula_factor,
936              X_eofy_reserve              => x_asset_fin_rec_new.eofy_reserve,
937              X_mrc_sob_type_code         => p_mrc_sob_type_code,
938              X_set_of_books_id           => px_asset_hdr_rec.set_of_books_id,
939              X_calling_fn                => l_calling_fn, p_log_level_rec => p_log_level_rec);
940 
941 
942          -- now update the primary or reporting amounts accordingly
943          if (p_mrc_sob_type_code <> 'R') then
944 
945             delete from fa_adjustments
946              where asset_id        = px_asset_hdr_rec.asset_id
947                and book_type_code  = px_asset_hdr_rec.book_type_code
948                and adjustment_type in ('COST', 'COST CLEARING');
949 
950          else
951 
952             delete from fa_mc_adjustments
953              where asset_id        = px_asset_hdr_rec.asset_id
954                and book_type_code  = px_asset_hdr_rec.book_type_code
955                and adjustment_type in ('COST', 'COST CLEARING')
956                and set_of_books_id = px_asset_hdr_rec.set_of_books_id;
957 
958          end if;
959 
960 
961          FA_DEPRN_SUMMARY_PKG.Update_Row
962                       (X_Book_Type_Code                 => px_asset_hdr_rec.book_type_code,
963                        X_Asset_Id                       => px_asset_hdr_rec.asset_id,
964                        X_Adjusted_Cost                  => x_asset_fin_rec_new.adjusted_cost,
965                        X_Period_Counter                 => p_period_rec.period_counter - 1,
966                        X_Reval_Amortization_Basis       => x_asset_deprn_rec_new.reval_amortization_basis,
967                        X_mrc_sob_type_code              => p_mrc_sob_type_code,
968                        X_set_of_books_id                => px_asset_hdr_rec.set_of_books_id,
969                        X_Calling_Fn                     => l_calling_fn
970                       , p_log_level_rec => p_log_level_rec);
971 
972 
973       end if;   -- end amort nbv
974 
975        -- If the processed asset is GROUP asset and tracking method is 'ALLOCATE',
976        -- Call TRACK_ASSETS to allocate unplanned amount into members.
977        -- For track member feature
978        -- Only when the unplanned depreciation is kicked from group asset whose tracking method is
979        -- ALLOCATE, system needs to allocate the entered unplanned depreciation amount into
980        -- members.
981        if x_asset_fin_rec_new.group_asset_id is null and
982           nvl(x_asset_fin_rec_new.tracking_method,'OTHER') = 'ALLOCATE' and
983           (x_asset_deprn_rec_new.deprn_reserve - l_deprn_exp_amort_nbv - l_reserve_adjustment_amount) <> 0 then
984 
985          if not fa_cache_pkg.fazccmt (x_asset_fin_rec_new.deprn_method_code,x_asset_fin_rec_new.life_in_months,p_log_level_rec => p_log_level_rec) then
986            fa_srvr_msg.add_message (calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
987            raise adj_err;
988          end if;
989 
990          l_ret_code := FA_TRACK_MEMBER_PVT.TRACK_ASSETS
991                            (P_book_type_code             => px_asset_hdr_rec.book_type_code,
992                             P_group_asset_id             => px_asset_hdr_rec.asset_id,
993                             P_period_counter             => p_period_rec.period_num,
994                             P_fiscal_year                => p_period_rec.fiscal_year,
995                             P_group_deprn_basis          => fa_cache_pkg.fazccmt_record.deprn_basis_rule,
996                             P_group_exclude_salvage      => fa_cache_pkg.fazccmt_record.exclude_salvage_value_flag,
997                             P_group_bonus_rule           => x_asset_fin_rec_new.bonus_rule,
998                             P_group_deprn_amount         => x_asset_deprn_rec_new.deprn_reserve -
999                                                            l_deprn_exp_amort_nbv -
1000                                                            l_reserve_adjustment_amount,
1001                             P_group_bonus_amount         => 0,
1002                             P_tracking_method            => x_asset_fin_rec_new.tracking_method,
1003                             P_allocate_to_fully_ret_flag => x_asset_fin_rec_new.allocate_to_fully_ret_flag,
1004                             P_allocate_to_fully_rsv_flag => x_asset_fin_rec_new.allocate_to_fully_rsv_flag,
1005                             P_excess_allocation_option   => x_asset_fin_rec_new.excess_allocation_option,
1006                             P_subtraction_flag           => 'N',
1007                             P_group_level_override       => l_group_level_override,
1008                             P_period_of_addition         => 'Y',
1009                             P_transaction_date_entered   => px_trans_rec.transaction_date_entered,
1010                             P_mode                       => 'UNPLANNED',
1011                             P_mrc_sob_type_code          => p_mrc_sob_type_code,
1012                             P_set_of_books_id            => px_asset_hdr_rec.set_of_books_id,
1013                             X_new_deprn_amount           => x_group_deprn_amount,
1014                             X_new_bonus_amount           => x_group_bonus_amount,  p_log_level_rec => p_log_level_rec);
1015 
1016          if l_ret_code <> 0 then
1017             raise adj_err;
1018          elsif x_group_deprn_amount <> (x_asset_deprn_rec_new.deprn_reserve
1019                                        - l_deprn_exp_amort_nbv - l_reserve_adjustment_amount) then
1020             raise adj_err;
1021          end if;
1022 
1023        end if; -- End of Group Unplanned at period of addition
1024 
1025    end if;  --  end period of add
1026 
1027    return true;
1028 
1029 EXCEPTION
1030 
1031    when adj_err then
1032       fa_srvr_msg.add_message(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1033       return false;
1034 
1035    when others then
1036       fa_srvr_msg.add_sql_error
1037           (calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1038       return false;
1039 
1040 END do_adjustment;
1041 
1042 
1043 
1044 -- this function contains check_changes_before_commit logic (from faxfa1b.pls)
1045 -- insure something is changing and that the depreciate flag is not
1046 -- changing in conjuction with something else.
1047 --
1048 -- note: main change check excludes global flex and calculated values
1049 -- may need to add the global and capitalize values later
1050 -- as in the calc engine need to determine intent for nullable fields
1051 --
1052 -- now called from the public api to avoid errors resulting from
1053 -- calls from group/reclass apis that may result in no change
1054 
1055 FUNCTION validate_adjustment
1056    (p_inv_trans_rec           IN     FA_API_TYPES.inv_trans_rec_type,
1057     p_trans_rec               IN     FA_API_TYPES.trans_rec_type,
1058     p_asset_type_rec          IN     FA_API_TYPES.asset_type_rec_type,
1059     p_asset_fin_rec_old       IN     FA_API_TYPES.asset_fin_rec_type,
1060     p_asset_fin_rec_adj       IN     FA_API_TYPES.asset_fin_rec_type,
1061     p_asset_deprn_rec_old     IN     FA_API_TYPES.asset_deprn_rec_type,
1062     p_asset_deprn_rec_adj     IN     FA_API_TYPES.asset_deprn_rec_type,
1063     p_asset_hdr_rec           IN     FA_API_TYPES.asset_hdr_rec_type,
1064     p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1065 
1066     h_asset_id                 number;
1067 
1068     CURSOR c_group_mem_no_depreciate is
1069     select 1 from dual
1070     where exists
1071     (select 'x' from fa_books
1072     where book_type_code = p_asset_hdr_rec.book_type_code
1073     and   group_asset_id = h_asset_id
1074     and   transaction_header_id_out is null
1075     and   depreciate_flag = 'NO');
1076     l_dummy_num number;
1077 
1078    l_no_changes_made          boolean;
1079    l_no_changes_to_uom        boolean;
1080    l_no_changes_to_dep_flag   boolean;
1081    l_no_changes_to_method     boolean;
1082    l_no_changes_to_group      boolean;
1083    l_no_changes_to_reduction  boolean;
1084    l_no_changes_to_impairment boolean;
1085    l_no_changes_adjusted_cost boolean; /*bug#16426081 */
1086    l_calling_fn               varchar2(35)  := 'do_adjustment_pvt.validate_adj';
1087 
1088 BEGIN
1089 
1090 if (nvl(p_trans_rec.transaction_key, 'NULL') <> 'SG') then
1091    -- no need to check for changes made if driven by invoice
1092    if p_inv_trans_rec.transaction_type is not null then
1093       l_no_changes_made := FALSE;
1094    elsif
1095       (nvl(p_asset_fin_rec_adj.cost, 0)                  = 0 and
1096        nvl(p_asset_fin_rec_adj.original_cost, 0)         = 0 and
1097        nvl(p_asset_deprn_rec_adj.deprn_reserve, 0)       = 0 and
1098        nvl(p_asset_deprn_rec_adj.ytd_deprn, 0)           = 0 and
1099        --Test code for 9371739
1100        NOT (NVL(p_asset_deprn_rec_adj.allow_taxup_flag,FALSE)) AND
1101        --End of test code for 9371739
1102        nvl(p_asset_deprn_rec_adj.bonus_deprn_reserve, 0) = 0 and
1103        nvl(p_asset_deprn_rec_adj.bonus_ytd_deprn, 0)     = 0 and
1104        nvl(p_asset_deprn_rec_adj.impairment_reserve, 0)      = 0 and
1105        nvl(p_asset_deprn_rec_adj.ytd_impairment, 0)      = 0 and
1106        nvl(p_asset_deprn_rec_adj.reval_deprn_reserve, 0) = 0 and
1107        nvl(p_asset_fin_rec_adj.reval_ceiling, 0)         = 0 and
1108        nvl(p_asset_fin_rec_adj.production_capacity, 0)   = 0 and
1109        nvl(p_asset_fin_rec_adj.cip_cost, 0)              = 0 and
1110        nvl(p_asset_fin_rec_adj.percent_salvage_value, 0) = 0 and
1111        nvl(p_asset_fin_rec_adj.allowed_deprn_limit,0)    = 0 and
1112        nvl(p_asset_fin_rec_adj.allowed_deprn_limit_amount, 0) = 0 and
1113        p_asset_fin_rec_old.date_placed_in_service =
1114           nvl(p_asset_fin_rec_adj.date_placed_in_service,
1115               p_asset_fin_rec_old.date_placed_in_service) and
1116        p_asset_fin_rec_old.prorate_convention_code =
1117           nvl(p_asset_fin_rec_adj.prorate_convention_code,
1118               p_asset_fin_rec_old.prorate_convention_code) and
1119        nvl(p_asset_fin_rec_old.salvage_value, 0) =
1120           nvl(p_asset_fin_rec_adj.salvage_value,0) +
1121               nvl(p_asset_fin_rec_old.salvage_value, 0) and
1122        nvl(p_asset_fin_rec_old.itc_amount_id, FND_API.G_MISS_NUM) =
1123           nvl(p_asset_fin_rec_adj.itc_amount_id,
1124               nvl(p_asset_fin_rec_old.itc_amount_id, FND_API.G_MISS_NUM)) and
1125        nvl(p_asset_fin_rec_old.ceiling_name, FND_API.G_MISS_CHAR) =
1126           nvl(p_asset_fin_rec_adj.ceiling_name,
1127               nvl(p_asset_fin_rec_old.ceiling_name, FND_API.G_MISS_CHAR)) and
1128        nvl(p_asset_fin_rec_old.short_fiscal_year_flag, FND_API.G_MISS_CHAR) =
1129           nvl(p_asset_fin_rec_adj.short_fiscal_year_flag,
1130               nvl(p_asset_fin_rec_old.short_fiscal_year_flag, FND_API.G_MISS_CHAR)) and
1131 
1132        -- Bug:8240522
1133        nvl(p_asset_fin_rec_old.contract_id, FND_API.G_MISS_NUM) =
1134           nvl(p_asset_fin_rec_adj.contract_id,
1135               nvl(p_asset_fin_rec_old.contract_id, FND_API.G_MISS_NUM)) and
1136 
1137        -- group columns
1138        nvl(p_asset_fin_rec_old.salvage_type, FND_API.G_MISS_CHAR) =
1139           nvl(p_asset_fin_rec_adj.salvage_type,
1140               nvl(p_asset_fin_rec_old.salvage_type, FND_API.G_MISS_CHAR)) and
1141        nvl(p_asset_fin_rec_old.deprn_limit_type, FND_API.G_MISS_CHAR) =
1142           nvl(p_asset_fin_rec_adj.deprn_limit_type,
1143               nvl(p_asset_fin_rec_old.deprn_limit_type, FND_API.G_MISS_CHAR)) and
1144 
1145        nvl(p_asset_fin_rec_old.over_depreciate_option,FND_API.G_MISS_CHAR) =
1146           nvl(p_asset_fin_rec_adj.over_depreciate_option,
1147               nvl(p_asset_fin_rec_old.over_depreciate_option, FND_API.G_MISS_CHAR)) and
1148        nvl(p_asset_fin_rec_old.super_group_id, FND_API.G_MISS_NUM) =
1149           nvl(p_asset_fin_rec_adj.super_group_id,
1150               nvl(p_asset_fin_rec_old.super_group_id, FND_API.G_MISS_NUM)) and
1151 
1152        -- Japan Tax phase3
1153        nvl(p_asset_fin_rec_old.extended_deprn_flag, FND_API.G_MISS_CHAR) =
1154           nvl(p_asset_fin_rec_adj.extended_deprn_flag,
1155               nvl(p_asset_fin_rec_old.extended_deprn_flag, FND_API.G_MISS_CHAR)) and
1156        nvl(p_asset_fin_rec_old.extended_depreciation_period, FND_API.G_MISS_NUM) =
1157           nvl(p_asset_fin_rec_adj.extended_depreciation_period,
1158               nvl(p_asset_fin_rec_old.extended_depreciation_period, FND_API.G_MISS_NUM)) and
1159 
1160        -- global flex columns
1161        nvl(p_asset_fin_rec_old.global_attribute1, FND_API.G_MISS_CHAR) =
1162           nvl(p_asset_fin_rec_adj.global_attribute1,
1163               nvl(p_asset_fin_rec_old.global_attribute1, FND_API.G_MISS_CHAR)) and
1164        nvl(p_asset_fin_rec_old.global_attribute2, FND_API.G_MISS_CHAR) =
1165           nvl(p_asset_fin_rec_adj.global_attribute2,
1166               nvl(p_asset_fin_rec_old.global_attribute2, FND_API.G_MISS_CHAR)) and
1167        nvl(p_asset_fin_rec_old.global_attribute3, FND_API.G_MISS_CHAR) =
1168           nvl(p_asset_fin_rec_adj.global_attribute3,
1169               nvl(p_asset_fin_rec_old.global_attribute3, FND_API.G_MISS_CHAR)) and
1170        nvl(p_asset_fin_rec_old.global_attribute4, FND_API.G_MISS_CHAR) =
1171           nvl(p_asset_fin_rec_adj.global_attribute4,
1172               nvl(p_asset_fin_rec_old.global_attribute4, FND_API.G_MISS_CHAR)) and
1173        nvl(p_asset_fin_rec_old.global_attribute5, FND_API.G_MISS_CHAR) =
1174           nvl(p_asset_fin_rec_adj.global_attribute5,
1175               nvl(p_asset_fin_rec_old.global_attribute5, FND_API.G_MISS_CHAR)) and
1176        nvl(p_asset_fin_rec_old.global_attribute6, FND_API.G_MISS_CHAR) =
1177           nvl(p_asset_fin_rec_adj.global_attribute6,
1178               nvl(p_asset_fin_rec_old.global_attribute6, FND_API.G_MISS_CHAR)) and
1179        nvl(p_asset_fin_rec_old.global_attribute7, FND_API.G_MISS_CHAR) =
1180           nvl(p_asset_fin_rec_adj.global_attribute7,
1181               nvl(p_asset_fin_rec_old.global_attribute7, FND_API.G_MISS_CHAR)) and
1182        nvl(p_asset_fin_rec_old.global_attribute8, FND_API.G_MISS_CHAR) =
1183           nvl(p_asset_fin_rec_adj.global_attribute8,
1184               nvl(p_asset_fin_rec_old.global_attribute8, FND_API.G_MISS_CHAR)) and
1185        nvl(p_asset_fin_rec_old.global_attribute9, FND_API.G_MISS_CHAR) =
1186           nvl(p_asset_fin_rec_adj.global_attribute9,
1187               nvl(p_asset_fin_rec_old.global_attribute9, FND_API.G_MISS_CHAR)) and
1188        nvl(p_asset_fin_rec_old.global_attribute10, FND_API.G_MISS_CHAR) =
1189           nvl(p_asset_fin_rec_adj.global_attribute10,
1190               nvl(p_asset_fin_rec_old.global_attribute10, FND_API.G_MISS_CHAR)) and
1191        nvl(p_asset_fin_rec_old.global_attribute11, FND_API.G_MISS_CHAR) =
1192           nvl(p_asset_fin_rec_adj.global_attribute11,
1193               nvl(p_asset_fin_rec_old.global_attribute11, FND_API.G_MISS_CHAR)) and
1194        nvl(p_asset_fin_rec_old.global_attribute12, FND_API.G_MISS_CHAR) =
1195           nvl(p_asset_fin_rec_adj.global_attribute12,
1196               nvl(p_asset_fin_rec_old.global_attribute12, FND_API.G_MISS_CHAR)) and
1197        nvl(p_asset_fin_rec_old.global_attribute13, FND_API.G_MISS_CHAR) =
1198           nvl(p_asset_fin_rec_adj.global_attribute13,
1199               nvl(p_asset_fin_rec_old.global_attribute13, FND_API.G_MISS_CHAR)) and
1200        nvl(p_asset_fin_rec_old.global_attribute14, FND_API.G_MISS_CHAR) =
1201           nvl(p_asset_fin_rec_adj.global_attribute14,
1202               nvl(p_asset_fin_rec_old.global_attribute14, FND_API.G_MISS_CHAR)) and
1203        nvl(p_asset_fin_rec_old.global_attribute15, FND_API.G_MISS_CHAR) =
1204           nvl(p_asset_fin_rec_adj.global_attribute15,
1205               nvl(p_asset_fin_rec_old.global_attribute15, FND_API.G_MISS_CHAR)) and
1206        nvl(p_asset_fin_rec_old.global_attribute16, FND_API.G_MISS_CHAR) =
1207           nvl(p_asset_fin_rec_adj.global_attribute16,
1208               nvl(p_asset_fin_rec_old.global_attribute16, FND_API.G_MISS_CHAR)) and
1209        nvl(p_asset_fin_rec_old.global_attribute17, FND_API.G_MISS_CHAR) =
1210           nvl(p_asset_fin_rec_adj.global_attribute17,
1211               nvl(p_asset_fin_rec_old.global_attribute17, FND_API.G_MISS_CHAR)) and
1212        nvl(p_asset_fin_rec_old.global_attribute18, FND_API.G_MISS_CHAR) =
1213           nvl(p_asset_fin_rec_adj.global_attribute18,
1214               nvl(p_asset_fin_rec_old.global_attribute18, FND_API.G_MISS_CHAR)) and
1215        nvl(p_asset_fin_rec_old.global_attribute19, FND_API.G_MISS_CHAR) =
1216           nvl(p_asset_fin_rec_adj.global_attribute19,
1217               nvl(p_asset_fin_rec_old.global_attribute19, FND_API.G_MISS_CHAR)) and
1218        nvl(p_asset_fin_rec_old.global_attribute20, FND_API.G_MISS_CHAR) =
1219           nvl(p_asset_fin_rec_adj.global_attribute20,
1220               nvl(p_asset_fin_rec_old.global_attribute20, FND_API.G_MISS_CHAR)) and
1221        nvl(p_asset_fin_rec_old.global_attribute_category, FND_API.G_MISS_CHAR) =
1222           nvl(p_asset_fin_rec_adj.global_attribute_category,
1223               nvl(p_asset_fin_rec_old.global_attribute_category, FND_API.G_MISS_CHAR))) then
1224          l_no_changes_made := TRUE;
1225    else
1226          l_no_changes_made := FALSE;
1227    end if;
1228 
1229    if nvl(p_asset_fin_rec_old.unit_of_measure, FND_API.G_MISS_CHAR) =
1230          nvl(p_asset_fin_rec_adj.unit_of_measure,
1231              nvl(p_asset_fin_rec_old.unit_of_measure, FND_API.G_MISS_CHAR)) then
1232       l_no_changes_to_uom := TRUE;
1233    else
1234       l_no_changes_to_uom := FALSE;
1235    end if;
1236 
1237    if (p_asset_fin_rec_old.depreciate_flag = nvl(p_asset_fin_rec_adj.depreciate_flag,
1238                                                  p_asset_fin_rec_old.depreciate_flag)) then
1239       l_no_changes_to_dep_flag := TRUE;
1240    else
1241       l_no_changes_to_dep_flag := FALSE;
1242    end if;
1243 
1244    /*bug#16426081 starts*/
1245    if (p_asset_fin_rec_old.adjusted_cost = nvl(p_asset_fin_rec_adj.adjusted_cost,
1246                                                  p_asset_fin_rec_old.adjusted_cost)) then
1247       l_no_changes_adjusted_cost := TRUE;
1248    else
1249       l_no_changes_adjusted_cost := FALSE;
1250    end if;
1251    /*bug#16426081 ends*/
1252 
1253    if (nvl(p_asset_fin_rec_old.cash_generating_unit_id, FND_API.G_MISS_NUM) =
1254        nvl(p_asset_fin_rec_adj.cash_generating_unit_id,
1255         nvl(p_asset_fin_rec_old.cash_generating_unit_id, FND_API.G_MISS_NUM)))
1256    then
1257       l_no_changes_to_impairment := TRUE;
1258    else
1259       l_no_changes_to_impairment := FALSE;
1260    end if;
1261 
1262    if  p_asset_fin_rec_old.deprn_method_code =
1263           nvl(p_asset_fin_rec_adj.deprn_method_code,
1264               p_asset_fin_rec_old.deprn_method_code) and
1265        nvl(p_asset_fin_rec_old.life_in_months, FND_API.G_MISS_NUM) =
1266           nvl(p_asset_fin_rec_adj.life_in_months,
1267               nvl(p_asset_fin_rec_old.life_in_months, FND_API.G_MISS_NUM)) and
1268        nvl(p_asset_fin_rec_old.basic_rate, FND_API.G_MISS_NUM) =
1269           nvl(p_asset_fin_rec_adj.basic_rate,
1270               nvl(p_asset_fin_rec_old.basic_rate, FND_API.G_MISS_NUM)) and
1271        nvl(p_asset_fin_rec_old.adjusted_rate, FND_API.G_MISS_NUM) =
1272           nvl(p_asset_fin_rec_adj.adjusted_rate,
1273               nvl(p_asset_fin_rec_old.adjusted_rate, FND_API.G_MISS_NUM)) and
1274        nvl(p_asset_fin_rec_old.bonus_rule, FND_API.G_MISS_CHAR) =
1275           nvl(p_asset_fin_rec_adj.bonus_rule,
1276               nvl(p_asset_fin_rec_old.bonus_rule, FND_API.G_MISS_CHAR)) then
1277       l_no_changes_to_method := TRUE;
1278    else
1279       l_no_changes_to_method := FALSE;
1280    end if;
1281 
1282 
1283    if (p_asset_type_rec.asset_type =  'GROUP') then
1284       if  nvl(p_asset_fin_rec_old.recognize_gain_loss, FND_API.G_MISS_CHAR) =
1285              nvl(p_asset_fin_rec_adj.recognize_gain_loss,
1286                  nvl(p_asset_fin_rec_old.recognize_gain_loss, FND_API.G_MISS_CHAR)) and
1287           nvl(p_asset_fin_rec_old.recapture_reserve_flag, FND_API.G_MISS_CHAR) =
1288              nvl(p_asset_fin_rec_adj.recapture_reserve_flag,
1289                  nvl(p_asset_fin_rec_old.recapture_reserve_flag, FND_API.G_MISS_CHAR)) and
1290           nvl(p_asset_fin_rec_old.limit_proceeds_flag, FND_API.G_MISS_CHAR) =
1291              nvl(p_asset_fin_rec_adj.limit_proceeds_flag,
1292                  nvl(p_asset_fin_rec_old.limit_proceeds_flag, FND_API.G_MISS_CHAR)) and
1293           nvl(p_asset_fin_rec_old.terminal_gain_loss, FND_API.G_MISS_CHAR) =
1294              nvl(p_asset_fin_rec_adj.terminal_gain_loss,
1295                  nvl(p_asset_fin_rec_old.terminal_gain_loss, FND_API.G_MISS_CHAR)) and
1296           nvl(p_asset_fin_rec_old.tracking_method, FND_API.G_MISS_CHAR) =
1297              nvl(p_asset_fin_rec_adj.tracking_method,
1298                  nvl(p_asset_fin_rec_old.tracking_method, FND_API.G_MISS_CHAR)) and
1299           nvl(p_asset_fin_rec_old.exclude_fully_rsv_flag, FND_API.G_MISS_CHAR) =
1300              nvl(p_asset_fin_rec_adj.exclude_fully_rsv_flag,
1301                  nvl(p_asset_fin_rec_old.exclude_fully_rsv_flag, FND_API.G_MISS_CHAR)) and
1302           nvl(p_asset_fin_rec_old.excess_allocation_option, FND_API.G_MISS_CHAR) =
1303              nvl(p_asset_fin_rec_adj.excess_allocation_option,
1304                  nvl(p_asset_fin_rec_old.excess_allocation_option, FND_API.G_MISS_CHAR)) and
1305           nvl(p_asset_fin_rec_old.depreciation_option, FND_API.G_MISS_CHAR) =
1306              nvl(p_asset_fin_rec_adj.depreciation_option,
1307                  nvl(p_asset_fin_rec_old.depreciation_option, FND_API.G_MISS_CHAR)) and
1308           nvl(p_asset_fin_rec_old.member_rollup_flag, FND_API.G_MISS_CHAR) =
1309              nvl(p_asset_fin_rec_adj.member_rollup_flag,
1310                  nvl(p_asset_fin_rec_old.member_rollup_flag, FND_API.G_MISS_CHAR)) and
1311           nvl(p_asset_fin_rec_old.allocate_to_fully_rsv_flag, FND_API.G_MISS_CHAR) =
1312              nvl(p_asset_fin_rec_adj.allocate_to_fully_rsv_flag,
1313                  nvl(p_asset_fin_rec_old.allocate_to_fully_rsv_flag, FND_API.G_MISS_CHAR)) and
1314           /* HH group ed */
1315           nvl(p_asset_fin_rec_old.disabled_flag, FND_API.G_MISS_CHAR) =
1316              nvl(p_asset_fin_rec_adj.disabled_flag,
1317                  nvl(p_asset_fin_rec_old.disabled_flag, FND_API.G_MISS_CHAR)) and /* end HH */
1318           nvl(p_asset_fin_rec_old.allocate_to_fully_ret_flag, FND_API.G_MISS_CHAR) =
1319              nvl(p_asset_fin_rec_adj.allocate_to_fully_ret_flag,
1320                  nvl(p_asset_fin_rec_old.allocate_to_fully_ret_flag, FND_API.G_MISS_CHAR)) then
1321 
1322           if (p_log_level_rec.statement_level) then
1323             fa_debug_pkg.add('l_calling_fn', 'Do not need to set it to true again', 'TRUE', p_log_level_rec => p_log_level_rec);
1324           end if;
1325 
1326       else
1327          l_no_changes_made := FALSE;
1328       end if;
1329       l_no_changes_to_group := TRUE;
1330    else
1331       if  nvl(p_asset_fin_rec_old.group_asset_id, FND_API.G_MISS_NUM) =
1332              nvl(p_asset_fin_rec_adj.group_asset_id,
1333                  nvl(p_asset_fin_rec_old.group_asset_id, FND_API.G_MISS_NUM)) then
1334          l_no_changes_to_group := TRUE;
1335       else
1336          l_no_changes_to_group := FALSE;
1337       end if;
1338    end if;
1339 
1340    if  nvl(p_asset_fin_rec_adj.reduction_rate, 0) = 0 and
1341        nvl(p_asset_fin_rec_old.reduce_addition_flag, FND_API.G_MISS_CHAR) =
1342           nvl(p_asset_fin_rec_adj.reduce_addition_flag,
1343               nvl(p_asset_fin_rec_old.reduce_addition_flag, FND_API.G_MISS_CHAR)) and
1344        nvl(p_asset_fin_rec_old.reduce_adjustment_flag, FND_API.G_MISS_CHAR) =
1345           nvl(p_asset_fin_rec_adj.reduce_adjustment_flag,
1346               nvl(p_asset_fin_rec_old.reduce_adjustment_flag, FND_API.G_MISS_CHAR)) and
1347        nvl(p_asset_fin_rec_old.reduce_retirement_flag, FND_API.G_MISS_CHAR) =
1348           nvl(p_asset_fin_rec_adj.reduce_retirement_flag,
1349               nvl(p_asset_fin_rec_old.reduce_retirement_flag, FND_API.G_MISS_CHAR)) then
1350       l_no_changes_to_reduction := TRUE;
1351    else
1352       l_no_changes_to_reduction := FALSE;
1353    end if;
1354 
1355    if (l_no_changes_made) then
1356       if (l_no_changes_to_uom) then
1357          if (l_no_changes_to_group) and (l_no_changes_to_reduction) and (l_no_changes_to_method) then
1358             if (l_no_changes_to_dep_flag) and (l_no_changes_to_impairment)
1359                and (l_no_changes_adjusted_cost) /*bug#16426081*/ then
1360                fa_srvr_msg.add_message(
1361                    calling_fn => l_calling_fn,
1362                    name       => 'FA_SHARED_NO_CHANGES_TO_COMMIT', p_log_level_rec => p_log_level_rec);
1363                return FALSE;
1364 
1365                -- old code would handle adj_req_status here as an else stmt
1366                -- we're doing it in calc engine
1367             end if;
1368          end if;
1369       end if;
1370 
1371       if (not l_no_changes_to_group) and ((not l_no_changes_to_method) and
1372          (nvl(p_asset_fin_rec_adj.depreciation_option,
1373               nvl(p_asset_fin_rec_old.depreciation_option, 'NULL')) <> 'GROUP')) then
1374 
1375          if (p_log_level_rec.statement_level) then
1376            fa_debug_pkg.add('l_calling_fn', 'No method change if depreciation_option <> ', 'GROUP', p_log_level_rec => p_log_level_rec);
1377          end if;
1378 
1379          fa_srvr_msg.add_message(
1380              calling_fn => l_calling_fn,
1381              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1382          return FALSE;
1383       end if;
1384 
1385       if (not l_no_changes_to_dep_flag) and
1386          ((not l_no_changes_to_reduction) or
1387           (not l_no_changes_to_group) or
1388           (not l_no_changes_to_impairment) or
1389           (not l_no_changes_adjusted_cost) or /*bug#16426081 */
1390           (not l_no_changes_to_method)) then
1391          fa_srvr_msg.add_message(
1392              calling_fn => l_calling_fn,
1393              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1394          return FALSE;
1395       end if;
1396 
1397       if (not l_no_changes_to_impairment) and
1398          ((not l_no_changes_to_reduction) or
1399           (not l_no_changes_to_group) or
1400           (not l_no_changes_made) or
1401           (not l_no_changes_to_method)) then
1402          fa_srvr_msg.add_message(
1403              calling_fn => l_calling_fn,
1404              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1405          return FALSE;
1406       end if;
1407 
1408    else
1409 
1410       if (not l_no_changes_to_dep_flag) then
1411          fa_srvr_msg.add_message(
1412              calling_fn => l_calling_fn,
1413              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1414          return FALSE;
1415       end if;
1416 
1417       if (not l_no_changes_to_impairment) then
1418          fa_srvr_msg.add_message(
1419              calling_fn => l_calling_fn,
1420              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1421          return FALSE;
1422       end if;
1423 
1424       if (not l_no_changes_to_group) then
1425          fa_srvr_msg.add_message(
1426              calling_fn => l_calling_fn,
1427              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1428          return FALSE;
1429       end if;
1430       /*bug#16426081 starts*/
1431       if (not l_no_changes_adjusted_cost) then
1432          fa_srvr_msg.add_message(
1433              calling_fn => l_calling_fn,
1434              name       => 'FA_BK_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
1435          return FALSE;
1436       end if;
1437       /*bug#16426081 ends*/
1438 
1439    end if;
1440 
1441 end if;
1442 
1443 IF not FA_ASSET_VAL_PVT.validate_energy_transactions (
1444  	       p_trans_rec            => p_trans_rec,
1445  	       p_asset_type_rec       => p_asset_type_rec,
1446  	       p_asset_fin_rec_old    => p_asset_fin_rec_old,
1447  	       p_asset_fin_rec_adj    => p_asset_fin_rec_adj,
1448  	       p_asset_hdr_rec        => p_asset_hdr_rec ,
1449  	       p_log_level_rec        => p_log_level_rec) then
1450 
1451    return FALSE;
1452 END IF;
1453 
1454 
1455    return true;
1456 
1457 END validate_adjustment;
1458 
1459 /*bug#16426081 */
1460 function process_trx_stack (
1461    -- specific parameter
1462    p_orig_trx_type            IN VARCHAR2,
1463    x_trx_stack                OUT NOCOPY  BOOLEAN,
1464    -- Standard Parameters --
1465    p_validation_level         IN  NUMBER :=FND_API.G_VALID_LEVEL_FULL,
1466    x_return_status            OUT NOCOPY  VARCHAR2,
1467    x_msg_count                OUT NOCOPY  NUMBER,
1468    x_msg_data                 OUT NOCOPY  VARCHAR2,
1469    p_calling_fn               IN  VARCHAR2,
1470    p_log_level_rec            IN  FA_API_TYPES.log_level_rec_type,
1471    -- Transaction Object --
1472    px_trans_rec                IN OUT NOCOPY  fa_api_types.trans_rec_type,
1473    px_dist_trans_rec           IN OUT NOCOPY  fa_api_types.trans_rec_type,
1474    -- Asset Object --
1475    px_asset_hdr_rec            IN OUT NOCOPY  fa_api_types.asset_hdr_rec_type,
1476    px_asset_desc_rec           IN OUT NOCOPY  fa_api_types.asset_desc_rec_type,
1477    px_asset_type_rec           IN OUT NOCOPY  fa_api_types.asset_type_rec_type,
1478    px_asset_cat_rec            IN OUT NOCOPY  fa_api_types.asset_cat_rec_type,
1479    px_asset_hierarchy_rec      IN OUT NOCOPY  fa_api_types.asset_hierarchy_rec_type,
1480    px_asset_fin_rec            IN OUT NOCOPY  fa_api_types.asset_fin_rec_type,
1481    px_asset_deprn_rec          IN OUT NOCOPY  fa_api_types.asset_deprn_rec_type,
1482    px_asset_dist_tbl           IN OUT NOCOPY  fa_api_types.asset_dist_tbl_type,
1483    -- Invoice Object --
1484    px_inv_tbl                  IN OUT NOCOPY  fa_api_types.inv_tbl_type,
1485    ---- adjustment related parameters -------------
1486    p_asset_fin_rec_adj        IN     FA_API_TYPES.asset_fin_rec_type,
1487    x_asset_fin_rec_new        OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
1488    x_asset_fin_mrc_tbl_new    OUT NOCOPY FA_API_TYPES.asset_fin_tbl_type,
1489    px_inv_trans_rec           IN OUT NOCOPY FA_API_TYPES.inv_trans_rec_type,
1490    p_asset_deprn_rec_adj      IN     FA_API_TYPES.asset_deprn_rec_type,
1491    x_asset_deprn_rec_new      OUT NOCOPY FA_API_TYPES.asset_deprn_rec_type,
1492    x_asset_deprn_mrc_tbl_new  OUT NOCOPY FA_API_TYPES.asset_deprn_tbl_type,
1493    p_group_reclass_options_rec IN    FA_API_TYPES.group_reclass_options_rec_type
1494 
1495    ) return boolean is
1496    l_original_trx_type  varchar2(3) := p_orig_trx_type;
1497    l_asset_fin_rec_adj  FA_API_TYPES.asset_fin_rec_type;
1498    l_asset_fin_rec_old  FA_API_TYPES.asset_fin_rec_type;
1499    l_asset_deprn_rec_old FA_API_TYPES.asset_deprn_rec_type;
1500    l_asset_fin_rec_in  FA_API_TYPES.asset_fin_rec_type;
1501    l_trans_rec_in  fa_api_types.trans_rec_type;
1502    l_group_asset_id number;
1503    l_reduction_rate number;
1504    l_asset_id number;
1505    l_adjusted_cost number;
1506 
1507 
1508    l_adj_count  number := 0;
1509    l_ind_trx_count number := 0;
1510    l_return boolean := TRUE;
1511    l_group_flag boolean := false;
1512    l_adj_cost_flag boolean := false;
1513    l_date_sec date := sysdate;
1514    l_sec_diff number;
1515 
1516    l_calling_fn               varchar2(35)  := 'FA_ADJUSTMENT_PVT.process_trx_stack';
1517 
1518 BEGIN
1519    if (p_log_level_rec.statement_level) then
1520      fa_debug_pkg.add(l_calling_fn, 'l_original_trx_type', l_original_trx_type,
1521                      p_log_level_rec => p_log_level_rec);
1522    end if;
1523    if (l_original_trx_type = 'ADD') then
1524       if (nvl(px_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM
1525          and nvl(px_asset_deprn_rec.deprn_reserve,0) <> 0
1526       ) then
1527          l_adj_count := l_adj_count+1;
1528          l_group_asset_id := px_asset_fin_rec.group_asset_id;
1529          l_reduction_rate := px_asset_fin_rec.reduction_rate;
1530          px_asset_fin_rec.group_asset_id := null;
1531          px_asset_fin_rec.reduction_rate := null;
1532          l_group_flag := true;
1533       end if;
1534       if (px_asset_fin_rec.adjusted_cost <> 0) then
1535          if (not fa_cache_pkg.fazccmt(px_asset_fin_rec.deprn_method_code,px_asset_fin_rec.life_in_months,
1536                                       p_log_level_rec => p_log_level_rec)) then
1537             if (p_log_level_rec.statement_level) then
1538                   fa_debug_pkg.add(l_calling_fn, 'Error calling', 'fa_cache_pkg.fazccmt', p_log_level_rec => p_log_level_rec);
1539             end if;
1540             raise FND_API.G_EXC_UNEXPECTED_ERROR;
1541          end if;
1542          if(nvl(fa_cache_pkg.fazcdrd_record.rule_name,'ZZ') = 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT') then
1543             l_adj_count := l_adj_count+1;
1544             l_adjusted_cost := px_asset_fin_rec.adjusted_cost;
1545             l_adj_cost_flag := true;
1546          end if;
1547          px_asset_fin_rec.adjusted_cost := null;
1548       end if;
1549    end if;
1550    if (l_original_trx_type = 'ADJ') then
1551       l_asset_fin_rec_adj := p_asset_fin_rec_adj;
1552       if (nvl(p_asset_fin_rec_adj.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM
1553           and nvl(p_asset_deprn_rec_adj.deprn_reserve,0) <> 0
1554          ) then
1555          l_adj_count := l_adj_count+1;
1556          l_group_asset_id := p_asset_fin_rec_adj.group_asset_id;
1557          l_reduction_rate := p_asset_fin_rec_adj.reduction_rate;
1558          l_asset_fin_rec_adj.group_asset_id := null;
1559          l_asset_fin_rec_adj.reduction_rate := null;
1560          l_group_flag := true;
1561       end if;
1562       if ((p_asset_fin_rec_adj.adjusted_cost <> 0) and
1563           (nvl(p_asset_fin_rec_adj.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM ) )then
1564          l_adj_count := l_adj_count+1;
1565          l_adjusted_cost := p_asset_fin_rec_adj.adjusted_cost;
1566          l_asset_fin_rec_adj.adjusted_cost := null;
1567          l_adj_cost_flag := true;
1568       end if;
1569    end if;
1570    if (p_log_level_rec.statement_level) then
1571      fa_debug_pkg.add(l_calling_fn, 'l_adj_count', l_adj_count,
1572                      p_log_level_rec => p_log_level_rec);
1573    end if;
1574    if l_adj_count = 0 then
1575       x_trx_stack := false;
1576       return true;
1577    end if;
1578    x_trx_stack := true;
1579 
1580    /* Transactions should be processed in following order
1581    1. Original transaction
1582    2. Transaction that sets adjusted_cost
1583    3. Transaction setting group_asset_id
1584    */
1585    if (l_original_trx_type = 'ADD') then
1586       fa_addition_pub.do_addition
1587       (p_api_version             => 1.0,
1588        p_init_msg_list           => FND_API.G_FALSE,
1589        p_commit                  => FND_API.G_FALSE,
1590        p_validation_level        => FND_API.G_VALID_LEVEL_FULL,
1591        x_return_status           => x_return_status,
1592        x_msg_count               => x_msg_count,
1593        x_msg_data                => x_msg_data,
1594        p_calling_fn              => null,
1595        px_trans_rec              => px_trans_rec,
1596        px_dist_trans_rec         => px_dist_trans_rec,
1597        px_asset_hdr_rec          => px_asset_hdr_rec,
1598        px_asset_desc_rec         => px_asset_desc_rec,
1599        px_asset_type_rec         => px_asset_type_rec,
1600        px_asset_cat_rec          => px_asset_cat_rec,
1601        px_asset_hierarchy_rec    => px_asset_hierarchy_rec,
1602        px_asset_fin_rec          => px_asset_fin_rec,
1603        px_asset_deprn_rec        => px_asset_deprn_rec,
1604        px_asset_dist_tbl         => px_asset_dist_tbl,
1605        px_inv_tbl                => px_inv_tbl
1606       );
1607    else
1608       FA_ADJUSTMENT_PUB.do_adjustment
1609       (p_api_version             => 1.0,
1610       p_init_msg_list           => FND_API.G_FALSE,
1611       p_commit                  => FND_API.G_FALSE,
1612       p_validation_level        => FND_API.G_VALID_LEVEL_FULL,
1613       x_return_status           => x_return_status,
1614       x_msg_count               => x_msg_count,
1615       x_msg_data                => x_msg_data,
1616       p_calling_fn              => null,
1617       px_trans_rec              => px_trans_rec,
1618       px_asset_hdr_rec          => px_asset_hdr_rec,
1619       p_asset_fin_rec_adj       => l_asset_fin_rec_adj,
1620       x_asset_fin_rec_new       => x_asset_fin_rec_new,
1621       x_asset_fin_mrc_tbl_new   => x_asset_fin_mrc_tbl_new,
1622       px_inv_trans_rec          => px_inv_trans_rec,
1623       px_inv_tbl                => px_inv_tbl,
1624       p_asset_deprn_rec_adj     => p_asset_deprn_rec_adj,
1625       x_asset_deprn_rec_new     => x_asset_deprn_rec_new,
1626       x_asset_deprn_mrc_tbl_new => x_asset_deprn_mrc_tbl_new,
1627       p_group_reclass_options_rec => p_group_reclass_options_rec
1628       );
1629    end if;
1630    if (p_log_level_rec.statement_level) then
1631      fa_debug_pkg.add(l_calling_fn, 'x_return_status after original trx', x_return_status,
1632                      p_log_level_rec => p_log_level_rec);
1633    end if;
1634    if (x_return_status = FND_API.G_RET_STS_ERROR) then
1635       l_return := false;
1636       return false;
1637    else
1638       l_asset_id := px_asset_hdr_rec.asset_id;
1639       l_date_sec := px_trans_rec.who_info.last_update_date;
1640       if (p_log_level_rec.statement_level) then
1641         fa_debug_pkg.add(l_calling_fn, 'l_asset_id after original trx', l_asset_id,
1642                         p_log_level_rec => p_log_level_rec);
1643         fa_debug_pkg.add(l_calling_fn, 'px_trans_rec.who_info.last_update_date', px_trans_rec.who_info.last_update_date,
1644                         p_log_level_rec => p_log_level_rec);
1645         fa_debug_pkg.add(l_calling_fn, 'px_trans_rec.amortization_start_date', px_trans_rec.amortization_start_date,
1646                         p_log_level_rec => p_log_level_rec);
1647       end if;
1648    end if;
1649    for ind in 1..l_adj_count
1650    loop
1651       declare
1652          l_trans_rec                FA_API_TYPES.trans_rec_type;
1653          l_asset_hdr_rec            FA_API_TYPES.asset_hdr_rec_type;
1654          l_asset_fin_rec_adj_1      FA_API_TYPES.asset_fin_rec_type;
1655          l_asset_fin_rec_new        FA_API_TYPES.asset_fin_rec_type;
1656          l_asset_fin_mrc_tbl_new    FA_API_TYPES.asset_fin_tbl_type;
1657          l_inv_trans_rec            FA_API_TYPES.inv_trans_rec_type;
1658          l_inv_tbl                  FA_API_TYPES.inv_tbl_type;
1659          l_inv_rate_tbl             FA_API_TYPES.inv_rate_tbl_type;
1660          l_asset_deprn_rec_adj      FA_API_TYPES.asset_deprn_rec_type;
1661          l_asset_deprn_rec_new      FA_API_TYPES.asset_deprn_rec_type;
1662          l_asset_deprn_mrc_tbl_new  FA_API_TYPES.asset_deprn_tbl_type;
1663          l_inv_rec                  FA_API_TYPES.inv_rec_type;
1664          l_group_reclass_options_rec FA_API_TYPES.group_reclass_options_rec_type;
1665          l_cal_close_date     date;
1666       begin
1667          if (p_log_level_rec.statement_level) then
1668            fa_debug_pkg.add(l_calling_fn, 'inside loop start ind', ind,
1669                            p_log_level_rec => p_log_level_rec);
1670          end if;
1671          if ((sysdate-l_date_sec)*24*60*60 < 1) then
1672             dbms_lock.sleep(1);
1673          end if;
1674          /*
1675          select calendar_period_close_date
1676          into   l_cal_close_date
1677          from   fa_deprn_periods
1678          where  book_type_code = px_asset_hdr_rec.book_type_code
1679          and    period_close_date is null;
1680          */
1681 
1682          l_trans_rec.amortization_start_date := px_trans_rec.amortization_start_date ;
1683 
1684          l_asset_hdr_rec.asset_id := l_asset_id;
1685          l_asset_hdr_rec.book_type_code := px_asset_hdr_rec.book_type_code;
1686 
1687          l_trans_rec.transaction_subtype := 'AMORTIZED';
1688          l_trans_rec.transaction_date_entered := l_trans_rec.amortization_start_date;
1689          l_trans_rec.transaction_type_code      := 'ADJUSTMENT';
1690          l_trans_rec.who_info.last_updated_by   := px_trans_rec.who_info.last_updated_by;
1691          l_trans_rec.who_info.creation_date := sysdate;
1692          l_trans_rec.who_info.last_update_date  := l_trans_rec.who_info.creation_date;
1693 
1694          if (l_group_flag and ind = 1) then
1695             if (p_log_level_rec.statement_level) then
1696               fa_debug_pkg.add(l_calling_fn, 'Group reclass l_group_asset_id ', l_group_asset_id,
1697                               p_log_level_rec => p_log_level_rec);
1698             end if;
1699             l_asset_fin_rec_adj_1.group_asset_id := l_group_asset_id;
1700             l_asset_fin_rec_adj_1.reduction_rate := l_reduction_rate;
1701             l_group_reclass_options_rec.group_reclass_type := 'CALC';
1702             l_group_reclass_options_rec.transfer_flag := 'YES';
1703          end if;
1704          if ((l_adj_cost_flag and ind = 1 and l_adj_count = 1) or (ind = 2) ) then
1705             l_asset_fin_rec_adj_1.adjusted_cost := l_adjusted_cost;
1706             if (p_log_level_rec.statement_level) then
1707               fa_debug_pkg.add(l_calling_fn, 'Update adjusted_cost ', 'l_adjusted_cost ',
1708                               p_log_level_rec => p_log_level_rec);
1709             end if;
1710          end if;
1711 
1712          FA_ADJUSTMENT_PUB.do_adjustment
1713            (p_api_version             => 1.0,
1714             p_init_msg_list           => FND_API.G_FALSE,
1715             p_commit                  => FND_API.G_FALSE,
1716             p_validation_level        => FND_API.G_VALID_LEVEL_FULL,
1717             x_return_status           => x_return_status,
1718             x_msg_count               => x_msg_count,
1719             x_msg_data                => x_msg_data,
1720             p_calling_fn              => null,
1721             px_trans_rec              => l_trans_rec,
1722             px_asset_hdr_rec          => l_asset_hdr_rec,
1723             p_asset_fin_rec_adj       => l_asset_fin_rec_adj_1,
1724             x_asset_fin_rec_new       => l_asset_fin_rec_new,
1725             x_asset_fin_mrc_tbl_new   => l_asset_fin_mrc_tbl_new,
1726             px_inv_trans_rec          => l_inv_trans_rec,
1727             px_inv_tbl                => l_inv_tbl,
1728             p_asset_deprn_rec_adj     => l_asset_deprn_rec_adj,
1729             x_asset_deprn_rec_new     => l_asset_deprn_rec_new,
1730             x_asset_deprn_mrc_tbl_new => l_asset_deprn_mrc_tbl_new,
1731             p_group_reclass_options_rec => l_group_reclass_options_rec
1732            );
1733          if (p_log_level_rec.statement_level) then
1734            fa_debug_pkg.add(l_calling_fn, ' x_return_status',  x_return_status,
1735                            p_log_level_rec => p_log_level_rec);
1736          end if;
1737          if (x_return_status = FND_API.G_RET_STS_ERROR) then
1738             l_return := false;
1739             exit;
1740          end if;
1741          if (p_log_level_rec.statement_level) then
1742            fa_debug_pkg.add(l_calling_fn, 'l_trans_rec.transaction_header_id',l_trans_rec.transaction_header_id,
1743                            p_log_level_rec => p_log_level_rec);
1744          end if;
1745          l_date_sec := l_trans_rec.who_info.last_update_date;
1746       exception
1747          when others then
1748             if (p_log_level_rec.statement_level) then
1749               fa_debug_pkg.add(l_calling_fn, 'error sqlerrm',sqlerrm,
1750                               p_log_level_rec => p_log_level_rec);
1751             end if;
1752             l_return := false;
1753             exit;
1754       end;
1755    end loop;
1756    return l_return;
1757 END process_trx_stack;
1758 
1759 END FA_ADJUSTMENT_PVT;