[Home] [Help]
PACKAGE BODY: APPS.IGI_IAC_REVAL_WRAPPER
Source
1 PACKAGE BODY IGI_IAC_REVAL_WRAPPER AS
2 -- $Header: igiiarwb.pls 120.6.12000000.1 2007/08/01 16:18:35 npandya ship $
3
4 l_rec igi_iac_revaluation_rates%rowtype; -- create this for quicker access via sql navigator
5
6 --===========================FND_LOG.START=====================================
7
8 g_state_level NUMBER := FND_LOG.LEVEL_STATEMENT;
9 g_proc_level NUMBER := FND_LOG.LEVEL_PROCEDURE;
10 g_event_level NUMBER := FND_LOG.LEVEL_EVENT;
11 g_excep_level NUMBER := FND_LOG.LEVEL_EXCEPTION;
12 g_error_level NUMBER := FND_LOG.LEVEL_ERROR;
13 g_unexp_level NUMBER := FND_LOG.LEVEL_UNEXPECTED;
14 g_path VARCHAR2(100) := 'IGI.PLSQL.igiiarwb.IGI_IAC_REVAL_WRAPPER.';
15
16 --===========================FND_LOG.END=======================================
17
18 function do_reval_calc_asset ( L_reval_params in out NOCOPY IGI_IAC_TYPES.iac_reval_params
19 , fp_reval_output_asset IN OUT NOCOPY IGI_IAC_TYPES.iac_reval_output_asset
20 )
21 return boolean is
22
23 l_reval_params_old IGI_IAC_TYPES.iac_reval_params;
24 fp_reval_output_asset_old IGI_IAC_TYPES.iac_reval_output_asset;
25 l_path varchar2(100) := g_path||'do_reval_calc_asset';
26 begin
27
28 l_reval_params_old := l_reval_params;
29 fp_reval_output_asset_old := fp_reval_output_asset;
30
31 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Revaluation engine prepare for calculations');
32 IF NOT IGI_IAC_REVAL_ENGINE.Prepare_calculations
33 ( p_iac_reval_params => L_reval_params )
34 THEN
35 -- add to the message stack!
36 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failure IGI_IAC_REVAL_ENGINE.Prepare_calculations');
37 return false;
38 END IF;
39 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Revaluation engine first set of calculations...');
40 IF NOT IGI_IAC_REVAL_ENGINE.First_set_calculations
41 ( p_iac_reval_params => L_reval_params )
42 THEN
43 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failure IGI_IAC_REVAL_ENGINE.First_set_calculations');
44 -- add to the message stack!
45 return false;
46 END IF;
47
48 fp_reval_output_asset := L_Reval_params.reval_output_asset;
49
50 /* call the apis to create/update records in db (first set) */
51 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'CRUD for the first set of calculations.');
52 IF NOT IGI_IAC_REVAL_CRUD.crud_iac_tables
53 ( fp_reval_params => L_Reval_params
54 , fp_second_set => false
55 )
56 THEN
57 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failure CRUD IGI_IAC_REVAL_ENGINE.First_set_calculations');
58 return false;
59 END IF;
60
61 /* call to next set of calculations */
62 IF L_reval_params.reval_control.mixed_scenario THEN
63 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'If mixed, call SWAP and process the second set of calculations');
64 DECLARE
65 L_reval_params2 IGI_IAC_TYPES.iac_reval_params := L_reval_params;
66 BEGIN
67 IF NOT IGI_IAC_REVAL_ENGINE.swap ( fp_reval_params1 => L_Reval_params
68 , fp_reval_params2 => L_reval_params2 )
69 THEN
70 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failure IGI_IAC_REVAL_ENGINE.swap');
71 return false;
72 END IF;
73
74 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'performing the second set of calculations');
75 IF NOT IGI_IAC_REVAL_ENGINE.Next_set_calculations
76 ( p_iac_reval_params => L_reval_params2 )
77 THEN
78 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failure IGI_IAC_REVAL_ENGINE.Next_set_calculations');
79 return false;
80 END IF;
81 fp_reval_output_asset := L_Reval_params2.reval_output_asset;
82 /* call the apis to create/update records in db (second set) */
83 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'CRUD for the second set of calculations');
84 IF NOT IGI_IAC_REVAL_CRUD.crud_iac_tables
85 ( fp_reval_params => L_Reval_params2
86 , fp_second_set => true
87 )
88 THEN
89 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'failure CRUD IGI_IAC_REVAL_ENGINE.Next_set_calculations');
90 return false;
91 END IF;
92
93 END;
94 END IF;
95 return true;
96 exception when others then
97 l_reval_params := l_reval_params_old;
98 fp_reval_output_asset:= fp_reval_output_asset_old;
99 igi_iac_debug_pkg.debug_unexpected_msg(l_path);
100 return false;
101 end;
102
103 procedure print_exceptions ( fp_reval_exceptions in igi_iac_types.iac_reval_exceptions
104 , fp_revaluation_id in number
105 ) is
106 idx binary_integer;
107 l_exception_line igi_iac_types.iac_reval_Exception_line;
108 l_path varchar2(100) := g_path||'print_exceptions';
109 begin
110
111 idx := fp_reval_exceptions.FIRST;
112 while idx <= fp_reval_exceptions.LAST loop
113 l_exception_line := fp_reval_exceptions( idx) ;
114 IF NOT IGI_IAC_REVAL_CRUD.create_exceptions
115 ( fp_reval_exceptions => l_exception_line
116 , fp_revaluation_id => fp_revaluation_id
117 )
118 THEN
119 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'+unable to create any exceptions');
120 return;
121 END IF;
122
123 if idx < fp_reval_exceptions.LAST then
124 idx := fp_reval_exceptions.next( idx );
125 else
126 exit;
127 end if;
128
129 end loop;
130 end;
131
132 function do_revaluation_asset
133 ( fp_revaluation_id in number
134 , fp_asset_id in number
135 , fp_book_type_code in varchar2
136 , fp_reval_mode in varchar2
137 , fp_reval_rate in number
138 , fp_period_counter in number
139 , fp_calling_program in varchar2
140 , fp_reval_output_asset in out NOCOPY IGI_IAC_TYPES.iac_reval_output_asset
141 , fp_reval_messages in out NOCOPY IGI_IAC_TYPES.iac_reval_mesg
142 , fp_reval_messages_idx in out NOCOPY IGI_IAC_TYPES.iac_reval_mesg_idx
143 , fp_reval_exceptions in out NOCOPY IGI_IAC_TYPES.iac_reval_exceptions
144 , fp_reval_exceptions_idx in out NOCOPY IGI_IAC_TYPES.iac_reval_exceptions_idx
145 )
146 return boolean is
147 L_reval_control IGI_IAC_TYPES.iac_reval_control_type;
148 L_reval_params IGI_IAC_TYPES.iac_reval_params;
149 L_Reval_output_dists IGI_IAC_TYPES.iac_reval_output_dists;
150 L_reval_output_dists_idx IGI_IAC_TYPES.iac_reval_output_dists_idx;
151 L_exception_info IGI_IAC_TYPES.iac_reval_exception_line;
152 l_path varchar2(100) := g_path||'do_revaluation_asset';
153 begin
154 /* initialize the control record for the asset */
155 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Initialization of the control structure');
156 if fp_calling_program = 'IGIIARVC' then
157 IF NOT IGI_IAC_REVAL_INIT_CONTROL.init_control_for_srs
158 ( fp_asset_id => fp_asset_id
159 , fp_book_type_code => fp_book_type_code
160 , fp_revaluation_id => fp_revaluation_id
161 , fp_revaluation_mode => fp_reval_mode
162 , fp_period_counter => fp_period_counter
163 , fp_iac_reval_control_type => L_reval_control
164 ) then
165 -- add message to the stack
166 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failed IGI_IAC_REVAL_INIT_CONTROL.init_control_for_srs');
167 return false;
168 end if;
169 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'success IGI_IAC_REVAL_INIT_CONTROL.init_control_for_srs');
170 elsif fp_calling_program = 'IGIIAIAR' then
171 IF NOT IGI_IAC_REVAL_INIT_CONTROL.init_control_for_calc
172 ( fp_asset_id => fp_asset_id
173 , fp_book_type_code => fp_book_type_code
174 , fp_revaluation_id => fp_revaluation_id
175 , fp_revaluation_mode => fp_reval_mode
176 , fp_period_counter => fp_period_counter
177 , fp_iac_reval_control_type => L_reval_control
178 ) then
179 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Failed IGI_IAC_REVAL_INIT_CONTROL.init_control_for_calc');
180 return false;
181 end if;
182 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'success IGI_IAC_REVAL_INIT_CONTROL.init_control_for_calc');
183 end if;
184
185 /* initialize the structures and records */
186 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Initialization of data structures.');
187 if fp_calling_program = 'IGIIARVC' then
188 IF NOT IGI_IAC_REVAL_INIT_STRUCT.init_struct_for_srs
189 ( fp_asset_id => fp_asset_id
190 , fp_book_type_code => fp_book_type_code
191 , fp_revaluation_id => fp_revaluation_id
192 , fp_revaluation_mode => fp_reval_mode
193 , fp_period_counter => fp_period_counter
194 , fp_control => L_reval_control
195 , fp_reval_params => L_reval_params
196 ) then
197 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'failed IGI_IAC_REVAL_INIT_STRUCT.init_struct_for_srs');
198 return false;
199 end if;
200 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'success IGI_IAC_REVAL_INIT_STRUCT.init_struct_for_srs');
201 elsif fp_calling_program = 'IGIIAIAR' then
202 IF NOT IGI_IAC_REVAL_INIT_STRUCT.init_struct_for_calc
203 ( fp_asset_id => fp_asset_id
204 , fp_book_type_code => fp_book_type_code
205 , fp_revaluation_id => fp_revaluation_id
206 , fp_revaluation_mode => fp_reval_mode
207 , fp_period_counter => fp_period_counter
208 , fp_control => L_reval_control
209 , fp_reval_params => L_reval_params
210 ) then
211 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'failed IGI_IAC_REVAL_INIT_STRUCT.init_struct_for_calc');
212 -- add message to the stack
213 return false;
214 end if;
215 else
216 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Unknown calling program.Exiting.');
217 end if;
218
219 /* validate the asset for business rules */
220 /* this should return true to proceed, false to stop */
221
222 IF L_reval_params.reval_control.validate_business_rules THEN
223
224 fp_reval_exceptions_idx := fp_reval_exceptions_idx + 1;
225 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Validation of business rules.');
226 declare
227 l_reval_exceptions igi_iac_types.iac_reval_exceptions;
228 l_reval_idx igi_iac_types.iac_reval_exceptions_idx;
229 begin
230 IF NOT IGI_IAC_REVAL_VALIDATION.validate_asset
231 ( fp_asset_id => fp_asset_id
232 , fp_book_type_code => fp_book_type_code
233 , fp_revaluation_id => fp_revaluation_id
234 , fp_reval_type => L_reval_params.reval_asset_rules.revaluation_type
235 , fp_period_counter => fp_period_counter
236 , fp_exceptions => l_reval_exceptions
237 , fp_exceptions_idx => l_reval_idx
238 ) then
239 -- add exception to exception stack
240 -- validation has failed, so do not proceed with this asset.
241 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Failed IGI_IAC_REVAL_VALIDATION.validate_asset');
242 fp_reval_exceptions := l_reval_exceptions ;
243 IF L_reval_params.reval_control.crud_allowed THEN
244
245 print_exceptions ( fp_reval_exceptions => fp_reval_exceptions,
246 fp_Revaluation_id => fp_revaluation_id
247 );
248
249 return true;
250 END IF;
251 end if;
252
253 EXCEPTION WHEN OTHERS THEN
254 return true;
255 END;
256
257 END IF;
258 /* calls to the revaluation engine (calc) */
259
260 if not do_reval_calc_asset ( L_reval_params => L_reval_params
261 , fp_reval_output_asset => fp_reval_output_asset
262 )
263 then
264 igi_iac_debug_pkg.debug_other_string(g_error_level,l_path,'Calculation has failed.');
265 return false;
266 end if;
267
268 igi_iac_debug_pkg.debug_other_string(g_state_level,l_path,'Success IGI_IAC_REVAL_WRAPPER.do_revaluation_asset');
269 return true;
270 exception when others then
271 igi_iac_debug_pkg.debug_unexpected_msg(l_path);
272 return false;
273 end;
274
275 function do_calculation_asset
276 ( fp_revaluation_id number
277 , fp_asset_id number
278 , fp_book_type_code varchar2
279 , fp_reval_mode varchar2
280 , fp_reval_rate number
281 , fp_period_counter number
282 , fp_iac_reval_output_asset out NOCOPY IGI_IAC_TYPES.iac_reval_output_asset
283 )
284 return boolean is
285 pragma autonomous_transaction;
286 l_reval_messages IGI_IAC_TYPES.iac_reval_mesg;
287 l_reval_messages_idx IGI_IAC_TYPES.iac_reval_mesg_idx := 1;
288 l_reval_exceptions IGI_IAC_TYPES.iac_reval_exceptions;
289 l_reval_exceptions_idx IGI_IAC_TYPES.iac_reval_exceptions_idx := 1;
290 l_reval_output_asset IGI_IAC_TYPES.iac_reval_output_asset;
291 l_path varchar2(100) := g_path||'do_calculation_asset';
292 begin
293
294 if not do_revaluation_asset
295 ( fp_revaluation_id => fp_revaluation_id
296 , fp_asset_id => fp_asset_id
297 , fp_book_type_code => fp_book_type_code
298 , fp_reval_mode => fp_reval_mode
299 , fp_reval_rate => fp_reval_rate
300 , fp_period_counter => fp_period_counter
301 , fp_calling_program => 'IGIIAIAR'
302 , fp_reval_messages => l_reval_messages
303 , fp_reval_output_asset => l_reval_output_asset
304 , fp_reval_messages_idx => l_reval_messages_idx
305 , fp_reval_exceptions => l_reval_exceptions
306 , fp_reval_exceptions_idx => l_reval_exceptions_idx )
307 then
308 rollback;
309 return false;
310 end if;
311
312 fp_iac_reval_output_asset := l_reval_output_asset;
313 rollback;
314 return true;
315 exception when others then
316 rollback;
317 igi_iac_debug_pkg.debug_unexpected_msg(l_path);
318 return false;
319 end;
320
321 END;