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