[Home] [Help]
PACKAGE BODY: APPS.FA_RECLASS_PUB
Source
1 PACKAGE BODY FA_RECLASS_PUB as
2 /* $Header: FAPRECB.pls 120.5 2005/07/28 00:17:34 tkawamur noship $ */
3
4 g_log_level_rec fa_api_types.log_level_rec_type;
5
6 /* ---------------------------------------------------------------
7 * Name : Do_reclass
8 * Type : Procedure
9 * Returns : N/A
10 * Purpose : Perform reclass transaction for an asset
11 * Calling Details : This procedure expects the following parameters with
12 * valid data for it to perform the Reclass transaction
13 * successfully
14 * px_trans_rec.amortization_start_date
15 * px_asset_hdr_rec.asset_id
16 * px_asset_cat_rec_new.category_id
17 * ---------------------------------------------------------------- */
18 G_PKG_NAME CONSTANT VARCHAR2(30) := 'FA_RECLASS_PUB';
19
20 PROCEDURE do_reclass (
21 -- std parameters
22 p_api_version IN NUMBER,
23 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
24 p_commit IN VARCHAR2 := FND_API.G_FALSE,
25 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
26 p_calling_fn IN VARCHAR2,
27 x_return_status OUT NOCOPY VARCHAR2,
28 x_msg_count OUT NOCOPY NUMBER,
29 x_msg_data OUT NOCOPY VARCHAR2,
30 -- api parameters
31 px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
32 px_asset_hdr_rec IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
33 px_asset_cat_rec_new IN OUT NOCOPY FA_API_TYPES.asset_cat_rec_type,
34 p_recl_opt_rec IN FA_API_TYPES.reclass_options_rec_type) IS
35
36 l_api_version CONSTANT NUMBER := 1.0;
37 l_api_name CONSTANT VARCHAR2(30) := 'RECLASS API';
38 l_corp_book VARCHAR2(15);
39 l_status BOOLEAN;
40 l_sysdate date;
41 l_addition_rec fa_additions%ROWTYPE;
42 l_asset_desc_rec FA_API_TYPES.asset_desc_rec_type;
43 l_asset_type_rec FA_API_TYPES.asset_type_rec_type;
44 l_asset_cat_rec_old FA_API_TYPES.asset_cat_rec_type;
45 l_period_rec FA_API_TYPES.period_rec_type;
46 l_num_dummy number:= 0;
47
48 l_calling_fn varchar2(40) := 'FA_RECLASS_PUB.do_reclass';
49
50 CURSOR C_corp_book( p_asset_id number ) IS
51 SELECT bc.book_type_code
52 FROM fa_books bks,
53 fa_book_controls bc
54 WHERE bks.book_type_code = bc.distribution_source_book
55 AND bks.book_type_code = bc.book_type_code
56 AND bks.asset_id = p_asset_id
57 AND bks.date_ineffective is null;
58
59 CURSOR c_asset_parent is
60 select parent_hierarchy_id
61 from fa_asset_hierarchy
62 where asset_id = px_asset_hdr_rec.asset_id;
63
64 CURSOR C_txn_date is
65 select greatest(calendar_period_open_date,
66 least(sysdate, calendar_period_close_date))
67 from fa_deprn_periods
68 where book_type_code = px_asset_hdr_rec.book_type_code
69 and period_close_date is null;
70
71 l_err_stage varchar2(640);
72 l_override_flag varchar2(1);
73 l_asset_hr_rec FA_API_TYPES.asset_hierarchy_rec_type;
74 l_asset_hr_opt_rec FA_API_TYPES.asset_hr_options_rec_type;
75 l_crl_enabled BOOLEAN := FALSE;
76 BEGIN
77
78 -- initialize date;
79 l_sysdate := sysdate;
80
81 -- Standard start of API savepoint.
82 SAVEPOINT Reclass_Asset_Begin;
83
84 if (not g_log_level_rec.initialized) then
85 if (NOT fa_util_pub.get_log_level_rec (
86 x_log_level_rec => g_log_level_rec
87 )) then
88 raise FND_API.G_EXC_UNEXPECTED_ERROR;
89 end if;
90 end if;
91
92
93 l_err_stage:= 'Standard call to check for call compatibility.';
94 -- dbms_output.put_line(l_err_stage);
95 IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version,
96 l_api_name, G_PKG_NAME) then
97 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
98 END IF;
99
100 l_err_stage:= 'Initialize message list if p_init_msg_list is set to TRUE.';
101 -- dbms_output.put_line(l_err_stage);
102 IF FND_API.To_Boolean(p_init_msg_list) THEN
103 -- Initialize error message stack.
104 FA_SRVR_MSG.Init_Server_Message;
105 -- Initialize debug message stack.
106 FA_DEBUG_PKG.Initialize;
107 END IF;
108
109 -- bugfix 2158910 Override FA: PRINT_DEBUG profile option.
110 -- IF FND_API.To_Boolean(p_debug_flag) THEN
111 -- FA_DEBUG_PKG.Set_Debug_Flag;
112 -- ELSE
113 -- FA_DEBUG_PKG.Set_Debug_Flag('NO');
114 -- END IF;
115
116 l_err_stage := 'validate required parameters';
117 -- -- dbms_output.put_line(l_err_stage);
118 if ( px_asset_hdr_rec.asset_id is null or
119 px_asset_cat_rec_new.category_id is null) then
120 fa_srvr_msg.add_message(
121 calling_fn => l_calling_fn,
122 name => 'FA_SHARED_ITEM_NULL'
123 ,p_log_level_rec => g_log_level_rec);
124 raise FND_API.G_EXC_ERROR;
125 end if;
126
127
128 l_err_stage:= 'check that asset is valid';
129 -- -- dbms_output.put_line(l_err_stage);
130 select count(book_type_code)
131 into l_num_dummy
132 from fa_books b
133 where asset_id = px_asset_hdr_rec.asset_id
134 and date_ineffective is null;
135 if l_num_dummy = 0 then
136 fa_srvr_msg.add_message(
137 calling_fn => l_calling_fn,
138 name => 'FA_INVALID_ASSET'
139 ,p_log_level_rec => g_log_level_rec);
140 raise FND_API.G_EXC_ERROR;
141 end if;
142
143 l_err_stage:= 'determine the corporate book';
144 -- dbms_output.put_line(l_err_stage);
145 open c_corp_book( px_asset_hdr_rec.asset_id );
146 fetch c_corp_book into l_corp_book;
147 if l_corp_book is null then
148 close c_corp_book;
149 FA_SRVR_MSG.Add_Message(
150 calling_fn => l_calling_fn
151 ,p_log_level_rec => g_log_level_rec);
152 raise FND_API.G_EXC_ERROR;
153 end if;
154 close c_corp_book;
155
156 px_asset_hdr_rec.book_type_code := l_corp_book;
157
158 -- load the book controls cache
159 if not fa_cache_pkg.fazcbc(X_book => px_asset_hdr_rec.book_type_code,
160 p_log_level_rec => g_log_level_rec) then
161 raise FND_API.G_EXC_ERROR;
162 end if;
163
164 if (g_log_level_rec.statement_level) then
165 fa_debug_pkg.add(l_calling_fn, 'Book', px_asset_hdr_rec.book_type_code
166 ,p_log_level_rec => g_log_level_rec);
167 fa_debug_pkg.add(l_calling_fn, 'Asset_id', px_asset_hdr_rec.asset_id
168 ,p_log_level_rec => g_log_level_rec);
169 fa_debug_pkg.add(l_calling_fn, 'Transaction_date_entered', px_trans_rec.transaction_date_entered
170 ,p_log_level_rec => g_log_level_rec);
171 fa_debug_pkg.add(l_calling_fn, '-', 'calling FA_TRX_APPROVAL_PKG.faxcat'
172 ,p_log_level_rec => g_log_level_rec);
173 end if;
174
175 -- call asset level transaction approval
176 -- only if not called from mass process
177 if nvl(p_recl_opt_rec.mass_request_id, -1) = -1 then
178 l_err_stage:= 'FA_TRX_APPROVAL_PKG.faxcat';
179 -- dbms_output.put_line(l_err_stage);
180 if NOT FA_TRX_APPROVAL_PKG.faxcat(
181 X_book =>px_asset_hdr_rec.book_type_code,
182 X_asset_id =>px_asset_hdr_rec.asset_id,
183 X_trx_type =>'RECLASS',
184 X_trx_date =>px_trans_rec.transaction_date_entered,
185 X_init_message_flag=>'NO',
186 p_log_level_rec => g_log_level_rec) then
187 FA_SRVR_MSG.Add_Message(
188 Calling_FN => l_calling_fn
189 ,p_log_level_rec => g_log_level_rec);
190 raise FND_API.G_EXC_ERROR;
191 end if;
192 end if;
193
194 -- BUG# 3549470
195 -- force the population of trx_date_entered here
196
197 if not FA_UTIL_PVT.get_period_rec
198 (p_book => px_asset_hdr_rec.book_type_code,
199 x_period_rec => l_period_rec,
200 p_log_level_rec => g_log_level_rec) then
201 raise FND_API.G_EXC_ERROR;
202 end if;
203
204 px_trans_rec.transaction_date_entered :=
205 greatest(l_period_rec.calendar_period_open_date,
206 least(sysdate,l_period_rec.calendar_period_close_date));
207
208 px_trans_rec.transaction_date_entered :=
209 to_date(to_char(px_trans_rec.transaction_date_entered,'DD/MM/YYYY'),'DD/MM/YYYY');
210
211 -- for redefault the user must specify whether to
212 -- expense/amortize the adjustments. If not then
213 -- consider it as expense.
214 if ( p_recl_opt_rec.redefault_flag = 'YES' and
215 ( nvl(px_trans_rec.transaction_subtype, 'XX') not in
216 ('EXPENSED', 'AMORTIZED'
217 ))) then
218 px_trans_rec.transaction_subtype := 'EXPENSED';
219 end if;
220
221 -- dbms_output.put_line('transaction_subtype '|| px_trans_rec.transaction_subtype );
222
223 l_err_stage:= 'fa_utils_pvt.get_asset_desc_rec';
224 -- dbms_output.put_line(l_err_stage);
225 if not fa_util_pvt.get_asset_desc_rec(
226 p_asset_hdr_rec => px_asset_hdr_rec ,
227 px_asset_desc_rec => l_asset_desc_rec,
228 p_log_level_rec => g_log_level_rec) then
229 fa_srvr_msg.add_message(
230 calling_fn => l_calling_fn,
231 name => 'FA_PROJ_GET_ASSET_INFO'
232 ,p_log_level_rec => g_log_level_rec);
233 raise FND_API.G_EXC_ERROR;
234 end if;
235
236 l_err_stage:= 'fa_utils_pvt.get_asset_type_rec';
237 -- dbms_output.put_line(l_err_stage);
238 if not fa_util_pvt.get_asset_type_rec(
239 p_asset_hdr_rec => px_asset_hdr_rec,
240 px_asset_type_rec => l_asset_type_rec,
241 p_date_effective => null,
242 p_log_level_rec => g_log_level_rec) then
243 fa_srvr_msg.add_message(
244 calling_fn => l_calling_fn
245 ,p_log_level_rec => g_log_level_rec);
246 raise FND_API.G_EXC_ERROR;
247 end if;
248
249 -- get current category details
250 l_err_stage:= 'fa_utils_pvt.get_asset_cat_rec';
251 -- dbms_output.put_line(l_err_stage);
252 if not fa_util_pvt.get_asset_cat_rec(
253 p_asset_hdr_rec => px_asset_hdr_rec,
254 px_asset_cat_rec => l_asset_cat_rec_old,
255 p_date_effective => null,
256 p_log_level_rec => g_log_level_rec) then
257 fa_srvr_msg.add_message(
258 calling_fn => l_calling_fn
259 ,p_log_level_rec => g_log_level_rec);
260 raise FND_API.G_EXC_ERROR;
261 end if;
262
263 l_err_stage:= 'check if old and new categories are same';
264 -- dbms_output.put_line(l_err_stage);
265 if ( l_asset_cat_rec_old.category_id = px_asset_cat_rec_new.category_id) then
266 -- do nothing. Skip
267 return ;
268 end if;
269
270 l_err_stage:= 'Check if CRL enabled';
271 -- dbms_output.put_line(l_err_stage);
272 if (nvl(fnd_profile.value('CRL-FA ENABLED'), 'N') = 'Y') then
273 l_crl_enabled := TRUE;
274 end if;
275
276 if l_crl_enabled then
277 -- dbms_output.put_line('CRL Is Enabled');
278
279 l_err_stage:= 'Check_override_allowed';
280 -- dbms_output.put_line(l_err_stage);
281 if (not fa_cua_asset_APIS.check_override_allowed(
282 p_attribute_name => 'CATEGORY',
283 p_book_type_code => px_asset_hdr_rec.book_type_code,
284 p_asset_id => px_asset_hdr_rec.asset_id,
285 x_override_flag => l_override_flag)) then
286 fa_srvr_msg.add_message(
287 calling_fn => l_calling_fn
288 ,p_log_level_rec => g_log_level_rec);
289 raise FND_API.G_EXC_ERROR;
290 end if;
291 if l_override_flag = 'N' then
292 fa_srvr_msg.add_message(
293 calling_fn => l_calling_fn,
294 name => 'FA_OVERRIDE_NOT_ALLOWED',
295 token1 => 'CATEGORY'
296 ,p_log_level_rec => g_log_level_rec);
297 raise FND_API.G_EXC_ERROR;
298 end if;
299
300 l_err_stage:= 'c_asset_parent';
301 -- dbms_output.put_line(l_err_stage);
302 open C_asset_parent;
303 fetch C_asset_parent into l_asset_hr_rec.parent_hierarchy_id;
304 close C_asset_parent;
305
306 if l_asset_hr_rec.parent_hierarchy_id is not null then
307 -- create/submit batch to derive asset hierarchy attributes
308
309 l_asset_hr_opt_rec.event_code := 'CHANGE_ASSET_CATEGORY';
310 l_asset_hr_opt_rec.status_code := 'N';
311 l_asset_hr_opt_rec.source_entity_name := 'ASSET';
312 l_asset_hr_opt_rec.source_entity_value:= px_asset_hdr_rec.asset_id;
313 l_asset_hr_opt_rec.source_attribute_name:= 'CATEGORY';
314 l_asset_hr_opt_rec.source_attribute_old_id:= l_asset_cat_rec_old.category_id;
315 l_asset_hr_opt_rec.source_attribute_new_id:= px_asset_cat_rec_new.category_id;
316 l_asset_hr_opt_rec.description:= null;
317
318 if px_trans_rec.transaction_subtype = 'AMORTIZED' then
319 l_asset_hr_opt_rec.amortize_flag:= 'Y';
320 if px_trans_rec.amortization_start_date is null then
321 l_err_stage:= 'C_txn_date';
322 -- dbms_output.put_line(l_err_stage);
323 Open C_txn_date;
324 Fetch C_txn_date into l_asset_hr_opt_rec.amortization_start_date;
325 Close C_txn_date;
326 else
327 l_asset_hr_opt_rec.amortization_start_date := px_trans_rec.amortization_start_date;
328 end if;
329 else
330 l_asset_hr_opt_rec.amortize_flag:= 'N';
331 l_asset_hr_opt_rec.amortization_start_date := null;
332 end if;
333
334 l_err_stage:= 'calling FA_ASSET_HIERARCHY_PVT.create_batch';
335 -- dbms_output.put_line(l_err_stage );
336 if not FA_ASSET_HIERARCHY_PVT.create_batch(
337 p_asset_hdr_rec => px_asset_hdr_rec,
338 p_trans_rec => px_trans_rec,
339 p_asset_hr_opt_rec => l_asset_hr_opt_rec) then
340 raise FND_API.G_EXC_ERROR;
341 end if;
342 end if; -- parent_hierarchy not null
343 end if; -- if l_crl_enabled
344
345 if ( (not l_crl_enabled) OR
346 l_asset_hr_rec.parent_hierarchy_id is null) then
347 -- dbms_output.put_line('CRL Not Enabled');
348 px_trans_rec.transaction_type_code := 'RECLASS';
349
350 if (g_log_level_rec.statement_level) then
351 fa_debug_pkg.add(l_calling_fn, 'Transaction_type_code', px_trans_rec.transaction_type_code
352 ,p_log_level_rec => g_log_level_rec);
353 fa_debug_pkg.add(l_calling_fn, '-', 'calling FA_RECLASS_PVT.do_reclass'
354 ,p_log_level_rec => g_log_level_rec);
355 end if;
356
357
358 l_err_stage:= 'calling FA_RECLASS_PVT.do_reclass';
359 -- dbms_output.put_line(l_err_stage);
360 if not FA_RECLASS_PVT.do_reclass(
361 px_trans_rec,
362 l_asset_desc_rec,
363 px_asset_hdr_rec,
364 l_asset_type_rec,
365 l_asset_cat_rec_old,
366 px_asset_cat_rec_new,
367 p_recl_opt_rec,
368 p_log_level_rec => g_log_level_rec) then
369
370 raise FND_API.G_EXC_ERROR;
371 end if;
372 end if; -- if not crl_enabled
373
374 if FND_API.To_Boolean(p_commit) THEN
375 commit;
376 end if;
377
378 FND_MSG_PUB.Count_And_Get(
379 p_count => x_msg_count,
380 p_data => x_msg_data );
381
382 x_return_status := FND_API.G_RET_STS_SUCCESS;
383
384 EXCEPTION
385 when FND_API.G_EXC_ERROR then
386 rollback to Reclass_Asset_Begin;
387 FA_SRVR_MSG.Add_Message(
388 calling_fn => l_calling_fn,
389 p_log_level_rec => g_log_level_rec);
390 FND_MSG_PUB.Count_And_Get(
391 p_count => x_msg_count,
392 p_data => x_msg_data );
393 x_return_status := FND_API.G_RET_STS_ERROR;
394
395 when others then
396 rollback to Reclass_Asset_Begin;
397 fa_srvr_msg.add_sql_error(
398 calling_fn => l_calling_fn
399 ,p_log_level_rec => g_log_level_rec);
400 FND_MSG_PUB.Count_And_Get(
401 p_count => x_msg_count,
402 p_data => x_msg_data );
403 raise FND_API.G_EXC_UNEXPECTED_ERROR;
404 END do_reclass;
405
406
407 END FA_RECLASS_PUB;