DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_UNPLANNED_PVT

Source


1 PACKAGE BODY FA_UNPLANNED_PVT as
2 /* $Header: FAVUNPLB.pls 120.33.12020000.3 2012/11/30 14:10:04 spooyath ship $   */
3 
4 g_release                  number  := fa_cache_pkg.fazarel_release;
5 
6 FUNCTION do_unplanned
7    (px_trans_rec              IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
8     p_asset_hdr_rec           IN     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           IN     FA_API_TYPES.asset_fin_rec_type,
13     p_asset_deprn_rec         IN     FA_API_TYPES.asset_deprn_rec_type,
14     p_unplanned_deprn_rec     IN     FA_API_TYPES.unplanned_deprn_rec_type,
15     p_period_rec              IN     FA_API_TYPES.period_rec_type,
16     p_mrc_sob_type_code       IN     VARCHAR2,
17     p_log_level_rec           IN     FA_API_TYPES.log_level_rec_type) return boolean is
18 
19    -- used for method cache
20    l_deprn_basis_rule          VARCHAR2(4);
21    l_rate_source_rule          VARCHAR2(10);
22 
23    --  used for mrc
24    l_debit_credit_flag         VARCHAR2(2);
25    l_unplanned_amount          NUMBER;
26    l_amount_inserted           NUMBER;
27 
28    --
29    -- For calling faxama.
30    --
31    l_deprn_exp                 NUMBER := 0;
32    l_bonus_deprn_exp           NUMBER := 0;
33    l_impairment_exp            NUMBER := 0;
34    l_deprn_rsv                 NUMBER := 0;
35    l_asset_deprn_rec_adj       FA_API_TYPES.ASSET_DEPRN_REC_TYPE;
36    l_asset_deprn_rec_new       FA_API_TYPES.ASSET_DEPRN_REC_TYPE;
37    l_group_reclass_options_rec FA_API_TYPES.group_reclass_options_rec_type;
38    l_temp_raf                  NUMBER;
39 
40    l_status                    boolean;
41    l_rowid                     rowid;
42 
43    l_transaction_subtype       VARCHAR2(9);
44    l_transaction_key           VARCHAR2(2);
45    l_rounding_flag             VARCHAR2(3);
46 
47    l_adj                       fa_adjust_type_pkg.fa_adj_row_struct;
48 
49    -- used for return values
50    l_asset_fin_rec             FA_API_TYPES.asset_fin_rec_type;
51    l_asset_fin_rec_null        FA_API_TYPES.asset_fin_rec_type;
52 
53    deprn_override_flag_default varchar2(1);
54 
55    -- Bug:5930979:Japan Tax Reform Project
56    l_method_type               number := 0;
57    l_success                   integer;
58    l_rate_in_use               number;
59 
60    l_calling_fn                VARCHAR2(35) := 'fa_unplanned_pvt.do_unplanned';
61    unp_err                     EXCEPTION;
62    --Secondary changes
63    l_secondary_asset_hdr_rec        fa_api_types.asset_hdr_rec_type;
64    l_secondary_trans_rec               fa_api_types.trans_rec_type;
65    l_secondary_sob_id                   number;
66    l_mem_nbv_sum               NUMBER;    /* Added for Bug 12334717 */
67 BEGIN
68 
69    if (p_log_level_rec.statement_level) then
70       fa_debug_pkg.add(l_calling_fn, 'Begin', p_asset_hdr_rec.asset_id, p_log_level_rec => p_log_level_rec);
71    end if;
72 
73    l_asset_fin_rec          := p_asset_fin_rec;
74 
75    l_unplanned_amount       := p_unplanned_deprn_rec.unplanned_amount;
76 
77    l_rounding_flag       := 'ADJ';
78    l_transaction_key     := px_trans_rec.transaction_key;
79    l_transaction_subtype := p_unplanned_deprn_rec.unplanned_type;
80 
81    deprn_override_flag_default:= fa_std_types.FA_NO_OVERRIDE;
82 
83    if not FA_CACHE_PKG.fazccmt(p_asset_fin_rec.deprn_method_code,
84                                p_asset_fin_rec.life_in_months,
85                                p_log_level_rec => p_log_level_rec) then
86       raise unp_err;
87    end if;
88 
89 
90    -- check that method is valid for unplanned - only need to due this for primary
91 
92    if (p_mrc_sob_type_code <> 'R') then
93 
94       l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
95       l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
96 
97       if (l_rate_source_rule    = 'TABLE' or
98           (l_deprn_basis_rule   = 'NBV' and
99            l_rate_source_rule  <> 'FLAT')) and
100          (not (l_deprn_basis_rule = 'NBV' and
101                l_rate_source_rule = 'PRODUCTION' and
102                fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE')) then
103 
104          -- Bug:5930979:Japan Tax Reform Project
105          if not (l_rate_source_rule  = 'FORMULA') then
106             fa_srvr_msg.add_message
107               (name       => '*** unplanned not allowed ***',
108                calling_fn => l_calling_fn,
109                p_log_level_rec => p_log_level_rec);
110             raise unp_err;
111          end if;
112       end if;
113 
114 
115       -- verify amount is less then recoverable cost or reserve
116 
117       -- Fix for bug #2897597.  If group asset has over depreciate
118       -- option as YES or DEPRN, then allow the unplanned amount to be
119       -- greater than the nbv
120 
121       -- BUG# 2898745
122       -- nesting the comparison with reserve back under cost > 0
123       -- also adding checks to prevent negative cost assets
124       -- from over depreciating (previously, no restrictions existed)
125 
126       -- Bug 11695122 : Check for cost = 0 also
127 
128        /* Added for Bug 12334717 Start */
129       If  (p_asset_type_rec.asset_type = 'GROUP' and
130            l_deprn_basis_rule = 'NBV' and
131            l_rate_source_rule = 'PRODUCTION' and
132            fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') then
133 
134                SELECT SUM(recoverable_cost) -
135                       SUM (FA_UTIL_PVT.get_asset_deprn_resv (p_asset_hdr_rec.book_type_code,
136                                                              asset_id,
137                                                              p_asset_hdr_rec.set_of_books_id,
138                                                              p_period_rec.period_counter,
139                                                              p_mrc_sob_type_code ))
140                       INTO l_mem_nbv_sum
141                       FROM fa_books
142                       WHERE group_asset_id = p_asset_hdr_rec.asset_id
143                         AND book_type_code = p_asset_hdr_rec.book_type_code
144                         AND transaction_header_id_out IS NULL;
145 
146                if (l_mem_nbv_sum = 0 and l_unplanned_amount <> 0) or
147                   (l_mem_nbv_sum < 0 and l_mem_nbv_sum > l_unplanned_amount) or
148                   (l_mem_nbv_sum > 0 and l_mem_nbv_sum < l_unplanned_amount) then
149 
150                 fa_srvr_msg.add_message
151                     (name       => 'FA_UNP_GRP_MEM_AMT',
152                      calling_fn => l_calling_fn,
153                      p_log_level_rec => p_log_level_rec);
154                 raise unp_err;
155                end if;
156       end if;
157        /* Added for Bug 12334717 End */
158 
159       if (p_asset_fin_rec.cost >= 0) then
160          if (p_unplanned_deprn_rec.unplanned_amount > 0) then
161             if (p_unplanned_deprn_rec.unplanned_amount >
162                 (p_asset_fin_rec.adjusted_recoverable_cost - p_asset_deprn_rec.deprn_reserve) and
163                 (nvl(p_asset_fin_rec.over_depreciate_option, 'NO') not in
164                  ('YES', 'DEPRN'))) then
165 
166                 fa_srvr_msg.add_message
167                     (name       => 'FA_UNP_DEP_AMT_1',
168                      calling_fn => l_calling_fn,
169                      p_log_level_rec => p_log_level_rec);
170                 raise unp_err;
171             end if;
172          elsif (p_unplanned_deprn_rec.unplanned_amount < 0) and
173                (p_asset_type_rec.asset_type <> 'GROUP' OR p_asset_fin_rec.cost = 0 ) then
174             if ((-1) * (p_unplanned_deprn_rec.unplanned_amount)  > p_asset_deprn_rec.deprn_reserve) then
175 
176                 fa_srvr_msg.add_message
177                    (name       => 'FA_UNP_DEP_AMT_2',
178                     calling_fn => l_calling_fn,
179                     p_log_level_rec => p_log_level_rec);
180                raise unp_err;
181             end if;
182          end if;
183       elsif (p_asset_fin_rec.cost < 0) then
184          if (p_unplanned_deprn_rec.unplanned_amount < 0) then
185             if (p_unplanned_deprn_rec.unplanned_amount <
186                 (p_asset_fin_rec.adjusted_recoverable_cost - p_asset_deprn_rec.deprn_reserve) and
187                 (nvl(p_asset_fin_rec.over_depreciate_option, 'NO') not in
188                  ('YES', 'DEPRN'))) then
189 
190                 fa_srvr_msg.add_message
191                     (name       => 'FA_UNP_DEP_AMT_1',
192                      calling_fn => l_calling_fn,
193                      p_log_level_rec => p_log_level_rec);
194                 raise unp_err;
195             end if;
196          elsif (p_unplanned_deprn_rec.unplanned_amount > 0) and
197                (p_asset_type_rec.asset_type <> 'GROUP') then
198             if (p_unplanned_deprn_rec.unplanned_amount > (-1 * p_asset_deprn_rec.deprn_reserve)) then
199 
200                 fa_srvr_msg.add_message
201                    (name       => 'FA_UNP_DEP_AMT_2',
202                     calling_fn => l_calling_fn,
203                     p_log_level_rec => p_log_level_rec);
204                raise unp_err;
205             end if;
206          end if;
207 
208       end if; --(p_asset_fin_rec.cost > 0)
209 
210       -- void original addition row in period of addition
211       if (p_asset_hdr_rec.period_of_addition = 'Y' and
212           G_release = 11) then
213           FA_TRANSACTION_HEADERS_PKG.Update_Trx_Type
214              (X_Book_Type_Code                => p_asset_hdr_rec.book_type_code,
215               X_Asset_Id                      => p_asset_hdr_rec.asset_id,
216               X_Transaction_Type_Code         => px_trans_rec.transaction_type_code,
217               X_New_Transaction_Type          => px_trans_rec.transaction_type_code || '/VOID',
218               X_Return_Status                 => l_status,
219               X_Calling_Fn                    => l_calling_fn,
220               p_log_level_rec                 => p_log_level_rec);
221       end if;
222 
223       if not l_status then
224          raise unp_err;
225       end if;
226 
227       -- SLA UPTAKE
228       -- assign an event for the transaction
229       -- at this point key info asset/book/trx info is known from initialize
230       -- call and the above code (i.e. trx_type, etc)
231 
232       select fa_transaction_headers_s.nextval
233         into px_trans_rec.transaction_header_id
234         from dual;
235 
236       -- Bug 15877517 : Reinitialize who_info as well
237       px_trans_rec.who_info.creation_date := sysdate;
238       px_trans_rec.who_info.last_update_date := sysdate;
239 
240       if not fa_xla_events_pvt.create_transaction_event
241                (p_asset_hdr_rec => p_asset_hdr_rec,
242                 p_asset_type_rec=> p_asset_type_rec,
243                 px_trans_rec    => px_trans_rec,
244                 p_event_status  => NULL,
245                 p_calling_fn    => l_calling_fn,
246                 p_log_level_rec => p_log_level_rec) then
247          raise unp_err;
248       end if;
249         /*=================================================================
250         Secondary Changes Start
251         If primary and secondary sob_id is different then we need to
252         create/update/delete event for secondary ledger*/
253          l_secondary_sob_id := FA_XLA_EVENTS_PVT.get_secondary_sob_id(p_asset_hdr_rec.book_type_code);
254 
255          if(l_secondary_sob_id is not null) then
256            l_secondary_asset_hdr_rec := p_asset_hdr_rec;
257            l_secondary_trans_rec        := px_trans_rec;
258 
259            l_secondary_asset_hdr_rec.set_of_books_id := l_secondary_sob_id;
260 
261              if not fa_xla_events_pvt.create_transaction_event
262                   (p_asset_hdr_rec => l_secondary_asset_hdr_rec,
263                    p_asset_type_rec=> p_asset_type_rec,
264                    px_trans_rec    => l_secondary_trans_rec,
265                    p_event_status  => NULL,
266                    p_calling_fn    => l_calling_fn
267                    ,p_log_level_rec => p_log_level_rec) then
268                 raise unp_err;
269              end if;
270          end if;
271         /*Secondary Changes End
272         ==================================================================*/
273       FA_TRANSACTION_HEADERS_PKG.Insert_Row
274                       (X_Rowid                          => l_rowid,
275                        X_Transaction_Header_Id          => px_trans_rec.transaction_header_id,
276                        X_Book_Type_Code                 => p_asset_hdr_rec.book_type_code,
277                        X_Asset_Id                       => p_asset_hdr_rec.asset_id,
278                        X_Transaction_Type_Code          => px_trans_rec.transaction_type_code,
279                        X_Transaction_Date_Entered       => px_trans_rec.transaction_date_entered,
280                        X_Date_Effective                 => px_trans_rec.who_info.creation_date,
281                        X_Last_Update_Date               => px_trans_rec.who_info.last_update_date,
282                        X_Last_Updated_By                => px_trans_rec.who_info.last_updated_by,
283                        X_Transaction_Name               => px_trans_rec.transaction_name,
284                        X_Invoice_Transaction_Id         => NULL,
285                        X_Source_Transaction_Header_Id   => px_trans_rec.source_transaction_header_id,
286                        X_Mass_Reference_Id              => px_trans_rec.mass_reference_id,
287                        X_Last_Update_Login              => px_trans_rec.who_info.last_update_login,
288                        X_Transaction_Subtype            => l_transaction_subtype,
289                        X_Attribute1                     => px_trans_rec.desc_flex.attribute1,
290                        X_Attribute2                     => px_trans_rec.desc_flex.attribute2,
291                        X_Attribute3                     => px_trans_rec.desc_flex.attribute3,
292                        X_Attribute4                     => px_trans_rec.desc_flex.attribute4,
293                        X_Attribute5                     => px_trans_rec.desc_flex.attribute5,
294                        X_Attribute6                     => px_trans_rec.desc_flex.attribute6,
295                        X_Attribute7                     => px_trans_rec.desc_flex.attribute7,
296                        X_Attribute8                     => px_trans_rec.desc_flex.attribute8,
297                        X_Attribute9                     => px_trans_rec.desc_flex.attribute9,
298                        X_Attribute10                    => px_trans_rec.desc_flex.attribute10,
299                        X_Attribute11                    => px_trans_rec.desc_flex.attribute11,
300                        X_Attribute12                    => px_trans_rec.desc_flex.attribute12,
301                        X_Attribute13                    => px_trans_rec.desc_flex.attribute13,
302                        X_Attribute14                    => px_trans_rec.desc_flex.attribute14,
303                        X_Attribute15                    => px_trans_rec.desc_flex.attribute15,
304                        X_Attribute_Category_Code        => px_trans_rec.desc_flex.attribute_category_code,
305                        X_Transaction_Key                => l_transaction_key,
306                        X_Amortization_Start_Date        => NULL,
307                        X_Calling_Interface              => px_trans_rec.calling_interface,
308                        X_Mass_Transaction_ID            => px_trans_rec.mass_transaction_id,
309                        X_member_transaction_header_id   => px_trans_rec.member_transaction_header_id,
310                        X_event_id                       => px_trans_rec.event_id,
311                        X_Return_Status                  => l_status,
312                        X_Calling_Fn                     => l_calling_fn,
313                        p_log_level_rec                  => p_log_level_rec);
314 
315       if not l_status then
316          raise unp_err;
317       end if;
318 
319    end if;  -- primary book
320 
321    if not FA_UTILS_PKG.faxrnd
322             (X_amount => l_unplanned_amount,
323              X_book   => p_asset_hdr_rec.book_type_code,
324              X_set_of_books_id => p_asset_hdr_rec.set_of_books_id,
325              p_log_level_rec => p_log_level_rec) then
326       raise unp_err;
327    end if;
328 
329 
330    -- If the processed asset is the member asset whose tracking method is 'ALLOCATE',
331    -- system should not process the amortization for the member level.
332 
333    -- Bug 5506943/5695201 Allowing for Allocate also.
334 
335    if (l_asset_fin_rec.group_asset_id is null) or
336       (l_asset_fin_rec.group_asset_id is not null and
337        nvl(l_asset_fin_rec.tracking_method,'OTHER') <> 'OTHER') then
338 
339       l_asset_deprn_rec_adj.deprn_amount := p_unplanned_deprn_rec.unplanned_amount;
340 
341       if (px_trans_rec.transaction_subtype = 'AMORTIZED') then
342 
343          if (p_log_level_rec.statement_level) then
344             fa_debug_pkg.add(l_calling_fn, 'Calling', 'FA_AMORT_PVT.calc_raf_adj_cost', p_log_level_rec => p_log_level_rec);
345             fa_debug_pkg.add(l_calling_fn, 'before adj cap', l_asset_fin_rec.adjusted_capacity, p_log_level_rec => p_log_level_rec);
346             fa_debug_pkg.add(l_calling_fn, 'before adj rsv old', p_asset_deprn_rec.deprn_reserve, p_log_level_rec => p_log_level_rec);
347          end if;
348 
349          if not FA_AMORT_PVT.calc_raf_adj_cost
350                     (p_trans_rec           => px_trans_rec,
351                      p_asset_hdr_rec       => p_asset_hdr_rec,
352                      p_asset_desc_rec      => p_asset_desc_rec,
353                      p_asset_type_rec      => p_asset_type_rec,
354                      p_asset_fin_rec_old   => p_asset_fin_rec,
355                      px_asset_fin_rec_new  => l_asset_fin_rec,
356                      p_asset_deprn_rec_adj => l_asset_deprn_rec_adj,
357                      p_asset_deprn_rec_new => p_asset_deprn_rec,
358                      p_period_rec          => p_period_rec,
359                      p_group_reclass_options_rec => l_group_reclass_options_rec,
360                      p_mrc_sob_type_code   => p_mrc_sob_type_code,
361                      p_log_level_rec       => p_log_level_rec) then
362             if (p_log_level_rec.statement_level) then
363                fa_debug_pkg.add(l_calling_fn, 'Failed calling', 'FA_AMORT_PVT.calc_raf_adj_cost', p_log_level_rec => p_log_level_rec);
364             end if;
365 
366             raise unp_err;
367          end if;
368 
369          if (p_log_level_rec.statement_level) then
370             fa_debug_pkg.add(l_calling_fn, 'after adj cap', l_asset_fin_rec.adjusted_capacity, p_log_level_rec => p_log_level_rec);
371             fa_debug_pkg.add(l_calling_fn, 'End Calling', 'FA_AMORT_PVT.calc_raf_adj_cost', p_log_level_rec => p_log_level_rec);
372          end if;
373 
374          -- no need to insert any catchup as we're already inserting
375          -- the value provided... so skipping call to faxiat
376 
377       end if;  -- end amortize
378 
379       l_asset_fin_rec.adjustment_required_status := 'NONE';
380 
381       l_temp_raf := l_asset_fin_rec.rate_adjustment_factor;
382 
383       ----------------------------------------------
384       -- Call Depreciable Basis Rule
385       -- for Unplanned Depreciation
386       ----------------------------------------------
387       if (not FA_CALC_DEPRN_BASIS1_PKG.CALL_DEPRN_BASIS
388                (
389                 p_event_type             => 'UNPLANNED_ADJ',
390                 p_asset_fin_rec_new      => p_asset_fin_rec,
391                 p_asset_fin_rec_old      => p_asset_fin_rec,
392                 p_asset_hdr_rec          => p_asset_hdr_rec,
393                 p_asset_type_rec         => p_asset_type_rec,
394                 p_asset_deprn_rec        => p_asset_deprn_rec,
395                 p_trans_rec              => px_trans_rec,
396                 p_period_rec             => p_period_rec,
397                 p_unplanned_deprn_rec    => p_unplanned_deprn_rec,
398                 p_mrc_sob_type_code      => p_mrc_sob_type_code,
399                 px_new_adjusted_cost     => l_asset_fin_rec.adjusted_cost,
400                 px_new_raf               => l_asset_fin_rec.rate_adjustment_factor,
401                 px_new_formula_factor    => l_asset_fin_rec.formula_factor,
402                 p_log_level_rec          => p_log_level_rec
403                 )) then
404          raise unp_err;
405       end if;
406 
407       -- Deprn basis function has been called in calc_raf_adj above so
408       -- do not call deprn basis function if it's been called
409       -- In Addition to the above case,
410       -- ENERGY
411       -- Replace raf with the raf returned by faxama call.
412       -- If this asset is:
413       --  1. Member of Energy Straight line group
414       --  2. tracking method is calculate
415       --  This is because raf is set in previous faxama call.
416       --  Also, above depreciable basis call was made without hypo amounts that
417       --  is mandatory for raf calculation.
418       if ((l_asset_fin_rec.group_asset_id is null and
419            px_trans_rec.transaction_subtype = 'AMORTIZED' and
420            p_asset_type_rec.asset_type = 'GROUP'))
421              or
422          ((p_asset_type_rec.asset_type <> 'GROUP') and
423           (l_asset_fin_rec.group_asset_id is not null) and
424           (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE') and
425           (nvl(l_asset_fin_rec.tracking_method, 'NO TRACK') = 'CALCULATE')) then
426 
427          l_asset_fin_rec.rate_adjustment_factor := l_temp_raf;
428 
429       end if;
430 
431       if (l_unplanned_amount <> 0) then
432          l_asset_fin_rec.period_counter_fully_reserved := NULL;
433       end if;
434 
435       l_asset_fin_rec.period_counter_life_complete := l_asset_fin_rec.period_counter_fully_reserved;
436 
437       -- terminate the row
438       fa_books_pkg.deactivate_row
439         (X_asset_id                  => p_asset_hdr_rec.asset_id,
440          X_book_type_code            => p_asset_hdr_rec.book_type_code,
441          X_transaction_header_id_out => px_trans_rec.transaction_header_id,
442          X_date_ineffective          => px_trans_rec.who_info.last_update_date,
443          X_mrc_sob_type_code         => p_mrc_sob_type_code,
444          X_set_of_books_id           => p_asset_hdr_rec.set_of_books_id,
445          X_Calling_Fn                => l_calling_fn,
446          p_log_level_rec             => p_log_level_rec);
447 
448       l_rowid := null;
449 
450       -- ENERGY
451       -- This is not only change for energy.  Allocation of unplanned amount must be done in
452       -- process group adjustment in case of large number of member assets exist for a group.
453       -- A condition refering 'ENERGY PERIOD END BALANCE' can be removed from rel 12.
454       if (px_trans_rec.calling_interface = 'FAXASSET') and
455          (l_asset_fin_rec.group_asset_id is null and
456           nvl(l_asset_fin_rec.tracking_method, 'NO TRACK') = 'ALLOCATE')
457          and (fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE')
458          then
459          l_asset_fin_rec.adjustment_required_status := 'GADJ';
460 
461          if (p_mrc_sob_type_code <> 'R') then
462             if not fa_xla_events_pvt.update_transaction_event
463                 (p_ledger_id              => p_asset_hdr_rec.set_of_books_id,
464                  p_transaction_header_id  => px_trans_rec.transaction_header_id,
465                  p_book_type_code         => p_asset_hdr_rec.book_type_code,
466                  p_event_type_code        => 'UNPLANNED_DEPRECIATION',
467                  p_event_date             => px_trans_rec.transaction_date_entered, --?
468                  p_event_status_code      => fa_xla_events_pvt.C_EVENT_INCOMPLETE,
469                  p_calling_fn             => l_calling_fn,
470                  p_log_level_rec          => p_log_level_rec) then
471                raise unp_err;
472             end if;
473          end if;
474       end if;
475 
476 
477       -- insert the row
478       fa_books_pkg.insert_row
479          (X_Rowid                        => l_rowid,
480           X_Book_Type_Code               => p_asset_hdr_rec.book_type_code,
481           X_Asset_Id                     => p_asset_hdr_rec.asset_id,
482           X_Date_Placed_In_Service       => l_asset_fin_rec.date_placed_in_service,
483           X_Date_Effective               => px_trans_rec.who_info.last_update_date,
484           X_Deprn_Start_Date             => l_asset_fin_rec.deprn_start_date,
485           X_Deprn_Method_Code            => l_asset_fin_rec.deprn_method_code,
486           X_Life_In_Months               => l_asset_fin_rec.life_in_months,
487           X_Rate_Adjustment_Factor       => l_asset_fin_rec.rate_adjustment_factor,
488           X_Adjusted_Cost                => l_asset_fin_rec.adjusted_cost,
489           X_Cost                         => l_asset_fin_rec.cost,
490           X_Original_Cost                => l_asset_fin_rec.original_cost,
491           X_Salvage_Value                => l_asset_fin_rec.salvage_value,
492           X_Prorate_Convention_Code      => l_asset_fin_rec.prorate_convention_code,
493           X_Prorate_Date                 => l_asset_fin_rec.prorate_date,
494           X_Cost_Change_Flag             => l_asset_fin_rec.cost_change_flag,
495           X_Adjustment_Required_Status   => l_asset_fin_rec.adjustment_required_status,
496           X_Capitalize_Flag              => l_asset_fin_rec.capitalize_flag,
497           X_Retirement_Pending_Flag      => l_asset_fin_rec.retirement_pending_flag,
498           X_Depreciate_Flag              => l_asset_fin_rec.depreciate_flag,
499           X_Disabled_Flag                => l_asset_fin_rec.disabled_flag, --HH
500           X_Last_Update_Date             => px_trans_rec.who_info.last_update_date,
501           X_Last_Updated_By              => px_trans_rec.who_info.last_updated_by,
502           X_Date_Ineffective             => NULL,
503           X_Transaction_Header_Id_In     => px_trans_rec.transaction_header_id,
504           X_Transaction_Header_Id_Out    => NULL,
505           X_Itc_Amount_Id                => l_asset_fin_rec.itc_amount_id,
506           X_Itc_Amount                   => l_asset_fin_rec.itc_amount,
507           X_Retirement_Id                => l_asset_fin_rec.retirement_id,
508           X_Tax_Request_Id               => l_asset_fin_rec.tax_request_id,
509           X_Itc_Basis                    => l_asset_fin_rec.itc_basis,
510           X_Basic_Rate                   => l_asset_fin_rec.basic_rate,
511           X_Adjusted_Rate                => l_asset_fin_rec.adjusted_rate,
512           X_Bonus_Rule                   => l_asset_fin_rec.bonus_rule,
513           X_Ceiling_Name                 => l_asset_fin_rec.ceiling_name,
514           X_Recoverable_Cost             => l_asset_fin_rec.recoverable_cost,
515           X_Last_Update_Login            => px_trans_rec.who_info.last_update_login,
516           X_Adjusted_Capacity            => l_asset_fin_rec.adjusted_capacity,
517           X_Fully_Rsvd_Revals_Counter    => l_asset_fin_rec.fully_rsvd_revals_counter,
518           X_Idled_Flag                   => l_asset_fin_rec.idled_flag,
519           X_Period_Counter_Capitalized   => l_asset_fin_rec.period_counter_capitalized,
520           X_PC_Fully_Reserved            => l_asset_fin_rec.period_counter_fully_reserved,
521           X_Period_Counter_Fully_Retired => l_asset_fin_rec.period_counter_fully_retired,
522           X_Production_Capacity          => l_asset_fin_rec.production_capacity,
523           X_Reval_Amortization_Basis     => l_asset_fin_rec.reval_amortization_basis,
524           X_Reval_Ceiling                => l_asset_fin_rec.reval_ceiling,
525           X_Unit_Of_Measure              => l_asset_fin_rec.unit_of_measure,
526           X_Unrevalued_Cost              => l_asset_fin_rec.unrevalued_cost,
527           X_Annual_Deprn_Rounding_Flag   => l_rounding_flag,
528           X_Percent_Salvage_Value        => l_asset_fin_rec.percent_salvage_value,
529           X_Allowed_Deprn_Limit          => l_asset_fin_rec.allowed_deprn_limit,
530           X_Allowed_Deprn_Limit_Amount   => l_asset_fin_rec.allowed_deprn_limit_amount,
531           X_Period_Counter_Life_Complete => l_asset_fin_rec.period_counter_life_complete,
532           X_Adjusted_Recoverable_Cost    => l_asset_fin_rec.adjusted_recoverable_cost,
533           X_Short_Fiscal_Year_Flag       => l_asset_fin_rec.short_fiscal_year_flag,
534           X_Conversion_Date              => l_asset_fin_rec.conversion_date,
535           X_Orig_Deprn_Start_Date        => l_asset_fin_rec.orig_deprn_start_date,
536           X_Remaining_Life1              => l_asset_fin_rec.remaining_life1,
537           X_Remaining_Life2              => l_asset_fin_rec.remaining_life2,
538           X_Old_Adj_Cost                 => l_asset_fin_rec.old_adjusted_cost,
539           X_Formula_Factor               => l_asset_fin_rec.formula_factor,
540           X_gf_Attribute1                => l_asset_fin_rec.global_attribute1,
541           X_gf_Attribute2                => l_asset_fin_rec.global_attribute2,
542           X_gf_Attribute3                => l_asset_fin_rec.global_attribute3,
543           X_gf_Attribute4                => l_asset_fin_rec.global_attribute4,
544           X_gf_Attribute5                => l_asset_fin_rec.global_attribute5,
545           X_gf_Attribute6                => l_asset_fin_rec.global_attribute6,
546           X_gf_Attribute7                => l_asset_fin_rec.global_attribute7,
547           X_gf_Attribute8                => l_asset_fin_rec.global_attribute8,
548           X_gf_Attribute9                => l_asset_fin_rec.global_attribute9,
549           X_gf_Attribute10               => l_asset_fin_rec.global_attribute10,
550           X_gf_Attribute11               => l_asset_fin_rec.global_attribute11,
551           X_gf_Attribute12               => l_asset_fin_rec.global_attribute12,
552           X_gf_Attribute13               => l_asset_fin_rec.global_attribute13,
553           X_gf_Attribute14               => l_asset_fin_rec.global_attribute14,
554           X_gf_Attribute15               => l_asset_fin_rec.global_attribute15,
555           X_gf_Attribute16               => l_asset_fin_rec.global_attribute16,
556           X_gf_Attribute17               => l_asset_fin_rec.global_attribute17,
557           X_gf_Attribute18               => l_asset_fin_rec.global_attribute18,
558           X_gf_Attribute19               => l_asset_fin_rec.global_attribute19,
559           X_gf_Attribute20               => l_asset_fin_rec.global_attribute20,
560           X_global_attribute_category    => l_asset_fin_rec.global_attribute_category,
561           X_group_asset_id               => l_asset_fin_rec.group_asset_id,
562           X_salvage_type                 => l_asset_fin_rec.salvage_type,
563           X_deprn_limit_type             => l_asset_fin_rec.deprn_limit_type,
564           X_over_depreciate_option       => l_asset_fin_rec.over_depreciate_option,
565           X_super_group_id               => l_asset_fin_rec.super_group_id,
566           X_reduction_rate               => l_asset_fin_rec.reduction_rate,
567           X_reduce_addition_flag         => l_asset_fin_rec.reduce_addition_flag,
568           X_reduce_adjustment_flag       => l_asset_fin_rec.reduce_adjustment_flag,
569           X_reduce_retirement_flag       => l_asset_fin_rec.reduce_retirement_flag,
570           X_recognize_gain_loss          => l_asset_fin_rec.recognize_gain_loss,
571           X_recapture_reserve_flag       => l_asset_fin_rec.recapture_reserve_flag,
572           X_limit_proceeds_flag          => l_asset_fin_rec.limit_proceeds_flag,
573           X_terminal_gain_loss           => l_asset_fin_rec.terminal_gain_loss,
574           X_exclude_proceeds_from_basis  => l_asset_fin_rec.exclude_proceeds_from_basis,
575           X_retirement_deprn_option      => l_asset_fin_rec.retirement_deprn_option,
576           X_tracking_method              => l_asset_fin_rec.tracking_method,
577           X_allocate_to_fully_rsv_flag   => l_asset_fin_rec.allocate_to_fully_rsv_flag,
578           X_allocate_to_fully_ret_flag   => l_asset_fin_rec.allocate_to_fully_ret_flag,
579           X_exclude_fully_rsv_flag       => l_asset_fin_rec.exclude_fully_rsv_flag,
580           X_excess_allocation_option     => l_asset_fin_rec.excess_allocation_option,
581           X_depreciation_option          => l_asset_fin_rec.depreciation_option,
582           X_member_rollup_flag           => l_asset_fin_rec.member_rollup_flag,
583           X_ytd_proceeds                 => l_asset_fin_rec.ytd_proceeds,
584           X_ltd_proceeds                 => l_asset_fin_rec.ltd_proceeds,
585           X_eofy_reserve                 => l_asset_fin_rec.eofy_reserve,
586           X_cip_cost                     => l_asset_fin_rec.cip_cost,
587           X_terminal_gain_loss_amount    => l_asset_fin_rec.terminal_gain_loss_amount,
588           X_ltd_cost_of_removal          => l_asset_fin_rec.ltd_cost_of_removal,
589           X_cash_generating_unit_id      => l_asset_fin_rec.cash_generating_unit_id,
590           X_extended_deprn_flag          => l_asset_fin_rec.extended_deprn_flag,
591           X_extended_depreciation_period => l_asset_fin_rec.extended_depreciation_period,
592           X_mrc_sob_type_code            => p_mrc_sob_type_code,
593           X_set_of_books_id              => p_asset_hdr_rec.set_of_books_id,
594           X_Return_Status                => l_status,
595           X_Calling_Fn                   => l_calling_fn,
596           p_log_level_rec => p_log_level_rec);
597 
598       if not l_status then
599          raise unp_err;
600       end if;
601 
602       -- Bug:5930979:Japan Tax Reform Project
603       if fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag = 'YES' then
604          if (p_mrc_sob_type_code <> 'R') then
605             FA_CDE_PKG.faxgfr (X_Book_Type_Code         => p_asset_hdr_rec.book_type_code,
606                                X_Asset_Id               => p_asset_hdr_rec.asset_id,
607                                X_Short_Fiscal_Year_Flag => l_asset_fin_rec.short_fiscal_year_flag,
608                                X_Conversion_Date        => l_asset_fin_rec.conversion_date,
609                                X_Prorate_Date           => l_asset_fin_rec.prorate_date,
610                                X_Orig_Deprn_Start_Date  => l_asset_fin_rec.orig_deprn_start_date,
611                                C_Prorate_Date           => NULL,
612                                C_Conversion_Date        => NULL,
613                                C_Orig_Deprn_Start_Date  => NULL,
614                                X_Method_Code            => l_asset_fin_rec.deprn_method_code,
615                                X_Life_In_Months         => l_asset_fin_rec.life_in_months,
616                                X_Fiscal_Year            => -99,
617                                X_Current_Period         => p_period_rec.period_counter,
618                                X_calling_interface      => 'UNPLANNED',
619                                X_Rate                   => l_rate_in_use,
620                                X_Method_Type            => l_method_type,
621                                X_Success                => l_success,
622                                p_log_level_rec          => p_log_level_rec);
623 
624             if (l_success <= 0) then
625                fa_srvr_msg.add_message(calling_fn => 'FA_UNPLANNED_PVT.do_unplanned', p_log_level_rec => p_log_level_rec);
626                raise unp_err;
627             end if;
628 
629             Update FA_BOOKS
630             Set rate_in_use = l_rate_in_use
631             Where book_type_code = p_asset_hdr_rec.book_type_code
632             And asset_id = p_asset_hdr_rec.asset_id
633             And date_ineffective is null;
634          end if;
635       end if;
636 
637       if (l_unplanned_amount > 0) then
638          l_debit_credit_flag := 'DR';
639          l_unplanned_amount  := l_unplanned_amount;
640       else
641          l_debit_credit_flag := 'CR';
642          l_unplanned_amount  := (-1) * l_unplanned_amount;
643       end if;
644 
645       l_adj.transaction_header_id    := px_trans_rec.transaction_header_id;
646       l_adj.asset_id                 := p_asset_hdr_rec.asset_id;
647       l_adj.book_type_code           := p_asset_hdr_rec.book_type_code;
648       l_adj.period_counter_created   := p_period_rec.period_counter;
649       l_adj.period_counter_adjusted  := p_period_rec.period_counter;
650       l_adj.current_units            := p_asset_desc_rec.current_units ;
651       l_adj.selection_mode           := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE;
652       l_adj.selection_thid           := 0;
653       l_adj.selection_retid          := 0;
654       l_adj.leveling_flag            := FALSE;
655       l_adj.last_update_date         := px_trans_rec.who_info.last_update_date;
656 
657       l_adj.flush_adj_flag           := TRUE;
658       l_adj.gen_ccid_flag            := FALSE;
659       l_adj.annualized_adjustment    := 0;
660       l_adj.asset_invoice_id         := 0;
661       l_adj.code_combination_id      := p_unplanned_deprn_rec.code_combination_id;
662       l_adj.distribution_id          := 0;
663 
664       l_adj.deprn_override_flag:= '';
665 
666       l_adj.source_type_code    := 'DEPRECIATION';
667       l_adj.adjustment_type     := 'EXPENSE';
668       l_adj.account             := FA_UNPLANNED_PUB.G_expense_account;
669       l_adj.account_type        := 'DEPRN_EXPENSE_ACCT';
670       l_adj.debit_credit_flag   := l_debit_credit_flag;
671       l_adj.adjustment_amount   := l_unplanned_amount;
672       l_adj.mrc_sob_type_code   := p_mrc_sob_type_code;
673       l_adj.set_of_books_id     := p_asset_hdr_rec.set_of_books_id;
674 
675       if (l_asset_fin_rec.group_asset_id is not null) and
676          (nvl(l_asset_fin_rec.member_rollup_flag, 'N') = 'N') then
677          l_adj.track_member_flag := 'Y';
678       else
679          l_adj.track_member_flag := null;
680       end if;
681 
682       if not FA_INS_ADJUST_PKG.faxinaj
683                (l_adj,
684                 px_trans_rec.who_info.last_update_date,
685                 px_trans_rec.who_info.last_updated_by,
686                 px_trans_rec.who_info.last_update_login,
687                 p_log_level_rec => p_log_level_rec
688                ) then
689          raise unp_err;
690       end if;
691       -- Bug 12917863 update adj cost in books row of fads so that it is not reset to original
692       -- if rollback is run in 11i
693       if p_asset_hdr_rec.period_of_addition = 'Y' then
694       --and G_release = 11)   /*removed the condition for Bug:13936080*/
695          FA_DEPRN_SUMMARY_PKG.Update_Row
696                         (X_Book_Type_Code                 => p_asset_hdr_rec.book_type_code,
697                          X_Asset_Id                       => p_asset_hdr_rec.asset_id,
698                          X_Adjusted_Cost                  => l_asset_fin_rec.adjusted_cost,
699 	  	         X_Period_Counter                 => FA_CACHE_PKG.fazcbc_record.last_period_counter,
700                          X_mrc_sob_type_code              => p_mrc_sob_type_code,
701 			 X_set_of_books_id                => p_asset_hdr_rec.set_of_books_id,
702                          X_Calling_Fn                     => l_calling_fn,
703 			 p_log_level_rec                  => p_log_level_rec
704                         );
705        END IF;
706    end if; -- check if the processed asset is not a member asset with ALLOCATE method
707 
708    return true;
709 
710 EXCEPTION
711    when unp_err then
712       fa_srvr_msg.add_message
713         (calling_fn => l_calling_fn,
714          p_log_level_rec => p_log_level_rec);
715       return false;
716 
717    when others then
718       fa_srvr_msg.add_sql_error
719         (calling_fn => l_calling_fn,
720          p_log_level_rec => p_log_level_rec);
721       return false;
722 
723 END do_unplanned;
724 
725 END FA_UNPLANNED_PVT;