DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_PAYGTN_PKG

Source


1 PACKAGE BODY PAY_PAYGTN_PKG AS
2 /* $Header: pypaygtn.pkb 120.17 2011/10/14 15:43:55 sgotlasw ship $ */
3 /*
4    Copyright (c) Oracle Corporation 1991,1992,1993. All rights reserved
5 --
6    Name        :This package defines the cursors needed for GTN to run Multi-Threaded
7 --
8    Change List
9    -----------
10    Date         Name        Vers   Description
11    -----------  ----------  -----  -----------------------------------
12    21-NOV-1999  ssarma      40.0   created
13 --
14    15-JUN-2000  tclewis     115.1  Modified the action_cursor to use the
15                                    gross_earnings_asg_gre_run balance instead
16                                    or the payment_asg_gre_run balance.  Reason
17                                    payroll runs with 0 net earnings were not showing
18                                    up on the report.  Added code to check the
19                                    paymest_asg_gre_run balance if the balance for
20                                    gross_earnings_asg_gre_run is 0.  This is to
21                                    fix a problem where non payroll payments
22                                    are not picked up if that is the only element
23                                    processed in the payroll run.
24 
25    15-JUN-2000  tclewis     115.1  Changed the checks for gross earnings and net pay
26                                    to look for a non zero run result instead.  This is
27                                    a fix for bug 2327399, in which the report is missing
28                                    0 earnings payroll actions.
29 
30    03-JUL-2002 tclewis      115.4  Changed the check for non zero run results for
31                                    earnings elements to check no non zero run results
32                                    for element type.
33    06-AUG-2002 rmonge      115.5  Modified the Action_type to varchar2(30).
34                                   bug 2447123
35    21-oct-2002 tclewis     115.7   removed the "for Update... " in the action_creation
36                                    code.
37    04-Feb-2004 schauhan    115.8  Modified the query for the cursors c_actions and
38                                   c_parameters to reduce the cost of the cursor query
39                                   c_actions.Bug 3364759
40    04-May-2004 irgonzal    115.9  Bug fix 3270485. Added logic to range_cursor
41                                   procedure to ensure the "header information" gets
42                                   inserted into pay_us_rpt_totals.
43    01-Oct-2004 saurgupt    115.10 Bug 3679305: Modified the procedure range_cursor. Changed the sqlstr
44                                   to improve performance.
45    05-Oct-2004 saurgupt    115.11 Bug 3679305: Modified the procedure range_cursor. Changed the sqlstr.
46                                   Added the new variable l_payroll_test to improve performance.
47    09-Dec-2004 sgajula     115.12 Added action_create_bra,archive_init,archive_code,archive_deinit
48                                   for implementing BRA.
49    15-MAR-2005 sdhole      115.13 Bug No.4237962,  Removed ppa_run.action_status = 'C'
50                                   from range_cursor, action_creation and action_create_bra.
51    26-Aug-2005 sackumar    115.14 Bug No.4344971, Introduced a new condition in sql present in
52                                   action_create_bra and action_create functions to remove
53                                   the Merge Cartesian join .
54    30-Aug-2005 sackumar    115.15 Introduced Index Hint in get_futa_def_bal_id cursor in
55                                   ARCHIVE_INIT procedure.
56    12-SEP-2005 pragupta    115.16 Bug 453407: Added an extra condition in the p_er_liab_where
57                                   variable to avoid duplication of rows in the procedure
58                                   load_er_liab of pay_gtnlod_pkg.
59    15-SEP-2005 meshah      115.17 removed the index hint from the range cursor.
60                                   bug 4591091.
61    07-APR-2006 rdhingra    115.18 Bug 5148084: Added procedure create_gtn_xml_data
62                                   Modified ARCHIVE_DEINIT to submit XML Report Publisher
63    24-APR-2006 rdhingra    115.19 Bug 5148084: Modified Cursor get_application_detais
64                                   to reflect changes of parameters to XML Report Publisher
65                                   concurrent program
66    30-Aug-2006 kvsankar    115.20 Bug 5478638 : Passed Application ID instead of
67                                   Application Name to the concurrent program
68                                   "XML Report Publisher"
69    16-Oct-2006 jdevasah    114.21 Bug 4942114 : changed the parameters to
70                                   pay_gtnlod_pkg.load_data procedure in ARCHIVE_CODE.
71 				  Commented assignment statements in ARCHVIE_INIT.
72 				  Created global variables which are input paramenters
73 				  to pay_gtnlod_pkg.load_data procedure.
74    21-jan-2007 asgugupt    114.22 Bug 6365474 : changed the parameters to
75                                   fnd_request.submit_request in ARCHIVE_DEINIT.
76 
77    06-Mar-2008	skameswa   115.25 Bug 6799553 : Modified the procedure ARCHIVE_DEINIT to include
78 				  a new cursor get_printer_details and a call to
79 				  fnd_request.set_print_options whose parameters were retrieved by
80 				  the above mentioned cursor
81    10-Apr-2008  priupadh   115.26 Bug 6670508 Added delete statment for pay_us_rpt_totals table
82                                   in archive_deinit,deleting for the current run as payroll act id gets
83                                   stored in column tax_unit_id .
84    21-Apr-2008  priupadh   115.27 Bug 6670508 Moved delete statment outside if clause , to delete the data
85                                   in 11i and R12 .
86    04-Aug-2008  kagangul   115.28 Bug 7297300. Changed Cursor (get_printer_details) Parameter Name
87 				  from request_id to c_request_id.
88    04-Mar-2009  skpatil    115.29  Bug 8216159: Changed action_creation_bra cursor to include balance
89                                    adjustments('B') action_type
90    14-Oct-2011  sgotlasw   115.30  Bug 12637772: Range cursor code has been modified to
91                                    include the employee in 'US GROSS TO NET SUMMARY REPORT'
92                                    who has 'Balance Adjustments' or 'Balance Initializations'
93                                    alone in the pay period.
94 */
95 ----------------------------------- range_cursor ----------------------------------
96 --
97   g_proc_name             VARCHAR2(240);
98   p_ded_bal_status1       VARCHAR2(1);
99   p_ded_bal_status2       VARCHAR2(1);
100   p_earn_bal_status       VARCHAR2(1);
101   p_fed_bal_status        VARCHAR2(1);
102   p_state_bal_status      VARCHAR2(1);
103   p_local_bal_status      VARCHAR2(1);
104   p_fed_liab_bal_status   VARCHAR2(1);
105   p_state_liab_bal_status VARCHAR2(1);
106 /*-- Bug#4942114 starts -- */
107 /* p_ded_view_name         VARCHAR2(30);
108   p_earn_view_name        VARCHAR2(30);
109   p_fed_view_name         VARCHAR2(30);
110   p_state_view_name       VARCHAR2(30);
111   p_local_view_name       VARCHAR2(30);
112   p_fed_liab_view_name    VARCHAR2(30);
113   p_state_liab_view_name  VARCHAR2(30);*/
114 /*-- Bug#4942114 ends -- */
115   p_asg_flag              VARCHAR2(5);
116 /*-- Bug#4942114 starts -- */
117 /* p_futa_where            VARCHAR2(2000);
118   p_futa_from             VARCHAR2(200);
119   p_er_liab_where         VARCHAR2(2000);
120   p_er_liab_from          VARCHAR2(2000);
121   p_wc_er_liab_where      VARCHAR2(2000);
122   p_wc_er_liab_from       VARCHAR2(2000);*/
123 /*-- Bug#4942114 ends -- */
124 
125   p_ppa_finder            VARCHAR2(20);
126   g_payroll_action_id     NUMBER;
127   l_arch_count            NUMBER := 0;
128   p_template_code         xdo_templates_tl.template_code%TYPE;
129   /*-- Bug#4942114 starts -- */
130   p_futa_status_count     number :=0;
131   p_futa_def_bal_id number;
132   p_wc_er_liab_status_count number :=0;
133   p_er_liab_status varchar2(1);
134   /*-- Bug#4942114 ends -- */
135 
136 procedure range_cursor (pactid in number, sqlstr out nocopy varchar2) is
137 
138   leg_param    pay_payroll_actions.legislative_parameters%type;
139   l_consolidation_set_id number;
140   l_payroll_id number;
141   l_tax_unit_id number;
142   l_ppa_finder  number;
143   l_leg_start_date date;
144   l_leg_end_date   date;
145   l_business_group_id number;
146 
147   l_payroll_text   varchar2(70);
148 --
149 begin
150 
151     -- hr_utility.trace_on('Y','GTN');
152      hr_utility.trace('reached range_cursor');
153 
154 
155    select ppa.legislative_parameters,
156           pay_paygtn_pkg.get_parameter('TRANSFER_CONC_SET',ppa.legislative_parameters),
157           pay_paygtn_pkg.get_parameter('TRANSFER_PAYROLL',ppa.legislative_parameters),
158           pay_paygtn_pkg.get_parameter('TRANSFER_GRE',ppa.legislative_parameters),
159           pay_paygtn_pkg.get_parameter('PPA_FINDER',ppa.legislative_parameters),
160           ppa.start_date,
161           ppa.effective_date,
162           ppa.business_group_id
163      into leg_param,
164           l_consolidation_set_id,
165           l_payroll_id,
166           l_tax_unit_id,
167           l_ppa_finder,
168           l_leg_start_date,
169           l_leg_end_date,
170           l_business_group_id
171      from pay_payroll_actions ppa
172      where ppa.payroll_action_id = pactid;
173 
174     IF l_payroll_id is not null THEN  -- added to improve the performance
175        l_payroll_text := 'and ppa_run.payroll_id = ' || to_char(l_payroll_id) ;
176     ELSE
177          l_payroll_text := null;
178     END IF;
179 
180     insert into pay_us_rpt_totals (tax_unit_id,attribute1,organization_id,
181                                       attribute2,attribute3,attribute4,attribute5)
182                               values (pactid,'GTN',l_ppa_finder,
183                                       leg_param, l_business_group_id,
184                                       to_char(l_leg_start_date,'MM/DD/YYYY'),
185                                       to_char(l_leg_end_date,'MM/DD/YYYY'));
186 
187 /* pay gtn code */
188 /*  Bug 12637772: Action Types 'B','I' have been added in the below query to pick
189                   the employee in 'US GROSS TO NET SUMMARY REPORT' who has
190                   'Balance Adjustments' or 'Balance Initializations' alone in the pay period. */
191 
192    sqlstr := 'select distinct asg.person_id
193                 from per_assignments_f      asg,
194                      pay_assignment_actions act_run, /* run and quickpay assignment actions */
195                      pay_payroll_actions    ppa_run, /* run and quickpay payroll actions */
196                      pay_payroll_actions    ppa_gen  /* PYUGEN information */
197                where ppa_gen.payroll_action_id    = :payroll_action_id
198                  and ppa_run.effective_date between  /* date join btwn run and pyugen ppa */
199                                             ppa_gen.start_date and ppa_gen.effective_date
200                  and ppa_run.action_type         in (''R'',''Q'',''V'',''B'',''I'')
201                  and ppa_run.consolidation_set_id = '''||l_consolidation_set_id||''''||l_payroll_text||'
202                  and ppa_run.payroll_action_id    = act_run.payroll_action_id
203                  and act_run.action_status        = ''C''
204                  and asg.assignment_id            = act_run.assignment_id
205                  and ppa_run.effective_date between  /* date join btwn run and asg */
206                                             asg.effective_start_date and asg.effective_end_date
207                 and asg.business_group_id +0    = ppa_gen.business_group_id
208            order by asg.person_id';
209 
210      hr_utility.trace('leaving range_cursor');
211 
212 end range_cursor;
213 ---------------------------------- action_creation ----------------------------------
214 --
215 procedure action_create_bra(pactid in number,
216                           stperson in number,
217                           endperson in number,
218                           chunk in number) is
219 
220   leg_param    pay_payroll_actions.legislative_parameters%type;
221   l_consolidation_set_id number;
222   l_payroll_id number;
223   l_tax_unit_id number;
224 
225 --Bug 3364759 --Declared these local variables which will be populated by  the cursor c_parameters.
226   l_business_group_id number;
227   l_start_date date;
228   l_effective_date date;
229 
230 --
231 -- Bug 3364759 --Added business_group_id,start_date and effective_date in the select statement
232                -- of the cursor c_parameters.
233   cursor c_parameters ( pactid number) is
234    select ppa.legislative_parameters,
235           ppa.business_group_id,
236           ppa.start_date,
237           ppa.effective_date,
238           pay_paygtn_pkg.get_parameter('TRANSFER_CONC_SET',ppa.legislative_parameters),
239           pay_paygtn_pkg.get_parameter('TRANSFER_PAYROLL',ppa.legislative_parameters),
240           pay_paygtn_pkg.get_parameter('TRANSFER_GRE',ppa.legislative_parameters)
241      from pay_payroll_actions ppa
242     where ppa.payroll_action_id = pactid;
243 
244 --Bug 3364759 --Used the local variables l_business_group_id,l_start_date,l_effective_date in the
245               -- cursor query to reduce its cost.Also removed the forced index  PAY_PAYROLL_ACTIONS_N5.
246   CURSOR c_actions
247       (
248          pactid    number,
249          stperson  number,
250          endperson number
251       ) is
252               select /*+ ORDERED
253                          INDEX (ppa_gen PAY_PAYROLL_ACTIONS_PK)
254                          INDEX (act_run PAY_ASSIGNMENT_ACTIONS_N50)
255                          INDEX (asg     PER_ASSIGNMENTS_F_PK) */
256                      ppa_run.action_type,
257                      act_run.assignment_action_id,
258                      asg.assignment_id,
259                      act_run.tax_unit_id
260                      from pay_payroll_actions    ppa_run, /* run and quickpay payroll actions */
261                           pay_assignment_actions act_run, /* run and quickpay assignment actions */
262                           per_assignments_f      asg
263   		 where ppa_run.effective_date between
264 	                                            l_start_date
265                                                 and l_effective_date
266                  and ppa_run.action_type         in ('R','Q','V','B')  /* 8216159 */
267                  and ppa_run.consolidation_set_id = l_consolidation_set_id
268                  AND (l_payroll_id IS NULL
269                       OR  PPA_RUN.PAYROLL_ID  = l_payroll_id)
270                  and ppa_run.payroll_action_id    = act_run.payroll_action_id
271                  and act_run.action_status        = 'C'
272  		 and act_run.tax_unit_id          = nvl(l_tax_unit_id,
273                                                         act_run.tax_unit_id)
274                  and asg.assignment_id            = act_run.assignment_id
275                  and ppa_run.effective_date between  /* date join btwn run and asg */
276                                                     asg.effective_start_date
277                                                 and asg.effective_end_date
278 		 and asg.business_group_id +0     = l_business_group_id
279                  and asg.person_id          between stperson and endperson;
280 --                       for update of asg.assignment_id;
281 
282 
283 --
284       lockingactid    number;
285       lockedactid     number;
286       assignid        number;
287       greid           number;
288       num             number;
289       action_type     varchar2(30);
290       l_payments_bal  number;
291       l_gross_defined_balance_id number;
292       l_payments_defined_balance_id number;
293       l_create_act    varchar2(1);
294 
295 --
296    -- algorithm is quite similar to the other process cases,
297    -- but we have to take into account assignments and
298    -- personal payment methods.
299    begin
300       --hr_utility.trace_on('Y','ORACLE');
301       hr_utility.trace('entering action_creation');
302       hr_utility.set_location('procpyr',1);
303       open c_parameters(pactid);
304 
305 --Bug 3364759 -- Fetced the values of the cursors in the variables  l_business_group_id, l_start_date, l_effective_date
306               -- as well.
307       fetch c_parameters into leg_param,
308                               l_business_group_id,
309                               l_start_date,
310                               l_effective_date,
311                               l_consolidation_set_id,
312                               l_payroll_id,
313                               l_tax_unit_id;
314       close c_parameters;
315 /*      begin
316         select to_number(ue.creator_id)
317           into l_gross_defined_balance_id
318           from ff_user_entities ue,
319                ff_database_items di
320 --         where di.user_name = 'PAYMENTS_ASG_GRE_RUN'
321           where di.user_name = 'GROSS_EARNINGS_ASG_GRE_RUN'
322            and ue.user_entity_id = di.user_entity_id
323            and ue.creator_type = 'B'
324            and nvl(ue.legislation_code,'US') = 'US';
325       exception when others then
326            hr_utility.trace('Error getting defined balance id');
327            raise;
328       end;
329 
330       begin
331         select to_number(ue.creator_id)
332           into l_payments_defined_balance_id
333           from ff_user_entities ue,
334                ff_database_items di
335           where di.user_name = 'PAYMENTS_ASG_GRE_RUN'
336            and ue.user_entity_id = di.user_entity_id
337            and ue.creator_type = 'B'
338            and nvl(ue.legislation_code,'US') = 'US';
339       exception when others then
340            hr_utility.trace('Error getting defined balance id');
341            raise;
342       end;
343 */
344 
345       hr_utility.set_location('procpyr',1);
346       open c_actions(pactid,stperson,endperson);
347       num := 0;
348       loop
349          hr_utility.set_location('procpyr',2);
350          fetch c_actions into action_type,lockedactid,assignid,greid;
351          if c_actions%found then num := num + 1; end if;
352          exit when c_actions%notfound;
353 --
354         begin
355 
356           select 'Y'
357           into l_create_act
358           from dual
359           where exists (
360               select 'Y'
361               from   pay_run_result_values rrv,
362                      pay_input_values_F    iv,
363                      pay_run_results       rr
364               where  nvl(rrv.result_value,0) <> to_char(0)
365               and    iv.input_value_id = rrv.input_value_id
366 	      and    iv.element_type_id = rr.element_type_id
367 	      and    iv.name = 'Pay Value'
368               and    rr.run_result_id = rrv.run_result_id
369               and    rr.assignment_action_id = lockedactid);
370 
371         exception
372            when NO_DATA_FOUND THEN
373              l_create_act := 'N';
374         end;
375 
376 
377 /*        pay_balance_pkg.set_context('TAX_UNIT_ID',greid);
378         l_payments_bal := nvl(pay_balance_pkg.get_value(p_defined_balance_id => l_gross_defined_balance_id,
379                                                         p_assignment_action_id => lockedactid),0);
380 
381         if l_payments_bal = 0 and action_type in ('R','Q') then
382 --
383 -- Check the Payments_asg_gre_run balance incase Gross earnings is 0
384 -- and we have a non payroll payment (only element processed) action.
385 --
386 -- Not going to set the context again as
387            l_payments_bal := nvl(pay_balance_pkg.get_value(p_defined_balance_id => l_payments_defined_balance_id,
388                                                        p_assignment_action_id => lockedactid),0);
389         end if;
390 */
391 /*        if l_payments_bal = 0 and action_type in ('R','Q') then */
392 
393           if l_create_act = 'N' then
394 
395 
396            null;
397         else
398         	hr_utility.set_location('procpyr',3);
399         	select pay_assignment_actions_s.nextval
400         	into   lockingactid
401         	from   dual;
402 --
403         	-- insert the action record.
404         	hr_nonrun_asact.insact(lockingactid =>lockingactid,
405         			        object_id   =>lockedactid,
406         			        pactid      =>pactid,
407         			        chunk       =>chunk,
408         			        greid       =>greid);
409 --
410          	-- insert an interlock to this action.
411     --     	hr_nonrun_asact.insint(lockingactid,lockedactid);
412         end if;
413 --
414       end loop;
415       close c_actions;
416       hr_utility.trace('leaving action_creation');
417 end action_create_bra;
418 
419 ---------------------------------- action_creation ----------------------------------
420 --
421 procedure action_creation(pactid in number,
422                           stperson in number,
423                           endperson in number,
424                           chunk in number) is
425 
426   leg_param    pay_payroll_actions.legislative_parameters%type;
427   l_consolidation_set_id number;
428   l_payroll_id number;
429   l_tax_unit_id number;
430 
431 --Bug 3364759 --Declared these local variables which will be populated by  the cursor c_parameters.
432   l_business_group_id number;
433   l_start_date date;
434   l_effective_date date;
435 
436 --
437 -- Bug 3364759 --Added business_group_id,start_date and effective_date in the select statement
438                -- of the cursor c_parameters.
439   cursor c_parameters ( pactid number) is
440    select ppa.legislative_parameters,
441           ppa.business_group_id,
442           ppa.start_date,
443           ppa.effective_date,
444           pay_paygtn_pkg.get_parameter('TRANSFER_CONC_SET',ppa.legislative_parameters),
445           pay_paygtn_pkg.get_parameter('TRANSFER_PAYROLL',ppa.legislative_parameters),
446           pay_paygtn_pkg.get_parameter('TRANSFER_GRE',ppa.legislative_parameters)
447      from pay_payroll_actions ppa
448     where ppa.payroll_action_id = pactid;
449 
450 --Bug 3364759 --Used the local variables l_business_group_id,l_start_date,l_effective_date in the
451               -- cursor query to reduce its cost.Also removed the forced index  PAY_PAYROLL_ACTIONS_N5.
452   CURSOR c_actions
453       (
454          pactid    number,
455          stperson  number,
456          endperson number
457       ) is
458               select /*+ ORDERED
459                          INDEX (ppa_gen PAY_PAYROLL_ACTIONS_PK)
460                          INDEX (act_run PAY_ASSIGNMENT_ACTIONS_N50)
461                          INDEX (asg     PER_ASSIGNMENTS_F_PK) */
462                      ppa_run.action_type,
463                      act_run.assignment_action_id,
464                      asg.assignment_id,
465                      act_run.tax_unit_id
466                      from pay_payroll_actions    ppa_run, /* run and quickpay payroll actions */
467                           pay_assignment_actions act_run, /* run and quickpay assignment actions */
468                           per_assignments_f      asg
469   		 where ppa_run.effective_date between
470 	                                            l_start_date
471                                                 and l_effective_date
472                  and ppa_run.action_type         in ('R','Q','V')
473                  and ppa_run.consolidation_set_id = l_consolidation_set_id
474                  AND (l_payroll_id IS NULL
475                       OR  PPA_RUN.PAYROLL_ID  = l_payroll_id)
476                  and ppa_run.payroll_action_id    = act_run.payroll_action_id
477                  and act_run.action_status        = 'C'
478  		 and act_run.tax_unit_id          = nvl(l_tax_unit_id,
479                                                         act_run.tax_unit_id)
480                  and asg.assignment_id            = act_run.assignment_id
481                  and ppa_run.effective_date between  /* date join btwn run and asg */
482                                                     asg.effective_start_date
483                                                 and asg.effective_end_date
484 		 and asg.business_group_id +0     = l_business_group_id
485                  and asg.person_id          between stperson and endperson;
486 --                       for update of asg.assignment_id;
487 
488 
489 --
490       lockingactid    number;
491       lockedactid     number;
492       assignid        number;
493       greid           number;
494       num             number;
495       action_type     varchar2(30);
496       l_payments_bal  number;
497       l_gross_defined_balance_id number;
498       l_payments_defined_balance_id number;
499       l_create_act    varchar2(1);
500 
501 --
502    -- algorithm is quite similar to the other process cases,
503    -- but we have to take into account assignments and
504    -- personal payment methods.
505    begin
506       --hr_utility.trace_on('Y','ORACLE');
507       hr_utility.trace('entering action_creation');
508       hr_utility.set_location('procpyr',1);
509       open c_parameters(pactid);
510 
511 --Bug 3364759 -- Fetced the values of the cursors in the variables  l_business_group_id, l_start_date, l_effective_date
512               -- as well.
513       fetch c_parameters into leg_param,
514                               l_business_group_id,
515                               l_start_date,
516                               l_effective_date,
517                               l_consolidation_set_id,
518                               l_payroll_id,
519                               l_tax_unit_id;
520       close c_parameters;
521 /*      begin
522         select to_number(ue.creator_id)
523           into l_gross_defined_balance_id
524           from ff_user_entities ue,
525                ff_database_items di
526 --         where di.user_name = 'PAYMENTS_ASG_GRE_RUN'
527           where di.user_name = 'GROSS_EARNINGS_ASG_GRE_RUN'
528            and ue.user_entity_id = di.user_entity_id
529            and ue.creator_type = 'B'
530            and nvl(ue.legislation_code,'US') = 'US';
531       exception when others then
532            hr_utility.trace('Error getting defined balance id');
533            raise;
534       end;
535 
536       begin
537         select to_number(ue.creator_id)
538           into l_payments_defined_balance_id
539           from ff_user_entities ue,
540                ff_database_items di
541           where di.user_name = 'PAYMENTS_ASG_GRE_RUN'
542            and ue.user_entity_id = di.user_entity_id
543            and ue.creator_type = 'B'
544            and nvl(ue.legislation_code,'US') = 'US';
545       exception when others then
546            hr_utility.trace('Error getting defined balance id');
547            raise;
548       end;
549 */
550 
551       hr_utility.set_location('procpyr',1);
552       open c_actions(pactid,stperson,endperson);
553       num := 0;
554       loop
555          hr_utility.set_location('procpyr',2);
556          fetch c_actions into action_type,lockedactid,assignid,greid;
557          if c_actions%found then num := num + 1; end if;
558          exit when c_actions%notfound;
559 --
560         begin
561 
562           select 'Y'
563           into l_create_act
564           from dual
565           where exists (
566               select 'Y'
567               from   pay_run_result_values rrv,
568                      pay_input_values_F    iv,
569                      pay_run_results       rr
570               where  nvl(rrv.result_value,0) <> to_char(0)
571               and    iv.input_value_id = rrv.input_value_id
572               and    iv.name = 'Pay Value'
573 	      and    iv.element_type_id = rr.element_type_id
574 	      and    rr.run_result_id = rrv.run_result_id
575               and    rr.assignment_action_id = lockedactid);
576 
577         exception
578            when NO_DATA_FOUND THEN
579              l_create_act := 'N';
580         end;
581 
582 
583 /*        pay_balance_pkg.set_context('TAX_UNIT_ID',greid);
584         l_payments_bal := nvl(pay_balance_pkg.get_value(p_defined_balance_id => l_gross_defined_balance_id,
585                                                         p_assignment_action_id => lockedactid),0);
586 
587         if l_payments_bal = 0 and action_type in ('R','Q') then
588 --
589 -- Check the Payments_asg_gre_run balance incase Gross earnings is 0
590 -- and we have a non payroll payment (only element processed) action.
591 --
592 -- Not going to set the context again as
593            l_payments_bal := nvl(pay_balance_pkg.get_value(p_defined_balance_id => l_payments_defined_balance_id,
594                                                        p_assignment_action_id => lockedactid),0);
595         end if;
596 */
597 /*        if l_payments_bal = 0 and action_type in ('R','Q') then */
598 
599           if l_create_act = 'N' then
600 
601 
602            null;
603         else
604         	hr_utility.set_location('procpyr',3);
605         	select pay_assignment_actions_s.nextval
606         	into   lockingactid
607         	from   dual;
608 --
609         	-- insert the action record.
610         	hr_nonrun_asact.insact(lockingactid,assignid,pactid,chunk,greid);
611 --
612          	-- insert an interlock to this action.
613          	hr_nonrun_asact.insint(lockingactid,lockedactid);
614         end if;
615 --
616       end loop;
617       close c_actions;
618       hr_utility.trace('leaving action_creation');
619 end action_creation;
620 ---------------------------------- sort_action ----------------------------------
621 procedure sort_action
622 (
623    payactid   in     varchar2,     /* payroll action id */
624    sqlstr     in out nocopy varchar2,     /* string holding the sql statement */
625    len        out  nocopy  number        /* length of the sql string */
626 ) is
627 begin
628 
629       sqlstr :=  'select paa1.rowid
630                     from pay_assignment_actions paa1,   -- PYUGEN assignment action
631                          pay_payroll_actions    ppa1    -- PYUGEN payroll action id
632                    where ppa1.payroll_action_id = :pactid
633                      and paa1.payroll_action_id = ppa1.payroll_action_id
634                    order by paa1.assignment_action_id
635                    for update of paa1.assignment_id';
636 
637       len := length(sqlstr); -- return the length of the string.
638    end sort_action;
639 ------------------------------ get_parameter -------------------------------
640 function get_parameter(name in varchar2,
641                        parameter_list varchar2) return varchar2
642 is
643   start_ptr number;
644   end_ptr   number;
645   token_val pay_payroll_actions.legislative_parameters%type;
646   par_value pay_payroll_actions.legislative_parameters%type;
647 begin
648 --
649      token_val := name||'=';
650 --
651      start_ptr := instr(parameter_list, token_val) + length(token_val);
652      end_ptr := instr(parameter_list, ' ',start_ptr);
653 --
654      /* if there is no spaces use then length of the string */
655      if end_ptr = 0 then
656         end_ptr := length(parameter_list)+1;
657      end if;
658 --
659      /* Did we find the token */
660      if instr(parameter_list, token_val) = 0 then
661        par_value := NULL;
662      else
663        par_value := substr(parameter_list, start_ptr, end_ptr - start_ptr);
664      end if;
665 --
666      return par_value;
667 --
668 end get_parameter;
669 
670 Procedure ARCHIVE_INIT(p_payroll_action_id IN NUMBER) IS
671 
672 l_param varchar2(240);
673 p_business_group_id number;
674 p_start_date date;
675 p_end_date date;
676 p_consolidation_set_id number;
677 p_payroll_id number;
678 p_gre_id number;
679 p_sort1  varchar2(20);
680 p_sort2  varchar2(20);
681 p_sort3  varchar2(20);
682 l_trunc_date date;
683 /*-- Bug#4942114 starts -- */
684 /* l_futa_def_bal_id number;
685 l_temp_count number;
686 l_er_liab_status varchar2(1); */
687 /*-- Bug#4942114 ends -- */
688 
689 cursor get_futa_def_bal_id(cp_business_group_id number) is
690 SELECT /*+ index(pbd PAY_BALANCE_DIMENSIONS_PK)*/ pdb.defined_balance_id
691   FROM pay_defined_balances pdb,
692        pay_balance_types pbt,
693        pay_balance_dimensions pbd
694  WHERE pdb.balance_dimension_id = pbd.balance_dimension_id
695    AND pdb.balance_type_id = pbt.balance_type_id
696    AND (   pdb.business_group_id = cp_business_group_id
697         OR pdb.legislation_code = 'US'
698        )
699    AND pbt.legislation_code = 'US'
700    AND pbd.legislation_code = 'US'
701    AND pbd.database_item_suffix = '_ASG_GRE_RUN'
702    AND pbt.balance_name = 'FUTA CREDIT';
703 
704  cursor chk_futa_status(cp_business_group_id number,cp_start_date date,cp_defined_balance_id number) IS
705  select count(*)
706  from  pay_balance_validation pbv
707  where pbv.business_group_id = cp_business_group_id
708  and   pbv.defined_balance_id = cp_defined_balance_id
709  AND   NVL (pbv.run_balance_status, 'I') = 'V'
710  and NVL(pbv.balance_load_date, cp_start_date) <= cp_start_date;
711 
712 cursor c_wc_er_liab_valid_count(cp_business_group_id number,cp_start_date date) IS
713 select count(*)
714  from  pay_balance_validation pbv,
715        pay_defined_balances pdb,
716        pay_balance_types pbt,
717        pay_balance_dimensions pbd
718  where (pbv.business_group_id = cp_business_group_id)
719  and   pbv.defined_balance_id = pdb.defined_balance_id
720  and   pdb.balance_dimension_id = pbd.balance_dimension_id
721  and   pdb.balance_type_id = pbt.balance_type_id
722  and   (pdb.business_group_id = cp_business_group_id or
723         pdb.legislation_code = 'US')
724  and pbt.legislation_code = 'US'
725  and pbd.legislation_code = 'US'
726  and   pbd.database_item_suffix = '_ASG_JD_GRE_RUN'
727  and pbt.balance_name in ('Workers Compensation',
728                           'Workers Compensation2 ER',
729                           'Workers Compensation3 ER')
730  AND   NVL (pbv.run_balance_status, 'I') = 'V'
731  and NVL(pbv.balance_load_date, cp_start_date) <= cp_start_date;
732 begin
733 
734 begin
735 --
736   --   hr_utility.trace_on (null,'1');
737       hr_utility.trace('entering archive_init');
738  select
739         ppa.legislative_parameters,
740         ppa.business_group_id,
741         ppa.start_date,
742         ppa.effective_date
743    into l_param,
744         p_business_group_id,
745         p_start_date,
746         p_end_date
747    from pay_payroll_actions ppa
748   where ppa.payroll_action_id = p_payroll_action_id;
749 
750   g_payroll_action_id    := p_payroll_action_id;
751   p_consolidation_set_id := pay_paygtn_pkg.get_parameter('TRANSFER_CONC_SET',l_param);
752   p_payroll_id           := pay_paygtn_pkg.get_parameter('TRANSFER_PAYROLL',l_param);
753   p_gre_id               := pay_paygtn_pkg.get_parameter('TRANSFER_GRE',l_param);
754   p_sort1                := pay_paygtn_pkg.get_parameter('TRANSFER_SORT1',l_param);
755   p_sort2                := pay_paygtn_pkg.get_parameter('TRANSFER_SORT2',l_param);
756   p_sort3                := pay_paygtn_pkg.get_parameter('TRANSFER_SORT3',l_param);
757   p_ppa_finder           := pay_paygtn_pkg.get_parameter('TRANSFER_PPA_FINDER',l_param);
758   p_template_code        := pay_paygtn_pkg.get_parameter('TRANSFER_TEMPLATE',l_param);
759   p_asg_flag             := nvl(pay_paygtn_pkg.get_parameter('TRANSFER_EMP_INFO',l_param),'N');
760 
761   hr_utility.trace('p_asg_flag in archive_init='||p_asg_flag);
762        p_ded_bal_status1 := pay_us_payroll_utils.check_balance_status(p_start_date
763                                                           ,p_business_group_id
764                                                          ,'PAY_US_PRE_TAX_DEDUCTIONS','US');
765        p_ded_bal_status2 := pay_us_payroll_utils.check_balance_status(p_start_date
766                                                           ,p_business_group_id
767                                                          ,'PAY_US_AFTER_TAX_DEDUCTIONS','US');
768    /*-- Bug#4942114 starts -- */
769      /* if p_ded_bal_status1 = 'Y' AND p_ded_bal_status2 = 'Y' THEN
770            p_ded_view_name := 'PAY_US_ASG_RUN_DED_RBR_V';
771       else
772            p_ded_view_name := 'PAY_US_GTN_DEDUCT_V';
773       end if; */
774       /*-- Bug#4942114 ends -- */
775      p_earn_bal_status := pay_us_payroll_utils.check_balance_status(p_start_date
776                                    ,p_business_group_id
777                                    ,'PAY_US_EARNINGS_AMTS','US');
778    /*-- Bug#4942114 starts -- */
779      /* if p_earn_bal_status = 'Y' THEN
780            p_earn_view_name := 'PAY_US_ASG_RUN_EARN_AMT_RBR_V';
781       else
782            p_earn_view_name := 'PAY_US_GTN_EARNINGS_V';
783       end if; */
784   /*-- Bug#4942114 ends -- */
785  p_fed_bal_status := pay_us_payroll_utils.check_balance_status(p_start_date
786                                                          ,p_business_group_id
787                                                         ,'PAY_US_TAX_DEDN_FED','US');
788  p_state_bal_status := pay_us_payroll_utils.check_balance_status(p_start_date
789                                                          ,p_business_group_id
790                                                         ,'PAY_US_TAX_DEDN_STATE','US');
791  p_local_bal_status := pay_us_payroll_utils.check_balance_status(p_start_date
792                                                          ,p_business_group_id
793                                                         ,'PAY_US_TAX_DEDN_LOCAL','US');
794    /*-- Bug#4942114 starts -- */
795    /*  if p_fed_bal_status = 'Y'  THEN
796           p_fed_view_name := 'PAY_US_ASG_RUN_FED_TAX_RBR_V';
797      else
798           p_fed_view_name := 'PAY_US_FED_TAXES_V';
799      end if;
800 
801      if p_state_bal_status = 'Y'  THEN
802           p_state_view_name := 'PAY_US_ASG_RUN_STATE_TAX_RBR_V';
803      else
804           p_state_view_name := 'PAY_US_STATE_TAXES_V';
805      end if;
806 
807      if p_local_bal_status = 'Y'  THEN
808           p_local_view_name := 'PAY_US_ASG_RUN_LOCAL_TAX_RBR_V';
809      else
810           p_local_view_name := 'PAY_US_LOCAL_TAXES_V';
811      end if; */
812    /*-- Bug#4942114 ends -- */
813 
814  p_fed_liab_bal_status := pay_us_payroll_utils.check_balance_status(p_start_date
815                                                          ,p_business_group_id
816                                                         ,'PAY_US_FED_LIABILITIES','US');
817  p_state_liab_bal_status := pay_us_payroll_utils.check_balance_status(p_start_date
818                                                          ,p_business_group_id
819                                                         ,'PAY_US_STATE_LIABILITIES','US');
820  /*-- Bug#4942114 starts -- */
821     /* if p_fed_liab_bal_status = 'Y'  THEN
822           p_fed_liab_view_name := 'PAY_US_ASG_RUN_FED_LIAB_RBR_V';
823      else
824           p_fed_liab_view_name := 'PAY_US_FED_LIABILITIES_V';
825      end if;
826 
827      if p_state_liab_bal_status = 'Y'  THEN
828           p_state_liab_view_name := 'PAY_US_ASG_RUN_ST_LIAB_RBR_V';
829      else
830           p_state_liab_view_name := 'PAY_US_STATE_LIABILITIES_V';
831      end if; */
832      /*-- Bug#4942114 ends -- */
833 
834    l_trunc_date := trunc(p_start_date,'Y');
835  --  l_temp_count :=0; -- Bug#4942114
836 open get_futa_def_bal_id(p_business_group_id);
837 -- fetch get_futa_def_bal_id into l_futa_def_bal_id; /*-- Bug#4942114--*/
838    fetch get_futa_def_bal_id into p_futa_def_bal_id; /*-- Bug#4942114--*/
839 close get_futa_def_bal_id;
840 
841 /*-- Bug#4942114 starts --*/
842 /* if l_futa_def_bal_id is not NULL then
843      open chk_futa_status(p_business_group_id,p_start_date,l_futa_def_bal_id);
844      fetch chk_futa_status into l_temp_count; */
845 if p_futa_def_bal_id is not NULL then
846    open chk_futa_status(p_business_group_id,p_start_date,p_futa_def_bal_id);
847    fetch chk_futa_status into p_futa_status_count;
848  /*-- Bug#4942114 ends --*/
849    close chk_futa_status;
850 end if;
851 /*-- Bug#4942114 starts --*/
852   /* if l_temp_count = 1 then
853       p_futa_where := ' prb.defined_balance_id = '|| l_futa_def_bal_id
854                      ||' AND prb.assignment_action_id = ';
855       p_futa_from := ' pay_run_balances prb ';
856    else
857      p_futa_where := ' prr.status in ('||'''P'''||','||'''PA'''||')
858                 and pet.element_type_id      = prr.element_type_id
859             	and prr.assignment_action_id = ';
860       p_futa_from := ' pay_run_results prr ';
861    end if; */
862   /* -- Bug#4942114 ends --*/
863 p_er_liab_status := pay_us_payroll_utils.check_balance_status(p_start_date
864                                                          ,p_business_group_id
865                                                          ,'PAY_US_EMPLOYER_LIABILITY','US'); -- Bug#4942114
866 /* -- Bug#4942114 starts --*/
867 /*l_er_liab_status := pay_us_payroll_utils.check_balance_status(p_start_date
868                                                          ,p_business_group_id
869                                                          ,'PAY_US_EMPLOYER_LIABILITY','US');
870 if l_er_liab_status = 'Y' THEN
871   p_er_liab_where := ' prb.defined_balance_id = pdb.defined_balance_id
872               and   (pdb.business_group_id ='||p_business_group_id||
873                  ' or pbd.legislation_code ='|| '''US'''||')
874               and  pdb.balance_type_id = pbt.balance_type_id
875               and pdb.balance_dimension_id = pbd.balance_dimension_id
876               and pbd.legislation_code = '||'''US'''||
877             ' and pbd.database_item_suffix ='||'''_ASG_GRE_RUN'''||
878            ' and   prb.assignment_action_id = ';
879 p_er_liab_from := 'pay_run_balances prb,
880 		   pay_defined_balances pdb,
881 		   pay_balance_dimensions pbd ';
882 
883 else
884  p_er_liab_where := ' prr.element_type_id +0 = pet.element_type_id
885              and   prr.status in (' || '''P''' || ', ' || '''PA''' || ')
886              and   prr.assignment_action_id = ';
887 p_er_liab_from  := ' pay_run_results prr ';
888 end if; */
889 /*-- Bug#4942114 ends --*/
890 
891    open c_wc_er_liab_valid_count(p_business_group_id,l_trunc_date);
892      fetch c_wc_er_liab_valid_count into p_wc_er_liab_status_count; -- Bug#4942114
893    --fetch c_wc_er_liab_valid_count into l_temp_count; -- Bug#4942114
894    close c_wc_er_liab_valid_count;
895 
896  /*-- Bug#4942114 starts --*/
897    /* if l_temp_count = 3 then
898       p_wc_er_liab_where := ' prb.defined_balance_id = pdb.defined_balance_id
899                          AND pdb.balance_type_id = pbt.balance_type_id
900                          AND pdb.balance_dimension_id = pbd.balance_dimension_id
901                          AND pbd.legislation_code = '||'''US'''
902                      ||'  AND pbd.database_item_suffix ='||'''_ASG_JD_GRE_RUN'''
903                      ||' AND (pdb.legislation_code ='||'''US'''
904                               ||' OR pdb.business_group_id ='||p_business_group_id||')
905                           and    prb.assignment_action_id = paa.assignment_action_id
906                           and    prb.tax_unit_id = paa.tax_unit_id
907                           and    prb.jurisdiction_code = pst.state_code
908                           and    prb.tax_unit_id  = paa.tax_unit_id';
909     p_wc_er_liab_from :=' pay_run_balances prb,
910     			pay_balance_dimensions pbd,
911     			pay_defined_balances pdb ';
912 
913    else
914      p_wc_er_liab_where := ' prr.element_type_id +0   = pet.element_type_id
915                            and prr.assignment_action_id = paa.assignment_action_id';
916      p_wc_er_liab_from := ' pay_run_results prr ';
917    end if; */
918   /*-- Bug#4942114 ends --*/
919 
920  exception
921  when no_data_found then
922 null;
923 end;
924       hr_utility.trace('leaving archive_init');
925 end ARCHIVE_INIT;
926 
927 
928 Procedure ARCHIVE_CODE (p_payroll_action_id                 IN NUMBER
929 	     	       ,p_chunk_number                       IN NUMBER)  IS
930 begin
931       hr_utility.trace('entering archive_code');
932       hr_utility.trace('l_arch_count ='||l_arch_count);
933  /*-- Bug#4942114 starts --*/
934   /* pay_gtnlod_pkg.load_data(p_payroll_action_id => p_payroll_action_id,
935     			    p_chunk => p_chunk_number,
936                             ppa_finder => p_ppa_finder,
937                             p_ded_view_name =>  p_ded_view_name,
938 		       	    p_earn_view_name => p_earn_view_name,
939 		            p_fed_view_name  => p_fed_view_name,
940 			    p_state_view_name  => p_state_view_name,
941 			    p_local_view_name => p_local_view_name,
942 			    p_fed_liab_view_name => p_fed_liab_view_name,
943 			    p_state_liab_view_name => p_state_liab_view_name,
944 			    p_futa_where => p_futa_where,
945 			    p_futa_from  => p_futa_from,
946 			    p_er_liab_where => p_er_liab_where,
947 			    p_er_liab_from  => p_er_liab_from,
948 			    p_wc_er_liab_where => p_wc_er_liab_where,
949 			    p_wc_er_liab_from  => p_wc_er_liab_from,
950 			    p_asg_flag => p_asg_flag);
951 	l_arch_count := l_arch_count +1;
952    */
953 
954       pay_gtnlod_pkg.load_data(p_payroll_action_id => p_payroll_action_id,
955     			    p_chunk => p_chunk_number,
956                             ppa_finder => p_ppa_finder,
957 			    p_ded_bal_status1 => p_ded_bal_status1,
958 			    p_ded_bal_status2 => p_ded_bal_status2,
959 			    p_earn_bal_status => p_earn_bal_status,
960 			    p_fed_bal_status  => p_fed_bal_status,
961 			    p_state_bal_status=> p_state_bal_status,
962 			    p_local_bal_status=> p_local_bal_status,
963 			    p_fed_liab_bal_status => p_fed_liab_bal_status,
964 			    p_state_liab_bal_status => p_state_liab_bal_status,
965 			    p_futa_status_count => p_futa_status_count,
966 			    p_futa_def_bal_id => p_futa_def_bal_id,
967 			    p_er_liab_status => p_er_liab_status,
968 			    p_wc_er_liab_status_count => p_wc_er_liab_status_count,
969 			    p_asg_flag => p_asg_flag);
970  /*-- Bug#4942114 ends --*/
971       hr_utility.trace('leaving archive_code');
972 end ARCHIVE_CODE;
973 
974 PROCEDURE CREATE_GTN_XML_DATA
975 IS
976     lb_xml_blob     BLOB;
977     lv_proc_name    VARCHAR2(100);
978 
979 BEGIN
980 
981    lv_proc_name := g_proc_name || 'CREATE_GTN_XML_DATA';
982    hr_utility.trace ('Entering '|| lv_proc_name);
983 
984    pay_us_xdo_report.populate_gtn_report_data(p_ppa_finder => p_ppa_finder
985                                                 ,p_xfdf_blob  => lb_xml_blob);
986    pay_core_files.write_to_magtape_lob(lb_xml_blob);
987 
988    hr_utility.trace ('Leaving '|| lv_proc_name);
989 
990 EXCEPTION WHEN OTHERS THEN
991    HR_UTILITY.TRACE('Inside Exception WHEN OTHERS of Procedure' || lv_proc_name);
992 END CREATE_GTN_XML_DATA;
993 
994 
995 Procedure ARCHIVE_DEINIT(p_payroll_action_id IN NUMBER) IS
996 
997    -- Get request_id
998    CURSOR get_request_id (c_pact_id NUMBER)IS
999    SELECT request_id
1000      FROM pay_payroll_actions
1001     WHERE payroll_action_id = c_pact_id;
1002 
1003    -- Get Application Short Name and Application ID
1004    CURSOR get_application_detais(c_request_id NUMBER) IS
1005    SELECT app.application_short_name, fcp.application_id
1006      FROM fnd_application_vl app,
1007           fnd_concurrent_programs fcp,
1008           fnd_concurrent_requests r
1009     WHERE fcp.concurrent_program_id = r.concurrent_program_id
1010       AND r.request_id = c_request_id
1011       and app.application_id = fcp.application_id;
1012 
1013 
1014     -- Get template type
1015     CURSOR get_template_type(c_templ_code xdo_templates_tl.template_code%TYPE) IS
1016     SELECT template_type_code
1017       FROM xdo_templates_vl
1018      WHERE template_code = c_templ_code;
1019 --bug 6365474
1020   cursor csr_release is
1021   select      to_number(substr(PRODUCT_VERSION,1,2))
1022     from FND_PRODUCT_INSTALLATIONS
1023    where APPLICATION_ID = 800;
1024    l_release       number;
1025 --bug 6365474
1026 
1027 -- bug 6799553
1028 -- Get printer details
1029    /*CURSOR get_printer_details(request_id NUMBER) IS
1030    SELECT printer, print_style, number_of_copies, save_output_flag, print_group
1031    FROM fnd_concurrent_requests
1032    WHERE request_id = request_id ;*/
1033 -- bug 7297300
1034    /* Changing the Parameter Name from request_id to c_request_id */
1035    CURSOR get_printer_details(c_request_id NUMBER) IS
1036    SELECT printer, print_style, number_of_copies, save_output_flag, print_group
1037    FROM fnd_concurrent_requests
1038    WHERE request_id = c_request_id ;
1039 
1040    printer                 fnd_concurrent_requests.printer%TYPE;
1041    print_style             fnd_concurrent_requests.print_style%TYPE;
1042    number_of_copies        fnd_concurrent_requests.number_of_copies%TYPE;
1043    save_output_flag        fnd_concurrent_requests.save_output_flag%TYPE;
1044    save_output             BOOLEAN;
1045    print_group             fnd_concurrent_requests.print_group%TYPE;
1046    result                  BOOLEAN;
1047 -- bug 6799553
1048 
1049    ln_req_id               NUMBER;
1050    ln_current_request_id   NUMBER;
1051    ln_application_id       NUMBER;
1052    lv_proc_name            VARCHAR2(100);
1053    lv_template_type        xdo_templates_b.template_type_code%TYPE;
1054    lv_template_code        xdo_templates_tl.template_code%TYPE;
1055    lv_app_short_name       fnd_application_vl.application_short_name%TYPE;
1056 
1057 
1058 BEGIN
1059 
1060    lv_proc_name := g_proc_name || 'CREATE_GTN_XML_DATA';
1061    hr_utility.trace ('Entering '|| lv_proc_name);
1062    hr_utility.trace ('p_payroll_action_id '|| p_payroll_action_id);
1063    hr_utility.trace ('p_template_code '|| p_template_code);
1064 --bug 6365474
1065    OPEN csr_release;
1066    FETCH csr_release INTO l_release;
1067    CLOSE csr_release;
1068 --bug 6365474
1069    lv_template_code := p_template_code;
1070 
1071    OPEN get_request_id(p_payroll_action_id);
1072    FETCH get_request_id INTO ln_current_request_id;
1073    CLOSE get_request_id;
1074 
1075    OPEN get_application_detais(ln_current_request_id);
1076    FETCH get_application_detais INTO lv_app_short_name
1077                                     ,ln_application_id;
1078    CLOSE get_application_detais;
1079 
1080    OPEN get_template_type(lv_template_code);
1081    FETCH get_template_type INTO lv_template_type;
1082    CLOSE get_template_type;
1083 
1084  -- bug 6799553
1085    OPEN get_printer_details(ln_current_request_id);
1086    FETCH get_printer_details INTO printer,print_style,number_of_copies,save_output_flag,print_group;
1087    CLOSE get_printer_details ;
1088 
1089    if(save_output_flag is not NULL ) then
1090 	if(save_output_flag = 'Y') then
1091 	save_output := true;
1092 	elsif(save_output_flag = 'N') then
1093 	save_output := false;
1094 	end if;
1095    end if;
1096    result := fnd_request.set_print_options
1097             (
1098                 printer => printer,
1099                 style => print_style,
1100                 copies => number_of_copies,
1101                 save_output => save_output,
1102                 print_together => print_group
1103             );
1104  -- bug 6799553
1105 
1106    pay_archive.remove_report_actions(p_payroll_action_id);
1107 
1108    hr_utility.trace ('ln_current_request_id '|| ln_current_request_id);
1109    hr_utility.trace ('lv_template_code '|| lv_template_code);
1110    hr_utility.trace ('ln_application_id '|| ln_application_id);
1111    hr_utility.trace ('lv_template_type '|| lv_template_type);
1112 --bug 6365474
1113 if(l_release = 12) then
1114 
1115    ln_req_id := fnd_request.submit_request
1116                             (
1117                                application    => 'XDO',
1118                                program        => 'XDOREPPB',
1119                                argument1      => 'N',
1120                                argument2      => ln_current_request_id,
1121                                argument3      => ln_application_id,
1122                                argument4      => lv_template_code,
1123                                argument5      => NULL,
1124                                argument6      => 'N',
1125                                argument7      => lv_template_type,
1126                                argument8      => 'PDF'
1127 			     );
1128    hr_utility.trace ('Leaving 12'|| lv_proc_name);
1129 else
1130 --bug 6365474
1131    ln_req_id := fnd_request.submit_request
1132                             (
1133                                application    => 'XDO',
1134                                program        => 'XDOREPPB',
1135                                argument1      => ln_current_request_id,
1136                                argument2      => ln_application_id,
1137                                argument3      => lv_template_code,
1138                                argument4      => NULL,
1139                                argument5      => 'N',
1140                                argument6      => lv_template_type,
1141                                argument7      => 'PDF'
1142 			     );
1143 
1144 
1145 
1146    hr_utility.trace ('Leaving 11i'|| lv_proc_name);
1147 --bug 6365474
1148 end if;
1149 --bug 6365474
1150 
1151 --bug 6670508
1152 delete from pay_us_rpt_totals where tax_unit_id = p_payroll_action_id;
1153 --bug 6670508
1154 
1155 end ARCHIVE_DEINIT;
1156 
1157 BEGIN
1158 --        hr_utility.trace_on(NULL,'trc_pypaygtn');
1159         g_proc_name := 'PAY_PAYGTN_PKG.';
1160 
1161 END PAY_PAYGTN_PKG;