DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_US_EMP_DT_TAX_RULES

Source


1 package body pay_us_emp_dt_tax_rules as
2 /* $Header: pyusdtw4.pkb 120.19.12010000.1 2008/07/27 23:49:44 appldev ship $ */
3 
4   /* Name        : maintain_element_entry
5      Purpose     : This procedure can be used to create as well as update the vertex
6                    element entry for an assignment. It calls the element entries api
7                    to insert and update the element entry record.
8      Parameters  :
9                   p_assignment_id     -> The assignment for which the vertex elemnt entry is to be
10                                          created/modified.
11                   p_effective_start_date -> The start date of the element entry.
12                   p_effective_end_date   -> The end date of the element entry.
13                   p_session_date         -> This will be helpful for the various update modes.
14                   p_jurisdiction_code    -> The jurisdiction code for which the elemnt entry is to
15                                             created/updated.
16                   p_percentage_time      -> Time in the jurisdiction.
17                   p_mode                 -> If can have the following values :
18                                             'INSERT'
19                                             'CORRECTION',
20                                             'UPDATE',
21                                             'UPDATE_CHANGE_INSERT',
22                                             'UPDATE_OVERRIDE',
23                                             'ZAP'
24                                             'INSERT_OLD'
25     Note : Since the change in location might lead us to scenarios where we might
26            want to do various kinds of updates, all kinds of update modes have been
27            added.
28   */
29 
30   procedure maintain_element_entry (p_assignment_id        in number,
31                                     p_effective_start_date in date,
32                                     p_effective_end_date   in date,
33                                     p_session_date         in date,
34                                     p_jurisdiction_code    in varchar2,
35                                     p_percentage_time      in number,
36                                     p_mode                 in varchar2) is
37 
38    l_inp_value_id_table   hr_entry.number_table;
39    l_scr_value_table      hr_entry.varchar2_table;
40 
41    l_element_type_id      number       :=0;
42    l_inp_name             varchar2(80) :=null;
43    l_inp_val_id           number       :=0;
44    i                      number       := 1;
45    l_element_link_id      number       :=0;
46    l_element_entry_id     number       :=0;
47    l_effective_start_date date;
48    l_effective_end_date   date;
49    l_mode                 varchar2(30);
50    l_delete_flag          varchar2(1) := 'N';
51    l_percent              number;
52    l_end_of_time          date := to_date('31/12/4712','dd/mm/yyyy');
53    l_payroll_installed    boolean := FALSE;
54 
55    /* Cursor to get the vertex element type */
56 
57    cursor csr_tax_element is
58        select pet.element_type_id,
59               piv.input_value_id,
60               piv.name
61        from   PAY_INPUT_VALUES_F  piv,
62               PAY_ELEMENT_TYPES_F pet
63        where  p_session_date between piv.effective_start_date
64                              and piv.effective_end_date
65        and    pet.element_type_id       = piv.element_type_id
66        and    p_session_date between pet.effective_start_date
67                              and pet.effective_end_date
68        and    pet.element_name          = 'VERTEX';
69 
70    /* Cursor to get the element entry for the jurisdiction */
71 
72    cursor csr_ele_entry (p_element_link number, p_inp_val number)is
73        select pee.element_entry_id
74        from   PAY_ELEMENT_ENTRY_VALUES_F pev,
75               PAY_ELEMENT_ENTRIES_F pee
76        where    pev.screen_entry_value   = p_jurisdiction_code
77        and    pev.input_value_id + 0   = p_inp_val
78        and    p_session_date between pev.effective_start_date
79                              and pev.effective_end_date
80        and    pev.element_entry_id     = pee.element_entry_id
81        and    p_session_date between pee.effective_start_date
82                              and pee.effective_end_date
83        and    pee.element_link_id      = p_element_link
84        and    pee.assignment_id        = p_assignment_id;
85 
86    /* Cursor to get the current percentage of the element entry */
87 
88    cursor csr_get_curr_percnt (p_ele_entry_id number, p_inp_val number)is
89        select pev.screen_entry_value
90        from   PAY_ELEMENT_ENTRY_VALUES_F pev
91        where  pev.screen_entry_value is not null
92        and    pev.input_value_id + 0  = p_inp_val
93        and    p_session_date between pev.effective_start_date
94                              and pev.effective_end_date
95        and  pev.element_entry_id     = p_ele_entry_id;
96 
97 
98    begin
99 
100     l_payroll_installed := hr_utility.chk_product_install(p_product =>'Oracle Payroll',
101                                                                p_legislation => 'US');
102     if l_payroll_installed then
103 
104        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry'
105                                ,1);
106 
107        open  csr_tax_element;
108 
109        loop
110 
111           fetch csr_tax_element into l_element_type_id,
112                                      l_inp_val_id,
113                                      l_inp_name;
114 
115           exit when csr_tax_element%NOTFOUND;
116 
117           if upper(l_inp_name) = 'PAY VALUE'
118           then
119                l_inp_value_id_table(1) := l_inp_val_id;
120           elsif upper(l_inp_name) = 'JURISDICTION'
121           then
122                l_inp_value_id_table(2) := l_inp_val_id;
123           elsif upper(l_inp_name) = 'PERCENTAGE'
124           then
125                l_inp_value_id_table(3) := l_inp_val_id;
126           end if;
127        end loop;
128 
129        close csr_tax_element;
130 
131        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry'
132                                ,2);
133 
134        /* Check that all of the input value id for vertex, exists */
135 
136        for i in 1..3 loop
137 
138            if l_inp_value_id_table(i) = null or
139               l_inp_value_id_table(i) = 0
140            then
141                fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
142                fnd_message.set_token('1','VERTEX');
143                fnd_message.raise_error;
144            end if;
145 
146        end loop;
147 
148        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry'
149                                 ,3);
150 
151        /* Get element link */
152        l_element_link_id := hr_entry_api.get_link(
153                                  P_assignment_id   => p_assignment_id,
154                                  P_element_type_id => l_element_type_id,
155                                  P_session_date    => p_effective_start_date);
156 
157        if l_element_link_id is null or l_element_link_id = 0
158        then
159            fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
160            fnd_message.set_token('1','VERTEX');
161            fnd_message.raise_error;
162        end if;
163 
164        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry'
165                                 ,4);
166 
167        /* Store screen entry value in the table */
168 
169        l_scr_value_table(1)     := null;
170        l_scr_value_table(2)     := p_jurisdiction_code;
171        l_scr_value_table(3)     := nvl(fnd_number.number_to_canonical(p_percentage_time),'0');
172 
173        /* assign the parameters to local variables because the element entry procedures
174           expect them to be in out parameters */
175 
176        l_effective_start_date   := p_effective_start_date;
177        l_effective_end_date     := p_effective_end_date;
178        l_mode                   := p_mode;
179 
180        if p_mode = 'INSERT' then
181 
182              /* Create the vertex element entry */
183 
184              hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry' ,5);
185 
186              hr_entry_api.insert_element_entry( P_effective_start_date     => l_effective_start_date,
187                                                 P_effective_end_date       => l_effective_end_date,
188                                                 P_element_entry_id         => l_element_entry_id,
189                                                 P_assignment_id            => p_assignment_id,
190                                                 P_element_link_id          => l_element_link_id,
191                                                 P_creator_type             => 'UT',
192                                                 P_entry_type               => 'E',
193                                                 P_num_entry_values         => 3,
194                                                 P_input_value_id_tbl       => l_inp_value_id_table,
195                                                 P_entry_value_tbl          => l_scr_value_table);
196 
197               hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry' ,6);
198 
199     elsif p_mode in ('CORRECTION','UPDATE', 'UPDATE_CHANGE_INSERT','UPDATE_OVERRIDE','ZAP','DELETE_NEXT_CHANGE','FUTURE_CHANGE','INSERT_OLD') then
200 
201              /* Get the element entry of the vertex element entry that is to be updated
202                 or deleted */
203 
204              hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_element_entry' ,7);
205 
206 
207               open csr_ele_entry(l_element_link_id, l_inp_value_id_table(2));
208 
209               fetch csr_ele_entry into l_element_entry_id;
210 
211               /* Added the delete flag for the upgrade. Currently, there
212                  may be state tax records which might not have a vertex
213                  element entry */
214 
215               if csr_ele_entry%NOTFOUND then
216                 if p_mode in('ZAP','DELETE_NEXT_CHANGE','FUTURE_CHANGE') then
217 
218                     l_delete_flag := 'N';
219                 else
220 
221                     close csr_ele_entry;
222                     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
223                     fnd_message.set_token('PROCEDURE',
224                      'pay_us_emp_dt_tax_rules.maintain_element_entry');
225                     fnd_message.set_token('STEP','1');
226                     fnd_message.raise_error;
227 
228                 end if;
229 
230               else /* found the element entry id */
231 
232                   l_delete_flag := 'Y';
233 
234               end if;
235 
236               close csr_ele_entry;
237 
238               if p_mode = 'INSERT_OLD' then
239 
240                  open csr_get_curr_percnt(l_element_entry_id, l_inp_value_id_table(3));
241 
242                  fetch csr_get_curr_percnt into l_scr_value_table(3);
243 
244                  if csr_get_curr_percnt%NOTFOUND then
245 
246                     close csr_get_curr_percnt;
247                     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
248                     fnd_message.set_token('PROCEDURE',
249                         'pay_us_emp_dt_tax_rules.maintain_element_entry');
250                     fnd_message.set_token('STEP','2');
251                     fnd_message.raise_error;
252 
253                   end if;
254 
255                   close csr_get_curr_percnt;
256 
257                   if p_effective_end_date = l_end_of_time then
258 
259                      l_mode := 'UPDATE';
260 
261                   else
262 
263                      l_mode := 'UPDATE_CHANGE_INSERT';
264 
265                   end if;
266 
267               end if;
268 
269               if p_mode in ('ZAP','DELETE_NEXT_CHANGE','FUTURE_CHANGE')
270                  and l_delete_flag = 'Y' then
271 
272                  hr_entry_api.delete_element_entry(
273                     p_dt_delete_mode           => l_mode,
274                     p_session_date             => p_session_date,
275                     p_element_entry_id         => l_element_entry_id);
276 
277               elsif p_mode in ('CORRECTION','UPDATE', 'UPDATE_CHANGE_INSERT','UPDATE_OVERRIDE','INSERT_OLD') then
278 
279                  hr_entry_api.update_element_entry(
280                     p_dt_update_mode           => l_mode,
281                     p_session_date             => p_session_date,
282                     p_element_entry_id         => l_element_entry_id,
283                     p_num_entry_values         => 3,
284                     p_input_value_id_tbl       => l_inp_value_id_table,
285                     p_entry_value_tbl          => l_scr_value_table);
286 
287               end if;
288 
289            end if;
290 
291     end if;
292 
293   end maintain_element_entry;
294 
295 
296   /* Name        : maintain_wc_ele_entry
297      Purpose     : This procedure can be used to create as well as update the worker's
298                    compensation element entry for an assignment. It calls the element
299                    entries api to insert and update the element entry record.
300      Parameters  :
301                   p_assignment_id     -> The assignment for which the vertex elemnt entry is to be
302                                          created/modified.
303                   p_effective_start_date -> The start date of the element entry.
304                   p_effective_end_date   -> The end date of the element entry.
305                   p_session_date         -> This will be helpful for changing the wc element
306                                             entry for change in the federal record.
307                   p_jurisdiction_code    -> The jurisdiction code for which the elemnt entry is to
308                                             created/updated.
309                   p_mode                 -> If can have the following values :
310                                             'INSERT'
311                                             'CORRECTION',
312                                             'UPDATE',
313                                             'UPDATE_CHANGE_INSERT',
314                                             'UPDATE_OVERRIDE',
315                                             'ZAP'
316     Note : For every change in federal record, we will be changing the worker's comp element entry.
317   */
318 
319   procedure maintain_wc_ele_entry (p_assignment_id        in number,
320                                    p_effective_start_date in date,
321                                    p_effective_end_date   in date,
322                                    p_session_date         in date,
323                                    p_jurisdiction_code    in varchar2,
324                                    p_mode                 in varchar2) is
325 
326    l_inp_value_id_table   hr_entry.number_table;
330    l_inp_name             varchar2(80) :=null;
327    l_scr_value_table      hr_entry.varchar2_table;
328 
329    l_element_type_id      number       :=0;
331    l_inp_val_id           number       :=0;
332    l_element_link_id      number       :=0;
333    l_element_entry_id     number       :=0;
334    l_effective_start_date date         := null;
335    l_effective_end_date   date         := null;
336    l_mode                 varchar2(30);
337    l_delete_flag          varchar2(1);
338    l_payroll_installed    boolean := FALSE;
339 
340    /* Cursor to get the worker's compensation element type */
341 
342    cursor csr_wc_tax_element is
343        select pet.element_type_id,
344               piv.input_value_id,
345               piv.name
346        from   PAY_INPUT_VALUES_F  piv,
347               PAY_ELEMENT_TYPES_F pet
348        where    p_session_date between piv.effective_start_date
349               and piv.effective_end_date
350        and    pet.element_type_id       = piv.element_type_id
351        and    p_session_date between pet.effective_start_date
352               and pet.effective_end_date
353        and    pet.element_name   = 'Workers Compensation'; -- Bug 3354060 FTS on PAY_ELEMENT_TYPES_F was removed. Done by removing
354                                                            -- 'upper' from pet.element_name and 'WORKERS COMPENSATION' was changed to
355                                                            -- 'Workers Compensation'
356 
357 
358    /* Cursor to get the worker's compensation element entry */
359 
360    cursor csr_wc_ele_entry (p_element_link number)is
361        select pee.element_entry_id
362        from   PAY_ELEMENT_ENTRIES_F pee
363        where  p_session_date between pee.effective_start_date
364               and pee.effective_end_date
365        and    pee.element_link_id       = p_element_link
366        and    pee.assignment_id         = p_assignment_id;
367 
368    begin
369 
370     l_payroll_installed := hr_utility.chk_product_install(p_product =>'Oracle Payroll',
371                                                                p_legislation => 'US');
372     if l_payroll_installed then
373 
374        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_wc_ele_entry'
375                                ,1);
376 
377        open  csr_wc_tax_element;
378 
379        loop
380 
381           fetch csr_wc_tax_element into l_element_type_id,
382                                         l_inp_val_id,
383                                         l_inp_name;
384 
385           exit when csr_wc_tax_element%NOTFOUND;
386 
387           if upper(l_inp_name) = 'PAY VALUE' then
388 
389                l_inp_value_id_table(1) := l_inp_val_id;
390 
391           elsif upper(l_inp_name) = 'JURISDICTION' then
392 
393                l_inp_value_id_table(2) := l_inp_val_id;
394 
395           end if;
396 
397        end loop;
398 
399        close csr_wc_tax_element;
400 
401        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_wc_ele_entry'
402                                ,2);
403 
404        /* Check that all of the input value id for vertex, exists */
405 
406        for i in 1..2 loop
407 
408            if l_inp_value_id_table(i) = null or
409               l_inp_value_id_table(i) = 0 then
410 
411                fnd_message.set_name('PAY', 'HR_7713_TAX_ELEMENT_ERROR');
412                fnd_message.raise_error;
413 
414            end if;
415 
416        end loop;
417 
418        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_wc_ele_entry'
419                                 ,3);
420 
421        /* Get element link */
422        l_element_link_id := hr_entry_api.get_link(
423                                  P_assignment_id   => p_assignment_id,
424                                  P_element_type_id => l_element_type_id,
425                                  P_session_date    => p_effective_start_date);
426 
427        if l_element_link_id is null or l_element_link_id = 0
428        then
429 
430            fnd_message.set_name('PAY', 'HR_7713_TAX_ELEMENT_ERROR');
431            fnd_message.raise_error;
432 
433        end if;
434 
435        hr_utility.set_location('pay_us_emp_dt_tax_rules.maintain_wc_ele_entry'
436                                 ,4);
437 
438        /* Store screen entry value in the table */
439 
440        l_scr_value_table(1)     := null;
441        l_scr_value_table(2)     := p_jurisdiction_code;
442 
443        /* assign the parameters to local variables because the element entry procedures
444           expect them to be in out parameters */
445 
446        l_effective_start_date   := p_effective_start_date;
447        l_effective_end_date     := p_effective_end_date;
448        l_mode                   := p_mode;
449 
450        if p_mode = 'INSERT'
451        then
452 
453            /* Insert the worker's compensation element entry */
454 
455            hr_utility.set_location(
456                 'pay_us_emp_dt_tax_rules.maintain_wc_ele_entry' ,5);
457            hr_entry_api.insert_element_entry(
458                 P_effective_start_date     => l_effective_start_date,
459                 P_effective_end_date       => l_effective_end_date,
460                 P_element_entry_id         => l_element_entry_id,
464                 P_entry_type               => 'E',
461                 P_assignment_id            => p_assignment_id,
462                 P_element_link_id          => l_element_link_id,
463                 P_creator_type             => 'UT',
465                 P_num_entry_values         => 2,
466                 P_input_value_id_tbl       => l_inp_value_id_table,
467                 P_entry_value_tbl          => l_scr_value_table);
468 
469             hr_utility.set_location(
470                  'pay_us_emp_dt_tax_rules.maintain_wc_ele_entry' ,8);
471 
472           elsif p_mode in ('CORRECTION', 'UPDATE', 'UPDATE_CHANGE_INSERT','UPDATE_OVERRIDE','ZAP')then
473 
474              /* Update the worker's compensation element entry */
475 
476               open csr_wc_ele_entry(l_element_link_id);
477 
478               fetch csr_wc_ele_entry into l_element_entry_id;
479 
480               if csr_wc_ele_entry%NOTFOUND then
481 
482                 if p_mode in('ZAP','DELETE_NEXT_CHANGE','FUTURE_CHANGE') then
483 
484                     l_delete_flag := 'N';
485                 else
486 
487                   close csr_wc_ele_entry;
488                   fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
489                   fnd_message.set_token('PROCEDURE',
490                  'pay_us_emp_dt_tax_rules.maintain_wc_ele_entry');
491                  fnd_message.set_token('STEP','8');
492                   fnd_message.raise_error;
493 
494                 end if;
495 
496               else /* found the wc element entry id */
497 
498                   l_delete_flag := 'Y';
499 
500               end if;
501 
502               close csr_wc_ele_entry;
503 
504               if p_mode = 'ZAP' and l_delete_flag = 'Y' then
505 
506                  /* All of the tax %age records will be created from the date on which the
507                     default tax rules criteria was met till the end of time. So, we should
508                     get records for the state, county and city for the same effective start
509                     date */
510 
511                  hr_entry_api.delete_element_entry(
512                     p_dt_delete_mode           => l_mode,
513                     p_session_date             => p_session_date,
514                     p_element_entry_id         => l_element_entry_id);
515 
516               elsif p_mode in ('CORRECTION','UPDATE', 'UPDATE_CHANGE_INSERT','UPDATE_OVERRIDE') then
517 
518                  hr_entry_api.update_element_entry(
519                     p_dt_update_mode           => l_mode,
520                     p_session_date             => p_session_date,
521                     p_element_entry_id         => l_element_entry_id,
522                     p_num_entry_values         => 2,
523                     p_input_value_id_tbl       => l_inp_value_id_table,
524                     p_entry_value_tbl          => l_scr_value_table);
525 
526               end if;
527 
528           end if;
529 
530      end if;
531 
532   end maintain_wc_ele_entry;
533 
534 
535   /* Name         : create_tax_percentage
536      Purpose      : This procedure will be called whenever a state tax rule or a county
537                     tax rule or a city tax rule record gets created.
538                     It gets all of the location changes that have taken place for the
539                     assignment and then for each of location change, it creates an element
540                     entry for the jurisdiction depending upon the kind of tax rule record
541                     that is getting created.
542      Parameters   :
543                    p_assignment_id     -> The assignemnt for which the tax rule record and hence
544                                           the percentage record is getting created.
545                    p_state_code        -> If p_state_code is not null and p_county_code is null
546                                           and p_city_code is null then the p_state_code specifies
547                                           the state for which the tax %age record is being created.
548                    p_county_code       -> If p_state_code is not null and p_county_code is not null
549                                           and p_city_code is null then it specifies the county in the
550                                           state of p_state_code, for which the tax percentage record
551                                           is being created.
552                    p_city_code         -> If p_state_code is not null and p_county_code is not null
553                                           and p_city_code is not null then it specifies the city in
554                                           the county of p_county_code for the state of p_state_code,
555                                           for which the tax percentage record is being created.
556                    p_time_in_state     -> If a state %age record is being created then it specifies
557                                           the time in state.
558                    p_time_in_county    -> If a county %age record is being created then it specifies
559                                           the time in county.
560                    p_time_in_city      -> If a city %age record is being created then it specifies
561                                           the time in city.
562   */
563 
564   procedure create_tax_percentage (p_assignment_id       in number,
565                                    p_state_code          in varchar2,
566                                    p_county_code         in varchar2,
570                                    p_time_in_city        in number) is
567                                    p_city_code           in varchar2,
568                                    p_time_in_state       in number,
569                                    p_time_in_county      in number,
571 
572   l_first_location_id    number(15) := 0;
573   l_next_location_id     number(15) := 0;
574   l_first_effective_date date := null;
575   l_first_prev_date      date := null;
576   l_next_effective_date  date := null;
577   l_next_prev_date       date := null;
578   l_jurisdiction_code    varchar2(11);
579   l_default_date         date;
580   l_time                 number;
581   l_ctr                  number := 0;
582   l_mode                 varchar2(30);
583 
584    /* Get Effective_start_Date of the federal record to set the effective date
585       of the element entry. All of the element entries should be created from
586       the date the deafulting tax rules criteria was met. Since the federal
587       record is created from the date the defaulting criteria is met,
588       taking the min(Federal effective start date) will give us the date on
589       which the defaulting criteria was met and hence the effective start date
590       of the element entry */
591 
592    cursor csr_get_eff_date is
593        select min(effective_start_date)
594        from   PAY_US_EMP_FED_TAX_RULES_F
595        where  assignment_id = p_assignment_id;
596 
597   /* Since a change in location may have taken place before the default tax
598      rules criteria is met, we will consider only those locations whose
599      effective_end_date >= default tax rules date i.e. the federal tax rules
600      date. Thus we will be breaking the percentage records only for those
601      change in locations which have taken place after the default tax rules
602     date.
603            L1      L2     L3      L4      L2
604     Asg |--------|------|-------|------|------
605 
606     Federal Tax       |----|---|----|---|---------------
607 
608     Note, in the above example the default tax rules criteria was satisfied
609     after change in location to L2. So, we should not be considering L1.
610     Also, since the same location may get assigned after some time period,
611     we have no other alternative than to query up all the records after the
612     default criteria date and then manual identify the change in locations
613     by means of comparing the location id */
614 
615   cursor csr_get_locations (passignment number, pdefault_date date) is
616     select paf1.location_id,
617            paf1.effective_start_date,
618            paf1.effective_start_date - 1
619     from per_assignments_f paf1
620     where paf1.assignment_id = passignment
621     and paf1.effective_start_date >= pdefault_date
622     order by 2;
623 
624   begin
625 
626     /* Form the jurisdiction code */
627 
628     if p_state_code is not null and p_county_code is null and
629        p_city_code is null
630     then
631 
632            l_jurisdiction_code := p_state_code || '-000-0000';
633            l_time              := p_time_in_state;
634 
635     elsif p_state_code is not null and p_county_code is not null and
636           p_city_code is null
637     then
638 
639              l_jurisdiction_code := p_state_code || '-' || p_county_code ||
640                                     '-0000';
641              l_time              := p_time_in_county;
642 
643     elsif p_state_code is not null and p_county_code is not null and
644           p_city_code is not null
645     then
646 
647             l_jurisdiction_code := p_state_code || '-' || p_county_code ||
648                                     '-' || p_city_code;
649             l_time              := p_time_in_city;
650 
651     end if;
652 
653     /* Get effective Start date of the Federal Tax Rules record */
654 
655     open  csr_get_eff_date;
656 
657     fetch csr_get_eff_date into l_default_date;
658 
659     if l_default_date is null then
660 
661          close csr_get_eff_date;
662          fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
663          fnd_message.set_token('PROCEDURE',
664                  'pay_us_emp_dt_tax_rules.create_tax_percentage');
665          fnd_message.set_token('STEP','1');
666          fnd_message.raise_error;
667 
668     end if;
669 
670     close csr_get_eff_date;
671 
672     /* Get all of the changes in location for the assignment */
673 
674     open csr_get_locations(p_assignment_id, l_default_date);
675 
676     fetch csr_get_locations into l_first_location_id, l_first_effective_date,
677                                  l_first_prev_date;
678     l_ctr := 1;
679 
680     /* The effective start date of the first location might be less than
681        the date on which the default tax criteria was met. So, set the
682        effective start date to the date on which the default tax rules
683       criteria was satisfied */
684 
685     l_first_effective_date := l_default_date;
686 
687     /* Initialise the next location id, next effective date and
688        next prev date  before doing the fetch */
689 
690     l_next_location_id     := null;
691     l_next_effective_date  := null;
692     l_next_prev_date       := null;
693 
694     loop
695 
699                                    l_next_prev_date;
696      exit when csr_get_locations%NOTFOUND;
697 
698      fetch csr_get_locations into l_next_location_id, l_next_effective_date,
700 
701     if l_next_location_id <> l_first_location_id then
702 
703       if l_ctr = 1 then
704 
705          l_mode := 'INSERT';
706 
707       else
708 
709          l_mode := 'UPDATE';
710 
711       end if;
712 
713       /* Call maintain_element_entry for the first location */
714 
715       if l_ctr = 1 then
716 
717        maintain_element_entry(p_assignment_id        => p_assignment_id,
718                               p_effective_start_date => l_first_effective_date,
719                               p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
720                               p_session_date         => l_first_effective_date,
721                               p_jurisdiction_code    => l_jurisdiction_code,
722                               p_percentage_time      => l_time,
723                               p_mode                 => 'INSERT');
724 
725       else
726 
727 
728        maintain_element_entry(p_assignment_id        => p_assignment_id,
729                               p_effective_start_date => l_first_effective_date,
730                               p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
731                               p_session_date         => l_first_effective_date,
732                               p_jurisdiction_code    => l_jurisdiction_code,
733                               p_percentage_time      => l_time,
734                               p_mode                 => 'UPDATE');
735       end if;
736 
737       l_first_location_id    := l_next_location_id;
738       l_first_effective_date := l_next_effective_date;
739       l_first_prev_date      := l_next_prev_date;
740       /* Initialise the next location id, next effective date and
741          next prev date  before doing the fetch */
742       l_next_location_id     := null;
743       l_next_effective_date  := null;
744       l_next_prev_date       := null;
745       l_ctr := l_ctr + 1;
746 
747      end if;
748 
749     end loop;
750 
751     close csr_get_locations;
752 
753     /* Create the element entry for the last change in location . The last
754        element entry record for the percentage time should be created till
755        end of time. hence, 31-dec-4712. */
756 
757     if l_ctr = 1 then
758 
759 
760       maintain_element_entry(p_assignment_id        => p_assignment_id,
761                            p_effective_start_date => l_first_effective_date,
762                            p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
763                            p_session_date         => l_first_effective_date,
764                            p_jurisdiction_code    => l_jurisdiction_code,
765                            p_percentage_time      => l_time,
766                            p_mode                 => 'INSERT');
767     else
768 
769 
770        maintain_element_entry(p_assignment_id        => p_assignment_id,
771                            p_effective_start_date => l_first_effective_date,
772                            p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
773                            p_session_date         => l_first_effective_date,
774                            p_jurisdiction_code    => l_jurisdiction_code,
775                            p_percentage_time      => l_time,
776                            p_mode                 => 'UPDATE');
777 
778     end if;
779 
780 
781 
782   end create_tax_percentage;
783 
784 
785   /* Name        : insert_fed_tax_row
786      Purpose     : To create the federal tax rule record. It also calls the
787                    maintain_wc_ele_entry routine to create the worker's compensation
788                    for the SUI state
789   */
790 
791   procedure insert_fed_tax_row ( p_emp_fed_tax_rule_id in out nocopy number,
792 				                 p_effective_start_date in date,
793                                   p_effective_end_date in date,
794                                   p_assignment_id in number,
795                                   p_sui_state_code in varchar2,
796                                   p_sui_jurisdiction_code in varchar2,
797                                   p_business_group_id in number,
798                                   p_additional_wa_amount in number,
799                                   p_filing_status_code in varchar2,
800                                   p_fit_override_amount in number,
801  				                  p_fit_override_rate in number,
802                                   p_withholding_allowances in number,
803                                   p_cumulative_taxation in varchar2,
804                                   p_eic_filing_status_code in varchar2,
805                                   p_fit_additional_tax in number,
806                                   p_fit_exempt in varchar2,
807                                   p_futa_tax_exempt in varchar2,
808                                   p_medicare_tax_exempt in varchar2,
809                                   p_ss_tax_exempt in varchar2,
810                                   p_wage_exempt in varchar2,
811                                   p_statutory_employee in varchar2,
815                                   p_attribute_category        in varchar2,
812                                   p_w2_filed_year in number,
813                                   p_supp_tax_override_rate in number,
814                                   p_excessive_wa_reject_date in date,
816                                   p_attribute1                in varchar2,
817                                   p_attribute2                in varchar2,
818                                   p_attribute3                in varchar2,
819                                   p_attribute4                in varchar2,
820                                   p_attribute5                in varchar2,
821                                   p_attribute6                in varchar2,
822                                   p_attribute7                in varchar2,
823                                   p_attribute8                in varchar2,
824                                   p_attribute9                in varchar2,
825                                   p_attribute10               in varchar2,
826                                   p_attribute11               in varchar2,
827                                   p_attribute12               in varchar2,
828                                   p_attribute13               in varchar2,
829                                   p_attribute14               in varchar2,
830                                   p_attribute15               in varchar2,
831                                   p_attribute16               in varchar2,
832                                   p_attribute17               in varchar2,
833                                   p_attribute18               in varchar2,
834                                   p_attribute19               in varchar2,
835                                   p_attribute20               in varchar2,
836                                   p_attribute21               in varchar2,
837                                   p_attribute22               in varchar2,
838                                   p_attribute23               in varchar2,
839                                   p_attribute24               in varchar2,
840                                   p_attribute25               in varchar2,
841                                   p_attribute26               in varchar2,
842                                   p_attribute27               in varchar2,
843                                   p_attribute28               in varchar2,
844                                   p_attribute29               in varchar2,
845                                   p_attribute30               in varchar2,
846                                   p_fed_information_category  in varchar2,
847                                   p_fed_information1          in varchar2,
848                                   p_fed_information2          in varchar2,
849                                   p_fed_information3          in varchar2,
850                                   p_fed_information4          in varchar2,
851                                   p_fed_information5          in varchar2,
852                                   p_fed_information6          in varchar2,
853                                   p_fed_information7          in varchar2,
854                                   p_fed_information8          in varchar2,
855                                   p_fed_information9          in varchar2,
856                                   p_fed_information10         in varchar2,
857                                   p_fed_information11         in varchar2,
858                                   p_fed_information12         in varchar2,
859                                   p_fed_information13         in varchar2,
860                                   p_fed_information14         in varchar2,
861                                   p_fed_information15         in varchar2,
862                                   p_fed_information16         in varchar2,
863                                   p_fed_information17         in varchar2,
864                                   p_fed_information18         in varchar2,
865                                   p_fed_information19         in varchar2,
866                                   p_fed_information20         in varchar2,
867                                   p_fed_information21         in varchar2,
868                                   p_fed_information22         in varchar2,
869                                   p_fed_information23         in varchar2,
870                                   p_fed_information24         in varchar2,
871                                   p_fed_information25         in varchar2,
872                                   p_fed_information26         in varchar2,
873                                   p_fed_information27         in varchar2,
874                                   p_fed_information28         in varchar2,
875                                   p_fed_information29         in varchar2,
876                                   p_fed_information30         in varchar2,
877                                   p_mode  in varchar2) is
878 
879 
880   l_step   number;
881   l_pos    number;
882 
883   l_new_date             date;
884   cursor csr_fed_tax_rule_id is
885   select PAY_US_EMP_FED_TAX_RULES_S.nextval
886   from sys.DUAL;
887 
888   begin
889 
890 
891      hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_fed_tax_row'||
892                              ' - Opening cursor', 1);
893 
894      if p_mode = 'INSERT' then
895 
896        open csr_fed_tax_rule_id;
897 
898        hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_fed_tax_row'||
899                              ' - Fetching cursor', 2);
900 
904                              ' - Closing cursor', 3);
901        fetch csr_fed_tax_rule_id into p_emp_fed_tax_rule_id;
902 
903        hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_fed_tax_row'||
905 
906        close csr_fed_tax_rule_id;
907 
908 
909        hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_fed_tax_row'||
910                              ' - inserting row', 4);
911 
912      end if;
913 
914      l_step := 1;
915 
916      if p_mode = 'UPDATE' then
917 
918           select p_effective_start_date -1
919           into l_new_date
920           from DUAL;
921 
922           /* Update the Federal tax record as of the p_effective_start_date */
923 
924           l_step := 2;
925 
926           update PAY_US_EMP_FED_TAX_RULES_F
927           set    effective_end_date = l_new_date
928           where assignment_id        = p_assignment_id
929           and   effective_end_date   = p_effective_end_date;
930 
931       end if;
932 
933      l_step := 3;
934 
935      insert into PAY_US_EMP_FED_TAX_RULES_F
936      (emp_fed_tax_rule_id,
937       effective_start_date,
938       effective_end_date,
939       assignment_id,
940       sui_state_code,
941       sui_jurisdiction_code,
942       business_group_id,
943       additional_wa_amount,
944       filing_status_code,
945       fit_override_amount,
946       fit_override_rate,
947       withholding_allowances,
948       cumulative_taxation,
949       eic_filing_status_code,
950       fit_additional_tax,
951       fit_exempt,
952       futa_tax_exempt,
953       medicare_tax_exempt,
954       ss_tax_exempt,
955       wage_exempt,
956       statutory_employee,
957       w2_filed_year,
958       supp_tax_override_rate,
959       excessive_wa_reject_date,
960       object_version_number,
961       attribute_category,
962       attribute1,
963       attribute2,
964       attribute3,
965       attribute4,
966       attribute5,
967       attribute6,
968       attribute7,
969       attribute8,
970       attribute9,
971       attribute10,
972       attribute11,
973       attribute12,
974       attribute13,
975       attribute14,
976       attribute15,
977       attribute16,
978       attribute17,
979       attribute18,
980       attribute19,
981       attribute20,
982       attribute21,
983       attribute22,
984       attribute23,
985       attribute24,
986       attribute25,
987       attribute26,
988       attribute27,
989       attribute28,
990       attribute29,
991       attribute30,
992       fed_information_category,
993       fed_information1,
994       fed_information2,
995       fed_information3,
996       fed_information4,
997       fed_information5,
998       fed_information6,
999       fed_information7,
1000       fed_information8,
1001       fed_information9,
1002       fed_information10,
1003       fed_information11,
1004       fed_information12,
1005       fed_information13,
1006       fed_information14,
1007       fed_information15,
1008       fed_information16,
1009       fed_information17,
1010       fed_information18,
1011       fed_information19,
1012       fed_information20,
1013       fed_information21,
1014       fed_information22,
1015       fed_information23,
1016       fed_information24,
1017       fed_information25,
1018       fed_information26,
1019       fed_information27,
1020       fed_information28,
1021       fed_information29,
1022       fed_information30)
1023      values
1024      (p_emp_fed_tax_rule_id,
1025       p_effective_start_date,
1026       p_effective_end_date,
1027       p_assignment_id,
1028       p_sui_state_code,
1029       p_sui_jurisdiction_code,
1030       p_business_group_id,
1031       p_additional_wa_amount,
1032       lpad(p_filing_status_code,2,'0'),
1033       p_fit_override_amount,
1034       p_fit_override_rate,
1035       p_withholding_allowances,
1036       p_cumulative_taxation,
1037       p_eic_filing_status_code,
1038       p_fit_additional_tax,
1039       p_fit_exempt,
1040       p_futa_tax_exempt,
1041       p_medicare_tax_exempt,
1042       p_ss_tax_exempt,
1043       p_wage_exempt,
1044       p_statutory_employee,
1045       p_w2_filed_year,
1046       p_supp_tax_override_rate,
1047       p_excessive_wa_reject_date,
1048       0,
1049       p_attribute_category,
1050       p_attribute1,
1051       p_attribute2,
1052       p_attribute3,
1053       p_attribute4,
1054       p_attribute5,
1055       p_attribute6,
1056       p_attribute7,
1057       p_attribute8,
1058       p_attribute9,
1059       p_attribute10,
1060       p_attribute11,
1061       p_attribute12,
1062       p_attribute13,
1063       p_attribute14,
1064       p_attribute15,
1065       p_attribute16,
1066       p_attribute17,
1067       p_attribute18,
1068       p_attribute19,
1069       p_attribute20,
1070       p_attribute21,
1071       p_attribute22,
1072       p_attribute23,
1073       p_attribute24,
1074       p_attribute25,
1075       p_attribute26,
1079       p_attribute30,
1076       p_attribute27,
1077       p_attribute28,
1078       p_attribute29,
1080       p_fed_information_category,
1081       p_fed_information1,
1082       p_fed_information2,
1083       p_fed_information3,
1084       p_fed_information4,
1085       p_fed_information5,
1086       p_fed_information6,
1087       p_fed_information7,
1088       p_fed_information8,
1089       p_fed_information9,
1090       p_fed_information10,
1091       p_fed_information11,
1092       p_fed_information12,
1093       p_fed_information13,
1094       p_fed_information14,
1095       p_fed_information15,
1096       p_fed_information16,
1097       p_fed_information17,
1098       p_fed_information18,
1099       p_fed_information19,
1100       p_fed_information20,
1101       p_fed_information21,
1102       p_fed_information22,
1103       p_fed_information23,
1104       p_fed_information24,
1105       p_fed_information25,
1106       p_fed_information26,
1107       p_fed_information27,
1108       p_fed_information28,
1109       p_fed_information29,
1110       p_fed_information30);
1111 
1112 
1113       /* create workers compensation element entry for the sui state in
1114          the federal record */
1115 
1116       hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_fed_tax_row'||
1117                              ' - inserting row', 5);
1118       l_step := 4;
1119 
1120       if  hr_utility.chk_product_install(p_product =>'Oracle Payroll',
1121                                          p_legislation => 'US') then
1122 
1123          maintain_wc_ele_entry (p_assignment_id      => p_assignment_id,
1124                            p_effective_start_date => p_effective_start_date,
1125                            p_effective_end_date   => p_effective_end_date,
1126                            p_session_date         => p_effective_start_date,
1127                            p_jurisdiction_code    => p_sui_jurisdiction_code,
1128                            p_mode                 => p_mode);
1129       end if;
1130 
1131       exception
1132       when others then
1133       l_pos := instr(substr(sqlerrm,1,60),'HR_7713_TAX_ELEMENT_ERROR');
1134 
1135       if l_pos = 0 then
1136         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
1137         fnd_message.set_token('PROCEDURE',
1138                        'pay_us_emp_dt_tax_rules.insert_fed_tax_row - '|| substr(sqlerrm,1,60));
1139         fnd_message.set_token('STEP',to_char(l_step));
1140         fnd_message.raise_error;
1141 
1142       else
1143          fnd_message.set_name('PAY', 'HR_7713_TAX_ELEMENT_ERROR');
1144          fnd_message.raise_error;
1145       end if;
1146   end insert_fed_tax_row;
1147 
1148 
1149   /* Name        : insert_state_tax_row
1150      Purpose     : To create the state tax rule record. It also calls the
1151                    create_tax_percentage routine to create the %age records
1152                    for the state, for every change in location of the assignment
1153   */
1154 
1155   procedure insert_state_tax_row ( p_row_id in out nocopy varchar2,
1156                                    p_emp_state_tax_rule_id in out nocopy number,
1157                                    p_effective_start_date in date,
1158                                    p_effective_end_date in date,
1159                                    p_assignment_id in number,
1160                                    p_state_code in varchar2,
1161                                    p_jurisdiction_code in varchar2,
1162                                    p_business_group_id in number,
1163                                    p_additional_wa_amount in number,
1164                                    p_filing_status_code in varchar2,
1165                                    p_remainder_percent in number,
1166                                    p_secondary_wa in number,
1167                                    p_sit_additional_tax in number,
1168                                    p_sit_override_amount in number,
1169                                    p_sit_override_rate in number,
1170                                    p_withholding_allowances in number,
1171                                    p_excessive_wa_reject_date in date,
1172                                    p_sdi_exempt in varchar2,
1173                                    p_sit_exempt in varchar2,
1174                                    p_sit_optional_calc_ind in varchar2,
1175                                    p_state_non_resident_cert in varchar2,
1176                                    p_sui_exempt in varchar2,
1177                                    p_wc_exempt in varchar2,
1178                                    p_wage_exempt in varchar2,
1179                                    p_sui_wage_base_override_amt in number,
1180                                    p_supp_tax_override_rate in number,
1181                                    p_time_in_state in number,
1182                                    p_attribute_category        in varchar2,
1183                                    p_attribute1                in varchar2,
1184                                    p_attribute2                in varchar2,
1185                                    p_attribute3                in varchar2,
1186                                    p_attribute4                in varchar2,
1187                                    p_attribute5                in varchar2,
1188                                    p_attribute6                in varchar2,
1189                                    p_attribute7                in varchar2,
1193                                    p_attribute11               in varchar2,
1190                                    p_attribute8                in varchar2,
1191                                    p_attribute9                in varchar2,
1192                                    p_attribute10               in varchar2,
1194                                    p_attribute12               in varchar2,
1195                                    p_attribute13               in varchar2,
1196                                    p_attribute14               in varchar2,
1197                                    p_attribute15               in varchar2,
1198                                    p_attribute16               in varchar2,
1199                                    p_attribute17               in varchar2,
1200                                    p_attribute18               in varchar2,
1201                                    p_attribute19               in varchar2,
1202                                    p_attribute20               in varchar2,
1203                                    p_attribute21               in varchar2,
1204                                    p_attribute22               in varchar2,
1205                                    p_attribute23               in varchar2,
1206                                    p_attribute24               in varchar2,
1207                                    p_attribute25               in varchar2,
1208                                    p_attribute26               in varchar2,
1209                                    p_attribute27               in varchar2,
1210                                    p_attribute28               in varchar2,
1211                                    p_attribute29               in varchar2,
1212                                    p_attribute30               in varchar2,
1213                                    p_sta_information_category  in varchar2,
1214                                    p_sta_information1          in varchar2,
1215                                    p_sta_information2          in varchar2,
1216                                    p_sta_information3          in varchar2,
1217                                    p_sta_information4          in varchar2,
1218                                    p_sta_information5          in varchar2,
1219                                    p_sta_information6          in varchar2,
1220                                    p_sta_information7          in varchar2,
1221                                    p_sta_information8          in varchar2,
1222                                    p_sta_information9          in varchar2,
1223                                    p_sta_information10         in varchar2,
1224                                    p_sta_information11         in varchar2,
1225                                    p_sta_information12         in varchar2,
1226                                    p_sta_information13         in varchar2,
1227                                    p_sta_information14         in varchar2,
1228                                    p_sta_information15         in varchar2,
1229                                    p_sta_information16         in varchar2,
1230                                    p_sta_information17         in varchar2,
1231                                    p_sta_information18         in varchar2,
1232                                    p_sta_information19         in varchar2,
1233                                    p_sta_information20         in varchar2,
1234                                    p_sta_information21         in varchar2,
1235                                    p_sta_information22         in varchar2,
1236                                    p_sta_information23         in varchar2,
1237                                    p_sta_information24         in varchar2,
1238                                    p_sta_information25         in varchar2,
1239                                    p_sta_information26         in varchar2,
1240                                    p_sta_information27         in varchar2,
1241                                    p_sta_information28         in varchar2,
1242                                    p_sta_information29         in varchar2,
1243                                    p_sta_information30         in varchar2
1244                                    ) is
1245 
1246   cursor csr_state_tax_rule_id is
1247     select PAY_US_EMP_STATE_TAX_RULES_S.nextval
1248     from sys.DUAL;
1249 
1250   cursor csr_get_row_id is
1251     select rowidtochar(rowid)
1252     from PAY_US_EMP_STATE_TAX_RULES_F str
1253     where str.emp_state_tax_rule_id = p_emp_state_tax_rule_id
1254     and   str.effective_start_date  = p_effective_start_date
1255     and   str.effective_end_date    = p_effective_end_date;
1256 
1257   begin
1258 
1259 
1260      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
1261                              ' - Opening cursor', 1);
1262 
1263      open csr_state_tax_rule_id;
1264 
1265      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
1266                              ' - Fetching cursor', 2);
1267 
1268      fetch csr_state_tax_rule_id into p_emp_state_tax_rule_id;
1269 
1270      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
1271                              ' - Closing cursor', 3);
1272 
1273      close csr_state_tax_rule_id;
1274 
1275 
1276      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
1277                              ' - inserting row', 4);
1278 
1279      insert into PAY_US_EMP_STATE_TAX_RULES_F
1280      (emp_state_tax_rule_id,
1281       effective_start_date,
1282       effective_end_date,
1283       assignment_id,
1287       additional_wa_amount,
1284       state_code,
1285       jurisdiction_code,
1286       business_group_id,
1288       filing_status_code,
1289       remainder_percent,
1290       secondary_wa,
1291       sit_additional_tax,
1292       sit_override_amount,
1293       sit_override_rate,
1294       withholding_allowances,
1295       excessive_wa_reject_date,
1296       sdi_exempt,
1297       sit_exempt,
1298       sit_optional_calc_ind,
1299       state_non_resident_cert,
1300       sui_exempt,
1301       wc_exempt,
1302       wage_exempt,
1303       sui_wage_base_override_amount,
1304       supp_tax_override_rate,
1305       object_version_number,
1306       attribute_category,
1307       attribute1,
1308       attribute2,
1309       attribute3,
1310       attribute4,
1311       attribute5,
1312       attribute6,
1313       attribute7,
1314       attribute8,
1315       attribute9,
1316       attribute10,
1317       attribute11,
1318       attribute12,
1319       attribute13,
1320       attribute14,
1321       attribute15,
1322       attribute16,
1323       attribute17,
1324       attribute18,
1325       attribute19,
1326       attribute20,
1327       attribute21,
1328       attribute22,
1329       attribute23,
1330       attribute24,
1331       attribute25,
1332       attribute26,
1333       attribute27,
1334       attribute28,
1335       attribute29,
1336       attribute30,
1337       sta_information_category,
1338       sta_information1,
1339       sta_information2,
1340       sta_information3,
1341       sta_information4,
1342       sta_information5,
1343       sta_information6,
1344       sta_information7,
1345       sta_information8,
1346       sta_information9,
1347       sta_information10,
1348       sta_information11,
1349       sta_information12,
1350       sta_information13,
1351       sta_information14,
1352       sta_information15,
1353       sta_information16,
1354       sta_information17,
1355       sta_information18,
1356       sta_information19,
1357       sta_information20,
1358       sta_information21,
1359       sta_information22,
1360       sta_information23,
1361       sta_information24,
1362       sta_information25,
1363       sta_information26,
1364       sta_information27,
1365       sta_information28,
1366       sta_information29,
1367       sta_information30)
1368      values
1369      (p_emp_state_tax_rule_id,
1370       p_effective_start_date,
1371       p_effective_end_date,
1372       p_assignment_id,
1373       p_state_code,
1374       p_jurisdiction_code,
1375       p_business_group_id,
1376       p_additional_wa_amount,
1377       lpad(p_filing_status_code,2,'0'),
1378       p_remainder_percent,
1379       p_secondary_wa,
1380       p_sit_additional_tax,
1381       p_sit_override_amount,
1382       p_sit_override_rate,
1383       p_withholding_allowances,
1384       p_excessive_wa_reject_date,
1385       p_sdi_exempt,
1386       p_sit_exempt,
1387       p_sit_optional_calc_ind,
1388       p_state_non_resident_cert,
1389       p_sui_exempt,
1390       p_wc_exempt,
1391       p_wage_exempt,
1392       p_sui_wage_base_override_amt,
1393       p_supp_tax_override_rate,
1394       0,
1395       p_attribute_category,
1396       p_attribute1,
1397       p_attribute2,
1398       p_attribute3,
1399       p_attribute4,
1400       p_attribute5,
1401       p_attribute6,
1402       p_attribute7,
1403       p_attribute8,
1404       p_attribute9,
1405       p_attribute10,
1406       p_attribute11,
1407       p_attribute12,
1408       p_attribute13,
1409       p_attribute14,
1410       p_attribute15,
1411       p_attribute16,
1412       p_attribute17,
1413       p_attribute18,
1414       p_attribute19,
1415       p_attribute20,
1416       p_attribute21,
1417       p_attribute22,
1418       p_attribute23,
1419       p_attribute24,
1420       p_attribute25,
1421       p_attribute26,
1422       p_attribute27,
1423       p_attribute28,
1424       p_attribute29,
1425       p_attribute30,
1426       p_sta_information_category,
1427       p_sta_information1,
1428       p_sta_information2,
1429       p_sta_information3,
1430       p_sta_information4,
1431       p_sta_information5,
1432       p_sta_information6,
1433       p_sta_information7,
1434       p_sta_information8,
1435       p_sta_information9,
1436       p_sta_information10,
1437       p_sta_information11,
1438       p_sta_information12,
1439       p_sta_information13,
1440       p_sta_information14,
1441       p_sta_information15,
1442       p_sta_information16,
1443       p_sta_information17,
1444       p_sta_information18,
1445       p_sta_information19,
1446       p_sta_information20,
1447       p_sta_information21,
1448       p_sta_information22,
1449       p_sta_information23,
1450       p_sta_information24,
1451       p_sta_information25,
1452       p_sta_information26,
1453       p_sta_information27,
1454       p_sta_information28,
1455       p_sta_information29,
1456       p_sta_information30);
1457 
1458      if sql%notfound then
1462         fnd_message.set_token('STEP','4');
1459         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
1460         fnd_message.set_token('PROCEDURE',
1461                         'pay_us_emp_dt_tax_rules.insert_state_tax_row');
1463         fnd_message.raise_error;
1464      end if;
1465 
1466      open csr_get_row_id;
1467 
1468      fetch csr_get_row_id into p_row_id;
1469 
1470      if csr_get_row_id%NOTFOUND then
1471         close csr_get_row_id;
1472         raise no_data_found;
1473      end if;
1474 
1475      close csr_get_row_id;
1476 
1477      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
1478                              ' - creating %age record ', 5);
1479 
1480      /* Get the changes in location of an assignment.
1481        For each change in location, create vertex element entry with
1482        time in state as 0% - if Payroll is installed */
1483 
1484      if hr_utility.chk_product_install(p_product     =>'Oracle Payroll',
1485                                        p_legislation => 'US') then
1486 
1487         create_tax_percentage (p_assignment_id => p_assignment_id,
1488                                p_state_code    => p_state_code,
1489                                p_county_code   => null,
1490                                p_city_code     => null,
1491                                p_time_in_state => nvl(p_time_in_state,0),
1492                                p_time_in_county => 0,
1493                                p_time_in_city   => 0);
1494 
1495         /* Insert row into the pay_us_asg_reporting table */
1496 
1497         pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
1498                                            P_jurisdiction  =>  p_jurisdiction_code,
1499                                            P_tax_unit_id   =>  NULL );
1500       end if;
1501 
1502   end insert_state_tax_row;
1503 
1504 
1505   /* Name        : insert_county_tax_row
1506      Purpose     : To create the county tax rule record. It also calls the
1507                    create_tax_percentage routine to create the %age records
1508                    for the county, for every change in location of the assignment
1509   */
1510   procedure insert_county_tax_row ( p_row_id in out nocopy varchar2,
1511                                     p_emp_county_tax_rule_id in out nocopy number,
1512                                     p_effective_start_date in date,
1513                                     p_effective_end_date in date,
1514                                     p_assignment_id in number,
1515                                     p_state_code in varchar2,
1516                                     p_county_code in varchar2,
1517                                     p_business_group_id in number,
1518                                     p_additional_wa_rate in number,
1519                                     p_filing_status_code in varchar2,
1520                                     p_jurisdiction_code in varchar2,
1521                                     p_lit_additional_tax in number,
1522                                     p_lit_override_amount in number,
1523                                     p_lit_override_rate in number,
1524                                     p_withholding_allowances in number,
1525                                     p_lit_exempt in varchar2,
1526                                     p_sd_exempt in varchar2,
1527                                     p_ht_exempt in varchar2,
1528                                     p_wage_exempt in varchar2,
1529                                     p_school_district_code in varchar2,
1530                                     p_time_in_county in number,
1531                                     p_attribute_category        in varchar2,
1532                                     p_attribute1                in varchar2,
1533                                     p_attribute2                in varchar2,
1534                                     p_attribute3                in varchar2,
1535                                     p_attribute4                in varchar2,
1536                                     p_attribute5                in varchar2,
1537                                     p_attribute6                in varchar2,
1538                                     p_attribute7                in varchar2,
1539                                     p_attribute8                in varchar2,
1540                                     p_attribute9                in varchar2,
1541                                     p_attribute10               in varchar2,
1542                                     p_attribute11               in varchar2,
1543                                     p_attribute12               in varchar2,
1544                                     p_attribute13               in varchar2,
1545                                     p_attribute14               in varchar2,
1546                                     p_attribute15               in varchar2,
1547                                     p_attribute16               in varchar2,
1548                                     p_attribute17               in varchar2,
1549                                     p_attribute18               in varchar2,
1550                                     p_attribute19               in varchar2,
1551                                     p_attribute20               in varchar2,
1552                                     p_attribute21               in varchar2,
1553                                     p_attribute22               in varchar2,
1554                                     p_attribute23               in varchar2,
1555                                     p_attribute24               in varchar2,
1559                                     p_attribute28               in varchar2,
1556                                     p_attribute25               in varchar2,
1557                                     p_attribute26               in varchar2,
1558                                     p_attribute27               in varchar2,
1560                                     p_attribute29               in varchar2,
1561                                     p_attribute30               in varchar2,
1562                                     p_cnt_information_category  in varchar2,
1563                                     p_cnt_information1          in varchar2,
1564                                     p_cnt_information2          in varchar2,
1565                                     p_cnt_information3          in varchar2,
1566                                     p_cnt_information4          in varchar2,
1567                                     p_cnt_information5          in varchar2,
1568                                     p_cnt_information6          in varchar2,
1569                                     p_cnt_information7          in varchar2,
1570                                     p_cnt_information8          in varchar2,
1571                                     p_cnt_information9          in varchar2,
1572                                     p_cnt_information10         in varchar2,
1573                                     p_cnt_information11         in varchar2,
1574                                     p_cnt_information12         in varchar2,
1575                                     p_cnt_information13         in varchar2,
1576                                     p_cnt_information14         in varchar2,
1577                                     p_cnt_information15         in varchar2,
1578                                     p_cnt_information16         in varchar2,
1579                                     p_cnt_information17         in varchar2,
1580                                     p_cnt_information18         in varchar2,
1581                                     p_cnt_information19         in varchar2,
1582                                     p_cnt_information20         in varchar2,
1583                                     p_cnt_information21         in varchar2,
1584                                     p_cnt_information22         in varchar2,
1585                                     p_cnt_information23         in varchar2,
1586                                     p_cnt_information24         in varchar2,
1587                                     p_cnt_information25         in varchar2,
1588                                     p_cnt_information26         in varchar2,
1589                                     p_cnt_information27         in varchar2,
1590                                     p_cnt_information28         in varchar2,
1591                                     p_cnt_information29         in varchar2,
1592                                     p_cnt_information30         in varchar2) is
1593 
1594   cursor csr_county_tax_rule_id is
1595     select PAY_US_EMP_COUNTY_TAX_RULES_S.nextval
1596     from sys.DUAL;
1597 
1598   cursor csr_get_row_id is
1599     select rowidtochar(rowid)
1600     from PAY_US_EMP_COUNTY_TAX_RULES_F ctr
1601     where ctr.emp_county_tax_rule_id = p_emp_county_tax_rule_id
1602     and   ctr.effective_start_date  = p_effective_start_date
1603     and   ctr.effective_end_date    = p_effective_end_date;
1604 
1605   begin
1606 
1607     if p_school_district_code is not null
1608     then
1609 
1610        /* Check that the school district is assigned to only one county/city
1611           at a given point in time */
1612 
1613         pay_us_emp_dt_tax_val.check_school_district(
1614                               p_assignment => p_assignment_id,
1615                               p_start_date => p_effective_start_date,
1616                               p_end_date   => p_effective_end_date,
1617                               p_mode       => 'I',
1618                               p_rowid      => null);
1619     end if;
1620 
1621     hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_county_tax_row'||
1622                              ' - Opening cursor', 1);
1623 
1624      open csr_county_tax_rule_id;
1625 
1626     hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_county_tax_row'||
1627                              ' - Fetching cursor', 2);
1628 
1629      fetch csr_county_tax_rule_id into p_emp_county_tax_rule_id;
1630 
1631     hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_county_tax_row'||
1632                              ' - Closing cursor', 3);
1633 
1634      close csr_county_tax_rule_id;
1635 
1636 
1637     hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_county_tax_row'||
1638                              ' - inserting row', 4);
1639 
1640 
1641      insert into pay_us_emp_county_tax_rules_f
1642      (emp_county_tax_rule_id,
1643       effective_start_date,
1644       effective_end_date,
1645       assignment_id,
1646       state_code,
1647       county_code,
1648       business_group_id,
1649       additional_wa_rate,
1650       filing_status_code,
1651       jurisdiction_code,
1652       lit_additional_tax,
1653       lit_override_amount,
1654       lit_override_rate,
1655       withholding_allowances,
1656       lit_exempt,
1657       sd_exempt,
1658       ht_exempt,
1659       wage_exempt,
1660       school_district_code,
1661       object_version_number,
1662       attribute_category,
1663       attribute1,
1664       attribute2,
1665       attribute3,
1666       attribute4,
1667       attribute5,
1668       attribute6,
1669       attribute7,
1670       attribute8,
1671       attribute9,
1675       attribute13,
1672       attribute10,
1673       attribute11,
1674       attribute12,
1676       attribute14,
1677       attribute15,
1678       attribute16,
1679       attribute17,
1680       attribute18,
1681       attribute19,
1682       attribute20,
1683       attribute21,
1684       attribute22,
1685       attribute23,
1686       attribute24,
1687       attribute25,
1688       attribute26,
1689       attribute27,
1690       attribute28,
1691       attribute29,
1692       attribute30,
1693       cnt_information_category,
1694       cnt_information1,
1695       cnt_information2,
1696       cnt_information3,
1697       cnt_information4,
1698       cnt_information5,
1699       cnt_information6,
1700       cnt_information7,
1701       cnt_information8,
1702       cnt_information9,
1703       cnt_information10,
1704       cnt_information11,
1705       cnt_information12,
1706       cnt_information13,
1707       cnt_information14,
1708       cnt_information15,
1709       cnt_information16,
1710       cnt_information17,
1711       cnt_information18,
1712       cnt_information19,
1713       cnt_information20,
1714       cnt_information21,
1715       cnt_information22,
1716       cnt_information23,
1717       cnt_information24,
1718       cnt_information25,
1719       cnt_information26,
1720       cnt_information27,
1721       cnt_information28,
1722       cnt_information29,
1723       cnt_information30)
1724      values
1725      (p_emp_county_tax_rule_id,
1726       p_effective_start_date,
1727       p_effective_end_date,
1728       p_assignment_id,
1729       p_state_code,
1730       p_county_code,
1731       p_business_group_id,
1732       p_additional_wa_rate,
1733       lpad(p_filing_status_code,2,'0'),
1734       p_jurisdiction_code,
1735       p_lit_additional_tax,
1736       p_lit_override_amount,
1737       p_lit_override_rate,
1738       p_withholding_allowances,
1739       p_lit_exempt,
1740       p_sd_exempt,
1741       p_ht_exempt,
1742       p_wage_exempt,
1743       p_school_district_code,
1744       0,
1745       p_attribute_category,
1746       p_attribute1,
1747       p_attribute2,
1748       p_attribute3,
1749       p_attribute4,
1750       p_attribute5,
1751       p_attribute6,
1752       p_attribute7,
1753       p_attribute8,
1754       p_attribute9,
1755       p_attribute10,
1756       p_attribute11,
1757       p_attribute12,
1758       p_attribute13,
1759       p_attribute14,
1760       p_attribute15,
1761       p_attribute16,
1762       p_attribute17,
1763       p_attribute18,
1764       p_attribute19,
1765       p_attribute20,
1766       p_attribute21,
1767       p_attribute22,
1768       p_attribute23,
1769       p_attribute24,
1770       p_attribute25,
1771       p_attribute26,
1772       p_attribute27,
1773       p_attribute28,
1774       p_attribute29,
1775       p_attribute30,
1776       p_cnt_information_category,
1777       p_cnt_information1,
1778       p_cnt_information2,
1779       p_cnt_information3,
1780       p_cnt_information4,
1781       p_cnt_information5,
1782       p_cnt_information6,
1783       p_cnt_information7,
1784       p_cnt_information8,
1785       p_cnt_information9,
1786       p_cnt_information10,
1787       p_cnt_information11,
1788       p_cnt_information12,
1789       p_cnt_information13,
1790       p_cnt_information14,
1791       p_cnt_information15,
1792       p_cnt_information16,
1793       p_cnt_information17,
1794       p_cnt_information18,
1795       p_cnt_information19,
1796       p_cnt_information20,
1797       p_cnt_information21,
1798       p_cnt_information22,
1799       p_cnt_information23,
1800       p_cnt_information24,
1801       p_cnt_information25,
1802       p_cnt_information26,
1803       p_cnt_information27,
1804       p_cnt_information28,
1805       p_cnt_information29,
1806       p_cnt_information30);
1807 
1808      if sql%notfound then
1809         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
1810         fnd_message.set_token('PROCEDURE',
1811                         'pay_us_emp_dt_tax_rules.insert_county_tax_row');
1812         fnd_message.set_token('STEP','4');
1813         fnd_message.raise_error;
1814      end if;
1815 
1816      open csr_get_row_id;
1817 
1818      fetch csr_get_row_id into p_row_id;
1819 
1820      if csr_get_row_id%NOTFOUND then
1821         close csr_get_row_id;
1822         raise no_data_found;
1823      end if;
1824 
1825      close csr_get_row_id;
1826 
1827     hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_county_tax_row'||
1828                              ' - creating %age record ', 5);
1829 
1830      /* Get the changes in location of an assignment.
1831        For each change in location, create vertex element entry with
1832        time in county as 0% */
1833 
1834      if hr_utility.chk_product_install(p_product     =>'Oracle Payroll',
1835                                        p_legislation => 'US') then
1836 
1837         create_tax_percentage (p_assignment_id  => p_assignment_id,
1838                                p_state_code     => p_state_code,
1839                                p_county_code    => p_county_code,
1843                                p_time_in_city   => 0);
1840                                p_city_code      => null,
1841                                p_time_in_state  => 0,
1842                                p_time_in_county => nvl(p_time_in_county,0),
1844 
1845         /* Insert row into the pay_us_asg_reporting table */
1846 
1847         pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
1848                                            P_jurisdiction  =>  p_jurisdiction_code,
1849                                            P_tax_unit_id   =>  NULL );
1850 
1851         if p_school_district_code is not null then
1852            pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
1853                     P_jurisdiction => p_state_code || '-'|| p_school_district_code,
1854                     P_tax_unit_id   =>  NULL );
1855         end if;
1856 
1857      end if;
1858 
1859   end insert_county_tax_row;
1860 
1861 
1862   /* Name        : insert_city_tax_row
1863      Purpose     : To create the city tax rule record. It also calls the
1864                    create_tax_percentage routine to create the %age records
1865                    for the city, for every change in location of the assignment
1866   */
1867 
1868   procedure insert_city_tax_row ( p_row_id in out nocopy varchar2,
1869                                   p_emp_city_tax_rule_id in out nocopy number,
1870                                   p_effective_start_date in date,
1871                                   p_effective_end_date in date,
1872                                   p_assignment_id in number,
1873                                   p_state_code in varchar2,
1874                                   p_county_code in varchar2,
1875                                   p_city_code in varchar2,
1876                                   p_business_group_id in number,
1877                                   p_additional_wa_rate in number,
1878                                   p_filing_status_code in varchar2,
1879                                   p_jurisdiction_code in varchar2,
1880                                   p_lit_additional_tax in number,
1881                                   p_lit_override_amount in number,
1882                                   p_lit_override_rate in number,
1883                                   p_withholding_allowances in number,
1884                                   p_lit_exempt in varchar2,
1885                                   p_sd_exempt in varchar2,
1886                                   p_ht_exempt in varchar2,
1887                                   p_wage_exempt in varchar2,
1888                                   p_school_district_code in varchar2,
1889                                   p_time_in_city in number,
1890                                   p_attribute_category        in varchar2,
1891                                   p_attribute1                in varchar2,
1892                                   p_attribute2                in varchar2,
1893                                   p_attribute3                in varchar2,
1894                                   p_attribute4                in varchar2,
1895                                   p_attribute5                in varchar2,
1896                                   p_attribute6                in varchar2,
1897                                   p_attribute7                in varchar2,
1898                                   p_attribute8                in varchar2,
1899                                   p_attribute9                in varchar2,
1900                                   p_attribute10               in varchar2,
1901                                   p_attribute11               in varchar2,
1902                                   p_attribute12               in varchar2,
1903                                   p_attribute13               in varchar2,
1904                                   p_attribute14               in varchar2,
1905                                   p_attribute15               in varchar2,
1906                                   p_attribute16               in varchar2,
1907                                   p_attribute17               in varchar2,
1908                                   p_attribute18               in varchar2,
1909                                   p_attribute19               in varchar2,
1910                                   p_attribute20               in varchar2,
1911                                   p_attribute21               in varchar2,
1912                                   p_attribute22               in varchar2,
1913                                   p_attribute23               in varchar2,
1914                                   p_attribute24               in varchar2,
1915                                   p_attribute25               in varchar2,
1916                                   p_attribute26               in varchar2,
1917                                   p_attribute27               in varchar2,
1918                                   p_attribute28               in varchar2,
1919                                   p_attribute29               in varchar2,
1920                                   p_attribute30               in varchar2,
1921                                   p_cty_information_category  in varchar2,
1922                                   p_cty_information1          in varchar2,
1923                                   p_cty_information2          in varchar2,
1924                                   p_cty_information3          in varchar2,
1925                                   p_cty_information4          in varchar2,
1926                                   p_cty_information5          in varchar2,
1927                                   p_cty_information6          in varchar2,
1931                                   p_cty_information10         in varchar2,
1928                                   p_cty_information7          in varchar2,
1929                                   p_cty_information8          in varchar2,
1930                                   p_cty_information9          in varchar2,
1932                                   p_cty_information11         in varchar2,
1933                                   p_cty_information12         in varchar2,
1934                                   p_cty_information13         in varchar2,
1935                                   p_cty_information14         in varchar2,
1936                                   p_cty_information15         in varchar2,
1937                                   p_cty_information16         in varchar2,
1938                                   p_cty_information17         in varchar2,
1939                                   p_cty_information18         in varchar2,
1940                                   p_cty_information19         in varchar2,
1941                                   p_cty_information20         in varchar2,
1942                                   p_cty_information21         in varchar2,
1943                                   p_cty_information22         in varchar2,
1944                                   p_cty_information23         in varchar2,
1945                                   p_cty_information24         in varchar2,
1946                                   p_cty_information25         in varchar2,
1947                                   p_cty_information26         in varchar2,
1948                                   p_cty_information27         in varchar2,
1949                                   p_cty_information28         in varchar2,
1950                                   p_cty_information29         in varchar2,
1951                                   p_cty_information30         in varchar2) is
1952 
1953   cursor csr_city_tax_rule_id is
1954     select PAY_US_EMP_CITY_TAX_RULES_S.nextval
1955     from sys.DUAL;
1956 
1957   cursor csr_get_row_id is
1958     select rowidtochar(rowid)
1959     from PAY_US_EMP_CITY_TAX_RULES_F ctr
1960     where ctr.emp_city_tax_rule_id = p_emp_city_tax_rule_id
1961     and   ctr.effective_start_date  = p_effective_start_date
1962     and   ctr.effective_end_date    = p_effective_end_date;
1963 
1964   begin
1965 
1966      if p_school_district_code is not null
1967      then
1968 
1969        /* Check that the school district is assigned to only one county/city
1970           at a given point in time */
1971 
1972         pay_us_emp_dt_tax_val.check_school_district(
1973                               p_assignment => p_assignment_id,
1974                               p_start_date => p_effective_start_date,
1975                               p_end_date   => p_effective_end_date,
1976                               p_mode       => 'I',
1977                               p_rowid      => null);
1978      end if;
1979 
1980      hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_city_tax_row'||
1981                              ' - Opening cursor', 1);
1982 
1983      open csr_city_tax_rule_id;
1984 
1985      hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_city_tax_row'||
1986                              ' - Fetching cursor', 2);
1987 
1988      fetch csr_city_tax_rule_id into p_emp_city_tax_rule_id;
1989 
1990      hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_city_tax_row'||
1991                              ' - Closing cursor', 3);
1992 
1993      close csr_city_tax_rule_id;
1994 
1995 
1996      hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_city_tax_row'||
1997                              ' - inserting row', 4);
1998 
1999      insert into PAY_US_EMP_CITY_TAX_RULES_F
2000      (emp_city_tax_rule_id,
2001       effective_start_date,
2002       effective_end_date,
2003       assignment_id,
2004       state_code,
2005       county_code,
2006       city_code,
2007       business_group_id,
2008       additional_wa_rate,
2009       filing_status_code,
2010       jurisdiction_code,
2011       lit_additional_tax,
2012       lit_override_amount,
2013       lit_override_rate,
2014       withholding_allowances,
2015       lit_exempt,
2016       sd_exempt,
2017       ht_exempt,
2018       wage_exempt,
2019       school_district_code,
2020       object_version_number,
2021       attribute_category,
2022       attribute1,
2023       attribute2,
2024       attribute3,
2025       attribute4,
2026       attribute5,
2027       attribute6,
2028       attribute7,
2029       attribute8,
2030       attribute9,
2031       attribute10,
2032       attribute11,
2033       attribute12,
2034       attribute13,
2035       attribute14,
2036       attribute15,
2037       attribute16,
2038       attribute17,
2039       attribute18,
2040       attribute19,
2041       attribute20,
2042       attribute21,
2043       attribute22,
2044       attribute23,
2045       attribute24,
2046       attribute25,
2047       attribute26,
2048       attribute27,
2049       attribute28,
2050       attribute29,
2051       attribute30,
2052       cty_information_category,
2053       cty_information1,
2054       cty_information2,
2055       cty_information3,
2056       cty_information4,
2057       cty_information5,
2058       cty_information6,
2059       cty_information7,
2060       cty_information8,
2061       cty_information9,
2065       cty_information13,
2062       cty_information10,
2063       cty_information11,
2064       cty_information12,
2066       cty_information14,
2067       cty_information15,
2068       cty_information16,
2069       cty_information17,
2070       cty_information18,
2071       cty_information19,
2072       cty_information20,
2073       cty_information21,
2074       cty_information22,
2075       cty_information23,
2076       cty_information24,
2077       cty_information25,
2078       cty_information26,
2079       cty_information27,
2080       cty_information28,
2081       cty_information29,
2082       cty_information30)
2083      values
2084      (p_emp_city_tax_rule_id,
2085       p_effective_start_date,
2086       p_effective_end_date,
2087       p_assignment_id,
2088       p_state_code,
2089       p_county_code,
2090       p_city_code,
2091       p_business_group_id,
2092       p_additional_wa_rate,
2093       lpad(p_filing_status_code,2,'0'),
2094       p_jurisdiction_code,
2095       p_lit_additional_tax,
2096       p_lit_override_amount,
2097       p_lit_override_rate,
2098       p_withholding_allowances,
2099       p_lit_exempt,
2100       p_sd_exempt,
2101       p_ht_exempt,
2102       p_wage_exempt,
2103       p_school_district_code,
2104       0,
2105       p_attribute_category,
2106       p_attribute1,
2107       p_attribute2,
2108       p_attribute3,
2109       p_attribute4,
2110       p_attribute5,
2111       p_attribute6,
2112       p_attribute7,
2113       p_attribute8,
2114       p_attribute9,
2115       p_attribute10,
2116       p_attribute11,
2117       p_attribute12,
2118       p_attribute13,
2119       p_attribute14,
2120       p_attribute15,
2121       p_attribute16,
2122       p_attribute17,
2123       p_attribute18,
2124       p_attribute19,
2125       p_attribute20,
2126       p_attribute21,
2127       p_attribute22,
2128       p_attribute23,
2129       p_attribute24,
2130       p_attribute25,
2131       p_attribute26,
2132       p_attribute27,
2133       p_attribute28,
2134       p_attribute29,
2135       p_attribute30,
2136       p_cty_information_category,
2137       p_cty_information1,
2138       p_cty_information2,
2139       p_cty_information3,
2140       p_cty_information4,
2141       p_cty_information5,
2142       p_cty_information6,
2143       p_cty_information7,
2144       p_cty_information8,
2145       p_cty_information9,
2146       p_cty_information10,
2147       p_cty_information11,
2148       p_cty_information12,
2149       p_cty_information13,
2150       p_cty_information14,
2151       p_cty_information15,
2152       p_cty_information16,
2153       p_cty_information17,
2154       p_cty_information18,
2155       p_cty_information19,
2156       p_cty_information20,
2157       p_cty_information21,
2158       p_cty_information22,
2159       p_cty_information23,
2160       p_cty_information24,
2161       p_cty_information25,
2162       p_cty_information26,
2163       p_cty_information27,
2164       p_cty_information28,
2165       p_cty_information29,
2166       p_cty_information30);
2167 
2168      if sql%notfound then
2169 
2170         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
2171         fnd_message.set_token('PROCEDURE',
2172                         'pay_us_emp_dt_tax_rules.insert_city_tax_row');
2173         fnd_message.set_token('STEP','4');
2174         fnd_message.raise_error;
2175 
2176      end if;
2177 
2178      open csr_get_row_id;
2179 
2180      fetch csr_get_row_id into p_row_id;
2181 
2182      if csr_get_row_id%NOTFOUND then
2183         close csr_get_row_id;
2184         raise no_data_found;
2185      end if;
2186 
2187      close csr_get_row_id;
2188 
2189 
2190       hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_city_tax_row'||
2191                              ' - creating %age record ', 5);
2192 
2193      /* Get the changes in location of an assignment.
2194        For each change in location, create vertex element entry with
2195        time in city as 0%
2196        Note: When this procedure will be called by the default_tax routine
2197        there will be only one location for which the record will be created
2198        thus resulting in only one city tax record with 100% - makes sense??
2199        In most of the cases the defaulting routine will create tax records
2200        from begin of time till end of time */
2201 
2202      if hr_utility.chk_product_install(p_product     =>'Oracle Payroll',
2203                                        p_legislation => 'US') then
2204 
2205         create_tax_percentage (p_assignment_id  => p_assignment_id,
2206                                p_state_code     => p_state_code,
2207                                p_county_code    => p_county_code,
2208                                p_city_code      => p_city_code,
2209                                p_time_in_state  => 0,
2210                                p_time_in_county => 0,
2211                                p_time_in_city   => nvl(p_time_in_city,0));
2212 
2213         /* Insert row into the pay_us_asg_reporting table */
2214 
2215         pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
2216                                            P_jurisdiction  =>  p_jurisdiction_code,
2220            pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
2217                                            P_tax_unit_id   =>  NULL );
2218 
2219         if p_school_district_code is not null then
2221                     P_jurisdiction => p_state_code || '-'|| p_school_district_code,
2222                     P_tax_unit_id   =>  NULL );
2223         end if;
2224 
2225      end if;
2226 
2227   end insert_city_tax_row;
2228 
2229 
2230   /* Name        : update_fed_tax_row
2231      Purpose     : To update the federal tax rule record. It also calls the
2232                    maintain_wc_ele_entry routine to update the worker's compensation
2233                    for the SUI state
2234   */
2235 
2236   procedure update_fed_tax_row ( p_row_id                    in varchar2,
2237                                   p_emp_fed_tax_rule_id      in number,
2238 				                  p_effective_start_date     in date,
2239                                   p_effective_end_date       in date,
2240                                   p_assignment_id            in number,
2241                                   p_sui_state_code           in varchar2,
2242                                   p_sui_jurisdiction_code    in varchar2,
2243                                   p_business_group_id        in number,
2244                                   p_additional_wa_amount     in number,
2245                                   p_filing_status_code       in varchar2,
2246                                   p_fit_override_amount      in number,
2247  				                  p_fit_override_rate        in number,
2248                                   p_withholding_allowances   in number,
2249                                   p_cumulative_taxation      in varchar2,
2250                                   p_eic_filing_status_code   in varchar2,
2251                                   p_fit_additional_tax       in number,
2252                                   p_fit_exempt               in varchar2,
2253                                   p_futa_tax_exempt          in varchar2,
2254                                   p_medicare_tax_exempt      in varchar2,
2255                                   p_ss_tax_exempt            in varchar2,
2256                                   p_wage_exempt              in varchar2,
2257                                   p_statutory_employee       in varchar2,
2258                                   p_w2_filed_year            in number,
2259                                   p_supp_tax_override_rate   in number,
2260                                   p_excessive_wa_reject_date in date,
2261                                   p_session_date             in date,
2262                                   p_attribute_category        in varchar2,
2263                                   p_attribute1                in varchar2,
2264                                   p_attribute2                in varchar2,
2265                                   p_attribute3                in varchar2,
2266                                   p_attribute4                in varchar2,
2267                                   p_attribute5                in varchar2,
2268                                   p_attribute6                in varchar2,
2269                                   p_attribute7                in varchar2,
2270                                   p_attribute8                in varchar2,
2271                                   p_attribute9                in varchar2,
2272                                   p_attribute10               in varchar2,
2273                                   p_attribute11               in varchar2,
2274                                   p_attribute12               in varchar2,
2275                                   p_attribute13               in varchar2,
2276                                   p_attribute14               in varchar2,
2277                                   p_attribute15               in varchar2,
2278                                   p_attribute16               in varchar2,
2279                                   p_attribute17               in varchar2,
2280                                   p_attribute18               in varchar2,
2281                                   p_attribute19               in varchar2,
2282                                   p_attribute20               in varchar2,
2283                                   p_attribute21               in varchar2,
2284                                   p_attribute22               in varchar2,
2285                                   p_attribute23               in varchar2,
2286                                   p_attribute24               in varchar2,
2287                                   p_attribute25               in varchar2,
2288                                   p_attribute26               in varchar2,
2289                                   p_attribute27               in varchar2,
2290                                   p_attribute28               in varchar2,
2291                                   p_attribute29               in varchar2,
2292                                   p_attribute30               in varchar2,
2293                                   p_fed_information_category  in varchar2,
2294                                   p_fed_information1          in varchar2,
2295                                   p_fed_information2          in varchar2,
2296                                   p_fed_information3          in varchar2,
2297                                   p_fed_information4          in varchar2,
2298                                   p_fed_information5          in varchar2,
2299                                   p_fed_information6          in varchar2,
2300                                   p_fed_information7          in varchar2,
2301                                   p_fed_information8          in varchar2,
2305                                   p_fed_information12         in varchar2,
2302                                   p_fed_information9          in varchar2,
2303                                   p_fed_information10         in varchar2,
2304                                   p_fed_information11         in varchar2,
2306                                   p_fed_information13         in varchar2,
2307                                   p_fed_information14         in varchar2,
2308                                   p_fed_information15         in varchar2,
2309                                   p_fed_information16         in varchar2,
2310                                   p_fed_information17         in varchar2,
2311                                   p_fed_information18         in varchar2,
2312                                   p_fed_information19         in varchar2,
2313                                   p_fed_information20         in varchar2,
2314                                   p_fed_information21         in varchar2,
2315                                   p_fed_information22         in varchar2,
2316                                   p_fed_information23         in varchar2,
2317                                   p_fed_information24         in varchar2,
2318                                   p_fed_information25         in varchar2,
2319                                   p_fed_information26         in varchar2,
2320                                   p_fed_information27         in varchar2,
2321                                   p_fed_information28         in varchar2,
2322                                   p_fed_information29         in varchar2,
2323                                   p_fed_information30         in varchar2,
2324                                   p_mode                     in varchar2) is
2325 
2326   lv_warning          VARCHAR2(300);
2327 
2328   begin
2329 
2330 
2331      hr_utility.set_location('pay_us_emp_dt_tax_rules.update_fed_tax_row'||
2332                              ' - updating row', 1);
2333     ----added by  vaprakas Bug 5607135
2334     check_nra_status(p_assignment_id
2335                    , p_withholding_allowances
2336 		   , p_filing_status_code
2337 		   , p_fit_exempt
2338 		   , p_effective_start_date
2339 		   , p_effective_end_date
2340 		   , lv_warning);
2341 
2342      update PAY_US_EMP_FED_TAX_RULES_F
2343      set emp_fed_tax_rule_id   = p_emp_fed_tax_rule_id,
2344       effective_start_date     = p_effective_start_date,
2345       effective_end_date       = p_effective_end_date,
2346       assignment_id            = p_assignment_id ,
2347       sui_state_code           = p_sui_state_code,
2348       sui_jurisdiction_code    = p_sui_jurisdiction_code,
2349       business_group_id        = p_business_group_id ,
2350       additional_wa_amount     = p_additional_wa_amount,
2351       filing_status_code       = lpad(p_filing_status_code,2,'0'),
2352       fit_override_amount      = p_fit_override_amount,
2353       fit_override_rate        = p_fit_override_rate,
2354       withholding_allowances   = p_withholding_allowances,
2355       cumulative_taxation      = p_cumulative_taxation,
2356       eic_filing_status_code   = p_eic_filing_status_code,
2357       fit_additional_tax       = p_fit_additional_tax,
2358       fit_exempt               = p_fit_exempt,
2359       futa_tax_exempt          = p_futa_tax_exempt,
2360       medicare_tax_exempt      = p_medicare_tax_exempt,
2361       ss_tax_exempt            = p_ss_tax_exempt,
2362       wage_exempt              = p_wage_exempt,
2363       statutory_employee       = p_statutory_employee,
2364       w2_filed_year            = p_w2_filed_year,
2365       supp_tax_override_rate   = p_supp_tax_override_rate,
2366       excessive_wa_reject_date = p_excessive_wa_reject_date,
2367       attribute_category       = p_attribute_category,
2368       attribute1               = p_attribute1,
2369       attribute2               = p_attribute2,
2370       attribute3               = p_attribute3,
2371       attribute4               = p_attribute4,
2372       attribute5               = p_attribute5,
2373       attribute6               = p_attribute6,
2374       attribute7               = p_attribute7,
2375       attribute8               = p_attribute8,
2376       attribute9               = p_attribute9,
2377       attribute10              = p_attribute10,
2378       attribute11              = p_attribute11,
2379       attribute12              = p_attribute12,
2380       attribute13              = p_attribute13,
2381       attribute14              = p_attribute14,
2382       attribute15              = p_attribute15,
2383       attribute16              = p_attribute16,
2384       attribute17              = p_attribute17,
2385       attribute18              = p_attribute18,
2386       attribute19              = p_attribute19,
2387       attribute20              = p_attribute20,
2388       attribute21              = p_attribute21,
2389       attribute22              = p_attribute22,
2390       attribute23              = p_attribute23,
2391       attribute24              = p_attribute24,
2392       attribute25              = p_attribute25,
2393       attribute26              = p_attribute26,
2394       attribute27              = p_attribute27,
2395       attribute28              = p_attribute28,
2396       attribute29              = p_attribute29,
2397       attribute30              = p_attribute30,
2398       fed_information_category = p_fed_information_category,
2399       fed_information1         = p_fed_information1,
2400       fed_information2         = p_fed_information2,
2401       fed_information3         = p_fed_information3,
2402       fed_information4         = p_fed_information4,
2406       fed_information8         = p_fed_information8,
2403       fed_information5         = p_fed_information5,
2404       fed_information6         = p_fed_information6,
2405       fed_information7         = p_fed_information7,
2407       fed_information9         = p_fed_information9,
2408       fed_information10        = p_fed_information10,
2409       fed_information11        = p_fed_information11,
2410       fed_information12        = p_fed_information12,
2411       fed_information13        = p_fed_information13,
2412       fed_information14        = p_fed_information14,
2413       fed_information15        = p_fed_information15,
2414       fed_information16        = p_fed_information16,
2415       fed_information17        = p_fed_information17,
2416       fed_information18        = p_fed_information18,
2417       fed_information19        = p_fed_information19,
2418       fed_information20        = p_fed_information20,
2419       fed_information21        = p_fed_information21,
2420       fed_information22        = p_fed_information22,
2421       fed_information23        = p_fed_information23,
2422       fed_information24        = p_fed_information24,
2423       fed_information25        = p_fed_information25,
2424       fed_information26        = p_fed_information26,
2425       fed_information27        = p_fed_information27,
2426       fed_information28        = p_fed_information28,
2427       fed_information29        = p_fed_information29,
2428       fed_information30        = p_fed_information30
2429       where rowid              = chartorowid(p_row_id);
2430 
2431       if sql%notfound then
2432         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
2433         fnd_message.set_token('PROCEDURE',
2434                        'pay_us_emp_dt_tax_rules.update_fed_tax');
2435         fnd_message.set_token('STEP','1');
2436         fnd_message.raise_error;
2437       end if;
2438 
2439       /* Update workers compensation element entry for the sui state in
2440          the federal record */
2441 
2442       maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
2443                              p_effective_start_date => p_effective_start_date,
2444                              p_effective_end_date   => p_effective_end_date,
2445                              p_session_date         => p_session_date,
2446                              p_jurisdiction_code    => p_sui_jurisdiction_code,
2447                              p_mode                 => p_mode);
2448 
2449 
2450   end update_fed_tax_row;
2451 
2452   /* Name        : update_state_tax_row
2453      Purpose     : To update the state tax rule record.
2454   */
2455 
2456   procedure update_state_tax_row ( p_row_id in varchar2,
2457                                    p_emp_state_tax_rule_id in number,
2458                                    p_effective_start_date in date,
2459                                    p_effective_end_date in date,
2460                                    p_assignment_id in number,
2461                                    p_state_code in varchar2,
2462                                    p_jurisdiction_code in varchar2,
2463                                    p_business_group_id in number,
2464                                    p_additional_wa_amount in number,
2465                                    p_filing_status_code in varchar2,
2466                                    p_remainder_percent in number,
2467                                    p_secondary_wa in number,
2468                                    p_sit_additional_tax in number,
2469                                    p_sit_override_amount in number,
2470                                    p_sit_override_rate in number,
2471                                    p_withholding_allowances in number,
2472                                    p_excessive_wa_reject_date in date,
2473                                    p_sdi_exempt in varchar2,
2474                                    p_sit_exempt in varchar2,
2475                                    p_sit_optional_calc_ind in varchar2,
2476                                    p_state_non_resident_cert in varchar2,
2477                                    p_sui_exempt in varchar2,
2478                                    p_wc_exempt in varchar2,
2479                                    p_wage_exempt in varchar2,
2480                                    p_sui_wage_base_override_amt in number,
2481                                    p_supp_tax_override_rate in number,
2482                                    p_attribute_category        in varchar2,
2483                                    p_attribute1                in varchar2,
2484                                    p_attribute2                in varchar2,
2485                                    p_attribute3                in varchar2,
2486                                    p_attribute4                in varchar2,
2487                                    p_attribute5                in varchar2,
2488                                    p_attribute6                in varchar2,
2489                                    p_attribute7                in varchar2,
2490                                    p_attribute8                in varchar2,
2491                                    p_attribute9                in varchar2,
2492                                    p_attribute10               in varchar2,
2493                                    p_attribute11               in varchar2,
2494                                    p_attribute12               in varchar2,
2495                                    p_attribute13               in varchar2,
2496                                    p_attribute14               in varchar2,
2500                                    p_attribute18               in varchar2,
2497                                    p_attribute15               in varchar2,
2498                                    p_attribute16               in varchar2,
2499                                    p_attribute17               in varchar2,
2501                                    p_attribute19               in varchar2,
2502                                    p_attribute20               in varchar2,
2503                                    p_attribute21               in varchar2,
2504                                    p_attribute22               in varchar2,
2505                                    p_attribute23               in varchar2,
2506                                    p_attribute24               in varchar2,
2507                                    p_attribute25               in varchar2,
2508                                    p_attribute26               in varchar2,
2509                                    p_attribute27               in varchar2,
2510                                    p_attribute28               in varchar2,
2511                                    p_attribute29               in varchar2,
2512                                    p_attribute30               in varchar2,
2513                                    p_sta_information_category  in varchar2,
2514                                    p_sta_information1          in varchar2,
2515                                    p_sta_information2          in varchar2,
2516                                    p_sta_information3          in varchar2,
2517                                    p_sta_information4          in varchar2,
2518                                    p_sta_information5          in varchar2,
2519                                    p_sta_information6          in varchar2,
2520                                    p_sta_information7          in varchar2,
2521                                    p_sta_information8          in varchar2,
2522                                    p_sta_information9          in varchar2,
2523                                    p_sta_information10         in varchar2,
2524                                    p_sta_information11         in varchar2,
2525                                    p_sta_information12         in varchar2,
2526                                    p_sta_information13         in varchar2,
2527                                    p_sta_information14         in varchar2,
2528                                    p_sta_information15         in varchar2,
2529                                    p_sta_information16         in varchar2,
2530                                    p_sta_information17         in varchar2,
2531                                    p_sta_information18         in varchar2,
2532                                    p_sta_information19         in varchar2,
2533                                    p_sta_information20         in varchar2,
2534                                    p_sta_information21         in varchar2,
2535                                    p_sta_information22         in varchar2,
2536                                    p_sta_information23         in varchar2,
2537                                    p_sta_information24         in varchar2,
2538                                    p_sta_information25         in varchar2,
2539                                    p_sta_information26         in varchar2,
2540                                    p_sta_information27         in varchar2,
2541                                    p_sta_information28         in varchar2,
2542                                    p_sta_information29         in varchar2,
2543                                    p_sta_information30         in varchar2) is
2544   begin
2545 
2546      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
2547                              ' - updating row', 1);
2548 
2549      update PAY_US_EMP_STATE_TAX_RULES_F
2550      set emp_state_tax_rule_id      = p_emp_state_tax_rule_id,
2551       effective_start_date          = p_effective_start_date,
2552       effective_end_date            = p_effective_end_date,
2553       assignment_id                 = p_assignment_id,
2554       state_code                    = p_state_code,
2555       jurisdiction_code             = p_jurisdiction_code,
2556       business_group_id             = p_business_group_id,
2557       additional_wa_amount          = p_additional_wa_amount,
2558       filing_status_code            = lpad(p_filing_status_code,2,'0'),
2559       remainder_percent             = p_remainder_percent,
2560       secondary_wa                  = p_secondary_wa,
2561       sit_additional_tax            = p_sit_additional_tax,
2562       sit_override_amount           = p_sit_override_amount,
2563       sit_override_rate             = p_sit_override_rate,
2564       withholding_allowances        = p_withholding_allowances,
2565       excessive_wa_reject_date      = p_excessive_wa_reject_date,
2566       sdi_exempt                    = p_sdi_exempt,
2567       sit_exempt                    = p_sit_exempt,
2568       sit_optional_calc_ind         = p_sit_optional_calc_ind,
2569       state_non_resident_cert       = p_state_non_resident_cert,
2570       sui_exempt                    = p_sui_exempt,
2571       wc_exempt                     = p_wc_exempt,
2572       wage_exempt                   = p_wage_exempt,
2573       sui_wage_base_override_amount = p_sui_wage_base_override_amt,
2574       supp_tax_override_rate        = p_supp_tax_override_rate,
2575       attribute_category       = p_attribute_category,
2576       attribute1               = p_attribute1,
2577       attribute2               = p_attribute2,
2578       attribute3               = p_attribute3,
2579       attribute4               = p_attribute4,
2583       attribute8               = p_attribute8,
2580       attribute5               = p_attribute5,
2581       attribute6               = p_attribute6,
2582       attribute7               = p_attribute7,
2584       attribute9               = p_attribute9,
2585       attribute10              = p_attribute10,
2586       attribute11              = p_attribute11,
2587       attribute12              = p_attribute12,
2588       attribute13              = p_attribute13,
2589       attribute14              = p_attribute14,
2590       attribute15              = p_attribute15,
2591       attribute16              = p_attribute16,
2592       attribute17              = p_attribute17,
2593       attribute18              = p_attribute18,
2594       attribute19              = p_attribute19,
2595       attribute20              = p_attribute20,
2596       attribute21              = p_attribute21,
2597       attribute22              = p_attribute22,
2598       attribute23              = p_attribute23,
2599       attribute24              = p_attribute24,
2600       attribute25              = p_attribute25,
2601       attribute26              = p_attribute26,
2602       attribute27              = p_attribute27,
2603       attribute28              = p_attribute28,
2604       attribute29              = p_attribute29,
2605       attribute30              = p_attribute30,
2606       sta_information_category = p_sta_information_category,
2607       sta_information1         = p_sta_information1,
2608       sta_information2         = p_sta_information2,
2609       sta_information3         = p_sta_information3,
2610       sta_information4         = p_sta_information4,
2611       sta_information5         = p_sta_information5,
2612       sta_information6         = p_sta_information6,
2613       sta_information7         = p_sta_information7,
2614       sta_information8         = p_sta_information8,
2615       sta_information9         = p_sta_information9,
2616       sta_information10        = p_sta_information10,
2617       sta_information11        = p_sta_information11,
2618       sta_information12        = p_sta_information12,
2619       sta_information13        = p_sta_information13,
2620       sta_information14        = p_sta_information14,
2621       sta_information15        = p_sta_information15,
2622       sta_information16        = p_sta_information16,
2623       sta_information17        = p_sta_information17,
2624       sta_information18        = p_sta_information18,
2625       sta_information19        = p_sta_information19,
2626       sta_information20        = p_sta_information20,
2627       sta_information21        = p_sta_information21,
2628       sta_information22        = p_sta_information22,
2629       sta_information23        = p_sta_information23,
2630       sta_information24        = p_sta_information24,
2631       sta_information25        = p_sta_information25,
2632       sta_information26        = p_sta_information26,
2633       sta_information27        = p_sta_information27,
2634       sta_information28        = p_sta_information28,
2635       sta_information29        = p_sta_information29,
2636       sta_information30        = p_sta_information30
2637       where rowid  = chartorowid(p_row_id);
2638 
2639      if sql%notfound then
2640         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
2641         fnd_message.set_token('PROCEDURE',
2642                         'pay_us_emp_dt_tax_rules.update_state_tax_row');
2643         fnd_message.set_token('STEP','1');
2644         fnd_message.raise_error;
2645      end if;
2646 
2647      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_st_tax_row'||
2648                              ' - updated row', 2);
2649 
2650   end update_state_tax_row;
2651 
2652 
2653   /* Name        : update_county_tax_row
2654      Purpose     : To update the county tax rule record.
2655   */
2656   procedure update_county_tax_row ( p_row_id in varchar2,
2657                                     p_emp_county_tax_rule_id in number,
2658                                     p_effective_start_date in date,
2659                                     p_effective_end_date in date,
2660                                     p_assignment_id in number,
2661                                     p_state_code in varchar2,
2662                                     p_county_code in varchar2,
2663                                     p_business_group_id in number,
2664                                     p_additional_wa_rate in number,
2665                                     p_filing_status_code in varchar2,
2666                                     p_jurisdiction_code in varchar2,
2667                                     p_lit_additional_tax in number,
2668                                     p_lit_override_amount in number,
2669                                     p_lit_override_rate in number,
2670                                     p_withholding_allowances in number,
2671                                     p_lit_exempt in varchar2,
2672                                     p_sd_exempt in varchar2,
2673                                     p_ht_exempt in varchar2,
2674                                     p_wage_exempt in varchar2,
2675                                     p_school_district_code in varchar2,
2676                                     p_attribute_category        in varchar2,
2677                                     p_attribute1                in varchar2,
2678                                     p_attribute2                in varchar2,
2679                                     p_attribute3                in varchar2,
2680                                     p_attribute4                in varchar2,
2684                                     p_attribute8                in varchar2,
2681                                     p_attribute5                in varchar2,
2682                                     p_attribute6                in varchar2,
2683                                     p_attribute7                in varchar2,
2685                                     p_attribute9                in varchar2,
2686                                     p_attribute10               in varchar2,
2687                                     p_attribute11               in varchar2,
2688                                     p_attribute12               in varchar2,
2689                                     p_attribute13               in varchar2,
2690                                     p_attribute14               in varchar2,
2691                                     p_attribute15               in varchar2,
2692                                     p_attribute16               in varchar2,
2693                                     p_attribute17               in varchar2,
2694                                     p_attribute18               in varchar2,
2695                                     p_attribute19               in varchar2,
2696                                     p_attribute20               in varchar2,
2697                                     p_attribute21               in varchar2,
2698                                     p_attribute22               in varchar2,
2699                                     p_attribute23               in varchar2,
2700                                     p_attribute24               in varchar2,
2701                                     p_attribute25               in varchar2,
2702                                     p_attribute26               in varchar2,
2703                                     p_attribute27               in varchar2,
2704                                     p_attribute28               in varchar2,
2705                                     p_attribute29               in varchar2,
2706                                     p_attribute30               in varchar2,
2707                                     p_cnt_information_category  in varchar2,
2708                                     p_cnt_information1          in varchar2,
2709                                     p_cnt_information2          in varchar2,
2710                                     p_cnt_information3          in varchar2,
2711                                     p_cnt_information4          in varchar2,
2712                                     p_cnt_information5          in varchar2,
2713                                     p_cnt_information6          in varchar2,
2714                                     p_cnt_information7          in varchar2,
2715                                     p_cnt_information8          in varchar2,
2716                                     p_cnt_information9          in varchar2,
2717                                     p_cnt_information10         in varchar2,
2718                                     p_cnt_information11         in varchar2,
2719                                     p_cnt_information12         in varchar2,
2720                                     p_cnt_information13         in varchar2,
2721                                     p_cnt_information14         in varchar2,
2722                                     p_cnt_information15         in varchar2,
2723                                     p_cnt_information16         in varchar2,
2724                                     p_cnt_information17         in varchar2,
2725                                     p_cnt_information18         in varchar2,
2726                                     p_cnt_information19         in varchar2,
2727                                     p_cnt_information20         in varchar2,
2728                                     p_cnt_information21         in varchar2,
2729                                     p_cnt_information22         in varchar2,
2730                                     p_cnt_information23         in varchar2,
2731                                     p_cnt_information24         in varchar2,
2732                                     p_cnt_information25         in varchar2,
2733                                     p_cnt_information26         in varchar2,
2734                                     p_cnt_information27         in varchar2,
2735                                     p_cnt_information28         in varchar2,
2736                                     p_cnt_information29         in varchar2,
2737                                     p_cnt_information30         in varchar2) is
2738 
2739   begin
2740 
2741     if p_school_district_code is not null
2742     then
2743 
2744        hr_utility.set_location('pay_us_emp_dt_tax_rules.update_county_tax_row'||
2745                              ' - checking sd', 1);
2746        /* Check that the school district is assigned to only one county/city
2747           at a given point in time */
2748 
2749         pay_us_emp_dt_tax_val.check_school_district(
2750                               p_assignment => p_assignment_id,
2751                               p_start_date => p_effective_start_date,
2752                               p_end_date   => p_effective_end_date,
2753                               p_mode       => 'U',
2754                               p_rowid      => p_row_id);
2755     end if;
2756 
2757     hr_utility.set_location('pay_us_emp_dt_tax_rules.update_county_tax_row'||
2758                              ' - updating row', 2);
2759 
2760      update PAY_US_EMP_COUNTY_TAX_RULES_F
2761      set emp_county_tax_rule_id = p_emp_county_tax_rule_id,
2762       effective_start_date   = p_effective_start_date,
2763       effective_end_date     = p_effective_end_date,
2764       assignment_id          = p_assignment_id,
2768       additional_wa_rate     = p_additional_wa_rate,
2765       state_code             = p_state_code,
2766       county_code            = p_county_code,
2767       business_group_id      = p_business_group_id,
2769       filing_status_code     = lpad(p_filing_status_code,2,'0'),
2770       jurisdiction_code      = p_jurisdiction_code,
2771       lit_additional_tax     = p_lit_additional_tax,
2772       lit_override_amount    = p_lit_override_amount,
2773       lit_override_rate      = p_lit_override_rate,
2774       withholding_allowances = p_withholding_allowances,
2775       lit_exempt             = p_lit_exempt,
2776       sd_exempt              = p_sd_exempt,
2777       ht_exempt              = p_ht_exempt,
2778       wage_exempt            = p_wage_exempt,
2779       school_district_code   = p_school_district_code,
2780       attribute_category       = p_attribute_category,
2781       attribute1               = p_attribute1,
2782       attribute2               = p_attribute2,
2783       attribute3               = p_attribute3,
2784       attribute4               = p_attribute4,
2785       attribute5               = p_attribute5,
2786       attribute6               = p_attribute6,
2787       attribute7               = p_attribute7,
2788       attribute8               = p_attribute8,
2789       attribute9               = p_attribute9,
2790       attribute10              = p_attribute10,
2791       attribute11              = p_attribute11,
2792       attribute12              = p_attribute12,
2793       attribute13              = p_attribute13,
2794       attribute14              = p_attribute14,
2795       attribute15              = p_attribute15,
2796       attribute16              = p_attribute16,
2797       attribute17              = p_attribute17,
2798       attribute18              = p_attribute18,
2799       attribute19              = p_attribute19,
2800       attribute20              = p_attribute20,
2801       attribute21              = p_attribute21,
2802       attribute22              = p_attribute22,
2803       attribute23              = p_attribute23,
2804       attribute24              = p_attribute24,
2805       attribute25              = p_attribute25,
2806       attribute26              = p_attribute26,
2807       attribute27              = p_attribute27,
2808       attribute28              = p_attribute28,
2809       attribute29              = p_attribute29,
2810       attribute30              = p_attribute30,
2811       cnt_information_category = p_cnt_information_category,
2812       cnt_information1         = p_cnt_information1,
2813       cnt_information2         = p_cnt_information2,
2814       cnt_information3         = p_cnt_information3,
2815       cnt_information4         = p_cnt_information4,
2816       cnt_information5         = p_cnt_information5,
2817       cnt_information6         = p_cnt_information6,
2818       cnt_information7         = p_cnt_information7,
2819       cnt_information8         = p_cnt_information8,
2820       cnt_information9         = p_cnt_information9,
2821       cnt_information10        = p_cnt_information10,
2822       cnt_information11        = p_cnt_information11,
2823       cnt_information12        = p_cnt_information12,
2824       cnt_information13        = p_cnt_information13,
2825       cnt_information14        = p_cnt_information14,
2826       cnt_information15        = p_cnt_information15,
2827       cnt_information16        = p_cnt_information16,
2828       cnt_information17        = p_cnt_information17,
2829       cnt_information18        = p_cnt_information18,
2830       cnt_information19        = p_cnt_information19,
2831       cnt_information20        = p_cnt_information20,
2832       cnt_information21        = p_cnt_information21,
2833       cnt_information22        = p_cnt_information22,
2834       cnt_information23        = p_cnt_information23,
2835       cnt_information24        = p_cnt_information24,
2836       cnt_information25        = p_cnt_information25,
2837       cnt_information26        = p_cnt_information26,
2838       cnt_information27        = p_cnt_information27,
2839       cnt_information28        = p_cnt_information28,
2840       cnt_information29        = p_cnt_information29,
2841       cnt_information30        = p_cnt_information30
2842       where rowid  = chartorowid(p_row_id);
2843 
2844      if sql%notfound then
2845         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
2846         fnd_message.set_token('PROCEDURE',
2847                         'pay_us_emp_dt_tax_rules.update_county_tax_row');
2848         fnd_message.set_token('STEP','2');
2849         fnd_message.raise_error;
2850      end if;
2851 
2852      if p_school_district_code is not null then
2853 
2854         /* Insert row into the pay_us_asg_reporting table */
2855 
2856         hr_utility.set_location('pay_us_emp_dt_tax_rules.update_county_tax_row'||
2857                                   ' - asg_geo row', 3);
2858 
2859         pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
2860                                            P_jurisdiction  => p_state_code || '-'||
2861                                                              p_school_district_code,
2862                                            P_tax_unit_id   =>  NULL );
2863      end if;
2864 
2865   end update_county_tax_row;
2866 
2867 
2868   /* Name        : update_city_tax_row
2869      Purpose     : To update the city tax rule record.
2870   */
2871 
2872   procedure update_city_tax_row ( p_row_id in varchar2,
2873                                   p_emp_city_tax_rule_id in number,
2877                                   p_state_code in varchar2,
2874                                   p_effective_start_date in date,
2875                                   p_effective_end_date in date,
2876                                   p_assignment_id in number,
2878                                   p_county_code in varchar2,
2879                                   p_city_code in varchar2,
2880                                   p_business_group_id in number,
2881                                   p_additional_wa_rate in number,
2882                                   p_filing_status_code in varchar2,
2883                                   p_jurisdiction_code in varchar2,
2884                                   p_lit_additional_tax in number,
2885                                   p_lit_override_amount in number,
2886                                   p_lit_override_rate in number,
2887                                   p_withholding_allowances in number,
2888                                   p_lit_exempt in varchar2,
2889                                   p_sd_exempt in varchar2,
2890                                   p_ht_exempt in varchar2,
2891                                   p_wage_exempt in varchar2,
2892                                   p_school_district_code in varchar2,
2893                                   p_attribute_category        in varchar2,
2894                                   p_attribute1                in varchar2,
2895                                   p_attribute2                in varchar2,
2896                                   p_attribute3                in varchar2,
2897                                   p_attribute4                in varchar2,
2898                                   p_attribute5                in varchar2,
2899                                   p_attribute6                in varchar2,
2900                                   p_attribute7                in varchar2,
2901                                   p_attribute8                in varchar2,
2902                                   p_attribute9                in varchar2,
2903                                   p_attribute10               in varchar2,
2904                                   p_attribute11               in varchar2,
2905                                   p_attribute12               in varchar2,
2906                                   p_attribute13               in varchar2,
2907                                   p_attribute14               in varchar2,
2908                                   p_attribute15               in varchar2,
2909                                   p_attribute16               in varchar2,
2910                                   p_attribute17               in varchar2,
2911                                   p_attribute18               in varchar2,
2912                                   p_attribute19               in varchar2,
2913                                   p_attribute20               in varchar2,
2914                                   p_attribute21               in varchar2,
2915                                   p_attribute22               in varchar2,
2916                                   p_attribute23               in varchar2,
2917                                   p_attribute24               in varchar2,
2918                                   p_attribute25               in varchar2,
2919                                   p_attribute26               in varchar2,
2920                                   p_attribute27               in varchar2,
2921                                   p_attribute28               in varchar2,
2922                                   p_attribute29               in varchar2,
2923                                   p_attribute30               in varchar2,
2924                                   p_cty_information_category  in varchar2,
2925                                   p_cty_information1          in varchar2,
2926                                   p_cty_information2          in varchar2,
2927                                   p_cty_information3          in varchar2,
2928                                   p_cty_information4          in varchar2,
2929                                   p_cty_information5          in varchar2,
2930                                   p_cty_information6          in varchar2,
2931                                   p_cty_information7          in varchar2,
2932                                   p_cty_information8          in varchar2,
2933                                   p_cty_information9          in varchar2,
2934                                   p_cty_information10         in varchar2,
2935                                   p_cty_information11         in varchar2,
2936                                   p_cty_information12         in varchar2,
2937                                   p_cty_information13         in varchar2,
2938                                   p_cty_information14         in varchar2,
2939                                   p_cty_information15         in varchar2,
2940                                   p_cty_information16         in varchar2,
2941                                   p_cty_information17         in varchar2,
2942                                   p_cty_information18         in varchar2,
2943                                   p_cty_information19         in varchar2,
2944                                   p_cty_information20         in varchar2,
2945                                   p_cty_information21         in varchar2,
2946                                   p_cty_information22         in varchar2,
2947                                   p_cty_information23         in varchar2,
2948                                   p_cty_information24         in varchar2,
2949                                   p_cty_information25         in varchar2,
2950                                   p_cty_information26         in varchar2,
2954                                   p_cty_information30         in varchar2) is
2951                                   p_cty_information27         in varchar2,
2952                                   p_cty_information28         in varchar2,
2953                                   p_cty_information29         in varchar2,
2955   begin
2956 
2957      if p_school_district_code is not null
2958      then
2959 
2960         hr_utility.set_location('pay_us_emp_dt_tax_rules.update_city_tax_row'||
2961                              ' - checking sd', 1);
2962 
2963        /* Check that the school district is assigned to only one county/city
2964           at a given point in time */
2965 
2966         pay_us_emp_dt_tax_val.check_school_district(
2967                               p_assignment => p_assignment_id,
2968                               p_start_date => p_effective_start_date,
2969                               p_end_date   => p_effective_end_date,
2970                               p_mode       => 'U',
2971                               p_rowid      => p_row_id);
2972      end if;
2973 
2974      hr_utility.set_location('pay_us_emp_dt_tax_rules.update_city_tax_row'||
2975                              ' - updating row', 2);
2976 
2977      update PAY_US_EMP_CITY_TAX_RULES_F
2978      set emp_city_tax_rule_id = p_emp_city_tax_rule_id,
2979       effective_start_date    = p_effective_start_date,
2980       effective_end_date      = p_effective_end_date,
2981       assignment_id           = p_assignment_id,
2982       state_code              = p_state_code,
2983       county_code             = p_county_code,
2984       city_code               = p_city_code,
2985       business_group_id       = p_business_group_id,
2986       additional_wa_rate      = p_additional_wa_rate,
2987       filing_status_code      = lpad(p_filing_status_code,2,'0'),
2988       jurisdiction_code       = p_jurisdiction_code,
2989       lit_additional_tax      = p_lit_additional_tax,
2990       lit_override_amount     = p_lit_override_amount,
2991       lit_override_rate       = p_lit_override_rate,
2992       withholding_allowances  = p_withholding_allowances,
2993       lit_exempt              = p_lit_exempt,
2994       sd_exempt               = p_sd_exempt,
2995       ht_exempt               = p_ht_exempt,
2996       wage_exempt             = p_wage_exempt,
2997       school_district_code    = p_school_district_code,
2998       attribute_category       = p_attribute_category,
2999       attribute1               = p_attribute1,
3000       attribute2               = p_attribute2,
3001       attribute3               = p_attribute3,
3002       attribute4               = p_attribute4,
3003       attribute5               = p_attribute5,
3004       attribute6               = p_attribute6,
3005       attribute7               = p_attribute7,
3006       attribute8               = p_attribute8,
3007       attribute9               = p_attribute9,
3008       attribute10              = p_attribute10,
3009       attribute11              = p_attribute11,
3010       attribute12              = p_attribute12,
3011       attribute13              = p_attribute13,
3012       attribute14              = p_attribute14,
3013       attribute15              = p_attribute15,
3014       attribute16              = p_attribute16,
3015       attribute17              = p_attribute17,
3016       attribute18              = p_attribute18,
3017       attribute19              = p_attribute19,
3018       attribute20              = p_attribute20,
3019       attribute21              = p_attribute21,
3020       attribute22              = p_attribute22,
3021       attribute23              = p_attribute23,
3022       attribute24              = p_attribute24,
3023       attribute25              = p_attribute25,
3024       attribute26              = p_attribute26,
3025       attribute27              = p_attribute27,
3026       attribute28              = p_attribute28,
3027       attribute29              = p_attribute29,
3028       attribute30              = p_attribute30,
3029       cty_information_category = p_cty_information_category,
3030       cty_information1         = p_cty_information1,
3031       cty_information2         = p_cty_information2,
3032       cty_information3         = p_cty_information3,
3033       cty_information4         = p_cty_information4,
3034       cty_information5         = p_cty_information5,
3035       cty_information6         = p_cty_information6,
3036       cty_information7         = p_cty_information7,
3037       cty_information8         = p_cty_information8,
3038       cty_information9         = p_cty_information9,
3039       cty_information10        = p_cty_information10,
3040       cty_information11        = p_cty_information11,
3041       cty_information12        = p_cty_information12,
3042       cty_information13        = p_cty_information13,
3043       cty_information14        = p_cty_information14,
3044       cty_information15        = p_cty_information15,
3045       cty_information16        = p_cty_information16,
3046       cty_information17        = p_cty_information17,
3047       cty_information18        = p_cty_information18,
3048       cty_information19        = p_cty_information19,
3049       cty_information20        = p_cty_information20,
3050       cty_information21        = p_cty_information21,
3051       cty_information22        = p_cty_information22,
3052       cty_information23        = p_cty_information23,
3053       cty_information24        = p_cty_information24,
3054       cty_information25        = p_cty_information25,
3055       cty_information26        = p_cty_information26,
3056       cty_information27        = p_cty_information27,
3060       where rowid  = chartorowid(p_row_id);
3057       cty_information28        = p_cty_information28,
3058       cty_information29        = p_cty_information29,
3059       cty_information30        = p_cty_information30
3061 
3062      if sql%notfound then
3063 
3064         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
3065         fnd_message.set_token('PROCEDURE',
3066                         'pay_us_emp_dt_tax_rules.update_city_tax_row');
3067         fnd_message.set_token('STEP','2');
3068         fnd_message.raise_error;
3069 
3070      end if;
3071 
3072      if p_school_district_code is not null then
3073 
3074         /* Insert row into the pay_us_asg_reporting table */
3075 
3076         hr_utility.set_location('pay_us_emp_dt_tax_rules.update_city_tax_row'||
3077                                   ' - asg_geo row', 3);
3078 
3079         pay_asg_geo_pkg.create_asg_geo_row(P_assignment_id => p_assignment_id,
3080                                            P_jurisdiction  => p_state_code || '-' ||
3081                                                              p_school_district_code,
3082                                            P_tax_unit_id   =>  NULL );
3083      end if;
3084 
3085   end update_city_tax_row;
3086 
3087 
3088   /* Name     : delete_tax_row
3089      Purpose  : This routine will be called by the W4 form to purge a tax rule record.
3090                 Only purging(i.e. ZAP) of the tax record will be allowed. No other kind
3091                 of delete will be allowed for the tax record. If a state record is purged,
3092                 then all of the county and city records for that state, will also be purged.
3093                 Similarly, is a county record is purged then all of the city records under
3094                 that county, will also be purged.
3095                 Along with the tax rule record, the tax %age records associated with that
3096                 tax rules record, will also be purged i.e. delete cascade
3097     Parameters :
3098                 p_assignment_id     -> The assignment whose tax record will be purged.
3099                 p_state_code        -> State whose tax record will be purged
3100                 p_county_code       -> County whose tax record will be purged
3101                 p_city_code         -> City whose tax record will be purged
3102   */
3103 
3104   procedure delete_tax_row ( p_assignment_id in number,
3105                              p_state_code    in varchar2,
3106                              p_county_code   in varchar2,
3107                              p_city_code     in varchar2) is
3108 
3109   l_ret_code             number;
3110   l_ret_text             varchar2(240);
3111   l_jurisdiction_code    varchar2(11);
3112   l_effective_start_date date;
3113   l_payroll_installed    boolean := FALSE;
3114 
3115   /* Cursor to get the counties for the state */
3116   cursor csr_state_counties is
3117    select puc.jurisdiction_code
3118    from   PAY_US_EMP_COUNTY_TAX_RULES_F puc
3119    where  puc.assignment_id = p_assignment_id
3120    and    puc.state_code  = p_state_code;
3121 
3122   /* Cursor to get the cities for the state */
3123   cursor csr_state_cities is
3124    select puc.jurisdiction_code
3125    from   PAY_US_EMP_CITY_TAX_RULES_F puc
3126    where  puc.assignment_id = p_assignment_id
3127    and    puc.state_code  = p_state_code;
3128 
3129   /* Cursor to get the cities for the county */
3130   cursor csr_county_cities is
3131    select puc.jurisdiction_code
3132    from   PAY_US_EMP_CITY_TAX_RULES_F puc
3133    where  puc.assignment_id = p_assignment_id
3134    and    puc.state_code  = p_state_code
3135    and    puc.county_code = p_county_code;
3136 
3137    /* cursor to get the start date of the tax %age record.
3138       The min federal effective date is the date on which the
3139       default tax rules criteria was satisfied. */
3140 
3141    cursor csr_get_eff_date is
3142        select min(effective_start_date)
3143        from   PAY_US_EMP_FED_TAX_RULES_F
3144        where  assignment_id = p_assignment_id;
3145 
3146    begin
3147 
3148          /* Check if payroll has been installed or not */
3149 
3150          l_payroll_installed := hr_utility.chk_product_install(p_product =>'Oracle Payroll',
3151                                                                p_legislation => 'US');
3152 
3153        /* Now all validations done. Go ahead and delete the element entries.
3154           Once the element entries are deleted, delete the tax rules records */
3155 
3156        /* Get the start date of the tax percentage records */
3157 
3158        open csr_get_eff_date;
3159 
3160        fetch csr_get_eff_date into l_effective_start_date;
3161 
3162        if l_effective_start_date is null then
3163            fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
3164            fnd_message.set_token('PROCEDURE',
3165                       'pay_us_emp_dt_tax_rules.delete_tax_row');
3166            fnd_message.set_token('STEP','1');
3167            fnd_message.raise_error;
3168        end if;
3169 
3170        close csr_get_eff_date;
3171 
3172        /* Processing for deleteing the state tax rule record */
3173 
3174        if p_state_code is not null and p_county_code is null
3175           and p_city_code is null then
3176 
3177          /* Delete the element entries only if Payroll is installed */
3178 
3179           if l_payroll_installed then
3180 
3184              open csr_state_cities;
3181             /* Get the cities for the state and call the maintain_element_entry routine
3182               to delete the city %age records for the cities in the state */
3183 
3185 
3186              loop
3187 
3188                fetch csr_state_cities into l_jurisdiction_code;
3189 
3190                exit when csr_state_cities%NOTFOUND;
3191 
3192                /* Delete the %age tax record for the jurisdiction */
3193 
3194                maintain_element_entry(p_assignment_id        => p_assignment_id,
3195                                       p_effective_start_date => l_effective_start_date,
3196                                     p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
3197                                       p_session_date         => l_effective_start_date,
3198                                       p_jurisdiction_code    => l_jurisdiction_code,
3199                                       p_percentage_time      => 0,
3200                                       p_mode                 => 'ZAP');
3201 
3202 
3203              end loop;
3204 
3205              close csr_state_cities;
3206 
3207              /* Get the counties for the state and call the maintain_element_entry routine
3208                 to delete the county %age records for the cities in the state */
3209 
3210              open csr_state_counties;
3211 
3212              loop
3213 
3214                 fetch csr_state_counties into l_jurisdiction_code;
3215 
3216                 exit when csr_state_counties%NOTFOUND;
3217 
3218                 /* Delete the %age tax record for the jurisdiction */
3219 
3220                 maintain_element_entry(p_assignment_id       => p_assignment_id,
3221                                       p_effective_start_date => l_effective_start_date,
3222                                       p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
3223                                       p_session_date         => l_effective_start_date,
3224                                       p_jurisdiction_code    => l_jurisdiction_code,
3225                                       p_percentage_time      => 0,
3226                                       p_mode                 => 'ZAP');
3227 
3228              end loop;
3229 
3230              close csr_state_counties;
3231 
3232              /* Delete the state %age records for the state */
3233 
3234                 maintain_element_entry(p_assignment_id       => p_assignment_id,
3235                                       p_effective_start_date => l_effective_start_date,
3236                                       p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
3237                                       p_session_date         => l_effective_start_date,
3238                                       p_jurisdiction_code    => p_state_code || '-000-0000',
3239                                       p_percentage_time      => 0,
3240                                       p_mode                 => 'ZAP');
3241          end if;
3242 
3243          /* Delete records from PAY_US_EMP_CITY_TAX_RULES_F */
3244 
3245          delete PAY_US_EMP_CITY_TAX_RULES_F
3246          where assignment_id = p_assignment_id
3247          and  state_code = p_state_code;
3248 
3249          /* Delete records from PAY_US_EMP_COUNTY_TAX_RULES_F */
3250 
3251          delete PAY_US_EMP_COUNTY_TAX_RULES_F
3252          where assignment_id = p_assignment_id
3253          and  state_code = p_state_code;
3254 
3255          /* Delete records from PAY_US_EMP_STATE_TAX_RULES_F */
3256 
3257          delete PAY_US_EMP_STATE_TAX_RULES_F
3258          where assignment_id = p_assignment_id
3259          and  state_code = p_state_code;
3260 
3261        elsif p_state_code is not null and p_county_code is not null
3262              and p_city_code is null then
3263 
3264          if l_payroll_installed then
3265 
3266              /* Get the cities for the county and call the maintain_element_entry routine
3267                 to delete the city %age records for the cities in the county */
3268 
3269              open csr_county_cities;
3270 
3271              loop
3272 
3273                  fetch csr_county_cities into l_jurisdiction_code;
3274 
3275                  exit when csr_county_cities%NOTFOUND;
3276 
3277                  /* Delete the %age tax record for the jurisdiction */
3278 
3279                  maintain_element_entry(p_assignment_id      => p_assignment_id,
3280                                       p_effective_start_date => l_effective_start_date,
3281                                       p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
3282                                       p_session_date         => l_effective_start_date,
3283                                       p_jurisdiction_code    => l_jurisdiction_code,
3284                                       p_percentage_time      => 0,
3285                                       p_mode                 => 'ZAP');
3286 
3287              end loop;
3288 
3289              close csr_county_cities;
3290 
3291              /* Delete the state %age records for the county */
3292 
3293              maintain_element_entry(p_assignment_id      => p_assignment_id,
3294                                       p_effective_start_date => l_effective_start_date,
3295                                       p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
3296                                       p_session_date         => l_effective_start_date,
3300                                       p_mode                 => 'ZAP');
3297                                       p_jurisdiction_code    => p_state_code ||'-' ||
3298                                                                 p_county_code ||'-0000',
3299                                       p_percentage_time      => 0,
3301           end if;
3302 
3303           /* Delete records from PAY_US_EMP_CITY_TAX_RULES_F */
3304 
3305           delete PAY_US_EMP_CITY_TAX_RULES_F
3306           where assignment_id = p_assignment_id
3307           and  state_code     = p_state_code
3308           and  county_code    = p_county_code;
3309 
3310           /* Delete records from PAY_US_EMP_COUNTY_TAX_RULES_F */
3311 
3312           delete PAY_US_EMP_COUNTY_TAX_RULES_F
3313           where assignment_id = p_assignment_id
3314           and  state_code     = p_state_code
3315           and  county_code    = p_county_code;
3316 
3317         elsif p_state_code is not null and p_county_code is not null
3318               and p_city_code is not null then
3319 
3320           if l_payroll_installed then
3321 
3322               /* Delete the state %age records for the city */
3323 
3324               maintain_element_entry(p_assignment_id      => p_assignment_id,
3325                                      p_effective_start_date => l_effective_start_date,
3326                                      p_effective_end_date   => to_date('31-12-4712','dd-mm-yyyy'),
3327                                      p_session_date         => l_effective_start_date,
3328                                      p_jurisdiction_code    => p_state_code ||'-' ||
3329                                                                p_county_code ||'-'|| p_city_code,
3330                                      p_percentage_time      => 0,
3331                                      p_mode                 => 'ZAP');
3332 
3333            end if;
3334 
3335            /* Delete records from PAY_US_EMP_CITY_TAX_RULES_F */
3336 
3337            delete PAY_US_EMP_CITY_TAX_RULES_F
3338            where assignment_id = p_assignment_id
3339            and  state_code     = p_state_code
3340            and  county_code    = p_county_code
3341            and  city_code      = p_city_code;
3342 
3343         end if;
3344 
3345    end delete_tax_row;
3346 
3347 
3348   /* Name        : lock_fed_tax_row
3349      Purpose     : To lock the federal tax rule record.
3350   */
3351 
3352   procedure lock_fed_tax_row ( p_row_id                    in varchar2,
3353                                   p_emp_fed_tax_rule_id      in number,
3354 				                  p_effective_start_date     in date,
3355                                   p_effective_end_date       in date,
3356                                   p_assignment_id            in number,
3357                                   p_sui_state_code           in varchar2,
3358                                   p_sui_jurisdiction_code    in varchar2,
3359                                   p_business_group_id        in number,
3360                                   p_additional_wa_amount     in number,
3361                                   p_filing_status_code       in varchar2,
3362                                   p_fit_override_amount      in number,
3363  				                  p_fit_override_rate        in number,
3364                                   p_withholding_allowances   in number,
3365                                   p_cumulative_taxation      in varchar2,
3366                                   p_eic_filing_status_code   in varchar2,
3367                                   p_fit_additional_tax       in number,
3368                                   p_fit_exempt               in varchar2,
3369                                   p_futa_tax_exempt          in varchar2,
3370                                   p_medicare_tax_exempt      in varchar2,
3371                                   p_ss_tax_exempt            in varchar2,
3372                                   p_wage_exempt              in varchar2,
3373                                   p_statutory_employee       in varchar2,
3374                                   p_w2_filed_year            in number,
3375                                   p_supp_tax_override_rate   in number,
3376                                   p_excessive_wa_reject_date in date,
3377                                   p_attribute_category        in varchar2,
3378                                   p_attribute1                in varchar2,
3379                                   p_attribute2                in varchar2,
3380                                   p_attribute3                in varchar2,
3381                                   p_attribute4                in varchar2,
3382                                   p_attribute5                in varchar2,
3383                                   p_attribute6                in varchar2,
3384                                   p_attribute7                in varchar2,
3385                                   p_attribute8                in varchar2,
3386                                   p_attribute9                in varchar2,
3387                                   p_attribute10               in varchar2,
3388                                   p_attribute11               in varchar2,
3389                                   p_attribute12               in varchar2,
3390                                   p_attribute13               in varchar2,
3391                                   p_attribute14               in varchar2,
3392                                   p_attribute15               in varchar2,
3393                                   p_attribute16               in varchar2,
3394                                   p_attribute17               in varchar2,
3398                                   p_attribute21               in varchar2,
3395                                   p_attribute18               in varchar2,
3396                                   p_attribute19               in varchar2,
3397                                   p_attribute20               in varchar2,
3399                                   p_attribute22               in varchar2,
3400                                   p_attribute23               in varchar2,
3401                                   p_attribute24               in varchar2,
3402                                   p_attribute25               in varchar2,
3403                                   p_attribute26               in varchar2,
3404                                   p_attribute27               in varchar2,
3405                                   p_attribute28               in varchar2,
3406                                   p_attribute29               in varchar2,
3407                                   p_attribute30               in varchar2,
3408                                   p_fed_information_category  in varchar2,
3409                                   p_fed_information1          in varchar2,
3410                                   p_fed_information2          in varchar2,
3411                                   p_fed_information3          in varchar2,
3412                                   p_fed_information4          in varchar2,
3413                                   p_fed_information5          in varchar2,
3414                                   p_fed_information6          in varchar2,
3415                                   p_fed_information7          in varchar2,
3416                                   p_fed_information8          in varchar2,
3417                                   p_fed_information9          in varchar2,
3418                                   p_fed_information10         in varchar2,
3419                                   p_fed_information11         in varchar2,
3420                                   p_fed_information12         in varchar2,
3421                                   p_fed_information13         in varchar2,
3422                                   p_fed_information14         in varchar2,
3423                                   p_fed_information15         in varchar2,
3424                                   p_fed_information16         in varchar2,
3425                                   p_fed_information17         in varchar2,
3426                                   p_fed_information18         in varchar2,
3427                                   p_fed_information19         in varchar2,
3428                                   p_fed_information20         in varchar2,
3429                                   p_fed_information21         in varchar2,
3430                                   p_fed_information22         in varchar2,
3431                                   p_fed_information23         in varchar2,
3432                                   p_fed_information24         in varchar2,
3433                                   p_fed_information25         in varchar2,
3434                                   p_fed_information26         in varchar2,
3435                                   p_fed_information27         in varchar2,
3436                                   p_fed_information28         in varchar2,
3437                                   p_fed_information29         in varchar2,
3438                                   p_fed_information30         in varchar2  ) is
3439 
3440   cursor csr_asg_rec is
3441   select assignment_id
3442   from   PER_ASSIGNMENTS_F
3443   where  assignment_id = p_assignment_id
3444   and    p_effective_start_date between effective_start_date
3445          and effective_end_date
3446   for update of assignment_id nowait;
3447 
3448   cursor csr_fed_rec is
3449   select *
3450   from   PAY_US_EMP_FED_TAX_RULES_F
3451   where  rowid = chartorowid(p_row_id)
3452   for update of emp_fed_tax_rule_id nowait;
3453 
3454   fed_rec csr_fed_rec%rowtype;
3455   l_assignment_id  number(9);
3456 
3457   begin
3458 
3459      open csr_asg_rec;
3460 
3461      fetch csr_asg_rec into l_assignment_id;
3462 
3463      if csr_asg_rec%NOTFOUND then
3464         close  csr_asg_rec;
3465         fnd_message.set_name('FND', 'FORM_UNABLE_TO_RESERVE_RECORD');
3466         fnd_message.raise_error;
3467      end if;
3468 
3469      close csr_asg_rec;
3470 
3471      open csr_fed_rec;
3472 
3473      fetch csr_fed_rec into fed_rec;
3474 
3475      if csr_fed_rec%NOTFOUND then
3476         close  csr_fed_rec;
3477         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
3478         fnd_message.set_token('PROCEDURE',
3479         'pay_us_emp_dt_tax_rules.lock_fed_tax_row');
3480         fnd_message.set_token('STEP', '1');
3481         fnd_message.raise_error;
3482      end if;
3483 
3484      close  csr_fed_rec;
3485 
3486       fed_rec.sui_state_code           := rtrim(fed_rec.sui_state_code);
3487       fed_rec.sui_jurisdiction_code    := rtrim(fed_rec.sui_jurisdiction_code);
3488       fed_rec.filing_status_code       := rtrim(fed_rec.filing_status_code);
3489       fed_rec.cumulative_taxation      := rtrim(fed_rec.cumulative_taxation);
3490       fed_rec.eic_filing_status_code   := rtrim(fed_rec.eic_filing_status_code);
3491       fed_rec.fit_exempt               := rtrim(fed_rec.fit_exempt);
3492       fed_rec.futa_tax_exempt          := rtrim(fed_rec.futa_tax_exempt);
3493       fed_rec.medicare_tax_exempt      := rtrim(fed_rec.medicare_tax_exempt);
3494       fed_rec.ss_tax_exempt            := rtrim(fed_rec.ss_tax_exempt);
3495       fed_rec.wage_exempt              := rtrim(fed_rec.wage_exempt);
3496       fed_rec.statutory_employee       := rtrim(fed_rec.statutory_employee);
3500       fed_rec.attribute3           := rtrim(fed_rec.attribute3);
3497       fed_rec.attribute_category   := rtrim(fed_rec.attribute_category);
3498       fed_rec.attribute1           := rtrim(fed_rec.attribute1);
3499       fed_rec.attribute2           := rtrim(fed_rec.attribute2);
3501       fed_rec.attribute4           := rtrim(fed_rec.attribute4);
3502       fed_rec.attribute5           := rtrim(fed_rec.attribute5);
3503       fed_rec.attribute6           := rtrim(fed_rec.attribute6);
3504       fed_rec.attribute7           := rtrim(fed_rec.attribute7);
3505       fed_rec.attribute8           := rtrim(fed_rec.attribute8);
3506       fed_rec.attribute9           := rtrim(fed_rec.attribute9);
3507       fed_rec.attribute10          := rtrim(fed_rec.attribute10);
3508       fed_rec.attribute11          := rtrim(fed_rec.attribute11);
3509       fed_rec.attribute12          := rtrim(fed_rec.attribute12);
3510       fed_rec.attribute13          := rtrim(fed_rec.attribute13);
3511       fed_rec.attribute14          := rtrim(fed_rec.attribute14);
3512       fed_rec.attribute15          := rtrim(fed_rec.attribute15);
3513       fed_rec.attribute16          := rtrim(fed_rec.attribute16);
3514       fed_rec.attribute17          := rtrim(fed_rec.attribute17);
3515       fed_rec.attribute18          := rtrim(fed_rec.attribute18);
3516       fed_rec.attribute19          := rtrim(fed_rec.attribute19);
3517       fed_rec.attribute20          := rtrim(fed_rec.attribute20);
3518       fed_rec.attribute21          := rtrim(fed_rec.attribute21);
3519       fed_rec.attribute22          := rtrim(fed_rec.attribute22);
3520       fed_rec.attribute23          := rtrim(fed_rec.attribute23);
3521       fed_rec.attribute24          := rtrim(fed_rec.attribute24);
3522       fed_rec.attribute25          := rtrim(fed_rec.attribute25);
3523       fed_rec.attribute26          := rtrim(fed_rec.attribute26);
3524       fed_rec.attribute27          := rtrim(fed_rec.attribute27);
3525       fed_rec.attribute28          := rtrim(fed_rec.attribute28);
3526       fed_rec.attribute29          := rtrim(fed_rec.attribute29);
3527       fed_rec.attribute30          := rtrim(fed_rec.attribute30);
3528       fed_rec.fed_information_category   := rtrim(fed_rec.fed_information_category);
3529       fed_rec.fed_information1     := rtrim(fed_rec.fed_information1);
3530       fed_rec.fed_information2     := rtrim(fed_rec.fed_information2);
3531       fed_rec.fed_information3     := rtrim(fed_rec.fed_information3);
3532       fed_rec.fed_information4     := rtrim(fed_rec.fed_information4);
3533       fed_rec.fed_information5     := rtrim(fed_rec.fed_information5);
3534       fed_rec.fed_information6     := rtrim(fed_rec.fed_information6);
3535       fed_rec.fed_information7     := rtrim(fed_rec.fed_information7);
3536       fed_rec.fed_information8     := rtrim(fed_rec.fed_information8);
3537       fed_rec.fed_information9     := rtrim(fed_rec.fed_information9);
3538       fed_rec.fed_information10    := rtrim(fed_rec.fed_information10);
3539       fed_rec.fed_information11    := rtrim(fed_rec.fed_information11);
3540       fed_rec.fed_information12    := rtrim(fed_rec.fed_information12);
3541       fed_rec.fed_information13    := rtrim(fed_rec.fed_information13);
3542       fed_rec.fed_information14    := rtrim(fed_rec.fed_information14);
3543       fed_rec.fed_information15    := rtrim(fed_rec.fed_information15);
3544       fed_rec.fed_information16    := rtrim(fed_rec.fed_information16);
3545       fed_rec.fed_information17    := rtrim(fed_rec.fed_information17);
3546       fed_rec.fed_information18    := rtrim(fed_rec.fed_information18);
3547       fed_rec.fed_information19    := rtrim(fed_rec.fed_information19);
3548       fed_rec.fed_information20    := rtrim(fed_rec.fed_information20);
3549       fed_rec.fed_information21    := rtrim(fed_rec.fed_information21);
3550       fed_rec.fed_information22    := rtrim(fed_rec.fed_information22);
3551       fed_rec.fed_information23    := rtrim(fed_rec.fed_information23);
3552       fed_rec.fed_information24    := rtrim(fed_rec.fed_information24);
3553       fed_rec.fed_information25    := rtrim(fed_rec.fed_information25);
3554       fed_rec.fed_information26    := rtrim(fed_rec.fed_information26);
3555       fed_rec.fed_information27    := rtrim(fed_rec.fed_information27);
3556       fed_rec.fed_information28    := rtrim(fed_rec.fed_information28);
3557       fed_rec.fed_information29    := rtrim(fed_rec.fed_information29);
3558       fed_rec.fed_information30    := rtrim(fed_rec.fed_information30);
3559 
3560 
3561         if ((fed_rec.emp_fed_tax_rule_id = p_emp_fed_tax_rule_id)
3562            or (fed_rec.emp_fed_tax_rule_id is null and
3563                p_emp_fed_tax_rule_id is null))
3564         and ((fed_rec.effective_start_date = p_effective_start_date)
3565            or (fed_rec.effective_start_date is null and
3566                p_effective_start_date is null))
3567         and ((fed_rec.effective_end_date = p_effective_end_date)
3568            or (fed_rec.effective_end_date is null and
3569                p_effective_end_date is null))
3570         and ((fed_rec.assignment_id = p_assignment_id)
3571            or (fed_rec.assignment_id is null and
3572                p_assignment_id is null))
3573         and ((fed_rec.sui_state_code = p_sui_state_code)
3574            or (fed_rec.sui_state_code is null and
3575                p_sui_state_code is null))
3576         and ((fed_rec.sui_jurisdiction_code = p_sui_jurisdiction_code)
3577            or (fed_rec.sui_jurisdiction_code is null and
3578                p_sui_jurisdiction_code is null))
3579         and ((fed_rec.business_group_id = p_business_group_id)
3580            or (fed_rec.business_group_id is null and
3581                p_business_group_id is null))
3582         and ((fed_rec.additional_wa_amount = p_additional_wa_amount)
3586            or (fed_rec.filing_status_code is null and
3583            or (fed_rec.additional_wa_amount is null and
3584                p_additional_wa_amount is null))
3585         and ((fed_rec.filing_status_code = lpad(p_filing_status_code,2,'0'))
3587                p_filing_status_code is null))
3588         and ((fed_rec.fit_override_amount = p_fit_override_amount)
3589            or (fed_rec.fit_override_amount is null and
3590                p_fit_override_amount is null))
3591         and ((fed_rec.fit_override_rate = p_fit_override_rate)
3592            or (fed_rec.fit_override_rate is null and
3593                p_fit_override_rate is null))
3594         and ((fed_rec.withholding_allowances = p_withholding_allowances)
3595            or (fed_rec.withholding_allowances is null and
3596                p_withholding_allowances is null))
3597         and ((fed_rec.cumulative_taxation = p_cumulative_taxation)
3598            or (fed_rec.cumulative_taxation is null and
3599                p_cumulative_taxation is null))
3600         and ((fed_rec.eic_filing_status_code = p_eic_filing_status_code)
3601            or (fed_rec.eic_filing_status_code is null and
3602                p_eic_filing_status_code is null))
3603         and ((fed_rec.fit_additional_tax = p_fit_additional_tax)
3604            or (fed_rec.fit_additional_tax is null and
3605                p_fit_additional_tax is null))
3606         and ((fed_rec.fit_exempt = p_fit_exempt)
3607            or (fed_rec.fit_exempt is null and
3608                p_fit_exempt is null))
3609         and ((fed_rec.futa_tax_exempt = p_futa_tax_exempt)
3610            or (fed_rec.futa_tax_exempt is null and
3611                p_futa_tax_exempt is null))
3612         and ((fed_rec.medicare_tax_exempt = p_medicare_tax_exempt)
3613            or (fed_rec.medicare_tax_exempt is null and
3614                p_medicare_tax_exempt is null))
3615         and ((fed_rec.ss_tax_exempt = p_ss_tax_exempt)
3616            or (fed_rec.ss_tax_exempt is null and
3617                p_ss_tax_exempt is null))
3618         and ((fed_rec.wage_exempt = p_wage_exempt)
3619            or (fed_rec.wage_exempt is null and
3620                p_wage_exempt is null))
3621         and ((fed_rec.statutory_employee = p_statutory_employee)
3622            or (fed_rec.statutory_employee is null and
3623                p_statutory_employee is null))
3624         and ((fed_rec.w2_filed_year = p_w2_filed_year)
3625            or (fed_rec.w2_filed_year is null and
3626                p_w2_filed_year is null))
3627         and ((fed_rec.supp_tax_override_rate = p_supp_tax_override_rate)
3628            or (fed_rec.supp_tax_override_rate is null and
3629                p_supp_tax_override_rate is null))
3630         and ((fed_rec.excessive_wa_reject_date = p_excessive_wa_reject_date)
3631            or (fed_rec.excessive_wa_reject_date is null and
3632                p_excessive_wa_reject_date is null))
3633         and ((fed_rec.attribute_category = p_attribute_category)
3634            or (fed_rec.attribute_category is null and
3635                p_attribute_category is null))
3636         and ((fed_rec.attribute1 = p_attribute1)
3637            or (fed_rec.attribute1 is null and
3638                p_attribute1 is null))
3639         and ((fed_rec.attribute2 = p_attribute2)
3640            or (fed_rec.attribute2 is null and
3641                p_attribute2 is null))
3642         and ((fed_rec.attribute3 = p_attribute3)
3643            or (fed_rec.attribute3 is null and
3644                p_attribute3 is null))
3645         and ((fed_rec.attribute4 = p_attribute4)
3646            or (fed_rec.attribute4 is null and
3647                p_attribute4 is null))
3648         and ((fed_rec.attribute5 = p_attribute5)
3649            or (fed_rec.attribute5 is null and
3650                p_attribute5 is null))
3651         and ((fed_rec.attribute6 = p_attribute6)
3652            or (fed_rec.attribute6 is null and
3653                p_attribute6 is null))
3654         and ((fed_rec.attribute7 = p_attribute7)
3655            or (fed_rec.attribute7 is null and
3656                p_attribute7 is null))
3657         and ((fed_rec.attribute8 = p_attribute8)
3658            or (fed_rec.attribute8 is null and
3659                p_attribute8 is null))
3660         and ((fed_rec.attribute9 = p_attribute9)
3661            or (fed_rec.attribute9 is null and
3662                p_attribute9 is null))
3663         and ((fed_rec.attribute10 = p_attribute10)
3664            or (fed_rec.attribute10 is null and
3665                p_attribute10 is null))
3666         and ((fed_rec.attribute11 = p_attribute11)
3667            or (fed_rec.attribute11 is null and
3668                p_attribute11 is null))
3669         and ((fed_rec.attribute12 = p_attribute12)
3670            or (fed_rec.attribute12 is null and
3671                p_attribute12 is null))
3672         and ((fed_rec.attribute13 = p_attribute13)
3673            or (fed_rec.attribute13 is null and
3674                p_attribute13 is null))
3675         and ((fed_rec.attribute14 = p_attribute14)
3676            or (fed_rec.attribute14 is null and
3677                p_attribute14 is null))
3678         and ((fed_rec.attribute15 = p_attribute15)
3679            or (fed_rec.attribute15 is null and
3680                p_attribute15 is null))
3681         and ((fed_rec.attribute16 = p_attribute16)
3682            or (fed_rec.attribute16 is null and
3683                p_attribute16 is null))
3684         and ((fed_rec.attribute17 = p_attribute17)
3685            or (fed_rec.attribute17 is null and
3686                p_attribute17 is null))
3687         and ((fed_rec.attribute18 = p_attribute18)
3688            or (fed_rec.attribute18 is null and
3692                p_attribute19 is null))
3689                p_attribute18 is null))
3690         and ((fed_rec.attribute19 = p_attribute19)
3691            or (fed_rec.attribute19 is null and
3693         and ((fed_rec.attribute20 = p_attribute20)
3694            or (fed_rec.attribute20 is null and
3695                p_attribute20 is null))
3696         and ((fed_rec.attribute21 = p_attribute21)
3697            or (fed_rec.attribute21 is null and
3698                p_attribute21 is null))
3699         and ((fed_rec.attribute22 = p_attribute22)
3700            or (fed_rec.attribute22 is null and
3701                p_attribute22 is null))
3702         and ((fed_rec.attribute23 = p_attribute23)
3703            or (fed_rec.attribute23 is null and
3704                p_attribute23 is null))
3705         and ((fed_rec.attribute24 = p_attribute24)
3706            or (fed_rec.attribute24 is null and
3707                p_attribute24 is null))
3708         and ((fed_rec.attribute25 = p_attribute25)
3709            or (fed_rec.attribute25 is null and
3710                p_attribute25 is null))
3711         and ((fed_rec.attribute26 = p_attribute26)
3712            or (fed_rec.attribute26 is null and
3713                p_attribute26 is null))
3714         and ((fed_rec.attribute27 = p_attribute27)
3715            or (fed_rec.attribute27 is null and
3716                p_attribute27 is null))
3717         and ((fed_rec.attribute28 = p_attribute28)
3718            or (fed_rec.attribute28 is null and
3719                p_attribute28 is null))
3720         and ((fed_rec.attribute29 = p_attribute29)
3721            or (fed_rec.attribute29 is null and
3722                p_attribute29 is null))
3723         and ((fed_rec.attribute30 = p_attribute30)
3724            or (fed_rec.attribute30 is null and
3725                p_attribute30 is null))
3726         and ((fed_rec.fed_information_category = p_fed_information_category)
3727            or (fed_rec.fed_information_category is null and
3728                p_fed_information_category is null))
3729         and ((fed_rec.fed_information1 = p_fed_information1)
3730            or (fed_rec.fed_information1 is null and
3731                p_fed_information1 is null))
3732         and ((fed_rec.fed_information2 = p_fed_information2)
3733            or (fed_rec.fed_information2 is null and
3734                p_fed_information2 is null))
3735         and ((fed_rec.fed_information3 = p_fed_information3)
3736            or (fed_rec.fed_information3 is null and
3737                p_fed_information3 is null))
3738         and ((fed_rec.fed_information4 = p_fed_information4)
3739            or (fed_rec.fed_information4 is null and
3740                p_fed_information4 is null))
3741         and ((fed_rec.fed_information5 = p_fed_information5)
3742            or (fed_rec.fed_information5 is null and
3743                p_fed_information5 is null))
3744         and ((fed_rec.fed_information6 = p_fed_information6)
3745            or (fed_rec.fed_information6 is null and
3746                p_fed_information6 is null))
3747         and ((fed_rec.fed_information7 = p_fed_information7)
3748            or (fed_rec.fed_information7 is null and
3749                p_fed_information7 is null))
3750         and ((fed_rec.fed_information8 = p_fed_information8)
3751            or (fed_rec.fed_information8 is null and
3752                p_fed_information8 is null))
3753         and ((fed_rec.fed_information9 = p_fed_information9)
3754            or (fed_rec.fed_information9 is null and
3755                p_fed_information9 is null))
3756         and ((fed_rec.fed_information10 = p_fed_information10)
3757            or (fed_rec.fed_information10 is null and
3758                p_fed_information10 is null))
3759         and ((fed_rec.fed_information11 = p_fed_information11)
3760            or (fed_rec.fed_information11 is null and
3761                p_fed_information11 is null))
3762         and ((fed_rec.fed_information12 = p_fed_information12)
3763            or (fed_rec.fed_information12 is null and
3764                p_fed_information12 is null))
3765         and ((fed_rec.fed_information13 = p_fed_information13)
3766            or (fed_rec.fed_information13 is null and
3767                p_fed_information13 is null))
3768         and ((fed_rec.fed_information14 = p_fed_information14)
3769            or (fed_rec.fed_information14 is null and
3770                p_fed_information14 is null))
3771         and ((fed_rec.fed_information15 = p_fed_information15)
3772            or (fed_rec.fed_information15 is null and
3773                p_fed_information15 is null))
3774         and ((fed_rec.fed_information16 = p_fed_information16)
3775            or (fed_rec.fed_information16 is null and
3776                p_fed_information16 is null))
3777         and ((fed_rec.fed_information17 = p_fed_information17)
3778            or (fed_rec.fed_information17 is null and
3779                p_fed_information17 is null))
3780         and ((fed_rec.fed_information18 = p_fed_information18)
3781            or (fed_rec.fed_information18 is null and
3782                p_fed_information18 is null))
3783         and ((fed_rec.fed_information19 = p_fed_information19)
3784            or (fed_rec.fed_information19 is null and
3785                p_fed_information19 is null))
3786         and ((fed_rec.fed_information20 = p_fed_information20)
3787            or (fed_rec.fed_information20 is null and
3788                p_fed_information20 is null))
3789         and ((fed_rec.fed_information21 = p_fed_information21)
3790            or (fed_rec.fed_information21 is null and
3791                p_fed_information21 is null))
3795         and ((fed_rec.fed_information23 = p_fed_information23)
3792         and ((fed_rec.fed_information22 = p_fed_information22)
3793            or (fed_rec.fed_information22 is null and
3794                p_fed_information22 is null))
3796            or (fed_rec.fed_information23 is null and
3797                p_fed_information23 is null))
3798         and ((fed_rec.fed_information24 = p_fed_information24)
3799            or (fed_rec.fed_information24 is null and
3800                p_fed_information24 is null))
3801         and ((fed_rec.fed_information25 = p_fed_information25)
3802            or (fed_rec.fed_information25 is null and
3803                p_fed_information25 is null))
3804         and ((fed_rec.fed_information26 = p_fed_information26)
3805            or (fed_rec.fed_information26 is null and
3806                p_fed_information26 is null))
3807         and ((fed_rec.fed_information27 = p_fed_information27)
3808            or (fed_rec.fed_information27 is null and
3809                p_fed_information27 is null))
3810         and ((fed_rec.fed_information28 = p_fed_information28)
3811            or (fed_rec.fed_information28 is null and
3812                p_fed_information28 is null))
3813         and ((fed_rec.fed_information29 = p_fed_information29)
3814            or (fed_rec.fed_information29 is null and
3815                p_fed_information29 is null))
3816         and ((fed_rec.fed_information30 = p_fed_information30)
3817            or (fed_rec.fed_information30 is null and
3818                p_fed_information30 is null))
3819      then
3820 
3821       return;
3822 
3823      else
3824 
3825         fnd_message.set_name('PAY', 'FORM_RECORD_CHANGED');
3826         fnd_message.raise_error;
3827 
3828      end if;
3829 
3830   end lock_fed_tax_row;
3831 
3832 
3833 
3834   /* Name        : lock_state_tax_row
3835      Purpose     : To lock the state tax rule record.
3836   */
3837 
3838   procedure lock_state_tax_row ( p_row_id in varchar2,
3839                                    p_emp_state_tax_rule_id in number,
3840                                    p_effective_start_date in date,
3841                                    p_effective_end_date in date,
3842                                    p_assignment_id in number,
3843                                    p_state_code in varchar2,
3844                                    p_jurisdiction_code in varchar2,
3845                                    p_business_group_id in number,
3846                                    p_additional_wa_amount in number,
3847                                    p_filing_status_code in varchar2,
3848                                    p_remainder_percent in number,
3849                                    p_secondary_wa in number,
3850                                    p_sit_additional_tax in number,
3851                                    p_sit_override_amount in number,
3852                                    p_sit_override_rate in number,
3853                                    p_withholding_allowances in number,
3854                                    p_excessive_wa_reject_date in date,
3855                                    p_sdi_exempt in varchar2,
3856                                    p_sit_exempt in varchar2,
3857                                    p_sit_optional_calc_ind in varchar2,
3858                                    p_state_non_resident_cert in varchar2,
3859                                    p_sui_exempt in varchar2,
3860                                    p_wc_exempt in varchar2,
3861                                    p_wage_exempt in varchar2,
3862                                    p_sui_wage_base_override_amt in number,
3863                                    p_supp_tax_override_rate in number,
3864                                    p_attribute_category        in varchar2,
3865                                    p_attribute1                in varchar2,
3866                                    p_attribute2                in varchar2,
3867                                    p_attribute3                in varchar2,
3868                                    p_attribute4                in varchar2,
3869                                    p_attribute5                in varchar2,
3870                                    p_attribute6                in varchar2,
3871                                    p_attribute7                in varchar2,
3872                                    p_attribute8                in varchar2,
3873                                    p_attribute9                in varchar2,
3874                                    p_attribute10               in varchar2,
3875                                    p_attribute11               in varchar2,
3876                                    p_attribute12               in varchar2,
3877                                    p_attribute13               in varchar2,
3878                                    p_attribute14               in varchar2,
3879                                    p_attribute15               in varchar2,
3880                                    p_attribute16               in varchar2,
3881                                    p_attribute17               in varchar2,
3882                                    p_attribute18               in varchar2,
3883                                    p_attribute19               in varchar2,
3884                                    p_attribute20               in varchar2,
3885                                    p_attribute21               in varchar2,
3886                                    p_attribute22               in varchar2,
3887                                    p_attribute23               in varchar2,
3891                                    p_attribute27               in varchar2,
3888                                    p_attribute24               in varchar2,
3889                                    p_attribute25               in varchar2,
3890                                    p_attribute26               in varchar2,
3892                                    p_attribute28               in varchar2,
3893                                    p_attribute29               in varchar2,
3894                                    p_attribute30               in varchar2,
3895                                    p_sta_information_category  in varchar2,
3896                                    p_sta_information1          in varchar2,
3897                                    p_sta_information2          in varchar2,
3898                                    p_sta_information3          in varchar2,
3899                                    p_sta_information4          in varchar2,
3900                                    p_sta_information5          in varchar2,
3901                                    p_sta_information6          in varchar2,
3902                                    p_sta_information7          in varchar2,
3903                                    p_sta_information8          in varchar2,
3904                                    p_sta_information9          in varchar2,
3905                                    p_sta_information10         in varchar2,
3906                                    p_sta_information11         in varchar2,
3907                                    p_sta_information12         in varchar2,
3908                                    p_sta_information13         in varchar2,
3909                                    p_sta_information14         in varchar2,
3910                                    p_sta_information15         in varchar2,
3911                                    p_sta_information16         in varchar2,
3912                                    p_sta_information17         in varchar2,
3913                                    p_sta_information18         in varchar2,
3914                                    p_sta_information19         in varchar2,
3915                                    p_sta_information20         in varchar2,
3916                                    p_sta_information21         in varchar2,
3917                                    p_sta_information22         in varchar2,
3918                                    p_sta_information23         in varchar2,
3919                                    p_sta_information24         in varchar2,
3920                                    p_sta_information25         in varchar2,
3921                                    p_sta_information26         in varchar2,
3922                                    p_sta_information27         in varchar2,
3923                                    p_sta_information28         in varchar2,
3924                                    p_sta_information29         in varchar2,
3925                                    p_sta_information30         in varchar2  ) is
3926 
3927   cursor csr_asg_rec is
3928   select assignment_id
3929   from   PER_ASSIGNMENTS_F
3930   where  assignment_id = p_assignment_id
3931   and    p_effective_start_date between effective_start_date
3932          and effective_end_date
3933   for update of assignment_id nowait;
3934 
3935   cursor csr_state_rec is
3936   select *
3937   from   PAY_US_EMP_STATE_TAX_RULES_F
3938   where  rowid = chartorowid(p_row_id)
3939   for update of emp_state_tax_rule_id nowait;
3940 
3941   state_rec   csr_state_rec%rowtype;
3942   l_assignment_id      number(9);
3943 
3944   begin
3945 
3946      open csr_asg_rec;
3947 
3948      fetch csr_asg_rec into l_assignment_id;
3949 
3950      if csr_asg_rec%NOTFOUND then
3951         close  csr_asg_rec;
3952         fnd_message.set_name('FND', 'FORM_UNABLE_TO_RESERVE_RECORD');
3953         fnd_message.raise_error;
3954      end if;
3955 
3956      close csr_asg_rec;
3957 
3958      open csr_state_rec;
3959 
3960      fetch csr_state_rec into state_rec;
3961 
3962      if csr_state_rec%NOTFOUND then
3963         close  csr_state_rec;
3964         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
3965         fnd_message.set_token('PROCEDURE',
3966         'pay_us_emp_dt_tax_rules.lock_state_tax_row');
3967         fnd_message.set_token('STEP', '1');
3968         fnd_message.raise_error;
3969      end if;
3970 
3971      close  csr_state_rec;
3972 
3973       state_rec.state_code               := rtrim(state_rec.state_code);
3974       state_rec.jurisdiction_code        := rtrim(state_rec.jurisdiction_code);
3975       state_rec.filing_status_code       := rtrim(state_rec.filing_status_code);
3976       state_rec.sdi_exempt               := rtrim(state_rec.sdi_exempt);
3977       state_rec.sit_exempt               := rtrim(state_rec.sit_exempt);
3978       state_rec.sit_optional_calc_ind    := rtrim(state_rec.sit_optional_calc_ind);
3979       state_rec.state_non_resident_cert  := rtrim(state_rec.state_non_resident_cert);
3980       state_rec.sui_exempt               := rtrim(state_rec.sui_exempt);
3981       state_rec.wc_exempt                 := rtrim(state_rec.wc_exempt);
3982       state_rec.wage_exempt               := rtrim(state_rec.wage_exempt);
3983       state_rec.attribute_category   := rtrim(state_rec.attribute_category);
3984       state_rec.attribute1           := rtrim(state_rec.attribute1);
3985       state_rec.attribute2           := rtrim(state_rec.attribute2);
3986       state_rec.attribute3           := rtrim(state_rec.attribute3);
3987       state_rec.attribute4           := rtrim(state_rec.attribute4);
3988       state_rec.attribute5           := rtrim(state_rec.attribute5);
3992       state_rec.attribute9           := rtrim(state_rec.attribute9);
3989       state_rec.attribute6           := rtrim(state_rec.attribute6);
3990       state_rec.attribute7           := rtrim(state_rec.attribute7);
3991       state_rec.attribute8           := rtrim(state_rec.attribute8);
3993       state_rec.attribute10          := rtrim(state_rec.attribute10);
3994       state_rec.attribute11          := rtrim(state_rec.attribute11);
3995       state_rec.attribute12          := rtrim(state_rec.attribute12);
3996       state_rec.attribute13          := rtrim(state_rec.attribute13);
3997       state_rec.attribute14          := rtrim(state_rec.attribute14);
3998       state_rec.attribute15          := rtrim(state_rec.attribute15);
3999       state_rec.attribute16          := rtrim(state_rec.attribute16);
4000       state_rec.attribute17          := rtrim(state_rec.attribute17);
4001       state_rec.attribute18          := rtrim(state_rec.attribute18);
4002       state_rec.attribute19          := rtrim(state_rec.attribute19);
4003       state_rec.attribute20          := rtrim(state_rec.attribute20);
4004       state_rec.attribute21          := rtrim(state_rec.attribute21);
4005       state_rec.attribute22          := rtrim(state_rec.attribute22);
4006       state_rec.attribute23          := rtrim(state_rec.attribute23);
4007       state_rec.attribute24          := rtrim(state_rec.attribute24);
4008       state_rec.attribute25          := rtrim(state_rec.attribute25);
4009       state_rec.attribute26          := rtrim(state_rec.attribute26);
4010       state_rec.attribute27          := rtrim(state_rec.attribute27);
4011       state_rec.attribute28          := rtrim(state_rec.attribute28);
4012       state_rec.attribute29          := rtrim(state_rec.attribute29);
4013       state_rec.attribute30          := rtrim(state_rec.attribute30);
4014       state_rec.sta_information_category   := rtrim(state_rec.sta_information_category);
4015       state_rec.sta_information1     := rtrim(state_rec.sta_information1);
4016       state_rec.sta_information2     := rtrim(state_rec.sta_information2);
4017       state_rec.sta_information3     := rtrim(state_rec.sta_information3);
4018       state_rec.sta_information4     := rtrim(state_rec.sta_information4);
4019       state_rec.sta_information5     := rtrim(state_rec.sta_information5);
4020       state_rec.sta_information6     := rtrim(state_rec.sta_information6);
4021       state_rec.sta_information7     := rtrim(state_rec.sta_information7);
4022       state_rec.sta_information8     := rtrim(state_rec.sta_information8);
4023       state_rec.sta_information9     := rtrim(state_rec.sta_information9);
4024       state_rec.sta_information10    := rtrim(state_rec.sta_information10);
4025       state_rec.sta_information11    := rtrim(state_rec.sta_information11);
4026       state_rec.sta_information12    := rtrim(state_rec.sta_information12);
4027       state_rec.sta_information13    := rtrim(state_rec.sta_information13);
4028       state_rec.sta_information14    := rtrim(state_rec.sta_information14);
4029       state_rec.sta_information15    := rtrim(state_rec.sta_information15);
4030       state_rec.sta_information16    := rtrim(state_rec.sta_information16);
4031       state_rec.sta_information17    := rtrim(state_rec.sta_information17);
4032       state_rec.sta_information18    := rtrim(state_rec.sta_information18);
4033       state_rec.sta_information19    := rtrim(state_rec.sta_information19);
4034       state_rec.sta_information20    := rtrim(state_rec.sta_information20);
4035       state_rec.sta_information21    := rtrim(state_rec.sta_information21);
4036       state_rec.sta_information22    := rtrim(state_rec.sta_information22);
4037       state_rec.sta_information23    := rtrim(state_rec.sta_information23);
4038       state_rec.sta_information24    := rtrim(state_rec.sta_information24);
4039       state_rec.sta_information25    := rtrim(state_rec.sta_information25);
4040       state_rec.sta_information26    := rtrim(state_rec.sta_information26);
4041       state_rec.sta_information27    := rtrim(state_rec.sta_information27);
4042       state_rec.sta_information28    := rtrim(state_rec.sta_information28);
4043       state_rec.sta_information29    := rtrim(state_rec.sta_information29);
4044       state_rec.sta_information30    := rtrim(state_rec.sta_information30);
4045 
4046         if ((state_rec.emp_state_tax_rule_id = p_emp_state_tax_rule_id)
4047            or (state_rec.emp_state_tax_rule_id is null and
4048                p_emp_state_tax_rule_id is null))
4049         and ((state_rec.effective_start_date = p_effective_start_date)
4050            or (state_rec.effective_start_date is null and
4051                p_effective_start_date is null))
4052         and ((state_rec.effective_end_date = p_effective_end_date)
4053            or (state_rec.effective_end_date is null and
4054                p_effective_end_date is null))
4055         and ((state_rec.assignment_id = p_assignment_id)
4056            or (state_rec.assignment_id is null and
4057                p_assignment_id is null))
4058         and ((state_rec.state_code = p_state_code)
4059            or (state_rec.state_code is null and
4060                p_state_code is null))
4061         and ((state_rec.jurisdiction_code = p_jurisdiction_code)
4062            or (state_rec.jurisdiction_code is null and
4063                p_jurisdiction_code is null))
4064         and ((state_rec.business_group_id = p_business_group_id)
4065            or (state_rec.business_group_id is null and
4066                p_business_group_id is null))
4067         and ((state_rec.additional_wa_amount = p_additional_wa_amount)
4068            or (state_rec.additional_wa_amount is null and
4069                p_additional_wa_amount is null))
4070         and ((state_rec.filing_status_code = lpad(p_filing_status_code,2,'0'))
4074            or (state_rec.remainder_percent is null and
4071            or (state_rec.filing_status_code is null and
4072                p_filing_status_code is null))
4073         and ((state_rec.remainder_percent = p_remainder_percent)
4075                p_remainder_percent is null))
4076         and ((state_rec.secondary_wa = p_secondary_wa)
4077            or (state_rec.secondary_wa is null and
4078                p_secondary_wa is null))
4079         and ((state_rec.sit_additional_tax = p_sit_additional_tax)
4080            or (state_rec.sit_additional_tax is null and
4081                p_sit_additional_tax is null))
4082         and ((state_rec.sit_override_amount = p_sit_override_amount)
4083            or (state_rec.sit_override_amount is null and
4084                p_sit_override_amount is null))
4085         and ((state_rec.sit_override_rate = p_sit_override_rate)
4086            or (state_rec.sit_override_rate is null and
4087                p_sit_override_rate is null))
4088         and ((state_rec.withholding_allowances = p_withholding_allowances)
4089            or (state_rec.withholding_allowances is null and
4090                p_withholding_allowances is null))
4091         and ((state_rec.excessive_wa_reject_date = p_excessive_wa_reject_date)
4092            or (state_rec.excessive_wa_reject_date is null and
4093                p_excessive_wa_reject_date is null))
4094         and ((state_rec.sdi_exempt = p_sdi_exempt)
4095            or (state_rec.sdi_exempt is null and
4096                p_sdi_exempt is null))
4097         and ((state_rec.sit_exempt = p_sit_exempt)
4098            or (state_rec.sit_exempt is null and
4099                p_sit_exempt is null))
4100         and ((state_rec.sit_optional_calc_ind = p_sit_optional_calc_ind)
4101            or (state_rec.sit_optional_calc_ind is null and
4102                p_sit_optional_calc_ind is null))
4103         and ((state_rec.state_non_resident_cert = p_state_non_resident_cert)
4104            or (state_rec.state_non_resident_cert is null and
4105                p_state_non_resident_cert is null))
4106         and ((state_rec.sui_exempt = p_sui_exempt)
4107            or (state_rec.sui_exempt is null and
4108                p_sui_exempt is null))
4109         and ((state_rec.wc_exempt = p_wc_exempt)
4110            or (state_rec.wc_exempt is null and
4111                p_wc_exempt is null))
4112         and ((state_rec.wage_exempt = p_wage_exempt)
4113            or (state_rec.wage_exempt is null and
4114                p_wage_exempt is null))
4115         and ((state_rec.sui_wage_base_override_amount = p_sui_wage_base_override_amt)
4116            or (state_rec.sui_wage_base_override_amount is null and
4117                p_sui_wage_base_override_amt is null))
4118         and ((state_rec.supp_tax_override_rate = p_supp_tax_override_rate)
4119            or (state_rec.supp_tax_override_rate is null and
4120                p_supp_tax_override_rate is null))
4121         and ((state_rec.attribute_category = p_attribute_category)
4122            or (state_rec.attribute_category is null and
4123                p_attribute_category is null))
4124         and ((state_rec.attribute1 = p_attribute1)
4125            or (state_rec.attribute1 is null and
4126                p_attribute1 is null))
4127         and ((state_rec.attribute2 = p_attribute2)
4128            or (state_rec.attribute2 is null and
4129                p_attribute2 is null))
4130         and ((state_rec.attribute3 = p_attribute3)
4131            or (state_rec.attribute3 is null and
4132                p_attribute3 is null))
4133         and ((state_rec.attribute4 = p_attribute4)
4134            or (state_rec.attribute4 is null and
4135                p_attribute4 is null))
4136         and ((state_rec.attribute5 = p_attribute5)
4137            or (state_rec.attribute5 is null and
4138                p_attribute5 is null))
4139         and ((state_rec.attribute6 = p_attribute6)
4140            or (state_rec.attribute6 is null and
4141                p_attribute6 is null))
4142         and ((state_rec.attribute7 = p_attribute7)
4143            or (state_rec.attribute7 is null and
4144                p_attribute7 is null))
4145         and ((state_rec.attribute8 = p_attribute8)
4146            or (state_rec.attribute8 is null and
4147                p_attribute8 is null))
4148         and ((state_rec.attribute9 = p_attribute9)
4149            or (state_rec.attribute9 is null and
4150                p_attribute9 is null))
4151         and ((state_rec.attribute10 = p_attribute10)
4152            or (state_rec.attribute10 is null and
4153                p_attribute10 is null))
4154         and ((state_rec.attribute11 = p_attribute11)
4155            or (state_rec.attribute11 is null and
4156                p_attribute11 is null))
4157         and ((state_rec.attribute12 = p_attribute12)
4158            or (state_rec.attribute12 is null and
4159                p_attribute12 is null))
4160         and ((state_rec.attribute13 = p_attribute13)
4161            or (state_rec.attribute13 is null and
4162                p_attribute13 is null))
4163         and ((state_rec.attribute14 = p_attribute14)
4164            or (state_rec.attribute14 is null and
4165                p_attribute14 is null))
4166         and ((state_rec.attribute15 = p_attribute15)
4167            or (state_rec.attribute15 is null and
4168                p_attribute15 is null))
4169         and ((state_rec.attribute16 = p_attribute16)
4170            or (state_rec.attribute16 is null and
4171                p_attribute16 is null))
4172         and ((state_rec.attribute17 = p_attribute17)
4173            or (state_rec.attribute17 is null and
4177                p_attribute18 is null))
4174                p_attribute17 is null))
4175         and ((state_rec.attribute18 = p_attribute18)
4176            or (state_rec.attribute18 is null and
4178         and ((state_rec.attribute19 = p_attribute19)
4179            or (state_rec.attribute19 is null and
4180                p_attribute19 is null))
4181         and ((state_rec.attribute20 = p_attribute20)
4182            or (state_rec.attribute20 is null and
4183                p_attribute20 is null))
4184         and ((state_rec.attribute21 = p_attribute21)
4185            or (state_rec.attribute21 is null and
4186                p_attribute21 is null))
4187         and ((state_rec.attribute22 = p_attribute22)
4188            or (state_rec.attribute22 is null and
4189                p_attribute22 is null))
4190         and ((state_rec.attribute23 = p_attribute23)
4191            or (state_rec.attribute23 is null and
4192                p_attribute23 is null))
4193         and ((state_rec.attribute24 = p_attribute24)
4194            or (state_rec.attribute24 is null and
4195                p_attribute24 is null))
4196         and ((state_rec.attribute25 = p_attribute25)
4197            or (state_rec.attribute25 is null and
4198                p_attribute25 is null))
4199         and ((state_rec.attribute26 = p_attribute26)
4200            or (state_rec.attribute26 is null and
4201                p_attribute26 is null))
4202         and ((state_rec.attribute27 = p_attribute27)
4203            or (state_rec.attribute27 is null and
4204                p_attribute27 is null))
4205         and ((state_rec.attribute28 = p_attribute28)
4206            or (state_rec.attribute28 is null and
4207                p_attribute28 is null))
4208         and ((state_rec.attribute29 = p_attribute29)
4209            or (state_rec.attribute29 is null and
4210                p_attribute29 is null))
4211         and ((state_rec.attribute30 = p_attribute30)
4212            or (state_rec.attribute30 is null and
4213                p_attribute30 is null))
4214         and ((state_rec.sta_information_category = p_sta_information_category)
4215            or (state_rec.sta_information_category is null and
4216                p_sta_information_category is null))
4217         and ((state_rec.sta_information1 = p_sta_information1)
4218            or (state_rec.sta_information1 is null and
4219                p_sta_information1 is null))
4220         and ((state_rec.sta_information2 = p_sta_information2)
4221            or (state_rec.sta_information2 is null and
4222                p_sta_information2 is null))
4223         and ((state_rec.sta_information3 = p_sta_information3)
4224            or (state_rec.sta_information3 is null and
4225                p_sta_information3 is null))
4226         and ((state_rec.sta_information4 = p_sta_information4)
4227            or (state_rec.sta_information4 is null and
4228                p_sta_information4 is null))
4229         and ((state_rec.sta_information5 = p_sta_information5)
4230            or (state_rec.sta_information5 is null and
4231                p_sta_information5 is null))
4232         and ((state_rec.sta_information6 = p_sta_information6)
4233            or (state_rec.sta_information6 is null and
4234                p_sta_information6 is null))
4235         and ((state_rec.sta_information7 = p_sta_information7)
4236            or (state_rec.sta_information7 is null and
4237                p_sta_information7 is null))
4238         and ((state_rec.sta_information8 = p_sta_information8)
4239            or (state_rec.sta_information8 is null and
4240                p_sta_information8 is null))
4241         and ((state_rec.sta_information9 = p_sta_information9)
4242            or (state_rec.sta_information9 is null and
4243                p_sta_information9 is null))
4244         and ((state_rec.sta_information10 = p_sta_information10)
4245            or (state_rec.sta_information10 is null and
4246                p_sta_information10 is null))
4247         and ((state_rec.sta_information11 = p_sta_information11)
4248            or (state_rec.sta_information11 is null and
4249                p_sta_information11 is null))
4250         and ((state_rec.sta_information12 = p_sta_information12)
4251            or (state_rec.sta_information12 is null and
4252                p_sta_information12 is null))
4253         and ((state_rec.sta_information13 = p_sta_information13)
4254            or (state_rec.sta_information13 is null and
4255                p_sta_information13 is null))
4256         and ((state_rec.sta_information14 = p_sta_information14)
4257            or (state_rec.sta_information14 is null and
4258                p_sta_information14 is null))
4259         and ((state_rec.sta_information15 = p_sta_information15)
4260            or (state_rec.sta_information15 is null and
4261                p_sta_information15 is null))
4262         and ((state_rec.sta_information16 = p_sta_information16)
4263            or (state_rec.sta_information16 is null and
4264                p_sta_information16 is null))
4265         and ((state_rec.sta_information17 = p_sta_information17)
4266            or (state_rec.sta_information17 is null and
4267                p_sta_information17 is null))
4268         and ((state_rec.sta_information18 = p_sta_information18)
4269            or (state_rec.sta_information18 is null and
4270                p_sta_information18 is null))
4271         and ((state_rec.sta_information19 = p_sta_information19)
4272            or (state_rec.sta_information19 is null and
4273                p_sta_information19 is null))
4274         and ((state_rec.sta_information20 = p_sta_information20)
4275            or (state_rec.sta_information20 is null and
4279                p_sta_information21 is null))
4276                p_sta_information20 is null))
4277         and ((state_rec.sta_information21 = p_sta_information21)
4278            or (state_rec.sta_information21 is null and
4280         and ((state_rec.sta_information22 = p_sta_information22)
4281            or (state_rec.sta_information22 is null and
4282                p_sta_information22 is null))
4283         and ((state_rec.sta_information23 = p_sta_information23)
4284            or (state_rec.sta_information23 is null and
4285                p_sta_information23 is null))
4286         and ((state_rec.sta_information24 = p_sta_information24)
4287            or (state_rec.sta_information24 is null and
4288                p_sta_information24 is null))
4289         and ((state_rec.sta_information25 = p_sta_information25)
4290            or (state_rec.sta_information25 is null and
4291                p_sta_information25 is null))
4292         and ((state_rec.sta_information26 = p_sta_information26)
4293            or (state_rec.sta_information26 is null and
4294                p_sta_information26 is null))
4295         and ((state_rec.sta_information27 = p_sta_information27)
4296            or (state_rec.sta_information27 is null and
4297                p_sta_information27 is null))
4298         and ((state_rec.sta_information28 = p_sta_information28)
4299            or (state_rec.sta_information28 is null and
4300                p_sta_information28 is null))
4301         and ((state_rec.sta_information29 = p_sta_information29)
4302            or (state_rec.sta_information29 is null and
4303                p_sta_information29 is null))
4304         and ((state_rec.sta_information30 = p_sta_information30)
4305            or (state_rec.sta_information30 is null and
4306                p_sta_information30 is null))
4307      then
4308 
4309       return;
4310 
4311      else
4312 
4313         fnd_message.set_name('PAY', 'FORM_RECORD_CHANGED');
4314         fnd_message.raise_error;
4315 
4316   end if;
4317 
4318   end lock_state_tax_row;
4319 
4320 
4321   /* Name        : lock_county_tax_row
4322      Purpose     : To lock the county tax rule record.
4323   */
4324 
4325   procedure lock_county_tax_row ( p_row_id in varchar2,
4326                                     p_emp_county_tax_rule_id in number,
4327                                     p_effective_start_date in date,
4328                                     p_effective_end_date in date,
4329                                     p_assignment_id in number,
4330                                     p_state_code in varchar2,
4331                                     p_county_code in varchar2,
4332                                     p_business_group_id in number,
4333                                     p_additional_wa_rate in number,
4334                                     p_filing_status_code in varchar2,
4335                                     p_jurisdiction_code in varchar2,
4336                                     p_lit_additional_tax in number,
4337                                     p_lit_override_amount in number,
4338                                     p_lit_override_rate in number,
4339                                     p_withholding_allowances in number,
4340                                     p_lit_exempt in varchar2,
4341                                     p_sd_exempt in varchar2,
4342                                     p_ht_exempt in varchar2,
4343                                     p_wage_exempt in varchar2,
4344                                     p_school_district_code in varchar2,
4345                                     p_attribute_category        in varchar2,
4346                                     p_attribute1                in varchar2,
4347                                     p_attribute2                in varchar2,
4348                                     p_attribute3                in varchar2,
4349                                     p_attribute4                in varchar2,
4350                                     p_attribute5                in varchar2,
4351                                     p_attribute6                in varchar2,
4352                                     p_attribute7                in varchar2,
4353                                     p_attribute8                in varchar2,
4354                                     p_attribute9                in varchar2,
4355                                     p_attribute10               in varchar2,
4356                                     p_attribute11               in varchar2,
4357                                     p_attribute12               in varchar2,
4358                                     p_attribute13               in varchar2,
4359                                     p_attribute14               in varchar2,
4360                                     p_attribute15               in varchar2,
4361                                     p_attribute16               in varchar2,
4362                                     p_attribute17               in varchar2,
4363                                     p_attribute18               in varchar2,
4364                                     p_attribute19               in varchar2,
4365                                     p_attribute20               in varchar2,
4366                                     p_attribute21               in varchar2,
4367                                     p_attribute22               in varchar2,
4368                                     p_attribute23               in varchar2,
4369                                     p_attribute24               in varchar2,
4370                                     p_attribute25               in varchar2,
4371                                     p_attribute26               in varchar2,
4375                                     p_attribute30               in varchar2,
4372                                     p_attribute27               in varchar2,
4373                                     p_attribute28               in varchar2,
4374                                     p_attribute29               in varchar2,
4376                                     p_cnt_information_category  in varchar2,
4377                                     p_cnt_information1          in varchar2,
4378                                     p_cnt_information2          in varchar2,
4379                                     p_cnt_information3          in varchar2,
4380                                     p_cnt_information4          in varchar2,
4381                                     p_cnt_information5          in varchar2,
4382                                     p_cnt_information6          in varchar2,
4383                                     p_cnt_information7          in varchar2,
4384                                     p_cnt_information8          in varchar2,
4385                                     p_cnt_information9          in varchar2,
4386                                     p_cnt_information10         in varchar2,
4387                                     p_cnt_information11         in varchar2,
4388                                     p_cnt_information12         in varchar2,
4389                                     p_cnt_information13         in varchar2,
4390                                     p_cnt_information14         in varchar2,
4391                                     p_cnt_information15         in varchar2,
4392                                     p_cnt_information16         in varchar2,
4393                                     p_cnt_information17         in varchar2,
4394                                     p_cnt_information18         in varchar2,
4395                                     p_cnt_information19         in varchar2,
4396                                     p_cnt_information20         in varchar2,
4397                                     p_cnt_information21         in varchar2,
4398                                     p_cnt_information22         in varchar2,
4399                                     p_cnt_information23         in varchar2,
4400                                     p_cnt_information24         in varchar2,
4401                                     p_cnt_information25         in varchar2,
4402                                     p_cnt_information26         in varchar2,
4403                                     p_cnt_information27         in varchar2,
4404                                     p_cnt_information28         in varchar2,
4405                                     p_cnt_information29         in varchar2,
4406                                     p_cnt_information30         in varchar2  ) is
4407 
4408   cursor csr_asg_rec is
4409   select assignment_id
4410   from   PER_ASSIGNMENTS_F
4411   where  assignment_id = p_assignment_id
4412   and    p_effective_start_date between effective_start_date
4413          and effective_end_date
4414   for update of assignment_id nowait;
4415 
4416 
4417   cursor csr_county_rec is
4418   select *
4419   from   PAY_US_EMP_COUNTY_TAX_RULES_F
4420   where  rowid = chartorowid(p_row_id)
4421   for update of emp_county_tax_rule_id nowait;
4422 
4423   county_rec csr_county_rec%rowtype;
4424   l_assignment_id      number(9);
4425 
4426   begin
4427 
4428      open csr_asg_rec;
4429 
4430      fetch csr_asg_rec into l_assignment_id;
4431 
4432      if csr_asg_rec%NOTFOUND then
4433         close  csr_asg_rec;
4434         fnd_message.set_name('FND', 'FORM_UNABLE_TO_RESERVE_RECORD');
4435         fnd_message.raise_error;
4436      end if;
4437 
4438      close csr_asg_rec;
4439 
4440      open csr_county_rec;
4441 
4442      fetch csr_county_rec into county_rec;
4443 
4444      if csr_county_rec%NOTFOUND then
4445         close  csr_county_rec;
4446         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
4447         fnd_message.set_token('PROCEDURE',
4448         'pay_us_emp_dt_tax_rules.lock_county_tax_row');
4449         fnd_message.set_token('STEP', '1');
4450         fnd_message.raise_error;
4451      end if;
4452 
4453      close  csr_county_rec;
4454 
4455       county_rec.state_code          := rtrim(county_rec.state_code);
4456       county_rec.county_code         := rtrim(county_rec.county_code);
4457       county_rec.filing_status_code  := rtrim(county_rec.filing_status_code);
4458       county_rec.jurisdiction_code   := rtrim(county_rec.jurisdiction_code);
4459       county_rec.lit_exempt          := rtrim(county_rec.lit_exempt);
4460       county_rec.sd_exempt            := rtrim(county_rec.sd_exempt);
4461       county_rec.ht_exempt           := rtrim(county_rec.ht_exempt);
4462       county_rec.wage_exempt         := rtrim(county_rec.wage_exempt);
4463       county_rec.school_district_code := rtrim(county_rec.school_district_code);
4464       county_rec.attribute_category   := rtrim(county_rec.attribute_category);
4465       county_rec.attribute1           := rtrim(county_rec.attribute1);
4466       county_rec.attribute2           := rtrim(county_rec.attribute2);
4467       county_rec.attribute3           := rtrim(county_rec.attribute3);
4468       county_rec.attribute4           := rtrim(county_rec.attribute4);
4469       county_rec.attribute5           := rtrim(county_rec.attribute5);
4470       county_rec.attribute6           := rtrim(county_rec.attribute6);
4471       county_rec.attribute7           := rtrim(county_rec.attribute7);
4472       county_rec.attribute8           := rtrim(county_rec.attribute8);
4476       county_rec.attribute12          := rtrim(county_rec.attribute12);
4473       county_rec.attribute9           := rtrim(county_rec.attribute9);
4474       county_rec.attribute10          := rtrim(county_rec.attribute10);
4475       county_rec.attribute11          := rtrim(county_rec.attribute11);
4477       county_rec.attribute13          := rtrim(county_rec.attribute13);
4478       county_rec.attribute14          := rtrim(county_rec.attribute14);
4479       county_rec.attribute15          := rtrim(county_rec.attribute15);
4480       county_rec.attribute16          := rtrim(county_rec.attribute16);
4481       county_rec.attribute17          := rtrim(county_rec.attribute17);
4482       county_rec.attribute18          := rtrim(county_rec.attribute18);
4483       county_rec.attribute19          := rtrim(county_rec.attribute19);
4484       county_rec.attribute20          := rtrim(county_rec.attribute20);
4485       county_rec.attribute21          := rtrim(county_rec.attribute21);
4486       county_rec.attribute22          := rtrim(county_rec.attribute22);
4487       county_rec.attribute23          := rtrim(county_rec.attribute23);
4488       county_rec.attribute24          := rtrim(county_rec.attribute24);
4489       county_rec.attribute25          := rtrim(county_rec.attribute25);
4490       county_rec.attribute26          := rtrim(county_rec.attribute26);
4491       county_rec.attribute27          := rtrim(county_rec.attribute27);
4492       county_rec.attribute28          := rtrim(county_rec.attribute28);
4493       county_rec.attribute29          := rtrim(county_rec.attribute29);
4494       county_rec.attribute30          := rtrim(county_rec.attribute30);
4495       county_rec.cnt_information_category   := rtrim(county_rec.cnt_information_category);
4496       county_rec.cnt_information1     := rtrim(county_rec.cnt_information1);
4497       county_rec.cnt_information2     := rtrim(county_rec.cnt_information2);
4498       county_rec.cnt_information3     := rtrim(county_rec.cnt_information3);
4499       county_rec.cnt_information4     := rtrim(county_rec.cnt_information4);
4500       county_rec.cnt_information5     := rtrim(county_rec.cnt_information5);
4501       county_rec.cnt_information6     := rtrim(county_rec.cnt_information6);
4502       county_rec.cnt_information7     := rtrim(county_rec.cnt_information7);
4503       county_rec.cnt_information8     := rtrim(county_rec.cnt_information8);
4504       county_rec.cnt_information9     := rtrim(county_rec.cnt_information9);
4505       county_rec.cnt_information10    := rtrim(county_rec.cnt_information10);
4506       county_rec.cnt_information11    := rtrim(county_rec.cnt_information11);
4507       county_rec.cnt_information12    := rtrim(county_rec.cnt_information12);
4508       county_rec.cnt_information13    := rtrim(county_rec.cnt_information13);
4509       county_rec.cnt_information14    := rtrim(county_rec.cnt_information14);
4510       county_rec.cnt_information15    := rtrim(county_rec.cnt_information15);
4511       county_rec.cnt_information16    := rtrim(county_rec.cnt_information16);
4512       county_rec.cnt_information17    := rtrim(county_rec.cnt_information17);
4513       county_rec.cnt_information18    := rtrim(county_rec.cnt_information18);
4514       county_rec.cnt_information19    := rtrim(county_rec.cnt_information19);
4515       county_rec.cnt_information20    := rtrim(county_rec.cnt_information20);
4516       county_rec.cnt_information21    := rtrim(county_rec.cnt_information21);
4517       county_rec.cnt_information22    := rtrim(county_rec.cnt_information22);
4518       county_rec.cnt_information23    := rtrim(county_rec.cnt_information23);
4519       county_rec.cnt_information24    := rtrim(county_rec.cnt_information24);
4520       county_rec.cnt_information25    := rtrim(county_rec.cnt_information25);
4521       county_rec.cnt_information26    := rtrim(county_rec.cnt_information26);
4522       county_rec.cnt_information27    := rtrim(county_rec.cnt_information27);
4523       county_rec.cnt_information28    := rtrim(county_rec.cnt_information28);
4524       county_rec.cnt_information29    := rtrim(county_rec.cnt_information29);
4525       county_rec.cnt_information30    := rtrim(county_rec.cnt_information30);
4526 
4527 
4528         if ((county_rec.emp_county_tax_rule_id = p_emp_county_tax_rule_id)
4529            or (county_rec.emp_county_tax_rule_id is null and
4530                p_emp_county_tax_rule_id is null))
4531         and ((county_rec.effective_start_date = p_effective_start_date)
4532            or (county_rec.effective_start_date is null and
4533                p_effective_start_date is null))
4534         and ((county_rec.effective_end_date = p_effective_end_date)
4535            or (county_rec.effective_end_date is null and
4536                p_effective_end_date is null))
4537         and ((county_rec.assignment_id = p_assignment_id)
4538            or (county_rec.assignment_id is null and
4539                p_assignment_id is null))
4540         and ((county_rec.state_code = p_state_code)
4541            or (county_rec.state_code is null and
4542                p_state_code is null))
4543         and ((county_rec.county_code = p_county_code)
4544            or (county_rec.county_code is null and
4545                p_county_code is null))
4546         and ((county_rec.business_group_id = p_business_group_id)
4547            or (county_rec.business_group_id is null and
4548                p_business_group_id is null))
4549         and ((county_rec.additional_wa_rate = p_additional_wa_rate)
4550            or (county_rec.additional_wa_rate is null and
4551                p_additional_wa_rate is null))
4552         and ((county_rec.filing_status_code = lpad(p_filing_status_code,2,'0'))
4553            or (county_rec.filing_status_code is null and
4554                p_filing_status_code is null))
4558         and ((county_rec.lit_additional_tax = p_lit_additional_tax)
4555         and ((county_rec.jurisdiction_code = p_jurisdiction_code)
4556            or (county_rec.jurisdiction_code is null and
4557                p_jurisdiction_code is null))
4559            or (county_rec.lit_additional_tax is null and
4560                p_lit_additional_tax is null))
4561         and ((county_rec.lit_override_amount = p_lit_override_amount)
4562            or (county_rec.lit_override_amount is null and
4563                p_lit_override_amount is null))
4564         and ((county_rec.lit_override_rate = p_lit_override_rate)
4565            or (county_rec.lit_override_rate is null and
4566                p_lit_override_rate is null))
4567         and ((county_rec.withholding_allowances = p_withholding_allowances)
4568            or (county_rec.withholding_allowances is null and
4569                p_withholding_allowances is null))
4570         and ((county_rec.lit_exempt = p_lit_exempt)
4571            or (county_rec.lit_exempt is null and
4572                p_lit_exempt is null))
4573         and ((county_rec.sd_exempt = p_sd_exempt)
4574            or (county_rec.sd_exempt is null and
4575                p_sd_exempt is null))
4576         and ((county_rec.ht_exempt = p_ht_exempt)
4577            or (county_rec.ht_exempt is null and
4578                p_ht_exempt is null))
4579         and ((county_rec.wage_exempt = p_wage_exempt)
4580            or (county_rec.wage_exempt is null and
4581                p_wage_exempt is null))
4582         and ((county_rec.school_district_code = p_school_district_code)
4583            or (county_rec.school_district_code is null and
4584                p_school_district_code is null))
4585         and ((county_rec.attribute_category = p_attribute_category)
4586            or (county_rec.attribute_category is null and
4587                p_attribute_category is null))
4588         and ((county_rec.attribute1 = p_attribute1)
4589            or (county_rec.attribute1 is null and
4590                p_attribute1 is null))
4591         and ((county_rec.attribute2 = p_attribute2)
4592            or (county_rec.attribute2 is null and
4593                p_attribute2 is null))
4594         and ((county_rec.attribute3 = p_attribute3)
4595            or (county_rec.attribute3 is null and
4596                p_attribute3 is null))
4597         and ((county_rec.attribute4 = p_attribute4)
4598            or (county_rec.attribute4 is null and
4599                p_attribute4 is null))
4600         and ((county_rec.attribute5 = p_attribute5)
4601            or (county_rec.attribute5 is null and
4602                p_attribute5 is null))
4603         and ((county_rec.attribute6 = p_attribute6)
4604            or (county_rec.attribute6 is null and
4605                p_attribute6 is null))
4606         and ((county_rec.attribute7 = p_attribute7)
4607            or (county_rec.attribute7 is null and
4608                p_attribute7 is null))
4609         and ((county_rec.attribute8 = p_attribute8)
4610            or (county_rec.attribute8 is null and
4611                p_attribute8 is null))
4612         and ((county_rec.attribute9 = p_attribute9)
4613            or (county_rec.attribute9 is null and
4614                p_attribute9 is null))
4615         and ((county_rec.attribute10 = p_attribute10)
4616            or (county_rec.attribute10 is null and
4617                p_attribute10 is null))
4618         and ((county_rec.attribute11 = p_attribute11)
4619            or (county_rec.attribute11 is null and
4620                p_attribute11 is null))
4621         and ((county_rec.attribute12 = p_attribute12)
4622            or (county_rec.attribute12 is null and
4623                p_attribute12 is null))
4624         and ((county_rec.attribute13 = p_attribute13)
4625            or (county_rec.attribute13 is null and
4626                p_attribute13 is null))
4627         and ((county_rec.attribute14 = p_attribute14)
4628            or (county_rec.attribute14 is null and
4629                p_attribute14 is null))
4630         and ((county_rec.attribute15 = p_attribute15)
4631            or (county_rec.attribute15 is null and
4632                p_attribute15 is null))
4633         and ((county_rec.attribute16 = p_attribute16)
4634            or (county_rec.attribute16 is null and
4635                p_attribute16 is null))
4636         and ((county_rec.attribute17 = p_attribute17)
4637            or (county_rec.attribute17 is null and
4638                p_attribute17 is null))
4639         and ((county_rec.attribute18 = p_attribute18)
4640            or (county_rec.attribute18 is null and
4641                p_attribute18 is null))
4642         and ((county_rec.attribute19 = p_attribute19)
4643            or (county_rec.attribute19 is null and
4644                p_attribute19 is null))
4645         and ((county_rec.attribute20 = p_attribute20)
4646            or (county_rec.attribute20 is null and
4647                p_attribute20 is null))
4648         and ((county_rec.attribute21 = p_attribute21)
4649            or (county_rec.attribute21 is null and
4650                p_attribute21 is null))
4651         and ((county_rec.attribute22 = p_attribute22)
4652            or (county_rec.attribute22 is null and
4653                p_attribute22 is null))
4654         and ((county_rec.attribute23 = p_attribute23)
4655            or (county_rec.attribute23 is null and
4656                p_attribute23 is null))
4657         and ((county_rec.attribute24 = p_attribute24)
4658            or (county_rec.attribute24 is null and
4659                p_attribute24 is null))
4663         and ((county_rec.attribute26 = p_attribute26)
4660         and ((county_rec.attribute25 = p_attribute25)
4661            or (county_rec.attribute25 is null and
4662                p_attribute25 is null))
4664            or (county_rec.attribute26 is null and
4665                p_attribute26 is null))
4666         and ((county_rec.attribute27 = p_attribute27)
4667            or (county_rec.attribute27 is null and
4668                p_attribute27 is null))
4669         and ((county_rec.attribute28 = p_attribute28)
4670            or (county_rec.attribute28 is null and
4671                p_attribute28 is null))
4672         and ((county_rec.attribute29 = p_attribute29)
4673            or (county_rec.attribute29 is null and
4674                p_attribute29 is null))
4675         and ((county_rec.attribute30 = p_attribute30)
4676            or (county_rec.attribute30 is null and
4677                p_attribute30 is null))
4678         and ((county_rec.cnt_information_category = p_cnt_information_category)
4679            or (county_rec.cnt_information_category is null and
4680                p_cnt_information_category is null))
4681         and ((county_rec.cnt_information1 = p_cnt_information1)
4682            or (county_rec.cnt_information1 is null and
4683                p_cnt_information1 is null))
4684         and ((county_rec.cnt_information2 = p_cnt_information2)
4685            or (county_rec.cnt_information2 is null and
4686                p_cnt_information2 is null))
4687         and ((county_rec.cnt_information3 = p_cnt_information3)
4688            or (county_rec.cnt_information3 is null and
4689                p_cnt_information3 is null))
4690         and ((county_rec.cnt_information4 = p_cnt_information4)
4691            or (county_rec.cnt_information4 is null and
4692                p_cnt_information4 is null))
4693         and ((county_rec.cnt_information5 = p_cnt_information5)
4694            or (county_rec.cnt_information5 is null and
4695                p_cnt_information5 is null))
4696         and ((county_rec.cnt_information6 = p_cnt_information6)
4697            or (county_rec.cnt_information6 is null and
4698                p_cnt_information6 is null))
4699         and ((county_rec.cnt_information7 = p_cnt_information7)
4700            or (county_rec.cnt_information7 is null and
4701                p_cnt_information7 is null))
4702         and ((county_rec.cnt_information8 = p_cnt_information8)
4703            or (county_rec.cnt_information8 is null and
4704                p_cnt_information8 is null))
4705         and ((county_rec.cnt_information9 = p_cnt_information9)
4706            or (county_rec.cnt_information9 is null and
4707                p_cnt_information9 is null))
4708         and ((county_rec.cnt_information10 = p_cnt_information10)
4709            or (county_rec.cnt_information10 is null and
4710                p_cnt_information10 is null))
4711         and ((county_rec.cnt_information11 = p_cnt_information11)
4712            or (county_rec.cnt_information11 is null and
4713                p_cnt_information11 is null))
4714         and ((county_rec.cnt_information12 = p_cnt_information12)
4715            or (county_rec.cnt_information12 is null and
4716                p_cnt_information12 is null))
4717         and ((county_rec.cnt_information13 = p_cnt_information13)
4718            or (county_rec.cnt_information13 is null and
4719                p_cnt_information13 is null))
4720         and ((county_rec.cnt_information14 = p_cnt_information14)
4721            or (county_rec.cnt_information14 is null and
4722                p_cnt_information14 is null))
4723         and ((county_rec.cnt_information15 = p_cnt_information15)
4724            or (county_rec.cnt_information15 is null and
4725                p_cnt_information15 is null))
4726         and ((county_rec.cnt_information16 = p_cnt_information16)
4727            or (county_rec.cnt_information16 is null and
4728                p_cnt_information16 is null))
4729         and ((county_rec.cnt_information17 = p_cnt_information17)
4730            or (county_rec.cnt_information17 is null and
4731                p_cnt_information17 is null))
4732         and ((county_rec.cnt_information18 = p_cnt_information18)
4733            or (county_rec.cnt_information18 is null and
4734                p_cnt_information18 is null))
4735         and ((county_rec.cnt_information19 = p_cnt_information19)
4736            or (county_rec.cnt_information19 is null and
4737                p_cnt_information19 is null))
4738         and ((county_rec.cnt_information20 = p_cnt_information20)
4739            or (county_rec.cnt_information20 is null and
4740                p_cnt_information20 is null))
4741         and ((county_rec.cnt_information21 = p_cnt_information21)
4742            or (county_rec.cnt_information21 is null and
4743                p_cnt_information21 is null))
4744         and ((county_rec.cnt_information22 = p_cnt_information22)
4745            or (county_rec.cnt_information22 is null and
4746                p_cnt_information22 is null))
4747         and ((county_rec.cnt_information23 = p_cnt_information23)
4748            or (county_rec.cnt_information23 is null and
4749                p_cnt_information23 is null))
4750         and ((county_rec.cnt_information24 = p_cnt_information24)
4751            or (county_rec.cnt_information24 is null and
4752                p_cnt_information24 is null))
4753         and ((county_rec.cnt_information25 = p_cnt_information25)
4754            or (county_rec.cnt_information25 is null and
4755                p_cnt_information25 is null))
4756         and ((county_rec.cnt_information26 = p_cnt_information26)
4757            or (county_rec.cnt_information26 is null and
4761                p_cnt_information27 is null))
4758                p_cnt_information26 is null))
4759         and ((county_rec.cnt_information27 = p_cnt_information27)
4760            or (county_rec.cnt_information27 is null and
4762         and ((county_rec.cnt_information28 = p_cnt_information28)
4763            or (county_rec.cnt_information28 is null and
4764                p_cnt_information28 is null))
4765         and ((county_rec.cnt_information29 = p_cnt_information29)
4766            or (county_rec.cnt_information29 is null and
4767                p_cnt_information29 is null))
4768         and ((county_rec.cnt_information30 = p_cnt_information30)
4769            or (county_rec.cnt_information30 is null and
4770                p_cnt_information30 is null))
4771      then
4772 
4773       return;
4774 
4775      else
4776 
4777         fnd_message.set_name('PAY', 'FORM_RECORD_CHANGED');
4778         fnd_message.raise_error;
4779 
4780      end if;
4781 
4782   end lock_county_tax_row;
4783 
4784 
4785   /* Name        : lock_city_tax_row
4786      Purpose     : To lock the city tax rule record.
4787   */
4788 
4789   procedure lock_city_tax_row ( p_row_id in varchar2,
4790                                   p_emp_city_tax_rule_id in number,
4791                                   p_effective_start_date in date,
4792                                   p_effective_end_date in date,
4793                                   p_assignment_id in number,
4794                                   p_state_code in varchar2,
4795                                   p_county_code in varchar2,
4796                                   p_city_code in varchar2,
4797                                   p_business_group_id in number,
4798                                   p_additional_wa_rate in number,
4799                                   p_filing_status_code in varchar2,
4800                                   p_jurisdiction_code in varchar2,
4801                                   p_lit_additional_tax in number,
4802                                   p_lit_override_amount in number,
4803                                   p_lit_override_rate in number,
4804                                   p_withholding_allowances in number,
4805                                   p_lit_exempt in varchar2,
4806                                   p_sd_exempt in varchar2,
4807                                   p_ht_exempt in varchar2,
4808                                   p_wage_exempt in varchar2,
4809                                   p_school_district_code in varchar2,
4810                                   p_attribute_category        in varchar2,
4811                                   p_attribute1                in varchar2,
4812                                   p_attribute2                in varchar2,
4813                                   p_attribute3                in varchar2,
4814                                   p_attribute4                in varchar2,
4815                                   p_attribute5                in varchar2,
4816                                   p_attribute6                in varchar2,
4817                                   p_attribute7                in varchar2,
4818                                   p_attribute8                in varchar2,
4819                                   p_attribute9                in varchar2,
4820                                   p_attribute10               in varchar2,
4821                                   p_attribute11               in varchar2,
4822                                   p_attribute12               in varchar2,
4823                                   p_attribute13               in varchar2,
4824                                   p_attribute14               in varchar2,
4825                                   p_attribute15               in varchar2,
4826                                   p_attribute16               in varchar2,
4827                                   p_attribute17               in varchar2,
4828                                   p_attribute18               in varchar2,
4829                                   p_attribute19               in varchar2,
4830                                   p_attribute20               in varchar2,
4831                                   p_attribute21               in varchar2,
4832                                   p_attribute22               in varchar2,
4833                                   p_attribute23               in varchar2,
4834                                   p_attribute24               in varchar2,
4835                                   p_attribute25               in varchar2,
4836                                   p_attribute26               in varchar2,
4837                                   p_attribute27               in varchar2,
4838                                   p_attribute28               in varchar2,
4839                                   p_attribute29               in varchar2,
4840                                   p_attribute30               in varchar2,
4841                                   p_cty_information_category  in varchar2,
4842                                   p_cty_information1          in varchar2,
4843                                   p_cty_information2          in varchar2,
4844                                   p_cty_information3          in varchar2,
4845                                   p_cty_information4          in varchar2,
4846                                   p_cty_information5          in varchar2,
4847                                   p_cty_information6          in varchar2,
4848                                   p_cty_information7          in varchar2,
4849                                   p_cty_information8          in varchar2,
4853                                   p_cty_information12         in varchar2,
4850                                   p_cty_information9          in varchar2,
4851                                   p_cty_information10         in varchar2,
4852                                   p_cty_information11         in varchar2,
4854                                   p_cty_information13         in varchar2,
4855                                   p_cty_information14         in varchar2,
4856                                   p_cty_information15         in varchar2,
4857                                   p_cty_information16         in varchar2,
4858                                   p_cty_information17         in varchar2,
4859                                   p_cty_information18         in varchar2,
4860                                   p_cty_information19         in varchar2,
4861                                   p_cty_information20         in varchar2,
4862                                   p_cty_information21         in varchar2,
4863                                   p_cty_information22         in varchar2,
4864                                   p_cty_information23         in varchar2,
4865                                   p_cty_information24         in varchar2,
4866                                   p_cty_information25         in varchar2,
4867                                   p_cty_information26         in varchar2,
4868                                   p_cty_information27         in varchar2,
4869                                   p_cty_information28         in varchar2,
4870                                   p_cty_information29         in varchar2,
4871                                   p_cty_information30         in varchar2  ) is
4872 
4873 
4874   cursor csr_asg_rec is
4875   select assignment_id
4876   from   PER_ASSIGNMENTS_F
4877   where  assignment_id = p_assignment_id
4878   and    p_effective_start_date between effective_start_date
4879          and effective_end_date
4880   for update of assignment_id nowait;
4881 
4882 
4883   cursor csr_city_rec is
4884   select *
4885   from   PAY_US_EMP_CITY_TAX_RULES_F
4886   where  rowid = chartorowid(p_row_id)
4887   for update of emp_city_tax_rule_id nowait;
4888 
4889   city_rec csr_city_rec%rowtype;
4890   l_assignment_id      number(9);
4891 
4892   begin
4893 
4894      open csr_asg_rec;
4895 
4896      fetch csr_asg_rec into l_assignment_id;
4897 
4898      if csr_asg_rec%NOTFOUND then
4899         close  csr_asg_rec;
4900         fnd_message.set_name('FND', 'FORM_UNABLE_TO_RESERVE_RECORD');
4901         fnd_message.raise_error;
4902      end if;
4903 
4904      close csr_asg_rec;
4905 
4906      open csr_city_rec;
4907 
4908      fetch csr_city_rec into city_rec;
4909 
4910      if csr_city_rec%NOTFOUND then
4911         close  csr_city_rec;
4912         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
4913         fnd_message.set_token('PROCEDURE',
4914         'pay_us_emp_dt_tax_rules.lock_city_tax_row');
4915         fnd_message.set_token('STEP', '1');
4916         fnd_message.raise_error;
4917      end if;
4918 
4919      close  csr_city_rec;
4920 
4921       city_rec.state_code           := rtrim(city_rec.state_code);
4922       city_rec.county_code          := rtrim(city_rec.county_code);
4923       city_rec.city_code            := rtrim(city_rec.city_code);
4924       city_rec.filing_status_code   := rtrim(city_rec.filing_status_code);
4925       city_rec.jurisdiction_code    := rtrim(city_rec.jurisdiction_code);
4926       city_rec.lit_exempt           := rtrim(city_rec.lit_exempt);
4927       city_rec.sd_exempt            := rtrim(city_rec.sd_exempt);
4928       city_rec.ht_exempt            := rtrim(city_rec.ht_exempt);
4929       city_rec.wage_exempt          := rtrim(city_rec.wage_exempt);
4930       city_rec.school_district_code := rtrim(city_rec.school_district_code);
4931       city_rec.attribute_category   := rtrim(city_rec.attribute_category);
4932       city_rec.attribute1           := rtrim(city_rec.attribute1);
4933       city_rec.attribute2           := rtrim(city_rec.attribute2);
4934       city_rec.attribute3           := rtrim(city_rec.attribute3);
4935       city_rec.attribute4           := rtrim(city_rec.attribute4);
4936       city_rec.attribute5           := rtrim(city_rec.attribute5);
4937       city_rec.attribute6           := rtrim(city_rec.attribute6);
4938       city_rec.attribute7           := rtrim(city_rec.attribute7);
4939       city_rec.attribute8           := rtrim(city_rec.attribute8);
4940       city_rec.attribute9           := rtrim(city_rec.attribute9);
4941       city_rec.attribute10          := rtrim(city_rec.attribute10);
4942       city_rec.attribute11          := rtrim(city_rec.attribute11);
4943       city_rec.attribute12          := rtrim(city_rec.attribute12);
4944       city_rec.attribute13          := rtrim(city_rec.attribute13);
4945       city_rec.attribute14          := rtrim(city_rec.attribute14);
4946       city_rec.attribute15          := rtrim(city_rec.attribute15);
4947       city_rec.attribute16          := rtrim(city_rec.attribute16);
4948       city_rec.attribute17          := rtrim(city_rec.attribute17);
4949       city_rec.attribute18          := rtrim(city_rec.attribute18);
4950       city_rec.attribute19          := rtrim(city_rec.attribute19);
4951       city_rec.attribute20          := rtrim(city_rec.attribute20);
4952       city_rec.attribute21          := rtrim(city_rec.attribute21);
4953       city_rec.attribute22          := rtrim(city_rec.attribute22);
4954       city_rec.attribute23          := rtrim(city_rec.attribute23);
4955       city_rec.attribute24          := rtrim(city_rec.attribute24);
4959       city_rec.attribute28          := rtrim(city_rec.attribute28);
4956       city_rec.attribute25          := rtrim(city_rec.attribute25);
4957       city_rec.attribute26          := rtrim(city_rec.attribute26);
4958       city_rec.attribute27          := rtrim(city_rec.attribute27);
4960       city_rec.attribute29          := rtrim(city_rec.attribute29);
4961       city_rec.attribute30          := rtrim(city_rec.attribute30);
4962       city_rec.cty_information_category   := rtrim(city_rec.cty_information_category);
4963       city_rec.cty_information1     := rtrim(city_rec.cty_information1);
4964       city_rec.cty_information2     := rtrim(city_rec.cty_information2);
4965       city_rec.cty_information3     := rtrim(city_rec.cty_information3);
4966       city_rec.cty_information4     := rtrim(city_rec.cty_information4);
4967       city_rec.cty_information5     := rtrim(city_rec.cty_information5);
4968       city_rec.cty_information6     := rtrim(city_rec.cty_information6);
4969       city_rec.cty_information7     := rtrim(city_rec.cty_information7);
4970       city_rec.cty_information8     := rtrim(city_rec.cty_information8);
4971       city_rec.cty_information9     := rtrim(city_rec.cty_information9);
4972       city_rec.cty_information10    := rtrim(city_rec.cty_information10);
4973       city_rec.cty_information11    := rtrim(city_rec.cty_information11);
4974       city_rec.cty_information12    := rtrim(city_rec.cty_information12);
4975       city_rec.cty_information13    := rtrim(city_rec.cty_information13);
4976       city_rec.cty_information14    := rtrim(city_rec.cty_information14);
4977       city_rec.cty_information15    := rtrim(city_rec.cty_information15);
4978       city_rec.cty_information16    := rtrim(city_rec.cty_information16);
4979       city_rec.cty_information17    := rtrim(city_rec.cty_information17);
4980       city_rec.cty_information18    := rtrim(city_rec.cty_information18);
4981       city_rec.cty_information19    := rtrim(city_rec.cty_information19);
4982       city_rec.cty_information20    := rtrim(city_rec.cty_information20);
4983       city_rec.cty_information21    := rtrim(city_rec.cty_information21);
4984       city_rec.cty_information22    := rtrim(city_rec.cty_information22);
4985       city_rec.cty_information23    := rtrim(city_rec.cty_information23);
4986       city_rec.cty_information24    := rtrim(city_rec.cty_information24);
4987       city_rec.cty_information25    := rtrim(city_rec.cty_information25);
4988       city_rec.cty_information26    := rtrim(city_rec.cty_information26);
4989       city_rec.cty_information27    := rtrim(city_rec.cty_information27);
4990       city_rec.cty_information28    := rtrim(city_rec.cty_information28);
4991       city_rec.cty_information29    := rtrim(city_rec.cty_information29);
4992       city_rec.cty_information30    := rtrim(city_rec.cty_information30);
4993 
4994         if ((city_rec.emp_city_tax_rule_id = p_emp_city_tax_rule_id)
4995            or (city_rec.emp_city_tax_rule_id is null and
4996                p_emp_city_tax_rule_id is null))
4997         and ((city_rec.effective_start_date = p_effective_start_date)
4998            or (city_rec.effective_start_date is null and
4999                p_effective_start_date is null))
5000         and ((city_rec.effective_end_date = p_effective_end_date)
5001            or (city_rec.effective_end_date is null and
5002                p_effective_end_date is null))
5003         and ((city_rec.assignment_id = p_assignment_id)
5004            or (city_rec.assignment_id is null and
5005                p_assignment_id is null))
5006         and ((city_rec.state_code = p_state_code)
5007            or (city_rec.state_code is null and
5008                p_state_code is null))
5009         and ((city_rec.county_code = p_county_code)
5010            or (city_rec.county_code is null and
5011                p_county_code is null))
5012         and ((city_rec.city_code = p_city_code)
5013            or (city_rec.city_code is null and
5014                p_city_code is null))
5015         and ((city_rec.business_group_id = p_business_group_id)
5016            or (city_rec.business_group_id is null and
5017                p_business_group_id is null))
5018         and ((city_rec.additional_wa_rate = p_additional_wa_rate)
5019            or (city_rec.additional_wa_rate is null and
5020                p_additional_wa_rate is null))
5021         and ((city_rec.filing_status_code = lpad(p_filing_status_code,2,'0'))
5022            or (city_rec.filing_status_code is null and
5023                p_filing_status_code is null))
5024         and ((city_rec.jurisdiction_code = p_jurisdiction_code)
5025            or (city_rec.jurisdiction_code is null and
5026                p_jurisdiction_code is null))
5027         and ((city_rec.lit_additional_tax = p_lit_additional_tax)
5028            or (city_rec.lit_additional_tax is null and
5029                p_lit_additional_tax is null))
5030         and ((city_rec.lit_override_amount = p_lit_override_amount)
5031            or (city_rec.lit_override_amount is null and
5032                p_lit_override_amount is null))
5033         and ((city_rec.lit_override_rate = p_lit_override_rate)
5034            or (city_rec.lit_override_rate is null and
5035                p_lit_override_rate is null))
5036         and ((city_rec.withholding_allowances = p_withholding_allowances)
5037            or (city_rec.withholding_allowances is null and
5038                p_withholding_allowances is null))
5039         and ((city_rec.lit_exempt = p_lit_exempt)
5040            or (city_rec.lit_exempt is null and
5041                p_lit_exempt is null))
5042         and ((city_rec.sd_exempt = p_sd_exempt)
5043            or (city_rec.sd_exempt is null and
5044                p_sd_exempt is null))
5045         and ((city_rec.ht_exempt = p_ht_exempt)
5046            or (city_rec.ht_exempt is null and
5050                p_wage_exempt is null))
5047                p_ht_exempt is null))
5048         and ((city_rec.wage_exempt = p_wage_exempt)
5049            or (city_rec.wage_exempt is null and
5051         and ((city_rec.school_district_code = p_school_district_code)
5052            or (city_rec.school_district_code is null and
5053                p_school_district_code is null))
5054         and ((city_rec.attribute_category = p_attribute_category)
5055            or (city_rec.attribute_category is null and
5056                p_attribute_category is null))
5057         and ((city_rec.attribute1 = p_attribute1)
5058            or (city_rec.attribute1 is null and
5059                p_attribute1 is null))
5060         and ((city_rec.attribute2 = p_attribute2)
5061            or (city_rec.attribute2 is null and
5062                p_attribute2 is null))
5063         and ((city_rec.attribute3 = p_attribute3)
5064            or (city_rec.attribute3 is null and
5065                p_attribute3 is null))
5066         and ((city_rec.attribute4 = p_attribute4)
5067            or (city_rec.attribute4 is null and
5068                p_attribute4 is null))
5069         and ((city_rec.attribute5 = p_attribute5)
5070            or (city_rec.attribute5 is null and
5071                p_attribute5 is null))
5072         and ((city_rec.attribute6 = p_attribute6)
5073            or (city_rec.attribute6 is null and
5074                p_attribute6 is null))
5075         and ((city_rec.attribute7 = p_attribute7)
5076            or (city_rec.attribute7 is null and
5077                p_attribute7 is null))
5078         and ((city_rec.attribute8 = p_attribute8)
5079            or (city_rec.attribute8 is null and
5080                p_attribute8 is null))
5081         and ((city_rec.attribute9 = p_attribute9)
5082            or (city_rec.attribute9 is null and
5083                p_attribute9 is null))
5084         and ((city_rec.attribute10 = p_attribute10)
5085            or (city_rec.attribute10 is null and
5086                p_attribute10 is null))
5087         and ((city_rec.attribute11 = p_attribute11)
5088            or (city_rec.attribute11 is null and
5089                p_attribute11 is null))
5090         and ((city_rec.attribute12 = p_attribute12)
5091            or (city_rec.attribute12 is null and
5092                p_attribute12 is null))
5093         and ((city_rec.attribute13 = p_attribute13)
5094            or (city_rec.attribute13 is null and
5095                p_attribute13 is null))
5096         and ((city_rec.attribute14 = p_attribute14)
5097            or (city_rec.attribute14 is null and
5098                p_attribute14 is null))
5099         and ((city_rec.attribute15 = p_attribute15)
5100            or (city_rec.attribute15 is null and
5101                p_attribute15 is null))
5102         and ((city_rec.attribute16 = p_attribute16)
5103            or (city_rec.attribute16 is null and
5104                p_attribute16 is null))
5105         and ((city_rec.attribute17 = p_attribute17)
5106            or (city_rec.attribute17 is null and
5107                p_attribute17 is null))
5108         and ((city_rec.attribute18 = p_attribute18)
5109            or (city_rec.attribute18 is null and
5110                p_attribute18 is null))
5111         and ((city_rec.attribute19 = p_attribute19)
5112            or (city_rec.attribute19 is null and
5113                p_attribute19 is null))
5114         and ((city_rec.attribute20 = p_attribute20)
5115            or (city_rec.attribute20 is null and
5116                p_attribute20 is null))
5117         and ((city_rec.attribute21 = p_attribute21)
5118            or (city_rec.attribute21 is null and
5119                p_attribute21 is null))
5120         and ((city_rec.attribute22 = p_attribute22)
5121            or (city_rec.attribute22 is null and
5122                p_attribute22 is null))
5123         and ((city_rec.attribute23 = p_attribute23)
5124            or (city_rec.attribute23 is null and
5125                p_attribute23 is null))
5126         and ((city_rec.attribute24 = p_attribute24)
5127            or (city_rec.attribute24 is null and
5128                p_attribute24 is null))
5129         and ((city_rec.attribute25 = p_attribute25)
5130            or (city_rec.attribute25 is null and
5131                p_attribute25 is null))
5132         and ((city_rec.attribute26 = p_attribute26)
5133            or (city_rec.attribute26 is null and
5134                p_attribute26 is null))
5135         and ((city_rec.attribute27 = p_attribute27)
5136            or (city_rec.attribute27 is null and
5137                p_attribute27 is null))
5138         and ((city_rec.attribute28 = p_attribute28)
5139            or (city_rec.attribute28 is null and
5140                p_attribute28 is null))
5141         and ((city_rec.attribute29 = p_attribute29)
5142            or (city_rec.attribute29 is null and
5143                p_attribute29 is null))
5144         and ((city_rec.attribute30 = p_attribute30)
5145            or (city_rec.attribute30 is null and
5146                p_attribute30 is null))
5147         and ((city_rec.cty_information_category = p_cty_information_category)
5148            or (city_rec.cty_information_category is null and
5149                p_cty_information_category is null))
5150         and ((city_rec.cty_information1 = p_cty_information1)
5151            or (city_rec.cty_information1 is null and
5152                p_cty_information1 is null))
5153         and ((city_rec.cty_information2 = p_cty_information2)
5154            or (city_rec.cty_information2 is null and
5155                p_cty_information2 is null))
5156         and ((city_rec.cty_information3 = p_cty_information3)
5160            or (city_rec.cty_information4 is null and
5157            or (city_rec.cty_information3 is null and
5158                p_cty_information3 is null))
5159         and ((city_rec.cty_information4 = p_cty_information4)
5161                p_cty_information4 is null))
5162         and ((city_rec.cty_information5 = p_cty_information5)
5163            or (city_rec.cty_information5 is null and
5164                p_cty_information5 is null))
5165         and ((city_rec.cty_information6 = p_cty_information6)
5166            or (city_rec.cty_information6 is null and
5167                p_cty_information6 is null))
5168         and ((city_rec.cty_information7 = p_cty_information7)
5169            or (city_rec.cty_information7 is null and
5170                p_cty_information7 is null))
5171         and ((city_rec.cty_information8 = p_cty_information8)
5172            or (city_rec.cty_information8 is null and
5173                p_cty_information8 is null))
5174         and ((city_rec.cty_information9 = p_cty_information9)
5175            or (city_rec.cty_information9 is null and
5176                p_cty_information9 is null))
5177         and ((city_rec.cty_information10 = p_cty_information10)
5178            or (city_rec.cty_information10 is null and
5179                p_cty_information10 is null))
5180         and ((city_rec.cty_information11 = p_cty_information11)
5181            or (city_rec.cty_information11 is null and
5182                p_cty_information11 is null))
5183         and ((city_rec.cty_information12 = p_cty_information12)
5184            or (city_rec.cty_information12 is null and
5185                p_cty_information12 is null))
5186         and ((city_rec.cty_information13 = p_cty_information13)
5187            or (city_rec.cty_information13 is null and
5188                p_cty_information13 is null))
5189         and ((city_rec.cty_information14 = p_cty_information14)
5190            or (city_rec.cty_information14 is null and
5191                p_cty_information14 is null))
5192         and ((city_rec.cty_information15 = p_cty_information15)
5193            or (city_rec.cty_information15 is null and
5194                p_cty_information15 is null))
5195         and ((city_rec.cty_information16 = p_cty_information16)
5196            or (city_rec.cty_information16 is null and
5197                p_cty_information16 is null))
5198         and ((city_rec.cty_information17 = p_cty_information17)
5199            or (city_rec.cty_information17 is null and
5200                p_cty_information17 is null))
5201         and ((city_rec.cty_information18 = p_cty_information18)
5202            or (city_rec.cty_information18 is null and
5203                p_cty_information18 is null))
5204         and ((city_rec.cty_information19 = p_cty_information19)
5205            or (city_rec.cty_information19 is null and
5206                p_cty_information19 is null))
5207         and ((city_rec.cty_information20 = p_cty_information20)
5208            or (city_rec.cty_information20 is null and
5209                p_cty_information20 is null))
5210         and ((city_rec.cty_information21 = p_cty_information21)
5211            or (city_rec.cty_information21 is null and
5212                p_cty_information21 is null))
5213         and ((city_rec.cty_information22 = p_cty_information22)
5214            or (city_rec.cty_information22 is null and
5215                p_cty_information22 is null))
5216         and ((city_rec.cty_information23 = p_cty_information23)
5217            or (city_rec.cty_information23 is null and
5218                p_cty_information23 is null))
5219         and ((city_rec.cty_information24 = p_cty_information24)
5220            or (city_rec.cty_information24 is null and
5221                p_cty_information24 is null))
5222         and ((city_rec.cty_information25 = p_cty_information25)
5223            or (city_rec.cty_information25 is null and
5224                p_cty_information25 is null))
5225         and ((city_rec.cty_information26 = p_cty_information26)
5226            or (city_rec.cty_information26 is null and
5227                p_cty_information26 is null))
5228         and ((city_rec.cty_information27 = p_cty_information27)
5229            or (city_rec.cty_information27 is null and
5230                p_cty_information27 is null))
5231         and ((city_rec.cty_information28 = p_cty_information28)
5232            or (city_rec.cty_information28 is null and
5233                p_cty_information28 is null))
5234         and ((city_rec.cty_information29 = p_cty_information29)
5235            or (city_rec.cty_information29 is null and
5236                p_cty_information29 is null))
5237         and ((city_rec.cty_information30 = p_cty_information30)
5238            or (city_rec.cty_information30 is null and
5239                p_cty_information30 is null))
5240      then
5241 
5242       return;
5243 
5244      else
5245 
5246         fnd_message.set_name('PAY', 'FORM_RECORD_CHANGED');
5247         fnd_message.raise_error;
5248 
5249   end if;
5250 
5251   end lock_city_tax_row;
5252 
5253 
5254 function insert_def_fed_rec(p_assignment_id         number,
5255                             p_effective_start_date  date,
5256                             p_effective_end_date    date,
5257                             p_sui_state_code        varchar2,
5258                             p_business_group_id     number)
5259 return number is
5260 
5261 l_filing_status_code     varchar2(2);
5262 l_eic_fstatus_code       varchar2(2);
5263 l_emp_fed_tax_rule_id   number;
5264 l_mode                  varchar2(30);
5265 
5269        from   HR_LOOKUPS
5266 /* Get the Filing Status */
5267 /*cursor csr_filing_status is
5268        select lookup_code
5270        where  lookup_type    = 'US_FIT_FILING_STATUS'
5271        and    upper(meaning) = 'SINGLE';
5272        */
5273 
5274 cursor csr_filing_status is
5275        select lookup_code
5276        from   FND_LOOKUP_VALUES
5277        where  lookup_type    = 'US_FIT_FILING_STATUS'
5278        and    upper(meaning) = 'SINGLE'
5279        and    language = 'US';
5280 
5281 /* Get EIC Filing Status */
5282 /*CURSOR csr_eic_fstatus is
5283        select lookup_code
5284        from   hr_lookups
5285        where  lookup_type    = 'US_EIC_FILING_STATUS'
5286        and    upper(meaning) = 'NO EIC';
5287        */
5288 
5289 CURSOR csr_eic_fstatus is
5290        select lookup_code
5291        from   fnd_lookup_values
5292        where  lookup_type    = 'US_EIC_FILING_STATUS'
5293        and    upper(meaning) = 'NO EIC'
5294        and    language = 'US';
5295 
5296 begin
5297 
5298       /* Get Filing Status */
5299       hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_fed_rec',1);
5300      --dbms_output.put_line('asg** '||to_char(p_assignment_id));
5301      --dbms_output.put_line('sd** '||to_char(p_effective_start_date));
5302      --dbms_output.put_line('ed** '||to_char(p_effective_end_date));
5303      --dbms_output.put_line('sui** '||p_sui_state_code);
5304      --dbms_output.put_line('bg** ' || to_char(p_business_group_id));
5305       hr_utility.trace('insert_def_fed_rec** ' || to_char(p_assignment_id));
5306       hr_utility.trace('insert_def_fed_rec** ' || to_char(p_effective_start_date));
5307       hr_utility.trace('insert_def_fed_rec** ' || to_char(p_effective_end_date));
5308       hr_utility.trace('insert_def_fed_rec** ' || p_sui_state_code);
5309       hr_utility.trace('insert_def_fed_rec** ' || to_char(p_business_group_id));
5310 
5311       open  csr_filing_status;
5312 
5313       fetch csr_filing_status into l_filing_status_code;
5314 
5315       if csr_filing_status%NOTFOUND then
5316          fnd_message.set_name('PAY','HR_6091_DEF_MISSING_LOOKUPS');
5317          fnd_message.set_token('LOOKUP_TYPE ','US_FIT_FILING_STATUS');
5318          fnd_message.raise_error;
5319       end if;
5320 
5321       close csr_filing_status;
5322 
5323       /* Get EIC Filing Status */
5324       hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_fed_rec',2);
5325 
5326       open  csr_eic_fstatus;
5327 
5328       fetch csr_eic_fstatus into l_eic_fstatus_code;
5329 
5330       if csr_eic_fstatus%NOTFOUND then
5331 
5332          fnd_message.set_name('PAY','HR_6091_DEF_MISSING_LOOKUPS');
5333          fnd_message.set_token('LOOKUP_TYPE ','US_EIC_FILING_STATUS');
5334          fnd_message.raise_error;
5335 
5336       end if;
5337 
5338       close csr_eic_fstatus;
5339 
5340       /* Insert Federal Tax Record */
5341 
5342      hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_fed_rec',3);
5343 
5344      l_mode := 'INSERT';
5345 
5346      insert_fed_tax_row(p_emp_fed_tax_rule_id  => l_emp_fed_tax_rule_id,
5347                      p_effective_start_date  => p_effective_start_date,
5348                      p_effective_end_date    => p_effective_end_date,
5349                      p_assignment_id         => p_assignment_id,
5350                      p_sui_state_code        => p_sui_state_code,
5351                      p_sui_jurisdiction_code => p_sui_state_code || '-000-0000',
5352                      p_business_group_id     => p_business_group_id,
5353                      p_additional_wa_amount  => 0,
5354                      p_filing_status_code    => lpad(l_filing_status_code,2,'0'),
5355                      p_fit_override_amount   => 0,
5356                      p_fit_override_rate     => 0,
5357                      p_withholding_allowances => 0,
5358                      p_cumulative_taxation   => 'N',
5359                      p_eic_filing_status_code => l_eic_fstatus_code,
5360                      p_fit_additional_tax    => 0,
5361                      p_fit_exempt            => 'N',
5362                      p_futa_tax_exempt       => 'N',
5363                      p_medicare_tax_exempt   => 'N',
5364                      p_ss_tax_exempt         => 'N',
5365                      p_wage_exempt           => 'N',
5366                      p_statutory_employee    => 'N',
5367                      p_w2_filed_year         => null,
5368                      p_supp_tax_override_rate => 0,
5369                      p_excessive_wa_reject_date => null,
5370                      p_attribute_category        => null,
5371                      p_attribute1                => null,
5372                      p_attribute2                => null,
5373                      p_attribute3                => null,
5374                      p_attribute4                => null,
5375                      p_attribute5                => null,
5376                      p_attribute6                => null,
5377                      p_attribute7                => null,
5378                      p_attribute8                => null,
5379                      p_attribute9                => null,
5380                      p_attribute10               => null,
5381                      p_attribute11               => null,
5382                      p_attribute12               => null,
5383                      p_attribute13               => null,
5384                      p_attribute14               => null,
5385                      p_attribute15               => null,
5389                      p_attribute19               => null,
5386                      p_attribute16               => null,
5387                      p_attribute17               => null,
5388                      p_attribute18               => null,
5390                      p_attribute20               => null,
5391                      p_attribute21               => null,
5392                      p_attribute22               => null,
5393                      p_attribute23               => null,
5394                      p_attribute24               => null,
5395                      p_attribute25               => null,
5396                      p_attribute26               => null,
5397                      p_attribute27               => null,
5398                      p_attribute28               => null,
5399                      p_attribute29               => null,
5400                      p_attribute30               => null,
5401                      p_fed_information_category  => null,
5402                      p_fed_information1          => null,
5403                      p_fed_information2          => null,
5404                      p_fed_information3          => null,
5405                      p_fed_information4          => null,
5406                      p_fed_information5          => null,
5407                      p_fed_information6          => null,
5408                      p_fed_information7          => null,
5409                      p_fed_information8          => null,
5410                      p_fed_information9          => null,
5411                      p_fed_information10         => null,
5412                      p_fed_information11         => null,
5413                      p_fed_information12         => null,
5414                      p_fed_information13         => null,
5415                      p_fed_information14         => null,
5416                      p_fed_information15         => null,
5417                      p_fed_information16         => null,
5418                      p_fed_information17         => null,
5419                      p_fed_information18         => null,
5420                      p_fed_information19         => null,
5421                      p_fed_information20         => null,
5422                      p_fed_information21         => null,
5423                      p_fed_information22         => null,
5424                      p_fed_information23         => null,
5425                      p_fed_information24         => null,
5426                      p_fed_information25         => null,
5427                      p_fed_information26         => null,
5428                      p_fed_information27         => null,
5429                      p_fed_information28         => null,
5430                      p_fed_information29         => null,
5431                      p_fed_information30         => null,
5432                      p_mode                   => 'INSERT');
5433 
5434 hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_fed_rec',5);
5435 
5436 return l_emp_fed_tax_rule_id;
5437 
5438 end  insert_def_fed_rec;
5439 
5440 
5441 /*  Insert state record   */
5442 
5443 
5444 function insert_def_state_rec(p_assignment_id        number,
5445                               p_effective_start_date date,
5446                               p_effective_end_date   date,
5447                               p_state_code           varchar2,
5448                               p_business_group_id    number,
5449                               p_percent_time         number)
5450 return number is
5451 
5452 l_emp_state_tax_rule_id       number;
5453 l_filing_status_code          varchar2(30);
5454 l_def_pref                    varchar2(30);
5455 ln_asg_tax_unit_id            number;
5456 l_allowances                  number;
5457 l_row_id                      varchar2(30);
5458 
5459 /* This cursor gets the filing status and exemptions from the federal record
5460    if needed */
5461 
5462 /*
5463 cursor csr_filing_status(p_assignment number, p_state varchar2) is
5464        select hrl.lookup_code, peft.withholding_allowances
5465        from   HR_LOOKUPS hrl
5466        ,      PAY_US_EMP_FED_TAX_RULES_V peft
5467        where  hrl.lookup_type    = 'US_FS_'||p_state
5468        and    upper(hrl.meaning) = decode(
5469               upper(substr(peft.filing_status,1,7)),
5470                            'MARRIED',
5471                            'MARRIED',
5472                            upper(peft.filing_status))
5473        and    peft.assignment_id = p_assignment ;
5474 */
5475 cursor csr_filing_status(p_assignment number, p_state varchar2) is
5476        select flv.lookup_code, peft.withholding_allowances
5477        from   FND_LOOKUP_VALUES flv
5478        ,      PAY_US_EMP_FED_TAX_RULES_V peft
5479        where  flv.lookup_type    = 'US_FS_'||p_state
5480        and    upper(flv.meaning) = decode(
5481               upper(substr(peft.filing_status,1,7)),
5482                            'MARRIED',
5483                            'MARRIED',
5484                            upper(peft.filing_status))
5485        and    peft.assignment_id = p_assignment
5486        and    language = 'US' ;
5487 
5488 
5489 cursor csr_get_asg_gre (p_assignment number)is
5490        select hsck.segment1
5491         from hr_soft_coding_keyflex hsck,
5492              per_assignments_f paf
5493        where paf.assignment_id = p_assignment
5494          and p_effective_start_date between paf.effective_start_date
5495                                         and paf.effective_end_date
5496          and paf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id;
5497 
5501               hr_organization_information hoi
5498 cursor csr_fed_or_def (p_tax_unit_id in number, p_state varchar2)is
5499        select hoi.org_information12
5500          from pay_us_states pus,
5502        where hoi.organization_id = p_tax_unit_id
5503          and hoi.org_information_context = 'State Tax Rules'
5504          and pus.state_code = p_state
5505          and hoi.org_information1 = pus.state_abbrev;
5506 
5507 
5508 cursor chk_state_exists is
5509 select 'Y'
5510 from dual
5511 where exists (select null
5512               from pay_us_emp_state_tax_rules_f pst
5513               where pst.assignment_id = p_assignment_id
5514               and   state_code = p_state_code
5515               and business_group_id + 0 = p_business_group_id);
5516 
5517 l_flag varchar2(1) := 'N';
5518 
5519 begin
5520 
5521   hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',1);
5522 
5523   open chk_state_exists;
5524   fetch chk_state_exists into l_flag;
5525   if chk_state_exists%NOTFOUND then
5526      l_flag := 'N';
5527   end if;
5528   close chk_state_exists;
5529 
5530   hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',91);
5531   if l_flag = 'N'then
5532      open csr_get_asg_gre(p_assignment_id);
5533      fetch csr_get_asg_gre into ln_asg_tax_unit_id;
5534      close csr_get_asg_gre;
5535 
5536      open csr_fed_or_def(ln_asg_tax_unit_id, p_state_code);
5537      fetch csr_fed_or_def into l_def_pref;
5538 
5539      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',2);
5540 
5541      if csr_fed_or_def%NOTFOUND then
5542         l_filing_status_code := '01';
5543         l_allowances := 0;
5544      end if;
5545      close csr_fed_or_def;
5546 
5547      hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',3);
5548 
5549 
5550      /* Bug 864068 - Added check for Connecticut (p_state_code = 07) to default
5551         the filing status for new Connecticut State Tax records to '07' instead
5552         of '01'; while '01' is single for most states and withholds state tax at
5553         the highest rate, '01' for Connecticut is married, with combined income
5554         less than $100,500 which isn't the highest tax rate. '07' is a new
5555         Vertex code for 'No Tax Form on File' which ensures withholding at
5556         the highest rate.
5557       */
5558 
5559      if p_state_code = '07' then
5560         hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',4);
5561         l_filing_status_code := '07';
5562         l_allowances         := 0;
5563     elsif p_state_code = '22' then   -- Bug No 4325326
5564         hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',4.4);
5565         l_filing_status_code := '04';
5566         l_allowances         := 0;
5567      elsif l_def_pref = 'SINGLE_ZERO' or l_def_pref is null then
5568         hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',5);
5569         l_filing_status_code := '01';
5570         l_allowances         := 0;
5571      elsif l_def_pref = 'FED_DEF' then
5572        hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',6);
5573        open  csr_filing_status(p_assignment_id, p_state_code);
5574        fetch csr_filing_status into l_filing_status_code, l_allowances;
5575        if csr_filing_status%NOTFOUND then
5576           hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',7);
5577           l_filing_status_code := '01';
5578           l_allowances := 0;
5579        end if;
5580        close csr_filing_status;
5581 
5582      end if;
5583 
5584   /* Insert State Tax record  */
5585 
5586   hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',8);
5587 
5588   insert_state_tax_row ( p_row_id                  => l_row_id,
5589                          p_emp_state_tax_rule_id  => l_emp_state_tax_rule_id,
5590                          p_effective_start_date    => p_effective_start_date,
5591                          p_effective_end_date      => p_effective_end_date,
5592                          p_assignment_id           => p_assignment_id,
5593                          p_state_code              => p_state_code,
5594                          p_jurisdiction_code       => p_state_code ||'-000-0000',
5595                          p_business_group_id       => p_business_group_id,
5596                          p_additional_wa_amount    => 0,
5597                          p_filing_status_code      => lpad(l_filing_status_code,2,'0'),
5598                          p_remainder_percent       => 0,
5599                          p_secondary_wa            => 0,
5600                          p_sit_additional_tax      => 0,
5601                          p_sit_override_amount     => 0,
5602                          p_sit_override_rate       => 0,
5603                          p_withholding_allowances  => l_allowances,
5604                          p_excessive_wa_reject_date => null,
5605                          p_sdi_exempt              => 'N',
5606                          p_sit_exempt              => 'N',
5607                          p_sit_optional_calc_ind   => null,
5608                          p_state_non_resident_cert => 'N',
5609                          p_sui_exempt              => 'N',
5610                          p_wc_exempt               => null,
5611                          p_wage_exempt             => 'N',
5612                          p_sui_wage_base_override_amt => null,
5613                          p_supp_tax_override_rate  => 0,
5614                          p_time_in_state           => nvl(p_percent_time,0),
5618                          p_attribute3                => null,
5615                          p_attribute_category        => null,
5616                          p_attribute1                => null,
5617                          p_attribute2                => null,
5619                          p_attribute4                => null,
5620                          p_attribute5                => null,
5621                          p_attribute6                => null,
5622                          p_attribute7                => null,
5623                          p_attribute8                => null,
5624                          p_attribute9                => null,
5625                          p_attribute10               => null,
5626                          p_attribute11               => null,
5627                          p_attribute12               => null,
5628                          p_attribute13               => null,
5629                          p_attribute14               => null,
5630                          p_attribute15               => null,
5631                          p_attribute16               => null,
5632                          p_attribute17               => null,
5633                          p_attribute18               => null,
5634                          p_attribute19               => null,
5635                          p_attribute20               => null,
5636                          p_attribute21               => null,
5637                          p_attribute22               => null,
5638                          p_attribute23               => null,
5639                          p_attribute24               => null,
5640                          p_attribute25               => null,
5641                          p_attribute26               => null,
5642                          p_attribute27               => null,
5643                          p_attribute28               => null,
5644                          p_attribute29               => null,
5645                          p_attribute30               => null,
5646                          p_sta_information_category  => null,
5647                          p_sta_information1          => null,
5648                          p_sta_information2          => null,
5649                          p_sta_information3          => null,
5650                          p_sta_information4          => null,
5651                          p_sta_information5          => null,
5652                          p_sta_information6          => null,
5653                          p_sta_information7          => null,
5654                          p_sta_information8          => null,
5655                          p_sta_information9          => null,
5656                          p_sta_information10         => null,
5657                          p_sta_information11         => null,
5658                          p_sta_information12         => null,
5659                          p_sta_information13         => null,
5660                          p_sta_information14         => null,
5661                          p_sta_information15         => null,
5662                          p_sta_information16         => null,
5663                          p_sta_information17         => null,
5664                          p_sta_information18         => null,
5665                          p_sta_information19         => null,
5666                          p_sta_information20         => null,
5667                          p_sta_information21         => null,
5668                          p_sta_information22         => null,
5669                          p_sta_information23         => null,
5670                          p_sta_information24         => null,
5671                          p_sta_information25         => null,
5672                          p_sta_information26         => null,
5673                          p_sta_information27         => null,
5674                          p_sta_information28         => null,
5675                          p_sta_information29         => null,
5676                          p_sta_information30         => null     );
5677 
5678   hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',9);
5679 
5680 end if;
5681 
5682   hr_utility.set_location('pay_us_emp_dt_tax_rules.ins_def_state',10);
5683 
5684 return l_emp_state_tax_rule_id;
5685 
5686 end  insert_def_state_rec;
5687 
5688 
5689 function insert_def_county_rec(p_assignment_id        number,
5690                                p_effective_start_date date,
5691                                p_effective_end_date   date,
5692                                p_state_code           varchar2,
5693                                p_county_code          varchar2,
5694                                p_business_group_id    number,
5695                                p_percent_time         number)
5696 return number is
5697 
5698 l_filing_status_code       varchar2(2);
5699 l_emp_county_tax_rule_id   number;
5700 l_row_id                   varchar2(30);
5701 
5702 /*
5703 cursor csr_filing_status is
5704        select lookup_code
5705        from   HR_LOOKUPS
5706        where  lookup_type    = 'US_LIT_FILING_STATUS'
5707        and    upper(meaning) = 'SINGLE';
5708 */
5709 
5710 cursor csr_filing_status is
5711        select lookup_code
5712        from   FND_LOOKUP_VALUES
5713        where  lookup_type    = 'US_LIT_FILING_STATUS'
5714        and    upper(meaning) = 'SINGLE'
5715        and    language = 'US';
5716 
5717 cursor chk_county_exists is
5718 select 'Y'
5719 from dual
5720 where exists (select null
5721               from pay_us_emp_county_tax_rules_f pst
5725               and business_group_id + 0 = p_business_group_id);
5722               where pst.assignment_id = p_assignment_id
5723               and   state_code = p_state_code
5724               and   county_code = p_county_code
5726 
5727 l_flag varchar2(1) := 'N';
5728 
5729 begin
5730 
5731   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_county_rec',1);
5732 
5733   open chk_county_exists;
5734   fetch chk_county_exists into l_flag;
5735   if chk_county_exists%NOTFOUND then
5736      l_flag := 'N';
5737   end if;
5738   close chk_county_exists;
5739 
5740   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_county_rec',91);
5741 
5742 if l_flag = 'N' then
5743 
5744   open  csr_filing_status;
5745 
5746   fetch csr_filing_status into l_filing_status_code;
5747 
5748   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_county_rec',2);
5749 
5750   if csr_filing_status%NOTFOUND then
5751 
5752      fnd_message.set_name('PAY','HR_6091_DEF_MISSING_LOOKUPS');
5753      fnd_message.set_token('LOOKUP_TYPE ','US_LIT_FILING_STATUS');
5754      fnd_message.raise_error;
5755 
5756   end if;
5757 
5758   close csr_filing_status;
5759 
5760   /* Insert County Tax record */
5761 
5762   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_county_rec',3);
5763 
5764 
5765   insert_county_tax_row(p_row_id                  => l_row_id,
5766                         p_emp_county_tax_rule_id  => l_emp_county_tax_rule_id,
5767                         p_effective_start_date    => p_effective_start_date,
5768                         p_effective_end_date      => p_effective_end_date,
5769                         p_assignment_id           => p_assignment_id,
5770                         p_state_code              => p_state_code,
5771                         p_county_code             => p_county_code,
5772                         p_business_group_id       => p_business_group_id,
5773                         p_additional_wa_rate      => 0,
5774                         p_filing_status_code      => lpad(l_filing_status_code,2,'0'),
5775                         p_jurisdiction_code       => p_state_code || '-' ||
5776                                                      p_county_code ||'-0000',
5777                         p_lit_additional_tax      => 0,
5778                         p_lit_override_amount     => 0,
5779                         p_lit_override_rate       => 0,
5780                         p_withholding_allowances  => 0,
5781                         p_lit_exempt              => 'N',
5782                         p_sd_exempt               => null,
5783                         p_ht_exempt               => null,
5784                         p_wage_exempt             => 'N',
5785                         p_school_district_code    => null,
5786                         p_time_in_county          => nvl(p_percent_time,0),
5787                         p_attribute_category        => null,
5788                         p_attribute1                => null,
5789                         p_attribute2                => null,
5790                         p_attribute3                => null,
5791                         p_attribute4                => null,
5792                         p_attribute5                => null,
5793                         p_attribute6                => null,
5794                         p_attribute7                => null,
5795                         p_attribute8                => null,
5796                         p_attribute9                => null,
5797                         p_attribute10               => null,
5798                         p_attribute11               => null,
5799                         p_attribute12               => null,
5800                         p_attribute13               => null,
5801                         p_attribute14               => null,
5802                         p_attribute15               => null,
5803                         p_attribute16               => null,
5804                         p_attribute17               => null,
5805                         p_attribute18               => null,
5806                         p_attribute19               => null,
5807                         p_attribute20               => null,
5808                         p_attribute21               => null,
5809                         p_attribute22               => null,
5810                         p_attribute23               => null,
5811                         p_attribute24               => null,
5812                         p_attribute25               => null,
5813                         p_attribute26               => null,
5814                         p_attribute27               => null,
5815                         p_attribute28               => null,
5816                         p_attribute29               => null,
5817                         p_attribute30               => null,
5818                         p_cnt_information_category  => null,
5819                         p_cnt_information1          => null,
5820                         p_cnt_information2          => null,
5821                         p_cnt_information3          => null,
5822                         p_cnt_information4          => null,
5823                         p_cnt_information5          => null,
5824                         p_cnt_information6          => null,
5825                         p_cnt_information7          => null,
5826                         p_cnt_information8          => null,
5827                         p_cnt_information9          => null,
5828                         p_cnt_information10         => null,
5832                         p_cnt_information14         => null,
5829                         p_cnt_information11         => null,
5830                         p_cnt_information12         => null,
5831                         p_cnt_information13         => null,
5833                         p_cnt_information15         => null,
5834                         p_cnt_information16         => null,
5835                         p_cnt_information17         => null,
5836                         p_cnt_information18         => null,
5837                         p_cnt_information19         => null,
5838                         p_cnt_information20         => null,
5839                         p_cnt_information21         => null,
5840                         p_cnt_information22         => null,
5841                         p_cnt_information23         => null,
5842                         p_cnt_information24         => null,
5843                         p_cnt_information25         => null,
5844                         p_cnt_information26         => null,
5845                         p_cnt_information27         => null,
5846                         p_cnt_information28         => null,
5847                         p_cnt_information29         => null,
5848                         p_cnt_information30         => null    );
5849 
5850   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_county_rec',4);
5851 end if;
5852   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_county_rec',5);
5853 
5854 return l_emp_county_tax_rule_id;
5855 
5856 end  insert_def_county_rec;
5857 
5858 
5859 function insert_def_city_rec(p_assignment_id        number,
5860                                p_effective_start_date date,
5861                                p_effective_end_date   date,
5862                                p_state_code           varchar2,
5863                                p_county_code          varchar2,
5864                                p_city_code            varchar2,
5865                                p_business_group_id    number,
5866                                p_percent_time       number)
5867 return number is
5868 
5869 l_filing_status_code       varchar2(2);
5870 l_emp_city_tax_rule_id   number;
5871 l_row_id                   varchar2(30);
5872 
5873 /*
5874 cursor csr_filing_status is
5875        select lookup_code
5876        from   HR_LOOKUPS
5877        where  lookup_type    = 'US_LIT_FILING_STATUS'
5878        and    upper(meaning) = 'SINGLE';
5879 */
5880 
5881 cursor csr_filing_status is
5882        select lookup_code
5883        from   FND_LOOKUP_VALUES
5884        where  lookup_type    = 'US_LIT_FILING_STATUS'
5885        and    upper(meaning) = 'SINGLE'
5886        and    language = 'US';
5887 
5888 cursor chk_city_exists is
5889 select 'Y'
5890 from dual
5891 where exists (select null
5892               from pay_us_emp_city_tax_rules_f pst
5893               where pst.assignment_id = p_assignment_id
5894               and   state_code = p_state_code
5895               and   county_code = p_county_code
5896               and   city_code = p_city_code
5897               and business_group_id + 0 = p_business_group_id);
5898 
5899 l_flag varchar2(1) := 'N';
5900 
5901 
5902 begin
5903 
5904   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_city_rec',1);
5905 
5906   open chk_city_exists;
5907   fetch chk_city_exists into l_flag;
5908   if chk_city_exists%NOTFOUND then
5909      l_flag := 'N';
5910   end if;
5911   close chk_city_exists;
5912 
5913   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_city_rec',91);
5914 
5915   if l_flag = 'N' then
5916 
5917   open  csr_filing_status;
5918 
5919   fetch csr_filing_status into l_filing_status_code;
5920 
5921   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_city_rec',2);
5922 
5923   if csr_filing_status%NOTFOUND then
5924 
5925      fnd_message.set_name('PAY','HR_6091_DEF_MISSING_LOOKUPS');
5926      fnd_message.set_token('LOOKUP_TYPE ','US_LIT_FILING_STATUS');
5927      fnd_message.raise_error;
5928 
5929   end if;
5930 
5931   close csr_filing_status;
5932 
5933   /* Insert City Tax record */
5934 
5935   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_city_rec',3);
5936 
5937 
5938   insert_city_tax_row(p_row_id                  => l_row_id,
5939                         p_emp_city_tax_rule_id  => l_emp_city_tax_rule_id,
5940                         p_effective_start_date    => p_effective_start_date,
5941                         p_effective_end_date      => p_effective_end_date,
5942                         p_assignment_id           => p_assignment_id,
5943                         p_state_code              => p_state_code,
5944                         p_county_code             => p_county_code,
5945                         p_city_code               => p_city_code,
5946                         p_business_group_id       => p_business_group_id,
5947                         p_additional_wa_rate      => 0,
5948                         p_filing_status_code      => lpad(l_filing_status_code,2,'0'),
5949                         p_jurisdiction_code       => p_state_code || '-' ||
5950                                            p_county_code ||'-' || p_city_code,
5951                         p_lit_additional_tax      => 0,
5952                         p_lit_override_amount     => 0,
5953                         p_lit_override_rate       => 0,
5954                         p_withholding_allowances  => 0,
5958                         p_wage_exempt             => 'N',
5955                         p_lit_exempt              => 'N',
5956                         p_sd_exempt               => null,
5957                         p_ht_exempt               => null,
5959                         p_school_district_code    => null,
5960                         p_time_in_city            => nvl(p_percent_time,0),
5961                         p_attribute_category        => null,
5962                         p_attribute1                => null,
5963                         p_attribute2                => null,
5964                         p_attribute3                => null,
5965                         p_attribute4                => null,
5966                         p_attribute5                => null,
5967                         p_attribute6                => null,
5968                         p_attribute7                => null,
5969                         p_attribute8                => null,
5970                         p_attribute9                => null,
5971                         p_attribute10               => null,
5972                         p_attribute11               => null,
5973                         p_attribute12               => null,
5974                         p_attribute13               => null,
5975                         p_attribute14               => null,
5976                         p_attribute15               => null,
5977                         p_attribute16               => null,
5978                         p_attribute17               => null,
5979                         p_attribute18               => null,
5980                         p_attribute19               => null,
5981                         p_attribute20               => null,
5982                         p_attribute21               => null,
5983                         p_attribute22               => null,
5984                         p_attribute23               => null,
5985                         p_attribute24               => null,
5986                         p_attribute25               => null,
5987                         p_attribute26               => null,
5988                         p_attribute27               => null,
5989                         p_attribute28               => null,
5990                         p_attribute29               => null,
5991                         p_attribute30               => null,
5992                         p_cty_information_category  => null,
5993                         p_cty_information1          => null,
5994                         p_cty_information2          => null,
5995                         p_cty_information3          => null,
5996                         p_cty_information4          => null,
5997                         p_cty_information5          => null,
5998                         p_cty_information6          => null,
5999                         p_cty_information7          => null,
6000                         p_cty_information8          => null,
6001                         p_cty_information9          => null,
6002                         p_cty_information10         => null,
6003                         p_cty_information11         => null,
6004                         p_cty_information12         => null,
6005                         p_cty_information13         => null,
6006                         p_cty_information14         => null,
6007                         p_cty_information15         => null,
6008                         p_cty_information16         => null,
6009                         p_cty_information17         => null,
6010                         p_cty_information18         => null,
6011                         p_cty_information19         => null,
6012                         p_cty_information20         => null,
6013                         p_cty_information21         => null,
6014                         p_cty_information22         => null,
6015                         p_cty_information23         => null,
6016                         p_cty_information24         => null,
6017                         p_cty_information25         => null,
6018                         p_cty_information26         => null,
6019                         p_cty_information27         => null,
6020                         p_cty_information28         => null,
6021                         p_cty_information29         => null,
6022                         p_cty_information30         => null     );
6023 
6024   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_city_rec',4);
6025 end if;
6026 
6027   hr_utility.set_location('pay_us_emp_dt_tax_rules.insert_def_city_rec',5);
6028 
6029 return l_emp_city_tax_rule_id;
6030 
6031 end  insert_def_city_rec;
6032 
6033 
6034 /*    Name          : zero_out_time
6035       Purpose       : Zero out time in state and localities
6036                       in preparation for setting the city of
6037                       the new work location to 100%
6038 */
6039 
6040 procedure zero_out_time(p_assignment_id         in number,
6041                         p_effective_start_date  in date,
6042                         p_effective_end_date    in date) is
6043 
6044 l_jurisdiction_code     varchar2(11);
6045 l_eff_start_date        date;
6046 
6047 /* Cursor to retrieve the jurisdictions for all existing
6048    VERTEX element entries */
6049 
6050 cursor csr_get_jurisdiction is
6051 select peev.screen_entry_value jurisdiction,
6052        peef.effective_start_date start_date
6053   from  PAY_ELEMENT_ENTRY_VALUES_F peev,
6054         PAY_ELEMENT_ENTRIES_F peef,
6055         PAY_INPUT_VALUES_F piv,
6056         PAY_ELEMENT_TYPES_F pet
6057   where pet.element_name = 'VERTEX'
6058     and pet.element_type_id = piv.element_type_id
6062     and peev.effective_start_date = peef.effective_start_date
6059     and piv.name = 'Jurisdiction'
6060     and piv.input_value_id = 0 + peev.input_value_id
6061     and peev.element_entry_id = peef.element_entry_id
6063     and peev.effective_end_date = peef.effective_end_date
6064     and p_assignment_id = peef.assignment_id
6065     and peef.effective_start_date = p_effective_start_date
6066     and peef.effective_end_date   = p_effective_end_date
6067     and peef.effective_start_date between pet.effective_start_date and pet.effective_end_date; -- Bug 3354060 added to remove MJC between
6068                                                                                                -- PAY_INPUT_VALUES_F  and
6069                                                                                                -- PAY_ELEMENT_ENTRIES_F
6070 
6071 begin
6072 
6073     hr_utility.set_location('pay_us_emp_dt_tax_rules.zero_out_time',1);
6074 
6075     open csr_get_jurisdiction;
6076 
6077     /* Now loop through all VERTEX element entries
6078        and set them to zero. */
6079 
6080     loop
6081 
6082        fetch csr_get_jurisdiction into l_jurisdiction_code,
6083                                        l_eff_start_date;
6084 
6085        exit when csr_get_jurisdiction%NOTFOUND;
6086 
6087        /* For the jurisdiction, set the %age time in that
6088           jurisdiction to zero */
6089 
6090        maintain_element_entry(
6091          p_assignment_id        => p_assignment_id,
6092          p_effective_start_date => p_effective_start_date,
6093          p_effective_end_date   => p_effective_end_date,
6094          p_session_date         => l_eff_start_date,
6095          p_jurisdiction_code    => l_jurisdiction_code,
6096          p_percentage_time      => 0,
6097          p_mode                 => 'CORRECTION');
6098 
6099      end loop;
6100 
6101      close csr_get_jurisdiction;
6102 
6103      hr_utility.set_location('pay_us_emp_dt_tax_rules.zero_out_time',2);
6104 
6105 end zero_out_time;
6106 
6107 /* Name    : set_sui_wage_base_override
6108    Purpose : To update sui_wage_base_override_amount for the new work location,
6109              with respect to every change in location state. The procedure
6110              will also take care of the condition of changing GRE when work
6111              location state remains unchanged / changed as well Rehire condition.
6112 */
6113 
6114 procedure set_sui_wage_base_override(p_assignment_id    in number,
6115                                      p_state_code       in varchar2 default null,
6116 				                     p_session_date     in date)
6117 is
6118 
6119 l_sui_er_wg_lt_curr_state  pay_us_state_tax_info_f.sui_er_wage_limit%type ;
6120 l_max_asg_eff_st_dt        date ;
6121 l_max_pact_dt              date ;
6122 l_tax_unit_id              number ;
6123 l_defined_balance_id       pay_defined_balances.defined_balance_id%type ;
6124 l_balance_value            number ;
6125 l_oth_combined_balance     number ;
6126 l_combined_balance_value   number ;
6127 l_sui_wg_base              number ;
6128 l_jurisdiction_code        varchar2(11) ;
6129 l_count                    number := 0 ;
6130 l_rehired                  varchar2(1) := 'N' ;
6131 l_actual_balance_value     number ;
6132 l_person_id                number ;
6133 
6134 cursor c_all_states(p_assignment_id in number,
6135 		            p_session_date in date) is
6136      select state_code
6137      from   pay_us_emp_state_tax_rules_f
6138      where  assignment_id = p_assignment_id ;
6139 
6140 cursor c_tax_unit_id(p_assignment_id in number,
6141                      p_session_date  in date) is
6142      select to_number(segment1) tax_unit_id
6143      from   hr_soft_coding_keyflex a,
6144             per_assignments_f  b
6145      where  b.assignment_id = p_assignment_id
6146      and    b.soft_coding_keyflex_id = a.soft_coding_keyflex_id
6147      and    p_session_date between b.effective_start_date and b.effective_end_date ;
6148 
6149 cursor c_defined_balance_id(p_dbi_name in varchar2) is
6150      select fnd_number.canonical_to_number(UE.creator_id)
6151      from  ff_user_entities  UE,
6152            ff_database_items DI
6153      where  DI.user_name            = p_dbi_name --'SUI_ER_TAXABLE_PER_JD_GRE_YTD'
6154        and  UE.user_entity_id       = DI.user_entity_id
6155        and  Ue.creator_type         = 'B'
6156        and  UE.legislation_code     = 'US' ;
6157 
6158 cursor c_max_asg_eff_st_date(p_assignment_id in number) is
6159       select max(effective_start_date)
6160       from   per_assignments_f paf,
6161              per_assignment_status_types past
6162       where  paf.assignment_id = p_assignment_id
6163       and    paf.assignment_status_type_id = past.assignment_status_type_id
6164       and    past.per_system_status = 'ACTIVE_ASSIGN'
6165       and   ((past.business_group_id is null
6166              and past.legislation_code is null)
6167              OR (past.business_group_id is null
6168                 and past.legislation_code = 'US')
6169              OR (past.legislation_code is null
6170                  and exists
6171                     (select 'x'
6172                      from  per_assignments_f paf_i
6173                      where paf_i.assignment_id = p_assignment_id
6174                      and   paf_i.business_group_id = past.business_group_id)
6175                  )
6176              )
6177       and    paf.payroll_id is not null ;
6178 
6182       where p_effective_date between effective_start_date
6179 cursor c_sui_wage_limit(p_state_code in varchar2, p_effective_date in date) is
6180       select sui_er_wage_limit
6181       from pay_us_state_tax_info_f
6183                                   and effective_end_date
6184         and sta_information_category = 'State tax limit rate info'
6185         and state_code = p_state_code ;
6186 
6187  Cursor c_max_pact_dt(p_assignment_id in number,
6188                       p_session_date in date) is
6189     select max(effective_date)
6190 	from pay_payroll_actions ppa,
6191 	     pay_assignment_actions paa,
6192 	     per_assignments_f paf
6193 	where paf.assignment_id = p_assignment_id
6194 	and   paf.assignment_id = paa.assignment_id
6195 	and   paa.payroll_action_id = ppa.payroll_action_id
6196 	and   ppa.action_type in ('R','Q','B','V','I')
6197 	and   nvl(ppa.date_earned,ppa.effective_date) between trunc(p_session_date,'Y')
6198 	                         and last_day(add_months(trunc(p_session_date,'Y'),11)) ;
6199 
6200  Cursor c_ckeck_rehire(p_assignment_id in number,
6201                        p_session_date in date) is
6202         select 'Y'
6203         from per_assignments_f paf_o,
6204              per_assignment_status_types past
6205         where paf_o.assignment_id = p_assignment_id
6206          and  paf_o.assignment_status_type_id = past.assignment_status_type_id
6207          and  past.per_system_status = 'ACTIVE_ASSIGN'
6208          and  ((past.business_group_id is null
6209                 and past.legislation_code is null)
6210                 OR (past.business_group_id is null
6211                     and past.legislation_code = 'US')
6212                 OR (past.legislation_code is null
6213                     and exists
6214                         (select 'x'
6215                          from  per_assignments_f paf_a
6216                          where paf_a.assignment_id = p_assignment_id
6217                          and   paf_a.business_group_id = past.business_group_id)
6218                     )
6219                )
6220 
6221         and   exists
6222        (
6223         select distinct paf_i.assignment_id
6224         from per_assignments_f paf_i,
6225              per_assignments_f paf_term
6226         where paf_i.person_id = paf_o.person_id
6227         and   paf_i.person_id = paf_term.person_id
6228         and   paf_i.assignment_id > paf_term.assignment_id
6229         and   paf_i.effective_start_date >= paf_term.effective_end_date
6230         and  ( trunc(paf_i.effective_end_date,'Y') = trunc(p_session_date,'Y')
6231               or (trunc(paf_i.effective_start_date,'Y') = trunc(p_session_date,'Y')
6232                  and trunc(paf_i.effective_end_date,'Y') > trunc(p_session_date,'Y')))
6233        ) ;
6234 
6235  Cursor c_get_person_id(p_assignment_id in number) is
6236         select distinct paf.person_id
6237         from per_assignments_f paf
6238         where paf.assignment_id = p_assignment_id ;
6239 
6240  Cursor c_get_all_assignments(p_person_id in number,
6241                               p_session_date in date) is
6242         select distinct paf.assignment_id
6243         from per_assignments_f paf
6244         where paf.person_id = p_person_id
6245         and  ( trunc(paf.effective_end_date,'Y') = trunc(p_session_date,'Y')
6246               or (trunc(paf.effective_start_date,'Y') = trunc(p_session_date,'Y')
6247                  and trunc(paf.effective_end_date,'Y') > trunc(p_session_date,'Y'))) ;
6248 
6249 
6250 type state_code_typ is table of varchar2(2) index by BINARY_INTEGER ;
6251 state_code_tab state_code_typ ;
6252 type balance_typ is table of number index by BINARY_INTEGER ;
6253 balance_tab   balance_typ ;
6254 begin
6255     --hr_utility.trace_on(null,'pyusdtw4') ;
6256 
6257     hr_utility.trace('Entering pay_us_emp_dt_tax_rules.set_sui_wage_base_override.') ;
6258     hr_utility.trace('p_assignment_id := ' || to_char(p_assignment_id)) ;
6259     hr_utility.trace('p_state_code := ' || p_state_code) ;
6260     hr_utility.trace('p_session_date := ' || to_char(p_session_date)) ;
6261 
6262     l_balance_value := 0 ;
6263     l_combined_balance_value := 0 ;
6264     l_sui_wg_base := 0 ;
6265     l_actual_balance_value := 0 ;
6266     l_oth_combined_balance := 0 ;
6267 
6268      hr_utility.trace('Getting Effective Start Date of Latest Active Assignment.') ;
6269      open c_max_asg_eff_st_date(p_assignment_id) ;
6270      fetch c_max_asg_eff_st_date into l_max_asg_eff_st_dt ;
6271      if c_max_asg_eff_st_date%notfound then
6272         close c_max_asg_eff_st_date ;
6273 	    raise hr_utility.hr_error ;
6274      end if ;
6275      hr_utility.trace('Effective Start Date of Latest Active Assignment: '|| to_char(l_max_asg_eff_st_dt)) ;
6276 
6277      hr_utility.trace('Getting Effective Date of Latest Payroll Action ID.') ;
6278      open c_max_pact_dt(p_assignment_id, p_session_date) ;
6279      fetch c_max_pact_dt into l_max_pact_dt ;
6280      if c_max_pact_dt%notfound then
6281         close c_max_pact_dt ;
6282 	 raise hr_utility.hr_error ;
6283      end if ;
6284      hr_utility.trace('Effective Date of Latest Payroll Action ID: '|| to_char(l_max_pact_dt)) ;
6285 
6286      hr_utility.trace('Getting Defined Balance ID for SUI_ER_TAXABLE_PER_JD_GRE_YTD.') ;
6287      open c_defined_balance_id('SUI_ER_TAXABLE_PER_JD_GRE_YTD') ;
6288      fetch c_defined_balance_id into l_defined_balance_id ;
6289      if c_defined_balance_id%notfound then
6290         close c_defined_balance_id ;
6291         raise hr_utility.hr_error ;
6292      end if ;
6293      hr_utility.trace('Defined Balance ID for SUI_ER_TAXABLE_PER_JD_GRE_YTD: '|| to_char(l_defined_balance_id)) ;
6297      fetch c_tax_unit_id into l_tax_unit_id ;
6294 
6295      hr_utility.trace('Getting Tax Unit ID.') ;
6296      open c_tax_unit_id(p_assignment_id, p_session_date ) ;
6298      if c_tax_unit_id%notfound then
6299         close c_tax_unit_id ;
6300     	raise hr_utility.hr_error ;
6301      end if ;
6302      hr_utility.trace('Tax Unit ID: '|| to_char(l_tax_unit_id)) ;
6303 
6304      hr_utility.trace('Getting Person ID.') ;
6305      open c_get_person_id(p_assignment_id) ;
6306      fetch c_get_person_id into l_person_id ;
6307      if c_get_person_id%notfound then
6308         close c_get_person_id ;
6309         raise hr_utility.hr_error ;
6310      end if ;
6311      hr_utility.trace('Person ID: '|| to_char(l_person_id)) ;
6312 
6313      hr_utility.trace('p_state_code := '||p_state_code) ;
6314      hr_utility.trace('p_assignment_id..Original := '||to_char(p_assignment_id)) ;
6315 
6316      hr_utility.trace('Getting Rehire Y or N Flag.') ;
6317      open c_ckeck_rehire(p_assignment_id, p_session_date) ;
6318      fetch c_ckeck_rehire into l_rehired ;
6319      if c_ckeck_rehire%notfound then
6320         l_rehired := 'N' ;
6321         close c_ckeck_rehire ;
6322      end if ;
6323      hr_utility.trace('Rehire Flag Value: '|| l_rehired) ;
6324 
6325    IF nvl(l_rehired,'N') = 'Y' THEN
6326      l_count := 1 ;
6327      /* For Rehired Condition, iterating through all the assignments for the concerned person
6328         either active for the current year or was effective from earlier and terminated within the current year */
6329      for i_get_all_assignments in c_get_all_assignments(l_person_id,p_session_date)
6330      loop
6331         hr_utility.trace('l_person_id := '||to_char(l_person_id)) ;
6332         /* For each of the above-mentioned assignment iterating through all the states the employee worked on
6333            and populating PL/SQL table with the SUI ER Taxable Balance value and corresponding State Code */
6334         for i_all_states in c_all_states(i_get_all_assignments.assignment_id,p_session_date)
6335         loop
6336         IF i_all_states.state_code <> '24'  THEN
6337 
6338          state_code_tab(l_count) := i_all_states.state_code ;
6339          l_jurisdiction_code := i_all_states.state_code || '-000-0000' ;
6340 
6341          hr_utility.trace('l_count := '||to_char(l_count)) ;
6342          hr_utility.trace('i_get_all_assignments.assignment_id:= '||to_char(i_get_all_assignments.assignment_id)) ;
6343          hr_utility.trace('l_tax_unit_id := '||to_char(l_tax_unit_id)) ;
6344          hr_utility.trace('l_jurisdiction_code := '||l_jurisdiction_code) ;
6345 
6346          pay_balance_pkg.set_context('TAX_UNIT_ID',l_tax_unit_id) ;
6347          pay_balance_pkg.set_context('JURISDICTION_CODE',l_jurisdiction_code) ;
6348 
6349          l_balance_value := pay_balance_pkg.get_value(
6350                                l_defined_balance_id ,
6351                                p_assignment_id,
6352                                nvl(l_max_pact_dt,GREATEST(l_max_asg_eff_st_dt,trunc(p_session_date,'Y')))) ;
6353 
6354          balance_tab(l_count) := l_balance_value ;
6355 
6356          hr_utility.trace('l_balance_value := '||to_char(l_balance_value)) ;
6357          /* Summing up the balance value */
6358          l_combined_balance_value := l_combined_balance_value + l_balance_value ;
6359 
6360          hr_utility.trace('l_combined_balance_value := '||to_char(l_combined_balance_value)) ;
6361 
6362          l_count := l_count + 1 ;
6363         END IF ;
6364         end loop ;
6365       end loop ;
6366       /* Eliminating the Duplicate 'State Code - Balance Value' combination and
6367          calculating the correct Summed up Balance value */
6368       IF state_code_tab.count <> 0 THEN
6369       for i in state_code_tab.first .. state_code_tab.last
6370       loop
6371           for j in 1 .. i-1
6372           loop
6373            if state_code_tab(i) = state_code_tab(j) then
6374               l_combined_balance_value := l_combined_balance_value - balance_tab(i) ;
6375               exit ;
6376            end if ;
6377           end loop ;
6378        end loop ;
6379       END IF ;
6380        hr_utility.trace('l_combined_balance_value B4 Subtracting Actual := '||to_char(l_combined_balance_value)) ;
6381        /* Looping through the current States under the Current Active Assignment
6382           and doing a balance call wrt to current jurisdiction and calculating
6383           eligible SUI Wage Base Override for the State */
6384        for i_all_curr_states in c_all_states(p_assignment_id,p_session_date)
6385        loop
6386          IF i_all_curr_states.state_code <> '24' THEN
6387 
6388             l_jurisdiction_code := i_all_curr_states.state_code || '-000-0000' ;
6389 
6390 
6391             pay_balance_pkg.set_context('TAX_UNIT_ID',l_tax_unit_id) ;
6392             pay_balance_pkg.set_context('JURISDICTION_CODE',l_jurisdiction_code) ;
6393 
6394             l_actual_balance_value := pay_balance_pkg.get_value(
6395                                l_defined_balance_id ,
6396                                p_assignment_id,
6397                                nvl(l_max_pact_dt,GREATEST(l_max_asg_eff_st_dt,trunc(p_session_date,'Y')))) ;
6398 
6399            l_oth_combined_balance := l_combined_balance_value - l_actual_balance_value ;
6400 
6401            hr_utility.trace('Actual States := '||i_all_curr_states.state_code) ;
6402            hr_utility.trace('l_actual_balance_value := '||to_char(l_actual_balance_value)) ;
6406            fetch c_sui_wage_limit into l_sui_er_wg_lt_curr_state ;
6403            hr_utility.trace('l_oth_combined_balance A4 Subtracting Actual := '||to_char(l_oth_combined_balance)) ;
6404 
6405            open c_sui_wage_limit(i_all_curr_states.state_code, p_session_date) ;
6407            close c_sui_wage_limit ;
6408            hr_utility.trace('SUI Wage Limit for the current State: '|| to_char(l_sui_er_wg_lt_curr_state)) ;
6409 
6410            IF l_oth_combined_balance < l_sui_er_wg_lt_curr_state THEN
6411               l_sui_wg_base := l_sui_er_wg_lt_curr_state - l_oth_combined_balance ;
6412            ELSIF l_oth_combined_balance >= l_sui_er_wg_lt_curr_state THEN
6413               l_sui_wg_base := 0 ;
6414            END IF ;
6415            hr_utility.trace('l_sui_wg_base := '||to_char(l_sui_wg_base)) ;
6416 
6417            IF l_oth_combined_balance > 0 OR l_actual_balance_value > 0 THEN
6418              update pay_us_emp_state_tax_rules_f
6419              set    sui_wage_base_override_amount = l_sui_wg_base
6420              where  assignment_id = p_assignment_id
6421              and    state_code = i_all_curr_states.state_code ;
6422            ELSE
6423 	          update pay_us_emp_state_tax_rules_f
6424               set    sui_wage_base_override_amount = null
6425               where  assignment_id = p_assignment_id
6426               and    state_code = i_all_curr_states.state_code ;
6427            END IF ;
6428            hr_utility.trace('SUI Wage Base Updated...') ;
6429          END IF ;
6430       end loop ;
6431    ELSE -- Not Rehired Condition
6432        hr_utility.trace('Not Rehired Condition... ') ;
6433        l_count := 1 ;
6434        /* Iterating through all the states where the employee worked for the Current Assignment
6435           and populating PL/SQL table with the State Code and SUI ER Taxable Balance value */
6436        for i_all_states in c_all_states(p_assignment_id,p_session_date)
6437        loop
6438         IF i_all_states.state_code <> '24' THEN
6439          hr_utility.trace('l_count := '||to_char(l_count)) ;
6440          state_code_tab(l_count) := i_all_states.state_code ;
6441          l_jurisdiction_code := i_all_states.state_code || '-000-0000' ;
6442 
6443          hr_utility.trace('l_tax_unit_id := '||to_char(l_tax_unit_id)) ;
6444          hr_utility.trace('l_jurisdiction_code := '||l_jurisdiction_code) ;
6445 
6446          pay_balance_pkg.set_context('TAX_UNIT_ID',l_tax_unit_id) ;
6447          pay_balance_pkg.set_context('JURISDICTION_CODE',l_jurisdiction_code) ;
6448 
6449          l_balance_value := pay_balance_pkg.get_value(
6450                                l_defined_balance_id ,
6451                                p_assignment_id,
6452                                nvl(l_max_pact_dt,GREATEST(l_max_asg_eff_st_dt,trunc(p_session_date,'Y')))) ;
6453 
6454          balance_tab(l_count) := l_balance_value ;
6455          hr_utility.trace('l_balance_value := '||to_char(l_balance_value)) ;
6456          /* Summing up the Total Balance Value */
6457          l_combined_balance_value := l_combined_balance_value + l_balance_value ;
6458          hr_utility.trace('l_combined_balance_value := '||to_char(l_combined_balance_value)) ;
6459          l_count := l_count + 1 ;
6460 
6461         END IF ;
6462        end loop ;
6463       /* Looping through the PL/SQL table to get the Eligible SUI Wage Base for each State
6464          and Updating the data */
6465       IF state_code_tab.count <> 0 THEN
6466        for i in state_code_tab.first .. state_code_tab.last
6467        loop
6468           l_oth_combined_balance := l_combined_balance_value - balance_tab(i) ;
6469 
6470           open c_sui_wage_limit(state_code_tab(i), p_session_date) ;
6471           fetch c_sui_wage_limit into l_sui_er_wg_lt_curr_state ;
6472           close c_sui_wage_limit ;
6473           hr_utility.trace('SUI Wage Limit for the current State: '|| to_char(l_sui_er_wg_lt_curr_state)) ;
6474 
6475           IF l_oth_combined_balance < l_sui_er_wg_lt_curr_state THEN
6476              l_sui_wg_base := l_sui_er_wg_lt_curr_state - l_oth_combined_balance ;
6477           ELSIF l_oth_combined_balance >= l_sui_er_wg_lt_curr_state THEN
6478              l_sui_wg_base := 0 ;
6479           END IF ;
6480           hr_utility.trace('State_code := '||state_code_tab(i)) ;
6481           hr_utility.trace('l_oth_combined_balance := '||to_char(l_oth_combined_balance)) ;
6482           hr_utility.trace('l_sui_wg_base := '||to_char(l_sui_wg_base)) ;
6483 
6484           IF l_oth_combined_balance > 0 OR l_combined_balance_value > 0 THEN
6485              update pay_us_emp_state_tax_rules_f
6486              set    sui_wage_base_override_amount = l_sui_wg_base
6487              where  assignment_id = p_assignment_id
6488              and    state_code = state_code_tab(i) ;
6489 	      ELSE
6490 	          update pay_us_emp_state_tax_rules_f
6491               set    sui_wage_base_override_amount = null
6492               where  assignment_id = p_assignment_id
6493               and    state_code = state_code_tab(i) ;
6494           END IF ;
6495           hr_utility.trace('SUI Wage Base Updated...') ;
6496        end loop ;
6497       END IF ;
6498  END IF ;
6499 /* Exception for the State of Minnesota - No SUI Wage Transfer allowed */
6500  IF p_state_code = '24' THEN
6501     open c_sui_wage_limit(p_state_code, l_max_asg_eff_st_dt) ;
6502     fetch c_sui_wage_limit into l_sui_er_wg_lt_curr_state ;
6503     close c_sui_wage_limit ;
6504 
6505     update pay_us_emp_state_tax_rules_f
6506     set    sui_wage_base_override_amount = l_sui_er_wg_lt_curr_state
6507     where  assignment_id = p_assignment_id
6508     and    state_code = p_state_code  ;
6509  END IF ;
6510 
6511 end set_sui_wage_base_override;
6512 
6513 
6514 /* Name    : create_new_location_rec
6515    Purpose : To create record for the new work location, with respect
6516              to every change in location and set the city record for
6517              the time period between p_validation_start_date and
6518              p_validation_end_date to 100%
6519 */
6520 
6521 procedure create_new_location_rec(p_assignment_id         in number,
6522                                   p_validation_start_date in date,
6523                                   p_validation_end_date   in date,
6524                                   p_session_date          in date,
6525                                   p_new_location_id       in number,
6526                                   p_res_state_code        in varchar2,
6527                                   p_res_county_code       in varchar2,
6528                                   p_res_city_code         in varchar2,
6529                                   p_business_group        in number,
6530                                   p_percent               in number) is
6531 
6532   l_state_code             varchar2(2);
6533   l_county_code            varchar2(3);
6534   l_city_code              varchar2(4);
6535   l_ovrd_state_code        varchar2(2);
6536   l_ovrd_county_code        varchar2(3);
6537   l_ovrd_city_code         varchar2(4);
6538   l_jurisdiction_code      varchar2(11);
6539   l_end_of_time            date := to_date('31/12/4712','DD/MM/YYYY');
6540   l_ret_code                            number := 0;
6541   l_ret_text                              varchar2(240) := null;
6542   l_emp_state_tax_rule_id    number;
6543   l_emp_county_tax_rule_id number;
6544   l_emp_city_tax_rule_id      number;
6545   l_default_date                     date;
6546 
6547 
6548 
6549   /* Cursor to get the state code, county code and the city code
6550      corresponding to a location id */
6551   /* lwthomps .. While we only want to create tax records for the
6552      primary cities, locations can corespond to vanity or secondary
6553      cities that share the same geocode.  For this reason I am removing
6554      the join to pay_us_city_names for primary = 'Y' (588982) */
6555 
6556   cursor csr_get_codes(p_location number) is
6557    select pus.state_code,
6558          puco.county_code,
6559          puci.city_code,
6560          pus1.state_code,
6561          puco1.county_code,
6562          puci1.city_code
6563    from  PAY_US_CITY_NAMES puci1,
6564          PAY_US_COUNTIES puco1,
6565          PAY_US_STATES pus1,
6566          PAY_US_CITY_NAMES puci,
6567          PAY_US_COUNTIES puco,
6568          PAY_US_STATES pus,
6569          HR_LOCATIONS hrl
6570   where  hrl.location_id  = p_location
6571   and    pus.state_abbrev = hrl.region_2
6572   and    puco.state_code  = pus.state_code
6573   and    puco.county_name = hrl.region_1
6574   and    puci.state_code  = puco.state_code
6575   and    puci.county_code = puco.county_code
6576   and    puci.city_name   = hrl.town_or_city
6577   and    pus1.state_abbrev = nvl(hrl.loc_information17,hrl.region_2)
6578   and    puco1.state_code  = pus1.state_code
6579   and    puco1.county_name = nvl(hrl.loc_information19,hrl.region_1)
6580   and    puci1.state_code  = puco1.state_code
6581   and    puci1.county_code = puco1.county_code
6585 
6582   and    puci1.city_name   = nvl(hrl.loc_information18,hrl.town_or_city);
6583 
6584   /* and    puci.primary_flag = 'Y';  */
6586   /* End changes by lwthomps (588982)*/
6587 
6588    cursor csr_get_eff_date is
6589        select min(effective_start_date)
6590        from   PAY_US_EMP_FED_TAX_RULES_F
6591        where  assignment_id = p_assignment_id;
6592 
6593  /* Added cursor csr_get_max_assign_end_dt
6594     for bug 2535501 to get the max(effective_end_date)
6595     of an assignment.  This will ensure that the end_date
6596     of the state, county and city tax_rules_f tables
6597     will have correct end dates when a new row is created.
6598 */
6599 
6600    cursor csr_get_max_assign_end_dt is
6601       select max(effective_end_date)
6602       from   per_assignments_f
6603       where  assignment_id = p_assignment_id;
6604 
6605 
6606 l_max_assign_end_dt date := NULL;
6607 
6608 begin
6609 
6610 
6611    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',1);
6612    if (p_new_location_id is null) and (p_res_state_code is not null
6613       and p_res_county_code is not null
6614       and p_res_city_code is not null )then
6615 
6616       /* called for residential address */
6617       l_state_code := p_res_state_code;
6618       l_county_code := p_res_county_code;
6619       l_city_code   := p_res_city_code;
6620 
6621    else   /* called for work location */
6622 
6623      /* Get the state code, county code and the city code for the
6624         new location */
6625 
6626    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',2);
6627      open csr_get_codes(p_new_location_id);
6628      fetch csr_get_codes into l_state_code, l_county_code,l_city_code,
6629                               l_ovrd_state_code, l_ovrd_county_code,
6630                               l_ovrd_city_code;
6631      if csr_get_codes%NOTFOUND then
6632        fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
6633        fnd_message.set_token('PROCEDURE',
6634                    'pay_us_emp_dt_tax_rules.create_new_loc_rec');
6635        fnd_message.set_token('STEP','2');
6636        fnd_message.raise_error;
6637       end if;
6638       close csr_get_codes;
6639 
6640     end if;
6641 
6642    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',3);
6643     /* Get the default date from the federal tax rules record */
6644 
6645        open csr_get_eff_date;
6646 
6647        fetch csr_get_eff_date into l_default_date;
6648 
6649        if l_default_date is null then
6650            fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
6651            fnd_message.set_token('PROCEDURE',
6652                       'pay_us_emp_dt_tax_rules.create_new_location_rec');
6653            fnd_message.set_token('STEP','1');
6654            fnd_message.raise_error;
6655        end if;
6656 
6657        close csr_get_eff_date;
6658 
6659     /* Create the new location records */
6660 
6661 
6662    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',4);
6663     l_ret_code := 0;
6664     l_ret_text := null;
6665     l_jurisdiction_code := l_state_code ||'-000-0000';
6666 
6667    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',5);
6668     pay_us_emp_dt_tax_val.check_jurisdiction_exists(p_assignment_id     => p_assignment_id,
6669                               p_jurisdiction_code => l_jurisdiction_code,
6670                               p_ret_code          => l_ret_code,
6671                               p_ret_text          => l_ret_text);
6672    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',6);
6673 
6674 /* Bug 2535501 */
6675 
6676    open csr_get_max_assign_end_dt;
6677    fetch csr_get_max_assign_end_dt into l_max_assign_end_dt;
6678 
6679 
6680    if csr_get_max_assign_end_dt%NOTFOUND then
6681         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
6682         fnd_message.set_token('PROCEDURE',
6683                    'pay_us_emp_dt_tax_rules.create_new_location_rec');
6684         fnd_message.set_token('STEP','3');
6685         fnd_message.raise_error;
6686     end if;
6687 
6688    close csr_get_max_assign_end_dt;
6689 
6690 /* End Bug 2535501 */
6691 
6692     /* If state record does not exist then the county and city
6693        records also do not exist */
6694 
6695         /* Create the state tax rule record and then create %age record
6696            for state. The ins_def_state_rec routine will create the
6697            state tax rule record from  begin of time till end of time
6698            and also the state percentage record for every change in
6699            location */
6700 
6701      if l_ret_code = 1 then
6702    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',7);
6703          l_emp_state_tax_rule_id :=
6704          insert_def_state_rec(p_assignment_id        => p_assignment_id,
6705                            p_effective_start_date => l_default_date,
6706                            p_effective_end_date   => l_max_assign_end_dt, -- Bug 2535501
6707 --                           p_effective_end_date   => l_end_of_time,
6708                            p_state_code           => l_state_code,
6709                            p_business_group_id    => p_business_group,
6710                            p_percent_time         => 0);
6711 
6712          /* Create the county tax rule record and then create %age record
6716             location */
6713             for state. The ins_def_county_rec routine will create the
6714             county tax rule record from  begin of time till end of time
6715             and also the county percentage record for every change in
6717    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',8);
6718 
6719          l_emp_county_tax_rule_id :=
6720          insert_def_county_rec(p_assignment_id        => p_assignment_id,
6721                            p_effective_start_date => l_default_date,
6722                            p_effective_end_date   => l_max_assign_end_dt, -- Bug 2535501
6723 --                           p_effective_end_date   => l_end_of_time,
6724                            p_state_code           => l_state_code,
6725                            p_county_code          => l_county_code,
6726                            p_business_group_id    => p_business_group,
6727                            p_percent_time         => 0);
6728 
6729          /* Create the city tax rule record and then create %age record
6730             for state. The ins_def_city_rec routine will create the
6731             city tax rule record from  begin of time till end of time
6732             and also the city percentage record for every change in
6733             location */
6734    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',9);
6735 
6736          l_emp_city_tax_rule_id :=
6737          insert_def_city_rec(p_assignment_id        => p_assignment_id,
6738                            p_effective_start_date => l_default_date,
6739                            p_effective_end_date   => l_max_assign_end_dt, -- Bug 2535501
6740 --                           p_effective_end_date   => l_end_of_time,
6741                            p_state_code           => l_state_code,
6742                            p_county_code          => l_county_code,
6743                            p_city_code            => l_city_code,
6744                            p_business_group_id    => p_business_group,
6745                            p_percent_time         => 0);
6746 
6747    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',10);
6748 
6749      elsif l_ret_code = 0 then
6750          hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',101);
6751          /* State record exists. Now check if county record exists */
6752          -- Update SUI Wage Base Override Amount
6753          -- Update SUI WAGE BASE Overide amount if payroll is installed otherwise don't
6754 	     -- call the procedure which does the update
6755          -- Turning Off SUI Wage Base Override Functionality due to Bug# 5486281
6756          /*
6757 	     IF  hr_utility.chk_product_install(p_product =>'Oracle Payroll',
6758                                            p_legislation => 'US')
6759          then
6760                  hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',102);
6761                  if p_assignment_id is not null and p_session_date is not null
6762 		         then
6763                       hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',103);
6764                       set_sui_wage_base_override(p_assignment_id,l_state_code,p_session_date) ;
6765                  end if ;
6766          end if;
6767        -- End Change
6768           */
6769 
6770         l_ret_code := 0;
6771         l_ret_text := null;
6772         l_jurisdiction_code := l_state_code ||'-' || l_county_code ||'-0000';
6773 
6774         hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',11);
6775         pay_us_emp_dt_tax_val.check_jurisdiction_exists(p_assignment_id     => p_assignment_id,
6776                                   p_jurisdiction_code => l_jurisdiction_code,
6777                                   p_ret_code          => l_ret_code,
6778                                   p_ret_text          => l_ret_text);
6779    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',12);
6780         /* If county record does not exist then city will also not exist */
6781         if l_ret_code = 1 then
6782 
6783            /* Create the county tax rule record and then create %age record
6784            for state. The ins_def_county_rec routine will create the
6785            county tax rule record from  begin of time till end of time
6786            and also the county percentage record for every change in
6787            location */
6788 
6789    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',13);
6790            l_emp_county_tax_rule_id :=
6791            insert_def_county_rec(p_assignment_id        => p_assignment_id,
6792                           p_effective_start_date => l_default_date,
6793                            p_effective_end_date   => l_max_assign_end_dt, -- Bug 2535501
6794 --                           p_effective_end_date   => l_end_of_time,
6795                           p_state_code           => l_state_code,
6796                           p_county_code          => l_county_code,
6797                           p_business_group_id    => p_business_group,
6798                           p_percent_time         => 0);
6799 
6800            /* Create the city tax rule record and then create %age record
6801            for state. The ins_def_city_rec routine will create the
6802            city tax rule record from  begin of time till end of time
6803            and also the city percentage record for every change in
6804            location */
6805 
6806    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',14);
6807            l_emp_city_tax_rule_id :=
6808            insert_def_city_rec(p_assignment_id        => p_assignment_id,
6812                           p_state_code           => l_state_code,
6809                           p_effective_start_date => l_default_date,
6810                            p_effective_end_date   => l_max_assign_end_dt, -- Bug 2535501
6811 --                           p_effective_end_date   => l_end_of_time,
6813                           p_county_code          => l_county_code,
6814                           p_city_code            => l_city_code,
6815                           p_business_group_id    => p_business_group,
6816                           p_percent_time         => 0);
6817    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',15);
6818 
6819         elsif l_ret_code = 0 then
6820           /* State and county records exist. Check if the city record exists */
6821 
6822           l_ret_code := 0;
6823           l_ret_text := null;
6824           l_jurisdiction_code := l_state_code ||'-' || l_county_code ||'-'||
6825                                  l_city_code;
6826 
6827    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',16);
6828           pay_us_emp_dt_tax_val.check_jurisdiction_exists(p_assignment_id     => p_assignment_id,
6829                                   p_jurisdiction_code => l_jurisdiction_code,
6830                                   p_ret_code          => l_ret_code,
6831                                   p_ret_text          => l_ret_text);
6832    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',17);
6833 
6834           /* If city record does not exist then create one */
6835 
6836           if l_ret_code = 1 then
6837 
6838             /* Create the city tax rule record and then create %age record
6839                for state. The ins_def_city_rec routine will create the
6840                city tax rule record from  begin of time till end of time
6841                and also the city percentage record for every change in
6842                location */
6843    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',18);
6844 
6845             l_emp_city_tax_rule_id :=
6846             insert_def_city_rec(p_assignment_id        => p_assignment_id,
6847                               p_effective_start_date => l_default_date,
6848                            p_effective_end_date   => l_max_assign_end_dt, -- Bug 2535501
6849 --                           p_effective_end_date   => l_end_of_time,
6850                               p_state_code           => l_state_code,
6851                               p_county_code          => l_county_code,
6852                               p_city_code            => l_city_code,
6853                               p_business_group_id    => p_business_group,
6854                               p_percent_time         => 0);
6855    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',19);
6856 
6857          end if;
6858 
6859         end if;
6860 
6861      end if;
6862 
6863     if l_ovrd_state_code <> l_state_code then
6864 
6865    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',20);
6866        l_emp_state_tax_rule_id :=
6867        insert_def_state_rec(p_assignment_id   => p_assignment_id,
6868                            p_effective_start_date => l_default_date,
6869                            p_effective_end_date   => l_end_of_time,
6870                            p_state_code           => l_ovrd_state_code,
6871                            p_business_group_id    => p_business_group,
6872                            p_percent_time         => 0);
6873    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',21);
6874 
6875     end if;
6876 
6877     if (l_ovrd_state_code <> l_state_code
6878        or l_ovrd_county_code <> l_county_code) then
6879    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',22);
6880          l_emp_county_tax_rule_id :=
6881          insert_def_county_rec(p_assignment_id        => p_assignment_id,
6882                            p_effective_start_date => l_default_date,
6883                            p_effective_end_date   => l_end_of_time,
6884                            p_state_code           => l_ovrd_state_code,
6885                            p_county_code          => l_ovrd_county_code,
6886                            p_business_group_id    => p_business_group,
6887                            p_percent_time         => 0);
6888    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',23);
6889     end if;
6890 
6891     if (l_ovrd_state_code <> l_state_code
6892        or l_ovrd_county_code <> l_county_code
6893        or l_ovrd_city_code <> l_city_code) then
6894    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',24);
6895             l_emp_city_tax_rule_id :=
6896             insert_def_city_rec(p_assignment_id        => p_assignment_id,
6897                               p_effective_start_date => l_default_date,
6898                               p_effective_end_date   => l_end_of_time,
6899                               p_state_code           => l_ovrd_state_code,
6900                               p_county_code          => l_ovrd_county_code,
6901                               p_city_code            => l_ovrd_city_code,
6902                               p_business_group_id    => p_business_group,
6903                               p_percent_time         => 0);
6904    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',25);
6905      end if;
6906 
6907    /* if called for change in location then set the city to 100% */
6908 
6909    if p_new_location_id is not null and
6910       p_percent = 100 and
6911       (p_res_state_code is null
6912       and p_res_county_code is null and p_res_city_code is null) then
6913 
6917      if l_state_code = l_ovrd_state_code and l_county_code = l_ovrd_county_code
6914    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',26);
6915      /* Now update the city record and set it to 100% */
6916 
6918         and l_city_code = l_ovrd_city_code then
6919         l_jurisdiction_code := l_state_code ||'-' || l_county_code ||'-'|| l_city_code;
6920    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',27);
6921      else
6922         l_jurisdiction_code := l_ovrd_state_code ||'-' || l_ovrd_county_code ||'-'||l_ovrd_city_code;
6923    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',28);
6924      end if;
6925 
6926    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',29);
6927      maintain_element_entry (p_assignment_id       => p_assignment_id,
6928                              p_effective_start_date => p_validation_start_date,
6929                              p_effective_end_date   => p_validation_end_date,
6930                              p_session_date         => p_session_date,
6931                              p_jurisdiction_code    => l_jurisdiction_code,
6932                              p_percentage_time      => 100,
6933                              p_mode                 => 'CORRECTION');
6934    hr_utility.set_location('pay_us_emp_dt_tax_rules.create_new_location_rec',30);
6935     end if;
6936 
6937 end create_new_location_rec;
6938 
6939 
6940 /* Name          : del_updt_entries_for_dates
6941      Purpose     : This procedure can be used to change the effective start date
6942                    and/or effective end date of the element entries and the
6943                    pay_element_entry_values, for a jurisdiction of
6944                    an assignment. It can also be used to delete the element entries
6945                    for a given date range.
6946      Parameters  :
6947                  p_assignment_id     -> The assignment for which the vertex elemnt entries are
6948                                          to be modified for their start and/or end dates.
6949                   p_session_date      -> The start date of the element entry.
6950                   p_new_start_date    -> The new start date of the element entry.
6951                   p_new_end_date      -> The new end date of the element entry.
6952                   p_mode              -> 'U' -> for update
6953                                          'D' -> for Delete
6954                                          'F' -> FUTURE_CHANGE (for Delete)
6955                                          'N' -> DELETE_NEXT_CHANGE
6956 */
6957 
6958 procedure del_updt_entries_for_dates (p_assignment_id        in number,
6959                                     p_jurisdiction_code    in varchar2,
6960                                     p_session_date         in date,
6961                                     p_new_start_date       in date,
6962                                     p_new_end_date         in date,
6963                                     p_mode                 in varchar2) is
6964 
6965    l_inp_value_id_table   hr_entry.number_table;
6966    l_scr_value_table      hr_entry.varchar2_table;
6967 
6968    l_element_type_id      number       :=0;
6969    l_inp_name             varchar2(80) :=null;
6970    l_inp_val_id           number       :=0;
6971    l_element_link_id      number       :=0;
6972    l_element_entry_id     number       :=0;
6973    l_effective_start_date date;
6974    l_effective_end_date   date;
6975    l_step                 number;
6976    l_mode                 varchar2(30);
6977 
6978    /* Cursor to get the vertex element type */
6979 
6980    cursor csr_tax_element is
6981        select pet.element_type_id,
6982               piv.input_value_id,
6983               piv.name
6984        from   PAY_INPUT_VALUES_F  piv,
6985               PAY_ELEMENT_TYPES_F pet
6986        where  p_session_date between piv.effective_start_date
6987                              and piv.effective_end_date
6988        and    pet.element_type_id       = piv.element_type_id
6989        and    p_session_date between pet.effective_start_date
6990                              and pet.effective_end_date
6991        and    pet.element_name          = 'VERTEX';
6992 
6993    /* Cursor to get the element entry for the jurisdiction */
6994 
6995    cursor csr_ele_entry (p_element_link number, p_inp_val number)is
6996        select pee.element_entry_id
6997        from   PAY_ELEMENT_ENTRY_VALUES_F pev,
6998               PAY_ELEMENT_ENTRIES_F pee
6999        where  pev.screen_entry_value   = p_jurisdiction_code
7000        and    pev.input_value_id + 0   = p_inp_val
7001        and    p_session_date between pev.effective_start_date
7002                              and pev.effective_end_date
7003        and    pev.element_entry_id     = pee.element_entry_id
7004        and    pee.element_link_id      = p_element_link
7005        and    p_session_date between pee.effective_start_date
7006                              and pee.effective_end_date
7007        and    pee.assignment_id        = p_assignment_id;
7008 
7009 begin
7010 
7011        hr_utility.set_location('pay_emp_dt_tax_rules.del_updt_entries_for_dates' ,1);
7012 
7013        l_step := 1;
7014        open  csr_tax_element;
7015 
7016        loop
7017 
7018           fetch csr_tax_element into l_element_type_id,
7019                                      l_inp_val_id,
7020                                      l_inp_name;
7021 
7022           exit when csr_tax_element%NOTFOUND;
7023 
7024           if upper(l_inp_name) = 'PAY VALUE'
7025           then
7029                l_inp_value_id_table(2) := l_inp_val_id;
7026                l_inp_value_id_table(1) := l_inp_val_id;
7027           elsif upper(l_inp_name) = 'JURISDICTION'
7028           then
7030           elsif upper(l_inp_name) = 'PERCENTAGE'
7031           then
7032                l_inp_value_id_table(3) := l_inp_val_id;
7033           end if;
7034        end loop;
7035 
7036        close csr_tax_element;
7037 
7038        hr_utility.set_location('pay_us_emp_dt_tax_rules.del_updt_entries_for_dates'
7039                                ,2);
7040 
7041        /* Check that all of the input value id for vertex, exists */
7042 
7043        for i in 1..3 loop
7044 
7045            if l_inp_value_id_table(i) = null or
7046               l_inp_value_id_table(i) = 0
7047            then
7048                fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
7049                fnd_message.set_token('1','INPUT VALUE');
7050                fnd_message.raise_error;
7051            end if;
7052 
7053        end loop;
7054 
7055        hr_utility.set_location('pay_us_emp_dt_tax_rules.del_updt_entries_for_dates'
7056                                 ,3);
7057 
7058        /* Get element link */
7059        l_step := 2;
7060        l_element_link_id := hr_entry_api.get_link(
7061                                  P_assignment_id   => p_assignment_id,
7062                                  P_element_type_id => l_element_type_id,
7063                                  P_session_date    => p_session_date);
7064 
7065        if l_element_link_id is null or l_element_link_id = 0
7066        then
7067            fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
7068            fnd_message.set_token('1','ELEMENT LINK');
7069            fnd_message.raise_error;
7070        end if;
7071 
7072        hr_utility.set_location('pay_us_emp_dt_tax_rules.del_updt_entries_for_dates'
7073                                 ,4);
7074 
7075        /* Get the Element Entry Id */
7076        l_step := 3;
7077        open csr_ele_entry(l_element_link_id, l_inp_value_id_table(2));
7078 
7079        fetch csr_ele_entry into l_element_entry_id;
7080 
7081        if csr_ele_entry%NOTFOUND then
7082 
7083           close csr_ele_entry;
7084           fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7085           fnd_message.set_token('PROCEDURE',
7086                        'pay_us_emp_dt_tax_rules.del_updt_entries_for_dates' ||
7087                        '- SQLCODE:'|| to_char(sqlcode));
7088           fnd_message.set_token('STEP',to_char(l_step));
7089           fnd_message.raise_error;
7090 
7091        end if;
7092 
7093        close csr_ele_entry;
7094 
7095        if p_mode = 'U' then
7096 
7097            /* Update Element Entries and Element Entry values as well */
7098 
7099            if p_new_start_date is not null
7100            then
7101 
7102                l_step := 4;
7103                update PAY_ELEMENT_ENTRIES_F
7104                set    effective_start_date = p_new_start_date
7105                where  element_entry_id = l_element_entry_id
7106                and    p_session_date between effective_start_date
7107                       and effective_end_date;
7108 
7109                l_step := 5;
7110                update PAY_ELEMENT_ENTRY_VALUES_F
7111                set    effective_start_date = p_new_start_date
7112                where  element_entry_id = l_element_entry_id
7113                and    p_session_date between effective_start_date
7114                       and effective_end_date;
7115            end if;
7116 
7117            if p_new_end_date is not null
7118            then
7119 
7120                l_step := 6;
7121                update PAY_ELEMENT_ENTRIES_F
7122                set    effective_end_date = p_new_end_date
7123                where  element_entry_id = l_element_entry_id
7124                and    p_session_date between effective_start_date
7125                       and effective_end_date;
7126 
7127                l_step := 7;
7128                update PAY_ELEMENT_ENTRY_VALUES_F
7129                set    effective_end_date = p_new_end_date
7130                where  element_entry_id = l_element_entry_id
7131                and    p_session_date between effective_start_date
7132                       and effective_end_date;
7133            end if;
7134 
7135         elsif p_mode = 'D' then
7136 
7137             /* Delete the element entries */
7138 
7139                l_step := 8;
7140                delete PAY_ELEMENT_ENTRY_VALUES_F
7141                where  element_entry_id = l_element_entry_id
7142                and    p_session_date between effective_start_date
7143                       and effective_end_date;
7144 
7145             /* Delete the element entry values */
7146 
7147                l_step := 9;
7148                delete PAY_ELEMENT_ENTRIES_F
7149                where  element_entry_id = l_element_entry_id
7150                and    p_session_date between effective_start_date
7151                       and effective_end_date;
7152 
7153         elsif p_mode = 'N' then /* Delete next change */
7154 
7155           l_mode := 'DELETE_NEXT_CHANGE';
7156           maintain_element_entry (p_assignment_id     => p_assignment_id,
7157                                  p_effective_start_date => p_session_date,
7158                                  p_effective_end_date   => null,
7159                                  p_session_date         => p_session_date,
7163 
7160                                  p_jurisdiction_code    => p_jurisdiction_code,
7161                                  p_percentage_time      => 0,
7162                                  p_mode                 => l_mode);
7164 
7165         elsif p_mode = 'F' then /* Delete future change */
7166 
7167           l_mode := 'FUTURE_CHANGE';
7168           maintain_element_entry (p_assignment_id     => p_assignment_id,
7169                                  p_effective_start_date => p_session_date,
7170                                  p_effective_end_date   => null,
7171                                  p_session_date         => p_session_date,
7172                                  p_jurisdiction_code    => p_jurisdiction_code,
7173                                  p_percentage_time      => 0,
7174                                  p_mode                 => l_mode);
7175 
7176          end if;
7177 
7178        exception
7179        when others then
7180         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7181         fnd_message.set_token('PROCEDURE',
7182                        'pay_us_emp_dt_tax_rules.del_updt_entries_for_dates' ||
7183                        '- SQLCODE:'|| to_char(sqlcode));
7184         fnd_message.set_token('STEP',to_char(l_step));
7185         fnd_message.raise_error;
7186 
7187 end del_updt_entries_for_dates;
7188 
7189 /* Name      : upd_del_entries
7190    Purpose   : Since we have to update the element entries of all the
7191                jurisdictions, we can get the jurisdictions that are
7192                valid as of the session date. from the tax rules tables.
7193                Then for each of the jurisdiction, we will call the
7194                del_updt_entries_for_dates to change their effective dates.
7195                This rotuine will also be called to delete the element entries
7196                for a specific date range.
7197    Parameters : p_assignment_id -> The assignment id.
7198                 p_session_date  -> The session date for which the element
7199                                     entries have to be updated/deleted.
7200                 p_new_start_date -> The new effective start date to which
7201                                     the effective start date of the records
7202                                     needs to be changed.
7203                 p_new_end_date   -> The new end date for the element entries
7204                                     effective as of the session date.
7205                 p_mode          ->  'U' -> Update
7206                                     'D' -> Delete
7207                                     'F' -> FUTURE_CHANGE (for Delete)
7208                                     'N' -> DELETE_NEXT_CHANGE
7209 */
7210 
7211 procedure upd_del_entries(p_assignment_id     in number,
7212                           p_session_date      in date,
7213                           p_new_start_date    in date,
7214                           p_new_end_date      in date,
7215                           p_mode              in varchar2) is
7216 
7217   l_state_code        varchar2(2);
7218   l_county_code       varchar2(3);
7219   l_city_code         varchar2(4);
7220   l_jurisdiction_code varchar2(11);
7221 
7222   cursor csr_get_states is
7223   select state_code
7224   from   PAY_US_EMP_STATE_TAX_RULES_F str
7225   where  str.assignment_id = p_assignment_id
7226   and    p_session_date between str.effective_start_date
7227          and str.effective_end_date;
7228 
7229   cursor csr_get_counties is
7230   select state_code,
7231          county_code
7232   from   PAY_US_EMP_COUNTY_TAX_RULES_F ctr
7233   where  ctr.assignment_id = p_assignment_id
7234   and    p_session_date between ctr.effective_start_date
7235          and ctr.effective_end_date;
7236 
7237   cursor csr_get_cities is
7238   select state_code,
7239          county_code,
7240          city_code
7241   from   PAY_US_EMP_CITY_TAX_RULES_F ctr
7242   where  ctr.assignment_id = p_assignment_id
7243   and    p_session_date between ctr.effective_start_date
7244          and ctr.effective_end_date;
7245 
7246   begin
7247 
7248        /* First let's handle the state records */
7249 
7250        open csr_get_states;
7251 
7252        loop
7253 
7254           fetch csr_get_states into l_state_code;
7255 
7256           exit when csr_get_states%NOTFOUND;
7257 
7258              /* Update the entries for their effective start and/or
7259                 effective end date */
7260 
7261              l_jurisdiction_code := l_state_code || '-000-0000';
7262              del_updt_entries_for_dates (p_assignment_id    => p_assignment_id,
7263                                     p_jurisdiction_code => l_jurisdiction_code,
7264                                     p_session_date      => p_session_date,
7265                                     p_new_start_date    => p_new_start_date,
7266                                     p_new_end_date      => p_new_end_date,
7267                                     p_mode              => p_mode);
7268        end loop;
7269 
7270        close csr_get_states;
7271 
7272        /* Now grab the counties */
7273 
7274        open csr_get_counties;
7275 
7276        loop
7277 
7278           fetch csr_get_counties into l_state_code,l_county_code;
7279 
7280           exit when csr_get_counties%NOTFOUND;
7281 
7282           /* Update the entries for their effective start and/or
7283              effective end date */
7284 
7285           l_jurisdiction_code := l_state_code || '-' || l_county_code ||
7289                                   p_jurisdiction_code => l_jurisdiction_code,
7286                                   '-0000';
7287 
7288           del_updt_entries_for_dates (p_assignment_id    => p_assignment_id,
7290                                   p_session_date      => p_session_date,
7291                                   p_new_start_date    => p_new_start_date,
7292                                   p_new_end_date      => p_new_end_date,
7293                                   p_mode              => p_mode);
7294 
7295        end loop;
7296 
7297        close csr_get_counties;
7298 
7299        /* Cities time */
7300 
7301        open csr_get_cities;
7302 
7303        loop
7304 
7305           fetch csr_get_cities into l_state_code,l_county_code, l_city_code;
7306 
7307           exit when csr_get_cities%NOTFOUND;
7308 
7309           /* Update the entries for their effective start and/or
7310              effective end date */
7311 
7312           l_jurisdiction_code := l_state_code || '-' || l_county_code ||
7313                                   '-' || l_city_code;
7314 
7315           del_updt_entries_for_dates (p_assignment_id    => p_assignment_id,
7316                                   p_jurisdiction_code => l_jurisdiction_code,
7317                                   p_session_date      => p_session_date,
7318                                   p_new_start_date    => p_new_start_date,
7319                                   p_new_end_date      => p_new_end_date,
7320                                   p_mode              => p_mode);
7321 
7322        end loop;
7323 
7324        close csr_get_cities;
7325 
7326 end upd_del_entries;
7327 
7328 
7329 
7330 /*   Name        : del_updt_wc_entry_for_dates
7331      Purpose     : This procedure can be used to change the effective start date
7332                    and/or effective end date of the workers comp.element
7333                    entry and the pay_element_entry_value, for an assignment. It
7334                    can also be used to delete the workers comp. element entry
7335                    for a given date range.
7336      Parameters  :
7337                  p_assignment_id     -> The assignment for which the workers
7338                                         comp. element entry are to be modified
7339                                         for their start and/or end dates.
7340                   p_session_date     -> The start date of the element entry.
7341                   p_new_start_date   -> The new start date of the element entry.
7342                   p_new_end_date     -> The new end date of the element entry.
7343                   p_mode             -> 'U' -> for update
7344                                         'D' -> for Delete
7345 */
7346 
7347 procedure del_updt_wc_entry_for_dates (p_assignment_id        in number,
7348                                          p_session_date         in date,
7349                                          p_new_start_date       in date,
7350                                          p_new_end_date         in date,
7351                                          p_mode                 in varchar2) is
7352 
7353 
7354    l_element_type_id      number       :=0;
7355    l_element_link_id      number       :=0;
7356    l_element_entry_id     number       :=0;
7357    l_effective_start_date date;
7358    l_effective_end_date   date;
7359    l_step                 number;
7360 
7361    /* Cursor to get the workers comp. element type */
7362 
7363    cursor csr_tax_element is
7364        select pet.element_type_id
7365        from   PAY_ELEMENT_TYPES_F pet
7366        where  pet.element_name = 'Workers Compensation'       -- Bug 3354060 FTS on PAY_ELEMENT_TYPES_F was removed. Done by removing
7367        and    p_session_date between pet.effective_start_date -- 'upper' from pet.element_name and 'WORKERS COMPENSATION' was changed to
7368                              and pet.effective_end_date;      -- 'Workers Compensation'
7369 
7370    /* Cursor to get the element entry for the jurisdiction */
7371 
7372    cursor csr_wc_ele_entry (p_element_link number)is
7373        select pee.element_entry_id
7374        from   PAY_ELEMENT_ENTRIES_F pee
7375        where  pee.assignment_id        = p_assignment_id
7376        and    p_session_date between pee.effective_start_date
7377                              and pee.effective_end_date
7378        and    pee.element_link_id      = p_element_link;
7379 
7380 begin
7381 
7382        hr_utility.set_location('pay_emp_tax_dt_tax_rules.del_updt_wc_entry_for_dates' ,1);
7383 
7384        l_step := 1;
7385        open  csr_tax_element;
7386 
7387           fetch csr_tax_element into l_element_type_id;
7388           if csr_tax_element%NOTFOUND then
7389              fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7390              fnd_message.set_token('PROCEDURE',
7391                      'pay_us_emp_dt_tax_rules.del_updt_wc_entry_for_dates');
7392              fnd_message.set_token('STEP',to_char(l_step));
7393              fnd_message.raise_error;
7394            end if;
7395 
7396        close csr_tax_element;
7397 
7398        hr_utility.set_location('pay_us_emp_dt_tax_rules.del_updt_wc_entry_for_dates' ,2);
7399 
7400        /* Get element link */
7401        l_step := 2;
7402        l_element_link_id := hr_entry_api.get_link(
7403                                  P_assignment_id   => p_assignment_id,
7404                                  P_element_type_id => l_element_type_id,
7405                                  P_session_date    => p_session_date);
7406 
7410            fnd_message.set_token('1','ELEMENT LINK');
7407        if l_element_link_id is null or l_element_link_id = 0
7408        then
7409            fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
7411            fnd_message.raise_error;
7412        end if;
7413 
7414        hr_utility.set_location('pay_us_emp_dt_tax_rules.del_updt_wc_entry_for_dates' ,3);
7415 
7416        /* Get the Element Entry Id */
7417        l_step := 3;
7418        open csr_wc_ele_entry(l_element_link_id);
7419 
7420        fetch csr_wc_ele_entry into l_element_entry_id;
7421 
7422        if csr_wc_ele_entry%NOTFOUND then
7423 
7424           close csr_wc_ele_entry;
7425           fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7426           fnd_message.set_token('PROCEDURE',
7427                      'pay_us_emp_dt_tax_rules.del_updt_wc_entry_for_dates' ||
7428                        '- SQLCODE:'|| to_char(sqlcode));
7429          fnd_message.set_token('STEP',to_char(l_step));
7430          fnd_message.raise_error;
7431 
7432        end if;
7433 
7434        close csr_wc_ele_entry;
7435 
7436        if p_mode = 'U' then
7437 
7438            /* Update Element Entries and Element Entry values as well */
7439 
7440            if p_new_start_date is not null
7441            then
7442 
7443                l_step := 4;
7444                update PAY_ELEMENT_ENTRIES_F
7445                set    effective_start_date = p_new_start_date
7446                where  element_entry_id = l_element_entry_id
7447                and    p_session_date between effective_start_date
7448                       and effective_end_date;
7449 
7450                l_step := 5;
7451                update PAY_ELEMENT_ENTRY_VALUES_F
7452                set    effective_start_date = p_new_start_date
7453                where  element_entry_id = l_element_entry_id
7454                and    p_session_date between effective_start_date
7455                       and effective_end_date;
7456 
7457            end if;
7458 
7459            if p_new_end_date is not null
7460            then
7461 
7462                l_step := 6;
7463                update PAY_ELEMENT_ENTRIES_F
7464                set    effective_end_date = p_new_end_date
7465                where  element_entry_id = l_element_entry_id
7466                and    p_session_date between effective_start_date
7467                       and effective_end_date;
7468 
7469                l_step := 7;
7470                update PAY_ELEMENT_ENTRY_VALUES_F
7471                set    effective_end_date = p_new_end_date
7472                where  element_entry_id = l_element_entry_id
7473                and    p_session_date between effective_start_date
7474                       and effective_end_date;
7475            end if;
7476 
7477         elsif p_mode = 'D' then
7478 
7479             /* Delete the element entry */
7480 
7481                l_step := 8;
7482                delete PAY_ELEMENT_ENTRY_VALUES_F
7483                where  element_entry_id = l_element_entry_id
7484                and    p_session_date between effective_start_date
7485                       and effective_end_date;
7486 
7487             /* Delete the element entry values */
7488 
7489                l_step := 9;
7490                delete PAY_ELEMENT_ENTRIES_F
7491                where  element_entry_id = l_element_entry_id
7492                and    p_session_date between effective_start_date
7493                       and effective_end_date;
7494          end if;
7495 
7496        exception
7497        when others then
7498         fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7499         fnd_message.set_token('PROCEDURE',
7500                      'pay_us_emp_dt_tax_rules.del_updt_wc_entry_for_dates' ||
7501                        '- SQLCODE:'|| to_char(sqlcode));
7502         fnd_message.set_token('STEP',to_char(l_step));
7503         fnd_message.raise_error;
7504 
7505 end del_updt_wc_entry_for_dates;
7506 
7507 
7508 
7509 /*     Name     : change_entries
7510        Purpose  : To create or update the %age tax records for
7511                   all of the existing tax rules records, for a given date
7512                   range i.e. from the p_start_date till p_end_date.
7513                   When this procedure is called with the mode of 'INSERT_OLD'
7514                   the %age passed by this routine to the maintain_element_entry
7515                   routine will not be of any importance because the maintain_element_entry
7516                   routine will do an update insert with the existing %age
7517 */
7518 
7519 procedure change_entries(p_assignment_id in number,
7520                              p_session_date  in date,
7521                              p_start_date    in date,
7522                              p_end_date      in date,
7523                              p_mode          in varchar2) is
7524 
7525   l_state_code     varchar2(2);
7526   l_county_code    varchar2(3);
7527   l_city_code      varchar2(4);
7528   l_jurisdiction_code varchar2(11);
7529 
7530   cursor csr_get_states is
7531   select state_code
7532   from   PAY_US_EMP_STATE_TAX_RULES_F str
7533   where  str.assignment_id = p_assignment_id
7534   and    p_session_date between
7535          str.effective_start_date and str.effective_end_date;
7536 
7537   cursor csr_get_counties is
7538   select state_code,
7539          county_code
7540   from   PAY_US_EMP_COUNTY_TAX_RULES_F ctr
7541   where  ctr.assignment_id = p_assignment_id
7542   and    p_session_date between
7546   select state_code,
7543          ctr.effective_start_date and ctr.effective_end_date;
7544 
7545   cursor csr_get_cities is
7547          county_code,
7548          city_code
7549   from   PAY_US_EMP_CITY_TAX_RULES_F ctr
7550   where  ctr.assignment_id = p_assignment_id
7551   and    p_session_date between
7552          ctr.effective_start_date and ctr.effective_end_date;
7553 
7554   begin
7555 
7556        /* First let's handle the state records */
7557 
7558        open csr_get_states;
7559 
7560        loop
7561 
7562           fetch csr_get_states into l_state_code;
7563 
7564           exit when csr_get_states%NOTFOUND;
7565 
7566           l_jurisdiction_code := l_state_code ||'-000-0000';
7567 
7568           /* change the tax %age record for the state */
7569           maintain_element_entry (p_assignment_id     => p_assignment_id,
7570                                p_effective_start_date => p_start_date,
7571                                p_effective_end_date   => p_end_date,
7572                                p_session_date         => p_session_date,
7573                                p_jurisdiction_code    => l_jurisdiction_code,
7574                                p_percentage_time      => 0,
7575                                p_mode                 => p_mode);
7576 
7577        end loop;
7578 
7579        close csr_get_states;
7580 
7581        /* Now grab the counties */
7582 
7583        open csr_get_counties;
7584 
7585        loop
7586 
7587           fetch csr_get_counties into l_state_code,l_county_code;
7588 
7589           exit when csr_get_counties%NOTFOUND;
7590 
7591           l_jurisdiction_code := l_state_code ||'-' ||
7592                                  l_county_code ||'-0000';
7593 
7594           /* change the tax %age record for the county  */
7595 
7596           maintain_element_entry (p_assignment_id     => p_assignment_id,
7597                                  p_effective_start_date => p_start_date,
7598                                  p_effective_end_date   => p_end_date,
7599                                  p_session_date         => p_session_date,
7600                                  p_jurisdiction_code    => l_jurisdiction_code,
7601                                  p_percentage_time      => 0,
7602                                  p_mode                 => p_mode);
7603 
7604        end loop;
7605 
7606        close csr_get_counties;
7607 
7608        /* Cities time */
7609 
7610        open csr_get_cities;
7611 
7612        loop
7613 
7614           fetch csr_get_cities into l_state_code,l_county_code, l_city_code;
7615 
7616           exit when csr_get_cities%NOTFOUND;
7617 
7618           l_jurisdiction_code := l_state_code ||'-' ||
7619                              l_county_code ||'-' || l_city_code;
7620 
7621           /* change the tax %age record for the city  */
7622 
7623           maintain_element_entry (p_assignment_id     => p_assignment_id,
7624                                  p_effective_start_date => p_start_date,
7625                                  p_effective_end_date   => p_end_date,
7626                                  p_session_date         => p_session_date,
7627                                  p_jurisdiction_code    => l_jurisdiction_code,
7628                                  p_percentage_time      => 0,
7629                                  p_mode                 => p_mode);
7630 
7631        end loop;
7632 
7633        close csr_get_cities;
7634 
7635 end change_entries;
7636 
7637 
7638 procedure pull_percentage (p_assignment_id        in number,
7639                            p_default_date         in date,
7640                            p_effective_start_date in date,
7641                            p_effective_end_date   in date,
7642                            p_session_date         in date,
7643                            p_new_location_id      in number,
7644                            p_business_group_id    in number) is
7645 
7646   l_ret_code              number;
7647   l_ret_text              varchar2(240);
7648   l_next_date             date;
7649   l_next_location         number;
7650   l_ovrd_loc              number;
7651   l_ovrd_percent          number := 0;
7652   l_percent               number := 100;
7653   l_validation_start_date date;
7654   l_validation_end_date   date;
7655   l_next_end_date         date;
7656   l_element_type_id       number;
7657   l_element_link_id       number;
7658 
7659   /* cursor to get the next location */
7660 
7661   cursor csr_get_next_location (p_next_eff_date date) is
7662   select paf.location_id, paf.effective_end_date
7663   from   PER_ASSIGNMENTS_F paf
7664   where  paf.assignment_id = p_assignment_id
7665          and p_next_eff_date between paf.effective_start_date
7666          and paf.effective_end_date;
7667 
7668    /* Get the Vertex element type */
7669    cursor csr_tax_element is
7670        select pet.element_type_id
7671        from   PAY_ELEMENT_TYPES_F pet
7672        where  pet.element_name          = 'VERTEX'
7673        and    p_session_date between pet.effective_start_date
7674                              and pet.effective_end_date;
7675 
7676   /* cursor to get the effective end date of the next element entry record */
7677   cursor csr_get_next_date (p_element_link number, p_date date)is
7678        select pee.effective_end_date
7679        from   PAY_ELEMENT_ENTRIES_F pee
7680        where  pee.assignment_id        = p_assignment_id
7684        and rownum < 2;
7681        and    p_date between pee.effective_start_date
7682                              and pee.effective_end_date
7683        and    pee.element_link_id      = p_element_link
7685 
7686     cursor csr_get_ovrd_loc(p_assignment number, p_session_dt date) is
7687     select nvl(hsck.segment18, paf.location_id)
7688     from   HR_SOFT_CODING_KEYFLEX hsck,
7689            PER_ASSIGNMENTS_F      paf
7690     where  paf.assignment_id = p_assignment
7691     and    p_session_dt between paf.effective_start_date
7692                      and paf.effective_end_date
7693     and    hsck.soft_coding_keyflex_id = paf.soft_coding_keyflex_id;
7694 
7695   begin
7696 
7697           l_validation_start_date := p_effective_start_date;
7698 
7699           /* Get the location of the assignment as of the default date */
7700           open csr_get_next_location(p_default_date);
7701           fetch csr_get_next_location into l_next_location, l_next_end_date;
7702           if csr_get_next_location%NOTFOUND
7703           then
7704              close csr_get_next_location;
7705              fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7706              fnd_message.set_token('PROCEDURE',
7707                    'pay_us_emp_dt_tax_rules.pull_percentage');
7708              fnd_message.set_token('STEP','1');
7709              fnd_message.raise_error;
7710             end if;
7711 
7712            close csr_get_next_location;
7713 
7714            if l_next_location <> p_new_location_id then
7715 
7716               l_validation_end_date := p_effective_end_date;
7717 
7718 
7719               /* Pull back the effective start date of the existing %age records to
7720                  the validation start date */
7721               upd_del_entries(p_assignment_id  => p_assignment_id,
7722                              p_session_date   => p_default_date,
7723                              p_new_start_date => l_validation_start_date,
7724                              p_new_end_date   => null,
7725                              p_mode           => 'U');
7726 
7727               /* Do an update insert for the existing %age records with the same %age */
7728 
7729               change_entries(p_assignment_id     => p_assignment_id,
7730                              p_session_date      => p_default_date,
7731                              p_start_date        => l_validation_start_date,
7732                              p_end_date          => l_next_end_date,
7733                              p_mode              => 'INSERT_OLD');
7734 
7735               /* Zero out the time for the existing %age records for l_validation_start_date and
7736                  p_effective_end_date */
7737 
7738               zero_out_time(p_assignment_id       => p_assignment_id,
7739                           p_effective_start_date  => l_validation_start_date,
7740                           p_effective_end_date    => l_validation_end_date);
7741 
7742               /* Create %age records for the new location, for
7743                  every change in location */
7744 
7745               l_ovrd_percent := 0;
7746               l_percent := 100;
7747               open csr_get_ovrd_loc(p_assignment_id, p_session_date);
7748               fetch csr_get_ovrd_loc into l_ovrd_loc;
7749               if csr_get_ovrd_loc%found then
7750                  if l_ovrd_loc <> p_new_location_id then
7751                     l_ovrd_percent := 100;
7752                     l_percent := 0;
7753                  end if;
7754               end if;
7755               close csr_get_ovrd_loc;
7756 
7757               create_new_location_rec(p_assignment_id  => p_assignment_id,
7758                           p_validation_start_date => l_validation_start_date,
7759                           p_validation_end_date   => l_validation_end_date,
7760                           p_session_date          => p_session_date,
7761                           p_new_location_id       => p_new_location_id,
7762                           p_res_state_code        => null,
7763                           p_res_county_code       => null,
7764                           p_res_city_code         => null,
7765                           p_business_group        => p_business_group_id,
7766                           p_percent               => l_percent);
7767 
7768                  if l_ovrd_percent = 100 then
7769                     create_new_location_rec(p_assignment_id  => p_assignment_id,
7770                           p_validation_start_date => l_validation_start_date,
7771                           p_validation_end_date   => l_validation_end_date,
7772                           p_session_date          => p_session_date,
7773                           p_new_location_id       => l_ovrd_loc,
7774                           p_res_state_code        => null,
7775                           p_res_county_code       => null,
7776                           p_res_city_code         => null,
7777                           p_business_group        => p_business_group_id,
7778                           p_percent               => l_ovrd_percent);
7779                  end if;
7780 
7781           else  /* next location = p_new_location_id */
7782 
7783             /* get the end date of the entries corresponding to the default
7784                 date as the effective start date */
7785 
7786 
7787             open csr_tax_element;
7788             fetch csr_tax_element into l_element_type_id;
7789             if csr_tax_element%NOTFOUND then
7790                 close csr_tax_element;
7791                 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7792                 fnd_message.set_token('PROCEDURE',
7796             end if;
7793                         'pay_us_emp_dt_tax_rules.pull_percentage');
7794                 fnd_message.set_token('STEP','2');
7795                 fnd_message.raise_error;
7797             close csr_tax_element;
7798 
7799             /* Get element link */
7800             l_element_link_id := hr_entry_api.get_link(
7801                                  P_assignment_id   => p_assignment_id,
7802                                  P_element_type_id => l_element_type_id,
7803                                  P_session_date    => p_session_date);
7804 
7805             if l_element_link_id is null or l_element_link_id = 0
7806             then
7807                 fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
7808                 fnd_message.set_token('1','VERTEX');
7809                 fnd_message.raise_error;
7810             end if;
7811 
7812             open csr_get_next_date(l_element_link_id, p_default_date);
7813             fetch csr_get_next_date into l_validation_end_date;
7814             if csr_get_next_date%NOTFOUND
7815             then
7816                 close csr_get_next_date;
7817                 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7818                 fnd_message.set_token('PROCEDURE',
7819                    'pay_us_emp_dt_tax_rules.pull_percentage');
7820                 fnd_message.set_token('STEP','3');
7821                 fnd_message.raise_error;
7822             end if;
7823 
7824             close csr_get_next_date;
7825 
7826 
7827             /* set the effective start date of the entries to the
7828               new effective start date i.e. the l_validation_start_date */
7829 
7830             upd_del_entries(p_assignment_id  => p_assignment_id,
7831                             p_session_date   => p_default_date,
7832                             p_new_start_date => l_validation_start_date,
7833                             p_new_end_date   => null,
7834                             p_mode           => 'U');
7835 
7836             /* inserting rec for all jurisdcitions for the new date
7837                range */
7838             zero_out_time(p_assignment_id         => p_assignment_id,
7839                           p_effective_start_date  => l_validation_start_date,
7840                           p_effective_end_date    => l_validation_end_date);
7841 
7842             /* Create the tax rules records and the %age records for the
7843                new location - if required and set the city %age to 100 */
7844 
7845               l_ovrd_percent := 0;
7846               l_percent := 100;
7847               open csr_get_ovrd_loc(p_assignment_id, p_session_date);
7848               fetch csr_get_ovrd_loc into l_ovrd_loc;
7849               if csr_get_ovrd_loc%found then
7850                  if l_ovrd_loc <> p_new_location_id then
7851                     l_ovrd_percent := 100;
7852                     l_percent := 0;
7853                  end if;
7854               end if;
7855               close csr_get_ovrd_loc;
7856 
7857             create_new_location_rec(p_assignment_id   => p_assignment_id,
7858                             p_validation_start_date => l_validation_start_date,
7859                             p_validation_end_date  => l_validation_end_date,
7860                             p_session_date         => p_session_date,
7861                             p_new_location_id      => p_new_location_id,
7862                             p_res_state_code       => null,
7863                             p_res_county_code      => null,
7864                             p_res_city_code        => null,
7865                             p_business_group       => p_business_group_id,
7866                             p_percent              => l_percent);
7867                  if l_ovrd_percent = 100 then
7868                     create_new_location_rec(p_assignment_id  => p_assignment_id,
7869                           p_validation_start_date => l_validation_start_date,
7870                           p_validation_end_date   => l_validation_end_date,
7871                           p_session_date          => p_session_date,
7872                           p_new_location_id       => l_ovrd_loc,
7873                           p_res_state_code        => null,
7874                           p_res_county_code       => null,
7875                           p_res_city_code         => null,
7876                           p_business_group        => p_business_group_id,
7877                           p_percent               => l_ovrd_percent);
7878 
7879                  end if;
7880 
7881 
7882 
7883          end if;
7884 
7885 end pull_percentage;
7886 
7887 
7888 /* Name    : correct_percentage
7889    Purpose : This is a nasty little procedure which is ideally
7890              supposed to handle the tax rows for a 'correction'
7891              to the assignment's location.
7892 */
7893 
7894 procedure correct_percentage (p_assignment_id        in number,
7895                               p_effective_start_date in date,
7896                               p_effective_end_date   in date,
7897                               p_session_date         in date,
7898                               p_new_location_id      in number,
7899                               p_business_group_id    in number,
7900                               p_ret_code             in out nocopy number,
7901                               p_ret_text             in out nocopy varchar2) is
7902 
7903 
7904   l_default_date      date;
7905   l_end_of_time       date := to_date('31/12/4712','dd/mm/yyyy');
7906   l_ret_code          number;
7907   l_ret_text          varchar2(240);
7911   l_pef_prev_date     date;
7908   l_pef_start_date    date;
7909   l_pef_new_start_date    date;
7910   l_pef_end_date      date;
7912   l_pef_next_date     date;
7913   l_next_location     number;
7914   l_next_loc_end_date date;
7915   l_payroll_installed boolean := FALSE;
7916   l_termination_flag   boolean := FALSE;
7917   l_validation_start_date date;
7918   l_validation_end_date   date;
7919   l_element_type_id   number;
7920   l_element_link_id   number;
7921   l_ovrd_loc          number;
7922   l_ovrd_percent      number;
7923   l_percent      number;
7924   /* Cursor to get the date on which the defaulting tax criteria was
7925      satisfied */
7926 
7927   cursor csr_get_eff_date (passignment number) is
7928   select min(ftr.effective_start_date)
7929   from PAY_US_EMP_FED_TAX_RULES_F ftr
7930   where ftr.assignment_id = passignment;
7931 
7932   /* Cursor to get the changes in assignment which in turn will help us
7933      in identifying the change in locations that has taken place within
7934      a given date range */
7935 
7936   cursor csr_get_locations (passignment number, p_start_date date,
7937                             p_end_date date) is
7938     select paf1.location_id,
7939            paf1.effective_start_date,
7940            paf1.effective_start_date - 1
7941     from per_assignments_f paf1
7942     where paf1.assignment_id = passignment
7943     and paf1.effective_start_date >= p_start_date
7944     and paf1.effective_end_date <= p_end_date
7945     order by 2;
7946 
7947 
7948    /* Get the Vertex element type */
7949    cursor csr_tax_element is
7950        select pet.element_type_id
7951        from   PAY_ELEMENT_TYPES_F pet
7952        where  pet.element_name          = 'VERTEX'
7953        and    p_session_date between pet.effective_start_date
7954                              and pet.effective_end_date;
7955 
7956    /* Cursor to check for multiple date effective records of the vertex
7957       element entries */
7958    cursor csr_multiple_rec(p_def_date date, p_ele_link number) is
7959       select 'Y'
7960       from pay_element_entries_f pef
7961       where pef.assignment_id = p_assignment_id
7962       and   pef.element_link_id = p_ele_link
7963       and   pef.effective_start_date >= p_def_date
7964       and   exists (select null
7965                     from pay_element_entries_f pee
7966                     where pee.assignment_id = p_assignment_id
7967                     and   pee.element_entry_id = pef.element_entry_id
7968                     and   pee.effective_start_date >= p_def_date
7969                     and   pee.effective_start_date <> pef.effective_start_date);
7970 
7971    /* Cursor to get the effective dates of the vertex element entries */
7972 
7973    cursor csr_ele_entry (p_element_link number)is
7974        select pee.effective_start_date,
7975              pee.effective_end_date,
7976              pee.effective_start_date -1
7977        from   PAY_ELEMENT_ENTRIES_F pee
7978        where  pee.assignment_id        = p_assignment_id
7979        and    p_session_date between pee.effective_start_date
7980                              and pee.effective_end_date
7981        and    pee.element_link_id      = p_element_link
7982        and rownum < 2;
7983 
7984   /* cursor to get the next location */
7985 
7986   cursor csr_get_next_location (p_next_eff_date date) is
7987   select paf.location_id
7988   from   PER_ASSIGNMENTS_F paf
7989   where  paf.assignment_id = p_assignment_id and
7990          p_next_eff_date between paf.effective_start_date
7991          and paf.effective_end_date;
7992 
7993 
7994 
7995   /* cursor to get the effective end date of the next element entry record */
7996   cursor csr_get_next_date (p_element_link number, p_date date)is
7997        select pee.effective_end_date
7998        from   PAY_ELEMENT_ENTRIES_F pee
7999        where  pee.assignment_id        = p_assignment_id
8000        and    p_date between pee.effective_start_date
8001                              and pee.effective_end_date
8002        and    pee.element_link_id      = p_element_link
8003        and rownum < 2;
8004 
8005     cursor csr_get_ovrd_loc(p_assignment number, p_session_dt date) is
8006     select nvl(hsck.segment18, paf.location_id)
8007     from   HR_SOFT_CODING_KEYFLEX hsck,
8008            PER_ASSIGNMENTS_F      paf
8009     where  paf.assignment_id = p_assignment
8010     and    p_session_dt between paf.effective_start_date
8011                      and paf.effective_end_date
8012     and    hsck.soft_coding_keyflex_id = paf.soft_coding_keyflex_id;
8013 
8014    procedure backward_processing(p_assignment           in number,
8015                                  p_eff_start_date       in date,
8016                                  p_validation_start_date in out nocopy date,
8017                                  p_new_location         in number,
8018                                  p_element_link         in number) is
8019 
8020    l_prev_location         number := 0;
8021    l_prev_processing       boolean := FALSE;
8022    l_eff_prev_date         date;
8023    l_validation_start_date date;
8024 
8025    /* cursor to get the previous location */
8026 
8027    cursor csr_get_prev_location (p_prev_eff_date date) is
8028    select paf.location_id
8029    from   PER_ASSIGNMENTS_F paf
8030    where  paf.assignment_id = p_assignment and
8031           p_prev_eff_date between paf.effective_start_date
8032           and paf.effective_end_date;
8033 
8034    /* cursor to get the effective start date of the previous element entry record */
8038        where  pee.assignment_id        = p_assignment
8035    cursor csr_get_prev_date (p_element_link number, p_date date)is
8036        select pee.effective_start_date
8037        from   PAY_ELEMENT_ENTRIES_F pee
8039        and    pee.element_link_id      = p_element_link
8040        and    p_date between pee.effective_start_date
8041                              and pee.effective_end_date
8042        and rownum < 2;
8043 
8044    begin
8045 
8046           l_validation_start_date := p_validation_start_date;
8047 
8048          /* Get the effective_end_date of the previous
8049             assignment record */
8050          select p_eff_start_date -1
8051          into   l_eff_prev_date
8052          from dual;
8053 
8054          /* get the previous location of the assignment */
8055 
8056          open csr_get_prev_location(l_eff_prev_date);
8057          fetch csr_get_prev_location into l_prev_location;
8058          if csr_get_prev_location%FOUND then
8059          l_prev_processing := TRUE;
8060          else
8061          l_prev_processing := FALSE;
8062          end if;
8063 
8064          close csr_get_prev_location;
8065 
8066          if l_prev_processing and l_prev_location = p_new_location then
8067 
8068             l_validation_start_date := null;
8069 
8070             /* get the effective start date of the previous set of %age records */
8071 
8072             open csr_get_prev_date(p_element_link,l_eff_prev_date);
8073             fetch csr_get_prev_date into l_validation_start_date;
8074             if csr_get_prev_date%NOTFOUND then
8075                close csr_get_prev_date;
8076                fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8077                fnd_message.set_token('PROCEDURE',
8078                            'pay_us_emp_dt_tax_rules.backward_processing');
8079                fnd_message.set_token('STEP','1');
8080                fnd_message.raise_error;
8081              end if;
8082 
8083              /* deleting the previous set */
8084 
8085              upd_del_entries(p_assignment_id  => p_assignment_id,
8086                             p_session_date   => l_validation_start_date,
8087                             p_new_start_date => null,
8088                             p_new_end_date   => null,
8089                             p_mode           => 'D');
8090 
8091              /* Pull back the effective start date of the current set */
8092 
8093              upd_del_entries(p_assignment_id  => p_assignment_id,
8094                          p_session_date   => p_eff_start_date,
8095                          p_new_start_date => l_validation_start_date,
8096                          p_new_end_date   => null,
8097                          p_mode           => 'U');
8098 
8099               /* Assign the new validation start date */
8100 
8101               p_validation_start_date := l_validation_start_date;
8102 
8103           end if;
8104 
8105    end backward_processing;
8106 
8107   begin
8108 
8109   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',1);
8110     l_payroll_installed := hr_utility.chk_product_install(p_product => 'Oracle Payroll',
8111                                                           p_legislation => 'US');
8112 
8113     /* Get effective Start date of the Federal Tax Rules record */
8114 
8115   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',2);
8116     open  csr_get_eff_date(p_assignment_id);
8117 
8118     fetch csr_get_eff_date into l_default_date;
8119 
8120     if l_default_date is null then
8121          close csr_get_eff_date;
8122          fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8123          fnd_message.set_token('PROCEDURE',
8124                  'pay_us_emp_dt_tax_rules.correct_percentage');
8125          fnd_message.set_token('STEP','1');
8126          fnd_message.raise_error;
8127     end if;
8128 
8129     close csr_get_eff_date;
8130 
8131   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',3);
8132     open csr_tax_element;
8133     fetch csr_tax_element into l_element_type_id;
8134     if csr_tax_element%NOTFOUND then
8135        close csr_tax_element;
8136        fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8137        fnd_message.set_token('PROCEDURE',
8138                  'pay_us_emp_dt_tax_rules.correct_percentage');
8139        fnd_message.set_token('STEP','2');
8140        fnd_message.raise_error;
8141     end if;
8142     close csr_tax_element;
8143 
8144   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',4);
8145     /* Get element link */
8146     l_element_link_id := hr_entry_api.get_link(
8147                              P_assignment_id   => p_assignment_id,
8148                              P_element_type_id => l_element_type_id,
8149                              P_session_date    => p_session_date);
8150 
8151     if l_element_link_id is null or l_element_link_id = 0 then
8152         fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
8153         fnd_message.set_token('1','VERTEX');
8154         fnd_message.raise_error;
8155     end if;
8156 
8157 
8158     /* Let's handle the condition where there is just one set of
8159        %age records - from the default date till end of time or the
8160        termination date.
8161 
8162             | Session date
8163             v
8164          T1        L1
8165     Asg  |----------------------------------------
8166     SL1  |----------------------------------------
8167     COL1 |----------------------------------------
8171             v
8168     CIL1 |----------------------------------------
8169 
8170             | Session date
8172          T1   T2    L1
8173     Asg  |----------------------------------------
8174     SL1       |----------------------------------------
8175     COL1      |----------------------------------------
8176     CIL1      |----------------------------------------
8177 
8178     The assignment record has not been broken up and L1 is corrected
8179     to L2. In the first scenario the defaulting criteria had been met as of the
8180     assignment effective start date. So, the tax records were created from time
8181     T1 i.e. the effective start date of the assignment. However, in the second case
8182     the defaulting criteria was met as of the date T2. So the tax records were created
8183     as of date T2 */
8184 
8185     if (p_effective_start_date <= l_default_date and
8186         p_effective_end_date   = l_end_of_time) then
8187   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',5);
8188 
8189         if l_payroll_installed then
8190           /* Get all of the percentage records and set the percentage to zero */
8191 
8192   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',6);
8193           zero_out_time(p_assignment_id         => p_assignment_id,
8194                         p_effective_start_date  => p_effective_start_date,
8195                         p_effective_end_date    => p_effective_end_date);
8196         end if;
8197 
8198         /* Create the tax rules records and the %age records for the
8199            new location - if required and set the city %age to 100 */
8200 
8201   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',7);
8202 
8203         l_ovrd_percent := 0;
8204         l_percent := 100;
8205         open csr_get_ovrd_loc(p_assignment_id, p_session_date);
8206         fetch csr_get_ovrd_loc into l_ovrd_loc;
8207         if csr_get_ovrd_loc%found then
8208            if l_ovrd_loc <> p_new_location_id then
8209             l_ovrd_percent := 100;
8210             l_percent := 0;
8211            end if;
8212         end if;
8213         close csr_get_ovrd_loc;
8214 
8215   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',8);
8216         create_new_location_rec(p_assignment_id    => p_assignment_id,
8217                              p_validation_start_date => p_effective_start_date,
8218                              p_validation_end_date   => p_effective_end_date,
8219                              p_session_date          => p_session_date,
8220                              p_new_location_id       => p_new_location_id,
8221                              p_res_state_code        => null,
8222                              p_res_county_code       => null,
8223                              p_res_city_code         => null,
8224                              p_business_group        => p_business_group_id,
8225                              p_percent               => l_percent);
8226   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',9);
8227         if l_ovrd_percent = 100 then
8228   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',10);
8229            create_new_location_rec(p_assignment_id  => p_assignment_id,
8230                           p_validation_start_date => p_effective_start_date,
8231                           p_validation_end_date   => p_effective_end_date,
8232                           p_session_date          => p_session_date,
8233                           p_new_location_id       => l_ovrd_loc,
8234                           p_res_state_code        => null,
8235                           p_res_county_code       => null,
8236                           p_res_city_code         => null,
8237                           p_business_group        => p_business_group_id,
8238                           p_percent               => l_ovrd_percent);
8239   hr_utility.set_location('pay_us_emp_dt_tax_rules.correct_percentage',11);
8240         end if;
8241 
8242 
8243     else /* multiple locations */
8244 
8245        /* Get the effective start date, effective end date and (effective start date - 1)
8246           of the %age record for the session date */
8247 
8248        open  csr_ele_entry(l_element_link_id);
8249 
8250        fetch csr_ele_entry into l_pef_start_date, l_pef_end_date,
8251                                 l_pef_prev_date;
8252 
8253        if csr_ele_entry%NOTFOUND then
8254            close csr_ele_entry;
8255            fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8256            fnd_message.set_token('PROCEDURE',
8257                    'pay_us_emp_dt_tax_rules.correct_percentage');
8258            fnd_message.set_token('STEP','2');
8259            fnd_message.raise_error;
8260        end if;
8261 
8262        close csr_ele_entry;
8263 
8264        /* Set the validation start date */
8265 
8266        if p_effective_start_date >= l_pef_start_date then
8267            l_validation_start_date := p_effective_start_date;
8268        else
8269            l_validation_start_date := l_pef_start_date;
8270        end if;
8271 
8272        /* Time to take care of the multiple assignment records scenario
8273           - assignment end date less than the element entries end date
8274 
8275                 | Session Date
8276                 V
8277              L1     L1
8278        Asg  |----|-------------------------------------------
8279 
8280        %age |------------------------------------------------
8281 
8282                 | Session Date
8283                 V
8287        %age |------------|---------------|-------|-----------
8284              L1     L1     L2         L2   L1      L3
8285        Asg  |----|-------|-----------|---|-------|-----------
8286 
8288 
8289                                  | Session Date
8290                                  V
8291              L1     L1     L2     L2   L2   L1      L3
8292        Asg  |----|-------|-----|------|--|-------|-----------
8293 
8294        %age |------------|---------------|-------|-----------
8295 
8296                             | Session Date
8297                             V
8298              L1     L1     L2     L2   L2   L1      L3
8299        Asg  |----|-------|-----|------|--|-------|-----------
8300 
8301        %age |------------|---------------|-------|-----------
8302 
8303                 | Session Date
8304                 V
8305              L1     L1     L2         L2   L1      L3
8306        Asg  |----|-------|-----------|---|-------|-----------
8307 
8308        %age    |---------|---------------|-------|-----------
8309 
8310        if the effective start date of the assignment record is less than
8311        or equal to the minimum of effective start date (i.e. the default date )
8312        of the vertex element entries then only the forward processing is required.
8313        However, if the effective start date of the assignment is equal to the
8314        effective start date of the element entries and the effective start date of the
8315        element entries is not the default date then the backward processing is also
8316        required .
8317        */
8318 
8319 
8320         if p_effective_end_date < l_pef_end_date then
8321 
8322           /* Forward processing */
8323 
8324           l_validation_end_date := p_effective_end_date;
8325 
8326           /* Get the effective start date of the next assignment record */
8327           select p_effective_end_date + 1
8328           into   l_pef_new_start_date
8329           from   sys.DUAL;
8330 
8331           /* Do an update insert for the same %age as of the l_pef_new_start_date */
8332           change_entries(p_assignment_id     => p_assignment_id,
8333                          p_session_date      => l_pef_new_start_date,
8334                          p_start_date        => l_pef_start_date,
8335                          p_end_date          => l_pef_end_date,
8336                          p_mode              => 'INSERT_OLD');
8337 
8338           if p_effective_start_date > l_pef_start_date then
8339 
8340              /*
8341                          | Session Date
8342                          V
8343                     L1   L1  L1   L2         L2   L1      L3
8344              Asg  |----|----|--|-----------|---|-------|-----------
8345 
8346              %age |------------|---------------|-------|-----------
8347              */
8348 
8349              /* Do an update insert for the same %age as of the l_validation_start_date */
8350 
8351              change_entries(p_assignment_id     => p_assignment_id,
8352                             p_session_date      => l_validation_start_date,
8353                             p_start_date        => l_pef_start_date,
8354                             p_end_date          => l_validation_end_date,
8355                             p_mode              => 'INSERT_OLD');
8356 
8357           elsif p_effective_start_date = l_pef_start_date and
8358                 l_pef_start_date <> l_default_date then
8359 
8360                 /*
8361                                      | Session Date
8362                                      V
8363                       L1     L1     L2     L2   L2   L1      L3
8364                 Asg  |----|-------|-----|------|--|-------|-----------
8365 
8366                 %age |------------|---------------|-------|-----------
8367 
8368                 */
8369 
8370                 /* Backward processing */
8371 
8372                 backward_processing(p_assignment        => p_assignment_id,
8373                                  p_eff_start_date       => p_effective_start_date,
8374                                  p_validation_start_date => l_validation_start_date,
8375                                  p_new_location         => p_new_location_id,
8376                                  p_element_link         => l_element_link_id);
8377           end if;
8378 
8379           /* set the %age for all of the existing %age records to zero for the
8380              l_validation_start_date and l_validation_end_date */
8381 
8382           zero_out_time(p_assignment_id     => p_assignment_id,
8383                     p_effective_start_date  => l_validation_start_date,
8384                     p_effective_end_date    => l_validation_end_date);
8385 
8386           /* create %age records for the new location, for every change in location
8387              of an assignment */
8388 
8389           l_ovrd_percent := 0;
8390           l_percent := 100;
8391           open csr_get_ovrd_loc(p_assignment_id, p_session_date);
8392           fetch csr_get_ovrd_loc into l_ovrd_loc;
8393           if csr_get_ovrd_loc%found then
8394              if l_ovrd_loc <> p_new_location_id then
8395                 l_ovrd_percent := 100;
8396                 l_percent := 0;
8397               end if;
8398           end if;
8399           close csr_get_ovrd_loc;
8400 
8401           create_new_location_rec(p_assignment_id         => p_assignment_id,
8402                                   p_validation_start_date => l_validation_start_date,
8403                                   p_validation_end_date   => l_validation_end_date,
8407                                   p_res_county_code       => null,
8404                                   p_session_date          => p_session_date,
8405                                   p_new_location_id       => p_new_location_id,
8406                                   p_res_state_code        => null,
8408                                   p_res_city_code         => null,
8409                                   p_business_group        => p_business_group_id,
8410                                   p_percent               => l_percent);
8411         if l_ovrd_percent = 100 then
8412            create_new_location_rec(p_assignment_id  => p_assignment_id,
8413                           p_validation_start_date => l_validation_start_date,
8414                           p_validation_end_date   => l_validation_end_date,
8415                           p_session_date          => p_session_date,
8416                           p_new_location_id       => l_ovrd_loc,
8417                           p_res_state_code        => null,
8418                           p_res_county_code       => null,
8419                           p_res_city_code         => null,
8420                           p_business_group        => p_business_group_id,
8421                           p_percent               => l_ovrd_percent);
8422         end if;
8423 
8424 
8425           /* The effective end date of the location record is same as the
8426              effective end date of the corresponding %age record.
8427 
8428                       | Session Date
8429                       V
8430                 L1     L1     L2         L2   L1      L3
8431           Asg  |----|-------|-----------|---|-------|-----------
8432 
8433           %age |------------|---------------|-------|-----------
8434 
8435                                                       | Session Date
8436                                                       V
8437                 L1     L1     L2         L2   L1      L1
8438           Asg  |----|-------|-----------|---|-------|-----------
8439 
8440           %age |------------|---------------|-------------------
8441 
8442 
8443           */
8444 
8445         elsif p_effective_end_date = l_pef_end_date then
8446 
8447           l_validation_start_date := p_effective_start_date;
8448           l_validation_end_date := l_pef_end_date;
8449 
8450           if l_pef_end_date <> l_end_of_time then
8451 
8452              select l_validation_end_date + 1
8453              into l_pef_next_date
8454              from SYS.DUAL;
8455 
8456              /* Get the next location of the assignment */
8457              open csr_get_next_location(l_pef_next_date);
8458              fetch csr_get_next_location into l_next_location;
8459              if csr_get_next_location%NOTFOUND
8460              then
8461                 l_termination_flag := TRUE;
8462              else
8463                 l_termination_flag := FALSE;
8464              end if;
8465              close csr_get_next_location;
8466 
8467           end if;
8468 
8469 
8470           /* The effective end date of the location record is same as the
8471               effective end date of the corresponding %age record. However
8472               the assignment has been terminated or is till end of time.
8473 
8474                                                 | Session Date
8475                                                 V
8476                    L1     L1     L2         L2   L1
8477             Asg  |----|-------|-----------|---|-------|
8478 
8479             %age |------------|---------------|-------|
8480 
8481                                                   | Session Date
8482                                                   V
8483                    L1     L1     L2         L2    L1
8484             Asg  |----|-------|-----------|-----|-----|
8485 
8486             %age |------------|---------------|-------|
8487 
8488                                                 | Session Date
8489                                                 V
8490                    L1     L1     L2         L2   L1
8491             Asg  |----|-------|-----------|---|-------
8492 
8493             %age |------------|---------------|-------
8494 
8495                                                   | Session Date
8496                                                   V
8497                    L1     L1     L2         L2    L1
8498             Asg  |----|-------|-----------|-----|-----
8499 
8500             %age |------------|---------------|-------
8501 
8502 
8503             We can possibly have 2 scenarios of effective start date -
8504             p_effective start date = l_pef_effective_start_date or
8505             p_effective start date > l_pef_effective_start_date
8506             We can not have the scenario of
8507             p_effective start date < l_pef_effective_start_date under this
8508             condition. Only in the case of the first %age record , we might
8509             have this scenario when the tax %age records get created from a
8510             date later than the assignment's start date
8511            */
8512 
8513             if (l_termination_flag or l_pef_end_date = l_end_of_time) then
8514 
8515               if p_effective_start_date > l_pef_start_date then
8516 
8517                   if l_termination_flag then
8518 
8519                      /* Do an update insert as of the l_validation_start_date */
8520 
8521                      change_entries(p_assignment_id     => p_assignment_id,
8522                                     p_session_date      => l_validation_start_date,
8526 
8523                                     p_start_date        => l_pef_start_date,
8524                                     p_end_date          => l_pef_end_date,
8525                                     p_mode              => 'UPDATE_CHANGE_INSERT');
8527                   elsif l_pef_end_date = l_end_of_time then
8528 
8529                      /* Do an update as of the l_validation_start_date */
8530 
8531                      change_entries(p_assignment_id     => p_assignment_id,
8532                                     p_session_date      => l_validation_start_date,
8533                                     p_start_date        => l_pef_start_date,
8534                                     p_end_date          => l_pef_end_date,
8535                                     p_mode              => 'UPDATE');
8536 
8537                   end if;
8538 
8539                  /* zero out time for the current element entries for
8540                  l_validation_start_date and l_validation_end_date */
8541 
8542                  zero_out_time(p_assignment_id     => p_assignment_id,
8543                            p_effective_start_date  => l_validation_start_date,
8544                            p_effective_end_date    => l_validation_end_date);
8545 
8546 
8547                  /* Create %age records for the new location, for
8548                     every change in location */
8549 
8550                 l_ovrd_percent := 0;
8551                 l_percent := 100;
8552                 open csr_get_ovrd_loc(p_assignment_id, p_session_date);
8553                 fetch csr_get_ovrd_loc into l_ovrd_loc;
8554                 if csr_get_ovrd_loc%found then
8555                    if l_ovrd_loc <> p_new_location_id then
8556                       l_ovrd_percent := 100;
8557                       l_percent := 0;
8558                     end if;
8559                 end if;
8560                 close csr_get_ovrd_loc;
8561 
8562                  create_new_location_rec(p_assignment_id  => p_assignment_id,
8563                           p_validation_start_date => l_validation_start_date,
8564                           p_validation_end_date   => l_validation_end_date,
8565                           p_session_date          => p_session_date,
8566                           p_new_location_id       => p_new_location_id,
8567                           p_res_state_code        => null,
8568                           p_res_county_code       => null,
8569                           p_res_city_code         => null,
8570                           p_business_group        => p_business_group_id,
8571                           p_percent               => l_percent);
8572                   if l_ovrd_percent = 100 then
8573                      create_new_location_rec(p_assignment_id  => p_assignment_id,
8574                           p_validation_start_date => l_validation_start_date,
8575                           p_validation_end_date   => l_validation_end_date,
8576                           p_session_date          => p_session_date,
8577                           p_new_location_id       => l_ovrd_loc,
8578                           p_res_state_code        => null,
8579                           p_res_county_code       => null,
8580                           p_res_city_code         => null,
8581                           p_business_group        => p_business_group_id,
8582                           p_percent               => l_ovrd_percent);
8583                   end if;
8584 
8585               elsif p_effective_start_date = l_pef_start_date then
8586 
8587                 /* Backward processing */
8588                 backward_processing(p_assignment        => p_assignment_id,
8589                                  p_eff_start_date       => p_effective_start_date,
8590                                  p_validation_start_date => l_validation_start_date,
8591                                  p_new_location         => p_new_location_id,
8592                                  p_element_link         => l_element_link_id);
8593 
8594                  /* zero out time for the date range between p_validation_start_date
8595                     and p_validation_end_date */
8596 
8597                  zero_out_time(p_assignment_id     => p_assignment_id,
8598                            p_effective_start_date  => l_validation_start_date,
8599                            p_effective_end_date    => l_validation_end_date);
8600 
8601                  /* Create the tax rules records and the %age records for the
8602                     new location - if required and set the city %age to 100 */
8603 
8604                 l_ovrd_percent := 0;
8605                 l_percent := 100;
8606                 open csr_get_ovrd_loc(p_assignment_id, p_session_date);
8607                 fetch csr_get_ovrd_loc into l_ovrd_loc;
8608                 if csr_get_ovrd_loc%found then
8609                    if l_ovrd_loc <> p_new_location_id then
8610                       l_ovrd_percent := 100;
8611                       l_percent := 0;
8612                     end if;
8613                 end if;
8614                 close csr_get_ovrd_loc;
8615 
8616                  create_new_location_rec(p_assignment_id   => p_assignment_id,
8617                                  p_validation_start_date => l_validation_start_date,
8618                                  p_validation_end_date  => l_validation_end_date,
8619                                  p_session_date         => p_session_date,
8620                                  p_new_location_id      => p_new_location_id,
8621                                  p_res_state_code       => null,
8622                                  p_res_county_code      => null,
8623                                  p_res_city_code        => null,
8627                      create_new_location_rec(p_assignment_id  => p_assignment_id,
8624                                  p_business_group       => p_business_group_id,
8625                                  p_percent              => l_percent);
8626                   if l_ovrd_percent = 100 then
8628                           p_validation_start_date => l_validation_start_date,
8629                           p_validation_end_date   => l_validation_end_date,
8630                           p_session_date          => p_session_date,
8631                           p_new_location_id       => l_ovrd_loc,
8632                           p_res_state_code        => null,
8633                           p_res_county_code       => null,
8634                           p_res_city_code         => null,
8635                           p_business_group        => p_business_group_id,
8636                           p_percent               => l_ovrd_percent);
8637                   end if;
8638 
8639 
8640              end if;  /* check for the p_effective_start_date > or = to the
8641                          l_pef_start_date */
8642 
8643             else /* Not a terminated assignment */
8644 
8645               /* Processing for the condition when next location <> new location.
8646 
8647                           | Session Date
8648                           V
8649                           L1          L2         L2   L1      L3
8650                  Asg  |------------|-----------|---|-------|-----------
8651 
8652                  %age |------------|---------------|-------|-----------
8653 
8654                                                 | Session Date
8655                                                 V
8656                           L1          L2         L2   L1      L3
8657                  Asg  |------------|-----------|---|-------|-----------
8658 
8659                  %age |------------|---------------|-------|-----------
8660 
8661                                                 | Session Date
8662                                                 V
8663                           L1            L2            L1      L3
8664                  Asg  |------------|---------------|-------|-----------
8665 
8666                  %age |------------|---------------|-------|-----------
8667 
8668                             | Session Date
8669                             V
8670                           L1          L2         L2   L1      L3
8671                  Asg  |------------|-----------|---|-------|-----------
8672 
8673                  %age      |-------|---------------|-------|-----------
8674 
8675                  In the above examples if we correct location as of the session date
8676                  to L3 then new location <> next location.
8677                */
8678 
8679                 l_validation_start_date := p_effective_start_date;
8680                 l_validation_end_date := l_pef_end_date;
8681 
8682                 if p_effective_start_date > l_pef_start_date then
8683 
8684                   /*
8685                                                | Session Date
8686                                                V
8687                             L1         L2     L2 (L5)   L3      L4
8688                    Asg  |------------|-------|-- ----|-------|-----------
8689 
8690                    %age |------------|---------------|-------|-----------
8691 
8692 
8693                                                | Session Date
8694                                                V
8695                             L1         L2     L2 (L3)   L3      L4
8696                    Asg  |------------|-------|-- ----|-------|-----------
8697 
8698                    %age |------------|---------------|-------|-----------
8699 
8700                    Note :  L2 (L5) means L2 changed to L5. Similarly
8701                            L2 (L3) means L2 changed to L3.
8702                    */
8703 
8704                    /* Do an update insert as of the l_validation_start_date */
8705 
8706                    change_entries(p_assignment_id     => p_assignment_id,
8707                                   p_session_date      => l_validation_start_date,
8708                                   p_start_date        => l_pef_start_date,
8709                                   p_end_date          => l_pef_end_date,
8710                                   p_mode              => 'UPDATE_CHANGE_INSERT');
8711 
8712                    /* next location = p_new_location_id */
8713 
8714                    if l_next_location = p_new_location_id then
8715 
8716                       /* Processing for the condition when next location = new location.
8717 
8718                                                       | Session Date
8719                                                       V
8720                                 L1          L2         L2   L1      L3
8721                        Asg  |------------|-----------|---|-------|-----------
8722 
8723                        %age |------------|---------------|-------|-----------
8724 
8725                       In the above example if we correct L2 as of the session date
8726                       to L1 then new location = next location.  */
8727 
8728 
8729                       /* Get the end date of the next %age records */
8730                       open csr_get_next_date(l_element_link_id,l_pef_next_date);
8731                       fetch csr_get_next_date into l_next_loc_end_date;
8732                       if csr_get_next_date%NOTFOUND then
8733                          close csr_get_next_date;
8734                          fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8735                          fnd_message.set_token('PROCEDURE',
8739                       end if;
8736                          'pay_us_emp_dt_tax_rules.correct_percentage');
8737                          fnd_message.set_token('STEP','4');
8738                          fnd_message.raise_error;
8740 
8741                       close csr_get_next_date;
8742 
8743                       /* set the validation end date to the end date of the next
8744                          set of %age records */
8745 
8746                       l_validation_end_date   := l_next_loc_end_date;
8747 
8748                       /* deleting the current set */
8749 
8750                       upd_del_entries(p_assignment_id  => p_assignment_id,
8751                                       p_session_date   => l_validation_start_date,
8752                                       p_new_start_date => null,
8753                                       p_new_end_date   => null,
8754                                       p_mode           => 'D');
8755 
8756                       /* Pull  the next set to the p_validation start date */
8757 
8758                       upd_del_entries(p_assignment_id  => p_assignment_id,
8759                                       p_session_date   => l_pef_next_date,
8760                                       p_new_start_date => l_validation_start_date,
8761                                       p_new_end_date   => null,
8762                                       p_mode           => 'U');
8763 
8764                       /* call zero_out_time for p_validation_start_date and
8765                          p_validation_end_date */
8766 
8767                       zero_out_time(p_assignment_id     => p_assignment_id,
8768                                 p_effective_start_date  => l_validation_start_date,
8769                                 p_effective_end_date    => l_validation_end_date);
8770 
8771                    end if;
8772 
8773                    /* Create the tax rules records and the %age records for the
8774                       new location - if required and set the city %age to 100 */
8775 
8776                 l_ovrd_percent := 0;
8777                 l_percent := 100;
8778                 open csr_get_ovrd_loc(p_assignment_id, p_session_date);
8779                 fetch csr_get_ovrd_loc into l_ovrd_loc;
8780                 if csr_get_ovrd_loc%found then
8781                    if l_ovrd_loc <> p_new_location_id then
8782                       l_ovrd_percent := 100;
8783                       l_percent := 0;
8784                     end if;
8785                 end if;
8786                 close csr_get_ovrd_loc;
8787 
8788 
8789                    create_new_location_rec(p_assignment_id   => p_assignment_id,
8790                                      p_validation_start_date => l_validation_start_date,
8791                                       p_validation_end_date  => l_validation_end_date,
8792                                       p_session_date         => p_session_date,
8793                                       p_new_location_id      => p_new_location_id,
8794                                       p_res_state_code       => null,
8795                                       p_res_county_code      => null,
8796                                       p_res_city_code        => null,
8797                                       p_business_group       => p_business_group_id,
8798                                       p_percent              => l_percent);
8799                   if l_ovrd_percent = 100 then
8800                      create_new_location_rec(p_assignment_id  => p_assignment_id,
8801                           p_validation_start_date => l_validation_start_date,
8802                           p_validation_end_date   => l_validation_end_date,
8803                           p_session_date          => p_session_date,
8804                           p_new_location_id       => l_ovrd_loc,
8805                           p_res_state_code        => null,
8806                           p_res_county_code       => null,
8807                           p_res_city_code         => null,
8808                           p_business_group        => p_business_group_id,
8809                           p_percent               => l_ovrd_percent);
8810                   end if;
8811 
8812                 elsif p_effective_start_date = l_pef_start_date then
8813 
8814 
8815                    /*
8816                                                | Session Date
8817                                                V
8818                             L1          L2 (L5)          L3      L4
8819                    Asg  |------------|---------------|-------|-----------
8820 
8821                    %age |------------|---------------|-------|-----------
8822 
8823                                                | Session Date
8824                                                V
8825                             L1          L2 (L1)          L3      L4
8826                    Asg  |------------|---------------|-------|-----------
8827 
8828                    %age |------------|---------------|-------|-----------
8829 
8830                                                 | Session Date
8831                                                 V
8832                              L1          L2 (L1)          L1      L4
8833                    Asg  |------------|---------------|-------|-----------
8834 
8835                    %age |------------|---------------|-------|-----------
8836 
8837 
8838                    Note :  L2 (L5) means L2 changed to L5. Similarly
8839                            L2 (L1) means L2 changed to L1.
8840                    */
8841 
8842                    /* Backward processing */
8846                                     p_new_location         => p_new_location_id,
8843                    backward_processing(p_assignment        => p_assignment_id,
8844                                     p_eff_start_date       => p_effective_start_date,
8845                                     p_validation_start_date => l_validation_start_date,
8847                                     p_element_link         => l_element_link_id);
8848 
8849                    /* next location = p_new_location_id */
8850 
8851                    if l_next_location = p_new_location_id then
8852 
8853                       /* Processing for the condition when next location = new location.
8854 
8855                                                   | Session Date
8856                                                   V
8857                                 L1          L2 (L1)            L1      L3
8858                        Asg  |------------|---------------|-------|-----------
8859 
8860                        %age |------------|---------------|-------|-----------
8861 
8862                                                   | Session Date
8863                                                   V
8864                                 L1          L2 (L3)          L3      L4
8865                        Asg  |------------|---------------|-------|-----------
8866 
8867                        %age |------------|---------------|-------|-----------
8868 
8869                       In the above example if we correct L2 as of the session date
8870                       to L1 then new location = next location.  */
8871 
8872 
8873                       /* Get the end date of the next %age records */
8874                       open csr_get_next_date(l_element_link_id,l_pef_next_date);
8875                       fetch csr_get_next_date into l_next_loc_end_date;
8876                       if csr_get_next_date%NOTFOUND then
8877                          close csr_get_next_date;
8878                          fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8879                          fnd_message.set_token('PROCEDURE',
8880                          'pay_us_emp_dt_tax_rules.correct_percentage');
8881                          fnd_message.set_token('STEP','4');
8882                          fnd_message.raise_error;
8883                       end if;
8884 
8885                       close csr_get_next_date;
8886 
8887                       /* set the validation end date to the end date of the next
8888                          set of %age records */
8889 
8890                       l_validation_end_date   := l_next_loc_end_date;
8891 
8892                       /* deleting the current set */
8893 
8894                       upd_del_entries(p_assignment_id  => p_assignment_id,
8895                                       p_session_date   => l_validation_start_date,
8896                                       p_new_start_date => null,
8897                                       p_new_end_date   => null,
8898                                       p_mode           => 'D');
8899 
8900                       /* Pull  the next set to the p_validation start date */
8901 
8902                       upd_del_entries(p_assignment_id  => p_assignment_id,
8903                                       p_session_date   => l_pef_next_date,
8904                                       p_new_start_date => l_validation_start_date,
8905                                       p_new_end_date   => null,
8906                                       p_mode           => 'U');
8907 
8908                   end if;
8909 
8910                   /* zero out time for the date range between p_validation_start_date
8911                      and p_validation_end_date */
8912 
8913                   zero_out_time(p_assignment_id     => p_assignment_id,
8914                             p_effective_start_date  => l_validation_start_date,
8915                             p_effective_end_date    => l_validation_end_date);
8916 
8917                   /* Create the tax rules records and the %age records for the
8918                      new location - if required and set the city %age to 100 */
8919 
8920                 l_ovrd_percent := 0;
8921                 l_percent := 100;
8922                 open csr_get_ovrd_loc(p_assignment_id, p_session_date);
8923                 fetch csr_get_ovrd_loc into l_ovrd_loc;
8924                 if csr_get_ovrd_loc%found then
8925                    if l_ovrd_loc <> p_new_location_id then
8926                       l_ovrd_percent := 100;
8927                       l_percent := 0;
8928                     end if;
8929                 end if;
8930                 close csr_get_ovrd_loc;
8931 
8932                   create_new_location_rec(p_assignment_id   => p_assignment_id,
8933                                     p_validation_start_date => l_validation_start_date,
8934                                      p_validation_end_date  => l_validation_end_date,
8935                                      p_session_date         => p_session_date,
8936                                      p_new_location_id      => p_new_location_id,
8937                                      p_res_state_code       => null,
8938                                      p_res_county_code      => null,
8939                                      p_res_city_code        => null,
8940                                      p_business_group       => p_business_group_id,
8941                                       p_percent              => l_percent);
8942                   if l_ovrd_percent = 100 then
8943                      create_new_location_rec(p_assignment_id  => p_assignment_id,
8944                           p_validation_start_date => l_validation_start_date,
8948                           p_res_state_code        => null,
8945                           p_validation_end_date   => l_validation_end_date,
8946                           p_session_date          => p_session_date,
8947                           p_new_location_id       => l_ovrd_loc,
8949                           p_res_county_code       => null,
8950                           p_res_city_code         => null,
8951                           p_business_group        => p_business_group_id,
8952                           p_percent               => l_ovrd_percent);
8953                   end if;
8954 
8955 
8956                end if;
8957 
8958         end if; /* terminated /unterminated assignment */
8959 
8960        end if; /* same/different effective end date */
8961 
8962     end if; /* Single and multiple locations */
8963 
8964 end correct_percentage;
8965 
8966 procedure update_percentage (p_assignment_id        in number,
8967                              p_effective_start_date in date,
8968                              p_effective_end_date   in date,
8969                              p_session_date         in date,
8970                              p_new_location_id      in number,
8971                              p_business_group_id    in number,
8972                              p_mode                 in varchar2,
8973                              p_ret_code             in out nocopy number,
8974                              p_ret_text             in out nocopy varchar2) is
8975 
8976  l_validation_start_date    date := null;
8977  l_validation_end_date      date := null;
8978  l_prev_end_date            date := null;
8979  l_next_location            number;
8980  l_pef_start_date           date;
8981  l_pef_end_date             date;
8982  l_pef_next_date            date;
8983  l_termination_flag         boolean:= FALSE;
8984  l_element_type_id          number;
8985  l_element_link_id          number;
8986  l_new_session_date         date;
8987  l_ovrd_loc              number;
8988  l_ovrd_percent          number := 0;
8989  l_percent               number := 100;
8990 
8991 
8992    /* Get the Vertex element type */
8993    cursor csr_tax_element is
8994        select pet.element_type_id
8995        from   PAY_ELEMENT_TYPES_F pet
8996        where  pet.element_name          = 'VERTEX'
8997        and    p_session_date between pet.effective_start_date
8998                              and pet.effective_end_date;
8999 
9000   /* Cursor to get the effective dates of the %age record for the
9001      session date */
9002 
9003   cursor csr_get_dates(p_element_link number, p_session_dt date) is
9004   select pef.effective_start_date,
9005          pef.effective_end_date,
9006          pef.effective_end_date + 1
9007   from   PAY_ELEMENT_ENTRIES_F pef
9008   where  pef.assignment_id = p_assignment_id
9009   and    p_session_dt between pef.effective_start_date
9010          and pef.effective_end_date
9011   and    pef.element_link_id      = p_element_link
9012   and    rownum < 2;
9013 
9014   /* cursor to get the next location */
9015 
9016   cursor csr_get_next_location (p_next_eff_date date) is
9017   select paf.location_id
9018   from   PER_ASSIGNMENTS_F paf
9019   where  paf.assignment_id = p_assignment_id and
9020          p_next_eff_date between paf.effective_start_date
9021          and paf.effective_end_date;
9022 
9023   /* cursor to get the effective end date of the next element entry record */
9024   cursor csr_get_next_date (p_element_link number, p_date date)is
9025        select pee.effective_end_date
9026        from   PAY_ELEMENT_ENTRIES_F pee
9027        where  pee.assignment_id        = p_assignment_id
9028        and    p_date between pee.effective_start_date
9029                              and pee.effective_end_date
9030        and    pee.element_link_id      = p_element_link
9031        and rownum < 2;
9032 
9033     cursor csr_get_ovrd_loc(p_assignment number, p_session_dt date) is
9034     select nvl(hsck.segment18, paf.location_id)
9035     from   HR_SOFT_CODING_KEYFLEX hsck,
9036            PER_ASSIGNMENTS_F      paf
9037     where  paf.assignment_id = p_assignment
9038     and    p_session_dt between paf.effective_start_date
9039                      and paf.effective_end_date
9040     and    hsck.soft_coding_keyflex_id = paf.soft_coding_keyflex_id;
9041 
9042 
9043 
9044 begin
9045 
9046     /* Check for Update
9047 
9048                         | Session date
9049                         V
9050     |-------------------------------------
9051 
9052     */
9053 
9054     if p_mode in ('UPDATE','UPDATE_OVERRIDE') then
9055 
9056        l_validation_start_date := p_session_date;
9057        l_validation_end_date       := to_date('31/12/4712','dd/mm/yyyy');
9058 
9059        /* Do an update for the element entries for all of the
9060           existing jurisdictions of the assignment */
9061 
9062        change_entries(p_assignment_id     => p_assignment_id,
9063                       p_session_date      => p_session_date,
9064                       p_start_date        => p_effective_start_date,
9065                       p_end_date          => p_effective_end_date,
9066                       p_mode              => p_mode);
9067 
9068        /* Create the tax rules records and the %age records for the
9069           new location - if required and set the city %age to 100 */
9070 
9071        l_ovrd_percent := 0;
9072        l_percent := 100;
9076           if l_ovrd_loc <> p_new_location_id then
9073        open csr_get_ovrd_loc(p_assignment_id, p_session_date);
9074        fetch csr_get_ovrd_loc into l_ovrd_loc;
9075        if csr_get_ovrd_loc%found then
9077              l_ovrd_percent := 100;
9078              l_percent := 0;
9079           end if;
9080        end if;
9081        close csr_get_ovrd_loc;
9082 
9083        create_new_location_rec(p_assignment_id   => p_assignment_id,
9084                          p_validation_start_date => l_validation_start_date,
9085                           p_validation_end_date  => l_validation_end_date,
9086                           p_session_date         => p_session_date,
9087                           p_new_location_id      => p_new_location_id,
9088                           p_res_state_code       => null,
9089                           p_res_county_code      => null,
9090                           p_res_city_code        => null,
9091                           p_business_group       => p_business_group_id,
9092                           p_percent              => l_percent);
9093        if l_ovrd_percent = 100 then
9094           create_new_location_rec(p_assignment_id  => p_assignment_id,
9095                           p_validation_start_date => l_validation_start_date,
9096                           p_validation_end_date   => l_validation_end_date,
9097                           p_session_date          => p_session_date,
9098                           p_new_location_id       => l_ovrd_loc,
9099                           p_res_state_code        => null,
9100                           p_res_county_code       => null,
9101                           p_res_city_code         => null,
9102                           p_business_group        => p_business_group_id,
9103                           p_percent               => l_ovrd_percent);
9104        end if;
9105 
9106 
9107      elsif p_mode = 'UPDATE_CHANGE_INSERT' then
9108 
9109        open csr_tax_element;
9110 
9111        fetch csr_tax_element into l_element_type_id;
9112 
9113        if csr_tax_element%NOTFOUND then
9114 
9115            close csr_tax_element;
9116            fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9117            fnd_message.set_token('PROCEDURE',
9118                    'pay_us_emp_dt_tax_rules.update_percentage');
9119            fnd_message.set_token('STEP','1');
9120            fnd_message.raise_error;
9121 
9122        end if;
9123 
9124        close csr_tax_element;
9125 
9126        /* Get element link */
9127 
9128        l_element_link_id := hr_entry_api.get_link(
9129                                  P_assignment_id   => p_assignment_id,
9130                                  P_element_type_id => l_element_type_id,
9131                                  P_session_date    => p_session_date);
9132 
9133        if l_element_link_id is null or l_element_link_id = 0 then
9134 
9135            fnd_message.set_name('PAY', 'HR_13140_TAX_ELEMENT_ERROR');
9136            fnd_message.set_token('1','VERTEX');
9137            fnd_message.raise_error;
9138 
9139        end if;
9140 
9141        /* Get the effective start date, effective end date and (effective end date + 1)
9142         of the %age record for the session date */
9143 
9144        open  csr_get_dates(l_element_link_id, p_session_date);
9145 
9146        fetch csr_get_dates into l_pef_start_date, l_pef_end_date, l_pef_next_date;
9147 
9148        if csr_get_dates%NOTFOUND then
9149 
9150            close csr_get_dates;
9151            fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9152            fnd_message.set_token('PROCEDURE',
9153                    'pay_us_emp_dt_tax_rules.update_percentage');
9154            fnd_message.set_token('STEP','2');
9155            fnd_message.raise_error;
9156 
9157        end if;
9158 
9159        close csr_get_dates;
9160 
9161        if p_effective_end_date <> l_pef_end_date then
9162 
9163          l_validation_start_date := p_session_date;
9164          l_validation_end_date   := p_effective_end_date;
9165 
9166 
9167          /* First do an update insert with the existing value of the
9168             existing jurisdictions as of the p_effective_end_date + 1 */
9169 
9170          select p_effective_end_date + 1
9171          into l_new_session_date
9172          from DUAL;
9173 
9174          change_entries(p_assignment_id     => p_assignment_id,
9175                         p_session_date      => l_new_session_date,
9176                         p_start_date        => l_pef_start_date,
9177                         p_end_date          => l_pef_end_date,
9178                         p_mode              => 'INSERT_OLD');
9179 
9180 
9181          /* Again do an update insert  for the element entries for all of the
9182             existing jurisdictions of the assignment, as of the session date */
9183 
9184          change_entries(p_assignment_id     => p_assignment_id,
9185                         p_session_date      => p_session_date,
9186                         p_start_date        => l_pef_start_date,
9187                         p_end_date          => l_validation_end_date,
9188                         p_mode              => 'UPDATE_CHANGE_INSERT');
9189 
9190          /* Create the tax rules records and the %age records for the
9191             new location - if required and set the city %age to 100 */
9192 
9193        l_ovrd_percent := 0;
9194        l_percent := 100;
9195        open csr_get_ovrd_loc(p_assignment_id, p_session_date);
9199              l_ovrd_percent := 100;
9196        fetch csr_get_ovrd_loc into l_ovrd_loc;
9197        if csr_get_ovrd_loc%found then
9198           if l_ovrd_loc <> p_new_location_id then
9200              l_percent := 0;
9201           end if;
9202        end if;
9203        close csr_get_ovrd_loc;
9204 
9205 
9206          create_new_location_rec(p_assignment_id   => p_assignment_id,
9207                          p_validation_start_date => l_validation_start_date,
9208                           p_validation_end_date  => l_validation_end_date,
9209                           p_session_date         => p_session_date,
9210                           p_new_location_id      => p_new_location_id,
9211                           p_res_state_code       => null,
9212                           p_res_county_code      => null,
9213                           p_res_city_code        => null,
9214                           p_business_group       => p_business_group_id,
9215                           p_percent              => l_percent);
9216        if l_ovrd_percent = 100 then
9217           create_new_location_rec(p_assignment_id  => p_assignment_id,
9218                           p_validation_start_date => l_validation_start_date,
9219                           p_validation_end_date   => l_validation_end_date,
9220                           p_session_date          => p_session_date,
9221                           p_new_location_id       => l_ovrd_loc,
9222                           p_res_state_code        => null,
9223                           p_res_county_code       => null,
9224                           p_res_city_code         => null,
9225                           p_business_group        => p_business_group_id,
9226                           p_percent               => l_ovrd_percent);
9227        end if;
9228 
9229 
9230 
9231         else /* the end dates of the assignment record and the %age rec.
9232                 are the same */
9233 
9234            l_validation_start_date := p_session_date;
9235            l_validation_end_date := l_pef_end_date;
9236 
9237            /* Get the next location of the assignment */
9238 
9239            open csr_get_next_location(l_pef_next_date);
9240 
9241            fetch csr_get_next_location into l_next_location;
9242 
9243            if csr_get_next_location%NOTFOUND then
9244 
9245                l_termination_flag := TRUE;
9246 
9247             else
9248 
9249                l_termination_flag := FALSE;
9250 
9251             end if;
9252 
9253             close csr_get_next_location;
9254 
9255             if l_termination_flag = FALSE and l_next_location = p_new_location_id then
9256 
9257                 /* get the effective end date of the next set of %age records */
9258 
9259                 open csr_get_next_date(l_element_link_id, l_pef_next_date);
9260 
9261                 fetch csr_get_next_date into l_validation_end_date;
9262 
9263                 if csr_get_next_date%NOTFOUND then
9264 
9265                    close csr_get_next_date;
9266                    fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9267                    fnd_message.set_token('PROCEDURE',
9268                        'pay_us_emp_dt_tax_rules.update_percentage');
9269                    fnd_message.set_token('STEP','2');
9270                    fnd_message.raise_error;
9271 
9272                 end if;
9273 
9274                 /* Pull forward the records as of the session date to
9275                    l_validation_start_date -1 */
9276 
9277                 select l_validation_start_date - 1
9278                 into l_prev_end_date
9279                 from SYS.DUAL;
9280 
9281                 upd_del_entries(p_assignment_id     => p_assignment_id,
9282                                 p_session_date      => p_session_date,
9283                                 p_new_start_date    => null,
9284                                 p_new_end_date      => l_prev_end_date,
9285                                 p_mode              => 'U');
9286 
9287                 /* Pull back the records as of the session date to
9288                    p_session_date +1 */
9289 
9290                 upd_del_entries(p_assignment_id     => p_assignment_id,
9291                                 p_session_date      => l_pef_next_date,
9292                                 p_new_start_date    => l_validation_start_date,
9293                                 p_new_end_date      => null,
9294                                 p_mode              => 'U');
9295 
9296            else  /* If termination flag is true or termination flag is false and
9297                     change in location has taken place */
9298 
9299                change_entries(p_assignment_id     => p_assignment_id,
9300                               p_session_date      => p_session_date,
9301                               p_start_date        => l_pef_start_date,
9302                               p_end_date          => l_pef_end_date,
9303                               p_mode              => 'UPDATE_CHANGE_INSERT');
9304 
9305                /* zero out the time for the new date range */
9306 
9307                zero_out_time(p_assignment_id     => p_assignment_id,
9308                          p_effective_start_date  => l_validation_start_date,
9309                          p_effective_end_date    => l_validation_end_date);
9310 
9311 
9312                /* Create the tax rules records and the %age records for the
9313                   new location - if required and set the city %age to 100 */
9314 
9315               l_ovrd_percent := 0;
9319               if csr_get_ovrd_loc%found then
9316               l_percent := 100;
9317               open csr_get_ovrd_loc(p_assignment_id, p_session_date);
9318               fetch csr_get_ovrd_loc into l_ovrd_loc;
9320                  if l_ovrd_loc <> p_new_location_id then
9321                     l_ovrd_percent := 100;
9322                     l_percent := 0;
9323                  end if;
9324               end if;
9325               close csr_get_ovrd_loc;
9326 
9327                create_new_location_rec(p_assignment_id   => p_assignment_id,
9328                           p_validation_start_date => l_validation_start_date,
9329                            p_validation_end_date  => l_validation_end_date,
9330                            p_session_date         => p_session_date,
9331                            p_new_location_id      => p_new_location_id,
9332                            p_res_state_code       => null,
9333                            p_res_county_code      => null,
9334                            p_res_city_code        => null,
9335                            p_business_group       => p_business_group_id,
9336                           p_percent              => l_percent);
9337        if l_ovrd_percent = 100 then
9338           create_new_location_rec(p_assignment_id  => p_assignment_id,
9339                           p_validation_start_date => l_validation_start_date,
9340                           p_validation_end_date   => l_validation_end_date,
9341                           p_session_date          => p_session_date,
9342                           p_new_location_id       => l_ovrd_loc,
9343                           p_res_state_code        => null,
9344                           p_res_county_code       => null,
9345                           p_res_city_code         => null,
9346                           p_business_group        => p_business_group_id,
9347                           p_percent               => l_ovrd_percent);
9348        end if;
9349 
9350 
9351 
9352            end if; /* Termination Flag is false or true */
9353 
9354       end if;
9355 
9356 end if;
9357 
9358 end update_percentage;
9359 
9360 
9361 /* Name    : correct_wc_entry
9362    Purpose : This will handle the workers comp element entry
9363              for a 'correction' to the assignment's location.
9364 */
9365 
9366 procedure correct_wc_entry (p_assignment_id        in number,
9367                                  p_effective_start_date in date,
9368                                  p_effective_end_date   in date,
9369                                  p_session_date         in date,
9370                                  p_new_location_id      in number,
9371                                  p_ret_code             in out nocopy number,
9372                                  p_ret_text             in out nocopy varchar2) is
9373 
9374 cursor csr_get_loc_state is
9375        select pus.state_code
9376        from   PAY_US_STATES       pus,
9377               HR_LOCATIONS        hrl
9378        where  hrl.location_id   = p_new_location_id
9379        and    pus.state_abbrev  = nvl(hrl.loc_information17,hrl.region_2);
9380 
9381 cursor csr_get_fed_rows is
9382    select pef.effective_start_date, pef.effective_end_date,
9383           pef.sui_jurisdiction_code
9384    from   PAY_US_EMP_FED_TAX_RULES_F pef
9385    where  pef.assignment_id = p_assignment_id
9386    and    p_effective_start_date <= pef.effective_end_date
9387    and    p_effective_end_date >= pef.effective_start_date;
9388 
9389 cursor csr_get_fed_details (p_start_date date, p_end_date date) is
9390    select * from pay_us_emp_fed_tax_rules_f
9391    where  assignment_id = p_assignment_id
9392    and    effective_start_date = p_start_date
9393    and    effective_end_date   = p_end_date;
9394 
9395 cursor csr_lck_fed_row (p_start_date date, p_end_date date)is
9396    select rowid
9397    from PAY_US_EMP_FED_TAX_RULES_F
9398    where assignment_id        = p_assignment_id
9399    and   effective_start_date = p_start_date
9400    and   effective_end_date   = p_end_date
9401    for update nowait;
9402 
9403 l_eff_start_date       date;
9404 l_eff_end_date         date;
9405 l_row_id               rowid;
9406 l_work_state_code      varchar2(2);
9407 l_new_date             date;
9408 l_jurisdiction_code    varchar2(11);
9409 l_step                 number;
9410 l_fed_rec              PAY_US_EMP_FED_TAX_RULES_F%rowtype;
9411 
9412 begin
9413 
9414      l_step := 1;
9415     /* Get the state code of the new work location */
9416     open csr_get_loc_state;
9417     fetch csr_get_loc_state into l_work_state_code;
9418     if csr_get_loc_state%NOTFOUND then
9419        close csr_get_loc_state;
9420        fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9421        fnd_message.set_token('PROCEDURE',
9422        'pay_us_emp_dt_tax_rules.correct_wc_entry');
9423        fnd_message.set_token('STEP',to_char(l_step));
9424        fnd_message.raise_error;
9425     end if;
9426     close csr_get_loc_state;
9427 
9428     l_step := 2;
9429     open csr_get_fed_rows;
9430     loop
9431 
9432         l_step := 3;
9433         fetch csr_get_fed_rows into l_eff_start_date, l_eff_end_date,
9434         l_jurisdiction_code;
9435         exit when csr_get_fed_rows%NOTFOUND;
9436         if l_eff_start_date >= p_effective_start_date and
9437            l_eff_end_date <= p_effective_end_date then
9438            l_step := 4;
9439 	   /* Lock the federal record before updating */
9440 	   open csr_lck_fed_row(l_eff_start_date, l_eff_end_date);
9441            l_step := 5;
9445               fnd_message.set_name('FND','FORM_UNABLE_TO_RESERVE_RECORD');
9442 	   fetch csr_lck_fed_row into l_row_id;
9443 	   if csr_lck_fed_row%NOTFOUND then
9444               close csr_lck_fed_row;
9446               fnd_message.raise_error;
9447            end if;
9448            close csr_lck_fed_row;
9449 
9450            /* Update the federal tax record for the SUI state */
9451            l_step := 6;
9452            update PAY_US_EMP_FED_TAX_RULES_F
9453            set    sui_state_code = l_work_state_code,
9454                   sui_jurisdiction_code = l_work_state_code ||'-000-0000'
9455            where  rowid = l_row_id;
9456 
9457            /* correct the jurisdiction for the Workers Compensation
9458               element entry */
9459            l_step := 7;
9460 
9461            maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
9462                                    p_effective_start_date => l_eff_start_date,
9463                                    p_effective_end_date   => l_eff_end_date,
9464                                    p_session_date         => l_eff_start_date,
9465                                    p_jurisdiction_code    => l_work_state_code ||'-000-0000',
9466                                    p_mode                 => 'CORRECTION');
9467 
9468          elsif l_eff_start_date < p_effective_start_date and
9469                l_eff_end_date <= p_effective_end_date then
9470 
9471                l_step := 8;
9472                select p_effective_start_date -1
9473                into l_new_date
9474                from DUAL;
9475 
9476                l_step := 9;
9477                open csr_get_fed_details(l_eff_start_date, l_eff_end_date);
9478                fetch csr_get_fed_details into l_fed_rec;
9479                if csr_get_fed_details%NOTFOUND then
9480                   close csr_get_fed_details;
9481                   fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9482                   fnd_message.set_token('PROCEDURE',
9483                   'pay_us_emp_dt_tax_rules.correct_wc_entry');
9484                  fnd_message.set_token('STEP',to_char(l_step));
9485                  fnd_message.raise_error;
9486                end if;
9487                close csr_get_fed_details;
9488 
9489                /* Update the Federal tax record as of the p_effective_start_date */
9490 
9491                l_step := 10;
9492                update PAY_US_EMP_FED_TAX_RULES_F
9493                set    effective_end_date = l_new_date
9494                where assignment_id        = p_assignment_id
9495                and   effective_start_date = l_eff_start_date
9496                and   effective_end_date   = l_eff_end_date;
9497 
9498                l_step := 11;
9499                insert into PAY_US_EMP_FED_TAX_RULES_F
9500                (emp_fed_tax_rule_id,
9501                 effective_start_date,
9502                 effective_end_date,
9503                 assignment_id,
9504                 sui_state_code,
9505                 sui_jurisdiction_code,
9506                 business_group_id,
9507                 additional_wa_amount,
9508                 filing_status_code,
9509                 fit_override_amount,
9510                 fit_override_rate,
9511                 withholding_allowances,
9512                 cumulative_taxation,
9513                 eic_filing_status_code,
9514                 fit_additional_tax,
9515                 fit_exempt,
9516                 futa_tax_exempt,
9517                 medicare_tax_exempt,
9518                 ss_tax_exempt,
9519                 wage_exempt,
9520                 statutory_employee,
9521                 w2_filed_year,
9522                 supp_tax_override_rate,
9523                 excessive_wa_reject_date,
9524                 object_version_number,
9525                 attribute_category,
9526                 attribute1,
9527                 attribute2,
9528                 attribute3,
9529                 attribute4,
9530                 attribute5,
9531                 attribute6,
9532                 attribute7,
9533                 attribute8,
9534                 attribute9,
9535                 attribute10,
9536                 attribute11,
9537                 attribute12,
9538                 attribute13,
9539                 attribute14,
9540                 attribute15,
9541                 attribute16,
9542                 attribute17,
9543                 attribute18,
9544                 attribute19,
9545                 attribute20,
9546                 attribute21,
9547                 attribute22,
9548                 attribute23,
9549                 attribute24,
9550                 attribute25,
9551                 attribute26,
9552                 attribute27,
9553                 attribute28,
9554                 attribute29,
9555                 attribute30,
9556                 fed_information_category,
9557                 fed_information1,
9558                 fed_information2,
9559                 fed_information3,
9560                 fed_information4,
9561                 fed_information5,
9562                 fed_information6,
9563                 fed_information7,
9564                 fed_information8,
9565                 fed_information9,
9566                 fed_information10,
9567                 fed_information11,
9568                 fed_information12,
9569                 fed_information13,
9570                 fed_information14,
9571                 fed_information15,
9575                 fed_information19,
9572                 fed_information16,
9573                 fed_information17,
9574                 fed_information18,
9576                 fed_information20,
9577                 fed_information21,
9578                 fed_information22,
9579                 fed_information23,
9580                 fed_information24,
9581                 fed_information25,
9582                 fed_information26,
9583                 fed_information27,
9584                 fed_information28,
9585                 fed_information29,
9586                 fed_information30
9587                 )
9588 
9589                values
9590                (l_fed_rec.emp_fed_tax_rule_id,
9591                 p_effective_start_date,
9592                 l_fed_rec.effective_end_date,
9593                 l_fed_rec.assignment_id,
9594                 l_work_state_code,
9595                 l_work_state_code || '-000-0000',
9596                 l_fed_rec.business_group_id,
9597                 l_fed_rec.additional_wa_amount,
9598                 lpad(l_fed_rec.filing_status_code,2,'0'),
9599                 l_fed_rec.fit_override_amount,
9600                 l_fed_rec.fit_override_rate,
9601                 l_fed_rec.withholding_allowances,
9602                 l_fed_rec.cumulative_taxation,
9603                 l_fed_rec.eic_filing_status_code,
9604                 l_fed_rec.fit_additional_tax,
9605                 l_fed_rec.fit_exempt,
9606                 l_fed_rec.futa_tax_exempt,
9607                 l_fed_rec.medicare_tax_exempt,
9608                 l_fed_rec.ss_tax_exempt,
9609                 l_fed_rec.wage_exempt,
9610                 l_fed_rec.statutory_employee,
9611                 l_fed_rec.w2_filed_year,
9612                 l_fed_rec.supp_tax_override_rate,
9613                 l_fed_rec.excessive_wa_reject_date,
9614                 0,
9615                 l_fed_rec.attribute_category,
9616                 l_fed_rec.attribute1,
9617                 l_fed_rec.attribute2,
9618                 l_fed_rec.attribute3,
9619                 l_fed_rec.attribute4,
9620                 l_fed_rec.attribute5,
9621                 l_fed_rec.attribute6,
9622                 l_fed_rec.attribute7,
9623                 l_fed_rec.attribute8,
9624                 l_fed_rec.attribute9,
9625                 l_fed_rec.attribute10,
9626                 l_fed_rec.attribute11,
9627                 l_fed_rec.attribute12,
9628                 l_fed_rec.attribute13,
9629                 l_fed_rec.attribute14,
9630                 l_fed_rec.attribute15,
9631                 l_fed_rec.attribute16,
9632                 l_fed_rec.attribute17,
9633                 l_fed_rec.attribute18,
9634                 l_fed_rec.attribute19,
9635                 l_fed_rec.attribute20,
9636                 l_fed_rec.attribute21,
9637                 l_fed_rec.attribute22,
9638                 l_fed_rec.attribute23,
9639                 l_fed_rec.attribute24,
9640                 l_fed_rec.attribute25,
9641                 l_fed_rec.attribute26,
9642                 l_fed_rec.attribute27,
9643                 l_fed_rec.attribute28,
9644                 l_fed_rec.attribute29,
9645                 l_fed_rec.attribute30,
9646                 l_fed_rec.fed_information_category,
9647                 l_fed_rec.fed_information1,
9648                 l_fed_rec.fed_information2,
9649                 l_fed_rec.fed_information3,
9650                 l_fed_rec.fed_information4,
9651                 l_fed_rec.fed_information5,
9652                 l_fed_rec.fed_information6,
9653                 l_fed_rec.fed_information7,
9654                 l_fed_rec.fed_information8,
9655                 l_fed_rec.fed_information9,
9656                 l_fed_rec.fed_information10,
9657                 l_fed_rec.fed_information11,
9658                 l_fed_rec.fed_information12,
9659                 l_fed_rec.fed_information13,
9660                 l_fed_rec.fed_information14,
9661                 l_fed_rec.fed_information15,
9662                 l_fed_rec.fed_information16,
9663                 l_fed_rec.fed_information17,
9664                 l_fed_rec.fed_information18,
9665                 l_fed_rec.fed_information19,
9666                 l_fed_rec.fed_information20,
9667                 l_fed_rec.fed_information21,
9668                 l_fed_rec.fed_information22,
9669                 l_fed_rec.fed_information23,
9670                 l_fed_rec.fed_information24,
9671                 l_fed_rec.fed_information25,
9672                 l_fed_rec.fed_information26,
9673                 l_fed_rec.fed_information27,
9674                 l_fed_rec.fed_information28,
9675                 l_fed_rec.fed_information29,
9676                 l_fed_rec.fed_information30
9677                 );
9678 
9679                if l_eff_end_date = to_date('31/12/4712','dd/mm/yyyy') then
9680                   /* Update the workers compensation for the new jurisdiction as of the
9681                      p_effective_start_date */
9682                   l_step := 12;
9683                   maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
9684                                          p_effective_start_date => l_eff_start_date,
9685                                          p_effective_end_date   => l_eff_end_date,
9686                                          p_session_date         => p_effective_start_date,
9687                                          p_jurisdiction_code    => l_work_state_code ||'-000-0000',
9688                                          p_mode                 => 'UPDATE');
9689                 else
9693                   maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
9690                   /* Update Insert the workers compensation for the new jurisdiction as of the
9691                      p_effective_start_date */
9692                   l_step := 13;
9694                                          p_effective_start_date => l_eff_start_date ,
9695                                          p_effective_end_date   => l_eff_end_date,
9696                                          p_session_date         => p_effective_start_date,
9697                                          p_jurisdiction_code    => l_work_state_code ||'-000-0000',
9698                                          p_mode                 => 'UPDATE_CHANGE_INSERT');
9699                 end if;
9700 
9701          elsif l_eff_start_date >= p_effective_start_date and
9702                l_eff_end_date > p_effective_end_date then
9703 
9704                l_step := 14;
9705                select p_effective_end_date +1
9706                into l_new_date
9707                from DUAL;
9708 
9709                open csr_get_fed_details(l_eff_start_date, l_eff_end_date);
9710                fetch csr_get_fed_details into l_fed_rec;
9711                if csr_get_fed_details%NOTFOUND then
9712                   close csr_get_fed_details;
9713                   fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9714                   fnd_message.set_token('PROCEDURE',
9715                   'pay_us_emp_dt_tax_rules.correct_wc_entry');
9716                  fnd_message.set_token('STEP',to_char(l_step));
9717                  fnd_message.raise_error;
9718                end if;
9719                close csr_get_fed_details;
9720 
9721                /* Update the Federal tax record as of the p_effective_start_date */
9722                l_step := 15;
9723               /*
9724                insert into PAY_US_EMP_FED_TAX_RULES_F
9725                select * from pay_us_emp_fed_tax_rules_f
9726                where  assignment_id = p_assignment_id
9727                and    effective_start_date = l_eff_start_date
9728                and    effective_end_date   = l_eff_end_date;
9729               */
9730 
9731                l_step := 16;
9732                update PAY_US_EMP_FED_TAX_RULES_F
9733                set    effective_end_date = p_effective_end_date,
9734                       sui_state_code     = l_work_state_code,
9735                       sui_jurisdiction_code = l_work_state_code || '-000-0000'
9736                where assignment_id        = p_assignment_id
9737                and   effective_start_date = l_eff_start_date
9738                and   effective_end_date   = l_eff_end_date
9739                and   rownum < 2;
9740 
9741                l_step := 17;
9742                insert into PAY_US_EMP_FED_TAX_RULES_F
9743                (emp_fed_tax_rule_id,
9744                 effective_start_date,
9745                 effective_end_date,
9746                 assignment_id,
9747                 sui_state_code,
9748                 sui_jurisdiction_code,
9749                 business_group_id,
9750                 additional_wa_amount,
9751                 filing_status_code,
9752                 fit_override_amount,
9753                 fit_override_rate,
9754                 withholding_allowances,
9755                 cumulative_taxation,
9756                 eic_filing_status_code,
9757                 fit_additional_tax,
9758                 fit_exempt,
9759                 futa_tax_exempt,
9760                 medicare_tax_exempt,
9761                 ss_tax_exempt,
9762                 wage_exempt,
9763                 statutory_employee,
9764                 w2_filed_year,
9765                 supp_tax_override_rate,
9766                 excessive_wa_reject_date,
9767                 object_version_number,
9768                 attribute_category,
9769                 attribute1,
9770                 attribute2,
9771                 attribute3,
9772                 attribute4,
9773                 attribute5,
9774                 attribute6,
9775                 attribute7,
9776                 attribute8,
9777                 attribute9,
9778                 attribute10,
9779                 attribute11,
9780                 attribute12,
9781                 attribute13,
9782                 attribute14,
9783                 attribute15,
9784                 attribute16,
9785                 attribute17,
9786                 attribute18,
9787                 attribute19,
9788                 attribute20,
9789                 attribute21,
9790                 attribute22,
9791                 attribute23,
9792                 attribute24,
9793                 attribute25,
9794                 attribute26,
9795                 attribute27,
9796                 attribute28,
9797                 attribute29,
9798                 attribute30,
9799                 fed_information_category,
9800                 fed_information1,
9801                 fed_information2,
9802                 fed_information3,
9803                 fed_information4,
9804                 fed_information5,
9805                 fed_information6,
9806                 fed_information7,
9807                 fed_information8,
9808                 fed_information9,
9809                 fed_information10,
9810                 fed_information11,
9811                 fed_information12,
9812                 fed_information13,
9813                 fed_information14,
9814                 fed_information15,
9815                 fed_information16,
9819                 fed_information20,
9816                 fed_information17,
9817                 fed_information18,
9818                 fed_information19,
9820                 fed_information21,
9821                 fed_information22,
9822                 fed_information23,
9823                 fed_information24,
9824                 fed_information25,
9825                 fed_information26,
9826                 fed_information27,
9827                 fed_information28,
9828                 fed_information29,
9829                 fed_information30
9830                 )
9831                values
9832                (l_fed_rec.emp_fed_tax_rule_id,
9833                 l_new_date,
9834                 l_fed_rec.effective_end_date,
9835                 l_fed_rec.assignment_id,
9836                 l_fed_rec.sui_state_code,
9837                 l_fed_rec.sui_jurisdiction_code,
9838                 l_fed_rec.business_group_id,
9839                 l_fed_rec.additional_wa_amount,
9840                 lpad(l_fed_rec.filing_status_code,2,'0'),
9841                 l_fed_rec.fit_override_amount,
9842                 l_fed_rec.fit_override_rate,
9843                 l_fed_rec.withholding_allowances,
9844                 l_fed_rec.cumulative_taxation,
9845                 l_fed_rec.eic_filing_status_code,
9846                 l_fed_rec.fit_additional_tax,
9847                 l_fed_rec.fit_exempt,
9848                 l_fed_rec.futa_tax_exempt,
9849                 l_fed_rec.medicare_tax_exempt,
9850                 l_fed_rec.ss_tax_exempt,
9851                 l_fed_rec.wage_exempt,
9852                 l_fed_rec.statutory_employee,
9853                 l_fed_rec.w2_filed_year,
9854                 l_fed_rec.supp_tax_override_rate,
9855                 l_fed_rec.excessive_wa_reject_date,
9856                 0,
9857                 l_fed_rec.attribute_category,
9858                 l_fed_rec.attribute1,
9859                 l_fed_rec.attribute2,
9860                 l_fed_rec.attribute3,
9861                 l_fed_rec.attribute4,
9862                 l_fed_rec.attribute5,
9863                 l_fed_rec.attribute6,
9864                 l_fed_rec.attribute7,
9865                 l_fed_rec.attribute8,
9866                 l_fed_rec.attribute9,
9867                 l_fed_rec.attribute10,
9868                 l_fed_rec.attribute11,
9869                 l_fed_rec.attribute12,
9870                 l_fed_rec.attribute13,
9871                 l_fed_rec.attribute14,
9872                 l_fed_rec.attribute15,
9873                 l_fed_rec.attribute16,
9874                 l_fed_rec.attribute17,
9875                 l_fed_rec.attribute18,
9876                 l_fed_rec.attribute19,
9877                 l_fed_rec.attribute20,
9878                 l_fed_rec.attribute21,
9879                 l_fed_rec.attribute22,
9880                 l_fed_rec.attribute23,
9881                 l_fed_rec.attribute24,
9882                 l_fed_rec.attribute25,
9883                 l_fed_rec.attribute26,
9884                 l_fed_rec.attribute27,
9885                 l_fed_rec.attribute28,
9886                 l_fed_rec.attribute29,
9887                 l_fed_rec.attribute30,
9888                 l_fed_rec.fed_information_category,
9889                 l_fed_rec.fed_information1,
9890                 l_fed_rec.fed_information2,
9891                 l_fed_rec.fed_information3,
9892                 l_fed_rec.fed_information4,
9893                 l_fed_rec.fed_information5,
9894                 l_fed_rec.fed_information6,
9895                 l_fed_rec.fed_information7,
9896                 l_fed_rec.fed_information8,
9897                 l_fed_rec.fed_information9,
9898                 l_fed_rec.fed_information10,
9899                 l_fed_rec.fed_information11,
9900                 l_fed_rec.fed_information12,
9901                 l_fed_rec.fed_information13,
9902                 l_fed_rec.fed_information14,
9903                 l_fed_rec.fed_information15,
9904                 l_fed_rec.fed_information16,
9905                 l_fed_rec.fed_information17,
9906                 l_fed_rec.fed_information18,
9907                 l_fed_rec.fed_information19,
9908                 l_fed_rec.fed_information20,
9909                 l_fed_rec.fed_information21,
9910                 l_fed_rec.fed_information22,
9911                 l_fed_rec.fed_information23,
9912                 l_fed_rec.fed_information24,
9913                 l_fed_rec.fed_information25,
9914                 l_fed_rec.fed_information26,
9915                 l_fed_rec.fed_information27,
9916                 l_fed_rec.fed_information28,
9917                 l_fed_rec.fed_information29,
9918                 l_fed_rec.fed_information30
9919                 );
9920 
9921                l_step := 18;
9922                maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
9923                                       p_effective_start_date => l_eff_start_date,
9924                                       p_effective_end_date   => l_eff_end_date,
9925                                       p_session_date         => l_eff_start_date,
9926                                       p_jurisdiction_code    => l_work_state_code || '-000-0000',
9927                                       p_mode                 => 'CORRECTION');
9928 
9929 
9930                if l_eff_end_date = to_date('31/12/4712','dd/mm/yyyy') then
9931                   /* Update the workers compensation for the old jurisdiction as of the
9932                      l_new_date */
9933                   l_step := 19;
9934                   maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
9938                                          p_jurisdiction_code    => l_jurisdiction_code,
9935                                          p_effective_start_date => l_eff_start_date,
9936                                          p_effective_end_date   => l_eff_end_date,
9937                                          p_session_date         => l_new_date,
9939                                          p_mode                 => 'UPDATE');
9940                 else
9941                   /* Update Insert the workers compensation for the old jurisdiction as of the
9942                      l_new_date */
9943                   l_step := 20;
9944                   maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
9945                                          p_effective_start_date => l_eff_start_date,
9946                                          p_effective_end_date   => l_eff_end_date,
9947                                          p_session_date         => l_new_date,
9948                                          p_jurisdiction_code    => l_jurisdiction_code,
9949                                          p_mode                 => 'UPDATE_CHANGE_INSERT');
9950                 end if;
9951 
9952          elsif l_eff_start_date < p_effective_start_date and
9953                l_eff_end_date > p_effective_end_date then
9954 
9955                l_step := 21;
9956                select p_effective_end_date +1
9957                into l_new_date
9958                from DUAL;
9959 
9960                open csr_get_fed_details(l_eff_start_date, l_eff_end_date);
9961                fetch csr_get_fed_details into l_fed_rec;
9962                if csr_get_fed_details%NOTFOUND then
9963                   close csr_get_fed_details;
9964                   fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
9965                   fnd_message.set_token('PROCEDURE',
9966                   'pay_us_emp_dt_tax_rules.correct_wc_entry');
9967                   fnd_message.set_token('STEP',to_char(l_step));
9968                   fnd_message.raise_error;
9969                end if;
9970                close csr_get_fed_details;
9971 
9972                /* Update the Federal tax record as of the p_effective_end_date + 1 */
9973 
9974                l_step := 23;
9975                update PAY_US_EMP_FED_TAX_RULES_F
9976                set    effective_end_date = p_effective_end_date
9977                where assignment_id        = p_assignment_id
9978                and   effective_start_date = l_eff_start_date
9979                and   effective_end_date   = l_eff_end_date;
9980 
9981                l_step := 24;
9982                insert into PAY_US_EMP_FED_TAX_RULES_F
9983                (emp_fed_tax_rule_id,
9984                 effective_start_date,
9985                 effective_end_date,
9986                 assignment_id,
9987                 sui_state_code,
9988                 sui_jurisdiction_code,
9989                 business_group_id,
9990                 additional_wa_amount,
9991                 filing_status_code,
9992                 fit_override_amount,
9993                 fit_override_rate,
9994                 withholding_allowances,
9995                 cumulative_taxation,
9996                 eic_filing_status_code,
9997                 fit_additional_tax,
9998                 fit_exempt,
9999                 futa_tax_exempt,
10000                 medicare_tax_exempt,
10001                 ss_tax_exempt,
10002                 wage_exempt,
10003                 statutory_employee,
10004                 w2_filed_year,
10005                 supp_tax_override_rate,
10006                 excessive_wa_reject_date,
10007                 object_version_number,
10008                 attribute_category,
10009                 attribute1,
10010                 attribute2,
10011                 attribute3,
10012                 attribute4,
10013                 attribute5,
10014                 attribute6,
10015                 attribute7,
10016                 attribute8,
10017                 attribute9,
10018                 attribute10,
10019                 attribute11,
10020                 attribute12,
10021                 attribute13,
10022                 attribute14,
10023                 attribute15,
10024                 attribute16,
10025                 attribute17,
10026                 attribute18,
10027                 attribute19,
10028                 attribute20,
10029                 attribute21,
10030                 attribute22,
10031                 attribute23,
10032                 attribute24,
10033                 attribute25,
10034                 attribute26,
10035                 attribute27,
10036                 attribute28,
10037                 attribute29,
10038                 attribute30,
10039                 fed_information_category,
10040                 fed_information1,
10041                 fed_information2,
10042                 fed_information3,
10043                 fed_information4,
10044                 fed_information5,
10045                 fed_information6,
10046                 fed_information7,
10047                 fed_information8,
10048                 fed_information9,
10049                 fed_information10,
10050                 fed_information11,
10051                 fed_information12,
10052                 fed_information13,
10053                 fed_information14,
10054                 fed_information15,
10055                 fed_information16,
10056                 fed_information17,
10057                 fed_information18,
10058                 fed_information19,
10062                 fed_information23,
10059                 fed_information20,
10060                 fed_information21,
10061                 fed_information22,
10063                 fed_information24,
10064                 fed_information25,
10065                 fed_information26,
10066                 fed_information27,
10067                 fed_information28,
10068                 fed_information29,
10069                 fed_information30  )
10070                values
10071                (l_fed_rec.emp_fed_tax_rule_id,
10072                 l_new_date,
10073                 l_fed_rec.effective_end_date,
10074                 l_fed_rec.assignment_id,
10075                 l_fed_rec.sui_state_code,
10076                 l_fed_rec.sui_jurisdiction_code,
10077                 l_fed_rec.business_group_id,
10078                 l_fed_rec.additional_wa_amount,
10079                 lpad(l_fed_rec.filing_status_code,2,'0'),
10080                 l_fed_rec.fit_override_amount,
10081                 l_fed_rec.fit_override_rate,
10082                 l_fed_rec.withholding_allowances,
10083                 l_fed_rec.cumulative_taxation,
10084                 l_fed_rec.eic_filing_status_code,
10085                 l_fed_rec.fit_additional_tax,
10086                 l_fed_rec.fit_exempt,
10087                 l_fed_rec.futa_tax_exempt,
10088                 l_fed_rec.medicare_tax_exempt,
10089                 l_fed_rec.ss_tax_exempt,
10090                 l_fed_rec.wage_exempt,
10091                 l_fed_rec.statutory_employee,
10092                 l_fed_rec.w2_filed_year,
10093                 l_fed_rec.supp_tax_override_rate,
10094                 l_fed_rec.excessive_wa_reject_date,
10095                 0,
10096                 l_fed_rec.attribute_category,
10097                 l_fed_rec.attribute1,
10098                 l_fed_rec.attribute2,
10099                 l_fed_rec.attribute3,
10100                 l_fed_rec.attribute4,
10101                 l_fed_rec.attribute5,
10102                 l_fed_rec.attribute6,
10103                 l_fed_rec.attribute7,
10104                 l_fed_rec.attribute8,
10105                 l_fed_rec.attribute9,
10106                 l_fed_rec.attribute10,
10107                 l_fed_rec.attribute11,
10108                 l_fed_rec.attribute12,
10109                 l_fed_rec.attribute13,
10110                 l_fed_rec.attribute14,
10111                 l_fed_rec.attribute15,
10112                 l_fed_rec.attribute16,
10113                 l_fed_rec.attribute17,
10114                 l_fed_rec.attribute18,
10115                 l_fed_rec.attribute19,
10116                 l_fed_rec.attribute20,
10117                 l_fed_rec.attribute21,
10118                 l_fed_rec.attribute22,
10119                 l_fed_rec.attribute23,
10120                 l_fed_rec.attribute24,
10121                 l_fed_rec.attribute25,
10122                 l_fed_rec.attribute26,
10123                 l_fed_rec.attribute27,
10124                 l_fed_rec.attribute28,
10125                 l_fed_rec.attribute29,
10126                 l_fed_rec.attribute30,
10127                 l_fed_rec.fed_information_category,
10128                 l_fed_rec.fed_information1,
10129                 l_fed_rec.fed_information2,
10130                 l_fed_rec.fed_information3,
10131                 l_fed_rec.fed_information4,
10132                 l_fed_rec.fed_information5,
10133                 l_fed_rec.fed_information6,
10134                 l_fed_rec.fed_information7,
10135                 l_fed_rec.fed_information8,
10136                 l_fed_rec.fed_information9,
10137                 l_fed_rec.fed_information10,
10138                 l_fed_rec.fed_information11,
10139                 l_fed_rec.fed_information12,
10140                 l_fed_rec.fed_information13,
10141                 l_fed_rec.fed_information14,
10142                 l_fed_rec.fed_information15,
10143                 l_fed_rec.fed_information16,
10144                 l_fed_rec.fed_information17,
10145                 l_fed_rec.fed_information18,
10146                 l_fed_rec.fed_information19,
10147                 l_fed_rec.fed_information20,
10148                 l_fed_rec.fed_information21,
10149                 l_fed_rec.fed_information22,
10150                 l_fed_rec.fed_information23,
10151                 l_fed_rec.fed_information24,
10152                 l_fed_rec.fed_information25,
10153                 l_fed_rec.fed_information26,
10154                 l_fed_rec.fed_information27,
10155                 l_fed_rec.fed_information28,
10156                 l_fed_rec.fed_information29,
10157                 l_fed_rec.fed_information30
10158                 );
10159 
10160                if l_eff_end_date = to_date('31/12/4712','dd/mm/yyyy') then
10161                   /* Update the workers compensation for the old jurisdiction as of the
10162                      l_new_date */
10163 
10164                   l_step := 26;
10165                   maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
10166                                          p_effective_start_date => l_eff_start_date,
10167                                          p_effective_end_date   => l_eff_end_date,
10168                                          p_session_date         => l_new_date,
10169                                          p_jurisdiction_code    => l_jurisdiction_code,
10170                                          p_mode                 => 'UPDATE');
10171                 else
10172                   /* Update Insert the workers compensation for the old jurisdiction as of the
10173                      l_new_date */
10177                                          p_effective_end_date   => l_eff_end_date,
10174                   l_step := 27;
10175                   maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
10176                                          p_effective_start_date => l_eff_start_date,
10178                                          p_session_date         => l_new_date,
10179                                          p_jurisdiction_code    => l_jurisdiction_code,
10180                                          p_mode                 => 'UPDATE_CHANGE_INSERT');
10181                 end if;
10182 
10183 
10184                l_step := 28;
10185                select p_effective_start_date -1
10186                into l_new_date
10187                from DUAL;
10188 
10189               /*  We do not ned to get the federal record again since we haev already got
10190                   it above.
10191 
10192                open csr_get_fed_details(l_eff_start_date, p_effective_end_date);
10193                fetch csr_get_fed_details into l_fed_rec;
10194                if csr_get_fed_details%NOTFOUND then
10195                   close csr_get_fed_details;
10196                   fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10197                   fnd_message.set_token('PROCEDURE',
10198                   'pay_us_emp_dt_tax_rules.correct_wc_entry');
10199                   fnd_message.set_token('STEP',to_char(l_step));
10200                   fnd_message.raise_error;
10201                end if;
10202                close csr_get_fed_details;
10203                */
10204 
10205                /* Update the Federal tax record as of the p_effective_start_date */
10206 
10207                l_step := 30;
10208                update PAY_US_EMP_FED_TAX_RULES_F
10209                set    effective_end_date = l_new_date
10210                where assignment_id        = p_assignment_id
10211                and   effective_start_date = l_eff_start_date
10212                and   effective_end_date   = p_effective_end_date;
10213 
10214                l_step := 31;
10215                insert into PAY_US_EMP_FED_TAX_RULES_F
10216                (emp_fed_tax_rule_id,
10217                 effective_start_date,
10218                 effective_end_date,
10219                 assignment_id,
10220                 sui_state_code,
10221                 sui_jurisdiction_code,
10222                 business_group_id,
10223                 additional_wa_amount,
10224                 filing_status_code,
10225                 fit_override_amount,
10226                 fit_override_rate,
10227                 withholding_allowances,
10228                 cumulative_taxation,
10229                 eic_filing_status_code,
10230                 fit_additional_tax,
10231                 fit_exempt,
10232                 futa_tax_exempt,
10233                 medicare_tax_exempt,
10234                 ss_tax_exempt,
10235                 wage_exempt,
10236                 statutory_employee,
10237                 w2_filed_year,
10238                 supp_tax_override_rate,
10239                 excessive_wa_reject_date,
10240                 object_version_number,
10241                 attribute_category,
10242                 attribute1,
10243                 attribute2,
10244                 attribute3,
10245                 attribute4,
10246                 attribute5,
10247                 attribute6,
10248                 attribute7,
10249                 attribute8,
10250                 attribute9,
10251                 attribute10,
10252                 attribute11,
10253                 attribute12,
10254                 attribute13,
10255                 attribute14,
10256                 attribute15,
10257                 attribute16,
10258                 attribute17,
10259                 attribute18,
10260                 attribute19,
10261                 attribute20,
10262                 attribute21,
10263                 attribute22,
10264                 attribute23,
10265                 attribute24,
10266                 attribute25,
10267                 attribute26,
10268                 attribute27,
10269                 attribute28,
10270                 attribute29,
10271                 attribute30,
10272                 fed_information_category,
10273                 fed_information1,
10274                 fed_information2,
10275                 fed_information3,
10276                 fed_information4,
10277                 fed_information5,
10278                 fed_information6,
10279                 fed_information7,
10280                 fed_information8,
10281                 fed_information9,
10282                 fed_information10,
10283                 fed_information11,
10284                 fed_information12,
10285                 fed_information13,
10286                 fed_information14,
10287                 fed_information15,
10288                 fed_information16,
10289                 fed_information17,
10290                 fed_information18,
10291                 fed_information19,
10292                 fed_information20,
10293                 fed_information21,
10294                 fed_information22,
10295                 fed_information23,
10296                 fed_information24,
10297                 fed_information25,
10298                 fed_information26,
10299                 fed_information27,
10300                 fed_information28,
10301                 fed_information29,
10302                 fed_information30   )
10303                values
10307                 l_fed_rec.assignment_id,
10304                (l_fed_rec.emp_fed_tax_rule_id,
10305                 p_effective_start_date,
10306                 p_effective_end_date,
10308                 l_work_state_code,
10309                 l_work_state_code || '-000-0000',
10310                 l_fed_rec.business_group_id,
10311                 l_fed_rec.additional_wa_amount,
10312                 lpad(l_fed_rec.filing_status_code,2,'0'),
10313                 l_fed_rec.fit_override_amount,
10314                 l_fed_rec.fit_override_rate,
10315                 l_fed_rec.withholding_allowances,
10316                 l_fed_rec.cumulative_taxation,
10317                 l_fed_rec.eic_filing_status_code,
10318                 l_fed_rec.fit_additional_tax,
10319                 l_fed_rec.fit_exempt,
10320                 l_fed_rec.futa_tax_exempt,
10321                 l_fed_rec.medicare_tax_exempt,
10322                 l_fed_rec.ss_tax_exempt,
10323                 l_fed_rec.wage_exempt,
10324                 l_fed_rec.statutory_employee,
10325                 l_fed_rec.w2_filed_year,
10326                 l_fed_rec.supp_tax_override_rate,
10327                 l_fed_rec.excessive_wa_reject_date,
10328                 0,
10329                 l_fed_rec.attribute_category,
10330                 l_fed_rec.attribute1,
10331                 l_fed_rec.attribute2,
10332                 l_fed_rec.attribute3,
10333                 l_fed_rec.attribute4,
10334                 l_fed_rec.attribute5,
10335                 l_fed_rec.attribute6,
10336                 l_fed_rec.attribute7,
10337                 l_fed_rec.attribute8,
10338                 l_fed_rec.attribute9,
10339                 l_fed_rec.attribute10,
10340                 l_fed_rec.attribute11,
10341                 l_fed_rec.attribute12,
10342                 l_fed_rec.attribute13,
10343                 l_fed_rec.attribute14,
10344                 l_fed_rec.attribute15,
10345                 l_fed_rec.attribute16,
10346                 l_fed_rec.attribute17,
10347                 l_fed_rec.attribute18,
10348                 l_fed_rec.attribute19,
10349                 l_fed_rec.attribute20,
10350                 l_fed_rec.attribute21,
10351                 l_fed_rec.attribute22,
10352                 l_fed_rec.attribute23,
10353                 l_fed_rec.attribute24,
10354                 l_fed_rec.attribute25,
10355                 l_fed_rec.attribute26,
10356                 l_fed_rec.attribute27,
10357                 l_fed_rec.attribute28,
10358                 l_fed_rec.attribute29,
10359                 l_fed_rec.attribute30,
10360                 l_fed_rec.fed_information_category,
10361                 l_fed_rec.fed_information1,
10362                 l_fed_rec.fed_information2,
10363                 l_fed_rec.fed_information3,
10364                 l_fed_rec.fed_information4,
10365                 l_fed_rec.fed_information5,
10366                 l_fed_rec.fed_information6,
10367                 l_fed_rec.fed_information7,
10368                 l_fed_rec.fed_information8,
10369                 l_fed_rec.fed_information9,
10370                 l_fed_rec.fed_information10,
10371                 l_fed_rec.fed_information11,
10372                 l_fed_rec.fed_information12,
10373                 l_fed_rec.fed_information13,
10374                 l_fed_rec.fed_information14,
10375                 l_fed_rec.fed_information15,
10376                 l_fed_rec.fed_information16,
10377                 l_fed_rec.fed_information17,
10378                 l_fed_rec.fed_information18,
10379                 l_fed_rec.fed_information19,
10380                 l_fed_rec.fed_information20,
10381                 l_fed_rec.fed_information21,
10382                 l_fed_rec.fed_information22,
10383                 l_fed_rec.fed_information23,
10384                 l_fed_rec.fed_information24,
10385                 l_fed_rec.fed_information25,
10386                 l_fed_rec.fed_information26,
10387                 l_fed_rec.fed_information27,
10388                 l_fed_rec.fed_information28,
10389                 l_fed_rec.fed_information29,
10390                 l_fed_rec.fed_information30
10391                 );
10392 
10393 
10394                /* Update Insert the workers compensation for the new jurisdiction as of the
10395                   p_effective_start_date */
10396                l_step := 32;
10397                maintain_wc_ele_entry (p_assignment_id        => p_assignment_id,
10398                                       p_effective_start_date => l_eff_start_date,
10399                                       p_effective_end_date   => p_effective_end_date,
10400                                       p_session_date         => p_effective_start_date,
10401                                       p_jurisdiction_code    => l_work_state_code ||'-000-0000',
10402                                       p_mode                 => 'UPDATE_CHANGE_INSERT');
10403 
10404         end if;
10405      end loop;
10406     close csr_get_fed_rows;
10407 
10408     exception
10409     when others then
10410        fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10411        fnd_message.set_token('PROCEDURE',
10412        'pay_us_emp_dt_tax_rules.correct_wc_entry');
10413        fnd_message.set_token('STEP',to_char(l_step));
10414        fnd_message.raise_error;
10415 end correct_wc_entry;
10416 
10420                                 p_effective_end_date   in date,
10417 
10418 procedure change_wc_entry (p_assignment_id        in number,
10419                                 p_effective_start_date in date,
10421                                 p_session_date         in date,
10422                                 p_new_location_id      in number,
10423                                 p_mode                 in varchar2,
10424                                 p_ret_code             in out nocopy number,
10425                                 p_ret_text             in out nocopy varchar2) is
10426 l_validation_start_date    date;
10427 l_validation_end_date      date;
10428 l_end_of_time              date := to_date('31/12/4712','dd/mm/yyyy');
10429 l_ret_code                 number := 0;
10430 l_ret_text                 varchar2(2000);
10431 
10432 begin
10433 
10434     if p_mode = 'CORRECTION' then
10435        l_validation_start_date := p_effective_start_date;
10436        l_validation_end_date   := p_effective_end_date;
10437     elsif p_mode = 'UPDATE' then
10438        l_validation_start_date := p_session_date;
10439        l_validation_end_date   := l_end_of_time;
10440     elsif p_mode = 'UPDATE_CHANGE_INSERT' then
10441        l_validation_start_date := p_session_date;
10442        l_validation_end_date   := p_effective_end_date;
10443     elsif p_mode = 'UPDATE_OVERRIDE' then
10444        l_validation_start_date := p_session_date;
10445        l_validation_end_date   := l_end_of_time;
10446     end if;
10447 
10448     hr_utility.set_location('pay_us_emp_dt_tax_rules.change_wc_entry',1);
10449     correct_wc_entry (p_assignment_id        => p_assignment_id,
10450                            p_effective_start_date => l_validation_start_date,
10451                            p_effective_end_date   => l_validation_end_date,
10452                            p_session_date         => p_session_date,
10453                            p_new_location_id      => p_new_location_id,
10454                            p_ret_code             => l_ret_code,
10455                            p_ret_text             => l_ret_text);
10456     hr_utility.set_location('pay_us_emp_dt_tax_rules.change_wc_entry',2);
10457 
10458 end change_wc_entry;
10459 
10460 procedure pull_tax_records( p_assignment_id   in number,
10461                            p_new_start_date  in date,
10462                            p_default_date    in date) is
10463        l_ef_date DATE;
10464        l_proc VARCHAR2(50) := 'pay_us_emp_dt_tax_rules.pull_tax_records';
10465 
10466 begin
10467        hr_utility.set_location('Entering: ' || l_proc, 5);
10468        /* dscully - modified to handle case where tax record changes
10469 	  have occured between old hire date and new hire date */
10470 
10471        if p_new_start_date < p_default_date then
10472 		l_ef_date := p_default_date;
10473        elsif p_new_start_date > p_default_date then
10474 		l_ef_date := p_new_start_date;
10475        else -- do nothing
10476 	  return;
10477        end if;
10478 
10479        /* First update the tax rules records */
10480 
10481        update PAY_US_EMP_FED_TAX_RULES_F
10482        set    effective_start_date = p_new_start_date
10483        where  assignment_id = p_assignment_id
10484        and    l_ef_date between effective_start_date and effective_end_date;
10485 
10486        if sql%notfound then
10487           fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10488           fnd_message.set_token('PROCEDURE',l_proc);
10489           fnd_message.set_token('STEP','2');
10490           fnd_message.raise_error;
10491        end if;
10492 
10493        update PAY_US_EMP_STATE_TAX_RULES_F
10494        set    effective_start_date = p_new_start_date
10495        where  assignment_id = p_assignment_id
10496        and    l_ef_date between effective_start_date and effective_end_date;
10497 
10498        if sql%notfound then
10499           fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10500           fnd_message.set_token('PROCEDURE',l_proc);
10501           fnd_message.set_token('STEP','3');
10502           fnd_message.raise_error;
10503        end if;
10504 
10505        update PAY_US_EMP_COUNTY_TAX_RULES_F
10506        set    effective_start_date = p_new_start_date
10507        where  assignment_id = p_assignment_id
10508        and    l_ef_date between effective_start_date and effective_end_date;
10509 
10510        if sql%notfound then
10511           fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10512           fnd_message.set_token('PROCEDURE',l_proc);
10513           fnd_message.set_token('STEP','4');
10514           fnd_message.raise_error;
10515        end if;
10516 
10517        update PAY_US_EMP_CITY_TAX_RULES_F
10518        set    effective_start_date = p_new_start_date
10519        where  assignment_id = p_assignment_id
10520        and    l_ef_date between effective_start_date and effective_end_date;
10521 
10522        if sql%notfound then
10523           fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10524           fnd_message.set_token('PROCEDURE',l_proc);
10525           fnd_message.set_token('STEP','5');
10526           fnd_message.raise_error;
10527        end if;
10528 
10529        /* Next delete any orphaned rows */
10530        if p_new_start_date > p_default_date then
10531 	       hr_utility.set_location(l_proc, 10);
10532 	       delete PAY_US_EMP_FED_TAX_RULES_F
10533 	       where  assignment_id = p_assignment_id
10534 	       and    p_new_start_date >  effective_start_date;
10538 	       and    p_new_start_date >  effective_start_date;
10535 
10536 	       delete PAY_US_EMP_STATE_TAX_RULES_F
10537 	       where  assignment_id = p_assignment_id
10539 
10540 	       delete PAY_US_EMP_COUNTY_TAX_RULES_F
10541 	       where  assignment_id = p_assignment_id
10542 	       and    p_new_start_date >  effective_start_date;
10543 
10544 	       delete PAY_US_EMP_CITY_TAX_RULES_F
10545 	       where  assignment_id = p_assignment_id
10546 	       and    p_new_start_date >  effective_start_date;
10547 
10548 	end if;
10549 
10550        hr_utility.set_location('Leaving: ' || l_proc, 20);
10551 
10552 end pull_tax_records;
10553 
10554 procedure check_hiring_date( p_assignment_id   in number,
10555                              p_default_date    in date,
10556                              p_s_start_date    in date) is
10557 
10558 
10559 l_payroll_installed boolean  := FALSE;
10560 
10561 begin
10562 
10563     /* If the hiring date has been changed and pulled back, for the
10564        assignment then pull back the start date of all of the tax
10565        rules records, workers compensation and the vertex element
10566        entries */
10567 
10568 
10569    /* Rmonge 27-jul-2001 */
10570    /* Added an verification for tax records maintenance and payroll     */
10571    /* installation. This is to make sure that                           */
10572    /* the HR only customers do not run into an error when this code is  */
10573 
10574 
10575    l_payroll_installed :=
10576    hr_utility.chk_product_install(p_product =>'Oracle Payroll',
10577                                   p_legislation => 'US');
10578 
10579 
10580 
10581     if hr_general.chk_maintain_tax_records = 'Y' then
10582 
10583          if p_s_start_date < p_default_date then
10584 
10585             pull_tax_records(p_assignment_id     => p_assignment_id,
10586                              p_new_start_date    => p_s_start_date,
10587                         p_default_date      => p_default_date);
10588 
10589 
10590          if l_payroll_installed then
10591 
10592 
10593        /* Now time to update the workers comp element entry */
10594 
10595              del_updt_wc_entry_for_dates (p_assignment_id  => p_assignment_id,
10596                                     p_session_date         => p_default_date,
10597                                     p_new_start_date       => p_s_start_date,
10598                                     p_new_end_date         => null,
10599                                     p_mode                 => 'U');
10600 
10601 
10602        /* Finally update the vertex element entries and close the
10603           chapter */
10604 
10605              upd_del_entries(p_assignment_id  => p_assignment_id,
10606                              p_session_date   => p_default_date,
10607                              p_new_start_date => p_s_start_date,
10608                              p_new_end_date   => null,
10609                              p_mode           => 'U');
10610 
10611     /* If the hiring date has been pulled forward then the person api
10612        pulls forward the element entries but does not pull forward the
10613        tax rules record. So, we will pull them forward */
10614 
10615       end if;  /* payroll installed */
10616 
10617     elsif p_s_start_date > p_default_date then
10618 
10619        pull_tax_records(p_assignment_id     => p_assignment_id,
10620                         p_new_start_date    => p_s_start_date,
10621                         p_default_date      => p_default_date);
10622 
10623     end if; /* start date */
10624 
10625 end if;  /* check maintain tax records */
10626 
10627 end check_hiring_date;
10628 
10629 procedure default_tax ( p_assignment_id          in number,
10630                         p_effective_start_date   in date,
10631                         p_effective_end_date     in date,
10632                         p_business_group_id      in number,
10633                         p_ret_code               in number,
10634                         p_ret_text               in varchar2) is
10635 
10636 l_res_state_code        varchar2(2);
10637 l_res_county_code       varchar2(3);
10638 l_res_city_code         varchar2(4);
10639 l_add_state_code        varchar2(2);
10640 l_add_county_code       varchar2(3);
10641 l_add_city_code         varchar2(4);
10642 l_work_state_code       varchar2(2);
10643 l_work_county_code      varchar2(3);
10644 l_work_city_code        varchar2(4);
10645 l_work1_state_code       varchar2(2);
10646 l_work1_county_code      varchar2(3);
10647 l_work1_city_code        varchar2(4);
10648 l_work2_state_code       varchar2(2);
10649 l_work2_county_code      varchar2(3);
10650 l_work2_city_code        varchar2(4);
10651 l_work3_state_code       varchar2(2);
10652 l_work3_county_code      varchar2(3);
10653 l_work3_city_code        varchar2(4);
10654 l_sui_state_code        varchar2(2);
10655 l_loc_city              varchar2(11);
10656 l_fed_tax_rule_id       number;
10657 l_state_tax_rule_id     number;
10658 l_county_tax_rule_id    number;
10659 l_city_tax_rule_id      number;
10660 l_work_state_name       varchar2(35) := null;
10661 l_work_county_name      varchar2(35) := null;
10662 l_work_city_name       varchar2(35) := null;
10663 l_work1_state_name       varchar2(35) := null;
10664 l_work1_county_name      varchar2(35) := null;
10665 l_work1_city_name       varchar2(35) := null;
10666 l_work2_state_name       varchar2(35) := null;
10667 l_work2_county_name      varchar2(35) := null;
10671 l_work3_city_name       varchar2(35) := null;
10668 l_work2_city_name       varchar2(35) := null;
10669 l_work3_state_name       varchar2(35) := null;
10670 l_work3_county_name      varchar2(35) := null;
10672 l_res_state_name        varchar2(35) := null;
10673 l_res_county_name       varchar2(35) := null;
10674 l_res_city_name         varchar2(35) := null;
10675 l_percent               number;
10676 
10677 cursor csr_chk_addr_ovrd is
10678   select pus.state_code,
10679          puc.county_code,
10680          pcn.city_code
10681   from   pay_us_city_names pcn,
10682          pay_us_counties puc,
10683          pay_us_states pus,
10684          per_addresses pa,
10685          per_assignments_f paf
10686   where  paf.assignment_id         = p_assignment_id
10687   and    p_effective_start_date between paf.effective_start_date and
10688                                 paf.effective_end_date
10689   and    pa.person_id              = paf.person_id
10690   and    pa.primary_flag           = 'Y'
10691   and    p_effective_start_date between pa.date_from and
10692                                      nvl(pa.date_to,to_date('12/31/4712','MM/DD/YYYY'))
10693   and    pa.add_information17 is not null
10694   and    pa.add_information19 is not null
10695   and    pa.add_information18 is not null
10696   and pa.add_information17 = pus.state_abbrev
10697   and puc.state_code = pus.state_code
10698   and puc.county_name = pa.add_information19
10699   and pcn.state_code = puc.state_code
10700   and pcn.county_code = puc.county_code
10701   and pcn.city_name = add_information18;
10702 
10703 begin
10704 
10705      /* Get the resident and the work state, county and city codes */
10706 
10707   hr_utility.set_location('pay_us_emp_dt_tax_rules.default_tax',1);
10708      pay_us_emp_dt_tax_val.get_orig_res_codes (p_assignment_id         => p_assignment_id,
10709 
10710                     p_session_date          => p_effective_start_date,
10711                     p_res_state_code        => l_res_state_code,
10712                     p_res_county_code       => l_res_county_code,
10713                     p_res_city_code         => l_res_city_code,
10714                     p_res_state_name        => l_res_state_name,
10715                     p_res_county_name       => l_res_county_name,
10716                     p_res_city_name         => l_res_city_name);
10717 
10718   hr_utility.set_location('pay_us_emp_dt_tax_rules.default_tax',2);
10719       if l_res_state_code is null then
10720           fnd_message.set_name('PER', 'PER_52985_ADD_NO_STATE_SET');
10721           fnd_message.raise_error;
10722       end if;
10723 
10724       if l_res_county_code is null then
10725           fnd_message.set_name('PER', 'PER_52984_ADD_NO_COUNTY_SET');
10726           fnd_message.raise_error;
10727       end if;
10728 
10729       if l_res_city_code is null then
10730           fnd_message.set_name('PER', 'PER_52986_ADD_NO_CITY_SET');
10731           fnd_message.raise_error;
10732       end if;
10733 
10734       /* Check to see if the address has an override or not . If there is
10735          an override for the address then get the non override address for
10736          the assignment and assign it to the additional state, county
10737          and city codes */
10738 
10739   hr_utility.set_location('pay_us_emp_dt_tax_rules.default_tax',3);
10740       open csr_chk_addr_ovrd;
10741       fetch csr_chk_addr_ovrd into l_add_state_code,
10742                                    l_add_county_code,
10743                                    l_add_city_code;
10744       if csr_chk_addr_ovrd%NOTFOUND then
10745          l_add_state_code := null;
10746          l_add_county_code := null;
10747          l_add_city_code := null;
10748       end if;
10749       close csr_chk_addr_ovrd;
10750 
10751   hr_utility.set_location('pay_us_emp_dt_tax_rules.default_tax',4);
10752      pay_us_emp_dt_tax_val.get_all_work_codes (p_assignment_id         => p_assignment_id,
10753                      p_session_date          => p_effective_start_date,
10754                      p_work_state_code       => l_work_state_code,
10755                      p_work_county_code      => l_work_county_code,
10756                      p_work_city_code        => l_work_city_code,
10757                      p_work_state_name       => l_work_state_name,
10758                      p_work_county_name      => l_work_county_name,
10759                      p_work_city_name        => l_work_city_name,
10760                      p_work1_state_code      => l_work1_state_code,
10761                      p_work1_county_code     => l_work1_county_code,
10762                      p_work1_city_code       => l_work1_city_code,
10763                      p_work1_state_name      => l_work1_state_name,
10764                      p_work1_county_name     => l_work1_county_name,
10765                      p_work1_city_name       => l_work1_city_name,
10766                      p_work2_state_code      => l_work2_state_code,
10767                      p_work2_county_code     => l_work2_county_code,
10768                      p_work2_city_code       => l_work2_city_code,
10769                      p_work2_state_name      => l_work2_state_name,
10770                      p_work2_county_name     => l_work2_county_name,
10771                      p_work2_city_name       => l_work2_city_name,
10772                      p_work3_state_code      => l_work3_state_code,
10776                      p_work3_county_name     => l_work3_county_name,
10773                      p_work3_county_code     => l_work3_county_code,
10774                      p_work3_city_code       => l_work3_city_code,
10775                      p_work3_state_name      => l_work3_state_name,
10777                      p_work3_city_name       => l_work3_city_name,
10778                      p_sui_state_code        => l_sui_state_code,
10779                      p_loc_city              => l_loc_city
10780                                                                 );
10781 
10782       if l_work_state_code is null or l_work_county_code is null
10783          or l_work_city_code is null then
10784           fnd_message.set_name('PAY', 'PY_51133_TXADJ_INVALID_CITY');
10785           fnd_message.raise_error;
10786       end if;
10787 
10788      /* Insert the default Federal tax Record */
10789 
10790      l_fed_tax_rule_id :=
10791        insert_def_fed_rec(p_assignment_id        => p_assignment_id,
10792                           p_effective_start_date => p_effective_start_date,
10793                           p_effective_end_date   => p_effective_end_date,
10794                           p_sui_state_code       => l_sui_state_code,
10795                           p_business_group_id    => p_business_group_id);
10796      /* Insert the default State tax record */
10797      /* Create state record for works and if needed resident state rec also */
10798      l_state_tax_rule_id :=
10799      insert_def_state_rec(p_assignment_id        => p_assignment_id,
10800                           p_effective_start_date => p_effective_start_date,
10801                           p_effective_end_date   => p_effective_end_date,
10802                           p_state_code           => l_work_state_code,
10803                           p_business_group_id    => p_business_group_id,
10804                           p_percent_time         => 0);
10805      if l_work1_state_code is not null then
10806      l_state_tax_rule_id :=
10807      insert_def_state_rec(p_assignment_id        => p_assignment_id,
10808                           p_effective_start_date => p_effective_start_date,
10809                           p_effective_end_date   => p_effective_end_date,
10810                           p_state_code           => l_work1_state_code,
10811                           p_business_group_id    => p_business_group_id,
10812                           p_percent_time         => 0);
10813      end if;
10814      if l_work2_state_code is not null then
10815      l_state_tax_rule_id :=
10816      insert_def_state_rec(p_assignment_id        => p_assignment_id,
10817                           p_effective_start_date => p_effective_start_date,
10818                           p_effective_end_date   => p_effective_end_date,
10819                           p_state_code           => l_work2_state_code,
10820                           p_business_group_id    => p_business_group_id,
10821                           p_percent_time         => 0);
10822      end if;
10823      if l_work3_state_code is not null then
10824      l_state_tax_rule_id :=
10825      insert_def_state_rec(p_assignment_id        => p_assignment_id,
10826                           p_effective_start_date => p_effective_start_date,
10827                           p_effective_end_date   => p_effective_end_date,
10828                           p_state_code           => l_work3_state_code,
10829                           p_business_group_id    => p_business_group_id,
10830                           p_percent_time         => 0);
10831      end if;
10832      if nvl(l_work_state_code,l_res_state_code) <> l_res_state_code
10833         or nvl(l_work1_state_code,l_res_state_code) <> l_res_state_code
10834         or nvl(l_work2_state_code, l_res_state_code) <> l_res_state_code
10835         or nvl(l_work3_state_code, l_res_state_code) <> l_res_state_code then
10836        l_state_tax_rule_id :=
10837        insert_def_state_rec(p_assignment_id        => p_assignment_id,
10838                             p_effective_start_date => p_effective_start_date,
10839                             p_effective_end_date   => p_effective_end_date,
10840                             p_state_code           => l_res_state_code,
10841                             p_business_group_id    => p_business_group_id,
10842                             p_percent_time         => 0);
10843 
10844      end if;
10845 
10846      /* Now check for the override state */
10847      if l_add_state_code is not null
10848         and l_res_state_code <> l_add_state_code then
10849        l_state_tax_rule_id :=
10850        insert_def_state_rec(p_assignment_id        => p_assignment_id,
10851                             p_effective_start_date => p_effective_start_date,
10852                             p_effective_end_date   => p_effective_end_date,
10853                             p_state_code           => l_add_state_code,
10854                             p_business_group_id    => p_business_group_id,
10855                             p_percent_time         => 0);
10856 
10857      end if;
10858      /* Insert the default county tax record */
10859      l_county_tax_rule_id :=
10860      insert_def_county_rec(p_assignment_id      => p_assignment_id,
10861                            p_effective_start_date => p_effective_start_date,
10862                            p_effective_end_date   => p_effective_end_date,
10863                            p_state_code           => l_work_state_code,
10864                            p_county_code          => l_work_county_code,
10865                            p_business_group_id    => p_business_group_id,
10866                            p_percent_time         => 0);
10867      if l_work1_county_code is not null then
10868      l_county_tax_rule_id :=
10872                            p_state_code           => l_work1_state_code,
10869      insert_def_county_rec(p_assignment_id      => p_assignment_id,
10870                            p_effective_start_date => p_effective_start_date,
10871                            p_effective_end_date   => p_effective_end_date,
10873                            p_county_code          => l_work1_county_code,
10874                            p_business_group_id    => p_business_group_id,
10875                            p_percent_time         => 0);
10876      end if;
10877      if l_work2_county_code is not null then
10878      l_county_tax_rule_id :=
10879      insert_def_county_rec(p_assignment_id      => p_assignment_id,
10880                            p_effective_start_date => p_effective_start_date,
10881                            p_effective_end_date   => p_effective_end_date,
10882                            p_state_code           => l_work2_state_code,
10883                            p_county_code          => l_work2_county_code,
10884                            p_business_group_id    => p_business_group_id,
10885                            p_percent_time         => 0);
10886      end if;
10887      if l_work3_county_code is not null then
10888      l_county_tax_rule_id :=
10889      insert_def_county_rec(p_assignment_id      => p_assignment_id,
10890                            p_effective_start_date => p_effective_start_date,
10891                            p_effective_end_date   => p_effective_end_date,
10892                            p_state_code           => l_work3_state_code,
10893                            p_county_code          => l_work3_county_code,
10894                            p_business_group_id    => p_business_group_id,
10895                            p_percent_time         => 0);
10896      end if;
10897      if (l_work_state_code <> l_res_state_code or
10898          l_work_county_code <> l_res_county_code) then
10899         l_county_tax_rule_id :=
10900 
10901         insert_def_county_rec(p_assignment_id      => p_assignment_id,
10902                               p_effective_start_date => p_effective_start_date,
10903                               p_effective_end_date   => p_effective_end_date,
10904                               p_state_code           => l_res_state_code,
10905                               p_county_code          => l_res_county_code,
10906                               p_business_group_id    => p_business_group_id,
10907                               p_percent_time         => 0);
10908      end if;
10909      /* Check for the override county */
10910      if l_add_county_code is not null then
10911         l_county_tax_rule_id :=
10912 
10913         insert_def_county_rec(p_assignment_id      => p_assignment_id,
10914                               p_effective_start_date => p_effective_start_date,
10915                               p_effective_end_date   => p_effective_end_date,
10916                               p_state_code           => l_add_state_code,
10917                               p_county_code          => l_add_county_code,
10918                               p_business_group_id    => p_business_group_id,
10919                               p_percent_time         => 0);
10920      end if;
10921 
10922      /* Insert the default city tax record */
10923      if l_loc_city = l_work_state_code ||'-'||l_work_county_code ||'-'||l_work_city_code
10924      then
10925         l_percent := 100;
10926      else
10927         l_percent := 0;
10928      end if;
10929 
10930      l_city_tax_rule_id :=
10931      insert_def_city_rec(p_assignment_id      => p_assignment_id,
10932                          p_effective_start_date => p_effective_start_date,
10933                          p_effective_end_date   => p_effective_end_date,
10934                          p_state_code           => l_work_state_code,
10935                          p_county_code          => l_work_county_code,
10936                          p_city_code            => l_work_city_code,
10937                          p_business_group_id    => p_business_group_id,
10938                          p_percent_time         => l_percent);
10939 
10940      if l_work1_city_code is not null then
10941         if l_loc_city = l_work1_state_code ||'-'||l_work1_county_code ||'-'||l_work1_city_code
10942         then
10943            l_percent := 100;
10944         else
10945            l_percent := 0;
10946         end if;
10947 
10948         l_city_tax_rule_id :=
10949         insert_def_city_rec(p_assignment_id      => p_assignment_id,
10950                          p_effective_start_date => p_effective_start_date,
10951                          p_effective_end_date   => p_effective_end_date,
10952                          p_state_code           => l_work1_state_code,
10953                          p_county_code          => l_work1_county_code,
10954                          p_city_code            => l_work1_city_code,
10955                          p_business_group_id    => p_business_group_id,
10956                          p_percent_time         => l_percent);
10957      end if;
10958 
10959      if l_work2_city_code is not null then
10960         if l_loc_city = l_work2_state_code ||'-'||l_work2_county_code ||'-'||l_work2_city_code
10961         then
10962            l_percent := 100;
10963         else
10964            l_percent := 0;
10965         end if;
10966 
10967         l_city_tax_rule_id :=
10968         insert_def_city_rec(p_assignment_id      => p_assignment_id,
10969                          p_effective_start_date => p_effective_start_date,
10970                          p_effective_end_date   => p_effective_end_date,
10974                          p_business_group_id    => p_business_group_id,
10971                          p_state_code           => l_work2_state_code,
10972                          p_county_code          => l_work2_county_code,
10973                          p_city_code            => l_work2_city_code,
10975                          p_percent_time         => l_percent);
10976      end if;
10977 
10978      if l_work3_city_code is not null then
10979         if l_loc_city = l_work3_state_code ||'-'||l_work3_county_code ||'-'||l_work3_city_code
10980         then
10981            l_percent := 100;
10982         else
10983            l_percent := 0;
10984         end if;
10985 
10986         l_city_tax_rule_id :=
10987         insert_def_city_rec(p_assignment_id      => p_assignment_id,
10988                          p_effective_start_date => p_effective_start_date,
10989                          p_effective_end_date   => p_effective_end_date,
10990                          p_state_code           => l_work3_state_code,
10991                          p_county_code          => l_work3_county_code,
10992                          p_city_code            => l_work3_city_code,
10993                          p_business_group_id    => p_business_group_id,
10994                          p_percent_time         => l_percent);
10995      end if;
10996 
10997      if (l_work_state_code  <> l_res_state_code or
10998          l_work_county_code <> l_res_county_code or
10999          l_work_city_code   <> l_res_city_code) then
11000          l_city_tax_rule_id :=
11001          insert_def_city_rec(p_assignment_id      => p_assignment_id,
11002                              p_effective_start_date => p_effective_start_date,
11003                              p_effective_end_date   => p_effective_end_date,
11004                              p_state_code           => l_res_state_code,
11005                              p_county_code          => l_res_county_code,
11006                              p_city_code            => l_res_city_code,
11007                              p_business_group_id    => p_business_group_id,
11008                              p_percent_time         => 0);
11009       end if;
11010      /* Check for override city */
11011      if l_add_city_code is not null then
11012          l_city_tax_rule_id :=
11013          insert_def_city_rec(p_assignment_id      => p_assignment_id,
11014                              p_effective_start_date => p_effective_start_date,
11015                              p_effective_end_date   => p_effective_end_date,
11016                              p_state_code           => l_add_state_code,
11017                              p_county_code          => l_add_county_code,
11018                              p_city_code            => l_add_city_code,
11019                              p_business_group_id    => p_business_group_id,
11020                              p_percent_time         => 0);
11021       end if;
11022 end default_tax;
11023 
11024 procedure check_defaulting(p_assignment_id        in number,
11025                            p_effective_start_date in date,
11026                            p_business_group_id    in number,
11027                            p_from_form            in varchar2,
11028                            p_fed_exists           in out nocopy varchar2,
11029                            p_ret_code             in out nocopy number,
11030                            p_ret_text             in out nocopy varchar2 ) is
11031 
11032 
11033   /* Cursor to check if a federal record exists or not */
11034   cursor csr_chk_federal is
11035   select 'Y'
11036   from   DUAL
11037   where  exists ( select null
11038                   from   PAY_US_EMP_FED_TAX_RULES_F ftr
11039                   where  ftr.assignment_id = p_assignment_id);
11040 
11041   /* Cursor to get the max effective end date of the assignment */
11042 
11043   cursor csr_asg_end_date is
11044      select max(effective_end_date)
11045      from   PER_ASSIGNMENTS_F paf
11046      where  paf.assignment_id = p_assignment_id;
11047 
11048   l_effective_end_date     date;
11049 
11050 begin
11051 
11052     /* Check to see if the defaulting of tax records has already taken place
11053        or not */
11054 
11055     open csr_chk_federal;
11056 
11057     fetch csr_chk_federal into p_fed_exists;
11058 
11059     if csr_chk_federal%NOTFOUND then
11060 
11061        p_fed_exists := 'N';
11062 
11063     else
11064 
11065        p_fed_exists := 'Y';
11066 
11067     end if;
11068 
11069     close csr_chk_federal;
11070 
11071     if p_fed_exists = 'N'
11072        and p_from_form in ('Assignment', 'Tax Rules','Address') then
11073        /* Check to see if future dated change in locations has taken
11074           place or not */
11075 
11076        if pay_us_emp_dt_tax_val.check_locations(p_assignment_id => p_assignment_id,
11077                               p_effective_start_date => p_effective_start_date,
11078                               p_business_group_id    => p_business_group_id)
11079        then
11080 
11081           /* message('Future dated location changes exist for which the
11082              defaulting criteria might not be satisfied.') */
11083 
11084           fnd_message.set_name('PAY', 'PAY_52299_TAX_FUT_LOC');
11085           fnd_message.raise_error;
11086 
11087        end if;
11088 
11092           when the assignment is not valid. */
11089        /* Get the max effective end date of the assignment.
11090           This is done to take care of the terminated assignment
11091           so that the tax records do not get created for the time
11093 
11094        open csr_asg_end_date;
11095 
11096        fetch csr_asg_end_date into l_effective_end_date;
11097 
11098        if l_effective_end_date is null then
11099 
11100          close csr_asg_end_date;
11101          fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
11102          fnd_message.set_token('PROCEDURE',
11103          'pay_us_emp_dt_tax_rules.check_defaulting');
11104          fnd_message.set_token('STEP','1');
11105          fnd_message.raise_error;
11106 
11107       end if;
11108 
11109       close csr_asg_end_date;
11110 
11111       /* Call the defaulting tax routine */
11112 
11113       default_tax ( p_assignment_id          => p_assignment_id,
11114                     p_effective_start_date   => p_effective_start_date,
11115                     p_effective_end_date     => l_effective_end_date,
11116                     p_business_group_id      => p_business_group_id,
11117                     p_ret_code               => p_ret_code,
11118                     p_ret_text               => p_ret_text);
11119 
11120    end if;
11121 
11122 end check_defaulting;
11123 
11124 
11125 procedure default_tax_with_validation(p_assignment_id        in number,
11126                                       p_person_id            in number,
11127                                       p_effective_start_date in date,
11128                                       p_effective_end_date   in date,
11129                                       p_session_date         in date,
11130                                       p_business_group_id    in number,
11131                                       p_from_form            in varchar2,
11132                                       p_mode                 in varchar2,
11133                                       p_location_id          in number,
11134                                       p_return_code          in out nocopy number,
11135                                       p_return_text          in out nocopy varchar2) is
11136 
11137 
11138 l_code                  number;
11139 l_time                  number;
11140 l_assignment_id         number;
11141 l_res_state_code        varchar2(2);
11142 l_res_county_code       varchar2(3);
11143 l_res_city_code         varchar2(4);
11144 l_res_state_name        varchar2(35);
11145 l_res_county_name       varchar2(35);
11146 l_res_city_name         varchar2(35);
11147 l_effective_end_date    date;
11148 l_ret_code              number;
11149 l_ret_text              varchar2(240);
11150 l_default_date          date;
11151 l_next_date             date;
11152 l_payroll_installed     boolean := FALSE;
11153 l_validation_start_date date;
11154 l_fed_exists            varchar2(1) := 'N';
11155 l_location_found        boolean := FALSE;
11156 l_end_date              date;
11157 l_next_start_date       date;
11158 l_ovrd_loc              number;
11159 
11160 
11161 
11162 
11163 
11164   /* Cursor to get the assignment if called from
11165     the address form. */
11166 /* rmonge  fix bug 3429449 */
11167 
11168   cursor csr_addr_get_assignment(p_person number) is
11169    select paf.assignment_id, min(paf.effective_start_date)
11170      from   per_addresses          pa,
11171             hr_soft_coding_keyflex hsck,
11172             per_assignments_f      paf
11173      where paf.person_id         = p_person
11174      and   paf.assignment_type   = 'E'
11175      and   paf.soft_coding_keyflex_id is not null
11176      and   paf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id
11177      and   paf.location_id       is not null
11178      and   paf.payroll_id        is not null
11179      and   paf.pay_basis_id      is not null
11180      and   pa.person_id           = paf.person_id
11181     --  and   pa.primary_flag        = 'Y'
11182      and (paf.effective_start_date between
11183         pa.date_from and nvl(pa.date_to,to_date('12/31/4712','MM/DD/YYYY'))
11184      or pa.date_from between paf.effective_start_date and paf.effective_end_date)
11185 group by assignment_id;
11186 
11187 
11188 
11189 /* old cursor */
11190 /*
11191   cursor csr_addr_get_assignment(p_person number) is
11192      select paf.assignment_id, min(paf.effective_start_date)
11193      from   per_addresses          pa,
11194             hr_soft_coding_keyflex hsck,
11195             per_assignments_f      paf
11196      where paf.person_id         = p_person
11197      and   paf.assignment_type   = 'E'
11198      and   paf.soft_coding_keyflex_id is not null
11199      and   paf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id
11200      and   paf.location_id       is not null
11201      and   paf.payroll_id        is not null
11202      and   paf.pay_basis_id      is not null
11203      and   pa.person_id           = paf.person_id
11204      and   pa.primary_flag        = 'Y'
11205 --     and  (paf.effective_end_date = to_date('12/31/4712','MM/DD/YYYY')
11206 
11207 --Added for bug 2535501 June 10, 2003 except for the group by
11208 -- p_effective_start_date is the p_date_from in the Address table
11209      and  paf.effective_end_date >= p_effective_start_date
11210 
11211  group by assignment_id ;
11212 */
11213 
11214 /* added a check for paf.effective_end_date for bug 1640913 */
11215 
11216   cursor csr_get_assignment(p_person number) is
11217      select paf.assignment_id, min(paf.effective_start_date)
11221      where paf.person_id      = p_person
11218      from   per_addresses          pa,
11219             hr_soft_coding_keyflex hsck,
11220             per_assignments_f      paf
11222      and   paf.assignment_type = 'E'
11223      and   paf.soft_coding_keyflex_id is not null
11224      and   paf.effective_end_date = to_date('12/31/4712','MM/DD/YYYY')
11225      and   paf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id
11226      and   paf.location_id is not null
11227      and   paf.payroll_id is not null
11228      and   paf.pay_basis_id is not null
11229      and   pa.person_id        = paf.person_id
11230      and   pa.primary_flag     = 'Y'
11231      group by assignment_id ;
11232 
11233   /* Cursor to check if the default tax rules criteria is
11234      met for the assignment. keep in mind the assignment
11235      does not necessarily have to be a primary assignment */
11236 
11237   cursor csr_chk_assignment(p_assignment number, p_session_date date) is
11238          select 1
11239          from   per_addresses          pa,
11240                 per_people_f           ppf,
11241                 hr_soft_coding_keyflex hsck,
11242                 per_assignments_f      paf
11243          where  paf.assignment_id = p_assignment
11244          and    p_session_date between paf.effective_start_date
11245                 and paf.effective_end_date
11246          and    paf.soft_coding_keyflex_id is not null
11247          and    paf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id
11248          and    paf.location_id is not null
11249          and    paf.payroll_id is not null
11250          and    paf.pay_basis_id is not null
11251          and    ppf.person_id    = paf.person_id
11252          and    pa.person_id     = ppf.person_id
11253          and    pa.primary_flag     = 'Y';
11254 
11255   /* Get the minimum effective start date of the assignment for which
11256      the defaulting criteria has been satisfied */
11257 
11258   cursor csr_get_min_eff_date(p_assignment number) is
11259          select min(paf.effective_start_date)
11260          from   per_addresses          pa,
11261                 per_people_f           ppf,
11262                 hr_soft_coding_keyflex hsck,
11263                 per_assignments_f      paf
11264          where  paf.assignment_id = p_assignment
11265          and    paf.soft_coding_keyflex_id is not null
11266          and    paf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id
11267          and    paf.location_id is not null
11268          and    paf.payroll_id is not null
11269          and    paf.pay_basis_id is not null
11270          and    ppf.person_id    = paf.person_id
11271          and    pa.person_id     = ppf.person_id
11272          and    pa.primary_flag     = 'Y';
11273 
11274   cursor csr_get_default_date (p_assignment number) is
11275          select min(effective_start_date)
11276          from   PAY_US_EMP_FED_TAX_RULES_F pef
11277          where  pef.assignment_id = p_assignment;
11278 
11279   cursor csr_get_end_date (p_assignment number,p_default_date date) is
11280          select effective_end_date
11281          from   PAY_US_EMP_FED_TAX_RULES_F pef
11282          where  pef.assignment_id = p_assignment
11283          and    pef.effective_start_date = p_default_date;
11284 
11285 cursor csr_chk_addr_ovrd(p_assignment number) is
11286  select  pus.state_code,
11287          puc.county_code,
11288          pcn.city_code
11289   from   pay_us_city_names pcn,
11290          pay_us_counties puc,
11291          pay_us_states pus,
11292          per_addresses pa,
11293          per_assignments_f paf
11294   where  paf.assignment_id         = p_assignment
11295   and    p_effective_start_date between paf.effective_start_date and
11296                                 paf.effective_end_date
11297   and    pa.person_id              = paf.person_id
11298   and    pa.primary_flag           = 'Y'
11299   and    p_effective_start_date between pa.date_from and
11300                                      nvl(pa.date_to,to_date('12/31/4712','MM/DD/YYYY'))
11301   and    pa.add_information17 is not null
11302   and    pa.add_information19 is not null
11303   and    pa.add_information18 is not null
11304   and pa.add_information17 = pus.state_abbrev
11305   and puc.state_code = pus.state_code
11306   and puc.county_name = pa.add_information19
11307   and pcn.state_code = puc.state_code
11308   and pcn.county_code = puc.county_code
11309   and pcn.city_name = add_information18;
11310 
11311 /* rmonge fix for 3429449 */
11312 /* adding new cursor to handle the call to csr_chk_addr_ovrd in the case of a  */
11313 /* new Assignment with tax override . I need to pass p_effective_start_date */
11314 /* the original cursor does not allow me to pass it */
11315 
11316 cursor csr_chk_addr_ovrd_2(p_assignment number,p_effective_start_date date ) is
11317  select  pus.state_code,
11318          puc.county_code,
11319          pcn.city_code
11320   from   pay_us_city_names pcn,
11321          pay_us_counties puc,
11322          pay_us_states pus,
11323          per_addresses pa,
11324          per_assignments_f paf
11325   where  paf.assignment_id         = p_assignment
11326   and    p_effective_start_date between paf.effective_start_date and
11327                                 paf.effective_end_date
11328   and    pa.person_id              = paf.person_id
11329   and    pa.primary_flag           = 'Y'
11330   and    p_effective_start_date between pa.date_from and
11334   and    pa.add_information18 is not null
11331                                      nvl(pa.date_to,to_date('12/31/4712','MM/DD/YYYY'))
11332   and    pa.add_information17 is not null
11333   and    pa.add_information19 is not null
11335   and pa.add_information17 = pus.state_abbrev
11336   and puc.state_code = pus.state_code
11337   and puc.county_name = pa.add_information19
11338   and pcn.state_code = puc.state_code
11339   and pcn.county_code = puc.county_code
11340   and pcn.city_name = add_information18;
11341 
11342 /* rmonge end of changes */
11343 
11344 /* begin modifications - dscully 21-JUN-2000 */
11345 /* removed nvl to default return to location id */
11346 /* instead, if cursor is NOTFOUND, we use location id */
11347 cursor csr_get_ovrd_loc(p_assignment number, p_session_dt date) is
11348  select hsck.segment18
11349  from   HR_SOFT_CODING_KEYFLEX hsck,
11350         PER_ASSIGNMENTS_F      paf
11351  where  paf.assignment_id = p_assignment
11352  and    p_session_dt between paf.effective_start_date
11353                      and paf.effective_end_date
11354  and    hsck.soft_coding_keyflex_id = paf.soft_coding_keyflex_id
11355  and    hsck.segment18 is not null;
11356 
11357 /* end modifications - dscully 21-JUN-2000 */
11358 
11359 /* begin modifications - dscully 20-jul-2000 */
11360 /* added cursors and vars for location maintenance in non payroll installs */
11361 
11362 cursor csr_max_loc_date(p_assignment_id NUMBER, p_loc_id NUMBER
11363 		       ,p_ef_date DATE) is
11364 	select	min(paf.effective_start_date) - 1
11365 	  from	per_assignments_f paf
11366 	 where  paf.assignment_id = p_assignment_id
11367 	   and	paf.effective_start_date > p_ef_date
11368 	   and	paf.location_id <> p_loc_id;
11369 
11370 cursor csr_min_loc_date(p_assignment_id NUMBER, p_loc_id NUMBER
11371 		       ,p_ef_date DATE) is
11372 	select 	max(paf.effective_end_date) + 1
11373 	  from 	per_assignments_f paf
11374 	 where 	paf.assignment_id = p_assignment_id
11375 	   and	paf.effective_end_date < p_ef_date
11376 	   and 	paf.location_id <> p_loc_id;
11377 
11378 cursor csr_fed_tax_loc(p_assignment_id NUMBER, p_min_date DATE
11379 		      ,p_max_date DATE) is
11380 	select	*
11381 	  from	pay_us_emp_fed_tax_rules_f ftr
11382 	 where	ftr.assignment_id = p_assignment_id
11383 	   and	ftr.effective_start_date <= p_max_date
11384 	   and	ftr.effective_end_date >= p_min_date;
11385 
11386 cursor csr_loc_state_code(p_location_id NUMBER) is
11387 	select 	pus.state_code
11388 	  from 	pay_us_states pus,
11389 		hr_locations hl
11390 	 where	hl.location_id = p_location_id
11391 	   and	pus.state_abbrev = nvl(loc_information17,region_2);
11392 
11393 /* end modifications - dscully 20-jul-2000*/
11394 
11395 l_loc_min_date date;
11396 l_loc_max_date date;
11397 l_loc_state_code pay_us_states.state_code%TYPE;
11398 
11399 
11400 l_add_state_code   varchar2(2);
11401 l_add_county_code varchar2(3);
11402 l_add_city_code   varchar2(4);
11403 l_loc_id          hr_locations.location_id%TYPE;
11404 
11405 begin
11406 
11407   -- hr_utility.trace_on(null,'AMITA');
11408   hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',1);
11409 
11410   hr_utility.trace('validate_default-asg ** ' || to_char(p_assignment_id));
11411   hr_utility.trace('validate_default-person id ** ' || to_char(p_person_id));
11412   hr_utility.trace('validate_default-eff start dt ** ' || to_char(p_effective_start_date,'dd-mon-yyyy'));
11413   hr_utility.trace('validate_defaulteff end dt ** ' || to_char(p_effective_end_date,'dd-mon-yyyy'));
11414   hr_utility.trace('validate_default - session dt ** ' || to_char(p_session_date,'dd-mon-yyyy'));
11415   hr_utility.trace('validate_default- bg ** ' || to_char(p_business_group_id));
11416   hr_utility.trace('validate_default - form name ** ' || p_from_form);
11417   hr_utility.trace('validate_default - mode ** ' || p_mode);
11418   hr_utility.trace('validate_default - location id ** ' || to_char(p_location_id));
11419   --dbms_output.put_line('asg** '||to_char(p_assignment_id));
11420   --dbms_output.put_line('asg** '||to_char(p_person_id));
11421   --dbms_output.put_line('sd** '||to_char(p_effective_start_date));
11422   --dbms_output.put_line('ed** '||to_char(p_effective_end_date));
11423   --dbms_output.put_line('sd** '||to_char(p_session_date));
11424   --dbms_output.put_line('bg** ' || to_char(p_business_group_id));
11425   --dbms_output.put_line('bg** ' || p_from_form);
11426   --dbms_output.put_line('bg** ' || p_mode);
11427   --dbms_output.put_line('bg** ' || to_char(p_location_id));
11428 
11429   /* First check if geocode has been installed or not. If no geocodes
11430      installed then return because there is nothing to be done by this
11431      defaulting procedure */
11432 
11433   if hr_general.chk_maintain_tax_records = 'N' then
11434      return;
11435   end if;
11436 
11437   /* Check if payroll has been installed or not */
11438 
11439   l_payroll_installed := hr_utility.chk_product_install(p_product =>'Oracle Payroll',                                                                           p_legislation => 'US');
11440 
11441   /* Set up the validation start date */
11442 
11443   if p_from_form = 'Assignment' then
11444 
11445         if (p_mode = 'CORRECTION' or p_mode is null) then
11446            l_validation_start_date := p_effective_start_date;
11447         else
11451   end if;
11448             l_validation_start_date := p_session_date;
11449         end if;
11450 
11452 
11453   if p_from_form = 'Address' then
11454 
11455       hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',2);
11456 
11457      /* Get all of the assignments */
11458 
11459      open csr_addr_get_assignment(p_person_id);
11460 
11461 
11462      loop
11463 
11464         fetch csr_addr_get_assignment into l_assignment_id, l_validation_start_date;
11465 
11466 
11467 
11468         exit when csr_addr_get_assignment%NOTFOUND;
11469 
11470         hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',3);
11471 
11472         /* Check whether the defaulting of tax rules has been done or not.
11473            If not then do the defaulting of tax rules else return 'Y' in
11474            l_fed_exists to indicate that the defaulting of tax rules has
11475            already taken place. */
11476 
11477         check_defaulting(p_assignment_id        => l_assignment_id,
11478                          p_effective_start_date => l_validation_start_date,
11479                          p_business_group_id    => p_business_group_id,
11480                          p_from_form            => 'Address',
11481                          p_fed_exists           => l_fed_exists,
11482                          p_ret_code             => p_return_code,
11483                          p_ret_text             => p_return_text);
11484 
11485         if l_fed_exists = 'Y' then
11486 
11487            /* The following logic will take care of the affect of change in
11488               resident address to the tax rules records and the tax %age
11489              records.
11490              Get the state code, county code and the city code for the resident
11491              address */
11492 
11493            pay_us_emp_dt_tax_val.get_orig_res_codes (p_assignment_id    => l_assignment_id,
11494                           p_session_date     => p_effective_start_date,
11495                           p_res_state_code   => l_res_state_code,
11496                           p_res_county_code  => l_res_county_code,
11497                           p_res_city_code    => l_res_city_code,
11498                           p_res_state_name   => l_res_state_name,
11499                           p_res_county_name  => l_res_county_name,
11500                           p_res_city_name    => l_res_city_name);
11501 
11502            open csr_chk_addr_ovrd_2(l_assignment_id,greatest(p_effective_start_date,l_validation_start_date ));
11503            fetch csr_chk_addr_ovrd_2 into l_add_state_code,
11504                                         l_add_county_code,
11505                                         l_add_city_code;
11506 
11507 
11508            if csr_chk_addr_ovrd_2%NOTFOUND then
11509               l_add_state_code := null;
11510               l_add_county_code := null;
11511               l_add_city_code := null;
11512 
11513            end if;
11514            close csr_chk_addr_ovrd_2;
11515 
11516            /* create the state, county and tax records for the resident address,
11517               if they do not already exist. The following routine will first
11518               check for the existence of the record. Only if the record does
11519               not exist, it will create one along with its corresponding %age
11520               record */
11521 
11522 
11523            if l_res_state_code is not null and l_res_county_code is not null
11524            and l_res_city_code is not null then
11525 
11526                create_new_location_rec(p_assignment_id        => l_assignment_id,
11527                                    p_validation_start_date => null,
11528                                    p_validation_end_date   => null,
11529                                    p_session_date          => null,
11530                                    p_new_location_id       => null,
11531                                    p_res_state_code        => l_res_state_code,
11532                                    p_res_county_code       => l_res_county_code,
11533                                    p_res_city_code         => l_res_city_code,
11534                                    p_business_group        => p_business_group_id,
11535                                    p_percent               => 0);
11536            end if;
11537 
11538            if l_add_state_code is not null and l_add_county_code is not null
11539            and l_add_city_code is not null then
11540 
11541                create_new_location_rec(p_assignment_id        => l_assignment_id,
11542                                    p_validation_start_date => null,
11543                                    p_validation_end_date   => null,
11544                                    p_session_date          => null,
11545                                    p_new_location_id       => null,
11546                                    p_res_state_code        => l_add_state_code,
11547                                    p_res_county_code       => l_add_county_code,
11548                                    p_res_city_code         => l_add_city_code,
11549                                    p_business_group        => p_business_group_id,
11550                                    p_percent               => 0);
11551            end if;
11552 
11553 
11554        end if;
11555 
11556      end loop;
11557 
11558      close csr_addr_get_assignment;
11559 
11560   end if; /* End of address form specific */
11561 
11562 
11563   /* The person package will call this routine if and only if the
11564      hiring date is pulled back */
11565 
11566   if p_from_form = 'Person' then
11567 
11571 
11568     /* Get all of the employee assignments for the person */
11569 
11570     open csr_get_assignment(p_person_id);
11572     loop
11573        fetch csr_get_assignment into l_assignment_id, l_validation_start_date;
11574 
11575        exit when csr_get_assignment%NOTFOUND;
11576 
11577        hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',3);
11578 
11579        /* Check whether the defaulting of tax rules has been done or not.
11580           If not then do the defaulting of tax rules else return 'Y' in
11581           l_fed_exists to indicate that the defaulting of tax rules has
11582           already taken place. */
11583 
11584 
11585        check_defaulting(p_assignment_id        => l_assignment_id,
11586                         p_effective_start_date => l_validation_start_date,
11587                         p_business_group_id    => p_business_group_id,
11588                         p_from_form            => 'Person',
11589                         p_fed_exists           => l_fed_exists,
11590                         p_ret_code             => p_return_code,
11591                         p_ret_text             => p_return_text);
11592 
11593         /* If the defaulting has take place i.e. tax records exist then pull
11594            back the tax rules as well as the tax %age records */
11595 
11596         if l_fed_exists = 'Y' then
11597 
11598           /* Get the default date */
11599 
11600           open csr_get_default_date(l_assignment_id);
11601 
11602           fetch csr_get_default_date into l_default_date;
11603 
11604           if l_default_date is null then
11605 
11606              close csr_get_default_date;
11607              fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
11608              fnd_message.set_token('PROCEDURE',
11609              'pay_us_emp_dt_tax_rules.default_tax_with_validation');
11610              fnd_message.set_token('STEP','1');
11611              fnd_message.raise_error;
11612 
11613           end if;
11614 
11615          close csr_get_default_date;
11616 
11617          /* Now check for pull back of the hiring date */
11618 
11619          check_hiring_date(p_assignment_id  => l_assignment_id,
11620                            p_default_date   => l_default_date,
11621                            p_s_start_date   => p_effective_start_date);
11622 
11623       end if;
11624 
11625     end loop;
11626 
11627     close csr_get_assignment;
11628 
11629   end if;  /* End of Person form processing */
11630 
11631   if p_from_form = 'Assignment' or p_from_form = 'Tax Rules' then
11632 
11633      hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',5);
11634 
11635      if p_from_form = 'Tax Rules' then
11636 
11637         /* Get the min effective start date of the assignment for which the
11638            defaulting criteria has been met */
11639 
11640         open csr_get_min_eff_date(p_assignment_id);
11641 
11642         fetch csr_get_min_eff_date into l_validation_start_date;
11643 
11644         if l_validation_start_date is null then
11645 
11646            hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',6);
11647 
11648            p_return_code := 1;
11649            p_return_text := 'Default rules not satisfied';
11650            close csr_get_min_eff_date;
11651            return;
11652 
11653         end if;
11654 
11655         close csr_get_min_eff_date;
11656 
11657      elsif p_from_form = 'Assignment' then
11658 
11659         open csr_chk_assignment(p_assignment_id, l_validation_start_date);
11660 
11661         fetch csr_chk_assignment into l_code;
11662 
11663         if csr_chk_assignment%NOTFOUND then
11664 
11665            hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',7);
11666 
11667            p_return_code := 1;
11668            p_return_text := 'Default rules not satisfied';
11669            close csr_chk_assignment;
11670            return;
11671 
11672         end if;
11673 
11674         close csr_chk_assignment;
11675 
11676      end if;
11677 
11678      /* Assign the assignment id to the l_assignment_id so that the same
11679         variable can be used for all of the forms, to call the default_tax
11680         routine */
11681 
11682      l_assignment_id := p_assignment_id;
11683 
11684      /* Check whether the defaulting of tax rules has been done or not.
11685         If not then do the defaulting of tax rules else return 'Y' in
11686         l_fed_exists to indicate that the defaulting of tax rules has
11687         already taken place. */
11688 
11689      check_defaulting(p_assignment_id        => p_assignment_id,
11690                       p_effective_start_date => l_validation_start_date,
11691                       p_business_group_id    => p_business_group_id,
11692                       p_from_form            => p_from_form,
11693                       p_fed_exists           => l_fed_exists,
11694                       p_ret_code             => p_return_code,
11695                       p_ret_text             => p_return_text);
11696 
11697      /* We will commit only if this routine has been called by the 'Tax Rules
11698         screen' and the defaulting of tax rules has gone through fine. We
11699         cannot commit in the Tax Rules screen because this routine gets
11700         called in the when new form instance trigger and if we commit after
11704      if l_fed_exists = 'N' and
11701         that the date tracked modes come up. So, commit if and only if called
11702         by the Tax Rules i.e. the W4 screen */
11703 
11705         p_from_form = 'Tax Rules' and p_return_code = 0 then
11706 
11707          commit;
11708 
11709      end if;
11710 
11711 
11712      if l_fed_exists = 'Y' then
11713 
11714         /* Get the default date */
11715 
11716         open csr_get_default_date(p_assignment_id);
11717 
11718         fetch csr_get_default_date into l_default_date;
11719 
11720         if csr_get_default_date%NOTFOUND then
11721 
11722            close csr_get_default_date;
11723            fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
11724            fnd_message.set_token('PROCEDURE',
11725            'pay_us_emp_dt_tax_rules.default_tax_with_validation');
11726            fnd_message.set_token('STEP','2');
11727            fnd_message.raise_error;
11728 
11729         end if;
11730 
11731         close csr_get_default_date;
11732 
11733      end if;
11734 
11735   end if; /* This marks the end of processing when called by the 'Tax Rules */
11736 
11737   hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',8);
11738 
11739 
11740   /* begin modifications - dscully 21-JUN-2000 */
11741   /* added default creation of tax records for taxation location */
11742 
11743   if p_from_form = 'Assignment' then
11744 
11745      l_assignment_id := p_assignment_id;
11746 
11747      /* check to see if there is an override location at the asg. level .
11748         If there is then set the override as p_location_id */
11749      l_loc_id := p_location_id;
11750      open csr_get_ovrd_loc(l_assignment_id, p_session_date);
11751      fetch csr_get_ovrd_loc into l_ovrd_loc;
11752      if csr_get_ovrd_loc%found then
11753            l_loc_id := l_ovrd_loc;
11754      end if;
11755      close csr_get_ovrd_loc;
11756 
11757      /* if a taxation location is set on the assignment create a default tax record */
11758      if l_ovrd_loc is not null then
11759 
11760 	/* this procedure checks to make sure record does not yet exist */
11761 	/* the date params are null because they only matter when setting non-zero
11762 	   percentages */
11763 
11764 	create_new_location_rec(p_assignment_id => p_assignment_id,
11765                                   p_validation_start_date => null,
11766                                   p_validation_end_date   => null,
11767                                   p_session_date          => null,
11768                                   p_new_location_id       => l_ovrd_loc,
11769                                   p_res_state_code        => null,
11770                                   p_res_county_code       => null,
11771                                   p_res_city_code         => null,
11772                                   p_business_group        => p_business_group_id,
11773                                   p_percent               => 0); /* if l_ovrd_loc is not null */
11774 
11775 -- Added to take care SUI Wage Base Override enh
11776 -- Turning Off SUI Wage Base Override Functionality due to Bug# 5486281
11777      /*
11778      else
11779          -- Start of SUI Wage Base Override Change
11780 	     --
11781          -- Update SUI WAGE BASE Overide amount you have payroll installed otherwise don't
11782 	     -- call the procedure which does the update
11783 
11784 
11785          IF  hr_utility.chk_product_install(p_product =>'Oracle Payroll',
11786                                             p_legislation => 'US')
11787          then
11788                   if p_assignment_id is not null and p_session_date is not null
11789         		  then
11790                        set_sui_wage_base_override(p_assignment_id,
11791 		                                          null,
11792 									              p_session_date) ;
11793                   end if ;
11794          end if;
11795 	      --
11796           -- End of SUI Wage Base Override Change
11797 	      --
11798       */
11799      end if; /* if l_ovrd_loc is not null */
11800 
11801      /* if the location changed do a bunch of element entry manipulation */
11802 
11803      if (p_location_id is not null) then
11804 
11805      if (l_payroll_installed) then
11806       /* end modifications - dscully 21-JUN-2000 */
11807       /* begin modifications - dscully 19-JUL-2000 */
11808       /* added code to handle location changes for non-payroll customers */
11809 
11810       if p_mode = 'CORRECTION' then
11811 
11812         /*
11813 
11814                      | Session date
11815                      v
11816               L1    L2     L3            L4            L4
11817         Asg |-----|-----|-------------|--------------|------
11818         Fed             |-------------|---------------------
11819         %age            |-------------|---------------------
11820         */
11821 
11822         if p_effective_end_date < l_default_date then
11823 
11824            select p_effective_end_date + 1
11825            into   l_next_date
11826            from   SYS.DUAL;
11827 
11828            if l_next_date < l_default_date then
11829 
11830              /* There are some more assignment records without the
11831                 tax records. So, error it out */
11832 
11833               fnd_message.set_name('PAY', 'PAY_52292_TAX_DEF_CRT');
11834               fnd_message.raise_error;
11835 
11839 
11836            else
11837 
11838               /* First update the tax rules records */
11840               pull_tax_records(p_assignment_id     => l_assignment_id,
11841                                p_new_start_date    => p_effective_start_date,
11842                                p_default_date      => l_default_date);
11843 
11844               /* set the effective start date of the wc entry to the
11845                  new effective start date i.e. the p_effective_start_date */
11846 
11847               del_updt_wc_entry_for_dates (p_assignment_id   => l_assignment_id,
11848                                       p_session_date         => l_default_date,
11849                                       p_new_start_date       => p_effective_start_date,
11850                                       p_new_end_date         => null,
11851                                       p_mode                 => 'U');
11852 
11853                pull_percentage(p_assignment_id        => l_assignment_id,
11854                                p_default_date         => l_default_date,
11855                                p_effective_start_date => p_effective_start_date,
11856                                p_effective_end_date   => p_effective_end_date,
11857                                p_session_date         => p_session_date,
11858                                p_new_location_id      => p_location_id,
11859                                p_business_group_id    => p_business_group_id);
11860              end if;
11861         else
11862 
11863           /* Correct the federal tax record and the worker's comp element entry for
11864              the new SUI Jurisdiction code and SUI state */
11865 
11866           change_wc_entry (p_assignment_id        => l_assignment_id,
11867                            p_effective_start_date => p_effective_start_date,
11868                            p_effective_end_date   => p_effective_end_date,
11869                            p_session_date         => p_session_date,
11870                            p_new_location_id      => l_loc_id,
11871                            p_mode                 => p_mode,
11872                            p_ret_code             => l_ret_code,
11873                            p_ret_text             => l_ret_text);
11874 
11875           /* Change the tax %age records for a correction in the
11876              location of the assignment */
11877 
11878           correct_percentage (p_assignment_id        => l_assignment_id,
11879                               p_effective_start_date => p_effective_start_date,
11880                               p_effective_end_date   => p_effective_end_date,
11881                               p_session_date         => p_session_date,
11882                               p_new_location_id      => p_location_id,
11883                               p_business_group_id    => p_business_group_id,
11884                               p_ret_code             => l_ret_code,
11885                               p_ret_text             => l_ret_text);
11886 
11887         end if;
11888 
11889       elsif p_mode in ('UPDATE','UPDATE_OVERRIDE','UPDATE_CHANGE_INSERT') then
11890 
11891           /* Update the federal tax record and the worker's comp element entry for
11892              the new SUI Jurisdiction code and SUI state */
11893 
11894           change_wc_entry (p_assignment_id        => l_assignment_id,
11895                            p_effective_start_date => p_effective_start_date,
11896                            p_effective_end_date   => p_effective_end_date,
11897                            p_session_date         => p_session_date,
11898                            p_new_location_id      => l_loc_id,
11899                            p_mode                 => p_mode,
11900                            p_ret_code             => l_ret_code,
11901                            p_ret_text             => l_ret_text);
11902 
11903          /* Change the %age records for the type of update in the
11904             location of the assignment */
11905 
11906          update_percentage (p_assignment_id        => l_assignment_id,
11907                             p_effective_start_date => p_effective_start_date,
11908                             p_effective_end_date   => p_effective_end_date,
11909                             p_session_date         => p_session_date,
11910                             p_new_location_id      => p_location_id,
11911                             p_business_group_id    => p_business_group_id,
11912                             p_mode                 => p_mode,
11913                             p_ret_code             => l_ret_code,
11914                             p_ret_text             => l_ret_text);
11915 
11916       elsif p_mode = 'DELETE_NEXT_CHANGE' then
11917 
11918          /* In case of DELETE_NEXT_CHANGE, if the next location is different from
11919             the current location then the assignment screen will error it out.
11920             If the next location is same as the current location then :
11921 
11922                                   | Session Date
11923                              L1   v               L1
11924             Asg.      |--------------------|-------------------------
11925             Tax Rules                      |-------------------------
11926             Tax %age                       |-------------------------
11927 
11928             In this scenario, the assignment routine deletes the tax %age records
11929             but does not delete the tax rules records. So, our tax routine will have
11930             to delete the tax rules records.
11931 
11932                              | Session Date
11933                       T1     v  T2        T3       T4      T5
11937             Tax %age            |------------------------------------
11934                           L1         L1       L1      L1       L1
11935             Asg.      |---------|---------|--------|-------|---------
11936             Tax Rules           |------------------------------------
11938 
11939             Here, the tax rules and the tax %age records will have to be pulled forward to
11940             time T3.
11941 
11942                                        | Session Date
11943                           L1        L1 v     L1      L2       L3
11944             Asg.      |---------|---------|--------|-------|---------
11945             Tax Rules           |------------------------------------
11946             Tax %age            |------------------|-------|---------
11947 
11948             In the above scenario, the assignment routine will only delete the next
11949             assignment record and will not do anything to the tax %age records, which
11950             is fine and that's how it should be.
11951 
11952                                                         | Session Date
11953                           L1        L1       L1      L3 v     L3
11954             Asg.      |---------|---------|--------|-------|---------
11955             Tax Rules           |------------------------------------
11956             Tax %age            |------------------|-----------------
11957 
11958             Here also, we do not need to do anything as the %age records do not get affected
11959             by the deletion of the assignment record.  */
11960 
11961             open csr_get_end_date(p_assignment_id,l_default_date);
11962 
11963             fetch csr_get_end_date into l_end_date;
11964 
11965             if csr_get_end_date%NOTFOUND then
11966 
11967                close csr_get_end_date;
11968                fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
11969                fnd_message.set_token('PROCEDURE',
11970                'pay_us_emp_dt_tax_rules.default_tax_with_validation');
11971                fnd_message.set_token('STEP','3');
11972                fnd_message.raise_error;
11973 
11974             end if;
11975 
11976             close csr_get_end_date;
11977 
11978 
11979             if (l_end_date   = to_date('31-12-4712','dd-mm-yyyy')) and
11980             not pay_us_emp_dt_tax_val.check_locations(p_assignment_id => p_assignment_id,
11981                                            p_effective_start_date => p_session_date,
11982                                            p_business_group_id    => p_business_group_id)
11983             then
11984 
11985                 /* Delete records from PAY_US_EMP_CITY_TAX_RULES_F */
11986 
11987                 delete PAY_US_EMP_CITY_TAX_RULES_F
11988                 where assignment_id = p_assignment_id
11989                 and business_group_id = p_business_group_id;
11990 
11991                 /* Delete records from PAY_US_EMP_COUNTY_TAX_RULES_F */
11992 
11993                 delete PAY_US_EMP_COUNTY_TAX_RULES_F
11994                 where assignment_id = p_assignment_id
11995                 and business_group_id = p_business_group_id;
11996 
11997                 /* Delete records from PAY_US_EMP_STATE_TAX_RULES_F */
11998 
11999                 delete PAY_US_EMP_STATE_TAX_RULES_F
12000                 where assignment_id = p_assignment_id
12001                 and business_group_id = p_business_group_id;
12002 
12003                 /* Delete records from PAY_US_EMP_FED_TAX_RULES_F */
12004 
12005                 delete PAY_US_EMP_FED_TAX_RULES_F
12006                 where assignment_id = p_assignment_id
12007                 and business_group_id = p_business_group_id;
12008 
12009             else
12010 
12011                  select l_default_date + 1
12012                  into l_next_start_date
12013                  from DUAL;
12014 
12015                  pull_tax_records(p_assignment_id     => p_assignment_id,
12016                                   p_new_start_date    => l_next_start_date,
12017                                   p_default_date      => l_default_date);
12018             end if;
12019 
12020       elsif p_mode = 'FUTURE_CHANGE' then
12021 
12022          /* Delete the next set of %age records */
12023             upd_del_entries(p_assignment_id  => l_assignment_id,
12024                             p_session_date   => p_session_date,
12025                             p_new_start_date => null,
12026                             p_new_end_date   => null,
12027                             p_mode           => 'F');
12028 
12029       end if; /* for correction/update/delete */
12030 
12031     /* begin modifications - dscully 20-jul-2000 */
12032     /* added hr only location code */
12033 
12034     else -- payroll is not installed
12035 
12036      /* This is being added for customers with the NA Address Patch but not payroll */
12037      /* In a perfect world, we would wrap the element entry code in the location maintenance */
12038      /* with if_payroll_installed checks.  However, since this is payroll, that would make too */
12039      /* much sense.  Because of the amount of ugliness and QA involved in retesting it in a */
12040      /* payroll context, we are just tacking on this code instead. */
12041 
12042      /* Because there are no element entries, we determine changes in location by looking at */
12043      /* the assignment record itself(which might be a better way of doing it!). */
12044 
12045      /* first lets make sure the record exists */
12046 
12050                                   p_validation_start_date => null,
12047      hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',100);
12048 
12049      create_new_location_rec(p_assignment_id => p_assignment_id,
12051                                   p_validation_end_date   => null,
12052                                   p_session_date          => null,
12053                                   p_new_location_id       => p_location_id,
12054                                   p_res_state_code        => null,
12055                                   p_res_county_code       => null,
12056                                   p_res_city_code         => null,
12057                                   p_business_group        => p_business_group_id,
12058                                   p_percent               => 0);
12059 
12060 
12061      /* next we get the begin and end dates for the new location being effective
12062         along with the state code of the jurisdiction */
12063 
12064      hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',105);
12065 
12066      open csr_max_loc_date(p_assignment_id,p_location_id,l_validation_start_date);
12067      fetch csr_max_loc_date into l_loc_max_date;
12068      close csr_max_loc_date;
12069 
12070      if l_loc_max_date is null then
12071 	l_loc_max_date := hr_api.g_eot;
12072      end if;
12073 
12074      --
12075 
12076      hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',110);
12077 
12078      open csr_min_loc_date(p_assignment_id,p_location_id,l_validation_start_date);
12079      fetch csr_min_loc_date into l_loc_min_date;
12080      close csr_min_loc_date;
12081 
12082      if l_loc_min_date is null then
12083 	l_loc_min_date := hr_api.g_sot;
12084      end if;
12085 
12086      --
12087      hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',115);
12088 
12089      open csr_loc_state_code(p_location_id);
12090      fetch csr_loc_state_code into l_loc_state_code;
12091 
12092      if csr_loc_state_code%NOTFOUND then
12093              close csr_loc_state_code;
12094              fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
12095              fnd_message.set_token('PROCEDURE',
12096              'pay_us_emp_dt_tax_rules.default_tax_with_validation');
12097              fnd_message.set_token('STEP','10');
12098              fnd_message.raise_error;
12099      end if;
12100 
12101      close csr_loc_state_code;
12102 
12103      --
12104 
12105      /* we update all records that partially fall within that date range */
12106 
12107      for tax_rec in csr_fed_tax_loc(p_assignment_id,l_loc_min_date,l_loc_max_date) loop
12108 
12109 	if tax_rec.effective_start_date < l_loc_min_date then
12110 
12111 	/* we go from:
12112 		ASG --------------|-------L1-----------------
12113 		TAX ----------|------------------------------
12114 	   to:
12115 		ASG --------------|-------L1-----------------
12119 
12116 		TAX ----------|---|--------------------------
12117 	*/
12118   	        hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',120);
12120 		/* insert the middle record */
12121 		insert_fed_tax_row(
12122      			tax_rec.emp_fed_tax_rule_id,
12123       			l_loc_min_date,
12124       			tax_rec.effective_end_date,
12125       			tax_rec.assignment_id,
12126       			l_loc_state_code,
12127       			l_loc_state_code || '-000-0000',
12128       			tax_rec.business_group_id,
12129       			tax_rec.additional_wa_amount,
12130       			tax_rec.filing_status_code,
12131       			tax_rec.fit_override_amount,
12132       			tax_rec.fit_override_rate,
12133       			tax_rec.withholding_allowances,
12134       			tax_rec.cumulative_taxation,
12135       			tax_rec.eic_filing_status_code,
12136       			tax_rec.fit_additional_tax,
12137       			tax_rec.fit_exempt,
12138       			tax_rec.futa_tax_exempt,
12139       			tax_rec.medicare_tax_exempt,
12140       			tax_rec.ss_tax_exempt,
12141       			tax_rec.wage_exempt,
12142       			tax_rec.statutory_employee,
12143       			tax_rec.w2_filed_year,
12144       			tax_rec.supp_tax_override_rate,
12145       			tax_rec.excessive_wa_reject_date,
12146                 tax_rec.attribute_category,
12147                 tax_rec.attribute1,
12148                 tax_rec.attribute2,
12149                 tax_rec.attribute3,
12150                 tax_rec.attribute4,
12151                 tax_rec.attribute5,
12152                 tax_rec.attribute6,
12153                 tax_rec.attribute7,
12154                 tax_rec.attribute8,
12155                 tax_rec.attribute9,
12156                 tax_rec.attribute10,
12157                 tax_rec.attribute11,
12158                 tax_rec.attribute12,
12159                 tax_rec.attribute13,
12160                 tax_rec.attribute14,
12161                 tax_rec.attribute15,
12162                 tax_rec.attribute16,
12163                 tax_rec.attribute17,
12164                 tax_rec.attribute18,
12165                 tax_rec.attribute19,
12166                 tax_rec.attribute20,
12167                 tax_rec.attribute21,
12168                 tax_rec.attribute22,
12169                 tax_rec.attribute23,
12170                 tax_rec.attribute24,
12171                 tax_rec.attribute25,
12172                 tax_rec.attribute26,
12173                 tax_rec.attribute27,
12174                 tax_rec.attribute28,
12175                 tax_rec.attribute29,
12176                 tax_rec.attribute30,
12177                 tax_rec.fed_information_category,
12178                 tax_rec.fed_information1,
12179                 tax_rec.fed_information2,
12180                 tax_rec.fed_information3,
12181                 tax_rec.fed_information4,
12182                 tax_rec.fed_information5,
12183                 tax_rec.fed_information6,
12184                 tax_rec.fed_information7,
12188                 tax_rec.fed_information11,
12185                 tax_rec.fed_information8,
12186                 tax_rec.fed_information9,
12187                 tax_rec.fed_information10,
12189                 tax_rec.fed_information12,
12190                 tax_rec.fed_information13,
12191                 tax_rec.fed_information14,
12192                 tax_rec.fed_information15,
12193                 tax_rec.fed_information16,
12194                 tax_rec.fed_information17,
12195                 tax_rec.fed_information18,
12196                 tax_rec.fed_information19,
12197                 tax_rec.fed_information20,
12198                 tax_rec.fed_information21,
12199                 tax_rec.fed_information22,
12200                 tax_rec.fed_information23,
12201                 tax_rec.fed_information24,
12202                 tax_rec.fed_information25,
12203                 tax_rec.fed_information26,
12204                 tax_rec.fed_information27,
12205                 tax_rec.fed_information28,
12206                 tax_rec.fed_information29,
12207                 tax_rec.fed_information30,
12208 			'UPDATE');
12209 	else
12210 
12211 	/* here we simply update the sui codes */
12212 
12213   		hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',125);
12214 
12215 		update pay_us_emp_fed_tax_rules_f
12216 		   set sui_state_code = l_loc_state_code,
12217 		       sui_jurisdiction_code = l_loc_state_code || '-000-0000'
12218  		 where emp_fed_tax_rule_id = tax_rec.emp_fed_tax_rule_id
12219 		   and effective_start_date = tax_rec.effective_start_date;
12220 
12221 	end if;
12222 
12223 	if tax_rec.effective_end_date > l_loc_max_date then
12224 	/* we go from the case:
12225 		ASG -------L1-----------------|--------------
12226 		TAX --------------------------------|--------
12227 	   to
12228 		ASG -------L1-----------------|--------------
12229 		TAX --------------------------|-----|--------
12230 	*/
12231 
12232   		hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',130);
12233 
12234 		insert_fed_tax_row(
12235 	     		tax_rec.emp_fed_tax_rule_id,
12236       			l_loc_max_date + 1,
12237       			tax_rec.effective_end_date,
12238       			tax_rec.assignment_id,
12239       			tax_rec.sui_state_code,
12240       			tax_rec.sui_jurisdiction_code,
12241       			tax_rec.business_group_id,
12242       			tax_rec.additional_wa_amount,
12243       			tax_rec.filing_status_code,
12244       			tax_rec.fit_override_amount,
12245       			tax_rec.fit_override_rate,
12246       			tax_rec.withholding_allowances,
12247       			tax_rec.cumulative_taxation,
12248       			tax_rec.eic_filing_status_code,
12249       			tax_rec.fit_additional_tax,
12250       			tax_rec.fit_exempt,
12251       			tax_rec.futa_tax_exempt,
12252       			tax_rec.medicare_tax_exempt,
12253       			tax_rec.ss_tax_exempt,
12254       			tax_rec.wage_exempt,
12255       			tax_rec.statutory_employee,
12256       			tax_rec.w2_filed_year,
12257       			tax_rec.supp_tax_override_rate,
12258       			tax_rec.excessive_wa_reject_date,
12262                 tax_rec.attribute3,
12259                 tax_rec.attribute_category,
12260                 tax_rec.attribute1,
12261                 tax_rec.attribute2,
12263                 tax_rec.attribute4,
12264                 tax_rec.attribute5,
12265                 tax_rec.attribute6,
12266                 tax_rec.attribute7,
12267                 tax_rec.attribute8,
12268                 tax_rec.attribute9,
12269                 tax_rec.attribute10,
12270                 tax_rec.attribute11,
12271                 tax_rec.attribute12,
12272                 tax_rec.attribute13,
12273                 tax_rec.attribute14,
12274                 tax_rec.attribute15,
12275                 tax_rec.attribute16,
12276                 tax_rec.attribute17,
12277                 tax_rec.attribute18,
12278                 tax_rec.attribute19,
12279                 tax_rec.attribute20,
12280                 tax_rec.attribute21,
12281                 tax_rec.attribute22,
12282                 tax_rec.attribute23,
12283                 tax_rec.attribute24,
12284                 tax_rec.attribute25,
12285                 tax_rec.attribute26,
12286                 tax_rec.attribute27,
12287                 tax_rec.attribute28,
12288                 tax_rec.attribute29,
12289                 tax_rec.attribute30,
12290                 tax_rec.fed_information_category,
12291                 tax_rec.fed_information1,
12292                 tax_rec.fed_information2,
12293                 tax_rec.fed_information3,
12294                 tax_rec.fed_information4,
12295                 tax_rec.fed_information5,
12296                 tax_rec.fed_information6,
12297                 tax_rec.fed_information7,
12298                 tax_rec.fed_information8,
12299                 tax_rec.fed_information9,
12300                 tax_rec.fed_information10,
12301                 tax_rec.fed_information11,
12302                 tax_rec.fed_information12,
12303                 tax_rec.fed_information13,
12304                 tax_rec.fed_information14,
12305                 tax_rec.fed_information15,
12306                 tax_rec.fed_information16,
12307                 tax_rec.fed_information17,
12308                 tax_rec.fed_information18,
12309                 tax_rec.fed_information19,
12310                 tax_rec.fed_information20,
12311                 tax_rec.fed_information21,
12312                 tax_rec.fed_information22,
12313                 tax_rec.fed_information23,
12314                 tax_rec.fed_information24,
12315                 tax_rec.fed_information25,
12316                 tax_rec.fed_information26,
12317                 tax_rec.fed_information27,
12318                 tax_rec.fed_information28,
12319                 tax_rec.fed_information29,
12320                 tax_rec.fed_information30,
12321 			'UPDATE');
12322 	end if;
12323      end loop;
12324 
12325      /* end modifications - dscully 20-jul-2000 */
12326      hr_utility.set_location('pay_us_emp_dt_tax_rules.validate_default',140);
12327     end if; /* for payroll installed/not installed */
12328     end if; /* for location id is not null */
12329 
12330   end if; /* call from assignment form */
12331 
12332 
12333 
12334 end; /*default_tax_with_validation */
12335   /* Name        : check_nra_status
12336      Purpose     : To check whether the employee is a Non Resident Alien.
12337                    Internal revenue doesnot allow NRA to claim W4 allowances >1
12338      Added by vaprakas 12/5/2006 bug 5607135
12339 
12340   */
12341 procedure check_nra_status(p_assignment_id          in number,
12342                            p_withholding_allowances in number,
12343                            p_filing_status_code     in varchar2,
12344                            p_fit_exempt             in varchar2,
12345                            p_effective_start_date   in date,
12346                            p_effective_end_date     in date,
12347 			   p_returned_warning       OUT NOCOPY VARCHAR2)
12348 is
12349 l_information_type           per_people_extra_info.information_type%TYPE;
12350 l_pei_information_category   per_people_extra_info.pei_information_category%TYPE;
12351 l_pei_information5           per_people_extra_info.pei_information5%TYPE;
12352 l_pei_information9           per_people_extra_info.pei_information9%TYPE;
12353 
12354 l_student_flag               varchar2(3);
12355 l_student                    per_people_extra_info.pei_information1%TYPE;
12356 l_business_apprentice        per_people_extra_info.pei_information2%TYPE;
12357 l_warning                    VARCHAR2(300);
12358 
12359 
12360 cursor csr_chk_student_status
12361             is
12362             select pei_information1,pei_information2
12363             from per_people_extra_info where person_id=(select distinct person_id from per_all_assignments_f
12364                                                     where assignment_id=p_assignment_id
12365                                                     and primary_flag='Y')
12366                           and information_type like 'PER_US_ADDITIONAL_DETAILS'
12367                           and pei_information_category like 'PER_US_ADDITIONAL_DETAILS'
12368 			  and (pei_information1 = 'Y'
12369                 or pei_information2 = 'Y');
12370 
12371 cursor csr_chk_nra_status
12372 is
12373 select information_type,pei_information_category,pei_information5,pei_information9
12374 from per_people_extra_info where person_id=(select distinct person_id from per_all_assignments_f
12375                                                     where assignment_id=p_assignment_id
12376                                                     and primary_flag='Y')
12377                            and information_type like 'PER_US_ADDITIONAL_DETAILS'
12378                            and pei_information_category like 'PER_US_ADDITIONAL_DETAILS'
12379                            and pei_information5 like 'N'
12380                            and pei_information9 not in ('US');
12381 begin
12382    l_student_flag :='No';
12383 
12384    open csr_chk_student_status;
12385    fetch csr_chk_student_status into l_student,l_business_apprentice;
12386    if csr_chk_student_status%FOUND
12387 	then l_student_flag :='Yes';
12388    end if;
12389    close csr_chk_student_status;
12390 
12391     open csr_chk_nra_status;
12392     fetch csr_chk_nra_status into
12393     l_information_type,l_pei_information_category,l_pei_information5,l_pei_information9;
12394         if csr_chk_nra_status%FOUND
12395           then
12396           if p_withholding_allowances > 1 and not
12397                    (l_pei_information9 in ('CA','MX','KS') or (l_student_flag ='Yes' and l_pei_information9 = 'IN'))
12398 			then
12399 	    l_warning := 'PAY_US_CHK_NRA_W4_ALLOWANCES';
12400             fnd_message.set_name('PAY', 'PAY_US_CHK_NRA_W4_ALLOWANCES');
12401             fnd_message.raise_error;
12402           end if;
12403           if p_filing_status_code <> '01'
12404             then
12405 	    l_warning := 'PAY_US_CHK_NRA_FILING_STATUS';
12406             fnd_message.set_name('PAY', 'PAY_US_CHK_NRA_FILING_STATUS');
12407 	    fnd_message.raise_error;
12408           end if;
12409           if (p_fit_exempt = 'Y')
12410             then
12411 	    l_warning := 'PAY_US_CHK_NRA_FIT_EXEMPTIONS';
12412         /**    fnd_message.set_name('PAY', 'PAY_US_CHK_NRA_FIT_EXEMPTIONS');
12413 	    fnd_message.raise_error; **/
12414           end if;
12415        end if;
12416     close csr_chk_nra_status;
12417     p_returned_warning := l_warning;
12418 end check_nra_status;
12419 
12420 
12421 end pay_us_emp_dt_tax_rules;
12422