DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_GB_PROCESS_P11D_ENTRIES_PKG

Source


1 PACKAGE BODY HR_GB_PROCESS_P11D_ENTRIES_PKG as
2 /* $Header: pygbp11d.pkb 120.18.12010000.2 2008/08/06 07:18:43 ubhat ship $ */
3     g_package            constant VARCHAR2(33) := '  hr_gb_process_p11d_entries_pkg.';
4    procedure  clob_to_blob(p_clob clob,
5                            p_blob in out nocopy Blob)
6    is
7         l_length_clob number;
8         l_offset integer;
9         l_varchar_buffer varchar2(32000);
10         l_raw_buffer raw(32000);
11         l_buffer_len number:= 32000;
12         l_chunk_len number;
13         l_blob blob;
14    begin
15         l_length_clob := dbms_lob.getlength(p_clob);
16         l_offset := 1;
17         while l_length_clob > 0 loop
18               hr_utility.trace('l_length_clob '|| l_length_clob);
19               if l_length_clob < l_buffer_len then
20                  l_chunk_len := l_length_clob;
21               else
22                   l_chunk_len := l_buffer_len;
23               end if;
24               DBMS_LOB.READ(p_clob,l_chunk_len,l_offset,l_varchar_buffer);
25               l_raw_buffer := utl_raw.cast_to_raw(l_varchar_buffer);
26               dbms_lob.write(p_blob,l_chunk_len, l_offset, l_raw_buffer);
27               l_offset := l_offset + l_chunk_len;
28               l_length_clob := l_length_clob - l_chunk_len;
29               hr_utility.trace('l_length_blob '|| dbms_lob.getlength(p_blob));
30         end loop;
31    end;
32 
33    procedure delete_entries(errbuf              out nocopy VARCHAR2,
34                             retcode             out nocopy NUMBER,
35                             p_element_type_id   in pay_element_types_f.element_type_id%type,
36                             p_start_date        in VARCHAR2,
37                             p_end_date          in VARCHAR2,
38                             p_bus_grp_id        in pay_element_types_f.business_group_id%type,
39                             p_assignment_set_id in Number   )
40    is
41         l_ben_start_date_id           pay_input_values_f.input_value_id%type;
42         l_ben_end_date_id             pay_input_values_f.input_value_id%type;
43         l_element_name                pay_element_types_f.element_name%type;
44         l_count                       NUMBER default 0;
45         l_effective_start_date_dummy  DATE;
46         l_effective_end_date_dummy    DATE;
47         l_del_warning_dummy           BOOLEAN;
48         e_p11d_element_err            exception;
49         e_p11d_ben_st_dt_err          exception;
50         e_p11d_ben_end_dt_err         exception;
51         cursor csr_get_element_name(v_element_type_id pay_element_types_f.element_type_id%type)
52         is
53         select element_name
54         from   pay_element_types_f pet
55         where  pet.element_type_id = v_element_type_id;
56 
57         cursor csr_get_benefit_date_id(v_ben_date_type   VARCHAR2,
58                                        v_element_type_id pay_element_types_f.element_type_id%type)
59         is
60         select input_value_id
61         from   pay_input_values_f piv
62         where  piv.element_type_id = v_element_type_id
63         and    piv.NAME = v_ben_date_type;
64 
65         cursor csr_get_del_element_entry_id(v_ben_start_date_id  pay_input_values_f.input_value_id%type,
66                                             v_start_date         VARCHAR2,
67                                             v_ben_end_date_id    pay_input_values_f.input_value_id%type,
68                                             v_end_date           VARCHAR2,
69                                             v_bus_grp_id         pay_element_types_f.business_group_id%type,
70                                             v_element_type_id    pay_element_types_f.element_type_id%type)
71         is
72         select /*+ ordered */
73               pee.element_entry_id, pee.object_version_number, pee.effective_start_date
74         from  pay_element_links_f pel,
75               pay_element_entries_f pee,
76               pay_element_entry_values_f peev_sd,
77               pay_element_entry_values_f peev_ed
78         where pel.element_type_id = v_element_type_id
79         and   pee.element_link_id = pel.element_link_id
80         and   pee.effective_start_date between pel.effective_start_date and pel.effective_end_date
81         and   pee.effective_end_date between pel.effective_start_date and pel.effective_end_date
82         and   peev_sd.element_entry_id = pee.element_entry_id
83         and   peev_ed.element_entry_id = pee.element_entry_id
84         and   peev_sd.element_entry_id = peev_ed.element_entry_id
85         and   peev_sd.input_value_id = v_ben_start_date_id
86         and   peev_sd.screen_entry_value >= v_start_date
87         and   peev_ed.input_value_id = v_ben_end_date_id
88         and   peev_ed.screen_entry_value <= v_end_date
89         and exists( select /*+ no_unnest */
90                                    1
91                     from  per_all_assignments_f paa
92                     where paa.assignment_id = pee.assignment_id
93                     and   paa.business_group_id = v_bus_grp_id);
94 
95         cursor csr_del_entries_assignset(v_ben_start_date_id pay_input_values_f.input_value_id%type,
96                                          v_start_date        VARCHAR2,
97                                          v_ben_end_date_id   pay_input_values_f.input_value_id%type,
98                                          v_end_date          VARCHAR2,
99                                          v_bus_grp_id        pay_element_types_f.business_group_id%type,
100                                          v_element_type_id   pay_element_types_f.element_type_id%type,
101                                          v_assignment_set_id Number)
102         is
103         select /*+ ordered */
104               pee.element_entry_id, pee.object_version_number, pee.effective_start_date
105         from  pay_element_links_f pel,
106               pay_element_entries_f pee,
107               pay_element_entry_values_f peev_sd,
108               pay_element_entry_values_f peev_ed
109         where pel.element_type_id = v_element_type_id
110         and   pee.element_link_id = pel.element_link_id
111         and   pee.effective_start_date between pel.effective_start_date and pel.effective_end_date
112         and   pee.effective_end_date between pel.effective_start_date and pel.effective_end_date
113         and   peev_sd.element_entry_id = pee.element_entry_id
114         and   peev_ed.element_entry_id = pee.element_entry_id
115         and   peev_sd.element_entry_id = peev_ed.element_entry_id
116         and   peev_sd.input_value_id = v_ben_start_date_id
117         and   peev_sd.screen_entry_value >= v_start_date
118         and   peev_ed.input_value_id = v_ben_end_date_id
119         and   peev_ed.screen_entry_value <= v_end_date
120         and exists( select /*+ no_unnest */
121                            1
122                     from  per_all_assignments_f paa,
123                           hr_assignment_sets has,
124                           hr_assignment_set_amendments hasa
125                     where paa.assignment_id = pee.assignment_id
126                     and   paa.business_group_id = v_bus_grp_id
127                     and   (    has.assignment_set_id = v_assignment_set_id
128                            and nvl(has.payroll_id, paa.payroll_id) = paa.payroll_id
129                            and has.assignment_set_id = hasa.assignment_set_id(+)
130                            and nvl(hasa.include_or_exclude, 'I') = 'I'
131                            and nvl(hasa.assignment_id, paa.assignment_id) = paa.assignment_id));
132 
133    -- BEGIN of the procedure delete_entries
134    begin
135         -- initialize the return code to 0
136         retcode := 0;
137         -- get the element name
138         open csr_get_element_name(p_element_type_id);
139         fetch csr_get_element_name into l_element_name;
140         if csr_get_element_name%notfound
141         then
142             close csr_get_element_name;
143             hr_utility.TRACE('Incorrect element type id '|| p_element_type_id);
144             raise e_p11d_element_err;
145         end if;
146         close csr_get_element_name;
147         hr_utility.TRACE('Value of element name='|| l_element_name);
148         -- get the benefit start date id
149         open csr_get_benefit_date_id(c_ben_start_date_string, p_element_type_id);
150         fetch csr_get_benefit_date_id into l_ben_start_date_id;
151         if csr_get_benefit_date_id%notfound
152         then
153             close csr_get_benefit_date_id;
154             hr_utility.TRACE('No Benefit Start date defined for element ');
155             raise e_p11d_ben_st_dt_err;
156         end if;
157         close csr_get_benefit_date_id;
158         hr_utility.TRACE('Value of benefit start date id = '|| to_char(l_ben_start_date_id) );
159         -- get the benefit END date id;
160         open csr_get_benefit_date_id(c_ben_end_date_string, p_element_type_id);
161         fetch csr_get_benefit_date_id into l_ben_end_date_id;
162         if csr_get_benefit_date_id%notfound
163         then
164             close csr_get_benefit_date_id;
165             hr_utility.TRACE('No Benefit End date defined for element type id ');
166             raise e_p11d_ben_end_dt_err;
167         end if;
168         close csr_get_benefit_date_id;
169         hr_utility.TRACE('Value of benefit end date  id ='|| to_char(l_ben_end_date_id) );
170         -- get the elementry id WHERE the start date is greater than the p_start_date
171         -- AND END date is less than the p_end_date. Only those element entry id's will
172         -- be returned WHERE the business group id is p_bus_grp_id
173         hr_utility.TRACE('p_start_date '|| p_start_date);
174         hr_utility.TRACE('p_end_date '|| p_end_date);
175         hr_utility.TRACE('p_bus_grp_id '|| p_bus_grp_id);
176         hr_utility.TRACE('p_element_type_id '|| p_element_type_id);
177         if p_assignment_set_id is null then
178            for del_element_entry in csr_get_del_element_entry_id(
179                                       l_ben_start_date_id,
180                                       p_start_date,
181                                       l_ben_end_date_id,
182                                       p_end_date,
183                                       p_bus_grp_id,
184                                       p_element_type_id)
185            loop
186                l_count := l_count + 1;
187                hr_utility.TRACE('Delete entries for element entry id '|| to_char(del_element_entry.element_entry_id) );
188                pay_element_entry_api.delete_element_entry(p_datetrack_delete_mode => 'ZAP',
189                                                           p_effective_date        => del_element_entry.effective_start_date,
190                                                           p_element_entry_id      => del_element_entry.element_entry_id,
191                                                           p_object_version_number => del_element_entry.object_version_number,
192                                                           p_effective_start_date  => l_effective_start_date_dummy,
193                                                           p_effective_end_date    => l_effective_end_date_dummy,
194                                                           p_delete_warning        => l_del_warning_dummy);
195                if mod(l_count, c_commit_num) = 0
196                then
197                    commit;
198                    hr_utility.TRACE('Commiting delete, counter = '|| to_char(l_count) );
199                end if;
200            end loop;
201         else
202            for del_element_entry in csr_del_entries_assignset(
203                                       l_ben_start_date_id,
204                                       p_start_date,
205                                       l_ben_end_date_id,
206                                       p_end_date,
207                                       p_bus_grp_id,
208                                       p_element_type_id,
209                                       p_assignment_set_id)
210            loop
211                l_count := l_count + 1;
212                hr_utility.TRACE('Delete entries for element entry id '|| to_char(del_element_entry.element_entry_id) );
213                pay_element_entry_api.delete_element_entry(p_datetrack_delete_mode => 'ZAP',
214                                                           p_effective_date        => del_element_entry.effective_start_date,
215                                                           p_element_entry_id      => del_element_entry.element_entry_id,
216                                                           p_object_version_number => del_element_entry.object_version_number,
217                                                           p_effective_start_date  => l_effective_start_date_dummy,
218                                                           p_effective_end_date    => l_effective_end_date_dummy,
219                                                           p_delete_warning        => l_del_warning_dummy);
220                if mod(l_count, c_commit_num) = 0
221                then
222                    commit;
223                    hr_utility.TRACE('Commiting delete, counter = '|| to_char(l_count) );
224                end if;
225            end loop;
226         end if;
227         commit;
228    exception
229      when e_p11d_element_err
230      then
231          hr_utility.set_message(800, 'HR_78046_GB_P11D_ELEMENT_ERR');
232          hr_utility.set_message_token(800, 'ELEMENT', l_element_name);
233          errbuf := hr_utility.get_message;
234          hr_utility.raise_error;
235          retcode := 1;
236          rollback;
237      when e_p11d_ben_st_dt_err
238      then
239          hr_utility.set_message(800, 'HR_78047_GB_P11D_BEN_ST_DT_ERR');
240          hr_utility.set_message_token(800, 'ELEMENT', l_element_name);
241          errbuf := hr_utility.get_message;
242          hr_utility.raise_error;
243          retcode := 1;
244          rollback;
245      when e_p11d_ben_end_dt_err
246      then
247          hr_utility.set_message(800, 'HR_78048_GB_P11D_BEN_ED_DT_ERR');
248          hr_utility.set_message_token(800, 'ELEMENT', l_element_name);
249          errbuf := hr_utility.get_message;
250          hr_utility.raise_error;
251          retcode := 1;
252          rollback;
253      when OTHERS
254      then
255          if csr_get_element_name%isopen
256          then
257              close csr_get_element_name;
258          end if;
259          if csr_get_benefit_date_id%isopen
260          then
261              close csr_get_benefit_date_id;
262          end if;
263          if csr_get_del_element_entry_id%isopen
264          then
265              close csr_get_del_element_entry_id;
266          end if;
267          hr_utility.set_message(800, 'HR_78045_GB_P11D_DEL_ERR');
268          hr_utility.set_message_token(800, 'ERRORMSG', sqlerrm);
269          errbuf := hr_utility.get_message;
270          hr_utility.raise_error;
271          retcode := 1;
272          rollback;
273    end delete_entries;
274 
275    function get_null_error(p_token1 in VARCHAR2,
276                            p_token2 in VARCHAR2,
277                            p_token3 in VARCHAR2)return VARCHAR2
278    is
279         l_errmsg                      VARCHAR2(1000);
280    begin
281         hr_utility.set_message(800, 'HR_78052_GB_P11D_VALUES_NULL');
282         hr_utility.set_message_token(800, '1INPUT_VALUE', p_token1);
283         hr_utility.set_message_token(800, '2INPUT_VALUE', p_token2);
284         -- hr_utility.set_message_token (800, '3INPUT_VALUE', p_token3);
285         l_errmsg := hr_utility.get_message;
286         return l_errmsg;
287    end get_null_error;
288 
289    function get_incorrect_val_error(p_token1 in VARCHAR2,
290                                     p_token2 in VARCHAR2,
291                                     p_token3 in VARCHAR2) return VARCHAR2
292    is
293         l_errmsg                      VARCHAR2(1000);
294    begin
295         hr_utility.set_message(800, 'HR_78051_GB_P11D_INCORRECT_VAL');
296         hr_utility.set_message_token(800, '1INPUT_VALUE', p_token1);
297         hr_utility.set_message_token(800, '2INPUT_VALUE', p_token2);
298         hr_utility.set_message_token(800, '3INPUT_VALUE', p_token3);
299         l_errmsg := hr_utility.get_message;
300         return l_errmsg;
301    end get_incorrect_val_error;
302 
303    function get_error_message(p_applid in NUMBER,
304                               p_message_name in VARCHAR2) return VARCHAR2
305    is
306         l_errmsg                      VARCHAR2(1000);
307    begin
308         hr_utility.set_message(p_applid, p_message_name);
309         l_errmsg := hr_utility.get_message;
310         return l_errmsg;
311    end get_error_message;
312 
313    function get_loan_amount(p_archive_payroll_action_id in VARCHAR2,
314                             p_employers_ref_no          in VARCHAR2,
315                             --p_employers_name      IN   VARCHAR2,
316                             p_person_id                 in VARCHAR2) return VARCHAR2
317    is
318         l_loan_amount                 NUMBER;
319    begin
320         select sum(nvl(pai.action_information7, 0) )
321         into  l_loan_amount
322         from  pay_action_information pai_comp,
323               pay_action_information pai_person,
324               pay_action_information pai,
325               pay_assignment_actions paa,
326               pay_payroll_actions ppa
327         where ppa.payroll_action_id = p_archive_payroll_action_id
328         and   ppa.payroll_action_id = paa.payroll_action_id
329         and   pai_comp.action_context_id = paa.assignment_action_id
330         and   pai_comp.action_information_category = 'EMEA PAYROLL INFO'
331         and   pai_comp.action_context_type = 'AAP'
332         and   pai_comp.action_information6 = p_employers_ref_no
333         -- AND pai_comp.action_information7 = p_employers_name
334         and   pai_person.action_context_id = paa.assignment_action_id
335         and   pai_person.action_information_category = 'ADDRESS DETAILS'
336         and   pai_person.action_context_type = 'AAP'
337         and   pai_person.action_information14 = 'Employee Address'
338         and   pai_person.action_information1 = p_person_id
339         and   pai.action_context_id = paa.assignment_action_id
340         and   pai.action_context_type = 'AAP'
341         and   pai.action_information_category = 'INT FREE AND LOW INT LOANS';
342       return to_char(l_loan_amount);
343    end get_loan_amount;
344 
345    function get_global_value(p_global_name in VARCHAR2,
346                              p_benefit_end_date in VARCHAR2 default '0001/01/01 00:00:00') return VARCHAR2
347    is
348         l_global_value ff_globals_f.global_value%type;
349         cursor csr_get_value
350         is
351         select global_value
352         from   ff_globals_f
353         where  legislation_code = 'GB'
354         and    GLOBAL_NAME = p_global_name
355         and    fnd_date.canonical_to_date(p_benefit_end_date)
356                between effective_start_date and effective_end_date;
357    begin
358         hr_utility.TRACE('p_benefit_end_date '|| p_benefit_end_date);
359         hr_utility.TRACE('p_global_name '|| p_global_name);
360         open csr_get_value;
361         fetch csr_get_value into l_global_value;
362         close csr_get_value;
363         return l_global_value;
364    end;
365 
366    function sum_and_set_global_var(p_varable_name in VARCHAR2,
367                                    p_variable_value in VARCHAR2) return NUMBER
368    is
369         l_present_val NUMBER;
370         l_new_val     NUMBER;
371         l_dummy       NUMBER;
372    begin
373         hr_utility.TRACE(' p_variable_value '|| p_variable_value);
374         l_present_val := per_formula_functions.get_number(p_varable_name);
375         hr_utility.TRACE(' l_present_val '|| l_present_val);
376         if l_present_val is null
377         then
378             if p_variable_value is null
379             then
380                 l_new_val := null;
381             else
382                 l_new_val := nvl(to_number(p_variable_value), 0);
383             end if;
384             hr_utility.TRACE('l_new_val '|| l_new_val);
385         else
386             l_new_val := l_present_val + nvl(to_number(p_variable_value), 0);
387             hr_utility.TRACE(' l_new_val '|| l_new_val);
388         end if;
389         l_dummy := per_formula_functions.set_number(p_varable_name, l_new_val);
390         hr_utility.TRACE(' l_dummy '|| l_dummy);
391         return l_new_val;
392    end;
393 
394    function max_and_set_global_var(p_variable_name     in Varchar2,
395                                    p_variable_datatype in Varchar2,
396                                    p_variable_value    in Varchar2) return varchar2
397    is
398         l_present_val varchar2(20);
399         l_warnmsg     varchar2(20);
400         l_dummy       NUMBER;
401    begin
402         l_warnmsg := '0';
403         if p_variable_datatype = 'N' then
404            -- we need to store the value st away
405            -- rates remain same for a vehicle type
406            -- !! the above statm is not true as second assignment (multi)
407            -- might not have this benefit type hence it will be zero,
408            -- so we don't want to store zero.
409            if nvl(per_formula_functions.get_number(p_variable_name),0) < nvl(to_number(p_variable_value),0) then
410               l_dummy := per_formula_functions.set_number(p_variable_name, p_variable_value);
411            end if;
412         end if;
413         if p_variable_datatype = 'T' then
414            -- we need to store the Y value
415            -- as this will be called only when the value is Y
416            l_dummy := per_formula_functions.set_text(p_variable_name, p_variable_value);
417         end if;
418         if p_variable_datatype = 'D' then
419            -- this is for date, we need to store the max date
420            -- this is used for date free fuel withdrawn
421            -- if p_variable_value is null or zero this won't be called
422            l_present_val := per_formula_functions.get_text(p_variable_name);
423            hr_utility.TRACE(' l_present_val '|| l_present_val);
424            if l_present_val is null
425            then
426                l_dummy := per_formula_functions.set_text(p_variable_name, p_variable_value);
427            else
428                if fnd_date.canonical_to_date(l_present_val) <>
429                   fnd_date.canonical_to_date(p_variable_value)
430                then
431                    l_warnmsg := '1';
432                    if fnd_date.canonical_to_date(l_present_val) <
433                       fnd_date.canonical_to_date(p_variable_value)
434                    then
435                        l_dummy := per_formula_functions.set_text(p_variable_name, p_variable_value);
436                    end if;
437                end if;
438            end if;
439         end if;
440         return l_warnmsg;
441    end;
442 
443    function get_lookup_desc (p_lookup_type    varchar2,
444                              p_lookup_code    varchar2,
445                              p_effective_date varchar2) return varchar2
446    is
447         l_description varchar2(150);
448    begin
449         /*Bug No. 3237648*/
450         /*Fetching from hr_lookups instead of fnd_lookup_values*/
451         select description into l_description
452         from  hr_lookups hlu
453         where hlu.lookup_type = p_lookup_type
454         and  hlu.lookup_code = p_lookup_code
455         and  hlu.ENABLED_FLAG = 'Y'
456         and  fnd_date.canonical_to_date(p_effective_date) between
457                  nvl(hlu.START_DATE_ACTIVE,fnd_date.canonical_to_date(p_effective_date))
458              and nvl(hlu.END_DATE_ACTIVE,fnd_date.canonical_to_date(p_effective_date));
459         return l_description ;
460     exception
461     when others then
462          l_description  := null;
463          return l_description ;
464     end;
465 
466     function check_desc_and_set_global_var(p_varable_name   in VARCHAR2,
467                                            p_variable_value in VARCHAR2,
468                                            p_lookup_type    in VARCHAR2 default null,
469                                            p_effective_date in VARCHAR2 default null) return NUMBER
470     is
471          l_present_val VARCHAR2(150);
472          l_new_val     VARCHAR2(150);
473          l_dummy       NUMBER;
474     begin
475          hr_utility.TRACE('.. p_varable_name ...'|| p_varable_name);
476          hr_utility.TRACE('.. p_variable_value ...'|| p_variable_value);
477          l_present_val := per_formula_functions.get_text(p_varable_name);
478          hr_utility.TRACE('..l_present_val.. '|| l_present_val);
479          if p_lookup_type is null
480          then
481             if l_present_val is null
482             then
483                 l_new_val := p_variable_value;
484                 l_dummy := per_formula_functions.set_text(p_varable_name, l_new_val);
485             else
486                 hr_utility.TRACE('..Checking present Value with variable value '|| l_present_val);
487                 if l_present_val <> nvl(p_variable_value, l_present_val)
488                 then
489                     l_new_val := 'Multiple';
490                     l_dummy := per_formula_functions.set_text(p_varable_name, l_new_val);
491                 end if;
492             end if;
493          else
494             l_new_val := get_lookup_desc (p_lookup_type,
495                                           p_variable_value,
496                                           p_effective_date || ' 00:00:00'); -- since it accepts date in canonical format
497             if l_present_val is null
498             then
499                 hr_utility.trace('New vale ' || l_new_val);
500                 l_dummy := per_formula_functions.set_text(p_varable_name, l_new_val);
501             else
502                 hr_utility.TRACE('..Checking present Value with variable value '|| l_present_val);
503                 if l_present_val <> nvl(l_new_val, l_present_val)
504                 then
505                     l_new_val := 'Multiple';
506                     l_dummy := per_formula_functions.set_text(p_varable_name, l_new_val);
507                 end if;
508             end if;
509          end if;
510          return l_dummy;
511    end;
512 
513    function get_and_push_message(p_application  in VARCHAR2,
514                                  p_message      in VARCHAR2,
515                                  p_stack_level  in VARCHAR2 default 'A',
516                                  p_token_name1  in VARCHAR2 default null,
517                                  p_token_value1 in VARCHAR2 default null,
518                                  p_token_name2  in VARCHAR2 default null,
519                                  p_token_value2 in VARCHAR2 default null,
520                                  p_token_name3  in VARCHAR2 default null,
521                                  p_token_value3 in VARCHAR2 default null,
522                                  p_token_name4  in VARCHAR2 default null,
523                                  p_token_value4 in VARCHAR2 default null,
524                                  p_token_name5  in VARCHAR2 default null,
525                                  p_token_value5 in VARCHAR2 default null) return VARCHAR2
526    is
527         l_error_str                   VARCHAR2(300);
528         l_application_id  Number;
529    begin
530         --
531         -- Keep this code as simple as possible.
532         --
533         if p_application = 'PER' then
534            l_application_id :=  800;
535         elsif p_application = 'PAY' then
536            l_application_id :=  801;
537         else
538            select application_id
539            into  l_application_id
540            from  fnd_application
541            where APPLICATION_SHORT_NAME = p_application;
542         end if;
543 
544         pay_core_utils.push_message(l_application_id, p_message, p_stack_level);
545         --
546         if p_token_name1 is not null and p_token_value1 is not null
547         then
548             pay_core_utils.push_token(p_token_name1, p_token_value1);
549         end if;
550         --
551         if  p_token_name2 is not null and p_token_value2 is not null
552         then
553             pay_core_utils.push_token(p_token_name2, p_token_value2);
554         end if;
555         --
556         if  p_token_name3 is not null and p_token_value3 is not null
557         then
558             pay_core_utils.push_token(p_token_name3, p_token_value3);
559         end if;
560         --
561         if  p_token_name4 is not null and p_token_value4 is not null
562         then
563             pay_core_utils.push_token(p_token_name4, p_token_value4);
564         end if;
565         --
566         if  p_token_name5 is not null and p_token_value5 is not null
567         then
568             pay_core_utils.push_token(p_token_name5, p_token_value5);
569         end if;
570         --
571         -- The above pushed the message into the stack
572         -- Now Just return the message to ff : name itself if the text is NULL,
573         -- otherwise return the (truncated) message text.
574         --
575         l_error_str := fffunc.gfm(
576                         p_application,
577                         p_message,
578                         p_token_name1,
579                         p_token_value1,
580                         p_token_name2,
581                         p_token_value2,
582                         p_token_name3,
583                         p_token_value3,
584                         p_token_name4,
585                         p_token_value4,
586                         p_token_name5,
587                         p_token_value5);
588         return l_error_str;
589    end;
590 
591    function get_assignment_number(p_action_id  in number,
592                                   p_lowest     in boolean  default false,
593                                   p_person_id  in varchar2 default null,
594                                   p_emp_ref    in varchar2 default null) return varchar2 is
595      l_asg_id  number;
596      l_asg_no  varchar2(25);
597 
598      cursor asg_id is
599      select assignment_id
600      from   pay_assignment_actions
601      where  assignment_action_id = p_action_id;
602 
603      cursor asg_low is
604      select min(paa2.assignment_id)
605        from pay_assignment_actions paa,
606             pay_assignment_actions paa2,
607             pay_action_information pai_comp,
608             pay_action_information pai_person
609       where paa.assignment_action_id = p_action_id
610         and paa2.payroll_action_id = paa.payroll_action_id
611         and pai_comp.action_context_id = paa2.assignment_action_id
612         and pai_comp.action_information_category = 'EMEA PAYROLL INFO'
613         and pai_person.action_context_id = paa2.assignment_action_id
614         and pai_person.action_information_category = 'ADDRESS DETAILS'
615         and pai_person.action_information14 = 'Employee Address'
616         and pai_person.action_information1 = p_person_id
617         and pai_comp.action_information6 = p_emp_ref;
618 
619      cursor asg_no is
620      select paa.assignment_number
621      from   per_assignments_f paa
622      where  paa.assignment_id = l_asg_id
623      and    paa.effective_end_date = (select max(paa2.effective_end_date)
624                                         from per_assignments_f paa2
625                                        where paa2.assignment_id = l_asg_id);
626 
627      cursor emp_no is
628      select employee_number
629      from   per_all_people_f
630      where  person_id = p_person_id;
631 
632    begin
633         if not p_lowest then
634            open asg_id;
635            fetch asg_id into l_asg_id;
636            close asg_id;
637         else
638            open asg_low;
639            fetch asg_low into l_asg_id;
640            close asg_low;
641         end if;
642 
643         open asg_no;
644         fetch asg_no into l_asg_no;
645         close asg_no;
646 
647         if l_asg_no is null then
648            open emp_no;
649            fetch emp_no into l_asg_no;
650            close emp_no;
651         end if;
652         return l_asg_no;
653    end;
654 
655 
656    function fetch_p11d_rep_data(p_assignment_action_id NUMBER) return l_typ_p11d_fields_rec
657    is
658         l_h_ce      VARCHAR2(10);
659         l_h_count   NUMBER;
660         l_f_count   NUMBER;
661         l_pactid    NUMBER;
662         l_rep_run   VARCHAR2(10);
663         l_p11d_fields l_typ_p11d_fields_rec;
664         l_h_sum_max_amt_outstanding  number;
665 
666         procedure populate_stored_fields is
667         begin
668              -- populating the person id
669              select action_information1
670              into  g_person_id
671              from  pay_action_information pai_person
672              where pai_person.action_context_id = p_assignment_action_id
673              and   pai_person.action_information_category = 'ADDRESS DETAILS'
674              and   pai_person.action_context_type = 'AAP'
675              and   pai_person.action_information14 = 'Employee Address';
676 
677              select action_information6,
678                     action_information7
679              into  g_emp_ref_no,
680                    g_employer_name
681              from  pay_action_information pai_comp
682              where pai_comp.action_context_id = p_assignment_action_id
683              and   pai_comp.action_context_type = 'AAP'
684              and   pai_comp.action_information_category = 'EMEA PAYROLL INFO';
685 
686              l_p11d_fields.employers_ref_no := g_emp_ref_no;
687              l_p11d_fields.employers_name   := replace(g_employer_name,'&','&');
688              hr_utility.trace('l_p11d_fields.employers_name' || l_p11d_fields.employers_name);
689 
690              select decode(action_information4, 'Y', 'Y', 'N'),
691                     action_information8, -- P11D changes 07/08 last_name
692                     action_information6, -- P11D changes 07/08 first_name
693                     substr(action_information15,9,2) ||
694                     substr(action_information15,6,2) ||
695                     substr(action_information15,1,4),
696                     action_information17
697              into  l_p11d_fields.director_flag,
698                    l_p11d_fields.sur_name,
699                    l_p11d_fields.fore_name,
700                    l_p11d_fields.date_of_birth,
701                    l_p11d_fields.gender
702              from  pay_action_information pai_gb
703              where pai_gb.action_context_id = p_assignment_action_id
704              and   pai_gb.action_context_type = 'AAP'
705              and   pai_gb.action_information_category = 'GB EMPLOYEE DETAILS';
706              --
707              select action_information1,
708                     action_information4,
709                     action_information10 -- emp number
710                 -- action_information14 -- assign num
711              into  l_p11d_fields.full_name,
712                    l_p11d_fields.national_ins_no,
713                    l_p11d_fields.employee_number
714              from  pay_action_information pai_emp
715              where pai_emp.action_context_id = p_assignment_action_id
716              and   pai_emp.action_context_type = 'AAP'
717              and   pai_emp.action_information_category = 'EMPLOYEE DETAILS';
718 
719              l_p11d_fields.employee_number := get_assignment_number(p_assignment_action_id, true, g_person_id, g_emp_ref_no);
720 
721              select payroll_action_id
722              into  l_pactid
723              from  pay_assignment_actions
724              where assignment_action_id = p_assignment_action_id;
725 
726              PAY_GB_P11D_ARCHIVE_SS.get_parameters(p_payroll_action_id => l_pactid,
727                                                    p_token_name        => 'Rep_Run',
728                                                    p_token_value       => l_rep_run);
729 
730              if to_number(l_rep_run) < 2005
731              then
732                  select action_information1,
733                         decode(action_information2,'0',null,to_char(to_number(action_information2),'FM999,999,990.00')),
734                         decode(action_information2,'0',null,to_char(to_number(action_information3),'FM999,999,990.00')),
735                         to_char(to_number(nvl(action_information4,'0')),'FM999,999,990.00'),
736                         action_information5,
737                         to_char(to_number(nvl(action_information6,'0')),'FM999,999,990.00'),
738                         to_char(to_number(nvl(action_information7,'0')),'FM999,999,990.00'),
739                         decode(action_information8,'0',null,to_char(to_number(action_information8),'FM999,999,990.00')),
740                         decode(action_information8,'0',null,to_char(to_number(action_information9),'FM999,999,990.00')),
741                         to_char(to_number(nvl(action_information10,'0')),'FM999,999,990.00'),
742                         to_char(to_number(nvl(action_information11,'0')),'FM999,999,990.00'),
743                         to_char(to_number(nvl(action_information12,'0')),'FM999,999,990.00'),
744                         to_char(to_number(nvl(action_information13,'0')),'FM999,999,990.00'),
745                         to_char(to_number(nvl(action_information14,'0')),'FM999,999,990.00'),
746                         to_char(to_number(nvl(action_information15,'0')),'FM999,999,990.00'),
747                         decode(action_information16,'0',null,to_char(to_number(action_information16),'FM999,999,990.00')),
748                         decode(action_information16,'0',null,to_char(to_number(action_information17),'FM999,999,990.00')),
749                         to_char(to_number(nvl(action_information18,'0')),'FM999,999,990.00'),
750                         to_char(to_number(nvl(action_information19,'0')),'FM999,999,990.00'),
751                         decode(action_information20,'0',null,to_char(to_number(action_information20),'FM999,999,990.00')),
752                         decode(action_information20,'0',null,to_char(to_number(action_information21),'FM999,999,990.00')),
753                         to_char(to_number(nvl(action_information22,'0')),'FM999,999,990.00'),
754                         action_information23,
755                         decode(action_information24,'0',null,to_char(to_number(action_information24),'FM999,999,990.00')),
756                         decode(action_information24,'0',null,to_char(to_number(action_information25),'FM999,999,990.00')),
757                         to_char(to_number(nvl(action_information26,'0')),'FM999,999,990.00'),
758                         decode(action_information27, 'Y', 'Y', 'N'),
759                         to_char(to_number(nvl(action_information28,'0')),'FM999,999,990.00'),
760                         to_char(to_number(nvl(action_information29,'0')),'FM999,999,990.00'),
761                         action_information30
762                  into   l_p11d_fields.a_desc, l_p11d_fields.a_cost, l_p11d_fields.a_amg,
763                         l_p11d_fields.a_ce, l_p11d_fields.b_desc, l_p11d_fields.b_ce,
764                         l_p11d_fields.b_tnp, l_p11d_fields.c_cost, l_p11d_fields.c_amg,
765                         l_p11d_fields.c_ce, l_p11d_fields.d_ce, l_p11d_fields.e_ce,
766                         l_p11d_fields.f_tcce, l_p11d_fields.f_tfce, l_p11d_fields.g_ce,
767                         l_p11d_fields.i_cost, l_p11d_fields.i_amg, l_p11d_fields.i_ce,
768                         l_p11d_fields.j_ce, l_p11d_fields.k_cost, l_p11d_fields.k_amg,
769                         l_p11d_fields.k_ce, l_p11d_fields.l_desc, l_p11d_fields.l_cost,
770                         l_p11d_fields.l_amg, l_p11d_fields.l_ce, l_p11d_fields.m_shares,
771                         l_h_ce, l_h_count, l_f_count
772                  from   pay_action_information pai_emp
773                  where  pai_emp.action_context_id = p_assignment_action_id
774                  and    pai_emp.action_context_type = 'AAP'
775                  and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTA';
776 
777                  select action_information1,
778                         decode(action_information2,'0',null,to_char(to_number(action_information2),'FM999,999,990.00')),
779                         decode(action_information2,'0',null,to_char(to_number(action_information3),'FM999,999,990.00')),
780                         to_char(to_number(nvl(action_information4,'0')),'FM999,999,990.00'),
781                         action_information5,
782                         decode(action_information6,'0',null,to_char(to_number(action_information6),'FM999,999,990.00')),
783                         decode(action_information6,'0',null,to_char(to_number(action_information7),'FM999,999,990.00')),
784                         to_char(to_number(nvl(action_information8,'0')),'FM999,999,990.00'),
785                         to_char(to_number(nvl(action_information9,'0')),'FM999,999,990.00'),
786                         decode(action_information10,'0',null,to_char(to_number(action_information10),'FM999,999,990.00')),
787                         decode(action_information10,'0',null,to_char(to_number(action_information11),'FM999,999,990.00')),
788                         to_char(to_number(nvl(action_information12,'0')),'FM999,999,990.00'),
789                         decode(action_information13,'0',null,to_char(to_number(action_information13),'FM999,999,990.00')),
790                         decode(action_information13,'0',null,to_char(to_number(action_information14),'FM999,999,990.00')),
791                         to_char(to_number(nvl(action_information15,'0')),'FM999,999,990.00'),
792                         decode(action_information16, 'Y', 'Y', 'N'),
793                         decode(action_information17,'0',null,to_char(to_number(action_information17),'FM999,999,990.00')),
794                         decode(action_information17,'0',null,to_char(to_number(action_information18),'FM999,999,990.00')),
795                         to_char(to_number(nvl(action_information19,'0')),'FM999,999,990.00'),
796                         decode(action_information20,'0',null,to_char(to_number(action_information20),'FM999,999,990.00')),
797                         decode(action_information20,'0',null,to_char(to_number(action_information21),'FM999,999,990.00')),
798                         to_char(to_number(nvl(action_information22,'0')),'FM999,999,990.00'),
799                         decode(action_information23,'0',null,to_char(to_number(action_information23),'FM999,999,990.00')),
800                         decode(action_information23,'0',null,to_char(to_number(action_information24),'FM999,999,990.00')),
801                         to_char(to_number(nvl(action_information25,'0')),'FM999,999,990.00'),
802                         action_information26,
803                         decode(action_information27,'0',null,to_char(to_number(action_information27),'FM999,999,990.00')),
804                         decode(action_information27,'0',null,to_char(to_number(action_information28),'FM999,999,990.00')),
805                         to_char(to_number(nvl(action_information29,'0')),'FM999,999,990.00')
806                  into   l_p11d_fields.n_desc, l_p11d_fields.n_cost, l_p11d_fields.n_amg,
807                         l_p11d_fields.n_ce, l_p11d_fields.na_desc, l_p11d_fields.na_cost,
808                         l_p11d_fields.na_amg, l_p11d_fields.na_ce,
809                         l_p11d_fields.n_taxpaid, l_p11d_fields.o1_cost,
810                         l_p11d_fields.o1_amg, l_p11d_fields.o1_ce, l_p11d_fields.o2_cost,
811                         l_p11d_fields.o2_amg, l_p11d_fields.o2_ce,
812                         l_p11d_fields.o_toi,
813                         l_p11d_fields.o3_cost, l_p11d_fields.o3_amg, l_p11d_fields.o3_ce,
814                         l_p11d_fields.o4_cost, l_p11d_fields.o4_amg, l_p11d_fields.o4_ce,
815                         l_p11d_fields.o5_cost, l_p11d_fields.o5_amg, l_p11d_fields.o5_ce,
816                         l_p11d_fields.o6_desc, l_p11d_fields.o6_cost,
817                         l_p11d_fields.o6_amg, l_p11d_fields.o6_ce
818                  from   pay_action_information pai_emp
819                  where  pai_emp.action_context_id = p_assignment_action_id
820                  and    pai_emp.action_context_type = 'AAP'
821                  and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTB';
822 
823                  hr_utility.trace('Fetching from Result C');
824                  select substr(action_information10,9,2) || ' ' ||
825                         substr(action_information10,6,2) || ' ' ||
826                         substr(action_information10,1,4) ,
827                         decode (action_information11,null,'N','Y'),to_number(nvl(ACTION_INFORMATION23,'0'))
828                  into  l_p11d_fields.f_date_free,l_p11d_fields.f_rein_yr,
829                        l_h_sum_max_amt_outstanding
830                  from  pay_action_information pai_emp
831                  where pai_emp.action_context_id = p_assignment_action_id
832                  and   pai_emp.action_context_type = 'AAP'
833                  and   pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTC';
834 
835              ELSE  /* For year 04/05 onwards */
836                  select action_information1,
837                         decode(action_information2,'0',null,to_char(to_number(action_information2),'FM999,999,990.00')),
838                         decode(action_information2,'0',null,to_char(to_number(action_information3),'FM999,999,990.00')),
839                         to_char(to_number(nvl(action_information4,'0')),'FM999,999,990.00'),
840                         action_information5,
841                         to_char(to_number(nvl(action_information6,'0')),'FM999,999,990.00'),
842                         to_char(to_number(nvl(action_information7,'0')),'FM999,999,990.00'),
843                         decode(action_information8,'0',null,to_char(to_number(action_information8),'FM999,999,990.00')),
844                         decode(action_information8,'0',null,to_char(to_number(action_information9),'FM999,999,990.00')),
845                         to_char(to_number(nvl(action_information10,'0')),'FM999,999,990.00'),
846                         to_char(to_number(nvl(action_information11,'0')),'FM999,999,990.00'),
847                         to_char(to_number(nvl(action_information12,'0')),'FM999,999,990.00'),
848                         to_char(to_number(nvl(action_information13,'0')),'FM999,999,990.00'),
849                         to_char(to_number(nvl(action_information14,'0')),'FM999,999,990.00'),
850                         to_char(to_number(nvl(action_information15,'0')),'FM999,999,990.00'),
851                         decode(action_information16,'0',null,to_char(to_number(action_information16),'FM999,999,990.00')),
852                         decode(action_information16,'0',null,to_char(to_number(action_information17),'FM999,999,990.00')),
853                         to_char(to_number(nvl(action_information18,'0')),'FM999,999,990.00'),
854                         to_char(to_number(nvl(action_information19,'0')),'FM999,999,990.00'),
855                         decode(action_information20,'0',null,to_char(to_number(action_information20),'FM999,999,990.00')),
856                         decode(action_information20,'0',null,to_char(to_number(action_information21),'FM999,999,990.00')),
857                         to_char(to_number(nvl(action_information22,'0')),'FM999,999,990.00'),
858                         action_information23,
859                         decode(action_information24,'0',null,to_char(to_number(action_information24),'FM999,999,990.00')),
860                         decode(action_information24,'0',null,to_char(to_number(action_information25),'FM999,999,990.00')),
861                         to_char(to_number(nvl(action_information26,'0')),'FM999,999,990.00'),
862                         to_char(to_number(nvl(action_information28,'0')),'FM999,999,990.00'),
863                         to_char(to_number(nvl(action_information29,'0')),'FM999,999,990.00'),
864                         action_information30
865                  into   l_p11d_fields.a_desc, l_p11d_fields.a_cost, l_p11d_fields.a_amg,
866                         l_p11d_fields.a_ce, l_p11d_fields.b_desc, l_p11d_fields.b_ce,
867                         l_p11d_fields.b_tnp, l_p11d_fields.c_cost, l_p11d_fields.c_amg,
868                         l_p11d_fields.c_ce, l_p11d_fields.d_ce, l_p11d_fields.e_ce,
869                         l_p11d_fields.f_tcce, l_p11d_fields.f_tfce, l_p11d_fields.g_ce,
870                         l_p11d_fields.i_cost, l_p11d_fields.i_amg, l_p11d_fields.i_ce,
871                         l_p11d_fields.j_ce, l_p11d_fields.k_cost, l_p11d_fields.k_amg,
872                         l_p11d_fields.k_ce, l_p11d_fields.l_desc, l_p11d_fields.l_cost,
873                         l_p11d_fields.l_amg, l_p11d_fields.l_ce,
874                         l_h_ce, l_h_count, l_f_count
875                  from   pay_action_information pai_emp
876                  where  pai_emp.action_context_id = p_assignment_action_id
877                  and    pai_emp.action_context_type = 'AAP'
878                  and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTA';
879 
880                  select action_information1,
881                         decode(action_information2,'0',null,to_char(to_number(action_information2),'FM999,999,990.00')),
882                         decode(action_information2,'0',null,to_char(to_number(action_information3),'FM999,999,990.00')),
883                         to_char(to_number(nvl(action_information4,'0')),'FM999,999,990.00'),
884                         action_information5,
885                         decode(action_information6,'0',null,to_char(to_number(action_information6),'FM999,999,990.00')),
886                         decode(action_information6,'0',null,to_char(to_number(action_information7),'FM999,999,990.00')),
887                         to_char(to_number(nvl(action_information8,'0')),'FM999,999,990.00'),
888                         to_char(to_number(nvl(action_information9,'0')),'FM999,999,990.00'),
889                         decode(action_information10,'0',null,to_char(to_number(action_information10),'FM999,999,990.00')),
890                         decode(action_information10,'0',null,to_char(to_number(action_information11),'FM999,999,990.00')),
891                         to_char(to_number(nvl(action_information12,'0')),'FM999,999,990.00'),
892                         decode(action_information13,'0',null,to_char(to_number(action_information13),'FM999,999,990.00')),
893                         decode(action_information13,'0',null,to_char(to_number(action_information14),'FM999,999,990.00')),
894                         to_char(to_number(nvl(action_information15,'0')),'FM999,999,990.00'),
895                         decode(action_information16, 'Y', 'Y', 'N'),
896                         decode(action_information17,'0',null,to_char(to_number(action_information17),'FM999,999,990.00')),
897                         decode(action_information17,'0',null,to_char(to_number(action_information18),'FM999,999,990.00')),
898                         to_char(to_number(nvl(action_information19,'0')),'FM999,999,990.00'),
899                         decode(action_information20,'0',null,to_char(to_number(action_information20),'FM999,999,990.00')),
900                         decode(action_information20,'0',null,to_char(to_number(action_information21),'FM999,999,990.00')),
901                         to_char(to_number(nvl(action_information22,'0')),'FM999,999,990.00'),
902                         decode(action_information23,'0',null,to_char(to_number(action_information23),'FM999,999,990.00')),
903                         decode(action_information23,'0',null,to_char(to_number(action_information24),'FM999,999,990.00')),
904                         to_char(to_number(nvl(action_information25,'0')),'FM999,999,990.00'),
905                         action_information26,
906                         decode(action_information27,'0',null,to_char(to_number(action_information27),'FM999,999,990.00')),
907                         decode(action_information27,'0',null,to_char(to_number(action_information28),'FM999,999,990.00')),
908                         to_char(to_number(nvl(action_information29,'0')),'FM999,999,990.00'),
909 			to_char(to_number(nvl(action_information30,'0')),'FM999,999,990.00') -- P11D changes 07/08
910                  into   l_p11d_fields.n_desc, l_p11d_fields.n_cost, l_p11d_fields.n_amg,
911                         l_p11d_fields.n_ce, l_p11d_fields.na_desc, l_p11d_fields.na_cost,
912                         l_p11d_fields.na_amg, l_p11d_fields.na_ce,
913                         l_p11d_fields.n_taxpaid, l_p11d_fields.o1_cost,
914                         l_p11d_fields.o1_amg, l_p11d_fields.o1_ce, l_p11d_fields.o2_cost,
915                         l_p11d_fields.o2_amg, l_p11d_fields.o2_ce,
916                         l_p11d_fields.o_toi,
917                         l_p11d_fields.o3_cost, l_p11d_fields.o3_amg, l_p11d_fields.o3_ce,
918                         l_p11d_fields.o4_cost, l_p11d_fields.o4_amg, l_p11d_fields.o4_ce,
919                         l_p11d_fields.o5_cost, l_p11d_fields.o5_amg, l_p11d_fields.o5_ce,
920                         l_p11d_fields.o6_desc, l_p11d_fields.o6_cost,
921                         l_p11d_fields.o6_amg, l_p11d_fields.o6_ce, l_p11d_fields.g_cef
922                  from   pay_action_information pai_emp
923                  where  pai_emp.action_context_id = p_assignment_action_id
924                  and    pai_emp.action_context_type = 'AAP'
925                  and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTB';
926 
927                  hr_utility.trace('Fetching from Result C');
928                  select to_number(nvl(ACTION_INFORMATION23,'0'))
929                  into   l_h_sum_max_amt_outstanding
930                  from   pay_action_information pai_emp
931                  where  pai_emp.action_context_id = p_assignment_action_id
932                  and    pai_emp.action_context_type = 'AAP'
933                  and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTC';
934              end if;
935 
936         end;
937         procedure populate_car_fields
938         is
939              cursor csr_car_benefits(p_pactid    NUMBER,
940                                      p_person_id VARCHAR2,
941                                      p_emp_ref   VARCHAR2,
942                                      p_emp_name  VARCHAR2)
943              is
944              select
945                    substr(pai_emp.action_information3,9,2) || ' ' ||
946                    substr(pai_emp.action_information3,6,2) || ' ' ||
947                    substr(pai_emp.action_information3,1,4) f_start,
948                    substr(pai_emp.action_information4,9,2) || ' ' ||
949                    substr(pai_emp.action_information4,6,2) || ' ' ||
950                    substr(pai_emp.action_information4,1,4) f_end,
951                    pai_emp.action_information6 || ' ' ||
952                    pai_emp.action_information7 f_make,
953                    substr(pai_emp.action_information8,9,2) || ' ' ||
954                    substr(pai_emp.action_information8,6,2) || ' ' ||
955                    substr(pai_emp.action_information8,1,4) f_dreg,
956                    to_char(to_number(pai_emp.action_information9),'FM999,999,990.00') f_lprice,
957                    to_char(to_number(pai_emp.action_information10),'FM999,999,990.00') f_cc,
958                    to_char(to_number(pai_emp.action_information11),'FM999,999,990.00') f_fcc,
959                    decode( pai_emp.action_information12,'0',null,PAY_GB_P11D_MAGTAPE.get_description(
960                            pai_emp.action_information12,'GB_FUEL_TYPE',pai_emp.action_information4)) f_fuel,
961                    pai_emp.action_information13 f_efig,
962                    decode(pai_emp.action_information13,null,'Y', 'N') f_nfig,
963                    to_char(to_number(pai_emp.action_information15),'FM999,999,990.00') f_oprice,
964                    to_char(to_number(pai_emp.action_information16),'FM999,999,990.00') f_cost,
965                    to_char(to_number(pai_emp.action_information17),'FM999,999,990.00') f_amg,
966                    substr(action_information26,9,2) || ' ' ||
967                    substr(action_information26,6,2) || ' ' ||
968                    substr(action_information26,1,4) f_date_free,
969                    decode(action_information27,'Y','Y','N') f_rein_yr,
970                    pai_emp.action_information18 f_esize
971              from  pay_action_information pai_emp
972              where pai_emp.action_information_category = 'CAR AND CAR FUEL 2003_04'
973              and   pai_emp.action_context_type = 'AAP'
974              and   pai_emp.action_context_id in( select paa.assignment_action_id
975                                                  from  pay_action_information pai_comp,
976                                                        pay_action_information pai_person,
977                                                        pay_assignment_actions paa,
978                                                        pay_payroll_actions ppa
979                                                  where ppa.payroll_action_id = p_pactid
980                                                  and   paa.payroll_action_id = ppa.payroll_action_id
981                                                  and   pai_comp.action_context_id = paa.assignment_action_id
982                                                  and   pai_comp.action_information_category = 'EMEA PAYROLL INFO'
983                                                  and   pai_comp.action_context_type = 'AAP'
984                                                  and   pai_person.action_context_id = paa.assignment_action_id
985                                                  and   pai_person.action_information_category = 'ADDRESS DETAILS'
986                                                  and   pai_person.action_context_type = 'AAP'
987                                                  and   pai_person.action_information14 = 'Employee Address'
988                                                  and   pai_person.action_information1 = p_person_id
989                                                  and   pai_comp.action_information6 = p_emp_ref
990                                                  and   pai_comp.action_information7 = p_emp_name)
991              order by pai_emp.action_information3 desc, -- ben st dt
992                       pai_emp.action_information4 desc, -- ben end dt
993                       pai_emp.action_information10 desc, -- cc for car
994                       pai_emp.action_information11 desc, -- cc for fuel
995                       pai_emp.action_information1 desc, -- ele entrty id
996                       pai_emp.action_information2 desc; -- effec date
997 
998              l_rec_count         INTEGER := 0;
999              l_tax_year_start    varchar2(10);
1000              l_tax_year_end      varchar2(10);
1001              l_ben_start         varchar2(10);
1002              l_ben_end           varchar2(10);
1003              l_tax_year          varchar2(4);
1004              l_date_reg          varchar2(10);
1005         begin
1006              hr_utility.trace('l_f_count ' || l_f_count);
1007              if l_f_count > 0
1008              then
1009                  hr_utility.trace('l_payroll_action_id ' || g_payroll_action_id);
1010                  hr_utility.trace('l_person_id ' || g_person_id);
1011                  l_tax_year := pay_gb_p11d_magtape.get_parameters(g_payroll_action_id,'Rep_Run');
1012                  l_tax_year_end := l_tax_year || '0405';
1013                  l_tax_year_start := to_char(to_number(l_tax_year) - 1) || '0406';
1014                  for car_benefits in csr_car_benefits(g_payroll_action_id,
1015                                                       g_person_id,
1016                                                       g_emp_ref_no,
1017                                                       g_employer_name)
1018                  loop
1019                      l_rec_count := l_rec_count + 1;
1020                      hr_utility.trace('l_rec_count ' || l_rec_count);
1021                      l_ben_start := car_benefits.f_start;
1022                      l_ben_end   := car_benefits.f_end;
1023                      l_ben_start := substr(l_ben_start,7,4) || substr(l_ben_start,4,2) || substr(l_ben_start,1,2);
1024                      l_ben_end   := substr(l_ben_end,7,4) || substr(l_ben_end,4,2) || substr(l_ben_end,1,2);
1025                      l_date_reg  := substr(car_benefits.f_dreg,7,4) || substr(car_benefits.f_dreg,4,2) || substr(car_benefits.f_dreg,1,2);
1026                      if l_rec_count = 1
1027                      then
1028                          hr_utility.trace('car_benefits.f_make ' || car_benefits.f_make);
1029                          hr_utility.trace('l_rec_count in 1 ' || l_rec_count);
1030                          if to_number(l_ben_start) > to_number(l_tax_year_start)
1031                          then
1032                              l_p11d_fields.f1_start := car_benefits.f_start;
1033                          else
1034                              l_p11d_fields.f1_start := ' ';
1035                          end if;
1036                          if to_number(l_ben_end) < to_number(l_tax_year_end)
1037                          then
1038                              l_p11d_fields.f1_end := car_benefits.f_end;
1039                          else
1040                              l_p11d_fields.f1_end := ' ';
1041                          end if;
1042                         l_p11d_fields.f1_make := car_benefits.f_make;
1043                         l_p11d_fields.f1_dreg := car_benefits.f_dreg;
1044                         l_p11d_fields.f1_lprice := car_benefits.f_lprice;
1045                         l_p11d_fields.f1_cc := car_benefits.f_cc;
1046                         l_p11d_fields.f1_fcc  := car_benefits.f_fcc;
1047                         l_p11d_fields.f1_fuel := car_benefits.f_fuel;
1048                         l_p11d_fields.f1_efig := car_benefits.f_efig;
1049                         l_p11d_fields.f1_nfig := car_benefits.f_nfig;
1050                         l_p11d_fields.f1_oprice := car_benefits.f_oprice;
1051                         -- l_p11d_fields.f1_aprice := car_benefits.f_aprice;
1052                         l_p11d_fields.f1_cost := car_benefits.f_cost;
1053                         l_p11d_fields.f1_amg := car_benefits.f_amg;
1054                         if car_benefits.f_esize = '9999' and
1055                            to_number(l_date_reg) > 19980101 and
1056                            to_number(nvl(car_benefits.f_efig,0)) > 0 then
1057                            l_p11d_fields.f1_esize := ' ';
1058                          else
1059                           l_p11d_fields.f1_esize := car_benefits.f_esize;
1060                         end if;
1061                         l_p11d_fields.f1_date_free := car_benefits.f_date_free;
1062                         l_p11d_fields.f1_rein_yr := car_benefits.f_rein_yr;
1063                      elsif l_rec_count = 2
1064                      then
1065                          hr_utility.trace('car_benefits.f_make ' || car_benefits.f_make);
1066                          hr_utility.trace('l_rec_count in 2' || l_rec_count);
1067                          if to_number(l_ben_start) > to_number(l_tax_year_start)
1068                          then
1069                              l_p11d_fields.f2_start := car_benefits.f_start;
1070                          else
1071                              l_p11d_fields.f2_start := ' ';
1072                          end if;
1073                          if to_number(l_ben_end) < to_number(l_tax_year_end)
1074                          then
1075                              l_p11d_fields.f2_end := car_benefits.f_end;
1076                          else
1077                              l_p11d_fields.f2_end := ' ';
1078                          end if;
1079                          l_p11d_fields.f2_make := car_benefits.f_make;
1080                          l_p11d_fields.f2_dreg := car_benefits.f_dreg;
1081                          l_p11d_fields.f2_lprice := car_benefits.f_lprice;
1082                          l_p11d_fields.f2_cc := car_benefits.f_cc;
1083                          l_p11d_fields.f2_fcc := car_benefits.f_fcc;
1084                          l_p11d_fields.f2_fuel := car_benefits.f_fuel;
1085                          l_p11d_fields.f2_efig := car_benefits.f_efig;
1086                          l_p11d_fields.f2_nfig := car_benefits.f_nfig;
1087                          l_p11d_fields.f2_oprice := car_benefits.f_oprice;
1088                          --l_p11d_fields.f2_aprice := car_benefits.f_aprice;
1089                          l_p11d_fields.f2_cost := car_benefits.f_cost;
1090                          l_p11d_fields.f2_amg := car_benefits.f_amg;
1091                          if car_benefits.f_esize = '9999' and
1092                             to_number(l_date_reg) > 19980101 and
1093                             to_number(nvl(car_benefits.f_efig,0)) > 0 then
1094                             l_p11d_fields.f2_esize := ' ';
1095                          else
1096                             l_p11d_fields.f2_esize := car_benefits.f_esize;
1097                          end if;
1098                          l_p11d_fields.f2_date_free := car_benefits.f_date_free;
1099                          l_p11d_fields.f2_rein_yr := car_benefits.f_rein_yr;
1100                          exit;
1101                      end if;
1102                 end loop;
1103             end if;
1104         end;
1105 
1106         procedure populate_interest_fields
1107         is
1108              cursor csr_int_benefits(p_pactid    NUMBER,
1109                                      p_person_id VARCHAR2,
1110                                      p_emp_ref   VARCHAR2,
1111                                      p_emp_name  VARCHAR2)
1112              is
1113              select
1114                    pai_emp.action_information5 h_njb,
1115                    to_char(to_number(pai_emp.action_information6),'FM999,999,990.00') h_ayb,
1116                    to_char(to_number(pai_emp.action_information7),'FM999,999,990.00') h_mao,
1117                    decode(pai_emp.action_information8,null,'NIL','0','NIL',to_char(to_number(pai_emp.action_information8),'FM999,999,990.00')) h_ip,
1118                    substr(pai_emp.action_information9,9,2) || decode(pai_emp.action_information9,null,null,' ') ||
1119                    substr(pai_emp.action_information9,6,2) || decode(pai_emp.action_information9,null,null,' ') ||
1120                    substr(pai_emp.action_information9,1,4) h_dlm,
1121                    substr(pai_emp.action_information10,9,2) ||decode(pai_emp.action_information10,null,null,' ') ||
1122                    substr(pai_emp.action_information10,6,2) ||decode(pai_emp.action_information10,null,null,' ') ||
1123                    substr(pai_emp.action_information10,1,4) h_dld,
1124                    to_char(to_number(nvl(pai_emp.action_information11,'0')),'FM999,999,990.00') h_ce,
1125                    to_char(to_number(nvl(pai_emp.action_information16,'0')),'FM999,999,990.00') h_aye
1126              from  pay_action_information pai_emp
1127              where pai_emp.action_information_category = 'INT FREE AND LOW INT LOANS'
1128              and   pai_emp.action_context_type = 'AAP'
1129              and   pai_emp.action_context_id in ( select paa.assignment_action_id
1130                                                   from   pay_action_information pai_comp,
1131                                                          pay_action_information pai_person,
1132                                                          pay_assignment_actions paa,
1133                                                          pay_payroll_actions ppa
1134                                                    where ppa.payroll_action_id = p_pactid
1135                                                    and   paa.payroll_action_id = ppa.payroll_action_id
1136                                                    and   pai_comp.action_context_id = paa.assignment_action_id
1137                                                    and   pai_comp.action_information_category = 'EMEA PAYROLL INFO'
1138                                                    and   pai_comp.action_context_type = 'AAP'
1139                                                    and   pai_person.action_context_id = paa.assignment_action_id
1140                                                    and   pai_person.action_information_category = 'ADDRESS DETAILS'
1141                                                    and   pai_person.action_context_type = 'AAP'
1142                                                    and   pai_person.action_information14 = 'Employee Address'
1143                                                    and   pai_person.action_information1 = p_person_id
1144                                                    and   pai_comp.action_information6 = p_emp_ref
1145                                                    and   pai_comp.action_information7 = p_emp_name)
1146              and   to_number(nvl(pai_emp.action_information11,'0')) > 0 -- report only int free lons where CE is greater than 0
1147              order by pai_emp.action_information3, -- ben st dt
1148                       pai_emp.action_information4, -- ben end dt
1149                       pai_emp.action_information9, -- dt loan made
1150                       pai_emp.action_information10, -- dt loan disc
1151                       pai_emp.action_information11, -- cc
1152                       pai_emp.action_information1, -- ele entrty id
1153                       pai_emp.action_information2; -- effec date
1154              l_rec_count         INTEGER := 0;
1155         begin
1156              hr_utility.trace('l_h_count ' || l_h_count);
1157              hr_utility.trace('max outstd ' || l_h_sum_max_amt_outstanding);
1158              if l_h_count > 2  and
1159              -- Added this extra and condition for 3558538
1160              -- this will ensure that only int free lons where CE is greater than 0
1161              -- are reported
1162                  l_h_sum_max_amt_outstanding > 5000
1163              then
1164                  l_p11d_fields.h2_ce := 'See Attached';
1165                  l_p11d_fields.h1_ce := l_h_ce;
1166                  hr_utility.trace('See att ' );
1167              elsif l_h_count > 0  and
1168              -- Added this extra and condition for 3558538
1169              -- this will ensure that only int free lons where CE is greater than 0
1170              -- are reported
1171                  l_h_sum_max_amt_outstanding > 5000
1172              then
1173                  hr_utility.trace('l_payroll_action_id ' || g_payroll_action_id);
1174                  hr_utility.trace('l_person_id ' || g_person_id);
1175                  for int_benefits in csr_int_benefits(g_payroll_action_id,
1176                                                       g_person_id,
1177                                                       g_emp_ref_no,
1178                                                       g_employer_name)
1179                  loop
1180                      l_rec_count := l_rec_count + 1;
1181                      hr_utility.trace('l_rec_count ' || l_rec_count);
1182                      if l_rec_count = 1
1183                      then
1184                          hr_utility.trace('int_benefits.h_njb ' || int_benefits.h_njb);
1185                          l_p11d_fields.h1_njb := int_benefits.h_njb;
1186                          l_p11d_fields.h1_ayb := int_benefits.h_ayb;
1187                          l_p11d_fields.h1_mao := int_benefits.h_mao;
1188                          l_p11d_fields.h1_ip := int_benefits.h_ip;
1189                          l_p11d_fields.h1_dlm := int_benefits.h_dlm;
1190                          l_p11d_fields.h1_dld := int_benefits.h_dld;
1191                          l_p11d_fields.h1_ce := int_benefits.h_ce;
1192                          l_p11d_fields.h1_aye := int_benefits.h_aye;
1193                       elsif l_rec_count = 2
1194                       then
1195                          hr_utility.trace('int_benefits.h_njb ' || int_benefits.h_njb);
1196                          l_p11d_fields.h2_njb := int_benefits.h_njb;
1197                          l_p11d_fields.h2_ayb := int_benefits.h_ayb;
1198                          l_p11d_fields.h2_mao := int_benefits.h_mao;
1199                          l_p11d_fields.h2_ip := int_benefits.h_ip;
1200                          l_p11d_fields.h2_dlm := int_benefits.h_dlm;
1201                          l_p11d_fields.h2_dld := int_benefits.h_dld;
1202                          l_p11d_fields.h2_ce := int_benefits.h_ce;
1203                          l_p11d_fields.h2_aye := int_benefits.h_aye;
1204                          exit;
1205                       end if;
1206                  end loop;
1207              end if;
1208         end;
1209    begin
1210         hr_utility.trace('Inside fetch p11d rep_data p_assignment_action_id' || p_assignment_action_id);
1211         select payroll_action_id
1212         into  g_payroll_action_id
1213         from  pay_assignment_actions
1214         where assignment_action_id = p_assignment_action_id;
1215 
1216         hr_utility.trace('g_payroll_action_id ' || g_payroll_action_id);
1217         populate_stored_fields;
1218         hr_utility.trace('Calling populate car fields ' );
1219         populate_car_fields;
1220         hr_utility.trace('Calling interest fields ' );
1221         populate_interest_fields;
1222         return l_p11d_fields;
1223    end;
1224 --
1225    function fetch_p11d_rep_data_blob(p_assignment_action_id Number) return BLOB
1226    is
1227         l_p11d_fields l_typ_p11d_fields_rec;
1228         l_xfdf_string varchar2(31000);
1229         l_xfdf_clob   CLOB;
1230         l_xfdf_blob   BLOB;
1231         l_rep_run     VARCHAR2(10);
1232         l_pactid      NUMBER;
1233    begin
1234         hr_utility.trace('p_assignment_action_id ' || p_assignment_action_id);
1235         l_p11d_fields := fetch_p11d_rep_data(p_assignment_action_id);
1236 
1237         select payroll_action_id
1238         into   l_pactid
1239         from   pay_assignment_actions
1240         where  assignment_action_id = p_assignment_action_id;
1241 
1242         PAY_GB_P11D_ARCHIVE_SS.get_parameters(p_payroll_action_id  => l_pactid,
1243                                               p_token_name         => 'Rep_Run',
1244                                               p_token_value        => l_rep_run);
1245 
1246         if to_number(l_rep_run) < 2005
1247         then
1248             l_xfdf_string := '<?xml version = "1.0" encoding = "UTF-8"?>
1249             <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
1250             <fields> ' ||
1251             ' <field name="'|| 'DIRECTOR_FLAG'   ||'"><value>' ||    l_p11d_fields.DIRECTOR_FLAG       || '</value></field> ' ||
1252             ' <field name="'|| 'FULL_NAME'       ||'"><value>' ||    l_p11d_fields.FULL_NAME           || '</value></field> ' ||
1253             ' <field name="'|| 'EMPLOYEE_NUMBER' ||'"><value>' ||    l_p11d_fields.EMPLOYEE_NUMBER     || '</value></field> ' ||
1254             ' <field name="'|| 'NATIONAL_INS_NO' ||'"><value>' ||    l_p11d_fields.NATIONAL_INS_NO     || '</value></field> ' ||
1255             ' <field name="'|| 'EMPLOYERS_REF_NO'||'"><value>' ||    l_p11d_fields.EMPLOYERS_REF_NO    || '</value></field> ' ||
1256             ' <field name="'|| 'EMPLOYERS_NAME'  ||'"><value>' ||    l_p11d_fields.EMPLOYERS_NAME      || '</value></field> ' ||
1257             ' <field name="'|| 'A_DESC'          ||'"><value>' ||    l_p11d_fields.A_DESC              || '</value></field> ' ||
1258             ' <field name="'|| 'A_COST'          ||'"><value>' ||    l_p11d_fields.A_COST              || '</value></field> ' ||
1259             ' <field name="'|| 'A_AMG'           ||'"><value>' ||    l_p11d_fields.A_AMG               || '</value></field> ' ||
1260             ' <field name="'|| 'A_CE'            ||'"><value>' ||    l_p11d_fields.A_CE                || '</value></field> ' ||
1261             ' <field name="'|| 'B_DESC'          ||'"><value>' ||    l_p11d_fields.B_DESC              || '</value></field> ' ||
1262             ' <field name="'|| 'B_CE'            ||'"><value>' ||    l_p11d_fields.B_CE                || '</value></field> ' ||
1263             ' <field name="'|| 'B_TNP'           ||'"><value>' ||    l_p11d_fields.B_TNP               || '</value></field> ' ||
1264             ' <field name="'|| 'C_COST'          ||'"><value>' ||    l_p11d_fields.C_COST              || '</value></field> ' ||
1265             ' <field name="'|| 'C_AMG'           ||'"><value>' ||    l_p11d_fields.C_AMG               || '</value></field> ' ||
1266             ' <field name="'|| 'C_CE'            ||'"><value>' ||    l_p11d_fields.C_CE                || '</value></field> ' ||
1267             ' <field name="'|| 'D_CE'            ||'"><value>' ||    l_p11d_fields.D_CE                || '</value></field> ' ||
1268             ' <field name="'|| 'E_CE'            ||'"><value>' ||    l_p11d_fields.E_CE                || '</value></field> ' ||
1269             ' <field name="'|| 'F1_MAKE'         ||'"><value>' ||    l_p11d_fields.F1_MAKE             || '</value></field> ' ||
1270             ' <field name="'|| 'F1_DREG1'        ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,0,2)  || '</value></field> ' ||
1271             ' <field name="'|| 'F1_DREG2'        ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,4,2)  || '</value></field> ' ||
1272             ' <field name="'|| 'F1_DREG3'        ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,7)    || '</value></field> ' ||
1273             ' <field name="'|| 'F1_EFIG'         ||'"><value>' ||    l_p11d_fields.F1_EFIG             || '</value></field> ' ||
1274             ' <field name="'|| 'F1_NFIG'         ||'"><value>' ||    l_p11d_fields.F1_NFIG             || '</value></field> ' ||
1275             ' <field name="'|| 'F1_ESIZE'        ||'"><value>' ||    l_p11d_fields.F1_ESIZE            || '</value></field> ' ||
1276             ' <field name="'|| 'F1_FUEL'         ||'"><value>' ||    l_p11d_fields.F1_FUEL             || '</value></field> ' ||
1277             ' <field name="'|| 'F1_START1'       ||'"><value>' ||   substr(l_p11d_fields.F1_START,0,2) || '</value></field> ' ||
1278             ' <field name="'|| 'F1_START2'       ||'"><value>' ||   substr(l_p11d_fields.F1_START,4,2) || '</value></field> ' ||
1279             ' <field name="'|| 'F1_START3'       ||'"><value>' ||   substr(l_p11d_fields.F1_START,7)   || '</value></field> ' ||
1280             ' <field name="'|| 'F1_END1'         ||'"><value>' ||   substr(l_p11d_fields.F1_END,0,2)   || '</value></field> ' ||
1281             ' <field name="'|| 'F1_END2'         ||'"><value>' ||   substr(l_p11d_fields.F1_END,4,2)   || '</value></field> ' ||
1282             ' <field name="'|| 'F1_END3'         ||'"><value>' ||   substr(l_p11d_fields.F1_END,7)     || '</value></field> ' ||
1283             ' <field name="'|| 'F1_LPRICE'       ||'"><value>' ||    l_p11d_fields.F1_LPRICE           || '</value></field> ' ||
1284             ' <field name="'|| 'F1_OPRICE'       ||'"><value>' ||    l_p11d_fields.F1_OPRICE           || '</value></field> ' ||
1285        --   ' <field name="'|| 'F1_APRICE'       ||'"><value>' ||    l_p11d_fields.F1_APRICE           || '</value></field> ' ||
1286             ' <field name="'|| 'F1_COST'         ||'"><value>' ||    l_p11d_fields.F1_COST             || '</value></field> ' ||
1287             ' <field name="'|| 'F1_AMG'          ||'"><value>' ||    l_p11d_fields.F1_AMG              || '</value></field> ' ||
1288             ' <field name="'|| 'F1_CC'           ||'"><value>' ||    l_p11d_fields.F1_CC               || '</value></field> ' ||
1289             ' <field name="'|| 'F1_FCC'          ||'"><value>' ||    l_p11d_fields.F1_FCC              || '</value></field> ' ||
1290             ' <field name="'|| 'F2_MAKE'         ||'"><value>' ||    l_p11d_fields.F2_MAKE             || '</value></field> ' ||
1291             ' <field name="'|| 'F2_DREG1'        ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,0,2)  || '</value></field> ' ||
1292             ' <field name="'|| 'F2_DREG2'        ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,4,2)  || '</value></field> ' ||
1293             ' <field name="'|| 'F2_DREG3'        ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,7)    || '</value></field> ' ||
1294             ' <field name="'|| 'F2_EFIG'         ||'"><value>' ||    l_p11d_fields.F2_EFIG             || '</value></field> ' ||
1295             ' <field name="'|| 'F2_NFIG'         ||'"><value>' ||    l_p11d_fields.F2_NFIG             || '</value></field> ' ||
1296             ' <field name="'|| 'F2_ESIZE'        ||'"><value>' ||    l_p11d_fields.F2_ESIZE            || '</value></field> ' ||
1297             ' <field name="'|| 'F2_FUEL'         ||'"><value>' ||    l_p11d_fields.F2_FUEL             || '</value></field> ' ||
1298             ' <field name="'|| 'F2_START1'       ||'"><value>' ||   substr(l_p11d_fields.F2_START,0,2) || '</value></field> ' ||
1299             ' <field name="'|| 'F2_START2'       ||'"><value>' ||   substr(l_p11d_fields.F2_START,4,2) || '</value></field> ' ||
1300             ' <field name="'|| 'F2_START3'       ||'"><value>' ||   substr(l_p11d_fields.F2_START,7)   || '</value></field> ' ||
1301             ' <field name="'|| 'F2_END1'         ||'"><value>' ||   substr(l_p11d_fields.F2_END,0,2)   || '</value></field> ' ||
1302             ' <field name="'|| 'F2_END2'         ||'"><value>' ||   substr(l_p11d_fields.F2_END,4,2)   || '</value></field> ' ||
1303             ' <field name="'|| 'F2_END3'         ||'"><value>' ||   substr(l_p11d_fields.F2_END,7)     || '</value></field> ' ||
1304             ' <field name="'|| 'F2_LPRICE'       ||'"><value>' ||    l_p11d_fields.F2_LPRICE           || '</value></field> ' ||
1305             ' <field name="'|| 'F2_OPRICE'       ||'"><value>' ||    l_p11d_fields.F2_OPRICE           || '</value></field> ' ||
1306             ' <field name="'|| 'F2_APRICE'       ||'"><value>' ||    l_p11d_fields.F2_APRICE           || '</value></field> ' ||
1307             ' <field name="'|| 'F2_COST'         ||'"><value>' ||    l_p11d_fields.F2_COST             || '</value></field> ' ||
1308             ' <field name="'|| 'F2_AMG'          ||'"><value>' ||    l_p11d_fields.F2_AMG              || '</value></field> ' ||
1309             ' <field name="'|| 'F2_CC'           ||'"><value>' ||    l_p11d_fields.F2_CC               || '</value></field> ' ||
1310             ' <field name="'|| 'F2_FCC'          ||'"><value>' ||    l_p11d_fields.F2_FCC              || '</value></field> ' ||
1311             ' <field name="'|| 'F_DATE_FREE1'    ||'"><value>' ||    substr(l_p11d_fields.F_DATE_FREE,0,2) || '</value></field> ' ||
1312             ' <field name="'|| 'F_DATE_FREE2'    ||'"><value>' ||    substr(l_p11d_fields.F_DATE_FREE,4,2) || '</value></field> ' ||
1313             ' <field name="'|| 'F_DATE_FREE3'    ||'"><value>' ||    substr(l_p11d_fields.F_DATE_FREE,7)   || '</value></field> ' ||
1314             ' <field name="'|| 'F_REIN_YR'       ||'"><value>' ||    l_p11d_fields.F_REIN_YR           || '</value></field> ' ||
1315             ' <field name="'|| 'F_TCCE'          ||'"><value>' ||    l_p11d_fields.F_TCCE              || '</value></field> ' ||
1316             ' <field name="'|| 'F_TFCE'          ||'"><value>' ||    l_p11d_fields.F_TFCE              || '</value></field> ' ||
1317             ' <field name="'|| 'G_CE'            ||'"><value>' ||    l_p11d_fields.G_CE                || '</value></field> ' ||
1318             ' <field name="'|| 'H1_NJB'          ||'"><value>' ||    l_p11d_fields.H1_NJB              || '</value></field> ' ||
1319             ' <field name="'|| 'H1_AYB'          ||'"><value>' ||    l_p11d_fields.H1_AYB              || '</value></field> ' ||
1320             ' <field name="'|| 'H1_AYE'          ||'"><value>' ||    l_p11d_fields.H1_AYE              || '</value></field> ' ||
1321             ' <field name="'|| 'H1_MAO'          ||'"><value>' ||    l_p11d_fields.H1_MAO              || '</value></field> ' ||
1322             ' <field name="'|| 'H1_IP'           ||'"><value>' ||    l_p11d_fields.H1_IP               || '</value></field> ' ||
1323             ' <field name="'|| 'H1_DLM1'         ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,0,2)  || '</value></field> ' ||
1324             ' <field name="'|| 'H1_DLM2'         ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,4,2)  || '</value></field> ' ||
1325             ' <field name="'|| 'H1_DLM3'         ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,7)    || '</value></field> ' ||
1326             ' <field name="'|| 'H1_DLD1'         ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,0,2)  || '</value></field> ' ||
1327             ' <field name="'|| 'H1_DLD2'         ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,4,2)  || '</value></field> ' ||
1328             ' <field name="'|| 'H1_DLD3'         ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,7)    || '</value></field> ' ||
1329             ' <field name="'|| 'H1_CE'           ||'"><value>' ||    nvl(l_p11d_fields.H1_CE,'0.00')   || '</value></field> ' ||
1330             ' <field name="'|| 'H2_NJB'          ||'"><value>' ||    l_p11d_fields.H2_NJB              || '</value></field> ' ||
1331             ' <field name="'|| 'H2_AYB'          ||'"><value>' ||    l_p11d_fields.H2_AYB              || '</value></field> ' ||
1332             ' <field name="'|| 'H2_AYE'          ||'"><value>' ||    l_p11d_fields.H2_AYE              || '</value></field> ' ||
1333             ' <field name="'|| 'H2_MAO'          ||'"><value>' ||    l_p11d_fields.H2_MAO              || '</value></field> ' ||
1334             ' <field name="'|| 'H2_IP'           ||'"><value>' ||    l_p11d_fields.H2_IP               || '</value></field> ' ||
1335             ' <field name="'|| 'H2_DLM1'         ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,0,2)  || '</value></field> ' ||
1336             ' <field name="'|| 'H2_DLM2'         ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,4,2)  || '</value></field> ' ||
1337             ' <field name="'|| 'H2_DLM3'         ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,7)    || '</value></field> ' ||
1338             ' <field name="'|| 'H2_DLD1'         ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,0,2)  || '</value></field> ' ||
1339             ' <field name="'|| 'H2_DLD2'         ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,4,2)  || '</value></field> ' ||
1340             ' <field name="'|| 'H2_DLD3'         ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,7)    || '</value></field> ' ||
1341             ' <field name="'|| 'H2_CE'           ||'"><value>' ||    nvl(l_p11d_fields.H2_CE,'0.00')   || '</value></field> ' ||
1342             ' <field name="'|| 'I_COST'          ||'"><value>' ||    l_p11d_fields.I_COST              || '</value></field> ' ||
1343             ' <field name="'|| 'I_AMG'           ||'"><value>' ||    l_p11d_fields.I_AMG               || '</value></field> ' ||
1344             ' <field name="'|| 'I_CE'            ||'"><value>' ||    l_p11d_fields.I_CE                || '</value></field> ' ||
1345             ' <field name="'|| 'J_CE'            ||'"><value>' ||    l_p11d_fields.J_CE                || '</value></field> ' ||
1346             ' <field name="'|| 'K_COST'          ||'"><value>' ||    l_p11d_fields.K_COST              || '</value></field> ' ||
1347             ' <field name="'|| 'K_AMG'           ||'"><value>' ||    l_p11d_fields.K_AMG               || '</value></field> ' ||
1348             ' <field name="'|| 'K_CE'            ||'"><value>' ||    l_p11d_fields.K_CE                || '</value></field> ' ||
1349             ' <field name="'|| 'L_DESC'          ||'"><value>' ||    l_p11d_fields.L_DESC              || '</value></field> ' ||
1350             ' <field name="'|| 'L_COST'          ||'"><value>' ||    l_p11d_fields.L_COST              || '</value></field> ' ||
1351             ' <field name="'|| 'L_AMG'           ||'"><value>' ||    l_p11d_fields.L_AMG               || '</value></field> ' ||
1352             ' <field name="'|| 'L_CE'            ||'"><value>' ||    l_p11d_fields.L_CE                || '</value></field> ' ||
1353             ' <field name="'|| 'M_SHARES'        ||'"><value>' ||    l_p11d_fields.M_SHARES            || '</value></field> ' ||
1354             ' <field name="'|| 'N_COST'          ||'"><value>' ||    l_p11d_fields.N_COST              || '</value></field> ' ||
1355             ' <field name="'|| 'N_AMG'           ||'"><value>' ||    l_p11d_fields.N_AMG               || '</value></field> ' ||
1356             ' <field name="'|| 'N_CE'            ||'"><value>' ||    l_p11d_fields.N_CE                || '</value></field> ' ||
1357             ' <field name="'|| 'N_DESC'          ||'"><value>' ||    replace(l_p11d_fields.N_DESC,'&','&')              || '</value></field> ' ||
1358             ' <field name="'|| 'NA_COST'         ||'"><value>' ||    l_p11d_fields.NA_COST             || '</value></field> ' ||
1359             ' <field name="'|| 'NA_AMG'          ||'"><value>' ||    l_p11d_fields.NA_AMG              || '</value></field> ' ||
1360             ' <field name="'|| 'NA_CE'           ||'"><value>' ||    l_p11d_fields.NA_CE               || '</value></field> ' ||
1361             ' <field name="'|| 'NA_DESC'         ||'"><value>' ||    l_p11d_fields.NA_DESC             || '</value></field> ' ||
1362             ' <field name="'|| 'N_TAXPAID'       ||'"><value>' ||    l_p11d_fields.N_TAXPAID           || '</value></field> ' ||
1363             ' <field name="'|| 'O1_COST'         ||'"><value>' ||    l_p11d_fields.O1_COST             || '</value></field> ' ||
1364             ' <field name="'|| 'O1_AMG'          ||'"><value>' ||    l_p11d_fields.O1_AMG              || '</value></field> ' ||
1365             ' <field name="'|| 'O1_CE'           ||'"><value>' ||    l_p11d_fields.O1_CE               || '</value></field> ' ||
1366             ' <field name="'|| 'O2_COST'         ||'"><value>' ||    l_p11d_fields.O2_COST             || '</value></field> ' ||
1367             ' <field name="'|| 'O2_AMG'          ||'"><value>' ||    l_p11d_fields.O2_AMG              || '</value></field> ' ||
1368             ' <field name="'|| 'O2_CE'           ||'"><value>' ||    l_p11d_fields.O2_CE               || '</value></field> ' ||
1369             ' <field name="'|| 'O3_COST'         ||'"><value>' ||    l_p11d_fields.O3_COST             || '</value></field> ' ||
1370             ' <field name="'|| 'O3_AMG'          ||'"><value>' ||    l_p11d_fields.O3_AMG              || '</value></field> ' ||
1371             ' <field name="'|| 'O3_CE'           ||'"><value>' ||    l_p11d_fields.O3_CE               || '</value></field> ' ||
1372             ' <field name="'|| 'O4_COST'         ||'"><value>' ||    l_p11d_fields.O4_COST             || '</value></field> ' ||
1373             ' <field name="'|| 'O4_AMG'          ||'"><value>' ||    l_p11d_fields.O4_AMG              || '</value></field> ' ||
1374             ' <field name="'|| 'O4_CE'           ||'"><value>' ||    l_p11d_fields.O4_CE               || '</value></field> ' ||
1375             ' <field name="'|| 'O5_COST'         ||'"><value>' ||    l_p11d_fields.O5_COST             || '</value></field> ' ||
1376             ' <field name="'|| 'O5_AMG'          ||'"><value>' ||    l_p11d_fields.O5_AMG              || '</value></field> ' ||
1377             ' <field name="'|| 'O5_CE'           ||'"><value>' ||    l_p11d_fields.O5_CE               || '</value></field> ' ||
1378             ' <field name="'|| 'O6_COST'         ||'"><value>' ||    l_p11d_fields.O6_COST             || '</value></field> ' ||
1379             ' <field name="'|| 'O6_AMG'          ||'"><value>' ||    l_p11d_fields.O6_AMG              || '</value></field> ' ||
1380             ' <field name="'|| 'O6_CE'           ||'"><value>' ||    l_p11d_fields.O6_CE               || '</value></field> ' ||
1381             ' <field name="'|| 'O6_DESC'         ||'"><value>' ||    l_p11d_fields.O6_DESC             || '</value></field> ' ||
1382             ' <field name="'|| 'O_TOI'           ||'"><value>' ||    l_p11d_fields.O_TOI               || '</value></field> ' ||
1383             '</fields>  </xfdf>';
1384         elsif to_number(l_rep_run) >= 2005 and to_number(l_rep_run) < 2008 then -- P11D changes 07/08
1385             l_xfdf_string := '<?xml version = "1.0" encoding = "UTF-8"?>
1386             <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
1387             <fields> ' ||
1388             ' <field name="'|| 'DIRECTOR_FLAG'    ||'"><value>' ||    l_p11d_fields.DIRECTOR_FLAG       || '</value></field> ' ||
1389             ' <field name="'|| 'FULL_NAME'        ||'"><value>' ||    l_p11d_fields.FULL_NAME           || '</value></field> ' ||
1390             ' <field name="'|| 'EMPLOYEE_NUMBER'  ||'"><value>' ||    l_p11d_fields.EMPLOYEE_NUMBER     || '</value></field> ' ||
1391             ' <field name="'|| 'NATIONAL_INS_NO'  ||'"><value>' ||    l_p11d_fields.NATIONAL_INS_NO     || '</value></field> ' ||
1392             ' <field name="'||'NI_1'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,1,1) || '</value></field> ' ||
1393             ' <field name="'||'NI_2'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,2,1) || '</value></field> ' ||
1394             ' <field name="'||'NI_3'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,3,1) || '</value></field> ' ||
1395             ' <field name="'||'NI_4'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,4,1) || '</value></field> ' ||
1396             ' <field name="'||'NI_5'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,5,1) || '</value></field> ' ||
1397             ' <field name="'||'NI_6'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,6,1) || '</value></field> ' ||
1398             ' <field name="'||'NI_7'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,7,1) || '</value></field> ' ||
1399             ' <field name="'||'NI_8'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,8,1) || '</value></field> ' ||
1400             ' <field name="'||'NI_9'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,9)   || '</value></field> ' ||
1401             ' <field name="'||'GENDER'            ||'"><value>' ||    l_p11d_fields.gender                   || '</value></field> ' ||
1402             ' <field name="'||'DB1'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,1,1)    || '</value></field> ' ||
1403             ' <field name="'||'DB2'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,2,1)    || '</value></field> ' ||
1404             ' <field name="'||'DB3'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,3,1)    || '</value></field> ' ||
1405             ' <field name="'||'DB4'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,4,1)    || '</value></field> ' ||
1406             ' <field name="'||'DB5'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,5,1)    || '</value></field> ' ||
1407             ' <field name="'||'DB6'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,6,1)    || '</value></field> ' ||
1408             ' <field name="'||'DB7'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,7,1)    || '</value></field> ' ||
1409             ' <field name="'||'DB8'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,8,1)    || '</value></field> ' ||
1410             ' <field name="'|| 'EMPLOYERS_REF_NO' ||'"><value>' ||    l_p11d_fields.EMPLOYERS_REF_NO    || '</value></field> ' ||
1411             ' <field name="'|| 'EMPLOYERS_NAME'   ||'"><value>' ||    l_p11d_fields.EMPLOYERS_NAME      || '</value></field> ' ||
1412             ' <field name="'|| 'A_DESC'           ||'"><value>' ||    l_p11d_fields.A_DESC              || '</value></field> ' ||
1413             ' <field name="'|| 'A_COST'           ||'"><value>' ||    l_p11d_fields.A_COST              || '</value></field> ' ||
1414             ' <field name="'|| 'A_AMG'            ||'"><value>' ||    l_p11d_fields.A_AMG               || '</value></field> ' ||
1415             ' <field name="'|| 'A_CE'             ||'"><value>' ||    l_p11d_fields.A_CE                || '</value></field> ' ||
1416             ' <field name="'|| 'B_DESC'           ||'"><value>' ||    l_p11d_fields.B_DESC              || '</value></field> ' ||
1417             ' <field name="'|| 'B_CE'             ||'"><value>' ||    l_p11d_fields.B_CE                || '</value></field> ' ||
1418             ' <field name="'|| 'B_TNP'            ||'"><value>' ||    l_p11d_fields.B_TNP               || '</value></field> ' ||
1419             ' <field name="'|| 'C_COST'           ||'"><value>' ||    l_p11d_fields.C_COST              || '</value></field> ' ||
1420             ' <field name="'|| 'C_AMG'            ||'"><value>' ||    l_p11d_fields.C_AMG               || '</value></field> ' ||
1421             ' <field name="'|| 'C_CE'             ||'"><value>' ||    l_p11d_fields.C_CE                || '</value></field> ' ||
1422             ' <field name="'|| 'D_CE'             ||'"><value>' ||    l_p11d_fields.D_CE                || '</value></field> ' ||
1423             ' <field name="'|| 'E_CE'             ||'"><value>' ||    l_p11d_fields.E_CE                || '</value></field> ' ||
1424             ' <field name="'|| 'F1_MAKE'          ||'"><value>' ||    l_p11d_fields.F1_MAKE             || '</value></field> ' ||
1425             ' <field name="'|| 'F1_DREG1'         ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,0,2)  || '</value></field> ' ||
1426             ' <field name="'|| 'F1_DREG2'         ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,4,2)  || '</value></field> ' ||
1427             ' <field name="'|| 'F1_DREG3'         ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,7)    || '</value></field> ' ||
1428             ' <field name="'|| 'F1_EFIG'          ||'"><value>' ||    l_p11d_fields.F1_EFIG             || '</value></field> ' ||
1429             ' <field name="'|| 'F1_NFIG'          ||'"><value>' ||    l_p11d_fields.F1_NFIG             || '</value></field> ' ||
1430             ' <field name="'|| 'F1_ESIZE'         ||'"><value>' ||    l_p11d_fields.F1_ESIZE            || '</value></field> ' ||
1431             ' <field name="'|| 'F1_FUEL'          ||'"><value>' ||    l_p11d_fields.F1_FUEL             || '</value></field> ' ||
1432             ' <field name="'|| 'F1_START1'        ||'"><value>' ||   substr(l_p11d_fields.F1_START,0,2) || '</value></field> ' ||
1433             ' <field name="'|| 'F1_START2'        ||'"><value>' ||   substr(l_p11d_fields.F1_START,4,2) || '</value></field> ' ||
1434             ' <field name="'|| 'F1_START3'        ||'"><value>' ||   substr(l_p11d_fields.F1_START,7)   || '</value></field> ' ||
1435             ' <field name="'|| 'F1_END1'          ||'"><value>' ||   substr(l_p11d_fields.F1_END,0,2)   || '</value></field> ' ||
1436             ' <field name="'|| 'F1_END2'          ||'"><value>' ||   substr(l_p11d_fields.F1_END,4,2)   || '</value></field> ' ||
1437             ' <field name="'|| 'F1_END3'          ||'"><value>' ||   substr(l_p11d_fields.F1_END,7)     || '</value></field> ' ||
1438             ' <field name="'|| 'F1_LPRICE'        ||'"><value>' ||    l_p11d_fields.F1_LPRICE           || '</value></field> ' ||
1439             ' <field name="'|| 'F1_OPRICE'        ||'"><value>' ||    l_p11d_fields.F1_OPRICE           || '</value></field> ' ||
1440        --   ' <field name="'|| 'F1_APRICE'        ||'"><value>' ||    l_p11d_fields.F1_APRICE           || '</value></field> ' ||
1441             ' <field name="'|| 'F1_COST'          ||'"><value>' ||    l_p11d_fields.F1_COST             || '</value></field> ' ||
1442             ' <field name="'|| 'F1_AMG'           ||'"><value>' ||    l_p11d_fields.F1_AMG              || '</value></field> ' ||
1443             ' <field name="'|| 'F1_DATE_FREE1'    ||'"><value>' ||    substr(l_p11d_fields.F1_DATE_FREE,0,2)  || '</value></field> ' ||
1444             ' <field name="'|| 'F1_DATE_FREE2'    ||'"><value>' ||    substr(l_p11d_fields.F1_DATE_FREE,4,2)  || '</value></field> ' ||
1445             ' <field name="'|| 'F1_DATE_FREE3'    ||'"><value>' ||    substr(l_p11d_fields.F1_DATE_FREE,7)    || '</value></field> ' ||
1446             ' <field name="'|| 'F1_REIN_YR'       ||'"><value>' ||    l_p11d_fields.F1_REIN_YR          || '</value></field> ' ||
1447             ' <field name="'|| 'F1_CC'            ||'"><value>' ||    l_p11d_fields.F1_CC               || '</value></field> ' ||
1448             ' <field name="'|| 'F1_FCC'           ||'"><value>' ||    l_p11d_fields.F1_FCC              || '</value></field> ' ||
1449             ' <field name="'|| 'F2_MAKE'          ||'"><value>' ||    l_p11d_fields.F2_MAKE             || '</value></field> ' ||
1450             ' <field name="'|| 'F2_DREG1'         ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,0,2)  || '</value></field> ' ||
1451             ' <field name="'|| 'F2_DREG2'         ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,4,2)  || '</value></field> ' ||
1452             ' <field name="'|| 'F2_DREG3'         ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,7)    || '</value></field> ' ||
1453             ' <field name="'|| 'F2_EFIG'          ||'"><value>' ||    l_p11d_fields.F2_EFIG             || '</value></field> ' ||
1454             ' <field name="'|| 'F2_NFIG'          ||'"><value>' ||    l_p11d_fields.F2_NFIG             || '</value></field> ' ||
1455             ' <field name="'|| 'F2_ESIZE'         ||'"><value>' ||    l_p11d_fields.F2_ESIZE            || '</value></field> ' ||
1456             ' <field name="'|| 'F2_FUEL'          ||'"><value>' ||    l_p11d_fields.F2_FUEL             || '</value></field> ' ||
1457             ' <field name="'|| 'F2_START1'        ||'"><value>' ||   substr(l_p11d_fields.F2_START,0,2) || '</value></field> ' ||
1458             ' <field name="'|| 'F2_START2'        ||'"><value>' ||   substr(l_p11d_fields.F2_START,4,2) || '</value></field> ' ||
1459             ' <field name="'|| 'F2_START3'        ||'"><value>' ||   substr(l_p11d_fields.F2_START,7)   || '</value></field> ' ||
1460             ' <field name="'|| 'F2_END1'          ||'"><value>' ||   substr(l_p11d_fields.F2_END,0,2)   || '</value></field> ' ||
1461             ' <field name="'|| 'F2_END2'          ||'"><value>' ||   substr(l_p11d_fields.F2_END,4,2)   || '</value></field> ' ||
1462             ' <field name="'|| 'F2_END3'          ||'"><value>' ||   substr(l_p11d_fields.F2_END,7)     || '</value></field> ' ||
1463             ' <field name="'|| 'F2_LPRICE'        ||'"><value>' ||    l_p11d_fields.F2_LPRICE           || '</value></field> ' ||
1464             ' <field name="'|| 'F2_OPRICE'        ||'"><value>' ||    l_p11d_fields.F2_OPRICE           || '</value></field> ' ||
1465             ' <field name="'|| 'F2_APRICE'        ||'"><value>' ||    l_p11d_fields.F2_APRICE           || '</value></field> ' ||
1466             ' <field name="'|| 'F2_COST'          ||'"><value>' ||    l_p11d_fields.F2_COST             || '</value></field> ' ||
1467             ' <field name="'|| 'F2_AMG'           ||'"><value>' ||    l_p11d_fields.F2_AMG              || '</value></field> ' ||
1468             ' <field name="'|| 'F2_DATE_FREE1'    ||'"><value>' ||    substr(l_p11d_fields.F2_DATE_FREE,0,2) || '</value></field> ' ||
1469             ' <field name="'|| 'F2_DATE_FREE2'    ||'"><value>' ||    substr(l_p11d_fields.F2_DATE_FREE,4,2) || '</value></field> ' ||
1470             ' <field name="'|| 'F2_DATE_FREE3'    ||'"><value>' ||    substr(l_p11d_fields.F2_DATE_FREE,7)   || '</value></field> ' ||
1471             ' <field name="'|| 'F2_REIN_YR'       ||'"><value>' ||    l_p11d_fields.F1_REIN_YR          || '</value></field> ' ||
1472             ' <field name="'|| 'F2_CC'            ||'"><value>' ||    l_p11d_fields.F2_CC               || '</value></field> ' ||
1473             ' <field name="'|| 'F2_FCC'           ||'"><value>' ||    l_p11d_fields.F2_FCC              || '</value></field> ' ||
1474             ' <field name="'|| 'F_TCCE'           ||'"><value>' ||    l_p11d_fields.F_TCCE              || '</value></field> ' ||
1475             ' <field name="'|| 'F_TFCE'           ||'"><value>' ||    l_p11d_fields.F_TFCE              || '</value></field> ' ||
1476             ' <field name="'|| 'G_CE'             ||'"><value>' ||    l_p11d_fields.G_CE                || '</value></field> ' ||
1477             ' <field name="'|| 'H1_NJB'           ||'"><value>' ||    l_p11d_fields.H1_NJB              || '</value></field> ' ||
1478             ' <field name="'|| 'H1_AYB'           ||'"><value>' ||    l_p11d_fields.H1_AYB              || '</value></field> ' ||
1479             ' <field name="'|| 'H1_AYE'           ||'"><value>' ||    l_p11d_fields.H1_AYE              || '</value></field> ' ||
1480             ' <field name="'|| 'H1_MAO'           ||'"><value>' ||    l_p11d_fields.H1_MAO              || '</value></field> ' ||
1481             ' <field name="'|| 'H1_IP'            ||'"><value>' ||    l_p11d_fields.H1_IP               || '</value></field> ' ||
1482             ' <field name="'|| 'H1_DLM1'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,0,2)  || '</value></field> ' ||
1483             ' <field name="'|| 'H1_DLM2'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,4,2)  || '</value></field> ' ||
1484             ' <field name="'|| 'H1_DLM3'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,7)    || '</value></field> ' ||
1485             ' <field name="'|| 'H1_DLD1'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,0,2)  || '</value></field> ' ||
1486             ' <field name="'|| 'H1_DLD2'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,4,2)  || '</value></field> ' ||
1487             ' <field name="'|| 'H1_DLD3'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,7)    || '</value></field> ' ||
1488             ' <field name="'|| 'H1_CE'            ||'"><value>' ||    nvl(l_p11d_fields.H1_CE,'0.00')   || '</value></field> ' ||
1489             ' <field name="'|| 'H2_NJB'           ||'"><value>' ||    l_p11d_fields.H2_NJB              || '</value></field> ' ||
1490             ' <field name="'|| 'H2_AYB'           ||'"><value>' ||    l_p11d_fields.H2_AYB              || '</value></field> ' ||
1491             ' <field name="'|| 'H2_AYE'           ||'"><value>' ||    l_p11d_fields.H2_AYE              || '</value></field> ' ||
1492             ' <field name="'|| 'H2_MAO'           ||'"><value>' ||    l_p11d_fields.H2_MAO              || '</value></field> ' ||
1493             ' <field name="'|| 'H2_IP'            ||'"><value>' ||    l_p11d_fields.H2_IP               || '</value></field> ' ||
1494             ' <field name="'|| 'H2_DLM1'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,0,2)  || '</value></field> ' ||
1495             ' <field name="'|| 'H2_DLM2'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,4,2)  || '</value></field> ' ||
1496             ' <field name="'|| 'H2_DLM3'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,7)    || '</value></field> ' ||
1497             ' <field name="'|| 'H2_DLD1'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,0,2)  || '</value></field> ' ||
1498             ' <field name="'|| 'H2_DLD2'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,4,2)  || '</value></field> ' ||
1499             ' <field name="'|| 'H2_DLD3'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,7)    || '</value></field> ' ||
1500             ' <field name="'|| 'H2_CE'            ||'"><value>' ||    nvl(l_p11d_fields.H2_CE,'0.00')   || '</value></field> ' ||
1501             ' <field name="'|| 'I_COST'           ||'"><value>' ||    l_p11d_fields.I_COST              || '</value></field> ' ||
1502             ' <field name="'|| 'I_AMG'            ||'"><value>' ||    l_p11d_fields.I_AMG               || '</value></field> ' ||
1503             ' <field name="'|| 'I_CE'             ||'"><value>' ||    l_p11d_fields.I_CE                || '</value></field> ' ||
1504             ' <field name="'|| 'J_CE'             ||'"><value>' ||    l_p11d_fields.J_CE                || '</value></field> ' ||
1505             ' <field name="'|| 'K_COST'           ||'"><value>' ||    l_p11d_fields.K_COST              || '</value></field> ' ||
1506             ' <field name="'|| 'K_AMG'            ||'"><value>' ||    l_p11d_fields.K_AMG               || '</value></field> ' ||
1507             ' <field name="'|| 'K_CE'             ||'"><value>' ||    l_p11d_fields.K_CE                || '</value></field> ' ||
1508             ' <field name="'|| 'L_DESC'           ||'"><value>' ||    l_p11d_fields.L_DESC              || '</value></field> ' ||
1509             ' <field name="'|| 'L_COST'           ||'"><value>' ||    l_p11d_fields.L_COST              || '</value></field> ' ||
1510             ' <field name="'|| 'L_AMG'            ||'"><value>' ||    l_p11d_fields.L_AMG               || '</value></field> ' ||
1511             ' <field name="'|| 'L_CE'             ||'"><value>' ||    l_p11d_fields.L_CE                || '</value></field> ' ||
1512             ' <field name="'|| 'M_COST'           ||'"><value>' ||    l_p11d_fields.N_COST              || '</value></field> ' ||
1513             ' <field name="'|| 'M_AMG'            ||'"><value>' ||    l_p11d_fields.N_AMG               || '</value></field> ' ||
1514             ' <field name="'|| 'M_CE'             ||'"><value>' ||    l_p11d_fields.N_CE                || '</value></field> ' ||
1515             ' <field name="'|| 'M_DESC'           ||'"><value>' ||    replace(l_p11d_fields.N_DESC,'&','&')  || '</value></field> ' ||
1516             ' <field name="'|| 'MA_COST'          ||'"><value>' ||    l_p11d_fields.NA_COST             || '</value></field> ' ||
1517             ' <field name="'|| 'MA_AMG'           ||'"><value>' ||    l_p11d_fields.NA_AMG              || '</value></field> ' ||
1518             ' <field name="'|| 'MA_CE'            ||'"><value>' ||    l_p11d_fields.NA_CE               || '</value></field> ' ||
1519             ' <field name="'|| 'MA_DESC'          ||'"><value>' ||    l_p11d_fields.NA_DESC             || '</value></field> ' ||
1520             ' <field name="'|| 'M_TAXPAID'        ||'"><value>' ||    l_p11d_fields.N_TAXPAID           || '</value></field> ' ||
1521             ' <field name="'|| 'N1_COST'          ||'"><value>' ||    l_p11d_fields.O1_COST             || '</value></field> ' ||
1522             ' <field name="'|| 'N1_AMG'           ||'"><value>' ||    l_p11d_fields.O1_AMG              || '</value></field> ' ||
1523             ' <field name="'|| 'N1_CE'            ||'"><value>' ||    l_p11d_fields.O1_CE               || '</value></field> ' ||
1524             ' <field name="'|| 'N2_COST'          ||'"><value>' ||    l_p11d_fields.O2_COST             || '</value></field> ' ||
1525             ' <field name="'|| 'N2_AMG'           ||'"><value>' ||    l_p11d_fields.O2_AMG              || '</value></field> ' ||
1526             ' <field name="'|| 'N2_CE'            ||'"><value>' ||    l_p11d_fields.O2_CE               || '</value></field> ' ||
1527             ' <field name="'|| 'N3_COST'          ||'"><value>' ||    l_p11d_fields.O3_COST             || '</value></field> ' ||
1528             ' <field name="'|| 'N3_AMG'           ||'"><value>' ||    l_p11d_fields.O3_AMG              || '</value></field> ' ||
1529             ' <field name="'|| 'N3_CE'            ||'"><value>' ||    l_p11d_fields.O3_CE               || '</value></field> ' ||
1530             ' <field name="'|| 'N4_COST'          ||'"><value>' ||    l_p11d_fields.O4_COST             || '</value></field> ' ||
1531             ' <field name="'|| 'N4_AMG'           ||'"><value>' ||    l_p11d_fields.O4_AMG              || '</value></field> ' ||
1532             ' <field name="'|| 'N4_CE'            ||'"><value>' ||    l_p11d_fields.O4_CE               || '</value></field> ' ||
1533             ' <field name="'|| 'N5_COST'          ||'"><value>' ||    l_p11d_fields.O5_COST             || '</value></field> ' ||
1534             ' <field name="'|| 'N5_AMG'           ||'"><value>' ||    l_p11d_fields.O5_AMG              || '</value></field> ' ||
1535             ' <field name="'|| 'N5_CE'            ||'"><value>' ||    l_p11d_fields.O5_CE               || '</value></field> ' ||
1536             ' <field name="'|| 'N6_COST'          ||'"><value>' ||    l_p11d_fields.O6_COST             || '</value></field> ' ||
1537             ' <field name="'|| 'N6_AMG'           ||'"><value>' ||    l_p11d_fields.O6_AMG              || '</value></field> ' ||
1538             ' <field name="'|| 'N6_CE'            ||'"><value>' ||    l_p11d_fields.O6_CE               || '</value></field> ' ||
1539             ' <field name="'|| 'N6_DESC'          ||'"><value>' ||    l_p11d_fields.O6_DESC             || '</value></field> ' ||
1540             ' <field name="'|| 'N_TOI'            ||'"><value>' ||    l_p11d_fields.O_TOI               || '</value></field> ' ||
1541             '</fields>  </xfdf>';
1542           else -- P11d changes 07/08
1543             l_xfdf_string := '<?xml version = "1.0" encoding = "UTF-8"?>
1544             <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
1545             <fields> ' ||
1546             ' <field name="'|| 'DIRECTOR_FLAG'    ||'"><value>' ||    l_p11d_fields.DIRECTOR_FLAG       || '</value></field> ' ||
1547             ' <field name="'|| 'SUR_NAME'        ||'"><value>' ||     l_p11d_fields.SUR_NAME           || '</value></field> ' ||
1548             ' <field name="'|| 'FORE_NAME'        ||'"><value>' ||    l_p11d_fields.FORE_NAME           || '</value></field> ' ||
1549             ' <field name="'|| 'EMPLOYEE_NUMBER'  ||'"><value>' ||    l_p11d_fields.EMPLOYEE_NUMBER     || '</value></field> ' ||
1550             ' <field name="'|| 'NATIONAL_INS_NO'  ||'"><value>' ||    l_p11d_fields.NATIONAL_INS_NO     || '</value></field> ' ||
1551             ' <field name="'||'NI_1'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,1,1) || '</value></field> ' ||
1552             ' <field name="'||'NI_2'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,2,1) || '</value></field> ' ||
1553             ' <field name="'||'NI_3'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,3,1) || '</value></field> ' ||
1554             ' <field name="'||'NI_4'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,4,1) || '</value></field> ' ||
1555             ' <field name="'||'NI_5'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,5,1) || '</value></field> ' ||
1556             ' <field name="'||'NI_6'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,6,1) || '</value></field> ' ||
1557             ' <field name="'||'NI_7'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,7,1) || '</value></field> ' ||
1558             ' <field name="'||'NI_8'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,8,1) || '</value></field> ' ||
1559             ' <field name="'||'NI_9'              ||'"><value>' ||substr(l_p11d_fields.NATIONAL_INS_NO ,9)   || '</value></field> ' ||
1560             ' <field name="'||'GENDER'            ||'"><value>' ||    l_p11d_fields.gender                   || '</value></field> ' ||
1561             ' <field name="'||'DB1'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,1,1)    || '</value></field> ' ||
1562             ' <field name="'||'DB2'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,2,1)    || '</value></field> ' ||
1563             ' <field name="'||'DB3'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,3,1)    || '</value></field> ' ||
1564             ' <field name="'||'DB4'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,4,1)    || '</value></field> ' ||
1565             ' <field name="'||'DB5'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,5,1)    || '</value></field> ' ||
1566             ' <field name="'||'DB6'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,6,1)    || '</value></field> ' ||
1567             ' <field name="'||'DB7'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,7,1)    || '</value></field> ' ||
1568             ' <field name="'||'DB8'               ||'"><value>' ||substr(l_p11d_fields.date_of_birth,8,1)    || '</value></field> ' ||
1569             ' <field name="'|| 'EMPLOYERS_REF_NO' ||'"><value>' ||    l_p11d_fields.EMPLOYERS_REF_NO    || '</value></field> ' ||
1570             ' <field name="'|| 'EMPLOYERS_NAME'   ||'"><value>' ||    l_p11d_fields.EMPLOYERS_NAME      || '</value></field> ' ||
1571             ' <field name="'|| 'A_DESC'           ||'"><value>' ||    l_p11d_fields.A_DESC              || '</value></field> ' ||
1572             ' <field name="'|| 'A_COST'           ||'"><value>' ||    l_p11d_fields.A_COST              || '</value></field> ' ||
1573             ' <field name="'|| 'A_AMG'            ||'"><value>' ||    l_p11d_fields.A_AMG               || '</value></field> ' ||
1574             ' <field name="'|| 'A_CE'             ||'"><value>' ||    l_p11d_fields.A_CE                || '</value></field> ' ||
1575             ' <field name="'|| 'B_DESC'           ||'"><value>' ||    l_p11d_fields.B_DESC              || '</value></field> ' ||
1576             ' <field name="'|| 'B_CE'             ||'"><value>' ||    l_p11d_fields.B_CE                || '</value></field> ' ||
1577             ' <field name="'|| 'B_TNP'            ||'"><value>' ||    l_p11d_fields.B_TNP               || '</value></field> ' ||
1578             ' <field name="'|| 'C_COST'           ||'"><value>' ||    l_p11d_fields.C_COST              || '</value></field> ' ||
1579             ' <field name="'|| 'C_AMG'            ||'"><value>' ||    l_p11d_fields.C_AMG               || '</value></field> ' ||
1580             ' <field name="'|| 'C_CE'             ||'"><value>' ||    l_p11d_fields.C_CE                || '</value></field> ' ||
1581             ' <field name="'|| 'D_CE'             ||'"><value>' ||    l_p11d_fields.D_CE                || '</value></field> ' ||
1582             ' <field name="'|| 'E_CE'             ||'"><value>' ||    l_p11d_fields.E_CE                || '</value></field> ' ||
1583             ' <field name="'|| 'F1_MAKE'          ||'"><value>' ||    l_p11d_fields.F1_MAKE             || '</value></field> ' ||
1584             ' <field name="'|| 'F1_DREG1'         ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,0,2)  || '</value></field> ' ||
1585             ' <field name="'|| 'F1_DREG2'         ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,4,2)  || '</value></field> ' ||
1586             ' <field name="'|| 'F1_DREG3'         ||'"><value>' ||   substr(l_p11d_fields.F1_DREG,7)    || '</value></field> ' ||
1587             ' <field name="'|| 'F1_EFIG'          ||'"><value>' ||    l_p11d_fields.F1_EFIG             || '</value></field> ' ||
1588             ' <field name="'|| 'F1_NFIG'          ||'"><value>' ||    l_p11d_fields.F1_NFIG             || '</value></field> ' ||
1589             ' <field name="'|| 'F1_ESIZE'         ||'"><value>' ||    l_p11d_fields.F1_ESIZE            || '</value></field> ' ||
1590             ' <field name="'|| 'F1_FUEL'          ||'"><value>' ||    l_p11d_fields.F1_FUEL             || '</value></field> ' ||
1591             ' <field name="'|| 'F1_START1'        ||'"><value>' ||   substr(l_p11d_fields.F1_START,0,2) || '</value></field> ' ||
1592             ' <field name="'|| 'F1_START2'        ||'"><value>' ||   substr(l_p11d_fields.F1_START,4,2) || '</value></field> ' ||
1593             ' <field name="'|| 'F1_START3'        ||'"><value>' ||   substr(l_p11d_fields.F1_START,7)   || '</value></field> ' ||
1594             ' <field name="'|| 'F1_END1'          ||'"><value>' ||   substr(l_p11d_fields.F1_END,0,2)   || '</value></field> ' ||
1595             ' <field name="'|| 'F1_END2'          ||'"><value>' ||   substr(l_p11d_fields.F1_END,4,2)   || '</value></field> ' ||
1596             ' <field name="'|| 'F1_END3'          ||'"><value>' ||   substr(l_p11d_fields.F1_END,7)     || '</value></field> ' ||
1597             ' <field name="'|| 'F1_LPRICE'        ||'"><value>' ||    l_p11d_fields.F1_LPRICE           || '</value></field> ' ||
1598             ' <field name="'|| 'F1_OPRICE'        ||'"><value>' ||    l_p11d_fields.F1_OPRICE           || '</value></field> ' ||
1599        --   ' <field name="'|| 'F1_APRICE'        ||'"><value>' ||    l_p11d_fields.F1_APRICE           || '</value></field> ' ||
1600             ' <field name="'|| 'F1_COST'          ||'"><value>' ||    l_p11d_fields.F1_COST             || '</value></field> ' ||
1601             ' <field name="'|| 'F1_AMG'           ||'"><value>' ||    l_p11d_fields.F1_AMG              || '</value></field> ' ||
1602             ' <field name="'|| 'F1_DATE_FREE1'    ||'"><value>' ||    substr(l_p11d_fields.F1_DATE_FREE,0,2)  || '</value></field> ' ||
1603             ' <field name="'|| 'F1_DATE_FREE2'    ||'"><value>' ||    substr(l_p11d_fields.F1_DATE_FREE,4,2)  || '</value></field> ' ||
1604             ' <field name="'|| 'F1_DATE_FREE3'    ||'"><value>' ||    substr(l_p11d_fields.F1_DATE_FREE,7)    || '</value></field> ' ||
1605             ' <field name="'|| 'F1_REIN_YR'       ||'"><value>' ||    l_p11d_fields.F1_REIN_YR          || '</value></field> ' ||
1606             ' <field name="'|| 'F1_CC'            ||'"><value>' ||    l_p11d_fields.F1_CC               || '</value></field> ' ||
1607             ' <field name="'|| 'F1_FCC'           ||'"><value>' ||    l_p11d_fields.F1_FCC              || '</value></field> ' ||
1608             ' <field name="'|| 'F2_MAKE'          ||'"><value>' ||    l_p11d_fields.F2_MAKE             || '</value></field> ' ||
1609             ' <field name="'|| 'F2_DREG1'         ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,0,2)  || '</value></field> ' ||
1610             ' <field name="'|| 'F2_DREG2'         ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,4,2)  || '</value></field> ' ||
1611             ' <field name="'|| 'F2_DREG3'         ||'"><value>' ||   substr(l_p11d_fields.F2_DREG,7)    || '</value></field> ' ||
1612             ' <field name="'|| 'F2_EFIG'          ||'"><value>' ||    l_p11d_fields.F2_EFIG             || '</value></field> ' ||
1613             ' <field name="'|| 'F2_NFIG'          ||'"><value>' ||    l_p11d_fields.F2_NFIG             || '</value></field> ' ||
1614             ' <field name="'|| 'F2_ESIZE'         ||'"><value>' ||    l_p11d_fields.F2_ESIZE            || '</value></field> ' ||
1615             ' <field name="'|| 'F2_FUEL'          ||'"><value>' ||    l_p11d_fields.F2_FUEL             || '</value></field> ' ||
1616             ' <field name="'|| 'F2_START1'        ||'"><value>' ||   substr(l_p11d_fields.F2_START,0,2) || '</value></field> ' ||
1617             ' <field name="'|| 'F2_START2'        ||'"><value>' ||   substr(l_p11d_fields.F2_START,4,2) || '</value></field> ' ||
1618             ' <field name="'|| 'F2_START3'        ||'"><value>' ||   substr(l_p11d_fields.F2_START,7)   || '</value></field> ' ||
1619             ' <field name="'|| 'F2_END1'          ||'"><value>' ||   substr(l_p11d_fields.F2_END,0,2)   || '</value></field> ' ||
1620             ' <field name="'|| 'F2_END2'          ||'"><value>' ||   substr(l_p11d_fields.F2_END,4,2)   || '</value></field> ' ||
1621             ' <field name="'|| 'F2_END3'          ||'"><value>' ||   substr(l_p11d_fields.F2_END,7)     || '</value></field> ' ||
1622             ' <field name="'|| 'F2_LPRICE'        ||'"><value>' ||    l_p11d_fields.F2_LPRICE           || '</value></field> ' ||
1623             ' <field name="'|| 'F2_OPRICE'        ||'"><value>' ||    l_p11d_fields.F2_OPRICE           || '</value></field> ' ||
1624             ' <field name="'|| 'F2_APRICE'        ||'"><value>' ||    l_p11d_fields.F2_APRICE           || '</value></field> ' ||
1625             ' <field name="'|| 'F2_COST'          ||'"><value>' ||    l_p11d_fields.F2_COST             || '</value></field> ' ||
1626             ' <field name="'|| 'F2_AMG'           ||'"><value>' ||    l_p11d_fields.F2_AMG              || '</value></field> ' ||
1627             ' <field name="'|| 'F2_DATE_FREE1'    ||'"><value>' ||    substr(l_p11d_fields.F2_DATE_FREE,0,2) || '</value></field> ' ||
1628             ' <field name="'|| 'F2_DATE_FREE2'    ||'"><value>' ||    substr(l_p11d_fields.F2_DATE_FREE,4,2) || '</value></field> ' ||
1629             ' <field name="'|| 'F2_DATE_FREE3'    ||'"><value>' ||    substr(l_p11d_fields.F2_DATE_FREE,7)   || '</value></field> ' ||
1630             ' <field name="'|| 'F2_REIN_YR'       ||'"><value>' ||    l_p11d_fields.F1_REIN_YR          || '</value></field> ' ||
1631             ' <field name="'|| 'F2_CC'            ||'"><value>' ||    l_p11d_fields.F2_CC               || '</value></field> ' ||
1632             ' <field name="'|| 'F2_FCC'           ||'"><value>' ||    l_p11d_fields.F2_FCC              || '</value></field> ' ||
1633             ' <field name="'|| 'F_TCCE'           ||'"><value>' ||    l_p11d_fields.F_TCCE              || '</value></field> ' ||
1634             ' <field name="'|| 'F_TFCE'           ||'"><value>' ||    l_p11d_fields.F_TFCE              || '</value></field> ' ||
1635             ' <field name="'|| 'G_CE'             ||'"><value>' ||    l_p11d_fields.G_CE                || '</value></field> ' ||
1636             ' <field name="'|| 'G_CEF'            ||'"><value>' ||    l_p11d_fields.G_CEF               || '</value></field> ' ||
1637             ' <field name="'|| 'H1_NJB'           ||'"><value>' ||    l_p11d_fields.H1_NJB              || '</value></field> ' ||
1638             ' <field name="'|| 'H1_AYB'           ||'"><value>' ||    l_p11d_fields.H1_AYB              || '</value></field> ' ||
1639             ' <field name="'|| 'H1_AYE'           ||'"><value>' ||    l_p11d_fields.H1_AYE              || '</value></field> ' ||
1640             ' <field name="'|| 'H1_MAO'           ||'"><value>' ||    l_p11d_fields.H1_MAO              || '</value></field> ' ||
1641             ' <field name="'|| 'H1_IP'            ||'"><value>' ||    l_p11d_fields.H1_IP               || '</value></field> ' ||
1642             ' <field name="'|| 'H1_DLM1'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,0,2)  || '</value></field> ' ||
1643             ' <field name="'|| 'H1_DLM2'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,4,2)  || '</value></field> ' ||
1644             ' <field name="'|| 'H1_DLM3'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLM,7)    || '</value></field> ' ||
1645             ' <field name="'|| 'H1_DLD1'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,0,2)  || '</value></field> ' ||
1646             ' <field name="'|| 'H1_DLD2'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,4,2)  || '</value></field> ' ||
1647             ' <field name="'|| 'H1_DLD3'          ||'"><value>' ||    substr(l_p11d_fields.H1_DLD,7)    || '</value></field> ' ||
1648             ' <field name="'|| 'H1_CE'            ||'"><value>' ||    nvl(l_p11d_fields.H1_CE,'0.00')   || '</value></field> ' ||
1649             ' <field name="'|| 'H2_NJB'           ||'"><value>' ||    l_p11d_fields.H2_NJB              || '</value></field> ' ||
1650             ' <field name="'|| 'H2_AYB'           ||'"><value>' ||    l_p11d_fields.H2_AYB              || '</value></field> ' ||
1651             ' <field name="'|| 'H2_AYE'           ||'"><value>' ||    l_p11d_fields.H2_AYE              || '</value></field> ' ||
1652             ' <field name="'|| 'H2_MAO'           ||'"><value>' ||    l_p11d_fields.H2_MAO              || '</value></field> ' ||
1653             ' <field name="'|| 'H2_IP'            ||'"><value>' ||    l_p11d_fields.H2_IP               || '</value></field> ' ||
1654             ' <field name="'|| 'H2_DLM1'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,0,2)  || '</value></field> ' ||
1655             ' <field name="'|| 'H2_DLM2'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,4,2)  || '</value></field> ' ||
1656             ' <field name="'|| 'H2_DLM3'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLM,7)    || '</value></field> ' ||
1657             ' <field name="'|| 'H2_DLD1'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,0,2)  || '</value></field> ' ||
1658             ' <field name="'|| 'H2_DLD2'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,4,2)  || '</value></field> ' ||
1659             ' <field name="'|| 'H2_DLD3'          ||'"><value>' ||    substr(l_p11d_fields.H2_DLD,7)    || '</value></field> ' ||
1660             ' <field name="'|| 'H2_CE'            ||'"><value>' ||    nvl(l_p11d_fields.H2_CE,'0.00')   || '</value></field> ' ||
1661             ' <field name="'|| 'I_COST'           ||'"><value>' ||    l_p11d_fields.I_COST              || '</value></field> ' ||
1662             ' <field name="'|| 'I_AMG'            ||'"><value>' ||    l_p11d_fields.I_AMG               || '</value></field> ' ||
1663             ' <field name="'|| 'I_CE'             ||'"><value>' ||    l_p11d_fields.I_CE                || '</value></field> ' ||
1664             ' <field name="'|| 'J_CE'             ||'"><value>' ||    l_p11d_fields.J_CE                || '</value></field> ' ||
1665             ' <field name="'|| 'K_COST'           ||'"><value>' ||    l_p11d_fields.K_COST              || '</value></field> ' ||
1666             ' <field name="'|| 'K_AMG'            ||'"><value>' ||    l_p11d_fields.K_AMG               || '</value></field> ' ||
1667             ' <field name="'|| 'K_CE'             ||'"><value>' ||    l_p11d_fields.K_CE                || '</value></field> ' ||
1668             ' <field name="'|| 'L_DESC'           ||'"><value>' ||    l_p11d_fields.L_DESC              || '</value></field> ' ||
1669             ' <field name="'|| 'L_COST'           ||'"><value>' ||    l_p11d_fields.L_COST              || '</value></field> ' ||
1670             ' <field name="'|| 'L_AMG'            ||'"><value>' ||    l_p11d_fields.L_AMG               || '</value></field> ' ||
1671             ' <field name="'|| 'L_CE'             ||'"><value>' ||    l_p11d_fields.L_CE                || '</value></field> ' ||
1672             ' <field name="'|| 'M_COST'           ||'"><value>' ||    l_p11d_fields.N_COST              || '</value></field> ' ||
1673             ' <field name="'|| 'M_AMG'            ||'"><value>' ||    l_p11d_fields.N_AMG               || '</value></field> ' ||
1674             ' <field name="'|| 'M_CE'             ||'"><value>' ||    l_p11d_fields.N_CE                || '</value></field> ' ||
1675             ' <field name="'|| 'M_DESC'           ||'"><value>' ||    replace(l_p11d_fields.N_DESC,'&','&')  || '</value></field> ' ||
1676             ' <field name="'|| 'MA_COST'          ||'"><value>' ||    l_p11d_fields.NA_COST             || '</value></field> ' ||
1677             ' <field name="'|| 'MA_AMG'           ||'"><value>' ||    l_p11d_fields.NA_AMG              || '</value></field> ' ||
1678             ' <field name="'|| 'MA_CE'            ||'"><value>' ||    l_p11d_fields.NA_CE               || '</value></field> ' ||
1679             ' <field name="'|| 'MA_DESC'          ||'"><value>' ||    l_p11d_fields.NA_DESC             || '</value></field> ' ||
1680             ' <field name="'|| 'M_TAXPAID'        ||'"><value>' ||    l_p11d_fields.N_TAXPAID           || '</value></field> ' ||
1681             ' <field name="'|| 'N1_COST'          ||'"><value>' ||    l_p11d_fields.O1_COST             || '</value></field> ' ||
1682             ' <field name="'|| 'N1_AMG'           ||'"><value>' ||    l_p11d_fields.O1_AMG              || '</value></field> ' ||
1683             ' <field name="'|| 'N1_CE'            ||'"><value>' ||    l_p11d_fields.O1_CE               || '</value></field> ' ||
1684             ' <field name="'|| 'N2_COST'          ||'"><value>' ||    l_p11d_fields.O2_COST             || '</value></field> ' ||
1685             ' <field name="'|| 'N2_AMG'           ||'"><value>' ||    l_p11d_fields.O2_AMG              || '</value></field> ' ||
1686             ' <field name="'|| 'N2_CE'            ||'"><value>' ||    l_p11d_fields.O2_CE               || '</value></field> ' ||
1687             ' <field name="'|| 'N3_COST'          ||'"><value>' ||    l_p11d_fields.O3_COST             || '</value></field> ' ||
1688             ' <field name="'|| 'N3_AMG'           ||'"><value>' ||    l_p11d_fields.O3_AMG              || '</value></field> ' ||
1689             ' <field name="'|| 'N3_CE'            ||'"><value>' ||    l_p11d_fields.O3_CE               || '</value></field> ' ||
1690             ' <field name="'|| 'N4_COST'          ||'"><value>' ||    l_p11d_fields.O4_COST             || '</value></field> ' ||
1691             ' <field name="'|| 'N4_AMG'           ||'"><value>' ||    l_p11d_fields.O4_AMG              || '</value></field> ' ||
1692             ' <field name="'|| 'N4_CE'            ||'"><value>' ||    l_p11d_fields.O4_CE               || '</value></field> ' ||
1693             ' <field name="'|| 'N5_COST'          ||'"><value>' ||    l_p11d_fields.O5_COST             || '</value></field> ' ||
1694             ' <field name="'|| 'N5_AMG'           ||'"><value>' ||    l_p11d_fields.O5_AMG              || '</value></field> ' ||
1695             ' <field name="'|| 'N5_CE'            ||'"><value>' ||    l_p11d_fields.O5_CE               || '</value></field> ' ||
1696             ' <field name="'|| 'N6_COST'          ||'"><value>' ||    l_p11d_fields.O6_COST             || '</value></field> ' ||
1697             ' <field name="'|| 'N6_AMG'           ||'"><value>' ||    l_p11d_fields.O6_AMG              || '</value></field> ' ||
1698             ' <field name="'|| 'N6_CE'            ||'"><value>' ||    l_p11d_fields.O6_CE               || '</value></field> ' ||
1699             ' <field name="'|| 'N6_DESC'          ||'"><value>' ||    l_p11d_fields.O6_DESC             || '</value></field> ' ||
1700             ' <field name="'|| 'N_TOI'            ||'"><value>' ||    l_p11d_fields.O_TOI               || '</value></field> ' ||
1701             '</fields>  </xfdf>';
1702 
1703         end if;
1704 
1705         dbms_lob.createtemporary(l_xfdf_clob,false,DBMS_LOB.CALL);
1706         dbms_lob.open(l_xfdf_clob,dbms_lob.lob_readwrite);
1707         dbms_lob.writeAppend( l_xfdf_clob, length(l_xfdf_string ), l_xfdf_string  );
1708         DBMS_LOB.CREATETEMPORARY(l_xfdf_blob,true);
1709         -- clob_to_blob(l_xfdf_string,l_xfdf_blob);
1710         clob_to_blob(l_xfdf_clob,l_xfdf_blob);
1711         -- insert into temp values          (l_xfdf_clob);
1712         dbms_lob.close(l_xfdf_clob);
1713         dbms_lob.freetemporary(l_xfdf_clob);
1714         hr_utility.trace('P11D.......................');
1715         return l_xfdf_blob;
1716    exception
1717    when OTHERS then
1718           HR_UTILITY.TRACE('sqleerm ' || sqlerrm);
1719           HR_UTILITY.RAISE_ERROR;
1720    end;
1721 --
1722 
1723    function get_p11d_year return VARCHAR2
1724    is
1725         l_year              VARCHAR2(4);
1726         l_effective_date    DATE;
1727         cursor csr_year
1728         is
1729         --select to_char(ses.effective_date, 'YYYY'), ses.effective_date
1730         select to_char(sysdate,'YYYY'), ses.effective_date
1731         from   fnd_sessions ses
1732         where  ses.session_id = userenv('sessionid');
1733    begin
1734         open csr_year;
1735         fetch csr_year into l_year, l_effective_date;
1736         close csr_year;
1737         /*
1738         if l_effective_date > to_date('06-04-'|| l_year, 'DD-MM-YYYY')
1739         then
1740             null;
1741         else
1742             l_year := to_char(to_number(l_year) - 1);
1743         end if;
1744         */
1745         return l_year;
1746    end;
1747 
1748    function get_ben_start_date return date
1749    is
1750         l_year              VARCHAR2(4);
1751    begin
1752         l_year := get_p11d_year;
1753         return to_date('06-04-'|| to_char(to_number(l_year) - 1), 'DD-MM-YYYY');
1754    end;
1755 
1756    function get_ben_end_date return DATE
1757    is
1758         l_year              VARCHAR2(4);
1759    begin
1760         l_year := get_p11d_year;
1761         return to_date('05-04-'|| l_year, 'DD-MM-YYYY');
1762    end;
1763 
1764    procedure update_leg_process_status(errbuf              out nocopy VARCHAR2,
1765                                        retcode             out nocopy NUMBER,
1766                                        p_payroll_action_id in  Number,
1767                                        p_new_status        in  Varchar2)
1768    is
1769         l_param_string VARCHAR2(2000);
1770         l_param_string_before_val VARCHAR2(2000);
1771         l_param_string_after_val VARCHAR2(2000);
1772         Old_Archive exception;
1773    begin
1774         retcode := 0;
1775         select legislative_parameters
1776         into   l_param_string
1777         from   pay_payroll_actions
1778         where  payroll_action_id = p_payroll_action_id;
1779         -- check if the archiver has Status in it
1780         -- if not then it is old archiver 2002-2003 archiver.
1781         -- the one prior to self service being supplied.
1782         -- so this cannot be run on them, hence we should error it
1783         if instr(l_param_string,'Status=') = 0
1784         then
1785             raise Old_Archive;
1786         end if;
1787         l_param_string_before_val := substr(l_param_string,1,instr(l_param_string, ' Status=')-2) ;
1788         l_param_string_after_val  := substr(l_param_string,instr(l_param_string, 'Status=') + length('Status=')+1) ;
1789         update pay_payroll_actions
1790         set  legislative_parameters =l_param_string_before_val ||  p_new_status ||
1791             ' Status=' || p_new_status || l_param_string_after_val
1792         where payroll_action_id = p_payroll_action_id; --8875;
1793    exception
1794    when Old_Archive then
1795         retcode := 1;
1796         hr_utility.set_message(800, 'HR_78078_P11D_STAT_INCOR_ARCH');
1797         errbuf := hr_utility.get_message;
1798         hr_utility.raise_error;
1799    when OTHERS then
1800         retcode := 1;
1801         hr_utility.set_message(800, 'HR_78077_P11D_STATUS_CHG_ERR');
1802         hr_utility.set_message_token(800, 'ERRORMSG', sqlerrm);
1803         errbuf := hr_utility.get_message;
1804         hr_utility.raise_error;
1805    end;
1806 
1807    function get_lookup_meaning(p_lookup_type varchar2,
1808                                p_lookup_code varchar2,
1809                                p_effective_date date) return varchar2
1810    is
1811         l_meaning varchar2(100);
1812         /*Bug No. 3237648*/
1813         /*Fetching from hr_lookups instead of fnd_lookup_values*/
1814         cursor csr_meaning is
1815         select meaning
1816         from   hr_lookups hlu
1817         where  hlu.lookup_type = p_lookup_type
1818         and    hlu.lookup_code = p_lookup_code
1819         and    hlu.enabled_flag='Y'
1820         and    p_effective_date between
1821                    nvl( hlu.START_DATE_ACTIVE,p_effective_date)
1822                and nvl( hlu.END_DATE_ACTIVE , p_effective_date);
1823    begin
1824         open csr_meaning;
1825         fetch csr_meaning into l_meaning;
1826         close csr_meaning;
1827         return l_meaning;
1828    end;
1829 
1830    function fetch_arch_param_details(p_payroll_action_id in  Number) return varchar2
1831    is
1832         l_benefit_end_date     VARCHAR2(20);
1833         l_benefit_start_date   VARCHAR2(20);
1834         l_payroll_id           NUMBER;
1835         l_payroll              varchar2(100);
1836         l_person_id            NUMBER;
1837         l_person               varchar2(100);
1838         l_rep_run              varchar2(10);
1839         l_consolidation_set_id NUMBER;
1840         l_consolidation_set    varchar2(100);
1841         l_tax_reference        VARCHAR2(200);
1842         l_assignment_set_id    NUMBER;
1843         l_assignment_set       VARCHAR2(200);
1844         l_run_type_code        varchar2(10);
1845         l_run_type_meaning     varchar2(20);
1846         l_status_code          varchar2(10);
1847         l_status_meaning       varchar2(20);
1848         l_return_string varchar2(1000);
1849         cursor csr_payroll(p_effective_date date)
1850         is
1851         select PAYROLL_NAME
1852         from  pay_payrolls_f
1853         where PAYROLL_ID =  l_payroll_id
1854         and   p_effective_date between
1855                   nvl(effective_start_date,p_effective_date)
1856               and nvl(effective_start_date,p_effective_date);
1857 
1858         cursor csr_person(p_effective_date date)
1859         is
1860         select FULL_NAME
1861         from  per_people_f
1862         where person_ID =  l_person_id
1863         and   p_effective_date between
1864                   nvl(effective_start_date,p_effective_date)
1865               and nvl(effective_start_date,p_effective_date);
1866 
1867         cursor csr_consolidation_set
1868         is
1869         select CONSOLIDATION_SET_NAME
1870         from   PAY_CONSOLIDATION_SETS
1871         where  CONSOLIDATION_SET_ID   = l_consolidation_set_id;
1872 
1873         cursor csr_assignment_set is
1874         select ASSIGNMENT_SET_NAME
1875         from   HR_ASSIGNMENT_SETS_V
1876         where  ASSIGNMENT_SET_ID =l_assignment_set_id;
1877 
1878         l_effective_date date;
1879    begin
1880         begin
1881              select effective_date into l_effective_date
1882              from   fnd_sessions
1883              where  SESSION_ID = userenv('sessionid');
1884         exception
1885         when Others then
1886              l_effective_date := sysdate;
1887         end;
1888         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1889          p_payroll_action_id           => p_payroll_action_id,
1890          p_token_name                  => 'PAYROLL',
1891          p_token_value                 => l_payroll_id);
1892         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1893          p_payroll_action_id           => p_payroll_action_id,
1894          p_token_name                  => 'PERSON',
1895          p_token_value                 => l_person_id);
1896         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1897          p_payroll_action_id           => p_payroll_action_id,
1898          p_token_name                  => 'CONSOLIDATION_SET',
1899          p_token_value                 => l_consolidation_set_id);
1900         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1901          p_payroll_action_id           => p_payroll_action_id,
1902          p_token_name                  => 'TAX_REFERENCE',
1903          p_token_value                 => l_tax_reference);
1904         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1905          p_payroll_action_id           => p_payroll_action_id,
1906          p_token_name                  => 'ASSIGNMENT_SET_ID',
1907          p_token_value                 => l_assignment_set_id);
1908         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1909          p_payroll_action_id           => p_payroll_action_id,
1910          p_token_name                  => 'BENEFIT_START_DATE',
1911          p_token_value                 => l_benefit_start_date);
1912         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1913          p_payroll_action_id           => p_payroll_action_id,
1914          p_token_name                  => 'BENEFIT_END_DATE',
1915          p_token_value                 => l_benefit_end_date);
1916         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1917          p_payroll_action_id           => p_payroll_action_id,
1918          p_token_name                  => 'Rep_Run',
1919          p_token_value                 => l_rep_run);
1920         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1921          p_payroll_action_id           => p_payroll_action_id,
1922          p_token_name                  => 'Status',
1923          p_token_value                 => l_status_code);
1924         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1925          p_payroll_action_id           => p_payroll_action_id,
1926          p_token_name                  => 'Run_Type',
1927          p_token_value                 => l_run_type_code);
1928         l_run_type_meaning := get_lookup_meaning('GB_P11D_RUN_TYPE',
1929                                                  l_run_type_code,
1930                                                  fnd_date.canonical_to_date(l_benefit_end_date));
1931         l_status_meaning := get_lookup_meaning('GB_P11D_LEGISLATIVE_RUN_STATUS',
1932                                                l_status_code,
1933                                                fnd_date.canonical_to_date(l_benefit_end_date));
1934         l_return_string := l_rep_run || '   ' || l_run_type_meaning || '   '  ||
1935                            l_status_meaning ||  '   ' ||
1936                            fnd_date.date_to_displaydate(fnd_date.canonical_to_date(l_benefit_start_date))||
1937                            '/' ||
1938                           fnd_date.date_to_displaydate(fnd_date.canonical_to_date(l_benefit_end_date));
1939 
1940         if l_payroll_id is not null
1941         then
1942             open csr_payroll(l_effective_date);
1943             fetch csr_payroll into l_payroll;
1944             close csr_payroll;
1945             l_return_string := l_return_string || l_payroll || '/';
1946         else
1947             l_return_string := l_return_string || '/';
1948         end if;
1949 
1950         if l_person_id is not null
1951         then
1952             open csr_person(l_effective_date);
1953             fetch csr_person into l_person;
1954             close csr_person;
1955             l_return_string := l_return_string || l_person || '/' ;
1956         else
1957             l_return_string := l_return_string || '/';
1958         end if;
1959 
1960         if l_tax_reference is not null
1961         then
1962             l_return_string := l_return_string || l_tax_reference || '/' ;
1963         else
1964             l_return_string := l_return_string || '/';
1965         end if;
1966 
1967         if l_consolidation_set_id is not null
1968         then
1969             open csr_consolidation_set;
1970             fetch csr_consolidation_set into l_consolidation_set;
1971             close csr_consolidation_set;
1972             l_return_string := l_return_string || l_consolidation_set || '/' ;
1973         else
1974             l_return_string := l_return_string || '/' ;
1975         end if;
1976 
1977         if l_assignment_set_id is not null
1978         then
1979             open csr_assignment_set;
1980             fetch csr_assignment_set into l_assignment_set;
1981             close csr_assignment_set;
1982             l_return_string := l_return_string || l_assignment_set ;
1983         end if;
1984         return l_return_string;
1985    end;
1986 
1987    function fetch_leg_process_status(p_payroll_action_id in  Number) return varchar2
1988    is
1989         l_benefit_end_date   VARCHAR2(20);
1990         l_benefit_start_date VARCHAR2(20);
1991         l_status_code        varchar2(10);
1992         l_status_meaning     varchar2(20);
1993    begin
1994         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1995          p_payroll_action_id           => p_payroll_action_id,
1996          p_token_name                  => 'BENEFIT_END_DATE',
1997          p_token_value                 => l_benefit_end_date);
1998         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
1999          p_payroll_action_id           => p_payroll_action_id,
2000          p_token_name                  => 'Status',
2001          p_token_value                 => l_status_code);
2002         l_status_meaning := get_lookup_meaning('GB_P11D_LEGISLATIVE_RUN_STATUS',
2003                                                l_status_code,
2004                                                fnd_date.canonical_to_date(l_benefit_end_date));
2005         return l_status_meaning;
2006    end;
2007 
2008    function fetch_leg_process_runtype(p_payroll_action_id in  Number) return varchar2
2009    is
2010         l_benefit_end_date            VARCHAR2(20);
2011         l_run_type_code               varchar2(10);
2012         l_run_type_meaning            varchar2(20);
2013    begin
2014         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
2015          p_payroll_action_id           => p_payroll_action_id,
2016          p_token_name                  => 'BENEFIT_END_DATE',
2017          p_token_value                 => l_benefit_end_date);
2018         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
2019          p_payroll_action_id           => p_payroll_action_id,
2020          p_token_name                  => 'Run_Type',
2021          p_token_value                 => l_run_type_code);
2022         l_run_type_meaning := get_lookup_meaning('GB_P11D_RUN_TYPE',
2023                                                  l_run_type_code,
2024                                                  fnd_date.canonical_to_date(l_benefit_end_date));
2025         return l_run_type_meaning;
2026    end;
2027 
2028    function fetch_leg_process_notes(p_payroll_action_id in  Number) return varchar2
2029    is
2030         l_notes            VARCHAR2(200);
2031    begin
2032         -- we know notes is the last parameter hence we are using simple substr
2033         -- to fetch it's value
2034         -- if we add further params then the below would not work!
2035         select substr(legislative_parameters,
2036                instr(legislative_parameters, 'NOTES=') + (length('NOTES=')))
2037         into  l_notes
2038         from  pay_payroll_actions
2039         where payroll_action_id = p_payroll_action_id;
2040         return l_notes;
2041    exception
2042    when others then
2043         l_notes := null;
2044         return l_notes;
2045    end;
2046 
2047    function get_pactid(p_assignment_action_id NUmber) return number
2048    is
2049         cursor csr_pactid
2050         is
2051         select payroll_action_id
2052         from   pay_assignment_actions
2053         where  assignment_action_id = p_assignment_action_id;
2054         l_pactid number;
2055    begin
2056         open csr_pactid ;
2057         fetch csr_pactid into l_pactid;
2058         close csr_pactid ;
2059         return l_pactid;
2060    end;
2061 
2062    function get_person_id (p_assignment_action_id NUmber) return number
2063    is
2064         cursor csr_person_id
2065         is
2066         select action_information1
2067         from  pay_action_information pai_person
2068         where pai_person.action_context_id = p_assignment_action_id
2069         and   pai_person.action_information_category = 'ADDRESS DETAILS'
2070         and   pai_person.action_information14 = 'Employee Address';
2071         l_person_id number;
2072    begin
2073         open csr_person_id ;
2074         fetch csr_person_id into l_person_id;
2075         close csr_person_id ;
2076         return l_person_id;
2077    end;
2078 
2079    procedure get_employer_details(p_assignment_action_id Number,
2080                                   p_emp_ref_no out nocopy  varchar2,
2081                                   p_employer_name out nocopy varchar2)
2082    is
2083         cursor csr_employer_details
2084         is
2085         select action_information6,
2086                action_information7
2087         from   pay_action_information pai_comp
2088         where  pai_comp.action_context_id = p_assignment_action_id
2089         and    pai_comp.action_information_category = 'EMEA PAYROLL INFO';
2090    begin
2091         open  csr_employer_details;
2092         fetch csr_employer_details into p_emp_ref_no,
2093                                         p_employer_name;
2094         close csr_employer_details;
2095    end;
2096 
2097    procedure get_employee_details(p_assignment_action_id Number,
2098                                   p_full_name out nocopy  varchar2,
2099                                   p_national_ins_no out nocopy  varchar2,
2100                                   p_employee_number out nocopy varchar2)
2101    is
2102         cursor csr_employee_details
2103         is
2104         select action_information1,
2105                action_information4,
2106                action_information10
2107         from   pay_action_information pai_emp
2108         where  pai_emp.action_context_id = p_assignment_action_id
2109         and    pai_emp.action_information_category = 'EMPLOYEE DETAILS';
2110    begin
2111         open  csr_employee_details;
2112         fetch csr_employee_details into p_full_name,
2113                                         p_national_ins_no,
2114                                         p_employee_number;
2115         close csr_employee_details;
2116    end;
2117 
2118    function fetch_ws1_ref_cursor (p_assignment_action_id Number,
2119                                   p_record_num out nocopy NUmber) return ref_cursor_typ
2120    is
2121         -- per_gb_xfdftableType is explicitly created type
2122         -- only modification needed is it could be of type blob
2123         -- i tried thta but could not access the blob valus in java routine.
2124         -- can be sorted later
2125         l_xfdf_str_tab per_gb_xfdftableType := per_gb_xfdftableType( );
2126         l_xfdf_str varchar2(32000);
2127         l_ret_ref_cursor ref_cursor_typ;
2128         l_offset integer;
2129         l_varchar_buffer varchar2(32000);
2130         l_raw_buffer raw(32000);
2131         l_buffer_len number:= 32000;
2132         l_chunk_len number;
2133 
2134         cursor csr_context_id (p_pactid    NUMBER,
2135                                p_person_id NUMBER,
2136                                p_emp_ref   VARCHAR2,
2137                                p_emp_name  VARCHAR2)
2138         is
2139         select /*+ ORDERED use_nl(ppa, paa, pai_comp, pai_person, pai_car)
2140                            use_index(pai_comp,pay_action_information_n2)
2141                            use_index(pai_person,pay_action_information_n2)
2142                            use_index(pai_car,pay_action_information_n2) */
2143                pai_car.action_context_id
2144         from   pay_payroll_actions ppa,
2145                pay_assignment_actions paa,
2146                pay_action_information pai_comp,
2147                pay_action_information pai_person,
2148                pay_action_information pai_car
2149         where  ppa.payroll_action_id = p_pactid
2150         and    paa.payroll_action_id = ppa.payroll_action_id
2151         and    pai_comp.action_context_id = paa.assignment_action_id
2152         and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
2153         and    pai_comp.action_context_type = 'AAP'
2154         and    pai_person.action_context_id = paa.assignment_action_id
2155         and    pai_person.action_information_category = 'ADDRESS DETAILS'
2156         and    pai_person.action_context_type = 'AAP'
2157         and    pai_person.action_information14 = 'Employee Address'
2158         and    pai_person.action_information1 = to_char(p_person_id)
2159         and    pai_comp.action_information6 = p_emp_ref
2160         and    pai_comp.action_information7 = p_emp_name
2161         and    pai_car.action_context_id = paa.assignment_action_id
2162         and    pai_car.action_information_category = 'LIVING ACCOMMODATION'
2163         and    pai_car.action_context_type = 'AAP'
2164         group by pai_car.action_context_id;
2165 
2166         cursor csr_living_acco (p_context_id NUMBER)
2167         is
2168         select pai_ben.ACTION_INFORMATION5 address,
2169                decode(months_between(
2170                 fnd_date.canonical_to_date(pai_ben.action_information4)+1,
2171                 fnd_date.canonical_to_date(pai_ben.action_information3)),12,'Y','N') full_year,
2172                to_char(to_number(nvl(pai_ben.action_information6,0)),'FM999,999,990.00') rent_employer,
2173                to_char(to_number(nvl(pai_ben.action_information7,0)),'FM999,999,990.00') annual_value,
2174                to_char(to_number(nvl(pai_ben.action_information18,0)),'FM999,999,990.00')Basic_Charge_Cost,
2175                to_char(to_number(nvl(pai_ben.action_information9,0)),'FM999,999,990.00') amg,
2176                to_char(to_number(nvl(pai_ben.action_information19,0)),'FM999,999,990.00')Basic_Charge,
2177                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2178                    nvl(pai_ben.action_information8,0)),'FM999,999,990.00'),null)gross_amount,
2179                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2180                    nvl(pai_ben.action_information13,0)),'FM999,999,990.00'),null) emp_share_of_cost,
2181                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2182                    nvl(pai_ben.action_information20,0)),'FM999,999,990.00'),null) cost_of_acco,
2183                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2184                    nvl(pai_ben.action_information22,0)),'FM999,999,990.00'),null) excess_of_cost,
2185                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2186                    nvl(pai_ben.action_information14,0)),'FM999,999,990.00'),null) INTEREST_VALUE,
2187                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2188                    nvl(pai_ben.action_information21,0)),'FM999,999,990.00'),null) INTEREST_AMOUNT,
2189                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2190                    nvl(pai_ben.action_information16,0)),'FM999,999,990.00'),null) rent_employee,
2191                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2192                    nvl(pai_ben.action_information9,0)),'FM999,999,990.00'),null) RENT_IN_AMG,
2193                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2194                    nvl(pai_ben.action_information17,0)),'FM999,999,990.00'),null) ADDITIONAL_CHARGE,
2195                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2196                    nvl(pai_ben.action_information19,0)),'FM999,999,990.00'),null) BASIC_CHARGE_2,
2197                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2198                    nvl(pai_ben.action_information16,0) - nvl(pai_ben.action_information9,0)),'FM999,999,990.00'),null) ACTUAL_RENT,
2199                decode(sign(pai_ben.action_information22),1,to_char(to_number(
2200                    nvl(pai_ben.action_information19,0)+nvl(pai_ben.action_information17,0)),'FM999,999,990.00'),null) TOTAL ,
2201                decode(sign(pai_ben.action_information22),
2202                       1,decode(months_between(
2203                         fnd_date.canonical_to_date(pai_ben.action_information4)+1,
2204                         fnd_date.canonical_to_date(pai_ben.action_information3)),12,null,
2205                       to_char(to_number(nvl(pai_ben.action_information15,0)))),null) NUMBER_OF_DAYS
2206         from  pay_action_information pai_ben
2207         where pai_ben.action_information_category = 'LIVING ACCOMMODATION'
2208         and   pai_ben.action_context_id = p_context_id
2209         and   pai_ben.action_context_type = 'AAP';
2210 
2211         l_emp_ref_no varchar2(150);
2212         l_employer_name varchar2(150);
2213         l_full_name varchar2(150);
2214         l_national_ins_no varchar2(150);
2215         l_employee_number varchar2(150);
2216         l_pactid number;
2217         l_person_id number;
2218         l_loop_count Number;
2219   begin
2220         get_employer_details(p_assignment_action_id,
2221                              l_emp_ref_no,
2222                              l_employer_name);
2223         get_employee_details(p_assignment_action_id,
2224                              l_full_name,
2225                              l_national_ins_no,
2226                              l_employee_number);
2227         l_pactid := get_pactid(p_assignment_action_id);
2228         l_person_id := get_person_id(p_assignment_action_id );
2229         l_loop_count := 0;
2230         for context_rec in csr_context_id(l_pactid,
2231                                           l_person_id,
2232                                           l_emp_ref_no,
2233                                           l_employer_name) loop
2234         for living_acco in  csr_living_acco(context_rec.action_context_id)
2235         loop
2236             l_loop_count := l_loop_count+1;
2237             l_xfdf_str_tab.extend;
2238             l_employee_number := get_assignment_number(context_rec.action_context_id);
2239             l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
2240             <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
2241             <fields> ' ||
2242            ' <field name="'||'EMPLOYERS_NAME'||'"><value>' ||replace(l_employer_name,'&','&') || '</value></field> ' ||
2243            ' <field name="'||'FULL_NAME'||'"><value>' ||l_full_name || '</value></field>  ' ||
2244            ' <field name="'||'EMPLOYERS_REF_NO'||'"><value>' ||l_emp_ref_no || '</value></field>  ' ||
2245            ' <field name="'||'EMPLOYEE_NUMBER'||'"><value>' ||l_employee_number || '</value></field>  ' ||
2246            -- ' <field name="'||'NATIONAL_INS_NO'||'"><value>' ||l_national_ins_no || '</value></field>  ' ||
2247            ' <field name="'||'NI_1'||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
2248            ' <field name="'||'NI_2'||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
2249            ' <field name="'||'NI_3'||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
2250            ' <field name="'||'NI_4'||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
2251            ' <field name="'||'NI_5'||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
2252            ' <field name="'||'NI_6'||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
2253            ' <field name="'||'NI_7'||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
2254            ' <field name="'||'NI_8'||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
2255            ' <field name="'||'NI_9'||'"><value>' ||substr(l_national_ins_no,9) || '</value></field>  '   ||
2256            ' <field name="'||'ADDRESS'||'"><value>' ||living_acco.address || '</value></field>  ' ||
2257            ' <field name="'||'FULL_YEAR'||'"><value>' ||living_acco.full_year || '</value></field>  ' ||
2258            ' <field name="'||'FULL_YEAR_Y'||'"><value>' ||living_acco.full_year || '</value></field>  ' ||
2259            ' <field name="'||'FULL_YEAR_N'||'"><value>' ||living_acco.full_year || '</value></field>  ' ||
2260            ' <field name="'||'RENT_EMPLOYER'||'"><value>' ||living_acco.rent_employer || '</value></field>  ' ||
2261            ' <field name="'||'ANNUAL_VALUE'||'"><value>' ||living_acco.annual_value || '</value></field>  ' ||
2262            ' <field name="'||'BASIC_CHARGE_COST'||'"><value>' ||living_acco.Basic_Charge_Cost || '</value></field>  ' ||
2263            ' <field name="'||'AMG'||'"><value>' ||living_acco.amg || '</value></field>  ' ||
2264            ' <field name="'||'BASIC_CHARGE'||'"><value>' ||living_acco.Basic_Charge || '</value></field>  ' ||
2265            ' <field name="'||'GROSS_AMOUNT'||'"><value>' ||living_acco.gross_amount || '</value></field>  ' ||
2266            ' <field name="'||'EMP_SHARE_OF_COST'||'"><value>' ||living_acco.emp_share_of_cost || '</value></field>  ' ||
2267            ' <field name="'||'COST_OF_ACCO'||'"><value>' ||living_acco.cost_of_acco || '</value></field>  ' ||
2268            ' <field name="'||'EXCESS_OF_COST'||'"><value>' ||living_acco.excess_of_cost || '</value></field>  ' ||
2269            ' <field name="'||'INTEREST_VALUE'||'"><value>' ||living_acco.INTEREST_VALUE || '</value></field>  ' ||
2270            ' <field name="'||'NUMBER_OF_DAYS'||'"><value>' ||living_acco.NUMBER_OF_DAYS || '</value></field>  ' ||
2271            ' <field name="'||'INTEREST_AMOUNT'||'"><value>' ||living_acco.INTEREST_AMOUNT || '</value></field>  ' ||
2272            ' <field name="'||'RENT_EMPLOYEE'||'"><value>' ||living_acco.rent_employee || '</value></field>  ' ||
2273            ' <field name="'||'RENT_IN_AMG'||'"><value>' ||living_acco.RENT_IN_AMG || '</value></field>  ' ||
2274            ' <field name="'||'ACTUAL_RENT'||'"><value>' ||living_acco.ACTUAL_RENT || '</value></field>  ' ||
2275            ' <field name="'||'ADDITIONAL_CHARGE'||'"><value>' ||living_acco.ADDITIONAL_CHARGE || '</value></field>  ' ||
2276            ' <field name="'||'BASIC_CHARGE_2'||'"><value>' ||living_acco.BASIC_CHARGE_2 || '</value></field>  ' ||
2277            ' <field name="'||'TOTAL'||'"><value>' ||living_acco.TOTAL || '</value></field>  ' ||
2278            '</fields>  </xfdf>';
2279         end loop;
2280         end loop;
2281         open l_ret_ref_cursor for
2282         select *
2283         from table (cast(l_xfdf_str_tab as per_gb_xfdftableType));
2284         p_record_num := l_loop_count;
2285         return l_ret_ref_cursor;
2286    end ;
2287 
2288 -------------------------------------------------------------------------------------------
2289 -- Function: rep_assignment_actions
2290 -- Description: Create a cursor depending on the parameters that are passed in
2291 --              and return the cursor to calling procedure (eg PER_P11d_PAPER_REP)
2292 --              using a Ref Cursor
2293 -------------------------------------------------------------------------------------------
2294    function rep_assignment_actions(p_payroll_action_id Number,
2295                                    p_assignment_action_id  Number,
2296                                    p_organization_id Number,
2297                                    p_location_code Varchar2,
2298                                    p_org_hierarchy Number,
2299                                    p_assignment_set_id Number,
2300                                    p_sort_order1 Varchar2,
2301                                    p_sort_order2 Varchar2,
2302                                    p_chunk_size  Number,
2303                                    p_chunk_number Number,
2304                                    p_person_type Varchar2) return ref_cursor_typ
2305    is
2306         l_ret_ref_cursor ref_cursor_typ;
2307         l_select varchar2(500);
2308         l_from   varchar2(500);
2309         l_where  varchar2(10000);
2310         l_group  varchar2(200);
2311         l_order  varchar2(100);
2312         l_sql    varchar2(15000);
2313         l_payroll_action_id Number;
2314         l_assignment_action_id  Number;
2315         l_organization_id Number;
2316         l_location_code Varchar2(100);
2317         l_org_hierarchy Number;
2318         l_assignment_set_id Number;
2319         l_sort_order1 Varchar2(100);
2320         l_sort_order2 Varchar2(100);
2321         l_pay_effective_date date;
2322         l_start    number;
2323         l_end      number;
2324         l_person_type Varchar2(20);
2325        --
2326         cursor pay_effective_date(c_payroll_action_id in number)
2327         is
2328         select pay.effective_date
2329         from   pay_payroll_actions pay
2330         where  pay.payroll_action_id = c_payroll_action_id;
2331      --
2332    begin
2333         if p_payroll_action_id = 0
2334         then
2335             l_payroll_action_id :=null;
2336         else
2337             l_payroll_action_id := p_payroll_action_id;
2338             --
2339             open pay_effective_date(l_payroll_action_id);
2340             fetch pay_effective_date into l_pay_effective_date;
2341             close pay_effective_date;
2342         end if;
2343 
2344         if p_assignment_action_id = 0
2345         then
2346             l_assignment_action_id := null;
2347         else
2348             l_assignment_action_id :=p_assignment_action_id;
2349         end if;
2350 
2351         if p_location_code = '0'
2352         then
2353             l_location_code :=null;
2354         else
2355             l_location_code :=p_location_code;
2356         end if;
2357 
2358         if p_org_hierarchy = 0
2359         then
2360             l_org_hierarchy :=null;
2361         else
2362             l_org_hierarchy :=p_org_hierarchy;
2363         end if;
2364 
2365         if p_assignment_set_id = 0
2366         then
2367             l_assignment_set_id :=null;
2368         else
2369             l_assignment_set_id :=p_assignment_set_id;
2370         end if;
2371 
2372         if p_sort_order1 = '0'
2373         then
2374             l_sort_order1 :=null;
2375         else
2376             l_sort_order1 :=p_sort_order1;
2377         end if;
2378 
2379         if p_sort_order2 = '0'
2380         then
2381             l_sort_order2 :=null;
2382         else
2383             l_sort_order2 :=p_sort_order2;
2384         end if;
2385 
2386         if p_person_type = '0'
2387         then
2388             l_person_type := null;
2389         else
2390             l_person_type := p_person_type;
2391         end if;
2392 
2393     /* since this query is fired just once in a session,
2394     instead of using the using clause,
2395     we are going to create the sql stmt by concatenating the values
2396     below is the example of it being dynamic
2397     */
2398  -- All above Commented out, start proper code here..
2399  --
2400         l_select := 'select asg_id
2401                      from (select asg_id, rownum as row_num
2402                            from (select /*+ ORDERED use_nl(paa,paf,emp,pai_payroll)
2403                                             use_index(pai_person,pay_action_information_n2)
2404                                             use_index(pai,pay_action_information_n2) */
2405                                         paf.person_id, max(paa.assignment_action_id) as asg_id ';
2406         l_from   := 'from   pay_assignment_actions paa,
2407                             per_all_assignments_f  paf,
2408                             pay_action_information emp,
2409                             pay_action_information pai_payroll ';
2410         l_where  := 'where  paa.payroll_action_id = ' || l_payroll_action_id || '
2411                      and    paa.action_status = ''C''
2412                      and    paa.assignment_id = paf.assignment_id
2413                      and    emp.action_information_category = ''EMPLOYEE DETAILS''
2414                      and    emp.action_context_id = paa.assignment_action_id
2415                      and    emp.action_context_type = ''AAP''
2416                      and    pai_payroll.action_information_category = ''GB EMPLOYEE DETAILS''
2417                      and    pai_payroll.action_context_id = paa.assignment_action_id
2418                      and    pai_payroll.action_context_type = ''AAP'' ';
2419         if l_assignment_action_id is not null
2420         then
2421             l_where :=  l_where || 'and   paa.assignment_action_id = ' || l_assignment_action_id ;
2422         end if;
2423 
2424         if l_person_type is not null
2425         then
2426             l_from := l_from || ' ,per_all_people_f pap
2427                                   ,per_person_types ppt ';
2428             l_where := l_where || 'and    pap.person_id = paf.person_id
2429                                    and    pap.person_type_id = ppt.person_type_id
2430                                    and    ppt.system_person_type = ''EX_EMP'' ';
2431         end if;
2432 
2433         if l_organization_id is not null
2434         then
2435             l_where := l_where || ' and   emp.action_information2 = ' || l_organization_id ;
2436         end if;
2437 
2438         if l_location_code is not null
2439         then
2440             l_where := l_where || ' and   nvl(emp.action_information30,''0'')= ''' || l_location_code || ''' ' ;
2441         end if;
2442 
2443         if l_org_hierarchy is not null
2444         then
2445             l_where := l_where || ' and   emp.action_information2 in(select organization_id_child
2446                                                                      from   per_org_structure_elements
2447                                                                      where  business_group_id = ' || l_org_hierarchy ||
2448                                                                    ' union
2449                                                                      select ' || l_org_hierarchy  || ' from dual)';
2450         end if;
2451 
2452         if l_assignment_set_id is not null
2453         then
2454             l_from := l_from  || ',hr_assignment_sets has
2455                                   ,hr_assignment_set_amendments hasa ';
2456             l_where := l_where ||
2457                         ' and    has.assignment_set_id  = ' || l_assignment_set_id ||
2458                         ' and    has.assignment_set_id = hasa.assignment_set_id(+)
2459                           and    ((    has.payroll_id is null
2460                                    and hasa.include_or_exclude = ''I''
2461                                    and hasa.assignment_id = paa.assignment_id
2462                                   )
2463                                   OR
2464                                  (     has.payroll_id is not null
2465                                    and has.payroll_id  = pai_payroll.ACTION_INFORMATION5
2466                                    and nvl(hasa.include_or_exclude, ''I'') = ''I''
2467                                    and nvl(hasa.assignment_id, paa.assignment_id) = paa.assignment_id
2468                                 )) ';
2469         end if;
2470 
2471         l_group  := ' group by paf.person_id, pai_payroll.action_information13 ';
2472 
2473         if l_sort_order1 is not null
2474         then
2475             if l_sort_order1 = 'NAME'
2476             then
2477                 l_order := ' ORDER BY emp.action_information1';
2478                 l_select := l_select || ',emp.action_information1 ';
2479                 l_group  := l_group || ',emp.action_information1 ';
2480             elsif l_sort_order1 = 'NUMBER'
2481             then
2482                 l_order := ' ORDER BY emp.action_information10';
2483                 l_select := l_select || ',emp.action_information10 ';
2484                 l_group  := l_group || ',emp.action_information10 ';
2485             end if;
2486         else -- sort order 1 is null
2487             if l_sort_order2 is not null
2488             then
2489                 if l_sort_order2 = 'NAME'
2490                 then
2491                     l_order := ' ORDER BY emp.action_information1';
2492                     l_select := l_select || ',emp.action_information1 ';
2493                     l_group  := l_group || ',emp.action_information1 ';
2494                 elsif l_sort_order2 = 'NUMBER'
2495                 then
2496                     l_order := ' ORDER BY emp.action_information10';
2497                     l_select := l_select || ',emp.action_information10 ';
2498                     l_group  := l_group || ',emp.action_information10 ';
2499                 end if;
2500             else -- sort order 2 is also null!
2501                 l_order := ' ORDER BY emp.action_information1';
2502                 l_select := l_select || ',emp.action_information1 ';
2503                 l_group  := l_group || ',emp.action_information1 ';
2504             end if;
2505         end if;
2506 
2507         l_start := ((p_chunk_number * p_chunk_size) - p_chunk_size) + 1;
2508         l_end   := (p_chunk_number * p_chunk_size);
2509         l_order := l_order || ')) where row_num between ' || l_start || ' and ' || l_end;
2510         /****************************************************************************/
2511         l_sql :=  l_select || l_from || l_where || l_group || l_order;
2512 
2513         open l_ret_ref_cursor
2514         for l_sql;
2515 
2516         return l_ret_ref_cursor;
2517    --
2518    end rep_assignment_actions;
2519 --------------------------------------------------------------------------------------------
2520    function fetch_ws2_ref_cursor (p_assignment_action_id Number,
2521                                   p_record_num out nocopy NUmber) return ref_cursor_typ
2522    is
2523         -- per_gb_xfdftableType is explicitly created type
2524         -- only modification needed is it could be of type blob
2525         -- i tried thta but could not access the blob valus in java routine.
2526         -- can be sorted later
2527         l_xfdf_str_tab per_gb_xfdftableType := per_gb_xfdftableType( );
2528         l_xfdf_str varchar2(32000);
2529         l_ret_ref_cursor ref_cursor_typ;
2530         l_offset integer;
2531         l_varchar_buffer varchar2(32000);
2532         l_raw_buffer raw(32000);
2533         l_buffer_len number:= 32000;
2534         l_chunk_len number;
2535         l_car_max_price number;
2536 
2537         cursor csr_engine_discount(p_size number,
2538                                    p_date date) is
2539         select to_number(i.value)
2540         from   pay_user_tables t,
2541                pay_user_rows_f r,
2542                pay_user_columns c,
2543                pay_user_column_instances_f i
2544         where  t.user_table_name = 'GB_CC_SCALE'
2545         and    t.user_table_id = r.user_table_id
2546         and    t.user_table_id = c.user_table_id
2547         and    c.user_column_name = 'BEFORE_JAN_1_1998'
2548         and    i.user_row_id = r.user_row_id
2549         and    i.user_column_id = c.user_column_id
2550         and    p_size between to_number(r.row_low_range_or_name) and to_number(r.row_high_range)
2551         and    p_date between r.effective_start_date and r.effective_end_date
2552         and    p_date between i.effective_start_date and i.effective_end_date;
2553 
2554         cursor csr_context_id (p_pactid    NUMBER,
2555                                p_person_id NUMBER,
2556                                p_emp_ref   VARCHAR2,
2557                                p_emp_name  VARCHAR2,
2558                                p_category  VARCHAR2)
2559         is
2560         select /*+ ORDERED use_nl(ppa, paa, pai_comp, pai_person, pai_car)
2561                            use_index(pai_comp,pay_action_information_n2)
2562                            use_index(pai_person,pay_action_information_n2)
2563                            use_index(pai_car,pay_action_information_n2) */
2564                pai_car.action_context_id
2565         from   pay_payroll_actions ppa,
2566                pay_assignment_actions paa,
2567                pay_action_information pai_comp,
2568                pay_action_information pai_person,
2569                pay_action_information pai_car
2570         where  ppa.payroll_action_id = p_pactid
2571         and    paa.payroll_action_id = ppa.payroll_action_id
2572         and    pai_comp.action_context_id = paa.assignment_action_id
2573         and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
2574         and    pai_comp.action_context_type = 'AAP'
2575         and    pai_person.action_context_id = paa.assignment_action_id
2576         and    pai_person.action_information_category = 'ADDRESS DETAILS'
2577         and    pai_person.action_context_type = 'AAP'
2578         and    pai_person.action_information14 = 'Employee Address'
2579         and    pai_person.action_information1 = to_char(p_person_id)
2580         and    pai_comp.action_information6 = p_emp_ref
2581         and    pai_comp.action_information7 = p_emp_name
2582         and    pai_car.action_context_id = paa.assignment_action_id
2583         and    pai_car.action_information_category = p_category
2584         and    pai_car.action_context_type = 'AAP'
2585         group by pai_car.action_context_id;
2586 
2587         cursor csr_car_entries (p_context_id Number)
2588         is
2589         select pai_emp.action_information3 ben_start,
2590                pai_emp.action_information4 ben_end,
2591                decode(months_between(
2592                 fnd_date.canonical_to_date(pai_emp.action_information4)+1,
2593                 fnd_date.canonical_to_date(pai_emp.action_information3)),12,'Y','N') FULL_YR_FLAG,
2594                -- pai_emp.ACTION_INFORMATION5,
2595                pai_emp.action_information6 make,
2596                pai_emp.action_information7 model,
2597                pai_emp.action_information8 date_registered,
2598                substr(pai_emp.action_information8,9,2) || '/' ||
2599                substr(pai_emp.action_information8,6,2) || '/' ||
2600                substr(pai_emp.action_information8,1,4) f_dreg,
2601                pai_emp.action_information13 CO2,
2602                substr(pai_emp.action_information3,9,2) || '/' ||
2603                substr(pai_emp.action_information3,6,2) || '/' ||
2604                substr(pai_emp.action_information3,1,4) f_start,
2605                substr(pai_emp.action_information4,9,2) || '/' ||
2606                substr(pai_emp.action_information4,6,2) || '/' ||
2607                substr(pai_emp.action_information4,1,4) f_end,
2608                to_char(to_number(nvl(pai_emp.action_information9,0)),'FM999,999,990.00') f_lprice,
2609                to_char(to_number(nvl(pai_emp.action_information10,0)),'FM999,999,990.00') f_cc,
2610                to_char(to_number(nvl(pai_emp.action_information11,0)),'FM999,999,990.00') f_fcc,
2611                decode( pai_emp.action_information12,'0',null,PAY_GB_P11D_MAGTAPE.get_description(
2612                      pai_emp.action_information12,'GB_FUEL_TYPE',pai_emp.action_information4)) f_fuel,
2613                -- DECODE(pai_emp.action_information13, NULL, 'On', 'Off') f_nfig,
2614                to_char(to_number(nvl(pai_emp.action_information16,0)),'FM999,999,990.00') f_oprice,
2615                to_char(to_number(nvl(pai_emp.action_information9,0) +nvl(pai_emp.action_information16,0)),
2616                       'FM999,999,990.00') TOTAL_INIT_PRICE,
2617                to_char(to_number(nvl(pai_emp.action_information17,0)),'FM999,999,990.00') f_aprice,
2618                to_char(to_number(nvl(pai_emp.action_information9,0) + nvl(pai_emp.action_information16,0) +
2619                       nvl(pai_emp.action_information17,0)),'FM999,999,990.00') TOTAL_PRICE,
2620                to_char(to_number(nvl(pai_emp.action_information18,0)),'FM999,999,990.00') f_cost,
2621                to_char(to_number(nvl(pai_emp.action_information9,0) + nvl(pai_emp.action_information16,0) +
2622                       nvl(pai_emp.action_information17,0) + nvl(pai_emp.action_information18,0)),
2623                       'FM999,999,990.00') FINAL_PRICE,
2624                to_char(to_number(nvl(pai_emp.action_information19,0)),'FM999,999,990.00') f_amg,
2625                pai_emp.action_information20 f_esize,
2626                to_char(to_number(nvl(pai_emp.action_information21,0)),'FM999,999,990.00') benefit_charge,
2627                to_char(to_number(nvl(pai_emp.action_information22,0)),'FM999,999,990') unavailable,
2628                to_char(to_number(nvl(pai_emp.action_information23,0)),'FM999,999,990.00') unavailable_value,
2629                to_char(to_number(nvl(pai_emp.action_information21,0) - nvl(pai_emp.action_information26,0) -
2630                       nvl(pai_emp.action_information27,0) - nvl(pai_emp.action_information23,0)),
2631                       'FM999,999,990.00') BENEFIT_AFTER_UNAVAIL,
2632                nvl(pai_emp.action_information24,'N') FUEL_BENEFIT,
2633                to_char(to_number(nvl(pai_emp.action_information25,0)),'FM999,999,990') BENEFIT_PERCENT,
2634                to_char(to_number(nvl(pai_emp.action_information26,0)),'FM999,999,990.00') STD_DISC,
2635                to_char(to_number(decode(pai_emp.action_information27,0,null,pai_emp.action_information27))
2636                       ,'FM999,999,990.00') ADD_DISC,
2637                to_char(to_number(decode(nvl(pai_emp.action_information27,0) +
2638                       nvl(pai_emp.action_information26,0),0,null, nvl(pai_emp.action_information27,0) +
2639                       nvl(pai_emp.action_information26,0))),'FM999,999,990.00') FULL_DISC,
2640                to_char(to_number(pai_emp.action_information28),'FM999,999,990.00') FUEL_SCALE,
2641                nvl(pai_emp.action_information21,0) ben_charge,
2642                nvl(pai_emp.action_information26,0) stand_disc,
2643                nvl(pai_emp.action_information27,0) additional_disc
2644         from   pay_action_information pai_emp
2645         where  pai_emp.action_information_category = 'CAR AND CAR FUEL'
2646         and    pai_emp.action_context_id = p_context_id
2647         and    pai_emp.action_context_type = 'AAP';
2648 
2649         cursor csr_car_entries_0304 (p_context_id Number)
2650         is
2651         select pai_emp.action_information3 ben_start,
2652                pai_emp.action_information4 ben_end,
2653                decode(
2654                   months_between(
2655                     fnd_date.canonical_to_date(pai_emp.action_information4)+1,
2656                     fnd_date.canonical_to_date(pai_emp.action_information3)),12,'Y','N') FULL_YR_FLAG,
2657                   --pai_emp.ACTION_INFORMATION5 co2,
2658                pai_emp.action_information6 make,
2659                pai_emp.action_information7 model,
2660                pai_emp.action_information8 date_registered,
2661                substr(pai_emp.action_information8,9,2) || ' ' ||
2662                substr(pai_emp.action_information8,6,2) || ' ' ||
2663                substr(pai_emp.action_information8,1,4) f_dreg,
2664                pai_emp.action_information13 co2,
2665                substr(pai_emp.action_information3,9,2) || ' ' ||
2666                substr(pai_emp.action_information3,6,2) || ' ' ||
2667                substr(pai_emp.action_information3,1,4) f_start,
2668                substr(pai_emp.action_information4,9,2) || ' ' ||
2669                substr(pai_emp.action_information4,6,2) || ' ' ||
2670                substr(pai_emp.action_information4,1,4) f_end,
2671                to_char(to_number(nvl(pai_emp.action_information9,0)),'FM999,999,990.00') f_lprice,
2672                to_char(to_number(nvl(pai_emp.action_information10,0)),'FM999,999,990.00') f_cc,
2673                to_char(to_number(nvl(pai_emp.action_information11,0)),'FM999,999,990.00') f_fcc,
2674                decode(pai_emp.action_information12,'0',null,PAY_GB_P11D_MAGTAPE.get_description(
2675                       pai_emp.action_information12,'GB_FUEL_TYPE',pai_emp.action_information4)) f_fuel,
2676                to_char(to_number(nvl(pai_emp.action_information15,0)),'FM999,999,990.00') f_oprice,
2677                to_char(to_number(nvl(pai_emp.action_information9,0) +
2678                       nvl(pai_emp.action_information15,0)),'FM999,999,990.00') TOTAL_INIT_PRICE,
2679                to_char(to_number(nvl(pai_emp.action_information16,0)),'FM999,999,990.00') f_cost,
2680                to_char(least(l_car_max_price,(to_number(nvl(pai_emp.action_information9,0) +
2681                        nvl(pai_emp.action_information15,0) -
2682                        nvl(pai_emp.action_information16,0)))),'FM999,999,990.00') FINAL_PRICE,
2683                to_char(to_number(nvl(pai_emp.action_information17,0)),'FM999,999,990.00') f_amg,
2684                pai_emp.action_information18 f_esize,
2685                to_char(to_number(nvl(pai_emp.action_information19,0)),'FM999,999,990') car_benefit_year,
2686                to_char(to_number(nvl(pai_emp.action_information20,0)),'FM999,999,990') unavailable,
2687                to_char(to_number(nvl(pai_emp.action_information21,0)),'FM999,999,990') unavailable_value,
2688                to_char(to_number(nvl(pai_emp.action_information19,0) -
2689                       nvl(pai_emp.action_information21,0)),'FM999,999,990.00') CAR_BENEFIT_AVAILABLE,
2690                to_char(to_number(nvl(pai_emp.action_information22,0)),'FM999,999,990') BENEFIT_PERCENT,
2691                to_char(to_number(nvl(pai_emp.action_information23,0)),'FM999,999,990') STD_DISC,
2692                to_char(to_number(nvl(pai_emp.action_information24,0)),'FM999,999,990') ROUND_NORMAL_CO2,
2693 	       -- Added substring function to get fuel benefit value from action_information25 (P11D 07/08 changes)
2694                nvl(substr(pai_emp.action_information25,1,instr(pai_emp.action_information25,':')-1),'N') FUEL_BENEFIT,
2695                to_char(to_number(pai_emp.action_information29),'FM999,999,990') FUEL_BENEFIT_YEAR,
2696                to_char(to_number(nvl(pai_emp.action_information23,0) +
2697                       nvl(pai_emp.action_information24,0)),'FM999,999,990') FULL_DISC,
2698                to_char(to_number(nvl(pai_emp.action_information22,0) -
2699                       nvl(pai_emp.action_information23,0) -
2700                       nvl(pai_emp.action_information24,0)), 'FM999,999,990') TOTAL_BENIFIT,
2701                to_char(to_number(nvl(pai_emp.action_information22,0) -
2702                       nvl(pai_emp.action_information23,0)),   'FM999,999,990') TOTAL_BENIFIT_2,
2703                decode (pai_emp.action_information26,null,null,
2704                       decode ( pai_emp.action_information27,'Y',null,
2705                       substr(pai_emp.action_information26,9,2) || ' ' ||
2706                       substr(pai_emp.action_information26,6,2) || ' ' ||
2707                       substr(pai_emp.action_information26,1,4))) f_withdraw,
2708                to_char(to_number(nvl(pai_emp.action_information28,0))) additional_days,
2709                decode (pai_emp.action_information26,null,to_char(to_number(nvl(pai_emp.action_information20,0))),
2710                       to_char(to_number(nvl(pai_emp.action_information20,0) +
2711                       nvl(pai_emp.action_information28,0)) ) ) total_days ,
2712                to_char(to_number(nvl(pai_emp.action_information30,0)),'FM999,999,990') fuel_unavailable
2713         from   pay_action_information pai_emp
2714         where  pai_emp.action_information_category = 'CAR AND CAR FUEL 2003_04'
2715         and    pai_emp.action_context_id = p_context_id
2716         and    pai_emp.action_context_type = 'AAP';
2717 
2718         -- car_rec csr_car_entries%rowtype;
2719         l_BEN_ST_DATE  varchar2(20);
2720         l_BEN_ED_DATE  varchar2(20);
2721         l_car_count    number;
2722         l_ONLY_CAR_FLAG varchar2(5);
2723         l_FUEL_FLAG varchar2(5);
2724         l_fuel_scale varchar2(20);
2725         l_FUEL_BENEFIT_YEAR VARCHAR2 (20);
2726         l_CAR_NUMBERS  number;
2727         l_MOD_CO2     number;
2728         l_PERCENT_1  varchar2(20);
2729         l_BEN_1      varchar2(20);
2730         l_PERCENT_2  varchar2(20);
2731         l_BEN_2 varchar2(20);
2732         l_PERCENT_3 varchar2(20);
2733         l_BEN_3 varchar2(20);
2734         l_PERCENT_4 varchar2(20);
2735         l_BEN_4 varchar2(20);
2736         l_BEN_5 varchar2(20);
2737         l_STD_DISC_1 varchar2(20);
2738         l_STD_DISC_2 varchar2(20);
2739         l_STD_DISC_3 varchar2(20);
2740         l_STD_DISC_4 varchar2(20);
2741         l_STD_DISC_5 varchar2(20);
2742         l_full_DISC varchar2(20);
2743         l_EXTRA_CO2  number;
2744         l_NORMAL_CO2  number;
2745         l_ROUND_NORMAL_CO2  number;
2746         l_CAR_BENEFIT_1  Number;
2747         l_CAR_BENEFIT_2  Number;
2748         l_CAR_BENEFIT_3  Number;
2749         -- ,4,5 can be varchar2 as these are not calc and are just read from benefit
2750         --charge
2751         l_CAR_BENEFIT_4  varchar2(20);
2752         l_CAR_BENEFIT_5  varchar2(20);
2753         l_emp_ref_no varchar2(150);
2754         l_employer_name varchar2(150);
2755         l_full_name varchar2(150);
2756         l_national_ins_no varchar2(150);
2757         l_employee_number varchar2(150);
2758         l_pactid number;
2759         l_person_id number;
2760         l_loop_count Number;
2761         l_esize varchar2(20);
2762         l_UNAVIALABLE_VAL_2 varchar2(20);
2763         l_rep_run varchar2(10);
2764         l_add_days varchar2(10);
2765         l_tot_days varchar2(10);
2766         l_unavailble_days varchar2(10);
2767    begin
2768         get_employer_details(p_assignment_action_id,
2769                              l_emp_ref_no,
2770                              l_employer_name);
2771         get_employee_details(p_assignment_action_id,
2772                              l_full_name,
2773                              l_national_ins_no,
2774                              l_employee_number);
2775         l_pactid := get_pactid(p_assignment_action_id);
2776         l_person_id := get_person_id (p_assignment_action_id );
2777         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
2778          p_payroll_action_id           => l_pactid,
2779          p_token_name                  => 'Rep_Run',
2780          p_token_value                 => l_rep_run);
2781 
2782         select to_number(global_value)
2783         into  l_car_max_price
2784         from  ff_globals_f
2785         where global_name = 'NI_CAR_MAX_PRICE'
2786         and   to_date('05-04-' || l_rep_run,'DD-MM-YYYY') between effective_start_date and effective_end_date;
2787 
2788         l_loop_count := 0;
2789         if l_rep_run = '2003'
2790         then
2791             for context_rec in csr_context_id(l_pactid,
2792                                               l_person_id,
2793                                               l_emp_ref_no,
2794                                               l_employer_name,
2795                                               'CAR AND CAR FUEL') loop
2796             for car_rec in  csr_car_entries(context_rec.action_context_id)
2797             loop
2798                 l_loop_count := l_loop_count+1;
2799                 -- Initialising the vars to null;
2800                 l_BEN_ST_DATE  := null;
2801                 l_BEN_ED_DATE  := null;
2802                 l_car_count    := null;
2803                 l_ONLY_CAR_FLAG :=null;
2804                 l_FUEL_FLAG :=null;
2805                 l_CAR_NUMBERS  := null;
2806                 l_MOD_CO2     := null;
2807                 l_PERCENT_1  := null;
2808                 l_BEN_1      := null;
2809                 l_PERCENT_2  := null;
2810                 l_BEN_2 := null;
2811                 l_PERCENT_3 := null;
2812                 l_BEN_3 := null;
2813                 l_PERCENT_4 := null;
2814                 l_BEN_4 := null;
2815                 l_BEN_5 := null;
2816                 l_STD_DISC_1 := null;
2817                 l_STD_DISC_2 := null;
2818                 l_STD_DISC_3 := null;
2819                 l_STD_DISC_4 := null;
2820                 l_STD_DISC_5 := null;
2821                 l_full_DISC  := null;
2822                 l_EXTRA_CO2  := null;
2823                 l_NORMAL_CO2  := null;
2824                 l_ROUND_NORMAL_CO2  := null;
2825                 l_CAR_BENEFIT_1  := null;
2826                 l_CAR_BENEFIT_2  := null;
2827                 l_CAR_BENEFIT_3  := null;
2828                 l_CAR_BENEFIT_4  := null;
2829                 l_CAR_BENEFIT_5  := null;
2830                 l_full_DISC := car_rec.FULL_DISC;
2831                 if car_rec.FULL_YR_FLAG = 'Y'
2832                 then
2833                     l_BEN_ST_DATE := null;
2834                     l_BEN_ED_DATE := null;
2835                 else
2836                     l_BEN_ST_DATE := car_rec.f_start;
2837                     l_BEN_ED_DATE := car_rec.f_end;
2838                 end if;
2839                 hr_utility.trace('A4');
2840                 select action_information30
2841                 into   l_car_count
2842                 from   pay_action_information pai_emp
2843                 where  pai_emp.action_context_id = p_assignment_action_id
2844                 and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTA';
2845 
2846                 hr_utility.trace('A5');
2847                 if l_car_count = 1
2848                 then
2849                     l_ONLY_CAR_FLAG := 'Y';
2850                 else
2851                     l_ONLY_CAR_FLAG := 'N';
2852                     l_CAR_NUMBERS := l_car_count;
2853                 end if   ;
2854                 hr_utility.trace('A6');
2855                 hr_utility.trace('date_registered ' ||car_rec.date_registered);
2856                 -- calculating benefit charge section
2857                 if fnd_date.canonical_to_date( car_rec.date_registered)
2858                    >= to_date('01-01-1998','dd-mm-yyyy') and car_rec.CO2 is not null
2859                 then
2860                     hr_utility.trace('A');
2861                     l_MOD_CO2 := floor(car_rec.CO2/5) * 5;
2862                     hr_utility.trace('b');
2863                     if (car_rec.f_fuel = 'B' or car_rec.f_fuel = 'C' or
2864                         car_rec.f_fuel = 'H' or car_rec.f_fuel = 'L' or
2865                         car_rec.f_fuel = 'P')
2866                     then
2867                         hr_utility.trace('c');
2868                         l_PERCENT_1 := car_rec.BENEFIT_PERCENT;
2869                         l_BEN_1 := car_rec.benefit_charge;
2870                         hr_utility.trace('d');
2871                     elsif ( car_rec.f_fuel ='D' )
2872                     then
2873                         hr_utility.trace('e');
2874                         l_PERCENT_2 := car_rec.BENEFIT_PERCENT;
2875                         l_BEN_2 := car_rec.benefit_charge;
2876                     end if;
2877 
2878                     hr_utility.trace('f');
2879                     if  car_rec.f_fuel  = 'H'
2880                     then
2881                         l_STD_DISC_1   := car_rec.STD_DISC;
2882                     elsif ( car_rec.f_fuel = 'B' or car_rec.f_fuel = 'C')
2883                     then
2884                         l_STD_DISC_2   := car_rec.STD_DISC;
2885                     end if;
2886                     hr_utility.trace('g');
2887                     if l_MOD_CO2 <= 145
2888                     then
2889                         l_EXTRA_CO2 := 165 -l_MOD_CO2;
2890                         l_NORMAL_CO2 := l_EXTRA_CO2/20;
2891                         l_ROUND_NORMAL_CO2 := floor(l_NORMAL_CO2);
2892                     end if;
2893                     hr_utility.trace('h');
2894                     l_CAR_BENEFIT_1   := car_rec.ben_charge - car_rec.stand_disc - car_rec.additional_disc;
2895                 elsif fnd_date.canonical_to_date( car_rec.date_registered)
2896                       >= to_date('01-01-1998','dd-mm-yyyy') and car_rec.co2 is null
2897                 then
2898                     hr_utility.trace('i');
2899                     if (car_rec.f_fuel = 'B' or car_rec.f_fuel = 'C' or
2900                         car_rec.f_fuel = 'H' or car_rec.f_fuel = 'L' or
2901                         car_rec.f_fuel = 'P' )
2902                     then
2903                         l_PERCENT_3 := car_rec.BENEFIT_PERCENT;
2904                         l_BEN_3 := car_rec.benefit_charge;
2905                     elsif car_rec.f_fuel ='D'
2906 			        then
2907                         l_PERCENT_4 := car_rec.BENEFIT_PERCENT;
2908                         l_BEN_4 := car_rec.benefit_charge;
2909                     elsif car_rec.f_fuel ='E'
2910 			        then
2911                         l_BEN_5 := car_rec.benefit_charge;
2912                     end if;
2913 
2914 			        if  car_rec.f_fuel  = 'H'
2915 			        then
2916                         l_STD_DISC_4   := car_rec.STD_DISC;
2917                     elsif ( car_rec.f_fuel = 'B' or car_rec.f_fuel = 'C')
2918 		       	        then
2919                         l_STD_DISC_5   := car_rec.STD_DISC;
2920                     elsif car_rec.f_fuel = 'E'
2921 		       	        then
2922                         l_STD_DISC_3   := car_rec.STD_DISC;
2923                     end if;
2924                     hr_utility.trace('j');
2925                     l_CAR_BENEFIT_2  := car_rec.ben_charge - car_rec.stand_disc      ;
2926                     l_full_DISC := null;
2927                elsif fnd_date.canonical_to_date( car_rec.date_registered)
2928                      < to_date('01-01-1998','dd-mm-yyyy')
2929 		       then
2930                    hr_utility.trace('K');
2931                    -- hr_utility.trace('car_rec.benefit_charge '|| car_rec.benefit_charge);
2932                    l_full_disc := null;
2933                    if car_rec.f_esize <= 1400
2934 			       then
2935                        l_CAR_BENEFIT_3 :=  car_rec.benefit_charge;
2936                    elsif car_rec.f_esize <= 2000
2937                    then
2938 		       	    l_CAR_BENEFIT_4 :=  car_rec.benefit_charge;
2939                    elsif car_rec.f_esize > 2000
2940 		       	then
2941                        l_CAR_BENEFIT_5 :=  car_rec.benefit_charge;
2942                    end if;
2943                end if;
2944                hr_utility.trace('k');
2945                -- fuel benefit
2946                l_esize := null;
2947                l_UNAVIALABLE_VAL_2 := null;
2948                if car_rec.FUEL_BENEFIT = 'Y'
2949                then
2950 	               l_esize := car_rec.f_esize;
2951                    l_UNAVIALABLE_VAL_2 := car_rec.unavailable_value;
2952                    if car_rec.f_fuel = 'P'
2953                    then
2954 			           l_FUEL_FLAG := 'P';
2955                    else
2956                        l_FUEL_FLAG := 'D';
2957                    end if;
2958                end if;
2959                hr_utility.trace('L');
2960                l_xfdf_str_tab.extend;
2961                l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
2962                    <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
2963                    <fields> ' ||
2964                    '<field name="'||'EMPLOYERS_NAME'||'"><value>'||replace(l_employer_name,'&','&')       ||'</value></field>'||
2965                    '<field name="'||'FULL_NAME'||'"><value>'||l_full_name||'</value></field>'||
2966                    '<field name="'||'EMPLOYERS_REF_NO'||'"><value>'||l_emp_ref_no||'</value></field>'||
2967                    '<field name="'||'EMPLOYEE_NUMBER'||'"><value>'||l_employee_number||'</value></field>'||
2968                    '<field name="'||'NATIONAL_INS_NO'||'"><value>'||l_national_ins_no||'</value></field>'||
2969                    '<field name="'||'MAKE'||'"><value>'||car_rec.make||'</value></field>'||
2970                    '<field name="'||'MODEL'||'"><value>'||car_rec.model||'</value></field>'||
2971                    '<field name="'||'DATE_FIRST_REG'||'"><value>'||car_rec.f_dreg||'</value></field>'||
2972                    '<field name="'||'CO2'||'"><value>'||car_rec.CO2||'</value></field>'||
2973                    '<field name="'||'FULL_YR_FLAG'||'"><value>'||car_rec.FULL_YR_FLAG||'</value></field>'||
2974                    '<field name="'||'BEN_ST_DATE'||'"><value>'||l_BEN_ST_DATE||'</value></field>'||
2975                    '<field name="'||'BEN_ED_DATE'||'"><value>'||l_BEN_ED_DATE||'</value></field>'||
2976                    '<field name="'||'UNAVAILABLE'||'"><value>'||car_rec.unavailable||'</value></field>'||
2977                    '<field name="'||'ONLY_CAR_FLAG'||'"><value>'||l_ONLY_CAR_FLAG||'</value></field>'||
2978                    '<field name="'||'CAR_NUMBERS'||'"><value>'||l_CAR_NUMBERS||'</value></field>'||
2979                    '<field name="'||'LIST_PRICE'||'"><value>'||car_rec.f_lprice||'</value></field>'||
2980                    '<field name="'||'OPTIONAL_EXTRAS'||'"><value>'||car_rec.f_oprice||'</value></field>'||
2981                    '<field name="'||'TOTAL_INIT_PRICE'||'"><value>'||car_rec.TOTAL_INIT_PRICE||'</value></field>'||
2982                    '<field name="'||'EXTRAS_LATER'||'"><value>'||car_rec.f_aprice||'</value></field>'||
2983                    '<field name="'||'TOTAL_PRICE'||'"><value>'||car_rec.TOTAL_PRICE||'</value></field>'||
2984                    '<field name="'||'CONTRIBUTIONS'||'"><value>'||car_rec.f_cost||'</value></field>'||
2985                    '<field name="'||'FINAL_PRICE'||'"><value>'||car_rec.FINAL_PRICE||'</value></field>'||
2986                    '<field name="'||'FINAL_PRICE_DUP'||'"><value>'||car_rec.FINAL_PRICE||'</value></field>'||
2987                    '<field name="'||'FUEL'||'"><value>'||car_rec.f_fuel||'</value></field>'||
2988                    '<field name="'||'MOD_CO2'||'"><value>'||l_MOD_CO2||'</value></field>'||
2989                    '<field name="'||'PERCENT_1'||'"><value>'||l_PERCENT_1||'</value></field>'||
2990                    '<field name="'||'BEN_1'||'"><value>'||l_BEN_1||'</value></field>'||
2991                    '<field name="'||'BEN_2'||'"><value>'||l_BEN_2||'</value></field>'||
2992                    '<field name="'||'PERCENT_2'||'"><value>'||l_PERCENT_2||'</value></field>'||
2993                    '<field name="'||'STD_DISC_1'||'"><value>'||l_STD_DISC_1||'</value></field>'||
2994                    '<field name="'||'STD_DISC_2'||'"><value>'||l_STD_DISC_2||'</value></field>'||
2995                    '<field name="'||'EXTRA_CO2'||'"><value>'||l_EXTRA_CO2||'</value></field>'||
2996                    '<field name="'||'NORMAL_CO2'||'"><value>'||l_NORMAL_CO2||'</value></field>'||
2997                    '<field name="'||'ROUND_NORMAL_CO2'||'"><value>'||l_ROUND_NORMAL_CO2||'</value></field>' ||
2998                    '<field name="'||'ADDITIONAL_DISC'||'"><value>'||car_rec.ADD_DISC||'</value></field>'||
2999                    '<field name="'||'FULL_DISCOUNT'||'"><value>'||l_FULL_DISC||'</value></field>'||
3000                    '<field name="'||'CAR_BENEFIT_1'||'"><value>'||to_char(to_number(l_CAR_BENEFIT_1),'FM999,999,990.00')||'</value></field>'||
3001                    '<field name="'||'PERCENT_3'||'"><value>'||l_PERCENT_3||'</value></field>'||
3002                    '<field name="'||'PERCENT_4'||'"><value>'||l_PERCENT_4||'</value></field>'||
3003                    '<field name="'||'BEN_3'||'"><value>'||l_BEN_3||'</value></field>'||
3004                    '<field name="'||'BEN_4'||'"><value>'||l_BEN_4||'</value></field>'||
3005                    '<field name="'||'BEN_5'||'"><value>'||l_BEN_5||'</value></field>'||
3006                    '<field name="'||'STD_DISC_3'||'"><value>'||l_STD_DISC_3||'</value></field>'||
3007                    '<field name="'||'STD_DISC_4'||'"><value>'||l_STD_DISC_4||'</value></field>'||
3008                    '<field name="'||'STD_DISC_5'||'"><value>'||l_STD_DISC_5||'</value></field>'||
3009                    '<field name="'||'CAR_BENEFIT_2'||'"><value>'||to_char(to_number(l_CAR_BENEFIT_2),'FM999,999,990.00')||'</value></field>'||
3010                    '<field name="'||'CAR_BENEFIT_3'||'"><value>'||l_CAR_BENEFIT_3 ||'</value></field>'||
3011                    '<field name="'||'CAR_BENEFIT_4'||'"><value>'||l_CAR_BENEFIT_4 ||'</value></field>'||
3012                    '<field name="'||'CAR_BENEFIT_5'||'"><value>'||l_CAR_BENEFIT_5 ||'</value></field>'||
3013                    '<field name="'||'UNAVAILABLE_VAL_1'||'"><value>'||car_rec.unavailable_value||'</value></field>'||
3014                    '<field name="'||'BENEFIT_AFTER_UNAVAIL'||'"><value>'||car_rec.BENEFIT_AFTER_UNAVAIL||'</value></field>'||
3015                    '<field name="'||'PRIVATE_USE_PAYMENT'||'"><value>'||car_rec.f_amg||'</value></field>'||
3016                    '<field name="'||'CASH_EQUIVALENT_CAR'||'"><value>'||car_rec.f_cc||'</value></field>'||
3017                    '<field name="'||'FUEL_FLAG'||'"><value>'||l_FUEL_FLAG||'</value></field>'||
3018                    '<field name="'||'ENGINE_CC'||'"><value>'||l_esize||'</value></field>'||
3019                    '<field name="'||'FUEL_SCALE'||'"><value>'||car_rec.FUEL_SCALE||'</value></field>'||
3020                    '<field name="'||'UNAVIALABLE_VAL_2'||'"><value>'||l_UNAVIALABLE_VAL_2||'</value></field>'||
3021                    '<field name="'||'FUEL_BENEFIT_CHARGE'||'"><value>'||car_rec.f_fcc||'</value></field>'||
3022                    '</fields>  </xfdf>';
3023             end loop;
3024             end loop;
3025             /* change from  l_rep_run = '2004' to l_rep_run > 2003 */
3026         elsif to_number(l_rep_run) < 2007 then
3027             for context_rec in csr_context_id(l_pactid,
3028                                               l_person_id,
3029                                               l_emp_ref_no,
3030                                               l_employer_name,
3031                                               'CAR AND CAR FUEL 2003_04') loop
3032             for car_rec in  csr_car_entries_0304(context_rec.action_context_id)
3033             loop
3034                 l_employee_number := get_assignment_number(context_rec.action_context_id);
3035                 l_loop_count := l_loop_count+1;
3036                 --Initialising the vars to null;
3037                 l_BEN_ST_DATE  := null;
3038                 l_BEN_ED_DATE  := null;
3039                 l_car_count    := null;
3040                 l_ONLY_CAR_FLAG :=null;
3041                 l_FUEL_FLAG :=null;
3042                 l_CAR_NUMBERS  := null;
3043                 l_MOD_CO2     := null;
3044                 l_PERCENT_1  := null;
3045                 l_BEN_1      := null;
3046                 l_PERCENT_2  := null;
3047                 l_BEN_2 := null;
3048                 l_PERCENT_3 := null;
3049                 l_BEN_3 := null;
3050                 l_PERCENT_4 := null;
3051                 l_BEN_4 := null;
3052                 l_BEN_5 := null;
3053                 l_STD_DISC_1 := null;
3054                 l_STD_DISC_2 := null;
3055                 l_STD_DISC_3 := null;
3056                 l_STD_DISC_4 := null;
3057                 l_STD_DISC_5 := null;
3058                 l_full_DISC  := null;
3059                 l_EXTRA_CO2  := null;
3060                 l_NORMAL_CO2  := null;
3061                 l_ROUND_NORMAL_CO2  := null;
3062                 l_CAR_BENEFIT_1  := null;
3063                 l_CAR_BENEFIT_2  := null;
3064                 l_CAR_BENEFIT_3  := null;
3065                 l_CAR_BENEFIT_4  := null;
3066                 l_CAR_BENEFIT_5  := null;
3067                 l_esize          := null;
3068                 l_add_days       := null;
3069                 l_tot_days       := null;
3070                 l_unavailble_days := null;
3071                 l_FUEL_BENEFIT_YEAR := null;
3072                 /*l_full_DISC := car_rec.FULL_DISC;  */
3073                 if car_rec.FULL_YR_FLAG = 'Y'
3074 				then
3075                     l_BEN_ST_DATE := null;
3076                     l_BEN_ED_DATE := null;
3077                 else
3078                     l_BEN_ST_DATE := car_rec.f_start;
3079                     l_BEN_ED_DATE := car_rec.f_end;
3080                 end if;
3081                 -- hr_utility.trace_on(null,'CAR');
3082                 hr_utility.trace('A4');
3083                 select action_information30
3084                 into   l_car_count
3085                 from   pay_action_information pai_emp
3086                 where  pai_emp.action_context_id = p_assignment_action_id
3087                 and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTA';
3088                 hr_utility.trace('A5');
3089                 if l_car_count = 1
3090 				then
3091                     l_ONLY_CAR_FLAG := 'Y';
3092                 else
3093                     l_ONLY_CAR_FLAG := 'N';
3094                     l_CAR_NUMBERS := l_car_count;
3095                 end if   ;
3096                 hr_utility.trace('A6');
3097                 hr_utility.trace('date_registered ' ||car_rec.date_registered);
3098                 -- calculating benefit charge section
3099                 if fnd_date.canonical_to_date( car_rec.date_registered)
3100                    >= to_date('01-01-1998','dd-mm-yyyy') and car_rec.CO2 is not null
3101                 then
3102                     hr_utility.trace('a');
3103                     l_MOD_CO2 := floor(car_rec.CO2/5) * 5;
3104                     hr_utility.trace('b');
3105                     l_PERCENT_1 := car_rec.BENEFIT_PERCENT;
3106                     --l_BEN_1 := car_rec.benefit_charge;
3107                     hr_utility.trace('c');
3108                     l_STD_DISC_1   := car_rec.STD_DISC;
3109                     hr_utility.trace('d');
3110                     if (car_rec.f_fuel = 'B' or car_rec.f_fuel = 'H') -- Bug #4293824
3111                     then
3112 					    if car_rec.CO2 <= 120
3113 						then
3114                              l_EXTRA_CO2 := 145 - car_rec.CO2;
3115                         end if;
3116                     end if;
3117                     l_ROUND_NORMAL_CO2 := car_rec.ROUND_NORMAL_CO2;
3118                     l_full_DISC        := car_rec.FULL_DISC;
3119                     l_CAR_BENEFIT_1    := car_rec.TOTAL_BENIFIT ;
3120                 elsif fnd_date.canonical_to_date( car_rec.date_registered)
3121                       >= to_date('01-01-1998','dd-mm-yyyy') and car_rec.CO2 is null
3122                 then
3123                     hr_utility.trace('e');
3124                    l_PERCENT_2 := car_rec.BENEFIT_PERCENT;
3125                    hr_utility.trace('f');
3126                    l_STD_DISC_2   := car_rec.STD_DISC;
3127                    l_CAR_BENEFIT_2 := car_rec.TOTAL_BENIFIT_2;
3128                 elsif (fnd_date.canonical_to_date( car_rec.date_registered)<  to_date('01-01-1998','dd-mm-yyyy'))
3129 				then
3130                     hr_utility.trace('g');
3131                     -- hr_utility.trace('car_rec.benefit_charge '|| car_rec.benefit_charge);
3132                     l_full_disc := null;
3133                     l_esize := car_rec.f_esize;
3134                     if car_rec.f_esize <= 1400
3135                     then
3136                         l_CAR_BENEFIT_3 :=  15;
3137                     elsif car_rec.f_esize <= 2000
3138                     then
3139                         l_CAR_BENEFIT_3 :=  22;
3140                     elsif car_rec.f_esize > 2000
3141                     then
3142 						l_CAR_BENEFIT_3 :=  32;
3143                     else
3144 					    l_CAR_BENEFIT_3 :=  32;
3145                     end if;
3146                 end if;
3147                 hr_utility.trace('h');
3148                 -- fuel benefit
3149                 if car_rec.FUEL_BENEFIT = 'Y'
3150 				then
3151                     L_FUEL_BENEFIT_YEAR := car_rec.FUEL_BENEFIT_YEAR;
3152                     l_add_days          := car_rec.additional_days;
3153                     l_tot_days        := car_rec.total_days;
3154                     l_unavailble_days   := car_rec.unavailable;
3155                 end if;
3156                 hr_utility.trace('i');
3157                 l_xfdf_str_tab.extend;
3158                 l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
3159                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
3160                     <fields> ' ||
3161                     '<field name="'||'EMPLOYERS_NAME'||'"><value>'||replace(l_employer_name,'&','&')       ||'</value></field>'||
3162                     '<field name="'||'FULL_NAME'||'"><value>'||l_full_name||'</value></field>'||
3163                     '<field name="'||'EMPLOYERS_REF_NO'||'"><value>'||l_emp_ref_no||'</value></field>'||
3164                     '<field name="'||'EMPLOYEE_NUMBER'||'"><value>'||l_employee_number||'</value></field>'||
3165                     -- '<field name="'||'NATIONAL_INS_NO'||'"><value>'||l_national_ins_no||'</value></field>'||
3166                     '<field name="'||'NI_1'||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
3167                     '<field name="'||'NI_2'||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
3168                     '<field name="'||'NI_3'||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
3169                     '<field name="'||'NI_4'||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
3170                     '<field name="'||'NI_5'||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
3171                     '<field name="'||'NI_6'||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
3172                     '<field name="'||'NI_7'||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
3173                     '<field name="'||'NI_8'||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
3174                     '<field name="'||'NI_9'||'"><value>' ||substr(l_national_ins_no,9) || '</value></field>  '   ||
3175                     '<field name="'||'MAKE'||'"><value>'||car_rec.make||'</value></field>'||
3176                     '<field name="'||'MODEL'||'"><value>'||car_rec.model||'</value></field>'||
3177                     '<field name="'||'DATE_FIRST_REG1'||'"><value>'||substr(car_rec.f_dreg,0,2)||'</value></field>'||
3178                     '<field name="'||'DATE_FIRST_REG2'||'"><value>'||substr(car_rec.f_dreg,4,2)||'</value></field>'||
3179                     '<field name="'||'DATE_FIRST_REG3'||'"><value>'||substr(car_rec.f_dreg,7)||'</value></field>'||
3180                     '<field name="'||'ONLY_CAR_FLAG'||'"><value>'||l_ONLY_CAR_FLAG||'</value></field>'||
3181                     --'<field name="'||'CO2'||'"><value>'||car_rec.CO2||'</value></field>'||
3182                     --'<field name="'||'FULL_YR_FLAG'||'"><value>'||car_rec.FULL_YR_FLAG||'</value></field>'||
3183                     '<field name="'||'CAR_NUMBERS'||'"><value>'||l_CAR_NUMBERS||'</value></field>'||
3184                     '<field name="'||'LIST_PRICE'||'"><value>'||car_rec.f_lprice||'</value></field>'||
3185                     '<field name="'||'EXTRAS_LATER'||'"><value>'||car_rec.f_oprice||'</value></field>'||
3186                     '<field name="'||'TOTAL_INIT_PRICE'||'"><value>'||car_rec.TOTAL_INIT_PRICE||'</value></field>'||
3187                     /*'<field name="'||'BEN_ST_DATE'||'"><value>'||l_BEN_ST_DATE||'</value></field>'||
3188                     '<field name="'||'BEN_ED_DATE'||'"><value>'||l_BEN_ED_DATE||'</value></field>'||
3189                     '<field name="'||'UNAVAILABLE'||'"><value>'||car_rec.unavailable||'</value></field>'||*/
3190                     '<field name="'||'CONTRIBUTIONS'||'"><value>'||car_rec.f_cost||'</value></field>'||
3191                     '<field name="'||'FINAL_PRICE'||'"><value>'||car_rec.FINAL_PRICE||'</value></field>'||
3192                     '<field name="'||'CO2'||'"><value>'||car_rec.co2||'</value></field>'||
3193                     '<field name="'||'FUEL'||'"><value>'||car_rec.f_fuel||'</value></field>'||
3194                     '<field name="'||'MOD_CO2'||'"><value>'||l_MOD_CO2||'</value></field>'||
3195                     '<field name="'||'PERCENT_1'||'"><value>'||l_PERCENT_1||'</value></field>'||
3196                     '<field name="'||'STD_DISC_1'||'"><value>'||l_STD_DISC_1||'</value></field>'||
3197                     '<field name="'||'EXTRA_CO2'||'"><value>'||l_EXTRA_CO2||'</value></field>'||
3198                     '<field name="'||'ROUND_NORMAL_CO2'||'"><value>'||l_ROUND_NORMAL_CO2||'</value></field>' ||
3199                     '<field name="'||'FULL_DISCOUNT'||'"><value>'||l_full_DISC||'</value></field>'||
3200                     '<field name="'||'CAR_BENEFIT_1'||'"><value>'||l_CAR_BENEFIT_1||'</value></field>'||
3201                     '<field name="'||'PERCENT_2'||'"><value>'||l_PERCENT_2||'</value></field>'||
3202                     '<field name="'||'STD_DISC_2'||'"><value>'||l_STD_DISC_2||'</value></field>'||
3203                     '<field name="'||'CAR_BENEFIT_2'||'"><value>'||l_CAR_BENEFIT_2||'</value></field>'||
3204                     '<field name="'||'ENGINE_CC'||'"><value>'||l_esize||'</value></field>'||
3205                     '<field name="'||'CAR_BENEFIT_3'||'"><value>'||l_CAR_BENEFIT_3||'</value></field>'||
3206                     '<field name="'||'CAR_BENEFIT_YEAR'||'"><value>'||car_rec.car_benefit_year||'</value></field>'||
3207                    '<field name="'||'BEN_ST_DATE1'||'"><value>'||substr(l_BEN_ST_DATE,0,2)||'</value></field>'||
3208                     '<field name="'||'BEN_ST_DATE2'||'"><value>'||substr(l_BEN_ST_DATE,4,2)||'</value></field>'||
3209                     '<field name="'||'BEN_ST_DATE3'||'"><value>'||substr(l_BEN_ST_DATE,7)||'</value></field>'||
3210                     '<field name="'||'BEN_ED_DATE1'||'"><value>'||substr(l_BEN_ED_DATE,0,2)||'</value></field>'||
3211                     '<field name="'||'BEN_ED_DATE2'||'"><value>'||substr(l_BEN_ED_DATE,4,2)||'</value></field>'||
3212                     '<field name="'||'BEN_ED_DATE3'||'"><value>'||substr(l_BEN_ED_DATE,7)||'</value></field>'||
3213                     '<field name="'||'UNAVAILABLE'||'"><value>'||car_rec.unavailable||'</value></field>'||
3214                     '<field name="'||'UNAVAILABLE_VAL_1'||'"><value>'||car_rec.unavailable_value||'</value></field>'||
3215                     '<field name="'||'CAR_BENEFIT_AVAILABLE'||'"><value>'||car_rec.CAR_BENEFIT_AVAILABLE||'</value></field>'||
3216                     '<field name="'||'PRIVATE_USE_PAYMENT'||'"><value>'||car_rec.f_amg||'</value></field>'||
3217                     '<field name="'||'CASH_EQUIVALENT_CAR'||'"><value>'||car_rec.f_cc||'</value></field>'||
3218                     '<field name="'||'FUEL_BENEFIT_YEAR'||'"><value>'||l_FUEL_BENEFIT_YEAR||'</value></field>'||
3219                     '<field name="'||'UNAVAILABLE_2'||'"><value>'||l_unavailble_days||'</value></field>'||
3220                     '<field name="'||'WITHDRAW_DATE1'||'"><value>'||substr(car_rec.f_withdraw,0,2)||'</value></field>'||
3221                     '<field name="'||'WITHDRAW_DATE2'||'"><value>'||substr(car_rec.f_withdraw,4,2)||'</value></field>'||
3222                     '<field name="'||'WITHDRAW_DATE3'||'"><value>'||substr(car_rec.f_withdraw,7)||'</value></field>'||
3223                     '<field name="'||'ADD_DAYS'||'"><value>'||l_add_days||'</value></field>'||
3224                     '<field name="'||'TOT_DAYS'||'"><value>'||l_tot_days||'</value></field>'||
3225                     '<field name="'||'UNAVIALABLE_VAL_2'||'"><value>'||car_rec.fuel_unavailable||'</value></field>'||
3226                     '<field name="'||'FUEL_BENEFIT_CHARGE'||'"><value>'||car_rec.f_fcc||'</value></field>'||
3227                     '</fields>  </xfdf>';
3228             end loop;
3229             end loop;
3230         else -- for RepRun 2007+
3231             for context_rec in csr_context_id(l_pactid,
3232                                               l_person_id,
3233                                               l_emp_ref_no,
3234                                               l_employer_name,
3235                                               'CAR AND CAR FUEL 2003_04') loop
3236             for car_rec in  csr_car_entries_0304(context_rec.action_context_id)
3237             loop
3238                 l_employee_number := get_assignment_number(context_rec.action_context_id);
3239                 l_loop_count := l_loop_count+1;
3240                 --Initialising the vars to null;
3241                 l_BEN_ST_DATE  := null;
3242                 l_BEN_ED_DATE  := null;
3243                 l_car_count    := null;
3244                 l_ONLY_CAR_FLAG :=null;
3245                 l_FUEL_FLAG :=null;
3246                 l_CAR_NUMBERS  := null;
3247                 l_MOD_CO2     := null;
3248                 l_PERCENT_1  := null;
3249                 l_BEN_1      := null;
3250                 l_PERCENT_2  := null;
3251                 l_BEN_2 := null;
3252                 l_PERCENT_3 := null;
3253                 l_BEN_3 := null;
3254                 l_PERCENT_4 := null;
3255                 l_BEN_4 := null;
3256                 l_BEN_5 := null;
3257                 l_STD_DISC_1 := null;
3258                 l_STD_DISC_2 := null;
3259                 l_STD_DISC_3 := null;
3260                 l_STD_DISC_4 := null;
3261                 l_STD_DISC_5 := null;
3262                 l_full_DISC  := null;
3263                 l_EXTRA_CO2  := null;
3264                 l_NORMAL_CO2  := null;
3265                 l_ROUND_NORMAL_CO2  := null;
3266                 l_CAR_BENEFIT_1  := null;
3267                 l_CAR_BENEFIT_2  := null;
3268                 l_CAR_BENEFIT_3  := null;
3269                 l_CAR_BENEFIT_4  := null;
3270                 l_CAR_BENEFIT_5  := null;
3271                 l_esize          := null;
3272                 l_add_days       := null;
3273                 l_tot_days       := null;
3274                 l_unavailble_days := null;
3275                 l_FUEL_BENEFIT_YEAR := null;
3276                 /*l_full_DISC := car_rec.FULL_DISC;  */
3277                 if car_rec.FULL_YR_FLAG = 'Y'
3278 				then
3279                     l_BEN_ST_DATE := null;
3280                     l_BEN_ED_DATE := null;
3281                 else
3282                     l_BEN_ST_DATE := car_rec.f_start;
3283                     l_BEN_ED_DATE := car_rec.f_end;
3284                 end if;
3285                 -- hr_utility.trace_on(null,'CAR');
3286                 hr_utility.trace('A4');
3287                 select action_information30
3288                 into   l_car_count
3289                 from   pay_action_information pai_emp
3290                 where  pai_emp.action_context_id = p_assignment_action_id
3291                 and    pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTA';
3292                 hr_utility.trace('A5');
3293                 if l_car_count = 1
3294 				then
3295                     l_ONLY_CAR_FLAG := 'Y';
3296                 else
3297                     l_ONLY_CAR_FLAG := 'N';
3298                     l_CAR_NUMBERS := l_car_count;
3299                 end if   ;
3300                 hr_utility.trace('A6');
3301                 hr_utility.trace('date_registered ' ||car_rec.date_registered);
3302                 -- calculating benefit charge section
3303                 if fnd_date.canonical_to_date( car_rec.date_registered)
3304                    >= to_date('01-01-1998','dd-mm-yyyy') and car_rec.CO2 is not null
3305                 then
3306                     hr_utility.trace('a');
3307                     l_MOD_CO2 := floor(car_rec.CO2/5) * 5;
3308                     hr_utility.trace('b');
3309                     l_PERCENT_1 := car_rec.BENEFIT_PERCENT;
3310                     hr_utility.trace('c');
3311                     l_STD_DISC_1   := car_rec.STD_DISC;
3312                     l_ROUND_NORMAL_CO2 := car_rec.ROUND_NORMAL_CO2;
3313                     l_full_DISC        := car_rec.FULL_DISC;
3314                     l_CAR_BENEFIT_1    := car_rec.TOTAL_BENIFIT ;
3315                 elsif fnd_date.canonical_to_date( car_rec.date_registered)
3316                       >= to_date('01-01-1998','dd-mm-yyyy') and car_rec.CO2 is null
3317                 then
3318                    hr_utility.trace('e');
3319                    l_PERCENT_2 := car_rec.BENEFIT_PERCENT;
3320                    hr_utility.trace('f');
3321                    l_STD_DISC_2   := car_rec.STD_DISC;
3322                    l_CAR_BENEFIT_2 := car_rec.TOTAL_BENIFIT_2;
3323                 elsif (fnd_date.canonical_to_date( car_rec.date_registered)<  to_date('01-01-1998','dd-mm-yyyy'))
3324 				then
3325                     hr_utility.trace('g');
3326                     -- hr_utility.trace('car_rec.benefit_charge '|| car_rec.benefit_charge);
3327                     l_full_disc := null;
3328                     l_esize := car_rec.f_esize;
3329                     open csr_engine_discount(to_number(l_esize),
3330                                              fnd_date.canonical_to_date(car_rec.ben_end));
3331                     fetch csr_engine_discount into l_CAR_BENEFIT_3;
3332                     close csr_engine_discount;
3333                 end if;
3334                 hr_utility.trace('h');
3335                 -- fuel benefit
3336                 if car_rec.FUEL_BENEFIT = 'Y'
3337 				then
3338                     L_FUEL_BENEFIT_YEAR := car_rec.FUEL_BENEFIT_YEAR;
3339                     l_add_days          := car_rec.additional_days;
3340                     l_tot_days        := car_rec.total_days;
3341                     l_unavailble_days   := car_rec.unavailable;
3342                 end if;
3343                 hr_utility.trace('i');
3344                 l_xfdf_str_tab.extend;
3345                 l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
3346                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
3347                     <fields> ' ||
3348                     '<field name="'||'EMPLOYERS_NAME'||'"><value>'||replace(l_employer_name,'&','&')       ||'</value></field>'||
3349                     '<field name="'||'FULL_NAME'||'"><value>'||l_full_name||'</value></field>'||
3350                     '<field name="'||'EMPLOYERS_REF_NO'||'"><value>'||l_emp_ref_no||'</value></field>'||
3351                     '<field name="'||'EMPLOYEE_NUMBER'||'"><value>'||l_employee_number||'</value></field>'||
3352                     -- '<field name="'||'NATIONAL_INS_NO'||'"><value>'||l_national_ins_no||'</value></field>'||
3353                     '<field name="'||'NI_1'||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
3354                     '<field name="'||'NI_2'||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
3355                     '<field name="'||'NI_3'||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
3356                     '<field name="'||'NI_4'||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
3357                     '<field name="'||'NI_5'||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
3358                     '<field name="'||'NI_6'||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
3359                     '<field name="'||'NI_7'||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
3360                     '<field name="'||'NI_8'||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
3361                     '<field name="'||'NI_9'||'"><value>' ||substr(l_national_ins_no,9) || '</value></field>  '   ||
3362                     '<field name="'||'MAKE'||'"><value>'||car_rec.make||'</value></field>'||
3363                     '<field name="'||'MODEL'||'"><value>'||car_rec.model||'</value></field>'||
3364 		    -- P11D changes 07/08 added make_model field
3365                     '<field name="'||'MAKE_MODEL'||'"><value>'||car_rec.make||' '||car_rec.model||'</value></field>'||
3366                     '<field name="'||'DATE_FIRST_REG1'||'"><value>'||substr(car_rec.f_dreg,0,2)||'</value></field>'||
3367                     '<field name="'||'DATE_FIRST_REG2'||'"><value>'||substr(car_rec.f_dreg,4,2)||'</value></field>'||
3368                     '<field name="'||'DATE_FIRST_REG3'||'"><value>'||substr(car_rec.f_dreg,7)||'</value></field>'||
3369                     '<field name="'||'ONLY_CAR_FLAG'||'"><value>'||l_ONLY_CAR_FLAG||'</value></field>'||
3370                     '<field name="'||'ONLY_CAR_FLAG_Y'||'"><value>'||l_ONLY_CAR_FLAG||'</value></field>'||
3371                     '<field name="'||'ONLY_CAR_FLAG_N'||'"><value>'||l_ONLY_CAR_FLAG||'</value></field>'||
3372                     --'<field name="'||'CO2'||'"><value>'||car_rec.CO2||'</value></field>'||
3373                     --'<field name="'||'FULL_YR_FLAG'||'"><value>'||car_rec.FULL_YR_FLAG||'</value></field>'||
3374                     '<field name="'||'CAR_NUMBERS'||'"><value>'||l_CAR_NUMBERS||'</value></field>'||
3375                     '<field name="'||'LIST_PRICE'||'"><value>'||car_rec.f_lprice||'</value></field>'||
3376                     '<field name="'||'EXTRAS_LATER'||'"><value>'||car_rec.f_oprice||'</value></field>'||
3377                     '<field name="'||'TOTAL_INIT_PRICE'||'"><value>'||car_rec.TOTAL_INIT_PRICE||'</value></field>'||
3378                     '<field name="'||'CONTRIBUTIONS'||'"><value>'||car_rec.f_cost||'</value></field>'||
3379                     '<field name="'||'FINAL_PRICE'||'"><value>'||car_rec.FINAL_PRICE||'</value></field>'||
3380                     '<field name="'||'CO2'||'"><value>'||car_rec.co2||'</value></field>'||
3381                     '<field name="'||'FUEL'||'"><value>'||car_rec.f_fuel||'</value></field>'||
3382                     '<field name="'||'MOD_CO2'||'"><value>'||l_MOD_CO2||'</value></field>'||
3383                     '<field name="'||'PERCENT_1'||'"><value>'||l_PERCENT_1||'</value></field>'||
3384                     '<field name="'||'STD_DISC_1'||'"><value>'||l_STD_DISC_1||'</value></field>'||
3385                     '<field name="'||'EXTRA_CO2'||'"><value>'||l_EXTRA_CO2||'</value></field>'||
3386                     '<field name="'||'ROUND_NORMAL_CO2'||'"><value>'||l_ROUND_NORMAL_CO2||'</value></field>' ||
3387                     '<field name="'||'FULL_DISCOUNT'||'"><value>'||l_full_DISC||'</value></field>'||
3388                     '<field name="'||'CAR_BENEFIT_1'||'"><value>'||l_CAR_BENEFIT_1||'</value></field>'||
3389                     '<field name="'||'PERCENT_2'||'"><value>'||l_PERCENT_2||'</value></field>'||
3390                     '<field name="'||'STD_DISC_2'||'"><value>'||l_STD_DISC_2||'</value></field>'||
3391                     '<field name="'||'CAR_BENEFIT_2'||'"><value>'||l_CAR_BENEFIT_2||'</value></field>'||
3392                     '<field name="'||'ENGINE_CC'||'"><value>'||l_esize||'</value></field>'||
3393                     '<field name="'||'CAR_BENEFIT_3'||'"><value>'||l_CAR_BENEFIT_3||'</value></field>'||
3394                     '<field name="'||'CAR_BENEFIT_YEAR'||'"><value>'||car_rec.car_benefit_year||'</value></field>'||
3395                    '<field name="'||'BEN_ST_DATE1'||'"><value>'||substr(l_BEN_ST_DATE,0,2)||'</value></field>'||
3396                     '<field name="'||'BEN_ST_DATE2'||'"><value>'||substr(l_BEN_ST_DATE,4,2)||'</value></field>'||
3397                     '<field name="'||'BEN_ST_DATE3'||'"><value>'||substr(l_BEN_ST_DATE,7)||'</value></field>'||
3398                     '<field name="'||'BEN_ED_DATE1'||'"><value>'||substr(l_BEN_ED_DATE,0,2)||'</value></field>'||
3399                     '<field name="'||'BEN_ED_DATE2'||'"><value>'||substr(l_BEN_ED_DATE,4,2)||'</value></field>'||
3400                     '<field name="'||'BEN_ED_DATE3'||'"><value>'||substr(l_BEN_ED_DATE,7)||'</value></field>'||
3401                     '<field name="'||'UNAVAILABLE'||'"><value>'||car_rec.unavailable||'</value></field>'||
3402                     '<field name="'||'UNAVAILABLE_VAL_1'||'"><value>'||car_rec.unavailable_value||'</value></field>'||
3403                     '<field name="'||'CAR_BENEFIT_AVAILABLE'||'"><value>'||car_rec.CAR_BENEFIT_AVAILABLE||'</value></field>'||
3404                     '<field name="'||'PRIVATE_USE_PAYMENT'||'"><value>'||car_rec.f_amg||'</value></field>'||
3405                     '<field name="'||'CASH_EQUIVALENT_CAR'||'"><value>'||car_rec.f_cc||'</value></field>'||
3406                     '<field name="'||'FUEL_BENEFIT_YEAR'||'"><value>'||l_FUEL_BENEFIT_YEAR||'</value></field>'||
3407                     '<field name="'||'UNAVAILABLE_2'||'"><value>'||l_unavailble_days||'</value></field>'||
3408                     '<field name="'||'WITHDRAW_DATE1'||'"><value>'||substr(car_rec.f_withdraw,0,2)||'</value></field>'||
3409                     '<field name="'||'WITHDRAW_DATE2'||'"><value>'||substr(car_rec.f_withdraw,4,2)||'</value></field>'||
3410                     '<field name="'||'WITHDRAW_DATE3'||'"><value>'||substr(car_rec.f_withdraw,7)||'</value></field>'||
3411                     '<field name="'||'ADD_DAYS'||'"><value>'||l_add_days||'</value></field>'||
3412                     '<field name="'||'TOT_DAYS'||'"><value>'||l_tot_days||'</value></field>'||
3413                     '<field name="'||'UNAVIALABLE_VAL_2'||'"><value>'||car_rec.fuel_unavailable||'</value></field>'||
3414                     '<field name="'||'FUEL_BENEFIT_CHARGE'||'"><value>'||car_rec.f_fcc||'</value></field>'||
3415                     '</fields>  </xfdf>';
3416             end loop;
3417             end loop;
3418         end if;
3419         open l_ret_ref_cursor for
3420         select *
3421         from table (cast(l_xfdf_str_tab as per_gb_xfdftableType));
3422         p_record_num := l_loop_count;
3423         return l_ret_ref_cursor;
3424    end ;
3425 
3426    function fetch_ws3_ref_cursor (p_assignment_action_id Number,
3427                                   p_record_num out nocopy NUmber) return ref_cursor_typ
3428    is
3429         -- per_gb_xfdftableType is explicitly created type
3430         -- only modification needed is it could be of type blob
3431         -- i tried thta but could not access the blob valus in java routine.
3432         -- can be sorted later
3433         l_xfdf_str_tab per_gb_xfdftableType := per_gb_xfdftableType( );
3434         l_xfdf_str varchar2(32000);
3435         l_ret_ref_cursor ref_cursor_typ;
3436 
3437         cursor csr_vans_entries(p_pactid Number,
3438                                 p_person_id Number,
3439                                 p_emp_ref Varchar2 ,
3440                                 p_emp_name Varchar2)
3441         is
3442         -- formatting in the ws is handled by the
3443         -- format feature in pdf. xdo is now supporting it
3444         -- but has limittaion where the fields are repating
3445         -- and hence the format clause is used for STD_UNAVILA_VAL
3446         select decode(ACTION_INFORMATION6, null,'Y','Y','N','N','Y') exclusive_flag,
3447                ACTION_INFORMATION7 dreg,
3448                nvl(ACTION_INFORMATION18,500) standard_charge,
3449                nvl(ACTION_INFORMATION8,0)  UNAVAILABLE_1,
3450                nvl(ACTION_INFORMATION9,0)  UNAVAILABLE_2,
3451                nvl(ACTION_INFORMATION10,0)  UNAVAILABLE_3,
3452                nvl(ACTION_INFORMATION11,0)  UNAVAILABLE_4,
3453                nvl(ACTION_INFORMATION12,0) UNAVAILABLE_VAL,
3454                nvl(ACTION_INFORMATION13,0) NUM_SHARE,
3455                nvl(ACTION_INFORMATION14,0) PVT_USE_PAYMENT,
3456                nvl(ACTION_INFORMATION15,0) CASH_EQUIVALENT
3457         from  pay_action_information
3458         where action_information_category = 'VANS 2002_03'
3459         and   action_context_id in (select paa.assignment_action_id
3460                                     from   pay_action_information pai_comp,
3461                                            pay_action_information pai_person,
3462                                            pay_assignment_actions paa,
3463                                            pay_payroll_actions ppa
3464                                     where  ppa.payroll_action_id = p_pactid
3465                                     and    paa.payroll_action_id = ppa.payroll_action_id
3466                                     and    pai_comp.action_context_id = paa.assignment_action_id
3467                                     and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
3468                                     and    pai_person.action_context_id = paa.assignment_action_id
3469                                     and    pai_person.action_information_category = 'ADDRESS DETAILS'
3470                                     and    pai_person.action_information14 = 'Employee Address'
3471                                     and    pai_person.action_information1 = to_char(p_person_id)
3472                                     and    pai_comp.action_information6 = p_emp_ref
3473                                     and    pai_comp.action_information7 = p_emp_name);
3474 
3475         cursor csr_vans_entries_05(p_pactid Number,
3476                                    p_person_id Number,
3477                                    p_emp_ref Varchar2 ,
3478                                    p_emp_name Varchar2)
3479         is
3480         select nvl(action_information5,' ') registration_number,
3481                action_information6          date_registered,
3482                -- count vans --
3483                -- number of worksheet --
3484                nvl(action_information24,0)  van_charged,  -- A
3485                action_information3          van_from_b,   --
3486                action_information4          van_to_b,     --
3487                action_information7          van_unavil_b, -- B
3488                action_information16         van_from_c,   --
3489                action_information17         van_to_c,     --
3490                action_information18         van_unavil_c, -- C
3491                action_information19         van_from_d,   --
3492                action_information20         van_to_d,     --
3493                action_information21         van_unavil_d, -- D
3494                nvl(action_information8,0)   van_tot_day_unavil, -- E
3495                nvl(action_information9,0)   van_unavil_value,   -- F
3496                nvl(action_information10,0)  van_reduce_value,   -- G
3497                nvl(action_information11,0)  van_sh_pcent_reduc, -- H
3498                nvl(action_information12,0)  van_sh_reduction,   -- J
3499                action_information13         van_explanation,    --
3500                nvl(action_information10,0) -
3501                nvl(action_information12,0)  van_reduce_share,   -- K
3502                nvl(action_information14,0)  van_private_uses,   -- L
3503                nvl(action_information15,0)  van_benefit_charge, -- M
3504                action_context_id
3505         from   pay_action_information
3506         where  action_information_category = 'VANS 2005'
3507         and    action_context_type = 'AAP'
3508         and    action_context_id in (select paa.assignment_action_id
3509                                     from   pay_action_information pai_comp,
3510                                            pay_action_information pai_person,
3511                                            pay_assignment_actions paa,
3512                                            pay_payroll_actions ppa
3513                                     where  ppa.payroll_action_id = p_pactid
3514                                     and    paa.payroll_action_id = ppa.payroll_action_id
3515                                     and    pai_comp.action_context_id = paa.assignment_action_id
3516                                     and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
3517                                     and    pai_comp.action_context_type = 'AAP'
3518                                     and    pai_person.action_context_id = paa.assignment_action_id
3519                                     and    pai_person.action_information_category = 'ADDRESS DETAILS'
3520                                     and    pai_person.action_context_type = 'AAP'
3521                                     and    pai_person.action_information14 = 'Employee Address'
3522                                     and    pai_person.action_information1 = to_char(p_person_id)
3523                                     and    pai_comp.action_information6 = p_emp_ref
3524                                     and    pai_comp.action_information7 = p_emp_name);
3525 
3526         cursor csr_vans_05_count(p_pactid Number,
3527                                  p_person_id Number,
3528                                  p_emp_ref Varchar2 ,
3529                                  p_emp_name Varchar2)
3530         is
3531         select count(*)
3532         from   pay_action_information
3533         where  action_information_category = 'VANS 2005'
3534         and    action_context_type = 'AAP'
3535         and    action_context_id in (select paa.assignment_action_id
3536                                     from   pay_action_information pai_comp,
3537                                            pay_action_information pai_person,
3538                                            pay_assignment_actions paa,
3539                                            pay_payroll_actions ppa
3540                                     where  ppa.payroll_action_id = p_pactid
3541                                     and    paa.payroll_action_id = ppa.payroll_action_id
3542                                     and    pai_comp.action_context_id = paa.assignment_action_id
3543                                     and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
3544                                     and    pai_comp.action_context_type = 'AAP'
3545                                     and    pai_person.action_context_id = paa.assignment_action_id
3546                                     and    pai_person.action_information_category = 'ADDRESS DETAILS'
3547                                     and    pai_person.action_context_type = 'AAP'
3548                                     and    pai_person.action_information14 = 'Employee Address'
3549                                     and    pai_person.action_information1 = to_char(p_person_id)
3550                                     and    pai_comp.action_information6 = p_emp_ref
3551                                     and    pai_comp.action_information7 = p_emp_name);
3552 
3553         -- P11D Changes 07/08
3554 	-- Cursor to fetch the VANS 2007 element details
3555 	cursor csr_vans_entries_07(p_pactid Number,
3556                                    p_person_id Number,
3557                                    p_emp_ref Varchar2 ,
3558                                    p_emp_name Varchar2)
3559         is
3560         select nvl(action_information5,' ') registration_number,
3561                -- count vans --
3562                -- number of worksheet --
3563        	       nvl(action_information24,0)  van_charged,  -- A
3564                action_information3          van_from_b,   --
3565                action_information4          van_to_b,     --
3566                action_information6          van_unavil_b, -- B
3567                action_information15         van_from_c,   --
3568                action_information16         van_to_c,     --
3569                action_information17         van_unavil_c, -- C
3570                action_information18         van_from_d,   --
3571                action_information19         van_to_d,     --
3572                action_information20         van_unavil_d, -- D
3573                nvl(action_information7,0)   van_tot_day_unavil, -- E
3574                nvl(action_information8,0)   van_unavil_value,   -- F
3575                nvl(action_information9,0)  van_reduce_value,   -- G
3576                nvl(action_information10,0)  van_sh_pcent_reduc, -- H
3577                nvl(action_information11,0)  van_sh_reduction,   -- J
3578                action_information12         van_explanation,    --
3579                nvl(action_information9,0) -
3580                nvl(action_information11,0)  van_reduce_share,   -- K
3581                nvl(action_information13,0)  van_private_uses,   -- L
3582                nvl(action_information14,0)  van_benefit_charge, -- M
3583                nvl(action_information24,0)  van_benefit_chare_tax, --P
3584                action_information25         van_fuel_withdrawn, --R date
3585                nvl(action_information26,0)  van_days_after_fuel_wd, --R
3586                nvl(action_information27,0)  van_total_days_no_fuel, -- S
3587                nvl(action_information28,0)  van_reduction, --T
3588                (nvl(action_information24,0)
3589                - nvl(action_information28,0)) van_fuel_charge_reduction, --V
3590                nvl(action_information29,0)    van_reduction_sharing, --W
3591                nvl(action_information30,0)    van_feul_ben_charge, --X
3592                action_context_id
3593         from   pay_action_information
3594         where  action_information_category = 'VANS 2007'
3595         and    action_context_type = 'AAP'
3596         and    action_context_id in (select paa.assignment_action_id
3597                                     from   pay_action_information pai_comp,
3598                                            pay_action_information pai_person,
3599                                            pay_assignment_actions paa,
3600                                            pay_payroll_actions ppa
3601                                     where  ppa.payroll_action_id = p_pactid
3602                                     and    paa.payroll_action_id = ppa.payroll_action_id
3603                                     and    pai_comp.action_context_id = paa.assignment_action_id
3604                                     and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
3605                                     and    pai_comp.action_context_type = 'AAP'
3606                                     and    pai_person.action_context_id = paa.assignment_action_id
3607                                     and    pai_person.action_information_category = 'ADDRESS DETAILS'
3608                                     and    pai_person.action_context_type = 'AAP'
3609                                     and    pai_person.action_information14 = 'Employee Address'
3610                                     and    pai_person.action_information1 = to_char(p_person_id)
3611                                     and    pai_comp.action_information6 = p_emp_ref
3612                                     and    pai_comp.action_information7 = p_emp_name);
3613         -- P11D Changes 07/08
3614 	-- Cursor to count the VANS 2007 element details
3615         cursor csr_vans_07_count(p_pactid Number,
3616                                  p_person_id Number,
3617                                  p_emp_ref Varchar2 ,
3618                                  p_emp_name Varchar2)
3619         is
3620         select count(*)
3621         from   pay_action_information
3622         where  action_information_category = 'VANS 2007'
3623         and    action_context_type = 'AAP'
3624         and    action_context_id in (select paa.assignment_action_id
3625                                     from   pay_action_information pai_comp,
3626                                            pay_action_information pai_person,
3627                                            pay_assignment_actions paa,
3628                                            pay_payroll_actions ppa
3629                                     where  ppa.payroll_action_id = p_pactid
3630                                     and    paa.payroll_action_id = ppa.payroll_action_id
3631                                     and    pai_comp.action_context_id = paa.assignment_action_id
3632                                     and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
3633                                     and    pai_comp.action_context_type = 'AAP'
3634                                     and    pai_person.action_context_id = paa.assignment_action_id
3635                                     and    pai_person.action_information_category = 'ADDRESS DETAILS'
3636                                     and    pai_person.action_context_type = 'AAP'
3637                                     and    pai_person.action_information14 = 'Employee Address'
3638                                     and    pai_person.action_information1 = to_char(p_person_id)
3639                                     and    pai_comp.action_information6 = p_emp_ref
3640                                     and    pai_comp.action_information7 = p_emp_name);
3641 
3642 
3643         l_emp_ref_no varchar2(150);
3644         l_employer_name varchar2(150);
3645         l_full_name varchar2(150);
3646         l_national_ins_no varchar2(150);
3647         l_employee_number varchar2(150);
3648         l_pactid number;
3649         l_person_id number;
3650         l_rep_run varchar2(10);
3651         l_loop_count number;
3652         l_vans_count  number;
3653         l_only_van   varchar2(2);
3654         l_after_flag varchar2(2);
3655         l_date_from  varchar2(15);
3656         l_date_to    varchar2(15);
3657         l_days_after_fuel_wd varchar2(30);
3658         l_fuel_charge_reduction varchar2(30);
3659    begin
3660         get_employer_details(p_assignment_action_id,
3661                              l_emp_ref_no,
3662                              l_employer_name);
3663         get_employee_details(p_assignment_action_id,
3664                              l_full_name,
3665                              l_national_ins_no,
3666                              l_employee_number);
3667         l_pactid := get_pactid(p_assignment_action_id);
3668         l_person_id := get_person_id (p_assignment_action_id );
3669         l_loop_count := 0;
3670 
3671         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
3672          p_payroll_action_id           => l_pactid,
3673          p_token_name                  => 'Rep_Run',
3674          p_token_value                 => l_rep_run);
3675 
3676         l_date_from := '06-04-' || to_char(to_number(l_rep_run) - 1 );
3677         l_date_to   := '05-04-' || l_rep_run;
3678 
3679         if to_number(l_rep_run) < '2006'
3680         then
3681             for van_entries in  csr_vans_entries(l_pactid,
3682                                                  l_person_id,
3683                                                  l_emp_ref_no,
3684                                                  l_employer_name)
3685             loop
3686                 l_loop_count := l_loop_count+1;
3687                 hr_utility.trace('a');
3688                 -- l_ws3_info_tab(l_loop_count).l_vans_entries := van_entries;
3689                 l_xfdf_str_tab.extend;
3690                 l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
3691                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
3692                     <fields> ' ||
3693                     '<field name="'||'Employer'||'"><value>' ||replace(l_employer_name,'&','&')  || '</value></field> ' ||
3694                     '<field name="'||'Employee'||'"><value>' ||l_full_name || '</value></field>  ' ||
3695                     '<field name="'||'PAYE_tax'||'"><value>' ||l_emp_ref_no || '</value></field>  ' ||
3696                     '<field name="'||'Works_no'||'"><value>' ||l_employee_number || '</value></field>  ' ||
3697                     -- ' <field name="'||'Nat_Ins_Num'||'"><value>' ||l_national_ins_no || '</value></field>  '  ||
3698                     '<field name="'||'NI_1'||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
3699                     '<field name="'||'NI_2'||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
3700                     '<field name="'||'NI_3'||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
3701                     '<field name="'||'NI_4'||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
3702                     '<field name="'||'NI_5'||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
3703                     '<field name="'||'NI_6'||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
3704                     '<field name="'||'NI_7'||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
3705                     '<field name="'||'NI_8'||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
3706                     '<field name="'||'NI_9'||'"><value>' ||substr(l_national_ins_no,9)   || '</value></field>  '  ||
3707                     '<field name="'||'exclusive_flag'||'"><value>' ||van_entries.exclusive_flag || '</value></field>  '  ;
3708                      hr_utility.trace('aa');
3709                 if van_entries.exclusive_flag = 'Y'
3710                 then -- we fill section 1
3711                     if fnd_date.canonical_to_date(van_entries.dreg) > to_date('05-04-2000','dd-mm-yyyy')
3712                     then
3713                         l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count) ||
3714                         '<field name="'||'date_flag'||'"><value>' ||'Y' || '</value></field>  '  ;
3715                     else
3716                         l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3717                         '<field name="'||'date_flag'||'"><value>' ||'N' || '</value></field>  '  ;
3718                     end if;
3719                     hr_utility.trace('2');
3720                     l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3721                         '<field name="'||'standard_charge'||'"><value>' ||van_entries.standard_charge || '</value></field>  '  ||
3722                         '<field name="'||'UNAVAILABLE_1'  ||'"><value>' ||van_entries.UNAVAILABLE_1   || '</value></field>  '  ||
3723                         '<field name="'||'UNAVAILABLE_2'  ||'"><value>' ||van_entries.UNAVAILABLE_2   || '</value></field>  '  ||
3724                         '<field name="'||'UNAVAILABLE_3'  ||'"><value>' ||van_entries.UNAVAILABLE_3   || '</value></field>  '  ||
3725                         '<field name="'||'UNAVAILABLE_4'  ||'"><value>' ||van_entries.UNAVAILABLE_4   || '</value></field>  '  ||
3726                         '<field name="'||'TOT_UNAVAILABLE'||'"><value>' ||(nvl(van_entries.UNAVAILABLE_1,0) + nvl(van_entries.UNAVAILABLE_2,0) +
3727                         nvl(van_entries.UNAVAILABLE_3,0) + nvl(van_entries.UNAVAILABLE_4,0))  || '</value></field>  '  ||
3728                         '<field name="'||'UNAVAILABLE_VAL'||'"><value>' ||van_entries.UNAVAILABLE_VAL || '</value></field>  '  ||
3729                         '<field name="'||'STD_RED'        ||'"><value>' || (nvl(van_entries.standard_charge,0) - nvl(van_entries.UNAVAILABLE_VAL,0)) || '</value></field>  ' ||
3730                         '<field name="'||'PVT_USE_PAYMENT'||'"><value>' ||van_entries.PVT_USE_PAYMENT || '</value></field>  '  ||
3731                         '<field name="'||'NON_SHARED_BEN' ||'"><value>' ||van_entries.CASH_EQUIVALENT || '</value></field>  '  ||
3732                         '<field name="'||'CE'             ||'"><value>' ||van_entries.CASH_EQUIVALENT || '</value></field>  '  ;
3733                     hr_utility.trace('3');
3734                 else -- else of van_entries.exclusive_flag = 'Y'
3735                     hr_utility.trace('4');
3736                     if fnd_date.canonical_to_date(van_entries.dreg) > to_date('05-04-2000','dd-mm-yyyy')
3737                     then
3738                         l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3739                         '<field name="'||'S_DATE_FLAG'||'"><value>' ||'Y' || '</value></field>  '  ;
3740                     else
3741                         l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3742                         '<field name="'||'S_DATE_FLAG'||'"><value>' ||'N' || '</value></field>  '  ;
3743                     end if;
3744                     l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3745                     '<field name="'||'S_STANDARD_CHARGE'||'"><value>' ||van_entries.standard_charge || '</value></field>  '  ;
3746                     hr_utility.trace('5');
3747                     if nvl(van_entries.UNAVAILABLE_VAL,0) = 0
3748                     then
3749                         l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3750                         '<field name="'||'S_FULL_YEAR_FLAG'||'"><value>' ||'Y' || '</value></field>  '  ;
3751                         hr_utility.trace('7');
3752                     else
3753                         hr_utility.trace('6');
3754                         l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3755                         '<field name="'||'S_FULL_YEAR_FLAG' ||'"><value>' ||'N'                       || '</value></field>  '  ||
3756                         '<field name="'||'S_UNAVAILABLE_1'  ||'"><value>' ||van_entries.UNAVAILABLE_1 || '</value></field>  '  ||
3757                         '<field name="'||'S_UNAVAILABLE_2'  ||'"><value>' ||van_entries.UNAVAILABLE_2 || '</value></field>  '  ||
3758                         '<field name="'||'S_UNAVAILABLE_3'  ||'"><value>' ||van_entries.UNAVAILABLE_3 || '</value></field>  '  ||
3759                         '<field name="'||'S_UNAVAILABLE_4'  ||'"><value>' ||van_entries.UNAVAILABLE_4 || '</value></field>  '  ||
3760                         '<field name="'||'S_TOT_UNAVAILABLE'||'"><value>' ||(nvl(van_entries.UNAVAILABLE_1,0) +
3761                         nvl(van_entries.UNAVAILABLE_2,0) + nvl(van_entries.UNAVAILABLE_3,0) + nvl(van_entries.UNAVAILABLE_4,0))  || '</value></field>  ' ||
3762                         '<field name="'||'S_UNAVAIL_VAL'    ||'"><value>' ||van_entries.UNAVAILABLE_VAL || '</value></field>  '  ;
3763                     end if;
3764                     hr_utility.trace('8');
3765                     l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  ||
3766                     '<field name="'||'S_STD_UNAVAIL'    ||'"><value>' ||
3767                     to_char(to_number((nvl(van_entries.standard_charge,0) - nvl(van_entries.UNAVAILABLE_VAL,0))),
3768     	                            'FM999,999,990.00') || '</value></field>  '  ||
3769                     '<field name="'||'S_NUM_SHARE'      ||'"><value>' || van_entries.NUM_SHARE  || '</value></field>  '  ||
3770                     '<field name="'||'S_CHRG_PER_SHARE' ||'"><value>' ||
3771                     ((nvl(van_entries.standard_charge,0) - nvl(van_entries.UNAVAILABLE_VAL,0))/van_entries.NUM_SHARE)
3772                                    || '</value></field>  ' ||
3773                     '<field name="'||'S_STD_CHARGE'||'"><value>' ||
3774                     ((nvl(van_entries.standard_charge,0) - nvl(van_entries.UNAVAILABLE_VAL,0))/van_entries.NUM_SHARE)
3775                                    || '</value></field>  '  ||
3776                     '<field name="'||'S_PVT_USE_PAYMENT'||'"><value>' ||van_entries.PVT_USE_PAYMENT || '</value></field>  '  ||
3777                     '<field name="'||'SHARED_BEN'       ||'"><value>' ||van_entries.CASH_EQUIVALENT || '</value></field>  '  ||
3778                     '<field name="'||'CE'               ||'"><value>' ||van_entries.CASH_EQUIVALENT || '</value></field>  '  ;
3779                 end if; -- end of checking for van_entries.exclusive_flag = 'Y'
3780                 hr_utility.trace('9');
3781                 l_xfdf_str_tab(l_loop_count) := l_xfdf_str_tab(l_loop_count)  || '</fields>  </xfdf>';
3782             end loop;
3783         elsif to_number(l_rep_run) >= 2006 and to_number(l_rep_run) < 2008 then -- P11D changes 07/08 -- l_rep_run > 2005, so 2006 onwards.
3784             open csr_vans_05_count(l_pactid,
3785                                    l_person_id,
3786                                    l_emp_ref_no,
3787                                    l_employer_name);
3788             fetch csr_vans_05_count into l_vans_count;
3789             close csr_vans_05_count;
3790 
3791             --l_only_van := 'Y';
3792             if l_vans_count > 1 then
3793                l_only_van := 'N';
3794             else
3795                l_vans_count := null;
3796                l_only_van := 'Y';
3797             end if;
3798 
3799             for vans_entries in  csr_vans_entries_05(l_pactid,
3800                                                      l_person_id,
3801                                                      l_emp_ref_no,
3802                                                      l_employer_name)
3803             loop
3804                 l_loop_count := l_loop_count+1;
3805                 hr_utility.trace('Vans');
3806                 l_after_flag := 'N';
3807                 if to_number(l_rep_run) < 2007 then
3808                    if fnd_date.canonical_to_date(vans_entries.date_registered) > to_date('05-04-2002','dd-mm-yyyy')
3809                    then
3810                        l_after_flag := 'Y';
3811                    end if;
3812                 else -- >= 2007
3813                    if fnd_date.canonical_to_date(vans_entries.date_registered) > to_date('05-04-2003','dd-mm-yyyy')
3814                    then
3815                        l_after_flag := 'Y';
3816                    end if;
3817                 end if;
3818 
3819                 /* check date from and date to */
3820                 if fnd_date.canonical_to_date(vans_entries.van_from_b) = to_date(l_date_from,'DD-MM-YYYY') and
3821                    fnd_date.canonical_to_date(vans_entries.van_to_b)  = to_date(l_date_to,'DD-MM-YYYY')
3822                 then
3823                     vans_entries.van_from_b := null;
3824                     vans_entries.van_to_b   := null;
3825                 end if;
3826                 /* end check  */
3827                 l_employee_number := get_assignment_number(vans_entries.action_context_id);
3828 
3829                 l_xfdf_str_tab.extend;
3830                 l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
3831                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
3832                     <fields> ' ||
3833                     '<field name="'||'Employer'   ||'"><value>' ||replace(l_employer_name,'&','&')      || '</value></field>  ' ||
3834                     '<field name="'||'Employee'   ||'"><value>' ||l_full_name                               || '</value></field>  ' ||
3835                     '<field name="'||'PAYE_tax'   ||'"><value>' ||l_emp_ref_no                              || '</value></field>  ' ||
3836                     '<field name="'||'Works_no'   ||'"><value>' ||l_employee_number                         || '</value></field>  ' ||
3837                     '<field name="'||'NI_1'       ||'"><value>' ||substr(l_national_ins_no,1,1)             || '</value></field>  ' ||
3838                     '<field name="'||'NI_2'       ||'"><value>' ||substr(l_national_ins_no,2,1)             || '</value></field>  ' ||
3839                     '<field name="'||'NI_3'       ||'"><value>' ||substr(l_national_ins_no,3,1)             || '</value></field>  ' ||
3840                     '<field name="'||'NI_4'       ||'"><value>' ||substr(l_national_ins_no,4,1)             || '</value></field>  ' ||
3841                     '<field name="'||'NI_5'       ||'"><value>' ||substr(l_national_ins_no,5,1)             || '</value></field>  ' ||
3842                     '<field name="'||'NI_6'       ||'"><value>' ||substr(l_national_ins_no,6,1)             || '</value></field>  ' ||
3843                     '<field name="'||'NI_7'       ||'"><value>' ||substr(l_national_ins_no,7,1)             || '</value></field>  ' ||
3844                     '<field name="'||'NI_8'       ||'"><value>' ||substr(l_national_ins_no,8,1)             || '</value></field>  ' ||
3845                     '<field name="'||'NI_9'       ||'"><value>' ||substr(l_national_ins_no,9)               || '</value></field>  ' ||
3846                     '<field name="'||'REG_NO'     ||'"><value>' ||vans_entries.registration_number          || '</value></field>  ' ||
3847                     '<field name="'||'REG_DAY'    ||'"><value>' ||substr(vans_entries.date_registered,9,2)  || '</value></field>  ' ||
3848                     '<field name="'||'REG_MONTH'  ||'"><value>' ||substr(vans_entries.date_registered,6,2)  || '</value></field>  ' ||
3849                     '<field name="'||'REG_YEAR'   ||'"><value>' ||substr(vans_entries.date_registered,1,4)  || '</value></field>  ' ||
3850                     '<field name="'||'ONLY_VAN'   ||'"><value>' ||l_only_van                                || '</value></field>  ' ||
3851                     '<field name="'||'ONLY_VAN_Y' ||'"><value>' ||l_only_van                                || '</value></field>  ' ||
3852                     '<field name="'||'ONLY_VAN_N' ||'"><value>' ||l_only_van                                || '</value></field>  ' ||
3853                     '<field name="'||'VAN_COUNT'  ||'"><value>' ||l_vans_count                              || '</value></field>  ' ||
3854                     '<field name="'||'VAN_AFTER'  ||'"><value>' ||l_after_flag                              || '</value></field>  ' ||
3855                     '<field name="'||'VAN_AFTER_Y'||'"><value>' ||l_after_flag                              || '</value></field>  ' ||
3856                     '<field name="'||'VAN_AFTER_N'||'"><value>' ||l_after_flag                              || '</value></field>  ' ||
3857                     '<field name="'||'VAN_A'      ||'"><value>' ||vans_entries.van_charged                  || '</value></field>  ' ||
3858                     '<field name="'||'VAN_B_FD'   ||'"><value>' ||substr(vans_entries.van_from_b,9,2)       || '</value></field>  ' ||
3859                     '<field name="'||'VAN_B_FM'   ||'"><value>' ||substr(vans_entries.van_from_b,6,2)       || '</value></field>  ' ||
3860                     '<field name="'||'VAN_B_FY'   ||'"><value>' ||substr(vans_entries.van_from_b,1,4)       || '</value></field>  ' ||
3861                     '<field name="'||'VAN_B_TD'   ||'"><value>' ||substr(vans_entries.van_to_b,9,2)         || '</value></field>  ' ||
3862                     '<field name="'||'VAN_B_TM'   ||'"><value>' ||substr(vans_entries.van_to_b,6,2)         || '</value></field>  ' ||
3863                     '<field name="'||'VAN_B_TY'   ||'"><value>' ||substr(vans_entries.van_to_b,1,4)         || '</value></field>  ' ||
3864                     '<field name="'||'VAN_B'      ||'"><value>' ||vans_entries.van_unavil_b                 || '</value></field>  ' ||
3865                     '<field name="'||'VAN_C_FD'   ||'"><value>' ||substr(vans_entries.van_from_c,9,2)       || '</value></field>  ' ||
3866                     '<field name="'||'VAN_C_FM'   ||'"><value>' ||substr(vans_entries.van_from_c,6,2)       || '</value></field>  ' ||
3867                     '<field name="'||'VAN_C_FY'   ||'"><value>' ||substr(vans_entries.van_from_c,1,4)       || '</value></field>  ' ||
3868                     '<field name="'||'VAN_C_TD'   ||'"><value>' ||substr(vans_entries.van_to_c,9,2)         || '</value></field>  ' ||
3869                     '<field name="'||'VAN_C_TM'   ||'"><value>' ||substr(vans_entries.van_to_c,6,2)         || '</value></field>  ' ||
3870                     '<field name="'||'VAN_C_TY'   ||'"><value>' ||substr(vans_entries.van_to_c,1,4)         || '</value></field>  ' ||
3871                     '<field name="'||'VAN_C'      ||'"><value>' ||vans_entries.van_unavil_c                 || '</value></field>  ' ||
3872                     '<field name="'||'VAN_D_FD'   ||'"><value>' ||substr(vans_entries.van_from_d,9,2)       || '</value></field>  ' ||
3873                     '<field name="'||'VAN_D_FM'   ||'"><value>' ||substr(vans_entries.van_from_d,6,2)       || '</value></field>  ' ||
3874                     '<field name="'||'VAN_D_FY'   ||'"><value>' ||substr(vans_entries.van_from_d,1,4)       || '</value></field>  ' ||
3875                     '<field name="'||'VAN_D_TD'   ||'"><value>' ||substr(vans_entries.van_to_d,9,2)         || '</value></field>  ' ||
3876                     '<field name="'||'VAN_D_TM'   ||'"><value>' ||substr(vans_entries.van_to_d,6,2)         || '</value></field>  ' ||
3877                     '<field name="'||'VAN_D_TY'   ||'"><value>' ||substr(vans_entries.van_to_d,1,4)         || '</value></field>  ' ||
3878                     '<field name="'||'VAN_D'      ||'"><value>' ||vans_entries.van_unavil_d                 || '</value></field>  ' ||
3879                     '<field name="'||'VAN_E'      ||'"><value>' ||vans_entries.van_tot_day_unavil           || '</value></field>  ' ||
3880                     '<field name="'||'VAN_F'      ||'"><value>' ||vans_entries.van_unavil_value             || '</value></field>  ' ||
3881                     '<field name="'||'VAN_G'      ||'"><value>' ||vans_entries.van_reduce_value             || '</value></field>  ' ||
3882                     '<field name="'||'VAN_G2'     ||'"><value>' ||vans_entries.van_reduce_value             || '</value></field>  ' ||
3883                     '<field name="'||'VAN_H'      ||'"><value>' ||vans_entries.van_sh_pcent_reduc           || '</value></field>  ' ||
3884                     '<field name="'||'VAN_J'      ||'"><value>' ||vans_entries.van_sh_reduction             || '</value></field>  ' ||
3885                     '<field name="'||'VAN_EXP'    ||'"><value>' ||vans_entries.van_explanation              || '</value></field>  ' ||
3886                     '<field name="'||'VAN_K'      ||'"><value>' ||vans_entries.van_reduce_share             || '</value></field>  ' ||
3887                     '<field name="'||'VAN_L'      ||'"><value>' ||vans_entries.van_private_uses             || '</value></field>  ' ||
3888                     '<field name="'||'VAN_M'      ||'"><value>' ||vans_entries.van_benefit_charge           || '</value></field>  ' ||
3889                     '</fields>  </xfdf>';
3890             end loop;
3891         else -- after 2008 onwords -- P11D changes 07/08
3892             open csr_vans_07_count(l_pactid,
3893                                    l_person_id,
3894                                    l_emp_ref_no,
3895                                    l_employer_name);
3896             fetch csr_vans_07_count into l_vans_count;
3897             close csr_vans_07_count;
3898 
3899             --l_only_van := 'Y';
3900             if l_vans_count > 1 then
3901                l_only_van := 'N';
3902             else
3903                l_vans_count := null;
3904                l_only_van := 'Y';
3905             end if;
3906 
3907             for vans_entries in  csr_vans_entries_07(l_pactid,
3908                                                      l_person_id,
3909                                                      l_emp_ref_no,
3910                                                      l_employer_name)
3911             loop
3912                 l_loop_count := l_loop_count+1;
3913                 /* bug 7146755  added the below variables to check if the employee receives no fuel benefit
3914                 then display the fields fuel_charge_reduction and days_after_fuel_wd to be null */
3915                 l_fuel_charge_reduction := vans_entries.van_fuel_charge_reduction;
3916                 l_days_after_fuel_wd  :=vans_entries.van_days_after_fuel_wd;
3917 
3918                 if (vans_entries.van_feul_ben_charge = '0')
3919                 THEN
3920                 l_fuel_charge_reduction := NULL;
3921                 l_days_after_fuel_wd  :=NULL;
3922                 END IF;
3923                 --end of bug 7146755
3924                 hr_utility.trace('Vans 2007');
3925                 l_after_flag := 'N';
3926                /* if to_number(l_rep_run) < 2007 then
3927                    if fnd_date.canonical_to_date(vans_entries.date_registered) > to_date('05-04-2002','dd-mm-yyyy')
3928                    then
3929                        l_after_flag := 'Y';
3930                    end if;
3931                 else -- >= 2007
3932                    if fnd_date.canonical_to_date(vans_entries.date_registered) > to_date('05-04-2003','dd-mm-yyyy')
3933                    then
3934                        l_after_flag := 'Y';
3935                    end if;
3936                 end if; */
3937 
3938                 /* check date from and date to */
3939 
3940                 if fnd_date.canonical_to_date(vans_entries.van_from_b) = to_date(l_date_from,'DD-MM-YYYY') and
3941                    fnd_date.canonical_to_date(vans_entries.van_to_b)  = to_date(l_date_to,'DD-MM-YYYY')
3942                 then
3943                     vans_entries.van_from_b := null;
3944                     vans_entries.van_to_b   := null;
3945                 end if;
3946                 /* end check  */
3947                 l_employee_number := get_assignment_number(vans_entries.action_context_id);
3948 
3949                 l_xfdf_str_tab.extend;
3950                 /* bug 7146755 reporting the variables l_fuel_charge_reduction and l_ days_after_fuel_wd
3951                 instead of vans_entries.van_fuel_charge_reduction and vans_entries.days_after_fuel_wd */
3952                 l_xfdf_str_tab(l_loop_count) := '<?xml version = "1.0" encoding = "UTF-8"?>
3953                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
3954                     <fields> ' ||
3955                     '<field name="'||'Employer'   ||'"><value>' ||replace(l_employer_name,'&','&')      || '</value></field>  ' ||
3956                     '<field name="'||'Employee'   ||'"><value>' ||l_full_name                               || '</value></field>  ' ||
3957                     '<field name="'||'PAYE_tax'   ||'"><value>' ||l_emp_ref_no                              || '</value></field>  ' ||
3958                     '<field name="'||'Works_no'   ||'"><value>' ||l_employee_number                         || '</value></field>  ' ||
3959                     '<field name="'||'NI_1'       ||'"><value>' ||substr(l_national_ins_no,1,1)             || '</value></field>  ' ||
3960                     '<field name="'||'NI_2'       ||'"><value>' ||substr(l_national_ins_no,2,1)             || '</value></field>  ' ||
3961                     '<field name="'||'NI_3'       ||'"><value>' ||substr(l_national_ins_no,3,1)             || '</value></field>  ' ||
3962                     '<field name="'||'NI_4'       ||'"><value>' ||substr(l_national_ins_no,4,1)             || '</value></field>  ' ||
3963                     '<field name="'||'NI_5'       ||'"><value>' ||substr(l_national_ins_no,5,1)             || '</value></field>  ' ||
3964                     '<field name="'||'NI_6'       ||'"><value>' ||substr(l_national_ins_no,6,1)             || '</value></field>  ' ||
3965                     '<field name="'||'NI_7'       ||'"><value>' ||substr(l_national_ins_no,7,1)             || '</value></field>  ' ||
3966                     '<field name="'||'NI_8'       ||'"><value>' ||substr(l_national_ins_no,8,1)             || '</value></field>  ' ||
3967                     '<field name="'||'NI_9'       ||'"><value>' ||substr(l_national_ins_no,9)               || '</value></field>  ' ||
3968                     '<field name="'||'REG_NO'     ||'"><value>' ||vans_entries.registration_number          || '</value></field>  ' ||
3969                     '<field name="'||'ONLY_VAN'   ||'"><value>' ||l_only_van                                || '</value></field>  ' ||
3970                     '<field name="'||'ONLY_VAN_Y' ||'"><value>' ||l_only_van                                || '</value></field>  ' ||
3971                     '<field name="'||'ONLY_VAN_N' ||'"><value>' ||l_only_van                                || '</value></field>  ' ||
3972                     '<field name="'||'VAN_COUNT'  ||'"><value>' ||l_vans_count                              || '</value></field>  ' ||
3973                     '<field name="'||'VAN_AFTER'  ||'"><value>' ||l_after_flag                              || '</value></field>  ' ||
3974                     '<field name="'||'VAN_A'      ||'"><value>' ||vans_entries.van_charged                  || '</value></field>  ' ||
3975                     '<field name="'||'VAN_B_FD'   ||'"><value>' ||substr(vans_entries.van_from_b,9,2)       || '</value></field>  ' ||
3976                     '<field name="'||'VAN_B_FM'   ||'"><value>' ||substr(vans_entries.van_from_b,6,2)       || '</value></field>  ' ||
3977                     '<field name="'||'VAN_B_FY'   ||'"><value>' ||substr(vans_entries.van_from_b,1,4)       || '</value></field>  ' ||
3978                     '<field name="'||'VAN_B_TD'   ||'"><value>' ||substr(vans_entries.van_to_b,9,2)         || '</value></field>  ' ||
3979                     '<field name="'||'VAN_B_TM'   ||'"><value>' ||substr(vans_entries.van_to_b,6,2)         || '</value></field>  ' ||
3980                     '<field name="'||'VAN_B_TY'   ||'"><value>' ||substr(vans_entries.van_to_b,1,4)         || '</value></field>  ' ||
3981                     '<field name="'||'VAN_B'      ||'"><value>' ||vans_entries.van_unavil_b                 || '</value></field>  ' ||
3982                     '<field name="'||'VAN_C_FD'   ||'"><value>' ||substr(vans_entries.van_from_c,9,2)       || '</value></field>  ' ||
3983                     '<field name="'||'VAN_C_FM'   ||'"><value>' ||substr(vans_entries.van_from_c,6,2)       || '</value></field>  ' ||
3984                     '<field name="'||'VAN_C_FY'   ||'"><value>' ||substr(vans_entries.van_from_c,1,4)       || '</value></field>  ' ||
3985                     '<field name="'||'VAN_C_TD'   ||'"><value>' ||substr(vans_entries.van_to_c,9,2)         || '</value></field>  ' ||
3986                     '<field name="'||'VAN_C_TM'   ||'"><value>' ||substr(vans_entries.van_to_c,6,2)         || '</value></field>  ' ||
3987                     '<field name="'||'VAN_C_TY'   ||'"><value>' ||substr(vans_entries.van_to_c,1,4)         || '</value></field>  ' ||
3988                     '<field name="'||'VAN_C'      ||'"><value>' ||vans_entries.van_unavil_c                 || '</value></field>  ' ||
3989                     '<field name="'||'VAN_D_FD'   ||'"><value>' ||substr(vans_entries.van_from_d,9,2)       || '</value></field>  ' ||
3990                     '<field name="'||'VAN_D_FM'   ||'"><value>' ||substr(vans_entries.van_from_d,6,2)       || '</value></field>  ' ||
3991                     '<field name="'||'VAN_D_FY'   ||'"><value>' ||substr(vans_entries.van_from_d,1,4)       || '</value></field>  ' ||
3992                     '<field name="'||'VAN_D_TD'   ||'"><value>' ||substr(vans_entries.van_to_d,9,2)         || '</value></field>  ' ||
3993                     '<field name="'||'VAN_D_TM'   ||'"><value>' ||substr(vans_entries.van_to_d,6,2)         || '</value></field>  ' ||
3994                     '<field name="'||'VAN_D_TY'   ||'"><value>' ||substr(vans_entries.van_to_d,1,4)         || '</value></field>  ' ||
3995                     '<field name="'||'VAN_D'      ||'"><value>' ||vans_entries.van_unavil_d                 || '</value></field>  ' ||
3996                     '<field name="'||'VAN_E'      ||'"><value>' ||vans_entries.van_tot_day_unavil           || '</value></field>  ' ||
3997                     '<field name="'||'VAN_F'      ||'"><value>' ||vans_entries.van_unavil_value             || '</value></field>  ' ||
3998                     '<field name="'||'VAN_G'      ||'"><value>' ||vans_entries.van_reduce_value             || '</value></field>  ' ||
3999                     '<field name="'||'VAN_G2'     ||'"><value>' ||vans_entries.van_reduce_value             || '</value></field>  ' ||
4000                     '<field name="'||'VAN_H'      ||'"><value>' ||vans_entries.van_sh_pcent_reduc           || '</value></field>  ' ||
4001                     '<field name="'||'VAN_J'      ||'"><value>' ||vans_entries.van_sh_reduction             || '</value></field>  ' ||
4002                     '<field name="'||'VAN_EXP'    ||'"><value>' ||vans_entries.van_explanation              || '</value></field>  ' ||
4003                     '<field name="'||'VAN_K'      ||'"><value>' ||vans_entries.van_reduce_share             || '</value></field>  ' ||
4004                     '<field name="'||'VAN_L'      ||'"><value>' ||vans_entries.van_private_uses             || '</value></field>  ' ||
4005                     '<field name="'||'VAN_M'      ||'"><value>' ||vans_entries.van_benefit_charge           || '</value></field>  ' ||
4006                     '<field name="'||'VAN_R_FD'   ||'"><value>' ||substr(vans_entries.van_fuel_withdrawn,9,2)       || '</value></field>  ' ||
4007                     '<field name="'||'VAN_R_FM'   ||'"><value>' ||substr(vans_entries.van_fuel_withdrawn,6,2)       || '</value></field>  ' ||
4008                     '<field name="'||'VAN_R_FY'   ||'"><value>' ||substr(vans_entries.van_fuel_withdrawn,1,4)       || '</value></field>  ' ||
4009                     '<field name="'||'VAN_R'      ||'"><value>' ||l_days_after_fuel_wd       || '</value></field>  ' ||
4010                     '<field name="'||'VAN_S'      ||'"><value>' ||vans_entries.van_total_days_no_fuel       || '</value></field>  ' ||
4011                     '<field name="'||'VAN_T'      ||'"><value>' ||vans_entries.van_reduction                || '</value></field>  ' ||
4012                     '<field name="'||'VAN_V'      ||'"><value>' ||l_fuel_charge_reduction    || '</value></field>  ' ||
4013                     '<field name="'||'VAN_W'      ||'"><value>' ||vans_entries.van_reduction_sharing        || '</value></field>  ' ||
4014                     '<field name="'||'VAN_X'      ||'"><value>' ||vans_entries.van_feul_ben_charge          || '</value></field>  ' ||
4015                     '</fields>  </xfdf>';
4016             end loop;
4017         end if;
4018 
4019         hr_utility.trace('10');
4020         open l_ret_ref_cursor for
4021         select *
4022         from table (cast(l_xfdf_str_tab as per_gb_xfdftableType));
4023         p_record_num := l_loop_count;
4024         return l_ret_ref_cursor;
4025    end ;
4026 
4027    function fetch_ws4_ref_cursor (p_assignment_action_id Number,
4028                                   p_record_num out nocopy NUmber) return ref_cursor_typ
4029    is
4030         -- per_gb_xfdftableType is explicitly created type
4031         -- only modification needed is it could be of type blob
4032         -- i tried thta but could not access the blob valus in java routine.
4033         -- can be sorted later
4034         l_xfdf_str_tab per_gb_xfdftableType := per_gb_xfdftableType( );
4035         l_xfdf_str varchar2(32000);
4036         l_ret_ref_cursor ref_cursor_typ;
4037         cursor csr_int_entries (p_pactid Number,
4038                                 p_person_id Number,
4039                                 p_emp_ref Varchar2 ,
4040                                 p_emp_name Varchar2)
4041         is
4042         select ACTION_INFORMATION7            Maximum_Amount_Outstanding,
4043                ' '                            Currency, -- 'GBP'Currency, -- as we currently support just GBP
4044                to_number(nvl(ACTION_INFORMATION6,'0'))  Amount_Outstanding_at_5th_Apri,
4045                to_number(nvl(ACTION_INFORMATION16,'0')) Amount_Outstanding_at_Year_End,
4046                ACTION_INFORMATION18           Official_Rate_of_Interest,
4047                ACTION_INFORMATION8            Total_Amount_of_Interest_Paid,
4048                ACTION_INFORMATION11           Cash_Equivalent,
4049                ACTION_INFORMATION19           Annual_Interest_Value,
4050                ACTION_INFORMATION20           Interest_Value,
4051                action_context_id
4052         from  pay_action_information
4053         where action_information_category = 'INT FREE AND LOW INT LOANS'
4054         and   action_context_type = 'AAP'
4055         and   action_context_id in(select paa.assignment_action_id
4056                                     from   pay_action_information pai_comp,
4057                                            pay_action_information pai_person,
4058                                            pay_assignment_actions paa,
4059                                            pay_payroll_actions ppa
4060                                     where  ppa.payroll_action_id = p_pactid
4061                                     and    paa.payroll_action_id = ppa.payroll_action_id
4062                                     and    pai_comp.action_context_id = paa.assignment_action_id
4063                                     and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
4064                                     and    pai_comp.action_context_type = 'AAP'
4065                                     and    pai_person.action_context_id = paa.assignment_action_id
4066                                     and    pai_person.action_information_category = 'ADDRESS DETAILS'
4067                                     and    pai_person.action_context_type = 'AAP'
4068                                     and    pai_person.action_information14 = 'Employee Address'
4069                                     and    pai_person.action_information1 = to_char(p_person_id)
4070                                     and    pai_comp.action_information6 = p_emp_ref
4071                                     and    pai_comp.action_information7 = p_emp_name)
4072         and   to_number(nvl(ACTION_INFORMATION11,'0')) > 0;
4073 
4074         l_emp_ref_no varchar2(150);
4075         l_employer_name varchar2(150);
4076         l_full_name varchar2(150);
4077         l_national_ins_no varchar2(150);
4078         l_employee_number varchar2(150);
4079         l_pactid number;
4080         l_person_id number;
4081         l_loop_count Number;
4082         l_field_num Number;
4083         l_tab_index Number;
4084         l_amt_sum Number;
4085         l_AMT_AS_PER_MTH Number;
4086         l_int Number;
4087         l_h_sum_max_amt_outstanding Number;
4088         l_rep_run varchar2(10);
4089         l_loan_threshold Number;
4090    begin
4091         hr_utility.trace('calling get_employer_details');
4092         get_employer_details(p_assignment_action_id,
4093                              l_emp_ref_no,
4094                              l_employer_name);
4095         hr_utility.trace('calling get_employee_details');
4096         get_employee_details(p_assignment_action_id,
4097                              l_full_name,
4098                              l_national_ins_no,
4099                              l_employee_number);
4100         l_pactid := get_pactid(p_assignment_action_id);
4101         l_person_id := get_person_id (p_assignment_action_id );
4102         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
4103          p_payroll_action_id           => l_pactid,
4104          p_token_name                  => 'Rep_Run',
4105          p_token_value                 => l_rep_run);
4106 
4107         l_loop_count := 0;
4108         hr_utility.trace('l_pactid ' || l_pactid);
4109         hr_utility.trace('l_person_id '|| l_person_id);
4110         hr_utility.trace('l_emp_ref_no '|| l_emp_ref_no);
4111         hr_utility.trace('l_employer_name '|| l_employer_name);
4112         l_tab_index := 0;
4113 
4114         select to_number(nvl(ACTION_INFORMATION23,'0'))
4115         into  l_h_sum_max_amt_outstanding
4116         from  pay_action_information pai_emp
4117         where pai_emp.action_context_id = p_assignment_action_id
4118         and   pai_emp.action_information_category = 'GB P11D ASSIGNMENT RESULTC';
4119 
4120         if to_number(l_rep_run) < 2007 then
4121            l_loan_threshold := 5000;
4122         else
4123            -- Fetch the minimum outstanding
4124            select to_number(global_value)
4125            into  l_loan_threshold
4126            from  ff_globals_f
4127            where global_name = 'P11D_LOW_INT_LOAN_THRESHOLD'
4128            and   to_date('05-04-' || l_rep_run,'DD-MM-YYYY') between effective_start_date and effective_end_date;
4129         end if;
4130 
4131         if l_h_sum_max_amt_outstanding > l_loan_threshold
4132         then
4133             for int_entries in  csr_int_entries(l_pactid,
4134                                                 l_person_id,
4135                                                 l_emp_ref_no,
4136                                                 l_employer_name)
4137             loop
4138                 l_employee_number := get_assignment_number(int_entries.action_context_id);
4139                 l_loop_count := l_loop_count+1;
4140                 hr_utility.trace('l_loop_count '  ||l_loop_count);
4141                 --we need 5 records in a single pdf template so if more than 5 exists
4142                 --we need extra pages ceil(l_loop_count/5) will give the index number
4143                 --for the l_ws4_info_tab
4144                 if l_tab_index =ceil(l_loop_count/5)
4145                 then
4146                     -- means same template input
4147                       null;
4148                 else -- new template input
4149                     if l_tab_index <> 0 then
4150                        -- this will end the first tempalet input.
4151                        l_xfdf_str_tab(l_tab_index) := l_xfdf_str_tab(l_tab_index) || '</fields>  </xfdf>';
4152                     end if;
4153                     -- assign the new index number of the template
4154                     l_tab_index := ceil(l_loop_count/5);
4155                     l_xfdf_str_tab.extend;
4156                     l_xfdf_str_tab(l_tab_index) := '<?xml version = "1.0" encoding = "UTF-8"?>
4157                         <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
4158                         <fields> ' ||
4159                         '<field name="'||'EMPLOYERS_NAME'||'"><value>' ||replace(l_employer_name,'&','&')  || '</value></field> ' ||
4160                         '<field name="'||'FULL_NAME'||'"><value>' ||l_full_name || '</value></field>  ' ||
4161                         '<field name="'||'EMPLOYERS_REF_NO'||'"><value>' ||l_emp_ref_no || '</value></field>  ' ||
4162                         '<field name="'||'EMPLOYEE_NUMBER'||'"><value>' ||l_employee_number || '</value></field>  ' ||
4163                         '<field name="'||'NI_1'||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
4164                         '<field name="'||'NI_2'||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
4165                         '<field name="'||'NI_3'||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
4166                         '<field name="'||'NI_4'||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
4167                         '<field name="'||'NI_5'||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
4168                         '<field name="'||'NI_6'||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
4169                         '<field name="'||'NI_7'||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
4170                         '<field name="'||'NI_8'||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
4171                         '<field name="'||'NI_9'||'"><value>' ||substr(l_national_ins_no,9) || '</value></field>  ' ;
4172                 end if;
4173                 hr_utility.trace('l_tab_index '  ||l_tab_index);
4174                 l_field_num := mod(l_loop_count,5);
4175                 if l_field_num = 0
4176                 then
4177                     l_field_num := 5;
4178                 end if;
4179                 hr_utility.trace('l_field_num '  ||l_field_num);
4180                 l_xfdf_str_tab(l_tab_index) :=  l_xfdf_str_tab(l_tab_index)  ||
4181                     '<field name="'||'MAX_OUT_'  || l_field_num ||'"><value>' ||int_entries.Maximum_Amount_Outstanding || '</value></field>  ' ||
4182                     '<field name="'||'CURRENCY_' || l_field_num ||'"><value>' ||int_entries.Currency || '</value></field>  ' ||
4183                     '<field name="'||'AMT_YRST_' || l_field_num ||'"><value>' ||int_entries.Amount_Outstanding_at_5th_Apri || '</value></field>  ' ||
4184                     '<field name="'||'AMT_YREND_'|| l_field_num ||'"><value>' ||int_entries.Amount_Outstanding_at_Year_End || '</value></field>  ' ;
4185                 l_amt_sum   :=  nvl(int_entries.Amount_Outstanding_at_5th_Apri,0) +
4186                                 nvl(int_entries.Amount_Outstanding_at_Year_End,0);
4187                 l_xfdf_str_tab(l_tab_index) :=        l_xfdf_str_tab(l_tab_index)  ||
4188                     '<field name="'||'AMT_SUM_'  || l_field_num ||'"><value>' ||l_amt_sum || '</value></field>  ' ||
4189                     '<field name="'||'AMT_AVG_'  || l_field_num ||'"><value>' ||(l_amt_sum/2) || '</value></field>  ' ||
4190                     '<field name="'||'TAX_MTH_'  || l_field_num ||'"><value>' ||(int_entries.Interest_Value) || '</value></field>  ' ;
4191                 l_AMT_AS_PER_MTH := (l_amt_sum/2)*(int_entries.Interest_Value/12);
4192                 l_xfdf_str_tab(l_tab_index) := l_xfdf_str_tab(l_tab_index)  ||
4193                     '<field name="'||'ACT_MTH_'|| l_field_num ||'"><value>' ||l_AMT_AS_PER_MTH || '</value></field>  ' ||
4194                     '<field name="'||'RATE_'   || l_field_num ||'"><value>' ||int_entries.Official_Rate_of_Interest || '</value></field>  ' ;
4195                 l_int := round(l_AMT_AS_PER_MTH *int_entries.Official_Rate_of_Interest/100,2);
4196                 l_xfdf_str_tab(l_tab_index) := l_xfdf_str_tab(l_tab_index)  ||
4197                     '<field name="'||'INT_'     || l_field_num ||'"><value>' ||l_int || '</value></field>  ' ||
4198                     '<field name="'||'EMP_INT_' || l_field_num ||'"><value>' ||int_entries.Total_Amount_of_Interest_Paid || '</value></field>  ' ||
4199                     '<field name="'||'CE_'      || l_field_num ||'"><value>' ||int_entries.Cash_Equivalent || '</value></field>  ' ;
4200             end loop;
4201         -- this will ensure the xfdf sytring ends with the correct fields
4202         end if;
4203         hr_utility.trace('After cursor close');
4204         hr_utility.trace('l_tab_index' || l_tab_index);
4205         if l_tab_index <> 0
4206         then
4207             l_xfdf_str_tab(l_tab_index) := l_xfdf_str_tab(l_tab_index) || '</fields>  </xfdf>';
4208         end if;
4209         open l_ret_ref_cursor for
4210         select *
4211         from table (cast(l_xfdf_str_tab as per_gb_xfdftableType));
4212         p_record_num := l_tab_index;
4213         return l_ret_ref_cursor;
4214    end ;
4215 
4216    function fetch_ws5_data_blob (p_assignment_action_id Number) return blob
4217    is
4218         l_xfdf_str clob;
4219         l_xfdf_blob_str blob;
4220         cursor csr_relocation_entries(p_pactid Number,
4221                                       p_person_id Number,
4222                                       p_emp_ref Varchar2 ,
4223                                       p_emp_name Varchar2)
4224         is
4225         select
4226               to_char(to_number(nvl(pai_ben.action_information9,0)),'FM999,999,990.00') GROSS_AMOUNT,
4227               to_char(to_number(nvl(pai_ben.action_information10,0)),'FM999,999,990.00') COST,
4228               to_char(to_number(nvl(pai_ben.action_information11,0)),'FM999,999,990.00') PAID_BY_EMPLOYEE,
4229               to_char(to_number(nvl(pai_ben.action_information10,0) - nvl(pai_ben.action_information11,0)),'FM999,999,990.00')QUALIFYING_BENEFITS,
4230               to_char(to_number(nvl(pai_ben.action_information13,0)),'FM999,999,990.00') COST_OF_ACCO,
4231               to_char(to_number(nvl(pai_ben.action_information9,0) + nvl(pai_ben.action_information13,0) +
4232               nvl(pai_ben.action_information10,0) - nvl(pai_ben.action_information11,0)),
4233                     'FM999,999,990.00') TOTAL,
4234               to_char(to_number(nvl(pai_ben.action_information14,0)),'FM999,999,990.00') EARLIER_YEARS,
4235               to_char(to_number(nvl(pai_ben.action_information15,0)),'FM999,999,990.00') AMOUNT_EXEMPTED,
4236               to_char(to_number(nvl(pai_ben.action_information5,0)),'FM999,999,990.00') FINAL_AMOUNT,
4237               action_context_id
4238         from  pay_action_information pai_ben
4239         where pai_ben.action_information_category = 'RELOCATION EXPENSES'
4240         and   pai_ben.action_context_type = 'AAP'
4241         and   pai_ben.action_context_id in ( select paa.assignment_action_id
4242                                              from   pay_action_information pai_comp,
4243                                                     pay_action_information pai_person,
4244                                                     pay_assignment_actions paa,
4245                                                     pay_payroll_actions ppa
4246                                              where  ppa.payroll_action_id = p_pactid
4247                                              and    paa.payroll_action_id = ppa.payroll_action_id
4248                                              and    pai_comp.action_context_id = paa.assignment_action_id
4249                                              and    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
4250                                              and    pai_comp.action_context_type = 'AAP'
4251                                              and    pai_person.action_context_id = paa.assignment_action_id
4252                                              and    pai_person.action_information_category = 'ADDRESS DETAILS'
4253                                              and    pai_person.action_context_type = 'AAP'
4254                                              and    pai_person.action_information14 = 'Employee Address'
4255                                              and    pai_person.action_information1 = to_char(p_person_id)
4256                                              and    pai_comp.action_information6 = p_emp_ref
4257                                              and    pai_comp.action_information7 = p_emp_name);
4258         l_emp_ref_no varchar2(150);
4259         l_employer_name varchar2(150);
4260         l_full_name varchar2(150);
4261         l_national_ins_no varchar2(150);
4262         l_employee_number varchar2(150);
4263         l_pactid number;
4264         l_person_id number;
4265         l_loop_count Number;
4266    begin
4267         get_employer_details(p_assignment_action_id,
4268                              l_emp_ref_no,
4269                              l_employer_name);
4270         get_employee_details(p_assignment_action_id,
4271                              l_full_name,
4272                              l_national_ins_no,
4273                              l_employee_number);
4274         l_pactid := get_pactid(p_assignment_action_id);
4275         l_person_id := get_person_id (p_assignment_action_id );
4276         l_loop_count := 0;
4277         dbms_lob.createtemporary(l_xfdf_str,false,DBMS_LOB.CALL);
4278         dbms_lob.open(l_xfdf_str,dbms_lob.lob_readwrite);
4279         for relocation_entries in  csr_relocation_entries(l_pactid,
4280                                                           l_person_id,
4281                                                           l_emp_ref_no,
4282                                                           l_employer_name)
4283         loop
4284             l_employee_number := get_assignment_number(relocation_entries.action_context_id);
4285             l_loop_count := l_loop_count+1;
4286             if l_loop_count = 1
4287             then
4288                 dbms_lob.writeAppend( l_xfdf_str,
4289                 length(
4290                 '<?xml version = "1.0" encoding = "UTF-8"?>
4291                  <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
4292                  <fields> ' ||
4293                 '<field name="'||'EMPLOYERS_NAME'   ||'"><value>' ||replace(l_employer_name,'&','&')  ||'</value></field> ' ||
4294                 '<field name="'||'FULL_NAME'        ||'"><value>' ||l_full_name                   || '</value></field>  ' ||
4295                 '<field name="'||'EMPLOYERS_REF_NO' ||'"><value>' ||l_emp_ref_no                  || '</value></field>  ' ||
4296                 '<field name="'||'EMPLOYEE_NUMBER'  ||'"><value>' ||l_employee_number             || '</value></field>  ' ||
4297                 '<field name="'||'NI_1'             ||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
4298                 '<field name="'||'NI_2'             ||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
4299                 '<field name="'||'NI_3'             ||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
4300                 '<field name="'||'NI_4'             ||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
4301                 '<field name="'||'NI_5'             ||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
4302                 '<field name="'||'NI_6'             ||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
4303                 '<field name="'||'NI_7'             ||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
4304                 '<field name="'||'NI_8'             ||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
4305                 '<field name="'||'NI_9'             ||'"><value>' ||substr(l_national_ins_no,9)   || '</value></field>  '),
4306                 '<?xml version = "1.0" encoding = "UTF-8"?>
4307                  <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
4308                  <fields> ' ||
4309                 '<field name="'||'EMPLOYERS_NAME'   ||'"><value>' ||replace(l_employer_name,'&','&')  ||'</value></field> ' ||
4310                 '<field name="'||'FULL_NAME'        ||'"><value>' ||l_full_name                   || '</value></field>  ' ||
4311                 '<field name="'||'EMPLOYERS_REF_NO' ||'"><value>' ||l_emp_ref_no                  || '</value></field>  ' ||
4312                 '<field name="'||'EMPLOYEE_NUMBER'  ||'"><value>' ||l_employee_number             || '</value></field>  ' ||
4313                 '<field name="'||'NI_1'             ||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
4314                 '<field name="'||'NI_2'             ||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
4315                 '<field name="'||'NI_3'             ||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
4316                 '<field name="'||'NI_4'             ||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
4317                 '<field name="'||'NI_5'             ||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
4318                 '<field name="'||'NI_6'             ||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
4319                 '<field name="'||'NI_7'             ||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
4320                 '<field name="'||'NI_8'             ||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
4321                 '<field name="'||'NI_9'             ||'"><value>' ||substr(l_national_ins_no,9)   || '</value></field>  ');
4322             end if;
4323             dbms_lob.writeAppend( l_xfdf_str,
4324             length(
4325             '<field name="'||'GROSS_AMOUNT'       ||'"><value>' ||relocation_entries.GROSS_AMOUNT        || '</value></field>  ' ||
4326             '<field name="'||'COST'               ||'"><value>' ||relocation_entries.COST                || '</value></field>  ' ||
4327             '<field name="'||'PAID_BY_EMPLOYEE'   ||'"><value>' ||relocation_entries.PAID_BY_EMPLOYEE    || '</value></field>  ' ||
4328             '<field name="'||'QUALIFYING_BENEFITS'||'"><value>' ||relocation_entries.QUALIFYING_BENEFITS || '</value></field>  ' ||
4329             '<field name="'||'COST_OF_ACCO'       ||'"><value>' ||relocation_entries.COST_OF_ACCO        || '</value></field>  ' ||
4330             '<field name="'||'TOTAL'              ||'"><value>' ||relocation_entries.TOTAL               || '</value></field>  ' ||
4331             '<field name="'||'EARLIER_YEARS'      ||'"><value>' ||relocation_entries.EARLIER_YEARS       || '</value></field>  ' ||
4332             '<field name="'||'AMOUNT_EXEMPTED'    ||'"><value>' ||relocation_entries.AMOUNT_EXEMPTED     || '</value></field>  ' ||
4333             '<field name="'||'FINAL_AMOUNT'       ||'"><value>' ||relocation_entries.FINAL_AMOUNT        || '</value></field>  '),
4334             '<field name="'||'GROSS_AMOUNT'       ||'"><value>' ||relocation_entries.GROSS_AMOUNT        || '</value></field>  ' ||
4335             '<field name="'||'COST'               ||'"><value>' ||relocation_entries.COST                || '</value></field>  ' ||
4336             '<field name="'||'PAID_BY_EMPLOYEE'   ||'"><value>' ||relocation_entries.PAID_BY_EMPLOYEE    || '</value></field>  ' ||
4337             '<field name="'||'QUALIFYING_BENEFITS'||'"><value>' ||relocation_entries.QUALIFYING_BENEFITS || '</value></field>  ' ||
4338             '<field name="'||'COST_OF_ACCO'       ||'"><value>' ||relocation_entries.COST_OF_ACCO        || '</value></field>  ' ||
4339             '<field name="'||'TOTAL'              ||'"><value>' ||relocation_entries.TOTAL               || '</value></field>  ' ||
4340             '<field name="'||'EARLIER_YEARS'      ||'"><value>' ||relocation_entries.EARLIER_YEARS       || '</value></field>  ' ||
4341             '<field name="'||'AMOUNT_EXEMPTED'    ||'"><value>' ||relocation_entries.AMOUNT_EXEMPTED     || '</value></field>  ' ||
4342             '<field name="'||'FINAL_AMOUNT'       ||'"><value>' ||relocation_entries.FINAL_AMOUNT        || '</value></field>  ');
4343         end loop;
4344         if l_loop_count <> 0
4345         then
4346             dbms_lob.writeAppend( l_xfdf_str,length('</fields>  </xfdf>'),'</fields>  </xfdf>');
4347         end if;
4348         DBMS_LOB.CREATETEMPORARY(l_xfdf_blob_str,true);
4349         clob_to_blob(l_xfdf_str,l_xfdf_blob_str);
4350         dbms_lob.close(l_xfdf_str);
4351         dbms_lob.freetemporary(l_xfdf_str);
4352         return  l_xfdf_blob_str;
4353    end;
4354 
4355    function fetch_ws6_ref_cursor (p_assignment_action_id Number,
4356                                   p_record_num out nocopy NUmber) return ref_cursor_typ
4357    is
4358         -- per_gb_xfdftableType is explicitly created type
4359         -- only modification needed is it could be of type blob
4360         -- i tried thta but could not access the blob valus in java routine.
4361         -- can be sorted later
4362         l_xfdf_str_tab per_gb_xfdftableType := per_gb_xfdftableType( );
4363         l_xfdf_str varchar2(32000);
4364         l_ret_ref_cursor ref_cursor_typ;
4365         l_offset integer;
4366         l_varchar_buffer varchar2(32000);
4367         l_raw_buffer raw(32000);
4368         l_buffer_len number:= 32000;
4369         l_chunk_len number;
4370 
4371         cursor csr_amap_entries (p_pactid Number,
4372                                  p_person_id Number,
4373                                  p_emp_ref Varchar2 ,
4374                                  p_emp_name Varchar2)
4375         is
4376         select nvl(ACTION_INFORMATION12,0)  C_MILEAGE_ALLOW_PAYMENTS,
4377                nvl(ACTION_INFORMATION13,0)  B_MILEAGE_ALLOW_PAYMENTS,
4378                nvl(ACTION_INFORMATION14,0)  M_MILEAGE_ALLOW_PAYMENTS,
4379                nvl(ACTION_INFORMATION16,0)  C_TAX_DEDUCTED_PAYMENTS,
4380                nvl(ACTION_INFORMATION17,0)  B_TAX_DEDUCTED_PAYMENTS,
4381                nvl(ACTION_INFORMATION18,0)  M_TAX_DEDUCTED_PAYMENTS,
4382                (nvl(ACTION_INFORMATION12,0) - nvl(ACTION_INFORMATION16,0)) C_NET_ALLOWANCE,
4383                (nvl(ACTION_INFORMATION13,0) - nvl(ACTION_INFORMATION17,0)) B_NET_ALLOWANCE,
4384                (nvl(ACTION_INFORMATION14,0) - nvl(ACTION_INFORMATION18,0)) M_NET_ALLOWANCE,
4385                nvl(ACTION_INFORMATION1,0)  C_BUSINESS_MILES,
4386                nvl(ACTION_INFORMATION2,0)  M_BUSINESS_MILES,
4387                nvl(ACTION_INFORMATION3,0)  B_BUSINESS_MILES,
4388                nvl(ACTION_INFORMATION4,0) c_reimbursement_rate1,
4389                nvl(ACTION_INFORMATION6,0) m_reimbursement_rate1,
4390                nvl(ACTION_INFORMATION8,0) b_reimbursement_rate1,
4391                nvl(ACTION_INFORMATION5,0) c_reimbursement_rate2,
4392                nvl(ACTION_INFORMATION7,0) m_reimbursement_rate2,
4393                nvl(ACTION_INFORMATION9,0) b_reimbursement_rate2,
4394                nvl(ACTION_INFORMATION19,0) PASSEN_PAYMENTS,
4395                nvl(ACTION_INFORMATION20,0) PASSEN_BUSINESS_MILES,
4396                nvl(ACTION_INFORMATION21,0) PASSENGER_BUS_MILES_AMOUNT
4397         from pay_action_information
4398         where action_information_category = 'GB P11D ASSIGNMENT RESULTC'
4399         and   action_context_type = 'AAP'
4400         and   action_context_id = p_assignment_action_id;/*Removed sub query for assignment action id*/
4401 
4402         l_emp_ref_no varchar2(150);
4403         l_employer_name varchar2(150);
4404         l_full_name varchar2(150);
4405         l_national_ins_no varchar2(150);
4406         l_employee_number varchar2(150);
4407         l_pactid number;
4408         l_rep_run  varchar2(10);
4409         l_person_id number;
4410         type ws6_info_rec_typ is record (
4411           l_net_allowance Varchar2(20),
4412           l_bus_mile_1_amount Varchar2(20),
4413           l_bus_mile_2_amount Varchar2(20),
4414           l_total_tax_payment Varchar2(20),
4415           l_vehiclecheck      Varchar2(10),
4416           l_taxable_passen_payment Number,
4417           l_total_payment    Number,
4418           l_total_approved_maps Varchar2(20),
4419           l_business_miles_1 Number,
4420           l_business_miles_2 Number,
4421           l_c_mileage_allow_payments Number,
4422           l_c_tax_deducted_payments Number,
4423           l_c_business_miles    Number,
4424           l_c_reimbrs1_rate1   Number,
4425           l_c_reimbrs2_rate2   Number,
4426           l_c_net_allowance Number,
4427           l_passen_payments Number,
4428           l_passenger_bus_miles_amount  Number,
4429           l_passen_business_miles   Number);
4430 
4431         type ws6_info_rec_tab_typ is table of ws6_info_rec_typ index by Binary_integer;
4432         l_ws6_info_tab ws6_info_rec_tab_typ;
4433         l_loop_count Number;
4434         l_sum_PASSEN_PAYMENTS Varchar2(15);
4435         l_sum_PASSEN_BUSINESS_MILES Varchar2(15);
4436         l_sum_PASS_BUS_MILES_AMOUNT Varchar2(15);
4437         l_sum_Taxable_passen_payments Varchar2(15);
4438         l_miles1 Number :=0;
4439         l_miles2 Number :=0;
4440         l_mile1_amount Number :=0;
4441         l_mile2_amount Number :=0;
4442         l_Carvan  Varchar2(5);
4443         l_MCycle  Varchar2(5);
4444         l_BCycle  Varchar2(5);
4445         l_cnt     Number:=0;
4446    begin
4447         get_employer_details(p_assignment_action_id,
4448                              l_emp_ref_no,
4449                              l_employer_name);
4450         get_employee_details(p_assignment_action_id,
4451                              l_full_name,
4452                              l_national_ins_no,
4453                              l_employee_number);
4454         l_pactid := get_pactid(p_assignment_action_id);
4455         l_person_id := get_person_id (p_assignment_action_id );
4456         l_employee_number := get_assignment_number(p_assignment_action_id,true,l_person_id,l_emp_ref_no);
4457         l_loop_count := 0;
4458         l_sum_PASSEN_PAYMENTS := 0;
4459         l_sum_PASSEN_BUSINESS_MILES := 0;
4460         l_sum_PASS_BUS_MILES_AMOUNT := 0;
4461         l_sum_Taxable_passen_payments:=0;
4462 
4463         for amap_entries in  csr_amap_entries(l_pactid,
4464                                               l_person_id,
4465                                               l_emp_ref_no,
4466                                               l_employer_name)
4467         loop
4468             l_Carvan := '';
4469             l_BCycle := '';
4470             l_MCycle := '';
4471             l_cnt    := 0;
4472             if amap_entries.C_BUSINESS_MILES > 0
4473             then
4474                 l_cnt := l_cnt + 1;
4475                 l_Carvan := 'CAR';
4476             end if;
4477             if amap_entries.M_BUSINESS_MILES > 0
4478             then
4479                 l_cnt := l_cnt + 1;
4480                 l_MCycle := 'MCY';
4481             end if;
4482             if amap_entries.B_BUSINESS_MILES > 0
4483             then
4484                 l_cnt := l_cnt + 1;
4485                 l_BCycle := 'BCY';
4486             end if;
4487             for i in 1 .. l_cnt
4488             loop
4489                 l_loop_count := l_loop_count+1;
4490                 -- l_ws6_info_tab(l_loop_count).l_amap_entries := amap_entries;
4491                 -- hardcoding 10000, as currently this si the fig,
4492                 -- if this changes then we may archve max limit as well.
4493                 HR_UTILITY.TRaCE('A');
4494                 if l_BCycle = 'BCY'
4495                 then
4496                     l_ws6_info_tab(l_loop_count).l_c_mileage_allow_payments := amap_entries.B_MILEAGE_ALLOW_PAYMENTS;
4497                     l_ws6_info_tab(l_loop_count).l_c_tax_deducted_payments  := amap_entries.B_TAX_DEDUCTED_PAYMENTS;
4498                     l_ws6_info_tab(l_loop_count).l_c_net_allowance          := amap_entries.B_NET_ALLOWANCE;
4499                     l_ws6_info_tab(l_loop_count).l_c_business_miles         := amap_entries.B_BUSINESS_MILES;
4500                     l_ws6_info_tab(l_loop_count).l_c_reimbrs1_rate1    := amap_entries.b_reimbursement_rate1;
4501                     l_ws6_info_tab(l_loop_count).l_c_reimbrs2_rate2    := amap_entries.b_reimbursement_rate2;
4502                     l_ws6_info_tab(l_loop_count).l_vehiclecheck           := 'B';
4503                     l_BCycle := '';
4504                 elsif l_MCycle = 'MCY'
4505                 then
4506                     l_ws6_info_tab(l_loop_count).l_c_mileage_allow_payments := amap_entries.M_MILEAGE_ALLOW_PAYMENTS;
4507                     l_ws6_info_tab(l_loop_count).l_c_tax_deducted_payments  := amap_entries.M_TAX_DEDUCTED_PAYMENTS;
4508                     l_ws6_info_tab(l_loop_count).l_c_net_allowance          := amap_entries.M_NET_ALLOWANCE;
4509                     l_ws6_info_tab(l_loop_count).l_c_business_miles       := amap_entries.M_BUSINESS_MILES;
4510                     l_ws6_info_tab(l_loop_count).l_c_reimbrs1_rate1  := amap_entries.m_reimbursement_rate1;
4511                     l_ws6_info_tab(l_loop_count).l_c_reimbrs2_rate2    := amap_entries.m_reimbursement_rate2;
4512                     l_ws6_info_tab(l_loop_count).l_vehiclecheck           := 'M';
4513                     l_MCycle := '';
4514                 elsif l_Carvan = 'CAR'
4515                 then
4516                     l_ws6_info_tab(l_loop_count).l_c_mileage_allow_payments := amap_entries.C_MILEAGE_ALLOW_PAYMENTS;
4517                     l_ws6_info_tab(l_loop_count).l_c_tax_deducted_payments := amap_entries.C_TAX_DEDUCTED_PAYMENTS;
4518                     l_ws6_info_tab(l_loop_count).l_c_net_allowance       := amap_entries.C_NET_ALLOWANCE;
4519                     l_ws6_info_tab(l_loop_count).l_c_business_miles      := amap_entries.C_BUSINESS_MILES;
4520                     l_ws6_info_tab(l_loop_count).l_c_reimbrs1_rate1    := amap_entries.c_reimbursement_rate1;
4521                     l_ws6_info_tab(l_loop_count).l_c_reimbrs2_rate2    :=  amap_entries.c_reimbursement_rate2;
4522                     l_ws6_info_tab(l_loop_count).l_vehiclecheck           := 'C';
4523                     l_Carvan :='';
4524                 end if;
4525                 l_ws6_info_tab(l_loop_count).l_passen_payments := amap_entries.PASSEN_PAYMENTS;
4526                 l_ws6_info_tab(l_loop_count).l_passenger_bus_miles_amount := amap_entries.PASSENGER_BUS_MILES_AMOUNT;
4527                 l_ws6_info_tab(l_loop_count).l_passen_business_miles := amap_entries.PASSEN_BUSINESS_MILES;
4528                 -- l_ws6_info_tab(l_loop_count).l_amap_entries.Taxable_payments := 0;
4529                 l_mile1_amount  :=0;
4530                 l_mile2_amount :=0;
4531                 if l_ws6_info_tab(l_loop_count).l_c_business_miles > 10000
4532                 then
4533                     l_miles1 := 10000;
4534                     HR_UTILITY.TRaCE('B');
4535                     l_miles2 := l_ws6_info_tab(l_loop_count).l_c_business_miles - 10000;
4536                 else
4537                     HR_UTILITY.TRaCE('C');
4538                     l_miles1 := l_ws6_info_tab(l_loop_count).l_c_business_miles;
4539                     l_miles2 := 0;
4540                 end if;
4541                 HR_UTILITY.TRaCE('D');
4542                 l_mile1_amount := l_ws6_info_tab(l_loop_count).l_c_reimbrs1_rate1 * l_miles1;
4543                 l_mile2_amount := l_ws6_info_tab(l_loop_count).l_c_reimbrs2_rate2 * l_miles2;
4544                 l_ws6_info_tab(l_loop_count).l_bus_mile_1_amount:= to_char(to_number(l_mile1_amount),'FM999,999,990.00');
4545                 HR_UTILITY.TRaCE('E');
4546                 l_ws6_info_tab(l_loop_count).l_bus_mile_2_amount:= to_char(to_number(l_mile2_amount),'FM999,999,990.00');
4547                 l_ws6_info_tab(l_loop_count).l_total_approved_maps:= to_char(to_number((l_mile1_amount+l_mile2_amount)),'FM999,999,990.00');
4548                 HR_UTILITY.TRaCE('EE');
4549                 l_ws6_info_tab(l_loop_count).l_total_payment :=
4550                    greatest(l_ws6_info_tab(l_loop_count).l_c_net_allowance -l_mile1_amount -  l_mile2_amount,0);
4551                 HR_UTILITY.TRaCE('FF');
4552                 l_ws6_info_tab(l_loop_count).l_business_miles_1:= l_miles1;
4553                 l_ws6_info_tab(l_loop_count).l_business_miles_2:= l_miles2;
4554                 --hr_uitility.trace('gg');
4555                 l_ws6_info_tab(l_loop_count).l_taxable_passen_payment :=
4556                    greatest(l_ws6_info_tab(l_loop_count).l_passen_payments -
4557                    l_ws6_info_tab(l_loop_count).l_passenger_bus_miles_amount,0);
4558                 l_ws6_info_tab(l_loop_count).l_total_tax_payment:=
4559                    to_char(to_number((l_ws6_info_tab(l_loop_count).l_total_payment +
4560                    l_ws6_info_tab(l_loop_count).l_taxable_passen_payment)),'FM999,999,990.00');
4561             end loop;
4562         end loop;
4563 
4564         for i in 1 .. l_loop_count
4565         loop
4566             if l_loop_count > 1 and i <> 1
4567             then
4568                 l_ws6_info_tab(i).l_passen_payments := 0;
4569                 l_ws6_info_tab(i).l_passen_business_miles :=0;
4570                 l_ws6_info_tab(i).l_passenger_bus_miles_amount :=0;
4571                 l_ws6_info_tab(i).l_taxable_passen_payment :=0;
4572                 -- l_ws6_info_tab(i).l_total_tax_payment := to_char(to_number(l_ws6_info_tab(i).l_total_tax_payment ),'FM999,999,990.00');
4573                 l_ws6_info_tab(i).l_total_tax_payment := to_char(to_number(l_ws6_info_tab(l_loop_count).l_total_payment),'FM999,999,990.00');
4574             end if;
4575         end loop;
4576         for i in 1 .. l_loop_count
4577         loop
4578             l_xfdf_str_tab.extend;
4579             l_xfdf_str_tab(i) := '<?xml version = "1.0" encoding = "UTF-8"?>
4580                 <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
4581                 <fields> ' ||
4582                 '<field name="'||'Employer'||'"><value>' ||replace(l_employer_name,'&','&')  || '</value></field> ' ||
4583                 '<field name="'||'Employee'||'"><value>' ||l_full_name || '</value></field>  ' ||
4584                 '<field name="'||'PAYE_tax'||'"><value>' ||l_emp_ref_no || '</value></field>  ' ||
4585                 '<field name="'||'Works_no'||'"><value>' ||l_employee_number || '</value></field>  ' ||
4586                 --'<field name="'||'Nat_Ins_Num'||'"><value>' ||l_national_ins_no || '</value></field>  ' ||
4587                 '<field name="'||'NI_1'||'"><value>' ||substr(l_national_ins_no,1,1) || '</value></field>  ' ||
4588                 '<field name="'||'NI_2'||'"><value>' ||substr(l_national_ins_no,2,1) || '</value></field>  ' ||
4589                 '<field name="'||'NI_3'||'"><value>' ||substr(l_national_ins_no,3,1) || '</value></field>  ' ||
4590                 '<field name="'||'NI_4'||'"><value>' ||substr(l_national_ins_no,4,1) || '</value></field>  ' ||
4591                 '<field name="'||'NI_5'||'"><value>' ||substr(l_national_ins_no,5,1) || '</value></field>  ' ||
4592                 '<field name="'||'NI_6'||'"><value>' ||substr(l_national_ins_no,6,1) || '</value></field>  ' ||
4593                 '<field name="'||'NI_7'||'"><value>' ||substr(l_national_ins_no,7,1) || '</value></field>  ' ||
4594                 '<field name="'||'NI_8'||'"><value>' ||substr(l_national_ins_no,8,1) || '</value></field>  ' ||
4595                 '<field name="'||'NI_9'||'"><value>' ||substr(l_national_ins_no,9) || '</value></field>  '  ||
4596                 '<field name="'||'Mileage'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_c_mileage_allow_payments),'FM999,999,990.00') || '</value></field>  ' ||
4597                 '<field name="'||'Mileage_2'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_c_tax_deducted_payments),'FM999,999,990.00') || '</value></field>  ' ||
4598                 '<field name="'||'Mileage_3'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_c_net_allowance),'FM999,999,990.00') || '</value></field>  ' ||
4599                 '<field name="'||'VehicleCheck'||'"><value>' || l_ws6_info_tab(i).l_vehiclecheck  || '</value></field>  ' ||
4600                 '<field name="'||'VehicleCheck_C'||'"><value>' || l_ws6_info_tab(i).l_vehiclecheck  || '</value></field>  ' ||
4601                 '<field name="'||'VehicleCheck_M'||'"><value>' || l_ws6_info_tab(i).l_vehiclecheck  || '</value></field>  ' ||
4602                 '<field name="'||'VehicleCheck_B'||'"><value>' || l_ws6_info_tab(i).l_vehiclecheck  || '</value></field>  ' ||
4603                 '<field name="'||'MilesTravelledBox'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_c_business_miles),'FM999,999,990.00')  || '</value></field>  ' ||
4604                 '<field name="'||'Rates'||'"><value>'   || l_ws6_info_tab(i).l_c_reimbrs1_rate1 * 100  || '</value></field>  ' ||
4605                 '<field name="'||'Rates_2'||'"><value>' || l_ws6_info_tab(i).l_c_reimbrs2_rate2 * 100  || '</value></field>  ' ||
4606                 '<field name="'||'Rates_3'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_business_miles_1),'FM999,999,990.00') || '</value></field>  ' ||
4607                 '<field name="'||'Rates_4'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_business_miles_2),'FM999,999,990.00') || '</value></field>  ' ||
4608                 '<field name="'||'4A'||'"><value>' ||l_ws6_info_tab(i).l_bus_mile_1_amount || '</value></field>  ' ||
4609                 '<field name="'||'4B'||'"><value>' ||l_ws6_info_tab(i).l_bus_mile_2_amount || '</value></field>  ' ||
4610                 '<field name="'||'4C'||'"><value>' ||l_ws6_info_tab(i).l_total_approved_maps || '</value></field>  ' ||
4611                 '<field name="'||'Payments'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_passen_payments),'FM999,999,990.00') || '</value></field>  ' ||
4612                 '<field name="'||'Payments_1'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_passen_business_miles),'FM999,999,990.00') || '</value></field>  ' ||
4613                 '<field name="'||'5M'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_passenger_bus_miles_amount),'FM999,999,990.00') || '</value></field>  ' ||
4614                 '<field name="'||'Taxable'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_total_payment),'FM999,999,990.00') || '</value></field>  ' ||
4615                 '<field name="'||'Taxable_1'||'"><value>' ||to_char(to_number(l_ws6_info_tab(i).l_taxable_passen_payment),'FM999,999,990.00') || '</value></field>  ' ||
4616                 '<field name="'||'Taxable_2'||'"><value>' ||l_ws6_info_tab(i).l_total_tax_payment || '</value></field>  ' ||
4617                 '</fields>  </xfdf>';
4618         end loop;
4619         open l_ret_ref_cursor for
4620         select *
4621         from table (cast(l_xfdf_str_tab as per_gb_xfdftableType));
4622         p_record_num := l_loop_count;
4623         return l_ret_ref_cursor;
4624    end ;
4625 
4626    /*To fetch no. of successful assignments for a payroll run*/
4627    function fetch_numberof_assignments(p_payroll_action_id Number) return number
4628    is
4629         cursor csr_pactid
4630         is
4631         select count(1)
4632         from  pay_assignment_actions
4633         where payroll_action_id = p_payroll_action_id
4634         and   action_status='C';
4635 
4636         l_pactid number;
4637    begin
4638         open csr_pactid ;
4639         fetch csr_pactid into l_pactid;
4640         close csr_pactid ;
4641         return l_pactid;
4642    end;
4643 
4644    function fetch_summary_xfdf_blob (p_assignment_action_id Number) return blob
4645    is
4646         l_xfdf_str clob;
4647         l_xfdf_blob_str blob;
4648         l_xfdf_intermetiate_var varchar2(20000);
4649         g_max_line    constant number := 46;
4650         g_desc_length constant number := 41;
4651         g_desc_size   constant number := 0.66;
4652 
4653         cursor csr_summary_entries (p_pactid Number,
4654                                     p_person_id Number,
4655                                     p_emp_ref Varchar2 ,
4656                                     p_emp_name Varchar2)
4657         is
4658         select decode(action_information_category,
4659                       'ASSETS TRANSFERRED','A',
4660                       'PAYMENTS MADE FOR EMP','B',
4661                       'VOUCHERS OR CREDIT CARDS','C',
4662                       'PVT MED TREATMENT OR INSURANCE','I',
4663                       'SERVICES SUPPLIED','K',
4664                       'ASSETS AT EMP DISPOSAL','L',
4665                       'P11D SHARES','M',
4666                       'OTHER ITEMS','N',
4667                       'OTHER ITEMS NON 1A','N',
4668                       'EXPENSES PAYMENTS','0') SECTION_TITLE,
4669                decode(action_information_category,
4670                       'ASSETS TRANSFERRED','Assets Transferred',
4671                       'PAYMENTS MADE FOR EMP','Payments made on behalf of employee',
4672                       'VOUCHERS OR CREDIT CARDS','Vouchers or credit cards',
4673                       'PVT MED TREATMENT OR INSURANCE','Private medical treatment or insurance',
4674                       'SERVICES SUPPLIED','Services Supplied',
4675                       'ASSETS AT EMP DISPOSAL','Assets placed at employee''s disposal',
4676                       'P11D SHARES','Shares',
4677                       'OTHER ITEMS','Other Items',
4678                       'OTHER ITEMS NON 1A','Other Items Non 1A',
4679                       'EXPENSES PAYMENTS','Expenses') SECTION_HEADING,
4680                decode(action_information_category,
4681                       'ASSETS TRANSFERRED',get_lookup_meaning(
4682                                            'GB_ASSET_TYPE',ACTION_INFORMATION6,
4683                                            fnd_date.canonical_to_date(ACTION_INFORMATION4))
4684                                            || ' ' || ACTION_INFORMATION5,
4685                       'PAYMENTS MADE FOR EMP',get_lookup_meaning(
4686                                            'GB_PAYMENTS_MADE',ACTION_INFORMATION6,
4687                                            fnd_date.canonical_to_date(ACTION_INFORMATION4))
4688                                            || ' ' || ACTION_INFORMATION5,
4689                       'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION5,
4690                       'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION10,
4691                       'SERVICES SUPPLIED',ACTION_INFORMATION10,
4692                       'ASSETS AT EMP DISPOSAL',get_lookup_meaning(
4693                                             'GB_ASSETS',ACTION_INFORMATION5,
4694                                             fnd_date.canonical_to_date(ACTION_INFORMATION4))
4695                                             || ' ' || ACTION_INFORMATION6,
4696                       'P11D SHARES','Share Related Benefits',
4697                       'OTHER ITEMS',replace(get_lookup_meaning(
4698                                            'GB_OTHER_ITEMS',ACTION_INFORMATION5,
4699                                            fnd_date.canonical_to_date(ACTION_INFORMATION4))
4700                                            || ' ' || ACTION_INFORMATION6,'&','&'),
4701                       'OTHER ITEMS NON 1A',get_lookup_meaning(
4702                                            'GB_OTHER_ITEMS_NON_1A',ACTION_INFORMATION5,
4703                                            fnd_date.canonical_to_date(ACTION_INFORMATION4))
4704                                            || ' ' || ACTION_INFORMATION6,
4705                       'EXPENSES PAYMENTS',get_lookup_meaning(
4706                                            'GB_EXPENSE_TYPE',ACTION_INFORMATION5,
4707                                            fnd_date.canonical_to_date(ACTION_INFORMATION4))
4708                                            || ' ' || ACTION_INFORMATION9) LINE_DETAIL,
4709                decode(action_information_category,
4710                             'ASSETS TRANSFERRED',ACTION_INFORMATION7,
4711                             'PAYMENTS MADE FOR EMP',null,
4712                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION6,
4713                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION5,
4714                             'SERVICES SUPPLIED',ACTION_INFORMATION5,
4715                             'ASSETS AT EMP DISPOSAL',ACTION_INFORMATION7,
4716                             'P11D SHARES',null,
4717                             'OTHER ITEMS',ACTION_INFORMATION7,
4718                             'OTHER ITEMS NON 1A',ACTION_INFORMATION7,
4719                             'EXPENSES PAYMENTS',ACTION_INFORMATION6) LINE_COL1,
4720                decode(action_information_category,
4721                             'ASSETS TRANSFERRED',ACTION_INFORMATION8,
4722                             'PAYMENTS MADE FOR EMP',ACTION_INFORMATION7,
4723                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION7,
4724                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION6,
4725                             'SERVICES SUPPLIED',ACTION_INFORMATION6,
4726                             'ASSETS AT EMP DISPOSAL',ACTION_INFORMATION8,
4727                             'P11D SHARES',null,
4728                             'OTHER ITEMS',ACTION_INFORMATION8,
4729                             'OTHER ITEMS NON 1A',ACTION_INFORMATION8,
4730                             'EXPENSES PAYMENTS',ACTION_INFORMATION7) LINE_COL2,
4731                decode(action_information_category,
4732                             'ASSETS TRANSFERRED',ACTION_INFORMATION9,
4733                             'PAYMENTS MADE FOR EMP',ACTION_INFORMATION8,
4734                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION11,
4735                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION7,
4736                             'SERVICES SUPPLIED',ACTION_INFORMATION7,
4737                             'ASSETS AT EMP DISPOSAL',ACTION_INFORMATION9,
4738                             'P11D SHARES',decode(ACTION_INFORMATION5,'Y','Yes'),
4739                             'OTHER ITEMS',ACTION_INFORMATION9,
4740                             'OTHER ITEMS NON 1A',ACTION_INFORMATION9,
4741                             'EXPENSES PAYMENTS',ACTION_INFORMATION8) LINE_COL3,
4742                to_char(fnd_date.canonical_to_date(ACTION_INFORMATION3),'DD-MON-YYYY') LINE_START_DATE,
4743                to_char(fnd_date.canonical_to_date(ACTION_INFORMATION4),'DD-MON-YYYY') LINE_END_DATE
4744         from  pay_action_information
4745         where action_information_category in(
4746                             'ASSETS TRANSFERRED',
4747                             'PAYMENTS MADE FOR EMP',
4748                             'VOUCHERS OR CREDIT CARDS',
4749                             'PVT MED TREATMENT OR INSURANCE',
4750                             'SERVICES SUPPLIED',
4751                             'ASSETS AT EMP DISPOSAL',
4752                             'P11D SHARES',
4753                             'OTHER ITEMS',
4754                             'OTHER ITEMS NON 1A',
4755                             'EXPENSES PAYMENTS')
4756         and action_context_type = 'AAP'
4757         and action_context_id in ( select paa.assignment_action_id
4758                                    from  pay_action_information pai_comp,
4759                                          pay_action_information pai_person,
4760                                          pay_assignment_actions paa,
4761                                          pay_payroll_actions ppa
4762                                    where ppa.payroll_action_id = p_pactid
4763                                    and   paa.payroll_action_id = ppa.payroll_action_id
4764                                    and   pai_comp.action_context_id = paa.assignment_action_id
4765                                    and   pai_comp.action_information_category = 'EMEA PAYROLL INFO'
4766                                    and   pai_person.action_context_id = paa.assignment_action_id
4767                                    and   pai_person.action_information_category = 'ADDRESS DETAILS'
4768                                    and   pai_person.action_information14 = 'Employee Address'
4769                                    and   pai_person.action_information1 = to_char(p_person_id)
4770                                    and   pai_comp.action_information6 = p_emp_ref
4771                                    and   pai_comp.action_information7 = p_emp_name)
4772         order by decode(action_information_category,
4773                             'ASSETS TRANSFERRED','A',
4774                             'PAYMENTS MADE FOR EMP','B',
4775                             'VOUCHERS OR CREDIT CARDS','C',
4776                             'PVT MED TREATMENT OR INSURANCE','I',
4777                             'SERVICES SUPPLIED','K',
4778                             'ASSETS AT EMP DISPOSAL','L',
4779                             'P11D SHARES','M',
4780                             'OTHER ITEMS','N',
4781                             'OTHER ITEMS NON 1A','N',
4782                             'EXPENSES PAYMENTS','O') asc,
4783                  decode(action_information_category,
4784                             'ASSETS TRANSFERRED','Assets Transferred',
4785                             'PAYMENTS MADE FOR EMP','Payments made on behalf of employee',
4786                             'VOUCHERS OR CREDIT CARDS','Vouchers or credit cards',
4787                             'PVT MED TREATMENT OR INSURANCE','Private medical treatment or insurance',
4788                             'SERVICES SUPPLIED','Services Supplied',
4789                             'ASSETS AT EMP DISPOSAL','Assets placed at employee''s disposal',
4790                             'P11D SHARES','Shares',
4791                             'OTHER ITEMS','Other Items',
4792                             'OTHER ITEMS NON 1A','Other Items Non 1A',
4793                             'EXPENSES PAYMENTS','Expenses') asc ;
4794 
4795         cursor csr_summary_entries_0405 (p_pactid Number,
4796                                          p_person_id Number,
4797                                          p_emp_ref Varchar2 ,
4798                                          p_emp_name Varchar2)
4799         is
4800         select decode(action_information_category,
4801                             'ASSETS TRANSFERRED','A',
4802                             'PAYMENTS MADE FOR EMP','B',
4803                             'VOUCHERS OR CREDIT CARDS','C',
4804                             'PVT MED TREATMENT OR INSURANCE','I',
4805                             'SERVICES SUPPLIED','K',
4806                             'ASSETS AT EMP DISPOSAL','L',
4807                             'OTHER ITEMS','M',
4808                             'OTHER ITEMS NON 1A','M',
4809                             'EXPENSES PAYMENTS','N') SECTION_TITLE,
4810                decode(action_information_category,
4811                             'ASSETS TRANSFERRED','Assets Transferred',
4812                             'PAYMENTS MADE FOR EMP','Payments made on behalf of employee',
4813                             'VOUCHERS OR CREDIT CARDS','Vouchers or credit cards',
4814                             'PVT MED TREATMENT OR INSURANCE','Private medical treatment or insurance',
4815                             'SERVICES SUPPLIED','Services Supplied',
4816                             'ASSETS AT EMP DISPOSAL','Assets placed at employee''s disposal',
4817                             'OTHER ITEMS','Other Items',
4818                             'OTHER ITEMS NON 1A','Other Items Non 1A',
4819                             'EXPENSES PAYMENTS','Expenses') SECTION_HEADING,
4820                decode(action_information_category,
4821                             'ASSETS TRANSFERRED',get_lookup_meaning(
4822                                                 'GB_ASSET_TYPE', ACTION_INFORMATION6,
4823                                                 fnd_date.canonical_to_date(ACTION_INFORMATION4))
4824                                                  || ' ' || ACTION_INFORMATION5,
4825                             'PAYMENTS MADE FOR EMP',get_lookup_meaning(
4826                                                 'GB_PAYMENTS_MADE', ACTION_INFORMATION6,
4827                                                 fnd_date.canonical_to_date(ACTION_INFORMATION4))
4828                                                  || ' ' || ACTION_INFORMATION5,
4829                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION5,
4830                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION10,
4831                             'SERVICES SUPPLIED',ACTION_INFORMATION10,
4832                             'ASSETS AT EMP DISPOSAL',get_lookup_meaning(
4833                                                 'GB_ASSETS', ACTION_INFORMATION5,
4834                                                 fnd_date.canonical_to_date(ACTION_INFORMATION4))
4835                                                  || ' ' || ACTION_INFORMATION6,
4836                             'OTHER ITEMS',replace(get_lookup_meaning(
4837                                                 'GB_OTHER_ITEMS',ACTION_INFORMATION5,
4838                                                 fnd_date.canonical_to_date(ACTION_INFORMATION4))
4839                                           || ' ' || ACTION_INFORMATION6,'&','&'),
4840                             'OTHER ITEMS NON 1A',get_lookup_meaning(
4841                                                 'GB_OTHER_ITEMS_NON_1A', ACTION_INFORMATION5,
4842                                                 fnd_date.canonical_to_date(ACTION_INFORMATION4))
4843                                           || ' ' || ACTION_INFORMATION6,
4844                             'EXPENSES PAYMENTS',get_lookup_meaning(
4845                                                 'GB_EXPENSE_TYPE',ACTION_INFORMATION5,
4846                                                 fnd_date.canonical_to_date(ACTION_INFORMATION4))
4847                                           || ' ' || ACTION_INFORMATION9) LINE_DETAIL,
4848                decode(action_information_category,
4849                             'ASSETS TRANSFERRED',ACTION_INFORMATION7,
4850                             'PAYMENTS MADE FOR EMP',null,
4851                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION6,
4852                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION5,
4853                             'SERVICES SUPPLIED',ACTION_INFORMATION5,
4854                             'ASSETS AT EMP DISPOSAL',ACTION_INFORMATION7,
4855                             'OTHER ITEMS',ACTION_INFORMATION7,
4856                             'OTHER ITEMS NON 1A',ACTION_INFORMATION7,
4857                             'EXPENSES PAYMENTS',ACTION_INFORMATION6) LINE_COL1,
4858                decode(action_information_category,
4859                             'ASSETS TRANSFERRED',ACTION_INFORMATION8,
4860                             'PAYMENTS MADE FOR EMP',ACTION_INFORMATION7,
4861                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION7,
4862                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION6,
4863                             'SERVICES SUPPLIED',ACTION_INFORMATION6,
4864                             'ASSETS AT EMP DISPOSAL',ACTION_INFORMATION8,
4865                             'OTHER ITEMS',ACTION_INFORMATION8,
4866                             'OTHER ITEMS NON 1A',ACTION_INFORMATION8,
4867                             'EXPENSES PAYMENTS',ACTION_INFORMATION7) LINE_COL2,
4868                decode(action_information_category,
4869                             'ASSETS TRANSFERRED',ACTION_INFORMATION9,
4870                             'PAYMENTS MADE FOR EMP',ACTION_INFORMATION8,
4871                             'VOUCHERS OR CREDIT CARDS',ACTION_INFORMATION11,
4872                             'PVT MED TREATMENT OR INSURANCE',ACTION_INFORMATION7,
4873                             'SERVICES SUPPLIED',ACTION_INFORMATION7,
4874                             'ASSETS AT EMP DISPOSAL',ACTION_INFORMATION9,
4875                             'OTHER ITEMS',ACTION_INFORMATION9,
4876                             'OTHER ITEMS NON 1A',ACTION_INFORMATION9,
4877                             'EXPENSES PAYMENTS',ACTION_INFORMATION8) LINE_COL3,
4878                to_char(fnd_date.canonical_to_date(ACTION_INFORMATION3),'DD-MON-YYYY') LINE_START_DATE,
4879                to_char(fnd_date.canonical_to_date(ACTION_INFORMATION4),'DD-MON-YYYY') LINE_END_DATE
4880                from  pay_action_information
4881                where action_information_category in(
4882                             'ASSETS TRANSFERRED',
4883                             'PAYMENTS MADE FOR EMP',
4884                             'VOUCHERS OR CREDIT CARDS',
4885                             'PVT MED TREATMENT OR INSURANCE',
4886                             'SERVICES SUPPLIED',
4887                             'ASSETS AT EMP DISPOSAL',
4888                             'OTHER ITEMS',
4889                             'OTHER ITEMS NON 1A',
4890                             'EXPENSES PAYMENTS')
4891                and action_context_type = 'AAP'
4892                and action_context_id in ( select paa.assignment_action_id
4893                                           from  pay_action_information pai_comp,
4894                                                 pay_action_information pai_person,
4895                                                 pay_assignment_actions paa,
4896                                                 pay_payroll_actions ppa
4897                                           where ppa.payroll_action_id = p_pactid
4898                                           and   paa.payroll_action_id = ppa.payroll_action_id
4899                                           and   pai_comp.action_context_id = paa.assignment_action_id
4900                                           and   pai_comp.action_information_category = 'EMEA PAYROLL INFO'
4901                                           and   pai_person.action_context_id = paa.assignment_action_id
4902                                           and   pai_person.action_information_category = 'ADDRESS DETAILS'
4903                                           and   pai_person.action_information14 = 'Employee Address'
4904                                           and   pai_person.action_information1 = to_char(p_person_id)
4905                                           and   pai_comp.action_information6 = p_emp_ref
4906                                           and   pai_comp.action_information7 = p_emp_name)
4907                order by
4908                      decode(action_information_category,
4909                             'ASSETS TRANSFERRED','A',
4910                             'PAYMENTS MADE FOR EMP','B',
4911                             'VOUCHERS OR CREDIT CARDS','C',
4912                             'PVT MED TREATMENT OR INSURANCE','I',
4913                             'SERVICES SUPPLIED','K',
4914                             'ASSETS AT EMP DISPOSAL','L',
4915                             'OTHER ITEMS','M',
4916                             'OTHER ITEMS NON 1A','M',
4917                             'EXPENSES PAYMENTS','N') asc,
4918                     decode(action_information_category,
4919                             'ASSETS TRANSFERRED','Assets Transferred',
4920                             'PAYMENTS MADE FOR EMP','Payments made on behalf of employee',
4921                             'VOUCHERS OR CREDIT CARDS','Vouchers or credit cards',
4922                             'PVT MED TREATMENT OR INSURANCE','Private medical treatment or insurance',
4923                             'SERVICES SUPPLIED','Services Supplied',
4924                             'ASSETS AT EMP DISPOSAL','Assets placed at employee''s disposal',
4925                             'OTHER ITEMS','Other Items',
4926                             'OTHER ITEMS NON 1A','Other Items Non 1A',
4927                             'EXPENSES PAYMENTS','Expenses') asc ;
4928         l_emp_ref_no varchar2(150);
4929         l_employer_name varchar2(150);
4930         l_full_name varchar2(150);
4931         l_national_ins_no varchar2(150);
4932         l_employee_number varchar2(150);
4933         l_pactid number;
4934         l_person_id number;
4935         l_loop_count Number;
4936         l_tot_col1 Number;
4937         l_tot_col2 Number;
4938         l_tot_col3 Number;
4939         l_prev_section  varchar2(150);
4940         l_rep_run   VARCHAR2(10);
4941         l_line_count number;
4942         l_temp       number;
4943         l_odd_page   boolean;
4944 
4945         function get_desc_line(p_desc varchar2) return number is
4946            l_length number;
4947            l_offset number  := 0;
4948            l_word   varchar2(100);
4949            x        number := 1;
4950            l_number number := 0;
4951            l_count  number := 0;
4952            l_ret    number := 1;
4953         begin
4954            if length(p_desc) < g_desc_length then
4955               l_ret := 1;
4956            else
4957               l_length := length(p_desc);
4958               loop
4959                  l_number := l_number+1;
4960                  l_offset := instr(p_desc, ' ', x, 1);
4961                  if l_offset > 0 then
4962                     l_word := substr(p_desc, x, l_offset-x);
4963                     if length(l_word) < g_desc_length  then
4964                         if length(l_word) + l_count > g_desc_length then
4965                            l_count := length(l_word) + 1;
4966                            l_ret := l_ret + 1;
4967                         else
4968                            l_count := l_count + length(l_word) + 1;
4969                         end if;
4970                     else
4971                         l_ret := l_ret + ceil(length(l_word)/g_desc_length);
4972                         l_count := length(l_word) - floor(length(l_word)/g_desc_length) * g_desc_length + 1;
4973                     end if;
4974                  else
4975                     l_word := substr(p_desc, x);
4976                     if length(l_word) < g_desc_length  then
4977                         if length(l_word) + l_count > g_desc_length then
4978                            l_count := length(l_word) + 1;
4979                            l_ret := l_ret + 1;
4980                         else
4981                            l_count := l_count + length(l_word) + 1;
4982                         end if;
4983                     else
4984                         l_ret := l_ret + ceil(length(l_word)/g_desc_length);
4985                         l_count := length(l_word) - floor(length(l_word)/g_desc_length) * g_desc_length + 1;
4986                     end if;
4987                     exit;
4988                  end if;
4989                  x := l_offset+1;
4990               end loop;
4991            end if;
4992            return l_ret;
4993         end;
4994 
4995         procedure set_line_desc(p_section_heading  varchar2) is
4996              l_line_desc varchar2(1000);
4997         begin
4998              /* Reference to Share can be removed when do work for P11D 05/06 */
4999              if p_section_heading = 'Shares'
5000              then
5001                  -- we need blank line as per spec
5002                  l_line_desc := ' <field name="'||'COL1_SDATE'||'"><value>' ||'Start Date'|| '</value></field>  ' ||
5003                  '<field name="'||'COL1_EDATE'||'"><value>' ||'End Date'|| '</value></field>  ' ||
5004                  '<field name="'||'LINE_DESC'||'"><value>' ||null || '</value></field>  ' ||
5005                  '<field name="'||'COL1_HEADING'||'"><value>' ||null || '</value></field>  ' ||
5006                  '<field name="'||'COL2_HEADING'||'"><value>' ||null || '</value></field>  ' ||
5007                  '<field name="'||'COL3_HEADING'||'"><value>' ||null || '</value></field>  ' ;
5008              elsif p_section_heading = 'Payments made on behalf of employee' then
5009                  l_line_desc := ' <field name="'||'COL1_SDATE'||'"><value>' ||'Start Date'|| '</value></field>  ' ||
5010                  '<field name="'||'COL1_EDATE'||'"><value>' ||'End Date'|| '</value></field>  ' ||
5011                  '<field name="'||'LINE_DESC'||'"><value>' ||'Description' || '</value></field>  ' ||
5012                  '<field name="'||'COL1_HEADING'||'"><value>' ||null || '</value></field>  ' ||
5013                  '<field name="'||'COL2_HEADING'||'"><value>' ||'Value' || '</value></field>  ' ||
5014                  '<field name="'||'COL3_HEADING'||'"><value>' ||'Tax Notional' || '</value></field>  ' ;
5015              elsif p_section_heading = 'Other Items Non 1A' then
5016                  l_line_desc := ' <field name="'||'COL1_SDATE'||'"><value>' ||'Start Date'|| '</value></field>  ' ||
5017                  '<field name="'||'COL1_EDATE'||'"><value>' ||'End Date'|| '</value></field>  ' ||
5018                  '<field name="'||'LINE_DESC'||'"><value>' ||'Description Non 1A' || '</value></field>  ' ||
5019                  '<field name="'||'COL1_HEADING'||'"><value>' ||'Value' || '</value></field>  ' ||
5020                  '<field name="'||'COL2_HEADING'||'"><value>' ||'Made Good' || '</value></field>  ' ||
5021                  '<field name="'||'COL3_HEADING'||'"><value>' ||'Benefit' || '</value></field>  ' ;
5022              elsif p_section_heading = 'Assets placed at employee''s disposal' then
5023                  l_line_desc := ' <field name="'||'COL1_SDATE'||'"><value>' ||'Start Date'|| '</value></field>  ' ||
5024                  '<field name="'||'COL1_EDATE'||'"><value>' ||'End Date'|| '</value></field>  ' ||
5025                  '<field name="'||'LINE_DESC'||'"><value>' ||'Description' || '</value></field>  ' ||
5026                  '<field name="'||'COL1_HEADING'||'"><value>' ||'Annual Value' || '</value></field>  ' ||
5027                  '<field name="'||'COL2_HEADING'||'"><value>' ||'Made Good' || '</value></field>  ' ||
5028                  '<field name="'||'COL3_HEADING'||'"><value>' ||'Benefit' || '</value></field>  ' ;
5029              else
5030                  l_line_desc := ' <field name="'||'COL1_SDATE'||'"><value>' ||'Start Date'|| '</value></field>  ' ||
5031                  '<field name="'||'COL1_EDATE'||'"><value>' ||'End Date'|| '</value></field>  ' ||
5032                  '<field name="'||'LINE_DESC'||'"><value>' ||'Description' || '</value></field>  ' ||
5033                  '<field name="'||'COL1_HEADING'||'"><value>' ||'Value' || '</value></field>  ' ||
5034                  '<field name="'||'COL2_HEADING'||'"><value>' ||'Made Good' || '</value></field>  ' ||
5035                  '<field name="'||'COL3_HEADING'||'"><value>' ||'Benefit' || '</value></field>  ' ;
5036              end if;
5037              dbms_lob.writeAppend( l_xfdf_str, length(l_line_desc) ,l_line_desc );
5038         end;
5039 
5040         procedure add_total_lines is
5041         begin
5042              if  l_prev_section = 'Shares'
5043              then
5044                   -- then we do print totals
5045                  null;
5046              elsif l_prev_section = 'Payments made on behalf of employee'
5047              then
5048                  l_xfdf_intermetiate_var :=
5049                        '<field name="'||'LINE_TOTAL'||'"><value>' ||'Totals' || '</value></field>  ' ||
5050                        '<field name="'||'TOT_COL1'||'"><value>' ||l_TOT_COL1 || '</value></field>  ' ||
5051                        '<field name="'||'TOT_COL2'||'"><value>' ||to_char(to_number(nvl(l_TOT_COL2,0)),'FM999,999,990.00') || '</value></field>  ' ||
5052                        '<field name="'||'TOT_COL3'||'"><value>' ||to_char(to_number(nvl(l_TOT_COL3,0)),'FM999,999,990.00') || '</value></field>  ' ;
5053                  dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5054              else
5055                  l_xfdf_intermetiate_var :=
5056                  ' <field name="'||'LINE_TOTAL'||'"><value>' ||'Totals' || '</value></field>  ' ||
5057                  ' <field name="'||'TOT_COL1'||'"><value>' ||to_char(to_number(nvl(l_TOT_COL1,0)),'FM999,999,990.00') || '</value></field>  ' ||
5058                  ' <field name="'||'TOT_COL2'||'"><value>' ||to_char(to_number(nvl(l_TOT_COL2,0)),'FM999,999,990.00') || '</value></field>  ' ||
5059                  ' <field name="'||'TOT_COL3'||'"><value>' ||to_char(to_number(nvl(l_TOT_COL3,0)),'FM999,999,990.00') || '</value></field>  ' ;
5060                  dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5061              end if;
5062         end;
5063 
5064         procedure add_detail_line(p_SECTION_HEADING varchar2,
5065                                   p_LINE_DETAIL varchar2,
5066                                   p_LINE_COL1 varchar2,
5067                                   p_LINE_COL2 varchar2,
5068                                   p_LINE_COL3 varchar2,
5069                                   p_LINE_SDATE varchar2,
5070                                   p_LINE_EDATE varchar2) is
5071         begin
5072              if p_SECTION_HEADING = 'Payments made on behalf of employee' or
5073                 p_SECTION_HEADING ='Shares'
5074              then
5075                  -- no defaulting of values reqd
5076                  if p_SECTION_HEADING = 'Payments made on behalf of employee'
5077                  then
5078                      l_xfdf_intermetiate_var :=
5079                      '<field name="'||'LINE_START_D'||'"><value>' ||p_LINE_SDATE   || '</value></field>  ' ||
5080                      '<field name="'||'LINE_END_D'||'"><value>'   ||p_LINE_EDATE   || '</value></field>  ' ||
5081                      '<field name="'||'LINE_DETAIL'||'"><value>' ||p_LINE_DETAIL || '</value></field>  ' ||
5082                      '<field name="'||'LINE_COL1'||'"><value>'   ||null   || '</value></field>  ' ||
5083                      '<field name="'||'LINE_COL2'||'"><value>'   ||to_char(to_number(nvl(p_LINE_COL2,0)),'FM999,999,990.00')   || '</value></field>  ' ||
5084                      '<field name="'||'LINE_COL3'||'"><value>'   ||to_char(to_number(nvl(p_LINE_COL3,0)),'FM999,999,990.00')   || '</value></field>  ' ;
5085                      dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5086                  else -- this mean it is shares entry
5087                      l_xfdf_intermetiate_var :=
5088                      '<field name="'||'LINE_START_D'||'"><value>' ||p_LINE_SDATE   || '</value></field>  ' ||
5089                      '<field name="'||'LINE_END_D'||'"><value>'   ||p_LINE_EDATE   || '</value></field>  ' ||
5090                      '<field name="'||'LINE_DETAIL'||'"><value>' ||p_LINE_DETAIL || '</value></field>  ' ||
5091                      '<field name="'||'LINE_COL1'||'"><value>'   ||p_LINE_COL1   || '</value></field>  ' ||
5092                      '<field name="'||'LINE_COL2'||'"><value>'   ||p_LINE_COL2   || '</value></field>  ' ||
5093                      '<field name="'||'LINE_COL3'||'"><value>'   ||p_LINE_COL3   || '</value></field>  ' ;
5094                      dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5095                  end if;
5096              else
5097                  l_xfdf_intermetiate_var :=
5098                  '<field name="'||'LINE_START_D'||'"><value>' ||p_LINE_SDATE   || '</value></field>  ' ||
5099                  '<field name="'||'LINE_END_D'||'"><value>'   ||p_LINE_EDATE   || '</value></field>  ' ||
5100                  '<field name="'||'LINE_DETAIL'||'"><value>' ||p_LINE_DETAIL || '</value></field>  ' ;
5101                  dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5102                  if nvl(p_LINE_COL1,nvl(p_LINE_COL3,0)) =  0
5103                  then
5104                      l_xfdf_intermetiate_var :=
5105                      '<field name="'||'LINE_COL1'||'"><value>'||to_char(to_number(nvl(p_LINE_COL3,0)),'FM999,999,990.00') || '</value></field>  ' ;
5106                      dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5107                  else
5108                      l_xfdf_intermetiate_var :=
5109                      '<field name="'||'LINE_COL1'||'"><value>'   ||to_char(to_number(nvl(p_LINE_COL1,nvl(p_LINE_COL3,0))),'FM999,999,990.00')   || '</value></field>  ' ;
5110                      dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5111                  end if;
5112                  l_xfdf_intermetiate_var :=
5113                  '<field name="'||'LINE_COL2'||'"><value>'   ||to_char(to_number(nvl(p_LINE_COL2,0)),'FM999,999,990.00')   || '</value></field>  ' ||
5114                  '<field name="'||'LINE_COL3'||'"><value>'   ||to_char(to_number(nvl(p_LINE_COL3,0)),'FM999,999,990.00')   || '</value></field>  ' ;
5115                  dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5116             end if;
5117         end;
5118    begin
5119         --hr_utility.trace_on(null,'KT');
5120         hr_utility.trace('calling get_employer_details');
5121         get_employer_details(p_assignment_action_id,
5122                              l_emp_ref_no,
5123                               l_employer_name);
5124         hr_utility.trace('calling get_employee_details');
5125         get_employee_details(p_assignment_action_id,
5126                              l_full_name,
5127                              l_national_ins_no,
5128                              l_employee_number);
5129         l_pactid := get_pactid(p_assignment_action_id);
5130         l_person_id := get_person_id (p_assignment_action_id );
5131         l_employee_number := get_assignment_number(p_assignment_action_id, true, l_person_id, l_emp_ref_no);
5132         l_loop_count := 0;
5133         -- hr_utility.trace_on(null,'SUMM');
5134         hr_utility.trace('l_pactid ' || l_pactid);
5135         hr_utility.trace('l_person_id '|| l_person_id);
5136         hr_utility.trace('l_emp_ref_no '|| l_emp_ref_no);
5137         hr_utility.trace('l_employer_name '|| l_employer_name);
5138         hr_utility.trace('opening the cursor');
5139         l_tot_col1 := null;
5140         l_tot_col2 := null;
5141         l_tot_col3 := null;
5142         l_prev_section := null;
5143         hr_utility.trace('l_prev_section ' || l_prev_section);
5144         dbms_lob.createtemporary(l_xfdf_str,false,DBMS_LOB.CALL);
5145         dbms_lob.open(l_xfdf_str,dbms_lob.lob_readwrite);
5146 
5147 
5148         PAY_GB_P11D_ARCHIVE_SS.get_parameters(
5149          p_payroll_action_id => l_pactid,
5150          p_token_name        => 'Rep_Run',
5151          p_token_value       => l_rep_run);
5152         l_loop_count := 0;
5153 
5154         l_odd_page := TRUE;
5155         l_line_count := 0;
5156         if l_odd_page then
5157            hr_utility.trace('Current page is odd page');
5158         else
5159            hr_utility.trace('Current page is even page');
5160         end if;
5161         if to_number(l_rep_run) < 2005
5162         then
5163             for summary_entries in  csr_summary_entries(l_pactid,
5164                                                         l_person_id,
5165                                                         l_emp_ref_no,
5166                                                         l_employer_name)
5167             loop
5168                 l_loop_count := l_loop_count+1;
5169                 if l_loop_count = 1
5170                 then
5171                     -- setting the emp details page title...
5172                     l_xfdf_intermetiate_var  := '<?xml version = "1.0" encoding = "UTF-8"?>
5173                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
5174                     <fields> ' ||
5175                     '<field name="'||'BEN_START_YEAR'||'"><value>' ||(to_number(l_rep_run) - 1) || '</value></field> ' ||
5176                     '<field name="'||'BEN_END_YEAR'||'"><value>' ||to_number(l_rep_run)  || '</value></field> ' ||
5177                     '<field name="'||'EMPLOYERS_NAME'||'"><value>' ||replace(l_employer_name,'&','&')       || '</value></field> ' ||
5178                     '<field name="'||'FULL_NAME'||'"><value>' ||l_full_name || '</value></field>  ' ||
5179                     '<field name="'||'EMPLOYERS_REF_NO'||'"><value>' ||l_emp_ref_no || '</value></field>  ' ||
5180                     '<field name="'||'EMPLOYEE_NUMBER'||'"><value>' ||l_employee_number || '</value></field>  ' ||
5181                     '<field name="'||'NATIONAL_INS_NO'||'"><value>' ||l_national_ins_no || '</value></field>  ' ;
5182                     dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5183                     -- add new section heading and section title
5184                     if summary_entries.SECTION_HEADING = 'Other Items Non 1A'
5185                     then
5186                         l_xfdf_intermetiate_var:=
5187                         '<field name="'||'SECTION_TITLE'||'"><value>' ||summary_entries.SECTION_TITLE || '</value></field>  ' ||
5188                         '<field name="'||'SECTION_HEADING'||'"><value>' ||'Other Items' || '</value></field>  ' ;
5189                         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5190                     else
5191                         l_xfdf_intermetiate_var:=
5192                         '<field name="'||'SECTION_TITLE'||'"><value>' ||summary_entries.SECTION_TITLE || '</value></field>  ' ||
5193                         '<field name="'||'SECTION_HEADING'||'"><value>' ||summary_entries.SECTION_HEADING || '</value></field>  ' ;
5194                         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5195                     end if;
5196                     -- add new line desc
5197                     set_line_desc(summary_entries.SECTION_HEADING);
5198                     hr_utility.trace('l_loop_count '  ||l_loop_count);
5199                     l_prev_section := summary_entries.SECTION_HEADING;
5200                     l_line_count := l_line_count + 2;
5201                 end if;
5202                 hr_utility.trace('l_prev_section ' || l_prev_section);
5203                 hr_utility.trace('summary_entries.SECTION_HEADING ' || summary_entries.SECTION_HEADING);
5204                 if l_prev_section = summary_entries.SECTION_HEADING
5205                 then
5206                     -- we just add the line details
5207                     add_detail_line(summary_entries.SECTION_HEADING,
5208                                     summary_entries.LINE_DETAIL,
5209                                     summary_entries.LINE_COL1,
5210                                     summary_entries.LINE_COL2,
5211                                     summary_entries.LINE_COL3,
5212                                     summary_entries.LINE_START_DATE,
5213                                     summary_entries.LINE_END_DATE);
5214                     l_temp := get_desc_line(summary_entries.LINE_DETAIL);
5215                     hr_utility.trace(summary_entries.LINE_DETAIL || ' : ' || l_temp);
5216                     if (l_temp > 1) then
5217                         l_line_count := l_line_count + (l_temp * g_desc_size);
5218                     else
5219                         l_line_count := l_line_count + 1;
5220                     end if;
5221                     -- we need to sum the totals
5222                     if summary_entries.SECTION_HEADING <> 'Shares'
5223                     then
5224                         if summary_entries.SECTION_HEADING ='Payments made on behalf of employee'
5225                         then
5226                             l_TOT_COL1 := null;
5227                             l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5228                             l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5229                         else
5230                             l_TOT_COL1 := nvl(l_TOT_COL1,0) + nvl(summary_entries.LINE_COL1,nvl(summary_entries.LINE_COL3,0));
5231                             l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5232                             l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5233                         end if;
5234                     end if;
5235                 else
5236                     hr_utility.trace('l_loop_count ' || l_loop_count);
5237                     add_total_lines;
5238                     l_line_count := l_line_count + 1;
5239                     hr_utility.trace('adding new section heading and title');
5240                     -- add new section heading and title
5241                     -- we do not add heading if the SECTION_HEADING is Other Items Non 1A
5242                     -- and prev was Other Items
5243                     if l_prev_section = 'Other Items' and  summary_entries.SECTION_HEADING = 'Other Items Non 1A'
5244                     then
5245                         -- we do not add section title and section heading
5246                         null;
5247                     else
5248                         l_xfdf_intermetiate_var  :=
5249                             '<field name="'||'SECTION_TITLE'||'"><value>' ||summary_entries.SECTION_TITLE || '</value></field>  ' ||
5250                             '<field name="'||'SECTION_HEADING'||'"><value>' ||summary_entries.SECTION_HEADING || '</value></field>  ' ;
5251                         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5252                         l_line_count := l_line_count + 1;
5253                     end if;
5254                     -- add new line desc
5255                     set_line_desc(summary_entries.SECTION_HEADING);
5256                     l_line_count := l_line_count + 1;
5257                     -- add the line details
5258                     add_detail_line(summary_entries.SECTION_HEADING,
5259                                     summary_entries.LINE_DETAIL,
5260                                     summary_entries.LINE_COL1,
5261                                     summary_entries.LINE_COL2,
5262                                     summary_entries.LINE_COL3,
5263                                     summary_entries.LINE_START_DATE,
5264                                     summary_entries.LINE_END_DATE);
5265                     l_temp := get_desc_line(summary_entries.LINE_DETAIL);
5266                     hr_utility.trace(summary_entries.LINE_DETAIL || ' : ' || l_temp);
5267                     if (l_temp > 1) then
5268                         l_line_count := l_line_count + (l_temp * g_desc_size);
5269                     else
5270                         l_line_count := l_line_count + 1;
5271                     end if;
5272                     -- resetting tot cols
5273                     l_tot_col1 := null;
5274                     l_tot_col2 := null;
5275                     l_tot_col3 := null;
5276                     l_prev_section := summary_entries.SECTION_HEADING;
5277                     -- we need to sum the totals
5278                     if summary_entries.SECTION_HEADING <> 'Shares'
5279                     then
5280                         if summary_entries.SECTION_HEADING ='Payments made on behalf of employee'
5281                         then
5282                             l_TOT_COL1 := null;
5283                             l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5284                             l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5285                         else
5286                             l_TOT_COL1 := nvl(l_TOT_COL1,0) +
5287                                           nvl(summary_entries.LINE_COL1,nvl(summary_entries.LINE_COL3,0));
5288                             l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5289                             l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5290                         end if;
5291                     end if;
5292                 end if;
5293                 if l_line_count > g_max_line then
5294                    l_odd_page := not(l_odd_page);
5295                    l_line_count := l_line_count - g_max_line;
5296                 end if;
5297             end loop;
5298         else
5299             /* This code is for year 04/05 onwards */
5300             for summary_entries in  csr_summary_entries_0405(l_pactid,
5301                                                              l_person_id,
5302                                                              l_emp_ref_no,
5303                                                              l_employer_name)
5304             loop
5305                 l_loop_count := l_loop_count+1;
5306                 if l_loop_count = 1
5307                 then
5308                     -- setting the emp details page title...
5309                     l_xfdf_intermetiate_var  := '<?xml version = "1.0" encoding = "UTF-8"?>
5310                         <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
5311                         <fields> ' ||
5312                         '<field name="'||'BEN_START_YEAR'||'"><value>' ||(to_number(l_rep_run) - 1) || '</value></field> ' ||
5313                         '<field name="'||'BEN_END_YEAR'||'"><value>' ||to_number(l_rep_run)  || '</value></field> ' ||
5314                         '<field name="'||'EMPLOYERS_NAME'||'"><value>' ||replace(l_employer_name,'&','&')       || '</value></field> ' ||
5315                         '<field name="'||'FULL_NAME'||'"><value>' ||l_full_name || '</value></field>  ' ||
5316                         '<field name="'||'EMPLOYERS_REF_NO'||'"><value>' ||l_emp_ref_no || '</value></field>  ' ||
5317                         '<field name="'||'EMPLOYEE_NUMBER'||'"><value>' ||l_employee_number || '</value></field>  ' ||
5318                         '<field name="'||'NATIONAL_INS_NO'||'"><value>' ||l_national_ins_no || '</value></field>  ' ;
5319                     dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5320                     -- add new section heading and section title
5321                     if summary_entries.SECTION_HEADING = 'Other Items Non 1A'
5322                     then
5323                         l_xfdf_intermetiate_var:=
5324                             '<field name="'||'SECTION_TITLE'||'"><value>' ||summary_entries.SECTION_TITLE || '</value></field>  ' ||
5325                             '<field name="'||'SECTION_HEADING'||'"><value>' ||'Other Items' || '</value></field>  ' ;
5326                         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5327                     else
5328                         l_xfdf_intermetiate_var:=
5329                            '<field name="'||'SECTION_TITLE'||'"><value>' ||summary_entries.SECTION_TITLE || '</value></field>  ' ||
5330                            '<field name="'||'SECTION_HEADING'||'"><value>' ||summary_entries.SECTION_HEADING || '</value></field>  ' ;
5331                         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5332                     end if;
5333                     -- add new line desc
5334 
5335                     set_line_desc(summary_entries.SECTION_HEADING);
5336                     hr_utility.trace('l_loop_count '  ||l_loop_count);
5337                     l_prev_section := summary_entries.SECTION_HEADING;
5338                     l_line_count := l_line_count + 2;
5339                     hr_utility.trace('Writing line_desc + header : ' || l_line_count);
5340                 end if;
5341                 hr_utility.trace('l_prev_section ' || l_prev_section);
5342                 hr_utility.trace('summary_entries.SECTION_HEADING ' || summary_entries.SECTION_HEADING);
5343                 if l_prev_section = summary_entries.SECTION_HEADING
5344                 then
5345                     -- we just add the line details
5346                     add_detail_line(summary_entries.SECTION_HEADING,
5347                                     summary_entries.LINE_DETAIL,
5348                                     summary_entries.LINE_COL1,
5349                                     summary_entries.LINE_COL2,
5350                                     summary_entries.LINE_COL3,
5351                                     summary_entries.LINE_START_DATE,
5352                                     summary_entries.LINE_END_DATE);
5353                     l_temp := get_desc_line(summary_entries.LINE_DETAIL);
5354                     hr_utility.trace(summary_entries.LINE_DETAIL || ' : ' || l_temp);
5355                     if (l_temp > 1) then
5356                         l_line_count := l_line_count + (l_temp * g_desc_size);
5357                     else
5358                         l_line_count := l_line_count + 1;
5359                     end if;
5360                     hr_utility.trace('Writing line details : ' || l_line_count);
5361                     -- we need to sum the totals
5362                     if summary_entries.SECTION_HEADING <> 'Shares'
5363                     then
5364                         if summary_entries.SECTION_HEADING ='Payments made on behalf of employee'
5365                         then
5366                             l_TOT_COL1 := null;
5367                             l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5368                             l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5369                         else
5370                             l_TOT_COL1 := nvl(l_TOT_COL1,0) +
5371                                 nvl(summary_entries.LINE_COL1,nvl(summary_entries.LINE_COL3,0));
5372                             l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5373                             l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5374                         end if;
5375                     end if;
5376                 else
5377                     hr_utility.trace('l_loop_count ' || l_loop_count);
5378                     add_total_lines;
5379                     l_line_count := l_line_count + 1;
5380                     hr_utility.trace('Writing total line : ' || l_line_count);
5381                     hr_utility.trace('adding new section heading and title');
5382                     -- add new section heading and title
5383                     -- we do not add heading if the SECTION_HEADING is Other Items Non 1A
5384                     -- and prev was Other Items
5385                     if l_prev_section = 'Other Items' and
5386                        summary_entries.SECTION_HEADING = 'Other Items Non 1A'
5387                     then
5388                         -- we do not add section title and section heading
5389                         null;
5390                     else
5391                         l_xfdf_intermetiate_var  :=
5392                            '<field name="'||'SECTION_TITLE'||'"><value>' ||summary_entries.SECTION_TITLE || '</value></field>  ' ||
5393                            '<field name="'||'SECTION_HEADING'||'"><value>' ||summary_entries.SECTION_HEADING || '</value></field>  ' ;
5394                         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5395                         l_line_count := l_line_count + 1;
5396                         hr_utility.trace('Writing header : ' || l_line_count);
5397                     end if;
5398                     -- add new line desc
5399                     set_line_desc(summary_entries.SECTION_HEADING);
5400                     l_line_count := l_line_count + 1;
5401                     hr_utility.trace('Writing line_desc : ' || l_line_count);
5402                     -- add the line details
5403                     add_detail_line(summary_entries.SECTION_HEADING,
5404                                     summary_entries.LINE_DETAIL,
5405                                     summary_entries.LINE_COL1,
5406                                     summary_entries.LINE_COL2,
5407                                     summary_entries.LINE_COL3,
5408                                     summary_entries.LINE_START_DATE,
5409                                     summary_entries.LINE_END_DATE);
5410                     l_temp := get_desc_line(summary_entries.LINE_DETAIL);
5411                     hr_utility.trace(summary_entries.LINE_DETAIL || ' : ' || l_temp);
5412                     if (l_temp > 1) then
5413                         l_line_count := l_line_count + (l_temp * g_desc_size);
5414                     else
5415                         l_line_count := l_line_count + 1;
5416                     end if;
5417                     hr_utility.trace('Writing line details : ' || l_line_count);
5418                     -- resetting tot cols
5419                     l_tot_col1 := null;
5420                     l_tot_col2 := null;
5421                     l_tot_col3 := null;
5422                     l_prev_section := summary_entries.SECTION_HEADING;
5423                     -- we need to sum the totals
5424                     -- no need to check for Shares
5425                     /* if summary_entries.SECTION_HEADING <> 'Shares' then */
5426                     if  summary_entries.SECTION_HEADING ='Payments made on behalf of employee'
5427                     then
5428                         l_TOT_COL1 := null;
5429                         l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5430                         l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5431                     else
5432                         l_TOT_COL1 := nvl(l_TOT_COL1,0) +
5433                                 nvl(summary_entries.LINE_COL1,nvl(summary_entries.LINE_COL3,0));
5434                         l_TOT_COL2 := nvl(l_TOT_COL2,0) + nvl(summary_entries.LINE_COL2,0);
5435                         l_TOT_COL3 := nvl(l_TOT_COL3,0) + nvl(summary_entries.LINE_COL3,0);
5436                     end if;
5437                    /* end if; */
5438                 end if;
5439                 if l_line_count > g_max_line then
5440                     hr_utility.trace('Line more than max line : ' || l_line_count);
5441                     if l_odd_page then
5442                        hr_utility.trace('Current page is odd page, resetting it to even');
5443                     else
5444                        hr_utility.trace('Current page is even page, resetting it to odd');
5445                     end if;
5446                    l_odd_page := not(l_odd_page);
5447                    l_line_count := l_line_count - g_max_line;
5448                    hr_utility.trace('New line count is : ' || l_line_count);
5449                 end if;
5450             end loop;
5451         end if;
5452        if l_loop_count <> 0
5453         then
5454             -- add last total line
5455             add_total_lines;
5456             l_line_count := l_line_count + 1;
5457             hr_utility.trace('Writing total line : ' || l_line_count);
5458             hr_utility.trace('Final Line : ' || l_line_count);
5459             if l_odd_page then
5460                hr_utility.trace('Current page is Odd page');
5461             else
5462                hr_utility.trace('Current page is Even page');
5463             end if;
5464 
5465             if l_line_count > g_max_line then
5466                hr_utility.trace('Line more than max line : ' || l_line_count);
5467                if l_odd_page then
5468                   hr_utility.trace('Current page is odd page, resetting it to even');
5469                else
5470                   hr_utility.trace('Current page is even page, resetting it to odd');
5471                end if;
5472                l_odd_page := not(l_odd_page);
5473                l_line_count := l_line_count - g_max_line;
5474                hr_utility.trace('New line count is : ' || l_line_count);
5475             end if;
5476 
5477             if l_odd_page then
5478                hr_utility.trace('Current page is Odd page');
5479                l_temp := ceil((g_max_line - l_line_count)/4) + 1;
5480                hr_utility.trace('Current line is : ' || l_line_count);
5481                hr_utility.trace('Writing more record (4 line / record) : ' || l_temp);
5482                for l_line_count in 0..l_temp loop
5483                   l_xfdf_intermetiate_var  :=
5484                       '<field name="'||'SECTION_TITLE'  ||'"><value>' ||null|| '</value></field>  ' ||
5485                       '<field name="'||'SECTION_HEADING'||'"><value>' ||null|| '</value></field>  ' ||
5486                       '<field name="'||'COL1_SDATE'     ||'"><value>' ||null|| '</value></field>  ' ||
5487                       '<field name="'||'COL1_EDATE'     ||'"><value>' ||null|| '</value></field>  ' ||
5488                       '<field name="'||'LINE_DESC'      ||'"><value>' ||null|| '</value></field>  ' ||
5489                       '<field name="'||'COL1_HEADING'   ||'"><value>' ||null|| '</value></field>  ' ||
5490                       '<field name="'||'COL2_HEADING'   ||'"><value>' ||null|| '</value></field>  ' ||
5491                       '<field name="'||'COL3_HEADING'   ||'"><value>' ||null|| '</value></field>  ' ||
5492                       '<field name="'||'LINE_START_D'   ||'"><value>' ||null|| '</value></field>  ' ||
5493                       '<field name="'||'LINE_END_D'     ||'"><value>' ||null|| '</value></field>  ' ||
5494                       '<field name="'||'LINE_DETAIL'    ||'"><value>' ||null|| '</value></field>  ' ||
5495                       '<field name="'||'LINE_COL1'      ||'"><value>' ||null|| '</value></field>  ' ||
5496                       '<field name="'||'LINE_COL2'      ||'"><value>' ||null|| '</value></field>  ' ||
5497                       '<field name="'||'LINE_COL3'      ||'"><value>' ||null|| '</value></field>  ' ||
5498                       '<field name="'||'LINE_TOTAL'     ||'"><value>' ||null|| '</value></field>  ' ||
5499                       '<field name="'||'TOT_COL1'       ||'"><value>' ||null|| '</value></field>  ' ||
5500                       '<field name="'||'TOT_COL2'       ||'"><value>' ||null|| '</value></field>  ' ||
5501                       '<field name="'||'TOT_COL3'       ||'"><value>' ||null|| '</value></field>  ' ;
5502                      dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5503                end loop;
5504             end if;
5505             -- this will ensure the xfdf string ends with the correct fields
5506             l_xfdf_intermetiate_var  :=  '</fields>  </xfdf>';
5507             dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5508         end if;
5509         DBMS_LOB.CREATETEMPORARY(l_xfdf_blob_str,true);
5510         clob_to_blob(l_xfdf_str,l_xfdf_blob_str);
5511         dbms_lob.close(l_xfdf_str);
5512         dbms_lob.freetemporary(l_xfdf_str);
5513         hr_utility.trace('blob length '|| dbms_lob.getlength(l_xfdf_blob_str));
5514         --   Adding this causes error in xdo so commented this
5515         --   DBMS_LOB.FREETEMPORARY(l_xfdf_blob_str);
5516         --hr_utility.trace_off;
5517         return l_xfdf_blob_str;
5518    end ;
5519   /*Added this function to generate pdf report for Address*/
5520   /*Bug No. 3201848*/
5521   function fetch_address_xfdf_blob (p_assignment_action_id Number) return blob
5522   is
5523         cursor csr_address_entries
5524         is
5525         select address_line1,
5526                address_line2,
5527                address_line3,
5528                town_or_city,
5529                postal_code,
5530                region_1
5531        from   per_addresses
5532        where  person_id = (
5533        select distinct person_id
5534        from   pay_assignment_actions paa,
5535               per_all_assignments_f  paf
5536        where  paa.assignment_action_id = p_assignment_action_id
5537        and    paf.assignment_id = paa.assignment_id)
5538        and    primary_flag = 'Y'
5539        and    sysdate between date_from and nvl(date_to, hr_general.end_of_time);
5540 
5541        cursor csr_person_name
5542        is
5543        select emp.action_information1             emp_name
5544        from   pay_action_information  emp
5545        where  emp.action_information_category   = 'EMPLOYEE DETAILS'
5546        and    emp.action_context_id             = p_assignment_action_id
5547        and    emp.action_context_type           = 'AAP';
5548 
5549         /*
5550         select emp.action_information1             emp_name
5551               ,adr.action_information5             adr_adress1
5552               ,adr.action_information6             adr_adress2
5553               ,adr.action_information7             adr_adress3
5554               ,adr.action_information8             adr_town
5555               ,adr.action_information12           adr_county
5556               ,adr.action_information9            adr_code
5557         from   pay_assignment_actions  paa
5558               ,pay_action_information  emp    -- Employee Details
5559               ,pay_action_information  adr    -- Address Details
5560               ,pay_action_information  prl    -- EMEA Payroll Info
5561         where  paa.assignment_action_id   = p_assignment_action_id
5562         and    emp.action_information_category   = 'EMPLOYEE DETAILS'
5563         and    emp.action_context_id             = paa.assignment_action_id
5564         and    emp.action_context_type           = 'AAP'
5565 --
5566         and    prl.action_information_category   = 'EMEA PAYROLL INFO'
5567         and    prl.action_context_id             = paa.assignment_action_id
5568         and    prl.action_context_type           = 'AAP'
5569 --
5570         and    adr.action_information_category   = 'ADDRESS DETAILS'
5571         and    adr.action_context_id             = paa.assignment_action_id
5572         and    adr.action_context_type           = 'AAP'
5573         and    adr.action_information14          = 'Employee Address';
5574         */
5575 --
5576          cursor csr_lookup(p_code Varchar2)
5577          is
5578          select hlu.meaning hlu_meaning
5579          from   hr_lookups hlu
5580          where  hlu.lookup_type='GB_COUNTY'
5581          and    hlu.lookup_code=p_code
5582          and    hlu.enabled_flag='Y';
5583 
5584          l_xfdf_str clob;
5585          l_xfdf_blob_str blob;
5586          l_xfdf_intermetiate_var varchar2(20000);
5587          l_adress1 pay_action_information.action_information5%type;
5588          l_adress2 pay_action_information.action_information6%type;
5589          l_adress3 pay_action_information.action_information7%type;
5590          l_town    pay_action_information.action_information8%type;
5591          l_county  pay_action_information.action_information12%type;
5592          l_employee_name pay_action_information.action_information1%type;
5593          l_code pay_action_information.action_information9%type;
5594          l_meaning hr_lookups.meaning%type;
5595    begin
5596         dbms_lob.createtemporary(l_xfdf_str,false,DBMS_LOB.CALL);
5597         dbms_lob.open(l_xfdf_str,dbms_lob.lob_readwrite);
5598         open csr_address_entries;
5599         fetch csr_address_entries into l_adress1,l_adress2,l_adress3,l_town,l_county,l_code;
5600         close csr_address_entries;
5601 
5602         open csr_person_name;
5603         fetch csr_person_name into l_employee_name;
5604         close csr_person_name;
5605 
5606         if l_code is not null
5607         then
5608            open csr_lookup(l_code);
5609            fetch csr_lookup into l_meaning;
5610            close csr_lookup;
5611         end if;
5612         l_xfdf_intermetiate_var  := '<?xml version = "1.0" encoding = "UTF-8"?>
5613                     <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
5614                        <fields> ' ||
5615                    ' <field name="'||'F_EMP_NAME'||'"><value>' || l_employee_name || '</value></field> ' ||
5616                    ' <field name="'||'F_ADDR1'||'"><value>'  || l_adress1 || '</value></field>  ' ||
5617                    ' <field name="'||'F_ADDR2'||'"><value>'  || l_adress2 || '</value></field>  ' ||
5618                    ' <field name="'||'F_ADDR3'||'"><value>'  || l_adress3 || '</value></field>  ' ||
5619                    ' <field name="'||'F_TOWN'||'"><value>'   || l_town || '</value></field>  ' ||
5620                    ' <field name="'||'F_COUNTY'||'"><value>' || ltrim(l_meaning || ' '|| l_county) || '</value></field>  ' ||
5621                    '</fields>  </xfdf>';
5622         dbms_lob.writeAppend( l_xfdf_str, length(l_xfdf_intermetiate_var) ,l_xfdf_intermetiate_var );
5623         DBMS_LOB.CREATETEMPORARY(l_xfdf_blob_str,true);
5624         clob_to_blob(l_xfdf_str,l_xfdf_blob_str);
5625         dbms_lob.close(l_xfdf_str);
5626         dbms_lob.freetemporary(l_xfdf_str);
5627         --   Adding this causes error in xdo so commented this
5628         --   DBMS_LOB.FREETEMPORARY(l_xfdf_blob_str);
5629         return l_xfdf_blob_str;
5630    end;
5631 
5632    FUNCTION write_magtape_records (p_arch_payroll_action_id   NUMBER,
5633                                    p_emp_ref_no               VARCHAR2,
5634                                    p_person_id                VARCHAR2,
5635                                    p_assignment_number    OUT NOCOPY VARCHAR2,
5636                                    p_INT_MAX_AMT_OUTSTANDING OUT NOCOPY VARCHAR2) RETURN NUMBER
5637    -- return 1 if the record is to be written to magtape file
5638    -- else 0
5639    IS
5640         CURSOR get_assignment_action_id
5641         IS
5642         SELECT /*+ ordered  */
5643                paa.assignment_action_id,
5644                paf.ASSIGNMENT_TYPE
5645                --  Added paf.ASSIGNMENT_TYPE as we need to write primary assign number in
5646                --  magtape if the primary and sec both have the p11d benefits
5647                -- In case if only secondary have benefits then we may write
5648                -- any  secondary assignment number in the magtape
5649         FROM   per_assignments_f paf,
5650                pay_assignment_actions paa,
5651                pay_action_information pai_comp
5652         WHERE  paf.person_id = p_person_id
5653         AND    paa.assignment_id = paf.assignment_id
5654         AND    paa.payroll_action_id = p_arch_payroll_action_id
5655         AND    pai_comp.action_context_id = paa.assignment_action_id
5656         AND    pai_comp.action_information_category = 'EMEA PAYROLL INFO'
5657         AND    pai_comp.action_information6 = p_emp_ref_no
5658         order by paf.ASSIGNMENT_TYPE, paa.assignment_action_id;
5659 
5660 
5661         CURSOR sum_marors_values
5662         IS
5663         SELECT /*+ ordered  */
5664               SUM (TO_NUMBER (NVL (pai.action_information7, '0')))
5665         FROM  per_assignments_f paf,
5666               pay_assignment_actions paa,
5667               pay_action_information pai_comp,
5668               pay_action_information pai
5669         WHERE paf.person_id = p_person_id
5670         AND   paa.payroll_action_id = p_arch_payroll_action_id
5671         AND   paa.assignment_id = paf.assignment_id
5672         AND   pai_comp.action_context_id = paa.assignment_action_id
5673         AND   pai_comp.action_information_category = 'EMEA PAYROLL INFO'
5674         AND   pai_comp.action_information6 = p_emp_ref_no
5675         AND   pai.action_context_id = paa.assignment_action_id
5676         AND   pai.action_information_category = 'MARORS'
5677         AND   pai.action_context_id = pai_comp.action_context_id;
5678 
5679         CURSOR fetch_ben_values (p_assignment_action_id   NUMBER,
5680                                  p_action_info_catg       VARCHAR2)
5681         IS
5682         SELECT *
5683         FROM   pay_action_information pai
5684         WHERE  pai.action_context_id = p_assignment_action_id
5685         AND    pai.action_information_category = p_action_info_catg;
5686 
5687         l_ce_values_a            fetch_ben_values%ROWTYPE;
5688         l_ce_values_b            fetch_ben_values%ROWTYPE;
5689         l_ce_values_c            fetch_ben_values%ROWTYPE;
5690         l_emp_details            fetch_ben_values%ROWTYPE;
5691         l_assignment_action_id   NUMBER (15);
5692         l_write_to_magtape       NUMBER  := 0;
5693         l_marors_ce              NUMBER;
5694         l_assignment_number      varchar2(30) ;
5695         l_dummy                  varchar2(30);
5696         l_rep_run                varchar2(10);
5697 
5698    BEGIN
5699 
5700         PAY_GB_P11D_ARCHIVE_SS.get_parameters(p_payroll_action_id => p_arch_payroll_action_id,
5701                                               p_token_name        => 'Rep_Run',
5702                                               p_token_value       => l_rep_run);
5703 
5704         OPEN get_assignment_action_id;
5705         FETCH get_assignment_action_id INTO l_assignment_action_id,l_dummy ;
5706         CLOSE get_assignment_action_id;
5707 
5708         OPEN fetch_ben_values (l_assignment_action_id,
5709                                'GB P11D ASSIGNMENT RESULTA');
5710         FETCH fetch_ben_values INTO l_ce_values_a;
5711         CLOSE fetch_ben_values;
5712 
5713         OPEN fetch_ben_values (l_assignment_action_id,
5714                                'GB P11D ASSIGNMENT RESULTB');
5715         FETCH fetch_ben_values INTO l_ce_values_b;
5716         CLOSE fetch_ben_values;
5717 
5718         OPEN fetch_ben_values (l_assignment_action_id,
5719                                'GB P11D ASSIGNMENT RESULTC');
5720         FETCH fetch_ben_values INTO l_ce_values_c;
5721         CLOSE fetch_ben_values;
5722 
5723         OPEN fetch_ben_values (l_assignment_action_id,
5724                                'EMPLOYEE DETAILS');
5725         FETCH fetch_ben_values INTO l_emp_details;
5726         CLOSE fetch_ben_values;
5727 
5728         p_assignment_number :=NVL(UPPER(l_emp_details.action_information14), ' ');
5729 
5730         IF to_number(l_rep_run) < 2005
5731         THEN
5732             IF    TO_NUMBER (l_ce_values_a.action_information4) > 0
5733                OR TO_NUMBER (l_ce_values_a.action_information6) > 0
5734                OR TO_NUMBER (l_ce_values_a.action_information7) > 0
5735                OR TO_NUMBER (l_ce_values_a.action_information10) > 0
5736                OR TO_NUMBER (l_ce_values_a.action_information11) > 0
5737                OR TO_NUMBER (l_ce_values_a.action_information12) > 0
5738                OR TO_NUMBER (l_ce_values_a.action_information13) > 0
5739                OR TO_NUMBER (l_ce_values_a.action_information14) > 0
5740                OR TO_NUMBER (l_ce_values_a.action_information15) > 0
5741                OR TO_NUMBER (l_ce_values_a.action_information18) > 0
5742                OR TO_NUMBER (l_ce_values_a.action_information19) > 0
5743                OR TO_NUMBER (l_ce_values_a.action_information22) > 0
5744                OR TO_NUMBER (l_ce_values_a.action_information26) > 0
5745                OR l_ce_values_a.action_information27 = 'Y'
5746                -- moving the check for free loans below as it is base don combinaiton
5747                -- of values
5748                /* OR TO_NUMBER (l_ce_values_a.action_information28) >= 0 -- this is int
5749                    -- free loan awaiting direction from IR */
5750                OR TO_NUMBER (l_ce_values_b.action_information4) > 0
5751                OR TO_NUMBER (l_ce_values_b.action_information8) > 0
5752                OR TO_NUMBER (l_ce_values_b.action_information9) > 0
5753                OR TO_NUMBER (l_ce_values_b.action_information12) > 0
5754                OR TO_NUMBER (l_ce_values_b.action_information15) > 0
5755                OR TO_NUMBER (l_ce_values_b.action_information19) > 0
5756                OR TO_NUMBER (l_ce_values_b.action_information22) > 0
5757                OR TO_NUMBER (l_ce_values_b.action_information25) > 0
5758                OR TO_NUMBER (l_ce_values_b.action_information29) > 0
5759             THEN
5760                 l_write_to_magtape := 1;
5761             END IF;
5762             -- chk for marors
5763             IF TO_NUMBER (nvl(l_ce_values_c.action_information15,'0')) >= 1 and
5764                TO_NUMBER (nvl(l_ce_values_c.action_information22,'0')) <> 0
5765             THEN
5766                 l_write_to_magtape := 1;
5767             END IF;
5768 
5769             if TO_NUMBER (l_ce_values_a.action_information28) > 0 and
5770                TO_NUMBER (l_ce_values_c.action_information23) > 5000
5771             then
5772                 l_write_to_magtape := 1;
5773             end if;
5774             p_INT_MAX_AMT_OUTSTANDING := nvl(l_ce_values_c.action_information23,'0');
5775         ELSE
5776             IF    TO_NUMBER (l_ce_values_a.action_information4) > 0
5777                OR TO_NUMBER (l_ce_values_a.action_information6) > 0
5778                OR TO_NUMBER (l_ce_values_a.action_information7) > 0
5779                OR TO_NUMBER (l_ce_values_a.action_information10) > 0
5780                OR TO_NUMBER (l_ce_values_a.action_information11) > 0
5781                OR TO_NUMBER (l_ce_values_a.action_information12) > 0
5782                OR TO_NUMBER (l_ce_values_a.action_information13) > 0
5783                OR TO_NUMBER (l_ce_values_a.action_information14) > 0
5784                OR TO_NUMBER (l_ce_values_a.action_information15) > 0
5785                OR TO_NUMBER (l_ce_values_a.action_information18) > 0
5786                OR TO_NUMBER (l_ce_values_a.action_information19) > 0
5787                OR TO_NUMBER (l_ce_values_a.action_information22) > 0
5788                OR TO_NUMBER (l_ce_values_a.action_information26) > 0
5789                -- moving the check for free loans below as it is base don combinaiton
5790                -- of values
5791                /* OR TO_NUMBER (l_ce_values_a.action_information28) >= 0 -- this is int
5792                -- free loan awaiting direction from IR */
5793                OR TO_NUMBER (l_ce_values_b.action_information4) > 0
5794                OR TO_NUMBER (l_ce_values_b.action_information8) > 0
5795                OR TO_NUMBER (l_ce_values_b.action_information9) > 0
5796                OR TO_NUMBER (l_ce_values_b.action_information12) > 0
5797                OR TO_NUMBER (l_ce_values_b.action_information15) > 0
5798                OR TO_NUMBER (l_ce_values_b.action_information19) > 0
5799                OR TO_NUMBER (l_ce_values_b.action_information22) > 0
5800                OR TO_NUMBER (l_ce_values_b.action_information25) > 0
5801                OR TO_NUMBER (l_ce_values_b.action_information29) > 0
5802             THEN
5803                 l_write_to_magtape := 1;
5804             END IF;
5805             -- chk for marors
5806             IF TO_NUMBER (nvl(l_ce_values_c.action_information13,'0')) >= 1 and
5807                TO_NUMBER (nvl(l_ce_values_c.action_information20,'0')) <> 0
5808             THEN
5809                 l_write_to_magtape := 1;
5810             END IF;
5811 
5812             if TO_NUMBER (l_ce_values_a.action_information27) > 0 and
5813                TO_NUMBER (l_ce_values_c.action_information21) > 5000
5814             then
5815                 l_write_to_magtape := 1;
5816             end if;
5817             p_INT_MAX_AMT_OUTSTANDING := nvl(l_ce_values_c.action_information21,'0');
5818         END IF;
5819         RETURN l_write_to_magtape;
5820    END;
5821 end hr_gb_process_p11d_entries_pkg;