1 PACKAGE BODY FA_ASSET_VAL_PVT as
2 /* $Header: FAVVALB.pls 120.136.12020000.7 2013/03/19 18:11:01 dvjoshi ship $ */
3
4 FUNCTION validate
5 (p_trans_rec IN FA_API_TYPES.trans_rec_type,
6 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
7 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
8 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
9 p_asset_cat_rec IN FA_API_TYPES.asset_cat_rec_type,
10 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
11 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type,
12 p_asset_dist_tbl IN FA_API_TYPES.asset_dist_tbl_type,
13 p_inv_tbl IN FA_API_TYPES.inv_tbl_type,
14 p_calling_fn IN VARCHAR2,
15 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN boolean IS
16
17 l_distribution_count number;
18 val_err exception;
19 l_asset_dist_tbl FA_API_TYPES.asset_dist_tbl_type;
20 -- Changes made as per the ER No.s 6606548 and 6606552 by Vkukutam Start
21 l_japan_tax_reform varchar2(1) := fnd_profile.value('FA_JAPAN_TAX_REFORMS');
22 -- Changes made as per the ER No.s 6606548 and 6606552 by Vkukutam End
23
24 l_curr_index number;
25
26 BEGIN
27 if ((p_trans_rec.transaction_type_code = 'ADDITION') OR
28 (p_trans_rec.transaction_type_code = 'CIP ADDITION') OR
29 (p_trans_rec.transaction_type_code = 'GROUP ADDITION')) then
30 if not validate_asset_book (
31 p_transaction_type_code => p_trans_rec.transaction_type_code,
32 p_book_type_code => p_asset_hdr_rec.book_type_code,
33 p_asset_id => p_asset_hdr_rec.asset_id,
34 p_calling_fn => p_calling_fn,
35 p_log_level_rec => p_log_level_rec
36 ) then
37 raise val_err;
38 end if;
39 if not validate_cost (
40 p_transaction_type_code => p_trans_rec.transaction_type_code,
41 p_cost => p_asset_fin_rec.cost,
42 p_asset_type => p_asset_type_rec.asset_type,
43 p_num_invoices => p_inv_tbl.COUNT,
44 p_calling_fn => p_calling_fn,
45 p_log_level_rec => p_log_level_rec
46 ) then
47 raise val_err;
48 end if;
49
50 -- Bug No#5708875
51 -- Addding validation for current units
52 if not validate_current_units (
53 p_transaction_type_code => p_trans_rec.transaction_type_code,
54 p_current_units => p_asset_desc_rec.current_units,
55 p_log_level_rec => p_log_level_rec
56 ) then
57 raise val_err;
58 end if;
59
60 -- Bug 7670767. added following condition to prevent addition of an extended asset as amortized
61 -- Bug 11811775 added condition to prevent addition of non fully reserved asset as extended
62 if (p_trans_rec.transaction_type_code = 'ADDITION' and
63 p_asset_fin_rec.deprn_method_code = 'JP-STL-EXTND') then
64 IF (l_japan_tax_reform = 'Y' and p_trans_rec.amortization_start_date is not NULL) then
65 fa_srvr_msg.add_message(
66 calling_fn => p_calling_fn,
67 name => 'FA_JP_EXTD_AMORT_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
68 return FALSE;
69 ELSIF (NVL(p_asset_deprn_rec.deprn_reserve,0) < (p_asset_fin_rec.cost - NVL(p_asset_fin_rec.prior_deprn_limit_amount,0))) THEN
70 fa_srvr_msg.add_message(
71 calling_fn => p_calling_fn,
72 name => 'FA_JP_EXTD_NOT_FULLY_RESERVED', p_log_level_rec => p_log_level_rec);
73 return FALSE;
74 END IF;
75 END IF;
76
77 -- bug 7670767 end
78
79 /* bug 11895180 restricted this call to assets having 250 db method code*/
80 -- if p_asset_fin_rec.deprn_method_code like 'JP%250DB%' then
81 -- JP_TAX_2012
82 if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES' then
83 if not validate_jp250db (
84 p_transaction_type_code => p_trans_rec.transaction_type_code,
85 p_book_type_code => p_asset_hdr_rec.book_type_code,
86 p_asset_id => p_asset_hdr_rec.asset_id,
87 p_method_code => p_asset_fin_rec.deprn_method_code,
88 p_life_in_months => p_asset_fin_rec.life_in_months,
89 p_asset_type => p_asset_type_rec.asset_type,
90 p_bonus_rule => p_asset_fin_rec.bonus_rule,
91 p_transaction_key => p_trans_rec.transaction_key,
92 p_cash_generating_unit_id => p_asset_fin_rec.cash_generating_unit_id,
93 p_deprn_override_flag => p_trans_rec.deprn_override_flag,
94 p_calling_fn => p_calling_fn,
95 p_log_level_rec => p_log_level_rec
96 ) then
97 raise val_err;
98 end if;
99 end if;
100
101 if (fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') then
102 if not validate_asset_number (
103 p_transaction_type_code => p_trans_rec.transaction_type_code,
104 p_asset_number => p_asset_desc_rec.asset_number,
105 p_asset_id => p_asset_hdr_rec.asset_id,
106 p_calling_fn => p_calling_fn,
107 p_log_level_rec => p_log_level_rec
108 ) then
109 raise val_err;
110 end if;
111 if not validate_owned_leased (
112 p_transaction_type_code => p_trans_rec.transaction_type_code,
113 p_owned_leased => p_asset_desc_rec.owned_leased,
114 p_calling_fn => p_calling_fn,
115 p_log_level_rec => p_log_level_rec
116 ) then
117 raise val_err;
118 end if;
119 if not validate_tag_number (
120 p_tag_number => p_asset_desc_rec.tag_number,
121 p_mass_addition_id => NULL,
122 p_calling_fn => p_calling_fn,
123 p_log_level_rec => p_log_level_rec
124 ) then
125 raise val_err;
126 end if;
127 if not validate_category (
128 p_transaction_type_code => p_trans_rec.transaction_type_code,
129 p_category_id => p_asset_cat_rec.category_id,
130 p_book_type_code => p_asset_hdr_rec.book_type_code,
131 p_calling_fn => p_calling_fn,
132 p_log_level_rec => p_log_level_rec
133 ) then
134 raise val_err;
135 end if;
136 if not validate_category_df (
137 p_transaction_type_code => p_trans_rec.transaction_type_code,
138 p_cat_desc_flex => p_asset_cat_rec.desc_flex,
139 p_calling_fn => p_calling_fn,
140 p_log_level_rec => p_log_level_rec
141 ) then
142 raise val_err;
143 end if;
144 if not validate_serial_number (
145 p_transaction_type_code => p_trans_rec.transaction_type_code,
146 p_serial_number => p_asset_desc_rec.serial_number,
147 p_calling_fn => p_calling_fn,
148 p_log_level_rec => p_log_level_rec
149 ) then
150 raise val_err;
151 end if;
152 if not validate_asset_key (
153 p_transaction_type_code => p_trans_rec.transaction_type_code,
154 p_asset_key_ccid => p_asset_desc_rec.asset_key_ccid,
155 p_calling_fn => p_calling_fn,
156 p_log_level_rec => p_log_level_rec
157 ) then
158 raise val_err;
159 end if;
160 if not validate_asset_type (
161 p_transaction_type_code => p_trans_rec.transaction_type_code,
162 p_asset_type => p_asset_type_rec.asset_type,
163 p_book_type_code => p_asset_hdr_rec.book_type_code,
164 p_category_id => p_asset_cat_rec.category_id,
165 p_calling_fn => p_calling_fn,
166 p_log_level_rec => p_log_level_rec
167 ) then
168 raise val_err;
169 end if;
170 if not validate_supplier_name (
171 p_transaction_type_code => p_trans_rec.transaction_type_code,
172 p_calling_fn => p_calling_fn,
173 p_log_level_rec => p_log_level_rec
174 ) then
175 raise val_err;
176 end if;
177 if not validate_supplier_number (
178 p_transaction_type_code => p_trans_rec.transaction_type_code,
179 p_calling_fn => p_calling_fn,
180 p_log_level_rec => p_log_level_rec
181 ) then
182 raise val_err;
183 end if;
184 if not validate_lease (
185 p_asset_id => p_asset_hdr_rec.asset_id,
186 p_lease_id => p_asset_desc_rec.lease_id,
187 p_category_id => p_asset_cat_rec.category_id,
188 p_log_level_rec => p_log_level_rec
189 ) then
190 raise val_err;
191 end if;
192
193 if not validate_warranty (
194 p_warranty_id => p_asset_desc_rec.warranty_id,
195 p_date_placed_in_service
196 => p_asset_fin_rec.date_placed_in_service,
197 p_book_type_code => p_asset_hdr_rec.book_type_code,
198 p_log_level_rec => p_log_level_rec
199 ) then
200 raise val_err;
201 end if;
202
203 if not validate_property_type (
204 p_property_type_code => p_asset_desc_rec.property_type_code,
205 p_log_level_rec => p_log_level_rec
206 ) then
207 raise val_err;
208 end if;
209
210 if not validate_1245_1250_code (
211 p_1245_1250_code => p_asset_desc_rec.property_1245_1250_code,
212 p_log_level_rec => p_log_level_rec
213 ) then
214 raise val_err;
215 end if;
216
217 l_distribution_count := p_asset_dist_tbl.COUNT;
218 l_asset_dist_tbl := p_asset_dist_tbl;
219
220 for i in 1..l_distribution_count loop
221
222 if not validate_assigned_to (
223 p_transaction_type_code => p_trans_rec.transaction_type_code,
224 p_assigned_to => p_asset_dist_tbl(i).assigned_to,
225 p_calling_fn => p_calling_fn,
226 p_log_level_rec => p_log_level_rec
227 ) then
228 raise val_err;
229 end if;
230
231 if not validate_expense_ccid (
232 p_expense_ccid => p_asset_dist_tbl(i).expense_ccid,
233 p_gl_chart_id => fa_cache_pkg.fazcbc_record.accounting_flex_structure,
234 p_calling_fn => p_calling_fn,
235 p_log_level_rec => p_log_level_rec
236 ) then
237 raise val_err;
238 end if;
239
240 if not validate_location_ccid (
241 p_transaction_type_code => p_trans_rec.transaction_type_code,
242 p_location_ccid => p_asset_dist_tbl(i).location_ccid,
243 p_calling_fn => p_calling_fn,
244 p_log_level_rec => p_log_level_rec
245 ) then
246 raise val_err;
247 end if;
248
249 -- bugfix 2846357
250 l_curr_index := i;
251 if not validate_duplicate_dist (
252 p_transaction_type_code => p_trans_rec.transaction_type_code,
253 p_asset_dist_tbl => l_asset_dist_tbl,
254 p_curr_index => l_curr_index,
255 p_calling_function => p_trans_rec.calling_interface,
256 p_log_level_rec => p_log_level_rec
257 ) then
258 raise val_err;
259 end if;
260
261
262 --Changes made as per the ER No.s 6606548 and 6606552 by Vkukutam Start
263 if l_japan_tax_reform = 'Y' AND p_trans_rec.calling_interface = 'FAMAPT' then
264
265 -- Bug# 7698030 start
266
267 if p_asset_fin_rec.deprn_method_code='JP-STL-EXTND' then
268
269 -- start validate JP-STL-EXTND
270 if not validate_JP_STL_EXTND(
271
272 p_prior_deprn_method => p_asset_fin_rec.prior_deprn_method,
273 p_prior_basic_rate => p_asset_fin_rec.prior_basic_rate,
274 p_prior_adjusted_rate => p_asset_fin_rec.prior_adjusted_rate,
275 p_prior_life_in_months => p_asset_fin_rec.prior_life_in_months,
276 p_calling_fn => p_calling_fn,
277 p_log_level_rec => p_log_level_rec
278 ) then
279
280 raise val_err;
281
282 end if;
283 -- end validate JP-STL-EXTND
284 /*For Jp-STL-EXTD we also need to
285 * validate Erlier depreciation limit,
286 * Period fully reserved
287 * Early first period extended depreciation
288 */
289 -- start validate_earl_deprn_limit
290 if not validate_earl_deprn_limit(
291 p_prior_deprn_limit_amount => p_asset_fin_rec.prior_deprn_limit_amount,
292 p_prior_deprn_limit => p_asset_fin_rec.prior_deprn_limit,
293 p_prior_deprn_limit_type => p_asset_fin_rec.prior_deprn_limit_type,
294 p_calling_fn => p_calling_fn,
295 p_log_level_rec => p_log_level_rec
296 ) then
297
298 raise val_err;
299
300 end if;
301 -- end validate_earl_deprn_limit
302
303 -- start validate_period_fully_reserved
304 if not validate_period_fully_reserved(
305 p_book_type_code => p_asset_hdr_rec.book_type_code,
306 p_pc_fully_reserved => p_asset_fin_rec.period_counter_fully_reserved,
307 p_date_placed_in_service => p_asset_fin_rec.date_placed_in_service,
308 p_calling_fn => p_calling_fn,
309 p_log_level_rec => p_log_level_rec
310 ) then
311
312 raise val_err;
313 end if;
314 -- end validate_period_fully_reserved
315
316 -- Start validate_fst_prd_extd_deprn
317 if not validate_fst_prd_extd_deprn(
318 p_book_type_code => p_asset_hdr_rec.book_type_code,
319 p_extended_deprn_period => p_asset_fin_rec.extended_depreciation_period,
320 p_date_placed_in_service => p_asset_fin_rec.date_placed_in_service,
321 p_calling_fn => p_calling_fn,
322 p_log_level_rec => p_log_level_rec
323 ) then
324
325 raise val_err;
326
327 end if;
328 --- end validate_fst_prd_extd_deprn
329 end if;
330 -- End of JP-STL-EXTD method validation
331 -- Start of Not JP STL EXTD validation
332 if p_asset_fin_rec.deprn_method_code <> 'JP-STL-EXTND' then
333
334 -- start validate_NOT_JP_STL_EXTND
335 if not validate_NOT_JP_STL_EXTND(
336 p_book_type_code => p_asset_hdr_rec.book_type_code,
337 p_deprn_limit => p_asset_fin_rec.allowed_deprn_limit,
338 p_sp_deprn_limit => p_asset_fin_rec.allowed_deprn_limit_amount,
339 p_deprn_reserve => p_asset_deprn_rec.deprn_reserve,
340 p_asset_type => p_asset_type_rec.asset_type,
341 p_pc_fully_reserved => p_asset_fin_rec.period_counter_fully_reserved,
342 p_date_placed_in_service => p_asset_fin_rec.date_placed_in_service,
343 p_cost => p_asset_fin_rec.cost,
344 p_calling_fn => p_calling_fn,
345 p_log_level_rec => p_log_level_rec
346 ) then
347
348 raise val_err;
349 end if;
350
351 end if;
352 -- Start of Not JP STL EXTD validation
353
354 -- Start Validation for JP 250 DB methods
355 -- if p_asset_fin_rec.deprn_method_code like 'JP%250DB%' then
356 -- JP_TAX_2012
357 if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES' then
358 if not validate_JP_250_DB(
359 p_deprn_method_code => p_asset_fin_rec.deprn_method_code,
360 p_cost => p_asset_fin_rec.cost,
361 p_nbv_at_switch => p_asset_fin_rec.nbv_at_switch,
362 p_deprn_reserve => p_asset_deprn_rec.deprn_reserve,
363 p_ytd_deprn => p_asset_deprn_rec.ytd_deprn,
364 p_calling_fn => p_calling_fn,
365 p_log_level_rec => p_log_level_rec
366 ) then
367
368
369 raise val_err;
370 end if;
371
372 end if;
373 -- End Validation for JP 250 DB methods
374
375 -- Bug# end 7698030
376 NULL;
377 end if;
378 --Changes made as per the ER No.s 6606548 and 6606552 by Vkukutam End
379
380 end loop;
381
382 end if; -- corporate
383
384 if (p_asset_fin_rec.group_asset_id is not null and
385 p_asset_fin_rec.group_asset_id <> FND_API.G_MISS_NUM and
386 nvl(fa_cache_pkg.fazcbc_record.allow_interco_group_flag, 'N') <> 'Y') then
387 if not fa_interco_pvt.validate_grp_interco
388 (p_asset_hdr_rec => p_asset_hdr_rec,
389 p_trans_rec => p_trans_rec,
390 p_asset_type_rec => p_asset_type_rec,
391 p_group_asset_id => p_asset_fin_rec.group_asset_id,
392 p_asset_dist_tbl => p_asset_dist_tbl,
393 p_calling_fn => p_calling_fn, p_log_level_rec => p_log_level_rec) then
394 raise val_err;
395 end if;
396 end if;
397
398 /*Bug 8728813 - Member Assets can not have initial reserve - start*/
399 if (p_trans_rec.transaction_type_code = 'ADDITION' and
400 nvl(p_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM and
401 nvl(p_asset_deprn_rec.deprn_reserve,0) <> 0 and
402 nvl(p_asset_deprn_rec.ytd_deprn,0) <> 0) then
403 fa_srvr_msg.add_message(
404 calling_fn => p_calling_fn,
405 name => 'FA_NO_RESERVE_ALLOWED_MEM_ADD',
406 p_log_level_rec => p_log_level_rec);
407 return FALSE;
408 end if;
409 /*Bug 8728813 - Member Assets can not have initial reserve - end*/
410
411 /*Bug 8828394 - Group Asset ID should be valid Group Asset ID - Begin*/
412 if nvl(p_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM then
413 if not validate_group_asset_id(
414 p_asset_id => p_asset_fin_rec.group_asset_id,
415 p_log_level_rec => p_log_level_rec
416 ) then
417 raise val_err;
418 end if;
419 end if;
420 /*Bug 8828394 - Group Asset ID should be valid Group Asset ID - End*/
421
422 end if; -- ADDITION only
423
424 return TRUE;
425
426 EXCEPTION
427 when val_err then
428 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate', p_log_level_rec => p_log_level_rec);
429 return FALSE;
430
431 END;
432
433 FUNCTION validate_asset_number
434 (p_transaction_type_code IN VARCHAR2,
435 p_asset_number IN VARCHAR2,
436 p_asset_id IN NUMBER DEFAULT NULL,
437 p_calling_fn IN VARCHAR2,
438 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
439
440 l_count number;
441 l_asset_number number(15) := 0;
442
443 BEGIN
444
445 if ((p_transaction_type_code = 'ADDITION') OR
446 (p_transaction_type_code = 'CIP ADDITION')) then
447
448 if (p_asset_number is not null) then
449
450 -- Asset number must be unique.
451 select count(*)
452 into l_count
453 from fa_additions_b
454 where asset_number = upper(p_asset_number);
455
456 if (l_count > 0) then
457 fa_srvr_msg.add_message(
458 calling_fn => 'fa_asset_val_pvt.validate_asset_number',
459 name => 'FA_ADD_ASSET_NUMBER_USED', p_log_level_rec => p_log_level_rec);
460 return FALSE;
461 end if;
462
463 -- Need to check fa_mass_additions also. Only do this validation
464 -- if it is being called from Prepare Mass Additions. Otherwise,
465 -- it fails during Post Mass Additions.
466 if (p_calling_fn = 'MASS_ADDITIONS_7.Check_S_Asset_Number') then
467 select count(*)
468 into l_count
469 from fa_mass_additions
470 where asset_number = p_asset_number
471 and queue_name = 'POST'; -- fix for bug 3433702
472
473 --if (l_count > 1) then
474 if (l_count > 0) then -- fix for bug 3433702
475 fa_srvr_msg.add_message(
476 calling_fn => 'fa_asset_val_pvt.validate_asset_number',
477 name => 'FA_ADD_ASSET_NUMBER_USED', p_log_level_rec => p_log_level_rec);
478 return FALSE;
479 end if;
480 end if;
481
482 if (p_asset_number <> to_char(nvl(p_asset_id, -999))) then
483
484 -- Check that numeric asset numbers are less than those used for
485 -- automatic asset numbering.
486 select count(*)
487 into l_count
488 from dual
489 where nvl(substr(p_asset_number, 1,1), '0') between '0' and '9'
490 and nvl(substr(p_asset_number, 2,1), '0') between '0' and '9'
491 and nvl(substr(p_asset_number, 3,1), '0') between '0' and '9'
492 and nvl(substr(p_asset_number, 4,1), '0') between '0' and '9'
493 and nvl(substr(p_asset_number, 5,1), '0') between '0' and '9'
494 and nvl(substr(p_asset_number, 6,1), '0') between '0' and '9'
495 and nvl(substr(p_asset_number, 7,1), '0') between '0' and '9'
496 and nvl(substr(p_asset_number, 8,1), '0') between '0' and '9'
497 and nvl(substr(p_asset_number, 9,1), '0') between '0' and '9'
498 and nvl(substr(p_asset_number,10,1), '0') between '0' and '9'
499 and nvl(substr(p_asset_number,11,1), '0') between '0' and '9'
500 and nvl(substr(p_asset_number,12,1), '0') between '0' and '9'
501 and nvl(substr(p_asset_number,13,1), '0') between '0' and '9'
502 and nvl(substr(p_asset_number,14,1), '0') between '0' and '9'
503 and nvl(substr(p_asset_number,15,1), '0') between '0' and '9';
504
505 if (l_count > 0) then
506 begin
507 l_asset_number := to_number(p_asset_number);
508 exception
509 when value_error then
510 null;
511 when others then
512 fa_srvr_msg.add_message(
513 calling_fn => 'fa_asset_val_pvt.validate_asset_number',
514 name => 'FA_ASSET_NUMBER',
515 token1 => 'ASSET_NUMBER',
516 value1 => p_asset_number, p_log_level_rec => p_log_level_rec);
517 return FALSE;
518 end;
519
520 if not fa_cache_pkg.fazsys(p_log_level_rec => p_log_level_rec) then
521 fa_srvr_msg.add_message (
522 calling_fn => 'fa_asset_val_pvt.validate_asset_number', p_log_level_rec => p_log_level_rec);
523 end if;
524
525 -- Fix for Bug #2585811. You don't need to validate if they
526 -- are using custom asset numbering.
527 if ((l_asset_number >=
528 fa_cache_pkg.fazsys_record.initial_asset_id) and
529 (nvl(fa_cache_pkg.fazsys_record.use_custom_asset_numbers_flag, 'N') <> 'Y')
530 ) then
531 fa_srvr_msg.add_message(
532 calling_fn => 'fa_asset_val_pvt.validate_asset_number',
533 name => 'FA_ADD_AUTOMATIC_NUMBER', p_log_level_rec => p_log_level_rec);
534 return FALSE;
535 end if;
536 end if;
537 end if;
538 else -- Asset Number is NULL
539 if not fa_cache_pkg.fazsys(p_log_level_rec => p_log_level_rec) then
540 fa_srvr_msg.add_message (
541 calling_fn => 'fa_asset_val_pvt.validate_asset_number', p_log_level_rec => p_log_level_rec);
542 end if;
543
544 -- Fix for Bug #2585811. If they are using custom asset numbering,
545 -- they must populate asset number.
546 if (nvl(fa_cache_pkg.fazsys_record.use_custom_asset_numbers_flag, 'N')
547 = 'Y')
548 then
549 fa_srvr_msg.add_message(
550 calling_fn => 'fa_asset_val_pvt.validate_asset_number',
551 name => 'FA_NULL_CUSTOM_ASSET_NUMBER', p_log_level_rec => p_log_level_rec);
552 return FALSE;
553 end if;
554 end if;
555 end if;
556
557 return TRUE;
558
559 END validate_asset_number;
560
561 FUNCTION validate_owned_leased
562 (p_transaction_type_code IN VARCHAR2,
563 p_owned_leased IN VARCHAR2,
564 p_calling_fn IN VARCHAR2,
565 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
566
567 BEGIN
568
569 if (p_owned_leased not in ('OWNED', 'LEASED')) then
570 fa_srvr_msg.add_message(
571 calling_fn => 'fa_asset_val_pvt.validate_owned_leased',
572 name => 'FA_INVALID_PARAMETER',
573 token1 => 'OWNED_LEASED',
574 value1 => nvl(p_owned_leased, '-999'),
575 p_log_level_rec => p_log_level_rec);
576
577 return FALSE;
578 end if;
579
580 return TRUE;
581
582 END validate_owned_leased;
583
584 FUNCTION validate_category
585 (p_transaction_type_code IN VARCHAR2,
586 p_category_id IN NUMBER,
587 p_book_type_code IN VARCHAR2 DEFAULT NULL,
588 p_calling_fn IN VARCHAR2,
589 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
590
591 BEGIN
592 -- Check that the category exists.
593 if not fa_cache_pkg.fazcat (
594 X_cat_id => p_category_id
595 , p_log_level_rec => p_log_level_rec) then
596 fa_srvr_msg.add_message(
597 calling_fn => 'fa_asset_val_pvt.validate_asset_category', p_log_level_rec => p_log_level_rec);
598 return FALSE;
599 end if;
600
601 -- Check that the category is enabled.
602 if (fa_cache_pkg.fazcat_record.enabled_flag <> 'Y') then
603 fa_srvr_msg.add_message(
604 calling_fn => 'fa_asset_val_pvt.validate_asset_category',
605 name => 'FA_INCORRECT_CATEGORY_ID',
606 token1 => 'CATEGORY_ID',
607 value1 => p_category_id, p_log_level_rec => p_log_level_rec);
608 return FALSE;
609 end if;
610
611 -- removed check on capitalize flag as this isn't an asset level thing - bmr
612 if (p_book_type_code is not null) then
613
614 -- Make sure that the category/book exists.
615 if not (fa_cache_pkg.fazccb (
616 X_Book => p_book_type_code,
617 X_Cat_Id => p_category_id
618 , p_log_level_rec => p_log_level_rec)) then
619
620 if (fa_cache_pkg.fazcbc_record.book_class = 'TAX') then
621 fa_srvr_msg.add_message(
622 calling_fn => 'fa_asset_val_pvt.validate_asset_category',
623 name => 'FA_MCP_CAT_NOT_IN_TAX', p_log_level_rec => p_log_level_rec);
624 else
625 fa_srvr_msg.add_message(
626 calling_fn => 'fa_asset_val_pvt.validate_asset_category',
627 name => 'FA_BOOK_CAT_NOT_SET_UP', p_log_level_rec => p_log_level_rec);
628 end if;
629
630 return FALSE;
631 end if;
632 end if;
633
634 return TRUE;
635 END validate_category;
636
637 -- Bug No#5708875
638 -- Addding validation for current units
639 --current units cannot be in fractions
640
641 FUNCTION validate_current_units
642 (p_transaction_type_code IN VARCHAR2,
643 p_current_units IN NUMBER,
644 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
645 BEGIN
646
647
648 if ((p_transaction_type_code = 'ADDITION') OR
649 (p_transaction_type_code = 'CIP ADDITION')) then
650
651 IF (Nvl(p_current_units,0) < 0) THEN /* Added for Bug 13644806 Start */
652 fa_srvr_msg.add_message(
653 calling_fn => 'fa_asset_val_pvt.validate_current_units',
654 name => 'FA_TFR_NONZERO', p_log_level_rec => p_log_level_rec);
655 return FALSE;
656 END IF ;
657 --Checking if the current units contain fractional value
658 --if instr(nvl(p_current_units,0),'.')=0 THEN
659 if (trunc(p_current_units) = p_current_units) THEN /* Added for Bug 13644806 End */
660 return TRUE;
661 else
662
663 fa_srvr_msg.add_message(
664 calling_fn => 'fa_asset_val_pvt.validate_current_units',
665 name => 'FA_NO_FRAC_UNITS', p_log_level_rec => p_log_level_rec);
666 return FALSE;
667 end if;
668 end if;
669 return TRUE;
670 END validate_current_units;
671
672
673 FUNCTION validate_category_df
674 (p_transaction_type_code IN VARCHAR2,
675 p_cat_desc_flex IN FA_API_TYPES.desc_flex_rec_type,
676 p_calling_fn IN VARCHAR2,
677 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
678
679 BEGIN
680 -- Check that the flexfield value is valid.
681
682 return TRUE;
683 END validate_category_df;
684
685 FUNCTION validate_serial_number
686 (p_transaction_type_code IN VARCHAR2,
687 p_serial_number IN VARCHAR2,
688 p_calling_fn IN VARCHAR2,
689 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
690
691 BEGIN
692 -- CRL check?
693
694 return TRUE;
695 END validate_serial_number;
696
697 FUNCTION validate_asset_key
698 (p_transaction_type_code IN VARCHAR2,
699 p_asset_key_ccid IN NUMBER,
700 p_calling_fn IN VARCHAR2,
701 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
702
703 l_required number;
704 l_is_asset_key_valid number;
705
706 cursor c_asset_key_req is
707 select 1
708 from fnd_id_flex_segments
709 where application_id = 140
710 and id_flex_code = 'KEY#'
711 and id_flex_num = fa_cache_pkg.fazsys_record.asset_key_flex_structure
712 and required_flag = 'Y';
713
714 BEGIN
715 -- check if the flexfield has any required segments
716 if G_asset_key_required is null then
717 if not fa_cache_pkg.fazsys(p_log_level_rec) then
718 fa_srvr_msg.add_message(
719 calling_fn => 'fa_asset_val_pvt.validate_asset_key', p_log_level_rec => p_log_level_rec);
720 return false;
721 end if;
722
723 open c_asset_key_req;
724 fetch c_asset_key_req into l_required;
725 if c_asset_key_req%notfound then
726 G_asset_key_required := FALSE;
727 else
728 G_asset_key_required := TRUE;
729 end if;
730 close c_asset_key_req;
731
732 end if;
733
734
735 -- check if the combination is null and required
736 if G_asset_key_required and p_asset_key_ccid is null then
737 fa_srvr_msg.add_message(
738 calling_fn => 'fa_asset_val_pvt.validate_asset_key',
739 name => 'FA_NULL_ASSET_KEY',
740 token1 => 'ASSET_KEY',
741 value1 => NULL, p_log_level_rec => p_log_level_rec);
742 return false;
743 end if;
744
745 -- check if the combination is valid
746 if (p_asset_key_ccid is not null) then
747
748 select count(*)
749 into l_is_asset_key_valid
750 from fa_asset_keywords
751 where code_combination_id = p_asset_key_ccid
752 and enabled_flag = 'Y';
753
754 if (l_is_asset_key_valid = 0) then
755 fa_srvr_msg.add_message(
756 calling_fn => 'fa_asset_val_pvt.validate_asset_key',
757 name => 'FA_INCORRECT_ASSET_KEY',
758 token1 => 'ASSET_KEY_CCID',
759 value1 => p_asset_key_ccid, p_log_level_rec => p_log_level_rec);
760 return false;
761 end if;
762 end if;
763
764 return TRUE;
765 END validate_asset_key;
766
767 FUNCTION validate_asset_type
768 (p_transaction_type_code IN VARCHAR2,
769 p_asset_type IN VARCHAR2,
770 p_book_type_code IN VARCHAR2,
771 p_category_id IN NUMBER,
772 p_calling_fn IN VARCHAR2,
773 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
774
775 l_capitalize_flag varchar2(3);
776
777 BEGIN
778
779 -- Check that it can only be capitalized, cip, or expensed.
780 if not ((p_asset_type = 'CAPITALIZED') or
781 (p_asset_type = 'CIP') or
782 (p_asset_type = 'EXPENSED') or
783 (p_asset_type = 'GROUP')) then
784
785 fa_srvr_msg.add_message(
786 calling_fn => 'fa_asset_val_pvt.validate_asset_type',
787 name => 'FA_DPR_BAD_ASSET_TYPE', p_log_level_rec => p_log_level_rec);
788 return FALSE;
789 end if;
790
791 -- Check for invalid asset_type/category combinations.
792 if ((fa_cache_pkg.fazcat_record.capitalize_flag = 'YES') and
793 (p_asset_type = 'EXPENSED')) then
794
795 fa_srvr_msg.add_message(
796 calling_fn => 'fa_asset_val_pvt.validate_asset_type',
797 name => 'FA_INCORRECT_ASSET_TYPE', p_log_level_rec => p_log_level_rec);
798 return FALSE;
799 end if;
800
801 if ((fa_cache_pkg.fazcat_record.capitalize_flag = 'NO') and
802 ((p_asset_type = 'CAPITALIZED') or
803 (p_asset_type = 'CIP') or
804 (p_asset_type = 'GROUP'))) then
805
806 fa_srvr_msg.add_message(
807 calling_fn => 'fa_asset_val_pvt.validate_asset_type',
808 name => 'FA_INCORRECT_ASSET_TYPE', p_log_level_rec => p_log_level_rec);
809 return FALSE;
810 end if;
811
812 -- If asset is CIP, check the CIP accounts.
813 if (p_asset_type = 'CIP') then
814 if ((fa_cache_pkg.fazccb_record.cip_clearing_acct is null) OR
815 (fa_cache_pkg.fazccb_record.cip_cost_acct is null)) then
816
817 fa_srvr_msg.add_message(
818 calling_fn => 'fa_asset_val_pvt.validate_asset_type',
819 name => 'FA_SHARED_NO_CIP_ACCOUNTS', p_log_level_rec => p_log_level_rec);
820 return FALSE;
821 end if;
822 end if;
823
824 -- do not allow group if not enabled
825 if (p_asset_type = 'GROUP' and
826 nvl(fa_cache_pkg.fazcbc_record.allow_group_deprn_flag, 'N') <> 'Y') then
827 fa_srvr_msg.add_message(
828 calling_fn => 'fa_asset_val_pvt.validate_asset_type',
829 name => '***FA_GROUP_NOT_ALLOWED***',
830 p_log_level_rec => p_log_level_rec);
831 return FALSE;
832 end if;
833
834 return TRUE;
835
836 END validate_asset_type;
837
838 FUNCTION validate_depreciate_flag
839 (p_depreciate_flag IN VARCHAR2,
840 p_calling_fn IN VARCHAR2,
841 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
842
843 BEGIN
844
845 if ((p_depreciate_flag <> 'YES' and
846 p_depreciate_flag <> 'NO') or
847 p_depreciate_flag IS NULL) then
848 fa_srvr_msg.add_message(
849 calling_fn => 'fa_asset_val_pvt.val_depreciate_flag',
850 name => 'FA_INCORRECT_DEPRECIATE_FLAG', p_log_level_rec => p_log_level_rec);
851 return FALSE;
852 end if;
853
854 return TRUE;
855
856 END validate_depreciate_flag;
857
858 FUNCTION validate_supplier_name
859 (p_transaction_type_code IN VARCHAR2,
860 p_calling_fn IN VARCHAR2,
861 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
862
863 BEGIN
864 -- From vendor_name_q lov in asset workbench.
865
866 -- Check any dependencies w/ asset type.
867
868 -- Check any dependencies w/ supplier number.
869
870 return TRUE;
871 END validate_supplier_name;
872
873 FUNCTION validate_supplier_number
874 (p_transaction_type_code IN VARCHAR2,
875 p_calling_fn IN VARCHAR2,
876 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
877
878 BEGIN
879 -- From vendor_number_q lov in asset workbench.
880
881 -- Check any dependencies w/ asset type.
882
883 -- Check any dependencies w/ supplier name.
884
885 return TRUE;
886 END validate_supplier_number;
887
888 FUNCTION validate_asset_book
889 (p_transaction_type_code IN VARCHAR2,
890 p_book_type_code IN VARCHAR2,
891 p_asset_id IN NUMBER,
892 p_calling_fn IN VARCHAR2,
893 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
894
895 l_exists number;
896
897 BEGIN
898 -- book controls cache should have already been loaded by calling api
899 -- so this is obsolete: Validate that book exists.
900
901 -- Validate that book is active.
902 if (fa_cache_pkg.fazcbc_record.date_ineffective is not null) then
903
904 fa_srvr_msg.add_message(
905 calling_fn => 'fa_asset_val_pvt.validate_asset_book',
906 name => 'FA_BOOK_INEFFECTIVE_BOOK', p_log_level_rec => p_log_level_rec);
907 return FALSE;
908 end if;
909
910 if ((p_transaction_type_code = 'ADDITION') OR
911 (p_transaction_type_code = 'CIP ADDITION') OR
912 (p_transaction_type_code = 'GROUP ADDITION')) then
913
914 -- Validate that asset does not already exist in book.
915 select count(*)
916 into l_exists
917 from fa_books
918 where book_type_code = p_book_type_code
919 and asset_id = p_asset_id
920 and rownum <= 1;
921
922 if (l_exists > 0) then
923 fa_srvr_msg.add_message(
924 calling_fn => 'fa_asset_val_pvt.validate_asset_book',
925 name => 'FA_MCP_IN_TAX_BOOK',
926 token1 => 'ASSET',
927 value1 => to_char (p_asset_id),
928 token2 => 'BOOK',
929 value2 => p_book_type_code,
930 p_log_level_rec => p_log_level_rec);
931 return FALSE;
932 end if;
933
934 -- For Addition transactions, asset must exist in the Corporate book.
935 if (fa_cache_pkg.fazcbc_record.book_class <> 'CORPORATE') then
936
937 select count(*)
938 into l_exists
939 from fa_books bks
940 where exists
941 (
942 select 'X'
943 from fa_book_controls bc
944 where bc.book_type_code = p_book_type_code
945 and bc.distribution_source_book = bks.book_type_code
946 )
947 and bks.asset_id = p_asset_id;
948
949 if (l_exists = 0) then
950 fa_srvr_msg.add_message(
951 calling_fn => 'fa_asset_val_pvt.validate_asset_book',
952 name => 'FA_MASSCHG_NOT_IN_CORP', p_log_level_rec => p_log_level_rec);
953 return FALSE;
954 end if;
955 end if;
956 else
957 -- for non-addition trxs verify asset does exist in book
958 select count(*)
959 into l_exists
960 from fa_books
961 where book_type_code = p_book_type_code
962 and asset_id = p_asset_id
963 and rownum <= 1;
964
965 if (l_exists = 0) then
966 fa_srvr_msg.add_message(
967 calling_fn => 'fa_asset_val_pvt.validate_asset_book',
968 name => 'FA_EXP_GET_ASSET_INFO', p_log_level_rec => p_log_level_rec);
969 return false;
970 end if;
971
972 if ((p_transaction_type_code = 'TRANSFER' or
973 p_transaction_type_code = 'RECLASS' or
974 p_transaction_type_code = 'UNIT ADJUSTMENT') and
975 fa_cache_pkg.fazcbc_record.book_class <> 'CORPORATE') then
976 fa_srvr_msg.add_message(
977 calling_fn => 'fa_asset_val_pvt.validate_asset_book',
978 name => '***FA_BOOK_NOT_CORP***',
979 p_log_level_rec => p_log_level_rec);
980 return false;
981 end if;
982 end if;
983
984 return TRUE;
985 END validate_asset_book;
986
987 /*Bug 8601485 - Verify the if transfer date of asset is before DPIS */
988 FUNCTION validate_asset_transfer_date
989 (p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
990 p_trans_rec IN FA_API_TYPES.trans_rec_type,
991 p_calling_fn IN VARCHAR2,
992 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
993 x_same_period NUMBER := 0; -- Added for 9643505
994 l_dpis DATE;
995
996 BEGIN
997
998 -- Retrieve the Date placed in service for the asset
999 select date_placed_in_service
1000 into l_dpis
1001 from fa_books
1002 where book_type_code = p_asset_hdr_rec.book_type_code
1003 and asset_id = p_asset_hdr_rec.asset_id
1004 and transaction_header_id_out is null;
1005
1006 BEGIN
1007
1008 SELECT 1
1009 INTO x_same_period
1010 FROM fa_calendar_periods fcp, fa_book_controls fbc
1011 WHERE fbc.book_type_code = p_asset_hdr_rec.book_type_code
1012 AND fcp.calendar_type = fbc.deprn_calendar
1013 AND p_trans_rec.transaction_date_entered BETWEEN
1014 fcp.start_date AND fcp.end_date
1015 AND l_dpis BETWEEN
1016 fcp.start_date AND fcp.end_date;
1017
1018 EXCEPTION
1019 WHEN OTHERS THEN
1020 x_same_period := 0;
1021 END;
1022
1023 if (p_trans_rec.transaction_date_entered < l_dpis) AND (x_same_period = 0) then
1024 return false;
1025 end if;
1026
1027 return TRUE;
1028 END validate_asset_transfer_date;
1029
1030 FUNCTION validate_cost
1031 (p_transaction_type_code IN VARCHAR2,
1032 p_cost IN NUMBER,
1033 p_asset_type IN VARCHAR2,
1034 p_num_invoices IN NUMBER DEFAULT 0,
1035 p_calling_fn IN VARCHAR2,
1036 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1037
1038 BEGIN
1039 -- If asset type is CIP, cost should be zero.
1040 if ((fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE') AND
1041 (p_asset_type = 'CIP') AND (p_cost <> 0) AND (p_num_invoices = 0)) then
1042 fa_srvr_msg.add_message(
1043 calling_fn => 'fa_asset_val_pvt.validate_cost',
1044 name => 'FA_BOOK_CIP_COST', p_log_level_rec => p_log_level_rec);
1045 return FALSE;
1046 elsif (p_asset_type = 'GROUP' and
1047 p_cost <> 0) then
1048 fa_srvr_msg.add_message(
1049 calling_fn => 'fa_asset_val_pvt.validate_cost',
1050 name => '***FA_BOOK_GROUP_COST***',
1051 p_log_level_rec => p_log_level_rec);
1052 return FALSE;
1053 end if;
1054
1055
1056
1057 return TRUE;
1058 END validate_cost;
1059
1060 FUNCTION validate_assigned_to
1061 (p_transaction_type_code IN VARCHAR2,
1062 p_assigned_to IN NUMBER,
1063 p_date IN DATE DEFAULT sysdate,
1064 p_calling_fn IN VARCHAR2,
1065 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1066
1067 l_rowcount number;
1068
1069 BEGIN
1070
1071 -- checks to see if employee is valid
1072 -- checks against p_date, p_date is default to sysdate
1073
1074 if p_assigned_to is not null then
1075
1076 select count(*)
1077 into l_rowcount
1078 from per_periods_of_service s, per_people_f p
1079 where p.person_id = s.person_id
1080 and trunc(p_date) between
1081 p.effective_start_date and p.effective_end_date
1082 and nvl(s.actual_termination_date,p_date) >= p_date
1083 and p.person_id = p_assigned_to;
1084
1085 if (l_rowcount = 0) then
1086 -- bugfix 3854700
1087 fa_srvr_msg.add_message(
1088 calling_fn => 'fa_asset_val_pvt.validate_assigned_to',
1089 name => 'FA_EMP_NOT_VALID' , p_log_level_rec => p_log_level_rec);
1090 return FALSE;
1091 end if;
1092 end if;
1093
1094 return TRUE;
1095
1096 END validate_assigned_to;
1097
1098 FUNCTION validate_location_ccid
1099 (p_transaction_type_code IN VARCHAR2,
1100 p_location_ccid IN NUMBER,
1101 p_calling_fn IN VARCHAR2,
1102 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1103
1104 l_is_location_valid number;
1105
1106 BEGIN
1107
1108 -- The location ccid cannot be null.
1109 if (p_location_ccid is null) then
1110 fa_srvr_msg.add_message(
1111 calling_fn => 'fa_asset_val_pvt.validate_location_ccid',
1112 name => 'FA_NULL_LOCATION', p_log_level_rec => p_log_level_rec);
1113 return FALSE;
1114 end if;
1115
1116 -- Check that location exists.
1117 select count(*)
1118 into l_is_location_valid
1119 from fa_locations
1120 where location_id = p_location_ccid
1121 and enabled_flag = 'Y';
1122
1123 if (l_is_location_valid = 0) then
1124 fa_srvr_msg.add_message(
1125 calling_fn => 'fa_asset_val_pvt.validate_location_ccid',
1126 name => 'FA_INCORRECT_LOCATION',
1127 token1 => 'LOCATION_ID',
1128 value1 => p_location_ccid, p_log_level_rec => p_log_level_rec);
1129 return FALSE;
1130 end if;
1131
1132 return TRUE;
1133
1134 END validate_location_ccid;
1135
1136 --bug 5501090: Added parameter p_asset_type
1137 FUNCTION validate_dpis
1138 (p_transaction_type_code IN VARCHAR2,
1139 p_book_type_code IN VARCHAR2,
1140 p_date_placed_in_service IN DATE,
1141 p_prorate_convention_code IN VARCHAR2 DEFAULT NULL,
1142 p_old_date_placed_in_service IN DATE DEFAULT NULL,
1143 p_asset_id IN NUMBER DEFAULT NULL,
1144 p_db_rule_name IN VARCHAR2 DEFAULT NULL, -- ENERGY
1145 p_rate_source_rule IN VARCHAR2 DEFAULT NULL, -- ENERGY
1146 p_transaction_subtype IN VARCHAR2 DEFAULT 'EXPENSED',
1147 p_asset_type IN VARCHAR2 DEFAULT NULL ,
1148 p_calling_interface IN VARCHAR2 DEFAULT NULL,
1149 p_calling_fn IN VARCHAR2,
1150 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1151 --
1152 -- NOTE: ENERGY ENHANCEMENT
1153 -- p_db_rule_name and p_rate_source_rule are added so that prior
1154 -- period date will not be allowed. p_db_rule_name is depreciable basis
1155 -- rule name.
1156 --
1157 -- NOTE: Bug:3724207
1158 -- p_old_date_placed_in_service and p_asset_id are populated from
1159 -- calc_fin_info(FAVCALB.pls) and not when this is called from otherplaces
1160 --
1161 -- Following cursor will fetch record if there is a transaction between addition and
1162 -- new dpis. However following transaction will be excluded.
1163 -- ADDITION, ADDITION/VOID, GROUP ADDITION/VOID, GROUP ADDITION, REINSTATEMENT,
1164 -- TRANSFER IN, TRANSFER IN/VOID, and any retirement which has been reinstated
1165 --
1166 CURSOR c_chk_trx_before_dpis is
1167 SELECT TH.TRANSACTION_HEADER_ID
1168 FROM FA_TRANSACTION_HEADERS TH
1169 WHERE TH.ASSET_ID = p_asset_id
1170 AND TH.BOOK_TYPE_CODE = p_book_type_code
1171 AND TH.TRANSACTION_TYPE_CODE IN ('ADJUSTMENT', 'GROUP ADJUSTMENT', 'REVALUATION', 'TAX')
1172 AND NVL(TH.AMORTIZATION_START_DATE, TH.TRANSACTION_DATE_ENTERED)
1173 < p_date_placed_in_service
1174 UNION
1175 SELECT TH.TRANSACTION_HEADER_ID
1176 FROM FA_TRANSACTION_HEADERS TH,
1177 FA_RETIREMENTS RET
1178 WHERE TH.ASSET_ID = p_asset_id
1179 AND TH.BOOK_TYPE_CODE = p_book_type_code
1180 AND TH.TRANSACTION_TYPE_CODE IN
1181 ('FULL RETIREMENT', 'PARTIAL RETIREMENT')
1182 AND NVL(TH.AMORTIZATION_START_DATE, TH.TRANSACTION_DATE_ENTERED)
1183 < p_date_placed_in_service
1184 AND RET.ASSET_ID = TH.ASSET_ID
1185 AND RET.BOOK_TYPE_CODE = TH.BOOK_TYPE_CODE
1186 AND RET.TRANSACTION_HEADER_ID_IN = TH.TRANSACTION_HEADER_ID
1187 AND RET.TRANSACTION_HEADER_ID_OUT IS NULL;
1188
1189 l_dpis_jdate number;
1190 l_dpis_fy number;
1191 l_dpis_per_num number;
1192 l_start_jdate number;
1193
1194 l_earliest_dpis date;
1195 l_count number;
1196 l_period_rec FA_API_TYPES.period_rec_type;
1197
1198 l_prorate_date date;
1199 l_check_prorate_date varchar2(1);
1200 l_temp_num number;
1201
1202 BEGIN
1203
1204 if (nvl(fa_cache_pkg.fazcbc_record.book_type_code, '-NULL') <>
1205 p_book_type_code) then
1206 if (NOT fa_cache_pkg.fazcbc (
1207 X_book => p_book_type_code
1208 )) then
1209 fa_srvr_msg.add_message(
1210 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1211 name => 'FA_POST_INVALID_BOOK');
1212 return FALSE;
1213 end if;
1214 end if;
1215
1216 -- Validate that dpis passes the LOW_RANGE criteria (fa_date.validate)
1217 if (p_date_placed_in_service < to_date('1000/01/01', 'YYYY/MM/DD')) then
1218 fa_srvr_msg.add_message(
1219 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1220 name => 'FA_YEAR_GREATER_THAN', p_log_level_rec => p_log_level_rec);
1221 return FALSE;
1222 end if;
1223
1224 -- Check that dpis is not too old.
1225 if not fa_cache_pkg.fazsys(p_log_level_rec => p_log_level_rec) then
1226 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate_dpis', p_log_level_rec => p_log_level_rec);
1227 return false;
1228 else
1229 l_earliest_dpis := fa_cache_pkg.fazsys_record.date_placed_in_service;
1230 end if;
1231
1232 if (p_date_placed_in_service < l_earliest_dpis) then
1233 fa_srvr_msg.add_message(
1234 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1235 name => 'FA_BOOK_DPIS_TOO_OLD', p_log_level_rec => p_log_level_rec);
1236 return FALSE;
1237 end if;
1238
1239 -- Not prior period transaction allowed for asset with
1240 -- Energy UOP
1241 if (p_db_rule_name = 'ENERGY PERIOD END BALANCE' and
1242 p_rate_source_rule = 'PRODUCTION') then
1243
1244 if not FA_UTIL_PVT.get_period_rec
1245 (p_book => p_book_type_code,
1246 p_effective_date => NULL,
1247 x_period_rec => l_period_rec, p_log_level_rec => p_log_level_rec) then
1248
1249 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate_dpis', p_log_level_rec => p_log_level_rec);
1250 return false;
1251 end if;
1252
1253 if (p_date_placed_in_service <> nvl(p_old_date_placed_in_service, p_date_placed_in_service) ) and
1254 (p_date_placed_in_service < l_period_rec.calendar_period_open_date) then
1255
1256 if (p_log_level_rec.statement_level) then
1257 fa_debug_pkg.add('fa_asset_val_pvt.validate_dpis', 'Error', p_date_placed_in_service, p_log_level_rec => p_log_level_rec);
1258 end if;
1259
1260 fa_srvr_msg.add_message(
1261 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1262 name => 'FA_CURRENT_DATE_ONLY', p_log_level_rec => p_log_level_rec);
1263 return FALSE;
1264 end if;
1265
1266 end if; -- (p_db_rule_name = 'ENERGY PERIOD END BALANCE' and
1267
1268 /* BUG# 875160 and 2144557 and 4146025
1269 * we allow future adds in masscp, and cip-in-tax
1270 * lifting this restriction from the apis. will need to
1271 * place this in form, etc if we wish to keep it there. --bmr
1272 */
1273
1274 -- Fix for Bug #2621438. Only validate this from FAXASSET
1275 if ((p_calling_fn in ('faxasset.fa_books_val2.dpis_val',
1276 'faxasset.fa_addition_books.date_placed_in_service')
1277 or (p_calling_interface = 'FAMAPT') )
1278 ) then
1279
1280 -- Check that dpis is not in a future period.
1281 if not FA_UTIL_PVT.get_period_rec
1282 (p_book => p_book_type_code,
1283 p_effective_date => NULL,
1284 x_period_rec => l_period_rec
1285 , p_log_level_rec => p_log_level_rec) then
1286 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate_dpis', p_log_level_rec => p_log_level_rec);
1287 return false;
1288 end if;
1289
1290 if (p_date_placed_in_service > l_period_rec.calendar_period_close_date) then
1291 fa_srvr_msg.add_message(
1292 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1293 name => 'FA_BOOK_FUTURE_PERIOD_DPIS', p_log_level_rec => p_log_level_rec);
1294 return FALSE;
1295 end if;
1296
1297
1298 -- Check that prorate calendars and conventions are setup for this dpis.
1299 -- Will only be called from faxasset since it can be a performance
1300 -- issue in mass processes and is kind of redundant with validations
1301 -- that occur in the calculation engine.
1302 if (p_prorate_convention_code is not null) then
1303
1304 begin
1305 select prorate_date
1306 into l_prorate_date
1307 from fa_conventions
1308 where prorate_convention_code = p_prorate_convention_code
1309 and p_date_placed_in_service between start_date and end_date;
1310
1311 exception
1312 when others then
1313 fa_srvr_msg.add_message(
1314 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1315 name => 'FA_BOOK_CANT_GEN_PRORATE_DATE', p_log_level_rec => p_log_level_rec);
1316 return FALSE;
1317 end;
1318
1319 -- Check that prorate date is defined for given dpis.
1320 begin
1321 select 'x'
1322 into l_check_prorate_date
1323 from fa_calendar_periods cp,
1324 fa_book_controls bc
1325 where bc.book_type_code = p_book_type_code
1326 and bc.prorate_calendar = cp.calendar_type
1327 and l_prorate_date between cp.start_date and cp.end_date;
1328
1329 exception
1330 when others then
1331 fa_srvr_msg.add_message(
1332 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1333 name => 'FA_BKS_INVALID_PRORATE_DATE', p_log_level_rec => p_log_level_rec);
1334 return FALSE;
1335 end;
1336
1337 end if;
1338 end if;
1339
1340 -- Check to see if calendar periods are setup
1341 l_dpis_jdate := to_number(to_char(p_date_placed_in_service,'J'));
1342
1343 if (not fa_cache_pkg.fazccp (
1344 X_target_calendar => fa_cache_pkg.fazcbc_record.deprn_calendar,
1345 X_target_fy_name => fa_cache_pkg.fazcbc_record.fiscal_year_name,
1346 X_target_jdate => l_dpis_jdate,
1347 X_period_num => l_dpis_per_num,
1348 X_fiscal_year => l_dpis_fy,
1349 X_start_jdate => l_start_jdate
1350 , p_log_level_rec => p_log_level_rec)) then
1351 fa_srvr_msg.add_message(
1352 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1353 name => 'FA_PROD_INCORRECT_DATE', p_log_level_rec => p_log_level_rec);
1354 return FALSE;
1355 end if;
1356
1357 -- Bug:3724207
1358 -- We should not allow dpis change when there is a transaction between addition and
1359 -- new dpis. However following transaction will be excluded.
1360 -- ADDITION, ADDITION/VOID, GROUP ADDITION/VOID, GROUP ADDITION, REINSTATEMENT,
1361 -- TRANSFER IN, TRANSFER IN/VOID, and any retirement which has been reinstated
1362 -- Bug 4246638: Add dist-related transactions to exclusion list
1363 --
1364 if p_transaction_subtype <> 'EXPENSED' and (p_date_placed_in_service <>
1365 nvl(p_old_date_placed_in_service, p_date_placed_in_service)) then
1366 OPEN c_chk_trx_before_dpis;
1367 FETCH c_chk_trx_before_dpis INTO l_temp_num;
1368
1369 if (c_chk_trx_before_dpis%FOUND) then
1370 CLOSE c_chk_trx_before_dpis;
1371
1372 -- Use message FA_AMORT_DATE_INVALID until new message
1373 -- FA_INVALID_DPIS is available
1374 fa_srvr_msg.add_message(
1375 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1376 -- name => 'FA_INVALID_DPIS', p_log_level_rec => p_log_level_rec);
1377 name => 'FA_AMORT_DATE_INVALID',
1378 p_log_level_rec => p_log_level_rec);
1379 return FALSE;
1380 end if;
1381
1382 CLOSE c_chk_trx_before_dpis;
1383
1384 end if; -- (p_date_placed_in_service <>
1385
1386 return TRUE;
1387
1388 END validate_dpis;
1389
1390 FUNCTION validate_rec_cost_reserve
1391 (p_transaction_type_code IN VARCHAR2,
1392 p_recoverable_cost IN NUMBER,
1393 p_deprn_reserve IN NUMBER,
1394 p_calling_fn IN VARCHAR2,
1395 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1396
1397 BEGIN
1398
1399 if (p_deprn_reserve <> 0 and
1400 (abs(p_recoverable_cost) < abs(p_deprn_reserve) or
1401 (sign(p_recoverable_cost) <> 0 and
1402 sign(p_recoverable_cost) = -sign(p_deprn_reserve)))) then
1403 fa_srvr_msg.add_message(
1404 calling_fn => 'validate_rec_cost_reserve',
1405 name => 'FA_BOOK_INVALID_RESERVE', p_log_level_rec => p_log_level_rec);
1406 return FALSE;
1407 end if;
1408
1409 return TRUE;
1410
1411 END validate_rec_cost_reserve;
1412
1413 FUNCTION validate_adj_rec_cost
1414 (p_adjusted_recoverable_cost IN NUMBER,
1415 p_deprn_reserve IN NUMBER,
1416 p_calling_fn IN VARCHAR2,
1417 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1418
1419 BEGIN
1420
1421 /* Added if condition for bug 863321 */
1422 IF ( (fa_cache_pkg.fazccmt_record.rate_source_rule <> 'PRODUCTION'
1423 or nvl(fa_cache_pkg.fazcdrd_record.rule_name,'ZZ') <> 'ENERGY PERIOD END BALANCE')
1424 and
1425 nvl(fa_cache_pkg.fazcdrd_record.rule_name,'ZZ') <> 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT' /*bug#16426081*/
1426 ) THEN
1427 if (abs(p_adjusted_recoverable_cost) < abs(p_deprn_reserve) or
1428 (sign(p_adjusted_recoverable_cost) <> 0 and
1429 sign(p_adjusted_recoverable_cost) = -sign(p_deprn_reserve))) then
1430 fa_srvr_msg.add_message(
1431 calling_fn => 'fa_asset_val_pvt.val_adj_rec_cost',
1432 name => 'FA_BOOK_INVALID_RESERVE', p_log_level_rec => p_log_level_rec);
1433 return FALSE;
1434 end if;
1435
1436 END IF;
1437 return TRUE;
1438
1439 END validate_adj_rec_cost;
1440
1441 FUNCTION validate_ytd_reserve /*Bug#9682863 - Modified the parameters/body - using recs now instead of individual parameter. */
1442 (p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
1443 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
1444 p_asset_fin_rec_new IN FA_API_TYPES.asset_fin_rec_type,
1445 p_asset_deprn_rec_new IN FA_API_TYPES.asset_deprn_rec_type,
1446 p_period_rec IN FA_API_TYPES.period_rec_type,
1447 p_asset_deprn_rec_old IN FA_API_TYPES.asset_deprn_rec_type, /*Fix for bug 8790562 */
1448 p_calling_fn IN VARCHAR2,
1449 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
1450
1451 l_current_fiscal_year FA_BOOK_CONTROLS.current_fiscal_year%TYPE;
1452 l_fiscal_year_name FA_BOOK_CONTROLS.fiscal_year_name%TYPE;
1453
1454 l_same_fiscal_year NUMBER;
1455 l_abs_deprn_reserve NUMBER;
1456 l_abs_ytd_deprn NUMBER;
1457
1458 BEGIN
1459
1460 -- no need to load book controls cache as it's loaded
1461 l_current_fiscal_year := fa_cache_pkg.fazcbc_record.current_fiscal_year;
1462 l_fiscal_year_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
1463
1464 -- Get absolute values.
1465 l_abs_deprn_reserve := abs (nvl(p_asset_deprn_rec_new.deprn_reserve, 0));
1466 l_abs_ytd_deprn := abs (nvl(p_asset_deprn_rec_new.ytd_deprn, 0));
1467
1468 -- no reserve for non capitalized assets
1469 if ((p_asset_type_rec.asset_type <> 'CAPITALIZED') and
1470 (nvl(p_asset_deprn_rec_new.deprn_reserve, 0) <> 0 or
1471 nvl(p_asset_deprn_rec_new.ytd_deprn, 0) <> 0 or
1472 nvl(p_asset_deprn_rec_new.bonus_ytd_deprn, 0) <> 0 or
1473 nvl(p_asset_deprn_rec_new.bonus_deprn_reserve, 0) <> 0 or
1474 nvl(p_asset_deprn_rec_new.ytd_impairment, 0) <> 0 or
1475 nvl(p_asset_deprn_rec_new.impairment_reserve, 0) <> 0 or
1476 nvl(p_asset_deprn_rec_new.reval_deprn_reserve, 0) <> 0 or
1477 nvl(p_asset_deprn_rec_new.reval_ytd_deprn, 0) <> 0 or
1478 nvl(p_asset_fin_rec_new.reval_amortization_basis, 0) <> 0 or
1479 nvl(p_asset_fin_rec_new.fully_rsvd_revals_counter, 0) <> 0)) then
1480 fa_srvr_msg.add_message(
1481 calling_fn => 'fa_asset_val_pvt.validate_ytd_reserve',
1482 name => 'FA_BOOK_INVALID_RESERVE', p_log_level_rec => p_log_level_rec);
1483 return FALSE;
1484 end if;
1485
1486
1487 -- ytd, ltd deprn validations from fa_books_trx3.when_validate_record
1488 -- in FAXASSET.
1489
1490 -- Bug 7229863: Validation for preventing ytd/reserve change
1491 -- if the asset is not backdated
1492 /* Fix for Bug #2429665. Should not have this validation.*/
1493 -- verify no reserve for asset in first period of life
1494 if (p_asset_fin_rec_new.prorate_date >= p_period_rec.calendar_period_open_date and
1495 p_asset_fin_rec_new.date_placed_in_service >= p_period_rec.calendar_period_open_date and
1496 (p_asset_deprn_rec_new.deprn_reserve <> 0 or
1497 p_asset_deprn_rec_new.ytd_deprn <> 0)) then
1498 fa_srvr_msg.add_message(
1499 calling_fn => 'fa_asset_val_pvt.validate_ytd_reserve',
1500 name => 'FA_NO_RSV_IN_FIRST_PERIOD', p_log_level_rec => p_log_level_rec);
1501 return false;
1502 end if;
1503 /*Fix for bug 8790562 - Not allowing reserve to be Zero*/
1504 if (p_asset_fin_rec_new.prorate_date >= p_period_rec.calendar_period_open_date and
1505 p_asset_fin_rec_new.date_placed_in_service >= p_period_rec.calendar_period_open_date and
1506 (p_asset_deprn_rec_old.ytd_deprn <> 0 and p_asset_deprn_rec_old.deprn_reserve <> 0) and
1507 (p_asset_deprn_rec_new.deprn_reserve = 0 or p_asset_deprn_rec_new.ytd_deprn = 0)) then
1508 fa_srvr_msg.add_message(
1509 calling_fn => 'fa_asset_val_pvt.validate_ytd_reserve',
1510 name => 'FA_NO_RSV_IN_FIRST_PERIOD', p_log_level_rec => p_log_level_rec);
1511 return false;
1512 end if;
1513
1514 -- in first year of life ytd must equal reserve
1515 if (p_asset_fin_rec_new.prorate_date >= p_period_rec.fy_start_date and
1516 p_asset_fin_rec_new.prorate_date <= p_period_rec.fy_end_date) then
1517 if (p_asset_deprn_rec_new.ytd_deprn <> p_asset_deprn_rec_new.deprn_reserve) then
1518 fa_srvr_msg.add_message(
1519 calling_fn => 'fa_asset_val_pvt.validate_ytd_reserve',
1520 name => 'FA_BOOK_RSV_EQL_YTD', p_log_level_rec => p_log_level_rec);
1521 return FALSE;
1522 end if;
1523 else
1524 -- BUG# 2341201
1525 -- need to consider the signs as well since due to historical
1526 -- data it is posible to have a negative ytd larger than the
1527 -- positive reserve - BMR
1528
1529 if (((sign(p_asset_deprn_rec_new.ytd_deprn) = sign(p_asset_deprn_rec_new.deprn_reserve)) or
1530 (sign(p_asset_deprn_rec_new.ytd_deprn) = 0) or
1531 (sign(p_asset_deprn_rec_new.deprn_reserve) = 0)) and
1532 (l_abs_ytd_deprn > l_abs_deprn_reserve)) then
1533 fa_srvr_msg.add_message(
1534 calling_fn => 'fa_asset_val_pvt.validate_ytd_reserve',
1535 name => 'FA_BOOK_YTD_EXCEED_RSV', p_log_level_rec => p_log_level_rec);
1536 return FALSE;
1537 end if;
1538 end if;
1539
1540 return TRUE;
1541
1542 EXCEPTION
1543 when others then
1544 fa_srvr_msg.add_sql_error(
1545 calling_fn => 'fa_asset_val_pvt.validate_ytd_reserve', p_log_level_rec => p_log_level_rec);
1546 return false;
1547
1548 END validate_ytd_reserve;
1549
1550 FUNCTION validate_short_tax_year
1551 (p_book_type_code IN VARCHAR2,
1552 p_transaction_type_code IN VARCHAR2,
1553 p_asset_type IN VARCHAR2,
1554 p_short_fiscal_year_flag IN VARCHAR2,
1555 p_conversion_date IN DATE,
1556 px_orig_deprn_start_date IN OUT NOCOPY DATE,
1557 p_date_placed_in_service IN DATE,
1558 p_ytd_deprn IN NUMBER,
1559 p_deprn_reserve IN NUMBER,
1560 p_period_rec IN FA_API_TYPES.period_rec_type,
1561 p_calling_fn IN VARCHAR2,
1562 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1563
1564 l_abs_ytd_deprn number;
1565 l_abs_deprn_reserve number;
1566
1567 BEGIN
1568
1569 -- The short_fiscal_year_flag should be YES or NO.
1570 if not ((p_short_fiscal_year_flag = 'YES') OR
1571 (p_short_fiscal_year_flag = 'NO')) then
1572 fa_srvr_msg.add_message(
1573 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1574 name => 'FA_INCORRECT_SHORT_FY_FLAG',
1575 token1 => 'SHORT_FY_FLAG',
1576 value1 => p_short_fiscal_year_flag, p_log_level_rec => p_log_level_rec);
1577 return FALSE;
1578 end if;
1579
1580 -- The short_fiscal_year_flag cannot be YES is the asset is not CAPITALIZED.
1581 if ((p_asset_type <> 'CAPITALIZED') AND
1582 (p_short_fiscal_year_flag = 'YES')) then
1583 fa_srvr_msg.add_message(
1584 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1585 name => 'FA_CANT_SET_SHORT_FY_FLAG', p_log_level_rec => p_log_level_rec);
1586 return FALSE;
1587 end if;
1588
1589 -- The conversion date cannot be null if the short_fiscal_year_flag is YES.
1590 if ((p_short_fiscal_year_flag = 'YES') AND
1591 (p_conversion_date is NULL)) then
1592 fa_srvr_msg.add_message(
1593 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1594 name => 'FA_MUST_SET_CONV_DATE', p_log_level_rec => p_log_level_rec);
1595 return FALSE;
1596 end if;
1597
1598 -- May default orig_deprn_start_date if short_fiscal_year_flag is YES.
1599 if ((p_short_fiscal_year_flag = 'YES') AND
1600 (px_orig_deprn_start_date is NULL)) then
1601 px_orig_deprn_start_date := p_date_placed_in_service;
1602 end if;
1603
1604 -- For creating new asset (non-add_to_asset) transactions, conversion
1605 -- date cannot have a value if short_fiscal_year_flag is not YES.
1606 if (((p_transaction_type_code <> 'ADDITION') OR
1607 (p_transaction_type_code <> 'CIP ADDITION')) AND
1608 (p_short_fiscal_year_flag <> 'YES') AND
1609 (p_conversion_date is not NULL)) then
1610 fa_srvr_msg.add_message(
1611 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1612 name => 'FA_CONV_DATE_NO_VAL',
1613 token1 => 'CONV_DATE',
1614 value1 => p_conversion_date, p_log_level_rec => p_log_level_rec);
1615 return FALSE;
1616 end if;
1617
1618 -- For creating new asset (non-add_to_asset) transactions, orig deprn start
1619 -- date cannot have a value if short_fiscal_year_flag is not YES.
1620 if (((p_transaction_type_code <> 'ADDITION') OR
1621 (p_transaction_type_code <> 'CIP ADDITION')) AND
1622 (p_short_fiscal_year_flag <> 'YES') AND
1623 (px_orig_deprn_start_date is not NULL)) then
1624 fa_srvr_msg.add_message(
1625 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1626 name => 'FA_CONV_DATE_NO_VAL',
1627 token1 => 'CONV_DATE',
1628 value1 => px_orig_deprn_start_date, p_log_level_rec => p_log_level_rec);
1629 return FALSE;
1630 end if;
1631
1632 -- Conversion date must fall in the current open period which also means
1633 -- reserve up until conversion must be provided.
1634 if (p_conversion_date is not null) then
1635 if (p_conversion_date < p_period_rec.calendar_period_open_date or
1636 p_conversion_date > p_period_rec.calendar_period_close_date) then
1637 fa_srvr_msg.add_message(
1638 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1639 name => 'FA_INCORRECT_CONV_DATE',
1640 token1 => 'CONV_DATE',
1641 value1 => p_conversion_date, p_log_level_rec => p_log_level_rec);
1642 return FALSE;
1643 end if;
1644
1645 -- Validate conversion_date <> current fiscal year end date.
1646 if (p_conversion_date = p_period_rec.fy_end_date) then
1647 fa_srvr_msg.add_message(
1648 calling_fn => 'fa_asset_val_pvt.validate_short_tax_year',
1649 name => 'FA_CONV_DATE_EQU_CURR_FYEND', p_log_level_rec => p_log_level_rec);
1650 return FALSE;
1651 end if;
1652 end if;
1653
1654 return TRUE;
1655
1656 END validate_short_tax_year;
1657
1658 FUNCTION validate_trx_date_entered
1659 (p_transaction_type_code IN VARCHAR2,
1660 p_book_type_code IN VARCHAR2,
1661 p_transaction_date_entered IN DATE,
1662 p_period_rec IN FA_API_TYPES.period_rec_type,
1663 p_calling_fn IN VARCHAR2,
1664 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1665
1666 begin
1667
1668 if (p_transaction_date_entered > p_period_rec.calendar_period_close_date) then
1669 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate_trx_date_entered',
1670 name => 'FA_SHARED_CANNOT_FUTURE',
1671 p_log_level_rec => p_log_level_rec);
1672 return FALSE;
1673 end if;
1674
1675 return TRUE;
1676
1677 end validate_trx_date_entered;
1678
1679 FUNCTION validate_amort_start_date
1680 (p_transaction_type_code IN VARCHAR2,
1681 p_asset_id IN NUMBER,
1682 p_book_type_code IN VARCHAR2,
1683 p_date_placed_in_service IN DATE DEFAULT NULL,
1684 p_conversion_date IN DATE DEFAULT NULL,
1685 p_period_rec IN FA_API_TYPES.period_rec_type,
1686 p_amortization_start_date IN DATE,
1687 p_db_rule_name IN VARCHAR2 DEFAULT NULL, -- ENERGY
1688 p_rate_source_rule IN VARCHAR2 DEFAULT NULL, -- ENERGY
1689 p_transaction_key IN VARCHAR2 DEFAULT 'XX',
1690 x_amortization_start_date OUT NOCOPY DATE,
1691 x_trxs_exist OUT NOCOPY VARCHAR2,
1692 p_calling_fn IN VARCHAR2,
1693 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1694
1695 l_transaction_date date;
1696 l_period_close_date date;
1697 l_period_open_date date;
1698 l_prior_transaction_date date;
1699 l_prior_date_effective date;
1700 l_amort_date date;
1701 l_avail_date date;
1702 l_count number;
1703 l_dpis_jdate number;
1704 l_amort_jdate number;
1705 l_dpis_fy number;
1706 l_amort_fy number;
1707 l_dpis_per_num number;
1708 l_amort_per_num number;
1709 l_fy_name varchar2(45);
1710 l_cal_type varchar2(15);
1711 l_start_jdate number;
1712 l_period_rec FA_API_TYPES.period_rec_type;
1713 l_calling_fn varchar2(40) := 'fa_asset_val_pvt.val_amort_date';
1714 error_found exception;
1715
1716 begin
1717
1718 x_amortization_start_date := p_amortization_start_date;
1719
1720 if (p_amortization_start_date is not null) then
1721
1722 -- sets to Y if any txn exist between current period
1723 -- and amortization period
1724 x_trxs_exist := 'N';
1725
1726 -- x_amortization_start_date cannot be future period
1727 l_transaction_date := greatest(p_period_rec.calendar_period_open_date,
1728 least(sysdate,
1729 p_period_rec.calendar_period_close_date));
1730 l_period_close_date := p_period_rec.calendar_period_close_date;
1731 l_period_open_date := p_period_rec.calendar_period_open_date;
1732
1733 if (x_amortization_start_date > l_period_close_date) then
1734 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
1735 name => 'FA_SHARED_CANNOT_FUTURE',
1736 p_log_level_rec => p_log_level_rec);
1737 return FALSE;
1738 end if;
1739
1740 -- x_amortization_start_date cannot be less than DPIS
1741 if (p_amortization_start_date < p_date_placed_in_service) then
1742 x_amortization_start_date := p_date_placed_in_service;
1743 x_trxs_exist := 'Y';
1744 end if;
1745
1746 -- get book controls info from cache
1747 -- assumes cache has been called
1748 l_fy_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
1749 l_cal_type := fa_cache_pkg.fazcbc_record.deprn_calendar;
1750
1751 -- checks if amort start date is valid
1752 l_amort_jdate := to_number(to_char(x_amortization_start_date,'J'));
1753 if (not fa_cache_pkg.fazccp
1754 (l_cal_type,
1755 l_fy_name,
1756 l_amort_jdate,
1757 l_amort_per_num,
1758 l_amort_fy,
1759 l_start_jdate, p_log_level_rec => p_log_level_rec)) then
1760 fa_srvr_msg.add_message(
1761 calling_fn => l_calling_fn,
1762 name => 'FA_PROD_INCORRECT_DATE', p_log_level_rec => p_log_level_rec);
1763 return FALSE;
1764 end if;
1765
1766 /****
1767 ** Bug3218011
1768 ** output parameter x_trxs_exist is not used so comment out follwoing
1769 ** 2 sql
1770 **
1771 -- removed section comparing fys as it was commented out
1772 -- check if amort start date is eariler than
1773 -- previous txn date, set txns_exist
1774 select MAX(transaction_date_entered),
1775 MAX(date_effective)
1776 into l_prior_transaction_date,
1777 l_prior_date_effective
1778 from fa_transaction_headers
1779 where asset_id = p_asset_id
1780 and book_type_code = p_book_type_code;
1781
1782 if (x_amortization_start_date < l_prior_transaction_date) then
1783 x_trxs_exist := 'Y';
1784 end if;
1785
1786 select count(*)
1787 into l_count
1788 from fa_deprn_periods pdp,
1789 fa_deprn_periods adp
1790 where pdp.book_type_code = p_book_type_code
1791 and pdp.book_type_code = adp.book_type_code
1792 and pdp.period_counter > adp.period_counter
1793 and l_prior_date_effective between pdp.period_open_date
1794 and nvl(pdp.period_close_date, to_date('31-12-4712','DD-MM-YYYY'))
1795 and x_amortization_start_date between
1796 adp.calendar_period_open_date and adp.calendar_period_close_date;
1797
1798 if (l_count > 0) then
1799 x_trxs_exist := 'Y';
1800 end if;
1801
1802 **
1803 ** End of Bug3218011
1804 ****/
1805
1806 -- Not prior period transaction allowed for asset with
1807 -- Energy UOP
1808 if (p_db_rule_name = 'ENERGY PERIOD END BALANCE' and
1809 p_rate_source_rule = 'PRODUCTION' and
1810 p_transaction_key <> 'MS') then
1811
1812 if (p_amortization_start_date < p_period_rec.calendar_period_open_date) then
1813 if (p_log_level_rec.statement_level) then
1814 fa_debug_pkg.add(l_calling_fn, 'Error', p_date_placed_in_service, p_log_level_rec => p_log_level_rec);
1815 end if;
1816 fa_srvr_msg.add_message(
1817 calling_fn => 'fa_asset_val_pvt.validate_dpis',
1818 name => 'FA_CURRENT_DATE_ONLY', p_log_level_rec => p_log_level_rec);
1819 return FALSE;
1820 end if;
1821
1822 end if; -- (p_db_rule_name = 'ENERGY PERIOD END BALANCE' and
1823
1824 -- check to see if any retire/reinstate/reval txn is in between
1825 -- x_new_amort_start_date and current_period.
1826 -- this check covers for the prior period retire/reinste/reval
1827 -- set x_new_amort_start_date := latest txn date
1828
1829 -- bug 3188779
1830 -- do not redefault at this point, but error and force
1831 -- user to pick a new date. also no need to prevent
1832 -- overlaps to a retirement either except in the case of
1833 -- group reclass which is done seperately in FAVCALB.pls.
1834 --
1835 -- changing logic to compare max(trx_date) to the amort date here too.
1836
1837 select MAX(transaction_date_entered) -- date_effective
1838 into l_prior_transaction_date -- l_prior_date_effective
1839 from fa_transaction_headers
1840 where asset_id = p_asset_id
1841 and book_type_code = p_book_type_code
1842 and transaction_type_code in
1843 ('REVALUATION');
1844 --('PARTIAL RETIREMENT','REINSTATEMENT','REVALUATION');
1845
1846
1847 if (x_amortization_start_date < l_prior_transaction_date) then
1848 fa_srvr_msg.add_message(
1849 calling_fn => l_calling_fn,
1850 name => 'FA_SHARED_OTHER_TRX_FOLLOW', p_log_level_rec => p_log_level_rec);
1851 raise error_found;
1852 end if;
1853
1854 /*
1855 if (l_prior_date_effective is not null) then
1856
1857 -- get the latest available date
1858 -- use get_period rec and period cache
1859
1860 if not FA_UTIL_PVT.get_period_rec
1861 (p_book => p_book_type_code,
1862 p_effective_date => l_prior_date_effective,
1863 x_period_rec => l_period_rec, p_log_level_rec => p_log_level_rec) then
1864 raise error_found;
1865 end if;
1866
1867 l_amort_date := greatest(l_period_rec.calendar_period_open_date,
1868 least(SYSDATE,
1869 l_period_rec.calendar_period_close_date));
1870
1871 if (x_amortization_start_date < l_amort_date) then
1872 x_amortization_start_date := l_amort_date;
1873 end if;
1874 end if;
1875 */
1876
1877 -- NOTE: code for validating amort date to conversion date has been removed
1878
1879 end if; -- amort date not null
1880
1881 return TRUE;
1882
1883 exception
1884 when error_found then
1885 fa_srvr_msg.add_message(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1886 return FALSE;
1887
1888 when others then
1889 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
1890 return false;
1891
1892 end validate_amort_start_date;
1893
1894
1895
1896 FUNCTION validate_life
1897 (p_deprn_method IN VARCHAR2,
1898 p_rate_source_rule IN VARCHAR2,
1899 p_life_in_months IN NUMBER,
1900 p_lim IN NUMBER,
1901 p_user_id IN NUMBER,
1902 p_curr_date IN DATE,
1903 px_new_life IN OUT NOCOPY NUMBER,
1904 p_calling_fn IN VARCHAR2,
1905 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
1906
1907 l_method_id number;
1908 l_rowid rowid;
1909
1910 l_method_id_old number;
1911 l_method_name fa_methods.name%type;
1912 l_deprn_basis_rule varchar2(4);
1913 l_stl_method_flag varchar2(3);
1914 l_dep_last_year_flag varchar2(3);
1915 l_exclude_sal_flag varchar2(3);
1916 l_polish_adj_calc_basis_flag varchar2(1);
1917 l_guarantee_rate_method_flag varchar2(3);
1918 l_original_rate number;
1919 l_revised_rate number;
1920 l_guarantee_rate number;
1921
1922 l_formula_actual varchar2(4000);
1923 l_formula_displayed varchar2(4000);
1924 l_formula_parsed varchar2(4000);
1925
1926 -- note due to formula changes, we are joining
1927 -- to the life of the category. Since we would not
1928 -- be entering this function is the method and life
1929 -- existed, the current method in cache will be that
1930 -- of the category. Thus we'll use that life in order
1931 -- to determine the correct formula to pull for new method.
1932
1933 CURSOR METHOD_DEF (p_deprn_method varchar2,
1934 p_life_in_months number) IS
1935 SELECT DISTINCT
1936 method_id,
1937 name,
1938 deprn_basis_rule,
1939 depreciate_lastyear_flag,
1940 stl_method_flag,
1941 exclude_salvage_value_flag,
1942 polish_adj_calc_basis_flag,
1943 guarantee_rate_method_flag
1944 FROM FA_METHODS
1945 WHERE METHOD_CODE = p_deprn_method
1946 AND LIFE_IN_MONTHS = p_life_in_months;
1947
1948 CURSOR C_FORMULA (p_method_id number) IS
1949 SELECT formula_actual,
1950 formula_displayed,
1951 formula_parsed,
1952 original_rate,
1953 revised_rate,
1954 guarantee_rate
1955 FROM FA_FORMULAS
1956 WHERE method_id = p_method_id;
1957
1958 l_calling_fn varchar2(35) := 'fa_asset_val_pvt.validate_life';
1959 error_found exception;
1960
1961 BEGIN
1962
1963 if (p_log_level_rec.statement_level) then
1964 fa_debug_pkg.add(l_calling_fn, 'calling', 'fazccmt', p_log_level_rec => p_log_level_rec);
1965 end if;
1966
1967 if not fa_cache_pkg.fazccmt
1968 (X_method => p_deprn_method,
1969 X_life => p_lim, p_log_level_rec => p_log_level_rec) then -- method not found
1970
1971 if (p_log_level_rec.statement_level) then
1972 fa_debug_pkg.add(l_calling_fn, 'after fazccmt', 'method not found', p_log_level_rec => p_log_level_rec);
1973 end if;
1974
1975 if (p_rate_source_rule = 'TABLE') then
1976
1977 if (p_life_in_months <> 0) then
1978 px_new_life := p_life_in_months;
1979 else
1980 fa_srvr_msg.add_message(
1981 CALLING_FN => 'fa_asset_val_pvt.validate_life',
1982 NAME => 'FA_LIM_TDM_NOTDEF', p_log_level_rec => p_log_level_rec);
1983 raise error_found;
1984 end if;
1985
1986 else -- not table
1987
1988 select FA_METHODS_S.NEXTVAL
1989 into l_method_id
1990 from sys.dual;
1991
1992 -- need to derive more values to distinguish between
1993 -- STL and Formula methods. Can't use cache as life
1994 -- is unknown so like the function in calc engine,
1995 -- we'll use cursor here, other option would be to
1996 -- pass the values as parameter into this function
1997 -- creating dependancies...
1998
1999 OPEN METHOD_DEF(p_deprn_method => p_deprn_method,
2000 p_life_in_months => fa_cache_pkg.fazccbd_record.life_in_months);
2001 FETCH METHOD_DEF
2002 INTO l_method_id_old,
2003 l_method_name,
2004 l_deprn_basis_rule,
2005 l_dep_last_year_flag,
2006 l_stl_method_flag,
2007 l_exclude_sal_flag,
2008 l_polish_adj_calc_basis_flag,
2009 l_guarantee_rate_method_flag;
2010
2011 if (METHOD_DEF%NOTFOUND) then
2012 CLOSE METHOD_DEF;
2013 fa_srvr_msg.add_message(
2014 CALLING_FN => l_calling_fn,
2015 NAME => 'FA_SHARED_OBJECT_NOT_DEF',
2016 TOKEN1 => 'OBJECT',
2017 VALUE1 => 'Method', p_log_level_rec => p_log_level_rec);
2018 raise error_found;
2019 else
2020 CLOSE METHOD_DEF;
2021 end if;
2022
2023 if (p_log_level_rec.statement_level) then
2024 fa_debug_pkg.add(l_calling_fn, 'inserting', 'new method', p_log_level_rec => p_log_level_rec);
2025 end if;
2026
2027 FA_METHODS_PKG.Insert_Row(
2028 X_Rowid => l_rowid,
2029 X_Method_Id => l_method_id,
2030 X_Method_Code => p_deprn_method,
2031 X_Life_In_Months => p_lim,
2032 X_Depreciate_Lastyear_Flag => l_dep_last_year_flag, -- 'YES',
2033 X_STL_Method_Flag => l_stl_method_flag, -- 'YES'
2034 X_Rate_Source_Rule => p_rate_source_rule, -- 'CALCULATED',
2035 X_Deprn_Basis_Rule => l_deprn_basis_rule, -- 'COST',
2036 X_Prorate_Periods_Per_Year => NULL,
2037 X_Name => l_method_name,
2038 X_Last_Update_Date => p_curr_date,
2039 X_Last_Updated_By => p_user_id,
2040 X_Created_By => p_user_id,
2041 X_Creation_Date => p_curr_date,
2042 X_Last_Update_Login => -1,
2043 X_Attribute1 => null,
2044 X_Attribute2 => null,
2045 X_Attribute3 => null,
2046 X_Attribute4 => null,
2047 X_Attribute5 => null,
2048 X_Attribute6 => null,
2049 X_Attribute7 => null,
2050 X_Attribute8 => null,
2051 X_Attribute9 => null,
2052 X_Attribute10 => null,
2053 X_Attribute11 => null,
2054 X_Attribute12 => null,
2055 X_Attribute13 => null,
2056 X_Attribute14 => null,
2057 X_Attribute15 => null,
2058 X_Attribute_Category_Code => null,
2059 X_Exclude_Salvage_Value_Flag => l_exclude_sal_flag,
2060 X_Polish_Adj_Calc_Basis_Flag => l_polish_adj_calc_basis_flag,
2061 X_Guarantee_Rate_Method_Flag => l_guarantee_rate_method_flag,
2062 X_Calling_Fn => 'fa_asset_val_pvt.validate_life', p_log_level_rec => p_log_level_rec);
2063
2064 -- if formula based, we need to copy the formula too
2065 if (p_rate_source_rule = 'FORMULA') then
2066 OPEN C_FORMULA (p_method_id => l_method_id_old);
2067 FETCH C_FORMULA
2068 INTO l_formula_actual,
2069 l_formula_displayed,
2070 l_formula_parsed,
2071 l_original_rate,
2072 l_revised_rate,
2073 l_guarantee_rate;
2074
2075 IF C_FORMULA%NOTFOUND then
2076 CLOSE C_FORMULA;
2077 fa_srvr_msg.add_message(
2078 CALLING_FN => 'fa_asset_val_pvt.validate_life',
2079 NAME => 'FA_FORMULA_RATE_NO_DATA_FOUND', p_log_level_rec => p_log_level_rec);
2080 raise error_found;
2081 else
2082 CLOSE C_FORMULA;
2083 end if;
2084
2085 FA_FORMULAS_PKG.insert_row
2086 (X_ROWID => l_rowid,
2087 X_METHOD_ID => l_method_id,
2088 X_FORMULA_ACTUAL => l_formula_actual,
2089 X_FORMULA_DISPLAYED => l_formula_displayed,
2090 X_FORMULA_PARSED => l_formula_parsed,
2091 X_CREATION_DATE => p_curr_date,
2092 X_CREATED_BY => p_user_id,
2093 X_LAST_UPDATE_DATE => p_curr_date,
2094 X_LAST_UPDATED_BY => p_user_id,
2095 X_LAST_UPDATE_LOGIN => -1,
2096 X_ORIGINAL_RATE => l_original_rate,
2097 X_REVISED_RATE => l_revised_rate,
2098 X_GUARANTEE_RATE => l_guarantee_rate, p_log_level_rec => p_log_level_rec);
2099
2100 end if;
2101
2102 end if; -- table based
2103
2104 -- default the new life in months to the remaining life in months of
2105 -- parent.
2106 if (p_lim <> 0) then
2107 px_new_life := p_lim;
2108 end if;
2109
2110 else
2111 if (p_log_level_rec.statement_level) then
2112 fa_debug_pkg.add(l_calling_fn, 'after fazccmt', 'method found', p_log_level_rec => p_log_level_rec);
2113 end if;
2114 end if;
2115
2116 return true;
2117
2118 EXCEPTION
2119 when error_found then
2120 FA_SRVR_MSG.Add_Message(
2121 CALLING_FN => 'fa_asset_val_pvt.validate_life', p_log_level_rec => p_log_level_rec);
2122 return false;
2123
2124 when others then
2125 FA_SRVR_MSG.Add_SQL_Error(
2126 CALLING_FN => 'fa_asset_val_pvt.validate_life', p_log_level_rec => p_log_level_rec);
2127 return false;
2128
2129 END validate_life;
2130
2131
2132
2133 FUNCTION validate_payables_ccid
2134 (px_payables_ccid IN OUT NOCOPY NUMBER,
2135 p_gl_chart_id IN NUMBER,
2136 p_calling_fn IN VARCHAR2,
2137 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2138
2139 l_is_valid_payables_ccid number;
2140
2141 BEGIN
2142
2143 if (px_payables_ccid is not NULL) then
2144
2145 -- Validate payables ccid exists.
2146 select count(*)
2147 into l_is_valid_payables_ccid
2148 from gl_code_combinations
2149 where code_combination_id = px_payables_ccid
2150 and chart_of_accounts_id = p_gl_chart_id
2151 and enabled_flag = 'Y'
2152 and summary_flag = 'N'
2153 and detail_posting_allowed_flag = 'Y';
2154
2155 if (l_is_valid_payables_ccid = 0) then
2156 fa_srvr_msg.add_message(
2157 calling_fn => 'fa_asset_val_pvt.validate_payables_ccid',
2158 name => 'FA_INCORRECT_PAYABLES_ID', p_log_level_rec => p_log_level_rec);
2159 return FALSE;
2160 end if;
2161 else
2162 -- Bug 885429 Payables CCID cannot be NULL, so set it to ZERO.
2163 -- Will generate the ccid based on default category if ccid is ZERO.
2164 fa_srvr_msg.add_message(
2165 calling_fn => 'fa_asset_val_pvt.validate_payables_ccid',
2166 name => 'FA_NULL_PAYABLES_CCID', p_log_level_rec => p_log_level_rec);
2167 px_payables_ccid := 0;
2168
2169 return FALSE;
2170 end if;
2171
2172 return TRUE;
2173
2174 END validate_payables_ccid;
2175
2176 FUNCTION validate_expense_ccid
2177 (p_expense_ccid IN NUMBER,
2178 p_gl_chart_id IN NUMBER,
2179 p_calling_fn IN VARCHAR2,
2180 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2181
2182 l_is_valid_expense_ccid number;
2183
2184 BEGIN
2185
2186 -- Expense ccid cannot be null.
2187 if (p_expense_ccid is null) then
2188 fa_srvr_msg.add_message(
2189 calling_fn => 'fa_asset_val_pvt.validate_expense_ccid',
2190 name => 'FA_NULL_EXPENSE_CCID', p_log_level_rec => p_log_level_rec);
2191 return FALSE;
2192 end if;
2193
2194 -- Check that expense ccid exists.
2195 select count(*)
2196 into l_is_valid_expense_ccid
2197 from gl_code_combinations
2198 where code_combination_id = p_expense_ccid
2199 and chart_of_accounts_id = p_gl_chart_id
2200 and enabled_flag = 'Y'
2201 and account_type = 'E'
2202 and summary_flag = 'N'
2203 and detail_posting_allowed_flag = 'Y';
2204
2205 if (l_is_valid_expense_ccid = 0) then
2206 fa_srvr_msg.add_message(
2207 calling_fn => 'fa_asset_val_pvt.validate_expense_ccid',
2208 name => 'FA_INCORRECT_EXPENSE_ID',
2209 token1 => 'EXPENSE_ID',
2210 value1 => p_expense_ccid, p_log_level_rec => p_log_level_rec);
2211 return FALSE;
2212 end if;
2213
2214 if not validate_ccid(p_book_type_code => fa_cache_pkg.fazcbc_record.book_type_code,
2215 p_ccid => p_expense_ccid,
2216 p_gl_chart_id => p_gl_chart_id,
2217 p_ledger_id => fa_cache_pkg.fazcbc_record.set_of_books_id,
2218 p_validation_date => greatest(fa_cache_pkg.fazcdp_record.calendar_period_open_date,
2219 least(sysdate,fa_cache_pkg.fazcdp_record.calendar_period_close_date)),
2220 p_calling_fn => p_calling_fn,
2221 p_log_level_rec => p_log_level_rec
2222 ) then
2223 return false;
2224 end if;
2225 return TRUE;
2226
2227 END validate_expense_ccid;
2228
2229 FUNCTION validate_fixed_assets_cost
2230 (p_fixed_assets_cost IN NUMBER,
2231 p_calling_fn IN VARCHAR2,
2232 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2233
2234 BEGIN
2235
2236 -- Fixed assets cost cannot be null.
2237 if (p_fixed_assets_cost is null) then
2238 fa_srvr_msg.add_message(
2239 calling_fn => 'fa_asset_val_pvt.validate_fixed_assets_cost',
2240 name => 'FA_NULL_FA_COST', p_log_level_rec => p_log_level_rec);
2241 return FALSE;
2242 end if;
2243
2244 return TRUE;
2245
2246 END validate_fixed_assets_cost;
2247
2248 FUNCTION validate_fixed_assets_units
2249 (p_fixed_assets_units IN NUMBER,
2250 p_calling_fn IN VARCHAR2,
2251 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2252
2253 BEGIN
2254
2255 -- Fixed assets units cannot be null.
2256 if (p_fixed_assets_units is null) then
2257 fa_srvr_msg.add_message(
2258 calling_fn => 'fa_asset_val_pvt.validate_fixed_assets_units',
2259 name => 'FA_NULL_FA_UNITS', p_log_level_rec => p_log_level_rec);
2260 return FALSE;
2261 else
2262
2263 -- Fixed assets units cannot be zero.
2264 if (p_fixed_assets_units = 0) then
2265 fa_srvr_msg.add_message(
2266 calling_fn => 'fa_asset_val_pvt.validate_fixed_assets_units',
2267 name => 'FA_ZERO_FA_UNITS', p_log_level_rec => p_log_level_rec);
2268 return FALSE;
2269 end if;
2270 end if;
2271
2272 return TRUE;
2273
2274 END validate_fixed_assets_units;
2275
2276 FUNCTION validate_payables_cost
2277 (p_payables_cost IN NUMBER,
2278 p_calling_fn IN VARCHAR2,
2279 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2280
2281 BEGIN
2282
2283 -- Payables cost cannot be null.
2284 if (p_payables_cost is null) then
2285 fa_srvr_msg.add_message(
2286 calling_fn => 'fa_asset_val_pvt.validate_payables_cost',
2287 name => 'FA_NULL_PA_COST', p_log_level_rec => p_log_level_rec);
2288 return FALSE;
2289 end if;
2290
2291 return TRUE;
2292
2293 END validate_payables_cost;
2294
2295 FUNCTION validate_payables_units
2296 (p_payables_units IN NUMBER,
2297 p_calling_fn IN VARCHAR2,
2298 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2299
2300 BEGIN
2301
2302 -- Payables units cannot be null.
2303 if (p_payables_units is null) then
2304 fa_srvr_msg.add_message(
2305 calling_fn => 'fa_asset_val_pvt.validate_payables_units',
2306 name => 'FA_NULL_PA_UNITS', p_log_level_rec => p_log_level_rec);
2307 return FALSE;
2308 end if;
2309
2310 return TRUE;
2311
2312 END validate_payables_units;
2313
2314 FUNCTION validate_po_vendor_id
2315 (p_po_vendor_id IN NUMBER,
2316 p_calling_fn IN VARCHAR2,
2317 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2318
2319 l_is_valid_vendor_id number;
2320
2321 BEGIN
2322
2323 if (p_po_vendor_id is not null) then
2324
2325 -- Validate po_vendor_id exists.
2326 select count(*)
2327 into l_is_valid_vendor_id
2328 from po_vendors
2329 where vendor_id = p_po_vendor_id;
2330
2331 if (l_is_valid_vendor_id = 0) then
2332 fa_srvr_msg.add_message(
2333 calling_fn => 'fa_asset_val_pvt.validate_po_vendor_id',
2334 name => 'FA_INCORRECT_PO_VENDOR_ID', p_log_level_rec => p_log_level_rec);
2335 return FALSE;
2336 end if;
2337 end if;
2338
2339 return TRUE;
2340
2341 END validate_po_vendor_id;
2342
2343 FUNCTION validate_unit_of_measure
2344 (p_unit_of_measure IN VARCHAR2,
2345 p_calling_fn IN VARCHAR2,
2346 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2347
2348 l_is_valid_uom number;
2349
2350 BEGIN
2351
2352 /* Bug#10094653:Checking for null UOM also*/
2353 -- Validate unit of measure exists.
2354 select count(*)
2355 into l_is_valid_uom
2356 from mtl_units_of_measure
2357 where unit_of_measure = p_unit_of_measure
2358 and nvl(disable_date, sysdate+1) > sysdate;
2359
2360 if (l_is_valid_uom = 0) then
2361 fa_srvr_msg.add_message(
2362 calling_fn => 'fa_asset_val_pvt.validate_unit_of_measure',
2363 name => 'FA_INCORRECT_UOM', p_log_level_rec => p_log_level_rec);
2364 return FALSE;
2365 end if;
2366 return TRUE;
2367
2368 END validate_unit_of_measure;
2369 -- Bug#7172602 Validating salvage value based on nbv.
2370 FUNCTION validate_salvage_value
2371 (p_salvage_value IN NUMBER,
2372 p_nbv IN NUMBER,
2373 p_calling_fn IN VARCHAR2,
2374 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2375
2376 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_salvage_value';
2377
2378 BEGIN
2379
2380 if (p_salvage_value is null or p_salvage_value = 0) then
2381 return TRUE;
2382 elsif ( p_nbv < 0 and p_salvage_value > 0 ) then
2383 fa_srvr_msg.add_message(calling_fn => l_calling_fn,name=> 'FA_BOOK_INVALID_SALVAGE');
2384 return FALSE;
2385 elsif ( p_nbv > 0 and p_salvage_value < 0) then
2386 fa_srvr_msg.add_message(calling_fn => l_calling_fn,name=> 'FA_BOOK_POS_SALVAGE_VALUE');
2387 return FALSE;
2388 elsif ( (p_nbv < p_salvage_value and p_nbv >=0) OR ( p_nbv > p_salvage_value and p_nbv <=0)) then
2389 fa_srvr_msg.add_message(calling_fn => l_calling_fn,name=> 'FA_BOOK_INVALID_SALVAGE');
2390 return FALSE;
2391 end if;
2392
2393 return TRUE;
2394
2395 END validate_salvage_value;
2396
2397 FUNCTION validate_tag_number
2398 (p_tag_number IN VARCHAR2,
2399 p_mass_addition_id IN NUMBER DEFAULT NULL,
2400 p_calling_fn IN VARCHAR2,
2401 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2402
2403 l_tag_number_count number;
2404
2405 BEGIN
2406
2407 if (p_tag_number is not null) then
2408
2409 -- Make sure that tag_number does not already exist in fa_additions.
2410 select count(*)
2411 into l_tag_number_count
2412 from fa_additions_b
2413 where tag_number = p_tag_number;
2414
2415 if (l_tag_number_count > 0) then
2416 fa_srvr_msg.add_message(
2417 calling_fn => 'fa_asset_val_pvt.validate_tag_number',
2418 name => 'FA_ADD_TAG_NUMBER_EXISTS',
2419 token1 => 'TAG_NUMBER', -- Fix for Bug#5015917. Passed tag number token to
2420 -- display actual tag number in the log.
2421 value1 => p_tag_number,
2422 p_log_level_rec => p_log_level_rec);
2423 return FALSE;
2424 end if;
2425
2426 end if;
2427
2428 return TRUE;
2429
2430 END validate_tag_number;
2431
2432 FUNCTION validate_split_merged_code
2433 (p_split_merged_code IN VARCHAR2,
2434 p_calling_fn IN VARCHAR2,
2435 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2436
2437 BEGIN
2438
2439 -- Split merged code cannot be zero.
2440 if (p_split_merged_code = 0) then
2441 fa_srvr_msg.add_message(
2442 calling_fn => 'fa_asset_val_pvt.validate_split_merged_code',
2443 name => 'FA_INCORRECT_SPLIT_MERGED_CODE', p_log_level_rec => p_log_level_rec);
2444 return FALSE;
2445 end if;
2446
2447 return TRUE;
2448
2449 END validate_split_merged_code;
2450
2451 /* Japan Tax Phase 3 -- Added New parameter p_extended_flag
2452 For extended assets pass this flag as TRUE */
2453 FUNCTION validate_exp_after_amort
2454 (p_asset_id IN number,
2455 p_book IN varchar2,
2456 p_extended_flag IN BOOLEAN DEFAULT FALSE,
2457 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
2458
2459 l_count number := 0 ; -- 6348506: initialize
2460 l_rolled_back_imp number := 0;
2461
2462 BEGIN
2463
2464 /* Japan Tax phase3 -- For extended assets consider transactions
2465 after extended transaction */
2466
2467 -- perf issue 6348506: Insead of getting the actual count, just check for existence
2468 -- It will return 1 if recs exists and 0 if not. It will not return no-data-found
2469
2470 /*Bug#10012899 - Modified both the queries to sync with validation in Asset workbench */
2471 if p_extended_flag then
2472 select count(1)
2473 into l_count
2474 from fa_books bk
2475 where bk.book_type_code= p_book
2476 and bk.asset_id= p_asset_id
2477 and (bk.rate_Adjustment_factor <> 1 OR
2478 (bk.rate_adjustment_factor = 1 and
2479 exists
2480 (select 'YES' -- and amortized before.
2481 from fa_transaction_headers th,
2482 fa_methods mt
2483 where th.book_type_code = bk.book_type_code
2484 and th.asset_id = bk.asset_id
2485 and (th.transaction_subtype = 'AMORTIZED'
2486 OR th.transaction_key = 'UA')
2487 and th.transaction_header_id = bk.transaction_header_id_in
2488 and mt.method_code = bk.deprn_method_code
2489 and mt.rate_source_rule IN ('TABLE','FLAT','PRODUCTION')
2490 and th.transaction_header_id > (select max(th2.transaction_header_id)
2491 from fa_transaction_headers th2
2492 where th2.book_type_code = p_book
2493 and th2.asset_id = p_asset_id
2494 and th2.transaction_key = 'ES'))));
2495 else
2496 select count(*)
2497 into l_count
2498 from fa_books bk
2499 where bk.book_type_code= p_book
2500 and bk.asset_id= p_asset_id
2501 and (bk.rate_Adjustment_factor <> 1 OR
2502 (bk.rate_adjustment_factor = 1 and
2503 exists
2504 (select 'YES'
2505 from fa_transaction_headers th,
2506 fa_methods mt
2507 where th.book_type_code = bk.book_type_code
2508 and th.asset_id = bk.asset_id
2509 and (th.transaction_subtype = 'AMORTIZED'
2510 OR th.transaction_key = 'UA')
2511 and th.transaction_header_id = bk.transaction_header_id_in
2512 and mt.method_code = bk.deprn_method_code
2513 and mt.rate_source_rule IN ('TABLE','FLAT','PRODUCTION','CALCULATED','FORMULA'))));
2514 end if;
2515
2516 /*8582979 - to allow expensed adj after impairment rollback */
2517 select count(1)
2518 into l_rolled_back_imp
2519 from dual
2520 where exists (
2521 select 1 from fa_transaction_headers
2522 where book_type_code = p_book
2523 and asset_id = p_asset_id
2524 and transaction_subtype = 'AMORTIZED' and transaction_key = 'RM');
2525 l_rolled_back_imp := l_rolled_back_imp * 2;
2526
2527 if ((l_count - l_rolled_back_imp) > 0) then
2528 fa_srvr_msg.add_message(
2529 calling_fn => 'fa_asset_val_pvt.validate_exp_after_amort',
2530 name => 'FA_BOOK_CANT_EXP_AFTER_AMORT', p_log_level_rec => p_log_level_rec);
2531 return FALSE;
2532 end if;
2533
2534 return true;
2535
2536 /** commenting out for perf issue 6348506
2537 --bug fix 2772517
2538 select count(*)
2539 into l_count
2540 from fa_transaction_headers
2541 where book_type_code = p_book
2542 and asset_id = p_asset_id
2543 -- and transaction_type_code = 'ADJUSTMENT' bug 5326226
2544 and (transaction_subtype = 'AMORTIZED' OR transaction_key = 'UA');
2545
2546 end if;
2547 Bug 2407786 - This is the consolidated select stmnt
2548 */
2549
2550
2551 /*
2552 select count(*)
2553 into l_count
2554 from fa_books bk
2555 where bk.book_type_code = p_book
2556 and bk.asset_id = p_asset_id
2557 and (bk.rate_Adjustment_factor <> 1 OR
2558 (bk.rate_adjustment_factor = 1 and
2559 exists (select 'YES' -- and amortized before.
2560 from fa_transaction_headers th,
2561 fa_methods mt
2562 where th.book_type_code = bk.book_type_code
2563 and th.asset_id = bk.asset_id
2564 and th.transaction_type_code = 'ADJUSTMENT'
2565 and (th.transaction_subtype = 'AMORTIZED' OR th.transaction_key = 'UA')
2566 and th.transaction_header_id = bk.transaction_header_id_in
2567 and mt.method_code = bk.deprn_method_code
2568 and mt.rate_source_rule IN ('TABLE','FLAT','PRODUCTION'))));
2569 */
2570
2571 EXCEPTION
2572 when others then
2573 fa_srvr_msg.add_sql_error(
2574 calling_fn => 'fa_asset_val_pvt.validate_exp_after_amort', p_log_level_rec => p_log_level_rec);
2575
2576 return false;
2577
2578 END validate_exp_after_amort;
2579
2580 FUNCTION validate_unplanned_exists
2581 (p_asset_id IN number,
2582 p_book IN varchar2,
2583 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2584
2585 l_count number;
2586
2587 BEGIN
2588
2589 SELECT count(*)
2590 INTO l_count
2591 FROM fa_transaction_headers
2592 WHERE book_type_code = p_book
2593 AND asset_id = p_asset_id
2594 AND transaction_key like 'U%';
2595
2596 if (l_count > 0) then
2597 fa_srvr_msg.add_message(calling_fn => 'FA_CHK_BOOKSTS_PKG.faxcbsx',
2598 name => '***FA_UNP_EXISTS***',
2599 p_log_level_rec => p_log_level_rec);
2600 return TRUE;
2601 else
2602 return FALSE;
2603 end if;
2604
2605 END validate_unplanned_exists;
2606
2607
2608
2609 FUNCTION validate_period_of_addition
2610 (p_asset_id IN number,
2611 p_book IN varchar2,
2612 p_mode IN varchar2 DEFAULT 'ABSOLUTE',
2613 px_period_of_addition IN OUT NOCOPY varchar2,
2614 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
2615
2616 l_last_pc number;
2617 l_count number;
2618 l_period_rec FA_API_TYPES.period_rec_type;
2619
2620 BEGIN
2621
2622 -- no need to load book controls cache here as it's loaded
2623 l_last_pc := FA_CACHE_PKG.fazcbc_record.last_period_counter;
2624
2625 if (p_mode = 'ABSOLUTE') then
2626 SELECT count(*)
2627 INTO l_count
2628 FROM fa_deprn_summary
2629 WHERE book_type_code = p_book
2630 AND asset_id = p_asset_id
2631 AND deprn_source_code = 'BOOKS'
2632 AND period_counter = l_last_pc;
2633
2634 if (l_count <> 0) then
2635 px_period_of_addition := 'Y';
2636 else
2637 px_period_of_addition := 'N';
2638 end if;
2639
2640 elsif (p_mode = 'CAPITALIZED') then
2641
2642 if not FA_UTIL_PVT.get_period_rec
2643 (p_book => p_book,
2644 p_effective_date => NULL,
2645 x_period_rec => l_period_rec
2646 , p_log_level_rec => p_log_level_rec) then
2647 fa_srvr_msg.add_message (
2648 calling_fn => 'fa_asset_val_pvt.validate_period_of_addition', p_log_level_rec => p_log_level_rec);
2649 return false;
2650 end if;
2651
2652 SELECT count(*)
2653 INTO l_count
2654 FROM fa_transaction_headers th
2655 WHERE th.asset_id = p_asset_id
2656 AND th.book_type_code = p_book
2657 AND th.transaction_type_code = 'ADDITION'
2658 AND th.date_effective > l_period_rec.period_open_date;
2659
2660 if (l_count <> 0) then
2661 px_period_of_addition := 'Y';
2662 else
2663 px_period_of_addition := 'N';
2664 end if;
2665
2666 else
2667 fa_srvr_msg.add_message (
2668 calling_fn => 'fa_asset_val_pvt.validate_period_of_addition',
2669 name => 'FA_CACHE_UNSUPPORTED_MODE', p_log_level_rec => p_log_level_rec);
2670 return false;
2671 end if;
2672
2673 return true;
2674
2675 EXCEPTION
2676 when others then
2677 fa_srvr_msg.add_sql_error(
2678 calling_fn => 'fa_asset_val_pvt.validate_period_of_addition', p_log_level_rec => p_log_level_rec);
2679 return false;
2680
2681 END validate_period_of_addition;
2682
2683 FUNCTION validate_fully_retired
2684 (p_asset_id IN number,
2685 p_book IN varchar2,
2686 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2687
2688 l_count number;
2689
2690 BEGIN
2691
2692 select count(*)
2693 into l_count
2694 FROM FA_BOOKS BK
2695 WHERE BK.ASSET_ID = p_asset_id
2696 AND BK.PERIOD_COUNTER_FULLY_RETIRED IS NOT NULL
2697 AND BK.DATE_INEFFECTIVE IS NULL
2698 AND BK.BOOK_TYPE_CODE = p_book
2699 AND rownum < 2;
2700
2701 if (l_count <> 0) then
2702 RETURN TRUE;
2703 else
2704 RETURN FALSE;
2705 end if;
2706
2707 EXCEPTION
2708 when others then
2709 fa_srvr_msg.add_sql_error(
2710 calling_fn => 'fa_asset_val_pvt.validate_period_of_addition', p_log_level_rec => p_log_level_rec);
2711 return false;
2712
2713 END validate_fully_retired;
2714
2715
2716 FUNCTION validate_add_to_asset_pending
2717 (p_asset_id in number,
2718 p_book in varchar2,
2719 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return BOOLEAN IS
2720
2721 l_count number;
2722
2723 BEGIN
2724
2725 select count(*)
2726 into l_count
2727 from fa_mass_additions
2728 where book_type_code = p_book
2729 and add_to_asset_id = p_asset_id
2730 and posting_status not in ('POSTED','MERGED','SPLIT','DELETE')
2731 and rownum < 2;
2732
2733 if (l_count <> 0) then
2734 return TRUE;
2735 else
2736 return FALSE;
2737 end if;
2738
2739 EXCEPTION
2740 when others then
2741 fa_srvr_msg.add_sql_error(calling_fn => 'fa_asset_val_pvt.validate_add_to_asset_pending',
2742 p_log_level_rec => p_log_level_rec);
2743 return false;
2744
2745 END validate_add_to_asset_pending;
2746
2747
2748 FUNCTION validate_asset_id_exist
2749 (p_asset_id in number,
2750 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return BOOLEAN IS
2751
2752 l_count number;
2753
2754 BEGIN
2755
2756 select count(*)
2757 into l_count
2758 from fa_additions
2759 where asset_id = p_asset_id
2760 and rownum < 2;
2761
2762 if (l_count <> 0) then
2763 return TRUE;
2764 else
2765 return FALSE;
2766 end if;
2767
2768 EXCEPTION
2769 when others then
2770 fa_srvr_msg.add_sql_error(
2771 calling_fn => 'fa_asset_val_pvt.validate_asset_id_exist', p_log_level_rec => p_log_level_rec);
2772 return FALSE;
2773
2774 END validate_asset_id_exist;
2775
2776 FUNCTION validate_ret_rst_pending
2777 (p_asset_id in number,
2778 p_book in varchar2,
2779 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return BOOLEAN IS
2780
2781 l_count number;
2782
2783 BEGIN
2784
2785 select count(*)
2786 into l_count
2787 from fa_retirements
2788 where book_type_code = p_book
2789 and asset_id = p_asset_id
2790 and status in ('PENDING','REINSTATE');
2791
2792 if (l_count <> 0) then
2793 return TRUE;
2794 else
2795 return FALSE;
2796 end if;
2797
2798 EXCEPTION
2799
2800 when others then
2801 fa_srvr_msg.add_sql_error(
2802 calling_fn => 'fa_asset_val_pvt.validate_ret_rst_pending', p_log_level_rec => p_log_level_rec);
2803
2804 return FALSE;
2805
2806 END validate_ret_rst_pending;
2807
2808 FUNCTION validate_fa_lookup_code
2809 (p_lookup_type in varchar2,
2810 p_lookup_code in varchar2,
2811 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return BOOLEAN IS
2812
2813 l_count number;
2814
2815 BEGIN
2816
2817 select count(*)
2818 into l_count
2819 from fa_lookups_b
2820 where lookup_type = p_lookup_type
2821 and lookup_code = p_lookup_code;
2822
2823 if (l_count <> 0) then
2824 return TRUE;
2825 else
2826 fa_srvr_msg.add_message
2827 (calling_fn => 'fa_asset_val_pvt.validate_fa_lookup_code',
2828 name => '***FA_BAD_LOOKUP_CODE***',
2829 p_log_level_rec => p_log_level_rec);
2830 return FALSE;
2831 end if;
2832
2833 EXCEPTION
2834 when others then
2835 fa_srvr_msg.add_sql_error(calling_fn => 'fa_asset_val_pvt.validate_fa_lookup_code',
2836 p_log_level_rec => p_log_level_rec);
2837 return false;
2838
2839 END validate_fa_lookup_code;
2840
2841 FUNCTION validate_dist_id
2842 (p_asset_id in number,
2843 p_dist_id in number,
2844 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return BOOLEAN IS
2845
2846 l_count number;
2847
2848 BEGIN
2849
2850 select count(*)
2851 into l_count
2852 from fa_distribution_history
2853 where asset_id = p_asset_id
2854 and distribution_id = p_dist_id;
2855
2856 if (l_count <> 0) then
2857 return TRUE;
2858 else
2859 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate_dist_id',
2860 p_log_level_rec => p_log_level_rec);
2861 return FALSE;
2862 end if;
2863
2864 EXCEPTION
2865 when others then
2866 fa_srvr_msg.add_sql_error(
2867 calling_fn => 'fa_asset_val_pvt.validate_dist_id', p_log_level_rec => p_log_level_rec);
2868 return FALSE;
2869
2870 END validate_dist_id;
2871
2872 FUNCTION validate_corp_pending_ret
2873 (p_asset_id in number,
2874 p_book in varchar2,
2875 p_transaction_header_id_in in number,
2876 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
2877
2878 l_count1 number := 0;
2879 l_count2 number := 0;
2880
2881 v_xfr_out_thid number;
2882
2883 BEGIN
2884
2885 /*---------------------------------------------------------------+
2886 | Bug 1577955. |
2887 | We need to check if there are any partial Unit Retirements in |
2888 | the Corporate book. Then we check if there were any cost |
2889 | adjustments or if depreciation was run on any of the |
2890 | associated Tax books before running Gain/Loss in the Corporate |
2891 | book. If that is the case, we will not allow |
2892 | the use of the 'Undo Retirement' function. |
2893 | Instead, Gain/Loss must be run on the Corp book first |
2894 | and then you may reinstate the asset. |
2895 +---------------------------------------------------------------+*/
2896 begin
2897 select distinct transaction_header_id
2898 into v_xfr_out_thid
2899 from fa_transaction_headers thd
2900 where thd.asset_id = p_Asset_Id
2901 and thd.TRANSACTION_TYPE_CODE = 'TRANSFER OUT'
2902 and thd.book_type_code = p_book
2903 and thd.transaction_header_id > p_Transaction_Header_Id_In
2904 and rownum = 1;
2905 exception
2906 when others then null;
2907 end;
2908
2909
2910 begin
2911 select count(*)
2912 into l_count1
2913 from fa_adjustments adj,
2914 fa_distribution_history dh
2915 where adj.asset_id = p_asset_id
2916 and adj.asset_id = dh.asset_id
2917 and adj.distribution_id = dh.distribution_id
2918 and dh.transaction_header_id_in = v_xfr_out_thid
2919 and adj.transaction_header_id <> v_xfr_out_thid;
2920 exception
2921 when others then null;
2922 end;
2923
2924
2925 begin
2926 select count(*)
2927 into l_count2
2928 from fa_deprn_detail dd,
2929 fa_distribution_history dh
2930 where dd.asset_id = p_asset_id
2931 and dd.asset_id = dh.asset_id
2932 and dd.distribution_id = dh.distribution_id
2933 and dh.transaction_header_id_in = v_xfr_out_thid;
2934 exception
2935 when others then null;
2936 end;
2937
2938 if (l_count1 <> 0 or l_count2 <> 0) then
2939 return TRUE;
2940 else
2941 return FALSE;
2942 end if;
2943
2944 EXCEPTION
2945 when others then
2946 fa_srvr_msg.add_sql_error(calling_fn => 'fa_asset_val_pvt.validate_corp_pending_ret',
2947 p_log_level_rec => p_log_level_rec);
2948
2949 return false;
2950
2951 END validate_corp_pending_ret;
2952
2953 FUNCTION validate_parent_asset(
2954 p_parent_asset_id IN number,
2955 p_asset_id IN number,
2956 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
2957
2958 l_count number:=0;
2959 l_corp_book varchar2(30);
2960 BEGIN
2961 -- always do this check for corp book
2962 if NOT FA_UTIL_PVT.get_corp_book(
2963 p_asset_id => p_asset_id,
2964 p_corp_book => l_corp_book , p_log_level_rec => p_log_level_rec) then
2965 return FALSE;
2966 end if;
2967
2968 select count(1)
2969 into l_count
2970 from fa_books
2971 where book_type_code = l_corp_book
2972 and asset_id = p_parent_asset_id
2973 and date_ineffective is null;
2974
2975 if l_count = 0 then
2976 fa_srvr_msg.add_message(
2977 calling_fn => 'validate_parent_asset',
2978 name => 'FA_INCORRECT_PARENT_ASSET', p_log_level_rec => p_log_level_rec);
2979 return FALSE;
2980 end if;
2981
2982 return TRUE;
2983
2984 END validate_parent_asset;
2985
2986 FUNCTION validate_warranty (
2987 p_warranty_id IN NUMBER,
2988 p_date_placed_in_service IN DATE,
2989 p_book_type_code IN VARCHAR2,
2990 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
2991
2992 l_count number := 0;
2993
2994 BEGIN
2995
2996 if p_warranty_id is not null then
2997
2998 -- Validate warranty is in valid date
2999 SELECT count(w.warranty_id) INTO l_count
3000 FROM fa_warranties w
3001 WHERE w.warranty_id = p_warranty_id
3002 AND p_date_placed_in_service between
3003 nvl (w.start_date, p_date_placed_in_service) and
3004 nvl (w.end_date, p_date_placed_in_service);
3005
3006 if l_count = 0 then
3007 fa_srvr_msg.add_message(
3008 calling_fn => 'validate_warranty',
3009 name => 'FA_INVALID_WARRANTY', p_log_level_rec => p_log_level_rec);
3010 return FALSE;
3011 end if;
3012
3013 -- Validate warranty currency is correct
3014 SELECT count(w.warranty_id) INTO l_count
3015 FROM gl_sets_of_books glsob,
3016 fa_book_controls bc,
3017 fa_warranties w
3018 WHERE w.warranty_id = p_warranty_id
3019 AND bc.book_type_code = p_book_type_code
3020 AND bc.set_of_books_id = glsob.set_of_books_id
3021 AND glsob.currency_code =
3022 nvl(w.currency_code, glsob.currency_code);
3023
3024 if l_count = 0 then
3025 fa_srvr_msg.add_message(
3026 calling_fn => 'validate_warranty',
3027 name => 'FA_SHARED_GET_CURRENCY_CODE', p_log_level_rec => p_log_level_rec);
3028 return FALSE;
3029 end if;
3030 end if;
3031
3032 return TRUE;
3033 END validate_warranty;
3034
3035 FUNCTION validate_lease(
3036 p_asset_id IN number,
3037 p_lease_id IN number,
3038 p_category_id IN NUMBER,
3039 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
3040
3041 CURSOR get_cat_type IS
3042 select category_type
3043 from fa_categories_b
3044 where category_id = p_category_id;
3045
3046 CURSOR C1 IS
3047 select currency_code
3048 from gl_sets_of_books sob,
3049 fa_book_controls bc,
3050 fa_books bk
3051 where bk.asset_id = p_asset_id
3052 and bk.date_ineffective is null
3053 and bk.book_type_code = bc.book_type_code
3054 and bc.set_of_books_id = sob.set_of_books_id;
3055
3056 l_cat_type varchar2(30);
3057 l_count number:=0;
3058 l_lease_currency varchar2(15);
3059 lease_error EXCEPTION;
3060 BEGIN
3061
3062 if p_lease_id is not null then
3063
3064 -- check if lease is valid
3065 select count(1)
3066 into l_count
3067 from fa_leases
3068 where lease_id = p_lease_id;
3069 if l_count = 0 then
3070 fa_srvr_msg.add_message(
3071 calling_fn => 'validate_lease',
3072 name => 'FA_INVALID_LEASE', p_log_level_rec => p_log_level_rec);
3073 return FALSE;
3074 end if;
3075
3076 -- check if lease is allowed
3077 OPEN get_cat_type;
3078 FETCH get_cat_type INTO l_cat_type;
3079 CLOSE get_cat_type;
3080 if nvl(l_cat_type,'NON-LEASE') NOT IN ( 'LEASE', 'LEASEHOLD IMPROVEMENT') then
3081 fa_srvr_msg.add_message(
3082 calling_fn => 'validate_lease',
3083 name => 'FA_CANT_ADD_LEASE', p_log_level_rec => p_log_level_rec);
3084 return FALSE;
3085 end if;
3086
3087 -- check if lease_currency same
3088 select currency_code
3089 into l_lease_currency
3090 from fa_leases
3091 where lease_id = p_lease_id;
3092 FOR c1_rec in c1 loop
3093 if (l_lease_currency <> c1_rec.currency_code) then
3094 raise lease_error;
3095 end if;
3096 END LOOP;
3097 end if;
3098
3099 return TRUE;
3100
3101 EXCEPTION
3102 when lease_error then
3103 fa_srvr_msg.add_message(
3104 calling_fn => 'validate_lease',
3105 name => 'FA_CURRENCY_NOT_MATCH', p_log_level_rec => p_log_level_rec);
3106 return FALSE;
3107
3108 END validate_lease;
3109
3110 FUNCTION validate_property_type(
3111 p_property_type_code in VARCHAR2,
3112 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
3113 l_count number:= 0;
3114 BEGIN
3115 if p_property_type_code is not null then
3116 select count(1)
3117 into l_count
3118 from fa_lookups_b
3119 where lookup_type = 'PROPERTY TYPE'
3120 and lookup_code = p_property_type_code;
3121
3122 if l_count = 0 then
3123 fa_srvr_msg.add_message(
3124 calling_fn => 'validate_property_type',
3125 name => 'FA_PROPERTY_TYPE_NOT_EXIST', p_log_level_rec => p_log_level_rec);
3126 return FALSE;
3127 end if;
3128 end if;
3129
3130 return TRUE;
3131
3132 END validate_property_type;
3133
3134
3135 FUNCTION validate_1245_1250_code(
3136 p_1245_1250_code in VARCHAR2,
3137 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
3138
3139 l_count number:= 0;
3140 BEGIN
3141 if p_1245_1250_code is not null then
3142 select count(1)
3143 into l_count
3144 from fa_lookups_b
3145 where lookup_type = '1245/1250 PROPERTY'
3146 and lookup_code = p_1245_1250_code;
3147
3148 if l_count = 0 then
3149 fa_srvr_msg.add_message(
3150 calling_fn => 'validate_1245_1250_code',
3151 name => 'FA_1245_1250_NOT_EXIST', p_log_level_rec => p_log_level_rec);
3152 return FALSE;
3153 end if;
3154 end if;
3155
3156 return TRUE;
3157
3158 END validate_1245_1250_code;
3159
3160 FUNCTION validate_group_asset
3161 (p_group_asset_id in NUMBER,
3162 p_book_type_code in VARCHAR2,
3163 p_asset_type in VARCHAR2,
3164 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean is
3165
3166 l_count number;
3167
3168 BEGIN
3169
3170 if (p_log_level_rec.statement_level) then
3171 fa_debug_pkg.add('val api', 'group', p_group_asset_id, p_log_level_rec => p_log_level_rec);
3172 fa_debug_pkg.add('val api', 'book', p_book_type_code, p_log_level_rec => p_log_level_rec);
3173 end if;
3174
3175 --
3176 -- Following sql is too expensive
3177 --
3178 -- select count(*)
3179 -- into l_count
3180 -- from FA_BOOKS
3181 -- where ASSET_ID = p_group_asset_id
3182 -- and BOOK_TYPE_CODE = p_book_type_code;
3183 l_count := null;
3184 select 1
3185 into l_count
3186 from dual
3187 where exists (select 'X'
3188 from FA_BOOKS
3189 where ASSET_ID = p_group_asset_id
3190 and BOOK_TYPE_CODE = p_book_type_code);
3191
3192 if l_count is null then
3193 fa_srvr_msg.add_message(
3194 calling_fn => 'fa_asset_val_pvt.validate_group_asset',
3195 name => 'FA_GROUP_NOT_IN_BOOK', p_log_level_rec => p_log_level_rec);
3196 return false;
3197 end if;
3198
3199
3200 if (p_asset_type <> 'CAPITALIZED' and
3201 p_asset_type <> 'CIP') then
3202 fa_srvr_msg.add_message(
3203 calling_fn => 'fa_asset_val_pvt.validate_group_asset',
3204 name => 'FA_INV_ASSET_TYPE', p_log_level_rec => p_log_level_rec);
3205 return false;
3206 end if;
3207
3208 return true;
3209
3210 END validate_group_asset;
3211
3212 --HH group enable/disable
3213 FUNCTION validate_disabled_flag
3214 (p_group_asset_id in NUMBER,
3215 p_book_type_code in VARCHAR2,
3216 p_old_flag IN VARCHAR2,
3217 p_new_flag IN VARCHAR2,
3218 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean is
3219
3220 l_calling_fn varchar2(40) :='fa_asset_val_pvt.validate_disabled_flag';
3221
3222 BEGIN
3223
3224 IF ((NVL(p_old_flag,'N') Not IN ('Y','N')) OR
3225 (NVL(p_new_flag,'N') Not IN ('Y','N'))) THEN
3226 -- Garbage value for flag.
3227 fa_srvr_msg.add_message(
3228 calling_fn => l_calling_fn,
3229 name => 'FA_INCORRECT_DISABLED_FLAG', p_log_level_rec => p_log_level_rec);
3230 return FALSE;
3231
3232 ELSIF (nvl(p_old_flag,'N')='Y' AND nvl(p_new_flag,'N')='Y') THEN
3233 --Disabled group.
3234 fa_srvr_msg.add_message(
3235 calling_fn => l_calling_fn,
3236 name => 'FA_DISABLED_GROUP', p_log_level_rec => p_log_level_rec);
3237 return FALSE;
3238 ELSIF (nvl(p_old_flag,'N')='N' AND nvl(p_new_flag,'N')='Y') THEN
3239 if NOT validate_group_info(p_group_asset_id => p_group_asset_id,
3240 p_book_type_code => p_book_type_code,
3241 p_calling_fn => l_calling_fn,
3242 p_log_level_rec => p_log_level_rec) THEN
3243 --Group doesn't meet criteria for disabling.
3244 return FALSE;
3245 end if;
3246 END IF;
3247
3248 RETURN TRUE;
3249
3250 END validate_disabled_flag;
3251
3252 FUNCTION validate_group_info
3253 (p_group_asset_id in NUMBER,
3254 p_book_type_code in VARCHAR2,
3255 p_calling_fn in VARCHAR2,
3256 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean is
3257
3258 l_has_members number;
3259 l_disabled number;
3260 l_calling_fn varchar2(40) :='fa_asset_val_pvt.validate_group_info';
3261
3262 BEGIN
3263
3264 SELECT count(1)
3265 INTO l_disabled
3266 FROM fa_books
3267 WHERE asset_id = p_group_asset_id
3268 AND book_type_code = p_book_type_code
3269 AND disabled_flag = 'Y'
3270 AND transaction_header_id_out is null;
3271
3272 if (l_disabled = 0) then
3273 if p_calling_fn <> 'fa_asset_val_pvt.validate_disabled_flag' then
3274 return true;
3275 else
3276 SELECT count(1)
3277 INTO l_has_members
3278 FROM fa_books
3279 WHERE group_asset_id = p_group_asset_id
3280 AND book_type_code = p_book_type_code
3281 AND transaction_header_id_out is null
3282 AND period_counter_fully_retired is null;
3283 end if;
3284 elsif (l_disabled > 0) then
3285 fa_srvr_msg.add_message(
3286 calling_fn => l_calling_fn,
3287 name => 'FA_DISABLED_GROUP', p_log_level_rec => p_log_level_rec);
3288 return false;
3289 end if;
3290
3291 if l_has_members > 0 then
3292 fa_srvr_msg.add_message(
3293 calling_fn => l_calling_fn,
3294 name => 'FA_CANT_DISABLE_GROUP', p_log_level_rec => p_log_level_rec);
3295 return false;
3296 end if;
3297
3298 return true;
3299
3300 END validate_group_info; -- End HH.
3301
3302 FUNCTION validate_over_depreciate
3303 (p_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type,
3304 p_asset_type VARCHAR2,
3305 p_over_depreciate_option VARCHAR2 default null,
3306 p_adjusted_recoverable_cost NUMBER default null,
3307 p_recoverable_cost NUMBER default null,
3308 p_deprn_reserve_new NUMBER default null,
3309 p_rate_source_rule VARCHAR2 default null,
3310 p_deprn_basis_rule VARCHAR2 default null,
3311 p_recapture_reserve_flag VARCHAR2 default null,
3312 p_deprn_limit_type VARCHAR2 default null,
3313 p_log_level_rec FA_API_TYPES.log_level_rec_type) return boolean is
3314
3315 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_over_depreciate';
3316
3317 l_member_count binary_integer := 0;
3318
3319 BEGIN
3320
3321
3322 if (p_asset_type = 'GROUP') then
3323
3324 if (nvl(p_adjusted_recoverable_cost, p_recoverable_cost) = 0) then
3325 --
3326 -- Check to see if there is no member belongs to this group asset
3327 -- If no member asset exists, terminal gain loss will take care
3328 -- remaining reserve handling
3329 --
3330 select count(transaction_header_id_in)
3331 into l_member_count
3332 from fa_books
3333 where group_asset_id = p_asset_hdr_rec.asset_id
3334 and book_type_code = p_asset_hdr_rec.book_type_code
3335 and transaction_header_id_out is null;
3336 else
3337 -- Group has a cost so set dummy 1
3338 l_member_count := 1;
3339 end if;
3340
3341
3342 if (l_member_count > 0) then
3343 -- Check to see if new reserve exceeds (adjusted )recoverable cost
3344 -- even thought asset is not suppsed to be over depreciated
3345 if (p_deprn_reserve_new is not null) and
3346 (nvl(p_adjusted_recoverable_cost, p_recoverable_cost) is not null) then
3347
3348 if (nvl(p_over_depreciate_option, fa_std_types.FA_OVER_DEPR_NO) =
3349 fa_std_types.FA_OVER_DEPR_NO) then
3350 if (nvl(p_adjusted_recoverable_cost, p_recoverable_cost) > 0 and
3351 nvl(p_adjusted_recoverable_cost, p_recoverable_cost) < p_deprn_reserve_new) or
3352 (nvl(p_adjusted_recoverable_cost, p_recoverable_cost) < 0 and
3353 nvl(p_adjusted_recoverable_cost, p_recoverable_cost) > p_deprn_reserve_new) then
3354 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
3355 name => 'FA_TOO_MUCH_RESERVE', p_log_level_rec => p_log_level_rec);
3356 return FALSE;
3357 end if;
3358
3359 end if;
3360 end if;
3361
3362 -- Over Depreciate cannot be DEPRN if method is flat-nbv
3363 if (p_rate_source_rule is not null) and
3364 (p_deprn_basis_rule is not null) then
3365 if (p_rate_source_rule = 'FLAT') and
3366 (p_deprn_basis_rule = 'NBV') and
3367 (nvl(p_over_depreciate_option, fa_std_types.FA_OVER_DEPR_NO) =
3368 fa_std_types.FA_OVER_DEPR_DEPRN) then
3369
3370 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
3371 name => 'FA_NO_OVER_DEPRN_ALLOWED', p_log_level_rec => p_log_level_rec);
3372 return false;
3373
3374 end if;
3375
3376 end if;
3377
3378 /* BUG# 2941674
3379 * removing this validation for now...
3380 * as we need it to account for CRL behavior
3381
3382 if (p_deprn_limit_type is not null) then
3383 if (p_deprn_limit_type <> 'NONE') and
3384 (nvl(p_over_depreciate_option, fa_std_types.FA_OVER_DEPR_NO) <>
3385 fa_std_types.FA_OVER_DEPR_NO) then
3386
3387 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
3388 name => 'FA_NO_OVER_DEPRN_ALLOWED', p_log_level_rec => p_log_level_rec);
3389 return false;
3390 end if;
3391
3392 end if;
3393
3394 */
3395
3396 if (nvl(p_recapture_reserve_flag, 'N') <> 'N') and
3397 (nvl(p_over_depreciate_option, fa_std_types.FA_OVER_DEPR_NO) <>
3398 fa_std_types.FA_OVER_DEPR_NO) then
3399
3400 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
3401 name => 'FA_NO_OVER_DEPRN_ALLOWED', p_log_level_rec => p_log_level_rec);
3402 return false;
3403 end if;
3404 end if; -- (l_member_count > 0)
3405
3406 end if; -- (p_asset_type = 'GROUP')
3407
3408
3409 return TRUE;
3410
3411 END validate_over_depreciate;
3412
3413 FUNCTION validate_cost_change (
3414 p_asset_id number,
3415 p_group_asset_id number,
3416 p_book_type_code varchar2,
3417 p_asset_type varchar2,
3418 p_transaction_header_id number,
3419 p_transaction_date date,
3420 p_cost number default 0,
3421 p_cost_adj number default 0,
3422 p_salvage_value number default 0,
3423 p_salvage_value_adj number default 0,
3424 p_deprn_limit_amount number default 0,
3425 p_deprn_limit_amount_adj number default 0,
3426 p_mrc_sob_type_code varchar2,
3427 p_set_of_books_id number,
3428 p_over_depreciate_option varchar2,
3429 p_log_level_rec FA_API_TYPES.log_level_rec_type) return boolean is
3430
3431 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_cost_change';
3432
3433 CURSOR c_get_current_amts IS
3434 SELECT SUM(inbk_cost - NVL(outbk_cost, 0)) ,
3435 SUM(inbk_salvage_value - NVL(outbk_salvage_value, 0)) ,
3436 SUM(NVL(inbk_allowed_deprn_limit_amt, 0) - NVL(outbk_allowed_deprn_limit_amt, 0))
3437 from ( SELECT inbk.cost inbk_cost
3438 ,outbk.cost outbk_cost
3439 ,inbk.salvage_value inbk_salvage_value
3440 ,outbk.salvage_value outbk_salvage_value
3441 ,inbk.allowed_deprn_limit_amount inbk_allowed_deprn_limit_amt
3442 ,outbk.allowed_deprn_limit_amount outbk_allowed_deprn_limit_amt
3443 FROM fa_transaction_headers th
3444 ,fa_books inbk
3445 ,fa_books outbk
3446 WHERE inbk.asset_id = p_asset_id
3447 AND inbk.book_type_code = p_book_type_code
3448 AND outbk.asset_id (+) = p_asset_id -- inbk.asset_id
3449 AND outbk.book_type_code (+) = p_book_type_code -- inbk.book_type_code
3450 AND inbk.transaction_header_id_in = th.transaction_header_id
3451 AND outbk.transaction_header_id_out(+) = th.transaction_header_id
3452 AND th.asset_id = p_asset_id
3453 AND th.book_type_code = p_book_type_code
3454 AND th.transaction_type_code NOT IN ('TRANSFER OUT', 'TRANSFER IN' , 'TRANSFER' , 'TRANSFER IN/VOID'
3455 ,'RECLASS' , 'UNIT ADJUSTMENT', 'REINSTATEMENT', 'ADDITION/VOID'
3456 ,'CIP ADDITION/VOID'
3457 ,'ADDITION' ,'CIP ADDITION')
3458 AND th.transaction_header_id <> p_transaction_header_id
3459 AND DECODE(th.transaction_subtype,
3460 'EXPENSED', inbk.date_placed_in_service,
3461 NVL(th.amortization_start_date, th.transaction_date_entered))
3462 <= p_transaction_date
3463 AND NOT EXISTS
3464 (SELECT 'Exclude Retirement which reinstatement exists'
3465 FROM fa_retirements ret
3466 ,fa_transaction_headers reith
3467 WHERE ret.transaction_header_id_in = th.transaction_header_id
3468 AND ret.transaction_header_id_out = reith.transaction_header_id
3469 AND NVL(reith.amortization_start_date, reith.transaction_date_entered)
3470 <= p_transaction_date)
3471 UNION ALL
3472 SELECT inbk.cost inbk_cost
3473 ,outbk.cost outbk_cost
3474 ,inbk.salvage_value inbk_salvage_value
3475 ,outbk.salvage_value outbk_salvage_value
3476 ,inbk.allowed_deprn_limit_amount inbk_allowed_deprn_limit_amt
3477 ,outbk.allowed_deprn_limit_amount outbk_allowed_deprn_limit_amt
3478 FROM fa_transaction_headers th
3479 ,fa_books inbk
3480 ,fa_books outbk
3481 WHERE inbk.asset_id = p_asset_id
3482 AND inbk.book_type_code = p_book_type_code
3483 AND outbk.asset_id (+) = p_asset_id
3484 AND outbk.book_type_code (+) = p_book_type_code
3485 AND inbk.transaction_header_id_in = th.transaction_header_id
3486 AND DECODE(th.transaction_type_code
3487 ,'ADDITION' , to_number(NULL)
3488 ,'CIP ADDITION', to_number(NULL)
3489 , outbk.transaction_header_id_out(+))
3490 = th.transaction_header_id
3491 AND th.asset_id = p_asset_id
3492 AND th.book_type_code = p_book_type_code
3493 AND th.transaction_type_code IN ('ADDITION' ,'CIP ADDITION')
3494 AND th.transaction_header_id <> p_transaction_header_id
3495 AND inbk.date_placed_in_service <= p_transaction_date
3496 AND NOT EXISTS
3497 (SELECT 'Exclude Retirement which reinstatement exists'
3498 FROM fa_retirements ret
3499 ,fa_transaction_headers reith
3500 WHERE ret.transaction_header_id_in = th.transaction_header_id
3501 AND ret.transaction_header_id_out = reith.transaction_header_id
3502 AND NVL(reith.amortization_start_date, reith.transaction_date_entered)
3503 <= p_transaction_date)) ;
3504
3505
3506 CURSOR c_get_current_mc_amts IS
3507 SELECT SUM(inbk_cost - NVL(outbk_cost, 0)) ,
3508 SUM(inbk_salvage_value - NVL(outbk_salvage_value, 0)) ,
3509 SUM(NVL(inbk_allowed_deprn_limit_amt, 0) - NVL(outbk_allowed_deprn_limit_amt, 0))
3510 from ( SELECT inbk.cost inbk_cost
3511 ,outbk.cost outbk_cost
3512 ,inbk.salvage_value inbk_salvage_value
3513 ,outbk.salvage_value outbk_salvage_value
3514 ,inbk.allowed_deprn_limit_amount inbk_allowed_deprn_limit_amt
3515 ,outbk.allowed_deprn_limit_amount outbk_allowed_deprn_limit_amt
3516 FROM fa_transaction_headers th
3517 ,fa_mc_books inbk
3518 ,fa_mc_books outbk
3519 WHERE inbk.asset_id = p_asset_id
3520 AND inbk.book_type_code = p_book_type_code
3521 AND outbk.asset_id (+) = p_asset_id -- inbk.asset_id
3522 AND outbk.book_type_code (+) = p_book_type_code -- inbk.book_type_code
3523 AND inbk.transaction_header_id_in = th.transaction_header_id
3524 AND outbk.transaction_header_id_out(+) = th.transaction_header_id
3525 AND th.asset_id = p_asset_id
3526 AND th.book_type_code = p_book_type_code
3527 AND th.transaction_type_code NOT IN ('TRANSFER OUT', 'TRANSFER IN' , 'TRANSFER' , 'TRANSFER IN/VOID'
3528 ,'RECLASS' , 'UNIT ADJUSTMENT', 'REINSTATEMENT', 'ADDITION/VOID'
3529 ,'CIP ADDITION/VOID'
3530 ,'ADDITION' ,'CIP ADDITION')
3531 AND th.transaction_header_id <> p_transaction_header_id
3532 AND DECODE(th.transaction_subtype,
3533 'EXPENSED', inbk.date_placed_in_service,
3534 NVL(th.amortization_start_date, th.transaction_date_entered))
3535 <= p_transaction_date
3536 AND NOT EXISTS
3537 (SELECT 'Exclude Retirement which reinstatement exists'
3538 FROM fa_retirements ret
3539 ,fa_transaction_headers reith
3540 WHERE ret.transaction_header_id_in = th.transaction_header_id
3541 AND ret.transaction_header_id_out = reith.transaction_header_id
3542 AND NVL(reith.amortization_start_date, reith.transaction_date_entered)
3543 <= p_transaction_date)
3544 UNION ALL
3545 SELECT inbk.cost inbk_cost
3546 ,outbk.cost outbk_cost
3547 ,inbk.salvage_value inbk_salvage_value
3548 ,outbk.salvage_value outbk_salvage_value
3549 ,inbk.allowed_deprn_limit_amount inbk_allowed_deprn_limit_amt
3550 ,outbk.allowed_deprn_limit_amount outbk_allowed_deprn_limit_amt
3551 FROM fa_transaction_headers th
3552 ,fa_mc_books inbk
3553 ,fa_mc_books outbk
3554 WHERE inbk.asset_id = p_asset_id
3555 AND inbk.book_type_code = p_book_type_code
3556 AND outbk.asset_id (+) = p_asset_id
3557 AND outbk.book_type_code (+) = p_book_type_code
3558 AND inbk.transaction_header_id_in = th.transaction_header_id
3559 AND DECODE(th.transaction_type_code
3560 ,'ADDITION' , to_number(NULL)
3561 ,'CIP ADDITION', to_number(NULL)
3562 , outbk.transaction_header_id_out(+))
3563 = th.transaction_header_id
3564 AND th.asset_id = p_asset_id
3565 AND th.book_type_code = p_book_type_code
3566 AND th.transaction_type_code IN ('ADDITION' ,'CIP ADDITION')
3567 AND th.transaction_header_id <> p_transaction_header_id
3568 AND inbk.date_placed_in_service <= p_transaction_date
3569 AND NOT EXISTS
3570 (SELECT 'Exclude Retirement which reinstatement exists'
3571 FROM fa_retirements ret
3572 ,fa_transaction_headers reith
3573 WHERE ret.transaction_header_id_in = th.transaction_header_id
3574 AND ret.transaction_header_id_out = reith.transaction_header_id
3575 AND NVL(reith.amortization_start_date, reith.transaction_date_entered)
3576 <= p_transaction_date)) ;
3577
3578 l_cost number := null;
3579 l_salvage_value number := null;
3580 l_deprn_limit_amount number := null;
3581
3582 val_err EXCEPTION;
3583
3584 BEGIN
3585
3586 --
3587 -- Perform the check only if
3588 -- Current cost is not 0
3589 -- and sign of current cost and delta cost is different. OR
3590 -- Current salvage_value is not 0
3591 -- and sign of current salvage_value and delta salvage_value is different
3592 -- and asset type is GROUP. OR
3593 -- Current deprn_limit_amount is not 0
3594 -- and sign of current deprn_limit_amount and delta deprn_limit_amount is different.
3595 --
3596 if (( p_cost <> 0 and p_cost_adj <> 0) and sign(p_cost_adj) <> sign(p_cost)) or
3597 (( p_salvage_value <> 0 and p_salvage_value_adj <> 0) and
3598 (sign(p_salvage_value_adj) <> sign(p_salvage_value)) and
3599 (p_asset_type <> 'GROUP')) or
3600 ((p_deprn_limit_amount <> 0 and p_deprn_limit_amount_adj <> 0) and
3601 sign(p_deprn_limit_amount_adj) <> sign(p_deprn_limit_amount)) then
3602
3603 /* Commented for bug# 5131759
3604 if (p_mrc_sob_type_code = 'R') then
3605 OPEN c_get_current_mc_amts;
3606 FETCH c_get_current_mc_amts INTO l_cost, l_salvage_value, l_deprn_limit_amount;
3607 CLOSE c_get_current_mc_amts;
3608 else
3609 OPEN c_get_current_amts;
3610 FETCH c_get_current_amts INTO l_cost, l_salvage_value, l_deprn_limit_amount;
3611 CLOSE c_get_current_amts;
3612 end if; -- (p_mrc_sob_type_code = 'R') */
3613
3614 --HH
3615 --Bug 3528634. Check cost change flag and other conditions in bug.
3616 --Only do for cost and salvage amounts. For deprn limit I think we always want
3617 --to check that. See bug for more details.
3618 --Also, using the already loaded cache structures here since this is only
3619 --called from calc now. Should this change, we may need to consider
3620 --changing the params passed in to this proc.
3621
3622 if (p_log_level_rec.statement_level) then
3623 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazccmt_record.rate_source_rule',
3624 fa_cache_pkg.fazccmt_record.rate_source_rule, p_log_level_rec => p_log_level_rec);
3625 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcdrd_record.rule_name',
3626 fa_cache_pkg.fazcdrd_record.rule_name, p_log_level_rec => p_log_level_rec);
3627 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.ALLOW_COST_SIGN_CHANGE_FLAG',
3628 fa_cache_pkg.fazcbc_record.ALLOW_COST_SIGN_CHANGE_FLAG, p_log_level_rec => p_log_level_rec);
3629 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazccmt_record.deprn_basis_rule',
3630 fa_cache_pkg.fazccmt_record.deprn_basis_rule, p_log_level_rec => p_log_level_rec);
3631 fa_debug_pkg.add(l_calling_fn, 'p_cost_adj',
3632 p_cost_adj, p_log_level_rec => p_log_level_rec);
3633 fa_debug_pkg.add(l_calling_fn, 'p_cost',
3634 p_cost, p_log_level_rec => p_log_level_rec);
3635 end if;
3636
3637 if (fa_cache_pkg.fazccmt_record.rate_source_rule NOT IN ('CALCULATED','FLAT','TABLE')
3638 and nvl(fa_cache_pkg.fazcdrd_record.rule_name,'ZZ') <> 'ENERGY PERIOD END BALANCE'
3639 ) OR
3640 (fa_cache_pkg.fazccmt_record.deprn_basis_rule = 'NBV'
3641 and nvl(fa_cache_pkg.fazcdrd_record.rule_name,'ZZ') <> 'ENERGY PERIOD END BALANCE'
3642 ) OR
3643 (NVL(fa_cache_pkg.fazcbc_record.ALLOW_COST_SIGN_CHANGE_FLAG,'N') = 'N') then
3644 --Members must also belong to a group that has the Over Depreciate Option as
3645 --"Allow and Depreciate"
3646
3647 if ((p_group_asset_id is not null) and
3648 (nvl(p_over_depreciate_option, fa_std_types.FA_OVER_DEPR_NO) =
3649 fa_std_types.FA_OVER_DEPR_DEPRN) and
3650 (NVL(fa_cache_pkg.fazcbc_record.ALLOW_COST_SIGN_CHANGE_FLAG,'N') = 'Y')) then
3651 if (p_log_level_rec.statement_level) then
3652 fa_debug_pkg.add(l_calling_fn, 'Member cost sign','can be changed', p_log_level_rec => p_log_level_rec);
3653 fa_debug_pkg.add(l_calling_fn, 'over depreciate option',p_over_depreciate_option, p_log_level_rec => p_log_level_rec);
3654 fa_debug_pkg.add(l_calling_fn, 'group_asset_id',p_group_asset_id, p_log_level_rec => p_log_level_rec);
3655 end if;
3656 else
3657 if (p_log_level_rec.statement_level) then
3658 fa_debug_pkg.add(l_calling_fn, 'validating cost and salvage','', p_log_level_rec => p_log_level_rec);
3659 fa_debug_pkg.add(l_calling_fn, 'sign change flag',
3660 fa_cache_pkg.fazcbc_record.ALLOW_COST_SIGN_CHANGE_FLAG, p_log_level_rec => p_log_level_rec);
3661 fa_debug_pkg.add(l_calling_fn, 'over depr option',p_over_depreciate_option, p_log_level_rec => p_log_level_rec);
3662 fa_debug_pkg.add(l_calling_fn, 'group_asset_id',p_group_asset_id, p_log_level_rec => p_log_level_rec);
3663 end if;
3664
3665 -- Added following if condition for bugfix# 5131759
3666 if (p_mrc_sob_type_code = 'R') then
3667 OPEN c_get_current_mc_amts;
3668 FETCH c_get_current_mc_amts INTO l_cost, l_salvage_value, l_deprn_limit_amount;
3669 CLOSE c_get_current_mc_amts;
3670 else
3671 OPEN c_get_current_amts;
3672 FETCH c_get_current_amts INTO l_cost, l_salvage_value, l_deprn_limit_amount;
3673 CLOSE c_get_current_amts;
3674 end if; -- (p_mrc_sob_type_code = 'R')
3675
3676 if (p_cost_adj <> 0) and
3677 (sign(nvl(l_cost, 0) + p_cost_adj) <> 0) and
3678 (sign(nvl(l_cost, 0) + p_cost_adj) <> sign(p_cost)) then
3679 if (p_log_level_rec.statement_level) then
3680 fa_debug_pkg.add(l_calling_fn, 'Delta Cost', 'Invalid', p_log_level_rec => p_log_level_rec);
3681 end if;
3682 raise val_err;
3683 end if;
3684
3685 if (p_salvage_value_adj <> 0) and
3686 (sign(nvl(l_salvage_value, 0) + p_salvage_value_adj) <> 0) and
3687 (sign(nvl(l_salvage_value, 0) + p_salvage_value_adj) <>
3688 sign(p_salvage_value)) and
3689 (p_salvage_value <> 0) then -- Bug#6618908
3690 if (p_log_level_rec.statement_level) then
3691 fa_debug_pkg.add(l_calling_fn, 'Delta Salvage Value', 'Invalid', p_log_level_rec => p_log_level_rec);
3692 end if;
3693 raise val_err;
3694 end if;
3695 end if; --group_asset_id not null...
3696
3697 end if; --Cost change condition. End HH.
3698
3699 -- Bug 16265184 need to populate correct amounts if they are null till now
3700 -- opened cursor c_get_current_amts
3701
3702 if (p_deprn_limit_amount_adj <> 0) then
3703 IF l_deprn_limit_amount is null then
3704 if (p_mrc_sob_type_code = 'R') then
3705 OPEN c_get_current_mc_amts;
3706 FETCH c_get_current_mc_amts INTO l_cost, l_salvage_value, l_deprn_limit_amount;
3707 CLOSE c_get_current_mc_amts;
3708 else
3709 OPEN c_get_current_amts;
3710 FETCH c_get_current_amts INTO l_cost, l_salvage_value, l_deprn_limit_amount;
3711 CLOSE c_get_current_amts;
3712 end if;
3713 END IF;
3714 IF (sign(nvl(l_deprn_limit_amount, 0) + p_deprn_limit_amount_adj) <> 0) and
3715 (sign(nvl(l_deprn_limit_amount, 0) + p_deprn_limit_amount_adj) <>
3716 sign(p_deprn_limit_amount)) then
3717 if (p_log_level_rec.statement_level) then
3718 fa_debug_pkg.add(l_calling_fn, 'Delta Deprn Limit Amount', 'Invalid', p_log_level_rec => p_log_level_rec);
3719 end if;
3720 raise val_err;
3721 end if;
3722 end if;
3723
3724 end if; -- ( p_cost <> 0)
3725
3726 return true;
3727
3728 EXCEPTION
3729 WHEN val_err THEN
3730 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
3731 name => 'FA_INVALID_AMOUNT_ADJUSTMENT', p_log_level_rec => p_log_level_rec);
3732 return false;
3733
3734 WHEN OTHERS THEN
3735 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
3736 return false;
3737
3738 END validate_cost_change;
3739
3740
3741 -- New function due for bug2846357
3742 --
3743 -- check if duplicate distribution info exist in p_asset_dist_tbl
3744 -- current row( p_curr_index) of p_asset_dist_tbl is compared to
3745 -- all of previous rows of p_asset_dist_tbl
3746 -- to check for duplicates
3747
3748 FUNCTION validate_duplicate_dist (
3749 p_transaction_type_code IN VARCHAR2,
3750 p_asset_dist_tbl IN OUT NOCOPY FA_API_TYPES.asset_dist_tbl_type,
3751 p_curr_index IN NUMBER,
3752 p_calling_function IN VARCHAR2,
3753 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) return boolean IS
3754
3755 l_high_bound number;
3756 dup_err exception;
3757 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_duplicate_dist';
3758
3759 BEGIN
3760
3761 l_high_bound := p_curr_index - 1;
3762 FOR k in p_asset_dist_tbl.first..l_high_bound LOOP
3763
3764 -- if TRANSFER check if transfering to same line
3765 if p_transaction_type_code = 'TRANSFER' then
3766 if ( p_asset_dist_tbl(k).distribution_id is not null and
3767 p_asset_dist_tbl(p_curr_index).distribution_id is not null) then
3768 if ( p_asset_dist_tbl(k).distribution_id =
3769 p_asset_dist_tbl(p_curr_index).distribution_id)
3770 then
3771 raise dup_err;
3772 end if;
3773 end if;
3774 end if;
3775
3776 -- Check for duplicate lines
3777 --Bug:16038304 Below Validation is bypassed for POST_ALL
3778 --as the same thing is getting through for POST and this
3779 --validation does not fire for POST case.
3780 --When POST MASS Additions is run with identical child line
3781 --merged to parent line it is posting the data properly in contrast to bug:2846357
3782 if p_calling_function <> 'POST_ALL' then
3783 if ( nvl(p_asset_dist_tbl(k).assigned_to,-99) = nvl(p_asset_dist_tbl(p_curr_index).assigned_to,-99) and
3784 p_asset_dist_tbl(k).expense_ccid = p_asset_dist_tbl(p_curr_index).expense_ccid and
3785 p_asset_dist_tbl(k).location_ccid = p_asset_dist_tbl(p_curr_index).location_ccid)
3786 then
3787 raise dup_err;
3788 end if;
3789 end if;
3790 END LOOP;
3791
3792 return true;
3793
3794 EXCEPTION
3795
3796 WHEN dup_err THEN
3797 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
3798 name => 'FA_TFR_SAME_LINE', p_log_level_rec => p_log_level_rec);
3799 return false;
3800
3801 WHEN OTHERS THEN
3802
3803 fa_srvr_msg.add_sql_error(
3804 calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
3805
3806 return false;
3807
3808 END validate_duplicate_dist;
3809
3810 FUNCTION validate_polish
3811 (p_transaction_type_code IN VARCHAR2,
3812 p_method_code IN VARCHAR2,
3813 p_life_in_months IN NUMBER DEFAULT NULL,
3814 p_asset_type IN VARCHAR2 DEFAULT NULL,
3815 p_bonus_rule IN VARCHAR2 DEFAULT NULL,
3816 p_ceiling_name IN VARCHAR2 DEFAULT NULL,
3817 p_deprn_limit_type IN VARCHAR2 DEFAULT NULL,
3818 p_group_asset_id IN NUMBER DEFAULT NULL,
3819 p_date_placed_in_service IN DATE DEFAULT NULL,
3820 p_calendar_period_open_date IN DATE DEFAULT NULL,
3821 p_ytd_deprn IN NUMBER DEFAULT NULL,
3822 p_deprn_reserve IN NUMBER DEFAULT NULL,
3823 p_calling_fn IN VARCHAR2,
3824 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN AS
3825
3826 l_deprn_basis_rule varchar2(80);
3827 l_polish_rule number;
3828 l_calling_fn varchar2(35) := 'fa_asset_val_pvt.validate_polish';
3829
3830 BEGIN
3831
3832 -- First find out if we have a polish mechanism here
3833 if not fa_cache_pkg.fazccmt (
3834 X_method => p_method_code,
3835 X_life => p_life_in_months
3836 , p_log_level_rec => p_log_level_rec) then
3837 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
3838
3839 return FALSE;
3840 end if;
3841
3842 if (fa_cache_pkg.fazccmt_record.deprn_basis_rule_id is not null) then
3843 l_polish_rule := fa_cache_pkg.fazcdbr_record.polish_rule;
3844 else
3845 -- No deprn basis rule attached to this method, so not Polish either
3846 return TRUE;
3847 end if;
3848
3849 if (nvl(l_polish_rule, FA_STD_TYPES.FAD_DBR_POLISH_NONE) not in (
3850 FA_STD_TYPES.FAD_DBR_POLISH_1,
3851 FA_STD_TYPES.FAD_DBR_POLISH_2,
3852 FA_STD_TYPES.FAD_DBR_POLISH_3,
3853 FA_STD_TYPES.FAD_DBR_POLISH_4,
3854 FA_STD_TYPES.FAD_DBR_POLISH_5)) then
3855 -- Not Polish rule
3856 return TRUE;
3857 end if;
3858
3859 -- This is a Polish rule, so start validations.
3860 /*
3861 -- No adjustments allowed on Polish mechanisms.
3862 if (p_transaction_type_code in ('ADJUSTMENT', 'CIP ADJUSTMENT',
3863 'GROUP ADJUSTMENT')) then
3864 fa_srvr_msg.add_message(
3865 calling_fn => l_calling_fn,
3866 name => 'FA_POLISH_NO_ADJ', p_log_level_rec => p_log_level_rec);
3867 return FALSE;
3868 end if;
3869
3870 -- No partial retirements allowed on Polish mechanisms.
3871 if (p_transaction_type_code = 'PARTIAL RETIREMENT') then
3872 fa_srvr_msg.add_message(
3873 calling_fn => l_calling_fn,
3874 name => 'FA_POLISH_NO_PARTIAL_RET', p_log_level_rec => p_log_level_rec);
3875 return FALSE;
3876 end if;
3877 */
3878 -- No revaluations allowed on Polish mechanisms.
3879 if (p_transaction_type_code = 'REVALUATION') then
3880 fa_srvr_msg.add_message(
3881 calling_fn => l_calling_fn,
3882 name => 'FA_POLISH_NO_REVAL', p_log_level_rec => p_log_level_rec);
3883 return FALSE;
3884 end if;
3885
3886 -- No tax reserve adjustments allowed on Polish mechanisms.
3887 if (p_transaction_type_code = 'TAX RESERVE ADJUSTMENT') then
3888 fa_srvr_msg.add_message(
3889 calling_fn => l_calling_fn,
3890 name => 'FA_POLISH_NO_TAX_RSV_ADJ', p_log_level_rec => p_log_level_rec);
3891 return FALSE;
3892 end if;
3893
3894 -- No adding an Polish asset with reserve.
3895 if (p_transaction_type_code in ('ADDITION',
3896 'CIP ADDITION',
3897 'GROUP ADDITION')) then
3898
3899 -- No backdated additions for Polish.
3900 if (p_date_placed_in_service < p_calendar_period_open_date) then
3901 fa_srvr_msg.add_message(
3902 calling_fn => l_calling_fn,
3903 name => 'FA_POLISH_NO_PRIOR_ADD', p_log_level_rec => p_log_level_rec);
3904 return FALSE;
3905 end if;
3906
3907 -- No adding an Polish asset with reserve.
3908 if ((nvl(p_ytd_deprn,0) <> 0) OR (nvl(p_deprn_reserve,0) <> 0)) then
3909 fa_srvr_msg.add_message(
3910 calling_fn => l_calling_fn,
3911 name => 'FA_POLISH_NO_ADD_RSV', p_log_level_rec => p_log_level_rec);
3912 return FALSE;
3913 end if;
3914 end if;
3915
3916 if (p_transaction_type_code in ('ADDITION',
3917 'CIP ADDITION',
3918 'GROUP ADDITION',
3919 'ADJUSTMENT',
3920 'CIP ADJUSTMENT',
3921 'GROUP ADJUSTMENT')) then
3922
3923 -- Mechanisms 1, 3, 4, 5 must have bonus rules attached
3924 if ((p_bonus_rule is null) and
3925 (l_polish_rule in (FA_STD_TYPES.FAD_DBR_POLISH_1,
3926 FA_STD_TYPES.FAD_DBR_POLISH_3,
3927 FA_STD_TYPES.FAD_DBR_POLISH_4,
3928 FA_STD_TYPES.FAD_DBR_POLISH_5))) then
3929
3930 fa_srvr_msg.add_message(
3931 calling_fn => l_calling_fn,
3932 name => 'FA_POLISH_NO_BONUS_RULE', p_log_level_rec => p_log_level_rec);
3933 return FALSE;
3934 end if;
3935
3936 -- No ceilings allowed on Polish rules
3937 if (p_ceiling_name is not null) then
3938 fa_srvr_msg.add_message(
3939 calling_fn => l_calling_fn,
3940 name => 'FA_POLISH_NO_CEILING', p_log_level_rec => p_log_level_rec);
3941 return FALSE;
3942 end if;
3943
3944 -- No depreciation limits allowed on Polish rules
3945 if (nvl(p_deprn_limit_type, 'NONE') <> 'NONE') then
3946 fa_srvr_msg.add_message(
3947 calling_fn => l_calling_fn,
3948 name => 'FA_POLISH_NO_LIMIT', p_log_level_rec => p_log_level_rec);
3949 return FALSE;
3950 end if;
3951
3952 -- No group assets or members of group assets allowed to have Polish
3953 if (p_asset_type = 'GROUP') OR (p_group_asset_id is not null) then
3954 fa_srvr_msg.add_message(
3955 calling_fn => l_calling_fn,
3956 name => 'FA_POLISH_NO_GROUP', p_log_level_rec => p_log_level_rec);
3957 return FALSE;
3958 end if;
3959 end if;
3960
3961 return TRUE;
3962
3963 EXCEPTION
3964 WHEN OTHERS THEN
3965
3966 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
3967
3968 return FALSE;
3969
3970 END validate_polish;
3971
3972 FUNCTION validate_jp250db
3973 (p_transaction_type_code IN VARCHAR2,
3974 p_book_type_code IN VARCHAR2,
3975 p_asset_id IN NUMBER,
3976 p_method_code IN VARCHAR2,
3977 p_life_in_months IN NUMBER DEFAULT NULL,
3978 p_asset_type IN VARCHAR2 DEFAULT NULL,
3979 p_bonus_rule IN VARCHAR2 DEFAULT NULL,
3980 p_transaction_key IN VARCHAR2 DEFAULT NULL,
3981 p_cash_generating_unit_id IN VARCHAR2 DEFAULT NULL,
3982 p_deprn_override_flag IN VARCHAR2 DEFAULT 'N',
3983 p_calling_fn IN VARCHAR2,
3984 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN AS
3985
3986 l_mrc_count number := 0;
3987 l_override_count number := 0;
3988 l_calling_fn varchar2(35) := 'fa_asset_val_pvt.validate_jp250db';
3989
3990 BEGIN
3991
3992 -- First find out if we have a jp 250db mechanism here
3993 if not fa_cache_pkg.fazccmt (
3994 X_method => p_method_code,
3995 X_life => p_life_in_months
3996 , p_log_level_rec => p_log_level_rec) then
3997 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
3998
3999 return FALSE;
4000 end if;
4001
4002 if (nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag, 'NO') <>
4003 'YES') then
4004 -- No guarantee rule attached to this method, so not JP 250DB either
4005 return TRUE;
4006 end if;
4007
4008 if (p_transaction_type_code = 'REVALUATION') then
4009 fa_srvr_msg.add_message(
4010 calling_fn => l_calling_fn,
4011 name => 'FA_REVAL_DUAL_RATE', p_log_level_rec => p_log_level_rec);
4012
4013 return FALSE;
4014 end if;
4015
4016 select count(*)
4017 into l_mrc_count
4018 from fa_mc_book_controls
4019 where book_type_code = p_book_type_code
4020 and enabled_flag = 'Y';
4021
4022 -- Fix for Bug #6334383. Cannot use this method with MRC books.
4023 if (l_mrc_count > 0) then
4024
4025 fa_srvr_msg.add_message(
4026 calling_fn => l_calling_fn,
4027 name => 'FA_MRC_DUAL_RATE', p_log_level_rec => p_log_level_rec);
4028
4029 return FALSE;
4030 end if;
4031
4032 /* Removed this resctriction for enhancement 6688475
4033 if (p_asset_type = 'CIP') then
4034 fa_srvr_msg.add_message(
4035 calling_fn => l_calling_fn,
4036 name => 'FA_CIP_DUAL_RATE', p_log_level_rec => p_log_level_rec);
4037
4038 return FALSE;
4039 end if;
4040 */
4041
4042 /* Japan Tax Phase3 -- Bonus is allowed
4043 Commenting the validation
4044 if (p_bonus_rule is not null) and (p_bonus_rule <> FND_API.G_MISS_CHAR) then
4045 fa_srvr_msg.add_message(
4046 calling_fn => l_calling_fn,
4047 name => 'FA_BONUS_DUAL_RATE', p_log_level_rec => p_log_level_rec);
4048
4049 return FALSE;
4050 end if; */
4051
4052 /*Phase5 impairment is allowed on 250db Assets
4053 -- removing the validation to prevent Assigning of CGUs on assets using garauntee rate method*/
4054
4055 return TRUE;
4056
4057 EXCEPTION
4058 WHEN OTHERS THEN
4059
4060 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
4061
4062 return FALSE;
4063
4064 END validate_jp250db;
4065
4066 FUNCTION validate_super_group (
4067 p_book_type_code IN VARCHAR2,
4068 p_old_super_group_id IN NUMBER,
4069 p_new_super_group_id IN NUMBER,
4070 p_calling_fn IN VARCHAR2,
4071 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4072
4073 l_calling_fn varchar2(40) := 'fa_asset_val_pvt.validate_super_group';
4074
4075 CURSOR c_check_used is
4076 select 'Y'
4077 from fa_super_group_rules
4078 where super_group_id = p_new_super_group_id
4079 and book_type_code = p_book_type_code
4080 and used_flag = 'Y';
4081
4082 l_used_flag varchar2(1);
4083
4084 BEGIN
4085
4086 if (not(nvl(p_old_super_group_id, -99) = nvl(p_new_super_group_id, -99))) then
4087 if (p_old_super_group_id is null) and
4088 (p_new_super_group_id is not null) then
4089
4090 OPEN c_check_used;
4091 FETCH c_check_used INTO l_used_flag;
4092
4093 if (c_check_used%FOUND) then
4094
4095 CLOSE c_check_used;
4096
4097 if (p_log_level_rec.statement_level) then
4098 fa_debug_pkg.add(l_calling_fn, 'p_book_type_code', p_book_type_code, p_log_level_rec => p_log_level_rec);
4099 fa_debug_pkg.add(l_calling_fn, 'p_new_super_group_id', p_new_super_group_id, p_log_level_rec => p_log_level_rec);
4100 fa_debug_pkg.add(l_calling_fn, 'This Super group is used', 'TRUE', p_log_level_rec => p_log_level_rec);
4101 end if;
4102
4103 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
4104 name => 'FA_SUPER_GROUP_USED', p_log_level_rec => p_log_level_rec);
4105
4106 return FALSE;
4107 end if; -- (c_check_used%FOUND)
4108
4109 CLOSE c_check_used;
4110
4111 end if; -- (p_old_super_group_id is null) and
4112
4113 end if;
4114
4115 return true;
4116
4117 EXCEPTION
4118 WHEN OTHERS THEN
4119 if (p_log_level_rec.statement_level) then
4120 fa_debug_pkg.add(l_calling_fn, 'p_book_type_code', p_book_type_code, p_log_level_rec => p_log_level_rec);
4121 fa_debug_pkg.add(l_calling_fn, 'p_old_super_group_id', p_old_super_group_id, p_log_level_rec => p_log_level_rec);
4122 fa_debug_pkg.add(l_calling_fn, 'p_new_super_group_id', p_new_super_group_id, p_log_level_rec => p_log_level_rec);
4123 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm, p_log_level_rec => p_log_level_rec);
4124 end if;
4125
4126 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
4127
4128 return FALSE;
4129 END validate_super_group;
4130
4131 FUNCTION validate_member_dpis
4132 (p_book_type_code IN VARCHAR2,
4133 p_date_placed_in_service IN DATE,
4134 p_group_asset_Id IN NUMBER,
4135 p_calling_fn IN VARCHAR2,
4136 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4137
4138 CURSOR c_group_dpis (p_group_asset_id NUMBER,
4139 p_book_type_code VARCHAR2) is
4140 select date_placed_in_service
4141 from fa_books
4142 where asset_id = p_group_asset_id
4143 and book_type_code = p_book_type_code
4144 and transaction_header_id_out is null;
4145
4146 l_group_dpis date;
4147 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_member_dpis';
4148
4149 BEGIN
4150
4151 open c_group_dpis(p_group_asset_Id, p_book_type_code);
4152 fetch c_group_dpis
4153 into l_group_dpis;
4154 close c_group_dpis;
4155
4156 if (p_date_placed_in_service < l_group_dpis) then
4157 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
4158 name => 'FA_INVALID_MEMBER_DPIS',
4159 token1 => 'DATE',
4160 value1 => l_group_dpis, p_log_level_rec => p_log_level_rec);
4161 return false;
4162 else
4163 return true;
4164 end if;
4165
4166 EXCEPTION
4167 WHEN OTHERS THEN
4168 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
4169 return false;
4170
4171 END validate_member_dpis;
4172
4173 FUNCTION validate_egy_prod_date (
4174 p_calendar_period_start_date IN DATE,
4175 p_transaction_date IN DATE,
4176 p_transaction_key IN VARCHAR2,
4177 p_rate_source_rule IN VARCHAR2,
4178 p_rule_name IN VARCHAR2,
4179 p_calling_fn IN VARCHAR2,
4180 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4181
4182 l_calling_fn varchar2(50) := 'FA_ASSET_VAL_PVT.validate_egy_prod_date';
4183
4184 BEGIN
4185
4186 if (p_log_level_rec.statement_level) then
4187 fa_debug_pkg.add(l_calling_fn, 'p_transaction_date', 'p_transaction_date', p_log_level_rec => p_log_level_rec);
4188 end if;
4189
4190 if (p_calendar_period_start_date > p_transaction_date) and
4191 (p_rate_source_rule = 'PRODUCTION') and
4192 (p_rule_name = 'ENERGY PERIOD END BALANCE') and
4193 (nvl(p_transaction_key, 'NULL') <> 'MS') then
4194
4195 fa_srvr_msg.add_message(
4196 calling_fn => l_calling_fn,
4197 name => 'FA_CURRENT_DATE_ONLY', p_log_level_rec => p_log_level_rec);
4198 return FALSE;
4199 end if;
4200
4201 if (p_log_level_rec.statement_level) then
4202 fa_debug_pkg.add(l_calling_fn, 'End', ' ', p_log_level_rec => p_log_level_rec);
4203 end if;
4204
4205 return true;
4206
4207 EXCEPTION
4208 WHEN OTHERS THEN
4209 if (p_log_level_rec.statement_level) then
4210 fa_debug_pkg.add(l_calling_fn, 'p_calendar_period_start_date', p_calendar_period_start_date, p_log_level_rec => p_log_level_rec);
4211 fa_debug_pkg.add(l_calling_fn, 'p_transaction_date', p_transaction_date, p_log_level_rec => p_log_level_rec);
4212 fa_debug_pkg.add(l_calling_fn, 'p_rate_source_rule', p_rate_source_rule, p_log_level_rec => p_log_level_rec);
4213 fa_debug_pkg.add(l_calling_fn, 'p_rule_name', p_rule_name, p_log_level_rec => p_log_level_rec);
4214 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm, p_log_level_rec => p_log_level_rec);
4215 end if;
4216
4217 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
4218
4219 return FALSE;
4220 END validate_egy_prod_date;
4221
4222 -- Bug:5154035
4223 FUNCTION validate_reval_exists (
4224 p_book_type_code IN VARCHAR2,
4225 p_asset_Id IN NUMBER,
4226 p_calling_fn IN VARCHAR2,
4227 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
4228
4229 CURSOR c_reval_exists (l_asset_id NUMBER,
4230 l_book_type_code VARCHAR2) is
4231 select 'x'
4232 from FA_Transaction_Headers
4233 where Asset_ID = l_asset_id
4234 and Book_type_Code = l_book_type_code
4235 and Transaction_Type_Code = 'REVALUATION';
4236
4237 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_reval_exists';
4238 l_reval_exists varchar2(1);
4239
4240 BEGIN
4241
4242 open c_reval_exists(p_asset_id, p_book_type_code);
4243 fetch c_reval_exists into l_reval_exists;
4244
4245 if (c_reval_exists%NOTFOUND) then
4246 close c_reval_exists;
4247 return false;
4248 end if;
4249
4250 close c_reval_exists;
4251
4252 return true;
4253
4254 EXCEPTION
4255 WHEN OTHERS THEN
4256 if (p_log_level_rec.statement_level) then
4257 fa_debug_pkg.add(l_calling_fn, 'p_asset_id', p_asset_id);
4258 fa_debug_pkg.add(l_calling_fn, 'p_book_type_code', p_book_type_code);
4259 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm);
4260 end if;
4261
4262 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn);
4263
4264 return false;
4265 END validate_reval_exists;
4266
4267
4268 /* Japan Tax Phase3 Prevent cost adjustment
4269 and method change for assets in extended depreciation */
4270 FUNCTION validate_extended_asset (
4271 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
4272 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
4273 p_asset_fin_rec_adj IN FA_API_TYPES.asset_fin_rec_type,
4274 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4275
4276 l_calling_fn varchar2(50) := 'FA_ASSET_VAL_PVT.validate_extended_asset';
4277 l_mrc_count number := 0;
4278
4279 BEGIN
4280
4281 if (p_log_level_rec.statement_level) then
4282 fa_debug_pkg.add(l_calling_fn, 'Enter ', p_asset_hdr_rec.asset_id, p_log_level_rec => p_log_level_rec);
4283 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.cost', p_asset_fin_rec_adj.cost, p_log_level_rec => p_log_level_rec);
4284 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.life_in_months', p_asset_fin_rec_adj.life_in_months, p_log_level_rec => p_log_level_rec);
4285 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.deprn_method_code',
4286 p_asset_fin_rec_adj.deprn_method_code, p_log_level_rec => p_log_level_rec);
4287 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.date_placed_in_service',
4288 p_asset_fin_rec_adj.date_placed_in_service, p_log_level_rec => p_log_level_rec);
4289 end if;
4290
4291 if (nvl(p_asset_fin_rec_adj.cost,0) <> 0) then
4292 fa_srvr_msg.add_message(
4293 calling_fn => l_calling_fn,
4294 name => 'FA_JP_COST_CHG_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
4295 return FALSE;
4296 end if;
4297
4298 if (p_asset_fin_rec_old.deprn_method_code <> nvl(p_asset_fin_rec_adj.deprn_method_code,
4299 p_asset_fin_rec_old.deprn_method_code)) then
4300 fa_srvr_msg.add_message(
4301 calling_fn => l_calling_fn,
4302 name => 'FA_JP_METHOD_CHG_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
4303 return FALSE;
4304 end if;
4305
4306 select count(*)
4307 into l_mrc_count
4308 from fa_mc_book_controls
4309 where book_type_code = p_asset_hdr_rec.book_type_code
4310 and enabled_flag = 'Y';
4311
4312 -- Cannot use extended deprn with MRC books.
4313 if (l_mrc_count > 0) then
4314
4315 fa_srvr_msg.add_message(
4316 calling_fn => l_calling_fn,
4317 name => 'FA_JP_MRC_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
4318
4319 return FALSE;
4320 end if;
4321
4322 -- Bug 6625840 prevent salvage value change
4323 if (nvl(p_asset_fin_rec_adj.percent_salvage_value, 0) <> 0 or
4324 nvl(p_asset_fin_rec_adj.salvage_value, 0) <> 0)then
4325 fa_srvr_msg.add_message(
4326 calling_fn => l_calling_fn,
4327 name => 'FA_JP_SALVAGE_CHG_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
4328 return FALSE;
4329 end if;
4330
4331 -- Bug 6625840 prevent deprn_limit change
4332 if (nvl(p_asset_fin_rec_adj.allowed_deprn_limit_amount, 0) <> 0 or
4333 nvl(p_asset_fin_rec_adj.allowed_deprn_limit, 0) <> 0) then
4334 fa_srvr_msg.add_message(
4335 calling_fn => l_calling_fn,
4336 name => 'FA_JP_LIMIT_CHG_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
4337 return FALSE;
4338 end if;
4339
4340 -- Bug 6669432 prevent DPIS change
4341 if (p_asset_fin_rec_old.date_placed_in_service <> nvl(p_asset_fin_rec_adj.date_placed_in_service,
4342 p_asset_fin_rec_old.date_placed_in_service)) then
4343 fa_srvr_msg.add_message(
4344 calling_fn => l_calling_fn,
4345 name => 'FA_JP_DPIS_CHG_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
4346 return FALSE;
4347 end if;
4348
4349 if (p_log_level_rec.statement_level) then
4350 fa_debug_pkg.add(l_calling_fn, 'End', ' ', p_log_level_rec => p_log_level_rec);
4351 end if;
4352
4353 return true;
4354
4355 EXCEPTION
4356 WHEN OTHERS THEN
4357 if (p_log_level_rec.statement_level) then
4358 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id, p_log_level_rec => p_log_level_rec);
4359 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.cost', p_asset_fin_rec_adj.cost, p_log_level_rec => p_log_level_rec);
4360 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.deprn_method_code',
4361 p_asset_fin_rec_adj.deprn_method_code, p_log_level_rec => p_log_level_rec);
4362 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm, p_log_level_rec => p_log_level_rec);
4363 end if;
4364
4365 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
4366
4367 return FALSE;
4368 END validate_extended_asset;
4369
4370 FUNCTION validate_extending_asset (
4371 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
4372 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
4373 p_asset_fin_rec_adj IN FA_API_TYPES.asset_fin_rec_type,
4374 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
4375 p_period_rec IN FA_API_TYPES.period_rec_type,
4376 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN is
4377
4378 l_calling_fn varchar2(50) := 'FA_ASSET_VAL_PVT.validate_extending_asset';
4379 l_count number :=0 ;
4380 BEGIN
4381
4382 -- Bug 7491880 Validation for extended deprn on group/member
4383 if (p_asset_type_rec.asset_type = 'GROUP') OR
4384 (p_asset_fin_rec_old.group_asset_id is not null) OR
4385 (nvl(p_asset_fin_rec_adj.group_asset_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) then
4386
4387 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
4388 name => 'FA_EXT_DPRN_NOT_ALLOWED_ON_GRP',
4389 p_log_level_rec => p_log_level_rec);
4390 return FALSE;
4391 end if;
4392
4393 -- Bug 10025180 : Don't extend an asset which is fully reserved in current period
4394 -- R12 : Auto rollback will update the pc_fully_rsvd to null
4395 -- 11i : Don't extend an asset which is not fully reserved
4396 -- Bug : 10115225 modified the below if condition
4397 if (p_asset_fin_rec_old.period_counter_fully_reserved is null)
4398 AND (NVL(p_asset_fin_rec_adj.period_counter_fully_reserved,p_period_rec.period_counter) = p_period_rec.period_counter )then
4399 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
4400 name => 'FA_CP_EXT_DPRN_NOT_ALLOWED',
4401 p_log_level_rec => p_log_level_rec);
4402 return FALSE;
4403 end if;
4404
4405 return TRUE;
4406
4407 EXCEPTION
4408 WHEN OTHERS THEN
4409 if (p_log_level_rec.statement_level) then
4410 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id, p_log_level_rec => p_log_level_rec);
4411 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm, p_log_level_rec => p_log_level_rec);
4412 end if;
4413
4414 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn , p_log_level_rec => p_log_level_rec);
4415
4416 return FALSE;
4417
4418 END validate_extending_asset;
4419
4420
4421 /** Japan Tax Reform ER No.s 6606548 and 6606552
4422 Validation of additional fields **/
4423
4424 -- Bug#7698030 Start
4425 FUNCTION validate_JP_STL_EXTND(
4426 p_prior_deprn_method IN VARCHAR2 DEFAULT NULL,
4427 p_prior_basic_rate IN NUMBER DEFAULT NULL,
4428 p_prior_adjusted_rate IN NUMBER DEFAULT NULL,
4429 p_prior_life_in_months IN NUMBER DEFAULT NULL,
4430 p_calling_fn IN VARCHAR2,
4431 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4432
4433 cursor lcu_deprn_method(p_prior_deprn_method in varchar2)
4434 is
4435
4436 select count('1')
4437 from fa_methods fm
4438 where fm.method_code = p_prior_deprn_method;
4439
4440 CURSOR l_life_in_months(p_method IN VARCHAR2
4441 ,p_life_in_months IN NUMBER
4442 )
4443 IS
4444 select count(1)
4445 from fa_methods fm
4446 where fm.method_code = p_method
4447 and fm.life_in_months = p_life_in_months;
4448
4449 CURSOR lc_depr_rates(p_method IN VARCHAR2
4450 ,p_prior_basic_rate IN NUMBER
4451 ,p_prior_adjusted_rate IN NUMBER )
4452 IS
4453 select count(1)
4454 from fa_methods fm
4455 ,fa_flat_rates ffr
4456 where fm.method_code = p_method
4457 and ffr.method_id = fm.method_id
4458 and ffr.basic_rate = p_prior_basic_rate
4459 and ffr.adjusted_rate = p_prior_adjusted_rate;
4460
4461 TYPE l_msg_error_rec IS RECORD(mass_addition_id NUMBER
4462 ,exception_code VARCHAR2(10)
4463 );
4464 TYPE l_msg_error_tbl IS TABLE OF l_msg_error_rec INDEX BY BINARY_INTEGER;
4465
4466 l_error_msg l_msg_error_tbl;
4467 l_dummy_cnt number := 0;
4468 l_count number := 1;
4469 l_exception_code varchar2(100);
4470 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_JP_STL_EXTND';
4471 validate_ex exception;
4472
4473 BEGIN
4474
4475 l_exception_code := null;
4476
4477 if (p_log_level_rec.statement_level) then
4478 fa_debug_pkg.add(p_calling_fn,
4479 'performing','JP-STL-EXTND method validation', p_log_level_rec => p_log_level_rec);
4480
4481 end if;
4482
4483 l_dummy_cnt := 0;
4484 if p_prior_deprn_method is not null then
4485 open lcu_deprn_method(p_prior_deprn_method);
4486 fetch lcu_deprn_method into l_dummy_cnt;
4487 close lcu_deprn_method;
4488 if l_dummy_cnt = 0 then
4489 fa_srvr_msg.add_message(
4490 CALLING_FN => l_calling_fn,
4491 NAME => 'FA_SHARED_OBJECT_NOT_DEF',
4492 TOKEN1 => 'OBJECT',
4493 VALUE1 => 'Method', p_log_level_rec => p_log_level_rec);
4494 return FALSE;
4495
4496 else
4497 if (p_prior_basic_rate is null or p_prior_adjusted_rate is null) and (p_prior_life_in_months is null) then
4498 fa_srvr_msg.add_message(
4499 CALLING_FN => l_calling_fn,
4500 NAME => 'FA_JP_RATES_LIFE_IN_MONTHS_NUL'
4501 , p_log_level_rec => p_log_level_rec);
4502 return FALSE;
4503 elsif p_prior_life_in_months is not null then
4504 l_dummy_cnt := 0;
4505 open l_life_in_months(p_prior_deprn_method
4506 ,p_prior_life_in_months
4507 );
4508 fetch l_life_in_months into l_dummy_cnt;
4509 close l_life_in_months;
4510 if l_dummy_cnt = 0 then
4511 fa_srvr_msg.add_message(
4512 CALLING_FN => l_calling_fn,
4513 NAME => 'FA_SHARED_INVALID_METHOD_LIFE'
4514 , p_log_level_rec => p_log_level_rec);
4515 return FALSE;
4516 end if;
4517 elsif p_prior_basic_rate is not null and p_prior_adjusted_rate is not null then
4518 l_dummy_cnt := 0;
4519 open lc_depr_rates(p_prior_deprn_method
4520 ,p_prior_basic_rate
4521 ,p_prior_adjusted_rate
4522 );
4523 fetch lc_depr_rates into l_dummy_cnt;
4524 close lc_depr_rates;
4525 if l_dummy_cnt = 0 then
4526 fa_srvr_msg.add_message(
4527 CALLING_FN => l_calling_fn,
4528 NAME => 'FA_SHARED_INVALID_METHOD_RATE'
4529 , p_log_level_rec => p_log_level_rec);
4530 return FALSE;
4531 end if;
4532 end if;
4533 end if;
4534
4535
4536 end if;
4537
4538
4539 return TRUE;
4540 exception
4541 WHEN OTHERS THEN
4542 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
4543 return false;
4544 END validate_JP_STL_EXTND;
4545
4546
4547 FUNCTION validate_earl_deprn_limit(
4548 p_prior_deprn_limit_amount IN NUMBER DEFAULT NULL,
4549 p_prior_deprn_limit IN NUMBER DEFAULT NULL,
4550 p_prior_deprn_limit_type IN VARCHAR2 DEFAULT NULL,
4551 p_calling_fn IN VARCHAR2,
4552 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4553
4554 TYPE l_msg_error_rec IS RECORD(mass_addition_id NUMBER
4555 ,exception_code VARCHAR2(10)
4556 );
4557 TYPE l_msg_error_tbl IS TABLE OF l_msg_error_rec INDEX BY BINARY_INTEGER;
4558
4559 l_error_msg l_msg_error_tbl;
4560
4561
4562
4563 l_count number := 1;
4564 l_exception_code varchar2(100);
4565 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_earl_deprn_limit';
4566 validate_ex exception;
4567
4568
4569 BEGIN
4570 l_exception_code := null;
4571
4572
4573 if (p_log_level_rec.statement_level) then
4574 fa_debug_pkg.add(p_calling_fn,
4575 'performing','Earlier depreciable limit Validation', p_log_level_rec => p_log_level_rec);
4576 end if;
4577
4578 if p_prior_deprn_limit_type in ('AMT','PCT') then
4579 if ( (p_prior_deprn_limit_amount is null) and (p_prior_deprn_limit is null) ) then
4580 fa_srvr_msg.add_message(
4581 CALLING_FN => l_calling_fn,
4582 NAME => 'FA_ADI_INVALID_DEPRNLIMIT_TYPE'
4583 , p_log_level_rec => p_log_level_rec);
4584 return FALSE;
4585 end if;
4586 else
4587 fa_srvr_msg.add_message(
4588 CALLING_FN => l_calling_fn,
4589 NAME => 'FA_ADI_INVALID_DEPRNLIMIT_TYPE'
4590 , p_log_level_rec => p_log_level_rec);
4591 return FALSE;
4592 end if;
4593
4594 return TRUE;
4595 exception
4596 WHEN OTHERS THEN
4597 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
4598 return false;
4599
4600 END validate_earl_deprn_limit;
4601
4602 FUNCTION validate_period_fully_reserved(
4603 p_book_type_code IN VARCHAR2,
4604 p_pc_fully_reserved IN NUMBER DEFAULT NULL,
4605 p_date_placed_in_service IN DATE,
4606 p_calling_fn IN VARCHAR2,
4607 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4608
4609 cursor lcu_period_info(p_book_type_code in varchar2
4610 ,p_period_ctr in number
4611 )
4612 is
4613 select fcp.end_date
4614 from fa_fiscal_year ffy
4615 ,fa_book_controls fbc
4616 ,fa_calendar_periods fcp
4617 ,fa_calendar_types fct
4618 where ffy.fiscal_year_name = fbc.fiscal_year_name
4619 and ffy.fiscal_year_name = fct.fiscal_year_name
4620 and fbc.book_type_code = p_book_type_code
4621 and fcp.calendar_type = fct.calendar_type
4622 and fct.calendar_type = fbc.deprn_calendar
4623 and fcp.start_date >= ffy.start_date
4624 and fcp.end_date <= ffy.end_date
4625 and (ffy.fiscal_year * fct.number_per_fiscal_year + fcp.period_num) = p_period_ctr;
4626
4627 cursor lcu_curr_open_period(p_book_type_code in varchar2
4628 )
4629 is
4630 select fdp.calendar_period_close_date
4631 from fa_book_controls fbc
4632 ,fa_deprn_periods fdp
4633 where fbc.book_type_code = fdp.book_type_code
4634 and fdp.period_counter = fbc.last_period_counter+1
4635 and fbc.book_type_code = p_book_type_code;
4636
4637 TYPE l_msg_error_rec IS RECORD(mass_addition_id NUMBER
4638 ,exception_code VARCHAR2(10)
4639 );
4640 TYPE l_msg_error_tbl IS TABLE OF l_msg_error_rec INDEX BY BINARY_INTEGER;
4641
4642 l_error_msg l_msg_error_tbl;
4643
4644 l_period_end_dt date;
4645 l_current_period_dt date;
4646 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_period_fully_reserved';
4647 l_count number := 1;
4648 l_exception_code varchar2(100);
4649 validate_ex exception;
4650
4651
4652 BEGIN
4653
4654 l_exception_code := null;
4655
4656 open lcu_curr_open_period(p_book_type_code
4657 );
4658 fetch lcu_curr_open_period into l_current_period_dt;
4659 close lcu_curr_open_period;
4660
4661
4662 if (p_log_level_rec.statement_level) then
4663 fa_debug_pkg.add(p_calling_fn,
4664 'performing','Period when fully reserved validation', p_log_level_rec => p_log_level_rec);
4665 end if;
4666
4667 if p_pc_fully_reserved is null then
4668 fa_srvr_msg.add_message(
4669 CALLING_FN => l_calling_fn,
4670 NAME => 'FA_JP_FULLY_RESERVED_PC_NULL'
4671 , p_log_level_rec => p_log_level_rec);
4672 return FALSE;
4673 end if;
4674
4675 l_period_end_dt := null;
4676 open lcu_period_info(p_book_type_code
4677 ,p_pc_fully_reserved
4678 );
4679 fetch lcu_period_info into l_period_end_dt;
4680 close lcu_period_info;
4681 if (l_period_end_dt is null) then
4682 fa_srvr_msg.add_message(
4683 CALLING_FN => l_calling_fn,
4684 NAME => 'FA_JP_PERIOD_ENDDATE_NULL'
4685 , p_log_level_rec => p_log_level_rec);
4686 return FALSE;
4687
4688 elsif (trunc(l_period_end_dt) < trunc(p_date_placed_in_service)) then
4689 fa_srvr_msg.add_message(
4690 CALLING_FN => l_calling_fn,
4691 NAME => 'FA_JP_ENDDATE_EARLY_DPIS'
4692 , p_log_level_rec => p_log_level_rec);
4693 return FALSE;
4694
4695 elsif (trunc(l_period_end_dt) > trunc(l_current_period_dt) ) then
4696
4697 fa_srvr_msg.add_message(
4698 CALLING_FN => l_calling_fn,
4699 NAME => 'FA_JP_ENDDATE_GREATER_CUR_DATE'
4700 , p_log_level_rec => p_log_level_rec);
4701 return FALSE;
4702 end if;
4703
4704
4705 return TRUE;
4706 exception
4707 WHEN OTHERS THEN
4708 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
4709 return false;
4710
4711 END validate_period_fully_reserved;
4712
4713 FUNCTION validate_fst_prd_extd_deprn(
4714 p_book_type_code IN VARCHAR2,
4715 p_extended_deprn_period IN NUMBER DEFAULT NULL,
4716 p_date_placed_in_service IN DATE,
4717 p_calling_fn IN VARCHAR2,
4718 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4719
4720 cursor lcu_period_info(p_book_type_code in varchar2,
4721 p_period_ctr in number) is
4722 select fcp.end_date
4723 from fa_fiscal_year ffy
4724 ,fa_book_controls fbc
4725 ,fa_calendar_periods fcp
4726 ,fa_calendar_types fct
4727 where ffy.fiscal_year_name = fbc.fiscal_year_name
4728 and ffy.fiscal_year_name = fct.fiscal_year_name
4729 and fbc.book_type_code = p_book_type_code
4730 and fcp.calendar_type = fct.calendar_type
4731 and fct.calendar_type = fbc.deprn_calendar
4732 and fcp.start_date >= ffy.start_date
4733 and fcp.end_date <= ffy.end_date
4734 and (ffy.fiscal_year * fct.number_per_fiscal_year + fcp.period_num) = p_period_ctr;
4735
4736 TYPE l_msg_error_rec IS RECORD(mass_addition_id NUMBER
4737 ,exception_code VARCHAR2(10)
4738 );
4739 TYPE l_msg_error_tbl IS TABLE OF l_msg_error_rec INDEX BY BINARY_INTEGER;
4740
4741 l_error_msg l_msg_error_tbl;
4742 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_fst_prd_extd_deprn';
4743 l_period_end_dt date;
4744 l_default_dt date := to_date('01-04-2007','DD-MM-RRRR');
4745
4746
4747
4748 l_count number := 1;
4749 l_exception_code varchar2(100);
4750 validate_ex exception;
4751
4752
4753 BEGIN
4754
4755 l_exception_code := null;
4756
4757 if (p_log_level_rec.statement_level) then
4758 fa_debug_pkg.add(p_calling_fn,
4759 'performing','First period of extended depreciation validation', p_log_level_rec => p_log_level_rec);
4760 end if;
4761
4762 l_period_end_dt := null;
4763 open lcu_period_info(p_book_type_code
4764 ,p_extended_deprn_period
4765 );
4766 fetch lcu_period_info into l_period_end_dt;
4767 close lcu_period_info;
4768 if l_period_end_dt is null then
4769 fa_srvr_msg.add_message(
4770 CALLING_FN => l_calling_fn,
4771 NAME => 'FA_JP_PERIOD_ENDDATE_NULL'
4772 , p_log_level_rec => p_log_level_rec);
4773 return FALSE;
4774 elsif (trunc(l_period_end_dt) < trunc(l_default_dt)) then
4775 fa_srvr_msg.add_message(
4776 CALLING_FN => l_calling_fn,
4777 NAME => 'FA_JP_PERIOD_ENDDATE_WRONG'
4778 , p_log_level_rec => p_log_level_rec);
4779 return FALSE;
4780 elsif (trunc(l_period_end_dt) < trunc(p_date_placed_in_service)) then
4781 fa_srvr_msg.add_message(
4782 CALLING_FN => l_calling_fn,
4783 NAME => 'FA_JP_ENDDATE_EARLY_DPIS'
4784 , p_log_level_rec => p_log_level_rec);
4785 return FALSE;
4786 end if;
4787
4788 return TRUE;
4789 exception
4790 WHEN OTHERS THEN
4791 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
4792 return false;
4793
4794
4795
4796 END validate_fst_prd_extd_deprn;
4797
4798 FUNCTION validate_NOT_JP_STL_EXTND(
4799 p_book_type_code IN VARCHAR2,
4800 p_deprn_limit IN NUMBER DEFAULT NULL,
4801 p_sp_deprn_limit IN NUMBER DEFAULT NULL,
4802 p_deprn_reserve IN NUMBER DEFAULT NULL,
4803 p_asset_type IN VARCHAR2 DEFAULT NULL,
4804 p_pc_fully_reserved IN NUMBER DEFAULT NULL,
4805 p_date_placed_in_service IN DATE,
4806 p_cost IN NUMBER DEFAULT NULL,
4807 p_calling_fn IN VARCHAR2,
4808 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4809
4810 TYPE l_msg_error_rec IS RECORD(mass_addition_id NUMBER
4811 ,exception_code VARCHAR2(10)
4812 );
4813 TYPE l_msg_error_tbl IS TABLE OF l_msg_error_rec INDEX BY BINARY_INTEGER;
4814
4815 l_error_msg l_msg_error_tbl;
4816
4817 l_count number := 1;
4818 l_period_end_dt date;
4819 l_current_period_dt date;
4820 l_amt number;
4821 l_exception_code varchar2(100);
4822 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_NOT_JP_STL_EXTND';
4823 validate_ex exception;
4824
4825 cursor lcu_period_info(p_book_type_code in varchar2
4826 ,p_period_ctr in number
4827 )
4828 is
4829 select fcp.end_date
4830 from fa_fiscal_year ffy
4831 ,fa_book_controls fbc
4832 ,fa_calendar_periods fcp
4833 ,fa_calendar_types fct
4834 where ffy.fiscal_year_name = fbc.fiscal_year_name
4835 and ffy.fiscal_year_name = fct.fiscal_year_name
4836 and fbc.book_type_code = p_book_type_code
4837 and fcp.calendar_type = fct.calendar_type
4838 and fct.calendar_type = fbc.deprn_calendar
4839 and fcp.start_date >= ffy.start_date
4840 and fcp.end_date <= ffy.end_date
4841 and (ffy.fiscal_year * fct.number_per_fiscal_year + fcp.period_num) = p_period_ctr;
4842
4843 cursor lcu_curr_open_period(p_book_type_code in varchar2
4844 )
4845 is
4846 select fdp.calendar_period_close_date
4847 from fa_book_controls fbc
4848 ,fa_deprn_periods fdp
4849 where fbc.book_type_code = fdp.book_type_code
4850 and fdp.period_counter = fbc.last_period_counter+1
4851 and fbc.book_type_code = p_book_type_code;
4852
4853
4854 BEGIN
4855
4856 l_exception_code := null;
4857
4858 if (p_log_level_rec.statement_level) then
4859 fa_debug_pkg.add(p_calling_fn,
4860 'performing','NOT-JP-STL_EXTND validation', p_log_level_rec => p_log_level_rec);
4861 end if;
4862
4863 open lcu_curr_open_period(p_book_type_code
4864 );
4865 fetch lcu_curr_open_period into l_current_period_dt;
4866 close lcu_curr_open_period;
4867 if p_deprn_limit is not null then
4868 l_amt := NVL(p_cost,0) * NVL(p_deprn_limit,0);
4869 l_amt := NVL(p_cost,0) - l_amt;
4870 end if;
4871 if p_sp_deprn_limit is not null then
4872 l_amt := NVL(p_sp_deprn_limit,0);
4873 end if;
4874 if NVL(p_cost,0) <> 0 AND NVL(p_cost,0) - NVL(l_amt,0) - NVL(p_deprn_reserve,0) = 0 then --- BUG# 7368126 "NVL(p_cost,0) > 0 AND" is added to avoid the erroring out of Mass Additions post program, if the Asset cost = 0
4875 --check with the nbv <= 0 then period full resrve is mandatory
4876 if p_asset_type NOT IN ( 'GROUP','CIP') then --- BUG# 7368126 "p_asset_type NOT IN ( 'GROUP','CIP')" is added to avoid the erroring out of Mass Additions post program, if the Asset_type is GROUP, CIP
4877 if (p_log_level_rec.statement_level) then
4878 fa_debug_pkg.add(p_calling_fn,
4879 'performing','First period of extended depreciation validation', p_log_level_rec => p_log_level_rec);
4880 end if;
4881 --Bug7114834 Changed the condition that checks for null p_pc_fully_reserved
4882 if p_pc_fully_reserved is not null then
4883
4884 l_period_end_dt := null;
4885 open lcu_period_info(p_book_type_code
4886 ,p_pc_fully_reserved
4887 );
4888 fetch lcu_period_info into l_period_end_dt;
4889 close lcu_period_info;
4890 if (trunc(l_period_end_dt) < trunc(p_date_placed_in_service)) then
4891 fa_srvr_msg.add_message(
4892 CALLING_FN => l_calling_fn,
4893 NAME => 'FA_JP_ENDDATE_EARLY_DPIS'
4894 , p_log_level_rec => p_log_level_rec);
4895 return FALSE;
4896 elsif (trunc(l_period_end_dt) > trunc(l_current_period_dt) ) then
4897 fa_srvr_msg.add_message(
4898 CALLING_FN => l_calling_fn,
4899 NAME => 'FA_JP_ENDDATE_GREATER_CUR_DATE'
4900 , p_log_level_rec => p_log_level_rec);
4901 return FALSE;
4902 end if;
4903 end if; --p_pc_fully_reserved is not null
4904 end if; -- p_asset_type NOT IN ( 'GROUP','CIP')
4905 end if;
4906
4907 return TRUE;
4908 exception
4909 WHEN OTHERS THEN
4910 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
4911 return false;
4912
4913 END validate_NOT_JP_STL_EXTND;
4914
4915 FUNCTION validate_JP_250_DB(
4916 p_deprn_method_code IN VARCHAR2 DEFAULT NULL,
4917 p_cost IN NUMBER DEFAULT NULL,
4918 p_nbv_at_switch IN NUMBER DEFAULT NULL,
4919 p_deprn_reserve IN NUMBER DEFAULT NULL,
4920 p_ytd_deprn IN NUMBER DEFAULT NULL,
4921 p_calling_fn IN VARCHAR2,
4922 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
4923
4924 cursor lcu_rates_info(p_method_code in varchar2)
4925 is
4926 select ff.original_rate
4927 ,ff.revised_rate
4928 ,ff.guarantee_rate
4929 from fa_formulas ff
4930 ,fa_methods fm
4931 where ff.method_id = fm.method_id
4932 and fm.method_code = p_method_code;
4933
4934 TYPE l_msg_error_rec IS RECORD(mass_addition_id NUMBER
4935 ,exception_code VARCHAR2(10)
4936 );
4937 TYPE l_msg_error_tbl IS TABLE OF l_msg_error_rec INDEX BY BINARY_INTEGER;
4938
4939 l_error_msg l_msg_error_tbl;
4940
4941 l_count number := 1;
4942 l_nbv number := 0;
4943 l_exception_code varchar2(100);
4944 l_calling_fn varchar2(50) := 'fa_asset_val_pvt.validate_JP_250_DB';
4945 validate_ex exception;
4946
4947 l_rates_info_rec lcu_rates_info%rowtype;
4948
4949 BEGIN
4950
4951 l_exception_code := null;
4952
4953 if (p_log_level_rec.statement_level) then
4954 fa_debug_pkg.add(p_calling_fn,
4955 'performing','JP 250 DB validation', p_log_level_rec => p_log_level_rec);
4956 end if;
4957
4958 -- bug7668308:Added ytd, in order to calculate correct NBV.
4959 l_nbv := NVL(p_cost,0) - (NVL(p_deprn_reserve,0) - NVL(p_ytd_deprn,0));
4960
4961
4962
4963
4964
4965 open lcu_rates_info(p_deprn_method_code);
4966 fetch lcu_rates_info into l_rates_info_rec;
4967
4968 -- Bug:7668308:Added trunc to calculate correct rate in use.
4969 if (trunc(NVL(p_cost,0) * l_rates_info_rec.guarantee_rate)) > (trunc(l_nbv*l_rates_info_rec.original_rate)) then
4970
4971 if p_nbv_at_switch is null then
4972 fa_srvr_msg.add_message(
4973 CALLING_FN => l_calling_fn,
4974 NAME => 'FA_JP_NBV_NULL'
4975 , p_log_level_rec => p_log_level_rec);
4976 return FALSE;
4977 end if;
4978 if p_nbv_at_switch < 0 then
4979 fa_srvr_msg.add_message(
4980 CALLING_FN => l_calling_fn,
4981 NAME => 'FA_JP_NBV_NEGATIVE'
4982 , p_log_level_rec => p_log_level_rec);
4983 return FALSE;
4984 end if;
4985 if p_nbv_at_switch > NVL(p_cost,0) then
4986 fa_srvr_msg.add_message(
4987 CALLING_FN => l_calling_fn,
4988 NAME => 'FA_JP_NBV_GREATER_COST'
4989 , p_log_level_rec => p_log_level_rec);
4990 return FALSE;
4991 end if;
4992
4993 end if;
4994 close lcu_rates_info;
4995
4996
4997 return TRUE;
4998 exception
4999 WHEN OTHERS THEN
5000 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn, p_log_level_rec => p_log_level_rec);
5001 return false;
5002
5003
5004 END validate_JP_250_DB;
5005 --Bug#7698030 End
5006
5007 --Bug 7260056 Negative transfer amount allowed based on depreciate_option
5008 FUNCTION validate_reserve_transfer (
5009 p_book_type_code IN VARCHAR2 DEFAULT NULL,
5010 p_asset_id IN NUMBER DEFAULT NULL,
5011 p_transfer_amount IN NUMBER DEFAULT 0,
5012 p_calling_fn IN VARCHAR2,
5013 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
5014
5015 cursor c_get_books_info(c_asset_id number,
5016 c_book_type_code varchar2) IS
5017 select over_depreciate_option
5018 from fa_books
5019 where asset_id = c_asset_id
5020 and book_type_code = c_book_type_code
5021 and transaction_header_id_out is null;
5022
5023 l_over_depreciate_option varchar2(30);
5024
5025 BEGIN
5026
5027 if (p_transfer_amount is not null) then
5028 OPEN c_get_books_info(p_asset_id,p_book_type_code);
5029 FETCH c_get_books_info INTO l_over_depreciate_option;
5030 CLOSE c_get_books_info;
5031
5032 if (p_transfer_amount = 0) then
5033 fa_srvr_msg.add_message(
5034 calling_fn => p_calling_fn,
5035 name => 'FA_ZERO_RESERVE_TRANSFER_AMOUNT', p_log_level_rec => p_log_level_rec);
5036 return FALSE;
5037 elsif ( p_transfer_amount < 0 ) and
5038 (l_over_depreciate_option = 'NO' or l_over_depreciate_option is NULL ) then
5039 fa_srvr_msg.add_message(
5040 calling_fn => p_calling_fn,
5041 name => 'FA_NEGATIVE_RESERVE_TRANSFER_AMOUNT_NOT_ALLOWED', p_log_level_rec => p_log_level_rec);
5042 return FALSE;
5043 end if;
5044
5045 end if; -- transfer_amount
5046
5047 return true;
5048
5049 EXCEPTION
5050 WHEN OTHERS THEN
5051 if (p_log_level_rec.statement_level) then
5052 fa_debug_pkg.add(p_calling_fn, 'p_asset_id', p_asset_id, p_log_level_rec => p_log_level_rec);
5053 fa_debug_pkg.add(p_calling_fn, 'p_book_type_code', p_book_type_code, p_log_level_rec => p_log_level_rec);
5054 fa_debug_pkg.add(p_calling_fn, 'EXCEPTION: OTHERS', sqlerrm, p_log_level_rec => p_log_level_rec);
5055 end if;
5056
5057 fa_srvr_msg.add_sql_error(calling_fn => p_calling_fn, p_log_level_rec => p_log_level_rec);
5058 return FALSE;
5059 END validate_reserve_transfer;
5060
5061 /* Bug#7693266- To validate change of salvage_type or deprn_limit_type of group asset */
5062 FUNCTION validate_sal_deprn_sum (
5063 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
5064 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
5065 p_asset_fin_rec_adj IN FA_API_TYPES.asset_fin_rec_type,
5066 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
5067
5068 CURSOR c_mem_exists IS
5069 select 1
5070 from fa_books
5071 where group_asset_id = p_asset_hdr_rec.asset_id
5072 and book_type_code = p_asset_hdr_rec.book_type_code
5073 and transaction_header_id_out is null;
5074
5075 l_calling_fn varchar2(50) := 'FA_ASSET_VAL_PVT.validate_sal_deprn_sum';
5076 l_dummy NUMBER;
5077 l_valid_parameter BOOLEAN := TRUE;
5078
5079 BEGIN
5080 /* Checking for salvage_type and deprn_limit_type changed to SUM for group asset with member */
5081 if (((p_asset_fin_rec_adj.salvage_type = 'SUM') and
5082 (p_asset_fin_rec_adj.salvage_type <> nvl(p_asset_fin_rec_old.salvage_type,
5083 p_asset_fin_rec_adj.salvage_type))) or
5084 ((p_asset_fin_rec_adj.deprn_limit_type = 'SUM') and
5085 (p_asset_fin_rec_adj.deprn_limit_type <> nvl(p_asset_fin_rec_old.deprn_limit_type,
5086 p_asset_fin_rec_adj.deprn_limit_type)))) then
5087
5088 if (p_asset_fin_rec_adj.cost = 0) then
5089 OPEN c_mem_exists;
5090 FETCH c_mem_exists INTO l_dummy;
5091 CLOSE c_mem_exists;
5092 if (l_dummy > 0) then
5093 fa_srvr_msg.add_message(
5094 calling_fn => l_calling_fn,
5095 name =>'FA_MEMBER_EXIST_IN_GROUP');
5096 l_valid_parameter := FALSE;
5097 else
5098 return TRUE;
5099 end if;
5100 else
5101 l_valid_parameter := FALSE;
5102 end if;
5103 if (not l_valid_parameter) then
5104 if (p_asset_fin_rec_adj.salvage_type = 'SUM') then
5105 fa_srvr_msg.add_message(
5106 calling_fn => l_calling_fn,
5107 name => 'FA_INVALID_PARAMETER',
5108 token1 => 'VALUE',
5109 value1 => p_asset_fin_rec_adj.salvage_type,
5110 token2 => 'PARAM',
5111 value2 => 'SALVAGE_TYPE',
5112 p_log_level_rec => p_log_level_rec);
5113 else
5114 fa_srvr_msg.add_message(
5115 calling_fn => l_calling_fn,
5116 name => 'FA_INVALID_PARAMETER',
5117 token1 => 'VALUE',
5118 value1 => p_asset_fin_rec_adj.deprn_limit_type,
5119 token2 => 'PARAM',
5120 value2 => 'DEPRN_LIMIT_TYPE',
5121 p_log_level_rec => p_log_level_rec);
5122 end if;
5123 return FALSE;
5124 end if;
5125 end if; -- End of SUM loop
5126
5127 if (p_log_level_rec.statement_level) then
5128 fa_debug_pkg.add(l_calling_fn, 'End', ' ');
5129 end if;
5130
5131 return TRUE;
5132
5133 EXCEPTION
5134 WHEN OTHERS THEN
5135 if (p_log_level_rec.statement_level) then
5136 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id);
5137 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.salvage_type', p_asset_fin_rec_adj.salvage_type);
5138 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_adj.deprn_limit_type',
5139 p_asset_fin_rec_adj.deprn_limit_type);
5140 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm);
5141 end if;
5142 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn );
5143 return FALSE;
5144
5145 END validate_sal_deprn_sum;
5146
5147 FUNCTION validate_impairment_exists
5148 (p_asset_id IN number,
5149 p_book IN varchar2,
5150 p_mrc_sob_type_code IN varchar2,
5151 p_set_of_books_id IN number,
5152 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
5153
5154 l_check_imp_flag varchar(15);
5155 l_period_rec FA_API_TYPES.period_rec_type;
5156
5157 CURSOR c_mc_check_imp is
5158 select 'POSTED'
5159 from fa_mc_impairments
5160 where status = 'POSTED'
5161 and (asset_id = p_asset_id or cash_generating_unit_id = (select cash_generating_unit_id
5162 from fa_mc_books bk
5163 where bk.asset_id = p_asset_id
5164 and bk.book_type_code = p_book
5165 and bk.date_ineffective is null))
5166 and book_type_code = p_book
5167 AND PERIOD_COUNTER_IMPAIRED = l_period_rec.period_counter
5168 AND set_of_books_id = p_set_of_books_id;
5169
5170 CURSOR c_check_imp is
5171 select 'POSTED'
5172 from fa_impairments
5173 where status = 'POSTED'
5174 and (asset_id = p_asset_id or cash_generating_unit_id = (select cash_generating_unit_id
5175 from fa_books bk
5176 where bk.asset_id = p_asset_id
5177 and bk.book_type_code = p_book
5178 and bk.date_ineffective is null))
5179 and book_type_code = p_book
5180 AND PERIOD_COUNTER_IMPAIRED = l_period_rec.period_counter;
5181
5182 BEGIN
5183 if (NOT FA_UTIL_PVT.get_period_rec (
5184 p_book => p_book,
5185 p_effective_date => NULL,
5186 x_period_rec => l_period_rec,
5187 p_log_level_rec => p_log_level_rec -- Bug:5475024
5188 )) then
5189 return false;
5190 end if;
5191
5192 if (p_mrc_sob_type_code = 'R') then
5193 OPEN c_mc_check_imp;
5194 FETCH c_check_imp INTO l_check_imp_flag;
5195 CLOSE c_check_imp;
5196 else
5197 OPEN c_check_imp;
5198 FETCH c_check_imp INTO l_check_imp_flag;
5199 CLOSE c_check_imp;
5200 end if;
5201 if nvl(l_check_imp_flag,'NOTPOSTED') = 'POSTED' then
5202 fa_srvr_msg.add_message(calling_fn => 'FA_CHK_BOOKSTS_PKG.faxcbsx',
5203 name => 'FA_IMPAIR_ROLLBACK_TRX',
5204 token1 => 'FA_ASSET_ID',
5205 value1 => to_char(p_asset_id),
5206 p_log_level_rec => p_log_level_rec);
5207 return false;
5208 end if;
5209 /*Bug#8436466 */
5210 update fa_impairments
5211 set status = 'NEW'
5212 where status = 'PREVIEWED'
5213 and (asset_id = p_asset_id
5214 or cash_generating_unit_id = (select cash_generating_unit_id
5215 from fa_books bk
5216 where bk.asset_id = p_asset_id
5217 and bk.book_type_code = p_book
5218 and bk.date_ineffective is null))
5219 and book_type_code = p_book
5220 and period_counter_impaired = l_period_rec.period_counter;
5221
5222 delete from fa_mc_impairments
5223 where status = 'PREVIEWED'
5224 and (asset_id = p_asset_id
5225 or cash_generating_unit_id = (select cash_generating_unit_id
5226 from fa_books bk
5227 where bk.asset_id = p_asset_id
5228 and bk.book_type_code = p_book
5229 and bk.date_ineffective is null))
5230 and book_type_code = p_book
5231 and period_counter_impaired = l_period_rec.period_counter;
5232 return true;
5233 end validate_impairment_exists;
5234
5235
5236 /*Bug# 8527619 This function is called from public APIs to check if group will become over depreciate
5237 NBV should not have sign different than cost, when over_depreciation_option is set to NO*/
5238 FUNCTION validate_over_depreciation (
5239 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
5240 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type default null,
5241 p_validation_type IN varchar2,
5242 p_cost_adj IN number,
5243 p_rsv_adj IN number,
5244 p_mrc_sob_type_code IN varchar2 default 'P',
5245 p_asset_retire_rec IN FA_API_TYPES.asset_retire_rec_type default null,
5246 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null
5247 ) RETURN BOOLEAN IS
5248
5249 l_calling_fn varchar2(50) := 'FA_ASSET_VAL_PVT.validate_over_depreciation';
5250 l_deprn_reserve number :=0;
5251 l_deprn_reserve_mem number := 0;
5252 l_ytd_deprn number;
5253 dummy_num number;
5254 dummy_char varchar2(10);
5255 dummy_bool boolean;l_over_drpn_opt varchar2(3);
5256 l_new_group_cost number := 0;
5257 l_new_group_reserve number := 0;
5258 l_new_mem_cost number := 0;
5259 l_new_mem_reserve number := 0;
5260 l_group_cost number := 0;
5261
5262 l_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type;
5263 l_asset_hdr_rec_mem FA_API_TYPES.asset_hdr_rec_type;
5264 l_asset_fin_rec_grp FA_API_TYPES.asset_fin_rec_type;
5265 l_asset_fin_rec_mem FA_API_TYPES.asset_fin_rec_type;
5266 l_mem_asset_deprn_rec fa_api_types.asset_deprn_rec_type;
5267 l_grp_asset_deprn_rec fa_api_types.asset_deprn_rec_type;
5268 l_mem_salvage_val number := 0;
5269 add_err1 exception;
5270
5271 CURSOR c_get_currency_code IS
5272 select currency_code
5273 from gl_sets_of_books sob
5274 where sob.set_of_books_id = p_asset_hdr_rec.set_of_books_id;
5275 l_currency_code varchar2(15) := '';
5276
5277 BEGIN
5278 if p_log_level_rec.statement_level then
5279 fa_debug_pkg.add(l_calling_fn, 'validate_over_depreciation', 'BEGINS', p_log_level_rec);
5280 fa_debug_pkg.add(l_calling_fn, 'p_validation_type', p_validation_type, p_log_level_rec);
5281 fa_debug_pkg.add(l_calling_fn, 'p_cost_adj', p_cost_adj, p_log_level_rec);
5282 fa_debug_pkg.add(l_calling_fn, 'p_rsv_adj', p_rsv_adj, p_log_level_rec);
5283 end if;
5284
5285 l_asset_hdr_rec := p_asset_hdr_rec;
5286 l_asset_hdr_rec_mem := p_asset_hdr_rec;
5287 if p_validation_type <> 'RECLASS_DEST' then /*passing header for group only */
5288 l_asset_hdr_rec.asset_id := p_asset_fin_rec.group_asset_id ;
5289 end if;
5290 l_asset_fin_rec_mem := p_asset_fin_rec;
5291
5292 --Fetch group record.
5293 if not FA_UTIL_PVT.get_asset_fin_rec
5294 (p_asset_hdr_rec => l_asset_hdr_rec,
5295 px_asset_fin_rec => l_asset_fin_rec_grp,
5296 p_transaction_header_id => NULL,
5297 p_mrc_sob_type_code => p_mrc_sob_type_code,
5298 p_log_level_rec => p_log_level_rec) then
5299 if (p_log_level_rec.statement_level) then
5300 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling get_asset_fin_rec',
5301 p_log_level_rec => p_log_level_rec);
5302 end if;
5303 raise add_err1;
5304 end if;
5305
5306 --Initialize cache
5307 if not fa_cache_pkg.fazccmt
5308 (X_method => l_asset_fin_rec_grp.deprn_method_code,
5309 X_life => l_asset_fin_rec_grp.life_in_months) then
5310 if (p_log_level_rec.statement_level) then
5311 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling fazccmt',
5312 p_log_level_rec => p_log_level_rec);
5313 end if;
5314 raise add_err1;
5315 end if;
5316
5317 /*Need to do following validation only for
5318 -energy (UOP/STL) group
5319 -Over Depreciation - Do not Allow
5320 -tracking method - Allocate /
5321 - CALCULATE and not sumup.*/
5322
5323 if ( fa_cache_pkg.fazccmt_record.rate_source_rule = 'PRODUCTION' ) and
5324 (p_asset_fin_rec.group_Asset_id is not null OR p_validation_type = 'RECLASS_DEST' ) and
5325 (l_asset_fin_rec_grp.tracking_method = ('ALLOCATE') OR
5326 (l_asset_fin_rec_grp.tracking_method = 'CALCULATE' and
5327 nvl(l_asset_fin_rec_grp.member_rollup_flag, 'N') = 'N')) and
5328 (l_asset_fin_rec_grp.over_depreciate_option = fa_std_types.FA_OVER_DEPR_NO ) then
5329
5330 if p_log_level_rec.statement_level then
5331 fa_debug_pkg.add(l_calling_fn, 'Inside IF', 'Need to validate', p_log_level_rec);
5332 end if;
5333
5334 if not FA_UTIL_PVT.get_asset_deprn_rec
5335 (p_asset_hdr_rec => l_asset_hdr_rec,
5336 px_asset_deprn_rec => l_grp_asset_deprn_rec,
5337 p_period_counter => NULL,
5338 p_mrc_sob_type_code => p_mrc_sob_type_code,
5339 p_log_level_rec => p_log_level_rec
5340 ) then
5341 if (p_log_level_rec.statement_level) then
5342 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling get_asset_deprn_rec',
5343 p_log_level_rec => p_log_level_rec);
5344 end if;
5345 raise add_err1;
5346 end if;
5347
5348 if p_log_level_rec.statement_level then
5349 fa_debug_pkg.add(l_calling_fn, 'group id:reserve:', l_asset_hdr_rec.asset_id || ' : ' || l_grp_asset_deprn_rec.deprn_reserve, p_log_level_rec);
5350 end if;
5351 if p_validation_type = 'RETIREMENT' then
5352 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) - nvl(p_cost_adj,0);
5353 /*if last member reserve will be cleared by terminal gain/loss */
5354 if l_asset_fin_rec_grp.cost <> p_asset_fin_rec.cost then
5355 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) - nvl(p_rsv_adj,0);
5356 end if;
5357
5358 elsif p_validation_type = 'ADDITION' then
5359 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) + nvl(p_cost_adj,0);
5360 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) + nvl(l_deprn_reserve_mem,0);
5361
5362 elsif p_validation_type = 'ADJUSTMENT' then
5363
5364 if not FA_UTIL_PVT.get_asset_fin_rec
5365 (p_asset_hdr_rec => l_asset_hdr_rec_mem,
5366 px_asset_fin_rec => l_asset_fin_rec_mem,
5367 p_transaction_header_id => NULL,
5368 p_mrc_sob_type_code => p_mrc_sob_type_code,
5369 p_log_level_rec => p_log_level_rec) then
5370 if (p_log_level_rec.statement_level) then
5371 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling get_asset_fin_rec',
5372 p_log_level_rec => p_log_level_rec);
5373 end if;
5374 raise add_err1;
5375 end if;
5376
5377 if not FA_UTIL_PVT.get_asset_deprn_rec
5378 (p_asset_hdr_rec => l_asset_hdr_rec_mem,
5379 px_asset_deprn_rec => l_mem_asset_deprn_rec,
5380 p_period_counter => NULL,
5381 p_mrc_sob_type_code => p_mrc_sob_type_code,
5382 p_log_level_rec => p_log_level_rec
5383 ) then
5384 if (p_log_level_rec.statement_level) then
5385 fa_debug_pkg.add(l_calling_fn, 'ERROR', 'Calling get_asset_deprn_rec',
5386 p_log_level_rec => p_log_level_rec);
5387 end if;
5388 raise add_err1;
5389 end if;
5390 if p_log_level_rec.statement_level then
5391 fa_debug_pkg.add(l_calling_fn, 'Member asset id:cost:reserve:', l_asset_hdr_rec_mem.asset_id || ' : ' || l_asset_fin_rec_mem.cost || ' : ' || l_mem_asset_deprn_rec.deprn_reserve, p_log_level_rec);
5392 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id, p_log_level_rec);
5393 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.group_asset_id', p_asset_fin_rec.group_asset_id, p_log_level_rec);
5394 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec_mem.group_asset_id', l_asset_fin_rec_mem.group_asset_id, p_log_level_rec);
5395 end if;
5396 /*Bug 8754829 -start*/
5397 if (p_cost_adj = 0 AND
5398 nvl(p_asset_fin_rec.group_asset_id,-99) <> nvl(l_asset_fin_rec_mem.group_asset_id,-99)
5399 ) then
5400 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) + nvl(l_asset_fin_rec_mem.cost,0);
5401 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) + nvl(l_mem_asset_deprn_rec.deprn_reserve,0);
5402 else
5403 l_new_mem_cost := nvl(p_cost_adj,0) + nvl(l_asset_fin_rec_mem.cost,0);
5404 l_new_mem_reserve := nvl(l_mem_asset_deprn_rec.deprn_reserve,0);
5405 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) + nvl(p_cost_adj,0);
5406 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0);
5407
5408 if l_asset_fin_rec_mem.SALVAGE_TYPE = 'AMT' then
5409 l_mem_salvage_val := l_asset_fin_rec_mem.salvage_value;
5410 else
5411 l_mem_salvage_val := l_new_mem_cost*l_asset_fin_rec_mem.percent_salvage_value;
5412 if not FA_UTILS_PKG.faxrnd(l_mem_salvage_val,
5413 l_asset_hdr_rec_mem.book_type_code,
5414 l_asset_hdr_rec_mem.set_of_books_id) then
5415 raise add_err1;
5416 end if;
5417 end if;
5418 l_new_mem_cost := l_new_mem_cost - nvl(l_mem_salvage_val,0);
5419 if p_log_level_rec.statement_level then
5420 fa_debug_pkg.add(l_calling_fn, 'Before member over deprn', ' ', p_log_level_rec);
5421 fa_debug_pkg.add(l_calling_fn, 'l_new_mem_cost', l_new_mem_cost, p_log_level_rec);
5422 fa_debug_pkg.add(l_calling_fn, 'l_mem_salvage_val', l_mem_salvage_val, p_log_level_rec);
5423 fa_debug_pkg.add(l_calling_fn, 'l_new_mem_reserve', l_new_mem_reserve, p_log_level_rec);
5424 end if;
5425
5426
5427 if (l_new_mem_cost = 0 and l_new_mem_reserve <> 0) OR
5428 (l_new_mem_cost > l_new_mem_reserve and l_new_mem_cost < 0 ) OR
5429 (l_new_mem_cost < l_new_mem_reserve and l_new_mem_cost > 0 ) then
5430
5431 open c_get_currency_code;
5432 fetch c_get_currency_code into l_currency_code;
5433 close c_get_currency_code;
5434 fa_srvr_msg.add_message(calling_fn => l_calling_fn
5435 ,name => 'FA_NOT_VALID_MEM_TRANSACTION'
5436 ,token1 => 'ASSET_NUMBER',
5437 value1 => l_asset_hdr_rec_mem.asset_id
5438 ,token2 => 'CURRENCY_CODE',
5439 value2 => l_currency_code
5440 ,p_log_level_rec => p_log_level_rec);
5441 return false;
5442 end if;
5443 -- Set back to original value as it has to be recomputed
5444 l_new_mem_cost := l_new_mem_cost + nvl(l_mem_salvage_val,0);
5445 end if;
5446 /*Bug 8754829 -end*/
5447 elsif p_validation_type = 'REINSTATEMENT' then
5448
5449 if p_asset_retire_rec.recognize_gain_loss = 'NO' then
5450 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) + nvl(p_asset_retire_rec.cost_retired,0);
5451 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) + nvl(p_asset_retire_rec.cost_retired,0);
5452 elsif p_asset_retire_rec.recognize_gain_loss = 'YES' then
5453 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) + nvl(p_asset_retire_rec.cost_retired,0);
5454 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) + nvl(p_asset_retire_rec.reserve_retired,0);
5455 END IF;
5456 elsif p_validation_type = 'RECLASS_SOURCE' then
5457 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) - nvl(p_cost_adj,0);
5458 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) - nvl(p_rsv_adj,0);
5459 elsif p_validation_type = 'RECLASS_DEST' then
5460 l_new_group_cost := nvl(l_asset_fin_rec_grp.cost,0) + nvl(p_cost_adj,0);
5461 l_new_group_reserve := nvl(l_grp_asset_deprn_rec.deprn_reserve,0) + nvl(p_rsv_adj,0);
5462 end if;
5463
5464 if p_log_level_rec.statement_level then
5465 fa_debug_pkg.add(l_calling_fn, 'validate_over_depreciation l_new_group_cost', l_new_group_cost, p_log_level_rec);
5466 fa_debug_pkg.add(l_calling_fn, 'validate_over_depreciation l_new_group_reserve', l_new_group_reserve, p_log_level_rec);
5467 end if;
5468
5469 if (l_new_group_cost = 0 and l_new_group_reserve <> 0) OR
5470 (l_new_group_cost > l_new_group_reserve and l_new_group_cost < 0 ) OR
5471 (l_new_group_cost < l_new_group_reserve and l_new_group_cost > 0 ) then
5472 open c_get_currency_code;
5473 fetch c_get_currency_code into l_currency_code;
5474 close c_get_currency_code;
5475 fa_srvr_msg.add_message(calling_fn => l_calling_fn
5476 ,name => 'FA_NOT_VALID_TRANSACTION'
5477 ,token1 => 'ASSET_NUMBER',
5478 value1 => l_asset_hdr_rec.asset_id
5479 ,token2 => 'CURRENCY_CODE',
5480 value2 => l_currency_code
5481 ,p_log_level_rec => p_log_level_rec);
5482 return false;
5483 end if;
5484 end if;
5485 return TRUE;
5486
5487 EXCEPTION
5488 WHEN add_err1 then
5489 if (p_log_level_rec.statement_level) then
5490 fa_debug_pkg.add(l_calling_fn, 'ERROR executing ',l_calling_fn,p_log_level_rec);
5491 fa_debug_pkg.add(l_calling_fn, 'Asset id :',l_asset_hdr_rec_mem.asset_id,p_log_level_rec);
5492 fa_debug_pkg.add(l_calling_fn, 'Book type code :',p_asset_hdr_rec.book_type_Code,p_log_level_rec);
5493 end if;
5494 return false;
5495 WHEN OTHERS THEN
5496 if (p_log_level_rec.statement_level) then
5497 fa_debug_pkg.add(l_calling_fn, 'EXCEPTION: OTHERS', sqlerrm);
5498 end if;
5499 fa_srvr_msg.add_sql_error( calling_fn => l_calling_fn );
5500 return FALSE;
5501 END validate_over_depreciation;
5502
5503 FUNCTION validate_grp_track_method(
5504 p_asset_fin_rec_old IN fa_api_types.asset_fin_rec_type,
5505 p_asset_fin_rec_new IN fa_api_types.asset_fin_rec_type,
5506 p_group_reclass_options_rec IN fa_api_types.group_reclass_options_rec_type,
5507 p_log_level_rec IN fa_api_types.log_level_rec_type DEFAULT NULL) RETURN BOOLEAN IS
5508
5509 BEGIN
5510
5511 IF (NVL(p_asset_fin_rec_old.group_asset_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) AND
5512 (NVL(p_asset_fin_rec_new.group_asset_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) THEN
5513 IF NVL(p_asset_fin_rec_old.tracking_method, FND_API.G_MISS_CHAR) <>
5514 NVL(p_asset_fin_rec_new.tracking_method, FND_API.G_MISS_CHAR) AND
5515 (p_group_reclass_options_rec.group_reclass_type = 'CALC') THEN
5516 FA_SRVR_MSG.ADD_MESSAGE(CALLING_FN => 'FA_ASSET_VAL_PVT.validate_grp_track_method',
5517 NAME => 'FA_GRP_RCL_TRACK_MISMATCH',
5518 TOKEN1 => 'EXISTING_TRACK_METHOD',
5519 VALUE1 => p_asset_fin_rec_old.tracking_method,
5520 p_log_level_rec => p_log_level_rec);
5521 RETURN FALSE;
5522 ELSE
5523 RETURN TRUE;
5524 END IF;
5525 END IF;
5526
5527 RETURN TRUE;
5528
5529 END validate_grp_track_method;
5530
5531 /* Bug#8584206-To validate type of transactions allowed on Energy UOP assets */
5532 FUNCTION validate_energy_transactions (
5533 p_trans_rec IN FA_API_TYPES.trans_rec_type,
5534 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type default null,
5535 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type default null,
5536 p_asset_fin_rec_adj IN FA_API_TYPES.asset_fin_rec_type default null,
5537 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
5538 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
5539
5540 l_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
5541 l_asset_type_rec FA_API_TYPES.asset_type_rec_type;
5542 l_group_asset_fin_rec FA_API_TYPES.asset_fin_rec_type;
5543 l_group_asset_hdr_rec FA_API_TYPES.asset_hdr_rec_type;
5544 h_asset_id number;
5545
5546 CURSOR c_group_mem_no_depreciate is
5547 select count(1) from dual
5548 where exists
5549 (select 'x' from fa_books
5550 where book_type_code = p_asset_hdr_rec.book_type_code
5551 and group_asset_id = h_asset_id
5552 and transaction_header_id_out is null
5553 and depreciate_flag = 'NO');
5554 l_dummy_num number;
5555
5556 CURSOR c_asset_with_reserve is
5557 select count(1) from dual
5558 where exists
5559 (select 'x' from fa_deprn_summary
5560 where book_type_code = p_asset_hdr_rec.book_type_code
5561 and asset_id = p_asset_hdr_rec.asset_id
5562 and deprn_source_code = 'BOOKS'
5563 and deprn_reserve > 0);
5564 l_dummy_num_rsv number;
5565
5566 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.validate_egy_trans';
5567 val_err exception;
5568
5569 BEGIN
5570 if (p_log_level_rec.statement_level) then
5571 fa_debug_pkg.add(l_calling_fn, 'begin', '', p_log_level_rec);
5572 end if;
5573
5574 l_asset_fin_rec := p_asset_fin_rec_old;
5575 l_asset_type_rec := p_asset_type_rec;
5576
5577 -- First load asset type cache it is null
5578 IF l_asset_type_rec.asset_type is NULL Then
5579 if not FA_UTIL_PVT.get_asset_type_rec(p_asset_hdr_rec => p_asset_hdr_rec,
5580 px_asset_type_rec => l_asset_type_rec,
5581 p_date_effective => NULL,
5582 p_log_level_rec => p_log_level_rec) then
5583 raise val_err;
5584 end if;
5585
5586 IF (p_log_level_rec.statement_level) then
5587 fa_debug_pkg.add(l_calling_fn, 'loaded asset type cache', '', p_log_level_rec);
5588 END IF;
5589 END IF;
5590
5591 -- Next load finrec in case of it is null
5592 IF l_asset_fin_rec.cost is NULL Then
5593 if p_log_level_rec.statement_level then
5594 fa_debug_pkg.add(l_calling_fn, 'asset_fin_rec is NULL', '', p_log_level_rec);
5595 end if;
5596
5597 IF not FA_UTIL_PVT.get_asset_fin_rec(p_asset_hdr_rec => p_asset_hdr_rec,
5598 px_asset_fin_rec => l_asset_fin_rec,
5599 p_transaction_header_id => NULL,
5600 p_mrc_sob_type_code => 'P',
5601 p_log_level_rec => p_log_level_rec) then
5602 raise val_err;
5603 END IF;
5604
5605 IF (p_log_level_rec.statement_level) then
5606 fa_debug_pkg.add(l_calling_fn, 'loaded finreec cache', '', p_log_level_rec);
5607 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec.cost', l_asset_fin_rec.cost, p_log_level_rec);
5608 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec.group_asset_id',
5609 nvl(l_asset_fin_rec.group_asset_id,-100), p_log_level_rec);
5610 fa_debug_pkg.add(l_calling_fn, 'l_asset_fin_rec.depreciate_flag',
5611 l_asset_fin_rec.depreciate_flag, p_log_level_rec);
5612 fa_debug_pkg.add(l_calling_fn, 'complete finreec cache', '', p_log_level_rec);
5613 END IF;
5614 END IF;
5615
5616 --Load method cache
5617 if (not fa_cache_pkg.fazccmt(l_asset_fin_rec.deprn_method_code,
5618 l_asset_fin_rec.life_in_months,
5619 p_log_level_rec => p_log_level_rec)) then
5620 if (p_log_level_rec.statement_level) then
5621 fa_debug_pkg.add(l_calling_fn, 'Error calling', 'fa_cache_pkg.fazccmt', p_log_level_rec);
5622 end if;
5623
5624 raise val_err;
5625 end if;
5626
5627 IF (p_log_level_rec.statement_level) then
5628 fa_debug_pkg.add(l_calling_fn, 'loaded method cache : source_rule',
5629 fa_cache_pkg.fazccmt_record.rate_source_rule, p_log_level_rec);
5630 END IF;
5631
5632 IF fa_cache_pkg.fazccmt_record.rate_source_rule = 'PRODUCTION' THEN
5633 IF l_asset_type_rec.asset_type = 'CAPITALIZED' THEN
5634 -- During reclass into group, Group should have tracking method of ALLOCATE if asset is added with reserve.
5635 IF (nvl(l_asset_fin_rec.group_asset_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM and
5636 nvl(p_asset_fin_rec_adj.group_asset_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM ) THEN -- reclass case
5637 open c_asset_with_reserve;
5638 fetch c_asset_with_reserve into l_dummy_num_rsv;
5639 close c_asset_with_reserve;
5640
5641 IF l_dummy_num_rsv = 1 THEN
5642 l_group_asset_hdr_rec.asset_id := p_asset_fin_rec_adj.group_asset_id;
5643 l_group_asset_hdr_rec.book_type_code := p_asset_hdr_rec.book_type_code;
5644
5645 IF not FA_UTIL_PVT.get_asset_fin_rec(p_asset_hdr_rec => l_group_asset_hdr_rec,
5646 px_asset_fin_rec => l_group_asset_fin_rec,
5647 p_transaction_header_id => NULL,
5648 p_mrc_sob_type_code => 'P',
5649 p_log_level_rec => p_log_level_rec) then
5650 raise val_err;
5651 END IF;
5652
5653 IF nvl(l_group_asset_fin_rec.tracking_method,'ZZZ') <> 'ALLOCATE' THEN
5654 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5655 name => 'FA_PROD_MEM_NO_ALLOCATE',
5656 p_log_level_rec => p_log_level_rec);
5657 return FALSE;
5658 END IF;
5659 END IF; -- l_dummy_num_rsv = 1
5660 END IF; -- reclass case
5661
5662 -- Asset cannot be reclassed out of group if it was added with reserve when depreciate_flag = YES
5663 /* IF (l_asset_fin_rec.depreciate_flag = 'YES' and
5664 nvl(l_asset_fin_rec.group_asset_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM and
5665 p_asset_fin_rec_adj.group_asset_id = FND_API.G_MISS_NUM ) THEN -- reclass out case
5666
5667 open c_asset_with_reserve;
5668 fetch c_asset_with_reserve into l_dummy_num_rsv;
5669 close c_asset_with_reserve;
5670
5671 IF l_dummy_num_rsv = 1 THEN
5672 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5673 name => 'FA_PROD_MEM_NO_CAP_RESV',
5674 p_log_level_rec => p_log_level_rec);
5675 return FALSE;
5676 END IF;
5677 END IF; -- p_asset_fin_rec.depreciate_flag = 'YES' Commented for ENH 12600386 */
5678
5679 -- Validations when depreciate_flag = 'NO'
5680 IF l_asset_fin_rec.depreciate_flag = 'NO' THEN
5681
5682 -- No transaction allowed on members asset with depreciate_flag = 'NO' except,
5683 -- a) moving out of group b) Setting depreciate_flag = 'YES'
5684 /* IF nvl(l_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN
5685
5686 IF (nvl(p_asset_fin_rec_adj.group_asset_id,-99) <> FND_API.G_MISS_NUM AND Commented for ENH 12600386 */
5687 IF ( nvl(p_asset_fin_rec_adj.depreciate_flag,'NO') <> 'YES' ) THEN /* Added for ENH 12600386 */
5688 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5689 name => 'FA_PROD_MEM_INVALID_TRANS',
5690 p_log_level_rec => p_log_level_rec);
5691 return FALSE;
5692 END IF;
5693 /* ELSE
5694
5695 -- Do not allow to depreciate_flag = YES on standalone asset
5696 -- if it is created with reserve. Other transactions allowed
5697 IF (nvl(p_asset_fin_rec_adj.depreciate_flag,'NO') = 'YES' ) THEN
5698 open c_asset_with_reserve;
5699 fetch c_asset_with_reserve into l_dummy_num_rsv;
5700 close c_asset_with_reserve;
5701
5702 IF l_dummy_num_rsv = 1 THEN
5703 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5704 name => 'FA_PROD_CAP_DEPRN_RESV',
5705 p_log_level_rec => p_log_level_rec);
5706 return FALSE;
5707 END IF;
5708 END IF;
5709 END IF; -- nvl(l_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN Commented for ENH 12600386 */
5710 ELSE
5711 -- Check if member's group has any other members with depreciate_flag = NO. If so, raise error.
5712 -- Allowed transactions for such cases is, setting depreciating flag = NO and group reclass
5713 -- (out or assign to other group)
5714
5715 IF ( nvl(p_asset_fin_rec_adj.depreciate_flag,'YES') = 'YES' and
5716 nvl(l_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM and
5717 nvl(p_asset_fin_rec_adj.group_asset_id,l_asset_fin_rec.group_asset_id) <>
5718 FND_API.G_MISS_NUM and
5719 nvl(p_asset_fin_rec_adj.group_asset_id,l_asset_fin_rec.group_asset_id) =
5720 l_asset_fin_rec.group_asset_id) THEN
5721
5722 h_asset_id := l_asset_fin_rec.group_asset_id;
5723
5724 open c_group_mem_no_depreciate;
5725 fetch c_group_mem_no_depreciate into l_dummy_num;
5726 close c_group_mem_no_depreciate;
5727
5728 IF l_dummy_num = 1 THEN
5729 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5730 name => 'FA_PROD_GRP_NO_DEPR_FLAG',
5731 p_log_level_rec => p_log_level_rec);
5732 return FALSE;
5733 END IF;
5734 END IF;
5735 END IF; --l_asset_fin_rec.depreciate_flag = 'NO'
5736
5737 END IF; --l_asset_type_rec.asset_type = 'CAPITALIZED'
5738
5739 IF l_asset_type_rec.asset_type = 'GROUP' THEN
5740
5741 IF (nvl(p_trans_rec.transaction_key, 'NULL') <> 'GC') THEN
5742
5743 h_asset_id := p_asset_hdr_rec.asset_id;
5744
5745 open c_group_mem_no_depreciate;
5746 fetch c_group_mem_no_depreciate into l_dummy_num;
5747 close c_group_mem_no_depreciate;
5748
5749 IF l_dummy_num = 1 THEN
5750 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5751 name => 'FA_PROD_GRP_NO_DEPR_FLAG',
5752 p_log_level_rec => p_log_level_rec);
5753 return FALSE;
5754 END IF;
5755
5756 END IF;
5757
5758 END IF; --l_asset_type_rec.asset_type = 'GROUP'
5759
5760 END IF; --fa_cache_pkg.fazccmt_record.rate_source_rule = 'PRODUCTION'
5761
5762 return true;
5763
5764 EXCEPTION
5765 WHEN val_err THEN
5766 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5767 name => 'ERROR executing : '|| l_calling_fn,
5768 p_log_level_rec => p_log_level_rec);
5769 return FALSE;
5770
5771 WHEN OTHERS THEN
5772 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn);
5773 return false;
5774
5775 END validate_energy_transactions;
5776
5777 /* Bug#8633654-To validate type of transactions allowed on Energy UOP assets */
5778 FUNCTION validate_mbr_reins_possible (
5779 p_asset_retire_rec IN FA_API_TYPES.asset_retire_rec_type,
5780 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
5781 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
5782
5783 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.validate_mbr_reins_possible';
5784
5785
5786 /* Cursor to get retirement adjustment happened during retirement */
5787 cursor c_ret_adj_amount is
5788 select nvl(sum(decode(debit_credit_flag,'DR',adjustment_amount,-1*adjustment_amount)),0) ret_adj_amount
5789 from fa_transaction_headers th -- member
5790 , fa_transaction_headers gth -- group
5791 , fa_adjustments aj
5792 where th.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5793 and th.source_transaction_header_id = gth.transaction_header_id
5794 and gth.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5795 and gth.member_transaction_header_id = p_asset_retire_rec.detail_info.transaction_header_id_in
5796 and aj.asset_id = th.asset_id
5797 and aj.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5798 and aj.transaction_header_id = th.transaction_header_id;
5799
5800
5801 /* Cursor to get sum of all members adjusted cost */
5802 cursor c_mbr_adjusted_cost is
5803 select nvl(sum(bk.adjusted_cost),0) mbr_sum_adj_cost
5804 from fa_books bk
5805 where bk.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5806 and bk.transaction_header_id_out is null
5807 and bk.group_asset_id = p_asset_fin_rec.group_asset_id;
5808
5809 /* Cursor to get details during retirement, we have to use cursor as retire_rec will not provide salvage details*/
5810 cursor c_ret_mem_details is
5811 select bk.cost,nvl(bk.salvage_value,0)
5812 from fa_books bk
5813 where bk.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5814 and bk.asset_id = p_asset_retire_rec.detail_info.asset_id
5815 and bk.transaction_header_id_out = p_asset_retire_rec.detail_info.transaction_header_id_in;
5816
5817 /* Cursor to get last pending retirment for the group */
5818 cursor c_last_ret_mem_details is
5819 select ad.asset_id, ad.asset_number,
5820 ret.transaction_header_id_in
5821 from fa_retirements ret,
5822 fa_additions_b ad
5823 where ret.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5824 and ad.asset_id = ret.asset_id
5825 and ret.transaction_header_id_in =
5826 (select max(far.transaction_header_id_in)
5827 from fa_retirements far,
5828 fa_books bk
5829 where far.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5830 and far.asset_id = bk.asset_id
5831 and bk.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5832 and bk.group_asset_id = p_asset_fin_rec.group_asset_id
5833 and bk.transaction_header_id_out is null
5834 and far.status = 'PROCESSED');
5835
5836
5837 /* Cursor to get group cost */
5838 cursor c_grp_cost is
5839 select bk.cost
5840 from fa_books bk
5841 where bk.book_type_code = p_asset_retire_rec.detail_info.book_type_code
5842 and bk.asset_id = p_asset_fin_rec.group_asset_id
5843 and bk.transaction_header_id_out is null;
5844
5845
5846 l_ret_adj_amount number;
5847 l_mbr_sum_adj_cost number;
5848 l_ret_cost number;
5849 l_ret_salvage_value number;
5850 l_max_ret_adj_reverse number;
5851 l_max_ret_trx_id number;
5852 l_last_asset_id fa_additions_b.asset_id%type;
5853 l_last_asset_num fa_additions_b.asset_number%type;
5854 l_grp_cost fa_books.cost%type;
5855
5856 val_err exception;
5857
5858
5859 BEGIN
5860 IF (p_log_level_rec.statement_level) THEN
5861 fa_debug_pkg.add(l_calling_fn, 'bein', ' ', p_log_level_rec);
5862 fa_debug_pkg.add(l_calling_fn, 'retirement_id : recognize_gain_loss',
5863 p_asset_retire_rec.retirement_id ||':'|| p_asset_retire_rec.recognize_gain_loss,
5864 p_log_level_rec);
5865 END IF;
5866
5867 IF p_asset_retire_rec.recognize_gain_loss = 'YES' THEN
5868 return TRUE;
5869 END IF;
5870
5871 open c_ret_adj_amount;
5872 fetch c_ret_adj_amount into l_ret_adj_amount;
5873 close c_ret_adj_amount;
5874
5875 IF (p_log_level_rec.statement_level) THEN
5876 fa_debug_pkg.add(l_calling_fn, 'l_ret_adj_amount', l_ret_adj_amount, p_log_level_rec);
5877 END IF;
5878
5879 if l_ret_adj_amount = 0 THEN
5880 return TRUE;
5881 end if;
5882
5883
5884 /* check if group cost is zero. That means, this reinstatement is first after retirement */
5885 open c_grp_cost;
5886 fetch c_grp_cost into l_grp_cost;
5887 close c_grp_cost;
5888 IF (p_log_level_rec.statement_level) THEN
5889 fa_debug_pkg.add(l_calling_fn, 'l_grp_cost', l_grp_cost, p_log_level_rec);
5890 END IF;
5891 if (l_grp_cost = 0) then
5892 open c_last_ret_mem_details;
5893 fetch c_last_ret_mem_details into l_last_asset_id,l_last_asset_num,l_max_ret_trx_id;
5894 close c_last_ret_mem_details;
5895 IF (p_log_level_rec.statement_level) THEN
5896 fa_debug_pkg.add(l_calling_fn, 'l_last_asset_id', l_last_asset_id, p_log_level_rec);
5897 fa_debug_pkg.add(l_calling_fn, 'l_last_asset_num', l_last_asset_num, p_log_level_rec);
5898 fa_debug_pkg.add(l_calling_fn, 'l_max_ret_trx_id', l_max_ret_trx_id, p_log_level_rec);
5899 fa_debug_pkg.add(l_calling_fn, 'detail_info.transaction_header_id_in', p_asset_retire_rec.detail_info.transaction_header_id_in,
5900 p_log_level_rec);
5901 END IF;
5902
5903 if nvl(l_max_ret_trx_id,-99) <> p_asset_retire_rec.detail_info.transaction_header_id_in then
5904 fa_srvr_msg.add_message(
5905 calling_fn => l_calling_fn,
5906 name => 'FA_EGY_REINS_LAST_RET',
5907 token1 => 'ASSET_NUMBER',
5908 value1 => l_last_asset_num
5909 );
5910 raise val_err;
5911 end if;
5912
5913 end if;
5914
5915 open c_mbr_adjusted_cost;
5916 fetch c_mbr_adjusted_cost into l_mbr_sum_adj_cost;
5917 close c_mbr_adjusted_cost;
5918
5919 IF (p_log_level_rec.statement_level) THEN
5920 fa_debug_pkg.add(l_calling_fn, 'l_mbr_adjusted_cost', l_mbr_sum_adj_cost,p_log_level_rec);
5921 END IF;
5922
5923 open c_ret_mem_details;
5924 fetch c_ret_mem_details into l_ret_cost, l_ret_salvage_value;
5925 close c_ret_mem_details;
5926
5927 IF (p_log_level_rec.statement_level) THEN
5928 fa_debug_pkg.add(l_calling_fn, 'p_asset_retire_rec.cost_retired', p_asset_retire_rec.cost_retired,p_log_level_rec);
5929 fa_debug_pkg.add(l_calling_fn, 'p_asset_retire_rec.reserve_retired', p_asset_retire_rec.reserve_retired,p_log_level_rec);
5930 fa_debug_pkg.add(l_calling_fn, 'l_ret_salvage_value', l_ret_salvage_value,p_log_level_rec);
5931 END IF;
5932
5933
5934 l_max_ret_adj_reverse := nvl(l_mbr_sum_adj_cost,0) + p_asset_retire_rec.cost_retired -
5935 nvl(p_asset_retire_rec.reserve_retired,0) - nvl(l_ret_salvage_value,0);
5936
5937 IF (p_log_level_rec.statement_level) THEN
5938 fa_debug_pkg.add(l_calling_fn, 'l_max_ret_adj_reverse', l_max_ret_adj_reverse,p_log_level_rec);
5939 END IF;
5940
5941 if l_ret_adj_amount*sign(l_ret_adj_amount) > l_max_ret_adj_reverse*sign(l_max_ret_adj_reverse) then
5942 fa_srvr_msg.add_message(
5943 calling_fn => l_calling_fn,
5944 name => 'FA_EGY_REINS_NOT_POSSIBLE');
5945 raise val_err;
5946 end if;
5947
5948 return TRUE;
5949
5950 EXCEPTION
5951 WHEN val_err THEN
5952 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
5953 name => 'ERROR executing : '|| l_calling_fn,
5954 p_log_level_rec => p_log_level_rec);
5955 return FALSE;
5956
5957 WHEN OTHERS THEN
5958 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn);
5959 return false;
5960
5961 END validate_mbr_reins_possible;
5962
5963 -- Bug 8722521 : Validation for Japan methods during Tax upload
5964 FUNCTION validate_jp_taxupl (
5965 p_trans_rec IN FA_API_TYPES.trans_rec_type,
5966 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
5967 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
5968 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
5969 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type,
5970 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
5971
5972
5973 --Bug# 7608030 start
5974 l_p_rsv_counter number;
5975 l_ext_period_counter number;
5976 l_fiscal_yr number;
5977 l_period_num number;
5978 l_num_fy_yr number;
5979 l_period_end_dt date;
5980 l_current_period_dt date;
5981 l_default_dt date := to_date('01-04-2007','DD-MM-RRRR');
5982 --#Bug 7608030 end
5983
5984 -- Bug 7698030 start open period
5985 cursor l_curr_open_period(p_book_type_code in varchar2
5986 )
5987 is
5988 select fdp.calendar_period_close_date
5989 from fa_book_controls fbc
5990 ,fa_deprn_periods fdp
5991 where fbc.book_type_code = fdp.book_type_code
5992 and fdp.period_counter = fbc.last_period_counter+1
5993 and fbc.book_type_code = p_book_type_code;
5994
5995 --7608030 full reserv counter
5996 cursor l_period_info(p_book_type_code in varchar2
5997 ,p_period in number -- Bug 9131620
5998 )
5999 is
6000 select fcp.end_date
6001 ,ffy.fiscal_year
6002 ,fcp.period_num
6003 ,fct.number_per_fiscal_year
6004 from fa_fiscal_year ffy
6005 ,fa_book_controls fbc
6006 ,fa_calendar_periods fcp
6007 ,fa_calendar_types fct
6008 where ffy.fiscal_year_name = fbc.fiscal_year_name
6009 and ffy.fiscal_year_name = fct.fiscal_year_name
6010 and fbc.book_type_code = p_book_type_code
6011 and fcp.calendar_type = fct.calendar_type
6012 and fct.calendar_type = fbc.deprn_calendar
6013 and fcp.start_date >= ffy.start_date
6014 and fcp.end_date <= ffy.end_date
6015 and (fcp.period_num + (fct.number_per_fiscal_year * ffy.fiscal_year)) = p_period; -- Bug 9131620
6016
6017 --Bug 7698030 end
6018
6019 -- Exceptions
6020
6021 val_error EXCEPTION;
6022 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.validate_jp_taxupl';
6023
6024 Begin
6025
6026 if p_asset_fin_rec.deprn_method_code='JP-STL-EXTND' then
6027 if not fa_asset_val_pvt.validate_JP_STL_EXTND(
6028 p_prior_deprn_method => p_asset_fin_rec.prior_deprn_method,
6029 p_prior_basic_rate => p_asset_fin_rec.prior_basic_rate,
6030 p_prior_adjusted_rate => p_asset_fin_rec.prior_adjusted_rate,
6031 p_prior_life_in_months => p_asset_fin_rec.prior_life_in_months,
6032 p_calling_fn => l_calling_fn,
6033 p_log_level_rec => p_log_level_rec) then
6034
6035 raise val_error;
6036
6037 end if;
6038 -- end validate JP-STL-EXTND
6039 /*For Jp-STL-EXTD we also need to
6040 * validate Erlier depreciation limit,
6041 * Period fully reserved
6042 * Early first period extended depreciation
6043 */
6044
6045 -- start validate_earl_deprn_limit
6046 if not fa_asset_val_pvt.validate_earl_deprn_limit(
6047 p_prior_deprn_limit_amount => p_asset_fin_rec.prior_deprn_limit_amount,
6048 p_prior_deprn_limit => p_asset_fin_rec.prior_deprn_limit,
6049 p_prior_deprn_limit_type => p_asset_fin_rec.prior_deprn_limit_type,
6050 p_calling_fn => l_calling_fn,
6051 p_log_level_rec => p_log_level_rec) then
6052
6053 raise val_error;
6054
6055 end if;
6056 -- end validate_earl_deprn_limit
6057
6058 /*
6059 * For period fully reserv counter
6060 */
6061 l_period_end_dt := null;
6062 l_period_num := null;
6063 l_num_fy_yr := null;
6064 l_p_rsv_counter := null;
6065 open l_period_info(p_asset_hdr_rec.book_type_code
6066 ,p_asset_fin_rec.period_counter_fully_reserved); -- Bug 9131620
6067 fetch l_period_info into l_period_end_dt
6068 ,l_fiscal_yr
6069 ,l_period_num
6070 ,l_num_fy_yr;
6071 close l_period_info;
6072
6073 --Fetching the current open Period
6074 open l_curr_open_period(p_asset_hdr_rec.book_type_code);
6075 fetch l_curr_open_period into l_current_period_dt;
6076 close l_curr_open_period;
6077
6078 if (trunc(l_period_end_dt) < trunc(p_asset_fin_rec.date_placed_in_service)) then
6079 fa_srvr_msg.add_message( CALLING_FN => l_calling_fn,
6080 NAME => 'FA_JP_ENDDATE_EARLY_DPIS'
6081 , p_log_level_rec => p_log_level_rec);
6082 raise val_error;
6083 elsif (trunc(l_period_end_dt) > trunc(l_current_period_dt) ) then
6084 fa_srvr_msg.add_message( CALLING_FN => l_calling_fn,
6085 NAME => 'FA_JP_ENDDATE_GREATER_CUR_DATE'
6086 , p_log_level_rec => p_log_level_rec);
6087 raise val_error;
6088 elsif l_period_end_dt is null then
6089 fa_srvr_msg.add_message(CALLING_FN => l_calling_fn,
6090 NAME => 'FA_JP_PERIOD_ENDDATE_NULL'
6091 , p_log_level_rec => p_log_level_rec);
6092 raise val_error;
6093 else
6094 l_p_rsv_counter := (l_fiscal_yr * l_num_fy_yr) + l_period_num; -- end
6095 end if;
6096
6097 -- start validate_period_fully_reserved
6098 if not fa_asset_val_pvt.validate_period_fully_reserved(
6099 p_book_type_code => p_asset_hdr_rec.book_type_code,
6100 p_pc_fully_reserved => l_p_rsv_counter,
6101 p_date_placed_in_service => p_asset_fin_rec.date_placed_in_service,
6102 p_calling_fn => l_calling_fn,
6103 p_log_level_rec => p_log_level_rec) then
6104
6105 raise val_error;
6106 end if;
6107 -- end validate_period_fully_reserved
6108
6109 -- Start extd deprn period
6110
6111 l_period_end_dt := null;
6112 l_period_num := null;
6113 l_period_end_dt := null;
6114 l_num_fy_yr := null;
6115 l_ext_period_counter := null;
6116 open l_period_info(p_asset_hdr_rec.book_type_code
6117 ,p_asset_fin_rec.extended_depreciation_period); -- Bug 9131620
6118 fetch l_period_info into l_period_end_dt
6119 ,l_fiscal_yr
6120 ,l_period_num
6121 ,l_num_fy_yr;
6122 close l_period_info;
6123
6124 if l_period_end_dt is null then
6125 fa_srvr_msg.add_message(
6126 CALLING_FN => l_calling_fn,
6127 NAME => 'FA_JP_PERIOD_ENDDATE_NULL'
6128 , p_log_level_rec => p_log_level_rec);
6129 raise val_error;
6130 elsif (trunc(l_period_end_dt) < trunc(l_default_dt)) then
6131 fa_srvr_msg.add_message(
6132 CALLING_FN => l_calling_fn,
6133 NAME => 'FA_JP_PERIOD_ENDDATE_WRONG'
6134 , p_log_level_rec => p_log_level_rec);
6135 raise val_error;
6136 elsif (trunc(l_period_end_dt) < trunc(p_asset_fin_rec.date_placed_in_service)) then
6137 fa_srvr_msg.add_message(
6138 CALLING_FN => l_calling_fn,
6139 NAME => 'FA_JP_ENDDATE_EARLY_DPIS'
6140 , p_log_level_rec => p_log_level_rec);
6141 raise val_error;
6142 else
6143 l_ext_period_counter := (l_fiscal_yr * l_num_fy_yr) + l_period_num; -- end
6144 end if;
6145
6146 -- Start validate_fst_prd_extd_deprn
6147 if not fa_asset_val_pvt.validate_fst_prd_extd_deprn(
6148 p_book_type_code => p_asset_hdr_rec.book_type_code,
6149 p_extended_deprn_period => l_ext_period_counter,
6150 p_date_placed_in_service => p_asset_fin_rec.date_placed_in_service,
6151 p_calling_fn => l_calling_fn,
6152 p_log_level_rec => p_log_level_rec) then
6153
6154 raise val_error;
6155
6156 end if;
6157 --- end validate_fst_prd_extd_deprn
6158 end if;
6159 -- End of JP-STL-EXTD method validation
6160
6161 -- Start of Not JP STL EXTD validation
6162 /*if p_asset_fin_rec.deprn_method_code <> 'JP-STL-EXTND' then
6163
6164 -- start validate_NOT_JP_STL_EXTND
6165 if not fa_asset_val_pvt.validate_NOT_JP_STL_EXTND(
6166 p_book_type_code => p_asset_hdr_rec.book_type_code,
6167 p_deprn_limit => l_asset_fin_rec_adj.allowed_deprn_limit,
6168 p_sp_deprn_limit => l_asset_fin_rec_adj.allowed_deprn_limit_amount,
6169 p_deprn_reserve => p_asset_deprn_rec.deprn_reserve,
6170 p_asset_type => l_asset_type(l_loop_count),
6171 p_pc_fully_reserved => l_p_rsv_counter,
6172 p_date_placed_in_service => p_asset_fin_rec.date_placed_in_service,
6173 p_cost => p_asset_fin_rec.cost,
6174 p_mass_addition_id => l_request_id,
6175 p_calling_fn => l_calling_fn,
6176 p_log_level_rec => p_log_level_rec) then
6177
6178 raise val_error;
6179 end if;
6180
6181 end if; */
6182 -- Start of Not JP STL EXTD validation
6183
6184 -- Start Validation for JP 250 DB methods
6185 -- if p_asset_fin_rec.deprn_method_code like 'JP%250DB%' then
6186 -- JP_TAX_2012
6187 if nvl(fa_cache_pkg.fazccmt_record.guarantee_rate_method_flag,'NO') = 'YES' then
6188
6189 if not fa_asset_val_pvt.validate_JP_250_DB(
6190 p_deprn_method_code => p_asset_fin_rec.deprn_method_code,
6191 p_cost => p_asset_fin_rec.cost,
6192 p_nbv_at_switch => p_asset_fin_rec.nbv_at_switch,
6193 p_deprn_reserve => p_asset_deprn_rec.deprn_reserve,
6194 p_ytd_deprn => p_asset_deprn_rec.ytd_deprn,
6195 p_calling_fn => l_calling_fn,
6196 p_log_level_rec => p_log_level_rec) then
6197
6198 raise val_error;
6199 end if;
6200
6201 end if;
6202
6203 return TRUE;
6204
6205 EXCEPTION
6206 WHEN val_error THEN
6207 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6208 name => 'ERROR executing : '|| l_calling_fn);
6209 return FALSE;
6210
6211 WHEN OTHERS THEN
6212 fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn);
6213 return false;
6214
6215 END validate_jp_taxupl;
6216
6217 --Bug 8828394 - Group Asset ID should be valid Group Asset ID
6218 FUNCTION validate_group_asset_id(
6219 p_asset_id IN NUMBER,
6220 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null
6221 ) RETURN BOOLEAN IS
6222
6223 l_count number;
6224
6225 BEGIN
6226 l_count := null;
6227
6228 begin
6229 select 1
6230 into l_count
6231 from dual
6232 where exists (select 'X'
6233 from fa_additions_b
6234 where asset_id = p_asset_id
6235 and asset_type = 'GROUP');
6236 exception
6237 when no_data_found then
6238 l_count := null;
6239 end;
6240
6241 if l_count is null then
6242 fa_srvr_msg.add_message(
6243 calling_fn => 'fa_asset_val_pvt.validate_group_asset_id',
6244 name => 'FA_INV_GROUP_ASSET_ID');
6245 return false;
6246 end if;
6247
6248 return true;
6249 END validate_group_asset_id;
6250
6251 -- Bug 8471701
6252 FUNCTION validate_ltd_deprn_change (
6253 p_book_type_code IN VARCHAR2,
6254 p_asset_Id IN NUMBER,
6255 p_calling_fn IN VARCHAR2,
6256 p_log_level_rec IN FA_API_TYPES.log_level_rec_type
6257 ) RETURN BOOLEAN IS
6258
6259 CURSOR c_check_dist IS
6260 select count(1)
6261 from fa_deprn_detail fdd,
6262 fa_distribution_history fdh
6263 where fdd.distribution_id = fdh.distribution_id
6264 and fdd.book_type_code = p_book_type_code
6265 and fdd.asset_id = p_asset_Id
6266 and fdd.deprn_source_code = 'B'
6267 and fdh.transaction_header_id_out is not null;
6268
6269 l_inactive_dist NUMBER := 0;
6270 BEGIN
6271 -- Check if any of the distributions for B row are inactive.
6272 -- If any, do not allow the reserve change transaction.
6273 OPEN c_check_dist;
6274 FETCH c_check_dist INTO l_inactive_dist;
6275 CLOSE c_check_dist;
6276
6277 if (l_inactive_dist > 0) then
6278 fa_srvr_msg.add_message(
6279 calling_fn => p_calling_fn,
6280 name =>'FA_INVALID_RESERVE_CHANGE',
6281 p_log_level_rec => p_log_level_rec);
6282
6283 return false;
6284 else
6285 return true;
6286 end if;
6287
6288 EXCEPTION
6289 WHEN OTHERS THEN
6290 if (p_log_level_rec.statement_level) then
6291 fa_debug_pkg.add(p_calling_fn, 'p_asset_id', p_asset_id, p_log_level_rec => p_log_level_rec);
6292 fa_debug_pkg.add(p_calling_fn, 'p_book_type_code', p_book_type_code, p_log_level_rec => p_log_level_rec);
6293 fa_debug_pkg.add(p_calling_fn, 'EXCEPTION: OTHERS', sqlerrm, p_log_level_rec => p_log_level_rec);
6294 end if;
6295
6296 fa_srvr_msg.add_sql_error(calling_fn => p_calling_fn, p_log_level_rec => p_log_level_rec);
6297
6298 return false;
6299 END validate_ltd_deprn_change;
6300 -- End Bug 8471701
6301
6302 /*phase5 This function will validate if current transaction is overlapping to any previously done impairment*/
6303 /*Bug 10316358 now we are allowing transaction in same fiscal year of imapairment which are effective from
6304 current period (amortization start date = current period and transaction which are not backdated to same
6305 fiscal year of an impairment*/
6306 FUNCTION check_overlapping_impairment (
6307 p_trans_rec IN FA_API_TYPES.trans_rec_type,
6308 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
6309 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
6310
6311 l_imp_exists number := 0;
6312 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.check_overlapping_impairment';
6313 l_fiscal_year varchar2 (30);
6314 l_cal_period_open_date date;
6315 BEGIN
6316 if (p_log_level_rec.statement_level) then
6317 fa_debug_pkg.add(l_calling_fn, 'begin', '', p_log_level_rec);
6318 fa_debug_pkg.add(l_calling_fn, 'Marcos rate_source_rule ', fa_cache_pkg.fazccmt_record.rate_source_rule, p_log_level_rec);
6319 fa_debug_pkg.add(l_calling_fn, 'Marcos method_code ', fa_cache_pkg.fazccmt_record.method_code, p_log_level_rec);
6320 end if;
6321
6322 if (nvl(fa_cache_pkg.fazcbc_record.book_type_code, '-NULL') <>
6323 p_asset_hdr_rec.BOOK_TYPE_CODE) then
6324 if (NOT fa_cache_pkg.fazcbc (
6325 X_book => p_asset_hdr_rec.BOOK_TYPE_CODE,
6326 p_log_level_rec => p_log_level_rec
6327 )) then
6328 fa_srvr_msg.add_message(
6329 calling_fn => l_calling_fn,
6330 name => 'FA_POST_INVALID_BOOK');
6331 return FALSE;
6332 end if;
6333 end if;
6334
6335 if (NOT fa_cache_pkg.fazcdp (
6336 x_book_type_code => p_asset_hdr_rec.BOOK_TYPE_CODE, p_log_level_rec => p_log_level_rec)
6337 ) then
6338 fa_srvr_msg.add_message(
6339 calling_fn => l_calling_fn,
6340 name => 'FA_POST_INVALID_BOOK');
6341 return FALSE;
6342 end if;
6343
6344 l_fiscal_year := FA_CACHE_PKG.fazcbc_record.fiscal_year_name;
6345 l_cal_period_open_date := FA_CACHE_PKG.fazcdp_record.calendar_period_open_date;
6346
6347 BEGIN
6348
6349 SELECT count(*)
6350 INTO l_imp_exists
6351 FROM
6352 FA_TRANSACTION_HEADERS FATH,
6353 FA_DEPRN_PERIODS FADP,
6354 FA_FISCAL_YEAR FAFY
6355 WHERE FATH.BOOK_TYPE_CODE = p_asset_hdr_rec.BOOK_TYPE_CODE
6356 AND FAFY.FISCAL_YEAR_NAME = l_fiscal_year
6357 AND FATH.ASSET_ID = p_asset_hdr_rec.ASSET_ID
6358 AND FADP.BOOK_TYPE_CODE = FATH.BOOK_TYPE_CODE
6359 AND NVL(FATH.TRANSACTION_KEY,'XX') = 'IM'
6360 AND FATH.DATE_EFFECTIVE BETWEEN FADP.period_open_date AND NVL(FADP.period_close_date, SYSDATE)
6361 AND FAFY.FISCAL_YEAR = FADP.FISCAL_YEAR
6362 AND NVL (p_trans_rec.AMORTIZATION_START_DATE,p_trans_rec.TRANSACTION_DATE_ENTERED) < NVL(l_cal_period_open_date, SYSDATE)
6363 AND NVL (p_trans_rec.AMORTIZATION_START_DATE,p_trans_rec.TRANSACTION_DATE_ENTERED) <= NVL(FAFY.END_DATE, SYSDATE);
6364
6365 EXCEPTION
6366 WHEN NO_DATA_FOUND THEN
6367 l_imp_exists := 0;
6368 END;
6369
6370 IF l_imp_exists > 0 then
6371 IF (p_log_level_rec.statement_level) then
6372 fa_debug_pkg.add(l_calling_fn, 'Current Transaction is overlapped to previously done Impairment', '', p_log_level_rec);
6373 fa_debug_pkg.add(l_calling_fn, 'OR Amort start date/trx date is backdated ', 'to same Fiscal year in which an impairment already exists', p_log_level_rec);
6374 END IF;
6375 Return FALSE;
6376 ELSE
6377 Return TRUE;
6378 END IF;
6379
6380 END check_overlapping_impairment;
6381
6382 /*phase5 This function will restrict any impairment posted on Asset added with depreciate flag NO and wiithout reserve*/
6383 FUNCTION check_non_depreciating_asset (
6384 p_asset_id IN NUMBER,
6385 p_book_type_code IN VARCHAR2,
6386 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
6387
6388 l_restrict_trx VARCHAR2(1) := 'N';
6389 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.check_non_depreciating_asset';
6390
6391 BEGIN
6392 if (p_log_level_rec.statement_level) then
6393 fa_debug_pkg.add(l_calling_fn, 'begin', 'l_calling_fn', p_log_level_rec);
6394 end if;
6395 BEGIN
6396 SELECT 'Y'
6397 INTO l_restrict_trx
6398 FROM FA_BOOKS FABK
6399 WHERE FABK.ASSET_ID = p_asset_id
6400 AND FABK.BOOK_TYPE_CODE = p_book_type_code
6401 AND NOT EXISTS (SELECT 1 FROM FA_BOOKS FABK1
6402 WHERE FABK1.ASSET_ID = p_asset_id
6403 AND FABK1.BOOK_TYPE_CODE = p_book_type_code
6404 AND FABK1.DEPRECIATE_FLAG = 'YES')
6405 AND NOT EXISTS (SELECT 1 FROM FA_DEPRN_SUMMARY FADS
6406 WHERE FADS.ASSET_ID = p_asset_id
6407 AND FADS.BOOK_TYPE_CODE = p_book_type_code
6408 AND FADS.DEPRN_SOURCE_CODE = 'BOOKS'
6409 AND FADS.DEPRN_RESERVE > 0 );
6410
6411 EXCEPTION
6412 WHEN NO_DATA_FOUND THEN
6413 l_restrict_trx := 'N';
6414 END;
6415
6416
6417 IF (l_restrict_trx = 'Y') then
6418 IF (p_log_level_rec.statement_level) then
6419 fa_debug_pkg.add(l_calling_fn, 'This asset is added with Deprecition flag NO and without Reserve', '', p_log_level_rec);
6420 END IF;
6421 Return FALSE;
6422 ELSE
6423 Return TRUE;
6424 END IF;
6425
6426 END check_non_depreciating_asset;
6427
6428 FUNCTION validate_bonus_rule_resv
6429 (p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
6430 p_asset_desc_rec IN FA_API_TYPES.asset_desc_rec_type,
6431 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
6432 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
6433 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type,
6434 p_calling_fn IN VARCHAR2,
6435 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) RETURN BOOLEAN IS
6436 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.validate_bonus_rule_resv';
6437 Begin
6438 IF (p_log_level_rec.statement_level) then
6439 fa_debug_pkg.add(l_calling_fn, 'p_asset_type_rec.asset_type', p_asset_type_rec.asset_type, p_log_level_rec);
6440 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.bonus_rule', p_asset_fin_rec.bonus_rule, p_log_level_rec);
6441 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.group_asset_id', p_asset_fin_rec.group_asset_id, p_log_level_rec);
6442 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.member_rollup_flag', p_asset_fin_rec.member_rollup_flag, p_log_level_rec);
6443 fa_debug_pkg.add(l_calling_fn, 'p_asset_deprn_rec.bonus_deprn_reserve', p_asset_deprn_rec.bonus_deprn_reserve, p_log_level_rec);
6444 END IF;
6445
6446 -- No bonus rule for group asset
6447 if (nvl(p_asset_fin_rec.bonus_rule,FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR ) then
6448 if (p_asset_type_rec.asset_type = 'GROUP' ) then
6449 fa_srvr_msg.add_message(
6450 calling_fn => p_calling_fn,
6451 name =>'FA_NO_BONUS_FOR_GROUP',
6452 p_log_level_rec => p_log_level_rec);
6453 return false;
6454 end if;
6455
6456 -- No bonus rule for member asset
6457 if ( (nvl(p_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM and
6458 nvl(p_asset_fin_rec.member_rollup_flag,'Z') <> 'Y' )
6459 ) then
6460 fa_srvr_msg.add_message(
6461 calling_fn => p_calling_fn,
6462 name =>'FA_NO_BONUS_FOR_MBR',
6463 p_log_level_rec => p_log_level_rec);
6464 return false;
6465 end if;
6466 end if;
6467
6468 -- No bonus_reserve when no bonus rule specified
6469 if (p_asset_deprn_rec.bonus_deprn_reserve <> FND_API.G_MISS_NUM AND
6470 nvl(p_asset_deprn_rec.bonus_deprn_reserve,0) <> 0
6471 ) then
6472 if (nvl(p_asset_fin_rec.bonus_rule,FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR )then
6473 fa_srvr_msg.add_message(
6474 calling_fn => p_calling_fn,
6475 name =>'FA_BONUS_RULE_NO_RESV',
6476 p_log_level_rec => p_log_level_rec);
6477 return false;
6478 end if;
6479 end if;
6480
6481 return TRUE;
6482
6483 end validate_bonus_rule_resv;
6484
6485 /* Bug 9916378 */
6486 FUNCTION validate_uop_method (
6487 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
6488 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
6489 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
6490 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type default null,
6491 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type default null,
6492 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN is
6493
6494 l_old_rate_source_rule fa_methods.rate_source_rule%type;
6495 l_old_deprn_basis_rule fa_methods.deprn_basis_rule%type;
6496 l_rate_source_rule fa_methods.rate_source_rule%type;
6497 l_deprn_basis_rule fa_methods.deprn_basis_rule%type;
6498 l_grp_rate_source_rule fa_methods.rate_source_rule%type;
6499 l_grp_deprn_basis_rule fa_methods.deprn_basis_rule%type;
6500 l_grp_method_code fa_methods.method_code%type;
6501 l_old_grp_rate_source_rule fa_methods.rate_source_rule%type;
6502 l_old_grp_deprn_basis_rule fa_methods.deprn_basis_rule%type;
6503 l_old_grp_method_code fa_methods.method_code%type;
6504 l_corp_rate_source_rule fa_methods.rate_source_rule%type;
6505 l_corp_deprn_basis_rule fa_methods.deprn_basis_rule%type;
6506 l_corp_method_code fa_methods.method_code%type;
6507
6508 /* Added for ENH 12600386 Start */
6509 l_deprn_reserve fa_deprn_summary.deprn_reserve%type;
6510 l_ytd_deprn fa_deprn_summary.ytd_deprn%type;
6511
6512 cursor asset_deprn is
6513 select deprn_reserve, ytd_deprn
6514 from fa_deprn_summary
6515 where asset_id = p_asset_hdr_rec.asset_id
6516 and book_type_code = p_asset_hdr_rec.book_type_code
6517 and deprn_source_code = 'BOOKS';
6518 /* Added for ENH 12600386 End */
6519
6520 l_grp_mem_exists varchar2(1) := 'N';
6521
6522 /* Get method details */
6523 cursor method_details(p_method_code in varchar2) is
6524 select rate_source_rule, deprn_basis_rule
6525 from fa_methods mth
6526 where mth.method_code = p_method_code;
6527
6528 cursor group_method_details(p_group_asset_id in number) is
6529 select method_code, rate_source_rule, deprn_basis_rule
6530 from fa_methods mth, fa_books bk
6531 where mth.method_code = bk.deprn_method_code
6532 and bk.asset_id = p_group_asset_id
6533 and bk.book_type_code = p_asset_hdr_rec.book_type_code
6534 and bk.transaction_header_id_out is null;
6535
6536 cursor corp_method_details is
6537 select method_code, rate_source_rule, deprn_basis_rule
6538 from fa_methods mth, fa_books bk
6539 where mth.method_code = bk.deprn_method_code
6540 and bk.asset_id = p_asset_hdr_rec.asset_id
6541 and bk.book_type_code = fa_cache_pkg.fazcbc_record.distribution_source_book
6542 and bk.transaction_header_id_out is null;
6543
6544 cursor members_for_grp is
6545 select 'Y'
6546 from fa_books bk
6547 where bk.group_asset_id = p_asset_hdr_rec.asset_id
6548 and bk.book_type_code = p_asset_hdr_rec.book_type_code
6549 and bk.transaction_header_id_out is null;
6550
6551 /* Check any tax books exists with UOP method */
6552 cursor check_tax_book_method is
6553 select 'x'
6554 from fa_books bk,
6555 fa_book_controls bc,
6556 fa_methods mth
6557 where bc.distribution_source_book = p_asset_hdr_rec.book_type_code
6558 and bc.book_class = 'TAX'
6559 and bk.book_type_code = bc.book_type_code
6560 and bk.asset_id = p_asset_hdr_rec.asset_id
6561 and bk.transaction_header_id_out is null
6562 and bk.deprn_method_code = mth.method_code
6563 and mth.rate_source_rule = 'PRODUCTION'
6564 and l_rate_source_rule <> 'PRODUCTION';
6565
6566
6567 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.validate_uop_method_change';
6568
6569 check_flag varchar2(3) := 'N';
6570
6571 l_trx_date date;
6572
6573 l_group_asset_id number;
6574 val_err exception;
6575 l_deprn_resv number ;
6576 Begin
6577
6578 IF (p_log_level_rec.statement_level) then
6579 fa_debug_pkg.add(l_calling_fn, 'p_asset_type_rec.asset_type', p_asset_type_rec.asset_type, p_log_level_rec);
6580 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_old.deprn_method_code',
6581 p_asset_fin_rec_old.deprn_method_code, p_log_level_rec);
6582 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_old.group_asset_id',
6583 p_asset_fin_rec_old.group_asset_id, p_log_level_rec);
6584 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.deprn_method_code',
6585 p_asset_fin_rec.deprn_method_code, p_log_level_rec);
6586 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcbc_record.book_class',
6587 fa_cache_pkg.fazcbc_record.book_class, p_log_level_rec);
6588 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.period_of_addition',
6589 p_asset_hdr_rec.period_of_addition, p_log_level_rec);
6590 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazcdrd_record.rule_name',
6591 fa_cache_pkg.fazcdrd_record.rule_name, p_log_level_rec);
6592 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazccmt_record.rate_source_rule',
6593 fa_cache_pkg.fazccmt_record.rate_source_rule, p_log_level_rec);
6594 fa_debug_pkg.add(l_calling_fn, 'fa_cache_pkg.fazccmt_record.deprn_basis_rule',
6595 fa_cache_pkg.fazccmt_record.rate_source_rule, p_log_level_rec);
6596 END IF;
6597
6598 if p_asset_fin_rec_old.deprn_method_code is not null then
6599 open method_details(p_asset_fin_rec_old.deprn_method_code);
6600 fetch method_details into l_old_rate_source_rule, l_old_deprn_basis_rule;
6601 close method_details;
6602 end if;
6603 if p_asset_fin_rec.deprn_method_code is not null then
6604 open method_details(p_asset_fin_rec.deprn_method_code);
6605 fetch method_details into l_rate_source_rule, l_deprn_basis_rule;
6606 close method_details;
6607 else
6608 l_rate_source_rule := fa_cache_pkg.fazccmt_record.rate_source_rule;
6609 l_deprn_basis_rule := fa_cache_pkg.fazccmt_record.deprn_basis_rule;
6610 end if;
6611 if fa_cache_pkg.fazcbc_record.book_class = 'TAX' then
6612 open corp_method_details;
6613 fetch corp_method_details into l_corp_method_code, l_corp_rate_source_rule, l_corp_deprn_basis_rule;
6614 close corp_method_details;
6615 end if;
6616 if nvl(p_asset_fin_rec_old.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM then
6617 open group_method_details(p_asset_fin_rec_old.group_asset_id);
6618 fetch group_method_details into l_old_grp_method_code, l_old_grp_rate_source_rule, l_old_grp_deprn_basis_rule;
6619 close group_method_details;
6620 end if;
6621 if nvl(p_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM then
6622 open group_method_details(p_asset_fin_rec.group_asset_id);
6623 fetch group_method_details into l_grp_method_code, l_grp_rate_source_rule, l_grp_deprn_basis_rule;
6624 close group_method_details;
6625 end if;
6626
6627 IF (p_log_level_rec.statement_level) then
6628 fa_debug_pkg.add(l_calling_fn, 'l_old_rate_source_rule', l_old_rate_source_rule, p_log_level_rec);
6629 fa_debug_pkg.add(l_calling_fn, 'l_old_deprn_basis_rule', l_old_deprn_basis_rule, p_log_level_rec);
6630 fa_debug_pkg.add(l_calling_fn, 'l_rate_source_rule', l_rate_source_rule, p_log_level_rec);
6631 fa_debug_pkg.add(l_calling_fn, 'l_deprn_basis_rule', l_deprn_basis_rule, p_log_level_rec);
6632 fa_debug_pkg.add(l_calling_fn, 'l_corp_rate_source_rule', l_corp_rate_source_rule, p_log_level_rec);
6633 fa_debug_pkg.add(l_calling_fn, 'l_corp_deprn_basis_rule', l_corp_deprn_basis_rule, p_log_level_rec);
6634 fa_debug_pkg.add(l_calling_fn, 'l_old_grp_rate_source_rule', l_old_grp_rate_source_rule, p_log_level_rec);
6635 fa_debug_pkg.add(l_calling_fn, 'l_old_grp_deprn_basis_rule', l_old_grp_deprn_basis_rule, p_log_level_rec);
6636 fa_debug_pkg.add(l_calling_fn, 'l_grp_rate_source_rule', l_grp_rate_source_rule, p_log_level_rec);
6637 fa_debug_pkg.add(l_calling_fn, 'l_grp_deprn_basis_rule', l_grp_deprn_basis_rule, p_log_level_rec);
6638 END IF;
6639
6640 -- Do not allow group or member with UOP method (other than ENERGY)
6641 if (l_rate_source_rule = 'PRODUCTION'
6642 and l_deprn_basis_rule <> 'NBV') then
6643 if (p_asset_type_rec.asset_type = 'GROUP' ) then
6644 fa_srvr_msg.add_message(
6645 calling_fn => l_calling_fn,
6646 name =>'FA_UOP_NO_GROUP',
6647 p_log_level_rec => p_log_level_rec);
6648 return false;
6649 end if;
6650
6651 l_group_asset_id := nvl(p_asset_fin_rec.group_asset_id,p_asset_fin_rec_old.group_asset_id);
6652
6653 -- No UOP for member asset
6654 if ( (nvl(l_group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM and
6655 nvl(p_asset_fin_rec.member_rollup_flag,'Z') <> 'Y' )
6656 ) then
6657 fa_srvr_msg.add_message(
6658 calling_fn => l_calling_fn,
6659 name =>'FA_UOP_NO_MBR',
6660 p_log_level_rec => p_log_level_rec);
6661 return false;
6662 end if;
6663 end if;
6664
6665 --Check for group assignment or change
6666 if (nvl(p_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> nvl(p_asset_fin_rec_old.group_asset_id,FND_API.G_MISS_NUM) and
6667 nvl(p_asset_fin_rec.group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM )
6668 then
6669 if ( l_grp_rate_source_rule = 'PRODUCTION' and l_grp_deprn_basis_rule = 'NBV'
6670 and
6671 (l_rate_source_rule <> 'PRODUCTION' OR l_deprn_basis_rule <> 'NBV') )then
6672 fa_srvr_msg.add_message(
6673 calling_fn => l_calling_fn,
6674 name =>'FA_EGY_GRP_MBR',
6675 p_log_level_rec => p_log_level_rec);
6676 return false;
6677 end if;
6678
6679 if ( l_rate_source_rule = 'PRODUCTION' and l_deprn_basis_rule = 'NBV'
6680 and
6681 (l_grp_rate_source_rule <> 'PRODUCTION' OR l_grp_deprn_basis_rule <> 'NBV') )then
6682 fa_srvr_msg.add_message(
6683 calling_fn => l_calling_fn,
6684 name =>'FA_EGY_MBR_GRP',
6685 p_log_level_rec => p_log_level_rec);
6686 return false;
6687 end if;
6688 end if; -- group assignment
6689
6690 -- Check method change
6691 if nvl(p_asset_fin_rec.deprn_method_code,p_asset_fin_rec_old.deprn_method_code) <>
6692 nvl(p_asset_fin_rec_old.deprn_method_code,p_asset_fin_rec.deprn_method_code) then
6693
6694 /* Added for ENH 12600386 Start */
6695 if (l_rate_source_rule = 'PRODUCTION' and l_deprn_basis_rule <> 'NBV') then
6696
6697 open asset_deprn;
6698 fetch asset_deprn into l_deprn_reserve, l_ytd_deprn ;
6699
6700 if (asset_deprn%NOTFOUND) then
6701 close asset_deprn;
6702 l_deprn_reserve := 0;
6703 l_ytd_deprn := 0;
6704 else
6705 close asset_deprn;
6706 end if;
6707
6708 if (nvl(l_deprn_reserve,0) <> 0 OR
6709 nvl(l_ytd_deprn,0) <> 0) then
6710 fa_srvr_msg.add_message(
6711 calling_fn => l_calling_fn,
6712 name => 'FA_NO_RESERVE_FOR_PROD', p_log_level_rec => p_log_level_rec);
6713 return false;
6714 end if;
6715 end if;
6716 /* Added for ENH 12600386 End */
6717
6718 --No change to UOP method after period of addition
6719 if (l_old_rate_source_rule = 'PRODUCTION' and l_old_deprn_basis_rule <> 'NBV' and
6720 l_rate_source_rule <> 'PRODUCTION' and p_asset_hdr_rec.period_of_addition = 'N' ) then
6721 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6722 name =>'FA_BOOK_NO_CHANGE_TO_PROD',
6723 p_log_level_rec => p_log_level_rec);
6724 return false;
6725 end if;
6726
6727 --No change to production based method from non-production for member assets
6728 if (l_old_rate_source_rule <> 'PRODUCTION' and l_rate_source_rule = 'PRODUCTION'
6729 and p_asset_fin_rec_old.group_asset_id is not null ) then
6730 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6731 name =>'FA_UOP_NO_MBR',
6732 p_log_level_rec => p_log_level_rec);
6733 return false;
6734 end if;
6735
6736 if fa_cache_pkg.fazcbc_record.book_class = 'CORPORATE' then
6737 open check_tax_book_method;
6738 fetch check_tax_book_method into check_flag;
6739 if (check_tax_book_method%found) then
6740 close check_tax_book_method;
6741 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6742 name =>'FA_BOOK_MUST_USE_UOP',
6743 p_log_level_rec => p_log_level_rec);
6744 return false;
6745 end if;
6746 close check_tax_book_method;
6747 else
6748 if (l_rate_source_rule = 'PRODUCTION') and
6749 (l_corp_rate_source_rule <> 'PRODUCTION') then
6750 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6751 name =>'FA_BOOK_CORP_NOT_UOP',
6752 p_log_level_rec => p_log_level_rec);
6753 return false;
6754 end if;
6755 end if; -- book_class
6756
6757 if p_asset_type_rec.asset_type = 'GROUP' then
6758 open members_for_grp;
6759 fetch members_for_grp into l_grp_mem_exists;
6760 close members_for_grp;
6761 end if;
6762
6763 -- Do not allow method change to and from ENERGY UOP for group and member assets.
6764 if ( l_old_rate_source_rule = 'PRODUCTION' and l_old_deprn_basis_rule = 'NBV'
6765 and (l_rate_source_rule <> 'PRODUCTION' or l_deprn_basis_rule <> 'NBV'))
6766 OR
6767 ( l_rate_source_rule = 'PRODUCTION' and l_deprn_basis_rule = 'NBV'
6768 and (l_old_rate_source_rule <> 'PRODUCTION' or l_old_deprn_basis_rule <> 'NBV'))then
6769 if ((p_asset_type_rec.asset_type = 'GROUP' and l_grp_mem_exists = 'Y')
6770 or p_asset_fin_rec_old.group_asset_id is not null ) then
6771 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6772 name =>'FA_EGY_NO_METHOD_CHANGE',
6773 p_log_level_rec => p_log_level_rec);
6774 return false;
6775 end if;
6776 end if; -- ENERGY UOP for group and member
6777
6778 l_deprn_resv := nvl(p_asset_deprn_rec.deprn_reserve,0);
6779
6780 if (l_old_rate_source_rule = 'PRODUCTION' and l_old_deprn_basis_rule = 'NBV') and
6781 (l_rate_source_rule <> 'PRODUCTION' OR l_deprn_basis_rule <> 'NBV' ) then
6782 if (abs(p_asset_fin_rec_old.adjusted_recoverable_cost) < abs(l_deprn_resv) or
6783 (sign(p_asset_fin_rec_old.adjusted_recoverable_cost) <> 0 and
6784 sign(p_asset_fin_rec_old.adjusted_recoverable_cost) = -sign(l_deprn_resv))) then
6785 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
6786 name => 'FA_EGY_INVALID_RESERVE',
6787 p_log_level_rec => p_log_level_rec);
6788 return FALSE;
6789 end if;
6790 end if;
6791
6792 end if; -- method change
6793 return TRUE;
6794 end validate_uop_method;
6795
6796 FUNCTION validate_prev_period_amort
6797 (
6798 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
6799 p_trans_rec IN FA_API_TYPES.trans_rec_type,
6800 p_period_rec IN FA_API_TYPES.period_rec_type,
6801 p_asset_retire_rec IN FA_API_TYPES.asset_retire_rec_type default null,
6802 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN is
6803
6804 l_calling_fn varchar2(100) := 'FA_ASSET_VAL_PVT.validate_prev_period_amort';
6805
6806 cursor c_amort_trx is
6807 select 'Y'
6808 from fa_books bk
6809 where bk.book_type_code = p_asset_hdr_rec.book_type_code
6810 and bk.asset_id= p_asset_hdr_rec.asset_id
6811 and (bk.rate_Adjustment_factor <> 1 OR
6812 (bk.rate_adjustment_factor = 1 and
6813 exists
6814 (select 'YES'
6815 from fa_transaction_headers th,
6816 fa_methods mt
6817 where th.book_type_code = bk.book_type_code
6818 and th.asset_id = bk.asset_id
6819 and (th.transaction_subtype = 'AMORTIZED'
6820 OR th.transaction_key = 'UA')
6821 and th.transaction_header_id = bk.transaction_header_id_in
6822 and mt.method_code = bk.deprn_method_code
6823 and mt.rate_source_rule IN ('TABLE','FLAT','PRODUCTION','CALCULATED','FORMULA'))));
6824
6825 l_flag varchar2(1);
6826
6827 BEGIN
6828 if (nvl(fa_cache_pkg.fazcbc_record.prevent_prior_period_txns_flag,'N') <> 'Y' ) then
6829 return TRUE;
6830 end if;
6831
6832 if (p_trans_rec.amortization_start_date is not null) then
6833 if (p_trans_rec.amortization_start_date < p_period_rec.calendar_period_open_date) then
6834 fa_srvr_msg.add_message(
6835 calling_fn => l_calling_fn,
6836 name => 'FA_PREVENT_PREV_PRD', p_log_level_rec => p_log_level_rec);
6837 return FALSE;
6838 end if;
6839 else
6840 if p_trans_rec.transaction_type_code like '%RETIRE%' then
6841 open c_amort_trx;
6842 fetch c_amort_trx into l_flag;
6843 close c_amort_trx;
6844 if (l_flag = 'Y' and p_asset_retire_rec.date_retired < p_period_rec.calendar_period_open_date) then
6845 fa_srvr_msg.add_message(
6846 calling_fn => l_calling_fn,
6847 name => 'FA_PREVENT_PREV_PRD', p_log_level_rec => p_log_level_rec);
6848 return FALSE;
6849 end if;
6850 end if; -- RETIRE
6851 end if; -- amort date not null
6852
6853 return TRUE;
6854 END validate_prev_period_amort;
6855
6856 /* Bug 13513616/9559584 */
6857 FUNCTION is_financial_info_changed
6858 (
6859 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type,
6860 p_asset_fin_rec_adj IN FA_API_TYPES.asset_fin_rec_type,
6861 px_asset_fin_rec_new IN OUT NOCOPY FA_API_TYPES.asset_fin_rec_type,
6862 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
6863 l_fin_info_changed BOOLEAN := TRUE;
6864 BEGIN
6865 if not (nvl(p_asset_fin_rec_old.cash_generating_unit_id, FND_API.G_MISS_NUM) =
6866 nvl(p_asset_fin_rec_adj.cash_generating_unit_id,
6867 nvl(p_asset_fin_rec_old.cash_generating_unit_id, FND_API.G_MISS_NUM))) then
6868 l_fin_info_changed := FALSE;
6869 elsif nvl(p_asset_fin_rec_adj.contract_change_flag,FALSE) then
6870 l_fin_info_changed := FALSE;
6871 elsif nvl(p_asset_fin_rec_old.disabled_flag, FND_API.G_MISS_CHAR) <>
6872 nvl(px_asset_fin_rec_new.disabled_flag,nvl(p_asset_fin_rec_old.disabled_flag, FND_API.G_MISS_CHAR)) then
6873 l_fin_info_changed := FALSE;
6874 elsif not( nvl(p_asset_fin_rec_old.global_attribute1, FND_API.G_MISS_CHAR) =
6875 nvl(p_asset_fin_rec_adj.global_attribute1,
6876 nvl(p_asset_fin_rec_old.global_attribute1, FND_API.G_MISS_CHAR)) and
6877 nvl(p_asset_fin_rec_old.global_attribute2, FND_API.G_MISS_CHAR) =
6878 nvl(p_asset_fin_rec_adj.global_attribute2,
6879 nvl(p_asset_fin_rec_old.global_attribute2, FND_API.G_MISS_CHAR)) and
6880 nvl(p_asset_fin_rec_old.global_attribute3, FND_API.G_MISS_CHAR) =
6881 nvl(p_asset_fin_rec_adj.global_attribute3,
6882 nvl(p_asset_fin_rec_old.global_attribute3, FND_API.G_MISS_CHAR)) and
6883 nvl(p_asset_fin_rec_old.global_attribute4, FND_API.G_MISS_CHAR) =
6884 nvl(p_asset_fin_rec_adj.global_attribute4,
6885 nvl(p_asset_fin_rec_old.global_attribute4, FND_API.G_MISS_CHAR)) and
6886 nvl(p_asset_fin_rec_old.global_attribute5, FND_API.G_MISS_CHAR) =
6887 nvl(p_asset_fin_rec_adj.global_attribute5,
6888 nvl(p_asset_fin_rec_old.global_attribute5, FND_API.G_MISS_CHAR)) and
6889 nvl(p_asset_fin_rec_old.global_attribute6, FND_API.G_MISS_CHAR) =
6890 nvl(p_asset_fin_rec_adj.global_attribute6,
6891 nvl(p_asset_fin_rec_old.global_attribute6, FND_API.G_MISS_CHAR)) and
6892 nvl(p_asset_fin_rec_old.global_attribute7, FND_API.G_MISS_CHAR) =
6893 nvl(p_asset_fin_rec_adj.global_attribute7,
6894 nvl(p_asset_fin_rec_old.global_attribute7, FND_API.G_MISS_CHAR)) and
6895 nvl(p_asset_fin_rec_old.global_attribute8, FND_API.G_MISS_CHAR) =
6896 nvl(p_asset_fin_rec_adj.global_attribute8,
6897 nvl(p_asset_fin_rec_old.global_attribute8, FND_API.G_MISS_CHAR)) and
6898 nvl(p_asset_fin_rec_old.global_attribute9, FND_API.G_MISS_CHAR) =
6899 nvl(p_asset_fin_rec_adj.global_attribute9,
6900 nvl(p_asset_fin_rec_old.global_attribute9, FND_API.G_MISS_CHAR)) and
6901 nvl(p_asset_fin_rec_old.global_attribute10, FND_API.G_MISS_CHAR) =
6902 nvl(p_asset_fin_rec_adj.global_attribute10,
6903 nvl(p_asset_fin_rec_old.global_attribute10, FND_API.G_MISS_CHAR)) and
6904 nvl(p_asset_fin_rec_old.global_attribute11, FND_API.G_MISS_CHAR) =
6905 nvl(p_asset_fin_rec_adj.global_attribute11,
6906 nvl(p_asset_fin_rec_old.global_attribute11, FND_API.G_MISS_CHAR)) and
6907 nvl(p_asset_fin_rec_old.global_attribute12, FND_API.G_MISS_CHAR) =
6908 nvl(p_asset_fin_rec_adj.global_attribute12,
6909 nvl(p_asset_fin_rec_old.global_attribute12, FND_API.G_MISS_CHAR)) and
6910 nvl(p_asset_fin_rec_old.global_attribute13, FND_API.G_MISS_CHAR) =
6911 nvl(p_asset_fin_rec_adj.global_attribute13,
6912 nvl(p_asset_fin_rec_old.global_attribute13, FND_API.G_MISS_CHAR)) and
6913 nvl(p_asset_fin_rec_old.global_attribute14, FND_API.G_MISS_CHAR) =
6914 nvl(p_asset_fin_rec_adj.global_attribute14,
6915 nvl(p_asset_fin_rec_old.global_attribute14, FND_API.G_MISS_CHAR)) and
6916 nvl(p_asset_fin_rec_old.global_attribute15, FND_API.G_MISS_CHAR) =
6917 nvl(p_asset_fin_rec_adj.global_attribute15,
6918 nvl(p_asset_fin_rec_old.global_attribute15, FND_API.G_MISS_CHAR)) and
6919 nvl(p_asset_fin_rec_old.global_attribute16, FND_API.G_MISS_CHAR) =
6920 nvl(p_asset_fin_rec_adj.global_attribute16,
6921 nvl(p_asset_fin_rec_old.global_attribute16, FND_API.G_MISS_CHAR)) and
6922 nvl(p_asset_fin_rec_old.global_attribute17, FND_API.G_MISS_CHAR) =
6923 nvl(p_asset_fin_rec_adj.global_attribute17,
6924 nvl(p_asset_fin_rec_old.global_attribute17, FND_API.G_MISS_CHAR)) and
6925 nvl(p_asset_fin_rec_old.global_attribute18, FND_API.G_MISS_CHAR) =
6926 nvl(p_asset_fin_rec_adj.global_attribute18,
6927 nvl(p_asset_fin_rec_old.global_attribute18, FND_API.G_MISS_CHAR)) and
6928 nvl(p_asset_fin_rec_old.global_attribute19, FND_API.G_MISS_CHAR) =
6929 nvl(p_asset_fin_rec_adj.global_attribute19,
6930 nvl(p_asset_fin_rec_old.global_attribute19, FND_API.G_MISS_CHAR)) and
6931 nvl(p_asset_fin_rec_old.global_attribute20, FND_API.G_MISS_CHAR) =
6932 nvl(p_asset_fin_rec_adj.global_attribute20,
6933 nvl(p_asset_fin_rec_old.global_attribute20, FND_API.G_MISS_CHAR)) and
6934 nvl(p_asset_fin_rec_old.global_attribute_category, FND_API.G_MISS_CHAR) =
6935 nvl(p_asset_fin_rec_adj.global_attribute_category,
6936 nvl(p_asset_fin_rec_old.global_attribute_category, FND_API.G_MISS_CHAR))) then
6937 l_fin_info_changed := FALSE;
6938 end if;
6939 if not (l_fin_info_changed) then
6940 px_asset_fin_rec_new.adjusted_cost := p_asset_fin_rec_old.adjusted_cost ;
6941 px_asset_fin_rec_new.rate_adjustment_factor := p_asset_fin_rec_old.rate_adjustment_factor ;
6942 px_asset_fin_rec_new.formula_factor := p_asset_fin_rec_old.formula_factor ;
6943 end if;
6944 return l_fin_info_changed ;
6945 END is_financial_info_changed;
6946
6947 FUNCTION validate_ccid
6948 (p_book_type_code IN VARCHAR2,
6949 p_ccid IN NUMBER,
6950 p_gl_chart_id IN NUMBER,
6951 p_ledger_id IN NUMBER,
6952 p_validation_date IN DATE,
6953 p_calling_fn IN VARCHAR2,
6954 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN IS
6955 l_bal_seg_col_name gl_ledgers.bal_seg_column_name%type;
6956 l_bal_seg_value_option_code gl_ledgers.bal_seg_value_option_code%type;
6957 query_str VARCHAR2(1000);
6958 l_valid varchar2(1) := 'N';
6959 l_validation_date DATE;
6960 BEGIN
6961 SELECT bal_seg_value_option_code,bal_seg_column_name
6962 INTO l_bal_seg_value_option_code,l_bal_seg_col_name
6963 FROM gl_ledgers
6964 WHERE ledger_id = p_ledger_id;
6965
6966 if ( nvl(l_bal_seg_value_option_code,'A') <> 'A' ) then
6967 if p_validation_date is null then
6968 if not fa_cache_pkg.fazcdp
6969 (x_book_type_code => p_book_type_code,
6970 x_period_counter => null,
6971 x_effective_date => null, p_log_level_rec => p_log_level_rec) then
6972 fa_srvr_msg.add_message(calling_fn => 'fa_asset_val_pvt.validate_ccid', p_log_level_rec => p_log_level_rec);
6973 return false;
6974 end if;
6975 l_validation_date := greatest(fa_cache_pkg.fazcdp_record.calendar_period_open_date,
6976 least(sysdate,fa_cache_pkg.fazcdp_record.calendar_period_close_date));
6977 else
6978 l_validation_date := p_validation_date;
6979 end if;
6980 BEGIN
6981 query_str := 'SELECT ''Y''
6982 FROM gl_ledger_segment_values glsv
6983 WHERE glsv.segment_value in ( SELECT ' || l_bal_seg_col_name || '
6984 FROM gl_code_combinations gcc
6985 WHERE chart_of_accounts_id = :h_gl_chart_id
6986 AND code_combination_id = :h_expense_ccid
6987 AND enabled_flag = ''Y'')
6988 AND nvl(END_DATE,:h_val_date) <= :h_val_date
6989 AND ledger_id = :h_ledger_id';
6990 EXECUTE IMMEDIATE query_str
6991 INTO l_valid
6992 USING p_gl_chart_id,p_ccid,l_validation_date,l_validation_date,p_ledger_id ;
6993 EXCEPTION
6994 when NO_DATA_FOUND then
6995 fa_srvr_msg.add_message(
6996 calling_fn => 'fa_asset_val_pvt.validate_ccid',name => 'FA_INVALID_BALANCING_SEGMENT',p_log_level_rec => p_log_level_rec);
6997 return false;
6998 END;
6999 end if;
7000 return true;
7001 EXCEPTION
7002 WHEN OTHERS THEN
7003 fa_srvr_msg.add_sql_error(
7004 calling_fn => 'fa_asset_val_pvt.validate_ccid', p_log_level_rec => p_log_level_rec);
7005 return false;
7006 END validate_ccid;
7007
7008 /*bug#16426081 */
7009 FUNCTION validate_cca_rules (
7010 p_trans_rec IN FA_API_TYPES.trans_rec_type,
7011 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
7012 p_asset_type_rec IN FA_API_TYPES.asset_type_rec_type,
7013 p_asset_fin_rec IN FA_API_TYPES.asset_fin_rec_type,
7014 p_asset_fin_rec_old IN FA_API_TYPES.asset_fin_rec_type default null,
7015 p_asset_deprn_rec IN FA_API_TYPES.asset_deprn_rec_type default null,
7016 p_asset_deprn_rec_adj IN FA_API_TYPES.asset_deprn_rec_type default null,
7017 p_period_rec IN FA_API_TYPES.period_rec_type,
7018 p_log_level_rec IN FA_API_TYPES.log_level_rec_type) RETURN BOOLEAN is
7019
7020 cursor c_method_details(p_method_code in varchar2) is
7021 select mt.method_code, mt.method_id, mt.deprn_basis_rule,ru.rule_name
7022 from fa_methods mt, fa_deprn_basis_rules ru
7023 where mt.deprn_basis_rule_id = ru.deprn_basis_rule_id(+)
7024 and mt.method_code = p_method_code;
7025
7026 cursor c_grp_details(p_grp_asset_id in number) is
7027 select bk.asset_id, bk.tracking_method,bk.member_rollup_flag,bk.deprn_method_code
7028 from fa_books bk
7029 where bk.book_type_code = p_asset_hdr_rec.book_type_code
7030 and bk.asset_id = p_grp_asset_id
7031 and transaction_header_id_out is null;
7032
7033 cursor c_ret_count is
7034 select count(1)
7035 from dual
7036 where exists
7037 (
7038 select 1
7039 from fa_retirements
7040 where book_type_code = p_asset_hdr_rec.book_type_code
7041 and asset_id = p_asset_hdr_rec.asset_id
7042 and status = 'PROCESSED'
7043 );
7044
7045 cursor c_mem_exists is
7046 select count(1)
7047 from dual
7048 where exists
7049 (
7050 select 1
7051 from fa_books bk
7052 where book_type_code = p_asset_hdr_rec.book_type_code
7053 and group_asset_id = p_asset_hdr_rec.asset_id
7054 and transaction_header_id_out is null
7055 );
7056
7057 cursor c_other_mem(p_group_asset_id in number) is
7058 select count(1)
7059 from dual
7060 where exists
7061 (
7062 select 1
7063 from fa_books bk
7064 where book_type_code = p_asset_hdr_rec.book_type_code
7065 and group_asset_id = p_group_asset_id
7066 and asset_id <> p_asset_hdr_rec.asset_id
7067 and transaction_header_id_out is null
7068 );
7069
7070 cursor c_get_adj_cost is
7071 select adjusted_cost
7072 from fa_books
7073 where book_type_code = p_asset_hdr_rec.book_type_code
7074 and asset_id = p_asset_hdr_rec.asset_id
7075 and transaction_header_id_out is null;
7076
7077 l_dummy_num number;
7078
7079 l_cost number;
7080 l_old_cost number;
7081 l_adjusted_cost number;
7082 l_deprn_reserve number;
7083 l_group_asset_id number;
7084 l_method_det c_method_details%rowtype;
7085 l_old_method_det c_method_details%rowtype;
7086 l_grp_method_det c_method_details%rowtype;
7087 l_grp_fin_det c_grp_details%rowtype;
7088 l_old_group_asset_id number;
7089 l_old_grp_fin_det c_grp_details%rowtype;
7090 l_calling_fn varchar2(100) := 'fa_addition_pub.validate_cca_rules';
7091
7092 begin
7093 l_cost := nvl(p_asset_fin_rec.cost,0);
7094 l_old_cost := nvl(p_asset_fin_rec_old.cost,0);
7095 l_deprn_reserve := nvl(p_asset_deprn_rec.deprn_reserve,0);
7096 l_adjusted_cost := nvl(p_asset_fin_rec.adjusted_cost,0);
7097 l_group_asset_id := p_asset_fin_rec.group_asset_id;
7098 l_old_group_asset_id := p_asset_fin_rec_old.group_asset_id;
7099
7100 if (p_log_level_rec.statement_level) then
7101 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id, p_log_level_rec => p_log_level_rec);
7102 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.group_asset_id', p_asset_fin_rec.group_asset_id, p_log_level_rec => p_log_level_rec);
7103 end if;
7104
7105 open c_method_details(nvl(p_asset_fin_rec.deprn_method_code,p_asset_fin_rec_old.deprn_method_code));
7106 fetch c_method_details into l_method_det;
7107 close c_method_details;
7108 if(p_asset_fin_rec_old.deprn_method_code is not null) then
7109 open c_method_details(p_asset_fin_rec_old.deprn_method_code);
7110 fetch c_method_details into l_old_method_det;
7111 close c_method_details;
7112 end if;
7113
7114 if (nvl(l_group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM) then
7115 open c_grp_details (l_group_asset_id);
7116 fetch c_grp_details into l_grp_fin_det;
7117 close c_grp_details;
7118
7119 open c_method_details(l_grp_fin_det.deprn_method_code);
7120 fetch c_method_details into l_grp_method_det;
7121 close c_method_details;
7122 end if;
7123 if (l_old_group_asset_id is not null) then
7124 open c_grp_details (l_old_group_asset_id);
7125 fetch c_grp_details into l_old_grp_fin_det;
7126 close c_grp_details;
7127 end if;
7128 if (p_log_level_rec.statement_level) then
7129 fa_debug_pkg.add(l_calling_fn, 'p_asset_hdr_rec.asset_id', p_asset_hdr_rec.asset_id, p_log_level_rec => p_log_level_rec);
7130 fa_debug_pkg.add(l_calling_fn, 'p_trans_rec.transaction_type_code', p_trans_rec.transaction_type_code, p_log_level_rec => p_log_level_rec);
7131 fa_debug_pkg.add(l_calling_fn, 'l_cost', l_cost, p_log_level_rec => p_log_level_rec);
7132 fa_debug_pkg.add(l_calling_fn, 'l_deprn_reserve', l_deprn_reserve, p_log_level_rec => p_log_level_rec);
7133 fa_debug_pkg.add(l_calling_fn, 'l_adjusted_cost', l_adjusted_cost, p_log_level_rec => p_log_level_rec);
7134 fa_debug_pkg.add(l_calling_fn, 'l_group_asset_id', l_group_asset_id, p_log_level_rec => p_log_level_rec);
7135 fa_debug_pkg.add(l_calling_fn, 'l_old_group_asset_id', l_old_group_asset_id, p_log_level_rec => p_log_level_rec);
7136 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.tracking_method', p_asset_fin_rec.tracking_method, p_log_level_rec => p_log_level_rec);
7137 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.member_rollup_flag', p_asset_fin_rec.member_rollup_flag, p_log_level_rec => p_log_level_rec);
7138 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec.deprn_method_code', p_asset_fin_rec.deprn_method_code, p_log_level_rec => p_log_level_rec);
7139 fa_debug_pkg.add(l_calling_fn, 'p_asset_fin_rec_old.deprn_method_code', p_asset_fin_rec_old.deprn_method_code, p_log_level_rec => p_log_level_rec);
7140 fa_debug_pkg.add(l_calling_fn, 'l_method_det.rule_name', l_method_det.rule_name, p_log_level_rec => p_log_level_rec);
7141 fa_debug_pkg.add(l_calling_fn, 'l_method_det.deprn_basis_rule', l_method_det.deprn_basis_rule, p_log_level_rec => p_log_level_rec);
7142 fa_debug_pkg.add(l_calling_fn, 'l_old_method_det.rule_name', l_old_method_det.rule_name, p_log_level_rec => p_log_level_rec);
7143 fa_debug_pkg.add(l_calling_fn, 'l_old_method_det.deprn_basis_rule', l_old_method_det.deprn_basis_rule, p_log_level_rec => p_log_level_rec);
7144 fa_debug_pkg.add(l_calling_fn, 'l_grp_method_det.rule_name', l_grp_method_det.rule_name, p_log_level_rec => p_log_level_rec);
7145 fa_debug_pkg.add(l_calling_fn, 'l_grp_method_det.deprn_basis_rule', l_grp_method_det.deprn_basis_rule, p_log_level_rec => p_log_level_rec);
7146 fa_debug_pkg.add(l_calling_fn, 'l_grp_fin_det.tracking_method', l_grp_fin_det.tracking_method, p_log_level_rec => p_log_level_rec);
7147 fa_debug_pkg.add(l_calling_fn, 'l_grp_fin_det.member_rollup_flag', l_grp_fin_det.member_rollup_flag, p_log_level_rec => p_log_level_rec);
7148 fa_debug_pkg.add(l_calling_fn, 'l_old_grp_fin_det.tracking_metho', l_old_grp_fin_det.tracking_method, p_log_level_rec => p_log_level_rec);
7149 fa_debug_pkg.add(l_calling_fn, 'l_old_grp_fin_det.member_rollup_flag', l_old_grp_fin_det.member_rollup_flag, p_log_level_rec => p_log_level_rec);
7150 end if;
7151
7152 /* Adjusted_cost related */
7153 if(nvl(l_adjusted_cost,0) <> 0) and (p_trans_rec.transaction_key = 'BA') then
7154
7155 if(nvl(l_group_asset_id,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM or
7156 nvl(p_asset_fin_rec.tracking_method,'NONE') <> 'CALCULATE' or
7157 nvl(p_asset_fin_rec.member_rollup_flag,'N') <> 'Y' or
7158 nvl(p_asset_hdr_rec.period_of_addition,'N') <> 'Y' or
7159 nvl(l_method_det.rule_name,'ZZ') <> 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT' or
7160 p_asset_fin_rec.date_placed_in_service >= p_period_rec.calendar_period_open_date
7161 ) then
7162 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7163 name =>'FA_CCA_NO_ADJ_COST',
7164 p_log_level_rec => p_log_level_rec);
7165 return false;
7166 end if;
7167 if (l_cost <> 0 and l_method_det.deprn_basis_rule = 'NBV') then
7168 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7169 name =>'FA_CCA_NO_ADJ_COST',
7170 p_log_level_rec => p_log_level_rec);
7171 return false;
7172 end if;
7173 if (l_cost <> 0 and sign(l_cost) <> sign(l_adjusted_cost) ) then
7174 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7175 name =>'FA_CCA_NO_ADJ_COST',
7176 p_log_level_rec => p_log_level_rec);
7177 return false;
7178 end if;
7179
7180 end if;
7181 -- and rules name not YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT
7182 if( nvl(l_method_det.rule_name,'ZZ') <> 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT' and
7183 nvl(l_old_method_det.rule_name,'ZZ') <> 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT'
7184 ) then
7185 return TRUE;
7186 end if;
7187 /*Deprn_reserve related*/
7188 if((nvl(p_asset_deprn_rec_adj.deprn_reserve,0) <> 0 and nvl(p_asset_fin_rec.tracking_method,'NONE') = 'CALCULATE' )
7189 or (p_trans_rec.transaction_type_code like '%ADDITION%' and l_deprn_reserve <> 0 )) then
7190 if (sign(l_deprn_reserve) <> sign(l_cost)) then
7191 if (l_method_det.deprn_basis_rule = 'NBV' and
7192 l_cost <> 0 ) then
7193 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7194 name =>'FA_CCA_RESV_NOT_ALLOWED',
7195 p_log_level_rec => p_log_level_rec);
7196 return false;
7197 end if;
7198 end if;
7199 end if;
7200 /*Group change related : When making as standalone asset */
7201 if(p_trans_rec.transaction_type_code like '%ADJUSTMENT%' and
7202 l_old_group_asset_id > 0 and nvl(l_group_asset_id,FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM) then
7203 open c_ret_count;
7204 fetch c_ret_count into l_dummy_num;
7205 close c_ret_count;
7206 if (l_dummy_num > 0) then
7207 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7208 name =>'FA_CCA_RET_EXISTS',
7209 p_log_level_rec => p_log_level_rec);
7210 return false;
7211 end if;
7212 end if;
7213
7214 -- Remaining validations not needed when tracking method <> CALCULATE
7215 if (nvl(p_asset_fin_rec.tracking_method,'NONE') <> 'CALCULATE' or
7216 nvl(p_asset_fin_rec.member_rollup_flag,'N') <> 'Y' ) then
7217 return TRUE;
7218 end if;
7219
7220 if(p_asset_type_rec.asset_type = 'GROUP' ) then
7221 if(p_trans_rec.transaction_type_code like '%ADJUSTMENT%' and
7222 p_asset_fin_rec.deprn_method_code <> p_asset_fin_rec_old.deprn_method_code
7223 ) then
7224 if(nvl(l_method_det.rule_name,'ZZ') <> nvl(l_old_method_det.rule_name,'ZZ') or
7225 l_method_det.deprn_basis_rule <> l_old_method_det.deprn_basis_rule
7226 ) then
7227 open c_mem_exists;
7228 fetch c_mem_exists into l_dummy_num;
7229 close c_mem_exists;
7230 if (l_dummy_num > 0) then
7231 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7232 name =>'FA_CCA_MTD_NOT_ALLOWED',
7233 p_log_level_rec => p_log_level_rec);
7234 return false;
7235 end if;
7236 end if; --l_method_det.rule_name
7237 end if; -- p_trans_rec.transaction_type_code
7238 return TRUE;
7239 end if; --p_asset_type_rec.asset_type
7240
7241 /*Method related for member asset*/
7242 if( nvl(l_method_det.rule_name,'ZZ') = 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT') then
7243 if (nvl(l_method_det.rule_name,'ZZ') <> nvl(l_grp_method_det.rule_name,'YY') or
7244 l_method_det.deprn_basis_rule <> l_grp_method_det.deprn_basis_rule
7245 ) then
7246 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7247 name =>'FA_CCA_DIFF_GRP',
7248 p_log_level_rec => p_log_level_rec);
7249 return false;
7250 end if;
7251 end if;
7252 if( nvl(l_grp_method_det.rule_name,'ZZ') = 'YEAR END BALANCE WITH POSITIVE REDUCTION AMOUNT') then
7253 if (nvl(l_method_det.rule_name,'ZZ') <> nvl(l_grp_method_det.rule_name,'ZZ') or
7254 l_method_det.deprn_basis_rule <> l_grp_method_det.deprn_basis_rule
7255 ) then
7256 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7257 name =>'FA_CCA_DIFF_MBR',
7258 p_log_level_rec => p_log_level_rec);
7259 return false;
7260 end if;
7261 end if;
7262
7263 /*10.1 specific : */
7264
7265 -- Allow only one member in a group
7266 if(p_trans_rec.transaction_type_code like '%ADJUSTMENT%' and
7267 nvl(l_group_asset_id,FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM and
7268 nvl(l_old_group_asset_id,FND_API.G_MISS_NUM) <> nvl(l_group_asset_id,FND_API.G_MISS_NUM) and
7269 l_method_det.deprn_basis_rule = 'NBV' and
7270 p_asset_type_rec.asset_type <> 'GROUP'
7271 ) then
7272 open c_other_mem(l_group_asset_id);
7273 fetch c_other_mem into l_dummy_num;
7274 close c_other_mem;
7275 if (l_dummy_num > 0) then
7276 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7277 name =>'FA_CCA_ONE_MEM',
7278 p_log_level_rec => p_log_level_rec);
7279 return false;
7280 end if;
7281 end if;
7282 --No transactions if cost is zero, adjusted_cost non-zero
7283 if(l_method_det.deprn_basis_rule = 'NBV' and l_old_cost = 0 and l_adjusted_cost = 0 and p_asset_type_rec.asset_type <> 'GROUP'
7284 and nvl(l_old_group_asset_id,FND_API.G_MISS_NUM) = nvl(l_group_asset_id,FND_API.G_MISS_NUM) and
7285 p_trans_rec.transaction_type_code not like '%ADDITION%'
7286 ) then
7287 open c_get_adj_cost;
7288 fetch c_get_adj_cost into l_dummy_num;
7289 close c_get_adj_cost;
7290 if(nvl(l_dummy_num,0) <> 0 ) then
7291 fa_srvr_msg.add_message(calling_fn => l_calling_fn,
7292 name =>'FA_CCA_NO_TRX',
7293 p_log_level_rec => p_log_level_rec);
7294 return false;
7295 end if;
7296 end if;
7297
7298 /*10.1 specific ends: */
7299
7300 return TRUE;
7301
7302 end validate_cca_rules;
7303
7304 END FA_ASSET_VAL_PVT;