DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_IE_P35

Source


1 PACKAGE BODY PAY_IE_P35 AS
2    /* $Header: pyiep35x.pkb 120.60.12020000.9 2013/02/12 05:31:48 rsahai ship $ */
3 
4 --
5 -- Constants
6 --
7    l_package                  VARCHAR2 (31) := 'pay_ie_p35.';
8 --
9 -- Global Variables
10 --
11   -- Bug c_context_name - PRSI Context Balance Design Change
12    l_assignment_action_id     pay_assignment_actions.assignment_action_id%TYPE;
13    l_context_id               ff_contexts.context_id%TYPE;
14    l_defined_balance_id       pay_defined_balances.defined_balance_id%TYPE;
15    p_person_id_global         per_people_f.person_id%TYPE; -- to store the person_id in a package level variable to be used in c_context_name cursor
16    l_class_count              NUMBER (4);
17    l_weeks_at_initial_class   NUMBER (4);
18    l_weeks_at_second_class    NUMBER (4);
19    l_weeks_at_third_class     NUMBER (4);
20    l_weeks_at_fourth_class    NUMBER (4);
21    l_weeks_at_fifth_class     NUMBER (4);
22    l_initial_class            pay_run_result_values.result_value%TYPE;
23    l_second_class             pay_run_result_values.result_value%TYPE;
24    l_third_class              pay_run_result_values.result_value%TYPE;
25    l_fourth_class             pay_run_result_values.result_value%TYPE;
26    l_fifth_class              pay_run_result_values.result_value%TYPE;
27    l_context_value_counter    NUMBER (2) := 0;
28    l_start_date               DATE;
29    l_end_date                 DATE;
30    l_bg_id                    NUMBER;
31    l_segment4                 hr_soft_coding_keyflex.segment4%TYPE;
32    l_assignment_set_id	      hr_assignment_sets.assignment_set_id%TYPE;
33    l_payroll_id		      pay_all_payrolls_f.payroll_id%TYPE;
34 
35 
36    -- declaring the pl/sql table for storing the first 5 contribution class values
37    TYPE type_context_value_tab IS TABLE OF pay_run_result_values.result_value%TYPE
38    INDEX BY BINARY_INTEGER;
39 
40    -- For 5 PRSI classes
41    TYPE prsi_class is record
42 			(prsi_class pay_run_result_values.result_value%TYPE,
43                    prsi_class_bal NUMBER(4));
44 
45    TYPE prsi_class_tab IS TABLE OF prsi_class INDEX BY BINARY_INTEGER;
46 
47    l_prsi_class_tab	prsi_class_tab;
48    l_prsi_class_bal	prsi_class_tab;
49    l_prsi_class_tab1	prsi_class_tab;  --8259095
50    l_prsi_class_temp	prsi_class_tab; -- For making other tables empty
51 
52   -- declaring a pl/sql table for storing the the max assignment action ids against assignments for a person.
53   -- Bug fix4004470
54    TYPE asg_action_ids_tab IS TABLE OF pay_assignment_actions.assignment_action_id%TYPE
55    INDEX BY BINARY_INTEGER;
56 
57    t_context_value            type_context_value_tab;
58    t_empty_table              type_context_value_tab; -- for emptying the t_context_value pl/sql table
59 
60   -- t_asg_action_id               asg_action_ids_tab;  --Bug fix 4004470
61   -- t_empty_asg_table             asg_action_ids_tab; -- for emptying the t_asg_action_id pl/sql table( Bug fix 4023794)
62   t_asg_action_id			pay_assignment_actions.assignment_action_id%TYPE;
63 
64 
65 -- Bug 3460687 Temporary tables to hold Class Names
66    t_context_value_balinit    type_context_value_tab;
67    t_context_value_tmp        type_context_value_tab;
68    p_start_date               DATE;
69    p_end_date                 DATE;
70 
71 --8259095
72 TYPE supp_wk_tab is table of number INDEX BY pay_run_result_values.result_value%TYPE;
73 l_supp_wk_tab supp_wk_tab;
74 l_supp_wk_tab_empty supp_wk_tab; --9080372
75 --8259095
76 
77 --6633719
78 /* Function to check the override ppsn */
79 FUNCTION OVERRIDE_PPSN(asg_id NUMBER)
80 RETURN VARCHAR2
81 IS
82 
83 CURSOR csr_ppsn_override(p_asg_id NUMBER)
84 IS
85 SELECT aei_information1 PPSN_OVERRIDE
86 FROM per_assignment_extra_info
87 WHERE assignment_id = p_asg_id
88 AND aei_information_category = 'IE_ASG_OVERRIDE';
89 
90 l_ppsn_override varchar2(100);
91 
92 BEGIN
93 
94   OPEN csr_ppsn_override(asg_id);
95   FETCH csr_ppsn_override INTO l_ppsn_override;
96   CLOSE csr_ppsn_override;
97   RETURN l_ppsn_override;
98 
99 END override_ppsn;
100 --6633719
101 
102    /*Added to check multiple assignments*/
103 FUNCTION check_multiple_assignments(p_assignment_id number
104 				   ,p_start_date date
105 				   ,p_end_date date
106 				   ,p_bg_id number)
107 RETURN NUMBER AS
108 l_person_id	per_people_f.person_id%TYPE;
109 l_actid	pay_assignment_actions.assignment_action_id%TYPE;
110 
111 cursor csr_check_multiple_asg IS
112 	select paaf.person_id
113 	from  per_assignments_f paaf, per_assignments_f paaf1
114 	where paaf.assignment_id= p_assignment_id
115 	and   paaf.business_group_id = p_bg_id
116 	and   paaf.business_group_id =paaf1.business_group_id
117 	and   paaf.person_id = paaf1.person_id
118 	and   paaf1.primary_flag <> 'Y'
119 	and   paaf1.effective_end_date >= p_start_date
120 	and   paaf1.effective_start_date <= p_end_date;
121 
122 cursor csr_get_max_assact is
123 SELECT MAX(paa.assignment_action_id)
124 	FROM per_assignments_f paf,
125 	      pay_assignment_actions paa,
126 	      pay_payroll_actions ppa,
127 	      per_time_periods ptp
128 	WHERE paf.person_id = l_person_id
129 	  AND paf.assignment_id = paa.assignment_id
130 	  AND paa.action_status IN ('C','S') --10225372
131 	  AND ppa.payroll_action_id = paa.payroll_action_id
132 	  AND ppa.action_type in ('R','Q','I','B','V')
133 	  --AND ppa.time_period_id = ptp.time_period_id
134 	  --AND ptp.end_date BETWEEN p_start_date AND p_end_date
135 	  AND ppa.payroll_id = ptp.payroll_id                                       -- Bug 5070091 Offset payroll change
136 	  AND ppa.date_earned between ptp.start_date and ptp.end_date
137 	  AND ppa.effective_date between p_start_date and p_end_date
138 	  AND paf.effective_start_date <= p_end_date
139 	  AND paf.effective_end_date >= p_start_date;
140 
141 
142 
143    BEGIN
144 
145 	open csr_check_multiple_asg;
146 	fetch csr_check_multiple_asg into l_person_id;
147 	CLOSE csr_check_multiple_asg;
148 
149 	if l_person_id is not null then
150 		open csr_get_max_assact ;
151 		fetch csr_get_max_assact into l_actid;
152 		close csr_get_max_assact ;
153 
154 		if l_actid is not null then
155 			return l_actid;
156 		else return -1;
157 		end if;
158 	else
159 		return -1;
160 	end if;
161    END check_multiple_assignments;
162 
163 --------------------------------------------------------------------------------
164 --  Added new procedure for P60 changes to PRSI section - 5657992
165 --  This function returns the IE PRSI Insurable weeks for this employment
166 --------------------------------------------------------------------------------
167 Function get_p60_prsi_weeks(p_prsi_class		varchar2,
168 				    l_segment4		number,
169 				    p_max_action_id	number,
170 				    p_assignment_action_id number) return number as
171 l_p60_weeks number;
172 BEGIN
173 
174 	 l_p60_weeks := pay_balance_pkg.get_value (
175 					get_defined_balance_id ('_PER_PAYE_REF_PRSI_YTD', 'IE PRSI Insurable Weeks'),
176 		         		p_max_action_id,
177 					l_segment4,
178 		                  NULL,
179 				      l_context_id,
180 		                  p_prsi_class,
181 		                  NULL,
182 				      NULL
183 		               )
184 				   -
185 				   pay_balance_pkg.get_value (
186 					get_defined_balance_id ('_PER_PAYE_REF_PRSI_YTD', 'IE PRSI Insurable Weeks'),
187 		         		p_assignment_action_id,
188 					l_segment4,
189 		                  NULL,
190 				      l_context_id,
191 		                  p_prsi_class,
192 		                  NULL,
193 				      NULL
194 		               );
195 return l_p60_weeks;
196 END get_p60_prsi_weeks;
197 
198 
199 --------------------------------------------------------------------------------
200 -- Added new procedure for P60 changes to PRSI section - 5657992
201 -- This procedure calculates, this employment figures for
202 -- 1. IE PRSI Employee Contribution.
203 -- 2. IE PRSI Total Contribution (Employee + Employer
204 -- 3. IE PRSI Insurable weeks.
205 -- 4. IE PRSI contribution classes(initial and second class) and
206 -- insurable weeks for second class.
207 --------------------------------------------------------------------------------
208 PROCEDURE get_p60_prsi_details(p_assignment_action_id number,
209 					 p_max_action_id		number,
210 					 p_person_id		number,
211 					 p_segment4			hr_soft_coding_keyflex.segment4%TYPE,
212 					 p_tot_insurable_weeks	number,
213 					 p_prsi_employee_cont   number,
214 					 p_prsi_tot_cont		number,
215 					 p_insurable_weeks	out nocopy varchar2,
216 					 p_this_emp_prsi_cont   out nocopy varchar2,
217 					 p_this_tot_prsi		out nocopy varchar2,
218 					 p_this_initial_class	out nocopy varchar2,
219 					 p_this_sec_class		out nocopy varchar2,
220 					 p_this_weeks_at_sec_class out nocopy varchar2,
221 					 p_Act_Context_id  number default NULL,  --6633719
222 					 p_Act_Context_value varchar2 default NULL, --6633719
223 					 p_dimension_name varchar2 default '_PER_PAYE_REF_YTD',  --6633719
224 					 p_ppsn_override VARCHAR2 default NULL --6633719
225                      ) is
226 
227 
228 l_child_assignemnt_action	pay_assignment_actions.assignment_action_id%TYPE;
229 l_p60_prsi				prsi_class_tab;
230 
231 -- cursor to get child action
232 cursor c1 is
233 select assignment_action_id from pay_assignment_actions
234 where source_action_id = p_max_action_id;
235 
236 -- This fetch all prsi classes from run-results where assignment action id
237 -- lies between child of p_max_action_id and p_assignment_action_id(last period max action id)
238 CURSOR get_prsi_classes is
239 SELECT   /*+ ordered */
240                   asg.business_group_id business_group_id,
241                   asg.person_id person_id, per.full_name full_name,
242                   per.original_date_of_hire original_hire_date,
243                   MIN (ptp.end_date) minimum_effective_date,
244 			asg.primary_flag,
245 			paa.assignment_action_id,
246                   trim(rrv1.result_value) result_value
247              FROM per_people_f per,
248                   per_assignments_f asg,
249                   pay_assignment_actions paa,
250                   pay_payroll_actions ppa,
251                   per_time_periods ptp,
252                   pay_run_results prr,
253                   pay_element_types_f pet,
254                   pay_input_values_f piv1,
255                   pay_run_result_values rrv1
256             WHERE per.person_id = p_person_id
257               AND per.current_employee_flag = 'Y'
258               AND per.effective_start_date =
259                         (SELECT MIN (per2.effective_start_date)
260                            FROM per_people_f per2
261              			      , per_periods_of_service pos2
262                             WHERE per2.person_id = per.person_id
263                             AND per2.effective_start_date <= p_end_date
264 			                AND pos2.person_id = per2.person_id
265 			                AND pos2.date_start between per2.effective_start_date and per2.effective_end_date
266              			    AND NVL (pos2.final_process_date, p_end_date) >= p_start_date
267              			    AND per2.current_employee_flag = 'Y'  )
268               AND asg.person_id = per.person_id
269               AND asg.effective_start_date =
270                         (SELECT MIN (asg2.effective_start_date)
271                            FROM per_assignments_f asg2,
272 			                    per_assignment_status_types ast
273                             WHERE asg2.assignment_id = asg.assignment_id
274                             AND asg2.effective_start_date <= p_end_date
275                             AND NVL (asg2.effective_end_date, p_end_date) >= p_start_date
276             			    AND asg2.assignment_type = 'E'
277                             AND asg2.assignment_status_type_id = ast.assignment_status_type_id )
278               AND asg.assignment_type = 'E'
279               AND paa.assignment_id = asg.assignment_id
280               AND paa.action_status = 'C'
281               and paa.assignment_action_id > p_assignment_action_id
282 		  -- used nvl because for action_type='B' l_child_assignemnt_action will be null
283               and paa.assignment_action_id <= nvl(l_child_assignemnt_action,p_max_action_id)
284     		  AND paa.tax_unit_id = to_number(p_segment4)
285               AND ppa.payroll_action_id = paa.payroll_action_id
286               AND ppa.action_type IN ('Q', 'R', 'B')
287               AND ppa.payroll_id = ptp.payroll_id
288               AND ppa.date_earned between ptp.start_date and ptp.end_date
289     		  and ppa.effective_date between p_start_date AND p_end_date
290               AND pet.element_name = 'IE PRSI Contribution Class'
291               AND pet.legislation_code = 'IE'
292               AND pet.element_type_id = piv1.element_type_id
293               AND piv1.NAME = 'Contribution_Class'
294               AND piv1.legislation_code = 'IE'
295               AND prr.assignment_action_id = paa.assignment_action_id
296               AND prr.element_type_id = pet.element_type_id
297               AND rrv1.input_value_id = piv1.input_value_id
298               AND rrv1.run_result_id = prr.run_result_id
299          GROUP BY asg.business_group_id,
300                   asg.person_id,
301                   per.full_name,
302                   per.original_date_of_hire,
303                   asg.primary_flag,
304 		      paa.assignment_action_id,
305                   trim(rrv1.result_value)
306          ORDER BY asg.primary_flag desc,minimum_effective_date,paa.assignment_action_id;
307 temp_flag    NUMBER (2);
308 l_counter    NUMBER (2) := 0;
309 l_p60_prsi_classes            type_context_value_tab;
310 l_p60_all_classes			prsi_class_tab;
311 l_p60_prsi_class_bal		prsi_class_tab;
312 l_cnt					number;
313 BEGIN
314 
315 -- get the total insurable weeks for the last period max action id
316 
317 hr_utility.set_location('Period action id..'||p_assignment_action_id,101);
318 hr_utility.set_location('Max action id..'|| p_max_action_id,101);
319 
320 OPEN c1;
321 FETCH c1 into l_child_assignemnt_action;
322 CLOSE c1;
323 
324 	p_insurable_weeks := to_char(p_tot_insurable_weeks - NVL (
325 		   pay_ie_p35.get_total_insurable_weeks (p_person_id
326 									,to_number(l_segment4)
327 									,p_assignment_action_id
328 									,p_Act_Context_id  --6633719
329 									,p_Act_Context_value --6633719
330 									,p_dimension_name  --6633719
331                                     ,p_ppsn_override), --6633719
332 		   0
333 		));
334 hr_utility.set_location('p_tot_insurable_weeks..'|| p_tot_insurable_weeks,103);
335 hr_utility.set_location('p_insurable_weeks..'|| p_insurable_weeks,104);
336 	-- get the employee and total PRSI contribution till the last period max action id
337 	p_this_emp_prsi_cont :=    to_char(p_prsi_employee_cont -
338 					   	ROUND (
339 						     NVL (
340 							  pay_balance_pkg.get_value (
341 							     pay_ie_p35.get_defined_balance_id (
342 								  p_dimension_name,   --'_PER_PAYE_REF_YTD',  --6633719
343 								  'IE PRSI Employee'
344 							     ),
345 							     p_assignment_action_id,
346 							    l_segment4, -- paye reference value
347 							    null,
348 							    p_Act_Context_id,  --null,  -6633719
349 							    p_Act_Context_value,  --null,  --6633719
350 							    null,
351 							    null,
352 							    null,
353 							    'TRUE'
354 							  ),
355 							  0
356 						     )
357 						   + NVL (
358 							  pay_balance_pkg.get_value (
359 							     pay_ie_p35.get_defined_balance_id (
360 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
361 								  'IE PRSI K Employee Lump Sum'
362 							     ),
363 							     p_assignment_action_id,
364 							     l_segment4, -- paye reference value
365 							    null,
366 							    p_Act_Context_id,  --null,  --6633719
367 							    p_Act_Context_value,  --null,  --6633719
368 							    null,
369 							    null,
370 							    null,
371 							    'TRUE'
372 							  ),
373 							  0
374 						     )
375 						   + NVL (
376 							  pay_balance_pkg.get_value (
377 							     pay_ie_p35.get_defined_balance_id (
378 								  '_PER_YTD',
379 								  'IE PRSI M Employee Lump Sum'
380 							     ),
381 							     p_assignment_action_id,
382 							     l_segment4, -- paye reference value
383 							    null,
384 							    null,
385 							    null,
386 							    null,
387 							    null,
388 							    null,
389 							    'TRUE'
390 							  ),
391 							  0
392 						     ),
393 						   2
394 						));
395 				   hr_utility.set_location ('p_prsi_employee_cont'|| p_this_emp_prsi_cont,105);
396 				   hr_utility.set_location ('p_this_emp_prsi_cont'|| p_this_emp_prsi_cont,106);
397 
398 				   p_this_tot_prsi := to_char(p_prsi_tot_cont -
399 						ROUND (
400 						     NVL (
401 							  pay_balance_pkg.get_value (
402 							     pay_ie_p35.get_defined_balance_id (
403 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
404 								  'IE PRSI Employee'
405 							     ),
406 							     p_assignment_action_id,
407 							     l_segment4, -- paye reference value
408 							    null,
409 							    p_Act_Context_id,  --null,  --6633719
410 							    p_Act_Context_value,  --null,  --6633719
411 							    null,
412 							    null,
413 							    null,
414 							    'TRUE'
415 							  ),
416 							  0
417 						     )
418 						   + NVL (
419 							  pay_balance_pkg.get_value (
420 							     pay_ie_p35.get_defined_balance_id (
421 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
422 								  'IE PRSI Employer'
423 							     ),
424 							     p_assignment_action_id,
425 							     l_segment4, -- paye reference value
426 							    null,
427 							    p_Act_Context_id,  --null,  --6633719
428 							    p_Act_Context_value,  --null,  --6633719
429 							    null,
430 							    null,
431 							    null,
432 							    'TRUE'
433 							  ),
434 							  0
435 						     )
436 						   + NVL (
437 							  pay_balance_pkg.get_value (
438 							     pay_ie_p35.get_defined_balance_id (
439 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
440 								  'IE PRSI K Employee Lump Sum'
441 							     ),
442 							     p_assignment_action_id,
443 							   l_segment4, -- paye reference value
444 							    null,
445 							    p_Act_Context_id,  --null,  --6633719
446 							    p_Act_Context_value,  --null,  --6633719
447 							    null,
448 							    null,
449 							    null,
450 							    'TRUE'
451 							  ),
452 							  0
453 						     )
454 						   + NVL (
455 							  pay_balance_pkg.get_value (
456 							     pay_ie_p35.get_defined_balance_id (
457 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
458 								  'IE PRSI M Employee Lump Sum'
459 							     ),
460 							     p_assignment_action_id,
461 							     l_segment4, -- paye reference value
462 							    null,
463 							    p_Act_Context_id,  --null,  --6633719
464 							    p_Act_Context_value,  --null,  --6633719
465 							    null,
466 							    null,
467 							    null,
468 							    'TRUE'
469 							  ),
470 							  0
471 						     )
472 						   + NVL (
473 							  pay_balance_pkg.get_value (
474 							     pay_ie_p35.get_defined_balance_id (
475 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
476 								  'IE PRSI K Employer Lump Sum'
477 							     ),
478 							     p_assignment_action_id,
479 							     l_segment4, -- paye reference value
480 							    null,
481 							    p_Act_Context_id,  --null,  --6633719
482 							    p_Act_Context_value,  --null,  --6633719
483 							    null,
484 							    null,
485 							    null,
486 							    'TRUE'
487 							  ),
488 							  0
489 						     )
490 						   + NVL (
491 							  pay_balance_pkg.get_value (
492 							     pay_ie_p35.get_defined_balance_id (
493 								  p_dimension_name,  --'_PER_PAYE_REF_YTD',  --6633719
494 								  'IE PRSI M Employer Lump Sum'
495 							     ),
496 							     p_assignment_action_id,
497 							     l_segment4, -- paye reference value
498 							    null,
499 							    p_Act_Context_id,  --null,  --6633719
500 							    p_Act_Context_value,  --null,  --6633719
501 							    null,
502 							    null,
503 							    null,
504 							    'TRUE'
505 							  ),
506 							  0
507 						     ),
508 						   2
509 						));
510 				hr_utility.set_location ('p_this_tot_prsi'|| p_this_tot_prsi,105);
511 				hr_utility.set_location ('p_prsi_tot_cont'|| p_prsi_tot_cont,106);
512 FOR i IN get_prsi_classes
513 LOOP
514 	IF l_counter = 0 THEN
515 		l_counter := l_counter + 1;
516 		l_p60_prsi_classes(l_counter) := i.result_value;
517 		hr_utility.set_location ('Initial Class Value is :'|| l_p60_prsi_classes(l_counter), 16);
518 	ELSE
519 		FOR k IN 1 .. l_counter
520 		loop
521 			IF l_p60_prsi_classes(k) = i.result_value THEN
522 				temp_flag :=1;
523 				exit;
524 			ELSE
525 				temp_flag :=0;
526 			END IF;
527 		END LOOP;
528 		IF temp_flag = 0 AND l_counter <=9 THEN
529 			l_counter := l_counter + 1;
530 			l_p60_prsi_classes(l_counter) := i.result_value;
531 			hr_utility.set_location ('Subsequent Class Value is :'|| l_p60_prsi_classes(l_counter), 17);
532 		END IF;
533 		temp_flag := null;
534 	END IF;
535 END LOOP;
536 
537 FOR i in 1..l_p60_prsi_classes.COUNT
538 LOOP
539 	l_p60_all_classes(i).prsi_class := substr(l_p60_prsi_classes(i),4,2);
540 	l_p60_all_classes(i).prsi_class_bal := get_p60_prsi_weeks(l_p60_prsi_classes(i),
541 							                      to_number(l_segment4),
542 										    p_max_action_id,
543 										    p_assignment_action_id);
544 END LOOP;
545 
546 --Collect all PRSI classes with non-zero PRSI weeks in a separate PL/SQL table
547 l_cnt :=0;
548 FOR i in 1..l_p60_all_classes.COUNT
549 LOOP
550 	IF l_p60_all_classes(i).prsi_class_bal<>0 then
551 		l_cnt := l_cnt + 1;
552 		l_p60_prsi_class_bal(l_cnt).prsi_class := l_p60_all_classes(i).prsi_class;
553 		l_p60_prsi_class_bal(l_cnt).prsi_class_bal := l_p60_all_classes(i).prsi_class_bal;
554 	END IF;
555 END LOOP;
556 
557 -- get the initial and second from the non zero
558 -- plsql table.Sine the req is to display only non zero clases
559 IF l_cnt >=1 then
560 	if l_p60_prsi_class_bal(1).prsi_class is not null then
561 		p_this_initial_class	     := l_p60_prsi_class_bal(1).prsi_class;
562 	end if;
563 END IF;
564 
565 
566 IF l_cnt >1 then
567 	if l_p60_prsi_class_bal(2).prsi_class is not null then
568 		p_this_sec_class	       := l_p60_prsi_class_bal(2).prsi_class;
569 		p_this_weeks_at_sec_class := l_p60_prsi_class_bal(2).prsi_class_bal;
570 	end if;
571 END IF;
572 
573 -- empty the pl/sql tables.
574 l_p60_prsi_class_bal := l_prsi_class_temp;
575 l_p60_prsi_class_bal := l_prsi_class_temp;
576 
577 END get_p60_prsi_details;
578 
579 --------------------------------------------------------------------------------+
580 --
581 --------------------------------------------------------------------------------+
582 
583    FUNCTION get_parameter (
584       p_payroll_action_id   IN   NUMBER,
585       p_token_name          IN   VARCHAR2
586    )
587       RETURN VARCHAR2
588    AS
589       CURSOR csr_parameter_info (p_pact_id NUMBER, p_token CHAR)
590       IS
591          SELECT SUBSTR (
592                    legislative_parameters,
593                      INSTR (legislative_parameters, p_token)
594                    + (  LENGTH (p_token)
595                       + 1
596                      ),
597                      INSTR (
598                         legislative_parameters,
599                         ' ',
600                         INSTR (legislative_parameters, p_token)
601                      )
602                    - (  INSTR (legislative_parameters, p_token)
603                       + LENGTH (p_token)
604                      )
605                 ),
606                 business_group_id bg_id
607            FROM pay_payroll_actions
608           WHERE payroll_action_id = p_pact_id;
609 
610       l_business_group_id   NUMBER;
611       l_token_value         VARCHAR2 (50);
612    BEGIN
613       hr_utility.set_location (   'p_token_name = '
614                                || p_token_name, 20);
615       OPEN csr_parameter_info (p_payroll_action_id, p_token_name);
616       FETCH csr_parameter_info INTO l_token_value, l_business_group_id;
617       CLOSE csr_parameter_info;
618 
619       IF p_token_name = 'BG_ID'
620       THEN
621          l_token_value := TO_CHAR (l_business_group_id);
622       ELSE
623          l_token_value := TRIM (l_token_value);
624       END IF;
625 
626       hr_utility.set_location (   'l_token_value = '
627                                || l_token_value, 20);
628       hr_utility.set_location (   'Leaving         '
629                                || 'get_parameters', 30);
630       RETURN l_token_value;
631    END get_parameter;
632 
633    FUNCTION get_defined_balance_id (
634       p_dimension_name   VARCHAR2,
635       p_balance_name     VARCHAR2
636    )
637       RETURN NUMBER
638    AS
639       CURSOR csr_defined_balance_id
640       IS
641          SELECT pdb.defined_balance_id
642            FROM pay_balance_dimensions pbd,
643                 pay_balance_types pbt,
644                 pay_defined_balances pdb
645           WHERE pbd.dimension_name = p_dimension_name
646             AND pbd.business_group_id IS NULL
647             AND pbd.legislation_code = 'IE'
648             AND pbt.balance_name = p_balance_name
649             AND pbt.business_group_id IS NULL
650             AND pbt.legislation_code = 'IE'
651             AND pdb.balance_type_id = pbt.balance_type_id
652             AND pdb.balance_dimension_id = pbd.balance_dimension_id
653             AND pdb.business_group_id IS NULL
654             AND pdb.legislation_code = 'IE';
655 
656       l_defined_balance_id   pay_defined_balances.defined_balance_id%TYPE;
657    BEGIN
658       OPEN csr_defined_balance_id;
659       FETCH csr_defined_balance_id INTO l_defined_balance_id;
660       CLOSE csr_defined_balance_id;
661       RETURN l_defined_balance_id;
662    END;
663 
664 
665 --------------------------------------------------------------------------------+
666  -- Range cursor returns the ids of the assignments to be archived
667  --------------------------------------------------------------------------------+
668    PROCEDURE range_code (
669       p_payroll_action_id   IN              NUMBER,
670       sqlstr              OUT NOCOPY      VARCHAR2
671    )
672    IS
673       l_proc_name                VARCHAR2 (100) :=    l_package|| 'range_code';
674       l_dummy                    NUMBER;
675       p30_error                  EXCEPTION;
676       l_payroll_action_message   VARCHAR2 (255);
677       l_start_date               DATE;
678       l_end_date                 DATE;
679       l_bg_id                    NUMBER;
680 	l_out_var               VARCHAR2 (30);
681       --
682 CURSOR csr_p30_process
683       IS
684          SELECT NVL (MIN (ppa.payroll_action_id), 0)
685            FROM pay_payroll_actions ppa
686           WHERE ppa.report_type = 'IEP30_PRGLOCK'
687             AND ppa.action_status = 'C'
688             AND TO_DATE (
689                    pay_ie_p35.get_parameter (
690                       ppa.payroll_action_id,
691                       'END_DATE'
692                    ),
693                    'YYYY/MM/DD'
694                 ) between l_start_date and l_end_date
695             AND ppa.business_group_id = l_bg_id;
696 vik_str varchar2(2000);
697    BEGIN
698 	--hr_utility.trace_on(null,'vikp35');
699 
700       hr_utility.set_location (l_proc_name, 1);
701 	l_out_var := pay_ie_p35.get_parameter (
702 					p_payroll_action_id=> p_payroll_action_id,
703 					p_token_name=> 'END_DATE'
704 					);
705       l_end_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
706       l_out_var := pay_ie_p35.get_parameter (
707 					p_payroll_action_id=> p_payroll_action_id,
708 			            p_token_name=> 'START_DATE'
709 					);
710       l_start_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
711       l_out_var := pay_ie_p35.get_parameter (
712 					p_payroll_action_id=> p_payroll_action_id,
713 			            p_token_name=> 'BG_ID'
714 					);
715       l_bg_id := TO_NUMBER (l_out_var);
716 
717      /* hr_utility.set_location ('Start Date '||to_char(l_start_date), 2);
718 	hr_utility.set_location ('End Date '|| to_char(l_end_date), 3);
719 	hr_utility.set_location ('Business Group id '|| to_char(l_bg_id), 4);*/
720 
721       -- Check to make sure there is a p30 process run
722       -- existing for business group, otherwise fail
723 hr_utility.set_location ('End Date 1',22);
724       OPEN csr_p30_process;
725       FETCH csr_p30_process INTO l_dummy;
726 hr_utility.set_location ('End Date 2',22);
727       IF l_dummy = 0
728       THEN
729          CLOSE csr_p30_process;
730          RAISE p30_error;
731       END IF;
732 
733       CLOSE csr_p30_process;
734       --
735   hr_utility.set_location ('End Date 3',22);
736       sqlstr := 'select distinct asg.person_id
737                    from per_periods_of_service pos,
738                         per_assignments_f      asg,
739                         pay_payroll_actions    ppa
740                   where ppa.payroll_action_id = :payroll_action_id
741                     and pos.person_id         = asg.person_id
742                     and pos.period_of_service_id = asg.period_of_service_id
743                     and pos.business_group_id = ppa.business_group_id
744                     and asg.business_group_id = ppa.business_group_id
745                   order by asg.person_id';
746   hr_utility.set_location ('End Date 4',22);
747 
748 EXCEPTION
749       WHEN p30_error
750       THEN
751          -- Write to the conc logfile, and try to archive err msg.
752          hr_utility.set_location (
753                ' Leaving with EXCEPTION: '
754             || l_proc_name,
755             100
756          );
757          l_payroll_action_message :=
758                SUBSTR (
759                   'P35 Report Process Failed: No P30 Process exists for the Business Group as on the specified end date.',
760                   1,
761                   240
762                );
763          fnd_file.put_line (fnd_file.LOG, l_payroll_action_message);
764 
765    END range_code;
766 
767 
768 --------------------------------------------------------------------------------+
769 -- Creates assignment action id for all the valid person id's in
770 -- the range selected by the Range code.
771 -- Locks the max assignment action(can be from P30, Prepayment for run-result
772 -- for a given assignment.
773 --------------------------------------------------------------------------------+
774    PROCEDURE action_creation (
775       pactid      IN   NUMBER,
776       stperson    IN   NUMBER,
777       endperson   IN   NUMBER,
778       CHUNK       IN   NUMBER
779       ) IS
780 
781 l_proc_name             VARCHAR2 (100) := l_package|| 'assignment_action_code';
782 l_actid                 NUMBER;
783 l_locked_action         NUMBER;
784 l_out_var               VARCHAR2 (30);
785 l_aact_id			pay_assignment_actions.assignment_action_id%TYPE;
786 l_set_flag			hr_assignment_set_amendments.include_or_exclude%TYPE ;
787 l_temp_person_id		per_people_f.person_id%TYPE :=0;
788 l_start_date		date;
789 l_end_date			date;
790 l_bg_id			number;
791 
792 CURSOR csr_get_flag_from_set
793 IS
794 	SELECT DISTINCT hasa.include_or_exclude FROM
795 		hr_assignment_set_amendments hasa,
796 		hr_assignment_sets has
797 	WHERE hasa.assignment_set_id = has.assignment_set_id
798 	AND	has.business_group_id  = l_bg_id
799 	AND	has.assignment_set_id  = l_assignment_set_id;
800 
801 CURSOR csr_locked_asgs
802 IS
803 	SELECT /*+ ORDERED USE_NL(asg, paa, ppa, ptp, flex) push_subq */
804 		asg.person_id,
805 		paa.assignment_id,
806 		fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) aa -- Bug 4672715
807 		,fnd_number.canonical_to_number(substr(min(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) aamin -- 8322991
808 	FROM  per_assignments_f asg,
809 		pay_assignment_actions paa,
810 		pay_payroll_actions ppa,
811 		pay_all_payrolls_f pap,
812 		per_time_periods ptp,
813 		hr_soft_coding_keyflex flex
814 	WHERE paa.source_action_id IS NULL
815 	  AND paa.payroll_action_id = ppa.payroll_action_id
816 	  --Added for date track updates of payroll with diff pay ref no
817 	  AND ppa.payroll_id = pap.payroll_id
818 	  /* For time period impact */
819 	  -- AND ppa.time_period_id = ptp.time_period_id                          -- Bug 5070091 Offset payroll change
820 	  AND ppa.payroll_id = ptp.payroll_id
821 	  AND ppa.date_earned between ptp.start_date and ptp.end_date
822 	  --AND ptp.end_date BETWEEN l_start_date AND l_end_date
823 	  AND ppa.effective_date between l_start_date AND l_end_date
824 	  ---
825 	  AND paa.action_status IN ('C','S') --10225372
826 	  AND ppa.action_type IN ('R','Q','I','B','V') --Bug Fix 3747646
827 	  AND ppa.business_group_id = l_bg_id
828 	  AND paa.assignment_id = asg.assignment_id
829 	  AND asg.effective_start_date <= l_end_date
830 	  AND asg.effective_end_date >= l_start_date
831 	  --AND asg.primary_flag = 'Y'
832 	  AND asg.business_group_id = ppa.business_group_id
833 	  AND asg.person_id BETWEEN stperson AND endperson
834 	  --decode added to pick the previous assignments also in case of ReHire having diff overrides.
835 	  AND asg.effective_end_date = DECODE(OVERRIDE_PPSN(asg.assignment_id),NULL, --6633719
836 		     (SELECT MAX (paf.effective_end_date)
837 			   FROM per_assignments_f paf,
838 				  pay_assignment_actions paa1, --Bug fix 4130665
839 				  pay_payroll_actions ppa1,
840 				  per_time_periods ptp1      --Tar 15081088.6
841                          ,pay_all_payrolls_f pay
842 				 ,hr_soft_coding_keyflex flex1
843 			   WHERE paf.person_id = asg.person_id
844 	    --            AND paf.primary_flag = 'Y'
845 			    --Added for bug fix 4130665
846 			    AND paf.assignment_id = paa1.assignment_id
847 			    AND paa1.action_status IN ('C','S') --10225372
848 			    AND ppa1.payroll_action_id = paa1.payroll_action_id
849 			    AND ppa1.action_type in ('R','Q','I','B','V')
850 			    /* For time period impact */
851 			    --AND ppa1.time_period_id = ptp1.time_period_id          --Tar 15081088.6
852 			    AND ppa1.payroll_id = ptp1.payroll_id
853                       AND ppa1.date_earned between ptp1.start_date and ptp1.end_date
854 			    AND ppa1.effective_date between l_start_date AND l_end_date
855 			    ---------
856 			    --AND ptp.end_date BETWEEN l_start_date AND l_end_date   --Tar 15081088.6      -- Bug 5070091 Offset payroll change
857 			    and pay.payroll_id = paf.payroll_id
858 			    and pay.soft_coding_keyflex_id = flex1.soft_coding_keyflex_id
859 			    and flex1.segment4 = l_segment4
860 			    AND ((paf.payroll_id = asg.payroll_id AND
861 				    paf.assignment_id =asg.assignment_id)
862 				  OR paf.assignment_id <> asg.assignment_id)    -- Fix for duplicate records in Rehire case
863 			    AND paf.effective_start_date <= l_end_date
864 			    AND paf.effective_end_date >= l_start_date
865 			    AND pay.effective_start_date <= l_end_date
866 			    AND pay.effective_end_date >= l_start_date)	-- Bug 4867657
867 			    ,asg.effective_end_date) --6633719
868 	  --Added for bug fix 3567562,to restrict the assignments to the PAYE reference selected as parameter.
869 	  AND pap.payroll_id = asg.payroll_id
870 	  AND flex.soft_coding_keyflex_id = pap.soft_coding_keyflex_id
871 	  -- Bug 4142582
872 	  AND flex.segment4 = l_segment4
873 	  AND pap.effective_start_date <= l_end_date
874 	  AND pap.effective_end_date >= l_start_date
875 	  AND (pap.payroll_id in (select b.payroll_id from per_assignments_f a,per_assignments_f b
876 					  where a.payroll_id = l_payroll_id
877 					  and a.person_id = b.person_id
878 					  and a.person_id = asg.person_id
879 					  --bug 6642916
880 					  and a.effective_start_date<= l_end_date
881 					and a.effective_end_date>= l_start_date)
882 					or l_payroll_id is null)  -- Vik Added for payroll
883 	--and check_assignment_in_set(asg.assignment_id,l_assignment_set_id,l_bg_id)=1
884 	  AND ((l_assignment_set_id is not null
885 	     AND (l_set_flag ='I' AND EXISTS(SELECT 1
886 						    FROM  hr_assignment_set_amendments hasa
887 							 ,  hr_assignment_sets has
888 							 ,  per_assignments_f paf
889 						--	 ,  pay_all_payrolls_f pay
890 						--	 ,  hr_soft_coding_keyflex hflex
891 					  WHERE has.assignment_set_id = hasa.assignment_set_id
892 					  AND   has.business_group_id = l_bg_id
893 					  AND   has.assignment_set_id = l_assignment_set_id
894 					  AND   hasa.assignment_id    = paf.assignment_id
895 					  AND   paf.person_id         = asg.person_id)
896 					  --AND   paf.payroll_id        = pay.payroll_id
897 					  --AND   pay.soft_coding_keyflex_id = hflex.soft_coding_keyflex_id
898 					  --AND   hflex.segment4 = l_segment4)
899 		OR l_set_flag = 'E' AND NOT EXISTS(SELECT 1
900 						    FROM  hr_assignment_set_amendments hasa
901 							 ,  hr_assignment_sets has
902 							 ,  per_assignments_f paf
903 						--	 ,  pay_all_payrolls_f pay
904 						--	 ,  hr_soft_coding_keyflex hflex
905 					  WHERE has.assignment_set_id = hasa.assignment_set_id
906 					  AND   has.business_group_id = l_bg_id
907 					  AND   has.assignment_set_id = l_assignment_set_id
908 					  AND   hasa.assignment_id    = paf.assignment_id
909 					  AND   paf.person_id         = asg.person_id
910 					  --AND   paf.payroll_id        = pay.payroll_id
911 					  --AND   pay.soft_coding_keyflex_id = hflex.soft_coding_keyflex_id
912 					  --AND   hflex.segment4 = l_segment4
913 					  )))
914 	  OR l_assignment_set_id IS NULL)
915 	  AND NOT EXISTS (
916 			SELECT 1
917 			  FROM pay_assignment_actions paa_p35,
918 				 pay_payroll_actions ppa_p35,
919 				 per_assignments_f paaf_p35,
920 				 pay_all_payrolls_f ppf_p35,
921 				hr_soft_coding_keyflex flex_p35,
922 				pay_action_interlocks plock
923 			 WHERE ppa_p35.report_type = 'IEP35'
924 			   AND paa_p35.action_status = 'C'
925 			   AND TO_CHAR ( TO_DATE (
926 				    pay_ie_p35.get_parameter (
927 					 ppa_p35.payroll_action_id,
928 					 'END_DATE'
929 				    ),'YYYY/MM/DD'),'YYYY') = TO_CHAR(l_end_date,'YYYY')               --4641756
930 			   AND ppa_p35.payroll_action_id = paa_p35.payroll_action_id
931 			   --AND paa_p35.assignment_id = asg.assignment_id
932 			   AND paa_p35.assignment_id = paaf_p35.assignment_id
933 			   AND paaf_p35.person_id = asg.person_id
934 			   and paa_p35.assignment_action_id = plock.locking_action_id
935 			   and plock.locked_action_id in (select assignment_action_id from pay_assignment_actions
936 			                                  where assignment_id=asg.assignment_id)
937 			   AND paaf_p35.payroll_id = ppf_p35.payroll_id
938 			   AND ppf_p35.soft_coding_keyflex_id = flex_p35.soft_coding_keyflex_id
939 			   AND flex_p35.segment4 = l_segment4)
940 	GROUP BY asg.person_id,paa.assignment_id
941 	ORDER BY asg.person_id,
942 	fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) desc, -- Bug 4672715
943 	paa.assignment_id desc;
944 
945 --6633719
946 cursor csr_ppsn_override(p_asg_id number)
947 is
948 select aei_information1 PPSN_OVERRIDE
949 from per_assignment_extra_info
950 where assignment_id = p_asg_id
951 and aei_information_category = 'IE_ASG_OVERRIDE';
952 
953 l_ppsn_override per_assignment_extra_info.aei_information1%type;
954 
955 cursor csr_ppsn_max_asg(p_ppsn_override varchar2, p_person_id number)
956 is
957 select MAX(paei.assignment_id) ovrride_asg
958 from per_assignment_extra_info paei
959 where paei.information_type = 'IE_ASG_OVERRIDE'
960 and paei.aei_information1 = p_ppsn_override
961 and exists
962 (select 1 from per_all_assignments_f paaf
963   where paaf.assignment_id = paei.assignment_id
964   and paaf.person_id  = p_person_id)
965 GROUP BY paei.aei_information1;
966 
967 l_ppsn_override_asg per_assignment_extra_info.assignment_id%type;
968 
969 --6633719
970 
971 /*  --8322991
972 -- Dont create action if the latest tax basis is exclusion 5867343
973 CURSOR csr_exclusion (p_action_id NUMBER) IS
974 SELECT 'Y', ppa.action_type
975   FROM pay_run_result_values prrv,
976        pay_run_results prr,
977        pay_input_values_f pivf,
978        pay_element_types_f pet,
979        pay_assignment_actions paa,
980 	 pay_payroll_actions ppa
981  WHERE ppa.payroll_action_id= paa.payroll_action_id
982    AND ((paa.source_action_id= p_action_id
983    AND prr.assignment_action_id = paa.assignment_action_id )
984       OR (paa.assignment_action_id = p_action_id AND prr.assignment_action_id = paa.assignment_action_id ))
985    AND prr.element_type_id = pet.element_type_id
986    AND pet.element_name = 'IE PAYE details'
987    AND prrv.run_result_id = prr.run_result_id
988    AND prrv.input_value_id = pivf.input_value_id
989    AND pivf.name = 'Tax Basis'
990    and result_value = 'IE_EXCLUDE';
991 */ --8322991
992 
993 --8322991
994 -- Dont create action if the tax basis is exclusion for whole year(Tax Period).
995 CURSOR csr_exclusion_year (p_action_id_min NUMBER, p_action_id_max NUMBER, p_asg_id NUMBER) IS
996 SELECT count(1) cnt
997   FROM pay_run_result_values prrv,
998        pay_run_results prr,
999        pay_input_values_f pivf,
1000        pay_element_types_f pet,
1001        pay_assignment_actions paa,
1002 	 pay_payroll_actions ppa
1003  WHERE ppa.payroll_action_id= paa.payroll_action_id
1004    AND paa.assignment_id = p_asg_id
1005    AND ((paa.source_action_id between p_action_id_min AND p_action_id_max
1006    AND prr.assignment_action_id = paa.assignment_action_id )
1007       OR (paa.assignment_action_id between p_action_id_min AND p_action_id_max AND prr.assignment_action_id = paa.assignment_action_id ))
1008    AND prr.element_type_id = pet.element_type_id
1009    AND pet.element_name = 'IE PAYE details'
1010    AND prrv.run_result_id = prr.run_result_id
1011    AND prrv.input_value_id = pivf.input_value_id
1012    AND pivf.name = 'Tax Basis'
1013    and result_value <> 'IE_EXCLUDE';
1014 
1015 l_count NUMBER := 0;
1016 --8322991
1017 
1018 --8874161
1019 CURSOR csr_inc_levy(p_action_id_max NUMBER, p_asg_id NUMBER)
1020 IS
1021 SELECT
1022 pay_balance_pkg.get_value (
1023 pay_ie_p35.get_defined_balance_id (
1024 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1025 'IE Income Tax Levy'),
1026 p_action_id_max,
1027 l_segment4,
1028 null,
1029 null,
1030 null,
1031 null,
1032 null,
1033 null,
1034 'TRUE'
1035 )
1036 FROM DUAL;
1037 
1038 l_levi_amount number := 0;
1039 --8874161
1040 
1041 
1042 --12382953
1043 CURSOR csr_usc_prsi_tax_amt(p_action_id_max NUMBER, p_asg_id NUMBER)
1044 IS
1045 SELECT
1046 pay_balance_pkg.get_value (
1047 pay_ie_p35.get_defined_balance_id (
1048 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1049 'IE USC Balance'),
1050 p_action_id_max,
1051 l_segment4,
1052 null,
1053 null,
1054 null,
1055 null,
1056 null,
1057 null,
1058 'TRUE'
1059 ) usc,
1060 (pay_balance_pkg.get_value (
1061 pay_ie_p35.get_defined_balance_id (
1062 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1063 'IE PRSI Employee'),
1064 p_action_id_max,
1065 l_segment4,
1066 null,
1067 null,
1068 null,
1069 null,
1070 null,
1071 null,
1072 'TRUE'
1073 ) +
1074 pay_balance_pkg.get_value (
1075 pay_ie_p35.get_defined_balance_id (
1076 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1077 'IE PRSI Employer'),
1078 p_action_id_max,
1079 l_segment4,
1080 null,
1081 null,
1082 null,
1083 null,
1084 null,
1085 null,
1086 'TRUE'
1087 ) +
1088 pay_balance_pkg.get_value (
1089 pay_ie_p35.get_defined_balance_id (
1090 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1091 'IE PRSI M Employee Lump Sum'),
1092 p_action_id_max,
1093 l_segment4,
1094 null,
1095 null,
1096 null,
1097 null,
1098 null,
1099 null,
1100 'TRUE'
1101 ) +
1102 pay_balance_pkg.get_value (
1103 pay_ie_p35.get_defined_balance_id (
1104 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1105 'IE PRSI M Employer Lump Sum'),
1106 p_action_id_max,
1107 l_segment4,
1108 null,
1109 null,
1110 null,
1111 null,
1112 null,
1113 null,
1114 'TRUE'
1115 ) +
1116 pay_balance_pkg.get_value (
1117 pay_ie_p35.get_defined_balance_id (
1118 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1119 'IE PRSI K Employee Lump Sum'),
1120 p_action_id_max,
1121 l_segment4,
1122 null,
1123 null,
1124 null,
1125 null,
1126 null,
1127 null,
1128 'TRUE'
1129 ) +
1130 pay_balance_pkg.get_value (
1131 pay_ie_p35.get_defined_balance_id (
1132 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1133 'IE PRSI K Employer Lump Sum'),
1134 p_action_id_max,
1135 l_segment4,
1136 null,
1137 null,
1138 null,
1139 null,
1140 null,
1141 null,
1142 'TRUE'
1143 ) ) prsi,
1144 pay_balance_pkg.get_value (
1145 pay_ie_p35.get_defined_balance_id (
1146 DECODE(PAY_IE_P35.OVERRIDE_PPSN(p_asg_id),NULL,'_PER_PAYE_REF_YTD','_PER_PAYE_REF_PPSN_YTD'),
1147 'IE Taxable Pay'),
1148 p_action_id_max,
1149 l_segment4,
1150 null,
1151 null,
1152 null,
1153 null,
1154 null,
1155 null,
1156 'TRUE'
1157 ) taxable_pay
1158 FROM DUAL;
1159 
1160 l_usc_amount number := 0;
1161 l_prsi_amount number := 0;
1162 l_tax_amount number := 0;
1163 
1164 --12382953
1165 
1166 CURSOR csr_action_type (p_assignment_id NUMBER) IS
1167 SELECT fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) asg_action_id
1168 , fnd_number.canonical_to_number(substr(min(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) asg_action_id_min  --12382953
1169   FROM pay_assignment_actions paa,
1170 	 pay_payroll_actions ppa
1171  WHERE ppa.payroll_action_id = paa.payroll_action_id
1172    and paa.assignment_id = p_assignment_id
1173    and ppa.action_type in ('R','Q')
1174    and paa.source_action_id is null
1175    AND ppa.effective_date between l_start_date AND l_end_date;
1176 
1177 
1178 l_flag_exclusion	varchar2(1) := 'N';
1179 l_flag_action_type	pay_payroll_actions.action_type%TYPE;
1180 l_flag_action_id		pay_assignment_actions.assignment_action_id%TYPE;
1181 
1182 --12382953
1183 l_min_action_id pay_assignment_actions.assignment_action_id%TYPE;
1184 l_max_action_id pay_assignment_actions.assignment_action_id%TYPE;
1185 --12382953
1186 
1187 BEGIN
1188 
1189 	--
1190 	l_segment4 := pay_ie_p35.get_parameter( p_payroll_action_id=> pactid,
1191 							    p_token_name=> 'EMP_NO');
1192 	l_out_var := pay_ie_p35.get_parameter (
1193 			    p_payroll_action_id=> pactid,
1194 			    p_token_name=> 'ASSIGNMENT_SET_ID'
1195 			 );
1196 	l_assignment_set_id := to_number(l_out_var);
1197 
1198 	l_out_var := pay_ie_p35.get_parameter (
1199 			    p_payroll_action_id=> pactid,
1200 			    p_token_name=> 'PAYROLL'
1201 			 );
1202 	l_payroll_id := to_number(l_out_var);
1203 
1204 	l_out_var := pay_ie_p35.get_parameter (
1205 					p_payroll_action_id=> pactid,
1206 					p_token_name=> 'END_DATE'
1207 					);
1208       l_end_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
1209       l_out_var := pay_ie_p35.get_parameter (
1210 					p_payroll_action_id=> pactid,
1211 			            p_token_name=> 'START_DATE'
1212 					);
1213       l_start_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
1214       l_out_var := pay_ie_p35.get_parameter (
1215 					p_payroll_action_id=> pactid,
1216 			            p_token_name=> 'BG_ID'
1217 					);
1218       l_bg_id := TO_NUMBER (l_out_var);
1219 
1220 	hr_utility.set_location ('l_segment4 ' ||l_segment4, 12);
1221 	hr_utility.set_location ('l_assignment_set_id ' || to_char(l_assignment_set_id), 12);
1222 	hr_utility.set_location ('l_payroll_id ' || to_char(l_payroll_id), 13);
1223 	hr_utility.set_location ('stperson ' || to_char(stperson), 14);
1224 	hr_utility.set_location ('endperson ' || to_char(endperson), 15);
1225 	hr_utility.set_location ('l_bg_id ' || to_char(l_bg_id), 16);
1226 	hr_utility.set_location ('pactid ' || to_char(pactid), 16);
1227 
1228 	--
1229 	OPEN csr_get_flag_from_set;
1230 	FETCH csr_get_flag_from_set into l_set_flag;
1231 	CLOSE csr_get_flag_from_set;
1232 	--
1233 	l_temp_person_id := 0;
1234 --6633719QA
1235 	l_ppsn_override := NULL;
1236 	l_ppsn_override_asg := NULL;
1237 --6633719QA
1238 
1239 	FOR csr_select_asg_rec IN csr_locked_asgs
1240 	LOOP
1241 	hr_utility.set_location('Person id..'||to_char(csr_select_asg_rec.person_id),17);
1242 	hr_utility.set_location('Temp Person id..'||to_char(l_temp_person_id),18);
1243 	hr_utility.set_location('csr_select_asg_rec.assignment_id'||to_char(csr_select_asg_rec.assignment_id),18);
1244 --6633719QA
1245 --Reinitailising the variables as person changes.
1246     IF l_temp_person_id <> csr_select_asg_rec.person_id
1247     THEN
1248     l_ppsn_override := NULL;
1249     l_ppsn_override_asg := NULL;
1250     END IF;
1251 --6633719QA
1252 	--
1253 	--6633719
1254             OPEN csr_ppsn_override(csr_select_asg_rec.assignment_id);
1255             FETCH csr_ppsn_override INTO l_ppsn_override;
1256 --6633719QA
1257             IF csr_ppsn_override%NOTFOUND THEN
1258             l_ppsn_override := NULL;
1259             END IF;
1260 --6633719QA
1261             CLOSE csr_ppsn_override;
1262 
1263 	hr_utility.set_location('l_ppsn_override'||to_char(l_ppsn_override),19);
1264             IF l_ppsn_override IS NOT NULL   --6633719QA
1265             THEN
1266 			OPEN csr_ppsn_max_asg(l_ppsn_override,csr_select_asg_rec.person_id);
1267 			FETCH csr_ppsn_max_asg INTO l_ppsn_override_asg;
1268 			CLOSE csr_ppsn_max_asg;
1269             END IF;  --6633719QA
1270 	hr_utility.set_location('l_ppsn_override_asg'||to_char(l_ppsn_override_asg),20);
1271 
1272 		-- Create assignment action per person
1273         IF ((l_temp_person_id <> csr_select_asg_rec.person_id
1274             and l_ppsn_override IS NULL)
1275             OR
1276             (l_ppsn_override_asg = csr_select_asg_rec.assignment_id
1277             and l_ppsn_override IS NOT NULL)
1278             )
1279         THEN
1280     --6633719
1281 			--8322991
1282 			l_count := 0;
1283 			l_levi_amount := 0; --8874161
1284 --12382953
1285 			l_usc_amount := 0;
1286 			l_prsi_amount:= 0;
1287 			l_tax_amount := 0;
1288 --12382953
1289 hr_utility.set_location('csr_select_asg_rec.aamin '||to_char(csr_select_asg_rec.aamin),18);
1290 hr_utility.set_location('csr_select_asg_rec.aa '||to_char(csr_select_asg_rec.aa),18);
1291 hr_utility.set_location('csr_select_asg_rec.assignment_id '||to_char(csr_select_asg_rec.assignment_id),18);
1292 --12382953
1293 l_max_action_id := 0;
1294 l_min_action_id := 0;
1295 			OPEN csr_action_type(csr_select_asg_rec.assignment_id);
1296 			FETCH csr_action_type into l_max_action_id, l_min_action_id;
1297 			CLOSE csr_action_type;
1298 hr_utility.set_location('l_max_action_id: '||to_char(l_max_action_id),19);
1299 hr_utility.set_location('l_min_action_id: '||to_char(l_min_action_id),19);
1300 --12382953
1301 			OPEN  csr_exclusion_year(l_min_action_id, l_max_action_id, csr_select_asg_rec.assignment_id); --12382953
1302 			FETCH csr_exclusion_year INTO l_count;
1303 			CLOSE csr_exclusion_year;
1304 
1305 hr_utility.set_location('l_count: '||to_char(l_count),19);
1306 
1307 			--8874161
1308 			OPEN csr_inc_levy(l_max_action_id, csr_select_asg_rec.assignment_id);
1309 			FETCH csr_inc_levy INTO l_levi_amount;
1310 			CLOSE csr_inc_levy;
1311 
1312 hr_utility.set_location('l_levi_amount: '||to_char(l_levi_amount),19);
1313 
1314 --12382953
1315 			OPEN csr_usc_prsi_tax_amt(l_max_action_id, csr_select_asg_rec.assignment_id);
1316 			FETCH csr_usc_prsi_tax_amt INTO l_usc_amount, l_prsi_amount, l_tax_amount ;
1317 			CLOSE csr_usc_prsi_tax_amt;
1318 
1319 hr_utility.set_location('l_usc_amount: '||to_char(l_usc_amount),19);
1320 hr_utility.set_location('l_prsi_amount: '||to_char(l_prsi_amount),19);
1321 hr_utility.set_location('l_tax_amount: '||to_char(l_tax_amount),19);
1322 --12382953
1323 			IF l_count <> 0 OR  l_levi_amount <> 0
1324 			OR l_usc_amount <> 0 OR l_prsi_amount <> 0 OR l_tax_amount <> 0 THEN  --8874161  --12382953
1325 					SELECT pay_assignment_actions_s.NEXTVAL
1326 					INTO l_actid
1327 					FROM DUAL;
1328 
1329 hr_utility.set_location('INSIDE IF',18);
1330 hr_utility.set_location('Insert asg actions asg_id '||to_char(csr_select_asg_rec.assignment_id),18);
1331 hr_utility.set_location('Insert asg actions l_actid '||to_char(l_actid),18);
1332 hr_utility.set_location('Insert asg actions pactid '||to_char(pactid),18);
1333 
1334 					hr_nonrun_asact.insact (l_actid,
1335 									csr_select_asg_rec.assignment_id,
1336 									pactid,
1337 									CHUNK,
1338 									to_number(l_segment4)
1339 									);
1340 			END IF;
1341 			--8322991
1342 
1343 /* --8322991  Commented the code
1344 		      -- 5867343
1345 			l_flag_exclusion := 'N';
1346 			OPEN csr_exclusion(csr_select_asg_rec.aa);
1347 			FETCH csr_exclusion into l_flag_exclusion, l_flag_action_type;
1348 			CLOSE csr_exclusion;
1349 
1350 			IF l_flag_exclusion <> 'Y' then
1351 				IF l_flag_action_type not in ('I','B','V') then
1352 					SELECT pay_assignment_actions_s.NEXTVAL
1353 					INTO l_actid
1354 					FROM DUAL;
1355 
1356 hr_utility.set_location('INSIDE IF',18);
1357 hr_utility.set_location('Insert asg actions asg_id '||to_char(csr_select_asg_rec.assignment_id),18);
1358 hr_utility.set_location('Insert asg actions l_actid '||to_char(l_actid),18);
1359 hr_utility.set_location('Insert asg actions pactid '||to_char(pactid),18);
1360 
1361 					hr_nonrun_asact.insact (l_actid,
1362 									csr_select_asg_rec.assignment_id,
1363 									pactid,
1364 									CHUNK,
1365 									to_number(l_segment4)
1366 									);
1367 				ELSE
1368 					-- get the last run
1369 					OPEN csr_action_type(csr_select_asg_rec.assignment_id);
1370 					FETCH csr_action_type into l_flag_action_id;
1371 					CLOSE csr_action_type;
1372 
1373 					OPEN csr_exclusion(l_flag_action_id);
1374 					FETCH csr_exclusion into l_flag_exclusion, l_flag_action_type;
1375 					CLOSE csr_exclusion;
1376 
1377 					IF l_flag_exclusion <> 'Y' then
1378 						SELECT pay_assignment_actions_s.NEXTVAL
1379 						INTO l_actid
1380 						FROM DUAL;
1381 hr_utility.set_location('INSIDE ELSE',18);
1382 hr_utility.set_location('Insert asg actions asg_id '||to_char(csr_select_asg_rec.assignment_id),18);
1383 hr_utility.set_location('Insert asg actions l_actid '||to_char(l_actid),18);
1384 hr_utility.set_location('Insert asg actions pactid '||to_char(pactid),18);
1385 						hr_nonrun_asact.insact (l_actid,
1386 									csr_select_asg_rec.assignment_id,
1387 									pactid,
1388 									CHUNK,
1389 									to_number(l_segment4)
1390 									);
1391 					END IF;
1392 				END IF;
1393 			END IF;
1394 */ --8322991
1395 
1396 		END IF;
1397 		--
1398 		-- Lock all the run-result assignment actions for a person per assignment.
1399 		-- IF l_flag_exclusion <> 'Y' then  --8322991
1400 		IF l_count <> 0  OR  l_levi_amount <> 0
1401 		OR l_usc_amount <> 0 OR l_prsi_amount <> 0 OR l_tax_amount <> 0 THEN  --8874161  --12382953
1402 
1403 hr_utility.set_location('Insert asg action Intlks l_actid'||to_char(l_actid),18);
1404 hr_utility.set_location('Insert asg action Intlks  csr_select_asg_rec.aa'||to_char(csr_select_asg_rec.aa),18);
1405 			hr_nonrun_asact.insint (l_actid,csr_select_asg_rec.aa);
1406 		END IF;
1407 		l_temp_person_id := csr_select_asg_rec.person_id;
1408 	--
1409 	END LOOP;
1410 
1411 hr_utility.set_location ('Leaving action_creation', 18);
1412 END action_creation;
1413 
1414 
1415 Procedure archive_code  (p_assactid       IN NUMBER
1416 				,p_effective_date IN DATE) is
1417 
1418 
1419 	l_proc_name                      VARCHAR2 (100) := l_package|| 'archive_code';
1420       l_actid                          NUMBER;
1421       l_locked_action                  NUMBER;
1422       l_out_var                        VARCHAR2 (30);
1423       l_effective_date                 DATE;
1424       l_arch_ppsn                      pay_action_information.action_information4%TYPE;
1425       l_arch_works_number              pay_action_information.action_information14%TYPE
1426                                                                    DEFAULT ' '; --BUG 3306202 Added default value
1427 	l_segment4				   hr_soft_coding_keyflex.segment4%TYPE;
1428       l_arch_person_id                 per_assignments_f.person_id%TYPE;
1429       l_arch_assignment_id             pay_assignment_actions.assignment_id%TYPE;
1430       l_arch_assmt_action_id_bal       pay_assignment_actions.assignment_action_id%TYPE;
1431       l_arch_tax_deduction_basis       pay_action_information.action_information17%TYPE;
1432       l_arch_surname                   pay_action_information.action_information29%TYPE;
1433       l_arch_first_name                pay_action_information.action_information28%TYPE;
1434       l_arch_dob                       pay_action_information.action_information25%TYPE;
1435       l_arch_address_line1             pay_action_information.action_information5%TYPE;
1436       l_arch_address_line2             pay_action_information.action_information6%TYPE;
1437       l_arch_address_line3             pay_action_information.action_information7%TYPE; -- BUG 4066315
1438       l_arch_address_line4             pay_action_information.action_information9%TYPE; -- BUG 4066315
1439       l_length_address_line2           NUMBER; -- BUG 4066315
1440       l_available_space                NUMBER; -- BUG 4066315
1441       l_arch_hire_date                 pay_action_information.action_information24%TYPE;
1442       l_arch_payroll_action_id         pay_assignment_actions.payroll_action_id%TYPE;
1443       l_arch_annual_tax_credit         pay_action_information.action_information26%TYPE;
1444       l_arch_term_date                 pay_action_information.action_information25%TYPE;
1445       l_arch_mothers_name              per_people_f.per_information1%TYPE;
1446       l_arch_totwks_insurble_emplmnt   pay_run_result_values.result_value%TYPE;
1447       l_arch_initial_class             pay_run_result_values.result_value%TYPE;
1448       l_arch_second_class              pay_run_result_values.result_value%TYPE;
1449       l_arch_third_class               pay_run_result_values.result_value%TYPE;
1450       l_arch_fourth_class              pay_run_result_values.result_value%TYPE;
1451       l_arch_fifth_class               pay_run_result_values.result_value%TYPE;
1452 	l_arch_weeks_at_initial_class	   pay_run_result_values.result_value%TYPE;
1453       l_arch_weeks_at_second_class     pay_run_result_values.result_value%TYPE;
1454       l_arch_weeks_at_third_class      pay_run_result_values.result_value%TYPE;
1455       l_arch_weeks_at_fourth_class     pay_run_result_values.result_value%TYPE;
1456 	l_arch_weeks_at_fifth_class      pay_run_result_values.result_value%TYPE;
1457       l_arch_net_tax                   pay_action_information.action_information4%TYPE;
1458       l_arch_tax_or_refund             pay_action_information.action_information4%TYPE;
1459       l_arch_employees_prsi_cont       pay_action_information.action_information4%TYPE;
1460       l_arch_total_prsi_cont           pay_action_information.action_information4%TYPE;
1461       l_arch_employer_prsi_cont        pay_action_information.action_information4%TYPE;
1462       l_arch_pay                       pay_action_information.action_information4%TYPE;
1463       l_arch_non_tax_pay               pay_action_information.action_information4%TYPE; --Bug 4063502
1464       l_arch_prev_pay                  pay_action_information.action_information4%TYPE;
1465       l_arch_prev_tax                  pay_action_information.action_information4%TYPE;
1466       l_arch_ovn                       pay_action_information.object_version_number%TYPE;
1467       l_arch_previous_emp_pay          pay_action_information.action_information28%TYPE;
1468       l_arch_previous_emp_pay_usc          pay_action_information.action_information28%TYPE; --14659262
1469       l_arch_previous_emp_tax          pay_action_information.action_information29%TYPE;
1470       l_arch_previous_emp_usc          pay_action_information.action_information29%TYPE;  --14659262
1471       l_arch_pr_indicator              pay_action_information.action_information30%TYPE;
1472       l_arch_action_info_id            NUMBER;
1473       l_arch_total_notional_pay        pay_action_information.action_information4%TYPE;
1474 	l_arch_total_share_scheme        pay_action_information.action_information4%TYPE; --16306646
1475 	l_p35_taxable_pay_adjust         pay_action_information.action_information4%TYPE; --16306646
1476 	l_p35_gross_pay_adjust           pay_action_information.action_information4%TYPE; --16306646
1477 	l_period_type		         pay_all_payrolls_f.period_type%TYPE; --Bug 4154171
1478 -- Temporary variable to hold values when Class K or M exists
1479       l_temp_prsi_cont                 pay_action_information.action_information4%TYPE := NULL;
1480       l_oth_arch_ovn		         pay_action_information.object_version_number%TYPE;
1481       l_pds_id			         per_periods_of_service.period_of_service_id%TYPE;
1482       l_asg_id			         per_assignments_f.assignment_id%TYPE;
1483       l_aact_id			         pay_assignment_actions.assignment_action_id%TYPE;
1484       l_max_act_for_bal 	         pay_assignment_actions.assignment_action_id%TYPE;
1485       l_set_flag				   hr_assignment_set_amendments.include_or_exclude%TYPE ;
1486 	l_arch_primary_flag		   per_assignments_f.primary_flag%TYPE;
1487 	l_arch_asg_location_id             per_assignments_f.location_id%TYPE; -- 10277535
1488 	l_arch_org_id                      per_assignments_f.organization_id%TYPE; -- 11674153
1489 	v_primary_flag			   per_assignments_f.primary_flag%TYPE;
1490 	-- pension variables
1491 	l_arch_pen_emp_rbs		   pay_action_information.action_information30%TYPE;
1492 	l_arch_pen_empr_rbs		   pay_action_information.action_information30%TYPE;
1493 	l_arch_pen_emp_prsa		   pay_action_information.action_information30%TYPE;
1494 	l_arch_pen_empr_prsa		   pay_action_information.action_information30%TYPE;
1495 	l_arch_pen_emp_rac		   pay_action_information.action_information30%TYPE;
1496 	-- P60 enhancement changes. bug
1497 
1498 	-- bik medical insurance 5867343
1499 	l_medical_insurance		   pay_action_information.action_information30%TYPE;
1500 	l_arch_gross_pay                   pay_action_information.action_information4%TYPE; /* 8520684 */
1501         l_arch_income_levy                 pay_action_information.action_information4%TYPE;
1502         l_arch_income_levy_first           pay_action_information.action_information4%TYPE;
1503 	l_arch_income_levy_second          pay_action_information.action_information4%TYPE;
1504         l_arch_income_levy_third           pay_action_information.action_information4%TYPE;
1505         l_arch_illness_benefit           pay_action_information.action_information4%TYPE; --14656910
1506 	l_arch_parking_levy                pay_action_information.action_information4%TYPE;
1507 	l_temp_gross_pay                   pay_action_information.action_information4%TYPE := NULL;
1508 	l_temp_income_levy                 pay_action_information.action_information4%TYPE := NULL;
1509 
1510 --12382953
1511 	l_arch_gross_pay_usc               pay_action_information.action_information4%TYPE;
1512 	l_temp_gross_pay_usc               pay_action_information.action_information4%TYPE;
1513 
1514 	l_arch_usc                 pay_action_information.action_information4%TYPE;
1515 	l_arch_usc_first           pay_action_information.action_information4%TYPE;
1516 	l_arch_usc_second          pay_action_information.action_information4%TYPE;
1517 	l_arch_usc_third           pay_action_information.action_information4%TYPE;
1518 	l_temp_usc                 pay_action_information.action_information4%TYPE := NULL;
1519       l_exclusion_order  VARCHAR2(10) := '0';
1520 --12382953
1521 
1522 	/* 8978805 */
1523 
1524 	l_arch_total_this_gross_pay   pay_action_information.action_information4%TYPE;
1525         l_arch_prev_gross_pay        pay_action_information.action_information4%TYPE;
1526         l_arch_prev_gross_pay_adjust pay_action_information.action_information4%TYPE;
1527         l_arch_prev_gross_pay_BIK    pay_action_information.action_information4%TYPE;
1528         l_arch_this_income_levy       pay_action_information.action_information4%TYPE;
1529 --6633719
1530 l_dimension_name VARCHAR2(100):= '_PER_PAYE_REF_YTD';
1531 
1532 --11857084
1533 l_arch_tot_this_gross_pay_usc     pay_action_information.action_information4%TYPE;
1534 l_arch_prev_gross_pay_usc         pay_action_information.action_information4%TYPE;
1535 l_arch_prev_gross_pay_adj_usc     pay_action_information.action_information4%TYPE;
1536 l_arch_prev_gross_pay_BIK_usc     pay_action_information.action_information4%TYPE;
1537 l_arch_prev_gross_pay_CO_usc      pay_action_information.action_information4%TYPE;
1538 l_arch_this_usc                   pay_action_information.action_information4%TYPE;
1539 l_arch_prev_gross_pay_CP_usc      pay_action_information.action_information4%TYPE; --11076169
1540 l_arch_prev_gross_pay_ERPRSA      pay_action_information.action_information4%TYPE; --16242337
1541 --11857084
1542 
1543 
1544 CURSOR get_actid_from_interlocks IS
1545 	SELECT * from pay_action_interlocks
1546 	where locking_action_id = p_assactid
1547 	order by locking_action_id,locked_action_id desc;
1548 
1549 -- Cursor to get action type, so that we can identify whether a assignment action
1550 -- is from P30, prepayments or run-results
1551 
1552 CURSOR get_action_type(p_action_id number)
1553 IS
1554 	SELECT paa.assignment_action_id,ppa.action_type
1555 	FROM pay_action_interlocks pal,
1556 	    pay_assignment_actions paa,
1557 	    pay_payroll_actions ppa
1558 	WHERE pal.locked_action_id = p_action_id
1559 	AND pal.locking_action_id = paa.assignment_action_id
1560 	AND ppa.payroll_action_id = paa.payroll_action_id
1561 	AND paa.action_status IN ('C','S') --10225372
1562 	AND (ppa.action_type IN ('P', 'U')
1563 	OR (ppa.action_type='X' and ppa.report_type = 'IEPS'
1564 	   and paa.source_action_id IS NULL
1565 	   and exists (select 1 from pay_action_information pai
1566 			   where pai.action_information_category = 'IE EMPLOYEE DETAILS'
1567 			   AND pai.action_context_type='AAP'
1568 			   AND pai.action_context_id=paa.assignment_action_id)))
1569 	ORDER BY paa.assignment_action_id DESC;
1570 
1571 /*CURSOR get_action_type(p_action_id number) is
1572 	select ppa.action_type, ppa.report_type
1573 	from	 pay_payroll_actions ppa,
1574 		 pay_assignment_actions paa
1575 	where  ppa.payroll_action_id = paa.payroll_action_id
1576 	and    paa.source_action_id IS NULL
1577 	and	 paa.assignment_action_id = p_action_id;*/
1578 
1579 -- Cursor to check if P30 exists
1580 -- p_asg_act_id is run-result action id
1581 
1582 /*CURSOR csr_latest_p30_action (p_asg_act_id NUMBER)
1583 IS
1584    SELECT   paa.assignment_action_id
1585 	 FROM pay_action_interlocks pal,
1586 		pay_assignment_actions paa,
1587 		pay_payroll_actions ppa,
1588 		pay_action_information pai
1589 	WHERE pal.locked_action_id = p_asg_act_id
1590 	  AND pal.locking_action_id = paa.assignment_action_id
1591 	  AND paa.source_action_id IS NULL
1592 	  AND ppa.payroll_action_id = paa.payroll_action_id
1593 	  AND paa.action_status = 'C'
1594 	  AND ppa.report_type = 'IEPS'
1595 	  AND pai.action_information_category = 'IE EMPLOYEE DETAILS'
1596 	  AND pai.action_context_type='AAP'
1597 	  AND pai.action_context_id=paa.assignment_action_id
1598    ORDER BY 1 DESC;
1599 
1600 -- Cursor to check if Prepayments exists
1601 -- p_asg_act_id is run-result action id
1602 
1603 CURSOR csr_latest_prepay_action (p_asg_act_id NUMBER)
1604 IS
1605    SELECT paa.assignment_action_id
1606      FROM pay_action_interlocks pal,
1607 	    pay_assignment_actions paa,
1608 	    pay_payroll_actions ppa
1609     WHERE pal.locked_action_id = p_asg_act_id
1610 	AND pal.locking_action_id = paa.assignment_action_id
1611 	AND ppa.payroll_action_id = paa.payroll_action_id
1612 	AND paa.action_status = 'C'
1613 	AND ppa.action_type IN ('P', 'U');*/
1614 
1615 
1616 -- Cursor to get the balance values from P30
1617 -- p_locked_action_id is P30s assignment action id
1618 CURSOR csr_p30_bal_value (p_locked_action_id   NUMBER,
1619 			              p_balance_name       VARCHAR2,  --6633719
1620                           p_dimension_name VARCHAR2) IS  --6633719
1621 	SELECT SUBSTR (pai1.action_information4, 1, 30) bval
1622 	FROM pay_action_information pai1,
1623 	    pay_balance_types pbt,
1624 	    pay_balance_dimensions pbd,
1625 	    pay_defined_balances pdb
1626 	WHERE pdb.balance_type_id = pbt.balance_type_id
1627 	AND pbt.legislation_code = 'IE'
1628 	AND UPPER (pbt.balance_name) = p_balance_name
1629 	AND pbd.legislation_code = 'IE'
1630 	AND pbd.dimension_name = p_dimension_name  -- 6633719 '_PER_PAYE_REF_YTD' -- changes made
1631 	AND pdb.balance_dimension_id = pbd.balance_dimension_id
1632 	AND pai1.action_context_type = 'AAP'
1633 	AND pai1.action_information_category = 'EMEA BALANCES'
1634 	AND pai1.action_information1 = pdb.defined_balance_id
1635 	AND pai1.action_context_id = p_locked_action_id;
1636 
1637 --6633719
1638 CURSOR csr_rehire_ppsn_arch(p_locked_action_id   NUMBER)
1639     IS
1640     SELECT NVL(action_information20,'N') PPSN_BAL_ARCHIVED
1641     FROM pay_action_information pai
1642     WHERE
1643 	pai.action_context_type = 'AAP'
1644 	AND pai.action_information_category = 'IE EMPLOYEE DETAILS'
1645 	AND pai.action_context_id = p_locked_action_id;
1646 
1647 -- N = Not Archived by Leg Generator PPSN Balances , Y = Archived PPSN Balances by Leg Generator.
1648 l_ppsn_bal_archived varchar2(1) := 'N';
1649 --6633719
1650 
1651 -- Cursor to get employee and address details from P30 legislative archive
1652 -- p_locked_action_id is P30s assignment action id
1653 -- p_rr_action is Payroll Run assignment action id 4672715
1654 CURSOR csr_p30_found (p_locked_action NUMBER,
1655                       p_arch_net_tax VARCHAR2,
1656                       p_rr_action NUMBER) IS
1657 	SELECT NVL (pact_edi.action_information4, ' '), --PPSN number
1658 	    NVL (pact_edi.action_information14, ' '), -- WORKS_NUMBER
1659 	    paf.person_id,
1660 	    paf.primary_flag,    -- changes made
1661 	    paf.location_id, -- 10277535
1662 	    paf.ORGANIZATION_ID,  --11674153
1663 	    paf.assignment_id,
1664 	    NVL (TRIM (RPAD (pact_iedi.action_information29, 20)), ' '), -- SURNAME
1665 	    NVL (TRIM (RPAD (pact_iedi.action_information28, 20)), ' '), -- FIRST_NAME
1666 	    NVL (TRIM (pact_iedi.action_information25), '31-12-4712'), -- DOB
1667 	    NVL (TRIM (RPAD (pact_ad.action_information5, 30)), ' '), -- ADDRESS_LINE1
1668 	    NVL (TRIM (pact_ad.action_information6), ' '),            -- ADDRESS_LINE2
1669 	    NVL (TRIM ( pact_ad.action_information7), ' '),          -- ADDRESS_LINE3   BUG 4066315
1670 	    NVL (
1671 		 TRIM (
1672 			    hr_general.decode_lookup (
1673 				 'IE_COUNTY',
1674 				 TRIM (pact_ad.action_information9)
1675 			    )
1676 		    ||' '||
1677 			    hr_general.decode_lookup (
1678 				 'IE_POSTAL_CODE',
1679 				 TRIM (pact_ad.action_information12)
1680 			    )
1681 		 ),
1682 		 ' '
1683 	    ), --ADDRESS LINE 4
1684 
1685 
1686 	    NVL (TO_CHAR (pps.date_start, 'dd-mm-yyyy'), '31-12-4712'), -- HIRE_DATE
1687 	/*Bug 4154171*/
1688 	ptp.period_type, --PERIOD_TYPE
1689 	    DECODE (
1690 		 TO_CHAR (
1691 		    NVL (
1692 			 pps.actual_termination_date,
1693 			 TO_DATE ('31-12-4712', 'DD-MM-YYYY')
1694 		    ),
1695 		    'YYYY'
1696 		 ),
1697 		 TO_CHAR (pay_ie_p35.get_end_date, 'RRRR') --Bug fix 3745861
1698 	   , TO_CHAR (pps.actual_termination_date, 'dd-mm-yyyy'),
1699 		 '31-12-4712'
1700 	    ), -- TERM_DATE
1701 	    NVL (TRIM (RPAD (ppf.per_information1, 30)), ' '), -- MOTHERS_NAME
1702 	    DECODE (SIGN (TO_NUMBER (p_arch_net_tax)), -1, 'H9', 1, 'J7'), --Q1_PR_Indicator
1703 	    NVL (
1704 		 ROUND (
1705 		    TO_NUMBER (
1706 			 pay_balance_pkg.get_value (
1707 			    pay_ie_p35.get_defined_balance_id (
1708 				 '_ASG_YTD',
1709 				 'IE P45 Pay'
1710 			    ),
1711 			    p_rr_action
1712 			 )
1713 		    ),
1714 		    2
1715 		 ),
1716 		 0
1717 	    ), -- Q1_Previous_Emp_Pay
1718 	    NVL (
1719 		 ROUND (
1720 		    TO_NUMBER (
1721 			 pay_balance_pkg.get_value (
1722 			    pay_ie_p35.get_defined_balance_id (
1723 				 '_ASG_YTD',
1724 				 'IE P45 Tax Deducted'
1725 			    ),
1726 			    p_rr_action
1727 			 )
1728 		    ),
1729 		    2
1730 		 ),
1731 		 0
1732 	    ) -- Q1_Previous_Emp_Tax
1733 --14659262
1734 	    ,NVL (
1735 		 ROUND (
1736 		    TO_NUMBER (
1737 			 pay_balance_pkg.get_value (
1738 			    pay_ie_p35.get_defined_balance_id (
1739 				 '_ASG_YTD',
1740 				 'IE P45 USC Pay'
1741 			    ),
1742 			    p_rr_action
1743 			 )
1744 		    ),
1745 		    2
1746 		 ),
1747 		 0
1748 	    ) -- Q1_Previous_Emp_Pay_USC
1749 	    ,NVL (
1750 		 ROUND (
1751 		    TO_NUMBER (
1752 			 pay_balance_pkg.get_value (
1753 			    pay_ie_p35.get_defined_balance_id (
1754 				 '_ASG_YTD',
1755 				 'IE P45 USC Deducted'
1756 			    ),
1757 			    p_rr_action
1758 			 )
1759 		    ),
1760 		    2
1761 		 ),
1762 		 0
1763 	    ) -- Q1_Previous_Emp_USC
1764 --14659262
1765 	FROM pay_action_information pact_edi,
1766 	    pay_action_information pact_iedi,
1767 	    pay_action_information pact_ad,
1768 	    per_assignments_f paf,
1769 	    per_periods_of_service pps,
1770 	   -- pay_ie_paye_details_f payef,
1771 	    per_time_periods ptp,
1772 	    per_people_f ppf
1773 	WHERE pact_iedi.action_information_category = 'IE EMPLOYEE DETAILS'
1774 	AND pact_iedi.action_context_type = 'AAP'
1775 	AND pact_iedi.action_context_id = p_locked_action
1776 	AND pact_edi.action_information_category = 'EMPLOYEE DETAILS'
1777 	AND pact_edi.action_context_type = 'AAP'
1778 	AND pact_edi.action_context_id = p_locked_action
1779 	AND pact_ad.action_information_category = 'ADDRESS DETAILS'
1780 	AND pact_ad.action_context_type = 'AAP'
1781 	AND pact_ad.action_information14 = 'Employee Address'
1782 	AND pact_ad.action_context_id = p_locked_action
1783 	AND ptp.time_period_id =
1784 					TO_NUMBER (pact_edi.action_information16)
1785 	AND paf.assignment_id = pact_ad.assignment_id
1786 	--AND paf.primary_flag = 'Y'
1787 	AND paf.effective_end_date =
1788 		    (SELECT MAX (asg.effective_end_date)
1789 			 FROM per_assignments_f asg
1790 			WHERE asg.assignment_id = paf.assignment_id
1791 			  AND asg.effective_start_date <=
1792 					  l_end_date --pay_ie_p35.get_start_date()
1793 			  AND asg.effective_end_date >=
1794 					 l_start_date -- pay_ie_p35.get_end_date()
1795 							 )
1796 	AND paf.period_of_service_id = pps.period_of_service_id
1797 	AND paf.person_id = pps.person_id
1798 	AND ppf.person_id = paf.person_id
1799 	AND ppf.effective_end_date =
1800 		    (SELECT MAX (per.effective_end_date)
1801 			 FROM per_people_f per
1802 			WHERE per.person_id = ppf.person_id
1803 			  AND per.effective_start_date <=
1804 					  l_end_date --pay_ie_p35.get_start_date()
1805 			  AND per.effective_end_date >=
1806 					  l_start_date --pay_ie_p35.get_end_date()
1807 							  );
1808 
1809 -- Prepayment cursor
1810 -- p_locked_action is pre-payments locked action.
1811 -- p_rr_action is Payroll Run assignment action id 4672715
1812 CURSOR csr_prepay_found (p_locked_action NUMBER,
1813                          p_rr_action NUMBER,
1814                          p_dimension_name VARCHAR2,   --6633719  3new pmtr added
1815                          p_context_id number,
1816                          p_context_value pay_action_contexts.CONTEXT_VALUE%type ) IS
1817 	SELECT NVL (SUBSTR (ppf.national_identifier, 1, 9), ' '), -- PPSN
1818 	    -- for bug 5301598, increased the size to 12
1819 	    NVL (SUBSTR (paf.assignment_number, 1, 12), ' '), --WORKS NUMBER
1820 	    paf.person_id, -- FOR CALCULATION
1821 	    paf.primary_flag,  -- changes made
1822 	    paf.location_id, -- 10277535
1823 	    paf.organization_id, --11674153
1824 	    paf.assignment_id, -- FOR CALCULATION
1825 	    paa.assignment_action_id, -- FOR CALCULATION
1826 	    DECODE (
1827 		 SIGN (
1828 		    NVL (
1829 			 pay_balance_pkg.get_value (
1830 			    pay_ie_p35.get_defined_balance_id (
1831 				 p_dimension_name,  --'_PER_PAYE_REF_YTD', -- changes made --6633719
1832 				 'IE Net Tax'
1833 			    ),
1834 			         p_rr_action, -- paa.assignment_action_id,
1835 				   l_segment4, -- paye reference value
1836 				   null,
1837 				   p_context_id,  --null,
1838 				   p_context_value, --null,
1839 				   null,
1840 				   null,
1841 				   null,
1842 				   'TRUE'
1843 
1844 			 ),
1845 			 0
1846 		    )
1847 		 ),
1848 		 -1, '1',
1849 		 1, '0',
1850 		 '0'
1851 	    ), --TAX OR REFUND
1852 	  /*Bug 4154171*/
1853 	/*DECODE (
1854 		 payef.tax_basis,
1855 		 'IE_EMERGENCY', '2',
1856 		 NULL, '2',
1857 		 DECODE (payef.info_source, 'IE_P45', '1', '0')
1858 	    ), --TAX_DEDUCTION_BASIS*/
1859 
1860 	    TRIM (RPAD (ppf.last_name, 20)), --SURNAME
1861 	    /* Bug 4560952*/
1862 	    NVL (TRIM (RPAD (ppf.first_name||' '||ppf.middle_names, 20)), ' '), --FIRST_NAME
1863 	    TO_CHAR (ppf.date_of_birth, 'dd-mm-yyyy'), --DOB
1864 	    NVL (TRIM (RPAD (pad.address_line1, 30)), ' '), --ADDRESS_LINE1
1865 	    NVL (TRIM (pad.address_line2), ' '), --ADDRESS_LINE2
1866 	    NVL (TRIM (pad.address_line3), ' '), --ADDRESS_LINE3
1867 	    NVL (TRIM (hr_general.decode_lookup ('IE_COUNTY',
1868 				 TRIM (pad.region_1)
1869 			    )
1870 		    ||' '||  (
1871 			    hr_general.decode_lookup (
1872 				 'IE_POSTAL_CODE',
1873 				 TRIM (pad.postal_code)
1874 			    )
1875 			 )
1876 		 ),
1877 		 ' '
1878 	    ), --ADDRESS_LINE4
1879 
1880 	    TO_CHAR (pps.date_start, 'dd-mm-yyyy'), --HIRE_DATE
1881 	    DECODE (
1882 		 TO_CHAR (
1883 		    NVL (
1884 			 pps.actual_termination_date,
1885 			 TO_DATE ('31-12-4712', 'DD-MM-YYYY')
1886 		    ),
1887 		    'YYYY'
1888 		 ),
1889 		 TO_CHAR (l_end_date, 'YYYY'), TO_CHAR (
1890 							    pps.actual_termination_date,
1891 							    'dd-mm-yyyy'
1892 							 ),
1893 		 '31-12-4712'
1894 	    ), --TERM_DATE
1895 	    papf.period_type, --PERIOD_TYPE
1896 	/*Bug 4154171*/
1897 	/*TO_CHAR (
1898 		 NVL (
1899 		    DECODE (
1900 			 papf.period_type,
1901 			 'Lunar Month', ROUND (
1902 						 (payef.weekly_tax_credit * 52),
1903 						 2
1904 					    ),
1905 			 DECODE (
1906 			    INSTR (papf.period_type, 'Week'),
1907 			    0, ROUND (
1908 				    (payef.monthly_tax_credit * 12),
1909 				    2
1910 				 ),
1911 			    ROUND (
1912 				 (payef.weekly_tax_credit * 52),
1913 				 2
1914 			    )
1915 			 )
1916 		    ),
1917 		    0
1918 		 )
1919 	    ), --ANNUAL_TAX_CREDIT*/
1920 
1921 	    NVL (TRIM (RPAD (ppf.per_information1, 30)), ' '), --MOTHERS_NAME
1922 	    DECODE (
1923 		 SIGN (
1924 		  pay_balance_pkg.get_value (
1925 			    pay_ie_p35.get_defined_balance_id (
1926 				  p_dimension_name,  --'_PER_PAYE_REF_YTD', -- changes made--6633719
1927 				 'IE Net Tax'
1928 			    ),
1929 			    p_rr_action, --paa.assignment_action_id,
1930 			    l_segment4, -- paye reference value
1931 				  null,
1932 				   p_context_id,  --null,
1933 				   p_context_value,  --null,
1934 				   null,
1935 				   null,
1936 				   null,
1937 				  'TRUE'
1938 			 )
1939 		 ),
1940 		 -1, 'H9',
1941 		 1, 'J7'
1942 	    ), --Q1_PR_Indicator
1943 	    NVL (
1944 		 ROUND (
1945 		    TO_NUMBER (
1946 			 pay_balance_pkg.get_value (
1947 			    pay_ie_p35.get_defined_balance_id (
1948 				 '_ASG_YTD',
1949 				 'IE P45 Pay'
1950 			    ),
1951 			    p_rr_action
1952 			 )
1953 		    ),
1954 		    2
1955 		 ),
1956 		 0
1957 	    ), -- Q1_Previous_Emp_Pay
1958 	    NVL (
1959 		 ROUND (
1960 		    TO_NUMBER (
1961 			 pay_balance_pkg.get_value (
1962 			    pay_ie_p35.get_defined_balance_id (
1963 				 '_ASG_YTD',
1964 				 'IE P45 Tax Deducted'
1965 			    ),
1966 			    p_rr_action
1967 			 )
1968 		    ),
1969 		    2
1970 		 ),
1971 		 0
1972 	    ) -- Q1_Previous_Emp_Tax
1973 --14659262
1974 	    ,NVL (
1975 		 ROUND (
1976 		    TO_NUMBER (
1977 			 pay_balance_pkg.get_value (
1978 			    pay_ie_p35.get_defined_balance_id (
1979 				 '_ASG_YTD',
1980 				 'IE P45 USC Pay'
1981 			    ),
1982 			    p_rr_action
1983 			 )
1984 		    ),
1985 		    2
1986 		 ),
1987 		 0
1988 	    ) -- Q1_Previous_Emp_Pay_USC
1989 	    ,NVL (
1990 		 ROUND (
1991 		    TO_NUMBER (
1992 			 pay_balance_pkg.get_value (
1993 			    pay_ie_p35.get_defined_balance_id (
1994 				 '_ASG_YTD',
1995 				 'IE P45 USC Deducted'
1996 			    ),
1997 			    p_rr_action
1998 			 )
1999 		    ),
2000 		    2
2001 		 ),
2002 		 0
2003 	    ) -- Q1_Previous_Emp_USC
2004 --14659262
2005 	FROM pay_action_interlocks pai,
2006 	    pay_assignment_actions paa,
2007 	    per_people_f ppf,
2008 	    per_periods_of_service pps,
2009 	    per_assignments_f paf,
2010 	    per_addresses pad,
2011 	   -- pay_ie_paye_details_f payef, --Bug 4154171
2012 	    pay_all_payrolls_f papf,
2013 	    pay_payroll_actions ppa
2014 	WHERE pai.locking_action_id = p_locked_action
2015 	AND paa.assignment_action_id = pai.locked_action_id
2016 	-- Added for bug 5874653
2017 	AND ppa.payroll_action_id = paa.payroll_action_id
2018 	AND ppa.effective_date BETWEEN nvl(pad.date_from,ppa.effective_date) AND nvl(pad.date_to,ppa.effective_date)
2019 	-- end bug 5874653
2020 	AND paa.source_action_id IS NULL
2021 	AND paf.assignment_id = paa.assignment_id
2022 	--AND paf.primary_flag = 'Y'
2023 	AND ppf.person_id = paf.person_id
2024 	AND pad.person_id(+) = paf.person_id
2025 	AND NVL (pad.primary_flag, 'Y') = 'Y'
2026 	AND paf.effective_end_date =
2027 		    (SELECT MAX (asg.effective_end_date)
2028 			 FROM per_assignments_f asg
2029 			WHERE asg.assignment_id = paf.assignment_id
2030 			  AND asg.effective_start_date <= l_end_date
2031 			  AND asg.effective_end_date >= l_start_date)
2032 	AND ppf.effective_end_date =
2033 		    (SELECT MAX (per.effective_end_date)
2034 			 FROM per_people_f per
2035 			WHERE per.person_id = ppf.person_id
2036 			  AND per.effective_start_date <= l_end_date
2037 			  AND per.effective_end_date >= l_start_date)
2038 	AND paf.period_of_service_id = pps.period_of_service_id
2039 	AND paf.person_id = pps.person_id
2040 	AND papf.payroll_id = paf.payroll_id
2041 	AND papf.effective_end_date =
2042 		    (SELECT MAX (papf1.effective_end_date)
2043 			 FROM pay_all_payrolls_f papf1
2044 			WHERE papf1.payroll_id = papf.payroll_id
2045 			  AND papf1.effective_start_date <= l_end_date
2046 			  AND papf1.effective_end_date >= l_start_date);
2047 
2048 /* cursor for payroll run results data */
2049       CURSOR csr_run_results_found (p_locked_action NUMBER,
2050                                     p_dimension_name VARCHAR2,  --6633719 3new pmtr added
2051                                     p_context_id number,
2052                                     p_context_value pay_action_contexts.CONTEXT_VALUE%type )
2053       IS
2054          SELECT NVL (SUBSTR (ppf.national_identifier, 1, 9), ' '), --PPSN
2055 	          -- for bug 5301598, increased the size to 12
2056                 NVL (SUBSTR (paf.assignment_number, 1, 12), ' '), -- WORKS NUMBER
2057                 paf.person_id, -- FOR CALCULATION
2058                 paf.primary_flag,    -- changes made
2059 		paf.location_id, -- 10277535
2060 		paf.organization_id, --11674153
2061 		    paa.assignment_id, -- FOR CALCULATION
2062 		    paa.assignment_action_id, -- FOR CALCULATION
2063 		    DECODE (
2064                    SIGN (
2065                       NVL (
2066                          pay_balance_pkg.get_value (
2067                             pay_ie_p35.get_defined_balance_id (
2068                                p_dimension_name,  --'_PER_PAYE_REF_YTD', -- changes made--6633719
2069                                'IE Net Tax'
2070                             ),
2071                             paa.assignment_action_id,
2072                                 l_segment4, -- paye reference value
2073 					  null,
2074 					   p_context_id,  --null,
2075 					   p_context_value, --null,
2076 					   null,
2077 					   null,
2078 					   null,
2079 					   'TRUE'
2080                          ),
2081                          0
2082                       )
2083                    ),
2084                    -1, '1',
2085                    1, '0',
2086                    '0'
2087                 ),  --TAX_OR_REFUND
2088 		/*Bug 4154171*/
2089              /*   DECODE (
2090                    payef.tax_basis,
2091                    'IE_EMERGENCY', '2',
2092                    NULL, '2',
2093                    DECODE (payef.info_source, 'IE_P45', '1', '0')
2094                 ), --TAX_DEDUCTION_BASIS*/
2095 
2096                 TRIM (RPAD (ppf.last_name, 20)), --SURNAME
2097 		    /*Bug 4560952*/
2098                 NVL (TRIM (RPAD (ppf.first_name||' '||ppf.middle_names, 20)), ' '), --FIRST_NAME
2099                 TO_CHAR (ppf.date_of_birth, 'dd-mm-yyyy'), -- DOB
2100                 NVL (TRIM (RPAD (pad.address_line1, 30)), ' '), -- ADDRESS_LINE1
2101 		    NVL (TRIM  (pad.address_line2), ' '), -- ADDRESS_LINE2
2102                 NVL (TRIM (pad.address_line3), ' '), -- ADDRESS_LINE3
2103                 NVL (
2104                    TRIM (
2105                             hr_general.decode_lookup (
2106                                'IE_COUNTY',
2107                                TRIM (pad.region_1)
2108                             )
2109                       ||' '||
2110                             hr_general.decode_lookup (
2111                                'IE_POSTAL_CODE',
2112                                TRIM (pad.postal_code)
2113                             )
2114                    ),
2115                    ' '
2116                 ), -- ADDRESS_LINE4
2117 
2118                 TO_CHAR (pps.date_start, 'dd-mm-yyyy'), -- HIRE_DATE
2119                 DECODE (
2120                    TO_CHAR (
2121                       NVL (
2122                          pps.actual_termination_date,
2123                          TO_DATE ('31-12-4712', 'DD-MM-YYYY')
2124                       ),
2125                       'YYYY'
2126                    ),
2127                    TO_CHAR (l_end_date, 'YYYY'), TO_CHAR (
2128                                                     pps.actual_termination_date,
2129                                                     'dd-mm-yyyy'
2130                                                  ),
2131                    '31-12-4712'
2132                 ), -- TERM_DATE
2133                papf.period_type, --PERIOD_TYPE
2134 	       /*Bug 4154171*/
2135 	       /* TO_CHAR (
2136                    NVL (
2137                       DECODE (
2138                          papf.period_type,
2139                          'Lunar Month', ROUND (
2140                                            (payef.weekly_tax_credit * 52),
2141                                            2
2142                                         ),
2143                          DECODE (
2144                             INSTR (papf.period_type, 'Week'),
2145                             0, ROUND (
2146                                   (payef.monthly_tax_credit * 12),
2147                                   2
2148                                ),
2149                             ROUND (
2150                                (payef.weekly_tax_credit * 52),
2151                                2
2152                             )
2153                          )
2154                       ),
2155                       0
2156                    )
2157                 ), -- ANNUAL_TAX_CREDIT*/
2158 
2159                 NVL (TRIM (RPAD (ppf.per_information1, 30)), ' '), --  MOTHERS_NAME
2160                 DECODE (
2161                    SIGN (
2162                       pay_balance_pkg.get_value (
2163                             pay_ie_p35.get_defined_balance_id (
2164                                p_dimension_name,  ---'_PER_PAYE_REF_YTD', -- changes made--6633719
2165                                'IE Net Tax'
2166                             ),
2167                             paa.assignment_action_id,
2168                             l_segment4, -- paye reference value
2169 				    null,
2170 				    p_context_id,  --null,
2171 				    p_context_value,  --null,
2172 				    null,
2173 				    null,
2174 				    null,
2175 				    'TRUE'
2176                          )
2177                    ),
2178                    -1, 'H9',
2179                    1, 'J7'
2180                 ), --Q1_PR_Indicator
2181                 NVL (
2182                    ROUND (
2183                       TO_NUMBER (
2184                          pay_balance_pkg.get_value (
2185                             pay_ie_p35.get_defined_balance_id (
2186                                '_ASG_YTD',
2187                                'IE P45 Pay'
2188                             ),
2189                             p_locked_action
2190                          )
2191                       ),
2192                       2
2193                    ),
2194                    0
2195                 ), -- Q1_Previous_Emp_Pay
2196                 NVL (
2197                    ROUND (
2198                       TO_NUMBER (
2199                          pay_balance_pkg.get_value (
2200                             pay_ie_p35.get_defined_balance_id (
2201                                '_ASG_YTD',
2202                                'IE P45 Tax Deducted'
2203                             ),
2204                             p_locked_action
2205                          )
2206                       ),
2207                       2
2208                    ),
2209                    0
2210                 ) -- Q1_Previous_Emp_Tax
2211 --14659262
2212                 ,NVL (
2213                    ROUND (
2214                       TO_NUMBER (
2215                          pay_balance_pkg.get_value (
2216                             pay_ie_p35.get_defined_balance_id (
2217                                '_ASG_YTD',
2218                                'IE P45 USC Pay'
2219                             ),
2220                             p_locked_action
2221                          )
2222                       ),
2223                       2
2224                    ),
2225                    0
2226                 ) -- Q1_Previous_Emp_Pay_USC
2227                 ,NVL (
2228                    ROUND (
2229                       TO_NUMBER (
2230                          pay_balance_pkg.get_value (
2231                             pay_ie_p35.get_defined_balance_id (
2232                                '_ASG_YTD',
2233                                'IE P45 USC Deducted'
2234                             ),
2235                             p_locked_action
2236                          )
2237                       ),
2238                       2
2239                    ),
2240                    0
2241                 ) -- Q1_Previous_Emp_USC
2242 --14659262
2243            FROM pay_assignment_actions paa,
2244                 per_people_f ppf,
2245                 per_periods_of_service pps,
2246                 per_assignments_f paf,
2247                 per_addresses pad,
2248                -- pay_ie_paye_details_f payef,
2249                 pay_all_payrolls_f papf,
2250 		    pay_payroll_actions ppa
2251           WHERE paa.assignment_action_id = p_locked_action
2252 	      -- Added for bug 5874653
2253 		AND ppa.payroll_action_id = paa.payroll_action_id
2254 		AND ppa.effective_date BETWEEN nvl(pad.date_from,ppa.effective_date) AND nvl(pad.date_to,ppa.effective_date)
2255 		-- end bug 5874653
2256             AND paf.assignment_id = paa.assignment_id
2257             --AND paf.primary_flag = 'Y'
2258             AND ppf.person_id = paf.person_id
2259             AND pad.person_id(+) = paf.person_id
2260             AND NVL (pad.primary_flag, 'Y') = 'Y'
2261             AND paf.effective_end_date =
2262                       (SELECT MAX (asg.effective_end_date)
2263                          FROM per_assignments_f asg
2264                         WHERE asg.assignment_id = paf.assignment_id
2265                           AND asg.effective_start_date <= l_end_date
2266                           AND asg.effective_end_date >= l_start_date)
2267             AND ppf.effective_end_date =
2268                       (SELECT MAX (per.effective_end_date)
2269                          FROM per_people_f per
2270                         WHERE per.person_id = ppf.person_id
2271                           AND per.effective_start_date <= l_end_date
2272                           AND per.effective_end_date >= l_start_date)
2273             AND paf.period_of_service_id = pps.period_of_service_id
2274             AND paf.person_id = pps.person_id
2275            /* AND payef.assignment_id(+) = paa.assignment_id
2276             AND (   payef.effective_end_date =
2277                           (SELECT MAX (paye.effective_end_date)
2278                              FROM pay_ie_paye_details_f paye
2279                             WHERE paye.assignment_id = paf.assignment_id
2280                               AND paye.effective_start_date <= l_end_date
2281                               AND paye.effective_end_date >= l_start_date)
2282                  OR payef.effective_end_date IS NULL
2283                 )*/
2284             AND papf.payroll_id = paf.payroll_id
2285             AND papf.effective_end_date =
2286                       (SELECT MAX (papf1.effective_end_date)
2287                          FROM pay_all_payrolls_f papf1
2288                         WHERE papf1.payroll_id = papf.payroll_id
2289                           AND papf1.effective_start_date <= l_end_date
2290                           AND papf1.effective_end_date >= l_start_date);
2291 
2292 
2293  /* Bug 4049920*/
2294 CURSOR csr_annual_tax_credit(p_assignment_id NUMBER, p_term_date DATE) IS
2295 SELECT  DECODE (
2296 		 paye.tax_basis,
2297 		 'IE_WEEK1_MONTH1' , '1',		--7710479
2298 		 'IE_EXEMPT_WEEK_MONTH' , '1',	--7710479
2299 		 'IE_EMERGENCY', '2',
2300 		 'IE_EXCLUDE', '3',                 --12382953
2301 		 'IE_CUMULATIVE', '0',              --10234322
2302 		 NULL, '2',
2303 		 DECODE (paye.info_source, 'IE_P45', '1', '0')
2304 	    ), --TAX_DEDUCTION_BASIS
2305      NVL ( DECODE (
2306 			 ptp.period_type,
2307 			 'Lunar Month', ROUND (
2308 						 (paye.weekly_tax_credit * 52),
2309 						 2
2310 					    ),
2311 			 DECODE (
2312 			    INSTR (ptp.period_type, 'Week'),
2313 			    0, ROUND (
2314 				    (paye.monthly_tax_credit * 12),
2315 				    2
2316 				 ),
2317 			    ROUND (
2318 				 (paye.weekly_tax_credit * 52),
2319 				 2
2320 			    )
2321 			 )
2322 		    ),
2323 		    0)    --Bug 4111753
2324 /*( NVL(paye.weekly_tax_credit,0) +
2325 	  NVL(paye.Monthly_tax_credit,0)) * ptp.period_num */
2326 FROM   per_assignments_f paf,
2327 	 per_time_periods ptp,
2328 	 pay_ie_paye_details_f paye
2329 WHERE  paf.assignment_id = p_assignment_id
2330 AND    paye.assignment_id=paf.assignment_id
2331 AND    p_term_date between paf.effective_start_date
2332 			 and paf.effective_end_date
2333 -- Bug 6774415 changed effective date to certificate date
2334 AND    p_term_date between paye.certificate_start_date
2335 			 and NVL(paye.certificate_end_date,to_date('31/12/4712','DD/MM/YYYY'))
2336 AND    paf.payroll_id = ptp.payroll_id
2337 AND    p_term_date between ptp.start_date and ptp.end_date
2338 -- Bug 6774415 order by eff date to handle overlapping certificates
2339 ORDER BY paye.effective_start_date DESC;
2340 
2341  /*Bug 4154171*/
2342  /*Cursor to fetch paye details for non terminated employees*/
2343  CURSOR csr_paye_details(p_assignment_id  NUMBER, p_period_type VARCHAR2)
2344  IS
2345  SELECT DECODE (
2346                    payef.tax_basis,
2347 			'IE_WEEK1_MONTH1' , '1',		--7710479
2348 			'IE_EXEMPT_WEEK_MONTH' , '1',		--7710479
2349                    'IE_EMERGENCY', '2',
2350 			 'IE_EXCLUDE', '3',                 --12382953
2351 			 'IE_CUMULATIVE', '0',              --10234322
2352                    NULL, '2',
2353                    DECODE (payef.info_source, 'IE_P45', '1', '0')
2354                 ), --TAX_DEDUCTION_BASIS
2355 	 TO_CHAR (
2356                    NVL (
2357                       DECODE (
2358                          p_period_type,
2359                          'Lunar Month', ROUND (
2360                                            (payef.weekly_tax_credit * 52),
2361                                            2
2362                                         ),
2363                          DECODE (
2364                             INSTR (p_period_type, 'Week'),
2365                             0, ROUND (
2366                                   (payef.monthly_tax_credit * 12),
2367                                   2
2368                                ),
2369                             ROUND (
2370                                (payef.weekly_tax_credit * 52),
2371                                2
2372                             )
2373                          )
2374                       ),
2375                       0
2376                    )
2377                 ) -- ANNUAL_TAX_CREDIT
2378    FROM	  pay_ie_paye_details_f payef
2379    WHERE  payef.assignment_id=p_assignment_id
2380 -- Bug 6774415 changed effective date to certificate date
2381    AND payef.certificate_start_date <= l_end_date
2382    AND NVL(payef.certificate_end_date,to_date('31/12/4712','DD/MM/YYYY')) >= l_start_date
2383    ORDER BY payef.effective_end_date desc;
2384 
2385 CURSOR get_assignment_id is
2386 	select payroll_action_id,assignment_id,chunk_number
2387 	from  pay_assignment_actions
2388 	where assignment_action_id = p_assactid;
2389 
2390 /*** Cursors for Previous employment balances */
2391 CURSOR c_get_periods_of_service(v_person_id NUMBER,
2392 					  v_assignment_id NUMBER) IS
2393 	/*SELECT period_of_service_id
2394 	FROM   per_periods_of_service pps
2395 	WHERE  person_id = v_person_id
2396 	AND    actual_termination_date is not NULL
2397 	AND    actual_termination_date between l_start_date
2398 					   and l_end_date
2399 	ORDER BY  actual_termination_date desc;   */
2400 SELECT max(pps.period_of_service_id)
2401 	FROM   per_periods_of_service pps
2402 	      ,per_assignments_f asg
2403 	      ,pay_all_payrolls_f pay
2404 	      ,hr_soft_coding_keyflex flex
2405 	WHERE  pps.person_id = v_person_id
2406 	AND    pps.person_id = asg.person_id
2407 	AND    asg.period_of_service_id <> pps.period_of_service_id
2408 	AND    asg.assignment_id = v_assignment_id
2409 	AND    asg.payroll_id = pay.payroll_id
2410 	AND    pay.soft_coding_keyflex_id = flex.soft_coding_keyflex_id
2411 	AND    flex.segment4 = l_segment4
2412 	AND    actual_termination_date IS NOT NULL
2413 	AND    actual_termination_date BETWEEN l_start_date
2414 					   AND l_end_date;
2415 
2416 /*CURSOR c_get_terminated_asg(p_pds_id NUMBER) IS
2417 	SELECT assignment_id
2418 	FROM   per_assignments_f
2419 	WHERE  period_of_service_id = p_pds_id
2420 	AND    primary_flag = 'Y';*/
2421 
2422 /*
2423 CURSOR c_get_max_aact(p_pds_id NUMBER) IS
2424 	SELECT max(paa.assignment_action_id)
2425 	FROM   pay_assignment_Actions paa,
2426 	       pay_payroll_actions ppa
2427 	--       ,per_time_periods ptp    -- removed to improve performance 4771780
2428 	WHERE  paa.assignment_id in (SELECT assignment_id
2429 						FROM   per_assignments_f
2430 						WHERE  period_of_service_id = p_pds_id)
2431 	AND    paa.payroll_action_id = ppa.payroll_action_id
2432 	AND    ppa.action_type IN ('R','Q','I','B','V')
2433 	AND    paa.action_status = 'C' */
2434 	/* Impact of time period */
2435 	--	AND    ptp.time_period_id = ppa.time_period_id
2436       --  Removed ptp to improve the performance 4771780
2437       --  AND    ppa.payroll_id  = ptp.payroll_id
2438       --  AND    ppa.date_earned between ptp.start_date and ptp.end_date
2439       --  AND    ptp.end_Date BETWEEN l_start_date
2440       --			 AND l_end_date
2441 
2442 
2443       CURSOR c_get_max_aact(p_pds_id NUMBER,
2444                        c_ppsn varchar2,
2445 		       c_person_id NUMBER) IS
2446 	SELECT fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||
2447                paa.assignment_action_id),16))
2448 	FROM   pay_assignment_Actions paa,
2449 	       pay_payroll_actions ppa
2450 
2451 	WHERE ( (c_ppsn is null and paa.assignment_id in (SELECT paf.assignment_id
2452 						FROM   per_assignments_f paf
2453 						WHERE  paf.period_of_service_id = p_pds_id
2454 						  AND  paf.person_id=c_person_id))
2455                OR
2456                (c_ppsn is not null and paa.assignment_id in (SELECT paf.assignment_id
2457 						FROM   per_assignments_f paf, per_assignment_extra_info paei
2458 						WHERE  paf.period_of_service_id = p_pds_id
2459 						  AND  paf.person_id=c_person_id
2460 						  AND  paf.assignment_id=paei.assignment_id
2461 						  AND  paei.information_type = 'IE_ASG_OVERRIDE'
2462 						  AND  paei.aei_information1 = c_ppsn
2463 						  ))
2464 
2465              )
2466 	AND    paa.payroll_action_id = ppa.payroll_action_id
2467 	AND    ppa.action_type IN ('R','Q','I','B','V')
2468 	AND    paa.action_status IN ('C','S') --10225372
2469         AND paa.source_action_id is null
2470 	  AND    ppa.effective_date between l_start_date and l_end_date;
2471 
2472 	  /**  End Cursors for Previous employment balances **/
2473 
2474 /* Cursor to fetch primary flag for terminated assignments*/
2475 CURSOR csr_get_primary_flag(p_action_id number) is
2476       -- for bug 5301598, increased the size to 12
2477 	select NVL (SUBSTR (paf.assignment_number, 1, 12), ' '), -- WORKS NUMBER
2478 		 paf.primary_flag,
2479 		 paf.assignment_id
2480 	from per_assignments_f paf,
2481 	     pay_assignment_actions paa
2482 	where paf.assignment_id = paa.assignment_id
2483 	and   paa.assignment_action_id = p_action_id
2484 	and paf.effective_start_date <= l_end_date
2485 	and paf.effective_end_date   >= l_start_date;
2486 
2487 
2488 /* Cursor to fetch primary flag for active assignments*/
2489 CURSOR csr_get_primary_flag_active(p_action_id number) is
2490       -- for bug 5301598, increased the size to 12
2491 	select NVL (SUBSTR (paf.assignment_number, 1, 12), ' '), -- WORKS NUMBER
2492 		 paf.primary_flag,
2493 		 paf.assignment_id,
2494 		 max(effective_end_date) end_date
2495 	from per_assignments_f paf,
2496 	     pay_assignment_actions paa
2497 	where paf.assignment_id = paa.assignment_id
2498 	and   paa.assignment_action_id = p_action_id
2499 	and paf.effective_start_date <= l_end_date
2500 	and paf.effective_end_date   >= l_start_date
2501 	group by NVL (SUBSTR (paf.assignment_number, 1, 12), ' '), paf.primary_flag, paf.assignment_id
2502 	having max(effective_end_date) >= l_end_date;
2503 
2504 --6633719
2505 /* Cursor to fetch primary flag for terminated assignments for PPSN OVERRIDE case*/
2506 CURSOR csr_get_primary_flag1(p_ppsn_override varchar2) is
2507 	select NVL (SUBSTR (paf.assignment_number, 1, 12), ' ') -- WORKS NUMBER
2508 	from per_assignments_f paf, per_assignment_extra_info paei
2509 	where paf.assignment_id = paei.assignment_id
2510 	and aei_information1 = p_ppsn_override
2511     and paf.effective_start_date <= l_end_date
2512 	and paf.effective_end_date   >= l_start_date
2513 	and primary_flag = 'Y'
2514 	group by NVL (SUBSTR (paf.assignment_number, 1, 12), ' ');
2515 
2516 /* Cursor to fetch primary flag for active assignments PPSN OVERRIDE case*/
2517 CURSOR csr_get_primary_flag_active1(p_ppsn_override varchar2) is
2518 	select NVL (SUBSTR (paf.assignment_number, 1, 12), ' ') -- WORKS NUMBER
2519 	from per_assignments_f paf,
2520 	     per_assignment_extra_info paei
2521 	where paf.assignment_id = paei.assignment_id
2522     and aei_information1 = p_ppsn_override
2523 	and paf.effective_start_date <= l_end_date
2524 	and paf.effective_end_date   >= l_start_date
2525 	and primary_flag = 'Y'
2526 	group by NVL (SUBSTR (paf.assignment_number, 1, 12), ' ')
2527 	having max(effective_end_date) >= l_end_date;
2528 
2529 --6633719
2530 
2531 cnt			number;
2532 v_action_type	pay_payroll_actions.action_type%TYPE;
2533 v_report_type	pay_payroll_actions.report_type%TYPE;
2534 v_work_number	per_assignments_f.assignment_number%TYPE;
2535 v_assignment_id	pay_assignment_actions.assignment_id%TYPE;
2536 v_action_id		pay_assignment_actions.assignment_action_id%TYPE;
2537 v_payroll_action_id pay_payroll_actions.payroll_action_id%TYPE;
2538 v_chunk		pay_assignment_actions.chunk_number%TYPE;
2539 l_max_assignment_id per_assignments_f.assignment_id%TYPE;
2540 v_date		date;
2541 asg_assignment_id	per_assignments_f.assignment_id%TYPE;
2542 l_max_action_id	pay_assignment_actions.assignment_action_id%TYPE;
2543 l_cnt		number;
2544 l_pl_cnt    number; --8259095
2545 -- for P60 enhancement.
2546 l_prev_pay		pay_action_information.action_information4%TYPE;
2547 l_this_pay		pay_action_information.action_information4%TYPE;
2548 l_this_pay_usc		pay_action_information.action_information4%TYPE;  --14659262
2549 l_prev_tax		pay_action_information.action_information4%TYPE;
2550 l_this_tax		pay_action_information.action_information4%TYPE;
2551 l_this_usc		pay_action_information.action_information4%TYPE;  --14659262
2552 l_temp_pay		pay_action_information.action_information4%TYPE;
2553 l_temp_tax		pay_action_information.action_information4%TYPE;
2554 
2555 -- end P60
2556 -- For P60 changes to PRSI section
2557 l_this_insurable_weeks	pay_run_result_values.result_value%TYPE;
2558 l_this_emp_prsi_cont	pay_run_result_values.result_value%TYPE;
2559 l_this_tot_prsi		pay_run_result_values.result_value%TYPE;
2560 l_this_initial_class	pay_run_result_values.result_value%TYPE;
2561 l_this_sec_class		pay_run_result_values.result_value%TYPE;
2562 l_this_weeks_at_sec_class	pay_run_result_values.result_value%TYPE;
2563 -- end P60 changes to PRSI section
2564 
2565 --6633719
2566 l_ppsn_override per_assignment_extra_info.aei_information1%type;
2567 
2568 cursor csr_ppsn_override(p_asg_id number)
2569 is
2570 select aei_information1 PPSN_OVERRIDE
2571 from per_assignment_extra_info
2572 where assignment_id = p_asg_id
2573 and aei_information_category = 'IE_ASG_OVERRIDE';
2574 
2575 l_child_assignment_action_id pay_assignment_actions.assignment_action_id%type;
2576 
2577 CURSOR csr_child_actions(p_asg_id number) IS
2578 SELECT paa.assignment_action_id child_assignment_action_id
2579        --,prt.run_method run_type
2580 FROM   pay_assignment_actions paa,
2581        pay_run_types_f prt
2582 WHERE  paa.run_type_id = prt.run_type_id
2583 AND    prt.run_method IN ('N','P')
2584 AND    p_effective_date BETWEEN prt.effective_start_date AND prt.effective_end_date
2585 AND    paa.assignment_action_id = (SELECT /*+ USE_NL(paa, ppa) */
2586 				          fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||
2587 				          paa.assignment_action_id),16)) child_assignment_action_id
2588 				   FROM   pay_assignment_actions paa,
2589 					  pay_payroll_actions    ppa
2590 				   WHERE  paa.assignment_id = p_asg_id
2591 				   AND    ppa.payroll_action_id = paa.payroll_action_id
2592 				   AND    (paa.source_action_id is not null or ppa.action_type in ('I','V'))
2593 				   AND    ppa.effective_date between trunc(p_effective_date,'Y') and p_effective_date
2594 				   AND    ppa.action_type in ('R', 'Q', 'I', 'V')
2595 				   AND    paa.action_status = 'C');
2596 
2597 
2598 CURSOR Cur_Act_Contexts(p_source_id number) IS
2599 SELECT pac.context_id, pac.context_value
2600 FROM pay_action_contexts pac, ff_contexts ffc
2601 WHERE pac.assignment_action_id = p_source_id
2602 AND ffc.context_name = 'SOURCE_TEXT'
2603 AND ffc.context_id = pac.context_id;
2604 
2605 l_Act_Context_id pay_action_contexts.context_id%type;
2606 l_Act_Context_value pay_action_contexts.context_value%type;
2607 
2608 --6633719
2609 
2610 --12382953
2611 
2612 CURSOR csr_min_max_asg_act_yr (p_assignment_id NUMBER) IS
2613 SELECT
2614  fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) asg_action_id_max
2615 ,fnd_number.canonical_to_number(substr(min(lpad(paa.action_sequence,15,'0')||paa.assignment_action_id),16)) asg_action_id_min
2616   FROM pay_assignment_actions paa,
2617 	 pay_payroll_actions ppa
2618  WHERE ppa.payroll_action_id = paa.payroll_action_id
2619    and paa.assignment_id = p_assignment_id
2620    and ppa.action_type in ('R','Q')
2621    and paa.source_action_id is null
2622    AND ppa.effective_date between l_start_date AND l_end_date;
2623 
2624 l_min_act_id pay_assignment_actions.assignment_action_id%TYPE;
2625 l_max_act_id pay_assignment_actions.assignment_action_id%TYPE;
2626 
2627 
2628 CURSOR csr_exclusion_flag (p_action_id_min NUMBER, p_action_id_max NUMBER, p_asg_id NUMBER) IS
2629 SELECT count(1) cnt
2630   FROM pay_run_result_values prrv,
2631        pay_run_results prr,
2632        pay_input_values_f pivf,
2633        pay_element_types_f pet,
2634        pay_assignment_actions paa,
2635 	 pay_payroll_actions ppa
2636  WHERE ppa.payroll_action_id= paa.payroll_action_id
2637    AND paa.assignment_id = p_asg_id
2638    AND ((paa.source_action_id between p_action_id_min AND p_action_id_max
2639    AND prr.assignment_action_id = paa.assignment_action_id )
2640       OR (paa.assignment_action_id between p_action_id_min AND p_action_id_max AND prr.assignment_action_id = paa.assignment_action_id ))
2641    AND prr.element_type_id = pet.element_type_id
2642    AND pet.element_name = 'IE PAYE details'
2643    AND prrv.run_result_id = prr.run_result_id
2644    AND prrv.input_value_id = pivf.input_value_id
2645    AND pivf.name = 'Tax Basis'
2646    and result_value = 'IE_EXCLUDE';
2647 
2648 l_excl_count NUMBER := 0;
2649 --12382953
2650 
2651 BEGIN
2652 	v_payroll_action_id := 0;
2653 	v_assignment_id	:= 0;
2654 	v_chunk		:= 0;
2655 	--6633719
2656       l_ppsn_override := NULL;
2657 	l_child_assignment_action_id := NULL;
2658 	l_Act_Context_id := NULL;
2659 	l_Act_Context_value := NULL;
2660     --6633719
2661     hr_utility.set_location('p_assactid ..'||p_assactid,1000);
2662     hr_utility.set_location('p_effective_date..'||p_effective_date,1000);
2663 
2664 
2665 	OPEN get_assignment_id;
2666 	FETCH get_assignment_id into v_payroll_action_id,v_assignment_id,v_chunk;
2667 	CLOSE get_assignment_id;
2668 
2669     hr_utility.set_location('v_payroll_action_id..'||v_payroll_action_id,1000);
2670     hr_utility.set_location('v_assignment_id..'||v_assignment_id,1000);
2671     hr_utility.set_location('v_chunk..'||v_chunk,1000);
2672 	--6633719
2673 	OPEN csr_ppsn_override(v_assignment_id);
2674 	FETCH csr_ppsn_override INTO l_ppsn_override;
2675 	CLOSE csr_ppsn_override;
2676     hr_utility.set_location('l_ppsn_override..'||l_ppsn_override,1000);
2677 
2678     IF l_ppsn_override IS NOT NULL THEN
2679         l_dimension_name := '_PER_PAYE_REF_PPSN_YTD';
2680     ELSE
2681         l_dimension_name := '_PER_PAYE_REF_YTD';
2682     END IF;
2683 
2684     hr_utility.set_location('l_dimension_name..'||l_dimension_name,1000);
2685 
2686 /* -- commented as new dimension ('_PER_PAYE_REF_PPSN_YTD') does not require contexes.
2687     IF l_ppsn_override IS NOT NULL THEN
2688 	OPEN csr_child_actions(v_assignment_id);
2689 	FETCH csr_child_actions INTO l_child_assignment_action_id;
2690 	CLOSE csr_child_actions;
2691     hr_utility.set_location('l_child_assignment_action_id..'||l_child_assignment_action_id,1000);
2692 
2693     IF l_child_assignment_action_id IS NOT NULL THEN
2694     OPEN Cur_Act_Contexts(l_child_assignment_action_id);
2695     FETCH Cur_Act_Contexts INTO l_Act_Context_id,l_Act_Context_value;
2696     CLOSE Cur_Act_Contexts;
2697     hr_utility.set_location('l_Act_Context_id..'||l_Act_Context_id,1000);
2698     hr_utility.set_location('l_Act_Context_value..'||l_Act_Context_value,1000);
2699     END IF;
2700 
2701     END IF;
2702 */
2703 	--6633719
2704 
2705 	l_out_var :=
2706             pay_ie_p35.get_parameter (
2707                p_payroll_action_id=> v_payroll_action_id,
2708                p_token_name=> 'END_DATE'
2709             );
2710       l_end_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
2711       l_out_var :=
2712             pay_ie_p35.get_parameter (
2713                p_payroll_action_id=> v_payroll_action_id,
2714                p_token_name=> 'START_DATE'
2715             );
2716       l_start_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
2717       l_out_var :=
2718             pay_ie_p35.get_parameter (
2719                p_payroll_action_id=> v_payroll_action_id,
2720                p_token_name=> 'BG_ID'
2721             );
2722       l_bg_id := TO_NUMBER (l_out_var);
2723 
2724 	l_segment4 := pay_ie_p35.get_parameter( p_payroll_action_id=> v_payroll_action_id,
2725 							    p_token_name=> 'EMP_NO');
2726 	l_out_var := pay_ie_p35.get_parameter (
2727 			    p_payroll_action_id=> v_payroll_action_id,
2728 			    p_token_name=> 'ASSIGNMENT_SET_ID'
2729 			 );
2730 	l_assignment_set_id := to_number(l_out_var);
2731 
2732 	l_out_var := pay_ie_p35.get_parameter (
2733 			    p_payroll_action_id=> v_payroll_action_id,
2734 			    p_token_name=> 'PAYROLL'
2735 			 );
2736 	l_payroll_id := to_number(l_out_var);
2737 
2738 --12382953
2739 l_max_act_id := 0;
2740 l_min_act_id := 0;
2741 l_excl_count := 0;
2742 l_exclusion_order := 0;
2743 
2744 OPEN csr_min_max_asg_act_yr(v_assignment_id);
2745 FETCH csr_min_max_asg_act_yr INTO l_max_act_id, l_min_act_id;
2746 CLOSE csr_min_max_asg_act_yr;
2747 
2748 OPEN csr_exclusion_flag(l_min_act_id, l_max_act_id, v_assignment_id );
2749 FETCH csr_exclusion_flag INTO l_excl_count;
2750 CLOSE csr_exclusion_flag;
2751 --12382953
2752 
2753 	cnt := 0;
2754 	-- Bug 3550403 : Flushing the variables for every assignment
2755 	l_arch_pay := '0';
2756 	l_arch_non_tax_pay := '0';
2757 	l_arch_net_tax := '0';
2758 	l_arch_employees_prsi_cont := '0';
2759 	l_temp_prsi_cont := '0';
2760 	l_arch_employer_prsi_cont := '0';
2761 	l_arch_total_prsi_cont := '0';
2762 	-- Tar 4061469.99 Flushing variables
2763 	l_arch_second_class := ' ';
2764 	l_arch_third_class := ' ';
2765 	l_arch_third_class := ' ';
2766 	l_arch_fourth_class := ' ';
2767 	l_arch_fifth_class := ' ';
2768 
2769 	l_arch_weeks_at_initial_class := 0;
2770 	l_arch_weeks_at_second_class := 0;
2771 	l_arch_weeks_at_third_class := 0;
2772 	l_arch_weeks_at_fourth_class := 0;
2773 	l_arch_weeks_at_fifth_class := 0;
2774 	/*Bug 4023751- Flushing the variables for every assignment*/
2775 	l_arch_ppsn:=' ';
2776 	l_arch_works_number:=' ';
2777 	l_arch_person_id:=null;
2778 	l_arch_assignment_id:=null;
2779 	l_max_assignment_id :=null;
2780 
2781 	l_arch_assmt_action_id_bal:=null;
2782 	l_arch_tax_or_refund:=0;
2783 	/*Bug 4154171*/
2784 	l_arch_tax_deduction_basis:='2';
2785 	l_period_type := null;
2786 
2787 	l_arch_surname:=null;
2788 	l_arch_first_name:=null;
2789 	l_arch_dob:=null;
2790 	l_arch_address_line1:=null;
2791 	l_arch_address_line2:=null;
2792 	l_arch_address_line3:=null;
2793 	l_arch_address_line4:=null; -- BUG 4066315
2794 	l_arch_hire_date:=null;
2795 	l_arch_term_date:=null;
2796 	l_arch_annual_tax_credit:=0;
2797 	l_arch_mothers_name:=null;
2798 	l_arch_pr_indicator:=null;
2799 	l_arch_previous_emp_pay:=0;
2800 	l_arch_previous_emp_pay_usc:=0; --14659262
2801 	l_arch_previous_emp_tax:=0;
2802 	l_arch_previous_emp_usc:=0;  --14659262
2803 	l_arch_total_notional_pay:=0;
2804 	l_arch_total_share_scheme:=0; --16306646
2805 	l_p35_taxable_pay_adjust:=0; --16306646
2806 	l_p35_gross_pay_adjust:=0; --16306646
2807 	-- pension balances
2808 	l_arch_pen_emp_rbs   := '0';
2809 	l_arch_pen_empr_rbs  := '0';
2810 	l_arch_pen_emp_prsa  := '0';
2811 	l_arch_pen_empr_prsa := '0';
2812 	l_arch_pen_emp_rac   := '0';
2813 
2814 	l_arch_gross_pay     := '0'; /* 8520684 */
2815 	l_arch_income_levy   := '0';
2816 	l_arch_income_levy_first  := '0';
2817 	l_arch_income_levy_second := '0';
2818 	l_arch_income_levy_third  := '0';
2819 	l_arch_illness_benefit := '0'; --14656910
2820 	l_arch_parking_levy  := '0';
2821 	l_temp_gross_pay     := '0';
2822 	l_temp_income_levy   := '0';
2823 
2824 --12382953
2825 	l_arch_gross_pay_usc := '0';
2826 	l_temp_gross_pay_usc := '0';
2827 	l_arch_usc        := '0';
2828 	l_arch_usc_first  := '0';
2829 	l_arch_usc_second := '0';
2830 	l_arch_usc_third  := '0';
2831 	l_temp_usc        := '0';
2832 --12382953
2833 
2834 
2835 	cnt := 0;
2836 	--hr_utility.trace_on(null,'P35');
2837 	hr_utility.set_location('In archive code..'||to_char(cnt),1001);
2838 	FOR csr_interlocks IN get_actid_from_interlocks
2839 	LOOP
2840 		v_action_id := csr_interlocks.locked_action_id;
2841 		hr_utility.set_location('csr_interlocks.locked_action_id ..'||csr_interlocks.locked_action_id,1002);
2842 
2843 
2844 		-- v_action_id is either prepay or P30 action id
2845 		OPEN get_action_type(csr_interlocks.locked_action_id);
2846 		FETCH get_action_type into v_action_id,v_action_type;
2847 		CLOSE get_action_type;
2848 
2849 			hr_utility.set_location('Inside the loop ..',1002);
2850 			hr_utility.set_location('Action Type ..'||v_action_type,1003);
2851 			hr_utility.set_location('v_action_id ..'||v_action_id,1003);
2852 --6633719
2853         IF l_ppsn_override IS NOT NULL THEN
2854          OPEN csr_rehire_ppsn_arch(v_action_id);
2855          FETCH csr_rehire_ppsn_arch INTO l_ppsn_bal_archived;
2856 --6633719QA
2857          IF csr_rehire_ppsn_arch%NOTFOUND
2858          THEN
2859          l_ppsn_bal_archived := 'N';
2860          END IF;
2861 --6633719QA
2862          CLOSE csr_rehire_ppsn_arch;
2863 
2864 		 hr_utility.set_location('l_ppsn_bal_archived ..'||l_ppsn_bal_archived,1004);
2865 		END IF;
2866 --6633719
2867 		IF cnt = 0 then
2868 		-- This part to executed only once for each locking action id to fetch balances for max assignment actionid
2869 		--
2870 			--l_actid := csr_interlocks.locking_action_id;
2871 			IF v_action_type = 'X' then
2872 
2873 				l_max_action_id := csr_interlocks.locked_action_id;
2874 
2875 			    hr_utility.set_location('l_max_action_id ..'||l_max_action_id,1005);
2876 			    hr_utility.set_location('Inside IEPS ..'||to_char(l_actid),1005);
2877 
2878 			    OPEN csr_p30_bal_value (v_action_id, 'IE TAXABLE PAY',l_dimension_name);
2879 			    FETCH csr_p30_bal_value INTO l_arch_pay;
2880 			--6633719 if condition added for the scenarios where employee is rehired
2881 			--and have different PPSN OVERRIDES and for terminated (previous assignments)
2882 			--the PPSN dimension balances not archived.
2883 			--e.g terminated in JUL and rehired in DEC with different PPSN OVERRIDE.
2884                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
2885 
2886 			        l_arch_pay :=
2887 				   TO_CHAR (
2888 					ROUND (
2889 					   NVL (
2890 						pay_balance_pkg.get_value (
2891 						   pay_ie_p35.get_defined_balance_id (
2892 							l_dimension_name,
2893 							'IE Taxable Pay'
2894 						   ),
2895 						   csr_interlocks.locked_action_id,
2896 						   l_segment4, -- paye reference value
2897 						    null,
2898 						    null,
2899 						    null,
2900 						    null,
2901 						    null,
2902 						    null,
2903 						    'TRUE'
2904 						),
2905 						0
2906 					   ),
2907 					   2
2908 					)
2909 				   );
2910 
2911                 hr_utility.set_location('l_arch_pay not archived ..'||l_arch_pay,1004);
2912 
2913 			     END IF;
2914 			--6633719
2915                 CLOSE csr_p30_bal_value;
2916 			    hr_utility.set_location('l_arch_pay..'||l_arch_pay,1005);
2917 
2918 			    OPEN csr_p30_bal_value (v_action_id, 'IE NET TAX',l_dimension_name);
2919 			    FETCH csr_p30_bal_value INTO l_arch_net_tax;
2920 			--6633719
2921                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
2922 
2923 			        l_arch_net_tax :=
2924 				   TO_CHAR (
2925 					ROUND (
2926 					   NVL (
2927 						pay_balance_pkg.get_value (
2928 						   pay_ie_p35.get_defined_balance_id (
2929 							l_dimension_name,
2930 							'IE Net Tax'
2931 						   ),
2932 						   csr_interlocks.locked_action_id,
2933 						   l_segment4, -- paye reference value
2934 						    null,
2935 						    null,
2936 						    null,
2937 						    null,
2938 						    null,
2939 						    null,
2940 						    'TRUE'
2941 						),
2942 						0
2943 					   ),
2944 					   2
2945 					)
2946 				   );
2947 
2948                 hr_utility.set_location('l_arch_net_tax not archived ..'||l_arch_net_tax,1004);
2949 
2950 			     END IF;
2951 			--6633719
2952                 CLOSE csr_p30_bal_value;
2953 			    hr_utility.set_location('l_arch_net_tax..'||l_arch_net_tax,1005);
2954 
2955 			    OPEN csr_p30_bal_value (v_action_id, 'IE PRSI EMPLOYEE',l_dimension_name);
2956 			    FETCH csr_p30_bal_value INTO l_arch_employees_prsi_cont;
2957 			--6633719
2958                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
2959 
2960 			        l_arch_employees_prsi_cont :=
2961 				   TO_CHAR (
2962 					ROUND (
2963 					   NVL (
2964 						pay_balance_pkg.get_value (
2965 						   pay_ie_p35.get_defined_balance_id (
2966 							l_dimension_name,
2967 							'IE PRSI Employee'
2968 						   ),
2969 						   csr_interlocks.locked_action_id,
2970 						   l_segment4, -- paye reference value
2971 						    null,
2972 						    null,
2973 						    null,
2974 						    null,
2975 						    null,
2976 						    null,
2977 						    'TRUE'
2978 						),
2979 						0
2980 					   ),
2981 					   2
2982 					)
2983 				   );
2984 
2985                 hr_utility.set_location('l_arch_employees_prsi_cont not archived ..'||l_arch_employees_prsi_cont,1004);
2986 
2987 			     END IF;
2988 			--6633719
2989                 CLOSE csr_p30_bal_value;
2990 			    hr_utility.set_location('l_arch_employees_prsi_cont..'||l_arch_employees_prsi_cont,1005);
2991 
2992 			    --Bug 4553755
2993 			    /*OPEN csr_p30_bal_value (v_action_id, 'IE BIK TAXABLE AND PRSIABLE PAY');
2994 			    FETCH csr_p30_bal_value INTO l_arch_total_notional_pay;
2995 			    CLOSE csr_p30_bal_value;*/
2996 
2997 			    -- Added K and M Employee figures in case of severance payment
2998 			    OPEN csr_p30_bal_value (v_action_id,'IE PRSI K EMPLOYEE LUMP SUM',l_dimension_name);
2999 			    FETCH csr_p30_bal_value INTO l_temp_prsi_cont;
3000 			--6633719
3001                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3002 
3003 			        l_temp_prsi_cont :=
3004 				   TO_CHAR (
3005 					ROUND (
3006 					   NVL (
3007 						pay_balance_pkg.get_value (
3008 						   pay_ie_p35.get_defined_balance_id (
3009 							l_dimension_name,
3010 							'IE PRSI K Employee Lump Sum'
3011 						   ),
3012 						   csr_interlocks.locked_action_id,
3013 						   l_segment4, -- paye reference value
3014 						    null,
3015 						    null,
3016 						    null,
3017 						    null,
3018 						    null,
3019 						    null,
3020 						    'TRUE'
3021 						),
3022 						0
3023 					   ),
3024 					   2
3025 					)
3026 				   );
3027 
3028                 hr_utility.set_location('l_temp_prsi_cont not archived ..'||l_temp_prsi_cont,1004);
3029 
3030 			     END IF;
3031 			--6633719
3032 			    CLOSE csr_p30_bal_value;
3033 			    hr_utility.set_location('IE PRSI K EMPLOYEE LUMP SUM l_temp_prsi_cont..'||l_temp_prsi_cont,1005);
3034 
3035 			    l_arch_employees_prsi_cont :=
3036 				  TO_CHAR (
3037 					 TO_NUMBER (l_arch_employees_prsi_cont)
3038 				     + TO_NUMBER (NVL (l_temp_prsi_cont, '0'))
3039 				  );
3040 			    l_temp_prsi_cont := NULL;
3041 hr_utility.set_location('IE PRSI K EMPLOYEE LUMP SUM l_arch_employees_prsi_cont..'||l_arch_employees_prsi_cont,1005);
3042 
3043                 OPEN csr_p30_bal_value (v_action_id,'IE PRSI M EMPLOYEE LUMP SUM',l_dimension_name);
3044 			    FETCH csr_p30_bal_value INTO l_temp_prsi_cont;
3045 			--6633719
3046                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3047 
3048 			        l_temp_prsi_cont :=
3049 				   TO_CHAR (
3050 					ROUND (
3051 					   NVL (
3052 						pay_balance_pkg.get_value (
3053 						   pay_ie_p35.get_defined_balance_id (
3054 							l_dimension_name,
3055 							'IE PRSI M Employee Lump Sum'
3056 						   ),
3057 						   csr_interlocks.locked_action_id,
3058 						   l_segment4, -- paye reference value
3059 						    null,
3060 						    null,
3061 						    null,
3062 						    null,
3063 						    null,
3064 						    null,
3065 						    'TRUE'
3066 						),
3067 						0
3068 					   ),
3069 					   2
3070 					)
3071 				   );
3072 
3073                 hr_utility.set_location('l_temp_prsi_cont not archived ..'||l_temp_prsi_cont,1004);
3074 
3075 			     END IF;
3076 			--6633719
3077                 CLOSE csr_p30_bal_value;
3078 			    hr_utility.set_location('IE PRSI M EMPLOYEE LUMP SUM l_temp_prsi_cont..'||l_temp_prsi_cont,1005);
3079 
3080                 l_arch_employees_prsi_cont :=
3081 				  TO_CHAR (
3082 					 TO_NUMBER (l_arch_employees_prsi_cont)
3083 				     + TO_NUMBER (NVL (l_temp_prsi_cont, '0'))
3084 				  );
3085 			    l_temp_prsi_cont := NULL;
3086 hr_utility.set_location('E PRSI M EMPLOYEE LUMP SUM l_arch_employees_prsi_cont..'||l_arch_employees_prsi_cont,1005);
3087 
3088 			    OPEN csr_p30_bal_value (v_action_id, 'IE PRSI EMPLOYER',l_dimension_name);
3089 			    FETCH csr_p30_bal_value INTO l_arch_employer_prsi_cont;
3090 			--6633719
3091                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3092 
3093 			        l_arch_employer_prsi_cont :=
3094 				   TO_CHAR (
3095 					ROUND (
3096 					   NVL (
3097 						pay_balance_pkg.get_value (
3098 						   pay_ie_p35.get_defined_balance_id (
3099 							l_dimension_name,
3100 							'IE PRSI Employer'
3101 						   ),
3102 						   csr_interlocks.locked_action_id,
3103 						   l_segment4, -- paye reference value
3104 						    null,
3105 						    null,
3106 						    null,
3107 						    null,
3108 						    null,
3109 						    null,
3110 						    'TRUE'
3111 						),
3112 						0
3113 					   ),
3114 					   2
3115 					)
3116 				   );
3117 
3118                 hr_utility.set_location('l_arch_employer_prsi_cont not archived ..'||l_arch_employer_prsi_cont,1004);
3119 
3120 			     END IF;
3121 			--6633719
3122 			    CLOSE csr_p30_bal_value;
3123 			    hr_utility.set_location('IE PRSI EMPLOYER l_arch_employer_prsi_cont..'||l_arch_employer_prsi_cont,1005);
3124 
3125 		-- Added K and M Employer figuresin case of severance payment
3126 			    OPEN csr_p30_bal_value (v_action_id,'IE PRSI K EMPLOYER LUMP SUM',l_dimension_name);
3127 			    FETCH csr_p30_bal_value INTO l_temp_prsi_cont;
3128 			--6633719
3129                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3130 
3131 			        l_temp_prsi_cont :=
3132 				   TO_CHAR (
3133 					ROUND (
3134 					   NVL (
3135 						pay_balance_pkg.get_value (
3136 						   pay_ie_p35.get_defined_balance_id (
3137 							l_dimension_name,
3138 							'IE PRSI K Employer Lump Sum'
3139 						   ),
3140 						   csr_interlocks.locked_action_id,
3141 						   l_segment4, -- paye reference value
3142 						    null,
3143 						    null,
3144 						    null,
3145 						    null,
3146 						    null,
3147 						    null,
3148 						    'TRUE'
3149 						),
3150 						0
3151 					   ),
3152 					   2
3153 					)
3154 				   );
3155 
3156                 hr_utility.set_location('l_temp_prsi_cont not archived ..'||l_temp_prsi_cont,1004);
3157 
3158 			     END IF;
3159 			--6633719
3160 			    CLOSE csr_p30_bal_value;
3161 			    hr_utility.set_location('IE PRSI K EMPLOYER LUMP SUM l_temp_prsi_cont..'||l_temp_prsi_cont,1005);
3162 
3163                 l_arch_employer_prsi_cont :=
3164 				  TO_CHAR (
3165 					 TO_NUMBER (l_arch_employer_prsi_cont)
3166 				     + TO_NUMBER (NVL (l_temp_prsi_cont, '0'))
3167 				  );
3168 			    l_temp_prsi_cont := NULL;
3169 			    hr_utility.set_location('IE PRSI K EMPLOYER LUMP SUM l_arch_employer_prsi_cont..'||l_arch_employer_prsi_cont,1005);
3170 
3171                 OPEN csr_p30_bal_value (v_action_id,'IE PRSI M EMPLOYER LUMP SUM',l_dimension_name);
3172 			    FETCH csr_p30_bal_value INTO l_temp_prsi_cont;
3173 			--6633719
3174                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3175 
3176 			        l_temp_prsi_cont :=
3177 				   TO_CHAR (
3178 					ROUND (
3179 					   NVL (
3180 						pay_balance_pkg.get_value (
3181 						   pay_ie_p35.get_defined_balance_id (
3182 							l_dimension_name,
3183 							'IE PRSI M Employer Lump Sum'
3184 						   ),
3185 						   csr_interlocks.locked_action_id,
3186 						   l_segment4, -- paye reference value
3187 						    null,
3188 						    null,
3189 						    null,
3190 						    null,
3191 						    null,
3192 						    null,
3193 						    'TRUE'
3194 						),
3195 						0
3196 					   ),
3197 					   2
3198 					)
3199 				   );
3200 
3201                 hr_utility.set_location('l_temp_prsi_cont not archived ..'||l_temp_prsi_cont,1004);
3202 
3203 			     END IF;
3204 			--6633719
3205                 CLOSE csr_p30_bal_value;
3206 			    hr_utility.set_location('IE PRSI M EMPLOYER LUMP SUM l_temp_prsi_cont..'||l_temp_prsi_cont,1005);
3207 
3208                 l_arch_employer_prsi_cont :=
3209 				  TO_CHAR (
3210 					 TO_NUMBER (l_arch_employer_prsi_cont)
3211 				     + TO_NUMBER (NVL (l_temp_prsi_cont, '0'))
3212 				  );
3213 			    l_temp_prsi_cont := NULL;
3214 			    l_arch_total_prsi_cont :=
3215 				  TO_CHAR (
3216 					 TO_NUMBER (NVL (l_arch_employees_prsi_cont, 0))
3217 				     + TO_NUMBER (NVL (l_arch_employer_prsi_cont, 0))
3218 				  );
3219 			    hr_utility.set_location('l_arch_total_prsi_cont..'||l_arch_total_prsi_cont,1005);
3220                        --Bug 4553755
3221    -- Passed Payroll Run assignment action id csr_interlocks.locked_action_id 4672715
3222 
3223 			     l_arch_total_notional_pay :=
3224 				   TO_CHAR (
3225 					ROUND (
3226 					   NVL (
3227 						pay_balance_pkg.get_value (
3228 						   pay_ie_p35.get_defined_balance_id (
3229 							l_dimension_name, --'_PER_PAYE_REF_YTD',--6633719
3230 							'IE BIK Taxable and PRSIable Pay'
3231 						   ),
3232 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3233 						   l_segment4, -- paye reference value
3234 						    null,
3235 						    l_Act_Context_id,  --null,
3236 						    l_Act_Context_value,  --null,
3237 						    null,
3238 						    null,
3239 						    null,
3240 						    'TRUE'
3241 						),
3242 						0
3243 					   ),
3244 					   2
3245 					)
3246 				   );
3247 			    hr_utility.set_location('l_arch_total_notional_pay..'||l_arch_total_notional_pay,1005);
3248 --16306646
3249 			     l_arch_total_share_scheme :=
3250 				   TO_CHAR (
3251 					ROUND (
3252 					   NVL (
3253 						pay_balance_pkg.get_value (
3254 						   pay_ie_p35.get_defined_balance_id (
3255 							l_dimension_name, --'_PER_PAYE_REF_YTD',--6633719
3256 							'P35 Notional Pay Adjust Balance'  --'IE Share Schemes'
3257 						   ),
3258 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3259 						   l_segment4, -- paye reference value
3260 						    null,
3261 						    l_Act_Context_id,  --null,
3262 						    l_Act_Context_value,  --null,
3263 						    null,
3264 						    null,
3265 						    null,
3266 						    'TRUE'
3267 						),
3268 						0
3269 					   ),
3270 					   2
3271 					)
3272 				   );
3273 			    hr_utility.set_location('l_arch_total_share_scheme..'||l_arch_total_share_scheme,1005);
3274 
3275 			     l_p35_taxable_pay_adjust :=
3276 				   TO_CHAR (
3277 					ROUND (
3278 					   NVL (
3279 						pay_balance_pkg.get_value (
3280 						   pay_ie_p35.get_defined_balance_id (
3281 							l_dimension_name, --'_PER_PAYE_REF_YTD',--6633719
3282 							'P35 Taxable Pay Adjust Balance'
3283 						   ),
3284 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3285 						   l_segment4, -- paye reference value
3286 						    null,
3287 						    l_Act_Context_id,  --null,
3288 						    l_Act_Context_value,  --null,
3289 						    null,
3290 						    null,
3291 						    null,
3292 						    'TRUE'
3293 						),
3294 						0
3295 					   ),
3296 					   2
3297 					)
3298 				   );
3299 			    hr_utility.set_location('l_p35_taxable_pay_adjust..'||l_p35_taxable_pay_adjust,1005);
3300 
3301 			     l_p35_gross_pay_adjust :=
3302 				   TO_CHAR (
3303 					ROUND (
3304 					   NVL (
3305 						pay_balance_pkg.get_value (
3306 						   pay_ie_p35.get_defined_balance_id (
3307 							l_dimension_name, --'_PER_PAYE_REF_YTD',--6633719
3308 							'P35 Gross Pay Adjust Balance'
3309 						   ),
3310 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3311 						   l_segment4, -- paye reference value
3312 						    null,
3313 						    l_Act_Context_id,  --null,
3314 						    l_Act_Context_value,  --null,
3315 						    null,
3316 						    null,
3317 						    null,
3318 						    'TRUE'
3319 						),
3320 						0
3321 					   ),
3322 					   2
3323 					)
3324 				   );
3325 			    hr_utility.set_location('l_p35_gross_pay_adjust..'||l_p35_gross_pay_adjust,1005);
3326 --16306646
3327 
3328    -- Passed Payroll Run assignment action id csr_interlocks.locked_action_id 4672715
3329 			    /* Start Pension Balances */
3330 			    l_arch_pen_emp_rbs :=
3331 				   TO_CHAR (
3332 					ROUND (
3333 					   NVL (
3334 						pay_balance_pkg.get_value (
3335 						   pay_ie_p35.get_defined_balance_id (
3336 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
3337 							'IE RBS EE Contribution'
3338 						   ),
3339 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3340 						   l_segment4, -- paye reference value
3341 						    null,
3342 						    l_Act_Context_id, --null,
3343 						    l_Act_Context_value, --null,
3344 						    null,
3345 						    null,
3346 						    null,
3347 						    'TRUE'
3348 						),
3349 						0
3350 					   ),
3351 					   2
3352 					)
3353 					+
3354 					ROUND (
3355 					   NVL (
3356 						pay_balance_pkg.get_value (
3357 						   pay_ie_p35.get_defined_balance_id (
3358 							l_dimension_name,  --'_PER_PAYE_REF_YTD', --6633719
3359 							'IE RBS EE AVC Contribution'
3360 						   ),
3361 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3362 						   l_segment4, -- paye reference value
3363 						    null,
3364 						    l_Act_Context_id,  --null,
3365 						    l_Act_Context_value,  --null,
3366 						    null,
3367 						    null,
3368 						    null,
3369 						    'TRUE'
3370 						),
3371 						0
3372 					   ),
3373 					   2
3374 					)
3375 				   );
3376 			    hr_utility.set_location('l_arch_pen_emp_rbs..'||l_arch_pen_emp_rbs,1005);
3377 				l_arch_pen_empr_rbs :=
3378 				   TO_CHAR (
3379 					ROUND (
3380 					   NVL (
3381 						pay_balance_pkg.get_value (
3382 						   pay_ie_p35.get_defined_balance_id (
3383 							l_dimension_name,   --'_PER_PAYE_REF_YTD',--6633719
3384 							'IE RBS ER Contribution'
3385 						   ),
3386 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3387 						   l_segment4, -- paye reference value
3388 						    null,
3389 						    l_Act_Context_id,  --null,
3390 						    l_Act_Context_value,  --null,
3391 						    null,
3392 						    null,
3393 						    null,
3394 						    'TRUE'
3395 						),
3396 						0
3397 					   ),
3398 					   2
3399 					)
3400 				     );
3401 			    hr_utility.set_location('l_arch_pen_empr_rbs..'||l_arch_pen_empr_rbs,1005);
3402 				l_arch_pen_emp_prsa :=
3403 					   TO_CHAR (
3404 						ROUND (
3405 						   NVL (
3406 							pay_balance_pkg.get_value (
3407 							   pay_ie_p35.get_defined_balance_id (
3408 								l_dimension_name,   ---'_PER_PAYE_REF_YTD',--6633719
3409 								'IE PRSA EE Contribution'
3410 							   ),
3411 							   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3412 							  l_segment4, -- paye reference value
3413 							    null,
3414 							    l_Act_Context_id,  --null,
3415 							    l_Act_Context_value,  --null,
3416 							    null,
3417 							    null,
3418 							    null,
3419 							    'TRUE'
3420 							),
3421 							0
3422 						   ),
3423 						   2
3424 						)
3425 						+
3426 						ROUND (
3427 						   NVL (
3428 							pay_balance_pkg.get_value (
3429 							   pay_ie_p35.get_defined_balance_id (
3430 								l_dimension_name,  ---'_PER_PAYE_REF_YTD',--6633719
3431 								'IE PRSA EE AVC Contribution'
3432 							   ),
3433 							   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3434 							   l_segment4, -- paye reference value
3435 							    null,
3436 							    l_Act_Context_id,  --null,
3437 							    l_Act_Context_value,  --null,
3438 							    null,
3439 							    null,
3440 							    null,
3441 							    'TRUE'
3442 							),
3443 							0
3444 						   ),
3445 						   2
3446 						)
3447 					   );
3448 			    hr_utility.set_location('l_arch_pen_emp_prsa..'||l_arch_pen_emp_prsa,1005);
3449 				l_arch_pen_empr_prsa :=
3450 				   TO_CHAR (
3451 					ROUND (
3452 					   NVL (
3453 						pay_balance_pkg.get_value (
3454 						   pay_ie_p35.get_defined_balance_id (
3455 							l_dimension_name,   ---'_PER_PAYE_REF_YTD',--6633719
3456 							'IE PRSA ER Contribution'
3457 						   ),
3458 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3459 						  l_segment4, -- paye reference value
3460 						    null,
3461 						    l_Act_Context_id,  --null,
3462 						    l_Act_Context_value,  --null,
3463 						    null,
3464 						    null,
3465 						    null,
3466 						    'TRUE'
3467 						),
3468 						0
3469 					   ),
3470 					   2
3471 					)
3472 				     );
3473 			    hr_utility.set_location('l_arch_pen_empr_prsa..'||l_arch_pen_empr_prsa,1005);
3474 				l_arch_pen_emp_rac :=
3475 				   TO_CHAR (
3476 					ROUND (
3477 					   NVL (
3478 						pay_balance_pkg.get_value (
3479 						   pay_ie_p35.get_defined_balance_id (
3480 							l_dimension_name,   ---'_PER_PAYE_REF_YTD',--6633719
3481 							'IE RAC EE Contribution'
3482 						   ),
3483 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3484 						  l_segment4, -- paye reference value
3485 						    null,
3486 						    l_Act_Context_id,  --null,
3487 						    l_Act_Context_value,  --null,
3488 						    null,
3489 						    null,
3490 						    null,
3491 						    'TRUE'
3492 						),
3493 						0
3494 					   ),
3495 					   2
3496 					)
3497 				     );
3498 			/* End Pension Balances */
3499 			    hr_utility.set_location('l_arch_pen_emp_rac..'||l_arch_pen_emp_rac,1005);
3500 			    /* start of gross pay balances */
3501                             OPEN csr_p30_bal_value (v_action_id, 'IE GROSS INCOME ADJUSTMENT',l_dimension_name); /* 8520684 */
3502 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay;
3503 			--6633719
3504                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3505 
3506 			        l_temp_gross_pay :=
3507 				   TO_CHAR (
3508 					ROUND (
3509 					   NVL (
3510 						pay_balance_pkg.get_value (
3511 						   pay_ie_p35.get_defined_balance_id (
3512 							l_dimension_name,
3513 							'IE Gross Income Adjustment'
3514 						   ),
3515 						   csr_interlocks.locked_action_id,
3516 						   l_segment4, -- paye reference value
3517 						    null,
3518 						    null,
3519 						    null,
3520 						    null,
3521 						    null,
3522 						    null,
3523 						    'TRUE'
3524 						),
3525 						0
3526 					   ),
3527 					   2
3528 					)
3529 				   );
3530                      hr_utility.set_location('l_temp_gross_pay not archived ..'|| l_temp_gross_pay,1004);
3531                  END IF;
3532                             CLOSE csr_p30_bal_value;
3533 hr_utility.set_location('IE Gross Income Adjustment l_temp_gross_pay..'||l_temp_gross_pay,1005);
3534 
3535 			    l_arch_gross_pay :=
3536 				  TO_CHAR (
3537 					 TO_NUMBER (l_arch_gross_pay)
3538 				     + TO_NUMBER (NVL (l_temp_gross_pay, '0'))
3539 				  );
3540 			    l_temp_gross_pay := NULL;
3541 hr_utility.set_location('IE Gross Income Adjustment l_arch_gross_pay..'||l_arch_gross_pay,1005);
3542 
3543                             OPEN csr_p30_bal_value (v_action_id, 'IE GROSS INCOME',l_dimension_name);
3544 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay;
3545 			--6633719
3546                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3547 
3548 			        l_temp_gross_pay :=
3549 				   TO_CHAR (
3550 					ROUND (
3551 					   NVL (
3552 						pay_balance_pkg.get_value (
3553 						   pay_ie_p35.get_defined_balance_id (
3554 							l_dimension_name,
3555 							'IE Gross Income'
3556 						   ),
3557 						   csr_interlocks.locked_action_id,
3558 						   l_segment4, -- paye reference value
3559 						    null,
3560 						    null,
3561 						    null,
3562 						    null,
3563 						    null,
3564 						    null,
3565 						    'TRUE'
3566 						),
3567 						0
3568 					   ),
3569 					   2
3570 					)
3571 				   );
3572                      hr_utility.set_location('l_temp_gross_pay not archived ..'|| l_temp_gross_pay,1004);
3573                  END IF;
3574                             CLOSE csr_p30_bal_value;
3575 hr_utility.set_location('IE Gross Income l_temp_gross_pay..'||l_temp_gross_pay,1005);
3576 
3577 			    l_arch_gross_pay :=
3578 				  TO_CHAR (
3579 					 TO_NUMBER (l_arch_gross_pay)
3580 				     + TO_NUMBER (NVL (l_temp_gross_pay, '0'))
3581 				  );
3582 			    l_temp_gross_pay := NULL;
3583 hr_utility.set_location('IE Gross Income l_arch_gross_pay..'||l_arch_gross_pay,1005);
3584 
3585                             OPEN csr_p30_bal_value (v_action_id, 'IE BIK TAXABLE AND PRSIABLE PAY',l_dimension_name);
3586 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay;
3587 			--6633719
3588                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3589 
3590 			        l_temp_gross_pay :=
3591 				   TO_CHAR (
3592 					ROUND (
3593 					   NVL (
3594 						pay_balance_pkg.get_value (
3595 						   pay_ie_p35.get_defined_balance_id (
3596 							l_dimension_name,
3597 							'IE BIK Taxable and PRSIable Pay'
3598 						   ),
3599 						   csr_interlocks.locked_action_id,
3600 						   l_segment4, -- paye reference value
3601 						    null,
3602 						    null,
3603 						    null,
3604 						    null,
3605 						    null,
3606 						    null,
3607 						    'TRUE'
3608 						),
3609 						0
3610 					   ),
3611 					   2
3612 					)
3613 				   );
3614                      hr_utility.set_location('l_temp_gross_pay not archived ..'|| l_temp_gross_pay,1004);
3615                  END IF;
3616                             CLOSE csr_p30_bal_value;
3617 hr_utility.set_location('IE BIK Taxable and PRSIable Pay l_temp_gross_pay..'||l_temp_gross_pay,1005);
3618 
3619 			    l_arch_gross_pay :=
3620 				  TO_CHAR (
3621 					 TO_NUMBER (l_arch_gross_pay)
3622 				     + TO_NUMBER (NVL (l_temp_gross_pay, '0'))
3623 				  );
3624 			    l_temp_gross_pay := NULL;
3625 hr_utility.set_location('IE BIK Taxable and PRSIable Pay l_arch_gross_pay..'||l_arch_gross_pay,1005);
3626 
3627                             /*  income tax levy  balances */
3628                             OPEN csr_p30_bal_value (v_action_id, 'IE INCOME TAX LEVY',l_dimension_name); /* 8520684 */
3629 			    FETCH csr_p30_bal_value INTO l_temp_income_levy;
3630 			--6633719
3631                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3632 
3633 			        l_temp_income_levy :=
3634 				   TO_CHAR (
3635 					ROUND (
3636 					   NVL (
3637 						pay_balance_pkg.get_value (
3638 						   pay_ie_p35.get_defined_balance_id (
3639 							l_dimension_name,
3640 							'IE Income Tax Levy'
3641 						   ),
3642 						   csr_interlocks.locked_action_id,
3643 						   l_segment4, -- paye reference value
3644 						    null,
3645 						    null,
3646 						    null,
3647 						    null,
3648 						    null,
3649 						    null,
3650 						    'TRUE'
3651 						),
3652 						0
3653 					   ),
3654 					   2
3655 					)
3656 				   );
3657                      hr_utility.set_location('l_temp_income_levy not archived ..'|| l_temp_income_levy,1004);
3658                  END IF;
3659                             CLOSE csr_p30_bal_value;
3660 hr_utility.set_location('IE Income Tax Levy l_temp_income_levy..'||l_temp_income_levy,1005);
3661 
3662 			    l_arch_income_levy :=
3663 				  TO_CHAR (
3664 					 TO_NUMBER (l_arch_income_levy)
3665 				     + TO_NUMBER (NVL (l_temp_income_levy, '0'))
3666 				  );
3667 			    l_temp_income_levy := NULL;
3668 hr_utility.set_location('IE Income Tax Levy l_arch_income_levy..'||l_arch_income_levy,1005);
3669 
3670                         /* 8978805 */
3671 			/*
3672                             OPEN csr_p30_bal_value (v_action_id, 'IE INCOME TAX LEVY REFUND AMOUNT',l_dimension_name);
3673 			    FETCH csr_p30_bal_value INTO l_temp_income_levy;
3674 			--6633719
3675                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3676 
3677 			        l_temp_income_levy :=
3678 				   TO_CHAR (
3679 					ROUND (
3680 					   NVL (
3681 						pay_balance_pkg.get_value (
3682 						   pay_ie_p35.get_defined_balance_id (
3683 							l_dimension_name,
3684 							'IE Income Tax Levy Refund Amount'
3685 						   ),
3686 						   csr_interlocks.locked_action_id,
3687 						   l_segment4, -- paye reference value
3688 						    null,
3689 						    null,
3690 						    null,
3691 						    null,
3692 						    null,
3693 						    null,
3694 						    'TRUE'
3695 						),
3696 						0
3697 					   ),
3698 					   2
3699 					)
3700 				   );
3701                      hr_utility.set_location('l_temp_income_levy not archived ..'|| l_temp_income_levy,1004);
3702                  END IF;
3703 CLOSE csr_p30_bal_value;
3704 hr_utility.set_location('IE Income Tax Levy Refund Amount l_temp_income_levy..'||l_temp_income_levy,1005);	*/
3705 
3706 			    l_arch_income_levy :=
3707 				  TO_CHAR (
3708 					 TO_NUMBER (l_arch_income_levy)
3709 				     + TO_NUMBER (NVL (l_temp_income_levy, '0'))
3710 				  );
3711 			    l_temp_income_levy := NULL;
3712 hr_utility.set_location('IE Income Tax Levy Refund Amount l_arch_income_levy..'||l_arch_income_levy,1005);
3713 
3714                             /* first band */
3715                             OPEN csr_p30_bal_value (v_action_id, 'IE INCOME TAX LEVY FIRST BAND',l_dimension_name); /* 8520684 */
3716 			    FETCH csr_p30_bal_value INTO l_arch_income_levy_first;
3717 			--6633719
3718                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3719 
3720 			        l_arch_income_levy_first :=
3721 				   TO_CHAR (
3722 					ROUND (
3723 					   NVL (
3724 						pay_balance_pkg.get_value (
3725 						   pay_ie_p35.get_defined_balance_id (
3726 							l_dimension_name,
3727 							'IE Income Tax Levy First Band'
3728 						   ),
3729 						   csr_interlocks.locked_action_id,
3730 						   l_segment4, -- paye reference value
3731 						    null,
3732 						    null,
3733 						    null,
3734 						    null,
3735 						    null,
3736 						    null,
3737 						    'TRUE'
3738 						),
3739 						0
3740 					   ),
3741 					   2
3742 					)
3743 				   );
3744 
3745                 hr_utility.set_location('l_arch_income_levy_first not archived ..'||l_arch_income_levy_first,1004);
3746 
3747 			     END IF;
3748 			--6633719
3749                 CLOSE csr_p30_bal_value;
3750 			    hr_utility.set_location('l_arch_income_levy_first..'||l_arch_income_levy_first,1005);
3751 
3752                             /* second band  */
3753                             OPEN csr_p30_bal_value (v_action_id, 'IE INCOME TAX LEVY SECOND BAND',l_dimension_name); /* 8520684 */
3754 			    FETCH csr_p30_bal_value INTO l_arch_income_levy_second;
3755 			--6633719
3756                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3757 
3758 			        l_arch_income_levy_second :=
3759 				   TO_CHAR (
3760 					ROUND (
3761 					   NVL (
3762 						pay_balance_pkg.get_value (
3763 						   pay_ie_p35.get_defined_balance_id (
3764 							l_dimension_name,
3765 							'IE Income Tax Levy Second Band'
3766 						   ),
3767 						   csr_interlocks.locked_action_id,
3768 						   l_segment4, -- paye reference value
3769 						    null,
3770 						    null,
3771 						    null,
3772 						    null,
3773 						    null,
3774 						    null,
3775 						    'TRUE'
3776 						),
3777 						0
3778 					   ),
3779 					   2
3780 					)
3781 				   );
3782 
3783                 hr_utility.set_location('l_arch_income_levy_second not archived ..'||l_arch_income_levy_second,1004);
3784 
3785 			     END IF;
3786 			--6633719
3787                 CLOSE csr_p30_bal_value;
3788 			    hr_utility.set_location('l_arch_income_levy_second..'||l_arch_income_levy_second,1005);
3789 
3790 
3791                             /* Third band  */
3792                             OPEN csr_p30_bal_value (v_action_id, 'IE INCOME TAX LEVY THIRD BAND',l_dimension_name); /* 8520684 */
3793 			    FETCH csr_p30_bal_value INTO l_arch_income_levy_third;
3794 			--6633719
3795                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3796 
3797 			        l_arch_income_levy_third :=
3798 				   TO_CHAR (
3799 					ROUND (
3800 					   NVL (
3801 						pay_balance_pkg.get_value (
3802 						   pay_ie_p35.get_defined_balance_id (
3803 							l_dimension_name,
3804 							'IE Income Tax Levy Third Band'
3805 						   ),
3806 						   csr_interlocks.locked_action_id,
3807 						   l_segment4, -- paye reference value
3808 						    null,
3809 						    null,
3810 						    null,
3811 						    null,
3812 						    null,
3813 						    null,
3814 						    'TRUE'
3815 						),
3816 						0
3817 					   ),
3818 					   2
3819 					)
3820 				   );
3821 
3822                 hr_utility.set_location('l_arch_income_levy_third not archived ..'||l_arch_income_levy_third,1004);
3823 
3824 			     END IF;
3825 			--6633719
3826                 CLOSE csr_p30_bal_value;
3827 			    hr_utility.set_location('l_arch_income_levy_third..'||l_arch_income_levy_third,1005);
3828 
3829 --14656910
3830 /* Illness Benefit */
3831 				OPEN csr_p30_bal_value (v_action_id, 'IE ILLNESS BENEFIT',l_dimension_name); /* 8520684 */
3832 				FETCH csr_p30_bal_value INTO l_arch_illness_benefit;
3833 				--6633719
3834 				IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3835 
3836 			        l_arch_illness_benefit :=
3837 				   TO_CHAR (
3838 					ROUND (
3839 					   NVL (
3840 						pay_balance_pkg.get_value (
3841 						   pay_ie_p35.get_defined_balance_id (
3842 							l_dimension_name,
3843 							'IE Illness Benefit'
3844 						   ),
3845 						   csr_interlocks.locked_action_id,
3846 						   l_segment4, -- paye reference value
3847 						    null,
3848 						    null,
3849 						    null,
3850 						    null,
3851 						    null,
3852 						    null,
3853 						    'TRUE'
3854 						),
3855 						0
3856 					   ),
3857 					   2
3858 					)
3859 				   );
3860 
3861 				hr_utility.set_location('l_arch_illness_benefit not archived ..'||l_arch_illness_benefit,1004);
3862 
3863 				END IF;
3864 				--6633719
3865 				CLOSE csr_p30_bal_value;
3866 				hr_utility.set_location('l_arch_illness_benefit..'||l_arch_illness_benefit,1005);
3867 --14656910
3868 
3869 			    /* Parking Levy   */
3870                             OPEN csr_p30_bal_value (v_action_id, 'IE PARKING LEVY',l_dimension_name); /* 8520684 */
3871 			    FETCH csr_p30_bal_value INTO l_arch_parking_levy;
3872 			--6633719
3873                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3874 
3875 			        l_arch_parking_levy :=
3876 				   TO_CHAR (
3877 					ROUND (
3878 					   NVL (
3879 						pay_balance_pkg.get_value (
3880 						   pay_ie_p35.get_defined_balance_id (
3881 							l_dimension_name,
3882 							'IE Parking Levy'
3883 						   ),
3884 						   csr_interlocks.locked_action_id,
3885 						   l_segment4, -- paye reference value
3886 						    null,
3887 						    null,
3888 						    null,
3889 						    null,
3890 						    null,
3891 						    null,
3892 						    'TRUE'
3893 						),
3894 						0
3895 					   ),
3896 					   2
3897 					)
3898 				   );
3899 
3900                 hr_utility.set_location('l_arch_parking_levy not archived ..'||l_arch_parking_levy,1004);
3901 
3902 			     END IF;
3903 			--6633719
3904                 CLOSE csr_p30_bal_value;
3905 			    hr_utility.set_location('l_arch_parking_levy..'||l_arch_parking_levy,1005);
3906 
3907 
3908 			-- BIK Medical insurance 5867343
3909 			l_medical_insurance :=
3910 				   TO_CHAR (
3911 					ROUND (
3912 					   NVL (
3913 						pay_balance_pkg.get_value (
3914 						   pay_ie_p35.get_defined_balance_id (
3915 							l_dimension_name,  ---'_PER_PAYE_REF_YTD',--6633719
3916 							'IE BIK Medical Insurance'
3917 						   ),
3918 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
3919 						  l_segment4, -- paye reference value
3920 						    null,
3921 						    l_Act_Context_id,  --null,
3922 						    l_Act_Context_value,  --null,
3923 						    null,
3924 						    null,
3925 						    null,
3926 						    'TRUE'
3927 						),
3928 						0
3929 					   ),
3930 					   2
3931 					)
3932 				     );
3933 			    hr_utility.set_location('l_medical_insurance..'||l_medical_insurance,1005);
3934 			    /*Bug No. 4063502*/
3935 			     IF nvl(l_arch_pay,0) = 0 THEN -- if IE TAXABLE PAY is 0
3936 			    hr_utility.set_location('Inside If l_arch_non_tax_pay..'||l_arch_non_tax_pay,1005);
3937 				l_arch_non_tax_pay :=
3938 					 TO_CHAR (
3939 					    ROUND (
3940 						 NVL (
3941 						  pay_balance_pkg.get_value (
3942 						     pay_ie_p35.get_defined_balance_id (
3943 							l_dimension_name,   ---'_PER_PAYE_REF_YTD',--6633719
3944 							'Total Pay'
3945 						     ),
3946 						     csr_interlocks.locked_action_id,
3947 						   l_segment4, -- paye reference value
3948 						    null,
3949 						    l_Act_Context_id,  --null,
3950 						    l_Act_Context_value,  --null,
3951 						    null,
3952 						    null,
3953 						    null,
3954 						    'TRUE'
3955 						  ),
3956 						  0
3957 						 ),
3958 						 2
3959 					    )
3960 					 );
3961 			    hr_utility.set_location('l_arch_non_tax_pay..'||l_arch_non_tax_pay,1005);
3962 			     END IF;
3963 
3964 
3965 			    SELECT DECODE (
3966 					SIGN (TO_NUMBER (NVL (l_arch_net_tax, 0))),
3967 					-1, '1',
3968 					1, '0',
3969 					'0'
3970 				   )
3971 				INTO l_arch_tax_or_refund
3972 				FROM DUAL;
3973 
3974 
3975 		   hr_utility.set_location('l_arch_tax_or_refund..'||l_arch_tax_or_refund,1005);
3976            hr_utility.set_location('b4  cursor csr_p30_found..',1005);
3977 
3978 
3979 --12382953
3980 
3981 /* start of gross pay USC balances */
3982                             OPEN csr_p30_bal_value (v_action_id, 'IE GROSS INCOME ADJUSTMENT',l_dimension_name);
3983 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay_usc;
3984 			--6633719
3985                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
3986 
3987 			        l_temp_gross_pay_usc :=
3988 				   TO_CHAR (
3989 					ROUND (
3990 					   NVL (
3991 						pay_balance_pkg.get_value (
3992 						   pay_ie_p35.get_defined_balance_id (
3993 							l_dimension_name,
3994 							'IE Gross Income Adjustment'
3995 						   ),
3996 						   csr_interlocks.locked_action_id,
3997 						   l_segment4, -- paye reference value
3998 						    null,
3999 						    null,
4000 						    null,
4001 						    null,
4002 						    null,
4003 						    null,
4004 						    'TRUE'
4005 						),
4006 						0
4007 					   ),
4008 					   2
4009 					)
4010 				   );
4011                      hr_utility.set_location('l_temp_gross_pay_usc not archived ..'|| l_temp_gross_pay_usc,1004);
4012                  END IF;
4013                             CLOSE csr_p30_bal_value;
4014 hr_utility.set_location('IE Gross Income Adjustment l_temp_gross_pay_usc..'||l_temp_gross_pay_usc,1005);
4015 
4016 			    l_arch_gross_pay_usc :=
4017 				  TO_CHAR (
4018 					 TO_NUMBER (l_arch_gross_pay_usc)
4019 				     + TO_NUMBER (NVL (l_temp_gross_pay_usc, '0'))
4020 				  );
4021 			    l_temp_gross_pay_usc := NULL;
4022 hr_utility.set_location('IE Gross Income Adjustment l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1005);
4023 
4024                             OPEN csr_p30_bal_value (v_action_id, 'IE USCABLE PAY',l_dimension_name);
4025 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay_usc;
4026 			--6633719
4027                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4028 
4029 			        l_temp_gross_pay_usc :=
4030 				   TO_CHAR (
4031 					ROUND (
4032 					   NVL (
4033 						pay_balance_pkg.get_value (
4034 						   pay_ie_p35.get_defined_balance_id (
4035 							l_dimension_name,
4036 							'IE USCable Pay'
4037 						   ),
4038 						   csr_interlocks.locked_action_id,
4039 						   l_segment4, -- paye reference value
4040 						    null,
4041 						    null,
4042 						    null,
4043 						    null,
4044 						    null,
4045 						    null,
4046 						    'TRUE'
4047 						),
4048 						0
4049 					   ),
4050 					   2
4051 					)
4052 				   );
4053                      hr_utility.set_location('l_temp_gross_pay_usc not archived ..'|| l_temp_gross_pay_usc,1004);
4054                  END IF;
4055                             CLOSE csr_p30_bal_value;
4056 hr_utility.set_location('IE USCable Pay l_temp_gross_pay_usc..'||l_temp_gross_pay_usc,1005);
4057 
4058 			    l_arch_gross_pay_usc :=
4059 				  TO_CHAR (
4060 					 TO_NUMBER (l_arch_gross_pay_usc)
4061 				     + TO_NUMBER (NVL (l_temp_gross_pay_usc, '0'))
4062 				  );
4063 			    l_temp_gross_pay_usc := NULL;
4064 hr_utility.set_location('IE USCable Pay l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1005);
4065 
4066                             OPEN csr_p30_bal_value (v_action_id, 'IE BIK TAXABLE AND PRSIABLE PAY',l_dimension_name);
4067 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay_usc;
4068 			--6633719
4069                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4070 
4071 			        l_temp_gross_pay_usc :=
4072 				   TO_CHAR (
4073 					ROUND (
4074 					   NVL (
4075 						pay_balance_pkg.get_value (
4076 						   pay_ie_p35.get_defined_balance_id (
4077 							l_dimension_name,
4078 							'IE BIK Taxable and PRSIable Pay'
4079 						   ),
4080 						   csr_interlocks.locked_action_id,
4081 						   l_segment4, -- paye reference value
4082 						    null,
4083 						    null,
4084 						    null,
4085 						    null,
4086 						    null,
4087 						    null,
4088 						    'TRUE'
4089 						),
4090 						0
4091 					   ),
4092 					   2
4093 					)
4094 				   );
4095                      hr_utility.set_location('l_temp_gross_pay_usc not archived ..'|| l_temp_gross_pay_usc,1004);
4096                  END IF;
4097                             CLOSE csr_p30_bal_value;
4098 hr_utility.set_location('IE BIK Taxable and PRSIable Pay l_temp_gross_pay_usc..'||l_temp_gross_pay_usc,1005);
4099 
4100 			    l_arch_gross_pay_usc :=
4101 				  TO_CHAR (
4102 					 TO_NUMBER (l_arch_gross_pay_usc)
4103 				     + TO_NUMBER (NVL (l_temp_gross_pay_usc, '0'))
4104 				  );
4105 			    l_temp_gross_pay_usc := NULL;
4106 hr_utility.set_location('IE BIK Taxable and PRSIable Pay l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1005);
4107 
4108 --
4109                             OPEN csr_p30_bal_value (v_action_id, 'IE COURT ORDER',l_dimension_name);
4110 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay_usc;
4111 			--6633719
4112                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4113 
4114 			        l_temp_gross_pay_usc :=
4115 				   TO_CHAR (
4116 					ROUND (
4117 					   NVL (
4118 						pay_balance_pkg.get_value (
4119 						   pay_ie_p35.get_defined_balance_id (
4120 							l_dimension_name,
4121 							'IE Court Order'
4122 						   ),
4123 						   csr_interlocks.locked_action_id,
4124 						   l_segment4, -- paye reference value
4125 						    null,
4126 						    null,
4127 						    null,
4128 						    null,
4129 						    null,
4130 						    null,
4131 						    'TRUE'
4132 						),
4133 						0
4134 					   ),
4135 					   2
4136 					)
4137 				   );
4138                      hr_utility.set_location('l_temp_gross_pay_usc not archived ..'|| l_temp_gross_pay_usc,1004);
4139                  END IF;
4140                             CLOSE csr_p30_bal_value;
4141 hr_utility.set_location('IE Court Order l_temp_gross_pay_usc..'||l_temp_gross_pay_usc,1005);
4142 
4143 			    l_arch_gross_pay_usc :=
4144 				  TO_CHAR (
4145 					 TO_NUMBER (l_arch_gross_pay_usc)
4146 				     - TO_NUMBER (NVL (l_temp_gross_pay_usc, '0'))
4147 				  );
4148 			    l_temp_gross_pay_usc := NULL;
4149 hr_utility.set_location('IE Court Order l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1005);
4150 --
4151 
4152 --11076169
4153 --
4154                             OPEN csr_p30_bal_value (v_action_id, 'IE COURT ORDER CHILD PORTION',l_dimension_name);
4155 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay_usc;
4156 			--6633719
4157                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4158 
4159 			        l_temp_gross_pay_usc :=
4160 				   TO_CHAR (
4161 					ROUND (
4162 					   NVL (
4163 						pay_balance_pkg.get_value (
4164 						   pay_ie_p35.get_defined_balance_id (
4165 							l_dimension_name,
4166 							'IE Court Order Child Portion'
4167 						   ),
4168 						   csr_interlocks.locked_action_id,
4169 						   l_segment4, -- paye reference value
4170 						    null,
4171 						    null,
4172 						    null,
4173 						    null,
4174 						    null,
4175 						    null,
4176 						    'TRUE'
4177 						),
4178 						0
4179 					   ),
4180 					   2
4181 					)
4182 				   );
4183                      hr_utility.set_location('l_temp_gross_pay_usc not archived ..'|| l_temp_gross_pay_usc,1004);
4184                  END IF;
4185                             CLOSE csr_p30_bal_value;
4186 hr_utility.set_location('IE Court Order Child Portion l_temp_gross_pay_usc..'||l_temp_gross_pay_usc,1005);
4187 
4188 			    l_arch_gross_pay_usc :=
4189 				  TO_CHAR (
4190 					 TO_NUMBER (l_arch_gross_pay_usc)
4191 				     + TO_NUMBER (NVL (l_temp_gross_pay_usc, '0'))
4192 				  );
4193 			    l_temp_gross_pay_usc := NULL;
4194 hr_utility.set_location('IE Court Order Child Portion l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1005);
4195 --
4196 --11076169
4197 
4198 --16242337
4199 --
4200                             OPEN csr_p30_bal_value (v_action_id, 'IE PRSA ER CONTRIBUTION',l_dimension_name);
4201 			    FETCH csr_p30_bal_value INTO l_temp_gross_pay_usc;
4202 			--6633719
4203                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4204 
4205 			        l_temp_gross_pay_usc :=
4206 				   TO_CHAR (
4207 					ROUND (
4208 					   NVL (
4209 						pay_balance_pkg.get_value (
4210 						   pay_ie_p35.get_defined_balance_id (
4211 							l_dimension_name,
4212 							'IE PRSA ER Contribution'
4213 						   ),
4214 						   csr_interlocks.locked_action_id,
4215 						   l_segment4, -- paye reference value
4216 						    null,
4217 						    null,
4218 						    null,
4219 						    null,
4220 						    null,
4221 						    null,
4222 						    'TRUE'
4223 						),
4224 						0
4225 					   ),
4226 					   2
4227 					)
4228 				   );
4229                      hr_utility.set_location('l_temp_gross_pay_usc not archived ..'|| l_temp_gross_pay_usc,1004);
4230                  END IF;
4231                             CLOSE csr_p30_bal_value;
4232 hr_utility.set_location('IE PRSA ER Contribution l_temp_gross_pay_usc..'||l_temp_gross_pay_usc,1005);
4233 
4234 			    l_arch_gross_pay_usc :=
4235 				  TO_CHAR (
4236 					 TO_NUMBER (l_arch_gross_pay_usc)
4237 				     + TO_NUMBER (NVL (l_temp_gross_pay_usc, '0'))
4238 				  );
4239 			    l_temp_gross_pay_usc := NULL;
4240 hr_utility.set_location('IE PRSA ER Contribution l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1005);
4241 --
4242 --16242337
4243 
4244 /*  USC balances */
4245                             OPEN csr_p30_bal_value (v_action_id, 'IE USC BALANCE',l_dimension_name);
4246 			    FETCH csr_p30_bal_value INTO l_temp_usc;
4247 			--6633719
4248                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4249 
4250 			        l_temp_usc :=
4251 				   TO_CHAR (
4252 					ROUND (
4253 					   NVL (
4254 						pay_balance_pkg.get_value (
4255 						   pay_ie_p35.get_defined_balance_id (
4256 							l_dimension_name,
4257 							'IE USC Balance'
4258 						   ),
4259 						   csr_interlocks.locked_action_id,
4260 						   l_segment4, -- paye reference value
4261 						    null,
4262 						    null,
4263 						    null,
4264 						    null,
4265 						    null,
4266 						    null,
4267 						    'TRUE'
4268 						),
4269 						0
4270 					   ),
4271 					   2
4272 					)
4273 				   );
4274                      hr_utility.set_location('l_temp_usc not archived ..'|| l_temp_usc,1004);
4275                  END IF;
4276                             CLOSE csr_p30_bal_value;
4277 hr_utility.set_location('IE USC Balance l_temp_usc..'||l_temp_usc,1005);
4278 
4279 			    l_arch_usc :=
4280 				  TO_CHAR (
4281 					 TO_NUMBER (l_arch_usc)
4282 				     + TO_NUMBER (NVL (l_temp_usc, '0'))
4283 				  );
4284 			    l_temp_usc := NULL;
4285 hr_utility.set_location('IE USC Balance l_arch_usc..'||l_arch_usc,1005);
4286 
4287                             /* first band */
4288                             OPEN csr_p30_bal_value (v_action_id, 'IE USC FIRST BAND',l_dimension_name); /* 8520684 */
4289 			    FETCH csr_p30_bal_value INTO l_arch_usc_first;
4290 			--6633719
4291                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4292 
4293 			        l_arch_usc_first :=
4294 				   TO_CHAR (
4295 					ROUND (
4296 					   NVL (
4297 						pay_balance_pkg.get_value (
4298 						   pay_ie_p35.get_defined_balance_id (
4299 							l_dimension_name,
4300 							'IE USC First Band'
4301 						   ),
4302 						   csr_interlocks.locked_action_id,
4303 						   l_segment4, -- paye reference value
4304 						    null,
4305 						    null,
4306 						    null,
4307 						    null,
4308 						    null,
4309 						    null,
4310 						    'TRUE'
4311 						),
4312 						0
4313 					   ),
4314 					   2
4315 					)
4316 				   );
4317 
4318                 hr_utility.set_location('l_arch_usc_first not archived ..'||l_arch_usc_first,1004);
4319 
4320 			     END IF;
4321 			--6633719
4322                 CLOSE csr_p30_bal_value;
4323 			    hr_utility.set_location('l_arch_usc_first..'||l_arch_usc_first,1005);
4324 
4325                             /* second band  */
4326                             OPEN csr_p30_bal_value (v_action_id, 'IE USC SECOND BAND',l_dimension_name); /* 8520684 */
4327 			    FETCH csr_p30_bal_value INTO l_arch_usc_second;
4328 			--6633719
4329                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4330 
4331 			        l_arch_usc_second :=
4332 				   TO_CHAR (
4333 					ROUND (
4334 					   NVL (
4335 						pay_balance_pkg.get_value (
4336 						   pay_ie_p35.get_defined_balance_id (
4337 							l_dimension_name,
4338 							'IE USC Second Band'
4339 						   ),
4340 						   csr_interlocks.locked_action_id,
4341 						   l_segment4, -- paye reference value
4342 						    null,
4343 						    null,
4344 						    null,
4345 						    null,
4346 						    null,
4347 						    null,
4348 						    'TRUE'
4349 						),
4350 						0
4351 					   ),
4352 					   2
4353 					)
4354 				   );
4355 
4356                 hr_utility.set_location('l_arch_usc_second not archived ..'||l_arch_usc_second,1004);
4357 
4358 			     END IF;
4359 			--6633719
4360                 CLOSE csr_p30_bal_value;
4361 			    hr_utility.set_location('l_arch_usc_second..'||l_arch_usc_second,1005);
4362 
4363 
4364                             /* Third band  */
4365                             OPEN csr_p30_bal_value (v_action_id, 'IE USC THIRD BAND',l_dimension_name); /* 8520684 */
4366 			    FETCH csr_p30_bal_value INTO l_arch_usc_third;
4367 			--6633719
4368                  IF csr_p30_bal_value%NOTFOUND AND l_ppsn_bal_archived = 'N' THEN
4369 
4370 			        l_arch_usc_third :=
4371 				   TO_CHAR (
4372 					ROUND (
4373 					   NVL (
4374 						pay_balance_pkg.get_value (
4375 						   pay_ie_p35.get_defined_balance_id (
4376 							l_dimension_name,
4377 							'IE USC Third Band'
4378 						   ),
4379 						   csr_interlocks.locked_action_id,
4380 						   l_segment4, -- paye reference value
4381 						    null,
4382 						    null,
4383 						    null,
4384 						    null,
4385 						    null,
4386 						    null,
4387 						    'TRUE'
4388 						),
4389 						0
4390 					   ),
4391 					   2
4392 					)
4393 				   );
4394 
4395                 hr_utility.set_location('l_arch_usc_third not archived ..'||l_arch_usc_third,1004);
4396 
4397 			     END IF;
4398 			--6633719
4399                 CLOSE csr_p30_bal_value;
4400 			    hr_utility.set_location('l_arch_usc_third..'||l_arch_usc_third,1005);
4401 
4402 --12382953
4403 				   --
4404 			-- BUG 3306202 Added cursor CSR_P30_PERSON
4405 			OPEN csr_p30_found (v_action_id, l_arch_net_tax,csr_interlocks.locked_action_id);
4406 			/*Shifted this cursor for bug 4023751*/
4407 			FETCH csr_p30_found INTO l_arch_ppsn,
4408 							    l_arch_works_number,
4409 							    l_arch_person_id,
4410 							    l_arch_primary_flag,
4411 							    l_arch_asg_location_id, -- 10277535
4412 							    l_arch_org_id, --11674153
4413 							    l_arch_assignment_id,
4414 							--    l_arch_tax_deduction_basis,
4415 							    l_arch_surname,
4416 							    l_arch_first_name,
4417 							    l_arch_dob,
4418 							    l_arch_address_line1,
4419 							    l_arch_address_line2,
4420 							    l_arch_address_line3,
4421 							    l_arch_address_line4,
4422 							    l_arch_hire_date,
4423 							    l_period_type,
4424 							--    l_arch_annual_tax_credit,
4425 							    l_arch_term_date,
4426 							    l_arch_mothers_name,
4427 							    l_arch_pr_indicator,
4428 							    l_arch_previous_emp_pay,
4429 							    l_arch_previous_emp_tax, l_arch_previous_emp_pay_usc, l_arch_previous_emp_usc; --14659262
4430 			CLOSE csr_p30_found;
4431 			/* lock this v_action_id*/
4432            hr_utility.set_location('after  cursor csr_p30_found..',1005);
4433 		   hr_utility.set_location('l_arch_works_number..'||l_arch_works_number,1005);
4434 		   hr_utility.set_location('l_arch_ppsn..'||l_arch_ppsn,1005);
4435 		   hr_utility.set_location('l_arch_primary_flag..'||l_arch_primary_flag,1005);
4436 		   hr_utility.set_location('l_arch_asg_location_id..'||l_arch_asg_location_id,1005); -- 10277535
4437 		   hr_utility.set_location('l_arch_org_id..'||l_arch_org_id,1005); -- 11674153
4438 		   hr_utility.set_location('l_arch_assignment_id..'||l_arch_assignment_id,1005);
4439 
4440 		ELSIF v_action_type in ('P','U') THEN
4441 			hr_utility.set_location('Inside P,U ..'||to_char(l_actid),1006);
4442 			l_max_action_id := csr_interlocks.locked_action_id;
4443 			hr_utility.set_location('l_max_action_id..'||l_max_action_id,1006);
4444 			hr_utility.set_location('v_action_id..'||v_action_id,1006);
4445 			hr_utility.set_location('B4 cursor csr_prepay_found..',1006);
4446 
4447 			OPEN csr_prepay_found (v_action_id,
4448                                    csr_interlocks.locked_action_id,
4449                                    l_dimension_name,
4450                                    l_Act_Context_id,
4451                                    l_Act_Context_value);
4452 			FETCH csr_prepay_found INTO l_arch_ppsn,
4453 								 l_arch_works_number,
4454 								 l_arch_person_id,
4455 								 l_arch_primary_flag,
4456 								 l_arch_asg_location_id, -- 10277535
4457 								 l_arch_org_id, --11674153
4458 								 l_arch_assignment_id,
4459 								 l_arch_assmt_action_id_bal,
4460 								 l_arch_tax_or_refund,
4461 							   --    l_arch_tax_deduction_basis,
4462 								 l_arch_surname,
4463 								 l_arch_first_name,
4464 								 l_arch_dob,
4465 								 l_arch_address_line1,
4466 								 l_arch_address_line2,
4467 								 l_arch_address_line3,
4468 								 l_arch_address_line4, -- BUG 4066315
4469 								 l_arch_hire_date,
4470 								 l_arch_term_date,
4471 								 l_period_type,
4472 							   --    l_arch_annual_tax_credit,
4473 								 l_arch_mothers_name,
4474 								 l_arch_pr_indicator,
4475 								 l_arch_previous_emp_pay,
4476 								 l_arch_previous_emp_tax, l_arch_previous_emp_pay_usc, l_arch_previous_emp_usc;  --14659262
4477 			   CLOSE csr_prepay_found;
4478 			hr_utility.set_location('After cursor csr_prepay_found..',1006);
4479 		   hr_utility.set_location('l_arch_works_number..'||l_arch_works_number,1006);
4480 		   hr_utility.set_location('l_arch_ppsn..'||l_arch_ppsn,1006);
4481 		   hr_utility.set_location('l_arch_primary_flag..'||l_arch_primary_flag,1006);
4482 		   hr_utility.set_location('l_arch_asg_location_id..'||l_arch_asg_location_id,1005); -- 10277535
4483 		   hr_utility.set_location('l_arch_org_id..'||l_arch_org_id,1005); -- 11674153
4484 		   hr_utility.set_location('l_arch_assignment_id..'||l_arch_assignment_id,1006);
4485 
4486 
4487 			    /* if data found in the prepayment cursor then call the below functions to retrieve the remaining data for archiving */
4488 			   -- Added K and M Employee and Employer figures for severance payment to variables l_arch_employees_prsi_cont and l_arch_total_prsi_cont
4489                            -- Passed Payroll Run assignment action id csr_interlocks.locked_action_id 4672715
4490 			   l_arch_net_tax :=
4491 				   TO_CHAR (
4492 					ROUND (
4493 					   NVL (
4494 						pay_balance_pkg.get_value (
4495 						   pay_ie_p35.get_defined_balance_id (
4496 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4497 							'IE Net Tax'
4498 						   ),
4499 						   csr_interlocks.locked_action_id,
4500 						   l_segment4, -- paye reference value
4501 						    null,
4502 						    l_Act_Context_id,  --null,
4503 						    l_Act_Context_value,  --null,
4504 						    null,
4505 						    null,
4506 						    null,
4507 						    'TRUE'
4508 						),
4509 						0
4510 					   ),
4511 					   2
4512 					)
4513 				   );
4514 			hr_utility.set_location('l_arch_net_tax..'||l_arch_net_tax,1006);
4515 			   l_arch_employees_prsi_cont :=
4516 				   TO_CHAR (
4517 					ROUND (
4518 					     NVL (
4519 						  pay_balance_pkg.get_value (
4520 						     pay_ie_p35.get_defined_balance_id (
4521 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4522 							  'IE PRSI Employee'
4523 						     ),
4524 						     csr_interlocks.locked_action_id,
4525 						  l_segment4, -- paye reference value
4526 						    null,
4527 						    l_Act_Context_id,  --null,
4528 						    l_Act_Context_value,  --null,
4529 						    null,
4530 						    null,
4531 						    null,
4532 						    'TRUE'
4533 						  ),
4534 						  0
4535 					     )
4536 					   + NVL (
4537 						  pay_balance_pkg.get_value (
4538 						     pay_ie_p35.get_defined_balance_id (
4539 							  l_dimension_name, --'_PER_PAYE_REF_YTD',--6633719
4540 							  'IE PRSI K Employee Lump Sum'
4541 						     ),
4542 						     csr_interlocks.locked_action_id,
4543 						   l_segment4, -- paye reference value
4544 						    null,
4545 						    l_Act_Context_id,  --null,
4546 						    l_Act_Context_value, --null,
4547 						    null,
4548 						    null,
4549 						    null,
4550 						    'TRUE'
4551 						  ),
4552 						  0
4553 					     )
4554 					   + NVL (
4555 						  pay_balance_pkg.get_value (
4556 						     pay_ie_p35.get_defined_balance_id (
4557 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4558 							  'IE PRSI M Employee Lump Sum'
4559 						     ),
4560 						     csr_interlocks.locked_action_id,
4561 						  l_segment4, -- paye reference value
4562 						    null,
4563 						    l_Act_Context_id,  --null,
4564 						    l_Act_Context_value, --null,
4565 						    null,
4566 						    null,
4567 						    null,
4568 						    'TRUE'
4569 						  ),
4570 						  0
4571 					     ),
4572 					   2
4573 					)
4574 				   );
4575 			hr_utility.set_location('l_arch_employees_prsi_cont..'||l_arch_employees_prsi_cont,1006);
4576 				l_arch_total_prsi_cont :=
4577 				   TO_CHAR (
4578 					ROUND (
4579 					     NVL (
4580 						  pay_balance_pkg.get_value (
4581 						     pay_ie_p35.get_defined_balance_id (
4582 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4583 							  'IE PRSI Employee'
4584 						     ),
4585 						     csr_interlocks.locked_action_id,
4586 						  l_segment4, -- paye reference value
4587 						    null,
4588 						    l_Act_Context_id,  --null,
4589 						    l_Act_Context_value, --null,
4590 						    null,
4591 						    null,
4592 						    null,
4593 						    'TRUE'
4594 						  ),
4595 						  0
4596 					     )
4597 					   + NVL (
4598 						  pay_balance_pkg.get_value (
4599 						     pay_ie_p35.get_defined_balance_id (
4600 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4601 							  'IE PRSI Employer'
4602 						     ),
4603 						     csr_interlocks.locked_action_id,
4604 						  l_segment4, -- paye reference value
4605 						    null,
4606 						    l_Act_Context_id,  --null,
4607 						    l_Act_Context_value,  --null,
4608 						    null,
4609 						    null,
4610 						    null,
4611 						    'TRUE'
4612 						  ),
4613 						  0
4614 					     )
4615 					   + NVL (
4616 						  pay_balance_pkg.get_value (
4617 						     pay_ie_p35.get_defined_balance_id (
4618 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4619 							  'IE PRSI K Employee Lump Sum'
4620 						     ),
4621 						     csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4622 						 l_segment4, -- paye reference value
4623 						    null,
4624 						    l_Act_Context_id,  --null,
4625 						    l_Act_Context_value,  --null,
4626 						    null,
4627 						    null,
4628 						    null,
4629 						    'TRUE'
4630 						  ),
4631 						  0
4632 					     )
4633 					   + NVL (
4634 						  pay_balance_pkg.get_value (
4635 						     pay_ie_p35.get_defined_balance_id (
4636 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4637 							  'IE PRSI M Employee Lump Sum'
4638 						     ),
4639 						     csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4640 						  l_segment4, -- paye reference value
4641 						    null,
4642 						    l_Act_Context_id,  --null,
4643 						    l_Act_Context_value,  --null,
4644 						    null,
4645 						    null,
4646 						    null,
4647 						    'TRUE'
4648 						  ),
4649 						  0
4650 					     )
4651 					   + NVL (
4652 						  pay_balance_pkg.get_value (
4653 						     pay_ie_p35.get_defined_balance_id (
4654 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4655 							  'IE PRSI K Employer Lump Sum'
4656 						     ),
4657 						     csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4658 						   l_segment4, -- paye reference value
4659 						    null,
4660 						    l_Act_Context_id,  --null,
4661 						    l_Act_Context_value,  --null,
4662 						    null,
4663 						    null,
4664 						    null,
4665 						    'TRUE'
4666 						  ),
4667 						  0
4668 					     )
4669 					   + NVL (
4670 						  pay_balance_pkg.get_value (
4671 						     pay_ie_p35.get_defined_balance_id (
4672 							  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4673 							  'IE PRSI M Employer Lump Sum'
4674 						     ),
4675 						     csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4676 						     l_segment4, -- paye reference value
4677 						    null,
4678 						    l_Act_Context_id, --null,
4679 						    l_Act_Context_value, --null,
4680 						    null,
4681 						    null,
4682 						    null,
4683 						    'TRUE'
4684 						  ),
4685 						  0
4686 					     ),
4687 					   2
4688 					)
4689 				   );
4690 			hr_utility.set_location('l_arch_total_prsi_cont..'||l_arch_total_prsi_cont,1006);
4691 				l_arch_pay :=
4692 				   TO_CHAR (
4693 					ROUND (
4694 					   NVL (
4695 						pay_balance_pkg.get_value (
4696 						   pay_ie_p35.get_defined_balance_id (
4697 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4698 							'IE Taxable Pay'
4699 						   ),
4700 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4701 						   l_segment4, -- paye reference value
4702 						    null,
4703 						    l_Act_Context_id,  --null,
4704 						    l_Act_Context_value,  --null,
4705 						    null,
4706 						    null,
4707 						    null,
4708 						    'TRUE'
4709 						),
4710 						0
4711 					   ),
4712 					   2
4713 					)
4714 				   );
4715 			hr_utility.set_location('l_arch_pay..'||l_arch_pay,1006);
4716 				l_arch_total_notional_pay :=
4717 				   TO_CHAR (
4718 					ROUND (
4719 					   NVL (
4720 						pay_balance_pkg.get_value (
4721 						   pay_ie_p35.get_defined_balance_id (
4722 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4723 							'IE BIK Taxable and PRSIable Pay'
4724 						   ),
4725 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4726 						   l_segment4, -- paye reference value
4727 						    null,
4728 						    l_Act_Context_id,  --null,
4729 						    l_Act_Context_value,  --null,
4730 						    null,
4731 						    null,
4732 						    null,
4733 						    'TRUE'
4734 						),
4735 						0
4736 					   ),
4737 					   2
4738 					)
4739 				   );
4740 			hr_utility.set_location('l_arch_total_notional_pay..'||l_arch_total_notional_pay,1006);
4741 --16306646
4742 				l_arch_total_share_scheme :=
4743 				   TO_CHAR (
4744 					ROUND (
4745 					   NVL (
4746 						pay_balance_pkg.get_value (
4747 						   pay_ie_p35.get_defined_balance_id (
4748 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4749 							'P35 Notional Pay Adjust Balance'  --'IE Share Schemes'
4750 						   ),
4751 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4752 						   l_segment4, -- paye reference value
4753 						    null,
4754 						    l_Act_Context_id,  --null,
4755 						    l_Act_Context_value,  --null,
4756 						    null,
4757 						    null,
4758 						    null,
4759 						    'TRUE'
4760 						),
4761 						0
4762 					   ),
4763 					   2
4764 					)
4765 				   );
4766 			hr_utility.set_location('l_arch_total_share_scheme..'||l_arch_total_share_scheme,1006);
4767 
4768 				l_p35_taxable_pay_adjust :=
4769 				   TO_CHAR (
4770 					ROUND (
4771 					   NVL (
4772 						pay_balance_pkg.get_value (
4773 						   pay_ie_p35.get_defined_balance_id (
4774 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4775 							'P35 Taxable Pay Adjust Balance'
4776 						   ),
4777 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4778 						   l_segment4, -- paye reference value
4779 						    null,
4780 						    l_Act_Context_id,  --null,
4781 						    l_Act_Context_value,  --null,
4782 						    null,
4783 						    null,
4784 						    null,
4785 						    'TRUE'
4786 						),
4787 						0
4788 					   ),
4789 					   2
4790 					)
4791 				   );
4792 			hr_utility.set_location('l_p35_taxable_pay_adjust..'||l_p35_taxable_pay_adjust,1006);
4793 
4794 				l_p35_gross_pay_adjust :=
4795 				   TO_CHAR (
4796 					ROUND (
4797 					   NVL (
4798 						pay_balance_pkg.get_value (
4799 						   pay_ie_p35.get_defined_balance_id (
4800 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4801 							'P35 Gross Pay Adjust Balance'
4802 						   ),
4803 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4804 						   l_segment4, -- paye reference value
4805 						    null,
4806 						    l_Act_Context_id,  --null,
4807 						    l_Act_Context_value,  --null,
4808 						    null,
4809 						    null,
4810 						    null,
4811 						    'TRUE'
4812 						),
4813 						0
4814 					   ),
4815 					   2
4816 					)
4817 				   );
4818 			hr_utility.set_location('l_p35_gross_pay_adjust..'||l_p35_gross_pay_adjust,1006);
4819 --16306646
4820 			/* Start Pension Balances */
4821 				l_arch_pen_emp_rbs :=
4822 				   TO_CHAR (
4823 					ROUND (
4824 					   NVL (
4825 						pay_balance_pkg.get_value (
4826 						   pay_ie_p35.get_defined_balance_id (
4827 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4828 							'IE RBS EE Contribution'
4829 						   ),
4830 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4831 						   l_segment4, -- paye reference value
4832 						    null,
4833 						    l_Act_Context_id,  --null,
4834 						    l_Act_Context_value,  --null,
4835 						    null,
4836 						    null,
4837 						    null,
4838 						    'TRUE'
4839 						),
4840 						0
4841 					   ),
4842 					   2
4843 					)
4844 					+
4845 					ROUND (
4846 					   NVL (
4847 						pay_balance_pkg.get_value (
4848 						   pay_ie_p35.get_defined_balance_id (
4849 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4850 							'IE RBS EE AVC Contribution'
4851 						   ),
4852 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4853 						   l_segment4, -- paye reference value
4854 						    null,
4855 						    l_Act_Context_id,  --null,
4856 						    l_Act_Context_value,  --null,
4857 						    null,
4858 						    null,
4859 						    null,
4860 						    'TRUE'
4861 						),
4862 						0
4863 					   ),
4864 					   2
4865 					)
4866 				   );
4867 			hr_utility.set_location('l_arch_pen_emp_rbs..'||l_arch_pen_emp_rbs,1006);
4868 			  l_arch_pen_empr_rbs :=
4869 			   TO_CHAR (
4870 				ROUND (
4871 				   NVL (
4872 					pay_balance_pkg.get_value (
4873 					   pay_ie_p35.get_defined_balance_id (
4874 						l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4875 						'IE RBS ER Contribution'
4876 					   ),
4877 					   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4878 					   l_segment4, -- paye reference value
4879 					    null,
4880 					    l_Act_Context_id,  --null,
4881 					    l_Act_Context_value,  --null,
4882 					    null,
4883 					    null,
4884 					    null,
4885 					    'TRUE'
4886 					),
4887 					0
4888 				   ),
4889 				   2
4890 				)
4891 			     );
4892 			hr_utility.set_location('l_arch_pen_empr_rbs..'||l_arch_pen_empr_rbs,1006);
4893 			l_arch_pen_emp_prsa :=
4894 				   TO_CHAR (
4895 					ROUND (
4896 					   NVL (
4897 						pay_balance_pkg.get_value (
4898 						   pay_ie_p35.get_defined_balance_id (
4899 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4900 							'IE PRSA EE Contribution'
4901 						   ),
4902 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4903 						  l_segment4, -- paye reference value
4904 						    null,
4905 						    l_Act_Context_id,  --null,
4906 						    l_Act_Context_value,  --null,
4907 						    null,
4908 						    null,
4909 						    null,
4910 						    'TRUE'
4911 						),
4912 						0
4913 					   ),
4914 					   2
4915 					)
4916 					+
4917 					ROUND (
4918 					   NVL (
4919 						pay_balance_pkg.get_value (
4920 						   pay_ie_p35.get_defined_balance_id (
4921 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4922 							'IE PRSA EE AVC Contribution'
4923 						   ),
4924 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4925 						  l_segment4, -- paye reference value
4926 						    null,
4927 						    l_Act_Context_id, --null,
4928 						    l_Act_Context_value,  --null,
4929 						    null,
4930 						    null,
4931 						    null,
4932 						    'TRUE'
4933 						),
4934 						0
4935 					   ),
4936 					   2
4937 					)
4938 				   );
4939 			hr_utility.set_location('l_arch_pen_emp_prsa..'||l_arch_pen_emp_prsa,1006);
4940 			  l_arch_pen_empr_prsa :=
4941 			   TO_CHAR (
4942 				ROUND (
4943 				   NVL (
4944 					pay_balance_pkg.get_value (
4945 					   pay_ie_p35.get_defined_balance_id (
4946 						l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4947 						'IE PRSA ER Contribution'
4948 					   ),
4949 					   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4950 					  l_segment4, -- paye reference value
4951 					    null,
4952 					    l_Act_Context_id, --null,
4953 					    l_Act_Context_value, --null,
4954 					    null,
4955 					    null,
4956 					    null,
4957 					    'TRUE'
4958 					),
4959 					0
4960 				   ),
4961 				   2
4962 				)
4963 			     );
4964 			hr_utility.set_location('l_arch_pen_empr_prsa..'||l_arch_pen_empr_prsa,1006);
4965 			l_arch_pen_emp_rac :=
4966 			   TO_CHAR (
4967 				ROUND (
4968 				   NVL (
4969 					pay_balance_pkg.get_value (
4970 					   pay_ie_p35.get_defined_balance_id (
4971 						l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
4972 						'IE RAC EE Contribution'
4973 					   ),
4974 					   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
4975 					   l_segment4, -- paye reference value
4976 					    null,
4977 					    l_Act_Context_id, --null,
4978 					    l_Act_Context_value, --null,
4979 					    null,
4980 					    null,
4981 					    null,
4982 					    'TRUE'
4983 					),
4984 					0
4985 				   ),
4986 				   2
4987 				)
4988 			     );
4989 			hr_utility.set_location('l_arch_pen_emp_rac..'||l_arch_pen_emp_rac,1006);
4990 			/* End Pension Balances */
4991 
4992 			/* 8520684 */
4993                         /* gross pay balances */
4994                         l_arch_gross_pay :=
4995 				   TO_CHAR (
4996 					ROUND (
4997 					   NVL (
4998 						pay_balance_pkg.get_value (
4999 						   pay_ie_p35.get_defined_balance_id (
5000 							l_dimension_name,
5001 							'IE Gross Income Adjustment'
5002 						   ),
5003 						   csr_interlocks.locked_action_id,
5004 						   l_segment4, -- paye reference value
5005 						    null,
5006 						    null,
5007 						    null,
5008 						    null,
5009 						    null,
5010 						    null,
5011 						    'TRUE'
5012 						),
5013 						0
5014 					   ),
5015 					   2
5016 					)
5017 				   )
5018 
5019 			          +
5020 
5021 				  TO_CHAR (
5022 					ROUND (
5023 					   NVL (
5024 						pay_balance_pkg.get_value (
5025 						   pay_ie_p35.get_defined_balance_id (
5026 							l_dimension_name,
5027 							'IE Gross Income'
5028 						   ),
5029 						   csr_interlocks.locked_action_id,
5030 						   l_segment4, -- paye reference value
5031 						    null,
5032 						    null,
5033 						    null,
5034 						    null,
5035 						    null,
5036 						    null,
5037 						    'TRUE'
5038 						),
5039 						0
5040 					   ),
5041 					   2
5042 					)
5043 				   )
5044 				   +
5045 				   TO_CHAR (
5046 					ROUND (
5047 					   NVL (
5048 						pay_balance_pkg.get_value (
5049 						   pay_ie_p35.get_defined_balance_id (
5050 							l_dimension_name,
5051 							'IE BIK Taxable and PRSIable Pay'
5052 						   ),
5053 						   csr_interlocks.locked_action_id,
5054 						   l_segment4, -- paye reference value
5055 						    null,
5056 						    null,
5057 						    null,
5058 						    null,
5059 						    null,
5060 						    null,
5061 						    'TRUE'
5062 						),
5063 						0
5064 					   ),
5065 					   2
5066 					)
5067 				   );
5068 
5069                         /* 8520684 */
5070                         /* income levy balances */
5071                         l_arch_income_levy :=
5072 				   TO_CHAR (
5073 					ROUND (
5074 					   NVL (
5075 						pay_balance_pkg.get_value (
5076 						   pay_ie_p35.get_defined_balance_id (
5077 							l_dimension_name,
5078 							'IE Income Tax Levy'
5079 						   ),
5080 						   csr_interlocks.locked_action_id,
5081 						   l_segment4, -- paye reference value
5082 						    null,
5083 						    null,
5084 						    null,
5085 						    null,
5086 						    null,
5087 						    null,
5088 						    'TRUE'
5089 						),
5090 						0
5091 					   ),
5092 					   2
5093 					)
5094 				   )
5095 				  /* 8978805 */
5096 				  /*
5097 				   +
5098 				   TO_CHAR (
5099 					ROUND (
5100 					   NVL (
5101 						pay_balance_pkg.get_value (
5102 						   pay_ie_p35.get_defined_balance_id (
5103 							l_dimension_name,
5104 							'IE Income Tax Levy Refund Amount'
5105 						   ),
5106 						   csr_interlocks.locked_action_id,
5107 						   l_segment4, -- paye reference value
5108 						    null,
5109 						    null,
5110 						    null,
5111 						    null,
5112 						    null,
5113 						    null,
5114 						    'TRUE'
5115 						),
5116 						0
5117 					   ),
5118 					   2
5119 					)
5120 				   ) */
5121 				   ;
5122                         /* 8520684 */
5123                         /* income levy first band */
5124                         l_arch_income_levy_first :=
5125 				   TO_CHAR (
5126 					ROUND (
5127 					   NVL (
5128 						pay_balance_pkg.get_value (
5129 						   pay_ie_p35.get_defined_balance_id (
5130 							l_dimension_name,
5131 							'IE Income Tax Levy First Band'
5132 						   ),
5133 						   csr_interlocks.locked_action_id,
5134 						   l_segment4, -- paye reference value
5135 						    null,
5136 						    null,
5137 						    null,
5138 						    null,
5139 						    null,
5140 						    null,
5141 						    'TRUE'
5142 						),
5143 						0
5144 					   ),
5145 					   2
5146 					)
5147 				   );
5148                         /* 8520684 */
5149                         /* income Levy second band balances */
5150                         l_arch_income_levy_second :=
5151 				   TO_CHAR (
5152 					ROUND (
5153 					   NVL (
5154 						pay_balance_pkg.get_value (
5155 						   pay_ie_p35.get_defined_balance_id (
5156 							l_dimension_name,
5157 							'IE Income Tax Levy Second Band'
5158 						   ),
5159 						   csr_interlocks.locked_action_id,
5160 						   l_segment4, -- paye reference value
5161 						    null,
5162 						    null,
5163 						    null,
5164 						    null,
5165 						    null,
5166 						    null,
5167 						    'TRUE'
5168 						),
5169 						0
5170 					   ),
5171 					   2
5172 					)
5173 				   );
5174                         /* 8520684 */
5175                         /* income levy third band balances */
5176                         l_arch_income_levy_third :=
5177 				   TO_CHAR (
5178 					ROUND (
5179 					   NVL (
5180 						pay_balance_pkg.get_value (
5181 						   pay_ie_p35.get_defined_balance_id (
5182 							l_dimension_name,
5183 							'IE Income Tax Levy Third Band'
5184 						   ),
5185 						   csr_interlocks.locked_action_id,
5186 						   l_segment4, -- paye reference value
5187 						    null,
5188 						    null,
5189 						    null,
5190 						    null,
5191 						    null,
5192 						    null,
5193 						    'TRUE'
5194 						),
5195 						0
5196 					   ),
5197 					   2
5198 					)
5199 				   );
5200                            /* 8520684 */
5201 
5202 --14656910
5203                         /* 8520684 */
5204                         /* IE Illness Benefit */
5205                         l_arch_illness_benefit :=
5206 				   TO_CHAR (
5207 					ROUND (
5208 					   NVL (
5209 						pay_balance_pkg.get_value (
5210 						   pay_ie_p35.get_defined_balance_id (
5211 							l_dimension_name,
5212 							'IE Illness Benefit'
5213 						   ),
5214 						   csr_interlocks.locked_action_id,
5215 						   l_segment4, -- paye reference value
5216 						    null,
5217 						    null,
5218 						    null,
5219 						    null,
5220 						    null,
5221 						    null,
5222 						    'TRUE'
5223 						),
5224 						0
5225 					   ),
5226 					   2
5227 					)
5228 				   );
5229                            /* 8520684 */
5230 --14656910
5231 			   /* Parking Levy balances */
5232 		           l_arch_parking_levy :=
5233 				   TO_CHAR (
5234 					ROUND (
5235 					   NVL (
5236 						pay_balance_pkg.get_value (
5237 						   pay_ie_p35.get_defined_balance_id (
5238 							l_dimension_name,
5239 							'IE Parking Levy'
5240 						   ),
5241 						   csr_interlocks.locked_action_id,
5242 						   l_segment4, -- paye reference value
5243 						    null,
5244 						    null,
5245 						    null,
5246 						    null,
5247 						    null,
5248 						    null,
5249 						    'TRUE'
5250 						),
5251 						0
5252 					   ),
5253 					   2
5254 					)
5255 				   );
5256 			-- BIK Medical insurance 5867343
5257 			l_medical_insurance :=
5258 				   TO_CHAR (
5259 					ROUND (
5260 					   NVL (
5261 						pay_balance_pkg.get_value (
5262 						   pay_ie_p35.get_defined_balance_id (
5263 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5264 							'IE BIK Medical Insurance'
5265 						   ),
5266 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
5267 						   l_segment4, -- paye reference value
5268 						    null,
5269 						    l_Act_Context_id,  --null,
5270 						    l_Act_Context_value, --null,
5271 						    null,
5272 						    null,
5273 						    null,
5274 						    'TRUE'
5275 						),
5276 						0
5277 					   ),
5278 					   2
5279 					)
5280 				     );
5281 			hr_utility.set_location('l_medical_insurance..'||l_medical_insurance,1006);
5282 
5283 --12382953
5284 
5285 /* gross pay USC balances */
5286                         l_arch_gross_pay_usc :=
5287 				   TO_CHAR (
5288 					ROUND (
5289 					   NVL (
5290 						pay_balance_pkg.get_value (
5291 						   pay_ie_p35.get_defined_balance_id (
5292 							l_dimension_name,
5293 							'IE Gross Income Adjustment'
5294 						   ),
5295 						   csr_interlocks.locked_action_id,
5296 						   l_segment4, -- paye reference value
5297 						    null,
5298 						    null,
5299 						    null,
5300 						    null,
5301 						    null,
5302 						    null,
5303 						    'TRUE'
5304 						),
5305 						0
5306 					   ),
5307 					   2
5308 					)
5309 				   )
5310 
5311 			          +
5312 
5313 				  TO_CHAR (
5314 					ROUND (
5315 					   NVL (
5316 						pay_balance_pkg.get_value (
5317 						   pay_ie_p35.get_defined_balance_id (
5318 							l_dimension_name,
5319 							'IE USCable Pay'
5320 						   ),
5321 						   csr_interlocks.locked_action_id,
5322 						   l_segment4, -- paye reference value
5323 						    null,
5324 						    null,
5325 						    null,
5326 						    null,
5327 						    null,
5328 						    null,
5329 						    'TRUE'
5330 						),
5331 						0
5332 					   ),
5333 					   2
5334 					)
5335 				   )
5336 				   +
5337 				   TO_CHAR (
5338 					ROUND (
5339 					   NVL (
5340 						pay_balance_pkg.get_value (
5341 						   pay_ie_p35.get_defined_balance_id (
5342 							l_dimension_name,
5343 							'IE BIK Taxable and PRSIable Pay'
5344 						   ),
5345 						   csr_interlocks.locked_action_id,
5346 						   l_segment4, -- paye reference value
5347 						    null,
5348 						    null,
5349 						    null,
5350 						    null,
5351 						    null,
5352 						    null,
5353 						    'TRUE'
5354 						),
5355 						0
5356 					   ),
5357 					   2
5358 					)
5359 				   )
5360 				   -
5361 				   TO_CHAR (
5362 					ROUND (
5363 					   NVL (
5364 						pay_balance_pkg.get_value (
5365 						   pay_ie_p35.get_defined_balance_id (
5366 							l_dimension_name,
5367 							'IE Court Order'
5368 						   ),
5369 						   csr_interlocks.locked_action_id,
5370 						   l_segment4, -- paye reference value
5371 						    null,
5372 						    null,
5373 						    null,
5374 						    null,
5375 						    null,
5376 						    null,
5377 						    'TRUE'
5378 						),
5379 						0
5380 					   ),
5381 					   2
5382 					)
5383 				   )
5384 --11076169
5385 				   +
5386 				   TO_CHAR (
5387 					ROUND (
5388 					   NVL (
5389 						pay_balance_pkg.get_value (
5390 						   pay_ie_p35.get_defined_balance_id (
5391 							l_dimension_name,
5392 							'IE Court Order Child Portion'
5393 						   ),
5394 						   csr_interlocks.locked_action_id,
5395 						   l_segment4, -- paye reference value
5396 						    null,
5397 						    null,
5398 						    null,
5399 						    null,
5400 						    null,
5401 						    null,
5402 						    'TRUE'
5403 						),
5404 						0
5405 					   ),
5406 					   2
5407 					)
5408 				   )
5409 --11076169
5410 --16242337
5411 				   +
5412 				   TO_CHAR (
5413 					ROUND (
5414 					   NVL (
5415 						pay_balance_pkg.get_value (
5416 						   pay_ie_p35.get_defined_balance_id (
5417 							l_dimension_name,
5418 							'IE PRSA ER Contribution'
5419 						   ),
5420 						   csr_interlocks.locked_action_id,
5421 						   l_segment4, -- paye reference value
5422 						    null,
5423 						    null,
5424 						    null,
5425 						    null,
5426 						    null,
5427 						    null,
5428 						    'TRUE'
5429 						),
5430 						0
5431 					   ),
5432 					   2
5433 					)
5434 				   );
5435 --16242337
5436 
5437 
5438 /* USC balances */
5439                         l_arch_usc :=
5440 				   TO_CHAR (
5441 					ROUND (
5442 					   NVL (
5443 						pay_balance_pkg.get_value (
5444 						   pay_ie_p35.get_defined_balance_id (
5445 							l_dimension_name,
5446 							'IE USC Balance'
5447 						   ),
5448 						   csr_interlocks.locked_action_id,
5449 						   l_segment4, -- paye reference value
5450 						    null,
5451 						    null,
5452 						    null,
5453 						    null,
5454 						    null,
5455 						    null,
5456 						    'TRUE'
5457 						),
5458 						0
5459 					   ),
5460 					   2
5461 					)
5462 				   );
5463 
5464 /* USC first band */
5465                         l_arch_usc_first :=
5466 				   TO_CHAR (
5467 					ROUND (
5468 					   NVL (
5469 						pay_balance_pkg.get_value (
5470 						   pay_ie_p35.get_defined_balance_id (
5471 							l_dimension_name,
5472 							'IE USC First Band'
5473 						   ),
5474 						   csr_interlocks.locked_action_id,
5475 						   l_segment4, -- paye reference value
5476 						    null,
5477 						    null,
5478 						    null,
5479 						    null,
5480 						    null,
5481 						    null,
5482 						    'TRUE'
5483 						),
5484 						0
5485 					   ),
5486 					   2
5487 					)
5488 				   );
5489 
5490 /* USC second band balances */
5491                         l_arch_usc_second :=
5492 				   TO_CHAR (
5493 					ROUND (
5494 					   NVL (
5495 						pay_balance_pkg.get_value (
5496 						   pay_ie_p35.get_defined_balance_id (
5497 							l_dimension_name,
5498 							'IE USC Second Band'
5499 						   ),
5500 						   csr_interlocks.locked_action_id,
5501 						   l_segment4, -- paye reference value
5502 						    null,
5503 						    null,
5504 						    null,
5505 						    null,
5506 						    null,
5507 						    null,
5508 						    'TRUE'
5509 						),
5510 						0
5511 					   ),
5512 					   2
5513 					)
5514 				   );
5515 
5516 /* USC third band balances */
5517                         l_arch_usc_third :=
5518 				   TO_CHAR (
5519 					ROUND (
5520 					   NVL (
5521 						pay_balance_pkg.get_value (
5522 						   pay_ie_p35.get_defined_balance_id (
5523 							l_dimension_name,
5524 							'IE USC Third Band'
5525 						   ),
5526 						   csr_interlocks.locked_action_id,
5527 						   l_segment4, -- paye reference value
5528 						    null,
5529 						    null,
5530 						    null,
5531 						    null,
5532 						    null,
5533 						    null,
5534 						    'TRUE'
5535 						),
5536 						0
5537 					   ),
5538 					   2
5539 					)
5540 				   );
5541 
5542 --12382953
5543 
5544 		     /*Bug No. 4063502*/
5545 		    --
5546 		     IF nvl(l_arch_pay,0) = 0 THEN
5547 			    l_arch_non_tax_pay :=
5548 					 TO_CHAR (
5549 					    ROUND (
5550 						 NVL (
5551 						    pay_balance_pkg.get_value (
5552 							 pay_ie_p35.get_defined_balance_id (
5553 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5554 							    'Total Pay'
5555 							 ),
5556 							 csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
5557 							 l_segment4, -- paye reference value
5558 							    null,
5559 							    l_Act_Context_id, --null,
5560 							    l_Act_Context_value,  --null,
5561 							    null,
5562 							    null,
5563 							    null,
5564 							    'TRUE'
5565 						    ),
5566 						    0
5567 						 ),
5568 						 2
5569 					    )
5570 					 );
5571 			hr_utility.set_location('l_arch_non_tax_pay..'||l_arch_non_tax_pay,1006);
5572 			 END IF;
5573 			/* lock this v_action_id*/
5574 			--
5575 			ELSE --v_action_type in ('R','Q','I','B','V') THEN
5576 				hr_utility.set_location('Inside R,Q ..'||to_char(l_actid),1007);
5577 				-- get data from run-reults
5578 				hr_utility.set_location('csr_interlocks.locked_action_id..'||csr_interlocks.locked_action_id,1007);
5579 
5580 				OPEN csr_run_results_found (csr_interlocks.locked_action_id,
5581                                             l_dimension_name,
5582                                             l_Act_Context_id,
5583                                             l_Act_Context_value);
5584 				FETCH csr_run_results_found INTO l_arch_ppsn,
5585 										l_arch_works_number,
5586 										l_arch_person_id,
5587 										l_arch_primary_flag,
5588 										l_arch_asg_location_id, --10277535
5589 										l_arch_org_id, --11674153
5590 										l_arch_assignment_id,
5591 										l_arch_assmt_action_id_bal,
5592 										l_arch_tax_or_refund,
5593 									--      l_arch_tax_deduction_basis,
5594 										l_arch_surname,
5595 										l_arch_first_name,
5596 										l_arch_dob,
5597 										l_arch_address_line1,
5598 										l_arch_address_line2,
5599 										l_arch_address_line3,
5600 										l_arch_address_line4,
5601 										l_arch_hire_date,
5602 										l_arch_term_date,
5603 										l_period_type,
5604 									--      l_arch_annual_tax_credit,
5605 										l_arch_mothers_name,
5606 										l_arch_pr_indicator,
5607 										l_arch_previous_emp_pay,
5608 										l_arch_previous_emp_tax, l_arch_previous_emp_pay, l_arch_previous_emp_usc; --14659262
5609 				CLOSE csr_run_results_found;
5610 
5611            hr_utility.set_location('After csr_run_results_found..',5001);
5612 		   hr_utility.set_location('l_arch_works_number..'||l_arch_works_number,5001);
5613 		   hr_utility.set_location('l_arch_ppsn..'||l_arch_ppsn,5001);
5614 		   hr_utility.set_location('l_arch_primary_flag..'||l_arch_primary_flag,5001);
5615 		   hr_utility.set_location('l_arch_asg_location_id..'||l_arch_asg_location_id,1005); -- 10277535
5616 		   hr_utility.set_location('l_arch_org_id..'||l_arch_org_id,1005); -- 11674153
5617 		   hr_utility.set_location('l_arch_assignment_id..'||l_arch_assignment_id,5001);
5618 
5619            hr_utility.set_location('l_arch_previous_emp_pay..'||l_arch_previous_emp_pay,5001);
5620            hr_utility.set_location('l_arch_previous_emp_pay_usc..'||l_arch_previous_emp_pay_usc,5001); --14659262
5621                   /* if data is found in the payroll run results cursor, then calculate the remaining values required for archiving */
5622 				   -- Added K and M Employee and Employer figures for severance payment to variables l_arch_employees_prsi_cont and l_arch_total_prsi_cont
5623 				   hr_utility.set_location ('B4 Arch Net Tax getval'|| l_arch_assmt_action_id_bal,996);
5624 				   l_arch_net_tax :=
5625 					   TO_CHAR (
5626 						ROUND (
5627 						   NVL (
5628 							pay_balance_pkg.get_value (
5629 							   pay_ie_p35.get_defined_balance_id (
5630 								l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5631 								'IE Net Tax'
5632 							   ),
5633 							   l_arch_assmt_action_id_bal,
5634 							   l_segment4, -- paye reference value
5635 							    null,
5636 							    l_Act_Context_id,  --null,
5637 							    l_Act_Context_value, --null,
5638 							    null,
5639 							    null,
5640 							    null,
5641 							    'TRUE'
5642 							),
5643 							0
5644 						   ),
5645 						   2
5646 						)
5647 					   );
5648                     hr_utility.set_location ('l_arch_net_tax'|| l_arch_net_tax,997);
5649 				   l_arch_employees_prsi_cont :=
5650 					   TO_CHAR (
5651 						ROUND (
5652 						     NVL (
5653 							  pay_balance_pkg.get_value (
5654 							     pay_ie_p35.get_defined_balance_id (
5655 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5656 								  'IE PRSI Employee'
5657 							     ),
5658 							     l_arch_assmt_action_id_bal,
5659 							    l_segment4, -- paye reference value
5660 							    null,
5661 							    l_Act_Context_id,  --null,
5662 							    l_Act_Context_value,  --null,
5663 							    null,
5664 							    null,
5665 							    null,
5666 							    'TRUE'
5667 							  ),
5668 							  0
5669 						     )
5670 						   + NVL (
5671 							  pay_balance_pkg.get_value (
5672 							     pay_ie_p35.get_defined_balance_id (
5673 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5674 								  'IE PRSI K Employee Lump Sum'
5675 							     ),
5676 							     l_arch_assmt_action_id_bal,
5677 							     l_segment4, -- paye reference value
5678 							    null,
5679 							    l_Act_Context_id, --null,
5680 							    l_Act_Context_value,  --null
5681 							    null,
5682 							    null,
5683 							    null,
5684 							    'TRUE'
5685 							  ),
5686 							  0
5687 						     )
5688 						   + NVL (
5689 							  pay_balance_pkg.get_value (
5690 							     pay_ie_p35.get_defined_balance_id (
5691 								  '_PER_YTD',
5692 								  'IE PRSI M Employee Lump Sum'
5693 							     ),
5694 							     l_arch_assmt_action_id_bal,
5695 							     l_segment4, -- paye reference value
5696 							    null,
5697 							    null,
5698 							    null,
5699 							    null,
5700 							    null,
5701 							    null,
5702 							    'TRUE'
5703 							  ),
5704 							  0
5705 						     ),
5706 						   2
5707 						)
5708 					   );
5709 hr_utility.set_location ('l_arch_employees_prsi_cont'|| l_arch_employees_prsi_cont,997);
5710 
5711 				   l_arch_total_prsi_cont :=
5712 					   TO_CHAR (
5713 						ROUND (
5714 						     NVL (
5715 							  pay_balance_pkg.get_value (
5716 							     pay_ie_p35.get_defined_balance_id (
5717 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5718 								  'IE PRSI Employee'
5719 							     ),
5720 							     l_arch_assmt_action_id_bal,
5721 							     l_segment4, -- paye reference value
5722 							    null,
5723 							    l_Act_Context_id,  --null,
5724 							    l_Act_Context_value,  --null,
5725 							    null,
5726 							    null,
5727 							    null,
5728 							    'TRUE'
5729 							  ),
5730 							  0
5731 						     )
5732 						   + NVL (
5733 							  pay_balance_pkg.get_value (
5734 							     pay_ie_p35.get_defined_balance_id (
5735 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5736 								  'IE PRSI Employer'
5737 							     ),
5738 							     l_arch_assmt_action_id_bal,
5739 							     l_segment4, -- paye reference value
5740 							    null,
5741 							    l_Act_Context_id,  --null,
5742 							    l_Act_Context_value,  --null,
5743 							    null,
5744 							    null,
5745 							    null,
5746 							    'TRUE'
5747 							  ),
5748 							  0
5749 						     )
5750 						   + NVL (
5751 							  pay_balance_pkg.get_value (
5752 							     pay_ie_p35.get_defined_balance_id (
5753 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5754 								  'IE PRSI K Employee Lump Sum'
5755 							     ),
5756 							     l_arch_assmt_action_id_bal,
5757 							   l_segment4, -- paye reference value
5758 							    null,
5759 							    l_Act_Context_id,  --null,
5760 							    l_Act_Context_value,  --null,
5761 							    null,
5762 							    null,
5763 							    null,
5764 							    'TRUE'
5765 							  ),
5766 							  0
5767 						     )
5768 						   + NVL (
5769 							  pay_balance_pkg.get_value (
5770 							     pay_ie_p35.get_defined_balance_id (
5771 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5772 								  'IE PRSI M Employee Lump Sum'
5773 							     ),
5774 							     l_arch_assmt_action_id_bal,
5775 							     l_segment4, -- paye reference value
5776 							    null,
5777 							    l_Act_Context_id,  --null,
5778 							    l_Act_Context_value,  --null,
5779 							    null,
5780 							    null,
5781 							    null,
5782 							    'TRUE'
5783 							  ),
5784 							  0
5785 						     )
5786 						   + NVL (
5787 							  pay_balance_pkg.get_value (
5788 							     pay_ie_p35.get_defined_balance_id (
5789 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5790 								  'IE PRSI K Employer Lump Sum'
5791 							     ),
5792 							     l_arch_assmt_action_id_bal,
5793 							     l_segment4, -- paye reference value
5794 							    null,
5795 							    l_Act_Context_id,  --null,
5796 							    l_Act_Context_value,  --null,
5797 							    null,
5798 							    null,
5799 							    null,
5800 							    'TRUE'
5801 							  ),
5802 							  0
5803 						     )
5804 						   + NVL (
5805 							  pay_balance_pkg.get_value (
5806 							     pay_ie_p35.get_defined_balance_id (
5807 								  l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5808 								  'IE PRSI M Employer Lump Sum'
5809 							     ),
5810 							     l_arch_assmt_action_id_bal,
5811 							     l_segment4, -- paye reference value
5812 							    null,
5813 							    l_Act_Context_id,  --null,
5814 							    l_Act_Context_value,  --null,
5815 							    null,
5816 							    null,
5817 							    null,
5818 							    'TRUE'
5819 							  ),
5820 							  0
5821 						     ),
5822 						   2
5823 						)
5824 					   );
5825 hr_utility.set_location ('l_arch_total_prsi_cont'|| l_arch_total_prsi_cont,998);
5826 				   l_arch_pay :=
5827 					   TO_CHAR (
5828 						ROUND (
5829 						   NVL (
5830 							pay_balance_pkg.get_value (
5831 							   pay_ie_p35.get_defined_balance_id (
5832 								l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5833 								'IE Taxable Pay'
5834 							   ),
5835 							   l_arch_assmt_action_id_bal,
5836 							   l_segment4, -- paye reference value
5837 							    null,
5838 							    l_Act_Context_id,  --null,
5839 							    l_Act_Context_value,  --null,
5840 							    null,
5841 							    null,
5842 							    null,
5843 							    'TRUE'
5844 							),
5845 							0
5846 						   ),
5847 						   2
5848 						)
5849 					   );
5850 				 hr_utility.set_location ('vik l_arch_assmt_action_id_bal '|| l_arch_assmt_action_id_bal,999);
5851 				 hr_utility.set_location ('vik l_segment4 '|| l_segment4,999);
5852 				 hr_utility.set_location ('vik l_arch_pay '|| l_arch_pay,999);
5853 
5854 				 hr_utility.set_location ('l_arch_total_notional_pay'|| l_arch_total_notional_pay,1990);
5855 				 l_arch_total_notional_pay :=
5856 					   TO_CHAR (
5857 						ROUND (
5858 						   NVL (
5859 							pay_balance_pkg.get_value (
5860 							   pay_ie_p35.get_defined_balance_id (
5861 								l_dimension_name,  ---'_PER_PAYE_REF_YTD',--6633719
5862 								'IE BIK Taxable and PRSIable Pay'
5863 							   ),
5864 							   l_arch_assmt_action_id_bal,
5865 							   l_segment4, -- paye reference value
5866 							    null,
5867 							    l_Act_Context_id, --null,
5868 							    l_Act_Context_value, --null,
5869 							    null,
5870 							    null,
5871 							    null,
5872 							    'TRUE'
5873 							),
5874 							0
5875 						   ),
5876 						   2
5877 						)
5878 					   );
5879 				 hr_utility.set_location ('l_arch_total_notional_pay'|| l_arch_total_notional_pay,1990);
5880 --16306646
5881 				 l_arch_total_share_scheme :=
5882 					   TO_CHAR (
5883 						ROUND (
5884 						   NVL (
5885 							pay_balance_pkg.get_value (
5886 							   pay_ie_p35.get_defined_balance_id (
5887 								l_dimension_name,  ---'_PER_PAYE_REF_YTD',--6633719
5888 								'P35 Notional Pay Adjust Balance'  --'IE Share Schemes'
5889 							   ),
5890 							   l_arch_assmt_action_id_bal,
5891 							   l_segment4, -- paye reference value
5892 							    null,
5893 							    l_Act_Context_id, --null,
5894 							    l_Act_Context_value, --null,
5895 							    null,
5896 							    null,
5897 							    null,
5898 							    'TRUE'
5899 							),
5900 							0
5901 						   ),
5902 						   2
5903 						)
5904 					   );
5905 				 hr_utility.set_location ('l_arch_total_share_scheme'|| l_arch_total_share_scheme,1990);
5906 
5907 				 l_p35_taxable_pay_adjust :=
5908 					   TO_CHAR (
5909 						ROUND (
5910 						   NVL (
5911 							pay_balance_pkg.get_value (
5912 							   pay_ie_p35.get_defined_balance_id (
5913 								l_dimension_name,  ---'_PER_PAYE_REF_YTD',--6633719
5914 								'P35 Taxable Pay Adjust Balance'
5915 							   ),
5916 							   l_arch_assmt_action_id_bal,
5917 							   l_segment4, -- paye reference value
5918 							    null,
5919 							    l_Act_Context_id, --null,
5920 							    l_Act_Context_value, --null,
5921 							    null,
5922 							    null,
5923 							    null,
5924 							    'TRUE'
5925 							),
5926 							0
5927 						   ),
5928 						   2
5929 						)
5930 					   );
5931 				 hr_utility.set_location ('l_p35_taxable_pay_adjust'|| l_p35_taxable_pay_adjust,1990);
5932 
5933 				 l_p35_gross_pay_adjust :=
5934 					   TO_CHAR (
5935 						ROUND (
5936 						   NVL (
5937 							pay_balance_pkg.get_value (
5938 							   pay_ie_p35.get_defined_balance_id (
5939 								l_dimension_name,  ---'_PER_PAYE_REF_YTD',--6633719
5940 								'P35 Gross Pay Adjust Balance'
5941 							   ),
5942 							   l_arch_assmt_action_id_bal,
5943 							   l_segment4, -- paye reference value
5944 							    null,
5945 							    l_Act_Context_id, --null,
5946 							    l_Act_Context_value, --null,
5947 							    null,
5948 							    null,
5949 							    null,
5950 							    'TRUE'
5951 							),
5952 							0
5953 						   ),
5954 						   2
5955 						)
5956 					   );
5957 				 hr_utility.set_location ('l_p35_gross_pay_adjust'|| l_p35_gross_pay_adjust,1990);
5958 --16306646
5959 			/* Start Pension Balances */
5960 				l_arch_pen_emp_rbs :=
5961 				   TO_CHAR (
5962 					ROUND (
5963 					   NVL (
5964 						pay_balance_pkg.get_value (
5965 						   pay_ie_p35.get_defined_balance_id (
5966 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5967 							'IE RBS EE Contribution'
5968 						   ),
5969 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
5970 						   l_segment4, -- paye reference value
5971 						    null,
5972 						    l_Act_Context_id,  --null,
5973 						    l_Act_Context_value,  --null,
5974 						    null,
5975 						    null,
5976 						    null,
5977 						    'TRUE'
5978 						),
5979 						0
5980 					   ),
5981 					   2
5982 					)
5983 					+
5984 					ROUND (
5985 					   NVL (
5986 						pay_balance_pkg.get_value (
5987 						   pay_ie_p35.get_defined_balance_id (
5988 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
5989 							'IE RBS EE AVC Contribution'
5990 						   ),
5991 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
5992 						   l_segment4, -- paye reference value
5993 						    null,
5994 						    l_Act_Context_id,  --null,
5995 						    l_Act_Context_value,  --null,
5996 						    null,
5997 						    null,
5998 						    null,
5999 						    'TRUE'
6000 						),
6001 						0
6002 					   ),
6003 					   2
6004 					)
6005 				   );
6006 				 hr_utility.set_location ('l_arch_pen_emp_rbs'|| l_arch_pen_emp_rbs,1990);
6007 				l_arch_pen_empr_rbs :=
6008 				   TO_CHAR (
6009 					ROUND (
6010 					   NVL (
6011 						pay_balance_pkg.get_value (
6012 						   pay_ie_p35.get_defined_balance_id (
6013 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6014 							'IE RBS ER Contribution'
6015 						   ),
6016 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
6017 						   l_segment4, -- paye reference value
6018 						    null,
6019 						    l_Act_Context_id,  --null,
6020 						    l_Act_Context_value,   --null,
6021 						    null,
6022 						    null,
6023 						    null,
6024 						    'TRUE'
6025 						),
6026 						0
6027 					   ),
6028 					   2
6029 					)
6030 				     );
6031 				 hr_utility.set_location ('l_arch_pen_empr_rbs'|| l_arch_pen_empr_rbs,1990);
6032 				l_arch_pen_emp_prsa :=
6033 					   TO_CHAR (
6034 						ROUND (
6035 						   NVL (
6036 							pay_balance_pkg.get_value (
6037 							   pay_ie_p35.get_defined_balance_id (
6038 								l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6039 								'IE PRSA EE Contribution'
6040 							   ),
6041 							   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
6042 							   l_segment4, -- paye reference value
6043 							    null,
6044 							    l_Act_Context_id,  --null,
6045 							    l_Act_Context_value,  --null,
6046 							    null,
6047 							    null,
6048 							    null,
6049 							    'TRUE'
6050 							),
6051 							0
6052 						   ),
6053 						   2
6054 						)
6055 						+
6056 						ROUND (
6057 						   NVL (
6058 							pay_balance_pkg.get_value (
6059 							   pay_ie_p35.get_defined_balance_id (
6060 								l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6061 								'IE PRSA EE AVC Contribution'
6062 							   ),
6063 							   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
6064 							  l_segment4, -- paye reference value
6065 							    null,
6066 							    l_Act_Context_id,  --null,
6067 							    l_Act_Context_value,  --null,
6068 							    null,
6069 							    null,
6070 							    null,
6071 							    'TRUE'
6072 							),
6073 							0
6074 						   ),
6075 						   2
6076 						)
6077 					   );
6078 				 hr_utility.set_location ('l_arch_pen_emp_prsa'|| l_arch_pen_emp_prsa,1990);
6079 				l_arch_pen_empr_prsa :=
6080 				   TO_CHAR (
6081 					ROUND (
6082 					   NVL (
6083 						pay_balance_pkg.get_value (
6084 						   pay_ie_p35.get_defined_balance_id (
6085 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6086 							'IE PRSA ER Contribution'
6087 						   ),
6088 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
6089 						   l_segment4, -- paye reference value
6090 							    null,
6091 							    l_Act_Context_id,  --null,
6092 							    l_Act_Context_value,  --null,
6093 							    null,
6094 							    null,
6095 							    null,
6096 							    'TRUE'
6097 						),
6098 						0
6099 					   ),
6100 					   2
6101 					)
6102 				     );
6103 				 hr_utility.set_location ('l_arch_pen_empr_prsa'|| l_arch_pen_empr_prsa,1990);
6104 				l_arch_pen_emp_rac :=
6105 				   TO_CHAR (
6106 					ROUND (
6107 					   NVL (
6108 						pay_balance_pkg.get_value (
6109 						   pay_ie_p35.get_defined_balance_id (
6110 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6111 							'IE RAC EE Contribution'
6112 						   ),
6113 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
6114 						  l_segment4, -- paye reference value
6115 							    null,
6116 							    l_Act_Context_id, --null,
6117 							    l_Act_Context_value,  --null,
6118 							    null,
6119 							    null,
6120 							    null,
6121 							    'TRUE'
6122 						),
6123 						0
6124 					   ),
6125 					   2
6126 					)
6127 				     );
6128 				 hr_utility.set_location ('l_arch_pen_emp_rac'|| l_arch_pen_emp_rac,1990);
6129 			/* End Pension Balances */
6130 
6131 			/* 8520684 */
6132                         /* gross pay balances */
6133                         l_arch_gross_pay :=
6134 				   TO_CHAR (
6135 					ROUND (
6136 					   NVL (
6137 						pay_balance_pkg.get_value (
6138 						   pay_ie_p35.get_defined_balance_id (
6139 							l_dimension_name,
6140 							'IE Gross Income Adjustment'
6141 						   ),
6142 						   csr_interlocks.locked_action_id,
6143 						   l_segment4, -- paye reference value
6144 						    null,
6145 						    null,
6146 						    null,
6147 						    null,
6148 						    null,
6149 						    null,
6150 						    'TRUE'
6151 						),
6152 						0
6153 					   ),
6154 					   2
6155 					)
6156 				   )
6157 
6158 			          +
6159 
6160 				  TO_CHAR (
6161 					ROUND (
6162 					   NVL (
6163 						pay_balance_pkg.get_value (
6164 						   pay_ie_p35.get_defined_balance_id (
6165 							l_dimension_name,
6166 							'IE Gross Income'
6167 						   ),
6168 						   csr_interlocks.locked_action_id,
6169 						   l_segment4, -- paye reference value
6170 						    null,
6171 						    null,
6172 						    null,
6173 						    null,
6174 						    null,
6175 						    null,
6176 						    'TRUE'
6177 						),
6178 						0
6179 					   ),
6180 					   2
6181 					)
6182 				   )
6183 				   +
6184 				   TO_CHAR (
6185 					ROUND (
6186 					   NVL (
6187 						pay_balance_pkg.get_value (
6188 						   pay_ie_p35.get_defined_balance_id (
6189 							l_dimension_name,
6190 							'IE BIK Taxable and PRSIable Pay'
6191 						   ),
6192 						   csr_interlocks.locked_action_id,
6193 						   l_segment4, -- paye reference value
6194 						    null,
6195 						    null,
6196 						    null,
6197 						    null,
6198 						    null,
6199 						    null,
6200 						    'TRUE'
6201 						),
6202 						0
6203 					   ),
6204 					   2
6205 					)
6206 				   );
6207 
6208                         /* 8520684 */
6209                         /* income levy balances */
6210                         l_arch_income_levy :=
6211 				   TO_CHAR (
6212 					ROUND (
6213 					   NVL (
6214 						pay_balance_pkg.get_value (
6215 						   pay_ie_p35.get_defined_balance_id (
6216 							l_dimension_name,
6217 							'IE Income Tax Levy'
6218 						   ),
6219 						   csr_interlocks.locked_action_id,
6220 						   l_segment4, -- paye reference value
6221 						    null,
6222 						    null,
6223 						    null,
6224 						    null,
6225 						    null,
6226 						    null,
6227 						    'TRUE'
6228 						),
6229 						0
6230 					   ),
6231 					   2
6232 					)
6233 				   )
6234 				   /* 8978805 */
6235 				   /*
6236 				   +
6237 				   TO_CHAR (
6238 					ROUND (
6239 					   NVL (
6240 						pay_balance_pkg.get_value (
6241 						   pay_ie_p35.get_defined_balance_id (
6242 							l_dimension_name,
6243 							'IE Income Tax Levy Refund Amount'
6244 						   ),
6245 						   csr_interlocks.locked_action_id,
6246 						   l_segment4, -- paye reference value
6247 						    null,
6248 						    null,
6249 						    null,
6250 						    null,
6251 						    null,
6252 						    null,
6253 						    'TRUE'
6254 						),
6255 						0
6256 					   ),
6257 					   2
6258 					)
6259 				   )*/
6260 				   ;
6261                         /* 8520684 */
6262                         /* income levy first band */
6263                         l_arch_income_levy_first :=
6264 				   TO_CHAR (
6265 					ROUND (
6266 					   NVL (
6267 						pay_balance_pkg.get_value (
6268 						   pay_ie_p35.get_defined_balance_id (
6269 							l_dimension_name,
6270 							'IE Income Tax Levy First Band'
6271 						   ),
6272 						   csr_interlocks.locked_action_id,
6273 						   l_segment4, -- paye reference value
6274 						    null,
6275 						    null,
6276 						    null,
6277 						    null,
6278 						    null,
6279 						    null,
6280 						    'TRUE'
6281 						),
6282 						0
6283 					   ),
6284 					   2
6285 					)
6286 				   );
6287                         /* 8520684 */
6288                         /* income Levy second band balances */
6289                         l_arch_income_levy_second :=
6290 				   TO_CHAR (
6291 					ROUND (
6292 					   NVL (
6293 						pay_balance_pkg.get_value (
6294 						   pay_ie_p35.get_defined_balance_id (
6295 							l_dimension_name,
6296 							'IE Income Tax Levy Second Band'
6297 						   ),
6298 						   csr_interlocks.locked_action_id,
6299 						   l_segment4, -- paye reference value
6300 						    null,
6301 						    null,
6302 						    null,
6303 						    null,
6304 						    null,
6305 						    null,
6306 						    'TRUE'
6307 						),
6308 						0
6309 					   ),
6310 					   2
6311 					)
6312 				   );
6313                         /* 8520684 */
6314                         /* income levy third band balances */
6315                         l_arch_income_levy_third :=
6316 				   TO_CHAR (
6317 					ROUND (
6318 					   NVL (
6319 						pay_balance_pkg.get_value (
6320 						   pay_ie_p35.get_defined_balance_id (
6321 							l_dimension_name,
6322 							'IE Income Tax Levy Third Band'
6323 						   ),
6324 						   csr_interlocks.locked_action_id,
6325 						   l_segment4, -- paye reference value
6326 						    null,
6327 						    null,
6328 						    null,
6329 						    null,
6330 						    null,
6331 						    null,
6332 						    'TRUE'
6333 						),
6334 						0
6335 					   ),
6336 					   2
6337 					)
6338 				   );
6339                            /* 8520684 */
6340 
6341 --14656910
6342                         /* 8520684 */
6343                         /* IE Illness Benefit */
6344                         l_arch_illness_benefit :=
6345 				   TO_CHAR (
6346 					ROUND (
6347 					   NVL (
6348 						pay_balance_pkg.get_value (
6349 						   pay_ie_p35.get_defined_balance_id (
6350 							l_dimension_name,
6351 							'IE Illness Benefit'
6352 						   ),
6353 						   csr_interlocks.locked_action_id,
6354 						   l_segment4, -- paye reference value
6355 						    null,
6356 						    null,
6357 						    null,
6358 						    null,
6359 						    null,
6360 						    null,
6361 						    'TRUE'
6362 						),
6363 						0
6364 					   ),
6365 					   2
6366 					)
6367 				   );
6368                            /* 8520684 */
6369 --14656910
6370 			   /* Parking Levy balances */
6371 		           l_arch_parking_levy :=
6372 				   TO_CHAR (
6373 					ROUND (
6374 					   NVL (
6375 						pay_balance_pkg.get_value (
6376 						   pay_ie_p35.get_defined_balance_id (
6377 							l_dimension_name,
6378 							'IE Parking Levy'
6379 						   ),
6380 						   csr_interlocks.locked_action_id,
6381 						   l_segment4, -- paye reference value
6382 						    null,
6383 						    null,
6384 						    null,
6385 						    null,
6386 						    null,
6387 						    null,
6388 						    'TRUE'
6389 						),
6390 						0
6391 					   ),
6392 					   2
6393 					)
6394 				   );
6395 			-- BIK Medical insurance
6396 			l_medical_insurance :=
6397 				   TO_CHAR (
6398 					ROUND (
6399 					   NVL (
6400 						pay_balance_pkg.get_value (
6401 						   pay_ie_p35.get_defined_balance_id (
6402 							l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6403 							'IE BIK Medical Insurance'
6404 						   ),
6405 						   csr_interlocks.locked_action_id, --l_arch_assmt_action_id_bal,
6406 						   l_segment4, -- paye reference value
6407 						    null,
6408 						    l_Act_Context_id,  --null,
6409 						    l_Act_Context_value,  --null,
6410 						    null,
6411 						    null,
6412 						    null,
6413 						    'TRUE'
6414 						),
6415 						0
6416 					   ),
6417 					   2
6418 					)
6419 				     );
6420 				 hr_utility.set_location ('l_medical_insurance'|| l_medical_insurance,1990);
6421 
6422 --12382953
6423 /* gross pay USC balances */
6424                         l_arch_gross_pay_usc :=
6425 				   TO_CHAR (
6426 					ROUND (
6427 					   NVL (
6428 						pay_balance_pkg.get_value (
6429 						   pay_ie_p35.get_defined_balance_id (
6430 							l_dimension_name,
6431 							'IE Gross Income Adjustment'
6432 						   ),
6433 						   csr_interlocks.locked_action_id,
6434 						   l_segment4, -- paye reference value
6435 						    null,
6436 						    null,
6437 						    null,
6438 						    null,
6439 						    null,
6440 						    null,
6441 						    'TRUE'
6442 						),
6443 						0
6444 					   ),
6445 					   2
6446 					)
6447 				   )
6448 
6449 			          +
6450 
6451 				  TO_CHAR (
6452 					ROUND (
6453 					   NVL (
6454 						pay_balance_pkg.get_value (
6455 						   pay_ie_p35.get_defined_balance_id (
6456 							l_dimension_name,
6457 							'IE USCable Pay'
6458 						   ),
6459 						   csr_interlocks.locked_action_id,
6460 						   l_segment4, -- paye reference value
6461 						    null,
6462 						    null,
6463 						    null,
6464 						    null,
6465 						    null,
6466 						    null,
6467 						    'TRUE'
6468 						),
6469 						0
6470 					   ),
6471 					   2
6472 					)
6473 				   )
6474 				   +
6475 				   TO_CHAR (
6476 					ROUND (
6477 					   NVL (
6478 						pay_balance_pkg.get_value (
6479 						   pay_ie_p35.get_defined_balance_id (
6480 							l_dimension_name,
6481 							'IE BIK Taxable and PRSIable Pay'
6482 						   ),
6483 						   csr_interlocks.locked_action_id,
6484 						   l_segment4, -- paye reference value
6485 						    null,
6486 						    null,
6487 						    null,
6488 						    null,
6489 						    null,
6490 						    null,
6491 						    'TRUE'
6492 						),
6493 						0
6494 					   ),
6495 					   2
6496 					)
6497 				   )
6498 				   -
6499 				   TO_CHAR (
6500 					ROUND (
6501 					   NVL (
6502 						pay_balance_pkg.get_value (
6503 						   pay_ie_p35.get_defined_balance_id (
6504 							l_dimension_name,
6505 							'IE Court Order'
6506 						   ),
6507 						   csr_interlocks.locked_action_id,
6508 						   l_segment4, -- paye reference value
6509 						    null,
6510 						    null,
6511 						    null,
6512 						    null,
6513 						    null,
6514 						    null,
6515 						    'TRUE'
6516 						),
6517 						0
6518 					   ),
6519 					   2
6520 					)
6521 				   )
6522 --11076169
6523 				   +
6524 				   TO_CHAR (
6525 					ROUND (
6526 					   NVL (
6527 						pay_balance_pkg.get_value (
6528 						   pay_ie_p35.get_defined_balance_id (
6529 							l_dimension_name,
6530 							'IE Court Order Child Portion'
6531 						   ),
6532 						   csr_interlocks.locked_action_id,
6533 						   l_segment4, -- paye reference value
6534 						    null,
6535 						    null,
6536 						    null,
6537 						    null,
6538 						    null,
6539 						    null,
6540 						    'TRUE'
6541 						),
6542 						0
6543 					   ),
6544 					   2
6545 					)
6546 				   )
6547 --11076169
6548 --16242337
6549 				   +
6550 				   TO_CHAR (
6551 					ROUND (
6552 					   NVL (
6553 						pay_balance_pkg.get_value (
6554 						   pay_ie_p35.get_defined_balance_id (
6555 							l_dimension_name,
6556 							'IE PRSA ER Contribution'
6557 						   ),
6558 						   csr_interlocks.locked_action_id,
6559 						   l_segment4, -- paye reference value
6560 						    null,
6561 						    null,
6562 						    null,
6563 						    null,
6564 						    null,
6565 						    null,
6566 						    'TRUE'
6567 						),
6568 						0
6569 					   ),
6570 					   2
6571 					)
6572 				   );
6573 --16242337
6574 
6575 
6576 /* USC balances */
6577                         l_arch_usc :=
6578 				   TO_CHAR (
6579 					ROUND (
6580 					   NVL (
6581 						pay_balance_pkg.get_value (
6582 						   pay_ie_p35.get_defined_balance_id (
6583 							l_dimension_name,
6584 							'IE USC Balance'
6585 						   ),
6586 						   csr_interlocks.locked_action_id,
6587 						   l_segment4, -- paye reference value
6588 						    null,
6589 						    null,
6590 						    null,
6591 						    null,
6592 						    null,
6593 						    null,
6594 						    'TRUE'
6595 						),
6596 						0
6597 					   ),
6598 					   2
6599 					)
6600 				   );
6601 
6602 /* USC first band */
6603                         l_arch_usc_first :=
6604 				   TO_CHAR (
6605 					ROUND (
6606 					   NVL (
6607 						pay_balance_pkg.get_value (
6608 						   pay_ie_p35.get_defined_balance_id (
6609 							l_dimension_name,
6610 							'IE USC First Band'
6611 						   ),
6612 						   csr_interlocks.locked_action_id,
6613 						   l_segment4, -- paye reference value
6614 						    null,
6615 						    null,
6616 						    null,
6617 						    null,
6618 						    null,
6619 						    null,
6620 						    'TRUE'
6621 						),
6622 						0
6623 					   ),
6624 					   2
6625 					)
6626 				   );
6627 
6628 /* USC second band balances */
6629                         l_arch_usc_second :=
6630 				   TO_CHAR (
6631 					ROUND (
6632 					   NVL (
6633 						pay_balance_pkg.get_value (
6634 						   pay_ie_p35.get_defined_balance_id (
6635 							l_dimension_name,
6636 							'IE USC Second Band'
6637 						   ),
6638 						   csr_interlocks.locked_action_id,
6639 						   l_segment4, -- paye reference value
6640 						    null,
6641 						    null,
6642 						    null,
6643 						    null,
6644 						    null,
6645 						    null,
6646 						    'TRUE'
6647 						),
6648 						0
6649 					   ),
6650 					   2
6651 					)
6652 				   );
6653 
6654 /* USC third band balances */
6655                         l_arch_usc_third :=
6656 				   TO_CHAR (
6657 					ROUND (
6658 					   NVL (
6659 						pay_balance_pkg.get_value (
6660 						   pay_ie_p35.get_defined_balance_id (
6661 							l_dimension_name,
6662 							'IE USC Third Band'
6663 						   ),
6664 						   csr_interlocks.locked_action_id,
6665 						   l_segment4, -- paye reference value
6666 						    null,
6667 						    null,
6668 						    null,
6669 						    null,
6670 						    null,
6671 						    null,
6672 						    'TRUE'
6673 						),
6674 						0
6675 					   ),
6676 					   2
6677 					)
6678 				   );
6679 
6680 --12382953
6681 
6682 				/*Bug No. 4063502*/
6683 				IF nvl(l_arch_pay,0) = 0 THEN
6684 				   hr_utility.set_location ('l_arch_non_tax_pay'|| l_arch_assmt_action_id_bal,1991);
6685 				    l_arch_non_tax_pay :=
6686 						 TO_CHAR (
6687 						    ROUND (
6688 							 NVL (
6689 							    pay_balance_pkg.get_value (
6690 								 pay_ie_p35.get_defined_balance_id (
6691 								    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
6692 								    'Total Pay'
6693 								 ),
6694 								 l_arch_assmt_action_id_bal,
6695 								 l_segment4, -- paye reference value
6696 							    null,
6697 							    l_Act_Context_id,  --null,
6698 							    l_Act_Context_value,  --null,
6699 							    null,
6700 							    null,
6701 							    null,
6702 							    'TRUE'
6703 							    ),
6704 							    0
6705 							 ),
6706 							 2
6707 						    )
6708 						 );
6709 				END IF;
6710 				 hr_utility.set_location ('l_arch_non_tax_pay'|| l_arch_non_tax_pay,1990);
6711 		     END IF;
6712 		    --setting the assignment id to fetch PRSI values
6713                 l_max_assignment_id := l_arch_assignment_id;
6714 		    l_max_action_id	:= csr_interlocks.locked_action_id;
6715 	     END IF;
6716 	     cnt := cnt +1;
6717 
6718 		hr_utility.set_location('before csr_get_primary_flag_active.'||v_action_id,1991);
6719 		hr_utility.set_location('l_arch_previous_emp_pay.'||l_arch_previous_emp_pay,5001);
6720 		hr_utility.set_location('l_arch_previous_emp_pay_usc.'||l_arch_previous_emp_pay_usc,5001);  --14659262
6721 
6722 		OPEN csr_get_primary_flag_active(v_action_id);
6723 		FETCH csr_get_primary_flag_active into v_work_number,v_primary_flag,asg_assignment_id,v_date;
6724 		IF csr_get_primary_flag_active%NOTFOUND then
6725 			hr_utility.set_location('Inside csr_get_primary_flag_active.'||v_action_id,1992);
6726 			OPEN csr_get_primary_flag(v_action_id);
6727 			FETCH csr_get_primary_flag into v_work_number,v_primary_flag,asg_assignment_id;
6728 			CLOSE csr_get_primary_flag;
6729 			hr_utility.set_location('Inside csr_get_primary_flag_active.'||v_action_id,1993);
6730 		END IF;
6731 		hr_utility.set_location('CLOSE csr_get_primary_flag_active.'||v_action_id,1994);
6732 		CLOSE csr_get_primary_flag_active;
6733 
6734 		hr_utility.set_location('v_primary_flag ..'||v_primary_flag,1008);
6735 		hr_utility.set_location('l_arch_works_number ..'||l_arch_works_number,1008);
6736 		hr_utility.set_location('v_work_number ..'||v_work_number,1008);
6737 
6738 		IF v_primary_flag = 'Y' then
6739 		     IF l_ppsn_override IS NULL THEN  --6633719
6740 			 l_arch_works_number := v_work_number;
6741 			 END IF;
6742 			l_arch_previous_emp_pay := NVL (
6743 			 ROUND (
6744 			    TO_NUMBER (
6745 				 pay_balance_pkg.get_value (
6746 				    pay_ie_p35.get_defined_balance_id (
6747 					 '_ASG_YTD',
6748 					 'IE P45 Pay'
6749 				    ),
6750 				    csr_interlocks.locked_action_id
6751 				 )
6752 			    ),
6753 			    2
6754 			 ),
6755 			 0
6756 		    );
6757 hr_utility.set_location('l_arch_previous_emp_pay.'||l_arch_previous_emp_pay,5001);
6758 --14659262
6759 			l_arch_previous_emp_pay_usc := NVL (
6760 			 ROUND (
6761 			    TO_NUMBER (
6762 				 pay_balance_pkg.get_value (
6763 				    pay_ie_p35.get_defined_balance_id (
6764 					 '_ASG_YTD',
6765 					 'IE P45 USC Pay'
6766 				    ),
6767 				    csr_interlocks.locked_action_id
6768 				 )
6769 			    ),
6770 			    2
6771 			 ),
6772 			 0
6773 		    );
6774 hr_utility.set_location('l_arch_previous_emp_pay_usc.'||l_arch_previous_emp_pay_usc,5001);
6775 --14659262
6776 
6777 		    l_arch_previous_emp_tax :=  NVL (
6778 			 ROUND (
6779 			    TO_NUMBER (
6780 				 pay_balance_pkg.get_value (
6781 				    pay_ie_p35.get_defined_balance_id (
6782 					 '_ASG_YTD',
6783 					 'IE P45 Tax Deducted'
6784 				    ),
6785 				    csr_interlocks.locked_action_id
6786 				 )
6787 			    ),
6788 			    2
6789 			 ),
6790 			 0
6791 		    );
6792 hr_utility.set_location('l_arch_previous_emp_tax.'||l_arch_previous_emp_tax,5001);
6793 
6794 --14659262
6795 		    l_arch_previous_emp_usc :=  NVL (
6796 			 ROUND (
6797 			    TO_NUMBER (
6798 				 pay_balance_pkg.get_value (
6799 				    pay_ie_p35.get_defined_balance_id (
6800 					 '_ASG_YTD',
6801 					 'IE P45 USC Deducted'
6802 				    ),
6803 				    csr_interlocks.locked_action_id
6804 				 )
6805 			    ),
6806 			    2
6807 			 ),
6808 			 0
6809 		    );
6810 hr_utility.set_location('l_arch_previous_emp_usc.'||l_arch_previous_emp_usc,5001);
6811 --14659262
6812 			--EXIT;
6813 			--setting the assignment id to fetch PRSI values
6814 			--6633719
6815 			IF asg_assignment_id <> l_max_assignment_id AND l_ppsn_override IS NULL THEN
6816 				l_max_assignment_id := asg_assignment_id;
6817 			END IF;
6818 		END IF;
6819 		 --
6820 	      hr_utility.set_location('l_arch_previous_emp_pay.'||l_arch_previous_emp_pay,5002);
6821         hr_utility.set_location('l_arch_previous_emp_pay_usc.'||l_arch_previous_emp_pay_usc,5002);  --14659262
6822 	      --
6823 	      IF (	v_action_type not in ('P','U','X') or v_action_type is null) then
6824 			v_action_id := csr_interlocks.locked_action_id;
6825 			hr_utility.set_location('Inside if ..'||v_action_id,2001);
6826 		ELSE
6827 		/* create a child assignment action and lock the P30 or prepayment
6828 		   action. The need for having child assignment action for
6829 		   retry of pay_payroll action.
6830 		 */
6831 			hr_utility.set_location('Inside Else ..',2002);
6832 			SELECT pay_assignment_actions_s.NEXTVAL
6833 			INTO l_actid
6834 			FROM DUAL;
6835 			OPEN get_assignment_id;
6836 			FETCH get_assignment_id into v_payroll_action_id,v_assignment_id,v_chunk;
6837 			CLOSE get_assignment_id;
6838 			hr_nonrun_asact.insact (l_actid,
6839 							v_assignment_id,
6840 							v_payroll_action_id,
6841 							v_chunk,
6842 							to_number(l_segment4),
6843 							status       => 'C',
6844 							source_act => p_assactid
6845 							);
6846 			hr_utility.set_location('Inside Else ..'||v_action_id,2003);
6847 			hr_nonrun_asact.insint (l_actid,v_action_id);
6848 		END IF;
6849 	END LOOP;
6850 	-- Calculate values common for the three
6851 	--6633719
6852 	/* picking the works number of primary assignment for PPSN OVERRIDE*/
6853 	IF l_ppsn_override IS NOT NULL THEN
6854 
6855         hr_utility.set_location('before l_arch_works_number ..'||l_arch_works_number,1008);
6856         hr_utility.set_location('before l_ppsn_override ..'||l_ppsn_override,1008);
6857 
6858     	OPEN csr_get_primary_flag_active1(l_ppsn_override);
6859 		FETCH csr_get_primary_flag_active1 into l_arch_works_number;
6860 		hr_utility.set_location('Inside csr_get_primary_flag_active1.'||v_assignment_id,1992);
6861 		IF csr_get_primary_flag_active1%NOTFOUND then
6862 			OPEN csr_get_primary_flag1(l_ppsn_override);
6863 			FETCH csr_get_primary_flag1 into l_arch_works_number;
6864 			CLOSE csr_get_primary_flag1;
6865 			hr_utility.set_location('Inside csr_get_primary_flag1.'||v_assignment_id,1993);
6866 		END IF;
6867 		hr_utility.set_location('CLOSE csr_get_primary_flag_active1.',1994);
6868 		CLOSE csr_get_primary_flag_active1;
6869 		hr_utility.set_location('after l_arch_works_number ..'||l_arch_works_number,1008);
6870 	END IF;
6871 	--6633719
6872 
6873 	hr_utility.set_location ('Starting on other common values', 10);
6874 	l_arch_totwks_insurble_emplmnt :=
6875 	   TO_CHAR (
6876 		NVL (
6877 		   pay_ie_p35.get_total_insurable_weeks (l_arch_person_id
6878 									,to_number(l_segment4)
6879 									,l_max_action_id
6880 									,l_Act_Context_id   --6633719
6881 									,l_Act_Context_value  --6633719
6882 									,l_dimension_name  --6633719
6883                                     ,l_ppsn_override),  --6633719
6884 		   0
6885 		)
6886 	   );
6887 hr_utility.set_location('l_arch_totwks_insurble_emplmnt.'||l_arch_totwks_insurble_emplmnt,5001);
6888 --
6889 
6890 	l_arch_initial_class :=
6891 	     NVL (pay_ie_p35.get_initial_class (l_max_action_id,to_number(l_segment4),l_ppsn_override), ' '); --6633719
6892 	   -- class A is displayed when PRSIable pay is zero.
6893 	   -- Eliminate class A.
6894 	   IF l_arch_pay = 0 or l_arch_initial_class = 'A' THEN
6895 		l_arch_initial_class := NULL;
6896 	   END if;
6897 	/*Bug fix 4049920*/
6898 	IF l_arch_term_date <> '31-12-4712' THEN
6899 		hr_utility.set_location (   'Actual Termination date  -'
6900 				    || l_arch_term_date, 15);
6901 		OPEN csr_annual_tax_credit(l_max_assignment_id,TO_DATE(l_arch_term_date,'dd-mm-yyyy'));
6902 		FETCH csr_annual_tax_credit INTO l_arch_tax_deduction_basis,l_arch_annual_tax_credit;
6903 		CLOSE csr_annual_tax_credit;
6904 	ELSE
6905 		OPEN csr_paye_details(l_max_assignment_id,l_period_type);
6906 		FETCH csr_paye_details INTO l_arch_tax_deduction_basis,l_arch_annual_tax_credit;
6907 		CLOSE csr_paye_details;
6908 
6909 	END IF;
6910 --12382953
6911       IF l_excl_count <> 0 THEN
6912 	    l_arch_tax_deduction_basis  := '3';
6913           l_exclusion_order := '1';
6914 	END IF;
6915 --12382953
6916 
6917 	hr_utility.set_location ('Termination date  -'|| l_arch_term_date, 15);
6918 
6919 	hr_utility.set_location('Before initial Class',101);
6920 	hr_utility.set_location('initial Class..'||nvl(l_arch_initial_class,'A'),101);
6921 
6922 -- diaplay classes only if the total pay has value.
6923 	IF l_arch_pay <> 0  THEN
6924 		--l_prsi_class_tab(1).prsi_class := l_arch_initial_class;
6925 		--l_prsi_class_tab(1).prsi_class_bal := get_prsi_weeks(t_context_value(1),
6926 		--									     to_number(l_segment4)); -- some dummy value
6927 		hr_utility.set_location('vik t_context_value.COUNT..'||t_context_value.COUNT,100);
6928 		FOR j in 1..t_context_value.COUNT
6929 		LOOP
6930 			l_prsi_class_tab(j).prsi_class := substr(t_context_value(j),4,2);
6931 			l_prsi_class_tab(j).prsi_class_bal := get_prsi_weeks(t_context_value(j),
6932 											     to_number(l_segment4));
6933 		END LOOP;
6934 	END IF;
6935 hr_utility.set_location('l_arch_previous_emp_pay..'||l_arch_previous_emp_pay,5002.4);
6936 hr_utility.set_location('l_arch_previous_emp_pay_usc..'||l_arch_previous_emp_pay_usc,5002.4);  --14659262
6937 hr_utility.set_location('initial Class..'||nvl(l_arch_initial_class,'B'),102);
6938 
6939 --8259095
6940 hr_utility.set_location('l_supp_wk_tab.COUNT:'||l_supp_wk_tab.COUNT,102);
6941 IF l_supp_wk_tab.COUNT > 0 THEN  --9394859
6942           FOR j in 1..l_prsi_class_tab.COUNT LOOP
6943              IF l_supp_wk_tab.EXISTS(l_prsi_class_tab(j).prsi_class) THEN
6944 hr_utility.set_location('l_supp_wk_tab() Value:'||l_supp_wk_tab(l_prsi_class_tab(j).prsi_class),102);
6945                  l_prsi_class_tab(j).prsi_class_bal := l_prsi_class_tab(j).prsi_class_bal + l_supp_wk_tab(l_prsi_class_tab(j).prsi_class);
6946              END IF;
6947           END LOOP;
6948 
6949           IF l_prsi_class_tab.COUNT > 0 Then
6950           FOR i IN 1..l_prsi_class_tab.COUNT LOOP
6951              If l_prsi_class_tab(i).prsi_class_bal = 0 Then
6952                 l_prsi_class_tab.DELETE(i);
6953              End If;
6954           END LOOP;
6955           End If;
6956 
6957 l_cnt := 0;
6958 l_pl_cnt := l_prsi_class_tab.FIRST;
6959  LOOP
6960     EXIT WHEN l_pl_cnt IS NULL;
6961     l_cnt := l_cnt + 1;
6962     l_prsi_class_tab1(l_cnt) := l_prsi_class_tab(l_pl_cnt);
6963     l_pl_cnt := l_prsi_class_tab.NEXT (l_pl_cnt);
6964  END LOOP;
6965 
6966  l_prsi_class_tab := l_prsi_class_tab1;
6967 END IF; --9394859
6968 
6969 --8259095
6970 
6971 /* if for eg second class and third class exists but weeks at second class is zero
6972    then third class will become the second class ie it is promoted */
6973 hr_utility.set_location('Before initial Class',101);
6974 hr_utility.set_location('initial Class..'||nvl(l_arch_initial_class,'Y'),101);
6975 hr_utility.set_location('vik l_prsi_class_tab.COUNT..'||l_prsi_class_tab.COUNT,102);
6976 
6977 --Collect all PRSI classes with non-zero PRSI weeks in a separate PL/SQL table
6978 l_cnt :=0;
6979 FOR i in 1..l_prsi_class_tab.COUNT
6980 LOOP
6981 	-- Bug 5864713, added check l_arch_total_prsi_cont > 0
6982 	IF (l_prsi_class_tab(i).prsi_class_bal<>0  or l_arch_total_prsi_cont > 0) and l_prsi_class_tab(i).prsi_class <> 'A' then
6983 		l_cnt := l_cnt + 1;
6984 		l_prsi_class_bal(l_cnt).prsi_class := l_prsi_class_tab(i).prsi_class;
6985 		l_prsi_class_bal(l_cnt).prsi_class_bal := l_prsi_class_tab(i).prsi_class_bal;
6986 		hr_utility.set_location('l_prsi_class_tab.COUNT'||l_prsi_class_tab.COUNT,101);
6987 		hr_utility.set_location('l_prsi_class_bal'||l_cnt||l_prsi_class_tab(i).prsi_class,101);
6988 		hr_utility.set_location('l_prsi_class_bal'||l_cnt||l_prsi_class_tab(i).prsi_class_bal,102);
6989 	END IF;
6990 END LOOP;
6991 
6992 hr_utility.set_location('l_arch_previous_emp_pay..'||l_arch_previous_emp_pay,5002.5);
6993 hr_utility.set_location('l_arch_previous_emp_pay_usc..'||l_arch_previous_emp_pay_usc,5002.5);  --14659262
6994 
6995 -- get the initial ,first , second, third, fourth and fifth from the non zero
6996 -- plsql table.Sine the req is to display only non zero clases
6997 IF l_cnt >=1 then
6998 	if l_prsi_class_bal(1).prsi_class is not null then
6999 		l_arch_initial_class	     := l_prsi_class_bal(1).prsi_class;
7000 		l_arch_weeks_at_initial_class := l_prsi_class_bal(1).prsi_class_bal;
7001 	end if;
7002 END IF;
7003 
7004 
7005 IF l_cnt >1 then
7006 	if l_prsi_class_bal(2).prsi_class is not null then
7007 		l_arch_second_class	     := l_prsi_class_bal(2).prsi_class;
7008 		l_arch_weeks_at_second_class := l_prsi_class_bal(2).prsi_class_bal;
7009 	end if;
7010 END IF;
7011 hr_utility.set_location('Hi',104);
7012 IF l_cnt >2 then
7013 	if l_prsi_class_bal(3).prsi_class is not null then
7014 		l_arch_third_class	     := l_prsi_class_bal(3).prsi_class;
7015 		l_arch_weeks_at_third_class  := l_prsi_class_bal(3).prsi_class_bal;
7016 	end if;
7017 END IF;
7018 
7019 IF l_cnt >3 then
7020 	if l_prsi_class_bal(4).prsi_class is not null then
7021 		l_arch_fourth_class	     := l_prsi_class_bal(4).prsi_class;
7022 		l_arch_weeks_at_fourth_class := l_prsi_class_bal(4).prsi_class_bal;
7023 	end if;
7024 END IF;
7025 IF l_cnt >4 then
7026 	if l_prsi_class_bal(5).prsi_class is not null then
7027 		l_arch_fifth_class:= l_prsi_class_bal(5).prsi_class||'-'||l_prsi_class_bal(5).prsi_class_bal;
7028 		l_arch_initial_class := l_arch_initial_class||'-'||l_arch_weeks_at_initial_class;
7029 	end if;
7030 END IF;
7031 
7032 	 l_arch_weeks_at_initial_class       := NVL(l_arch_weeks_at_second_class,0);
7033 	 l_arch_weeks_at_second_class       := NVL(l_arch_weeks_at_second_class,0);
7034 	 l_arch_weeks_at_third_class		:= NVL(l_arch_weeks_at_third_class,0);
7035 	 l_arch_weeks_at_fourth_class		:= NVL(l_arch_weeks_at_fourth_class,0);
7036 	 l_arch_weeks_at_fifth_class		:= NVL(l_arch_weeks_at_fifth_class,0);
7037 	 l_arch_initial_class			:= NVL(l_arch_initial_class,' ');
7038 	 l_arch_second_class			:= NVL(l_arch_second_class,' ');
7039 	 l_arch_third_class			:= NVL(l_arch_third_class,' ');
7040 	 l_arch_fourth_class			:= NVL(l_arch_fourth_class,' ');
7041 
7042 	   /* Date will be locked now. */
7043 	 hr_utility.set_location ('b4 INSINT Locking ID' ||L_ACTID,994);
7044 	 hr_utility.set_location ('b4 INSACT Locked ID ' ||l_locked_action,995);
7045 
7046 
7047 	hr_utility.set_location ('Asg ID  -'|| l_max_assignment_id,14);
7048 	hr_utility.set_location (   'Asg Act ID  -'|| l_locked_action, 15);
7049 
7050 	-- For BUG Fix 4066315
7051 	-- Concatination of employee address line 2 with line 3 and remaining line 3 with line 4
7052 	if (l_arch_address_line3 is not null) then
7053 		l_length_address_line2 := LENGTH(l_arch_address_line2);
7054 		l_available_space := 29 - l_length_address_line2; -- -1 for including the space
7055 		if l_available_space < 0 then
7056 			l_available_space := 0;
7057 		end if;
7058 		l_arch_address_line2:=l_arch_address_line2||' '||SUBSTR(l_arch_address_line3,1,l_available_space);
7059 		l_arch_address_line3:=(SUBSTR(l_arch_address_line3,l_available_space+1,14))||' '||l_arch_address_line4;
7060 	else
7061 		l_arch_address_line3:=l_arch_address_line4;
7062 	end if;
7063 
7064 	/***** Open curosrs for previous employment balances ****/
7065 	-- removed the condition l_arch_previous_emp_pay for 5435931.
7066 	-- as case can come where person is rehired but not P45 is entered.
7067 	-- so in this l_arch_previous_emp_pay will be zero. So to handle this
7068 	-- case removed the check for l_arch_previous_emp_pay <> 0.
7069 	--IF l_arch_previous_emp_pay <> 0 THEN
7070 		OPEN c_get_periods_of_service(l_arch_person_id,l_max_assignment_id);
7071 		FETCH c_get_periods_of_service into l_pds_id;
7072 		CLOSE c_get_periods_of_service;
7073 		hr_utility.set_location('Period of Service id..'||to_char(l_pds_id),3002);
7074 		IF l_pds_id IS NOT NULL THEN
7075 			/*OPEN c_get_terminated_asg(l_pds_id);
7076 			FETCH c_get_terminated_asg into l_asg_id;
7077 			CLOSE c_get_terminated_asg;
7078 
7079 			IF l_asg_id IS NOT NULL THEN*/
7080 				OPEN c_get_max_aact(l_pds_id,l_ppsn_override,l_arch_person_id);
7081 				FETCH c_get_max_aact INTO l_aact_id;
7082 				CLOSE c_get_max_aact;
7083 				hr_utility.set_location('l_aact_id..'||to_char(l_aact_id),3003);
7084 		END IF;
7085 		hr_utility.set_location('l_arch_previous_emp_pay..'||l_arch_previous_emp_pay,5004);
7086 		hr_utility.set_location('l_arch_previous_emp_pay_usc..'||l_arch_previous_emp_pay_usc,5004);  --14659262
7087 		hr_utility.set_location('l_arch_pay..'||l_arch_pay,5004);
7088 		hr_utility.set_location('l_aact_id..'||l_aact_id,5004);
7089 		IF l_aact_id IS NOT NULL THEN
7090 			-- for bug 5435931.
7091 			l_this_pay := l_arch_pay - pay_balance_pkg.get_value (
7092 							 pay_ie_p35.get_defined_balance_id (
7093 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7094 							    'IE Taxable Pay'
7095 							 ),
7096 							 l_aact_id,
7097 							 l_segment4, -- paye reference value
7098 							 null,
7099 							 l_Act_Context_id,  --null,
7100 							 l_Act_Context_value,  --null,
7101 							 null,
7102 							 null,
7103 							 null,
7104 							 'TRUE'
7105 
7106 							);
7107 			hr_utility.set_location('l_this_pay..'||l_this_pay,5004);
7108 			l_this_tax := l_arch_net_tax - pay_balance_pkg.get_value (
7109 							 pay_ie_p35.get_defined_balance_id (
7110 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7111 							    'IE Net Tax'
7112 							 ),
7113 							 l_aact_id,
7114 							 l_segment4, -- paye reference value
7115 							 null,
7116 							 l_Act_Context_id,  --null,
7117 							 l_Act_Context_value,  --null,
7118 							 null,
7119 							 null,
7120 							 null,
7121 							 'TRUE'
7122 
7123 							);
7124 			hr_utility.set_location('l_this_tax..'||l_this_tax,5004);
7125 			/* 8978805 */
7126 			l_arch_prev_gross_pay :=  pay_balance_pkg.get_value (
7127 							 pay_ie_p35.get_defined_balance_id (
7128 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7129 							    'IE Gross Income'
7130 							 ),
7131 							 l_aact_id,
7132 							 l_segment4, -- paye reference value
7133 							 null,
7134 							 l_Act_Context_id,  --null,
7135 							 l_Act_Context_value,  --null,
7136 							 null,
7137 							 null,
7138 							 null,
7139 							 'TRUE'
7140 
7141 							);
7142                          hr_utility.set_location('prev gross pay..'|| l_arch_prev_gross_pay,5004);
7143                          l_arch_prev_gross_pay_adjust := pay_balance_pkg.get_value (
7144 							 pay_ie_p35.get_defined_balance_id (
7145 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7146 							    'IE Gross Income Adjustment'
7147 							 ),
7148 							 l_aact_id,
7149 							 l_segment4, -- paye reference value
7150 							 null,
7151 							 l_Act_Context_id,  --null,
7152 							 l_Act_Context_value,  --null,
7153 							 null,
7154 							 null,
7155 							 null,
7156 							 'TRUE'
7157 
7158 							);
7159                        hr_utility.set_location('prev gross pay adjust..'|| l_arch_prev_gross_pay_adjust,5004);
7160                        l_arch_prev_gross_pay_BIK :=  pay_balance_pkg.get_value (
7161 							 pay_ie_p35.get_defined_balance_id (
7162 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7163 							    'IE BIK Taxable and PRSIable Pay'
7164 							 ),
7165 							 l_aact_id,
7166 							 l_segment4, -- paye reference value
7167 							 null,
7168 							 l_Act_Context_id,  --null,
7169 							 l_Act_Context_value,  --null,
7170 							 null,
7171 							 null,
7172 							 null,
7173 							 'TRUE'
7174 
7175 							);
7176                          hr_utility.set_location('prev BIK..'|| l_arch_prev_gross_pay_BIK,5004);
7177                          l_arch_prev_gross_pay:=NVL(l_arch_prev_gross_pay,0) + NVL(l_arch_prev_gross_pay_adjust,0) + NVL(l_arch_prev_gross_pay_BIK,0);
7178 			 hr_utility.set_location('l_arch_prev_gross_pay '|| l_arch_prev_gross_pay,5004);
7179 			 l_arch_total_this_gross_pay:=l_arch_gross_pay - l_arch_prev_gross_pay;
7180                           hr_utility.set_location('actual this gross pay..'|| l_arch_total_this_gross_pay,5004);
7181 			l_arch_this_income_levy :=l_arch_income_levy - pay_balance_pkg.get_value (
7182 							 pay_ie_p35.get_defined_balance_id (
7183 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7184 							    'IE Income Tax Levy'
7185 							 ),
7186 							 l_aact_id,
7187 							 l_segment4, -- paye reference value
7188 							 null,
7189 							 l_Act_Context_id,  --null,
7190 							 l_Act_Context_value,  --null,
7191 							 null,
7192 							 null,
7193 							 null,
7194 							 'TRUE'
7195 
7196 							);
7197                          hr_utility.set_location('l_arch_this_income_levy '|| l_arch_this_income_levy,5004);
7198 
7199 --11857084
7200 				l_arch_prev_gross_pay_usc :=  pay_balance_pkg.get_value (
7201 							 pay_ie_p35.get_defined_balance_id (
7202 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7203 							    'IE USCable Pay'
7204 							 ),
7205 							 l_aact_id,
7206 							 l_segment4, -- paye reference value
7207 							 null,
7208 							 l_Act_Context_id,  --null,
7209 							 l_Act_Context_value,  --null,
7210 							 null,
7211 							 null,
7212 							 null,
7213 							 'TRUE'
7214 
7215 							);
7216 				 hr_utility.set_location('prev gross pay usc..'|| l_arch_prev_gross_pay_usc,5004);
7217 				 l_arch_prev_gross_pay_adj_usc := pay_balance_pkg.get_value (
7218 							 pay_ie_p35.get_defined_balance_id (
7219 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7220 							    'IE Gross Income Adjustment'
7221 							 ),
7222 							 l_aact_id,
7223 							 l_segment4, -- paye reference value
7224 							 null,
7225 							 l_Act_Context_id,  --null,
7226 							 l_Act_Context_value,  --null,
7227 							 null,
7228 							 null,
7229 							 null,
7230 							 'TRUE'
7231 
7232 							);
7233 				hr_utility.set_location('prev gross pay adjust usc..'|| l_arch_prev_gross_pay_adj_usc,5004);
7234 				l_arch_prev_gross_pay_BIK_usc :=  pay_balance_pkg.get_value (
7235 							 pay_ie_p35.get_defined_balance_id (
7236 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7237 							    'IE BIK Taxable and PRSIable Pay'
7238 							 ),
7239 							 l_aact_id,
7240 							 l_segment4, -- paye reference value
7241 							 null,
7242 							 l_Act_Context_id,  --null,
7243 							 l_Act_Context_value,  --null,
7244 							 null,
7245 							 null,
7246 							 null,
7247 							 'TRUE'
7248 
7249 							);
7250 				hr_utility.set_location('prev BIK usc..'|| l_arch_prev_gross_pay_BIK_usc,5004);
7251 
7252 				l_arch_prev_gross_pay_CO_usc :=  pay_balance_pkg.get_value (
7253 							 pay_ie_p35.get_defined_balance_id (
7254 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7255 							    'IE Court Order'
7256 							 ),
7257 							 l_aact_id,
7258 							 l_segment4, -- paye reference value
7259 							 null,
7260 							 l_Act_Context_id,  --null,
7261 							 l_Act_Context_value,  --null,
7262 							 null,
7263 							 null,
7264 							 null,
7265 							 'TRUE'
7266 
7267 							);
7268 				hr_utility.set_location('prev CO usc..'|| l_arch_prev_gross_pay_CO_usc,5004);
7269 
7270 --11076169
7271 				l_arch_prev_gross_pay_CP_usc :=  pay_balance_pkg.get_value (
7272 							 pay_ie_p35.get_defined_balance_id (
7273 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7274 							    'IE Court Order Child Portion'
7275 							 ),
7276 							 l_aact_id,
7277 							 l_segment4, -- paye reference value
7278 							 null,
7279 							 l_Act_Context_id,  --null,
7280 							 l_Act_Context_value,  --null,
7281 							 null,
7282 							 null,
7283 							 null,
7284 							 'TRUE'
7285 
7286 							);
7287 				hr_utility.set_location('prev CP usc..'|| l_arch_prev_gross_pay_CP_usc,5004);
7288 --11076169
7289 
7290 --16242337
7291 				l_arch_prev_gross_pay_ERPRSA :=  pay_balance_pkg.get_value (
7292 							 pay_ie_p35.get_defined_balance_id (
7293 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7294 							    'IE PRSA ER Contribution'
7295 							 ),
7296 							 l_aact_id,
7297 							 l_segment4, -- paye reference value
7298 							 null,
7299 							 l_Act_Context_id,  --null,
7300 							 l_Act_Context_value,  --null,
7301 							 null,
7302 							 null,
7303 							 null,
7304 							 'TRUE'
7305 
7306 							);
7307 				hr_utility.set_location('prev ER PRSA usc..'|| l_arch_prev_gross_pay_ERPRSA,5004);
7308 --16242337
7309 
7310 				l_arch_prev_gross_pay_usc :=NVL(l_arch_prev_gross_pay_usc,0) +
7311 							     NVL(l_arch_prev_gross_pay_adj_usc,0) +
7312 						     NVL(l_arch_prev_gross_pay_BIK_usc,0) -
7313 						     NVL(l_arch_prev_gross_pay_CO_usc,0) +
7314 						     NVL(l_arch_prev_gross_pay_CP_usc,0)+  --11076169
7315 						     NVL(l_arch_prev_gross_pay_ERPRSA,0);  --16242337
7316 
7317 				hr_utility.set_location('l_arch_prev_gross_pay_usc '|| l_arch_prev_gross_pay_usc,5004);
7318 
7319 				l_arch_tot_this_gross_pay_usc := l_arch_gross_pay_usc - l_arch_prev_gross_pay_usc;
7320 				 hr_utility.set_location('actual this gross pay usc..'|| l_arch_tot_this_gross_pay_usc,5004);
7321 
7322 				l_arch_this_usc :=l_arch_usc - pay_balance_pkg.get_value (
7323 							 pay_ie_p35.get_defined_balance_id (
7324 							    l_dimension_name,  --'_PER_PAYE_REF_YTD',--6633719
7325 							    'IE USC Balance'
7326 							 ),
7327 							 l_aact_id,
7328 							 l_segment4, -- paye reference value
7329 							 null,
7330 							 l_Act_Context_id,  --null,
7331 							 l_Act_Context_value,  --null,
7332 							 null,
7333 							 null,
7334 							 null,
7335 							 'TRUE'
7336 
7337 							);
7338 				 hr_utility.set_location('l_arch_this_usc '|| l_arch_this_usc,5004);
7339 --11857084
7340 
7341 
7342 			-- For P60 changes, PRSI this employment Section C.
7343 			get_p60_prsi_details(p_assignment_action_id => l_aact_id,
7344 		     				 p_max_action_id		=> l_max_action_id,
7345 						 p_person_id		=> l_arch_person_id,
7346 						 p_segment4			=> l_segment4,
7347 						 p_tot_insurable_weeks  => to_number(l_arch_totwks_insurble_emplmnt),
7348 						 p_prsi_employee_cont   => to_number(l_arch_employees_prsi_cont),
7349 						 p_prsi_tot_cont		=> to_number(l_arch_total_prsi_cont),
7350 						 p_insurable_weeks	=> l_this_insurable_weeks,
7351 						 p_this_emp_prsi_cont   => l_this_emp_prsi_cont,
7352 						 p_this_tot_prsi		=> l_this_tot_prsi,
7353 						 p_this_initial_class	=> l_this_initial_class,
7354 						 p_this_sec_class		=> l_this_sec_class,
7355 						 p_this_weeks_at_sec_class => l_this_weeks_at_sec_class,
7356 						 p_Act_Context_id		=> l_Act_Context_id,    --6633719
7357 						 p_Act_Context_value	=> l_Act_Context_value,  --6633719
7358 						 p_dimension_name		=> l_dimension_name,  --6633719
7359 						 p_ppsn_override   => l_ppsn_override  --6633719
7360                          );
7361 
7362 			hr_utility.set_location('After get_p60_prsi_details call',5004);
7363 
7364 		ELSE
7365 		     -- this case will come say employee joins on 2-jan-2006.
7366 		     -- Enter P45 details. So in this case pervious emp pay is <> 0
7367 		     -- but does not have previous period of service. So in this case
7368 		     -- thispay should be total taxable pay _PER_PAYE_REF_YTD
7369 			l_this_pay := l_arch_pay;
7370 			l_this_tax := l_arch_net_tax;
7371 			l_this_insurable_weeks := l_arch_totwks_insurble_emplmnt;
7372 			l_this_emp_prsi_cont := l_arch_employees_prsi_cont;
7373 			l_this_tot_prsi := l_arch_total_prsi_cont ;
7374 			l_this_initial_class := l_arch_initial_class;
7375 			l_this_sec_class := l_arch_second_class;
7376 			l_this_weeks_at_sec_class := l_arch_weeks_at_second_class;
7377 
7378 			/* 8978805 */
7379 			l_arch_total_this_gross_pay:=l_arch_gross_pay;
7380                         l_arch_this_income_levy :=l_arch_income_levy;
7381 
7382 --11857084
7383 			l_arch_tot_this_gross_pay_usc := l_arch_gross_pay_usc;
7384 			l_arch_this_usc := l_arch_usc;
7385 --11857084
7386 
7387 		END IF; --l_aactid is not null
7388 
7389 l_this_pay_usc := l_arch_tot_this_gross_pay_usc; --14659262
7390 l_this_usc := l_arch_this_usc; --14659262
7391 
7392 	/*ELSE
7393 		-- this case will if there is no previous employment. So in this
7394 		-- thispay should be total taxable pay _PER_PAYE_REF_YTD
7395 		l_this_pay := l_arch_pay;
7396 		l_this_tax := l_arch_net_tax;
7397 	-- end bug 5435931
7398 	END IF;*/-- l_arch_previous_emp_pay <> 0
7399 	hr_utility.set_location('l_arch_previous_emp_pay..'||l_arch_previous_emp_pay,5004);
7400 	hr_utility.set_location('l_arch_previous_emp_pay_usc..'||l_arch_previous_emp_pay_usc,5004);  --14659262
7401 	hr_utility.set_location('Before Update',1009);
7402 	/* update assignment actions */
7403 
7404 	IF v_assignment_id <> l_max_assignment_id THEN
7405 		UPDATE pay_assignment_actions SET assignment_id = l_max_assignment_id
7406 		WHERE  assignment_action_id = p_assactid
7407 		AND    payroll_action_id= v_payroll_action_id;
7408 
7409 		UPDATE pay_assignment_actions SET assignment_id = l_max_assignment_id
7410 		WHERE  source_action_id = p_assactid
7411 		AND    payroll_action_id = v_payroll_action_id;
7412 	END IF;
7413 
7414 	hr_utility.set_location('After Update',1009);
7415 
7416 	  -- print the hiredate only it falls in the current tax year.
7417         IF to_char(to_date(l_arch_hire_date,'DD-MM-YYYY'),'YYYY') <> to_char(l_start_date,'YYYY') THEN
7418               l_arch_hire_date := null;
7419         END IF;
7420 
7421 	  -- if have - in initial class bug 5864661
7422         IF instr(l_this_initial_class,'-',1) > 0 THEN
7423 		l_this_initial_class := substr(l_this_initial_class,1,instr(l_this_initial_class,'-',1)-1);
7424 	  END IF;
7425 
7426 hr_utility.set_location('Before create_action_information IE P35 DETAIL',1009);
7427 
7428 	IF l_arch_pay >= 1 OR l_arch_income_levy > 0 OR l_arch_usc <> 0 --14656910V9
7429 	--OR l_arch_non_tax_pay > 0 --6620003  --8874161  --8987577
7430 	THEN
7431 
7432         hr_utility.set_location('l_arch_works_number..'||l_arch_works_number,1009);
7433 		hr_utility.set_location('l_ppsn_override..'||l_ppsn_override,1009);
7434 		hr_utility.set_location('l_arch_ppsn..'||l_arch_ppsn,1009);
7435 		hr_utility.set_location('l_max_assignment_id..'||l_max_assignment_id,1009);
7436 
7437 hr_utility.set_location('Outside l_arch_initial_class:'||l_arch_initial_class,1009);
7438 --9080372
7439         IF NVL(l_arch_total_prsi_cont,0) = 0 THEN
7440           l_arch_initial_class := NVL(TRIM(l_arch_initial_class),'M');
7441 hr_utility.set_location('Inside l_arch_initial_class:'||l_arch_initial_class,1009);
7442         END IF;
7443 --9080372
7444 
7445                l_arch_pay := l_arch_pay + l_p35_taxable_pay_adjust; --16306646
7446 hr_utility.set_location('l_arch_pay..'||l_arch_pay,1009); --16306646
7447 
7448 	         pay_action_information_api.create_action_information (
7449 	            p_action_context_id=> p_assactid,
7450 	            p_action_context_type=> 'AAP',
7451 	            p_action_information_category=> 'IE P35 DETAIL',
7452 	            p_assignment_id	   => l_max_assignment_id,
7453 	            p_action_information1=> NVL(l_ppsn_override,l_arch_ppsn),  --6633719
7454 	            p_action_information2=> l_arch_works_number,
7455 	            p_action_information3=> l_arch_totwks_insurble_emplmnt,
7456 	            p_action_information4=> l_arch_initial_class,
7457 	            p_action_information5=> l_arch_second_class,
7458 	            p_action_information6=> l_arch_weeks_at_second_class,
7459 	            p_action_information7=> l_arch_third_class,
7460 	            p_action_information8=> l_arch_weeks_at_third_class,
7461 	            p_action_information9=> l_arch_fourth_class,
7462 	            p_action_information10=> l_arch_weeks_at_fourth_class,
7463 	            p_action_information11=> l_arch_fifth_class,
7464 	            p_action_information12=> l_arch_net_tax,
7465 	            p_action_information13=> l_arch_tax_or_refund,
7466 	            p_action_information14=> l_arch_employees_prsi_cont,
7467 	            p_action_information15=> l_arch_total_prsi_cont,
7468 	            p_action_information16=> l_arch_pay,
7469 	            p_action_information17=> l_arch_tax_deduction_basis,
7470 	            p_action_information18=> l_arch_surname,
7471 	            p_action_information19=> l_arch_first_name,
7472 	            p_action_information20=> l_arch_dob,
7473 	            p_action_information21=> substr(l_arch_address_line1,1,30), -- bug 5869390
7474 	            p_action_information22=> substr(l_arch_address_line2,1,30), -- bug 5869390
7475 	            p_action_information23=> substr(l_arch_address_line3,1,30), -- bug 5869390
7476 	            p_action_information24=> l_arch_hire_date,
7477 	            p_action_information25=> l_arch_term_date,
7478 	            p_action_information26=> l_arch_annual_tax_credit,
7479 	            p_action_information27=> l_arch_mothers_name,
7480 			-- for bug 5435931
7481 	            p_action_information28=> l_arch_previous_emp_pay||'|'||l_this_pay,
7482 	            p_action_information29=> l_arch_previous_emp_tax||'|'||l_this_tax,
7483 			-- end for bug 5435931
7484 	            p_action_information30=> l_arch_pr_indicator,
7485 	            p_action_information_id=> l_arch_action_info_id,
7486 	            p_object_version_number=> l_arch_ovn);
7487 
7488         hr_utility.set_location('Before create_action_information IE P35 ADDITIONAL DETAILS',1009);
7489 
7490 	  l_arch_total_notional_pay := l_arch_total_notional_pay + l_arch_total_share_scheme ; --16306646
7491         l_arch_gross_pay_usc :=  l_arch_gross_pay_usc + l_p35_gross_pay_adjust; --16306646
7492 
7493 
7494 	  hr_utility.set_location('l_arch_total_notional_pay..'||l_arch_total_notional_pay,1009); --16306646
7495 	  hr_utility.set_location('l_arch_gross_pay_usc..'||l_arch_gross_pay_usc,1009); --16306646
7496 
7497 	         pay_action_information_api.create_action_information (
7498 	            p_action_context_id=> p_assactid,
7499 	            p_action_context_type=> 'AAP',
7500 	            p_action_information_category=> 'IE P35 ADDITIONAL DETAILS',
7501 	            p_assignment_id=> l_max_assignment_id,
7502 	            p_action_information1=> l_arch_total_notional_pay,
7503 	            p_action_information2=> l_arch_pen_emp_rbs,
7504 			p_action_information3=> l_arch_pen_empr_rbs,
7505 			p_action_information4=> l_arch_pen_emp_prsa,
7506 			p_action_information5=> l_arch_pen_empr_prsa,
7507 			p_action_information6=> l_arch_pen_emp_rac,
7508 			p_action_information11=> l_this_emp_prsi_cont,
7509 			p_action_information12=> l_this_tot_prsi,
7510 			p_action_information13=> l_this_insurable_weeks,
7511 			p_action_information14=> l_this_initial_class,
7512 			p_action_information15=> l_this_sec_class,
7513 			p_action_information16=> l_this_weeks_at_sec_class,
7514 			p_action_information17=> to_char(floor(to_number(l_medical_insurance))*100), -- 5867343,6502227, 16242337, 16266482
7515 			p_action_information18=> l_arch_gross_pay,             -- gross pay  /* 8520684 */
7516 			p_action_information19=> l_arch_income_levy,           -- income levy
7517 			--p_action_information20=> l_arch_income_levy_first,     -- income levy first band  --14659262
7518 			--p_action_information21=> l_arch_income_levy_second,    -- income levy second band  --14659262
7519 			p_action_information20=> l_arch_previous_emp_pay_usc||'|'||l_this_pay_usc,     --14659262
7520 			p_action_information21=> l_arch_previous_emp_usc||'|'||l_this_usc,    --14659262
7521 			--p_action_information22=> l_arch_income_levy_third,   -- income levy third band  --14656910
7522 			p_action_information22=> l_arch_illness_benefit,       -- illness_benefit  --14656910
7523 			p_action_information23=> l_arch_parking_levy,           -- parking levy
7524 			p_action_information24=> l_arch_total_this_gross_pay,    -- This employement gross pay
7525 			p_action_information25=> l_arch_this_income_levy,        -- this employmement incoem elvy
7526 			p_action_information26=> NVL(l_arch_asg_location_id,0)||'|'||NVL(l_arch_org_id,0),   -- assignment level lcoation id 10277535 --11674153
7527 --12382953
7528 			p_action_information27=> l_arch_gross_pay_usc,         -- gross pay USC
7529 			p_action_information7=> l_arch_usc,                    -- USC Balance
7530 			p_action_information8=> l_arch_usc_first,              -- USC first band
7531 			p_action_information9=> l_arch_usc_second,             -- USC second band
7532 			p_action_information10=> l_arch_usc_third,             -- USC third band
7533 			p_action_information28=> l_exclusion_order,            -- exclusionOrder
7534 --12382953
7535 --11857084
7536 			p_action_information29=> l_arch_tot_this_gross_pay_usc,    -- This employement gross pay usc
7537 			p_action_information30=> l_arch_this_usc,        -- this employmement usc
7538 --11857084
7539 	            p_action_information_id=> l_arch_action_info_id,
7540 	            p_object_version_number=> l_oth_arch_ovn
7541 	         );
7542 hr_utility.set_location('After create_action_information IE P35 ADDITIONAL DETAILS',1009);
7543 
7544 		END IF;
7545 -- Empty the pl/sql tables
7546 l_prsi_class_bal := l_prsi_class_temp;
7547 l_prsi_class_tab := l_prsi_class_temp;
7548 l_prsi_class_tab1:= l_prsi_class_temp;  --9080372
7549 END archive_code;
7550 
7551 Procedure deinit_code (p_payroll_action_id IN NUMBER) is
7552 
7553 l_proc			CONSTANT VARCHAR2(50):= l_package||'deinit_code';
7554 l_archived		      NUMBER(1);
7555 l_out_var               VARCHAR2 (30);
7556 l_ovn                   NUMBER;
7557 l_action_info_id        NUMBER;
7558 l_employer_number       VARCHAR2 (240);
7559 l_employer_address1     VARCHAR2 (240);
7560 l_employer_address2     VARCHAR2 (240);
7561 l_employer_address3     VARCHAR2 (240);
7562 l_employer_name         VARCHAR2 (240);
7563 l_contact_name          VARCHAR2 (240);
7564 l_location_name         VARCHAR2 (240);  -- 10277535
7565 l_contact_number        VARCHAR2 (240);
7566 /*Added for bug fix 3815830*/
7567 l_trade_name            VARCHAR2 (240);
7568 l_fax_number            VARCHAR2 (240);
7569 l_bg_id                    NUMBER;
7570 l_email_addr            VARCHAR2 (240);  -- 12556436
7571 
7572 
7573 CURSOR csr_check_payroll_action IS
7574   SELECT 1
7575   FROM   DUAL
7576   WHERE EXISTS (SELECT NULL
7577   		FROM pay_action_information pai
7578   		WHERE pai.action_context_id = p_payroll_action_id
7579   		AND   pai.action_context_type = 'PA'
7580   		AND   rownum = 1
7581   	       );
7582 
7583       /* Added the cursor for BUG 2987230 */
7584 CURSOR csr_p35_header_info
7585 IS
7586 SELECT hoi2.org_information2, -- 'EMPLOYER_NUMBER
7587                 --nvl(trim(rpad(hou.name,30)),' '), -- ('EMPLOYER_NAME=P'),
7588                 --Added for bug fix 3567562,Modifed source of Employer Name
7589                 NVL (TRIM (RPAD (hou.name, 30)), ' '), -- ('EMPLOYER_NAME=P'),
7590                 NVL (TRIM (RPAD (hoi2.org_information3, 30)), ' '), -- ('TRADE_NAME=P'), /*Added for bug fix 3815830*/
7591                 NVL (TRIM (RPAD (hl.ADDRESS_LINE_1, 30)), ' '), -- ('EMPLOYER_ADDRESS1=P'),
7592                 NVL (TRIM (RPAD (hl.ADDRESS_LINE_2, 30)), ' '), -- ('EMPLOYER_ADDRESS2=P'),
7593                 NVL (TRIM (RPAD (hl.ADDRESS_LINE_3, 30)), ' '), -- ('EMPLOYER_ADDRESS3=P'),
7594                 NVL (TRIM (RPAD (hoi2.org_information4, 20)), ' '), -- ('CONTACT_NAME=P'),
7595                 NVL (TRIM (RPAD (hl.TELEPHONE_NUMBER_1, 12)), ' ' ), -- ('CONTACT_NUMBER=P'),
7596 	          NVL (TRIM (RPAD (hl.TELEPHONE_NUMBER_2, 12)), ' ') --('FAX_NO=P') /*Added for bug fix 3815830*/
7597 		  , NVL (TRIM (RPAD (hl.LOCATION_CODE, 30)), ' ') -- 10277535
7598 		  , NVL (TRIM (RPAD (hoi3.ORG_INFORMATION2, 30)), ' ') -- 12556436 EMAIL ADDRESS
7599            FROM hr_all_organization_units hou,
7600 	          hr_locations hl,
7601 		    pay_payroll_actions ppa,
7602 		    hr_organization_information hoi1,
7603 		    hr_organization_information hoi2
7604 		    ,hr_organization_information hoi3 --12556436
7605           WHERE ppa.payroll_action_id = p_payroll_action_id
7606             AND hou.business_group_id = ppa.business_group_id
7607             AND hou.organization_id = pay_ie_p35.get_parameter (ppa.payroll_action_id, 'EMP_NO')
7608 		AND hl.location_id(+) = hou.location_id
7609 		AND hou.organization_id=hoi1.organization_id
7610 		AND hoi2.organization_id(+)= hoi1.organization_id
7611 		AND hoi1.org_information_context='CLASS'
7612 		AND hoi1.org_information1='HR_LEGAL_EMPLOYER'
7613 		AND hoi1.org_information2='Y'
7614 		AND hoi2.org_information_context (+) ='IE_EMPLOYER_INFO'
7615 		--12556436
7616 		AND hoi3.organization_id(+)= hoi1.organization_id
7617 		AND hoi3.org_information_context (+) ='ORG_CONTACT_DETAILS'
7618 		AND hoi3.ORG_INFORMATION1(+) = 'EMAIL';
7619 		--12556436
7620 BEGIN
7621 
7622 l_archived := 0;
7623 OPEN csr_check_payroll_action;
7624 FETCH csr_check_payroll_action into l_archived;
7625 CLOSE csr_check_payroll_action;
7626 IF l_archived = 0 THEN
7627 	l_out_var := pay_ie_p35.get_parameter (
7628 					p_payroll_action_id=> p_payroll_action_id,
7629 					p_token_name=> 'END_DATE'
7630 					);
7631       l_end_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
7632       l_out_var := pay_ie_p35.get_parameter (
7633 					p_payroll_action_id=> p_payroll_action_id,
7634 			            p_token_name=> 'START_DATE'
7635 					);
7636       l_start_date := TO_DATE (l_out_var, 'YYYY/MM/DD');
7637       l_out_var := pay_ie_p35.get_parameter (
7638 					p_payroll_action_id=> p_payroll_action_id,
7639 			            p_token_name=> 'BG_ID'
7640 					);
7641       l_bg_id := TO_NUMBER (l_out_var);
7642 
7643 	/* Added code for BUG 2987230 */
7644       -- Collect header deatils
7645       OPEN csr_p35_header_info;
7646       --Modified sequence of variables fetched for bug no 3567562
7647       FETCH csr_p35_header_info INTO l_employer_number,
7648                                      l_employer_name,
7649 						 l_trade_name, /*Added for bug fix 3815830*/
7650                                      l_employer_address1,
7651                                      l_employer_address2,
7652                                      l_employer_address3,
7653                                      l_contact_name,
7654                                      l_contact_number,
7655 						 l_fax_number /*Added for bug fix 3815830*/
7656 						 ,l_location_name -- 10277535
7657                                      ,l_email_addr; --12556436
7658       CLOSE csr_p35_header_info;
7659 
7660 --10242128
7661 IF l_contact_number IS NOT NULL THEN
7662   IF l_contact_number <> ' ' THEN
7663     l_contact_number := REPLACE(l_contact_number,' ');
7664     l_contact_number := REPLACE(l_contact_number,'(');
7665     l_contact_number := REPLACE(l_contact_number,')');
7666     l_contact_number := REPLACE(l_contact_number,'-');
7667     l_contact_number := REPLACE(l_contact_number,'+');
7668     l_contact_number := REPLACE(l_contact_number,'.');
7669 
7670   END IF;
7671 END IF;
7672 
7673 IF l_fax_number IS NOT NULL THEN
7674   IF l_fax_number <> ' ' THEN
7675     l_fax_number := REPLACE(l_fax_number,' ');
7676     l_fax_number := REPLACE(l_fax_number,'(');
7677     l_fax_number := REPLACE(l_fax_number,')');
7678     l_fax_number := REPLACE(l_fax_number,'-');
7679     l_fax_number := REPLACE(l_fax_number,'+');
7680     l_fax_number := REPLACE(l_fax_number,'.');
7681   END IF;
7682 END IF;
7683 --10242128
7684 
7685       -- Archive header info
7686       pay_action_information_api.create_action_information (
7687          p_action_information_id=> l_action_info_id,
7688          p_action_context_id=> p_payroll_action_id,
7689          p_action_context_type=> 'PA',
7690          p_object_version_number=> l_ovn,
7691          p_action_information_category=> 'ADDRESS DETAILS',
7692          p_action_information1=> l_employer_number,
7693 	   p_action_information9=> l_trade_name, /*Added for bug fix 3815830*/
7694          p_action_information5=> l_employer_address1,
7695          p_action_information6=> l_employer_address2,
7696          p_action_information7=> l_employer_address3,
7697          p_action_information26=> l_employer_name,
7698          p_action_information27=> l_contact_name,
7699          p_action_information28=> l_contact_number,
7700 	 p_action_information10=> l_fax_number  /*Added for bug fix 3815830*/
7701 	 ,p_action_information11=>l_location_name -- 10277535
7702          ,p_action_information29=> l_email_addr --12556436
7703       );
7704 END IF;
7705 
7706 END deinit_code;
7707 
7708 
7709 
7710    FUNCTION get_initial_class (p_max_action_id IN NUMBER,
7711 					 l_segment4 IN NUMBER,
7712                      p_ppsn_override IN VARCHAR2)  --6633719
7713       RETURN VARCHAR2
7714    AS
7715       -- Bug 2979713 - PRSI Context Balance Design Change
7716 
7717       -- cursor to retrive the context_id - to be used in get_total_insurable_weeks function
7718       CURSOR c_context_id
7719       IS
7720          SELECT context_id
7721            FROM ff_contexts
7722           WHERE context_name = 'SOURCE_TEXT';
7723 
7724       -- get the latest assignment_action_id to calculate the balances for the calculating the
7725       -- total insurable weeks, weeks at first class etc.
7726       -- Bug 3381002 : Added the condition paa.action_status='C', removed ppa.action_status='C' and added
7727       -- the action type 'I'
7728 
7729       /*CURSOR c_assignment_action_id (
7730          p_person_id    NUMBER,
7731          p_start_date   DATE,
7732          p_end_date     DATE
7733       )
7734       IS
7735          SELECT   /*+ ORDERED USE_NL(paa, ppa, ptp)
7736                   fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||
7737                   paa.assignment_action_id),16)) assignment_action_id  --bug fix 4004470
7738              FROM per_people_f ppf,
7739                   per_assignments_f paf,
7740                   pay_assignment_actions paa,
7741                   pay_payroll_actions ppa,
7742                   per_time_periods ptp
7743             WHERE
7744 		   ppf.person_id = p_person_id
7745 		  AND paf.assignment_id = p_assignment_id -- vik added code for getting values for given assignment
7746               AND ppf.current_employee_flag = 'Y'
7747               AND paf.person_id = ppf.person_id
7748               --AND paf.primary_flag = 'Y' -- removed join
7749               AND paf.assignment_type = 'E'
7750               AND paf.assignment_status_type_id =
7751 	      --Added for bug fix 3828506
7752 	                          (SELECT ast.assignment_status_type_id
7753 	                           FROM   per_assignment_status_types ast
7754 				   WHERE  ast.per_system_status = 'ACTIVE_ASSIGN'
7755 				   AND    ast.assignment_status_type_id =  paf.assignment_status_type_id)
7756               AND paa.assignment_id = paf.assignment_id
7757               AND paa.action_status IN ('C','S') --10225372
7758               AND ppa.payroll_action_id = paa.payroll_action_id
7759               AND ppa.action_type IN ('R', 'Q', 'I', 'B')
7760               AND ptp.time_period_id = ppa.time_period_id
7761               AND ptp.end_date BETWEEN p_start_date AND p_end_date
7762 	      group by paa.assignment_id;*/
7763         /* ORDER BY paa.action_sequence DESC;*/
7764 
7765 
7766 
7767       -- cursor for retrieving the context values
7768       -- Bug 3460687 : Changed ppa.action_status to paa.action_status
7769        CURSOR c_context_name (
7770          p_person_id    NUMBER,
7771          p_start_date   DATE,
7772          p_end_date     DATE,
7773 	   p_date         DATE  --8259095
7774       )
7775       IS
7776          SELECT   /*+ ordered */
7777                   asg.business_group_id business_group_id,
7778                   asg.person_id person_id, per.full_name full_name,
7779                   per.original_date_of_hire original_hire_date,
7780                   MIN (ptp.end_date) minimum_effective_date,
7781 			asg.primary_flag,
7782 			paa.assignment_action_id,
7783                   trim(rrv1.result_value) result_value
7784              FROM per_people_f per,
7785                   per_assignments_f asg,
7786                   pay_assignment_actions paa,
7787                   pay_payroll_actions ppa,
7788                   per_time_periods ptp,
7789                   pay_run_results prr,
7790                   pay_element_types_f pet,
7791                   pay_input_values_f piv1,
7792                   pay_run_result_values rrv1,
7793                   per_assignment_extra_info paei  --6633719
7794             WHERE per.person_id = p_person_id
7795             --6633719 these condition added to fetch the contexes having similar PPSN OVERRIDE if given
7796               AND paei.assignment_id(+) = asg.assignment_id
7797               AND paei.aei_information_category(+) = 'IE_ASG_OVERRIDE'
7798               AND nvl(paei.aei_information1,'X') =  nvl(p_ppsn_override,'X')
7799             --6633719
7800 		  --AND asg.assignment_id = p_assignment_id -- vik added code for getting values for given assignment
7801               AND per.current_employee_flag = 'Y'
7802               AND per.effective_start_date =
7803                         (SELECT MIN (per2.effective_start_date)
7804                            FROM per_people_f per2
7805 			    -- Bug Fix 4004384
7806 			    , per_periods_of_service pos2
7807                             WHERE per2.person_id = per.person_id
7808                             AND per2.effective_start_date <= p_end_date
7809 			    AND pos2.person_id = per2.person_id
7810 			    AND pos2.date_start between per2.effective_start_date and per2.effective_end_date
7811 			    AND NVL (pos2.final_process_date, p_end_date) >=p_start_date
7812                          -- AND NVL (per2.effective_end_date, p_end_date) >=p_start_date
7813 			    --Added for bug fix 3828506
7814 			    AND per2.current_employee_flag = 'Y'  )
7815               AND asg.person_id = per.person_id
7816               AND asg.effective_start_date =
7817                         (SELECT MIN (asg2.effective_start_date)
7818                            FROM per_assignments_f asg2,
7819 			        per_assignment_status_types ast --Bug fix 3828506
7820                             WHERE asg2.assignment_id = asg.assignment_id
7821                             AND asg2.effective_start_date <= p_end_date
7822                             AND NVL (asg2.effective_end_date, p_end_date) >= p_start_date
7823 			    --Added for bug fix 3828506
7824 			    --AND asg2.primary_flag = 'Y' ---- removed join
7825 			    AND asg2.assignment_type = 'E'
7826                             AND asg2.assignment_status_type_id = ast.assignment_status_type_id )
7827 			    -- Bug Fix 4004384
7828 			  --  AND ast.pay_system_status ='P') -- Bug Fix 4025532
7829 	                 -- AND ast.per_system_status ='ACTIVE_ASSIGN')
7830               --AND asg.primary_flag = 'Y' -- removed join
7831               AND asg.assignment_type = 'E'
7832 	      --Bug Fix 3828506
7833               AND paa.assignment_id = asg.assignment_id
7834               AND paa.action_status = 'C'
7835 		  AND paa.tax_unit_id = l_segment4
7836               AND ppa.payroll_action_id = paa.payroll_action_id
7837               AND ppa.action_type IN ('Q', 'R', 'B')
7838 		  /* impact of tim period */
7839              -- AND ppa.time_period_id = ptp.time_period_id
7840               AND ppa.payroll_id = ptp.payroll_id
7841               AND ppa.date_earned between ptp.start_date and ptp.end_date
7842 		  and ppa.effective_date between p_start_date and p_end_date
7843 		  --
7844               --AND ptp.end_date BETWEEN p_start_date AND p_end_date                    -- Bug 5070091 Offset payroll change
7845               AND pet.element_name IN ('IE PRSI Contribution Class','Setup PRSI Context Element') /* 5763147 */
7846               AND pet.legislation_code = 'IE'
7847 
7848 /*              AND pet.effective_start_date =
7849                         (SELECT MAX (pet2.effective_start_date)
7850                            FROM pay_element_types_f pet2
7851                           WHERE pet.element_type_id = pet2.element_type_id
7852                             AND pet2.effective_start_date <= p_end_date
7853                             AND NVL (pet2.effective_end_date, p_end_date) >=
7854                                                                  p_start_date)*/
7855               AND pet.element_type_id = piv1.element_type_id
7856               AND piv1.NAME IN ('Contribution_Class','Context Contribution Class') /* 5763147 */
7857               AND piv1.legislation_code = 'IE'
7858 
7859 /*              AND piv1.effective_start_date =
7860                         (SELECT MAX (piv1a.effective_start_date)
7861                            FROM pay_input_values_f piv1a
7862                           WHERE piv1.input_value_id = piv1a.input_value_id
7863                             AND piv1a.effective_start_date <= p_end_date
7864                             AND NVL (piv1a.effective_end_date, p_end_date) >=
7865                                                                  p_start_date)*/
7866               AND prr.assignment_action_id = paa.assignment_action_id
7867               AND prr.element_type_id = pet.element_type_id
7868               AND rrv1.input_value_id = piv1.input_value_id
7869               AND rrv1.run_result_id = prr.run_result_id
7870 		  AND trim(rrv1.result_value) IS NOT NULL  --8247074
7871 		  HAVING MIN(ptp.end_date) = p_date	  --8259095
7872          GROUP BY asg.business_group_id,
7873                   asg.person_id,
7874                   per.full_name,
7875                   per.original_date_of_hire,
7876 			asg.primary_flag,
7877 			paa.assignment_action_id,
7878                   trim(rrv1.result_value)
7879          ORDER BY asg.primary_flag desc,minimum_effective_date,paa.assignment_action_id;
7880 
7881 
7882 -- Bug 3460687 Added cursor to fetch Balance Initialization Class Values and Class Names
7883       CURSOR c_context_name_bal_init (
7884          p_person_id    NUMBER,
7885          p_start_date   DATE,
7886          p_end_date     DATE
7887       )
7888       IS
7889          SELECT   /*+ ordered */
7890                   TO_NUMBER (
7891                      MAX (
7892                         DECODE (
7893                            piv1.NAME,
7894                            'Insurable Weeks', rrv1.result_value,
7895                            '0'
7896                         )
7897                      )
7898                   ) weeks,
7899                   MAX (
7900                      DECODE (
7901                         piv1.NAME,
7902                         'Context Contribution Class', rrv1.result_value,
7903                         '0'
7904                      )
7905                   ) class_name
7906              FROM per_people_f per,
7907                   per_assignments_f asg,
7908                   pay_assignment_actions paa,
7909                   pay_payroll_actions ppa,
7910                   per_time_periods ptp,
7911                   pay_run_results prr,
7912                   pay_element_types_f pet,
7913                   pay_input_values_f piv1,
7914                   pay_run_result_values rrv1
7915             WHERE per.person_id = p_person_id
7916 		  --ANd asg.assignment_id = p_assignment_id -- vik added code for getting values for given assignment
7917               AND per.effective_start_date =
7918                         (SELECT MIN (per2.effective_start_date)
7919                            FROM per_people_f per2
7920                           WHERE per.person_id = per2.person_id
7921                             AND per2.effective_start_date <= p_end_date
7922                             AND NVL (per2.effective_end_date, p_end_date) >=
7923                                                                  p_start_date
7924 			    --Added for bug fix 3828506
7925 			    AND per2.current_employee_flag = 'Y')
7926               AND per.current_employee_flag = 'Y'
7927               AND asg.person_id = per.person_id
7928               --AND asg.primary_flag = 'Y' -- removed join
7929               AND asg.assignment_type = 'E'
7930               AND asg.assignment_status_type_id =
7931                         ( SELECT ast.assignment_status_type_id
7932                           FROM   per_assignment_status_types ast
7933                           WHERE  ast.per_system_status ='ACTIVE_ASSIGN'
7934 			  AND    ast.assignment_status_type_id = asg.assignment_status_type_id)
7935               AND asg.effective_start_date =
7936                         (SELECT MIN (asg2.effective_start_date)
7937                            FROM per_assignments_f asg2,
7938 			        per_assignment_status_types ast --For bug fix 3828506
7939                           WHERE asg2.assignment_id = asg.assignment_id
7940                             AND asg2.effective_start_date <= p_end_date
7941                             AND NVL (asg2.effective_end_date, p_end_date) >= p_start_date
7942 			    --Added for bug fix 3828506
7943 			    --AND asg2.primary_flag = 'Y' -- removed join
7944 			    AND asg2.assignment_type = 'E'
7945                             AND asg2.assignment_status_type_id = ast.assignment_status_type_id
7946 			    AND ast.per_system_status ='ACTIVE_ASSIGN')
7947               AND paa.assignment_id = asg.assignment_id
7948               AND paa.action_status = 'C'
7949               AND ppa.payroll_action_id = paa.payroll_action_id
7950               AND ppa.action_type = 'I'
7951 		  /* time period impact */
7952               --  AND ppa.time_period_id = ptp.time_period_id
7953               AND ppa.payroll_id = ptp.payroll_id
7954               AND ppa.date_earned between ptp.start_date and ptp.end_date
7955 		  AND ppa.effective_date between p_start_date and p_end_date
7956 		  --
7957               --AND ptp.end_date BETWEEN p_start_date AND p_end_date                  -- Bug 5070091 Offset payroll change
7958               AND paa.assignment_action_id = prr.assignment_action_id
7959               AND pet.element_name = 'Setup PRSI Context Element'
7960               AND pet.legislation_code = 'IE'
7961 
7962 /*              AND pet.effective_start_date =
7963                         (SELECT MAX (pet2.effective_start_date)
7964                            FROM pay_element_types_f pet2
7965                           WHERE pet.element_type_id = pet2.element_type_id
7966                             AND pet2.effective_start_date <= p_end_date
7967                             AND NVL (pet2.effective_end_date, p_end_date) >=
7968                                                                  p_start_date)
7969 */
7970               AND pet.element_type_id = piv1.element_type_id
7971               AND piv1.NAME IN
7972                             ('Insurable Weeks', 'Context Contribution Class')
7973               AND piv1.legislation_code = 'IE'
7974 
7975 /*              AND piv1.effective_start_date =
7976                         (SELECT MAX (piv1a.effective_start_date)
7977                            FROM pay_input_values_f piv1a
7978                           WHERE piv1.input_value_id = piv1a.input_value_id
7979                             AND piv1a.effective_start_date <= p_end_date
7980                             AND NVL (piv1a.effective_end_date, p_end_date) >=
7981                                                                  p_start_date)*/
7982               AND prr.element_type_id = pet.element_type_id
7983               AND rrv1.run_result_id = prr.run_result_id
7984               AND rrv1.input_value_id = piv1.input_value_id
7985          GROUP BY prr.run_result_id
7986            HAVING MAX (
7987                      DECODE (
7988                         piv1.NAME,
7989                         'Context Contribution Class', rrv1.result_value,
7990                         '0'
7991                      )
7992                   ) <> '0'
7993          ORDER BY weeks DESC;
7994 
7995 
7996 -- Bug 3460687 Temporary variables to use when swapping classes when both Balance Initialization and
7997 -- Payrolls exist
7998 
7999       temp_flag                     NUMBER (2);
8000       l_context_value_counter_bal   NUMBER (2) := 0;
8001       l_context_value_counter_tmp   NUMBER (2) := 0;
8002       l_index NUMBER(10);
8003 
8004 --8259095
8005        CURSOR c_main_supp_week (
8006          p_person_id    NUMBER,
8007          p_start_date   DATE,
8008          p_end_date     DATE
8009       )
8010       IS
8011          SELECT   /*+ ordered */
8012                   asg.business_group_id bg_id,
8013                   asg.person_id per_id,
8014                   MIN (ptp.end_date) min_eff_date,
8015 			      ptp.time_period_id
8016              FROM per_people_f per,
8017                   per_assignments_f asg,
8018                   pay_assignment_actions paa,
8019                   pay_payroll_actions ppa,
8020                   per_time_periods ptp,
8021                   pay_run_results prr,
8022                   pay_element_types_f pet,
8023                   pay_input_values_f piv1,
8024                   pay_run_result_values rrv1,
8025                   per_assignment_extra_info paei
8026             WHERE per.person_id = p_person_id
8027               AND paei.assignment_id(+) = asg.assignment_id
8028               AND paei.aei_information_category(+) = 'IE_ASG_OVERRIDE'
8029               AND nvl(paei.aei_information1,'X') =  nvl(p_ppsn_override,'X')
8030               AND per.current_employee_flag = 'Y'
8031               AND per.effective_start_date =
8032                         (SELECT MIN (per2.effective_start_date)
8033                            FROM per_people_f per2
8034 			    , per_periods_of_service pos2
8035                             WHERE per2.person_id = per.person_id
8036                             AND per2.effective_start_date <= p_end_date
8037 			    AND pos2.person_id = per2.person_id
8038 			    AND pos2.date_start between per2.effective_start_date and per2.effective_end_date
8039 			    AND NVL (pos2.final_process_date, p_end_date) >=p_start_date
8040 			    AND per2.current_employee_flag = 'Y'  )
8041               AND asg.person_id = per.person_id
8042               AND asg.effective_start_date =
8043                         (SELECT MIN (asg2.effective_start_date)
8044                            FROM per_assignments_f asg2,
8045 			        per_assignment_status_types ast --Bug fix 3828506
8046                             WHERE asg2.assignment_id = asg.assignment_id
8047                             AND asg2.effective_start_date <= p_end_date
8048                             AND NVL (asg2.effective_end_date, p_end_date) >= p_start_date
8049 			    AND asg2.assignment_type = 'E'
8050                             AND asg2.assignment_status_type_id = ast.assignment_status_type_id )
8051               AND asg.assignment_type = 'E'
8052               AND paa.assignment_id = asg.assignment_id
8053               AND paa.action_status = 'C'
8054 		  AND paa.tax_unit_id = l_segment4
8055               AND ppa.payroll_action_id = paa.payroll_action_id
8056               AND ppa.action_type IN ('Q', 'R', 'B')
8057               AND ppa.payroll_id = ptp.payroll_id
8058               AND ppa.date_earned between ptp.start_date and ptp.end_date
8059 		  and ppa.effective_date between p_start_date and p_end_date
8060               AND pet.element_name IN ('IE PRSI Contribution Class','Setup PRSI Context Element') /* 5763147 */
8061               AND pet.legislation_code = 'IE'
8062               AND pet.element_type_id = piv1.element_type_id
8063               AND piv1.NAME IN ('Contribution_Class','Context Contribution Class') /* 5763147 */
8064               AND piv1.legislation_code = 'IE'
8065               AND prr.assignment_action_id = paa.assignment_action_id
8066               AND prr.element_type_id = pet.element_type_id
8067               AND rrv1.input_value_id = piv1.input_value_id
8068               AND rrv1.run_result_id = prr.run_result_id
8069 		  AND trim(rrv1.result_value) IS NOT NULL
8070           GROUP BY asg.business_group_id,
8071                   asg.person_id,
8072                   ptp.time_period_id
8073           ORDER BY min_eff_date;
8074 
8075 l_supp_run_class pay_run_result_values.result_value%type;
8076 TYPE type_context_name IS table of c_context_name%rowtype INDEX BY BINARY_INTEGER;
8077 l_type_context_name_tab type_context_name;
8078 --8259095
8079 
8080    BEGIN
8081       --
8082 
8083 
8084       l_class_count := 0;
8085       l_weeks_at_initial_class := 0;
8086       l_weeks_at_second_class := 0;
8087       l_weeks_at_third_class := 0;
8088       l_weeks_at_fourth_class := 0;
8089 	l_weeks_at_fifth_class := 0;
8090       l_index := 1;
8091 -- l_context_value_counter := 0;
8092       l_initial_class := NULL;
8093       l_second_class := NULL;
8094       l_third_class := NULL;
8095       l_fourth_class := NULL;
8096 	l_fifth_class := NULL;
8097 	l_supp_run_class := NULL; 	--8259095
8098 
8099 	-- Flush the prsi_class_tab table.
8100 
8101       --
8102       -- Bug 2979713 - PRSI Context Balance Design Change
8103 
8104 
8105       --
8106 
8107      -- hr_utility.TRACE ('In procedure get_initial_class');
8108       -- Fetching the values of context_id, balance_dimension_id, assignment_action_id for furthur
8109       -- usage in the get_weeks_at_class procedures
8110 
8111       OPEN c_context_id;
8112       FETCH c_context_id INTO l_context_id;
8113       CLOSE c_context_id;
8114 
8115       l_defined_balance_id :=
8116            get_defined_balance_id ('_PER_PAYE_REF_PRSI_YTD', 'IE PRSI Insurable Weeks');
8117 
8118        --Bug fix 4004470
8119       /*OPEN c_assignment_action_id (
8120          p_person_id_global,
8121          p_start_date,
8122          p_end_date
8123       );
8124       CLOSE c_assignment_action_id;*/
8125 
8126       --Bug fix 4023794,  Emptying the pl/sql table
8127       /*  t_asg_action_id := t_empty_asg_table ;
8128 
8129       FOR r_asg_action_id IN c_assignment_action_id (p_person_id_global,p_start_date,p_end_date)
8130       LOOP
8131            t_asg_action_id(l_index) := r_asg_action_id.assignment_action_id;
8132 	   l_index := l_index + 1;
8133       END LOOP;*/
8134       t_asg_action_id := p_max_action_id;
8135 
8136      hr_utility.set_location (   'context_id='|| l_context_id, 10);
8137       hr_utility.set_location (   'l_balance_dimension_id=' || l_defined_balance_id, 20      );
8138       hr_utility.set_location ( 'l_assignment_action_id='|| t_asg_action_id, 30);
8139       -- looping the c_context_name cursor and stroring the first 5 classes for the assignment_id passed into the pl/sql table
8140       hr_utility.set_location (  'p_person_id_global' || p_person_id_global, 31);
8141 	hr_utility.set_location (  'p_start_date' || p_start_date, 32);
8142 	hr_utility.set_location (  'p_end_date' || p_end_date, 33);
8143 
8144 --8259095
8145     FOR r_c_main_supp_week IN c_main_supp_week(
8146                                  p_person_id_global,
8147                                  p_start_date,
8148                                  p_end_date
8149                               )
8150     LOOP
8151         l_type_context_name_tab.DELETE;
8152         OPEN c_context_name (
8153                                  p_person_id_global,
8154                                  p_start_date,
8155                                  p_end_date,
8156                                  r_c_main_supp_week.min_eff_date
8157                               );
8158         FETCH c_context_name bulk collect into l_type_context_name_tab;
8159         CLOSE c_context_name;
8160         l_supp_run_class := NULL;
8161 
8162         IF l_type_context_name_tab.COUNT > 1 THEN
8163         FOR p in l_type_context_name_tab.FIRST..l_type_context_name_tab.LAST
8164         LOOP
8165           l_supp_run_class := substr(l_type_context_name_tab(p).result_value,4,2);
8166 
8167           IF p = l_type_context_name_tab.LAST THEN
8168 				if l_context_value_counter = 0 then
8169 						l_context_value_counter := l_context_value_counter + 1;
8170 						t_context_value(l_context_value_counter) := l_type_context_name_tab(p).result_value;
8171 						hr_utility.set_location ('Initial Class Value is :'|| t_context_value (l_context_value_counter), 16);
8172 				else
8173 					For k in 1 .. l_context_value_counter
8174 					loop
8175 						if t_context_value(k) = l_type_context_name_tab(p).result_value then
8176 							temp_flag :=1;
8177 							exit;
8178 						else
8179 							temp_flag :=0;
8180 						end if;
8181 					END LOOP;
8182 					if temp_flag = 0 and l_context_value_counter <=9 then
8183 						l_context_value_counter := l_context_value_counter + 1;
8184 						t_context_value(l_context_value_counter) := l_type_context_name_tab(p).result_value;
8185 						hr_utility.set_location ('Subsequent Class Value is :'|| t_context_value (l_context_value_counter), 17);
8186 					END IF;
8187 					temp_flag := null;
8188 				END IF;
8189              IF l_supp_wk_tab.EXISTS(l_supp_run_class) THEN
8190                 l_supp_wk_tab(l_supp_run_class) := l_supp_wk_tab(l_supp_run_class) +
8191 				pay_balance_pkg.get_value (
8192 							get_defined_balance_id ('_ASG_PTD', 'IE PRSI Insurable Weeks'),
8193 							l_type_context_name_tab(p).assignment_action_id,
8194 							l_segment4,
8195 							NULL,
8196 							NULL,
8197 							NULL,
8198 							NULL,
8199 							NULL
8200 							);
8201 	        Else
8202 	           l_supp_wk_tab(l_supp_run_class) :=   pay_balance_pkg.get_value (
8203 							                            get_defined_balance_id ('_ASG_PTD', 'IE PRSI Insurable Weeks'),
8204 							                            l_type_context_name_tab(p).assignment_action_id,
8205 							                            l_segment4,
8206 						                                NULL,
8207 							                            NULL,
8208 							                            NULL,
8209 						                                NULL,
8210 							                            NULL
8211 						                                );
8212 	        End If;
8213           ELSE
8214             IF l_supp_wk_tab.EXISTS(l_supp_run_class) THEN
8215                 l_supp_wk_tab(l_supp_run_class) := l_supp_wk_tab(l_supp_run_class) -
8216 				pay_balance_pkg.get_value (
8217 							get_defined_balance_id ('_ASG_RUN', 'IE PRSI Insurable Weeks'),
8218 							l_type_context_name_tab(p).assignment_action_id,
8219 							l_segment4,
8220 							NULL,
8221 							NULL,
8222 							NULL,
8223 							NULL,
8224 							NULL
8225 							);
8226 	        Else
8227 	            l_supp_wk_tab(l_supp_run_class) := - (pay_balance_pkg.get_value (
8228 							                            get_defined_balance_id ('_ASG_RUN', 'IE PRSI Insurable Weeks'),
8229 							                            l_type_context_name_tab(p).assignment_action_id,
8230 							                            l_segment4,
8231 						                                NULL,
8232 							                            NULL,
8233 							                            NULL,
8234 						                                NULL,
8235 							                            NULL
8236 						                                ));
8237 	        End If;
8238           END IF;
8239           END LOOP;
8240         ELSIF l_type_context_name_tab.COUNT = 1 THEN
8241 			FOR q in l_type_context_name_tab.FIRST..l_type_context_name_tab.LAST
8242 			LOOP
8243 				if l_context_value_counter = 0 then
8244 						l_context_value_counter := l_context_value_counter + 1;
8245 						t_context_value(l_context_value_counter) := l_type_context_name_tab(q).result_value;
8246 						hr_utility.set_location ('Initial Class Value is :'|| t_context_value (l_context_value_counter), 18);
8247 				else
8248 					For k in 1 .. l_context_value_counter
8249 					loop
8250 						if t_context_value(k) = l_type_context_name_tab(q).result_value then
8251 							temp_flag :=1;
8252 							exit;
8253 						else
8254 							temp_flag :=0;
8255 						end if;
8256 					END LOOP;
8257 					if temp_flag = 0 and l_context_value_counter <=9 then
8258 						l_context_value_counter := l_context_value_counter + 1;
8259 						t_context_value(l_context_value_counter) := l_type_context_name_tab(q).result_value;
8260 						hr_utility.set_location ('Subsequent Class Value is :'|| t_context_value (l_context_value_counter), 19);
8261 					END IF;
8262 					temp_flag := null;
8263 				END IF;
8264 			END LOOP;
8265         END IF;
8266     END LOOP;
8267 --8259095
8268 
8269 /* -- 8259095 commented the old logic to get the Ins Weeks, same logic used in new code with supp classes.
8270       FOR r_c_context_name IN c_context_name (
8271                                  p_person_id_global,
8272                                  p_start_date,
8273                                  p_end_date
8274                               )
8275       LOOP
8276 
8277 	hr_utility.set_location('Inside c_context_name cursor..',203);
8278 	hr_utility.set_location('Inside c_context_name cursor..',203);
8279 	if l_context_value_counter = 0 then
8280 		l_context_value_counter := l_context_value_counter + 1;
8281 		t_context_value(l_context_value_counter) := r_c_context_name.result_value;
8282 		hr_utility.set_location ('Initial Class Value is :'|| t_context_value (l_context_value_counter), 16);
8283 	else
8284 		--For j in 1 .. 1
8285 		--LOOP
8286 			For k in 1 .. l_context_value_counter
8287 			loop
8288 				if t_context_value(k) = r_c_context_name.result_value then
8289 					temp_flag :=1;
8290 					exit;
8291 				else
8292 					temp_flag :=0;
8293 				end if;
8294 			END LOOP;
8295 			if temp_flag = 0 and l_context_value_counter <=9 then
8296 				l_context_value_counter := l_context_value_counter + 1;
8297 				t_context_value(l_context_value_counter) := r_c_context_name.result_value;
8298 				hr_utility.set_location ('Subsequent Class Value is :'|| t_context_value (l_context_value_counter), 17);
8299 				--temp := null;
8300 				--exit;
8301 			END IF;
8302 			temp_flag := null;
8303 		--END LOOP;
8304 	END IF;
8305 	END LOOP;
8306 */ --8259095
8307 
8308 
8309 /*           For i IN 1 .. l_context_value_counter
8310 	     LOOP
8311 			IF r_c_context_name.result_value <> t_context_value (i) THEN
8312 				t_context_value (l_context_value_counter) := r_c_context_name.result_value;
8313 				l_context_value_counter :=   l_context_value_counter + 1;
8314 		            hr_utility.set_location ('Class Value is :'|| t_context_value (l_context_value_counter), 16);
8315 			ELSE
8316 				EXIT;
8317 			END IF;
8318 		END LOOP;
8319       END LOOP;*/
8320 
8321 
8322 -- Bug 3460687 Fetching all Balance Initialization classes into a pl/sql table
8323       FOR bal_context_name IN c_context_name_bal_init (
8324                                  p_person_id_global,
8325                                  p_start_date,
8326                                  p_end_date
8327                               )
8328       LOOP
8329          IF l_context_value_counter_bal <= 10
8330          THEN
8331             l_context_value_counter_bal :=   l_context_value_counter_bal
8332                                            + 1;
8333             t_context_value_balinit (l_context_value_counter_bal) :=
8334                                                   bal_context_name.class_name;
8335             hr_utility.set_location (
8336                   'Class Value for Balance Initialization is :'
8337                || t_context_value_balinit (l_context_value_counter_bal),
8338                16
8339             );
8340          END IF;
8341       END LOOP;
8342 
8343 
8344 -- Bug 3460687 In case of only Balance Initialization and no Payrolls
8345 -- Putting all Classes into the global t_context_value table
8346       IF  t_context_value_balinit.COUNT <> 0 AND t_context_value.COUNT = 0
8347       THEN
8348          t_context_value := t_context_value_balinit;
8349          l_context_value_counter := l_context_value_counter_bal;
8350       END IF;
8351 
8352 
8353 -- Bug 3460687 In case of both Balance Initialization and Payrolls
8354 
8355       IF  t_context_value_balinit.COUNT <> 0 AND t_context_value.COUNT <> 0
8356       THEN
8357          t_context_value_tmp := t_context_value_balinit;
8358          l_context_value_counter_tmp := l_context_value_counter_bal;
8359 
8360          FOR i IN 1 .. l_context_value_counter
8361          LOOP
8362             FOR j IN 1 .. l_context_value_counter_bal
8363             LOOP
8364                IF t_context_value (i) = t_context_value_balinit (j)
8365                THEN
8366                   temp_flag := 1;
8367                   EXIT;
8368                ELSE
8369                   temp_flag := 0;
8370                END IF;
8371             END LOOP;
8372 
8373             IF  temp_flag = 0 AND l_context_value_counter_tmp <= 10
8374             THEN
8375                l_context_value_counter_tmp :=
8376                                               l_context_value_counter_tmp
8377                                             + 1;
8378                t_context_value_tmp (l_context_value_counter_tmp) :=
8379                                                           t_context_value (i);
8380                /*hr_utility.TRACE (
8381                   'A Payroll class unmatched with Balance Initialization found'
8382                );*/
8383             END IF;
8384 
8385             temp_flag := NULL;
8386          END LOOP;
8387 
8388          t_context_value := t_context_value_tmp;
8389          l_context_value_counter := l_context_value_counter_tmp;
8390       END IF;
8391 
8392       -- fetching the first class value
8393            -- Bug 2993535 - ERRORING IN CASE OF A PERSON WITHOUT A PAYROLL
8394            -- The below if clause has been added to fix the issue.
8395       IF l_context_value_counter <> 0
8396       THEN
8397          l_initial_class := NVL (t_context_value (1), NULL);
8398          hr_utility.set_location (   'l_initial_class' || l_initial_class, 50);
8399          --hr_utility.TRACE ('About to leave initial class');
8400       END IF;
8401 
8402       RETURN SUBSTR (l_initial_class, 4, 2);
8403    EXCEPTION
8404       WHEN OTHERS
8405       THEN
8406          -- Bug 2993535 - ERRORING IN CASE OF A PERSON WITHOUT A PAYROLL
8407          -- The below if clause has been added to fix the issue.
8408          -- close c_context_id;
8409          -- close c_assignment_action_id;
8410          t_context_value := t_empty_table;
8411          hr_utility.set_location ('Error in get_total_insurable_weeks', 200);
8412          RAISE;
8413    END get_initial_class;
8414 
8415 
8416 --
8417    FUNCTION get_second_class (p_assignment_id IN NUMBER)
8418       RETURN VARCHAR2
8419    AS
8420    BEGIN
8421       --
8422            -- Bug 2979713 - PRSI Context Balance Design Change
8423       --
8424       -- fetching the second class value
8425 
8426      -- hr_utility.TRACE ('In procedure get second class');
8427       hr_utility.set_location (   't_context_value '
8428                                || p_assignment_id, 20);
8429 
8430       IF l_context_value_counter >= 2
8431       THEN
8432          l_second_class := NVL (t_context_value (2), NULL);
8433       ELSE
8434          l_second_class := NULL;
8435       END IF;
8436 
8437     --  hr_utility.TRACE ('About to leave get second class');
8438       RETURN SUBSTR (l_second_class, 4, 2);
8439    END get_second_class;
8440 
8441 
8442 --
8443    FUNCTION get_p60_second_class (p_assignment_id IN NUMBER)
8444       RETURN VARCHAR2
8445    AS
8446 
8447 --
8448       CURSOR c_p60_second_class
8449       IS
8450          SELECT SUBSTR (piw.combined_class, 1, 2),
8451                 NVL (piw.insurable_weeks, 0)
8452            FROM pay_ie_p35_insurable_weeks_v piw
8453           WHERE piw.person_id =
8454                       (SELECT asg.person_id
8455                          FROM per_assignments_f asg
8456                         WHERE asg.assignment_id = p_assignment_id
8457                           AND asg.effective_start_date =
8458                                     (SELECT MIN (asg2.effective_start_date)
8459                                        FROM per_assignments_f asg2
8460                                       WHERE asg.assignment_id =
8461                                                            asg2.assignment_id))
8462             AND piw.insurable_weeks =
8463                       (SELECT MAX (piw2.insurable_weeks)
8464                          FROM pay_ie_p35_insurable_weeks_v piw2
8465                         WHERE piw2.person_id = piw.person_id
8466                           AND SUBSTR (piw2.combined_class, 1, 2) <>
8467                                                     RPAD (l_initial_class, 2))
8468             AND piw.minimum_effective_date =
8469                       (SELECT MIN (piw3.minimum_effective_date)
8470                          FROM pay_ie_p35_insurable_weeks_v piw3
8471                         WHERE piw3.person_id = piw.person_id
8472                           AND piw3.insurable_weeks = piw.insurable_weeks
8473                           AND SUBSTR (piw3.combined_class, 1, 2) <>
8474                                                     RPAD (l_initial_class, 2));
8475    --
8476    BEGIN
8477   --    hr_utility.TRACE ('In get P60 second class');
8478       /*hr_utility.TRACE (   'p_assignment_id : '
8479                         || TO_CHAR (p_assignment_id));
8480       hr_utility.TRACE (
8481             'l_class_count_at_second_class : '
8482          || TO_CHAR (l_class_count)
8483       );
8484 */
8485       IF l_class_count >= 2
8486       THEN
8487          OPEN c_p60_second_class;
8488          FETCH c_p60_second_class INTO l_second_class, l_weeks_at_second_class;
8489          CLOSE c_p60_second_class;
8490       ELSE
8491          l_second_class := ' ';
8492       END IF;
8493 
8494       /*hr_utility.TRACE (   'l_second_class : '
8495                         || l_second_class);
8496       hr_utility.TRACE (
8497             'l_weeks_at_second_class : '
8498          || TO_CHAR (l_weeks_at_second_class)
8499       );
8500       hr_utility.TRACE (   'l_initial_class : '
8501                         || l_initial_class);
8502       hr_utility.TRACE ('Leaving get_second_class');*/
8503       RETURN l_second_class;
8504    END get_p60_second_class;
8505 
8506 
8507 --
8508    FUNCTION get_third_class (p_assignment_id IN NUMBER)
8509       RETURN VARCHAR2
8510    AS
8511    BEGIN
8512            -- Bug 2979713 - PRSI Context Balance Design Change
8513       -- fetching the third class value
8514 
8515       --hr_utility.TRACE ('IN Procedure get third class');
8516 
8517       IF l_context_value_counter >= 3
8518       THEN
8519          l_third_class := NVL (t_context_value (3), NULL);
8520       ELSE
8521          l_third_class := NULL;
8522       END IF;
8523 
8524       --hr_utility.TRACE ('About to leave get third class');
8525       RETURN SUBSTR (l_third_class, 4, 2);
8526    END get_third_class;
8527 
8528 
8529 --
8530    FUNCTION get_fourth_class (p_assignment_id IN NUMBER)
8531       RETURN VARCHAR2
8532    AS
8533    BEGIN
8534            --
8535            -- Bug 2979713 - PRSI Context Balance Design Change
8536       --
8537       -- fetching the forth class value
8538 
8539      -- hr_utility.TRACE ('In procedure get fourth class');
8540 
8541       IF l_context_value_counter >= 4
8542       THEN
8543          l_fourth_class := NVL (t_context_value (4), NULL);
8544       ELSE
8545          l_fourth_class := NULL;
8546       END IF;
8547 
8548     --  hr_utility.TRACE ('About to leave get fourth class');
8549       RETURN SUBSTR (l_fourth_class, 4, 2);
8550    END get_fourth_class;
8551 
8552 
8553 --
8554    FUNCTION get_fifth_class (p_assignment_id IN NUMBER)
8555       RETURN VARCHAR2
8556    AS
8557    BEGIN
8558            --
8559       -- Bug 2979713 - PRSI Context Balance Design Change
8560       --
8561       -- fetching the fifth class value
8562 
8563       --hr_utility.TRACE ('In procedure get fifith class');
8564 
8565       IF l_context_value_counter >= 5
8566       THEN
8567          l_fifth_class := NVL (t_context_value (5), NULL);
8568       ELSE
8569          l_fifth_class := NULL;
8570       END IF;
8571 
8572    --   hr_utility.TRACE ('About to leave get fifith class');
8573       RETURN SUBSTR (l_fifth_class, 4, 2);
8574    END get_fifth_class;
8575 
8576 
8577 --
8578 /* new function */
8579 
8580 FUNCTION get_prsi_weeks (l_class IN varchar2,
8581 				 l_segment4  in number)
8582       RETURN NUMBER
8583 
8584    AS
8585 	l_weeks	number:=0;
8586    BEGIN
8587 hr_utility.set_location('l_class..'||l_class,11);
8588 hr_utility.set_location('l_defined_balance_id..'||l_defined_balance_id,11);
8589 hr_utility.set_location('t_asg_action_id..'||t_asg_action_id,11);
8590 hr_utility.set_location('l_segment4..'||l_segment4,11);
8591 hr_utility.set_location('l_class..'||l_class,11);
8592 hr_utility.set_location('l_context_id..'||l_context_id,11);
8593 hr_utility.set_location('l_class..'||l_class,11);
8594 hr_utility.set_location('l_class..'||l_class,11);
8595 
8596 
8597       l_weeks := 0;
8598 
8599 	   l_weeks := l_weeks +
8600                pay_balance_pkg.get_value (
8601                   l_defined_balance_id,
8602          		t_asg_action_id,
8603 			l_segment4,
8604                   NULL,
8605                   l_context_id,
8606                   l_class,
8607                   NULL,
8608                   NULL
8609                );
8610 hr_utility.set_location('l_weeks..'||l_weeks,11);
8611       RETURN l_weeks;
8612 END get_prsi_weeks;
8613 /* End of new function */
8614 
8615    FUNCTION weeks_at_initial_class (p_assignment_id IN NUMBER,
8616 						l_segment4  in number)
8617       RETURN NUMBER
8618    AS
8619       l_initial_weeks   NUMBER (4);
8620    BEGIN
8621       --
8622       -- Bug 2979713 - PRSI Context Balance Design Change
8623       --
8624     --  hr_utility.TRACE ('In procedure weeks_at_initial_class');
8625 
8626       IF l_initial_class IS NOT NULL
8627       THEN
8628       --Bug fix 4023794, flusing of variables
8629       l_initial_weeks := 0;
8630       --FOR csr_action_rec IN 1..t_asg_action_id.count
8631       --LOOP  -- Bug fix 4004470
8632           l_initial_weeks :=  l_initial_weeks +
8633 	                       pay_balance_pkg.get_value (
8634                                l_defined_balance_id,
8635                                t_asg_action_id,
8636 					 l_segment4,
8637                                NULL,
8638                                l_context_id,
8639                                l_initial_class,
8640                                NULL,
8641                                NULL
8642                             );
8643          hr_utility.set_location (   'l_initial_weeks'
8644                                   || l_initial_weeks, 40);
8645        --END LOOP;
8646       ELSE
8647          l_initial_weeks := 0;
8648       END IF;
8649 
8650 
8651      -- hr_utility.TRACE ('Leaving weeks_at_initial_class');
8652       RETURN l_initial_weeks;
8653    END weeks_at_initial_class;
8654 
8655 
8656 --
8657    FUNCTION weeks_at_second_class (p_assignment_id IN NUMBER,
8658 					     l_segment4  in number)
8659       RETURN NUMBER
8660    AS
8661    BEGIN
8662       --
8663       -- Bug 2979713 - PRSI Context Balance Design Change
8664       --
8665      -- hr_utility.TRACE ('In proceduer weeks_at_second_class');
8666 
8667       IF l_second_class IS NOT NULL
8668       THEN -- Bug fix 4004470
8669       l_weeks_at_second_class := 0;   --Bug fix 4023794, flusing of variables
8670       --FOR csr_action_rec IN 1..t_asg_action_id.count
8671       --LOOP
8672          l_weeks_at_second_class := l_weeks_at_second_class +
8673                pay_balance_pkg.get_value (
8674                   l_defined_balance_id,
8675                   -- l_assignment_action_id,
8676 			t_asg_action_id,
8677 			l_segment4,
8678                   NULL,
8679                   l_context_id,
8680                   l_second_class,
8681                   NULL,
8682                   NULL
8683                );
8684 	--END LOOP;
8685       ELSE
8686          l_weeks_at_second_class := 0;
8687       END IF;
8688    --   hr_utility.TRACE ('Leaving proceduer weeks_at_second_class');
8689       RETURN l_weeks_at_second_class;
8690    END weeks_at_second_class;
8691 
8692 
8693 --
8694    FUNCTION weeks_at_third_class (p_assignment_id IN NUMBER,
8695 					    l_segment4  in number)
8696       RETURN NUMBER
8697    AS
8698    BEGIN
8699       --
8700       -- Bug 2979713 - PRSI Context Balance Design Change
8701       --
8702      -- hr_utility.TRACE ('In procedure weeks_at_third_class');
8703       IF l_third_class IS NOT NULL
8704       THEN     -- Bug fix 4004470
8705               l_weeks_at_third_class := 0; --Bug fix 4023794, flusing of variables
8706 	      --FOR csr_action_rec IN 1..t_asg_action_id.count
8707 	      --LOOP
8708 		 l_weeks_at_third_class := l_weeks_at_third_class +
8709 		       pay_balance_pkg.get_value (
8710 			  l_defined_balance_id,
8711 			  --l_assignment_action_id,
8712 			  t_asg_action_id,
8713 			  l_segment4,
8714 			  NULL,
8715 			  l_context_id,
8716 			  l_third_class,
8717 			  NULL,
8718 			  NULL
8719 		       );
8720 	      --END LOOP;
8721       ELSE
8722          l_weeks_at_third_class := 0;
8723       END IF;
8724     --  hr_utility.TRACE ('Leaving procedure weeks_at_third_class');
8725       RETURN l_weeks_at_third_class;
8726    END weeks_at_third_class;
8727 
8728 
8729 --
8730    FUNCTION weeks_at_fourth_class (p_assignment_id IN NUMBER,
8731 					     l_segment4  in number)
8732       RETURN NUMBER
8733    AS
8734    BEGIN
8735       -- Bug 2979713 - PRSI Context Balance Design Change
8736 
8737     -- hr_utility.TRACE ('In procedure weeks_at_fourth_class');
8738       IF l_fourth_class IS NOT NULL
8739       THEN    -- Bug fix 4004470
8740              l_weeks_at_fourth_class := 0; --Bug fix 4023794, flusing of variables
8741 	      --FOR csr_action_rec IN 1..t_asg_action_id.count
8742 	      --LOOP
8743 		 l_weeks_at_fourth_class := l_weeks_at_fourth_class +
8744 		       pay_balance_pkg.get_value (
8745 			  l_defined_balance_id,
8746 			  -- l_assignment_action_id,
8747 			  t_asg_action_id,
8748 			  l_segment4,
8749 			  NULL,
8750 			  l_context_id,
8751 			  l_fourth_class,
8752 			  NULL,
8753 			  NULL
8754 		       );
8755 	     -- END LOOP;
8756       ELSE
8757          l_weeks_at_fourth_class := 0;
8758       END IF;
8759 
8760 --hr_utility.TRACE ('Ieaving weeks_at_fourth_class');
8761       RETURN l_weeks_at_fourth_class;
8762       --hr_utility.TRACE ('About to leave get weeks at fourth class');
8763    END weeks_at_fourth_class;
8764 
8765 
8766 /* Added for fifth class by vik */
8767 
8768   FUNCTION weeks_at_fifth_class (p_assignment_id IN NUMBER,
8769 					     l_segment4  in number)
8770       RETURN NUMBER
8771    AS
8772    BEGIN
8773       -- Bug 2979713 - PRSI Context Balance Design Change
8774 
8775     -- hr_utility.TRACE ('In procedure weeks_at_fourth_class');
8776       IF l_fifth_class IS NOT NULL
8777       THEN
8778              l_weeks_at_fifth_class := 0;
8779 		 l_weeks_at_fifth_class := l_weeks_at_fifth_class +
8780 		       pay_balance_pkg.get_value (
8781 			  l_defined_balance_id,
8782 			  t_asg_action_id,
8783 			  l_segment4,
8784 			  NULL,
8785 			  l_context_id,
8786 			  l_fifth_class,
8787 			  NULL,
8788 			  NULL
8789 		       );
8790       ELSE
8791          l_weeks_at_fifth_class := 0;
8792       END IF;
8793 
8794       RETURN l_weeks_at_fifth_class;
8795    END weeks_at_fifth_class;
8796 
8797 /* End of weeks_at_fifth class */
8798 
8799 --
8800 
8801    FUNCTION get_total_insurable_weeks (p_person_id IN NUMBER
8802 						,p_tax_unit_id IN NUMBER
8803 						,p_assignment_action_id IN NUMBER
8804 						,p_Act_Context_id  number default NULL  --6633719
8805 						,p_Act_Context_value varchar2 default NULL --6633719
8806 						,p_dimension_name varchar2 default '_PER_PAYE_REF_YTD' --6633719
8807                         ,p_ppsn_override VARCHAR2 default NULL) --6633719
8808       RETURN NUMBER
8809    AS
8810 
8811       l_total_weeks                NUMBER (4) := 0; --Bug No 4555227
8812       l_get_assignment_action_id   pay_assignment_actions.assignment_action_id%TYPE;
8813    --
8814    --
8815 
8816    BEGIN
8817        --
8818 	 hr_utility.set_location('In Insurable Weeks.',201);
8819 	 hr_utility.set_location('In Insurable Weeks.'||to_char(p_assignment_action_id),202);
8820 
8821 	p_start_date := get_start_date ();
8822       p_end_date := get_end_date ();
8823 
8824 	IF p_person_id <> p_person_id_global OR p_ppsn_override IS NOT NULL  --6633719
8825       THEN
8826          t_context_value := t_empty_table;
8827          l_context_value_counter := 0;
8828          t_context_value_balinit := t_empty_table;
8829          t_context_value_tmp := t_empty_table;
8830          l_supp_wk_tab := l_supp_wk_tab_empty;  --9080372
8831       END IF;
8832 
8833 	p_person_id_global := p_person_id;
8834 
8835 	 l_total_weeks := 0;
8836 	  --Bug fix 4004470
8837          l_total_weeks :=l_total_weeks +
8838                  nvl(pay_balance_pkg.get_value (
8839 			    pay_ie_p35.get_defined_balance_id (
8840 				 p_dimension_name,  --'_PER_PAYE_REF_YTD', -- changes made  --6633719
8841 				 'IE PRSI Insurable Weeks'
8842 			    ),
8843 			    p_assignment_action_id, --paa.assignment_action_id,
8844 			    p_tax_unit_id, -- paye reference value
8845 				  null,
8846 				   p_Act_Context_id,  --null,  --6633719
8847 				   p_Act_Context_value,  --null,  --6633719
8848 				   null,
8849 				   null,
8850 				   null,
8851 				  'TRUE'
8852 			 ),0)
8853 		   +
8854 		   nvl(pay_balance_pkg.get_value (
8855 			    pay_ie_p35.get_defined_balance_id (
8856 				 p_dimension_name,  --'_PER_PAYE_REF_YTD', -- changes made  --6633719
8857 				 'IE PRSI K Term Insurable Weeks'
8858 			    ),
8859 			    p_assignment_action_id, --paa.assignment_action_id,
8860 			    p_tax_unit_id, -- paye reference value
8861 				  null,
8862 				   p_Act_Context_id,  --null,  --6633719
8863 				   p_Act_Context_value,  --null,  --6633719
8864 				   null,
8865 				   null,
8866 				   null,
8867 				  'TRUE'
8868 			 ),0)
8869                   + nvl(pay_balance_pkg.get_value (
8870 			    pay_ie_p35.get_defined_balance_id (
8871 				 p_dimension_name,  --'_PER_PAYE_REF_YTD', -- changes made  --6633719
8872 				 'IE PRSI M Term Insurable Weeks'
8873 			    ),
8874 			    p_assignment_action_id, --paa.assignment_action_id,
8875 			    p_tax_unit_id, -- paye reference value
8876 				  null,
8877 				   p_Act_Context_id,  --null,  --6633719
8878 				   p_Act_Context_value,  --null,  --6633719
8879 				   null,
8880 				   null,
8881 				   null,
8882 				  'TRUE'
8883 			 ),0) ;
8884 
8885 
8886 
8887      /* CLOSE c_get_assignment_action_id;*/
8888         --hr_utility.TRACE ('Else l_total_weeks='|| l_total_weeks);
8889       RETURN l_total_weeks;
8890    EXCEPTION
8891       WHEN OTHERS
8892       THEN
8893          --CLOSE c_get_assignment_action_id;
8894          t_context_value := t_empty_table;
8895          t_context_value_balinit := t_empty_table;
8896          t_context_value_tmp := t_empty_table;
8897          hr_utility.set_location ('Error in get_total_insurable_weeks', 200);
8898          RAISE;
8899    END get_total_insurable_weeks;
8900 
8901 
8902 --
8903    FUNCTION get_start_date
8904       RETURN DATE
8905    AS
8906       l_start_date   DATE;
8907    BEGIN
8908       SELECT fnd_date.canonical_to_date (
8909                    SUBSTR (fpov.profile_option_value, 1, 4)
8910                 || '01/01 00:00:00'
8911              )
8912         INTO l_start_date
8913         FROM fnd_profile_option_values fpov, fnd_profile_options fpo
8914        WHERE fpo.profile_option_id = fpov.profile_option_id
8915          AND fpo.application_id = fpov.application_id
8916          AND fpo.profile_option_name = 'PAY_IE_P35_REPORTING_YEAR'
8917          AND fpov.level_id = 10001
8918          AND fpov.level_value = 0;
8919 
8920       RETURN l_start_date;
8921    END get_start_date;
8922 
8923 
8924 --
8925    FUNCTION get_end_date
8926       RETURN DATE
8927    AS
8928       l_end_date   DATE;
8929    BEGIN
8930       SELECT fnd_date.canonical_to_date (
8931                    SUBSTR (fpov.profile_option_value, 1, 4)
8932                 || '12/31 23:59:59'
8933              )
8934         INTO l_end_date
8935         FROM fnd_profile_option_values fpov, fnd_profile_options fpo
8936        WHERE fpo.profile_option_id = fpov.profile_option_id
8937          AND fpo.application_id = fpov.application_id
8938          AND fpo.profile_option_name = 'PAY_IE_P35_REPORTING_YEAR'
8939          AND fpov.level_id = 10001
8940          AND fpov.level_value = 0;
8941 
8942       RETURN l_end_date;
8943    END get_end_date;
8944 
8945 Function check_assignment_in_set(
8946  				 p_assignment_id per_assignments_f.assignment_id%TYPE,
8947 				 p_assignment_set_id hr_assignment_sets.assignment_set_id%TYPE,
8948 				 p_business_group per_assignments_f.business_group_id%TYPE
8949 				) return NUMBER
8950 		AS
8951 	CURSOR csr_locked_asg_sets
8952 	is
8953         select hasa.include_or_exclude from hr_assignment_set_amendments hasa, hr_assignment_sets has
8954 	                               where hasa.assignment_set_id = has.assignment_set_id
8955 				       and has.business_group_id = p_business_group
8956 				       and has.assignment_set_id = p_assignment_set_id
8957 				       and hasa.assignment_id = p_assignment_id;
8958 	CURSOR csr_get_flag_from_set
8959 	is
8960 	select distinct hasa.include_or_exclude from hr_assignment_set_amendments hasa, hr_assignment_sets has
8961 	                               where hasa.assignment_set_id = has.assignment_set_id
8962 				       and has.business_group_id = p_business_group
8963 				       and has.assignment_set_id = p_assignment_set_id;
8964 	l_set_flag Varchar2(30) :=null;
8965 	l_flag Varchar2(30) :=null;
8966 	BEGIN
8967 		IF p_assignment_set_id is null THEN
8968 		 return 1;
8969 		ELSE
8970 			OPEN csr_locked_asg_sets;
8971 			FETCH csr_locked_asg_sets into l_set_flag;
8972 			CLOSE csr_locked_asg_sets;
8973 			IF (l_set_flag IS NOT NULL) THEN
8974 				IF l_set_flag ='E' THEN
8975 				   return 0;
8976 				ELSIF l_set_flag ='I' THEN
8977 				   return 1;
8978 				END IF;
8979 			ELSE --l_set_flag is null
8980 				OPEN csr_get_flag_from_set;
8981 				FETCH csr_get_flag_from_set into l_flag;
8982 				CLOSE csr_get_flag_from_set ;
8983 				IF l_flag IS NULL THEN
8984 					return 0; -- Assignment set is empty
8985 				ELSIF l_flag ='I' THEN
8986 					return 0; --Present assignment is not present is Inclusion set
8987 				ELSIF l_flag ='E' THEN
8988 					return 1; --Present assignment is not present is Exclusion set
8989 				END IF;
8990 			END IF;
8991 		END IF;
8992 END check_assignment_in_set;
8993 
8994    /*Added for bug fix 3815830*/
8995    FUNCTION replace_xml_symbols(p_string IN VARCHAR2)
8996       RETURN VARCHAR2
8997    AS
8998 
8999       l_string   VARCHAR2(300);
9000 
9001    BEGIN
9002 
9003 
9004 	l_string :=  p_string;
9005 
9006 	l_string := replace(l_string, '&', '&');
9007 	l_string := replace(l_string, '<', '<');
9008 	l_string := replace(l_string, '>', '>');
9009       l_string := replace(l_string, '''',''');
9010 	l_string := replace(l_string, '"', '"');
9011 	-- bug 6275544, called
9012 	l_string := pay_ie_p35_magtape.test_XML(l_string);
9013 	-- bug 5867343, special characters.
9014 	/*l_string := replace(l_string, fnd_global.local_chr(193),'Á');
9015 	l_string := replace(l_string, fnd_global.local_chr(201),'É');
9016 	l_string := replace(l_string, fnd_global.local_chr(205),'Í');
9017 	l_string := replace(l_string, fnd_global.local_chr(211),'Ó');
9018 	l_string := replace(l_string, fnd_global.local_chr(218),'Ú');
9019 	l_string := replace(l_string, fnd_global.local_chr(225),'á');
9020 	l_string := replace(l_string, fnd_global.local_chr(233),'é');
9021 	l_string := replace(l_string, fnd_global.local_chr(237),'í');
9022 	l_string := replace(l_string, fnd_global.local_chr(243),'ó');
9023 	l_string := replace(l_string, fnd_global.local_chr(250),'ú');*/
9024 
9025 
9026 
9027 
9028    RETURN l_string;
9029    EXCEPTION when no_data_found then
9030      null;
9031    END replace_xml_symbols;
9032 
9033  END pay_ie_p35;