DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_FR_SICK_PAY_PROCESSING

Source


1 PACKAGE BODY pay_fr_sick_pay_processing AS
2   /* $Header: pyfrsppr.pkb 120.1 2005/08/29 07:42:08 ayegappa noship $ */
3   --
4   --
5   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6   -- Constants identifying the processing mode.
7   --
8   -- cs_PROCESS        - Currently trying to process each guarantee.
9   -- cs_FINAL_PROCESS  - Processing to completion the best guarantee.
10   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11   --
12   cs_PROCESS                 CONSTANT NUMBER := 10;
13   cs_FINAL_PROCESS           CONSTANT NUMBER := 20;
14   --
15   --
16   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17 
18   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19   --
20   cs_MARGIN           CONSTANT NUMBER := 1;
21   --
22   --
23   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24   -- Global variables
25   --
26   -- g_ctl                    - Holds control information used to manage the processing.
27   -- g_rules                  - Enumerated set of rules covering all possible types of
28   --                            guarantee.
29   -- g_iter_rules             - Enumerated set of rules identifying which elements are
30   --                            relevant to be processed on a particular iteration for each
31   --                            type of guarantee.
32   -- g_asg                    - Holds information on the current assignment being processed.
33   -- g_absence                - Holds information on the current absence being processed.
34   -- g_coverages              - Holds information on all the guarantees that cover the
35   --                            absence being processed.
36   -- g_guarantee_type_lookups - Holds a mapping between between the internal reference
37   --                            for each type of guarantee (numeric) and a corresponding
38   --                            lookup code for external use.
39   --
40   -- NB. the blank versions are used when the corresponding global variable needs to
41   --     be cleared out.
42   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43   --
44   g_ctl                    t_ctl;
45   g_asg                    t_asg;
46   g_absence                t_absence_arch;
47   g_rules                  t_rules;
48   g_iter_rules             t_iter_rules;
49   g_coverages              t_coverages;
50   g_guarantee_type_lookups t_guarantee_type_lookups;
51   --
52   blank_ctl                t_ctl;
53   blank_absence            t_absence_arch;
54   blank_coverages          t_coverages;
55   l_mode                   VARCHAR2(1);
56   --
57   --
58   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59   -- Defines the processing rules for each type of guarantee. Broken down into basic
60   -- rules dictating their overall processing and further iteration rules which identify
61   -- which elements need to be processed on each iteration for that guarantee -
62   --
63   -- Basic Rules (g_rules):
64   --
65   -- stop   - Iteration on which to stop the processing.
66   -- repeat - Iteration from which to start repeating the processing. This is used to
67   --          control access to the iteration rules e.g. an value of 3 means the
68   --          following -
69   --
70   --          Iteration     : 1 2 3 4 5 6 7 etc...
71   --          Iteration Rule: 1 2 3 3 3 3 3 etc...
72   --
73   --          The overall affect is to use the third iteration rule for all processing
74   --          of the guarantee once the actual iteration has reached 3.
75   --
76   -- Iteration Rules (g_iter_rules):
77   --
78   -- ijss_payment    - Y/N flag indicating inclusion of the ijss payment.
79   -- deduct_for_sick - Y/N flag indicating inclusion of the deduction for sickness.
80   -- gi_payment      - Y/N flag indicating inclusion of the guaranteed income payment.
81   -- sick_adj        - Y/N flag indicating that an adjsutment is required (net to
82   --                   gross processing).
83   -- sick_ins        - Y/N flag indicating inclusion of the third party insurance payment.
84   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
85   --
86   PROCEDURE initialise_processing_rules IS
87   BEGIN
88 
89    hr_utility.set_location('initialise_processing_rules ',10);
90     --
91     --
92     -- Garantie au net processing rules.
93     --
94     g_rules(cs_GN).repeat := 1;
95     g_rules(cs_GN).stop   := NULL;
96     --
97     g_iter_rules(cs_GN + 1).ijss_payment    := 'Y';
98     g_iter_rules(cs_GN + 1).deduct_for_sick := 'Y';
99     g_iter_rules(cs_GN + 1).gi_payment      := 'N';
100     g_iter_rules(cs_GN + 1).sick_adj        := 'Y';
101     g_iter_rules(cs_GN + 1).gi_adj          := 'N';
102     g_iter_rules(cs_GN + 1).gross_ijss_adj  := 'N';
103 
104     --
105     --
106     -- Legal processing rules.
107     --
108     g_rules(cs_LE).repeat := NULL;
109     g_rules(cs_LE).stop   := 2;
110     --
111     g_iter_rules(cs_LE + 1).ijss_payment    := 'Y';
112     g_iter_rules(cs_LE + 1).deduct_for_sick := 'Y';
113     g_iter_rules(cs_LE + 1).gi_payment      := 'Y';
114     g_iter_rules(cs_LE + 1).sick_adj        := 'N';
115     g_iter_rules(cs_LE + 1).gi_adj          := 'N';
116     g_iter_rules(cs_LE + 1).gross_ijss_adj  := 'N';
117 
118     --
119     --
120     -- Collectively agreed gross with adjustment processing rules.
121     --
122     g_rules(cs_CA_G_ADJ).repeat := 2;
123     g_rules(cs_CA_G_ADJ).stop   := NULL;
124     --
125     g_iter_rules(cs_CA_G_ADJ + 1).ijss_payment    := 'N';
126     g_iter_rules(cs_CA_G_ADJ + 1).deduct_for_sick := 'Y';
127     g_iter_rules(cs_CA_G_ADJ + 1).gi_payment      := 'Y';
128     g_iter_rules(cs_CA_G_ADJ + 1).sick_adj        := 'N';
129     g_iter_rules(cs_CA_G_ADJ + 1).gi_adj          := 'N';
130     g_iter_rules(cs_CA_G_ADJ + 1).gross_ijss_adj  := 'N';
131 
132     --
133     g_iter_rules(cs_CA_G_ADJ + 2).ijss_payment    := 'Y';
134     g_iter_rules(cs_CA_G_ADJ + 2).deduct_for_sick := 'Y';
135     g_iter_rules(cs_CA_G_ADJ + 2).gi_payment      := 'Y';
136     g_iter_rules(cs_CA_G_ADJ + 2).sick_adj        := 'Y';
137     g_iter_rules(cs_CA_G_ADJ + 2).gi_adj          := 'N';
138     g_iter_rules(cs_CA_G_ADJ + 2).gross_ijss_adj  := 'N';
139 
140     --
141     --
142     -- Collectively agreed gross without adjustment processing rules.
143     --
144     g_rules(cs_CA_G_NOADJ).repeat := NULL;
145     g_rules(cs_CA_G_NOADJ).stop   := 2;
146     --
147     g_iter_rules(cs_CA_G_NOADJ + 1).ijss_payment    := 'Y';
148     g_iter_rules(cs_CA_G_NOADJ + 1).deduct_for_sick := 'Y';
149     g_iter_rules(cs_CA_G_NOADJ + 1).gi_payment      := 'Y';
150     g_iter_rules(cs_CA_G_NOADJ + 1).sick_adj        := 'N';
151     g_iter_rules(cs_CA_G_NOADJ + 1).gi_adj          := 'N';
152     g_iter_rules(cs_CA_G_NOADJ + 1).gross_ijss_adj  := 'N';
153 
154     --
155     --
156     -- Collectively agreed net processing rules.
157     --
158     g_rules(cs_CA_N).repeat := 1;
159     g_rules(cs_CA_N).stop   := NULL;
160     --
161     g_iter_rules(cs_CA_N + 1).ijss_payment    := 'Y';
162     g_iter_rules(cs_CA_N + 1).deduct_for_sick := 'Y';
163     g_iter_rules(cs_CA_N + 1).gi_payment      := 'N';
164     g_iter_rules(cs_CA_N + 1).sick_adj        := 'Y';
165     g_iter_rules(cs_CA_N + 1).gi_adj          := 'N';
166     g_iter_rules(cs_CA_N + 1).gross_ijss_adj  := 'N';
167 
168     --
169     --
170     -- No guarantee processing rules.
171     --
172     g_rules(cs_NO_G).repeat := NULL;
173     g_rules(cs_NO_G).stop   := 2;
174     --
175     g_iter_rules(cs_NO_G + 1).ijss_payment    := 'Y';
176     g_iter_rules(cs_NO_G + 1).deduct_for_sick := 'Y';
177     g_iter_rules(cs_NO_G + 1).gi_payment      := 'N';
178     g_iter_rules(cs_NO_G + 1).sick_adj        := 'N';
179     g_iter_rules(cs_NO_G + 1).gi_adj          := 'N';
180     g_iter_rules(cs_NO_G + 1).gross_ijss_adj  := 'N';
181 
182 
183     --
184     -- Final Run Processing Rules
185     --
186     g_rules(cs_FINAL).repeat := NULL;
187     g_rules(cs_FINAL).stop   := 2;
188     --
189 
190     g_iter_rules(cs_FINAL + 1).ijss_payment    := 'Y';
191     g_iter_rules(cs_FINAL + 1).deduct_for_sick := 'Y';
192     g_iter_rules(cs_FINAL + 1).gi_payment      := 'Y';
193     g_iter_rules(cs_FINAL + 1).sick_adj        := 'Y';
194     g_iter_rules(cs_FINAL + 1).gi_adj          := 'Y';
195     g_iter_rules(cs_FINAL + 1).gross_ijss_adj  := 'Y';
196     --
197 hr_utility.set_location('initialise_processing_rules ',100);
198 
199   END initialise_processing_rules;
200   --
201   --
202   -- Defines the mapping between the interanl reference to each type of guarantee (numeric)
203   -- to a corresponding LOOKUP_CODE within the LOOKUP_TYPE of FR_GI_TYPES.
204   --
205   PROCEDURE initialise_guarantee_lookups IS
206   BEGIN
207   hr_utility.set_location('initialise_guarantee_lookup ',10);
208     g_guarantee_type_lookups(cs_GN)         := 'GN';
209     g_guarantee_type_lookups(cs_LE)         := 'LE';
210     g_guarantee_type_lookups(cs_CA_G_ADJ)   := 'CA_G_ADJ';
211     g_guarantee_type_lookups(cs_CA_G_NOADJ) := 'CA_G_NOADJ';
212     g_guarantee_type_lookups(cs_CA_N)       := 'CA_N';
213     g_guarantee_type_lookups(cs_NO_G)       := 'NO_G';
214 
215    hr_utility.set_location('initialise_guarantee_lookup ',100);
216   END initialise_guarantee_lookups;
217   --
218   --
219   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220   -- Placeholder for the external procedure.It is used to initialise the various data
221 
222   -- Structures required to process an absence. The following values are populated
223   -- prior to calling this -
224   --
225   -- p_mode   - Initialise Value or  Compare and indicate the best one
226   --
227   -- g_asg:
228   --
229   -- assignment_id - The assignment being processed.
230   -- base_net      - The net pay the employee would receive this period (independent of
231   --                 any sickness absences).
232   --
233   -- g_absence:
234   --
235   -- element_entry_id - The sickness element entry being processed
236   -- date_earned      - The processing date.
237   -- ID               - The ID of the absence linked to the element entry.
238   --
239   -- The following values are populated by the call -
240   --
241   -- g_absence:
242   --
243   -- sick_deduction   - Deduction for sickness (gross)
244   -- ijss_estimated   - Y/N flag identifying if the above payment details were estimated
245   --                    or based on a notification from CPAM.
246   -- sick_ins_gross   - Third party insurance payment information.
247   -- sick_ins_net     - Third party insurance payment information.
248   -- sick_ins_payment - Third party insurance payment information.
249   --
250   -- NB. The actual values that are set will vary based on the particular absence.
251   --
252   -- g_coverages:
253   --
254   -- g_type       - Type of guarantee.
255   -- cagr_id      - Collective agreement from which the guarantee was granted.
256   -- gi_payment   - Guaranteed income payment.
257   -- net          - Net to be paid to the employee.
258   -- ijss_gross       - IJSS payment information.
259   -- ijss_net         - IJSS payment information.
260   -- ijss_payment     - IJSS payment information.
261   --                guaranteed income.
262   -- band1        - Number of days drawn from band 1 compensation that were involved in
263   --                the calculation of the guaranteed income.
264   -- band2        - As above.
265   -- band3        - As above.
266   -- band4        - As above.
267   -- best_method  'Y' or 'N' Flag to identify Final run and Pointing Best Method
268   -- NB. This is actually a list of all the guarantees that cover the absence. The actual
269   --     values will vary based on the type of guarantee.
270   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
271   --
272 
273   PROCEDURE external_procedure
274   (p_mode      IN OUT NOCOPY VARCHAR2
275   ,p_asg       IN OUT NOCOPY t_asg
276   ,p_absence   IN OUT NOCOPY t_absence_arch
277   ,p_coverages IN OUT NOCOPY t_coverages) IS
278   BEGIN
279 
280   hr_utility.set_location('External Procedure ',10);
281   pay_fr_sickness_calc.CALC_SICKNESS(p_mode,p_asg,p_absence,p_coverages);
282 
283   hr_utility.set_location('External Procedure ',100);
284   END external_procedure;
285   --
286   --
287   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
288   -- it initiates the processing of each coverage type and also of best one with
289   -- required adjustment values.
290   --
291   -- It is used at initialisation time and also when the  best guarantee is active.
292   --
293   -- The processing mode (g_ctl.p_mode) is used to identify the current mode NB. once
294   -- set to cs_FINAL_PROCESS,only best coverage will be processed for final net.
295   -- Detected by a call to the function final_processing() in the main controlling
296   --  logic iterate().
297   --
298   -- It should be noted that the actual processing control for a guarantee is
299   -- defined in iterate(). This logic simply decides pointer for best guarantee.
300   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
301   --
302   PROCEDURE process_control_info IS
303     --
304     --
305     -- Local variables.
306     --
307     l_calculate      BOOLEAN;
308     l_idx            NUMBER := 0;
309     l_best_net_g_idx NUMBER;
310     l_best           BOOLEAN;
311 
312   BEGIN
313     --
314     -- Search through all the guarantees to see if any do not have a net amount. The
315     -- three possible options are
316     --
317     -- 1. ALL guarantees have a net amount so pick the best one for processing.
318     -- 2. The guarantee with no net amount is currently being processed so do nothing.
319     -- 3. Process the guarantee with no net amount.
320     --
321     hr_utility.set_location('Process Control info ',10);
322       l_idx := g_coverages.FIRST;
323 
324       LOOP
325 
326         --
327         --  Find the first type which has not been processed.
328         --
329         hr_utility.set_location('Process Control info Inside Loop',l_idx);
330         l_calculate := (NVL(g_coverages(l_idx).processed_flag,'N') = 'Y');
331 
332         --
333         --
334         -- Finish looping if ALL coverages have been checked OR there is a coverage
335         -- that needs to be processed.
336         --
337 
338         EXIT WHEN l_idx = g_coverages.LAST OR NOT l_calculate;
339         --
340         --
341         -- Move onto next guarantee.
342         --
343         l_idx := g_coverages.NEXT(l_idx);
344 
345       END LOOP;
346       --
347       --
348       -- All guarantees has not been processed then process current one.
349       --
350       IF NOT l_calculate THEN
351 
352          --
353          --
354          -- The processing to find the net for this guarantee is already in progress.
355          --
356 	hr_utility.set_location('Process Control info inside not calculate',20);
357 
358          IF NVL(g_ctl.g_idx,-1) = l_idx THEN
359 		NULL;
360          --
361          --
362          -- Find the net for this guarantee.
363          --
364          ELSE
365 
366             g_ctl.p_mode := cs_PROCESS;
367             g_ctl.g_idx  := l_idx;
368             g_ctl.iter   := 1;
372       ELSE
369             hr_utility.set_location('Process Control info after cs_process',30);
370          END IF;
371 
373        hr_utility.set_location('Process Control info',40);
374          l_mode := 'C';
375          external_procedure(l_mode, g_asg, g_absence, g_coverages);
376 
377          l_idx := g_coverages.FIRST;
378 
379        LOOP
380 
381         --
382         --  Find the best method.
383         --
384         l_best := (NVL(g_coverages(l_idx).best_method,'N') = 'Y');
385         hr_utility.set_location('Process Control info',50);
386 
387         --
388         --
389         -- Finish looping if All have been checked OR there is a best coverage
390         --
391 
392         EXIT WHEN l_idx = g_coverages.LAST OR l_best;
393         --
394         --
395         -- Move onto next guarantee.
396         --
397         l_idx := g_coverages.NEXT(l_idx);
398 
399       hr_utility.set_location('Process Control info',60);
400       END LOOP;
401 
402       -- Process the best one and set mode to Final
403          g_ctl.p_mode := cs_FINAL_PROCESS;
404          g_ctl.g_idx  := l_idx;
405          g_ctl.iter   := 1;
406       hr_utility.set_location('Process Control info',70);
407 
408     END IF;
409 
410     hr_utility.set_location('Process Control info',100);
411   END process_control_info;
412 
413   --
414   --
415   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
416   -- Initialise the data structures for the processing of a new absence (see description
417   -- for external_procedure() for details).
418   --
419   -- Having initialised the data structures setup the processing control information
420   -- based on this.
421   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
422   --
423   PROCEDURE initialise_absence
424   (p_element_entry_id NUMBER
425   ,p_date_earned      DATE) IS
426     --
427     --
428     -- Returns the ID for the absence linked to the element entry.
429     --
430     CURSOR csr_absence_id(p_element_entry_id NUMBER, p_date_earned DATE) IS
431       SELECT creator_id ID
432       FROM   pay_element_entries_f
433       WHERE  element_entry_id = p_element_entry_id
434         AND  creator_type     = 'A'
435         AND  creator_id       IS NOT NULL;
436   BEGIN
437     --
438     --
439     -- Setup basic absence information.
440     --
441     g_absence.element_entry_id := p_element_entry_id;
442     g_absence.date_earned      := p_date_earned;
443     --
444     --
445     -- Get the absence ID linked to the element entry being processed.
446     --
447     hr_utility.set_location('Initialise Absence',10);
448     -- Added lines for CPAM Processing
449     IF pay_fr_sickness_calc.g_absence_calc.initiator = 'CPAM' THEN
450        g_absence.ID := pay_fr_sickness_calc.g_absence_calc.ID;
451     ELSE
452        OPEN  csr_absence_id(p_element_entry_id, p_date_earned);
453        FETCH csr_absence_id INTO g_absence.ID;
454        CLOSE csr_absence_id;
455     END IF;
456     --
457     hr_utility.set_location('Initialise Absence',20);
458     --
459     -- Initialise information required to process the absence.
460     --
461     l_mode := 'I';
462     hr_utility.set_location('Initialise Absence',30);
463     external_procedure(l_mode, g_asg, g_absence, g_coverages);
464     hr_utility.set_location('Initialise Absence',40);
465     --
466     --
467     -- Initialise the control information.
468     --
469     process_control_info();
470     hr_utility.set_location('Initialise Absence',100);
471   END initialise_absence;
472   --
473   --
474   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
475   -- Absence has been processed to completion so clear down the data structures in
476   -- preparation for a new absnece NB. the assignment information is not cleared down as
477   -- it may be relevant for the processing of the next absence.
478   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
479   --
480   PROCEDURE reset_data_structures IS
481   BEGIN
482     g_ctl       := blank_ctl;
483     g_absence   := blank_absence;
484     g_coverages := blank_coverages;
485     hr_utility.set_location('Reset Data Str',100);
486   END reset_data_structures;
487   --
488   --
489   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
490   -- Initialise the data structures for processing a new assignment NB. this also means a
491   -- new absence is being procxessed so initialise for that as well.
492   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
493   --
494   PROCEDURE initialise_assignment
495   (p_assignment_id         NUMBER
496   ,p_net_pay               NUMBER
497   ,p_element_entry_id      NUMBER
498   ,p_date_earned           DATE
499   ,p_assignment_action_id  NUMBER
500   ,p_business_group_id     NUMBER
501   ,p_payroll_action_id     NUMBER
502   ,p_payroll_id            NUMBER
503   ,p_element_type_id       NUMBER
504   ,p_deduct_formula        NUMBER
505   ,p_action_start_date     DATE
509 
506   ,p_action_end_date       DATE
507   ,p_ded_ref_salary        NUMBER
508   ,p_lg_ref_salary	   NUMBER) IS
510   BEGIN
511     --
512     --
513     -- Record assignment information.
514     --
515     g_asg.assignment_id 	:= p_assignment_id;
516     g_asg.base_net      	:= p_net_pay;
517     g_asg.payroll_id    	:= p_payroll_id;
518     g_asg.assignment_action_id  := p_assignment_action_id;
519     g_asg.business_group_id     := p_business_group_id;
520     g_asg.payroll_action_id     := p_payroll_action_id;
521     g_asg.element_type_id       := p_element_type_id;
522     g_asg.deduct_formula        := p_deduct_formula;
523     g_asg.action_start_date     := p_action_start_date;
524     g_asg.action_end_date       := p_action_end_date;
525     g_asg.ded_ref_salary	:= p_ded_ref_salary;
526     g_asg.lg_ref_salary		:= p_lg_ref_salary;
527     g_asg.sick_net              := p_net_pay;
528 
529     --
530     --
531     -- Retrieve information for processing the new absence.
532     --
533     hr_utility.set_location('Initialise Assignment',10);
534     initialise_absence(p_element_entry_id, p_date_earned);
535     hr_utility.set_location('Initialise Assignment',100);
536   END initialise_assignment;
537   --
538   --
539   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
540   -- co-ordination for the two levels of initialisation - assignment and absence. It also
541   -- identifies if an initialisation has taken place.
542   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
543   --
544   FUNCTION initialise
545   (p_assignment_id    	   NUMBER
546   ,p_element_entry_id      NUMBER
547   ,p_date_earned           DATE
548   ,p_assignment_action_id  NUMBER
549   ,p_business_group_id     NUMBER
550   ,p_payroll_action_id     NUMBER
551   ,p_payroll_id            NUMBER
552   ,p_element_type_id       NUMBER
553   ,p_net_pay               NUMBER
554   ,p_deduct_formula        NUMBER
555   ,p_action_start_date     DATE
556   ,p_action_end_date       DATE
557   ,p_ded_ref_salary        NUMBER
558   ,p_lg_ref_salary	   NUMBER
559 
560   ) RETURN BOOLEAN IS
561     --
562     --
563     -- Local variables.
564     --
565     l_initialised BOOLEAN := FALSE;
566   BEGIN
567     --
568     --
569     -- A new assignment is being processed so reset the assignment information and
570     -- initialise the information for the absence.
571     -- bug 99999999 added action_start_date check as g_asg not being initialized
572     -- in retropay covering multiple periods
573     --
574     hr_utility.set_location('Initialise',10);
575     IF NOT (NVL(g_asg.assignment_id, -1) = p_assignment_id
576             and (g_asg.action_start_date = p_action_start_date) ) THEN
577       initialise_assignment(p_assignment_id,
578                             p_net_pay,
579                             p_element_entry_id,
580                             p_date_earned,
581                             p_assignment_action_id,
582                             p_business_group_id,
583                             p_payroll_action_id,
584                             p_payroll_id,
585                             p_element_type_id,
586                             p_deduct_formula,
587                             p_action_start_date,
588                             p_action_end_date,
589                             p_ded_ref_salary,
590 			    p_lg_ref_salary  );
591       l_initialised := TRUE;
592       hr_utility.set_location('Initialise ',20);
593     --
594     --
595     -- A new absence is being processed so initialise the information for the absence.
596     --
597     ELSIF NOT ( NVL(g_absence.element_entry_id, -1) = p_element_entry_id) THEN
598       g_asg.sick_net := p_net_pay;
599       initialise_absence(p_element_entry_id, p_date_earned);
600       l_initialised := TRUE;
601       hr_utility.set_location('Initialise',30);
602 
603     ELSIF NOT (g_absence.date_earned = p_date_earned) THEN
604 
605     initialise_assignment(p_assignment_id,
606                             p_net_pay,
607                             p_element_entry_id,
608                             p_date_earned,
609                             p_assignment_action_id,
610                             p_business_group_id,
611                             p_payroll_action_id,
612                             p_payroll_id,
613                             p_element_type_id,
614                             p_deduct_formula,
615                             p_action_start_date,
616                             p_action_end_date,
617                             p_ded_ref_salary,
618 			    p_lg_ref_salary  );
619 
620       l_initialised := TRUE;
621       hr_utility.set_location('Initialise',40);
622 
623      END IF;
624 
625     --
626     --
627     -- Return indicator identifying if initialisation occured.
628     --
629     hr_utility.set_location('Initialise',100);
630     RETURN l_initialised;
631   END initialise;
632   --
633   --
634   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
635   -- Increments the iteration.
636   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
637   --
641     g_ctl.iter := g_ctl.iter + 1;
638   PROCEDURE increment_iteration IS
639   BEGIN
640       hr_utility.set_location('Increment Iteration',10);
642     hr_utility.set_location('Increment Iteration',100);
643   END increment_iteration;
644   --
645   --
646   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
647   -- Identfies if the processing mode is cs_FINAL_PROCESS i.e. now processing the best
648   -- guarantee to completion.
649   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
650   --
651   FUNCTION final_processing RETURN BOOLEAN IS
652   BEGIN
653   hr_utility.set_location('Final Processing',10);
654     RETURN (g_ctl.p_mode = cs_FINAL_PROCESS);
655   END final_processing;
656   --
657   --
658   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
659   -- Identifies the type for the current guarantee NB. this is enumerated as a numeric
660   -- constant which allows access to processing information for that guarantee type.
661   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
662   --
663   FUNCTION g_type RETURN NUMBER IS
664   BEGIN
665   hr_utility.set_location('g_type',10);
666 
667     IF final_processing THEN
668 
669     	RETURN cs_FINAL;
670     ELSE
671     hr_utility.set_location('g_type',11);
672     	RETURN g_coverages(g_ctl.g_idx).g_type;
673 
674     END IF;
675   END g_type;
676 
677   --
678   --
679   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
680   -- Idnetifies when the processing should stop for the current guarantee.
681   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
682   --
683   FUNCTION stop_processing
684   (p_net_pay NUMBER) RETURN BOOLEAN IS
685     --
686     --
687     -- Local variables.
688     --
689     l_target_net NUMBER;
690 
691   BEGIN
692     --
693     --
694     -- Simple case where the processing is stopped at a specified iteration.
695     --
696     hr_utility.set_location('Stop Processing',10);
697     hr_utility.set_location('Stop Processing Iterate No is'|| to_char(g_ctl.iter) , 15);
698     IF g_rules(g_type).stop IS NOT NULL THEN
699       RETURN (g_rules(g_type).stop = g_ctl.iter);
700     --
701     --
702     -- Check to see if the currently calculated net pay is close enough to the target net.
703     --
704     ELSE
705     hr_utility.set_location('Stop Processing',20);
706       l_target_net := nvl(g_coverages(g_ctl.g_idx).net,0);
707  hr_utility.set_location('Stop Processing'||l_target_net || p_net_pay,25);
708       RETURN (l_target_net + cs_MARGIN >= p_net_pay AND l_target_net - cs_MARGIN <= p_net_pay);
709     END IF;
710     hr_utility.set_location('Stop Processing',100);
711   END stop_processing;
712   --
713   --
714   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
715   -- Sets an adjustment as required for the processing of the current guarantee.
716   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
717   --
718   PROCEDURE set_adjustment
719   (p_net_pay NUMBER) IS
720     --
721     --
722     -- Local variables
723     --
724     l_dummy      NUMBER;
725     l_target_net NUMBER;
726     l_diff       NUMBER;
727     l_sick_adj   NUMBER;
728     l_init       NUMBER;
729   BEGIN
730   hr_utility.set_location('Set Adjustment',10);
731     --
732     --
733     -- Get the target net for the current guarantee.
734     --
735     l_target_net := nvl(g_coverages(g_ctl.g_idx).net,0);
736 
737 select decode(l_target_net,0,1,l_target_net) into l_init from dual;
738 
739  hr_utility.set_location('Set Adjustment target net: ' || l_target_net,15);
740  hr_utility.set_location('Set Adjustment init: ' || l_init,17);
741 
742  --
743     --
744     -- There has not been an adjustment so set an initial value.
745     --
746     IF g_coverages(g_ctl.g_idx).sick_adj IS NULL THEN
747  hr_utility.set_location('Set Adjustment target net: ' || l_target_net,18);
748 
749       l_dummy    := pay_iterate.initialise(g_absence.element_entry_id, l_init, -1 * l_init, l_init);
750       l_sick_adj := pay_iterate.get_interpolation_guess(g_absence.element_entry_id, 0);
751       hr_utility.set_location('Set Adjustment',20);
752     --
753     --
754     -- Refine the adjustment.
755     --
756     ELSE
757  hr_utility.set_location('Set Adjustment target net: ' || l_target_net,25);
758 
759       l_diff     := l_target_net - p_net_pay;
760 
761 hr_utility.set_location('Set Adjustment diff: ' || l_diff,25);
762 
763       l_sick_adj := pay_iterate.get_interpolation_guess(g_absence.element_entry_id, l_diff);
764       hr_utility.set_location('Set Adjustment',30);
765     END IF;
766     --
767     --
768     -- Set the sickness adjustment.
769     --
770     g_coverages(g_ctl.g_idx).sick_adj := l_sick_adj;
771     hr_utility.set_location('Set Adjustment',100);
772   END;
773   --
774   --
775   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
776   -- Sets the net pay for the current guarantee.
780   (p_net_pay NUMBER) IS
777   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
778   --
779   PROCEDURE set_net_pay
781   BEGIN
782   hr_utility.set_location('Set Net Pay',10);
783     g_coverages(g_ctl.g_idx).net := p_net_pay;
784   END set_net_pay;
785   --
786   --
787   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
788   -- Identifies if an adjustment is required for the processing of the current guarantee.
789   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
790   --
791   FUNCTION adjustment_needed RETURN BOOLEAN IS
792   BEGIN
793   hr_utility.set_location('Adjustment Needed',10);
794 
795     RETURN (g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).sick_adj = 'Y');
796 
797 
798   END adjustment_needed;
799   --
800   --
801   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
802   -- Controls the iteration of the iterative formula associated with the sickness
803   -- element.
804   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
805   --
806  FUNCTION iterate
807    (p_assignment_id         NUMBER
808    ,p_element_entry_id      NUMBER
809    ,p_date_earned           DATE
810    ,p_assignment_action_id  NUMBER
811    ,p_business_group_id     NUMBER
812    ,p_payroll_action_id     NUMBER
813    ,p_payroll_id            NUMBER
814    ,p_element_type_id       NUMBER
815    ,p_net_pay               NUMBER
816    ,p_deduct_formula        NUMBER
817    ,p_action_start_date     DATE
818    ,p_action_end_date       DATE
819    ,p_ded_ref_salary        NUMBER
820    ,p_lg_ref_salary	    NUMBER
821    ,p_stop_processing OUT NOCOPY   VARCHAR2)  RETURN NUMBER IS
822 
823   BEGIN
824 
825  -- hr_utility.trace_on(NULL,'REQID');
826   hr_utility.set_location('Iterate',10);
827 
828 hr_utility.set_location('base net' || g_asg.base_net,10);
829 hr_utility.set_location('sick net' || g_asg.sick_net,10);
830 hr_utility.set_location('present net'|| p_net_pay,10);
831 
832     --
833     --
834     -- Checking for a change in assignment or absnece and initialising the processing
835     -- as appropriate. If no initialisation then simply increment the iteration.
836     --
837     IF NOT initialise(p_assignment_id,
838                       p_element_entry_id,
839                       p_date_earned,
840                       p_assignment_action_id,
841                       p_business_group_id,
842                       p_payroll_action_id,
843                       p_payroll_id,
844                       p_element_type_id,
845                       p_net_pay,
846                       p_deduct_formula,
847                       p_action_start_date,
848                       p_action_end_date,
849                       p_ded_ref_salary,
850                       p_lg_ref_salary   ) THEN
851 
852           increment_iteration;
853 
854     hr_utility.set_location('Iterate',20);
855     --
856     --
857     -- Processing the guarantee that pays the best net.
858     --
859     IF final_processing THEN
860       --
861       --
862       -- Check to see if processing should stop.
863       --
864       hr_utility.set_location('Iterate',30);
865       IF stop_processing(p_net_pay) THEN
866         reset_data_structures;
867    hr_utility.set_location('Iterate',40);
868         p_stop_processing := 'Y';
869       END IF;
870     --
871     --
872     -- Finding the best net to pay the employee.
873     --
874     ELSE
875 
876 IF (g_coverages(g_ctl.g_idx).g_type = 30 and g_ctl.iter= 2) then
877 
878          IF ((nvl(g_coverages(g_ctl.g_idx).gi_payment1,0) + nvl(g_coverages(g_ctl.g_idx).gi_payment2,0)) = 0) then
879              set_net_pay(nvl(p_net_pay,0) + nvl(g_absence.ijss_net,0)+nvl(g_absence.ijss_payment,0));
880              hr_utility.set_location('net pay' || p_net_pay,18);
881              hr_utility.set_location(' totnet pay' || g_coverages(g_ctl.g_idx).net,20);
882          ELSE
883              set_net_pay(nvl(p_net_pay,0)+ nvl(g_coverages(g_ctl.g_idx).ijss_net_adjustment,0));
884              hr_utility.set_location('net pay' || p_net_pay,19);
885              hr_utility.set_location(' totnet pay' || g_coverages(g_ctl.g_idx).net,21);
886 
887          END IF;
888 
889       END IF;
890 
891       IF stop_processing(p_net_pay) then
892 
893          set_net_pay(p_net_pay);
894          g_coverages(g_ctl.g_idx).processed_flag := 'Y';
895   	 hr_utility.set_location('Iterate',70);
896 
897       ELSIF adjustment_needed THEN
898 
899         set_adjustment(p_net_pay);
900         hr_utility.set_location('Iterate',50);
901 
902       END IF;
903 
904       --
905       --
906       -- Check to see if there are any more guarantees that need to be processed to get their net amount.
907       --
908       process_control_info();
909 
910       hr_utility.set_location('Iterate',80);
911 
912     END IF;
913 
914   END IF;
915 
916     --
917     --
921  -- hr_utility.trace_off;
918     -- Simply return a value NB. declared as a function so it cab be used via a formula function.
919     --
920     hr_utility.set_location('Iterate',90);
922 
923     RETURN 0;
924   EXCEPTION
925     WHEN OTHERS THEN
926       hr_utility.set_location('iterate',-10);
927       hr_utility.trace(SQLCODE);
928       hr_utility.trace(SQLERRM);
929       -- hr_utility.trace_off;
930       RAISE;
931 
932 
933   END iterate;
934   --
935   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
936   -- Returns the values to be processed for the current iteration for the guarantee.
937   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
938   --
939   FUNCTION indirects
940   (
941   P_ABSENCE_ID			         OUT NOCOPY NUMBER,
942   P_ijss_net 				 OUT NOCOPY NUMBER,
943   P_ijss_payment 			 OUT NOCOPY NUMBER,
944   P_ijss_gross1 			 OUT NOCOPY NUMBER,
945   P_ijss_gross2 			 OUT NOCOPY NUMBER,
946   p_ijss_estmtd                          OUT NOCOPY VARCHAR2,
947   P_ijss_gross1_rate			 OUT NOCOPY NUMBER,
948   P_ijss_gross2_rate			 OUT NOCOPY NUMBER,
949   P_ijss_gross1_base			 OUT NOCOPY NUMBER,
950   P_ijss_gross2_base			 OUT NOCOPY NUMBER,
951   P_ijss_gross1_fromdate		 OUT NOCOPY DATE,
952   P_ijss_gross2_fromdate		 OUT NOCOPY DATE,
953   P_ijss_gross1_todate			 OUT NOCOPY DATE,
954   P_ijss_gross2_todate			 OUT NOCOPY DATE,
955   P_gi_payment1 			 OUT NOCOPY NUMBER,
956   P_gi_payment2 			 OUT NOCOPY NUMBER,
957   P_gi_payment1_rate			 OUT NOCOPY NUMBER,
958   P_gi_payment2_rate			 OUT NOCOPY NUMBER,
959   P_gi_payment1_base			 OUT NOCOPY NUMBER,
960   P_gi_payment2_base			 OUT NOCOPY NUMBER,
961   P_gi_payment1_fromdate		 OUT NOCOPY DATE,
962   P_gi_payment2_fromdate		 OUT NOCOPY DATE,
963   P_gi_payment1_todate			 OUT NOCOPY DATE,
964   P_gi_payment2_todate			 OUT NOCOPY DATE,
965   P_sick_adj				 OUT NOCOPY NUMBER,
966   P_sick_deduct   			 OUT NOCOPY NUMBER,
967   P_sick_deduct_rate			 OUT NOCOPY NUMBER,
968   P_sick_deduct_base			 OUT NOCOPY NUMBER,
969   P_gi_adjustment 			 OUT NOCOPY NUMBER,
970   P_gross_ijss_adj 			 OUT NOCOPY NUMBER,
971   P_audit			         OUT NOCOPY VARCHAR2,
972   P_deduct_start_date                    OUT NOCOPY DATE,
973   P_deduct_end_date                      OUT NOCOPY DATE,
974   -- added for paid days balances
975   p_red_partial_days                     OUT NOCOPY NUMBER,
976   p_red_unpaid_days                      OUT NOCOPY NUMBER,
977   -- Obtains the current Rate Input value 4504304
978   p_net                                  OUT NOCOPY NUMBER
979   --
980 )	    RETURN NUMBER IS
981 
982 
983 
984   BEGIN
985 
986 
987     --
988     --
989     -- Pass values for the IJSS payment when appropriate.
990     --
991     -- hr_utility.trace_on(NULL,'REQID');
992 
993     hr_utility.set_location('Indirects',10);
994 
995 
996     IF g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).ijss_payment = 'Y' THEN
997 
998       		p_ijss_net             	:= NVL(g_absence.ijss_net, 0);
999                 p_ijss_payment         	:= NVL(g_absence.ijss_payment, 0);
1000                  hr_utility.set_location('Indirects',11);
1001                 p_ijss_gross1          	:= NVL(g_coverages(g_ctl.g_idx).ijss_gross1, 0);
1002                 p_ijss_gross2          	:= NVL(g_coverages(g_ctl.g_idx).ijss_gross2, 0);
1003                  hr_utility.set_location('Indirects',12);
1004                 p_ijss_gross1_rate     	:= NVL(g_coverages(g_ctl.g_idx).ijss_gross_rate1, 0);
1005                 p_ijss_gross2_rate     	:= NVL(g_coverages(g_ctl.g_idx).ijss_gross_rate2, 0);
1006                  hr_utility.set_location('Indirects',13);
1007                 p_ijss_gross1_base     	:= NVL(g_coverages(g_ctl.g_idx).ijss_gross_days1, 0);
1008                 p_ijss_gross2_base     	:= NVL(g_coverages(g_ctl.g_idx).ijss_gross_days2, 0);
1009                  hr_utility.set_location('Indirects',14);
1010                 p_ijss_gross1_fromdate 	:= g_coverages(g_ctl.g_idx).ijss_from_date1;
1011                 p_ijss_gross2_fromdate 	:= g_coverages(g_ctl.g_idx).ijss_from_date2;
1012                 p_ijss_gross1_todate   	:= g_coverages(g_ctl.g_idx).ijss_to_date1;
1013                 p_ijss_gross2_todate   	:= g_coverages(g_ctl.g_idx).ijss_to_date2;
1014                  hr_utility.set_location('Indirects',15);
1015                 p_ijss_estmtd           := NVL(g_absence.ijss_estimated, 'N');
1016                  hr_utility.set_location('Indirects',16);
1017 
1018     ELSE
1019      		p_ijss_net	       	:= 0;
1020         	p_ijss_payment	       	:= 0;
1021      		p_ijss_gross1          	:= 0;
1022                	p_ijss_gross2          	:= 0;
1023                	p_ijss_gross1_rate     	:= 0;
1024                	p_ijss_gross2_rate     	:= 0;
1025                	p_ijss_gross1_base     	:= 0;
1026                	p_ijss_gross2_base     	:= 0;
1027                	p_ijss_estmtd        	:= 'U';
1028 
1029      END IF;
1030 
1031     hr_utility.set_location('Indirects',20);
1032 
1033     --
1034     --
1035     -- Pass value for the guaranteed income payment when appropriate.
1036     --
1037 
1038     IF g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).gi_payment = 'Y' THEN
1039 
1040                 p_gi_payment1          	:= NVL(g_coverages(g_ctl.g_idx).gi_payment1, 0);
1044                 p_gi_payment1_base     	:= NVL(g_coverages(g_ctl.g_idx).gi_days1, 0);
1041                 p_gi_payment2          	:= NVL(g_coverages(g_ctl.g_idx).gi_payment2, 0);
1042                 p_gi_payment1_rate     	:= NVL(g_coverages(g_ctl.g_idx).gi_rate1, 0);
1043                 p_gi_payment2_rate     	:= NVL(g_coverages(g_ctl.g_idx).gi_rate2, 0);
1045                 p_gi_payment2_base     	:= NVL(g_coverages(g_ctl.g_idx).gi_days2, 0);
1046                 p_gi_payment1_fromdate 	:= g_coverages(g_ctl.g_idx).gi_from_date1;
1047                 p_gi_payment2_fromdate 	:= g_coverages(g_ctl.g_idx).gi_from_date2;
1048                 p_gi_payment1_todate   	:= g_coverages(g_ctl.g_idx).gi_to_date1;
1049                 p_gi_payment2_todate   	:= g_coverages(g_ctl.g_idx).gi_to_date2;
1050                 -- Added for days paid balances
1051                 p_red_partial_days      := g_absence.partial_paid_days;
1052                 p_red_unpaid_days       := g_absence.unpaid_days;
1053                 --
1054 
1055     ELSE
1056 
1057     		p_gi_payment1        	:= 0;
1058 		p_gi_payment2        	:= 0;
1059 		p_gi_payment1_rate   	:= 0;
1060 		p_gi_payment2_rate   	:= 0;
1061 		p_gi_payment1_base   	:= 0;
1062 		p_gi_payment2_base   	:= 0;
1063 		-- Added for days paid balances
1064 		p_red_partial_days      := 0;
1065 		p_red_unpaid_days       := 0;
1066                 --
1067 
1068 
1069 
1070     END IF;
1071 
1072     hr_utility.set_location('Indirects',30);
1073 
1074     --
1075     --
1076     -- Pass value for the sickness adjustment when appropriate.
1077     --
1078 
1079     IF g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).sick_adj = 'Y' THEN
1080 
1081     		p_sick_adj := NVL(g_coverages(g_ctl.g_idx).sick_adj, 0);
1082 
1083     ELSE
1084 
1085     		p_sick_adj := 0;
1086 
1087     END IF;
1088 
1089     hr_utility.set_location('Indirects',40);
1090 
1091     --
1092     --
1093     -- Pass value for the sickness deduction when appropriate.
1094     --
1095 
1096     IF g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).deduct_for_sick = 'Y' THEN
1097 
1098     	          p_sick_deduct 	  := NVL(g_absence.sick_deduction, 0);
1099 	          p_sick_deduct_rate      := NVL(g_absence.sick_deduction_rate, 0);
1100 	          p_sick_deduct_base      := NVL(g_absence.sick_deduction_base, 0);
1101                   p_deduct_start_date     := g_absence.sick_deduct_start_date;
1102                   p_deduct_end_date       := g_absence.sick_deduct_end_date;
1103 
1104      ELSE
1105     	          p_sick_deduct	  := 0;
1106         	  p_sick_deduct_rate   := 0;
1107 	      	  p_sick_deduct_base   := 0;
1108 
1109     END IF;
1110 
1111     hr_utility.set_location('Indirects',60);
1112 
1113     --
1114     --
1115     -- Pass value for the guaranteed income adjustment when appropriate.
1116     --
1117 
1118     IF g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).gi_adj = 'Y' THEN
1119 
1120     		  p_gi_adjustment 		   := NVL(g_absence.gi_adjustment, 0);
1121 
1122     ELSE
1123 
1124     		  p_gi_adjustment 		   := 0;
1125 
1126     END IF;
1127 
1128     --
1129     --
1130     -- Pass value for the gross IJSS adjustment when appropriate.
1131     --
1132 
1133     IF g_iter_rules(g_type + LEAST(NVL(g_rules(g_type).repeat,g_ctl.iter), g_ctl.iter)).gross_ijss_adj = 'Y' THEN
1134 
1135         	   p_gross_ijss_adj := NVL(g_absence.gross_ijss_adjustment, 0);
1136 
1137     ELSE
1138 
1139         	   p_gross_ijss_adj := 0;
1140 
1141     END IF;
1142 
1143     hr_utility.set_location('Indirects',65);
1144 
1145     --
1146     --
1147     -- Trigger the auditing when processing the final result NB. it is not needed when
1148     -- finding the best to pay to the employee.
1149     --
1150     IF final_processing THEN
1151       p_audit           := 'Y';
1152       g_ctl.audit_g_idx := g_coverages.FIRST;
1153       -- Obtain current record rate value
1154       p_net             := NVL(g_coverages(g_ctl.audit_g_idx).net,0);
1155     ELSE
1156       p_audit := 'N';
1157       -- Assign 0 to p_net
1158       p_net   := 0;
1159     END IF;
1160     hr_utility.set_location('Indirects',70);
1161     --
1162     --
1163     -- Pass the ID for the absence.
1164     --
1165     p_absence_id := g_absence.ID;
1166     --
1167     --
1168     -- Simply return a value NB. declared as a function so it cab be used via a formula function.
1169     --
1170 
1171     hr_utility.set_location('Indirects',100);
1172 
1173     -- hr_utility.trace_off;
1174 
1175 
1176     RETURN 0;
1177      EXCEPTION
1178         WHEN OTHERS THEN
1179           hr_utility.set_location('iterate ',-10);
1180           hr_utility.trace(SQLCODE);
1181           hr_utility.trace(SQLERRM);
1182     --      hr_utility.trace_off;
1183       RAISE;
1184 
1185   END indirects;
1186   --
1187   --
1188   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1189   -- Returns the values to be processed for the current iteration for the guarantee.
1190   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1191   --
1192   FUNCTION audit
1193   (p_parent_abs_id           OUT NOCOPY NUMBER
1194   ,p_guarantee_type          OUT NOCOPY VARCHAR2
1195   ,p_cagr_id                 OUT NOCOPY NUMBER
1196   ,p_net                     OUT NOCOPY NUMBER
1197   ,p_gi_payment              OUT NOCOPY NUMBER
1198   ,p_band1                   OUT NOCOPY NUMBER
1199   ,p_band2                   OUT NOCOPY NUMBER
1200   ,p_band3                   OUT NOCOPY NUMBER
1201   ,p_band4                   OUT NOCOPY NUMBER
1202   ,p_best_method             OUT NOCOPY VARCHAR2
1203   ,p_sick_adjustment         OUT NOCOPY NUMBER
1204   ,p_gi_adjustment           OUT NOCOPY NUMBER
1205   ,p_gross_ijss_adj          OUT NOCOPY NUMBER
1206   ,p_ijss_gross              OUT NOCOPY NUMBER
1207   ,p_audit                   OUT NOCOPY VARCHAR2
1208   ,p_payment_start_date      OUT NOCOPY DATE
1209   ,P_payment_end_date        OUT NOCOPY DATE
1210   ) RETURN NUMBER IS
1211 
1212   BEGIN
1213     --
1214     --
1215     -- Return the audit values.
1216     --
1217     -- hr_utility.trace_on(NULL,'REQID');
1218     p_parent_abs_id           := NVL(g_absence.parent_absence_id,0);
1219     p_guarantee_type          := NVL(g_guarantee_type_lookups(g_coverages(g_ctl.audit_g_idx).g_type),'U');
1220     p_cagr_id                 := NVL(g_coverages(g_ctl.audit_g_idx).cagr_id,0);
1221     p_gi_payment              := NVL(g_coverages(g_ctl.audit_g_idx).gi_payment1,0) + NVL(g_coverages(g_ctl.audit_g_idx).gi_payment2,0);
1222     p_band1                   := NVL(g_coverages(g_ctl.audit_g_idx).band1,0);
1223     p_band2                   := NVL(g_coverages(g_ctl.audit_g_idx).band2,0);
1224     p_band3                   := NVL(g_coverages(g_ctl.audit_g_idx).band3,0);
1225     p_band4                   := NVL(g_coverages(g_ctl.audit_g_idx).band4,0);
1226     p_best_method	      := NVL(g_coverages(g_ctl.audit_g_idx).best_method,'N');
1227     p_payment_start_date      := g_coverages(g_ctl.audit_g_idx).gi_from_date1;
1228     p_payment_end_date        := NVL(g_coverages(g_ctl.audit_g_idx).gi_to_date2, g_coverages(g_ctl.audit_g_idx).gi_to_date1);
1229     p_sick_adjustment         := NVL(g_coverages(g_ctl.audit_g_idx).sick_adj,0);
1230     p_gi_adjustment           := NVL(g_absence.gi_adjustment,0);
1231     p_gross_ijss_adj          := NVL(g_absence.gross_ijss_adjustment,0);
1232     p_ijss_gross              := NVL(g_coverages(g_ctl.audit_g_idx).ijss_gross2,0) + NVL(g_coverages(g_ctl.audit_g_idx).ijss_gross1,0);
1233 
1234     --
1235     if p_best_method <> 'Y' then p_best_method := 'N' ;
1236        end if;
1237     --
1238     -- All the coverages have been audited so stop.
1239     --
1240     hr_utility.set_location('Audit',10);
1241     IF g_ctl.audit_g_idx = g_coverages.LAST THEN
1242      /* Assign 0 for Rate input */
1243       p_net   := 0;
1244       p_audit := 'N';
1245     --
1246     --
1247     -- Move to the next coverage.
1248     --
1249     ELSE
1250       g_ctl.audit_g_idx := g_coverages.NEXT(g_ctl.audit_g_idx);
1251       /* Obtain the new Rate value */
1252       p_net             := NVL(g_coverages(g_ctl.audit_g_idx).net,0);
1253       p_audit := 'Y';
1254     END IF;
1255     --
1256     --
1257     -- Simply return a value NB. declared as a function so it cab be used via a formula function.
1258     --
1259     RETURN 0;
1260 
1261     hr_utility.set_location('Audit',100);
1262     -- hr_utility.trace_off;
1263   END audit;
1264 
1265 FUNCTION get_guarantee_id(
1266 P_type      IN  VARCHAR2 )  RETURN NUMBER is
1267 
1268     --
1269     -- Local variables.
1270     --
1271     l_idx            NUMBER := 0;
1272     l_best           BOOLEAN;
1273 
1274 BEGIN
1275 --
1276   l_idx :=   g_guarantee_type_lookups.FIRST;
1277 
1278  LOOP
1279         --
1280         --  Find the best method.
1281         --
1282         l_best :=  (NVL(g_guarantee_type_lookups(l_idx),'U') = p_type) ;
1283 
1284         hr_utility.set_location('Get Guarantee ID',50);
1285 
1286         --
1287         --
1288         -- Finish looping if All have been checked OR there is a best coverage
1289         --
1290 
1291         EXIT WHEN l_idx = g_guarantee_type_lookups.LAST OR l_best;
1292         --
1293         --
1294         -- Move onto next guarantee.
1295         --
1296         l_idx := g_guarantee_type_lookups.NEXT(l_idx);
1297 
1298       hr_utility.set_location('Get Gurantee ID',60);
1299 
1300 END LOOP;
1301 
1302 IF(l_best) then
1303 
1304   return l_idx;
1305 
1306 else
1307 
1308   return -1;
1309 
1310 END IF;
1311 
1312 END get_guarantee_id;
1313 
1314   --
1315 BEGIN
1316   --
1317   --
1318   -- Setup the processing rules which control how each type of income guarantee is processed.
1319   --
1320   hr_utility.set_location('PAY_FR_SICK_PAY_PROCESSING',50);
1321   initialise_processing_rules;
1322   --
1323   --
1324   -- Setup the mapping between internal constants identifying each guarantee type with an
1325   -- external reference (LOOKUP_CODE).
1326   --
1327   initialise_guarantee_lookups;
1328 
1329   hr_utility.set_location('PAY_FR_SICK_PAY_PROCESSING',100);
1330 END pay_fr_sick_pay_processing;