1 Package Body ame_act_shd as
2 /* $Header: amactrhi.pkb 120.4 2005/11/22 03:12 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_act_shd.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |---------------------------< constraint_error >---------------------------|
12 -- ----------------------------------------------------------------------------
13 Procedure constraint_error
14 (p_constraint_name in all_constraints.constraint_name%TYPE
15 ) Is
16 --
17 l_proc varchar2(72) := g_package||'constraint_error';
18 --
19 Begin
20 --
21 If (p_constraint_name = 'AME_ACTIONS_PK') Then
22 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
23 fnd_message.set_token('PROCEDURE', l_proc);
24 fnd_message.set_token('STEP','5');
25 fnd_message.raise_error;
26 Else
27 fnd_message.set_name('PAY', 'HR_7877_API_INVALID_CONSTRAINT');
28 fnd_message.set_token('PROCEDURE', l_proc);
29 fnd_message.set_token('CONSTRAINT_NAME', p_constraint_name);
30 fnd_message.raise_error;
31 End If;
32 --
33 End constraint_error;
34 --
35 -- ----------------------------------------------------------------------------
36 -- |-----------------------------< api_updating >-----------------------------|
37 -- ----------------------------------------------------------------------------
38 Function api_updating
39 (p_effective_date in date
40 ,p_action_id in number
41 ,p_action_type_id in number
42 ,p_object_version_number in number
43 ) Return Boolean Is
44 --
45 -- Cursor selects the 'current' row from the HR Schema
46 --
47 Cursor C_Sel1 is
48 select
49 action_id
50 ,action_type_id
51 ,parameter
52 ,start_date
53 ,end_date
54 ,description
55 ,security_group_id
56 ,parameter_two
57 ,object_version_number
58 from ame_actions
59 where action_id = p_action_id
60 and action_type_id = p_action_type_id
61 and p_effective_date
62 between start_date and nvl(end_date - ame_util.oneSecond,p_effective_date);
63 --
64 l_fct_ret boolean;
65 --
66 Begin
67 --
68 If (p_effective_date is null or
69 p_action_id is null or
70 p_object_version_number is null) Then
71 --
72 -- One of the primary key arguments is null therefore we must
73 -- set the returning function value to false
74 --
75 l_fct_ret := false;
76 Else
77 If (p_action_id =
78 ame_act_shd.g_old_rec.action_id and
79 p_object_version_number =
80 ame_act_shd.g_old_rec.object_version_number
81 ) Then
82 --
83 -- The g_old_rec is current therefore we must
84 -- set the returning function to true
85 --
86 l_fct_ret := true;
87 Else
88 --
89 -- Select the current row
90 --
91 Open C_Sel1;
92 Fetch C_Sel1 Into ame_act_shd.g_old_rec;
93 If C_Sel1%notfound Then
94 Close C_Sel1;
95 --
96 -- The primary key is invalid therefore we must error
97 --
98 fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
99 fnd_message.raise_error;
100 End If;
101 Close C_Sel1;
102 If (p_object_version_number
103 <> ame_act_shd.g_old_rec.object_version_number) Then
104 fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
105 fnd_message.raise_error;
106 End If;
107 l_fct_ret := true;
108 End If;
109 End If;
110 Return (l_fct_ret);
111 --
112 End api_updating;
113 --
114 -- ----------------------------------------------------------------------------
115 -- |-----------------------< upd_end_date >-------------------------|
116 -- ----------------------------------------------------------------------------
117 Procedure upd_end_date
118 (p_effective_date in date
119 ,p_action_id in number
120 ,p_action_type_id in number
121 ,p_new_end_date in date
122 ,p_validation_start_date in date
123 ,p_validation_end_date in date
124 ,p_object_version_number out nocopy number
125 ) is
126 --
127 l_proc varchar2(72) := g_package||'upd_end_date';
128 l_current_user_id integer;
129 l_object_version_number number;
130 --
131 Begin
132 hr_utility.set_location('Entering:'||l_proc, 5);
133 --
134 -- Because we are updating a row we must get the next object
135 -- version number.
136 --
137 l_object_version_number :=
138 ame_act_shd.get_object_version_number
139 (p_action_id => p_action_id
140 ,p_action_type_id => p_action_type_id
141 );
142 --
143 hr_utility.set_location(l_proc, 10);
144 --
145 l_current_user_id := fnd_global.user_id;
146 --
147 -- Update the specified datetrack row setting the effective
148 -- end date to the specified new effective end date.
149 --
150 update ame_actions t
151 set t.end_date = p_new_end_date
152 ,t.last_updated_by = l_current_user_id
153 ,t.last_update_date = p_new_end_date
154 ,t.last_update_login = l_current_user_id
155 ,t.object_version_number = l_object_version_number
156 where t.action_id = p_action_id
157 and t.action_type_id = p_action_type_id
158 and p_effective_date between t.start_date
159 and nvl(t.end_date - ame_util.oneSecond,sysdate);
160 --
161 --
162 p_object_version_number := l_object_version_number;
163 hr_utility.set_location(' Leaving:'||l_proc, 15);
164 --
165 End upd_end_date;
166 --
167 -- ----------------------------------------------------------------------------
168 -- |---------------------------------< lck >----------------------------------|
169 -- ----------------------------------------------------------------------------
170 Procedure lck
171 (p_effective_date in date
172 ,p_datetrack_mode in varchar2
173 ,p_action_id in number
174 ,p_action_type_id in number
175 ,p_object_version_number in number
176 ,p_validation_start_date out nocopy date
177 ,p_validation_end_date out nocopy date
178 ) is
179 --
180 l_proc varchar2(72) := g_package||'lck';
181 l_validation_start_date date;
182 l_validation_end_date date;
183 l_argument varchar2(30);
184 --
185 -- Cursor C_Sel1 selects the current locked row as of session date
186 -- ensuring that the object version numbers match.
187 --
188 Cursor C_Sel1 is
189 select
190 action_id
191 ,action_type_id
192 ,parameter
193 ,start_date
194 ,end_date
195 ,description
196 ,security_group_id
197 ,parameter_two
198 ,object_version_number
199 from ame_actions
200 where action_id = p_action_id
201 and action_type_id = p_action_type_id
202 and p_effective_date
203 between start_date and nvl(end_date - ame_util.oneSecond, sysdate)
204 for update nowait;
205 --
206 --
207 --
208 Begin
209 hr_utility.set_location('Entering:'||l_proc, 5);
210 --
211 -- Ensure that all the mandatory arguments are not null
212 --
213 hr_api.mandatory_arg_error(p_api_name => l_proc
214 ,p_argument => 'effective_date'
215 ,p_argument_value => p_effective_date
216 );
217 --
218 hr_api.mandatory_arg_error(p_api_name => l_proc
219 ,p_argument => 'datetrack_mode'
220 ,p_argument_value => p_datetrack_mode
221 );
222 --
223 hr_api.mandatory_arg_error(p_api_name => l_proc
224 ,p_argument => 'action_id'
225 ,p_argument_value => p_action_id
226 );
227 --
228 hr_api.mandatory_arg_error(p_api_name => l_proc
229 ,p_argument => 'object_version_number'
230 ,p_argument_value => p_object_version_number
231 );
232 --
233 -- Check to ensure the datetrack mode is not INSERT.
234 --
235 If (p_datetrack_mode <> hr_api.g_insert) then
236 --
237 -- We must select and lock the current row.
238 --
239 Open C_Sel1;
240 Fetch C_Sel1 Into ame_act_shd.g_old_rec;
241 If C_Sel1%notfound then
242 Close C_Sel1;
243 --
244 -- The primary key is invalid therefore we must error
245 --
246 fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
247 fnd_message.raise_error;
248 End If;
249 Close C_Sel1;
250 If (p_object_version_number
251 <> ame_act_shd.g_old_rec.object_version_number) Then
252 fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
253 fnd_message.raise_error;
254 End If;
255 --
256 --
257 --
258 Else
259 --
260 -- We are doing a datetrack 'INSERT' which is illegal within this
261 -- procedure therefore we must error (note: to lck on insert the
262 -- private procedure ins_lck should be called).
263 --
264 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
265 fnd_message.set_token('PROCEDURE', l_proc);
266 fnd_message.set_token('STEP','20');
267 fnd_message.raise_error;
268 End If;
269 --
270 -- Set the validation start and end date OUT arguments
271 --
272 if (p_datetrack_mode = hr_api.g_update) then
273 p_validation_start_date := p_effective_date;
274 p_validation_end_date := ame_act_shd.g_old_rec.end_date;
275 elsif (p_datetrack_mode = hr_api.g_delete) then
276 p_validation_start_date := p_effective_date;
277 p_validation_end_date := p_effective_date;
278 end if;
279 --
280 hr_utility.set_location(' Leaving:'||l_proc, 30);
281 --
282 -- We need to trap the ORA LOCK exception
283 --
284 Exception
285 When HR_Api.Object_Locked then
286 --
287 -- The object is locked therefore we need to supply a meaningful
288 -- error message.
289 --
290 fnd_message.set_name('PAY', 'HR_7165_OBJECT_LOCKED');
291 fnd_message.set_token('TABLE_NAME', 'ame_actions');
292 fnd_message.raise_error;
293 End lck;
294 --
295 -- ----------------------------------------------------------------------------
296 -- |-----------------------------< convert_args >-----------------------------|
297 -- ----------------------------------------------------------------------------
298 Function convert_args
299 (p_action_id in number
300 ,p_action_type_id in number
301 ,p_parameter in varchar2
302 ,p_start_date in date
303 ,p_end_date in date
304 ,p_description in varchar2
305 ,p_security_group_id in number
306 ,p_parameter_two in varchar2
307 ,p_object_version_number in number
308 )
309 Return g_rec_type is
310 --
311 l_rec g_rec_type;
312 --
313 Begin
314 --
315 -- Convert arguments into local l_rec structure.
316 --
317 l_rec.action_id := p_action_id;
318 l_rec.action_type_id := p_action_type_id;
319 l_rec.parameter := p_parameter;
320 l_rec.start_date := p_start_date;
321 l_rec.end_date := p_end_date;
322 l_rec.description := p_description;
323 l_rec.security_group_id := p_security_group_id;
324 l_rec.parameter_two := p_parameter_two;
325 l_rec.object_version_number := p_object_version_number;
326 --
327 -- Return the plsql record structure.
328 --
329 Return(l_rec);
330 --
331 End convert_args;
332 --
333 -- ----------------------------------------------------------------------------
334 -- |------------------------< get_object_version_number >----------------------|
335 -- ----------------------------------------------------------------------------
336 Function get_object_version_number
337 (p_action_id in number
338 ,p_action_type_id in number
339 )
340 Return number is
341 --
342 l_ovn number;
343 --
344 Begin
345 --
346 -- get the next ovn
347 --
348 select nvl(max(t.object_version_number),0) + 1
349 into l_ovn
350 from ame_actions t
351 where t.action_id = p_action_id
352 and t.action_type_id = p_action_type_id;
353 --
354 -- Return the new object_version_number.
355 --
356 Return(l_ovn);
357 --
358 End get_object_version_number;
359 --
360 -- ----------------------------------------------------------------------------
361 -- |-----------------------------< child_rows_exist >-------------------------|
362 -- ----------------------------------------------------------------------------
363 Procedure child_rows_exist
364 (p_action_id in number
365 ,p_start_date in date
366 ,p_end_date in date
367 ) is
368 --
369 Cursor C_Sel1 is
370 select count(*)
371 from ame_action_usages
372 where action_id = p_action_id
373 and start_date < nvl(end_date,p_start_date)
374 and (end_date is null or end_date >= p_start_date);
375 --
376 --
377 --
378 l_child_count integer;
379 --
380 Begin
381 --
382 --
383 --
384 Open C_Sel1;
385 Fetch C_Sel1 into l_child_count;
386 Close C_Sel1;
387 If l_child_count >0 then
388 fnd_message.set_name('PER','AME_400642_ATU_EXST_CNTDEL_ACT');
389 --fnd_message.raise_error;
390 hr_multi_message.add;
391 End If;
392 --
393 --
394 --
395 --
396 End child_rows_exist;
397 --
398 end ame_act_shd;