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