DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_RST_BUS

Source


1 Package Body pqh_rst_bus as
2 /* $Header: pqrstrhi.pkb 120.5 2011/04/28 09:38:46 sidsaxen ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)	:= '  pqh_rst_bus.';  -- Global package name
9 --
10 --
11 -- ----------------------------------------------------------------------------
12 -- |                     LOCAL Functions                           |
13 -- ----------------------------------------------------------------------------
14 --
15 function get_rule_set_name (p_rule_set_id in number) return varchar2 is
16    l_rule_set_name pqh_rule_sets_tl.rule_set_name%type;
17 cursor c1 is select rule_set_name
18              from pqh_rule_sets_vl
19              where rule_set_id = p_rule_set_id;
20 begin
21    open c1;
22    fetch c1 into l_rule_set_name;
23    close c1;
24    return l_rule_set_name;
25 end;
26 --
27 -- ----------------------------------------------------------------------------
28 -- |                     LOCAL Functions END                       |
29 -- ----------------------------------------------------------------------------
30 --
31 -- ----------------------------------------------------------------------------
32 -- |------< chk_rule_set_id >------|
33 -- ----------------------------------------------------------------------------
34 --
35 -- Description
36 --   This procedure is used to check that the primary key for the table
37 --   is created properly. It should be null on insert and
38 --   should not be able to be updated.
39 --
40 -- Pre Conditions
41 --   None.
42 --
43 -- In Parameters
44 --   rule_set_id PK of record being inserted or updated.
45 --   object_version_number Object version number of record being
46 --                         inserted or updated.
47 --
48 -- Post Success
49 --   Processing continues
50 --
51 -- Post Failure
52 --   Errors handled by the procedure
53 --
54 -- Access Status
55 --   Internal table handler use only.
56 --
57 Procedure chk_rule_set_id(p_rule_set_id                in number,
58                            p_object_version_number       in number) is
59   --
60   l_proc         varchar2(72) := g_package||'chk_rule_set_id';
61   l_api_updating boolean;
62   --
63 Begin
64   --
65   hr_utility.set_location('Entering:'||l_proc, 5);
66   --
67   l_api_updating := pqh_rst_shd.api_updating
68     (p_rule_set_id                => p_rule_set_id,
69      p_object_version_number       => p_object_version_number);
70   --
71   if (l_api_updating
72      and nvl(p_rule_set_id,hr_api.g_number)
73      <>  pqh_rst_shd.g_old_rec.rule_set_id) then
74     --
75     -- raise error as PK has changed
76     --
77     pqh_rst_shd.constraint_error('RULE_SETS_PK');
78     --
79   elsif not l_api_updating then
80     --
81     -- check if PK is null
82     --
83     if p_rule_set_id is not null then
84       --
85       -- raise error as PK is not null
86       --
87       pqh_rst_shd.constraint_error('RULE_SETS_PK');
88       --
89     end if;
90     --
91   end if;
92   --
93   hr_utility.set_location('Leaving:'||l_proc, 10);
94   --
95 End chk_rule_set_id;
96 --
97 -- ----------------------------------------------------------------------------
98 -- |------< chk_rule_set_name >------|
99 -- ----------------------------------------------------------------------------
100 --
101 -- Description
102 --   This procedure is used to check that the rule set name is unique
103 --
104 -- Pre Conditions
105 --   None.
106 --
107 -- In Parameters
108 --   rule_set_id PK of record being inserted or updated.
109 --   object_version_number Object version number of record being
110 --                         inserted or updated.
111 --
112 -- Post Success
113 --   Processing continues
114 --
115 -- Post Failure
116 --   Errors handled by the procedure
117 --
118 -- Access Status
119 --   Internal table handler use only.
120 --
121 Procedure chk_rule_set_name(p_rule_set_id                 in number,
122                             p_rule_set_name               in varchar2,
123                             p_object_version_number       in number) is
124   --
125   l_api_updating boolean;
126   l_dummy        varchar2(1);
127   --
128   Cursor csr_rst_name is
129   select null
130     from pqh_rule_sets_vl
131    where rule_set_name = p_rule_set_name;
132   --
133   l_proc         varchar2(72) := g_package||'chk_rule_set_name';
134   --
135 Begin
136   --
137   hr_utility.set_location('Entering:'||l_proc, 5);
138   --
139   l_api_updating := pqh_rst_shd.api_updating
140     (p_rule_set_id                => p_rule_set_id,
141      p_object_version_number      => p_object_version_number);
142   --
143   if (l_api_updating
144      and nvl(p_rule_set_name,hr_api.g_varchar2)
145      <>  pqh_rst_shd.g_old_rec.rule_set_name
146      OR NOT l_api_updating) then
147     --
148     -- raise error as PK has changed
149     --
150     Open csr_rst_name;
151     Fetch csr_rst_name into l_dummy;
152     If csr_rst_name%found then
153        Close csr_rst_name;
154        hr_utility.set_message(8302,'PQH_DUPLICATE_RULE_SET_NAME');
155        hr_utility.raise_error;
156     End if;
157     Close csr_rst_name;
158     --
159   end if;
160   --
161   hr_utility.set_location('Leaving:'||l_proc, 10);
162   --
163 End chk_rule_set_name;
164 --
165 -- ----------------------------------------------------------------------------
166 -- |------< chk_referenced_rule_set_id >------|
167 -- ----------------------------------------------------------------------------
168 --
169 -- Description
170 --   This procedure checks that a referenced foreign key actually exists
171 --   in the referenced table.
172 --
173 -- Pre-Conditions
174 --   None.
175 --
176 -- In Parameters
177 --   p_rule_set_id PK
178 --   p_referenced_rule_set_id ID of FK column
179 --   p_object_version_number object version number
180 --
181 -- Post Success
182 --   Processing continues
183 --
184 -- Post Failure
185 --   Error raised.
186 --
187 -- Access Status
188 --   Internal table handler use only.
189 --
190 Procedure chk_referenced_rule_set_id (p_rule_set_id            in number,
191                                       p_referenced_rule_set_id in number,
192                                       p_rule_category          in varchar2,
193                                       p_object_version_number  in number) is
194   --
195   l_proc         varchar2(72) := g_package||'chk_referenced_rule_set_id';
196   l_api_updating boolean;
197   l_seeded_rule_flag pqh_rule_sets.seeded_rule_flag%type;
198   l_rule_category pqh_rule_sets.rule_category%type;
199   l_ref_rule_set_name pqh_rule_sets_tl.rule_set_name%type;
200   --
201   cursor c1 is
202     select seeded_rule_flag,rule_set_name,rule_category
203     from   pqh_rule_sets_vl
204     where  rule_set_id = p_referenced_rule_set_id;
205   --
206 Begin
207   --
208   hr_utility.set_location('Entering:'||l_proc,5);
209   --
210   l_api_updating := pqh_rst_shd.api_updating
211     (p_rule_set_id                => p_rule_set_id,
212       p_object_version_number   => p_object_version_number);
213   --
214   if (l_api_updating and
215      (nvl(p_referenced_rule_set_id,hr_api.g_number)
216       <> nvl(pqh_rst_shd.g_old_rec.referenced_rule_set_id,hr_api.g_number)
217       or nvl(p_rule_category,hr_api.g_number)
218       <> nvl(pqh_rst_shd.g_old_rec.rule_category,hr_api.g_number))
219       or not l_api_updating) then
220     --
221     if p_referenced_rule_set_id is not null then
222        open c1;
223        fetch c1 into l_seeded_rule_flag,l_ref_rule_set_name,l_rule_category;
224        if c1%notfound then
225           close c1;
226           pqh_rst_shd.constraint_error('PQH_RULE_SETS_FK4');
227        else
228           close c1;
229           if l_rule_category <> p_rule_category then
230              hr_utility.set_location ('rule category does not match with reference rule',10);
231              hr_utility.set_message(8302,'PQH_CBR_RULE_CAT_REF');
232              hr_utility.set_message_token('CATEGORY_REF',l_rule_category);
233              hr_utility.set_message_token('CATEGORY_RULS',p_rule_category);
234              hr_utility.raise_error;
235           end if;
236           if l_seeded_rule_flag <> 'Y' then
237              hr_utility.set_location ('user defined rule is being made reference rule',10);
238              hr_utility.set_message(8302,'PQH_CBR_USER_DEF_REF');
239              hr_utility.set_message_token('REFERENCE_RULE_SET',l_ref_rule_set_name);
240              hr_utility.raise_error;
241           end if;
242        end if;
243     else
244        if p_rule_category <> 'REALLOCATION' then
245           hr_utility.set_location('Reference rule has to be there',20);
246           hr_utility.set_message(8302,'PQH_CBR_BGT_REALLOC_NO_REF');
247           hr_utility.raise_error;
248        end if;
249     end if;
250   end if;
251   --
252   hr_utility.set_location('Leaving:'||l_proc,10);
253   --
254 End chk_referenced_rule_set_id;
255 --
256 -- ----------------------------------------------------------------------------
257 -- |------< chk_business_group_id >------|
258 -- ----------------------------------------------------------------------------
259 --
260 -- Description
261 --   This procedure checks that a referenced foreign key actually exists
262 --   in the referenced table.
263 --
264 -- Pre-Conditions
265 --   None.
266 --
267 -- In Parameters
268 --   p_rule_set_id PK
269 --   p_business_group_id ID of FK column
270 --   p_object_version_number object version number
271 --
272 -- Post Success
273 --   Processing continues
274 --
275 -- Post Failure
276 --   Error raised.
277 --
278 -- Access Status
279 --   Internal table handler use only.
280 --
281 Procedure chk_business_group_id (p_rule_set_id          in number,
282                             p_business_group_id        in number,
283                             p_object_version_number in number) is
284   --
285   l_proc         varchar2(72) := g_package||'chk_business_group_id';
286   l_api_updating boolean;
287   l_dummy        varchar2(1);
288   --
289   cursor c1 is
290     select null
291     from   per_business_groups a
292     where  a.organization_id = p_business_group_id;
293   --
294 Begin
295   --
296   hr_utility.set_location('Entering:'||l_proc,5);
297   --
298   l_api_updating := pqh_rst_shd.api_updating
299     (p_rule_set_id                => p_rule_set_id,
300       p_object_version_number   => p_object_version_number);
301   --
302   if (l_api_updating
303      and nvl(p_business_group_id,hr_api.g_number)
304      <> nvl(pqh_rst_shd.g_old_rec.business_group_id,hr_api.g_number)
305      or not l_api_updating) then
306     --
307     -- check if business_group_id exists in hr_all_organization_units table
308     --
309     --
310     open c1;
311       --
312       fetch c1 into l_dummy;
313       if c1%notfound then
314         --
315         close c1;
316         --
317         -- raise error as FK does not relate to PK in hr_all_organization_units
318         -- table.
319         --
320         pqh_rst_shd.constraint_error('PQH_RULE_SETS_FK3');
321         --
322       end if;
323       --
324     close c1;
325     --
326   end if;
327   --
328   hr_utility.set_location('Leaving:'||l_proc,10);
329   --
330 End chk_business_group_id;
331 --
332 -- ----------------------------------------------------------------------------
333 -- |----------< chk_duplicate_rule_set >--------------------------------------|
334 -- ----------------------------------------------------------------------------
335 --
336 -- Description
337 --   This procedure checks that a referenced foreign key actually exists
338 --   in the referenced table.
339 --
340 -- Pre-Conditions
341 --   None.
342 --
343 -- In Parameters
344 --   p_rule_set_id PK
345 --   p_organization_id ID of FK column
346 --   p_object_version_number object version number
347 --
348 -- Post Success
349 --   Processing continues
350 --
351 -- Post Failure
352 --   Error raised.
353 --
354 -- Access Status
355 --   Internal table handler use only.
356 --
357 Procedure chk_duplicate_rule_set (p_rule_set_id               in number,
358                                   p_organization_id           in number,
359                                   p_organization_structure_id in NUMBER,
360                                   p_business_group_id         in number,
361                                   p_starting_organization_id  in number,
362                                   p_rule_category	      in varchar2,
363                                   p_referenced_rule_set_id    in number,
364                                   p_object_version_number     in number) is
365   --
366   l_proc         varchar2(72) := g_package||'chk_duplicate_rule_set';
367   l_api_updating boolean;
368   l_business_group_id hr_all_organization_units.business_group_id%type;
369   l_rule_set_name   pqh_rule_sets_tl.rule_set_name%type;
370   l_rule_set_id     pqh_rule_sets.rule_set_id%type;
371   --
372   cursor c1 is
373     select rule_set_id
374     from   pqh_rule_sets
375     where ((p_organization_id is null and organization_id is null) or
376                          (organization_id = p_organization_id))
377     and ((p_organization_structure_id is null and organization_structure_id is null) or
378                          (organization_structure_id = p_organization_structure_id))
379     and ((p_business_group_id is null and business_group_id is null) or
380                          (business_group_id = p_business_group_id))
381     and ((p_starting_organization_id is null and starting_organization_id is null) or
382                          (starting_organization_id = p_starting_organization_id))
383     and ((p_rule_category is null and rule_category is null) or
384     			 (rule_category = p_rule_category))
385     and ((p_referenced_rule_set_id is null and referenced_rule_set_id is null) or
386     			 (referenced_rule_set_id = p_referenced_rule_set_id))
387     and rule_set_id <> p_rule_set_id;
388 
389   --
390 Begin
391   --
392   hr_utility.set_location('Entering:'||l_proc,5);
393   --
394   l_api_updating := pqh_rst_shd.api_updating
395     (p_rule_set_id                => p_rule_set_id,
396       p_object_version_number   => p_object_version_number);
397   --
398   if (l_api_updating and (
399       nvl(p_organization_id,hr_api.g_number) <> nvl(pqh_rst_shd.g_old_rec.organization_id,hr_api.g_number)
400    or nvl(p_organization_structure_id,hr_api.g_number) <> nvl(pqh_rst_shd.g_old_rec.organization_structure_id,hr_api.g_number)
401    or nvl(p_business_group_id,hr_api.g_number) <> nvl(pqh_rst_shd.g_old_rec.business_group_id,hr_api.g_number)
402    or nvl(p_starting_organization_id,hr_api.g_number) <> nvl(pqh_rst_shd.g_old_rec.starting_organization_id,hr_api.g_number)
403    or nvl(p_rule_category,hr_api.g_varchar2) <> nvl(pqh_rst_shd.g_old_rec.rule_category,hr_api.g_varchar2)
404    or nvl(p_referenced_rule_set_id,hr_api.g_number) <> nvl(pqh_rst_shd.g_old_rec.referenced_rule_set_id,hr_api.g_number))
405      or not l_api_updating) then
406      --
407      -- check for duplicate rule sets
408      --
409       open c1;
410       fetch c1 into l_rule_set_id;
411       if c1%found then
412         close c1;
413         --
414         l_rule_set_name := get_rule_set_name(p_rule_set_id);
415         --
416         hr_utility.set_message(8302,'PQH_DUP_RULE_SET');
417         hr_utility.set_message_token('REFERENCE_RULE_SET',l_rule_set_name);
418         hr_utility.raise_error;
419         --
420       end if;
421       --
422       close c1;
423       --
424   end if;
425   --
426   hr_utility.set_location('Leaving:'||l_proc,10);
427   --
428 End chk_duplicate_rule_set;
429 --
430 --
431 -- ----------------------------------------------------------------------------
432 -- |----------< chk_dup_rule_set >--------------------------------------------|
433 -- ----------------------------------------------------------------------------
434 --
435 -- Description
436 --   This procedure checks whether Rule being inserted or updated does not
437 --   already exist for the same scope and referenced rule.
438 --
439 -- Pre-Conditions
440 --   None.
441 --
442 -- In Parameters
443 --   p_rule_set_id PK
444 --   p_organization_id ID of FK column
445 --   p_object_version_number object version number
446 --
447 -- Post Success
448 --   Processing continues
449 --
450 -- Post Failure
451 --   Error raised.
452 --
453 -- Access Status
454 --   Internal table handler use only.
455 --
456   PROCEDURE chk_dup_rule_set(p_rule_set_id               IN NUMBER,
457                              p_organization_id           IN NUMBER,
458                              p_organization_structure_id IN NUMBER,
459                              p_business_group_id         IN NUMBER,
460                              p_starting_organization_id  IN NUMBER,
461                              p_rule_category	         IN VARCHAR2,
462                              p_referenced_rule_set_id    IN NUMBER,
463                              p_seeded_rule_flag          IN VARCHAR2,
464                              p_object_version_number     IN NUMBER) IS
465   --
466     l_proc              VARCHAR2(72) := g_package||'chk_ins_dup_rule_set';
467     l_rule_set_id       PQH_RULE_SETS.rule_set_id%TYPE;
468     l_ref_rule_set_name PQH_RULE_SETS_TL.rule_set_name%TYPE;
469   --
470     CURSOR c1 IS
471     SELECT rule_set_id
472       FROM pqh_rule_sets
473      WHERE rule_set_id                      <> NVL(p_rule_set_id,-1)
474        AND NVL(business_group_id,-1)         = NVL(p_business_group_id,-1)
475        AND NVL(organization_structure_id,-1) = NVL(p_organization_structure_id,-1)
476        AND NVL(starting_organization_id,-1)  = NVL(p_starting_organization_id,-1)
477        AND NVL(organization_id,-1)           = NVL(p_organization_id,-1)
478        AND rule_category                     = p_rule_category
479        AND referenced_rule_set_id            = p_referenced_rule_set_id
480        AND NVL(seeded_rule_flag,'N')         = 'N'
481        AND NVL(p_seeded_rule_flag,'N')       = 'N';
482   --
483   BEGIN
484   --
485     HR_UTILITY.set_location('Entering: '||l_proc,5);
486   --
487     OPEN c1;
488     FETCH c1 into l_rule_set_id;
489     IF c1%FOUND THEN
490        CLOSE c1;
491        l_ref_rule_set_name := get_rule_set_name(p_referenced_rule_set_id);
492        HR_UTILITY.set_message(8302,'PQH_DUP_RULE_SET');
493        HR_UTILITY.set_message_token('REFERENCE_RULE_SET',l_ref_rule_set_name);
494        HR_UTILITY.raise_error;
495     END IF;
496     CLOSE c1;
497   --
498     HR_UTILITY.set_location('Leaving: '||l_proc,10);
499   --
500   END chk_dup_rule_set;
501 --
502 --
503 -- ----------------------------------------------------------------------------
504 -- |------< chk_organization_id >------|
505 -- ----------------------------------------------------------------------------
506 --
507 -- Description
508 --   This procedure checks that a referenced foreign key actually exists
509 --   in the referenced table.
510 --
511 -- Pre-Conditions
512 --   None.
513 --
514 -- In Parameters
515 --   p_rule_set_id PK
516 --   p_organization_id ID of FK column
517 --   p_object_version_number object version number
518 --
519 -- Post Success
520 --   Processing continues
521 --
522 -- Post Failure
523 --   Error raised.
524 --
525 -- Access Status
526 --   Internal table handler use only.
527 --
528 Procedure chk_organization_id (p_rule_set_id            in number,
529                             p_organization_id           in number,
530                             p_business_group_id         in number,
531                             p_object_version_number     in number) is
532   --
533   l_proc         varchar2(72) := g_package||'chk_organization_id';
534   l_api_updating boolean;
535   l_dummy        varchar2(1);
536   l_business_group_id hr_all_organization_units.business_group_id%type;
537   --
538   cursor c1 is
539     select business_group_id
540     from   hr_all_organization_units a
541     where  a.organization_id = p_organization_id;
542   --
543 Begin
544   --
545   hr_utility.set_location('Entering:'||l_proc,5);
546   --
547   l_api_updating := pqh_rst_shd.api_updating
548     (p_rule_set_id                => p_rule_set_id,
549       p_object_version_number   => p_object_version_number);
550   --
551   -- if business group is changed or organization is changed this rule should kick in
552   -- provided organization id is there
553   --
554   if (l_api_updating
555      and (nvl(p_business_group_id,hr_api.g_number)
556      <> nvl(pqh_rst_shd.g_old_rec.business_group_id,hr_api.g_number)
557      or nvl(p_organization_id,hr_api.g_number)
558      <> nvl(pqh_rst_shd.g_old_rec.organization_id,hr_api.g_number))
559      or not l_api_updating)
560      and p_organization_id is not null then
561      --
562      -- check if organization value exists in hr_all_organization_units table
563      --
564       open c1;
565       --
566       fetch c1 into l_business_group_id;
567       if c1%notfound then
568         --
569         close c1;
570         --
571         -- raise error as FK does not relate to PK in hr_all_organization_units
572         -- table.
573         --
574         hr_utility.set_message(8302,'PQH_ORG_NOT_VALID');
575         hr_utility.raise_error;
576         --
577       end if;
578       --
579       close c1;
580       --
581       --
582       -- Check if the organization_structure belongs to the same business_group
583       -- As the passed business_group
584       --
585       If l_business_group_id <> p_business_group_id then
586          --
587          hr_utility.set_message(8302,'PQH_ORG_NOT_IN_BG');
588          hr_utility.raise_error;
589          --
590       End if;
591       --
592   end if;
593   --
594   hr_utility.set_location('Leaving:'||l_proc,10);
595   --
596 End chk_organization_id;
597 --
598 -- ----------------------------------------------------------------------------
599 -- |------< chk_organization_structure_id >------|
600 -- ----------------------------------------------------------------------------
601 --
602 -- Description
603 --   This procedure checks that a referenced foreign key actually exists
604 --   in the referenced table.
605 --
606 -- Pre-Conditions
607 --   None.
608 --
609 -- In Parameters
610 --   p_rule_set_id PK
611 --   p_organization_structure_id ID of FK column
612 --   p_object_version_number object version number
613 --
614 -- Post Success
615 --   Processing continues
616 --
617 -- Post Failure
618 --   Error raised.
619 --
620 -- Access Status
621 --   Internal table handler use only.
622 --
623 Procedure chk_organization_structure_id (p_rule_set_id               in number,
624                                          p_organization_structure_id in number,
625                                          p_business_group_id         in number,
626                                          p_object_version_number     in number) is
627   --
628   l_proc         varchar2(72) := g_package||'chk_organization_structure_id';
629   l_api_updating boolean;
630   l_dummy        varchar2(1);
631 l_business_group_id per_organization_structures.business_group_id%type;
632 
633   --
634   cursor c1 is
635     select business_group_id
636     from   per_organization_structures a
637     where  a.organization_structure_id = p_organization_structure_id;
638   --
639 Begin
640   --
641   hr_utility.set_location('Entering:'||l_proc,5);
642   --
643   l_api_updating := pqh_rst_shd.api_updating
644     (p_rule_set_id                => p_rule_set_id,
645       p_object_version_number   => p_object_version_number);
646   --
647   if (l_api_updating
648      and (nvl(p_organization_structure_id,hr_api.g_number)
649      <> nvl(pqh_rst_shd.g_old_rec.organization_structure_id,hr_api.g_number)
650      or nvl(p_organization_structure_id,hr_api.g_number)
651      <> nvl(pqh_rst_shd.g_old_rec.organization_structure_id,hr_api.g_number))
652      or not l_api_updating) and
653      p_organization_structure_id is not null then
654     --
655     -- check if organization_structure_id value exists in per_organization_structures table
656     --
657     open c1;
658       --
659       fetch c1 into l_business_group_id;
660       if c1%notfound then
661         --
662         close c1;
663         --
664         -- raise error as FK does not relate to PK in per_organization_structures
665         -- table.
666         --
667         pqh_rst_shd.constraint_error('PQH_RULE_SETS_FK2');
668         --
669       end if;
670       --
671     close c1;
672     --
673     --
674     -- Check if the organization_structure belongs to the same business_group
675     -- As the passed business_group
676     --
677     If l_business_group_id <> p_business_group_id then
678       hr_utility.set_message(8302,'PQH_ORG_STRUCT_NOT_IN_BG');
679       hr_utility.raise_error;
680     End if;
681     --
682 
683   end if;
684   --
685   hr_utility.set_location('Leaving:'||l_proc,10);
686   --
687 End chk_organization_structure_id;
688 --
689 -- ----------------------------------------------------------------------------
690 -- |------< chk_rule_level_cd >------|
691 -- ----------------------------------------------------------------------------
692 --
693 -- Description
694 --   This procedure is used to check that the lookup value is valid.
695 --
696 -- Pre Conditions
697 --   None.
698 --
699 -- In Parameters
700 --   rule_set_id PK of record being inserted or updated.
701 --   rule_level_cd Value of lookup code.
702 --   effective_date effective date
703 --   object_version_number Object version number of record being
704 --                         inserted or updated.
705 --
706 -- Post Success
707 --   Processing continues
708 --
709 -- Post Failure
710 --   Error handled by procedure
711 --
712 -- Access Status
713 --   Internal table handler use only.
714 --
715 Procedure chk_rule_level_cd(p_rule_set_id                in number,
716                             p_rule_level_cd               in varchar2,
717                             p_effective_date              in date,
718                             p_object_version_number       in number) is
719   --
720   l_proc         varchar2(72) := g_package||'chk_rule_level_cd';
721   l_api_updating boolean;
722   --
723 Begin
724   --
725   hr_utility.set_location('Entering:'||l_proc, 5);
726   --
727   l_api_updating := pqh_rst_shd.api_updating
728     (p_rule_set_id                => p_rule_set_id,
729      p_object_version_number       => p_object_version_number);
730   --
731   if (l_api_updating
732       and p_rule_level_cd
733       <> nvl(pqh_rst_shd.g_old_rec.rule_level_cd,hr_api.g_varchar2)
734       or not l_api_updating)
735       and p_rule_level_cd is not null then
736     --
737     -- check if value of lookup falls within lookup type.
738     --
739     if hr_api.not_exists_in_hr_lookups
740           (p_lookup_type    => 'PQH_RULE_LEVEL',
741            p_lookup_code    => p_rule_level_cd,
742            p_effective_date => p_effective_date) then
743       --
744       -- raise error as does not exist as lookup
745       --
746       hr_utility.set_message(801,'HR_LOOKUP_DOES_NOT_EXIST');
747       hr_utility.raise_error;
748       --
749     end if;
750     --
751   end if;
752   --
753   hr_utility.set_location('Leaving:'||l_proc,10);
754   --
755 end chk_rule_level_cd;
756 --
757 --
758 -- ----------------------------------------------------------------------------
759 -- |------< chk_rule_applicability >------|
760 -- ----------------------------------------------------------------------------
761 --
762 -- Description
763 --   This procedure is used to check that the lookup value is valid.
764 --
765 -- Pre Conditions
766 --   None.
767 --
768 -- In Parameters
769 --   rule_set_id PK of record being inserted or updated.
770 --   rule_applicability Value of lookup code.
771 --   effective_date effective date
772 --   object_version_number Object version number of record being
773 --                         inserted or updated.
774 --
775 -- Post Success
776 --   Processing continues
777 --
778 -- Post Failure
779 --   Error handled by procedure
780 --
781 -- Access Status
782 --   Internal table handler use only.
783 --
784 Procedure chk_rule_applicability(p_rule_set_id                in number,
785                                  p_rule_applicability          in varchar2,
786                                  p_rule_category               in varchar2,
787                                  p_effective_date              in date,
788                                  p_object_version_number       in number) is
789   --
790   l_proc         varchar2(72) := g_package||'chk_rule_applicability';
791   l_api_updating boolean;
792   l_rule_category_meaning varchar2(240);
793   --
794 Begin
795   --
796   hr_utility.set_location('Entering:'||l_proc, 5);
797   --
798   l_api_updating := pqh_rst_shd.api_updating
799     (p_rule_set_id                => p_rule_set_id,
800      p_object_version_number       => p_object_version_number);
801   --
802   if (l_api_updating
803       and (p_rule_applicability <> nvl(pqh_rst_shd.g_old_rec.rule_applicability,hr_api.g_varchar2)
804       or p_rule_category <> nvl(pqh_rst_shd.g_old_rec.rule_category,hr_api.g_varchar2))
805       or not l_api_updating)
806       and p_rule_applicability is not null then
807     --
808     -- check if value of lookup falls within lookup type.
809     --
810     if hr_api.not_exists_in_hr_lookups
811           (p_lookup_type    => 'PQH_CBR_APPLICABILITY',
812            p_lookup_code    => p_rule_applicability,
813            p_effective_date => p_effective_date) then
814       --
815       -- raise error as does not exist as lookup
816       --
817       hr_utility.set_message(801,'HR_LOOKUP_DOES_NOT_EXIST');
818       hr_utility.raise_error;
819       --
820     end if;
821     if p_rule_category ='REALLOCATION' then
822        if p_rule_applicability not in ('DONOR','RECEIVER') then
823           hr_utility.set_message(8302,'PQH_CBR_BR_APPL_MISMATCH');
824           hr_utility.raise_error;
825        end if;
826     else
827        if p_rule_applicability not in ('NONE') then
828 	select hr_general.decode_lookup('PQH_CBR_RULE_CATEGORY', p_rule_category)
829 	into l_rule_category_meaning from dual;
830 		if l_rule_category_meaning is not null then
831 			l_rule_category_meaning := '"'||l_rule_category_meaning||'"';
832 		end if;
833 	hr_utility.set_message(8302,'PQH_CBR_OTHER_APPL_MISMATCH');
834 	hr_utility.set_message_token('CATEGORY_RULE', l_rule_category_meaning);
835         hr_utility.raise_error;
836        end if;
837     end if;
838     --
839   end if;
840   --
841   hr_utility.set_location('Leaving:'||l_proc,10);
842   --
843 end chk_rule_applicability;
844 --
845 --
846 -- ----------------------------------------------------------------------------
847 -- |------< chk_rule_category >------|
848 -- ----------------------------------------------------------------------------
849 --
850 -- Description
851 --   This procedure is used to check that the lookup value is valid.
852 --
853 -- Pre Conditions
854 --   None.
855 --
856 -- In Parameters
857 --   rule_set_id PK of record being inserted or updated.
858 --   rule_category Value of lookup code.
859 --   effective_date effective date
860 --   object_version_number Object version number of record being
861 --                         inserted or updated.
862 --
863 -- Post Success
864 --   Processing continues
865 --
866 -- Post Failure
867 --   Error handled by procedure
868 --
869 -- Access Status
870 --   Internal table handler use only.
871 --
872 Procedure chk_rule_category(p_rule_set_id                in number,
873                             p_rule_category               in varchar2,
874                             p_effective_date              in date,
875                             p_object_version_number       in number) is
876   --
877   l_proc         varchar2(72) := g_package||'chk_rule_category';
878   l_api_updating boolean;
879   --
880 Begin
881   --
882   hr_utility.set_location('Entering:'||l_proc, 5);
883   --
884   l_api_updating := pqh_rst_shd.api_updating
885     (p_rule_set_id                => p_rule_set_id,
886      p_object_version_number      => p_object_version_number);
887   --
888   if (l_api_updating
889       and p_rule_category
890       <> nvl(pqh_rst_shd.g_old_rec.rule_category,hr_api.g_varchar2)
891       or not l_api_updating)
892       and p_rule_category is not null then
893     --
894     -- check if value of lookup falls within lookup type.
895     --
896     if hr_api.not_exists_in_hr_lookups
897           (p_lookup_type    => 'PQH_CBR_RULE_CATEGORY',
898            p_lookup_code    => p_rule_category,
899            p_effective_date => p_effective_date) then
900       --
901       -- raise error as does not exist as lookup
902       --
903       hr_utility.set_message(801,'HR_LOOKUP_DOES_NOT_EXIST');
904       hr_utility.raise_error;
905       --
906     end if;
907     --
908   end if;
909   --
910   hr_utility.set_location('Leaving:'||l_proc,10);
911   --
912 end chk_rule_category;
913 --
914 ----------------------------Extra API checks----------------------------------
915 --
916 -- ----------------------------------------------------------------------------
917 -- |------< get_org_structure_version_id >------|
918 -- ----------------------------------------------------------------------------
919 --
920 -- Description
921 --   This procedure is used to check if there is a overlap of entered
922 --   org structure and existing org structures for the Business Group
923 --   and Referenced rule set
924 --
925 Procedure get_org_structure_version_id
926                               (p_org_structure_id IN   NUMBER,
927                                p_org_structure_version_id  OUT NOCOPY  NUMBER) is
928 Cursor c1 is
929   Select org_structure_version_id
930     From per_org_structure_versions
931    Where organization_structure_id = p_org_structure_id
932      AND version_number =
933          (select max(version_number)
934           From per_org_structure_versions
935           Where organization_structure_id = p_org_structure_id);
936 Begin
937   --
938   Open c1;
939   Fetch c1 into p_org_structure_version_id;
940   Close c1;
941   --
942   --
943 End;
944 --
945 --
946 --
947 Procedure chk_org_in_org_structure
948                            (p_rule_set_id                    in number,
949                             p_starting_organization_id       in number,
950                             p_organization_structure_id      in number,
951                             p_object_version_number          in number) is
952 --
953   l_proc                      varchar2(72) := g_package||'chk_org_in_org_structure';
954   l_dummy                     varchar2(1);
955   l_api_updating boolean;
956   l_org_structure_version_id  per_org_structure_versions.org_structure_version_id%type;
957 --
958 Cursor c1 is
959   Select null
960    FROM per_org_structure_elements a
961    WHERE a.org_structure_version_id   = l_org_structure_version_id
962    AND   a.organization_id_child      = p_starting_organization_id
963   UNION
964   Select null
965    FROM per_org_structure_elements b
966    WHERE b.org_structure_version_id   = l_org_structure_version_id
967    AND   b.organization_id_parent     = p_starting_organization_id;
968   --
969 Begin
970   --
971   hr_utility.set_location('Entering:'||l_proc, 5);
972   --
973   l_api_updating := pqh_rst_shd.api_updating
974      (p_rule_set_id            => p_rule_set_id,
975       p_object_version_number   => p_object_version_number);
976   --
977   if (l_api_updating
978      and ( nvl(p_starting_organization_id,hr_api.g_number)
979      <> nvl(pqh_rst_shd.g_old_rec.starting_organization_id,hr_api.g_number)
980      or nvl(p_organization_structure_id,hr_api.g_number)
981      <> nvl(pqh_rst_shd.g_old_rec.organization_structure_id,hr_api.g_number))
982      or not l_api_updating) then
983     --
984     If p_organization_structure_id IS NOT NULL then
985     --
986     -- get version id for the structure;
987     --
988       get_org_structure_version_id
989       (p_org_structure_id         => p_organization_structure_id,
990        p_org_structure_version_id => l_org_structure_version_id);
991       --
992       Open c1;
993       --
994       Fetch c1 into l_dummy;
995       --
996       If c1%notfound then
997         Close c1;
998         hr_utility.set_message(8302, 'PQH_ORG_NOT_IN_ORG_STRUCT');
999         hr_utility.raise_error;
1000       End if;
1001       --
1002       Close c1;
1003       --
1004     End if;
1005     --
1006   End if;
1007   --
1008   hr_utility.set_location(' Leaving:'||l_proc, 10);
1009   --
1010 End;
1011 --
1012 --
1013 Procedure chk_rule_scope (p_rule_set_id                    in number,
1014                           p_starting_organization_id       in number,
1015                           p_organization_id                in number,
1016                           p_organization_structure_id      in number,
1017                           p_object_version_number          in number) is
1018 --
1019   l_proc                      varchar2(72) := g_package||'chk_rule_scope';
1020   l_api_updating boolean;
1021 --
1022 Begin
1023   --
1024   hr_utility.set_location('Entering:'||l_proc, 5);
1025   --
1026   l_api_updating := pqh_rst_shd.api_updating
1027      (p_rule_set_id            => p_rule_set_id,
1028       p_object_version_number   => p_object_version_number);
1029   --
1030   if (l_api_updating
1031      and ( nvl(p_starting_organization_id,hr_api.g_number)
1032      <> nvl(pqh_rst_shd.g_old_rec.starting_organization_id,hr_api.g_number)
1033      or nvl(p_organization_id,hr_api.g_number)
1034      <> nvl(pqh_rst_shd.g_old_rec.organization_id,hr_api.g_number)
1035      or nvl(p_organization_structure_id,hr_api.g_number)
1036      <> nvl(pqh_rst_shd.g_old_rec.organization_structure_id,hr_api.g_number))
1037      or not l_api_updating) then
1038     --
1039        if p_organization_structure_id is not null and p_organization_id is not null then
1040           hr_utility.set_location('org hier entered, org must be null',20);
1041           hr_utility.set_message(8302, 'PQH_ORG_WITH_ORG_STRUCT');
1042           hr_utility.raise_error;
1043        end if;
1044   end if;
1045   hr_utility.set_location(' Leaving:'||l_proc, 10);
1046   --
1047 End;
1048 --
1049 -- The foll procedures are written to check for org_structure overlap
1050 --
1051 ------------------------------------------------------------------------------
1052 -- |--------------------------< get_ref_rule_set_name>-----------------------
1053 ------------------------------------------------------------------------------
1054 --
1055 Procedure get_ref_rule_set_name(p_rule_set_id    in number,
1056                                 p_rule_set_name out nocopy varchar2) is
1057 --
1058 Cursor csr_ref is
1059  Select rule_set_name
1060    From pqh_rule_sets_tl
1061   Where rule_set_id = p_rule_set_id;
1062 --
1063   l_proc    varchar2(72) := g_package||'get_ref_rule_set_name';
1064 --
1065 Begin
1066   --
1067   hr_utility.set_location(' Entering:'||l_proc, 5);
1068   --
1069   Open csr_ref;
1070   --
1071   Fetch csr_ref into p_rule_set_name;
1072   --
1073   Close csr_ref;
1074   --
1075   hr_utility.set_location(' Leaving:'||l_proc, 10);
1076   --
1077 End;
1078 --
1079 --
1080 --
1081 -- ----------------------------------------------------------------------------
1082 -- |---------------------------< insert_validate >----------------------------|
1083 -- ----------------------------------------------------------------------------
1084 Procedure insert_validate(p_rec in pqh_rst_shd.g_rec_type
1085                          ,p_effective_date in date) is
1086 --
1087   l_proc  varchar2(72) := g_package||'insert_validate';
1088 --
1089 Begin
1090   hr_utility.set_location('Entering:'||l_proc, 5);
1091   --
1092   -- Call all supporting business operations
1093   --
1094   chk_rule_set_id
1095   (p_rule_set_id          => p_rec.rule_set_id,
1096    p_object_version_number => p_rec.object_version_number);
1097   --
1098   chk_rule_set_name
1099   (p_rule_set_id            => p_rec.rule_set_id,
1100    p_rule_set_name          => p_rec.rule_set_name,
1101    p_object_version_number  => p_rec.object_version_number);
1102   --
1103   chk_referenced_rule_set_id
1104   (p_rule_set_id            => p_rec.rule_set_id,
1105    p_referenced_rule_set_id => p_rec.referenced_rule_set_id,
1106    p_rule_category          => p_rec.rule_category,
1107    p_object_version_number  => p_rec.object_version_number);
1108   --
1109   chk_business_group_id
1110   (p_rule_set_id          => p_rec.rule_set_id,
1111    p_business_group_id        => p_rec.business_group_id,
1112    p_object_version_number => p_rec.object_version_number);
1113   --
1114   chk_organization_id
1115   (p_rule_set_id          => p_rec.rule_set_id,
1116    p_business_group_id        => p_rec.business_group_id,
1117    p_organization_id          => p_rec.organization_id,
1118    p_object_version_number => p_rec.object_version_number);
1119   --
1120   chk_organization_structure_id
1121   (p_rule_set_id          => p_rec.rule_set_id,
1122    p_business_group_id        => p_rec.business_group_id,
1123    p_organization_structure_id          => p_rec.organization_structure_id,
1124    p_object_version_number => p_rec.object_version_number);
1125   --
1126 /* Commented by deenath. Now calling chk_dup_rule_set.
1127   chk_duplicate_rule_set
1128   (p_rule_set_id               => p_rec.rule_set_id,
1129    p_business_group_id         => p_rec.business_group_id,
1130    p_organization_id           => p_rec.organization_id,
1131    p_referenced_rule_set_id    => p_rec.referenced_rule_Set_id,
1132    p_organization_structure_id => p_rec.organization_structure_id,
1133    p_starting_organization_id  => p_rec.starting_organization_id,
1134    p_rule_category             => p_rec.rule_category,
1135    p_object_version_number     => p_rec.object_version_number);
1136 */
1137   chk_dup_rule_set
1138   (p_rule_set_id               => p_rec.rule_set_id,
1139    p_business_group_id         => p_rec.business_group_id,
1140    p_organization_id           => p_rec.organization_id,
1141    p_referenced_rule_set_id    => p_rec.referenced_rule_Set_id,
1142    p_organization_structure_id => p_rec.organization_structure_id,
1143    p_starting_organization_id  => p_rec.starting_organization_id,
1144    p_rule_category             => p_rec.rule_category,
1145    p_seeded_rule_flag          => p_rec.seeded_rule_flag,
1146    p_object_version_number     => p_rec.object_version_number);
1147   --
1148   chk_org_in_org_structure
1149   (p_rule_set_id                => p_rec.rule_set_id,
1150    p_starting_organization_id   => p_rec.starting_organization_id,
1151    p_organization_structure_id  => p_rec.organization_structure_id,
1152    p_object_version_number      => p_rec.object_version_number);
1153   --
1154   chk_rule_scope
1155   (p_rule_set_id                => p_rec.rule_set_id,
1156    p_starting_organization_id   => p_rec.starting_organization_id,
1157    p_organization_id            => p_rec.organization_id,
1158    p_organization_structure_id  => p_rec.organization_structure_id,
1159    p_object_version_number      => p_rec.object_version_number);
1160   --
1161   chk_rule_level_cd
1162   (p_rule_set_id          => p_rec.rule_set_id,
1163    p_rule_level_cd         => p_rec.rule_level_cd,
1164    p_effective_date        => p_effective_date,
1165    p_object_version_number => p_rec.object_version_number);
1166   --
1167   chk_rule_category
1168   (p_rule_set_id          => p_rec.rule_set_id,
1169    p_rule_category         => p_rec.rule_category,
1170    p_effective_date        => p_effective_date,
1171    p_object_version_number => p_rec.object_version_number);
1172   --
1173   chk_rule_applicability
1174   (p_rule_set_id          => p_rec.rule_set_id,
1175    p_rule_applicability         => p_rec.rule_applicability,
1176    p_rule_category              => p_rec.rule_category,
1177    p_effective_date        => p_effective_date,
1178    p_object_version_number => p_rec.object_version_number);
1179   --
1180   -- call hr_api.validate_bus_grp_id
1181   --
1182   hr_api.validate_bus_grp_id(p_rec.business_group_id);  -- Validate Bus Grp
1183   --
1184   hr_utility.set_location(' Leaving:'||l_proc, 10);
1185 End insert_validate;
1186 --
1187 -- ----------------------------------------------------------------------------
1188 -- |---------------------------< update_validate >----------------------------|
1189 -- ----------------------------------------------------------------------------
1190 Procedure update_validate(p_rec in pqh_rst_shd.g_rec_type
1191                          ,p_effective_date in date) is
1192 --
1193   l_proc  varchar2(72) := g_package||'update_validate';
1194 --
1195 Begin
1196   hr_utility.set_location('Entering:'||l_proc, 5);
1197   --
1198   -- Call all supporting business operations
1199   --
1200   chk_rule_set_id
1201   (p_rule_set_id          => p_rec.rule_set_id,
1202    p_object_version_number => p_rec.object_version_number);
1203   --
1204   chk_rule_set_name
1205   (p_rule_set_id            => p_rec.rule_set_id,
1206    p_rule_set_name          => p_rec.rule_set_name,
1207    p_object_version_number  => p_rec.object_version_number);
1208   --
1209   chk_referenced_rule_set_id
1210   (p_rule_set_id            => p_rec.rule_set_id,
1211    p_referenced_rule_set_id => p_rec.referenced_rule_set_id,
1212    p_rule_category          => p_rec.rule_category,
1213    p_object_version_number  => p_rec.object_version_number);
1214   --
1215   chk_business_group_id
1216   (p_rule_set_id           => p_rec.rule_set_id,
1217    p_business_group_id     => p_rec.business_group_id,
1218    p_object_version_number => p_rec.object_version_number);
1219   --
1220   chk_organization_id
1221   (p_rule_set_id               => p_rec.rule_set_id,
1222    p_business_group_id         => p_rec.business_group_id,
1223    p_organization_id           => p_rec.organization_id,
1224    p_object_version_number     => p_rec.object_version_number);
1225   --
1226   chk_organization_structure_id
1227   (p_rule_set_id               => p_rec.rule_set_id,
1228    p_business_group_id         => p_rec.business_group_id,
1229    p_organization_structure_id => p_rec.organization_structure_id,
1230    p_object_version_number     => p_rec.object_version_number);
1231   --
1232 /* Commented by deenath. Now calling chk_dup_rule_set.
1233   chk_duplicate_rule_set
1234   (p_rule_set_id          => p_rec.rule_set_id,
1235    p_business_group_id         => p_rec.business_group_id,
1236    p_organization_id           => p_rec.organization_id,
1237    p_referenced_rule_set_id    => p_rec.referenced_rule_Set_id,
1238    p_organization_structure_id => p_rec.organization_structure_id,
1239    p_starting_organization_id  => p_rec.starting_organization_id,
1240    p_rule_category             => p_rec.rule_category,
1241    p_object_version_number => p_rec.object_version_number);
1242 */
1243   chk_dup_rule_set
1244   (p_rule_set_id               => p_rec.rule_set_id,
1245    p_business_group_id         => p_rec.business_group_id,
1246    p_organization_id           => p_rec.organization_id,
1247    p_referenced_rule_set_id    => p_rec.referenced_rule_Set_id,
1248    p_organization_structure_id => p_rec.organization_structure_id,
1249    p_starting_organization_id  => p_rec.starting_organization_id,
1250    p_rule_category             => p_rec.rule_category,
1251    p_seeded_rule_flag          => p_rec.seeded_rule_flag,
1252    p_object_version_number     => p_rec.object_version_number);
1253   --
1254   chk_org_in_org_structure
1255   (p_rule_set_id                => p_rec.rule_set_id,
1256    p_starting_organization_id   => p_rec.starting_organization_id,
1257    p_organization_structure_id  => p_rec.organization_structure_id,
1258    p_object_version_number      => p_rec.object_version_number);
1259   --
1260   chk_rule_scope
1261   (p_rule_set_id                => p_rec.rule_set_id,
1262    p_starting_organization_id   => p_rec.starting_organization_id,
1263    p_organization_id            => p_rec.organization_id,
1264    p_organization_structure_id  => p_rec.organization_structure_id,
1265    p_object_version_number      => p_rec.object_version_number);
1266   --
1267   chk_rule_level_cd
1268   (p_rule_set_id           => p_rec.rule_set_id,
1269    p_rule_level_cd         => p_rec.rule_level_cd,
1270    p_effective_date        => p_effective_date,
1271    p_object_version_number => p_rec.object_version_number);
1272   --
1273   chk_rule_category
1274   (p_rule_set_id           => p_rec.rule_set_id,
1275    p_rule_category         => p_rec.rule_category,
1276    p_effective_date        => p_effective_date,
1277    p_object_version_number => p_rec.object_version_number);
1278   --
1279   chk_rule_applicability
1280   (p_rule_set_id           => p_rec.rule_set_id,
1281    p_rule_applicability    => p_rec.rule_applicability,
1282    p_rule_category              => p_rec.rule_category,
1283    p_effective_date        => p_effective_date,
1284    p_object_version_number => p_rec.object_version_number);
1285   --
1286   -- call hr_api.validate_bus_grp_id
1287   --
1288   hr_api.validate_bus_grp_id(p_rec.business_group_id);  -- Validate Bus Grp
1289   --
1290   hr_utility.set_location(' Leaving:'||l_proc, 10);
1291 End update_validate;
1292 --
1293 -- ----------------------------------------------------------------------------
1294 -- |---------------------------< delete_validate >----------------------------|
1295 -- ----------------------------------------------------------------------------
1296 Procedure delete_validate(p_rec in pqh_rst_shd.g_rec_type
1297                          ,p_effective_date in date) is
1298 --
1299   l_proc  varchar2(72) := g_package||'delete_validate';
1300 --
1301 Begin
1302   hr_utility.set_location('Entering:'||l_proc, 5);
1303   --
1304   -- Call all supporting business operations
1305   --
1306   hr_utility.set_location(' Leaving:'||l_proc, 10);
1307 End delete_validate;
1308 --
1309 --
1310 --  ---------------------------------------------------------------------------
1311 --  |---------------------< return_legislation_code >-------------------------|
1312 --  ---------------------------------------------------------------------------
1313 --
1314 function return_legislation_code
1315   (p_rule_set_id in number) return varchar2 is
1316   --
1317   -- Declare cursor
1318   --
1319   cursor csr_leg_code is
1320     select a.legislation_code
1321     from   per_business_groups a,
1322            pqh_rule_sets b
1323     where b.rule_set_id      = p_rule_set_id
1324     and   a.business_group_id = b.business_group_id;
1325   --
1326   -- Declare local variables
1327   --
1328   l_legislation_code  varchar2(150);
1329   l_proc              varchar2(72)  :=  g_package||'return_legislation_code';
1330   --
1331 begin
1332   --
1333   hr_utility.set_location('Entering:'|| l_proc, 10);
1334   --
1335   -- Ensure that all the mandatory parameter are not null
1336   --
1337   hr_api.mandatory_arg_error(p_api_name       => l_proc,
1338                              p_argument       => 'rule_set_id',
1339                              p_argument_value => p_rule_set_id);
1340   --
1341   open csr_leg_code;
1342     --
1343     fetch csr_leg_code into l_legislation_code;
1344     --
1345     if csr_leg_code%notfound then
1346       --
1347       close csr_leg_code;
1348       --
1349       -- The primary key is invalid therefore we must error
1350       --
1351       hr_utility.set_message(801,'HR_7220_INVALID_PRIMARY_KEY');
1352       hr_utility.raise_error;
1353       --
1354     end if;
1355     --
1356   close csr_leg_code;
1357   --
1358   hr_utility.set_location(' Leaving:'|| l_proc, 20);
1359   --
1360   return l_legislation_code;
1361   --
1362 end return_legislation_code;
1363 --
1364 end pqh_rst_bus;