[Home] [Help]
PACKAGE BODY: APPS.FA_UNPLANNED_PUB
Source
1 PACKAGE BODY FA_UNPLANNED_PUB as
2 /* $Header: FAPUNPLB.pls 120.17 2006/05/08 14:41:26 vtandon noship $ */
3
4 --*********************** Global constants ******************************--
5
6 G_PKG_NAME CONSTANT varchar2(30) := 'FA_UNPLANNED_PUB';
7 G_API_NAME CONSTANT varchar2(30) := 'Unplanned API';
8 G_API_VERSION CONSTANT number := 1.0;
9
10 g_log_level_rec fa_api_types.log_level_rec_type;
11
12 --*********************** Private functions ******************************--
13
14 -- private declaration for books (mrc) wrapper
15
16 FUNCTION do_all_books
17 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
18 px_asset_hdr_rec IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
19 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
20 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
21 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
22 p_unplanned_deprn_rec IN FA_API_TYPES.unplanned_deprn_rec_type,
23 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN;
24
25
26 --*********************** Public procedures ******************************--
27
28 PROCEDURE do_unplanned
29 (p_api_version IN NUMBER,
30 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
31 p_commit IN VARCHAR2 := FND_API.G_FALSE,
32 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
33 p_calling_fn IN VARCHAR2 := NULL,
34 x_return_status OUT NOCOPY VARCHAR2,
35 x_msg_count OUT NOCOPY NUMBER,
36 x_msg_data OUT NOCOPY VARCHAR2,
37 px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
38 px_asset_hdr_rec IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
39 p_unplanned_deprn_rec IN FA_API_TYPES.unplanned_deprn_rec_type) IS
40
41 l_asset_desc_rec FA_API_TYPES.asset_desc_rec_type;
42 l_asset_type_rec FA_API_TYPES.asset_type_rec_type;
43 l_asset_cat_rec FA_API_TYPES.asset_cat_rec_type;
44
45 l_orig_set_of_books_id number;
46 l_orig_currency_context varchar2(64);
47
48 l_reporting_flag VARCHAR2(1);
49
50 l_calling_fn VARCHAR2(35) := 'fa_unplanned_pub.do_unplanned';
51 unp_err EXCEPTION;
52
53 BEGIN
54
55 SAVEPOINT do_unplanned;
56
57 if (not g_log_level_rec.initialized) then
58 if (NOT fa_util_pub.get_log_level_rec (
59 x_log_level_rec => g_log_level_rec
60 )) then
61 raise unp_err;
62 end if;
63 end if;
64
65 -- Initialize message list if p_init_msg_list is set to TRUE.
66 if (fnd_api.to_boolean(p_init_msg_list)) then
67 -- initialize error message stack.
68 fa_srvr_msg.init_server_message;
69
70 -- initialize debug message stack.
71 fa_debug_pkg.initialize;
72 end if;
73
74 -- Check version of the API
75 -- Standard call to check for API call compatibility.
76 if NOT fnd_api.compatible_api_call (
77 G_API_VERSION,
78 p_api_version,
79 G_API_NAME,
80 G_PKG_NAME) then
81 x_return_status := FND_API.G_RET_STS_ERROR;
82 raise unp_err;
83 end if;
84
85 -- set up sob/mrc info
86 -- call the cache for the primary transaction book
87 if (NOT fa_cache_pkg.fazcbc(X_book => px_asset_hdr_rec.book_type_code,
88 p_log_level_rec => g_log_level_rec)) then
89 raise unp_err;
90 end if;
91
92 px_asset_hdr_rec.set_of_books_id := fa_cache_pkg.fazcbc_record.set_of_books_id;
93
94 if not (FA_ASSET_VAL_PVT.validate_asset_book
95 (p_transaction_type_code => 'ADJUSTMENT',
96 p_book_type_code => px_asset_hdr_rec.book_type_code,
97 p_asset_id => px_asset_hdr_rec.asset_id,
98 p_calling_fn => l_calling_fn,
99 p_log_level_rec => g_log_level_rec)) then
100 raise unp_err;
101 end if;
102
103 -- get the current info for the primary book
104
105 FND_PROFILE.GET ('GL_SET_OF_BKS_ID',l_orig_set_of_books_id);
106 l_orig_currency_context := SUBSTRB(USERENV('CLIENT_INFO'),45,10);
107
108 fnd_profile.put('GL_SET_OF_BKS_ID', px_asset_hdr_rec.set_of_books_id);
109 fnd_client_info.set_currency_context (px_asset_hdr_rec.set_of_books_id);
110
111
112 -- Account for transaction submitted from a responsibility
113 -- that is not tied to a SOB_ID by getting the value from
114 -- the book struct
115
116 -- Get the book type code P,R or N
117 if not fa_cache_pkg.fazcsob
118 (X_set_of_books_id => px_asset_hdr_rec.set_of_books_id,
119 X_mrc_sob_type_code => l_reporting_flag,
120 p_log_level_rec => g_log_level_rec) then
121 raise unp_err;
122 end if;
123
124 -- Error out if the program is submitted from the Reporting Responsibility
125 -- No transaction permitted directly on reporting books.
126
127 IF l_reporting_flag = 'R' THEN
128 fa_srvr_msg.add_message
129 (NAME => 'MRC_OSP_INVALID_BOOK_TYPE',
130 CALLING_FN => l_calling_fn
131 ,p_log_level_rec => g_log_level_rec);
132 raise unp_err;
133 END IF;
134
135 -- end initial MRC validation
136
137
138 -- verify that the amortized type is populated and valid
139 if (p_unplanned_deprn_rec.unplanned_type is not null) then
140 if not FA_ASSET_VAL_PVT.validate_fa_lookup_code
141 (p_lookup_type => 'UNPLANNED DEPRN',
142 p_lookup_code => p_unplanned_deprn_rec.unplanned_type,
143 p_log_level_rec => g_log_level_rec) then
144 raise unp_err;
145 end if;
146 end if;
147
148 -- pop the asset type
149 if not FA_UTIL_PVT.get_asset_type_rec
150 (p_asset_hdr_rec => px_asset_hdr_rec,
151 px_asset_type_rec => l_asset_type_rec,
152 p_date_effective => null,
153 p_log_level_rec => g_log_level_rec) then
154 raise unp_err;
155 end if;
156
157 -- pop the asset category
158 if not FA_UTIL_PVT.get_asset_cat_rec
159 (p_asset_hdr_rec => px_asset_hdr_rec,
160 px_asset_cat_rec => l_asset_cat_rec,
161 p_date_effective => null,
162 p_log_level_rec => g_log_level_rec) then
163 raise unp_err;
164 end if;
165
166 -- pop the asset desc (needed for current units)
167 if not FA_UTIL_PVT.get_asset_desc_rec
168 (p_asset_hdr_rec => px_asset_hdr_rec,
169 px_asset_desc_rec => l_asset_desc_rec,
170 p_log_level_rec => g_log_level_rec) then
171 raise unp_err;
172 end if;
173
174 if (l_asset_type_rec.asset_type <> 'CAPITALIZED' and
175 l_asset_type_rec.asset_type <> 'GROUP') then
176 fa_srvr_msg.add_message
177 (name => '** NO_UNPLANNED_NON_CAP **',
178 calling_fn => l_calling_fn
179 ,p_log_level_rec => g_log_level_rec);
180 raise unp_err;
181 end if;
182
183
184
185 -- check / default the trx info
186 -- check the transaction_date
187
188 -- SLA Uptake
189 -- changing as period of addition is handled no differently
190
191 /*
192 if (px_asset_hdr_rec.period_of_addition = 'Y') then
193 if l_asset_type_rec.asset_type = 'GROUP' then
194 px_trans_rec.transaction_type_code := 'GROUP ADDITION';
195 else
196 px_trans_rec.transaction_type_code := 'ADDITION';
197 end if;
198 else
199 */
200 if l_asset_type_rec.asset_type = 'GROUP' then
201 px_trans_rec.transaction_type_code := 'GROUP ADJUSTMENT';
202 else
203 px_trans_rec.transaction_type_code := 'ADJUSTMENT';
204 end if;
205 -- end if;
206
207 if (px_trans_rec.transaction_subtype is null) then
208 px_trans_rec.transaction_subtype := 'EXPENSED';
209 end if;
210
211 -- but for group assets, we always amortize
212 -- SLA: obsolete
213 /*
214 if (l_asset_type_rec.asset_type = 'GROUP' and
215 px_asset_hdr_rec.period_of_addition <> 'Y') then
216 */
217 if (l_asset_type_rec.asset_type = 'GROUP') then
218 px_trans_rec.transaction_subtype := 'AMORTIZED';
219 end if;
220
221 -- set the subtype
222 if (px_trans_rec.transaction_subtype = 'AMORTIZED') then
223 px_trans_rec.transaction_key := 'UA';
224 else
225 px_trans_rec.transaction_key := 'UE';
226 end if;
227
228
229 -- check for prior amortizations/retirements
230 if (px_trans_rec.transaction_subtype <> 'AMORTIZED') then
231 if not FA_ASSET_VAL_PVT.validate_exp_after_amort
232 (p_asset_id => px_asset_hdr_rec.asset_id,
233 p_book => px_asset_hdr_rec.book_type_code,
234 p_log_level_rec => g_log_level_rec) then
235 raise unp_err;
236 end if;
237 else
238 if (fa_cache_pkg.fazcbc_record.amortize_flag = 'NO') then
239 fa_srvr_msg.add_message(
240 calling_fn => l_calling_fn,
241 name => 'FA_BOOK_AMORTIZED_NOT_ALLOW'
242 ,p_log_level_rec => g_log_level_rec);
243 raise unp_err;
244 end if;
245 end if;
246
247 if FA_ASSET_VAL_PVT.validate_fully_retired
248 (p_asset_id => px_asset_hdr_rec.asset_id,
249 p_book => px_asset_hdr_rec.book_type_code,
250 p_log_level_rec => g_log_level_rec) then
251 fa_srvr_msg.add_message
252 (name => 'FA_REC_RETIRED',
253 calling_fn => l_calling_fn
254 ,p_log_level_rec => g_log_level_rec);
255 raise unp_err;
256 end if;
257
258 -- call the mrc wrapper for the transaction book
259 if not do_all_books
260 (px_trans_rec => px_trans_rec,
261 px_asset_hdr_rec => px_asset_hdr_rec,
262 p_asset_desc_rec => l_asset_desc_rec,
263 p_asset_type_rec => l_asset_type_rec,
264 p_asset_cat_rec => l_asset_cat_rec,
265 p_unplanned_deprn_rec => p_unplanned_deprn_rec,
266 p_log_level_rec => g_log_level_rec)then
267 raise unp_err;
268 end if;
269
270 -- commit if p_commit is TRUE.
271 if (fnd_api.to_boolean (p_commit)) then
272 COMMIT WORK;
273 end if;
274
275 x_return_status := FND_API.G_RET_STS_SUCCESS;
276
277 EXCEPTION
278 when unp_err then
279 ROLLBACK to do_unplanned;
280
281 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
282 fnd_client_info.set_currency_context (l_orig_currency_context);
283
284 fa_srvr_msg.add_message(calling_fn => l_calling_fn
285 ,p_log_level_rec => g_log_level_rec);
286
287 -- Commented for bugfix 4672237
288 -- FA_DEBUG_PKG.dump_debug_messages(max_mesgs => 0);
289
290 FND_MSG_PUB.count_and_get (
291 p_count => x_msg_count,
292 p_data => x_msg_data
293 );
294
295 x_return_status := FND_API.G_RET_STS_ERROR;
296
297 when others then
298 ROLLBACK to do_unplanned;
299
300 fnd_profile.put('GL_SET_OF_BKS_ID', l_orig_set_of_books_id);
301 fnd_client_info.set_currency_context (l_orig_currency_context);
302
303 fa_srvr_msg.add_sql_error(
304 calling_fn => l_calling_fn
305 ,p_log_level_rec => g_log_level_rec);
306
307 -- Commented for bugfix 4672237
308 -- FA_DEBUG_PKG.dump_debug_messages(max_mesgs => 0);
309
310 FND_MSG_PUB.count_and_get (
311 p_count => x_msg_count,
312 p_data => x_msg_data
313 );
314
315 x_return_status := FND_API.G_RET_STS_ERROR;
316
317 END do_unplanned;
318
319
320 -----------------------------------------------------------------------------
321
322 -- Books (MRC) Wrapper - called from public API above
323 --
324 -- For non mrc books, this just calls the private API with provided params
325 -- For MRC, it processes the primary and then loops through each reporting
326 -- book calling the private api for each.
327
328
329 FUNCTION do_all_books
330 (px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
331 px_asset_hdr_rec IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
332 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
333 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
334 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
335 p_unplanned_deprn_rec IN FA_API_TYPES.unplanned_deprn_rec_type,
336 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
337
338 -- used for calling private api for reporting books
339 l_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type;
340 l_asset_fin_rec_adj FA_API_TYPES.asset_fin_rec_type;
341 l_asset_deprn_rec_adj FA_API_TYPES.asset_deprn_rec_type;
342
343 -- used for retrieving "old" and "new" structs from private api calls
344 l_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
345 l_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
346
347 l_unplanned_deprn_rec FA_API_TYPES.unplanned_deprn_rec_type;
348
349 l_reporting_flag varchar2(1);
350 l_period_rec FA_API_TYPES.period_rec_type;
351 l_sob_tbl FA_CACHE_PKG.fazcrsob_sob_tbl_type;
352
353 -- used for local runs
354 l_responsibility_id number;
355 l_application_id number;
356
357 -- used for get_rate
358 l_deprn_ratio number;
359 l_exchange_date date;
360 l_rate number;
361 l_result_code varchar2(15);
362
363 l_complete varchar2(1);
364 l_result_code1 varchar2(15);
365
366 l_exchange_rate number;
367 l_avg_rate number;
368
369 l_transaction_date date;
370
371 l_flex_structure_num number;
372 n_segs number;
373 all_segments fnd_flex_ext.SegmentArray;
374 l_account_segnum number;
375
376 l_status boolean;
377 l_rowid rowid;
378
379 -- Track Member
380 l_grp_trans_rec FA_API_TYPES.trans_rec_type;
381 l_grp_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type;
382 l_grp_asset_desc_rec FA_API_TYPES.asset_desc_rec_type;
383 l_grp_asset_type_rec FA_API_TYPES.asset_type_rec_type;
384 l_grp_asset_cat_rec FA_API_TYPES.asset_cat_rec_type;
385 l_grp_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
386 l_grp_asset_deprn_rec FA_API_TYPES.asset_deprn_rec_type;
387 l_grp_deprn_basis_rule VARCHAR2(4);
388 l_grp_rate_source_rule VARCHAR2(10);
389 l_ret_code number;
390 l_group_level_override VARCHAR2(1) := 'Y';
391 x_group_deprn_amount number;
392 x_group_bonus_amount number;
393
394
395 l_calling_fn varchar2(30) := 'fa_unplanned_pub.do_all_books';
396 unp_err EXCEPTION;
397
398 BEGIN
399
400 -- call transaction approval
401 if not FA_TRX_APPROVAL_PKG.faxcat
402 (X_book => px_asset_hdr_rec.book_type_code,
403 X_asset_id => px_asset_hdr_rec.asset_id,
404 X_trx_type => 'ADJUSTMENT',
405 X_trx_date => px_trans_rec.transaction_date_entered,
406 X_init_message_flag => 'NO',
407 p_log_level_rec => p_log_level_rec) then
408 raise unp_err;
409 end if;
410
411 if not FA_UTIL_PVT.get_period_rec
412 (p_book => px_asset_hdr_rec.book_type_code,
413 p_effective_date => NULL,
414 x_period_rec => l_period_rec,
415 p_log_level_rec => p_log_level_rec) then
416 raise unp_err;
417 end if;
418
419 -- Bug # 4882700
420 -- value for parameter "p_mode" is changed to ABSOLUTE from CAPITALIZED.
421 -- check period of addition
422 if not FA_ASSET_VAL_PVT.validate_period_of_addition
423 (p_asset_id => px_asset_hdr_rec.asset_id,
424 p_book => px_asset_hdr_rec.book_type_code,
425 p_mode => 'ABSOLUTE',
426 px_period_of_addition => px_asset_hdr_rec.period_of_addition,
427 p_log_level_rec => p_log_level_rec) then
428 raise unp_err;
429 end if;
430
431
432 -- trx_date for all expensed transactions will be last date of open period
433 l_transaction_date := greatest(l_period_rec.calendar_period_open_date,
434 least(sysdate,l_period_rec.calendar_period_close_date));
435
436
437 if (px_trans_rec.transaction_subtype = 'EXPENSED') then
438
439 if not FA_ASSET_VAL_PVT.validate_exp_after_amort
440 (p_asset_id => px_asset_hdr_rec.asset_id,
441 p_book => px_asset_hdr_rec.book_type_code,
442 p_log_level_rec => p_log_level_rec) then
443 raise unp_err;
444 end if;
445
446 px_trans_rec.transaction_date_entered :=
447 to_date(to_char(l_transaction_date,'DD/MM/YYYY'),'DD/MM/YYYY');
448
449 px_trans_rec.amortization_start_date := NULL;
450
451 else
452 -- might want to try to determin user intent here
453 -- if they populate amort_start_date instead of trx_date
454 if (px_trans_rec.amortization_start_date is not null) then
455 px_trans_rec.transaction_date_entered := px_trans_rec.amortization_start_date;
456 else
457 if (px_trans_rec.transaction_date_entered is null) then
458 l_transaction_date := greatest(l_period_rec.calendar_period_open_date,
459 least(sysdate,l_period_rec.calendar_period_close_date));
460 px_trans_rec.transaction_date_entered :=
461 to_date(to_char(l_transaction_date,'DD/MM/YYYY'),'DD/MM/YYYY');
462 end if;
463 px_trans_rec.amortization_start_date := px_trans_rec.transaction_date_entered;
464 end if;
465 end if;
466
467 -- BUG# 3549470
468 -- remove time stamps from both dates
469
470 px_trans_rec.transaction_date_entered :=
471 to_date(to_char(px_trans_rec.transaction_date_entered,'DD/MM/YYYY'),'DD/MM/YYYY');
472
473 px_trans_rec.amortization_start_date :=
474 to_date(to_char(px_trans_rec.amortization_start_date,'DD/MM/YYYY'),'DD/MM/YYYY');
475
476 if FA_ASSET_VAL_PVT.validate_fully_retired
477 (p_asset_id => px_asset_hdr_rec.asset_id,
478 p_book => px_asset_hdr_rec.book_type_code,
479 p_log_level_rec => p_log_level_rec) then
480 fa_srvr_msg.add_message
481 (name => 'FA_REC_RETIRED',
482 calling_fn => l_calling_fn
483 ,p_log_level_rec => p_log_level_rec);
484 raise unp_err;
485 end if;
486
487 l_flex_structure_num := fa_cache_pkg.fazcbc_record.accounting_flex_structure;
488
489 -- check the ccid / set up flex info
490 if not fnd_flex_apis.get_qualifier_segnum
491 (appl_id => 101,
492 key_flex_code => 'GL#',
493 structure_number => l_flex_structure_num,
494 flex_qual_name => 'GL_BALANCING',
495 segment_number => l_account_segnum) then
496 fa_srvr_msg.add_message
497 (calling_fn => 'fnd_flex_apis.get_qualifier_segnum'
498 ,p_log_level_rec => p_log_level_rec);
499 raise unp_err;
500 end if;
501
502 if not fnd_flex_ext.get_segments
503 (application_short_name => 'SQLGL',
504 key_flex_code => 'GL#',
505 structure_number => l_flex_structure_num,
506 combination_id => p_unplanned_deprn_rec.code_combination_id,
507 n_segments => n_segs,
508 segments => all_segments) then
509 fa_srvr_msg.add_message
510 (calling_fn => 'fnd_flex_ext.get_segments'
511 ,p_log_level_rec => p_log_level_rec);
512 raise unp_err;
513 end if;
514
515 G_expense_account := all_segments(l_account_segnum);
516
517
518 -- Check whether the balancing segments values for
519 -- different distributions are same or not.
520
521 l_status := FALSE;
522
523 FA_CHK_BALSEG_PKG.check_balancing_segments
524 (book => px_asset_hdr_rec.book_type_code,
525 asset_id => px_asset_hdr_rec.asset_id,
526 success => l_status,
527 calling_fn => 'CLIENT',
528 p_log_level_rec => p_log_level_rec);
529
530 if not (l_status) then
531 FA_SRVR_MSG.ADD_MESSAGE
532 (calling_fn => 'FA_CHK_BALSEG_PKG.chk_bal_segs'
533 ,p_log_level_rec => p_log_level_rec);
534 raise unp_err;
535 end if;
536
537
538 -- call the sob cache to get the table of sob_ids
539 if not FA_CACHE_PKG.fazcrsob
540 (x_book_type_code => px_asset_hdr_rec.book_type_code,
541 x_sob_tbl => l_sob_tbl,
542 p_log_level_rec => p_log_level_rec) then
543 raise unp_err;
544 end if;
545
546 -- set up the local asset_header and sob_id
547 l_asset_hdr_rec := px_asset_hdr_rec;
548
549
550 -- loop through each book starting with the primary and
551 -- call the private API for each
552
553 FOR l_sob_index in 0..l_sob_tbl.count LOOP
554
555
556 if (l_sob_index = 0) then
557 l_reporting_flag := 'P';
558 else
559 l_reporting_flag := 'R';
560 l_asset_hdr_rec.set_of_books_id := l_sob_tbl(l_sob_index);
561
562 -- set the sob_id and currency context
563 fnd_profile.put('GL_SET_OF_BKS_ID', l_sob_tbl(l_sob_index));
564 fnd_client_info.set_currency_context (to_char(l_sob_tbl(l_sob_index)));
565
566 end if;
567
568
569 -- call the cache to set the sob_id used for rounding and other lower
570 -- level code for each book.
571 if NOT fa_cache_pkg.fazcbcs(X_book => px_asset_hdr_rec.book_type_code,
572 p_log_level_rec => p_log_level_rec) then
573 raise unp_err;
574 end if;
575
576 -- load the old structs
577 if not FA_UTIL_PVT.get_asset_fin_rec
578 (p_asset_hdr_rec => px_asset_hdr_rec,
579 px_asset_fin_rec => l_asset_fin_rec,
580 p_transaction_header_id => NULL,
581 p_mrc_sob_type_code => l_reporting_flag,
582 p_log_level_rec => p_log_level_rec) then
583 raise unp_err;
584 end if;
585
586 if not FA_UTIL_PVT.get_asset_deprn_rec
587 (p_asset_hdr_rec => px_asset_hdr_rec ,
588 px_asset_deprn_rec => l_asset_deprn_rec,
589 p_period_counter => NULL,
590 p_mrc_sob_type_code => l_reporting_flag,
591 p_log_level_rec => p_log_level_rec) then
592 raise unp_err;
593 end if;
594
595 -- load the adj structs
596 if (l_sob_index = 0) then
597
598 -- set the primary structs
599 l_unplanned_deprn_rec := p_unplanned_deprn_rec;
600
601 -- do not allow unplanned on member assets in group centric
602 -- setups... will allow when tracking is enabled
603
604 if (l_asset_fin_rec.group_asset_id is not null and
605 l_asset_fin_rec.tracking_method is null) then
606 fa_srvr_msg.add_message
607 (name => '***FA_NO_UNPLANNED_MEMBER***',
608 calling_fn => l_calling_fn
609 ,p_log_level_rec => p_log_level_rec);
610 raise unp_err;
611 end if;
612
613 else
614
615 -- get the current average exchange rate to convert the unplanned amount
616 select avg_exchange_rate
617 into l_avg_rate
618 from fa_mc_books_rates
619 where asset_id = l_asset_hdr_rec.asset_id
620 and book_type_code = l_asset_hdr_rec.book_type_code
621 and set_of_books_id = l_asset_hdr_rec.set_of_books_id
622 and transaction_header_id =
623 (select max(transaction_header_id)
624 from fa_mc_books_rates
625 where asset_id = l_asset_hdr_rec.asset_id
626 and book_type_code = l_asset_hdr_rec.book_type_code
627 and set_of_books_id = l_asset_hdr_rec.set_of_books_id);
628
629 l_unplanned_deprn_rec.unplanned_amount := l_unplanned_deprn_rec.unplanned_amount * l_avg_rate;
630
631 if not FA_UTILS_PKG.faxrnd(l_unplanned_deprn_rec.unplanned_amount,
632 px_asset_hdr_rec.book_type_code,
633 p_log_level_rec => p_log_level_rec) then
634 raise unp_err;
635 end if;
636
637 end if;
638
639
640 if (p_log_level_rec.statement_level) then
641 fa_debug_pkg.add(l_calling_fn, 'call private do_unplanned', px_trans_rec.calling_interface,p_log_level_rec);
642 end if;
643
644 -- this could be broken into a seperate do_all_books function if desired
645 -- call the private api for the primary book
646 if not FA_UNPLANNED_PVT.do_unplanned
647 (px_trans_rec => px_trans_rec,
648 p_asset_hdr_rec => px_asset_hdr_rec,
649 p_asset_desc_rec => p_asset_desc_rec,
650 p_asset_type_rec => p_asset_type_rec,
651 p_asset_cat_rec => p_asset_cat_rec,
652 p_asset_fin_rec => l_asset_fin_rec, -- mrc
653 p_asset_deprn_rec => l_asset_deprn_rec, -- mrc
654 p_unplanned_deprn_rec => l_unplanned_deprn_rec,
655 p_period_rec => l_period_rec,
656 p_mrc_sob_type_code => l_reporting_flag,
657 p_log_level_rec => p_log_level_rec) then
658 raise unp_err;
659 end if;
660
661
662 if (p_log_level_rec.statement_level) then
663 fa_debug_pkg.add(l_calling_fn, 'Done FA_UNPLANNED_PVT.do_unplanned', ' ', p_log_level_rec);
664 end if;
665
666 if (l_sob_index = 0) then
667
668 -- set the primary structs
669 -- no need anymore - using locals anyway
670 -- Code hook for IAC
671 if (FA_IGI_EXT_PKG.IAC_Enabled) then
672 if not FA_IGI_EXT_PKG.Do_Unplanned(
673 p_trans_rec => px_trans_rec,
674 p_asset_hdr_rec => px_asset_hdr_rec,
675 p_asset_cat_rec => p_asset_cat_rec,
676 p_asset_desc_rec => p_asset_desc_rec,
677 p_asset_type_rec => p_asset_type_rec,
678 p_unplanned_deprn_rec => p_unplanned_deprn_rec,
679 p_period_rec => l_period_rec,
680 p_calling_function => 'FA_UNPLANNED_PUB.Do_Unplanned') then
681 raise unp_err;
682 end if;
683
684 end if; -- (FA_IGI_EXT_PKG.IAC_Enabled)
685
686 else
687 -- insert rates row into mc_books_rates
688 MC_FA_UTILITIES_PKG.insert_books_rates
689 (p_set_of_books_id => l_asset_hdr_rec.set_of_books_id,
690 p_asset_id => l_asset_hdr_rec.asset_id,
691 p_book_type_code => l_asset_hdr_rec.book_type_code,
692 p_transaction_header_id => px_trans_rec.transaction_header_id,
693 p_invoice_transaction_id => NULL,
694 p_exchange_date => px_trans_rec.transaction_date_entered,
695 p_cost => 0,
696 p_exchange_rate => l_avg_rate,
697 p_avg_exchange_rate => l_avg_rate,
698 p_last_updated_by => px_trans_rec.who_info.last_updated_by,
699 p_last_update_date => px_trans_rec.who_info.last_update_date,
700 p_last_update_login => px_trans_rec.who_info.last_update_login,
701 p_complete => 'Y',
702 p_trigger => 'unplanned api',
703 p_currency_code => l_asset_hdr_rec.set_of_books_id);
704 end if; -- primary book
705
706
707 -- ENERGY
708 -- Eventually, following allocation process should not happen when user performs
709 -- unplan from FAXASSET. For rel 11, I modified the condition so that the
710 -- allocation process will differ to Process Group Adjustment only if the deprn
711 -- basis rule is ENERGY PERIOD END BALANCE'.
712 -- if (px_trans_rec.calling_interface <> 'FAXASSET') then
713
714 if (not (px_trans_rec.calling_interface = 'FAXASSET' and
715 fa_cache_pkg.fazcdrd_record.rule_name = 'ENERGY PERIOD END BALANCE')) then
716
717 -- Calcualte Group Assets to which the processed member asset belongs
718 -- This is only when the Tracking Method is ALLOCATE.
719
720 -- If the processed asset is GROUP asset and tracking method is 'ALLOCATE',
721 -- Call TRACK_ASSETS to allocate unplanned amount into members.
722 -- For track member feature
723 -- Only when the unplanned depreciation is kicked from group asset whose tracking method is
724 -- ALLOCATE, system needs to allocate the entered unplanned depreciation amount into
725 -- members.
726
727 if l_asset_fin_rec.group_asset_id is null and
728 nvl(l_asset_fin_rec.tracking_method,'OTHER') = 'ALLOCATE' then
729
730 if not fa_cache_pkg.fazccmt (l_asset_fin_rec.deprn_method_code,l_asset_fin_rec.life_in_months) then
731 fa_srvr_msg.add_message (calling_fn => l_calling_fn
732 ,p_log_level_rec => p_log_level_rec);
733 raise unp_err;
734 end if;
735
736
737 l_ret_code := FA_TRACK_MEMBER_PVT.TRACK_ASSETS
738 (P_book_type_code => px_asset_hdr_rec.book_type_code,
739 P_group_asset_id => px_asset_hdr_rec.asset_id,
740 P_period_counter => l_period_rec.period_num,
741 P_fiscal_year => l_period_rec.fiscal_year,
742 P_group_deprn_basis => fa_cache_pkg.fazccmt_record.deprn_basis_rule,
743 P_group_exclude_salvage => fa_cache_pkg.fazccmt_record.exclude_salvage_value_flag,
744 P_group_bonus_rule => l_asset_fin_rec.bonus_rule,
745 P_group_deprn_amount => l_unplanned_deprn_rec.unplanned_amount,
746 P_group_bonus_amount => 0,
747 P_tracking_method => l_asset_fin_rec.tracking_method,
748 P_allocate_to_fully_ret_flag => l_asset_fin_rec.allocate_to_fully_ret_flag,
749 P_allocate_to_fully_rsv_flag => l_asset_fin_rec.allocate_to_fully_rsv_flag,
750 P_excess_allocation_option => l_asset_fin_rec.excess_allocation_option,
751 P_subtraction_flag => 'N',
752 P_group_level_override => l_group_level_override,
753 P_transaction_date_entered => px_trans_rec.transaction_date_entered,
754 P_mode => 'UNPLANNED',
755 X_new_deprn_amount => x_group_deprn_amount,
756 X_new_bonus_amount => x_group_bonus_amount
757 ,p_log_level_rec => p_log_level_rec);
758
759 if l_ret_code <> 0 then
760 raise unp_err;
761 elsif x_group_deprn_amount <> l_unplanned_deprn_rec.unplanned_amount then
762 raise unp_err;
763 end if;
764
765 end if;
766
767
768 end if;
769
770 -- If the asset is member asset and the group asset has tracking method, ALLOCATE,
771 -- Need to process Group Level Unplanned Depreciation Calculation.
772
773 if l_asset_fin_rec.group_asset_id is not null and
774 nvl(l_asset_fin_rec.tracking_method,'OTHER') = 'ALLOCATE' then
775
776 -- Copy group asset id to l_asset_hdr_rec.asset_id and get asset_fin_rec for the group
777 -- Copy member transaction header id to l_grp_trans_rec.member_transaction_header_id
778 -- and get new transaction_header_id for the group
779
780 l_grp_asset_hdr_rec := px_asset_hdr_rec;
781 l_grp_asset_hdr_rec.asset_id := l_asset_fin_rec.group_asset_id;
782
783 l_grp_trans_rec := px_trans_rec;
784 l_grp_trans_rec.member_transaction_header_id := px_trans_rec.transaction_header_id;
785
786 select fa_transaction_headers_s.nextval
787 into l_grp_trans_rec.transaction_header_id
788 from dual;
789
790 -- check period of addition for the group
791
792 if not FA_ASSET_VAL_PVT.validate_period_of_addition
793 (p_asset_id => l_grp_asset_hdr_rec.asset_id,
794 p_book => l_grp_asset_hdr_rec.book_type_code,
795 p_mode => 'ABSOLUTE',
796 px_period_of_addition => l_grp_asset_hdr_rec.period_of_addition,
797 p_log_level_rec => p_log_level_rec) then
798 raise unp_err;
799 end if;
800
801 -- pop the asset type
802 if not FA_UTIL_PVT.get_asset_type_rec
803 (p_asset_hdr_rec => l_grp_asset_hdr_rec,
804 px_asset_type_rec => l_grp_asset_type_rec,
805 p_date_effective => null,
806 p_log_level_rec => p_log_level_rec) then
807 raise unp_err;
808 end if;
809
810 -- pop the asset category
811 if not FA_UTIL_PVT.get_asset_cat_rec
812 (p_asset_hdr_rec => l_grp_asset_hdr_rec,
813 px_asset_cat_rec => l_grp_asset_cat_rec,
814 p_date_effective => null,
815 p_log_level_rec => p_log_level_rec) then
816 raise unp_err;
817 end if;
818
819 -- pop the asset desc (needed for current units)
820 if not FA_UTIL_PVT.get_asset_desc_rec
821 (p_asset_hdr_rec => l_grp_asset_hdr_rec,
822 px_asset_desc_rec => l_grp_asset_desc_rec,
823 p_log_level_rec => p_log_level_rec) then
824 raise unp_err;
825 end if;
826
827 if (l_grp_asset_type_rec.asset_type <> 'CAPITALIZED' and
828 l_grp_asset_type_rec.asset_type <> 'GROUP') then
829 fa_srvr_msg.add_message
830 (name => '** NO_UNPLANNED_NON_CAP **',
831 calling_fn => l_calling_fn
832 ,p_log_level_rec => p_log_level_rec);
833 raise unp_err;
834 end if;
835
836 -- check / default the trx info (This process assumes Group Asset)
837 -- SLA Uptake
838 -- remains the same regardless
839 /*
840 if (l_grp_asset_hdr_rec.period_of_addition = 'Y') then
841 l_grp_trans_rec.transaction_type_code := 'GROUP ADDITION';
842 else
843 */
844 l_grp_trans_rec.transaction_type_code := 'GROUP ADJUSTMENT';
845 --end if;
846
847 -- SLA Uptake
848 -- Conditions are no longer needed
849
850 if (l_grp_asset_type_rec.asset_type = 'GROUP') then
851 l_grp_trans_rec.transaction_subtype := 'AMORTIZED';
852 end if;
853
854 l_grp_trans_rec.transaction_key := 'UA';
855
856 /*
857 if (l_grp_asset_type_rec.asset_type = 'GROUP' and
858 l_grp_asset_hdr_rec.period_of_addition <> 'Y') then
859 l_grp_trans_rec.transaction_subtype := 'AMORTIZED';
860 end if;
861
862 -- set the subtype
863 if (l_grp_trans_rec.transaction_subtype = 'AMORTIZED') then
864 l_grp_trans_rec.transaction_key := 'UA';
865 else
866 l_grp_trans_rec.transaction_key := 'UE';
867 end if;
868 */
869
870 if FA_ASSET_VAL_PVT.validate_fully_retired
871 (p_asset_id => l_grp_asset_hdr_rec.asset_id,
872 p_book => l_grp_asset_hdr_rec.book_type_code,
873 p_log_level_rec => p_log_level_rec) then
874 fa_srvr_msg.add_message
875 (name => '*** fully retired ***',
876 calling_fn => l_calling_fn
877 ,p_log_level_rec => p_log_level_rec);
878 raise unp_err;
879 end if;
880
881 -- Check whether the balancing segments values for
882 -- different distributions are same or not.
883
884 l_status := FALSE;
885
886 FA_CHK_BALSEG_PKG.check_balancing_segments
887 (book => l_grp_asset_hdr_rec.book_type_code,
888 asset_id => l_grp_asset_hdr_rec.asset_id,
889 success => l_status,
890 calling_fn => 'CLIENT'
891 ,p_log_level_rec => p_log_level_rec);
892
893 --??? message needed here?
894 if not (l_status) then
895 FA_SRVR_MSG.ADD_MESSAGE
896 (NAME => '***flex fail***',
897 CALLING_FN => l_calling_fn
898 ,p_log_level_rec => p_log_level_rec);
899 raise unp_err;
900 end if;
901
902 -- load the old structs
903 if not FA_UTIL_PVT.get_asset_fin_rec
904 (p_asset_hdr_rec => l_grp_asset_hdr_rec,
905 px_asset_fin_rec => l_grp_asset_fin_rec,
906 p_transaction_header_id => NULL,
907 p_mrc_sob_type_code => l_reporting_flag,
908 p_log_level_rec => p_log_level_rec) then
909 raise unp_err;
910 end if;
911
912 --HH validate disabled_flag
913 --Doing this just as a precaustion in case the api get called directly.
914 --The form, if used, won't allow the trx as the button is not shown.
915 if not FA_ASSET_VAL_PVT.validate_disabled_flag
916 (p_group_asset_id => l_grp_asset_hdr_rec.asset_id,
917 p_book_type_code => l_grp_asset_hdr_rec.book_type_code,
918 p_old_flag => l_grp_asset_fin_rec.disabled_flag,
919 p_new_flag => l_grp_asset_fin_rec.disabled_flag,
920 p_log_level_rec => p_log_level_rec) then
921 fa_srvr_msg.add_message
922 (name => 'FA_NO_UNPLANNED_DIS_GROUP',
923 calling_fn => l_calling_fn
924 ,p_log_level_rec => p_log_level_rec);
925 raise unp_err;
926 end if; --end HH.
927
928 if not FA_UTIL_PVT.get_asset_deprn_rec
929 (p_asset_hdr_rec => l_grp_asset_hdr_rec ,
930 px_asset_deprn_rec => l_grp_asset_deprn_rec,
931 p_period_counter => NULL,
932 p_mrc_sob_type_code => l_reporting_flag,
933 p_log_level_rec => p_log_level_rec) then
934 raise unp_err;
935 end if;
936
937 -- this could be broken into a seperate do_all_books function if desired
938 -- call the private api for the primary book
939 if not FA_UNPLANNED_PVT.do_unplanned
940 (px_trans_rec => l_grp_trans_rec,
941 p_asset_hdr_rec => l_grp_asset_hdr_rec,
942 p_asset_desc_rec => l_grp_asset_desc_rec,
943 p_asset_type_rec => l_grp_asset_type_rec,
944 p_asset_cat_rec => l_grp_asset_cat_rec,
945 p_asset_fin_rec => l_grp_asset_fin_rec, -- mrc
946 p_asset_deprn_rec => l_grp_asset_deprn_rec, --mrc
947 p_unplanned_deprn_rec => l_unplanned_deprn_rec,
948 p_period_rec => l_period_rec,
949 p_mrc_sob_type_code => l_reporting_flag,
950 p_log_level_rec => p_log_level_rec) then
951 raise unp_err;
952 end if;
953
954 end if; -- Group Asset Process
955
956 end loop; -- sob loop
957
958 fnd_profile.put('GL_SET_OF_BKS_ID', px_asset_hdr_rec.set_of_books_id);
959 fnd_client_info.set_currency_context (px_asset_hdr_rec.set_of_books_id);
960
961 return true;
962
963 EXCEPTION
964 when unp_err then
965 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
966 p_log_level_rec => p_log_level_rec);
967 return false;
968
969 when others then
970 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
971 ,p_log_level_rec => p_log_level_rec);
972 return false;
973
974 END do_all_books;
975
976 END FA_UNPLANNED_PUB;