[Home] [Help]
PACKAGE BODY: APPS.FA_UNIT_ADJ_PUB
Source
1 PACKAGE BODY FA_UNIT_ADJ_PUB AS
2 /* $Header: FAPUADJB.pls 120.9 2006/08/25 15:45:02 spooyath noship $ */
3
4 G_PKG_NAME CONSTANT VARCHAR2(30) := 'FA_UNIT_ADJ_PUB';
5 g_log_level_rec fa_api_types.log_level_rec_type;
6
7 FUNCTION valid_input(px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
8 p_asset_hdr_rec IN FA_API_TYPES.asset_hdr_rec_type,
9 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
10 RETURN BOOLEAN;
11
12 PROCEDURE do_unit_adjustment(p_api_version IN NUMBER,
13 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
14 p_commit IN VARCHAR2 := FND_API.G_FALSE,
15 p_validation_level IN NUMBER := FND_API.G_VALID_LEVEL_FULL,
16 p_calling_fn IN VARCHAR2,
17 x_return_status OUT NOCOPY VARCHAR2,
18 x_msg_count OUT NOCOPY NUMBER,
19 x_msg_data OUT NOCOPY VARCHAR2,
20 px_trans_rec IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
21 px_asset_hdr_rec IN OUT NOCOPY FA_API_TYPES.asset_hdr_rec_type,
22 px_asset_dist_tbl IN OUT NOCOPY FA_API_TYPES.asset_dist_tbl_type)
23
24 IS
25
26 l_api_version CONSTANT NUMBER := 1.0;
27 l_api_name CONSTANT VARCHAR2(30) := 'UNIT ADJUSTMENT API';
28 l_period_addition varchar2(1);
29
30 -- Bug 5475276 Cursor to get the book_type_code
31 CURSOR c_corp_book( p_asset_id number ) IS
32 SELECT bc.book_type_code
33 FROM fa_books bks,
34 fa_book_controls bc
35 WHERE bks.book_type_code = bc.distribution_source_book
36 AND bks.book_type_code = bc.book_type_code
37 AND bks.asset_id = p_asset_id
38 AND bks.transaction_header_id_out is null;
39
40 l_asset_cat_rec FA_API_TYPES.asset_cat_rec_type;
41 l_period_rec FA_API_TYPES.period_rec_type;
42
43 BEGIN
44
45 SAVEPOINT unit_adj_pub;
46
47 if (not g_log_level_rec.initialized) then
48 if (NOT fa_util_pub.get_log_level_rec (
49 x_log_level_rec => g_log_level_rec
50 )) then
51 raise FND_API.G_EXC_ERROR;
52 end if;
53 end if;
54
55
56 IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version,
57 l_api_name, G_PKG_NAME) then
58 RAISE FND_API.G_EXC_ERROR;
59 END IF;
60
61 if (p_init_msg_list = FND_API.G_TRUE) then
62 fa_srvr_msg.Init_Server_Message;
63 fa_debug_pkg.Initialize;
64 end if;
65
66 if (px_asset_hdr_rec.asset_id is null) then
67 fa_srvr_msg.add_message(
68 calling_fn => 'FA_UNIT_ADJ_PUB.do_unit_adjustment',
69 name => 'FA_SHARED_ITEM_NULL',
70 token1 => 'ITEM',
71 value1 => 'Asset Id'
72 ,p_log_level_rec => g_log_level_rec);
73 raise FND_API.G_EXC_ERROR;
74 end if;
75
76 -- Bug 5475276 Get the book_type_code if it is not supplied.
77 if (px_asset_hdr_rec.book_type_code is null) then
78
79 open c_corp_book( px_asset_hdr_rec.asset_id );
80 fetch c_corp_book into px_asset_hdr_rec.book_type_code;
81 close c_corp_book;
82
83 if px_asset_hdr_rec.book_type_code is null then
84 fa_srvr_msg.add_message
85 (calling_fn => 'FA_UNIT_ADJ_PUB.do_unit_adjustment',
86 name => 'FA_EXP_GET_ASSET_INFO'
87 ,p_log_level_rec => g_log_level_rec);
88 raise FND_API.G_EXC_ERROR;
89 end if;
90 end if;
91
92 -- call the cache for the primary transaction book
93 if NOT fa_cache_pkg.fazcbc(X_book => px_asset_hdr_rec.book_type_code,
94 p_log_level_rec => g_log_level_rec) then
95 RAISE FND_API.G_EXC_ERROR;
96 end if;
97
98 -- validate book if corporate, validate asset
99
100 if not fa_asset_val_pvt.validate_asset_book
101 (p_transaction_type_code => 'UNIT ADJUSTMENT',
102 p_book_type_code => px_asset_hdr_rec.book_type_code,
103 p_asset_id => px_asset_hdr_rec.asset_id,
104 p_calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
105 p_log_level_rec => g_log_level_rec) then
106 raise FND_API.G_EXC_ERROR;
107 end if;
108
109 px_trans_rec.transaction_type_code := 'UNIT ADJUSTMENT';
110 IF NOT FA_TRX_APPROVAL_PKG.faxcat(
111 X_book =>px_asset_hdr_rec.book_type_code,
112 X_asset_id =>px_asset_hdr_rec.asset_id,
113 X_trx_type =>'TRANSFER',
114 X_trx_date =>px_trans_rec.transaction_date_entered,
115 X_init_message_flag=> 'NO',
116 p_log_level_rec => g_log_level_rec) then
117 raise FND_API.G_EXC_ERROR;
118 end if;
119
120 if not fa_asset_val_pvt.validate_period_of_addition
121 (px_asset_hdr_rec.asset_id,
122 px_asset_hdr_rec.book_type_code,
123 'ABSOLUTE',
124 l_period_addition,
125 p_log_level_rec => g_log_level_rec) then
126 RAISE FND_API.G_EXC_ERROR;
127 end if;
128 px_asset_hdr_rec.period_of_addition := l_period_addition;
129
130
131 -- validate input
132 if not valid_input(px_trans_rec,
133 px_asset_hdr_rec,
134 p_log_level_rec => g_log_level_rec) then
135 raise FND_API.G_EXC_ERROR;
136 end if;
137
138
139 -- BUG# 3325400
140 -- forcing selection of the thid here rather
141 -- then relying on table handler
142 select fa_transaction_headers_s.nextval
143 into px_trans_rec.transaction_header_id
144 from dual;
145
146 if not FA_DISTRIBUTION_PVT.do_distribution(
147 px_trans_rec => px_trans_rec,
148 px_asset_hdr_rec => px_asset_hdr_rec,
149 px_asset_cat_rec_new => l_asset_cat_rec,
150 px_asset_dist_tbl => px_asset_dist_tbl,
151 p_log_level_rec => g_log_level_rec) then
152 raise FND_API.G_EXC_ERROR;
153 end if;
154
155 /*
156 * Code hook for IAC
157 */
158 if (FA_IGI_EXT_PKG.IAC_Enabled) then
159 if not FA_IGI_EXT_PKG.Do_Unit_Adjustment(
160 p_trans_rec => px_trans_rec,
161 p_asset_hdr_rec => px_asset_hdr_rec,
162 p_asset_cat_rec => l_asset_cat_rec,
163 p_calling_function => 'FA_UNIT_ADJ_PUB.DO_UNIT_ADJUSTMENT') then
164 raise FND_API.G_EXC_ERROR;
165 end if;
166 end if; -- (FA_IGI_EXT_PKG.IAC_Enabled)
167
168 if cse_fa_integration_grp.is_oat_enabled then
169 if not cse_fa_integration_grp.unit_adjustment(
170 p_trans_rec => px_trans_rec,
171 p_asset_hdr_rec => px_asset_hdr_rec,
172 p_asset_dist_tbl => px_asset_dist_tbl) then
173 raise FND_API.G_EXC_ERROR;
174 end if;
175 end if;
176
177
178 if (p_commit = FND_API.G_TRUE) then
179 COMMIT WORK;
180 end if;
181
182 FND_MSG_PUB.Count_And_Get(
183 p_count => x_msg_count,
184 p_data => x_msg_data
185 );
186
187 -- Return the status.
188 x_return_status := FND_API.G_RET_STS_SUCCESS;
189
190
191 EXCEPTION
192 WHEN FND_API.G_EXC_ERROR THEN
193 FA_SRVR_MSG.Add_Message(
194 calling_fn => 'FA_UNIT_ADJ_PUB.do_unit_adjustment',
195 p_log_level_rec => g_log_level_rec);
196
197 FND_MSG_PUB.Count_And_Get(
198 p_count => x_msg_count,
199 p_data => x_msg_data
200 );
201 ROLLBACK TO unit_adj_pub;
202 x_return_status := FND_API.G_RET_STS_ERROR;
203
204 WHEN OTHERS THEN
205 FA_SRVR_MSG.Add_Sql_Error(
206 calling_fn => 'FA_UNIT_ADJ_PUB.do_unit_adjustment'
207 ,p_log_level_rec => g_log_level_rec);
208
209 FND_MSG_PUB.Count_And_Get(
210 p_count => x_msg_count,
211 p_data => x_msg_data
212 );
213 ROLLBACK TO unit_adj_pub;
214 x_return_status := FND_API.G_RET_STS_ERROR;
215
216 END;
217
218 FUNCTION valid_input(px_trans_rec IN OUT NOCOPY fa_api_types.trans_rec_type,
219 p_asset_hdr_rec IN fa_api_types.asset_hdr_rec_type,
220 p_log_level_rec IN fa_api_types.log_level_rec_type default null)
221 RETURN BOOLEAN IS
222
223 l_fiscal_year_name varchar2(30);
224 l_fiscal_year number;
225 l_fy_start_date date;
226 l_fy_end_date date;
227 l_count number;
228 l_max_transaction_date date;
229 l_period_rec FA_API_TYPES.period_rec_type;
230 l_override_flag varchar2(1);
231 l_transaction_date date;
232
233
234 BEGIN
235
236
237 -- check if asset is attached to hierarchy and see if it can
238 -- be override to proceed with normal unit adjustment
239 if (nvl(fnd_profile.value('CRL-FA ENABLED'), 'N') = 'Y') then
240 if (not fa_cua_asset_APIS.check_override_allowed(
241 p_attribute_name => 'DISTRIBUTION',
242 p_book_type_code => p_asset_hdr_rec.book_type_code,
243 p_asset_id => p_asset_hdr_rec.asset_id,
244 x_override_flag => l_override_flag)) then
245 fa_srvr_msg.add_message(
246 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
247 p_log_level_rec => p_log_level_rec);
248 return FALSE;
249 end if;
250 -- if override flag is set to No, do not allow the unit adjustment
251 if (l_override_flag = 'N') then
252 fa_srvr_msg.add_message(
253 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
254 name => 'CUA_NO_DIST_CHANGE_ALLOWED',
255 p_log_level_rec => p_log_level_rec);
256 return FALSE;
257 end if;
258 end if;
259
260
261 -- check if asset is fully retired
262 if FA_ASSET_VAL_PVT.validate_fully_retired(p_asset_hdr_rec.asset_id,
263 p_asset_hdr_rec.book_type_code,
264 p_log_level_rec => p_log_level_rec) then
265 fa_srvr_msg.add_message(
266 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
267 Name => 'FA_REC_RETIRED',
268 p_log_level_rec => p_log_level_rec);
269 return FALSE;
270 end if;
271
272 if not FA_UTIL_PVT.get_period_rec
273 (p_book => p_asset_hdr_rec.book_type_code,
274 x_period_rec => l_period_rec,
275 p_log_level_rec => p_log_level_rec) then
276 return FALSE;
277 end if;
278
279 if (px_trans_rec.transaction_date_entered is null or
280 p_asset_hdr_rec.period_of_addition = 'Y') then
281 l_transaction_date :=
282 greatest(l_period_rec.calendar_period_open_date,
283 least(sysdate,l_period_rec.calendar_period_close_date));
284 px_trans_rec.transaction_date_entered :=
285 to_date(to_char(l_transaction_date,'DD/MM/YYYY'),'DD/MM/YYYY');
286 else
287 if not fa_cache_pkg.fazcbc (X_book => p_asset_hdr_rec.book_type_code,
288 p_log_level_rec => p_log_level_rec) then
289 fa_srvr_msg.add_message( calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
290 p_log_level_rec => p_log_level_rec);
291 return false;
292 else
293 l_fiscal_year_name := fa_cache_pkg.fazcbc_record.fiscal_year_name;
294 l_fiscal_year := fa_cache_pkg.fazcbc_record.current_fiscal_year;
295 end if;
296
297 select start_date, end_date
298 into l_fy_start_Date, l_fy_end_date
299 from fa_fiscal_year
300 where fiscal_year = l_fiscal_year
301 and fiscal_year_name = l_fiscal_year_name;
302
303 if not FA_UTIL_PVT.get_latest_trans_date('FA_UNIT_ADJ_PUB.valid_input',
304 p_asset_hdr_rec.asset_id,
305 p_asset_hdr_rec.book_type_code,
306 l_max_transaction_date,
307 p_log_level_rec => p_log_level_rec) then
308 return FALSE;
309 end if;
310
311 if (px_trans_rec.transaction_date_entered < l_fy_start_date or
312 px_trans_rec.transaction_date_entered > l_fy_end_date) then
313 fa_srvr_msg.add_message(
314 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
315 name => 'FA_RET_DATE_MUSTBE_IN_CUR_FY',
316 p_log_level_rec => p_log_level_rec);
317 return FALSE;
318 end if;
319
320 if (px_trans_rec.transaction_date_entered > l_period_rec.calendar_period_close_date) then
321 fa_srvr_msg.add_message(
322 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
323 name => 'FA_SHARED_CANNOT_FUTURE',
324 p_log_level_rec => p_log_level_rec);
325 return FALSE;
326 end if;
327
328 if (px_trans_rec.transaction_date_entered < l_max_transaction_date) then
329 fa_srvr_msg.add_message(
330 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
331 name => 'FA_SHARED_OTHER_TRX_FOLLOW',
332 p_log_level_rec => p_log_level_rec);
333 return FALSE;
334 end if;
335
336 if (px_trans_rec.transaction_date_entered <to_date('1000/01/01', 'YYYY/MM/DD')) then
337 fa_srvr_msg.add_message(
338 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input',
339 name => 'FA_YEAR_GREATER_THAN',
340 p_log_level_rec => p_log_level_rec);
341 return FALSE;
342 end if;
343 end if;
344
345 return TRUE;
346
347 EXCEPTION
348 when others then
349 fa_srvr_msg.add_sql_error(
350 calling_fn => 'FA_UNIT_ADJ_PUB.valid_input'
351 ,p_log_level_rec => p_log_level_rec);
352 return FALSE;
353
354 END;
355
356 END FA_UNIT_ADJ_PUB;