[Home] [Help]
PACKAGE BODY: APPS.FA_ADDITION_PUB
Source
1 PACKAGE BODY FA_ADDITION_PUB AS
2 /* $Header: FAPADDB.pls 120.27.12010000.1 2008/07/28 13:12:45 appldev ship $ */
3
4 --*********************** Global constants *******************************--
5 G_PKG_NAME CONSTANT varchar2(30) := 'FA_ADDITION_PUB';
6 G_API_NAME CONSTANT varchar2(30) := 'Addition API';
7 G_API_VERSION CONSTANT number := 1.0;
8
9 g_log_level_rec fa_api_types.log_level_rec_type;
10
11 --*********************** Private procedures *****************************--
12
13 function do_all_books (
14 p_trans_rec IN fa_api_types.trans_rec_type,
15 p_primary_asset_hdr_rec IN fa_api_types.asset_hdr_rec_type,
16 p_primary_asset_fin_rec IN fa_api_types.asset_fin_rec_type,
17 p_primary_asset_deprn_rec IN fa_api_types.asset_deprn_rec_type,
18 p_report_asset_hdr_rec IN fa_api_types.asset_hdr_rec_type,
19 x_report_asset_fin_rec OUT NOCOPY fa_api_types.asset_fin_rec_type,
20 x_report_asset_deprn_rec OUT NOCOPY fa_api_types.asset_deprn_rec_type,
21 p_asset_fin_mrc_tbl IN fa_api_types.asset_fin_tbl_type,
22 p_asset_deprn_mrc_tbl IN fa_api_types.asset_deprn_tbl_type,
23 p_inv_tbl IN fa_api_types.inv_tbl_type,
24 x_exchange_rate OUT NOCOPY NUMBER,
25 x_return_status OUT NOCOPY VARCHAR2,
26 p_calling_fn IN VARCHAR2,
27 p_log_level_rec IN fa_api_types.log_level_rec_type default null) return boolean;
28
29 --*********************** Public procedures ******************************--
30 procedure do_addition (
31 -- Standard Parameters --
32 p_api_version IN NUMBER,
33 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
34 p_commit IN VARCHAR2 := FND_API.G_FALSE,
35 p_validation_level IN NUMBER :=FND_API.G_VALID_LEVEL_FULL,
36 x_return_status OUT NOCOPY VARCHAR2,
37 x_msg_count OUT NOCOPY NUMBER,
38 x_msg_data OUT NOCOPY VARCHAR2,
39 p_calling_fn IN VARCHAR2,
40 -- Transaction Object --
41 px_trans_rec IN OUT NOCOPY fa_api_types.trans_rec_type,
42 px_dist_trans_rec IN OUT NOCOPY fa_api_types.trans_rec_type,
43 -- Asset Object --
44 px_asset_hdr_rec IN OUT NOCOPY fa_api_types.asset_hdr_rec_type,
45 px_asset_desc_rec IN OUT NOCOPY fa_api_types.asset_desc_rec_type,
46 px_asset_type_rec IN OUT NOCOPY fa_api_types.asset_type_rec_type,
47 px_asset_cat_rec IN OUT NOCOPY fa_api_types.asset_cat_rec_type,
48 px_asset_hierarchy_rec IN OUT NOCOPY fa_api_types.asset_hierarchy_rec_type,
49 px_asset_fin_rec IN OUT NOCOPY fa_api_types.asset_fin_rec_type,
50 px_asset_deprn_rec IN OUT NOCOPY fa_api_types.asset_deprn_rec_type,
51 px_asset_dist_tbl IN OUT NOCOPY fa_api_types.asset_dist_tbl_type,
52 -- Invoice Object --
53 px_inv_tbl IN OUT NOCOPY fa_api_types.inv_tbl_type) as
54
55 add_err1 exception; -- sets return status
56 add_err2 exception; -- does not set return status
57 add_err3 exception; --Bug6391045
58 -- For corporate and tax books
59 l_trans_rec fa_api_types.trans_rec_type;
60 l_dist_trans_rec fa_api_types.trans_rec_type;
61 l_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
62 l_asset_fin_rec_old fa_api_types.asset_fin_rec_type;
63 l_asset_fin_rec fa_api_types.asset_fin_rec_type;
64 l_asset_fin_rec_new fa_api_types.asset_fin_rec_type;
65 l_asset_fin_mrc_tbl_new fa_api_types.asset_fin_tbl_type;
66 l_asset_deprn_rec_old fa_api_types.asset_deprn_rec_type;
67 l_asset_deprn_rec_new fa_api_types.asset_deprn_rec_type;
68 l_asset_deprn_mrc_tbl fa_api_types.asset_deprn_tbl_type;
69
70 l_inv_rec fa_api_types.inv_rec_type;
71 l_inv_trans_rec fa_api_types.inv_trans_rec_type;
72 l_period_rec fa_api_types.period_rec_type;
73
74 l_tax_book_tbl fa_cache_pkg.fazctbk_tbl_type;
75 l_initial_book boolean := TRUE;
76
77 -- For primary and reporting books
78 l_reporting_flag varchar2(1) := 'P';
79 l_rsob_tbl fa_cache_pkg.fazcrsob_sob_tbl_type;
80 l_mrc_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
81 l_mrc_asset_fin_rec_adj fa_api_types.asset_fin_rec_type;
82 l_mrc_asset_fin_rec_new fa_api_types.asset_fin_rec_type;
83 l_mrc_asset_deprn_rec_adj fa_api_types.asset_deprn_rec_type;
84 l_mrc_asset_deprn_rec_new fa_api_types.asset_deprn_rec_type;
85 l_exchange_rate number;
86 l_asset_hr_attr_rec_old FA_API_TYPES.asset_hr_attr_rec_type;
87 l_asset_hr_attr_rec_new FA_API_TYPES.asset_hr_attr_rec_type;
88
89 -- used to store original sob info upon entry into api
90 l_orig_set_of_books_id number;
91 l_orig_currency_context varchar2(64);
92
93 -- used for new group code
94 l_group_trans_rec fa_api_types.trans_rec_type;
95 l_group_asset_hdr_rec fa_api_types.asset_hdr_rec_type;
96 l_group_asset_desc_rec fa_api_types.asset_desc_rec_type;
97 l_group_asset_type_rec fa_api_types.asset_type_rec_type;
98 l_group_asset_cat_rec fa_api_types.asset_cat_rec_type;
99 l_group_asset_fin_rec_old fa_api_types.asset_fin_rec_type;
100 l_group_asset_fin_rec_adj fa_api_types.asset_fin_rec_type;
101 l_group_asset_fin_rec_new fa_api_types.asset_fin_rec_type;
102 l_group_asset_deprn_rec_old fa_api_types.asset_deprn_rec_type;
103 l_group_asset_deprn_rec_adj fa_api_types.asset_deprn_rec_type;
104 l_group_asset_deprn_rec_new fa_api_types.asset_deprn_rec_type;
105
106 l_group_reclass_options_rec fa_api_types.group_reclass_options_rec_type;
107
108 l_cip_cost number := 0;
109 l_calling_fn varchar2(30) := 'fa_addition_pub.do_addition';
110
111 begin
112
113 SAVEPOINT do_addition;
114 if (not g_log_level_rec.initialized) then
115 if (NOT fa_util_pub.get_log_level_rec (
116 x_log_level_rec => g_log_level_rec
117 )) then
118 raise add_err1;
119 end if;
120 end if;
121
122 -- Initialize message list if p_init_msg_list is set to TRUE.
123 if (fnd_api.to_boolean(p_init_msg_list)) then
124 -- initialize error message stack.
125 fa_srvr_msg.init_server_message;
126
127 -- initialize debug message stack.
128 fa_debug_pkg.initialize;
129 end if;
130
131 fnd_profile.get ('GL_SET_OF_BKS_ID',l_orig_set_of_books_id);
132 l_orig_currency_context := SUBSTRB(USERENV('CLIENT_INFO'),45,10);
133
134
135 -- Check version of the API
136 -- Standard call to check for API call compatibility.
137 if (NOT fnd_api.compatible_api_call (
138 G_API_VERSION,
139 p_api_version,
140 G_API_NAME,
141 G_PKG_NAME
142 )) then
143 raise add_err1;
144 end if;
145
146 -- Call the cache for the primary transaction book
147 if (NOT fa_cache_pkg.fazcbc (
148 X_book => px_asset_hdr_rec.book_type_code,
149 p_log_level_rec => g_log_level_rec)) then
150 raise add_err1;
151 end if;
152
153 -- Initialize the incoming values.
154 if (NOT fa_addition_pvt.initialize (
155 px_trans_rec => px_trans_rec,
156 px_dist_trans_rec => px_dist_trans_rec,
157 px_asset_hdr_rec => px_asset_hdr_rec,
158 px_asset_desc_rec => px_asset_desc_rec,
159 px_asset_type_rec => px_asset_type_rec,
160 px_asset_cat_rec => px_asset_cat_rec,
161 px_asset_hierarchy_rec => px_asset_hierarchy_rec,
162 px_asset_fin_rec => px_asset_fin_rec,
163 px_asset_deprn_rec => px_asset_deprn_rec,
164 px_asset_dist_tbl => px_asset_dist_tbl,
165 px_inv_tbl => px_inv_tbl,
166 x_return_status => x_return_status,
167 p_calling_fn => 'fa_addition_pub.do_addition',
168 p_log_level_rec => g_log_level_rec)) then
169 raise add_err2;
170 end if;
171
172 if (g_log_level_rec.statement_level) then
173 fa_debug_pkg.add('add after validate','allow_neg_nbv_type',
174 px_asset_fin_rec.over_depreciate_option,
175 p_log_level_rec => g_log_level_rec);
176 fa_debug_pkg.add('add after validate','px_asset_fin_rec.method',
177 px_asset_fin_rec.deprn_method_code
178 ,p_log_level_rec => g_log_level_rec);
179 end if;
180
181 -- this function will check if parent is valid, otherwise return false
182 -- check if override is allowed, otherwise return false
183 -- derive asset attributes
184 if px_asset_hierarchy_rec.parent_hierarchy_id is not null then
185 if NOT fa_asset_hierarchy_pvt.derive_asset_attribute (
186 px_asset_hdr_rec => px_asset_hdr_rec,
187 px_asset_desc_rec => px_asset_desc_rec,
188 px_asset_cat_rec => px_asset_cat_rec,
189 px_asset_hierarchy_rec => px_asset_hierarchy_rec,
190 px_asset_fin_rec => px_asset_fin_rec,
191 px_asset_dist_tbl => px_asset_dist_tbl,
192 p_derivation_type => 'ALL',
193 p_calling_function => 'fa_addition_pub.do_addition') then
194 raise add_err1;
195 end if;
196 end if;
197
198 -- Call the cache to get the dependent tax books
199 if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then
200 if (NOT fa_cache_pkg.fazctbk (
201 x_corp_book => px_asset_hdr_rec.book_type_code,
202 x_asset_type => px_asset_type_rec.asset_type,
203 x_tax_book_tbl => l_tax_book_tbl,
204 p_log_level_rec => g_log_level_rec)) then
205 raise add_err1;
206 end if;
207 end if;
208
209 for book_index in 0..l_tax_book_tbl.COUNT loop
210
211 l_asset_hdr_rec := px_asset_hdr_rec;
212 l_trans_rec := px_trans_rec;
213
214 -- BUG# 2417746 - populate the source_thid here for auto-copy
215 -- and cip-in-tax loops
216 if (book_index > 0) then
217 l_trans_rec.source_transaction_header_id :=
218 px_trans_rec.transaction_header_id;
219 end if;
220
221 -- Pop the transaction_header_id for the ADDITION row
222 select fa_transaction_headers_s.nextval
223 into l_trans_rec.transaction_header_id
224 from dual;
225
226 -- if the counter book_index is at 0, then process incoming
227 -- book else iterate through tax books
228 if (book_index = 0) then
229 l_asset_hdr_rec.book_type_code :=
230 px_asset_hdr_rec.book_type_code;
231
232 l_initial_book := TRUE;
233 else
234 l_asset_hdr_rec.book_type_code :=
235 l_tax_book_tbl(book_index);
236
237 l_initial_book := FALSE;
238 end if;
239
240 -- call the cache for the primary transaction book
241 if (NOT fa_cache_pkg.fazcbc (
242 X_book => l_asset_hdr_rec.book_type_code,
243 p_log_level_rec => g_log_level_rec)) then
244 raise add_err1;
245 end if;
246
247 l_asset_hdr_rec.set_of_books_id :=
248 fa_cache_pkg.fazcbc_record.set_of_books_id;
249
250 if (g_log_level_rec.statement_level) then
251 fa_debug_pkg.add('Corporate/Tax Book','c_t_book',
252 l_asset_hdr_rec.book_type_code
253 ,p_log_level_rec => g_log_level_rec);
254 end if;
255
256 -- Set the gl_sob profile to this book
257 fnd_profile.put('GL_SET_OF_BKS_ID', l_asset_hdr_rec.set_of_books_id);
258 fnd_client_info.set_currency_context (l_asset_hdr_rec.set_of_books_id);
259
260 if (NOT FA_UTIL_PVT.get_period_rec (
261 p_book => l_asset_hdr_rec.book_type_code,
262 p_effective_date => NULL,
263 x_period_rec => l_period_rec,
264 p_log_level_rec => g_log_level_rec)) then
265 raise add_err1;
266 end if;
267
268 if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then
269 -- Set the transaction_header_id for the corp book for later.
270 px_trans_rec.transaction_header_id :=
271 l_trans_rec.transaction_header_id;
272
273 -- For the TRANSFER IN row, thid is shared for all corp/tax books.
274 select fa_transaction_headers_s.nextval
275 into px_dist_trans_rec.transaction_header_id
276 from dual;
277
278 -- Set the current fin_rec to the one that was passed in.
279 l_asset_fin_rec := px_asset_fin_rec;
280 l_asset_deprn_rec_new := px_asset_deprn_rec;
281 else
282 -- Check to see if the source_transaction_header_id need to be
283 -- populated. BMR: removing this code as we should only
284 -- populate for trxs where the tax trx is spawned automatically
285 -- from corp (either via cip-in-tax, autocopy, masscopy)
286 -- ... old code ... see BUG# 2417746 for more details
287
288 -- If this is a tax book and was the initial book passed, then we
289 -- to set fin_rec to what was passed in. The initialize function
290 -- will have already handled everything.
291 if (l_initial_book = TRUE) then
292 l_asset_fin_rec := px_asset_fin_rec;
293 --Bug 6377492
294 px_trans_rec.transaction_header_id := l_trans_rec.transaction_header_id;
295 else
296 -- Otherwise we need to clear fin_rec and deprn_rec of everything
297 -- except cost and let calc engine determine everything.
298 l_asset_fin_rec := NULL;
299 l_asset_deprn_rec_new := NULL;
300
301 -- Initialize the incoming values.
302 if (NOT fa_addition_pvt.initialize (
303 px_trans_rec => l_trans_rec,
304 px_dist_trans_rec => px_dist_trans_rec,
305 px_asset_hdr_rec => l_asset_hdr_rec,
306 px_asset_desc_rec => px_asset_desc_rec,
307 px_asset_type_rec => px_asset_type_rec,
308 px_asset_cat_rec => px_asset_cat_rec,
309 px_asset_hierarchy_rec => px_asset_hierarchy_rec,
310 px_asset_fin_rec => l_asset_fin_rec,
311 px_asset_deprn_rec => l_asset_deprn_rec_new,
312 px_asset_dist_tbl => px_asset_dist_tbl,
316 p_log_level_rec => g_log_level_rec)) then
313 px_inv_tbl => px_inv_tbl,
314 x_return_status => x_return_status,
315 p_calling_fn => 'fa_addition_pub.do_addition',
317 raise add_err2;
318 end if;
319
320 if (px_asset_type_rec.asset_type = 'GROUP') then
321 l_asset_fin_rec.cost := 0;
322 -- HH group ed. Also set disabled_flag to Null as we
323 -- want group assets added w/ the flag null.
324 l_asset_fin_rec.disabled_flag := NULL; -- end HH
325
326 l_asset_fin_rec.over_depreciate_option := px_asset_fin_rec.over_depreciate_option;
327 l_asset_fin_rec.super_group_id := px_asset_fin_rec.super_group_id;
328 l_asset_fin_rec.reduction_rate := px_asset_fin_rec.reduction_rate;
329 l_asset_fin_rec.reduce_addition_flag := px_asset_fin_rec.reduce_addition_flag;
330 l_asset_fin_rec.reduce_adjustment_flag := px_asset_fin_rec.reduce_adjustment_flag;
331 l_asset_fin_rec.reduce_retirement_flag := px_asset_fin_rec.reduce_retirement_flag;
332 l_asset_fin_rec.recognize_gain_loss := px_asset_fin_rec.recognize_gain_loss;
333 l_asset_fin_rec.recapture_reserve_flag := px_asset_fin_rec.recapture_reserve_flag;
334 l_asset_fin_rec.limit_proceeds_flag := px_asset_fin_rec.limit_proceeds_flag;
335 l_asset_fin_rec.terminal_gain_loss := px_asset_fin_rec.terminal_gain_loss;
336 l_asset_fin_rec.tracking_method := px_asset_fin_rec.tracking_method;
337 l_asset_fin_rec.exclude_fully_rsv_flag := px_asset_fin_rec.exclude_fully_rsv_flag;
338 l_asset_fin_rec.excess_allocation_option := px_asset_fin_rec.excess_allocation_option;
339 l_asset_fin_rec.depreciation_option := px_asset_fin_rec.depreciation_option;
340 l_asset_fin_rec.member_rollup_flag := px_asset_fin_rec.member_rollup_flag;
341 l_asset_fin_rec.allocate_to_fully_rsv_flag := px_asset_fin_rec.allocate_to_fully_rsv_flag;
342 l_asset_fin_rec.allocate_to_fully_ret_flag := px_asset_fin_rec.allocate_to_fully_ret_flag;
343
344 else
345 l_asset_fin_rec.cost := px_asset_fin_rec.cost;
346 end if;
347
348 end if;
349 end if;
350
351 if (g_log_level_rec.statement_level) then
352 fa_debug_pkg.add('add before validate','allow_neg_nbv_type',
353 l_asset_fin_rec.over_depreciate_option
354 ,p_log_level_rec => g_log_level_rec);
355 end if;
356
357 if (p_validation_level = FND_API.G_VALID_LEVEL_FULL) then
358
359 if (g_log_level_rec.statement_level) then
360 fa_debug_pkg.add('add before validate','asset_type',
361 px_asset_type_rec.asset_type
362 ,p_log_level_rec => g_log_level_rec);
363 fa_debug_pkg.add('add before validate','trx_type',
364 l_trans_rec.transaction_type_code
365 ,p_log_level_rec => g_log_level_rec);
366 end if;
367
368
369 -- Complete the initial validation of the asset.
370 if (NOT fa_asset_val_pvt.validate (
371 p_trans_rec => l_trans_rec,
372 p_asset_hdr_rec => l_asset_hdr_rec,
373 p_asset_desc_rec => px_asset_desc_rec,
374 p_asset_type_rec => px_asset_type_rec,
375 p_asset_cat_rec => px_asset_cat_rec,
376 p_asset_fin_rec => l_asset_fin_rec,
377 p_asset_deprn_rec => px_asset_deprn_rec,
378 p_asset_dist_tbl => px_asset_dist_tbl,
379 p_inv_tbl => px_inv_tbl,
380 p_calling_fn => 'fa_addition_pub.do_addition',
381 p_log_level_rec => g_log_level_rec)) then
382 raise add_err1;
383 end if;
384 end if;
385
386 if (g_log_level_rec.statement_level) then
387 fa_debug_pkg.add('add after validate','allow_neg_nbv_type',
388 l_asset_fin_rec.over_depreciate_option
389 ,p_log_level_rec => g_log_level_rec);
390 end if;
391
392 -- Determine the asset_number if it was not provided
393 if (px_asset_desc_rec.asset_number is null) then
394 px_asset_desc_rec.asset_number :=
395 to_char (px_asset_hdr_rec.asset_id);
396 end if;
397
398 -- Process invoices if they exist
399 -- ignore group assets that might be coming from mass additions
400 -- as we don't want the invoice info maintained
401
402 if (px_inv_tbl.count > 0) and
403 (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') and
404 (px_asset_type_rec.asset_type <> 'GROUP')then
405
406 if (l_trans_rec.calling_interface = 'FAMAPT') then
407 l_inv_trans_rec.transaction_type := 'MASS ADDITION';
408 else
409 l_inv_trans_rec.transaction_type := 'INVOICE ADDITION';
410 end if;
411
412 if (NOT fa_invoice_pvt.invoice_engine (
413 px_trans_rec => l_trans_rec,
414 px_asset_hdr_rec => l_asset_hdr_rec,
415 p_asset_desc_rec => px_asset_desc_rec,
419 x_asset_fin_rec_new => l_asset_fin_rec_new,
416 p_asset_type_rec => px_asset_type_rec,
417 p_asset_cat_rec => px_asset_cat_rec,
418 p_asset_fin_rec_adj => l_asset_fin_rec,
420 x_asset_fin_mrc_tbl_new => l_asset_fin_mrc_tbl_new,
421 px_inv_trans_rec => l_inv_trans_rec,
422 px_inv_tbl => px_inv_tbl,
423 x_asset_deprn_rec_new => l_asset_deprn_rec_new,
424 x_asset_deprn_mrc_tbl_new => l_asset_deprn_mrc_tbl,
425 p_calling_fn => 'fa_addition_pub.do_addition',
426 p_log_level_rec => g_log_level_rec)) then
427 raise add_err1;
428 end if;
429
430 l_cip_cost := l_asset_fin_rec_new.cip_cost;
431
432 -- Need to account for case from FAXASSET if source
433 -- lines were added through Detail Addition w/ no cost.
434 if ((l_asset_fin_rec_new.cost = 0) and
435 (px_asset_fin_rec.cost <> 0)) then
436 l_asset_fin_rec_new := l_asset_fin_rec;
437 l_asset_deprn_rec_new := px_asset_deprn_rec;
438 l_asset_fin_mrc_tbl_new.delete;
439 l_asset_deprn_mrc_tbl.delete;
440 end if;
441 else
442 -- Need to set the new rec to the old rec so we
443 -- are passing the same recs in for both non invoices
444 -- and assets w/ invoices.
445 l_asset_fin_rec_new := l_asset_fin_rec;
446 l_asset_deprn_rec_new := px_asset_deprn_rec;
447
448 end if;
449
450
451 if (px_asset_type_rec.asset_type <> 'CIP') then
452 l_asset_fin_rec_new.cip_cost := 0;
453 elsif (nvl(fa_cache_pkg.fazcbc_record.allow_cip_dep_group_flag, 'N') = 'Y') then
454 l_asset_fin_rec_new.cip_cost := l_cip_cost;
455 else
456 l_asset_fin_rec_new.cip_cost := l_asset_fin_rec_new.cost;
457 end if;
458
459
460 if (g_log_level_rec.statement_level) then
461 fa_debug_pkg.add('add after inv engine','allow_neg_nbv_type',
462 l_asset_fin_rec_new.over_depreciate_option
463 ,p_log_level_rec => g_log_level_rec);
464 fa_debug_pkg.add('add after inv engine','l_asset_fin_rec.method',
465 l_asset_fin_rec.deprn_method_code
466 ,p_log_level_rec => g_log_level_rec);
467
468 end if;
469
470 if (g_log_level_rec.statement_level) then
471 fa_debug_pkg.add('Book','l_asset_hdr_rec.book_type_code',
472 l_asset_hdr_rec.book_type_code
473 ,p_log_level_rec => g_log_level_rec);
474 fa_debug_pkg.add('SOB','l_asset_hdr_rec.set_of_books_id',
475 to_char (l_asset_hdr_rec.set_of_books_id),g_log_level_rec);
476 end if;
477
478 -- Call cache to verify whether this is a primary or reporting book
479 if (NOT fa_cache_pkg.fazcsob (
480 X_set_of_books_id => l_asset_hdr_rec.set_of_books_id,
481 X_mrc_sob_type_code => l_reporting_flag,
482 p_log_level_rec => g_log_level_rec)) then
483 raise add_err1;
484 end if;
485
486 -- Call the reporting books cache to get rep books.
487 if (l_reporting_flag <> 'R') then
488 if (NOT fa_cache_pkg.fazcrsob (
489 x_book_type_code => l_asset_hdr_rec.book_type_code,
490 x_sob_tbl => l_rsob_tbl,
491 p_log_level_rec => g_log_level_rec)) then
492 raise add_err1;
493 end if;
494 end if;
495
496 for mrc_index in 0..l_rsob_tbl.COUNT loop
497
498 l_mrc_asset_hdr_rec := l_asset_hdr_rec;
499
500 -- if the counter mrc_index is at 0, then process incoming
501 -- book else iterate through reporting books
502 if (mrc_index = 0) then
503 l_mrc_asset_hdr_rec.set_of_books_id :=
504 l_asset_hdr_rec.set_of_books_id;
505 else
506 l_mrc_asset_hdr_rec.set_of_books_id :=
507 l_rsob_tbl(mrc_index);
508 l_reporting_flag := 'R';
509 end if;
510
511 -- Set the gl_sob profile to this reporting book
512 fnd_profile.put('GL_SET_OF_BKS_ID',
513 l_mrc_asset_hdr_rec.set_of_books_id);
514 fnd_client_info.set_currency_context (
515 l_mrc_asset_hdr_rec.set_of_books_id);
516
517 -- Need to always call fazcbcs
518 if (NOT fa_cache_pkg.fazcbcs (
519 X_book => l_mrc_asset_hdr_rec.book_type_code,
520 p_log_level_rec => g_log_level_rec)) then
521 raise add_err1;
522 end if;
523
524 -- call transaction approval for primary books only
525 -- Will probably need to break this into an MRC wrapper thing
526 if (l_reporting_flag <> 'R') then
527 if (px_asset_type_rec.asset_type = 'GROUP') then
528 l_trans_rec.transaction_key := 'GA';
529 end if;
530
531 -- call this for first bookonly if not a mass trx which
532 -- would have already called trx approval
533 if (nvl(fnd_global.conc_request_id, -1) <= 0) then
534 if (NOT fa_trx_approval_pkg.faxcat (
535 X_book => l_mrc_asset_hdr_rec.book_type_code,
536 X_asset_id => l_mrc_asset_hdr_rec.asset_id,
540 p_log_level_rec => g_log_level_rec)) then
537 X_trx_type => l_trans_rec.transaction_type_code,
538 X_trx_date => l_trans_rec.transaction_date_entered,
539 X_init_message_flag => 'NO',
541 raise add_err1;
542 end if;
543 end if;
544
545 -- Need to assign the primary financial info to the current
546 -- mrc placeholder variables.
547 l_mrc_asset_fin_rec_new := l_asset_fin_rec_new;
548 l_mrc_asset_deprn_rec_new := l_asset_deprn_rec_new;
549 else
550 -- Logic for reporting book.
551 if (NOT do_all_books (
552 p_trans_rec => l_trans_rec,
553 p_primary_asset_hdr_rec => l_asset_hdr_rec,
554 p_primary_asset_fin_rec => l_asset_fin_rec_new,
555 p_primary_asset_deprn_rec => l_asset_deprn_rec_new,
556 p_report_asset_hdr_rec => l_mrc_asset_hdr_rec,
557 x_report_asset_fin_rec => l_mrc_asset_fin_rec_new,
558 x_report_asset_deprn_rec => l_mrc_asset_deprn_rec_new,
559 p_asset_fin_mrc_tbl => l_asset_fin_mrc_tbl_new,
560 p_asset_deprn_mrc_tbl => l_asset_deprn_mrc_tbl,
561 p_inv_tbl => px_inv_tbl,
562 x_exchange_rate => l_exchange_rate,
563 x_return_status => x_return_status,
564 p_calling_fn => 'fa_addition_pub.do_addition',
565 p_log_level_rec => g_log_level_rec)) then
566 raise add_err1;
567 end if;
568 end if;
569
570 -- Fix for Bug #2653564. Do no pass same record group to two
571 -- different parameters, one of which is an OUT parameter.
572 l_mrc_asset_fin_rec_adj := l_mrc_asset_fin_rec_new;
573 l_mrc_asset_deprn_rec_adj := l_mrc_asset_deprn_rec_new;
574
575 if (g_log_level_rec.statement_level) then
576 fa_debug_pkg.add('add before calc engine','allow_neg_nbv_type',
577 l_mrc_asset_fin_rec_new.over_depreciate_option
578 ,p_log_level_rec => g_log_level_rec);
579 fa_debug_pkg.add('add before calc engine','l_asset_fin_rec_old.method',
580 l_asset_fin_rec_old.deprn_method_code
581 ,p_log_level_rec => g_log_level_rec);
582 fa_debug_pkg.add('add before calc engine','l_mrc_asset_fin_rec_adj.method',
583 l_mrc_asset_fin_rec_adj.deprn_method_code
584 ,p_log_level_rec => g_log_level_rec);
585 fa_debug_pkg.add('add before calc engine','l_mrc_asset_fin_rec_new.method',
586 l_mrc_asset_fin_rec_new.deprn_method_code
587 ,p_log_level_rec => g_log_level_rec);
588 end if;
589
590
591 -- Calculate intermediate variables.
592 if (NOT fa_asset_calc_pvt.calc_fin_info (
593 px_trans_rec => l_trans_rec,
594 p_inv_trans_rec => l_inv_trans_rec,
595 p_asset_hdr_rec => l_mrc_asset_hdr_rec,
596 p_asset_desc_rec => px_asset_desc_rec,
597 p_asset_type_rec => px_asset_type_rec,
598 p_asset_cat_rec => px_asset_cat_rec,
599 p_asset_fin_rec_old => l_asset_fin_rec_old,
600 p_asset_fin_rec_adj => l_mrc_asset_fin_rec_adj,
601 px_asset_fin_rec_new => l_mrc_asset_fin_rec_new,
602 p_asset_deprn_rec_old => l_asset_deprn_rec_old,
603 p_asset_deprn_rec_adj => l_mrc_asset_deprn_rec_adj,
604 px_asset_deprn_rec_new => l_mrc_asset_deprn_rec_new,
605 p_period_rec => l_period_rec,
606 p_mrc_sob_type_code => l_reporting_flag,
607 p_group_reclass_options_rec => l_group_reclass_options_rec,
608 p_calling_fn => 'fa_addition_pub.do_addition',
609 p_log_level_rec => g_log_level_rec)) then
610 raise add_err1;
611 end if;
612
613 if (g_log_level_rec.statement_level) then
614 fa_debug_pkg.add('add after calc engine','allow_neg_nbv_type',
615 l_mrc_asset_fin_rec_new.over_depreciate_option
616 ,p_log_level_rec => g_log_level_rec);
617 fa_debug_pkg.add('add after calc engine','l_asset_fin_rec_old.method',
618 l_asset_fin_rec_old.deprn_method_code
619 ,p_log_level_rec => g_log_level_rec);
620 fa_debug_pkg.add('add after calc engine','l_mrc_asset_fin_rec_adj.method',
621 l_mrc_asset_fin_rec_adj.deprn_method_code
622 ,p_log_level_rec => g_log_level_rec);
623 fa_debug_pkg.add('add after calc engine','l_mrc_asset_fin_rec_new.method',
624 l_mrc_asset_fin_rec_new.deprn_method_code
625 ,p_log_level_rec => g_log_level_rec);
626 end if;
627
628 -- If this is the corp primary book, we need to store the revised
629 -- data back in the original recs.
630 if ((fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') AND
631 (l_reporting_flag <> 'R')) then
632 px_asset_fin_rec := l_mrc_asset_fin_rec_new;
633 end if;
634
635 -- BUG#2797309 / BUG#3485177
636 -- Do not set amortization_start_date for non-cip assets
637 if (px_asset_type_rec.asset_type = 'CIP' and
638 l_mrc_asset_fin_rec_new.group_asset_id is null) then
639 l_trans_rec.amortization_start_date := NULL;
640 else
641 -- BUG# 2815608
645 l_trans_rec.transaction_subtype := 'AMORTIZED';
642 -- adding the following logic to set amortize subtype and date
643 -- if not provided, it is defaulted to DPIS - BMR
644 if (l_mrc_asset_fin_rec_new.group_asset_id is not null) then
646 if (l_trans_rec.amortization_start_date is null) then
647 l_trans_rec.amortization_start_date :=
648 l_asset_fin_rec_new.date_placed_in_service;
649 end if;
650 end if;
651 end if;
652
653 -- SLA
654 -- faxcde will result in null expense if prior fy expense
655 -- is null... set to 0.
656
657 if (l_mrc_asset_deprn_rec_new.prior_fy_expense is null) then
658 l_mrc_asset_deprn_rec_new.prior_fy_expense := 0;
659 end if;
660
661
662 if (NOT fa_addition_pvt.insert_asset (
663 p_trans_rec => l_trans_rec,
664 p_dist_trans_rec => px_dist_trans_rec,
665 p_asset_hdr_rec => l_mrc_asset_hdr_rec,
666 p_asset_desc_rec => px_asset_desc_rec,
667 p_asset_type_rec => px_asset_type_rec,
668 p_asset_cat_rec => px_asset_cat_rec,
669 p_asset_hierarchy_rec => px_asset_hierarchy_rec,
670 p_asset_fin_rec => l_mrc_asset_fin_rec_new,
671 p_asset_deprn_rec => l_mrc_asset_deprn_rec_new,
672 px_asset_dist_tbl => px_asset_dist_tbl,
673 p_inv_trans_rec => l_inv_trans_rec,
674 p_primary_cost => l_asset_fin_rec_new.cost,
675 p_exchange_rate => l_exchange_rate,
676 x_return_status => x_return_status,
677 p_mrc_sob_type_code => l_reporting_flag,
678 p_period_rec => l_period_rec,
679 p_calling_fn => 'fa_addition_pub.do_addition',
680 p_log_level_rec => g_log_level_rec)) then
681 raise add_err2;
682 end if;
683
684 -- call the group api
685 if (l_mrc_asset_fin_rec_new.group_asset_id is not null) then
686
687
688 if (l_reporting_flag <> 'R') then
689
690 -- set up the group recs
691 l_group_asset_hdr_rec := l_mrc_asset_hdr_rec;
692 l_group_asset_hdr_rec.asset_id := l_mrc_asset_fin_rec_new.group_asset_id;
693 l_group_trans_rec := l_trans_rec; -- will set the amort start date (will inherit the event id from member too)
694 l_group_trans_rec.transaction_key := 'MA';
695
696 if not FA_UTIL_PVT.get_asset_desc_rec
697 (p_asset_hdr_rec => l_group_asset_hdr_rec,
698 px_asset_desc_rec => l_group_asset_desc_rec,
699 p_log_level_rec => g_log_level_rec) then
700 raise add_err1;
701 end if;
702
703 if not FA_UTIL_PVT.get_asset_cat_rec
704 (p_asset_hdr_rec => l_group_asset_hdr_rec,
705 px_asset_cat_rec => l_group_asset_cat_rec,
706 p_date_effective => null,
707 p_log_level_rec => g_log_level_rec) then
708 raise add_err1;
709 end if;
710
711 if not FA_UTIL_PVT.get_asset_type_rec
712 (p_asset_hdr_rec => l_group_asset_hdr_rec,
713 px_asset_type_rec => l_group_asset_type_rec,
714 p_date_effective => null,
715 p_log_level_rec => g_log_level_rec) then
716 raise add_err1;
717 end if;
718
719 if not FA_ASSET_VAL_PVT.validate_period_of_addition
720 (p_asset_id => l_group_asset_hdr_rec.asset_id,
721 p_book => l_group_asset_hdr_rec.book_type_code,
722 p_mode => 'ABSOLUTE',
723 px_period_of_addition => l_group_asset_hdr_rec.period_of_addition,
724 p_log_level_rec => g_log_level_rec) then
725 raise add_err1;
726 end if;
727
728 l_group_trans_rec.transaction_type_code := 'GROUP ADJUSTMENT';
729 l_group_trans_rec.member_transaction_header_id := l_trans_rec.transaction_header_id;
730
731 if (NOT fa_trx_approval_pkg.faxcat
732 (X_book => l_group_asset_hdr_rec.book_type_code,
733 X_asset_id => l_group_asset_hdr_rec.asset_id,
734 X_trx_type => l_group_trans_rec.transaction_type_code,
735 X_trx_date => l_group_trans_rec.transaction_date_entered,
736 X_init_message_flag => 'NO',
737 p_log_level_rec => g_log_level_rec)) then
738 raise add_err1;
739 end if;
740
741
742 l_group_trans_rec.transaction_subtype := 'AMORTIZED';
743
744 select fa_transaction_headers_s.nextval
745 into l_group_trans_rec.transaction_header_id
746 from dual;
747
748 end if;
749
753 px_asset_fin_rec => l_group_asset_fin_rec_old,
750 -- load the old structs
751 if not FA_UTIL_PVT.get_asset_fin_rec
752 (p_asset_hdr_rec => l_group_asset_hdr_rec,
754 p_transaction_header_id => NULL,
755 p_mrc_sob_type_code => l_reporting_flag,
756 p_log_level_rec => g_log_level_rec) then raise add_err1;
757 end if;
758
759 --HH Validate disabled_flag
760 --We don't want to perform any transaction on a disabled group.
761 if not FA_ASSET_VAL_PVT.validate_disabled_flag
762 (p_group_asset_id => l_group_asset_hdr_rec.asset_id,
763 p_book_type_code => l_group_asset_hdr_rec.book_type_code,
764 p_old_flag => l_group_asset_fin_rec_old.disabled_flag,
765 p_new_flag => l_group_asset_fin_rec_old.disabled_flag,
766 p_log_level_rec => g_log_level_rec) then
767 raise add_err1;
768 end if; --End HH
769
770 if not FA_UTIL_PVT.get_asset_deprn_rec
771 (p_asset_hdr_rec => l_group_asset_hdr_rec ,
772 px_asset_deprn_rec => l_group_asset_deprn_rec_old,
773 p_period_counter => NULL,
774 p_mrc_sob_type_code => l_reporting_flag,
775 p_log_level_rec => g_log_level_rec) then raise add_err1;
776 end if;
777
778 if (g_log_level_rec.statement_level) then
779 fa_debug_pkg.add('add before grp adj call','l_mrc_asset_fin_rec_new.cip_cost',
780 l_mrc_asset_fin_rec_new.cip_cost
781 ,p_log_level_rec => g_log_level_rec);
782 fa_debug_pkg.add('add before grp adj call','l_mrc_asset_fin_rec_new.cost',
783 l_mrc_asset_fin_rec_new.cost
784 ,p_log_level_rec => g_log_level_rec);
785 end if;
786
787 -- copy the delta cost if any into the group's fin_rec
788 if (px_asset_type_rec.asset_type = 'CIP') then
789
790 if (fa_cache_pkg.fazcbc_record.allow_cip_dep_group_flag = 'Y') then
791 l_group_asset_fin_rec_adj.cip_cost := nvl(l_mrc_asset_fin_rec_new.cip_cost, 0);
792 l_group_asset_fin_rec_adj.cost := nvl(l_mrc_asset_fin_rec_new.cost, 0) - nvl(l_mrc_asset_fin_rec_new.cip_cost, 0);
793 else
794 l_group_asset_fin_rec_adj.cip_cost := nvl(l_mrc_asset_fin_rec_new.cip_cost, 0);
795 end if;
796 else
797 l_group_asset_fin_rec_adj.cost := nvl(l_mrc_asset_fin_rec_new.cost, 0);
798 l_group_asset_fin_rec_adj.salvage_value :=
799 nvl(l_mrc_asset_fin_rec_new.salvage_value, 0) -
800 nvl(l_asset_fin_rec_old.salvage_value, 0);
801 l_group_asset_fin_rec_adj.allowed_deprn_limit_amount :=
802 nvl(l_mrc_asset_fin_rec_new.allowed_deprn_limit_amount, 0) -
803 nvl(l_asset_fin_rec_old.allowed_deprn_limit_amount, 0);
804 end if;
805
806 if not FA_ADJUSTMENT_PVT.do_adjustment
807 (px_trans_rec => l_group_trans_rec,
808 px_asset_hdr_rec => l_group_asset_hdr_rec,
809 p_asset_desc_rec => l_group_asset_desc_rec,
810 p_asset_type_rec => l_group_asset_type_rec,
811 p_asset_cat_rec => l_group_asset_cat_rec,
812 p_asset_fin_rec_old => l_group_asset_fin_rec_old,
813 p_asset_fin_rec_adj => l_group_asset_fin_rec_adj,
814 x_asset_fin_rec_new => l_group_asset_fin_rec_new,
815 p_inv_trans_rec => l_inv_trans_rec,
816 p_asset_deprn_rec_old => l_group_asset_deprn_rec_old,
817 p_asset_deprn_rec_adj => l_group_asset_deprn_rec_adj,
818 x_asset_deprn_rec_new => l_group_asset_deprn_rec_new,
819 p_period_rec => l_period_rec,
820 p_mrc_sob_type_code => l_reporting_flag,
821 p_group_reclass_options_rec =>l_group_reclass_options_rec,
822 p_calling_fn => 'fa_addition_pub.do_addition',
823 p_log_level_rec => g_log_level_rec)then
824 raise add_err1;
825 end if; -- do_adjustment
826 end if; -- group asset id not null
827
828
829 -- add asset to the Asset Hierarchy for CORP book
830 if ((fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') AND
831 (l_reporting_flag <> 'R')) then
832 if px_asset_hierarchy_rec.parent_hierarchy_id is not null then
833 if not fa_asset_hierarchy_pvt.add_asset(
834 p_asset_hdr_rec => l_mrc_asset_hdr_rec,
835 p_asset_hierarchy_rec => px_asset_hierarchy_rec) then
836 -- p_calling_fn => 'fa_addition_pub.do_addition') then
837
838 raise add_err1;
839 end if;
840 end if;
841 end if;
842 end loop;
843
844 -- BUG# 2376085
845 -- reset GL sob id to original value before moving to next book
846 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
847 fnd_client_info.set_currency_context (l_orig_currency_context);
848
849 end loop;
850
851 -- call to workflow business event
852
853 fa_business_events.raise(p_event_name => 'oracle.apps.fa.addition.asset.add',
854 p_event_key => px_asset_hdr_rec.asset_id || to_char(sysdate,'RRDDDSSSSS'),
855 p_parameter_name1 => 'ASSET_ID',
856 p_parameter_value1 => px_asset_hdr_rec.asset_id,
857 p_parameter_name2 => 'ASSET_NUMBER',
858 p_parameter_value2 => px_asset_desc_rec.asset_number,
859 p_parameter_name3 => 'BOOK_TYPE_CODE',
860 p_parameter_value3 => l_asset_hdr_rec.book_type_code,
861 p_log_level_rec => g_log_level_rec);
862
863 if cse_fa_integration_grp.is_oat_enabled then
864 if not cse_fa_integration_grp.addition(
865 p_trans_rec => l_trans_rec,
866 p_asset_hdr_rec => l_asset_hdr_rec,
867 p_asset_desc_rec => px_asset_desc_rec,
868 p_asset_fin_rec => l_asset_fin_rec,
869 p_asset_dist_tbl => px_asset_dist_tbl,
870 p_inv_tbl => px_inv_tbl) then
871 raise add_err1;
872 end if;
873 end if;
874 -- Bug 6391045
875 -- Code hook for IAC
876
877 if (FA_IGI_EXT_PKG.IAC_Enabled) then
878 if not FA_IGI_EXT_PKG.Do_Addition(
879 p_trans_rec => l_trans_rec,
880 p_asset_hdr_rec => l_asset_hdr_rec,
881 p_asset_cat_rec => px_asset_cat_rec,
882 p_asset_desc_rec => px_asset_desc_rec,
883 p_asset_fin_rec => l_asset_fin_rec,
884 p_asset_deprn_rec => px_asset_deprn_rec,
885 p_asset_type_rec => px_asset_type_rec,
886 p_calling_function => l_calling_fn) then
887 raise add_err3;
888 end if;
889
890
891
892
893 end if; -- (FA_IGI_EXT_PKG.IAC_Enabled)
894
895 -- commit if p_commit is TRUE.
896 if (fnd_api.to_boolean (p_commit)) then
897 COMMIT WORK;
898 end if;
899
900 -- Reset the gl_sob profile
901 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
902 fnd_client_info.set_currency_context (l_orig_currency_context);
903
904 -- Standard call to get message count and if count is 1 get message info.
905 fnd_msg_pub.count_and_get (
906 p_count => x_msg_count,
907 p_data => x_msg_data
908 );
909
910 x_return_status := FND_API.G_RET_STS_SUCCESS;
911
912 exception
913 when add_err1 then
914
915 ROLLBACK TO do_addition;
916
917 -- set back to original environment when the procedure is finished
918 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
919 fnd_client_info.set_currency_context (l_orig_currency_context);
920
921 fa_srvr_msg.add_message
922 (calling_fn => 'fa_addition_pub.do_addition'
923 ,p_log_level_rec => g_log_level_rec);
924
925 FND_MSG_PUB.count_and_get (
926 p_count => x_msg_count,
927 p_data => x_msg_data
928 );
929
930 x_return_status := FND_API.G_RET_STS_ERROR;
931
932
933 when add_err2 then
934
935 ROLLBACK TO do_addition;
936
937 -- set back to original environment when the procedure is finished
938 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
939 fnd_client_info.set_currency_context (l_orig_currency_context);
940
941 fa_srvr_msg.add_message
942 (calling_fn => 'fa_addition_pub.do_addition'
943 ,p_log_level_rec => g_log_level_rec);
944
945 FND_MSG_PUB.count_and_get (
946 p_count => x_msg_count,
947 p_data => x_msg_data
948 );
949 --Bug 6391045
950 when add_err3 then
951
952 ROLLBACK TO do_addition;
953
954 -- set back to original environment when the procedure is finished
955 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
956 fnd_client_info.set_currency_context (l_orig_currency_context);
957
958 fa_srvr_msg.add_message(calling_fn => l_calling_fn
959 ,p_log_level_rec => g_log_level_rec);
960
961 FND_MSG_PUB.count_and_get (
962 p_count => x_msg_count,
963 p_data => x_msg_data
964 );
965
966 x_return_status := FND_API.G_RET_STS_ERROR;
967
968 --Bug6391045 ends
969 when others then
970
971 ROLLBACK TO do_addition;
972
976
973 -- set back to original environment when the procedure is finished
974 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
975 fnd_client_info.set_currency_context (l_orig_currency_context);
977 fa_srvr_msg.add_sql_error
978 (calling_fn => 'fa_addition_pub.do_addition'
979 ,p_log_level_rec => g_log_level_rec);
980
981 FND_MSG_PUB.count_and_get (
982 p_count => x_msg_count,
983 p_data => x_msg_data
984 );
985
986 x_return_status := FND_API.G_RET_STS_ERROR;
987
988 end do_addition;
989
990 function do_all_books (
991 p_trans_rec IN fa_api_types.trans_rec_type,
992 p_primary_asset_hdr_rec IN fa_api_types.asset_hdr_rec_type,
993 p_primary_asset_fin_rec IN fa_api_types.asset_fin_rec_type,
994 p_primary_asset_deprn_rec IN fa_api_types.asset_deprn_rec_type,
995 p_report_asset_hdr_rec IN fa_api_types.asset_hdr_rec_type,
996 x_report_asset_fin_rec OUT NOCOPY fa_api_types.asset_fin_rec_type,
997 x_report_asset_deprn_rec OUT NOCOPY fa_api_types.asset_deprn_rec_type,
998 p_asset_fin_mrc_tbl IN fa_api_types.asset_fin_tbl_type,
999 p_asset_deprn_mrc_tbl IN fa_api_types.asset_deprn_tbl_type,
1000 p_inv_tbl IN fa_api_types.inv_tbl_type,
1001 x_exchange_rate OUT NOCOPY NUMBER,
1002 x_return_status OUT NOCOPY VARCHAR2,
1003 p_calling_fn IN VARCHAR2,
1004 p_log_level_rec IN fa_api_types.log_level_rec_type default null) return boolean as
1005
1006 l_count number;
1007 l_mrc_populated boolean := FALSE;
1008 l_exchange_date date;
1009 l_exchange_rate number;
1010
1011 all_books_err exception;
1012
1013 begin
1014
1015 -- Initialize
1016 x_exchange_rate := NULL;
1017
1018 -- Determine the correct currency records
1019 for i in 1..p_asset_fin_mrc_tbl.COUNT loop
1020 l_count := i;
1021
1022 if (p_asset_fin_mrc_tbl(i).set_of_books_id =
1023 p_report_asset_hdr_rec.set_of_books_id) then
1024
1025 l_mrc_populated := TRUE;
1026 exit;
1027 else
1028 l_mrc_populated := FALSE;
1029 end if;
1030 end loop;
1031
1032 if (l_mrc_populated = TRUE) then
1033 x_report_asset_fin_rec := p_asset_fin_mrc_tbl(l_count);
1034 end if;
1035
1036 -- Determine exchange rate if there are invoices. For invoices, we
1037 -- always use the primary cost divided by the reporting cost.
1038 if ((p_inv_tbl.count > 0) and (l_mrc_populated)) then
1039 begin
1040 -- Exchange rate is then the cost of the reporting_book divided by
1041 -- the cost of the primary book.
1042 x_exchange_rate := x_report_asset_fin_rec.cost /
1043 p_primary_asset_fin_rec.cost;
1044 exception
1045 when zero_divide then
1046 x_exchange_rate := NULL;
1047 end;
1048 end if;
1049
1050 -- For a tax book, we need to use the rate from the corporate book
1051 -- if it is not a manual transaction.
1052 if (p_trans_rec.source_transaction_header_id is not null and
1053 fa_cache_pkg.fazcbc_record.book_class = 'TAX') then
1054 if not FA_MC_UTIL_PVT.get_existing_rate
1055 (p_set_of_books_id => p_report_asset_hdr_rec.set_of_books_id,
1056 p_transaction_header_id => p_trans_rec.source_transaction_header_id,
1057 px_rate => l_exchange_rate,
1058 px_avg_exchange_rate => x_exchange_rate,
1059 p_log_level_rec => p_log_level_rec) then
1060
1061 -- rate not found (corp may not have the same reporting option)
1062 -- get the current average rate for the addition
1063 l_exchange_date := p_trans_rec.transaction_date_entered;
1064
1065 if not FA_MC_UTIL_PVT.get_trx_rate
1066 (p_prim_set_of_books_id => p_primary_asset_hdr_rec.set_of_books_id,
1067 p_reporting_set_of_books_id => p_report_asset_hdr_rec.set_of_books_id,
1068 px_exchange_date => l_exchange_date,
1069 p_book_type_code => p_report_asset_hdr_rec.book_type_code,
1070 px_rate => x_exchange_rate,
1071 p_log_level_rec => p_log_level_rec)then
1072 raise all_books_err;
1073 end if;
1074 end if;
1075 else
1076 -- get the rate directly from gl if no invoices involved
1077 if (x_exchange_rate is null) then
1078
1079 l_exchange_date := p_trans_rec.transaction_date_entered;
1080
1081 if (NOT fa_mc_util_pvt.get_trx_rate (
1082 p_prim_set_of_books_id => p_primary_asset_hdr_rec.set_of_books_id,
1083 p_reporting_set_of_books_id => p_report_asset_hdr_rec.set_of_books_id,
1084 px_exchange_date => l_exchange_date,
1085 p_book_type_code => p_report_asset_hdr_rec.book_type_code,
1086 px_rate => x_exchange_rate,
1087 p_log_level_rec => p_log_level_rec)) then
1088 raise all_books_err;
1089 end if;
1090 end if;
1091 end if;
1092
1093 if (x_exchange_rate is null) then
1094 raise all_books_err;
1095 end if;
1099 if (l_mrc_populated = FALSE) then
1096
1097 -- If no fin_rec was found for the reporting sob, we'll have to calculate
1098 -- it manually by use the primary fin_rec and exchange rate.
1100
1101 -- Initialize values
1102 x_report_asset_fin_rec := p_primary_asset_fin_rec;
1103 x_report_asset_fin_rec.set_of_books_id :=
1104 p_report_asset_hdr_rec.set_of_books_id;
1105
1106 -- Convert the non-derived financial amounts using the retrieved
1107 -- rate. All other amounts will be handled by the calculation
1108 -- engines (rec cost, etc)
1109 x_report_asset_fin_rec.cost :=
1110 p_primary_asset_fin_rec.cost * x_exchange_rate;
1111 x_report_asset_fin_rec.unrevalued_cost :=
1112 p_primary_asset_fin_rec.unrevalued_cost * x_exchange_rate;
1113 x_report_asset_fin_rec.salvage_value :=
1114 p_primary_asset_fin_rec.salvage_value * x_exchange_rate;
1115 x_report_asset_fin_rec.original_cost :=
1116 p_primary_asset_fin_rec.original_cost * x_exchange_rate;
1117 x_report_asset_fin_rec.cip_cost :=
1118 p_primary_asset_fin_rec.cip_cost * x_exchange_rate;
1119
1120
1121 -- Round the converted amounts
1122 if (NOT fa_utils_pkg.faxrnd (
1123 x_amount => x_report_asset_fin_rec.cost,
1124 x_book => p_report_asset_hdr_rec.book_type_code,
1125 p_log_level_rec => p_log_level_rec)) then
1126 raise all_books_err;
1127 end if;
1128
1129 if (NOT fa_utils_pkg.faxrnd (
1130 x_amount => x_report_asset_fin_rec.unrevalued_cost,
1131 x_book => p_report_asset_hdr_rec.book_type_code,
1132 p_log_level_rec => p_log_level_rec)) then
1133 raise all_books_err;
1134 end if;
1135
1136 if (NOT fa_utils_pkg.faxrnd (
1137 x_amount => x_report_asset_fin_rec.salvage_value,
1138 x_book => p_report_asset_hdr_rec.book_type_code,
1139 p_log_level_rec => p_log_level_rec)) then
1140 raise all_books_err;
1141 end if;
1142
1143 if (NOT fa_utils_pkg.faxrnd (
1144 x_amount => x_report_asset_fin_rec.original_cost,
1145 x_book => p_report_asset_hdr_rec.book_type_code,
1146 p_log_level_rec => p_log_level_rec)) then
1147 raise all_books_err;
1148 end if;
1149
1150 if (NOT fa_utils_pkg.faxrnd (
1151 x_amount => x_report_asset_fin_rec.cip_cost,
1152 x_book => p_report_asset_hdr_rec.book_type_code,
1153 p_log_level_rec => p_log_level_rec)) then
1154 raise all_books_err;
1155 end if;
1156
1157 end if;
1158
1159 for i in 1..p_asset_deprn_mrc_tbl.COUNT loop
1160 l_count := i;
1161
1162 if (p_asset_deprn_mrc_tbl(i).set_of_books_id =
1163 p_report_asset_hdr_rec.set_of_books_id) then
1164
1165 l_mrc_populated := TRUE;
1166 exit;
1167 else
1168 l_mrc_populated := FALSE;
1169 end if;
1170 end loop;
1171
1172 if (l_mrc_populated = TRUE) then
1173 x_report_asset_deprn_rec := p_asset_deprn_mrc_tbl(l_count);
1174 else
1175 -- Initialize values
1176 x_report_asset_deprn_rec := p_primary_asset_deprn_rec;
1177 x_report_asset_deprn_rec.set_of_books_id :=
1178 p_report_asset_hdr_rec.set_of_books_id;
1179
1180 -- Convert the non-derived financial amounts using the retrieved
1181 -- rate. All other amounts will be handled by the calculation
1182 -- engines (rec cost, etc)
1183 x_report_asset_deprn_rec.deprn_reserve :=
1184 p_primary_asset_deprn_rec.deprn_reserve * x_exchange_rate;
1185 x_report_asset_deprn_rec.ytd_deprn :=
1186 p_primary_asset_deprn_rec.ytd_deprn * x_exchange_rate;
1187 x_report_asset_deprn_rec.bonus_deprn_reserve :=
1188 p_primary_asset_deprn_rec.bonus_deprn_reserve * x_exchange_rate;
1189 x_report_asset_deprn_rec.bonus_ytd_deprn :=
1190 p_primary_asset_deprn_rec.bonus_ytd_deprn * x_exchange_rate;
1191 x_report_asset_deprn_rec.reval_deprn_reserve :=
1192 p_primary_asset_deprn_rec.reval_deprn_reserve * x_exchange_rate;
1193
1194 -- Round the converted amounts
1195 if (NOT fa_utils_pkg.faxrnd (
1196 x_amount => x_report_asset_deprn_rec.deprn_reserve,
1197 x_book => p_report_asset_hdr_rec.book_type_code,
1198 p_log_level_rec => p_log_level_rec)) then
1199 raise all_books_err;
1200 end if;
1201
1202 if (NOT fa_utils_pkg.faxrnd (
1203 x_amount => x_report_asset_deprn_rec.ytd_deprn,
1204 x_book => p_report_asset_hdr_rec.book_type_code,
1205 p_log_level_rec => p_log_level_rec)) then
1206 raise all_books_err;
1207 end if;
1208
1209 if (NOT fa_utils_pkg.faxrnd (
1210 x_amount => x_report_asset_deprn_rec.bonus_deprn_reserve,
1211 x_book => p_report_asset_hdr_rec.book_type_code,
1212 p_log_level_rec => p_log_level_rec)) then
1213 raise all_books_err;
1214 end if;
1215
1216 if (NOT fa_utils_pkg.faxrnd (
1217 x_amount => x_report_asset_deprn_rec.bonus_ytd_deprn,
1218 x_book => p_report_asset_hdr_rec.book_type_code,
1219 p_log_level_rec => p_log_level_rec)) then
1220 raise all_books_err;
1221 end if;
1222
1223 if (NOT fa_utils_pkg.faxrnd (
1227 raise all_books_err;
1224 x_amount => x_report_asset_deprn_rec.reval_deprn_reserve,
1225 x_book => p_report_asset_hdr_rec.book_type_code,
1226 p_log_level_rec => p_log_level_rec)) then
1228 end if;
1229 end if;
1230
1231 return TRUE;
1232
1233 exception
1234 when all_books_err then
1235 fa_srvr_msg.add_message(
1236 calling_fn => 'fa_addition_pub.do_all_books'
1237 ,p_log_level_rec => p_log_level_rec);
1238 x_return_status := FND_API.G_RET_STS_ERROR;
1239
1240 return FALSE;
1241 when others then
1242 fa_srvr_msg.add_sql_error(
1243 calling_fn => 'fa_addition_pub.do_all_books'
1244 ,p_log_level_rec => p_log_level_rec);
1245 x_return_status := FND_API.G_RET_STS_ERROR;
1246
1247 return FALSE;
1248 end do_all_books;
1249
1250 END FA_ADDITION_PUB;