DBA Data[Home] [Help]

PACKAGE BODY: APPS.IGI_IAC_RECLASS_PKG

Source


1 PACKAGE BODY IGI_IAC_RECLASS_PKG AS
2 /* $Header: igiiarlb.pls 120.25.12000000.3 2007/11/05 14:03:44 sharoy ship $ */
3 --  A Global variable to set the debug mode
4     debug_reclass BOOLEAN;
5     l_output_dir varchar2(255);
6     l_debug_log varchar2(255);
7     l_debug_output varchar2(255);
8     l_debug_print Boolean;
9 
10     -- global vlaue for allow reval index and prof flag
11     ALLOW_INDEX_REVAL_FLAG BOOLEAN;
12     ALLOW_PROF_REVAL_FLAG  BOOLEAN;
13     SAME_PRICE_INDEX_FLAG  BOOLEAN;
14     DIFF_PRICE_INDEX_FLAG  BOOLEAN;
15 
16     l_trans_rec                      FA_API_TYPES.trans_rec_type;
17     l_asset_hdr_rec                  FA_API_TYPES.asset_hdr_rec_type;
18     l_asset_cat_rec_old              FA_API_TYPES.asset_cat_rec_type;
19     l_asset_cat_rec_new              FA_API_TYPES.asset_cat_rec_type;
20     l_asset_desc_rec                 FA_API_TYPES.asset_desc_rec_type;
21     l_asset_type_rec                 FA_API_TYPES.asset_type_rec_type;
22     l_calling_function              varchar2(250);
23     l_deprn_reserve_amount   NUmber;
24     chr_newline VARCHAR2(8);
25     l_deprn_ytd number; --- for ytd previous old active distributions
26 
27     --===========================FND_LOG.START=====================================
28 
29     g_state_level NUMBER;
30     g_proc_level  NUMBER;
31     g_event_level NUMBER;
32     g_excep_level NUMBER;
33     g_error_level NUMBER;
34     g_unexp_level NUMBER;
35     g_path        VARCHAR2(100);
36 
37     --===========================FND_LOG.END=====================================
38 
39     /*
40     * BOOLTOCHAR
41     *
42     * A utility function to convert boolean values to char to print in
43     * debug statements
44     */
45     FUNCTION BOOLTOCHAR(value IN BOOLEAN) RETURN VARCHAR2
46     IS
47     BEGIN
48         IF (value) THEN
49             RETURN 'TRUE';
50         ELSE
51             RETURN 'FALSE';
52         END IF;
53     END BOOLTOCHAR;
54 
55 -- ======================================================================
56 -- CATEGORY VALIDATION
57 -- ======================================================================
58 FUNCTION Do_validate_category
59 RETURN boolean is
60     l_return_value boolean;
61     l_original_category_id number;
62     l_new_category_id number;
63     l_old_cap_flag fa_categories.capitalize_flag%type;
64     l_old_cat_type fa_categories.category_type%type;
65     l_new_cap_flag fa_categories.capitalize_flag%type;
66     l_new_cat_type fa_categories.category_type%type;
67     l_old_index_reval_flag igi_iac_category_books.allow_indexed_reval_flag%Type;
68     l_old_prof_reval_flag igi_iac_category_books.allow_prof_reval_flag%Type;
69     l_new_index_reval_flag igi_iac_category_books.allow_indexed_reval_flag%Type;
70     l_new_prof_reval_flag igi_iac_category_books.allow_prof_reval_flag%Type;
71     l_path_name VARCHAR2(150);
72 
73 
74      -- cursor to validate category linked to iac book
75     Cursor get_category_id(c_category_id Number)is
76     SELECT category_id,allow_indexed_reval_flag,allow_prof_reval_flag
77     FROM igi_iac_category_books
78     WHERE book_type_code = l_asset_hdr_rec.book_type_code
79     AND category_id = c_category_id;
80 
81     --cursor to get the category capitalized
82     Cursor get_cat_cap_flag(c_category_id Number) is
83     SELECT capitalize_flag,category_type
84     FROM fa_categories
85     WHERE category_id = c_category_id;
86 
87 
88 BEGIN
89     l_path_name := g_path||'do_validate_category';
90     l_return_value := False;
91     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
92 		     p_full_path => l_path_name,
93 		     p_string => '     + Enter validate category');
94 
95      -- check if same category or null category
96     IF ((l_asset_cat_rec_old.category_id = l_asset_cat_rec_new.category_id)or
97         (l_asset_cat_rec_old.category_id is null or l_asset_cat_rec_new.category_id is null))
98          THEN
99   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
100 		     p_full_path => l_path_name,
101 		     p_string => '     + Same category old and new or null value');
102 
103           Return false;
104     End if;
105     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
106 		     p_full_path => l_path_name,
107 		     p_string => '     + different categories old ' || l_asset_cat_rec_old.category_id
108 				 || 'and new' ||l_asset_cat_rec_new.category_id );
109 
110     /**
111     --validate if both categories are added to IAC book controls
112     **/
113     -- A record should exisit in iac category books for both categories for same book_typec_code
114     -- check for original category id
115     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
116 		     p_full_path => l_path_name,
117 		     p_string => '     + orinignal category id iac book test ..'||l_asset_cat_rec_old.category_id);
118 
119    Open get_category_id(l_asset_cat_rec_old.category_id);
120     Fetch get_category_id into l_original_category_id,
121                                l_old_index_reval_flag,
122                                l_old_prof_reval_flag ;
123     IF NOT get_category_id%FOUND THEN
124         -- Raise error message that category is not exisiting in iac book
125        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
126 		     	p_full_path => l_path_name,
127 		     	p_string => '     +error message that category is not exisiting in iac book  '||l_asset_cat_rec_old.category_id);
128 
129        Close get_category_id;
130         Return false;
131     END IF;
132     Close get_category_id;
133 
134     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
135 		     p_full_path => l_path_name,
136 		     p_string => '     + Original category  exisits in iac book  '||l_asset_cat_rec_old.category_id);
137 
138     Open get_category_id(l_asset_cat_rec_new.category_id);
139     Fetch get_category_id into l_original_category_id,
140                                l_new_index_reval_flag,
141                                l_new_prof_reval_flag ;
142     IF NOT get_category_id%FOUND THEN
143         -- Raise error message that category is not exisiting in iac book
144        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
145 		     p_full_path => l_path_name,
146 		     p_string => '     +error message that category is not exisiting in iac book  '||l_asset_cat_rec_new.category_id);
147        Close get_category_id;
148         Return false;
149     END IF;
150     Close get_category_id;
151 
152     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
153 		     p_full_path => l_path_name,
154 		     p_string => '     + New category  exisits in iac book  '||l_asset_cat_rec_old.category_id);
155 
156     /**
157     --validate if both categories are captitalized
158     **/
159     -- for the old category
160     open get_cat_cap_flag(l_asset_cat_rec_old.category_id);
161     Fetch get_cat_cap_flag into l_old_cap_flag,
162                                 l_old_cat_type;
163     Close get_cat_cap_flag;
164     -- for new category
165     open get_cat_cap_flag(l_asset_cat_rec_new.category_id);
166     Fetch get_cat_cap_flag into l_new_cap_flag,
167                                 l_new_cat_type;
168     Close get_cat_cap_flag;
169     --check the category flags
170     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
171 		     p_full_path => l_path_name,
172 		     p_string => '     + check for category captilized falgs');
173 
174     IF (l_old_cap_flag = 'YES') THEN
175          IF (l_old_cap_flag <> l_new_cap_flag) THEN
176   		     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
177 		     		p_full_path => l_path_name,
178 		     		p_string => '     + both the categories not captilized falgs');
179 
180                      Return False;
181           End IF;
182      END IF;
183 
184      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
185 		     p_full_path => l_path_name,
186 		     p_string => '     + check for category captilized falgs success');
187 
188     /**
189     --Set the indexed and profesional flag for revaluation
190     **/
191     --set the allow index reval flag
192      IF l_new_index_reval_flag ='Y' THEN
193             allow_index_reval_flag := True;
194      ELSE
195             allow_index_reval_flag := False;
196      END IF;
197      --set the prof  reval flag
198      IF l_new_prof_reval_flag ='Y' THEN
199             allow_prof_reval_flag := True;
200      ELSE
201             allow_prof_reval_flag := False;
202      END IF;
203 
204      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
205 		     p_full_path => l_path_name,
206 		     p_string => '     + set the indexed and prof flags ');
207      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
208 		     p_full_path => l_path_name,
209 		     p_string => '     + set the indexed flag ' || l_new_index_reval_flag );
210      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
211 		     p_full_path => l_path_name,
212 		     p_string => '     + set the prof flag ' ||l_new_prof_reval_flag );
213      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
214 		     p_full_path => l_path_name,
215 		     p_string => '     + EXIT Validate category' );
216 
217    Return True;
218 
219 END; -- do validate category
220 
221 
222 -- ======================================================================
223 -- ASSET VALIDATION
224 -- ======================================================================
225 FUNCTION Do_Validate_Asset
226 RETURN boolean is
227 
228     -- cursor for to check asset type
229    /* Cursor to find out NOCOPY if the asset is revalued atleast once */
230 
231 	CURSOR 	c_asset_revalued(c_asset_id IGI_IAC_ASSET_BALANCES.asset_id%type) IS
232 		SELECT 'X'
233 		FROM	igi_iac_asset_balances
234 		WHERE	asset_id=l_asset_hdr_rec.asset_id
235         AND     book_type_code = l_asset_hdr_rec.book_type_code;
236 
237     l_asset_revalued c_asset_revalued%rowtype;
238     l_path_name VARCHAR2(150);
239 
240 BEGIN
241     l_path_name := g_path||'do_validate_asset';
242     -- check if revaluation atleast once
243      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
244 		     p_full_path => l_path_name,
245 		     p_string => '     + check if revaluation atleast once' );
246      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
247 		     p_full_path => l_path_name,
248 		     p_string => '     + check if revaluation atleast once ...' || l_asset_hdr_rec.asset_id );
249      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
250 		     p_full_path => l_path_name,
251 		     p_string => '     + check if revaluation atleast once ...' || l_asset_hdr_rec.book_type_code);
252 
253     	/* Check IF Asset is revalued at least once */
254         open c_asset_revalued(l_asset_hdr_rec.asset_id);
255 	    fetch c_asset_revalued into l_asset_revalued;
256     	IF c_asset_revalued%NOTFOUND THEN
257           	close c_asset_revalued;
258   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
259 		     	p_full_path => l_path_name,
260 		     	p_string => '+ No IAC revaluation atleast once');
261 
262    		RETURN(FALSE);
263          END IF;
264 
265     	close c_asset_revalued;
266 
267   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
268 		     p_full_path => l_path_name,
269 		     p_string => '     + check if revaluation atleast once success' );
270 
271    IF NOT (l_asset_type_rec.asset_type in ('CAPITALIZED') ) THEN
272         -- ERROR MESSAGE
273        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
274 		     p_full_path => l_path_name,
275 		     p_string => '     + NOT CAPITALIZED ASSET' );
276        return FALSE;
277     END IF;
278     Return True;
279 END; -- do validate asset
280 
281 /*
282 +===============================================================================+
283 |	Procedure To Insert Data into IGI_IAC_TRANSACTION_HEADERS		|
284 ================================================================================+
285 */
286     PROCEDURE Insert_data_trans_hdr(p_adjustment_id 		in out NOCOPY IGI_IAC_TRANSACTION_HEADERS.adjustment_id%type,
287     				p_transaction_header_id 	in IGI_IAC_TRANSACTION_HEADERS.transaction_header_id%type,
288     				p_adjustment_id_out		in IGI_IAC_TRANSACTION_HEADERS.adjustment_id_out%type,
289     				p_transaction_type_code		in IGI_IAC_TRANSACTION_HEADERS.transaction_type_code%type,
290     				p_transaction_date_entered 	in IGI_IAC_TRANSACTION_HEADERS.transaction_date_entered%type,
291     				p_mass_reference_id		in IGI_IAC_TRANSACTION_HEADERS.mass_reference_id%type,
292     				p_book_type_code		in IGI_IAC_TRANSACTION_HEADERS.book_type_code%type,
293     				p_asset_id			in IGI_IAC_TRANSACTION_HEADERS.asset_id%type,
294     				p_revaluation_flag		in IGI_IAC_TRANSACTION_HEADERS.revaluation_type_flag%type,
295       				p_adjustment_status		in IGI_IAC_TRANSACTION_HEADERS.adjustment_status%type,
296 	    			p_category_id			in IGI_IAC_TRANSACTION_HEADERS.category_id%type,
297     				p_period_counter		in IGI_IAC_TRANSACTION_HEADERS.period_counter%type,
298     				p_event_id              in number
299     				) IS
300 
301 
302 
303 
304     l_rowid 	VARCHAR2(25);
305     l_mesg	VARCHAR2(500);
306     l_path_name VARCHAR2(150);
307 
308     BEGIN
309     l_path_name := g_path||'insert_data_trans_hdr';
310 
311 
312     	/* Call the TBH  for inserting data into IGI_IAC_TRANSACTION_HEADERS */
313 
314     IGI_IAC_TRANS_HEADERS_PKG.insert_row(
315     			x_rowid                  	    =>l_rowid,
316     			x_adjustment_id                     =>p_adjustment_id ,
317     			x_transaction_header_id             =>p_transaction_header_id ,
318     			x_adjustment_id_out                 =>p_adjustment_id_out,
319     			x_transaction_type_code             =>p_transaction_type_code	,
320     			x_transaction_date_entered          =>p_transaction_date_entered ,
321     			x_mass_refrence_id                  =>p_mass_reference_id,
322     			x_transaction_sub_type              =>null,
323     			x_book_type_code                    =>p_book_type_code,
324     			x_asset_id                          =>p_asset_id,
325     			x_category_id                       =>p_category_id,
326     			x_adj_deprn_start_date              =>null,
327     			x_revaluation_type_flag             =>p_revaluation_flag,
328     			x_adjustment_status                 =>p_adjustment_status,
329     			x_period_counter                    =>p_period_counter,
330     			x_mode                              =>'R',
331     			x_event_id                          =>p_event_id
332     				);
333 
334 
335      EXCEPTION
336         WHEN OTHERS THEN
337   		igi_iac_debug_pkg.debug_unexpected_msg(p_full_path => l_path_name);
338 
339 		l_mesg:=SQLERRM;
340 		FA_SRVR_MSG.Add_Message(
341 	                Calling_FN 	=> l_calling_function ,
342         	        Name 		=> 'IGI_IAC_EXCEPTION',
343         	        TOKEN1		=> 'PACKAGE',
344         	        VALUE1		=> 'RECLASS',
345         	        TOKEN2		=> 'ERROR_MESSAGE',
346         	        VALUE2		=> l_mesg,
347                         APPLICATION     => 'IGI');
348 
349 		rollback;
350 
351     END insert_data_trans_hdr;
352 
353 
354 
355 /*
356 +===============================================================================+
357 |	Procedure to insert data into IGI_IAC_DET_BALANCES			|
358 ================================================================================+
359 */
360 
361     PROCEDURE insert_data_det(p_adjustment_id	in IGI_IAC_DET_BALANCES.adjustment_id%type,
362     			      p_asset_id		in IGI_IAC_DET_BALANCES.asset_id%type,
363     			      p_distribution_id		in IGI_IAC_DET_BALANCES.distribution_id%type,
364     			      p_period_counter		in IGI_IAC_DET_BALANCES.period_counter%type,
365     			      p_book_type_code		in IGI_IAC_DET_BALANCES.book_type_code%type,
366     			      p_adjusted_cost		in IGI_IAC_DET_BALANCES.adjustment_cost%type,
367     			      p_net_book_value		in IGI_IAC_DET_BALANCES.net_book_value%type,
368     			      p_reval_reserve		in IGI_IAC_DET_BALANCES.reval_reserve_cost%type,
369     			      p_reval_reserve_gen_fund	in IGI_IAC_DET_BALANCES.reval_reserve_gen_fund%type,
370     			      p_reval_reserve_backlog	in IGI_IAC_DET_BALANCES.reval_reserve_backlog%type,
371                       p_reval_reserve_net in IGI_IAC_DET_BALANCES.reval_reserve_net%type,
372     			      p_op_acct			in IGI_IAC_DET_BALANCES.operating_acct_cost%type,
373                       p_op_acct_net			in IGI_IAC_DET_BALANCES.operating_acct_net%type,
374     			      p_deprn_reserve		in IGI_IAC_DET_BALANCES.deprn_reserve%type,
375     			      p_deprn_reserve_backlog 	in IGI_IAC_DET_BALANCES.deprn_reserve_backlog%type,
376     			      p_deprn_ytd		in IGI_IAC_DET_BALANCES.deprn_ytd%type,
377     			      p_deprn_period		in IGI_IAC_DET_BALANCES.deprn_period%type,
378     			      p_gen_fund_acc		in IGI_IAC_DET_BALANCES.general_fund_acc%type,
379     			      p_gen_fund_per		in IGI_IAC_DET_BALANCES.general_fund_acc%type,
380     			      p_current_reval_factor	in IGI_IAC_DET_BALANCES.current_reval_factor%type,
381     			      p_cumulative_reval_factor in IGI_IAC_DET_BALANCES.cumulative_reval_factor%type,
382     			      p_reval_flag		in IGI_IAC_DET_BALANCES.active_flag%type,
383     			      p_op_acct_ytd		in IGI_IAC_DET_BALANCES.operating_acct_ytd%type,
384     			      p_operating_acct_backlog  in IGI_IAC_DET_BALANCES.operating_acct_backlog%type,
385     			      p_last_reval_date		in IGI_IAC_DET_BALANCES.last_reval_date%type
386     			      ) IS
387 
388 	l_rowid VARCHAR2(25);
389 	l_mesg	VARCHAR2(500);
390         l_path_name VARCHAR2(150);
391     BEGIN
392         l_path_name := g_path||'insert_data_det';
393 
394      	/* Call to TBH for insert into IGI_IAC_DET_BALANCES */
395      	IGI_IAC_DET_BALANCES_PKG.insert_row(
396 			x_rowid       			=>l_rowid,
397     			x_adjustment_id  		=>p_adjustment_id,
398     			x_asset_id  			=>p_asset_id,
399     			x_distribution_id 		=>p_distribution_id,
400     			x_book_type_code 		=>p_book_type_code,
401     			x_period_counter		=>p_period_counter,
402     			x_adjustment_cost 		=>p_adjusted_cost,
403     			x_net_book_value 		=>p_net_book_value,
404     			x_reval_reserve_cost  		=>p_reval_reserve,
405                 x_reval_reserve_backlog  	=>p_reval_reserve_backlog,
406     			x_reval_reserve_gen_fund 	=>p_reval_reserve_gen_fund,
407                 -- Bug 2767992 Sekhar Modified for reval reserve net
408     			x_reval_reserve_net      	=>p_reval_reserve_net,
409     			x_operating_acct_cost  		=>p_op_acct,
410     			x_operating_acct_backlog  	=>p_operating_acct_backlog,
411     			x_operating_acct_net       	=>p_op_acct_net,
412     			x_operating_acct_ytd     	=>p_op_acct_ytd,
413     			x_deprn_period  		=>p_deprn_period,
414     			x_deprn_ytd        		=>p_deprn_ytd,
415     			x_deprn_reserve     		=>p_deprn_reserve,
416     			x_deprn_reserve_backlog		=>p_deprn_reserve_backlog,
417     			x_general_fund_per    		=>p_gen_fund_per,
418     			x_general_fund_acc              =>p_gen_fund_acc,
419     			x_last_reval_date               =>p_last_reval_date,
420     			x_current_reval_factor  	=>p_current_reval_factor,
421     			x_cumulative_reval_factor    	=>p_cumulative_reval_factor,
422     			x_active_flag   		=>p_reval_flag,
423     			x_mode   			=>'R'
424     						);
425 
426      	EXCEPTION
427     	WHEN OTHERS THEN
428   		igi_iac_debug_pkg.debug_unexpected_msg(p_full_path => l_path_name);
429 
430 		l_mesg:=SQLERRM;
431 		FA_SRVR_MSG.Add_Message(
432 	                Calling_FN 	=> l_calling_function ,
433         	        Name 		=> 'IGI_IAC_EXCEPTION',
434         	        TOKEN1		=> 'PACKAGE',
435         	        VALUE1		=> 'RECLASS',
436         	        TOKEN2		=> 'ERROR_MESSAGE',
437         	        VALUE2		=> l_mesg,
438                     	APPLICATION 	=> 'IGI');
439 
440 		rollback;
441     END insert_data_det;
442 
443 /*
444 +===============================================================================+
445 |	Procedure to prorate the amounts based on the units assigned		|
446 ================================================================================+
447 */
448     PROCEDURE Prorate_amount_for_dist(P_dist_id		in FA_DISTRIBUTION_HISTORY.DISTRIBUTION_ID%type,
449 			          	P_units_dist   		in number,
450 					P_units_total		in number,
451 					P_reval_reserve  	in out NOCOPY number,
452 					P_general_fund 		in out NOCOPY number,
453 					P_backlog_deprn 	in out NOCOPY number,
454 					P_deprn_reserve		in out NOCOPY number,
455 					P_adjusted_cost		in out NOCOPY number,
456 					P_net_book_value	in out NOCOPY number,
457 					P_deprn_per		in out NOCOPY number,
458 					P_op_acct		in out NOCOPY number,
459 					p_ytd_deprn		in out NOCOPY number,
460 					p_op_acct_ytd		in out NOCOPY number,
461 					p_event_id          in number
462 
463 			             ) IS
464 
465 	prorate_factor 	number;
466 	l_mesg		VARCHAR2(500);
467         l_path_name VARCHAR2(150);
468 
469     BEGIN
470 
471         l_path_name := g_path||'prorate_amount_for_dist';
472 
473 	/*Prorate the various amounts between for the given distribution*/
474 
475 	Prorate_factor          := p_units_dist/P_units_total;
476 	P_reval_reserve         := P_reval_reserve* Prorate_factor  ;
477 	P_general_fund          := P_general_fund * Prorate_factor ;
478 	P_backlog_deprn         := P_backlog_deprn* Prorate_factor ;
479 	P_deprn_reserve         := P_deprn_reserve* Prorate_factor ;
480 	P_adjusted_cost         := P_adjusted_cost* Prorate_factor ;
481 	P_net_book_value        := P_net_book_value* Prorate_factor  ;
482 	P_deprn_per             := P_deprn_per* Prorate_factor;
483 	P_op_acct               := p_op_acct*Prorate_factor;
484 	P_ytd_deprn             := p_ytd_deprn*Prorate_factor;
485 	P_op_acct_ytd           := p_op_acct_ytd*Prorate_factor;
486 
487     EXCEPTION
488     	WHEN OTHERS THEN
489   		igi_iac_debug_pkg.debug_unexpected_msg(p_full_path => l_path_name);
490 
491 		l_mesg:=SQLERRM;
492 		FA_SRVR_MSG.Add_Message(
493 	                Calling_FN 	=> l_calling_function ,
494         	        Name 		=> 'IGI_IAC_EXCEPTION',
495         	        TOKEN1		=> 'PACKAGE',
496         	        VALUE1		=> 'RECLASS',
497         	        TOKEN2		=> 'ERROR_MESSAGE',
498         	        VALUE2		=> l_mesg,
499                     	APPLICATION 	=> 'IGI');
500 
501     END prorate_amount_for_dist;
502 
503 
504     procedure create_acctg_entry ( l_ccid         in number
505                                  , p_amount          in number
506                                  , l_adjust_type  in varchar2
507                                  , l_cr_dr_flag  in varchar2
508                                  , l_set_of_books_id in number
509                                  , fp_det_balances   in igi_iac_det_balances%rowtype
510 				 , l_adjust_offset_type in varchar2 Default Null
511 				 , l_Report_CCID	in varchar2 Default Null
512 				 , p_event_id       in number
513                                  )
514     is
515        l_rowid varchar2(30);
516        l_units_assigned number;
517        l_path_name VARCHAR2(150);
518     begin
519        l_rowid := null;
520        l_path_name := g_path||'create_acctg_entry';
521        if p_amount = 0 then
522   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
523 		     p_full_path => l_path_name,
524 		     p_string => '+amount is 0, accounting entries skipped');
525 
526           return;
527        end if;
528 
529        select units_assigned
530        into   l_units_assigned
531        from   fa_distribution_history
532        where  book_type_code = fp_det_balances.book_type_code
533          and  asset_id       = fp_det_balances.asset_id
534          and  distribution_id = fp_det_balances.distribution_id
535        ;
536 
537         IGI_IAC_ADJUSTMENTS_PKG.insert_row (
538             x_rowid                   => l_rowid,
539             x_adjustment_id           => fp_det_balances.adjustment_id,
540             x_book_type_code          => fp_det_balances.book_type_code,
541             x_code_combination_id     => l_ccid,
542             x_set_of_books_id         => l_set_of_books_id,
543             x_dr_cr_flag              => l_cr_dr_flag,
544             x_amount                  => p_amount,
545             x_adjustment_type         => l_adjust_type,
546             x_transfer_to_gl_flag     => 'Y',
547             x_units_assigned          => l_units_assigned,
548             x_asset_id                => fp_det_balances.asset_id,
549             x_distribution_id         => fp_det_balances.distribution_id,
550             x_period_counter          => fp_det_balances.period_counter,
551 	    x_adjustment_offset_type  => l_adjust_offset_type,
552 	    x_report_ccid             => l_report_ccid,
553             x_mode                    => 'R',
554             x_event_id                => p_event_id
555             ) ;
556 
557      end;
558 
559     function create_iac_acctg
560          ( fp_det_balances in IGI_IAC_DET_BALANCES%ROWTYPE
561           , fp_create_acctg_flag in boolean
562           , fp_adjustement_type in Varchar2
563        	 , l_Adjust_offset_type in varchar2 Default Null
564 	 , l_Report_CCID	in varchar2 Default Null
565 	 , p_event_id       in number
566           )
567     return boolean is
568       l_rowid rowid;
569       l_sob_id number;
570       l_coa_id number;
571       l_currency varchar2(30);
572       l_precision number;
573       l_dr_ccid  gl_code_combinations.code_combination_id%type;
574       l_cr_ccid  gl_code_combinations.code_combination_id%type;
575       l_revl_rsv_ccid gl_code_combinations.code_combination_id%type;
576       l_blog_rsv_ccid gl_code_combinations.code_combination_id%TYPE;
577       l_op_exp_ccid   gl_code_combinations.code_combination_id%TYPE;
578       l_gen_fund_ccid gl_code_combinations.code_combination_id%TYPE;
579       l_asset_cost_ccid gl_code_combinations.code_combination_id%TYPE;
580       l_deprn_rsv_ccid gl_code_combinations.code_combination_id%TYPE;
581       l_deprn_exp_ccid gl_code_combinations.code_combination_id%TYPE;
582       l_cr_dr_flag_cost varchar(2);
583       l_cr_dr_flag_reval_reserve varchar(2);
584       l_cr_dr_flag_gen_fund varchar(2);
585       l_cr_dr_flag_blog varchar(2);
586       l_cr_dr_flag_op varchar(2);
587       l_cr_dr_flag_exp varchar(2);
588       l_cr_dr_flag_reserve varchar(2);
589       l_path_name VARCHAR2(150);
590 
591       procedure check_ccid ( p_ccid_desc in varchar2) is
592   	   l_path_name VARCHAR2(150);
593       begin
594   	    l_path_name := g_path||'check_ccid';
595   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
596 		     	p_full_path => l_path_name,
597 		     	p_string => '+acctg creation for '||p_ccid_desc||' failed');
598   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
599 		     	p_full_path => l_path_name,
600 		     	p_string => 'error create_iac_acctg');
601       end;
602 
603       begin
604         l_path_name := g_path||'create_iac_acctg';
605 
606   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
607 		     	p_full_path => l_path_name,
608 		     	p_string => 'begin create_iac_acctg');
609   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
610 		     	p_full_path => l_path_name,
611 		     	p_string => '+        Det Balances');
612   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
613 		     	p_full_path => l_path_name,
614 		     	p_string => '+        book type code'||fp_det_balances.book_type_code);
615   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
616 		     	p_full_path => l_path_name,
617 		     	p_string => '+        asset id'||fp_det_balances.asset_id);
618   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
619 		     	p_full_path => l_path_name,
620 		     	p_string => '+        distribution id '||fp_det_balances.distribution_id);
621   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
622 		     	p_full_path => l_path_name,
623 		     	p_string => '+        adjustment id '||fp_det_balances.adjustment_id);
624   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
625 		     	p_full_path => l_path_name,
626 		     	p_string => '+        reval reserve '||fp_det_balances.reval_reserve_cost);
627   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
628 		     	p_full_path => l_path_name,
629 		     	p_string => '+        reserve backlog '||fp_det_balances.reval_reserve_backlog);
630   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
631 		     	p_full_path => l_path_name,
632 		     	p_string => '+        gen fund'||fp_det_balances.reval_reserve_gen_fund);
633   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
634 		     	p_full_path => l_path_name,
635 		     	p_string => '+        acct cost'||fp_det_balances.operating_acct_cost);
636   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
637 		     	p_full_path => l_path_name,
638 		     	p_string => '+        op acct backlog'||fp_det_balances.operating_acct_backlog);
639   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
640 		     	p_full_path => l_path_name,
641 		     	p_string => '+        deprn ytd'||fp_det_balances.deprn_ytd);
642   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
643 		     	p_full_path => l_path_name,
644 		     	p_string => '+        rserv back deprn '||fp_det_balances.deprn_reserve_backlog);
645 
646 
647        if not fp_create_acctg_flag then
648   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
649 		     p_full_path => l_path_name,
650 		     p_string => '+acctg creation not allowed');
651   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
652 		     p_full_path => l_path_name,
653 		     p_string => 'end create_iac_acctg');
654 
655           return true;
656        end if;
657 
658        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
659 		     p_full_path => l_path_name,
660 		     p_string => '+acctg creation get gl information');
661 
662        if not IGI_IAC_COMMON_UTILS.GET_BOOK_GL_INFO
663               ( X_BOOK_TYPE_CODE      => fp_det_balances.book_type_code
664               , SET_OF_BOOKS_ID       => l_sob_id
665               , CHART_OF_ACCOUNTS_ID  => l_coa_id
666               , CURRENCY              => l_currency
667               , PRECISION             => l_precision
668               )
669        then
670   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
671 		     	p_full_path => l_path_name,
672 		     	p_string => '+acctg creation unable to get gl info');
673   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
674 		     	p_full_path => l_path_name,
675 		     	p_string => 'end create_iac_acctg');
676 
677           return false;
678        end if;
679        --
680        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
681 		     p_full_path => l_path_name,
682 		     p_string => '+acctg creation get all accounts');
683        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
684 		     p_full_path => l_path_name,
685 		     p_string => '+distribution id '|| fp_det_balances.distribution_id );
686 
687        IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
688                     ( X_book_type_code =>  fp_det_balances.book_type_code
689                     , X_asset_id       =>  fp_det_balances.asset_id
690                     , X_distribution_id => fp_det_balances.distribution_id
691                     ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
692                     ,X_calling_function => 'RECLASS'
693                     , X_account_type    => 'REVAL_RESERVE_ACCT'
694                     , account_ccid      => l_revl_rsv_ccid
695                     )
696        THEN
697           check_ccid ( 'reval reserve');
698           return false;
699        END IF;
700       IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
701                     ( X_book_type_code => fp_det_balances.book_type_code
702                     , X_asset_id       => fp_det_balances.asset_id
703                     , X_distribution_id => fp_det_balances.distribution_id
704                    ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
705                     ,X_calling_function => 'RECLASS'
706                     , X_account_type    => 'BACKLOG_DEPRN_RSV_ACCT'
707                     , account_ccid      => l_blog_rsv_ccid
708                     )
709        THEN
710           check_ccid ( 'backlog deprn reserve');
711           return false;
712        END IF;
713        IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
714                     ( X_book_type_code => fp_det_balances.book_type_code
715                     , X_asset_id       => fp_det_balances.asset_id
716                     , X_distribution_id => fp_det_balances.distribution_id
717                     ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
718                     ,X_calling_function => 'RECLASS'
719                     , X_account_type    => 'OPERATING_EXPENSE_ACCT'
720                     , account_ccid      => l_op_exp_ccid
721                     )
722        THEN
723           check_ccid ( 'operating account');
724           return false;
725        END IF;
726         IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
727                     ( X_book_type_code => fp_det_balances.book_type_code
728                     , X_asset_id       => fp_det_balances.asset_id
729                     , X_distribution_id => fp_det_balances.distribution_id
730                     ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
731                      ,X_calling_function => 'RECLASS'
732                     , X_account_type    => 'GENERAL_FUND_ACCT'
733                     , account_ccid      => l_gen_fund_ccid
734                     )
735        THEN
736           check_ccid ( 'general fund account');
737           return false;
738        END IF;
739         IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
740                     ( X_book_type_code => fp_det_balances.book_type_code
741                     , X_asset_id       => fp_det_balances.asset_id
742                     , X_distribution_id => fp_det_balances.distribution_id
743                     ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
744                     ,X_calling_function => 'RECLASS'
745                     , X_account_type    => 'ASSET_COST_ACCT'
746                     , account_ccid      => l_asset_cost_ccid
747                     )
748        THEN
749           check_ccid ( 'asset cost account');
750           return false;
751        END IF;
752        IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
753                     ( X_book_type_code => fp_det_balances.book_type_code
754                     , X_asset_id       => fp_det_balances.asset_id
755                     , X_distribution_id => fp_det_balances.distribution_id
756                     ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
757                     ,X_calling_function => 'RECLASS'
758                     , X_account_type    => 'DEPRN_RESERVE_ACCT'
759                     , account_ccid      => l_deprn_rsv_ccid
760                    )
761        THEN
762           check_ccid ( 'deprn reserve account');
763           return false;
764        END IF;
765        IF NOT IGI_IAC_COMMON_UTILS.get_account_ccid
766                     ( X_book_type_code => fp_det_balances.book_type_code
767                     , X_asset_id       => fp_det_balances.asset_id
768                     , X_distribution_id => fp_det_balances.distribution_id
769                     ,X_TRANSACTION_HEADER_ID => l_trans_rec.TRANSACTION_HEADER_ID
770                     ,X_calling_function => 'RECLASS'
771                     , X_account_type    => 'DEPRN_EXPENSE_ACCT'
772                     , account_ccid      => l_deprn_exp_ccid
773                     )
774        THEN
775           check_ccid ( 'deprn reserve account');
776           return false;
777        END IF;
778 
779        begin
780         If fp_adjustement_type = 'OLD' Then
781 
782   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
783 		     p_full_path => l_path_name,
784 		     p_string => '+acctg creation cost vs reval reserve');
785 
786           /*create_acctg_entry (  l_dr_ccid        => l_asset_cost_ccid
787                              , l_cr_ccid         => l_revl_rsv_ccid
788                              , p_amount          => fp_det_balances.reval_reserve_cost
789                              , l_dr_adjust_type  => 'COST'
790                              , l_cr_adjust_type  => 'REVAL RESERVE'
791                              , l_set_of_books_id => l_sob_id
792                              , fp_det_balances   => fp_det_balances
793                              );*/
794 
795              create_acctg_entry (  l_ccid            => l_asset_cost_ccid
796                                  , p_amount          => fp_det_balances.reval_reserve_cost
797                                  , l_adjust_type     => 'COST'
798                                  , l_cr_dr_flag      => 'CR'
799                                  , l_set_of_books_id => l_sob_id
800                                 , fp_det_balances   => fp_det_balances
801 				, l_adjust_offset_type	=> 'REVAL RESERVE'
802 				, l_report_ccid	=> l_revl_rsv_ccid
803 				, p_event_id    => p_event_id
804                                 );
805 
806             create_acctg_entry (  l_ccid             => l_revl_rsv_ccid
807                                 , p_amount          => fp_det_balances.reval_reserve_cost
808                                 , l_adjust_type     => 'REVAL RESERVE'
809                                 , l_cr_dr_flag      => 'DR'
810                                 , l_set_of_books_id => l_sob_id
811                                 , fp_det_balances   => fp_det_balances
812 				, l_adjust_offset_type	=> 'COST'
813 				, l_report_ccid	=> Null
814 				, p_event_id    => p_event_id
815                               );
816 
817   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
818 		     p_full_path => l_path_name,
819 		     p_string => '+acctg creation reval reserve vs backlog reserve');
820 
821          /*create_acctg_entry (  l_dr_ccid   =>    l_revl_rsv_ccid
822                              , l_cr_ccid   =>    l_blog_rsv_ccid
823                              , p_amount    =>    fp_det_balances.reval_reserve_backlog
824                              , l_dr_adjust_type  => 'REVAL RESERVE'
825                              , l_cr_adjust_type  => 'BL RESERVE'
826                              , l_set_of_books_id => l_sob_id
827                              , fp_det_balances   => fp_det_balances
828                              );*/
829           create_acctg_entry (  l_ccid             => l_revl_rsv_ccid
830                                 , p_amount          => fp_det_balances.reval_reserve_backlog
831                                 , l_adjust_type     => 'REVAL RESERVE'
832                                 , l_cr_dr_flag      => 'CR'
833                                 , l_set_of_books_id => l_sob_id
834                                 , fp_det_balances   => fp_det_balances
835 				, l_adjust_offset_type	=> 'BL RESERVE'
836 				, l_report_ccid	=> Null
837 				, p_event_id    => p_event_id
838                               );
839 
840          create_acctg_entry (  l_ccid               => l_blog_rsv_ccid
841                                 , p_amount          => fp_det_balances.reval_reserve_backlog
842                                 , l_adjust_type     => 'BL RESERVE'
843                                 , l_cr_dr_flag      => 'DR'
844                                 , l_set_of_books_id => l_sob_id
845                                 , fp_det_balances   => fp_det_balances
846 				, l_adjust_offset_type	=> 'REVAL RESERVE'
847 				, l_report_ccid	=> l_revl_rsv_ccid
848 				, p_event_id    => p_event_id
849                               );
850 
851   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
852 		     p_full_path => l_path_name,
853 		     p_string => '+acctg creation reval reserve vs gen fund');
854 
855 
856          /*create_acctg_entry (  l_dr_ccid   =>    l_revl_rsv_ccid
857                              , l_cr_ccid   =>    l_gen_fund_ccid
858                              , p_amount    =>    fp_det_balances.reval_reserve_gen_fund
859                              , l_dr_adjust_type  => 'REVAL RESERVE'
860                              , l_cr_adjust_type  => 'GENERAL FUND'
861                              , l_set_of_books_id => l_sob_id
862                              , fp_det_balances   => fp_det_balances
863                              );*/
864           create_acctg_entry (  l_ccid             => l_revl_rsv_ccid
865                                 , p_amount          => fp_det_balances.reval_reserve_gen_fund
866                                 , l_adjust_type     => 'REVAL RESERVE'
867                                 , l_cr_dr_flag      => 'CR'
868                                 , l_set_of_books_id => l_sob_id
869                                 , fp_det_balances   => fp_det_balances
870 				, l_adjust_offset_type	=> 'GENERAL FUND'
871 				, l_report_ccid	=> Null
872 				, p_event_id    => p_event_id
873                                    );
874 
875          create_acctg_entry (  l_ccid               => l_gen_fund_ccid
876                                 , p_amount          => fp_det_balances.reval_reserve_gen_fund
877                                 , l_adjust_type     => 'GENERAL FUND'
878                                 , l_cr_dr_flag      => 'DR'
879                                 , l_set_of_books_id => l_sob_id
880                                 , fp_det_balances   => fp_det_balances
881 				, l_adjust_offset_type	=> 'REVAL RESERVE'
882 				, l_report_ccid	=> l_revl_rsv_ccid
883 				, p_event_id    => p_event_id
884                               );
885 
886   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
887 		     p_full_path => l_path_name,
888 		     p_string => '+acctg creation op account vs cost');
889 
890          /*create_acctg_entry (  l_dr_ccid   =>    l_op_exp_ccid
891                              , l_cr_ccid   =>    l_asset_cost_ccid
892                              , p_amount    =>    fp_det_balances.operating_acct_cost
893                              , l_dr_adjust_type  => 'OP ACCOUNT'
894                              , l_cr_adjust_type  => 'COST'
895                              , l_set_of_books_id => l_sob_id
896                              , fp_det_balances   => fp_det_balances
897                              );*/
898              IF Diff_price_index_flag Then
899                 create_acctg_entry (  l_ccid               => l_op_exp_ccid
900                                 , p_amount          => fp_det_balances.operating_acct_cost
901                                 , l_adjust_type     => 'OP EXPENSE'
902                                 , l_cr_dr_flag      => 'DR'
903                                 , l_set_of_books_id => l_sob_id
904                                 , fp_det_balances   => fp_det_balances
905 				, l_adjust_offset_type	=> 'COST'
906 				, l_report_ccid	=> Null
907 				, p_event_id    => p_event_id
908                               );
909               End if;
910           create_acctg_entry (  l_ccid            => l_asset_cost_ccid
911                                  , p_amount          => fp_det_balances.operating_acct_cost
912                                  , l_adjust_type     => 'COST'
913                                  , l_cr_dr_flag      => 'CR'
914                                  , l_set_of_books_id => l_sob_id
915                                 , fp_det_balances   => fp_det_balances
916 				, l_adjust_offset_type	=> 'OP EXPENSE'
917 				, l_report_ccid	=> l_op_exp_ccid
918 				, p_event_id    => p_event_id
919                                 );
920 
921   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
922 		     p_full_path => l_path_name,
923 		     p_string => '+acctg creation backlog vs op account');
924 
925          /*create_acctg_entry (  l_dr_ccid   =>    l_blog_rsv_ccid
926                              , l_cr_ccid   =>    l_op_exp_ccid
927                              , p_amount    =>    fp_det_balances.operating_acct_backlog
928                              , l_dr_adjust_type  => 'BL RESERVE'
929                              , l_cr_adjust_type  => 'OP ACCOUNT'
930                              , l_set_of_books_id => l_sob_id
931                              , fp_det_balances   => fp_det_balances
932                              );*/
933           create_acctg_entry (  l_ccid               => l_blog_rsv_ccid
934                                 , p_amount          => fp_det_balances.operating_acct_backlog
935                                 , l_adjust_type     => 'BL RESERVE'
936                                 , l_cr_dr_flag      => 'DR'
937                                 , l_set_of_books_id => l_sob_id
938                                 , fp_det_balances   => fp_det_balances
939 				, l_adjust_offset_type	=> 'OP EXPENSE'
940 				, l_report_ccid	=> l_op_exp_ccid
941 				, p_event_id    => p_event_id
942                               );
943 
944              IF Diff_price_index_flag Then
945               create_acctg_entry (  l_ccid               => l_op_exp_ccid
946                                 , p_amount          => fp_det_balances.operating_acct_backlog
947                                 , l_adjust_type     => 'OP EXPENSE'
948                                 , l_cr_dr_flag      => 'CR'
949                                 , l_set_of_books_id => l_sob_id
950                                 , fp_det_balances   => fp_det_balances
951 				, l_adjust_offset_type	=> 'BL RESERVE'
952 				, l_report_ccid	=> Null
953 				, p_event_id    => p_event_id
954                               );
955              End if;
956 
957   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
958 		     p_full_path => l_path_name,
959 		     p_string => '+acctg creation deprn reserve vs deprn expense');
960 
961             create_acctg_entry (  l_ccid            => l_deprn_rsv_ccid
962                                 , p_amount          => fp_det_balances.deprn_reserve
963                                 , l_adjust_type     => 'RESERVE'
964                                 , l_cr_dr_flag      => 'DR'
965                                 , l_set_of_books_id => l_sob_id
966                                 , fp_det_balances   => fp_det_balances
967 				, l_adjust_offset_type	=> 'EXPENSE'
968 				, l_report_ccid	=> Null
969 				, p_event_id    => p_event_id
970                               );
971 
972 
973 
974           /* bug 2439006  additional dep_resrver account created old category depreciation expense negation
975             entry to the new category*/
976               IF Diff_price_index_flag Then
977 
978                          create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
979                                 , p_amount          => fp_det_balances.deprn_reserve
980                                 , l_adjust_type     => 'EXPENSE'
981                                 , l_cr_dr_flag      => 'CR'
982                                 , l_set_of_books_id => l_sob_id
983                                 , fp_det_balances   => fp_det_balances
984 				, l_adjust_offset_type	=> 'RESERVE'
985 				, l_report_ccid	=> Null
986 				, p_event_id    => p_event_id
987                               );
988 
989   	    		 igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
990 		     			p_full_path => l_path_name,
991 		     			p_string => '+acctg creation depreciation expenese for old ');
992 
993                           create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
994                                 , p_amount          => fp_det_balances.deprn_reserve
995                                 , l_adjust_type     => 'EXPENSE'
996                                 , l_cr_dr_flag      => 'DR'
997                                 , l_set_of_books_id => l_sob_id
998                                 , fp_det_balances   => fp_det_balances
999 				, l_adjust_offset_type	=> 'RESERVE'
1000 				, l_report_ccid	=> Null
1001 				, p_event_id    => p_event_id
1002                               );
1003 
1004                         l_deprn_reserve_amount:=  fp_det_balances.deprn_reserve;
1005                   End if;
1006 
1007           /* bug 2439006  YTD not required now beacuse of above accounting entry*/
1008 
1009 /*
1010                  debug(0,'+acctg creation depreciation expenese for YTD');
1011                            create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
1012                                 , p_amount          => fp_det_balances.deprn_ytd
1013                                 , l_adjust_type     => 'EXPENSE'
1014                                 , l_cr_dr_flag      => 'DR'
1015                                 , l_set_of_books_id => l_sob_id
1016                                 , fp_det_balances   => fp_det_balances
1017                               );*/
1018 
1019 
1020     /*         debug(0,'+acctg creation backlog reserve vs deprn reserve');
1021 
1022             create_acctg_entry (  l_ccid               => l_blog_rsv_ccid
1023                                 , p_amount          => fp_det_balances.reval_reserve_backlog
1024                                 , l_adjust_type     => 'BL RESERVE'
1025                                 , l_cr_dr_flag      => 'CR'
1026                                 , l_set_of_books_id => l_sob_id
1027                                 , fp_det_balances   => fp_det_balances
1028                               );
1029 
1030                         create_acctg_entry (  l_ccid            => l_deprn_rsv_ccid
1031                                 , p_amount          => fp_det_balances.reval_reserve_backlog
1032                                 , l_adjust_type     => 'RESERVE'
1033                                 , l_cr_dr_flag      => 'DR'
1034                                 , l_set_of_books_id => l_sob_id
1035                                 , fp_det_balances   => fp_det_balances
1036                               );*/
1037            --        end if;
1038 
1039            elsif  fp_adjustement_type = 'NEW' THEN
1040 
1041                IF Diff_price_index_flag Then
1042 
1043                       /* bug 2439006  YTD not required now beacuse of above accounting entry*/
1044     /*                 debug(0,'+acctg creation depreciation expenese for YTD');
1045                            create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
1046                                 , p_amount          => fp_det_balances.deprn_ytd
1047                                 , l_adjust_type     => 'EXPENSE'
1048                                 , l_cr_dr_flag      => 'CR'
1049                                 , l_set_of_books_id => l_sob_id
1050                                 , fp_det_balances   => fp_det_balances
1051                               );*/
1052 
1053           /* bug 2439006  additional dep_resrver account created old category depreciation expense negation
1054             entry to the new category*/
1055 
1056   	    	       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1057 		     			p_full_path => l_path_name,
1058 		     			p_string => '+acctg creation depreciation expenese for new ');
1059 
1060                        create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
1061                                 , p_amount          =>  l_deprn_reserve_amount
1062                                 , l_adjust_type     => 'EXPENSE'
1063                                 , l_cr_dr_flag      => 'CR'
1064                                 , l_set_of_books_id => l_sob_id
1065                                 , fp_det_balances   => fp_det_balances
1066 				, l_adjust_offset_type	=> 'RESERVE'
1067 				, l_report_ccid	=> Null
1068 				, p_event_id    => p_event_id
1069                               );
1070 
1071 
1072                 ELSE
1073 
1074   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1075 		     p_full_path => l_path_name,
1076 		     p_string => '+acctg creation cost vs reval reserve');
1077   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1078 		     p_full_path => l_path_name,
1079 		     p_string => '+acctg creation cost vs reval reserve');
1080 
1081           /*create_acctg_entry (  l_dr_ccid        => l_asset_cost_ccid
1082                              , l_cr_ccid         => l_revl_rsv_ccid
1083                              , p_amount          => fp_det_balances.reval_reserve_cost
1084                              , l_dr_adjust_type  => 'COST'
1085                              , l_cr_adjust_type  => 'REVAL RESERVE'
1086                              , l_set_of_books_id => l_sob_id
1087                              , fp_det_balances   => fp_det_balances
1088                              );*/
1089 
1090              create_acctg_entry (  l_ccid            => l_asset_cost_ccid
1091                                  , p_amount          => fp_det_balances.reval_reserve_cost
1092                                  , l_adjust_type     => 'COST'
1093                                  , l_cr_dr_flag      => 'DR'
1094                                  , l_set_of_books_id => l_sob_id
1095                                 , fp_det_balances   => fp_det_balances
1096 				, l_adjust_offset_type	=> 'REVAL RESERVE'
1097 				, l_report_ccid	=> l_revl_rsv_ccid
1098 				, p_event_id    => p_event_id
1099                                 );
1100             create_acctg_entry (  l_ccid             => l_revl_rsv_ccid
1101                                 , p_amount          => fp_det_balances.reval_reserve_cost
1102                                 , l_adjust_type     => 'REVAL RESERVE'
1103                                 , l_cr_dr_flag      => 'CR'
1104                                 , l_set_of_books_id => l_sob_id
1105                                 , fp_det_balances   => fp_det_balances
1106 				, l_adjust_offset_type	=> 'COST'
1107 				, l_report_ccid	=> Null
1108 				, p_event_id    => p_event_id
1109                               );
1110 
1111   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1112 		     p_full_path => l_path_name,
1113 		     p_string => '+acctg creation reval reserve vs backlog reserve');
1114 
1115          /*create_acctg_entry (  l_dr_ccid   =>    l_revl_rsv_ccid
1116                              , l_cr_ccid   =>    l_blog_rsv_ccid
1117                              , p_amount    =>    fp_det_balances.reval_reserve_backlog
1118                              , l_dr_adjust_type  => 'REVAL RESERVE'
1119                              , l_cr_adjust_type  => 'BL RESERVE'
1120                              , l_set_of_books_id => l_sob_id
1121                              , fp_det_balances   => fp_det_balances
1122                              );*/
1123           create_acctg_entry (  l_ccid             => l_revl_rsv_ccid
1124                                 , p_amount          => fp_det_balances.reval_reserve_backlog
1125                                 , l_adjust_type     => 'REVAL RESERVE'
1126                                 , l_cr_dr_flag      => 'DR'
1127                                 , l_set_of_books_id => l_sob_id
1128                                 , fp_det_balances   => fp_det_balances
1129 				, l_adjust_offset_type	=> 'BL RESERVE'
1130 				, l_report_ccid	=> Null
1131 				, p_event_id    => p_event_id
1132                               );
1133 
1134          create_acctg_entry (  l_ccid               => l_blog_rsv_ccid
1135                                 , p_amount          => fp_det_balances.reval_reserve_backlog
1136                                 , l_adjust_type     => 'BL RESERVE'
1137                                 , l_cr_dr_flag      => 'CR'
1138                                 , l_set_of_books_id => l_sob_id
1139                                 , fp_det_balances   => fp_det_balances
1140 				, l_adjust_offset_type	=> 'REVAL RESERVE'
1141 				, l_report_ccid	=> l_revl_rsv_ccid
1142 				, p_event_id    => p_event_id
1143                               );
1144 
1145   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1146 		     p_full_path => l_path_name,
1147 		     p_string => '+acctg creation reval reserve vs gen fund');
1148 
1149          /*create_acctg_entry (  l_dr_ccid   =>    l_revl_rsv_ccid
1150                              , l_cr_ccid   =>    l_gen_fund_ccid
1151                              , p_amount    =>    fp_det_balances.reval_reserve_gen_fund
1152                              , l_dr_adjust_type  => 'REVAL RESERVE'
1153                              , l_cr_adjust_type  => 'GENERAL FUND'
1154                              , l_set_of_books_id => l_sob_id
1155                              , fp_det_balances   => fp_det_balances
1156                              );*/
1157           create_acctg_entry (  l_ccid             => l_revl_rsv_ccid
1158                                 , p_amount          => fp_det_balances.reval_reserve_gen_fund
1159                                 , l_adjust_type     => 'REVAL RESERVE'
1160                                 , l_cr_dr_flag      => 'DR'
1161                                 , l_set_of_books_id => l_sob_id
1162                                 , fp_det_balances   => fp_det_balances
1163 				, l_adjust_offset_type	=> 'GENERAL FUND'
1164 				, l_report_ccid	=> Null
1165 				, p_event_id    => p_event_id
1166                                    );
1167 
1168          create_acctg_entry (  l_ccid               => l_gen_fund_ccid
1169                                 , p_amount          => fp_det_balances.reval_reserve_gen_fund
1170                                 , l_adjust_type     => 'GENERAL FUND'
1171                                 , l_cr_dr_flag      => 'CR'
1172                                 , l_set_of_books_id => l_sob_id
1173                                 , fp_det_balances   => fp_det_balances
1174 				, l_adjust_offset_type	=> 'REVAL RESERVE'
1175 				, l_report_ccid	=> l_revl_rsv_ccid
1176 				, p_event_id    => p_event_id
1177                               );
1178 
1179   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1180 		     p_full_path => l_path_name,
1181 		     p_string => '+acctg creation op account vs cost');
1182 
1183          /*create_acctg_entry (  l_dr_ccid   =>    l_op_exp_ccid
1184                              , l_cr_ccid   =>    l_asset_cost_ccid
1185                              , p_amount    =>    fp_det_balances.operating_acct_cost
1186                              , l_dr_adjust_type  => 'OP ACCOUNT'
1187                              , l_cr_adjust_type  => 'COST'
1188                              , l_set_of_books_id => l_sob_id
1189                              , fp_det_balances   => fp_det_balances
1190                              );*/
1191 
1192          /*  create_acctg_entry (  l_ccid               => l_op_exp_ccid
1193                                 , p_amount          => fp_det_balances.operating_acct_cost
1194                                 , l_adjust_type     => 'OP EXPENSE'
1195                                 , l_cr_dr_flag      => 'CR'
1196                                 , l_set_of_books_id => l_sob_id
1197                                 , fp_det_balances   => fp_det_balances
1198                               );*/
1199 
1200           create_acctg_entry (  l_ccid            => l_asset_cost_ccid
1201                                  , p_amount          => fp_det_balances.operating_acct_cost
1202                                  , l_adjust_type     => 'COST'
1203                                  , l_cr_dr_flag      => 'DR'
1204                                  , l_set_of_books_id => l_sob_id
1205                                 , fp_det_balances   => fp_det_balances
1206 				, l_adjust_offset_type	=> 'OP EXPENSE'
1207 				, l_report_ccid	=> l_op_exp_ccid,
1208 				p_event_id    => p_event_id
1209                                 );
1210 
1211   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1212 		     p_full_path => l_path_name,
1213 		     p_string => '+acctg creation backlog vs op account');
1214 
1215          /*create_acctg_entry (  l_dr_ccid   =>    l_blog_rsv_ccid
1216                              , l_cr_ccid   =>    l_op_exp_ccid
1217                              , p_amount    =>    fp_det_balances.operating_acct_backlog
1218                              , l_dr_adjust_type  => 'BL RESERVE'
1219                              , l_cr_adjust_type  => 'OP EXPENSE'
1220                              , l_set_of_books_id => l_sob_id
1221                              , fp_det_balances   => fp_det_balances
1222                              );*/
1223           create_acctg_entry (  l_ccid               => l_blog_rsv_ccid
1224                                 , p_amount          => fp_det_balances.operating_acct_backlog
1225                                 , l_adjust_type     => 'BL RESERVE'
1226                                 , l_cr_dr_flag      => 'CR'
1227                                 , l_set_of_books_id => l_sob_id
1228                                 , fp_det_balances   => fp_det_balances
1229 				, l_adjust_offset_type	=> 'OP EXPENSE'
1230 				, l_report_ccid	=> l_op_exp_ccid
1231 				, p_event_id    => p_event_id
1232                               );
1233 
1234 
1235         /*   create_acctg_entry (  l_ccid               => l_op_exp_ccid
1236                                 , p_amount          => fp_det_balances.operating_acct_backlog
1237                                 , l_adjust_type     => 'OP EXPENSE'
1238                                 , l_cr_dr_flag      => 'DR'
1239                                 , l_set_of_books_id => l_sob_id
1240                                 , fp_det_balances   => fp_det_balances
1241                               );*/
1242 
1243     -- removing these entries as per bug 2483321
1244   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1245 		     p_full_path => l_path_name,
1246 		     p_string => '+acctg creation deprn reserve vs deprn expense');
1247 
1248             create_acctg_entry (  l_ccid            => l_deprn_rsv_ccid
1249                                 , p_amount          => fp_det_balances.deprn_reserve
1250                                 , l_adjust_type     => 'RESERVE'
1251                                 , l_cr_dr_flag      => 'CR'
1252                                 , l_set_of_books_id => l_sob_id
1253                                 , fp_det_balances   => fp_det_balances
1254 				, l_adjust_offset_type	=> 'EXPENSE'
1255 				, l_report_ccid	=> Null
1256 				, p_event_id    => p_event_id
1257                               );
1258           /* create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
1259                                 , p_amount          => fp_det_balances.deprn_reserve
1260                                 , l_adjust_type     => 'EXPENSE'
1261                                 , l_cr_dr_flag      => 'DR'
1262                                 , l_set_of_books_id => l_sob_id
1263                                 , fp_det_balances   => fp_det_balances
1264                               );*/
1265 
1266         /*    debug(0,'+acctg creation depreciation expenese for YTD');
1267                            create_acctg_entry (  l_ccid               =>  l_deprn_exp_ccid
1268                                 , p_amount          => fp_det_balances.deprn_ytd
1269                                 , l_adjust_type     => 'EXPENSE'
1270                                 , l_cr_dr_flag      => 'CR'
1271                                 , l_set_of_books_id => l_sob_id
1272                                 , fp_det_balances   => fp_det_balances
1273                               );*/
1274 
1275 
1276     /*     debug(0,'+acctg creation backlog reserve vs deprn reserve');
1277 
1278             create_acctg_entry (  l_ccid               => l_blog_rsv_ccid
1279                                 , p_amount          => fp_det_balances.reval_reserve_backlog
1280                                 , l_adjust_type     => 'BL RESERVE'
1281                                 , l_cr_dr_flag      => 'CR'
1282                                 , l_set_of_books_id => l_sob_id
1283                                 , fp_det_balances   => fp_det_balances
1284                               );
1285 
1286                         create_acctg_entry (  l_ccid            => l_deprn_rsv_ccid
1287                                 , p_amount          => fp_det_balances.reval_reserve_backlog
1288                                 , l_adjust_type     => 'RESERVE'
1289                                 , l_cr_dr_flag      => 'DR'
1290                                 , l_set_of_books_id => l_sob_id
1291                                 , fp_det_balances   => fp_det_balances
1292                               ); */
1293                      end if;
1294 
1295            end if;
1296           end;
1297 
1298   	 igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1299 		     p_full_path => l_path_name,
1300 		     p_string => 'end acctg creation');
1301        return true;
1302     end;
1303 
1304 -- ======================================================================
1305 -- FUNCTION Do_No_Index_Reval
1306 -- fix for bug 3356588 - processing an asset when the new category that it
1307 -- has been reclassified to has indexed revaluation switched off
1308 -- Code does:
1309 -- 1. Create a new transaction header line for the asset for the new cat
1310 -- 2. Reverse the accounting entries for the existing dist ids.
1311 -- 3. Does not  create accounting entries for the new dists.
1312 -- 4. The det balances for the existing dists are brought forward only
1313 --    with YTD values
1314 -- 5. The det balances for the new dists are all 0 with cumulative reval
1315 --    factor of 1
1316 -- 6. The asset balances for the asset are all 0 with cumulative reval
1317 -- factor of 1
1318 -- ======================================================================
1319 FUNCTION Do_No_Index_Reval(p_event_id in number) RETURN BOOLEAN
1320 IS
1321 
1322 	/* Cursor to select all distributions for an asset that are active and the distribution
1323 	impacted by the reclass */
1324 
1325 	CURSOR 	c_all_dist IS
1326 	SELECT	distribution_id,
1327 		transaction_header_id_in,
1328 		units_assigned
1329 	FROM 	fa_distribution_history
1330 	WHERE	asset_id=l_asset_hdr_rec.asset_id
1331 	AND	book_type_code=l_asset_hdr_rec.book_type_code
1332 	AND	transaction_header_id_out=l_trans_rec.transaction_header_id;
1333 
1334 	/* Cursor to select  the distribution(s)  undergoing the reclasss */
1335 
1336 	CURSOR 	c_old_dist(c_dist_id IN FA_DISTRIBUTION_HISTORY.distribution_id%TYPE) IS
1337 	SELECT	distribution_id
1338 	FROM 	fa_distribution_history
1339 	WHERE 	asset_id=l_asset_hdr_rec.asset_id
1340 	AND    book_type_code=l_asset_hdr_rec.book_type_code
1341 	AND    transaction_header_id_out=l_trans_rec.transaction_header_id
1342 	AND    distribution_id=c_dist_id;
1343 
1344    	/* Cursor to select  the  new distribution(s)  undergoing the reclasss */
1345 
1346 	CURSOR 	c_new_dist(c_dist_id IN FA_DISTRIBUTION_HISTORY.distribution_id%TYPE) IS
1347 	SELECT	distribution_id
1348 	FROM 	fa_distribution_history
1349 	WHERE 	asset_id=l_asset_hdr_rec.asset_id
1350 	AND    book_type_code=l_asset_hdr_rec.book_type_code
1351 	AND    transaction_header_id_in=l_trans_rec.transaction_header_id
1352 	AND    distribution_id=c_dist_id;
1353 
1354 	/* Cursor to select the details of impacted distribution in this reclass*/
1355 
1356 	CURSOR 	c_impacted_dist(c_imp_dist_id FA_DISTRIBUTION_HISTORY.distribution_id%TYPE) IS
1357 	SELECT 	a.distribution_id,
1358 			a.units_assigned
1359 	FROM 	fa_distribution_history a, fa_distribution_history b
1360 	WHERE	a.asset_id=l_asset_hdr_rec.asset_id
1361 	AND    a.book_type_code=l_asset_hdr_rec.book_type_code
1362         AND     a.asset_id = b.asset_id
1363         AND     a.book_type_code = b.book_type_code
1364         AND     a.transaction_header_id_in=l_trans_rec.transaction_header_id
1365         AND     b.transaction_header_id_out = l_trans_rec.transaction_header_id
1366         AND 	nvl(a.location_id,-1) = nvl(b.location_id,-1)
1367         AND     a.units_assigned = b.units_assigned
1368         AND    b.distribution_id=c_imp_dist_id;
1369 
1370         CURSOR c_impacted_dist_new(c_imp_dist_id FA_DISTRIBUTION_HISTORY.distribution_id%TYPE ,
1371                                 c_imp_dist_id_new FA_DISTRIBUTION_HISTORY.distribution_id%TYPE) IS
1372 	SELECT 	a.distribution_id,
1373 		a.units_assigned
1374 	FROM 	fa_distribution_history a, fa_distribution_history b
1375 	WHERE	a.asset_id=l_asset_hdr_rec.asset_id
1376 	AND     a.book_type_code=l_asset_hdr_rec.book_type_code
1377         AND     a.asset_id = b.asset_id
1378         AND     a.book_type_code = b.book_type_code
1379         AND     a.transaction_header_id_in=l_trans_rec.transaction_header_id
1380         AND     b.transaction_header_id_out = l_trans_rec.transaction_header_id
1381         AND 	nvl(a.location_id,-1) = nvl(b.location_id,-1)
1382         AND    a.units_assigned = b.units_assigned
1383         AND    b.distribution_id=c_imp_dist_id
1384         AND  	a.distribution_id > c_imp_dist_id_new;
1385 
1386 	/* Cursor to select adjustment_id or the previous transaction */
1387 
1388 	CURSOR 	c_prev_data IS
1389 	SELECT	a.rowid,a.adjustment_id
1390 	FROM 	igi_iac_transaction_headers a
1391 	WHERE	a.adjustment_id_out IS NULL
1392         AND     a.asset_id = l_asset_hdr_rec.asset_id;
1393 
1394 
1395 	/* Cursor  to find the amounts that need to be transferres to the new  dist
1396 	 created by reclass */
1397 
1398 	CURSOR 	c_amounts(c_period_counter IN IGI_IAC_ASSET_BALANCES.period_counter%TYPE) IS
1399 	SELECT	*
1400 	FROM	igi_iac_asset_balances
1401 	WHERE 	asset_id=l_asset_hdr_rec.asset_id
1402         AND     book_type_code=l_asset_hdr_rec.book_type_code
1403         AND     period_counter=(SELECT max(period_counter)
1404 			        FROM   igi_iac_asset_balances
1405 			        WHERE  asset_id=l_asset_hdr_rec.asset_id
1406                			AND     book_type_code=l_asset_hdr_rec.book_type_code);
1407 
1408 	/* Cursor to find the total number of units for the asset itself ( active) */
1409 
1410 	CURSOR 	c_units IS
1411 	SELECT 	sum(units_assigned)
1412 	FROM	fa_distribution_history
1413         WHERE   asset_id=l_asset_hdr_rec.asset_id
1414         AND     book_type_code=l_asset_hdr_rec.book_type_code
1415         AND     transaction_header_id_out IS NULL;
1416 
1417 	/* Cursor to find the total no of units involved in the transfer of old dist to new */
1418 
1419 	CURSOR 	c_dist_units IS
1420 	SELECT	sum(units_assigned)
1421 	FROM    fa_distribution_history
1422         WHERE   asset_id=l_asset_hdr_rec.asset_id
1423         AND     book_type_code=l_asset_hdr_rec.book_type_code
1424         AND     transaction_header_id_in=l_trans_rec.transaction_header_id;
1425 
1426 	/* Cursor for ytd deprn */
1427 
1428 	CURSOR 	c_ytd_deprn(c_start_counter IGI_IAC_ASSET_BALANCES.period_counter%TYPE
1429 			           ,c_current_counter IGI_IAC_ASSET_BALANCES.period_counter%TYPE) IS
1430 	SELECT 	nvl(sum(deprn_amount),0) deprn_amount
1431 	FROM 	igi_iac_asset_balances
1432 	WHERE 	book_type_code=l_asset_hdr_rec.book_type_code
1433 	AND	asset_id=l_asset_hdr_rec.asset_id
1434 	AND	period_counter between c_start_counter and c_current_counter;
1435 
1436 	/* Cursor for operating account ytd */
1437 
1438 	CURSOR 	c_op_acct_ytd(c_start_counter IGI_IAC_ASSET_BALANCES.period_counter%TYPE
1439 			             ,c_current_counter IGI_IAC_ASSET_BALANCES.period_counter%TYPE) IS
1440 	SELECT 	nvl(sum(operating_acct),0) operating_acct
1441 	FROM 	igi_iac_asset_balances
1442 	WHERE 	book_type_code=l_asset_hdr_rec.book_type_code
1443 	AND	asset_id=l_asset_hdr_rec.asset_id
1444 	AND	period_counter BETWEEN c_start_counter AND c_current_counter;
1445 
1446 	/* Cursor to select the start period number for a given fiscal year */
1447 
1448 	 CURSOR c_start_period_counter(c_fiscal_year FA_DEPRN_PERIODS.fiscal_year%TYPE) IS
1449 	 SELECT (number_per_fiscal_year*c_fiscal_year)+1
1450 	 FROM	fa_calendar_types
1451 	 WHERE   calendar_type=(SELECT deprn_calendar
1452                                 FROM fa_book_controls
1453 	 		        WHERE book_type_code=l_asset_hdr_rec.book_type_code);
1454 
1455 	 /* Cursor to select the adjustment_id from the sequence for a new record */
1456 
1457 	 CURSOR	c_adj_id IS
1458 	 SELECT igi_iac_transaction_headers_s.nextval
1459 	 FROM	dual;
1460 
1461 	 /*  To select the asset's deprn_expense from fa_books */
1462 
1463 	CURSOR 	c_deprn_expense(c_period_counter FA_DEPRN_SUMMARY.period_counter%TYPE) IS
1464 	SELECT 	deprn_amount
1465 	FROM 	fa_deprn_summary
1466 	WHERE 	book_type_code = l_asset_hdr_rec.book_type_code
1467 	AND   	period_counter = c_period_counter
1468 	AND   	asset_id=l_asset_hdr_rec.asset_id;
1469 
1470 	 /* Cursor to select the reval reserve backlog,op acct backlog and gen fund per for the dist */
1471 
1472 	 CURSOR	c_backlog_data(c_current_period_Counter fa_deprn_periods.period_counter%TYPE) IS
1473 	 SELECT sum(nvl(iadb.reval_reserve_backlog,0)) reval_reserve_backlog,
1474 	 		sum(nvl(iadb.operating_acct_backlog,0)) operating_acct_backlog,
1475 	 		sum(nvl(iadb.general_fund_per,0)) general_fund_per
1476 	 FROM	igi_iac_det_balances iadb,fa_distribution_history fdh
1477 	 WHERE 	iadb.book_type_code = l_asset_hdr_rec.book_type_code
1478 	 AND   	iadb.period_counter = c_current_period_counter
1479 	 AND   	iadb.asset_id=l_asset_hdr_rec.asset_id
1480 	 AND	iadb.asset_id=fdh.asset_id
1481 	 AND	iadb.book_type_code =fdh.book_type_code
1482 	 AND 	fdh.transaction_header_id_out=l_trans_rec.transaction_header_id
1483 	 AND	fdh.distribution_id=iadb.distribution_id;
1484 
1485 	/*  To find the asset number */
1486 
1487 	CURSOR	c_asset_num IS
1488 	SELECT 	asset_number
1489 	FROM	fa_additions
1490 	WHERE	asset_id=l_asset_hdr_rec.asset_id;
1491 
1492     /* get the closing det balances record */
1493     CURSOR  c_closing_det_balances( p_old_dist  IGI_IAC_ADJUSTMENTS.distribution_id%TYPE,
1494                                     p_adjustment_id IGI_IAC_ADJUSTMENTS.adjustment_id%TYPE)IS
1495     SELECT *
1496     FROM igi_iac_det_balances
1497     WHERE asset_id=l_asset_hdr_rec.asset_id
1498     AND book_type_code = l_asset_hdr_rec.book_type_code
1499     AND distribution_id = p_old_dist
1500     AND adjustment_id = p_adjustment_id;
1501 
1502     /* Cursor to get incactive distributuiions to be carried forward */
1503     CURSOR   get_all_prev_inactive_dist (C_prev_data_adjustment_id NUMBER)
1504     IS
1505     SELECT *
1506     FROM igi_iac_det_balances
1507     WHERE asset_id=l_asset_hdr_rec.asset_id
1508     AND book_type_code = l_asset_hdr_rec.book_type_code
1509     AND adjustment_id = C_prev_data_adjustment_id;
1510 --    AND nvl(active_flag,'Y') = 'N';
1511 
1512 
1513    /* Enhancemnet 2480915 Cursor to fetch the igi_fa_deprn deatils */
1514     CURSOR c_get_deprn_dist (c_book_type_code VARCHAR2,
1515                              c_asset_id NUMBER,
1516                              c_distribution_id NUMBER,
1517                              c_adjustment_id NUMBER)
1518     IS
1519     SELECT *
1520     FROM IGI_IAC_FA_DEPRN
1521     WHERE book_type_code = c_book_type_code
1522     AND asset_id = c_asset_id
1523     AND Distribution_id = c_distribution_id
1524     AND adjustment_id = c_adjustment_id;
1525 
1526 
1527 --	l_asset_revalued		    c_asset_revalued%rowtype;
1528 	l_impacted_dist 		    c_impacted_dist%ROWTYPE;
1529 	l_amounts 			        c_amounts%ROWTYPE;
1530 	l_backlog_data			    c_backlog_data%ROWTYPE;
1531         l_get_deprn_dist             c_get_deprn_dist%ROWTYPE;
1532 	l_old_dist			        c_old_dist%ROWTYPE;
1533 	l_dist_units			    FA_DISTRIBUTION_HISTORY.units_assigned%TYPE;
1534 	l_prd_rec 			        IGI_IAC_TYPES.prd_rec;
1535 	l_prd_rec_prior			    IGI_IAC_TYPES.prd_rec;
1536 
1537 	l_prev_data 			    c_prev_data%ROWTYPE;
1538 	l_adj_id 			        IGI_IAC_ADJUSTMENTS.adjustment_id%TYPE;
1539 	l_current_period_counter 	FA_DEPRN_PERIODS.period_counter%TYPE;
1540 	l_start_period_counter		FA_DEPRN_PERIODS.period_counter%TYPE;
1541 
1542 	l_asset_num			        FA_ADDITIONS.asset_number%TYPE;
1543 	l_units				        FA_DISTRIBUTION_HISTORY.units_assigned%TYPE;
1544 	l_reval_reserve 		    IGI_IAC_DET_BALANCES.reval_reserve_cost%TYPE;
1545 	l_general_fund 			    IGI_IAC_DET_BALANCES.general_fund_acc%TYPE;
1546 	l_Backlog_deprn_reserve 	IGI_IAC_DET_BALANCES.deprn_reserve_backlog%TYPE;
1547 	l_deprn_reserve			    IGI_IAC_DET_BALANCES.deprn_reserve%TYPE;
1548 	l_adjusted_cost			    IGI_IAC_DET_BALANCES.adjustment_cost%TYPE;
1549 	l_net_book_value 		    IGI_IAC_DET_BALANCES.net_book_value%TYPE;
1550 	l_deprn_per 			    IGI_IAC_DET_BALANCES.deprn_period%TYPE;
1551 	l_ytd_deprn 			    IGI_IAC_DET_BALANCES.deprn_ytd%TYPE;
1552 	l_op_acct 			        IGI_IAC_DET_BALANCES.operating_acct_ytd%TYPE;
1553 	l_op_acct_ytd			    IGI_IAC_DET_BALANCES.operating_acct_ytd%TYPE;
1554 	l_general_fund_per		    IGI_IAC_DET_BALANCES.general_fund_per%TYPE;
1555 	l_reval_reserve_backlog		IGI_IAC_DET_BALANCES.reval_reserve_backlog%TYPE;
1556 	l_operating_acct_backlog	IGI_IAC_DET_BALANCES.operating_acct_backlog%TYPE;
1557 	l_reval_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%TYPE;
1558 	l_gen_fund_ccid 		    IGI_IAC_ADJUSTMENTS.code_combination_id%TYPE;
1559 	l_backlog_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%TYPE;
1560 	l_deprn_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%TYPE;
1561 	l_cost_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%TYPE;
1562 	l_prior_period_counter		IGI_IAC_TRANSACTION_HEADERS.period_counter%TYPE;
1563 	l_historic_deprn_expense 	FA_DEPRN_SUMMARY.deprn_amount%TYPE;
1564 	l_Expense_diff			    IGI_IAC_DET_BALANCES.deprn_period%TYPE;
1565 	l_expense_ccid			    IGI_IAC_ADJUSTMENTS.code_combination_id%TYPE;
1566         l_closing_det_balances      IGI_IAC_DET_BALANCES%ROWTYPE;
1567         l_adjustment_id             IGI_IAC_ADJUSTMENTS.adjustment_id%TYPE;
1568         l_get_all_prev_dist         get_all_prev_inactive_dist%ROWTYPE;
1569 
1570         l_rowid                     ROWID;
1571 	l_return_value			    BOOLEAN;
1572 	l_Prorate_factor		    NUMBER;
1573 	l_deprn_expense			    NUMBER;
1574 	x 				            VARCHAR2(100);
1575 	prior_period 			    VARCHAR2(100);
1576 	l_mesg				        VARCHAR2(500);
1577         l_adjustment_id_out         NUMBER;
1578         l_prev_adjustment_id        NUMBER;
1579         l_transaction_type_code     VARCHAR2(50);
1580         l_transaction_id            NUMBER ;
1581         l_mass_reference_id         NUMBER ;
1582         l_adjustment_status         VARCHAR2(50);
1583         l_path_name VARCHAR2(150);
1584 
1585     BEGIN
1586         l_transaction_type_code     := NULL;
1587         l_adjustment_status         := NULL ;
1588         l_path_name := g_path||'do_no_index_reval';
1589 
1590       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1591 		     	p_full_path => l_path_name,
1592 		     	p_string => '     + Index revaluation OFF - In Do_No_Index_Reval');
1593 
1594 	/* Store the previous transaction adjustment id */
1595 
1596     -- get the latest transaction
1597     IF NOT igi_iac_common_utils.Get_Latest_Transaction (
1598                        		X_book_type_code    => l_asset_hdr_rec.book_type_code,
1599                        		X_asset_id          => l_asset_hdr_rec.asset_id,
1600                        		X_Transaction_Type_Code	=> l_transaction_type_code,
1601                        		X_Transaction_Id	=> l_transaction_id,
1602                        		X_Mass_Reference_ID	=> l_mass_reference_id,
1603                        		X_Adjustment_Id		=> l_adjustment_id_out,
1604                        		X_Prev_Adjustment_Id => l_prev_adjustment_id,
1605                        		X_Adjustment_Status	=> l_adjustment_status) THEN
1606   	  igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
1607 		     p_full_path => l_path_name,
1608 		     p_string => '*** Error in fetching the latest transaction');
1609         RETURN FALSE;
1610     END IF;
1611 
1612     -- Get the current open period
1613 	IF igi_iac_common_utils.get_open_period_info(l_asset_hdr_rec.book_type_code,l_prd_rec) THEN
1614 		l_current_period_counter:=l_prd_rec.period_counter;
1615   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1616 		     	p_full_path => l_path_name,
1617 		     	p_string => '     + Current OPen Period counter' ||l_prd_rec.period_counter );
1618 	END IF;
1619 
1620   	-- Fetch the adjustment id from the sequence
1621     OPEN c_adj_id;
1622     FETCH c_adj_id INTO l_adj_id;
1623     CLOSE c_adj_id;
1624 
1625   	-- Insert into transaction headers
1626 	insert_data_trans_hdr(l_adj_id,
1627 		              l_trans_rec.transaction_header_id,
1628 		              NULL,
1629 		              l_trans_rec.transaction_type_code,
1630 		              l_trans_rec.transaction_date_entered,
1631 		              l_trans_rec.mass_reference_id,
1632 		              l_asset_hdr_rec.book_type_code,
1633 		              l_asset_hdr_rec.Asset_id,
1634 		              NULL,
1635 		              'COMPLETE',
1636                               l_asset_cat_rec_old.category_id,
1637 	                      -- l_asset_cat_rec_new.category_id,
1638 		              l_current_period_counter,
1639 		              p_event_id
1640 		              );
1641 
1642         igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1643 		     	p_full_path => l_path_name,
1644 		     	p_string => '     + After Insert into trans header' );
1645 
1646     -- Need to close the previous transaction to pick the latest catgeory --
1647     IGI_IAC_TRANS_HEADERS_PKG.update_row (
1648     		x_prev_adjustment_id          =>l_adjustment_id_out,
1649     		x_adjustment_id		          =>l_adj_id,
1650     		x_mode                        =>'R'
1651 				                          );
1652 
1653     OPEN c_units;
1654     FETCH c_units INTO l_units;
1655     CLOSE c_units;
1656 
1657     OPEN c_dist_units;
1658     FETCH c_dist_units INTO l_dist_units;
1659     CLOSE c_dist_units;
1660 
1661     l_impacted_dist := NULL;
1662 	FOR l_all_dist IN c_all_dist
1663 	LOOP
1664 		OPEN c_start_period_counter(l_prd_rec.fiscal_year);
1665 		FETCH c_start_period_counter INTO l_start_period_counter;
1666 	        CLOSE c_start_period_counter;
1667 
1668 		OPEN c_ytd_deprn(l_start_period_counter,l_prd_rec.period_counter);
1669 		FETCH c_ytd_deprn INTO l_ytd_deprn;
1670 		CLOSE c_ytd_deprn;
1671 
1672 		OPEN c_op_acct_ytd(l_start_period_counter,l_prd_rec.period_counter);
1673 		FETCH c_op_acct_ytd INTO l_op_acct_ytd;
1674 		CLOSE c_op_acct_ytd;
1675 
1676 		OPEN c_old_dist(l_all_dist.distribution_id);
1677 		FETCH c_old_dist INTO l_old_dist;
1678 		CLOSE c_old_dist;
1679 
1680         IF  (l_impacted_dist.distribution_id  IS NULL ) THEN
1681     		OPEN c_impacted_dist(l_all_dist.distribution_id);
1682 	    	FETCH c_impacted_dist INTO l_impacted_dist;
1683   	      		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1684 		     		 p_full_path => l_path_name,
1685 		     		 p_string => '         + impacted distribution id ' || l_all_dist.distribution_id);
1686   	      		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1687 		    		 p_full_path => l_path_name,
1688 		     		 p_string => '         + new impacted distribution id ' || l_impacted_dist.distribution_id);
1689 
1690 	    	CLOSE c_impacted_dist;
1691         ELSE
1692                 OPEN c_impacted_dist_new(l_all_dist.distribution_id,l_impacted_dist.distribution_id);
1693 	        FETCH c_impacted_dist_new INTO l_impacted_dist;
1694   	      		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1695 		     		 p_full_path => l_path_name,
1696 		     		 p_string => '         + impacted distribution id ' || l_all_dist.distribution_id);
1697   	      		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1698 		     		 p_full_path => l_path_name,
1699 		     		 p_string => '         + new impacted distribution id ' || l_impacted_dist.distribution_id);
1700 
1701 	    	CLOSE c_impacted_dist_new;
1702         END IF;
1703 
1704 	OPEN c_old_dist(l_all_dist.distribution_id);
1705 	FETCH c_old_dist INTO l_old_dist;
1706         IF c_old_dist%NOTFOUND THEN
1707   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1708 		     p_full_path => l_path_name,
1709 		     p_string => ' No old distribution for asset found ' || l_old_dist.distribution_id);
1710             CLOSE c_old_dist;
1711             RETURN FALSE;
1712         END IF;
1713         CLOSE c_old_dist;
1714   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1715 		     p_full_path => l_path_name,
1716 		     p_string => '  + no old distribution for asset ' || l_old_dist.distribution_id);
1717 
1718         /* get the closing det balances record form iac det balances */
1719         l_adjustment_id :=l_prev_adjustment_id;
1720 
1721         OPEN c_closing_det_balances(l_old_dist.distribution_id,l_prev_adjustment_id);
1722         FETCH c_closing_det_balances INTO l_closing_det_balances;
1723         IF c_closing_det_balances%NOTFOUND THEN
1724   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1725 		     	p_full_path => l_path_name,
1726 		     	p_string => '  +  old distruibution id ' || l_old_dist.distribution_id);
1727   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1728 		     	p_full_path => l_path_name,
1729 		     	p_string => '  +  adjustement id  '||l_prev_adjustment_id);
1730   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1731 		     	p_full_path => l_path_name,
1732 		     	p_string => ' Could not  find the IAC  det balances record ');
1733             CLOSE c_closing_det_balances;
1734             RETURN FALSE;
1735         END IF;
1736 
1737   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1738 		     	p_full_path => l_path_name,
1739 		     	p_string => '  +  old distruibution id ' || l_old_dist.distribution_id);
1740   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1741 		     	p_full_path => l_path_name,
1742 		     	p_string => '  +  adjustement id  '||l_prev_adjustment_id);
1743 
1744         CLOSE c_closing_det_balances;
1745 
1746 
1747         l_closing_det_balances.adjustment_id    := l_adj_id;
1748         l_closing_det_balances.period_counter := l_current_period_counter;
1749         l_deprn_reserve_amount:=  0;
1750 
1751         UPDATE igi_iac_transaction_headers
1752         SET category_id = l_asset_cat_rec_old.category_id
1753         WHERE adjustment_id = l_adj_id;
1754 
1755         -- reverse the accounting entries for the existing dist ids
1756         IF create_iac_acctg ( l_closing_det_balances,TRUE,'OLD',p_event_id => p_event_id) THEN
1757   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1758 		     		p_full_path => l_path_name,
1759 		     		p_string => '+Accounting entries created for old');
1760         ELSE
1761   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
1762 		     		p_full_path => l_path_name,
1763 		     		p_string => 'Failed to create Accounting entries');
1764             	RETURN FALSE;
1765         END IF;
1766 
1767         -- bring the existing dists with their YTD values
1768         insert_data_det(p_adjustment_id                 =>l_adj_id,
1769         		      p_asset_id		=>l_asset_hdr_rec.asset_id,
1770     			      p_distribution_id	        =>l_closing_det_balances.distribution_id,
1771     			      p_period_counter	        =>l_closing_det_balances.period_counter,
1772     			      p_book_type_code          =>l_asset_hdr_rec.book_type_code,
1773     			      p_adjusted_cost	        =>0,
1774     			      p_net_book_value      	=>0,
1775     			      p_reval_reserve	        =>0,
1776     			      p_reval_reserve_gen_fund	=>0,
1777     			      p_reval_reserve_backlog	=>0,
1778                               p_reval_reserve_net       =>0,
1779     			      p_op_acct			=>0,
1780                               p_op_acct_net             =>0,
1781     			      p_deprn_reserve		=>0,
1782     			      p_deprn_reserve_backlog 	=>0,
1783     			      p_deprn_ytd		=>l_closing_det_balances.DEPRN_YTD,
1784     			      p_deprn_period	    	=>0,
1785     			      p_gen_fund_acc		=>0,
1786     			      p_gen_fund_per		=>0,
1787     			      p_current_reval_factor	=>l_closing_det_balances.current_reval_factor,
1788     			      p_cumulative_reval_factor =>l_closing_det_balances.cumulative_reval_factor,
1789     			      p_reval_flag		=> 'N',
1790     			      p_op_acct_ytd		=>l_closing_det_balances.OPERATING_ACCT_YTD,
1791     			      p_operating_acct_backlog  =>0,
1792     			      p_last_reval_date		=>l_closing_det_balances.last_reval_date);
1793 
1794         -- enchancement 2480915 maintiain the ytd values ---
1795         OPEN  c_get_deprn_dist  (l_asset_hdr_rec.book_type_code,
1796                                  l_asset_hdr_rec.asset_id,
1797                                  l_closing_det_balances.distribution_id ,
1798                                  l_adjustment_id_out );
1799         FETCH    c_get_deprn_dist INTO l_get_deprn_dist;
1800         IF c_get_deprn_dist%FOUND THEN
1801             -- Call to TBH for insert into IGI_IAC_ADJUSTMENTS
1802     	    IGI_IAC_FA_DEPRN_PKG.insert_row(
1803     		            	x_rowid                =>l_rowid,
1804                			x_adjustment_id        =>l_adj_id,
1805     		            	x_book_type_code       =>l_asset_hdr_rec.book_type_code,
1806                			x_asset_id             =>l_asset_hdr_rec.asset_id,
1807      		            	x_distribution_id      =>l_closing_det_balances.distribution_id,
1808                			x_period_counter       =>l_closing_det_balances.period_counter,
1809                                 x_deprn_period         => 0,
1810                                 x_deprn_ytd             =>l_get_deprn_dist.deprn_ytd,
1811                                 x_deprn_reserve        => 0,
1812                                 x_active_flag          => 'N',
1813                 		x_mode                 =>'R'
1814             		                             );
1815 
1816         END IF;
1817         CLOSE c_get_deprn_dist;
1818         -- enchancement 2480915 maintiain the ytd values ---
1819         -- before performing the new distribution entries update with new catgeory
1820         UPDATE igi_iac_transaction_headers
1821         SET category_id = l_asset_cat_rec_new.category_id
1822         WHERE adjustment_id = l_adj_id;
1823 
1824         -- create entries in igi_iac_det_balances for the new dist
1825         insert_data_det(p_adjustment_id  =>l_adj_id,
1826         		      p_asset_id		        =>l_asset_hdr_rec.asset_id,
1827     			      p_distribution_id	        =>l_impacted_dist.distribution_id,
1828     			      p_period_counter	        =>l_current_period_counter,
1829     			      p_book_type_code          =>l_asset_hdr_rec.book_type_code,
1830     			      p_adjusted_cost	        =>0,
1831     			      p_net_book_value      	=>0,
1832     			      p_reval_reserve	        =>0,
1833     			      p_reval_reserve_gen_fund	=>0,
1834     			      p_reval_reserve_backlog	=>0,
1835                       p_reval_reserve_net	    =>0,
1836     			      p_op_acct			        =>0,
1837                       p_op_acct_net			    =>0,
1838     			      p_deprn_reserve		    =>0,
1839     			      p_deprn_reserve_backlog 	=>0,
1840     			      p_deprn_ytd		        =>0,
1841     			      p_deprn_period	    	=>0,
1842     			      p_gen_fund_acc		    =>0,
1843     			      p_gen_fund_per		    =>0,
1844     			      p_current_reval_factor	=>1,
1845     			      p_cumulative_reval_factor =>1,
1846     			      p_reval_flag		        => NULL,
1847     			      p_op_acct_ytd		        =>0,
1848     			      p_operating_acct_backlog  =>0,
1849     			      p_last_reval_date		    =>l_closing_det_balances.last_reval_date);
1850 
1851          -- enchancement 2480915 maintiain the  FA YTD  values ---
1852          OPEN  c_get_deprn_dist  (l_asset_hdr_rec.book_type_code,
1853                                   l_asset_hdr_rec.asset_id,
1854                                   l_old_dist.distribution_id ,
1855                                   l_adjustment_id_out );
1856          FETCH    c_get_deprn_dist INTO l_get_deprn_dist;
1857          IF c_get_deprn_dist%FOUND THEN
1858             /* Call to TBH for insert into IGI_IAC_ADJUSTMENTS */
1859     	    IGI_IAC_FA_DEPRN_PKG.insert_row(
1860     		            	x_rowid           =>l_rowid,
1861                 		x_adjustment_id   =>l_adj_id,
1862     		            	x_book_type_code  =>l_asset_hdr_rec.book_type_code,
1863                 		x_asset_id        =>l_asset_hdr_rec.asset_id,
1864      		            	x_distribution_id =>l_impacted_dist.distribution_id,
1865                 		x_period_counter  =>l_current_period_counter,
1866                                 x_deprn_period    => 0,
1867                                 x_deprn_ytd       => 0,
1868                                 x_deprn_reserve   => 0,
1869                                 x_active_flag     => NULL,
1870                 		x_mode            =>'R'
1871             			                     );
1872 
1873           END IF;
1874           CLOSE c_get_deprn_dist;
1875           -- enchancement 2480915 maintiain the ytd values ---
1876 	END LOOP;
1877 	 /* End of loop for all active distributions */
1878 
1879     /* Update the asset balanaces to zero in case new category has no indexed revalutions */
1880 
1881     IF NOT (ALLOW_INDEX_REVAL_FLAG) THEN
1882             igi_iac_asset_balances_pkg.update_row(
1883 	    			X_asset_id		          => l_asset_hdr_rec.asset_id,
1884 					X_book_type_code	      => l_asset_hdr_rec.book_type_code,
1885 					X_period_counter	      => l_current_period_counter ,
1886 					X_net_book_value	      => 0,
1887 					X_adjusted_cost		      => 0,
1888 					X_operating_acct	      => 0,
1889 					X_reval_reserve		      => 0,
1890 					X_deprn_amount		      => 0,
1891 					X_deprn_reserve		      => 0,
1892 					X_backlog_deprn_reserve   => 0,
1893 					X_general_fund		      => 0,
1894 					X_last_reval_date	      => Null,
1895 					X_current_reval_factor	  => 1,
1896         			X_cumulative_reval_factor => 1) ;
1897 
1898     END IF;
1899 
1900     /* get the ytd sum of the active distributiions*/
1901     l_deprn_ytd := 0;
1902     /* bring forward all the inactive distributions to the current adjustment */
1903     FOR  l_get_all_prev_dist in get_all_prev_inactive_dist (l_prev_adjustment_id) LOOP
1904         IF l_get_all_prev_dist.active_flag = 'N' THEN
1905                       /*create a record with new adjustment id */
1906             insert_data_det(p_adjustment_id     =>l_adj_id,
1907     			      p_asset_id		        =>l_asset_hdr_rec.asset_id,
1908     			      p_distribution_id	        =>l_get_all_prev_dist.distribution_id,
1909     			      p_period_counter	        =>l_current_period_counter,
1910     			      p_book_type_code          =>l_get_all_prev_dist.book_type_code,
1911     			      p_adjusted_cost	        =>l_get_all_prev_dist.adjustment_cost,
1912     			      p_net_book_value      	=>l_get_all_prev_dist.net_book_value,
1913     			      p_reval_reserve	        =>l_get_all_prev_dist.reval_reserve_cost,
1914     			      p_reval_reserve_gen_fund	=>l_get_all_prev_dist.reval_reserve_gen_fund,
1915     			      p_reval_reserve_backlog	=>l_get_all_prev_dist.reval_reserve_backlog,
1916     			      p_op_acct			        =>l_get_all_prev_dist.OPERATING_ACCT_COST,
1917     			      p_deprn_reserve		    =>l_get_all_prev_dist.deprn_reserve,
1918     			      p_deprn_reserve_backlog 	=>l_get_all_prev_dist.deprn_reserve_backlog,
1919     			      p_deprn_ytd		        => l_get_all_prev_dist.deprn_ytd,
1920                       p_reval_reserve_net	    =>l_get_all_prev_dist.reval_reserve_net,
1921                       p_op_acct_net			    =>l_get_all_prev_dist.OPERATING_ACCT_net,
1922     			      p_deprn_period	    	=>l_get_all_prev_dist.deprn_period,
1923     			      p_gen_fund_acc		    =>l_get_all_prev_dist.general_fund_acc,
1924     			      p_gen_fund_per		    =>l_get_all_prev_dist.general_fund_per,
1925     			      p_current_reval_factor	=>l_get_all_prev_dist.current_reval_factor,
1926     			      p_cumulative_reval_factor =>l_get_all_prev_dist.cumulative_reval_factor,
1927     			      p_reval_flag		        => l_get_all_prev_dist.active_flag,
1928     			      p_op_acct_ytd		        =>l_get_all_prev_dist.OPERATING_ACCT_YTD,
1929     			      p_operating_acct_backlog  =>l_get_all_prev_dist.OPERATING_ACCT_BACKLOG,
1930     			      p_last_reval_date		    =>l_get_all_prev_dist.last_reval_date);
1931 
1932           -- enchancement 2480915 maintiain the ytd values ---
1933           Open  c_get_deprn_dist  (l_asset_hdr_rec.book_type_code,
1934                                    l_asset_hdr_rec.asset_id,
1935                                    l_get_all_prev_dist.distribution_id ,
1936                                    l_adjustment_id_out );
1937           Fetch    c_get_deprn_dist into l_get_deprn_dist;
1938           IF c_get_deprn_dist%FOUND THEN
1939                            /* Call to TBH for insert into IGI_IAC_ADJUSTMENTS */
1940     	            IGI_IAC_FA_DEPRN_PKG.insert_row(
1941     		            	x_rowid                 =>l_rowid,
1942                 			x_adjustment_id         =>l_adj_id,
1943     		            	x_book_type_code        =>l_asset_hdr_rec.book_type_code,
1944                 			x_asset_id              =>l_asset_hdr_rec.asset_id,
1945      		            	x_distribution_id       =>l_get_all_prev_dist.distribution_id,
1946                 			x_period_counter        =>l_closing_det_balances.period_counter,
1947                             x_deprn_period          => l_get_deprn_dist.deprn_period,
1948                             x_deprn_ytd             =>l_get_deprn_dist.deprn_ytd,
1949                             x_deprn_reserve         =>l_get_deprn_dist.deprn_reserve,
1950                             x_active_flag           => 'N',
1951                 			x_mode                  =>'R'
1952             			);
1953 
1954            END IF;
1955            Close c_get_deprn_dist;
1956            -- enchancement 2480915 maintiain the ytd values ---
1957        ELSE
1958            l_deprn_ytd := l_deprn_ytd + l_get_all_prev_dist.deprn_ytd;
1959        END IF;
1960 
1961     END LOOP; -- inactive distributions
1962 
1963     RETURN(TRUE);
1964 
1965 
1966 EXCEPTION
1967   WHEN OTHERS THEN
1968     igi_iac_debug_pkg.debug_unexpected_msg(p_full_path => l_path_name);
1969     l_mesg:=SQLERRM;
1970     FA_SRVR_MSG.Add_Message(
1971 	                Calling_FN 	=> l_calling_function ,
1972         	        Name 		=> 'IGI_IAC_EXCEPTION',
1973         	        TOKEN1		=> 'PACKAGE',
1974         	        VALUE1		=> 'Reclass-Do_No_Index_Reval',
1975         	        TOKEN2		=> 'ERROR_MESSAGE',
1976         	        VALUE2		=> l_mesg,
1977                     APPLICATION => 'IGI');
1978 
1979     RETURN(FALSE);
1980 
1981 END; --do_no_index_reval
1982 
1983 
1984 -- ======================================================================
1985 -- SAME PRICE INDEX RECLASS
1986 -- function do all that needed for if both catgeories old and new has same
1987 -- price index
1988 -- ======================================================================
1989 FUNCTION do_same_price_index(p_event_id in number)
1990 Return boolean is
1991 
1992 	/* Cursor to select all distributions for an asset that are active and the distribution
1993 	impacted by the reclass */
1994 
1995 	CURSOR 	c_all_dist IS
1996 		SELECT	distribution_id,
1997 			    transaction_header_id_in,
1998 			    units_assigned
1999 		FROM 	fa_distribution_history
2000 		WHERE	asset_id=l_asset_hdr_rec.asset_id
2001 		AND	book_type_code=l_asset_hdr_rec.book_type_code
2002 		AND	transaction_header_id_out=l_trans_rec.transaction_header_id;
2003 
2004 	/* Cursor to select  the distribution(s)  undergoing the reclasss */
2005 
2006 	CURSOR 	c_old_dist(c_dist_id in FA_DISTRIBUTION_HISTORY.distribution_id%type) IS
2007 		SELECT	distribution_id
2008 		FROM 	fa_distribution_history
2009 		WHERE 	asset_id=l_asset_hdr_rec.asset_id
2010 		AND	    book_type_code=l_asset_hdr_rec.book_type_code
2011 		AND	    transaction_header_id_out=l_trans_rec.transaction_header_id
2012 		AND	    distribution_id=c_dist_id;
2013 
2014    	/* Cursor to select  the  new distribution(s)  undergoing the reclasss */
2015 
2016 	CURSOR 	c_new_dist(c_dist_id in FA_DISTRIBUTION_HISTORY.distribution_id%type) IS
2017 		SELECT	distribution_id
2018 		FROM 	fa_distribution_history
2019 		WHERE 	asset_id=l_asset_hdr_rec.asset_id
2020 		AND	    book_type_code=l_asset_hdr_rec.book_type_code
2021 		AND	    transaction_header_id_in=l_trans_rec.transaction_header_id
2022 		AND	    distribution_id=c_dist_id;
2023 
2024 	/* Cursor to select the details of impacted distribution in this reclass*/
2025 
2026 	CURSOR 	c_impacted_dist(c_imp_dist_id FA_DISTRIBUTION_HISTORY.distribution_id%type) IS
2027 		SELECT 	a.distribution_id,
2028 			    a.units_assigned
2029 		FROM 	fa_distribution_history a, fa_distribution_history b
2030 		WHERE	a.asset_id=l_asset_hdr_rec.asset_id
2031 		AND	    a.book_type_code=l_asset_hdr_rec.book_type_code
2032         AND     a.asset_id = b.asset_id
2033         AND     a.book_type_code = b.book_type_code
2034         AND     a.transaction_header_id_in=l_trans_rec.transaction_header_id
2035         AND     b.transaction_header_id_out = l_trans_rec.transaction_header_id
2036         AND 	nvl(a.location_id,-1) = nvl(b.location_id,-1)
2037         AND    a.units_assigned = b.units_assigned
2038         AND	    b.distribution_id=c_imp_dist_id;
2039 
2040       CURSOR 	c_impacted_dist_new(c_imp_dist_id FA_DISTRIBUTION_HISTORY.distribution_id%type ,
2041                                                        c_imp_dist_id_new FA_DISTRIBUTION_HISTORY.distribution_id%type) IS
2042 		SELECT 	a.distribution_id,
2043 			    a.units_assigned
2044 		FROM 	fa_distribution_history a, fa_distribution_history b
2045 		WHERE	a.asset_id=l_asset_hdr_rec.asset_id
2046 		AND	    a.book_type_code=l_asset_hdr_rec.book_type_code
2047         AND     a.asset_id = b.asset_id
2048         AND     a.book_type_code = b.book_type_code
2049         AND     a.transaction_header_id_in=l_trans_rec.transaction_header_id
2050         AND     b.transaction_header_id_out = l_trans_rec.transaction_header_id
2051         AND 	nvl(a.location_id,-1) = nvl(b.location_id,-1)
2052         AND    a.units_assigned = b.units_assigned
2053         AND	    b.distribution_id=c_imp_dist_id
2054          AND  	a.distribution_id > c_imp_dist_id_new;
2055 
2056 	/* Cursor to select adjustment_id or the previous transaction */
2057 
2058 	CURSOR 	c_prev_data IS
2059 		SELECT	a.rowid,a.adjustment_id
2060 		FROM 	igi_iac_transaction_headers a
2061 		WHERE	a.adjustment_id_out is null
2062         and     a.asset_id = l_asset_hdr_rec.asset_id;
2063 
2064 
2065 	/* Cursor  to find the amounts that need to be transferres to the new  dist
2066 	 created by reclass */
2067 
2068 	CURSOR 	c_amounts(c_period_counter in IGI_IAC_ASSET_BALANCES.period_counter%type) IS
2069 		SELECT	*
2070 		FROM	igi_iac_asset_balances
2071 		WHERE 	asset_id=l_asset_hdr_rec.asset_id
2072                 AND     book_type_code=l_asset_hdr_rec.book_type_code
2073 		AND	period_counter=(select max(period_counter)
2074 					from 	igi_iac_asset_balances
2075 					WHERE 	asset_id=l_asset_hdr_rec.asset_id
2076                 			AND     book_type_code=l_asset_hdr_rec.book_type_code)
2077 					;
2078 
2079 	/* Cursor to find period counter from which the reclass is valid
2080 	   Needed only in case of prior period transfers
2081 
2082 	CURSOR 	c_prior_period_counter(c_trx_date in FA_DEPRN_PERIODS.period_open_date%type) IS
2083 		SELECT 	period_counter
2084 		FROM 	fa_deprn_periods
2085 		WHERE 	c_trx_date between period_open_date and period_close_date
2086 		AND 	book_type_code=p_asset_hdr_rec.book_type_code; */
2087 
2088 	/* Cursor to find the total number of units for the asset itself ( active) */
2089 
2090 	CURSOR 	c_units IS
2091 		SELECT 	sum(units_assigned)
2092 		FROM	fa_distribution_history
2093     	WHERE 	asset_id=l_asset_hdr_rec.asset_id
2094         AND     book_type_code=l_asset_hdr_rec.book_type_code
2095 		AND	transaction_header_id_out is null;
2096 
2097 	/* Cursor to find the total no of units involved in the transfer of old dist to new */
2098 
2099 	CURSOR 	c_dist_units IS
2100 		SELECT	sum(units_assigned)
2101 		FROM    fa_distribution_history
2102                 WHERE   asset_id=l_asset_hdr_rec.asset_id
2103                 AND     book_type_code=l_asset_hdr_rec.book_type_code
2104 		AND	transaction_header_id_in=l_trans_rec.transaction_header_id;
2105 
2106 	/* Cursor for ytd deprn */
2107 
2108 	CURSOR 	c_ytd_deprn(c_start_counter IGI_IAC_ASSET_BALANCES.period_counter%type
2109 			   ,c_current_counter IGI_IAC_ASSET_BALANCES.period_counter%type) IS
2110 		SELECT 	nvl(sum(deprn_amount),0) deprn_amount
2111 		FROM 	igi_iac_asset_balances
2112 		WHERE 	book_type_code=l_asset_hdr_rec.book_type_code
2113 		AND	asset_id=l_asset_hdr_rec.asset_id
2114 		AND	period_counter between c_start_counter and c_current_counter;
2115 
2116 	/* Cursor for operating account ytd */
2117 
2118 	CURSOR 	c_op_acct_ytd(c_start_counter IGI_IAC_ASSET_BALANCES.period_counter%type
2119 			   ,c_current_counter IGI_IAC_ASSET_BALANCES.period_counter%type) IS
2120 		SELECT 	nvl(sum(operating_acct),0) operating_acct
2121 		FROM 	igi_iac_asset_balances
2122 		WHERE 	book_type_code=l_asset_hdr_rec.book_type_code
2123 		AND	asset_id=l_asset_hdr_rec.asset_id
2124 		AND	period_counter between c_start_counter and c_current_counter;
2125 
2126 	/* Cursor to select the start period number for a given fiscal year */
2127 
2128 	 CURSOR c_start_period_counter(c_fiscal_year FA_DEPRN_PERIODS.fiscal_year%type) IS
2129 	 	SELECT (number_per_fiscal_year*c_fiscal_year)+1
2130 	 	FROM	fa_calendar_types
2131 	 	WHERE   calendar_type=(select deprn_calendar from fa_book_controls
2132 	 				where book_type_code=l_asset_hdr_rec.book_type_code);
2133 
2134 	 /* Cursor to select the adjustment_id from the sequence for a new record */
2135 
2136 	 CURSOR	c_adj_id IS
2137 	 	SELECT 	igi_iac_transaction_headers_s.nextval
2138 	 	FROM	dual;
2139 
2140 	 /*  To select the asset's deprn_expense from fa_books */
2141 
2142 	CURSOR 	c_deprn_expense(c_period_counter FA_DEPRN_SUMMARY.period_counter%type) IS
2143 	        SELECT 	deprn_amount
2144 	        FROM 	fa_deprn_summary
2145 	        WHERE 	book_type_code = l_asset_hdr_rec.book_type_code
2146 	        AND   	period_counter = c_period_counter
2147 	        AND   	asset_id=l_asset_hdr_rec.asset_id;
2148 
2149 	 /* Cursor to select the reval reserve backlog,op acct backlog and gen fund per for the dist */
2150 
2151 	 CURSOR	c_backlog_data(c_current_period_Counter fa_deprn_periods.period_counter%type) IS
2152 	 	SELECT 	sum(nvl(iadb.reval_reserve_backlog,0)) reval_reserve_backlog,
2153 	 		sum(nvl(iadb.operating_acct_backlog,0)) operating_acct_backlog,
2154 	 		sum(nvl(iadb.general_fund_per,0)) general_fund_per
2155 	 	FROM	igi_iac_det_balances iadb,fa_distribution_history fdh
2156 	 	WHERE 	iadb.book_type_code = l_asset_hdr_rec.book_type_code
2157 	        AND   	iadb.period_counter = c_current_period_counter
2158 	        AND   	iadb.asset_id=l_asset_hdr_rec.asset_id
2159 	        AND	iadb.asset_id=fdh.asset_id
2160 	        AND	iadb.book_type_code =fdh.book_type_code
2161 	        AND 	fdh.transaction_header_id_out=l_trans_rec.transaction_header_id
2162 	        AND	fdh.distribution_id=iadb.distribution_id;
2163 
2164 	/*  To find the asset number */
2165 
2166 	CURSOR	c_asset_num IS
2167 		SELECT 	asset_number
2168 		FROM	fa_additions
2169 		WHERE	asset_id=l_asset_hdr_rec.asset_id;
2170 
2171     /* get the closing det balances record */
2172     CURSOR  c_closing_det_balances( p_old_dist  IGI_IAC_ADJUSTMENTS.distribution_id%type,
2173                                     p_adjustment_id IGI_IAC_ADJUSTMENTS.adjustment_id%type)is
2174     SELECT *
2175     FROM igi_iac_det_balances
2176     WHERE asset_id=l_asset_hdr_rec.asset_id
2177     AND book_type_code = l_asset_hdr_rec.book_type_code
2178     AND distribution_id = p_old_dist
2179     AND adjustment_id = p_adjustment_id;
2180 
2181     /* Cursor to get incactive distributuiions to be carried forward */
2182     CURSOR   get_all_prev_inactive_dist (C_prev_data_adjustment_id Number)
2183     is
2184     SELECT *
2185     FROM igi_iac_det_balances
2186     WHERE asset_id=l_asset_hdr_rec.asset_id
2187     AND book_type_code = l_asset_hdr_rec.book_type_code
2188     AND adjustment_id = C_prev_data_adjustment_id;
2189 --    AND nvl(active_flag,'Y') = 'N';
2190 
2191 
2192    /* Enhancemnet 2480915 Cursor to fetch the igi_fa_deprn deatils */
2193     CURSOR c_get_deprn_dist (c_book_type_code Varchar2,
2194                                       c_asset_id Number,
2195                                       c_distribution_id Number,
2196                                       c_adjustment_id Number)      is
2197     SELECT *
2198     FROM IGI_IAC_FA_DEPRN
2199     WHERE book_type_code = c_book_type_code
2200     AND asset_id = c_asset_id
2201     AND Distribution_id = c_distribution_id
2202     AND adjustment_id = c_adjustment_id;
2203 
2204 
2205 --	l_asset_revalued		    c_asset_revalued%rowtype;
2206 	l_impacted_dist 		    c_impacted_dist%rowtype;
2207 	l_amounts 			        c_amounts%rowtype;
2208 	l_backlog_data			    c_backlog_data%rowtype;
2209     l_get_deprn_dist             c_get_deprn_dist%rowtype;
2210 	l_old_dist			        c_old_dist%rowtype;
2211 	l_dist_units			    FA_DISTRIBUTION_HISTORY.units_assigned%type;
2212 	l_prd_rec 			        IGI_IAC_TYPES.prd_rec;
2213 	l_prd_rec_prior			    IGI_IAC_TYPES.prd_rec;
2214 
2215 	l_prev_data 			    c_prev_data%rowtype;
2216 	l_adj_id 			        IGI_IAC_ADJUSTMENTS.adjustment_id%type;
2217 	l_current_period_counter 	FA_DEPRN_PERIODS.period_counter%type;
2218 	l_start_period_counter		FA_DEPRN_PERIODS.period_counter%type;
2219 
2220 	l_asset_num			        FA_ADDITIONS.asset_number%type;
2221 	l_units				        FA_DISTRIBUTION_HISTORY.units_assigned%type;
2222 	l_reval_reserve 		    IGI_IAC_DET_BALANCES.reval_reserve_cost%type;
2223 	l_general_fund 			    IGI_IAC_DET_BALANCES.general_fund_acc%type;
2224 	l_Backlog_deprn_reserve 	IGI_IAC_DET_BALANCES.deprn_reserve_backlog%type;
2225 	l_deprn_reserve			    IGI_IAC_DET_BALANCES.deprn_reserve%type;
2226 	l_adjusted_cost			    IGI_IAC_DET_BALANCES.adjustment_cost%type;
2227 	l_net_book_value 		    IGI_IAC_DET_BALANCES.net_book_value%type;
2228 	l_deprn_per 			    IGI_IAC_DET_BALANCES.deprn_period%type;
2229 	l_ytd_deprn 			    IGI_IAC_DET_BALANCES.deprn_ytd%type;
2230 	l_op_acct 			        IGI_IAC_DET_BALANCES.operating_acct_ytd%type;
2231 	l_op_acct_ytd			    IGI_IAC_DET_BALANCES.operating_acct_ytd%type;
2232 	l_general_fund_per		    IGI_IAC_DET_BALANCES.general_fund_per%type;
2233 	l_reval_reserve_backlog		IGI_IAC_DET_BALANCES.reval_reserve_backlog%type;
2234 	l_operating_acct_backlog	IGI_IAC_DET_BALANCES.operating_acct_backlog%type;
2235 	l_reval_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%type;
2236 	l_gen_fund_ccid 		    IGI_IAC_ADJUSTMENTS.code_combination_id%type;
2237 	l_backlog_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%type;
2238 	l_deprn_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%type;
2239 	l_cost_ccid 			    IGI_IAC_ADJUSTMENTS.code_combination_id%type;
2240 	l_prior_period_counter		IGI_IAC_TRANSACTION_HEADERS.period_counter%type;
2241 	l_historic_deprn_expense 	FA_DEPRN_SUMMARY.deprn_amount%type;
2242 	l_Expense_diff			    IGI_IAC_DET_BALANCES.deprn_period%type;
2243 	l_expense_ccid			    IGI_IAC_ADJUSTMENTS.code_combination_id%type;
2244       l_closing_det_balances      IGI_IAC_DET_BALANCES%ROWTYPE;
2245       l_adjustment_id             IGI_IAC_ADJUSTMENTS.adjustment_id%type;
2246       l_get_all_prev_dist   get_all_prev_inactive_dist%ROWTYPE;
2247 
2248       l_rowid                         rowid;
2249       l_return_value			    boolean;
2250       l_Prorate_factor		    number;
2251       l_deprn_expense			    number;
2252       x 				            varchar2(100);
2253       prior_period 			    Varchar2(100);
2254       l_mesg				        VARCHAR2(500);
2255       l_adjustment_id_out    Number;
2256       l_prev_adjustment_id Number;
2257       l_transaction_type_code varchar2(50);
2258       l_transaction_id  number ;
2259       l_mass_reference_id number ;
2260       l_adjustment_status varchar2(50);
2261       l_path_name VARCHAR2(150);
2262 
2263     BEGIN
2264       l_transaction_type_code := Null;
2265       l_adjustment_status := null ;
2266       l_path_name := g_path||'do_same_price_index';
2267 
2268       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2269 		     p_full_path => l_path_name,
2270 		     p_string => '     + Same price index begin ');
2271 
2272 	/* Store the previous transaction adjustment id */
2273 /*	open c_prev_data;
2274 	fetch c_prev_data into l_prev_data;
2275     IF NOT c_prev_data%FOUND THEN
2276          debug(0,'     + Fetch the previous transaction adjustment id does not exisit');
2277     END IF;
2278 
2279 	close c_prev_data;*/
2280 
2281            IF NOT igi_iac_common_utils.Get_Latest_Transaction (
2282                        		X_book_type_code    => l_asset_hdr_rec.book_type_code,
2283                        		X_asset_id          => l_asset_hdr_rec.asset_id,
2284                        		X_Transaction_Type_Code	=> l_transaction_type_code,
2285                        		X_Transaction_Id	=> l_transaction_id,
2286                        		X_Mass_Reference_ID	=> l_mass_reference_id,
2287                        		X_Adjustment_Id		=> l_adjustment_id_out,
2288                        		X_Prev_Adjustment_Id => l_prev_adjustment_id,
2289                        		X_Adjustment_Status	=> l_adjustment_status) THEN
2290   	    		igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
2291 		     			p_full_path => l_path_name,
2292 		     			p_string => '*** Error in fetching the latest transaction');
2293 
2294                         return FALSE;
2295                    END IF;
2296 
2297       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2298 		     p_full_path => l_path_name,
2299 		     p_string => '     + Fetch the previous transaction adjustment id '||l_prev_adjustment_id);
2300 
2301 
2302     /*Get the open period and create new transaction record in the transaction headers table */
2303 	IF igi_iac_common_utils.get_open_period_info(l_asset_hdr_rec.book_type_code,l_prd_rec) THEN
2304 		l_current_period_counter:=l_prd_rec.period_counter;
2305   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2306 		     	p_full_path => l_path_name,
2307 		     	p_string => '     + Current OPen Period counter' ||l_prd_rec.period_counter );
2308 
2309 	END IF;
2310 
2311   	/*Fetch the adjustment id from the sequence*/
2312    open c_adj_id;
2313    fetch c_adj_id into l_adj_id;
2314    close c_adj_id;
2315 
2316       	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2317 		     p_full_path => l_path_name,
2318 		     p_string => '     + before Insert into trans header' );
2319 
2320   	/*Insert into transaction headers */
2321 	insert_data_trans_hdr(l_adj_id,
2322 			l_trans_rec.transaction_header_id,
2323 			NULL,
2324 			l_trans_rec.transaction_type_code,
2325 			l_trans_rec.transaction_date_entered,
2326 			l_trans_rec.mass_reference_id,
2327 			l_asset_hdr_rec.book_type_code,
2328 			l_asset_hdr_rec.Asset_id,
2329 			null,
2330 			'COMPLETE',
2331             	   	l_asset_cat_rec_old.category_id,
2332 	       		-- l_asset_cat_rec_new.category_id,
2333 			l_current_period_counter,
2334             p_event_id
2335 			);
2336 
2337       	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2338 		     p_full_path => l_path_name,
2339 		     p_string => '     + After Insert into trans header' );
2340 
2341 	/* To select the backlog data for the old distribution to be prorated into new */
2342        -- Bug 2588308 sekhar --
2343        -- Need to close the previous transaction to pick the latest catgeory --
2344 
2345        IGI_IAC_TRANS_HEADERS_PKG.update_row (
2346     		x_prev_adjustment_id                =>l_adjustment_id_out,
2347     		x_adjustment_id		            =>l_adj_id,
2348     		x_mode                              =>'R'
2349 				  );
2350 
2351 
2352 	open c_backlog_data(l_current_period_counter);
2353 	fetch c_backlog_data into l_backlog_data;
2354 	close c_backlog_data;
2355 
2356 
2357 	/* Distribution(s) involved in the transfer (old and new) and the non impacted ones*/
2358 
2359 		open c_amounts(l_current_period_counter);
2360 		fetch c_amounts into l_amounts;
2361 		close c_amounts;
2362 
2363 		open c_units;
2364 		fetch c_units into l_units;
2365 		close c_units;
2366 
2367 		open c_dist_units;
2368 		fetch c_dist_units into l_dist_units;
2369 		close c_dist_units;
2370         l_impacted_dist := Null;
2371 	FOR l_all_dist in c_all_dist
2372 	loop
2373 
2374 		/*l_reval_reserve:=l_amounts.reval_reserve;
2375 		l_general_fund:=l_amounts.general_fund;
2376 		l_Backlog_deprn_reserve:=l_amounts.backlog_deprn_reserve;
2377 		l_deprn_reserve:=l_amounts.deprn_reserve;
2378 		l_adjusted_cost:=l_amounts.adjusted_cost;
2379 		l_net_book_value:=l_amounts.net_book_value;
2380 		l_deprn_per:=l_amounts.deprn_amount;
2381 		l_op_acct:=l_amounts.operating_acct;*/
2382 
2383 		open c_start_period_counter(l_prd_rec.fiscal_year);
2384 		fetch c_start_period_counter into l_start_period_counter;
2385 		close c_start_period_counter;
2386 
2387 
2388 		open c_ytd_deprn(l_start_period_counter,l_prd_rec.period_counter);
2389 		fetch c_ytd_deprn into l_ytd_deprn;
2390 		close c_ytd_deprn;
2391 
2392 		open c_op_acct_ytd(l_start_period_counter,l_prd_rec.period_counter);
2393 		fetch c_op_acct_ytd into l_op_acct_ytd;
2394 		close c_op_acct_ytd;
2395 
2396 		open c_old_dist(l_all_dist.distribution_id);
2397 		fetch c_old_dist into l_old_dist;
2398 		close c_old_dist;
2399          If  (l_impacted_dist.distribution_id  IS NULL ) Then
2400     		open c_impacted_dist(l_all_dist.distribution_id);
2401 	    	fetch c_impacted_dist into l_impacted_dist;
2402   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2403 		     		p_full_path => l_path_name,
2404 		     		p_string => '         + impacted distribution id ' || l_all_dist.distribution_id);
2405   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2406 		     		p_full_path => l_path_name,
2407 		     		p_string => '         + new impacted distribution id ' || l_impacted_dist.distribution_id);
2408 	    	close c_impacted_dist;
2409         Else
2410             	open c_impacted_dist_new(l_all_dist.distribution_id,l_impacted_dist.distribution_id);
2411 	    	fetch c_impacted_dist_new into l_impacted_dist;
2412   	        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2413 		     		p_full_path => l_path_name,
2414 		     		p_string => '         + impacted distribution id ' || l_all_dist.distribution_id);
2415   	        igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2416 		     		p_full_path => l_path_name,
2417 		     		p_string => '         + new impacted distribution id ' || l_impacted_dist.distribution_id);
2418 
2419 	    	close c_impacted_dist_new;
2420         End if;
2421 
2422 		open c_old_dist(l_all_dist.distribution_id);
2423 		fetch c_old_dist into l_old_dist;
2424         IF c_old_dist%NOTFOUND THEN
2425   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2426 		     		p_full_path => l_path_name,
2427 		     		p_string => ' No old distribution for asset found ' || l_old_dist.distribution_id);
2428 
2429             close c_old_dist;
2430             return false;
2431         End if;
2432         close c_old_dist;
2433   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2434 		     		p_full_path => l_path_name,
2435 		     		p_string => '  + no old distribution for asset ' || l_old_dist.distribution_id);
2436 
2437         /* get the closing det balances record form iac det balances */
2438         l_adjustment_id :=l_prev_adjustment_id;
2439       --        open c_closing_det_balances(l_old_dist,l_adjustment_id);
2440 
2441         open c_closing_det_balances(l_old_dist.distribution_id,l_prev_adjustment_id);
2442         fetch c_closing_det_balances into l_closing_det_balances;
2443         IF c_closing_det_balances%NOTFOUND THEN
2444   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2445 		     		p_full_path => l_path_name,
2446 		     		p_string => '  +  old distruibution id ' || l_old_dist.distribution_id);
2447   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2448 		     		p_full_path => l_path_name,
2449 		     		p_string => '  +  adjustement id  '||l_prev_adjustment_id);
2450   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2451 		     		p_full_path => l_path_name,
2452 		     		p_string => ' Could not  find the IAC  det balances record ');
2453 
2454             close c_closing_det_balances;
2455             return false;
2456           End if;
2457   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2458 		     		p_full_path => l_path_name,
2459 		     		p_string => '  +  old distruibution id ' || l_old_dist.distribution_id);
2460   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2461 		     		p_full_path => l_path_name,
2462 		     		p_string => '  +  adjustement id  '||l_prev_adjustment_id);
2463 
2464         close c_closing_det_balances;
2465 
2466 
2467         l_closing_det_balances.adjustment_id    := l_adj_id;
2468         l_closing_det_balances.period_counter := l_current_period_counter;
2469         l_deprn_reserve_amount:=  0;
2470 
2471         Update igi_iac_transaction_headers
2472           set category_id = l_asset_cat_rec_old.category_id
2473           where adjustment_id = l_adj_id;
2474 
2475         if create_iac_acctg ( l_closing_det_balances,TRUE,'OLD',p_event_id => p_event_id) Then
2476   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2477 		     		p_full_path => l_path_name,
2478 		     		p_string => '+Accounting entries created for old');
2479          else
2480   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2481 		     		p_full_path => l_path_name,
2482 		     		p_string => 'Failed to create Accounting entries');
2483 
2484             return false;
2485         end if;
2486                     /* IF (DIFF_PRICE_INDEX_FLAG) AND
2487                        (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG) THEN
2488                            l_closing_det_balances.DEPRN_YTD := 0;
2489                       END IF;*/
2490 
2491 
2492                       insert_data_det(p_adjustment_id  =>l_adj_id,
2493         		      p_asset_id		        =>l_asset_hdr_rec.asset_id,
2494     			      p_distribution_id	        =>l_closing_det_balances.distribution_id,
2495     			      p_period_counter	        =>l_closing_det_balances.period_counter,
2496     			      p_book_type_code          =>l_asset_hdr_rec.book_type_code,
2497     			      p_adjusted_cost	        =>0,
2498     			      p_net_book_value      	=>0,
2499     			      p_reval_reserve	        =>0,
2500     			      p_reval_reserve_gen_fund	=>0,
2501     			      p_reval_reserve_backlog	=>0,
2502                       p_reval_reserve_net	        =>0,
2503     			      p_op_acct			        =>0,
2504                       p_op_acct_net			        =>0,
2505     			      p_deprn_reserve		    =>0,
2506     			      p_deprn_reserve_backlog 	=>0,
2507     			      p_deprn_ytd		        =>l_closing_det_balances.DEPRN_YTD,
2508     			      p_deprn_period	    	=>0,
2509     			      p_gen_fund_acc		    =>0,
2510     			      p_gen_fund_per		    =>0,
2511     			      p_current_reval_factor	=>l_closing_det_balances.current_reval_factor,
2512     			      p_cumulative_reval_factor =>l_closing_det_balances.cumulative_reval_factor,
2513     			      p_reval_flag		        => 'N',
2514     			      p_op_acct_ytd		        =>0,
2515     			      p_operating_acct_backlog  =>0,
2516     			      p_last_reval_date		    =>l_closing_det_balances.last_reval_date);
2517 
2518 
2519                    -- enchancement 2480915 maintiain the ytd values ---
2520                    Open  c_get_deprn_dist  (l_asset_hdr_rec.book_type_code,
2521                                       l_asset_hdr_rec.asset_id,
2522                                       l_closing_det_balances.distribution_id ,
2523                                       l_adjustment_id_out );
2524                     Fetch    c_get_deprn_dist into l_get_deprn_dist;
2525                     IF c_get_deprn_dist%FOUND THEN
2526                            /* Call to TBH for insert into IGI_IAC_ADJUSTMENTS */
2527     	            IGI_IAC_FA_DEPRN_PKG.insert_row(
2528     		            	x_rowid                             =>l_rowid,
2529                 			x_adjustment_id                =>l_adj_id,
2530     		            	x_book_type_code             =>l_asset_hdr_rec.book_type_code,
2531                 			x_asset_id                         =>l_asset_hdr_rec.asset_id,
2532      		            	x_distribution_id                 =>l_closing_det_balances.distribution_id,
2533                 			x_period_counter               =>l_closing_det_balances.period_counter,
2534                             x_deprn_period                 => 0,
2535                            x_deprn_ytd                     =>l_get_deprn_dist.deprn_ytd,
2536                             x_deprn_reserve              => 0,
2537                             x_active_flag                    => 'N',
2538                 			x_mode                              =>'R'
2539             			);
2540 
2541                     END IF;
2542                    Close c_get_deprn_dist;
2543                   -- enchancement 2480915 maintiain the ytd values ---
2544 
2545 
2546 
2547 
2548          -- before performing the new distribution account entries update with new catgeory
2549           Update igi_iac_transaction_headers
2550           set category_id = l_asset_cat_rec_new.category_id
2551           where adjustment_id = l_adj_id;
2552 
2553 
2554          IF (DIFF_PRICE_INDEX_FLAG) AND
2555            (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG) THEN
2556 
2557                l_closing_det_balances.distribution_id := l_impacted_dist.distribution_id;
2558                if create_iac_acctg ( l_closing_det_balances,TRUE,'NEW',p_event_id => p_event_id) Then
2559   	       	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2560 		     	p_full_path => l_path_name,
2561 		     	p_string => '+Accounting entries created for new ');
2562 
2563                else
2564   	       	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2565 		     	p_full_path => l_path_name,
2566 		     	p_string => 'Failed to create Accounting entries ');
2567 
2568             	return false;
2569                end if;
2570         end if;
2571 /*                     debug(0,'Create Det balances for new dist for diff price index');
2572                     debug(0,'dist id'||l_closing_det_balances.distribution_id );
2573                     debug(0,'adjustment id '|| l_adj_id);
2574                     debug(0,'period counter'|| l_closing_det_balances.period_counter);*/
2575 
2576 
2577              /*   insert_data_det(p_adjustment_id  =>l_adj_id,
2578         		      p_asset_id		        =>l_asset_hdr_rec.asset_id,
2579     			      p_distribution_id	        =>l_impacted_dist.distribution_id,
2580     			      p_period_counter	        =>l_closing_det_balances.period_counter,
2581     			      p_book_type_code          =>l_asset_hdr_rec.book_type_code,
2582     			      p_adjusted_cost	        =>0,
2583     			      p_net_book_value      	=>0,
2584     			      p_reval_reserve	        =>0,
2585     			      p_reval_reserve_gen_fund	=>0,
2586     			      p_reval_reserve_backlog	=>0,
2587     			      p_op_acct			        =>0,
2588     			      p_deprn_reserve		    =>0,
2589     			      p_deprn_reserve_backlog 	=>0,
2590     			      p_deprn_ytd		        =>0,
2591     			      p_deprn_period	    	=>0,
2592     			      p_gen_fund_acc		    =>0,
2593     			      p_gen_fund_per		    =>0,
2594     			      p_current_reval_factor	=>0,
2595     			      p_cumulative_reval_factor =>0,
2596     			      p_reval_flag		        => Null,
2597     			      p_op_acct_ytd		        =>0,
2598     			      p_operating_acct_backlog  =>0,
2599     			      p_last_reval_date		    =>l_closing_det_balances.last_reval_date);
2600         END IF;*/
2601 
2602         /* Create a  det balances record for the new distribution only for same price index*/
2603 
2604         IF (SAME_PRICE_INDEX_FLAG) AND
2605            (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG) THEN
2606 
2607 
2608              l_closing_det_balances.distribution_id  := l_impacted_dist.distribution_id;
2609              l_closing_det_balances.period_counter := l_current_period_counter;
2610             --accounting entry for YTD
2611             if create_iac_acctg ( l_closing_det_balances,TRUE,'NEW',p_event_id => p_event_id) Then
2612   	    	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2613 		     		p_full_path => l_path_name,
2614 		     		p_string => '+Accounting entries created');
2615 
2616             else
2617   	    	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2618 		     		p_full_path => l_path_name,
2619 		     		p_string => 'Failed to create Accounting entries ');
2620 
2621                 return false;
2622             end if;
2623            l_closing_det_balances.deprn_YTD := 0;
2624 
2625             insert_data_det(p_adjustment_id         =>l_adj_id,
2626     			      p_asset_id		        =>l_asset_hdr_rec.asset_id,
2627     			      p_distribution_id	        =>l_impacted_dist.distribution_id,
2628     			      p_period_counter	        =>l_current_period_counter,
2629     			      p_book_type_code          =>l_asset_hdr_rec.book_type_code,
2630     			      p_adjusted_cost	        =>l_closing_det_balances.adjustment_cost,
2631     			      p_net_book_value      	=>l_closing_det_balances.net_book_value,
2632     			      p_reval_reserve	        =>l_closing_det_balances.reval_reserve_cost,
2633     			      p_reval_reserve_gen_fund	=>l_closing_det_balances.reval_reserve_gen_fund,
2634     			      p_reval_reserve_backlog	=>l_closing_det_balances.reval_reserve_backlog,
2635                        -- Bug 2767992 Sekhar Modified for reval reserve net
2636                       p_reval_reserve_net	        =>l_closing_det_balances.reval_reserve_net,
2637     			      p_op_acct			        =>l_closing_det_balances.OPERATING_ACCT_COST,
2638                       p_op_acct_net			        =>l_closing_det_balances.OPERATING_ACCT_net,
2639     			      p_deprn_reserve		    =>l_closing_det_balances.deprn_reserve,
2640     			      p_deprn_reserve_backlog 	=>l_closing_det_balances.deprn_reserve_backlog,
2641     			      p_deprn_ytd		        =>l_closing_det_balances.deprn_YTD,
2642     			      p_deprn_period	    	=>l_closing_det_balances.deprn_period,
2643     			      p_gen_fund_acc		    =>l_closing_det_balances.general_fund_acc,
2644     			      p_gen_fund_per		    =>l_closing_det_balances.general_fund_per,
2645     			      p_current_reval_factor	=>l_closing_det_balances.current_reval_factor,
2646     			      p_cumulative_reval_factor =>l_closing_det_balances.cumulative_reval_factor,
2647     			      p_reval_flag		        => Null,
2648     			      p_op_acct_ytd		        =>l_closing_det_balances.OPERATING_ACCT_YTD,
2649     			      p_operating_acct_backlog  =>l_closing_det_balances.OPERATING_ACCT_BACKLOG,
2650     			      p_last_reval_date		    =>l_closing_det_balances.last_reval_date);
2651 
2652 
2653                                  -- enchancement 2480915 maintiain the ytd values ---
2654                    Open  c_get_deprn_dist  (l_asset_hdr_rec.book_type_code,
2655                                       l_asset_hdr_rec.asset_id,
2656                                       l_old_dist.distribution_id ,
2657                                       l_adjustment_id_out );
2658                     Fetch    c_get_deprn_dist into l_get_deprn_dist;
2659                     IF c_get_deprn_dist%FOUND THEN
2660                            /* Call to TBH for insert into IGI_IAC_ADJUSTMENTS */
2661     	            IGI_IAC_FA_DEPRN_PKG.insert_row(
2662     		            	x_rowid                             =>l_rowid,
2663                 			x_adjustment_id                =>l_adj_id,
2664     		            	x_book_type_code             =>l_asset_hdr_rec.book_type_code,
2665                 			x_asset_id                         =>l_asset_hdr_rec.asset_id,
2666      		            	x_distribution_id                 =>l_closing_det_balances.distribution_id,
2667                 			x_period_counter               =>l_closing_det_balances.period_counter,
2668                             x_deprn_period                 => l_get_deprn_dist.deprn_period,
2669                            x_deprn_ytd                     =>0,
2670                             x_deprn_reserve              =>l_get_deprn_dist.deprn_reserve,
2671                             x_active_flag                    => Null,
2672                 			x_mode                              =>'R'
2673             			);
2674 
2675                     END IF;
2676                    Close c_get_deprn_dist;
2677                   -- enchancement 2480915 maintiain the ytd values ---
2678 
2679 
2680   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2681 		     	p_full_path => l_path_name,
2682 		     	p_string => '  +  After insert into det balances ' || l_old_dist.distribution_id);
2683 
2684                 open c_closing_det_balances(l_impacted_dist.distribution_id,l_adj_id);
2685                 fetch c_closing_det_balances into l_closing_det_balances;
2686                 IF c_closing_det_balances%NOTFOUND THEN
2687   	    	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2688 		    		p_full_path => l_path_name,
2689 		    		p_string => ' Could not  find the IAC records ');
2690 
2691                     close c_closing_det_balances;
2692                     return false;
2693                 End if;
2694 
2695   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2696 		     		p_full_path => l_path_name,
2697 		    		 p_string => '  +  old distruibution id ' || l_impacted_dist.distribution_id);
2698   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2699 		     		p_full_path => l_path_name,
2700 		    		 p_string => '  +  adjustement id  '|| l_adj_id);
2701 
2702 
2703                 close c_closing_det_balances;
2704 
2705             ELSIF (NOT (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG))  THEN
2706 
2707                     l_closing_det_balances.distribution_id  := l_impacted_dist.distribution_id;
2708                     insert_data_det(p_adjustment_id         =>l_adj_id,
2709     			      p_asset_id		        =>l_asset_hdr_rec.asset_id,
2710     			      p_distribution_id	        =>l_impacted_dist.distribution_id,
2711     			      p_period_counter	        =>l_current_period_counter,
2712     			      p_book_type_code          =>l_asset_hdr_rec.book_type_code,
2713     			      p_adjusted_cost	        =>0,
2714     			      p_net_book_value      	=>0,
2715     			      p_reval_reserve	        =>0,
2716                       p_reval_reserve_net	        =>0,
2717     			      p_reval_reserve_gen_fund	=>0,
2718     			      p_reval_reserve_backlog	=>0,
2719     			      p_op_acct			        =>0,
2720                       p_op_acct_net			        =>0,
2721     			      p_deprn_reserve		    =>0,
2722     			      p_deprn_reserve_backlog 	=>0,
2723     			      p_deprn_ytd		        =>0,
2724     			      p_deprn_period	    	=>0,
2725     			      p_gen_fund_acc		    =>0,
2726     			      p_gen_fund_per		    =>0,
2727     			      p_current_reval_factor	=>0,
2728     			      p_cumulative_reval_factor =>0,
2729     			      p_reval_flag		        => Null,
2730     			      p_op_acct_ytd		        =>0,
2731     			      p_operating_acct_backlog  =>0,
2732     			      p_last_reval_date		    =>l_closing_det_balances.last_reval_date);
2733 
2734 
2735 		END IF;
2736 		/* End of loop for insert into det_balances table */
2737 
2738 	End Loop;
2739 	 /* End of loop for all active distributions */
2740 
2741 
2742     /* Update the asset balanaces to zero in case new category is has no prof and indexed revalutions */
2743 
2744     IF NOT (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG) THEN
2745             igi_iac_asset_balances_pkg.update_row(
2746 	    			X_asset_id		          => l_asset_hdr_rec.asset_id,
2747 					X_book_type_code	      => l_asset_hdr_rec.book_type_code,
2748 					X_period_counter	      => l_current_period_counter ,
2749 					X_net_book_value	      => 0,
2750 					X_adjusted_cost		      => 0,
2751 					X_operating_acct	      => 0,
2752 					X_reval_reserve		      => 0,
2753 					X_deprn_amount		      => 0,
2754 					X_deprn_reserve		      => 0,
2755 					X_backlog_deprn_reserve   => 0,
2756 					X_general_fund		      => 0,
2757 					X_last_reval_date	      => Null,
2758 					X_current_reval_factor	  => 0,
2759         			X_cumulative_reval_factor => 0) ;
2760 
2761     END IF;
2762 
2763     /* get the ytd sum of the active distributiions*/
2764     l_deprn_ytd := 0;
2765     /* bring forward all the inactive distributions to the current adjustment */
2766     FOR  l_get_all_prev_dist in get_all_prev_inactive_dist (l_prev_adjustment_id) LOOP
2767 
2768 
2769                     IF l_get_all_prev_dist.active_flag = 'N' THEN
2770                       /*create a record with new distribution id */
2771                    /*IF (DIFF_PRICE_INDEX_FLAG) AND
2772                        (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG) THEN
2773                             l_get_all_prev_dist.deprn_ytd := 0;
2774                       END IF;*/
2775 
2776                     insert_data_det(p_adjustment_id         =>l_adj_id,
2777     			      p_asset_id		        =>l_asset_hdr_rec.asset_id,
2778     			      p_distribution_id	        =>l_get_all_prev_dist.distribution_id,
2779     			      p_period_counter	        =>l_current_period_counter,
2780     			      p_book_type_code          =>l_get_all_prev_dist.book_type_code,
2781     			      p_adjusted_cost	          =>l_get_all_prev_dist.adjustment_cost,
2782     			      p_net_book_value      	=>l_get_all_prev_dist.net_book_value,
2783     			      p_reval_reserve	        =>l_get_all_prev_dist.reval_reserve_cost,
2784     			      p_reval_reserve_gen_fund	=>l_get_all_prev_dist.reval_reserve_gen_fund,
2785     			      p_reval_reserve_backlog	=>l_get_all_prev_dist.reval_reserve_backlog,
2786     			      p_op_acct			        =>l_get_all_prev_dist.OPERATING_ACCT_COST,
2787     			      p_deprn_reserve		    =>l_get_all_prev_dist.deprn_reserve,
2788     			      p_deprn_reserve_backlog 	=>l_get_all_prev_dist.deprn_reserve_backlog,
2789     			      p_deprn_ytd		        => l_get_all_prev_dist.deprn_ytd,
2790                        -- Bug 2767992 Sekhar Modified for reval reserve net
2791                       p_reval_reserve_net	        =>l_get_all_prev_dist.reval_reserve_net,
2792                       p_op_acct_net			        =>l_get_all_prev_dist.OPERATING_ACCT_net,
2793                      -- p_deprn_ytd		        => 0,
2794     			      p_deprn_period	    	=>l_get_all_prev_dist.deprn_period,
2795     			      p_gen_fund_acc		    =>l_get_all_prev_dist.general_fund_acc,
2796     			      p_gen_fund_per		    =>l_get_all_prev_dist.general_fund_per,
2797     			      p_current_reval_factor	=>l_get_all_prev_dist.current_reval_factor,
2798     			      p_cumulative_reval_factor =>l_get_all_prev_dist.cumulative_reval_factor,
2799     			      p_reval_flag		        => l_get_all_prev_dist.active_flag,
2800     			      p_op_acct_ytd		        =>l_get_all_prev_dist.OPERATING_ACCT_YTD,
2801     			      p_operating_acct_backlog  =>l_get_all_prev_dist.OPERATING_ACCT_BACKLOG,
2802     			      p_last_reval_date		    =>l_get_all_prev_dist.last_reval_date);
2803 
2804                     -- enchancement 2480915 maintiain the ytd values ---
2805                    Open  c_get_deprn_dist  (l_asset_hdr_rec.book_type_code,
2806                                       l_asset_hdr_rec.asset_id,
2807                                       l_get_all_prev_dist.distribution_id ,
2808                                       l_adjustment_id_out );
2809                     Fetch    c_get_deprn_dist into l_get_deprn_dist;
2810                     IF c_get_deprn_dist%FOUND THEN
2811                            /* Call to TBH for insert into IGI_IAC_ADJUSTMENTS */
2812     	            IGI_IAC_FA_DEPRN_PKG.insert_row(
2813     		            	x_rowid                             =>l_rowid,
2814                 			x_adjustment_id                =>l_adj_id,
2815     		            	x_book_type_code             =>l_asset_hdr_rec.book_type_code,
2816                 			x_asset_id                         =>l_asset_hdr_rec.asset_id,
2817      		            	x_distribution_id                 =>l_get_all_prev_dist.distribution_id,
2818                 			x_period_counter               =>l_closing_det_balances.period_counter,
2819                             x_deprn_period                 => l_get_deprn_dist.deprn_period,
2820                            x_deprn_ytd                     =>l_get_deprn_dist.deprn_ytd,
2821                             x_deprn_reserve              =>l_get_deprn_dist.deprn_reserve,
2822                             x_active_flag                    => 'N',
2823                 			x_mode                              =>'R'
2824             			);
2825 
2826                     END IF;
2827                    Close c_get_deprn_dist;
2828                   -- enchancement 2480915 maintiain the ytd values ---
2829 
2830 
2831                 ELSE
2832                     l_deprn_ytd := l_deprn_ytd + l_get_all_prev_dist.deprn_ytd;
2833                  END IF;
2834 
2835     END LOOP;
2836 
2837 
2838 
2839     /*Terminate the previous active row with the adjustment_id_out in transaction_headers table*/
2840       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2841 		     p_full_path => l_path_name,
2842 		     p_string => ' close the prevooius adjusment');
2843       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2844 		     p_full_path => l_path_name,
2845 		     p_string => 'old adjusment id ' || l_adjustment_id_out);
2846       igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2847 		     p_full_path => l_path_name,
2848 		     p_string => 'current adjusment id ' || l_adj_id);
2849 
2850 	IGI_IAC_TRANS_HEADERS_PKG.update_row (
2851     		x_prev_adjustment_id                =>l_adjustment_id_out,
2852     		x_adjustment_id		            =>l_adj_id,
2853     		x_mode                              =>'R'
2854 				  );
2855 
2856 	RETURN(TRUE);
2857 
2858 
2859 EXCEPTION
2860  WHEN OTHERS THEN
2861     igi_iac_debug_pkg.debug_unexpected_msg(p_full_path => l_path_name);
2862     l_mesg:=SQLERRM;
2863     FA_SRVR_MSG.Add_Message(
2864 	                Calling_FN 	=> l_calling_function ,
2865         	        Name 		=> 'IGI_IAC_EXCEPTION',
2866         	        TOKEN1		=> 'PACKAGE',
2867         	        VALUE1		=> 'Reclass',
2868         	        TOKEN2		=> 'ERROR_MESSAGE',
2869         	        VALUE2		=> l_mesg,
2870                     APPLICATION => 'IGI');
2871 
2872     RETURN(FALSE);
2873 
2874 END; --do_same_price_index
2875 
2876 
2877     PROCEDURE Debug_Period(p_period igi_iac_types.prd_rec) IS
2878   	  l_path_name VARCHAR2(150);
2879     BEGIN
2880   	  l_path_name := g_path||'debug_period';
2881   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2882 		     p_full_path => l_path_name,
2883 		     p_string => '         Period counter :'||to_char(p_period.period_counter));
2884   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2885 		     p_full_path => l_path_name,
2886 		     p_string => '         Period Num :'||to_char(p_period.period_num));
2887   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2888 		     p_full_path => l_path_name,
2889 		     p_string => '         Fiscal Year :'||to_char(p_period.fiscal_year));
2890   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2891 		     p_full_path => l_path_name,
2892 		     p_string => '         Period Name :'||p_period.period_name);
2893 
2894     END Debug_Period;
2895 
2896     PROCEDURE Debug_Asset(p_asset igi_iac_types.iac_reval_input_asset) IS
2897   	  l_path_name VARCHAR2(150);
2898     BEGIN
2899   	  l_path_name := g_path||'debug_asset';
2900   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2901 		     p_full_path => l_path_name,
2902 		     p_string => '         Net book value :'||to_char(p_asset.net_book_value));
2903   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2904 		     p_full_path => l_path_name,
2905 		     p_string => '         Adjusted Cost :'||to_char(p_asset.adjusted_cost));
2906   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2907 		     p_full_path => l_path_name,
2908 		     p_string => '         Operating Account :'||to_char(p_asset.operating_acct));
2909   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2910 		     p_full_path => l_path_name,
2911 		     p_string => '         Reval Reserve :'||to_char(p_asset.reval_reserve));
2912   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2913 		     p_full_path => l_path_name,
2914 		     p_string => '         Deprn Amount :'||to_char(p_asset.deprn_amount));
2915   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2916 		     p_full_path => l_path_name,
2917 		     p_string => '         Deprn Reserve :'||to_char(p_asset.deprn_reserve));
2918   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2919 		     p_full_path => l_path_name,
2920 		     p_string => '         Backlog Deprn Reserve :'||to_char(p_asset.backlog_deprn_reserve));
2921   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2922 		     p_full_path => l_path_name,
2923 		     p_string => '         General Fund :'||to_char(p_asset.general_fund));
2924   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2925 		     p_full_path => l_path_name,
2926 		     p_string => '         Current Reval Factor :'||to_char(p_asset.current_reval_factor));
2927   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
2928 		     p_full_path => l_path_name,
2929 		     p_string => '         Cumulative Reval Factor :'||to_char(p_asset.Cumulative_reval_factor));
2930 
2931     END Debug_Asset;
2932 
2933 -- ======================================================================
2934 -- DIFFERENT PRICE INDEX RECLASS
2935 -- function do all that needed for if both catgeories old and new has same
2936 -- price index
2937 -- ======================================================================
2938 FUNCTION Do_Revaluation_Catchup(
2939         p_book_type_code                 VARCHAR2,
2940         p_asset_id                       NUMBER,
2941         p_category_id                    NUMBER,
2942         p_calling_function               VARCHAR2,
2943         p_event_id                       number
2944     ) return BOOLEAN IS
2945 
2946 CURSOR c_allow_indexed_reval_flag IS
2947         SELECT allow_indexed_reval_flag
2948         FROM igi_iac_category_books
2949         WHERE book_type_code = p_book_type_code
2950         AND category_id = p_category_id;
2951 
2952         CURSOR c_period_num_for_catchup IS
2953         SELECT period_num_for_catchup
2954         FROM igi_iac_book_controls
2955         WHERE book_type_code = p_book_type_code;
2956 
2957         CURSOR c_prof_occ_reval_periods is
2958         SELECT revaluation_type,revaluation_period,revaluation_factor,new_cost,current_cost
2959         FROM igi_iac_revaluations rev,
2960              igi_iac_reval_asset_rules rul
2961         WHERE rev.revaluation_id = rul.revaluation_id
2962         AND   rev.book_type_code = l_asset_hdr_rec.BOOK_TYPE_CODE
2963         AND   rev.book_type_code = rul.book_type_code
2964         AND   rul.revaluation_type in ('O','P')
2965        -- bug 2844230 Sekhar
2966        -- Not required unable to fecth previous revaluations
2967       --  AND   rul.category_id = l_asset_cat_rec_new.category_id
2968         AND   rul.asset_id = l_asset_hdr_rec.ASSET_ID
2969         order by revaluation_period;
2970 
2971         /* Cursor to get fully reserved, fully retired info for the asset from FA */
2972    	    CURSOR c_fa_books(p_asset_id fa_books.asset_id%TYPE) IS
2973    	        SELECT salvage_value,cost
2974    	        FROM fa_books
2975    	        WHERE book_type_code = p_book_type_code
2976    	        AND   asset_id = p_asset_id
2977    	        AND   transactioN_header_id_out is NULL ;
2978 
2979 
2980         l_dpis_period_counter       NUMBER;
2981         l_open_period               igi_iac_types.prd_rec;
2982         l_period_info               igi_iac_types.prd_rec;
2983         l_allow_indexed_reval_flag  igi_iac_category_books.allow_indexed_reval_flag%TYPE;
2984         l_period_num_for_catchup    igi_iac_book_controls.period_num_for_catchup%TYPE;
2985         l_idx1                      BINARY_INTEGER;
2986         l_idx2                      BINARY_INTEGER;
2987         l_reval_control             igi_iac_types.iac_reval_control_tab;
2988         l_reval_asset_params        igi_iac_types.iac_reval_asset_params_tab;
2989         l_reval_input_asset         igi_iac_types.iac_reval_asset_tab;
2990         l_reval_output_asset        igi_iac_types.iac_reval_asset_tab;
2991         l_reval_output_asset_mvmt   igi_iac_types.iac_reval_asset_tab;
2992         l_reval_asset_rules         igi_iac_types.iac_reval_asset_rules_tab;
2993         l_prev_rate_info            igi_iac_types.iac_reval_rates_tab;
2994         l_curr_rate_info_first      igi_iac_types.iac_reval_rates_tab;
2995         l_curr_rate_info_next       igi_iac_types.iac_reval_rates_tab;
2996         l_curr_rate_info            igi_iac_types.iac_reval_rates_tab;
2997         l_reval_exceptions          igi_iac_types.iac_reval_exceptions_tab;
2998         l_fa_asset_info             igi_iac_types.iac_reval_fa_asset_info_tab;
2999         l_reval_params              igi_iac_types.iac_reval_params;
3000         l_reval_asset               igi_iac_types.iac_reval_input_asset;
3001         l_reval_asset_out           igi_iac_types.iac_reval_output_asset;
3002         l_revaluation_id            igi_iac_revaluations.revaluation_id%TYPE;
3003         l_user_id                   NUMBER;
3004         l_login_id                  NUMBER;
3005         l_current_reval_factor      igi_iac_asset_balances.current_reval_factor%TYPE;
3006         l_cumulative_reval_factor   igi_iac_asset_balances.cumulative_reval_factor%TYPE;
3007         l_last_reval_period         igi_iac_asset_balances.period_counter%TYPE;
3008         l_prof_occ_reval_periods    c_prof_occ_reval_periods%ROWTYPE;
3009         l_rowid			    VARCHAR2(25);
3010 	/* Bug 2961656 vgadde 08-Jul-2003 Start(1) */
3011         l_fa_deprn_amount_py        NUMBER;
3012         l_fa_deprn_amount_cy        NUMBER;
3013         l_last_asset_period         NUMBER;
3014         l_salvage_value             Number;
3015         l_cost                      Number;
3016 	/* Bug 2961656 vgadde 08-Jul-2003 End(1) */
3017         l_path_name VARCHAR2(150);
3018     BEGIN
3019         l_idx1 := 0;
3020         l_idx2 := 0;
3021         l_user_id := fnd_global.user_id;
3022         l_login_id := fnd_global.login_id;
3023         l_path_name := g_path||'do_revaluation_catchup';
3024 
3025   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3026 		     	p_full_path => l_path_name,
3027 		     	p_string => '=========================================');
3028   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3029 		     	p_full_path => l_path_name,
3030 		     	p_string => 'Start of IAC Prior Additions  Processing....');
3031   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3032 		     	p_full_path => l_path_name,
3033 		     	p_string => '-----Parameters from FA code hook-----------');
3034   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3035 		     	p_full_path => l_path_name,
3036 		     	p_string => '     Book type code  :'||p_book_type_code);
3037   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3038 		     	p_full_path => l_path_name,
3039 		     	p_string => '     Category Id     :'||to_char(p_category_id));
3040   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3041 		     	p_full_path => l_path_name,
3042 		     	p_string => '     Asset Id        :'||to_char(p_asset_id));
3043   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3044 		     	p_full_path => l_path_name,
3045 		     	p_string => '--------------------------------------------');
3046 
3047 
3048         OPEN c_allow_indexed_reval_flag;
3049         FETCH c_allow_indexed_reval_flag INTO l_allow_indexed_reval_flag;
3050         CLOSE c_allow_indexed_reval_flag;
3051 
3052       /*  Debug('     Allow Indexed reval flag :'||l_allow_indexed_reval_flag);
3053         IF (l_allow_indexed_reval_flag = 'N') THEN
3054             return TRUE;
3055         END IF;*/
3056 
3057         IF NOT igi_iac_common_utils.get_dpis_period_counter(p_book_type_code,
3058                                                             p_asset_id,
3059                                                             l_dpis_period_counter) THEN
3060   	      igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3061 		     	p_full_path => l_path_name,
3062 		     	p_string => '*** Error in Fetching DPIS period counter');
3063               return FALSE;
3064         END IF;
3065 
3066         IF NOT igi_iac_common_utils.get_open_period_info(p_book_type_code,
3067                                                          l_open_period) THEN
3068   	      igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3069 		     	p_full_path => l_path_name,
3070 		     	p_string => '*** Error in Fetching Open period info for book');
3071               return FALSE;
3072         END IF;
3073 
3074         OPEN c_period_num_for_catchup;
3075         FETCH c_period_num_for_catchup INTO l_period_num_for_catchup;
3076         CLOSE c_period_num_for_catchup;
3077 
3078 
3079   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3080 		     p_full_path => l_path_name,
3081 		     p_string => '     Revaluation catchup period for the book :'||to_char(l_period_num_for_catchup));
3082   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3083 		     p_full_path => l_path_name,
3084 		     p_string => '------- Revaluation catchup periods for the asset -------');
3085 
3086         /* get the first revaluation period */
3087         OPEN c_prof_occ_reval_periods;
3088         FETCH c_prof_occ_reval_periods into l_prof_occ_reval_periods;
3089         IF NOT c_prof_occ_reval_periods%FOUND THEN
3090              l_prof_occ_reval_periods.revaluation_period :=l_open_period.period_counter-1;
3091         END IF;
3092         CLOSE  c_prof_occ_reval_periods;
3093 
3094         /* do revaluations till the first period of revaluations found in the asset rules*/
3095 
3096         FOR l_period_counter IN l_dpis_period_counter..l_open_period.period_counter-1 LOOP
3097 
3098             IF NOT igi_iac_common_utils.get_period_info_for_counter(p_book_type_code,
3099                                                                     l_period_counter,
3100                                                                     l_period_info) THEN
3101   		igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3102 		     		p_full_path => l_path_name,
3103 		     		p_string => '*** Error in fetching period info');
3104 
3105                 return FALSE;
3106             END IF;
3107 
3108 
3109 
3110             IF (l_period_num_for_catchup = l_period_info.period_num) THEN
3111                 Debug_Period(l_period_info);
3112   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3113 		     		p_full_path => l_path_name,
3114 		     		p_string => 'catch up Reval period ' || to_char(l_period_counter));
3115 
3116                 l_idx1 := l_idx1 + 1;
3117                 l_reval_control(l_idx1).revaluation_mode := 'L'; -- Live Mode
3118                 l_reval_asset_rules(l_idx1).revaluation_type := 'O'; -- Occasional
3119                 l_reval_asset_params(l_idx1).asset_id := p_asset_id;
3120                 l_reval_asset_params(l_idx1).category_id := p_category_id;
3121                 l_reval_asset_params(l_idx1).book_type_code := p_book_type_code;
3122                 l_reval_asset_params(l_idx1).period_counter := l_period_counter;
3123 
3124             END IF;
3125         END LOOP;
3126 
3127   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3128 		     p_full_path => l_path_name,
3129 		     p_string => '------------------------------------------------------');
3130 
3131         /* Get the number of professional revaluations done and intialize the structure */
3132   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3133 		     p_full_path => l_path_name,
3134 		     p_string => 'Get the number of professional revaluations done and intialize the structure');
3135 
3136         IF l_idx1 = 0 then
3137          FOR l_period_counter IN l_dpis_period_counter..l_open_period.period_counter-1 LOOP
3138 
3139             IF NOT igi_iac_common_utils.get_period_info_for_counter(p_book_type_code,
3140                                                                     l_period_counter,
3141                                                                     l_period_info) THEN
3142   		igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3143 		     		p_full_path => l_path_name,
3144 		     		p_string => '*** Error in fetching period info');
3145 
3146                 return FALSE;
3147             END IF;
3148 
3149             FOR l_prof_occ_reval_periods in c_prof_occ_reval_periods LOOP
3150 
3151                 IF (l_prof_occ_reval_periods.revaluation_period = l_period_counter) THEN
3152                     Debug_Period(l_period_info);
3153   	    	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3154 		     		p_full_path => l_path_name,
3155 		     		p_string => ' Reval period ' || to_char(l_period_counter));
3156   	    	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3157 		     		p_full_path => l_path_name,
3158 		     		p_string => ' Reval type ' || l_prof_occ_reval_periods.revaluation_type);
3159   	    	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3160 		     		p_full_path => l_path_name,
3161 		     		p_string => ' Reval new cost '|| l_prof_occ_reval_periods.new_cost);
3162   	    	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3163 		     		p_full_path => l_path_name,
3164 		     		p_string => ' Reval current cost '|| l_prof_occ_reval_periods.current_cost);
3165 
3166                     l_idx1 := l_idx1 + 1;
3167                     l_reval_control(l_idx1).revaluation_mode := 'L'; -- Live Mode
3168                     l_reval_asset_rules(l_idx1).revaluation_type :=l_prof_occ_reval_periods.revaluation_type; -- Occasional
3169                     l_reval_asset_params(l_idx1).asset_id := p_asset_id;
3170                     l_reval_asset_params(l_idx1).category_id := p_category_id;
3171                     l_reval_asset_params(l_idx1).book_type_code := p_book_type_code;
3172                     l_reval_asset_params(l_idx1).period_counter := l_period_counter;
3173                     l_reval_asset_rules(l_idx1).new_cost := l_prof_occ_reval_periods.new_cost;
3174                     l_reval_asset_rules(l_idx1).current_cost :=l_prof_occ_reval_periods.current_cost;
3175 
3176             END IF;
3177            END LOOP;
3178         END LOOP;
3179         END IF;
3180 
3181   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3182 		     p_full_path => l_path_name,
3183 		     p_string => '------------------------------------------------------');
3184         /* Get the number of professional revaluations done and intialize the structure */
3185 
3186 
3187         IF (l_idx1 = 0) THEN /* No catch-up required */
3188   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3189 		     		p_full_path => l_path_name,
3190 		     		p_string => ' No revaluation catchup periods found');
3191 
3192             return TRUE;
3193         END IF;
3194 
3195 	/* Bug 2961656 vgadde 08-Jul-2003 Start(2) */
3196         IF NOT igi_iac_catchup_pkg.get_FA_Deprn_Expense(p_asset_id,
3197                                  p_book_type_code,
3198                                  l_open_period.period_counter,
3199                                  'RECLASS',
3200                                  NULL,
3201                                  NULL,
3202                                  l_fa_deprn_amount_py,
3203                                  l_fa_deprn_amount_cy,
3204                                  l_last_asset_period) THEN
3205   	    	igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3206 		     	p_full_path => l_path_name,
3207 		     	p_string => '*** Error in get_FA_Deprn_Expense function');
3208 
3209                 return FALSE;
3210         END IF;
3211 	/* Bug 2961656 vgadde 08-Jul-2003 End(2) */
3212        /*Salavge value correction*/
3213                 -- resreve
3214                 OPEN c_fa_books(p_asset_id);
3215             	FETCH c_fa_books into   l_salvage_value,
3216                                         l_cost;
3217             	CLOSE c_fa_books;
3218                 IF l_salvage_value <> 0 Then
3219   		   igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3220 		     			p_full_path => l_path_name,
3221 		     			p_string => '+Salavge Value Correction deprn_amount_py before :' ||l_fa_deprn_amount_py);
3222 
3223                  -- deprn amount l_fa_deprn_amount_py
3224                 IF NOT igi_iac_salvage_pkg.correction(p_asset_id => p_asset_id,
3225                                                       P_book_type_code =>p_book_type_code,
3226                                                       P_value=>l_fa_deprn_amount_py,
3227                                                       P_cost=>l_cost,
3228                                                       P_salvage_value=>l_salvage_value,
3229                                                       P_calling_program=>'RECLASS') THEN
3230   	    	    igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3231 		     		p_full_path => l_path_name,
3232 		     		p_string => '+Salvage Value Correction Failed : ');
3233 
3234                     return false;
3235                 END IF;
3236 
3237   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3238 		     p_full_path => l_path_name,
3239 		     p_string => '+Salavge Value Correction deprn_amount_py after :' ||l_fa_deprn_amount_py );
3240   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3241 		     p_full_path => l_path_name,
3242 		     p_string => '+Salavge Value Correction deprn_amount_cy before :' ||l_fa_deprn_amount_cy);
3243 
3244 
3245                    -- deprn l_fa_deprn_amount_cy
3246                    IF NOT igi_iac_salvage_pkg.correction(p_asset_id => p_asset_id,
3247                                                       P_book_type_code =>p_book_type_code,
3248                                                       P_value=>l_fa_deprn_amount_cy,
3249                                                       P_cost=>l_cost,
3250                                                       P_salvage_value=>l_salvage_value,
3251                                                       P_calling_program=>'RECLASS') THEN
3252 
3253   			igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3254 		     			p_full_path => l_path_name,
3255 		     			p_string => '+Salvage Value Correction Failed : ');
3256 
3257                     return false;
3258                   END IF;
3259 
3260   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3261 		     	p_full_path => l_path_name,
3262 		    	 p_string => '+Salavge Value Correction deprn_amount_cy after :' ||l_fa_deprn_amount_cy);
3263 
3264                  END IF;
3265             /*salvage value correction*/
3266 
3267   	  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3268 		     	p_full_path => l_path_name,
3269 		     	p_string => '     Calling Revaluation Initialization program ');
3270 
3271         IF NOT igi_iac_catchup_pkg.do_reval_init_struct(l_open_period.period_counter,
3272                                                         l_reval_control,
3273                                                         l_reval_asset_params,
3274                                                         l_reval_input_asset,
3275                                                         l_reval_output_asset,
3276                                                         l_reval_output_asset_mvmt,
3277                                                         l_reval_asset_rules,
3278                                                         l_prev_rate_info,
3279                                                         l_curr_rate_info_first,
3280                                                         l_curr_rate_info_next,
3281                                                         l_curr_rate_info,
3282                                                         l_reval_exceptions,
3283                                                         l_fa_asset_info,
3284                                                         l_fa_deprn_amount_py, 	-- For bug 2961656
3285                                                         l_fa_deprn_amount_cy,	-- For bug 2961656
3286                                                         l_last_asset_period,	-- For bug 2961656
3287                                                         'RECLASS') THEN
3288 
3289   	      igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3290 		     		p_full_path => l_path_name,
3291 		     		p_string => '*** Error in catchup pkg for revaluation initialization');
3292 
3293             return FALSE;
3294         END IF;
3295 
3296   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3297 		     p_full_path => l_path_name,
3298 		     p_string => '     Back from Revaluation Initialization');
3299 
3300         FOR l_idx2 IN 1..l_idx1 LOOP
3301 
3302             IF (l_idx2 <> 1) THEN
3303 
3304                 l_reval_asset := l_reval_output_asset(l_idx2 - 1);
3305 
3306   		  igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3307 		     		p_full_path => l_path_name,
3308 		     		p_string => ' Doing depreciation catchup for the periods between revaluation');
3309 
3310                 IF NOT igi_iac_catchup_pkg.do_deprn_catchup(l_reval_asset_params(l_idx2 - 1).period_counter +1,
3311                                                      l_reval_asset_params(l_idx2).period_counter  +1,
3312                                                      l_open_period.period_counter,
3313                                                      FALSE,
3314                                                      'RECLASS',
3315                                                      l_fa_deprn_amount_py, 	-- For bug 2961656
3316                                                      l_fa_deprn_amount_cy,	-- For bug 2961656
3317                                                      l_last_asset_period,	-- For bug 2961656
3318                                                      NULL,			-- For bug 2961656
3319                                                      NULL,			-- For bug 2961656
3320                                                      l_reval_asset ,
3321                                                      p_event_id => p_event_id)THEN
3322   			igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3323 		     			p_full_path => l_path_name,
3324 		     			p_string => '*** Error in depreciation catchup');
3325 
3326                         return FALSE;
3327                 END IF;
3328 
3329   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3330 		     		p_full_path => l_path_name,
3331 		     		p_string => 'Back from depreciation catchup');
3332 
3333 
3334                 l_current_reval_factor := l_reval_input_asset(l_idx2).current_reval_factor;
3335                 l_cumulative_reval_factor := l_reval_input_asset(l_idx2).cumulative_reval_factor;
3336                 l_reval_input_asset(l_idx2) := l_reval_asset;
3337                 l_reval_input_asset(l_idx2).current_reval_factor := l_current_reval_factor;
3338                 l_reval_input_asset(l_idx2).cumulative_reval_factor := l_cumulative_reval_factor;
3339             END IF;
3340 
3341             IF (l_idx2 = l_idx1) THEN
3342                 /* Last revaluation - Insert records into revaluation tables*/
3343        /*         SELECT igi_iac_revaluations_s.nextval
3344                 INTO l_revaluation_id
3345                 FROM DUAL;
3346                 Debug(0,'Last Revaluation - Inseting into igi_iac_revaluations');
3347                 Debug(0,'Revaluation Id :'||to_char(l_revaluation_id));
3348 
3349 
3350 
3351                INSERT INTO igi_iac_revaluations
3352                        (revaluation_id,
3353                         book_type_code,
3354                         revaluation_date,
3355                         revaluation_period,
3356                         status,
3357                         reval_request_id,
3358                         create_request_id,
3359                         calling_program,
3360                         last_update_date,
3361                         created_by,
3362                         last_update_login,
3363                         last_updated_by,
3364                         creation_date)
3365                 VALUES (l_revaluation_id,
3366                         p_book_type_code,
3367                         sysdate,
3368                         l_reval_asset_params(l_idx1).period_counter,
3369                         'NEW',
3370                         NULL,
3371                         NULL,
3372                         'RECLASS',
3373                         sysdate,
3374                         l_user_id,
3375                         l_login_id,
3376                         l_user_id,
3377                         sysdate);
3378 
3379                 Debug(0,'Inserting into igi_iac_reval_asset_rules');
3380                 INSERT INTO igi_iac_reval_asset_rules
3381                        (revaluation_id,
3382                         book_type_code,
3383                         category_id,
3384                         asset_id,
3385                         revaluation_factor,
3386                         revaluation_type,
3387                         new_cost,
3388                         current_cost,
3389                         selected_for_reval_flag,
3390                         selected_for_calc_flag,
3391                         created_by,
3392                         creation_date,
3393                         last_update_login,
3394                         last_update_date,
3395                         last_updated_by,
3396                         allow_prof_update)
3397                 VALUES (l_revaluation_id,
3398                         l_reval_asset_params(l_idx1).book_type_code,
3399                         l_reval_asset_params(l_idx1).category_id,
3400                         l_reval_asset_params(l_idx1).asset_id,
3401                         l_reval_asset_rules(l_idx1).revaluation_factor,
3402                         l_reval_asset_rules(l_idx1).revaluation_type,
3403                         l_reval_asset_rules(l_idx1).new_cost,
3404                         l_reval_input_asset(l_idx2).adjusted_cost,
3405                         'Y',
3406                         'N',
3407                         l_user_id,
3408                         sysdate,
3409                         l_login_id,
3410                         sysdate,
3411                         l_user_id,
3412                         NULL);*/
3413 
3414                         /* Last revaluation - Insert records into revaluation tables*/
3415 
3416   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3417 		     	p_full_path => l_path_name,
3418 		     	p_string => '		Last Revaluation - Inserting into igi_iac_revaluations');
3419 
3420 
3421 		l_rowid := NULL;
3422 		l_revaluation_id := NULL;
3423 
3424                 igi_iac_revaluations_pkg.insert_row
3425                        (l_rowid,
3426                        	l_revaluation_id,
3427                         p_book_type_code,
3428                         sysdate,
3429                         l_reval_asset_params(l_idx1).period_counter,
3430                         'NEW',
3431                         NULL,
3432                         NULL,
3433                         'ADDITION',
3434                         X_event_id => p_event_id);
3435 
3436   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3437 		     	p_full_path => l_path_name,
3438 		     	p_string => '		Revaluation Id :'||to_char(l_revaluation_id));
3439 
3440   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3441 		     	p_full_path => l_path_name,
3442 		     	p_string => '		Inserting into igi_iac_reval_asset_rules');
3443 
3444                 l_rowid := NULL;
3445                 igi_iac_reval_asset_rules_pkg.insert_row
3446                        (l_rowid,
3447                        	l_revaluation_id,
3448                         l_reval_asset_params(l_idx1).book_type_code,
3449                         l_reval_asset_params(l_idx1).category_id,
3450                         l_reval_asset_params(l_idx1).asset_id,
3451                         l_reval_asset_rules(l_idx1).revaluation_factor,
3452                         l_reval_asset_rules(l_idx1).revaluation_type,
3453                         l_reval_asset_rules(l_idx1).new_cost,
3454                         l_reval_input_asset(l_idx2).adjusted_cost,
3455                         'Y',
3456                         'N',
3457                         NULL);
3458 
3459 
3460 		l_last_reval_period := l_reval_asset_params(l_idx2).period_counter;
3461 		l_reval_asset_params(l_idx2).period_counter := l_open_period.period_counter ;
3462 		l_reval_input_asset(l_idx2).period_counter := l_open_period.period_counter ;
3463 		l_reval_asset_params(l_idx2).revaluation_id := l_revaluation_id;
3464 		l_reval_asset_rules(l_idx2).revaluation_id := l_revaluation_id;
3465 
3466   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3467 		     		p_full_path => l_path_name,
3468 		     		p_string => '		Period counter passed to Reval CRUD :'||to_char(l_open_period.period_counter ));
3469 
3470 
3471             END IF;
3472 
3473             l_reval_params.reval_control := l_reval_control(l_idx2);
3474             l_reval_params.reval_asset_params := l_reval_asset_params(l_idx2);
3475             l_reval_params.reval_input_asset := l_reval_input_asset(l_idx2);
3476             l_reval_params.reval_output_asset := l_reval_input_asset(l_idx2);
3477             l_reval_params.reval_output_asset_mvmt := l_reval_output_asset_mvmt(l_idx2);
3478             l_reval_params.reval_asset_rules := l_reval_asset_rules(l_idx2);
3479             l_reval_params.reval_prev_rate_info := l_prev_rate_info(l_idx2);
3480             l_reval_params.reval_curr_rate_info_first := l_curr_rate_info_first(l_idx2);
3481             l_reval_params.reval_curr_rate_info_next := l_curr_rate_info_next(l_idx2);
3482             l_reval_params.reval_asset_exceptions := l_reval_exceptions(l_idx2);
3483             l_reval_params.fa_asset_info := l_fa_asset_info(l_idx2);
3484 
3485             /* call revaluation processing function here */
3486 
3487   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3488 		     	p_full_path => l_path_name,
3489 		     	p_string => '     Input asset balances to revaluation program');
3490 
3491 
3492             Debug_Asset(l_reval_input_asset(l_idx2));
3493 
3494             IF NOT igi_iac_reval_wrapper.do_reval_calc_asset(l_reval_params,
3495                                                              l_reval_asset_out) THEN
3496   		igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3497 		     		p_full_path => l_path_name,
3498 		     		p_string => '*** Error in Revaluation Program');
3499 
3500                 return FALSE;
3501             END IF;
3502 
3503             l_current_reval_factor := l_reval_output_asset(l_idx2).current_reval_factor;
3504             l_cumulative_reval_factor := l_reval_output_asset(l_idx2).cumulative_reval_factor;
3505             l_reval_output_asset(l_idx2) := l_reval_asset_out;
3506             l_reval_output_asset(l_idx2).current_reval_factor := l_current_reval_factor;
3507             l_reval_output_asset(l_idx2).cumulative_reval_factor := l_cumulative_reval_factor;
3508 
3509               /* Bug 2425856 vgadde 20/06/2002 Start(1) */
3510             BEGIN
3511                 IF (l_idx2 = l_idx1) THEN /* Last Revaluation */
3512   		    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3513 		     		p_full_path => l_path_name,
3514 		     		p_string => '     Last revaluation period :'||to_char(l_last_reval_period));
3515   		    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3516 		     		p_full_path => l_path_name,
3517 		     		p_string => '     Revaluation Id :'||to_char(l_revaluation_id));
3518 
3519 
3520                     UPDATE igi_iac_revaluation_rates
3521                     SET period_counter = l_last_reval_period
3522                     WHERE revaluation_id =  l_revaluation_id
3523                     AND asset_id = p_asset_id
3524                     AND book_type_code = p_book_type_code;
3525 
3526                     IF SQL%FOUND then
3527   			igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3528 		     			p_full_path => l_path_name,
3529 		     			p_string => '     Records in reval rates updated for correct period');
3530                     ELSE
3531   			igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3532 		     			p_full_path => l_path_name,
3533 		     			p_string => '***  No record found in reval rates table to update');
3534 
3535                         return FALSE;
3536                     END IF;
3537                 END IF;
3538             END;
3539             /* Bug 2425856 vgadde 20/06/2002 End(1) */
3540 
3541         END LOOP;
3542 
3543         IF (l_last_reval_period < l_open_period.period_counter) THEN
3544 
3545   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3546 		    	 p_full_path => l_path_name,
3547 		     	p_string => '	Doing the final catchup for depreciation');
3548 
3549 
3550             l_reval_asset := l_reval_output_asset(l_idx1);
3551             IF NOT igi_iac_catchup_pkg.do_deprn_catchup(l_last_reval_period  + 1,
3552                                                  l_open_period.period_counter,
3553                                                  l_open_period.period_counter,
3554                                                  TRUE,
3555                                                  'RECLASS',
3556                                                  l_fa_deprn_amount_py, 	-- For bug 2961656
3557                                                  l_fa_deprn_amount_cy,	-- For bug 2961656
3558                                                  l_last_asset_period,	-- For bug 2961656
3559                                                  NULL,			-- For bug 2961656
3560                                                  NULL,			-- For bug 2961656
3561                                                  l_reval_asset ,
3562                                                  p_event_id => p_event_id)THEN
3563   		igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3564 		     		p_full_path => l_path_name,
3565 		     		p_string => '*** Error in depreciation catchup for final run'                     );
3566 
3567                 return FALSE;
3568             END IF;
3569 
3570   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3571 		     	p_full_path => l_path_name,
3572 		     	p_string => '     Output from final catchup');
3573 
3574             Debug_Asset(l_reval_asset);
3575 
3576         END IF;
3577 
3578         -- Code added by Venkat Gadde
3579         BEGIN
3580         UPDATE IGI_IAC_ADJUSTMENTS
3581         SET EVENT_ID = P_EVENT_ID
3582         WHERE BOOK_TYPE_CODE = P_BOOK_TYPE_CODE
3583         AND ASSET_ID = P_ASSET_ID
3584         AND PERIOD_COUNTER = l_open_period.period_counter
3585         AND ADJUSTMENT_ID IN (SELECT ADJUSTMENT_ID
3586                               FROM IGI_IAC_TRANSACTION_HEADERS
3587                               WHERE BOOK_TYPE_CODE = P_BOOK_TYPE_CODE
3588                               AND ASSET_ID = P_ASSET_ID
3589                               AND PERIOD_COUNTER = l_open_period.period_counter
3590                               AND TRANSACTION_TYPE_CODE = 'RECLASS'
3591                               AND EVENT_ID IS NULL);
3592 
3593         UPDATE IGI_IAC_TRANSACTION_HEADERS
3594         SET EVENT_ID = P_EVENT_ID
3595         WHERE BOOK_TYPE_CODE = P_BOOK_TYPE_CODE
3596         AND ASSET_ID = P_ASSET_ID
3597         AND PERIOD_COUNTER = l_open_period.period_counter
3598         AND TRANSACTION_TYPE_CODE = 'RECLASS'
3599         AND EVENT_ID IS NULL;
3600 
3601  	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3602 		     	p_full_path => l_path_name,
3603 		     	p_string => '     Updated all reclass trasactions with event_id');
3604         EXCEPTION
3605         WHEN NO_DATA_FOUND THEN
3606           NULL;
3607         END;
3608         -- End of code added by Venkat Gadde
3609 
3610         return TRUE;
3611 
3612         EXCEPTION
3613             WHEN OTHERS THEN
3614 	  	igi_iac_debug_pkg.debug_unexpected_msg(p_full_path => l_path_name);
3615                 return FALSE;
3616 
3617 
3618 END Do_Revaluation_Catchup;
3619 
3620 
3621 FUNCTION Do_Diff_Price_Index(p_event_id number)
3622 Return BOOLEAN IS
3623 
3624       /* bug 2502128 need to update the reval rates ..only one record should have staus = 'Y'  for an asset */
3625      Cursor C_Reval_Rates is
3626       SELECT max(adjustment_id)
3627       FROM   igi_iac_transaction_headers ith
3628       WHERE  ith.book_type_code =l_asset_hdr_rec.book_type_code
3629       AND    ith.asset_id = l_asset_hdr_rec.asset_id
3630       AND    (ith.transaction_type_code = 'RECLASS' AND  ith.Transaction_sub_type ='REVALUATION');
3631 
3632    l_units Number;
3633    l_get_latest_adjustment_id number;
3634    l_adjustment_id_out number;
3635    l_transaction_type_code varchar2(50);
3636    l_transaction_id number ;
3637    l_mass_reference_id number;
3638    l_adjustment_status varchar2(50);
3639    l_path_name VARCHAR2(150);
3640 
3641 BEGIN
3642    l_transaction_type_code := Null;
3643    l_adjustment_status := null ;
3644    l_path_name := g_path||'do_diff_price_index';
3645 
3646   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3647 		     p_full_path => l_path_name,
3648 		     p_string => 'Enter The Do different price index');
3649 
3650         l_get_latest_adjustment_id:=0;
3651         /* Create a new transaction header for RECLASS reversal of the det balances and
3652         create the adjustments accordingly */
3653         /* to do this call the same price index */
3654         IF Do_same_price_index(p_event_id) then
3655   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3656 		     	p_full_path => l_path_name,
3657 		     	p_string => '+DIFF PRICE INDEX RECLASS REVERSAL SUCCESS');
3658         ELSE
3659   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3660 		     	p_full_path => l_path_name,
3661 		     	p_string => 'DIFFERENT PRICE INDEX RECLASS NEGATION FAILED ');
3662 
3663                 return false;
3664         End IF;
3665 
3666         /* From the dpis to the current period to do the revalutions and professional revalutions
3667         call the catchup program*/
3668         /*revaluation program will create the entries reuiqred in det balanes and asset balances*/
3669 
3670         IF (DIFF_PRICE_INDEX_FLAG) AND
3671            (ALLOW_INDEX_REVAL_FLAG OR ALLOW_PROF_REVAL_FLAG) THEN
3672 
3673             IF NOT Do_Revaluation_Catchup(l_asset_hdr_rec.book_type_code,
3674                                  l_asset_hdr_rec.asset_id,
3675                                  l_asset_cat_rec_new.category_id,
3676                                  'RECLASS',
3677                                  p_event_id => p_event_id)THEN
3678 
3679   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3680 		     		p_full_path => l_path_name,
3681 		     		p_string => 'FAILED TO DO DIFFERENT PRICE INDEX RECLASSIFICATION');
3682 
3683                 return false;
3684             End IF;
3685         END IF;
3686 
3687             /* bug 2502128 need to update the reval rates ..only one record should have staus = 'Y'  for an asset */
3688             OPEN C_Reval_Rates;
3689             FETCH C_Reval_Rates into l_get_latest_adjustment_id;
3690             CLOSE C_Reval_Rates;
3691             IF NOT  IGI_IAC_REVAL_CRUD.update_reval_rates (fp_adjustment_id =>  l_get_latest_adjustment_id) THEN
3692   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3693 		     		p_full_path => l_path_name,
3694 		     		p_string => 'FAILED UPDATE REVAL RATES');
3695              END IF;
3696 
3697   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3698 		     		p_full_path => l_path_name,
3699 		     		p_string => 'SUCESSFULL DIFF PRICE INDEX');
3700 
3701          return True;
3702 END;-- do diff price index
3703 
3704 
3705 
3706 
3707 -- ======================================================================
3708 -- PRINT PARAMETER VALUES
3709 -- ======================================================================
3710 /*=========================================================================+*/
3711 PROCEDURE Print_Parameter_values is
3712   	l_path_name VARCHAR2(150);
3713 BEGIN
3714   	l_path_name := g_path||'print_parameter_values';
3715   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3716 		     p_full_path => l_path_name,
3717 		     p_string => '+PARAMTER VALUES RECEIVED TO Do_RECLASS');
3718   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3719 		     p_full_path => l_path_name,
3720 		     p_string => '     +ASSET_TRANS_HDR_REC');
3721   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3722 		     p_full_path => l_path_name,
3723 		     p_string => '         +TRANSACTION_HEADER_ID.......... '||l_trans_rec.TRANSACTION_HEADER_ID );
3724   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3725 		     p_full_path => l_path_name,
3726 		     p_string => '         +TRANSACTION_TYPE_CODE.......... '||l_trans_rec.TRANSACTION_TYPE_CODE );
3727   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3728 		     p_full_path => l_path_name,
3729 		     p_string => '         +TRANSACTION_DATE_ENTERED....... '||l_trans_rec.TRANSACTION_DATE_ENTERED );
3730   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3731 		     p_full_path => l_path_name,
3732 		     p_string => '         +TRANSACTION_NAME............... '||l_trans_rec.TRANSACTION_NAME);
3733   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3734 		     p_full_path => l_path_name,
3735 		     p_string => '         +SOURCE_TRANSACTION_HEADER_ID... '||l_trans_rec.SOURCE_TRANSACTION_HEADER_ID);
3736   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3737 		     p_full_path => l_path_name,
3738 		     p_string => '         +MASS_REFERENCE_ID.............. '|| l_trans_rec.MASS_REFERENCE_ID);
3739   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3740 		     p_full_path => l_path_name,
3741 		     p_string => '         +TRANSACTION_SUBTYPE............ '|| l_trans_rec.TRANSACTION_SUBTYPE);
3742   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3743 		     p_full_path => l_path_name,
3744 		     p_string => '         +TRANSACTION_KEY................ '|| l_trans_rec.TRANSACTION_KEY);
3745   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3746 		     p_full_path => l_path_name,
3747 		     p_string => '         +AMORTIZATION_START_DATE........ '||l_trans_rec.AMORTIZATION_START_DATE);
3748   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3749 		     p_full_path => l_path_name,
3750 		     p_string => '         +CALLING_INTERFACE.............. '||l_trans_rec.CALLING_INTERFACE);
3751   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3752 		     p_full_path => l_path_name,
3753 		     p_string => '         +MASS_TRANSACTION_ID............ '||l_trans_rec.MASS_TRANSACTION_ID);
3754   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3755 		     p_full_path => l_path_name,
3756 		     p_string => '     +ASSET_HDR_REC');
3757   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3758 		     p_full_path => l_path_name,
3759 		     p_string => '         +ASSET_ID....................... '|| l_asset_hdr_rec.ASSET_ID );
3760   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3761 		     p_full_path => l_path_name,
3762 		     p_string => '         +BOOK_TYPE_CODE................. '|| l_asset_hdr_rec.BOOK_TYPE_CODE );
3763   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3764 		     p_full_path => l_path_name,
3765 		     p_string => '         +SET_OF_BOOKS_ID................ '|| l_asset_hdr_rec.SET_OF_BOOKS_ID);
3766   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3767 		     p_full_path => l_path_name,
3768 		     p_string => '         +PERIOD_OF_ADDITION............. '||l_asset_hdr_rec.PERIOD_OF_ADDITION);
3769   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3770 		     p_full_path => l_path_name,
3771 		     p_string => '     +ASSET_CAT_REC_OLD');
3772   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3773 		     p_full_path => l_path_name,
3774 		     p_string => '         +CATEGORY_ID.................... '|| l_asset_cat_rec_old.category_id);
3775   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3776 		     p_full_path => l_path_name,
3777 		     p_string => '     +ASSET_CAT_REC_NEW');
3778   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3779 		     p_full_path => l_path_name,
3780 		     p_string => '         +CATEGORY_ID.................... '|| l_asset_cat_rec_new.category_id);
3781   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3782 		     p_full_path => l_path_name,
3783 		     p_string => '     +ASSET_TYPE_REC');
3784   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3785 		     p_full_path => l_path_name,
3786 		     p_string => '         +ASSET_TYPE..................... '|| l_asset_type_rec.asset_type );
3787   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3788 		     p_full_path => l_path_name,
3789 		     p_string => '     +CALLING FUNCTION................... ' || l_calling_function);
3790   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3791 		     p_full_path => l_path_name,
3792 		     p_string => '+PARAMTER VALUES RECEIVED TO Do_RECLASS');
3793 END;
3794 
3795 
3796 
3797 
3798 -- ======================================================================
3799 -- RECLASS
3800 -- ======================================================================
3801 /*=========================================================================+
3802  | Function Name:                                                          |
3803  |    Do_Reclass                                                           |
3804  |                                                                         |
3805  | Description:                                                            |
3806  |    This IAC hook function is to process reclassification for IAC and    |
3807  |    called from Reclass API(FA_RECLASS_PUB.Do_Reclass).                  |
3808  |                                                                         |
3809  +=========================================================================*/
3810 
3811 FUNCTION Do_Reclass(
3812    p_trans_rec                      FA_API_TYPES.trans_rec_type,
3813    p_asset_hdr_rec                  FA_API_TYPES.asset_hdr_rec_type,
3814    p_asset_cat_rec_old              FA_API_TYPES.asset_cat_rec_type,
3815    p_asset_cat_rec_new              FA_API_TYPES.asset_cat_rec_type,
3816    p_asset_desc_rec                 FA_API_TYPES.asset_desc_rec_type,
3817    p_asset_type_rec                 FA_API_TYPES.asset_type_rec_type,
3818    p_calling_function               VARCHAR2,
3819    p_event_id                       number  --R12 uptake
3820 ) return BOOLEAN is
3821 
3822   l_old_price_index igi_iac_category_books.price_index_id%type;
3823   l_new_price_index igi_iac_category_books.price_index_id%type;
3824 
3825   -- cursor to get the price index of the asset
3826   Cursor get_price_index(c_category_id number) is
3827   SELECT price_index_id
3828   FROM igi_iac_category_books
3829   WHERE book_type_code = l_asset_hdr_rec.book_type_code
3830   AND category_id = c_category_id;
3831 
3832 
3833     l_set_of_books_id		Number;
3834     l_chart_of_accounts_id  Number;
3835     l_currency				Varchar2(5);
3836     l_precision 			Number;
3837     l_prd_rec               igi_iac_types.prd_rec;
3838     l_path_name VARCHAR2(150);
3839 
3840 BEGIN
3841     l_set_of_books_id		:=0;
3842     l_chart_of_accounts_id  :=0;
3843     l_precision 			:=0;
3844     l_path_name := g_path||'do_reclass';
3845 
3846        /* igi_iac_debug_pkg.debug_on('RECLASS');
3847         igi_iac_debug_pkg.debug(0,'Creating a message log file for RECLASS');
3848         igi_iac_debug_pkg.debug(0,'Date '||sysdate);
3849         igi_iac_debug_pkg.debug(0,'Calling function '||p_calling_function);
3850         igi_iac_debug_pkg.debug(0,'Entry for IAC reclass');*/
3851      --
3852   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3853 		     p_full_path => l_path_name,
3854 		     p_string => 'Creating a message log file for RECLASS');
3855   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3856 		     p_full_path => l_path_name,
3857 		     p_string => 'Date '||sysdate);
3858   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3859 		     p_full_path => l_path_name,
3860 		     p_string => 'Calling function '||p_calling_function);
3861   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3862 		     p_full_path => l_path_name,
3863 		     p_string => 'Entry for IAC reclass');
3864 
3865      --validate the IAC book
3866         IF Not (igi_iac_common_utils.is_iac_book(p_asset_hdr_rec.book_type_code)) THEN
3867   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3868 		     		p_full_path => l_path_name,
3869 		     		p_string => 'Not an IAC book ..'||p_asset_hdr_rec.book_type_code);
3870 
3871                 Return True;
3872         End if;
3873 
3874 	IF NOT igi_iac_common_utils.populate_iac_fa_deprn_data(p_asset_hdr_rec.book_type_code,
3875 	    							  'RECLASS') THEN
3876   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3877 		     		p_full_path => l_path_name,
3878 		     		p_string => '*** Error in Synchronizing Depreciation Data ***');
3879 
3880 		return FALSE;
3881 	END IF;
3882 
3883 
3884         -- assign the parameters to local vlaues;
3885         l_trans_rec :=p_trans_rec;
3886         l_asset_hdr_rec := p_asset_hdr_rec;
3887         l_asset_cat_rec_old :=p_asset_cat_rec_old;
3888         l_asset_cat_rec_new :=p_asset_cat_rec_new;
3889         l_asset_desc_rec:= p_asset_desc_rec;
3890         l_asset_type_rec:= p_asset_type_rec;
3891         l_calling_function  := p_calling_function;
3892 
3893         Print_Parameter_values;
3894 
3895         /* return ture if the reclass being done in the same period asset added */
3896         IF l_asset_hdr_rec.PERIOD_OF_ADDITION = 'Y' THEN
3897   	    igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3898 		     		p_full_path => l_path_name,
3899 		     		p_string => 'RECLASS in the same period as asset Added');
3900 
3901             Return True;
3902        END IF;
3903 
3904         --set the default vlaues missing
3905         -- set of books id
3906         IF l_asset_hdr_rec.set_of_books_id is null then
3907             IF NOT igi_iac_common_utils.get_book_gl_info (l_asset_hdr_rec.book_type_code,
3908 						l_set_of_books_id,
3909 						l_chart_of_accounts_id,
3910     					l_currency,
3911         				l_precision ) THEN
3912   		  igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3913 		     		p_full_path => l_path_name,
3914 		     		p_string => '+Set of books Failed');
3915                   FA_SRVR_MSG.Add_Message(
3916                           CALLING_FN => p_calling_function,
3917                           NAME => 'IGI_IAC_NO_SET_OF_BOOKS_INFO',
3918                           TRANSLATE => TRUE,
3919                           APPLICATION => 'IGI');
3920                   Return False;
3921              END IF;
3922 
3923   	     igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3924 		     		p_full_path => l_path_name,
3925 		     		p_string => '+Set of books value is set to ....'|| l_set_of_books_id);
3926 
3927              l_asset_hdr_rec.set_of_books_id := l_set_of_books_id;
3928           END IF;
3929 
3930       -- validate the category
3931   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3932 		     p_full_path => l_path_name,
3933 		     p_string => '+Validate categories');
3934         IF not do_validate_category THEN
3935   		  igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3936 		     		p_full_path => l_path_name,
3937 		     		p_string => '+Failed Validate categories');
3938                   FA_SRVR_MSG.Add_Message(
3939                        CALLING_FN => p_calling_function,
3940                        NAME => 'IGI_IAC_CATEGORY_VALIDATION',
3941                        TRANSLATE => TRUE,
3942                        APPLICATION => 'IGI');
3943                  Return False;
3944         END IF;
3945 
3946   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3947 		     p_full_path => l_path_name,
3948 		     p_string => '+Validate categories successful');
3949 
3950       -- validate the asset
3951   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3952 		     p_full_path => l_path_name,
3953 		     p_string => '+Validate Asset');
3954 
3955         IF NOT do_validate_asset THEN
3956   		igi_iac_debug_pkg.debug_other_string(p_level => g_error_level,
3957 		     		p_full_path => l_path_name,
3958 		     		p_string => '+Failed Validate Asset');
3959 
3960                  FA_SRVR_MSG.Add_Message(
3961                        CALLING_FN =>p_calling_function ,
3962                        NAME => 'IGI_IAC_ASSET_VALIDATION',
3963                        TRANSLATE => TRUE,
3964                        APPLICATION => 'IGI');
3965                  Return TRUE;
3966         END IF;
3967 
3968   	igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
3969 		     p_full_path => l_path_name,
3970 		     p_string => '+Validate Asset successfully');
3971 
3972        -- Check whether adjustments exist in the open period
3973        -- If Adjustments exists then stop the Reclassification
3974        IF IGI_IAC_COMMON_UTILS.Is_Asset_Adjustment_Done(l_asset_hdr_rec.book_type_code,
3975                                     l_asset_hdr_rec.asset_id) THEN
3976 
3977             FA_SRVR_MSG.Add_Message(
3978 	                Calling_FN 	=> l_calling_function ,
3979         	        Name 		=> 'IGI_IAC_ADJUSTMENT_EXCEPTION',
3980         	        TRANSLATE => TRUE,
3981                     APPLICATION => 'IGI');
3982 
3983             RETURN FALSE;
3984        END IF;
3985     -- compare the price indexes of the categories
3986     -- get the old price index
3987     Open get_price_index(l_asset_cat_rec_old.category_id);
3988     Fetch get_price_index into l_old_price_index;
3989     Close get_price_index;
3990 
3991     -- get the price index for new category
3992     Open get_price_index(l_asset_cat_rec_new.category_id);
3993     Fetch get_price_index into l_new_price_index;
3994     Close get_price_index;
3995 
3996     -- compare and call the reclass accordingly
3997     -- bug 3356588
3998     IF (ALLOW_INDEX_REVAL_FLAG) THEN
3999 
4000        IF l_old_price_index = l_new_Price_index THEN
4001 
4002            -- call the same price index
4003   	   igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
4004 		     p_full_path => l_path_name,
4005 		     p_string => '+SAME PRICE INDEX');
4006 
4007 
4008            SAME_PRICE_INDEX_FLAG := TRUE;
4009            DIFF_PRICE_INDEX_FLAG:= FALSE;
4010            IF do_same_price_index(p_event_id) THEN
4011   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
4012 		     		p_full_path => l_path_name,
4013 		     		p_string => '+SAME PRICE INDEX SUCCESS');
4014             ELSE
4015   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
4016 		     		p_full_path => l_path_name,
4017 		     		p_string => 'SAME PRICE INDEX IAC RECLASSIFICATION FAILED');
4018 
4019                 FA_SRVR_MSG.Add_Message(
4020                        CALLING_FN =>p_calling_function ,
4021                        NAME => 'IGI_IAC_SAME_PRICE_FAILED',
4022                        TRANSLATE => TRUE,
4023                        APPLICATION =>'IGI');
4024                 return false;
4025            end if; -- do_same_price_index
4026            --        Null;
4027        ELSE
4028            SAME_PRICE_INDEX_FLAG := FALSE;
4029            DIFF_PRICE_INDEX_FLAG:= TRUE;
4030            IF Do_Diff_Price_Index(p_event_id => p_event_id) THEN
4031                -- call the different price index
4032   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
4033 		     		p_full_path => l_path_name,
4034 		     		p_string => '+DIFFERENT PRICE INDEX');
4035 
4036                 return True;
4037            ELSE
4038   		igi_iac_debug_pkg.debug_other_string(p_level => g_state_level,
4039 		     		p_full_path => l_path_name,
4040 		     		p_string => '+DIFFERENT PRICE INDEX RETURNED FALSE');
4041                 return false;
4042            END IF;
4043        END IF;
4044    ELSE -- ALLOW_INDEX_REVAL_FALG is off
4045       -- call do_no_index_reval function that processes the asset when
4046       -- the category has indexed revaluation switched off
4047       IF Do_No_Index_Reval(p_event_id => p_event_id) THEN
4048          RETURN TRUE;
4049       ELSE
4050          RETURN FALSE;
4051       END IF;
4052    END IF;
4053    Return TRUE;
4054 
4055 END;
4056 BEGIN
4057     debug_reclass := FALSE;
4058     l_debug_print := FALSE;
4059 
4060     -- global vlaue for allow reval index and prof flag
4061     ALLOW_INDEX_REVAL_FLAG := FALSE;
4062     ALLOW_PROF_REVAL_FLAG  := FALSE;
4063     SAME_PRICE_INDEX_FLAG  := FALSE;
4064     DIFF_PRICE_INDEX_FLAG  := FALSE;
4065 
4066     l_calling_function := 'FA_RECLASS_PVT.do_reclass';
4067     chr_newline  := fnd_global.newline;
4068 
4069     --===========================FND_LOG.START=====================================
4070     g_state_level :=	FND_LOG.LEVEL_STATEMENT;
4071     g_proc_level  :=	FND_LOG.LEVEL_PROCEDURE;
4072     g_event_level :=	FND_LOG.LEVEL_EVENT;
4073     g_excep_level :=	FND_LOG.LEVEL_EXCEPTION;
4074     g_error_level :=	FND_LOG.LEVEL_ERROR;
4075     g_unexp_level :=	FND_LOG.LEVEL_UNEXPECTED;
4076     g_path        := 'IGI.PLSQL.igiiarlb.igi_iac_reclass_pkg.';
4077     --===========================FND_LOG.END=====================================
4078 
4079 
4080 END; --reclass package