DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_DOC_BUS

Source


1 Package Body pqh_doc_bus as
2 /* $Header: pqdocrhi.pkb 120.2 2005/09/19 14:55:19 rthiagar noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pqh_doc_bus.';  -- Global package name
9 --
10 -- The following two global variables are only to be
11 -- used by the return_legislation_code function.
12 --
13 g_legislation_code            varchar2(150)  default null;
14 g_document_id                 number         default null;
15 --
16 --  ---------------------------------------------------------------------------
17 --  |----------------------< set_security_group_id >--------------------------|
18 --  ---------------------------------------------------------------------------
19 --
20 Procedure set_security_group_id
21   (p_document_id                          in number
22   ,p_associated_column1                   in varchar2 default null
23   ) is
24   --
25   -- Declare cursor
26   --
27   cursor csr_sec_grp is
28     select pbg.security_group_id
29       from per_business_groups pbg
30          , pqh_documents_f doc
31          , pqh_transaction_categories ptc
32          , pqh_txn_category_documents pcd
33      where doc.document_id = p_document_id
34       and  pbg.business_group_id = ptc.business_group_id
35       and pcd.document_id = doc.document_id
36       and pcd.transaction_category_id = ptc.transaction_category_id;
37   --
38   -- Declare local variables
39   --
40   l_security_group_id number;
41   l_proc              varchar2(72)  :=  g_package||'set_security_group_id';
42   --
43 begin
44   --
45   hr_utility.set_location('Entering:'|| l_proc, 10);
46   --
47   -- Ensure that all the mandatory parameter are not null
48   --
49   hr_api.mandatory_arg_error
50     (p_api_name           => l_proc
51     ,p_argument           => 'document_id'
52     ,p_argument_value     => p_document_id
53     );
54   --
55   open csr_sec_grp;
56   fetch csr_sec_grp into l_security_group_id;
57   --
58   if csr_sec_grp%notfound then
59      --
60      close csr_sec_grp;
61      --
62      -- The primary key is invalid therefore we must error
63      --
64      fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
65      hr_multi_message.add
66        (p_associated_column1
67          => nvl(p_associated_column1,'DOCUMENT_ID')
68        );
69      --
70   else
71     close csr_sec_grp;
72     --
73     -- Set the security_group_id in CLIENT_INFO
74     --
75     hr_api.set_security_group_id
76       (p_security_group_id => l_security_group_id
77       );
78   end if;
79   --
80   hr_utility.set_location(' Leaving:'|| l_proc, 20);
81   --
82 end set_security_group_id;
83 --
84 --  ---------------------------------------------------------------------------
85 --  |---------------------< return_legislation_code >-------------------------|
86 --  ---------------------------------------------------------------------------
87 --
88 Function return_legislation_code
89   (p_document_id                          in     number
90   )
91   Return Varchar2 Is
92   --
93   -- Declare cursor
94   --
95   cursor csr_leg_code is
96     select pbg.legislation_code
97       from per_business_groups     pbg
98          , pqh_documents_f doc
99          , pqh_transaction_categories ptc
100          , pqh_txn_category_documents pcd
101 where doc.document_id = p_document_id
102       and pbg.business_group_id = ptc.business_group_id
103       and pcd.document_id = doc.document_id
104       and pcd.transaction_category_id = ptc.transaction_category_id;
105   --
106   -- Declare local variables
107   --
108   l_legislation_code  varchar2(150);
109   l_proc              varchar2(72)  :=  g_package||'return_legislation_code';
110   --
111 Begin
112   --
113   hr_utility.set_location('Entering:'|| l_proc, 10);
114   --
115   -- Ensure that all the mandatory parameter are not null
116   --
117   hr_api.mandatory_arg_error
118     (p_api_name           => l_proc
119     ,p_argument           => 'document_id'
120     ,p_argument_value     => p_document_id
121     );
122   --
123   if ( nvl(pqh_doc_bus.g_document_id, hr_api.g_number)
124        = p_document_id) then
125     --
126     -- The legislation code has already been found with a previous
127     -- call to this function. Just return the value in the global
128     -- variable.
129     --
130     l_legislation_code := pqh_doc_bus.g_legislation_code;
131     hr_utility.set_location(l_proc, 20);
132   else
133     --
134     -- The ID is different to the last call to this function
135     -- or this is the first call to this function.
136     --
137     open csr_leg_code;
138     fetch csr_leg_code into l_legislation_code;
139     --
140     if csr_leg_code%notfound then
141       --
142       -- The primary key is invalid therefore we must error
143       --
144       close csr_leg_code;
145       fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
146       fnd_message.raise_error;
147     end if;
148     hr_utility.set_location(l_proc,30);
149     --
150     -- Set the global variables so the values are
151     -- available for the next call to this function.
152     --
153     close csr_leg_code;
154     pqh_doc_bus.g_document_id                 := p_document_id;
155     pqh_doc_bus.g_legislation_code  := l_legislation_code;
156   end if;
157   hr_utility.set_location(' Leaving:'|| l_proc, 40);
158   return l_legislation_code;
159 end return_legislation_code;
160 --
161 -- ----------------------------------------------------------------------------
162 -- |-----------------------< chk_non_updateable_args >------------------------|
163 -- ----------------------------------------------------------------------------
164 -- {Start Of Comments}
165 --
166 -- Description:
167 --   This procedure is used to ensure that non updateable attributes have
168 --   not been updated. If an attribute has been updated an error is generated.
169 --
170 -- Pre Conditions:
171 --   g_old_rec has been populated with details of the values currently in
172 --   the database.
173 --
174 -- In Arguments:
175 --   p_rec has been populated with the updated values the user would like the
176 --   record set to.
177 --
178 -- Post Success:
179 --   Processing continues if all the non updateable attributes have not
180 --   changed.
181 --
182 -- Post Failure:
183 --   An application error is raised if any of the non updatable attributes
184 --   have been altered.
185 --
186 -- {End Of Comments}
187 -- ----------------------------------------------------------------------------
188 Procedure chk_non_updateable_args
189   (p_effective_date  in date
190   ,p_rec             in pqh_doc_shd.g_rec_type
191   ) IS
192 --
193   l_proc     varchar2(72) := g_package || 'chk_non_updateable_args';
194 --
195 Begin
196   --
197   -- Only proceed with the validation if a row exists for the current
198   -- record in the HR Schema.
199   --
200   IF NOT pqh_doc_shd.api_updating
201       (p_document_id                      => p_rec.document_id
202       ,p_effective_date                   => p_effective_date
203       ,p_object_version_number            => p_rec.object_version_number
204       ) THEN
205      fnd_message.set_name('PER', 'HR_6153_ALL_PROCEDURE_FAIL');
206      fnd_message.set_token('PROCEDURE ', l_proc);
207      fnd_message.set_token('STEP ', '5');
208      fnd_message.raise_error;
209   END IF;
210   --
211   -- EDIT_HERE: Add checks to ensure non-updateable args have
212   --            not been updated.
213   --
214 End chk_non_updateable_args;
215 --
216 -- ----------------------------------------------------------------------------
217 -- |--------------------------< dt_update_validate >--------------------------|
218 -- ----------------------------------------------------------------------------
219 -- {Start Of Comments}
220 --
221 -- Description:
222 --   This procedure is used for referential integrity of datetracked
223 --   parent entities when a datetrack update operation is taking place
224 --   and where there is no cascading of update defined for this entity.
225 --
226 -- Prerequisites:
227 --   This procedure is called from the update_validate.
228 --
229 -- In Parameters:
230 --
231 -- Post Success:
232 --   Processing continues.
233 --
234 -- Post Failure:
235 --
236 -- Developer Implementation Notes:
237 --   This procedure should not need maintenance unless the HR Schema model
238 --   changes.
239 --
240 -- Access Status:
241 --   Internal Row Handler Use Only.
242 --
243 -- {End Of Comments}
244 -- ----------------------------------------------------------------------------
245 Procedure dt_update_validate
246   (p_datetrack_mode                in varchar2
247   ,p_validation_start_date         in date
248   ,p_validation_end_date           in date
249   ) Is
250 --
251   l_proc  varchar2(72) := g_package||'dt_update_validate';
252 --
253 Begin
254   --
255   -- Ensure that the p_datetrack_mode argument is not null
256   --
257   hr_api.mandatory_arg_error
258     (p_api_name       => l_proc
259     ,p_argument       => 'datetrack_mode'
260     ,p_argument_value => p_datetrack_mode
261     );
262   --
263   -- Mode will be valid, as this is checked at the start of the upd.
264   --
265   -- Ensure the arguments are not null
266   --
267   hr_api.mandatory_arg_error
268     (p_api_name       => l_proc
269     ,p_argument       => 'validation_start_date'
270     ,p_argument_value => p_validation_start_date
271     );
272   --
273   hr_api.mandatory_arg_error
274     (p_api_name       => l_proc
275     ,p_argument       => 'validation_end_date'
276     ,p_argument_value => p_validation_end_date
277     );
278   --
279     --
280   --
281 Exception
282   When Others Then
283     --
284     -- An unhandled or unexpected error has occurred which
285     -- we must report
286     --
287     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
288     fnd_message.set_token('PROCEDURE', l_proc);
289     fnd_message.set_token('STEP','15');
290     fnd_message.raise_error;
291 End dt_update_validate;
292 --
293 -- ----------------------------------------------------------------------------
294 -- |--------------------------< dt_delete_validate >--------------------------|
295 -- ----------------------------------------------------------------------------
296 -- {Start Of Comments}
297 --
298 -- Description:
299 --   This procedure is used for referential integrity of datetracked
300 --   child entities when either a datetrack DELETE or ZAP is in operation
301 --   and where there is no cascading of delete defined for this entity.
302 --   For the datetrack mode of DELETE or ZAP we must ensure that no
303 --   datetracked child rows exist between the validation start and end
304 --   dates.
305 --
306 -- Prerequisites:
307 --   This procedure is called from the delete_validate.
308 --
309 -- In Parameters:
310 --
311 -- Post Success:
312 --   Processing continues.
313 --
314 -- Post Failure:
315 --   If a row exists by determining the returning Boolean value from the
316 --   generic dt_api.rows_exist function then we must supply an error via
317 --   the use of the local exception handler l_rows_exist.
318 --
319 -- Developer Implementation Notes:
320 --   This procedure should not need maintenance unless the HR Schema model
321 --   changes.
322 --
323 -- Access Status:
324 --   Internal Row Handler Use Only.
325 --
326 -- {End Of Comments}
327 -- ----------------------------------------------------------------------------
328 Procedure dt_delete_validate
329   (p_document_id                      in number
330   ,p_datetrack_mode                   in varchar2
331   ,p_validation_start_date            in date
332   ,p_validation_end_date              in date
333   ) Is
334 --
335   l_proc        varchar2(72)    := g_package||'dt_delete_validate';
336 --
337 Begin
338   --
339   -- Ensure that the p_datetrack_mode argument is not null
340   --
341   hr_api.mandatory_arg_error
342     (p_api_name       => l_proc
343     ,p_argument       => 'datetrack_mode'
344     ,p_argument_value => p_datetrack_mode
345     );
346   --
347   -- Only perform the validation if the datetrack mode is either
348   -- DELETE or ZAP
349   --
350   If (p_datetrack_mode = hr_api.g_delete or
351       p_datetrack_mode = hr_api.g_zap) then
352     --
353     --
354     -- Ensure the arguments are not null
355     --
356     hr_api.mandatory_arg_error
357       (p_api_name       => l_proc
358       ,p_argument       => 'validation_start_date'
359       ,p_argument_value => p_validation_start_date
360       );
361     --
362     hr_api.mandatory_arg_error
363       (p_api_name       => l_proc
364       ,p_argument       => 'validation_end_date'
365       ,p_argument_value => p_validation_end_date
366       );
367     --
368     hr_api.mandatory_arg_error
369       (p_api_name       => l_proc
370       ,p_argument       => 'document_id'
371       ,p_argument_value => p_document_id
372       );
373     --
374   If (p_datetrack_mode <> hr_api.g_future_change) then
375     If (dt_api.rows_exist
376        (p_base_table_name => 'pqh_document_attributes_f'
377        ,p_base_key_column => 'document_id'
378        ,p_base_key_value  => p_document_id
379        ,p_from_date       => p_validation_start_date
380        ,p_to_date         => p_validation_end_date
381        )) Then
382          fnd_message.set_name('PAY','HR_7215_DT_CHILD_EXISTS');
383          fnd_message.set_token('TABLE_NAME','pqh_document_attributes_f');
384          hr_multi_message.add;
385     End If;
386   End if;
387   --
388   End If;
389   --
390 Exception
391   When Others Then
392     --
393     -- An unhandled or unexpected error has occurred which
394     -- we must report
395     --
396     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
397     fnd_message.set_token('PROCEDURE', l_proc);
398     fnd_message.set_token('STEP','15');
399     fnd_message.raise_error;
400   --
401 End dt_delete_validate;
402 --
403 -- ----------------------------------------------------------------------------
404 -- |---------------------------< insert_validate >----------------------------|
405 -- ----------------------------------------------------------------------------
406 Procedure insert_validate
407   (p_rec                   in pqh_doc_shd.g_rec_type
408   ,p_effective_date        in date
409   ,p_datetrack_mode        in varchar2
410   ,p_validation_start_date in date
411   ,p_validation_end_date   in date
412   ) is
413 --
414   l_proc        varchar2(72) := g_package||'insert_validate';
415 --
416 CURSOR cur_is_duplicate_name(p_short_name varchar2) IS
417 SELECT 'X'
418 FROM   pqh_documents_f
419 WHERE short_name = p_short_name;
420 --
421 l_short_name varchar2(10);
422 Begin
423   hr_utility.set_location('Entering:'||l_proc, 5);
424   --
425   -- Call all supporting business operations
426   --
427      OPEN cur_is_duplicate_name(p_rec.short_name);
428          FETCH cur_is_duplicate_name INTO l_short_name;
429      CLOSE cur_is_duplicate_name;
430 
431      If (l_short_name = 'X') THEN
432        fnd_message.set_name('PQH', 'PQH_SS_DUPLICATE_SHORT_NAME');
433        fnd_message.raise_error;
434      END IF;
435 
436   --
437   -- "-- No business group context.  HR_STANDARD_LOOKUPS used for validation."
438   --
439   --
440   hr_utility.set_location(' Leaving:'||l_proc, 10);
441 End insert_validate;
442 --
443 -- ----------------------------------------------------------------------------
444 -- |---------------------------< update_validate >----------------------------|
445 -- ----------------------------------------------------------------------------
446 Procedure update_validate
447   (p_rec                     in pqh_doc_shd.g_rec_type
448   ,p_effective_date          in date
449   ,p_datetrack_mode          in varchar2
450   ,p_validation_start_date   in date
451   ,p_validation_end_date     in date
452   ) is
453 --
454   l_proc        varchar2(72) := g_package||'update_validate';
455 --
456 CURSOR cur_is_duplicate_name(p_short_name varchar2) IS
457 SELECT 'X'
458 FROM   pqh_documents_f
459 WHERE document_id <> p_rec.document_id
460 and p_effective_date between effective_start_date and
461        effective_end_date
462 and short_name = p_short_name;
463 --
464 l_short_name varchar2(10);
465 
466 Begin
467   hr_utility.set_location('Entering:'||l_proc, 5);
468   --
469   -- Call all supporting business operations
470      OPEN cur_is_duplicate_name(p_rec.short_name);
471          FETCH cur_is_duplicate_name INTO l_short_name;
472      CLOSE cur_is_duplicate_name;
473 
474      If (l_short_name = 'X') THEN
475        fnd_message.set_name('PQH', 'PQH_SS_DUPLICATE_SHORT_NAME');
476        fnd_message.raise_error;
477      END IF;
478 
479   --
480   --
481   -- "-- No business group context.  HR_STANDARD_LOOKUPS used for validation."
482   --
483   -- Call the datetrack update integrity operation
484   --
485   dt_update_validate
486     (p_datetrack_mode                 => p_datetrack_mode
487     ,p_validation_start_date          => p_validation_start_date
488     ,p_validation_end_date            => p_validation_end_date
489     );
490   --
491   chk_non_updateable_args
492     (p_effective_date  => p_effective_date
493     ,p_rec             => p_rec
494     );
495   --
496   --
497   hr_utility.set_location(' Leaving:'||l_proc, 10);
498 End update_validate;
499 --
500 -- ----------------------------------------------------------------------------
501 -- |---------------------------< delete_validate >----------------------------|
502 -- ----------------------------------------------------------------------------
503 Procedure delete_validate
504   (p_rec                    in pqh_doc_shd.g_rec_type
505   ,p_effective_date         in date
506   ,p_datetrack_mode         in varchar2
507   ,p_validation_start_date  in date
508   ,p_validation_end_date    in date
509   ) is
510 --
511   l_proc        varchar2(72) := g_package||'delete_validate';
512 --
513 Begin
514   hr_utility.set_location('Entering:'||l_proc, 5);
515   --
516   -- Call all supporting business operations
517   --
518   dt_delete_validate
519     (p_datetrack_mode                   => p_datetrack_mode
520     ,p_validation_start_date            => p_validation_start_date
521     ,p_validation_end_date              => p_validation_end_date
522     ,p_document_id                      => p_rec.document_id
523     );
524   --
525   hr_utility.set_location(' Leaving:'||l_proc, 10);
526 End delete_validate;
527 --
528 end pqh_doc_bus;