DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_FR_INSURANCE_PROCESS

Source


1 PACKAGE BODY pay_fr_insurance_process AS
2   /* $Header: pyfrtpin.pkb 115.3 2002/11/25 13:25:37 vsjain noship $ */
3   --
4   --
5   --
6   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8   --
9   cs_MARGIN           CONSTANT NUMBER := 1;
10   --
11   --
12   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13   -- Global variables
14   --
15   -- g_ctl                    - Holds control information used to manage the processing.
16   -- g_ins                    - Holds information for insurance record.
17   --
18   -- NB. the blank versions are used when the corresponding global variable needs to
19   --     be cleared out.
20   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21   --
22   g_ctl                    t_ctl;
23   g_ins                    t_ins;
24 
25   --
26   blank_ctl                t_ctl;
27   blank_ins		   t_ins;
28 
29   l_mode                   VARCHAR2(1);
30 
31   g_trace Number := 0;
32 
33   --
34   --
35   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36   -- Initialise the data structures for the processing of a new insurance payment
37   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38   --
39 
40   PROCEDURE initialise_insurance
41   (p_assignment_id     NUMBER
42   ,p_net_pay           NUMBER
43   ,p_element_entry_id  NUMBER
44   ,p_date_earned       DATE
45   ,p_subject_insurance NUMBER
46   ,p_exempt_insurance  NUMBER
47   ,p_recipient         Varchar2) IS
48 
49 
50     BEGIN
51 
52     hr_utility.set_location('Initialise insurance',10);
53 
54     --
55     --
56     -- Setup basic absence information.
57     --
58     hr_utility.set_location('p_recipient ='||p_recipient,95);
59 
60     g_ins.assignment_id 	:= p_assignment_id;
61     g_ins.element_entry_id 	:= p_element_entry_id;
62     g_ins.date_earned      	:= p_date_earned;
63     g_ins.insurance_subject  	:= p_subject_insurance;
64     g_ins.insurance_exempt    	:= p_exempt_insurance;
65 
66     IF p_recipient = 'EMPLOYEE' then
67         g_ins.base_net		   := 0 - (g_ins.insurance_subject + g_ins.insurance_exempt);
68         g_ins.insurance_reduction  := 0 - (g_ins.insurance_subject + g_ins.insurance_exempt);
69     ELSE
70     	g_ins.base_net		:= 0;
71     END IF;
72 
73 
74 
75     hr_utility.set_location('Initialise Insurance',100);
76 
77   END initialise_insurance;
78 
79   --
80   --
81   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
82   -- Insurance Element has been processed to completion so clear down the data structures in
83   -- preparation for a new Insurance Element NB.
84   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
85   --
86   PROCEDURE reset_data_structures IS
87   BEGIN
88     g_ctl       := blank_ctl;
89     g_ins       := blank_ins;
90     hr_utility.set_location('Reset Data Str',100);
91   END reset_data_structures;
92 
93   --
94   --
95   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
96   -- co-ordination for the three levels of initialisation - assignment and insurance payment
97   -- or date earned. It also identifies if an initialisation has taken place.
98   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99   --
100 
101   FUNCTION initialise
102   (p_assignment_id    NUMBER
103   ,p_element_entry_id NUMBER
104   ,p_date_earned      DATE
105   ,p_net_pay          NUMBER
106   ,p_subject_insurance  NUMBER
107   ,p_exempt_insurance    NUMBER
108   ,p_recipient        VARCHAR2	) RETURN BOOLEAN IS
109 
110     --
111     --
112     -- Local variables.
113     --
114 
115     l_initialised BOOLEAN := FALSE;
116 
117   BEGIN
118 
119   hr_utility.set_location('p_recipient ='||p_recipient,95);
120     --
121     --
122     -- A new assignment is being processed so reset information and
123     -- initialise the information for insurance record.
124     --
125     hr_utility.set_location('Initialise',10);
126     IF NOT (NVL(g_ins.assignment_id, -1) = p_assignment_id) THEN
127 
128       initialise_insurance(p_assignment_id,
129                            p_net_pay,
130                            p_element_entry_id,
131                            p_date_earned,
132                            p_subject_insurance,
133                            p_exempt_insurance,
134                            p_recipient);
135 
136 
137       l_initialised := TRUE;
138       hr_utility.set_location('Initialise',20);
139     --
140     --
141     -- A new insurance element is being processed so initialise information for insurance.
142     --
143 
144     ELSIF g_ins.element_entry_id IS NULL THEN
145 
146       initialise_insurance(p_assignment_id,
147                            p_net_pay,
148                            p_element_entry_id,
149                            p_date_earned,
150                            p_subject_insurance,
151                            p_exempt_insurance,
152                            p_recipient);
153 
154       l_initialised := TRUE;
155       hr_utility.set_location('Initialise',30);
156 
157     ELSIF NOT (g_ins.date_earned = p_date_earned) THEN
158       initialise_insurance(p_assignment_id,
159                            p_net_pay,
160                            p_element_entry_id,
161                            p_date_earned,
162                            p_subject_insurance,
163                            p_exempt_insurance,
164                            p_recipient);
165 
166       l_initialised := TRUE;
167       hr_utility.set_location('Initialise',40);
168 
169     END IF;
170 
171     --
172     --
173     -- Return indicator identifying if initialisation occured.
174     --
175 
176     hr_utility.set_location('Initialise',100);
177     RETURN l_initialised;
178 
179   END initialise;
180 
181   --
182   --
183   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
184   -- Increments the iteration.
185   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
186   --
187 
188   PROCEDURE increment_iteration IS
189   BEGIN
190     hr_utility.set_location('Increment Iteration',10);
191     g_ctl.iter := g_ctl.iter + 1;
192     hr_utility.set_location('Increment Iteration',100);
193   END increment_iteration;
194 
195   --
196   --
197   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
198   -- Idnetifies when the processing should stop for the current guarantee.
199   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200   --
201 
202   FUNCTION stop_processing
203   (p_net_pay NUMBER) RETURN BOOLEAN IS
204     --
205     --
206     -- Local variables.
207     --
208     l_target_net NUMBER;
209 
210   BEGIN
211 
212       hr_utility.set_location('Stop Processing',10);
213     --
214     --
215     --Check to see if the currently calculated net pay is close enough to the target net.
216     --
217       l_target_net := g_ins.base_net;
218       RETURN (l_target_net + cs_MARGIN >= p_net_pay AND l_target_net - cs_MARGIN <= p_net_pay);
219       hr_utility.set_location('Stop Processing',100);
220 
221   END stop_processing;
222   --
223   --
224   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
225   -- Sets an adjustment as required for the processing of the current guarantee.
226   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
227   --
228   PROCEDURE set_adjustment
229   (p_net_pay NUMBER) IS
230     --
231     --
232     -- Local variables
233     --
234     l_dummy      NUMBER;
235     l_target_net NUMBER;
236     l_diff       NUMBER;
237     l_ins_adj   NUMBER;
238     l_init     NUMBER := 0;
239   BEGIN
240   hr_utility.set_location('Set Adjustment',10);
241     --
242     --
243     -- Get the target net for the current guarantee.
244     --
245     l_target_net := g_ins.base_net;
246 
247     select decode(nvl(g_ins.insurance_subject,0),0,1,g_ins.insurance_subject) into l_init from dual;
248     --
249     --
250     -- There has not been an adjustment so set an initial value.
251     --
252     IF g_ins.insurance_adjustment IS NULL THEN
253       l_dummy    := pay_iterate.initialise(g_ins.element_entry_id, l_target_net, -1 * l_init, l_init);
254       l_ins_adj  := pay_iterate.get_interpolation_guess(g_ins.element_entry_id, 0);
255       hr_utility.set_location('Set Adjustment',20);
256     --
257     --
258     -- Refine the adjustment.
259     --
260     ELSE
261 
262       l_diff     := l_target_net - p_net_pay;
263       l_ins_adj  := pay_iterate.get_interpolation_guess(g_ins.element_entry_id, l_diff);
264       hr_utility.set_location('Target net ='||l_target_net,90);
265       hr_utility.set_location('Net pay ='||p_net_pay,90);
266       hr_utility.set_location('Difference ='||l_diff,90);
267       hr_utility.set_location('Adjustment ='||l_ins_adj,100);
268       hr_utility.set_location('Set Adjustment',30);
269 
270     END IF;
271     --
272     --
273     -- Set the insurance adjustment.
274     --
275     g_ins.insurance_adjustment := l_ins_adj;
276     hr_utility.set_location('Set Adjustment',100);
277   END;
278   --
279   --
280   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
281   -- Sets the net pay for the current guarantee.
282   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
283   --
284   PROCEDURE set_net_pay
285   (p_net_pay NUMBER) IS
286   BEGIN
287   hr_utility.set_location('Set Net Pay',10);
288     g_ins.base_net := p_net_pay;
289   END set_net_pay;
290 
291   --
292   --
293   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
294   -- Controls the iteration of the iterative formula associated with the sickness
295   -- element.
296   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
297   --
298 
299   FUNCTION iterate
300   (p_assignment_id       NUMBER
301   ,p_element_entry_id    NUMBER
302   ,p_date_earned         DATE
303   ,p_net_pay             NUMBER
304   ,p_subject_insurance   NUMBER
305   ,p_exempt_insurance	 NUMBER
306   ,p_recipient           VARCHAR2
307   ,p_stop_processing OUT NOCOPY VARCHAR2) RETURN NUMBER IS
308 
309   BEGIN
310 
311    -- hr_utility.trace_on(NULL,'INSURANCE');
312 
313 
314        --
315        --
316        -- Checking for a change in assignment or absnece and initialising the processing
317        -- as appropriate. If no initialisation then simply increment the iteration.
318 
319      hr_utility.set_location('Assignment Id = '||p_assignment_id,80);
320      hr_utility.set_location('Element_entry_id ='||p_element_entry_id,81);
321      hr_utility.set_location('p_net_pay     ='||p_net_pay,83);
322      hr_utility.set_location('p_subject_insurance ='||p_subject_insurance,84);
323      hr_utility.set_location('p_exempt_insurance ='||p_exempt_insurance,85);
324      hr_utility.set_location('p_exempt_insurance ='||p_recipient,95);
325 
326 
327 
328     hr_utility.set_location('Iterate',10);
329     --
330     --
331     -- Checking for a change in assignment or absnece and initialising the processing
332     -- as appropriate. If no initialisation then simply increment the iteration.
333     --
334     IF initialise(p_assignment_id,
335                       p_element_entry_id,
336                       p_date_earned,
337                       p_net_pay,
338                       p_subject_insurance,
339                       p_exempt_insurance,
340                       p_recipient)    THEN
344       hr_utility.set_location('Iterate',20);
341 
342       increment_iteration;
343 
345     END IF;
346 
347     IF stop_processing(p_net_pay) then
348 
349       -- set_net_pay(p_net_pay);
350 
351        reset_data_structures;
352        p_stop_processing := 'Y';
353 
354 
355         hr_utility.set_location('p_stop_processing ='||p_stop_processing,02);
356 
357        hr_utility.set_location('Iterate',70);
358 
359     ELSE
360         set_adjustment(p_net_pay);
361         hr_utility.set_location('Iterate',50);
362 
363     END IF;
364 
365         hr_utility.set_location('Iterate',80);
366 
367     --
368     --
369     -- Simply return a value NB. declared as a function so it cab be used via a formula function.
370     --
371 
372     hr_utility.set_location('Iterate',90);
373 
374    -- hr_utility.trace_off;
375 
376     RETURN 0;
377   EXCEPTION
378     WHEN OTHERS THEN
379       hr_utility.set_location('iterate ',-10);
380       hr_utility.trace(SQLCODE);
381       hr_utility.trace(SQLERRM);
382       -- hr_utility.trace_off;
383       RAISE;
384 
385   END iterate;
386 
387   --
388   --
389   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
390   -- Returns the values to be processed for the current iteration for the guarantee.
391   -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
392   --
393 
394   FUNCTION indirects
395   (p_ins_subject      OUT NOCOPY NUMBER
396   ,p_ins_exempt       OUT NOCOPY NUMBER
397   ,p_ins_adjustment   OUT NOCOPY NUMBER
398   ,p_ins_reduction    OUT NOCOPY NUMBER) RETURN NUMBER IS
399 
400   BEGIN
401 
402     --
403     --
404     -- Pass value for the sickness adjustment when appropriate.
405     --
406 
407       hr_utility.set_location('Indirects',10);
408 
409     --
410     --
411     -- Pass values for the third party insurance payment when appropriate.
412     --
413 
414       p_ins_subject      := NVL(g_ins.insurance_subject, 0);
415       p_ins_exempt       := NVL(g_ins.insurance_exempt, 0);
416       p_ins_adjustment   := NVL(g_ins.insurance_adjustment, 0);
417       p_ins_reduction    := NVL(g_ins.insurance_reduction , 0);
418 
419 
420       hr_utility.set_location('Indirects',50);
421 
422       hr_utility.set_location('p_ins_subject(o) ='||p_ins_subject,100);
423       hr_utility.set_location('p_ins_exempt(o) ='||p_ins_exempt,100);
424       hr_utility.set_location('p_ins_adjustment(o) ='||p_ins_adjustment,100);
425 
426 
427     --
428     --
429     -- Simply return a value NB. declared as a function so it can be used via a formula function.
430     --
431 
432     hr_utility.set_location('Indirects',100);
433     -- hr_utility.trace_off;
434     RETURN 0;
435   END indirects;
436     --
437 BEGIN
438 
439   hr_utility.set_location('PAY_FR_INSURANCE_PROCESS',100);
440 
441 END pay_fr_insurance_process;