DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_ZA_IRP5_ARCHIVE_PKG

Source


1 package body pay_za_irp5_archive_pkg as
2 /* $Header: pyzaarch.pkb 120.14.12010000.2 2008/08/14 07:24:35 rbabla ship $ */
3 sql_range          varchar2(4000);
4 prev_asg_id        number;
5 g_size             number;           -- Used to keep track of the size of the IRP5 file
6 g_file_count       number;           -- Total Number of all records on file
7 g_employer_count   number;           -- Total Number of all records for the employer
8 g_employer_code    number;           -- Total code value for the employer
9 g_employer_amounts number;           -- Total amounts for the employer
10 g_previous_code    varchar2(256);    -- The last SARS code that was written out
11 g_ls_assid         number;           -- The current Assignment ID used by the Lump Sum Function
12 g_ls_assactid      number;           -- The current Assignment Action ID used by the Lump Sum Function
13 g_ls_size          number;           -- The size of the PLSQL table used by the Lump Sum Function
14 g_ls_index         number;           -- An index into the PLSQL table used by the Lump Sum Function
15 g_ls_indicator     varchar2(1);      -- The Lump Sum Indicator used by the Lump Sum Function
16 type char_table is table of varchar2(60)
17      index by binary_integer;
18 g_ls_table         char_table;       -- The PL_SQL table used by the Lump Sum Function
19 
20 /*--------------------------------------------------------------------------
21   Name      : range_cursor
22   Purpose   : This returns the select statement that is used to create the
23               range rows.
24   Arguments :
25   Notes     : The range cursor determines which people should be processed.
26               The normal practice is to include everyone, and then limit
27               the list during the assignment action creation.
28 --------------------------------------------------------------------------*/
29 procedure range_cursor
30 (
31    pactid in  number,
32    sqlstr out nocopy varchar2
33 )  is
34 begin
35 
36    sql_range :=
37 'SELECT distinct ASG.person_id
38 FROM   per_assignments_f   ASG,
39        pay_payrolls_f      PPY,
40        pay_payroll_actions PPA
41 WHERE  PPA.payroll_action_id     = :payroll_action_id
42   AND  ASG.business_group_id     = PPA.business_group_id
43   AND  ASG.assignment_type       = ''E''
44   AND  PPY.payroll_id            = ASG.payroll_id
45 ORDER  BY ASG.person_id';
46 
47    sqlstr := sql_range;
48 
49 end range_cursor;
50 
51 /*--------------------------------------------------------------------------
52   Name      : action_creation
53   Purpose   : This creates the assignment actions for a specific chunk.
54   Arguments :
55   Notes     :
56 --------------------------------------------------------------------------*/
57 procedure action_creation
58 (
59    pactid    in number,
60    stperson  in number,
61    endperson in number,
62    chunk     in number
63 ) is
64 
65 -- This cursor returns all assignments for which processing took place
66 -- in the Tax Year.
67 -- Note: This cursor does not date effectively join to per_assignments_f.
68 --       Duplicate assignments are, however, removed in the cursor loop.
69 /*
70    "The cursor looks for assignments that were processed
71    "on the specific payroll that was given in the TYE Archiver SRS -
72    "BUT, this means it will find the Assignment for ALL the payrolls it was on during
73    "the Tax year (and for which processing took place), whenever the TYE Archiver SRS
74    "is run for each of those payrolls, and not only the last payroll that the
75    "assignment was on at TYE.
76    "This needs to change to only pick up Assignments that are on the specific payroll,
77    "AT TAX YEAR END, that was given in the TYE Archiver SRS
78    "- it will resolve the problem of duplicate certificates
79    "being produced for Assignments where the payroll had been changed during
80    "the Tax Year. "Duplicates" is meant in the sense that Certificates are produced for
81    "such an Assignment when the Tax Year End is run for EACH of the payrolls that it
82    "was on during the Tax Year - which is incorrect, it should only be done for the
83    "payroll that the assignment was on AT TAX YEAR END.
84    "As follows:
85 */
86 --Modified cursor get_asg to date effectively select assignments as at Tax Year End
87 --and to limit them to where the payroll is equal to the specific payroll that was
88 --given in the TYE Archiver SRS
89 cursor get_asg(p_payroll_id pay_all_payrolls_f.payroll_id%TYPE) is
90    SELECT /*+ INDEX(asg PER_ASSIGNMENTS_F_N12) */
91           /* we used the above hint to always ensure that the use the person_id
92              index on per_assignments_f, otherwise, it is feasible the CBO may decide to
93              choose the N7 (payroll_id) index due to it being a bind */
94           asg.person_id     person_id
95         , asg.assignment_id assignment_id
96      FROM
97           per_all_assignments_f asg
98         , pay_all_payrolls_f    ppf
99         , pay_payroll_actions   ppa_arch
100     WHERE
101           asg.business_group_id + 0 = ppa_arch.business_group_id
102       AND asg.person_id BETWEEN stperson
103                             AND endperson
104       AND ppf.payroll_id      = p_payroll_id
105       AND ppf.payroll_id      = asg.payroll_id
106       AND
107         ( ppa_arch.effective_date BETWEEN asg.effective_start_date
108                                       AND asg.effective_end_date
109           OR
110            ( asg.effective_end_date <= ppa_arch.effective_date
111              AND asg.effective_end_date =
112                ( SELECT MAX(asg2.effective_end_date)
113                    FROM per_all_assignments_f asg2
114                   WHERE asg2.assignment_id  = asg.assignment_id
115                )
116            )
117         )
118       AND ppa_arch.payroll_action_id = pactid
119       AND EXISTS (SELECT /*+ ORDERED */
120                          /* the ordered hint will force the paa table to be joined to first */
121                          NULL
122                     FROM pay_assignment_actions     paa
123                        , pay_payroll_actions        ppa
124                    WHERE paa.assignment_id        = asg.assignment_id
125                      AND ppa.effective_date BETWEEN ppa_arch.start_date
126                                                 AND ppa_arch.effective_date
127                      AND ppa.action_type         IN ('R', 'Q', 'V', 'B', 'I')
128                      AND ppf.payroll_id           = ppa.payroll_id
129                      AND paa.payroll_action_id    = ppa.payroll_action_id)
130    order by 1, 2
131    for update of asg.assignment_id;
132 
133 -- Note: A Run Result source_type of E means the entry was a normal entry,
134 --       and not an indirect result
135 -- Note: The source_id is the Source Element Entry
136 /*
137    "The TYE Archiver Payroll Action is tied to the specific payroll that was given
138    "in the TYE Archiver SRS - thus, whenever the pay_payroll_actions.payroll_id is used
139    "subsequently, it will limit the query to ONLY processing that took place on the
140    "last payroll the assignment was on at TYE - thus, for e.g. cursor lumpsum, in which any
141    "Lump Sums run on the earlier payroll will NOT be found because ppa_arch.payroll_id is used.
142    "
143    "If cursor lumpsum is changed to not use ppa_arch.payroll_id, it does find the
144    "Lump Sums run on an earlier payroll, as follows:
145 */
146 --Modified cursor lumpsum to find 'ZA_Tax_On_Lump_Sums' processing that took place on
147 --earlier payrolls for the assignment also, not only for the assignment's payroll as at TYE.
148 --It now looks for all ASSIGNMENT ACTIONS for the Assignment in which the
149 --'ZA_Tax_On_Lump_Sums' element was processed, not for PAYROLL ACTIONS
150 --for the Payroll as at Tax Year End anymore.
151 cursor lumpsum (pay_action_id number, asg_id number) is
152 select distinct pac.context_value
153    from   pay_action_contexts    pac,
154           pay_assignment_actions paa,
155           pay_payroll_actions    ppa,
156 	  ff_contexts            ffc
157    where  paa.assignment_id = asg_id
158      and  paa.payroll_action_id = ppa.payroll_action_id
159      and  ppa.action_type in ('R', 'Q', 'V', 'B', 'I') -- added for 5165859
160      AND  pac.assignment_Action_id = paa.assignment_action_id
161      And  pac.context_value <> 'To Be Advised'
162      and  ffc.context_name = 'SOURCE_TEXT'
163      and  ffc.context_id = pac.context_id
164      and  ppa.effective_date >= (select ppa_arch.start_date
165                                    from pay_payroll_actions ppa_arch
166                                   where ppa_arch.payroll_action_id = pay_action_id)
167      and  ppa.effective_date <= (select ppa_arch.effective_date
168                                    from pay_payroll_actions ppa_arch
169                                   where ppa_arch.payroll_action_id = pay_action_id);
170 
171 asg_set_id   number;
172 person_id    number;
173 l_payroll_id number;
174 leg_param    pay_payroll_actions.legislative_parameters%type;
175 asg_include  boolean;
176 lockingactid number;
177 v_incl_sw    char;
178 l_ppa_payroll_id pay_payroll_actions.payroll_id%TYPE;
179 
180 BEGIN
181 
182 --  hr_utility.trace_on(null, 'TYE2005');
183 
184    -- Get the legislative parameters from the archiver payroll action
185    select legislative_parameters,payroll_id
186    into   leg_param,l_ppa_payroll_id
187    from   pay_payroll_actions
188    where  payroll_action_id = pactid;
189 
190    asg_set_id   := get_parameter('ASG_SET_ID', leg_param);
191    person_id    := get_parameter('PERSON_ID',  leg_param);
192    l_payroll_id := get_parameter('PAYROLL_ID', leg_param);
193 
194    -- Update the Payroll Action with the Payroll ID
195    --
196    IF l_ppa_payroll_id IS NULL THEN
197       update pay_payroll_actions
198          set payroll_id = l_payroll_id
199        where payroll_action_id = pactid;
200    END IF;
201 
202    if  asg_set_id is not null then
203 -- TAR37293; need to find out if assignments in assignment-set are set to Include or Exclude.
204        begin
205          select distinct include_or_exclude
206          into v_incl_sw
207          from   hr_assignment_set_amendments
208          where  assignment_set_id = asg_set_id;
209        exception
210          when no_data_found  then
211 -- TAR37293;default to Include, should not go here though.
212               v_incl_sw := 'I';
213        end;
214    end if;
215    for asgrec in get_asg(l_payroll_id) loop
216 
217       hr_utility.set_location('ASS: ' || to_char(asgrec.assignment_id), 5);
218       asg_include := TRUE;
219 
220       -- Remove duplicate assignments
221       if prev_asg_id <> asgrec.assignment_id then
222 
223          prev_asg_id := asgrec.assignment_id;
224 
225          if asg_set_id is not null then
226 
227             declare
228                inc_flag varchar2(5);
229             begin
230                select include_or_exclude
231                into   inc_flag
232                from   hr_assignment_set_amendments
233                where  assignment_set_id = asg_set_id
234                  and  assignment_id = asgrec.assignment_id;
235 
236                if inc_flag = 'E' then
237                   asg_include := FALSE;
238                end if;
239             exception
240 -- TAR37293; goes through this exception, for each assignment in the payroll but not in the
241 -- relevant assignment_set.
242                when no_data_found then
243                     if  v_incl_sw = 'I' then
244                         asg_include := FALSE;
245                     else
246                         asg_include := TRUE;
247                     end if;
248             end ;
249 
250          end if;
251 
252          if person_id is not null then
253             if person_id <> asgrec.person_id then
254                asg_include := FALSE;
255             end if;
256          end if;
257 
258             -- Process Lump Sums
259          if asg_include = TRUE then
260             for lumprec in lumpsum(pactid, asgrec.assignment_id) loop
261 
262                hr_utility.set_location('LUMP SUM:' || to_char(asgrec.assignment_id),10);
263 
264                select pay_assignment_actions_s.nextval
265                into   lockingactid
266                from   dual;
267               hr_utility.set_location('lockingactidM:' || lockingactid,10);
268                -- Insert Lump Sums into pay_assignment_actions
269                hr_nonrun_asact.insact
270                (
271                   lockingactid => lockingactid,
272                   assignid     => asgrec.assignment_id,
273                   pactid       => pactid,
274                   chunk        => chunk,
275                   greid        => null,
276                   source_act   => null -- for advance retro
277                 );
278 
279             end loop;
280 -- For Normal
281 
282             select pay_assignment_actions_s.nextval
283             into   lockingactid
284             from   dual;
285 
286             -- Insert assignment into pay_assignment_actions
287             hr_nonrun_asact.insact
288             (
289                lockingactid,
290                asgrec.assignment_id,
291                pactid,
292                chunk,
293                null
294             );
295 
296          end if;
297 
298       end if;
299 
300    end loop;
301 --   hr_utility.trace_off;
302 
303 end action_creation;
304 
305 /*--------------------------------------------------------------------------
306   Name      : archive_data
307   Purpose   : This sets up the contexts needed for the live (non-archive)
308               database items
309   Arguments :
310   Notes     : Every possible context for a specific assignment action has to
311               be added to the PL/SQL table
312 --------------------------------------------------------------------------*/
313 procedure archive_data
314 (
315    p_assactid       in number,
316    p_effective_date in date
317 ) is
318 
319 asgid        pay_assignment_actions.assignment_id%type;
320 l_count      number;
321 l_flag       number;
322 l_context_no number;
323 aaseq        number;
324 aaid         number;
325 l_pact_id    number;
326 paid         number;
327 l_payroll_id number;
328 l_eff_date   date;
329 l_dir_no     number;
330 l_main_crt_flag number;
331 
332 -- Deductions SARS codes
333 cursor cursars is
334    select distinct code
335    from   pay_za_irp5_bal_codes
336    where  code in (4001, 4002, 4003, 4004, 4005, 4006, 4007, 4018);
337 
338 -- A list of distinct Clearance Numbers
339 /* For 4346920  */
340 
341 CURSOR curclr (p_assignment_Action_id IN number
342                ) is
343   Select distinct context_value clearance_number
344   FROM PAY_ACTION_CONTEXTS PAC,
345        ff_contexts         fcon
346 Where pac.context_id               = fcon.context_id
347 AND   fcon.context_name            ='SOURCE_NUMBER'
348 And PAC.ASSIGNMENT_ACTION_ID in
349 (
350      Select paa_all.assignment_Action_id from
351         pay_assignment_actions paa,
352         pay_assignment_actions paa_all,
353         pay_payroll_actions ppa,
354         per_time_periods    ptp
355      Where paa.assignment_action_id = p_assignment_Action_id
356         and paa_all.assignment_id = paa.assignment_id
357         and paa_all.payroll_action_id = ppa.payroll_action_id
358         and ppa.time_period_id = ptp.time_period_id
359         and ptp.end_date > add_months(p_effective_date,-12)
360         and ptp.end_date <=   p_effective_date
361         and ppa.action_type in ('R', 'Q','V', 'B', 'I') -- added for 5165859
362  )
363 UNION
364 Select '99999999999'
365 FROM dual;
366 
367 -- Cursor for Directive Number Context
368 /*CURSOR curdirnum (p_assignment_action_id IN number) is
369    Select max(context_value) directive_number
370    From
371         PAY_ACTION_CONTEXTS PAC,
372         ff_contexts         fcon
373    Where PAC.assignment_action_id     = p_assignment_action_id
374    AND   pac.context_id               = fcon.context_id
375    AND   fcon.context_name            ='SOURCE_TEXT'; */
376 
377 CURSOR curdirnum (p_ass_id IN NUMBER ,p_pact_id IN number) is
378   SELECT DISTINCT pac.context_value directive_number
379    from   pay_action_contexts    pac,
380           pay_assignment_actions paa,
381           pay_payroll_actions    ppa,
382 	  ff_contexts            ffc
383    where  paa.assignment_id = p_ass_id
384      and  paa.payroll_action_id = ppa.payroll_action_id
385      and  ppa.action_type in ('R', 'Q', 'V', 'B', 'I') -- added for 5165859
386      AND  pac.assignment_Action_id = paa.assignment_action_id
387      And  pac.context_value <> 'To Be Advised'
388      and  ffc.context_name = 'SOURCE_TEXT'
389      and  ffc.context_id = pac.context_id
390      and  ppa.effective_date >= (select ppa_arch.start_date
391                                    from pay_payroll_actions ppa_arch
392                                   where ppa_arch.payroll_action_id = p_pact_id)
393      and  ppa.effective_date <= (select ppa_arch.effective_date
394                                    from pay_payroll_actions ppa_arch
395                                   where ppa_arch.payroll_action_id = p_pact_id);
396 
397 begin
398 l_main_crt_flag :=0;
399 --hr_utility.trace_on(null,'TYE2005');
400 hr_utility.set_location('archive_data ',1);
401 hr_utility.set_location('p_assactid ' ||p_assactid,1);
402 hr_utility.set_location('p_effective_date ' ||to_char(p_effective_date,'DD-MON-YYYY'),1);
403    -- Get some contexts
404    -- Note: The last entry in this tax year is chosen. It might happen that a person
405    --       transfers between payrolls, but this is not catered for; since he is
406    --       supposed to start on a new assignment number.
407    select aa.assignment_id,
408           paf.payroll_id,
409           ppa.effective_date,
410           ppa.payroll_action_id
411    into   asgid, l_payroll_id, l_eff_date, l_pact_id
412    from   pay_assignment_actions aa,
413           pay_payroll_actions    ppa,
414           per_assignments_f      paf
415    where  aa.assignment_action_id = p_assactid
416      and  aa.assignment_id = paf.assignment_id
417      and  ppa.payroll_action_id = aa.payroll_action_id
418      and  paf.effective_start_date =
419      (
420         select max(paf2.effective_start_date)
421         from   per_assignments_f paf2
422         where  paf2.effective_start_date <= ppa.effective_date
423         and    paf2.assignment_id = aa.assignment_id
424      );
425 
426 hr_utility.set_location('l_pact_id is ' || l_pact_id, 999);
427 
428    -- Clear the PL/SQL table that contains the contexts
429    l_context_no := pay_archive.g_context_values.sz;
430    hr_utility.set_location('l_context_no ' ||l_context_no,1);
431    for i in 1..l_context_no loop
432 
433 
434 
435       pay_archive.g_context_values.name(i)  := NULL;
436       pay_archive.g_context_values.value(i) := NULL;
437 
438    end loop;
439 
440    pay_archive.g_context_values.sz := 0;
441    l_count := 0;
442 
443    /* Set up the assignment id, date earned and payroll id contexts */
444    l_count := l_count + 1;
445    pay_archive.g_context_values.name(l_count)  := 'ASSIGNMENT_ID';
446    pay_archive.g_context_values.value(l_count) := asgid;
447 hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
448 hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
449 
450 
451    l_count := l_count + 1;
452    pay_archive.g_context_values.name(l_count)  := 'PAYROLL_ID';
453    pay_archive.g_context_values.value(l_count) := l_payroll_id;
454 
455 hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
456 hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
457 
458    l_count := l_count + 1;
459    pay_archive.g_context_values.name(l_count)  := 'DATE_EARNED';
460    pay_archive.g_context_values.value(l_count) := l_eff_date;
461 hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
462 hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
463    -- Select the maximum action_sequence of an assignment action, for which
464    -- a ZA_Tax_On_Lump_Sums element was processed in the same period, and
465    -- for which a previous archive assignment action did not archive of the
466    -- same period into A_PAY_PROC_PERIOD_ID
467 /*
468 "This will not select the processing of any ZA_Tax_On_Lump_Sums that took place for this
469 "Assignment while it was still on an earlier Payroll.
470 "Thus, modified to not limit the search to Lump Sum processing that took place on the
471 "Payroll that the assignment was on at Tax Year End. Instead it will also look for
472 "Lump Sum processing that took place on earlier payrolls for this assignment
473 */
474 /*
475 As part of Lump Sum Enhancement the Assignment_action_id is stored
476 in the table pay_assignment_actions during action_creation which will be used here
477 */
478 Select count(*)
479    into   l_main_crt_flag
480     From pay_assignment_actions paa_arch
481     Where paa_arch.assignment_action_id > p_assactid
482     AND   paa_arch.payroll_action_id = l_pact_id
483     AND   paa_arch.assignment_id = asgid;
484 
485 
486    -- Note: It is important that the Main Certificate has a higher action_sequence,
487    --       since this is needed for the Lump Sum Database Item. The Report can,
488    --       however sort by assignment_id asc, assignment_action_id desc to avoid
489    --       printing the Lump Sum Certificates before the Main Certificate
490 
491       select max(paa.action_sequence)
492       into   aaseq
493       from   pay_assignment_actions     paa,
494              pay_payroll_actions        ppa
495       where  paa.assignment_id = asgid
496         and  paa.payroll_action_id = ppa.payroll_action_id
497         and  ppa.action_type IN ('R', 'Q', 'V', 'B', 'I')
498         and  ppa.effective_date <= p_effective_date;
499 
500 
501 
502    select assignment_action_id, payroll_action_id
503    into   aaid, paid
504    from   pay_assignment_actions
505    where  assignment_id = asgid
506      and  action_sequence = aaseq;
507 
508    -- Assignment Action ID of a max(action_sequence) Payroll Run
509    l_count := l_count + 1;
510    pay_archive.g_context_values.name(l_count)  := 'ASSIGNMENT_ACTION_ID';
511    pay_archive.g_context_values.value(l_count) := aaid;
512    pay_archive.balance_aa := aaid;
513    hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
514    hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
515 
516    l_count := l_count + 1;
517    pay_archive.g_context_values.name(l_count)  := 'PAYROLL_ACTION_ID';
518    pay_archive.g_context_values.value(l_count) := paid;
519    hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
520    hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
521 
522    -- Save the current count
523    l_flag := l_count;
524 
525    -- Populate the PL/SQL table with Clearance Numbers
526    -- execute cursor only if the certificate is main certificate
527    IF l_main_crt_flag = 0 then
528       for clrrev in curclr(aaid)  loop
529          l_count := l_count + 1;
530          pay_archive.g_context_values.name(l_count)  := 'SOURCE_NUMBER';
531          pay_archive.g_context_values.value(l_count) := clrrev.clearance_number;
532          hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
533          hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
534       end loop;
535    END if;
536    -- Make sure that at least one Clearance Number exist,
537    -- otherwise create a dummy one
538    if l_flag = l_count then
539 
540       l_count := l_count + 1;
541       pay_archive.g_context_values.name(l_count)  := 'SOURCE_NUMBER';
542       pay_archive.g_context_values.value(l_count) := '99999999999';
543       hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),2);
544       hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),2);
545    end if;
546    l_flag := l_count;
547    l_dir_no :=1;
548 
549    IF l_main_crt_flag > 0 then
550       for dirnumrev in curdirnum (asgid,l_pact_id) loop
551          IF l_main_crt_flag = l_dir_no then
552             l_count := l_count + 1;
553             pay_archive.g_context_values.name(l_count)  := 'SOURCE_TEXT';
554             pay_archive.g_context_values.value(l_count) := dirnumrev.directive_number;
555             hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),1);
556             hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),1);
557          END if;
558          l_dir_no := l_dir_no +1;
559       end loop;
560    -- Setting default Tax directive Number
561       if l_flag = l_count then
562         l_count := l_count + 1;
563         pay_archive.g_context_values.name(l_count)  := 'SOURCE_TEXT';
564         pay_archive.g_context_values.value(l_count) := 'To Be Advised';
565         hr_utility.set_location('pay_archive.g_context_values.name(l_count) ' ||pay_archive.g_context_values.name(l_count),2);
566         hr_utility.set_location('pay_archive.g_context_values.value(l_count) ' ||pay_archive.g_context_values.value(l_count),2);
567       end if;
568    else
569 -- setting Context for Main Certificate
570         l_count := l_count + 1;
571         hr_utility.set_location('setting Context for Main Certificate ' ,3);
572         pay_archive.g_context_values.name(l_count)  := 'SOURCE_TEXT';
573         pay_archive.g_context_values.value(l_count) := 'To Be Advised';
574 
575    END if;
576 
577 
578    l_main_crt_flag := 0;
579 
580    -- Populate the PL/SQL table with Deduction SARS codes
581    for sarrec in cursars loop
582       l_count := l_count + 1;
583       pay_archive.g_context_values.name(l_count)  := 'SOURCE_ID';
584       pay_archive.g_context_values.value(l_count) := sarrec.code;
585    end loop;
586 
587    pay_archive.g_context_values.sz := l_count;
588 --hr_utility.trace_off;
589 
590 end archive_data;
591 
592 /*--------------------------------------------------------------------------
593   Name      : archinit
594   Purpose   : This procedure can be used to perform an initialisation
595               section
596   Arguments :
597   Notes     :
598 --------------------------------------------------------------------------*/
599 procedure archinit
600 (
601    p_payroll_action_id in NUMBER
602 )  is
603    l_req_id NUMBER ;
604 begin
605    NULL ;
606 END archinit ;
607 
608 procedure archdinit
609 (
610    p_payroll_action_id in NUMBER
611 )  is
612    l_req_id NUMBER ;
613    l_start_date DATE;
614    l_end_date DATE;
615    leg_param pay_payroll_actions.legislative_parameters%type;
616 begin
617    select legislative_parameters
618    into   leg_param
619    from   pay_payroll_actions
620    where  payroll_action_id = p_payroll_action_id;
621 
622    l_start_date  := to_date(get_parameter('START_DATE', leg_param),'YYYY/MM/DD hh24:mi:ss');
623    l_end_date    := to_date(get_parameter('END_DATE',  leg_param),'YYYY/MM/DD hh24:mi:ss');
624    l_req_id      := fnd_request.submit_request( 'PAY', -- application
625         'PYZATYVL', -- program
626         'Create Tax Year End exception log',  -- description
627         NULL,                         -- start_time
628         NULL,                         -- sub_request
629         p_payroll_action_id,l_start_date,l_end_date,chr(0),-- Start of Parameters or Arguments
630         '','','','','','',
631         '','','','','','','','','','',
632         '','','','','','','','','','',
633         '','','','','','','','','','',
634         '','','','','','','','','','',
635         '','','','','','','','','','',
636         '','','','','','','','','','',
637         '','','','','','','','','','',
638         '','','','','','','','','','',
639         '','','','','','','','','','');
640 
641 
642      IF (l_req_id = 0) THEN
643          FND_FILE.PUT_LINE(FND_FILE.LOG, 'Unable to Create Tax Certificate Exception Log');
644      END IF;
645 end archdinit;
646 
647 /*--------------------------------------------------------------------------
648   Name      : get_parameter
649   Purpose   : Returns a legislative parameter
650   Arguments :
651   Notes     : The legislative parameter field must be of the form:
652               PARAMETER_NAME=PARAMETER_VALUE. No spaces is allowed in either
653               the PARAMETER_NAME or the PARAMETER_VALUE.
654 --------------------------------------------------------------------------*/
655 function get_parameter
656 (
657    name        in varchar2,
658    parameter_list varchar2
659 )  return varchar2 is
660 
661 start_ptr number;
662 end_ptr   number;
663 token_val pay_payroll_actions.legislative_parameters%type;
664 par_value pay_payroll_actions.legislative_parameters%type;
665 
666 begin
667 
668    token_val := name || '=';
669 
670    start_ptr := instr(parameter_list, token_val) + length(token_val);
671    end_ptr   := instr(parameter_list, ' ', start_ptr);
672 
673    /* if there is no spaces, then use the length of the string */
674    if end_ptr = 0 then
675      end_ptr := length(parameter_list) + 1;
676    end if;
677 
678    /* Did we find the token */
679    if instr(parameter_list, token_val) = 0 then
680      par_value := NULL;
681    else
682      par_value := substr(parameter_list, start_ptr, end_ptr - start_ptr);
683    end if;
684 
685    return par_value;
686 
687 end get_parameter;
688 
689 /*--------------------------------------------------------------------------
690   Name      : get_lump_sum
691   Purpose   : Returns the Lump Sum Balances one by one
692   Arguments :
693   Notes     : The balances are placed in the PL/SQL table in the following
694               order: current PTD, future PTD, current YTD, future YTD
695               g_ls_assactid is the Assignment Action ID of a Payroll Run
696               pay_archive.archive_aa is the Assignment Action ID of the
697               Archiver
698 --------------------------------------------------------------------------*/
699 function get_lump_sum
700 (
701    p_assid    in number,     -- The Assignment ID
702    p_assactid in number,     -- The Assignment Action ID of a Payroll Run
703    p_index    in number      -- Identifies the balance we are looking for
704 )  return varchar2 is
705 
706 i number;
707 
708 begin
709 
710    -- Check whether this is the first time this assignment_id is processed
711    if p_assid <> g_ls_assid then
712 
713       -- Set the global variables
714       g_ls_assid    := p_assid;
715       g_ls_assactid := p_assactid;
716 
717       -- Get and cache the Lump Sum Indicator
718 /*     Select decode(count(source_action_id),0,'N','Y')
719      into   g_ls_indicator
720      From pay_assignment_actions paa_arch
721      Where paa_arch.assignment_action_id = pay_archive.archive_aa;*/
722 
723         Select decode(count(*), 0 ,'Y', 'N')
724            into   g_ls_indicator
725             From      pay_payroll_actions    ppa_arch,
726               pay_assignment_actions paa_arch
727         where paa_arch.assignment_action_id = pay_archive.archive_aa
728         and   ppa_arch.payroll_action_id    = paa_arch.payroll_action_id
729         and   paa_arch.assignment_action_id =
730         (
731            select max(paa.assignment_action_id)
732            from   pay_assignment_actions paa
733            where  paa.payroll_action_id = ppa_arch.payroll_action_id
734            and   paa.assignment_id = paa_arch.assignment_id
735         ) ;
736 
737       -- Clear the PL/SQL table
738       g_ls_table.delete;
739 
740       -- Check whether this is the main certificate
741       if g_ls_indicator = 'N' then
742 
743          -- This means there is no ZA_Tax_On_Lump_Sums, therefore PTD, LS_YTD = 0
744          -- Populate the PLSQL table with retro YTD values
745 
746          -- bug no 4276047. Added Executive Equity Shares
747 
748       null;
749       else
750 
751          -- Populate the PLSQL table with retro PTD
752             -- bug no 4276047. Added Executive Equity Shares
753 
754       null;
755       end if;
756 
757    else
758 
759       -- Check whether is the first time this assignment_action_id is processed
760       if p_assactid <> g_ls_assactid then
761 
762          -- Set the global variables
763          g_ls_assactid := p_assactid;
764 
765          -- Get and cache the Lump Sum Indicator
766 /*        Select decode(count(source_action_id),0,'N','Y')
767            into   g_ls_indicator
768             From pay_assignment_actions paa_arch
769             Where paa_arch.assignment_action_id = pay_archive.archive_aa;*/
770 
771         Select decode(count(*), 0 ,'Y', 'N')
772            into   g_ls_indicator
773             From      pay_payroll_actions    ppa_arch,
774               pay_assignment_actions paa_arch
775         where paa_arch.assignment_action_id = pay_archive.archive_aa
776         and   ppa_arch.payroll_action_id    = paa_arch.payroll_action_id
777         and   paa_arch.assignment_action_id =
778         (
779            select max(paa.assignment_action_id)
780            from   pay_assignment_actions paa
781            where  paa.payroll_action_id = ppa_arch.payroll_action_id
782            and   paa.assignment_id = paa_arch.assignment_id
783         ) ;
784 
785          -- Check whether this is the main certificate
786          if g_ls_indicator = 'N' then
787 
788             -- Pull all the summed PTD values of the PLSQL table
789             null;
790 
791          else
792 
793             -- Populate the PLSQL table with PTD
794             -- return first PTD
795             null;
796 
797          end if;
798 
799       else
800 
801          -- Check whether this is the main certificate
802          if g_ls_indicator = 'N' then
803 
804             -- Pull all the summed PTD values of the PLSQL table
805             null;
806 
807          else
808 
809             -- Pull the current period's PTD values of the PLSQL table
810             null;
811 
812          end if;
813 
814       end if;
815 
816    end if;
817 
818 end get_lump_sum;
819 
820 --------------------------------------------------------------------------------------------
821 -- This function is used to return the initials of the employee
822 -- Note: initials('Francois, Daniel, van der Merwe') would return 'FDV'
823 -- Note: A maximum of five characters is returned
824 --------------------------------------------------------------------------------------------
825 function initials(name varchar2) return varchar2 is
826 
827    l_initials varchar2(255);
828    l_pos      number;
829    l_name     varchar2(255);
830 
831 begin
832 
833    -- Get the first initial
834    l_name := rtrim(ltrim(name));
835    if length(l_name) > 0 then
836 
837       l_initials := substr(l_name, 1, 1);
838 
839    end if;
840 
841    -- Check for a comma
842    if l_initials = ',' or l_initials = '&' then
843 
844       l_initials := '';
845 
846    end if;
847 
848    l_pos := instr(l_name, ',', 1, 1);
849    while l_pos <> 0 loop
850 
851       -- Move the Position indicator to the character after the comma
852       l_pos := l_pos + 1;
853 
854       -- Move forward until you find something that is not a space
855       while substr(l_name, l_pos, 1) = ' ' loop
856 
857          l_pos := l_pos + 1;
858 
859       end loop;
860 
861       -- Append the initial
862       l_initials := l_initials || substr(l_name, l_pos, 1);
863 
864       -- Find the next initial
865       l_pos := instr(l_name, ',', l_pos, 1);
866 
867    end loop;
868 
869    -- Check for a empty string
870    if l_initials is null then
871 
872       l_initials := '&&&';
873 
874    end if;
875 
876    -- Format the result and limit it to 5 characters
877    l_initials := upper(substr(l_initials, 1, 5));
878 
879    return l_initials;
880 
881 end initials;
882 
883 function names(name varchar2) return varchar2 is
884 
885 l_pos    number;
886 l_pos2   number;
887 l_name   varchar2(255);
888 l_answer varchar2(255);
889 
890 begin
891 
892    -- Remove any unnecessary spaces
893    l_name := ltrim(rtrim(name));
894 
895    -- Get the first name
896    l_pos := instr(l_name, ',', 1, 1);
897    l_answer := rtrim(substr(l_name, 1, l_pos - 1));
898 
899    -- Append the second name
900    l_pos2 := instr(l_name, ',', l_pos + 1, 1);
901    if l_pos2 = 0 then
902 
903       -- Concatenate the rest of the string
904       l_answer := l_answer || ' ' || ltrim(rtrim( substr(l_name, l_pos + 1) ));
905 
906    else
907 
908       -- Concatenate the name up to the comma
909       l_answer := l_answer || ' ' || ltrim(rtrim( substr(l_name, l_pos + 1, l_pos2 - l_pos - 1) ));
910 
911    end if;
912 
913    l_answer := ltrim(rtrim(l_answer));
914 
915    return l_answer;
916 
917 end names;
918 
919 function clean(name varchar2) return varchar2 is
920 
921 l_invalid varchar2(255);
922 l_answer  varchar2(255);
923 l_pos     number;
924 l_count   number;
925 
926 begin
927 
928    l_invalid := '&`''';
929    l_answer := name;
930 
931    if l_answer = '&&&,&&&' then
932 
933       return '&&&';
934 
935    else
936 
937       -- Loop through the invalid characters
938       for l_count in 1..length(l_invalid) loop
939 
940          l_pos := instr(l_answer, substr(l_invalid, l_count, 1), 1, 1);
941          while l_pos <> 0 loop
942 
943             -- Replace the invalid character with a space
944             l_answer := substr(l_answer, 1, l_pos - 1) || ' ' || substr(l_answer, l_pos + 1);
945             l_pos := instr(l_answer, substr(l_invalid, l_count, 1), 1, 1);
946 
947          end loop;
948 
949       end loop;
950 
951       return l_answer;
952 
953    end if;
954 
955 end;
956 
957 function get_size return number is
958 begin
959 
960    return g_size;
961 
962 end;
963 
964 function get_employer_count return number is
965 begin
966 
967    return g_employer_count;
968 
969 end;
970 
971 function get_employer_code return number is
972 begin
973 
974    return g_employer_code;
975 
976 end;
977 
978 function get_employer_amounts return number is
979 begin
980 
981    return g_employer_amounts;
982 
983 end;
984 
985 function get_file_count return number is
986 begin
987 
988    return g_file_count;
989 
990 end;
991 
992 function gen_x
993 (
994    p_code      in varchar2,
995    p_bg_id     in varchar2,
996    p_tax_year  in varchar2,
997    p_test_flag in varchar2
998 )  return varchar2 is
999 
1000 l_count number;
1001 l_temp  varchar2(255);
1002 
1003 begin
1004 
1005    -- Check whether this is the Init formula
1006    if p_code = '0000' then
1007 
1008       -- Only use the overriding Generation Number if this is a LIVE file
1009       if p_test_flag = 'N' then
1010 
1011          -- Get the overriding Generation Number
1012          l_temp := pay_magtape_generic.get_parameter_value('GEN_NUM');
1013 
1014          -- Check whether a valid overriding Generation Number was given
1015          if l_temp is not null then
1016 
1017             begin
1018 
1019                -- Override the Generation Number
1020                l_count := to_number(l_temp);
1021 
1022                if l_count < 1 or l_count > 9999 then
1023                   l_temp := null;
1024                end if;
1025 
1026             exception when invalid_number then
1027                -- Get the Generation Number the old way
1028                l_temp := null;
1029 
1030             end;
1031 
1032          end if;
1033 
1034          -- Check whether an overriding Generation Number was not entered
1035          if l_temp is null then
1036 
1037             -- Check whether this is the first time that THIS Creator is running in this tax year
1038             -- If the answer is yes, then reset the Generation Number to 0
1039             select count(*)
1040             into   l_count
1041             from   pay_payroll_actions
1042             where  action_type = 'X'
1043             and    report_type = 'ZA_IRP5'
1044             and    business_group_id = to_number(p_bg_id)
1045             and    pay_za_irp5_archive_pkg.get_parameter('TAX_YEAR', legislative_parameters) = p_tax_year;
1046 
1047             if l_count = 1 then
1048 
1049                -- Reset the Generation Number to 0
1050                update hr_organization_information
1051                set    org_information11       = '0'
1052                where  organization_id         = to_number(p_bg_id)
1053                and    org_information_context = 'ZA_TAX_FILE_ENTITY';
1054 
1055             end if;
1056 
1057          else   -- An overriding Generation Number was entered
1058 
1059             -- Subtract one from the number, since it will be added again in the Header
1060             l_count := l_count - 1;
1061 
1062             -- Update the Generation Number
1063             update hr_organization_information
1064             set    org_information11       = to_char(l_count)
1065             where  organization_id         = to_number(p_bg_id)
1066             and    org_information_context = 'ZA_TAX_FILE_ENTITY';
1067 
1068          end if;
1069 
1070       else   -- This is a TEST file
1071 
1072          l_count := 0;
1073 
1074       end if;
1075 
1076    else   -- This is the Header formula
1077 
1078       -- Get the Generation Number
1079       select nvl(to_number(org_information11), 0)
1080       into   l_count
1081       from   hr_organization_information
1082       where  organization_id         = to_number(p_bg_id)
1083       and    org_information_context = 'ZA_TAX_FILE_ENTITY';
1084 
1085       -- Check Test Flag
1086       if p_test_flag = 'LIVE' then
1087 
1088          -- Increment the Generation Number
1089          l_count := l_count + 1;
1090 
1091          -- Wrap at 9999
1092          if l_count = 10000 then
1093 
1094             l_count := 1;
1095 
1096          end if;
1097 
1098          -- Set the Generation Number
1099          update hr_organization_information
1100          set    org_information11       = to_char(l_count)
1101          where  organization_id         = to_number(p_bg_id)
1102          and    org_information_context = 'ZA_TAX_FILE_ENTITY';
1103 
1104       end if;
1105 
1106       -- If the answer was 0, then rather return 1
1107       if l_count = 0 then
1108 
1109          l_count := 1;
1110 
1111       end if;
1112 
1113    end if;
1114 
1115    -- Return the Generation Number
1116    return lpad(to_char(l_count), 4, '0');
1117 
1118 end gen_x;
1119 
1120 /* Not used */
1121 function cert_num
1122 (
1123    p_bg       number,
1124    p_tax_year varchar2,
1125    p_pay      varchar2,
1126    p_ass      number
1127 ) return varchar2 is
1128 
1129 l_max_num varchar2(30);
1130 
1131 begin
1132 
1133    if max_num = 'START' then
1134 
1135       -- Get the current largest number
1136       select max(substr(paa.serial_number, 5, 6))
1137       into   max_num
1138       from   pay_assignment_actions paa,
1139              pay_payroll_actions    ppa
1140       where  ppa.business_group_id = p_bg
1141       and    ppa.report_type = 'ZA_IRP5'
1142       and    ppa.action_type = 'X'
1143       and    substr(ppa.legislative_parameters,
1144              instr(ppa.legislative_parameters, 'TAX_YEAR') + 9, 4) = p_tax_year
1145       and    ppa.payroll_action_id <> substr(p_pay, 28, 9)
1146       and    paa.payroll_action_id = ppa.payroll_action_id
1147       and    paa.assignment_id = p_ass
1148       and    substr(paa.serial_number, 1, 2) = '&&';
1149 
1150       select max(substr(paa.serial_number, 3, 6))
1151       into   l_max_num
1152       from   pay_assignment_actions paa,
1153              pay_payroll_actions    ppa
1154       where  ppa.business_group_id = p_bg
1155       and    ppa.report_type = 'ZA_IRP5'
1156       and    ppa.action_type = 'X'
1157       and    substr(ppa.legislative_parameters,
1158              instr(ppa.legislative_parameters, 'TAX_YEAR') + 9, 4) = p_tax_year
1159       and    ppa.payroll_action_id <> substr(p_pay, 28, 9)
1160       and    paa.payroll_action_id = ppa.payroll_action_id
1161       and    paa.assignment_id = p_ass
1162       and    substr(paa.serial_number, 1, 2) <> '&&';
1163 
1164       if l_max_num > max_num then
1165 
1166          max_num := l_max_num;
1167 
1168       end if;
1169 
1170    end if;
1171 
1172    -- Add 1 to the largest number
1173    max_num := lpad(to_char(to_number(max_num) + 1), 6, '0');
1174 
1175    return max_num;
1176 
1177 end;
1178 
1179 function set_size
1180 (
1181    p_code         in varchar2,
1182    p_type         in varchar2,
1183    p_value        in varchar2,
1184    p_tax_status   in varchar2,
1185    p_nature       in varchar2
1186 )  return varchar2 is
1187 
1188 l_text      varchar2(256);
1189 l_code      varchar2(256);
1190 l_value     varchar2(256);
1191 l_gen       number;
1192    l_code2     varchar2(256);
1193    l_sars_code varchar2(256);
1194 
1195 begin
1196 
1197    -- Remove any spaces
1198    l_value := rtrim(ltrim(p_value));
1199 
1200    -- Check for empty fields
1201    if (l_value = '&&&') or (l_value = '0') or (l_value = '0.00') then
1202 
1203       -- Check whether the field should be blank or left out
1204       if p_code in ('1010', '2010', '3010', '6010', '7010') then
1205 
1206          l_text := p_code || ',';
1207          -- Increment the file size
1208          g_size := g_size + length(l_text);
1209 
1210       -- Check whether the counters should be initialized
1211       elsif p_code = '0000' then
1212 
1213          g_size             := 0;
1214          g_employer_count   := 0;
1215          g_employer_code    := 0;
1216          g_employer_amounts := 0;
1217          g_file_count       := 0;
1218 
1219       else
1220 
1221          l_text := '';
1222 
1223       end if;
1224 
1225    -- Check for a terminator field
1226    elsif (l_value = '@@@') then
1227 
1228       l_text := ',9999' || fnd_global.local_chr(13) || fnd_global.local_chr(10);
1229       -- Increment the file size
1230       g_size := g_size + 7;
1231 
1232    -- A value field was provided
1233    else
1234 
1235       -- Check for the start of a record
1236       if p_code in ('1010', '2010', '3010', '6010', '7010') then
1237          l_text := p_code;
1238       else
1239 
1240          l_code2 := substr(p_code, 1, 4);
1241 
1242          if to_number(l_code2) >= 3601 and to_number(l_code2) <= 3907
1243             and to_number(l_code2) not in (3695, 3696, 3697, 3698, 3699) then
1244 
1245             l_sars_code := py_za_tax_certificates.get_sars_code
1246                               (
1247                                  l_code2,
1248                                  p_tax_status,
1249                                  p_nature
1250                               );
1251 
1252             l_text := ',' || l_sars_code || substr(p_code, 5);
1253 
1254          else
1255             l_text := ',' || p_code;
1256 
1257          end if;
1258       end if;
1259 
1260       -- Append the value
1261       if p_type = 'N' then
1262          l_text := l_text || ',' || l_value;
1263       else
1264          -- Add quotes if it is a character field
1265          l_text := l_text || ',"' || l_value || '"';
1266       end if;
1267 
1268       -- Increment the file size
1269       g_size := g_size + length(l_text);
1270 
1271    end if;
1272 
1273    -- Get the 4 digit SARS code
1274    l_code := substr(p_code, 1, 4);
1275 
1276    -- Check whether the Employer record count should be incremented
1277    if l_code in ('2010', '3010') then
1278 
1279       g_employer_count := g_employer_count + 1;
1280 
1281    end if;
1282 
1283    -- Check whether the file record count should be incremented
1284    if l_code in ('1010', '2010', '3010', '6010') then
1285 
1286       g_file_count := g_file_count + 1;
1287 
1288    end if;
1289 
1290    -- Check whether the Employer code count should be incremented
1291    if l_code not in ('1010', '1020', '1030', '1040', '1050', '1060', '1070', '1080', '1090',
1292                      '1100', '1110', '1120', '1130', '6010', '6020', '6030', '7010') then
1293 
1294       -- Only count those codes that were written out
1295       if ((l_value = '&&&') or (l_value = '0') or (l_value = '0.00')) then
1296 
1297          null;
1298 
1299       else
1300 
1301          -- Check whether the '9999' was written for a valid range
1302          if l_code = '9999' then
1303 
1304             if g_previous_code not in ('1010', '1020', '1030', '1040', '1050', '1060', '1070',
1305                '1080', '1090', '1100', '1110', '1120', '1130', '6010', '6020', '6030', '7010') then
1306 
1307                g_employer_code := g_employer_code + 9999;
1308                hr_utility.trace('COUNT(9999,' || to_char(g_employer_code) || ',' || l_value || ')');
1309 
1310             end if;
1311 
1312          else
1313 
1314              if (l_sars_code is not null and to_number(l_sars_code) > to_number(l_code)) then
1315 
1316                 g_employer_code := g_employer_code + to_number(l_sars_code);
1317                 hr_utility.trace('COUNT(l_sars_code = ' || l_sars_code || ',' || to_char(g_employer_code) || ',' || l_value || ')');
1318 
1319              else
1320 
1321                g_employer_code := g_employer_code + to_number(l_code);
1322                hr_utility.trace('COUNT(l_code = ' || l_code || ',' || to_char(g_employer_code) || ',' || l_value || ')');
1323 
1324             end if;
1325 
1326          end if;
1327 
1328       end if;
1329 
1330    end if;
1331 
1332    -- Check whether the Employer amounts total should be incremented
1333    if to_number(l_code) >= 3601 and to_number(l_code) <= 4493 then --Changed for code 6030 in electronic tax file
1334 
1335       g_employer_amounts := g_employer_amounts + to_number(l_value);
1336 
1337    end if;
1338 
1339    -- Check whether the Employer counts should be reset
1340    if l_code = '6030' then
1341 
1342       g_employer_count   := 0;
1343       g_employer_code    := 0;
1344       g_employer_amounts := 0;
1345 
1346    end if;
1347 
1348    -- Check whether the File counts should be reset
1349    if l_code = '7010' then
1350 
1351       g_size       := 0;
1352       g_file_count := 0;
1353 
1354    end if;
1355 
1356    -- Store the code that was written out
1357    g_previous_code := l_code;
1358 
1359    hr_utility.trace('DO(' || l_code || ',' || l_value || ',' || l_text || ')');
1360 
1361    return l_text;
1362 
1363 end;
1364 
1365 function za_power
1366 (
1367    p_number in number,
1368    p_power  in number
1369 )  return number is
1370 
1371 begin
1372 
1373    return power(p_number, p_power);
1374 
1375 end;
1376 
1377 function za_to_char
1378 (
1379    p_number in number,
1380    p_format in varchar2
1381 )  return varchar2 is
1382 
1383 begin
1384 
1385    -- Check whether the Format parameter was defaulted
1386    if p_format = '&&&' then
1387 
1388       return to_char(p_number);
1389 
1390    else
1391 
1392       return ltrim(to_char(p_number, p_format));
1393 
1394    end if;
1395 
1396 end;
1397 
1398 function put_nature
1399 (
1400    p_nature in varchar2
1401 )  return varchar2 is
1402 begin
1403 
1404    g_nature := p_nature;
1405 
1406    return p_nature;
1407 
1408 end put_nature;
1409 
1410 function put_3696
1411 (
1412    p_3696 in number
1413 )  return varchar2 is
1414 
1415 begin
1416 
1417    g_3696 := p_3696;
1418 
1419    return 'Y';
1420 
1421 end put_3696;
1422 
1423 function put_3699
1424 (
1425    p_3699 in number
1426 )  return varchar2 is
1427 
1428 begin
1429 
1430    g_3699 := p_3699;
1431 
1432    return 'Y';
1433 
1434 end put_3699;
1435 
1436 function get_stored_values
1437 (
1438    p_nature out nocopy varchar2,
1439    p_3699   out nocopy number,
1440    p_3696   out nocopy number
1441 )  return varchar2 is
1442 
1443 begin
1444 
1445    p_nature := g_nature;
1446    p_3699   := g_3699;
1447    p_3696   := g_3696;
1448 
1449    return 'Y';
1450 
1451 end get_stored_values;
1452 
1453 begin
1454 
1455    prev_asg_id := 0;
1456    g_size := 0;
1457 
1458 end pay_za_irp5_archive_pkg;