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