DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_US_TAX_INTERNAL

Source


1 PACKAGE BODY pay_us_tax_internal AS
2 /* $Header: pytaxbsi.pkb 120.11 2010/07/21 10:50:56 sjawid ship $ */
3 --
4 -- Package Variables
5 --
6    g_package  varchar2(33) := '  pay_us_tax_internal.';
7    --
8    PRV constant number := -1;
9    NXT constant number := 1;
10    --
11    TYPE location_rec is record
12       (
13        assignment_id per_assignments_f.assignment_id%TYPE,
14        location_id   per_assignments_f.location_id%TYPE,
15        start_date    per_assignments_f.effective_start_date%TYPE,
16        end_date      per_assignments_f.effective_end_date%TYPE
17       );
18    --
19    TYPE location_tbl is table of location_rec index by
20       binary_integer;
21 
22   cursor csr_get_tax_loc(p_assignment number, p_session_dt date) is
23   select hsck.segment18
24   from   HR_SOFT_CODING_KEYFLEX hsck,
25          PER_ASSIGNMENTS_F      paf
26   where  paf.assignment_id = p_assignment
27   and    p_session_dt between paf.effective_start_date
28                       and paf.effective_end_date
29   and    hsck.soft_coding_keyflex_id = paf.soft_coding_keyflex_id
30   and    hsck.segment18 is not null;
31 
32 cursor csr_loc_addr(p_lc_id number) is
33      select sta.state_code, cnt.county_code, cty.city_code,
34 	    sta2.state_code, cnt2.county_code, cty2.city_code
35      from   hr_locations loc
36            ,pay_us_states sta
37            ,pay_us_counties cnt
38            ,pay_us_city_names cty
39            ,pay_us_states sta2
40            ,pay_us_counties cnt2
41            ,pay_us_city_names cty2
42      where  loc.location_id = p_lc_id
43      AND   cnt.state_code = sta.state_code
44      AND   loc.town_or_city = cty.city_name
45      AND   loc.region_1 = cnt.county_name
46      AND   loc.region_2 = sta.state_abbrev
47      AND   cnt.state_code = cty.state_code
48      AND   cnt.county_code = cty.county_code
49      AND   cnt2.state_code = sta2.state_code
50      AND   nvl(loc.loc_information18,loc.town_or_city) = cty2.city_name
51      AND   nvl(loc.loc_information19,loc.region_1) = cnt2.county_name
52      AND   nvl(loc.loc_information17,loc.region_2) = sta2.state_abbrev
53      AND   cnt2.state_code = cty2.state_code
54      AND   cnt2.county_code = cty2.county_code;
55 
56 
57   cursor csr_res_addr(p_person_id number,p_effective_date date) is
58      select sta.state_code, cnt.county_code, cty.city_code,
59 	    sta2.state_code, cnt2.county_code, cty2.city_code
60      from   per_addresses adr
61            ,pay_us_states sta
62            ,pay_us_counties cnt
63            ,pay_us_city_names cty
64 	   ,pay_us_states sta2
65 	   ,pay_us_counties cnt2
66 	   ,pay_us_city_names cty2
67      where  adr.person_id = p_person_id
68      and    adr.primary_flag = 'Y'
69      and    p_effective_date between adr.date_from
70                                  and nvl(adr.date_to, hr_api.g_eot)
71      AND   CNT.STATE_CODE = STA.STATE_CODE
72      AND   ADR.TOWN_OR_CITY = CTY.CITY_NAME
73      AND   ADR.REGION_1 = CNT.COUNTY_NAME
74      AND   ADR.REGION_2 = STA.STATE_ABBREV
75      AND   CNT.STATE_CODE = CTY.STATE_CODE
76      AND   CNT.COUNTY_CODE = CTY.COUNTY_CODE
77      AND   CNT2.STATE_CODE = STA2.STATE_CODE
78      AND   nvl(adr.add_information18,ADR.TOWN_OR_CITY) = CTY2.CITY_NAME
79      AND   nvl(adr.add_information19,ADR.REGION_1) = CNT2.COUNTY_NAME
80      AND   nvl(adr.add_information17,ADR.REGION_2) = STA2.STATE_ABBREV
81      AND   CNT2.STATE_CODE = CTY2.STATE_CODE
82      AND   CNT2.COUNTY_CODE = CTY2.COUNTY_CODE;
83 
84 /*  Bug# 6496113 and 5600887: Condition checks for date effectivity which is not
85     required for person address form. The person address form will use the
86     following cursor */
87   cursor csr_res_addr_no_eff_dt(p_person_id number,p_effective_date date) is
88           select sta.state_code, cnt.county_code, cty.city_code,
89 	    sta2.state_code, cnt2.county_code, cty2.city_code
90      from   per_addresses adr
91            ,pay_us_states sta
92            ,pay_us_counties cnt
93            ,pay_us_city_names cty
94 	   ,pay_us_states sta2
95 	   ,pay_us_counties cnt2
96 	   ,pay_us_city_names cty2
97      where  adr.person_id = p_person_id
98      and    adr.primary_flag = 'Y'
99 
100 
101      AND   CNT.STATE_CODE = STA.STATE_CODE
102      AND   ADR.TOWN_OR_CITY = CTY.CITY_NAME
103      AND   ADR.REGION_1 = CNT.COUNTY_NAME
104      AND   ADR.REGION_2 = STA.STATE_ABBREV
105      AND   CNT.STATE_CODE = CTY.STATE_CODE
106      AND   CNT.COUNTY_CODE = CTY.COUNTY_CODE
107      AND   CNT2.STATE_CODE = STA2.STATE_CODE
108      AND   nvl(adr.add_information18,ADR.TOWN_OR_CITY) = CTY2.CITY_NAME
109      AND   nvl(adr.add_information19,ADR.REGION_1) = CNT2.COUNTY_NAME
110      AND   nvl(adr.add_information17,ADR.REGION_2) = STA2.STATE_ABBREV
111      AND   CNT2.STATE_CODE = CTY2.STATE_CODE
112      AND   CNT2.COUNTY_CODE = CTY2.COUNTY_CODE;
113 
114 
115  cursor csr_future_state_rule( p_state_code number,
116 			       p_assignment_id number,
117 				l_csr_date date default hr_api.g_sot) is
118     select null
119     from   pay_us_emp_state_tax_rules_f sta
120     where  sta.assignment_id = p_assignment_id
121     and    sta.state_code = p_state_code
122     and    sta.effective_start_date > l_csr_date;
123   --
124   cursor csr_future_county_rule( p_state_code number, p_county_code number,
125 				 p_assignment_id number,
126 				 l_csr_date date default hr_api.g_sot) is
127     select null
128     from   pay_us_emp_county_tax_rules_f cnt
129     where  cnt.assignment_id = p_assignment_id
130     and    cnt.state_code = p_state_code
131     and    cnt.county_code = p_county_code
132     and    cnt.effective_start_date > l_csr_date;
133   --
134   cursor csr_future_city_rule( p_state_code number, p_county_code number,
135 			       p_city_code varchar2, p_assignment_id number,
136 			       l_csr_date date default hr_api.g_sot) is
137     select null
138     from   pay_us_emp_city_tax_rules_f cty
139     where  cty.assignment_id = p_assignment_id
140     and    cty.state_code = p_state_code
141     and    cty.county_code = p_county_code
142     and    cty.city_code = p_city_code
143     and    cty.effective_start_date > l_csr_date;
144   --
145   -- reimp - moved csr because its used by more than one proc.
146   --
147   cursor csr_defaulting_met(p_asg_id number,p_ef_date date) is
148     select null
149     from   per_assignments_f asg, per_addresses adr
150     where  asg.assignment_id = p_asg_id
151     and    p_ef_date between asg.effective_start_date
152            and asg.effective_end_date
153     and    asg.pay_basis_id is not null
154     and    asg.payroll_id is not null
155     and    asg.location_id is not null
156     and    asg.soft_coding_keyflex_id is not null
157     and    asg.assignment_type = 'E'
158     and    asg.person_id = adr.person_id
159     and    p_ef_date between adr.date_from
160                               and nvl(adr.date_to, hr_api.g_eot)
161     and    adr.primary_flag = 'Y'
162     and    rownum = 1
163     and    exists (select null
164                    from  hr_soft_coding_keyflex sck
165                    where sck.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
166                    and   sck.segment1 is not null);
167   --
168 
169   cursor csr_defaulting_date(p_assignment_id number) is
170     select 	min(effective_start_date)
171     from 	pay_us_emp_fed_tax_rules_f
172     where 	assignment_id = p_assignment_id;
173 
174 --
175 -- ----------------------------------------------------------------------------
176 -- |----------------------< create_tax_rules_for_jd >-------------------------|
177 -- ----------------------------------------------------------------------------
178 --
179    Procedure create_tax_rules_for_jd
180       (
181  	p_state_code		   in  varchar default null,
182 	p_county_code		   in  varchar default null,
183 	p_city_code		   in  varchar default null,
184 	p_assignment_id		   in  varchar default null,
185 	p_effective_date	   in  date
186       ) IS
187 
188    	l_tmp_id number;
189 	l_tmp_ovn number;
190 	l_tmp_eff_start_date date;
191 	l_tmp_eff_end_date date;
192 	l_temp_char varchar2(50);
193 
194  begin
195 
196   if p_state_code is not null then
197 
198     open csr_future_state_rule(p_state_code,p_assignment_id);
199     fetch csr_future_state_rule into l_temp_char;
200     if csr_future_state_rule%notfound then
201       close csr_future_state_rule; -- 3431376
202       pay_state_tax_rule_api.create_state_tax_rule (
203                      p_effective_date         => p_effective_date
204                     ,p_default_flag           => 'Y'
205                     ,p_assignment_id          => p_assignment_id
206                     ,p_state_code             => p_state_code
207                     ,p_emp_state_tax_rule_id  => l_tmp_id
208                     ,p_object_version_number  => l_tmp_ovn
209                     ,p_effective_start_date   => l_tmp_eff_start_date
210                     ,p_effective_end_date     => l_tmp_eff_end_date
211                     );
212     else
213        close csr_future_state_rule;
214     end if;
215 
216     if p_county_code is not null then
217      	 open csr_future_county_rule(p_state_code,p_county_code,
218 				     p_assignment_id);
219      	 fetch csr_future_county_rule into l_temp_char;
220      	 if csr_future_county_rule%notfound then
221                 close csr_future_county_rule;
222       	    	pay_county_tax_rule_api.create_county_tax_rule (
223                    p_effective_date         => p_effective_date
224                   ,p_assignment_id          => p_assignment_id
225                   ,p_state_code             => p_state_code
226                   ,p_county_code            => p_county_code
227                   ,p_additional_wa_rate     => 0
228                   ,p_filing_status_code     => '01'
229                   ,p_lit_additional_tax     => 0
230                   ,p_lit_override_amount    => 0
231                   ,p_lit_override_rate      => 0
232                   ,p_withholding_allowances => 0
233                   ,p_lit_exempt             => 'N'
234                   ,p_emp_county_tax_rule_id => l_tmp_id
235                   ,p_object_version_number  => l_tmp_ovn
236                   ,p_effective_start_date   => l_tmp_eff_start_date
237                   ,p_effective_end_date     => l_tmp_eff_end_date
238                   );
239          else
240             close csr_future_county_rule;
241          end if;
242 
243 	 if p_city_code is not null then
244     	   open csr_future_city_rule(p_state_code,p_county_code,
245 		 	      	     p_city_code,p_assignment_id);
246     	   fetch csr_future_city_rule into l_temp_char;
247     	   if csr_future_city_rule%notfound then
248                 close csr_future_city_rule;
249       		pay_city_tax_rule_api.create_city_tax_rule (
250                    p_effective_date         => p_effective_date
251                   ,p_assignment_id          => p_assignment_id
252                   ,p_state_code             => p_state_code
253                   ,p_county_code            => p_county_code
254                   ,p_city_code              => p_city_code
255                   ,p_additional_wa_rate     => 0
256                   ,p_filing_status_code     => '01'
257                   ,p_lit_additional_tax     => 0
258                   ,p_lit_override_amount    => 0
259                   ,p_lit_override_rate      => 0
260                   ,p_withholding_allowances => 0
261                   ,p_lit_exempt             => 'N'
262                   ,p_emp_city_tax_rule_id   => l_tmp_id
263                   ,p_object_version_number  => l_tmp_ovn
264                   ,p_effective_start_date   => l_tmp_eff_start_date
265                   ,p_effective_end_date     => l_tmp_eff_end_date
266                   );
267            else
268               close csr_future_city_rule;
269            end if;
270 
271 	 end if; -- city not null
272        end if;	-- county not null
273      end if; -- state not not null
274 end create_tax_rules_for_jd;
275 
276 --
277 -- ----------------------------------------------------------------------------
278 -- |----------------------< maintain_tax_percentage >-------------------------|
279 -- ----------------------------------------------------------------------------
280 --
281    Procedure maintain_tax_percentage
282       (
283        p_assignment_id              in     number,
284        p_effective_date             in     date,
285        p_state_code                 in     varchar2,
286        p_county_code                in     varchar2,
287        p_city_code                  in     varchar2,
288        p_percentage                 in     number  default 0,
289        p_calculate_pct              in     boolean default true,
290        p_datetrack_mode             in     varchar2,
291        p_effective_start_date       in out nocopy date,
292        p_effective_end_date         in out nocopy date
293       ) is
294       --
295       -- -----------------------------------------------------------------
296       -- Declare cursors, types and local variables
297       -- -----------------------------------------------------------------
298       --
299       -- Cursor to determine all of the location changes in an
300       -- assignment.
301       --
302       -- reimp - changed cursor to only return rows on or after the defaulting
303       -- of taxes
304       Cursor csr_assignment_locations(p_assignment_id number,
305 				      p_def_date date) is
306          select location_id,
307                 effective_start_date,
308                 effective_end_date
309          from per_assignments_f
310          where assignment_id = p_assignment_id
311 	   and effective_start_date >= p_def_date
312          order by effective_start_date;
313       --
314       -- cursor finds the subordinate jurisdictions for use in
315       -- the percent sum routine.
316       --
317       cursor csr_get_sub_jurisdictions
318                 (
319                  p_assignment_id             number,
320                  p_subordinate_jurisdiction  varchar2,
321                  p_exclude_jurisdiction      varchar2,
322                  p_effective_date            date
323                 ) is
324          select peef.effective_start_date,
325             peef.effective_end_date,
326             peevf.screen_entry_value
327          from pay_element_entries_f peef,
328               pay_element_entry_values_f peevf,
329               pay_input_values_f pivf,
330               pay_element_types_f petf,
331               pay_element_links_f pelf
332          where peef.assignment_id = p_assignment_id
333            and peef.creator_type = 'UT'
334            and petf.element_name = 'VERTEX'
335            and peevf.screen_entry_value like p_subordinate_jurisdiction||'%'
336            and peevf.screen_entry_value not like '%'||p_exclude_jurisdiction||'%'
337            and upper(pivf.name)='JURISDICTION'
338            and peevf.input_value_id = pivf.input_value_id
339            and peef.element_entry_id = peevf.element_entry_id
340            and p_effective_date between peef.effective_start_date and
341                peef.effective_end_date
342            and peef.effective_start_date = peevf.effective_start_date
343            and peef.effective_end_date = peevf.effective_end_date
344            and peef.element_link_id = pelf.element_link_id
345            and pelf.element_type_id = petf.element_type_id
346          order by peef.assignment_id asc,
347                   petf.element_name asc,
348                   peef.element_entry_id asc,
349                   peef.effective_start_date asc,
350                   peevf.element_entry_value_id asc;
351 
352       -- Cursor to get the 'VERTEX' element type.
353       --
354       Cursor csr_vertex_element is
355          select petf.element_type_id,
356                 pivf.input_value_id,
357                 pivf.name
358          from PAY_ELEMENT_TYPES_F petf,
359               PAY_INPUT_VALUES_F pivf
360          where petf.element_name = 'VERTEX'
361            and p_effective_date between petf.effective_start_date
362               and petf.effective_end_date
363            and petf.element_type_id = pivf.element_type_id
364            and p_effective_date between pivf.effective_start_date
365               and pivf.effective_end_date;
366       --
367       -- Cursor to get the 'VERTEX' element entry for
368       -- the jurisdiction.
369       --
370       cursor csr_ele_entry (p_element_link  number,
371                             p_input_val     number,
372                             p_jurisdiction  varchar2,
373                             p_assignment_id number) is
374          select peef.element_entry_id
375          from PAY_ELEMENT_ENTRIES_F peef,
376               PAY_ELEMENT_ENTRY_VALUES_F pevf
377          where peef.assignment_id = p_assignment_id
378            and p_effective_date between peef.effective_start_date
379            and peef.effective_end_date
380            and peef.element_link_id = p_element_link
381            and pevf.element_entry_id = peef.element_entry_id
382            and p_effective_date between pevf.effective_start_date
383               and pevf.effective_end_date
384            and pevf.input_value_id = p_input_val
385            and pevf.screen_entry_value like p_jurisdiction;
386       --
387       -- Cursor to get the 'VERTEX' element entry for
388       -- the jurisdiction.(INSERT OVERRIDE)
389       --
390       cursor csr_ele_entry_io (p_element_link  number,
391                                p_input_val     number,
392                                p_jurisdiction  varchar2,
393                                p_assignment_id number) is
394          select peef.element_entry_id, peef.effective_start_date
395          from PAY_ELEMENT_ENTRIES_F peef,
396               PAY_ELEMENT_ENTRY_VALUES_F pevf
397          where peef.assignment_id = p_assignment_id
398            and peef.element_link_id = p_element_link
399            and pevf.element_entry_id = peef.element_entry_id
400            and pevf.input_value_id = p_input_val
401            and pevf.screen_entry_value = p_jurisdiction
402            and rownum = 1
403            order by peef.effective_start_date asc;
404       --
405       -- Finds all vertex entries for an assignment
406       -- in a particular jurisdiction for INSERT_OVERRIDE.
407       --
408       cursor csr_vertex_in_jurisdiction(p_element_link number,
409                                         p_input_val number)is
410          select peef.element_entry_id, peef.effective_start_date,
411                 peef.effective_end_date
412          from PAY_ELEMENT_ENTRIES_F peef,
413               PAY_ELEMENT_ENTRY_VALUES_F pevf
414          where peef.assignment_id = p_assignment_id
415            and peef.element_link_id = p_element_link
416            and pevf.element_entry_id = peef.element_entry_id
417            and pevf.effective_start_date = peef.effective_start_date
418            and pevf.effective_end_date = peef.effective_end_date /* bug 9491711 */
419            and p_effective_date between pevf.effective_start_date
420               and pevf.effective_end_date
421            and pevf.input_value_id = p_input_val
422            and pevf.screen_entry_value =
423                p_state_code ||'-'|| p_county_code ||'-'|| p_city_code
424          order by peef.effective_start_date;
425       --
426       -- Cursor to get the current percentage of the element entry
427       --
428       cursor csr_get_curr_percnt (p_ele_entry_id   number,
429                                   p_input_val      number,
430                                   p_effective_date date)is
431          select screen_entry_value
432          from PAY_ELEMENT_ENTRY_VALUES_F
433          where element_entry_id = p_ele_entry_id
434            and  p_effective_date between effective_start_date
435               and effective_end_date
436            and input_value_id = p_input_val
437            and screen_entry_value is not null;
438       --
439       -- Find all jurisdiction codes for a given assignment.
440       --
441       cursor csr_get_jurisdiction (l_assignment_id  number,
442                                    l_effective_date date) is
443          select /*+ ORDERED
444                     INDEX(PAF PER_ASSIGNMENTS_F_PK)
445                     USE_NL(PAF, HL, PUS, PUC, PUCN) */
446                 pus.state_code ||'-'|| puc.county_code ||'-'|| pucn.city_code
447          from per_assignments_f paf,
448               hr_locations      hl,
449               pay_us_states     pus,
450               pay_us_counties   puc,
451               pay_us_city_names pucn
452          where paf.assignment_id  = l_assignment_id
453            and l_effective_date   between paf.effective_start_date
454                                       and paf.effective_end_date
455            and hl.location_id     = paf.location_id
456            and nvl(hl.loc_information18, hl.town_or_city) = pucn.city_name
457            and nvl(hl.loc_information19, hl.region_1)     = puc.county_name
458            and nvl(hl.loc_information17, hl.region_2)     = pus.state_abbrev
459            and pus.state_code     = puc.state_code
460            and puc.state_code     = pucn.state_code
461            and puc.county_code    = pucn.county_code;
462       --
463       cursor csr_get_ele_entry_id(
464                                   p_assignment_id  number,
465                                   p_jurisdiction   varchar2,
466                                   p_effective_date date
467                                  ) is
468          select peef.element_entry_id
469          from pay_element_entries_f peef, pay_element_entry_values_f peevf,
470               pay_element_links_f pelf, pay_element_types_f petf
471          where peef.assignment_id= p_assignment_id
472            and petf.element_name='VERTEX'
473            and peevf.screen_entry_value = p_jurisdiction
474            and p_effective_date between peef.effective_start_date
475                and peef.effective_end_date
476            and peef.element_link_id = pelf.element_link_id
477            and pelf.element_type_id = petf.element_type_id
478            and peef.element_entry_id = peevf.element_entry_id
479            and p_effective_date between peevf.effective_start_date
480                and peevf.effective_end_date;
481       --
482       TYPE l_element_rec is table of csr_vertex_in_jurisdiction%ROWTYPE
483            index by binary_integer;
484       --
485       TYPE location_rec is record
486          (
487           assignment_id per_assignments_f.assignment_id%TYPE,
488           location_id   per_assignments_f.location_id%TYPE,
489           start_date    per_assignments_f.effective_start_date%TYPE,
490           end_date      per_assignments_f.effective_end_date%TYPE
491          );
492       --
493       TYPE location_tbl is table of location_rec index by
494            binary_integer;
495       --
496       l_proc                 varchar2(72) := g_package||'maintain_tax_percentage';
497       l_element_type_id      pay_element_types_f.element_type_id%TYPE := null;
498       t_element_entry_id     pay_element_types_f.element_type_id%TYPE := null;
499       l_input_value_id_tbl   hr_entry.number_table;
500       l_new_vertex_value_tbl hr_entry.varchar2_table;
501       l_element_rec_tbl      l_element_rec;
502       l_asg_tbl              location_tbl;
503       l_location_chg_tbl     location_tbl;
504       l_state_code           pay_us_emp_city_tax_rules_f.state_code%TYPE;
505       l_county_code          pay_us_emp_city_tax_rules_f.county_code%TYPE;
506       l_city_code            pay_us_emp_city_tax_rules_f.city_code%TYPE;
507       l_jurisdiction         pay_us_emp_city_tax_rules_f.jurisdiction_code%TYPE;
508       l_datetrack_mode       varchar2(30);
509       l_location_id          per_assignments_f.location_id%TYPE;
510       l_start_date           per_assignments_f.effective_start_date%TYPE;
511       l_end_date             per_assignments_f.effective_end_date%TYPE;
512       cur_location_id        per_assignments_f.location_id%TYPE;
513       cur_start_date         per_assignments_f.effective_start_date%TYPE;
514       cur_end_date           per_assignments_f.effective_end_date%TYPE;
515       l_effective_start_date pay_us_emp_city_tax_rules_f.effective_start_date%TYPE;
516       l_effective_end_date   pay_us_emp_city_tax_rules_f.effective_end_date%TYPE;
517       l_assignment_id        per_assignments_f.assignment_id%TYPE := null;
518       l_effective_date       per_assignments_f.effective_start_date%TYPE := null;
519       l_input_value_id       pay_input_values_f.input_value_id%TYPE := null;
520       l_input_name           pay_input_values_f.name%TYPE := null;
521       l_element_link_id      pay_element_links_f.element_link_id%TYPE := null;
522       l_element_entry_id     pay_element_entries_f.element_entry_id%TYPE := null;
523       l_io                   boolean;
524       l_modified_correction  boolean := FALSE;
525       l_validate             boolean;
526       l_payroll_installed    boolean;
527       l_inc                  number;
528       l_asg_inc              number;
529       l_pct_inc              number;
530       l_percentage           number;
531       l_defaulting_date      date;
532       l_entry_found          boolean;
533       t_effective_start_date date;
534 --
535 -- ----------------------------------------------------------------------------
536 -- |-------------------< get_curr_jurisdiction_db_value >---------------------|
537 -- ----------------------------------------------------------------------------
538 --
539    function get_curr_jurisdiction_db_value
540                (
541                 p_assignment_id      number,
542                 p_jurisdiction       varchar2,
543                 p_effective_date     date,
544                 p_element_link_id    number,
545                 p_input_value_id_tbl hr_entry.number_table
546                )
547    return number is
548       l_element_entry_id   number;
549       l_cp		   varchar2(80);
550       l_current_percentage number;
551       l_proc                 varchar2(72)
552                              := g_package||'get_curr_jurisdiction_db_value';
553    begin
554       hr_utility.set_location('Entering:'||l_proc, 10);
555       open csr_ele_entry
556               (
557                p_element_link_id,
558                p_input_value_id_tbl(2),
559                p_jurisdiction,
560                p_assignment_id
561               );
562       fetch csr_ele_entry into l_element_entry_id;
563       hr_utility.set_location(l_proc, 20);
564       if csr_ele_entry%FOUND then
565          close csr_ele_entry;
566          open csr_get_curr_percnt
567                  (
568                   l_element_entry_id,
569                   p_input_value_id_tbl(3),
570                   p_effective_date
571                  );
572          fetch csr_get_curr_percnt into l_cp;
573 	 l_current_percentage := fnd_number.canonical_to_number(l_cp);
574          if csr_get_curr_percnt%FOUND then
575             close csr_get_curr_percnt;
576             return l_current_percentage;
577          else
578             close csr_get_curr_percnt;
579          end if;
580       end if;
581       close csr_ele_entry;
582       hr_utility.set_location('Leaving:'||l_proc, 30);
583       return 0;
584    end get_curr_jurisdiction_db_value;
585 --
586 -- ----------------------------------------------------------------------------
587 -- |--------------------------< chk_work_location >---------------------------|
588 -- ----------------------------------------------------------------------------
589 -- Check to see if the jurisdiction is a work location.
590 --
591    function chk_work_location(l_assignment_id  number,
592                               p_effective_date date,
593                               p_jurisdiction   varchar2
594                              )
595    return boolean is
596       l_jurisdiction varchar2(11);
597       l_proc                 varchar2(72)
598                              := g_package||'chk_work_location';
599    begin
600       hr_utility.set_location('Entering:'||l_proc, 10);
601       open csr_get_jurisdiction
602               (
603                p_assignment_id,
604                p_effective_date
605               );
606       fetch csr_get_jurisdiction into l_jurisdiction;
607       if csr_get_jurisdiction%FOUND and
608          l_jurisdiction = p_jurisdiction then
609          close csr_get_jurisdiction;
610          return TRUE;
611       else
612          close csr_get_jurisdiction;
613          return FALSE;
614       end if;
615       hr_utility.set_location('Leaving:'||l_proc, 20);
616    end chk_work_location;
617 --
618 -- ----------------------------------------------------------------------------
619 -- |----------------------------< asg_loc_comp >------------------------------|
620 -- ----------------------------------------------------------------------------
621 -- Determine if an assignment's current location has been changed to the same
622 -- location as the next or previous assignment record.
623 --
624    function asg_loc_comp(
625                          t_asg_tbl         location_tbl,
626                          l_prev_next       number,
627                          l_effective_date  date,
628                          l_defaulting_date date
629                         )
630    return boolean is
631       l_inc number;
632       l_proc                 varchar2(72)
633                              := g_package||'asg_loc_comp';
634    Begin
635       hr_utility.set_location('Entering:'||l_proc, 10);
636       if t_asg_tbl.first is not null then
637          l_inc := t_asg_tbl.first;
638          while t_asg_tbl.exists(l_inc) loop
639             if l_effective_date >= t_asg_tbl(l_inc).start_date
640                and l_effective_date <= t_asg_tbl(l_inc).end_date
641                then
642                if t_asg_tbl.exists(l_inc+l_prev_next) then
643                   if t_asg_tbl(l_inc).location_id =
644                      t_asg_tbl(l_inc+l_prev_next).location_id and
645                      t_asg_tbl(l_inc+l_prev_next).start_date >=
646                      l_defaulting_date then
647                      return TRUE;
648                   end if;
649                end if;
650             end if;
651          l_inc := t_asg_tbl.next(l_inc);
652          end loop;
653       end if;
654       hr_utility.set_location('Leaving:'||l_proc, 20);
655       return FALSE;
656    end asg_loc_comp;
657 --
658 -- ----------------------------------------------------------------------------
659 -- |--------------------< set_and_correct_jurisdiction >----------------------|
660 -- ----------------------------------------------------------------------------
661 -- This procedure corrects the actual percentage stored within the
662 -- pay_element_entry_values_f structure for a 'VERTEX' element in a given
663 -- jurisdiction.
664 --
665     procedure set_and_correct_jurisdiction
666                (
667                 p_assignment_id      number,
668                 p_jurisdiction       varchar2,
669                 p_percentage         number,
670                 p_element_link_id    number,
671                 p_input_value_id_tbl hr_entry.number_table,
672                 p_effective_date     date
673                )
674    is
675       l_proc                 varchar2(72)
676                              := g_package||'set_and_correct_jurisdiction';
677       l_new_vertex_value_tbl hr_entry.varchar2_table;
678       l_element_entry_id     number;
679    begin
680       hr_utility.set_location('Entering:'||l_proc, 10);
681       open csr_ele_entry
682               (
683                p_element_link_id,
684                p_input_value_id_tbl(2),
685                p_jurisdiction,
686                p_assignment_id
687               );
688       fetch csr_ele_entry into l_element_entry_id;
689       if csr_ele_entry%FOUND then
690          close csr_ele_entry;
691          l_new_vertex_value_tbl(1)     := null;
692          l_new_vertex_value_tbl(2)     := p_jurisdiction;
693          if p_percentage is not null then
694             hr_utility.set_location(l_proc, 20);
695             l_new_vertex_value_tbl(3)     := fnd_number.canonical_to_number(p_percentage);
696             hr_entry_api.update_element_entry
697                (
698                 p_dt_update_mode           => 'CORRECTION',
699                 p_session_date             => p_effective_date,
700                 p_element_entry_id         => l_element_entry_id,
701                 p_num_entry_values         => 3,
702                 p_input_value_id_tbl       => p_input_value_id_tbl,
703                 p_entry_value_tbl          => l_new_vertex_value_tbl
704                );
705          else
706             hr_utility.set_location(l_proc, 30);
707             hr_utility.set_message(801, 'HR_7040_PERCENT_RANGE');
708             hr_utility.set_message_token('1',l_proc);
709             hr_utility.raise_error;
710          end if;
711       else
712                hr_utility.set_message(801, 'HR_13140_TAX_ELEMENT_ERROR');
713                hr_utility.set_message_token('2','VERTEX');
714                hr_utility.raise_error;
715       end if;
716       hr_utility.set_location('Leaving:'||l_proc, 40);
717    end set_and_correct_jurisdiction;
718 --
719 -- ----------------------------------------------------------------------------
720 -- |------------------< get_sub_jurisdiction_sum >----------------------------|
721 -- ----------------------------------------------------------------------------
722 -- This procedure determines the percentage sum of subordinate jurisdictions
723 -- for the current jurisdiction at the effective_date for an assignemnt.
724 --
725    function get_sub_jurisdiction_sum
726                (
727                 p_jurisdiction        varchar2,
728                 p_assignment_id       number,
729                 p_element_link_id     number,
730                 p_input_value_id_tbl  hr_entry.number_table,
731                 p_effective_date      date
732                )
733    return number is
734       l_state                varchar2(10);
735       l_county               varchar2(10);
736       l_city                 varchar2(10);
737       l_exclude_jurisdiction varchar2(11);
738       l_sum                  number := 0;
739       l_proc                 varchar2(72)
740                              := g_package||'get_sub_jurisdiction_sum';
741    begin
742       hr_utility.set_location('Entering:'||l_proc, 10);
743       l_state := substr(p_jurisdiction,1,2);
744       l_county := nvl(substr(p_jurisdiction,4,3),'000');
745       l_city := nvl(substr(p_jurisdiction,8,4),'0000');
746       l_exclude_jurisdiction := l_state||'-'||l_county||'-'||l_city;
747       for sub_jurisdiction in csr_get_sub_jurisdictions
748                 (
749                  p_assignment_id,
750                  p_jurisdiction,
751                  l_exclude_jurisdiction,
752                  p_effective_date
753                 ) loop
754          l_sum := l_sum + get_curr_jurisdiction_db_value
755                              (
756                               p_assignment_id,
757                               sub_jurisdiction.screen_entry_value,
758                               p_effective_date,
759                               p_element_link_id,
760                               p_input_value_id_tbl
761                              );
762       end loop;
763       hr_utility.set_location('Leaving:'||l_proc, 20);
764       return l_sum;
765    end get_sub_jurisdiction_sum;
766 --
767 -- ----------------------------------------------------------------------------
768 -- |-----------------------< calculate_db_percentage >------------------------|
769 -- ----------------------------------------------------------------------------
770 -- This procedure determines the actual percentage to be stored within the
771 -- pay_element_entry_values_f structure for a 'VERTEX' element in a given
772 -- jurisdiction.
773 --
774    procedure calculate_db_percentage
775                 (
776                  p_scn_percent          number,
777                  p_state_code           varchar2,
778                  p_county_code          varchar2,
779                  p_city_code            varchar2,
780                  p_element_link_id      number,
781                  p_input_value_id_tbl   hr_entry.number_table,
782                  p_effective_date       date
783                 )
784    is
785       l_proc                   varchar2(72) := g_package||'calculate_db_percentage';
786       l_curr_cty_db_value      number :=0;
787       l_curr_cnt_db_value      number :=0;
788       l_curr_sta_db_value      number :=0;
789       l_new_cty_db_value       number :=0;
790       l_new_cnt_db_value       number :=0;
791       l_new_sta_db_value       number :=0;
792       l_cty_sum                number :=0;
793       l_cty_cnt_sum            number :=0;
794       l_other_jurisdiction_sum number :=0;
795    begin
796       hr_utility.set_location('Entering:'||l_proc, 10);
797       l_jurisdiction := p_state_code||'-'||
798                         p_county_code||'-'||
799                         p_city_code;
800       if p_city_code <> '0000' then
801          hr_utility.set_location(l_proc, 15);
802          l_curr_cty_db_value := get_curr_jurisdiction_db_value
803                                    (
804                                     p_assignment_id,
805                                     l_jurisdiction,
806                                     p_effective_date,
807                                     p_element_link_id,
808                                     p_input_value_id_tbl
809                                    );
810          hr_utility.set_location(l_proc, 20);
811          l_curr_cnt_db_value := get_curr_jurisdiction_db_value
812                                    (
813                                     p_assignment_id,
814                                     p_state_code||'-'||
815                                     p_county_code||'-0000',
816                                     p_effective_date,
817                                     p_element_link_id,
818                                     p_input_value_id_tbl
819                                    );
820          l_new_cnt_db_value := l_curr_cty_db_value - p_scn_percent +
821                                l_curr_cnt_db_value;
822          if l_new_cnt_db_value < 0 then
823             hr_utility.set_message(801, 'PAY_52236_TAX_CITY_PERCENT');
824             hr_utility.set_message_token('PROCEDURE', l_proc);
825             hr_utility.set_message_token('STEP','25');
826             hr_utility.raise_error;
827          else
828             hr_utility.set_location(l_proc, 30);
829             set_and_correct_jurisdiction
830                (
831                 p_assignment_id,
832                 l_jurisdiction,
833                 p_scn_percent,
834                 p_element_link_id,
835                 p_input_value_id_tbl,
836                 p_effective_date
837                );
838             hr_utility.set_location(l_proc, 35);
839             set_and_correct_jurisdiction
840                (
841                 p_assignment_id,
842                 p_state_code||'-'||p_county_code||'-0000',
843                 l_new_cnt_db_value,
844                 p_element_link_id,
845                 p_input_value_id_tbl,
846                 p_effective_date
847                );
848          end if;
849       elsif p_county_code <> '000' and p_city_code = '0000' then
850          hr_utility.set_location(l_proc, 40);
851          l_curr_cnt_db_value := get_curr_jurisdiction_db_value
852                                    (
853                                     p_assignment_id,
854                                     l_jurisdiction,
855                                     p_effective_date,
856                                     p_element_link_id,
857                                     p_input_value_id_tbl
858                                    );
859          hr_utility.set_location(l_proc, 45);
860          l_cty_sum := get_sub_jurisdiction_sum
861                          (
862                           p_state_code||'-'||p_county_code,
863                           p_assignment_id,
864                           p_element_link_id,
865                           p_input_value_id_tbl,
866                           p_effective_date
867                           );
868          hr_utility.set_location(l_proc, 50);
869          l_curr_sta_db_value := get_curr_jurisdiction_db_value
870                                    (
871                                     p_assignment_id,
872                                     p_state_code||'-'||'000-0000',
873                                     p_effective_date,
874                                     p_element_link_id,
875                                     p_input_value_id_tbl
876                                    );
877          l_new_cnt_db_value := p_scn_percent - l_cty_sum;
878          if l_new_cnt_db_value < 0 then
879             hr_utility.set_message(801, 'PAY_72831_TAX_MIN_CNT_PCT');
880             hr_utility.raise_error;
881          else
882             hr_utility.set_location(l_proc, 60);
883             l_new_sta_db_value := l_curr_cnt_db_value - l_new_cnt_db_value
884                                   + l_curr_sta_db_value;
885             if l_new_sta_db_value < 0 then
886                hr_utility.set_message(801, 'PAY_52237_TAX_COUNTY_PERCENT');
887                hr_utility.raise_error;
888             else
889                hr_utility.set_location(l_proc, 70);
890                set_and_correct_jurisdiction
891                   (
892                    p_assignment_id,
893                    l_jurisdiction,
894                    l_new_cnt_db_value,
895                    p_element_link_id,
896                    p_input_value_id_tbl,
897                    p_effective_date
898                   );
899                hr_utility.set_location(l_proc, 75);
900                set_and_correct_jurisdiction
901                   (
902                    p_assignment_id,
903                    p_state_code||'-'||'000-0000',
904                    l_new_sta_db_value,
905                    p_element_link_id,
906                    p_input_value_id_tbl,
907                    p_effective_date
908                   );
909             end if;
910          end if;
911       elsif p_state_code <> '00' and p_county_code = '000' and
912             p_city_code = '0000' then
913          hr_utility.set_location(l_proc, 80);
914          l_cty_cnt_sum := get_sub_jurisdiction_sum
915                              (
916                               p_state_code,
917                               p_assignment_id,
918                               p_element_link_id,
919                               p_input_value_id_tbl,
920                               p_effective_date
921                              );
922          l_new_sta_db_value := p_scn_percent - l_cty_cnt_sum;
923          if l_new_sta_db_value < 0 then
924             hr_utility.set_message(801, 'PAY_72832_TAX_MIN_STA_PCT');
925             hr_utility.raise_error;
926          else
927             hr_utility.set_location(l_proc, 90);
928             for asg_other_jurisdiction in csr_get_sub_jurisdictions
929                                              (
930                                               p_assignment_id,
931                                               '',
932                                               p_state_code||'-',
933                                               p_effective_date
934                                              ) loop
935                hr_utility.set_location(l_proc, 95);
936                l_other_jurisdiction_sum := l_other_jurisdiction_sum +
937                                            get_curr_jurisdiction_db_value
938                                               (
939                                                p_assignment_id,
940                                                asg_other_jurisdiction.screen_entry_value,
941                                                p_effective_date,
942                                                p_element_link_id,
943                                                p_input_value_id_tbl
944                                               );
945             end loop;
946             if l_cty_cnt_sum + l_new_sta_db_value +
947                l_other_jurisdiction_sum > 100 then
948                hr_utility.set_message(801, 'PAY_72833_TAX_MAX_STA_PCT');
949                hr_utility.raise_error;
950             else
951                hr_utility.set_location(l_proc, 105);
952                set_and_correct_jurisdiction
953                   (
954                    p_assignment_id,
955                    l_jurisdiction,
956                    l_new_sta_db_value,
957                    p_element_link_id,
958                    p_input_value_id_tbl,
959                    p_effective_date
960                   );
961             end if;
962          end if;
963       end if;
964       hr_utility.set_location('Leaving:'||l_proc, 110);
965    end calculate_db_percentage;
966 
967    Begin
968       --
969       hr_utility.set_location('Entering:'|| l_proc, 5);
970       --
971       --
972       -- Process Logic
973       --
974       --
975       -- Check to see if the PAYROLL product is installed.
976       --
977       l_payroll_installed := hr_utility.chk_product_install
978                                 (p_product     =>'Oracle Payroll',
979                                  p_legislation =>'US');
980       if l_payroll_installed then
981 
982        hr_utility.set_location(l_proc, 15);
983          --
984          -- Find the element entry type id, input_value, and
985          -- input name for and element type with a screen value
986          -- of 'VERTEX'.
987          --
988          Open csr_vertex_element;
989 
990          hr_utility.set_location(l_proc, 20);
991 
992          loop
993             Fetch csr_vertex_element into l_element_type_id,
994                                        l_input_value_id,
995                                        l_input_name;
996             exit when csr_vertex_element%NOTFOUND;
997 
998             if upper(l_input_name) = 'PAY VALUE' then
999                l_input_value_id_tbl(1) := l_input_value_id;
1000             elsif upper(l_input_name) = 'JURISDICTION' then
1001                l_input_value_id_tbl(2) := l_input_value_id;
1002             elsif upper(l_input_name) = 'PERCENTAGE' then
1003                l_input_value_id_tbl(3) := l_input_value_id;
1004             end if;
1005          end loop;
1006 
1007          Close csr_vertex_element;
1008 
1009          hr_utility.set_location(l_proc, 25);
1010 
1011          --
1012          -- Check that all of the input value id(s)
1013          -- for the vertex element exist.
1014          --
1015          for i in 1..3 loop
1016             if l_input_value_id_tbl(i) = null or
1017                l_input_value_id_tbl(i) = 0 then
1018                hr_utility.set_message(801, 'HR_13140_TAX_ELEMENT_ERROR');
1019                hr_utility.set_message_token('26','VERTEX');
1020                hr_utility.raise_error;
1021             end if;
1022          end loop;
1023          --
1024          hr_utility.set_location(l_proc, 30);
1025          --
1026          -- assign the parameters to local variables because
1027          -- the element entry procedures expect them to be in
1028          -- out parameters
1029          --
1030          l_effective_start_date   := p_effective_start_date;
1031          l_effective_end_date     := p_effective_end_date;
1032          l_datetrack_mode         := p_datetrack_mode;
1033 
1034          l_jurisdiction := p_state_code||'-'||
1035                            p_county_code||'-'||p_city_code;
1036 
1037          if p_datetrack_mode <> 'ZAP' then
1038             --
1039             -- Get element link id
1040             --
1041             l_element_link_id := hr_entry_api.get_link
1042                                     (
1043                                      p_assignment_id   => p_assignment_id,
1044                                      p_element_type_id => l_element_type_id,
1045                                      p_session_date    => l_effective_start_date
1046                                     );
1047             if l_element_link_id is null or
1048                l_element_link_id = 0 then
1049                hr_utility.set_message(801, 'HR_13140_TAX_ELEMENT_ERROR');
1050                hr_utility.set_message_token('31','VERTEX');
1051                hr_utility.raise_error;
1052             end if;
1053          else
1054             open csr_get_ele_entry_id(
1055                                       p_assignment_id,
1056                                       l_jurisdiction,
1057                                       p_effective_date
1058                                      );
1059             fetch csr_get_ele_entry_id into l_element_entry_id;
1060             close csr_get_ele_entry_id;
1061          end if;
1062          --
1063          hr_utility.set_location(l_proc, 35);
1064          --
1065          if p_percentage < 0 or p_percentage > 100 then
1066             hr_utility.set_message(801, 'HR_7040_PERCENT_RANGE');
1067             hr_utility.set_message_token('PROCEDURE', l_proc);
1068             hr_utility.set_message_token('STEP','36');
1069             hr_utility.raise_error;
1070          end if;
1071          --
1072          --  Store screen entry value in the table
1073          --
1074          l_new_vertex_value_tbl(1)     := null;
1075          l_new_vertex_value_tbl(2)     := l_jurisdiction;
1076          l_new_vertex_value_tbl(3)     := nvl(fnd_number.canonical_to_number(p_percentage),'0');
1077          --
1078          If p_datetrack_mode in ('DELETE_NEXT_CHANGE',
1079                                  'FUTURE_CHANGE',
1080                                  'DELETE',
1081                                  'CORRECTION',
1082                                  'UPDATE',
1083                                  'UPDATE_CHANGE_INSERT',
1084                                  'UPDATE_OVERRIDE',
1085                                  'INSERT_OVERRIDE',
1086                                  'INSERT_OLD') then
1087             --
1088             hr_utility.set_location(l_proc, 40);
1089             --
1090             -- Find the element link id for the current assignment
1091             -- with the derived element entry type id.
1092             --
1093             if p_datetrack_mode = 'INSERT_OVERRIDE' then
1094                Open csr_ele_entry_io (
1095                                       l_element_link_id,
1096                                       l_input_value_id_tbl(2),
1097                                       l_jurisdiction,
1098                                       p_assignment_id);
1099                Fetch csr_ele_entry_io into l_element_entry_id, t_effective_start_date;
1100                Close csr_ele_entry_io;
1101             else
1102                Open csr_ele_entry (
1103                                    l_element_link_id,
1104                                    l_input_value_id_tbl(2),
1105                                    l_jurisdiction,
1106                                    p_assignment_id
1107                                   );
1108                Fetch csr_ele_entry into l_element_entry_id;
1109                Close csr_ele_entry;
1110             end if;
1111             --
1112             hr_utility.set_location(l_proc, 45);
1113             --
1114             if p_datetrack_mode not in ('UPDATE','INSERT_OVERRIDE', 'UPDATE_OVERRIDE') then
1115                open csr_get_curr_percnt(l_element_entry_id,
1116                                         l_input_value_id_tbl(3),
1117                                         p_effective_date);
1118                fetch csr_get_curr_percnt into l_new_vertex_value_tbl(3);
1119                if csr_get_curr_percnt%NOTFOUND then
1120                   close csr_get_curr_percnt;
1121                   hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1122                   hr_utility.set_message_token('PROCEDURE', l_proc);
1123                   hr_utility.set_message_token('STEP','46');
1124                   hr_utility.raise_error;
1125                end if;
1126                close csr_get_curr_percnt;
1127             end if;
1128          End if;
1129 
1130          --
1131          hr_utility.set_location(l_proc, 47);
1132          --
1133          --
1134          -- Find defaulting date
1135          --
1136          Open csr_defaulting_date(p_assignment_id);
1137          Fetch csr_defaulting_date into l_defaulting_date;
1138          close csr_defaulting_date;
1139 
1140          --
1141          -- Find and store the assignment location changes.
1142          --
1143          Open csr_assignment_locations(p_assignment_id,l_defaulting_date);
1144          Fetch csr_assignment_locations
1145           into cur_location_id,
1146                cur_start_date,
1147                cur_end_date;
1148 
1149          if csr_assignment_locations%FOUND then
1150             --
1151             hr_utility.set_location(l_proc, 50);
1152             --
1153 
1154             l_location_id := cur_location_id;
1155             l_start_date := cur_start_date;
1156             l_end_date := cur_end_date;
1157             l_inc := 0;
1158             l_asg_inc := 0;
1159             While csr_assignment_locations%FOUND loop
1160                --
1161                hr_utility.set_location(l_proc, 55);
1162                --
1163                l_asg_inc := l_asg_inc + 1;
1164 
1165                --
1166                -- Store all assignment records.
1167                --
1168                l_asg_tbl(l_asg_inc).start_date := cur_start_date;
1169                l_asg_tbl(l_asg_inc).end_date := cur_end_date;
1170                l_asg_tbl(l_asg_inc).location_id := cur_location_id;
1171 
1172                Fetch csr_assignment_locations
1173                   into cur_location_id,
1174                        cur_start_date,
1175                        cur_end_date;
1176 
1177                if csr_assignment_locations%FOUND then
1178                   if l_location_id <> cur_location_id then
1179                      l_location_chg_tbl(l_inc).location_id
1180                                             := l_location_id;
1181                      l_location_chg_tbl(l_inc).start_date
1182                                             := l_start_date;
1183                      l_location_chg_tbl(l_inc).end_date
1184                                             := l_end_date;
1185                      l_inc     := l_inc + 1;
1186                      l_location_id := cur_location_id;
1187                      l_start_date := cur_start_date;
1188                      l_end_date := cur_end_date;
1189                   else
1190                      l_end_date := cur_end_date;
1191                   end if;
1192                else
1193                   l_location_chg_tbl(l_inc).location_id := l_location_id;
1194                   l_location_chg_tbl(l_inc).start_date := l_start_date;
1195                   l_location_chg_tbl(l_inc).end_date := l_end_date;
1196                end if;
1197             End loop;
1198             --
1199             hr_utility.set_location(l_proc, 60);
1200             --
1201          elsif p_datetrack_mode <> 'ZAP' then
1202             close csr_assignment_locations;
1203 
1204             hr_utility.set_message(801, 'HR_51746_ASG_INV_ASG_ID');
1205             hr_utility.set_message_token('PROCEDURE', l_proc);
1206             hr_utility.raise_error;
1207          end if;
1208          if csr_assignment_locations%ISOPEN then
1209             close csr_assignment_locations;
1210          end if;
1211 
1212          --
1213          -- Locate all of the percentage records for the current
1214          -- Jurisdiction.
1215          --
1216          l_inc := 0;
1217          l_io := FALSE;
1218          --
1219          hr_utility.set_location(l_proc, 65);
1220          --
1221          for l_insert_old_recs in csr_vertex_in_jurisdiction
1222                                     (
1223                                      l_element_link_id,
1224                                      l_input_value_id_tbl(2)
1225                                     ) loop
1226             l_inc := l_inc + 1;
1227             l_element_rec_tbl(l_inc).element_entry_id
1228                := l_insert_old_recs.element_entry_id;
1229             l_element_rec_tbl(l_inc).effective_start_date
1230                := l_insert_old_recs.effective_start_date;
1231             l_element_rec_tbl(l_inc).effective_end_date
1232                := l_insert_old_recs.effective_end_date;
1233             if l_insert_old_recs.effective_start_date < p_effective_date then
1234                l_io := TRUE;
1235                if p_effective_date >= l_insert_old_recs.effective_start_date
1236                   and p_effective_date <= l_insert_old_recs.effective_end_date then
1237                   l_pct_inc := l_inc;
1238                end if;
1239             end if;
1240          end loop;
1241       -- end if; -- if l_payroll_installed
1242       --
1243       -- Select the corresponding datetrack mode
1244       --
1245       -- a. call hr_entry_api.update_element_entry with a datetrack_mode
1246       --    of 'UPDATE' if the effective end date of the current record
1247       --    is the end of time.
1248       -- b. if the effective end date of the current record is not the
1249       --    end of time then call hr_entry_api.update_element_entry with
1250       --    a mode of 'UPDATE_INSERT'.
1251       --
1252       If p_datetrack_mode = 'INSERT_OLD' then
1253          --
1254          hr_utility.set_location(l_proc, 70);
1255          --
1256          l_pct_inc := 0;
1257          l_inc := 0;
1258          --
1259          -- Scan the percentage records for the current record.
1260          --
1261          for l_insert_old_recs in csr_vertex_in_jurisdiction
1262                                      (
1263                                       l_element_link_id,
1264                                       l_input_value_id_tbl(2)
1265                                      ) loop
1266             l_inc := l_inc + 1;
1267             l_element_rec_tbl(l_inc).element_entry_id
1268                := l_insert_old_recs.element_entry_id;
1269             l_element_rec_tbl(l_inc).effective_start_date
1270                := l_insert_old_recs.effective_start_date;
1271             l_element_rec_tbl(l_inc).effective_end_date
1272                := l_insert_old_recs.effective_end_date;
1273             If p_effective_date >=
1274                l_element_rec_tbl(l_inc).effective_start_date and
1275                p_effective_date <=
1276                l_element_rec_tbl(l_inc).effective_end_date then
1277                l_pct_inc := l_inc;
1278             End if;
1279          end loop;
1280          --
1281          -- Make sure that the start and end dates match the 'VERTEX'
1282          -- Element Entry row(s).
1283          --
1284          If l_element_rec_tbl(l_pct_inc).effective_end_date = hr_api.g_eot
1285             or not l_element_rec_tbl.exists(l_pct_inc + 1) then
1286             --
1287             hr_utility.set_location(l_proc, 75);
1288             --
1289             hr_entry_api.update_element_entry
1290                (
1291                 p_dt_update_mode           => 'UPDATE',
1292                 p_session_date             => p_effective_date,
1293                 p_element_entry_id         => l_element_entry_id,
1294                 p_num_entry_values         => 3,
1295                 p_input_value_id_tbl       => l_input_value_id_tbl,
1296                 p_entry_value_tbl          => l_new_vertex_value_tbl
1297                );
1298          else
1299             --
1300             hr_utility.set_location(l_proc, 80);
1301             --
1302             hr_entry_api.update_element_entry
1303                (
1304                 p_dt_update_mode           => 'UPDATE_CHANGE_INSERT',
1305                 p_session_date             => p_effective_date,
1306                 p_element_entry_id         => l_element_entry_id,
1307                 p_num_entry_values         => 3,
1308                 p_input_value_id_tbl       => l_input_value_id_tbl,
1309                 p_entry_value_tbl          => l_new_vertex_value_tbl
1310                );
1311          end if;
1312          --
1313          -- a. get the current jurisdiction's percentage record.
1314          -- b. if the current percentage record is the last record with an
1315          --    effective end date of the end of time then call
1316          --    hr_entry_api.update_element_entry with a mode of 'UPDATE'.
1317          -- c. else if call hr_entry_api.update_element_entry with a mode
1318          --    of 'UPDATE_INSERT'.
1319          -- d. remove any percentage records which are before the new effective
1320          --    date from pay_element_entry_values_f and pay_element_entries_f.
1321          -- e. if the new effective date is before the old defaulting date then
1322          --    update the effective start date of the first record in
1323          --    pay_element_entries_f and pay_element_entry_values_f.
1324       elsif p_datetrack_mode = 'INSERT_OVERRIDE' then
1325          --
1326          hr_utility.set_location(l_proc, 85);
1327          --
1328          if l_io = TRUE then
1329             l_new_vertex_value_tbl(3) := get_curr_jurisdiction_db_value
1330                                             (
1331                                              p_assignment_id,
1332                                              l_jurisdiction,
1333                                              p_effective_date,
1334                                              l_element_link_id,
1335                                              l_input_value_id_tbl
1336                                             );
1337             if l_element_rec_tbl(l_pct_inc).effective_start_date <= p_effective_date and
1338                l_element_rec_tbl(l_pct_inc).effective_end_date >= p_effective_date and
1339                (l_element_rec_tbl(l_pct_inc).effective_end_date = hr_api.g_eot
1340                 or not l_element_rec_tbl.exists(l_pct_inc + 1)) then
1341                --
1342                hr_utility.set_location(l_proc, 90);
1343                --
1344                hr_entry_api.update_element_entry
1345                   (
1346                    p_dt_update_mode           => 'UPDATE',
1347                    p_session_date             => p_effective_date,
1348                    p_element_entry_id         => l_element_entry_id,
1349                    p_num_entry_values         => 3,
1350                    p_input_value_id_tbl       => l_input_value_id_tbl,
1351                    p_entry_value_tbl          => l_new_vertex_value_tbl);
1352             else
1353                --
1354                hr_utility.set_location(l_proc, 95);
1355                --
1356                hr_entry_api.update_element_entry
1357                   (
1358                    p_dt_update_mode           => 'UPDATE_CHANGE_INSERT',
1359                    p_session_date             => p_effective_date,
1360                    p_element_entry_id         => l_element_entry_id,
1361                    p_num_entry_values         => 3,
1362                    p_input_value_id_tbl       => l_input_value_id_tbl,
1363                    p_entry_value_tbl          => l_new_vertex_value_tbl);
1364             end if;
1365             --
1366             -- Remove trailing records
1367             --
1368             Begin
1369                --
1370                hr_utility.set_location(l_proc, 100);
1371                --
1372                --
1373                -- Remove element entry values first
1374                --
1375                Delete from pay_element_entry_values_f
1376                Where element_entry_id = l_element_entry_id
1377                  and effective_start_date < p_effective_date;
1378                --
1379                -- Next, remove the parent element entry records.
1380                --
1381                Delete from pay_element_entries_f
1382                Where element_entry_id = l_element_entry_id
1383                  and effective_start_date < p_effective_date;
1384             Exception
1385                when others then
1386                   hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1387                   hr_utility.set_message_token('PROCEDURE', l_proc ||
1388                             '- SQLCODE:'|| to_char(sqlcode));
1389                   hr_utility.set_message_token('STEP','102');
1390                   hr_utility.raise_error;
1391             End;
1392          else
1393             --
1394             hr_utility.set_location(l_proc, 105);
1395             --
1396             Begin
1397                Update pay_element_entry_values_f
1398                Set effective_start_date = p_effective_date
1399                Where element_entry_id = l_element_entry_id
1400                  and effective_start_date = t_effective_start_date;
1401                --
1402                Update pay_element_entries_f
1403                Set effective_start_date = p_effective_date
1404                Where element_entry_id = l_element_entry_id
1405                  and effective_start_date = t_effective_start_date;
1406                --
1407             Exception
1408                when others then
1409                   hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1410                   hr_utility.set_message_token('PROCEDURE', l_proc ||
1411                      '- SQLCODE:'|| to_char(sqlcode));
1412                   hr_utility.set_message_token('STEP','109');
1413                   hr_utility.raise_error;
1414             End;
1415          End if;
1416          /*
1417             a. create a percentage record for the new jurisdiction at
1418                the defaulting date.
1419             b. apply all location changes to the new percentage record, by
1420                calling hr_entry_element.update_element_entry with MODE
1421                 = 'UPDATE' at the start date for each location change.
1422             c. correct the percentage for the current jurisdiction record to
1423                0% for assignment jurisdiction not equal to the current
1424                jurisdiction and 100% where the assignment jurisdiction and
1425                current jurisdiction are equal and the current jurisdiction
1426                is a city.
1427          */
1428       elsif p_datetrack_mode = 'INSERT' then
1429          --
1430          hr_utility.set_location(l_proc ,110);
1431 
1432          If l_defaulting_date is not null then
1433             --
1434             -- Create a percentage record for the new jurisdiction at
1435             --    the defaulting date.
1436             --
1437             l_new_vertex_value_tbl(3) := '0';
1438             --
1439             hr_utility.set_location(l_proc ,115);
1440             --
1441             hr_entry_api.insert_element_entry
1442                (
1443                 p_effective_start_date => l_defaulting_date,
1444                 p_effective_end_date   => l_effective_end_date,
1445                 p_element_entry_id     => l_element_entry_id,
1446                 p_assignment_id        => p_assignment_id,
1447                 p_element_link_id      => l_element_link_id,
1448                 p_creator_type         => 'UT',
1449                 p_entry_type           => 'E',
1450                 p_num_entry_values     => 3,
1451                 p_input_value_id_tbl   => l_input_value_id_tbl,
1452                 p_entry_value_tbl      => l_new_vertex_value_tbl
1453                );
1454             --
1455             hr_utility.set_location(l_proc ,120);
1456             --
1457             --  Find all location changes in the assignment record.
1458             --  Apply all location changes to the new percentage record, by
1459             --  calling hr_entry_element.update_element_entry with MODE = 'UPDATE'.
1460             --
1461             if l_location_chg_tbl.first is not null then
1462                --
1463                hr_utility.set_location(l_proc ,125);
1464                --
1465                l_inc := l_location_chg_tbl.next(l_location_chg_tbl.first);
1466                While l_location_chg_tbl.exists(l_inc) loop
1467                   --
1468                   -- Get location percentage;
1469                   -- The percentage is assigned 0% for location not equal to
1470                   -- current jurisdiction and 100% where the jurisdiction and location
1471                   -- are equal.
1472                   --
1473                   hr_entry_api.update_element_entry
1474                      (
1475                       p_dt_update_mode           => 'UPDATE',
1476                       p_session_date             => l_location_chg_tbl(l_inc).start_date,
1477                       p_element_entry_id         => l_element_entry_id,
1478                       p_num_entry_values         => 3,
1479                       p_input_value_id_tbl       => l_input_value_id_tbl,
1480                       p_entry_value_tbl          => l_new_vertex_value_tbl);
1481                   l_inc := l_location_chg_tbl.next(l_inc);
1482                End loop;
1483                --
1484                -- Set the proper percentage.  If current jurisdiction is a CITY,
1485                -- and the assignment jurisdiction is the same, then the percentage
1486                -- = '100' else percentage = '0'.
1487                --
1488                If p_city_code <> '0000' and
1489                   chk_work_location(
1490                                     p_assignment_id,
1491                                     p_effective_date,
1492                                     p_state_code||'-'||
1493                                     p_county_code||'-'||
1494                                     p_city_code
1495                                    ) then
1496                   --
1497                   hr_utility.set_location(l_proc ,125);
1498                   --
1499                   l_new_vertex_value_tbl(3) := '100';
1500                else
1501                   l_new_vertex_value_tbl(3) := '0';
1502                end if;               --
1503                --
1504                hr_utility.set_location(l_proc ,130);
1505                --
1506                hr_entry_api.update_element_entry
1507                   (
1508                    p_dt_update_mode           => 'CORRECTION',
1509                    p_session_date             => p_effective_date,
1510                    p_element_entry_id         => l_element_entry_id,
1511                    p_num_entry_values         => 3,
1512                    p_input_value_id_tbl       => l_input_value_id_tbl,
1513                    p_entry_value_tbl          => l_new_vertex_value_tbl
1514                   );
1515             else
1516                hr_utility.set_message(801, 'HR_51746_ASG_INV_ASG_ID');
1517                hr_utility.set_message_token('PROCEDURE', l_proc);
1518                hr_utility.raise_error;
1519             end if;
1520          end if;
1521          --
1522       /*
1523          a. find the current assignment location record.
1524          b. find the current element_entry (percentage) record for the current
1525             jurisdiction and effective date.
1526          c. if the end date of the current assignment location record is less
1527             than the effective end date for the current percentage record and
1528             the percentage record's effective end date = the end of time or the
1529             current percentage record is the last record, then call
1530             hr_entry_api.update_element_entry with a mode of 'UPDATE' and
1531             a session date = the curr ent assignments effective end date + 1.
1532          d. else if the current assignment location record's effective end
1533             date < the currect assignments' element entry record's effective end
1534             date, then call hr_entry_api.update_element_entry with a mode of
1535             'UPDATE_INSERT' and a session date = the current assignments
1536             effective end date + 1.
1537          e. set the percentage value to the new percentage.
1538          f. if the current percentage record's effective start date < the
1539             current assignment location record's effective start date then call
1540             hr_entry_api.update_element_entry with a mode of 'UPDATE_CHANGE_INSERT'
1541             and at the assignments effective start date + 1.
1542          g. else if not modified then find the current assignment's defaulting
1543             date.
1544          h. check to see if the value of the assignment's location for the next
1545             record. if it is the same as the current assignment record's
1546             location, then call hr_entry_api.delete_element_entry with a mode of
1547             'DELETE_NEXT_CHANGE' at the effective date.
1548          g. check the value of the location for the assignment's prior record, if
1549             it is the same as the location for the assignment's current record,
1550             call hr_entry_api.delete_element_entry with a mode of
1551             'DELETE_NEXT_CHANGE' at the effective end date of the assignment's
1552             next record.
1553          h. if this is a call from the public api correct percentage, calculate
1554             the jurisdiction's new element entry value.
1555          i. else call hr_entry_api.update_element_entry with a mode of 'CORRECTION'
1556             at the effective date.
1557       */
1558       elsif p_datetrack_mode = 'CORRECTION' then
1559          --
1560          hr_utility.set_location(l_proc ,140);
1561          --
1562          l_inc := 0;
1563          if l_location_chg_tbl.first is not null then
1564             l_inc := l_location_chg_tbl.first;
1565             While l_location_chg_tbl.exists(l_inc) loop
1566                If p_effective_date >= l_location_chg_tbl(l_inc).start_date and
1567                   p_effective_date <= l_location_chg_tbl(l_inc).end_date then
1568                   l_asg_inc := l_inc;
1569                end if;
1570                l_inc := l_location_chg_tbl.next(l_inc);
1571             End loop;
1572             l_inc := 0;
1573             for l_insert_old_recs in csr_vertex_in_jurisdiction
1574                   (l_element_link_id,
1575                    l_input_value_id_tbl(2)) loop
1576                l_inc := l_inc + 1;
1577                l_element_rec_tbl(l_inc).element_entry_id
1578                   := l_insert_old_recs.element_entry_id;
1579                l_element_rec_tbl(l_inc).effective_start_date
1580                   := l_insert_old_recs.effective_start_date;
1581                l_element_rec_tbl(l_inc).effective_end_date
1582                   := l_insert_old_recs.effective_end_date;
1583                if l_insert_old_recs.effective_end_date >= p_effective_date and
1584                   l_insert_old_recs.effective_start_date <= p_effective_date then
1585                   l_pct_inc := l_inc;
1586                end if;
1587             end loop;
1588          else
1589             hr_utility.set_message(801, 'HR_51746_ASG_INV_ASG_ID');
1590             hr_utility.set_message_token('PROCEDURE', l_proc);
1591             hr_utility.raise_error;
1592          end if;
1593          If l_location_chg_tbl(l_asg_inc).end_date <
1594             l_element_rec_tbl(l_pct_inc).effective_end_date
1595             and (l_element_rec_tbl(l_pct_inc).effective_end_date = hr_api.g_eot
1596                  or not l_element_rec_tbl.exists(l_pct_inc + 1)) then
1597             --
1598             hr_utility.set_location(l_proc ,145);
1599             --
1600             hr_entry_api.update_element_entry
1601                (
1602                 p_dt_update_mode           => 'UPDATE',
1603                 p_session_date             => l_location_chg_tbl(l_asg_inc).end_date + 1,
1604                 p_element_entry_id         => l_element_entry_id,
1605                 p_num_entry_values         => 3,
1606                 p_input_value_id_tbl       => l_input_value_id_tbl,
1607                 p_entry_value_tbl          => l_new_vertex_value_tbl
1608                );
1609          elsif l_location_chg_tbl(l_asg_inc).end_date <
1610             l_element_rec_tbl(l_pct_inc).effective_end_date then
1611             --
1612             hr_utility.set_location(l_proc ,150);
1613             --
1614             hr_entry_api.update_element_entry
1615                (
1616                 p_dt_update_mode           => 'UPDATE_CHANGE_INSERT',
1617                 p_session_date             => l_location_chg_tbl(l_asg_inc).end_date + 1,
1618                 p_element_entry_id         => l_element_entry_id,
1619                 p_num_entry_values         => 3,
1620                 p_input_value_id_tbl       => l_input_value_id_tbl,
1621                 p_entry_value_tbl          => l_new_vertex_value_tbl
1622                );
1623          end if;
1624          l_new_vertex_value_tbl(3) := fnd_number.canonical_to_number(p_percentage);
1625          if l_element_rec_tbl(l_pct_inc).effective_start_date <
1626             l_location_chg_tbl(l_asg_inc).start_date then
1627             l_modified_correction := TRUE;
1628             --
1629             -- With new pct values
1630             --
1631             --
1632             hr_utility.set_location(l_proc ,155);
1633             --
1634             hr_entry_api.update_element_entry
1635                (
1636                 p_dt_update_mode           => 'UPDATE_CHANGE_INSERT',
1637                 p_session_date             => l_location_chg_tbl(l_asg_inc).start_date,
1638                 p_element_entry_id         => l_element_entry_id,
1639                 p_num_entry_values         => 3,
1640                 p_input_value_id_tbl       => l_input_value_id_tbl,
1641                 p_entry_value_tbl          => l_new_vertex_value_tbl
1642                );
1643          else
1644             If l_modified_correction = FALSE then
1645                if l_defaulting_date is null then
1646                   hr_utility.set_message(801, 'HR_7182_DT_NO_MIN_MAX_ROWS');
1647                   hr_utility.set_message_token('PROCEDURE', l_proc);
1648                   hr_utility.raise_error;
1649                end if;
1650 
1651                if asg_loc_comp(
1652                                l_asg_tbl ,
1653                                NXT,
1654                                p_effective_date,
1655                                l_defaulting_date
1656                               ) = TRUE and p_calculate_pct = FALSE then
1657                   --
1658                   hr_utility.set_location(l_proc ,160);
1659                   --
1660                   hr_entry_api.delete_element_entry
1661                      (
1662                       p_dt_delete_mode   => 'DELETE_NEXT_CHANGE',
1663                       p_session_date     => p_effective_date,
1664                       p_element_entry_id => l_element_entry_id
1665                      );
1666                End if;
1667                if asg_loc_comp(
1668                                l_asg_tbl,
1669                                PRV,
1670                                p_effective_date,
1671                                l_defaulting_date
1672                               ) = TRUE and p_calculate_pct = FALSE then
1673                   --
1674                   hr_utility.set_location(l_proc ,165);
1675                   --
1676                   hr_entry_api.delete_element_entry
1677                      (
1678                       p_dt_delete_mode   => 'DELETE_NEXT_CHANGE',
1679                       p_session_date     => l_element_rec_tbl(l_pct_inc).effective_start_date - 1,
1680                       p_element_entry_id => l_element_entry_id
1681                      );
1682                   End if;
1683                --
1684                if p_calculate_pct then
1685                   --
1686                   hr_utility.set_location(l_proc ,170);
1687                   --
1688                   calculate_db_percentage
1689                      (
1690                       p_percentage,
1691                       p_state_code,
1692                       p_county_code,
1693                       p_city_code,
1694                       l_element_link_id,
1695                       l_input_value_id_tbl,
1696                       p_effective_date
1697                      );
1698                else
1699                   --
1700                   hr_utility.set_location(l_proc ,175);
1701                   --
1702                   hr_entry_api.update_element_entry
1703                      (
1704                       p_dt_update_mode     => 'CORRECTION',
1705                       p_session_date       => p_effective_date,
1706                       p_element_entry_id   => l_element_entry_id,
1707                       p_num_entry_values   => 3,
1708                       p_input_value_id_tbl => l_input_value_id_tbl,
1709                       p_entry_value_tbl    => l_new_vertex_value_tbl
1710                      );
1711                end if;
1712             end if;
1713          End if;
1714          --
1715       /*
1716          a. if the current assignment location record's effective end date <
1717             current percentage record's effective end date and current percentage
1718             record's effective end date = hr_api.g_eot or the next percentage
1719             record doesn't exist then call hr_entry_api.update_element_entry with
1720             a mode of 'UPDATE' at the the assignment record's effective end
1721             date + 1.
1722          b. else if the current assignment location record's effective end date
1723             < the current percentage record's effective end date then call
1724             hr_entry_api.update_element_entry with a mode of 'UPDATE_CHANGE_INSERT'
1725             at the next assignment record's effective end date.
1726          c. call hr_entry_api.update_element_entry with a mode of
1727             'UPDATE_CHANGE_INSERT' at the effective date and with the new percentage
1728             value.
1729          d. if the assignment's next record's location is the same as the current
1730             assignment record's location then call hr_entry_api.delete_element_entry
1731             with a mode of 'DELETE_NEXT_CHANGE' at the effective date.
1732       */
1733       elsif p_datetrack_mode = 'UPDATE_CHANGE_INSERT' then
1734          --
1735          hr_utility.set_location(l_proc ,180);
1736          --
1737          l_inc := 0;
1738          if l_location_chg_tbl.first is not null then
1739             l_inc := l_location_chg_tbl.first;
1740             While l_location_chg_tbl.exists(l_inc) loop
1741                If p_effective_date >= l_location_chg_tbl(l_inc).start_date and
1742                   p_effective_date <= l_location_chg_tbl(l_inc).end_date then
1743                   l_asg_inc := l_inc;
1744                end if;
1745                l_inc := l_location_chg_tbl.next(l_inc);
1746             End loop;
1747             l_inc := 0;
1748             for l_insert_old_recs in csr_vertex_in_jurisdiction
1749                   (l_element_link_id,
1750                    l_input_value_id_tbl(2)) loop
1751                l_inc := l_inc + 1;
1752                l_element_rec_tbl(l_inc).element_entry_id
1753                   := l_insert_old_recs.element_entry_id;
1754                l_element_rec_tbl(l_inc).effective_start_date
1755                   := l_insert_old_recs.effective_start_date;
1756                l_element_rec_tbl(l_inc).effective_end_date
1757                   := l_insert_old_recs.effective_end_date;
1758                if l_insert_old_recs.effective_end_date >= p_effective_date and
1759                   l_insert_old_recs.effective_start_date <= p_effective_date then
1760                   l_pct_inc := l_inc;
1761                end if;
1762             end loop;
1763          else
1764             hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1765             hr_utility.set_message_token('PROCEDURE', l_proc ||
1766                '- SQLCODE:'|| to_char(sqlcode));
1767             hr_utility.set_message_token('STEP','184');
1768             hr_utility.raise_error;
1769          end if;
1770          If l_location_chg_tbl(l_asg_inc).end_date <
1771             l_element_rec_tbl(l_pct_inc).effective_end_date
1772             and (l_element_rec_tbl(l_pct_inc).effective_end_date = hr_api.g_eot
1773                  or not l_element_rec_tbl.exists(l_pct_inc + 1)) then
1774             --
1775             hr_utility.set_location(l_proc ,185);
1776             --
1777             hr_entry_api.update_element_entry
1778                (
1779                 p_dt_update_mode           => 'UPDATE',
1780                 p_session_date             => l_location_chg_tbl(l_asg_inc).end_date + 1,
1781                 p_element_entry_id         => l_element_entry_id,
1782                 p_num_entry_values         => 3,
1783                 p_input_value_id_tbl       => l_input_value_id_tbl,
1784                 p_entry_value_tbl          => l_new_vertex_value_tbl
1785                );
1786          elsif l_location_chg_tbl(l_asg_inc).end_date <
1787             l_element_rec_tbl(l_pct_inc).effective_end_date then
1788             --
1789             hr_utility.set_location(l_proc ,190);
1790             --
1791             hr_entry_api.update_element_entry
1792                (
1793                 p_dt_update_mode           => 'UPDATE_CHANGE_INSERT',
1794                 p_session_date             => l_location_chg_tbl(l_asg_inc).end_date + 1,
1795                 p_element_entry_id         => l_element_entry_id,
1796                 p_num_entry_values         => 3,
1797                 p_input_value_id_tbl       => l_input_value_id_tbl,
1798                 p_entry_value_tbl          => l_new_vertex_value_tbl
1799                );
1800          end if;
1801          --
1802          -- Call hr_entry_api.update_element_entry with MODE =
1803          -- 'UPDATE_CHANGE_INSERT' as of the effective date.
1804          --
1805          l_new_vertex_value_tbl(3) := fnd_number.canonical_to_number(p_percentage);
1806          --
1807          hr_utility.set_location(l_proc ,195);
1808          --
1809          hr_entry_api.update_element_entry
1810             (
1811              p_dt_update_mode           => p_datetrack_mode,
1812              p_session_date             => p_effective_date,
1813              p_element_entry_id         => l_element_entry_id,
1814              p_num_entry_values         => 3,
1815              p_input_value_id_tbl       => l_input_value_id_tbl,
1816              p_entry_value_tbl          => l_new_vertex_value_tbl
1817             );
1818          if asg_loc_comp(
1819                          l_asg_tbl,
1820                          NXT,
1821                          p_effective_date,
1822                          p_effective_date
1823                         ) then
1824             --
1825             hr_utility.set_location(l_proc ,200);
1826             --
1827             hr_entry_api.delete_element_entry
1828                (
1829                 p_dt_delete_mode           => 'DELETE_NEXT_CHANGE',
1830                 p_session_date             => p_effective_date,
1831                 p_element_entry_id         => l_element_entry_id
1832                );
1833          end if;
1834       /*
1835          a. call hr_entry_api.update_element_entry with a mode of p_datetrack_mode
1836             at the effective date.
1837       */
1838       elsif p_datetrack_mode in ('UPDATE_OVERRIDE', 'UPDATE') then
1839          hr_utility.set_location(l_proc ,205);
1840          --
1841          hr_entry_api.update_element_entry
1842             (
1843              p_dt_update_mode           => p_datetrack_mode,
1844              p_session_date             => p_effective_date,
1845              p_element_entry_id         => l_element_entry_id,
1846              p_num_entry_values         => 3,
1847              p_input_value_id_tbl       => l_input_value_id_tbl,
1848              p_entry_value_tbl          => l_new_vertex_value_tbl
1849             );
1850 
1851       /*
1852          a. get the value of the old percentage record.
1853          b. check to see if the current assignment record's effective end date
1854             < next percentage record's
1855       */
1856       elsif p_datetrack_mode in ('ZAP', 'DELETE', 'FUTURE_CHANGE') then
1857          --
1858          hr_utility.set_location(l_proc ,210);
1859          --
1860          hr_entry_api.delete_element_entry
1861            (
1862             p_dt_delete_mode           => p_datetrack_mode,
1863             p_session_date             => p_effective_date,
1864             p_element_entry_id         => l_element_entry_id
1865            );
1866 
1867       elsif p_datetrack_mode = 'DELETE_NEXT_CHANGE' then
1868          --
1869          hr_utility.set_location(l_proc ,215);
1870          --
1871          l_asg_inc := 0;
1872          l_pct_inc := 0;
1873          l_inc := 0;
1874          --
1875          -- Look for assignment record breaks that need to be inserted.
1876          --
1877          if l_location_chg_tbl.first is not null then
1878             --
1879             -- Scan the percentage records for the next record after the current
1880             -- record.
1881             --
1882             for l_insert_old_recs in csr_vertex_in_jurisdiction
1883                                         (
1884                                          l_element_link_id,
1885                                          l_input_value_id_tbl(2)
1886                                         ) loop
1887                l_inc := l_inc + 1;
1888                l_element_rec_tbl(l_inc).element_entry_id
1889                   := l_insert_old_recs.element_entry_id;
1890                l_element_rec_tbl(l_inc).effective_start_date
1891                   := l_insert_old_recs.effective_start_date;
1892                l_element_rec_tbl(l_inc).effective_end_date
1893                   := l_insert_old_recs.effective_end_date;
1894                If p_effective_date >=
1895                   l_element_rec_tbl(l_inc).effective_start_date and
1896                   p_effective_date <=
1897                   l_element_rec_tbl(l_inc).effective_end_date then
1898                   l_pct_inc := l_inc + 1;
1899                End if;
1900             end loop;
1901             if l_element_rec_tbl.exists(l_pct_inc) then
1902                l_inc := l_location_chg_tbl.first;
1903                While l_location_chg_tbl.exists(l_inc) loop
1904                   If l_element_rec_tbl(l_pct_inc).effective_start_date >=
1905                      l_location_chg_tbl(l_inc).start_date and
1906                      l_element_rec_tbl(l_pct_inc).effective_start_date <
1907                      l_location_chg_tbl(l_inc).end_date+1 then
1908                      l_asg_inc := l_inc;
1909                   End if;
1910                   l_inc := l_location_chg_tbl.next(l_inc);
1911                End loop;
1912                --
1913                -- Make sure that the start and end dates match the 'VERTEX'
1914                -- Element Entry row(s).
1915                --
1916                hr_utility.set_location(l_proc ,220);
1917                --
1918                l_new_vertex_value_tbl(3) := get_curr_jurisdiction_db_value
1919                                                (
1920                                                 p_assignment_id,
1921                                                 l_jurisdiction,
1922                                                 l_element_rec_tbl(l_pct_inc).effective_start_date,
1923                                                 l_element_link_id,
1924                                                 l_input_value_id_tbl
1925                                                );
1926                If l_location_chg_tbl(l_asg_inc).end_date <
1927                   l_element_rec_tbl(l_pct_inc).effective_end_date
1928                   and (l_element_rec_tbl(l_pct_inc).effective_end_date = hr_api.g_eot
1929                        or not l_element_rec_tbl.exists(l_pct_inc + 1)) then
1930                   --
1931                   hr_utility.set_location(l_proc ,225);
1932                   --
1933                   hr_entry_api.update_element_entry
1934                      (
1935                       p_dt_update_mode           => 'UPDATE',
1936                       p_session_date             => l_location_chg_tbl(l_asg_inc).end_date + 1,
1937                       p_element_entry_id         => l_element_entry_id,
1938                       p_num_entry_values         => 3,
1939                       p_input_value_id_tbl       => l_input_value_id_tbl,
1940                       p_entry_value_tbl          => l_new_vertex_value_tbl
1941                      );
1942                elsif l_location_chg_tbl(l_asg_inc).end_date <
1943                   l_element_rec_tbl(l_pct_inc).effective_start_date then
1944                   --
1945                   hr_utility.set_location(l_proc ,230);
1946                   --
1947                   hr_entry_api.update_element_entry
1948                      (
1949                       p_dt_update_mode           => 'UPDATE_CHANGE_INSERT',
1950                       p_session_date             => l_location_chg_tbl(l_asg_inc).end_date + 1,
1951                       p_element_entry_id         => l_element_entry_id,
1952                       p_num_entry_values         => 3,
1953                       p_input_value_id_tbl       => l_input_value_id_tbl,
1954                       p_entry_value_tbl          => l_new_vertex_value_tbl
1955                      );
1956                end if;
1957             end if;
1958          end if;
1959          --
1960          -- Call hr_entry_api.delete_element_entry with MODE =
1961          -- 'DELETE_NEXT_CHANGE' for any rows found.
1962          --
1963          hr_utility.set_location(l_proc ,235);
1964          --
1965          hr_entry_api.delete_element_entry
1966             (
1967              p_dt_delete_mode           => p_datetrack_mode,
1968              p_session_date             => p_effective_date,
1969              p_element_entry_id         => l_element_entry_id
1970             );
1971 
1972       end if;
1973       --
1974       hr_utility.set_location(l_proc, 245);
1975       --
1976       -- Set all output arguments
1977       --
1978       p_effective_start_date := l_effective_start_date;
1979       p_effective_end_date := l_effective_end_date;
1980       --
1981       end if; -- if l_payroll_installed
1982       --
1983       hr_utility.set_location(' Leaving:'||l_proc, 250);
1984       --
1985       --
1986    end maintain_tax_percentage;
1987 
1988 -- ----------------------------------------------------------------------------
1989 -- |-----------------------------< maintain_wc >------------------------------|
1990 -- ----------------------------------------------------------------------------
1991 --
1992 
1993 procedure maintain_wc
1994   (p_emp_fed_tax_rule_id            in     number
1995   ,p_effective_start_date           in     date
1996   ,p_effective_end_date             in     date
1997   ,p_effective_date                 in     date
1998   ,p_datetrack_mode                 in     varchar2
1999   ) is
2000   --
2001   -- Declare cursors and local variables
2002   --
2003   l_proc varchar2(72) := g_package||'maintain_wc';
2004   l_assignment_id        pay_us_emp_fed_tax_rules_f.assignment_id%TYPE;
2005   l_jurisdiction_code    pay_us_emp_fed_tax_rules_f.sui_jurisdiction_code%TYPE;
2006   l_element_type_id      number       :=0;
2007   l_inp_name             varchar2(50) :=null;
2008   l_inp_val_id           number       :=0;
2009   l_element_link_id      number       :=0;
2010   l_element_entry_id     number       :=0;
2011   l_effective_start_date date         := null;
2012   l_effective_end_date   date         := null;
2013   l_effective_date       date;
2014   l_mode                 varchar2(30);
2015   l_delete_flag          varchar2(1);
2016   l_payroll_installed    boolean := FALSE;
2017   l_wc_min_start_date    pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
2018   l_defaulting_date      pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
2019   l_get_old_value_date   date;
2020   l_temp_char            varchar2(2);
2021   lc_workers_comp        varchar2(25) := 'Workers Compensation';
2022   l_tmp_date             date;
2023 
2024   l_inp_value_id_table   hr_entry.number_table;
2025   l_scr_value_table      hr_entry.varchar2_table;
2026 
2027   /* Cursor to get details about the federal tax rule */
2028 
2029   cursor csr_fed_detail is
2030     select fed.assignment_id,
2031            fed.sui_jurisdiction_code
2032     from   pay_us_emp_fed_tax_rules_f fed
2033     where  fed.emp_fed_tax_rule_id = p_emp_fed_tax_rule_id
2034     and    l_get_old_value_date between fed.effective_start_date
2035            and fed.effective_end_date;
2036 
2037   /* Cursor to check for existence of the federal tax rule */
2038 
2039   cursor csr_fed_rule_exists is
2040      select null
2041      from   pay_us_emp_fed_tax_rules_f fed
2042      where  fed.emp_fed_tax_rule_id = p_emp_fed_tax_rule_id
2043      and    fed.effective_start_date = l_effective_end_date + 1;
2044 
2045   /* Cursor to get the tax defaulting date */
2046 
2047   cursor csr_min_fed_tax_date is
2048      select min(effective_start_date)
2049      from pay_us_emp_fed_tax_rules_f
2050      where emp_fed_tax_rule_id = p_emp_fed_tax_rule_id;
2051 
2052   /* Cursor to get the worker's compensation element type */
2053 
2054   cursor csr_wc_tax_element is
2055     select pet.element_type_id,
2056            piv.input_value_id,
2057            piv.name
2058     from   PAY_ELEMENT_TYPES_F pet,
2059            PAY_INPUT_VALUES_F  piv
2060     where  pet.element_name   = lc_workers_comp
2061     and    l_get_old_value_date between pet.effective_start_date
2062            and pet.effective_end_date
2063     and    pet.element_type_id       = piv.element_type_id
2064     and    l_get_old_value_date between piv.effective_start_date
2065            and piv.effective_end_date;
2066 
2067   /* Cursor to get the worker's compensation element entry */
2068 
2069   cursor csr_wc_ele_entry (p_element_link number)is
2070     select pee.element_entry_id
2071     from   PAY_ELEMENT_ENTRIES_F pee
2072     where  pee.assignment_id         = l_assignment_id
2073     and    pee.element_link_id       = p_element_link
2074     and    rownum < 2;
2075 
2076   /* Cursor to get the worker's compensation earliest start date */
2077 
2078   cursor csr_wc_min_start is
2079     select min(pee.effective_start_date)
2080     from   PAY_ELEMENT_ENTRIES_F pee
2081     where  pee.element_entry_id      = l_element_entry_id;
2082 
2083   /* Cursor to get the current worker's compensation jurisdiction */
2084 
2085   cursor csr_get_curr_jurisd (p_csr_ele_entry_id number, p_csr_inp_val number) is
2086     select pev.screen_entry_value
2087     from   pay_element_entry_values_f pev
2088     where  pev.element_entry_id      = p_csr_ele_entry_id
2089     and    l_get_old_value_date between pev.effective_start_date
2090                             and pev.effective_end_date
2091     and    pev.input_value_id        = p_csr_inp_val
2092     and    pev.screen_entry_value is not null;
2093 
2094   /* Cursor to check for existing worker's comp entries to be purged or ended */
2095 
2096   cursor csr_get_ele_entry_id(l_csr_assignment_id  number
2097                              ,l_csr_effective_date date
2098                              ) is
2099     select peef.element_entry_id
2100     from   pay_element_entries_f peef
2101           ,pay_element_entry_values_f peevf
2102           ,pay_element_links_f pelf
2103           ,pay_element_types_f petf
2104     where  peef.assignment_id= l_csr_assignment_id
2105       and  petf.element_name = lc_workers_comp
2106       and  l_csr_effective_date < peef.effective_end_date
2107       and  peef.element_link_id = pelf.element_link_id
2108       and  pelf.element_type_id = petf.element_type_id
2109       and  peef.element_entry_id = peevf.element_entry_id
2110       and  l_csr_effective_date < peevf.effective_end_date;
2111   --
2112 begin
2113   --
2114   l_effective_date := trunc(p_effective_date);
2115   l_effective_start_date := trunc(p_effective_start_date);
2116   l_effective_end_date := trunc(p_effective_end_date);
2117   --
2118   -- Check that Oracle Payroll is installed
2119   --
2120   l_payroll_installed := hr_utility.chk_product_install(
2121                                               p_product =>'Oracle Payroll',
2122                                               p_legislation => 'US');
2123   if l_payroll_installed then
2124 
2125     hr_utility.set_location('Entering:'|| l_proc ,10);
2126     --
2127     if p_datetrack_mode = 'INSERT_OVERRIDE' then
2128       open csr_min_fed_tax_date;
2129       fetch csr_min_fed_tax_date into l_defaulting_date;
2130       if csr_min_fed_tax_date%notfound then
2131         close csr_min_fed_tax_date;
2132         hr_utility.set_message(801, 'HR_7182_DT_NO_MIN_MAX_ROWS');
2133         hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
2134         hr_utility.raise_error;
2135       end if;
2136       close csr_min_fed_tax_date;
2137       --
2138       -- Set l_get_old_value_date to the later of l_effective_date and
2139       -- l_defaulting_date. If l_effective_date is before l_defaulting_date,
2140       -- it will be unable to fetch existing wc element entry information,
2141       -- so we fetch that information as of the defaulting date,
2142       -- then pull back the workers comp entry, if necessary.
2143       --
2144       if l_effective_date < l_defaulting_date then
2145         l_get_old_value_date := l_defaulting_date;
2146       else
2147         l_get_old_value_date := l_effective_date;
2148       end if;
2149     else
2150       l_get_old_value_date := l_effective_date;
2151     end if;
2152     --
2153     -- Get assignment_id and jurisdiction code for p_emp_fed_tax_rule_id
2154     --
2155     open  csr_fed_detail;
2156     fetch csr_fed_detail into l_assignment_id, l_jurisdiction_code;
2157     if csr_fed_detail%NOTFOUND then
2158       close csr_fed_detail;
2159       --
2160       -- No Federal tax rule exists for this id
2161       --
2162       hr_utility.set_message(801, 'HR_7182_DT_NO_MIN_MAX_ROWS');
2163       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
2164       hr_utility.raise_error;
2165     end if;
2166     close csr_fed_detail;
2167     --
2168     -- Check for datetrack modes ZAP and DELETE.  These should only be processed
2169     -- when the assignment is terminated or purged.  In these cases, the assignment delete
2170     -- code might process the element entries, including the workers compensation entries.
2171     -- If the entries have already been purged or deleted, there is nothing to do here,
2172     -- otherwise, perform the delete.
2173     --
2174     if p_datetrack_mode in('ZAP','DELETE') then
2175        if p_datetrack_mode = hr_api.g_zap then
2176          l_tmp_date := hr_api.g_date;
2177        else
2178          l_tmp_date := l_effective_date;
2179        end if;
2180        open csr_get_ele_entry_id(l_assignment_id
2181                                 ,l_tmp_date);
2182        fetch csr_get_ele_entry_id into l_element_entry_id;
2183        if csr_get_ele_entry_id%found then
2184          hr_entry_api.delete_element_entry(
2185              p_dt_delete_mode           => p_datetrack_mode,
2186              p_session_date             => l_effective_date,
2187              p_element_entry_id         => l_element_entry_id);
2188        end if;
2189        --
2190     else        -- p_datetrack_mode not in ('ZAP','DELETE')
2191        --
2192        -- Get element_type_id and input values for the workers comp element.
2193        --
2194        open  csr_wc_tax_element;
2195        loop
2196          fetch csr_wc_tax_element into l_element_type_id,
2197                                        l_inp_val_id,
2198                                        l_inp_name;
2199          exit when csr_wc_tax_element%NOTFOUND;
2200 
2201          if upper(l_inp_name) = 'PAY VALUE' then
2202            l_inp_value_id_table(1) := l_inp_val_id;
2203          elsif upper(l_inp_name) = 'JURISDICTION' then
2204            l_inp_value_id_table(2) := l_inp_val_id;
2205          end if;
2206 
2207        end loop;
2208 
2209        close csr_wc_tax_element;
2210 
2211        hr_utility.set_location('Entering:'|| l_proc,20);
2212 
2213        /* Check that all of the input value id for vertex, exists */
2214 
2215        for i in 1..2 loop
2216           if l_inp_value_id_table(i) = null or
2217              l_inp_value_id_table(i) = 0 then
2218 
2219              fnd_message.set_name('PAY', 'HR_7713_TAX_ELEMENT_ERROR');
2220              fnd_message.raise_error;
2221           end if;
2222        end loop;
2223        hr_utility.set_location('Entering:'|| l_proc, 30);
2224 
2225        /* Get element link */
2226        l_element_link_id := hr_entry_api.get_link(
2227                               P_assignment_id   => l_assignment_id,
2228                               P_element_type_id => l_element_type_id,
2229                               P_session_date    => l_get_old_value_date);
2230 
2231        if l_element_link_id is null or l_element_link_id = 0 then
2232            fnd_message.set_name('PAY', 'HR_7713_TAX_ELEMENT_ERROR');
2233            fnd_message.raise_error;
2234        end if;
2235        hr_utility.set_location('Entering:'|| l_proc, 40);
2236 
2237        /* Store screen entry value in the table */
2238        l_scr_value_table(1)     := null;
2239        l_scr_value_table(2)     := l_jurisdiction_code;
2240 
2241        /* assign the parameters to local variables because the element entry
2242           procedures expect them to be in out parameters */
2243        l_effective_start_date   := trunc(p_effective_start_date);
2244        l_effective_end_date     := trunc(p_effective_end_date);
2245        l_mode                   := p_datetrack_mode;
2246 
2247        if p_datetrack_mode = 'INSERT' then
2248          /* Insert the worker's compensation element entry */
2249 
2250          hr_utility.set_location('Entering:'|| l_proc, 50);
2251          hr_entry_api.insert_element_entry(
2252               P_effective_start_date     => l_effective_start_date,
2253               P_effective_end_date       => l_effective_end_date,
2254               P_element_entry_id         => l_element_entry_id,
2255               P_assignment_id            => l_assignment_id,
2256               P_element_link_id          => l_element_link_id,
2257               P_creator_type             => 'UT',
2258               P_entry_type               => 'E',
2259               P_num_entry_values         => 2,
2260               P_input_value_id_tbl       => l_inp_value_id_table,
2261               P_entry_value_tbl          => l_scr_value_table);
2262          hr_utility.set_location('Entering:'|| l_proc, 80);
2263 
2264        elsif p_datetrack_mode in ('CORRECTION', 'UPDATE', 'UPDATE_CHANGE_INSERT',
2265                         'UPDATE_OVERRIDE', 'DELETE_NEXT_CHANGE',
2266                         'FUTURE_CHANGE', 'INSERT_OVERRIDE', 'INSERT_OLD') then
2267              /* Get the worker's compensation element entry id */
2268 
2269          open csr_wc_ele_entry(l_element_link_id);
2270          fetch csr_wc_ele_entry into l_element_entry_id;
2271          if csr_wc_ele_entry%NOTFOUND then
2272            if p_datetrack_mode in('DELETE_NEXT_CHANGE','FUTURE_CHANGE') then
2273               l_delete_flag := 'N';
2274            else
2275               close csr_wc_ele_entry;
2276               fnd_message.set_name(801, 'HR_6153_ALL_PROCEDURE_FAIL');
2277               fnd_message.set_token('PROCEDURE', l_proc);
2278               fnd_message.set_token('STEP','8');
2279               fnd_message.raise_error;
2280            end if;
2281          else /* found the wc element entry id */
2282            l_delete_flag := 'Y';
2283          end if;
2284 
2285          close csr_wc_ele_entry;
2286 
2287          if p_datetrack_mode in('DELETE_NEXT_CHANGE', 'FUTURE_CHANGE')
2288                    and l_delete_flag = 'Y' then
2289 
2290          /* All of the tax %age records will be created from the date on which the
2291             default tax rules criteria was met till the end of time. So, we should
2292             get records for the state, county and city for the same effective start
2293             date */
2294             hr_entry_api.delete_element_entry(
2295                 p_dt_delete_mode           => l_mode,
2296                 p_session_date             => l_effective_date,
2297                 p_element_entry_id         => l_element_entry_id);
2298 
2299 
2300          elsif p_datetrack_mode in ('CORRECTION','UPDATE', 'UPDATE_CHANGE_INSERT',
2301                           'UPDATE_OVERRIDE') then
2302 
2303             hr_entry_api.update_element_entry(
2304                p_dt_update_mode           => l_mode,
2305                p_session_date             => l_effective_date,
2306                p_element_entry_id         => l_element_entry_id,
2307                p_num_entry_values         => 2,
2308                p_input_value_id_tbl       => l_inp_value_id_table,
2309                p_entry_value_tbl          => l_scr_value_table);
2310 
2311          elsif p_datetrack_mode in ('INSERT_OVERRIDE') then
2312 
2313            open csr_wc_min_start;
2314            fetch csr_wc_min_start into l_wc_min_start_date;
2315            close csr_wc_min_start;
2316 
2317            if l_effective_date > l_wc_min_start_date then
2318              -- Perform an 'INSERT_OLD' at l_effective_date, then delete earlier entries.
2319 
2320              open csr_get_curr_jurisd(l_element_entry_id, l_inp_value_id_table(2));
2321              fetch csr_get_curr_jurisd into l_scr_value_table(2);
2322              if csr_get_curr_jurisd%notfound then
2323                close csr_get_curr_jurisd;
2324                hr_utility.set_message('801','HR_6153_ALL_PROCEDURE_FAIL');
2325                hr_utility.set_message_token('PROCEDURE', l_proc);
2326                hr_utility.set_message_token('STEP', '9');
2327                hr_utility.raise_error;
2328              end if;
2329              close csr_get_curr_jurisd;
2330 
2331              open csr_fed_rule_exists;
2332              fetch csr_fed_rule_exists into l_temp_char;
2333              if csr_fed_rule_exists%notfound then
2334                l_mode := 'UPDATE';
2335              else
2336                l_mode := 'UPDATE_CHANGE_INSERT';
2337              end if;
2338              close csr_fed_rule_exists;
2339 
2340              hr_entry_api.update_element_entry(
2341                 p_dt_update_mode           => l_mode,
2342                 p_session_date             => l_effective_date,
2343                 p_element_entry_id         => l_element_entry_id,
2344                 p_num_entry_values         => 2,
2345                 p_input_value_id_tbl       => l_inp_value_id_table,
2346                 p_entry_value_tbl          => l_scr_value_table);
2347 
2348              delete from pay_element_entry_values_f pev
2349              where  pev.element_entry_id     = l_element_entry_id
2350              and    pev.effective_start_date < l_effective_date;
2351 
2352              delete from pay_element_entries_f pee
2353              where  pee.element_entry_id     = l_element_entry_id
2354              and    pee.effective_start_date < l_effective_date;
2355 
2356            elsif l_effective_date < l_wc_min_start_date then
2357              -- Manually set effective start date of earliest record to l_effective_date
2358 
2359              update pay_element_entry_values_f pev
2360              set    pev.effective_start_date = l_effective_date
2361              where  pev.element_entry_id     = l_element_entry_id
2362              and    pev.effective_start_date = l_wc_min_start_date;
2363 
2364              update pay_element_entries_f pee
2365              set    pee.effective_start_date = l_effective_date
2366              where  pee.element_entry_id     = l_element_entry_id
2367              and    pee.effective_start_date = l_wc_min_start_date;
2368            end if;
2369 
2370          elsif p_datetrack_mode in ('INSERT_OLD') then
2371            open csr_get_curr_jurisd(l_element_entry_id, l_inp_value_id_table(2));
2372            fetch csr_get_curr_jurisd into l_scr_value_table(2);
2373            if csr_get_curr_jurisd%notfound then
2374              close csr_get_curr_jurisd;
2375              hr_utility.set_message('801','HR_6153_ALL_PROCEDURE_FAIL');
2376              hr_utility.set_message_token('PROCEDURE', l_proc);
2377              hr_utility.set_message_token('STEP', '9');
2378              hr_utility.raise_error;
2379            end if;
2380            close csr_get_curr_jurisd;
2381 
2382            open csr_fed_rule_exists;
2383            fetch csr_fed_rule_exists into l_temp_char;
2384            if csr_fed_rule_exists%notfound then
2385              l_mode := 'UPDATE';
2386            else
2387              l_mode := 'UPDATE_CHANGE_INSERT';
2388            end if;
2389            close csr_fed_rule_exists;
2390 
2391            hr_entry_api.update_element_entry(
2392               p_dt_update_mode           => l_mode,
2393               p_session_date             => l_effective_date,
2394               p_element_entry_id         => l_element_entry_id,
2395               p_num_entry_values         => 2,
2396               p_input_value_id_tbl       => l_inp_value_id_table,
2397               p_entry_value_tbl          => l_scr_value_table);
2398 
2399          end if;
2400 
2401        end if;
2402 
2403     end if;
2404 
2405   end if;
2406   --
2407   -- Set OUT parameter
2408   --
2409   --
2410 end maintain_wc;
2411 
2412 -- ----------------------------------------------------------------------------
2413 -- |------------------------< delete_fed_tax_rule >---------------------------|
2414 -- ----------------------------------------------------------------------------
2415 --
2416 procedure delete_fed_tax_rule
2417   (p_effective_date                 in     date
2418   ,p_datetrack_delete_mode          in     varchar2
2419   ,p_assignment_id                  in     number
2420   ,p_delete_routine                 in     varchar2
2421   ,p_effective_start_date              out nocopy date
2422   ,p_effective_end_date                out nocopy date
2423   ,p_object_version_number             out nocopy number
2424   ) is
2425   --
2426   -- Declare cursors and local variables
2427   --
2428   l_proc                       varchar2(72) := g_package||'delete_fed_tax_rule';
2429   l_effective_date             date;
2430   l_state_code                 pay_us_emp_state_tax_rules_f.state_code%TYPE;
2431   l_emp_fed_tax_rule_id        pay_us_emp_fed_tax_rules_f.emp_fed_tax_rule_id%TYPE;
2432   l_effective_start_date       pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
2433   l_effective_end_date         pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
2434   l_object_version_number      pay_us_emp_fed_tax_rules_f.object_version_number%TYPE;
2435   l_tmp_effective_start_date   pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
2436   l_tmp_effective_end_date     pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
2437   l_tmp_object_version_number  pay_us_emp_fed_tax_rules_f.object_version_number%TYPE;
2438   --
2439   l_exit_quietly          exception;
2440   --
2441   cursor csr_fed_rule is
2442     select fed.emp_fed_tax_rule_id, fed.object_version_number
2443     from   pay_us_emp_fed_tax_rules_f fed
2444     where  fed.assignment_id = p_assignment_id
2445     and    l_effective_date between fed.effective_start_date
2446                                 and fed.effective_end_date;
2447   --
2448   cursor csr_state_rules is
2449     select sta.state_code, sta.object_version_number
2450     from   pay_us_emp_state_tax_rules_f sta
2451     where  sta.assignment_id = p_assignment_id
2452     and    l_effective_date between sta.effective_start_date
2453                                 and sta.effective_end_date;
2454   --
2455   --
2456 begin
2457   --
2458   --
2459   l_effective_date := trunc(p_effective_date);
2460   --
2461   -- Validate that a federal tax rule exists for this assignment
2462   --
2463   open csr_fed_rule;
2464   fetch csr_fed_rule into l_emp_fed_tax_rule_id, l_object_version_number;
2465   if csr_fed_rule%notfound then
2466     close csr_fed_rule;
2467     raise l_exit_quietly;
2468   end if;
2469   close csr_fed_rule;
2470   --
2471   if p_datetrack_delete_mode NOT IN ('ZAP', 'DELETE') then
2472     hr_utility.set_message(801, 'HR_7204_DT_DEL_MODE_INVALID');
2473     hr_utility.raise_error;
2474   end if;
2475   --
2476   -- Validate that this routine is called from Assignment code
2477   --
2478   if nvl(p_delete_routine,'X') <> 'ASSIGNMENT' then
2479     hr_utility.set_message(801, 'HR_6674_PAY_ASSIGN');
2480     hr_utility.raise_error;
2481   end if;
2482   --
2483   open csr_state_rules;
2484   loop
2485     fetch csr_state_rules into l_state_code, l_tmp_object_version_number;
2486     exit when csr_state_rules%notfound;
2487     --
2488     --  Call delete_tax_rules API here passing in l_assignment_id, l_state_code
2489     pay_us_tax_api.delete_tax_rule(
2490                     p_validate              => NULL
2491                    ,p_effective_date        => l_effective_date
2492                    ,p_assignment_id         => p_assignment_id
2493                    ,p_state_code            => l_state_code
2494                    ,p_county_code           => '000'
2495                    ,p_city_code             => '0000'
2496                    ,p_datetrack_mode        => p_datetrack_delete_mode
2497                    ,p_effective_start_date  => l_tmp_effective_start_date
2498                    ,p_effective_end_date    => l_tmp_effective_end_date
2499                    ,p_object_version_number => l_tmp_object_version_number
2500                    ,p_delete_routine        => p_delete_routine
2501                    );
2502     --
2503   end loop;
2504   close csr_state_rules;
2505   --
2506   maintain_wc(
2507                    p_emp_fed_tax_rule_id    => l_emp_fed_tax_rule_id
2508                   ,p_effective_start_date   => l_effective_start_date
2509                   ,p_effective_end_date     => l_effective_end_date
2510                   ,p_effective_date         => l_effective_date
2511                   ,p_datetrack_mode         => p_datetrack_delete_mode
2512                   );
2513   --
2514   pay_fed_del.del(p_emp_fed_tax_rule_id     => l_emp_fed_tax_rule_id
2515                  ,p_effective_start_date    => l_effective_start_date
2516                  ,p_effective_end_date      => l_effective_end_date
2517                  ,p_object_version_number   => l_object_version_number
2518                  ,p_effective_date          => l_effective_date
2519                  ,p_datetrack_mode          => p_datetrack_delete_mode
2520                  ,p_delete_routine          => p_delete_routine
2521                  );
2522   --
2523   --
2524   hr_utility.set_location(l_proc, 60);
2525   --
2526   -- Set all output arguments
2527   --
2528   p_effective_start_date := l_effective_start_date;
2529   p_effective_end_date := l_effective_end_date;
2530   p_object_version_number := l_object_version_number;
2531   --
2532   hr_utility.set_location(' Leaving:'||l_proc, 70);
2533   --
2534 exception
2535   --
2536   when l_exit_quietly then
2537     --
2538     p_effective_start_date := null;
2539     p_effective_end_date := null;
2540     p_object_version_number := null;
2541     --
2542     hr_utility.set_location(' Leaving:'||l_proc, 75);
2543     --
2544     --
2545 end delete_fed_tax_rule;
2546 -- ----------------------------------------------------------------------------
2547 -- |---------------------------< address_change >-------------------------|
2548 -- ----------------------------------------------------------------------------
2549 --
2550 procedure address_change
2551     (p_effective_date               In      date
2552     ,p_person_id                    In      number     default null
2553     ,p_assignment_id                In      number     default null
2554     ) is
2555   --
2556   -- Declare cursors and local variables
2557   --
2558   l_proc                        varchar2(72) := g_package||'address_change';
2559   l_effective_date              date;
2560   l_defaulting_date		date;
2561   l_temp_char                   varchar2(10);
2562   l_assignment_id               per_assignments_f.assignment_id%TYPE;
2563   l_person_id                   per_assignments_f.person_id%TYPE;
2564   l_res_state_code              pay_us_states.state_code%TYPE;
2565   l_res_county_code             pay_us_counties.county_code%TYPE;
2566   l_res_city_code               pay_us_city_names.city_code%TYPE;
2567   l_res_ovrd_state_code         pay_us_states.state_code%TYPE;
2568   l_res_ovrd_county_code        pay_us_counties.county_code%TYPE;
2569   l_res_ovrd_city_code          pay_us_city_names.city_code%TYPE;
2570 
2571   --
2572   cursor csr_per_id is
2573     select null
2574     from   per_people_f peo
2575     where  peo.person_id = p_person_id;
2576   --
2577   cursor csr_asg_id is
2578     select asg.person_id
2579     from   per_assignments_f asg
2580     where  asg.assignment_id = p_assignment_id;
2581   --
2582   cursor csr_per_asg_id is
2583     select asg.assignment_id
2584     from   per_assignments_f asg
2585     where  asg.person_id = p_person_id
2586     and    l_effective_date between asg.effective_start_date
2587            and asg.effective_end_date;
2588   --
2589   --
2590 
2591 begin
2592   --
2593   hr_utility.set_location('Entering:'|| l_proc, 10);
2594   --
2595   -- Ensure that all the mandatory arguments are not null
2596   --
2597   hr_api.mandatory_arg_error(p_api_name       => l_proc,
2598                              p_argument       => 'effective_date',
2599                              p_argument_value => p_effective_date);
2600   --
2601   l_effective_date := trunc(p_effective_date);
2602   --
2603   -- Validate p_person_id or p_assignment_id
2604   --
2605   if p_assignment_id is not null then
2606     open csr_asg_id;
2607     fetch csr_asg_id into l_person_id;
2608     if csr_asg_id%notfound then
2609       close csr_asg_id;
2610       hr_utility.set_message(801, 'HR_7702_PDT_VALUE_NOT_FOUND');
2611       hr_utility.raise_error;
2612     end if;
2613     close csr_asg_id;
2614   elsif p_person_id is not null then
2615     open  csr_per_id;
2616     fetch csr_per_id into l_temp_char;
2617     if csr_per_id%NOTFOUND then
2618       close csr_per_id;
2619       hr_utility.set_message(801, 'HR_51396_WEB_PERSON_NOT_FND');
2620       hr_utility.raise_error;
2621     end if;
2622     close csr_per_id;
2623     l_person_id := p_person_id;
2624   else
2625     hr_utility.set_message(801,'HR_6480_FF_DEF_RULE');
2626     hr_utility.set_message_token('ELEMENT_OR_INPUT',
2627                                  'Assignment_id or person_id');
2628     hr_utility.raise_error;
2629   end if;
2630   --
2631   -- Select the codes for the new primary residence state, county and city
2632   --
2633   open csr_res_addr(l_person_id,l_effective_date);
2634   fetch csr_res_addr into l_res_state_code, l_res_county_code, l_res_city_code,
2635 			  l_res_ovrd_state_code, l_res_ovrd_county_code,
2636 			  l_res_ovrd_city_code;
2637   if csr_res_addr%NOTFOUND then
2638     close csr_res_addr;
2639     -- it is being called by Person Address form So checks for date
2640     -- effectivity which is not required for person address form.
2641     -- Cursor csr_res_addr_no_eff_dt does not check for effective dates
2642     open csr_res_addr_no_eff_dt(l_person_id,l_effective_date);
2643     fetch csr_res_addr_no_eff_dt into l_res_state_code, l_res_county_code, l_res_city_code,
2644 			  l_res_ovrd_state_code, l_res_ovrd_county_code,
2645 			  l_res_ovrd_city_code;
2646     if csr_res_addr_no_eff_dt%NOTFOUND then
2647        close csr_res_addr_no_eff_dt;
2648        hr_utility.set_message(801, 'HR_7144_PER_NO_PRIM_ADD');
2649        hr_utility.raise_error;
2650     end if;
2651     close csr_res_addr_no_eff_dt;
2652   else
2653    close csr_res_addr;
2654   end if;
2655   --
2656   if p_assignment_id is null then
2657     --
2658     -- Cursor through the assignments for the given person_id
2659     --
2660     open  csr_per_asg_id;
2661     loop
2662       fetch csr_per_asg_id into l_assignment_id;
2663       exit when csr_per_asg_id%NOTFOUND;
2664       --
2665       open csr_defaulting_date(l_assignment_id);
2666       fetch csr_defaulting_date into l_defaulting_date;
2667       close csr_defaulting_date;
2668       if l_defaulting_date is not null then
2669         --
2670    	create_tax_rules_for_jd(p_state_code => l_res_state_code,
2671 				p_county_code => l_res_county_code,
2672 				p_city_code => l_res_city_code,
2673 				p_effective_date => l_defaulting_date,
2674 				p_assignment_id => l_assignment_id
2675 				);
2676 
2677    	create_tax_rules_for_jd(p_state_code => l_res_ovrd_state_code,
2678 				p_county_code => l_res_ovrd_county_code,
2679 				p_city_code => l_res_ovrd_city_code,
2680 				p_effective_date => l_defaulting_date,
2681 				p_assignment_id => l_assignment_id
2682 				);
2683 
2684       end if;
2685       --
2686     end loop;
2687     close csr_per_asg_id;
2688     --
2689   else
2690     --
2691       open csr_defaulting_date(p_assignment_id);
2692       fetch csr_defaulting_date into l_defaulting_date;
2693       close csr_defaulting_date;
2694       if l_defaulting_date is not null then
2695         --
2696    	create_tax_rules_for_jd(p_state_code => l_res_state_code,
2697 				p_county_code => l_res_county_code,
2698 				p_city_code => l_res_city_code,
2699 				p_effective_date => l_defaulting_date,
2700 				p_assignment_id => p_assignment_id
2701 				);
2702 
2703    	create_tax_rules_for_jd(p_state_code => l_res_ovrd_state_code,
2704 				p_county_code => l_res_ovrd_county_code,
2705 				p_city_code => l_res_ovrd_city_code,
2706 				p_effective_date => l_defaulting_date,
2707 				p_assignment_id => p_assignment_id
2708 				);
2709 
2710        end if; -- defaulting date
2711     --
2712   end if; -- assignment id null
2713   --
2714   -- Set all output arguments
2715   --
2716   --
2717   hr_utility.set_location(' Leaving:'||l_proc, 40);
2718   --
2719 end address_change;
2720 -- ----------------------------------------------------------------------------
2721 -- |-----------------------< validate_us_address >-----------------------|
2722 -- ----------------------------------------------------------------------------
2723 --
2724 procedure validate_us_address(p_person_id      number
2725                             , p_effective_date date
2726                             , p_primary_flag   varchar2
2727                             , p_style          varchar2) IS
2728 
2729   --
2730   cursor csr_latest_pos is
2731      select final_process_date
2732        from per_periods_of_service pos
2733       where pos.person_id = p_person_id
2734         and pos.date_start =
2735              (select max(date_start)
2736                 from per_periods_of_service pos2
2737                where pos2.person_id = pos.person_id
2738                  and date_start <= p_effective_date);
2739    --
2740    l_proc          varchar2(100) := g_package||'validate_us_address';
2741    --
2742    l_final_date    date; -- final process date
2743 
2744 BEGIN
2745     hr_utility.set_location('Entering:'|| l_proc, 10);
2746     --
2747     if p_primary_flag = 'Y' then
2748        if p_style <> 'US' then
2749             hr_utility.set_location(l_proc, 15);
2750             if Hr_General2.is_person_type(p_person_id,'EX_EMP',p_effective_date) then
2751                --
2752                hr_utility.set_location(l_proc, 20);
2753                --
2754                open csr_latest_pos;
2755                fetch csr_latest_pos into l_final_date;
2756                if csr_latest_pos%FOUND then
2757                   if (l_final_date is null)
2758                     or (l_final_date is not null
2759                          and l_final_date >= p_effective_date)
2760                   then
2761                      close csr_latest_pos;
2762                      hr_utility.set_message(800, 'HR_51283_ADD_MUST_BE_US_STYLE');
2763                      hr_utility.raise_error;
2764 
2765                   end if;
2766                end if;
2767                close csr_latest_pos;
2768             elsif Hr_General2.is_person_type(p_person_id,'EMP',p_effective_date) then
2769                 hr_utility.set_location(l_proc, 30);
2770                 hr_utility.set_message(800, 'HR_51283_ADD_MUST_BE_US_STYLE');
2771                 hr_utility.raise_error;
2772             end if;
2773        end if; -- style
2774     end if; -- primary flag
2775           --
2776     hr_utility.set_location('Leaving:'|| l_proc, 50);
2777 
2778 END validate_us_address;
2779 -- ----------------------------------------------------------------------------
2780 -- |-----------------------< create_default_tax_rules >-----------------------|
2781 -- ----------------------------------------------------------------------------
2782 --
2783 procedure create_default_tax_rules
2784   (p_effective_date                 in      date
2785   ,p_assignment_id                  in      number
2786   ,p_emp_fed_tax_rule_id                out nocopy number
2787   ,p_fed_object_version_number          out nocopy number
2788   ,p_fed_effective_start_date           out nocopy date
2789   ,p_fed_effective_end_date             out nocopy date
2790   ) is
2791   --
2792   -- Declare cursors and local variables
2793   --
2794   l_proc                 varchar2(72) := g_package||'create_default_tax_rules';
2795   l_effective_date              date;
2796   l_emp_fed_tax_rule_id    pay_us_emp_fed_tax_rules_f.emp_fed_tax_rule_id%TYPE;
2797   l_fed_effective_start_date
2798                           pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
2799   l_fed_effective_end_date  pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
2800   l_fed_object_version_number
2801                          pay_us_emp_fed_tax_rules_f.object_version_number%TYPE;
2802   l_business_group_id       per_assignments_f.business_group_id%TYPE;
2803   l_additional_wa_amount
2804                      pay_us_emp_fed_tax_rules_f.additional_wa_amount%TYPE:='0';
2805   l_filing_status_code
2806                      pay_us_emp_fed_tax_rules_f.filing_status_code%TYPE:='01';
2807 /*
2808   l_eic_filing_status_code
2809        pay_us_emp_fed_tax_rules_f.eic_filing_status_code%TYPE:='3'; No EIC */
2810 
2811   l_eic_filing_status_code
2812        pay_us_emp_fed_tax_rules_f.eic_filing_status_code%TYPE; /* No EIC */
2813 
2814   l_fit_override_amount
2815                      pay_us_emp_fed_tax_rules_f.fit_override_amount%TYPE:='0';
2816   l_fit_override_rate
2817                      pay_us_emp_fed_tax_rules_f.fit_override_rate%TYPE:='0';
2818   l_withholding_allowances
2819                    pay_us_emp_fed_tax_rules_f.withholding_allowances%TYPE:='0';
2820   l_cumulative_taxation    pay_us_emp_fed_tax_rules_f.cumulative_taxation%TYPE;
2821   l_fit_additional_tax     pay_us_emp_fed_tax_rules_f.fit_additional_tax%TYPE;
2822   l_fit_exempt             pay_us_emp_fed_tax_rules_f.fit_exempt%TYPE;
2823   l_futa_tax_exempt        pay_us_emp_fed_tax_rules_f.futa_tax_exempt%TYPE;
2824   l_medicare_tax_exempt    pay_us_emp_fed_tax_rules_f.medicare_tax_exempt%TYPE;
2825   l_ss_tax_exempt          pay_us_emp_fed_tax_rules_f.ss_tax_exempt%TYPE;
2826   l_wage_exempt            pay_us_emp_fed_tax_rules_f.wage_exempt%TYPE;
2827   l_statutory_employee     pay_us_emp_fed_tax_rules_f.statutory_employee%TYPE;
2828   l_supp_tax_override_rate pay_us_emp_fed_tax_rules_f.supp_tax_override_rate%TYPE;
2829   --
2830   l_temp_tax_rule_id        pay_us_emp_fed_tax_rules_f.emp_fed_tax_rule_id%TYPE;
2831   l_temp_eff_start_date   pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
2832   l_temp_eff_end_date       pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
2833   l_temp_ovn             pay_us_emp_fed_tax_rules_f.object_version_number%TYPE;
2834   --
2835   l_default_flag            varchar2(1) := 'Y';
2836   l_asg_min_start_date      per_assignments_f.effective_start_date%TYPE;
2837   l_adr_min_start_date      per_addresses.date_from%TYPE;
2838   l_defaulting_date         per_assignments_f.effective_start_date%TYPE;
2839 
2840   l_loc_state_code          pay_us_states.state_code%TYPE;
2841   l_loc_ovrd_state_code     pay_us_states.state_code%TYPE;
2842   l_loc_county_code         pay_us_counties.county_code%TYPE;
2843   l_loc_ovrd_county_code    pay_us_counties.county_code%TYPE;
2844   l_loc_city_code           pay_us_city_names.city_code%TYPE;
2845   l_loc_ovrd_city_code      pay_us_city_names.city_code%TYPE;
2846 
2847   l_res_state_code          pay_us_states.state_code%TYPE;
2848   l_res_county_code         pay_us_counties.county_code%TYPE;
2849   l_res_city_code           pay_us_city_names.city_code%TYPE;
2850   l_res_ovrd_state_code     pay_us_states.state_code%TYPE;
2851   l_res_ovrd_county_code    pay_us_counties.county_code%TYPE;
2852   l_res_ovrd_city_code      pay_us_city_names.city_code%TYPE;
2853 
2854   l_tax_location_id		hr_locations.location_id%TYPE;
2855   l_tax_loc_state_code          pay_us_states.state_code%TYPE;
2856   l_tax_loc_ovrd_state_code     pay_us_states.state_code%TYPE;
2857   l_tax_loc_county_code         pay_us_counties.county_code%TYPE;
2858   l_tax_loc_ovrd_county_code    pay_us_counties.county_code%TYPE;
2859   l_tax_loc_city_code           pay_us_city_names.city_code%TYPE;
2860   l_tax_loc_ovrd_city_code      pay_us_city_names.city_code%TYPE;
2861 
2862   l_sui_state_code	    pay_us_states.state_code%TYPE;
2863   l_sui_state_jd_code       pay_state_rules.jurisdiction_code%TYPE;
2864 
2865   l_tmp_loc_id              number;
2866   l_hold_loc_id             number;
2867   l_person_id		    per_people_f.person_id%TYPE;
2868   --
2869   l_exit_quietly            exception;
2870   --
2871   cursor csr_asg_bg_id is
2872     select asg.business_group_id
2873     from   per_assignments_f asg
2874     where  asg.assignment_id = p_assignment_id
2875     and    l_effective_date between asg.effective_start_date
2876            and asg.effective_end_date;
2877   --
2878   cursor csr_asg_defaulting_date is
2879      select min(asg.effective_start_date)
2880      from   per_assignments_f asg
2881      where  asg.assignment_id = p_assignment_id
2882      and    asg.pay_basis_id is not null
2883      and    asg.payroll_id is not null
2884      and    asg.soft_coding_keyflex_id is not null
2885      and    asg.location_id is not null
2886      and    asg.assignment_type = 'E'
2887      and    exists (select null
2888                   from   hr_soft_coding_keyflex sck
2889                   where  sck.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
2890                   and    sck.segment1 is not null);
2891   --
2892   cursor csr_adr_defaulting_date is
2893      select min(adr.date_from)
2894      from   per_addresses adr
2895             ,per_assignments_f asg
2896      where  asg.assignment_id = p_assignment_id
2897      and    adr.person_id = asg.person_id
2898      and    adr.primary_flag = 'Y';
2899   --
2900   cursor csr_asg_loc_id is
2901     select location_id
2902     from   per_assignments_f
2903     where  assignment_id = p_assignment_id
2904     and    effective_end_date > l_effective_date
2905     order by effective_end_date;
2906 
2907   cursor csr_get_asg_details is
2908     select location_id,person_id
2909     from   per_assignments_f
2910     where  assignment_id = p_assignment_id
2911     and	   l_defaulting_date between effective_start_date and effective_end_date;
2912   --
2913   --
2914 begin
2915   --
2916   hr_utility.set_location('Entering:'|| l_proc, 10);
2917   --
2918   l_effective_date := trunc(p_effective_date);
2919   --
2920   hr_utility.set_location(l_proc, 20);
2921   --
2922   -- First check if geocode has been installed or not. If no geocodes
2923   -- installed then return because there is nothing to be done by this
2924   -- defaulting procedure
2925   if hr_general.chk_maintain_tax_records = 'N' then
2926      raise l_exit_quietly;
2927   end if;
2928   --
2929   -- Validate p_assignment_id and get its business_group_id
2930   --
2931   open  csr_asg_bg_id;
2932   fetch csr_asg_bg_id into l_business_group_id;
2933   if csr_asg_bg_id%NOTFOUND then
2934     close csr_asg_bg_id;
2935     hr_utility.set_message(801, 'HR_51253_PYP_ASS__NOT_VALID');
2936     hr_utility.raise_error;
2937   end if;
2938   close csr_asg_bg_id;
2939   --
2940   -- Check that no Federal rule already exists for this assignment
2941   --
2942   open csr_defaulting_date(p_assignment_id);
2943   fetch csr_defaulting_date into l_defaulting_date;
2944   close csr_defaulting_date;
2945   if l_defaulting_date is not null then
2946     raise l_exit_quietly;
2947   end if;
2948   --
2949   hr_utility.set_location(l_proc, 30);
2950 
2951   -- Select initial date that the tax defaulting criteria was met.
2952   -- Check when the assignment criteria was met, and when the primary
2953   -- address criteria was met.  The defaulting date will be the later
2954   -- of these two dates.
2955   --
2956   open csr_asg_defaulting_date;
2957   fetch csr_asg_defaulting_date into l_asg_min_start_date;
2958   close csr_asg_defaulting_date;
2959 
2960   if l_asg_min_start_date is null then
2961     raise l_exit_quietly;
2962   end if;
2963 
2964   open csr_asg_loc_id;
2965   fetch csr_asg_loc_id into l_hold_loc_id;
2966   loop
2967     exit when csr_asg_loc_id%notfound;
2968     fetch csr_asg_loc_id into l_tmp_loc_id;
2969     if l_tmp_loc_id <> l_hold_loc_id then
2970        close csr_asg_loc_id;
2971        hr_utility.set_message('801','PAY_52299_TAX_FUT_LOC');
2972        hr_utility.raise_error;
2973     end if;
2974   end loop;
2975   close csr_asg_loc_id;
2976   --
2977   -- Select initial date that the tax defaulting criteria was met.
2978   -- Check when the assignment criteria was met, and when the primary
2979   -- address criteria was met.  The defaulting date will be the later
2980   -- of these two dates.
2981   --
2982 -- rmonge
2983 --  open csr_asg_defaulting_date;
2984 --  fetch csr_asg_defaulting_date into l_asg_min_start_date;
2985 --  close csr_asg_defaulting_date;
2986 --  if l_asg_min_start_date is null then
2987 --    raise l_exit_quietly;
2988 --  end if;
2989   --
2990   hr_utility.set_location(l_proc, 40);
2991   open csr_adr_defaulting_date;
2992   fetch csr_adr_defaulting_date into l_adr_min_start_date;
2993   close csr_adr_defaulting_date;
2994   if l_adr_min_start_date is null then
2995     raise l_exit_quietly;
2996   end if;
2997   --
2998   if l_adr_min_start_date > l_asg_min_start_date then
2999     l_defaulting_date := l_adr_min_start_date;
3000   else
3001     l_defaulting_date := l_asg_min_start_date;
3002   end if;
3003   --
3004   -- Select state, county, city codes for the work location of the assignment.
3005   --
3006 
3007   open csr_get_asg_details;
3008   fetch csr_get_asg_details into l_tmp_loc_id, l_person_id;
3009   close csr_get_asg_details;
3010 
3011   open csr_loc_addr(l_tmp_loc_id);
3012   fetch csr_loc_addr into l_loc_state_code, l_loc_county_code, l_loc_city_code,
3013 			  l_loc_ovrd_state_code, l_loc_ovrd_county_code,
3014 			  l_loc_ovrd_city_code;
3015 
3016   if csr_loc_addr%NOTFOUND then
3017     close csr_loc_addr;
3018     hr_utility.set_message(801, 'HR_51138_TAX_NOT_COMP_LOC_COV');
3019     hr_utility.raise_error;
3020   end if;
3021   close csr_loc_addr;
3022   hr_utility.set_location(l_proc, 50);
3023   --
3024   -- Derive the jurisdiction codes for the assignment work location.
3025   if l_loc_ovrd_state_code is not null then
3026 	l_sui_state_code := l_loc_ovrd_state_code;
3027   else
3028 	l_sui_state_code := l_loc_state_code;
3029   end if;
3030 
3031 
3032   --
3033   -- Set default values
3034   --
3035   l_cumulative_taxation     := 'N';
3036   l_fit_additional_tax      := 0;
3037   l_fit_exempt              := 'N';
3038   l_futa_tax_exempt         := 'N';
3039   l_medicare_tax_exempt     := 'N';
3040   l_ss_tax_exempt           := 'N';
3041   l_wage_exempt             := 'N';
3042   l_statutory_employee      := 'N';
3043   l_supp_tax_override_rate  := 0;
3044   --
3045 
3046 -- Testing bug 2277932
3047 -- Eliminated the default value of '3' assigned to l_eic_filing_status_code
3048 -- Selecting the value from fnd_common_lookups
3049 
3050  begin
3051   select lookup_code
3052   into   l_eic_filing_status_code
3053   from  fnd_common_lookups
3054   where  lookup_type ='US_EIC_FILING_STATUS'
3055   and   Meaning='No EIC';
3056  exception
3057   when no_data_found then
3058       l_eic_filing_status_code := '0';
3059   end ;
3060 
3061   -- Insert a default federal tax rule
3062   --
3063   pay_fed_ins.ins (p_emp_fed_tax_rule_id          => l_emp_fed_tax_rule_id
3064                   ,p_effective_start_date         => l_fed_effective_start_date
3065                   ,p_effective_end_date           => l_fed_effective_end_date
3066                   ,p_assignment_id                => p_assignment_id
3067                   ,p_sui_state_code               => l_sui_state_code
3068                   ,p_sui_jurisdiction_code        => l_sui_state_code || '-000-0000'
3069                   ,p_business_group_id            => l_business_group_id
3070                   ,p_additional_wa_amount         => l_additional_wa_amount
3071                   ,p_filing_status_code           => l_filing_status_code
3072 		  ,p_eic_filing_status_code       => l_eic_filing_status_code
3073                   ,p_fit_override_amount          => l_fit_override_amount
3074                   ,p_fit_override_rate            => l_fit_override_rate
3075                   ,p_withholding_allowances       => l_withholding_allowances
3076                   ,p_cumulative_taxation          => l_cumulative_taxation
3077                   ,p_fit_additional_tax           => l_fit_additional_tax
3078                   ,p_fit_exempt                   => l_fit_exempt
3079                   ,p_futa_tax_exempt              => l_futa_tax_exempt
3080                   ,p_medicare_tax_exempt          => l_medicare_tax_exempt
3081                   ,p_ss_tax_exempt                => l_ss_tax_exempt
3082                   ,p_wage_exempt                  => l_wage_exempt
3083                   ,p_statutory_employee           => l_statutory_employee
3084                   ,p_supp_tax_override_rate       => l_supp_tax_override_rate
3085                   ,p_object_version_number        => l_fed_object_version_number
3086                   ,p_effective_date               => l_defaulting_date
3087                   ,p_attribute_category        => null
3088                   ,p_attribute1                => null
3089                   ,p_attribute2                => null
3090                   ,p_attribute3                => null
3091                   ,p_attribute4                => null
3092                   ,p_attribute5                => null
3093                   ,p_attribute6                => null
3094                   ,p_attribute7                => null
3095                   ,p_attribute8                => null
3096                   ,p_attribute9                => null
3097                   ,p_attribute10               => null
3098                   ,p_attribute11               => null
3099                   ,p_attribute12               => null
3100                   ,p_attribute13               => null
3101                   ,p_attribute14               => null
3102                   ,p_attribute15               => null
3103                   ,p_attribute16               => null
3104                   ,p_attribute17               => null
3105                   ,p_attribute18               => null
3106                   ,p_attribute19               => null
3107                   ,p_attribute20               => null
3108                   ,p_attribute21               => null
3109                   ,p_attribute22               => null
3110                   ,p_attribute23               => null
3111                   ,p_attribute24               => null
3112                   ,p_attribute25               => null
3113                   ,p_attribute26               => null
3114                   ,p_attribute27               => null
3115                   ,p_attribute28               => null
3116                   ,p_attribute29               => null
3117                   ,p_attribute30               => null
3118                   ,p_fed_information_category  => null
3119                   ,p_fed_information1          => null
3120                   ,p_fed_information2          => null
3121                   ,p_fed_information3          => null
3122                   ,p_fed_information4          => null
3123                   ,p_fed_information5          => null
3124                   ,p_fed_information6          => null
3125                   ,p_fed_information7          => null
3126                   ,p_fed_information8          => null
3127                   ,p_fed_information9          => null
3128                   ,p_fed_information10         => null
3129                   ,p_fed_information11         => null
3130                   ,p_fed_information12         => null
3131                   ,p_fed_information13         => null
3132                   ,p_fed_information14         => null
3133                   ,p_fed_information15         => null
3134                   ,p_fed_information16         => null
3135                   ,p_fed_information17         => null
3136                   ,p_fed_information18         => null
3137                   ,p_fed_information19         => null
3138                   ,p_fed_information20         => null
3139                   ,p_fed_information21         => null
3140                   ,p_fed_information22         => null
3141                   ,p_fed_information23         => null
3142                   ,p_fed_information24         => null
3143                   ,p_fed_information25         => null
3144                   ,p_fed_information26         => null
3145                   ,p_fed_information27         => null
3146                   ,p_fed_information28         => null
3147                   ,p_fed_information29         => null
3148                   ,p_fed_information30         => null                  );
3149   --
3150   -- Create a workers compensation element entry for this assignment.
3151   --
3152   maintain_wc(
3153                    p_emp_fed_tax_rule_id    => l_emp_fed_tax_rule_id
3154                   ,p_effective_start_date   => l_fed_effective_start_date
3155                   ,p_effective_end_date     => l_fed_effective_end_date
3156                   ,p_effective_date         => l_defaulting_date
3157                   ,p_datetrack_mode         => 'INSERT'
3158                   );
3159 
3160  --
3161   -- Create a default tax rules for the work location
3162   --
3163   create_tax_rules_for_jd(p_effective_date        => l_defaulting_date
3164                         ,p_assignment_id          => p_assignment_id
3165                         ,p_state_code             => l_loc_state_code
3166 			,p_county_code		  => l_loc_county_code
3167 			,p_city_code		  => l_loc_city_code
3168                         );
3169 
3170   --
3171   -- Create a default tax rules for the work location taxation address
3172   --
3173   create_tax_rules_for_jd(p_effective_date        => l_defaulting_date
3174                         ,p_assignment_id          => p_assignment_id
3175                         ,p_state_code             => l_loc_ovrd_state_code
3176 			,p_county_code		  => l_loc_ovrd_county_code
3177 			,p_city_code		  => l_loc_ovrd_city_code
3178                         );
3179 
3180   --
3181   -- create default tax rules for taxation location
3182   --
3183   open csr_get_tax_loc(p_assignment_id,l_defaulting_date);
3184   fetch csr_get_tax_loc into l_tax_location_id;
3185   if csr_get_tax_loc%FOUND then
3186 	open csr_loc_addr(l_tax_location_id);
3187 	fetch csr_loc_addr into l_tax_loc_state_code,l_tax_loc_county_code,
3188 				l_tax_loc_city_code,l_tax_loc_ovrd_state_code,
3189 				l_tax_loc_ovrd_county_code,l_tax_loc_ovrd_city_code;
3190 
3191   	if csr_loc_addr%NOTFOUND then
3192     		close csr_loc_addr;
3193 		close csr_get_tax_loc;
3194     		hr_utility.set_message(801, 'PY_51133_TXADJ_INVALID_CITY');
3195     		hr_utility.raise_error;
3196   	end if;
3197 
3198 	close csr_loc_addr;
3199 
3200    	create_tax_rules_for_jd(p_state_code => l_tax_loc_state_code,
3201 				p_county_code => l_tax_loc_county_code,
3202 				p_city_code => l_tax_loc_city_code,
3203 				p_effective_date => l_defaulting_date,
3204 				p_assignment_id => p_assignment_id
3205 				);
3206 
3207    	create_tax_rules_for_jd(p_state_code => l_tax_loc_ovrd_state_code,
3208 				p_county_code => l_tax_loc_ovrd_county_code,
3209 				p_city_code => l_tax_loc_ovrd_city_code,
3210 				p_effective_date => l_defaulting_date,
3211 				p_assignment_id => p_assignment_id
3212 				);
3213   end if; -- csr_get_tax_loc
3214 
3215   close csr_get_tax_loc;
3216 
3217   --
3218   -- Select state, county and city codes for the person's residence.
3219   --
3220   open csr_res_addr(l_person_id,l_defaulting_date);
3221   fetch csr_res_addr into l_res_state_code, l_res_county_code, l_res_city_code,
3222 			  l_res_ovrd_state_code, l_res_ovrd_county_code,
3223 			  l_res_ovrd_city_code;
3224   if csr_res_addr%NOTFOUND then
3225     close csr_res_addr;
3226     hr_utility.set_message(801, 'HR_7144_PER_NO_PRIM_ADD');
3227     hr_utility.raise_error;
3228   end if;
3229   close csr_res_addr;
3230   --
3231   -- Determine if other tax rules for the residence location should be created
3232   --
3233   if (l_res_state_code||l_res_county_code||l_res_city_code <>
3234 	l_loc_state_code||l_loc_county_code||l_loc_city_code) and
3235      (l_res_state_code||l_res_county_code||l_res_city_code <>
3236 	l_loc_ovrd_state_code||l_loc_ovrd_county_code||l_loc_ovrd_city_code) then
3237 
3238      -- Create Tax Rules for Residence Address
3239 
3240      create_tax_rules_for_jd(p_effective_date        => l_defaulting_date
3241                             ,p_assignment_id         => p_assignment_id
3242                             ,p_state_code            => l_res_state_code
3243 			    ,p_county_code	     => l_res_county_code
3244 			    ,p_city_code	     => l_res_city_code
3245                             );
3246   end if;
3247 
3248   if (l_res_ovrd_state_code||l_res_ovrd_county_code||l_res_ovrd_city_code <>
3249 	l_loc_state_code||l_loc_county_code||l_loc_city_code) and
3250      (l_res_ovrd_state_code||l_res_ovrd_county_code||l_res_city_code <>
3251 	l_loc_ovrd_state_code||l_loc_ovrd_county_code||l_loc_ovrd_city_code) then
3252 
3253      -- Create Tax Rules for Taxation Address
3254 
3255      create_tax_rules_for_jd(p_effective_date        => l_defaulting_date
3256                             ,p_assignment_id         => p_assignment_id
3257                             ,p_state_code            => l_res_ovrd_state_code
3258 			    ,p_county_code	     => l_res_ovrd_county_code
3259 			    ,p_city_code	     => l_res_ovrd_city_code
3260                             );
3261   end if;
3262   --
3263   hr_utility.set_location(l_proc, 60);
3264   --
3265   -- Set all output arguments
3266   --
3267   p_emp_fed_tax_rule_id := l_emp_fed_tax_rule_id;
3268   p_fed_effective_start_date := l_fed_effective_start_date;
3269   p_fed_effective_end_date := l_fed_effective_end_date;
3270   p_fed_object_version_number := l_fed_object_version_number;
3271   --
3272   hr_utility.set_location(' Leaving:'||l_proc, 70);
3273   --
3274 exception
3275   --
3276   when l_exit_quietly then
3277     --
3278     -- One of the following conditions has made it unnecessary to create tax
3279     -- rules:
3280     --  Geocodes are not installed, Federal tax rules already exist, the
3281     --  assignment or primary address does not meet tax rule defaulting
3282     --  criteria.  We return to the calling program without making any changes.
3283     --
3284     p_emp_fed_tax_rule_id := null;
3285     p_fed_effective_start_date := null;
3286     p_fed_effective_end_date := null;
3287     p_fed_object_version_number  := null;
3288     hr_utility.set_location(' Leaving:'||l_proc, 75);
3289   --
3290 end create_default_tax_rules;
3291 
3292 -- ----------------------------------------------------------------------------
3293 -- |----------------------< maintain_us_employee_taxes >----------------------|
3294 -- ----------------------------------------------------------------------------
3295 procedure maintain_us_employee_taxes
3296 (  p_effective_date                 in  date
3297   ,p_datetrack_mode                 in  varchar2  default null
3298   ,p_assignment_id                  in  number    default null
3299   ,p_location_id                    in  number    default null
3300   ,p_address_id                     in  number    default null
3301   ,p_delete_routine                 in  varchar2  default null
3302  ) is
3303   TYPE assign_tbl_type IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3304   --
3305   -- Declare cursors and local variables
3306   --
3307   l_proc               varchar2(72) := g_package||'maintain_us_employee_taxes';
3308   l_counter                    number := 0;
3309   l_effective_date             date;
3310   l_assignment_id              per_assignments_f.assignment_id%TYPE;
3311   l_location_id                per_assignments_f.location_id%TYPE;
3312   l_defaulting_date       pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
3313   l_fed_tax_rule_id       pay_us_emp_fed_tax_rules_f.emp_fed_tax_rule_id%TYPE;
3314   l_fed_object_version_number
3315                           pay_us_emp_fed_tax_rules_f.object_version_number%TYPE;
3316   l_fed_eff_start_date    pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
3317   l_fed_eff_end_date      pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
3318   l_tax_location_id	  hr_locations.location_id%TYPE;
3319   l_tax_loc_state_code	  pay_us_states.state_code%TYPE;
3320   l_tax_loc_county_code	  pay_us_counties.county_code%TYPE;
3321   l_tax_loc_city_code	  pay_us_city_names.city_code%TYPE;
3322   l_tax_loc_ovrd_state_code	  pay_us_states.state_code%TYPE;
3323   l_tax_loc_ovrd_county_code	  pay_us_counties.county_code%TYPE;
3324   l_tax_loc_ovrd_city_code	  pay_us_city_names.city_code%TYPE;
3325   l_temp_char             varchar2(1);
3326   l_temp_num              number;
3327   l_cnt                   number;
3328   l_assignment_tbl        assign_tbl_type;
3329   -- >> 2858888
3330   l_person_id             per_all_people_f.person_id%TYPE;
3331   l_adr_primary           per_addresses.primary_flag%TYPE;
3332   l_adr_style             per_addresses.style%TYPE;
3333   -- <<
3334   l_exit_quietly          exception;
3335   l_payroll_id            per_all_assignments_f.payroll_id%TYPE;
3336   l_effective_start_date  per_all_assignments_f.effective_start_date%TYPE;
3337   l_effective_end_date    per_all_assignments_f.effective_end_date%TYPE;
3338   --
3339 -- rmonge Bug fix 3599825.
3340 
3341   cursor csr_asg_id(p_csr_assignment_id number) is
3342     select null
3343     from per_assignments_f  asg,
3344         hr_organization_information bus
3345     where asg.assignment_id    = p_csr_assignment_id
3346     and bus.organization_id  = asg.business_group_id
3347     and bus.org_information9  = 'US'
3348     and bus.org_information_context = 'Business Group Information'
3349     and p_effective_date  between asg.effective_start_date
3350                               and asg.effective_end_date ;
3351 
3352 
3353   --
3354   cursor csr_adr_id(p_adr_id number) is
3355     select person_id, primary_flag, style  -- #2858888
3356     from   per_addresses adr
3357     where  adr.address_id = p_adr_id;
3358   --
3359   cursor csr_adr_asg_id(p_adr_id number) is
3360     select asg.assignment_id
3361     from   per_assignments_f asg,
3362            per_addresses     adr
3363     where  asg.person_id = adr.person_id
3364     and    p_effective_date between asg.effective_start_date
3365                                 and asg.effective_end_date
3366     and    adr.address_id = p_adr_id;
3367   --
3368 /*Bug8285850 Cursor to check if the current update or correction statement
3369 is removing payroll information from the assignment.This will
3370 return records only when we have Vertex or Workers compensation links setup
3371 as link to all payrolls and  trying to remove payroll after defaulting*/
3372 
3373   cursor csr_defaultpayrollremoved(p_assignment_id number,p_effective_date date) is
3374     select null
3375     from  per_all_assignments_f paa,
3376           pay_element_links_f pel,
3377           pay_element_types_f pet
3378     where paa.assignment_id=p_assignment_id
3379     and   paa.payroll_id is null
3380     and   p_effective_date between paa.effective_start_date
3381 	                       and paa.effective_end_date
3382     and   paa.business_group_id=pel.business_group_id
3383     and   pel.link_to_all_payrolls_flag = 'Y'
3384     and   p_effective_date between pel.effective_start_date
3385 	                       and pel.effective_end_date
3386     and   pel.element_type_id=pet.element_type_id
3387     and   p_effective_date between pet.effective_start_date
3388                                and pet.effective_end_date
3389     and   pet.element_name in ('VERTEX','Workers Compensation');
3390 
3391 /*Bug8285850 Cursor to get the details of the assignment that is being updated */
3392 
3393   cursor csr_asgmt_details(p_assignment_id number,p_effective_date date) is
3394     select payroll_id,
3395            effective_start_date,
3396 	   effective_end_date
3397     from  per_all_assignments_f
3398     where assignment_id=p_assignment_id
3399     and   p_effective_date between effective_start_date
3400                                and effective_end_date;
3401 
3402   --
3403 begin
3404   --
3405   hr_utility.set_location('Entering:'|| l_proc, 10);
3406   --
3407   l_effective_date := trunc(p_effective_date);
3408   --
3409   hr_utility.set_location(l_proc, 20);
3410   --
3411   -- First check if geocode has been installed or not. If no geocodes
3412   -- installed then return because there is nothing to be done by this
3413   -- procedure
3414   if hr_general.chk_maintain_tax_records = 'N' then
3415      raise l_exit_quietly;
3416   end if;
3417   --
3418   if p_assignment_id is null and p_address_id is null then
3419     hr_utility.set_message(801,'HR_6480_FF_DEF_RULE');
3420     hr_utility.set_message_token('ELEMENT_OR_INPUT',
3421                           'Assignment_id or address_id');
3422     hr_utility.raise_error;
3423   end if;
3424   --
3425   hr_utility.set_location(l_proc, 30);
3426   --
3427   --
3428   if p_datetrack_mode NOT IN ('ZAP',
3429                               'DELETE',
3430                               'UPDATE',
3431                               'CORRECTION',
3432                               'UPDATE_OVERRIDE',
3433                               'UPDATE_CHANGE_INSERT') then
3434     hr_utility.set_message(801, 'HR_7204_DT_DEL_MODE_INVALID');
3435     hr_utility.raise_error;
3436   elsif p_datetrack_mode in ('ZAP', 'DELETE') then
3437     hr_utility.set_location(l_proc, 40);
3438     --
3439     if p_assignment_id is not null then
3440       l_assignment_tbl(1) := p_assignment_id;
3441     else
3442       l_cnt := 0;
3443       for l_assgn_rec in csr_adr_asg_id(p_address_id) loop
3444         l_cnt := l_cnt + 1;
3445         l_assignment_tbl(l_cnt) := l_assgn_rec.assignment_id;
3446       end loop;
3447     end if;
3448     --
3449     for l_cnt in 1..l_assignment_tbl.last loop
3450       open csr_asg_id(l_assignment_tbl(l_cnt));
3451       fetch csr_asg_id into l_temp_num;
3452       if csr_asg_id%notfound then
3453         close csr_asg_id;
3454         hr_utility.set_message(801,'PAY_7702_PDT_VALUE_NOT_FOUND');
3455         hr_utility.raise_error;
3456       end if;
3457       close csr_asg_id;
3458       --
3459       hr_utility.set_location(l_proc, 45);
3460       delete_fed_tax_rule(
3461                         p_effective_date         => l_effective_date
3462                        ,p_datetrack_delete_mode  => p_datetrack_mode
3463                        ,p_assignment_id          => l_assignment_tbl(l_cnt)
3464                        ,p_delete_routine         => p_delete_routine
3465                        ,p_effective_start_date   => l_fed_eff_start_date
3466                        ,p_effective_end_date     => l_fed_eff_end_date
3467                        ,p_object_version_number  => l_fed_object_version_number
3468                        );
3469     end loop;
3470   else
3471     if p_assignment_id is not null then
3472       --
3473       hr_utility.set_location(l_proc, 50);
3474       l_assignment_id := p_assignment_id;
3475       --
3476       open csr_asg_id(l_assignment_id);
3477       fetch csr_asg_id into l_temp_num;
3478       if csr_asg_id%notfound then
3479         close csr_asg_id;
3480         hr_utility.set_message(801,'PAY_7702_PDT_VALUE_NOT_FOUND');
3481         hr_utility.raise_error;
3482       end if;
3483       close csr_asg_id;
3484       --
3485       open csr_defaulting_date(l_assignment_id);
3486       fetch csr_defaulting_date into l_defaulting_date;
3487       close csr_defaulting_date;
3488 
3489       if l_defaulting_date is null then
3490 
3491         create_default_tax_rules(
3492                       p_effective_date         => l_effective_date
3493                      ,p_assignment_id          => p_assignment_id
3494                      ,p_emp_fed_tax_rule_id    => l_fed_tax_rule_id
3495                      ,p_fed_object_version_number => l_fed_object_version_number
3496                      ,p_fed_effective_start_date  => l_fed_eff_start_date
3497                      ,p_fed_effective_end_date    => l_fed_eff_end_date
3498                      );
3499 
3500       else
3501 	-- reimp - discovered it was possible to remove defaulting conditions
3502 	-- we need to make sure that this change is not removing some defaulting
3503 	-- condition.  To do this, we check to make sure that if l_effective_date => l_default_date
3504 	-- then chk_defaulting_met must be true;
3505 	if l_effective_date >= l_defaulting_date then
3506 
3507 		open csr_defaulting_met(p_assignment_id,l_effective_date);
3508 		fetch csr_defaulting_met into l_temp_char;
3509 
3510 		/*Modified for bug 8285850.Introduced cursor csr_asgpayrollremoved
3511 		 to check if the current update or correction operation is trying
3512 		 to remove the payroll information after the defaulting for a setup
3513 		 with vertex or Workers compensation link set as Link to All Payrolls.*/
3514 
3515 		if csr_defaulting_met%NOTFOUND then
3516 
3517 		open csr_defaultpayrollremoved(p_assignment_id,p_effective_date);
3518 		fetch csr_defaultpayrollremoved into l_temp_char;
3519 
3520                /*An error will be thrown,if we try to remove payroll for an employee
3521 	         with default tax records created and his business group has Vertex
3522 		 or Workers Compensations set as Link to all payrolls.If these links
3523 		 are Open, we will permit the removal of payroll*/
3524 
3525 		  if csr_defaultpayrollremoved%FOUND then
3526 		      close csr_defaulting_met;
3527 		      close csr_defaultpayrollremoved;
3528 		      hr_utility.set_message(801,'PAY_75264_US_PAYROLL_REMOVAL');
3529       		      hr_utility.raise_error;
3530                   end if;
3531 
3532    		close csr_defaultpayrollremoved;
3533                 close csr_defaulting_met;
3534 
3535 		/*Check to make sure we are not removing payroll for which there are
3536 		  assignment actions at future date */
3537 
3538 		  open csr_asgmt_details(p_assignment_id,l_effective_date);
3539 		  fetch csr_asgmt_details into l_payroll_id,
3540 		                         l_effective_start_date,l_effective_end_date;
3541                   close csr_asgmt_details;
3542 		  if p_datetrack_mode='CORRECTION' then
3543 
3544 		  hrentmnt.check_payroll_changes_asg
3545                    (p_assignment_id,l_payroll_id,p_datetrack_mode,
3546 		    l_effective_start_date,l_effective_end_date);
3547 
3548 		  elsif p_datetrack_mode='UPDATE' then
3549 
3550 		  hrentmnt.check_payroll_changes_asg
3551                    (p_assignment_id,l_payroll_id,p_datetrack_mode,
3552 		    l_effective_date,l_effective_end_date);
3553 
3554 		  end if;
3555                 else
3556                    close csr_defaulting_met;
3557 		end if;
3558 
3559 	end if;
3560 
3561         -- I'm overriding the value of p_location_id if the datetrace mode
3562         -- is UPDATE_OVERRIDE and the location_id was passed as default value
3563         -- ie:hr_api.g_number.  Reason for this is we should take the value of
3564         -- the location_id as of the effective date of the change and we must
3565         -- maintain the tax records.  The value of
3566         -- per_us_extra_assignment_rules.g_old_assgt_location  is set in the user
3567         -- hook (before) procedure to used for stored data.
3568         --
3569         if p_datetrack_mode = 'UPDATE_OVERRIDE' THEN
3570            l_location_id := per_us_extra_assignment_rules.g_old_assgt_location;
3571         else
3572            l_location_id := p_location_id;
3573         end if;
3574         --
3575 	open csr_get_tax_loc(p_assignment_id,l_effective_date);
3576 	fetch csr_get_tax_loc into l_tax_location_id;
3577 	if csr_get_tax_loc%FOUND then
3578 		open csr_loc_addr(l_tax_location_id);
3579 		fetch csr_loc_addr into l_tax_loc_state_code,l_tax_loc_county_code,
3580 					l_tax_loc_city_code,l_tax_loc_ovrd_state_code,
3581 					l_tax_loc_ovrd_county_code,l_tax_loc_ovrd_city_code;
3582 
3583   		if csr_loc_addr%NOTFOUND then
3584     			close csr_loc_addr;
3585 			close csr_get_tax_loc;
3586     			hr_utility.set_message(801, 'PY_51133_TXADJ_INVALID_CITY');
3587     			hr_utility.raise_error;
3588   		end if;
3589 
3590 		close csr_loc_addr;
3591 
3592 		create_tax_rules_for_jd(p_state_code => l_tax_loc_state_code,
3593 					p_county_code => l_tax_loc_county_code,
3594 					p_city_code => l_tax_loc_city_code,
3595 					p_effective_date => l_defaulting_date,
3596 					p_assignment_id => p_assignment_id
3597 					);
3598 
3599 
3600 
3601 		create_tax_rules_for_jd(p_state_code => l_tax_loc_ovrd_state_code,
3602 					p_county_code => l_tax_loc_ovrd_county_code,
3603 					p_city_code => l_tax_loc_ovrd_city_code,
3604 					p_effective_date => l_defaulting_date,
3605 					p_assignment_id => p_assignment_id
3606 					);
3607 	end if; -- csr_get_tax_loc
3608         close csr_get_tax_loc;
3609 
3610 	-- reimp - changed hr_api.g_number to be null, since this code assumes null
3611 	-- to mean the location hasn't changed.
3612 
3613 	if l_location_id = hr_api.g_number then
3614 		l_location_id := null;
3615 	end if;
3616 
3617 	-- reimp - changed the conditions before move_tax_default_date is called
3618 	-- before it required l_location_id to not be null/hr_api.g_number
3619 
3620         if  l_location_id is not null and
3621                l_effective_date >= l_defaulting_date then
3622             --
3623             hr_utility.set_location(l_proc, 60);
3624             --
3625               location_change(
3626                      p_effective_date            => l_effective_date
3627                     ,p_datetrack_mode            => p_datetrack_mode
3628                     ,p_assignment_id             => p_assignment_id
3629                     ,p_location_id               => l_location_id
3630                     );
3631 
3632          elsif l_effective_date < l_defaulting_date then
3633             --
3634             hr_utility.set_location(l_proc, 70);
3635             --
3636             move_tax_default_date(
3637                      p_effective_date            => l_effective_date
3638                     ,p_datetrack_mode            => p_datetrack_mode
3639                     ,p_assignment_id             => p_assignment_id
3640                     ,p_new_location_id           => l_location_id
3641                     );
3642           end if;  -- assignment id is not null, defaulting date found, pull back?
3643       end if;   -- assignment id is not null, defaulting date found?
3644 
3645     else      -- assignment id is null, so address id must not be null
3646       --
3647       hr_utility.set_location(l_proc, 80);
3648       --
3649       open csr_adr_id(p_address_id);
3650       fetch csr_adr_id into l_person_id, l_adr_primary, l_adr_style;
3651       if csr_adr_id%notfound then
3652         close csr_adr_id;
3653         hr_utility.set_message(801,'HR_51396_WEB_PERSON_NOT_FND');
3654         hr_utility.raise_error;
3655       --
3656       -- # 2858888: validate address is US style
3657       -- Reverting these changes, no longer needed (3406718)
3658       --else
3659       -- validate_us_address(l_person_id, l_effective_date
3660       --                      ,l_adr_primary, l_adr_style);
3661       end if;
3662       close csr_adr_id;
3663       --
3664       -- This will loop through each assignment for the given person's
3665       -- address_id
3666       --
3667       hr_utility.set_location(l_proc, 85);
3668       for l_assgn_rec in csr_adr_asg_id(p_address_id) loop
3669         --
3670         open csr_defaulting_date(l_assgn_rec.assignment_id);
3671         fetch csr_defaulting_date into l_defaulting_date;
3672         close csr_defaulting_date;
3673         --
3674         if l_defaulting_date is null then
3675           --
3676           hr_utility.set_location(l_proc, 90);
3677           --
3678           create_default_tax_rules(
3679                           p_effective_date            => l_effective_date
3680                          ,p_assignment_id             => l_assgn_rec.assignment_id
3681                          ,p_emp_fed_tax_rule_id       => l_fed_tax_rule_id
3682                          ,p_fed_object_version_number => l_fed_object_version_number
3683                          ,p_fed_effective_start_date  => l_fed_eff_start_date
3684                          ,p_fed_effective_end_date    => l_fed_eff_end_date
3685                          );
3686           --
3687         else      -- federal tax rule found for this assignment
3688           --
3689           -- address id not null, defaulting date found, hire date null
3690           --
3691           hr_utility.set_location(l_proc, 100);
3692           --
3693           address_change(
3694                    p_effective_date            => l_effective_date
3695                   ,p_assignment_id             => l_assgn_rec.assignment_id
3696                   );
3697           --
3698         end if;  -- address id not null, defaulting date found?
3699       end loop;  -- loop through each assignment for address_id
3700     end if;  -- assignment id is not null?
3701   end if;  -- datetrack mode is ZAP?
3702   --
3703   hr_utility.set_location(' Leaving:'||l_proc, 120);
3704  --
3705 exception
3706   --
3707   when l_exit_quietly then
3708     hr_utility.set_location(' Leaving:'||l_proc, 125);
3709   --
3710 end maintain_us_employee_taxes;
3711 
3712 -- ----------------------------------------------------------------------------
3713 -- |---------------------------< location_change >--------------------------|
3714 -- ----------------------------------------------------------------------------
3715 procedure location_change
3716     (p_effective_date               In      date
3717     ,p_datetrack_mode               In      varchar2
3718     ,p_assignment_id                In      number
3719     ,p_location_id                  In      number
3720   ) is
3721   --
3722   -- Declare cursors and local variables
3723   --
3724   l_proc                        varchar2(72) := g_package||'location_change';
3725   l_effective_date              date;
3726   l_temp_char                   varchar2(10);
3727   l_default_flag                varchar2(1) := 'Y';
3728   l_defaulting_date        pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
3729   l_fed_tax_end_date       pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
3730   l_assignment_id               per_assignments_f.assignment_id%TYPE;
3731   l_business_group_id           per_assignments_f.business_group_id%TYPE;
3732   l_location_id                 per_assignments_f.location_id%TYPE;
3733   l_loc_id                      per_assignments_f.location_id%TYPE;
3734   l_chg_effective_start_date    per_assignments_f.effective_start_date%TYPE;
3735   l_chg_effective_end_date      per_assignments_f.effective_end_date%TYPE;
3736   l_sui_state_code		pay_us_states.state_code%TYPE;
3737   l_loc_state_code              pay_us_states.state_code%TYPE;
3738   l_loc_ovrd_state_code		pay_us_states.state_code%TYPE;
3739   l_loc_county_code             pay_us_counties.county_code%TYPE;
3740   l_loc_ovrd_county_code	pay_us_counties.county_code%TYPE;
3741   l_loc_city_code               pay_us_city_names.city_code%TYPE;
3742   l_loc_ovrd_city_code		pay_us_city_names.city_name%TYPE;
3743   l_jurisdiction_code     pay_us_emp_fed_tax_rules_f.sui_jurisdiction_code%TYPE;
3744   l_csr_state_code              pay_us_states.state_code%TYPE;
3745   l_csr_county_code             pay_us_counties.county_code%TYPE;
3746   l_csr_city_code               pay_us_city_names.city_code%TYPE;
3747 
3748   l_dt_mode                     varchar2(25);
3749   l_pct_eff_start_date     pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
3750   l_pct_eff_end_date        pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
3751   l_city_pct                    number;
3752   --
3753   l_fed_rec                     pay_fed_shd.g_rec_type;
3754   l_fed_rec_dup                 pay_fed_shd.g_rec_type;
3755   l_sta_rec                     pay_sta_shd.g_rec_type;
3756   l_sta_rec_dup                 pay_sta_shd.g_rec_type;
3757   l_cnt_rec                     pay_cnt_shd.g_rec_type;
3758   l_cnt_rec_dup                 pay_cnt_shd.g_rec_type;
3759   l_cty_rec                     pay_cty_shd.g_rec_type;
3760   l_cty_rec_dup                 pay_cty_shd.g_rec_type;
3761   l_exit_quietly                exception;
3762   --
3763   cursor csr_fed_tax_dates is
3764     select min(effective_start_date), max(effective_end_date)
3765     from   pay_us_emp_fed_tax_rules_f
3766     where  assignment_id = p_assignment_id;
3767   --
3768   cursor csr_asg_data is
3769     select asg.location_id, asg.effective_start_date, asg.effective_end_date
3770     from   per_assignments_f asg
3771     where  asg.assignment_id = p_assignment_id
3772     and    l_effective_date between asg.effective_start_date
3773            and asg.effective_end_date;
3774   --
3775   cursor csr_chk_location_id is
3776     select null
3777     from   hr_locations loc
3778     where  loc.location_id = p_location_id;
3779   --
3780   cursor csr_fed_rec1(l_csr_assignment_id number
3781                      ,l_csr_start_date date
3782                      ,l_csr_end_date date) is
3783      select emp_fed_tax_rule_id
3784            ,effective_start_date
3785            ,effective_end_date
3786            ,assignment_id
3787            ,sui_state_code
3788            ,sui_jurisdiction_code
3789            ,business_group_id
3790            ,additional_wa_amount
3791            ,filing_status_code
3792            ,fit_override_amount
3793            ,fit_override_rate
3794            ,withholding_allowances
3795            ,cumulative_taxation
3796            ,eic_filing_status_code
3797            ,fit_additional_tax
3798            ,fit_exempt
3799            ,futa_tax_exempt
3800            ,medicare_tax_exempt
3801            ,ss_tax_exempt
3802            ,wage_exempt
3803            ,statutory_employee
3804            ,w2_filed_year
3805            ,supp_tax_override_rate
3806            ,excessive_wa_reject_date
3807            ,object_version_number
3808            ,attribute_category
3809            ,attribute1
3810            ,attribute2
3811            ,attribute3
3812            ,attribute4
3813            ,attribute5
3814            ,attribute6
3815            ,attribute7
3816            ,attribute8
3817            ,attribute9
3818            ,attribute10
3819            ,attribute11
3820            ,attribute12
3821            ,attribute13
3822            ,attribute14
3823            ,attribute15
3824            ,attribute16
3825            ,attribute17
3826            ,attribute18
3827            ,attribute19
3828            ,attribute20
3829            ,attribute21
3830            ,attribute22
3831            ,attribute23
3832            ,attribute24
3833            ,attribute25
3834            ,attribute26
3835            ,attribute27
3836            ,attribute28
3837            ,attribute29
3838            ,attribute30
3839            ,fed_information_category
3840            ,fed_information1
3841            ,fed_information2
3842            ,fed_information3
3843            ,fed_information4
3844            ,fed_information5
3845            ,fed_information6
3846            ,fed_information7
3847            ,fed_information8
3848            ,fed_information9
3849            ,fed_information10
3850            ,fed_information11
3851            ,fed_information12
3852            ,fed_information13
3853            ,fed_information14
3854            ,fed_information15
3855            ,fed_information16
3856            ,fed_information17
3857            ,fed_information18
3858            ,fed_information19
3859            ,fed_information20
3860            ,fed_information21
3861            ,fed_information22
3862            ,fed_information23
3863            ,fed_information24
3864            ,fed_information25
3865            ,fed_information26
3866            ,fed_information27
3867            ,fed_information28
3868            ,fed_information29
3869            ,fed_information30
3870      from   pay_us_emp_fed_tax_rules_f
3871      where  assignment_id = l_csr_assignment_id
3872      and    effective_end_date >= l_csr_start_date
3873      and    effective_start_date <= l_csr_end_date;
3874   --
3875   cursor csr_fed_rec2(l_csr_assignment_id number
3876                      ,l_csr_start_date date
3877                      ,l_csr_end_date date) is
3878      select emp_fed_tax_rule_id
3879            ,effective_start_date
3880            ,effective_end_date
3881            ,assignment_id
3882            ,sui_state_code
3883            ,sui_jurisdiction_code
3884            ,business_group_id
3885            ,additional_wa_amount
3886            ,filing_status_code
3887            ,fit_override_amount
3888            ,fit_override_rate
3889            ,withholding_allowances
3890            ,cumulative_taxation
3891            ,eic_filing_status_code
3892            ,fit_additional_tax
3893            ,fit_exempt
3894            ,futa_tax_exempt
3895            ,medicare_tax_exempt
3896            ,ss_tax_exempt
3897            ,wage_exempt
3898            ,statutory_employee
3899            ,w2_filed_year
3900            ,supp_tax_override_rate
3901            ,excessive_wa_reject_date
3902            ,object_version_number
3903            ,attribute_category
3904            ,attribute1
3905            ,attribute2
3906            ,attribute3
3907            ,attribute4
3908            ,attribute5
3909            ,attribute6
3910            ,attribute7
3911            ,attribute8
3912            ,attribute9
3913            ,attribute10
3914            ,attribute11
3915            ,attribute12
3916            ,attribute13
3917            ,attribute14
3918            ,attribute15
3919            ,attribute16
3920            ,attribute17
3921            ,attribute18
3922            ,attribute19
3923            ,attribute20
3924            ,attribute21
3925            ,attribute22
3926            ,attribute23
3927            ,attribute24
3928            ,attribute25
3929            ,attribute26
3930            ,attribute27
3931            ,attribute28
3932            ,attribute29
3933            ,attribute30
3934            ,fed_information_category
3935            ,fed_information1
3936            ,fed_information2
3937            ,fed_information3
3938            ,fed_information4
3939            ,fed_information5
3940            ,fed_information6
3941            ,fed_information7
3942            ,fed_information8
3943            ,fed_information9
3944            ,fed_information10
3945            ,fed_information11
3946            ,fed_information12
3947            ,fed_information13
3948            ,fed_information14
3949            ,fed_information15
3950            ,fed_information16
3951            ,fed_information17
3952            ,fed_information18
3953            ,fed_information19
3954            ,fed_information20
3955            ,fed_information21
3956            ,fed_information22
3957            ,fed_information23
3958            ,fed_information24
3959            ,fed_information25
3960            ,fed_information26
3961            ,fed_information27
3962            ,fed_information28
3963            ,fed_information29
3964            ,fed_information30
3965      from   pay_us_emp_fed_tax_rules_f
3966      where  assignment_id = l_csr_assignment_id
3967      and    effective_start_date between l_csr_start_date and l_csr_end_date;
3968   --
3969   cursor csr_sta_rec1(l_csr_assignment_id number
3970                      ,l_csr_start_date date
3971                      ,l_csr_end_date date) is
3972      select emp_state_tax_rule_id
3973            ,effective_start_date
3974            ,effective_end_date
3975            ,assignment_id
3976            ,state_code
3977            ,jurisdiction_code
3978            ,business_group_id
3979            ,additional_wa_amount
3980            ,filing_status_code
3981            ,remainder_percent
3982            ,secondary_wa
3983            ,sit_additional_tax
3984            ,sit_override_amount
3985            ,sit_override_rate
3986            ,withholding_allowances
3987            ,excessive_wa_reject_date
3988            ,sdi_exempt
3989            ,sit_exempt
3990            ,sit_optional_calc_ind
3991            ,state_non_resident_cert
3992            ,sui_exempt
3993            ,wc_exempt
3994            ,wage_exempt
3995            ,sui_wage_base_override_amount
3996            ,supp_tax_override_rate
3997            ,object_version_number
3998            ,attribute_category
3999            ,attribute1
4000            ,attribute2
4001            ,attribute3
4002            ,attribute4
4003            ,attribute5
4004            ,attribute6
4005            ,attribute7
4006            ,attribute8
4007            ,attribute9
4008            ,attribute10
4009            ,attribute11
4010            ,attribute12
4011            ,attribute13
4012            ,attribute14
4013            ,attribute15
4014            ,attribute16
4015            ,attribute17
4016            ,attribute18
4017            ,attribute19
4018            ,attribute20
4019            ,attribute21
4020            ,attribute22
4021            ,attribute23
4022            ,attribute24
4023            ,attribute25
4024            ,attribute26
4025            ,attribute27
4026            ,attribute28
4027            ,attribute29
4028            ,attribute30
4029            ,sta_information_category
4030            ,sta_information1
4031            ,sta_information2
4032            ,sta_information3
4033            ,sta_information4
4034            ,sta_information5
4035            ,sta_information6
4036            ,sta_information7
4037            ,sta_information8
4038            ,sta_information9
4039            ,sta_information10
4040            ,sta_information11
4041            ,sta_information12
4042            ,sta_information13
4043            ,sta_information14
4044            ,sta_information15
4045            ,sta_information16
4046            ,sta_information17
4047            ,sta_information18
4048            ,sta_information19
4049            ,sta_information20
4050            ,sta_information21
4051            ,sta_information22
4052            ,sta_information23
4053            ,sta_information24
4054            ,sta_information25
4055            ,sta_information26
4056            ,sta_information27
4057            ,sta_information28
4058            ,sta_information29
4059            ,sta_information30
4060      from   pay_us_emp_state_tax_rules_f
4061      where  assignment_id = l_csr_assignment_id
4062      and    effective_end_date >= l_csr_start_date
4063      and    effective_start_date <= l_csr_end_date;
4064   --
4065   cursor csr_cnt_rec1(l_csr_assignment_id number
4066                      ,l_csr_start_date date
4067                      ,l_csr_end_date date) is
4068      select emp_county_tax_rule_id
4069            ,effective_start_date
4070            ,effective_end_date
4071            ,assignment_id
4072            ,state_code
4073            ,county_code
4074            ,business_group_id
4075            ,additional_wa_rate
4076            ,filing_status_code
4077            ,jurisdiction_code
4078            ,lit_additional_tax
4079            ,lit_override_amount
4080            ,lit_override_rate
4081            ,withholding_allowances
4082            ,lit_exempt
4083            ,sd_exempt
4084            ,ht_exempt
4085            ,wage_exempt
4086            ,school_district_code
4087            ,object_version_number
4088            ,attribute_category
4089            ,attribute1
4090            ,attribute2
4091            ,attribute3
4092            ,attribute4
4093            ,attribute5
4094            ,attribute6
4095            ,attribute7
4096            ,attribute8
4097            ,attribute9
4098            ,attribute10
4099            ,attribute11
4100            ,attribute12
4101            ,attribute13
4102            ,attribute14
4103            ,attribute15
4104            ,attribute16
4105            ,attribute17
4106            ,attribute18
4107            ,attribute19
4108            ,attribute20
4109            ,attribute21
4110            ,attribute22
4111            ,attribute23
4112            ,attribute24
4113            ,attribute25
4114            ,attribute26
4115            ,attribute27
4116            ,attribute28
4117            ,attribute29
4118            ,attribute30
4119            ,cnt_information_category
4120            ,cnt_information1
4121            ,cnt_information2
4122            ,cnt_information3
4123            ,cnt_information4
4124            ,cnt_information5
4125            ,cnt_information6
4126            ,cnt_information7
4127            ,cnt_information8
4128            ,cnt_information9
4129            ,cnt_information10
4130            ,cnt_information11
4131            ,cnt_information12
4132            ,cnt_information13
4133            ,cnt_information14
4134            ,cnt_information15
4135            ,cnt_information16
4136            ,cnt_information17
4137            ,cnt_information18
4138            ,cnt_information19
4139            ,cnt_information20
4140            ,cnt_information21
4141            ,cnt_information22
4142            ,cnt_information23
4143            ,cnt_information24
4144            ,cnt_information25
4145            ,cnt_information26
4146            ,cnt_information27
4147            ,cnt_information28
4148            ,cnt_information29
4149            ,cnt_information30
4150      from   pay_us_emp_county_tax_rules_f
4151      where  assignment_id = l_csr_assignment_id
4152      and    effective_end_date >= l_csr_start_date
4153      and    effective_start_date <= l_csr_end_date;
4154   --
4155   cursor csr_cty_rec1(l_csr_assignment_id number
4156                      ,l_csr_start_date date
4157                      ,l_csr_end_date date) is
4158      select emp_city_tax_rule_id
4159            ,effective_start_date
4160            ,effective_end_date
4161            ,assignment_id
4162            ,state_code
4163            ,county_code
4164            ,city_code
4165            ,business_group_id
4166            ,additional_wa_rate
4167            ,filing_status_code
4168            ,jurisdiction_code
4169            ,lit_additional_tax
4170            ,lit_override_amount
4171            ,lit_override_rate
4172            ,withholding_allowances
4173            ,lit_exempt
4174            ,sd_exempt
4175            ,ht_exempt
4176            ,wage_exempt
4177            ,school_district_code
4178            ,object_version_number
4179            ,attribute_category
4180            ,attribute1
4181            ,attribute2
4182            ,attribute3
4183            ,attribute4
4184            ,attribute5
4185            ,attribute6
4186            ,attribute7
4187            ,attribute8
4188            ,attribute9
4189            ,attribute10
4190            ,attribute11
4191            ,attribute12
4192            ,attribute13
4193            ,attribute14
4194            ,attribute15
4195            ,attribute16
4196            ,attribute17
4197            ,attribute18
4198            ,attribute19
4199            ,attribute20
4200            ,attribute21
4201            ,attribute22
4202            ,attribute23
4203            ,attribute24
4204            ,attribute25
4205            ,attribute26
4206            ,attribute27
4207            ,attribute28
4208            ,attribute29
4209            ,attribute30
4210            ,cty_information_category
4211            ,cty_information1
4212            ,cty_information2
4213            ,cty_information3
4214            ,cty_information4
4215            ,cty_information5
4216            ,cty_information6
4217            ,cty_information7
4218            ,cty_information8
4219            ,cty_information9
4220            ,cty_information10
4221            ,cty_information11
4222            ,cty_information12
4223            ,cty_information13
4224            ,cty_information14
4225            ,cty_information15
4226            ,cty_information16
4227            ,cty_information17
4228            ,cty_information18
4229            ,cty_information19
4230            ,cty_information20
4231            ,cty_information21
4232            ,cty_information22
4233            ,cty_information23
4234            ,cty_information24
4235            ,cty_information25
4236            ,cty_information26
4237            ,cty_information27
4238            ,cty_information28
4239            ,cty_information29
4240            ,cty_information30
4241      from   pay_us_emp_city_tax_rules_f
4242      where  assignment_id = l_csr_assignment_id
4243      and    effective_end_date >= l_csr_start_date
4244      and    effective_start_date <= l_csr_end_date;
4245   --
4246   cursor csr_asg_state_code is
4247      select sta.state_code
4248      from   pay_us_emp_state_tax_rules_f sta
4249      where  sta.assignment_id = p_assignment_id;
4250   --
4251   cursor csr_asg_county_code is
4252      select cnt.state_code, cnt.county_code
4253      from   pay_us_emp_county_tax_rules_f cnt
4254      where  cnt.assignment_id = p_assignment_id;
4255   --
4256   cursor csr_asg_city_code is
4257      select cty.state_code, cty.county_code, cty.city_code
4258      from   pay_us_emp_city_tax_rules_f cty
4259      where  cty.assignment_id = p_assignment_id;
4260   --
4261   cursor csr_fed_rule_exists(l_csr_tmp_date in date) is
4262      select null
4263      from   pay_us_emp_fed_tax_rules_f fed
4264      where  fed.assignment_id = p_assignment_id
4265      and    fed.effective_start_date = l_csr_tmp_date;
4266   --
4267 begin
4268   --
4269   hr_utility.set_location('Entering:'|| l_proc, 10);
4270   --
4271   -- Ensure that all the mandatory arguments are not null
4272   --
4273   hr_api.mandatory_arg_error(p_api_name       => l_proc,
4274                              p_argument       => 'effective_date',
4275                              p_argument_value => p_effective_date);
4276   --
4277   if p_assignment_id is null then
4278     hr_utility.set_message(801, 'HR_51253_PYP_ASS__NOT_VALID');
4279     hr_utility.raise_error;
4280   end if;
4281   --
4282   if p_datetrack_mode in('CORRECTION', 'UPDATE', 'UPDATE_CHANGE_INSERT',
4283                          'UPDATE_OVERRIDE') and p_location_id is null then
4284     hr_utility.set_message(801, 'HR_7880_PDT_VALUE_NOT_FOUND');
4285     hr_utility.raise_error;
4286   end if;
4287   --
4288   l_effective_date := trunc(p_effective_date);
4289   --
4290   hr_utility.set_location(l_proc, 20);
4291   --
4292   -- First check if geocode has been installed or not. If no geocodes
4293   -- installed then return because there is nothing to be done by this
4294   -- defaulting procedure
4295   if hr_general.chk_maintain_tax_records = 'N' then
4296      return;
4297   end if;
4298   --
4299   -- Validate p_assignment_id and p_location_id
4300   --
4301   open  csr_asg_data;
4302   fetch csr_asg_data into l_loc_id,
4303                           l_chg_effective_start_date,
4304                           l_chg_effective_end_date;
4305   if csr_asg_data%notfound then
4306     close csr_asg_data;
4307     hr_utility.set_message(801, 'HR_51253_PYP_ASS__NOT_VALID');
4308     hr_utility.raise_error;
4309   end if;
4310   close csr_asg_data;
4311   --
4312   -- Ensure that the new location id is different from the current location id
4313   --
4314   -- bug 924139  comment the following if statement as it is comparing the
4315   -- new location record to itself.  Hense tax records are not being updated
4316   -- when we change the location on the assignment record and the location
4317   -- address resided in a different state.
4318   --
4319   -- bug 1168727  comparing the p_location_id to global
4320   -- per_us_extra_assignment_rules.g_old_assgt_location.  If the old location
4321   -- id is same as the parameter location id then there is no need to update
4322   -- the tax records.  PLEASE NOTE THAT THE GLOBAL IS DEFINE IN PACKAGE
4323   -- per_us_extra_assignment_rules AND SET IN PROCEDURE get_curr_ass_location_id.
4324   --
4325   -- We will always attempt to process the location change is the date track
4326   -- mode is UPDATE_OVERRIDE.
4327   --
4328   if p_datetrack_mode in ('CORRECTION', 'UPDATE',
4329                          'UPDATE_CHANGE_INSERT' ) and
4330     p_location_id = per_us_extra_assignment_rules.g_old_assgt_location then
4331     RAISE l_exit_quietly;
4332   end if;
4333   --
4334   if p_datetrack_mode in('CORRECTION', 'UPDATE',
4335                          'UPDATE_CHANGE_INSERT' ) then
4336     open  csr_chk_location_id;
4337     fetch csr_chk_location_id into l_temp_char;
4338     if csr_chk_location_id%notfound then
4339       close csr_chk_location_id;
4340       hr_utility.set_message(801, 'HR_7880_PDT_VALUE_NOT_FOUND');
4341       hr_utility.raise_error;
4342     end if;
4343     close csr_chk_location_id;
4344     l_location_id := p_location_id;
4345   else
4346     l_location_id := l_loc_id;
4347   end if;
4348   --
4349   -- Get overall start and end dates of the federal tax rule
4350   --
4351   open  csr_fed_tax_dates;
4352   fetch csr_fed_tax_dates into l_defaulting_date, l_fed_tax_end_date;
4353   close csr_fed_tax_dates;
4354   if l_chg_effective_start_date < l_defaulting_date then
4355     hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4356     hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4357     hr_utility.set_message_token('SESSION_DATE', l_chg_effective_start_date);
4358     hr_utility.raise_error;
4359   end if;
4360   --
4361   hr_utility.set_location(l_proc, 30);
4362   --
4363   -- Select state, county and city codes for the new work location of the
4364   -- assignment.
4365   --
4366   open csr_loc_addr(l_location_id);
4367   fetch csr_loc_addr into l_loc_state_code, l_loc_county_code, l_loc_city_code,
4368 			  l_loc_ovrd_state_code,l_loc_ovrd_county_code,l_loc_ovrd_city_code;
4369   if csr_loc_addr%NOTFOUND then
4370     close csr_loc_addr;
4371     hr_utility.set_message(801, 'PY_51133_TXADJ_INVALID_CITY');
4372     hr_utility.raise_error;
4373   end if;
4374   close csr_loc_addr;
4375 
4376   -- since l_loc_ovrd_state_code defaults to the loc_state_code, we
4377   -- use it to set the sui
4378   l_sui_state_code := l_loc_ovrd_state_code;
4379 
4380   --
4381   hr_utility.set_location(l_proc, 40);
4382   --
4383   --
4384   --  Branch according to p_datetrack_mode here
4385   --
4386   if p_datetrack_mode = 'CORRECTION' then
4387     --
4388     hr_utility.set_location(l_proc, 50);
4389     --
4390     -- Select the federal tax record as of the assignment end date.
4391     --
4392     open csr_fed_rec1(p_assignment_id, l_chg_effective_end_date,
4393                           l_chg_effective_end_date);
4394     fetch csr_fed_rec1 into l_fed_rec;
4395     if csr_fed_rec1%notfound then
4396       -- No federal tax rule exists as of the end of the assignment record!
4397       close csr_fed_rec1;
4398       hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4399       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4400       hr_utility.set_message_token('SESSION_DATE', l_chg_effective_end_date);
4401       hr_utility.raise_error;
4402     end if;
4403     close csr_fed_rec1;
4404     --
4405     -- If the assignment effective end date does not match the federal tax rule
4406     -- effective end date, update the federal record to create a federal row
4407     -- with the same effective end date as the assignment.  Do the same for the
4408     -- workers comp entry.
4409     --
4410     if l_fed_rec.effective_end_date > l_chg_effective_end_date then
4411       open csr_fed_rule_exists(l_fed_rec.effective_end_date + 1);
4412       fetch csr_fed_rule_exists into l_temp_char;
4413       if csr_fed_rule_exists%notfound then
4414         l_dt_mode := 'UPDATE';
4415       else
4416         l_dt_mode := 'UPDATE_CHANGE_INSERT';
4417       end if;
4418       close csr_fed_rule_exists;
4419       pay_fed_upd.upd(l_fed_rec, l_chg_effective_end_date + 1, l_dt_mode);
4420       maintain_wc(
4421                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4422                   ,p_effective_start_date => l_fed_rec.effective_start_date
4423                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4424                   ,p_effective_date       => l_chg_effective_end_date + 1
4425                   ,p_datetrack_mode       => l_dt_mode
4426                   );
4427     end if;
4428     --
4429     -- Select the federal record as of the assignment start date.
4430     --
4431     open csr_fed_rec1(p_assignment_id, l_chg_effective_start_date,
4432                       l_chg_effective_start_date);
4433     fetch csr_fed_rec1 into l_fed_rec;
4434     if csr_fed_rec1%notfound then
4435       -- No federal tax rule exists as of the start of the assignment record!
4436       close csr_fed_rec1;
4437       hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4438       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4439       hr_utility.set_message_token('SESSION_DATE', l_chg_effective_start_date);
4440       hr_utility.raise_error;
4441     end if;
4442     close csr_fed_rec1;
4443     --
4444     -- Set new sui location in the record structure.
4445     --
4446       l_fed_rec.sui_state_code := l_sui_state_code;
4447       l_fed_rec.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
4448     --
4449     -- If the start dates do not match, update the federal record to create a
4450     -- row with the same start date as the assignment.  If they do match,
4451     -- correct the federal record.  Do the same for the workers comp entry.
4452     --
4453     if l_fed_rec.effective_start_date = l_chg_effective_start_date then
4454       --
4455       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, 'CORRECTION');
4456       maintain_wc(
4457                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4458                   ,p_effective_start_date => l_fed_rec.effective_start_date
4459                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4460                   ,p_effective_date       => l_chg_effective_start_date
4461                   ,p_datetrack_mode       => 'CORRECTION'
4462                   );
4463       --
4464     elsif l_fed_rec.effective_start_date < l_chg_effective_start_date then
4465       open csr_fed_rule_exists(l_fed_rec.effective_end_date + 1);
4466       fetch csr_fed_rule_exists into l_temp_char;
4467       if csr_fed_rule_exists%notfound then
4468         l_dt_mode := 'UPDATE';
4469       else
4470         l_dt_mode := 'UPDATE_CHANGE_INSERT';
4471       end if;
4472       close csr_fed_rule_exists;
4473       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, l_dt_mode);
4474       maintain_wc(
4475                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4476                   ,p_effective_start_date => l_fed_rec.effective_start_date
4477                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4478                   ,p_effective_date       => l_chg_effective_start_date
4479                   ,p_datetrack_mode       => l_dt_mode
4480                   );
4481     end if;
4482     --
4483     -- Correct sui_state and sui_jurisdiction for each federal record that
4484     -- exists at all between the start date + 1 and the end date of the
4485     -- assignment
4486     --
4487     for l_fed_rec in csr_fed_rec2(p_assignment_id, l_chg_effective_start_date+1,
4488                                   l_chg_effective_end_date)
4489     loop
4490 
4491 /* changes for bug 1970341 possible a DB issue. */
4492 --      l_fed_rec_dup := l_fed_rec;
4493 
4494       l_fed_rec_dup.emp_fed_tax_rule_id       := l_fed_rec.emp_fed_tax_rule_id;
4495       l_fed_rec_dup.effective_start_date      := l_fed_rec.effective_start_date;
4496       l_fed_rec_dup.effective_end_date        := l_fed_rec.effective_end_date;
4497       l_fed_rec_dup.assignment_id             := l_fed_rec.assignment_id;
4498       l_fed_rec_dup.sui_state_code            := l_fed_rec.sui_state_code;
4499       l_fed_rec_dup.sui_jurisdiction_code     := l_fed_rec.sui_jurisdiction_code;
4500       l_fed_rec_dup.business_group_id         := l_fed_rec.business_group_id;
4501       l_fed_rec_dup.additional_wa_amount      := l_fed_rec.additional_wa_amount;
4502       l_fed_rec_dup.filing_status_code        := l_fed_rec.filing_status_code;
4503       l_fed_rec_dup.fit_override_amount       := l_fed_rec.fit_override_amount;
4504       l_fed_rec_dup.fit_override_rate         := l_fed_rec.fit_override_rate;
4505       l_fed_rec_dup.withholding_allowances    := l_fed_rec.withholding_allowances;
4506       l_fed_rec_dup.cumulative_taxation       := l_fed_rec.cumulative_taxation;
4507       l_fed_rec_dup.eic_filing_status_code    := l_fed_rec.eic_filing_status_code;
4508       l_fed_rec_dup.fit_additional_tax        := l_fed_rec.fit_additional_tax;
4509       l_fed_rec_dup.fit_exempt                := l_fed_rec.fit_exempt;
4510       l_fed_rec_dup.futa_tax_exempt           := l_fed_rec.futa_tax_exempt;
4511       l_fed_rec_dup.medicare_tax_exempt       := l_fed_rec.medicare_tax_exempt;
4512       l_fed_rec_dup.ss_tax_exempt             := l_fed_rec.ss_tax_exempt;
4513       l_fed_rec_dup.wage_exempt               := l_fed_rec.wage_exempt;
4514       l_fed_rec_dup.statutory_employee        := l_fed_rec.statutory_employee;
4515       l_fed_rec_dup.w2_filed_year             := l_fed_rec.w2_filed_year;
4516       l_fed_rec_dup.supp_tax_override_rate    := l_fed_rec.supp_tax_override_rate;
4517       l_fed_rec_dup.excessive_wa_reject_date  := l_fed_rec.excessive_wa_reject_date;
4518       l_fed_rec_dup.object_version_number     := l_fed_rec.object_version_number;
4519       l_fed_rec_dup.attribute_category        := l_fed_rec.attribute_category;
4520       l_fed_rec_dup.attribute1                := l_fed_rec.attribute1;
4521       l_fed_rec_dup.attribute2                := l_fed_rec.attribute2;
4522       l_fed_rec_dup.attribute3                := l_fed_rec.attribute3;
4523       l_fed_rec_dup.attribute4                := l_fed_rec.attribute4;
4524       l_fed_rec_dup.attribute5                := l_fed_rec.attribute5;
4525       l_fed_rec_dup.attribute6                := l_fed_rec.attribute6;
4526       l_fed_rec_dup.attribute7                := l_fed_rec.attribute7;
4527       l_fed_rec_dup.attribute8                := l_fed_rec.attribute8;
4528       l_fed_rec_dup.attribute9                := l_fed_rec.attribute9;
4529       l_fed_rec_dup.attribute10               := l_fed_rec.attribute10;
4530       l_fed_rec_dup.attribute11               := l_fed_rec.attribute11;
4531       l_fed_rec_dup.attribute12               := l_fed_rec.attribute12;
4532       l_fed_rec_dup.attribute13               := l_fed_rec.attribute13;
4533       l_fed_rec_dup.attribute14               := l_fed_rec.attribute14;
4534       l_fed_rec_dup.attribute15               := l_fed_rec.attribute15;
4535       l_fed_rec_dup.attribute16               := l_fed_rec.attribute16;
4536       l_fed_rec_dup.attribute17               := l_fed_rec.attribute17;
4537       l_fed_rec_dup.attribute18               := l_fed_rec.attribute18;
4538       l_fed_rec_dup.attribute19               := l_fed_rec.attribute19;
4539       l_fed_rec_dup.attribute20               := l_fed_rec.attribute20;
4540       l_fed_rec_dup.attribute21               := l_fed_rec.attribute21;
4541       l_fed_rec_dup.attribute22               := l_fed_rec.attribute22;
4542       l_fed_rec_dup.attribute23               := l_fed_rec.attribute23;
4543       l_fed_rec_dup.attribute24               := l_fed_rec.attribute24;
4544       l_fed_rec_dup.attribute25               := l_fed_rec.attribute25;
4545       l_fed_rec_dup.attribute26               := l_fed_rec.attribute26;
4546       l_fed_rec_dup.attribute27               := l_fed_rec.attribute27;
4547       l_fed_rec_dup.attribute28               := l_fed_rec.attribute28;
4548       l_fed_rec_dup.attribute29               := l_fed_rec.attribute29;
4549       l_fed_rec_dup.attribute30               := l_fed_rec.attribute30;
4550       l_fed_rec_dup.fed_information_category  := l_fed_rec.fed_information_category;
4551       l_fed_rec_dup.fed_information1          := l_fed_rec.fed_information1;
4552       l_fed_rec_dup.fed_information2          := l_fed_rec.fed_information2;
4553       l_fed_rec_dup.fed_information3          := l_fed_rec.fed_information3;
4554       l_fed_rec_dup.fed_information4          := l_fed_rec.fed_information4;
4555       l_fed_rec_dup.fed_information5          := l_fed_rec.fed_information5;
4556       l_fed_rec_dup.fed_information6          := l_fed_rec.fed_information6;
4557       l_fed_rec_dup.fed_information7          := l_fed_rec.fed_information7;
4558       l_fed_rec_dup.fed_information8          := l_fed_rec.fed_information8;
4559       l_fed_rec_dup.fed_information9          := l_fed_rec.fed_information9;
4560       l_fed_rec_dup.fed_information10         := l_fed_rec.fed_information10;
4561       l_fed_rec_dup.fed_information11         := l_fed_rec.fed_information11;
4562       l_fed_rec_dup.fed_information12         := l_fed_rec.fed_information12;
4563       l_fed_rec_dup.fed_information13         := l_fed_rec.fed_information13;
4564       l_fed_rec_dup.fed_information14         := l_fed_rec.fed_information14;
4565       l_fed_rec_dup.fed_information15         := l_fed_rec.fed_information15;
4566       l_fed_rec_dup.fed_information16         := l_fed_rec.fed_information16;
4567       l_fed_rec_dup.fed_information17         := l_fed_rec.fed_information17;
4568       l_fed_rec_dup.fed_information18         := l_fed_rec.fed_information18;
4569       l_fed_rec_dup.fed_information19         := l_fed_rec.fed_information19;
4570       l_fed_rec_dup.fed_information20         := l_fed_rec.fed_information20;
4571       l_fed_rec_dup.fed_information21         := l_fed_rec.fed_information21;
4572       l_fed_rec_dup.fed_information22         := l_fed_rec.fed_information22;
4573       l_fed_rec_dup.fed_information23         := l_fed_rec.fed_information23;
4574       l_fed_rec_dup.fed_information24         := l_fed_rec.fed_information24;
4575       l_fed_rec_dup.fed_information25         := l_fed_rec.fed_information25;
4576       l_fed_rec_dup.fed_information26         := l_fed_rec.fed_information26;
4577       l_fed_rec_dup.fed_information27         := l_fed_rec.fed_information27;
4578       l_fed_rec_dup.fed_information28         := l_fed_rec.fed_information28;
4579       l_fed_rec_dup.fed_information29         := l_fed_rec.fed_information29;
4580       l_fed_rec_dup.fed_information30         := l_fed_rec.fed_information30;
4581 /* changes for bug 1970341 possible a DB issue. */
4582 
4583       l_fed_rec_dup.sui_state_code            := l_sui_state_code;
4584       l_fed_rec_dup.sui_jurisdiction_code     := l_sui_state_code || '-000-0000';
4585 
4586       pay_fed_upd.upd(l_fed_rec_dup, l_fed_rec_dup.effective_start_date,
4587                       'CORRECTION');
4588       maintain_wc(
4589                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4590                   ,p_effective_start_date => l_fed_rec.effective_start_date
4591                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4592                   ,p_effective_date       => l_chg_effective_start_date
4593                   ,p_datetrack_mode       => 'CORRECTION'
4594                   );
4595     end loop;
4596     --
4597 
4598 
4599   elsif p_datetrack_mode = 'UPDATE' then
4600     --
4601     hr_utility.set_location(l_proc, 60);
4602     --
4603     -- Select the federal record as of the assignment start date.
4604     --
4605     open csr_fed_rec1(p_assignment_id, l_chg_effective_start_date,
4606                       l_chg_effective_start_date);
4607     fetch csr_fed_rec1 into l_fed_rec;
4608     if csr_fed_rec1%notfound then
4609       -- No federal tax rule exists as of the start of the assignment record!
4610       close csr_fed_rec1;
4611       hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4612       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4613       hr_utility.set_message_token('SESSION_DATE', l_chg_effective_start_date);
4614       hr_utility.raise_error;
4615     end if;
4616     close csr_fed_rec1;
4617     --
4618     -- Set new sui location in the record structure.
4619     --
4620       l_fed_rec.sui_state_code := l_sui_state_code;
4621       l_fed_rec.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
4622     --
4623     -- If the start dates do not match, update the federal record to create a
4624     -- row with the same start date as the assignment.  If they do match,
4625     -- correct the federal record.  Do the same for the workers comp entry.
4626     --
4627     if l_fed_rec.effective_start_date = l_chg_effective_start_date then
4628       --
4629       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, 'CORRECTION');
4630       maintain_wc(
4631                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4632                   ,p_effective_start_date => l_fed_rec.effective_start_date
4633                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4634                   ,p_effective_date       => l_chg_effective_start_date
4635                   ,p_datetrack_mode       => 'CORRECTION'
4636                   );
4637       --
4638     elsif l_fed_rec.effective_start_date < l_chg_effective_start_date then
4639       open csr_fed_rule_exists(l_fed_rec.effective_end_date + 1);
4640       fetch csr_fed_rule_exists into l_temp_char;
4641       if csr_fed_rule_exists%notfound then
4642         l_dt_mode := 'UPDATE';
4643       else
4644         l_dt_mode := 'UPDATE_CHANGE_INSERT';
4645       end if;
4646       close csr_fed_rule_exists;
4647       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, l_dt_mode);
4648       maintain_wc(
4649                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4650                   ,p_effective_start_date => l_fed_rec.effective_start_date
4651                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4652                   ,p_effective_date       => l_chg_effective_start_date
4653                   ,p_datetrack_mode       => l_dt_mode
4654                   );
4655     end if;
4656     --
4657     -- Correct sui_state and sui_jurisdiction for each federal record that
4658     -- exists at all between the start and end dates of the assignment. Correct
4659     -- the workers comp entry.
4660     --
4661     for l_fed_rec in csr_fed_rec2(p_assignment_id, l_chg_effective_start_date+1,
4662                                   l_chg_effective_end_date)
4663     loop
4664 
4665 /* changes for bug 1970341 possible a DB issue. */
4666 --      l_fed_rec_dup := l_fed_rec;
4667 
4668       l_fed_rec_dup.emp_fed_tax_rule_id       := l_fed_rec.emp_fed_tax_rule_id;
4669       l_fed_rec_dup.effective_start_date      := l_fed_rec.effective_start_date;
4670       l_fed_rec_dup.effective_end_date        := l_fed_rec.effective_end_date;
4671       l_fed_rec_dup.assignment_id             := l_fed_rec.assignment_id;
4672       l_fed_rec_dup.sui_state_code            := l_fed_rec.sui_state_code;
4673       l_fed_rec_dup.sui_jurisdiction_code     := l_fed_rec.sui_jurisdiction_code;
4674       l_fed_rec_dup.business_group_id         := l_fed_rec.business_group_id;
4675       l_fed_rec_dup.additional_wa_amount      := l_fed_rec.additional_wa_amount;
4676       l_fed_rec_dup.filing_status_code        := l_fed_rec.filing_status_code;
4677       l_fed_rec_dup.fit_override_amount       := l_fed_rec.fit_override_amount;
4678       l_fed_rec_dup.fit_override_rate         := l_fed_rec.fit_override_rate;
4679       l_fed_rec_dup.withholding_allowances    := l_fed_rec.withholding_allowances;
4680       l_fed_rec_dup.cumulative_taxation       := l_fed_rec.cumulative_taxation;
4681       l_fed_rec_dup.eic_filing_status_code    := l_fed_rec.eic_filing_status_code;
4682       l_fed_rec_dup.fit_additional_tax        := l_fed_rec.fit_additional_tax;
4683       l_fed_rec_dup.fit_exempt                := l_fed_rec.fit_exempt;
4684       l_fed_rec_dup.futa_tax_exempt           := l_fed_rec.futa_tax_exempt;
4685       l_fed_rec_dup.medicare_tax_exempt       := l_fed_rec.medicare_tax_exempt;
4686       l_fed_rec_dup.ss_tax_exempt             := l_fed_rec.ss_tax_exempt;
4687       l_fed_rec_dup.wage_exempt               := l_fed_rec.wage_exempt;
4688       l_fed_rec_dup.statutory_employee        := l_fed_rec.statutory_employee;
4689       l_fed_rec_dup.w2_filed_year             := l_fed_rec.w2_filed_year;
4690       l_fed_rec_dup.supp_tax_override_rate    := l_fed_rec.supp_tax_override_rate;
4691       l_fed_rec_dup.excessive_wa_reject_date  := l_fed_rec.excessive_wa_reject_date;
4692       l_fed_rec_dup.object_version_number     := l_fed_rec.object_version_number;
4693       l_fed_rec_dup.attribute_category        := l_fed_rec.attribute_category;
4694       l_fed_rec_dup.attribute1                := l_fed_rec.attribute1;
4695       l_fed_rec_dup.attribute2                := l_fed_rec.attribute2;
4696       l_fed_rec_dup.attribute3                := l_fed_rec.attribute3;
4697       l_fed_rec_dup.attribute4                := l_fed_rec.attribute4;
4698       l_fed_rec_dup.attribute5                := l_fed_rec.attribute5;
4699       l_fed_rec_dup.attribute6                := l_fed_rec.attribute6;
4700       l_fed_rec_dup.attribute7                := l_fed_rec.attribute7;
4701       l_fed_rec_dup.attribute8                := l_fed_rec.attribute8;
4702       l_fed_rec_dup.attribute9                := l_fed_rec.attribute9;
4703       l_fed_rec_dup.attribute10               := l_fed_rec.attribute10;
4704       l_fed_rec_dup.attribute11               := l_fed_rec.attribute11;
4705       l_fed_rec_dup.attribute12               := l_fed_rec.attribute12;
4706       l_fed_rec_dup.attribute13               := l_fed_rec.attribute13;
4707       l_fed_rec_dup.attribute14               := l_fed_rec.attribute14;
4708       l_fed_rec_dup.attribute15               := l_fed_rec.attribute15;
4709       l_fed_rec_dup.attribute16               := l_fed_rec.attribute16;
4710       l_fed_rec_dup.attribute17               := l_fed_rec.attribute17;
4711       l_fed_rec_dup.attribute18               := l_fed_rec.attribute18;
4712       l_fed_rec_dup.attribute19               := l_fed_rec.attribute19;
4713       l_fed_rec_dup.attribute20               := l_fed_rec.attribute20;
4714       l_fed_rec_dup.attribute21               := l_fed_rec.attribute21;
4715       l_fed_rec_dup.attribute22               := l_fed_rec.attribute22;
4716       l_fed_rec_dup.attribute23               := l_fed_rec.attribute23;
4717       l_fed_rec_dup.attribute24               := l_fed_rec.attribute24;
4718       l_fed_rec_dup.attribute25               := l_fed_rec.attribute25;
4719       l_fed_rec_dup.attribute26               := l_fed_rec.attribute26;
4720       l_fed_rec_dup.attribute27               := l_fed_rec.attribute27;
4721       l_fed_rec_dup.attribute28               := l_fed_rec.attribute28;
4722       l_fed_rec_dup.attribute29               := l_fed_rec.attribute29;
4723       l_fed_rec_dup.attribute30               := l_fed_rec.attribute30;
4724       l_fed_rec_dup.fed_information_category  := l_fed_rec.fed_information_category;
4725       l_fed_rec_dup.fed_information1          := l_fed_rec.fed_information1;
4726       l_fed_rec_dup.fed_information2          := l_fed_rec.fed_information2;
4727       l_fed_rec_dup.fed_information3          := l_fed_rec.fed_information3;
4728       l_fed_rec_dup.fed_information4          := l_fed_rec.fed_information4;
4729       l_fed_rec_dup.fed_information5          := l_fed_rec.fed_information5;
4730       l_fed_rec_dup.fed_information6          := l_fed_rec.fed_information6;
4731       l_fed_rec_dup.fed_information7          := l_fed_rec.fed_information7;
4732       l_fed_rec_dup.fed_information8          := l_fed_rec.fed_information8;
4733       l_fed_rec_dup.fed_information9          := l_fed_rec.fed_information9;
4734       l_fed_rec_dup.fed_information10         := l_fed_rec.fed_information10;
4735       l_fed_rec_dup.fed_information11         := l_fed_rec.fed_information11;
4736       l_fed_rec_dup.fed_information12         := l_fed_rec.fed_information12;
4737       l_fed_rec_dup.fed_information13         := l_fed_rec.fed_information13;
4738       l_fed_rec_dup.fed_information14         := l_fed_rec.fed_information14;
4739       l_fed_rec_dup.fed_information15         := l_fed_rec.fed_information15;
4740       l_fed_rec_dup.fed_information16         := l_fed_rec.fed_information16;
4741       l_fed_rec_dup.fed_information17         := l_fed_rec.fed_information17;
4742       l_fed_rec_dup.fed_information18         := l_fed_rec.fed_information18;
4743       l_fed_rec_dup.fed_information19         := l_fed_rec.fed_information19;
4744       l_fed_rec_dup.fed_information20         := l_fed_rec.fed_information20;
4745       l_fed_rec_dup.fed_information21         := l_fed_rec.fed_information21;
4746       l_fed_rec_dup.fed_information22         := l_fed_rec.fed_information22;
4747       l_fed_rec_dup.fed_information23         := l_fed_rec.fed_information23;
4748       l_fed_rec_dup.fed_information24         := l_fed_rec.fed_information24;
4749       l_fed_rec_dup.fed_information25         := l_fed_rec.fed_information25;
4750       l_fed_rec_dup.fed_information26         := l_fed_rec.fed_information26;
4751       l_fed_rec_dup.fed_information27         := l_fed_rec.fed_information27;
4752       l_fed_rec_dup.fed_information28         := l_fed_rec.fed_information28;
4753       l_fed_rec_dup.fed_information29         := l_fed_rec.fed_information29;
4754       l_fed_rec_dup.fed_information30         := l_fed_rec.fed_information30;
4755 
4756 /* changes for bug 1970341 possible a DB issue. */
4757 
4758       l_fed_rec_dup.sui_state_code := l_sui_state_code;
4759       l_fed_rec_dup.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
4760       pay_fed_upd.upd(l_fed_rec_dup, l_fed_rec_dup.effective_start_date,
4761                       'CORRECTION');
4762       maintain_wc(
4763                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4764                   ,p_effective_start_date => l_fed_rec.effective_start_date
4765                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4766                   ,p_effective_date       => l_chg_effective_start_date
4767                   ,p_datetrack_mode       => 'CORRECTION'
4768                   );
4769     end loop;
4770 
4771 
4772   elsif p_datetrack_mode = 'UPDATE_CHANGE_INSERT' then
4773     --
4774     hr_utility.set_location(l_proc, 70);
4775     --
4776     -- Select the federal tax record as of the assignment end date.
4777     --
4778     open csr_fed_rec1(p_assignment_id, l_chg_effective_end_date,
4779                       l_chg_effective_end_date);
4780       fetch csr_fed_rec1 into l_fed_rec;
4781     if csr_fed_rec1%notfound then
4782       -- No federal tax rule exists as of the end of the assignment record!
4783       close csr_fed_rec1;
4784       hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4785       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4786       hr_utility.set_message_token('SESSION_DATE', l_chg_effective_end_date);
4787       hr_utility.raise_error;
4788     end if;
4789     close csr_fed_rec1;
4790     --
4791     -- If the assignment effective end date does not match the federal tax rule
4792     -- effective end date, update the federal record to create a federal row
4793     -- with the same effective end date as the assignment.  Do the same for the
4794     -- workers comp entry.
4795     --
4796     if l_fed_rec.effective_end_date > l_chg_effective_end_date then
4797       open csr_fed_rule_exists(l_fed_rec.effective_end_date + 1);
4798       fetch csr_fed_rule_exists into l_temp_char;
4799       if csr_fed_rule_exists%notfound then
4800         l_dt_mode := 'UPDATE';
4801       else
4802         l_dt_mode := 'UPDATE_CHANGE_INSERT';
4803       end if;
4804       close csr_fed_rule_exists;
4805       pay_fed_upd.upd(l_fed_rec, l_chg_effective_end_date + 1, l_dt_mode);
4806       maintain_wc(
4807                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4808                   ,p_effective_start_date => l_fed_rec.effective_start_date
4809                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4810                   ,p_effective_date       => l_chg_effective_end_date + 1
4811                   ,p_datetrack_mode       => l_dt_mode
4812                   );
4813     end if;
4814     --
4815     -- Select the federal record as of the assignment start date.
4816     --
4817     open csr_fed_rec1(p_assignment_id, l_chg_effective_start_date,
4818                       l_chg_effective_start_date);
4819     fetch csr_fed_rec1 into l_fed_rec;
4820     if csr_fed_rec1%notfound then
4821       -- No federal tax rule exists as of the start of the assignment record!
4822       close csr_fed_rec1;
4823       hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4824       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4825       hr_utility.set_message_token('SESSION_DATE', l_chg_effective_start_date);
4826       hr_utility.raise_error;
4827     end if;
4828     close csr_fed_rec1;
4829     --
4830     -- Set new sui location in the record structure.
4831     --
4832       l_fed_rec.sui_state_code := l_sui_state_code;
4833       l_fed_rec.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
4834     --
4835     -- If the start dates do not match, update the federal record to create a
4836     -- row with the same start date as the assignment.  If they do match,
4837     -- correct the federal record.  Do the same for the workers comp entry.
4838     --
4839     if l_fed_rec.effective_start_date = l_chg_effective_start_date then
4840       --
4841       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, 'CORRECTION');
4842       maintain_wc(
4843                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4844                   ,p_effective_start_date => l_fed_rec.effective_start_date
4845                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4846                   ,p_effective_date       => l_chg_effective_start_date
4847                   ,p_datetrack_mode       => 'CORRECTION'
4848                   );
4849       --
4850     elsif l_fed_rec.effective_start_date < l_chg_effective_start_date then
4851       open csr_fed_rule_exists(l_fed_rec.effective_end_date + 1);
4852       fetch csr_fed_rule_exists into l_temp_char;
4853       if csr_fed_rule_exists%notfound then
4854         l_dt_mode := 'UPDATE';
4855       else
4856         l_dt_mode := 'UPDATE_CHANGE_INSERT';
4857       end if;
4858       close csr_fed_rule_exists;
4859       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, l_dt_mode);
4860       maintain_wc(
4861                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4862                   ,p_effective_start_date => l_fed_rec.effective_start_date
4863                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4864                   ,p_effective_date       => l_chg_effective_start_date
4865                   ,p_datetrack_mode       => l_dt_mode
4866                   );
4867     end if;
4868     --
4869     -- Correct sui_state and sui_jurisdiction for each federal record that
4870 
4871     -- exists at all between the start date + 1 and the end date of the
4872     -- assignment.  Do the same for the workers comp entry.
4873     --
4874     for l_fed_rec in csr_fed_rec2(p_assignment_id, l_chg_effective_start_date+1,
4875                                   l_chg_effective_end_date)
4876     loop
4877 
4878 /* changes for bug 1970341 possible a DB issue. */
4879 --      l_fed_rec_dup := l_fed_rec;
4880 
4881       l_fed_rec_dup.emp_fed_tax_rule_id       := l_fed_rec.emp_fed_tax_rule_id;
4882       l_fed_rec_dup.effective_start_date      := l_fed_rec.effective_start_date;
4883       l_fed_rec_dup.effective_end_date        := l_fed_rec.effective_end_date;
4884       l_fed_rec_dup.assignment_id             := l_fed_rec.assignment_id;
4885       l_fed_rec_dup.sui_state_code            := l_fed_rec.sui_state_code;
4886       l_fed_rec_dup.sui_jurisdiction_code     := l_fed_rec.sui_jurisdiction_code;
4887       l_fed_rec_dup.business_group_id         := l_fed_rec.business_group_id;
4888       l_fed_rec_dup.additional_wa_amount      := l_fed_rec.additional_wa_amount;
4889       l_fed_rec_dup.filing_status_code        := l_fed_rec.filing_status_code;
4890       l_fed_rec_dup.fit_override_amount       := l_fed_rec.fit_override_amount;
4891       l_fed_rec_dup.fit_override_rate         := l_fed_rec.fit_override_rate;
4892       l_fed_rec_dup.withholding_allowances    := l_fed_rec.withholding_allowances;
4893       l_fed_rec_dup.cumulative_taxation       := l_fed_rec.cumulative_taxation;
4894       l_fed_rec_dup.eic_filing_status_code    := l_fed_rec.eic_filing_status_code;
4895       l_fed_rec_dup.fit_additional_tax        := l_fed_rec.fit_additional_tax;
4896       l_fed_rec_dup.fit_exempt                := l_fed_rec.fit_exempt;
4897       l_fed_rec_dup.futa_tax_exempt           := l_fed_rec.futa_tax_exempt;
4898       l_fed_rec_dup.medicare_tax_exempt       := l_fed_rec.medicare_tax_exempt;
4899       l_fed_rec_dup.ss_tax_exempt             := l_fed_rec.ss_tax_exempt;
4900       l_fed_rec_dup.wage_exempt               := l_fed_rec.wage_exempt;
4901       l_fed_rec_dup.statutory_employee        := l_fed_rec.statutory_employee;
4902       l_fed_rec_dup.w2_filed_year             := l_fed_rec.w2_filed_year;
4903       l_fed_rec_dup.supp_tax_override_rate    := l_fed_rec.supp_tax_override_rate;
4904       l_fed_rec_dup.excessive_wa_reject_date  := l_fed_rec.excessive_wa_reject_date;
4905       l_fed_rec_dup.object_version_number     := l_fed_rec.object_version_number;
4906       l_fed_rec_dup.attribute_category        := l_fed_rec.attribute_category;
4907       l_fed_rec_dup.attribute1                := l_fed_rec.attribute1;
4908       l_fed_rec_dup.attribute2                := l_fed_rec.attribute2;
4909       l_fed_rec_dup.attribute3                := l_fed_rec.attribute3;
4910       l_fed_rec_dup.attribute4                := l_fed_rec.attribute4;
4911       l_fed_rec_dup.attribute5                := l_fed_rec.attribute5;
4912       l_fed_rec_dup.attribute6                := l_fed_rec.attribute6;
4913       l_fed_rec_dup.attribute7                := l_fed_rec.attribute7;
4914       l_fed_rec_dup.attribute8                := l_fed_rec.attribute8;
4915       l_fed_rec_dup.attribute9                := l_fed_rec.attribute9;
4916       l_fed_rec_dup.attribute10               := l_fed_rec.attribute10;
4917       l_fed_rec_dup.attribute11               := l_fed_rec.attribute11;
4918       l_fed_rec_dup.attribute12               := l_fed_rec.attribute12;
4919       l_fed_rec_dup.attribute13               := l_fed_rec.attribute13;
4920       l_fed_rec_dup.attribute14               := l_fed_rec.attribute14;
4921       l_fed_rec_dup.attribute15               := l_fed_rec.attribute15;
4922       l_fed_rec_dup.attribute16               := l_fed_rec.attribute16;
4923       l_fed_rec_dup.attribute17               := l_fed_rec.attribute17;
4924       l_fed_rec_dup.attribute18               := l_fed_rec.attribute18;
4925       l_fed_rec_dup.attribute19               := l_fed_rec.attribute19;
4926       l_fed_rec_dup.attribute20               := l_fed_rec.attribute20;
4927       l_fed_rec_dup.attribute21               := l_fed_rec.attribute21;
4928       l_fed_rec_dup.attribute22               := l_fed_rec.attribute22;
4929       l_fed_rec_dup.attribute23               := l_fed_rec.attribute23;
4930       l_fed_rec_dup.attribute24               := l_fed_rec.attribute24;
4931       l_fed_rec_dup.attribute25               := l_fed_rec.attribute25;
4932       l_fed_rec_dup.attribute26               := l_fed_rec.attribute26;
4933       l_fed_rec_dup.attribute27               := l_fed_rec.attribute27;
4934       l_fed_rec_dup.attribute28               := l_fed_rec.attribute28;
4935       l_fed_rec_dup.attribute29               := l_fed_rec.attribute29;
4936       l_fed_rec_dup.attribute30               := l_fed_rec.attribute30;
4937       l_fed_rec_dup.fed_information_category  := l_fed_rec.fed_information_category;
4938       l_fed_rec_dup.fed_information1          := l_fed_rec.fed_information1;
4939       l_fed_rec_dup.fed_information2          := l_fed_rec.fed_information2;
4940       l_fed_rec_dup.fed_information3          := l_fed_rec.fed_information3;
4941       l_fed_rec_dup.fed_information4          := l_fed_rec.fed_information4;
4942       l_fed_rec_dup.fed_information5          := l_fed_rec.fed_information5;
4943       l_fed_rec_dup.fed_information6          := l_fed_rec.fed_information6;
4944       l_fed_rec_dup.fed_information7          := l_fed_rec.fed_information7;
4945       l_fed_rec_dup.fed_information8          := l_fed_rec.fed_information8;
4946       l_fed_rec_dup.fed_information9          := l_fed_rec.fed_information9;
4947       l_fed_rec_dup.fed_information10         := l_fed_rec.fed_information10;
4948       l_fed_rec_dup.fed_information11         := l_fed_rec.fed_information11;
4949       l_fed_rec_dup.fed_information12         := l_fed_rec.fed_information12;
4950       l_fed_rec_dup.fed_information13         := l_fed_rec.fed_information13;
4951       l_fed_rec_dup.fed_information14         := l_fed_rec.fed_information14;
4952       l_fed_rec_dup.fed_information15         := l_fed_rec.fed_information15;
4953       l_fed_rec_dup.fed_information16         := l_fed_rec.fed_information16;
4954       l_fed_rec_dup.fed_information17         := l_fed_rec.fed_information17;
4955       l_fed_rec_dup.fed_information18         := l_fed_rec.fed_information18;
4956       l_fed_rec_dup.fed_information19         := l_fed_rec.fed_information19;
4957       l_fed_rec_dup.fed_information20         := l_fed_rec.fed_information20;
4958       l_fed_rec_dup.fed_information21         := l_fed_rec.fed_information21;
4959       l_fed_rec_dup.fed_information22         := l_fed_rec.fed_information22;
4960       l_fed_rec_dup.fed_information23         := l_fed_rec.fed_information23;
4961       l_fed_rec_dup.fed_information24         := l_fed_rec.fed_information24;
4962       l_fed_rec_dup.fed_information25         := l_fed_rec.fed_information25;
4963       l_fed_rec_dup.fed_information26         := l_fed_rec.fed_information26;
4964       l_fed_rec_dup.fed_information27         := l_fed_rec.fed_information27;
4965       l_fed_rec_dup.fed_information28         := l_fed_rec.fed_information28;
4966       l_fed_rec_dup.fed_information29         := l_fed_rec.fed_information29;
4967       l_fed_rec_dup.fed_information30         := l_fed_rec.fed_information30;
4968 
4969 /* changes for bug 1970341 possible a DB issue. */
4970 
4971       l_fed_rec_dup.sui_state_code := l_sui_state_code;
4972       l_fed_rec_dup.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
4973       pay_fed_upd.upd(l_fed_rec_dup, l_fed_rec_dup.effective_start_date,
4974                       'CORRECTION');
4975       maintain_wc(
4976                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
4977                   ,p_effective_start_date => l_fed_rec.effective_start_date
4978                   ,p_effective_end_date   => l_fed_rec.effective_end_date
4979                   ,p_effective_date       => l_chg_effective_start_date
4980                   ,p_datetrack_mode       => 'CORRECTION'
4981                   );
4982     end loop;
4983 
4984 
4985   elsif p_datetrack_mode = 'UPDATE_OVERRIDE' then
4986     --
4987     hr_utility.set_location(l_proc, 80);
4988     --
4989     -- Select the federal record as of the assignment start date.
4990     --
4991     open csr_fed_rec1(p_assignment_id, l_chg_effective_start_date,
4992                       l_chg_effective_start_date);
4993     fetch csr_fed_rec1 into l_fed_rec;
4994     if csr_fed_rec1%notfound then
4995       -- No federal tax rule exists as of the start of the assignment record!
4996       close csr_fed_rec1;
4997       hr_utility.set_message(801, 'HR_7180_DT_NO_ROW_EXIST');
4998       hr_utility.set_message_token('TABLE_NAME','PAY_US_EMP_FED_TAX_RULES_F');
4999       hr_utility.set_message_token('SESSION_DATE', l_chg_effective_start_date);
5000       hr_utility.raise_error;
5001     end if;
5002     close csr_fed_rec1;
5003     --
5004     -- Set new sui location in the record structure.
5005     --
5006       l_fed_rec.sui_state_code := l_sui_state_code;
5007       l_fed_rec.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
5008     --
5009     -- If the start dates do not match, update the federal record to create a
5010     -- row with the same start date as the assignment.  If they do match,
5011     -- correct the federal record.  Do the same for the workers comp entry.
5012     --
5013     if l_fed_rec.effective_start_date = l_chg_effective_start_date then
5014       --
5015       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, 'CORRECTION');
5016       maintain_wc(
5017                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
5018                   ,p_effective_start_date => l_fed_rec.effective_start_date
5019                   ,p_effective_end_date   => l_fed_rec.effective_end_date
5020                   ,p_effective_date       => l_chg_effective_start_date
5021                   ,p_datetrack_mode       => 'CORRECTION'
5022                   );
5023       --
5024     elsif l_fed_rec.effective_start_date < l_chg_effective_start_date then
5025       open csr_fed_rule_exists(l_fed_rec.effective_end_date + 1);
5026       fetch csr_fed_rule_exists into l_temp_char;
5027       if csr_fed_rule_exists%notfound then
5028         l_dt_mode := 'UPDATE';
5029       else
5030         l_dt_mode := 'UPDATE_CHANGE_INSERT';
5031       end if;
5032       close csr_fed_rule_exists;
5033       pay_fed_upd.upd(l_fed_rec, l_chg_effective_start_date, l_dt_mode);
5034       maintain_wc(
5035                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
5036                   ,p_effective_start_date => l_fed_rec.effective_start_date
5037                   ,p_effective_end_date   => l_fed_rec.effective_end_date
5038                   ,p_effective_date       => l_chg_effective_start_date
5039                   ,p_datetrack_mode       => l_dt_mode
5040                   );
5041     end if;
5042     --
5043     -- Correct sui_state and sui_jurisdiction for each federal record that
5044     -- exists at all between the start date + 1 and the end date of the
5045     -- assignment.  Do the same for the workers comp entry.
5046     --
5047     for l_fed_rec in csr_fed_rec2(p_assignment_id, l_chg_effective_start_date+1,
5048                                   l_chg_effective_end_date)
5049     loop
5050 
5051 /* changes for bug 1970341 possible a DB issue. */
5052 --      l_fed_rec_dup := l_fed_rec;
5053 
5054       l_fed_rec_dup.emp_fed_tax_rule_id       := l_fed_rec.emp_fed_tax_rule_id;
5055       l_fed_rec_dup.effective_start_date      := l_fed_rec.effective_start_date;
5056       l_fed_rec_dup.effective_end_date        := l_fed_rec.effective_end_date;
5057       l_fed_rec_dup.assignment_id             := l_fed_rec.assignment_id;
5058       l_fed_rec_dup.sui_state_code            := l_fed_rec.sui_state_code;
5059       l_fed_rec_dup.sui_jurisdiction_code     := l_fed_rec.sui_jurisdiction_code;
5060       l_fed_rec_dup.business_group_id         := l_fed_rec.business_group_id;
5061       l_fed_rec_dup.additional_wa_amount      := l_fed_rec.additional_wa_amount;
5062       l_fed_rec_dup.filing_status_code        := l_fed_rec.filing_status_code;
5063       l_fed_rec_dup.fit_override_amount       := l_fed_rec.fit_override_amount;
5064       l_fed_rec_dup.fit_override_rate         := l_fed_rec.fit_override_rate;
5065       l_fed_rec_dup.withholding_allowances    := l_fed_rec.withholding_allowances;
5066       l_fed_rec_dup.cumulative_taxation       := l_fed_rec.cumulative_taxation;
5067       l_fed_rec_dup.eic_filing_status_code    := l_fed_rec.eic_filing_status_code;
5068       l_fed_rec_dup.fit_additional_tax        := l_fed_rec.fit_additional_tax;
5069       l_fed_rec_dup.fit_exempt                := l_fed_rec.fit_exempt;
5070       l_fed_rec_dup.futa_tax_exempt           := l_fed_rec.futa_tax_exempt;
5071       l_fed_rec_dup.medicare_tax_exempt       := l_fed_rec.medicare_tax_exempt;
5072       l_fed_rec_dup.ss_tax_exempt             := l_fed_rec.ss_tax_exempt;
5073       l_fed_rec_dup.wage_exempt               := l_fed_rec.wage_exempt;
5074       l_fed_rec_dup.statutory_employee        := l_fed_rec.statutory_employee;
5075       l_fed_rec_dup.w2_filed_year             := l_fed_rec.w2_filed_year;
5076       l_fed_rec_dup.supp_tax_override_rate    := l_fed_rec.supp_tax_override_rate;
5077       l_fed_rec_dup.excessive_wa_reject_date  := l_fed_rec.excessive_wa_reject_date;
5078       l_fed_rec_dup.object_version_number     := l_fed_rec.object_version_number;
5079       l_fed_rec_dup.attribute_category        := l_fed_rec.attribute_category;
5080       l_fed_rec_dup.attribute1                := l_fed_rec.attribute1;
5081       l_fed_rec_dup.attribute2                := l_fed_rec.attribute2;
5082       l_fed_rec_dup.attribute3                := l_fed_rec.attribute3;
5083       l_fed_rec_dup.attribute4                := l_fed_rec.attribute4;
5084       l_fed_rec_dup.attribute5                := l_fed_rec.attribute5;
5085       l_fed_rec_dup.attribute6                := l_fed_rec.attribute6;
5086       l_fed_rec_dup.attribute7                := l_fed_rec.attribute7;
5087       l_fed_rec_dup.attribute8                := l_fed_rec.attribute8;
5088       l_fed_rec_dup.attribute9                := l_fed_rec.attribute9;
5089       l_fed_rec_dup.attribute10               := l_fed_rec.attribute10;
5090       l_fed_rec_dup.attribute11               := l_fed_rec.attribute11;
5091       l_fed_rec_dup.attribute12               := l_fed_rec.attribute12;
5092       l_fed_rec_dup.attribute13               := l_fed_rec.attribute13;
5093       l_fed_rec_dup.attribute14               := l_fed_rec.attribute14;
5094       l_fed_rec_dup.attribute15               := l_fed_rec.attribute15;
5095       l_fed_rec_dup.attribute16               := l_fed_rec.attribute16;
5096       l_fed_rec_dup.attribute17               := l_fed_rec.attribute17;
5097       l_fed_rec_dup.attribute18               := l_fed_rec.attribute18;
5098       l_fed_rec_dup.attribute19               := l_fed_rec.attribute19;
5099       l_fed_rec_dup.attribute20               := l_fed_rec.attribute20;
5100       l_fed_rec_dup.attribute21               := l_fed_rec.attribute21;
5101       l_fed_rec_dup.attribute22               := l_fed_rec.attribute22;
5102       l_fed_rec_dup.attribute23               := l_fed_rec.attribute23;
5103       l_fed_rec_dup.attribute24               := l_fed_rec.attribute24;
5104       l_fed_rec_dup.attribute25               := l_fed_rec.attribute25;
5105       l_fed_rec_dup.attribute26               := l_fed_rec.attribute26;
5106       l_fed_rec_dup.attribute27               := l_fed_rec.attribute27;
5107       l_fed_rec_dup.attribute28               := l_fed_rec.attribute28;
5108       l_fed_rec_dup.attribute29               := l_fed_rec.attribute29;
5109       l_fed_rec_dup.attribute30               := l_fed_rec.attribute30;
5110       l_fed_rec_dup.fed_information_category  := l_fed_rec.fed_information_category;
5111       l_fed_rec_dup.fed_information1          := l_fed_rec.fed_information1;
5112       l_fed_rec_dup.fed_information2          := l_fed_rec.fed_information2;
5113       l_fed_rec_dup.fed_information3          := l_fed_rec.fed_information3;
5114       l_fed_rec_dup.fed_information4          := l_fed_rec.fed_information4;
5115       l_fed_rec_dup.fed_information5          := l_fed_rec.fed_information5;
5116       l_fed_rec_dup.fed_information6          := l_fed_rec.fed_information6;
5117       l_fed_rec_dup.fed_information7          := l_fed_rec.fed_information7;
5118       l_fed_rec_dup.fed_information8          := l_fed_rec.fed_information8;
5119       l_fed_rec_dup.fed_information9          := l_fed_rec.fed_information9;
5120       l_fed_rec_dup.fed_information10         := l_fed_rec.fed_information10;
5121       l_fed_rec_dup.fed_information11         := l_fed_rec.fed_information11;
5122       l_fed_rec_dup.fed_information12         := l_fed_rec.fed_information12;
5123       l_fed_rec_dup.fed_information13         := l_fed_rec.fed_information13;
5124       l_fed_rec_dup.fed_information14         := l_fed_rec.fed_information14;
5125       l_fed_rec_dup.fed_information15         := l_fed_rec.fed_information15;
5126       l_fed_rec_dup.fed_information16         := l_fed_rec.fed_information16;
5127       l_fed_rec_dup.fed_information17         := l_fed_rec.fed_information17;
5128       l_fed_rec_dup.fed_information18         := l_fed_rec.fed_information18;
5129       l_fed_rec_dup.fed_information19         := l_fed_rec.fed_information19;
5130       l_fed_rec_dup.fed_information20         := l_fed_rec.fed_information20;
5131       l_fed_rec_dup.fed_information21         := l_fed_rec.fed_information21;
5132       l_fed_rec_dup.fed_information22         := l_fed_rec.fed_information22;
5133       l_fed_rec_dup.fed_information23         := l_fed_rec.fed_information23;
5134       l_fed_rec_dup.fed_information24         := l_fed_rec.fed_information24;
5135       l_fed_rec_dup.fed_information25         := l_fed_rec.fed_information25;
5136       l_fed_rec_dup.fed_information26         := l_fed_rec.fed_information26;
5137       l_fed_rec_dup.fed_information27         := l_fed_rec.fed_information27;
5138       l_fed_rec_dup.fed_information28         := l_fed_rec.fed_information28;
5139       l_fed_rec_dup.fed_information29         := l_fed_rec.fed_information29;
5140       l_fed_rec_dup.fed_information30         := l_fed_rec.fed_information30;
5141 
5142 /* changes for bug 1970341 possible a DB issue. */
5143 
5144       l_fed_rec_dup.sui_state_code := l_sui_state_code;
5145       l_fed_rec_dup.sui_jurisdiction_code := l_sui_state_code || '-000-0000';
5146       pay_fed_upd.upd(l_fed_rec_dup, l_fed_rec_dup.effective_start_date,
5147                       'CORRECTION');
5148       maintain_wc(
5149                    p_emp_fed_tax_rule_id  => l_fed_rec.emp_fed_tax_rule_id
5150                   ,p_effective_start_date => l_fed_rec.effective_start_date
5151                   ,p_effective_end_date   => l_fed_rec.effective_end_date
5152                   ,p_effective_date       => l_fed_rec.effective_start_date
5153                   ,p_datetrack_mode       => 'CORRECTION'
5154                   );
5155     end loop;
5156 
5157   elsif p_datetrack_mode in ('ZAP', 'DELETE',
5158                              'DELETE_NEXT_CHANGE',
5159                              'FUTURE_CHANGE') then
5160     --
5161     hr_utility.set_location(l_proc, 110);
5162     --
5163     -- This process should not be called with these modes.  Call
5164     -- Maintain_us_emp_taxes for a ZAP delete.
5165     -- Other delete modes are not allowed.
5166       hr_utility.set_message(801, 'HR_7204_DT_DEL_MODE_INVALID');
5167       hr_utility.raise_error;
5168 
5169   else
5170     -- Unknown datetrack mode
5171       hr_utility.set_message(801, 'HR_7184_DT_MODE_UNKNOWN');
5172       hr_utility.set_message_token('DT_MODE', p_datetrack_mode);
5173       hr_utility.raise_error;
5174 
5175   end if;
5176   --
5177   --
5178   --
5179   --
5180   -- Modify the existing tax percentages
5181   --
5182   open csr_asg_city_code;
5183   loop
5184     fetch csr_asg_city_code into l_csr_state_code, l_csr_county_code,
5185                                  l_csr_city_code;
5186     exit when csr_asg_city_code%notfound;
5187     --
5188     l_city_pct := 0;
5189     l_pct_eff_start_date := l_chg_effective_start_date;
5190     l_pct_eff_end_date := l_chg_effective_end_date;
5191 
5192     /* we check to see if the entry being updated matches the ovrd jurisdiction, which
5193        defaults to the mailing address jurisdiction if not present.  If so, set that
5194        percentage at 100 */
5195 
5196     if l_loc_ovrd_state_code||l_loc_ovrd_county_code||l_loc_ovrd_city_code =
5197                 l_csr_state_code||l_csr_county_code||l_csr_city_code then
5198       l_city_pct := 100;
5199     end if;
5200     maintain_tax_percentage(
5201                  p_assignment_id        => p_assignment_id
5202                 ,p_effective_date       => l_effective_date
5203                 ,p_state_code           => l_csr_state_code
5204                 ,p_county_code          => l_csr_county_code
5205                 ,p_city_code            => l_csr_city_code
5206                 ,p_percentage           => l_city_pct
5207                 ,p_datetrack_mode       => p_datetrack_mode
5208                 ,p_effective_start_date => l_pct_eff_start_date
5209                 ,p_effective_end_date   => l_pct_eff_end_date
5210                 ,p_calculate_pct        => FALSE
5211                 );
5212   end loop;
5213   close csr_asg_city_code;
5214   --
5215   open csr_asg_county_code;
5216   loop
5217     fetch csr_asg_county_code into l_csr_state_code, l_csr_county_code;
5218     exit when csr_asg_county_code%notfound;
5219     l_pct_eff_start_date := l_chg_effective_start_date;
5220     l_pct_eff_end_date := l_chg_effective_end_date;
5221     maintain_tax_percentage(
5222                  p_assignment_id        => p_assignment_id
5223                 ,p_effective_date       => l_effective_date
5224                 ,p_state_code           => l_csr_state_code
5225                 ,p_county_code          => l_csr_county_code
5226                 ,p_city_code            => '0000'
5227                 ,p_percentage           => 0
5228                 ,p_datetrack_mode       => p_datetrack_mode
5229                 ,p_effective_start_date => l_pct_eff_start_date
5230                 ,p_effective_end_date   => l_pct_eff_end_date
5231                 ,p_calculate_pct        => FALSE
5232                 );
5233   end loop;
5234   close csr_asg_county_code;
5235   --
5236   open csr_asg_state_code;
5237   loop
5238     fetch csr_asg_state_code into l_csr_state_code;
5239     exit when csr_asg_state_code%notfound;
5240     l_pct_eff_start_date := l_chg_effective_start_date;
5241     l_pct_eff_end_date := l_chg_effective_end_date;
5242     maintain_tax_percentage(
5243                  p_assignment_id        => p_assignment_id
5244                 ,p_effective_date       => l_effective_date
5245                 ,p_state_code           => l_csr_state_code
5246                 ,p_county_code          => '000'
5247                 ,p_city_code            => '0000'
5248                 ,p_percentage           => 0
5249                 ,p_datetrack_mode       => p_datetrack_mode
5250                 ,p_effective_start_date => l_pct_eff_start_date
5251                 ,p_effective_end_date   => l_pct_eff_end_date
5252                 ,p_calculate_pct        => FALSE
5253                 );
5254   end loop;
5255   close csr_asg_state_code;
5256   --
5257   -- Create new tax rules if they do not already exist.
5258   -- first for the mailing address
5259   create_tax_rules_for_jd(p_state_code 	=> l_loc_state_code,
5260 			p_county_code 	=> l_loc_county_code,
5261 			p_city_code 	=> l_loc_city_code,
5262 			p_effective_date => l_effective_date,
5263 			p_assignment_id => p_assignment_id
5264 			);
5265 
5266   -- last for the taxation address
5267   create_tax_rules_for_jd(p_state_code 	=> l_loc_ovrd_state_code,
5268 			p_county_code 	=> l_loc_ovrd_county_code,
5269 			p_city_code 	=> l_loc_ovrd_city_code,
5270 			p_effective_date => l_effective_date,
5271 			p_assignment_id => p_assignment_id
5272 			);
5273 
5274 
5275   --
5276   hr_utility.set_location(' Leaving:'||l_proc, 130);
5277   --
5278 exception
5279   --
5280   -- This is called when location_change runs but the new location is the
5281   -- same as the existing location
5282   --
5283   when l_exit_quietly then
5284      null;
5285 end location_change;
5286 
5287 -- ----------------------------------------------------------------------------
5288 -- |-------------------------< move_tax_default_date >------------------------|
5289 -- ----------------------------------------------------------------------------
5290 procedure move_tax_default_date
5291     (p_effective_date               In      date
5292     ,p_datetrack_mode               In      varchar2
5293     ,p_assignment_id                In      number
5294     ,p_new_location_id              In      number     default null
5295     ,p_new_hire_date                In      date       default null
5296   ) is
5297   --
5298   -- Declare cursors and local variables
5299   --
5300   l_proc                     varchar2(72) := g_package||'move_tax_default_date';
5301   l_effective_date              date;
5302   l_new_hire_date               date;
5303   l_tmp_loc_id			hr_locations.location_id%TYPE;
5304   l_new_location_id		hr_locations.location_id%TYPE;
5305   l_temp_char                   varchar2(10);
5306   l_tmp_effective_start_date
5307                            pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
5308   l_tmp_effective_end_date   pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
5309   l_tmp_object_version_number
5310                           pay_us_emp_fed_tax_rules_f.object_version_number%TYPE;
5311   l_emp_fed_tax_rule_id     pay_us_emp_fed_tax_rules_f.emp_fed_tax_rule_id%TYPE;
5312   l_new_default_date       pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
5313   l_defaulting_date        pay_us_emp_fed_tax_rules_f.effective_start_date%TYPE;
5314   l_fed_eed                  pay_us_emp_fed_tax_rules_f.effective_end_date%TYPE;
5315   l_default_flag                varchar2(1) := 'Y';
5316   l_defaulting_met              boolean;
5317   l_asg_eed                     per_assignments_f.effective_end_date%TYPE;
5318   l_asg_esd                     per_assignments_f.effective_start_date%TYPE;
5319   l_loc_state_code              pay_us_states.state_code%TYPE;
5320   l_loc_county_code             pay_us_counties.county_code%TYPE;
5321   l_loc_city_code               pay_us_city_names.city_code%TYPE;
5322   l_loc_ovrd_state_code		pay_us_states.state_code%TYPE;
5323   l_loc_ovrd_county_code        pay_us_counties.county_code%TYPE;
5324   l_loc_ovrd_city_code          pay_us_city_names.city_code%TYPE;
5325   l_state_code                  pay_us_emp_state_tax_rules_f.state_code%TYPE;
5326   l_county_code                 pay_us_emp_county_tax_rules_f.county_code%TYPE;
5327   l_city_code                   pay_us_emp_city_tax_rules_f.city_code%TYPE;
5328   l_city_pct                    number;
5329   --
5330   l_fed_rec                     pay_fed_shd.g_rec_type;
5331   l_fed_rec_dup                 pay_fed_shd.g_rec_type;
5332   l_state_rec                   pay_sta_shd.g_rec_type;
5333   l_state_rec_dup               pay_sta_shd.g_rec_type;
5334   l_county_rec                  pay_cnt_shd.g_rec_type;
5335   l_county_rec_dup              pay_cnt_shd.g_rec_type;
5336   l_city_rec                    pay_cty_shd.g_rec_type;
5337   l_city_rec_dup                pay_cty_shd.g_rec_type;
5338   l_exists                      varchar2(1);
5339   --
5340   l_exit_quietly                exception;
5341   --
5342   cursor csr_check_payroll(p_csr_date1 date, p_csr_date2 date) is
5343       select null
5344       from  per_assignments_f paf
5345            ,pay_payroll_actions ppa
5346            ,pay_assignment_actions paa
5347            ,pay_run_results prr
5348       where  paf.assignment_id = p_assignment_id
5349       and    ((paf.effective_start_date <= p_csr_date1
5350              and paf.effective_end_date >= p_csr_date1)
5351       OR    (paf.effective_start_date between p_csr_date1 and p_csr_date2 ) )
5352       and    ppa.payroll_id = paf.payroll_id
5353       and    ppa.action_type in ('Q','R')
5354       and    ppa.date_earned between p_csr_date1 and p_csr_date2
5355       and    ppa.payroll_action_id = paa.payroll_action_id
5356       and    paa.assignment_id =  paf.assignment_id
5357       and    paa.assignment_action_id = prr.assignment_action_id ;
5358 --
5359   cursor csr_fed_tax_rule is
5360     select min(effective_start_date), min(effective_end_date),
5361            emp_fed_tax_rule_id
5362     from   pay_us_emp_fed_tax_rules_f
5363     where  assignment_id = p_assignment_id
5364     group by emp_fed_tax_rule_id;
5365   --
5366   cursor csr_asg_data(p_csr_asg_id number, p_csr_eff_date date) is
5367     select asg.effective_start_date, asg.effective_end_date
5368     from   per_assignments_f asg
5369     where  asg.assignment_id = p_csr_asg_id
5370     and    p_csr_eff_date between asg.effective_start_date
5371            and asg.effective_end_date;
5372   --
5373   cursor csr_assignment_id is
5374     select null
5375     from   per_assignments_f asg
5376     where  asg.assignment_id = p_assignment_id;
5377   --
5378   -- reimp - added cursor to get current location id
5379   --	     since it is not passed in if it is unchanged
5380 
5381   cursor csr_asg_loc_id(p_date date) is
5382     select location_id
5383     from   per_assignments_f asg
5384     where  asg.assignment_id = p_assignment_id
5385       and  p_date between asg.effective_start_date and asg.effective_end_date;
5386   --
5387   cursor csr_future_fed_rule(l_csr_date date default hr_api.g_date) is
5388     select null
5389     from   pay_us_emp_fed_tax_rules_f fed
5390     where  fed.assignment_id = p_assignment_id
5391     and    fed.effective_start_date > l_csr_date;
5392   --
5393   cursor csr_fed_rec(l_csr_assignment_id number
5394                     ,l_csr_effective_date date) is
5395      select emp_fed_tax_rule_id
5396            ,effective_start_date
5397            ,effective_end_date
5398            ,assignment_id
5399            ,sui_state_code
5400            ,sui_jurisdiction_code
5401            ,business_group_id
5402            ,additional_wa_amount
5403            ,filing_status_code
5404            ,fit_override_amount
5405            ,fit_override_rate
5406            ,withholding_allowances
5407            ,cumulative_taxation
5408            ,eic_filing_status_code
5409            ,fit_additional_tax
5410            ,fit_exempt
5411            ,futa_tax_exempt
5412            ,medicare_tax_exempt
5413            ,ss_tax_exempt
5414            ,wage_exempt
5415            ,statutory_employee
5416            ,w2_filed_year
5417            ,supp_tax_override_rate
5418            ,excessive_wa_reject_date
5419            ,object_version_number
5420            ,attribute_category
5421            ,attribute1
5422            ,attribute2
5423            ,attribute3
5424            ,attribute4
5425            ,attribute5
5426            ,attribute6
5427            ,attribute7
5428            ,attribute8
5429            ,attribute9
5430            ,attribute10
5431            ,attribute11
5432            ,attribute12
5433            ,attribute13
5434            ,attribute14
5435            ,attribute15
5436            ,attribute16
5437            ,attribute17
5438            ,attribute18
5439            ,attribute19
5440            ,attribute20
5441            ,attribute21
5442            ,attribute22
5443            ,attribute23
5444            ,attribute24
5445            ,attribute25
5446            ,attribute26
5447            ,attribute27
5448            ,attribute28
5449            ,attribute29
5450            ,attribute30
5451            ,fed_information_category
5452            ,fed_information1
5453            ,fed_information2
5454            ,fed_information3
5455            ,fed_information4
5456            ,fed_information5
5457            ,fed_information6
5458            ,fed_information7
5459            ,fed_information8
5460            ,fed_information9
5461            ,fed_information10
5462            ,fed_information11
5463            ,fed_information12
5464            ,fed_information13
5465            ,fed_information14
5466            ,fed_information15
5467            ,fed_information16
5468            ,fed_information17
5469            ,fed_information18
5470            ,fed_information19
5471            ,fed_information20
5472            ,fed_information21
5473            ,fed_information22
5474            ,fed_information23
5475            ,fed_information24
5476            ,fed_information25
5477            ,fed_information26
5478            ,fed_information27
5479            ,fed_information28
5480            ,fed_information29
5481            ,fed_information30
5482      from   pay_us_emp_fed_tax_rules_f
5483      where  assignment_id = l_csr_assignment_id
5484      and    l_csr_effective_date between effective_start_date
5485                                  and effective_end_date;
5486   --
5487   cursor csr_fed_rows(l_csr_assignment_id number
5488                      ,l_csr_effective_date date) is
5489      select emp_fed_tax_rule_id
5490            ,effective_start_date
5491            ,effective_end_date
5492            ,assignment_id
5493            ,sui_state_code
5494            ,sui_jurisdiction_code
5495            ,business_group_id
5496            ,additional_wa_amount
5497            ,filing_status_code
5498            ,fit_override_amount
5499            ,fit_override_rate
5500            ,withholding_allowances
5501            ,cumulative_taxation
5502            ,eic_filing_status_code
5503            ,fit_additional_tax
5504            ,fit_exempt
5505            ,futa_tax_exempt
5506            ,medicare_tax_exempt
5507            ,ss_tax_exempt
5508            ,wage_exempt
5509            ,statutory_employee
5510            ,w2_filed_year
5511            ,supp_tax_override_rate
5512            ,excessive_wa_reject_date
5513            ,object_version_number
5514            ,attribute_category
5515            ,attribute1
5516            ,attribute2
5517            ,attribute3
5518            ,attribute4
5519            ,attribute5
5520            ,attribute6
5521            ,attribute7
5522            ,attribute8
5523            ,attribute9
5524            ,attribute10
5525            ,attribute11
5526            ,attribute12
5527            ,attribute13
5528            ,attribute14
5529            ,attribute15
5530            ,attribute16
5531            ,attribute17
5532            ,attribute18
5533            ,attribute19
5534            ,attribute20
5535            ,attribute21
5536            ,attribute22
5537            ,attribute23
5538            ,attribute24
5539            ,attribute25
5540            ,attribute26
5541            ,attribute27
5542            ,attribute28
5543            ,attribute29
5544            ,attribute30
5545            ,fed_information_category
5546            ,fed_information1
5547            ,fed_information2
5548            ,fed_information3
5549            ,fed_information4
5550            ,fed_information5
5551            ,fed_information6
5552            ,fed_information7
5553            ,fed_information8
5554            ,fed_information9
5555            ,fed_information10
5556            ,fed_information11
5557            ,fed_information12
5558            ,fed_information13
5559            ,fed_information14
5560            ,fed_information15
5561            ,fed_information16
5562            ,fed_information17
5563            ,fed_information18
5564            ,fed_information19
5565            ,fed_information20
5566            ,fed_information21
5567            ,fed_information22
5568            ,fed_information23
5569            ,fed_information24
5570            ,fed_information25
5571            ,fed_information26
5572            ,fed_information27
5573            ,fed_information28
5574            ,fed_information29
5575            ,fed_information30
5576      from   pay_us_emp_fed_tax_rules_f
5577      where  assignment_id = l_csr_assignment_id
5578      and    l_csr_effective_date <= effective_end_date
5579      order by effective_start_date;
5580   --
5581   cursor csr_state_rec(l_csr_assignment_id number
5582                       ,l_csr_effective_date date) is
5583     select emp_state_tax_rule_id
5584           ,effective_start_date
5585           ,effective_end_date
5586           ,assignment_id
5587           ,state_code
5588           ,jurisdiction_code
5589           ,business_group_id
5590           ,additional_wa_amount
5591           ,filing_status_code
5592           ,remainder_percent
5593           ,secondary_wa
5594           ,sit_additional_tax
5595           ,sit_override_amount
5596           ,sit_override_rate
5597           ,withholding_allowances
5598           ,excessive_wa_reject_date
5599           ,sdi_exempt
5600           ,sit_exempt
5601           ,sit_optional_calc_ind
5602           ,state_non_resident_cert
5603           ,sui_exempt
5604           ,wc_exempt
5605           ,wage_exempt
5606           ,sui_wage_base_override_amount
5607           ,supp_tax_override_rate
5608           ,object_version_number
5609            ,attribute_category
5610            ,attribute1
5611            ,attribute2
5612            ,attribute3
5613            ,attribute4
5614            ,attribute5
5615            ,attribute6
5616            ,attribute7
5617            ,attribute8
5618            ,attribute9
5619            ,attribute10
5620            ,attribute11
5621            ,attribute12
5622            ,attribute13
5623            ,attribute14
5624            ,attribute15
5625            ,attribute16
5626            ,attribute17
5627            ,attribute18
5628            ,attribute19
5629            ,attribute20
5630            ,attribute21
5631            ,attribute22
5632            ,attribute23
5633            ,attribute24
5634            ,attribute25
5635            ,attribute26
5636            ,attribute27
5637            ,attribute28
5638            ,attribute29
5639            ,attribute30
5640            ,sta_information_category
5641            ,sta_information1
5642            ,sta_information2
5643            ,sta_information3
5644            ,sta_information4
5645            ,sta_information5
5646            ,sta_information6
5647            ,sta_information7
5648            ,sta_information8
5649            ,sta_information9
5650            ,sta_information10
5651            ,sta_information11
5652            ,sta_information12
5653            ,sta_information13
5654            ,sta_information14
5655            ,sta_information15
5656            ,sta_information16
5657            ,sta_information17
5658            ,sta_information18
5659            ,sta_information19
5660            ,sta_information20
5661            ,sta_information21
5662            ,sta_information22
5663            ,sta_information23
5664            ,sta_information24
5665            ,sta_information25
5666            ,sta_information26
5667            ,sta_information27
5668            ,sta_information28
5669            ,sta_information29
5670            ,sta_information30
5671      from  pay_us_emp_state_tax_rules_f
5672      where assignment_id = l_csr_assignment_id
5673      and   l_csr_effective_date between effective_start_date
5674                                 and effective_end_date;
5675   --
5676   cursor csr_county_rec(l_csr_assignment_id number
5677                        ,l_csr_effective_date date) is
5678     select emp_county_tax_rule_id
5679           ,effective_start_date
5680           ,effective_end_date
5681           ,assignment_id
5682           ,state_code
5683           ,county_code
5684           ,business_group_id
5685           ,additional_wa_rate
5686           ,filing_status_code
5687           ,jurisdiction_code
5688           ,lit_additional_tax
5689           ,lit_override_amount
5690           ,lit_override_rate
5691           ,withholding_allowances
5692           ,lit_exempt
5693           ,sd_exempt
5694           ,ht_exempt
5695           ,wage_exempt
5696           ,school_district_code
5697           ,object_version_number
5698            ,attribute_category
5699            ,attribute1
5700            ,attribute2
5701            ,attribute3
5702            ,attribute4
5703            ,attribute5
5704            ,attribute6
5705            ,attribute7
5706            ,attribute8
5707            ,attribute9
5708            ,attribute10
5709            ,attribute11
5710            ,attribute12
5711            ,attribute13
5712            ,attribute14
5713            ,attribute15
5714            ,attribute16
5715            ,attribute17
5716            ,attribute18
5717            ,attribute19
5718            ,attribute20
5719            ,attribute21
5720            ,attribute22
5721            ,attribute23
5722            ,attribute24
5723            ,attribute25
5724            ,attribute26
5725            ,attribute27
5726            ,attribute28
5727            ,attribute29
5728            ,attribute30
5729            ,cnt_information_category
5730            ,cnt_information1
5731            ,cnt_information2
5732            ,cnt_information3
5733            ,cnt_information4
5734            ,cnt_information5
5735            ,cnt_information6
5736            ,cnt_information7
5737            ,cnt_information8
5738            ,cnt_information9
5739            ,cnt_information10
5740            ,cnt_information11
5741            ,cnt_information12
5742            ,cnt_information13
5743            ,cnt_information14
5744            ,cnt_information15
5745            ,cnt_information16
5746            ,cnt_information17
5747            ,cnt_information18
5748            ,cnt_information19
5749            ,cnt_information20
5750            ,cnt_information21
5751            ,cnt_information22
5752            ,cnt_information23
5753            ,cnt_information24
5754            ,cnt_information25
5755            ,cnt_information26
5756            ,cnt_information27
5757            ,cnt_information28
5758            ,cnt_information29
5759            ,cnt_information30
5760      from   pay_us_emp_county_tax_rules_f
5761      where assignment_id = l_csr_assignment_id
5762      and   l_csr_effective_date between effective_start_date
5763                                 and effective_end_date;
5764   --
5765   cursor csr_city_rec(l_csr_assignment_id number
5766                      ,l_csr_effective_date date) is
5767     select emp_city_tax_rule_id
5768           ,effective_start_date
5769           ,effective_end_date
5770           ,assignment_id
5771           ,state_code
5772           ,county_code
5773           ,city_code
5774           ,business_group_id
5775           ,additional_wa_rate
5776           ,filing_status_code
5777           ,jurisdiction_code
5778           ,lit_additional_tax
5779           ,lit_override_amount
5780           ,lit_override_rate
5781           ,withholding_allowances
5782           ,lit_exempt
5783           ,sd_exempt
5784           ,ht_exempt
5785           ,wage_exempt
5786           ,school_district_code
5787           ,object_version_number
5788            ,attribute_category
5789            ,attribute1
5790            ,attribute2
5791            ,attribute3
5792            ,attribute4
5793            ,attribute5
5794            ,attribute6
5795            ,attribute7
5796            ,attribute8
5797            ,attribute9
5798            ,attribute10
5799            ,attribute11
5800            ,attribute12
5801            ,attribute13
5802            ,attribute14
5803            ,attribute15
5804            ,attribute16
5805            ,attribute17
5806            ,attribute18
5807            ,attribute19
5808            ,attribute20
5809            ,attribute21
5810            ,attribute22
5811            ,attribute23
5812            ,attribute24
5813            ,attribute25
5814            ,attribute26
5815            ,attribute27
5816            ,attribute28
5817            ,attribute29
5818            ,attribute30
5819            ,cty_information_category
5820            ,cty_information1
5821            ,cty_information2
5822            ,cty_information3
5823            ,cty_information4
5824            ,cty_information5
5825            ,cty_information6
5826            ,cty_information7
5827            ,cty_information8
5828            ,cty_information9
5829            ,cty_information10
5830            ,cty_information11
5831            ,cty_information12
5832            ,cty_information13
5833            ,cty_information14
5834            ,cty_information15
5835            ,cty_information16
5836            ,cty_information17
5837            ,cty_information18
5838            ,cty_information19
5839            ,cty_information20
5840            ,cty_information21
5841            ,cty_information22
5842            ,cty_information23
5843            ,cty_information24
5844            ,cty_information25
5845            ,cty_information26
5846            ,cty_information27
5847            ,cty_information28
5848            ,cty_information29
5849            ,cty_information30
5850     from   pay_us_emp_city_tax_rules_f
5851      where assignment_id = l_csr_assignment_id
5852      and   l_csr_effective_date between effective_start_date
5853                                 and effective_end_date;
5854   --
5855   --
5856   procedure pull_back_taxes(p_assignment_id       in number
5857                            ,p_emp_fed_tax_rule_id in number
5858                            ,p_fed_eed             in date
5859                            ,p_new_default_date    in date
5860                            ,p_defaulting_date     in date
5861                            ) is
5862     l_tmp_esd        date;
5863     l_tmp_eed        date;
5864     l_state_rec      pay_sta_shd.g_rec_type;
5865     l_county_rec     pay_cnt_shd.g_rec_type;
5866     l_city_rec       pay_cty_shd.g_rec_type;
5867 
5868     begin
5869         update pay_us_emp_fed_tax_rules_f
5870         set    effective_start_date = p_new_default_date
5871         where  assignment_id = p_assignment_id
5872         and    effective_start_date = p_defaulting_date;
5873         --
5874         maintain_wc(
5875                   p_emp_fed_tax_rule_id   => p_emp_fed_tax_rule_id
5876                  ,p_effective_start_date  => p_defaulting_date
5877                  ,p_effective_end_date    => p_fed_eed
5878                  ,p_effective_date        => p_new_default_date
5879                  ,p_datetrack_mode        => 'INSERT_OVERRIDE'
5880                  );
5881         --
5882         for l_state_rec in csr_state_rec(p_assignment_id, p_defaulting_date)
5883         loop
5884           --
5885           update pay_us_emp_state_tax_rules_f
5886           set    effective_start_date = p_new_default_date
5887           where  effective_start_date = p_defaulting_date
5888           and    assignment_id = p_assignment_id
5889           and    state_code = l_state_rec.state_code;
5890           --
5891           l_tmp_esd  := p_defaulting_date;
5892           l_tmp_eed  := p_fed_eed;
5893           maintain_tax_percentage(
5894                       p_assignment_id        => p_assignment_id
5895                      ,p_effective_date       => p_new_default_date
5896                      ,p_state_code           => l_state_rec.state_code
5897                      ,p_county_code          => '000'
5898                      ,p_city_code            => '0000'
5899                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
5900                      ,p_effective_start_date => l_tmp_esd
5901                      ,p_effective_end_date   => l_tmp_eed
5902                      ,p_calculate_pct        => FALSE
5903                      );
5904         end loop;        -- l_state_rec
5905         --
5906         for l_county_rec in csr_county_rec(p_assignment_id, p_defaulting_date)
5907         loop
5908           --
5909           update pay_us_emp_county_tax_rules_f
5910           set    effective_start_date = p_new_default_date
5911           where  effective_start_date = p_defaulting_date
5912           and    assignment_id = p_assignment_id
5913           and    state_code = l_county_rec.state_code
5914           and    county_code = l_county_rec.county_code;
5915           --
5916           l_tmp_esd  := p_defaulting_date;
5917           l_tmp_eed  := p_fed_eed;
5918           maintain_tax_percentage(
5919                       p_assignment_id        => p_assignment_id
5920                      ,p_effective_date       => p_new_default_date
5921                      ,p_state_code           => l_county_rec.state_code
5922                      ,p_county_code          => l_county_rec.county_code
5923                      ,p_city_code            => '0000'
5924                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
5925                      ,p_effective_start_date => l_tmp_esd
5926                      ,p_effective_end_date   => l_tmp_eed
5927                      ,p_calculate_pct        => FALSE
5928                      );
5929         end loop;        -- l_county_rec
5930         --
5931         for l_city_rec in csr_city_rec(p_assignment_id, p_defaulting_date)
5932         loop
5933           --
5934           update pay_us_emp_city_tax_rules_f
5935           set    effective_start_date = p_new_default_date
5936           where  effective_start_date = p_defaulting_date
5937           and    assignment_id = p_assignment_id
5938           and    state_code = l_city_rec.state_code
5939           and    county_code = l_city_rec.county_code
5940           and    city_code = l_city_rec.city_code;
5941           --
5942           l_tmp_esd  := p_defaulting_date;
5943           l_tmp_eed  := p_fed_eed;
5944           maintain_tax_percentage(
5945                       p_assignment_id        => p_assignment_id
5946                      ,p_effective_date       => p_new_default_date
5947                      ,p_state_code           => l_city_rec.state_code
5948                      ,p_county_code          => l_city_rec.county_code
5949                      ,p_city_code            => l_city_rec.city_code
5950                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
5951                      ,p_effective_start_date => l_tmp_esd
5952                      ,p_effective_end_date   => l_tmp_eed
5953                      ,p_calculate_pct        => FALSE
5954                      );
5955           --
5956         end loop;        -- l_city_rec
5957         --
5958     end pull_back_taxes;
5959   --
5960   --
5961   procedure reset_element_entries(p_assignment_id       in number
5962                                  ,p_emp_fed_tax_rule_id in number
5963                                  ,p_fed_eed             in date
5964                                  ,p_defaulting_date     in date
5965                                  ) is
5966     l_tmp_esd        date;
5967     l_tmp_eed        date;
5968     l_state_rec      pay_sta_shd.g_rec_type;
5969     l_county_rec     pay_cnt_shd.g_rec_type;
5970     l_city_rec       pay_cty_shd.g_rec_type;
5971 
5972     begin
5973         maintain_wc(
5974                   p_emp_fed_tax_rule_id   => p_emp_fed_tax_rule_id
5975                  ,p_effective_start_date  => p_defaulting_date
5976                  ,p_effective_end_date    => p_fed_eed
5977                  ,p_effective_date        => p_defaulting_date
5978                  ,p_datetrack_mode        => 'INSERT_OVERRIDE'
5979                  );
5980         --
5981         for l_state_rec in csr_state_rec(p_assignment_id, p_defaulting_date)
5982         loop
5983           --
5984           l_tmp_esd := p_defaulting_date;
5985           l_tmp_eed := p_fed_eed;
5986           maintain_tax_percentage(
5987                       p_assignment_id        => p_assignment_id
5988                      ,p_effective_date       => p_defaulting_date
5989                      ,p_state_code           => l_state_rec.state_code
5990                      ,p_county_code          => '000'
5991                      ,p_city_code            => '0000'
5992                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
5993                      ,p_effective_start_date => l_tmp_esd
5994                      ,p_effective_end_date   => l_tmp_eed
5995                      ,p_calculate_pct        => FALSE
5996                      );
5997           --
5998         end loop;        -- l_state_rec
5999         --
6000         for l_county_rec in csr_county_rec(p_assignment_id, p_defaulting_date)
6001         loop
6002           --
6003           l_tmp_esd  := p_defaulting_date;
6004           l_tmp_eed  := p_fed_eed;
6005           maintain_tax_percentage(
6006                       p_assignment_id        => p_assignment_id
6007                      ,p_effective_date       => p_defaulting_date
6008                      ,p_state_code           => l_county_rec.state_code
6009                      ,p_county_code          => l_county_rec.county_code
6010                      ,p_city_code            => '0000'
6011                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6012                      ,p_effective_start_date => l_tmp_esd
6013                      ,p_effective_end_date   => l_tmp_eed
6014                      ,p_calculate_pct        => FALSE
6015                      );
6016           --
6017         end loop;        -- l_county_rec
6018         --
6019         for l_city_rec in csr_city_rec(p_assignment_id, p_defaulting_date)
6020         loop
6021           --
6022           l_tmp_esd  := p_defaulting_date;
6023           l_tmp_eed  := p_fed_eed;
6024           maintain_tax_percentage(
6025                       p_assignment_id        => p_assignment_id
6026                      ,p_effective_date       => p_defaulting_date
6027                      ,p_state_code           => l_city_rec.state_code
6028                      ,p_county_code          => l_city_rec.county_code
6029                      ,p_city_code            => l_city_rec.city_code
6030                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6031                      ,p_effective_start_date => l_tmp_esd
6032                      ,p_effective_end_date   => l_tmp_eed
6033                      ,p_calculate_pct        => FALSE
6034                      );
6035           --
6036         end loop;        -- l_city_rec
6037         --
6038     end reset_element_entries;
6039   --
6040   --
6041   procedure push_forward_taxes(p_assignment_id       in number
6042                               ,p_fed_eed             in date
6043                               ,p_new_default_date    in date
6044                               ,p_defaulting_date     in date
6045                               ) is
6046     l_tmp_esd        date;
6047     l_tmp_eed        date;
6048     l_fed_rec                     pay_fed_shd.g_rec_type;
6049     l_fed_rec_dup                 pay_fed_shd.g_rec_type;
6050     l_state_rec                   pay_sta_shd.g_rec_type;
6051     l_state_rec_dup               pay_sta_shd.g_rec_type;
6052     l_county_rec                  pay_cnt_shd.g_rec_type;
6053     l_county_rec_dup              pay_cnt_shd.g_rec_type;
6054     l_city_rec                    pay_cty_shd.g_rec_type;
6055     l_city_rec_dup                pay_cty_shd.g_rec_type;
6056     l_exists                      varchar2(1);
6057 
6058     begin
6059       --
6060       -- Moving taxes forward involves removing part of the tax records.  This
6061       -- call checks if payroll has been run for this assignment
6062       --
6063       open csr_check_payroll(p_defaulting_date, p_new_default_date);
6064       fetch csr_check_payroll into l_exists;
6065       if csr_check_payroll%FOUND then
6066         hr_utility.set_location(l_proc,15);
6067         close csr_check_payroll;
6068         hr_utility.set_message(801, 'PAY_52235_TAX_RULE_DELETE');
6069         hr_utility.raise_error;
6070       end if;
6071       close csr_check_payroll;
6072       --
6073       -- Create a break in the federal tax rule at the new defaulting date, then
6074       -- delete any federal tax rules that begin before the new defaulting date.
6075       -- The same is done for the other tax rules, the tax percentages, and the
6076       -- workers compensation entry.
6077       --
6078       open csr_fed_rec(p_assignment_id, p_new_default_date);
6079       fetch csr_fed_rec into l_fed_rec;
6080 
6081 /* changes for bug 1970341 possible a DB issue. */
6082 --      l_fed_rec_dup := l_fed_rec;
6083 
6084       l_fed_rec_dup.emp_fed_tax_rule_id       := l_fed_rec.emp_fed_tax_rule_id;
6085       l_fed_rec_dup.effective_start_date      := l_fed_rec.effective_start_date;
6086       l_fed_rec_dup.effective_end_date        := l_fed_rec.effective_end_date;
6087       l_fed_rec_dup.assignment_id             := l_fed_rec.assignment_id;
6088       l_fed_rec_dup.sui_state_code            := l_fed_rec.sui_state_code;
6089       l_fed_rec_dup.sui_jurisdiction_code     := l_fed_rec.sui_jurisdiction_code ;
6090       l_fed_rec_dup.business_group_id         := l_fed_rec.business_group_id;
6091       l_fed_rec_dup.additional_wa_amount      := l_fed_rec.additional_wa_amount;
6092       l_fed_rec_dup.filing_status_code        := l_fed_rec.filing_status_code;
6093       l_fed_rec_dup.fit_override_amount       := l_fed_rec.fit_override_amount;
6094       l_fed_rec_dup.fit_override_rate         := l_fed_rec.fit_override_rate;
6095       l_fed_rec_dup.withholding_allowances    := l_fed_rec.withholding_allowances;
6096       l_fed_rec_dup.cumulative_taxation       := l_fed_rec.cumulative_taxation;
6097       l_fed_rec_dup.eic_filing_status_code    := l_fed_rec.eic_filing_status_code;
6098       l_fed_rec_dup.fit_additional_tax        := l_fed_rec.fit_additional_tax;
6099       l_fed_rec_dup.fit_exempt                := l_fed_rec.fit_exempt;
6100       l_fed_rec_dup.futa_tax_exempt           := l_fed_rec.futa_tax_exempt;
6101       l_fed_rec_dup.medicare_tax_exempt       := l_fed_rec.medicare_tax_exempt;
6102       l_fed_rec_dup.ss_tax_exempt             := l_fed_rec.ss_tax_exempt;
6103       l_fed_rec_dup.wage_exempt               := l_fed_rec.wage_exempt;
6104       l_fed_rec_dup.statutory_employee        := l_fed_rec.statutory_employee;
6105       l_fed_rec_dup.w2_filed_year             := l_fed_rec.w2_filed_year;
6106       l_fed_rec_dup.supp_tax_override_rate    := l_fed_rec.supp_tax_override_rate;
6107       l_fed_rec_dup.excessive_wa_reject_date  := l_fed_rec.excessive_wa_reject_date;
6108       l_fed_rec_dup.object_version_number     := l_fed_rec.object_version_number ;
6109       l_fed_rec_dup.attribute_category        := l_fed_rec.attribute_category;
6110       l_fed_rec_dup.attribute1                := l_fed_rec.attribute1;
6111       l_fed_rec_dup.attribute2                := l_fed_rec.attribute2;
6112       l_fed_rec_dup.attribute3                := l_fed_rec.attribute3;
6113       l_fed_rec_dup.attribute4                := l_fed_rec.attribute4;
6114       l_fed_rec_dup.attribute5                := l_fed_rec.attribute5;
6115       l_fed_rec_dup.attribute6                := l_fed_rec.attribute6;
6116       l_fed_rec_dup.attribute7                := l_fed_rec.attribute7;
6117       l_fed_rec_dup.attribute8                := l_fed_rec.attribute8;
6118       l_fed_rec_dup.attribute9                := l_fed_rec.attribute9;
6119       l_fed_rec_dup.attribute10               := l_fed_rec.attribute10;
6120       l_fed_rec_dup.attribute11               := l_fed_rec.attribute11;
6121       l_fed_rec_dup.attribute12               := l_fed_rec.attribute12;
6122       l_fed_rec_dup.attribute13               := l_fed_rec.attribute13;
6123       l_fed_rec_dup.attribute14               := l_fed_rec.attribute14;
6124       l_fed_rec_dup.attribute15               := l_fed_rec.attribute15;
6125       l_fed_rec_dup.attribute16               := l_fed_rec.attribute16;
6126       l_fed_rec_dup.attribute17               := l_fed_rec.attribute17;
6127       l_fed_rec_dup.attribute18               := l_fed_rec.attribute18;
6128       l_fed_rec_dup.attribute19               := l_fed_rec.attribute19;
6129       l_fed_rec_dup.attribute20               := l_fed_rec.attribute20;
6130       l_fed_rec_dup.attribute21               := l_fed_rec.attribute21;
6131       l_fed_rec_dup.attribute22               := l_fed_rec.attribute22;
6132       l_fed_rec_dup.attribute23               := l_fed_rec.attribute23;
6133       l_fed_rec_dup.attribute24               := l_fed_rec.attribute24;
6134       l_fed_rec_dup.attribute25               := l_fed_rec.attribute25;
6135       l_fed_rec_dup.attribute26               := l_fed_rec.attribute26;
6136       l_fed_rec_dup.attribute27               := l_fed_rec.attribute27;
6137       l_fed_rec_dup.attribute28               := l_fed_rec.attribute28;
6138       l_fed_rec_dup.attribute29               := l_fed_rec.attribute29;
6139       l_fed_rec_dup.attribute30               := l_fed_rec.attribute30;
6140       l_fed_rec_dup.fed_information_category  := l_fed_rec.fed_information_category;
6141       l_fed_rec_dup.fed_information1          := l_fed_rec.fed_information1;
6142       l_fed_rec_dup.fed_information2          := l_fed_rec.fed_information2;
6143       l_fed_rec_dup.fed_information3          := l_fed_rec.fed_information3;
6144       l_fed_rec_dup.fed_information4          := l_fed_rec.fed_information4;
6145       l_fed_rec_dup.fed_information5          := l_fed_rec.fed_information5;
6146       l_fed_rec_dup.fed_information6          := l_fed_rec.fed_information6;
6147       l_fed_rec_dup.fed_information7          := l_fed_rec.fed_information7;
6148       l_fed_rec_dup.fed_information8          := l_fed_rec.fed_information8;
6149       l_fed_rec_dup.fed_information9          := l_fed_rec.fed_information9;
6150       l_fed_rec_dup.fed_information10         := l_fed_rec.fed_information10;
6151       l_fed_rec_dup.fed_information11         := l_fed_rec.fed_information11;
6152       l_fed_rec_dup.fed_information12         := l_fed_rec.fed_information12;
6153       l_fed_rec_dup.fed_information13         := l_fed_rec.fed_information13;
6154       l_fed_rec_dup.fed_information14         := l_fed_rec.fed_information14;
6155       l_fed_rec_dup.fed_information15         := l_fed_rec.fed_information15;
6156       l_fed_rec_dup.fed_information16         := l_fed_rec.fed_information16;
6157       l_fed_rec_dup.fed_information17         := l_fed_rec.fed_information17;
6158       l_fed_rec_dup.fed_information18         := l_fed_rec.fed_information18;
6159       l_fed_rec_dup.fed_information19         := l_fed_rec.fed_information19;
6160       l_fed_rec_dup.fed_information20         := l_fed_rec.fed_information20;
6161       l_fed_rec_dup.fed_information21         := l_fed_rec.fed_information21;
6162       l_fed_rec_dup.fed_information22         := l_fed_rec.fed_information22;
6163       l_fed_rec_dup.fed_information23         := l_fed_rec.fed_information23;
6164       l_fed_rec_dup.fed_information24         := l_fed_rec.fed_information24;
6165       l_fed_rec_dup.fed_information25         := l_fed_rec.fed_information25;
6166       l_fed_rec_dup.fed_information26         := l_fed_rec.fed_information26;
6167       l_fed_rec_dup.fed_information27         := l_fed_rec.fed_information27;
6168       l_fed_rec_dup.fed_information28         := l_fed_rec.fed_information28;
6169       l_fed_rec_dup.fed_information29         := l_fed_rec.fed_information29;
6170       l_fed_rec_dup.fed_information30         := l_fed_rec.fed_information30;
6171 
6172 
6173 /* changes for bug 1970341 possible a DB issue. */
6174 
6175       if l_fed_rec_dup.effective_start_date <> p_new_default_date then
6176         open csr_future_fed_rule(l_fed_rec_dup.effective_end_date);
6177         fetch csr_future_fed_rule into l_temp_char;
6178         if csr_future_fed_rule%notfound then
6179           pay_fed_upd.upd(p_rec            => l_fed_rec_dup
6180                          ,p_effective_date => p_new_default_date
6181                          ,p_datetrack_mode => 'UPDATE');
6182         else
6183           pay_fed_upd.upd(p_rec            => l_fed_rec_dup
6184                          ,p_effective_date => p_new_default_date
6185                          ,p_datetrack_mode => 'UPDATE_CHANGE_INSERT');
6186         end if;
6187         close csr_future_fed_rule;
6188       end if;
6189       close csr_fed_rec;
6190 
6191       delete from pay_us_emp_fed_tax_rules_f
6192       where  assignment_id = p_assignment_id
6193       and    effective_start_date < p_new_default_date;
6194 
6195       maintain_wc(
6196                   p_emp_fed_tax_rule_id   => l_fed_rec.emp_fed_tax_rule_id
6197                  ,p_effective_start_date  => l_fed_rec.effective_start_date
6198                  ,p_effective_end_date    => l_fed_rec.effective_end_date
6199                  ,p_effective_date        => p_new_default_date
6200                  ,p_datetrack_mode        => 'INSERT_OVERRIDE'
6201                  );
6202       --
6203       for l_state_rec in csr_state_rec(p_assignment_id, p_new_default_date)
6204       loop
6205         l_state_rec_dup := l_state_rec;
6206         if l_state_rec_dup.effective_start_date <> p_new_default_date then
6207           open csr_future_state_rule(l_state_rec_dup.state_code,
6208 				     l_state_rec_dup.assignment_id,
6209 				     l_state_rec_dup.effective_end_date);
6210           fetch csr_future_state_rule into l_temp_char;
6211           if csr_future_state_rule%notfound then
6212             pay_sta_upd.upd(p_rec            => l_state_rec_dup
6213                            ,p_effective_date => p_new_default_date
6214                            ,p_datetrack_mode => 'UPDATE');
6215           else
6216             pay_sta_upd.upd(p_rec            => l_state_rec_dup
6217                            ,p_effective_date => p_new_default_date
6218                            ,p_datetrack_mode => 'UPDATE_CHANGE_INSERT');
6219           end if;
6220           close csr_future_state_rule;
6221         end if;
6222         --
6223         l_tmp_esd  := p_new_default_date;
6224         l_tmp_eed  := p_fed_eed;
6225         maintain_tax_percentage(
6226                       p_assignment_id        => p_assignment_id
6227                      ,p_effective_date       => p_new_default_date
6228                      ,p_state_code           => l_state_rec.state_code
6229                      ,p_county_code          => '000'
6230                      ,p_city_code            => '0000'
6231                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6232                      ,p_effective_start_date => l_tmp_esd
6233                      ,p_effective_end_date   => l_tmp_eed
6234                      ,p_calculate_pct        => FALSE
6235                      );
6236         --
6237       end loop;        -- l_state_rec
6238       --
6239       delete from pay_us_emp_state_tax_rules_f
6240       where  assignment_id = p_assignment_id
6241       and    effective_start_date < p_new_default_date;
6242       --
6243       for l_county_rec in csr_county_rec(p_assignment_id, p_new_default_date)
6244       loop
6245         l_county_rec_dup := l_county_rec;
6246         if l_county_rec_dup.effective_start_date <> p_new_default_date then
6247           open csr_future_county_rule(l_county_rec_dup.state_code,
6248 				      l_county_rec_dup.county_code,
6249 				      l_county_rec_dup.assignment_id,
6250 				      l_county_rec_dup.effective_end_date);
6251           fetch csr_future_county_rule into l_temp_char;
6252           if csr_future_county_rule%notfound then
6253             pay_cnt_upd.upd(p_rec            => l_county_rec_dup
6254                            ,p_effective_date => p_new_default_date
6255                            ,p_datetrack_mode => 'UPDATE');
6256           else
6257             pay_cnt_upd.upd(p_rec            => l_county_rec_dup
6258                            ,p_effective_date => p_new_default_date
6259                            ,p_datetrack_mode => 'UPDATE_CHANGE_INSERT');
6260           end if;
6261           close csr_future_county_rule;
6262         end if;
6263         --
6264         l_tmp_esd  := p_new_default_date;
6265         l_tmp_eed  := p_fed_eed;
6266         maintain_tax_percentage(
6267                     p_assignment_id        => p_assignment_id
6268                    ,p_effective_date       => p_new_default_date
6269                    ,p_state_code           => l_county_rec.state_code
6270                    ,p_county_code          => l_county_rec.county_code
6271                    ,p_city_code            => '0000'
6272                    ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6273                    ,p_effective_start_date => l_tmp_esd
6274                    ,p_effective_end_date   => l_tmp_eed
6275                    ,p_calculate_pct        => FALSE
6276                    );
6277         --
6278       end loop;        -- l_county_rec
6279       --
6280       delete from pay_us_emp_county_tax_rules_f
6281       where  assignment_id = p_assignment_id
6282       and    effective_start_date < p_new_default_date;
6283       --
6284       for l_city_rec in csr_city_rec(p_assignment_id, p_new_default_date)
6285       loop
6286         l_city_rec_dup := l_city_rec;
6287         if l_city_rec_dup.effective_start_date <> p_new_default_date then
6288           open csr_future_city_rule(l_city_rec_dup.state_code,
6289 				    l_city_rec_dup.county_code,
6290 				    l_city_rec_dup.city_code,
6291 				    l_city_rec_dup.assignment_id,
6292 				    l_city_rec_dup.effective_end_date);
6293 
6294           fetch csr_future_city_rule into l_temp_char;
6295           if csr_future_city_rule%notfound then
6296             pay_cty_upd.upd(p_rec            => l_city_rec_dup
6297                            ,p_effective_date => p_new_default_date
6298                            ,p_datetrack_mode => 'UPDATE');
6299           else
6300             pay_cty_upd.upd(p_rec            => l_city_rec_dup
6301                            ,p_effective_date => p_new_default_date
6302                            ,p_datetrack_mode => 'UPDATE_CHANGE_INSERT');
6303           end if;
6304           close csr_future_city_rule;
6305         end if;
6306         --
6307         l_tmp_esd  := p_new_default_date;
6308         l_tmp_eed  := p_fed_eed;
6309         maintain_tax_percentage(
6310                     p_assignment_id        => p_assignment_id
6311                    ,p_effective_date       => p_new_default_date
6312                    ,p_state_code           => l_city_rec.state_code
6313                    ,p_county_code          => l_city_rec.county_code
6314                    ,p_city_code            => l_city_rec.city_code
6315                    ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6316                    ,p_effective_start_date => l_tmp_esd
6317                    ,p_effective_end_date   => l_tmp_eed
6318                    ,p_calculate_pct        => FALSE
6319                    );
6320         --
6321       end loop;        -- l_city_rec
6322       --
6323       delete from pay_us_emp_city_tax_rules_f
6324       where  assignment_id = p_assignment_id
6325       and    effective_start_date < p_new_default_date;
6326 
6327     end push_forward_taxes;
6328   --
6329   --
6330 begin          -- move_tax_default_date procedure
6331   --
6332   hr_utility.set_location('Entering:'|| l_proc, 10);
6333   --
6334   l_new_hire_date := trunc(p_new_hire_date);
6335   l_effective_date := nvl(l_new_hire_date, trunc(p_effective_date));
6336   --
6337   hr_utility.set_location(l_proc, 20);
6338   --
6339   -- First check if geocode has been installed or not. If no geocodes
6340   -- installed then return because there is nothing to be done by this
6341   -- defaulting procedure
6342   if hr_general.chk_maintain_tax_records = 'N' then
6343      return;
6344   end if;
6345   --
6346   -- Check that L_EFFECTIVE_DATE is not null
6347   --
6348   hr_api.mandatory_arg_error(p_api_name       => l_proc,
6349                              p_argument       => 'effective_date',
6350                              p_argument_value => l_effective_date);
6351   --
6352   -- Validate p_assignment_id against per_assignments_f
6353   --
6354   if p_assignment_id is null then
6355     hr_utility.set_message(801,'PAY_7702_PDT_VALUE_NOT_FOUND');
6356     hr_utility.raise_error;
6357   else
6358     open csr_assignment_id;
6359     fetch csr_assignment_id into l_temp_char;
6360     if csr_assignment_id%notfound then
6361       close csr_assignment_id;
6362       hr_utility.set_message(801,'PAY_7702_PDT_VALUE_NOT_FOUND');
6363       hr_utility.raise_error;
6364     end if;
6365     close csr_assignment_id;
6366   end if;
6367 
6368   --
6369   -- Get the start and end dates of the current assignment record.
6370   --
6371   open csr_asg_data(p_assignment_id, l_effective_date);
6372   fetch csr_asg_data into l_asg_esd, l_asg_eed;
6373   if csr_asg_data%notfound then
6374     close csr_asg_data;
6375     hr_utility.set_message(801,'HR_7026_ELE_ENTRY_ASS_NOT_EXST');
6376     hr_utility.set_message_token('DATE',l_effective_date);
6377     hr_utility.raise_error;
6378   end if;
6379   close csr_asg_data;
6380   --
6381   -- Identify the new default date as either the new hire date passed in, or
6382   -- the start date of the current assignment record.
6383   --
6384   l_new_default_date := nvl(l_new_hire_date, l_asg_esd);
6385   --
6386   open csr_fed_tax_rule;
6387   fetch csr_fed_tax_rule into l_defaulting_date, l_fed_eed,
6388                               l_emp_fed_tax_rule_id;
6389   if csr_fed_tax_rule%notfound then
6390     close csr_fed_tax_rule;
6391     hr_utility.set_message(801,'PAY_51465_PDT_INVALID_LOC');
6392     hr_utility.raise_error;
6393   end if;
6394   close csr_fed_tax_rule;
6395   --
6396   -- To pull back the defaulting date, the assignment as of the new default date
6397   -- must be immediately before the old hire date.  This section checks this
6398   -- condition.
6399   --
6400   if l_new_default_date < l_defaulting_date then
6401     open csr_asg_data(p_assignment_id, l_new_default_date);
6402     fetch csr_asg_data into l_asg_esd, l_asg_eed;
6403     if csr_asg_data%notfound then
6404       close csr_asg_data;
6405       hr_utility.set_message(801,'HR_7026_ELE_ENTRY_ASS_NOT_EXST');
6406       hr_utility.set_message_token('DATE',l_new_default_date);
6407       hr_utility.raise_error;
6408     end if;
6409     close csr_asg_data;
6410     --
6411     if l_defaulting_date - 1 not between l_asg_esd and l_asg_eed then
6412       raise l_exit_quietly;
6413     end if;
6414   end if;
6415 
6416   -- reimp
6417   -- Figure out if the location is the same as the next location
6418   --
6419   -- In case of CORRECTION or UPDATE_INSERT, we check to see the location
6420   -- of the current asg record, and the location of the next asg record.  If
6421   -- they are different, we set p_new_location_id to the current location id.
6422   -- Otherwise we set it to null.
6423   --
6424   -- If it is DELETE_*_CHANGE or ZAP it doesn't matter what the location id is.
6425   --
6426   -- If it is UPDATE_OVERRIDE, the location_id is passed in by the maintain taxes proc.
6427   --
6428   if p_datetrack_mode in (hr_api.g_correction,hr_api.g_update_change_insert) then
6429     open csr_asg_loc_id(l_new_default_date);
6430     fetch csr_asg_loc_id into l_new_location_id;
6431     if csr_asg_loc_id%NOTFOUND then
6432 	close csr_asg_loc_id;
6433 	l_new_location_id := null;
6434     else
6435 	close csr_asg_loc_id;
6436   	open  csr_asg_loc_id(l_defaulting_date);
6437 	fetch csr_asg_loc_id into l_tmp_loc_id;
6438 	close csr_asg_loc_id;
6439 	if l_tmp_loc_id = l_new_location_id then
6440 		l_new_location_id := null;
6441 	end if;
6442     end if;
6443   end if;
6444 
6445   if l_new_location_id is not null then
6446     open csr_loc_addr(l_new_location_id);
6447     fetch csr_loc_addr into l_loc_state_code, l_loc_county_code,
6448                             l_loc_city_code, l_loc_ovrd_state_code,
6449 			    l_loc_ovrd_county_code,l_loc_ovrd_city_code;
6450     if csr_loc_addr%notfound then
6451       close csr_loc_addr;
6452       hr_utility.set_message(801,'HR_51357_POS_LOC_NOT_EXIST');
6453       hr_utility.raise_error;
6454     end if;
6455     close csr_loc_addr;
6456 
6457   end if;
6458   --
6459   -- Determine if defaulting criteria is met at the new default date.
6460   --
6461   open csr_defaulting_met(p_assignment_id,l_new_default_date);
6462   fetch csr_defaulting_met into l_temp_char;
6463   if csr_defaulting_met%found then
6464     l_defaulting_met := True;
6465   else
6466     l_defaulting_met := False;
6467   end if;
6468   close csr_defaulting_met;
6469 
6470   --
6471   --
6472   -- This section handles the cases where this procedure is called from a
6473   -- change to the person's hire date.  In these cases, the new hire date
6474   -- could result in changes to the starting dates of the tax records.  This
6475   -- change could pull back the tax defaulting date, or push it forward.
6476   --
6477   If l_new_hire_date is not null then
6478     if l_new_default_date < l_defaulting_date then
6479       if l_defaulting_met then
6480         --
6481         -- Pull back the start dates of all tax rules and element entries.
6482         --
6483         pull_back_taxes(p_assignment_id       => p_assignment_id
6484                        ,p_emp_fed_tax_rule_id => l_emp_fed_tax_rule_id
6485                        ,p_fed_eed             => l_fed_eed
6486                        ,p_new_default_date    => l_new_default_date
6487                        ,p_defaulting_date     => l_defaulting_date
6488                        );
6489         --
6490       else             -- hire_date is given, pull back, defaulting not met
6491         --
6492         -- Reset the element entries to the old default date in case they were
6493         -- moved.
6494         --
6495         reset_element_entries(p_assignment_id       => p_assignment_id
6496                              ,p_emp_fed_tax_rule_id => l_emp_fed_tax_rule_id
6497                              ,p_fed_eed             => l_fed_eed
6498                              ,p_defaulting_date     => l_defaulting_date
6499                              );
6500         --
6501       end if;          -- hire date given, pull back, defaulting met?
6502       --
6503     elsif l_new_default_date > l_defaulting_date then   -- hire_date given, push
6504                                                         -- forward
6505       --
6506       push_forward_taxes(p_assignment_id       => p_assignment_id
6507                         ,p_fed_eed             => l_fed_eed
6508                         ,p_new_default_date    => l_new_default_date
6509                         ,p_defaulting_date     => l_defaulting_date
6510                         );
6511       --
6512     end if;          -- pull back / push forward?
6513   end if;          -- hire date is not null?
6514   --
6515   --
6516   -- This section handles the cases where this procedure is called from a change
6517   -- to the assignment, i.e., l_new_hire_date is null.  In these cases, the new
6518   -- defaulting date will be earlier than the current defaulting date.  If the
6519   -- change to the assignment occurred after the current defaulting date, the
6520   -- procedure for location changes would have been called.
6521   --
6522   if l_new_hire_date is null and l_new_default_date < l_defaulting_date then
6523     --
6524     if p_datetrack_mode = 'DELETE_NEXT_CHANGE' then
6525       if l_defaulting_met then
6526         --
6527         -- Pull back the start date of all tax rules and tax element entries.
6528         --
6529         pull_back_taxes(p_assignment_id       => p_assignment_id
6530                        ,p_emp_fed_tax_rule_id => l_emp_fed_tax_rule_id
6531                        ,p_fed_eed             => l_fed_eed
6532                        ,p_new_default_date    => l_new_default_date
6533                        ,p_defaulting_date     => l_defaulting_date
6534                        );
6535         --
6536       else      -- DELETE_NEXT_CHANGE, defaulting not met
6537         --
6538         if l_asg_eed = hr_api.g_eot then
6539           --
6540           -- This delete extends to the end of time, so it removes the taxes.
6541           --
6542           delete_fed_tax_rule(
6543                           p_effective_date        => l_defaulting_date
6544                          ,p_datetrack_delete_mode => 'ZAP'
6545                          ,p_assignment_id         => p_assignment_id
6546                          ,p_delete_routine        => 'ASSIGNMENT'
6547                          ,p_effective_start_date  => l_tmp_effective_start_date
6548                          ,p_effective_end_date    => l_tmp_effective_end_date
6549                          ,p_object_version_number => l_tmp_object_version_number
6550                          );
6551           --
6552         else        -- DELETE_NEXT_CHANGE, push defaulting date forward to
6553                     -- assignment break
6554           --
6555           push_forward_taxes(p_assignment_id       => p_assignment_id
6556                             ,p_fed_eed             => l_fed_eed
6557                             ,p_new_default_date    => l_asg_eed + 1
6558                             ,p_defaulting_date     => l_defaulting_date
6559                             );
6560           --
6561         end if;        -- DELETE_NEXT_CHANGE, l_fed_eed at end of time?
6562         --
6563       end if;        -- DELETE_NEXT_CHANGE, defaulting met?
6564 
6565 
6566     elsif p_datetrack_mode = 'FUTURE_CHANGE' then
6567       if l_defaulting_met then
6568         --
6569         -- Pull back the start date of all tax rules and tax element entries.
6570         --
6571         pull_back_taxes(p_assignment_id       => p_assignment_id
6572                        ,p_emp_fed_tax_rule_id => l_emp_fed_tax_rule_id
6573                        ,p_fed_eed             => l_fed_eed
6574                        ,p_new_default_date    => l_new_default_date
6575                        ,p_defaulting_date     => l_defaulting_date
6576                        );
6577         --
6578       else   -- FUTURE_CHANGE, defaulting not met
6579         --
6580         -- Purge all tax rules.
6581         --
6582         delete_fed_tax_rule(
6583                          p_effective_date        => l_defaulting_date
6584                         ,p_datetrack_delete_mode => 'ZAP'
6585                         ,p_assignment_id         => p_assignment_id
6586                         ,p_delete_routine        => 'ASSIGNMENT'
6587                         ,p_effective_start_date  => l_tmp_effective_start_date
6588                         ,p_effective_end_date    => l_tmp_effective_end_date
6589                         ,p_object_version_number => l_tmp_object_version_number
6590                            );
6591         --
6592       end if;      -- FUTURE_CHANGE, defaulting met?
6593 
6594 
6595     elsif p_datetrack_mode in('CORRECTION', 'UPDATE_CHANGE_INSERT') then
6596       if l_defaulting_met then
6597         if l_new_location_id is not null then
6598           --
6599           -- Pull back start date of federal tax rule and workers comp entry.
6600           --
6601           update pay_us_emp_fed_tax_rules_f
6602           set    effective_start_date = l_new_default_date
6603           where  assignment_id = p_assignment_id
6604           and    effective_start_date = l_defaulting_date;
6605           --
6606           maintain_wc(
6607                   p_emp_fed_tax_rule_id   => l_emp_fed_tax_rule_id
6608                  ,p_effective_start_date  => l_defaulting_date
6609                  ,p_effective_end_date    => l_fed_eed
6610                  ,p_effective_date        => l_new_default_date
6611                  ,p_datetrack_mode        => 'INSERT_OVERRIDE'
6612                  );
6613           --
6614           -- Create a break in the federal tax rule at the old defaulting date.
6615           -- Do the same for the workers comp entry.
6616           --
6617           open csr_fed_rec(p_assignment_id, l_defaulting_date);
6618           fetch csr_fed_rec into l_fed_rec;
6619             open csr_future_fed_rule(l_fed_rec.effective_end_date);
6620             fetch csr_future_fed_rule into l_temp_char;
6621             if csr_future_fed_rule%notfound then
6622               pay_fed_upd.upd(p_rec          => l_fed_rec
6623                              ,p_effective_date => l_defaulting_date
6624                              ,p_datetrack_mode => 'UPDATE');
6625             else
6626               pay_fed_upd.upd(p_rec          => l_fed_rec
6627                              ,p_effective_date => l_defaulting_date
6628                              ,p_datetrack_mode => 'UPDATE_CHANGE_INSERT');
6629             end if;
6630           close csr_future_fed_rule;
6631           close csr_fed_rec;
6632           --
6633           maintain_wc(
6634                   p_emp_fed_tax_rule_id   => l_emp_fed_tax_rule_id
6635                  ,p_effective_start_date  => l_new_default_date
6636                  ,p_effective_end_date    => l_fed_eed
6637                  ,p_effective_date        => l_defaulting_date
6638                  ,p_datetrack_mode        => 'INSERT_OLD'
6639                  );
6640           --
6641           -- Update the federal tax rule and workers comp entry to the new
6642           -- location at the new defaulting date.
6643           --
6644           open csr_fed_rec(p_assignment_id, l_new_default_date);
6645           fetch csr_fed_rec into l_fed_rec;
6646             l_fed_rec.sui_state_code := l_loc_ovrd_state_code;
6647             l_fed_rec.sui_jurisdiction_code := l_loc_ovrd_state_code||'-000-0000';
6648             pay_fed_upd.upd(p_rec          => l_fed_rec
6649                            ,p_effective_date => l_new_default_date
6650                            ,p_datetrack_mode => 'CORRECTION');
6651           close csr_fed_rec;
6652           --
6653           maintain_wc(
6654                   p_emp_fed_tax_rule_id   => l_emp_fed_tax_rule_id
6655                  ,p_effective_start_date  => l_new_default_date
6656                  ,p_effective_end_date    => l_fed_eed
6657                  ,p_effective_date        => l_new_default_date
6658                  ,p_datetrack_mode        => 'CORRECTION'
6659                  );
6660           --
6661           -- Pull back the state tax rule and %age to the new default date.
6662           -- Create a break in the %age at the old default date, then correct
6663           -- the location at the new default date.
6664           --
6665           for l_state_rec in csr_state_rec(p_assignment_id, l_defaulting_date)
6666           loop
6667             --
6668             update pay_us_emp_state_tax_rules_f
6669             set    effective_start_date = l_new_default_date
6670             where  effective_start_date = l_defaulting_date
6671             and    assignment_id = p_assignment_id
6672             and    state_code = l_state_rec.state_code;
6673             --
6674             l_tmp_effective_start_date := l_defaulting_date;
6675             l_tmp_effective_end_date   := l_fed_eed;
6676             maintain_tax_percentage(
6677                         p_assignment_id        => p_assignment_id
6678                        ,p_effective_date       => l_new_default_date
6679                        ,p_state_code           => l_state_rec.state_code
6680                        ,p_county_code          => '000'
6681                        ,p_city_code            => '0000'
6682                        ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6683                        ,p_effective_start_date => l_tmp_effective_start_date
6684                        ,p_effective_end_date   => l_tmp_effective_end_date
6685                        ,p_calculate_pct        => FALSE
6686                        );
6687             --
6688             --
6689             l_tmp_effective_start_date := l_defaulting_date;
6690             l_tmp_effective_end_date   := l_fed_eed;
6691             maintain_tax_percentage(
6692                       p_assignment_id        => p_assignment_id
6693                      ,p_effective_date       => l_defaulting_date
6694                      ,p_state_code           => l_state_rec.state_code
6695                      ,p_county_code          => '000'
6696                      ,p_city_code            => '0000'
6697                      ,p_datetrack_mode       => 'INSERT_OLD'
6698                      ,p_effective_start_date => l_tmp_effective_start_date
6699                      ,p_effective_end_date   => l_tmp_effective_end_date
6700                      ,p_calculate_pct        => FALSE
6701                      );
6702             --
6703             --
6704             l_tmp_effective_start_date := l_defaulting_date;
6705             l_tmp_effective_end_date   := l_fed_eed;
6706             maintain_tax_percentage(
6707                       p_assignment_id        => p_assignment_id
6708                      ,p_effective_date       => l_new_default_date
6709                      ,p_state_code           => l_state_rec.state_code
6710                      ,p_county_code          => '000'
6711                      ,p_city_code            => '0000'
6712                      ,p_percentage           => 0
6713                      ,p_datetrack_mode       => 'CORRECTION'
6714                      ,p_effective_start_date => l_tmp_effective_start_date
6715                      ,p_effective_end_date   => l_tmp_effective_end_date
6716                      ,p_calculate_pct        => FALSE
6717                      );
6718           --
6719           end loop;        -- l_state_rec
6720           --
6721           -- Pull back the county tax rule and %age to the new default date.
6722           -- Create a break in the %age at the old default date, then correct
6723           -- the location at the new default date.
6724           --
6725           for l_county_rec in csr_county_rec(p_assignment_id, l_defaulting_date)
6726           loop
6727             --
6728             update pay_us_emp_county_tax_rules_f
6729             set    effective_start_date = l_new_default_date
6730             where  effective_start_date = l_defaulting_date
6731             and    assignment_id = p_assignment_id
6732             and    state_code = l_county_rec.state_code
6733             and    county_code = l_county_rec.county_code;
6734             --
6735             l_tmp_effective_start_date := l_defaulting_date;
6736             l_tmp_effective_end_date   := l_fed_eed;
6737             maintain_tax_percentage(
6738                       p_assignment_id        => p_assignment_id
6739                      ,p_effective_date       => l_new_default_date
6740                      ,p_state_code           => l_county_rec.state_code
6741                      ,p_county_code          => l_county_rec.county_code
6742                      ,p_city_code            => '0000'
6743                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6744                      ,p_effective_start_date => l_tmp_effective_start_date
6745                      ,p_effective_end_date   => l_tmp_effective_end_date
6746                      ,p_calculate_pct        => FALSE
6747                      );
6748             --
6749             --
6750             l_tmp_effective_start_date := l_defaulting_date;
6751             l_tmp_effective_end_date   := l_fed_eed;
6752             maintain_tax_percentage(
6753                       p_assignment_id        => p_assignment_id
6754                      ,p_effective_date       => l_defaulting_date
6755                      ,p_state_code           => l_county_rec.state_code
6756                      ,p_county_code          => l_county_rec.county_code
6757                      ,p_city_code            => '0000'
6758                      ,p_datetrack_mode       => 'INSERT_OLD'
6759                      ,p_effective_start_date => l_tmp_effective_start_date
6760                      ,p_effective_end_date   => l_tmp_effective_end_date
6761                      ,p_calculate_pct        => FALSE
6762                      );
6763             --
6764             --
6765             l_tmp_effective_start_date := l_defaulting_date;
6766             l_tmp_effective_end_date   := l_fed_eed;
6767             maintain_tax_percentage(
6768                       p_assignment_id        => p_assignment_id
6769                      ,p_effective_date       => l_new_default_date
6770                      ,p_state_code           => l_county_rec.state_code
6771                      ,p_county_code          => l_county_rec.county_code
6772                      ,p_city_code            => '0000'
6773                      ,p_percentage           => 0
6774                      ,p_datetrack_mode       => 'CORRECTION'
6775                      ,p_effective_start_date => l_tmp_effective_start_date
6776                      ,p_effective_end_date   => l_tmp_effective_end_date
6777                      ,p_calculate_pct        => FALSE
6778                      );
6779           --
6780           end loop;        -- l_county_rec
6781           --
6782           -- Pull back the city tax rule and %age to the new default date.
6783           -- Create a break in the %age at the old default date, then correct
6784           -- the location at the new default date.
6785           --
6786           for l_city_rec in csr_city_rec(p_assignment_id, l_defaulting_date)
6787           loop
6788             --
6789             update pay_us_emp_city_tax_rules_f
6790             set    effective_start_date = l_new_default_date
6791             where  effective_start_date = l_defaulting_date
6792             and    assignment_id = p_assignment_id
6793             and    state_code = l_city_rec.state_code
6794             and    county_code = l_city_rec.county_code
6795             and    city_code = l_city_rec.city_code;
6796             --
6797             l_tmp_effective_start_date := l_defaulting_date;
6798             l_tmp_effective_end_date   := l_fed_eed;
6799             maintain_tax_percentage(
6800                       p_assignment_id        => p_assignment_id
6801                      ,p_effective_date       => l_new_default_date
6802                      ,p_state_code           => l_city_rec.state_code
6803                      ,p_county_code          => l_city_rec.county_code
6804                      ,p_city_code            => l_city_rec.city_code
6805                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
6806                      ,p_effective_start_date => l_tmp_effective_start_date
6807                      ,p_effective_end_date   => l_tmp_effective_end_date
6808                      ,p_calculate_pct        => FALSE
6809                      );
6810             --
6811             --
6812             l_tmp_effective_start_date := l_defaulting_date;
6813             l_tmp_effective_end_date   := l_fed_eed;
6814             maintain_tax_percentage(
6815                       p_assignment_id        => p_assignment_id
6816                      ,p_effective_date       => l_defaulting_date
6817                      ,p_state_code           => l_city_rec.state_code
6818                      ,p_county_code          => l_city_rec.county_code
6819                      ,p_city_code            => l_city_rec.city_code
6820                      ,p_datetrack_mode       => 'INSERT_OLD'
6821                      ,p_effective_start_date => l_tmp_effective_start_date
6822                      ,p_effective_end_date   => l_tmp_effective_end_date
6823                      ,p_calculate_pct        => FALSE
6824                      );
6825             --
6826             --
6827             l_tmp_effective_start_date := l_defaulting_date;
6828             l_tmp_effective_end_date   := l_fed_eed;
6829             if l_loc_ovrd_state_code||'-'||l_loc_ovrd_county_code||'-'||l_loc_ovrd_city_code =
6830                l_city_rec.state_code||'-'||l_city_rec.county_code||
6831                '-'||l_city_rec.city_code then
6832               l_city_pct := 100;
6833             else
6834               l_city_pct := 0;
6835             end if;
6836             maintain_tax_percentage(
6837                       p_assignment_id        => p_assignment_id
6838                      ,p_effective_date       => l_new_default_date
6839                      ,p_state_code           => l_city_rec.state_code
6840                      ,p_county_code          => l_city_rec.county_code
6841                      ,p_city_code            => l_city_rec.city_code
6842                      ,p_percentage           => l_city_pct
6843                      ,p_datetrack_mode       => 'CORRECTION'
6844                      ,p_effective_start_date => l_tmp_effective_start_date
6845                      ,p_effective_end_date   => l_tmp_effective_end_date
6846                      ,p_calculate_pct        => FALSE
6847                      );
6848           --
6849           end loop;        -- l_city_rec
6850           --
6851         else       -- CORRECTION or UPD_CHG_INS, defaulting met, same location
6852           --
6853           -- Pull back the start date of all tax rules and tax element entries.
6854           --
6855           pull_back_taxes(p_assignment_id       => p_assignment_id
6856                          ,p_emp_fed_tax_rule_id => l_emp_fed_tax_rule_id
6857                          ,p_fed_eed             => l_fed_eed
6858                          ,p_new_default_date    => l_new_default_date
6859                          ,p_defaulting_date     => l_defaulting_date
6860                          );
6861           --
6862         end if;      -- CORRECTION, defaulting met, l_new_location_id is null?
6863           --
6864       else       -- CORRECTION, defaulting not met
6865         --
6866         -- Reset start date of tax element entries to old default date.  In some
6867         -- cases, changes to an assignment will move the element entries.  In
6868         -- this case, the tax entries should not be moved.  Nothing needs to be
6869         -- done for the tax rules.
6870         --
6871         reset_element_entries(p_assignment_id       => p_assignment_id
6872                              ,p_emp_fed_tax_rule_id => l_emp_fed_tax_rule_id
6873                              ,p_fed_eed             => l_fed_eed
6874                              ,p_defaulting_date     => l_defaulting_date
6875                              );
6876         --
6877       end if;       -- CORRECTION, defaulting_met?
6878 
6879 
6880 
6881     elsif p_datetrack_mode = 'UPDATE_OVERRIDE' then
6882       --
6883       if l_defaulting_met then
6884         if l_new_location_id is not null then
6885           --
6886           -- Purge the taxes, then create new default records at the new default
6887           -- date for the new location.
6888           --
6889           delete_fed_tax_rule (
6890                p_effective_date        => l_defaulting_date
6891               ,p_datetrack_delete_mode => 'ZAP'
6892               ,p_assignment_id         => p_assignment_id
6893               ,p_delete_routine        => 'ASSIGNMENT'
6894               ,p_effective_start_date  => l_tmp_effective_start_date
6895               ,p_effective_end_date    => l_tmp_effective_end_date
6896               ,p_object_version_number => l_tmp_object_version_number
6897               );
6898           --
6899           create_default_tax_rules (
6900                p_effective_date        => l_defaulting_date
6901               ,p_assignment_id         => p_assignment_id
6902               ,p_emp_fed_tax_rule_id   => l_emp_fed_tax_rule_id
6903               ,p_fed_object_version_number => l_tmp_object_version_number
6904               ,p_fed_effective_start_date  => l_tmp_effective_start_date
6905               ,p_fed_effective_end_date    => l_tmp_effective_end_date
6906               );
6907           --
6908         else         -- UPDATE_OVERRIDE, defaulting met, same location
6909           --
6910           -- Pull back the start date of the federal tax rule and the workers
6911           -- comp element entry.
6912           --
6913           update pay_us_emp_fed_tax_rules_f
6914           set    effective_start_date = l_new_default_date
6915           where  assignment_id = p_assignment_id
6916           and    effective_start_date = l_defaulting_date;
6917           --
6918           maintain_wc(
6919                   p_emp_fed_tax_rule_id   => l_emp_fed_tax_rule_id
6920                  ,p_effective_start_date  => l_defaulting_date
6921                  ,p_effective_end_date    => l_fed_eed
6922                  ,p_effective_date        => l_new_default_date
6923                  ,p_datetrack_mode        => 'INSERT_OVERRIDE'
6924                  );
6925           --
6926           -- Correct the sui_state of all future federal tax rule and the
6927           -- workers comp element entry rows.
6928           --
6929           l_loc_state_code := null;
6930           for l_fed_rec in csr_fed_rows(p_assignment_id, l_defaulting_date)
6931           loop
6932             l_loc_state_code := nvl(l_loc_state_code, l_fed_rec.sui_state_code);
6933             l_fed_rec.sui_state_code := l_loc_state_code;
6934             l_fed_rec.sui_jurisdiction_code := l_loc_state_code||'-000-0000';
6935 /* changes for bug 1970341 possible a DB issue. */
6936 --      l_fed_rec_dup := l_fed_rec;
6937 
6938       l_fed_rec_dup.emp_fed_tax_rule_id       := l_fed_rec.emp_fed_tax_rule_id;
6939       l_fed_rec_dup.effective_start_date      := l_fed_rec.effective_start_date;
6940       l_fed_rec_dup.effective_end_date        := l_fed_rec.effective_end_date;
6941       l_fed_rec_dup.assignment_id             := l_fed_rec.assignment_id;
6942       l_fed_rec_dup.sui_state_code            := l_fed_rec.sui_state_code;
6943       l_fed_rec_dup.sui_jurisdiction_code     := l_fed_rec.sui_jurisdiction_code ;
6944       l_fed_rec_dup.business_group_id         := l_fed_rec.business_group_id;
6945       l_fed_rec_dup.additional_wa_amount      := l_fed_rec.additional_wa_amount;
6946       l_fed_rec_dup.filing_status_code        := l_fed_rec.filing_status_code;
6947       l_fed_rec_dup.fit_override_amount       := l_fed_rec.fit_override_amount;
6948       l_fed_rec_dup.fit_override_rate         := l_fed_rec.fit_override_rate;
6949       l_fed_rec_dup.withholding_allowances    := l_fed_rec.withholding_allowances;
6950       l_fed_rec_dup.cumulative_taxation       := l_fed_rec.cumulative_taxation;
6951       l_fed_rec_dup.eic_filing_status_code    := l_fed_rec.eic_filing_status_code;
6952       l_fed_rec_dup.fit_additional_tax        := l_fed_rec.fit_additional_tax;
6953       l_fed_rec_dup.fit_exempt                := l_fed_rec.fit_exempt;
6954       l_fed_rec_dup.futa_tax_exempt           := l_fed_rec.futa_tax_exempt;
6955       l_fed_rec_dup.medicare_tax_exempt       := l_fed_rec.medicare_tax_exempt;
6956       l_fed_rec_dup.ss_tax_exempt             := l_fed_rec.ss_tax_exempt;
6957       l_fed_rec_dup.wage_exempt               := l_fed_rec.wage_exempt;
6958       l_fed_rec_dup.statutory_employee        := l_fed_rec.statutory_employee;
6959       l_fed_rec_dup.w2_filed_year             := l_fed_rec.w2_filed_year;
6960       l_fed_rec_dup.supp_tax_override_rate    := l_fed_rec.supp_tax_override_rate;
6961       l_fed_rec_dup.excessive_wa_reject_date  := l_fed_rec.excessive_wa_reject_date;
6962       l_fed_rec_dup.object_version_number     := l_fed_rec.object_version_number ;
6963       l_fed_rec_dup.attribute_category        := l_fed_rec.attribute_category;
6964       l_fed_rec_dup.attribute1                := l_fed_rec.attribute1;
6965       l_fed_rec_dup.attribute2                := l_fed_rec.attribute2;
6966       l_fed_rec_dup.attribute3                := l_fed_rec.attribute3;
6967       l_fed_rec_dup.attribute4                := l_fed_rec.attribute4;
6968       l_fed_rec_dup.attribute5                := l_fed_rec.attribute5;
6969       l_fed_rec_dup.attribute6                := l_fed_rec.attribute6;
6970       l_fed_rec_dup.attribute7                := l_fed_rec.attribute7;
6971       l_fed_rec_dup.attribute8                := l_fed_rec.attribute8;
6972       l_fed_rec_dup.attribute9                := l_fed_rec.attribute9;
6973       l_fed_rec_dup.attribute10               := l_fed_rec.attribute10;
6974       l_fed_rec_dup.attribute11               := l_fed_rec.attribute11;
6975       l_fed_rec_dup.attribute12               := l_fed_rec.attribute12;
6976       l_fed_rec_dup.attribute13               := l_fed_rec.attribute13;
6977       l_fed_rec_dup.attribute14               := l_fed_rec.attribute14;
6978       l_fed_rec_dup.attribute15               := l_fed_rec.attribute15;
6979       l_fed_rec_dup.attribute16               := l_fed_rec.attribute16;
6980       l_fed_rec_dup.attribute17               := l_fed_rec.attribute17;
6981       l_fed_rec_dup.attribute18               := l_fed_rec.attribute18;
6982       l_fed_rec_dup.attribute19               := l_fed_rec.attribute19;
6983       l_fed_rec_dup.attribute20               := l_fed_rec.attribute20;
6984       l_fed_rec_dup.attribute21               := l_fed_rec.attribute21;
6985       l_fed_rec_dup.attribute22               := l_fed_rec.attribute22;
6986       l_fed_rec_dup.attribute23               := l_fed_rec.attribute23;
6987       l_fed_rec_dup.attribute24               := l_fed_rec.attribute24;
6988       l_fed_rec_dup.attribute25               := l_fed_rec.attribute25;
6989       l_fed_rec_dup.attribute26               := l_fed_rec.attribute26;
6990       l_fed_rec_dup.attribute27               := l_fed_rec.attribute27;
6991       l_fed_rec_dup.attribute28               := l_fed_rec.attribute28;
6992       l_fed_rec_dup.attribute29               := l_fed_rec.attribute29;
6993       l_fed_rec_dup.attribute30               := l_fed_rec.attribute30;
6994       l_fed_rec_dup.fed_information_category  := l_fed_rec.fed_information_category;
6995       l_fed_rec_dup.fed_information1          := l_fed_rec.fed_information1;
6996       l_fed_rec_dup.fed_information2          := l_fed_rec.fed_information2;
6997       l_fed_rec_dup.fed_information3          := l_fed_rec.fed_information3;
6998       l_fed_rec_dup.fed_information4          := l_fed_rec.fed_information4;
6999       l_fed_rec_dup.fed_information5          := l_fed_rec.fed_information5;
7000       l_fed_rec_dup.fed_information6          := l_fed_rec.fed_information6;
7001       l_fed_rec_dup.fed_information7          := l_fed_rec.fed_information7;
7002       l_fed_rec_dup.fed_information8          := l_fed_rec.fed_information8;
7003       l_fed_rec_dup.fed_information9          := l_fed_rec.fed_information9;
7004       l_fed_rec_dup.fed_information10         := l_fed_rec.fed_information10;
7005       l_fed_rec_dup.fed_information11         := l_fed_rec.fed_information11;
7006       l_fed_rec_dup.fed_information12         := l_fed_rec.fed_information12;
7007       l_fed_rec_dup.fed_information13         := l_fed_rec.fed_information13;
7008       l_fed_rec_dup.fed_information14         := l_fed_rec.fed_information14;
7009       l_fed_rec_dup.fed_information15         := l_fed_rec.fed_information15;
7010       l_fed_rec_dup.fed_information16         := l_fed_rec.fed_information16;
7011       l_fed_rec_dup.fed_information17         := l_fed_rec.fed_information17;
7012       l_fed_rec_dup.fed_information18         := l_fed_rec.fed_information18;
7013       l_fed_rec_dup.fed_information19         := l_fed_rec.fed_information19;
7014       l_fed_rec_dup.fed_information20         := l_fed_rec.fed_information20;
7015       l_fed_rec_dup.fed_information21         := l_fed_rec.fed_information21;
7016       l_fed_rec_dup.fed_information22         := l_fed_rec.fed_information22;
7017       l_fed_rec_dup.fed_information23         := l_fed_rec.fed_information23;
7018       l_fed_rec_dup.fed_information24         := l_fed_rec.fed_information24;
7019       l_fed_rec_dup.fed_information25         := l_fed_rec.fed_information25;
7020       l_fed_rec_dup.fed_information26         := l_fed_rec.fed_information26;
7021       l_fed_rec_dup.fed_information27         := l_fed_rec.fed_information27;
7022       l_fed_rec_dup.fed_information28         := l_fed_rec.fed_information28;
7023       l_fed_rec_dup.fed_information29         := l_fed_rec.fed_information29;
7024       l_fed_rec_dup.fed_information30         := l_fed_rec.fed_information30;
7025 
7026 /* changes for bug 1970341 possible a DB issue. */
7027 
7028             pay_fed_upd.upd(p_rec            => l_fed_rec_dup
7029                          ,p_effective_date => l_fed_rec_dup.effective_start_date
7030                          ,p_datetrack_mode => 'CORRECTION');
7031             maintain_wc(
7032                   p_emp_fed_tax_rule_id   => l_emp_fed_tax_rule_id
7033                  ,p_effective_start_date  => l_fed_rec_dup.effective_start_date
7034                  ,p_effective_end_date    => l_fed_rec_dup.effective_end_date
7035                  ,p_effective_date        => l_fed_rec_dup.effective_start_date
7036                  ,p_datetrack_mode        => 'CORRECTION'
7037                  );
7038           end loop;
7039           --
7040           -- Pull back the state tax rule and %age to the new default date.
7041           -- Then delete future changes on the %ages.
7042           --
7043           for l_state_rec in csr_state_rec(p_assignment_id, l_defaulting_date)
7044           loop
7045             --
7046             update pay_us_emp_state_tax_rules_f
7047             set    effective_start_date = l_new_default_date
7048             where  effective_start_date = l_defaulting_date
7049             and    assignment_id = p_assignment_id
7050             and    state_code = l_state_rec.state_code;
7051             --
7052             l_tmp_effective_start_date := l_defaulting_date;
7053             l_tmp_effective_end_date   := l_fed_eed;
7054             maintain_tax_percentage(
7055                       p_assignment_id        => p_assignment_id
7056                      ,p_effective_date       => l_new_default_date
7057                      ,p_state_code           => l_state_rec.state_code
7058                      ,p_county_code          => '000'
7059                      ,p_city_code            => '0000'
7060                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
7061                      ,p_effective_start_date => l_tmp_effective_start_date
7062                      ,p_effective_end_date   => l_tmp_effective_end_date
7063                      ,p_calculate_pct        => FALSE
7064                      );
7065             --
7066             --
7067             l_tmp_effective_start_date := l_defaulting_date;
7068             l_tmp_effective_end_date   := l_fed_eed;
7069             maintain_tax_percentage(
7070                       p_assignment_id        => p_assignment_id
7071                      ,p_effective_date       => l_new_default_date
7072                      ,p_state_code           => l_state_rec.state_code
7073                      ,p_county_code          => '000'
7074                      ,p_city_code            => '0000'
7075                      ,p_datetrack_mode       => 'FUTURE_CHANGE'
7076                      ,p_effective_start_date => l_tmp_effective_start_date
7077                      ,p_effective_end_date   => l_tmp_effective_end_date
7078                      ,p_calculate_pct        => FALSE
7079                      );
7080           --
7081           end loop;        -- l_state_rec
7082           --
7083           -- Pull back the county tax rule and %age to the new default date.
7084           -- Then delete future changes on the %ages.
7085           --
7086           for l_county_rec in csr_county_rec(p_assignment_id, l_defaulting_date)
7087           loop
7088             --
7089             update pay_us_emp_county_tax_rules_f
7090             set    effective_start_date = l_new_default_date
7091             where  effective_start_date = l_defaulting_date
7092             and    assignment_id = p_assignment_id
7093             and    state_code = l_county_rec.state_code
7094             and    county_code = l_county_rec.county_code;
7095             --
7096             l_tmp_effective_start_date := l_defaulting_date;
7097             l_tmp_effective_end_date   := l_fed_eed;
7098             maintain_tax_percentage(
7099                       p_assignment_id        => p_assignment_id
7100                      ,p_effective_date       => l_new_default_date
7101                      ,p_state_code           => l_county_rec.state_code
7102                      ,p_county_code          => l_county_rec.county_code
7103                      ,p_city_code            => '0000'
7104                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
7105                      ,p_effective_start_date => l_tmp_effective_start_date
7106                      ,p_effective_end_date   => l_tmp_effective_end_date
7107                      ,p_calculate_pct        => FALSE
7108                      );
7109             --
7110             --
7111             l_tmp_effective_start_date := l_defaulting_date;
7112             l_tmp_effective_end_date   := l_fed_eed;
7113             maintain_tax_percentage(
7114                      p_assignment_id        => p_assignment_id
7115                      ,p_effective_date       => l_new_default_date
7116                      ,p_state_code           => l_county_rec.state_code
7117                      ,p_county_code          => l_county_rec.county_code
7118                      ,p_city_code            => '0000'
7119                      ,p_datetrack_mode       => 'FUTURE_CHANGE'
7120                      ,p_effective_start_date => l_tmp_effective_start_date
7121                      ,p_effective_end_date   => l_tmp_effective_end_date
7122                      ,p_calculate_pct        => FALSE
7123                      );
7124           --
7125           end loop;        -- l_county_rec
7126           --
7127           -- Pull back the city tax rule and %age to the new default date.
7128           -- Then delete future changes on the %ages.
7129           --
7130           for l_city_rec in csr_city_rec(p_assignment_id, l_defaulting_date)
7131           loop
7132             --
7133             update pay_us_emp_city_tax_rules_f
7134             set    effective_start_date = l_new_default_date
7135             where  effective_start_date = l_defaulting_date
7136             and    assignment_id = p_assignment_id
7137             and    state_code = l_city_rec.state_code
7138             and    county_code = l_city_rec.county_code
7139             and    city_code = l_city_rec.city_code;
7140             --
7141             l_tmp_effective_start_date := l_defaulting_date;
7142             l_tmp_effective_end_date   := l_fed_eed;
7143             maintain_tax_percentage(
7144                       p_assignment_id        => p_assignment_id
7145                      ,p_effective_date       => l_new_default_date
7146                      ,p_state_code           => l_city_rec.state_code
7147                      ,p_county_code          => l_city_rec.county_code
7148                      ,p_city_code            => l_city_rec.city_code
7149                      ,p_datetrack_mode       => 'INSERT_OVERRIDE'
7150                      ,p_effective_start_date => l_tmp_effective_start_date
7151                      ,p_effective_end_date   => l_tmp_effective_end_date
7152                      ,p_calculate_pct        => FALSE
7153                      );
7154             --
7155             --
7156             l_tmp_effective_start_date := l_defaulting_date;
7157             l_tmp_effective_end_date   := l_fed_eed;
7158             maintain_tax_percentage(
7159                       p_assignment_id        => p_assignment_id
7160                      ,p_effective_date       => l_new_default_date
7161                      ,p_state_code           => l_city_rec.state_code
7162                      ,p_county_code          => l_city_rec.county_code
7163                      ,p_city_code            => l_city_rec.city_code
7164                      ,p_datetrack_mode       => 'FUTURE_CHANGE'
7165                      ,p_effective_start_date => l_tmp_effective_start_date
7166                      ,p_effective_end_date   => l_tmp_effective_end_date
7167                      ,p_calculate_pct        => FALSE
7168                      );
7169           --
7170           end loop;        -- l_city_rec
7171           --
7172           --
7173         end if;      -- UPDATE_OVERRIDE, defaulting met, location null?
7174       else           -- UPDATE_OVERRIDE, defaulting not met
7175         --
7176         -- Remove all tax records for this assignment.
7177         --
7178         delete_fed_tax_rule (
7179              p_effective_date        => l_defaulting_date
7180             ,p_datetrack_delete_mode => 'ZAP'
7181             ,p_assignment_id         => p_assignment_id
7182             ,p_delete_routine        => 'ASSIGNMENT'
7183             ,p_effective_start_date  => l_tmp_effective_start_date
7184             ,p_effective_end_date    => l_tmp_effective_end_date
7185             ,p_object_version_number => l_tmp_object_version_number
7186             );
7187         --
7188       end if;        -- UPDATE_OVERRIDE, defaulting_met?
7189 
7190 
7191     else          -- hire date is null, datetrack mode is invalid
7192       --
7193       hr_utility.set_message(801,'HR_7184_DT_MODE_UNKNOWN');
7194       hr_utility.set_message_token('DT_MODE',p_datetrack_mode);
7195       hr_utility.raise_error;
7196       --
7197     end if;       -- hire date is null, branching on datetrack mode
7198   end if;        -- hire date is null and new default < old default
7199   --
7200   --
7201   -- If the state, county or city tax rules for the new location do
7202   -- not exist, create them.
7203   --
7204   if l_new_location_id is not null and l_defaulting_met then
7205     --
7206     create_tax_rules_for_jd(p_effective_date      => l_new_default_date
7207                           ,p_assignment_id        => p_assignment_id
7208                           ,p_state_code           => l_loc_state_code
7209 	  		  ,p_county_code	  => l_loc_county_code
7210 		  	  ,p_city_code		  => l_loc_city_code
7211                           );
7212 
7213     create_tax_rules_for_jd(p_effective_date      => l_new_default_date
7214                           ,p_assignment_id        => p_assignment_id
7215                           ,p_state_code           => l_loc_ovrd_state_code
7216 	  		  ,p_county_code	  => l_loc_ovrd_county_code
7217 		  	  ,p_city_code		  => l_loc_ovrd_city_code
7218                           );
7219   end if;
7220   --
7221   hr_utility.set_location(' Leaving:'||l_proc, 130);
7222   --
7223 exception
7224   --
7225   when l_exit_quietly then
7226     --
7227     hr_utility.set_location(' Leaving:'||l_proc, 135);
7228   --
7229 end move_tax_default_date;
7230 
7231 
7232 --
7233 End pay_us_tax_internal;