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