[Home] [Help]
PACKAGE BODY: APPS.HR_US_FF_UDF1
Source
1 PACKAGE BODY hr_us_ff_udf1 AS
2 /* $Header: pyusudf1.pkb 120.64 2012/01/05 09:45:03 emunisek ship $ */
3 /*
4 +======================================================================+
5 | Copyright (c) 1993 Oracle Corporation |
6 | Redwood Shores, California, USA |
7 | All rights reserved. |
8 +======================================================================+
9
10 Name : hr_us_ff_udf1
11 Filename : pyusudf1.pkb
12 Change List
13 -----------
14 Date Name Vers Bug No Description
15 ---- ---- ---- ------ -----------
16 19-AUG-02 TCLEWIS 115.0 Created
17 10-Oct-02 EKIM 115.2 2522002 Added functions
18 neg_earning, calc_earning
19 06-Aug-03 VMEHTA 115.4 Corrected the definition
20 (parameters) for
21 get_prev_ptd_values
22
23 08-Aug-03 VMEHTA 115.5 Corrected the definition
24 (parameters) for
25 get_prev_ptd_values
26 30-APR-04 TCLEWIS 115.6 Added functions
27 get_work_jurisdictions
28 and
29 Jurisdiction_processed
30 07-JUL-04 TCLEWIS 115.9 Changed plsql tables to be
31 indexed by binary integer.
32 version 115.7 was leap
33 frogged to 115.9, so
34 implementd 115.7 change.
35 02-AUN-04 TCLEWIS 115.10 ADDED GET_JD_PERCENT
36
37 27-AUG-04 TCLEWIS 115.12 Added code to load the resident
38 jurisdiction to the Juridiction_code_tbl.
39 This is because when a person works and
40 lives in the same JD, we have to pass
41 both to vertex and vertex will determine
42 how to tax.
43 23-SEP-04 FUSMAN 115.13 3909937 Changed the second cursor in function
44 get_prev_ptd_values to use
45 effective_date instead of date_earned.
46 23-SEP-04 meshah 115.14 3909937 get_prev_ptd_values, made changes
47 24-SEP-04 vmehta 115.15 3909937 get_prev_ptd_values, made
48 change to get full wages if
49 not processing home
50 jurisdiction (state), else get
51 only aggregate wages
52 27-SEP-04 vmehta 115.16 3909937 Added a check for dates in
53 query for getting person
54 address.
55 06-OCT-04 ppanda 115.17 3915176 Function GET_PRV_PTD_VALUES changed to
56 support previously withheld City, County
57 and School Dist Taxes
58 27-DEC-04 ppanda 115.21 3861379 Rolled back the fix 3926044
59 For Georgia Supp SIT 3926044 fix cannot
60 be shipped
61 09-APR-05 PPANDA 115.22 4241122 get_work_jurisdiction function
62 modified to support new value for
63 parameter p_INITIALIZE. Changes documented
64 above to the function definition.
65
66 A New function get_jurisdiction_type added
67
68 02-MAY-05 PPANDA 115.23 4337890 Exception added to formula function
69 get_Work_jurisdiction
70 27-MAY-05 SAIKRISH 115.25 4383819 Increase l_max_jurisdictions to 200
71 01-JUN-05 PPANDA 115.26 4217503 in get_work_jurisdiction function
72 a new criteria added to handle
73 number of work jurisdiction
74 02-JUN-05 ppanda 115.27 4374308 get_work_jurisdiction function
75 was using two local variables
76 to store the zip code of live and
77 work where size was not enough
78 when zip code had extension.
79 variable sizes increased.
80
81 27-JUN-05 ppanda 115.28 4227824 get_work_jurisdiction function
82 modified to support Homeworker
83 12-JUL-05 schauhan 115.29 4194339 Added function get_executive_status
84 20-AUG-05 saikrish 115.30 4532107 Added get_it_work_jurisdictions,
85 get_jd_level_threshold,get_th_assignment for
86 Consultant Taxation.
87 24-AUG-05 saikrish 115.31 4532107 Corrected Further Payroll DFF segment
88 columns in cursor csr_period_flag,
89 get_it_work_jurisdictions.
90 31-AUG-05 saikrish 115.35 4532107 Defaulted Further Payroll DFF segment
91 Use Information Hours to P (Previous
92 Pay Period).
93 05-SEP-05 saikrish 115.36 4590974 changed csr_it_element_entries
94 to query on end_date rather than
95 date_earned.
96 08-SEP-05 saikrish 115.38 4532107 Removed to_char for character
97 trace variables.
98 09-SEP-05 saikrish 115.39 4590974 Modified get_jd_tax_balances.
99 Corrected to 'State Tax Rules 2'
100 15-SEP-05 saikrish 115.43 4532107 Replaced csr_balance_ro with
101 balance call, _ASG_JD_RTD dimension
102 16-SEP-05 saikrish 115.44 4532107 Added message calls.
103 19-SEP-05 saikrish 115.45 4532107 Restricting tokens to length of 50
104 22-SEP-05 saikrish 115.46 4626170 Checking the termination of person
105 added cursor csr_term_date.
106 23-SEP-05 saikrish 115.47 4626170 Checking the hiring of person
107 added cursor csr_eff_dates.
108 29-SEP-05 saikrish 115.48 4638194 MOdified the dimension from
109 _ASG_JD_RTD to _PER_JD_GRE_RTD
110 07-NOV-05 saikrish 115.49 4626170 Enabled checking of hire and
111 termination of asssignment.
112 29-NOV-05 saikrish 115.50 4626170 Checking the termination date
113 based on date paid.
114 01-DEC-05 ppanda 115.51 4758960 get_work_jurisdiction function
115 modified to return work jurisdiction
116 count correctly ignoring the resident
117 jurisdiction code which is always added
118 at the end when its not an work
119 jurisdiction
120 03-APR-06 PPANDA 115.53 4715851 Few session variables were defined to fix
121 the Enhanced tax interface issue on local
122 tax.
123 02-MAY-06 PPANDA 115.55 5092586 get_work_jurisdiction function changed to
124 use Date Earned instead of Date Paid while
125 fetching VERTEX element entries.
126 03-MAY-06 PPANDA 115.56 5227022 get_work_jurisdiction function changed
127 When P_initialize flag was N, for information
128 time processing code was having issue to
129 fetch next jurisdiction from the pl/sql table
130 used in enhanced tax interface.
131 31-OCT-06 ssouresr 115.58 5602889 The function get_work_jurisdiction has been
132 5515072 modified to ensure that a resident jurisdiction
133 is not returned if the employee has not worked
134 in that jurisdiction
135 21-NOV-06 ssouresr 115.59 Added extra parameter to get_tax_exists
136 23-JAN-07 saikrish 115.60 5722893 Added new function get_jit_data.
137 07-MAR-07 SAIKRISH 115.62 Added new function get_rs_jd,get_wk_jd
138 15-MAR-07 jdevasah 115.67 5648961 The function get_it_work_jurisdiction has been
139 modified to assign null to l_start_date and
140 l_end_date for the first pay period when
141 l_pay_period_flag = 'P'.
142 11-MAY-07 jdevasah 115.68 5981447 Modified the function get_it_work_jurisdiction
143 with the following changes,
144 1. changed definition of the cursor csr_term_dates
145 to fetch hired date.
146 2. Added new date variables l_ws_start_date,
147 l_ws_end_date. These two variables are start and
148 end dates to calculate scheduled working hours
149 3. logic to calculate start and end dates for capturing
150 information hours and tagged hours is modified.
151 16-MAY-07 jdevasah 115.69 5981447 Added new condition in function get_jit_data to get
152 default supplemental calc method.
153 21-SEP-07 jdevasah 115.71 6371062 refined cdefiniton of cursor csr_term_dates in
154 in order to pick only active records from period of
155 service table.
156
157 25-OCT-07 jdevasah 115.72 6524016 Added two newparameters to the cursor csr_term_dates.
158 Pay period'start and end dates are passed to this
159 cursor.
160
161 14-NOV-07 jdevasah 115.73 6598477 Added new condition in get_it_jd_percent function
162 to handle CITY.
163 03-DEC-07 ssouresr 115.74 6495410 modified logic that was summing up percentages for
164 County. This was causing problems when city tax in KY
165 eliminates county tax.
166 08-MAR-08 ssouresr 115.75 6794452 Backed out changes made in previous version of the file
167 10-MAR-08 jdevasah 115.76 2122611 Added new function get_wc_flag.
168 10-APR-08 sjawid 115.77 6899939 Added new function parameter p_get_regular_wage to
169 115.78 get_prev_ptd_values
170 09-MAY-08 pannapur 115.79 5972214 Added function get_max_perc to find the city
171 wherein more time is worked in case of multiple
172 work jurisdictions
173 115.80 5972214 Removed get_max_perc
174 12-MAY-08 jdevasah 115.81 6869097 Modified Threshold hours calculation logic in function
175 get_it_work_jurisdiction.
176 10-JUL-08 Pannapur 115.83 7238809 Modified get_prev_ptd_values
177 10-JUL-08 Pannapur 115.84 Problem with ARCS .so arcsed in once again
178 12-JUL-08 jdevasah 115.85 6957929 Modified get_it_work_jurisdiction function to make the
179 functionality in sync with non EMJT. When work and
180 resident locations are same jurisdiction_type in the
181 pl/sql table must be 'RW'.
182 14-JUL-08 pannapur 115.86 Reverted back the fix made in 115.83
183 08-Aug-08 Pannapur 115.87 7238809 Added new function parameter per_adr_geocode to
184 115.88 get_prev_ptd_values
185 115.89 get_prev_ptd_values
186 15-SEP-08 jdevasah 115.90 7114362 modified get_it_work_jurisdiction function to make
187 payroll works for terminated assignments.
188 05-NOV-08 jdevasah 115.97 7520832 Modified get_wc_flag function in order to deduct WC
189 115.98 amount on the pay period close as possible to end
190 of the quarter.
191 18-DEC-08 jdevasah 115.99 7655549 Modified CSR_GET_VALID_EMPLOYMENT cursor
192 in GET_WC_FLAG function.
193 19-DEC-08 emunisek 115.101 5972214 Created new function COLORADOCITY_HT_COLLECTORNOT
194 to decide for a given coloradocity if the head tax
195 can be deducted or not.It needs the payperiod to be the
196 last one of the given month and the current city is with
197 maximum time percentage of all the colorado head tax
198 jurisdictions the assignment is related with.
199 14-MAY-09 emunisek 115.103 8406097 Modified COLORADOCITY_HT_COLLECTORNOT function to
200 consider average time percentage for work jurisdictions
201 over a month to find the jurisdiction with maximum
202 percentage.
203 Also introduced a check to see if the Date Paid and
204 Date Earned are of different month for payrolls of period
205 less than month and give out a warning if Head Tax gets
206 skipped.
207
208 16-Jun-09 jdevasah 115.104 8592027 Modified GET_WC_FLAG to use regular payment date
209 instead of date earned to determine the appropriate
210 pay period to deduct Workers compensation fee.
211 24-Dec-09 tclewis 115.107 9232546 modified
212 get_it_work_jurisdictions
213 added code to att the primary
214 work JD to the staging table
215 if an entry doesnt exist.
216 08-JUN-10 nchinnam 115.108 9546119 Modified message PAY_US_EMJT_EMPLOYEE_INFO as Information.
217 18-Aug-11 emunisek 115.112 12583094 Added new functions count_remaining_pay_periods
218 and fnd_canonical_to_date.
219 23-Aug-11 tclewis 115.113 Added code for PA Act 32. Added new function
220 GET_PSD_JD_CODE.
221 27-OCT-11 tclewis 115.114 Added check of tax_uni_id
222 prior to inserting to asg_reportings
223 in proc GET_PSD_JD_CODE.
224 05-JAN-12 emunisek 115.124 12618403 Added new function get_ht_withheld_per_jd_month.This will be
225 using same route text as the DBI HEAD_TAX_WITHHELD_PER_JD_MONTH
226 but will check for Jurisdiction Code without county code to give
227 City level value.
228 05-JAN-12 emunisek 115.126 12618403 Resolved GSCC Errors
229 */
230
231 FUNCTION get_tax_jurisdiction(p_assignment_id number
232 ,p_date_earned date
233 )
234 RETURN varchar2
235 IS
236
237 l_return_value varchar2(1);
238
239 BEGIN
240 hr_utility.trace('BEGIN -> hr_us_ff_udf1.get_tax_jurisdiction ');
241 select nvl(hoi.org_information16,'N')
242 into l_return_value
243 from per_assignments_f paf,
244 hr_organization_information hoi,
245 hr_soft_coding_keyflex hsk
246 where paf.assignment_id = p_assignment_id
247 and p_date_earned between paf.effective_start_date
248 and paf.effective_end_date
249 and paf.soft_coding_keyflex_id = hsk.soft_coding_keyflex_id
250 and hsk.segment1 = hoi.organization_id
251 and hoi.org_information_context = 'W2 Reporting Rules';
252
253 hr_utility.trace('get_tax_jurisdiction retrun_value = ' || l_return_value);
254 hr_utility.trace('END -> hr_us_ff_udf1.get_tax_jurisdiction ');
255 return (l_return_value);
256 EXCEPTION
257 WHEN NO_DATA_FOUND THEN
258 return ('N');
259 END get_tax_jurisdiction;
260
261 --
262 --
263 FUNCTION calc_earning (p_template_earning number,
264 p_addl_asg_gre_itd number,
265 p_neg_earn_asg_gre_itd number)
266 RETURN NUMBER
267 IS
268
269 l_ret number;
270
271 BEGIN
272 hr_utility.trace('tab.count = '||to_char(hr_us_ff_udf1.l_neg_earn_tab.count));
273
274 IF hr_us_ff_udf1.l_neg_earn_tab.count <= 0 THEN
275 hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn := 0;
276 hr_us_ff_udf1.l_neg_earn_tab(1).neg_earn_feed := 0;
277 hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn := p_neg_earn_asg_gre_itd;
278 END IF;
279
280 hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn := p_template_earning +
281 p_addl_asg_gre_itd +
282 hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn;
283
284 hr_utility.trace('temp_earn = '||
285 to_char(hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn));
286
287 IF hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn < 0 THEN
288 hr_us_ff_udf1.l_neg_earn_tab(1).neg_earn_feed :=
289 hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn;
290 ELSE
291 IF (hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn > 0) and
292 ( hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn = 0 ) THEN
293 hr_us_ff_udf1.l_neg_earn_tab(1).neg_earn_feed := 0;
294 END IF;
295
296 IF ( hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn >= 0) and
297 ( hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn < 0) THEN
298 hr_us_ff_udf1.l_neg_earn_tab(1).neg_earn_feed :=
299 ( -1 * hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn);
300 END IF;
301 END IF;
302
303 hr_utility.trace('neg_earn_feed = '||
304 to_char(hr_us_ff_udf1.l_neg_earn_tab(1).neg_earn_feed));
305
306 hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn
307 := hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn +
308 (-1 * hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn);
309
310 hr_utility.trace('reduced_neg_earn = '||
311 to_char(hr_us_ff_udf1.l_neg_earn_tab(1).reduced_neg_earn));
312
313 l_ret := hr_us_ff_udf1.l_neg_earn_tab(1).temp_earn;
314
315 return l_ret;
316 END calc_earning;
317 --
318 --
319 FUNCTION neg_earning RETURN NUMBER is
320 l_ret number;
321 BEGIN
322 l_ret := hr_us_ff_udf1.l_neg_earn_tab(1).neg_earn_feed;
323 hr_utility.trace('hr_us_ff_udf1.neg_earning : neg_earn_feed = '||
324 to_char(l_ret));
325 return l_ret;
326 END neg_earning;
327
328 /*Function added for 6899939*/
329 FUNCTION get_prev_ptd_values(
330 p_assignment_action_id number, -- Context
331 p_tax_unit_id number, -- Context
332 p_jurisdiction_code varchar2, -- Context
333 p_fed_or_state varchar2, -- Parameter
334 p_regular_aggregate number, -- Parameter
335 calc_PRV_GRS OUT nocopy number, -- Paramter
336 calc_PRV_TAX OUT nocopy number )
337
338 RETURN NUMBER IS
339 BEGIN
340 RETURN get_prev_ptd_values(
341 p_assignment_action_id
342 ,p_tax_unit_id
343 ,p_jurisdiction_code
344 ,p_fed_or_state
345 ,p_regular_aggregate
346 ,calc_PRV_GRS
347 ,calc_PRV_TAX
348 ,'N');
349 END get_prev_ptd_values;
350
351 /*Function added for 7238809*/
352 FUNCTION get_prev_ptd_values(
353 p_assignment_action_id number, -- Context
354 p_tax_unit_id number, -- Context
355 p_jurisdiction_code varchar2, -- Context
356 p_fed_or_state varchar2, -- Parameter
357 p_regular_aggregate number, -- Parameter
358 calc_PRV_GRS OUT nocopy number, -- Paramter
359 calc_PRV_TAX OUT nocopy number,
360 p_get_regular_wage varchar2 )
361
362 RETURN NUMBER IS
363
364 CURSOR csr_l_home_juris (p_assignment_action_id IN NUMBER) IS
365
366 SELECT hr_us_ff_udfs.addr_val(NVL(add_information17, region_2),
367 NVL(add_information19, region_1),
368 NVL(add_information18, town_or_city),
369 NVL(add_information20, postal_code)
370 )
371
372 FROM per_addresses pad,
373 per_assignments_f paf,
374 pay_assignment_actions paa,
375 pay_payroll_actions ppa
376
377 WHERE pad.primary_flag = 'Y'
378 AND pad.person_id = paf.person_id
379 AND ppa.date_earned BETWEEN pad.date_from
380 AND NVL(pad.date_to, TO_DATE('12/31/4712',
381 'MM/DD/YYYY'))
382 AND ppa.date_earned BETWEEN paf.effective_start_date
383 AND paf.effective_end_date
384 AND paf.assignment_id = paa.assignment_id
385 AND paa.payroll_action_id = ppa.payroll_action_id
386 AND paa.assignment_action_id = p_assignment_action_id;
387
388 l_home_juris varchar2(11);
389
390 BEGIN
391
392 OPEN csr_l_home_juris(p_assignment_action_id);
393 FETCH csr_l_home_juris INTO l_home_juris;
394 IF csr_l_home_juris%NOTFOUND THEN
395 l_home_juris := '00-000-0000';
396 END IF;
397 CLOSE csr_l_home_juris;
398
399
400 RETURN get_prev_ptd_values(
401 p_assignment_action_id
402 ,p_tax_unit_id
403 ,p_jurisdiction_code
404 ,p_fed_or_state
405 ,p_regular_aggregate
406 ,calc_PRV_GRS
407 ,calc_PRV_TAX
408 ,p_get_regular_wage
409 ,l_home_juris);
410 END get_prev_ptd_values;
411
412
413 FUNCTION get_prev_ptd_values(
414 p_assignment_action_id number, -- context
415 p_tax_unit_id number,-- context
416 p_jurisdiction_code varchar2, -- context
417 p_fed_or_state varchar2, -- parameter
418 p_regular_aggregate number,
419 calc_PRV_GRS OUT nocopy number,
420 calc_PRV_TAX OUT nocopy number,
421 p_get_regular_wage varchar2, -- Paramter /*6899939*/
422 per_adr_geocode varchar2 -- Parameter /*7238809*/
423 )
424 RETURN NUMBER IS
425
426 l_defined_balance_tab pay_balance_pkg.t_balance_value_tab;
427 l_context_tab pay_balance_pkg.t_context_tab;
428 l_bal_out_tab pay_balance_pkg.t_detailed_bal_out_tab;
429 l_assignment_id number;
430 l_bal_assact number;
431 l_payroll_id number;
432 l_asg_type varchar2(11) := null;
433 l_regular_aggregate number;
434 l_get_full_wage varchar2(1);
435
436
437 BEGIN
438 -- hr_utility.trace_on(NULL,'ORCL');
439 l_get_full_wage := 'Y';
440 hr_utility.trace('Entering get_prev_ptd_values' );
441 hr_utility.trace('p_regular_aggregate = ' ||
442 to_char(p_regular_aggregate) );
443
444 SELECT paa.assignment_id
445 INTO l_assignment_id
446 FROM pay_assignment_actions paa
447 where paa.assignment_action_id = p_assignment_action_id;
448
449
450 /* commented for bug 7238809 .As fetching home jurisdiction using
451 fnd sessions does not pick the correct value .
452 SELECT hr_us_ff_udfs.addr_val(NVL(add_information17, region_2),
453 NVL(add_information19, region_1),
454 NVL(add_information18, town_or_city),
455 NVL(add_information20, postal_code)
456 )
457 INTO l_home_juris
458 FROM per_addresses pad,
459 per_assignments_f paf,
460 fnd_sessions fs
461 WHERE pad.primary_flag = 'Y'
462 AND pad.person_id = paf.person_id
463 AND fs.effective_date BETWEEN pad.date_from
464 AND NVL(pad.date_to, TO_DATE('12/31/4712',
465 'MM/DD/YYYY'))
466 AND fs.effective_date BETWEEN paf.effective_start_date
467 AND paf.effective_end_date
468 AND fs.session_id = USERENV('sessionid')
469 AND paf.assignment_id = l_assignment_id; */
470
471 SELECT /*+ RULE */ paa1.assignment_action_id,
472 ppa1.payroll_id
473 INTO l_bal_assact,
474 l_payroll_id
475 FROM pay_assignment_Actions paa1,
476 pay_payroll_actions ppa1
477 WHERE paa1.assignment_id = l_assignment_id
478 AND paa1.tax_unit_id = p_tax_unit_id
479 AND paa1.action_sequence =
480 (SELECT max(paa_prev.action_sequence)
481 FROM per_time_periods ptp
482 , pay_payroll_actions ppa
483 , pay_assignment_actions paa
484 , per_time_periods ptp_prev
485 , pay_payroll_actions ppa_prev
486 , pay_assignment_actions paa_prev
487 WHERE paa.assignment_action_id = p_assignment_action_id
488 AND ppa.payroll_action_id = paa.payroll_action_id
489 -- AND ptp.time_period_id = ppa.time_period_id
490 AND ppa.effective_date between ptp.start_date /*Bug:3909937*/
491 and ptp.end_date
492 AND ptp.payroll_id = ppa.payroll_id
493 AND ptp_prev.payroll_id = ppa.payroll_id
494 AND ptp.start_date - 1 between ptp_prev.start_date
495 and ptp_prev.end_date
496 AND paa_prev.assignment_id = paa.assignment_id
497 AND paa_prev.payroll_action_id = ppa_prev.payroll_action_id
498 AND ppa_prev.action_type IN ('R', 'Q', 'B')
499 -- AND ppa_prev.time_period_id = ptp_prev.time_period_id)
500 --AND ppa_prev.date_earned between ptp_prev.start_date
501 AND ppa_prev.effective_date between ptp_prev.start_date
502 and ptp_prev.end_date)
503 AND paa1.payroll_action_id = ppa1.payroll_action_id ;
504
505 hr_utility.trace('Previous period AAID ' || to_char(l_bal_assact) );
506
507
508 IF nvl(p_regular_aggregate,0)= 0 THEN
509 hr_utility.trace('p_regular_aggregate = 0 asg_type = ASG' );
510
511 l_asg_type := 'ASG';
512 ELSE
513 l_asg_type := 'PER_PAYROLL';
514
515 hr_utility.trace('p_regular_aggregate not = 0 asg_type = PER_PAYROLL' );
516
517 pay_balance_pkg.set_context('PAYROLL_ID',l_payroll_id);
518
519 END IF;
520
521 IF p_fed_or_state = 'FED' THEN
522
523 hr_utility.trace('p_fed_or_state = FED' );
524
525 -- MAY NEED FOR AGGREGATION.
526 --pay_balance_pkg.set_context('PAYROLL_ID',l_payroll_id);
527
528 SELECT creator_id
529 INTO l_defined_balance_tab(1).defined_balance_id
530 FROM ff_user_entities
531 WHERE user_entity_name = 'REGULAR_EARNINGS_' || l_asg_type || '_GRE_PTD'
532 AND legislation_code = 'US';
533
534 l_defined_balance_tab(1).balance_value := 0;
535
536 hr_utility.trace('REGULAR_EARNINGS_' || l_asg_type || '_GRE_PTD' || ' = '
537 || to_char(l_defined_balance_tab(1).defined_balance_id));
538
539 l_context_tab(1).tax_unit_id := p_tax_unit_id;
540 l_context_tab(1).jurisdiction_code := Null;
541 l_context_tab(1).source_id := null;
542 l_context_tab(1).source_text := null;
543 l_context_tab(1).source_number := null;
544 l_context_tab(1).source_text2 := null;
545
546 SELECT creator_id
547 INTO l_defined_balance_tab(2).defined_balance_id
548 FROM ff_user_entities
549 WHERE user_entity_name = 'SUPPLEMENTAL_EARNINGS_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
550 AND legislation_code = 'US';
551 l_defined_balance_tab(2).balance_value := 0;
552
553 hr_utility.trace('REGULAR_EARNINGS_' || l_asg_type || '_GRE_PTD' || ' = '
554 || to_char(l_defined_balance_tab(2).defined_balance_id));
555
556 l_context_tab(2).tax_unit_id := p_tax_unit_id;
557 l_context_tab(2).jurisdiction_code := null;
558 l_context_tab(2).source_id := null;
559 l_context_tab(2).source_text := null;
560 l_context_tab(2).source_number := null;
561 l_context_tab(2).source_text2 := null;
562
563 SELECT creator_id
564 INTO l_defined_balance_tab(3).defined_balance_id
565 FROM ff_user_entities
566 WHERE user_entity_name = 'FIT_NON_AGGREGATE_RED_SUBJ_WHABLE_' || l_asg_type || '_GRE_PTD'
567 AND legislation_code = 'US';
568
569 l_defined_balance_tab(3).balance_value := 0;
570
571 hr_utility.trace('FIT_NON_AGGREGATE_RED_SUBJ_WHABLE_' || l_asg_type || '_GRE_PTD' || ' = '
572 || to_char(l_defined_balance_tab(3).defined_balance_id));
573
574
575 l_context_tab(3).tax_unit_id := p_tax_unit_id;
576 l_context_tab(3).jurisdiction_code := null;
577 l_context_tab(3).source_id := null;
578 l_context_tab(3).source_text := null;
579 l_context_tab(3).source_number := null;
580 l_context_tab(3).source_text2 := null;
581
582 SELECT creator_id
583 INTO l_defined_balance_tab(4).defined_balance_id
584 FROM ff_user_entities
585 WHERE user_entity_name = 'DEF_COMP_401K_' || l_asg_type || '_GRE_PTD'
586 AND legislation_code = 'US';
587
588 l_defined_balance_tab(4).balance_value := 0;
589
590 hr_utility.trace('DEF_COMP_401K_' || l_asg_type || '_GRE_PTD' || ' = '
591 || to_char(l_defined_balance_tab(4).defined_balance_id));
592
593 l_context_tab(4).tax_unit_id := p_tax_unit_id;
594 l_context_tab(4).jurisdiction_code := null;
595 l_context_tab(4).source_id := null;
596 l_context_tab(4).source_text := null;
597 l_context_tab(4).source_number := null;
598 l_context_tab(4).source_text2 := null;
599
600 SELECT creator_id
601 INTO l_defined_balance_tab(5).defined_balance_id
602 FROM ff_user_entities
603 WHERE user_entity_name = 'DEF_COMP_403B_' || l_asg_type || '_GRE_PTD'
604 AND legislation_code = 'US';
605
606 l_defined_balance_tab(5).balance_value := 0;
607
608 hr_utility.trace('DEF_COMP_403B_' || l_asg_type || '_GRE_PTD' || ' = '
609 || to_char(l_defined_balance_tab(5).defined_balance_id));
610
611 l_context_tab(5).tax_unit_id := p_tax_unit_id;
612 l_context_tab(5).jurisdiction_code := null;
613 l_context_tab(5).source_id := null;
614 l_context_tab(5).source_text := null;
615 l_context_tab(5).source_number := null;
616 l_context_tab(5).source_text2 := null;
617
618 SELECT creator_id
619 INTO l_defined_balance_tab(6).defined_balance_id
620 FROM ff_user_entities
621 WHERE user_entity_name = 'DEF_COMP_457_' || l_asg_type || '_GRE_PTD'
622 AND legislation_code = 'US';
623
624 l_defined_balance_tab(6).balance_value := 0;
625
626 hr_utility.trace('DEF_COMP_457_' || l_asg_type || '_GRE_PTD' || ' = '
627 || to_char(l_defined_balance_tab(6).defined_balance_id));
628
629 l_context_tab(6).tax_unit_id := p_tax_unit_id;
630 l_context_tab(6).jurisdiction_code := null;
631 l_context_tab(6).source_id := null;
632 l_context_tab(6).source_text := null;
633 l_context_tab(6).source_number := null;
634 l_context_tab(6).source_text2 := null;
635
636 SELECT creator_id
637 INTO l_defined_balance_tab(7).defined_balance_id
638 FROM ff_user_entities
639 WHERE user_entity_name = 'OTHER_PRETAX_' || l_asg_type || '_GRE_PTD'
640 AND legislation_code = 'US';
641
642 hr_utility.trace('OTHER_PRETAX_' || l_asg_type || '_GRE_PTD' || ' = '
643 || to_char(l_defined_balance_tab(7).defined_balance_id));
644
645 l_defined_balance_tab(7).balance_value := 0;
646
647 l_context_tab(7).tax_unit_id := p_tax_unit_id;
648 l_context_tab(7).jurisdiction_code := null;
649 l_context_tab(7).source_id := null;
650 l_context_tab(7).source_text := null;
651 l_context_tab(7).source_number := null;
652 l_context_tab(7).source_text2 := null;
653
654 SELECT creator_id
655 INTO l_defined_balance_tab(8).defined_balance_id
656 FROM ff_user_entities
657 WHERE user_entity_name = 'SECTION_125_' || l_asg_type || '_GRE_PTD'
658 AND legislation_code = 'US';
659
660 hr_utility.trace('SECTION_125_' || l_asg_type || '_GRE_PTD' || ' = '
661 || to_char(l_defined_balance_tab(8).defined_balance_id));
662
663 l_defined_balance_tab(8).balance_value := 0;
664
665 l_context_tab(8).tax_unit_id := p_tax_unit_id;
666 l_context_tab(8).jurisdiction_code := null;
667 l_context_tab(8).source_id := null;
668 l_context_tab(8).source_text := null;
669 l_context_tab(8).source_number := null;
670 l_context_tab(8).source_text2 := null;
671
672 SELECT creator_id
673 INTO l_defined_balance_tab(9).defined_balance_id
674 FROM ff_user_entities
675 WHERE user_entity_name = 'DEPENDENT_CARE_' || l_asg_type || '_GRE_PTD'
676 AND legislation_code = 'US';
677
678 hr_utility.trace('DEPENDENT_CARE_' || l_asg_type || '_GRE_PTD' || ' = '
679 || to_char(l_defined_balance_tab(9).defined_balance_id));
680
681 l_defined_balance_tab(9).balance_value := 0;
682
683 l_context_tab(9).tax_unit_id := p_tax_unit_id;
684 l_context_tab(9).jurisdiction_code := null;
685 l_context_tab(9).source_id := null;
686 l_context_tab(9).source_text := null;
687 l_context_tab(9).source_number := null;
688 l_context_tab(9).source_text2 := null;
689
690 SELECT creator_id
691 INTO l_defined_balance_tab(10).defined_balance_id
692 FROM ff_user_entities
693 WHERE user_entity_name = 'DEF_COMP_401K_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
694 AND legislation_code = 'US';
695
696 hr_utility.trace('DEF_COMP_401K_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD' || ' = '
697 || to_char(l_defined_balance_tab(10).defined_balance_id));
698
699
700 l_defined_balance_tab(10).balance_value := 0;
701
702 l_context_tab(10).tax_unit_id := p_tax_unit_id;
703 l_context_tab(10).jurisdiction_code := null;
704 l_context_tab(10).source_id := null;
705 l_context_tab(10).source_text := null;
706 l_context_tab(10).source_number := null;
707 l_context_tab(10).source_text2 := null;
708
709 SELECT creator_id
710 INTO l_defined_balance_tab(11).defined_balance_id
711 FROM ff_user_entities
712 WHERE user_entity_name = 'DEF_COMP_403B_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
713 AND legislation_code = 'US';
714
715 hr_utility.trace('DEF_COMP_403B_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD' || ' = '
716 || to_char(l_defined_balance_tab(11).defined_balance_id));
717
718 l_defined_balance_tab(11).balance_value := 0;
719
720 l_context_tab(11).tax_unit_id := p_tax_unit_id;
721 l_context_tab(11).jurisdiction_code := null;
722 l_context_tab(11).source_id := null;
723 l_context_tab(11).source_text := null;
724 l_context_tab(11).source_number := null;
725 l_context_tab(11).source_text2 := null;
726
727 SELECT creator_id
728 INTO l_defined_balance_tab(12).defined_balance_id
729 FROM ff_user_entities
730 WHERE user_entity_name = 'DEF_COMP_457_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
731 AND legislation_code = 'US';
732
733 hr_utility.trace('DEF_COMP_457_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD' || ' = '
734 || to_char(l_defined_balance_tab(12).defined_balance_id));
735
736 l_defined_balance_tab(12).balance_value := 0;
737
738 l_context_tab(12).tax_unit_id := p_tax_unit_id;
739 l_context_tab(12).jurisdiction_code := null;
740 l_context_tab(12).source_id := null;
741 l_context_tab(12).source_text := null;
742 l_context_tab(12).source_number := null;
743 l_context_tab(12).source_text2 := null;
744
745 SELECT creator_id
746 INTO l_defined_balance_tab(13).defined_balance_id
747 FROM ff_user_entities
748 WHERE user_entity_name = 'OTHER_PRETAX_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
749 AND legislation_code = 'US';
750
751 hr_utility.trace('OTHER_PRETAX_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD' || ' = '
752 || to_char(l_defined_balance_tab(13).defined_balance_id));
753
754 l_defined_balance_tab(13).balance_value := 0;
755
756 l_context_tab(13).tax_unit_id := p_tax_unit_id;
757 l_context_tab(13).jurisdiction_code := null;
758 l_context_tab(13).source_id := null;
759 l_context_tab(13).source_text := null;
760 l_context_tab(13).source_number := null;
761 l_context_tab(13).source_text2 := null;
762
763 SELECT creator_id
764 INTO l_defined_balance_tab(14).defined_balance_id
765 FROM ff_user_entities
766 WHERE user_entity_name = 'SECTION_125_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
767 AND legislation_code = 'US';
768
769 hr_utility.trace('SECTION_125_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD' || ' = '
770 || to_char(l_defined_balance_tab(14).defined_balance_id));
771
772 l_defined_balance_tab(14).balance_value := 0;
773
774 l_context_tab(14).tax_unit_id := p_tax_unit_id;
775 l_context_tab(14).jurisdiction_code := null;
776 l_context_tab(14).source_id := null;
777 l_context_tab(14).source_text := null;
778 l_context_tab(14).source_number := null;
779 l_context_tab(14).source_text2 := null;
780
781 SELECT creator_id
782 INTO l_defined_balance_tab(15).defined_balance_id
783 FROM ff_user_entities
784 WHERE user_entity_name = 'DEPENDENT_CARE_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD'
785 AND legislation_code = 'US';
786
787 hr_utility.trace('DEPENDENT_CARE_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD' || ' = '
788 || to_char(l_defined_balance_tab(15).defined_balance_id));
789
790 l_defined_balance_tab(15).balance_value := 0;
791
792 l_context_tab(15).tax_unit_id := p_tax_unit_id;
793 l_context_tab(15).jurisdiction_code := null;
794 l_context_tab(15).source_id := null;
795 l_context_tab(15).source_text := null;
796 l_context_tab(15).source_number := null;
797 l_context_tab(15).source_text2 := null;
798
799 SELECT creator_id
800 INTO l_defined_balance_tab(16).defined_balance_id
801 FROM ff_user_entities
802 WHERE user_entity_name = 'FIT_NON_W2_DEF_COMP_401_' || l_asg_type || '_GRE_PTD'
803 AND legislation_code = 'US';
804
805 hr_utility.trace('FIT_NON_W2_DEF_COMP_401_' || l_asg_type || '_GRE_PTD' || ' = '
806 || to_char(l_defined_balance_tab(16).defined_balance_id));
807
808 l_defined_balance_tab(16).balance_value := 0;
809
810 l_context_tab(16).tax_unit_id := p_tax_unit_id;
811 l_context_tab(16).jurisdiction_code := null;
812 l_context_tab(16).source_id := null;
813 l_context_tab(16).source_text := null;
814 l_context_tab(16).source_number := null;
815 l_context_tab(16).source_text2 := null;
816
817 SELECT creator_id
818 INTO l_defined_balance_tab(17).defined_balance_id
819 FROM ff_user_entities
820 WHERE user_entity_name = 'FIT_NON_W2_DEF_COMP_403_' || l_asg_type || '_GRE_PTD'
821 AND legislation_code = 'US';
822
823 hr_utility.trace('FIT_NON_W2_DEF_COMP_403_' || l_asg_type || '_GRE_PTD' || ' = '
824 || to_char(l_defined_balance_tab(17).defined_balance_id));
825
826 l_defined_balance_tab(17).balance_value := 0;
827
828 l_context_tab(17).tax_unit_id := p_tax_unit_id;
829 l_context_tab(17).jurisdiction_code := null;
830 l_context_tab(17).source_id := null;
831 l_context_tab(17).source_text := null;
832 l_context_tab(17).source_number := null;
833 l_context_tab(17).source_text2 := null;
834
835 SELECT creator_id
836 INTO l_defined_balance_tab(18).defined_balance_id
837 FROM ff_user_entities
838 WHERE user_entity_name = 'FIT_NON_W2_DEF_COMP_457_' || l_asg_type || '_GRE_PTD'
839 AND legislation_code = 'US';
840
841 hr_utility.trace('FIT_NON_W2_DEF_COMP_457_' || l_asg_type || '_GRE_PTD' || ' = '
842 || to_char(l_defined_balance_tab(18).defined_balance_id));
843
844 l_defined_balance_tab(18).balance_value := 0;
845
846 l_context_tab(18).tax_unit_id := p_tax_unit_id;
847 l_context_tab(18).jurisdiction_code := null;
848 l_context_tab(18).source_id := null;
849 l_context_tab(18).source_text := null;
850 l_context_tab(18).source_number := null;
851 l_context_tab(18).source_text2 := null;
852
853 SELECT creator_id
854 INTO l_defined_balance_tab(19).defined_balance_id
855 FROM ff_user_entities
856 WHERE user_entity_name = 'FIT_NON_W2_SECTION_125_' || l_asg_type || '_GRE_PTD'
857 AND legislation_code = 'US';
858
859 hr_utility.trace('FIT_NON_W2_SECTION_125_' || l_asg_type || '_GRE_PTD' || ' = '
860 || to_char(l_defined_balance_tab(19).defined_balance_id));
861
862 l_defined_balance_tab(19).balance_value := 0;
863
864 l_context_tab(19).tax_unit_id := p_tax_unit_id;
865 l_context_tab(19).jurisdiction_code := null;
866 l_context_tab(19).source_id := null;
867 l_context_tab(19).source_text := null;
868 l_context_tab(19).source_number := null;
869 l_context_tab(19).source_text2 := null;
870
871 SELECT creator_id
872 INTO l_defined_balance_tab(20).defined_balance_id
873 FROM ff_user_entities
874 WHERE user_entity_name = 'FIT_NON_W2_DEPENDENT_CARE_' || l_asg_type || '_GRE_PTD'
875 AND legislation_code = 'US';
876
877 hr_utility.trace('FIT_NON_W2_DEPENDENT_CARE_' || l_asg_type || '_GRE_PTD' || ' = '
878 || to_char(l_defined_balance_tab(20).defined_balance_id));
879
880 l_defined_balance_tab(20).balance_value := 0;
881
882 l_context_tab(20).tax_unit_id := p_tax_unit_id;
883 l_context_tab(20).jurisdiction_code := null;
884 l_context_tab(20).source_id := null;
885 l_context_tab(20).source_text := null;
886 l_context_tab(20).source_number := null;
887 l_context_tab(20).source_text2 := null;
888
889 SELECT creator_id
890 INTO l_defined_balance_tab(21).defined_balance_id
891 FROM ff_user_entities
892 WHERE user_entity_name = 'FIT_NON_W2_OTHER_PRETAX_' || l_asg_type || '_GRE_PTD'
893 AND legislation_code = 'US';
894
895 hr_utility.trace('FIT_NON_W2_OTHER_PRETAX_' || l_asg_type || '_GRE_PTD' || ' = '
896 || to_char(l_defined_balance_tab(21).defined_balance_id));
897
898 l_defined_balance_tab(21).balance_value := 0;
899
900 l_context_tab(21).tax_unit_id := p_tax_unit_id;
901 l_context_tab(21).jurisdiction_code := null;
902 l_context_tab(21).source_id := null;
903 l_context_tab(21).source_text := null;
904 l_context_tab(21).source_number := null;
905 l_context_tab(21).source_text2 := null;
906
907
908 SELECT creator_id
909 INTO l_defined_balance_tab(22).defined_balance_id
910 FROM ff_user_entities
911 WHERE user_entity_name = 'FIT_WITHHELD_' || l_asg_type || '_GRE_PTD'
912 AND legislation_code = 'US';
913
914 hr_utility.trace('FIT_WITHHELD_' || l_asg_type || '_GRE_PTD' || ' = '
915 || to_char(l_defined_balance_tab(22).defined_balance_id));
916
917 l_defined_balance_tab(22).balance_value := 0;
918
919 l_context_tab(22).tax_unit_id := p_tax_unit_id;
920 l_context_tab(22).jurisdiction_code := null;
921 l_context_tab(22).source_id := null;
922 l_context_tab(22).source_text := null;
923 l_context_tab(22).source_number := null;
924 l_context_tab(22).source_text2 := null;
925
926 SELECT creator_id
927 INTO l_defined_balance_tab(23).defined_balance_id
928 FROM ff_user_entities
929 WHERE user_entity_name = 'FIT_SUPP_WITHHELD_' || l_asg_type || '_GRE_PTD'
930 AND legislation_code = 'US';
931
932 hr_utility.trace('FIT_SUPP_WITHHELD_' || l_asg_type || '_GRE_PTD' || ' = '
933 || to_char(l_defined_balance_tab(23).defined_balance_id));
934
935 l_defined_balance_tab(23).balance_value := 0;
936
937 l_context_tab(23).tax_unit_id := p_tax_unit_id;
938 l_context_tab(23).jurisdiction_code := null;
939 l_context_tab(23).source_id := null;
940 l_context_tab(23).source_text := null;
941 l_context_tab(23).source_number := null;
942 l_context_tab(23).source_text2 := null;
943
944 pay_balance_pkg.get_value (p_assignment_action_id => l_bal_assact,
945 p_defined_balance_lst => l_defined_balance_tab,
946 p_context_lst => l_context_tab,
947 p_get_rr_route => FALSE,
948 p_get_rb_route => FALSE,
949 p_output_table => l_bal_out_tab);
950
951 hr_utility.trace('Return value from balance call');
952 hr_utility.trace( 'REGULAR_EARNINGS_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(1).balance_value,0)));
953 hr_utility.trace( 'SUPPLEMENTAL_EARNINGS_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(2).balance_value,0)));
954 hr_utility.trace( 'FIT_NON_AGGREGATE_RED_SUBJ_WHABLE_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(3).balance_value,0)));
955 hr_utility.trace( 'DEF_COMP_401K_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(4).balance_value,0)));
956 hr_utility.trace( 'DEF_COMP_403B_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(5).balance_value,0)));
957 hr_utility.trace( 'DEF_COMP_457_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(6).balance_value,0)));
958 hr_utility.trace( 'OTHER_PRETAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(7).balance_value,0)));
959 hr_utility.trace( 'SECTION_125_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(8).balance_value,0)));
960 hr_utility.trace( 'DEPENDENT_CARE_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(9).balance_value,0)));
961
962 hr_utility.trace( 'DEF_COMP_401K_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(10).balance_value,0)));
963 hr_utility.trace( 'DEF_COMP_403B_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(11).balance_value,0)));
964 hr_utility.trace( 'DEF_COMP_457_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(12).balance_value,0)));
965 hr_utility.trace( 'OTHER_PRETAX_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(13).balance_value,0)));
966 hr_utility.trace( 'SECTION_125_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(14).balance_value,0)));
967 hr_utility.trace( 'DEPENDENT_CARE_FOR_FIT_SUBJECT_TO_TAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(15).balance_value,0)));
968
969 hr_utility.trace( 'FIT_NON_W2_DEF_COMP_401_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(16).balance_value,0)));
970 hr_utility.trace( 'FIT_NON_W2_DEF_COMP_403_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(17).balance_value,0)));
971 hr_utility.trace( 'FIT_NON_W2_DEF_COMP_457_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(18).balance_value,0)));
972 hr_utility.trace( 'FIT_NON_W2_SECTION_125_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(19).balance_value,0)));
973 hr_utility.trace( 'FIT_NON_W2_DEPENDENT_CARE_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(20).balance_value,0)));
974 hr_utility.trace( 'FIT_NON_W2_OTHER_PRETAX_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(21).balance_value,0)));
975
976 hr_utility.trace( 'FIT_WITHHELD_' || l_asg_type || '_PTD = '|| to_char(nvl(l_bal_out_tab(22).balance_value,0)));
977 hr_utility.trace( 'FIT_SUPP_WITHHELD_' || l_asg_type || '_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(23).balance_value,0)));
978
979
980
981 calc_PRV_GRS := nvl(l_bal_out_tab(1).balance_value,0) -- REGULAR_EARNINGS_ASG_GRE_PTD
982 + nvl(l_bal_out_tab(2).balance_value,0) -- SUPPLEMENTAL_EARNINGS_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD
983 - nvl(l_bal_out_tab(3).balance_value,0) -- FIT_NON_AGGREGATE_RED_SUBJ_WHABLE_ASG_GRE_PTD
984 - nvl(l_bal_out_tab(4).balance_value,0) -- DEF_COMP_401K_ASG_GRE_PTD
985 - nvl(l_bal_out_tab(5).balance_value,0) -- DEF_COMP_403B_ASG_GRE_PTD
986 - nvl(l_bal_out_tab(6).balance_value,0) -- DEF_COMP_457_ASG_GRE_PTD
987 - nvl(l_bal_out_tab(7).balance_value,0) -- OTHER_PRETAX_ASG_GRE_PTD
988 - nvl(l_bal_out_tab(8).balance_value,0) -- SECTION_125_ASG_GRE_PTD
989 - nvl(l_bal_out_tab(9).balance_value,0) -- DEPENDENT_CARE_ASG_GRE_PTD
990
991 + nvl(l_bal_out_tab(10).balance_value,0) -- 'DEF_COMP_401K_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD'
992 + nvl(l_bal_out_tab(11).balance_value,0) -- 'DEF_COMP_403B_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD'
993 + nvl(l_bal_out_tab(12).balance_value,0) -- 'DEF_COMP_457_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD'
994 + nvl(l_bal_out_tab(13).balance_value,0) -- 'OTHER_PRETAX_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD'
995 + nvl(l_bal_out_tab(14).balance_value,0) -- 'SECTION_125_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD'
996 + nvl(l_bal_out_tab(15).balance_value,0) -- 'DEPENDENT_CARE_FOR_FIT_SUBJECT_TO_TAX_ASG_GRE_PTD'
997
998 + nvl(l_bal_out_tab(16).balance_value,0) -- 'FIT_NON_W2_DEF_COMP_401_ASG_GRE_PTD'
999 + nvl(l_bal_out_tab(17).balance_value,0) -- 'FIT_NON_W2_DEF_COMP_403_ASG_GRE_PTD'
1000 + nvl(l_bal_out_tab(18).balance_value,0) -- 'FIT_NON_W2_DEF_COMP_457_ASG_GRE_PTD'
1001 + nvl(l_bal_out_tab(19).balance_value,0) -- 'FIT_NON_W2_SECTION_125_ASG_GRE_PTD'
1002 + nvl(l_bal_out_tab(20).balance_value,0) -- 'FIT_NON_W2_DEPENDENT_CARE_ASG_GRE_PTD'
1003 + nvl(l_bal_out_tab(21).balance_value,0); -- 'FIT_NON_W2_OTHER_PRETAX_ASG_GRE_PTD'
1004
1005 hr_utility.trace( 'calc_PRV_GRS = '|| to_char(nvl(calc_PRV_GRS,0)));
1006
1007 calc_PRV_TAX := nvl(l_bal_out_tab(22).balance_value,0) -- FIT_WITHHELD_ASG_PTD
1008 - nvl(l_bal_out_tab(23).balance_value,0); -- FIT_SUPP_WITHHELD_ASG_GRE_PTD
1009
1010 hr_utility.trace( 'calc_PRV_TAX = '|| to_char(nvl(calc_PRV_TAX,0)));
1011
1012 ELSIF p_fed_or_state = 'STATE' THEN
1013
1014 hr_utility.trace('p_fed_or_state = STATE');
1015
1016 /*IF ((SUBSTR(l_home_juris, 1, 2)
1017 = SUBSTR(p_jurisdiction_code, 1, 2))
1018 OR
1019 p_get_regular_wage='Y') 6899939*/
1020
1021 /* Modifed for both 6899939 and 7238809 .Finding home jurisdiction based on sessiondate does not
1022 fetch correct address in 7238809 */
1023 IF ((SUBSTR(per_adr_geocode, 1, 2)
1024 = SUBSTR(p_jurisdiction_code, 1, 2))
1025 OR
1026 p_get_regular_wage='Y')
1027
1028 THEN
1029 /*
1030 * If we are processing home jurisdiction, then return
1031 * only aggregate wages, otherwise return full wages
1032 */
1033 l_get_full_wage := 'N';
1034 END IF;
1035
1036 SELECT creator_id
1037 INTO l_defined_balance_tab(1).defined_balance_id
1038 FROM ff_user_entities
1039 WHERE user_entity_name = 'SIT_SUBJ_WHABLE_' || l_asg_type || '_JD_GRE_PTD'
1040 AND legislation_code = 'US';
1041
1042 hr_utility.trace('SIT_SUBJ_WHABLE_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1043 || to_char(l_defined_balance_tab(1).defined_balance_id));
1044
1045 l_defined_balance_tab(1).balance_value := 0;
1046
1047 l_context_tab(1).tax_unit_id := p_tax_unit_id;
1048 l_context_tab(1).jurisdiction_code := p_jurisdiction_code;
1049 l_context_tab(1).source_id := null;
1050 l_context_tab(1).source_text := null;
1051 l_context_tab(1).source_number := null;
1052 l_context_tab(1).source_text2 := null;
1053
1054 SELECT creator_id
1055 INTO l_defined_balance_tab(2).defined_balance_id
1056 FROM ff_user_entities
1057 WHERE user_entity_name = 'SIT_NON_AGGREGATE_RED_SUBJ_WHABLE_' || l_asg_type || '_JD_GRE_PTD'
1058 AND legislation_code = 'US';
1059
1060 hr_utility.trace('SIT_NON_AGGREGATE_RED_SUBJ_WHABLE_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1061 || to_char(l_defined_balance_tab(2).defined_balance_id));
1062
1063 l_defined_balance_tab(2).balance_value := 0;
1064
1065 l_context_tab(2).tax_unit_id := p_tax_unit_id;
1066 l_context_tab(2).jurisdiction_code := p_jurisdiction_code;
1067 l_context_tab(2).source_id := null;
1068 l_context_tab(2).source_text := null;
1069 l_context_tab(2).source_number := null;
1070 l_context_tab(2).source_text2 := null;
1071
1072 SELECT creator_id
1073 INTO l_defined_balance_tab(3).defined_balance_id
1074 FROM ff_user_entities
1075 WHERE user_entity_name = 'SIT_PRE_TAX_REDNS_' || l_asg_type || '_JD_GRE_PTD'
1076 AND legislation_code = 'US';
1077
1078 hr_utility.trace('SIT_PRE_TAX_REDNS_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1079 || to_char(l_defined_balance_tab(3).defined_balance_id));
1080
1081 l_defined_balance_tab(3).balance_value := 0;
1082
1083 l_context_tab(3).tax_unit_id := p_tax_unit_id;
1084 l_context_tab(3).jurisdiction_code := p_jurisdiction_code;
1085 l_context_tab(3).source_id := null;
1086 l_context_tab(3).source_text := null;
1087 l_context_tab(3).source_number := null;
1088 l_context_tab(3).source_text2 := null;
1089
1090 SELECT creator_id
1091 INTO l_defined_balance_tab(4).defined_balance_id
1092 FROM ff_user_entities
1093 WHERE user_entity_name = 'SIT_WITHHELD_' || l_asg_type || '_JD_GRE_PTD'
1094 AND legislation_code = 'US';
1095
1096 hr_utility.trace('SIT_WITHHELD_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1097 || to_char(l_defined_balance_tab(4).defined_balance_id));
1098
1099 l_defined_balance_tab(5).balance_value := 0;
1100
1101 l_context_tab(4).tax_unit_id := p_tax_unit_id;
1102 l_context_tab(4).jurisdiction_code := p_jurisdiction_code;
1103 l_context_tab(4).source_id := null;
1104 l_context_tab(4).source_text := null;
1105 l_context_tab(4).source_number := null;
1106 l_context_tab(4).source_text2 := null;
1107
1108 SELECT creator_id
1109 INTO l_defined_balance_tab(5).defined_balance_id
1110 FROM ff_user_entities
1111 WHERE user_entity_name = 'SIT_SUPP_WITHHELD_' || l_asg_type || '_JD_GRE_PTD'
1112 AND legislation_code = 'US';
1113
1114 hr_utility.trace('SIT_SUPP_WITHHELD_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1115 || to_char(l_defined_balance_tab(5).defined_balance_id));
1116
1117 l_defined_balance_tab(5).balance_value := 0;
1118
1119 l_context_tab(5).tax_unit_id := p_tax_unit_id;
1120 l_context_tab(5).jurisdiction_code := p_jurisdiction_code;
1121 l_context_tab(5).source_id := null;
1122 l_context_tab(5).source_text := null;
1123 l_context_tab(5).source_number := null;
1124 l_context_tab(5).source_text2 := null;
1125
1126 pay_balance_pkg.get_value (p_assignment_action_id => l_bal_assact,
1127 p_defined_balance_lst => l_defined_balance_tab,
1128 p_context_lst => l_context_tab,
1129 p_get_rr_route => FALSE,
1130 p_get_rb_route => FALSE,
1131 p_output_table => l_bal_out_tab);
1132
1133 hr_utility.trace('Return value from balance call');
1134 hr_utility.trace( 'SIT_SUBJ_WHABLE_' || l_asg_type || '_JD_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(1).balance_value,0)));
1135 hr_utility.trace( 'SIT_NON_AGGREGATE_RED_SUBJ_WHABLE_' || l_asg_type || '_JD_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(2).balance_value,0)));
1136 hr_utility.trace( 'SIT_PRE_TAX_REDNS_' || l_asg_type || '_JD_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(3).balance_value,0)));
1137 hr_utility.trace( 'SIT_WITHHELD_' || l_asg_type || '_JD_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(4).balance_value,0)));
1138 hr_utility.trace( 'SIT_SUPP_WITHHELD_' || l_asg_type || '_JD_GRE_PTD = '|| to_char(nvl(l_bal_out_tab(5).balance_value,0)));
1139
1140 calc_PRV_GRS := nvl(l_bal_out_tab(1).balance_value,0) -- SIT_SUBJ_WHABLE_ASG_JD_GRE_PTD
1141 - nvl(l_bal_out_tab(3).balance_value,0); -- SIT_PRE_TAX_REDNS_ASG_JD_GRE_PTD
1142
1143
1144 calc_PRV_TAX := nvl(l_bal_out_tab(4).balance_value,0); -- SIT_WITHHELD_ASG_JD_GRE_PTD
1145
1146 IF (l_get_full_wage <> 'Y')
1147 THEN
1148 calc_PRV_GRS := calc_PRV_GRS
1149 -NVL(l_bal_out_tab(2).balance_value,0);
1150 -- SIT_NON_AGGREGATE_RED_SUBJ_WHABLE_ASG_JD_GRE_PTD
1151 calc_PRV_TAX := calc_PRV_TAX
1152 -NVL(l_bal_out_tab(5).balance_value,0);
1153 -- SIT_SUPP_WITHHELD_ASG_JD_GRE_PTD
1154 END IF;
1155
1156 hr_utility.trace( 'calc_PRV_GRS = '|| to_char(nvl(calc_PRV_GRS,0)));
1157 hr_utility.trace( 'calc_PRV_TAX = '|| to_char(nvl(calc_PRV_TAX,0)));
1158 -- End of State Level Balance Fetch
1159 --
1160 --{
1161 -- This piece of code added for determining the Previous Pay Period City Level balances
1162 -- For fixing bug # 3915176
1163 -- Only City Tax withheld is derived from this piece of code not City level Wages
1164 -- Code needs modification for deriving City level wages
1165 --
1166 ELSIF p_fed_or_state = 'CITY' THEN
1167 hr_utility.trace('p_fed_or_state = CITY');
1168 SELECT creator_id
1169 INTO l_defined_balance_tab(1).defined_balance_id
1170 FROM ff_user_entities
1171 WHERE user_entity_name = 'CITY_WITHHELD_' || l_asg_type || '_JD_GRE_PTD'
1172 AND legislation_code = 'US';
1173
1174 hr_utility.trace('CITY_WITHHELD_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1175 || to_char(l_defined_balance_tab(1).defined_balance_id));
1176
1177 l_defined_balance_tab(1).balance_value := 0;
1178 l_context_tab(1).tax_unit_id := p_tax_unit_id;
1179 l_context_tab(1).jurisdiction_code := p_jurisdiction_code;
1180 l_context_tab(1).source_id := null;
1181 l_context_tab(1).source_text := null;
1182 l_context_tab(1).source_number := null;
1183 l_context_tab(1).source_text2 := null;
1184
1185 pay_balance_pkg.get_value (p_assignment_action_id => l_bal_assact,
1186 p_defined_balance_lst => l_defined_balance_tab,
1187 p_context_lst => l_context_tab,
1188 p_get_rr_route => FALSE,
1189 p_get_rb_route => FALSE,
1190 p_output_table => l_bal_out_tab);
1191 calc_PRV_GRS := 0;
1192 calc_PRV_TAX := NVL(l_bal_out_tab(1).balance_value,0);
1193
1194 hr_utility.trace( 'CITY calc_PRV_GRS = '|| to_char(nvl(calc_PRV_GRS,0)));
1195 hr_utility.trace( 'CITY calc_PRV_TAX = '|| to_char(nvl(calc_PRV_TAX,0)));
1196 --}
1197 --{
1198 -- This piece of code added for determining the Previous Pay Period County Level balances
1199 -- For fixing bug # 3915176
1200 -- Only County Tax withheld is derived from this piece of code not County level Wages
1201 -- Code needs modification for deriving County level wages
1202 --
1203 ELSIF p_fed_or_state = 'COUNTY' THEN
1204 hr_utility.trace('p_fed_or_state = COUNTY');
1205 SELECT creator_id
1206 INTO l_defined_balance_tab(1).defined_balance_id
1207 FROM ff_user_entities
1208 WHERE user_entity_name = 'COUNTY_WITHHELD_' || l_asg_type || '_JD_GRE_PTD'
1209 AND legislation_code = 'US';
1210
1211 hr_utility.trace('COUNTY_WITHHELD_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1212 || to_char(l_defined_balance_tab(1).defined_balance_id));
1213
1214 l_defined_balance_tab(1).balance_value := 0;
1215 l_context_tab(1).tax_unit_id := p_tax_unit_id;
1216 l_context_tab(1).jurisdiction_code := p_jurisdiction_code;
1217 l_context_tab(1).source_id := null;
1218 l_context_tab(1).source_text := null;
1219 l_context_tab(1).source_number := null;
1220 l_context_tab(1).source_text2 := null;
1221
1222 pay_balance_pkg.get_value (p_assignment_action_id => l_bal_assact,
1223 p_defined_balance_lst => l_defined_balance_tab,
1224 p_context_lst => l_context_tab,
1225 p_get_rr_route => FALSE,
1226 p_get_rb_route => FALSE,
1227 p_output_table => l_bal_out_tab);
1228 calc_PRV_GRS := 0;
1229 calc_PRV_TAX := NVL(l_bal_out_tab(1).balance_value,0);
1230
1231 hr_utility.trace( 'COUNTY calc_PRV_GRS = '|| to_char(nvl(calc_PRV_GRS,0)));
1232 hr_utility.trace( 'COUNTY calc_PRV_TAX = '|| to_char(nvl(calc_PRV_TAX,0)));
1233 --}
1234 --{
1235 -- This piece of code added for determining the Previous Pay Period School
1236 -- District Level balances. For fixing bug # 3915176
1237 -- Only School Dist. Tax withheld is derived from this piece of code not School Dist. level Wages
1238 -- Code needs modification for deriving School Dist. level wages
1239 --
1240 ELSIF p_fed_or_state = 'SCHOOL' THEN
1241 hr_utility.trace('p_fed_or_state = SCHOOL');
1242 SELECT creator_id
1243 INTO l_defined_balance_tab(1).defined_balance_id
1244 FROM ff_user_entities
1245 WHERE user_entity_name = 'SCHOOL_WITHHELD_' || l_asg_type || '_JD_GRE_PTD'
1246 AND legislation_code = 'US';
1247
1248 hr_utility.trace('SCHOOL_WITHHELD_' || l_asg_type || '_JD_GRE_PTD' || ' = '
1249 || to_char(l_defined_balance_tab(1).defined_balance_id));
1250
1251 l_defined_balance_tab(1).balance_value := 0;
1252 l_context_tab(1).tax_unit_id := p_tax_unit_id;
1253 l_context_tab(1).jurisdiction_code := p_jurisdiction_code;
1254 l_context_tab(1).source_id := null;
1255 l_context_tab(1).source_text := null;
1256 l_context_tab(1).source_number := null;
1257 l_context_tab(1).source_text2 := null;
1258
1259 pay_balance_pkg.get_value (p_assignment_action_id => l_bal_assact,
1260 p_defined_balance_lst => l_defined_balance_tab,
1261 p_context_lst => l_context_tab,
1262 p_get_rr_route => FALSE,
1263 p_get_rb_route => FALSE,
1264 p_output_table => l_bal_out_tab);
1265 calc_PRV_GRS := 0;
1266 calc_PRV_TAX := NVL(l_bal_out_tab(1).balance_value,0);
1267
1268 hr_utility.trace( 'School Dist. calc_PRV_GRS = '|| to_char(nvl(calc_PRV_GRS,0)));
1269 hr_utility.trace( 'School Dist. calc_PRV_TAX = '|| to_char(nvl(calc_PRV_TAX,0)));
1270 --}
1271
1272 END IF;
1273
1274 hr_utility.trace('End of GET_PRV_PTD_VALUES');
1275 return 0;
1276 --
1277 EXCEPTION
1278 WHEN OTHERS THEN
1279 hr_utility.trace('Exception handler');
1280 hr_utility.trace('SQLCODE = ' || SQLCODE);
1281 hr_utility.trace('SQLERRM = ' || SUBSTR(SQLERRM,1,80));
1282 calc_PRV_GRS := 0;
1283 calc_PRV_TAX := 0;
1284 RETURN 0;
1285 END get_prev_ptd_values;
1286
1287 /* This Function used to manage pl/table for work/tagged/home jurisdictions
1288 associated with an assignment
1289
1290 Parameter Purpose
1291 --------- -------
1292 p_INITIALIZE This parmaeter determines to process the pl/table
1293 jurisdiction_codes_tbl. This parameter expects one of 3
1294 values. (Y, N, F)
1295 Y denotes Initialize and populate the pl table
1296 N denotes Fetch jurisction that is stored next to the
1297 jurisdiction assigned to p_jurisdiction_code
1298 F denotes Fecth the First jurisdiction stored in the pl
1299 table
1300
1301 This function is being called from US_TAX_VERTEX2 formula with P_INITIALIZE
1302 value as 'Y'. PL table is always initialized for each assignment.
1303
1304 This function is called from US_TAX_VERTEX_HOME2 formula with P_INITIALIZE
1305 value as 'F'.
1306
1307 This function is repeatedly called from US_TAX_VERTEX_WORK2 depending on the
1308 number of work jurisdiction stored in the pl table.For this call P_INITIALIZE
1309 value is set as 'N'.
1310 */
1311 FUNCTION get_work_jurisdictions(p_assignment_action_id number
1312 ,p_INITIALIZE in varchar2
1313 ,p_jurisdiction_code in out NOCOPY varchar2
1314 ,p_percentage out NOCOPY number
1315 )
1316 RETURN varchar2
1317 IS
1318
1319 TOO_MANY_JURISDICTIONS EXCEPTION;
1320
1321 /*************************************************************
1322 * Maximum number of Work Jurisdictions that Quantum can Handle
1323 *************************************************************/
1324 /* bug 4383819, Changed max_jurisdiction to 200*/
1325 l_max_jurisdictions number := 200;
1326 l_assignment_id number;
1327 l_date_paid date;
1328 l_date_earned date;
1329
1330 l_ee_id number;
1331 l_jurisdiction_code varchar2(11);
1332 l_res_jurisdiction_code varchar2(11);
1333 l_jd_type varchar2(2);
1334
1335 l_percentage number;
1336 p_array_count number;
1337 l_index_value number;
1338
1339 l_jd_found varchar2(1);
1340 l_return_value varchar2(28);
1341
1342 l_state varchar2(2);
1343 l_county varchar2(120);
1344 l_city varchar2(30);
1345 l_zip_code varchar2(10);
1346
1347 l_res_state varchar2(2);
1348 l_res_county varchar2(120);
1349 l_res_city varchar2(100);
1350 l_res_zip varchar2(10);
1351
1352 l_wah Varchar2(1);
1353 cnt number;
1354 l_counter INTEGER;
1355
1356 Cursor Vertex_EE_Cursor is
1357 select pev1.element_entry_id,
1358 pev1.screen_entry_value Jurisdiction_code,
1359 pev2.screen_entry_value Percentage
1360 from pay_element_entry_values_f pev1,
1361 pay_element_entry_values_f pev2,
1362 pay_element_entries_f pee,
1363 pay_element_links_f pel,
1364 pay_element_types_f pet,
1365 pay_input_values_f piv1,
1366 pay_input_values_f piv2
1367 where pee.assignment_id = l_assignment_id
1368 -- and l_date_paid between pee.effective_start_date
1369 and l_date_earned between pee.effective_start_date
1370 and pee.effective_end_date
1371 and pee.element_link_id = pel.element_link_id
1372 and pee.effective_start_date between pel.effective_start_date
1373 and pel.effective_end_date
1374 and pel.element_type_id = pet.element_type_id
1375 and pet.element_name = 'VERTEX'
1376 and pee.effective_start_date between pet.effective_start_date
1377 and pet.effective_end_date
1378 and pee.element_entry_id = pev1.element_entry_id
1379 and pee.effective_start_date between pev1.effective_start_date
1380 and pev1.effective_end_date
1381 and pev1.input_value_id = piv1.input_value_id
1382 and pee.effective_start_date between piv1.effective_start_date
1383 and piv1.effective_end_date
1384 and piv1.name = 'Jurisdiction'
1385 and pee.element_entry_id = pev2.element_entry_id
1386 and pee.effective_start_date between pev2.effective_start_date
1387 and pev2.effective_end_date
1388 and pev2.input_value_id = piv2.input_value_id
1389 and pee.effective_start_date between piv2.effective_start_date
1390 and piv2.effective_end_date
1391 and piv2.name = 'Percentage';
1392
1393 Cursor tagged_earnings_Cursor is
1394 select /*+ INDEX (paa pay_assignment_actions_n51) */ distinct
1395 peev.element_entry_id,
1396 peev.screen_entry_value
1397 from pay_element_classifications pec
1398 ,pay_element_types_f pet
1399 ,pay_element_entries_f pee
1400 ,pay_element_links_f pel
1401 ,pay_input_values_f piv
1402 ,pay_element_entry_values_f peev
1403 where pec.classification_name in
1404 ( 'Earnings', 'Supplemental Earnings','Imputed Earnings' )
1405 and pet.classification_id = pec.classification_id
1406 and pee.effective_start_date between pet.effective_start_date
1407 and pet.effective_end_date
1408 and pee.assignment_id = l_assignment_id
1409 and l_date_earned between pee.effective_start_date
1410 and pee.effective_end_date
1411 and pet.element_type_id = pel.element_type_id
1412 and pel.element_link_id = pee.element_link_id
1413 and pee.effective_start_date between pel.effective_start_date
1414 and pel.effective_end_date
1415 and pet.element_type_id = piv.element_type_id
1416 and piv.name = 'Jurisdiction'
1417 and pee.effective_start_date between piv.effective_start_date
1418 and piv.effective_end_date
1419 and pee.element_entry_id = peev.element_entry_id
1420 and peev.input_value_id = piv.input_value_id
1421 and pee.effective_start_date between peev.effective_start_date
1422 and peev.effective_end_date
1423 and peev.screen_entry_value is not null;
1424
1425 -- Get flag to determine assignment has only IT time.
1426 CURSOR csr_use_it_flag (p_assignment_action_id IN NUMBER) IS
1427 SELECT NVL(fed.fed_information1,'N'),paa.assignment_id
1428 FROM pay_us_emp_fed_tax_rules_f fed,
1429 pay_assignment_actions paa,
1430 pay_payroll_actions ppa
1431 WHERE paa.assignment_id = fed.assignment_id
1432 AND paa.assignment_action_id = p_assignment_action_id
1433 AND paa.payroll_action_id = ppa.payroll_action_id
1434 AND NVL(ppa.date_earned,ppa.effective_date)
1435 BETWEEN fed.effective_start_date AND fed.effective_end_date;
1436
1437 l_use_it_flag pay_us_emp_fed_tax_rules_f.fed_information1%TYPE;
1438 l_payroll_id pay_payrolls_f.payroll_id%TYPE;
1439 l_time_period_id pay_payroll_actions.time_period_id%TYPE;
1440 l_return_flag VARCHAR2(2);
1441 l_business_group_id NUMBER;
1442 l_tax_unit_id NUMBER;
1443
1444 BEGIN
1445 -- hr_utility.trace_on(NULL,'SK_hr_us_ff_udf1');
1446 hr_utility.trace('Begin get_work_jurisdictions');
1447 hr_utility.trace('get_work_jurisdictions query 1');
1448 hr_utility.trace('Fetch Payroll Details ');
1449
1450 SELECT paa.assignment_id,
1451 ppa.EFFECTIVE_DATE,
1452 ppa.date_earned,
1453 ppa.time_period_id,
1454 ppa.payroll_id,
1455 ppa.business_group_id,
1456 paa.tax_unit_id
1457 INTO l_assignment_id,
1458 l_date_paid,
1459 l_date_earned,
1460 l_time_period_id,
1461 l_payroll_id,
1462 l_business_group_id,
1463 l_tax_unit_id
1464 FROM pay_assignment_actions paa,
1465 pay_payroll_actions ppa
1466 WHERE paa.assignment_action_id = p_assignment_action_id
1467 AND ppa.payroll_action_id = paa.payroll_action_id;
1468
1469 hr_utility.trace('Assignment_Action_Id :'||to_char(p_assignment_action_id));
1470 hr_utility.trace('Assignment_ID :'||to_char(l_assignment_id));
1471 hr_utility.trace('Jurisdiction Code :'||p_jurisdiction_code);
1472 hr_utility.trace('Initialize Flag :'||p_initialize);
1473 hr_utility.trace('Date Earned :'||to_char(l_date_earned,'dd-mon-yyyy'));
1474 hr_utility.trace('Date Paid :'||to_char(l_date_paid,'dd-mon-yyyy'));
1475
1476 OPEN csr_use_it_flag(p_assignment_action_id);
1477 FETCH csr_use_it_flag INTO l_use_it_flag,
1478 l_assignment_id;
1479 IF csr_use_it_flag%NOTFOUND THEN
1480 l_use_it_flag := 'N';
1481 END IF;
1482 CLOSE csr_use_it_flag;
1483
1484 hr_utility.trace('Process Information Hours : '||l_use_it_flag);
1485
1486 IF l_use_it_flag = 'Y' AND p_initialize = 'Y' THEN
1487 --{
1488 g_use_it_flag := 'Y';
1489 hr_utility.trace('EMJT: Calling get_it_work_jurisdiction to process Information Hours');
1490 l_return_flag := get_it_work_jurisdictions
1491 (p_assignment_action_id => p_assignment_action_id
1492 ,p_initialize => p_initialize
1493 ,p_jurisdiction_code => p_jurisdiction_code
1494 ,p_percentage => p_percentage
1495 ,p_assignment_id => l_assignment_id
1496 ,p_date_paid => l_date_paid
1497 ,p_date_earned => l_date_earned
1498 ,p_time_period_id => l_time_period_id
1499 ,p_payroll_id => l_payroll_id
1500 ,p_business_group_id => l_business_group_id
1501 ,p_tax_unit_id => l_tax_unit_id
1502 );
1503 p_jurisdiction_code := 'NULL';
1504 p_percentage := 0;
1505 hr_utility.trace(' Returning after call to get_it_work_jurisdiction');
1506 RETURN('0');
1507 --}
1508 END IF; -- l_use_it_flag = 'Y'
1509
1510
1511 IF l_use_it_flag = 'N' THEN
1512 --{
1513 hr_utility.trace('Taxation would use W-4% configured for the assignment ');
1514 cnt :=0;
1515 IF p_initialize = 'Y' THEN
1516 -- LOAD the pl Table and return only NULL jurisdiction
1517 --{
1518 hr_utility.trace('get_work_jurisdictions || p_initialize = Y');
1519 g_use_it_flag := 'N';
1520 --
1521 -- initialize the PL/SQL tables
1522 --
1523 jurisdiction_codes_tbl.delete;
1524 res_jurisdiction_codes_tbl.delete; -- Added for Bug # 4715851
1525 state_processed_tbl.delete;
1526 county_processed_tbl.delete;
1527 city_processed_tbl.delete;
1528
1529 hr_utility.trace('get_work_jurisdictions plsql tables cleared');
1530
1531 -- GET the RESIDENT jurisdictions and load in to the *_processed_tables
1532 --
1533 hr_utility.trace('2nd Query in get_work_jurisdictions for fetching '
1534 ||' resident address details');
1535 SELECT nvl(ADDR.add_information17,ADDR.region_2) state,
1536 nvl(ADDR.add_information19,ADDR.region_1) county,
1537 nvl(ADDR.add_information18,ADDR.town_or_city) city,
1538 nvl(ADDR.add_information20,ADDR.postal_code) zip,
1539 nvl(ASSIGN.work_at_home,'N')
1540 INTO l_res_state,
1541 l_res_county,
1542 l_res_city,
1543 l_res_zip,
1544 l_wah
1545 FROM per_addresses ADDR
1546 ,per_all_assignments_f ASSIGN
1547 WHERE l_date_earned BETWEEN ASSIGN.effective_start_date
1548 AND ASSIGN.effective_end_date
1549 and ASSIGN.assignment_id = l_assignment_id
1550 and ADDR.person_id = ASSIGN.person_id
1551 and ADDR.primary_flag = 'Y'
1552 and l_date_earned BETWEEN nvl(ADDR.date_from, l_date_earned)
1553 AND nvl(ADDR.date_to, l_date_earned);
1554
1555 hr_utility.trace('2nd query returned res address details');
1556 l_res_jurisdiction_code := hr_us_ff_udfs.addr_val(l_res_state
1557 , l_res_county
1558 , l_res_city
1559 , l_res_zip);
1560
1561 -- IF this is a user defined city IE: city_code = 'U***' the change
1562 -- the city code to all 0 (zeros)
1563
1564 IF substr(l_res_jurisdiction_code,8,1) = 'U' THEN
1565 l_res_jurisdiction_code := substr(l_res_jurisdiction_code,1,7) ||
1566 '0000' ;
1567 END IF;
1568
1569 hr_utility.trace('Resident Jurisdiction Code = ' ||
1570 l_res_jurisdiction_code);
1571 hr_utility.trace('Home Workers Flag = ' || l_wah);
1572
1573 IF l_wah = 'N' THEN
1574 --{
1575 -- Get the vertex element Entries
1576 OPEN Vertex_EE_Cursor;
1577 FETCH Vertex_EE_Cursor into
1578 l_ee_id,
1579 l_jurisdiction_code,
1580 l_percentage;
1581
1582 hr_utility.trace('open fetch vertex_ee_cursor');
1583 LOOP
1584 hr_utility.trace('Processing Tagged Jurisdiction Code'||
1585 l_jurisdiction_code);
1586 EXIT WHEN Vertex_EE_Cursor%NOTFOUND;
1587 -- IF this is a user defined city IE: city_code = 'U***' the
1588 -- change the city code to all 0 (zeros)
1589 if substr(l_jurisdiction_code,8,1) = 'U' then
1590 l_jurisdiction_code := substr(l_jurisdiction_code,1,7) ||
1591 '0000' ;
1592 end if;
1593 IF nvl(l_percentage,0) <> 0 THEN
1594 --{
1595 IF jurisdiction_codes_tbl.count >= l_max_jurisdictions THEN
1596 raise TOO_MANY_JURISDICTIONS;
1597 hr_utility.trace('too many jurisdictions');
1598 END IF;
1599 hr_utility.trace('Jurisdiction Code'|| l_jurisdiction_code ||
1600 ' loaded into pl table');
1601 jurisdiction_codes_tbl( to_number(substr(l_jurisdiction_code,
1602 1,2) ||
1603 substr(l_jurisdiction_code,4,3) ||
1604 substr(l_jurisdiction_code,8,4) )
1605 ).jurisdiction_code := l_jurisdiction_code;
1606 jurisdiction_codes_tbl( to_number(substr(l_jurisdiction_code,
1607 1,2) ||
1608 substr(l_jurisdiction_code,4,3) ||
1609 substr(l_jurisdiction_code,8,4) )
1610 ).percentage := l_percentage;
1611 jurisdiction_codes_tbl( to_number(substr(l_jurisdiction_code,
1612 1,2) ||
1613 substr(l_jurisdiction_code,4,3) ||
1614 substr(l_jurisdiction_code,8,4) )
1615 ).hours := 0;
1616 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1617 1,2) ||
1618 substr(l_jurisdiction_code,4,3) ||
1619 substr(l_jurisdiction_code,8,4) )
1620 ).jd_type := 'WK';
1621 --}
1622 END IF;
1623 FETCH Vertex_EE_Cursor into
1624 l_ee_id,
1625 l_jurisdiction_code,
1626 l_percentage;
1627 END LOOP;
1628 hr_utility.trace('end of loop 1 vertex_ee_cursor');
1629 CLOSE Vertex_EE_Cursor;
1630 --}
1631 END IF; -- if l_wah = 'N' then
1632
1633 -- Look for and load tagged earnings;
1634 OPEN tagged_earnings_Cursor;
1635 FETCH tagged_earnings_Cursor into
1636 l_ee_id,
1637 l_jurisdiction_code;
1638
1639 hr_utility.trace(' open fetch tagged_earnings_cursor');
1640 hr_utility.trace('loop tagged earnings cursor');
1641
1642 LOOP
1643 hr_utility.trace('Processing Tagged Jurisdiction Code'||
1644 l_jurisdiction_code);
1645 EXIT WHEN tagged_earnings_Cursor%NOTFOUND;
1646 -- IF this is a user defined city IE: city_code = 'U***' the
1647 -- change the city code to all 0 (zeros)
1648
1649 IF substr(l_jurisdiction_code,8,1) = 'U' then
1650 l_jurisdiction_code := substr(l_jurisdiction_code,1,7)
1651 || '0000' ;
1652 END IF;
1653 -- 1) see if JD exists in plsql table
1654 -- 2) if not add the JD, to the plsql table with a 0 percent.
1655 IF jurisdiction_codes_tbl.EXISTS(
1656 to_number(substr(l_jurisdiction_code,1,2) ||
1657 substr(l_jurisdiction_code,4,3) ||
1658 substr(l_jurisdiction_code,8,4) )
1659 ) THEN
1660 --{
1661 NULL;
1662 --}
1663 ELSE
1664 --{
1665 IF jurisdiction_codes_tbl.count >= l_max_jurisdictions THEN
1666 raise TOO_MANY_JURISDICTIONS;
1667 hr_utility.trace('too many jurisdictions');
1668 END IF;
1669 hr_utility.trace('Jurisdiction Code'|| l_jurisdiction_code ||
1670 ' loaded into pl table');
1671
1672 jurisdiction_codes_tbl( to_number(substr(l_jurisdiction_code,
1673 1,2) ||
1674 substr(l_jurisdiction_code,4,3) ||
1675 substr(l_jurisdiction_code,8,4) )
1676 ).jurisdiction_code := l_jurisdiction_code;
1677 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1678 1,2) ||
1679 substr(l_jurisdiction_code,4,3) ||
1680 substr(l_jurisdiction_code,8,4) )
1681 ).percentage := 0;
1682 jurisdiction_codes_tbl( to_number(substr(l_jurisdiction_code,
1683 1,2) ||
1684 substr(l_jurisdiction_code,4,3) ||
1685 substr(l_jurisdiction_code,8,4) )
1686 ).hours := 0;
1687
1688 --}
1689 END IF;
1690 -- This is set JD_TYPE for Tagged earnings
1691 if l_jurisdiction_code = l_res_jurisdiction_code then
1692 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1693 1,2) ||
1694 substr(l_jurisdiction_code,4,3) ||
1695 substr(l_jurisdiction_code,8,4) )
1696 ).jd_type := 'RT';
1697 else
1698 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1699 1,2) ||
1700 substr(l_jurisdiction_code,4,3) ||
1701 substr(l_jurisdiction_code,8,4) )
1702 ).jd_type := 'TG';
1703 end if;
1704
1705 FETCH tagged_earnings_Cursor into
1706 l_ee_id,
1707 l_jurisdiction_code;
1708 hr_utility.trace('fetch 2 from cursor tagged_earnings_Cursor');
1709
1710 END LOOP;
1711 hr_utility.trace('end of loop 2 tagged_earnings_Cursor');
1712 CLOSE tagged_earnings_Cursor;
1713 --
1714 -- This section is determine Primary Work Jurisdiction for the assignment
1715 --
1716 IF l_wah = 'N' THEN -- Home Workers flag is set to NO
1717 --{
1718 -- Find and load the primary Work location to the jurisdiction.
1719 SELECT nvl(HRLOC.loc_information18,HRLOC.town_or_city),
1720 nvl(HRLOC.loc_information19,HRLOC.region_1),
1721 nvl(HRLOC.loc_information17,HRLOC.region_2),
1722 substr(nvl(HRLOC.loc_information20,HRLOC.postal_code)
1723 ,1,5)
1724 INTO l_city,
1725 l_county,
1726 l_state,
1727 l_zip_code
1728 FROM hr_locations HRLOC
1729 , hr_soft_coding_keyflex HRSCKF
1730 , per_all_assignments_f ASSIGN
1731 WHERE l_date_earned BETWEEN ASSIGN.effective_start_date
1732 AND ASSIGN.effective_end_date
1733 AND ASSIGN.assignment_id = l_assignment_id
1734 AND ASSIGN.soft_coding_keyflex_id = HRSCKF.soft_coding_keyflex_id
1735 AND nvl(HRSCKF.segment18,
1736 ASSIGN.location_id) = HRLOC.location_id;
1737 l_jd_found := 'N';
1738 hr_utility.trace('Primary work location query');
1739 l_jurisdiction_code := hr_us_ff_udfs.addr_val(l_state,
1740 l_county,
1741 l_city,
1742 l_zip_code);
1743 hr_utility.trace('Primary work loc JD CODE = ' ||
1744 l_jurisdiction_code);
1745
1746 -- IF this is a user defined city IE: city_code = 'U***' the
1747 -- change the city code to all 0 (zeros)
1748 if substr(l_jurisdiction_code,8,1) = 'U' then
1749 l_jurisdiction_code := substr(l_jurisdiction_code,1,7) ||
1750 '0000' ;
1751 end if;
1752
1753 IF jurisdiction_codes_tbl.EXISTS(
1754 to_number(substr(l_jurisdiction_code,1,2) ||
1755 substr(l_jurisdiction_code,4,3) ||
1756 substr(l_jurisdiction_code,8,4) )
1757 ) THEN
1758 --{
1759 hr_utility.trace('Work Jurisdiction already loaded.'||
1760 ' Updating JD_Type');
1761 if l_jurisdiction_code = l_res_jurisdiction_code then
1762 jurisdiction_codes_tbl(to_number(substr(
1763 l_jurisdiction_code, 1,2) ||
1764 substr(l_jurisdiction_code,4,3) ||
1765 substr(l_jurisdiction_code,8,4) )
1766 ).jd_type := 'RW';
1767 else
1768 jurisdiction_codes_tbl(to_number(substr(
1769 l_jurisdiction_code, 1,2) ||
1770 substr(l_jurisdiction_code,4,3) ||
1771 substr(l_jurisdiction_code,8,4) )
1772 ).jd_type := 'WK';
1773 end if;
1774 --}
1775 ELSE
1776 --{
1777 hr_utility.trace('Jurisdiction Code'|| l_jurisdiction_code ||
1778 ' loaded into pl table');
1779 IF jurisdiction_codes_tbl.count >= l_max_jurisdictions THEN
1780 raise TOO_MANY_JURISDICTIONS;
1781 hr_utility.trace('too many jurisdictions');
1782 END IF;
1783 hr_utility.trace('Populating table with Pri work location');
1784 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1785 1,2) || substr(l_jurisdiction_code,4,3) ||
1786 substr(l_jurisdiction_code,8,4) )
1787 ).jurisdiction_code := l_jurisdiction_code;
1788 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1789 1,2) || substr(l_jurisdiction_code,4,3) ||
1790 substr(l_jurisdiction_code,8,4) )
1791 ).percentage := 0;
1792 jurisdiction_codes_tbl(to_number(substr(
1793 l_jurisdiction_code, 1,2) ||
1794 substr(l_jurisdiction_code,4,3) ||
1795 substr(l_jurisdiction_code,8,4) )
1796 ).jd_type := 'WK';
1797 jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
1798 1,2) ||
1799 substr(l_jurisdiction_code,4,3) ||
1800 substr(l_jurisdiction_code,8,4) )
1801 ).hours := 0;
1802
1803 --}
1804 END IF;
1805 --}
1806 END IF; -- if l_wah = 'N' then
1807 -- Load the resident jurisdiction if not already loaded via one of the
1808 -- other queries. Note the resident jurisdiction is querried at the
1809 -- begining of this function.
1810 hr_utility.trace('Processing Resident jurisdiction ');
1811 IF jurisdiction_codes_tbl.EXISTS(
1812 to_number(substr(l_res_jurisdiction_code,
1813 1,2) ||
1814 substr(l_res_jurisdiction_code,4,3) ||
1815 substr(l_res_jurisdiction_code,8,4) )
1816 ) THEN
1817 --{
1818 hr_utility.trace('Resident jurisdiction exist in pl table');
1819 IF (l_wah = 'N') THEN
1820 --{
1821 IF (jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code, 1,2) ||
1822 substr(l_res_jurisdiction_code, 4,3) ||
1823 substr(l_res_jurisdiction_code, 8,4) )
1824 ).jd_type <> 'RT')
1825 THEN
1826 jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code, 1,2) ||
1827 substr(l_res_jurisdiction_code, 4,3) ||
1828 substr(l_res_jurisdiction_code, 8,4) )
1829 ).jd_type := 'RW';
1830 END IF;
1831 --}
1832 ELSE
1833 --{
1834 jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code, 1,2) ||
1835 substr(l_res_jurisdiction_code, 4,3) ||
1836 substr(l_res_jurisdiction_code, 8,4) )
1837 ).jd_type := 'HW';
1838 --}
1839 END IF;
1840 --}
1841 ELSE
1842 --{
1843 -- If Residence jurisdiction does not exist in the pl/sql table
1844 IF jurisdiction_codes_tbl.count >= l_max_jurisdictions THEN
1845 raise TOO_MANY_JURISDICTIONS;
1846 hr_utility.trace('too many jurisdictions');
1847 END IF;
1848 hr_utility.trace('Populating pl table for Resident Jurisdiction');
1849 --
1850 -- For bug 4715851 res_jurisdiction_codes_tbl used
1851 -- in place of jurisdiction_codes_tbl
1852 IF l_wah = 'N' THEN
1853 --{
1854 res_jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code,1,2) ||
1855 substr(l_res_jurisdiction_code,4,3) ||
1856 substr(l_res_jurisdiction_code,8,4) )
1857 ).jurisdiction_code := l_res_jurisdiction_code;
1858
1859 res_jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code,1,2) ||
1860 substr(l_res_jurisdiction_code,4,3) ||
1861 substr(l_res_jurisdiction_code,8,4) )
1862 ).percentage := 0;
1863 res_jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code,1,2) ||
1864 substr(l_res_jurisdiction_code,4,3) ||
1865 substr(l_res_jurisdiction_code,8,4))
1866 ).jd_type := 'RS';
1867 res_jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code,1,2) ||
1868 substr(l_res_jurisdiction_code, 4,3) ||
1869 substr(l_res_jurisdiction_code, 8,4))
1870 ).hours := 0;
1871 --}
1872 ELSE
1873 --{
1874 jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code,1,2) ||
1875 substr(l_res_jurisdiction_code,4,3) ||
1876 substr(l_res_jurisdiction_code,8,4) )
1877 ).jurisdiction_code := l_res_jurisdiction_code;
1878
1879 jurisdiction_codes_tbl( to_number(substr(l_res_jurisdiction_code,
1880 1,2) ||
1881 substr(l_res_jurisdiction_code,4,3) ||
1882 substr(l_res_jurisdiction_code,8,4) )
1883 ).percentage := 100;
1884 jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code, 1,2) ||
1885 substr(l_res_jurisdiction_code, 4,3) ||
1886 substr(l_res_jurisdiction_code, 8,4) )
1887 ).jd_type := 'HW';
1888 jurisdiction_codes_tbl(to_number(substr(l_res_jurisdiction_code, 1,2) ||
1889 substr(l_res_jurisdiction_code, 4,3) ||
1890 substr(l_res_jurisdiction_code, 8,4) )
1891 ).hours := 0;
1892 --}
1893 END IF; --l_wah = 'N'
1894 --}
1895 END IF;
1896 hr_utility.trace('Jurisdiction Table count = '||
1897 to_char(jurisdiction_codes_tbl.COUNT));
1898 hr_utility.trace('Return section begin');
1899 --As Initialize section doesn't expect the return value
1900 p_jurisdiction_code := 'NULL';
1901 p_percentage := 0;
1902 RETURN('0');
1903
1904 --}End of Initialize = 'Y'
1905 END IF;
1906 --}
1907 END IF; --l_use_it_flag = 'N' THEN
1908
1909 IF p_initialize = 'F' THEN
1910 -- This is to get first jurisdiction loaed into pl table
1911 -- jurisdiction_codes_tbl
1912 -- BEGIN
1913 IF jurisdiction_codes_tbl.COUNT = 0 THEN
1914 --{
1915 hr_utility.trace('Table count = 0');
1916 p_jurisdiction_code := '';
1917 p_percentage := 0;
1918 --}
1919 ELSE
1920 --{
1921 hr_utility.trace('Table count <> 0');
1922 p_jurisdiction_code :=
1923 jurisdiction_codes_tbl(jurisdiction_codes_tbl.FIRST).jurisdiction_code;
1924 p_percentage :=
1925 jurisdiction_codes_tbl(jurisdiction_codes_tbl.FIRST).percentage;
1926 --}
1927 END IF;
1928 hr_utility.trace('p_jurisdiction_code = ' || p_jurisdiction_code);
1929 hr_utility.trace('p_percentage = ' || to_char(p_percentage));
1930 hr_utility.trace('Done with p_initialize F');
1931 --
1932 --} End of Initialize = 'F'
1933 ELSIF p_initialize = 'C' THEN
1934 -- This is to get the number of jurisdiction associated with
1935 -- a given assignment
1936 -- BEGIN
1937 hr_utility.trace('This is to count no of jurisdiction associated with');
1938 hr_utility.trace('all the element entries defined for the assignment ');
1939 cnt := 0;
1940 IF jurisdiction_codes_tbl.COUNT >= 1
1941 THEN
1942 --{
1943 cnt := jurisdiction_codes_tbl.COUNT;
1944 l_counter := NULL;
1945 l_counter := jurisdiction_codes_tbl.FIRST;
1946 WHILE l_counter IS NOT NULL
1947 LOOP
1948 if (jurisdiction_codes_tbl(l_counter).jd_type = 'RS')
1949 then
1950 cnt := cnt - 1;
1951 end if;
1952 l_counter := jurisdiction_codes_tbl.NEXT(l_counter);
1953 END LOOP;
1954 p_percentage := cnt;
1955 --}
1956 END IF;
1957 hr_utility.trace('Work Jurisdiction Table Count = '||to_char(cnt));
1958 hr_utility.trace('Done with p_initialize=C');
1959
1960 --} End of Initialize = 'C'
1961 ELSIF p_initialize = 'N' THEN
1962
1963 hr_utility.trace('Initialize = n');
1964 hr_utility.trace('Fetching Next Jurisdiction stored in PL Table');
1965 IF jurisdiction_codes_tbl.EXISTS(
1966 to_number(substr(p_jurisdiction_code,1,2) ||
1967 substr(p_jurisdiction_code,4,3) ||
1968 substr(p_jurisdiction_code,8,4) )
1969 ) THEN
1970
1971 IF jurisdiction_codes_tbl.NEXT(to_number(substr(p_jurisdiction_code,1,2) ||
1972 substr(p_jurisdiction_code,4,3) ||
1973 substr(p_jurisdiction_code,8,4) )
1974 ) is NULL THEN
1975 p_jurisdiction_code := 'NULL';
1976 p_percentage := 0;
1977 hr_utility.trace('Next jurisdiction is NULL');
1978 ELSE -- When next jurisdiction is Not Null
1979 --{
1980 -- This is to fetch next jurisdiction from the pl table
1981 -- when information time is being processed
1982 --{
1983 hr_utility.trace('Fetching Next Jurisdiction');
1984 l_index_value :=jurisdiction_codes_tbl.next (
1985 to_number(substr(p_jurisdiction_code,1,2) ||
1986 substr(p_jurisdiction_code,4,3) ||
1987 substr(p_jurisdiction_code,8,4) )
1988 );
1989 p_jurisdiction_code :=
1990 jurisdiction_codes_tbl(l_index_value).jurisdiction_code;
1991 p_percentage := jurisdiction_codes_tbl(l_index_value).percentage;
1992 --}
1993 END IF;
1994 --}
1995 ELSE -- if jurisdiction code passed does not exist in PL table
1996 --{
1997 hr_utility.trace('Jurisdiction Code '||p_jurisdiction_code||
1998 ' passed does not exist in PL table ');
1999 p_jurisdiction_code := 'NULL';
2000 p_percentage := 0;
2001 hr_utility.trace('Next jurisdiction is NULL');
2002 --}
2003 END IF;
2004 hr_utility.trace('p_jurisdiction_code = ' || p_jurisdiction_code);
2005 hr_utility.trace('p_percentage = ' || to_char(p_percentage));
2006 hr_utility.trace('End of get_work_jurisdictions for p_initialize=N');
2007 --}
2008 END IF;
2009 --
2010 -- This section is used only for debug
2011 hr_utility.trace('======================================================');
2012 IF jurisdiction_codes_tbl.COUNT > 0 THEN
2013 hr_utility.trace('Display the value of jurisdiction_codes_tbl');
2014 l_jurisdiction_code :=
2015 jurisdiction_codes_tbl(jurisdiction_codes_tbl.FIRST).jurisdiction_code;
2016 l_percentage :=
2017 jurisdiction_codes_tbl(jurisdiction_codes_tbl.FIRST).percentage;
2018 l_jd_type := jurisdiction_codes_tbl(jurisdiction_codes_tbl.FIRST).jd_type;
2019 hr_utility.trace('Jurisdiction_code 1st = '|| l_jurisdiction_code);
2020 hr_utility.trace('Percentage 1st = '|| to_char(l_percentage));
2021 hr_utility.trace('JD_Type 1st = '|| l_jd_type);
2022 l_jurisdiction_code :=
2023 jurisdiction_codes_tbl(jurisdiction_codes_tbl.LAST).jurisdiction_code;
2024 l_percentage :=
2025 jurisdiction_codes_tbl(jurisdiction_codes_tbl.LAST).percentage;
2026 l_jd_type := jurisdiction_codes_tbl(jurisdiction_codes_tbl.LAST).jd_type;
2027
2028 hr_utility.trace('Jurisdiction_code last = '|| l_jurisdiction_code);
2029 hr_utility.trace('Percentage last = '|| to_char(l_percentage));
2030 hr_utility.trace('JD_Type last = '|| l_jd_type);
2031 hr_utility.trace('======================================================');
2032 --
2033 -- End of pl/sql table debug messages
2034 --
2035 hr_utility.trace('Display the value of jurisdiction_codes_tbl');
2036 hr_utility.trace('End get_work_jurisdictions');
2037
2038 END IF; --jurisdiction_codes_tbl.COUNT > 0
2039
2040 RETURN ('0');
2041 /*EXCEPTION
2042 WHEN NO_DATA_FOUND THEN
2043 hr_utility.trace('Exception raised NO_DATA_FOUND in '||
2044 'get_work_jurisdictions');
2045 p_jurisdiction_code := 'NULL';
2046 p_percentage := 0;
2047 return ('0');
2048 WHEN TOO_MANY_JURISDICTIONS THEN
2049 hr_utility.set_message(801, 'PAY_75242_PAY_TOO_MANY_JD');
2050 hr_utility.set_message_token('MAX_WORK_JDS', l_max_jurisdictions);
2051 hr_utility.raise_error; -- create a new message--
2052 raise;
2053 WHEN OTHERS THEN
2054 hr_utility.trace('Exception raised OTHERS in '||
2055 'get_work_jurisdictions');
2056 hr_utility.trace('Mesg: '||substr(sqlerrm,1,45));
2057 p_jurisdiction_code := 'NULL';
2058 p_percentage := 0;
2059 return ('0');*/
2060
2061 -- End of Function get_work_jurisdictions
2062 END get_work_jurisdictions;
2063 --
2064
2065 FUNCTION Jurisdiction_processed( p_jurisdiction_code in varchar2
2066 ,p_jd_level in varchar
2067 )
2068 RETURN varchar2
2069 IS
2070 BEGIN
2071 IF p_jd_level = 'STATE' THEN
2072 IF state_processed_tbl.EXISTS( to_number(substr(p_jurisdiction_code,1,2))
2073 ) THEN
2074 RETURN 'Y';
2075 ELSE -- Added this state Jurisdiction to the state_processed_tbl table
2076 state_processed_tbl( to_number(substr(p_jurisdiction_code,1,2))
2077 ) := 'Y';
2078 RETURN 'N';
2079 END IF;
2080 ELSIF p_jd_level = 'COUNTY' THEN
2081 IF county_processed_tbl.EXISTS(to_number(substr(p_jurisdiction_code,1,2) ||
2082 substr(p_jurisdiction_code,4,3) )
2083 ) THEN
2084 RETURN 'Y';
2085 ELSE -- Added this state Jurisdiction to the county_processed_tbl table
2086 county_processed_tbl(to_number(substr(p_jurisdiction_code,1,2) ||
2087 substr(p_jurisdiction_code,4,3) )
2088 ) := 'Y';
2089 RETURN 'N';
2090 END IF;
2091 ELSIF p_jd_level = 'CITY' THEN
2092
2093 IF city_processed_tbl.EXISTS( to_number(substr(p_jurisdiction_code,1,2) ||
2094 substr(p_jurisdiction_code,4,3) ||
2095 substr(p_jurisdiction_code,8,4) )
2096 ) THEN
2097 RETURN 'Y';
2098 ELSE -- Added this state Jurisdiction to the city_processed_tbl table
2099 city_processed_tbl( to_number(substr(p_jurisdiction_code,1,2) ||
2100 substr(p_jurisdiction_code,4,3) ||
2101 substr(p_jurisdiction_code,8,4) )
2102 ) := 'Y';
2103 RETURN 'N';
2104 END IF;
2105
2106 ELSE
2107 return('N');
2108 END IF;
2109
2110 EXCEPTION
2111 WHEN OTHERS THEN
2112 return ('N');
2113 END Jurisdiction_processed;
2114
2115 FUNCTION get_fed_prev_ptd_values(
2116 p_assignment_action_id number, -- context
2117 p_tax_unit_id number, -- context
2118 p_fed_or_state varchar2, -- parameter
2119 p_regular_aggregate number, -- parameter
2120 calc_PRV_GRS OUT nocopy number,-- parameter
2121 calc_PRV_TAX OUT nocopy number)-- parameter
2122 RETURN NUMBER IS
2123 l_dummy_value number;
2124 BEGIN
2125 --{
2126 l_dummy_value := hr_us_ff_udf1.get_prev_ptd_values(p_assignment_action_id
2127 ,p_tax_unit_id
2128 ,'00-000-0000'
2129 ,p_fed_or_state
2130 ,p_regular_aggregate
2131 ,calc_PRV_GRS
2132 ,calc_PRV_TAX );
2133
2134 return 0;
2135 --
2136 EXCEPTION
2137 WHEN OTHERS THEN
2138 hr_utility.trace('Exception handler');
2139 hr_utility.trace('SQLCODE = ' || SQLCODE);
2140 hr_utility.trace('SQLERRM = ' || SUBSTR(SQLERRM,1,80));
2141 calc_PRV_GRS := 0;
2142 calc_PRV_TAX := 0;
2143 RETURN 0;
2144 --}
2145 END get_fed_prev_ptd_values;
2146
2147 FUNCTION get_jd_percent(p_jurisdiction_code VARCHAR2 -- Parameter
2148 ,p_jd_level VARCHAR2 -- Parameter
2149 ,p_hours_to_accumulate OUT nocopy NUMBER -- Parameter
2150 ,p_wages_to_accrue_flag OUT nocopy VARCHAR2 -- Parameter
2151 )
2152 RETURN NUMBER
2153 IS
2154 l_jd_level number;
2155 l_pad number;
2156 l_entry_jd number;
2157 l_max_jd number;
2158 l_temp_jd number;
2159 l_percentage number;
2160 l_index_value number;
2161 l_return number;
2162 begin
2163 --{
2164 hr_utility.trace('IN get_jd_percent');
2165 hr_utility.trace('get_jd_percent Use Information Hours Flag =>'||hr_us_ff_udf1.g_use_it_flag);
2166 IF hr_us_ff_udf1.g_use_it_flag = 'Y' THEN
2167 --{
2168 hr_utility.trace('get_jd_percent Calling Function get_it_jd_percent');
2169 l_percentage :=
2170 hr_us_ff_udf1.get_it_jd_percent(p_jurisdiction_code => p_jurisdiction_code
2171 ,p_jd_level => p_jd_level
2172 ,p_hours_to_accumulate => p_hours_to_accumulate
2173 ,p_wages_to_accrue_flag => p_wages_to_accrue_flag
2174 );
2175 hr_utility.trace('get_it_jd_percent Percentage Returned for '
2176 ||p_jd_level||' => '||to_char(l_percentage));
2177 -- RETURN l_percentage;
2178 --}
2179 ELSE
2180 --{
2181 hr_utility.trace('get_jd_percent p_jd_level = ' || p_jd_level) ;
2182 if p_jd_level = 'COUNTY' THEN
2183 l_jd_level := 5;
2184 else
2185 l_jd_level := 2;
2186 end if;
2187
2188 if substr(p_jurisdiction_code,1,1) = 0 then
2189 l_pad := 8;
2190 l_jd_level := l_jd_level - 1;
2191 else
2192 l_pad := 9;
2193 end if;
2194
2195 hr_utility.trace('get_jd_percent l_pad = ' || to_char(l_pad)) ;
2196 hr_utility.trace('get_jd_percent l_jd_level = ' || to_char(l_jd_level)) ;
2197
2198 l_entry_jd := to_number(substr(p_jurisdiction_code,1,2) ||
2199 substr(p_jurisdiction_code,4,3) ||
2200 substr(p_jurisdiction_code,8,4) );
2201
2202 l_temp_jd := rpad(substr(l_entry_jd,1,l_jd_level),l_pad,0);
2203 l_max_jd := rpad(substr(l_entry_jd,1,l_jd_level),l_pad,9);
2204
2205 hr_utility.trace('get_jd_percent l_temp_jd = ' || to_char(l_temp_jd)) ;
2206 hr_utility.trace('get_jd_percent l_max_jd = ' || to_char(l_max_jd)) ;
2207 hr_utility.trace('get_jd_percent next = ' || to_char(jurisdiction_codes_tbl.NEXT(l_temp_jd -1 ))) ;
2208
2209 if jurisdiction_codes_tbl.NEXT(l_temp_jd -1 ) is NULL
2210 OR jurisdiction_codes_tbl.NEXT(l_temp_jd -1 ) > l_max_jd THEN
2211 --{
2212 l_percentage := 0;
2213 --}
2214 else
2215 --{
2216 l_percentage := 0;
2217 l_index_value := jurisdiction_codes_tbl.NEXT(l_temp_jd - 1 );
2218 WHILE l_index_value is not null LOOP
2219 --{
2220 l_percentage := l_percentage + jurisdiction_codes_tbl(l_index_value).percentage;
2221
2222 IF jurisdiction_codes_tbl.NEXT(l_index_value) is NULL
2223 OR jurisdiction_codes_tbl.NEXT(l_index_value) > l_max_jd THEN
2224 --{
2225 l_index_value := NULL;
2226 --}
2227 ELSE
2228 --{
2229 l_index_value := jurisdiction_codes_tbl.NEXT(l_index_value);
2230 --}
2231 END IF;
2232 --}
2233 END LOOP;
2234 --}
2235 end if;
2236 hr_utility.trace('get_jd_percent Percentage Returned for '
2237 ||p_jd_level||' => '||to_char(l_percentage));
2238 -- RETURN l_percentage;
2239
2240 END IF;--IF g_use_it_flag = 'Y'
2241 RETURN l_percentage;
2242 EXCEPTION
2243 WHEN OTHERS THEN
2244 RETURN 0;
2245 --}
2246 end get_jd_percent;
2247 --
2248 -- This function would be used to fetch Jurisdiction type stored against a
2249 -- jurisdiction in the pl table jurisdiction_codes_tbl. This pl table is
2250 -- populated in function get_work_jurisdiction
2251 --
2252 FUNCTION get_jurisdiction_type(p_jurisdiction_code varchar2)
2253 RETURN varchar2
2254 IS
2255 l_jurisdiction_code varchar2(100);
2256 l_jd_type varchar2(100);
2257 BEGIN
2258 --{
2259 l_jurisdiction_code := p_jurisdiction_code;
2260 l_jd_type := 'NL';
2261 IF jurisdiction_codes_tbl.EXISTS(
2262 to_number(substr(l_jurisdiction_code,1,2) ||
2263 substr(l_jurisdiction_code,4,3) ||
2264 substr(l_jurisdiction_code,8,4) )
2265 ) THEN
2266 --{
2267 l_jd_type := jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
2268 1,2) ||
2269 substr(l_jurisdiction_code,4,3) ||
2270 substr(l_jurisdiction_code,8,4) )
2271 ).jd_type;
2272 --}
2273 ELSIF res_jurisdiction_codes_tbl.EXISTS(
2274 to_number(substr(l_jurisdiction_code,1,2) ||
2275 substr(l_jurisdiction_code,4,3) ||
2276 substr(l_jurisdiction_code,8,4) )
2277 ) THEN
2278 --{
2279 l_jd_type := res_jurisdiction_codes_tbl(to_number(substr(l_jurisdiction_code,
2280 1,2) ||
2281 substr(l_jurisdiction_code,4,3) ||
2282 substr(l_jurisdiction_code,8,4) )
2283 ).jd_type;
2284 --}
2285 ELSE
2286 --{
2287 l_jd_type := 'NL';
2288 --}
2289 END IF;
2290 return(l_jd_type);
2291
2292 EXCEPTION
2293 WHEN OTHERS THEN
2294 return ('NL');
2295 --}
2296 END get_jurisdiction_type;
2297
2298 --
2299 -- This function is used to fetch the status of Employee. It is used for determining
2300 -- whether executive weekly maximum should be applicable for a employee.
2301 --
2302 FUNCTION get_executive_status(p_assignment_id number,
2303 p_date_earned date,
2304 p_jurisdiction_code varchar2
2305 )
2306 RETURN varchar2
2307 IS
2308
2309 CURSOR get_executive_status
2310 IS
2311 select sta_information2
2312 from pay_us_emp_state_tax_rules_f
2313 where assignment_id = p_assignment_id
2314 and p_date_earned between effective_start_date and effective_end_date
2315 and jurisdiction_code = p_jurisdiction_code;
2316
2317 l_executive_status varchar2(1) := 'N';
2318 BEGIN
2319
2320 OPEN get_executive_status;
2321 FETCH get_executive_status INTO l_executive_status;
2322 CLOSE get_executive_status;
2323 return(nvl(l_executive_status,'N'));
2324 EXCEPTION
2325 WHEN OTHERS THEN
2326 return ('N');
2327
2328 END get_executive_status;
2329
2330 -- Bug#2122611
2331 -- This function used for determining whether Workers compensation
2332 -- amount should be deducted in the current pay period or not.
2333 --
2334
2335 FUNCTION get_wc_flag(p_assignment_id number,
2336 p_date_earned date,
2337 p_wc_flat_rate_period varchar2
2338 )
2339 RETURN varchar2
2340 IS
2341
2342 l_last_period_for_wc varchar2(1) := 'N';
2343 l_pay_period_start_date date;
2344 l_pay_period_end_date date;
2345 l_payroll_id number(9); /*7520832*/
2346 l_person_id number(10);
2347 l_date date;
2348
2349 /* Bug#8592027: Changes start */
2350 l_regular_payment_date date;
2351 --l_nearest_end_date date;
2352 l_nearest_check_date date;
2353 /* Bug#8592027: Changes end */
2354
2355 l_valid number(1);
2356
2357 -- Get start and end dates of the pay period for the given date_earned
2358 CURSOR csr_get_period_dates IS
2359 select ptp.start_date,
2360 ptp.end_date,
2361 ptp.regular_payment_date, /* Bug#8592027 */
2362 ptp.payroll_id, /*7520832*/
2363 paaf.person_id /* 765549 */
2364 from per_all_assignments_f paaf,
2365 pay_all_payrolls_f papf,
2366 per_time_periods ptp
2367 where paaf.payroll_id = papf.payroll_id
2368 and papf.payroll_id = ptp.payroll_id
2369 and assignment_id = p_assignment_id
2370 and p_date_earned between ptp.start_date
2371 and ptp.end_date
2372 and p_date_earned between papf.effective_start_date
2373 and papf.effective_end_date
2374 and p_date_earned between paaf.effective_start_date
2375 and paaf.effective_end_date;
2376
2377 /* Checks whether the employee is valid as of last date of the pay period.
2378 Bug#7655549: per_periods_of_service should be used to check employee's
2379 Validity. */
2380 CURSOR CSR_GET_VALID_EMPLOYMENT IS
2381 select 1
2382 from per_periods_of_service
2383 where person_id = l_person_id
2384 and l_date between date_start and nvl(actual_termination_date,to_date('12/31/4712','MM/DD/YYYY'));
2385
2386
2387 /*7520832: Cursor to fetch nearest pay period to the WC effective date*/
2388 CURSOR CSR_GET_NEAREST_PERIOD IS
2389 select max(nvl(regular_payment_date,end_date))
2390 from per_time_periods
2391 where payroll_id = l_payroll_id
2392 and nvl(regular_payment_date,end_date) <= l_date;
2393
2394 BEGIN
2395
2396 hr_utility.trace('In hr_us_ff_udf1.get_wc_flag() function');
2397 hr_utility.trace('**PARAMETERS**');
2398 hr_utility.trace('p_assignment_id: ' || to_char(p_assignment_id));
2399 hr_utility.trace('p_date_earned: ' || to_char(p_date_earned));
2400 hr_utility.trace('p_wc_flat_rate_period: ' || p_wc_flat_rate_period);
2401 OPEN csr_get_period_dates;
2402
2403 FETCH csr_get_period_dates INTO l_pay_period_start_date,l_pay_period_end_date,
2404 l_regular_payment_date,
2405 l_payroll_id,l_person_id; /*7520832*/
2406 IF csr_get_period_dates%NOTFOUND THEN
2407 hr_utility.trace('Pay period for the given date_earned is NOT found');
2408 CLOSE csr_get_period_dates;
2409 return (l_last_period_for_wc);
2410 END IF;
2411
2412 IF (p_wc_flat_rate_period = 'YEAR') THEN
2413 l_date := to_date( '31-12-' || to_char(l_pay_period_start_date,'yyyy'),'DD-MM-YYYY');
2414 -- last day of the year
2415
2416 ELSIF (p_wc_flat_rate_period = 'MONTH') THEN
2417 l_date := last_day(l_pay_period_start_date);
2418 -- last day of the month
2419
2420 ELSIF (p_wc_flat_rate_period = 'QUARTER') THEN
2421 l_date := add_months(trunc(l_pay_period_start_date,'YY'),3*to_number(to_char(l_pay_period_start_date,'Q')))-1;
2422 -- last day of the Quarter
2423 END IF;
2424 hr_utility.trace('Date to check the Validity: ' || to_char(l_date));
2425 /*7520832: Changes starts*/
2426
2427 /*
2428 if (l_date between l_pay_period_start_date and l_pay_period_end_date ) then
2429 l_last_period_for_wc := 'Y'; -- deduct WC in the current pay period.
2430 else
2431 l_last_period_for_wc := 'N';
2432 end if;
2433 */
2434 OPEN CSR_GET_NEAREST_PERIOD;
2435
2436 --FETCH CSR_GET_NEAREST_PERIOD INTO l_nearest_end_date;
2437 FETCH CSR_GET_NEAREST_PERIOD INTO l_nearest_check_date;
2438
2439 IF CSR_GET_NEAREST_PERIOD%NOTFOUND THEN
2440 hr_utility.trace('Nearest WC Pay period for the given date_earned is NOT found');
2441 CLOSE CSR_GET_NEAREST_PERIOD;
2442 CLOSE csr_get_period_dates;
2443 return (l_last_period_for_wc);
2444 END IF;
2445 /*IF current pay period is the nearest one to the WC effective date then
2446 deduct WC in the current payroll <=>l_last_period_for_wc := 'Y' */
2447 --if ( l_nearest_end_date = l_pay_period_end_date ) then
2448 if ( l_nearest_check_date = nvl(l_regular_payment_date,l_pay_period_end_date) ) then
2449 l_last_period_for_wc := 'Y';
2450 else
2451 l_last_period_for_wc := 'N';
2452 end if;
2453
2454 hr_utility.trace('Should deduct WC in this pay period? ' || l_last_period_for_wc);
2455 CLOSE CSR_GET_NEAREST_PERIOD;
2456 /*7520832: Changes ends*/
2457 CLOSE csr_get_period_dates;
2458
2459
2460 -- Check the assignment's validity as of last date of the pay period.
2461 OPEN CSR_GET_VALID_EMPLOYMENT;
2462 FETCH CSR_GET_VALID_EMPLOYMENT into l_valid;
2463
2464 IF CSR_GET_VALID_EMPLOYMENT%NOTFOUND THEN
2465 CLOSE CSR_GET_VALID_EMPLOYMENT;
2466 hr_utility.trace('Assignment is not valid for WC deduction');
2467 return ('N');
2468 END IF;
2469 CLOSE CSR_GET_VALID_EMPLOYMENT;
2470 return(l_last_period_for_wc);
2471 EXCEPTION
2472 WHEN OTHERS THEN
2473 return ('N');
2474
2475 END get_wc_flag;
2476
2477 --
2478 -- FUNCTION get_it_work_jurisdictions
2479 --
2480 /* This Function used to manage pl/table for work/tagged/home jurisdictions
2481 associated with an assignment
2482
2483 Parameter Purpose
2484 --------- -------
2485 p_INITIALIZE This parmaeter determines to process the pl/table
2486 jurisdiction_codes_tbl. This parameter expects one of 3
2487 values. (Y, N, F)
2488 Y denotes Initialize and populate the pl table
2489 N denotes Fetch jurisction that is stored next to the
2490 jurisdiction assigned to p_jurisdiction_code
2491 F denotes Fecth the First jurisdiction stored in the pl
2492 table
2493
2494 This function is being called from US_TAX_VERTEX2 formula with P_INITIALIZE
2495 value as 'Y'. PL table is always initialized for each assignment.
2496
2497 This function is called from US_TAX_VERTEX_HOME2 formula with P_INITIALIZE
2498 value as 'F'.
2499
2500 This function is repeatedly called from US_TAX_VERTEX_WORK2 depending on the
2501 number of work jurisdiction stored in the pl table.For this call P_INITIALIZE
2502 value is set as 'N'.
2503 */
2504 FUNCTION get_it_work_jurisdictions(p_assignment_action_id IN NUMBER
2505 ,p_initialize IN VARCHAR2
2506 ,p_jurisdiction_code IN OUT NOCOPY VARCHAR2
2507 ,p_percentage OUT NOCOPY NUMBER
2508 ,p_assignment_id IN NUMBER
2509 ,p_date_paid IN DATE
2510 ,p_date_earned IN DATE
2511 ,p_time_period_id IN NUMBER
2512 ,p_payroll_id IN NUMBER
2513 ,p_business_group_id IN NUMBER
2514 ,p_tax_unit_id IN NUMBER
2515 )
2516 RETURN VARCHAR2
2517 IS
2518
2519 TOO_MANY_JURISDICTIONS EXCEPTION;
2520 l_max_jurisdictions NUMBER;
2521 l_assignment_id NUMBER;
2522 l_date_paid DATE;
2523 l_date_earned DATE;
2524
2525 l_ee_id NUMBER;
2526 l_jurisdiction_code VARCHAR2(11);
2527 l_res_jurisdiction_code VARCHAR2(11);
2528 l_work_jurisdiction_code VARCHAR2(11);
2529 l_wk_jurisdiction_code VARCHAR2(11);
2530 l_jd_type VARCHAR2(2);
2531
2532 l_percentage NUMBER;
2533 p_array_count NUMBER;
2534 l_index_value NUMBER;
2535
2536 l_jd_found VARCHAR2(1);
2537 l_return_value VARCHAR2(28);
2538
2539 l_state VARCHAR2(2);
2540 l_county VARCHAR2(120);
2541 l_city VARCHAR2(30);
2542 l_zip_code VARCHAR2(10);
2543
2544 l_res_state VARCHAR2(2);
2545 l_res_county VARCHAR2(120);
2546 l_res_city VARCHAR2(100);
2547 l_res_zip VARCHAR2(10);
2548 l_wah VARCHAR2(1);
2549
2550 cnt NUMBER;
2551
2552 -- Get Further Payroll Information , Use Informational Hours From flag.
2553 -- Current_pay_period (C) or Previous_pay_period(P)
2554 CURSOR csr_period_flag (p_assignment_action_id IN NUMBER) IS
2555 SELECT NVL(prl_information12 ,'P') --Defaulted to Previous
2556 ,NVL(prl_information13 ,'YTD') --defaulted to Tax Year
2557 FROM pay_payrolls_f payroll,
2558 pay_assignment_actions paa,
2559 pay_payroll_actions ppa
2560 WHERE ppa.payroll_id = payroll.payroll_id
2561 AND paa.payroll_action_id = ppa.payroll_action_id
2562 AND paa.assignment_action_id = p_assignment_action_id
2563 AND NVL(ppa.date_earned,ppa.effective_date)
2564 BETWEEN payroll.effective_start_date
2565 AND payroll.effective_end_date;
2566
2567 l_pay_period_flag pay_payrolls_f.prl_information11%TYPE;
2568 l_threshold_basis pay_payrolls_f.prl_information13%TYPE;
2569
2570 -- Cursor to get all the informational time element entries
2571 -- Jurisdiction Code and Hours screen entry values are retrieved
2572 -- All element entries are considered based on the start date and end date.
2573 -- Hours are summed for each jurisdiction.
2574 --
2575 CURSOR csr_it_element_entries(p_start_date IN DATE,
2576 p_end_date IN DATE,
2577 p_assignment_id IN NUMBER,
2578 p_date_earned IN DATE) IS
2579 SELECT pev1.screen_entry_value Jurisdiction,
2580 SUM(pev2.screen_entry_value) Hours
2581 FROM pay_element_entry_values_f pev1,
2582 pay_element_entry_values_f pev2,
2583 pay_element_entries_f pee,
2584 pay_element_links_f pel,
2585 pay_element_types_f pet,
2586 pay_input_values_f piv1,
2587 pay_input_values_f piv2,
2588 pay_element_type_extra_info extra
2589 WHERE extra.information_type = 'PAY_US_INFORMATION_TIME'
2590 AND extra.eei_information1 = 'Y'
2591 AND extra.element_type_id = pet.element_type_id
2592 AND pet.element_type_id = pel.element_type_id
2593 AND p_end_date BETWEEN pet.effective_start_date
2594 AND pet.effective_end_date
2595 AND pel.element_link_id = pee.element_link_id
2596 AND p_end_date BETWEEN pel.effective_start_date
2597 AND pel.effective_end_date
2598 AND pee.assignment_id = p_assignment_id
2599 AND ( (pee.effective_start_date BETWEEN p_start_date
2600 AND p_end_date)
2601 OR
2602 (pee.effective_end_date BETWEEN p_start_date
2603 AND p_end_date)
2604 )
2605 AND pee.element_entry_id = pev1.element_entry_id
2606 AND p_end_date BETWEEN pee.effective_start_date
2607 AND pee.effective_end_date
2608 AND pev1.input_value_id = piv1.input_value_id
2609 AND p_end_date BETWEEN pev1.effective_start_date
2610 AND pev1.effective_end_date
2611 AND piv1.name = 'Jurisdiction'
2612 AND p_end_date BETWEEN piv1.effective_start_date
2613 AND piv1.effective_end_date
2614 AND pee.element_entry_id = pev2.element_entry_id
2615 AND p_end_date BETWEEN pee.effective_start_date
2616 AND pee.effective_end_date
2617 AND pev2.input_value_id = piv2.input_value_id
2618 AND piv2.name = 'Hours'
2619 AND p_end_date BETWEEN piv2.effective_start_date
2620 AND piv2.effective_end_date
2621 AND pev1.screen_entry_value IS NOT NULL
2622 AND pev2.screen_entry_value IS NOT NULL
2623 GROUP BY pev1.screen_entry_value;
2624
2625 l_sum_hours NUMBER;
2626 l_scheduled_work_hours NUMBER;
2627 l_total_hours NUMBER;
2628 l_work_hours NUMBER;
2629 l_remaining_hours NUMBER;
2630 l_jd_hours NUMBER;
2631 l_end_date DATE;
2632 l_start_date DATE;
2633 l_time_period_id pay_payroll_actions.time_period_id%TYPE;
2634 l_counter INTEGER;
2635 l_tg_jurisdiction_code VARCHAR2(20);
2636 l_tg_sum_hours NUMBER;
2637 l_tg_total_hours NUMBER;
2638 l_tg_hours_fetched NUMBER;
2639 l_tg_jd_code_fetched VARCHAR2(20);
2640 l_it_hours_fetched NUMBER;
2641 l_hours_fetched NUMBER;
2642 l_tg_hours NUMBER;
2643 l_ws_name VARCHAR2(200);
2644 l_total_percent NUMBER;
2645 l_primary_work_jd_flag VARCHAR2(1);
2646 l_primary_work_jd_index_value NUMBER;
2647 l_extra_percent NUMBER;
2648 l_last_jd_index_value NUMBER;
2649 l_denominator NUMBER;
2650
2651 -- Get start_date, end_date for the given time_period_id and payroll_id
2652 --
2653 CURSOR csr_time_period(p_time_period_id IN NUMBER,
2654 p_payroll_id IN NUMBER) IS
2655 SELECT end_date,
2656 start_date
2657 FROM per_time_periods
2658 WHERE time_period_id = p_time_period_id
2659 AND payroll_id = p_payroll_id;
2660
2661
2662 -- Get start_date, end_date for the given time_period_id and payroll_id
2663 --
2664 CURSOR csr_time_period_prev(p_prev_end_date IN DATE,
2665 p_payroll_id IN NUMBER) IS
2666 SELECT end_date,
2667 start_date
2668 FROM per_time_periods
2669 WHERE end_date = p_prev_end_date
2670 AND payroll_id = p_payroll_id;
2671
2672 -- Get Work Jurisdiction for the assignment
2673 --
2674 CURSOR csr_work_jd (p_date_earned IN DATE, p_assignment_id IN NUMBER) IS
2675 SELECT NVL(hrloc.loc_information18,hrloc.town_or_city),
2676 NVL(hrloc.loc_information19,hrloc.region_1),
2677 NVL(hrloc.loc_information17,hrloc.region_2),
2678 SUBSTR(NVL(hrloc.loc_information20,hrloc.postal_code),1,5)
2679 FROM hr_locations hrloc
2680 ,hr_soft_coding_keyflex hrsckf
2681 ,per_all_assignments_f assign
2682 WHERE p_date_earned BETWEEN assign.effective_start_date
2683 AND assign.effective_end_date
2684 AND assign.assignment_id = p_assignment_id
2685 AND assign.soft_coding_keyflex_id = hrsckf.soft_coding_keyflex_id
2686 AND NVL(hrsckf.segment18,
2687 assign.location_id) = hrloc.location_id;
2688 /*
2689 --Get the Positive Pay entries(same as Tagged Entries)
2690 --
2691 CURSOR csr_tagged_entries(p_start_date IN DATE,
2692 p_end_date IN DATE,
2693 p_assignment_id IN NUMBER,
2694 p_date_earned IN DATE) IS
2695 SELECT pev1.screen_entry_value Jurisdiction,
2696 SUM(pev2.screen_entry_value) Hours
2697 FROM pay_element_entry_values_f pev1,
2698 pay_element_entry_values_f pev2,
2699 pay_element_entries_f pee,
2700 pay_element_links_f pel,
2701 pay_element_types_f pet,
2702 pay_input_values_f piv1,
2703 pay_input_values_f piv2,
2704 pay_element_classifications pec
2705 WHERE pec.classification_name IN ( 'Earnings', 'Supplemental Earnings','Imputed Earnings' )
2706 AND pec.legislation_code = 'US'
2707 AND pec.classification_id = pet.classification_id
2708 AND pet.element_type_id = pel.element_type_id
2709 AND p_date_earned BETWEEN pet.effective_start_date
2710 AND pet.effective_end_date
2711 AND pel.element_link_id = pee.element_link_id
2712 AND p_date_earned BETWEEN pel.effective_start_date
2713 AND pel.effective_end_date
2714 AND pee.assignment_id = p_assignment_id
2715 AND pee.effective_start_date BETWEEN p_start_date
2716 AND p_end_date
2717 AND pee.element_entry_id = pev1.element_entry_id
2718 AND p_date_earned BETWEEN pee.effective_start_date
2719 AND pee.effective_end_date
2720 AND pev1.input_value_id = piv1.input_value_id
2721 AND p_date_earned BETWEEN pev1.effective_start_date
2722 AND pev1.effective_end_date
2723 AND piv1.name = 'Jurisdiction'
2724 AND p_date_earned BETWEEN piv1.effective_start_date
2725 AND piv1.effective_end_date
2726 AND pee.element_entry_id = pev2.element_entry_id
2727 AND p_date_earned BETWEEN pee.effective_start_date
2728 AND pee.effective_end_date
2729 AND pev2.input_value_id = piv2.input_value_id
2730 AND piv2.name = 'Hours'
2731 AND p_date_earned BETWEEN piv2.effective_start_date
2732 AND piv2.effective_end_date
2733 AND pev1.screen_entry_value IS NOT NULL
2734 AND pev2.screen_entry_value IS NOT NULL
2735 GROUP BY pev1.screen_entry_value;
2736 */
2737
2738 CURSOR csr_tagged_entries(p_start_date IN DATE,
2739 p_end_date IN DATE,
2740 p_assignment_id IN NUMBER,
2741 p_date_earned IN DATE)
2742 IS
2743 SELECT /*+ INDEX (paa pay_assignment_actions_n51) */ DISTINCT
2744 peev.screen_entry_value Jurisdiction,
2745 0 Hours
2746 FROM pay_element_classifications pec
2747 ,pay_element_types_f pet
2748 ,pay_element_entries_f pee
2749 ,pay_element_links_f pel
2750 ,pay_input_values_f piv
2751 ,pay_element_entry_values_f peev
2752 WHERE pec.classification_name in
2753 ( 'Earnings', 'Supplemental Earnings','Imputed Earnings' )
2754 AND pec.legislation_code = 'US'
2755 AND pet.classification_id = pec.classification_id
2756 AND (( pee.effective_start_date BETWEEN p_start_date
2757 AND p_end_date)
2758 OR
2759 ( pee.effective_end_date BETWEEN p_start_date
2760 AND p_end_date)
2761 )
2762 AND p_end_date BETWEEN pet.effective_start_date
2763 AND pet.effective_end_date
2764 AND pee.assignment_id = p_assignment_id
2765 AND pet.element_type_id = pel.element_type_id
2766 AND pel.element_link_id = pee.element_link_id
2767 AND p_end_date BETWEEN pel.effective_start_date
2768 AND pel.effective_end_date
2769 AND pet.element_type_id = piv.element_type_id
2770 AND piv.name = 'Jurisdiction'
2771 AND pee.effective_start_date BETWEEN piv.effective_start_date
2772 AND piv.effective_end_date
2773 AND pee.element_entry_id = peev.element_entry_id
2774 AND peev.input_value_id = piv.input_value_id
2775 AND pee.effective_start_date BETWEEN peev.effective_start_date
2776 AND peev.effective_end_date
2777 AND peev.screen_entry_value IS NOT NULL;
2778
2779
2780 -- Get work schedule details
2781 --
2782 CURSOR csr_ws(p_assignment_id IN NUMBER,p_date_earned IN DATE) IS
2783 SELECT segment4
2784 FROM hr_soft_coding_keyflex target,
2785 per_all_assignments_f assign
2786 WHERE ASSIGN.assignment_id = p_assignment_id
2787 AND target.soft_coding_keyflex_id = ASSIGN.soft_coding_keyflex_id
2788 AND target.enabled_flag = 'Y'
2789 AND p_date_earned BETWEEN assign.effective_start_date
2790 AND assign.effective_end_date;
2791
2792 CURSOR csr_resident_jd(p_assignment_id IN NUMBER,p_date_earned IN DATE) IS
2793 SELECT NVL(addr.add_information17,addr.region_2) state,
2794 NVL(addr.add_information19,addr.region_1) county,
2795 NVL(addr.add_information18,addr.town_or_city) city,
2796 NVL(addr.add_information20,addr.postal_code) zip,
2797 NVL(assign.work_at_home,'N')
2798 FROM per_addresses addr
2799 ,per_all_assignments_f assign
2800 WHERE p_date_earned BETWEEN assign.effective_start_date
2801 AND assign.effective_end_date
2802 AND assign.assignment_id = p_assignment_id
2803 AND addr.person_id = assign.person_id
2804 AND addr.primary_flag = 'Y'
2805 AND p_date_earned BETWEEN NVL(addr.date_from, p_date_earned)
2806 AND NVL(addr.date_to, p_date_earned);
2807
2808 -- Get Full Name, Assignment Number
2809 CURSOR csr_person_details(p_assignment_id IN NUMBER,p_date_paid IN DATE) IS
2810 SELECT ppf.full_name, paf.assignment_number
2811 FROM per_all_people_f ppf,
2812 per_all_assignments_f paf
2813 WHERE ppf.person_id = paf.person_id
2814 AND paf.assignment_id = p_assignment_id
2815 AND p_date_paid BETWEEN paf.effective_start_date
2816 AND paf.effective_end_date
2817 AND p_date_paid BETWEEN ppf.effective_start_date
2818 AND ppf.effective_end_date;
2819
2820 l_full_name per_all_people_f.full_name%TYPE;
2821 l_assignment_number per_all_assignments_f.assignment_number%TYPE;
2822
2823 -- Get actual_termination_date for the person
2824 CURSOR csr_eff_dates(p_assignment_id IN NUMBER, p_date_paid IN DATE ) IS
2825 SELECT paa.effective_start_date,
2826 paa.effective_end_date
2827 FROM per_all_assignments_f paa
2828 WHERE paa.assignment_id = p_assignment_id
2829 AND p_date_paid BETWEEN paa.effective_start_date
2830 AND paa.effective_end_date;
2831
2832 l_effective_start_date DATE;
2833 l_max_start_date DATE;
2834 l_effective_end_date DATE;
2835 l_max_end_date DATE;
2836 l_actual_termination_date per_periods_of_service.actual_termination_date%TYPE;
2837
2838 -- Get actual_termination_date for the person
2839 CURSOR csr_term_dates(p_assignment_id IN NUMBER, p_date_earned IN DATE,p_date_start IN DATE,p_date_end IN DATE ) IS
2840 SELECT pps.actual_termination_date,pps.date_start
2841 FROM per_periods_of_service pps,
2842 per_all_assignments_f paa
2843 WHERE paa.assignment_id = p_assignment_id
2844 AND paa.person_id = pps.person_id
2845 AND p_date_earned BETWEEN paa.effective_start_date
2846 AND paa.effective_end_date
2847 AND p_date_end >= pps.date_start
2848 AND p_date_start <= NVL(pps.actual_termination_date,to_date('31-12-4712','DD-MM-YYYY'));
2849
2850
2851 -- Get
2852 CURSOR csr_person_id (p_assignment_id IN NUMBER) IS
2853 SELECT person_id
2854 FROM per_all_assignments_f
2855 WHERE assignment_id = p_assignment_id;
2856
2857 l_person_id per_all_assignments_f.person_id%TYPE;
2858
2859 l_jurisdiction VARCHAR2(20);
2860 l_calc_percent VARCHAR2(10);
2861 l_threshold_hours_state NUMBER;
2862 l_threshold_hours_county NUMBER;
2863 l_threshold_hours_city NUMBER;
2864 l_sit_withheld NUMBER;
2865 l_county_withheld NUMBER;
2866 l_city_withheld NUMBER;
2867 l_ih_excluding_pay_period NUMBER;
2868 l_ih_above_threshold NUMBER;
2869 l_ih_for_primary_wk NUMBER;
2870 l_state_ih_logged NUMBER;
2871 l_county_ih_logged NUMBER;
2872 l_city_ih_logged NUMBER;
2873 l_total_state_hours NUMBER;
2874 l_total_county_hours NUMBER;
2875 l_total_state_percent NUMBER;
2876 l_total_county_percent NUMBER;
2877 l_in_counter INTEGER;
2878 l_prev_end_date DATE;
2879 /*Bug#5981447: Variables to hold start and end dates
2880 to calculate work schduled hours */
2881 l_ws_start_date DATE;
2882 l_ws_end_date DATE;
2883 /*Bug#5981447: Ends here */
2884 l_sit_city_withheld NUMBER;
2885 l_county_city_withheld NUMBER;
2886 l_sit_county_withheld NUMBER;
2887
2888 l_spelled_jd_code VARCHAR2(200);
2889
2890 BEGIN
2891 --{
2892 l_max_jurisdictions := 200;
2893 l_total_hours := 0;
2894 l_work_hours := 0;
2895 l_remaining_hours := 0;
2896 l_jd_hours := 0;
2897 l_counter := NULL;
2898 l_tg_total_hours := 0;
2899 l_total_percent := 0;
2900 l_primary_work_jd_flag := 'N';
2901 l_extra_percent := 0;
2902 l_denominator := 0;
2903
2904 l_total_state_hours := 0;
2905 l_total_county_hours := 0;
2906 l_total_state_percent := 0;
2907 l_total_county_percent := 0;
2908
2909 l_sit_city_withheld := 0;
2910 l_county_city_withheld := 0;
2911 l_sit_county_withheld := 0;
2912
2913 hr_utility.trace('EMJT : Begin get_it_work_jurisdictions');
2914 hr_utility.trace('EMJT : p_assignment_action_id -> '
2915 ||to_char(p_assignment_action_id));
2916 hr_utility.trace('EMJT : p_assignment_id -> '||
2917 to_char(p_assignment_id));
2918 hr_utility.trace('EMJT : p_date_earned -> '||to_char(p_date_earned));
2919 hr_utility.trace('EMJT : p_date_paid -> '||to_char(p_date_paid));
2920 hr_utility.trace('EMJT : p_time_period_id -> '||
2921 to_char(p_time_period_id));
2922 hr_utility.trace('EMJT : p_payroll_id -> '||to_char(p_payroll_id));
2923 hr_utility.trace('EMJT : =====================================================');
2924
2925
2926 OPEN csr_person_id (p_assignment_id);
2927 FETCH csr_person_id INTO l_person_id;
2928 IF csr_person_id%NOTFOUND THEN
2929 hr_utility.trace('EMJT: Person Id not found');
2930 END IF;
2931
2932 CLOSE csr_person_id;
2933
2934 --
2935 -- Determine the pay period, whether it is current or previous
2936 -- This is used to fetch element entries for the user configured period
2937 --
2938 OPEN csr_period_flag(p_assignment_action_id);
2939 FETCH csr_period_flag INTO l_pay_period_flag,
2940 l_threshold_basis;
2941 CLOSE csr_period_flag;
2942 hr_utility.trace('EMJT : l_pay_period_flag -> '|| l_pay_period_flag );
2943 hr_utility.trace('EMJT : l_threshold_basis -> '|| l_threshold_basis );
2944 /* IF l_pay_period_flag = 'C' THEN --Current Pay Period
2945 OPEN csr_time_period(p_time_period_id, p_payroll_id);
2946 ELSIF l_pay_period_flag = 'P' THEN --Previous Pay Period
2947 -- l_time_period_id := p_time_period_id - 1;
2948 -- IF l_time_period_id <= 0 THEN
2949 -- l_time_period_id := p_time_period_id;
2950 -- END IF;
2951 OPEN csr_time_period(l_time_period_id,p_payroll_id);
2952 END IF; --l_pay_period_flag = 'C'
2953 */
2954 OPEN csr_time_period(p_time_period_id, p_payroll_id);
2955 FETCH csr_time_period INTO l_end_date,
2956 l_start_date;
2957 CLOSE csr_time_period;
2958 /* Assign current pay period's start and end dates */
2959 l_ws_start_date := l_start_date;
2960 l_ws_end_date := l_end_date;
2961
2962 OPEN csr_term_dates (p_assignment_id, p_date_earned,l_start_date,l_end_date);
2963 FETCH csr_term_dates INTO l_effective_end_date,l_effective_start_date;
2964 CLOSE csr_term_dates;
2965
2966 l_effective_end_date := NVL( l_effective_end_date,to_date('12/31/4712','mm/dd/yyyy'));
2967
2968 hr_utility.trace('EMJT : l_effective_start_date -> '|| l_effective_start_date);
2969 hr_utility.trace('EMJT : l_effective_end_date -> '|| l_effective_end_date);
2970
2971 IF l_pay_period_flag = 'P' THEN
2972
2973 l_prev_end_date := l_start_date - 1;
2974
2975 OPEN csr_time_period_prev(l_prev_end_date, p_payroll_id);
2976 FETCH csr_time_period_prev INTO l_end_date, l_start_date;
2977
2978 /*There is no previous pay period available.
2979 Assign null to l_start_Date and l_end_date */
2980
2981 IF csr_time_period_prev%NOTFOUND THEN
2982 l_start_date :=null;
2983 l_end_date :=null;
2984 ELSIF l_effective_start_date >=l_end_date or l_effective_end_date <= l_start_date THEN
2985 /* no previous pay period exists for the assignment */
2986 l_start_date :=null;
2987 l_end_date :=null;
2988 ELSE
2989 l_ws_start_date := l_start_date;
2990 l_ws_end_date := l_end_date;
2991 END IF;
2992
2993 CLOSE csr_time_period_prev;
2994
2995 END IF;
2996
2997 hr_utility.trace('EMJT : After csr_time_period -> ');
2998 hr_utility.trace('EMJT : l_end_date -> '||to_char(l_end_date));
2999 hr_utility.trace('EMJT : l_start_date -> '||to_char(l_start_date));
3000 hr_utility.trace('EMJT : l_ws_end_date -> '||to_char(l_ws_end_date));
3001 hr_utility.trace('EMJT : l_ws_start_date -> '||to_char(l_ws_start_date));
3002
3003 -- Need to fetch scheduled hours configured for the assignment for the
3004 -- current pay period.
3005 OPEN csr_ws(p_assignment_id,
3006 p_date_earned);
3007 FETCH csr_ws INTO l_ws_name;
3008 IF csr_ws%NOTFOUND THEN
3009 hr_utility.trace('EMJT : get_id_work_jurisdiction Work Scheduled Not Found ');
3010 END IF;
3011 CLOSE csr_ws;
3012
3013 /* Start and end dates for the work scheduled hours calculation */
3014 /*Bug#7114362: l_ws_start_date should not be NULL even when l_effective_start_date is
3015 NULL*/
3016 l_ws_start_date := greatest ( NVL(l_effective_start_date,to_date('01-01-0001','DD-MM-YYYY')), l_ws_start_date);
3017 l_ws_end_date := least ( l_effective_end_date, l_ws_end_date);
3018
3019 /* Start and end dates for fetching information and tagged hours */
3020 IF l_start_date is null and l_end_date is null THEN
3021 /* There is no Previous pay period available.
3022 No need to process information and tagged hours */
3023 l_max_start_date := null;
3024 l_max_end_Date := null;
3025 ELSE
3026 l_max_start_date := l_ws_start_date;
3027 l_max_end_Date := l_ws_end_date;
3028 END IF;
3029
3030 hr_utility.trace('EMJT : l_max_start_date -> '|| l_max_start_date);
3031 hr_utility.trace('EMJT : l_max_end_date -> '|| l_max_end_date);
3032 hr_utility.trace('EMJT : l_ws_end_date -> '||to_char(l_ws_end_date));
3033 hr_utility.trace('EMJT : l_ws_start_date -> '||to_char(l_ws_start_date));
3034
3035 /* need to use l_ws_start_date and l_ws_end_date for work scheduled hours calculation */
3036
3037 l_scheduled_work_hours :=
3038 hr_us_ff_udfs.work_schedule_total_hours(p_business_group_id,
3039 l_ws_name,
3040 l_ws_start_date,
3041 l_ws_end_date);
3042
3043 IF l_ws_start_date = l_ws_end_date AND
3044 NVL(l_scheduled_work_hours,0) <= 0 THEN
3045
3046 l_scheduled_work_hours :=
3047 hr_us_ff_udfs.work_schedule_total_hours(p_business_group_id,
3048 l_ws_name,
3049 l_ws_start_date,
3050 l_ws_end_date);
3051 IF l_scheduled_work_hours = 0 THEN
3052 hr_utility.trace('EMJT : Scheduled hours set to 8');
3053 l_scheduled_work_hours := 8; -- Defaulted to 8 hours
3054 END IF;
3055 END IF;
3056
3057
3058 hr_utility.trace('EMJT : Scheduled Hours for the assignment -> '||
3059 to_char(l_scheduled_work_hours));
3060 IF p_initialize = 'Y' THEN
3061 --{
3062 -- pl/sql table initialized for all twork location where Information Time
3063 -- and Positive Pay hours are logged. This call initiated from the
3064 -- US_TAX_VERTEX2 fast formula
3065
3066 hr_utility.trace('EMJT : get_it_work_jurisdictions || p_initialize = Y');
3067 jurisdiction_codes_tbl.delete;
3068 state_processed_tbl.delete;
3069 county_processed_tbl.delete;
3070 city_processed_tbl.delete;
3071
3072 jurisdiction_codes_tbl_stg.delete;
3073
3074 -- GET the RESIDENT jurisdictions and load in to the *_processed_tables
3075 --
3076 hr_utility.trace('EMJT : get_work_jurisdictions Get Resident Address details');
3077
3078 OPEN csr_resident_jd(p_assignment_id,p_date_earned);
3079 FETCH csr_resident_jd INTO l_res_state,
3080 l_res_county,
3081 l_res_city,
3082 l_res_zip,
3083 l_wah;
3084
3085 CLOSE csr_resident_jd;
3086
3087 hr_utility.trace('EMJT : get_it_work_jurisdictions Resident Address Fetched');
3088 l_res_jurisdiction_code := hr_us_ff_udfs.addr_val(l_res_state
3089 , l_res_county
3090 , l_res_city
3091 , l_res_zip);
3092
3093 -- IF this is a user defined city IE: city_code = 'U***' the change
3094 -- the city code to all 0 (zeros)
3095
3096 IF SUBSTR(l_res_jurisdiction_code,8,1) = 'U' THEN
3097 l_res_jurisdiction_code := SUBSTR(l_res_jurisdiction_code,1,7) ||
3098 '0000' ;
3099 END IF;
3100 hr_utility.trace('EMJT : Resident Jurisdiction Code -> ' ||
3101 l_res_jurisdiction_code);
3102 hr_utility.trace('EMJT : Home Workers Flag -> ' || l_wah);
3103
3104 --
3105 -- Determine the address components of primary work jurisdiction.
3106 --
3107 hr_utility.trace('EMJT : get_it_work_jurisdictions Fetch Primary Work Location');
3108 OPEN csr_work_jd(p_date_earned,
3109 p_assignment_id);
3110 FETCH csr_work_jd INTO l_city,
3111 l_county,
3112 l_state,
3113 l_zip_code;
3114
3115 IF csr_work_jd%NOTFOUND THEN
3116 hr_utility.trace('EMJT : Primary Work Location address componets NOT Found');
3117 END IF;
3118 CLOSE csr_work_jd;
3119 hr_utility.trace('EMJT : Determine Jurisdiction Code for Primary Work Location');
3120 l_work_jurisdiction_code := hr_us_ff_udfs.addr_val(l_state,
3121 l_county,
3122 l_city,
3123 l_zip_code);
3124
3125 hr_utility.trace('EMJT : Primary work Jursdiction CODE -> '
3126 || l_work_jurisdiction_code);
3127
3128 -- Check to see whether employee is configured as "Home Worker"
3129 -- If employee is a Home worker use resident jurisdiction as primary
3130 -- work jurisdiction code instead of actual primary work jurisdiction
3131 -- available for the assignment
3132
3133 IF l_wah = 'Y' THEN
3134 l_work_jurisdiction_code := l_res_jurisdiction_code;
3135 hr_utility.trace('EMJT : As assignment is configured as Home Worker ');
3136 hr_utility.trace('EMJT : Residence Jurisdiction overrides the Primary Work Jurisdiction');
3137 hr_utility.trace('EMJT : Primary work Jursdiction CODE -> '
3138 || l_work_jurisdiction_code);
3139 END IF;
3140
3141 -- Fetch all the informational time element entries logged for the
3142 -- Pay period being processed
3143 hr_utility.trace('EMJT : Fetching all Information Hours Element Entris for Assignment');
3144 hr_utility.trace('EMJT : For Assignment '||to_char(p_assignment_id));
3145 hr_utility.trace('EMJT : Start Date '||to_char(l_start_date,'dd-mon-yyyy'));
3146 hr_utility.trace('EMJT : End Date '||to_char(l_end_date,'dd-mon-yyyy'));
3147 BEGIN
3148 /* OPEN csr_it_element_entries(l_start_date,
3149 l_end_date,
3150 p_assignment_id,
3151 p_date_earned);
3152 */
3153
3154 OPEN csr_it_element_entries(l_max_start_date, --l_start_date,
3155 l_max_end_date, --l_end_date,
3156 p_assignment_id,
3157 p_date_earned);
3158
3159 FETCH csr_it_element_entries INTO l_jurisdiction_code,
3160 l_sum_hours;
3161 hr_utility.trace('EMJT : 1st Information Time JD Code fetched-> '||l_jurisdiction_code);
3162 hr_utility.trace('EMJT : 1st Information Time Hours -> '||to_char(l_sum_hours));
3163 LOOP
3164 --{
3165 EXIT WHEN csr_it_element_entries%NOTFOUND;
3166
3167 jurisdiction_codes_tbl_stg( TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2) ||
3168 SUBSTR(l_jurisdiction_code,4,3) ||
3169 SUBSTR(l_jurisdiction_code,8,4) )
3170 ).jurisdiction_code := l_jurisdiction_code;
3171
3172 jurisdiction_codes_tbl_stg( TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2) ||
3173 SUBSTR(l_jurisdiction_code,4,3) ||
3174 SUBSTR(l_jurisdiction_code,8,4) )
3175 ).hours := l_sum_hours;
3176
3177 jurisdiction_codes_tbl_stg( TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2) ||
3178 SUBSTR(l_jurisdiction_code,4,3) ||
3179 SUBSTR(l_jurisdiction_code,8,4) )
3180 ).jd_type := 'IT'; --Informational Time
3181
3182 jurisdiction_codes_tbl_stg( TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2) ||
3183 SUBSTR(l_jurisdiction_code,4,3) ||
3184 SUBSTR(l_jurisdiction_code,8,4) )
3185 ).tg_hours := 0; --Initialize Tagged Hours
3186
3187 hr_utility.trace('EMJT : ===============================================');
3188 hr_utility.trace('EMJT : Information Hours entry tagged to JD Code -> ' ||l_jurisdiction_code);
3189 hr_utility.trace('EMJT : Information Hours logged -> ' ||to_char(l_sum_hours));
3190 hr_utility.trace('EMJT : ===============================================');
3191 -- Add information time logged to local variable to compute the
3192 -- the total information time hours logged for the assignment
3193 l_total_hours := l_total_hours + l_sum_hours;
3194 --
3195 -- If hours entered for jurisdiction is primary work jurisdiction
3196 -- set the flag to Yes
3197 IF l_work_jurisdiction_code = l_jurisdiction_code THEN
3198 l_primary_work_jd_flag := 'Y';
3199 l_primary_work_jd_index_value :=
3200 TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2) ||
3201 SUBSTR(l_jurisdiction_code,4,3) ||
3202 SUBSTR(l_jurisdiction_code,8,4));
3203 END IF;
3204 -- Fetch the next jurisdiction and hours from cursor csr_it_element_entries
3205 --
3206 FETCH csr_it_element_entries INTO l_jurisdiction_code,
3207 l_sum_hours;
3208 --}
3209 END LOOP;
3210 CLOSE csr_it_element_entries;
3211 EXCEPTION
3212 WHEN OTHERS THEN
3213 hr_utility.trace('EMJT : ERROR Encountered while processing Information Hours EE');
3214 hr_utility.trace(substr(sqlerrm,1,45));
3215 hr_utility.trace(substr(sqlerrm,46,45));
3216 END;
3217 hr_utility.trace('EMJT : Information Hours Element Entries fetched and loaded ');
3218 hr_utility.trace('EMJT : Total no. of Jurisdiction loaded in to pl/sql table ->'||
3219 to_char(jurisdiction_codes_tbl_stg.COUNT));
3220 hr_utility.trace('EMJT : Total Information Hours logged -> ' ||to_char(l_total_hours));
3221
3222 -- Determine whether total hours match against scheduled hours.
3223 -- In case total hours fall less than scheduled hours, add the
3224 -- remaining hours to primary work jurisdiction.
3225 --
3226 IF l_total_hours < l_scheduled_work_hours THEN
3227 --{
3228 l_remaining_hours := l_scheduled_work_hours - l_total_hours;
3229 hr_utility.trace('EMJT : Total Hours entered '||to_char(l_total_hours)||
3230 ' less than Scheduled Hours '||
3231 to_char(l_scheduled_work_hours));
3232 hr_utility.trace('EMJT : Entered Hours short of Sheduled Hours ' ||
3233 to_char(l_remaining_hours));
3234 -- Check whether work jurisdiction is available in pl table.
3235 -- If yes, add l_remaining_hours to the hours logged against work
3236 -- jurisdiction Else assign l_remaining_hours to the work jurisdiction.
3237 IF jurisdiction_codes_tbl_stg.EXISTS(
3238 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3239 SUBSTR(l_work_jurisdiction_code,4,3) ||
3240 SUBSTR(l_work_jurisdiction_code,8,4) )
3241 ) THEN
3242 --{
3243 l_work_hours := jurisdiction_codes_tbl_stg(
3244 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3245 SUBSTR(l_work_jurisdiction_code,4,3) ||
3246 SUBSTR(l_work_jurisdiction_code,8,4) )
3247 ).hours;
3248 jurisdiction_codes_tbl_stg(
3249 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3250 SUBSTR(l_work_jurisdiction_code,4,3) ||
3251 SUBSTR(l_work_jurisdiction_code,8,4) )
3252 ).hours := l_work_hours + l_remaining_hours;
3253 l_primary_work_jd_flag := 'Y';
3254 --
3255 l_primary_work_jd_index_value :=
3256 TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2) ||
3257 SUBSTR(l_jurisdiction_code,4,3) ||
3258 SUBSTR(l_jurisdiction_code,8,4));
3259
3260 hr_utility.trace('EMJT : l_work_hours ' || to_char(l_work_hours));
3261 --}
3262 ELSE
3263 --{
3264 -- No Informational Time logged against work location.
3265 -- Insert work jurisdiction into pl table with jd_type as WK
3266 jurisdiction_codes_tbl_stg(
3267 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3268 SUBSTR(l_work_jurisdiction_code,4,3) ||
3269 SUBSTR(l_work_jurisdiction_code,8,4) )
3270 ).jurisdiction_code := l_work_jurisdiction_code;
3271 /*Bug#6957929: Jurisdiction type must be 'RW' when work and resident
3272 jurisdictions are same.*/
3273 if l_res_jurisdiction_code = l_work_jurisdiction_code then
3274 jurisdiction_codes_tbl_stg(
3275 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3276 SUBSTR(l_work_jurisdiction_code,4,3) ||
3277 SUBSTR(l_work_jurisdiction_code,8,4) )
3278 ).jd_type := 'RW'; --Work Location
3279 else
3280 jurisdiction_codes_tbl_stg(
3281 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3282 SUBSTR(l_work_jurisdiction_code,4,3) ||
3283 SUBSTR(l_work_jurisdiction_code,8,4) )
3284 ).jd_type := 'WK'; --Work Location
3285 end if;
3286 /*
3287 jurisdiction_codes_tbl_stg(
3288 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3289 SUBSTR(l_work_jurisdiction_code,4,3) ||
3290 SUBSTR(l_work_jurisdiction_code,8,4) )
3291 ).jd_type := 'WK'; --Work Location
3292 */
3293 /*Bug#6957929: Changes end here*/
3294
3295 jurisdiction_codes_tbl_stg(
3296 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3297 SUBSTR(l_work_jurisdiction_code,4,3) ||
3298 SUBSTR(l_work_jurisdiction_code,8,4) )
3299 ).hours := l_remaining_hours;
3300
3301 jurisdiction_codes_tbl_stg(
3302 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3303 SUBSTR(l_work_jurisdiction_code,4,3) ||
3304 SUBSTR(l_work_jurisdiction_code,8,4) )
3305 ).tg_hours := 0; --Initialize Tagged Hours
3306 l_primary_work_jd_flag := 'Y';
3307 l_primary_work_jd_index_value :=
3308 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
3309 SUBSTR(l_work_jurisdiction_code,4,3) ||
3310 SUBSTR(l_work_jurisdiction_code,8,4));
3311 --}
3312 END IF; -- jurisdiction_codes_tbl_stg.EXISTS
3313
3314 hr_utility.trace('EMJT : Hours logged to primary Work Jurisdiction ->'||
3315 to_char(l_work_hours));
3316 hr_utility.trace('EMJT : Total no. of Jurisdiction loaded in to pl/sql table ->'||
3317 to_char(jurisdiction_codes_tbl_stg.COUNT));
3318 --}
3319 ELSE -- Check to see if there is an entry in the stg table for primary
3320 -- work jurisdiction if not add it.
3321 IF jurisdiction_codes_tbl_stg.EXISTS(
3322 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3323 ||
3324 SUBSTR(l_work_jurisdiction_code,4,3)
3325 ||
3326 SUBSTR(l_work_jurisdiction_code,8,4)
3327 )
3328 ) THEN
3329 NULL;
3330 ELSE
3331 jurisdiction_codes_tbl_stg(
3332 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3333 ||
3334 SUBSTR(l_work_jurisdiction_code,4,3)
3335 ||
3336 SUBSTR(l_work_jurisdiction_code,8,4)
3337 )
3338 ).jurisdiction_code :=
3339 l_work_jurisdiction_code;
3340 /*Bug#6957929: Jurisdiction type must be 'RW' when work and resident
3341 * jurisdictions are same.*/
3342 if l_res_jurisdiction_code = l_work_jurisdiction_code then
3343 jurisdiction_codes_tbl_stg(
3344 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3345 ||
3346 SUBSTR(l_work_jurisdiction_code,4,3)
3347 ||
3348 SUBSTR(l_work_jurisdiction_code,8,4)
3349 )
3350 ).jd_type := 'RW'; --Work Location
3351 else
3352 jurisdiction_codes_tbl_stg(
3353 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3354 ||
3355 SUBSTR(l_work_jurisdiction_code,4,3)
3356 ||
3357 SUBSTR(l_work_jurisdiction_code,8,4)
3358 )
3359 ).jd_type := 'WK'; --Work Location
3360 end if;
3361 /*
3362 * jurisdiction_codes_tbl_stg(
3363 * TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3364 * ||
3365 * SUBSTR(l_work_jurisdiction_code,4,3)
3366 * ||
3367 * SUBSTR(l_work_jurisdiction_code,8,4)
3368 * )
3369 * ).jd_type
3370 * :=
3371 * 'WK';
3372 * --Work
3373 * Location
3374 * */
3375 /*Bug#6957929: Changes end here*/
3376
3377 jurisdiction_codes_tbl_stg(
3378 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3379 ||
3380 SUBSTR(l_work_jurisdiction_code,4,3)
3381 ||
3382 SUBSTR(l_work_jurisdiction_code,8,4)
3383 )
3384 ).hours := 0;
3385
3386 jurisdiction_codes_tbl_stg(
3387 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3388 ||
3389 SUBSTR(l_work_jurisdiction_code,4,3)
3390 ||
3391 SUBSTR(l_work_jurisdiction_code,8,4)
3392 )
3393 ).tg_hours := 0; --Initialize Tagged Hours
3394 l_primary_work_jd_flag := 'Y';
3395 l_primary_work_jd_index_value :=
3396 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3397 ||
3398 SUBSTR(l_work_jurisdiction_code,4,3)
3399 ||
3400 SUBSTR(l_work_jurisdiction_code,8,4));
3401 --}
3402 END IF; -- jurisdiction_codes_tbl_stg.EXISTS
3403
3404
3405 END IF; --l_total_hours < l_scheduled_work_hours
3406
3407
3408 hr_utility.trace('EMJT : Fetching Tagged and/or Positive Pay Hours Element Entries ');
3409 --
3410 -- Processing Tagged Entries for the assignment
3411 --
3412 BEGIN
3413 -- For tagged eearnings start and date date change fir fixing issue 4626170
3414 --
3415 /* OPEN csr_tagged_entries(l_start_date,
3416 l_end_date,
3417 p_assignment_id,
3418 p_date_earned);
3419 */
3420 OPEN csr_tagged_entries(l_max_start_date,
3421 l_max_end_date,
3422 p_assignment_id,
3423 p_date_earned);
3424 --{
3425 FETCH csr_tagged_entries INTO l_tg_jurisdiction_code,
3426 l_tg_sum_hours;
3427 LOOP
3428 --{
3429 EXIT WHEN csr_tagged_entries%NOTFOUND;
3430
3431 IF jurisdiction_codes_tbl_stg.EXISTS(
3432 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3433 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3434 SUBSTR(l_tg_jurisdiction_code,8,4) )
3435 ) THEN
3436 --{
3437 l_hours_fetched := jurisdiction_codes_tbl_stg(
3438 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3439 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3440 SUBSTR(l_tg_jurisdiction_code,8,4) )
3441 ).hours;
3442
3443 jurisdiction_codes_tbl_stg(
3444 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3445 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3446 SUBSTR(l_tg_jurisdiction_code,8,4) )
3447 ).hours := l_hours_fetched + l_tg_sum_hours;
3448
3449 jurisdiction_codes_tbl_stg(
3450 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3451 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3452 SUBSTR(l_tg_jurisdiction_code,8,4) )
3453 ).tg_hours := l_tg_sum_hours;
3454 --}
3455 ELSE
3456 --{
3457 jurisdiction_codes_tbl_stg(
3458 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3459 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3460 SUBSTR(l_tg_jurisdiction_code,8,4) )
3461 ).jurisdiction_code := l_tg_jurisdiction_code;
3462
3463 jurisdiction_codes_tbl_stg(
3464 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3465 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3466 SUBSTR(l_tg_jurisdiction_code,8,4) )
3467 ).hours := l_tg_sum_hours;
3468
3469 jurisdiction_codes_tbl_stg(
3470 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3471 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3472 SUBSTR(l_tg_jurisdiction_code,8,4) )
3473 ).tg_hours := l_tg_sum_hours;
3474
3475 jurisdiction_codes_tbl_stg(
3476 TO_NUMBER(SUBSTR(l_tg_jurisdiction_code,1,2) ||
3477 SUBSTR(l_tg_jurisdiction_code,4,3) ||
3478 SUBSTR(l_tg_jurisdiction_code,8,4) )
3479 ).jd_type := 'TG'; --Informational Time
3480
3481 --}
3482 END IF;
3483
3484 hr_utility.trace('EMJT : ===============================================');
3485 hr_utility.trace('EMJT : Tagged Jurisdiction Code -> ' ||
3486 l_tg_jurisdiction_code);
3487 hr_utility.trace('EMJT : Tagged/Positive_Pay Hours -> ' ||
3488 to_char(l_tg_sum_hours));
3489 hr_utility.trace('EMJT : ===============================================');
3490
3491 FETCH csr_tagged_entries INTO l_tg_jurisdiction_code,
3492 l_tg_sum_hours;
3493 --}
3494 END LOOP;
3495 CLOSE csr_tagged_entries;
3496 EXCEPTION
3497 WHEN OTHERS THEN
3498 hr_utility.trace('EMJT : ERROR Encountered while processing Tagged EE');
3499 hr_utility.trace(substr(sqlerrm,1,45));
3500 hr_utility.trace(substr(sqlerrm,46,45));
3501 END;
3502 hr_utility.trace('EMJT : Tagged and/or Positive Pay Hours Element Entries Fetched and Loaded');
3503
3504 --Just to print the contents of jurisdiction_codes_tbl_stg
3505 l_counter := jurisdiction_codes_tbl_stg.FIRST;
3506 l_last_jd_index_value := jurisdiction_codes_tbl_stg.LAST;
3507 WHILE l_counter IS NOT NULL LOOP
3508 hr_utility.trace('EMJT : =========================================================');
3509 hr_utility.trace('EMJT : jurisdiction_codes_tbl_stg('||to_char(l_counter)||').hours ->'
3510 || jurisdiction_codes_tbl_stg(l_counter).hours);
3511 hr_utility.trace('EMJT : jurisdiction_codes_tbl_stg('||to_char(l_counter)||').tg_hours ->'
3512 || jurisdiction_codes_tbl_stg(l_counter).tg_hours);
3513 hr_utility.trace('EMJT : jurisdiction_codes_tbl_stg('||to_char(l_counter)||').jurisdiction_code->'
3514 || jurisdiction_codes_tbl_stg(l_counter).jurisdiction_code);
3515 hr_utility.trace('EMJT : jurisdiction_codes_tbl_stg('||to_char(l_counter)||').percentage ->'
3516 || jurisdiction_codes_tbl_stg(l_counter).percentage);
3517 hr_utility.trace('EMJT : jurisdiction_codes_tbl_stg('||to_char(l_counter)||').jd_type ->'
3518 || jurisdiction_codes_tbl_stg(l_counter).jd_type);
3519 hr_utility.trace('EMJT : =========================================================');
3520 l_counter := jurisdiction_codes_tbl_stg.NEXT(l_counter);
3521 END LOOP; --WHILE l_counter
3522
3523 --============================================================================================
3524 --This part of the code is used to populate state, county and city level pl tables
3525
3526 -- State pl tables -> jd_codes_tbl_state_STG (STAGING) and jd_codes_tbl_state (MAIN)
3527 -- County pl tables -> jd_codes_tbl_county_STG (STAGING) and jd_codes_tbl_county (MAIN)
3528 -- City pl tables -> jd_codes_tbl_city_STG (STAGING) and jd_codes_tbl_city (MAIN)
3529
3530 --
3531 -- This is to upload the primary work jurisdiction entered hours into staging table
3532 -- created for threshold purpose
3533 --
3534
3535 --Initialize the state and county pl tables.
3536 --Purge all the staging pl/sql table used for Threshold
3537 hr_utility.trace('EMJT: Purge All pl/sql table used for Threshold ');
3538 jd_codes_tbl_state_stg.delete;
3539 jd_codes_tbl_state.delete;
3540 jd_codes_tbl_county_stg.delete;
3541 jd_codes_tbl_county.delete;
3542 jd_codes_tbl_city_stg.delete;
3543 hr_utility.trace('EMJT: PL/SQL tables are purged');
3544 -- Loop thru the staging table to see whether any of the jurisdiction under threshold for taxing
3545 -- Get the hours for each jurisdiction
3546
3547 --Start processing state data, populating the jd_codes_tbl_state.
3548
3549 l_counter := jurisdiction_codes_tbl_stg.FIRST;
3550 l_last_jd_index_value := jurisdiction_codes_tbl_stg.LAST;
3551 hr_utility.trace('EMJT: First JD Code '||to_char(l_counter));
3552 hr_utility.trace('EMJT: Last JD Code '||to_char(l_last_jd_index_value));
3553 WHILE l_counter IS NOT NULL LOOP
3554 BEGIN
3555 --{
3556 l_jurisdiction := jurisdiction_codes_tbl_stg(l_counter).jurisdiction_code ;
3557 l_jd_hours := jurisdiction_codes_tbl_stg(l_counter).hours ;
3558 hr_utility.trace('EMJT: l_jurisdiction '|| l_jurisdiction);
3559 hr_utility.trace('EMJT: l_counter '|| to_char(l_counter));
3560 --Processing For State
3561 IF jd_codes_tbl_state_stg.EXISTS(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||'0000000')
3562 ) THEN
3563 --{
3564 jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000')).hours
3565 := jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000')).hours
3566 + l_jd_hours;
3567 hr_utility.trace('EMJT: State JD Code Exists in State Stg PL table');
3568 --}
3569 ELSE
3570 --{
3571 hr_utility.trace('EMJT: State JD Code doesnot Exists in State Stage pl/sql table');
3572 jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000')).jurisdiction_code
3573 := SUBSTR(l_jurisdiction,1,2)||'-000-0000';
3574 jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000')).hours
3575 := l_jd_hours;
3576
3577 IF l_jd_hours > 0 THEN
3578 jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000')).calc_percent
3579 := 'Y';
3580 ELSE
3581 jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000')).calc_percent
3582 := 'N';
3583 END IF;
3584 hr_utility.trace('EMJT: State JD Code '|| SUBSTR(l_jurisdiction,1,2)||'-000-0000'
3585 ||' loaded to pl/sql table');
3586 --}
3587 END IF;
3588 --End of processing for state
3589
3590 hr_utility.trace('EMJT : =======================================================================');
3591 hr_utility.trace('EMJT : jd_codes_tbl_state_stg.count ->' || jd_codes_tbl_state_stg.COUNT);
3592 hr_utility.trace('EMJT : l_counter ->'||l_counter);
3593
3594 /* hr_utility.trace('EMJT : jd_codes_tbl_state_stg.jurisdiction_code->' || jd_codes_tbl_state_stg(l_counter).jurisdiction_code);
3595 hr_utility.trace('EMJT : jd_codes_tbl_state_stg('||to_char(l_counter)||').hours ->'
3596 || jd_codes_tbl_state_stg(l_counter).hours);
3597 hr_utility.trace('EMJT : jd_codes_tbl_state_stg('||to_char(l_counter)||').percentage ->'
3598 || jd_codes_tbl_state_stg(l_counter).percentage);
3599 hr_utility.trace('EMJT : jd_codes_tbl_state_stg('||to_char(l_counter)||').calc_percent ->'
3600 || jd_codes_tbl_state_stg(l_counter).calc_percent);*/
3601 hr_utility.trace('EMJT : ========================================================================');
3602
3603 --Processing For County
3604 IF jd_codes_tbl_county_stg.EXISTS(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3605 SUBSTR(l_jurisdiction,4,3)||
3606 '0000')
3607 ) THEN
3608 --{
3609 jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3610 SUBSTR(l_jurisdiction,4,3)||'0000')).hours
3611 := jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3612 SUBSTR(l_jurisdiction,4,3)||'0000')).hours
3613 + l_jd_hours;
3614 hr_utility.trace('EMJT: County JD Code Exists in State Stage pl/sql table');
3615 --}
3616 ELSE
3617 --{
3618 hr_utility.trace('EMJT: County JD Code doesnot Exists in County Stg pl table');
3619 hr_utility.trace('EMJT: County JD Code '||SUBSTR(l_jurisdiction,1,7)||'0000');
3620 jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3621 SUBSTR(l_jurisdiction,4,3)||
3622 '0000')).jurisdiction_code
3623 := SUBSTR(l_jurisdiction,1,7)||'0000';
3624
3625 jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3626 SUBSTR(l_jurisdiction,4,3)||
3627 '0000')
3628 ).hours := l_jd_hours;
3629
3630 IF l_jd_hours > 0 THEN
3631 jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3632 SUBSTR(l_jurisdiction,4,3)||
3633 '0000')
3634 ).calc_percent := 'Y';
3635 ELSE
3636 jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3637 SUBSTR(l_jurisdiction,4,3)||
3638 '0000')
3639 ).calc_percent := 'N';
3640 END IF;
3641 hr_utility.trace('EMJT: County JD Code '|| SUBSTR(l_jurisdiction,1,7)||'0000'
3642 ||' loaded to pl/sql table');
3643
3644 --}
3645 END IF;
3646 --End of processing for county.
3647
3648 l_counter := jurisdiction_codes_tbl_stg.NEXT(l_counter);
3649 --}
3650 EXCEPTION
3651 WHEN OTHERS THEN
3652 hr_utility.trace('EMJT: ERROR in populating State/County Stg Pl Table');
3653 hr_utility.trace(substr(sqlerrm,1,45));
3654 hr_utility.trace(substr(sqlerrm,46,45));
3655 RAISE;
3656 END;
3657 END LOOP;
3658 hr_utility.trace('EMJT: Staging table jd_codes_tbl_state_stg populated sucessfully');
3659 hr_utility.trace('EMJT: Staging table jd_codes_tbl_county_stg populated sucessfully');
3660 l_counter := NULL;
3661 --
3662 --This part of the code populates the MAIN STATE PL TABLE that will be used in get_jd_percent
3663 --FROM jd_codes_tbl_state_stg INTO jd_codes_tbl_state
3664 --
3665 hr_utility.trace('EMJT STATE:==============================================================');
3666 hr_utility.trace('EMJT STATE: Main State Processing');
3667 l_counter := jd_codes_tbl_state_stg.FIRST;
3668 l_last_jd_index_value := jd_codes_tbl_state_stg.LAST;
3669 hr_utility.trace('EMJT STATE: State First JD Code '||to_char(l_counter));
3670 hr_utility.trace('EMJT STATE: State Last JD Code '||to_char(l_last_jd_index_value));
3671
3672 WHILE l_counter IS NOT NULL LOOP
3673 --{
3674 l_jurisdiction := jd_codes_tbl_state_stg(l_counter).jurisdiction_code ;
3675 l_jd_hours := jd_codes_tbl_state_stg(l_counter).hours ;
3676 l_calc_percent := jd_codes_tbl_state_stg(l_counter).calc_percent ;
3677 hr_utility.trace('EMJT STATE: State l_counter ->'|| l_counter);
3678 hr_utility.trace('EMJT STATE: State Jurisdiction Code =>'|| l_jurisdiction);
3679 hr_utility.trace('EMJT STATE: State Hours =>'|| to_char(l_jd_hours));
3680 hr_utility.trace('EMJT STATE: State Calculate Percentage =>'|| l_calc_percent);
3681 -- When Jurisdiction state is same as primary work state no thresholding
3682 IF l_calc_percent = 'N' THEN
3683 --{
3684 hr_utility.trace('EMJT STATE: Thresholding Not required load in jd_codes_tbl_state');
3685 jd_codes_tbl_state(l_counter).jurisdiction_code := l_jurisdiction;
3686 jd_codes_tbl_state(l_counter).hours := l_jd_hours;
3687 jd_codes_tbl_state(l_counter).calc_percent := l_calc_percent;
3688 --}
3689 ELSE
3690 --{
3691 IF SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2) THEN
3692 --{
3693 hr_utility.trace('EMJT STATE: Work state is same as Primary Work State');
3694 hr_utility.trace('EMJT STATE: Threshold check not required load in jd_codes_tbl_state');
3695 IF jd_codes_tbl_state.EXISTS(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||'0000000'))
3696 THEN
3697 --{
3698 hr_utility.trace('EMJT STATE: HERE in if');
3699 hr_utility.trace('EMJT STATE: TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||''0000000'')-> '||TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||'0000000'));
3700 hr_utility.trace('EMJT STATE: l_counter '|| to_char(l_counter));
3701 jd_codes_tbl_state(l_counter).hours
3702 := NVL(jd_codes_tbl_state(l_counter).hours,0) + l_jd_hours;
3703 --}
3704 ELSE
3705 --{
3706 hr_utility.trace('EMJT STATE: IN ELSE');
3707 jd_codes_tbl_state(l_counter).jurisdiction_code := l_jurisdiction;
3708 jd_codes_tbl_state(l_counter).hours := l_jd_hours;
3709 jd_codes_tbl_state(l_counter).calc_percent := l_calc_percent;
3710 hr_utility.trace('EMJT STATE: Primary Work State JD loaded into jd_codes_tbl_state');
3711 --}
3712 END IF;
3713 --}
3714 ELSE --SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2)
3715 --{
3716 hr_utility.trace('EMJT STATE: Work state is NOT same as Primar Work State');
3717 --Fetch State level Threshold
3718 hr_utility.trace('EMJT STATE: Fetching Threshold Hours configured for State ');
3719 hr_utility.trace('EMJT STATE: Processing State JD Code '||l_jurisdiction);
3720 l_threshold_hours_state := get_jd_level_threshold(p_tax_unit_id
3721 ,l_jurisdiction
3722 ,'STATE');
3723 hr_utility.trace('EMJT STATE: Threshold_Hours_State '|| to_char(l_threshold_hours_state));
3724 IF l_threshold_hours_state > 0 THEN
3725 --{
3726 -- Fetch the state level tax balance accrued for the person
3727 -- If Tax balance found then tax the state as per hours logged for the state
3728 -- otherwise hours will be accounted to primary work state
3729 -- for SIT Witheld and/or SIT Supp Witheld
3730 hr_utility.trace('EMJT STATE: Threshold_Hours_State > 0 so Fetch SIT Witheld for Assignment');
3731
3732
3733
3734 /* Bug 6869097:The following code checks whether SIT is withheld already for the
3735 assignment and if it finds SIT is withheld already it assumes that the
3736 assignemnt has crossed the threshold limit already and inserts the
3737 current record. But there are some situations where tax is withheld
3738 for an assignment even before the threshold limit is reached. So commented
3739 the following code so that it can go on with threshold checking irrespective
3740 of SIT Withheld balance.
3741 */
3742
3743 /* l_sit_withheld :=
3744 hr_us_ff_udf1.get_jd_tax_balance(p_threshold_basis => l_threshold_basis
3745 ,p_assignment_action_id => p_assignment_action_id
3746 ,p_jurisdiction_code => l_jurisdiction
3747 ,p_tax_unit_id => p_tax_unit_id
3748 ,p_jurisdiction_level => 'STATE'
3749 ,p_effective_date => p_date_paid
3750 ,p_assignment_id => p_assignment_id);
3751 hr_utility.trace('EMJT STATE: SIT Withheld for Assignment -> '|| to_char(l_sit_withheld));
3752 IF l_sit_withheld > 0 THEN
3753 --{
3754 hr_utility.trace('EMJT STATE: As Tax Withheld previously in State NO THRESHOLD CHECK');
3755 jd_codes_tbl_state(l_counter).jurisdiction_code := l_jurisdiction;
3756 jd_codes_tbl_state(l_counter).hours := l_jd_hours;
3757 jd_codes_tbl_state(l_counter).calc_percent := l_calc_percent;
3758 hr_utility.trace('EMJT STATE: State JD '||l_jurisdiction||' loaded in jd_codes_tbl_state ');
3759 --}
3760 ELSE --l_sit_withheld > 0 */
3761
3762 /*Bug#6869097: changes end here*/
3763 --{
3764 -- Fetch Information Hours logged for the person depending on the payroll effective date
3765 -- call to get_th_assignment for the STATE
3766 hr_utility.trace('EMJT STATE: Fetch Information Hours Logged for Assignment ');
3767 l_state_ih_logged
3768 := hr_us_ff_udf1.get_person_it_hours(p_person_id => l_person_id
3769 ,p_assignment_id => p_assignment_id
3770 ,p_jurisdiction_code => l_jurisdiction
3771 ,p_jd_level => 2
3772 ,p_threshold_basis => l_threshold_basis
3773 ,p_effective_date => l_max_end_date -- p_date_paid
3774 ,p_end_date => l_end_date);
3775 hr_utility.trace('EMJT STATE: Information Hours Logged for Assignment for State => '
3776 || to_char(l_state_ih_logged));
3777 IF l_state_ih_logged >= l_threshold_hours_state THEN
3778 --{
3779 hr_utility.trace('EMJT STATE: Information Hours Logged > Threshold_Hours_State ');
3780 l_ih_excluding_pay_period := l_state_ih_logged - l_jd_hours;
3781 hr_utility.trace('EMJT STATE: Information Hours Processed Prior This Pay Period -> '
3782 || to_char(l_ih_excluding_pay_period));
3783 -- if information hours processed till last payroll run is greater than the
3784 -- threshold limit configured at the State level then hours logged for the state
3785 -- would be accounted for that state
3786 --
3787 IF l_ih_excluding_pay_period >= l_threshold_hours_state THEN
3788 --{
3789 hr_utility.trace('EMJT STATE: Hours till last Pay Period > Threshold_Hours_State');
3790 jd_codes_tbl_state(l_counter).jurisdiction_code := l_jurisdiction;
3791 jd_codes_tbl_state(l_counter).hours := l_jd_hours;
3792 jd_codes_tbl_state(l_counter).calc_percent := l_calc_percent;
3793 hr_utility.trace('EMJT STATE: State JD loaded into jd_codes_tbl_state '|| l_jurisdiction);
3794 hr_utility.trace('EMJT STATE: Hours loaded into jd_codes_tbl_state '|| to_char(l_jd_hours));
3795 --}
3796 ELSE --l_ih_excluding_pay_period >= l_threshold_hours_state
3797 --{
3798 -- if information hours processed till last payroll run is less than the
3799 -- threshold limit configured at the State level
3800 -- Calculate information hours that is exceeds threshold limit
3801 --
3802 l_ih_above_threshold := l_state_ih_logged - l_threshold_hours_state;
3803 hr_utility.trace('EMJT STATE: Information Hours Above Threshold -> '
3804 || to_char(l_ih_above_threshold));
3805 --
3806 -- Calculate information hours that would be accounted to primary work location
3807 -- due to threshold
3808 hr_utility.trace('EMJT STATE: l_jurisdiction -> '|| l_jurisdiction);
3809 hr_utility.trace('EMJT STATE: l_counter -> '|| to_char(l_counter));
3810
3811 l_ih_for_primary_wk :=
3812 jd_codes_tbl_state_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
3813 '0000000')).hours - l_ih_above_threshold;
3814 hr_utility.trace('EMJT STATE: Hours Accounted for Primary Work Location '
3815 ||to_char(l_ih_for_primary_wk));
3816
3817 -- if information hours logged for the state is more than threshold
3818 -- configured for the state, only exceeded hours would be accounted for that
3819 -- state
3820 IF l_ih_above_threshold > 0 THEN
3821 IF jd_codes_tbl_state.EXISTS(
3822 TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||'0000000'))
3823 THEN
3824 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_jurisdiction_code,1,2)
3825 ||'0000000')).hours :=
3826 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3827 ||'0000000')).hours + l_ih_above_threshold ;
3828 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)
3829 ||'0000000')).calc_percent := l_calc_percent;
3830 ELSE
3831 jd_codes_tbl_state(l_counter).jurisdiction_code := l_jurisdiction;
3832 jd_codes_tbl_state(l_counter).hours := l_ih_above_threshold ;
3833 jd_codes_tbl_state(l_counter).calc_percent := l_calc_percent;
3834 END IF;
3835 END IF;
3836 -- When Total information hours logged for the person is above threshold
3837 -- but there are some information hours need to accounted to primary
3838 -- work location due to threshold limit
3839 -- This is determine if part of information hours entered for the processing pay
3840 -- period need to be accounted to primary work location due to
3841 --
3842 IF l_ih_for_primary_wk > 0 THEN
3843 --{
3844 hr_utility.trace(' EMJT STATE: l_ih_for_primary_wk -> ' || to_char(l_ih_for_primary_wk));
3845 IF jd_codes_tbl_state.EXISTS(
3846 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||'0000000'))
3847 THEN
3848 --{
3849 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3850 ||'0000000')).hours :=
3851 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3852 ||'0000000')).hours + l_ih_for_primary_wk ;
3853 hr_utility.trace('EMJT STATE: Hours accounted for Primary WK JD State in IF '
3854 || to_char(l_ih_for_primary_wk));
3855 --}
3856 ELSE
3857 --{
3858 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3859 ||'0000000')).jurisdiction_code
3860 := SUBSTR(l_work_jurisdiction_code,1,2)||'-000-0000';
3861 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3862 ||'0000000')).hours := l_ih_for_primary_wk;
3863 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3864 ||'0000000')).calc_percent := l_calc_percent;
3865 hr_utility.trace('EMJT STATE: Primary WK JD State loaded into pl table jd_codes_tbl_state');
3866 hr_utility.trace('EMJT STATE: Hours accounted for Primary WK JD State in ELSE '
3867 ||to_char(l_ih_for_primary_wk));
3868 --}
3869 END IF;
3870 --}
3871 END IF; --l_ih_for_primary_wk > 0
3872 --}
3873 END IF; --l_ih_excluding_pay_period >= l_threshold_hours_state
3874 --}
3875 ELSE
3876 --{
3877 -- If Information Hours Logged for the assignment is less than Threshold Hours
3878 -- configured for the state, information hours would be accounted to primary work
3879 -- State
3880 IF jd_codes_tbl_state.EXISTS(
3881 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||'0000000'))
3882 THEN
3883 --{
3884 hr_utility.trace('EMJT STATE: l_jd_hours -> '|| to_char(l_jd_hours) );
3885 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3886 ||'0000000')).hours :=
3887 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3888 ||'0000000')).hours + l_jd_hours ;
3889 hr_utility.trace('EMJT STATE: Hours accounted for Primary WK JD State in IF l_jd_hours'
3890 || to_char(l_jd_hours));
3891 --}
3892 ELSE
3893 --{
3894 hr_utility.trace('EMJT STATE: l_work_jurisdiction_code -> '|| l_work_jurisdiction_code);
3895 hr_utility.trace('EMJT STATE: l_counter -> '|| to_char(l_counter));
3896 hr_utility.trace('EMJT STATE: l_calc_percent -> '|| l_calc_percent);
3897 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3898 ||'0000000')).jurisdiction_code
3899 := SUBSTR(l_work_jurisdiction_code,1,2)||'-000-0000';
3900 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3901 ||'0000000')).hours := l_jd_hours;
3902 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)
3903 ||'0000000')).calc_percent := l_calc_percent;
3904 hr_utility.trace('EMJT STATE: Primary WK JD State loaded into pl table jd_codes_tbl_state');
3905 hr_utility.trace('EMJT STATE: Hours accounted for Primary WK JD State in ELSE l_jd_hours '
3906 ||to_char(l_jd_hours));
3907 --}
3908 END IF;
3909 --}
3910 END IF; --l_state_ih_logged > l_threshold_hours_state
3911 --}
3912 -- END IF;--l_sit_withheld > 0 /*6869097*/
3913 --}
3914 ELSE
3915 -- If Threshold Hours not logged for a State load Jurisdiction into jd_codes_tbl_state
3916 --
3917 --{
3918 jd_codes_tbl_state(l_counter).jurisdiction_code := l_jurisdiction;
3919 jd_codes_tbl_state(l_counter).hours := l_jd_hours;
3920 jd_codes_tbl_state(l_counter).calc_percent := l_calc_percent;
3921 hr_utility.trace('EMJT STATE: Work JD State loaded into jd_codes_tbl_state =>'
3922 ||l_jurisdiction);
3923 hr_utility.trace('EMJT STATE: Hours accounted for Primary WK JD State '
3924 ||to_char(l_ih_for_primary_wk));
3925 --}
3926 END IF;--l_threshold_hours_state > 0
3927 --}
3928 END IF; --SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2)
3929 --}
3930 END IF; --l_calc_percent = 'N'
3931
3932 /* hr_utility.trace('EMJT:Testing =================================================');
3933 l_in_counter := NULL;
3934 l_in_counter := jd_codes_tbl_state.FIRST;
3935 WHILE l_in_counter IS NOT NULL LOOP
3936 hr_utility.trace('EMJT: jd_codes_tbl_state.jurisdiction_code -> '||jd_codes_tbl_state(l_in_counter).jurisdiction_code);
3937 hr_utility.trace('EMJT: jd_codes_tbl_state.hours -> '||jd_codes_tbl_state(l_in_counter).hours);
3938 l_in_counter := jd_codes_tbl_state.NEXT(l_in_counter);
3939 END LOOP;
3940 hr_utility.trace('EMJT:=================================================');*/
3941
3942 hr_utility.trace('EMJT STATE: Setting the Index counter to fetch next JD State ');
3943 l_counter := jd_codes_tbl_state_stg.NEXT(l_counter);
3944 hr_utility.trace('EMJT STATE: Next Index Counter Value '||to_char(l_counter));
3945 --}
3946 END LOOP;
3947 hr_utility.trace('EMJT STATE: Final jd_codes_tbl_state.count ->' || jd_codes_tbl_state.COUNT);
3948 hr_utility.trace('EMJT STATE: PL Table jd_codes_tbl_state_stg processed Successfully');
3949 --Done with populating the jd_codes_tbl_state.
3950
3951
3952 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3953 l_counter := NULL;
3954 l_counter := jd_codes_tbl_state.FIRST;
3955 l_last_jd_index_value := jd_codes_tbl_state.LAST;
3956 hr_utility.trace('EMJT STATE: jd_codes_tbl_state.FIRST->' || jd_codes_tbl_state.FIRST);
3957 hr_utility.trace('EMJT STATE: jd_codes_tbl_state.LAST->' || jd_codes_tbl_state.LAST);
3958
3959 WHILE l_counter IS NOT NULL LOOP
3960 hr_utility.trace('EMJT STATE: =========================================================');
3961 hr_utility.trace('EMJT STATE: jd_codes_tbl_state('||to_char(l_counter)||').hours ->'
3962 || jd_codes_tbl_state(l_counter).hours);
3963 hr_utility.trace('EMJT STATE: jd_codes_tbl_state('||to_char(l_counter)||').jurisdiction_code->'
3964 || jd_codes_tbl_state(l_counter).jurisdiction_code);
3965 hr_utility.trace('EMJT STATE: jd_codes_tbl_state('||to_char(l_counter)||').percentage ->'
3966 || jd_codes_tbl_state(l_counter).percentage);
3967 hr_utility.trace('EMJT STATE: =========================================================');
3968 l_total_state_hours := l_total_state_hours + NVL(jd_codes_tbl_state(l_counter).hours,0);
3969 l_counter := jd_codes_tbl_state.NEXT(l_counter);
3970 END LOOP;
3971
3972 hr_utility.trace('EMJT STATE: Final l_total_state_hours ->' || to_char(l_total_state_hours) );
3973 hr_utility.trace('EMJT STATE: Final l_scheduled_work_hours ->' || to_char(l_scheduled_work_hours) );
3974
3975 IF l_total_state_hours <= l_scheduled_work_hours THEN
3976 l_denominator := l_scheduled_work_hours;
3977 ELSIF l_total_state_hours > l_scheduled_work_hours THEN
3978 l_denominator := l_total_state_hours;
3979 END IF;
3980
3981 hr_utility.trace('EMJT STATE: Final l_denominator ->' || to_char(l_denominator) );
3982
3983 l_counter := NULL;
3984 l_counter := jd_codes_tbl_state.FIRST;
3985 l_last_jd_index_value := jd_codes_tbl_state.LAST;
3986 WHILE l_counter IS NOT NULL LOOP
3987 l_jd_hours := jd_codes_tbl_state(l_counter).hours ;
3988 jd_codes_tbl_state(l_counter).percentage :=
3989 ROUND((l_jd_hours/l_denominator) * 100);
3990 /* hr_utility.trace('EMJT: =========================================================');
3991 hr_utility.trace('EMJT: jd_codes_tbl_state('||to_char(l_counter)||').hours ->'
3992 || jd_codes_tbl_state(l_counter).hours);
3993 hr_utility.trace('EMJT: jd_codes_tbl_state('||to_char(l_counter)||').jurisdiction_code->'
3994 || jd_codes_tbl_state(l_counter).jurisdiction_code);
3995 hr_utility.trace('EMJT: jd_codes_tbl_state('||to_char(l_counter)||').percentage ->'
3996 || jd_codes_tbl_state(l_counter).percentage);
3997 hr_utility.trace('EMJT: =========================================================');*/
3998 l_total_state_percent := l_total_state_percent
3999 + jd_codes_tbl_state(l_counter).percentage;
4000 l_counter := jd_codes_tbl_state.NEXT(l_counter);
4001 END LOOP; --WHILE l_counter
4002
4003 hr_utility.trace('EMJT STATE: (TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||''0000000'')) '||
4004 TO_CHAR(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||'0000000')));
4005 IF l_total_state_percent > 100 THEN
4006 --{
4007 l_extra_percent := l_total_state_percent - 100;
4008 IF l_primary_work_jd_flag = 'Y' THEN
4009 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||'0000000')).percentage
4010 := jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||'0000000')).percentage
4011 - l_extra_percent;
4012 ELSE
4013 jd_codes_tbl_state(l_last_jd_index_value).percentage
4014 := jd_codes_tbl_state(l_last_jd_index_value).percentage
4015 - l_extra_percent;
4016 END IF;
4017 --}
4018 ELSIF l_total_state_percent < 100 THEN
4019 --{
4020 l_extra_percent := 100 - l_total_state_percent;
4021 IF l_primary_work_jd_flag = 'Y' THEN
4022 jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||'0000000')).percentage
4023 := jd_codes_tbl_state(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||'0000000')).percentage
4024 + l_extra_percent;
4025 ELSE
4026 jd_codes_tbl_state(l_last_jd_index_value).percentage
4027 := jd_codes_tbl_state(l_last_jd_index_value).percentage
4028 + l_extra_percent;
4029 END IF;
4030 --}
4031 END IF; --l_total_state_percent > 100
4032
4033
4034 l_counter := NULL;
4035 l_counter := jd_codes_tbl_state.FIRST;
4036 -- l_last_jd_index_value := jd_codes_tbl_state.LAST;
4037 hr_utility.trace('EMJT STATE: jd_codes_tbl_state.FIRST->' || jd_codes_tbl_state.FIRST);
4038 hr_utility.trace('EMJT STATE: jd_codes_tbl_state.LAST->' || jd_codes_tbl_state.LAST);
4039 WHILE l_counter IS NOT NULL LOOP
4040 hr_utility.trace('EMJT STATE: Final State Table');
4041 hr_utility.trace('EMJT STATE: =========================================================');
4042 hr_utility.trace('EMJT STATE: jd_codes_tbl_state('||to_char(l_counter)||').hours ->'
4043 || jd_codes_tbl_state(l_counter).hours);
4044 hr_utility.trace('EMJT STATE: jd_codes_tbl_state('||to_char(l_counter)||').jurisdiction_code->'
4045 || jd_codes_tbl_state(l_counter).jurisdiction_code);
4046 hr_utility.trace('EMJT STATE: jd_codes_tbl_state('||to_char(l_counter)||').percentage ->'
4047 || jd_codes_tbl_state(l_counter).percentage);
4048 hr_utility.trace('EMJT STATE: =========================================================');
4049 -- l_total_state_hours := l_total_state_hours + jd_codes_tbl_state(l_counter).hours;
4050 l_counter := jd_codes_tbl_state.NEXT(l_counter);
4051 END LOOP;
4052
4053 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4054 hr_utility.trace('EMJT COUNTY:==============================================================');
4055 hr_utility.trace('EMJT COUNTY: Main COUNTY Processing');
4056
4057 --Starting processing the county, populating jd_codes_tbl_county.
4058 --
4059 --This part of the code populates the MAIN COUNTY PL TABLE from the staging county pl table.
4060 --INTO jd_codes_tbl_county
4061 --FROM jd_codes_tbl_county_stg
4062 --
4063 l_counter := NULL;
4064 l_counter := jd_codes_tbl_county_stg.FIRST;
4065 l_last_jd_index_value := jd_codes_tbl_county_stg.LAST;
4066 hr_utility.trace('EMJT COUNTY: l_counter First JD Code -> '|| to_char(l_counter));
4067 hr_utility.trace('EMJT COUNTY: Last JD Code ->'|| to_char(l_last_jd_index_value));
4068 WHILE l_counter IS NOT NULL LOOP
4069 --{
4070 l_jurisdiction := jd_codes_tbl_county_stg(l_counter).jurisdiction_code ;
4071 l_jd_hours := jd_codes_tbl_county_stg(l_counter).hours ;
4072 l_calc_percent := jd_codes_tbl_county_stg(l_counter).calc_percent ;
4073 hr_utility.trace('EMJT COUNTY: Jurisdiction Code =>'|| l_jurisdiction);
4074 hr_utility.trace('EMJT COUNTY: l_jd_hours =>'|| to_char(l_jd_hours));
4075 hr_utility.trace('EMJT COUNTY: Calculate Percenrage =>'|| l_calc_percent);
4076
4077 -- When Jurisdiction county is same as primary work county no thresholding
4078 IF l_calc_percent = 'N' THEN
4079 --{
4080 hr_utility.trace('EMJT COUNTY: Thresholding Not required load in jd_codes_tbl_county');
4081 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4082 jd_codes_tbl_county(l_counter).hours := l_jd_hours;
4083 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4084 --}
4085 ELSE
4086 --{
4087 IF SUBSTR(l_jurisdiction,1,2)||SUBSTR(l_jurisdiction,4,3) =
4088 SUBSTR(l_work_jurisdiction_code,1,2)||SUBSTR(l_work_jurisdiction_code,4,3) THEN
4089 --{
4090 hr_utility.trace('EMJT COUNTY: Work County is same as Primar Work County');
4091 hr_utility.trace('EMJT COUNTY: Threshold check not required to load in jd_codes_tbl_county');
4092 IF jd_codes_tbl_county.EXISTS(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4093 SUBSTR(l_jurisdiction,4,3) ||'0000'))
4094 THEN
4095 --{
4096 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4097 SUBSTR(l_jurisdiction,4,3) ||
4098 '0000')).hours
4099 := jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4100 SUBSTR(l_jurisdiction,4,3) ||
4101 '0000')).hours + l_jd_hours;
4102 --}
4103 ELSE
4104 --{
4105 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4106 jd_codes_tbl_county(l_counter).hours := l_jd_hours;
4107 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4108 hr_utility.trace('EMJT COUNTY: Primary Work State JD loaded into jd_codes_tbl_state');
4109 --}
4110 END IF;
4111 --}
4112 ELSE --SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2)
4113 --{
4114 --Fetch County level threshold
4115 hr_utility.trace('EMJT COUNTY: Work County is NOT same as Primary Work County');
4116 hr_utility.trace('EMJT COUNTY: Fetching Threshold Hours configured for County ');
4117 hr_utility.trace('EMJT COUNTY: Processing County JD Code '|| l_jurisdiction);
4118
4119 l_threshold_hours_county := get_jd_level_threshold(p_tax_unit_id
4120 ,l_jurisdiction
4121 ,'COUNTY');
4122 hr_utility.trace('EMJT COUNTY: Threshold_Hours_County '|| to_char(l_threshold_hours_county));
4123 IF l_threshold_hours_county > 0 THEN
4124 --{
4125 -- Fetch the county level tax balance accrued for the person
4126 -- If Tax balance found then tax the county as per hours logged for the county
4127 -- otherwise hours will be accounted to primary work county
4128 hr_utility.trace('EMJT COUNTY: Threshold_Hours_County > 0 so Fetch County Witheld for Assignment');
4129
4130 /* Bug#6869097:The following code checks whether county tax is withheld already
4131 for the assignment and if it finds SIT is withheld already it assumes that
4132 the assignemnt has crossed the threshold limit already and inserts the
4133 current record. Commented the following code so that it can go on with
4134 threshold checking irrespective of county tax Withheld balance.
4135 */
4136
4137 /* l_county_withheld :=
4138 hr_us_ff_udf1.get_jd_tax_balance(p_threshold_basis => l_threshold_basis
4139 ,p_assignment_action_id=> p_assignment_action_id
4140 ,p_jurisdiction_code => l_jurisdiction
4141 ,p_tax_unit_id => p_tax_unit_id
4142 ,p_jurisdiction_level => 'COUNTY'
4143 ,p_effective_date => p_date_paid
4144 ,p_assignment_id => p_assignment_id);
4145 hr_utility.trace('EMJT COUNTY: County Withheld for Assignment '|| to_char(l_county_withheld));
4146 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county.COUNT -> '|| jd_codes_tbl_county.COUNT);
4147
4148 --=============================================================================
4149 IF l_county_withheld = 0 THEN
4150
4151 l_sit_county_withheld :=
4152 hr_us_ff_udf1.get_jd_tax_balance(p_threshold_basis => l_threshold_basis
4153 ,p_assignment_action_id => p_assignment_action_id
4154 ,p_jurisdiction_code => l_jurisdiction
4155 ,p_tax_unit_id => p_tax_unit_id
4156 ,p_jurisdiction_level => 'STATE'
4157 ,p_effective_date => p_date_paid
4158 ,p_assignment_id => p_assignment_id);
4159 hr_utility.trace('EMJT: l_sit_county_withheld -> '||to_char(l_sit_county_withheld));
4160 END IF;
4161 --=============================================================================
4162
4163 IF l_county_withheld > 0 THEN
4164 --{
4165 hr_utility.trace('EMJT COUNTY: As Tax Withheld previously in County NO THRESHOLD CHECK');
4166 hr_utility.trace('EMJT COUNTY: l_county_withheld > 0 ');
4167 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4168 jd_codes_tbl_county(l_counter).hours := l_jd_hours;
4169 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4170 hr_utility.trace('EMJT COUNTY: County JD '||l_jurisdiction||' loaded in jd_codes_tbl_county ');
4171 --}
4172 ELSIF l_county_withheld = 0 AND l_sit_county_withheld > 0 THEN
4173 --{
4174 hr_utility.trace('EMJT COUNTY: l_county_withheld = 0 AND l_sit_county_withheld > 0 ');
4175 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4176 jd_codes_tbl_county(l_counter).hours := l_jd_hours;
4177 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4178 hr_utility.trace('EMJT COUNTY: County JD '||l_jurisdiction||' loaded in jd_codes_tbl_county ');
4179 --}
4180 -- ELSE --l_county_withheld > 0 */
4181
4182 /*Bug#6869097: changes end here*/
4183 --{
4184 -- Fetch Information Hours logged for the person depending on the payroll effective date
4185 -- call to get_th_assignment for the COUNTY
4186 hr_utility.trace('EMJT COUNTY: Fetch Information Hours Logged for Assignment ');
4187 l_county_ih_logged
4188 := hr_us_ff_udf1.get_person_it_hours(p_person_id => l_person_id
4189 ,p_assignment_id => p_assignment_id
4190 ,p_jurisdiction_code => l_jurisdiction
4191 ,p_jd_level => 6
4192 ,p_threshold_basis => l_threshold_basis
4193 ,p_effective_date => l_max_end_date --p_date_paid
4194 ,p_end_date => l_end_date);
4195 hr_utility.trace('EMJT COUNTY: Information Hours Logged for Assignment => '|| to_char(l_county_ih_logged));
4196 IF l_county_ih_logged >= l_threshold_hours_county THEN
4197 --{
4198 hr_utility.trace('EMJT COUNTY: Information Hours Logged > Threshold_Hours_County ');
4199 l_ih_excluding_pay_period := l_county_ih_logged
4200 - l_jd_hours;
4201 hr_utility.trace('EMJT COUNTY: Information Hours Processed Prior This Pay Period '
4202 || to_char(l_ih_excluding_pay_period));
4203 -- if information hours processed till last payroll run is greater than the
4204 -- threshold limit configured at the County level then hours logged for the county
4205 -- would be accounted for that county
4206 --
4207 IF l_ih_excluding_pay_period >= l_threshold_hours_county THEN
4208 --{
4209 hr_utility.trace('EMJT COUNTY: Hours till last Pay Period > Threshold_Hours_State');
4210 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4211 jd_codes_tbl_county(l_counter).hours := l_jd_hours;
4212 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4213 hr_utility.trace('EMJT COUNTY: County JD loaded into jd_codes_tbl_county '|| l_jurisdiction);
4214 hr_utility.trace('EMJT COUNTY: Hours loaded into jd_codes_tbl_county '|| to_char(l_jd_hours));
4215
4216 --}
4217 ELSE --l_ih_excluding_pay_period >= l_threshold_hours_county
4218 --{
4219 -- if information hours processed till last payroll run is less than the
4220 -- threshold limit configured at the county level
4221 -- Calculate information hours that is exceeds threshold limit
4222 l_ih_above_threshold := l_county_ih_logged - l_threshold_hours_county;
4223 hr_utility.trace('EMJT COUNTY: Information Hours Above Threshold '
4224 || to_char(l_ih_above_threshold));
4225
4226 -- Calculate information hours that would be accounted to primary work location
4227 -- due to threshold
4228 l_ih_for_primary_wk := jd_codes_tbl_county_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4229 SUBSTR(l_jurisdiction,4,3) ||
4230 '0000')
4231 ).hours - l_ih_above_threshold;
4232 hr_utility.trace('EMJT COUNTY: Hours Accounted for Primary Work Location '
4233 || to_char(l_ih_for_primary_wk));
4234
4235 -- if information hours logged for the county is more than threshold
4236 -- configured for the county, only exceeded hours would be accounted for that
4237 -- county
4238 IF l_ih_above_threshold > 0 THEN
4239 IF jd_codes_tbl_county.EXISTS(
4240 TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
4241 SUBSTR(l_jurisdiction,4,3) ||'0000'))
4242 THEN
4243 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
4244 SUBSTR(l_jurisdiction,4,3)||'0000')).hours :=
4245 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
4246 SUBSTR(l_jurisdiction,4,3)||'0000')).hours
4247 + l_ih_above_threshold ;
4248 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_jurisdiction,1,2)||
4249 SUBSTR(l_jurisdiction,4,3) ||'0000')).calc_percent := l_calc_percent;
4250 ELSE
4251 --{
4252 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4253 jd_codes_tbl_county(l_counter).hours := l_ih_above_threshold ;
4254 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4255 --}
4256 END IF;
4257 END IF;
4258 -- When Total information hours logged for the person is above threshold
4259 -- but there are some information hours need to accounted to primary
4260 -- work location due to threshold limit
4261 -- This is determine if part of information hours entered for the processing pay
4262 -- period need to be accounted to primary work location due to
4263 --
4264 IF l_ih_for_primary_wk > 0 THEN
4265 --{
4266 IF jd_codes_tbl_county.EXISTS(
4267 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4268 SUBSTR(l_work_jurisdiction_code,4,3) ||
4269 '0000'))
4270 THEN
4271 --{
4272 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4273 SUBSTR(l_work_jurisdiction_code,4,3) ||
4274 '0000')
4275 ).hours :=
4276 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4277 SUBSTR(l_work_jurisdiction_code,4,3) ||
4278 '0000')
4279 ).hours + l_ih_for_primary_wk ;
4280 hr_utility.trace('EMJT COUNTY: Hours accounted for Primary WK JD County '
4281 || to_char(l_ih_for_primary_wk));
4282
4283 --}
4284 ELSE
4285 --{
4286 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4287 SUBSTR(l_work_jurisdiction_code,4,3) ||
4288 '0000')).jurisdiction_code
4289 := SUBSTR(l_work_jurisdiction_code,1,7)||'0000';
4290 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4291 SUBSTR(l_work_jurisdiction_code,4,3) ||
4292 '0000')).hours
4293 := l_ih_for_primary_wk;
4294 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4295 SUBSTR(l_work_jurisdiction_code,4,3) ||
4296 '0000')).calc_percent
4297 := l_calc_percent;
4298 hr_utility.trace('EMJT COUNTY: Primary WK JD State loaded into pl table jd_codes_tbl_county');
4299 hr_utility.trace('EMJT COUNTY: Hours accounted for Primary WK JD County '
4300 ||to_char(l_ih_for_primary_wk));
4301 --}
4302 END IF;
4303 --}
4304 END IF; --l_ih_for_primary_wk > 0
4305 --}
4306 END IF; --l_ih_excluding_pay_period >= l_threshold_hours_county
4307 --}
4308 ELSE -- l_county_ih_logged >= l_threshold_hours_county
4309 --{
4310 -- If Information Hours Logged for the assignment is less than Threshold Hours
4311 -- configured for the County, information hours would be accounted to primary work
4312 -- County
4313 IF jd_codes_tbl_county.EXISTS(
4314 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4315 SUBSTR(l_work_jurisdiction_code,4,3) ||
4316 '0000'))
4317 THEN
4318 --{
4319 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4320 SUBSTR(l_work_jurisdiction_code,4,3) ||
4321 '0000')).hours :=
4322 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4323 SUBSTR(l_work_jurisdiction_code,4,3) ||
4324 '0000')).hours + l_jd_hours ;
4325 hr_utility.trace('EMJT COUNTY: Hours accounted for Primary WK JD County '
4326 ||to_char(l_jd_hours));
4327 --}
4328 ELSE
4329 --{
4330 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4331 SUBSTR(l_work_jurisdiction_code,4,3) ||
4332 '0000')).jurisdiction_code
4333 := SUBSTR(l_work_jurisdiction_code,1,7)||'0000';
4334 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4335 SUBSTR(l_work_jurisdiction_code,4,3) ||
4336 '0000')).hours := l_jd_hours;
4337 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4338 SUBSTR(l_work_jurisdiction_code,4,3) ||
4339 '0000')).calc_percent := l_calc_percent;
4340 hr_utility.trace('EMJT COUNTY: Primary WK JD County loaded into pl table jd_codes_tbl_county');
4341 hr_utility.trace('EMJT COUNTY: Hours accounted for Primary WK JD County '
4342 ||to_char(l_jd_hours));
4343 --}
4344 END IF;
4345 --}
4346 END IF;
4347 --}
4348 -- END IF;--l_county_withheld > 0 /*Bug#6869097*/
4349 --}
4350 ELSE
4351 -- If Threshold Hours not logged for the County load Jurisdiction into jd_codes_tbl_state
4352 --
4353 --{
4354 jd_codes_tbl_county(l_counter).jurisdiction_code := l_jurisdiction;
4355 jd_codes_tbl_county(l_counter).hours := l_jd_hours;
4356 jd_codes_tbl_county(l_counter).calc_percent := l_calc_percent;
4357 hr_utility.trace('EMJT COUNTY: Work JD State loaded into jd_codes_tbl_state =>'
4358 ||l_jurisdiction);
4359 hr_utility.trace('EMJT COUNTY: Hours accounted for Primary WK JD State '
4360 ||to_char(l_ih_for_primary_wk));
4361 --}
4362 END IF;--l_threshold_hours_county > 0
4363 --}
4364 END IF; --SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2)
4365 --}
4366 END IF; --l_calc_percent = 'N'
4367 --}
4368 hr_utility.trace('EMJT COUNTY: =======================================================================');
4369 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county.COUNT -> '|| jd_codes_tbl_county.COUNT);
4370 /* hr_utility.trace('EMJT : jd_codes_tbl_county('||to_char(l_counter)||').hours ->'
4371 || jd_codes_tbl_county(l_counter).hours);
4372 hr_utility.trace('EMJT : jd_codes_tbl_county('||to_char(l_counter)||').jurisdiction_code->'
4373 || jd_codes_tbl_county(l_counter).jurisdiction_code);
4374 hr_utility.trace('EMJT : jd_codes_tbl_county('||to_char(l_counter)||').percentage ->'
4375 || jd_codes_tbl_county(l_counter).percentage);
4376 hr_utility.trace('EMJT : jd_codes_tbl_county('||to_char(l_counter)||').calc_percent ->'
4377 || jd_codes_tbl_county(l_counter).calc_percent);*/
4378 hr_utility.trace('EMJT COUNTY: ========================================================================');
4379 hr_utility.trace('EMJT COUNTY: Setting the Index counter to fetch next JD County ');
4380 l_counter := jd_codes_tbl_county_stg.NEXT(l_counter);
4381 hr_utility.trace('EMJT COUNTY: Next Index Counter Value '||to_char(l_counter));
4382 END LOOP;
4383 --Done with populating the jd_codes_tbl_county
4384 hr_utility.trace('EMJT COUNTY: PL Table jd_codes_tbl_county_stg processed Successfully');
4385 hr_utility.trace('EMJT COUNTY: PL Table jd_codes_tbl_county populated with required County details');
4386
4387
4388 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4389 l_counter := NULL;
4390 l_counter := jd_codes_tbl_county.FIRST;
4391 l_last_jd_index_value := jd_codes_tbl_county.LAST;
4392 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county.FIRST->' || jd_codes_tbl_county.FIRST);
4393 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county.LAST->' || jd_codes_tbl_county.LAST);
4394
4395 WHILE l_counter IS NOT NULL LOOP
4396 /* hr_utility.trace('EMJT: =========================================================');
4397 hr_utility.trace('EMJT: jd_codes_tbl_county('||to_char(l_counter)||').hours ->'
4398 || jd_codes_tbl_county(l_counter).hours);
4399 hr_utility.trace('EMJT: jd_codes_tbl_county('||to_char(l_counter)||').jurisdiction_code->'
4400 || jd_codes_tbl_county(l_counter).jurisdiction_code);
4401 hr_utility.trace('EMJT: jd_codes_tbl_county('||to_char(l_counter)||').percentage ->'
4402 || jd_codes_tbl_county(l_counter).percentage);
4403 hr_utility.trace('EMJT: =========================================================');*/
4404 l_total_county_hours := l_total_county_hours + NVL(jd_codes_tbl_county(l_counter).hours,0);
4405 l_counter := jd_codes_tbl_county.NEXT(l_counter);
4406 END LOOP;
4407
4408 hr_utility.trace('EMJT COUNTY: l_total_county_hours ->' || to_char(l_total_county_hours) );
4409
4410 IF l_total_county_hours <= l_scheduled_work_hours THEN
4411 l_denominator := l_scheduled_work_hours;
4412 ELSIF l_total_county_hours > l_scheduled_work_hours THEN
4413 l_denominator := l_total_county_hours;
4414 END IF;
4415
4416 l_counter := NULL;
4417 l_counter := jd_codes_tbl_county.FIRST;
4418 l_last_jd_index_value := jd_codes_tbl_county.LAST;
4419 WHILE l_counter IS NOT NULL LOOP
4420 l_jd_hours := jd_codes_tbl_county(l_counter).hours ;
4421 jd_codes_tbl_county(l_counter).percentage :=
4422 ROUND((l_jd_hours/l_denominator) * 100);
4423 /* hr_utility.trace('EMJT: =========================================================');
4424 hr_utility.trace('EMJT: jd_codes_tbl_county('||to_char(l_counter)||').hours ->'
4425 || jd_codes_tbl_county(l_counter).hours);
4426 hr_utility.trace('EMJT: jd_codes_tbl_county('||to_char(l_counter)||').jurisdiction_code->'
4427 || jd_codes_tbl_county(l_counter).jurisdiction_code);
4428 hr_utility.trace('EMJT: jd_codes_tbl_county('||to_char(l_counter)||').percentage ->'
4429 || jd_codes_tbl_county(l_counter).percentage);
4430 hr_utility.trace('EMJT: =========================================================');*/
4431 l_total_county_percent := l_total_county_percent
4432 + jd_codes_tbl_county(l_counter).percentage;
4433 l_counter := jd_codes_tbl_county.NEXT(l_counter);
4434 END LOOP; --WHILE l_counter
4435
4436 l_extra_percent := 0;
4437 IF l_total_county_percent > 100 THEN
4438 --{
4439 l_extra_percent := l_total_county_percent - 100;
4440 IF l_primary_work_jd_flag = 'Y' THEN
4441 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||
4442 SUBSTR(l_work_jurisdiction_code,4,3)||'0000')).percentage
4443 := jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||
4444 SUBSTR(l_work_jurisdiction_code,4,3)||'0000')).percentage
4445 - l_extra_percent;
4446 ELSE
4447 jd_codes_tbl_county(l_last_jd_index_value).percentage
4448 := jd_codes_tbl_county(l_last_jd_index_value).percentage
4449 - l_extra_percent;
4450 END IF;
4451 --}
4452 ELSIF l_total_county_percent < 100 THEN
4453 --{
4454 l_extra_percent := 100 - l_total_county_percent;
4455 IF l_primary_work_jd_flag = 'Y' THEN
4456 jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||
4457 SUBSTR(l_work_jurisdiction_code,4,3)||'0000')).percentage
4458 := jd_codes_tbl_county(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2)||
4459 SUBSTR(l_work_jurisdiction_code,4,3)||'0000')).percentage
4460 + l_extra_percent;
4461 ELSE
4462 jd_codes_tbl_county(l_last_jd_index_value).percentage
4463 := jd_codes_tbl_county(l_last_jd_index_value).percentage
4464 + l_extra_percent;
4465 END IF;
4466 --}
4467 END IF; --l_total_county_percent > 100
4468
4469
4470 l_counter := NULL;
4471 l_counter := jd_codes_tbl_county.FIRST;
4472 -- l_last_jd_index_value := jd_codes_tbl_county.LAST;
4473 -- hr_utility.trace('EMJT: jd_codes_tbl_county.FIRST->' || jd_codes_tbl_county.FIRST);
4474 -- hr_utility.trace('EMJT: jd_codes_tbl_county.LAST->' || jd_codes_tbl_county.LAST);
4475
4476 WHILE l_counter IS NOT NULL LOOP
4477 hr_utility.trace('EMJT COUNTY: Final County Table ');
4478 hr_utility.trace('EMJT COUNTY: =========================================================');
4479 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county('||to_char(l_counter)||').hours ->'
4480 || jd_codes_tbl_county(l_counter).hours);
4481 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county('||to_char(l_counter)||').jurisdiction_code->'
4482 || jd_codes_tbl_county(l_counter).jurisdiction_code);
4483 hr_utility.trace('EMJT COUNTY: jd_codes_tbl_county('||to_char(l_counter)||').percentage ->'
4484 || jd_codes_tbl_county(l_counter).percentage);
4485 hr_utility.trace('EMJT COUNTY: =========================================================');
4486 -- l_total_county_hours := l_total_county_hours + jd_codes_tbl_county(l_counter).hours;
4487 l_counter := jd_codes_tbl_county.NEXT(l_counter);
4488 END LOOP;
4489
4490 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4491
4492 hr_utility.trace('EMJT CITY :===========================================================');
4493 hr_utility.trace('EMJT CITY: Main City Processing');
4494
4495 --Starting processing the city, populating jurisdiction_codes_tbl.
4496 l_counter := NULL;
4497 --
4498 --This part of the code populates the MAIN COUNTY PL TABLE from the staging city pl table.
4499 --INTO jurisdiction_codes_tbl
4500 --FROM jd_codes_tbl_city_stg
4501 -- l_primary_work_jd_index_value
4502 l_counter := jurisdiction_codes_tbl_stg.FIRST;
4503 l_last_jd_index_value := jurisdiction_codes_tbl_stg.LAST;
4504 hr_utility.trace('EMJT CITY: First JD Code '||to_char(l_counter));
4505 hr_utility.trace('EMJT CITY: Last JD Code '||to_char(l_last_jd_index_value));
4506
4507 WHILE l_counter IS NOT NULL LOOP
4508 --{
4509 l_jurisdiction := jurisdiction_codes_tbl_stg(l_counter).jurisdiction_code ;
4510 l_jd_hours := jurisdiction_codes_tbl_stg(l_counter).hours ;
4511 hr_utility.trace('EMJT CITY: l_counter =>'|| to_char(l_counter));
4512 hr_utility.trace('EMJT CITY: Jurisdiction Code =>'|| l_jurisdiction);
4513 hr_utility.trace('EMJT CITY: l_jd_hours =>'|| to_char(l_jd_hours));
4514 hr_utility.trace('EMJT CITY: l_work_jurisdiction_code '|| l_work_jurisdiction_code);
4515
4516 IF SUBSTR(l_jurisdiction,1,2) ||
4517 SUBSTR(l_jurisdiction,4,3) ||
4518 SUBSTR(l_jurisdiction,8,4) =
4519 SUBSTR(l_work_jurisdiction_code,1,2) ||
4520 SUBSTR(l_work_jurisdiction_code,4,3) ||
4521 SUBSTR(l_work_jurisdiction_code,8,4)
4522 THEN
4523 --{
4524
4525 IF jd_codes_tbl_city_stg.EXISTS(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4526 SUBSTR(l_jurisdiction,4,3) ||
4527 SUBSTR(l_jurisdiction,8,4) ))
4528 THEN
4529 --{
4530 hr_utility.trace('EMJT CITY: Primary WK JD already in jd_codes_tbl_city_stg');
4531 hr_utility.trace('EMJT CITY: Add This JD Hours to Primary Work Location');
4532 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4533 SUBSTR(l_jurisdiction,4,3) ||
4534 SUBSTR(l_jurisdiction,8,4))).hours
4535 := jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4536 SUBSTR(l_jurisdiction,4,3) ||
4537 SUBSTR(l_jurisdiction,8,4) )
4538 ).hours + l_jd_hours;
4539 --}
4540 ELSE
4541 --{
4542 hr_utility.trace('EMJT CITY: Primary work jurisidction loaded in jd_codes_tbl_city_stg');
4543 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4544 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4545 jd_codes_tbl_city_stg(l_counter).jd_type :=
4546 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4547 --}
4548 END IF;
4549 --}
4550 ELSE --SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2)
4551 --{
4552 hr_utility.trace('EMJT CITY: l_counter not work_jd '|| l_work_jurisdiction_code);
4553
4554 IF l_jd_hours = 0 AND jurisdiction_codes_tbl_stg(l_counter).jd_type = 'TG' THEN
4555 --{
4556 IF jd_codes_tbl_city_stg.EXISTS(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4557 SUBSTR(l_jurisdiction,4,3) ||
4558 SUBSTR(l_jurisdiction,8,4) ))
4559 THEN
4560 --{
4561 hr_utility.trace('EMJT CITY: This is a Tagged Jurisdiction which is already loaded');
4562 --}
4563 ELSE
4564 --{
4565 hr_utility.trace('EMJT CITY: Load Tagged Jurisdiction into jd_codes_tbl_city_stg');
4566 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4567 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4568 jd_codes_tbl_city_stg(l_counter).jd_type :=
4569 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4570 --}
4571 END IF;
4572 --}
4573 ELSE --l_jd_hours = 0 and jd_codes_tbl_city_stg(l_counter).jd_type = 'TG'
4574 --Fetch City level threshold
4575 hr_utility.trace('EMJT CITY: Fetch Threshold Hours for City');
4576 l_threshold_hours_city := get_jd_level_threshold(p_tax_unit_id
4577 ,l_jurisdiction
4578 ,'CITY');
4579 hr_utility.trace('EMJT CITY: Threshold Hours for City '||to_char(l_threshold_hours_city));
4580 IF l_threshold_hours_city > 0 THEN
4581 --{
4582 -- Fetch the city level tax balance accrued for the person
4583 -- If Tax balance found then tax the city as per hours logged for the city
4584 -- otherwise hours will be accounted to primary work city
4585 hr_utility.trace('EMJT CITY: Fetch City level Tax Withheld for Assignment');
4586
4587
4588 /* Bug#6869097:The following code checks whether city tax is withheld already
4589 for the assignment and if it finds city tax is withheld already it assumes that
4590 the assignemnt has crossed the threshold limit already and inserts the
4591 current record. Commented the following code so that it can go on with
4592 threshold checking irrespective of city tax Withheld balance.
4593 */
4594
4595 /* l_city_withheld :=
4596 hr_us_ff_udf1.get_jd_tax_balance(p_threshold_basis => l_threshold_basis
4597 ,p_assignment_action_id=> p_assignment_action_id
4598 ,p_jurisdiction_code => l_jurisdiction
4599 ,p_tax_unit_id => p_tax_unit_id
4600 ,p_jurisdiction_level => 'CITY'
4601 ,p_effective_date => p_date_paid
4602 ,p_assignment_id => p_assignment_id);
4603 hr_utility.trace('EMJT CITY: City level Tax Withheld for Assignment '||
4604 to_char(l_city_withheld));
4605
4606 --=============================================================================
4607 IF l_city_withheld = 0 THEN
4608
4609 l_county_city_withheld :=
4610 hr_us_ff_udf1.get_jd_tax_balance(p_threshold_basis => l_threshold_basis
4611 ,p_assignment_action_id=> p_assignment_action_id
4612 ,p_jurisdiction_code => l_jurisdiction
4613 ,p_tax_unit_id => p_tax_unit_id
4614 ,p_jurisdiction_level => 'COUNTY'
4615 ,p_effective_date => p_date_paid
4616 ,p_assignment_id => p_assignment_id);
4617 hr_utility.trace('EMJT: l_county_city_withheld -> '||to_char(l_county_city_withheld));
4618
4619 IF l_county_city_withheld = 0 THEN
4620
4621 l_sit_city_withheld :=
4622 hr_us_ff_udf1.get_jd_tax_balance(p_threshold_basis => l_threshold_basis
4623 ,p_assignment_action_id => p_assignment_action_id
4624 ,p_jurisdiction_code => l_jurisdiction
4625 ,p_tax_unit_id => p_tax_unit_id
4626 ,p_jurisdiction_level => 'STATE'
4627 ,p_effective_date => p_date_paid
4628 ,p_assignment_id => p_assignment_id);
4629 hr_utility.trace('EMJT: l_sit_city_withheld -> '||to_char(l_sit_city_withheld));
4630 END IF;
4631
4632 END IF;
4633
4634
4635 --=============================================================================
4636 IF l_city_withheld > 0 THEN
4637 --{
4638 hr_utility.trace('EMJT CITY: As City level Tax is Withheld previously ');
4639 hr_utility.trace('EMJT CITY: NO THRESHOLD Validation required for the City');
4640 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4641 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4642 jd_codes_tbl_city_stg(l_counter).jd_type :=
4643 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4644 --}
4645 ELSIF l_city_withheld = 0 AND l_county_city_withheld > 0 THEN
4646 --{
4647 hr_utility.trace('EMJT CITY: l_city_withheld = 0 AND l_county_city_withheld > 0 ');
4648 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4649 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4650 jd_codes_tbl_city_stg(l_counter).jd_type :=
4651 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4652 --}
4653 ELSIF l_city_withheld = 0 AND l_county_city_withheld = 0 AND l_sit_city_withheld > 0 THEN
4654 --{
4655 hr_utility.trace('EMJT CITY: l_city_withheld = 0 l_county_city_withheld = 0 l_sit_city_withheld > 0');
4656 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4657 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4658 jd_codes_tbl_city_stg(l_counter).jd_type :=
4659 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4660 --}
4661 ELSE --l_city_withheld > 0 */
4662 --{
4663
4664 /*Bug#6869097:Changes end here*/
4665
4666 -- Fetch Information Hours logged for the person depending on the payroll effective date
4667 -- call to get_th_assignment for the CITY
4668 hr_utility.trace('EMJT CITY: Fetch Information Hours Logged for the CITY JD');
4669 l_city_ih_logged
4670 := hr_us_ff_udf1.get_person_it_hours(p_person_id => l_person_id
4671 ,p_assignment_id => p_assignment_id
4672 ,p_jurisdiction_code => l_jurisdiction
4673 ,p_jd_level => 11
4674 ,p_threshold_basis => l_threshold_basis
4675 ,p_effective_date => l_max_end_date --p_date_paid
4676 ,p_end_date => l_end_date);
4677 hr_utility.trace('EMJT CITY: Information Hours logged for the assignment '
4678 ||to_char(l_city_ih_logged));
4679 IF l_city_ih_logged > l_threshold_hours_city THEN
4680 --{
4681 hr_utility.trace('EMJT CITY: City Information Hours logged > Threshold_Hours_City');
4682 l_ih_excluding_pay_period := l_city_ih_logged
4683 - l_jd_hours;
4684 hr_utility.trace('EMJT CITY: City Information Hours till last Pay period'
4685 ||to_char(l_ih_excluding_pay_period));
4686 -- if information hours processed till last payroll run is greater than the
4687 -- threshold limit configured at the City level then hours logged for the city
4688 -- would be accounted for that city
4689 --
4690 IF l_ih_excluding_pay_period >= l_threshold_hours_city THEN
4691 --{
4692 hr_utility.trace('EMJT CITY: Information Hours excluding Current Pay Period');
4693 hr_utility.trace('EMJT CITY: >= Threshold Hours configured for the city');
4694 --
4695 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4696 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4697 jd_codes_tbl_city_stg(l_counter).jd_type :=
4698 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4699 hr_utility.trace('EMJT CITY: Information Hours accounted to logged JD '||l_jurisdiction);
4700 --}
4701 ELSE --l_ih_excluding_pay_period >= l_threshold_hours_city
4702 --{
4703 -- if information hours processed till last payroll run is less than the
4704 -- threshold limit configured at the city level
4705 -- Calculate information hours that is exceeds threshold limit
4706 l_ih_above_threshold := l_city_ih_logged - l_threshold_hours_city;
4707 hr_utility.trace('EMJT CITY: Information Hours above City Threshold '
4708 ||to_char(l_ih_above_threshold));
4709 -- Calculate information hours that would be accounted to primary work location
4710 -- due to threshold
4711 l_ih_for_primary_wk :=
4712 jurisdiction_codes_tbl_stg(TO_NUMBER(SUBSTR(l_jurisdiction,1,2) ||
4713 SUBSTR(l_jurisdiction,4,3) ||
4714 SUBSTR(l_jurisdiction,8,4) )
4715 ).hours - l_ih_above_threshold;
4716 hr_utility.trace('EMJT CITY: Information Hours to be logged for Primar Work '
4717 ||to_char(l_ih_for_primary_wk));
4718 -- if information hours logged for the city is more than threshold
4719 -- configured for the city, only exceeded hours would be accounted for that
4720 -- city
4721 IF l_ih_above_threshold > 0 THEN
4722 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4723 jd_codes_tbl_city_stg(l_counter).hours := l_ih_above_threshold ;
4724 jd_codes_tbl_city_stg(l_counter).jd_type :=
4725 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4726 hr_utility.trace('EMJT CITY: As Information Hours above Threshold ');
4727 hr_utility.trace('EMJT CITY: Log Hours '||to_char(l_ih_for_primary_wk)
4728 ||' to JD '||l_jurisdiction);
4729 END IF;
4730 -- When Total information hours logged for the person is above threshold
4731 -- but there are some information hours need to accounted to primary
4732 -- work location due to threshold limit
4733 -- This is determine if part of information hours entered for the processing pay
4734 -- period need to be accounted to primary work location due to
4735 --
4736 IF l_ih_for_primary_wk > 0 THEN
4737 --{
4738 IF jd_codes_tbl_city_stg.EXISTS(
4739 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4740 SUBSTR(l_work_jurisdiction_code,4,3) ||
4741 SUBSTR(l_work_jurisdiction_code,8,4) ) )
4742 THEN
4743 --{
4744 hr_utility.trace('EMJT CITY: Hours Added to Primary Work Jurisdiction '
4745 ||to_char(l_ih_for_primary_wk));
4746 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4747 SUBSTR(l_work_jurisdiction_code,4,3) ||
4748 SUBSTR(l_work_jurisdiction_code,8,4) )
4749 ).hours :=
4750 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4751 SUBSTR(l_work_jurisdiction_code,4,3) ||
4752 SUBSTR(l_work_jurisdiction_code,8,4) )
4753 ).hours + l_ih_for_primary_wk ;
4754 --}
4755 ELSE
4756 --{
4757 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4758 SUBSTR(l_work_jurisdiction_code,4,3) ||
4759 SUBSTR(l_work_jurisdiction_code,8,4) )
4760 ).jurisdiction_code
4761 := l_work_jurisdiction_code;
4762 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4763 SUBSTR(l_work_jurisdiction_code,4,3) ||
4764 SUBSTR(l_work_jurisdiction_code,8,4) )).hours
4765 := l_ih_for_primary_wk;
4766 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4767 SUBSTR(l_work_jurisdiction_code,4,3) ||
4768 SUBSTR(l_work_jurisdiction_code,8,4) )).jd_type
4769 := jurisdiction_codes_tbl_stg(l_counter).jd_type;
4770 hr_utility.trace('EMJT CITY: Hours logged for Primary Work Jurisdiction '
4771 ||to_char(l_ih_for_primary_wk));
4772
4773 --}
4774 END IF;
4775 --}
4776 END IF; --l_ih_for_primary_wk > 0
4777 --}
4778 END IF;
4779 --}
4780 ELSE --l_ih_excluding_pay_period >= l_threshold_hours_state
4781 --{
4782 -- If Information Hours Logged for the assignment is less than Threshold Hours
4783 -- configured for the City, information hours would be accounted to primary work
4784 -- State
4785 hr_utility.trace('EMJT CITY : l_work_jurisdiction_code ->'|| l_work_jurisdiction_code);
4786 hr_utility.trace('EMJT CITY : l_counter ->'|| l_counter);
4787 IF jd_codes_tbl_city_stg.EXISTS(
4788 TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4789 SUBSTR(l_work_jurisdiction_code,4,3) ||
4790 SUBSTR(l_work_jurisdiction_code,8,4) ))
4791 THEN
4792 --{
4793 hr_utility.trace('EMJT CITY : IN IF l_counter ->'|| l_counter);
4794 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4795 SUBSTR(l_work_jurisdiction_code,4,3) ||
4796 SUBSTR(l_work_jurisdiction_code,8,4) )).hours :=
4797 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4798 SUBSTR(l_work_jurisdiction_code,4,3) ||
4799 SUBSTR(l_work_jurisdiction_code,8,4) )).hours + l_jd_hours ;
4800 hr_utility.trace('EMJT CITY: Hours accounted for Primary WK JD State '
4801 ||to_char(l_jd_hours));
4802 --}
4803 ELSE
4804 --{
4805 hr_utility.trace('EMJT CITY : IN ELSE l_counter ->'|| l_counter);
4806 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4807 SUBSTR(l_work_jurisdiction_code,4,3) ||
4808 SUBSTR(l_work_jurisdiction_code,8,4) )
4809 ).jurisdiction_code
4810 := l_work_jurisdiction_code;
4811 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4812 SUBSTR(l_work_jurisdiction_code,4,3) ||
4813 SUBSTR(l_work_jurisdiction_code,8,4) )).hours
4814 := l_jd_hours;
4815 jd_codes_tbl_city_stg(TO_NUMBER(SUBSTR(l_work_jurisdiction_code,1,2) ||
4816 SUBSTR(l_work_jurisdiction_code,4,3) ||
4817 SUBSTR(l_work_jurisdiction_code,8,4) )).jd_type
4818 := 'WK';
4819 hr_utility.trace('EMJT CITY: Primary WK JD City loaded into jd_codes_tbl_city_stg');
4820 hr_utility.trace('EMJT CITY: Hours accounted for Primary WK JD City '
4821 ||to_char(l_jd_hours));
4822 --}
4823 END IF;
4824 --}
4825 END IF; --l_city_ih_logged > l_threshold_hours_city
4826 --}
4827 -- END IF;--l_city_withheld > 0 /*6869097*/
4828 --}
4829 ELSE
4830 --{
4831 -- If Threshold Hours not logged for a City load Jurisdiction into jd_codes_tbl_city_stg
4832 --
4833 jd_codes_tbl_city_stg(l_counter).jurisdiction_code := l_jurisdiction;
4834 jd_codes_tbl_city_stg(l_counter).hours := l_jd_hours;
4835 jd_codes_tbl_city_stg(l_counter).jd_type :=
4836 jurisdiction_codes_tbl_stg(l_counter).jd_type;
4837 hr_utility.trace('EMJT CITY: Work City JD loaded into jd_codes_tbl_city_stg =>'
4838 ||l_jurisdiction);
4839 --}
4840 END IF;--l_threshold_hours_city > 0
4841 --}
4842 END IF; --l_jd_hours = 0 and jd_codes_tbl_city_stg(l_counter).jd_type = 'TG'
4843 --}
4844 END IF; --SUBSTR(l_jurisdiction,1,2) = SUBSTR(l_work_jurisdiction_code,1,2)
4845 --}
4846 hr_utility.trace('EMJT CITY: Setting the Index counter to fetch next JD City ');
4847 l_counter := jurisdiction_codes_tbl_stg.NEXT(l_counter);
4848 hr_utility.trace('EMJT CITY: Next Index Counter Value '||to_char(l_counter));
4849
4850 END LOOP;
4851 --Done with populating the jurisdiction_codes_tbl
4852 hr_utility.trace('EMJT CITY: PL Table jd_codes_tbl_city_stg processed Successfully');
4853
4854 --=============================================================================================
4855
4856 hr_utility.trace('EMJT CITY: Total Informational Time Hours entered -> '||to_char(l_total_hours));
4857 IF l_total_hours <= l_scheduled_work_hours THEN
4858 l_denominator := l_scheduled_work_hours;
4859 ELSIF l_total_hours > l_scheduled_work_hours THEN
4860 l_denominator := l_total_hours;
4861 END IF;
4862
4863 l_counter := NULL;
4864 l_counter := jd_codes_tbl_city_stg.FIRST;
4865 l_last_jd_index_value := jd_codes_tbl_city_stg.LAST;
4866 WHILE l_counter IS NOT NULL LOOP
4867 l_jd_hours := jd_codes_tbl_city_stg(l_counter).hours ;
4868 jd_codes_tbl_city_stg(l_counter).percentage :=
4869 ROUND((l_jd_hours/l_denominator) * 100);
4870 hr_utility.trace('EMJT CITY: =========================================================');
4871 hr_utility.trace('EMJT CITY: jd_codes_tbl_city_stg('||to_char(l_counter)||').hours ->'
4872 || jd_codes_tbl_city_stg(l_counter).hours);
4873 hr_utility.trace('EMJT CITY: jd_codes_tbl_city_stg('||to_char(l_counter)||').tg_hours ->'
4874 || jd_codes_tbl_city_stg(l_counter).tg_hours);
4875 hr_utility.trace('EMJT CITY: jd_codes_tbl_city_stg('||to_char(l_counter)||').jurisdiction_code->'
4876 || jd_codes_tbl_city_stg(l_counter).jurisdiction_code);
4877 hr_utility.trace('EMJT CITY: jd_codes_tbl_city_stg('||to_char(l_counter)||').percentage ->'
4878 || jd_codes_tbl_city_stg(l_counter).percentage);
4879 hr_utility.trace('EMJT CITY: jd_codes_tbl_city_stg('||to_char(l_counter)||').jd_type ->'
4880 || jd_codes_tbl_city_stg(l_counter).jd_type);
4881 hr_utility.trace('EMJT CITY: =========================================================');
4882 l_total_percent := l_total_percent
4883 + jd_codes_tbl_city_stg(l_counter).percentage;
4884 l_counter := jd_codes_tbl_city_stg.NEXT(l_counter);
4885 END LOOP; --WHILE l_counter
4886
4887
4888 IF l_total_percent > 100 THEN
4889 --{
4890 l_extra_percent := l_total_percent - 100;
4891 IF l_primary_work_jd_flag = 'Y' THEN
4892 jd_codes_tbl_city_stg(l_primary_work_jd_index_value).percentage
4893 := jd_codes_tbl_city_stg(l_primary_work_jd_index_value).percentage
4894 - l_extra_percent;
4895 ELSE
4896 jd_codes_tbl_city_stg(l_last_jd_index_value).percentage
4897 := jd_codes_tbl_city_stg(l_last_jd_index_value).percentage
4898 - l_extra_percent;
4899 END IF;
4900 --}
4901 ELSIF l_total_percent < 100 THEN
4902 --{
4903 l_extra_percent := 100 - l_total_percent;
4904 IF l_primary_work_jd_flag = 'Y' THEN
4905 jd_codes_tbl_city_stg(l_primary_work_jd_index_value).percentage
4906 := jd_codes_tbl_city_stg(l_primary_work_jd_index_value).percentage
4907 + l_extra_percent;
4908 ELSE
4909 jd_codes_tbl_city_stg(l_last_jd_index_value).percentage
4910 := jd_codes_tbl_city_stg(l_last_jd_index_value).percentage
4911 + l_extra_percent;
4912 END IF;
4913 --}
4914 END IF; --l_total_percent > 100
4915
4916 --========================================================================
4917 OPEN csr_person_details(p_assignment_id, p_date_paid);
4918 FETCH csr_person_details INTO l_full_name, l_assignment_number;
4919 CLOSE csr_person_details;
4920 --========================================================================
4921 hr_utility.trace('EMJT Full Name -> '|| l_full_name );
4922 hr_utility.trace('EMJT Assignment Number -> '|| l_assignment_number );
4923 --
4924 --Populate jurisdiction_codes_tbl
4925 --
4926 l_counter := jd_codes_tbl_city_stg.FIRST;
4927 WHILE l_counter IS NOT NULL LOOP
4928 jurisdiction_codes_tbl(l_counter).jurisdiction_code
4929 := jd_codes_tbl_city_stg(l_counter).jurisdiction_code;
4930 jurisdiction_codes_tbl(l_counter).percentage
4931 := jd_codes_tbl_city_stg(l_counter).percentage;
4932 jurisdiction_codes_tbl(l_counter).jd_type
4933 := jd_codes_tbl_city_stg(l_counter).jd_type;
4934 jurisdiction_codes_tbl(l_counter).hours
4935 := jd_codes_tbl_city_stg(l_counter).hours;
4936 jurisdiction_codes_tbl(l_counter).wages_to_accrue_flag
4937 := jd_codes_tbl_city_stg(l_counter).wages_to_accrue_flag;
4938 jurisdiction_codes_tbl(l_counter).tg_hours
4939 := jd_codes_tbl_city_stg(l_counter).tg_hours;
4940 jurisdiction_codes_tbl(l_counter).other_pay_hours
4941 := jd_codes_tbl_city_stg(l_counter).other_pay_hours;
4942 hr_utility.trace('EMJT CITY: ===================================================');
4943 hr_utility.trace('EMJT CITY: jurisdiction_codes_tbl('||to_char(l_counter)||').jurisdiction_code->'
4944 || jurisdiction_codes_tbl(l_counter).jurisdiction_code);
4945 hr_utility.trace('EMJT CITY: jurisdiction_codes_tbl('||to_char(l_counter)||').hours ->'
4946 || jurisdiction_codes_tbl(l_counter).hours);
4947 hr_utility.trace('EMJT CITY: jurisdiction_codes_tbl('||to_char(l_counter)||').tg_hours ->'
4948 || jurisdiction_codes_tbl(l_counter).tg_hours);
4949 hr_utility.trace('EMJT CITY: jurisdiction_codes_tbl('||to_char(l_counter)||').percentage ->'
4950 || jurisdiction_codes_tbl(l_counter).percentage);
4951 hr_utility.trace('EMJT CITY: jurisdiction_codes_tbl('||to_char(l_counter)||').jd_type ->'
4952 || jurisdiction_codes_tbl(l_counter).jd_type);
4953 hr_utility.trace('EMJT CITY: ===================================================');
4954 --================================================================================================
4955 l_spelled_jd_code :=
4956 pay_us_employee_payslip_web.get_full_jurisdiction_name(
4957 jd_codes_tbl_city_stg(l_counter).jurisdiction_code);
4958 hr_utility.trace('EMJT spelled jd code -> '|| l_spelled_jd_code );
4959
4960 -- Fix for bug#9546119
4961 -- pay_core_utils.push_message(801,'PAY_US_EMJT_EMPLOYEE_INFO','P');
4962 pay_core_utils.push_message(801,'PAY_US_EMJT_EMPLOYEE_INFO','I');
4963 pay_core_utils.push_token('EMPLOYEE_NAME',SUBSTR(l_full_name,1,50));
4964 pay_core_utils.push_token('ASSIGNMENT_NUMBER',SUBSTR(l_assignment_number,1,50));
4965 pay_core_utils.push_token('JURISDICTION_NAME',SUBSTR(l_spelled_jd_code,1,50));
4966 pay_core_utils.push_token('HOURS',SUBSTR(jd_codes_tbl_city_stg(l_counter).hours,1,50));
4967 pay_core_utils.push_token('PERCENTAGE',SUBSTR(jd_codes_tbl_city_stg(l_counter).percentage,1,50));
4968 --================================================================================================
4969 l_counter := jd_codes_tbl_city_stg.NEXT(l_counter);
4970 END LOOP; --WHILE l_counter
4971 --}
4972 END IF; --p_initialize = 'Y'
4973 RETURN ('0');
4974 EXCEPTION
4975 WHEN NO_DATA_FOUND THEN
4976 hr_utility.trace('Exception raised NO_DATA_FOUND in '||'get_it_work_jurisdictions');
4977 p_jurisdiction_code := 'NULL';
4978 p_percentage := 0;
4979 RETURN ('0');
4980 WHEN TOO_MANY_JURISDICTIONS THEN
4981 hr_utility.set_message(801, 'PAY_75242_PAY_TOO_MANY_JD');
4982 hr_utility.set_message_token('MAX_WORK_JDS', l_max_jurisdictions);
4983 hr_utility.raise_error;
4984 RAISE;
4985 WHEN OTHERS THEN
4986 hr_utility.trace('Exception raised OTHERS in '||'get_it_work_jurisdictions');
4987 hr_utility.trace('Mesg: '||substr(sqlerrm,1,45));
4988 p_jurisdiction_code := 'NULL';
4989 p_percentage := 0;
4990 RETURN ('0');
4991 -- End of Function get_it_work_jurisdictions
4992 --}
4993 END get_it_work_jurisdictions;
4994
4995 --Function to get balance value
4996 FUNCTION get_jd_tax_balance(p_threshold_basis IN VARCHAR2
4997 ,p_assignment_action_id IN NUMBER
4998 ,p_jurisdiction_code IN VARCHAR2
4999 ,p_tax_unit_id IN NUMBER
5000 ,p_jurisdiction_level IN VARCHAR2
5001 ,p_effective_date IN DATE
5002 ,p_assignment_id IN NUMBER
5003 ) RETURN NUMBER AS
5004
5005 l_value NUMBER;
5006
5007 CURSOR csr_defined_balance_id(p_balance_name IN VARCHAR2
5008 ,p_database_item_suffix IN VARCHAR2) IS
5009 SELECT pdb.defined_balance_id, pbt.balance_type_id
5010 FROM pay_defined_balances pdb,
5011 pay_balance_types pbt,
5012 pay_balance_dimensions pbd
5013 WHERE pdb.balance_dimension_id = pbd.balance_dimension_id
5014 AND pdb.balance_type_id = pbt.balance_type_id
5015 AND pbt.balance_name = p_balance_name
5016 AND pbd.database_item_suffix = p_database_item_suffix
5017 AND pdb.legislation_code = 'US';
5018
5019 l_defined_balance_id pay_defined_balances.defined_balance_id%TYPE;
5020 l_balance_type_id pay_balance_types.balance_type_id%TYPE;
5021 l_state_flag VARCHAR2(1);
5022 l_state_tax_flag VARCHAR2(1);
5023 l_county_tax_flag VARCHAR2(1);
5024 l_city_tax_flag VARCHAR2(1);
5025
5026 l_jurisdiction_level NUMBER;
5027
5028 BEGIN
5029 hr_utility.trace('EMJT: ================================================================');
5030 hr_utility.trace('EMJT: In get_jd_tax_balance');
5031 hr_utility.trace('EMJT: p_threshold_basis -> '||p_threshold_basis);
5032 hr_utility.trace('EMJT: p_jurisdiction_level -> '||p_jurisdiction_level);
5033 hr_utility.trace('EMJT: p_jurisdiction_code -> '||p_jurisdiction_code);
5034 hr_utility.trace('EMJT: p_tax_unit_id -> '||p_tax_unit_id);
5035 hr_utility.trace('EMJT: p_assignment_action_id -> '|| p_assignment_action_id);
5036
5037 l_value := 0;
5038 l_state_tax_flag := 'N';
5039 l_county_tax_flag := 'N';
5040 l_city_tax_flag := 'N';
5041
5042 IF p_jurisdiction_level = 'STATE' THEN
5043
5044 l_state_tax_flag :=
5045 pay_get_tax_exists_pkg.get_tax_exists(p_juri_code => p_jurisdiction_code,
5046 p_date_earned => p_effective_date,
5047 p_tax_unit_id => p_tax_unit_id,
5048 p_assign_id => p_assignment_id,
5049 p_pact_id => NULL,
5050 p_type => 'SIT_WK',
5051 p_call => 'F');
5052
5053 hr_utility.trace('EMJT: l_state_tax_flag -> '|| l_state_tax_flag);
5054 ELSIF p_jurisdiction_level = 'COUNTY' THEN
5055 l_county_tax_flag :=
5056 pay_get_tax_exists_pkg.get_tax_exists(p_juri_code => p_jurisdiction_code,
5057 p_date_earned => p_effective_date,
5058 p_tax_unit_id => p_tax_unit_id,
5059 p_assign_id => p_assignment_id,
5060 p_pact_id => NULL,
5061 p_type => 'COUNTY_WK',
5062 p_call => 'F');
5063
5064 hr_utility.trace('EMJT: l_county_tax_flag -> '|| l_county_tax_flag);
5065 ELSIF p_jurisdiction_level ='CITY' THEN
5066 l_city_tax_flag :=
5067 pay_get_tax_exists_pkg.get_tax_exists(p_juri_code => p_jurisdiction_code,
5068 p_date_earned => p_effective_date,
5069 p_tax_unit_id => p_tax_unit_id,
5070 p_assign_id => p_assignment_id,
5071 p_pact_id => NULL,
5072 p_type => 'CITY_WK',
5073 p_call => 'F');
5074 hr_utility.trace('EMJT: l_city_tax_flag -> '|| l_city_tax_flag);
5075 END IF; --p_jurisdiction_level = 'STATE'
5076
5077
5078 IF l_state_tax_flag = 'Y' THEN
5079 --{
5080
5081 IF p_threshold_basis = 'YTD' THEN
5082 --{
5083 hr_utility.trace('EMJT: Getting SIT Withheld for YTD');
5084 OPEN csr_defined_balance_id('SIT Withheld','_PER_JD_GRE_YTD');
5085 hr_utility.trace('EMJT: Fetching SIT Withheld _PER_JD_GRE_YTD ');
5086 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5087 CLOSE csr_defined_balance_id;
5088
5089 hr_utility.trace('EMJT: STATE l_defined_balance_id -> '|| l_defined_balance_id);
5090 hr_utility.trace('EMJT: STATE l_balance_type_id -> '|| l_balance_type_id);
5091
5092 pay_balance_pkg.set_context('TAX_UNIT_ID',p_tax_unit_id);
5093 pay_balance_pkg.set_context('ASSIGNMENT_ACTION_ID',p_assignment_action_id);
5094 pay_balance_pkg.set_context('JURISDICTION_CODE',p_jurisdiction_code);
5095
5096 l_value := NVL(pay_balance_pkg.get_value
5097 (p_defined_balance_id => l_defined_balance_id
5098 ,p_assignment_action_id => p_assignment_action_id)
5099 ,0);
5100
5101 IF l_value = 0 THEN
5102 --{
5103 OPEN csr_defined_balance_id('SIT Supp Withheld','_PER_JD_GRE_YTD');
5104 hr_utility.trace('EMJT: Fetching SIT Supp Withheld_PER_JD_GRE_YTD for YTD ');
5105 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5106 CLOSE csr_defined_balance_id;
5107 l_value := NVL(pay_balance_pkg.get_value
5108 (p_defined_balance_id => l_defined_balance_id
5109 ,p_assignment_action_id => p_assignment_action_id)
5110 ,0);
5111 --}
5112 END IF;
5113 --}
5114 ELSIF p_threshold_basis = 'RTD' THEN
5115 --{
5116
5117 OPEN csr_defined_balance_id('SIT Withheld','_PER_JD_GRE_RTD');
5118 hr_utility.trace('EMJT: Fetching SIT Withheld _PER_JD_GRE_RTD ');
5119 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5120 CLOSE csr_defined_balance_id;
5121
5122 pay_balance_pkg.set_context('TAX_UNIT_ID',p_tax_unit_id);
5123 pay_balance_pkg.set_context('ASSIGNMENT_ACTION_ID',p_assignment_action_id);
5124 pay_balance_pkg.set_context('JURISDICTION_CODE',p_jurisdiction_code);
5125 l_value := NVL(pay_balance_pkg.get_value
5126 (p_defined_balance_id => l_defined_balance_id
5127 ,p_assignment_action_id => p_assignment_action_id)
5128 ,0);
5129
5130 IF l_value = 0 THEN
5131 --{
5132 OPEN csr_defined_balance_id('SIT Supp Withheld','_PER_JD_GRE_RTD');
5133 hr_utility.trace('EMJT: Fetching SIT Supp Withheld_PER_JD_GRE_RTD for RTD');
5134 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5135 CLOSE csr_defined_balance_id;
5136
5137 l_value := NVL(pay_balance_pkg.get_value
5138 (p_defined_balance_id => l_defined_balance_id
5139 ,p_assignment_action_id => p_assignment_action_id)
5140 ,0);
5141 --}
5142 END IF; --l_value = 0
5143 --}
5144 END IF; --p_threshold_basis = 'YTD'
5145 --}
5146 END IF; --l_state_tax_flag = 'Y'
5147
5148
5149 IF l_county_tax_flag = 'Y' THEN
5150 --{
5151
5152 IF p_threshold_basis = 'YTD' THEN
5153 --{
5154 OPEN csr_defined_balance_id('County Withheld','_PER_JD_GRE_YTD');
5155 hr_utility.trace('EMJT: Fetching County Withheld_PER_JD_GRE_YTD ');
5156 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5157 CLOSE csr_defined_balance_id;
5158
5159 hr_utility.trace('EMJT: COUNTY l_defined_balance_id -> '|| l_defined_balance_id);
5160 hr_utility.trace('EMJT: COUNTY l_balance_type_id -> '|| l_balance_type_id);
5161
5162 pay_balance_pkg.set_context('TAX_UNIT_ID',p_tax_unit_id);
5163 pay_balance_pkg.set_context('ASSIGNMENT_ACTION_ID',p_assignment_action_id);
5164 pay_balance_pkg.set_context('JURISDICTION_CODE',p_jurisdiction_code);
5165 hr_utility.trace('EMJT: p_threshold_basis = YTD');
5166 l_value := NVL(pay_balance_pkg.get_value
5167 (p_defined_balance_id => l_defined_balance_id
5168 ,p_assignment_action_id => p_assignment_action_id)
5169 ,0);
5170
5171 --}
5172 ELSIF p_threshold_basis = 'RTD' THEN
5173 --{
5174 hr_utility.trace('EMJT COUNTY: p_threshold_basis = RTD');
5175 OPEN csr_defined_balance_id('County Withheld','_PER_JD_GRE_RTD');
5176 hr_utility.trace('EMJT: Fetching County Withheld_PER_JD_GRE_RTD ');
5177 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5178 CLOSE csr_defined_balance_id;
5179
5180 hr_utility.trace('EMJT: COUNTY l_defined_balance_id -> '|| l_defined_balance_id);
5181 hr_utility.trace('EMJT: COUNTY l_balance_type_id -> '|| l_balance_type_id);
5182
5183 pay_balance_pkg.set_context('TAX_UNIT_ID',p_tax_unit_id);
5184 pay_balance_pkg.set_context('ASSIGNMENT_ACTION_ID',p_assignment_action_id);
5185 pay_balance_pkg.set_context('JURISDICTION_CODE',p_jurisdiction_code);
5186 l_value := NVL(pay_balance_pkg.get_value
5187 (p_defined_balance_id => l_defined_balance_id
5188 ,p_assignment_action_id => p_assignment_action_id)
5189 ,0);
5190 --}
5191 END IF; --p_threshold_basis = 'YTD'
5192
5193 --}
5194 END IF; --l_county_tax_flag = 'Y'
5195
5196 IF l_city_tax_flag = 'Y' THEN
5197 --{
5198
5199 IF p_threshold_basis = 'YTD' THEN
5200 --{
5201 hr_utility.trace('EMJT CITY: p_threshold_basis = YTD');
5202 OPEN csr_defined_balance_id('City Withheld','_PER_JD_GRE_YTD');
5203 hr_utility.trace('EMJT : Fetching City Withheld_PER_JD_GRE_YTD');
5204 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5205 CLOSE csr_defined_balance_id;
5206
5207 hr_utility.trace('EMJT: CITY l_defined_balance_id -> '|| l_defined_balance_id);
5208 hr_utility.trace('EMJT: CITY l_balance_type_id -> '|| l_balance_type_id);
5209
5210 pay_balance_pkg.set_context('TAX_UNIT_ID',p_tax_unit_id);
5211 pay_balance_pkg.set_context('ASSIGNMENT_ACTION_ID',p_assignment_action_id);
5212 pay_balance_pkg.set_context('JURISDICTION_CODE',p_jurisdiction_code);
5213
5214 l_value := NVL(pay_balance_pkg.get_value
5215 (p_defined_balance_id => l_defined_balance_id
5216 ,p_assignment_action_id => p_assignment_action_id)
5217 ,0);
5218
5219 --}
5220 ELSIF p_threshold_basis = 'RTD' THEN
5221 --{
5222 hr_utility.trace('EMJT CITY : p_threshold_basis = RTD');
5223
5224 OPEN csr_defined_balance_id('City Withheld','_PER_JD_GRE_RTD');
5225 hr_utility.trace('EMJT CITY: Fetching City Withheld_PER_JD_GRE_RTD');
5226 FETCH csr_defined_balance_id INTO l_defined_balance_id,l_balance_type_id;
5227 CLOSE csr_defined_balance_id;
5228
5229 hr_utility.trace('EMJT: CITY RTD l_defined_balance_id -> '|| l_defined_balance_id);
5230 hr_utility.trace('EMJT: CITY RTD l_balance_type_id -> '|| l_balance_type_id);
5231
5232 pay_balance_pkg.set_context('TAX_UNIT_ID',p_tax_unit_id);
5233 pay_balance_pkg.set_context('ASSIGNMENT_ACTION_ID',p_assignment_action_id);
5234 pay_balance_pkg.set_context('JURISDICTION_CODE',p_jurisdiction_code);
5235
5236 l_value := NVL(pay_balance_pkg.get_value
5237 (p_defined_balance_id => l_defined_balance_id
5238 ,p_assignment_action_id => p_assignment_action_id)
5239 ,0);
5240
5241 --}
5242 END IF; --p_threshold_basis = 'YTD'
5243 --}
5244 END IF; --l_city_tax_flag = 'Y'
5245
5246 hr_utility.trace('EMJT: l_value from get_jd_tax_balance ->'|| to_char(l_value));
5247 hr_utility.trace('EMJT: ================================================================');
5248 RETURN l_value;
5249
5250 EXCEPTION
5251 WHEN OTHERS THEN
5252 hr_utility.trace('Exception handler');
5253 hr_utility.trace('SQLCODE = ' || SQLCODE);
5254 hr_utility.trace('SQLERRM = ' || SUBSTR(SQLERRM,1,80));
5255 hr_utility.trace('EMJT: Exception OTHERS in get_jd_tax_balance, returning 0');
5256 RETURN 0;
5257 END get_jd_tax_balance;
5258
5259
5260 --Function to get IT threshold hours for a given Jurisdiction
5261 FUNCTION get_jd_level_threshold(p_tax_unit_id NUMBER
5262 ,p_jurisdiction_code VARCHAR2
5263 ,p_jd_level VARCHAR2) RETURN NUMBER AS
5264
5265 --Threshold hours at state level
5266 CURSOR csr_state_rules(p_tax_unit_id IN NUMBER
5267 ,p_state_code IN VARCHAR2) IS
5268 SELECT NVL(org_information2,0)
5269 FROM hr_organization_information hoi,
5270 pay_us_states pus
5271 WHERE hoi.organization_id = p_tax_unit_id
5272 AND hoi.org_information_context = 'State Tax Rules 2'
5273 AND hoi.org_information1 = pus.state_abbrev
5274 AND pus.state_code = p_state_code;
5275
5276 --Threshold hours at Local level
5277 CURSOR csr_local_rules(p_tax_unit_id IN NUMBER
5278 ,p_jurisdiction_code IN VARCHAR2) IS
5279 SELECT NVL(org_information4,0)
5280 FROM hr_organization_information
5281 WHERE organization_id = p_tax_unit_id
5282 AND org_information_context = 'Local Tax Rules'
5283 AND org_information1 = p_jurisdiction_code;
5284
5285 l_state_threshold VARCHAR2(10);
5286 l_local_threshold VARCHAR2(10);
5287
5288 BEGIN
5289
5290 hr_utility.trace('EMJT: ================================================================');
5291 hr_utility.trace('EMJT: In get_jd_level_threshold');
5292 IF p_jd_level = 'STATE' THEN
5293 OPEN csr_state_rules(p_tax_unit_id,
5294 SUBSTR(p_jurisdiction_code,1,2));
5295 FETCH csr_state_rules INTO l_state_threshold;
5296 CLOSE csr_state_rules;
5297 hr_utility.trace('EMJT: SUBSTR(p_jurisdiction_code,1,2) -> ' || SUBSTR(p_jurisdiction_code,1,2));
5298 hr_utility.trace('EMJT: l_state_threshold from get_jd_level_threshold -> '
5299 || l_state_threshold);
5300 hr_utility.trace('EMJT: ================================================================');
5301 RETURN TO_NUMBER(l_state_threshold);
5302
5303 ELSIF p_jd_level = 'COUNTY' THEN
5304 OPEN csr_local_rules(p_tax_unit_id,
5305 substr(p_jurisdiction_code,1,7)||'0000'
5306 );
5307 FETCH csr_local_rules INTO l_local_threshold;
5308 CLOSE csr_local_rules;
5309 hr_utility.trace('EMJT: substr(p_jurisdiction_code,1,7)||''0000'' -> ' || substr(p_jurisdiction_code,1,7)||'0000');
5310 hr_utility.trace('EMJT: l_county_threshold from get_jd_level_threshold -> '
5311 || NVL(l_local_threshold,0));
5312
5313 IF NVL(l_local_threshold,0) = 0 THEN
5314 OPEN csr_state_rules(p_tax_unit_id, SUBSTR(p_jurisdiction_code,1,2));
5315 FETCH csr_state_rules INTO l_state_threshold;
5316 CLOSE csr_state_rules;
5317 hr_utility.trace('EMJT: l_state_threshold from get_jd_level_threshold -> '
5318 || l_state_threshold);
5319 hr_utility.trace('EMJT: ================================================================');
5320 RETURN TO_NUMBER(NVL(l_state_threshold,0));
5321 ELSE
5322 RETURN TO_NUMBER(NVL(l_local_threshold,0));
5323 END IF;
5324
5325
5326 ELSIF p_jd_level = 'CITY' THEN
5327 OPEN csr_local_rules(p_tax_unit_id,
5328 p_jurisdiction_code);
5329 FETCH csr_local_rules INTO l_local_threshold;
5330 CLOSE csr_local_rules;
5331 hr_utility.trace('EMJT: p_jurisdiction_code -> ' || p_jurisdiction_code);
5332 hr_utility.trace('EMJT: l_local_threshold from get_jd_level_threshold -> '
5333 || NVL(l_local_threshold,0));
5334 hr_utility.trace('EMJT: ================================================');
5335 IF NVL(l_local_threshold,0) = 0 THEN
5336 OPEN csr_state_rules(p_tax_unit_id, SUBSTR(p_jurisdiction_code,1,2));
5337 FETCH csr_state_rules INTO l_state_threshold;
5338 CLOSE csr_state_rules;
5339 hr_utility.trace('EMJT: l_state_threshold from get_jd_level_threshold -> '
5340 || l_state_threshold);
5341 hr_utility.trace('EMJT: ================================================================');
5342 RETURN TO_NUMBER(NVL(l_state_threshold,0));
5343 ELSE
5344 RETURN TO_NUMBER(NVL(l_local_threshold,0));
5345 END IF;
5346
5347 END IF;
5348 EXCEPTION
5349 WHEN OTHERS THEN
5350 hr_utility.trace('EMJT: Exception OTHERS in get_jd_level_threshold, returning 0');
5351 RETURN 0;
5352 END get_jd_level_threshold;
5353
5354 --Function to get Informational Hours logged by the assignment for
5355 --each jurisdiction code in the pl table.
5356 FUNCTION get_person_it_hours(p_person_id IN NUMBER
5357 ,p_assignment_id IN NUMBER
5358 ,p_jurisdiction_code IN VARCHAR2
5359 ,p_jd_level IN VARCHAR2 --2,6,11
5360 ,p_threshold_basis IN VARCHAR2 --YTD,RTD
5361 ,p_effective_date IN DATE
5362 ,p_end_date IN DATE) RETURN NUMBER AS
5363
5364 -- Cursor to get all the informational time element entries
5365 -- Jurisdiction Code and Hours screen entry values are retrieved
5366 -- All element entries are considered based on the start date and end date.
5367 -- Hours are summed for each jurisdiction.
5368 -- pev1.screen_entry_value Jurisdiction,
5369 CURSOR csr_element_entries(p_start_date IN DATE,
5370 p_end_date IN DATE,
5371 p_person_id IN NUMBER,
5372 p_assignment_id IN NUMBER,
5373 p_effective_date IN DATE,
5374 p_jurisdiction_code IN VARCHAR2,
5375 p_jd_level IN NUMBER) IS
5376 SELECT SUM(pev2.screen_entry_value) Hours
5377 FROM pay_element_entry_values_f pev1,
5378 pay_element_entry_values_f pev2,
5379 pay_element_entries_f pee,
5380 pay_element_links_f pel,
5381 pay_element_types_f pet,
5382 pay_input_values_f piv1,
5383 pay_input_values_f piv2,
5384 pay_element_type_extra_info extra,
5385 per_assignments_f paf
5386 WHERE extra.information_type = 'PAY_US_INFORMATION_TIME'
5387 AND extra.eei_information1 = 'Y'
5388 AND extra.element_type_id = pet.element_type_id
5389 AND pet.element_type_id = pel.element_type_id
5390 AND pee.effective_start_date BETWEEN pet.effective_start_date
5391 AND pet.effective_end_date
5392 AND pel.element_link_id = pee.element_link_id
5393 AND pee.effective_start_date BETWEEN pel.effective_start_date
5394 AND pel.effective_end_date
5395 AND pee.effective_start_date BETWEEN p_start_date
5396 AND p_end_date
5397 AND paf.assignment_id = pee.assignment_id
5398 AND pee.effective_start_date BETWEEN paf.effective_start_date
5399 AND paf.effective_end_date
5400 AND paf.person_id = p_person_id
5401 AND pee.element_entry_id = pev1.element_entry_id
5402 AND pee.effective_start_date BETWEEN pee.effective_start_date
5403 AND pee.effective_end_date
5404 AND pev1.input_value_id = piv1.input_value_id
5405 AND pee.effective_start_date BETWEEN pev1.effective_start_date
5406 AND pev1.effective_end_date
5407 AND piv1.name = 'Jurisdiction'
5408 AND pee.effective_start_date BETWEEN piv1.effective_start_date
5409 AND piv1.effective_end_date
5410 AND pee.element_entry_id = pev2.element_entry_id
5411 AND pee.effective_start_date BETWEEN pee.effective_start_date
5412 AND pee.effective_end_date
5413 AND pev2.input_value_id = piv2.input_value_id
5414 AND piv2.name = 'Hours'
5415 AND pee.effective_start_date BETWEEN piv2.effective_start_date
5416 AND piv2.effective_end_date
5417 AND SUBSTR(pev1.screen_entry_value,1,p_jd_level)
5418 = SUBSTR(p_jurisdiction_code,1,p_jd_level);
5419
5420 l_start_date DATE;
5421 l_end_date DATE;
5422 l_hours NUMBER;
5423
5424 BEGIN
5425 hr_utility.trace('EMJT: ================================================================');
5426 hr_utility.trace('EMJT: In get_person_it_hours');
5427 hr_utility.trace('EMJT: Jurisdiction Code -> '||p_jurisdiction_code);
5428 hr_utility.trace('EMJT: Threshold Basis -> '||p_threshold_basis);
5429 hr_utility.trace('EMJT: Jurisdiction Level -> '||p_jd_level);
5430 hr_utility.trace('EMJT: Payroll Effective Date -> '||to_char(p_effective_date,'DD-MON-YYYY'));
5431 hr_utility.trace('EMJT: Payroll Period End Date -> '||to_char(p_end_date,'DD-MON-YYYY'));
5432
5433 --p_effective_date - pay_payroll_actions.effective_date;
5434 --p_date_earned - pay_payroll_actions.date_earned;
5435
5436 IF p_threshold_basis = 'YTD' THEN
5437 l_start_date := TRUNC(p_effective_date,'Y');
5438 l_end_date := p_effective_date;
5439 ELSIF p_threshold_basis = 'RTD' THEN
5440 l_start_date := ADD_MONTHS(p_end_date, -12);
5441 l_end_date := p_end_date;
5442 END IF;
5443
5444 hr_utility.trace('EMJT: p_effective_date -> '|| p_effective_date );
5445 hr_utility.trace('EMJT: l_start_date -> '|| l_start_date );
5446 hr_utility.trace('EMJT: l_end_date -> '|| l_end_date );
5447
5448 OPEN csr_element_entries(l_start_date
5449 ,l_end_date
5450 ,p_person_id
5451 ,p_assignment_id
5452 ,p_effective_date
5453 ,p_jurisdiction_code
5454 ,p_jd_level );
5455
5456 FETCH csr_element_entries INTO l_hours;
5457 CLOSE csr_element_entries;
5458
5459 hr_utility.trace('EMJT: l_hours -> '|| to_char(l_hours ) );
5460 hr_utility.trace('EMJT: ========================================================');
5461
5462 RETURN l_hours;
5463
5464 END get_person_it_hours;
5465 --
5466 -- This function would be used for fetching percentage to be used STATE and
5467 -- COUNTY level percentage to be used for distributing wages over different
5468 -- jurisdictions when assignment is configured to process information hours
5469 --
5470 FUNCTION get_it_jd_percent(p_jurisdiction_code VARCHAR2 -- parameter
5471 ,p_jd_level VARCHAR2 -- parameter
5472 ,p_hours_to_accumulate OUT nocopy NUMBER -- parameter
5473 ,p_wages_to_accrue_flag OUT nocopy VARCHAR2 -- parameter
5474 )
5475 RETURN NUMBER
5476 IS
5477 l_jd_level number;
5478 l_pad number;
5479 l_entry_jd number;
5480 l_temp_jd number;
5481 l_percentage number;
5482 l_return number;
5483 BEGIN
5484 --{
5485 hr_utility.trace('EMJT: ================================================================');
5486 hr_utility.trace('EMJT: IN get_it_jd_percent ') ;
5487 --
5488 -- This flag is set to Y when assignment is configured to process information
5489 -- hours for deriving the percentage of wages to be distributed over various
5490 -- jurisidictions person worked during the payroll period
5491 --
5492 hr_utility.trace('EMJT: get_it_jd_percent Jurisdiction Level = ' || p_jd_level) ;
5493 hr_utility.trace('EMJT: get_it_jd_percent Jurisdiction Code = ' || p_jurisdiction_code) ;
5494 IF p_jd_level = 'COUNTY' THEN
5495 l_jd_level := 5;
5496 ELSIF p_jd_level = 'STATE' THEN
5497 l_jd_level := 2;
5498 END IF;
5499
5500 IF SUBSTR(p_jurisdiction_code,1,1) = 0 THEN
5501 l_pad := 8;
5502 l_jd_level := l_jd_level - 1;
5503 ELSE
5504 l_pad := 9;
5505 END IF;
5506
5507 hr_utility.trace('EMJT: get_it_jd_percent l_pad = ' || to_char(l_pad)) ;
5508 hr_utility.trace('EMJT: get_it_jd_percent l_jd_level = ' || to_char(l_jd_level)) ;
5509
5510 l_entry_jd := TO_NUMBER(SUBSTR(p_jurisdiction_code,1,2) ||
5511 SUBSTR(p_jurisdiction_code,4,3) ||
5512 SUBSTR(p_jurisdiction_code,8,4) );
5513
5514 l_temp_jd := RPAD(SUBSTR(l_entry_jd,1,l_jd_level),l_pad,0);
5515
5516 hr_utility.trace('EMJT: get_it_jd_percent l_temp_jd = ' || to_char(l_temp_jd)) ;
5517
5518 --Fetch the percentage stored for the State
5519 --
5520 IF p_jd_level = 'STATE' THEN
5521 --{
5522 IF jd_codes_tbl_state.EXISTS(TO_NUMBER(l_temp_jd))
5523 THEN
5524 l_percentage := jd_codes_tbl_state(TO_NUMBER(l_temp_jd)).percentage;
5525 ELSE
5526 l_percentage := 0;
5527 END IF;
5528 --} end of p_jd_level = 'STATE'
5529 ELSIF p_jd_level = 'COUNTY' THEN
5530 --{
5531 IF jd_codes_tbl_county.EXISTS(TO_NUMBER(l_temp_jd))
5532 THEN
5533 l_percentage := jd_codes_tbl_county(TO_NUMBER(l_temp_jd)).percentage;
5534 ELSE
5535 l_percentage := 0;
5536 END IF;
5537 --}end of p_jd_level = 'COUNTY'
5538 /*Bug#6598477 begins*/
5539 ELSIF p_jd_level = 'CITY' THEN
5540 --{
5541 IF jurisdiction_codes_tbl.EXISTS(TO_NUMBER(l_temp_jd))
5542 THEN
5543 l_percentage := jurisdiction_codes_tbl(TO_NUMBER(l_temp_jd)).percentage;
5544 ELSE
5545 l_percentage := 0;
5546 END IF;
5547 --}end of p_jd_level = 'CITY'
5548 /*Bug#6598477 ends*/
5549 END IF;
5550 hr_utility.trace('EMJT: get_it_jd_percent Percentage Derived for Jurisdiction = '
5551 || to_char(l_percentage)) ;
5552 -- Dummy values assigned to the OUT variables
5553 p_hours_to_accumulate := 0;
5554 p_wages_to_accrue_flag := 'AIHW';
5555 --
5556 -- Percentage returned based on the jurisidction level and jurisdiction code passed
5557 --
5558 hr_utility.trace('EMJT: l_percentage from get_it_jd_percent ->'|| to_char(l_percentage));
5559 hr_utility.trace('EMJT: ================================================================');
5560 RETURN l_percentage;
5561 EXCEPTION
5562 WHEN OTHERS THEN
5563 hr_utility.trace('EMJT: Exception OTHERS in get_it_jd_percent, returning 0');
5564 RETURN 0;
5565 --}
5566 END get_it_jd_percent;
5567
5568 function across_calendar_years(p_payroll_action_id in number)
5569 return varchar2 is
5570
5571 l_date_earned date;
5572 l_date_paid date;
5573 l_check_years varchar2(1);
5574
5575 cursor csr_get_dates is
5576 select effective_date,
5577 date_earned
5578 from pay_payroll_actions
5579 where payroll_action_id = p_payroll_action_id;
5580
5581 begin
5582
5583 open csr_get_dates;
5584 fetch csr_get_dates
5585 into l_date_paid,
5586 l_date_earned;
5587 close csr_get_dates;
5588
5589 if to_char(l_date_paid,'YYYY') = to_char(l_date_earned,'YYYY') then
5590 l_check_years := 'N';
5591 else
5592 l_check_years := 'Y';
5593 end if;
5594
5595 return l_check_years;
5596
5597 end across_calendar_years;
5598
5599
5600 FUNCTION get_work_state (p_jurisdiction_code in varchar2)
5601 RETURN varchar2 IS
5602
5603 l_exists varchar2(2);
5604 i number;
5605 BEGIN
5606 l_exists := 'N';
5607
5608 IF jurisdiction_codes_tbl.COUNT > 0 THEN
5609
5610 i := jurisdiction_codes_tbl.FIRST; -- get subscript of first element
5611 WHILE i IS NOT NULL LOOP
5612
5613 hr_utility.trace('plsql table='||substr(jurisdiction_codes_tbl(i).jurisdiction_code,1,2));
5614 IF p_jurisdiction_code = substr(jurisdiction_codes_tbl(i).jurisdiction_code,1,2)
5615 THEN
5616 l_exists := 'Y';
5617 EXIT;
5618 END IF;
5619
5620 i := jurisdiction_codes_tbl.NEXT(i); -- get subscript of next element
5621 END LOOP;
5622
5623 END IF;
5624
5625 RETURN l_exists;
5626
5627 END get_work_state;
5628
5629 --Function to return the SUI Wage Limits.
5630 FUNCTION get_jit_data(p_jurisdiction_code IN VARCHAR2
5631 ,p_date_earned IN DATE
5632 ,p_jit_type IN VARCHAR2)
5633 RETURN NUMBER IS
5634
5635 CURSOR csr_sui_er_wage_limit(p_jurisdiction_code IN VARCHAR2,p_date_earned IN DATE) IS
5636 SELECT NVL(sui_er_wage_limit,0)
5637 FROM pay_us_state_tax_info_f
5638 WHERE state_code = SUBSTR(p_jurisdiction_code,1,2)
5639 AND p_date_earned BETWEEN effective_start_date AND effective_end_date;
5640
5641 l_sui_er_wage_limit pay_us_state_tax_info_f.sui_er_wage_limit%TYPE;
5642
5643 CURSOR csr_sui_ee_wage_limit(p_jurisdiction_code IN VARCHAR2,p_date_earned IN DATE) IS
5644 SELECT NVL(sui_ee_wage_limit,0)
5645 FROM pay_us_state_tax_info_f
5646 WHERE state_code = SUBSTR(p_jurisdiction_code,1,2)
5647 AND p_date_earned BETWEEN effective_start_date AND effective_end_date;
5648
5649 l_sui_ee_wage_limit pay_us_state_tax_info_f.sui_ee_wage_limit%TYPE;
5650
5651 CURSOR csr_supp_calc_method(p_jurisdiction_code IN VARCHAR2,p_date_earned IN DATE) IS
5652 SELECT NVL(sta_information18,' ')
5653 FROM pay_us_state_tax_info_f
5654 WHERE state_code = SUBSTR(p_jurisdiction_code,1,2)
5655 AND p_date_earned BETWEEN effective_start_date AND effective_end_date;
5656
5657 l_supp_calc_meth pay_us_state_tax_info_f.sta_information18%TYPE;
5658
5659 l_return_value NUMBER;
5660
5661 BEGIN
5662
5663 hr_utility.trace('hr_us_ff_udf1.get_jit_date');
5664 hr_utility.trace('p_jurisdiction_code --> '|| p_jurisdiction_code);
5665 hr_utility.trace('p_date_earned --> '|| p_date_earned);
5666 hr_utility.trace('p_jit_type --> '|| p_jit_type);
5667
5668 IF p_jit_type = 'SUI_ER_WAGE_LIMIT' THEN
5669 OPEN csr_sui_er_wage_limit(p_jurisdiction_code,p_date_earned);
5670 FETCH csr_sui_er_wage_limit INTO l_sui_er_wage_limit;
5671 CLOSE csr_sui_er_wage_limit;
5672 l_return_value := l_sui_er_wage_limit;
5673 hr_utility.trace('l_sui_er_wage_limit --> '|| l_sui_er_wage_limit);
5674
5675 END IF; /* SUI_ER_WAGE_LIMIT */
5676
5677 IF p_jit_type = 'SUI_EE_WAGE_LIMIT' THEN
5678
5679 OPEN csr_sui_ee_wage_limit(p_jurisdiction_code,p_date_earned);
5680 FETCH csr_sui_ee_wage_limit INTO l_sui_ee_wage_limit;
5681 CLOSE csr_sui_ee_wage_limit;
5682 l_return_value := l_sui_ee_wage_limit;
5683 hr_utility.trace('l_sui_ee_wage_limit --> '|| l_sui_ee_wage_limit);
5684
5685 END IF; /* SUI_EE_WAGE_LIMIT */
5686
5687 IF p_jit_type = 'DEFAULT_SUPP_CALC_METH' THEN
5688
5689 OPEN csr_supp_calc_method(p_jurisdiction_code,p_date_earned);
5690 FETCH csr_supp_calc_method INTO l_supp_calc_meth;
5691 CLOSE csr_supp_calc_method;
5692 l_return_value := l_supp_calc_meth;
5693 hr_utility.trace('DEFAULT_SUPP_CALC_METH --> '|| l_supp_calc_meth);
5694 END IF; /* DEFAULT_SUPP_CALC_METH */
5695
5696 hr_utility.trace('l_return_value --> '|| l_return_value);
5697 RETURN l_return_value;
5698
5699 END get_jit_data;
5700
5701 FUNCTION get_rs_jd (p_assignment_id IN NUMBER,
5702 p_date_earned IN DATE)
5703 RETURN VARCHAR2 IS
5704
5705 CURSOR c_override_jd (p_assignment_id IN NUMBER,p_date_earned IN DATE) IS
5706 SELECT puc.state_code || '-' || puc.county_code || '-' ||pucty.city_code
5707 FROM pay_us_counties puc,
5708 pay_us_states pus,
5709 pay_us_city_names pucty,
5710 per_addresses pa,
5711 per_assignments_f paf
5712 WHERE paf.assignment_id = p_assignment_id
5713 AND paf.person_id = pa.person_id
5714 AND p_date_earned BETWEEN paf.effective_start_date AND paf.effective_end_date
5715 AND paf.primary_flag = 'Y'
5716 AND paf.assignment_type = 'E'
5717 AND pa.primary_flag = 'Y'
5718 AND pa.country = 'US'
5719 AND pa.style = 'US'
5720 AND TO_DATE('01-01-'||TO_CHAR(p_date_earned,'YYYY'), 'DD-MM-YYYY') BETWEEN
5721 pa.date_from AND NVL(pa.date_to,to_date('31-12-4712','DD-MM-YYYY'))
5722 AND pus.state_abbrev = pa.add_information17 --override state
5723 AND puc.state_code = pus.state_code
5724 AND puc.county_name = pa.add_information19 --Override County
5725 AND pucty.state_code = pus.state_code
5726 AND pucty.county_code = puc.county_code
5727 AND pucty.city_name = pa.add_information18; -- Override City.
5728
5729
5730 CURSOR c_jd (p_assignment_id IN NUMBER,p_date_earned IN DATE) IS
5731 SELECT puc.state_code || '-' || puc.county_code || '-' ||pucty.city_code
5732 FROM pay_us_counties puc,
5733 pay_us_states pus,
5734 pay_us_city_names pucty,
5735 per_addresses pa,
5736 per_assignments_f paf
5737 WHERE paf.assignment_id = p_assignment_id
5738 AND paf.person_id = pa.person_id
5739 AND p_date_earned BETWEEN paf.effective_start_date AND paf.effective_end_date
5740 AND paf.primary_flag = 'Y'
5741 AND paf.assignment_type = 'E'
5742 AND pa.primary_flag = 'Y'
5743 AND pa.country = 'US'
5744 AND pa.style = 'US'
5745 AND TO_DATE('01-01-'||TO_CHAR(p_date_earned,'YYYY'), 'DD-MM-YYYY') BETWEEN
5746 pa.date_from AND NVL(pa.date_to,to_date('31-12-4712','DD-MM-YYYY'))
5747 AND pus.state_abbrev = pa.region_2 --Regular state
5748 AND puc.state_code = pus.state_code
5749 AND puc.county_name = pa.region_1 --Regular County
5750 AND pucty.state_code = pus.state_code
5751 AND pucty.county_code = puc.county_code
5752 AND pucty.city_name = pa.town_or_city; -- Regular City.
5753
5754
5755 l_rs_jd VARCHAR2(200);
5756
5757 BEGIN
5758
5759 OPEN c_override_jd(p_assignment_id,p_date_earned);
5760 FETCH c_override_jd INTO l_rs_jd;
5761 IF c_override_jd%NOTFOUND THEN
5762
5763 OPEN c_jd(p_assignment_id,p_date_earned);
5764 FETCH c_jd INTO l_rs_jd;
5765 IF c_jd%NOTFOUND THEN
5766 l_rs_jd := NULL;
5767 END IF;
5768 CLOSE c_jd;
5769
5770 END IF;
5771 CLOSE c_override_jd;
5772
5773 hr_utility.trace('hr_us_ff_udf1.get_rs_jd');
5774 --hr_utility.trace('p_jurisdiction_code --> '|| p_jurisdiction_code);
5775 hr_utility.trace('p_date_earned --> '|| p_date_earned);
5776 --hr_utility.trace('p_jit_type --> '|| p_jit_type);
5777
5778 hr_utility.trace('l_rs_jd --> '|| l_rs_jd );
5779 --dbms_output.put_line('l_rs_jd --> '|| l_rs_jd);
5780
5781 RETURN l_rs_jd;
5782
5783
5784 END get_rs_jd;
5785
5786 FUNCTION get_wk_jd(p_assignment_id IN NUMBER,
5787 p_date_earned IN DATE,
5788 p_jurisdiction_code IN VARCHAR2)
5789 RETURN VARCHAR2 IS
5790
5791 CURSOR c_override_wk_jd (p_assignment_id IN NUMBER,
5792 p_date_earned IN DATE,
5793 p_jurisdiction_code IN VARCHAR2) IS
5794 SELECT puc.state_code || '-' || puc.county_code || '-' ||pucty.city_code
5795 FROM pay_us_counties puc,
5796 pay_us_states pus,
5797 pay_us_city_names pucty,
5798 hr_locations hl,
5799 per_assignments_f paf
5800 WHERE paf.assignment_id = p_assignment_id
5801 AND TO_DATE('01-01-'||TO_CHAR(p_date_earned,'YYYY'), 'DD-MM-YYYY') BETWEEN
5802 paf.effective_start_date AND paf.effective_end_date
5803 AND paf.location_id = hl.location_id
5804 AND hl.loc_information17 = pus.state_abbrev --override state
5805 AND puc.state_code = pus.state_code
5806 AND hl.loc_information19 = puc.county_name --override county
5807 AND puc.state_code = SUBSTR(p_jurisdiction_code, 1, 2)
5808 AND puc.county_code = SUBSTR(p_jurisdiction_code, 4, 3)
5809 AND hl.loc_information18 = pucty.city_name --override city
5810 AND pucty.state_code = SUBSTR(p_jurisdiction_code, 1, 2)
5811 AND pucty.county_code = SUBSTR(p_jurisdiction_code, 4, 3)
5812 AND pucty.city_code = SUBSTR(p_jurisdiction_code, 8, 4);
5813
5814 CURSOR c_reg_wk_jd (p_assignment_id IN NUMBER,
5815 p_date_earned IN DATE,
5816 p_jurisdiction_code IN VARCHAR2) IS
5817 SELECT puc.state_code || '-' || puc.county_code || '-' ||pucty.city_code
5818 FROM pay_us_counties puc,
5819 pay_us_states pus,
5820 pay_us_city_names pucty,
5821 hr_locations hl,
5822 per_assignments_f paf
5823 WHERE paf.assignment_id = p_assignment_id
5824 AND TO_DATE('01-01-'||TO_CHAR(p_date_earned,'YYYY'), 'DD-MM-YYYY') BETWEEN
5825 paf.effective_start_date AND paf.effective_end_date
5826 AND paf.location_id = hl.location_id
5827 AND hl.region_2 = pus.state_abbrev --reg state
5828 AND puc.state_code = pus.state_code
5829 AND hl.region_1 = puc.county_name --reg county
5830 AND puc.state_code = SUBSTR(p_jurisdiction_code, 1, 2)
5831 AND puc.county_code = SUBSTR(p_jurisdiction_code, 4, 3)
5832 AND hl.town_or_city = pucty.city_name --reg city
5833 AND pucty.state_code = SUBSTR(p_jurisdiction_code, 1, 2)
5834 AND pucty.county_code = SUBSTR(p_jurisdiction_code, 4, 3)
5835 AND pucty.city_code = SUBSTR(p_jurisdiction_code, 8, 4);
5836
5837 l_wk_jd VARCHAR2(200);
5838
5839 BEGIN
5840
5841
5842 OPEN c_override_wk_jd (p_assignment_id,p_date_earned,p_jurisdiction_code);
5843 FETCH c_override_wk_jd INTO l_wk_jd;
5844 IF c_override_wk_jd%NOTFOUND THEN
5845 OPEN c_reg_wk_jd(p_assignment_id,p_date_earned,p_jurisdiction_code);
5846 FETCH c_reg_wk_jd INTO l_wk_jd;
5847 IF c_reg_wk_jd%NOTFOUND THEN
5848 l_wk_jd := NULL;
5849 END IF;
5850 CLOSE c_reg_wk_jd;
5851 END IF;
5852 CLOSE c_override_wk_jd;
5853
5854
5855 hr_utility.trace('hr_us_ff_udf1.get_wk_jd');
5856 hr_utility.trace('p_jurisdiction_code --> '|| p_jurisdiction_code);
5857 hr_utility.trace('p_date_earned --> '|| p_date_earned);
5858 --hr_utility.trace('p_jit_type --> '|| p_jit_type);
5859
5860 hr_utility.trace('l_wk_jd --> '|| l_wk_jd );
5861
5862 --dbms_output.put_line('l_wk_jd --> '|| l_wk_jd);
5863
5864 RETURN l_wk_jd;
5865
5866 END get_wk_jd;
5867
5868
5869 /*Function created for Bug 5972214
5870 This function is used to check for a given Colorado Jurisdiction, the Head
5871 tax can be deducted or not.
5872 For the city with Head tax to be able to collect Head(OPT) tax it needs
5873 to satisfy these conditions
5874 1)The current payperiod must be the last one of the present month
5875 2)The city should have the maximum time percentage of all the Colorado
5876 jurisdictions in which the Employee works
5877 3)If two jurisdictions are with same percentage, then primary is given
5878 priority if it is one of them.If none of them are primary,pick one of them
5879 which is based on the order in which the same percentage jurisdictions
5880 present in the pl/sql table.This table order is employed to make sure
5881 only one city is selected to collect head tax.
5882 4)For a payroll with duration less than a month, use of Date Paid in different
5883 month will cause Head Tax to be skipped in some cases.A warning message
5884 will be thrown in the Concurrent Request Log file for such assignments
5885 with Assignment ID,Assignment Number,Jurisdiction code to help customer to
5886 do Balance adjustment for skipped assignments.
5887 */
5888 FUNCTION coloradocity_ht_collectornot(
5889 p_assignment_id NUMBER,
5890 p_date_earned DATE,
5891 p_payroll_action_id NUMBER,
5892 p_jurisdiction_code VARCHAR2,
5893 p_prim_jurisdiction_code VARCHAR2,
5894 p_monthly_gross NUMBER )
5895 RETURN NUMBER
5896 IS
5897
5898 l_max_jd_code VARCHAR2(11); --Jurisdiction for City with maximum percentage
5899 l_max_percent NUMBER(3); --Maximum Percentage
5900 l_max_jd_code1 VARCHAR2(11); --Jurisdiction for City with maximum percentage
5901 l_max_percent1 NUMBER(3); --Maximum Percentage
5902 l_collect_ht NUMBER(1); -- Flag to decide Head Tax to be collected or not
5903 l_counter NUMBER(1);
5904 l_pay_period_start_date DATE;
5905 l_pay_period_end_date DATE;
5906 l_payroll_id NUMBER(9);
5907 l_date DATE;
5908 l_nearest_end_date DATE;
5909 l_date_paid DATE;
5910
5911 -- Get start and end dates of the pay period for the given date_earned
5912 CURSOR csr_get_period_dates IS
5913 select ptp.start_date,
5914 ptp.end_date,
5915 ptp.payroll_id
5916 from per_all_assignments_f paaf,
5917 pay_all_payrolls_f papf,
5918 per_time_periods ptp
5919 where paaf.payroll_id = papf.payroll_id
5920 and papf.payroll_id = ptp.payroll_id
5921 and assignment_id = p_assignment_id
5922 and p_date_earned between ptp.start_date
5923 and ptp.end_date
5924 and p_date_earned between papf.effective_start_date
5925 and papf.effective_end_date
5926 and p_date_earned between paaf.effective_start_date
5927 and paaf.effective_end_date;
5928
5929 --Cursor to fetch nearest pay period to the WC effective date
5930 CURSOR CSR_GET_NEAREST_PERIOD IS
5931 select max(end_date)
5932 from per_time_periods
5933 where payroll_id = l_payroll_id
5934 and end_date <= l_date;
5935
5936 --Cursor to fetch the average percentage of employee's time in each of
5937 --his Colorado work Jurisdictions.The cursor fetches the jurisdictions
5938 --in the descending order of its percentage,in ascending order of
5939 --Jurisdictions for those with same percentage
5940 CURSOR JURISDICTION_PERCENTAGE IS
5941 select jurisdiction_code,
5942 round(sum(percentage*days)/(last_day(p_date_earned)-trunc(p_date_earned,'MONTH')+1),2) percentage
5943 from
5944 ( select pev1.element_entry_id,
5945 pev1.screen_entry_value Jurisdiction_code,
5946 pev2.screen_entry_value Percentage,
5947 least(last_day(p_date_earned),pee.effective_end_date)
5948 -greatest(pee.effective_start_date,trunc(p_date_earned,'MONTH') )+1 days
5949 from pay_element_entry_values_f pev1,
5950 pay_element_entry_values_f pev2,
5951 pay_element_entries_f pee,
5952 pay_element_links_f pel,
5953 pay_element_types_f pet,
5954 pay_input_values_f piv1,
5955 pay_input_values_f piv2
5956 where pee.assignment_id = p_assignment_id
5957 and pee.effective_start_date<=last_day(p_date_earned)
5958 and pee.effective_end_date>=trunc(p_date_earned,'MONTH')
5959 and pee.element_link_id = pel.element_link_id
5960 and pee.effective_start_date between pel.effective_start_date
5961 and pel.effective_end_date
5962 and pel.element_type_id = pet.element_type_id
5963 and pet.element_name = 'VERTEX'
5964 and pee.effective_start_date between pet.effective_start_date
5965 and pet.effective_end_date
5966 and pee.element_entry_id = pev1.element_entry_id
5967 and pee.effective_start_date between pev1.effective_start_date
5968 and pev1.effective_end_date
5969 and pev1.input_value_id = piv1.input_value_id
5970 and pee.effective_start_date between piv1.effective_start_date
5971 and piv1.effective_end_date
5972 and piv1.name = 'Jurisdiction'
5973 and pee.element_entry_id = pev2.element_entry_id
5974 and pee.effective_start_date between pev2.effective_start_date
5975 and pev2.effective_end_date
5976 and pev2.input_value_id = piv2.input_value_id
5977 and pee.effective_start_date between piv2.effective_start_date
5978 and piv2.effective_end_date
5979 and piv2.name = 'Percentage'
5980 and pev1.screen_entry_value in ('06-001-0030','06-005-0030',
5981 '06-035-0030','06-005-0870',
5982 '06-031-0140','06-005-0450',
5983 '06-005-0850'))
5984 group by jurisdiction_code order by percentage desc,jurisdiction_code;
5985
5986 -- Get the Date Paid for the current run
5987 CURSOR csr_get_date_paid IS
5988 select effective_date
5989 from pay_payroll_actions
5990 where payroll_action_id = p_payroll_action_id;
5991
5992 --To print the Warning message for an assignment whose possible Head Tax
5993 --might not be withheld due to Date Paid in different month than that of
5994 --Date Earned.
5995 PROCEDURE print_warning(p_pay_period_end_date DATE,
5996 p_date_paid DATE,
5997 p_assignment_id NUMBER,
5998 p_payroll_id NUMBER,
5999 p_jurisdiction_code VARCHAR2,
6000 p_monthly_gross NUMBER)
6001 IS
6002
6003 CURSOR get_number_periods_per_year IS
6004 SELECT number_per_fiscal_year
6005 FROM per_time_period_types pttt,
6006 pay_all_payrolls_f papf
6007 WHERE pttt.period_type=papf.period_type
6008 AND papf.payroll_id=p_payroll_id;
6009
6010 CURSOR get_assignment_number IS
6011 SELECT assignment_number
6012 FROM per_all_assignments_f
6013 WHERE assignment_id=p_assignment_id;
6014
6015 l_num_periods_per_year per_time_period_types.number_per_fiscal_year%TYPE;
6016 l_assignment_number per_all_assignments_f.assignment_number%TYPE;
6017 l_ht_deducted NUMBER;
6018
6019 BEGIN
6020
6021
6022 OPEN get_number_periods_per_year;
6023 FETCH get_number_periods_per_year INTO l_num_periods_per_year;
6024
6025 OPEN get_assignment_number;
6026 FETCH get_assignment_number INTO l_assignment_number;
6027
6028 l_ht_deducted :=0;
6029
6030 /*To ensure warning will not be thrown if Head Tax gets deducted
6031 with current earnings alone */
6032
6033 IF ((p_jurisdiction_code = '06-001-0030') OR /* Aurora */
6034 (p_jurisdiction_code = '06-005-0030') OR /* Aurora */
6035 (p_jurisdiction_code = '06-035-0030') OR /* Aurora */
6036 (p_jurisdiction_code = '06-005-0870') ) /* Greenwood Village */
6037 THEN
6038
6039 IF p_monthly_gross >= 250
6040 THEN
6041 l_ht_deducted :=1;
6042 END IF;
6043
6044 ELSIF ((p_jurisdiction_code = '06-031-0140') or /* Denver */
6045 (p_jurisdiction_code = '06-005-0450') ) /* Sheridan */
6046 THEN
6047
6048 IF p_monthly_gross >= 500
6049 THEN
6050 l_ht_deducted :=1;
6051 END IF;
6052
6053 ELSE /*Glendale*/
6054
6055 IF p_monthly_gross >= 750
6056 THEN
6057 l_ht_deducted :=1;
6058 END IF;
6059
6060 END IF;
6061
6062 /*Warning shown only if Payperiod duration is less than Month */
6063 IF TRUNC(p_pay_period_end_date,'MONTH')<>TRUNC(p_date_paid,'MONTH')
6064 AND l_num_periods_per_year > 12 AND l_ht_deducted = 0
6065 THEN
6066 fnd_file.put_line(FND_FILE.LOG,'WARNING: For Assignment with Assignment ID '||
6067 TO_CHAR(p_assignment_id)||' Assignment Number '||TO_CHAR(l_assignment_number)||
6068 ' Head Tax is not withheld for Jurisdiction '||p_jurisdiction_code||' as Date Paid'||
6069 ' Paid and Date Earned are in different months.');
6070 END IF;
6071
6072 CLOSE get_number_periods_per_year;
6073 CLOSE get_assignment_number;
6074
6075 END print_warning;
6076
6077 BEGIN
6078
6079 hr_utility.trace('IN coloradocity_ht_collectornot');
6080 hr_utility.trace('p_assignment_id: ' || to_char(p_assignment_id));
6081 hr_utility.trace('p_date_earned: ' || to_char(p_date_earned));
6082 hr_utility.trace('Current Jurisdiction'||p_jurisdiction_code);
6083 hr_utility.trace('Primary Work Jurisdiction of the Assignment'||
6084 p_prim_jurisdiction_code);
6085
6086 l_collect_ht :=0;
6087
6088 /*Check if the current payperiod is last payperiod of the month*/
6089
6090 /*Get the Start date and End date of Current Payperiod using the Date Earned*/
6091 OPEN csr_get_period_dates;
6092 FETCH csr_get_period_dates INTO
6093 l_pay_period_start_date,l_pay_period_end_date,l_payroll_id;
6094 IF csr_get_period_dates%NOTFOUND THEN
6095 hr_utility.trace('Pay period for the given date_earned is NOT found');
6096 CLOSE csr_get_period_dates;
6097 return (l_collect_ht);
6098 END IF;
6099
6100 /*Get the Last day of the month in which current payperiod is present*/
6101 l_date := last_day(l_pay_period_end_date);
6102
6103 /*Get the nearest pay period end date to the Last of the month */
6104 OPEN CSR_GET_NEAREST_PERIOD;
6105 FETCH CSR_GET_NEAREST_PERIOD INTO l_nearest_end_date;
6106 IF CSR_GET_NEAREST_PERIOD%NOTFOUND THEN
6107 hr_utility.trace('Nearest Pay period for the given date_earned is NOT found');
6108 CLOSE CSR_GET_NEAREST_PERIOD;
6109 CLOSE csr_get_period_dates;
6110 return (l_collect_ht);
6111 END IF;
6112
6113 /*To check if a null value is returned for nearest pay period enddate of month*/
6114 IF l_nearest_end_date IS NULL
6115 THEN
6116 hr_utility.trace('Null value returned for nearest payperiod end date');
6117 hr_utility.trace('So returning '||to_char(l_collect_ht));
6118 return(l_collect_ht);
6119 END IF;
6120
6121 /*To check if the current payperiod is the last payperiod of the month*/
6122 if ( l_nearest_end_date <> l_pay_period_end_date ) then
6123 hr_utility.trace('Present Payperiod is not the lastone of the month');
6124 hr_utility.trace('So returning '||to_char(l_collect_ht));
6125 return(l_collect_ht);
6126 end if;
6127
6128 /* Get the Date Paid for the current run */
6129 OPEN CSR_GET_DATE_PAID;
6130 FETCH CSR_GET_DATE_PAID INTO l_date_paid;
6131 CLOSE CSR_GET_DATE_PAID;
6132
6133 /*Get the Jurisdiction with maximum percentage*/
6134 OPEN jurisdiction_percentage;
6135 FETCH jurisdiction_percentage INTO l_max_jd_code,l_max_percent;
6136
6137 /*Check if the current jurisdiction has maximum percentage*/
6138 /*Return 0 if the current jurisdiction does not have maximum
6139 percentage and the maximum jurisdiction code is greater than
6140 current jurisdiction*/
6141
6142 IF l_max_jd_code <> p_jurisdiction_code
6143 AND least(p_jurisdiction_code,l_max_jd_code)=p_jurisdiction_code
6144 THEN
6145 hr_utility.trace('To collect Head Tax for Colorado or not'||to_char(l_collect_ht));
6146 RETURN l_collect_ht;
6147 END IF;
6148
6149 /*Return 1 if the current jurisdiction has maximum
6150 percentage and it is the primary work jurisdiction*/
6151
6152 IF l_max_jd_code = p_jurisdiction_code
6153 AND p_jurisdiction_code = p_prim_jurisdiction_code
6154 THEN
6155 print_warning(l_pay_period_end_date,l_date_paid,p_assignment_id,l_payroll_id,p_jurisdiction_code,p_monthly_gross);
6156 l_collect_ht :=1;
6157 hr_utility.trace('To collect Head Tax for Colorado or not'||to_char(l_collect_ht));
6158 RETURN l_collect_ht;
6159 END IF;
6160
6161 l_counter :=0;
6162 WHILE l_counter IS NOT NULL
6163 LOOP
6164
6165 FETCH jurisdiction_percentage INTO l_max_jd_code1,l_max_percent1;
6166
6167 IF jurisdiction_percentage%FOUND AND l_max_percent1 = l_max_percent THEN
6168
6169 /*Return 1 only for primary work jurisdiction if multiple jurisdictions have
6170 same high percentage as primary.For others return 0*/
6171
6172 IF l_max_jd_code1 = p_prim_jurisdiction_code THEN
6173 IF p_jurisdiction_code = p_prim_jurisdiction_code THEN
6174 CLOSE jurisdiction_percentage;
6175 print_warning(l_pay_period_end_date,l_date_paid,p_assignment_id,l_payroll_id,p_jurisdiction_code,p_monthly_gross);
6176 l_collect_ht :=1;
6177 hr_utility.trace('To collect Head Tax for Colorado or not'||to_char(l_collect_ht));
6178 RETURN l_collect_ht;
6179 ELSE
6180 CLOSE jurisdiction_percentage;
6181 hr_utility.trace('To collect Head Tax for Colorado or not'||to_char(l_collect_ht));
6182 RETURN l_collect_ht;
6183 END IF;
6184 END IF;
6185
6186 ELSE
6187
6188 l_counter := NULL;
6189
6190 END IF;
6191
6192 END LOOP;
6193
6194 CLOSE jurisdiction_percentage;
6195
6196 IF l_max_jd_code = p_jurisdiction_code THEN
6197 print_warning(l_pay_period_end_date,l_date_paid,p_assignment_id,l_payroll_id,p_jurisdiction_code,p_monthly_gross);
6198 l_collect_ht := 1;
6199 hr_utility.trace('To collect Head Tax for Colorado or not'||to_char(l_collect_ht));
6200 RETURN l_collect_ht;
6201 END IF;
6202 hr_utility.trace('To collect Head Tax for Colorado or not'||to_char(l_collect_ht));
6203 RETURN l_collect_ht;
6204
6205 END coloradocity_ht_collectornot;
6206
6207 /*Added for Bug#12583094*/
6208
6209 --Function to give the number of pay periods left in the given year based on the p_logical_hire_date.
6210 FUNCTION count_remaining_pay_periods(p_payroll_action_id IN pay_payroll_actions.payroll_action_id%TYPE, --Context
6211 p_logical_hire_date IN DATE ) --Parameter
6212 RETURN NUMBER IS
6213
6214 CURSOR get_count IS
6215 SELECT decode(count(regular_payment_date),0,1,count(regular_payment_date))
6216 FROM pay_payroll_actions paction,
6217 per_time_periods target
6218 WHERE paction.payroll_action_id = p_payroll_action_id
6219 AND target.payroll_id = paction.payroll_id
6220 AND to_char(target.regular_payment_date,'YYYY')=to_char(paction.effective_date,'YYYY')
6221 AND target.regular_payment_date >= p_logical_hire_date;
6222
6223 l_remaining_periods NUMBER;
6224
6225 BEGIN
6226
6227 hr_utility.trace('Entering hr_us_ff_udf1.count_remaining_pay_periods');
6228 hr_utility.trace( 'p_payroll_action Id '|| p_payroll_action_id);
6229 hr_utility.trace( 'p_logical_hire_date '|| to_char(p_logical_hire_date,'dd-mon-yyyy'));
6230
6231 l_remaining_periods := 0;
6232
6233 OPEN get_count;
6234 FETCH get_count INTO l_remaining_periods;
6235 IF get_count%NOTFOUND THEN
6236 l_remaining_periods := 0;
6237 END IF;
6238 CLOSE get_count;
6239
6240 hr_utility.trace('Leaving hr_us_ff_udf1.count_remaining_pay_periods');
6241 return l_remaining_periods;
6242
6243 EXCEPTION
6244 WHEN OTHERS THEN
6245 hr_utility.trace('Exception raised in hr_us_ff_udf1.count_remaining pay periods .');
6246 return 0;
6247 END count_remaining_pay_periods;
6248
6249 FUNCTION GET_PSD_JD_CODE
6250 ( p_assignment_id IN number --Context
6251 ,p_tax_unit_id IN number --context
6252 ,p_date_paid IN date -- parameter
6253 ,p_loc_addr_geocode IN varchar2 --parameter
6254 ,p_per_addr_geocode IN varchar2 --parameter
6255 ) RETURN varchar2 is
6256
6257 /* DBI Fetched in fast formula
6258 ~FURTHER_CITY_TAX_INFO_PA_WORK_SCHOOL_DSTS_CODE -- FORMAT varchar2(5)
6259 */
6260
6261 l_psd_jurisdiction_code varchar2(16);
6262 l_work_city_school_district varchar2(5);
6263 l_res_city_school_district varchar2(5);
6264 l_res_psd_code varchar2(6);
6265 l_work_psd_code varchar2(6);
6266 l_asg_rep_row_exists varchar2(1);
6267 l_date_paid date;
6268 BEGIN
6269 hr_utility.trace('Entering GET_PSD_JD_CODE .');
6270
6271
6272 hr_utility.trace( 'assignment_Id '|| p_assignment_id);
6273 hr_utility.trace( 'p_date_paid '|| to_char(p_date_paid,'dd-mon-yyyy'));
6274 hr_utility.trace( 'loc_addr_geocode '|| p_loc_addr_geocode);
6275 hr_utility.trace( 'per_addr_geocode '|| p_per_addr_geocode);
6276
6277
6278
6279 l_psd_jurisdiction_code := '00-880000-880000';
6280
6281 l_date_paid := p_date_paid;
6282
6283
6284 -- 1 check if the person lives in PA
6285
6286 IF substr(p_per_addr_geocode,1,2) <> '39'
6287 AND substr(p_loc_addr_geocode,1,2) <> '39' THEN
6288
6289 l_psd_jurisdiction_code := substr(p_per_addr_geocode,1,2) || '-8800000-880000';
6290
6291 hr_utility.trace('GET_PSD_JD_CODE: state resident nor work jurisdiction are PA returning dummy psd jurisdiction_code');
6292
6293 return l_psd_jurisdiction_code;
6294
6295 ELSE
6296
6297
6298 IF substr(p_per_addr_geocode,1,2) <> '39' THEN
6299
6300 hr_utility.trace('GET_PSD_JD_CODE: state resident jurisdiction is NOT PA returning dummy psd JD code for resident portion');
6301
6302 l_psd_jurisdiction_code := '39-880000';
6303
6304 ELSE
6305
6306 -- GET THE RESIDENT SCHOOL DISTRICT CODE
6307
6308 hr_utility.trace('GET_PSD_JD_CODE: Get resident jd school dsts code');
6309
6310 BEGIN
6311
6312 SELECT school_district_code
6313 INTO l_res_city_school_district
6314 FROM PAY_US_EMP_CITY_TAX_RULES_F
6315 WHERE assignment_id = p_assignment_id
6316 AND jurisdiction_code = p_per_addr_geocode
6317 AND l_date_paid between effective_start_date and effective_end_date;
6318
6319 EXCEPTION
6320
6321 WHEN NO_DATA_FOUND THEN
6322
6323 l_res_city_school_district := '99999';
6324
6325 END;
6326
6327 -- get the resident psd.
6328 BEGIN
6329
6330 hr_utility.trace('GET_PSD_JD_CODE: Get resident PSD WITH School dsts code');
6331
6332 SELECT sch_information_category
6333 INTO l_res_psd_code
6334 FROM pay_us_school_dsts_tax_info_f
6335 WHERE jurisdiction_code = p_per_addr_geocode
6336 AND school_dsts_code = l_res_city_school_district
6337 AND l_date_paid between effective_start_date and effective_end_date
6338 AND SCH_INFORMATION1 = 'PSDCODES';
6339
6340 l_psd_jurisdiction_code := substr(p_per_addr_geocode,1,2) || '-' || l_res_psd_code;
6341
6342 hr_utility.trace('GET_PSD_JD_CODE: state resident PSD JD code for resident portion = ' || l_psd_jurisdiction_code);
6343 EXCEPTION
6344
6345 WHEN NO_DATA_FOUND THEN
6346
6347 l_psd_jurisdiction_code := substr(p_per_addr_geocode,1,2) || '-990000';
6348
6349 END;
6350
6351 END IF;
6352
6353 -- Attempt to get the PSD code for the work location. If to many rows query from
6354 -- the city w4 form (pay_us_city_tax_info_f) and fetch the work school district.
6355
6356 IF substr(p_loc_addr_geocode,1,2) <> '39' THEN
6357
6358 hr_utility.trace('GET_PSD_JD_CODE: state WORK jurisdiction is NOT PA returning dummy PSD JD code for WORK portion');
6359
6360 l_psd_jurisdiction_code := l_psd_jurisdiction_code || '-880000';
6361
6362 ELSE
6363
6364 BEGIN
6365
6366 hr_utility.trace('GET_PSD_JD_CODE: Get work PSD WITHOUT school dsts code');
6367
6368 SELECT sch_information_category
6369 INTO l_work_psd_code
6370 FROM pay_us_school_dsts_tax_info_f
6371 WHERE jurisdiction_code = p_loc_addr_geocode
6372 AND l_date_paid between effective_start_date and effective_end_date
6373 AND SCH_INFORMATION1 = 'PSDCODES';
6374
6375 l_psd_jurisdiction_code := l_psd_jurisdiction_code || '-' || l_work_psd_code;
6376
6377 hr_utility.trace( 'GET_PSD_JD_CODE: Derived PDS Code = ' || l_psd_jurisdiction_code);
6378
6379 EXCEPTION
6380
6381 WHEN TOO_MANY_ROWS THEN
6382
6383 hr_utility.trace('GET_PSD_JD_CODE: Exception to_many_rows' );
6384 -- get the work school distrtict code from the employees state_w4
6385 BEGIN
6386
6387 hr_utility.trace('GET_PSD_JD_CODE: Get work jd school dsts code');
6388
6389 SELECT school_district_code
6390 INTO l_work_city_school_district
6391 FROM PAY_US_EMP_CITY_TAX_RULES_F
6392 WHERE assignment_id = p_assignment_id
6393 AND jurisdiction_code = p_loc_addr_geocode
6394 AND l_date_paid between effective_start_date and effective_end_date;
6395
6396 -- ATTEMPT to get the work jurisdiction PSD with School District code
6397
6398 hr_utility.trace('GET_PSD_JD_CODE: Get work PSD WITH School dsts code');
6399
6400 SELECT sch_information_category
6401 INTO l_work_psd_code
6402 FROM pay_us_school_dsts_tax_info_f
6403 WHERE jurisdiction_code = p_loc_addr_geocode
6404 AND school_dsts_code = l_work_city_school_district
6405 AND l_date_paid between effective_start_date and effective_end_date
6406 AND SCH_INFORMATION1 = 'PSDCODES';
6407
6408 l_psd_jurisdiction_code := l_psd_jurisdiction_code || '-' || l_work_psd_code;
6409
6410 hr_utility.trace( 'GET_PSD_JD_CODE: Derived PDS Code = ' || l_psd_jurisdiction_code);
6411
6412 EXCEPTION
6413
6414 WHEN OTHERS THEN
6415
6416 hr_utility.trace( 'GET_PSD_JD_CODE: Error fetching work school district code ');
6417 l_psd_jurisdiction_code := l_psd_jurisdiction_code || '-990000';
6418
6419 END;
6420
6421 WHEN OTHERS THEN
6422
6423 hr_utility.trace( 'GET_PSD_JD_CODE: Error fetching work school PSD ');
6424 l_psd_jurisdiction_code := l_psd_jurisdiction_code || '-990000';
6425
6426
6427 END;
6428
6429 END IF;
6430
6431
6432 -- check PAY_US_ASG_REPORTING to see if the resident / work psd jurisdiction
6433 -- codes exists for the assignment. If not add it
6434
6435 -- The below if statement used to determine if we need to store the data in
6436 -- pay_us_asg_reporting. One of the PSD codes should be valid (IE not 880000)
6437
6438 IF substr(l_psd_jurisdiction_code,4,6) <> '880000'
6439 OR substr(l_psd_jurisdiction_code,11,6) <> '880000' THEN
6440
6441 BEGIN
6442
6443 SELECT 'Y'
6444 INTO l_asg_rep_row_exists
6445 FROM PAY_US_ASG_REPORTING
6446 WHERE assignment_id = p_assignment_id
6447 AND JURISDICTION_CODE = l_psd_jurisdiction_code
6448 AND TAX_UNIT_ID = p_tax_unit_id;
6449
6450 EXCEPTION
6451
6452 WHEN NO_DATA_FOUND THEN
6453
6454 hr_utility.trace('GET_PSD_JD_CODE: PSD ROW ' || l_psd_jurisdiction_code || ' not found in ASG_REPORTING.. INSERTING');
6455
6456 INSERT INTO PAY_US_ASG_REPORTING
6457 ( ASSIGNMENT_ID
6458 ,JURISDICTION_CODE
6459 ,TAX_UNIT_ID)
6460 VALUES
6461 ( p_assignment_id
6462 ,l_psd_jurisdiction_code
6463 ,p_tax_unit_id);
6464
6465 END;
6466
6467 END IF;
6468
6469
6470 hr_utility.trace('Exiting GET_PSD_JD_CODE PSD_JD_CODE = ' || l_psd_jurisdiction_code);
6471
6472
6473 return l_psd_jurisdiction_code;
6474
6475 END IF;
6476
6477 EXCEPTION
6478 WHEN OTHERS THEN
6479
6480 hr_utility.trace('Exception Exiting GET_PSD_JD_CODE PSD_JD_CODE = 00-990000-990000');
6481
6482 return '00-99000-990000';
6483
6484 END GET_PSD_JD_CODE;
6485
6486 --Wrapper on fnd_date.canonical_to_date for US Localization.
6487
6488 FUNCTION fnd_canonical_to_date(p_input VARCHAR2)
6489 RETURN DATE IS
6490
6491 BEGIN
6492
6493 RETURN fnd_date.canonical_to_date(p_input);
6494
6495 END fnd_canonical_to_date;
6496
6497 /*End Bug#12583094*/
6498
6499 /*Function created for Bug#12618403*/
6500
6501 FUNCTION get_ht_withheld_per_jd_month( p_assignment_action_id IN number --Context
6502 ,p_jurisdiction_code IN varchar2) --Context
6503 RETURN NUMBER IS
6504
6505 CURSOR get_balance_type_id IS
6506 SELECT balance_type_id
6507 FROM pay_balance_types
6508 WHERE balance_name = 'Head Tax Withheld'
6509 AND legislation_code = 'US';
6510
6511 CURSOR get_value (p_asgmnt_action_id NUMBER,
6512 p_jurisdiction_code VARCHAR2,
6513 p_balance_type_id NUMBER) IS
6514 SELECT /*+ RULE*/ nvl(sum(fnd_number.canonical_to_number(TARGET.result_value) * FEED.scale),0)
6515 FROM pay_run_result_values TARGET
6516 ,pay_balance_types BAL
6517 ,pay_balance_feeds_f FEED
6518 ,pay_run_results RR
6519 ,pay_assignment_actions ASSACT
6520 ,pay_assignment_actions BAL_ASSACT
6521 ,pay_payroll_actions PACT
6522 ,pay_payroll_actions BACT
6523 ,per_all_assignments_f ASS
6524 WHERE BAL_ASSACT.assignment_action_id = p_asgmnt_action_id
6525 AND BAL_ASSACT.payroll_action_id = BACT.payroll_action_id
6526 AND FEED.balance_type_id = p_balance_type_id + decode(TARGET.INPUT_VALUE_ID, null, 0, 0)
6527 AND FEED.input_value_id = TARGET.input_value_id
6528 AND nvl(TARGET.result_value,'0') <> '0'
6529 AND TARGET.run_result_id = RR.run_result_id
6530 AND RR.assignment_action_id = ASSACT.assignment_action_id
6531 AND ASSACT.payroll_action_id = PACT.payroll_action_id
6532 AND PACT.effective_date between FEED.effective_start_date
6533 and FEED.effective_end_date
6534 AND RR.status in ('P','PA')
6535 AND ASSACT.action_sequence <= BAL_ASSACT.action_sequence
6536 AND ASSACT.assignment_id = ASS.assignment_id
6537 AND ASS.person_id = (select person_id from per_all_assignments_f START_ASS
6538 where START_ASS.assignment_id = BAL_ASSACT.assignment_id
6539 and rownum = 1)
6540 AND PACT.effective_date between ASS.effective_start_date
6541 and ASS.effective_end_date
6542 /* Month To Date */
6543 AND trunc(PACT.effective_date,'MM')
6544 = trunc(BACT.effective_date,'MM')
6545 /* Within Jurisdiction */
6546 and BAL.balance_type_id = p_balance_type_id
6547 and substr (SUBSTR(RR.jurisdiction_code,1,3)||'000'||SUBSTR(RR.jurisdiction_code,7), 1, BAL.jurisdiction_level) =
6548 substr (SUBSTR(p_jurisdiction_code,1,3)||'000'||SUBSTR(p_jurisdiction_code,7), 1, BAL.jurisdiction_level);
6549
6550 l_balance_type_id NUMBER;
6551 l_balance_value NUMBER;
6552
6553 BEGIN
6554
6555 hr_utility.trace('Inside hr_us_ff_udf1.get_ht_withheld_per_jd_month function');
6556
6557 OPEN get_balance_type_id;
6558 FETCH get_balance_type_id INTO l_balance_type_id;
6559 CLOSE get_balance_type_id;
6560
6561 OPEN get_value(p_assignment_action_id,p_jurisdiction_code,l_balance_type_id);
6562 FETCH get_value INTO l_balance_value;
6563 CLOSE get_value;
6564
6565 hr_utility.trace('Leaving hr_us_ff_udf1.get_ht_withheld_per_jd_month function');
6566 hr_utility.trace('Return Value :'||l_balance_value);
6567
6568 RETURN l_balance_value;
6569
6570 EXCEPTION
6571 WHEN OTHERS THEN
6572 hr_utility.trace('Exception raised in hr_us_ff_udf1.get_ht_withheld_per_jd_month function. Returning Zero');
6573 RETURN 0;
6574
6575 END;
6576
6577 /*End Bug#12618403*/
6578
6579 END hr_us_ff_udf1;