DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_NL_PAYSLIP_ARCHIVE

Source


1 PACKAGE BODY PAY_NL_PAYSLIP_ARCHIVE as
2 /* $Header: pynlparc.pkb 120.30 2010/11/01 14:10:57 vijranga noship $ */
3 
4 g_package                  varchar2(33) := '  PAY_NL_PAYSLIP_ARCHIVE.';
5 
6 
7 -----------------------------------------------------------------------------
8 -- Globals
9 -----------------------------------------------------------------------------
10 TYPE balance_rec IS RECORD (
11     balance_type_id      NUMBER,
12     balance_dimension_id NUMBER,
13     defined_balance_id   NUMBER,
14     balance_narrative    VARCHAR2(30),
15     balance_name         pay_balance_types.balance_name%TYPE,
16     database_item_suffix pay_balance_dimensions.database_item_suffix%TYPE,
17     si_type              hr_lookups.meaning%TYPE,
18     legislation_code     pay_balance_dimensions.legislation_code%TYPE);
19 
20 TYPE element_rec IS RECORD (
21     element_type_id      NUMBER,
22     input_value_id       NUMBER,
23     formula_id           NUMBER,
24     si_type              hr_lookups.meaning%TYPE,
25     element_narrative    VARCHAR2(30));
26 
27 TYPE statutory_element_rec IS RECORD (
28    classification_name  pay_element_classifications.classification_name%TYPE
29   ,element_name         pay_element_types_f.element_name%TYPE
30   ,element_type         VARCHAR2(1)
31   ,main_index           NUMBER
32   ,archive_flag		VARCHAR2(1)
33   ,standard		pay_element_types_f.element_name%TYPE
34   ,special		pay_element_types_f.element_name%TYPE
35   ,standard2		pay_element_types_f.element_name%TYPE
36   ,special2		pay_element_types_f.element_name%TYPE
37   ,payable_flag		VARCHAR2(1));
38 
39 
40 TYPE balance_table   IS TABLE OF  balance_rec   INDEX BY BINARY_INTEGER;
41 TYPE element_table   IS TABLE OF  element_rec   INDEX BY BINARY_INTEGER;
42 TYPE stat_element_table IS TABLE OF statutory_element_rec
43 			INDEX BY BINARY_INTEGER;
44 --
45 -- Global Tables for holding Elements, User/Statutory Balances.
46 --
47 g_element_table                   element_table;
48 g_user_balance_table              balance_table;
49 g_statutory_balance_table         balance_table;
50 g_stat_element_table              stat_element_table;
51 g_zvw_er_cont_std_run NUMBER;
52 g_zvw_er_cont_spl_run NUMBER;
53 g_zvw_er_cont_std_ytd NUMBER;
54 g_zvw_er_cont_spl_ytd NUMBER;
55 g_retro_zvw_er_cont_std_run NUMBER;
56 g_retro_zvw_er_cont_spl_run NUMBER;
57 g_retro_zvw_er_cont_std_ytd NUMBER;
58 g_retro_zvw_er_cont_spl_ytd NUMBER;
59 g_travel_allowance NUMBER;
60 g_retro_travel_allowance NUMBER;
61 g_travel_allowance_ytd NUMBER;
62 g_retro_travel_allowance_ytd NUMBER;
63 g_payroll_action_id	NUMBER;
64 
65 /*-------------------------------------------------------------------------------
66 |Name           : GET_DEFINED_BALANCE_ID                                       	|
67 |Type		: Function							|
68 |Description    : Function to get the defined balance id of the given balance 	|
69 |		  type and dimension						|
70 -------------------------------------------------------------------------------*/
71 
72 FUNCTION get_defined_balance_id (p_balance_name VARCHAR2
73 				,p_dimension_name VARCHAR2) RETURN NUMBER AS
74     --
75     CURSOR csr_defined_balance_id is
76     SELECT pdb.defined_balance_id
77     FROM   pay_balance_dimensions pbd
78           ,pay_balance_types      pbt
79           ,pay_defined_balances pdb
80     WHERE  pbd.database_item_suffix = p_dimension_name
81     AND    pbd.business_group_id is null
82     AND    pbd.legislation_code='NL'
83     AND    pbt.balance_name = p_balance_name
84     AND    pbt.business_group_id is null
85     AND    pbt.legislation_code='NL'
86     AND    pdb.balance_type_id = pbt.balance_type_id
87     AND    pdb.balance_dimension_id= pbd.balance_dimension_id
88     AND    pdb.business_group_id is null
89     AND    pdb.legislation_code='NL';
90     --
91     l_defined_balance_id pay_defined_balances.defined_balance_id%TYPE;
92     --
93 BEGIN
94     --
95     OPEN csr_defined_balance_id ;
96         FETCH csr_defined_balance_id INTO l_defined_balance_id;
97     CLOSE csr_defined_balance_id ;
98     RETURN l_defined_balance_id;
99     EXCEPTION
100     WHEN NO_DATA_FOUND THEN
101     hr_utility.set_location('get_defined_balance_id NO_DATA_FOUND'||SQLCODE||SQLERRM,2511);
102     null;
103     --
104 END get_defined_balance_id;
105 
106 /*-------------------------------------------------------------------------------
107 |Name           : SETUP_STATUTORY_BALANCE_TABLE                                	|
108 |Type			: Procedure														|
109 |Description    : Procedure sets the global table g_statutory_balance_table.    |
110 -------------------------------------------------------------------------------*/
111 Procedure setup_statutory_balance_table(p_date_earned IN DATE, p_bg_id NUMBER) is
112 	--
113 	--
114 	CURSOR csr_user_stat_exists IS
115 	SELECT 1
116 	FROM pay_user_tables put
117 	WHERE put.legislation_code IS NULL
118 	AND put.business_group_id = p_bg_id
119 	AND put.user_table_name   = 'NL_USER_STATUTORY_BALANCES';
120 	--
121 
122 	CURSOR csr_get_user_stat_balances(p_effecitve_date IN DATE) IS
123 
124 	SELECT TRIM(user_column_name)   bal_dimension
125 		  ,TRIM(pur.row_low_range_or_name)   bal_name
126 	FROM   pay_user_columns puc
127 		  ,pay_user_rows_f  pur
128 		  ,pay_user_tables  put
129 		  ,pay_user_column_instances_f puci
130 	WHERE  put.legislation_code  IS NULL
131 	AND    put.business_group_id = p_bg_id
132 	AND    pur.user_table_id     = put.user_table_id
133 	AND    puc.user_table_id     = put.user_table_id
134 	AND    puci.user_row_id      = pur.user_row_id
135 	AND    puci.user_column_id   = puc.user_column_id
136 	AND    put.user_table_name   = 'NL_USER_STATUTORY_BALANCES'
137 	AND    p_effecitve_date      BETWEEN puci.effective_start_date
138 								 AND     puci.effective_end_date
139 	AND    p_effecitve_date      BETWEEN pur.effective_start_date
140 								 AND     pur.effective_end_date;
141 	--
142 
143 	CURSOR csr_get_statutory_balances(p_effecitve_date IN DATE) IS
144 
145 	SELECT TRIM(user_column_name)   bal_dimension
146 		  ,TRIM(pur.row_low_range_or_name)   bal_name
147 	FROM   pay_user_columns puc
148 		  ,pay_user_rows_f  pur
149 		  ,pay_user_tables  put
150 		  ,pay_user_column_instances_f puci
151 	WHERE  put.legislation_code  = 'NL'
152 	AND    pur.user_table_id     = put.user_table_id
153 	AND    puc.user_table_id     = put.user_table_id
154 	AND    puci.user_row_id      = pur.user_row_id
155 	AND    puci.user_column_id   = puc.user_column_id
156 	AND    put.user_table_name   = 'NL_STATUTORY_BALANCES'
157 	AND    p_effecitve_date      BETWEEN puci.effective_start_date
158 								 AND     puci.effective_end_date
159 	AND    p_effecitve_date      BETWEEN pur.effective_start_date
160 								 AND     pur.effective_end_date;
161 	--
162 	--
163 
164 	l_index			NUMBER:=1;
165 	l_count			NUMBER:=1;
166 	l_user_stat_exists NUMBER:=0;
167 
168 BEGIN
169 --
170 --
171 --
172 OPEN csr_user_stat_exists;
173 FETCH csr_user_stat_exists INTO l_user_stat_exists;
174 CLOSE csr_user_stat_exists;
175 
176 IF l_user_stat_exists = 1 THEN
177 FOR stat_bal_rec IN csr_get_user_stat_balances(p_date_earned) LOOP
178     g_statutory_balance_table(l_index).balance_name         := stat_bal_rec.bal_name;
179     g_statutory_balance_table(l_index).database_item_suffix :=
180                                             stat_bal_rec.bal_dimension;
181 
182     --hr_utility.set_location('setup_statutory_balance_table bal_name'||g_statutory_balance_table(l_index).balance_name,673);
183     --hr_utility.set_location('setup_statutory_balance_table bal_dimension'||g_statutory_balance_table(l_index).database_item_suffix,673);
184 
185     g_statutory_balance_table(l_index).defined_balance_id   :=
186     				get_defined_balance_id (stat_bal_rec.bal_name,stat_bal_rec.bal_dimension);
187 
188     --hr_utility.set_location('setup_statutory_balance_table defined bal id'||g_statutory_balance_table(l_index).defined_balance_id,674);
189     l_index := l_index + 1;
190     --
191 END LOOP;
192 END IF;
193 /* If no data found in NL_USER_STATUTORY_BALANCES, use NL_STATUTORY_BALANCES*/
194 IF l_user_stat_exists = 0 THEN
195 FOR stat_bal_rec IN csr_get_statutory_balances(p_date_earned) LOOP
196   --
197   -- Check whether this balance-dimension combination has been archived
198   -- before while archiving user balances if not populate the table.
199 
200 
201     g_statutory_balance_table(l_index).balance_name         := stat_bal_rec.bal_name;
202     g_statutory_balance_table(l_index).database_item_suffix :=
203                                             stat_bal_rec.bal_dimension;
204 
205     --hr_utility.set_location('setup_statutory_balance_table bal_name'||g_statutory_balance_table(l_index).balance_name,673);
206     --hr_utility.set_location('setup_statutory_balance_table bal_dimension'||g_statutory_balance_table(l_index).database_item_suffix,673);
207 
208 
209     g_statutory_balance_table(l_index).defined_balance_id   :=
210     				get_defined_balance_id (stat_bal_rec.bal_name,stat_bal_rec.bal_dimension);
211 
212     --hr_utility.set_location('setup_statutory_balance_table defined bal id'||g_statutory_balance_table(l_index).defined_balance_id,674);
213 
214     l_index := l_index + 1;
215     --
216   /*END IF;*/
217 END LOOP;
218 END IF;
219 --
220 END;
221 
222 
223 
224 /*-------------------------------------------------------------------------------
225 |Name           : GET_PARAMETER    						|
226 |Type		: Function							|
227 |Description    : Funtion used in sql to decode legislative parameters     	|
228 -------------------------------------------------------------------------------*/
229 
230 function get_parameter(
231          p_parameter_string in varchar2
232         ,p_token            in varchar2
233         ,p_segment_number   in number default null )    RETURN varchar2
234 IS
235 
236   l_parameter  pay_payroll_actions.legislative_parameters%TYPE:=NULL;
237   l_start_pos  NUMBER;
238   l_delimiter  varchar2(1):=' ';
239   l_proc VARCHAR2(40):= g_package||' get parameter ';
240 
241 BEGIN
242 	--
243 	--hr_utility.set_location('Entering get_parameter',52);
244 	--
245 	l_start_pos := instr(' '||p_parameter_string,l_delimiter||p_token||'=');
246 	--
247 	IF l_start_pos = 0 THEN
248 		l_delimiter := '|';
249 		l_start_pos := instr(' '||p_parameter_string,l_delimiter||p_token||'=');
250 	end if;
251 
252 	IF l_start_pos <> 0 THEN
253 		l_start_pos := l_start_pos + length(p_token||'=');
254 		l_parameter := substr(p_parameter_string,
255 							  l_start_pos,
256 							  instr(p_parameter_string||' ',
257 							  l_delimiter,l_start_pos)
258 							  - l_start_pos);
259 		IF p_segment_number IS NOT NULL THEN
260 			l_parameter := ':'||l_parameter||':';
261 			l_parameter := substr(l_parameter,
262 								instr(l_parameter,':',1,p_segment_number)+1,
263 								instr(l_parameter,':',1,p_segment_number+1) -1
264 								- instr(l_parameter,':',1,p_segment_number));
265 		END IF;
266 	END IF;
267 	--
268 	--hr_utility.set_location('Leaving get_parameter',53);
269 	--hr_utility.set_location('Entering get_parameter l_parameter--'||l_parameter||'--',54);
270 	RETURN l_parameter;
271 END get_parameter;
272 
273 /*-------------------------------------------------------------------------------
274 |Name           : GET_ALL_PARAMETERS                                           	|
275 |Type		: Procedure							|
276 |Description    : Procedure which returns all the parameters of the archive	|
277 |		  process						   	|
278 -------------------------------------------------------------------------------*/
279 
280 PROCEDURE get_all_parameters(
281        p_payroll_action_id                    IN   NUMBER
282       ,p_business_group_id                    OUT  NOCOPY NUMBER
283       ,p_start_date                           OUT  NOCOPY VARCHAR2
284       ,p_end_date                             OUT  NOCOPY VARCHAR2
285       ,p_effective_date                       OUT  NOCOPY DATE
286       ,p_payroll_id                           OUT  NOCOPY VARCHAR2
287       ,p_consolidation_set                    OUT  NOCOPY VARCHAR2) IS
288 --
289 CURSOR csr_parameter_info(p_payroll_action_id NUMBER) IS
290 
291 SELECT PAY_NL_PAYSLIP_ARCHIVE.get_parameter(legislative_parameters,'PAYROLL_ID')
292       ,PAY_NL_PAYSLIP_ARCHIVE.get_parameter(legislative_parameters,'CONSOLIDATION_SET_ID')
293       ,PAY_NL_PAYSLIP_ARCHIVE.get_parameter(legislative_parameters,'START_DATE')
294       ,PAY_NL_PAYSLIP_ARCHIVE.get_parameter(legislative_parameters,'END_DATE')
295       ,effective_date
296       ,business_group_id
297 FROM  pay_payroll_actions
298 WHERE payroll_action_id = p_payroll_action_id;
299 
300 --
301 
302 l_proc VARCHAR2(240):= g_package||' get_all_parameters ';
303 --
304 BEGIN
305 --
306   --hr_utility.set_location('Entering get_all_parameters',51);
307 
308 OPEN csr_parameter_info (p_payroll_action_id);
309 FETCH csr_parameter_info INTO p_payroll_id
310 			     ,p_consolidation_set
311 			     ,p_start_date
312 			     ,p_end_date
313 			     ,p_effective_date
314 		     	     ,p_business_group_id;
315 CLOSE csr_parameter_info;
316 --
317 --hr_utility.set_location('Leaving get_all_parameters',54);
318 
319 END;
320 
321 
322 --
323 /*-------------------------------------------------------------------------------
324 |Name           : GET_EIT_DEFINITIONS                                       	|
325 |Type		: Procedure							|
326 |Description    : Procedure to get the Balances and Elements at the business 	|
327 |		  group level and archives the contexts EMEA BALANCE DEFINITION |
328 |		  AND EMEA ELEMENT DEFINITION					|
329 -------------------------------------------------------------------------------*/
330 
331 PROCEDURE get_eit_definitions(p_pactid            IN NUMBER,
332                               p_business_group_id IN NUMBER,
333                               p_payroll_pact      IN NUMBER,
334                               p_effective_date    IN DATE,
335                               p_eit_context       IN VARCHAR2,
336                               p_archive           IN VARCHAR2) IS
337 
338     --
339     -- This cursor fetches the EIT information stored at BG level for
340     -- NL_PAYSLIP_ELEMENTS/NL_PAYSLIP_BALANCES context
341     --
342     --
343     CURSOR csr_eit_values(p_bg_id   NUMBER
344                          ,p_context VARCHAR2) IS
345     SELECT org.org_information1,
346            org.org_information2,
347            org.org_information3,
348            org.org_information4
349     FROM   hr_organization_information_v org
350     WHERE  org.org_information_context = p_context
351     AND    org.organization_id = p_bg_id;
352     --
353     --
354     -- This cursor gets the balance information that needs to be
355     -- archived/populated in global pl/sql table for later use.
356     --
357     --
358     --
359     CURSOR csr_balance_name(p_balance_type_id      NUMBER
360                            ,p_balance_dimension_id NUMBER) IS
361     SELECT pbt.balance_name,
362            pbd.database_item_suffix,
363            pbt.legislation_code,
364            pdb.defined_balance_id
365     FROM   pay_balance_types pbt,
366            pay_balance_dimensions pbd,
367            pay_defined_balances pdb
368     WHERE  pdb.balance_type_id = pbt.balance_type_id
369     AND    pdb.balance_dimension_id = pbd.balance_dimension_id
370     AND    pbt.balance_type_id = p_balance_type_id
371     AND    pbd.balance_dimension_id = p_balance_dimension_id;
372     --
373     --
374     -- Supporting cursors for archiving EMEA_ELEMENT_DEFINITIONS
375     --
376     --
377     --
378     --Bug 3601121
379     --Returns the iterative formula id defined for an element
380     CURSOR csr_isgrossup_element(p_element_type_id NUMBER,
381                             p_effective_date  DATE) IS
382     SELECT pet.iterative_formula_id
383     FROM   pay_element_types_f pet
384     WHERE  pet.element_type_id = p_element_type_id
385     AND    p_effective_date BETWEEN pet.effective_start_date
386                             AND     pet.effective_end_date;
387 
388     CURSOR csr_input_value_uom(p_input_value_id NUMBER,
389                                p_effective_date DATE) IS
390     SELECT piv.uom
391     FROM   pay_input_values_f piv
392     WHERE  piv.input_value_id = p_input_value_id
393     AND    p_effective_date   BETWEEN piv.effective_start_date
394                               AND     piv.effective_end_date;
395 
396 	l_element_index       PLS_INTEGER :=0;
397 	l_balance_index       PLS_INTEGER :=0;
398 	l_action_info_id 	NUMBER;
399 	l_formula_id		NUMBER;
400 	l_uom			pay_input_values.uom%TYPE;
401 	l_ovn			NUMBER;
402 	l_business_group_id	NUMBER;
403 	l_listed                BOOLEAN;
404 	v_csr_balance_name      csr_balance_name%ROWTYPE;
405 	l_char                  varchar2(10);
406 BEGIN
407 --
408 --
409 --hr_utility.set_location('Entering Get EIT Definitions',56);
410 
411 FOR csr_eit_rec IN csr_eit_values(p_business_group_id
412                                  ,p_eit_context)  LOOP
413 --
414 
415 --hr_utility.set_location('For Each EIT Record'||p_eit_context,57);
416 --
417 
418 IF  p_eit_context = 'NL_PAYSLIP_BALANCES' THEN
419     --
420     --
421     OPEN
422          csr_balance_name(csr_eit_rec.org_information1
423                    ,csr_eit_rec.org_information2);
424             FETCH csr_balance_name INTO
425                       v_csr_balance_name.balance_name
426                      ,v_csr_balance_name.database_item_suffix
427                      ,v_csr_balance_name.legislation_code
428                      ,v_csr_balance_name.defined_balance_id;
429     CLOSE csr_balance_name;
430     l_listed := FALSE;
431     l_char := 'N';
432     FOR l_index in 1..g_statutory_balance_table.count LOOP
433     	IF g_statutory_balance_table(l_index).defined_balance_id = v_csr_balance_name.defined_balance_id THEN
434     	    l_listed := TRUE;
435     	    l_char := 'Y';
436     	    EXIT;
437     	END IF;
438     END LOOP;
439 
440     IF l_char = 'N' THEN
441 		l_balance_index := l_balance_index+1;
442 		g_user_balance_table(l_balance_index).balance_type_id      :=
443 								 csr_eit_rec.org_information1;
444 		g_user_balance_table(l_balance_index).balance_dimension_id :=
445 								 csr_eit_rec.org_information2;
446 		g_user_balance_table(l_balance_index).si_type    :=
447 								 csr_eit_rec.org_information3;
448 		g_user_balance_table(l_balance_index).balance_narrative    :=
449 								 csr_eit_rec.org_information4;
450 		g_user_balance_table(l_balance_index).balance_name := v_csr_balance_name.balance_name;
451 		g_user_balance_table(l_balance_index).database_item_suffix := v_csr_balance_name.database_item_suffix;
452 		g_user_balance_table(l_balance_index).legislation_code := v_csr_balance_name.legislation_code;
453 		g_user_balance_table(l_balance_index).defined_balance_id := v_csr_balance_name.defined_balance_id;
454     END IF;
455 	--
456 	--hr_utility.set_location('For NL_PAYSLIP_BALANCES'||p_eit_context,58);
457 	--
458 	--
459 	--
460     IF  p_archive = 'Y' THEN
461         --
462         --hr_utility.set_location('For NL_PAYSLIP_BALANCES'||g_user_balance_table(l_balance_index).balance_name,59);
463         --
464         -- Archive EMEA BALANCE DEFINITION
465         pay_action_information_api.create_action_information (
466         p_action_information_id        =>  l_action_info_id
467        ,p_action_context_id            =>  p_pactid
468        ,p_action_context_type          =>  'PA'
469        ,p_object_version_number        =>  l_ovn
470        ,p_effective_date               =>  p_effective_date
471        ,p_source_id                    =>  NULL
472        ,p_source_text                  =>  NULL
473        ,p_action_information_category  =>  'EMEA BALANCE DEFINITION'
474        ,p_action_information1          =>  NULL
475        ,p_action_information2          =>  v_csr_balance_name.defined_balance_id
476        ,p_action_information4          => csr_eit_rec.org_information4
477        ,p_action_information6          => csr_eit_rec.org_information3);
478 
479        --
480     END IF;
481     --
482 END IF;
483 --
484 IF  p_eit_context = 'NL_PAYSLIP_ELEMENTS' THEN
485     --
486     l_element_index := l_element_index + 1;
487     --
488     g_element_table(l_element_index).element_type_id   :=
489                                 csr_eit_rec.org_information1;
490     g_element_table(l_element_index).input_value_id    :=
491                                 csr_eit_rec.org_information2;
492     g_element_table(l_element_index).si_type           :=
493                                 csr_eit_rec.org_information3;
494     g_element_table(l_element_index).element_narrative :=
495                                 csr_eit_rec.org_information4;
496 
497     --
498 
499     --hr_utility.set_location('For NL_PAYSLIP_ELEMENTS'||g_element_table(l_element_index).element_type_id,59);
500     --
501     l_formula_id := NULL;
502     --Bug 3601121
503     --Fetch the iterative formula id defined for an element
504 
505     g_element_table(l_element_index).formula_id := l_formula_id;
506     --hr_utility.set_location('For NL_PAYSLIP_ELEMENTS'||g_element_table(l_element_index).formula_id,59);
507     --
508     OPEN csr_input_value_uom(csr_eit_rec.org_information2
509                             ,p_effective_date);
510         FETCH csr_input_value_uom INTO l_uom;
511     CLOSE csr_input_value_uom;
512     --
513     --hr_utility.set_location('For NL_PAYSLIP_ELEMENTS'||l_uom,59);
514     IF  p_archive = 'Y' THEN
515         --
516         -- Archive EMEA ELEMENT DEFINITION
517         --
518         --hr_utility.set_location('calling api for NL_PAYSLIP_ELEMENTS'||g_element_table(l_element_index).element_type_id,59);
519         --hr_utility.set_location('calling api for NL_PAYSLIP_ELEMENTS'||g_element_table(l_element_index).input_value_id,59);
520         --hr_utility.set_location('calling api for NL_PAYSLIP_ELEMENTS'||g_element_table(l_element_index).element_narrative,59);
521         --hr_utility.set_location('calling api for NL_PAYSLIP_ELEMENTS'||g_element_table(l_element_index).si_type,59);
522         --hr_utility.set_location('calling api for NL_PAYSLIP_ELEMENTS'||l_uom,59);
523         --
524         pay_action_information_api.create_action_information (
525              p_action_information_id        =>  l_action_info_id
526             ,p_action_context_id            =>  p_pactid
527             ,p_action_context_type          =>  'PA'
528             ,p_object_version_number        =>  l_ovn
529             ,p_effective_date               =>  p_effective_date
530             ,p_source_id                    =>  NULL
531             ,p_source_text                  =>  NULL
532             ,p_action_information_category  =>  'EMEA ELEMENT DEFINITION'
533             ,p_action_information1          =>  NULL
534             ,p_action_information2          =>	g_element_table(l_element_index).element_type_id
535             ,p_action_information3          =>	g_element_table(l_element_index).input_value_id
536             ,p_action_information4          =>	g_element_table(l_element_index).element_narrative
537 			,p_action_information5          => 'F'
538 			,p_action_information6          =>  l_uom
539 			,p_action_information7          =>  g_element_table(l_element_index).si_type);
540 
541 
542     --
543     --hr_utility.set_location('Leaving NL_PAYSLIP_ELEMENTS'||l_action_info_id,59);
544     --
545     END IF;
546     --
547 END IF;
548 --
549 --
550 END LOOP;
551 --
552 --
553 END get_eit_definitions;
554 
555 /*-------------------------------------------------------------------------------
556 |Name           : RANGE_CODE                                       		|
557 |Type		: Procedure							|
558 |Description    : This procedure returns a sql string to select a range of 	|
559 |		  assignments eligible for archival		  		|
560 -------------------------------------------------------------------------------*/
561 
562 Procedure RANGE_CODE (pactid    IN    NUMBER
563                      ,sqlstr    OUT   NOCOPY VARCHAR2) is
564 
565 	--
566 	--
567 	CURSOR csr_payrolls (p_payroll_id           NUMBER
568 						,p_consolidation_set_id NUMBER
569 						,p_effective_date       DATE) IS
570 	SELECT ppf.payroll_id
571 	FROM   pay_all_payrolls_f ppf
572 	WHERE  ppf.consolidation_set_id = p_consolidation_set_id
573 	AND    ppf.payroll_id = NVL(p_payroll_id,ppf.payroll_id)
574 	AND    p_effective_date BETWEEN ppf.effective_start_date
575 							AND     ppf.effective_end_date;
576 
577 
578 	-- This Cursor drives the archival of 'EMEA PAYROLL INFO' context.
579 	-- The Tax Office Name and Tax Ref No needs to be archived.
580 	-- It should only be archived if it has not be archived for this archive
581 	-- action.
582 
583 	CURSOR csr_hr_org_info(p_bus_group_id     NUMBER
584 						   ,p_pact_id         NUMBER
585 						  ) IS
586 	SELECT hoi_tax.organization_id          org_id
587 		  ,hou1.name                        tax_office_name
588 		  ,hoi_tax.org_information4         reg_no
589 	FROM   hr_all_organization_units        hou
590 		  ,hr_all_organization_units        hou1
591 		  ,hr_organization_information      hoi
592 		  ,hr_organization_information      hoi_tax
593 	WHERE  hoi.org_information_context      = 'CLASS'
594 	AND    hoi.org_information1             = 'HR_ORG'
595 	AND    hoi.organization_id              =  HOU.organization_id
596 	AND    hou.business_group_id            =  p_bus_group_id
597 	AND    hoi_tax.organization_id          =  hoi.organization_id
598 	AND    hoi_tax.org_information_context  = 'NL_ORG_INFORMATION'
599 	AND    hoi_tax.org_information4         IS NOT NULL
600 	AND    hou1.business_group_id            =  p_bus_group_id
601 	AND    hou1.organization_id              =  hoi_tax.org_information3
602 	AND    hoi_tax.org_information3 IS NOT NULL
603 	AND    NOT EXISTS (SELECT NULL
604 					   FROM   pay_action_information  pai
605 					   WHERE  pai.action_context_id   = p_pact_id
606 					   AND    pai.action_context_type = 'PA'
607 					   AND    pai.action_information_category ='EMEA PAYROLL INFO'
608 					   AND    pai.action_information1 = hoi_tax.organization_id);
609 
610 	--
611 	--
612 	--
613 	  CURSOR csr_payroll_mesg (p_payroll_id       NUMBER,
614 							   p_start_date       DATE,
615 							   p_end_date         DATE) IS
616 	  SELECT pact.payroll_action_id     payroll_action_id
617 			 ,pact.effective_date       effective_date
618 			 ,pact.date_earned          date_earned
619 			 ,pact.pay_advice_message   payroll_message
620 	  FROM   pay_payrolls_f             ppf,
621 			 pay_payroll_actions        pact
622 	  WHERE  pact.payroll_id            = ppf.payroll_id
623 	  AND    pact.effective_date        BETWEEN ppf.effective_start_date
624 										AND     ppf.effective_end_date
625 	  AND    pact.payroll_id            = p_payroll_id
626 	  AND    pact.effective_date        BETWEEN p_start_date
627 										AND     p_end_date
628 	  AND    pact.action_type IN ('R','Q')
629 	  AND    pact.action_status = 'C'
630 	  AND    NOT EXISTS (
631 					 SELECT NULL
632 					 FROM   pay_action_information    pai
633 					 WHERE  pai.action_context_id     = pactid
634 					 AND    pai.action_context_type   = 'PA'
635 					 AND    pai.action_information_category ='EMPLOYEE OTHER INFORMATION');
636 	--
637 	--
638 	l_business_group_id		NUMBER;
639 	l_start_date            	VARCHAR2(240);
640 	l_end_date              	VARCHAR2(240);
641 	l_canonical_start_date		DATE;
642 	l_canonical_end_date    	DATE;
643 	l_effective_date		DATE;
644 	l_payroll_id			NUMBER;
645 	l_consolidation_set		NUMBER;
646 	l_action_info_id		NUMBER;
647 	l_ovn				NUMBER;
648 
649 	--l_payroll_id_char		VARCHAR2(60);
650 	--l_consolidation_set_char	VARCHAR2(60);
651 	--
652 	--
653 
654 Begin
655 
656 	  --
657 	  --hr_utility.trace_on(NULL,'PSA');
658 	  --hr_utility.set_location('Entering Range Code',50);
659 	  --
660 	  pay_nl_payslip_archive.get_all_parameters(pactid
661 				,l_business_group_id
662 				,l_start_date
663 				,l_end_date
664 				,l_effective_date
665 				,l_payroll_id
666 				,l_consolidation_set);
667 
668 	  l_canonical_start_date := TO_DATE(l_start_date,'YYYY/MM/DD');
669 	  l_canonical_end_date   := TO_DATE(l_end_date,'YYYY/MM/DD');
670 
671 
672 	  --
673 	  g_payroll_action_id:=pactid;
674 	  --hr_utility.set_location('g_payroll_action_id    = ' || g_payroll_action_id,55);
675 	  --hr_utility.set_location('l_payroll_id           = ' || l_payroll_id,55);
676 	  --hr_utility.set_location('l_consolidation_set    = ' || l_consolidation_set,55);
677 	  --hr_utility.set_location('l_canonical_start_date = ' || l_canonical_start_date,55);
678 	  --hr_utility.set_location('l_canonical_end_date   = ' || l_canonical_end_date,55);
679 	  --
680 	  --
681 
682 	  -- Setup statutory balances pl/sql table
683 	  IF g_statutory_balance_table.count = 0 THEN
684 		  setup_statutory_balance_table(l_canonical_start_date,l_business_group_id);
685 	  END IF;
686 	  --
687 
688 	  -- Populates the global PL/SQL Table with Balance information and archives
689 	  -- EMEA BALANCE DEFINITION Context
690 	  --
691 	  pay_nl_payslip_archive.get_eit_definitions (
692 		p_pactid            => pactid
693 	  , p_business_group_id => l_business_group_id
694 	  , p_payroll_pact      => NULL
695 	  , p_effective_date    => l_canonical_start_date
696 	  , p_eit_context       => 'NL_PAYSLIP_BALANCES'
697 	  , p_archive           => 'Y');
698 	  --
699 	  --
700 	  --hr_utility.set_location('Inside Range Code',60);
701 
702 	  -- Populates the global PL/SQL Table with Element information and archives
703 	  -- EMEA ELEMENT DEFINITION Context
704 	  --
705 	  pay_nl_payslip_archive.get_eit_definitions (
706 		p_pactid            => pactid
707 	  , p_business_group_id => l_business_group_id
708 	  , p_payroll_pact      => NULL
709 	  , p_effective_date    => l_canonical_start_date
710 	  , p_eit_context       => 'NL_PAYSLIP_ELEMENTS'
711 	  , p_archive           => 'Y');
712 
713 	  --hr_utility.set_location('Inside Range Code',70);
714 	--
715 	FOR rec_payrolls in csr_payrolls(l_payroll_id
716 									,l_consolidation_set
717 									,l_canonical_end_date)  LOOP
718 	--hr_utility.set_location('Inside csr_payrolls loop',75);
719 
720 		pay_emp_action_arch.arch_pay_action_level_data (
721 								 p_payroll_action_id => pactid
722 								,p_payroll_id        => rec_payrolls.payroll_id
723 								,p_effective_date    => l_canonical_end_date);
724 								null;
725 	--
726 	END LOOP;
727 
728 	--hr_utility.set_location('Inside Range Code',80);
729 
730 	FOR hr_org_info_rec in csr_hr_org_info (l_business_group_id
731 										   ,pactid)
732 	LOOP
733 
734 		--hr_utility.set_location('Inside Range Code loop hr_org_info_rec.org_id'||hr_org_info_rec.org_id,90);
735 		--
736 		-- Archiving EMEA PAYROLL INFO context
737 		--
738 		pay_action_information_api.create_action_information (
739 		p_action_information_id        =>  l_action_info_id
740 		, p_action_context_id            =>  pactid
741 		, p_action_context_type          =>  'PA'
742 		, p_object_version_number        =>  l_ovn
743 		, p_effective_date               =>  l_effective_date
744 		, p_source_id                    =>  NULL
745 		, p_source_text                  =>  NULL
746 		, p_action_information_category  =>  'EMEA PAYROLL INFO'
747 		, p_action_information1          =>  pactid
748 		, p_action_information2          =>  hr_org_info_rec.org_id
749 		, p_action_information3          =>  NULL
750 		, p_action_information4          =>  hr_org_info_rec.tax_office_name
751 		, p_action_information5          =>  NULL
752 		, p_action_information6          =>  hr_org_info_rec.reg_no);
753 
754 	 END LOOP;
755 
756 	 --hr_utility.set_location('pactid'||pactid,100);
757 
758 	FOR rec_payroll_msg in csr_payroll_mesg(l_payroll_id
759 		  ,l_canonical_start_date
760 		  ,l_canonical_end_date)
761 	LOOP
762 		--hr_utility.set_location('coming inside loop'||rec_payroll_msg.payroll_action_id,200);
763 		--
764 		IF rec_payroll_msg.payroll_message IS NOT NULL THEN
765 			--
766 			pay_action_information_api.create_action_information (
767 			p_action_information_id        =>  l_action_info_id
768 			, p_action_context_id            =>  pactid
769 			, p_action_context_type          =>  'PA'
770 			, p_object_version_number        =>  l_ovn
771 			, p_effective_date               =>  rec_payroll_msg.effective_date
772 			, p_source_id                    =>  NULL
773 			, p_source_text                  =>  NULL
774 			, p_action_information_category  =>  'EMPLOYEE OTHER INFORMATION'
775 			, p_action_information1          =>  rec_payroll_msg.payroll_action_id
776 			, p_action_information2          =>  'MESG'
777 			, p_action_information3          =>  NULL
778 			, p_action_information4          =>  NULL
779 			, p_action_information5          =>  NULL
780 			, p_action_information6          =>  rec_payroll_msg.payroll_message);
781 			--
782 			null;
783 		END IF;
784 		--
785 	END LOOP;
786 	--hr_utility.set_location('outside loop',300);
787 
788 	sqlstr := 'SELECT DISTINCT person_id
789 	FROM  per_people_f ppf
790 		 ,pay_payroll_actions ppa
791 	WHERE ppa.payroll_action_id = :payroll_action_id
792 	AND   ppa.business_group_id = ppf.business_group_id
793 	ORDER BY ppf.person_id';
794 
795 	--hr_utility.set_location('Leaving Range Code',350);
796 
797 EXCEPTION
798 
799 	WHEN OTHERS THEN
800 	-- Return cursor that selects no rows
801 	sqlstr := 'select 1 from dual where to_char(:payroll_action_id) = dummy';
802 
803 
804 
805 END RANGE_CODE;
806 
807 /*-------------------------------------------------------------------------------
808 |Name           : ASSIGNMENT_ACTION_CODE                                      	|
809 |Type			: Procedure														|
810 |Description    : This procedure further restricts the assignment id's returned |
811 |		  		  by the range code. It locks all the completed Prepayments/	|
812 |		  		  Quickpay Prepayments in the specified period					|
813 -------------------------------------------------------------------------------*/
814 
815 Procedure ASSIGNMENT_ACTION_CODE (p_payroll_action_id  in number
816 				  ,p_start_person_id   in number
817 				  ,p_end_person_id     in number
818 				  ,p_chunk             in number) IS
819 
820 	-- Cursor to retrieve all Prepayment/Quickpay Prepayment assignment actions
821 	-- during the specified period
822 
823 	CURSOR csr_prepaid_assignments(p_pact_id          	NUMBER,
824 									stperson           	NUMBER,
825 									endperson          	NUMBER,
826 									p_payroll_id       	NUMBER,
827 									p_consolidation_id 	NUMBER,
828 									l_canonical_start_date	DATE,
829 									l_canonical_end_date	DATE) IS
830 	-- Andy's changes for bug 5107780
831 	SELECT /*+ ORDERED
832                    INDEX(ppa PAY_PAYROLL_ACTIONS_PK)
833                    INDEX(as1 PER_ASSIGNMENTS_F_N12)
834                    INDEX(ppf PAY_PAYROLLS_F_PK)
835                    INDEX(act PAY_ASSIGNMENT_ACTIONS_N51)
836                    INDEX(appa PAY_PAYROLL_ACTIONS_PK)
837                    INDEX(pai PAY_ACTION_INTERLOCKS_FK2)
838                    INDEX(act1 PAY_ASSIGNMENT_ACTIONS_PK)
839                    INDEX(appa2 PAY_PAYROLL_ACTIONS_PK)
840                    USE_NL(ppa as1 ppf act appa pai act1 appa2) */
841                 act.assignment_id            assignment_id,
842 		act.assignment_action_id     run_action_id,
843 		act1.assignment_action_id    prepaid_action_id
844 	FROM   pay_payroll_actions          ppa,
845 	       per_all_assignments_f        as1,
846 	       pay_assignment_actions       act,
847 	       pay_payroll_actions          appa,
848 	       pay_action_interlocks        pai,
849 	       pay_assignment_actions       act1,
850 	       pay_payroll_actions          appa2,
851 	       pay_payrolls_f               ppf
852 	WHERE  ppa.payroll_action_id        = p_pact_id
853 	AND    appa.consolidation_set_id    = p_consolidation_id
854 	AND    appa.effective_date  BETWEEN l_canonical_start_date 	AND     l_canonical_end_date
855 	AND    as1.person_id        BETWEEN stperson AND     endperson
856 	AND    appa.action_type             IN ('R','Q')
857 	-- Payroll Run or Quickpay Run
858 	AND    act.payroll_action_id        = appa.payroll_action_id
859 	AND    act.source_action_id         IS NULL -- Master Action
860 	AND    as1.assignment_id            = act.assignment_id
861 	AND    ppa.business_group_id        = as1.business_group_id
862 	AND    ppa.effective_date           BETWEEN as1.effective_start_date AND as1.effective_end_date
863 	AND    act.action_status            IN ('C','S')  -- 10228241
864 	AND    act.assignment_action_id     = pai.locked_action_id
865 	AND    appa2.payroll_id 			= ppf.payroll_id
866 	AND    ppf.business_group_id        = as1.business_group_id
867 	AND    ppa.effective_date           BETWEEN ppf.effective_start_date AND ppf.effective_end_date
868 	AND    act1.assignment_action_id    = pai.locking_action_id
869 	AND    act1.action_status           IN ('C','S') -- 10228241
870 	AND  ((ppf.Multi_Assignments_Flag='Y' AND act1.source_action_id IS NOT NULL)
871 	OR (ppf.Multi_Assignments_Flag='N' AND act1.source_action_id IS NULL))
872 	AND    act1.payroll_action_id       = appa2.payroll_action_id
873 	AND    appa2.action_type            IN ('P','U')
874 	AND    appa2.effective_date          BETWEEN l_canonical_start_date
875 	AND     l_canonical_end_date
876 	-- Prepayments or Quickpay Prepayments
877 	AND    (as1.payroll_id = p_payroll_id OR p_payroll_id IS NULL)
878 	AND    NOT EXISTS (SELECT /*+ ORDERED */ NULL
879 	FROM   pay_action_interlocks      pai1,
880 	pay_assignment_actions     act2,
881 	pay_payroll_actions        appa3
882 	WHERE  pai1.locked_action_id    = act.assignment_action_id
883 	AND    act2.assignment_action_id= pai1.locking_action_id
884 	AND    act2.payroll_action_id   = appa3.payroll_action_id
885 	AND    appa3.action_type        = 'X'
886 	AND    appa3.action_status      = 'C'
887 	AND    appa3.report_type        = 'NL_PS_ARCHIVE')
888 	AND  NOT EXISTS (  SELECT /*+ ORDERED */ NULL
889 	FROM   pay_action_interlocks      pai1,
890 	pay_assignment_actions     act2,
891 	pay_payroll_actions        appa3
892 	WHERE  pai1.locked_action_id    = act.assignment_action_id
893 	AND    act2.assignment_action_id= pai1.locking_action_id
894 	AND    act2.payroll_action_id   = appa3.payroll_action_id
895 	AND    appa3.action_type        = 'V'
896 	AND    appa3.action_status      = 'C')
897 	--group by act.assignment_id,act1.assignment_action_id
898 	ORDER BY act.assignment_id,act1.assignment_Action_id;
899 	-- End Andy's changes for bug 5107780
900 
901 	--Bug 3384315
902 	CURSOR 	get_prepayment_child_action(p_source_action_id	NUMBER
903 										,p_assignment_id	NUMBER) IS
904 	select paa.assignment_action_id
905 	from pay_assignment_Actions paa
906 	,pay_assignment_Actions paa1
907 	where paa.source_action_id=p_source_action_id
908 	and paa1.assignment_id <> p_assignment_id
909 	and paa.assignment_id=p_assignment_id
910 	and paa1.assignment_action_id=p_source_action_id;
911 
912 	l_business_group_id	NUMBER;
913 	l_start_date            VARCHAR2(240);
914 	l_end_date              VARCHAR2(240);
915 	l_canonical_start_date	DATE;
916 	l_canonical_end_date    DATE;
917 	l_effective_date	DATE;
918 	l_payroll_id		NUMBER;
919 	l_consolidation_set	NUMBER;
920 	l_prepay_action_id	NUMBER;
921 	l_actid			NUMBER;
922 	l_child_action_id	NUMBER;
923 	csr_rec csr_prepaid_assignments%ROWTYPE;
924 
925 BEGIN
926 	--
927 	--hr_utility.trace_on(NULL,'PSA');
928 	--hr_utility.set_location('Entering Assignment Action Code',400);
929 	--
930 
931 
932 	pay_nl_payslip_archive.get_all_parameters(p_payroll_action_id
933 	,l_business_group_id,l_start_date,l_end_date
934 	,l_effective_date,l_payroll_id,l_consolidation_set);
935 
936 	--
937 	l_canonical_start_date := TO_DATE(l_start_date,'YYYY/MM/DD');
938 	l_canonical_end_date   := TO_DATE(l_end_date,'YYYY/MM/DD');
939 
940 
941 	l_prepay_action_id := 0;
942 	--
943 	--hr_utility.set_location('Archive p_payroll_action_id'||p_payroll_action_id,425);
944 	--hr_utility.set_location('Archive p_start_person_id'||p_start_person_id,425);
945 	--hr_utility.set_location('Archive p_end_person_id'||p_end_person_id,425);
946 	--hr_utility.set_location('Archive l_payroll_id'||l_payroll_id,425);
947 	--hr_utility.set_location('Archive l_consolidation_set'||l_consolidation_set,425);
948 	--hr_utility.set_location('Archive l_canonical_start_date'||l_canonical_start_date,425);
949 	--hr_utility.set_location('Archive l_canonical_end_date'||l_canonical_end_date,425);
950 
951 	--
952 	OPEN csr_prepaid_assignments(p_payroll_action_id
953 	,p_start_person_id,p_end_person_id,l_payroll_id,l_consolidation_set
954 	,l_canonical_start_date,l_canonical_end_date) ;
955 	LOOP
956 		--
957 		FETCH csr_prepaid_assignments into csr_rec;
958 		EXIT WHEN csr_prepaid_assignments%NOTFOUND;
959 
960 		IF l_prepay_action_id <> csr_rec.prepaid_action_id THEN
961 			--
962 
963 			SELECT pay_assignment_actions_s.NEXTVAL
964 			INTO   l_actid
965 			FROM   dual;
966 			--
967 			-- Create the archive assignment action
968 			--
969 			--Bug 3384315
970 			l_child_action_id:=NULL;
971 			OPEN get_prepayment_child_action(csr_rec.prepaid_action_id,csr_rec.assignment_id);
972 			FETCH get_prepayment_child_action INTO l_child_action_id;
973 			CLOSE get_prepayment_child_action;
974 
975 			--hr_utility.set_location('Archive l_prepay_action_id'||l_prepay_action_id,425);
976 			--hr_utility.set_location('Archive l_child_action_id'||l_child_action_id,425);
977 
978 
979 			l_prepay_action_id := nvl(l_child_action_id,csr_rec.prepaid_action_id);
980 
981 			hr_utility.set_location('Archive l_prepay_action_id'||l_prepay_action_id,425);
982 			hr_utility.set_location('Archive csr_rec.prepaid_action_id'||csr_rec.prepaid_action_id,425);
983 
984 			hr_utility.set_location('Archive Assignment Action Id'||l_actid,450);
985 
986 			hr_nonrun_asact.insact(l_actid,csr_rec.assignment_id,
987 			p_payroll_action_id,p_chunk,NULL);
988 			--
989 			hr_utility.set_location('Archive Assignment Action Id'||l_actid,450);
990 			hr_utility.set_location('Archive Assignment Id'||csr_rec.assignment_id,450);
991 			hr_utility.set_location('Archive Payroll Action Id'||p_payroll_action_id,450);
992 
993 			-- Create archive to prepayment assignment action interlock
994 			--
995 			hr_nonrun_asact.insint(l_actid,l_prepay_action_id);
996 			--
997 		END IF;
998 		hr_utility.set_location('Archive Assignment Action Id'||l_actid,475);
999 		hr_utility.set_location('Archive Assignment run_action_id Id'||csr_rec.run_action_id,475);
1000 		-- Create archive to payroll master action interlock
1001 		hr_nonrun_asact.insint(l_actid,csr_rec.run_action_id);
1002 		--  l_prepay_action_id := csr_rec.prepaid_action_id;
1003 		--
1004 	END LOOP;
1005 
1006 	--
1007 	--hr_utility.set_location('Leaving Assignment Action Code',500);
1008 	--
1009 END ASSIGNMENT_ACTION_CODE;
1010 
1011 
1012 
1013 /*-------------------------------------------------------------------------------
1014 |Name           : SETUP_ELEMENT_TABLE                                		|
1015 |Type		: Procedure							|
1016 |Description    : Procedure sets the global table g_stat_element_table.		|
1017 -------------------------------------------------------------------------------*/
1018 
1019 PROCEDURE setup_element_table IS
1020 
1021 BEGIN
1022     --
1023     -- Setup Statutory Element Table and their display squence in
1024     -- Payments and Deduction section of the reports.
1025     --
1026     -- Section 1
1027     g_stat_element_table(1).classification_name := 'Earnings';
1028     g_stat_element_table(1).element_name        := NULL;
1029     g_stat_element_table(1).element_type        := 'E';
1030     g_stat_element_table(1).main_index          := 10000;
1031     g_stat_element_table(1).archive_flag        := 'Y';
1032     g_stat_element_table(1).standard            := 'Subject to Standard Tax : Earnings';
1033     g_stat_element_table(1).special		:= 'Subject to Special Tax : Earnings';
1034     g_stat_element_table(1).payable_flag        := 'Y';
1035     -- Section 3
1036     g_stat_element_table(2).classification_name := 'Imputed Earnings';
1037     g_stat_element_table(2).element_name        := NULL;
1038     g_stat_element_table(2).element_type        := NULL;
1039     g_stat_element_table(2).main_index          := 12000;
1040     g_stat_element_table(2).archive_flag        := 'Y';
1041     g_stat_element_table(2).standard            := 'SI Income Subject to Standard Tax : Imputed Earnings';
1042     g_stat_element_table(2).special            := 'SI Income Subject to Special Tax : Imputed Earnings';
1043     g_stat_element_table(2).standard2           := 'Subject to Standard Tax : Imputed Earnings';
1044     g_stat_element_table(2).special2        := 'Subject to Special Tax : Imputed Earnings';
1045     g_stat_element_table(2).payable_flag        := 'N';
1046 
1047     -- Section 4
1048     g_stat_element_table(3).classification_name := 'Pre-SI and Pre-Tax Deductions';
1049     g_stat_element_table(3).element_name        := NULL;
1050     g_stat_element_table(3).element_type        := 'D';
1051     g_stat_element_table(3).main_index          := 13000;
1052     g_stat_element_table(3).archive_flag        := 'Y';
1053     g_stat_element_table(3).standard            := 'SI Income Standard Deduction : Pre-SI and Pre-Tax Deductions';
1054     g_stat_element_table(3).special    := 'SI Income Special Deduction : Pre-SI and Pre-Tax Deductions';
1055     g_stat_element_table(3).payable_flag        := 'Y';
1056 
1057     -- Section 11
1058     g_stat_element_table(4).classification_name := 'Pre-Tax Deductions';
1059     g_stat_element_table(4).element_name        := NULL;
1060     g_stat_element_table(4).element_type        := 'D';
1061     g_stat_element_table(4).main_index          := 20000;
1062     g_stat_element_table(4).archive_flag        := 'Y';
1063     g_stat_element_table(4).standard            := 'Standard Tax Deduction : Pre-Tax Deductions';
1064     g_stat_element_table(4).special    := 'Special Tax Deduction : Pre-Tax Deductions';
1065     g_stat_element_table(4).payable_flag        := 'Y';
1066 
1067     -- Section 11
1068     g_stat_element_table(5).classification_name := 'Reductions';
1069     g_stat_element_table(5).element_name        := NULL;
1070     g_stat_element_table(5).element_type        := NULL;
1071     g_stat_element_table(5).main_index          := 14500;
1072     g_stat_element_table(5).archive_flag        := 'Y';
1073     g_stat_element_table(5).standard            := 'Standard Tax Reduction : Reductions';
1074     g_stat_element_table(5).special    := 'Special Tax Reduction : Reductions';
1075     g_stat_element_table(5).standard2           := 'SI Income Standard Tax Reduction : Reductions';
1076     g_stat_element_table(5).special2    := 'SI Income Special Tax Reduction : Reductions';
1077     g_stat_element_table(5).payable_flag        := 'N';
1078 
1079     --Section 12a
1080     g_stat_element_table(6).classification_name := 'Earnings';
1081     g_stat_element_table(6).element_name        := 'Employer ZVW Contribution Standard Tax';
1082     g_stat_element_table(6).element_type        := 'E';
1083     g_stat_element_table(6).main_index          := 18700;
1084     g_stat_element_table(6).archive_flag        := 'N';
1085     g_stat_element_table(6).standard            := 'Subject to Standard Tax : Earnings';
1086     g_stat_element_table(6).special    := '';
1087     g_stat_element_table(6).payable_flag        := 'Y';
1088 
1089     --Section 12b
1090     g_stat_element_table(7).classification_name := 'Earnings';
1091     g_stat_element_table(7).element_name        := 'Employer ZVW Contribution Special Tax';
1092     g_stat_element_table(7).element_type        := 'E';
1093     g_stat_element_table(7).main_index          := 18700;
1094     g_stat_element_table(7).archive_flag        := 'N';
1095     g_stat_element_table(7).standard            := '';
1096     g_stat_element_table(7).special    := 'Subject to Special Tax : Earnings';
1097     g_stat_element_table(7).payable_flag        := 'Y';
1098 
1099      -- Section 14a
1100     g_stat_element_table(8).classification_name := 'Employee Tax';
1101     g_stat_element_table(8).element_name        := 'Standard Tax Deduction';
1102     g_stat_element_table(8).element_type        := 'D';
1103     g_stat_element_table(8).main_index          := 23000;
1104     g_stat_element_table(8).archive_flag        := 'N';
1105     g_stat_element_table(8).standard            := '';
1106     g_stat_element_table(8).special    := '';
1107     g_stat_element_table(8).payable_flag        := 'Y';
1108     -- Section 14b
1109     g_stat_element_table(9).classification_name := 'Employee Tax';
1110     g_stat_element_table(9).element_name        := 'Special Tax Deduction';
1111     g_stat_element_table(9).element_type        := 'D';
1112     g_stat_element_table(9).main_index          := 24000;
1113     g_stat_element_table(9).archive_flag        := 'N';
1114     g_stat_element_table(9).standard            := '';
1115     g_stat_element_table(9).special    := '';
1116     g_stat_element_table(9).payable_flag        := 'Y';
1117     -- Section 14c
1118     g_stat_element_table(10).classification_name := 'Employee Tax';
1119     g_stat_element_table(10).element_name        := 'Beneficial Rule Special Tax Adjustment';
1120     g_stat_element_table(10).element_type        := 'D';
1121     g_stat_element_table(10).main_index          := 25000;
1122     g_stat_element_table(10).archive_flag        := 'N';
1123     g_stat_element_table(10).standard            := '';
1124     g_stat_element_table(10).special    := '';
1125     g_stat_element_table(10).payable_flag        := 'Y';
1126     --
1127     -- Bug 6447814 starts
1128     -- To include Employee Tax elements under Payments and Deductions Section of the Payslip.
1129     g_stat_element_table(11).classification_name := 'Employee Tax';
1130     g_stat_element_table(11).element_name        := NULL;
1131     g_stat_element_table(11).element_type        := 'D';
1132     g_stat_element_table(11).main_index          := 25100;
1133     g_stat_element_table(11).archive_flag        := 'N';
1134     g_stat_element_table(11).standard            := '';
1135     g_stat_element_table(11).special    := '';
1136     g_stat_element_table(11).payable_flag        := 'Y';
1137     -- Bug 6447814 Ends
1138     --
1139     -- Section 15
1140     g_stat_element_table(12).classification_name := 'Involuntary Deductions';
1141     g_stat_element_table(12).element_name        := NULL;
1142     g_stat_element_table(12).element_type        := 'D';
1143     g_stat_element_table(12).main_index          := 26000;
1144     g_stat_element_table(12).archive_flag        := 'Y';
1145     g_stat_element_table(12).standard            := '';
1146     g_stat_element_table(12).special    := '';
1147     g_stat_element_table(12).payable_flag        := 'Y';
1148     -- Section 16
1149     g_stat_element_table(13).classification_name := 'Voluntary Deductions';
1150     g_stat_element_table(13).element_name        := NULL;
1151     g_stat_element_table(13).element_type        := 'D';
1152     g_stat_element_table(13).main_index          := 27000;
1153     g_stat_element_table(13).archive_flag        := 'Y';
1154     g_stat_element_table(13).standard            := '';
1155     g_stat_element_table(13).special    := '';
1156     g_stat_element_table(13).payable_flag        := 'Y';
1157     -- Section 17
1158     g_stat_element_table(14).classification_name := 'Net Earnings';
1159     g_stat_element_table(14).element_name        := NULL;
1160     g_stat_element_table(14).element_type        := 'E';
1161     g_stat_element_table(14).main_index          := 28000;
1162     g_stat_element_table(14).archive_flag        := 'Y';
1163     g_stat_element_table(14).standard            := '';
1164     g_stat_element_table(14).special    := '';
1165     g_stat_element_table(14).payable_flag        := 'Y';
1166 
1167     -- Section 1
1168     g_stat_element_table(15).classification_name := 'Retro Earnings';
1169     g_stat_element_table(15).element_name        := NULL;
1170     g_stat_element_table(15).element_type        := 'E';
1171     g_stat_element_table(15).main_index          := 10500;
1172     g_stat_element_table(15).archive_flag        := 'Y';
1173     g_stat_element_table(15).standard            := 'Subject to Standard Tax : Retro Earnings';
1174     g_stat_element_table(15).special     := 'Subject to Special Tax : Retro Earnings';
1175     g_stat_element_table(15).payable_flag        := 'Y';
1176     -- Section 3
1177     g_stat_element_table(16).classification_name := 'Retro Imputed Earnings';
1178     g_stat_element_table(16).element_name        := NULL;
1179     g_stat_element_table(16).element_type        := NULL;
1180     g_stat_element_table(16).main_index          := 12500;
1181     g_stat_element_table(16).archive_flag        := 'Y';
1182     g_stat_element_table(16).standard            := 'SI Income Subject to Standard Tax : Retro Imputed Earnings';
1183     g_stat_element_table(16).special    := 'SI Income Subject to Special Tax : Retro Imputed Earnings';
1184     g_stat_element_table(16).standard2            := 'Subject to Standard Tax : Retro Imputed Earnings';
1185     g_stat_element_table(16).special2    := 'Subject to Special Tax : Retro Imputed Earnings';
1186     g_stat_element_table(16).payable_flag        := 'N';
1187 
1188     -- Section 4
1189     g_stat_element_table(17).classification_name := 'Retro Pre SI and Pre Tax Deductions';
1190     g_stat_element_table(17).element_name        := NULL;
1191     g_stat_element_table(17).element_type        := 'D';
1192     g_stat_element_table(17).main_index          := 13500;
1193     g_stat_element_table(17).archive_flag        := 'Y';
1194     g_stat_element_table(17).standard            := 'SI Income Standard Tax : Retro Pre SI and Pre Tax Deductions';
1195     g_stat_element_table(17).special    := 'SI Income Special Tax : Retro Pre SI and Pre Tax Deductions';
1196     g_stat_element_table(17).payable_flag        := 'Y';
1197 
1198     -- Section 11
1199     g_stat_element_table(18).classification_name := 'Retro Pre Tax Deductions';
1200     g_stat_element_table(18).element_name        := NULL;
1201     g_stat_element_table(18).element_type        := 'D';
1202     g_stat_element_table(18).main_index          := 20500;
1203     g_stat_element_table(18).archive_flag        := 'Y';
1204     g_stat_element_table(18).standard            := 'Standard Tax Deduction : Retro Pre Tax Deductions';
1205     g_stat_element_table(18).special    := 'Special Tax Deduction : Retro Pre Tax Deductions';
1206     g_stat_element_table(18).payable_flag        := 'Y';
1207 
1208     g_stat_element_table(19).classification_name := 'Retro Reductions';
1209     g_stat_element_table(19).element_name        := NULL;
1210     g_stat_element_table(19).element_type        := NULL;
1211     g_stat_element_table(19).main_index          := 14600;
1212     g_stat_element_table(19).archive_flag        := 'Y';
1213     g_stat_element_table(19).standard            := 'Standard Tax Reduction : Retro Reductions';
1214     g_stat_element_table(19).special     := 'Special Tax Reduction : Retro Reductions';
1215     g_stat_element_table(19).standard2           := 'SI Income Standard Tax Reduction : Retro Reductions';
1216     g_stat_element_table(19).special2     := 'SI Income Special Tax Reduction : Retro Reductions';
1217     g_stat_element_table(19).payable_flag        := 'N';
1218 
1219     -- Section 12a
1220     g_stat_element_table(20).classification_name := 'Retro Earnings';
1221     g_stat_element_table(20).element_name        := 'Retro Employer ZVW Contribution Standard Tax';
1222     g_stat_element_table(20).element_type        := 'E';
1223     g_stat_element_table(20).main_index          := 18750;
1224     g_stat_element_table(20).archive_flag        := 'N';
1225     g_stat_element_table(20).standard            := 'Subject to Standard Tax : Retro Earnings';
1226     g_stat_element_table(20).special     := '';
1227     g_stat_element_table(20).payable_flag        := 'Y';
1228 
1229         -- Section 12a
1230     g_stat_element_table(21).classification_name := 'Retro Earnings';
1231     g_stat_element_table(21).element_name        := 'Retro Employer ZVW Contribution Special Tax';
1232     g_stat_element_table(21).element_type        := 'E';
1233     g_stat_element_table(21).main_index          := 18750;
1234     g_stat_element_table(21).archive_flag        := 'N';
1235     g_stat_element_table(21).standard            := '';
1236     g_stat_element_table(21).special     := 'Subject to Special Tax : Retro Earnings';
1237     g_stat_element_table(21).payable_flag        := 'Y';
1238 
1239     -- Section 14a
1240     g_stat_element_table(22).classification_name := 'Retro Employee Deductions';
1241     g_stat_element_table(22).element_name        := 'Retro Standard Tax Deduction';
1242     g_stat_element_table(22).element_type        := 'D';
1243     g_stat_element_table(22).main_index          := 23500;
1244     g_stat_element_table(22).archive_flag        := 'N';
1245     g_stat_element_table(22).standard            := '';
1246     g_stat_element_table(22).special       := '';
1247     g_stat_element_table(22).payable_flag        := 'Y';
1248     -- Section 14a
1249     g_stat_element_table(23).classification_name := 'Retro Employee Deductions';
1250     g_stat_element_table(23).element_name        := 'Retro Standard Tax Deduction Current Quarter';
1251     g_stat_element_table(23).element_type        := 'D';
1252     g_stat_element_table(23).main_index          := 23500;
1253     g_stat_element_table(23).archive_flag        := 'N';
1254     g_stat_element_table(23).standard            := '';
1255     g_stat_element_table(23).special     := '';
1256     g_stat_element_table(23).payable_flag        := 'Y';
1257 
1258     -- Section 14b
1259     g_stat_element_table(24).classification_name := 'Retro Employee Deductions';
1260     g_stat_element_table(24).element_name        := 'Retro Special Tax Deduction';
1261     g_stat_element_table(24).element_type        := 'D';
1262     g_stat_element_table(24).main_index          := 24500;
1263     g_stat_element_table(24).archive_flag        := 'N';
1264     g_stat_element_table(24).standard            := '';
1265     g_stat_element_table(24).special     := '';
1266     g_stat_element_table(24).payable_flag        := 'Y';
1267     -- Section 14c
1268     g_stat_element_table(25).classification_name := 'Retro Employee Deductions';
1269     g_stat_element_table(25).element_name        := 'Retro Beneficial Rule Special Tax Adjustment';
1270     g_stat_element_table(25).element_type        := 'D';
1271     g_stat_element_table(25).main_index          := 25500;
1272     g_stat_element_table(25).archive_flag        := 'N';
1273     g_stat_element_table(25).standard            := '';
1274     g_stat_element_table(25).special     := '';
1275     g_stat_element_table(25).payable_flag        := 'Y';
1276 
1277 -- Bug 5957039
1278 -- to place after ZVW Employer Contribution
1279     g_stat_element_table(26).classification_name := 'Pre-Tax ZVW Refund';
1280     g_stat_element_table(26).element_name        := NULL;
1281     g_stat_element_table(26).element_type        := 'E';
1282     g_stat_element_table(26).main_index          := 18720;      --10980;
1283     g_stat_element_table(26).archive_flag        := 'Y';
1284     g_stat_element_table(26).standard            := NULL; --'Subject to Standard Tax : Earnings';
1285     g_stat_element_table(26).special     := NULL; --'Subject to Special Tax : Earnings';
1286     g_stat_element_table(26).payable_flag        := 'Y';
1287 
1288     g_stat_element_table(27).classification_name := 'Retro Pre-Tax ZVW Refund';
1289     g_stat_element_table(27).element_name        := NULL;
1290     g_stat_element_table(27).element_type        := 'E';
1291     g_stat_element_table(27).main_index          := 18770;      --10990;
1292     g_stat_element_table(27).archive_flag        := 'Y';
1293     g_stat_element_table(27).standard            := NULL; --'Subject to Standard Tax : Retro Earnings';
1294     g_stat_element_table(27).special     := NULL; --'Subject to Special Tax : Retro Earnings';
1295     g_stat_element_table(27).payable_flag        := 'Y';
1296 
1297 --5957039
1298 --to place after Net Earnings
1299     g_stat_element_table(28).classification_name := 'Pre-Tax ZVW Refund';
1300     g_stat_element_table(28).element_name        := NULL;
1301     g_stat_element_table(28).element_type        := 'E';
1302     g_stat_element_table(28).main_index          := 28050;      --10980;
1303     g_stat_element_table(28).archive_flag        := 'Y';
1304     g_stat_element_table(28).standard            := NULL; --'Subject to Standard Tax : Earnings';
1305     g_stat_element_table(28).special     := NULL; --'Subject to Special Tax : Earnings';
1306     g_stat_element_table(28).payable_flag        := 'Y';
1307 
1308     g_stat_element_table(29).classification_name := 'Retro Pre-Tax ZVW Refund';
1309     g_stat_element_table(29).element_name        := NULL;
1310     g_stat_element_table(29).element_type        := 'E';
1311     g_stat_element_table(29).main_index          := 28100;      --10990;
1312     g_stat_element_table(29).archive_flag        := 'Y';
1313     g_stat_element_table(29).standard            := NULL; --'Subject to Standard Tax : Retro Earnings';
1314     g_stat_element_table(29).special     := NULL; --'Subject to Special Tax : Retro Earnings';
1315     g_stat_element_table(29).payable_flag        := 'Y';
1316 
1317 -- Bug 5957039
1318 
1319 END setup_element_table;
1320 
1321 /*-------------------------------------------------------------------------------
1322 |Name           : ARCHIVE_INIT                                            	|
1323 |Type		: Procedure							|
1324 |Description    : Procedure sets the global tables g_statutory_balance_table,   |
1325 |		  g_stat_element_table,g_user_balance_table,g_element_table.	|
1326 -------------------------------------------------------------------------------*/
1327 
1328 Procedure ARCHIVE_INIT(p_payroll_action_id IN NUMBER) IS
1329 
1330 l_business_group_id	NUMBER;
1331 l_start_date            VARCHAR2(240);
1332 l_end_date              VARCHAR2(240);
1333 l_canonical_start_date	DATE;
1334 l_canonical_end_date    DATE;
1335 l_effective_date	DATE;
1336 l_payroll_id		NUMBER;
1337 l_consolidation_set	NUMBER;
1338 
1339 BEGIN
1340 	--
1341 	--hr_utility.set_location('Entering Archive Init',600);
1342 	--
1343 	pay_nl_payslip_archive.get_all_parameters(p_payroll_action_id
1344 					,l_business_group_id
1345 					,l_start_date,l_end_date,l_effective_date
1346 					,l_payroll_id,l_consolidation_set);
1347 	--
1348 	l_canonical_start_date := TO_DATE(l_start_date,'YYYY/MM/DD');
1349 	l_canonical_end_date   := TO_DATE(l_end_date,'YYYY/MM/DD');
1350 	--
1351 
1352 	--hr_utility.set_location('l_payroll_id           = ' || l_payroll_id,655);
1353 	--hr_utility.set_location('l_consolidation_set    = ' || l_consolidation_set,655);
1354 	--hr_utility.set_location('l_canonical_start_date = ' || l_canonical_start_date,655);
1355 	--hr_utility.set_location('l_canonical_end_date   = ' || l_canonical_end_date,655);
1356 	--
1357 	--
1358 
1359 	-- Setup statutory balances pl/sql table
1360 	IF g_statutory_balance_table.count = 0 THEN
1361 		setup_statutory_balance_table(l_canonical_start_date, l_business_group_id);
1362 	END IF;
1363 	--
1364 
1365 	-- Populates the global PL/SQL Table with Balance information and archives
1366 	-- EMEA BALANCE DEFINITION Context
1367 	--
1368 	IF  g_user_balance_table.count = 0   THEN
1369 		pay_nl_payslip_archive.get_eit_definitions (
1370 		p_pactid            => p_payroll_action_id
1371 		, p_business_group_id => l_business_group_id
1372 		, p_payroll_pact      => NULL
1373 		, p_effective_date    => l_canonical_start_date
1374 		, p_eit_context       => 'NL_PAYSLIP_BALANCES'
1375 		, p_archive           => 'N');
1376 		--
1377 		--
1378 		--hr_utility.set_location('Inside Archive Init Code',660);
1379 	END IF;
1380 	-- Populates the global PL/SQL Table with Element information and archives
1381 	-- EMEA ELEMENT DEFINITION Context
1382 	--
1383 	IF  g_element_table.count = 0 THEN
1384 		pay_nl_payslip_archive.get_eit_definitions (
1385 		p_pactid            => p_payroll_action_id
1386 		, p_business_group_id => l_business_group_id
1387 		, p_payroll_pact      => NULL
1388 		, p_effective_date    => l_canonical_start_date
1389 		, p_eit_context       => 'NL_PAYSLIP_ELEMENTS'
1390 		, p_archive           => 'N');
1391 		--
1392 	END IF;
1393 
1394 	--hr_utility.set_location('Inside Archive Init Code',670);
1395 
1396 
1397 	--hr_utility.set_location('Inside Archive Init Code',675);
1398 
1399 	-- Setup statutory element  pl/sql table
1400 	setup_element_table();
1401 	--
1402 	--hr_utility.set_location('Inside Archive Init Code',680);
1403 
1404 	--hr_utility.set_location('Leaving Archive Init',700);
1405 	--
1406 END ARCHIVE_INIT;
1407 
1408 /*-------------------------------------------------------------------------------
1409 |Name           : ARCHIVE_EMPLOYEE_DETAILS                            		|
1410 |Type		: Procedure							|
1411 |Description    : Procedure archives EMLOYEE DETAILS,ADRESS DETAILS AND		|
1412 |		  EMPLOYEE NET PAY DISTRIBUTION contexts			|
1413 -------------------------------------------------------------------------------*/
1414 
1415 Procedure ARCHIVE_EMPLOYEE_DETAILS (p_payroll_action_id       	IN NUMBER
1416                                    ,p_assactid                	IN NUMBER
1417                                    ,p_assignment_id            	IN NUMBER
1418                                    ,p_curr_pymt_ass_act_id 	IN NUMBER
1419  		                   ,p_date_earned              	IN DATE
1420                                    ,p_archive_effective_date  	IN DATE
1421                                    ,p_curr_pymt_eff_date    	IN DATE
1422                                    ,p_time_period_id           	IN NUMBER
1423   	                           ,p_record_count             	IN NUMBER) IS
1424 
1425 cursor	csr_add_info_13_14 is
1426 select	pai.action_information_id, pai.action_information1, pa.add_information13,
1427 	pa.add_information14, pai.object_version_number
1428 from	pay_action_information pai,
1429 	per_addresses pa
1430 where	pai.action_context_id 	= p_assactid
1431 and	pai.action_context_type 	= 'AAP'
1432 and	pai.action_information_category = 'ADDRESS DETAILS'
1433 and	pa.person_id 		= pai.action_information1
1434 and	pa.primary_flag 		= 'Y'
1435 and	p_archive_effective_date between pa.date_from
1436                                    and nvl(pa.date_to, p_archive_effective_date);
1437 
1438 BEGIN
1439 
1440 	--
1441 	pay_emp_action_arch.get_personal_information (
1442 		 p_payroll_action_id    => p_payroll_action_id
1443 		,p_assactid             => p_assactid
1444 		,p_assignment_id        => p_assignment_id
1445 		,p_curr_pymt_ass_act_id => p_curr_pymt_ass_act_id
1446 		,p_curr_eff_date        => p_archive_effective_date
1447 		,p_date_earned          => p_date_earned
1448 		,p_curr_pymt_eff_date   => p_curr_pymt_eff_date
1449 		,p_tax_unit_id          => NULL
1450 		,p_time_period_id       => p_time_period_id
1451 		,p_ppp_source_action_id => NULL);
1452 
1453 	FOR cntr IN csr_add_info_13_14
1454 	LOOP
1455 		pay_action_information_api.update_action_information(p_action_information_id => cntr.action_information_id
1456 								     ,p_object_version_number => cntr.object_version_number
1457 								     ,p_action_information26 => cntr.add_information13
1458 								     ,p_action_information27 => cntr.add_information14
1459 								     );
1460 
1461 	END LOOP;
1462 	--
1463 END ARCHIVE_EMPLOYEE_DETAILS;
1464 
1465 /*-------------------------------------------------------------------------------
1466 |Name           : ARCHIVE_NL_EMPLOYEE_DETAILS                            	|
1467 |Type		: Procedure							|
1468 |Description    : Procedure archives NL EMLOYEE DETAILS,NL OTHER EMPLOYEE 	|
1469 |		  DETAILS,ADDL EMPLOYEE DETAILS context				|
1470 -------------------------------------------------------------------------------*/
1471 
1472 Procedure ARCHIVE_NL_EMPLOYEE_DETAILS (p_assignment_id     IN NUMBER
1473                             ,p_assg_action_id              IN NUMBER
1474                             ,p_master_asg_act_id	   IN NUMBER
1475                             ,p_payroll_id                  IN NUMBER
1476                             ,p_date_earned                 IN DATE) IS
1477 
1478 CURSOR csr_nl_employee_details IS
1479 SELECT trim(scl.segment11)                tax_code
1480       ,FND_NUMBER.Canonical_To_Number(scl.segment12)    prev_year_sal
1481       ,scl.segment4					tax_reduction
1482       ,scl.segment7					labour_tax_reduction
1483       ,scl.segment9					add_senior_tax_reduction
1484       ,FND_NUMBER.Canonical_To_Number(scl.segment28)    individual_working_hours
1485 FROM   per_assignments_f            paf
1486       ,hr_soft_coding_keyflex       scl
1487 WHERE  paf.assignment_id            = p_assignment_id
1488 AND    p_date_earned                BETWEEN paf.effective_start_date
1489                                     AND     paf.effective_end_date
1490 AND    paf.soft_coding_keyflex_id   = scl.soft_coding_keyflex_id;
1491 --
1492 CURSOR csr_nl_emp_organization IS
1493 SELECT organization_id
1494 FROM	per_all_assignments_f
1495 WHERE assignment_id=p_assignment_id
1496 AND p_date_earned 	BETWEEN effective_start_date
1497                         AND     effective_end_date;
1498 --
1499 --
1500 --
1501 CURSOR csr_payroll_period is
1502 SELECT paf.period_type          period_type
1503       ,paf.business_group_id    bug_group_id
1504 FROM   pay_all_payrolls_f paf
1505 WHERE  payroll_id               = p_payroll_id
1506 AND    p_date_earned            BETWEEN paf.effective_start_date
1507                                 AND     paf.effective_end_date;
1508 --
1509 --
1510 CURSOR csr_get_context_id(p_context_name  		VARCHAR2
1511 			 ,p_assignment_action_id	NUMBER) IS
1512 SELECT ff.context_id     context_id
1513       ,pact.context_value   context_value
1514       , decode(context_value,'ZVW',0,'ZW',1,
1515                'WEWE',2,'WEWA',3,'WAOD',4,'WAOB',5,6) seq
1516 FROM   ff_contexts         ff
1517       ,pay_action_contexts pact
1518 WHERE  ff.context_name   = p_context_name
1519 AND    pact.context_id   = ff.context_id
1520 AND    pact.assignment_action_id=p_assignment_action_id
1521 ORDER  BY decode(context_value,'ZVW',0,'ZW',1,
1522           'WEWE',2,'WEWA',3,'WAOD',4,'WAOB',5,6);
1523 
1524 
1525 --
1526 -- Cursor to fetch the org_structure_version_id
1527 --
1528 CURSOR csr_get_org_struct_ver_id(p_org_struct_id NUMBER
1529                                 ,p_date_earned   DATE) IS
1530 SELECT org_structure_version_id
1531 FROM   per_org_structure_versions posv
1532 WHERE  organization_structure_id  =p_org_struct_id
1533 AND    p_date_earned           BETWEEN posv.date_from
1534                                AND NVL(posv.date_to,hr_general.end_of_time);
1535 
1536 
1537 --
1538 --
1539 --
1540 CURSOR csr_get_hr_org_address(p_organization_id NUMBER) IS
1541 SELECT hr_org_tl.NAME              name
1542       ,hr_loc.style		style
1543       ,hr_loc.region_1          street_name
1544       ,hr_loc.address_line_1    add_line1
1545       ,hr_loc.address_line_2    add_line2
1546       ,hr_loc.address_line_3    add_line3
1547 --      ,hr_loc.postal_code       postal_code
1548       ,pay_nl_general.get_postal_code_new(hr_loc.postal_code)       postal_code
1549       ,hr_loc.town_or_city      city
1550       ,hr_loc.region_2          province
1551       ,hr_loc.country           country
1552       ,hr_loc.region_3          po_box_no
1553 FROM   HR_ALL_ORGANIZATION_UNITS   hr_org
1554       ,HR_ALL_ORGANIZATION_UNITS_TL hr_org_tl
1555       ,hr_locations_all             hr_loc
1556 WHERE  hr_org.organization_id   = p_organization_id
1557 AND    hr_org.organization_id   = hr_org_tl.organization_id
1558 AND    hr_org.location_id    = hr_loc.location_id (+)
1559 AND    hr_org_tl.LANGUAGE = USERENV('LANG');
1560 
1561 --
1562 
1563 /*CURSOR csr_get_territory_name(p_territory_code VARCHAR2) Is
1564 SELECT TERRITORY_SHORT_NAME
1565 FROM FND_TERRITORIES_VL
1566 WHERE TERRITORY_CODE = p_territory_code;*/
1567 --
1568 --
1569 CURSOR csr_get_regular_working_hrs(p_assignment_id  NUMBER) IS
1570 SELECT paf.normal_hours         normal_hours
1571 FROM   per_all_assignments_f    paf
1572 WHERE  paf.assignment_id        = p_assignment_id
1573 AND    p_date_earned            BETWEEN paf.effective_start_date
1574                                 AND     paf.effective_end_date;
1575 
1576 
1577 CURSOR csr_element_si_type_value(p_assignment_action_id NUMBER
1578                                 ,p_effective_date       DATE) IS
1579 SELECT prv.result_value         value
1580       ,prv1.result_value        si_type
1581 FROM   pay_run_result_values    prv
1582       ,pay_run_results          prr
1583       ,pay_input_values_f       piv
1584       ,pay_input_values_f       piv1
1585       ,pay_run_result_values    prv1
1586       ,pay_element_types_f      pet
1587 WHERE  prr.status               IN ('P','PA')
1588 AND    prv.run_result_id        = prr.run_result_id
1589 AND    prr.assignment_action_id = p_assignment_action_id
1590 AND    prr.element_type_id      = pet.element_type_id
1591 AND    pet.legislation_code     = 'NL'
1592 AND    prv.input_value_id       = piv.input_value_id
1593 AND    prv1.input_value_id      = piv1.input_value_id
1594 AND    piv.name                 = 'SI Type Name'
1595 AND    p_effective_date        BETWEEN piv1.effective_start_date
1596                                 AND     piv1.effective_end_date
1597 AND    p_effective_date        BETWEEN piv.effective_start_date
1598                                 AND     piv.effective_end_date
1599 AND    piv.element_type_id      = prr.element_type_id
1600 AND    prv1.run_result_id       = prv.run_result_id
1601 AND    piv1.name                 = 'SI Type'
1602 AND    prv.result_value         IS NOT NULL
1603 AND    pet.element_name IN
1604 ('Net Employee SI Contribution', 'Employee SI Contribution Standard Tax',
1605        'Employee SI Contribution Special Tax', 'Employee SI Contribution');
1606 
1607 --
1608 	CURSOR csr_emp_phc_applies(p_assgn_action_id NUMBER
1609 				  ,p_date_earned     DATE) IS
1610 	SELECT 1
1611 	FROM pay_run_results prr
1612 	    ,pay_element_types_f pet
1613 	WHERE
1614 		pet.element_name = 'Private Health Insurance'
1615 	AND 	prr.assignment_action_id=p_assgn_action_id
1616 	AND 	prr.element_type_id=pet.element_type_id
1617 	AND     p_date_earned   BETWEEN pet.effective_start_date
1618 				AND     pet.effective_end_date;
1619 --Bug No 3384315
1620 --Cursor which gets the previous year income given assignment action id of payroll run
1621 Cursor get_prev_year_salary (p_asg_act_id number
1622                      ,p_date_earned date) is
1623 select result_value
1624 from pay_run_result_values prrv
1625 , pay_run_results prr
1626 ,pay_element_types_f pet
1627 ,pay_input_values_f piv
1628 where prrv.run_result_id=prr.run_result_id
1629 and prr.assignment_action_id=p_asg_act_id
1630 and prr.element_type_id=pet.element_type_id
1631 and pet.element_name = 'Special Tax Deduction'
1632 and prrv.input_value_id=piv.input_value_id
1633 and piv.legislation_code = 'NL'
1634 and piv.name = 'Previous Year Taxable Income'
1635 and p_date_earned   BETWEEN pet.effective_start_date
1636 		     AND     pet.effective_end_date
1637 and p_date_earned   BETWEEN piv.effective_start_date
1638                         AND piv.effective_end_date;
1639 
1640 --
1641 --
1642 csr_hr_org_address_rec 		csr_get_hr_org_address%ROWTYPE;
1643 l_value                         hr_lookups.lookup_code%TYPE;
1644 l_meaning                       hr_lookups.meaning%TYPE;
1645 l_tax_code                      hr_soft_coding_keyflex.segment1%TYPE;
1646 l_prev_year_sal		        hr_soft_coding_keyflex.segment1%TYPE;
1647 l_tax_reduction                 hr_soft_coding_keyflex.segment1%TYPE;
1648 l_labour_tax_reduction          hr_soft_coding_keyflex.segment1%TYPE;
1649 l_add_senior_tax_reduction      hr_soft_coding_keyflex.segment1%TYPE;
1650 l_org_struct_id			NUMBER;
1651 l_ni				hr_lookups.meaning%TYPE;
1652 l_period			hr_lookups.meaning%TYPE;
1653 l_table				hr_lookups.meaning%TYPE;
1654 l_age				NUMBER;
1655 l_period_type			pay_all_payrolls_f.period_type%TYPE;
1656 l_ret				pay_user_column_instances_f.value%TYPE;
1657 l_struct_id			NUMBER;
1658 l_min_wage_type			pay_user_columns.user_column_name%TYPE;
1659 l_min_wage_factor		NUMBER;
1660 l_bus_group_id			NUMBER;
1661 l_org_struct_ver_id		NUMBER;
1662 l_legal_min_payment		VARCHAR2(240);
1663 l_si_def_bal_id			NUMBER;
1664 l_context_id			NUMBER;
1665 l_context_value			pay_action_contexts.context_value%TYPE;
1666 l_seq				VARCHAR2(60);
1667 l_si_days			NUMBER;
1668 l_WAO  				VARCHAR2(30);
1669 l_WW   				VARCHAR2(30);
1670 l_ZVW  				VARCHAR2(30);
1671 l_ZW   				VARCHAR2(30);
1672 l_E1   				VARCHAR2(240);
1673 l_E2   				VARCHAR2(240);
1674 l_E3   				VARCHAR2(240);
1675 l_E4   				VARCHAR2(240);
1676 l_E5   				VARCHAR2(240);
1677 l_E6   				VARCHAR2(240);
1678 l_E7   				VARCHAR2(240);
1679 l_E8   				VARCHAR2(240);
1680 l_E9   				VARCHAR2(240);
1681 l_E10  				VARCHAR2(240);
1682 l_employer_id			NUMBER;
1683 l_regular_working_hours		NUMBER;
1684 l_action_info_id		NUMBER;
1685 l_ovn				NUMBER;
1686 l_organization_Id		NUMBER;
1687 l_individual_working_hours	NUMBER;
1688 l_not_defined			VARCHAR2(255);
1689 l_province			hr_lookups.meaning%TYPE;
1690 l_city				hr_lookups.meaning%TYPE;
1691 l_street_name			hr_lookups.meaning%TYPE;
1692 l_country			FND_TERRITORIES_TL.TERRITORY_SHORT_NAME%TYPE;
1693 l_dummy				NUMBER;
1694 --
1695 BEGIN
1696 --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS',1400);
1697 OPEN csr_nl_employee_details;
1698 	    --
1699 	    FETCH csr_nl_employee_details INTO l_tax_code
1700 					      ,l_dummy
1701 					      ,l_tax_reduction
1702 					      ,l_labour_tax_reduction
1703 					      ,l_add_senior_tax_reduction
1704 					      ,l_individual_working_hours;
1705 	    --
1706 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_prev_year_sal'||l_prev_year_sal,1420);
1707 
1708 	IF  csr_nl_employee_details%FOUND THEN
1709 
1710 		  --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_meaning'||l_meaning,1440);
1711 		  --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_tax_code'||l_tax_code,1440);
1712 		  --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS p_assignment_id'||p_assignment_id,1440);
1713 
1714 		  l_meaning:= hr_general.decode_lookup('NL_TAX_CODE'
1715 						     ,substr(l_tax_code,1,3));
1716 
1717 		  --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_ni'||l_ni,1440);
1718 
1719 		  IF  l_meaning is null THEN
1720 			-- Split the tax code
1721 			-- 1st Digit
1722 		  l_ni:= hr_general.decode_lookup('NL_TAX_TYPE'
1723 						     ,substr(l_tax_code,1,1));
1724 
1725 			-- 2nd Digit
1726 		  l_table:= hr_general.decode_lookup('NL_TAX_TABLE'
1727 							   ,substr(l_tax_code,2,1));
1728 
1729 			-- 3rd Digit
1730 		  l_period:= hr_general.decode_lookup('NL_PAYROLL_PERIOD'
1731 							   ,substr(l_tax_code,3,1));
1732 
1733 		  END IF;
1734 	ELSE
1735 		l_tax_code                      :='940';
1736 		l_prev_year_sal                 :='0.00';
1737 		l_tax_reduction                 :='N';
1738 		l_labour_tax_reduction          :='N';
1739 		l_add_senior_tax_reduction      :='N';
1740 
1741 	    END IF;
1742 	CLOSE csr_nl_employee_details;
1743 	--
1744 	--Bug No 3384315
1745 	--Get the previous year salary from the input value of special tax deduction element
1746 	OPEN get_prev_year_salary (p_master_asg_act_id, p_date_earned);
1747 	Fetch get_prev_year_salary INTO l_prev_year_sal;
1748 	CLOSE get_prev_year_salary;
1749 
1750 	IF l_prev_year_sal IS NULL THEN
1751 	l_prev_year_sal:='0.00';
1752 	END IF;
1753 
1754 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_tax_code'||l_tax_code,1440);
1755 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_tax_reduction'||l_tax_reduction,1440);
1756 
1757 	--Bug No.3380758
1758 	--Moved initializing l_age before assigning the l_tax_reduction
1759 
1760 	l_age := pay_nl_tax_pkg.get_age_payroll_period(p_assignment_id
1761 							,p_payroll_id
1762 							  ,p_date_earned);
1763 
1764 	IF l_tax_reduction = 'Y' THEN
1765 
1766 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_age'||l_age,1440);
1767 		IF l_age < 65 THEN
1768 		  l_tax_reduction :=hr_general.decode_lookup('HR_NL_REPORT_LABELS'
1769 							,'NL_GENERAL');
1770 	      ELSE
1771 		  l_tax_reduction:= hr_general.decode_lookup('HR_NL_REPORT_LABELS'
1772 							  ,'NL_SENIOR');
1773 		END IF;
1774 
1775 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_tax_reduction'||l_tax_reduction,1440);
1776 	END IF;
1777 	--
1778 	--
1779 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_tax_code'||l_tax_code,1440);
1780 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS p_assg_action_id'||p_assg_action_id,1400);
1781 	-- Archive NL EMPLOYEE DETAILS
1782 	--
1783 	--pay_action_information_api.create_action_information ();
1784 
1785 	 pay_action_information_api.create_action_information (
1786 	  p_action_information_id        => l_action_info_id
1787 	 ,p_action_context_id            => p_assg_action_id
1788 	 ,p_action_context_type          => 'AAP'
1789 	 ,p_object_version_number        => l_ovn
1790 	 ,p_effective_date               => p_date_earned
1791 	 ,p_source_id                    => NULL
1792 	 ,p_source_text                  => NULL
1793 	 ,p_action_information_category  => 'NL EMPLOYEE DETAILS'
1794 	 ,p_action_information21          =>l_tax_code
1795 	 ,p_action_information22          =>l_ni
1796 	 ,p_action_information23          =>l_table
1797 	 ,p_action_information24          =>l_period
1798 	 ,p_action_information25          =>l_prev_year_sal
1799 	 ,p_action_information26          =>l_tax_reduction
1800 	 ,p_action_information27          =>l_labour_tax_reduction
1801 	 ,p_action_information28          =>l_add_senior_tax_reduction);
1802 
1803 	 --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_action_info_id'||l_action_info_id,1400);
1804 
1805 	OPEN csr_payroll_period;
1806 	    FETCH csr_payroll_period INTO l_period_type,l_bus_group_id;
1807 	CLOSE csr_payroll_period;
1808 
1809 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_period_type'||l_period_type,1400);
1810 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_bus_group_id'||l_bus_group_id,1400);
1811 	--
1812 	IF  l_period_type     = 'Calendar Month' THEN
1813 	    l_min_wage_type   := 'Month';
1814 	    l_min_wage_factor := 1;
1815 	ELSIF  l_period_type  = 'Week' THEN
1816 	    l_min_wage_type   := 'Week';
1817 	    l_min_wage_factor := 1;
1818 	ELSIF  l_period_type  = 'Lunar Month' THEN
1819 	    l_min_wage_type   := 'Week';
1820 	    l_min_wage_factor := 4;
1821 	ELSIF  l_period_type  = 'Quarter' THEN
1822 	    l_min_wage_type   := 'Month';
1823 	    l_min_wage_factor := 3;
1824 	END IF;
1825 
1826 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_min_wage_type'||l_min_wage_type,1420);
1827 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_min_wage_factor'||l_min_wage_factor,1420);
1828 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_age'||l_age,1420);
1829 
1830 	IF l_age > 23 THEN
1831 	l_age:=23;
1832 	END IF;
1833 
1834 	BEGIN
1835 	    l_ret:= hruserdt.get_table_value(l_bus_group_id
1836 					    ,'NL_LEGAL_MINIMUM_WAGES'
1837 					    ,l_min_wage_type
1838 					    ,l_age);
1839 	EXCEPTION
1840 	    WHEN NO_DATA_FOUND THEN
1841 	    l_ret:='0';
1842 	END;
1843 	--
1844 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_ret'||l_ret,1425);
1845 
1846 	OPEN csr_nl_emp_organization;
1847 	FETCH csr_nl_emp_organization INTO l_organization_Id;
1848 	CLOSE csr_nl_emp_organization;
1849 
1850 	-- Derive the Org Structure Id from BG Level
1851 	--
1852 	l_struct_id := HR_NL_ORG_INFO.NAMED_HIERARCHY (l_bus_group_id);
1853 	--
1854 	--
1855 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_struct_id'||l_struct_id,1430);
1856 
1857 	-- Derive the Org Structure Version Id
1858 	--
1859 	OPEN csr_get_org_struct_ver_id (l_struct_id,p_date_earned);
1860 	     FETCH csr_get_org_struct_ver_id INTO l_org_struct_ver_id;
1861 	CLOSE csr_get_org_struct_ver_id;
1862 	--
1863 	--
1864 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_org_struct_ver_id'||l_org_struct_ver_id,1440);
1865 
1866 	l_employer_id := HR_NL_ORG_INFO.GET_TAX_ORG_ID(l_org_struct_ver_id
1867 						      ,l_organization_Id);
1868 	--
1869 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_employer_id'||l_employer_id,1450);
1870 	--Bug 3601121
1871 	l_legal_min_payment := NVL(fnd_number.number_to_canonical((FND_NUMBER.CANONICAL_TO_NUMBER(l_ret) * l_min_wage_factor)),'');
1872 
1873 	l_si_def_bal_id := get_defined_balance_id('Real Social Insurance Days'
1874 						 ,'_ASG_SIT_RUN');
1875 
1876 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_legal_min_payment'||l_legal_min_payment,1460);
1877 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_si_def_bal_id'||l_si_def_bal_id,1460);
1878 
1879 	OPEN csr_get_context_id('SOURCE_TEXT',p_master_asg_act_id);
1880 	    FETCH csr_get_context_id INTO l_context_id,l_context_value,l_seq;
1881 	CLOSE csr_get_context_id;
1882 
1883 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_context_id'||l_context_id,1470);
1884 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_context_value'||l_context_value,1470);
1885 
1886 	BEGIN
1887 	    l_si_days:=0;
1888 
1889 	    IF l_context_id IS NOT NULL THEN
1890 	    l_si_days := pay_balance_pkg.get_value(l_si_def_bal_id
1891 						   ,p_master_asg_act_id
1892 						   ,NULL
1893 						   ,NULL
1894 						   ,l_context_id
1895 						   ,l_context_value
1896 						   ,NULL
1897 						   ,NULL);
1898 	   END IF;
1899 
1900 	EXCEPTION
1901 	    WHEN OTHERS THEN
1902 	    l_si_days:=0;
1903 	END;
1904 
1905 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_si_days'||l_si_days,1480);
1906 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_si_days'||' '||l_si_days);
1907 	--
1908 	-- Archive NL OTHER EMPLOYEE DETAILS
1909 	--
1910 	--pay_action_information_api.create_action_information ();
1911 	--
1912 	--l_individual_working_hours
1913 	--
1914 	pay_action_information_api.create_action_information (
1915 		  p_action_information_id        => l_action_info_id
1916 		 ,p_action_context_id            => p_assg_action_id
1917 		 ,p_action_context_type          => 'AAP'
1918 		 ,p_object_version_number        => l_ovn
1919 		 ,p_effective_date               => p_date_earned
1920 		 ,p_source_id                    => NULL
1921 		 ,p_source_text                  => NULL
1922 		 ,p_action_information_category  => 'NL OTHER EMPLOYEE DETAILS'
1923 		 ,p_action_information4          =>p_payroll_id
1924 		 ,p_action_information5          =>l_employer_id
1925 		 ,p_action_information6          =>fnd_number.number_to_canonical(l_individual_working_hours)
1926 		 ,p_action_information7          =>l_legal_min_payment
1927 		 ,p_action_information8          =>fnd_number.number_to_canonical(l_si_days));
1928 
1929 	OPEN csr_get_hr_org_address(l_employer_id);
1930 	    FETCH csr_get_hr_org_address INTO csr_hr_org_address_rec;
1931 	CLOSE csr_get_hr_org_address;
1932 	--
1933 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_si_days'||l_si_days,1490);
1934 
1935 	OPEN csr_get_regular_working_hrs( p_assignment_id);
1936 	    FETCH csr_get_regular_working_hrs INTO l_regular_working_hours;
1937 	CLOSE csr_get_regular_working_hrs;
1938 
1939 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_regular_working_hours'||l_regular_working_hours,1500);
1940 	--
1941 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_regular_working_hours'||' '||l_regular_working_hours);
1942 	-- Archive ADDL EMPLOYEE DETAILS
1943 	--
1944 
1945 	l_city:= hr_general.decode_lookup('HR_NL_CITY',csr_hr_org_address_rec.city);
1946 
1947         l_province:= hr_general.decode_lookup('HR_NL_PROVINCE',csr_hr_org_address_rec.province);
1948 
1949 	l_country:=get_country_name(csr_hr_org_address_rec.country);
1950 
1951 	l_street_name:=csr_hr_org_address_rec.street_name;
1952 
1953 	IF csr_hr_org_address_rec.style = 'NL_GLB' THEN
1954 
1955 	l_street_name:= hr_general.decode_lookup('NL_REGION',csr_hr_org_address_rec.street_name);
1956 
1957 	END IF;
1958 
1959 	/*OPEN csr_get_territory_name(csr_hr_org_address_rec.country);
1960 		FETCH csr_get_territory_name INTO l_country;
1961 	CLOSE csr_get_territory_name;*/
1962 
1963 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS csr_hr_org_address_rec.name'||csr_hr_org_address_rec.name,1500);
1964 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS csr_hr_org_address_rec.city'||csr_hr_org_address_rec.city,1500);
1965 
1966 	--pay_action_information_api.create_action_information (..);
1967 	--
1968 	pay_action_information_api.create_action_information (
1969 		  p_action_information_id        => l_action_info_id
1970 		 ,p_action_context_id            => p_assg_action_id
1971 		 ,p_action_context_type          => 'AAP'
1972 		 ,p_object_version_number        => l_ovn
1973 		 ,p_effective_date               => p_date_earned
1974 		 ,p_source_id                    => NULL
1975 		 ,p_source_text                  => NULL
1976 		 ,p_action_information_category  => 'ADDL EMPLOYEE DETAILS'
1977 		 ,p_action_information4          =>csr_hr_org_address_rec.name
1978 		 ,p_action_information5          =>l_street_name
1979 		 ,p_action_information6          =>csr_hr_org_address_rec.add_line1
1980 		 ,p_action_information7          =>csr_hr_org_address_rec.add_line2
1981 		 ,p_action_information8          =>csr_hr_org_address_rec.add_line3
1982 		 ,p_action_information9          =>csr_hr_org_address_rec.postal_code
1983 		 ,p_action_information10         =>l_city
1984 	 	 ,p_action_information11         =>l_province
1985 	 	 ,p_action_information12         =>l_country
1986 	 	 ,p_action_information13         =>csr_hr_org_address_rec.po_box_no
1987 	 	 ,p_action_information14         =>fnd_number.number_to_canonical(l_regular_working_hours));
1988 
1989 	--
1990 	l_WAO   := 'N';
1991 	l_WW    := 'N';
1992 	l_ZVW   := 'N';
1993 	l_ZW    := 'N';
1994 	l_E1    := '';
1995 	l_E2    := '';
1996 	l_E3    := '';
1997 	l_E4    := '';
1998 	l_E5    := '';
1999 	l_E6    := '';
2000 	l_E7    := '';
2001 	l_E8    := '';
2002 	l_E9    := '';
2003 	l_E10   := '';
2004 	--
2005 	--
2006 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_WAO'||l_WAO,1500);
2007 
2008 	fnd_message.set_name('PAY','PAY_NL_SI_TYPE_NOT_DEFINED');
2009 	l_not_defined := substr(fnd_message.get,1,254);
2010 
2011 	 --hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_not_defined'||l_not_defined,1500);
2012 
2013 	FOR si_type_rec IN csr_element_si_type_value(p_master_asg_act_id
2014 						,p_date_earned) LOOP
2015 	    --
2016 
2017 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS si_type_rec.si_type'||si_type_rec.si_type,1700);
2018 	    IF  si_type_rec.si_type = 'WAOD' and l_not_defined <> si_type_rec.value   THEN
2019 		l_WAO := 'Y';
2020 	    ELSIF  si_type_rec.si_type = 'WAOB' and l_not_defined <> si_type_rec.value THEN
2021 		l_WAO := 'Y';
2022 	    ELSIF  si_type_rec.si_type = 'WEWE'  and l_not_defined <> si_type_rec.value THEN
2023 		l_WW := 'Y';
2024     	    ELSIF  si_type_rec.si_type = 'WEWA'  and l_not_defined <> si_type_rec.value THEN
2025 		l_WW := 'Y';
2026 	    ELSIF  si_type_rec.si_type = 'ZVW' and l_not_defined <> si_type_rec.value THEN
2027 		l_ZVW := 'Y';
2028 	    ELSIF  si_type_rec.si_type = 'ZW'  and l_not_defined <> si_type_rec.value THEN
2029 		l_ZW := 'Y';
2030 	    ELSIF  si_type_rec.si_type = 'E1'   THEN
2031 		l_E1 := si_type_rec.value;
2032 	    ELSIF  si_type_rec.si_type = 'E2'   THEN
2033 		l_E2 := si_type_rec.value;
2034 	    ELSIF  si_type_rec.si_type = 'E3'   THEN
2035 		l_E3 := si_type_rec.value;
2036 	    ELSIF  si_type_rec.si_type = 'E4'   THEN
2037 		l_E4 := si_type_rec.value;
2038 	    ELSIF  si_type_rec.si_type = 'E5'   THEN
2039 		l_E5 := si_type_rec.value;
2040 	    ELSIF  si_type_rec.si_type = 'E6'   THEN
2041 		l_E6 := si_type_rec.value;
2042 	    ELSIF  si_type_rec.si_type = 'E7'   THEN
2043 		l_E7 := si_type_rec.value;
2044 	    ELSIF  si_type_rec.si_type = 'E8'   THEN
2045 		l_E8 := si_type_rec.value;
2046 	    ELSIF  si_type_rec.si_type = 'E9'   THEN
2047 		l_E9 := si_type_rec.value;
2048 	    ELSIF  si_type_rec.si_type = 'E10'  THEN
2049 		l_E10 := si_type_rec.value;
2050 	    END IF;
2051 	    --
2052 	END LOOP ; --
2053 
2054 
2055     	OPEN csr_emp_phc_applies(p_master_asg_act_id
2056                               ,p_date_earned);
2057 	FETCH csr_emp_phc_applies into l_dummy;
2058     	IF csr_emp_phc_applies%FOUND THEN
2059 	    	l_ZVW:= 'N';
2060     	END IF;
2061 
2062 	-- Archive NL SI EMPLOYEE DETAILS
2063 	--
2064 	--pay_action_information_api.create_action_information (..);
2065 	--
2066 	pay_action_information_api.create_action_information (
2067 		  p_action_information_id        => l_action_info_id
2068 		 ,p_action_context_id            => p_assg_action_id
2069 		 ,p_action_context_type          => 'AAP'
2070 		 ,p_object_version_number        => l_ovn
2071 		 ,p_effective_date               => p_date_earned
2072 		 ,p_source_id                    => NULL
2073 		 ,p_source_text                  => NULL
2074 		 ,p_action_information_category  => 'NL SI EMPLOYEE DETAILS'
2075 		 ,p_action_information4          =>l_WAO
2076 		 ,p_action_information5          =>l_WW
2077 		 ,p_action_information6          =>l_ZVW
2078 		 ,p_action_information7          =>l_ZW
2079 		 ,p_action_information8          =>l_E1
2080 		 ,p_action_information9          =>l_E2
2081 		 ,p_action_information10         =>l_E3
2082 		 ,p_action_information11         =>l_E4
2083 		 ,p_action_information12         =>l_E5
2084 		 ,p_action_information13         =>l_E6
2085 		 ,p_action_information14         =>l_E7
2086 		 ,p_action_information15         =>l_E8
2087 		 ,p_action_information16         =>l_E9
2088 		 ,p_action_information17         =>l_E10);
2089 
2090 	--hr_utility.set_location('Inside  ARCHIVE_NL_EMPLOYEE_DETAILS l_regular_working_hours'||l_regular_working_hours,2000);
2091 
2092 END ARCHIVE_NL_EMPLOYEE_DETAILS;
2093 /*-------------------------------------------------------------------------------
2094 |Name           : get_country_name                                           	|
2095 |Type			: Function														|
2096 |Description    : Function to get the country name from FND_TERRITORIES_VL		|
2097 -------------------------------------------------------------------------------*/
2098 
2099 FUNCTION get_country_name(p_territory_code VARCHAR2) RETURN VARCHAR2 IS
2100 	CURSOR csr_get_territory_name(p_territory_code VARCHAR2) Is
2101 	SELECT TERRITORY_SHORT_NAME
2102 	FROM FND_TERRITORIES_VL
2103 	WHERE TERRITORY_CODE = p_territory_code;
2104 
2105 	l_country FND_TERRITORIES_VL.TERRITORY_SHORT_NAME%TYPE;
2106 BEGIN
2107 	OPEN csr_get_territory_name(p_territory_code);
2108 	FETCH csr_get_territory_name into l_country;
2109 	CLOSE csr_get_territory_name;
2110 	RETURN l_country;
2111 END;
2112 --
2113 /*-------------------------------------------------------------------------------
2114 |Name           : ARCHIVE_USER_ELEMENT_INFO     	                   	    	|
2115 |Type			: Procedure														|
2116 |Description    : Procedure archives EMEA ELEMENT INFO context					|
2117 -------------------------------------------------------------------------------*/
2118 PROCEDURE archive_user_element_info (p_action_context_id       IN NUMBER
2119                                     ,p_assignment_id           IN NUMBER
2120                                     ,p_child_assignment_action IN NUMBER
2121                                     ,p_effective_date          IN DATE
2122                                     ,p_record_count            IN NUMBER
2123                                     ,p_run_method              IN VARCHAR2)IS
2124 	--
2125 	CURSOR check_si_type (p_element_type_id      NUMBER
2126 						,p_effective_date       DATE) 	IS
2127 	SELECT 1
2128 	FROM   pay_input_values_f piv
2129 	WHERE  piv.element_type_id      = p_element_type_id
2130 	AND    piv.NAME                 = 'SI Type'
2131 	AND    p_effective_date         BETWEEN piv.effective_start_date
2132 	AND     piv.effective_end_date;
2133 	--
2134 	--
2135 	--
2136 	CURSOR csr_element_values (p_assignment_action_id NUMBER
2137 							  ,p_element_type_id      NUMBER
2138 							  ,p_input_value_id       NUMBER) IS
2139 	SELECT prv.result_value
2140 	FROM   pay_run_result_values    prv
2141 		  ,pay_run_results          prr
2142 	WHERE  prr.status               IN ('P','PA')
2143 	AND    prv.run_result_id        = prr.run_result_id
2144 	AND    prr.assignment_action_id = p_assignment_action_id
2145 	AND    prr.element_type_id      = p_element_type_id
2146 	AND    prv.input_value_id       = p_input_value_id
2147 	AND    prv.result_value         IS NOT NULL;
2148 	--
2149 	CURSOR csr_element_si_type_value(p_assignment_action_id NUMBER
2150 									,p_element_type_id      NUMBER
2151 									,p_input_value_id       NUMBER
2152 									,p_si_type              VARCHAR2
2153 									,p_effective_date       DATE) IS
2154 	SELECT prv.result_value         value
2155 		,prv1.result_value       si_type
2156 	FROM   pay_run_result_values    prv
2157 	,pay_run_results          prr
2158 	,pay_input_values_f       piv
2159 	,pay_run_result_values    prv1
2160 	WHERE  prr.status               IN ('P','PA')
2161 		AND    prv.run_result_id        = prr.run_result_id
2162 		AND    prr.assignment_action_id = p_assignment_action_id
2163 		AND    prr.element_type_id      = p_element_type_id
2164 		AND    prv.input_value_id       = p_input_value_id
2165 		AND    piv.name                 = 'SI Type'
2166 		AND    p_effective_date         BETWEEN piv.effective_start_date
2167 								AND     piv.effective_end_date
2168 		AND    piv.element_type_id      = prr.element_type_id
2169 		AND    prv1.run_result_id       = prv.run_result_id
2170 		AND    prv1.input_value_id      = piv.input_value_id
2171 		AND    prv1. result_value       = NVL(p_si_type,prv1. result_value)
2172 		AND    prv.result_value         IS NOT NULL;
2173 	--
2174     --
2175     CURSOR csr_get_si_type_name_iv_id(p_element_type_id	NUMBER
2176           ,p_effective_date	DATE) IS
2177 	select piv.input_value_id
2178 	from pay_input_values_f piv
2179 	,pay_element_types_f pet
2180 	where
2181 	pet.element_type_id=p_element_type_id
2182 	and pet.element_type_id=piv.element_type_id
2183 	and piv.name = 'SI Type Name'
2184 	and p_effective_date between piv.effective_start_date
2185 	and piv.effective_end_date;
2186 
2187    CURSOR csr_element_si_type_name(p_assignment_action_id NUMBER
2188 			    ,p_element_type_id      NUMBER
2189 			    ,p_si_type              VARCHAR2
2190 			    ,p_effective_date       DATE) IS
2191 	Select  prv1.result_value       si_type_name
2192 	From
2193 	pay_run_result_values    prv
2194 	,pay_run_results          prr
2195 	,pay_input_values_f       piv
2196 	,pay_run_result_values    prv1
2197 	,pay_input_values_f       piv1
2198 	where prr.status in ('P','PA')
2199 	AND    prr.run_result_id   = prv.run_result_id
2200 	AND    prr.assignment_action_id = p_assignment_action_id
2201 	AND    prr.element_type_id      = p_element_type_id
2202 	AND    piv.name                 = 'SI Type'
2203 	AND    prv.input_value_id       = piv.input_value_id
2204 	AND    p_effective_date      BETWEEN piv.effective_start_date
2205 	AND     piv.effective_end_date
2206 	AND    piv1.name                 = 'SI Type Name'
2207 	AND    prv1.input_value_id       = piv1.input_value_id
2208 	AND    p_effective_date      BETWEEN piv1.effective_start_date
2209 	AND     piv1.effective_end_date
2210 	AND    prv1.run_result_id       = prv.run_result_id
2211 	AND    prv.result_value         = p_si_type;
2212     --
2213     l_action_info_id  		NUMBER;
2214     l_column_sequence 		NUMBER;
2215     l_element_type_id 		NUMBER;
2216     l_main_sequence   		NUMBER;
2217     l_multi_sequence  		NUMBER;
2218     l_ovn             		NUMBER;
2219     l_record_count    		VARCHAR2(10);
2220     l_dummy	      		VARCHAR2(240);
2221     l_si_type_name_iv_id	NUMBER;
2222     l_si_type_name		VARCHAR2(240);
2223 --
2224 BEGIN
2225 	--
2226 	l_column_sequence := 0;
2227 	l_element_type_id := 0;
2228 	l_main_sequence   := 0;
2229 	l_multi_sequence  := NULL;
2230 
2231 	--hr_utility.set_location('Inside f p_record_count'||p_record_count,1520);
2232 
2233 	IF  p_record_count = 0  THEN
2234 		l_record_count := NULL;
2235 	ELSE
2236 		l_record_count := p_record_count + 1;
2237 	END IF;
2238 	--
2239 	FOR l_index IN 1 .. g_element_table.count
2240 	LOOP
2241 		--
2242 		--hr_utility.set_location('Inside archive_user_element_info l_record_count'||l_record_count,1530);
2243 
2244 		l_dummy := NULL;
2245 		OPEN check_si_type(g_element_table(l_index).element_type_id	,p_effective_date);
2246 		FETCH check_si_type INTO l_dummy;
2247 		CLOSE check_si_type;
2248 		-- If SI Type doesn't exist then normal processing
2249 
2250 		--hr_utility.set_location('Inside archive_user_element_info l_dummy'||l_dummy,1530);
2251 
2252 		IF  l_dummy IS NULL THEN
2253 			FOR rec_element_value IN csr_element_values
2254 				(p_child_assignment_action,g_element_table(l_index).element_type_id
2255 				,g_element_table(l_index).input_value_id)
2256 			LOOP
2257 				--
2258 				IF  l_element_type_id <> g_element_table(l_index).element_type_id THEN
2259 					l_main_sequence := l_main_sequence + 1;
2260 				END IF;
2261 				l_column_sequence := l_column_sequence + 1;
2262 				--
2263 				--hr_utility.set_location('Inside archive_user_element_info l_element_type_id'||l_element_type_id,1530);
2264 				--hr_utility.set_location('Inside archive_user_element_info g_element_table(l_index).element_type_id'||g_element_table(l_index).element_type_id,1530);
2265 				--hr_utility.set_location('Inside archive_user_element_info p_run_method'||p_run_method,1530);
2266 
2267 				-- If the run method is P, Process Separate, then only archive the
2268 				-- data if a skip rule (formula_id) has been set. If there is no
2269 				-- skip rule then the element info will be archived for the normal
2270 				-- assignment action and doesn't need to be archived twice. If it
2271 				-- is then duplicates will be displayed on the payslip.
2272 				--
2273 				--Commented this Chk,which prevents elements in the Proc Sep Runs
2274 				--to be skipped.
2275 				--IF  p_run_method = 'P' AND g_element_table(l_index).formula_id IS NULL THEN
2276 				--	NULL;
2277 				--ELSE
2278 				--
2279 				-- Archive EMEA ELEMENT INFO
2280 				--
2281 				--hr_utility.set_location('Inside archive_user_element_info p_run_method'||p_run_method,1530);
2282 				pay_action_information_api.create_action_information (
2283 					p_action_information_id        => l_action_info_id
2284 					,p_action_context_id            => p_action_context_id
2285 					,p_action_context_type          => 'AAP'
2286 					,p_object_version_number        => l_ovn
2287 					,p_assignment_id                => p_assignment_id
2288 					,p_effective_date               => p_effective_date
2289 					,p_source_id                    => p_child_assignment_action
2290 					,p_source_text                  => NULL
2291 					,p_action_information_category  => 'EMEA ELEMENT INFO'
2292 					,p_action_information1          => g_element_table(l_index).element_type_id
2293 					,p_action_information2          => g_element_table(l_index).input_value_id
2294 					,p_action_information3          => NULL
2295 					,p_action_information4          => rec_element_value.result_value
2296 					,p_action_information5          => l_main_sequence
2297 					,p_action_information6          => l_multi_sequence
2298 					,p_action_information7          => l_column_sequence
2299 					,p_action_information8          => l_record_count);
2300 				--hr_utility.set_location('Inside archive_user_element_info l_action_info_id'||l_action_info_id,1540);
2301 				--END IF;
2302 				--
2303 				l_multi_sequence := NVL(l_multi_sequence,0) + 1;
2304 				l_element_type_id := g_element_table(l_index).element_type_id;
2305 			--
2306 			END LOOP;
2307 		--
2308 		ELSE -- If SI Type exist then archive by SI Type Values
2309 			--
2310 			--hr_utility.set_location('Inside archive_user_element_info si type'||g_element_table(l_index).si_type,1542);
2311 			FOR rec_element_value IN csr_element_si_type_value (p_child_assignment_action
2312 			,g_element_table(l_index).element_type_id,g_element_table(l_index).input_value_id
2313 			,g_element_table(l_index).si_type,p_effective_date)
2314 			LOOP
2315 				--
2316 				--hr_utility.set_location('Inside archive_user_element_info si type'||rec_element_value.si_type,1544);
2317 				--hr_utility.set_location('Inside archive_user_element_info si type'||rec_element_value.value,1544);
2318 
2319 				IF  l_element_type_id <> g_element_table(l_index).element_type_id THEN
2320 					l_main_sequence := l_main_sequence + 1;
2321 				END IF;
2322 				l_column_sequence := l_column_sequence + 1;
2323 				--
2324 				-- If the run method is P, Process Separate, then only archive the
2325 				-- data if a skip rule (formula_id) has been set. If there is no
2326 				-- skip rule then the element info will be archived for the normal
2327 				-- assignment action and doesn't need to be archived twice. If it
2328 				-- is then duplicates will be displayed on the payslip.
2329 				--
2330 				--Commented this Chk,which prevents elements in the Proc Sep Runs
2331 				--to be skipped.
2332 				--IF  p_run_method = 'P' AND g_element_table(l_index).formula_id IS NULL THEN
2333 				--	NULL;
2334 				--ELSE
2335 
2336 				-- Retrieve SI Type Name
2337 				/*       OPEN csr_get_si_type_name_iv_id(
2338 				g_element_table(l_index).element_type_id
2339 				, p_effective_date);
2340 				FETCH csr_get_si_type_name_iv_id
2341 				INTO l_si_type_name_iv_id;
2342 				CLOSE csr_get_si_type_name_iv_id;
2343 				OPEN csr_element_values (
2344 				p_child_assignment_action
2345 				,g_element_table(l_index).element_type_id
2346 				,l_si_type_name_iv_id);
2347 				FETCH csr_element_values INTO l_si_type_name;
2348 				CLOSE csr_element_values;  */
2349 
2350 				OPEN csr_element_si_type_name(p_child_assignment_action
2351 				,g_element_table(l_index).element_type_id,rec_element_value.si_type,p_effective_date);
2352 				FETCH csr_element_si_type_name INTO l_si_type_name;
2353 				CLOSE csr_element_si_type_name;
2354 
2355 				--
2356 				-- Archive EMEA ELEMENT INFO
2357 				--
2358 
2359 				pay_action_information_api.create_action_information (
2360 					p_action_information_id        => l_action_info_id
2361 					,p_action_context_id            => p_action_context_id
2362 					,p_action_context_type          => 'AAP'
2363 					,p_object_version_number        => l_ovn
2364 					,p_assignment_id                => p_assignment_id
2365 					,p_effective_date               => p_effective_date
2366 					,p_source_id                    => p_child_assignment_action
2367 					,p_source_text                  => NULL
2368 					,p_action_information_category  => 'EMEA ELEMENT INFO'
2369 					,p_action_information1          => g_element_table(l_index).element_type_id
2370 					,p_action_information2          => g_element_table(l_index).input_value_id
2371 					,p_action_information3          => rec_element_value.si_type
2372 					,p_action_information4          => rec_element_value.value
2373 					,p_action_information5          => l_main_sequence
2374 					,p_action_information6          => l_multi_sequence
2375 					,p_action_information7          => l_column_sequence
2376 					,p_action_information8          => l_record_count
2377 					,p_action_information9          => l_si_type_name);
2378 					--hr_utility.set_location('Inside archive_user_element_info l_action_info_id'||l_action_info_id,1550);
2379 				--END IF;
2380 				--
2381 				--
2382 				l_multi_sequence := NVL(l_multi_sequence,0) + 1;
2383 				l_element_type_id := g_element_table(l_index).element_type_id;
2384 				--
2385 			END LOOP;
2386 		END IF;
2387 		l_multi_sequence := NULL;
2388 	END LOOP;
2389 	--hr_utility.set_location('Inside archive_user_element_info l_multi_sequence'||l_multi_sequence,1590);
2390 EXCEPTION
2391   WHEN NO_DATA_FOUND THEN
2392       NULL;
2393 END archive_user_element_info;
2394 --
2395 /*-------------------------------------------------------------------------------
2396 |Name           : PROCESS_BALANCE     	        		               	|
2397 |Type		: Procedure							|
2398 |Description    : Procedure archives EMEA BALANCES context			|
2399 -------------------------------------------------------------------------------*/
2400 
2401 PROCEDURE process_balance (p_action_context_id IN NUMBER
2402                           ,p_assignment_id     IN NUMBER
2403                           ,p_source_id         IN NUMBER
2404                           ,p_effective_date    IN DATE
2405                           ,p_balance           IN VARCHAR2
2406                           ,p_dimension         IN VARCHAR2
2407                           ,p_defined_bal_id    IN NUMBER
2408                           ,p_si_type           IN VARCHAR2
2409                           ,p_record_count      IN NUMBER)  IS
2410 
2411     --
2412     CURSOR csr_get_si_types(p_assig_action_id NUMBER
2413                            ,p_context_name    VARCHAR2) IS
2414     SELECT pac.context_id           context_id
2415           ,pac.context_value        value
2416     FROM   ff_contexts              ff
2417           ,pay_action_contexts      pac
2418     WHERE  ff.context_name          = p_context_name
2419     AND    pac.context_id           = ff.context_id
2420     AND    pac.assignment_Action_id = p_assig_action_id;
2421     --
2422     CURSOR csr_get_context_id(p_context_name  VARCHAR2) IS
2423     SELECT ff.context_id            context_id
2424     FROM   ff_contexts              ff
2425     WHERE  ff.context_name          = p_context_name;
2426     --
2427     --
2428     --
2429     --
2430     CURSOR csr_get_sit_type_name (p_balance_name     VARCHAR2
2431                                 ,p_assgn_action_id  NUMBER
2432                                 ,p_date_earned      DATE
2433                                 ,p_si_type	    VARCHAR2) IS
2434     SELECT prrv1.result_value       si_type_name
2435     FROM   pay_balance_feeds_f      pbf
2436           ,pay_balance_types        pbt
2437           ,pay_input_values_f       piv
2438           ,pay_input_values_f       piv1
2439           ,pay_input_values_f       piv2
2440           ,pay_element_types_f      pet
2441           ,pay_run_results          prr
2442           ,pay_run_result_values    prrv
2443           ,pay_run_result_values    prrv1
2444     WHERE  pbf.balance_type_id      = pbt.balance_type_id
2445     AND    pbt.balance_name         = p_balance_name
2446     AND    piv.input_value_id       = pbf.input_value_id
2447     AND	   (piv.name                 ='Pay Value'
2448     OR     piv.name                 ='Days')
2449     AND    pet.element_type_id      = piv.element_type_id
2450     AND    pet.classification_id <> (SELECT classification_id
2451             from pay_element_classifications
2452             where classification_name ='Balance Initialization'
2453             and business_group_id is null
2454             and legislation_code is null)
2455     AND    piv1.element_type_id     = pet.element_type_id
2456     AND    piv1.name                = 'SI Type Name'
2457     AND    piv2.element_type_id     = pet.element_type_id
2458     AND    piv2.name                = 'SI Type'
2459     AND    prr.element_type_id      = pet.element_type_id
2460     AND    prr.assignment_action_id = p_assgn_action_id
2461     AND    prrv.run_result_id       = prr.run_result_id
2462     AND    prrv.input_value_id      = piv2.input_value_id
2463     AND    prrv.result_value        = p_si_type
2464     AND    prrv1.run_result_id      = prrv.run_result_id
2465     AND    prrv1.input_value_id     = piv1.input_value_id
2466     AND    p_date_earned             BETWEEN pbf.effective_start_date
2467                                      AND     pbf.effective_end_date
2468     AND    p_date_earned             BETWEEN pet.effective_start_date
2469                                      AND     pet.effective_end_date
2470     AND    p_date_earned             BETWEEN piv.effective_start_date
2471                                      AND     piv.effective_end_date
2472     AND    p_date_earned             BETWEEN piv1.effective_start_date
2473                                      AND     piv1.effective_end_date
2474     AND    p_date_earned             BETWEEN piv2.effective_start_date
2475                                      AND     piv2.effective_end_date;
2476     --
2477 l_balance_value		NUMBER;
2478 l_si_type_name		VARCHAR2(240);
2479 l_context_id		NUMBER;
2480 l_action_info_id	NUMBER;
2481 l_ovn			NUMBER;
2482 l_record_count		NUMBER;
2483 BEGIN
2484 	--
2485 
2486 	hr_utility.set_location('Inside process_balance p_action_context_id'||p_action_context_id,1820);
2487 	hr_utility.set_location('Inside process_balance p_dimension'||p_dimension,1820);
2488 
2489 	IF  p_record_count = 0  THEN
2490 		l_record_count := NULL;
2491 	ELSE
2492 		l_record_count := p_record_count + 1;
2493 	END IF;
2494 
2495 	IF p_dimension LIKE '%SIT%' THEN
2496 		--
2497 		hr_utility.set_location('Inside process_balance p_si_type'||p_si_type,1840);
2498 
2499 		IF  p_si_type IS NULL THEN
2500 			--
2501 			-- Loop through pay_action_context table for all SI Type
2502 			--
2503 			hr_utility.set_location('Inside process_balance p_source_id'||p_source_id,1860);
2504 
2505 			FOR context_rec IN csr_get_si_types(p_source_id,'SOURCE_TEXT')
2506 			LOOP
2507 				--
2508 				l_balance_value := pay_balance_pkg.get_value(p_defined_bal_id,p_source_id
2509 									,null,null,context_rec.context_id,context_rec.value
2510 									,null,null);
2511 				--
2512 				IF  l_balance_value <> 0 THEN
2513 					--
2514 					-- Retreive SI Type Name from run results
2515 					--
2516 					hr_utility.set_location('Inside process_balance p_balance'||p_balance,1870);
2517 					hr_utility.set_location('Inside process_balance p_source_id'||p_source_id,1870);
2518 					hr_utility.set_location('Inside process_balance p_effective_date'||p_effective_date,1870);
2519 					hr_utility.set_location('Inside process_balance context_rec.value'||context_rec.value,1870);
2520 					BEGIN
2521 						OPEN csr_get_sit_type_name(p_balance
2522 						,p_source_id
2523 						,p_effective_date
2524 						,context_rec.value);
2525 						FETCH csr_get_sit_type_name INTO l_si_type_name;
2526 						CLOSE csr_get_sit_type_name;
2527 					EXCEPTION
2528 						WHEN OTHERS THEN
2529 						hr_utility.set_location('Inside process_balance No Data Found',1870);
2530 						null;
2531 					END;
2532 					--
2533 					hr_utility.set_location('Inside process_balance l_balance_value'||l_balance_value,1880);
2534 					hr_utility.set_location('Inside process_balance l_si_type_name'||l_si_type_name,1880);
2535 
2536 					-- Archive EMEA BALANCE Context
2537 					--
2538 					--pay_action_information_api.create_action_information (..);
2539 					--
2540 					pay_action_information_api.create_action_information (
2541 					p_action_information_id        => l_action_info_id
2542 					,p_action_context_id            => p_action_context_id
2543 					,p_action_context_type          => 'AAP'
2544 					,p_object_version_number        => l_ovn
2545 					,p_assignment_id                => p_assignment_id
2546 					,p_effective_date               => p_effective_date
2547 					,p_source_id                    => p_source_id
2548 					,p_source_text                  => NULL
2549 					,p_action_information_category  => 'EMEA BALANCES'
2550 					,p_action_information1          =>p_defined_bal_id
2551 					,p_action_information2          =>context_rec.value
2552 					,p_action_information4          =>fnd_number.number_to_canonical(l_balance_value)
2553 					,p_action_information5          =>l_record_count
2554 					,p_action_information6          =>l_si_type_name);
2555 
2556             END IF;
2557             --
2558             --hr_utility.set_location('Inside process_balance l_action_info_id'||l_action_info_id,1900);
2559             END LOOP;
2560 			--
2561         ELSE
2562             --
2563             BEGIN
2564 				OPEN csr_get_context_id('SOURCE_TEXT');
2565 				FETCH csr_get_context_id INTO l_context_id;
2566 				CLOSE csr_get_context_id;
2567             EXCEPTION
2568 				WHEN OTHERS THEN
2569 				hr_utility.set_location('Inside process_balance No Data Found',1820);
2570 				null;
2571     	    END;
2572 
2573 			hr_utility.set_location('Inside process_balance l_context_id'||l_context_id,1840);
2574 
2575 			l_balance_value := pay_balance_pkg.get_value(p_defined_bal_id,p_source_id
2576 			,null,null,l_context_id,p_si_type
2577 			,null,null);
2578 			--
2579 
2580 			--hr_utility.set_location('Inside process_balance l_balance_value'||l_balance_value,1860);
2581 
2582             IF  l_balance_value <> 0 THEN
2583 				--
2584 				-- Retreive SI Type Name from run results
2585 				--
2586 				hr_utility.set_location('Inside process_balance p_balance'||p_balance,1870);
2587 				hr_utility.set_location('Inside process_balance p_source_id'||p_source_id,1870);
2588 				hr_utility.set_location('Inside process_balance p_effective_date'||p_effective_date,1870);
2589 				hr_utility.set_location('Inside process_balance p_si_type'||p_si_type,1870);
2590 				BEGIN
2591 					OPEN csr_get_sit_type_name(p_balance
2592 					,p_source_id
2593 					,p_effective_date
2594 					,p_si_type);
2595 					FETCH csr_get_sit_type_name INTO l_si_type_name;
2596 					CLOSE csr_get_sit_type_name;
2597                 EXCEPTION
2598 					WHEN OTHERS THEN
2599 					hr_utility.set_location('Inside process_balance No Data Found',1875);
2600 					null;
2601 				END;
2602 				--
2603 
2604 				hr_utility.set_location('Inside process_balance l_si_type_name'||l_si_type_name,1880);
2605 				hr_utility.set_location('Inside process_balance l_balance_value'||l_balance_value,1880);
2606 
2607 				-- Archive EMEA BALANCE Context
2608 				--
2609 				--pay_action_information_api.create_action_information (..);
2610 				pay_action_information_api.create_action_information (
2611 					p_action_information_id        => l_action_info_id
2612 					,p_action_context_id            => p_action_context_id
2613 					,p_action_context_type          => 'AAP'
2614 					,p_object_version_number        => l_ovn
2615 					,p_assignment_id                => p_assignment_id
2616 					,p_effective_date               => p_effective_date
2617 					,p_source_id                    => p_source_id
2618 					,p_source_text                  => NULL
2619 					,p_action_information_category  => 'EMEA BALANCES'
2620 					,p_action_information1          =>p_defined_bal_id
2621 					,p_action_information2          =>p_si_type
2622 					,p_action_information4          =>fnd_number.number_to_canonical(l_balance_value)
2623 					,p_action_information5          =>l_record_count
2624 					,p_action_information6          =>l_si_type_name);
2625 				hr_utility.set_location('Inside process_balance l_action_info_id'||l_action_info_id,1900);
2626 			END IF;
2627 		END IF;
2628 		--
2629     ELSE
2630 
2631 		hr_utility.set_location('Inside process_balance coming in else',1850);
2632 		--
2633 		hr_utility.set_location('Inside process_balance p_balance'||p_balance,1850);
2634 		hr_utility.set_location('Inside process_balance p_defined_bal_id'||p_defined_bal_id,1850);
2635 		hr_utility.set_location('Inside process_balance p_source_id'||p_source_id,1850);
2636 		BEGIN
2637 		l_balance_value := pay_balance_pkg.get_value(p_defined_bal_id
2638 		,p_source_id);
2639 		EXCEPTION
2640 		WHEN OTHERS THEN
2641 		hr_utility.set_location('Inside process_balance'||SQLCODE||SQLERRM,1849);
2642 		null;
2643 		END;
2644 		hr_utility.set_location('Inside process_balance l_balance_value'||l_balance_value,1850);
2645 
2646 		IF  l_balance_value <> 0 THEN
2647 			--
2648 			-- Archive EMEA BALANCE Context
2649 			--
2650 			--pay_action_information_api.create_action_information (..);
2651 			--
2652 			pay_action_information_api.create_action_information (
2653 			p_action_information_id        => l_action_info_id
2654 			,p_action_context_id            => p_action_context_id
2655 			,p_action_context_type          => 'AAP'
2656 			,p_object_version_number        => l_ovn
2657 			,p_assignment_id                => p_assignment_id
2658 			,p_effective_date               => p_effective_date
2659 			,p_source_id                    => p_source_id
2660 			,p_source_text                  => NULL
2661 			,p_action_information_category  => 'EMEA BALANCES'
2662 			,p_action_information1          =>p_defined_bal_id
2663 			,p_action_information2          =>p_si_type
2664 			,p_action_information4          =>fnd_number.number_to_canonical(l_balance_value)
2665 			,p_action_information5          =>l_record_count
2666 			,p_action_information6          =>l_si_type_name);
2667 
2668 			hr_utility.set_location('Inside process_balance l_action_info_id'||l_action_info_id,1900);
2669         END IF;
2670         --
2671     END IF;
2672     EXCEPTION
2673 		WHEN OTHERS THEN
2674 		hr_utility.set_location('Inside process_balance No Data Found',1900);
2675 		null;
2676 END process_balance;
2677 --
2678 
2679 --
2680 
2681 /*-------------------------------------------------------------------------------
2682 |Name           : ARCHIVE_ELEMENT_INFO     		        	       				|
2683 |Type			: Procedure														|
2684 |Description    : Procedure archives NL CALCULATIONS for statutory elements		|
2685 -------------------------------------------------------------------------------*/
2686 
2687 PROCEDURE archive_element_info(p_arch_assign_action_id IN NUMBER
2688 			,p_run_assign_action_id  IN NUMBER
2689 			,p_class_name            IN VARCHAR2
2690 			,p_element_name          IN VARCHAR2
2691 			,p_date_earned           IN DATE
2692 			,p_index                 IN NUMBER
2693 			,p_type                  IN VARCHAR2
2694 			,p_archive_flag	       IN VARCHAR2
2695 			,p_standard	       IN VARCHAR2
2696 			,p_special	       IN VARCHAR2
2697 			,p_standard2	       IN VARCHAR2
2698 			,p_special2	       IN VARCHAR2
2699 			,p_payable_flag	       IN VARCHAR2
2700 			,p_record_count          IN NUMBER
2701 			,p_master_assign_action_id 	IN NUMBER
2702 			,p_payroll_action_id       	IN NUMBER
2703 			,p_assignment_id           	IN NUMBER
2704 			,p_effective_date	      		IN DATE
2705 			,p_child_count			IN NUMBER) IS
2706 	--
2707 	CURSOR csr_defined_balance_id (p_balance_name VARCHAR2
2708 								  ,p_dimension    VARCHAR2
2709 								  ,p_bus_group_id NUMBER) IS
2710 	SELECT pdb.defined_balance_id   defined_balance_id
2711 	FROM   pay_balance_dimensions   pbd
2712 		  ,pay_balance_types        pbt
2713 		  ,pay_defined_balances     pdb
2714 	WHERE  pbd.database_item_suffix = p_dimension
2715 	AND    pbt.balance_name         = p_balance_name
2716 	AND    (pbt.business_group_id   = p_bus_group_id
2717 	OR      pbt.legislation_code    = 'NL')
2718 	AND    (pbd.business_group_id   = p_bus_group_id
2719 	OR      pbd.legislation_code    = 'NL')
2720 	AND    pdb.balance_type_id      = pbt.balance_type_id
2721 	AND    pdb.balance_dimension_id = pbd.balance_dimension_id
2722 	AND    (pdb.business_group_id   = p_bus_group_id
2723 	OR      pdb.legislation_code    = 'NL');
2724 	--
2725 	--
2726 
2727 	CURSOR csr_retro_values (p_run_assign_action_id NUMBER
2728 							,p_class_name           VARCHAR2
2729 							,p_element_name         VARCHAR2
2730 							,p_input_value_name     VARCHAR2
2731 							,p_date_earned          DATE
2732 							,p_retro_period	  DATE
2733 							,p_creator_type	  VARCHAR2) IS
2734 	SELECT prv.result_value                 value
2735 		  ,pet.element_type_id          element_type_id
2736 		  ,pet.element_name             element_name
2737 		  ,nvl(pettl.reporting_name,pettl.element_name) reporting_name
2738 		  ,pet.processing_priority      priority
2739 		  ,pet.business_group_id	business_group_id
2740 		  ,prv.run_result_id            run_result_id
2741 
2742 	FROM   pay_run_result_values        prv
2743 		  ,pay_run_results              prr
2744 		  ,pay_element_types_f          pet
2745 		  ,pay_element_types_f_tl       pettl
2746 		  ,pay_input_values_f           piv
2747 		  ,pay_element_classifications  pec
2748 		  ,pay_element_entries_f        pee
2749 	WHERE  prr.status                   IN ('P','PA')
2750 	AND    prr.source_id                 = pee.element_entry_id
2751 	AND    pee.CREATOR_TYPE              = p_creator_type
2752 	AND    prv.run_result_id            = prr.run_result_id
2753 	AND    prr.assignment_action_id     = p_run_assign_action_id
2754 	AND    prr.element_type_id          = pet.element_type_id
2755 	AND    prv.input_value_id           = piv.input_value_id
2756 	AND    piv.name                     = p_input_value_name
2757 	AND    pet.classification_id        = pec.classification_id
2758 	AND    pec.classification_name      = p_class_name
2759 	AND    pet.element_name             = NVL(p_element_name,pet.element_name)
2760 	AND    pec.legislation_code         = 'NL'
2761 	AND    pet.element_type_id          = pettl.element_type_id
2762 	AND    pettl.language               = USERENV('LANG')
2763 	AND    p_retro_period		    = nvl( prr.start_date /*pay_nl_general.get_retro_period(prr.source_id,p_date_earned)*/,p_retro_period) --Bug 5107780
2764 	AND    p_date_earned                BETWEEN pet.effective_start_date
2765 										AND     pet.effective_end_date
2766 	AND    p_date_earned                BETWEEN piv.effective_start_date
2767 										AND     piv.effective_end_date;
2768 
2769 	CURSOR csr_retro_element_periods (p_run_assign_action_id NUMBER
2770 							  ,p_class_name           VARCHAR2
2771 							  ,p_element_name         VARCHAR2
2772 							  ,p_input_value_name     VARCHAR2
2773 							  ,p_date_earned          DATE) IS
2774 	SELECT unique prr.start_date --(pay_nl_general.get_retro_period(prr.source_id,p_date_earned)) Bug 5107780
2775 	FROM   pay_run_result_values        prv
2776 		  ,pay_run_results              prr
2777 		  ,pay_element_types_f          pet
2778 		  ,pay_element_types_f_tl       pettl
2779 		  ,pay_input_values_f           piv
2780 		  ,pay_element_classifications  pec
2781 	WHERE  prr.status                   IN ('P','PA')
2782 	AND    prv.run_result_id            = prr.run_result_id
2783 	AND    prr.assignment_action_id     = p_run_assign_action_id
2784 	AND    prr.element_type_id          = pet.element_type_id
2785 	AND    prv.input_value_id           = piv.input_value_id
2786 	AND    piv.name                     = p_input_value_name
2787 	AND    pet.classification_id        = pec.classification_id
2788 	AND    pec.classification_name      = p_class_name
2789 	AND    pet.element_name             = NVL(p_element_name,pet.element_name)
2790 	AND    piv.element_type_id          = pet.element_type_id
2791 	AND    pec.legislation_code         = 'NL'
2792 	AND    pet.element_type_id          = pettl.element_type_id
2793 	AND    pettl.language               = USERENV('LANG')
2794 	AND    p_date_earned                BETWEEN pet.effective_start_date
2795 										AND     pet.effective_end_date
2796 	AND    p_date_earned                BETWEEN piv.effective_start_date
2797 										AND     piv.effective_end_date
2798 	ORDER BY  prr.start_date ; --pay_nl_general.get_retro_period(prr.source_id,p_date_earned); Bug 5107780
2799 
2800 	CURSOR csr_element_values (p_run_assign_action_id NUMBER
2801 							  ,p_class_name           VARCHAR2
2802 							  ,p_element_name         VARCHAR2
2803 							  ,p_input_value_name     VARCHAR2
2804 							  ,p_date_earned          DATE) IS
2805 	SELECT prv.result_value             value
2806 		  ,fnd_date.date_to_canonical( prr.start_date /*pay_nl_general.get_retro_period(prr.source_id,p_date_earned)*/ ) RDate
2807 		  ,pet.element_type_id          element_type_id
2808 		  ,pet.element_name             element_name
2809 		  ,nvl(pettl.reporting_name,pettl.element_name) reporting_name
2810 		  ,pet.processing_priority      priority
2811 		  ,pet.business_group_id	business_group_id
2812   		  ,prv.run_result_id            run_result_id   /* 4389520*/
2813 	FROM   pay_run_result_values            prv
2814 		  ,pay_run_results              prr
2815 		  ,pay_element_types_f          pet
2816 		  ,pay_element_types_f_tl       pettl
2817 		  ,pay_input_values_f           piv
2818 		  ,pay_element_classifications  pec
2819 	WHERE  prr.status                   IN ('P','PA')
2820 	AND    prv.run_result_id            = prr.run_result_id
2821 	AND    prr.assignment_action_id     = p_run_assign_action_id
2822 	AND    prr.element_type_id          = pet.element_type_id
2823 	AND    prv.input_value_id           = piv.input_value_id
2824 	AND    piv.name                     = p_input_value_name
2825 	AND    pet.classification_id        = pec.classification_id
2826 	AND    pec.classification_name      = p_class_name
2827 	AND    pet.element_name             = NVL(p_element_name,pet.element_name)
2828 	AND    pec.legislation_code         = 'NL'
2829 	AND    pet.element_type_id          = pettl.element_type_id
2830 	AND    pet.element_type_id          = piv.element_type_id
2831 	AND    pettl.language               = USERENV('LANG')
2832 	AND    p_date_earned                BETWEEN pet.effective_start_date
2833 										AND     pet.effective_end_date
2834 	AND    p_date_earned                BETWEEN piv.effective_start_date
2835 										AND     piv.effective_end_date
2836 ORDER BY pet.element_name,prr.start_date            ;
2837 
2838 
2839 	--
2840 	CURSOR csr_sec_classification (p_element_type_id      NUMBER
2841 								  ,p_sub_class_name       VARCHAR2
2842 								  ,p_date_earned          DATE) IS
2843 	SELECT 1
2844 	FROM   pay_sub_classification_rules_f   pscf
2845 		  ,pay_element_classifications      pec
2846 	WHERE  pscf.element_type_id             = p_element_type_id
2847 	AND    pscf.classification_id           = pec.classification_id
2848 	AND    pec.classification_name          = p_sub_class_name
2849 	AND    pec.legislation_code             = 'NL'
2850 	AND    p_date_earned                    BETWEEN pscf.effective_start_date
2851 											AND     pscf.effective_end_date;
2852 	--
2853 
2854 	--6359807
2855 	CURSOR csr_sec_classification_psi_ptx (p_element_type_id      NUMBER
2856 						,p_date_earned          DATE) IS
2857 	SELECT pec.classification_name
2858 	FROM   pay_sub_classification_rules_f   pscf
2859 		 ,pay_element_classifications      pec
2860 	WHERE  pscf.element_type_id             = p_element_type_id
2861 	AND    pscf.classification_id           = pec.classification_id
2862 	AND    pec.classification_name
2863 	IN
2864 	('Pension Standard Tax : Pre-SI and Pre-Tax Deductions'
2865 	,'Pension Special Tax : Pre-SI and Pre-Tax Deductions'
2866 	,'Pension Standard Tax : Retro Pre SI Pre Tax Deductions'
2867 	,'Pension Special Tax : Retro Pre SI Pre Tax Deductions'
2868 	)
2869 	AND    pec.legislation_code             = 'NL'
2870 	AND    p_date_earned                    BETWEEN pscf.effective_start_date
2871 							    AND     pscf.effective_end_date;
2872 
2873 	l_classification_name pay_element_classifications.classification_name%TYPE;
2874 	--6359807
2875 
2876 	--
2877 	CURSOR csr_add_element_values (p_run_assign_action_id NUMBER
2878 								  ,p_class_name           VARCHAR2
2879 								  ,p_element_name         VARCHAR2
2880 								  ,p_input_value_name     VARCHAR2
2881 								  ,p_date_earned          DATE) IS
2882 	SELECT prv.result_value             value
2883 	FROM   pay_run_result_values        prv
2884 		  ,pay_run_results              prr
2885 		  ,pay_element_types_f          pet
2886 		  ,pay_input_values_f           piv
2887 		  ,pay_element_classifications  pec
2888 	WHERE  prr.status                   IN ('P','PA')
2889 	AND    prv.run_result_id            = prr.run_result_id
2890 	AND    prr.assignment_action_id     = p_run_assign_action_id
2891 	AND    prr.element_type_id          = pet.element_type_id
2892 	AND    prv.input_value_id           = piv.input_value_id
2893 	AND    piv.name                     = p_input_value_name
2894 	AND    pet.classification_id        = pec.classification_id
2895 	AND    pec.classification_name      = p_class_name
2896 	AND    pet.element_name             = NVL(p_element_name,pet.element_name)
2897 	AND    pet.element_type_id          = piv.element_type_id
2898 	AND    pec.legislation_code         = 'NL'
2899 	AND    p_date_earned                BETWEEN pet.effective_start_date
2900 										AND     pet.effective_end_date
2901 	AND    p_date_earned                BETWEEN piv.effective_start_date
2902 										AND     piv.effective_end_date;
2903 
2904 	--
2905 	-- Cursor to retrieve all N (Normal)and P (Process separate) Child Actions
2906 	-- for a given assignment action.
2907 	--
2908 	CURSOR csr_np_children (p_assignment_action_id NUMBER
2909 				   ,p_payroll_action_id    NUMBER
2910 				   ,p_assignment_id        NUMBER
2911 				   ,p_effective_date       DATE) IS
2912 	SELECT paa.assignment_action_id np_assignment_action_id
2913 	FROM   pay_assignment_actions   paa
2914 		  ,pay_run_types_f          prt
2915 	WHERE  paa.source_action_id     = p_assignment_action_id
2916 	AND    paa.payroll_action_id    = p_payroll_action_id
2917 	AND    paa.assignment_id        = p_assignment_id
2918 	AND    paa.run_type_id          = prt.run_type_id
2919 	AND    prt.run_method           IN ('N','P')
2920 	AND    p_effective_date         BETWEEN prt.effective_start_date
2921 						AND     prt.effective_end_date;
2922 
2923                          --Bug 7031784
2924    	CURSOR csr_chk_corr_feeds (p_element_type_id NUMBER) IS
2925    	SELECT pbt.balance_name
2926    	FROM pay_balance_types pbt,
2927         	            pay_balance_feeds_f pbf,
2928         	           pay_input_values_f piv
2929    	WHERE pbf.balance_type_id = pbt.balance_type_id
2930    	AND piv.input_value_id = pbf.input_value_id
2931    	AND piv.element_type_id = p_element_type_id
2932   	 AND piv.name = 'Pay Value'
2933   	 AND pbt.balance_name like '%Tax Correction'
2934   	 AND p_effective_date BETWEEN pbf.effective_start_date AND pbf.effective_end_date;
2935 
2936 
2937 	l_temp			NUMBER;
2938 	l_action_info_id	NUMBER;
2939 	l_ovn			NUMBER;
2940 	l_standard_rate		varchar2(255);
2941 	l_special_rate		varchar2(255);
2942 	l_payable		varchar2(255);
2943 	l_defined_balance_id	NUMBER;
2944 	l_rate			NUMBER;
2945 	l_index			NUMBER;
2946 	l_temp_index  NUMBER;
2947 	l_travel_flag   NUMBER;
2948 	l_retro_travel_flag   NUMBER;
2949 	l_pecentage_rate	pay_run_result_values.result_value%TYPE;
2950 	l_sum_standard_rate	varchar2(255);
2951 	l_sum_special_rate 	varchar2(255);
2952 	l_sum_payable  		varchar2(255);
2953 	l_date			varchar2(60);
2954 	l_priority		NUMBER;
2955 	l_reporting_name	pay_element_types.element_name%TYPE;
2956 	type element_retro_entries is table of DATE index by binary_integer;
2957 	l_element_retro_entries element_retro_entries;
2958 	type creator_type is table of varchar2(2) index by binary_integer;
2959 	l_creator_type creator_type;
2960 	l_element_type_id      pay_element_types_f.element_type_id%TYPE;
2961 	l_run_result_id        pay_run_results.run_result_id%TYPE;
2962 	l_corr_bal_name pay_balance_types.balance_name%TYPE;
2963 
2964 BEGIN
2965 
2966 --
2967 l_index:=p_index;
2968 l_temp_index := l_index;
2969 IF p_element_name IS NULL THEN
2970 
2971 FOR element_value_rec IN csr_element_values(p_run_assign_action_id
2972                                            ,p_class_name
2973                                            ,p_element_name
2974                                            ,'Pay Value'
2975                                            ,p_date_earned) LOOP
2976 l_travel_flag := 0;
2977 l_retro_travel_flag := 0;
2978 OPEN csr_sec_classification(element_value_rec.element_type_id
2979                                ,'Travel Allowance : Earnings'
2980                                ,p_date_earned);
2981 FETCH csr_sec_classification INTO l_travel_flag;
2982 CLOSE csr_sec_classification;
2983 
2984 OPEN csr_sec_classification(element_value_rec.element_type_id
2985                                ,'Travel Allowance : Retro Earnings'
2986                                ,p_date_earned);
2987 FETCH csr_sec_classification INTO l_retro_travel_flag;
2988 CLOSE csr_sec_classification;
2989 
2990 IF element_value_rec.element_name <> 'Employer ZVW Contribution Special Tax' AND
2991        element_value_rec.element_name <> 'Employer ZVW Contribution Standard Tax' AND
2992        element_value_rec.element_name <> 'Retro Employer ZVW Contribution Special Tax' AND
2993        element_value_rec.element_name <> 'Retro Employer ZVW Contribution Standard Tax' AND
2994        element_value_rec.element_name <> 'Standard Tax Deduction' AND
2995        element_value_rec.element_name <> 'Special Tax Deduction' AND
2996        element_value_rec.element_name <> 'Beneficial Rule Special Tax Adjustment' THEN
2997 
2998     --
2999      IF p_standard IS NOT NULL THEN
3000     OPEN csr_sec_classification(element_value_rec.element_type_id
3001                                ,p_standard
3002                                ,p_date_earned);
3003         FETCH csr_sec_classification INTO l_temp;
3004         IF  csr_sec_classification%FOUND THEN
3005             l_standard_rate := element_value_rec.value;
3006         ELSE
3007             l_standard_rate :=NULL;
3008         END IF;
3009     CLOSE csr_sec_classification;
3010     END IF;
3011 
3012     IF p_standard2 IS NOT NULL AND l_standard_rate is NULL THEN
3013     OPEN csr_sec_classification(element_value_rec.element_type_id
3014                                ,p_standard2
3015                                ,p_date_earned);
3016         FETCH csr_sec_classification INTO l_temp;
3017         IF  csr_sec_classification%FOUND THEN
3018             l_standard_rate := element_value_rec.value;
3019             IF p_class_name = 'Imputed Earnings' THEN
3020              l_index := 15800;
3021             END IF;
3022             IF p_class_name = 'Retro Imputed Earnings' THEN
3023              l_index := 15900;
3024             END IF;
3025         ELSE
3026             l_standard_rate :=NULL;
3027         END IF;
3028     CLOSE csr_sec_classification;
3029     END IF;
3030 
3031     IF p_special IS NOT NULL THEN
3032     OPEN csr_sec_classification(element_value_rec.element_type_id
3033                                ,p_special
3034                                ,p_date_earned);
3035         FETCH csr_sec_classification INTO l_temp;
3036         IF  csr_sec_classification%FOUND THEN
3037             l_special_rate := element_value_rec.value;
3038         ELSE
3039             l_special_rate :=NULL;
3040         END IF;
3041     CLOSE csr_sec_classification;
3042     --
3043     END IF;
3044 
3045     IF p_special2 IS NOT NULL AND l_special_rate IS NULL THEN
3046     OPEN csr_sec_classification(element_value_rec.element_type_id
3047                                ,p_special2
3048                                ,p_date_earned);
3049         FETCH csr_sec_classification INTO l_temp;
3050         IF  csr_sec_classification%FOUND THEN
3051             l_special_rate := element_value_rec.value;
3052             IF p_class_name = 'Imputed Earnings' THEN
3053              l_index := 15800;
3054             END IF;
3055             IF p_class_name = 'Retro Imputed Earnings' THEN
3056              l_index := 15900;
3057             END IF;
3058         ELSE
3059             l_special_rate :=NULL;
3060         END IF;
3061     CLOSE csr_sec_classification;
3062     --
3063     END IF;
3064 
3065 --6359807
3066     OPEN csr_sec_classification_psi_ptx(element_value_rec.element_type_id
3067                                ,p_date_earned);
3068         FETCH csr_sec_classification_psi_ptx INTO l_classification_name;
3069 	  IF  csr_sec_classification_psi_ptx%FOUND THEN
3070             IF l_classification_name like '%Standard%' THEN
3071 		  l_standard_rate := element_value_rec.value;
3072 		ELSIF l_classification_name like '%Special%' THEN
3073 		  l_special_rate := element_value_rec.value;
3074 		END IF;
3075         ELSE
3076             IF l_classification_name like '%Standard%' THEN
3077 		  l_standard_rate := NULL;
3078 		ELSIF l_classification_name like '%Special%' THEN
3079 		  l_special_rate := NULL;
3080 		END IF;
3081         END IF;
3082     CLOSE csr_sec_classification_psi_ptx;
3083 --6359807
3084 
3085     IF p_payable_flag='Y' THEN
3086         l_payable := element_value_rec.value;
3087 	l_element_type_id := element_value_rec.element_type_id ;
3088         l_run_result_id := element_value_rec.run_result_id;
3089     END IF;
3090 
3091     IF l_travel_flag = 1 THEN
3092       l_temp_index := l_index;
3093       l_index := 28500;
3094     END IF;
3095     IF l_retro_travel_flag = 1 THEN
3096       l_temp_index := l_index;
3097       l_index := 29000;
3098     END IF;
3099 
3100     hr_utility.set_location('Inside archive_payslip_element_info1 element_name'||element_value_rec.element_name,2120);
3101     hr_utility.set_location('Inside archive_payslip_element_info1 l_defined_balance_id'||l_defined_balance_id,2120);
3102     hr_utility.set_location('Inside archive_payslip_element_info1 business_group_id'||element_value_rec.business_group_id,2120);
3103 
3104     IF l_travel_flag = 1 THEN
3105       OPEN csr_defined_balance_id('Tax Travel Allowance','_ASG_YTD',0);
3106       FETCH csr_defined_balance_id INTO l_defined_balance_id;
3107       IF csr_defined_balance_id%NOTFOUND then
3108         l_defined_balance_id := NULL;
3109       END IF;
3110       CLOSE csr_defined_balance_id;
3111     ELSIF l_retro_travel_flag = 1 THEN
3112       OPEN csr_defined_balance_id('Retro Tax Travel Allowance','_ASG_YTD',0);
3113       FETCH csr_defined_balance_id INTO l_defined_balance_id;
3114       IF csr_defined_balance_id%NOTFOUND then
3115         l_defined_balance_id := NULL;
3116       END IF;
3117       CLOSE csr_defined_balance_id;
3118     ELSE
3119       OPEN csr_defined_balance_id(element_value_rec.element_name,'_ASG_YTD',element_value_rec.business_group_id);
3120       FETCH csr_defined_balance_id INTO l_defined_balance_id;
3121       IF csr_defined_balance_id%NOTFOUND then
3122         l_defined_balance_id := NULL;
3123       END IF;
3124       CLOSE csr_defined_balance_id;
3125     END IF;
3126 
3127 --5957039
3128    IF p_class_name = 'Pre-Tax ZVW Refund'
3129    THEN
3130       OPEN csr_defined_balance_id('ZVW Refund','_ASG_YTD',element_value_rec.business_group_id);
3131       FETCH csr_defined_balance_id INTO l_defined_balance_id;
3132       IF csr_defined_balance_id%NOTFOUND then
3133         l_defined_balance_id := NULL;
3134       END IF;
3135       CLOSE csr_defined_balance_id;
3136    ELSIF p_class_name = 'Retro Pre-Tax ZVW Refund'
3137    THEN
3138 	OPEN csr_defined_balance_id('Retro ZVW Refund','_ASG_YTD',element_value_rec.business_group_id);
3139 	FETCH csr_defined_balance_id INTO l_defined_balance_id;
3140 	if csr_defined_balance_id%NOTFOUND then
3141 	     l_defined_balance_id := NULL;
3142 	end if;
3143 	CLOSE csr_defined_balance_id;
3144 --7031784
3145    ELSIF p_class_name = 'Employee Tax'
3146    THEN
3147     OPEN csr_chk_corr_feeds (element_value_rec.element_type_id);
3148     FETCH csr_chk_corr_feeds INTO l_corr_bal_name;
3149     IF csr_chk_corr_feeds%FOUND THEN
3150       OPEN csr_defined_balance_id(l_corr_bal_name,'_ASG_YTD',element_value_rec.business_group_id);
3151 	  FETCH csr_defined_balance_id INTO l_defined_balance_id;
3152 	  if csr_defined_balance_id%NOTFOUND then
3153 	     l_defined_balance_id := NULL;
3154 	  end if;
3155 	  CLOSE csr_defined_balance_id;
3156 	END IF;
3157 	CLOSE csr_chk_corr_feeds;
3158 --7031784
3159   END IF;
3160 --5957039
3161 
3162       hr_utility.set_location('Inside archive_payslip_element_info1 l_rate'||l_rate,2121);
3163       hr_utility.set_location('Inside archive_payslip_element_info1 l_defined_balance_id'||l_defined_balance_id,2121);
3164       hr_utility.set_location('Inside archive_payslip_element_info1 p_run_assign_action_id'||p_run_assign_action_id,2121);
3165 
3166       IF  l_defined_balance_id IS NOT NULL THEN
3167         l_rate := pay_balance_pkg.get_value(l_defined_balance_id
3168                                            ,p_run_assign_action_id);
3169       ELSE
3170         l_rate :=NULL;
3171       END IF;
3172 
3173     --
3174     --FND_FILE.PUT_LINE(FND_FILE.LOG, 'archive_element_info l_rate'||' '||l_rate);
3175     hr_utility.set_location('Inside archive_payslip_element_info1 l_rate'||l_rate,2122);
3176     --
3177     -- Special Tax Deduction Elemetns requires Pay Value and Percentage
3178     -- Rate to be archived.
3179     IF  p_element_name = 'Special Tax Deduction' THEN
3180         --
3181         -- Get Individual Percentage Value
3182         --
3183         OPEN csr_add_element_values(p_run_assign_action_id
3184                                    ,p_class_name
3185                                    ,p_element_name
3186                                    ,'Percentage Rate'
3187                                    ,p_date_earned);
3188 	FETCH csr_add_element_values INTO l_pecentage_rate;
3189         CLOSE csr_add_element_values;
3190         --
3191 	IF l_pecentage_rate IS NOT NULL THEN
3192 	l_pecentage_rate:=l_pecentage_rate||'%';
3193 	END IF;
3194     END IF;
3195     --
3196     hr_utility.set_location('Inside archive_payslip_element_info1 l_rate'||l_rate,2123);
3197     IF p_archive_flag = 'Y' OR(FND_NUMBER.canonical_to_number(l_standard_rate) is not null
3198     			    OR FND_NUMBER.canonical_to_number(l_special_rate) is not null
3199     			    OR FND_NUMBER.canonical_to_number(l_payable)  is not null
3200     			    OR l_rate is not null) THEN
3201     -- Archive NL CALCULATIONS
3202     --
3203     --pay_action_information_api.create_action_information (..);
3204     --
3205 
3206 --5957039
3207 IF  p_class_name IN ('Pre-Tax ZVW Refund', 'Retro Pre-Tax ZVW Refund')
3208 AND l_index BETWEEN 18720 AND 19000
3209 THEN
3210 	l_payable := -l_payable;
3211 	l_rate := -l_rate;
3212 END IF;
3213 --5957039
3214 
3215     	 pay_action_information_api.create_action_information (
3216     	  p_action_information_id        => l_action_info_id
3217     	 ,p_action_context_id            => p_arch_assign_action_id
3218     	 ,p_action_context_type          => 'AAP'
3219     	 ,p_object_version_number        => l_ovn
3220     	 ,p_effective_date               => p_date_earned
3221     	 ,p_source_id                    => NULL
3222     	 ,p_source_text                  => NULL
3223     	 ,p_action_information_category  => 'NL CALCULATIONS'
3224     	 ,p_action_information4          =>l_index
3225     	 ,p_action_information5          =>element_value_rec.priority
3226     	 ,p_action_information6          =>element_value_rec.reporting_name
3227     	 ,p_action_information7          =>l_pecentage_rate
3228     	 ,p_action_information8          =>p_type
3229     	 ,p_action_information9          =>element_value_rec.RDate  --Retro Period
3230     	 ,p_action_information10         =>l_standard_rate
3231     	 ,p_action_information11         =>l_special_rate
3232     	 ,p_action_information12         =>l_payable
3233     	 ,p_action_information13         =>fnd_number.number_to_canonical(l_rate)
3234          ,p_action_information16         =>l_element_type_id            /* 4389520*/
3235          ,p_action_information17         =>l_run_result_id         );
3236 
3237 
3238           IF l_travel_flag = 1 THEN
3239 		          g_travel_allowance := FND_NUMBER.canonical_to_number(l_payable);
3240 		          g_travel_allowance_ytd := l_rate;
3241     	  END IF;
3242           IF l_retro_travel_flag = 1 THEN
3243 		          g_retro_travel_allowance := FND_NUMBER.canonical_to_number(l_payable);
3244 		          g_retro_travel_allowance_ytd := l_rate;
3245     	  END IF;
3246 
3247     l_index := l_temp_index;
3248 	l_index := l_index + 1;
3249 
3250 	END IF;
3251 
3252 END IF;
3253 END LOOP;
3254 --
3255 hr_utility.set_location('Inside archive_payslip_element_info1 element_name'||p_element_name,2120);
3256 
3257 ELSIF p_element_name like 'Retro%' THEN
3258 
3259 --FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_element_name'||' '||p_element_name);
3260 --FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_child_count'||' '||p_child_count);
3261 
3262 IF p_child_count=0 THEN
3263 
3264 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 p_run_assign_action_id'||p_run_assign_action_id,2121);
3265 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 p_class_name'||p_class_name,2121);
3266 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 p_element_name'||p_element_name,2121);
3267 
3268 	 l_creator_type(0):='EE';
3269 	 l_creator_type(1):='RR';
3270 	 l_creator_type(2):='PR';
3271 	 l_creator_type(3):='NR';
3272 
3273 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_run_assign_action_id'||' '||p_run_assign_action_id);
3274 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_class_name'||' '||p_class_name);
3275 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_element_name'||' '||p_element_name);
3276 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_date_earned'||' '||p_date_earned);
3277 
3278 	 OPEN csr_retro_element_periods(p_run_assign_action_id
3279 		                 ,p_class_name
3280 		                 ,p_element_name
3281 		                 ,'Pay Value'
3282                                  ,p_date_earned);
3283 	  FETCH csr_retro_element_periods bulk collect into l_element_retro_entries;
3284 	  CLOSE csr_retro_element_periods;
3285 
3286 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'count'||' '||l_element_retro_entries.count);
3287 
3288 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 count'||l_element_retro_entries.count,2122);
3289 
3290 	IF l_element_retro_entries.count > 0 THEN
3291 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'count'||' '||l_element_retro_entries.count);
3292 
3293 	FOR i in l_element_retro_entries.first..l_element_retro_entries.last  LOOP
3294 
3295 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 retro_date'||l_element_retro_entries(i),2123);
3296 
3297 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries(i)'||' '||l_element_retro_entries(i));
3298 	FOR j in l_creator_type.first..l_creator_type.last LOOP
3299 	l_sum_standard_rate	:='0';
3300 	l_sum_special_rate 	:='0';
3301 	l_sum_payable  		:='0';
3302 	l_rate			:=NULL;
3303 
3304 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 l_sum_standard_rate'||l_sum_standard_rate,2124);
3305 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 l_sum_special_rate'||l_sum_special_rate,2124);
3306 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 l_sum_payable'||l_sum_payable,2124);
3307 
3308 	FOR csr_np_rec IN csr_np_children(
3309 				    p_master_assign_action_id,
3310 				    p_payroll_action_id,
3311 				    p_assignment_id,
3312 			    	    p_effective_date) LOOP
3313 
3314 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 '||csr_np_rec.np_assignment_action_id,2124);
3315 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 l_sum_payable'||l_sum_payable,2124);
3316 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'csr_np_rec.np_assignment_action_id'||' '||csr_np_rec.np_assignment_action_id);
3317 
3318 	FOR retro_element_value_rec IN csr_retro_values(csr_np_rec.np_assignment_action_id
3319 	                                           ,p_class_name
3320 	                                           ,p_element_name
3321 	                                           ,'Pay Value'
3322                                            	   ,p_date_earned
3323                                            	   ,l_element_retro_entries(i)
3324 						   ,l_creator_type(j)) LOOP
3325 
3326 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'retro_element_value_rec.value'||' '||retro_element_value_rec.value);
3327 
3328 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 element_name'||retro_element_value_rec.value,2125);
3329 	l_standard_rate:='0';
3330 	l_special_rate:='0';
3331 	l_payable:='0';
3332 
3333 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_standard'||' '||p_standard);
3334 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 l_sum_payable'||l_sum_payable,2126);
3335 	IF p_standard IS NOT NULL THEN
3336 	    OPEN csr_sec_classification(retro_element_value_rec.element_type_id
3337 	                               ,p_standard
3338 	                               ,p_date_earned);
3339 	        FETCH csr_sec_classification INTO l_temp;
3340 	        IF  csr_sec_classification%FOUND THEN
3341 	            l_standard_rate := retro_element_value_rec.value;
3342 	            l_sum_standard_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_standard_rate) + FND_NUMBER.canonical_to_number(l_standard_rate));
3343 	        ELSE
3344 	            l_standard_rate :=NULL;
3345 	        END IF;
3346 	    CLOSE csr_sec_classification;
3347 	    END IF;
3348 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_special'||' '||p_special);
3349 
3350 	    IF p_special IS NOT NULL THEN
3351 	    OPEN csr_sec_classification(retro_element_value_rec.element_type_id
3352 	                               ,p_special
3353 	                               ,p_date_earned);
3354 	        FETCH csr_sec_classification INTO l_temp;
3355 	        IF  csr_sec_classification%FOUND THEN
3356 	            l_special_rate := retro_element_value_rec.value;
3357 	            l_sum_special_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_special_rate) + FND_NUMBER.canonical_to_number(l_special_rate));
3358 	        ELSE
3359 	            l_special_rate :=NULL;
3360 	        END IF;
3361 	    CLOSE csr_sec_classification;
3362 	    --
3363 	hr_utility.set_location('Retro Inside archive_payslip_element_info1 l_sum_payable'||l_sum_payable,2126);
3364 	    END IF;
3365 
3366 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_payable_flag'||' '||p_payable_flag);
3367 
3368 	    hr_utility.set_location('Retro Inside archive_payslip_element_info2 p_payable_flag'||p_payable_flag,2120);
3369 
3370 	    IF p_payable_flag='Y' THEN
3371 		l_payable := retro_element_value_rec.value;
3372 		hr_utility.set_location('Retro Inside archive_payslip_element_info2 l_payable'||l_payable,2120);
3373 		hr_utility.set_location('Retro Inside archive_payslip_element_info2 l_sum_payable'||l_sum_payable,2120);
3374 	        l_sum_payable:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_payable) + FND_NUMBER.canonical_to_number(l_payable));
3375 	        hr_utility.set_location('Retro Inside archive_payslip_element_info2 l_sum_payable'||l_sum_payable,2120);
3376 	    END IF;
3377 
3378 
3379 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
3380 
3381 	    OPEN csr_defined_balance_id(retro_element_value_rec.element_name,'_ASG_YTD',retro_element_value_rec.business_group_id);
3382 	    FETCH csr_defined_balance_id INTO l_defined_balance_id;
3383 	    if csr_defined_balance_id%NOTFOUND then
3384 	           l_defined_balance_id := NULL;
3385             end if;
3386 	    CLOSE csr_defined_balance_id;
3387 
3388 --5957039
3389 	   IF p_class_name = 'Retro Pre-Tax ZVW Refund'
3390 	   THEN
3391 		OPEN csr_defined_balance_id('Retro ZVW Refund','_ASG_YTD',retro_element_value_rec.business_group_id);
3392 		FETCH csr_defined_balance_id INTO l_defined_balance_id;
3393 		IF csr_defined_balance_id%NOTFOUND then
3394 		  l_defined_balance_id := NULL;
3395 		END IF;
3396 		CLOSE csr_defined_balance_id;
3397 	   END IF;
3398 --5957039
3399 
3400     	    	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_defined_balance_id'||' '||l_defined_balance_id);
3401 	    IF  l_defined_balance_id IS NOT NULL THEN
3402 	        l_rate := pay_balance_pkg.get_value(l_defined_balance_id
3403 	                                           ,csr_np_rec.np_assignment_action_id);
3404 	    ELSE
3405 	        l_rate :=NULL;
3406 	    END IF;
3407 	    --
3408 	    --FND_FILE.PUT_LINE(FND_FILE.LOG, 'archive element info 1 l_rate'||' '||l_rate);
3409 	    hr_utility.set_location('Retro Inside archive_payslip_element_info2 l_rate'||l_rate,2122);
3410 	    --
3411 	    -- Special Tax Deduction Elemetns requires Pay Value and Percentage
3412 	    -- Rate to be archived.
3413 	    IF  p_element_name = 'Retro Special Tax Deduction' THEN
3414 	        --
3415 	        -- Get Individual Percentage Value
3416 	        --
3417 	        OPEN csr_add_element_values(csr_np_rec.np_assignment_action_id
3418 	                                   ,p_class_name
3419 	                                   ,p_element_name
3420 	                                   ,'Percentage Rate'
3421 	                                   ,p_date_earned);
3422 		FETCH csr_add_element_values INTO l_pecentage_rate;
3423 	        CLOSE csr_add_element_values;
3424 	        --
3425    	    	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_pecentage_rate'||' '||l_pecentage_rate);
3426 
3427 		IF l_pecentage_rate IS NOT NULL THEN
3428 		l_pecentage_rate:=l_pecentage_rate||'%';
3429 		END IF;
3430 	    END IF;
3431 
3432             --FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_pecentage_rate'||' '||l_pecentage_rate);
3433 
3434 	    l_priority:=retro_element_value_rec.priority;
3435 	    l_reporting_name:=retro_element_value_rec.reporting_name;
3436 
3437 	    l_date:=fnd_date.date_to_canonical(l_element_retro_entries(i));
3438 
3439 	    --
3440 	    END LOOP;
3441 
3442 	 --FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_pecentage_rate'||' '||l_pecentage_rate);
3443   	END LOOP;
3444 
3445   	IF FND_NUMBER.canonical_to_number(l_sum_standard_rate)=0 THEN
3446   	l_sum_standard_rate:=NULL;
3447   	END IF;
3448 
3449   	IF FND_NUMBER.canonical_to_number(l_sum_special_rate)=0 THEN
3450   	l_sum_special_rate:=NULL;
3451   	END IF;
3452 
3453   	IF FND_NUMBER.canonical_to_number(l_sum_payable)=0 THEN
3454   	l_sum_payable:=NULL;
3455   	END IF;
3456         hr_utility.set_location('Retro Inside archive_payslip_element_info2 l_rate'||l_rate,2123);
3457   	hr_utility.set_location('Retro Inside archive_payslip_element_info2 l_sum_payable'||l_sum_payable,2123);
3458 
3459 	    IF p_archive_flag = 'Y' OR(FND_NUMBER.canonical_to_number(l_sum_standard_rate) is not null
3460 	    			    OR FND_NUMBER.canonical_to_number(l_sum_special_rate) is not null
3461 	    			    OR FND_NUMBER.canonical_to_number(l_sum_payable)  is not null
3462 	    			    OR l_rate is not null) THEN
3463 	    -- Archive NL CALCULATIONS
3464 	    --
3465 	    --pay_action_information_api.create_action_information (..);
3466 	    --
3467 --5957039
3468 IF	p_class_name IN ('Pre-Tax ZVW Refund', 'Retro Pre-Tax ZVW Refund')
3469 	AND l_index BETWEEN 18720 AND 19000
3470 THEN
3471 	l_sum_payable := -l_sum_payable;
3472 	l_rate := -l_rate;
3473 END IF;
3474 --5957039
3475 	    	 pay_action_information_api.create_action_information (
3476 	    	  p_action_information_id        => l_action_info_id
3477 	    	 ,p_action_context_id            => p_arch_assign_action_id
3478 	    	 ,p_action_context_type          => 'AAP'
3479 	    	 ,p_object_version_number        => l_ovn
3480 	    	 ,p_effective_date               => p_date_earned
3481 	    	 ,p_source_id                    => NULL
3482 	    	 ,p_source_text                  => NULL
3483 	    	 ,p_action_information_category  => 'NL CALCULATIONS'
3484 	    	 ,p_action_information4          =>l_index
3485 	    	 ,p_action_information5          =>l_priority
3486 	    	 ,p_action_information6          =>l_reporting_name
3487 	    	 ,p_action_information7          =>l_pecentage_rate
3488 	    	 ,p_action_information8          =>p_type
3489 	    	 ,p_action_information9          =>l_date   --Retro Period
3490 	    	 ,p_action_information10         =>l_sum_standard_rate
3491 	    	 ,p_action_information11         =>l_sum_special_rate
3492 	    	 ,p_action_information12         =>l_sum_payable
3493 	    	 ,p_action_information13         =>fnd_number.number_to_canonical(l_rate)
3494                  ,p_action_information16         =>l_element_type_id
3495 		 ,p_action_information17         =>l_run_result_id
3496              );
3497 
3498 
3499 		IF p_element_name = 'Retro Employer ZVW Contribution Standard Tax' THEN
3500 		          g_retro_zvw_er_cont_std_run  := FND_NUMBER.canonical_to_number(l_sum_standard_rate);
3501 		          g_retro_zvw_er_cont_std_ytd  := l_rate;
3502              		END IF;
3503              		IF p_element_name = 'Retro Employer ZVW Contribution Special Tax' THEN
3504 		          g_retro_zvw_er_cont_spl_run  := FND_NUMBER.canonical_to_number(l_sum_special_rate);
3505 		          g_retro_zvw_er_cont_spl_ytd  := l_rate;
3506              		END IF;
3507 
3508 		l_index := l_index + 1;
3509 
3510 		END IF;
3511         END LOOP;
3512 	END LOOP;
3513      END IF;
3514 END IF;
3515 
3516 ELSE
3517 	IF p_child_count=0 THEN
3518 
3519 	l_sum_standard_rate	:='0';
3520 	l_sum_special_rate 	:='0';
3521 	l_sum_payable  		:='0';
3522 
3523 	FOR csr_np_rec IN csr_np_children(
3524 				    p_master_assign_action_id,
3525 				    p_payroll_action_id,
3526 				    p_assignment_id,
3527 			    	    p_effective_date) LOOP
3528 	--hr_utility.set_location('Inside archive_payslip_element_info2 np_assignment_action_id'||csr_np_rec.np_assignment_action_id,2120);
3529 	--hr_utility.set_location('Inside archive_payslip_element_info2 p_class_name'||p_class_name,2120);
3530 	--hr_utility.set_location('Inside archive_payslip_element_info2 p_element_name'||p_element_name,2120);
3531 	--hr_utility.set_location('Inside archive_payslip_element_info2 p_date_earned'||p_date_earned,2120);
3532 
3533 	FOR element_value_rec IN csr_element_values(csr_np_rec.np_assignment_action_id
3534 	                                           ,p_class_name
3535 	                                           ,p_element_name
3536 	                                           ,'Pay Value'
3537                                            	   ,p_date_earned) LOOP
3538 
3539 
3540 	IF p_standard IS NOT NULL THEN
3541 	    OPEN csr_sec_classification(element_value_rec.element_type_id
3542 	                               ,p_standard
3543 	                               ,p_date_earned);
3544 	        FETCH csr_sec_classification INTO l_temp;
3545 	        IF  csr_sec_classification%FOUND THEN
3546 	            l_standard_rate := element_value_rec.value;
3547 	            l_sum_standard_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_standard_rate) + FND_NUMBER.canonical_to_number(l_standard_rate));
3548 	        ELSE
3549 	            l_standard_rate :=NULL;
3550 	        END IF;
3551 	    CLOSE csr_sec_classification;
3552 	    END IF;
3553 
3554 	    IF p_special IS NOT NULL THEN
3555 	    OPEN csr_sec_classification(element_value_rec.element_type_id
3556 	                               ,p_special
3557 	                               ,p_date_earned);
3558 	        FETCH csr_sec_classification INTO l_temp;
3559 	        IF  csr_sec_classification%FOUND THEN
3560 	            l_special_rate := element_value_rec.value;
3561 	            l_sum_special_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_special_rate) + FND_NUMBER.canonical_to_number(l_special_rate));
3562 	        ELSE
3563 	            l_special_rate :=NULL;
3564 	        END IF;
3565 	    CLOSE csr_sec_classification;
3566 	    --
3567 	    END IF;
3568 	    --hr_utility.set_location('Inside archive_payslip_element_info2 p_payable_flag'||p_payable_flag,2120);
3569 
3570 	    IF p_payable_flag='Y' THEN
3571 		l_payable := element_value_rec.value;
3572 		hr_utility.set_location('Inside archive_payslip_element_info2 l_payable'||l_payable,2120);
3573 	        l_sum_payable:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_payable) + FND_NUMBER.canonical_to_number(nvl(l_payable,'0')));
3574 	        hr_utility.set_location('Inside archive_payslip_element_info2 l_sum_payable'||l_sum_payable,2120);
3575 	    END IF;
3576 
3577 	    --hr_utility.set_location('Inside archive_payslip_element_info2 element_name'||element_value_rec.element_name,2120);
3578 	    --hr_utility.set_location('Inside archive_payslip_element_info2 l_defined_balance_id'||l_defined_balance_id,2120);
3579 	    --hr_utility.set_location('Inside archive_payslip_element_info2 business_group_id'||element_value_rec.business_group_id,2120);
3580 
3581 	    OPEN csr_defined_balance_id(element_value_rec.element_name,'_ASG_YTD',element_value_rec.business_group_id);
3582 	    FETCH csr_defined_balance_id INTO l_defined_balance_id;
3583 	    if csr_defined_balance_id%NOTFOUND then
3584 	           l_defined_balance_id := NULL;
3585             end if;
3586 	    CLOSE csr_defined_balance_id;
3587 
3588 --5957039
3589 	IF p_class_name = 'Pre-Tax ZVW Refund'
3590 	THEN
3591 	    OPEN csr_defined_balance_id('ZVW Refund','_ASG_YTD',element_value_rec.business_group_id);
3592 	    FETCH csr_defined_balance_id INTO l_defined_balance_id;
3593 	    if csr_defined_balance_id%NOTFOUND then
3594 	           l_defined_balance_id := NULL;
3595             end if;
3596 	    CLOSE csr_defined_balance_id;
3597 	ELSIF p_class_name = 'Retro Pre-Tax ZVW Refund'
3598 	THEN
3599 		OPEN csr_defined_balance_id('Retro ZVW Refund','_ASG_YTD',element_value_rec.business_group_id);
3600 		FETCH csr_defined_balance_id INTO l_defined_balance_id;
3601 		if csr_defined_balance_id%NOTFOUND then
3602 		     l_defined_balance_id := NULL;
3603 		end if;
3604 		CLOSE csr_defined_balance_id;
3605 	END IF;
3606 --5957039
3607 
3608     	    --hr_utility.set_location('Inside archive_payslip_element_info2 l_rate'||l_rate,2121);
3609 	    --hr_utility.set_location('Inside archive_payslip_element_info2 l_defined_balance_id'||l_defined_balance_id,2121);
3610     	    --hr_utility.set_location('Inside archive_payslip_element_info2 np_assignment_action_id'||csr_np_rec.np_assignment_action_id,2121);
3611 
3612 	    IF  l_defined_balance_id IS NOT NULL THEN
3613 	        l_rate := pay_balance_pkg.get_value(l_defined_balance_id
3614 	                                           ,csr_np_rec.np_assignment_action_id);
3615 	    ELSE
3616 	        l_rate :=NULL;
3617 	    END IF;
3618 	    --
3619 	    --FND_FILE.PUT_LINE(FND_FILE.LOG, 'archive_element_info 2 l_rate'||' '||l_rate);
3620 	    --hr_utility.set_location('Inside archive_payslip_element_info2 l_rate'||l_rate,2122);
3621 	    --
3622 	    -- Special Tax Deduction Elemetns requires Pay Value and Percentage
3623 	    -- Rate to be archived.
3624 	    IF  p_element_name = 'Special Tax Deduction' THEN
3625 	        --
3626 	        -- Get Individual Percentage Value
3627 	        --
3628 	        OPEN csr_add_element_values(csr_np_rec.np_assignment_action_id
3629 	                                   ,p_class_name
3630 	                                   ,p_element_name
3631 	                                   ,'Percentage Rate'
3632 	                                   ,p_date_earned);
3633 		FETCH csr_add_element_values INTO l_pecentage_rate;
3634 	        CLOSE csr_add_element_values;
3635 	        --
3636 		IF l_pecentage_rate IS NOT NULL THEN
3637 		l_pecentage_rate:=l_pecentage_rate||'%';
3638 		END IF;
3639 	    END IF;
3640 	    l_priority:=element_value_rec.priority;
3641 	    l_reporting_name:=element_value_rec.reporting_name;
3642             --hr_utility.set_location('Inside archive_payslip_element_info element_value_rec.RDate'||element_value_rec.RDate,2123);
3643 	    l_date:=element_value_rec.RDate;
3644             --hr_utility.set_location('Inside archive_payslip_element_info l_date'||l_date,2123);
3645 	    --
3646 	    END LOOP;
3647   	END LOOP;
3648   	IF FND_NUMBER.canonical_to_number(l_sum_standard_rate)=0 THEN
3649   	l_sum_standard_rate:=NULL;
3650   	END IF;
3651 
3652   	IF FND_NUMBER.canonical_to_number(l_sum_special_rate)=0 THEN
3653   	l_sum_special_rate:=NULL;
3654   	END IF;
3655 
3656   	IF FND_NUMBER.canonical_to_number(l_sum_payable)=0 THEN
3657   	l_sum_payable:=NULL;
3658   	END IF;
3659         --hr_utility.set_location('Inside archive_payslip_element_info2 l_rate'||l_rate,2123);
3660   	--hr_utility.set_location('Inside archive_payslip_element_info2 l_sum_payable'||l_sum_payable,2123);
3661 
3662 	    IF p_archive_flag = 'Y' OR(FND_NUMBER.canonical_to_number(l_sum_standard_rate) is not null
3663 	    			    OR FND_NUMBER.canonical_to_number(l_sum_special_rate) is not null
3664 	    			    OR FND_NUMBER.canonical_to_number(l_sum_payable)  is not null
3665 	    			    OR l_rate is not null) THEN
3666 	    -- Archive NL CALCULATIONS
3667 	    --
3668 	    --pay_action_information_api.create_action_information (..);
3669 	    --
3670 --5957039
3671 IF	p_class_name IN ('Pre-Tax ZVW Refund', 'Retro Pre-Tax ZVW Refund')
3672 	AND l_index BETWEEN 18720 AND 19000
3673 THEN
3674 	l_sum_payable := -l_sum_payable;
3675 	l_rate := -l_rate;
3676 END IF;
3677 --5957039
3678 	    	 pay_action_information_api.create_action_information (
3679 	    	  p_action_information_id        => l_action_info_id
3680 	    	 ,p_action_context_id            => p_arch_assign_action_id
3681 	    	 ,p_action_context_type          => 'AAP'
3682 	    	 ,p_object_version_number        => l_ovn
3683 	    	 ,p_effective_date               => p_date_earned
3684 	    	 ,p_source_id                    => NULL
3685 	    	 ,p_source_text                  => NULL
3686 	    	 ,p_action_information_category  => 'NL CALCULATIONS'
3687 	    	 ,p_action_information4          =>l_index
3688 	    	 ,p_action_information5          =>l_priority
3689 	    	 ,p_action_information6          =>l_reporting_name
3690 	    	 ,p_action_information7          =>l_pecentage_rate
3691 	    	 ,p_action_information8          =>p_type
3692 	    	 ,p_action_information9          =>l_date   --Retro Period
3693 	    	 ,p_action_information10         =>l_sum_standard_rate
3694 	    	 ,p_action_information11         =>l_sum_special_rate
3695 	    	 ,p_action_information12         =>l_sum_payable
3696 	    	 ,p_action_information13         =>fnd_number.number_to_canonical(l_rate));
3697 
3698 
3699 		IF p_element_name = 'Employer ZVW Contribution Standard Tax' THEN
3700 		          g_zvw_er_cont_std_run := FND_NUMBER.canonical_to_number(l_sum_standard_rate);
3701 		          g_zvw_er_cont_std_ytd := l_rate;
3702 		END IF;
3703   	           	IF p_element_name = 'Employer ZVW Contribution Special Tax' THEN
3704 		          g_zvw_er_cont_spl_run := FND_NUMBER.canonical_to_number(l_sum_special_rate);
3705 		          g_zvw_er_cont_spl_ytd := l_rate;
3706              		END IF;
3707 
3708 		l_index := l_index + 1;
3709 
3710 	END IF;
3711 
3712 
3713 	END IF;
3714 
3715 END IF;
3716 END archive_element_info;
3717 --
3718 
3719 /*-------------------------------------------------------------------------------
3720 |Name           : ARCHIVE_PAYSLIP_ELEMENT_INFO     	        			       	|
3721 |Type			: Procedure														|
3722 |Description    : Procedure calls  ARCHIVE_ELEMENT_INFO to archive 				|
3723 |		  NL CALCULATIONS for each of the statutory elements					|
3724 -------------------------------------------------------------------------------*/
3725 
3726 PROCEDURE archive_payslip_element_info(
3727 					p_arch_assign_action_id 	IN NUMBER
3728 					,p_run_assign_action_id		IN NUMBER
3729 					,p_date_earned              IN DATE
3730 					,p_record_count             IN NUMBER
3731 					,p_master_assign_action_id 	IN NUMBER
3732 					,p_payroll_action_id       	IN NUMBER
3733 					,p_assignment_id           	IN NUMBER
3734 					,p_effective_date	      	IN DATE
3735 					,p_child_count			IN NUMBER) IS
3736 
3737 
3738 BEGIN
3739 	--
3740 	FOR l_index IN 1 .. g_stat_element_table.count
3741 	LOOP
3742 		--
3743 		archive_element_info(p_arch_assign_action_id
3744 							,p_run_assign_action_id
3745 							,g_stat_element_table(l_index).classification_name
3746 							,g_stat_element_table(l_index).element_name
3747 							,p_date_earned
3748 							,g_stat_element_table(l_index).main_index
3749 							,g_stat_element_table(l_index).element_type
3750 							,g_stat_element_table(l_index).archive_flag
3751 							,g_stat_element_table(l_index).standard
3752 							,g_stat_element_table(l_index).special
3753 							,g_stat_element_table(l_index).standard2
3754 							,g_stat_element_table(l_index).special2
3755 							,g_stat_element_table(l_index).payable_flag
3756 							,p_record_count
3757 							,p_master_assign_action_id
3758 							,p_payroll_action_id
3759 							,p_assignment_id
3760 							,p_effective_date
3761 							,p_child_count);
3762 
3763 		--
3764 	END LOOP;
3765 
3766 	--
3767 	--
3768 END archive_payslip_element_info;
3769 
3770 /*-------------------------------------------------------------------------------
3771 |Name           : ARCHIVE_BALANCE_INFO     		      	       					|
3772 |Type			: Procedure														|
3773 |Description    : Procedure archives NL CALCULATIONS for balances in Payment and|
3774 |		  		  Deduction section of the payslip								|
3775 -------------------------------------------------------------------------------*/
3776 
3777 PROCEDURE archive_balance_info(  p_arch_assign_action_id	IN NUMBER
3778 								,p_run_assign_action_id 	IN NUMBER
3779 								,p_balance_name         	IN VARCHAR2
3780 								,p_dimension            	IN VARCHAR2
3781 								,p_standard_bal_name    	IN VARCHAR2
3782 								,p_special_bal_name     	IN VARCHAR2
3783 								,p_non_tax_bal_name     	IN VARCHAR2
3784 								,p_multiply_factor      	IN NUMBER
3785 								,p_index                	IN NUMBER
3786 								,p_type       	                IN VARCHAR2
3787 								,p_record_count              	IN NUMBER
3788 								,p_date_earned	 		IN DATE
3789 								,p_archive_flag			IN VARCHAR2
3790 								,p_payable_flag			IN VARCHAR2
3791 								,p_payroll_action_id		IN NUMBER
3792 								,p_assignment_id		IN NUMBER
3793 								,p_effective_date		IN DATE) IS
3794 
3795 	--
3796 	CURSOR csr_get_context_id(p_run_assign_action_id VARCHAR2
3797 							 ,p_context_name         VARCHAR2) IS
3798 	SELECT pac.context_id           context_id
3799 		  ,pac.context_value        value
3800 	FROM   ff_contexts              ff
3801 		  ,pay_action_contexts      pac
3802 	WHERE  ff.context_name          = p_context_name
3803 	AND    pac.context_id           = ff.context_id
3804 	AND    pac.assignment_Action_id = p_run_assign_action_id;
3805 	--
3806 	CURSOR csr_get_translated_bal_name (p_balance_name VARCHAR2) IS
3807 	SELECT NVL(pbt_tl.reporting_name,pbt_tl.balance_name) bal_name
3808 	FROM   pay_balance_types        pbt
3809 		  ,pay_balance_types_tl     pbt_tl
3810 	WHERE  pbt.balance_name         = p_balance_name
3811 	AND    pbt.balance_type_id      = pbt_tl.balance_type_id
3812 	AND    pbt_tl.language          = USERENV('LANG');
3813 	--
3814 	CURSOR csr_get_sit_type_name (p_balance_name     VARCHAR2
3815 							   ,p_assgn_action_id  NUMBER
3816 							   ,p_date_earned      DATE
3817 							   ,p_si_type	    VARCHAR2) IS
3818 	SELECT prrv1.result_value        si_type_name
3819 	FROM   pay_balance_feeds_f      pbf
3820 		 ,pay_balance_types        pbt
3821 		 ,pay_input_values_f       piv
3822 		 ,pay_input_values_f       piv1
3823 		 ,pay_input_values_f       piv2
3824 		 ,pay_element_types_f      pet
3825 		 ,pay_run_results          prr
3826 		 ,pay_run_result_values    prrv
3827 		 ,pay_run_result_values    prrv1
3828 	WHERE  pbf.balance_type_id      = pbt.balance_type_id
3829 	AND    pbt.balance_name         like p_balance_name||'%'
3830 	AND    piv.input_value_id       = pbf.input_value_id
3831 	AND    piv.name                 ='Pay Value'
3832 	AND    pet.element_type_id      = piv.element_type_id
3833 	AND    pet.classification_id <>(SELECT classification_id
3834 		   from pay_element_classifications
3835 		   where classification_name ='Balance Initialization'
3836 		   and business_group_id is null
3837 		   and legislation_code is null)
3838 	AND    piv1.element_type_id     = pet.element_type_id
3839 	AND    piv1.name                = 'SI Type Name'
3840 	AND    piv2.element_type_id     = pet.element_type_id
3841 	AND    piv2.name                = 'SI Type'
3842 	AND    prr.element_type_id      = pet.element_type_id
3843 	AND    prr.assignment_action_id = p_assgn_action_id
3844 	AND    prrv.run_result_id       = prr.run_result_id
3845 	AND    prrv.input_value_id      = piv2.input_value_id
3846 	AND    prrv.result_value        = p_si_type
3847 	AND    prrv1.run_result_id      = prrv.run_result_id
3848 	AND    prrv1.input_value_id     = piv1.input_value_id
3849 	AND    p_date_earned             BETWEEN pbf.effective_start_date
3850 									AND     pbf.effective_end_date
3851 	AND    p_date_earned             BETWEEN pet.effective_start_date
3852 									AND     pet.effective_end_date
3853 	AND    p_date_earned             BETWEEN piv.effective_start_date
3854 									AND     piv.effective_end_date
3855 	AND    p_date_earned             BETWEEN piv1.effective_start_date
3856 									AND     piv1.effective_end_date
3857 	AND    p_date_earned             BETWEEN piv2.effective_start_date
3858 								 AND     piv2.effective_end_date;
3859 
3860 	CURSOR csr_emp_phc_applies(p_assgn_action_id NUMBER
3861 				  ,p_date_earned     DATE) IS
3862 	SELECT 1
3863 	FROM pay_run_results prr
3864 		,pay_element_types_f pet
3865 	WHERE
3866 		pet.element_name = 'Private Health Insurance'
3867 	AND 	prr.assignment_action_id=p_assgn_action_id
3868 	AND 	prr.element_type_id=pet.element_type_id
3869 	AND     p_date_earned   BETWEEN pet.effective_start_date
3870 				AND     pet.effective_end_date;
3871 	--
3872 	-- Cursor to retrieve all N (Normal)and P (Process separate) Child Actions
3873 	-- for a given assignment action.
3874 	--
3875 	CURSOR csr_np_children (p_assignment_action_id NUMBER
3876 				   ,p_payroll_action_id    NUMBER
3877 				   ,p_assignment_id        NUMBER
3878 				   ,p_effective_date       DATE) IS
3879 	SELECT paa.assignment_action_id np_assignment_action_id
3880 	FROM   pay_assignment_actions   paa
3881 		  ,pay_run_types_f          prt
3882 	WHERE  paa.source_action_id     = p_assignment_action_id
3883 	AND    paa.payroll_action_id    = p_payroll_action_id
3884 	AND    paa.assignment_id        = p_assignment_id
3885 	AND    paa.run_type_id          = prt.run_type_id
3886 	AND    prt.run_method           IN ('N','P')
3887 	AND    p_effective_date         BETWEEN prt.effective_start_date
3888 					AND     prt.effective_end_date
3889 	order by np_assignment_action_id;
3890 
3891 	-- Cursor to  return all the Runs for a Pre Payment Process which
3892 	-- is being archived.
3893 	--
3894 	CURSOR csr_assignment_actions(lp_locking_action_id NUMBER) IS
3895 	SELECT pre.locked_action_id        pre_assignment_action_id,
3896 		   pay.locked_action_id        master_assignment_action_id,
3897 		   assact.assignment_id        assignment_id,
3898 		   assact.payroll_action_id    pay_payroll_action_id,
3899 		   paa.effective_date          effective_date,
3900 		   ppaa.effective_date         pre_effective_date,
3901 		   paa.date_earned             date_earned,
3902 		   paa.time_period_id          time_period_id,
3903 		   paa.payroll_id		   payroll_id
3904 	FROM   pay_action_interlocks       pre,
3905 		   pay_action_interlocks       pay,
3906 		   pay_payroll_actions         paa,
3907 		   pay_payroll_actions         ppaa,
3908 		   pay_assignment_actions      assact,
3909 		   pay_assignment_actions      passact
3910 	WHERE  pre.locked_action_id      = pay.locking_action_id
3911 	AND    pre.locking_action_id     = lp_locking_action_id
3912 	AND    pre.locked_action_id      = passact.assignment_action_id
3913 	AND    passact.assignment_id	 =assact.assignment_id
3914 	AND    passact.payroll_action_id = ppaa.payroll_action_id
3915 	AND    ppaa.action_type          IN ('P','U')
3916 	AND    pay.locked_action_id      = assact.assignment_action_id
3917 	AND    assact.payroll_action_id  = paa.payroll_action_id
3918 	AND    assact.source_action_id   IS NULL
3919 	ORDER BY pay.locked_action_id;
3920 
3921 	v_csr_assignment_actions csr_assignment_actions%ROWTYPE;
3922 
3923 	--
3924 	l_year			NUMBER;
3925 	l_sum_year		NUMBER;
3926 	l_dummy			NUMBER;
3927 	l_archive_flag		VARCHAR2(10);
3928 	l_payable		NUMBER;
3929 	l_sum_payable		NUMBER;
3930 	l_si_type		pay_action_contexts.context_value%TYPE;
3931 	l_si_type_name		pay_run_result_values.result_value%TYPE;
3932 	l_def_bal_id		NUMBER;
3933 
3934 	l_standard_rate_run	NUMBER;
3935 	l_sum_standard_rate_run	NUMBER;
3936 	l_standard_rate_ytd	NUMBER;
3937 	l_special_rate_run	NUMBER;
3938 	l_sum_special_rate_run	NUMBER;
3939 	l_special_rate_ytd	NUMBER;
3940 	l_non_tax_rate_run	NUMBER;
3941 	l_sum_non_tax_rate_run	NUMBER;
3942 	l_non_tax_rate_ytd	NUMBER;
3943 
3944 	l_balance_name		pay_balance_types.balance_name%TYPE;
3945 	p_balance_sit_name	pay_balance_types.balance_name%TYPE;
3946 	l_action_info_id	NUMBER;
3947 	l_ovn			NUMBER;
3948 	l_index			NUMBER;
3949 	l_count 		NUMBER;
3950 	csr_np_rec		csr_np_children%ROWTYPE;
3951 	l_np_child_id		NUMBER;
3952 
3953 BEGIN
3954 	--
3955 	--hr_utility.set_location('Inside 	 p_dimension'||p_dimension,2110);
3956 
3957 	l_index:=p_index;
3958 
3959 	IF  p_dimension = '_ASG_SIT_YTD' THEN
3960 
3961 		OPEN csr_np_children(p_run_assign_action_id,p_payroll_action_id,
3962 		p_assignment_id,p_effective_date);
3963 		FETCH csr_np_children into l_np_child_id;
3964 		CLOSE csr_np_children;
3965 
3966 		hr_utility.set_location('Inside archive_balance_info1 p_balance_name'||p_balance_name,2222);
3967 		hr_utility.set_location('Inside archive_balance_info1 l_count'||l_count,2222);
3968 
3969 		IF l_np_child_id is not null THEN
3970 
3971 			hr_utility.set_location('Inside archive_balance_info1 l_count'||l_count,2223);
3972 			hr_utility.set_location('Inside archive_balance_info1 np_assignment_action_id'||l_np_child_id,2223);
3973 
3974 			-- Loop through pay_action_context table for all SI Type
3975 			FOR context_rec IN csr_get_context_id(l_np_child_id,'SOURCE_TEXT')
3976 			LOOP
3977 				--
3978 				l_sum_standard_rate_run:=0;
3979 				l_sum_special_rate_run :=0;
3980 				l_sum_non_tax_rate_run :=0;
3981 				l_sum_payable	       :=0;
3982 				l_sum_year	       :=0;
3983 
3984 				-- Loop through Payroll Run Actions locked by the Arch Asg Action
3985 				OPEN csr_assignment_actions(p_arch_assign_action_id);
3986 				LOOP
3987 					FETCH csr_assignment_actions INTO v_csr_assignment_actions;
3988 					EXIT WHEN csr_assignment_actions%NOTFOUND ;
3989 
3990 					/*FOR csr_np_rec IN csr_np_children(
3991 									p_run_assign_action_id,
3992 									p_payroll_action_id,
3993 									p_assignment_id,
3994 								p_effective_date) LOOP*/
3995 					-- Loop through Run Types in the Payroll Run Chosen
3996 					OPEN csr_np_children(v_csr_assignment_actions.master_assignment_action_id,
3997 					v_csr_assignment_actions.pay_payroll_action_id,
3998 					p_assignment_id,v_csr_assignment_actions.effective_date);
3999 					LOOP
4000 						FETCH csr_np_children into csr_np_rec;
4001 						EXIT when csr_np_children%NOTFOUND or csr_np_children%NOTFOUND IS NULL;
4002 
4003 						--hr_utility.set_location('Inside archive_balance_info p_standard_bal_name'||p_standard_bal_name,2120);
4004 
4005 						l_si_type           := context_rec.value;
4006 						l_standard_rate_run := 0;
4007 						l_special_rate_run := 0;
4008 						l_non_tax_rate_run := 0;
4009 
4010 						-- If Standard Balance exist for this balance then retrive them
4011 						IF  p_standard_bal_name IS NOT NULL THEN
4012 							--
4013 
4014 							l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_SIT_RUN');
4015 							l_standard_rate_run := pay_balance_pkg.get_value(
4016 							l_def_bal_id, csr_np_rec.np_assignment_action_id
4017 							,null,null,context_rec.context_id,context_rec.value
4018 							,null,null);
4019 
4020 							l_standard_rate_run := NVL(l_standard_rate_run,0) * p_multiply_factor;
4021 
4022 							-- YTD Figure
4023 							--
4024 							l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_SIT_YTD');
4025 							l_standard_rate_ytd := pay_balance_pkg.get_value(
4026 							l_def_bal_id, csr_np_rec.np_assignment_action_id
4027 							,null,null,context_rec.context_id,context_rec.value
4028 							,null,null);
4029 							l_standard_rate_ytd := NVL(l_standard_rate_ytd,0) * p_multiply_factor;
4030 							--
4031 						END IF;
4032 
4033 						--hr_utility.set_location('Inside archive_balance_info p_special_bal_name'||p_special_bal_name,2130);
4034 
4035 						-- If Special Balance exist for this balance then retrive them
4036 						IF  p_special_bal_name IS NOT NULL THEN
4037 							--
4038 							l_def_bal_id := get_defined_balance_id(p_special_bal_name,'_ASG_SIT_RUN');
4039 							l_special_rate_run := pay_balance_pkg.get_value(
4040 							l_def_bal_id, csr_np_rec.np_assignment_action_id
4041 							,null,null,context_rec.context_id,context_rec.value
4042 							,null,null);
4043 							l_special_rate_run := NVL(l_special_rate_run,0) * p_multiply_factor;
4044 							-- YTD Figure
4045 							--
4046 							l_def_bal_id := get_defined_balance_id(p_special_bal_name,'_ASG_SIT_YTD');
4047 							l_special_rate_ytd := pay_balance_pkg.get_value(
4048 							 l_def_bal_id, csr_np_rec.np_assignment_action_id
4049 							 ,null,null,context_rec.context_id,context_rec.value
4050 							 ,null,null);
4051 							l_special_rate_ytd := NVL(l_special_rate_ytd,0) * p_multiply_factor;
4052 							--
4053 						END IF;
4054 
4055 						--hr_utility.set_location('Inside archive_balance_info p_non_tax_bal_name'||p_non_tax_bal_name,2140);
4056 
4057 						-- If Non Taxable Balance exist for this balance then retrive them
4058 						IF  p_non_tax_bal_name IS NOT NULL THEN
4059 							--
4060 							l_def_bal_id := get_defined_balance_id(p_non_tax_bal_name,'_ASG_SIT_RUN');
4061 							l_non_tax_rate_run := pay_balance_pkg.get_value(
4062 							l_def_bal_id, csr_np_rec.np_assignment_action_id
4063 							,null,null,context_rec.context_id,context_rec.value
4064 							,null,null);
4065 							l_non_tax_rate_run      := NVL(l_non_tax_rate_run,0) * p_multiply_factor;
4066 
4067 							-- YTD Figure
4068 							--
4069 							l_def_bal_id := get_defined_balance_id(p_non_tax_bal_name,'_ASG_SIT_YTD');
4070 							l_non_tax_rate_ytd := pay_balance_pkg.get_value(
4071 							l_def_bal_id, csr_np_rec.np_assignment_action_id
4072 							,null,null,context_rec.context_id,context_rec.value
4073 							,null,null);
4074 							l_non_tax_rate_ytd      := NVL(l_non_tax_rate_ytd,0) * p_multiply_factor;
4075 							--
4076 
4077 						END IF;
4078 
4079 						--hr_utility.set_location('Inside archive_balance_info p_standard_bal_name'||p_standard_bal_name,2150);
4080 
4081 						--
4082 						IF  p_standard_bal_name IS NULL
4083 						AND p_special_bal_name  IS NULL
4084 						AND p_non_tax_bal_name  IS NULL THEN
4085 							--
4086 							l_def_bal_id := get_defined_balance_id (p_balance_name
4087 							,'_ASG_SIT_RUN');
4088 							IF p_payable_flag = 'Y' THEN
4089 								l_payable := pay_balance_pkg.get_value(
4090 								l_def_bal_id,csr_np_rec.np_assignment_action_id
4091 								,null,null,context_rec.context_id,context_rec.value
4092 								,null,null);
4093 								l_payable := nvl(l_payable,0) * p_multiply_factor;
4094 							END IF;
4095 							--
4096 							l_def_bal_id := get_defined_balance_id (p_balance_name,'_ASG_SIT_YTD');
4097 							l_year := pay_balance_pkg.get_value(
4098 							l_def_bal_id, csr_np_rec.np_assignment_action_id
4099 							,null,null,context_rec.context_id,context_rec.value
4100 							,null,null);
4101 							l_year := nvl(l_year,0) * p_multiply_factor;
4102 							--
4103 						ELSE
4104 							--
4105 							IF p_payable_flag = 'Y' THEN
4106 								l_payable := (nvl(l_standard_rate_run,0) +
4107 								nvl(l_special_rate_run,0) +
4108 								nvl(l_non_tax_rate_run,0));
4109 							END IF;
4110 							l_year := (nvl(l_standard_rate_ytd,0) +
4111 							nvl(l_special_rate_ytd,0) +
4112 							nvl(l_non_tax_rate_ytd,0));
4113 							--
4114 						END IF;
4115 
4116 						l_sum_standard_rate_run:=l_sum_standard_rate_run + l_standard_rate_run;
4117 						l_sum_special_rate_run :=l_sum_special_rate_run + l_special_rate_run;
4118 						l_sum_non_tax_rate_run :=l_sum_non_tax_rate_run + l_non_tax_rate_run;
4119 						l_sum_payable	       :=l_sum_payable + l_payable;
4120 						l_sum_year	       :=l_year;
4121 
4122 
4123 						IF p_standard_bal_name IS NULL AND l_sum_standard_rate_run=0 THEN
4124 							l_sum_standard_rate_run:=NULL;
4125 						END IF;
4126 
4127 						IF p_special_bal_name IS NULL AND l_sum_special_rate_run=0 THEN
4128 							l_sum_special_rate_run:=NULL;
4129 						END IF;
4130 
4131 						IF p_payable_flag='N' AND l_sum_payable=0 THEN
4132 							l_sum_payable:=NULL;
4133 						END IF;
4134 						--
4135 						--hr_utility.set_location('Inside archive_balance_info p_standard_bal_name'||p_standard_bal_name,2160);
4136 
4137 						-- Retreive SI Type Name from run results
4138 						--
4139 						p_balance_sit_name:=p_balance_name;
4140 
4141 						IF p_balance_name='Employee SI Contribution' THEN
4142 							p_balance_sit_name:='Employee SI Contribution Standard Tax';
4143 						END IF;
4144 
4145 						OPEN csr_get_sit_type_name(p_balance_sit_name
4146 						,csr_np_rec.np_assignment_action_id,p_date_earned,l_si_type);
4147 						FETCH csr_get_sit_type_name INTO l_si_type_name;
4148 						CLOSE csr_get_sit_type_name;
4149 						--
4150 						--hr_utility.set_location('Inside archive_balance_info p_standard_bal_name'||p_standard_bal_name,2170);
4151 						--
4152 						-- Get Balance Name to be reported in the Payslip
4153 						--
4154 						l_balance_name:=p_balance_name;
4155 
4156 						OPEN csr_get_translated_bal_name (p_balance_name);
4157 						FETCH csr_get_translated_bal_name INTO l_balance_name;
4158 						IF  csr_get_translated_bal_name%NOTFOUND THEN
4159 							l_balance_name :=hr_general.decode_lookup(
4160 							'HR_NL_REPORT_LABELS',UPPER(p_balance_name));
4161 							END IF;
4162 						CLOSE csr_get_translated_bal_name;
4163 					END LOOP;
4164 					CLOSE csr_np_children;
4165 				END LOOP;--End of Cursor csr_assignment_actions Loop
4166 				CLOSE csr_assignment_actions;
4167 
4168 				hr_utility.set_location('Inside archive_balance_info1 l_sum_standard_rate_run'||l_sum_standard_rate_run,2229);
4169 
4170 				IF l_si_type_name='ZVW' THEN
4171 				  IF p_balance_name = 'Employer SI Contribution' and l_index < 18700 THEN
4172 				    l_index := 18700;
4173 				  END IF;
4174 				  IF p_balance_name = 'Retro Employer SI Contribution' and l_index < 18750 THEN
4175 				    l_index := 18750;
4176 				  END IF;
4177 				  IF p_balance_name = 'Employee SI Contribution' and l_index < 18800 THEN
4178 				    l_index := 18800;
4179 				  END IF;
4180 				  IF p_balance_name = 'Retro Employee SI Contribution' and l_index < 18850 THEN
4181 				    l_index := 18850;
4182 				  END IF;
4183 				  IF p_balance_name = 'Net Employee SI Contribution' and l_index < 18900 THEN
4184 				    l_index := 18900;
4185 				  END IF;
4186 				  IF p_balance_name = 'Retro Net Employee SI Contribution' and l_index < 18950 THEN
4187 				    l_index := 18950;
4188 				  END IF;
4189 				END IF;
4190 
4191 				IF p_archive_flag = 'Y' OR (l_sum_standard_rate_run <> 0
4192 				OR  l_sum_special_rate_run  <> 0
4193 				OR  l_sum_payable  <> 0
4194 				OR  l_sum_year  <> 0 ) THEN
4195 					-- Archive NL CALCULATIONS
4196 					--
4197 					-- l_si_type      - SI Type
4198 					-- l_si_type_name - SI Type Name
4199 					-- l_payable      - Payable Figure
4200 					-- l_year         - Annual Figure
4201 					--pay_action_information_api.create_action_information (..);
4202 					--
4203 					pay_action_information_api.create_action_information (
4204 					p_action_information_id        => l_action_info_id
4205 					,p_action_context_id            => p_arch_assign_action_id
4206 					,p_action_context_type          => 'AAP'
4207 					,p_object_version_number        => l_ovn
4208 					,p_effective_date               => p_date_earned
4209 					,p_source_id                    => NULL
4210 					,p_source_text                  => NULL
4211 					,p_action_information_category  => 'NL CALCULATIONS'
4212 					,p_action_information4          =>l_index
4213 					,p_action_information5          =>NULL
4214 					,p_action_information6          =>l_balance_name
4215 					,p_action_information7          =>l_si_type_name
4216 					,p_action_information8          =>p_type
4217 					,p_action_information9          =>null
4218 					,p_action_information10         =>fnd_number.number_to_canonical(l_sum_standard_rate_run)
4219 					,p_action_information11         =>fnd_number.number_to_canonical(l_sum_special_rate_run)
4220 					,p_action_information12         =>fnd_number.number_to_canonical(l_sum_payable)
4221 					,p_action_information13         =>fnd_number.number_to_canonical(l_sum_year));
4222 
4223 					l_index:=l_index+1;
4224 				END IF;
4225 
4226 			END LOOP;--End of Cursor Loop  csr_get_context_id
4227   		END IF;
4228 	--
4229 	ELSE -- Non Context Dimension
4230 		l_sum_standard_rate_run:=0;
4231 		l_sum_special_rate_run :=0;
4232 		l_sum_non_tax_rate_run :=0;
4233 		l_sum_payable	   :=0;
4234 		l_sum_year	           :=0;
4235 		--hr_utility.set_location('Inside archive_balance_info p_standard_bal_name'||p_standard_bal_name,2180);
4236 		/*    FOR csr_np_rec IN csr_np_children(
4237 		p_run_assign_action_id,
4238 		p_payroll_action_id,
4239 		p_assignment_id,
4240 		p_effective_date) LOOP*/
4241 		-- Loop through Payroll Run Actions locked by the Arch Asg Action
4242 		OPEN csr_assignment_actions(p_arch_assign_action_id);
4243 		LOOP
4244 			FETCH csr_assignment_actions INTO v_csr_assignment_actions;
4245 			EXIT WHEN csr_assignment_actions%NOTFOUND ;
4246 
4247 			-- Loop through all the Child Action Actions under the Payroll Run Master
4248 			OPEN csr_np_children(v_csr_assignment_actions.master_assignment_action_id,
4249 			v_csr_assignment_actions.pay_payroll_action_id,
4250 			p_assignment_id,v_csr_assignment_actions.effective_date);
4251 			LOOP
4252 				FETCH csr_np_children into csr_np_rec;
4253 				EXIT when csr_np_children%NOTFOUND or csr_np_children%NOTFOUND IS NULL;
4254 
4255 				l_standard_rate_run := 0;
4256 				l_special_rate_run := 0;
4257 				l_non_tax_rate_run := 0;
4258 
4259 				-- If Standard balance exist for this balance then retrive them
4260 				IF  p_standard_bal_name IS NOT NULL THEN
4261 					--
4262 					l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_RUN');
4263 					l_standard_rate_run :=  pay_balance_pkg.get_value(
4264 					l_def_bal_id, csr_np_rec.np_assignment_action_id);
4265 					l_standard_rate_run := NVL(l_standard_rate_run,0) * p_multiply_factor;
4266 					-- YTD Value
4267 					--
4268 					l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_YTD');
4269 					l_standard_rate_ytd :=  pay_balance_pkg.get_value(
4270 					l_def_bal_id, csr_np_rec.np_assignment_action_id);
4271 					l_standard_rate_ytd := NVL(l_standard_rate_ytd,0) * p_multiply_factor;
4272 					--
4273 
4274 				END IF;
4275 
4276 				--hr_utility.set_location('Inside archive_balance_info p_special_bal_name'||p_special_bal_name,2190);
4277 
4278 				-- If Special Balance exist for this balance then retrive them
4279 				IF  p_special_bal_name IS NOT NULL THEN
4280 					--
4281 					l_def_bal_id := get_defined_balance_id(p_special_bal_name,'_ASG_RUN');
4282 					l_special_rate_run := pay_balance_pkg.get_value(
4283 					l_def_bal_id, csr_np_rec.np_assignment_action_id);
4284 					l_special_rate_run := NVL(l_special_rate_run,0) * p_multiply_factor;
4285 					-- YTD Value
4286 					--
4287 					l_def_bal_id := get_defined_balance_id(p_special_bal_name,'_ASG_YTD');
4288 					l_special_rate_ytd := pay_balance_pkg.get_value(l_def_bal_id, csr_np_rec.np_assignment_action_id);
4289 					l_special_rate_ytd := NVL(l_special_rate_ytd,0) * p_multiply_factor;
4290 					--
4291 				END IF;
4292 
4293 				--hr_utility.set_location('Inside archive_balance_info p_non_tax_bal_name'||p_non_tax_bal_name,2200);
4294 
4295 				-- If Non Taxable Balance exist for this balance then retrive them
4296 				IF  p_non_tax_bal_name IS NOT NULL THEN
4297 					--
4298 					l_def_bal_id := get_defined_balance_id(p_non_tax_bal_name,'_ASG_RUN');
4299 					l_non_tax_rate_run := pay_balance_pkg.get_value(l_def_bal_id, csr_np_rec.np_assignment_action_id);
4300 					l_non_tax_rate_run := NVL(l_non_tax_rate_run,0) * p_multiply_factor;
4301 					-- YTD Value
4302 					--
4303 					l_def_bal_id := get_defined_balance_id(p_non_tax_bal_name,'_ASG_YTD');
4304 					l_non_tax_rate_ytd := pay_balance_pkg.get_value(l_def_bal_id, csr_np_rec.np_assignment_action_id);
4305 					l_non_tax_rate_ytd := NVL(l_non_tax_rate_ytd,0) * p_multiply_factor;
4306 					--
4307 
4308 				END IF;
4309 				--
4310 
4311 				IF  p_standard_bal_name IS NULL
4312 				AND p_special_bal_name  IS NULL
4313 				AND p_non_tax_bal_name  IS NULL THEN
4314 
4315 					--hr_utility.set_location('Inside archive_balance_info p_balance_name'||p_balance_name,2150);
4316 					--hr_utility.set_location('Inside archive_balance_info l_def_bal_id'||l_def_bal_id,2150);
4317 					--hr_utility.set_location('Inside archive_balance_info p_run_assign_action_id'||p_run_assign_action_id,2150);
4318 					--hr_utility.set_location('Inside archive_balance_info p_multiply_factor'||p_multiply_factor,2150);
4319 					--
4320 					l_def_bal_id := get_defined_balance_id (p_balance_name,'_ASG_RUN');
4321 					--hr_utility.set_location('Inside archive_balance_info l_def_bal_id'||l_def_bal_id,2152);
4322 					IF p_payable_flag = 'Y' THEN
4323 						l_payable := pay_balance_pkg.get_value(l_def_bal_id
4324 						, csr_np_rec.np_assignment_action_id);
4325 						IF p_balance_name = 'Gross Salary' THEN
4326 						    l_payable := l_payable - (g_zvw_er_cont_std_run +
4327 						                                             g_zvw_er_cont_spl_run +
4328 						                                             g_retro_zvw_er_cont_std_run +
4329 						                                             g_retro_zvw_er_cont_spl_run +
4330                                                                      g_travel_allowance +
4331                                                                      g_retro_travel_allowance);
4332 						END IF;
4333 					END IF;
4334 
4335 					--hr_utility.set_location('Inside archive_balance_info l_payable'||l_payable,2152);
4336 					--
4337 					l_def_bal_id := get_defined_balance_id (p_balance_name,'_ASG_YTD');
4338 					--hr_utility.set_location('Inside archive_balance_info l_def_bal_id'||l_def_bal_id,2153);
4339 
4340 					l_year := pay_balance_pkg.get_value(l_def_bal_id, csr_np_rec.np_assignment_action_id);
4341 					IF p_balance_name = 'Gross Salary' THEN
4342 		    			    l_year := l_year - (g_zvw_er_cont_std_ytd +
4343 					                                  g_zvw_er_cont_spl_ytd +
4344 					                                  g_retro_zvw_er_cont_std_ytd +
4345 					                                  g_retro_zvw_er_cont_spl_ytd +
4346                                                       g_travel_allowance_ytd +
4347                                                       g_retro_travel_allowance_ytd);
4348 					 END IF;
4349 
4350 					l_year := nvl(l_year,0) * p_multiply_factor;
4351 
4352 					--hr_utility.set_location('Inside archive_balance_info l_payable'||l_payable,2153);
4353 					--hr_utility.set_location('Inside archive_balance_info l_year'||l_year,2153);
4354 					--
4355 				ELSE
4356 
4357 					--
4358 					IF p_payable_flag = 'Y' THEN
4359 						l_payable := (nvl(l_standard_rate_run,0) +
4360 						nvl(l_special_rate_run,0) +
4361 						nvl(l_non_tax_rate_run,0));
4362 					END IF;
4363 
4364 					l_year := (nvl(l_standard_rate_ytd,0) +
4365 					nvl(l_special_rate_ytd,0) +
4366 					nvl(l_non_tax_rate_ytd,0));
4367 					--
4368 
4369 				END IF;
4370 				--
4371 
4372 				l_sum_standard_rate_run :=l_sum_standard_rate_run + l_standard_rate_run;
4373 				l_sum_special_rate_run  :=l_sum_special_rate_run + l_special_rate_run;
4374 				l_sum_non_tax_rate_run  :=l_sum_non_tax_rate_run + l_non_tax_rate_run;
4375 				l_sum_payable	      :=l_sum_payable + l_payable;
4376 				l_sum_year			:=l_year;
4377 
4378 				IF p_standard_bal_name IS NULL AND l_sum_standard_rate_run=0 THEN
4379 					l_sum_standard_rate_run:=NULL;
4380 				END IF;
4381 
4382 				IF p_special_bal_name IS NULL AND l_sum_special_rate_run=0 THEN
4383 					l_sum_special_rate_run:=NULL;
4384 				END IF;
4385 
4386 				IF p_payable_flag='N' AND l_sum_payable=0 THEN
4387 					l_sum_payable:=NULL;
4388 				END IF;
4389 
4390 				--hr_utility.set_location('Inside archive_balance_info l_payable'||l_payable,2160);
4391 				--
4392 				/*IF p_payable_flag = 'N' THEN
4393 				l_payable:=NULL;
4394 				END IF;*/
4395 				--
4396 				l_balance_name:=p_balance_name;
4397 
4398 				-- Get Balance Name to be reported in the Payslip
4399 				--
4400 				OPEN csr_get_translated_bal_name (p_balance_name);
4401 				FETCH csr_get_translated_bal_name INTO l_balance_name;
4402 				IF  csr_get_translated_bal_name%NOTFOUND THEN
4403 					l_balance_name :=hr_general.decode_lookup(
4404 					'HR_NL_REPORT_LABELS',UPPER(p_balance_name));
4405 				END IF;
4406 				CLOSE csr_get_translated_bal_name;
4407 
4408 				l_archive_flag:=p_archive_flag;
4409 
4410 				IF l_balance_name = 'Employee Private Health Contribution' THEN
4411 					OPEN csr_emp_phc_applies(csr_np_rec.np_assignment_action_id
4412 					,p_date_earned);
4413 					FETCH csr_emp_phc_applies into l_dummy;
4414 					IF csr_emp_phc_applies%NOTFOUND THEN
4415 						l_archive_flag:= 'N';
4416 					END IF;
4417 					CLOSE csr_emp_phc_applies;
4418 				END IF;
4419 
4420 			END LOOP;
4421 			CLOSE csr_np_children;
4422 		END LOOP;--End of Cursor Loop csr_assignment_actions
4423 		CLOSE csr_assignment_actions;
4424 
4425 		IF l_archive_flag = 'Y' OR (l_sum_standard_rate_run <> 0
4426 		OR  l_sum_special_rate_run  <> 0
4427 		OR  l_sum_payable  <> 0
4428 		OR  l_sum_year  <> 0) THEN
4429 			-- Archive NL CALCULATIONS
4430 			--
4431 			-- l_payable - Payable figure
4432 			-- l_year    - Annual figure
4433 			--pay_action_information_api.create_action_information (..);
4434 			--
4435 			pay_action_information_api.create_action_information (
4436 			p_action_information_id        => l_action_info_id
4437 			,p_action_context_id            => p_arch_assign_action_id
4438 			,p_action_context_type          => 'AAP'
4439 			,p_object_version_number        => l_ovn
4440 			,p_effective_date               => p_date_earned
4441 			,p_source_id                    => NULL
4442 			,p_source_text                  => NULL
4443 			,p_action_information_category  => 'NL CALCULATIONS'
4444 			,p_action_information4          =>l_index
4445 			,p_action_information5          =>NULL
4446 			,p_action_information6          =>l_balance_name
4447 			,p_action_information7          =>NULL
4448 			,p_action_information8          =>p_type
4449 			,p_action_information9          =>null
4450 			,p_action_information10         =>fnd_number.number_to_canonical(l_sum_standard_rate_run)
4451 			,p_action_information11         =>fnd_number.number_to_canonical(l_sum_special_rate_run)
4452 			,p_action_information12         =>fnd_number.number_to_canonical(l_sum_payable)
4453 			,p_action_information13         =>fnd_number.number_to_canonical(l_sum_year));
4454 
4455 			l_index:=l_index+1;
4456 
4457 		END IF;
4458 
4459 	--hr_utility.set_location('Inside archive_balance_info p_standard_bal_name'||p_standard_bal_name,2170);
4460 	END IF;
4461 
4462 END archive_balance_info;
4463 
4464 /*---------------------------------------------------------------------------------
4465 |Name           : ARCHIVE_RETRO_BALANCE_INFO     		      	       	  |
4466 |Type		: Procedure							  |
4467 |Description    : Procedure archives NL CALCULATIONS for retro balances in Payment|
4468 |		   and Deduction section of the payslip				  |
4469 ----------------------------------------------------------------------------------*/
4470 
4471 PROCEDURE archive_retro_balance_info(p_arch_assign_action_id	IN NUMBER
4472 				,p_run_assign_action_id 	IN NUMBER
4473 				,p_balance_name         	IN VARCHAR2
4474 				,p_dimension            	IN VARCHAR2
4475 				,p_standard_bal_name    	IN VARCHAR2
4476 				,p_special_bal_name     	IN VARCHAR2
4477 				,p_non_tax_bal_name     	IN VARCHAR2
4478 				,p_multiply_factor      	IN NUMBER
4479 				,p_index                	IN NUMBER
4480 				,p_type       	                IN VARCHAR2
4481 				,p_record_count              	IN NUMBER
4482 				,p_date_earned	 		IN DATE
4483 				,p_archive_flag			IN VARCHAR2
4484 				,p_payable_flag			IN VARCHAR2
4485 				,p_payroll_action_id		IN NUMBER
4486                                 ,p_assignment_id		IN NUMBER
4487                                 ,p_effective_date		IN DATE) IS
4488 
4489 	-- Cursor to retrieve all N (Normal)and P (Process separate) Child Actions
4490 	-- for a given assignment action.
4491 	--
4492 	CURSOR csr_np_children (p_assignment_action_id NUMBER
4493 			   ,p_payroll_action_id    NUMBER
4494 			   ,p_assignment_id        NUMBER
4495 			   ,p_effective_date       DATE) IS
4496 	SELECT paa.assignment_action_id np_assignment_action_id
4497 	FROM   pay_assignment_actions   paa
4498 		  ,pay_run_types_f          prt
4499 	WHERE  paa.source_action_id     = p_assignment_action_id
4500 	AND    paa.payroll_action_id    = p_payroll_action_id
4501 	AND    paa.assignment_id        = p_assignment_id
4502 	AND    paa.run_type_id          = prt.run_type_id
4503 	AND    prt.run_method           IN ('N','P')
4504 	AND    p_effective_date         BETWEEN prt.effective_start_date
4505 					AND     prt.effective_end_date
4506 	order by np_assignment_action_id;
4507 
4508 	--Bug No. 3371141
4509 	--Added two additional parameters p_standard_bal_name,p_special_bal_name
4510 	CURSOR csr_retro_element_periods(p_assignment_action_id	NUMBER
4511 			,p_balance_name		VARCHAR2
4512 			,p_standard_bal_name	VARCHAR2
4513 			,p_special_bal_name     VARCHAR2
4514 			,p_date_earned		DATE
4515 			,p_classification_id    NUMBER ) IS
4516 	SELECT    unique  prr.start_date /*pay_nl_general.get_retro_period(prr.source_id,p_date_earned)*/ RDate -- Bug 5107780
4517 	FROM   pay_balance_feeds_f      pbf
4518 	 ,pay_balance_types        pbt
4519 	 ,pay_input_values_f       piv
4520 	 ,pay_element_types_f      pet
4521 	 ,pay_run_results          prr
4522 	WHERE  pbf.balance_type_id      = pbt.balance_type_id
4523 	AND   (pbt.balance_name         like p_balance_name||'%'
4524 	OR     pbt.balance_name         like nvl(p_standard_bal_name,p_balance_name)||'%'
4525 	OR     pbt.balance_name         like nvl(p_special_bal_name,p_balance_name)||'%')
4526 	AND    piv.input_value_id       = pbf.input_value_id
4527 	AND    piv.name                 ='Pay Value'
4528 	AND    pet.element_type_id      = piv.element_type_id
4529 	AND    pet.classification_id <> p_classification_id /*(SELECT classification_id
4530 	   from pay_element_classifications
4531 	   where classification_name ='Balance Initialization'
4532 	   and business_group_id is null
4533 	   and legislation_code is null) */ -- Bug 5107780
4534 	AND    prr.element_type_id      = pet.element_type_id
4535 	AND    prr.assignment_action_id = p_assignment_action_id
4536 	AND    p_date_earned             BETWEEN pbf.effective_start_date
4537 								AND     pbf.effective_end_date
4538 	AND    p_date_earned             BETWEEN pet.effective_start_date
4539 								AND     pet.effective_end_date
4540 	AND    p_date_earned             BETWEEN piv.effective_start_date
4541 								AND     piv.effective_end_date;
4542 
4543 
4544 	CURSOR csr_get_context_id(p_run_assign_action_id VARCHAR2
4545 				 ,p_context_name         VARCHAR2) IS
4546 	SELECT pac.context_id           context_id
4547 	  ,pac.context_value        value
4548 	FROM   ff_contexts              ff
4549 	  ,pay_action_contexts      pac
4550 	WHERE  ff.context_name          = p_context_name
4551 	AND    pac.context_id           = ff.context_id
4552 	AND    pac.assignment_Action_id = p_run_assign_action_id;
4553 
4554 	CURSOR csr_retro_values_nc(p_assignment_action_id	NUMBER
4555 								,p_balance_name		VARCHAR2
4556 								,p_date_earned		DATE
4557 								,p_retro_date		DATE
4558 								,p_creator_type	  VARCHAR2
4559 								,p_classification_id NUMBER ) IS
4560 	SELECT     sum(fnd_number.canonical_to_number(prrv.result_value))        result_value
4561 	,pet.processing_priority      priority
4562 	FROM   pay_balance_feeds_f      pbf
4563 		,pay_balance_types        pbt
4564 		,pay_input_values_f       piv
4565 		,pay_element_types_f      pet
4566 	--	,pay_element_types_f_tl   pettl       Bug 5107780
4567 		,pay_run_results          prr
4568 		,pay_run_result_values    prrv
4569 		,pay_element_entries_f        pee
4570 	WHERE  pbf.balance_type_id      = pbt.balance_type_id
4571 	AND    prr.source_id                 = pee.element_entry_id
4572 	AND    pee.CREATOR_TYPE              = p_creator_type
4573 	AND    pbt.balance_name         like p_balance_name|| '%'
4574 	AND    piv.input_value_id       = pbf.input_value_id
4575 	AND    piv.name                 ='Pay Value'
4576 	AND    pet.element_type_id      = piv.element_type_id
4577 	AND    pet.classification_id <>  p_classification_id /*(SELECT classification_id
4578 									from pay_element_classifications
4579 									where classification_name ='Balance Initialization'
4580 									and business_group_id is null
4581 									and legislation_code is null)  */    -- Bug 5107780
4582 	AND    prr.element_type_id      = pet.element_type_id
4583 	AND    prr.assignment_action_id = p_assignment_action_id
4584 	AND    prrv.run_result_id       = prr.run_result_id
4585 --	AND    pet.element_type_id      = pettl.element_type_id  Bug 5107780
4586 --	AND    pettl.language           = USERENV('LANG')      Bug 5107780
4587 	AND    p_date_earned             BETWEEN pbf.effective_start_date
4588 	AND     pbf.effective_end_date
4589 	AND    p_date_earned             BETWEEN pet.effective_start_date
4590 	AND     pet.effective_end_date
4591 	AND    p_date_earned             BETWEEN piv.effective_start_date
4592 	AND     piv.effective_end_date
4593 	and /*pay_nl_general.get_retro_period(prr.source_id,p_date_earned)*/ prr.start_date = p_retro_date -- Bug 5107780
4594 	group by pet.processing_priority;
4595 
4596 
4597 	CURSOR csr_retro_values(p_assignment_action_id	NUMBER
4598 							,p_balance_name		VARCHAR2
4599 							,p_date_earned		DATE
4600 							,p_retro_date		DATE
4601 							,p_si_type	        VARCHAR2
4602 							,p_creator_type	  VARCHAR2
4603 							,p_classification_id NUMBER) IS
4604 	SELECT sum(fnd_number.canonical_to_number(prrv2.result_value))
4605 		,prrv1.result_value
4606 		,pet.processing_priority
4607 	FROM   pay_balance_feeds_f      pbf
4608 		,pay_balance_types        pbt
4609 		,pay_input_values_f       piv
4610 		,pay_input_values_f       piv1
4611 		,pay_input_values_f       piv2
4612 		,pay_element_types_f      pet
4613 --		,pay_element_types_f_tl   pettl             Bug 5107780
4614 		,pay_run_results          prr
4615 		,pay_run_result_values    prrv
4616 		,pay_run_result_values    prrv1
4617 		,pay_run_result_values    prrv2
4618 		,pay_element_entries_f        pee
4619 	WHERE  pbf.balance_type_id      = pbt.balance_type_id
4620 	AND    prr.source_id                 = pee.element_entry_id
4621 	AND    pee.CREATOR_TYPE              = p_creator_type
4622 	AND    pbt.balance_name         like p_balance_name
4623 	AND    piv.input_value_id       = pbf.input_value_id
4624 	AND    piv.name                 ='Pay Value'
4625 	AND    pet.element_type_id      = piv.element_type_id
4626 	AND    pet.classification_id <> p_classification_id /*(SELECT classification_id
4627 	from pay_element_classifications
4628 	where classification_name ='Balance Initialization'
4629 	and business_group_id is null
4630 	and legislation_code is null) */ -- Bug 5107780
4631 	AND    piv1.element_type_id     = pet.element_type_id
4632 	AND    piv1.name                = 'SI Type Name'
4633 	AND    piv2.element_type_id     = pet.element_type_id
4634 	AND    piv2.name                = 'SI Type'
4635 	AND    prr.element_type_id      = pet.element_type_id
4636 	AND    prr.assignment_action_id = p_assignment_action_id
4637 	AND    prrv.run_result_id       = prr.run_result_id
4638 	AND    prrv.input_value_id      = piv2.input_value_id
4639 	AND    prrv.result_value        = p_si_type
4640 	AND    prrv1.run_result_id      = prrv.run_result_id
4641 	AND    prrv1.input_value_id     = piv1.input_value_id
4642 	AND    prrv2.run_result_id      = prrv.run_result_id
4643 	AND    prrv2.input_value_id     = piv.input_value_id
4644 --	AND    pet.element_type_id      = pettl.element_type_id  Bug 5107780
4645 --	AND    pettl.language           = USERENV('LANG')       Bug 5107780
4646 	AND    p_date_earned             BETWEEN pbf.effective_start_date
4647 	AND     pbf.effective_end_date
4648 	AND    p_date_earned             BETWEEN pet.effective_start_date
4649 	AND     pet.effective_end_date
4650 	AND    p_date_earned             BETWEEN piv.effective_start_date
4651 	AND     piv.effective_end_date
4652 	AND    p_date_earned            BETWEEN piv1.effective_start_date
4653 	AND     piv1.effective_end_date
4654 	AND    p_date_earned             BETWEEN piv2.effective_start_date
4655 	AND     piv2.effective_end_date
4656 	and /*pay_nl_general.get_retro_period(prr.source_id,p_date_earned)*/ prr.start_date = p_retro_date
4657     group by prrv1.result_value,pet.processing_priority; -- Bug 5107780
4658 
4659 
4660 	CURSOR csr_get_translated_bal_name (p_balance_name VARCHAR2) IS
4661 	SELECT NVL(pbt_tl.reporting_name,pbt_tl.balance_name) bal_name
4662 	FROM   pay_balance_types        pbt
4663 	,pay_balance_types_tl     pbt_tl
4664 	WHERE  pbt.balance_name         = p_balance_name
4665 	AND    pbt.balance_type_id      = pbt_tl.balance_type_id
4666 	AND    pbt_tl.language          = USERENV('LANG');
4667 
4668 
4669 	/* Bug 5107780*/
4670 	CURSOR csr_get_bal_init_class IS
4671 	SELECT classification_id
4672 		from pay_element_classifications
4673 		where classification_name ='Balance Initialization'
4674 		and business_group_id is null
4675 	and legislation_code is null;
4676 
4677 
4678 
4679 	l_value			VARCHAR2(255);
4680 	l_action_info_id	NUMBER;
4681 	l_ovn			NUMBER;
4682 	l_standard_rate		VARCHAR2(255);
4683 	l_special_rate		VARCHAR2(255);
4684 	l_standard_ptd		NUMBER;
4685 	l_special_ptd		NUMBER;
4686 	l_non_rate		VARCHAR2(255);
4687 	l_rate			VARCHAR2(255);
4688 	l_payable		NUMBER;
4689 	l_def_bal_id		NUMBER;
4690 	l_index			NUMBER;
4691 	l_sum_standard_rate	VARCHAR2(255);
4692 	l_sum_special_rate 	VARCHAR2(255);
4693 	l_sum_non_rate	 	VARCHAR2(255);
4694 	l_sum_payable  		VARCHAR2(255);
4695 	l_sum_ptd		NUMBER;
4696 	l_standard_year		NUMBER;
4697 	l_special_year		NUMBER;
4698 	l_non_year		NUMBER;
4699 	l_sum_year		NUMBER;
4700 	l_date			VARCHAR2(255);
4701 	l_priority		NUMBER;
4702 	l_np_child_id		NUMBER;
4703 	l_balance_name		VARCHAR2(255);
4704 	l_si_type		VARCHAR2(255);
4705 	l_si_type_name		VARCHAR2(255);
4706 	l_flag			NUMBER;
4707 	l_year_flag NUMBER;
4708 	l_bal_init_class_id     NUMBER;
4709 
4710 	type creator_type is table of varchar2(2) index by binary_integer;
4711 	l_creator_type creator_type;
4712 
4713 	type element_retro_entries is table of DATE index by binary_integer;
4714 	l_element_retro_entries element_retro_entries;
4715 
4716 BEGIN
4717 	-- Bug 5107780
4718 	OPEN csr_get_bal_init_class;
4719 	FETCH csr_get_bal_init_class INTO l_bal_init_class_id;
4720 	CLOSE csr_get_bal_init_class;
4721 
4722 	l_index:=p_index;
4723 	hr_utility.set_location('Inside archive_retro_balance_info l_index'||l_index,5000);
4724 	hr_utility.set_location('Inside archive_retro_balance_info p_dimension'||p_dimension,5000);
4725 
4726 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_balance_name'||' '||p_balance_name);
4727 	--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_dimension'||' '||p_dimension);
4728 
4729 	IF  p_dimension = '_ASG_SIT_YTD' THEN
4730 
4731 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_run_assign_action_id'||' '||p_run_assign_action_id);
4732 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_payroll_action_id'||' '||p_payroll_action_id);
4733 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_assignment_id'||' '||p_assignment_id);
4734 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_effective_date'||' '||p_effective_date);
4735 
4736 		--hr_utility.set_location('Inside archive_retro_balance_info p_run_assign_action_id'||p_run_assign_action_id,5010);
4737 		--hr_utility.set_location('Inside archive_retro_balance_info p_payroll_action_id'||p_payroll_action_id,5010);
4738 		--hr_utility.set_location('Inside archive_retro_balance_info p_assignment_id'||p_assignment_id,5010);
4739 		--hr_utility.set_location('Inside archive_retro_balance_info p_effective_date'||p_effective_date,5010);
4740 		--Get the child action id with highest sequence
4741 
4742 		l_creator_type(0):='EE';
4743 		l_creator_type(1):='RR';
4744 		l_creator_type(2):='PR';
4745 		l_creator_type(3):='NR';
4746 
4747 		OPEN csr_np_children(p_run_assign_action_id,p_payroll_action_id,
4748 		p_assignment_id,p_effective_date);
4749 		FETCH csr_np_children into l_np_child_id;
4750 		CLOSE csr_np_children;
4751 
4752 		--hr_utility.set_location('Inside archive_retro_balance_info l_np_child_id'||l_np_child_id,5020);
4753 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_np_child_id'||' '||l_np_child_id);
4754 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_balance_name'||' '||p_balance_name);
4755 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_standard_bal_name'||' '||p_standard_bal_name);
4756 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_special_bal_name'||' '||p_special_bal_name);
4757 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_date_earned'||' '||p_date_earned);
4758 		--Get all the retro periods
4759 		--hr_utility.set_location('Inside archive_retro_balance_info p_balance_name'||p_balance_name,5030);
4760 		--hr_utility.set_location('Inside archive_retro_balance_info p_standard_bal_name'||p_standard_bal_name,5030);
4761 		--hr_utility.set_location('Inside archive_retro_balance_info p_special_bal_name'||p_special_bal_name,5030);
4762 		--hr_utility.set_location('Inside archive_retro_balance_info p_date_earned'||p_date_earned,5030);
4763 
4764 		OPEN csr_retro_element_periods(l_np_child_id,p_balance_name,p_standard_bal_name
4765 		,p_special_bal_name,p_date_earned,l_bal_init_class_id);
4766 		FETCH csr_retro_element_periods bulk collect into l_element_retro_entries;
4767 		CLOSE csr_retro_element_periods;
4768 
4769 		--hr_utility.set_location('Inside archive_retro_balance_info p_date_earned'||p_date_earned,5040);
4770 
4771 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries.count'||' '||l_element_retro_entries.count);
4772 
4773 		-- Loop through pay_action_context table for all SI Type
4774 		FOR context_rec IN csr_get_context_id(l_np_child_id,'SOURCE_TEXT')
4775 		LOOP
4776 
4777 			--hr_utility.set_location('Inside archive_retro_balance_info l_element_retro_entries.count'||l_element_retro_entries.count,5050);
4778 			--FND_FILE.PUT_LINE(FND_FILE.LOG, 'context_rec'||' '||context_rec.value);
4779 
4780 			IF l_element_retro_entries.count > 0 THEN
4781 				FOR i in l_element_retro_entries.first..l_element_retro_entries.last  LOOP
4782 
4783 					--hr_utility.set_location('Inside archive_retro_balance_info l_element_retro_entries(i)'||l_element_retro_entries(i),5060);
4784 					FOR j in l_creator_type.first..l_creator_type.last LOOP
4785 						l_sum_standard_rate	:='0';
4786 						l_sum_special_rate 	:='0';
4787 						l_sum_payable  		:='0';
4788 						l_sum_year		:=0;
4789 						l_sum_non_rate		:='0';
4790 
4791 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries'||' '||l_element_retro_entries(i));
4792 
4793 						FOR csr_np_rec IN csr_np_children(p_run_assign_action_id,p_payroll_action_id,
4794 						p_assignment_id,p_effective_date)
4795 						LOOP
4796 							l_standard_rate		:='0';
4797 							l_special_rate		:='0';
4798 							l_standard_year		:=0;
4799 							l_special_year		:=0;
4800 							l_non_rate		:='0';
4801 							l_rate			:='0';
4802 							l_non_year		:=0;
4803 
4804 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_standard_bal_name'||' '||p_standard_bal_name);
4805 
4806 							--hr_utility.set_location('Inside archive_retro_balance_info p_standard_bal_name'||p_standard_bal_name,5070);
4807                             l_year_flag := 0;
4808 							IF p_standard_bal_name IS NOT NULL THEN
4809 
4810 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'csr_np_rec'||' '||csr_np_rec.np_assignment_action_id);
4811 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_standard_bal_name'||' '||p_standard_bal_name);
4812 								--FND_FILE.PUT_LINE(FND_FILE.LOG,' p_date_earned'||' '||p_date_earned);
4813 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries(i)'||' '||l_element_retro_entries(i));
4814 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'context_rec.value'||' '||context_rec.value);
4815 
4816 								--hr_utility.set_location('Inside archive_retro_balance_info np_assignment_action_id'||csr_np_rec.np_assignment_action_id,5080);
4817 
4818 								OPEN csr_retro_values(csr_np_rec.np_assignment_action_id,p_standard_bal_name
4819 								,p_date_earned,l_element_retro_entries(i),context_rec.value,l_creator_type(j),l_bal_init_class_id);
4820 								FETCH csr_retro_values INTO l_value,l_si_type_name,l_priority;
4821 
4822 								--hr_utility.set_location('Inside archive_retro_balance_info l_value'||l_value,5090);
4823 								--hr_utility.set_location('Inside archive_retro_balance_info l_si_type_name'||l_si_type_name,5090);
4824 								--hr_utility.set_location('Inside archive_retro_balance_info l_priority'||l_priority,5090);
4825 
4826 								--FND_FILE.PUT_LINE(FND_FILE.LOG,'l_value'||' '||l_value);
4827 
4828 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
4829 
4830 								IF  csr_retro_values%FOUND THEN
4831                                     l_year_flag := 1;
4832 									l_standard_rate := l_value;
4833 
4834 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_rate'||' '||l_standard_rate);
4835 
4836 									l_sum_standard_rate :=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_standard_rate) + FND_NUMBER.canonical_to_number(l_standard_rate));
4837 
4838 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_standard_rate'||' '||l_sum_standard_rate);
4839 
4840 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
4841 									IF l_si_type_name IS NOT NULL THEN
4842 										l_si_type:=l_si_type_name;
4843 									END IF;
4844 								END IF;
4845 								CLOSE csr_retro_values;
4846 									l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_SIT_YTD');
4847 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
4848 									IF  l_def_bal_id IS NOT NULL THEN
4849 										l_standard_year := pay_balance_pkg.get_value(l_def_bal_id
4850                                         ,csr_np_rec.np_assignment_action_id,null,null,context_rec.context_id,context_rec.value,null,null);
4851 									END IF;
4852 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_year'||' '||l_standard_year);
4853 
4854 							END IF;
4855 
4856 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_special_bal_name'||' '||p_special_bal_name);
4857 							--hr_utility.set_location('Inside archive_retro_balance_info p_special_bal_name'||p_special_bal_name,5100);
4858 							IF csr_retro_values%ISOPEN THEN
4859 							CLOSE csr_retro_values;
4860 							END IF;
4861 							IF p_special_bal_name IS NOT NULL THEN
4862 								OPEN csr_retro_values(csr_np_rec.np_assignment_action_id,p_special_bal_name
4863 								,p_date_earned,l_element_retro_entries(i),context_rec.value,l_creator_type(j),l_bal_init_class_id);
4864 								FETCH csr_retro_values INTO l_value,l_si_type_name,l_priority;
4865 								--FND_FILE.PUT_LINE(FND_FILE.LOG,' l_value'||' '||l_value);
4866 
4867 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
4868 
4869 								IF  csr_retro_values%FOUND THEN
4870                                     l_year_flag := 1;
4871 									l_special_rate := l_value;
4872 
4873 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_rate'||' '||l_special_rate);
4874 
4875 									l_sum_special_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_special_rate) + FND_NUMBER.canonical_to_number(l_special_rate));
4876 
4877 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_special_rate'||' '||l_sum_special_rate);
4878 
4879 									IF l_si_type_name IS NOT NULL THEN
4880 										l_si_type:=l_si_type_name;
4881 									END IF;
4882 								END IF;
4883 								--
4884 								CLOSE csr_retro_values;
4885 									l_def_bal_id := get_defined_balance_id (p_special_bal_name,'_ASG_SIT_YTD');
4886 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
4887 
4888 									IF  l_def_bal_id IS NOT NULL THEN
4889 										l_special_year := pay_balance_pkg.get_value(l_def_bal_id
4890                                         ,csr_np_rec.np_assignment_action_id,null,null,context_rec.context_id,context_rec.value,null,null);
4891 										--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_year'||' '||l_special_year);
4892 									END IF;
4893 							END IF;
4894 
4895 							--hr_utility.set_location('Inside archive_retro_balance_info p_non_tax_bal_name'||p_non_tax_bal_name,5110);
4896 
4897 
4898 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_non_tax_bal_name'||' '||p_non_tax_bal_name);
4899 
4900 							IF p_non_tax_bal_name IS NOT NULL THEN
4901 								OPEN csr_retro_values(csr_np_rec.np_assignment_action_id,p_non_tax_bal_name
4902 								,p_date_earned,l_element_retro_entries(i),context_rec.value,l_creator_type(j),l_bal_init_class_id);
4903 								FETCH csr_retro_values INTO l_value,l_si_type_name,l_priority;
4904 								--FND_FILE.PUT_LINE(FND_FILE.LOG,' l_value'||' '||l_value);
4905 
4906 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
4907 
4908 								IF  csr_retro_values%FOUND THEN
4909                                     l_year_flag := 1;
4910 									l_non_rate := l_value;
4911 
4912 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_non_rate'||' '||l_non_rate);
4913 
4914 									l_sum_non_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_non_rate) +FND_NUMBER.canonical_to_number(l_non_rate));
4915 
4916 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_non_rate'||' '||l_sum_non_rate);
4917 
4918 									IF l_si_type_name IS NOT NULL THEN
4919 										l_si_type:=l_si_type_name;
4920 									END IF;
4921 								END IF;
4922 								--
4923 								CLOSE csr_retro_values;
4924 
4925 									l_def_bal_id := get_defined_balance_id (p_non_tax_bal_name,'_ASG_SIT_YTD');
4926 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
4927 
4928 									IF  l_def_bal_id IS NOT NULL THEN
4929 										l_non_year := pay_balance_pkg.get_value(l_def_bal_id
4930                                         ,csr_np_rec.np_assignment_action_id,null,null,context_rec.context_id,context_rec.value,null,null);
4931 										--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_non_year'||' '||l_non_year);
4932 									END IF;
4933 							END IF;
4934 
4935 							--hr_utility.set_location('Inside archive_retro_balance_info p_balance_name'||p_balance_name,5120);
4936 
4937 							IF  p_standard_bal_name IS NULL
4938 							AND p_special_bal_name  IS NULL
4939 							AND p_non_tax_bal_name  IS NULL THEN
4940 
4941 								OPEN csr_retro_values(csr_np_rec.np_assignment_action_id,p_balance_name
4942 								,p_date_earned,l_element_retro_entries(i),context_rec.value,l_creator_type(j),l_bal_init_class_id);
4943 								FETCH csr_retro_values INTO l_value,l_si_type_name,l_priority;
4944 								--FND_FILE.PUT_LINE(FND_FILE.LOG,' l_value'||' '||l_value);
4945 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
4946 
4947 								IF  csr_retro_values%FOUND THEN
4948 									l_rate := l_value;
4949 
4950 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_rate'||' '||l_rate);
4951 
4952 									l_sum_payable:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_payable) +FND_NUMBER.canonical_to_number(l_rate));
4953 
4954 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
4955 
4956 								IF l_si_type_name IS NOT NULL THEN
4957 									l_si_type:=l_si_type_name;
4958 								END IF;
4959 								l_def_bal_id := get_defined_balance_id (p_balance_name,'_ASG_SIT_YTD');
4960 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
4961 
4962 								IF  l_def_bal_id IS NOT NULL THEN
4963 									l_sum_year := pay_balance_pkg.get_value(l_def_bal_id
4964                                         ,csr_np_rec.np_assignment_action_id,null,null,context_rec.context_id,context_rec.value,null,null);
4965 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_year'||' '||l_sum_year);
4966 								END IF;
4967 							END IF;
4968 						ELSE
4969 
4970 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_payable_flag'||' '||p_payable_flag);
4971 
4972 							IF p_payable_flag='Y' THEN
4973 
4974 								l_sum_payable:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_standard_rate)
4975 								+ FND_NUMBER.canonical_to_number(l_sum_special_rate) +FND_NUMBER.canonical_to_number(l_sum_non_rate));
4976 
4977 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
4978 							END IF;
4979 
4980 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_year'||' '||l_standard_year);
4981 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_year'||' '||l_special_year);
4982 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_non_year'||' '||l_non_year);
4983                             If l_year_flag =1 THEN
4984     							l_sum_year:=l_sum_year + l_standard_year + l_special_year + l_non_year;
4985 							END IF;
4986 
4987 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_year'||' '||l_sum_year);
4988 							END IF;
4989 							IF csr_retro_values%ISOPEN THEN
4990 								CLOSE csr_retro_values;
4991 							END IF;
4992 							--hr_utility.set_location('Inside archive_retro_balance_info l_sum_year'||l_sum_year,5130);
4993 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_balance_name'||' '||l_balance_name);
4994 							l_balance_name:=p_balance_name;
4995 							--hr_utility.set_location('Inside archive_retro_balance_info l_balance_name'||l_balance_name,5140);
4996 
4997 							OPEN csr_get_translated_bal_name (p_balance_name);
4998 							FETCH csr_get_translated_bal_name INTO l_balance_name;
4999 							IF  csr_get_translated_bal_name%NOTFOUND THEN
5000 								l_balance_name :=hr_general.decode_lookup('HR_NL_REPORT_LABELS',UPPER(p_balance_name));
5001 							END IF;
5002 							CLOSE csr_get_translated_bal_name;
5003 
5004 							--hr_utility.set_location('Inside archive_retro_balance_info l_balance_name'||l_balance_name,5150);
5005 
5006 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_balance_name'||' '||l_balance_name);
5007 
5008 							l_date:=fnd_date.date_to_canonical(l_element_retro_entries(i));
5009 							--Bug No. 3384315
5010 							--Fetch the si type name for the p_balance_name
5011 							IF l_si_type IS  NULL THEN
5012 							OPEN csr_retro_values(csr_np_rec.np_assignment_action_id,p_balance_name
5013 							,p_date_earned,l_element_retro_entries(i),context_rec.value,l_creator_type(j),l_bal_init_class_id);
5014 							FETCH csr_retro_values INTO l_value,l_si_type_name,l_priority;
5015 							CLOSE csr_retro_values;
5016 							IF l_si_type_name IS NOT NULL THEN
5017 								l_si_type:=l_si_type_name;
5018 							ELSE
5019 								l_si_type:=context_rec.value;
5020 							END IF;
5021 						END IF;
5022 	    			END LOOP;
5023 
5024 					--hr_utility.set_location('Inside archive_retro_balance_info l_balance_name'||l_balance_name,5150);
5025 
5026 
5027 					IF l_balance_name='Retro Net Employee SI Contribution' and
5028 						FND_NUMBER.canonical_to_number(l_sum_standard_rate)=0 THEN
5029 						l_sum_standard_rate:=NULL;
5030 					END IF;
5031 
5032 					IF l_balance_name='Retro Net Employee SI Contribution' and
5033 						FND_NUMBER.canonical_to_number(l_sum_special_rate)=0 THEN
5034 						l_sum_special_rate:=NULL;
5035 					END IF;
5036 
5037 					IF p_payable_flag='N' and FND_NUMBER.canonical_to_number(l_sum_payable) =0 THEN
5038 						l_sum_payable:=NULL;
5039 					END IF;
5040 				IF l_si_type_name='ZVW' THEN
5041 				  IF p_balance_name = 'Retro Employer SI Contribution' and l_index < 18750 THEN
5042 				    l_index := 18750;
5043 				  END IF;
5044 				  IF p_balance_name = 'Retro Employee SI Contribution' and l_index < 18850 THEN
5045 				    l_index := 18850;
5046 				  END IF;
5047 				  IF p_balance_name = 'Retro Net Employee SI Contribution' and l_index < 18950 THEN
5048 				    l_index := 18950;
5049 				  END IF;
5050 				END IF;
5051 					--hr_utility.set_location('Inside archive_retro_balance_info l_rate'||l_sum_year,5123);
5052 					--hr_utility.set_location('Inside archive_retro_balance_info l_sum_payable'||l_sum_payable,5123);
5053 
5054 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_standard_rate'||' '||l_sum_standard_rate);
5055 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_special_rate'||' '||l_sum_special_rate);
5056 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
5057 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_year'||' '||l_sum_year);
5058 
5059 					IF p_archive_flag = 'Y'
5060 						OR (FND_NUMBER.canonical_to_number(l_sum_standard_rate) <> 0
5061 						OR FND_NUMBER.canonical_to_number(l_sum_special_rate) <> 0
5062 						OR FND_NUMBER.canonical_to_number(l_sum_payable)  <> 0
5063 						OR l_sum_year <> 0) THEN
5064 
5065 						/* IF p_archive_flag = 'Y' OR(FND_NUMBER.canonical_to_number(l_sum_standard_rate) <> 0
5066 						OR FND_NUMBER.canonical_to_number(l_sum_special_rate) <> 0
5067 						OR FND_NUMBER.canonical_to_number(l_sum_payable)  <> 0
5068 						OR FND_NUMBER.canonical_to_number(l_sum_year) <> 0) THEN*/
5069 						-- Archive NL CALCULATIONS
5070 						--
5071 						--pay_action_information_api.create_action_information (..);
5072 						--
5073 
5074 						pay_action_information_api.create_action_information (
5075 						p_action_information_id        => l_action_info_id
5076 						,p_action_context_id            => p_arch_assign_action_id
5077 						,p_action_context_type          => 'AAP'
5078 						,p_object_version_number        => l_ovn
5079 						,p_effective_date               => p_date_earned
5080 						,p_source_id                    => NULL
5081 						,p_source_text                  => NULL
5082 						,p_action_information_category  => 'NL CALCULATIONS'
5083 						,p_action_information4          =>l_index
5084 						,p_action_information5          =>l_priority
5085 						,p_action_information6          =>l_balance_name
5086 						,p_action_information7          =>l_si_type
5087 						,p_action_information8          =>p_type
5088 						,p_action_information9          =>l_date   --Retro Period
5089 						,p_action_information10         =>l_sum_standard_rate
5090 						,p_action_information11         =>l_sum_special_rate
5091 						,p_action_information12         =>l_sum_payable
5092 						,p_action_information13         =>fnd_number.number_to_canonical(l_sum_year));
5093 						l_index := l_index + 1;
5094 					END IF;
5095 			END LOOP;
5096 		END LOOP;
5097 	END IF;
5098 END LOOP;
5099 	ELSE	--Non-context retro balances
5100 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_run_assign_action_id'||' '||p_run_assign_action_id);
5101 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_payroll_action_id'||' '||p_payroll_action_id);
5102 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_assignment_id'||' '||p_assignment_id);
5103 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_effective_date'||' '||p_effective_date);
5104 
5105 		--hr_utility.set_location('Inside archive_retro_balance_info non context p_balance_name'||p_balance_name,6000);
5106 		l_creator_type(0):='EE';
5107 		l_creator_type(1):='RR';
5108 		l_creator_type(2):='PR';
5109 		l_creator_type(3):='NR';
5110 
5111 		--Get the child action id with highest sequence
5112 		OPEN csr_np_children(p_run_assign_action_id,p_payroll_action_id,
5113 			p_assignment_id,p_effective_date);
5114 		FETCH csr_np_children into l_np_child_id;
5115 		CLOSE csr_np_children;
5116 
5117 		--hr_utility.set_location('Inside archive_retro_balance_info non context l_np_child_id'||l_np_child_id,6010);
5118 
5119 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_np_child_id'||' '||l_np_child_id);
5120 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_balance_name'||' '||p_balance_name);
5121 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_date_earned'||' '||p_date_earned);
5122 		--Get all the retro periods
5123 		OPEN csr_retro_element_periods(l_np_child_id,p_balance_name
5124 		,p_standard_bal_name,p_special_bal_name,p_date_earned,l_bal_init_class_id);
5125 		FETCH csr_retro_element_periods bulk collect into l_element_retro_entries;
5126 		CLOSE csr_retro_element_periods;
5127 
5128 		--hr_utility.set_location('Inside archive_retro_balance_info non context l_element_retro_entries.count'||l_element_retro_entries.count,6120);
5129 
5130 		--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries.count'||' '||l_element_retro_entries.count);
5131 
5132 
5133 		IF l_element_retro_entries.count > 0 THEN
5134 			FOR i in l_element_retro_entries.first..l_element_retro_entries.last
5135 			LOOP
5136 				--hr_utility.set_location('Inside archive_retro_balance_info non context p_balance_name'||p_balance_name,6120);
5137 				FOR j in l_creator_type.first..l_creator_type.last
5138 				LOOP
5139 					l_sum_standard_rate	:='0';
5140 					l_sum_special_rate 	:='0';
5141 					l_sum_payable  		:='0';
5142 					l_sum_year		:=0;
5143 					l_sum_ptd		:=0;
5144 					l_date			:=NULL;
5145 
5146 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries'||' '||l_element_retro_entries(i));
5147 
5148 					FOR csr_np_rec IN csr_np_children(p_run_assign_action_id,
5149 					p_payroll_action_id,p_assignment_id,p_effective_date)
5150 					LOOP
5151 						l_standard_rate		:='0';
5152 						l_special_rate		:='0';
5153 						l_standard_year		:=0;
5154 						l_special_year		:=0;
5155 						l_non_rate		:='0';
5156 						l_rate			:='0';
5157 						l_non_year		:=0;
5158 						l_standard_ptd		:=0;
5159 						l_special_ptd		:=0;
5160 
5161 
5162 						--hr_utility.set_location('Inside archive_retro_balance_info non context csr_np_rec.np_assignment_action_id'||csr_np_rec.np_assignment_action_id,6130);
5163 
5164 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_standard_bal_name'||' '||p_standard_bal_name);
5165 
5166 						--hr_utility.set_location('Inside archive_retro_balance_info non context p_standard_bal_name'||p_standard_bal_name,6140);
5167 
5168 						IF p_standard_bal_name IS NOT NULL THEN
5169 
5170 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'csr_np_rec'||' '||csr_np_rec.np_assignment_action_id);
5171 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_standard_bal_name'||' '||p_standard_bal_name);
5172 							--FND_FILE.PUT_LINE(FND_FILE.LOG,' p_date_earned'||' '||p_date_earned);
5173 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries(i)'||' '||l_element_retro_entries(i));
5174 
5175 							--hr_utility.set_location('Inside archive_retro_balance_info non context p_standard_bal_name'||p_standard_bal_name,6150);
5176 
5177 							OPEN csr_retro_values_nc(csr_np_rec.np_assignment_action_id,p_standard_bal_name
5178 							,p_date_earned,l_element_retro_entries(i),l_creator_type(j),l_bal_init_class_id);
5179 							FETCH csr_retro_values_nc INTO l_value,l_priority;
5180 
5181 							--FND_FILE.PUT_LINE(FND_FILE.LOG,' l_value'||' '||l_value);
5182 
5183 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
5184 							l_flag:=0;
5185 							IF  csr_retro_values_nc%FOUND THEN
5186 								l_standard_rate := l_value;
5187 								l_standard_rate := FND_NUMBER.number_to_canonical(NVL(FND_NUMBER.canonical_to_number(l_standard_rate),0) *
5188 								p_multiply_factor);
5189 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_rate'||' '||l_standard_rate);
5190 								l_sum_standard_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_standard_rate) + FND_NUMBER.canonical_to_number(l_standard_rate));
5191 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_standard_rate'||' '||l_sum_standard_rate);
5192 								l_flag:=1;
5193 								CLOSE csr_retro_values_nc;
5194 							ELSIF p_standard_bal_name = 'Retro Standard Taxable Income' THEN
5195 
5196 								IF csr_retro_values_nc%ISOPEN THEN
5197 									CLOSE csr_retro_values_nc;
5198 								END IF;
5199 								OPEN csr_retro_values_nc(csr_np_rec.np_assignment_action_id
5200 								,'Retro Standard Taxable Income Current Quarter',p_date_earned
5201 								,l_element_retro_entries(i),l_creator_type(j),l_bal_init_class_id);
5202 								FETCH csr_retro_values_nc INTO l_value,l_priority;
5203 
5204 								IF  csr_retro_values_nc%FOUND THEN
5205 									l_standard_rate := l_value;
5206 									l_flag:=1;
5207 								END IF;
5208 								CLOSE csr_retro_values_nc;
5209 								l_standard_rate := FND_NUMBER.number_to_canonical(NVL(FND_NUMBER.canonical_to_number(l_standard_rate),0) *
5210 								p_multiply_factor);
5211 
5212 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_rate'||' '||l_standard_rate);
5213 								l_sum_standard_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_standard_rate) +FND_NUMBER.canonical_to_number( l_standard_rate));
5214 
5215 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_standard_rate'||' '||l_sum_standard_rate);
5216 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
5217 
5218 								--hr_utility.set_location('Inside archive_retro_balance_info non context p_standard_bal_name'||p_standard_bal_name,6160);
5219 							END IF;
5220 							--IF l_flag=1 THEN
5221 								l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_YTD');
5222 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
5223 								IF  l_def_bal_id IS NOT NULL THEN
5224 									l_standard_year := pay_balance_pkg.get_value(l_def_bal_id
5225 									,csr_np_rec.np_assignment_action_id);
5226 								END IF;
5227 								IF /*l_standard_year=0 and*/ p_standard_bal_name = 'Retro Standard Taxable Income' THEN
5228 									l_def_bal_id := get_defined_balance_id ('Retro Standard Taxable Income Current Quarter'
5229 									,'_ASG_YTD');
5230 									IF  l_def_bal_id IS NOT NULL THEN
5231 										 l_standard_year := l_standard_year + pay_balance_pkg.get_value(l_def_bal_id,csr_np_rec.np_assignment_action_id);
5232 									END IF;
5233 	    					    END IF;
5234 								l_standard_year := l_standard_year * p_multiply_factor;
5235 								l_def_bal_id := get_defined_balance_id (p_standard_bal_name,'_ASG_PTD');
5236 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
5237 								IF  l_def_bal_id IS NOT NULL THEN
5238 									l_standard_ptd := pay_balance_pkg.get_value(l_def_bal_id
5239 									,csr_np_rec.np_assignment_action_id);
5240 								END IF;
5241 								IF l_standard_ptd=0 and p_standard_bal_name = 'Retro Standard Taxable Income' THEN
5242 									l_def_bal_id := get_defined_balance_id ('Retro Standard Taxable Income Current Quarter','_ASG_PTD');
5243 									IF  l_def_bal_id IS NOT NULL THEN
5244 										l_standard_ptd := pay_balance_pkg.get_value(l_def_bal_id
5245 										,csr_np_rec.np_assignment_action_id);
5246 									END IF;
5247 								END IF;
5248 						--	END IF;
5249 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_year'||' '||l_standard_year);
5250 
5251 						END IF;
5252 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_special_bal_name'||' '||p_special_bal_name);
5253 
5254 						--hr_utility.set_location('Inside archive_retro_balance_info non context p_special_bal_name'||p_special_bal_name,6170);
5255 						IF csr_retro_values_nc%ISOPEN THEN
5256 						CLOSE csr_retro_values_nc;
5257 						END IF;
5258 
5259 						IF p_special_bal_name IS NOT NULL THEN
5260 							--hr_utility.set_location('Inside archive_retro_balance_info non context p_special_bal_name'||p_special_bal_name,6180);
5261 							OPEN csr_retro_values_nc(csr_np_rec.np_assignment_action_id,p_special_bal_name
5262 							,p_date_earned,l_element_retro_entries(i),l_creator_type(j),l_bal_init_class_id);
5263 							FETCH csr_retro_values_nc INTO l_value,l_priority;
5264 							--FND_FILE.PUT_LINE(FND_FILE.LOG,' l_value'||' '||l_value);
5265 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
5266 
5267 							IF  csr_retro_values_nc%FOUND THEN
5268 								l_special_rate := l_value;
5269 
5270 								l_special_rate :=FND_NUMBER.number_to_canonical(NVL(FND_NUMBER.canonical_to_number(l_special_rate),0) *
5271 								p_multiply_factor);
5272 
5273 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_rate'||' '||l_special_rate);
5274 
5275 								l_sum_special_rate:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_special_rate) + FND_NUMBER.canonical_to_number(l_special_rate));
5276 
5277 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_special_rate'||' '||l_sum_special_rate);
5278 								l_flag:=1;
5279 								CLOSE csr_retro_values_nc;
5280 							END IF;
5281 								--hr_utility.set_location('Inside archive_retro_balance_info non context p_special_bal_name'||p_special_bal_name,6190);
5282 
5283 								l_def_bal_id := get_defined_balance_id (p_special_bal_name,'_ASG_YTD');
5284 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
5285 								IF  l_def_bal_id IS NOT NULL THEN
5286 									l_special_year := pay_balance_pkg.get_value(l_def_bal_id,csr_np_rec.np_assignment_action_id);
5287 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_year'||' '||l_special_year);
5288 								END IF;
5289 								l_special_year := l_special_year * p_multiply_factor;
5290 
5291 								l_def_bal_id := get_defined_balance_id (p_special_bal_name,'_ASG_PTD');
5292 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
5293 
5294 								IF  l_def_bal_id IS NOT NULL THEN
5295 									l_special_ptd := pay_balance_pkg.get_value(l_def_bal_id
5296 									,csr_np_rec.np_assignment_action_id);
5297 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_year'||' '||l_special_year);
5298 								END IF;
5299 							--
5300 							IF csr_retro_values_nc%ISOPEN THEN
5301 								CLOSE csr_retro_values_nc;
5302 							END IF;
5303 						END IF;--End of IF p_special_bal_name IS NOT NULL THEN
5304 
5305 
5306 						--hr_utility.set_location('Inside archive_retro_balance_info non context p_balance_name'||p_balance_name,6200);
5307 
5308 						IF  p_standard_bal_name IS NULL
5309 						AND p_special_bal_name  IS NULL
5310 						AND p_non_tax_bal_name  IS NULL THEN
5311 
5312 							--hr_utility.set_location('Inside archive_retro_balance_info non context p_balance_name'||p_balance_name,6210);
5313 
5314 							OPEN csr_retro_values_nc(csr_np_rec.np_assignment_action_id
5315 							,p_balance_name,p_date_earned,l_element_retro_entries(i),l_creator_type(j),l_bal_init_class_id);
5316 							FETCH csr_retro_values_nc INTO l_value,l_priority;
5317 							--FND_FILE.PUT_LINE(FND_FILE.LOG,' l_value'||' '||l_value);
5318 
5319 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_priority'||' '||l_priority);
5320 					        IF  csr_retro_values_nc%FOUND THEN
5321 								l_rate := l_value;
5322 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_rate'||' '||l_rate);
5323 								l_sum_payable:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_payable) + FND_NUMBER.canonical_to_number(l_rate));
5324 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
5325 
5326 								CLOSE csr_retro_values_nc;
5327 								--hr_utility.set_location('Inside archive_retro_balance_info non context p_balance_name'||p_balance_name,6220);
5328 
5329 								l_def_bal_id := get_defined_balance_id (p_balance_name,'_ASG_YTD');
5330 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_def_bal_id'||' '||l_def_bal_id);
5331 
5332 								IF  l_def_bal_id IS NOT NULL THEN
5333 									l_sum_year := pay_balance_pkg.get_value(l_def_bal_id,csr_np_rec.np_assignment_action_id);
5334 									--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_year'||' '||l_sum_year);
5335 									l_sum_year := l_sum_year * p_multiply_factor;
5336 								END IF;
5337 							END IF;
5338 						ELSE
5339 
5340 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'p_payable_flag'||' '||p_payable_flag);
5341 
5342 							IF p_payable_flag='Y' THEN
5343 								l_sum_payable:=FND_NUMBER.number_to_canonical(FND_NUMBER.canonical_to_number(l_sum_payable) + FND_NUMBER.canonical_to_number(l_sum_standard_rate) + FND_NUMBER.canonical_to_number(l_sum_special_rate));
5344 								--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
5345 							END IF;
5346 
5347 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_standard_year'||' '||l_standard_year);
5348 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_year'||' '||l_special_year);
5349 							IF l_flag = 1 THEN
5350 							  l_sum_year:=l_standard_year + l_special_year;
5351 							END IF;
5352 							--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_year'||' '||l_sum_year);
5353 						END IF;
5354 
5355 						IF csr_retro_values_nc%ISOPEN THEN
5356 							CLOSE csr_retro_values_nc;
5357 						END IF;
5358 						--hr_utility.set_location('Inside archive_retro_balance_info non context l_sum_year'||l_sum_year,6230);
5359 
5360 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_balance_name'||' '||l_balance_name);
5361 						l_balance_name:=p_balance_name;
5362 
5363 						--hr_utility.set_location('Inside archive_retro_balance_info non context l_balance_name'||l_balance_name,6240);
5364 
5365 						OPEN csr_get_translated_bal_name (p_balance_name);
5366 						FETCH csr_get_translated_bal_name INTO l_balance_name;
5367 						IF  csr_get_translated_bal_name%NOTFOUND THEN
5368 							l_balance_name :=hr_general.decode_lookup('HR_NL_REPORT_LABELS',UPPER(p_balance_name));
5369 						END IF;
5370 						CLOSE csr_get_translated_bal_name;
5371 						--hr_utility.set_location('Inside archive_retro_balance_info non context l_balance_name'||l_balance_name,6250);
5372 
5373 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_balance_name'||' '||l_balance_name);
5374 
5375 						l_sum_ptd:=l_standard_ptd + l_special_ptd;
5376 
5377 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'herel_standard_ptd'||' '||l_standard_ptd);
5378 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_special_ptd'||' '||l_special_ptd);
5379 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_ptd'||' '||l_sum_ptd);
5380 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_element_retro_entries(i)'||' '||l_element_retro_entries(i));
5381 						/*Commented codde to fix bug 4035406 - Retro period not displayed for Employee IZA contributions*/
5382 						/*IF l_sum_ptd <>0 THEN*/
5383 						l_date:=fnd_date.date_to_canonical(l_element_retro_entries(i));
5384 						/*END IF;*/
5385 						--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_date'||' '||l_date);
5386 						--
5387 					END LOOP;
5388 
5389 					--hr_utility.set_location('Inside archive_retro_balance_info non context l_date'||l_date,6260);
5390 
5391 
5392 
5393 
5394 
5395 					IF l_balance_name='Retro Employees Private Health' and FND_NUMBER.canonical_to_number(l_sum_standard_rate)=0 THEN
5396 						l_sum_standard_rate:=NULL;
5397 					END IF;
5398 
5399 					IF l_balance_name='Retro Employees Private Health' and FND_NUMBER.canonical_to_number(l_sum_special_rate)=0 THEN
5400 						l_sum_special_rate:=NULL;
5401 					END IF;
5402 
5403 					IF p_payable_flag='N' and FND_NUMBER.canonical_to_number(l_sum_payable) =0 THEN
5404 						l_sum_payable:=NULL;
5405 					END IF;
5406 
5407 					IF p_standard_bal_name IS NULL AND FND_NUMBER.canonical_to_number(l_sum_standard_rate)=0 THEN
5408 					l_sum_standard_rate:=NULL;
5409 				        END IF;
5410 
5411 				        IF p_special_bal_name IS NULL AND FND_NUMBER.canonical_to_number(l_sum_special_rate)=0 THEN
5412 					l_sum_special_rate:=NULL;
5413 				        END IF;
5414 
5415 
5416 
5417 					--hr_utility.set_location('Inside archive_retro_balance_info non context l_sum_standard_rate'||l_sum_standard_rate,6270);
5418 					--hr_utility.set_location('Inside archive_retro_balance_info non context l_sum_year'||l_sum_year,6280);
5419 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_standard_rate'||' '||l_sum_standard_rate);
5420 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_special_rate'||' '||l_sum_special_rate);
5421 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_payable'||' '||l_sum_payable);
5422 					--FND_FILE.PUT_LINE(FND_FILE.LOG, 'l_sum_year'||' '||l_sum_year);
5423 
5424 					/* for 4253974 */
5425 					IF ( p_archive_flag = 'Y' and l_date is not null and
5426 					      (FND_NUMBER.canonical_to_number(l_sum_standard_rate) <> 0   OR
5427 					       FND_NUMBER.canonical_to_number(l_sum_special_rate) <> 0    OR
5428 					       FND_NUMBER.canonical_to_number(l_sum_payable)  <> 0        OR
5429 					       FND_NUMBER.canonical_to_number(l_sum_payable)  IS NOT NULL OR
5430 					       l_sum_year <> 0))
5431 					OR (FND_NUMBER.canonical_to_number(l_sum_standard_rate) <> 0
5432 					OR FND_NUMBER.canonical_to_number(l_sum_special_rate) <> 0
5433 					OR FND_NUMBER.canonical_to_number(l_sum_payable)  <> 0
5434 					OR l_sum_year <> 0) THEN
5435 
5436 						/* IF p_archive_flag = 'Y' OR(FND_NUMBER.canonical_to_number(l_sum_standard_rate) <> 0
5437 						OR FND_NUMBER.canonical_to_number(l_sum_special_rate) <> 0
5438 						OR FND_NUMBER.canonical_to_number(l_sum_payable)  <> 0
5439 						OR FND_NUMBER.canonical_to_number(l_sum_year) <> 0) THEN*/
5440 						-- Archive NL CALCULATIONS
5441 						--
5442 						--pay_action_information_api.create_action_information (..);
5443 						--
5444 
5445 						pay_action_information_api.create_action_information (
5446 						p_action_information_id        => l_action_info_id
5447 						,p_action_context_id            => p_arch_assign_action_id
5448 						,p_action_context_type          => 'AAP'
5449 						,p_object_version_number        => l_ovn
5450 						,p_effective_date               => p_date_earned
5451 						,p_source_id                    => NULL
5452 						,p_source_text                  => NULL
5453 						,p_action_information_category  => 'NL CALCULATIONS'
5454 						,p_action_information4          =>l_index
5455 						,p_action_information5          =>l_priority
5456 						,p_action_information6          =>l_balance_name
5457 						,p_action_information7          =>l_si_type
5458 						,p_action_information8          =>p_type
5459 						,p_action_information9          =>l_date   --Retro Period
5460 						,p_action_information10         =>l_sum_standard_rate
5461 						,p_action_information11         =>l_sum_special_rate
5462 						,p_action_information12         =>l_sum_payable
5463 						,p_action_information13         =>fnd_number.number_to_canonical(l_sum_year));
5464 						l_index := l_index + 1;
5465 
5466 					END IF;
5467 				END LOOP;
5468 			END LOOP;
5469 		END IF;
5470 	END IF;
5471 
5472 END archive_retro_balance_info;
5473 
5474 
5475 
5476 /*-------------------------------------------------------------------------------
5477 |Name           : ARCHIVE_PAYSLIP_BALANCE_INFO     		      	       	        |
5478 |Type			: Procedure							                            |
5479 |Description    : Procedure calls archive_balance_info to archive 		        |
5480 |		  		  NL CALCULATIONS for balances in payment and deduction section	|
5481 -------------------------------------------------------------------------------*/
5482 
5483 PROCEDURE archive_payslip_balance_info(p_arch_assign_action_id    NUMBER
5484 										,p_run_assign_action_id     NUMBER
5485 										,p_date_earned              DATE
5486 										,p_record_count             NUMBER
5487 										,p_payroll_action_id	NUMBER
5488 										,p_assignment_id		NUMBER
5489 										,p_effective_date		DATE) IS
5490 
5491 BEGIN
5492 		--
5493 		-- Archive Gross Salary Balance
5494 		--
5495 
5496 		archive_balance_info(p_arch_assign_action_id
5497 		,p_run_assign_action_id,'Gross Salary','_ASG_YTD'
5498 		,NULL,NULL,NULL
5499 		,1,11000,NULL,p_record_count,p_date_earned
5500 		,'Y','Y',p_payroll_action_id
5501 		,p_assignment_id,p_effective_date);
5502 
5503 		--
5504 		--
5505 		-- Archive Foreigner Rule SI Income Balances
5506 		--
5507 		archive_balance_info(p_arch_assign_action_id
5508 		,p_run_assign_action_id
5509 		,'Foreigner Rule SI Income'
5510 		,'_ASG_YTD'
5511 		,'Foreigner Rule SI Income Standard Adjustment'
5512 		,'Foreigner Rule SI Income Special Adjustment'
5513 		,NULL
5514 		,1
5515 		,14800
5516 		,'D'
5517 		,p_record_count
5518 		,p_date_earned
5519 		,'N'
5520 		,'N'
5521 		,p_payroll_action_id
5522 		,p_assignment_id
5523 		,p_effective_date);
5524 
5525 		--
5526 		--
5527 		-- Archive SI Income Balances
5528 		--
5529 		archive_balance_info(p_arch_assign_action_id
5530 		,p_run_assign_action_id
5531 		,'SI Income'
5532 		,'_ASG_YTD'
5533 		,'SI Income Standard Tax'
5534 		,'SI Income Special Tax'
5535 		,NULL
5536 		,1
5537 		,15000
5538 		,NULL
5539 		,p_record_count
5540 		,p_date_earned
5541 		,'Y'
5542 		,'N'
5543 		,p_payroll_action_id
5544 		,p_assignment_id
5545 		,p_effective_date);
5546 
5547 		--
5548                 --
5549 		--
5550 		-- Archive IZA Income Balances
5551 		--
5552 		/*archive_balance_info(p_arch_assign_action_id
5553 		,p_run_assign_action_id
5554 		,'IZA Income'
5555 		,'_ASG_YTD'
5556 		,'IZA Income Standard Tax'
5557 		,'IZA Income Special Tax'
5558 		,'IZA Income Non Taxable'
5559 		,1
5560 		,15600
5561 		,NULL
5562 		,p_record_count
5563 		,p_date_earned
5564 		,'N'
5565 		,'N'
5566 		,p_payroll_action_id
5567 		,p_assignment_id
5568 		,p_effective_date);*/
5569 
5570 		--
5571 		--
5572 		-- Archive Employer SI Charges  Context Balance
5573 		--
5574 		archive_balance_info(p_arch_assign_action_id
5575 		,p_run_assign_action_id
5576 		,'Employer SI Contribution'
5577 		,'_ASG_SIT_YTD'
5578 		,'Employer SI Contribution Standard Tax'
5579 		,'Employer SI Contribution Special Tax'
5580 		,NULL
5581 		,1
5582 		,16000
5583 		,NULL
5584 		,p_record_count
5585 		,p_date_earned
5586 		,'N'
5587 		,'N'
5588 		,p_payroll_action_id
5589 		,p_assignment_id
5590 		,p_effective_date);
5591 
5592 		--
5593 		--
5594 		-- Archive Employee SI Charges  Context Balance
5595 		--
5596 		archive_balance_info(p_arch_assign_action_id
5597 		,p_run_assign_action_id
5598 		,'Employee SI Contribution'
5599 		,'_ASG_SIT_YTD'
5600 		,'Employee SI Contribution Standard Tax'
5601 		,'Employee SI Contribution Special Tax'
5602 		,'Employee SI Contribution Non Taxable'
5603 		,1
5604 		,17000
5605 		,'D'
5606 		,p_record_count
5607 		,p_date_earned
5608 		,'N'
5609 		,'Y'
5610 		,p_payroll_action_id
5611 		,p_assignment_id
5612 		,p_effective_date);
5613 
5614 		--
5615 		--
5616 		-- Archive Net Employee SI Contribution Context Balance
5617 		--
5618 		archive_balance_info(p_arch_assign_action_id
5619 		,p_run_assign_action_id
5620 		,'Net Employee SI Contribution'
5621 		,'_ASG_SIT_YTD'
5622 		,NULL
5623 		,NULL
5624 		,NULL
5625 		,1
5626 		,18000
5627 		,'D'
5628 		,p_record_count
5629 		,p_date_earned
5630 		,'N'
5631 		,'Y'
5632 		,p_payroll_action_id
5633 		,p_assignment_id
5634 		,p_effective_date);
5635 
5636 --
5637 		--
5638 		-- Archive Foreigner Rule ZVW Income Balances
5639 		--
5640 		archive_balance_info(p_arch_assign_action_id
5641 		,p_run_assign_action_id
5642 		,'Foreigner Rule ZVW Income'
5643 		,'_ASG_YTD'
5644 		,'Foreigner Rule ZVW Income Standard Adjustment'
5645 		,'Foreigner Rule ZVW Income Special Adjustment'
5646 		,NULL
5647 		,1
5648 		,18550
5649 		,'D'
5650 		,p_record_count
5651 		,p_date_earned
5652 		,'N'
5653 		,'N'
5654 		,p_payroll_action_id
5655 		,p_assignment_id
5656 		,p_effective_date);
5657 --
5658 		--
5659 		-- Archive ZVW Income Balances
5660 		--
5661 		archive_balance_info(p_arch_assign_action_id
5662 		,p_run_assign_action_id
5663 		,'ZVW Income'
5664 		,'_ASG_YTD'
5665 		,'ZVW Income Standard Tax'
5666 		,'ZVW Income Special Tax'
5667 		,NULL
5668 		,1
5669 		,18600
5670 		,NULL
5671 		,p_record_count
5672 		,p_date_earned
5673 		,'Y'
5674 		,'N'
5675 		,p_payroll_action_id
5676 		,p_assignment_id
5677 		,p_effective_date);
5678 
5679 		--
5680 
5681 		--
5682 		--
5683 		-- Archive Employee Private Health Contribution  Balance
5684 		--
5685 		/*archive_balance_info(p_arch_assign_action_id
5686 		,p_run_assign_action_id
5687 		,'Employee Private Health Contribution'
5688 		,'_ASG_YTD'
5689 		,NULL
5690 		,NULL
5691 		,NULL
5692 		,1
5693 		,19000
5694 		,'D'
5695 		,p_record_count
5696 		,p_date_earned
5697 		,'Y'
5698 		,'Y'
5699 		,p_payroll_action_id
5700 		,p_assignment_id
5701 		,p_effective_date);
5702 
5703 		--
5704 		--
5705 		-- Archive Nominal IZA Contribution Balance
5706 		--
5707 		archive_balance_info(p_arch_assign_action_id
5708 		,p_run_assign_action_id
5709 		,'Nominal IZA Contribution'
5710 	        ,'_ASG_YTD'
5711 	        ,NULL
5712 	        ,NULL
5713 	        ,NULL
5714 	        ,1
5715 	        ,19550
5716                 ,'D'
5717 	        ,p_record_count
5718 	        ,p_date_earned
5719 	        ,'N'
5720 	        ,'Y'
5721 	        ,p_payroll_action_id
5722 	        ,p_assignment_id
5723 	        ,p_effective_date);
5724 
5725                 --
5726 		--
5727 		-- Archive Employee IZA Contribution  Balance
5728 		--
5729 		archive_balance_info(p_arch_assign_action_id
5730 		,p_run_assign_action_id
5731 		,'Employee IZA Contribution'
5732 		,'_ASG_YTD'
5733 		,NULL
5734 		,NULL
5735 		,NULL
5736 		,1
5737 		,19600
5738 		,'D'
5739 		,p_record_count
5740 		,p_date_earned
5741 		,'N'
5742 		,'Y'
5743 		,p_payroll_action_id
5744 		,p_assignment_id
5745 		,p_effective_date);*/
5746 
5747 		--
5748 		--
5749 		-- Archive Foreigner Rule Standard/Special Balances
5750 		--
5751 		archive_balance_info(p_arch_assign_action_id
5752 		,p_run_assign_action_id
5753 		,'Foreigner Rule (Taxable)'
5754 		,'_ASG_YTD'
5755 		,'Foreigner Rule Standard Tax Adjustment'
5756 		,'Foreigner Rule Special Tax Adjustment'
5757 		,NULL
5758 		,1
5759 		,21000
5760 		,'D'
5761 		,p_record_count
5762 		,p_date_earned
5763 		,'N'
5764 		,'N'
5765 		,p_payroll_action_id
5766 		,p_assignment_id
5767 		,p_effective_date);
5768 
5769 		--
5770 		--
5771 		-- Archive Taxable Balance
5772 		--
5773 		archive_balance_info(p_arch_assign_action_id
5774 		,p_run_assign_action_id
5775 		,'Taxable Income'
5776 		,'_ASG_YTD'
5777 		,'Standard Taxable Income'
5778 		,'Special Taxable Income'
5779 		,NULL
5780 		,1
5781 		,22000
5782 		,NULL
5783 		,p_record_count
5784 		,p_date_earned
5785 		,'Y'
5786 		,'N'
5787 		,p_payroll_action_id
5788 		,p_assignment_id
5789 		,p_effective_date);
5790 
5791 		--
5792 		-- Archive Retro Foreigner Rule SI Income Balances
5793 		--
5794 		archive_retro_balance_info(p_arch_assign_action_id
5795 		,p_run_assign_action_id
5796 		,'Retro Foreigner Rule SI Income'
5797 		,'_ASG_YTD'
5798 		,'Retro Foreigner Rule SI Income Standard Adjustment'
5799 		,'Retro Foreigner Rule SI Income Special Adjustment'
5800 		,NULL
5801 		,1
5802 		,14900
5803 		,'D'
5804 		,p_record_count
5805 		,p_date_earned
5806 		,'N'
5807 		,'N'
5808 		,p_payroll_action_id
5809 		,p_assignment_id
5810 		,p_effective_date);
5811 
5812 		--
5813 		-- Archive Retro SI Income Balances
5814 		--
5815 		archive_retro_balance_info(p_arch_assign_action_id
5816 		,p_run_assign_action_id
5817 		,'Retro SI Income'
5818 		,'_ASG_YTD'
5819 		,'Retro SI Income Standard Tax'
5820 		,'Retro SI Income Special Tax'
5821 		,NULL
5822 		,1
5823 		,15500
5824 		,NULL
5825 		,p_record_count
5826 		,p_date_earned
5827 		,'Y'
5828 		,'N'
5829 		,p_payroll_action_id
5830 		,p_assignment_id
5831 		,p_effective_date);
5832                 --
5833 		-- Archive Retro IZA Income Balances
5834 		--
5835 		/*archive_retro_balance_info(p_arch_assign_action_id
5836 		,p_run_assign_action_id
5837 		,'Retro IZA Income'
5838 		,'_ASG_YTD'
5839 		,'Retro IZA Income Standard Tax'
5840 		,'Retro IZA Income Special Tax'
5841 		,'Retro IZA Income Non Taxable'
5842 		,1
5843 		,15700
5844 		,NULL
5845 		,p_record_count
5846 		,p_date_earned
5847 		,'N'
5848 		,'N'
5849 		,p_payroll_action_id
5850 		,p_assignment_id
5851 		,p_effective_date);*/
5852 
5853 		--
5854 		-- Archive Retro Employer SI Charges  Context Balance
5855 		--
5856 		archive_retro_balance_info(p_arch_assign_action_id
5857 		,p_run_assign_action_id
5858 		,'Retro Employer SI Contribution'
5859 		,'_ASG_SIT_YTD'
5860 		,'Retro Employer SI Contribution Standard Tax'
5861 		,'Retro Employer SI Contribution Special Tax'
5862 		,NULL
5863 		,1
5864 		,16500
5865 		,NULL
5866 		,p_record_count
5867 		,p_date_earned
5868 		,'N'
5869 		,'N'
5870 		,p_payroll_action_id
5871 		,p_assignment_id
5872 		,p_effective_date);
5873 
5874 		--
5875 		-- Archive Retro Employee SI Contribution  Context Balance
5876 		--
5877 		archive_retro_balance_info(p_arch_assign_action_id
5878 		,p_run_assign_action_id
5879 		,'Retro Employee SI Contribution'
5880 		,'_ASG_SIT_YTD'
5881 		,'Retro Employee SI Contribution Standard Tax'
5882 		,'Retro Employee SI Contribution Special Tax'
5883 		,'Retro Employee SI Contribution Non Taxable'
5884 		,1
5885 		,17500
5886 		,'D'
5887 		,p_record_count
5888 		,p_date_earned
5889 		,'N'
5890 		,'Y'
5891 		,p_payroll_action_id
5892 		,p_assignment_id
5893 		,p_effective_date);
5894 
5895 		--
5896 		-- Archive Retro Net Employee SI Contribution Context Balance
5897 		--
5898 		archive_retro_balance_info(p_arch_assign_action_id
5899 		,p_run_assign_action_id
5900 		,'Retro Net Employee SI Contribution'
5901 		,'_ASG_SIT_YTD'
5902 		,NULL
5903 		,NULL
5904 		,NULL
5905 		,1
5906 		,18500
5907 		,'D'
5908 		,p_record_count
5909 		,p_date_earned
5910 		,'N'
5911 		,'Y'
5912 		,p_payroll_action_id
5913 		,p_assignment_id
5914 		,p_effective_date);
5915 
5916 		-- Archive Retro ZVW Income Balances
5917 		--
5918 		archive_retro_balance_info(p_arch_assign_action_id
5919 		,p_run_assign_action_id
5920 		,'Retro ZVW Income'
5921 		,'_ASG_YTD'
5922 		,'Retro ZVW Income Standard Tax'
5923 		,'Retro ZVW Income Special Tax'
5924 		,NULL
5925 		,1
5926 		,18650
5927 		,NULL
5928 		,p_record_count
5929 		,p_date_earned
5930 		,'Y'
5931 		,'N'
5932 		,p_payroll_action_id
5933 		,p_assignment_id
5934 		,p_effective_date);
5935 		--
5936 		--
5937 		-- Archive Retro Employee Private Health Contribution  Balance
5938 		--
5939 	/*	archive_retro_balance_info(p_arch_assign_action_id
5940 		,p_run_assign_action_id
5941 		,'Retro Employee Private Health Contribution'
5942 		,'_ASG_YTD'
5943 		,NULL
5944 		,NULL
5945 		,NULL
5946 		,1
5947 		,19500
5948 		,'D'
5949 		,p_record_count
5950 		,p_date_earned
5951 		,'Y'
5952 		,'Y'
5953 		,p_payroll_action_id
5954 		,p_assignment_id
5955 		,p_effective_date);
5956 
5957 		-- Archive Retro Nominal IZA Contribution Balance
5958 		--
5959 		archive_retro_balance_info(p_arch_assign_action_id
5960                 ,p_run_assign_action_id
5961 	        ,'Retro Nominal IZA Contribution'
5962 	        ,'_ASG_YTD'
5963 	        ,NULL
5964 	        ,NULL
5965 	        ,NULL
5966 	        ,1
5967 	        ,19551
5968                 ,'D'
5969                 ,p_record_count
5970 	        ,p_date_earned
5971 	        ,'N'
5972 	        ,'Y'
5973 	        ,p_payroll_action_id
5974 	        ,p_assignment_id
5975 	        ,p_effective_date);
5976 
5977                 --
5978 		-- Archive Retro Employee IZA Contribution  Balance
5979 		--
5980 		archive_retro_balance_info(p_arch_assign_action_id
5981 		,p_run_assign_action_id
5982 		,'Retro Employee IZA Contribution'
5983 		,'_ASG_YTD'
5984 		,NULL
5985 		,NULL
5986 		,NULL
5987 		,1
5988 		,19700
5989 		,'D'
5990 		,p_record_count
5991 		,p_date_earned
5992 		,'N'
5993 		,'Y'
5994 		,p_payroll_action_id
5995 		,p_assignment_id
5996 		,p_effective_date);*/
5997 
5998 		-- Archive Retro Foreigner Rule Standard/Special Balances
5999 		--
6000 		archive_retro_balance_info(p_arch_assign_action_id
6001 		,p_run_assign_action_id
6002 		,'Retro Foreigner Rule (Taxable)'
6003 		,'_ASG_YTD'
6004 		,'Retro Foreigner Rule Standard Tax Adjustment'
6005 		,'Retro Foreigner Rule Special Tax Adjustment'
6006 		,NULL
6007 		,1
6008 		,21500
6009 		,'D'
6010 		,p_record_count
6011 		,p_date_earned
6012 		,'N'
6013 		,'N'
6014 		,p_payroll_action_id
6015 		,p_assignment_id
6016 		,p_effective_date);
6017 
6018 		--
6019 		-- Archive Retro Taxable Balance
6020 		--
6021 		archive_retro_balance_info(p_arch_assign_action_id
6022 		,p_run_assign_action_id
6023 		,'Retro Taxable Income'
6024 		,'_ASG_YTD'
6025 		,'Retro Standard Taxable Income'
6026 		,'Retro Special Taxable Income'
6027 		,NULL
6028 		,1
6029 		,22500
6030 		,NULL
6031 		,p_record_count
6032 		,p_date_earned
6033 		,'N'
6034 		,'N'
6035 		,p_payroll_action_id
6036 		,p_assignment_id
6037 		,p_effective_date);
6038 --
6039 END archive_payslip_balance_info;
6040 
6041 
6042 
6043 
6044 /*-------------------------------------------------------------------------------
6045 |Name           : ARCHIVE_CODE                                            		|
6046 |Type			: Procedure														|
6047 |Description    : This is the main procedure which calls the several procedures |
6048 |		  			to archive the data.										|
6049 -------------------------------------------------------------------------------*/
6050 
6051 Procedure ARCHIVE_CODE (p_assignment_action_id                 IN NUMBER
6052 	     	       ,p_effective_date                       IN DATE) IS
6053 
6054 
6055 -- Cursor to  return all the Runs for a Pre Payment Process which
6056 -- is being archived.
6057 --
6058 --Bug 3384315
6059 CURSOR csr_assignment_actions(p_locking_action_id NUMBER) IS
6060 SELECT pre.locked_action_id        pre_assignment_action_id,
6061 	   passact.source_action_id    master_pre_asg_action_id,
6062        pay.locked_action_id        master_assignment_action_id,
6063        assact.assignment_id        assignment_id,
6064        assact.payroll_action_id    pay_payroll_action_id,
6065        paa.effective_date          effective_date,
6066        ppaa.effective_date         pre_effective_date,
6067        paa.date_earned             date_earned,
6068        paa.time_period_id          time_period_id,
6069        paa.payroll_id		   payroll_id
6070 FROM   pay_action_interlocks       pre,
6071        pay_action_interlocks       pay,
6072        pay_payroll_actions         paa,
6073        pay_payroll_actions         ppaa,
6074        pay_assignment_actions      assact,
6075        pay_assignment_actions      passact
6076 WHERE  pre.locked_action_id      = pay.locking_action_id
6077 AND    pre.locking_action_id     = p_locking_action_id
6078 AND    pre.locked_action_id      = passact.assignment_action_id
6079 AND    passact.assignment_id	 =assact.assignment_id
6080 AND    passact.payroll_action_id = ppaa.payroll_action_id
6081 AND    ppaa.action_type          IN ('P','U')
6082 AND    pay.locked_action_id      = assact.assignment_action_id
6083 AND    assact.payroll_action_id  = paa.payroll_action_id
6084 AND    assact.source_action_id   IS NULL
6085 ORDER BY pay.locked_action_id DESC;
6086 
6087 cursor csr_get_max_assignment_action(p_assignment_action_id NUMBER)
6088 is
6089 select max(paa.assignment_Action_id) max_assact from
6090 pay_payroll_actions ppa,
6091 pay_assignment_Actions paa,
6092 pay_assignment_Actions paa1
6093 where paa1.assignment_Action_id = p_assignment_action_id
6094 and   paa1.payroll_action_id = ppa.payroll_action_id
6095 and   paa.assignment_id = paa1.assignment_id
6096 and   paa.payroll_action_id = ppa.payroll_action_id;
6097 
6098 
6099 -- Cursor to retrieve all the Child Actions for a given master
6100 -- assignment action.
6101 --
6102 CURSOR csr_child_actions(p_master_assignment_action NUMBER,
6103                          p_payroll_action_id        NUMBER,
6104                          p_assignment_id            NUMBER,
6105                          p_effective_date           DATE  ) IS
6106 SELECT paa.assignment_action_id child_assignment_action_id,
6107        'S'                      run_type
6108 FROM   pay_assignment_actions   paa,
6109        pay_run_types_f          prt
6110 WHERE  paa.source_action_id     = p_master_assignment_action
6111 AND    paa.payroll_action_id    = p_payroll_action_id
6112 AND    paa.assignment_id        = p_assignment_id
6113 AND    paa.run_type_id          = prt.run_type_id
6114 AND    prt.run_method           = 'S'
6115 AND    p_effective_date         BETWEEN prt.effective_start_date
6116                                 AND     prt.effective_end_date
6117 UNION
6118 SELECT paa.assignment_action_id child_assignment_action_id,
6119        'NP'                     run_type --Standard Run, Process Separate Run
6120 FROM   pay_assignment_actions   paa
6121 WHERE  paa.payroll_action_id    = p_payroll_action_id
6122 AND    paa.assignment_id        = p_assignment_id
6123 AND    paa.action_sequence = (
6124             SELECT MAX(paa1.action_sequence)
6125             FROM   pay_assignment_actions paa1,
6126                    pay_run_types_f        prt1
6127             WHERE  prt1.run_type_id         = paa1.run_type_id
6128             AND    prt1.run_method          IN ('N','P')
6129             AND    paa1.payroll_action_id   = p_payroll_action_id
6130             AND    paa1.assignment_id       = p_assignment_id
6131             AND    paa1.source_action_id    = p_master_assignment_action
6132             AND    p_effective_date BETWEEN prt1.effective_start_date
6133                                     AND     prt1.effective_end_date);
6134 
6135 --
6136 -- Cursor to retrieve all N (Normal)and P (Process separate) Child Actions
6137 -- for a given assignment action.
6138 --
6139 CURSOR csr_np_children (p_assignment_action_id NUMBER
6140                        ,p_payroll_action_id    NUMBER
6141                        ,p_assignment_id        NUMBER
6142                        ,p_effective_date       DATE) IS
6143 SELECT paa.assignment_action_id np_assignment_action_id,
6144        prt.run_method           run_method
6145 FROM   pay_assignment_actions   paa
6146       ,pay_run_types_f          prt
6147 WHERE  paa.source_action_id     = p_assignment_action_id
6148 AND    paa.payroll_action_id    = p_payroll_action_id
6149 AND    paa.assignment_id        = p_assignment_id
6150 AND    paa.run_type_id          = prt.run_type_id
6151 AND    prt.run_method           IN ('N','P')
6152 AND    p_effective_date         BETWEEN prt.effective_start_date
6153                                 AND     prt.effective_end_date;
6154 
6155 --Bug No. 3199386
6156 --shveerab
6157 CURSOR csr_period_end_date(p_assignment_action_id NUMBER) IS
6158 SELECT ptp.end_date                end_date,
6159          ptp.regular_payment_date  regular_payment_date,
6160          ptp.time_period_id        time_period_id
6161    FROM  per_time_periods    ptp
6162         ,pay_payroll_actions ppa
6163         ,pay_assignment_actions paa
6164   WHERE  ptp.payroll_id             =ppa.payroll_id
6165     AND  ppa.payroll_action_id      =paa.payroll_action_id
6166     And paa.assignment_action_id    =p_assignment_action_id
6167     AND ppa.date_earned BETWEEN ptp.start_date AND ptp.end_date;
6168 
6169 
6170 l_record_count  	NUMBER;
6171 l_chunk_number		NUMBER;
6172 l_iterative_flag	VARCHAR2(20);
6173 csr_rec			csr_assignment_actions%ROWTYPE;
6174 csr_rec_max             csr_assignment_actions%ROWTYPE;
6175 csr_child_rec		csr_child_actions%ROWTYPE;
6176 max_child_action        csr_child_actions%ROWTYPE;
6177 v_csr_max_assact csr_get_max_assignment_action%ROWTYPE;
6178 l_child_count		NUMBER;
6179 l_actid			NUMBER;
6180 l_action_context_id	NUMBER;
6181 g_archive_pact		NUMBER;
6182 p_assactid		NUMBER;
6183 l_period_end_date	DATE;
6184 l_payment_date		DATE;
6185 l_time_period_id	NUMBER;
6186 l_latest_child_asg_action_id NUMBER;
6187 l_prepay_asg_action_id NUMBER;
6188 l_max_prepay_action_id NUMBER;
6189 l_max_assact_id NUMBER;
6190 l_archive_stat NUMBER;
6191 l_archive_user NUMBER;
6192 l_stat_not_ytd NUMBER;
6193 l_user_not_ytd NUMBER;
6194 l_emp_archived NUMBER;
6195 l_nl_emp_archived NUMBER;
6196 --
6197 
6198 l_dp_de varchar2(2);
6199 
6200 BEGIN
6201 	--
6202 	--hr_utility.trace_on(NULL,'PSA');
6203 	--hr_utility.set_location('Entering Archive Code',800);
6204 	--
6205 	g_zvw_er_cont_std_run := 0;
6206 	g_zvw_er_cont_spl_run := 0;
6207 	g_zvw_er_cont_std_ytd := 0;
6208 	g_zvw_er_cont_spl_ytd := 0;
6209 	g_retro_zvw_er_cont_std_run  := 0;
6210 	g_retro_zvw_er_cont_spl_run  := 0;
6211 	g_retro_zvw_er_cont_std_ytd  := 0;
6212 	g_retro_zvw_er_cont_spl_ytd  := 0;
6213 	g_travel_allowance := 0;
6214 	g_retro_travel_allowance := 0;
6215       g_travel_allowance_ytd := 0;
6216 	g_retro_travel_allowance_ytd := 0;
6217 	--
6218 	-- Retrieve the chunk number for the current assignment action
6219 	--
6220 	SELECT paa.chunk_number
6221 	INTO   l_chunk_number
6222 	FROM   pay_assignment_actions paa
6223 	WHERE  paa.assignment_action_id = p_assignment_action_id;
6224 	--
6225 	l_record_count := 0;
6226 	l_archive_stat := 0;
6227 	l_archive_user := 0;
6228 	l_emp_archived := 0;
6229 	l_nl_emp_archived := 0;
6230 
6231 	--hr_utility.set_location('Inside Archive Code l_chunk_number'||l_chunk_number,850);
6232 	--hr_utility.set_location('Inside Archive Code p_assignment_action_id'||p_assignment_action_id,850);
6233 
6234 	OPEN csr_get_max_assignment_action(p_assignment_action_id);
6235 	FETCH csr_get_max_assignment_action INTO v_csr_max_assact;
6236 	CLOSE csr_get_max_assignment_action;
6237 
6238 
6239 	OPEN csr_assignment_actions(p_assignment_action_id);
6240 	LOOP
6241 		--
6242 		l_iterative_flag := 'N';
6243 		l_prepay_asg_action_id :=0;
6244 
6245 
6246 		--
6247 		FETCH csr_assignment_actions into csr_rec;
6248 
6249 		--Bug 5982957 Starts (To identify the Late Hire Assignments)
6250 		l_dp_de := pay_nl_general.check_de_dp_dimension_old(csr_rec.pay_payroll_action_id
6251 										,csr_rec.assignment_id
6252 										,csr_rec.master_assignment_action_id
6253 										);
6254 		--Bug 5982957 Ends
6255 
6256 		--EXIT when csr_assignment_actions%NOTFOUND or csr_assignment_actions%NOTFOUND IS NULL;
6257 
6258 		-- Archive the employee details for the last row returned by
6259 		-- the cursor csr_assignment_actions.
6260 		-- This will ensure that the the correct time period is passed
6261 		-- to the global package if there are multiple runs in a single
6262 		-- pre payment.
6263 		--
6264 
6265 		hr_utility.set_location('Inside Archive Code csr_rec.pre_assignment_action_id'||csr_rec.pre_assignment_action_id ,900);
6266 		hr_utility.set_location('Inside Archive Code csr_rec.assignment_id'||csr_rec.assignment_id ,900);
6267 		hr_utility.set_location('Inside Archive Code csr_rec.master_assignment_action_id'||csr_rec.master_assignment_action_id ,900);
6268 		hr_utility.set_location('Inside Archive Code g_payroll_action_id'||g_payroll_action_id,900);
6269 
6270 		If csr_assignment_actions%NOTFOUND THEN
6271 			--hr_utility.set_location('Inside Archive Code g_payroll_action_id'||g_payroll_action_id,950);
6272 		--	IF csr_assignment_actions%ROWCOUNT > 0 then
6273 				--Bug No. 3199386
6274 				--shveerab
6275 
6276 			/*	OPEN csr_period_end_date(csr_rec.master_assignment_action_id);
6277 				FETCH csr_period_end_date INTO l_period_end_date , l_payment_date,l_time_period_id;
6278 				CLOSE csr_period_end_date;
6279 				--
6280 				-- Archive EMPLOYEE DETAILS Context
6281 				--
6282 				--hr_utility.set_location('Inside Archive Code g_payroll_action_id'||g_payroll_action_id,1000);
6283 
6284 				--Added Additional Code (Bug:3869788) to Pick Up
6285 				--Prepayment Master Assignment Action Id if Multiple Asg Payment Consoliation is enabled
6286 				--Else Pick up the Prepayment Asg Action Id a before.
6287 				IF csr_rec.master_pre_asg_action_id IS NOT NULL THEN
6288 					l_prepay_asg_action_id := csr_rec.master_pre_asg_action_id;
6289 				ELSE
6290 					l_prepay_asg_action_id := csr_rec.pre_assignment_action_id;
6291 				END IF;
6292 				pay_nl_payslip_archive.archive_employee_details (
6293 				p_payroll_action_id   	=> g_payroll_action_id
6294 				,p_assactid            	=> p_assignment_action_id
6295 				,p_assignment_id       	=> csr_rec.assignment_id
6296 				,p_curr_pymt_ass_act_id	=> l_prepay_asg_action_id
6297 				,p_archive_effective_date => csr_rec.effective_date
6298 				,p_date_earned          	=> csr_rec.date_earned
6299 				,p_curr_pymt_eff_date   	=> l_payment_date
6300 				,p_time_period_id       	=> l_time_period_id
6301 				,p_record_count         	=> l_record_count);
6302 
6303 				pay_nl_payslip_archive.archive_nl_employee_details (
6304 				p_assg_action_id             => p_assignment_action_id
6305 				,p_assignment_id        => csr_rec.assignment_id
6306 				,p_master_asg_act_id 	=> l_latest_child_asg_action_id
6307 				,p_payroll_id		=>csr_rec.payroll_id
6308 				,p_date_earned         => csr_rec.effective_date);*/
6309 
6310 				-- Both User,Statutory Balances AND PAyslip Balances are archived for
6311 				-- S Type actions and the last(highest action sequence) N or P Type
6312 				--
6313 				-- Archive User Balances in EMEA BALANCES Context
6314 				--
6315 
6316 				/*FOR l_index IN 1 .. g_user_balance_table.count
6317 				LOOP
6318 
6319 					hr_utility.set_location('Inside Archive Code  for NP run Type'||g_user_balance_table(l_index).balance_name,1260);
6320 
6321 					pay_nl_payslip_archive.process_balance (
6322 					p_action_context_id => p_assignment_action_id
6323 					, p_assignment_id     => csr_rec.assignment_id
6324 					, p_source_id         => l_latest_child_asg_action_id
6325 					, p_effective_date    => csr_rec.effective_date
6326 					, p_balance           => g_user_balance_table(l_index).balance_name
6327 					, p_dimension         =>
6328 							g_user_balance_table(l_index).database_item_suffix
6329 					, p_defined_bal_id    =>
6330 							g_user_balance_table(l_index).defined_balance_id
6331 					, p_si_type           => g_user_balance_table(l_index).si_type
6332 					, p_record_count      => l_record_count);
6333 				END LOOP;*/
6334 
6335 				--
6336 				-- Archive Statutory Balances in EMEA BALANCES Context
6337 				--
6338 				/*FOR l_index IN 1 .. g_statutory_balance_table.count
6339 				LOOP
6340 
6341 					hr_utility.set_location('Inside Archive Code for NP run Type '||g_statutory_balance_table(l_index).balance_name,1270);
6342 					pay_nl_payslip_archive.process_balance (
6343 					p_action_context_id => p_assignment_action_id
6344 					,p_assignment_id     => csr_rec.assignment_id
6345 					,p_source_id         => l_latest_child_asg_action_id
6346 					,p_effective_date    => csr_rec.effective_date
6347 					,p_balance           => g_statutory_balance_table(l_index).balance_name
6348 					,p_dimension         => g_statutory_balance_table(l_index).database_item_suffix
6349 					,p_defined_bal_id    => g_statutory_balance_table(l_index).defined_balance_id
6350 					,p_si_type           => g_statutory_balance_table(l_index).si_type
6351 					,p_record_count      => l_record_count);
6352 
6353 				END LOOP;*/
6354 				--
6355 				-- Archive Payslip Balances in NL CALCULATIONS Context
6356 				--
6357 				/*pay_nl_payslip_archive.archive_payslip_balance_info(
6358 				p_arch_assign_action_id   => p_assignment_action_id
6359 				, p_run_assign_action_id    =>csr_rec.master_assignment_action_id
6360 				, p_date_earned             => csr_rec.date_earned
6361 				, p_record_count            =>l_record_count
6362 				,p_payroll_action_id        =>csr_rec.pay_payroll_action_id
6363 				,p_assignment_id           => csr_rec.assignment_id
6364 				,p_effective_date	       =>csr_rec.effective_date);*/
6365 
6366 		--	END IF;
6367 			EXIT;
6368 		END IF;
6369 
6370 		--hr_utility.set_location('Inside Archive Code master_assignment_action_id'||csr_rec.master_assignment_action_id,1100);
6371 		--
6372 		-- If child actions exist for the given master action
6373 		--
6374 
6375 		FOR csr_child_rec IN csr_child_actions(
6376 					 csr_rec.master_assignment_action_id,
6377 					 csr_rec.pay_payroll_action_id,
6378 					 csr_rec.assignment_id,
6379 					 csr_rec.effective_date)
6380 
6381 		LOOP
6382 
6383 		--hr_utility.set_location('Inside Archive Code pay_payroll_action_id'||csr_rec.pay_payroll_action_id,1200);
6384 		-- create additional archive assignment actions and interlocks
6385 
6386 		IF csr_child_rec.run_type = 'NP' THEN
6387 			l_child_count := 0;
6388 			FOR csr_np_rec IN csr_np_children(
6389 			csr_rec.master_assignment_action_id,
6390 			csr_rec.pay_payroll_action_id,
6391 			csr_rec.assignment_id,
6392 			csr_rec.effective_date)
6393 			LOOP
6394 				--
6395 				-- Archive Statutory Element Information in NL CALCULATIONS Context
6396 
6397 				pay_nl_payslip_archive.archive_payslip_element_info (
6398 				p_arch_assign_action_id   => p_assignment_action_id
6399 				, p_run_assign_action_id    =>
6400 				csr_np_rec.np_assignment_action_id
6401 				, p_date_earned             => csr_rec.date_earned
6402 				, p_record_count            => l_record_count
6403 				, p_master_assign_action_id => csr_rec.master_assignment_action_id
6404 				, p_payroll_action_id       => csr_rec.pay_payroll_action_id
6405 				, p_assignment_id           => csr_rec.assignment_id
6406 				, p_effective_date	      => csr_rec.effective_date
6407 				, p_child_count	      =>l_child_count);
6408 
6409 
6410 				IF l_child_count = 0 THEN
6411 					--
6412 					-- Archive NL EMPLOYEE DETAILS
6413 					--
6414 				l_latest_child_asg_action_id := csr_np_rec.np_assignment_action_id;
6415 
6416 				--Bug 5982957 Starts
6417 				IF l_dp_de = 'DE' THEN
6418 					pay_nl_payslip_archive.archive_nl_employee_details (
6419 					p_assg_action_id			=> p_assignment_action_id
6420 					,p_assignment_id			=> csr_rec.assignment_id
6421 					,p_master_asg_act_id 		=> l_latest_child_asg_action_id
6422 					,p_payroll_id			=>csr_rec.payroll_id
6423 					--,p_date_earned			=> csr_rec.effective_date);
6424 					,p_date_earned			=> csr_rec.date_earned);
6425 				END IF;
6426 				--Bug 5982957 Ends
6427 
6428 	 		     IF l_emp_archived = 0 THEN
6429 				OPEN csr_period_end_date(csr_rec.master_assignment_action_id);
6430     				FETCH csr_period_end_date INTO l_period_end_date , l_payment_date,l_time_period_id;
6431 				CLOSE csr_period_end_date;
6432     				--
6433     	   			-- Archive EMPLOYEE DETAILS Context
6434 	       			--
6435     				--hr_utility.set_location('Inside Archive Code g_payroll_action_id'||g_payroll_action_id,1000);
6436 
6437     				--Added Additional Code (Bug:3869788) to Pick Up
6438     				--Prepayment Master Assignment Action Id if Multiple Asg Payment Consoliation is enabled
6439     				--Else Pick up the Prepayment Asg Action Id a before.
6440     				IF csr_rec.master_pre_asg_action_id IS NOT NULL THEN
6441     					l_prepay_asg_action_id := csr_rec.master_pre_asg_action_id;
6442     				ELSE
6443     					l_prepay_asg_action_id := csr_rec.pre_assignment_action_id;
6444     				END IF;
6445     				pay_nl_payslip_archive.archive_employee_details (
6446     				p_payroll_action_id   	=> g_payroll_action_id
6447     				,p_assactid            	=> p_assignment_action_id
6448     				,p_assignment_id       	=> csr_rec.assignment_id
6449     				,p_curr_pymt_ass_act_id	=> l_prepay_asg_action_id
6450     				,p_archive_effective_date => csr_rec.effective_date
6451     				,p_date_earned          	=> csr_rec.date_earned
6452     				,p_curr_pymt_eff_date   	=> l_payment_date
6453     				,p_time_period_id       	=> l_time_period_id
6454     				,p_record_count         	=> l_record_count);
6455 
6456 			      IF l_nl_emp_archived = 0 THEN
6457 					--Bug 5982957 extra if condition added
6458 					IF l_dp_de = 'DP' THEN
6459 						pay_nl_payslip_archive.archive_nl_employee_details (
6460 						p_assg_action_id             => p_assignment_action_id
6461 						,p_assignment_id        => csr_rec.assignment_id
6462 						,p_master_asg_act_id 	=> l_latest_child_asg_action_id
6463 						,p_payroll_id		=>csr_rec.payroll_id
6464 						,p_date_earned         => csr_rec.effective_date);
6465 					END IF;
6466 					pay_nl_payslip_archive.archive_payslip_balance_info(
6467 					p_arch_assign_action_id   => p_assignment_action_id
6468 					, p_run_assign_action_id    =>csr_rec.master_assignment_action_id
6469 					, p_date_earned             => csr_rec.date_earned
6470 					, p_record_count            =>l_record_count
6471 					,p_payroll_action_id        =>csr_rec.pay_payroll_action_id
6472 					,p_assignment_id           => csr_rec.assignment_id
6473 					,p_effective_date	       =>csr_rec.effective_date);
6474 				END IF;
6475    				l_emp_archived := 1;
6476     				l_nl_emp_archived := 1;
6477 
6478               END IF;
6479 
6480     		END IF;
6481 
6482 				-- Archive User Element Information in EMEA ELEMENT INFO Context
6483 				pay_nl_payslip_archive.archive_user_element_info (
6484 				p_action_context_id       => p_assignment_action_id
6485 				, p_assignment_id           => csr_rec.assignment_id
6486 				, p_child_assignment_action =>
6487 				csr_np_rec.np_assignment_action_id
6488 				, p_effective_date          => csr_rec.date_earned
6489 				, p_record_count            => l_record_count
6490 				, p_run_method              => csr_np_rec.run_method);
6491 --
6492 				-- Archive Statutory Balances in EMEA BALANCES Context
6493 				--
6494 				FOR l_index IN 1 .. g_statutory_balance_table.count
6495 				LOOP
6496 				        IF (g_statutory_balance_table(l_index).database_item_suffix <> '_ASG_YTD' AND g_statutory_balance_table(l_index).database_item_suffix <> '_ASG_SIT_YTD') THEN
6497 				            l_stat_not_ytd := 1;
6498 				        ELSE
6499 				            l_stat_not_ytd := 0;
6500 				        END IF;
6501 				        IF ((v_csr_max_assact.max_assact <> p_assignment_action_id AND (l_stat_not_ytd = 1))
6502 				           OR (v_csr_max_assact.max_assact = p_assignment_action_id AND csr_np_rec.np_assignment_action_id <> csr_child_rec.child_assignment_action_id AND (l_stat_not_ytd = 1))
6503 				           OR v_csr_max_assact.max_assact = p_assignment_action_id AND csr_np_rec.np_assignment_action_id = csr_child_rec.child_assignment_action_id AND (l_archive_stat = 0 OR (l_archive_stat = 1 AND l_stat_not_ytd = 1))) THEN
6504 					hr_utility.set_location('Inside Archive Code for NP run Type '||g_statutory_balance_table(l_index).balance_name,1270);
6505 					pay_nl_payslip_archive.process_balance (
6506 					p_action_context_id => p_assignment_action_id
6507 					,p_assignment_id     => csr_rec.assignment_id
6508 					,p_source_id         => csr_np_rec.np_assignment_action_id
6509 					,p_effective_date    => csr_rec.effective_date
6510 					,p_balance           => g_statutory_balance_table(l_index).balance_name
6511 					,p_dimension         => g_statutory_balance_table(l_index).database_item_suffix
6512 					,p_defined_bal_id    => g_statutory_balance_table(l_index).defined_balance_id
6513 					,p_si_type           => g_statutory_balance_table(l_index).si_type
6514 					,p_record_count      => l_record_count);
6515 					END IF;
6516 
6517 				END LOOP;
6518 
6519 				-- Archive User Balances in EMEA BALANCES Context
6520 				--
6521 				FOR l_index IN 1 .. g_user_balance_table.count
6522 				LOOP
6523 				         IF (g_user_balance_table(l_index).database_item_suffix <> '_ASG_YTD' AND g_user_balance_table(l_index).database_item_suffix <> '_ASG_SIT_YTD') THEN
6524 					     l_user_not_ytd := 1;
6525 					   ELSE
6526 					     l_user_not_ytd := 0;
6527 				         END IF;
6528 				        IF ((v_csr_max_assact.max_assact <> p_assignment_action_id AND (l_user_not_ytd = 1))
6529 				        OR (v_csr_max_assact.max_assact = p_assignment_action_id AND csr_np_rec.np_assignment_action_id <> csr_child_rec.child_assignment_action_id AND (l_user_not_ytd = 1))
6530 				           OR v_csr_max_assact.max_assact = p_assignment_action_id AND csr_np_rec.np_assignment_action_id = csr_child_rec.child_assignment_action_id AND (l_archive_user = 0 OR (l_archive_user = 1 AND l_user_not_ytd = 1))) THEN
6531 					hr_utility.set_location('Inside Archive Code  for NP run Type'||g_user_balance_table(l_index).balance_name,1260);
6532 				        pay_nl_payslip_archive.process_balance (
6533 					p_action_context_id => p_assignment_action_id
6534 					, p_assignment_id     => csr_rec.assignment_id
6535 					, p_source_id         => csr_np_rec.np_assignment_action_id
6536 					, p_effective_date    => csr_rec.effective_date
6537 					, p_balance           => g_user_balance_table(l_index).balance_name
6538 					, p_dimension         => g_user_balance_table(l_index).database_item_suffix
6539 					, p_defined_bal_id    => g_user_balance_table(l_index).defined_balance_id
6540 					, p_si_type           => g_user_balance_table(l_index).si_type
6541 					, p_record_count      => l_record_count);
6542 					END IF;
6543 				END LOOP;
6544 
6545 				l_child_count := l_child_count + 1;
6546 
6547 			END LOOP;
6548 
6549 			END IF;
6550 
6551 			l_iterative_flag := 'Y';
6552 
6553 			END LOOP; -- child assignment actions
6554 			--
6555 
6556 			--hr_utility.set_location('Inside Archive Code l_record_count'||l_record_count,1300);
6557 
6558 			--
6559 			-- Archive for the main run
6560 			--
6561 			-- This section of the code can be removed once iterative engine setup has
6562 			-- been enabled for NL.i.e when rule type has been sedded for NL
6563 			--
6564 			--hr_utility.set_location('Inside Archive Code l_record_count'||l_record_count,1400);
6565 			--hr_utility.set_location('Inside Archive Code l_iterative_flag'||l_iterative_flag,1400);
6566 
6567 	IF  l_iterative_flag = 'N' THEN
6568 		--
6569 		-- Archive NL EMPLOYEE DETAILS,NL OTHER EMPLOYEE DETAILS
6570 		-- and NL SI EMPLOYEE DETAILS
6571 		--
6572 		--Bug 5982957 (Extra condition added "and l_dp_de= DP/DE")
6573 		IF l_nl_emp_archived = 0 and l_dp_de = 'DP' THEN
6574 			pay_nl_payslip_archive.archive_nl_employee_details (
6575 			p_assg_action_id        => p_assignment_action_id
6576 			,p_master_asg_act_id	=>csr_rec.master_assignment_action_id
6577 			,p_assignment_id        => csr_rec.assignment_id
6578 			,p_payroll_id           => csr_rec.payroll_id
6579 			,p_date_earned		=> csr_rec.effective_date);
6580 		ELSIF l_nl_emp_archived = 0 and l_dp_de = 'DE' THEN
6581 			pay_nl_payslip_archive.archive_nl_employee_details (
6582 			p_assg_action_id        => p_assignment_action_id
6583 			,p_master_asg_act_id	=> csr_rec.master_assignment_action_id
6584 			,p_assignment_id        => csr_rec.assignment_id
6585 			,p_payroll_id           => csr_rec.payroll_id
6586 			--,p_date_earned		=> csr_rec.effective_date);
6587 			,p_date_earned		=> csr_rec.date_earned);
6588 		END IF;
6589 
6590 		--hr_utility.set_location('Inside Archive Code p_assignment_action_id'||p_assignment_action_id,1500);
6591 
6592 		-- Archive User Element Information in EMEA ELEMENT INFO Context
6593 		pay_nl_payslip_archive.archive_user_element_info (
6594 		p_action_context_id       => p_assignment_action_id
6595 		, p_assignment_id           => csr_rec.assignment_id
6596 		, p_child_assignment_action =>
6597 		csr_rec.master_assignment_action_id
6598 		, p_effective_date          => csr_rec.date_earned
6599 		, p_record_count            => l_record_count
6600 		, p_run_method              => NULL);
6601 
6602 		--hr_utility.set_location('Inside Archive Code csr_rec.master_assignment_action_id'||csr_rec.master_assignment_action_id,1600);
6603 
6604 		-- Archive Statutory Element Information in NL CALCULATIONS Context
6605 
6606 		pay_nl_payslip_archive.archive_payslip_element_info (
6607 		p_arch_assign_action_id   => p_assignment_action_id
6608 		, p_run_assign_action_id    =>
6609 		csr_rec.master_assignment_action_id
6610 		, p_date_earned          => csr_rec.date_earned
6611 		, p_record_count            => l_record_count
6612 		, p_master_assign_action_id => csr_rec.master_assignment_action_id
6613 		, p_payroll_action_id       => csr_rec.pay_payroll_action_id
6614 		, p_assignment_id           => csr_rec.assignment_id
6615 		, p_effective_date	      => csr_rec.effective_date
6616 		, p_child_count	      =>l_child_count);
6617 
6618 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||l_iterative_flag,1700);
6619 		--
6620 		-- Archive User Balances
6621 		--
6622 		FOR l_index IN 1 .. g_user_balance_table.count
6623 		LOOP
6624 			--hr_utility.set_location('Inside Archive Code balance_name'||g_user_balance_table(l_index).balance_name,1800);
6625 			--hr_utility.set_location('Inside Archive Code database_item_suffix'||g_user_balance_table(l_index).database_item_suffix,1800);
6626 			--hr_utility.set_location('Inside Archive Code defined_balance_id'||g_user_balance_table(l_index).defined_balance_id,1800);
6627 			--hr_utility.set_location('Inside Archive Code si_type'||g_user_balance_table(l_index).si_type,1800);
6628 			--hr_utility.set_location('Inside Archive Code l_index'||l_index,1800);
6629 			--hr_utility.set_location('Inside Archive Code g_user_balance_table.count '||g_user_balance_table.count ,1800);
6630 			--hr_utility.set_location('Inside Archive Code master_assignment_action_id'||csr_rec.master_assignment_action_id,1800);
6631 			--hr_utility.set_location('Inside Archive Code csr_rec.date_earned '||csr_rec.date_earned ,1800);
6632 			--hr_utility.set_location('Inside Archive Code csr_rec.effective_date '||csr_rec.effective_date,1800);
6633 			--hr_utility.set_location('Inside Archive Code p_assignment_action_id '||p_assignment_action_id,1800);
6634 			--hr_utility.set_location('Inside Archive Code l_record_count '||l_record_count,1800);
6635 			--hr_utility.set_location('Inside Archive Code csr_rec.assignment_id '||csr_rec.assignment_id,1800);
6636 
6637 			BEGIN
6638 				pay_nl_payslip_archive.process_balance (
6639 				p_action_context_id => p_assignment_action_id
6640 				, p_assignment_id     => csr_rec.assignment_id
6641 				, p_source_id         => csr_rec.master_assignment_action_id
6642 				, p_effective_date    => csr_rec.effective_date
6643 				, p_balance           =>
6644 				g_user_balance_table(l_index).balance_name
6645 				, p_dimension         =>
6646 				g_user_balance_table(l_index).database_item_suffix
6647 				, p_defined_bal_id    =>
6648 				g_user_balance_table(l_index).defined_balance_id
6649 				,p_si_type           =>
6650 				g_user_balance_table(l_index).si_type
6651 				, p_record_count      => l_record_count);
6652 
6653 
6654 			EXCEPTION
6655 			WHEN OTHERS THEN
6656 				hr_utility.set_location('Inside Archive Code Exception'||SQLCODE||'sqlerr'||SQLERRM,1800);
6657 				raise;
6658 			END;
6659   		END LOOP;
6660 
6661 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||l_iterative_flag,1900);
6662 		--
6663 		-- Archive Statutory Balances
6664 		--
6665 		--hr_utility.set_location('Inside Archive Code l_count'||g_statutory_balance_table.count,2000);
6666 
6667 		FOR l_index IN 1 .. g_statutory_balance_table.count LOOP
6668 
6669 		--hr_utility.set_location('Inside Archive Code l_index'||l_index,2001);
6670 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||g_statutory_balance_table(l_index).balance_name,2001);
6671 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||g_statutory_balance_table(l_index).database_item_suffix,2001);
6672 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||g_statutory_balance_table(l_index).defined_balance_id,2001);
6673 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||g_statutory_balance_table(l_index).si_type,2001);
6674 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||l_record_count,2001);
6675 
6676 			pay_nl_payslip_archive.process_balance (
6677 			p_action_context_id => p_assignment_action_id
6678 			,p_assignment_id     => csr_rec.assignment_id
6679 			,p_source_id         => csr_rec.master_assignment_action_id
6680 			,p_effective_date    => csr_rec.effective_date
6681 			,p_balance           =>
6682 			g_statutory_balance_table(l_index).balance_name
6683 			,p_dimension         =>
6684 			g_statutory_balance_table(l_index).database_item_suffix
6685 			,p_defined_bal_id    =>
6686 			g_statutory_balance_table(l_index).defined_balance_id
6687 			,p_si_type           =>
6688 			g_statutory_balance_table(l_index).si_type
6689 			,p_record_count      => l_record_count);
6690 		END LOOP;
6691 
6692 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||l_iterative_flag,2100);
6693 		--
6694 		-- Archive Payslip Balances(displayed in payments deductions
6695 		-- section)  in NL CALCULATIONS Context
6696 		--
6697 		--hr_utility.set_location('Inside Archive Code p_assignment_action_id'||p_assignment_action_id,2100);
6698 		--hr_utility.set_location('Inside Archive Code csr_rec.master_assignment_action_id'||csr_rec.master_assignment_action_id,2100);
6699 		--hr_utility.set_location('Inside Archive Code csr_rec.date_earned'||csr_rec.date_earned,2100);
6700 		--hr_utility.set_location('Inside Archive Code l_record_count'||l_record_count,2100);
6701 	              IF l_nl_emp_archived = 0 THEN
6702 		pay_nl_payslip_archive.archive_payslip_balance_info(
6703 		p_arch_assign_action_id   => p_assignment_action_id
6704 		, p_run_assign_action_id    =>
6705 		  csr_rec.master_assignment_action_id
6706 		, p_date_earned             => csr_rec.date_earned
6707 		, p_record_count            => l_record_count
6708 		,p_payroll_action_id        =>csr_rec.pay_payroll_action_id
6709 		,p_assignment_id           => csr_rec.assignment_id
6710 		,p_effective_date	       =>csr_rec.effective_date);
6711 	              END IF;
6712 		l_nl_emp_archived := 1;
6713 
6714 		--hr_utility.set_location('Inside Archive Code l_iterative_flag'||l_iterative_flag,2200);
6715 		--
6716 	END IF;
6717 	l_record_count := l_record_count + 1;
6718 	l_archive_stat := 1;
6719 	l_archive_user := 1;
6720 END LOOP;
6721 close csr_assignment_actions;
6722 
6723 
6724 
6725 --hr_utility.set_location('Leaving Archive code',2300);
6726 --
6727 END ARCHIVE_CODE;
6728 
6729 END PAY_NL_PAYSLIP_ARCHIVE;