DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_CNU_SHD

Source


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