DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_GCF_SHD

Source


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