DBA Data[Home] [Help]
Skip to content

PACKAGE BODY: APPS.FA_REC_PVT_PKG3

Source


1 PACKAGE BODY FA_REC_PVT_PKG3 AS
2 /* $Header: FAXVRC3B.pls 120.5 2009/03/27 04:50:43 bridgway ship $ */
3 
4 /*===================================================================================+
5 | FUNCTION Validate_Rule_Changes						     |
6 +====================================================================================*/
7 
8 FUNCTION Validate_Rule_Changes(
9         p_asset_id              IN      NUMBER,
10         p_new_category_id       IN      NUMBER,
11         p_book_type_code        IN      VARCHAR2,
12         p_amortize_flag         IN      VARCHAR2,
13         p_old_rules             IN 	FA_LOAD_TBL_PKG.asset_deprn_info,
14         p_new_rules             IN   	FA_LOAD_TBL_PKG.asset_deprn_info,
15 	x_prorate_date	 OUT NOCOPY DATE,
16         x_rate_source_rule      OUT NOCOPY     VARCHAR2,
17         x_deprn_basis_rule      OUT NOCOPY     VARCHAR2
18         , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type)	RETURN BOOLEAN IS
19 BEGIN
20     ---- Validate each new depreciation rule ----
21 
22     /* Validate new depreciation ceiling. */
23     IF NOT Validate_Ceiling(
24 		p_asset_id		=> p_asset_id,
25 		p_book_type_code 	=> p_book_type_code,
26 		p_old_ceiling_name	=> p_old_rules.ceiling_name,
27 		p_new_ceiling_name	=> p_new_rules.ceiling_name,
28                 p_log_level_rec         => p_log_level_rec)
29     THEN
30 	FA_SRVR_MSG.Add_Message(
31 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Rule_Changes', p_log_level_rec => p_log_level_rec);
32 	RETURN (FALSE);
33     END IF;
34 
35     /* Validate new depreciation flag. */
36 /*  Skip this check -- we will not change depreciate flag through mass reclass.
37     IF NOT Validate_Deprn_Flag(
38 		p_old_rules		=> p_old_rules,
39 		p_new_rules		=> p_new_rules)
40     THEN
41 	FA_SRVR_MSG.Add_Message(
42 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Rule_Changes', p_log_level_rec => p_log_level_rec);
43 	RETURN (FALSE);
44     END IF;
45 */
46 
47     /* Validate new prorate convention. */
48     IF NOT Validate_Convention(
49 		p_asset_id		=> p_asset_id,
50 		p_book_type_code	=> p_book_type_code,
51 		p_date_placed_in_service => p_old_rules.start_dpis,
52 		p_old_conv		=> p_old_rules.prorate_conv_code,
53 		p_new_conv		=> p_new_rules.prorate_conv_code,
54 		p_amortize_flag 	=> p_amortize_flag,
55 		x_prorate_date		=> x_prorate_date,
56                 p_log_level_rec         => p_log_level_rec)
57     THEN
58 	FA_SRVR_MSG.Add_Message(
59 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Rule_Changes', p_log_level_rec => p_log_level_rec);
60 	RETURN (FALSE);
61     END IF;
62 
63     /* Validate new depreciation method. */
64     -- p_old_rules.start_dpis and end_dpis store the current date placed in
65     -- service for the asset.
66     IF NOT Validate_Deprn_Method(
67 		p_asset_id		=> p_asset_id,
68 		p_book_type_code	=> p_book_type_code,
69 		p_old_deprn_method 	=> p_old_rules.deprn_method,
70 		p_new_deprn_method	=> p_new_rules.deprn_method,
71 		p_new_category_id	=> p_new_category_id,
72                 x_rate_source_rule      => x_rate_source_rule,
73                 x_deprn_basis_rule      => x_deprn_basis_rule,
74                 p_log_level_rec         => p_log_level_rec
75 		)
76     THEN
77 	FA_SRVR_MSG.Add_Message(
78 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Rule_Changes', p_log_level_rec => p_log_level_rec);
79 	RETURN (FALSE);
80     END IF;
81 
82     /* Validate new life and rates. */
83     IF NOT Validate_Life_Rates(
84 		p_deprn_method		=> p_new_rules.deprn_method,
85 		p_basic_rate		=> p_new_rules.basic_rate,
86 		p_adjusted_rate		=> p_new_rules.adjusted_rate,
87 		p_life_in_months	=> p_new_rules.life_in_months,
88                 p_log_level_rec         => p_log_level_rec)
89     THEN
90 	FA_SRVR_MSG.Add_Message(
91 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Rule_Changes', p_log_level_rec => p_log_level_rec);
92 	RETURN (FALSE);
93     END IF;
94 
95     RETURN (TRUE);
96 EXCEPTION
97     WHEN OTHERS THEN
98         FA_SRVR_MSG.Add_SQL_Error(
99                 CALLING_FN =>  'FA_REC_PVT_PKG3.Validate_Rule_Changes', p_log_level_rec => p_log_level_rec);
100         RETURN (FALSE);
101 END Validate_Rule_Changes;
102 
103 
104 /*===================================================================================+
105 | FUNCTION Validate_Ceiling							     |
106 +====================================================================================*/
107 
108 FUNCTION Validate_Ceiling(
109         p_asset_id              IN      NUMBER,
110         p_book_type_code        IN      VARCHAR2,
111         p_old_ceiling_name      IN      VARCHAR2,
112 	p_new_ceiling_name	IN	VARCHAR2
113         , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type)       RETURN BOOLEAN IS
114 	l_book_class		VARCHAR2(15);
115 	l_allow_cost_ceil	VARCHAR2(3);
116 	l_allow_deprn_exp_ceil  VARCHAR2(3);
117 	l_cost			NUMBER;
118 	l_itc_amount_id		NUMBER(15);
119 	l_new_ceiling_type	VARCHAR2(30);
120 	CURSOR get_book_info IS
121 	    SELECT book_class, allow_cost_ceiling, allow_deprn_exp_ceiling
122 	    FROM FA_BOOK_CONTROLS
123     	    WHERE book_type_code = p_book_type_code;
124 	CURSOR get_ceiling_type IS
125 	    SELECT ceiling_type FROM FA_CEILING_TYPES
126     	    WHERE ceiling_name = p_new_ceiling_name;
127 	CURSOR get_cost_itc IS
128 	    SELECT cost, itc_amount_id FROM FA_BOOKS
129     	    WHERE asset_id = p_asset_id and book_type_code = p_book_type_code
130     	    AND date_ineffective IS NULL;
131 BEGIN
132     -- Skip validation if rule remains the same or if new ceiling name
133     -- is null.
134     IF (nvl(p_old_ceiling_name, 'NULL')
135 		= nvl(p_new_ceiling_name, 'NULL') OR
136 	p_new_ceiling_name IS NULL) THEN
137 	RETURN (TRUE);
138     END IF;
139 
140     OPEN get_book_info;
141     FETCH get_book_info INTO l_book_class, l_allow_cost_ceil, l_allow_deprn_exp_ceil;
142     CLOSE get_book_info;
143 
144     OPEN get_ceiling_type;
145     FETCH get_ceiling_type INTO l_new_ceiling_type;
146     CLOSE get_ceiling_type;
147 
148     OPEN get_cost_itc;
149     FETCH get_cost_itc INTO l_cost, l_itc_amount_id;
150     CLOSE get_cost_itc;
151 
152     IF (l_book_class IN ('BUDGET', 'CORPORATE') OR
153         l_cost <= 0) THEN
154 	FA_SRVR_MSG.Add_Message(
155 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Ceiling',
156 		NAME => 'FA_REC_CANNOT_SET_CEIL', p_log_level_rec => p_log_level_rec);
157 		/* Message text: 'You cannot set a depreciation ceiling for
158 		   an asset in a corporate or budget book or an asset with a
159 		   negative or zero cost.' */
160 	RETURN (FALSE);
161     END IF;
162 
163     IF (l_new_ceiling_type = 'RECOVERABLE COST CEILING') THEN
164 	IF (l_allow_cost_ceil = 'NO') THEN
165 	    FA_SRVR_MSG.Add_Message(
166 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Ceiling',
167 		NAME => 'FA_REC_NO_COST_CEIL', p_log_level_rec => p_log_level_rec);
168 		/* Message text:
169 		   'Cost ceiling is not allowed in this book.' */
170 	    RETURN (FALSE);
171 	END IF;
172     ELSIF (l_new_ceiling_type = 'DEPRN EXPENSE CEILING') THEN
173 	IF (l_allow_deprn_exp_ceil = 'NO') THEN
174 	    FA_SRVR_MSG.Add_Message(
175 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Ceiling',
176 		NAME => 'FA_REC_NO_DEPRN_EXP_CEIL', p_log_level_rec => p_log_level_rec);
177 		/* Message text:
178 		   'Depreciation expense ceiling is not allowed in this book.' */
179 	    RETURN (FALSE);
180 	END IF;
181     END IF;
182 
183     /* You can use either a depreciation cost ceiling or ITC for an asset,
184        but not both. */
185     IF (l_itc_amount_id IS NOT NULL AND
186 	l_new_ceiling_type = 'RECOVERABLE COST CEILING') THEN
187 	FA_SRVR_MSG.Add_Message(
188 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Ceiling',
189 		NAME => 'FA_BOOK_CANT_ITC_AND_COST_CEIL', p_log_level_rec => p_log_level_rec);
190 	RETURN (FALSE);
191     END IF;
192 
193     RETURN (TRUE);
194 EXCEPTION
195     WHEN OTHERS THEN
196         FA_SRVR_MSG.Add_SQL_Error(
197                 CALLING_FN =>  'FA_REC_PVT_PKG3.Validate_Ceiling', p_log_level_rec => p_log_level_rec);
198         RETURN (FALSE);
199 END Validate_Ceiling;
200 
201 
202 /*===================================================================================+
203 | FUNCTION Validate_Deprn_Flag							     |
204 +====================================================================================*/
205 
206 FUNCTION Validate_Deprn_Flag(
207         p_old_rules             IN      FA_LOAD_TBL_PKG.asset_deprn_info,
208         p_new_rules             IN      FA_LOAD_TBL_PKG.asset_deprn_info
209         , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type)       RETURN BOOLEAN IS
210 	CURSOR chk_deprn_flag IS
211 	    SELECT 'N'
212 	    FROM FA_METHODS mth
213 	    WHERE mth.method_code = p_old_rules.deprn_method
214 	    AND mth.rate_source_rule = 'PRODUCTION';
215 	check_flag	VARCHAR2(3);
216 BEGIN
217     -- Skip validation if rule remains the same.
218     IF (p_old_rules.depreciate_flag = p_new_rules.depreciate_flag) THEN
219 	RETURN (TRUE);
220     END IF;
221 
222     /* Other depreciation rules must remain the same, when changing the
223        Depreciate flag. */
224     IF NOT ((p_old_rules.prorate_conv_code = p_new_rules.prorate_conv_code) AND
225             (p_old_rules.deprn_method = p_new_rules.deprn_method) AND
226             (nvl(p_old_rules.life_in_months, 99999) =
227                         nvl(p_new_rules.life_in_months, 99999)) AND
228             (nvl(p_old_rules.basic_rate, 99999) =
229                         nvl(p_new_rules.basic_rate, 99999)) AND
230             (nvl(p_old_rules.adjusted_rate, 99999) =
231                         nvl(p_new_rules.adjusted_rate, 99999)) AND
232             (nvl(p_old_rules.production_capacity, 99999) =
233                         nvl(p_new_rules.production_capacity, 99999)) AND
234             (nvl(p_old_rules.unit_of_measure, 99999) =
235                         nvl(p_new_rules.unit_of_measure, 99999)) AND
236             (nvl(p_old_rules.bonus_rule, 'NULL') =
237                         nvl(p_new_rules.bonus_rule, 'NULL')) AND
238             (nvl(p_old_rules.ceiling_name, 'NULL') =
239                         nvl(p_new_rules.ceiling_name, 'NULL')) AND
240             (nvl(p_old_rules.allow_deprn_limit, 99) =
241                         nvl(p_new_rules.allow_deprn_limit, 99)) AND
242             (nvl(to_char(p_old_rules.deprn_limit_amount), 'NULL') =
243                         nvl(to_char(p_new_rules.deprn_limit_amount), 'NULL')) AND
244             (nvl(p_old_rules.percent_salvage_value, 99) =
245                         nvl(p_new_rules.percent_salvage_value, 99)))
246     THEN
247 	FA_SRVR_MSG.Add_Message(
248 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Flag',
249 		NAME => 'FA_REC_NO_MULTIPLE_CHANGES', p_log_level_rec => p_log_level_rec);
250 		/* Message text: 'You cannot make more than one adjustment
251 		   upon changing the Depreciate flag.' */
252 	RETURN (FALSE);
253     ELSE /* Other depreciation rules remain the same. */
254 	/* You cannot set Depreciate flag to No for units of production
255 	   assets. */
256 	IF (p_old_rules.depreciate_flag = 'YES' AND
257 	    p_new_rules.depreciate_flag = 'NO') THEN
258 	    OPEN chk_deprn_flag;
259 	    FETCH chk_deprn_flag INTO check_flag;
260 	    IF (chk_deprn_flag%found) THEN
261 		CLOSE chk_deprn_flag;
262 		FA_SRVR_MSG.Add_Message(
263 			CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Flag',
264 			NAME => 'FA_BOOK_INVALID_DEPRN_FLAG', p_log_level_rec => p_log_level_rec);
265 	 	RETURN (FALSE);
266 	    END IF;
267 	    CLOSE chk_deprn_flag;
268 	END IF;
269     END IF;
270 
271     RETURN (TRUE);
272 EXCEPTION
273     WHEN OTHERS THEN
274         FA_SRVR_MSG.Add_SQL_Error(
275                 CALLING_FN =>  'FA_REC_PVT_PKG3.Validate_Deprn_Flag', p_log_level_rec => p_log_level_rec);
276         RETURN (FALSE);
277 END Validate_Deprn_Flag;
278 
279 
280 /*===================================================================================+
281 | FUNCTION Validate_Convention							     |
282 +====================================================================================*/
283 
284 FUNCTION Validate_Convention(
285         p_asset_id              IN      NUMBER,
286         p_book_type_code        IN      VARCHAR2,
287 	p_date_placed_in_service IN	DATE,
288         p_old_conv              IN      VARCHAR2,
289         p_new_conv              IN      VARCHAR2,
290         p_amortize_flag         IN      VARCHAR2,
291 	x_prorate_date	 OUT NOCOPY DATE
292         , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type)       RETURN BOOLEAN IS
293 	l_dpis			DATE;
294 	l_prorate_date		DATE;
295 	check_flag		VARCHAR2(3);
296 	CURSOR get_prorate_date IS
297 	    SELECT conv.prorate_date
298 	    FROM FA_CONVENTIONS conv
299 	    WHERE conv.prorate_convention_code = p_new_conv
300 	    AND p_date_placed_in_service between conv.start_date and conv.end_date;
301 	CURSOR check_prorate_date IS
302 	    SELECT 'x'
303 	    FROM FA_CALENDAR_PERIODS cp, FA_BOOK_CONTROLS bc
304 	    WHERE bc.book_type_code = p_book_type_code
305 	    AND bc.prorate_calendar = cp.calendar_type
306 	    AND l_prorate_date between cp.start_date and cp.end_date;
307 BEGIN
308 
309     /* Get the prorate date.  This will be used in Do_Redefault(). */
310     OPEN get_prorate_date;
311     FETCH get_prorate_date INTO l_prorate_date;
312     IF (get_prorate_date%notfound) THEN
313 	CLOSE get_prorate_date;
314 	FA_SRVR_MSG.Add_Message(
315 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Convention',
316 	 	NAME => 'FA_BOOK_CANT_GEN_PRORATE_DATE', p_log_level_rec => p_log_level_rec);
317 	RETURN (FALSE);
318     END IF;
319     CLOSE get_prorate_date;
320 
321     x_prorate_date := l_prorate_date;
322 
323     -- Skip the rest of the validations if rule remains the same.
324     IF (p_old_conv = p_new_conv) THEN
325 	RETURN (TRUE);
326     END IF;
327 
328     /* Cannot amortize a prorate convention adjustment. */
329 -- Bug 1111642
330 --    IF (p_amortize_flag = 'YES') THEN
331 --	FA_SRVR_MSG.Add_Message(
332 --		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Convention',
333 --		NAME => 'FA_CANNOT_AMORTIZE_PRORATE_CHE', p_log_level_rec => p_log_level_rec);
334 --	RETURN (FALSE);
335 --    END IF;
336 
337     /* Check if the new prorate date is valid. */
338     OPEN check_prorate_date;
339     FETCH check_prorate_date INTO check_flag;
340     IF (check_prorate_date%notfound) THEN
341 	CLOSE check_prorate_date;
342 	FA_SRVR_MSG.Add_Message(
343 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Convention',
344 	 	NAME => 'FA_BKS_INVALID_PRORATE_DATE', p_log_level_rec => p_log_level_rec);
345 	RETURN (FALSE);
346     END IF;
347     CLOSE check_prorate_date;
348 
349     RETURN (TRUE);
350 EXCEPTION
351     WHEN OTHERS THEN
352         FA_SRVR_MSG.Add_SQL_Error(
353                 CALLING_FN =>  'FA_REC_PVT_PKG3.Validate_Convention', p_log_level_rec => p_log_level_rec);
354         RETURN (FALSE);
355 END Validate_Convention;
356 
357 
358 /*===================================================================================+
359 | FUNCTION Validate_Deprn_Method						     |
360 +====================================================================================*/
361 
362 FUNCTION Validate_Deprn_Method(
363         p_asset_id              IN      NUMBER,
364         p_book_type_code        IN      VARCHAR2,
365         p_old_deprn_method      IN      VARCHAR2,
366         p_new_deprn_method      IN      VARCHAR2,
367         p_new_category_id       IN      NUMBER,
368         x_rate_source_rule      OUT NOCOPY     VARCHAR2,
369         x_deprn_basis_rule      OUT NOCOPY     VARCHAR2
370         , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type)       RETURN BOOLEAN IS
371 	l_new_rate_src_rule	VARCHAR2(10);
372 	l_new_deprn_basis_rule	VARCHAR2(4);
373 	l_itc_amount_id		NUMBER(15);
374 	l_conversion_date	DATE;
375 	l_depreciation_check	VARCHAR2(3) := 'N';
376 		-- Indicates whether depreciation has already been run
377 		-- on the asset or not.
378 	l_book_class		VARCHAR2(15);
379 	l_count			NUMBER := 0;
380 	check_flag		VARCHAR2(3);
381 	CURSOR check_method IS
382 	    SELECT 'N'
383   	    FROM FA_METHODS mth
384 	    WHERE l_depreciation_check = 'Y'
385 	    AND p_old_deprn_method = mth.method_code
386 	    AND mth.rate_source_rule <> 'PRODUCTION'
387 	    AND l_new_rate_src_rule = 'PRODUCTION';
388 	CURSOR check_tax_book_method IS
389 	    SELECT 'x'
390 	    FROM FA_METHODS mth, FA_CATEGORY_BOOK_DEFAULTS cbd,
391 		 FA_BOOK_CONTROLS bc, FA_BOOKS bk
392 	    WHERE bc.distribution_source_book = p_book_type_code
393 	    AND bc.book_class = 'TAX'
394 	    AND bk.book_type_code = bc.book_type_code
395 	    AND bk.asset_id = p_asset_id
396 	    AND bk.date_ineffective IS NULL
397 	    AND bk.book_type_code = cbd.book_type_code
398 	    AND cbd.category_id = p_new_category_id
399 	    AND bk.date_placed_in_service between cbd.start_dpis
400 		and nvl(cbd.end_dpis, to_date('31-12-4712', 'DD-MM-YYYY'))
401 	    AND cbd.deprn_method = mth.method_code
402 	    AND mth.rate_source_rule = 'PRODUCTION'
403 	    AND l_new_rate_src_rule <> 'PRODUCTION';
404 	CURSOR check_corp_book_method IS
405 	    SELECT 'x'
406 	    FROM FA_METHODS corp_mth, FA_CATEGORY_BOOK_DEFAULTS cbd,
407 		 FA_BOOK_CONTROLS bc, FA_BOOKS bk
408 	    WHERE bc.book_type_code = p_book_type_code
409 	    AND bk.book_type_code = bc.distribution_source_book
410 	    AND bk.asset_id = p_asset_id
411 	    AND bk.date_ineffective IS NULL
412 	    AND bk.book_type_code = cbd.book_type_code
413 	    AND cbd.category_id = p_new_category_id
414 	    AND bk.date_placed_in_service between cbd.start_dpis
415 		and nvl(cbd.end_dpis, to_date('31-12-4712', 'DD-MM-YYYY'))
416 	    AND cbd.deprn_method = corp_mth.method_code
417 	    AND corp_mth.rate_source_rule <> 'PRODUCTION'
418 	    AND l_new_rate_src_rule = 'PRODUCTION';
419 	CURSOR get_rate_deprn_rules IS
420 	    SELECT rate_source_rule, deprn_basis_rule
421     	    FROM FA_METHODS
422     	    WHERE method_code = p_new_deprn_method;
423         /* cursor to get a book row for an asset */
424         CURSOR get_book_info IS
425             SELECT itc_amount_id, conversion_date
426             FROM FA_BOOKS
427             WHERE asset_id = p_asset_id AND book_type_code = p_book_type_code
428             AND date_ineffective IS NULL;
429 	CURSOR get_book_class IS
430 	    SELECT book_class FROM FA_BOOK_CONTROLS
431     	    WHERE book_type_code = p_book_type_code;
432         /* cursor to validate depreciation method change for a
433 	   short-tax-year asset */
434         CURSOR check_short_tax IS
435             SELECT 'N'
436             FROM FA_DEPRN_SUMMARY ds, FA_METHODS mth
437             WHERE mth.method_code = p_old_deprn_method
438             AND mth.rate_source_rule = 'FORMULA'
439             AND ds.asset_id = p_asset_id
440             AND ds.book_type_code = p_book_type_code
441             AND ds.deprn_source_code = 'DEPRN' AND deprn_amount <> 0;
442 BEGIN
443    -- If old_deprn_method is 'JP_STL_EXTND' then do not allow the method change
444        IF (p_old_deprn_method = 'JP-STL-EXTND') THEN
445 	RETURN (FALSE);
446        END IF;
447 
448     -- Get new rate source rule and depreciation basis rule for the new
449     -- depreciation method.
450     OPEN get_rate_deprn_rules;
451     FETCH get_rate_deprn_rules INTO l_new_rate_src_rule, l_new_deprn_basis_rule;
452     CLOSE get_rate_deprn_rules;
453 
454     x_rate_source_rule := l_new_rate_src_rule;
455     x_deprn_basis_rule := l_new_deprn_basis_rule;
456 
457     -- Skip validation if rule remains the same.
458     IF (p_old_deprn_method = p_new_deprn_method) THEN
459 	RETURN (TRUE);
460     END IF;
461 
462     -- Get the asset's current book information.
463     OPEN get_book_info;
464     FETCH get_book_info INTO l_itc_amount_id, l_conversion_date;
465     CLOSE get_book_info;
466 
467     -- Get the book class for the book being processed.
468     OPEN get_book_class;
469     FETCH get_book_class INTO l_book_class;
470     CLOSE get_book_class;
471 
472     SELECT count(1) INTO l_count FROM FA_DEPRN_SUMMARY
473     WHERE book_type_code = p_book_type_code AND asset_id = p_asset_id
474     AND deprn_source_code = 'DEPRN' AND deprn_amount <> 0
475     AND rownum < 2;
476 
477     IF (l_count > 0) THEN
478 	l_depreciation_check := 'Y'; -- Asset has already been depreciated.
479     END IF;
480 
481     /* You can assign ITC to assets that use a life-based depreciation method
482        only. */
483     IF (l_new_deprn_basis_rule = 'NBV' AND
484 	l_new_rate_src_rule = 'FLAT' AND
485 	l_itc_amount_id IS NOT NULL) THEN
486 	FA_SRVR_MSG.Add_Message(
487 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Method',
488 	 	NAME => 'FA_BOOK_INVALID_METHOD', p_log_level_rec => p_log_level_rec);
489 	RETURN (FALSE);
490     END IF;
491 
492     /* You cannot change to a production method after you run depreciation. */
493     OPEN check_method;
494     FETCH check_method INTO check_flag;
495     IF (check_method%found) THEN
496 	CLOSE check_method;
497 	FA_SRVR_MSG.Add_Message(
498 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Method',
499 	 	NAME => 'FA_BOOK_NO_CHANGE_TO_PROD', p_log_level_rec => p_log_level_rec);
500 	RETURN (FALSE);
501     END IF;
502     CLOSE check_method;
503 
504     IF (l_book_class = 'CORPORATE') THEN
505     /* Production method must be used in a corporate book, if a production
506        method will be used in any of the associated tax books.
507        Check the new depreciation methods for the corporate book and the
508        associated tax books. */
509 	OPEN check_tax_book_method;
510 	FETCH check_tax_book_method INTO check_flag;
511 	IF (check_tax_book_method%found) THEN
512 	    CLOSE check_tax_book_method;
513 	    FA_SRVR_MSG.Add_Message(
514 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Method',
515 	 	NAME => 'FA_REC_MUST_USE_UOP', p_log_level_rec => p_log_level_rec);
516 	        /* Message text: 'Production method must be used in a
517 		   corporate book, if a production method will be used in
518 		   any of the associated tax books.' */
519 	    RETURN (FALSE);
520         END IF;
521 	CLOSE check_tax_book_method;
522     ELSE /* TAX book */
523     /* Production method cannot be used in a tax book, if production method
524        will not be used in its associated corporate book.
525        Check the new depreciation methods for the corporate book and the
526        associated tax books. */
527 	OPEN check_corp_book_method;
528 	FETCH check_corp_book_method INTO check_flag;
529 	IF (check_corp_book_method%found) THEN
530 	    CLOSE check_corp_book_method;
531 	    FA_SRVR_MSG.Add_Message(
532 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Method',
533 	 	NAME => 'FA_REC_CORP_NOT_UOP', p_log_level_rec => p_log_level_rec);
534 		/* Message text: 'Production method cannot be used in
535 		   a tax book, if production method will not be used in its
536 		   associated corporate book.' */
537 	    RETURN (FALSE);
538         END IF;
539 	CLOSE check_corp_book_method;
540     END IF;
541 
542     /* Depreciation method cannot be changed from a FORMULA method to
543        a non-FORMULA method for a short-tax-year asset, if depreciation
544        has already run. */
545     IF (l_conversion_date IS NOT NULL AND
546         l_new_rate_src_rule <> 'FORMULA') THEN
547         /* If an asset is a short-tax-year asset and if the new method is
548            not a FORMULA method
549            -- Use conversion_date as a measure of whether an asset
550            is a short-tax-year asset or not, since short_fiscal_year_flag
551            can be 'NO' for short-tax-year assets, after the first fiscal
552            year. */
553         OPEN check_short_tax;
554         FETCH check_short_tax INTO check_flag;
555         IF (check_short_tax%found) THEN
556         /* Old method was a FORMULA method, and asset has already depreciated,
557            and therefore depreciation method change is disallowed. */
558             CLOSE check_short_tax;
559             FA_SRVR_MSG.Add_Message(
560                 CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Deprn_Method',
561                 NAME => 'FA_SHORT_TAX_METHOD', p_log_level_rec => p_log_level_rec);
562             /* New message:
563                 'Depreciation method cannot be changed from a formula-based
564                  method to a non-formula-based method for an asset added in
565                  a short fiscal year after depreciation has run.' */
566             RETURN (FALSE);
567         END IF;
568         CLOSE check_short_tax;
569     END IF;
570 
571     RETURN (TRUE);
572 EXCEPTION
573     WHEN OTHERS THEN
574         FA_SRVR_MSG.Add_SQL_Error(
575                 CALLING_FN =>  'FA_REC_PVT_PKG3.Validate_Deprn_Method', p_log_level_rec => p_log_level_rec);
576         RETURN (FALSE);
577 END Validate_Deprn_Method;
578 
579 
580 /*===================================================================================+
581 | FUNCTION Validate_Life_Rates							     |
582 +====================================================================================*/
583 
584 FUNCTION Validate_Life_Rates(
585         p_deprn_method          IN      VARCHAR2,
586         p_basic_rate            IN      NUMBER,
587         p_adjusted_rate         IN      NUMBER,
588         p_life_in_months        IN      NUMBER
589         , p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type)       RETURN BOOLEAN IS
590 	check_flag		VARCHAR2(3);
591 	l_rate_src_rule		VARCHAR2(10);
592 	CURSOR check_rate IS
593 	    SELECT 'Y'
594 	    FROM FA_FLAT_RATES fr, FA_METHODS mth
595 	    WHERE mth.method_code = p_deprn_method
596 	    AND mth.life_in_months IS NULL
597 	    AND mth.method_id = fr.method_id
598 	    AND fr.basic_rate = p_basic_rate
599 	    AND fr.adjusted_rate = p_adjusted_rate;
600 	CURSOR check_life IS
601 	    SELECT 'Y'
602 	    FROM FA_METHODS mth
603 	    WHERE mth.method_code = p_deprn_method
604 	    AND nvl(mth.life_in_months, 99999) = p_life_in_months;
605 	CURSOR get_rate_src_rule IS
606 	    SELECT rate_source_rule FROM FA_METHODS
607     	    WHERE method_code = p_deprn_method;
608 BEGIN
609     -- Small validation unit.  Just validate without checking whehter
610     -- change exists or not.
611 
612     -- Get new rate source rule for the new depreciation method.
613     OPEN get_rate_src_rule;
614     FETCH get_rate_src_rule INTO l_rate_src_rule;
615     CLOSE get_rate_src_rule;
616 
617     IF (l_rate_src_rule = 'FLAT') THEN
618 	OPEN check_rate;
619 	FETCH check_rate INTO check_flag;
620 	IF (check_rate%notfound) THEN
621 	    CLOSE check_rate;
622 	    FA_SRVR_MSG.Add_Message(
623 		CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Life_Rates',
624 	 	NAME => 'FA_SHARED_INVALID_METHOD_RATE', p_log_level_rec => p_log_level_rec);
625 	    RETURN (FALSE);
626         END IF;
627 	CLOSE check_rate;
628     ELSE
629 	IF (l_rate_src_rule <> 'PRODUCTION') THEN
630 	    OPEN check_life;
631 	    FETCH check_life INTO check_flag;
632 	    IF (check_life%notfound) THEN
633 	   	CLOSE check_life;
634 	 	FA_SRVR_MSG.Add_Message(
635 			CALLING_FN => 'FA_REC_PVT_PKG3.Validate_Life_Rates',
636 	 		NAME => 'FA_SHARED_INVALID_METHOD_LIFE', p_log_level_rec => p_log_level_rec);
637 	    	RETURN (FALSE);
638             END IF;
639 	    CLOSE check_life;
640 	END IF;
641     END IF;
642 
643     RETURN (TRUE);
644 EXCEPTION
645     WHEN OTHERS THEN
646         FA_SRVR_MSG.Add_SQL_Error(
647                 CALLING_FN =>  'FA_REC_PVT_PKG3.Validate_Life_Rates', p_log_level_rec => p_log_level_rec);
648         RETURN (FALSE);
649 END Validate_Life_Rates;
650 
651 
652 END FA_REC_PVT_PKG3;