[Home] [Help]
PACKAGE BODY: APPS.HXT_TIME_DETAIL
Source
1 PACKAGE BODY hxt_time_detail AS
2 /* $Header: hxttdet.pkb 120.34.12010000.4 2008/09/24 09:50:01 sabvenug ship $ */
3 --
4 -- Global variables for package
5 -- Used for parameters received that are not changed
6 g_debug BOOLEAN := hr_utility.debug_enabled;
7 g_ep_id NUMBER;
8 g_ep_type hxt_earning_policies.fcl_earn_type%TYPE;
9 g_egt_id NUMBER;
10 g_sdf_id NUMBER;
11 g_hdp_id NUMBER;
12 g_hol_id NUMBER;
13 g_sdp_id NUMBER; -- ORACLE bug #715964
14 g_pep_id NUMBER;
15 g_pip_id NUMBER;
16 g_sdovr_id NUMBER;
17 g_osp_id NUMBER;
18 g_hol_yn VARCHAR2 (1);
19 g_person_id NUMBER;
20 g_id NUMBER;
21 g_tim_id NUMBER;
22 g_date_worked DATE;
23 g_assignment_id NUMBER;
24 g_hours NUMBER;
25 g_time_in DATE;
26 g_time_out DATE;
27 g_element_type_id NUMBER;
28 g_fcl_earn_reason_code hxt_det_hours_worked.fcl_earn_reason_code%TYPE;
29 --C421
30 g_ffv_cost_center_id NUMBER;
31 g_ffv_labor_account_id NUMBER;
32 g_tas_id NUMBER;
33 g_location_id NUMBER;
34 g_sht_id NUMBER;
35 g_hrw_comment hxt_det_hours_worked.hrw_comment%TYPE; --C421
36 g_ffv_rate_code_id NUMBER;
37 g_rate_multiple NUMBER;
38 g_hourly_rate NUMBER;
39 g_amount NUMBER;
40 g_fcl_tax_rule_code hxt_det_hours_worked.fcl_tax_rule_code%TYPE;
41 --C421
42 g_separate_check_flag hxt_det_hours_worked.separate_check_flag%TYPE;
43 --C421
44 g_seqno NUMBER;
45 g_created_by NUMBER;
46 g_creation_date DATE;
47 g_last_updated_by NUMBER;
48 g_last_update_date DATE;
49 g_last_update_login NUMBER;
50 g_start_day_of_week CHAR (30); -- Increased to fit the whole name.
51 g_effective_start_date DATE;
52 g_effective_end_date DATE;
53 g_project_id NUMBER; -- PROJACCT
54 g_job_id NUMBER; -- TA35
55 g_pay_status CHAR (1); -- RETROPAY
56 g_pa_status CHAR (1); -- PROJACCT
57 g_period_start_date DATE;
58 g_retro_batch_id NUMBER; -- RETROPAY
59 b_first_time BOOLEAN; -- ZEROHRS
60 g_location VARCHAR2 (100);
61 --g_group_id NUMBER; -- HXT11i1
62 l_time_in DATE; -- SIR132
63 l_time_out DATE; -- SIR132
64 g_call_adjust_abs VARCHAR2 (1);
65 g_state_name hxt_det_hours_worked_f.state_name%TYPE;
66 g_county_name hxt_det_hours_worked_f.county_name%TYPE;
67 g_city_name hxt_det_hours_worked_f.city_name%TYPE;
68 g_zip_code hxt_det_hours_worked_f.zip_code%TYPE;
69
70 CURSOR check_abs_elem
71 IS
72 -- SELECT 'exist'
73 -- FROM sys.dual
74 -- WHERE EXISTS (
75 SELECT 'x'
76 FROM hxt_earn_groups erg, hxt_earning_policies egp
77 WHERE egp.ID = g_ep_id
78 AND erg.egt_id = egp.egt_id
79 AND erg.element_type_id = g_element_type_id;
80
81 l_abs_in_eg VARCHAR2 (5) := NULL;
82
83 CURSOR check_spc_dy_eg
84 IS
85 SELECT 'x'
86 FROM hxt_earn_group_types egt
87 WHERE egt.NAME = 'OTLR 7th Day Hours';
88
89 g_spc_dy_eg VARCHAR2 (1) := NULL;
90
91 --begin hxt11i1
92 --
93 -- The first part of the related_prem cursor looks for premium rows that are
94 -- not REG or OVT, but have a higher seqno than the one passed in. The second
95 -- part of the cursor (sub select) looks for REG and OVT rows with higher
96 -- sequence numbers than the one passed in. This is an effort to sandwich
97 -- premiums between their related REG and OVT elements. Without this there is
98 -- no guarantee thata premium selected would be associated with any given REG
99 -- or OVT row in the hxt_det_hours_worked_f table.
100 CURSOR related_prem (
101 a_parent_id NUMBER,
102 a_tim_id NUMBER,
103 a_seqno NUMBER,
104 a_hours NUMBER
105 )
106 IS
107 SELECT hrw.ROWID prem_row_id, hrw.seqno, hrw.time_in prem_time_in,
108 hrw.time_out prem_time_out, hrw.hours prem_hours,
109 elt.element_name
110 FROM hxt_pay_element_types_f_ddf_v eltv,
111 pay_element_types_f elt,
112 hxt_det_hours_worked hrw
113 WHERE hrw.tim_id = a_tim_id
114 AND hrw.parent_id = a_parent_id
115 AND hrw.seqno > a_seqno
116 -- The sub select below tries to keep this cursor bound to premiums
117 -- that fall between the REG and OVT pay elements that may already
118 -- exist on the detail table so that we don't get the wrong premium
119 -- when adjusting the hours on premiums rows
120 AND ( -- Be sure we stay with premiums for the detail record being
121 -- dealt with
122 (hrw.seqno <
123 (SELECT MIN (det.seqno)
124 FROM hxt_pay_element_types_f_ddf_v eltv2,
125 pay_element_types_f elt2,
126 hxt_det_hours_worked det
127 WHERE det.tim_id = a_tim_id
128 AND det.parent_id = a_parent_id
129 AND det.seqno > a_seqno
130 AND det.element_type_id = elt2.element_type_id
131 AND eltv2.hxt_earning_category IN ('REG', 'OVT')
132 AND det.date_worked BETWEEN elt2.effective_start_date
133 AND elt2.effective_end_date
134 AND eltv2.element_type_id = elt2.element_type_id
135 AND det.date_worked BETWEEN eltv2.effective_start_date
136 AND eltv2.effective_end_date)
137 )
138 OR -- Proceed if no REG and OVT elements exist for other
139
140 -- detail records
141 (NOT EXISTS (
142 SELECT det.seqno
143 FROM hxt_pay_element_types_f_ddf_v eltv2,
144 pay_element_types_f elt2,
145 hxt_det_hours_worked det
146 WHERE det.tim_id = a_tim_id
147 AND det.parent_id = a_parent_id
148 AND det.seqno > a_seqno
149 AND det.element_type_id = elt2.element_type_id
150 AND eltv2.hxt_earning_category IN ('REG', 'OVT')
151 AND det.date_worked BETWEEN elt2.effective_start_date
152 AND elt2.effective_end_date
153 AND eltv2.element_type_id = elt2.element_type_id
154 AND det.date_worked BETWEEN eltv2.effective_start_date
155 AND eltv2.effective_end_date)
156 )
157 )
158 AND elt.element_type_id = hrw.element_type_id
159 AND eltv.hxt_earning_category NOT IN ('REG', 'OVT')
160 AND hrw.date_worked BETWEEN elt.effective_start_date
161 AND elt.effective_end_date
162 AND NVL (hrw.hours, 0) <> 0
163 AND eltv.element_type_id = elt.element_type_id
164 AND hrw.date_worked BETWEEN eltv.effective_start_date
165 AND eltv.effective_end_date;
166
167 -- Function and Procedure declarations
168 FUNCTION contig_hours_worked (
169 p_date_worked IN hxt_det_hours_worked_f.date_worked%TYPE,
170 p_egt_id IN hxt_earn_groups.egt_id%TYPE,
171 p_tim_id IN hxt_det_hours_worked_f.tim_id%TYPE
172 )
173 RETURN hxt_det_hours_worked.hours%TYPE;
174
175 PROCEDURE overtime_hoursoverride (
176 p_date_worked IN hxt_det_hours_worked_f.date_worked%TYPE,
177 p_egt_id IN hxt_earn_groups.egt_id%TYPE,
178 p_tim_id IN hxt_det_hours_worked_f.tim_id%TYPE,
179 p_override_hrs OUT NOCOPY hxt_det_hours_worked_f.hours%TYPE,
180 p_override_element OUT NOCOPY hxt_det_hours_worked_f.element_type_id%TYPE
181 );
182
183 FUNCTION delete_zero_hour_details (
184 a_tim_id NUMBER,
185 a_ep_id NUMBER,
186 a_osp_id NUMBER,
187 a_date_worked DATE
188 )
189 RETURN NUMBER;
190
191 FUNCTION combine_contig_chunks
192 RETURN NUMBER;
193
194 FUNCTION holiday_rule_found (
195 p_ep_id IN hxt_earning_policies.ID%TYPE,
196 p_date_worked IN hxt_det_hours_worked_f.date_worked%TYPE
197 )
198 RETURN BOOLEAN
199 IS
200 l_holiday_rule_found BOOLEAN;
201 l_count_holiday_rules PLS_INTEGER;
202 c_holiday_rule CONSTANT hxt_earning_rules.egr_type%TYPE := 'HOL';
203 c_no_rule CONSTANT NUMBER := 0;
204 BEGIN
205 SELECT COUNT (1)
206 INTO l_count_holiday_rules
207 FROM hxt_earning_rules
208 WHERE egp_id = p_ep_id AND egr_type = c_holiday_rule
209 AND p_date_worked between effective_start_date and effective_end_date;
210
211 IF (l_count_holiday_rules > c_no_rule)
212 THEN
213 l_holiday_rule_found := TRUE;
214 ELSE
215 l_holiday_rule_found := FALSE;
216 END IF;
217 RETURN l_holiday_rule_found;
218 END holiday_rule_found;
219
220 FUNCTION call_gen_error (
221 p_location IN VARCHAR2,
222 p_error_text IN VARCHAR2,
223 p_oracle_error_text IN VARCHAR2 DEFAULT NULL
224 )
225 RETURN NUMBER
226 IS
227 -- calls error processing procedure --
228 BEGIN
229 hxt_util.gen_error (g_tim_id,
230 g_id,
231 NULL,
232 p_error_text,
233 p_location,
234 p_oracle_error_text,
235 g_effective_start_date,
236 g_effective_end_date,
237 'ERR'
238 );
239 hxt_util.DEBUG ('Return code is 2 from call gen error');
240 RETURN 2;
241 END;
242
243 FUNCTION call_hxthxc_gen_error (
244 p_app_short_name IN VARCHAR2,
245 p_msg_name IN VARCHAR2,
246 p_msg_token IN VARCHAR2,
247 p_location IN VARCHAR2,
248 p_error_text IN VARCHAR2,
249 p_oracle_error_text IN VARCHAR2 DEFAULT NULL
250 )
251 RETURN NUMBER
252 IS
253 -- calls error processing procedure --
254 BEGIN
255 hxt_util.gen_error (g_tim_id,
256 g_id,
257 NULL,
258 p_error_text,
259 p_location,
260 p_oracle_error_text,
261 g_effective_start_date,
262 g_effective_end_date,
263 'ERR'
264 );
265 hxc_time_entry_rules_utils_pkg.add_error_to_table
266 (p_message_table => hxt_hxc_retrieval_process.g_otm_messages,
267 p_message_name => p_msg_name,
268 p_message_token => NULL,
269 p_message_level => 'ERROR',
270 p_message_field => NULL,
271 p_application_short_name => p_app_short_name,
272 p_timecard_bb_id => NULL,
273 p_time_attribute_id => NULL,
274 p_timecard_bb_ovn => NULL,
275 p_time_attribute_ovn => NULL
276 );
277
278 IF g_debug
279 THEN
280 hr_utility.TRACE ('Adding to g_otm_messages' || p_msg_name);
281 END IF;
282
283 hxt_util.DEBUG ('Return code is 2 from call gen error');
284 RETURN 2;
285 END;
286
287 FUNCTION pay (
288 a_hours_to_pay IN NUMBER,
289 a_pay_element_type_id IN NUMBER,
290 a_time_in IN DATE,
291 a_time_out IN DATE,
292 a_date_worked IN DATE,
293 a_id IN NUMBER, -- parent id
294 a_assignment_id IN NUMBER,
295 a_fcl_earn_reason_code IN VARCHAR2,
296 a_ffv_cost_center_id IN NUMBER,
297 a_ffv_labor_account_id IN NUMBER,
298 a_tas_id IN NUMBER,
299 a_location_id IN NUMBER,
300 a_sht_id IN NUMBER,
301 a_hrw_comment IN VARCHAR2,
302 a_ffv_rate_code_id IN NUMBER,
303 a_rate_multiple IN NUMBER,
304 a_hourly_rate IN NUMBER,
305 a_amount IN NUMBER,
306 a_fcl_tax_rule_code IN VARCHAR2,
307 a_separate_check_flag IN VARCHAR2,
308 a_project_id IN NUMBER,
309 -- a_GROUP_ID IN NUMBER,
310 a_earn_policy_id IN NUMBER,
311 a_sdf_id IN NUMBER DEFAULT NULL,
312 a_state_name IN VARCHAR2 DEFAULT NULL,
313 a_county_name IN VARCHAR2 DEFAULT NULL,
314 a_city_name IN VARCHAR2 DEFAULT NULL,
315 a_zip_code IN VARCHAR2 DEFAULT NULL
316 )
317 RETURN NUMBER;
318
319 FUNCTION gen_special (
320 p_location IN VARCHAR2,
321 p_time_in IN DATE,
322 p_time_out IN DATE,
323 p_hours_worked IN NUMBER,
324 p_shift_diff_earning_id IN NUMBER,
325 p_sdovr_earning_id IN NUMBER
326 )
327 RETURN NUMBER;
328
329 ------------ generate special loads globals and calls gen_special-----------
330 ------------ return 0 normal 1 warning 2 error -----------
331 FUNCTION generate_special (
332 p_ep_id IN NUMBER,
333 p_ep_type IN VARCHAR2,
334 p_egt_id IN NUMBER,
335 p_sdf_id IN NUMBER,
336 p_hdp_id IN NUMBER,
337 p_hol_id IN NUMBER,
338 p_sdp_id IN NUMBER,
339 p_pep_id IN NUMBER,
340 p_pip_id IN NUMBER,
341 p_sdovr_id IN NUMBER,
342 p_osp_id IN NUMBER,
343 p_hol_yn IN VARCHAR2,
344 p_person_id IN NUMBER,
345 p_location IN VARCHAR2,
346 p_id IN NUMBER,
347 p_tim_id IN NUMBER,
348 p_date_worked IN DATE,
349 p_assignment_id IN NUMBER,
350 p_hours IN NUMBER,
351 p_time_in IN DATE,
352 p_time_out IN DATE,
353 p_element_type_id IN NUMBER,
354 p_fcl_earn_reason_code IN VARCHAR2,
355 p_ffv_cost_center_id IN NUMBER,
356 p_ffv_labor_account_id IN NUMBER,
357 p_tas_id IN NUMBER,
358 p_location_id IN NUMBER,
359 p_sht_id IN NUMBER,
360 p_hrw_comment IN VARCHAR2,
361 p_ffv_rate_code_id IN NUMBER,
362 p_rate_multiple IN NUMBER,
363 p_hourly_rate IN NUMBER,
364 p_amount IN NUMBER,
365 p_fcl_tax_rule_code IN VARCHAR2,
366 p_separate_check_flag IN VARCHAR2,
367 p_seqno IN NUMBER,
368 p_created_by IN NUMBER,
369 p_creation_date IN DATE,
370 p_last_updated_by IN NUMBER,
371 p_last_update_date IN DATE,
372 p_last_update_login IN NUMBER,
373 p_start_day_of_week IN VARCHAR2,
374 p_effective_start_date IN DATE,
375 p_effective_end_date IN DATE,
376 p_project_id IN NUMBER, -- PROJACCT
377 p_job_id IN NUMBER, -- TA35
378 p_pay_status IN VARCHAR2, -- RETROPAY
379 p_pa_status IN VARCHAR2, -- PROJACCT
380 p_retro_batch_id IN NUMBER, -- RETROPAY
381 p_period_start_date IN DATE,
382 p_call_adjust_abs IN VARCHAR2,
383 p_state_name IN VARCHAR2 DEFAULT NULL,
384 p_county_name IN VARCHAR2 DEFAULT NULL,
385 p_city_name IN VARCHAR2 DEFAULT NULL,
386 p_zip_code IN VARCHAR2 DEFAULT NULL
387 )
388 -- p_GROUP_ID IN NUMBER) -- HXT11i1
389 RETURN NUMBER
390 IS
391 BEGIN
392 g_debug := hr_utility.debug_enabled;
393
394 IF g_debug
395 THEN
396 hr_utility.set_location ('hxt_time_detail.GENERATE_SPECIAL', 10);
397 hr_utility.TRACE ( 'p_time_in :'
398 || TO_CHAR (p_time_in, 'DD-MON-YYYY HH24:MI:SS')
399 );
400 hr_utility.TRACE ( 'p_time_out :'
401 || TO_CHAR (p_time_out, 'DD-MON-YYYY HH24:MI:SS')
402 );
403 END IF;
404
405 -- Set global variables for package with parameter values
406 g_ep_id := p_ep_id;
407 g_ep_type := p_ep_type;
408 g_egt_id := p_egt_id;
409 g_sdf_id := p_sdf_id;
410 g_hdp_id := p_hdp_id;
411 g_hol_id := p_hol_id;
412 g_sdp_id := p_sdp_id; -- ORACLE bug #715964
413 g_pep_id := p_pep_id;
414 g_pip_id := p_pip_id;
415 g_sdovr_id := p_sdovr_id;
416 g_osp_id := p_osp_id;
417 g_hol_yn := p_hol_yn;
418 g_person_id := p_person_id;
419 g_id := p_id;
420 g_tim_id := p_tim_id;
421 g_date_worked := p_date_worked;
422 g_assignment_id := p_assignment_id;
423 g_hours := p_hours;
424 g_time_in := p_time_in;
425 g_time_out := p_time_out;
426 g_element_type_id := p_element_type_id;
427 g_fcl_earn_reason_code := p_fcl_earn_reason_code;
428 g_ffv_cost_center_id := p_ffv_cost_center_id;
429 g_ffv_labor_account_id := p_ffv_labor_account_id;
430 g_tas_id := p_tas_id;
431 g_location_id := p_location_id;
432 g_sht_id := p_sht_id;
433 g_hrw_comment := p_hrw_comment;
434 g_ffv_rate_code_id := p_ffv_rate_code_id;
435 g_rate_multiple := p_rate_multiple;
436 g_hourly_rate := p_hourly_rate;
437 g_amount := p_amount;
438 g_fcl_tax_rule_code := p_fcl_tax_rule_code;
439 g_separate_check_flag := p_separate_check_flag;
440 g_seqno := p_seqno;
441 g_created_by := p_created_by;
442 g_creation_date := p_creation_date;
443 g_last_updated_by := p_last_updated_by;
444 g_last_update_date := p_last_update_date;
445 g_last_update_login := p_last_update_login;
446 g_start_day_of_week := p_start_day_of_week;
447 g_effective_start_date := p_effective_start_date;
448 g_effective_end_date := p_effective_end_date;
449 g_project_id := p_project_id; -- PROJACCT
450 g_job_id := p_job_id;
451 g_pay_status := p_pay_status; -- RETROPAY
452 g_pa_status := p_pa_status; -- PROJACCT
453 g_retro_batch_id := p_retro_batch_id; -- RETROPAY
454 g_location := p_location; -- RETROPAY
455 g_period_start_date := p_period_start_date;
456 g_call_adjust_abs := p_call_adjust_abs;
457 g_state_name := p_state_name;
458 g_county_name := p_county_name;
459 g_city_name := p_city_name;
460 g_zip_code := p_zip_code;
461
462 -- g_GROUP_ID := p_GROUP_ID; -- HXT11i1
463 IF g_debug
464 THEN
465 hr_utility.set_location ('hxt_time_detail.GENERATE_SPECIAL', 20);
466 END IF;
467
468 RETURN gen_special (p_location,
469 g_time_in,
470 g_time_out,
471 g_hours,
472 g_sdf_id,
473 g_sdovr_id
474 );
475
476 IF g_debug
477 THEN
478 hr_utility.set_location ('hxt_time_detail.GENERATE_SPECIAL', 30);
479 END IF;
480 -- parameters used for compatibility with this version of gen special
481 END;
482
483 --
484 ----------------------------------GEN SPECIAL-----------------------------------
485 --
486 FUNCTION gen_special (
487 p_location IN VARCHAR2,
488 p_time_in IN DATE,
489 p_time_out IN DATE,
490 p_hours_worked IN NUMBER,
491 p_shift_diff_earning_id IN NUMBER,
492 p_sdovr_earning_id IN NUMBER
493 )
494 RETURN NUMBER
495 IS
496 -- Function GEN_SPECIAL
497 -- Purpose
498 -- Generate detail base and overtime records for the summary record that is
499 -- passed.This is called for earning policies where overtime is calculated
500 -- on a special basis.The earning rules are applied based on the category
501 -- that is passed (NULL or ABS).
502 --
503 -- To handle a summary hours record that spans shifts, the calling routine
504 -- splits the hours into segments that coincide with the shifts. It then
505 -- passes the time in and out of the segment, as well as the hours worked.
506 -- The times in and out are given so they may be inserted in the hours worked
507 -- table.Times,hours and shift differential earning are passed as parameters
508 -- as they are determined by the gen_details routine and not by the globals.
509 --
510 -- Returns
511 -- 0 - No errors occured
512 -- 1 - Warnings occured
513 -- 2 - Errors occured
514
515 -- Arguments
516 -- p_time_in - Received time in
517 -- p_time_out - Received time out
518 -- p_hours_worked - Received number of hours worked in segment
519 -- p_shift_diff_earning_id - Received id of shift diff earning -- if
520 -- applicable - It is passed unchanged to
521 -- gen premiums
522 -- p_location - The procedure and/or function path where an
523 -- error occurred -- Local variables - These may
524 -- be read by all local functions but should only
525 -- be modified by the main gen_special section
526 ERROR_CODE NUMBER := 0;
527 l_error_return NUMBER := 0; --SIR014
528 LOCATION VARCHAR2 (120) := p_location || ':SPCL';
529 summary_earning_category VARCHAR2 (10);
530 -- category of earning from
531 -- summary - NULL or ABS
532 rule_type_to_pay VARCHAR2 (3);
533 -- rule type to use ABS,HOL,DAY
534 hours_left_to_pay NUMBER; -- hours left to pay on this
535 -- segment
536 daily_rule_cap NUMBER; -- number of hours that the
537 -- current daily rule spans
538 hours_paid_daily_rule NUMBER;
539 -- number of hours that have been
540 -- accumulated toward finishing
541 -- the current daily rule
542 daily_earning_type NUMBER;
543 -- earning element type to apply
544 -- to current daily rule
545 previous_detail_hours_day NUMBER; -- hours on the details of
546 -- previous summaries this day
547 weekly_rule_cap NUMBER; -- number of hours that the
548 -- current weekly rule spans
549 weekly_earning_type NUMBER;
550 -- earning element to apply AFTER
551 -- the weekly cap is hit
552 hours_paid_weekly_rule NUMBER;
553 -- number of hours that have been
554 -- accumulated toward finishing
555 -- the current weekly rule
556 hours_paid_for_dtime_elig NUMBER;
557 -- number of hours paid to check
558 -- whether eligible for doubletime
559 current_weekly_earning NUMBER;
560 -- type being paid on weekly policy
561 weekly_pay_back_earning_type NUMBER;
562 weekly_pay_back_cap NUMBER;
563 in_pay_back_period BOOLEAN := FALSE;
564 saved_weekly_earning_type NUMBER;
565 -- earning element id of current
566 -- rule saved when reading next
567 -- rule in case there is no next
568 -- rule
569 previous_detail_hours_week NUMBER;
570 -- hours on the details of previous
571 -- summaries this week
572 first_weekly_cap_reached BOOLEAN := FALSE;
573 second_weekly_cap_reached BOOLEAN := FALSE;
574 consecutive_days_reached BOOLEAN;
575 -- TRUE means # of days have been
576 -- worked for special to apply
577 consecutive_days_limit NUMBER; -- number of days to work until
578 -- special rule applies
579 consec_days_worked NUMBER; -- SIR431 number of consec days
580 -- worked
581 special_daily_cap NUMBER;
582 -- number of hours to work during
583 -- which special_earning_type
584 -- applies after the consecutive
585 -- days limit is hit
586 special_earning_type NUMBER;
587 -- earning element id to apply
588 -- after consec. days limit is hit
589 -- Begin SPR C355
590 special_earning_type2 NUMBER;
591 -- earning element id to apply
592 -- after special_daily_cap is hit
593 special_daily_cap2 NUMBER;
594 -- number of hours to work during
595 -- which special_earning_type2
596 -- applies
597 consecutive_days_limit2 NUMBER; -- dummy - not used.
598 -- End SPR C355
599 special_and_weekly_base NUMBER;
600 -- the base earning element
601 -- applied to special and weekly
602 -- before their caps are hit as
603 -- they do not specify one
604 seven_day_cal_rule BOOLEAN;
605 -- TRUE when earn pol has 7 day
606 -- SPC rule --SIR017
607 five_day_cal_rule BOOLEAN;
608 -- TRUE when earn pol has 5 day
609 -- SPC rule --SIR017
610 g_cons_days_worked NUMBER; -- holds number of consecutive
611 -- days worked --SIR017
612 first_daily_rule_cap NUMBER;
613 -- number of hours that the first
614 -- daily rule spans --SIR017
615 l_day_total NUMBER;
616 -- number of hours worked on 6th
617 -- day of 7 day SPCrule--SIR017
618 -- End PICKWKLDAY SIR017
619 dummy_days NUMBER;
620 -- variable used to fetch daily
621 -- rule with same cursor as special
622 fetch_next_day BOOLEAN;
623 -- flag set to TRUE when a cap is
624 -- hit and next rule should be read
625 fetch_next_week BOOLEAN;
626 rule_to_pay VARCHAR2 (4);
627 -- string set to 'DAY' 'WKL' or
628 -- 'SPC' to show which rule applies
629 -- to a given sub-segment
630 hours_to_pay_this_rule NUMBER; -- number of hours of this
631 -- sub-segment
632 element_type_id_to_pay NUMBER;
633 -- element type of the sub-segment
634 start_day_of_week VARCHAR2 (30) := g_start_day_of_week;
635 end_of_day_rules BOOLEAN := FALSE;
636 -- TRUE signifies that last daily
637 -- rule has been read
638 loop_counter NUMBER := 0;
639 -- counts loop iterations for
640 -- checking
641 -- MHANDA
642 l_use_points_assigned VARCHAR2 (3);
643
644 -- variable used to fetch the value
645 -- of the flag ,checked or
646 -- unchecked ,to determine the
647 -- logic to be used for applying
648 -- the daily and weekly rules
649 CURSOR spc_earn_rules_cur (i_earn_policy NUMBER, i_days NUMBER)
650 IS
651 SELECT er.hours, er.element_type_id, er.days
652 FROM hxt_earning_rules er
653 WHERE er.egr_type = 'SPC'
654 AND er.days <= i_days
655 AND er.days IS NOT NULL
656 AND er.egp_id = i_earn_policy
657 AND g_date_worked BETWEEN er.effective_start_date
658 AND er.effective_end_date
659 ORDER BY er.days DESC, er.hours ASC;
660
661 CURSOR daily_earn_rules_cur (i_earn_policy NUMBER, i_egr_type VARCHAR2)
662 IS
663 SELECT er.hours, er.element_type_id, er.days
664 FROM hxt_earning_rules er
665 WHERE er.egr_type = i_egr_type
666 AND er.egp_id = i_earn_policy
667 AND g_date_worked BETWEEN er.effective_start_date
668 AND er.effective_end_date
669 ORDER BY er.seq_no;
670
671 CURSOR weekly_earn_rules_cur (i_earn_policy NUMBER)
672 IS
673 SELECT er.hours, er.element_type_id
674 FROM hxt_earning_rules er
675 WHERE er.egr_type = 'WKL'
676 AND er.egp_id = i_earn_policy
677 AND g_date_worked BETWEEN er.effective_start_date
678 AND er.effective_end_date
679 ORDER BY er.seq_no;
680
681 --SIR015
682 --CURSOR all_details_hours_day(cursor_day_worked DATE
683 -- , cursor_person_id NUMBER) IS
684 CURSOR all_details_hours_day (
685 cursor_day_worked DATE,
686 cursor_person_id NUMBER,
687 cursor_tim_id NUMBER
688 )
689 IS
690 SELECT daily_hours
691 FROM hxt_daily_hours_worked_v
692 WHERE work_date || '' = cursor_day_worked AND tim_id = cursor_tim_id;
693
694 FUNCTION get_weekly_total
695 RETURN NUMBER
696 IS
697 weekly_base_hours NUMBER;
698 weekly_total_hours NUMBER;
699 BEGIN
700 weekly_base_hours :=
701 hxt_td_util.get_weekly_total (LOCATION,
702 g_date_worked,
703 start_day_of_week,
704 g_tim_id,
705 special_and_weekly_base,
706 g_ep_id,
707 g_person_id
708 );
709 RETURN weekly_base_hours;
710 END;
711
712 FUNCTION get_weekly_total_prev_days
713 RETURN NUMBER
714 IS
715 weekly_base_hours NUMBER;
716 weekly_total_hours NUMBER;
717 BEGIN
718 weekly_base_hours :=
719 hxt_td_util.get_weekly_total_prev_days (LOCATION,
720 g_date_worked,
721 start_day_of_week,
722 g_tim_id,
723 special_and_weekly_base,
724 g_ep_id,
725 g_person_id
726 );
727 RETURN weekly_base_hours;
728 END get_weekly_total_prev_days;
729
730 FUNCTION get_weekly_total_to_date (
731 cp_earn_category IN VARCHAR2 DEFAULT NULL
732 )
733 RETURN NUMBER
734 IS
735 CURSOR weekly_total_to_date
736 IS
737 SELECT NVL (SUM (hrw.hours), 0)
738 FROM hxt_pay_element_types_f_ddf_v eltv,
739 pay_element_types_f elt,
740 hxt_earning_policies egp,
741 hxt_per_aei_ddf_v asmv,
742 per_assignments_f asm,
743 hxt_det_hours_worked hrw,
744 hxt_timecards tim
745 WHERE hrw.parent_id > 0
746 AND hrw.date_worked BETWEEN NEXT_DAY (g_date_worked - 7,
747 start_day_of_week
748 )
749 AND (g_date_worked - 1)
750 AND asm.assignment_id = hrw.assignment_id
751 AND eltv.hxt_earning_category LIKE NVL (cp_earn_category, '%')
752 AND hrw.date_worked BETWEEN asm.effective_start_date
753 AND asm.effective_end_date
754 AND asm.assignment_id = asmv.assignment_id
755 AND hrw.date_worked BETWEEN asmv.effective_start_date
756 AND asmv.effective_end_date
757 -- Commented out for OTLR Recurrring Period Preference support.
758 -- AND tim_id = g_tim_id
759 -- Added the following for OTLR Recurrring Period Preference support.
760 AND tim.for_person_id = g_person_id
761 AND tim.ID = hrw.tim_id
762 AND elt.element_type_id = hrw.element_type_id
763 AND ( -- If absence, only include earnings to be counted toward
764 -- hours to be worked before being eligible for overtime.
765
766 --USEEARNGROUP -- include ANY earnings, not just absences. RTF
767 ( EXISTS (
768 SELECT 1
769 FROM hxt_earn_groups erg
770 WHERE erg.egt_id = egp.egt_id
771 AND erg.element_type_id = elt.element_type_id)
772 AND egp.egt_id IS NOT NULL
773 )
774 )
775 AND hrw.date_worked BETWEEN egp.effective_start_date
776 AND egp.effective_end_date
777 -- next line changed to use override earning policy.
778 -- AND egp.id = asmv.hxt_earning_policy
779 AND egp.ID = g_ep_id
780 AND hrw.date_worked BETWEEN elt.effective_start_date
781 AND elt.effective_end_date
782 AND eltv.element_type_id = elt.element_type_id
783 AND hrw.date_worked BETWEEN eltv.effective_start_date
784 AND eltv.effective_end_date;
785
786 l_weekly_total_to_date NUMBER;
787 BEGIN
788 OPEN weekly_total_to_date;
789
790 FETCH weekly_total_to_date
791 INTO l_weekly_total_to_date;
792
793 CLOSE weekly_total_to_date;
794
795 RETURN NVL (l_weekly_total_to_date, 0);
796 END get_weekly_total_to_date;
797
798 -- Function added to calculate total hours to be worked before being
799 -- eligible for doubletime -- MHANDA
800 FUNCTION get_wkly_total_for_doubletime
801 RETURN NUMBER
802 IS
803 CURSOR weekly_total_to_date
804 IS
805 SELECT NVL (SUM (hrw.hours), 0)
806 FROM hxt_pay_element_types_f_ddf_v eltv,
807 pay_element_types_f elt,
808 hxt_earn_groups erg,
809 hxt_earning_policies egp,
810 hxt_per_aei_ddf_v asmv,
811 per_assignments_f asm,
812 hxt_det_hours_worked hrw,
813 hxt_timecards tim
814 WHERE hrw.parent_id > 0
815 AND hrw.date_worked BETWEEN NEXT_DAY (g_date_worked - 7,
816 start_day_of_week
817 )
818 AND (g_date_worked)
819 AND asm.assignment_id = hrw.assignment_id
820 AND hrw.date_worked BETWEEN asm.effective_start_date
821 AND asm.effective_end_date
822 AND asm.assignment_id = asmv.assignment_id
823 AND hrw.date_worked BETWEEN asmv.effective_start_date
824 AND asmv.effective_end_date
825 AND tim_id = g_tim_id
826 AND tim.ID = hrw.tim_id
827 AND elt.element_type_id = hrw.element_type_id
828 AND egp.egt_id IS NOT NULL
829 AND hrw.date_worked BETWEEN egp.effective_start_date
830 AND egp.effective_end_date
831 -- next line changed to use override earning policy.
832 -- AND egp.id = asmv.hxt_earning_policy
833 AND egp.ID = g_ep_id
834 AND hrw.element_type_id = erg.element_type_id
835 AND erg.egt_id = egp.egt_id
836 AND hrw.date_worked BETWEEN elt.effective_start_date
837 AND elt.effective_end_date
838 AND eltv.element_type_id = elt.element_type_id
839 AND hrw.date_worked BETWEEN eltv.effective_start_date
840 AND eltv.effective_end_date;
841
842 l_weekly_total_to_date NUMBER;
843 BEGIN
844 OPEN weekly_total_to_date;
845
846 FETCH weekly_total_to_date
847 INTO l_weekly_total_to_date;
848
849 CLOSE weekly_total_to_date;
850
851 RETURN NVL (l_weekly_total_to_date, 0);
852 END get_wkly_total_for_doubletime;
853
854 FUNCTION get_daily_total
855 RETURN NUMBER
856 IS
857 CURSOR daily_total
858 IS
859 SELECT NVL (SUM (hrw.hours), 0)
860 FROM hxt_pay_element_types_f_ddf_v eltv,
861 pay_element_types_f elt,
862 hxt_earning_policies egp,
863 hxt_per_aei_ddf_v asmv,
864 per_assignments_f asm,
865 hxt_det_hours_worked hrw,
866 hxt_timecards tim
867 WHERE hrw.parent_id > 0
868 AND hrw.date_worked = g_date_worked
869 AND asm.assignment_id = hrw.assignment_id
870 AND hrw.date_worked BETWEEN asm.effective_start_date
871 AND asm.effective_end_date
872 AND asm.assignment_id = asmv.assignment_id
873 AND hrw.date_worked BETWEEN asmv.effective_start_date
874 AND asmv.effective_end_date
875 AND tim_id = g_tim_id
876 AND tim.ID = hrw.tim_id
877 AND elt.element_type_id = hrw.element_type_id
878 AND ( -- If absence, only include earnings to be counted toward
879 -- hours to be worked before being eligible for overtime.
880 ( EXISTS (
881 SELECT 1
882 FROM hxt_earn_groups erg
883 WHERE erg.egt_id = egp.egt_id
884 AND erg.element_type_id =
885 elt.element_type_id)
886 AND eltv.hxt_earning_category = 'ABS'
887 AND egp.egt_id IS NOT NULL
888 )
889 OR eltv.hxt_earning_category = 'REG'
890 OR eltv.hxt_earning_category = 'OVT'
891 -- OR
892 -- to_char(hrw.element_type_id) LIKE
893 -- NVL(to_char(special_and_weekly_base), '%')
894 )
895 AND hrw.date_worked BETWEEN egp.effective_start_date
896 AND egp.effective_end_date
897 -- next line changed to use override earning policy.
898 -- AND egp.id = asmv.hxt_earning_policy
899 AND egp.ID = g_ep_id
900 AND hrw.date_worked BETWEEN elt.effective_start_date
901 AND elt.effective_end_date
902 AND eltv.element_type_id = elt.element_type_id
903 AND hrw.date_worked BETWEEN eltv.effective_start_date
904 AND eltv.effective_end_date;
905
906 l_daily_total NUMBER;
907 BEGIN
908 OPEN daily_total;
909
910 FETCH daily_total
911 INTO l_daily_total;
912
913 CLOSE daily_total;
914
915 RETURN NVL (l_daily_total, 0);
916 END get_daily_total;
917
918 -- we have a hole in the 7 day california rule, on the 6th day. Customers
919 -- may require that an employee be paid DoubleTime for any hours after 12.
920 -- but normal processing will see that as the weekly cap being hit and
921 -- pay it all as Overtime. This function is called at the end of explode
922 -- for the sixth day if the daily total > 12.
923 -- For example, a person works:
924 -- M T W T F S
925 -- 8 8 8 8 4 15
926 -- explodes as 8 8 8 8 4 4 reg
927 -- 11 OT
928 --
929 -- This function does: 15 - 12 = 3 (number of hrs over 12)
930 -- 11 - 3 = 8 (update detail record, chg 11 to 8)
931 -- insert new detail record - 3 hrs of doubletime.
932 FUNCTION adjust_for_double_time (p_day_total IN NUMBER)
933 RETURN NUMBER
934 IS
935 CURSOR overtime_cur
936 IS
937 SELECT hrw.ROWID hrw_rowid, hrw.hours
938 -- FROM pay_element_types_f_dfv eltv,
939 FROM hxt_pay_element_types_f_ddf_v eltv,
940 pay_element_types_f elt,
941 hxt_det_hours_worked hrw, --C421
942 hxt_timecards tim
943 WHERE hrw.date_worked = g_date_worked
944 AND tim_id = g_tim_id
945 AND tim.ID = hrw.tim_id
946 AND elt.element_type_id = hrw.element_type_id
947 AND eltv.hxt_earning_category = 'OVT'
948 AND hrw.date_worked BETWEEN elt.effective_start_date
949 AND elt.effective_end_date
950 AND eltv.element_type_id = elt.element_type_id
951 AND hrw.date_worked BETWEEN eltv.effective_start_date
952 AND eltv.effective_end_date;
953
954 CURSOR daily_earn_rules_cur2 (i_earn_policy NUMBER)
955 IS
956 SELECT er.element_type_id
957 FROM hxt_earning_rules er
958 WHERE er.egr_type = 'DAY'
959 AND er.egp_id = i_earn_policy
960 AND g_date_worked BETWEEN er.effective_start_date
961 AND er.effective_end_date
962 ORDER BY er.seq_no;
963
964 l_delta NUMBER;
965 l_hours_to_adjust NUMBER;
966 l_rowid ROWID;
967 l_dummy_elem NUMBER;
968 l_double_time_elem NUMBER;
969 BEGIN
970 IF g_debug
971 THEN
972 hr_utility.set_location ('adjust_for_double_time', 10);
973 END IF;
974
975 l_delta := p_day_total - 12;
976
977 OPEN overtime_cur;
978
979 FETCH overtime_cur
980 INTO l_rowid, l_hours_to_adjust;
981
982 IF overtime_cur%NOTFOUND
983 THEN
984 CLOSE overtime_cur;
985
986 RETURN 1;
987 END IF;
988
989 CLOSE overtime_cur;
990
991 UPDATE hxt_det_hours_worked_f
992 SET hours = l_hours_to_adjust - l_delta
993 WHERE ROWID = l_rowid;
994
995 OPEN daily_earn_rules_cur2 (g_ep_id);
996
997 FETCH daily_earn_rules_cur2
998 INTO l_dummy_elem;
999
1000 IF daily_earn_rules_cur2%FOUND
1001 THEN
1002 FETCH daily_earn_rules_cur2
1003 INTO l_dummy_elem;
1004
1005 IF daily_earn_rules_cur2%FOUND
1006 THEN
1007 FETCH daily_earn_rules_cur2
1008 INTO l_double_time_elem;
1009
1010 IF daily_earn_rules_cur2%FOUND
1011 THEN
1012 NULL;
1013 ELSE
1014 CLOSE daily_earn_rules_cur2;
1015
1016 RETURN 4;
1017 END IF;
1018 ELSE
1019 CLOSE daily_earn_rules_cur2;
1020
1021 RETURN 3;
1022 END IF;
1023 ELSE
1024 CLOSE daily_earn_rules_cur2;
1025
1026 hxt_util.DEBUG ('Return code is 2 from loc A');
1027 -- debug only --HXT115
1028 RETURN 2;
1029 END IF;
1030
1031 CLOSE daily_earn_rules_cur2;
1032
1033 IF g_debug
1034 THEN
1035 hr_utility.set_location ('adjust_for_double_time', 50);
1036 END IF;
1037
1038 IF pay (l_delta,
1039 l_double_time_elem,
1040 NULL,
1041 NULL,
1042 g_date_worked,
1043 g_id, -- parent id
1044 g_assignment_id,
1045 g_fcl_earn_reason_code,
1046 g_ffv_cost_center_id,
1047 g_ffv_labor_account_id,
1048 g_tas_id,
1049 g_location_id,
1050 g_sht_id,
1051 g_hrw_comment,
1052 g_ffv_rate_code_id,
1053 g_rate_multiple,
1054 g_hourly_rate,
1055 g_amount,
1056 g_fcl_tax_rule_code,
1057 g_separate_check_flag,
1058 g_project_id,
1059 -- g_GROUP_ID,
1060 g_ep_id,
1061 a_state_name => g_state_name,
1062 a_county_name => g_county_name,
1063 a_city_name => g_city_name,
1064 a_zip_code => g_zip_code
1065 ) <> 0
1066 THEN
1067 IF g_debug
1068 THEN
1069 hr_utility.set_location ('adjust_for_double_time', 75);
1070 END IF;
1071
1072 RETURN 5;
1073 END IF;
1074
1075 IF g_debug
1076 THEN
1077 hr_utility.set_location ('adjust_for_double_time', 100);
1078 END IF;
1079
1080 RETURN 0;
1081 END adjust_for_double_time;
1082
1083 FUNCTION get_weekly_total_incl_2day
1084 RETURN NUMBER
1085 IS
1086 CURSOR weekly_total_to_date
1087 IS
1088 SELECT NVL (SUM (hrw.hours), 0)
1089 FROM hxt_pay_element_types_f_ddf_v eltv,
1090 pay_element_types_f elt,
1091 hxt_earning_policies egp,
1092 hxt_per_aei_ddf_v asmv,
1093 per_assignments_f asm,
1094 hxt_det_hours_worked hrw,
1095 hxt_timecards tim
1096 WHERE hrw.date_worked BETWEEN NEXT_DAY (g_date_worked - 7,
1097 start_day_of_week
1098 )
1099 AND g_date_worked
1100 AND asm.assignment_id = hrw.assignment_id
1101 AND hrw.date_worked BETWEEN asm.effective_start_date
1102 AND asm.effective_end_date
1103 AND asm.assignment_id = asmv.assignment_id
1104 AND hrw.date_worked BETWEEN asmv.effective_start_date
1105 AND asmv.effective_end_date
1106 -- Commented out for OTLR Recurrring Period Preference support.
1107 -- and tim_id = g_tim_id
1108 -- Added the following for OTLR Recurrring Period Preference support.
1109 AND tim.for_person_id = g_person_id
1110 AND tim.ID = hrw.tim_id
1111 AND elt.element_type_id = hrw.element_type_id
1112 AND (
1113 -- If absence, only include earnings to be counted toward
1114 -- hours to be worked before being eligible for overtime.
1115 --USEEARNGROUP -- include ANY earnings, not just absences. RTF
1116 ( EXISTS (
1117 SELECT 1
1118 FROM hxt_earn_groups erg
1119 WHERE erg.egt_id = egp.egt_id
1120 AND erg.element_type_id = elt.element_type_id)
1121 AND egp.egt_id IS NOT NULL
1122 )
1123 )
1124 AND hrw.date_worked BETWEEN egp.effective_start_date
1125 AND egp.effective_end_date
1126 AND egp.ID = g_ep_id
1127 AND hrw.date_worked BETWEEN elt.effective_start_date
1128 AND elt.effective_end_date
1129 AND eltv.element_type_id = elt.element_type_id
1130 AND hrw.date_worked BETWEEN eltv.effective_start_date
1131 AND eltv.effective_end_date;
1132
1133 l_weekly_total_to_date NUMBER;
1134 BEGIN
1135 OPEN weekly_total_to_date;
1136
1137 FETCH weekly_total_to_date
1138 INTO l_weekly_total_to_date;
1139
1140 CLOSE weekly_total_to_date;
1141
1142 RETURN NVL (l_weekly_total_to_date, 0);
1143 END get_weekly_total_incl_2day;
1144
1145 FUNCTION segment_start_in_rule (
1146 p_rule_earning_type OUT NOCOPY NUMBER,
1147 p_segment_start_time IN DATE
1148 )
1149 RETURN BOOLEAN
1150 IS
1151 -- Checks to see if the segment start time falls within a shift diff rule.
1152 -- If so, returns the earning type of the rule. Returns true if the segment
1153 -- start is within a rule, false if it is not. The | in the comments shows
1154 -- where midnight falls. The segment start and stop are both dates while
1155 -- sdr.start and stop are numbers.
1156 CURSOR sd_rules
1157 IS
1158 SELECT sdr.element_type_id
1159 FROM hxt_shift_diff_rules sdr
1160 WHERE sdr.sdp_id = g_sdp_id
1161 AND g_date_worked BETWEEN sdr.effective_start_date
1162 AND sdr.effective_end_date
1163 AND ( ( sdr.start_time <=
1164 TO_NUMBER (TO_CHAR (p_segment_start_time,
1165 'HH24MI'
1166 )
1167 )
1168 AND TO_NUMBER (TO_CHAR (p_segment_start_time,
1169 'HH24MI')
1170 ) < sdr.stop_time
1171 )
1172 OR ( (TO_NUMBER (TO_CHAR (p_segment_start_time,
1173 'HH24MI'
1174 )
1175 ) <= sdr.start_time
1176 )
1177 AND TO_NUMBER (TO_CHAR (p_segment_start_time,
1178 'HH24MI')
1179 ) < sdr.stop_time
1180 AND sdr.start_time > sdr.stop_time
1181 )
1182 OR ( sdr.start_time <=
1183 TO_NUMBER (TO_CHAR (p_segment_start_time,
1184 'HH24MI'
1185 )
1186 )
1187 AND sdr.start_time > sdr.stop_time
1188 )
1189 );
1190 BEGIN
1191 OPEN sd_rules;
1192
1193 FETCH sd_rules
1194 INTO p_rule_earning_type;
1195
1196 IF sd_rules%NOTFOUND
1197 THEN
1198 CLOSE sd_rules;
1199
1200 RETURN FALSE;
1201 END IF;
1202
1203 CLOSE sd_rules;
1204
1205 RETURN TRUE;
1206 END segment_start_in_rule;
1207
1208 FUNCTION rule_start_in_segment (
1209 p_rule_earning_type OUT NOCOPY NUMBER,
1210 p_segment_start_time IN DATE,
1211 p_segment_stop_time IN DATE
1212 )
1213 RETURN BOOLEAN
1214 IS
1215 -- Checks to see if a shift diff rule starts within the time segment being
1216 -- generated. This is only called if it is already determined that the start
1217 -- of the segment does not fall within any rule.
1218 CURSOR sd_rules
1219 IS
1220 SELECT sdr.element_type_id
1221 FROM hxt_shift_diff_rules sdr
1222 WHERE sdr.sdp_id = g_sdp_id
1223 AND g_date_worked BETWEEN sdr.effective_start_date
1224 AND sdr.effective_end_date
1225 AND ( ( TO_NUMBER (TO_CHAR (p_segment_start_time,
1226 'HH24MI')
1227 ) < sdr.start_time
1228 AND sdr.start_time <
1229 TO_NUMBER (TO_CHAR (p_segment_stop_time,
1230 'HH24MI'
1231 )
1232 )
1233 )
1234 OR ( TO_NUMBER (TO_CHAR (p_segment_start_time,
1235 'HH24MI')
1236 ) > sdr.start_time
1237 AND sdr.start_time <
1238 TO_NUMBER (TO_CHAR (p_segment_stop_time,
1239 'HH24MI'
1240 )
1241 )
1242 AND TO_NUMBER (TO_CHAR (p_segment_start_time,
1243 'HH24MI')
1244 ) >
1245 TO_NUMBER (TO_CHAR (p_segment_stop_time,
1246 'HH24MI'
1247 )
1248 )
1249 )
1250 OR ( TO_NUMBER (TO_CHAR (p_segment_start_time,
1251 'HH24MI')
1252 ) < sdr.start_time
1253 AND TO_NUMBER (TO_CHAR (p_segment_start_time,
1254 'HH24MI')
1255 ) >
1256 TO_NUMBER (TO_CHAR (p_segment_stop_time,
1257 'HH24MI'
1258 )
1259 )
1260 )
1261 );
1262 BEGIN
1263 OPEN sd_rules;
1264
1265 FETCH sd_rules
1266 INTO p_rule_earning_type;
1267
1268 IF sd_rules%NOTFOUND
1269 THEN
1270 CLOSE sd_rules;
1271
1272 RETURN FALSE;
1273 END IF;
1274
1275 CLOSE sd_rules;
1276
1277 RETURN TRUE;
1278 END rule_start_in_segment;
1279
1280 -- END ORACLE bug #715964
1281 FUNCTION adjust_for_hdp_shortage (p_hours_short IN NUMBER)
1282 RETURN NUMBER
1283 IS
1284 -- Update existing det rows for hours that can't be deducted from this segment
1285 CURSOR current_dtl (c_hours_short NUMBER)
1286 IS
1287 SELECT dhw.ROWID dhw_rowid, dhw.parent_id, dhw.tim_id,
1288 dhw.hours, dhw.time_in, dhw.time_out, dhw.seqno
1289 FROM hxt_pay_element_types_f_ddf_v eltv,
1290 pay_element_types_f elt,
1291 hxt_det_hours_worked dhw
1292 WHERE dhw.tim_id = g_tim_id
1293 AND dhw.date_worked = g_date_worked
1294 AND dhw.hours > c_hours_short
1295 AND elt.element_type_id = dhw.element_type_id
1296 AND dhw.date_worked BETWEEN elt.effective_start_date
1297 AND elt.effective_end_date
1298 AND eltv.element_type_id = elt.element_type_id
1299 AND dhw.date_worked BETWEEN eltv.effective_start_date
1300 AND eltv.effective_end_date
1301 AND eltv.hxt_earning_category IN ('REG', 'OVT')
1302 ORDER BY dhw.date_worked DESC, dhw.time_in DESC, dhw.seqno DESC;
1303
1304 l_hours_to_adjust NUMBER;
1305 current_dtl_row current_dtl%ROWTYPE;
1306 l_proc VARCHAR2 (250);
1307 BEGIN
1308 IF g_debug
1309 THEN
1310 l_proc := 'hxt_time_detail.adjust_for_hdp_shortage';
1311 hr_utility.set_location (l_proc, 10);
1312 END IF;
1313
1314 OPEN current_dtl (p_hours_short);
1315
1316 FETCH current_dtl
1317 INTO current_dtl_row;
1318
1319 IF current_dtl%NOTFOUND
1320 THEN
1321 IF g_debug
1322 THEN
1323 hr_utility.set_location (l_proc, 20);
1324 END IF;
1325
1326 CLOSE current_dtl;
1327
1328 RETURN (p_hours_short);
1329 END IF;
1330
1331 CLOSE current_dtl;
1332
1333 IF g_debug
1334 THEN
1335 hr_utility.set_location (l_proc, 30);
1336 hr_utility.TRACE ('current_dtl_row.hours:'
1337 || current_dtl_row.hours
1338 );
1339 hr_utility.TRACE ('p_hours_short :' || p_hours_short);
1340 END IF;
1341
1342 l_hours_to_adjust := current_dtl_row.hours - p_hours_short;
1343
1344 IF g_debug
1345 THEN
1346 hr_utility.TRACE ('l_hours_to_adjust:' || l_hours_to_adjust);
1347 hr_utility.TRACE ( 'current_dtl_row.parent_id:'
1348 || current_dtl_row.parent_id
1349 );
1350 hr_utility.TRACE ('current_dtl_row.seqno:'
1351 || current_dtl_row.seqno
1352 );
1353 hr_utility.TRACE ('current_dtl_row.hours:'
1354 || current_dtl_row.hours
1355 );
1356 END IF;
1357
1358 FOR l_prem IN related_prem (current_dtl_row.parent_id,
1359 current_dtl_row.tim_id,
1360 current_dtl_row.seqno,
1361 current_dtl_row.hours
1362 )
1363 LOOP
1364 IF g_debug
1365 THEN
1366 hr_utility.set_location (l_proc, 40);
1367 END IF;
1368
1369 UPDATE hxt_det_hours_worked
1370 SET hours = l_hours_to_adjust,
1371 time_out = time_out - (p_hours_short / 24)
1372 WHERE ROWID = l_prem.prem_row_id;
1373 END LOOP;
1374
1375 IF g_debug
1376 THEN
1377 hr_utility.set_location (l_proc, 50);
1378 END IF;
1379
1380 UPDATE hxt_det_hours_worked
1381 SET hours = l_hours_to_adjust,
1382 time_out = time_out - (p_hours_short / 24)
1383 WHERE ROWID = current_dtl_row.dhw_rowid;
1384
1385 IF g_debug
1386 THEN
1387 hr_utility.set_location (l_proc, 60);
1388 END IF;
1389
1390 RETURN (0);
1391 END adjust_for_hdp_shortage;
1392
1393 FUNCTION adjust_for_3tier (
1394 a_tim_id NUMBER,
1395 a_ep_id NUMBER,
1396 a_date_worked DATE
1397 )
1398 RETURN NUMBER
1399 IS
1400 CURSOR ovt_hrs_cur (
1401 c_tim_id NUMBER,
1402 c_date_worked DATE,
1403 c_ovt_element NUMBER
1404 ) -- SIR 397
1405 IS
1406 SELECT det.ROWID det_rowid, det.hours, det.date_worked,
1407 det.parent_id, det.assignment_id,
1408 det.fcl_earn_reason_code, det.ffv_cost_center_id,
1409 det.tas_id, det.location_id, det.sht_id,
1410 det.hrw_comment, det.ffv_rate_code_id,
1411 det.rate_multiple, det.hourly_rate, det.amount,
1412 det.fcl_tax_rule_code, det.separate_check_flag,
1413 det.seqno, det.time_in, det.time_out, det.project_id,
1414 det.element_type_id, det.effective_end_date,
1415
1416 -- det.group_id,
1417 det.earn_pol_id, det.state_name, det.county_name,
1418 det.city_name, det.zip_code
1419 FROM hxt_det_hours_worked det
1420 WHERE det.element_type_id = c_ovt_element --SIR 397
1421 AND det.date_worked <= c_date_worked
1422 AND det.tim_id = c_tim_id
1423 AND det.hours <> 0
1424 ORDER BY det.date_worked DESC, det.time_out DESC, det.ID DESC;
1425
1426 CURSOR weekly_earn_rules_cur2 (
1427 c_earn_policy NUMBER,
1428 c_date_worked DATE
1429 )
1430 IS
1431 SELECT er.hours, er.element_type_id
1432 FROM hxt_earning_rules er
1433 WHERE er.egr_type = 'WKL'
1434 AND er.egp_id = c_earn_policy
1435 AND c_date_worked BETWEEN er.effective_start_date
1436 AND er.effective_end_date
1437 ORDER BY er.seq_no;
1438
1439 CURSOR sum_ovt_cur (
1440 c_tim_id NUMBER,
1441 c_date_worked DATE,
1442 c_second_elem NUMBER
1443 )
1444 IS
1445 SELECT NVL (SUM (hrw.hours), 0)
1446 FROM hxt_det_hours_worked hrw
1447 WHERE hrw.date_worked <= c_date_worked
1448 AND hrw.tim_id = c_tim_id
1449 AND hrw.element_type_id = c_second_elem;
1450
1451 CURSOR prem_amount_cur (c_date_worked DATE, c_elem NUMBER)
1452 IS
1453 SELECT NVL (hxt_premium_amount, 0)
1454 FROM hxt_pay_element_types_f_ddf_v eltv
1455 WHERE c_date_worked BETWEEN eltv.effective_start_date
1456 AND eltv.effective_end_date
1457 AND eltv.element_type_id = c_elem;
1458
1459 l_error_code NUMBER;
1460 l_delta NUMBER;
1461 l_hours_to_adjust NUMBER;
1462 l_hours_left NUMBER;
1463 l_first_elem NUMBER;
1464 l_second_elem NUMBER;
1465 l_third_elem NUMBER;
1466 l_first_cap NUMBER;
1467 l_second_cap NUMBER;
1468 l_third_cap NUMBER;
1469 l_ovt_hrs_cur ovt_hrs_cur%ROWTYPE;
1470 l_sum_hours NUMBER := 0;
1471 l_sum_reg NUMBER := 0;
1472 l_multiple NUMBER := 0;
1473 l_id NUMBER; --debug
1474 BEGIN
1475 -- collect earnings rules
1476 IF g_ep_type NOT IN ('SPECIAL', 'WEEKLY')
1477 THEN
1478 RETURN 0; -- nothing to do
1479 END IF;
1480
1481 IF g_debug
1482 THEN
1483 hr_utility.set_location ('adjust_for_3tier', 10);
1484 END IF;
1485
1486 OPEN weekly_earn_rules_cur2 (a_ep_id, a_date_worked);
1487
1488 FETCH weekly_earn_rules_cur2
1489 INTO l_first_cap, l_first_elem;
1490
1491 IF weekly_earn_rules_cur2%FOUND
1492 THEN
1493 FETCH weekly_earn_rules_cur2
1494 INTO l_second_cap, l_second_elem;
1495
1496 IF weekly_earn_rules_cur2%FOUND
1497 THEN
1498 FETCH weekly_earn_rules_cur2
1499 INTO l_third_cap, l_third_elem;
1500
1501 IF weekly_earn_rules_cur2%FOUND
1502 THEN
1503 NULL;
1504 ELSE
1505 l_third_cap := 999;
1506 END IF;
1507 ELSE
1508 l_second_cap := 999;
1509 END IF;
1510 ELSE
1511 CLOSE weekly_earn_rules_cur2;
1512
1513 hxt_util.DEBUG ('Return code is 2 from loc C');
1514 -- debug only --HXT115
1515 RETURN 2;
1516 END IF;
1517
1518 CLOSE weekly_earn_rules_cur2;
1519
1520 IF g_debug
1521 THEN
1522 hr_utility.set_location ('adjust_for_3tier', 30);
1523 END IF;
1524
1525 -- fetch sum of regular hours to date
1526 /* CHANGED call to get only REGULAR Hours Worked instead of total hours*/
1527 l_sum_reg := get_weekly_total_incl_2day;
1528
1529 -- l_sum_reg := get_weekly_total_to_date('REG');
1530
1531 -- fetch sum of overtime hours to date marker
1532 OPEN sum_ovt_cur (a_tim_id, a_date_worked, l_second_elem);
1533
1534 -- OPEN sum_ovt_cur(a_tim_id, a_date_worked);
1535 FETCH sum_ovt_cur
1536 INTO l_delta;
1537
1538 CLOSE sum_ovt_cur;
1539
1540 IF g_debug
1541 THEN
1542 hr_utility.set_location ('adjust_for_3tier', 50);
1543 END IF;
1544
1545 IF (l_sum_reg + l_delta) <= l_second_cap
1546 THEN
1547 IF g_debug
1548 THEN
1549 hr_utility.set_location ('adjust_for_3tier', 60);
1550 END IF;
1551
1552 RETURN 0;
1553 END IF;
1554
1555 -- if sum of overtime hours to date is greater than the second cap
1556 -- minus the first cap then set hours to adjust. Locate overtime
1557 -- records that must be adjusted
1558
1559 -- SIR 391 Change the criteria to: If the total overtime cap hours
1560 -- SIR 391 for the week are greater than the second cap then adjust the
1561 -- SIR 391 overtime records.
1562 IF (l_sum_reg + l_delta) <= l_second_cap
1563 THEN
1564 -- SIR 391 if(l_delta <= (l_second_cap - l_first_cap)) then
1565 RETURN (0);
1566 ELSE
1567 -- SIR 391 l_hours_to_adjust := (l_delta - (l_second_cap - l_first_cap));
1568 l_hours_to_adjust := (l_sum_reg + l_delta) - l_second_cap;
1569
1570 -- SIR 391
1571 OPEN prem_amount_cur (a_date_worked, l_third_elem);
1572
1573 FETCH prem_amount_cur
1574 INTO l_multiple;
1575
1576 CLOSE prem_amount_cur;
1577
1578 --SIR 397 OPEN ovt_hrs_cur(a_tim_id, a_date_worked);
1579 OPEN ovt_hrs_cur (a_tim_id, a_date_worked, l_second_elem);
1580
1581 -- SIR 397
1582 WHILE l_hours_to_adjust > 0
1583 LOOP -- fetch overtime rows in reverse order
1584 FETCH ovt_hrs_cur
1585 INTO l_ovt_hrs_cur;
1586
1587 IF ovt_hrs_cur%NOTFOUND
1588 THEN
1589 CLOSE ovt_hrs_cur;
1590
1591 RETURN 1;
1592 END IF;
1593
1594 --
1595 IF (l_ovt_hrs_cur.element_type_id = l_second_elem)
1596 THEN
1597 IF (l_ovt_hrs_cur.hours >= l_hours_to_adjust)
1598 THEN
1599 l_hours_left := l_hours_to_adjust;
1600 ELSE
1601 l_hours_left := l_ovt_hrs_cur.hours;
1602 END IF;
1603
1604 --
1605 IF (l_ovt_hrs_cur.hours > l_hours_left)
1606 THEN
1607 UPDATE hxt_det_hours_worked_f
1608 SET hours = (hours - l_hours_left),
1609 time_out =
1610 time_in
1611 + ((l_ovt_hrs_cur.hours - l_hours_left) / 24)
1612 WHERE ROWID = l_ovt_hrs_cur.det_rowid;
1613 ELSE
1614 UPDATE hxt_det_hours_worked_f
1615 --SIR382 SET hours = (hours - l_hours_left),
1616 --SIR382 time_out = time_in + (l_hours_left/24)
1617 SET hours = 0,
1618 time_out = time_in
1619 WHERE ROWID = l_ovt_hrs_cur.det_rowid;
1620 END IF;
1621
1622 --
1623 FOR l_prem IN related_prem (l_ovt_hrs_cur.parent_id,
1624 a_tim_id,
1625 l_ovt_hrs_cur.seqno,
1626 l_ovt_hrs_cur.hours
1627 )
1628 LOOP
1629 IF (l_ovt_hrs_cur.hours > l_hours_left)
1630 THEN
1631 UPDATE hxt_det_hours_worked_f
1632 SET hours = (hours - l_hours_left),
1633 time_out =
1634 time_in
1635 + ((l_ovt_hrs_cur.hours - l_hours_left) / 24
1636 )
1637 WHERE ROWID = l_prem.prem_row_id;
1638 ELSE
1639 UPDATE hxt_det_hours_worked_f
1640 SET hours = 0,
1641 time_out = time_in
1642 WHERE ROWID = l_prem.prem_row_id;
1643 END IF;
1644 END LOOP;
1645
1646 --
1647 IF g_debug
1648 THEN
1649 hr_utility.set_location ('adjust_for_3tier', 100);
1650 END IF;
1651
1652 IF (l_ovt_hrs_cur.hours > l_hours_left)
1653 THEN
1654 IF g_debug
1655 THEN
1656 hr_utility.set_location ('adjust_for_3tier', 110);
1657 END IF;
1658
1659 l_error_code :=
1660 pay (l_hours_left,
1661 l_third_elem,
1662 l_ovt_hrs_cur.time_in
1663 + ((l_ovt_hrs_cur.hours - l_hours_left) / 24),
1664 l_ovt_hrs_cur.time_in
1665 + (l_ovt_hrs_cur.hours / 24),
1666 l_ovt_hrs_cur.date_worked,
1667 l_ovt_hrs_cur.parent_id,
1668 l_ovt_hrs_cur.assignment_id,
1669 l_ovt_hrs_cur.fcl_earn_reason_code,
1670 l_ovt_hrs_cur.ffv_cost_center_id,
1671 NULL,
1672 l_ovt_hrs_cur.tas_id,
1673 l_ovt_hrs_cur.location_id,
1674 l_ovt_hrs_cur.sht_id,
1675 l_ovt_hrs_cur.hrw_comment,
1676 l_ovt_hrs_cur.ffv_rate_code_id,
1677 l_multiple,
1678 l_ovt_hrs_cur.hourly_rate,
1679 l_ovt_hrs_cur.amount,
1680 l_ovt_hrs_cur.fcl_tax_rule_code,
1681 l_ovt_hrs_cur.separate_check_flag,
1682 l_ovt_hrs_cur.project_id,
1683 -- l_ovt_hrs_cur.group_id,
1684 l_ovt_hrs_cur.earn_pol_id,
1685 a_state_name => l_ovt_hrs_cur.state_name,
1686 a_county_name => l_ovt_hrs_cur.county_name,
1687 a_city_name => l_ovt_hrs_cur.city_name,
1688 a_zip_code => l_ovt_hrs_cur.zip_code
1689 ); --SIR337
1690 ELSIF (l_ovt_hrs_cur.hours = l_hours_left)
1691 THEN
1692 IF g_debug
1693 THEN
1694 hr_utility.set_location ('adjust_for_3tier', 120);
1695 END IF;
1696
1697 l_error_code :=
1698 pay (l_hours_left,
1699 l_third_elem,
1700 l_ovt_hrs_cur.time_in,
1701 l_ovt_hrs_cur.time_out,
1702 l_ovt_hrs_cur.date_worked,
1703 l_ovt_hrs_cur.parent_id,
1704 l_ovt_hrs_cur.assignment_id,
1705 l_ovt_hrs_cur.fcl_earn_reason_code,
1706 l_ovt_hrs_cur.ffv_cost_center_id,
1707 NULL,
1708 l_ovt_hrs_cur.tas_id,
1709 l_ovt_hrs_cur.location_id,
1710 l_ovt_hrs_cur.sht_id,
1711 l_ovt_hrs_cur.hrw_comment,
1712 l_ovt_hrs_cur.ffv_rate_code_id,
1713 -- l_ovt_hrs_cur.rate_multiple,
1714 l_multiple,
1715 l_ovt_hrs_cur.hourly_rate,
1716 l_ovt_hrs_cur.amount,
1717 l_ovt_hrs_cur.fcl_tax_rule_code,
1718 l_ovt_hrs_cur.separate_check_flag,
1719 l_ovt_hrs_cur.project_id,
1720 -- l_ovt_hrs_cur.group_id,
1721 l_ovt_hrs_cur.earn_pol_id,
1722 a_state_name => l_ovt_hrs_cur.state_name,
1723 a_county_name => l_ovt_hrs_cur.county_name,
1724 a_city_name => l_ovt_hrs_cur.city_name,
1725 a_zip_code => l_ovt_hrs_cur.zip_code
1726 ); --SIR337
1727 ELSE
1728 IF g_debug
1729 THEN
1730 hr_utility.set_location ('adjust_for_3tier', 130);
1731 END IF;
1732
1733 l_error_code :=
1734 pay (l_hours_left,
1735 l_third_elem,
1736 l_ovt_hrs_cur.time_in,
1737 l_ovt_hrs_cur.time_out - (l_hours_left / 24),
1738 l_ovt_hrs_cur.date_worked,
1739 l_ovt_hrs_cur.parent_id,
1740 l_ovt_hrs_cur.assignment_id,
1741 l_ovt_hrs_cur.fcl_earn_reason_code,
1742 l_ovt_hrs_cur.ffv_cost_center_id,
1743 NULL,
1744 l_ovt_hrs_cur.tas_id,
1745 l_ovt_hrs_cur.location_id,
1746 l_ovt_hrs_cur.sht_id,
1747 l_ovt_hrs_cur.hrw_comment,
1748 l_ovt_hrs_cur.ffv_rate_code_id,
1749 -- l_ovt_hrs_cur.rate_multiple,
1750 l_multiple,
1751 l_ovt_hrs_cur.hourly_rate,
1752 l_ovt_hrs_cur.amount,
1753 l_ovt_hrs_cur.fcl_tax_rule_code,
1754 l_ovt_hrs_cur.separate_check_flag,
1755 l_ovt_hrs_cur.project_id,
1756 -- l_ovt_hrs_cur.group_id,
1757 l_ovt_hrs_cur.earn_pol_id,
1758 a_state_name => l_ovt_hrs_cur.state_name,
1759 a_county_name => l_ovt_hrs_cur.county_name,
1760 a_city_name => l_ovt_hrs_cur.city_name,
1761 a_zip_code => l_ovt_hrs_cur.zip_code
1762 ); --SIR337
1763 END IF;
1764
1765 --
1766 l_hours_to_adjust := (l_hours_to_adjust - l_hours_left);
1767 --
1768 END IF;
1769
1770 --
1771 IF (l_hours_to_adjust = 0)
1772 THEN
1773 CLOSE ovt_hrs_cur;
1774
1775 RETURN 0;
1776 END IF;
1777 --
1778 END LOOP;
1779 END IF;
1780
1781 CLOSE ovt_hrs_cur;
1782
1783 IF g_debug
1784 THEN
1785 hr_utility.set_location ('adjust_for_3tier', 200);
1786 END IF;
1787
1788 RETURN 0;
1789 EXCEPTION
1790 WHEN OTHERS
1791 THEN
1792 l_error_code :=
1793 call_hxthxc_gen_error ('HXC',
1794 'HXC_HXT_DEP_VAL_OTMERR',
1795 'Adjust_for_3tier',
1796 LOCATION,
1797 'Adjust_for_3tier.',
1798 SQLERRM
1799 );
1800 --2278400 l_error_code := call_gen_error(location, 'Adjust_for_3tier.', sqlerrm);
1801 RETURN 4;
1802 END adjust_for_3tier;
1803
1804 --
1805 --------------------------------------------------------------------------------
1806 --
1807 PROCEDURE adjust_hours_for_premium (
1808 dtl_parent_id IN NUMBER,
1809 dtl_tim_id IN NUMBER,
1810 dtl_seqno IN NUMBER,
1811 dtl_hours IN NUMBER,
1812 p_sum_time_in IN DATE,
1813 p_sum_time_out IN DATE,
1814 deduct_premium IN NUMBER,
1815 adjust_by IN VARCHAR2,
1816 prem_adjusted IN OUT NOCOPY BOOLEAN
1817 )
1818 IS
1819 CURSOR sdp_rule_cursor
1820 IS
1821 SELECT sdr.start_time, sdr.stop_time, sdr.carryover_time,
1822 elt.element_name
1823 FROM hxt_shift_diff_rules sdr, pay_element_types_f elt
1824 WHERE sdr.sdp_id = g_sdp_id
1825 AND sdr.element_type_id = elt.element_type_id
1826 AND trunc(p_sum_time_in) BETWEEN elt.effective_start_date
1827 AND elt.effective_end_date;
1828
1829 l_sdp_start DATE;
1830 l_sdp_stop DATE;
1831 l_sdp_carryover DATE;
1832 l_proc VARCHAR2 (250)
1833 := 'hxt_time_detail.adjust_hours_for_premium';
1834 BEGIN
1835 FOR l_sdp_rule IN sdp_rule_cursor
1836 LOOP
1837 hxt_time_summary.time_in_dates (l_sdp_rule.start_time,
1838 l_sdp_rule.stop_time,
1839 l_sdp_rule.carryover_time,
1840 l_sdp_start,
1841 l_sdp_stop,
1842 l_sdp_carryover,
1843 g_date_worked
1844 );
1845
1846 IF ( ( p_sum_time_in <= l_sdp_start
1847 AND l_sdp_start <= p_sum_time_out
1848 )
1849 AND ( p_sum_time_in <= l_sdp_stop
1850 AND l_sdp_stop <= p_sum_time_out
1851 )
1852 )
1853 OR ( ( l_sdp_start <= p_sum_time_in
1854 AND p_sum_time_in <= l_sdp_stop
1855 )
1856 AND ( l_sdp_start <= p_sum_time_out
1857 AND p_sum_time_out <= l_sdp_stop
1858 )
1859 )
1860 OR ( ( l_sdp_start <= p_sum_time_in
1861 AND p_sum_time_in <= l_sdp_stop
1862 )
1863 AND ( l_sdp_start <= p_sum_time_out
1864 AND l_sdp_stop <= p_sum_time_out
1865 )
1866 )
1867 THEN
1868 IF adjust_by = 'UPDATE'
1869 THEN
1870 FOR l_prem IN related_prem (dtl_parent_id,
1871 dtl_tim_id,
1872 dtl_seqno,
1873 dtl_hours
1874 )
1875 LOOP
1876 IF l_prem.element_name = l_sdp_rule.element_name
1877 THEN
1878 UPDATE hxt_det_hours_worked
1879 SET hours = l_prem.prem_hours - deduct_premium,
1880 time_out =
1881 time_in
1882 + ((l_prem.prem_hours - deduct_premium) / 24
1883 )
1884 WHERE ROWID = l_prem.prem_row_id;
1885 END IF;
1886
1887 prem_adjusted := TRUE;
1888 END LOOP;
1889 ELSIF adjust_by = 'DELETE'
1890 THEN
1891 FOR l_prem IN related_prem (dtl_parent_id,
1892 dtl_tim_id,
1893 dtl_seqno,
1894 dtl_hours
1895 )
1896 LOOP
1897 IF l_prem.element_name = l_sdp_rule.element_name
1898 THEN
1899 DELETE FROM hxt_det_hours_worked
1900 WHERE ROWID = l_prem.prem_row_id;
1901 END IF;
1902
1903 prem_adjusted := TRUE;
1904 END LOOP;
1905 END IF;
1906 END IF;
1907 END LOOP;
1908 END adjust_hours_for_premium;
1909
1910 --
1911 ---------------------------------------------------------------------------
1912 --
1913 FUNCTION adjust_hours_for_hdp
1914 RETURN NUMBER
1915 IS
1916 CURSOR current_dtl
1917 IS
1918 SELECT dhw.ROWID dhw_rowid, dhw.parent_id, dhw.tim_id,
1919 dhw.hours, dhw.time_in, dhw.time_out, dhw.seqno
1920 FROM hxt_pay_element_types_f_ddf_v eltv,
1921 pay_element_types_f elt,
1922 hxt_det_hours_worked dhw
1923 WHERE dhw.tim_id = g_tim_id
1924 AND dhw.date_worked = g_date_worked
1925 AND elt.element_type_id = dhw.element_type_id
1926 AND dhw.date_worked BETWEEN elt.effective_start_date
1927 AND elt.effective_end_date
1928 AND eltv.element_type_id = elt.element_type_id
1929 AND dhw.date_worked BETWEEN eltv.effective_start_date
1930 AND eltv.effective_end_date
1931 AND eltv.hxt_earning_category IN ('REG', 'OVT')
1932 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y' /* Bug: 4489952 */
1933 ORDER BY dhw.date_worked DESC,
1934 dhw.time_in DESC,
1935 dhw.seqno DESC,
1936 dhw.parent_id DESC;
1937
1938 CURSOR day_of_wk_prem_dtl
1939 IS
1940 SELECT dhw.ROWID dhw_rowid, dhw.parent_id, dhw.tim_id,
1941 dhw.hours, dhw.time_in, dhw.time_out, dhw.seqno
1942 FROM hxt_pay_element_types_f_ddf_v eltv,
1943 pay_element_types_f elt,
1944 hxt_det_hours_worked dhw
1945 WHERE dhw.tim_id = g_tim_id
1946 AND dhw.parent_id = g_id
1947 AND dhw.date_worked = g_date_worked
1948 AND elt.element_type_id = dhw.element_type_id
1949 AND dhw.date_worked BETWEEN elt.effective_start_date
1950 AND elt.effective_end_date
1951 AND eltv.element_type_id = elt.element_type_id
1952 AND elt.element_type_id = g_osp_id
1953 AND dhw.date_worked BETWEEN eltv.effective_start_date
1954 AND eltv.effective_end_date
1955 AND eltv.hxt_earning_category = 'OSP'
1956 AND eltv.hxt_premium_type <> 'FIXED'
1957 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y' /* Bug: 4489952 */
1958 ORDER BY dhw.date_worked DESC,
1959 dhw.time_in DESC,
1960 dhw.seqno DESC,
1961 dhw.parent_id DESC;
1962
1963 CURSOR oth_prem_dtl -- Bug 5447600
1964 IS
1965 SELECT dhw.ROWID dhw_rowid, dhw.parent_id, dhw.tim_id,
1966 dhw.hours, dhw.time_in, dhw.time_out, dhw.seqno
1967 FROM hxt_pay_element_types_f_ddf_v eltv,
1968 pay_element_types_f elt,
1969 hxt_det_hours_worked dhw
1970 WHERE dhw.parent_id = g_id
1971 AND dhw.element_type_id = elt.element_type_id
1972 AND dhw.date_worked BETWEEN elt.effective_start_date
1973 AND elt.effective_end_date
1974 AND eltv.element_type_id = elt.element_type_id
1975 AND dhw.date_worked BETWEEN eltv.effective_start_date
1976 AND eltv.effective_end_date
1977 AND eltv.hxt_earning_category = 'OTH'
1978 AND eltv.hxt_premium_type <> 'FIXED'
1979 AND dhw.tim_id = g_tim_id
1980 AND dhw.date_worked = g_date_worked
1981 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y' /* Bug: 4489952 */
1982 ORDER BY dhw.date_worked DESC,
1983 dhw.time_in DESC,
1984 dhw.seqno DESC,
1985 dhw.parent_id DESC;
1986
1987 CURSOR sdf_prem_detail_hours
1988 IS
1989 SELECT NVL (SUM (dhw.hours), 0) det_hours
1990 FROM hxt_pay_element_types_f_ddf_v eltv,
1991 pay_element_types_f elt,
1992 hxt_det_hours_worked dhw,
1993 hxt_sum_hours_worked shw
1994 WHERE shw.ID = g_id
1995 AND shw.ID = dhw.parent_id
1996 AND shw.element_type_id IS NULL
1997 AND dhw.element_type_id = elt.element_type_id
1998 AND dhw.date_worked BETWEEN elt.effective_start_date
1999 AND elt.effective_end_date
2000 AND eltv.element_type_id = elt.element_type_id
2001 AND dhw.date_worked BETWEEN eltv.effective_start_date
2002 AND eltv.effective_end_date
2003 AND eltv.hxt_earning_category = 'SDF'
2004 AND dhw.tim_id = g_tim_id
2005 AND dhw.date_worked = g_date_worked
2006 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y'; /* Bug: 4489952 */
2007
2008 CURSOR oth_prem_detail_hours -- Bug 5447600
2009 IS
2010 SELECT NVL (SUM (dhw.hours), 0) det_hours
2011 FROM hxt_pay_element_types_f_ddf_v eltv,
2012 pay_element_types_f elt,
2013 hxt_det_hours_worked dhw,
2014 hxt_sum_hours_worked shw
2015 WHERE shw.ID = g_id
2016 AND shw.ID = dhw.parent_id
2017 AND shw.element_type_id IS NULL
2018 AND dhw.element_type_id = elt.element_type_id
2019 AND dhw.date_worked BETWEEN elt.effective_start_date
2020 AND elt.effective_end_date
2021 AND eltv.element_type_id = elt.element_type_id
2022 AND dhw.date_worked BETWEEN eltv.effective_start_date
2023 AND eltv.effective_end_date
2024 AND eltv.hxt_earning_category = 'OTH'
2025 AND dhw.tim_id = g_tim_id
2026 AND dhw.date_worked = g_date_worked
2027 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y'; /* Bug: 4489952 */
2028
2029 CURSOR hdp_rule_cursor
2030 IS
2031 SELECT hours, time_period
2032 FROM hxt_hour_deduction_rules thdr
2033 WHERE thdr.hdp_id = g_hdp_id
2034 AND g_date_worked BETWEEN thdr.effective_start_date
2035 AND thdr.effective_end_date;
2036
2037 CURSOR detail_hours_today
2038 IS
2039 SELECT NVL (SUM (dhw.hours), 0) det_hours
2040 FROM hxt_pay_element_types_f_ddf_v eltv,
2041 pay_element_types_f elt,
2042 hxt_det_hours_worked dhw,
2043 hxt_sum_hours_worked shw
2044 WHERE shw.ID = g_id
2045 AND shw.ID = dhw.parent_id
2046 AND shw.element_type_id IS NULL
2047 AND dhw.element_type_id = elt.element_type_id
2048 AND dhw.date_worked BETWEEN elt.effective_start_date
2049 AND elt.effective_end_date
2050 AND eltv.element_type_id = elt.element_type_id
2051 AND dhw.date_worked BETWEEN eltv.effective_start_date
2052 AND eltv.effective_end_date
2053 AND eltv.hxt_earning_category IN ('REG', 'OVT')
2054 AND dhw.tim_id = g_tim_id
2055 AND dhw.date_worked = g_date_worked
2056 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y'; /* Bug: 4489952 */
2057
2058 CURSOR detail_hours_incl_prev_rows
2059 IS
2060 SELECT NVL (SUM (dhw.hours), 0) det_hours
2061 FROM hxt_pay_element_types_f_ddf_v eltv,
2062 pay_element_types_f elt,
2063 hxt_det_hours_worked dhw,
2064 hxt_sum_hours_worked shw --<-- New Table
2065 WHERE elt.element_type_id = dhw.element_type_id
2066 AND shw.ID = dhw.parent_id --<-- New Join
2067 AND shw.element_type_id IS NULL
2068 --<-- New check: No Hours Override
2069 AND dhw.date_worked BETWEEN elt.effective_start_date
2070 AND elt.effective_end_date
2071 AND eltv.element_type_id = elt.element_type_id
2072 AND dhw.date_worked BETWEEN eltv.effective_start_date
2073 AND eltv.effective_end_date
2074 AND eltv.hxt_earning_category IN ('REG', 'OVT')
2075 AND dhw.tim_id = g_tim_id
2076 AND dhw.date_worked = g_date_worked
2077 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y'; /* Bug: 4489952 */
2078
2079 CURSOR get_sum_hrs
2080 IS
2081 SELECT NVL (SUM (shw.hours), 0) sum_hours,
2082 COUNT(*) sum_count /*** 4969936 ***/
2083 FROM hxt_sum_hours_worked shw
2084 WHERE tim_id = g_tim_id AND shw.date_worked = g_date_worked
2085 AND not exists ( SELECT 'X' /* Bug: 4489952 */
2086 FROM hxt_add_elem_info_f hei, hxt_det_hours_worked dhw
2087 WHERE hei.element_type_id = dhw.element_type_id
2088 AND nvl(hei.exclude_from_explosion, 'N') = 'Y'
2089 AND dhw.parent_id = shw.id
2090 AND g_date_worked BETWEEN hei.effective_start_date
2091 AND hei.effective_end_date);
2092
2093 CURSOR get_sum_time_out
2094 IS
2095 SELECT hours, time_in, time_out
2096 FROM hxt_sum_hours_worked shw
2097 WHERE ID = g_id
2098 AND not exists ( SELECT 'X' /* Bug: 4489952 */
2099 FROM hxt_add_elem_info_f hei, hxt_det_hours_worked dhw
2100 WHERE hei.element_type_id = dhw.element_type_id
2101 AND nvl(hei.exclude_from_explosion, 'N') = 'Y'
2102 AND dhw.parent_id = shw.id
2103 AND g_date_worked BETWEEN hei.effective_start_date
2104 AND hei.effective_end_date);
2105
2106 CURSOR csr_work_hrs (
2107 p_date_worked hxt_sum_hours_worked_f.date_worked%TYPE,
2108 p_tim_id hxt_sum_hours_worked_f.tim_id%TYPE
2109 )
2110 IS
2111 SELECT shw.ID, shw.hours, shw.time_in, shw.time_out
2112 FROM hxt_sum_hours_worked shw
2113 WHERE shw.tim_id = p_tim_id
2114 AND shw.date_worked = p_date_worked
2115 AND (( shw.time_in IS NOT NULL
2116 AND shw.time_out IS NOT NULL
2117 AND shw.time_in <> shw.time_out
2118 )
2119 )
2120 AND not exists ( SELECT 'X' /* Bug: 4489952 */
2121 FROM hxt_add_elem_info_f hei, hxt_det_hours_worked dhw
2122 WHERE hei.element_type_id = dhw.element_type_id
2123 AND nvl(hei.exclude_from_explosion, 'N') = 'Y'
2124 AND dhw.parent_id = shw.id
2125 AND g_date_worked BETWEEN hei.effective_start_date
2126 AND hei.effective_end_date)
2127 ORDER BY shw.date_worked,
2128 shw.element_type_id,
2129 shw.time_in,
2130 shw.seqno,
2131 shw.ID;
2132
2133 CURSOR hdp_hours_deducted_today
2134 IS
2135 SELECT (NVL (sum_hours, 0) - NVL (det_hours, 0))
2136 FROM hxt_hdp_sum_hours_worked_v shw,
2137 hxt_hdp_det_hours_worked_v dhw
2138 WHERE dhw.det_date = g_date_worked
2139 AND dhw.det_tim_id = g_tim_id
2140 AND shw.sum_date = dhw.det_date
2141 AND shw.sum_tim_id = dhw.det_tim_id;
2142
2143 --Bug 4969936 Fix Start
2144
2145 CURSOR hdp_rules
2146 IS
2147 SELECT SUM(thdr.time_period) time_period,
2148 COUNT(*) hdp_count
2149 FROM hxt_hour_deduction_rules thdr
2150 WHERE thdr.hdp_id = g_hdp_id
2151 AND g_date_worked BETWEEN thdr.effective_start_date
2152 AND thdr.effective_end_date;
2153
2154 sum_row_count NUMBER := 0;
2155 hdp_hrs NUMBER := 0;
2156 hdp_time_period NUMBER := 0;
2157 hdp_row_count NUMBER := 0;
2158
2159 --Bug 4969936 Fix End
2160
2161 loop_count NUMBER := 0;
2162 hrs_deducted_today NUMBER := 0;
2163 sum_hours NUMBER := 0;
2164 sum_time_out DATE := NULL;
2165 sum_time_in DATE := NULL;
2166 hours_paid_today NUMBER := 0;
2167 sdf_prem_hours_paid NUMBER := 0;
2168 oth_prem_hours_paid NUMBER := 0;
2169 detail_hrs_total NUMBER := 0;
2170 sum_hrs_total NUMBER := 0;
2171 deduct_hours NUMBER := 0;
2172 test_hours NUMBER := 0;
2173 deduct_prem_hours NUMBER := 0;
2174 current_dtl_row current_dtl%ROWTYPE;
2175 l_prem_adjusted BOOLEAN := FALSE;
2176 l_proc VARCHAR2 (250)
2177 := 'hxt_time_detail.adjust_hours_for_hdp';
2178 BEGIN
2179 IF g_debug
2180 THEN
2181 hr_utility.set_location (l_proc, 10);
2182 END IF;
2183
2184 IF g_hdp_id IS NULL
2185 THEN
2186 IF g_debug
2187 THEN
2188 hr_utility.set_location (l_proc, 20);
2189 END IF;
2190
2191 RETURN (0);
2192 END IF;
2193
2194 OPEN get_sum_time_out;
2195
2196 FETCH get_sum_time_out
2197 INTO sum_hours, sum_time_in, sum_time_out;
2198
2199 IF g_debug
2200 THEN
2201 hr_utility.TRACE ( 'sum_time_in:'
2202 || TO_CHAR (sum_time_in,
2203 'dd-mon-yyyy hh24:mi:ss'
2204 )
2205 );
2206 hr_utility.TRACE ( 'sum_time_out:'
2207 || TO_CHAR (sum_time_out,
2208 'dd-mon-yyyy hh24:mi:ss'
2209 )
2210 );
2211 hr_utility.TRACE ( 'g_time_out:'
2212 || TO_CHAR (g_time_out,
2213 'dd-mon-yyyy hh24:mi:ss')
2214 );
2215 END IF;
2216
2217 CLOSE get_sum_time_out;
2218
2219 IF sum_time_out IS NOT NULL AND g_time_out IS NOT NULL
2220 THEN
2221 IF g_time_out < sum_time_out
2222 THEN
2223 IF g_debug
2224 THEN
2225 hr_utility.set_location (l_proc, 30);
2226 END IF;
2227
2228 RETURN (0);
2229 END IF;
2230 END IF;
2231
2232 IF g_debug
2233 THEN
2234 hr_utility.TRACE ( 'g_time_out:'
2235 || TO_CHAR (g_time_out,
2236 'dd-mon-yyyy hh24:mi:ss')
2237 );
2238 hr_utility.TRACE ('g_tim_id:' || g_tim_id);
2239 END IF;
2240
2241 -- Check for contiguity when time entered in Hours
2242 IF sum_time_in IS NULL AND sum_time_out IS NULL
2243 THEN
2244 IF g_debug
2245 THEN
2246 hr_utility.set_location (l_proc, 31);
2247 END IF;
2248
2249 OPEN detail_hours_incl_prev_rows;
2250
2251 FETCH detail_hours_incl_prev_rows
2252 INTO detail_hrs_total;
2253
2254 IF g_debug
2255 THEN
2256 hr_utility.TRACE ('detail_hrs_total:' || detail_hrs_total);
2257 END IF;
2258
2259 CLOSE detail_hours_incl_prev_rows;
2260
2261 OPEN get_sum_hrs;
2262
2263 FETCH get_sum_hrs
2264 INTO sum_hrs_total, sum_row_count;
2265
2266 IF g_debug
2267 THEN
2268 hr_utility.TRACE ('sum_hrs_total:' || sum_hrs_total);
2269 END IF;
2270
2271 CLOSE get_sum_hrs;
2272
2273 --Bug 4969936 Fix Start
2274 OPEN hdp_rules;
2275 FETCH hdp_rules
2276 INTO hdp_time_period, hdp_row_count;
2277 CLOSE hdp_rules;
2278 --Bug 4969936 Fix End
2279
2280 IF (detail_hrs_total = sum_hrs_total)
2281 OR (hdp_row_count = 1 AND sum_hrs_total = hdp_time_period * sum_row_count) /*** 4969936 ***/
2282 THEN
2283 -- Time for the day entered in multiple rows are contiguous
2284 -- i.e., nothing got deducted form the previous row based on the hour
2285 -- deduction policy as the hours entered on the previous row were not
2286 -- enough to apply the HDP
2287 -- So apply hour deduction policy considering both the rows and see
2288 -- if the summed up hours are eligible for any deduction.
2289 IF g_debug
2290 THEN
2291 hr_utility.set_location (l_proc, 32);
2292 END IF;
2293
2294 OPEN detail_hours_incl_prev_rows;
2295
2296 FETCH detail_hours_incl_prev_rows
2297 INTO hours_paid_today;
2298
2299 IF g_debug
2300 THEN
2301 hr_utility.TRACE ('hours_paid_today:' || hours_paid_today);
2302 END IF;
2303
2304 CLOSE detail_hours_incl_prev_rows;
2305 /* v115.103 - M. Bhammar
2306 ELSE
2307 -- Time entered on multiple rows are not contiguous in the sense that
2308 -- hour deduction policy has already been applied on the first row
2309 -- entered for the day. So, consider just the hours entered on the
2310 -- current row being processed and see if any hours can be deducted
2311 -- from this row based on the hour deduction policy.
2312 IF g_debug
2313 THEN
2314 hr_utility.set_location (l_proc, 33);
2315 END IF;
2316
2317 OPEN detail_hours_today;
2318
2319 FETCH detail_hours_today
2320 INTO hours_paid_today;
2321
2322 IF g_debug
2323 THEN
2324 hr_utility.TRACE ('hours_paid_today:' || hours_paid_today);
2325 END IF;
2326
2327 CLOSE detail_hours_today;
2328 */
2329 END IF;
2330 -- Check for contiguous entry when Time entered in TIME_IN/TIME_OUT
2331 ELSIF sum_time_in IS NOT NULL AND sum_time_out IS NOT NULL
2332 THEN
2333 IF g_debug
2334 THEN
2335 hr_utility.set_location (l_proc, 35);
2336 END IF;
2337
2338 FOR rec_work_hrs IN csr_work_hrs (g_date_worked, g_tim_id)
2339 LOOP
2340 IF g_debug
2341 THEN
2342 hr_utility.set_location (l_proc, 40);
2343 END IF;
2344
2345 loop_count := loop_count + 1;
2346
2347 IF g_debug
2348 THEN
2349 hr_utility.TRACE ('loop_count:' || loop_count);
2350 hr_utility.TRACE ( 'sum_time_in:'
2351 || TO_CHAR (sum_time_in,
2352 'dd-mon-yyyy hh24:mi:ss'
2353 )
2354 );
2355 hr_utility.TRACE ( 'sum_time_out:'
2356 || TO_CHAR (sum_time_out,
2357 'dd-mon-yyyy hh24:mi:ss'
2358 )
2359 );
2360 hr_utility.TRACE ( 'rec_work_hrs.time_out:'
2361 || TO_CHAR (rec_work_hrs.time_out,
2362 'dd-mon-yyyy hh24:mi:ss'
2363 )
2364 );
2365 hr_utility.TRACE ('rec_work_hrs.id:' || rec_work_hrs.ID);
2366 hr_utility.TRACE ('g_id:' || g_id);
2367 END IF;
2368
2369 -- Check whether the Time entered on two rows is contiguous or not
2370 IF sum_time_in <> sum_time_out
2371 AND sum_time_in = rec_work_hrs.time_out
2372 THEN
2373 IF g_debug
2374 THEN
2375 hr_utility.set_location (l_proc, 50);
2376 END IF;
2377
2378 OPEN hdp_hours_deducted_today;
2379
2380 FETCH hdp_hours_deducted_today
2381 INTO hrs_deducted_today;
2382
2383 IF g_debug
2384 THEN
2385 hr_utility.TRACE ( 'hrs_deducted_today :'
2386 || hrs_deducted_today
2387 );
2388 END IF;
2389
2390 CLOSE hdp_hours_deducted_today;
2391
2392 OPEN detail_hours_incl_prev_rows;
2393
2394 FETCH detail_hours_incl_prev_rows
2395 INTO detail_hrs_total;
2396
2397 IF g_debug
2398 THEN
2399 hr_utility.TRACE ('detail_hrs_total:' || detail_hrs_total
2400 );
2401 END IF;
2402
2403 CLOSE detail_hours_incl_prev_rows;
2404
2405 hours_paid_today := detail_hrs_total + hrs_deducted_today;
2406
2407 IF g_debug
2408 THEN
2409 hr_utility.TRACE ('hours_paid_today:' || hours_paid_today
2410 );
2411 END IF;
2412
2413 EXIT;
2414 ELSIF loop_count = 1 AND g_id = rec_work_hrs.ID
2415 THEN
2416 IF g_debug
2417 THEN
2418 hr_utility.set_location (l_proc, 51);
2419 END IF;
2420
2421 OPEN detail_hours_incl_prev_rows;
2422
2423 FETCH detail_hours_incl_prev_rows
2424 INTO hours_paid_today;
2425
2426 IF g_debug
2427 THEN
2428 hr_utility.TRACE ('hours_paid_today:' || hours_paid_today
2429 );
2430 END IF;
2431
2432 CLOSE detail_hours_incl_prev_rows;
2433
2434 EXIT;
2435 ELSE
2436 IF g_debug
2437 THEN
2438 hr_utility.set_location (l_proc, 52);
2439 END IF;
2440
2441 OPEN detail_hours_today;
2442
2443 FETCH detail_hours_today
2444 INTO hours_paid_today;
2445
2446 CLOSE detail_hours_today;
2447 -- hours_paid_today := 0;
2448 END IF;
2449 END LOOP;
2450 END IF;
2451
2452 IF g_debug
2453 THEN
2454 hr_utility.set_location (l_proc, 53);
2455 END IF;
2456
2457 FOR hdp_rule IN hdp_rule_cursor
2458 LOOP
2459 IF g_debug
2460 THEN
2461 hr_utility.set_location (l_proc, 54);
2462 END IF;
2463
2464 IF g_debug
2465 THEN
2466 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2467 hr_utility.TRACE ('hours_paid_today:' || hours_paid_today);
2468 hr_utility.TRACE ( 'hdp_rule.time_period:'
2469 || hdp_rule.time_period
2470 );
2471 hr_utility.TRACE ('hdp_rule.hours:' || hdp_rule.hours);
2472 END IF;
2473
2474 deduct_hours :=
2475 deduct_hours
2476 + ( FLOOR (hours_paid_today / hdp_rule.time_period)
2477 * hdp_rule.hours
2478 );
2479
2480 IF g_debug
2481 THEN
2482 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2483 END IF;
2484
2485 /* Moved the following statement outside the cursor loop for bug: 5481772 */
2486 -- deduct_hours := deduct_hours - hrs_deducted_today;
2487
2488 IF g_debug
2489 THEN
2490 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2491 END IF;
2492 END LOOP;
2493
2494 deduct_hours := deduct_hours - hrs_deducted_today;
2495
2496 IF g_debug
2497 THEN
2498 hr_utility.set_location (l_proc, 55);
2499 END IF;
2500
2501 -- deduct_prem_hours := deduct_hours;
2502 OPEN sdf_prem_detail_hours;
2503
2504 FETCH sdf_prem_detail_hours
2505 INTO sdf_prem_hours_paid;
2506
2507 IF g_debug
2508 THEN
2509 hr_utility.TRACE ('sdf_prem_hours_paid:' || sdf_prem_hours_paid);
2510 END IF;
2511
2512 CLOSE sdf_prem_detail_hours;
2513
2514 OPEN oth_prem_detail_hours;
2515
2516 FETCH oth_prem_detail_hours
2517 INTO oth_prem_hours_paid;
2518
2519 CLOSE oth_prem_detail_hours;
2520
2521 IF g_debug
2522 THEN
2523 hr_utility.TRACE ('oth_prem_hours_paid' || oth_prem_hours_paid);
2524 END IF;
2525
2526 IF g_debug
2527 THEN
2528 hr_utility.TRACE ('deduct_prem_hours:' || deduct_prem_hours);
2529 hr_utility.TRACE ('sdf_prem_hours_paid:' || sdf_prem_hours_paid);
2530 END IF;
2531
2532 FOR hdp_rule IN hdp_rule_cursor
2533 LOOP
2534 deduct_prem_hours :=
2535 deduct_prem_hours
2536 + ( FLOOR (sdf_prem_hours_paid / hdp_rule.time_period)
2537 * hdp_rule.hours
2538 );
2539
2540 IF g_debug
2541 THEN
2542 hr_utility.TRACE ('deduct_prem_hours:' || deduct_prem_hours);
2543 END IF;
2544 END LOOP;
2545
2546 IF g_debug
2547 THEN
2548 hr_utility.set_location (l_proc, 60);
2549 END IF;
2550
2551 FOR current_dtl_row IN current_dtl
2552 LOOP
2553 IF g_debug
2554 THEN
2555 hr_utility.set_location (l_proc, 70);
2556 END IF;
2557
2558 EXIT WHEN deduct_hours = 0 AND l_prem_adjusted = TRUE;
2559
2560 IF g_debug
2561 THEN
2562 hr_utility.set_location (l_proc, 80);
2563 END IF;
2564
2565 IF deduct_hours = 0 AND l_prem_adjusted = FALSE
2566 THEN
2567 IF g_debug
2568 THEN
2569 hr_utility.set_location (l_proc, 90);
2570 END IF;
2571
2572 -- We just need to adjust the premium hrs and not the
2573 -- REG or OT detail rows
2574 adjust_hours_for_premium (current_dtl_row.parent_id,
2575 current_dtl_row.tim_id,
2576 current_dtl_row.seqno,
2577 current_dtl_row.hours,
2578 sum_time_in,
2579 sum_time_out,
2580 deduct_prem_hours,
2581 'UPDATE',
2582 l_prem_adjusted
2583 );
2584 END IF;
2585
2586 IF g_debug
2587 THEN
2588 hr_utility.set_location (l_proc, 100);
2589 END IF;
2590
2591 IF deduct_hours <> 0
2592 THEN
2593 IF g_debug
2594 THEN
2595 hr_utility.set_location (l_proc, 110);
2596 END IF;
2597
2598 IF g_debug
2599 THEN
2600 hr_utility.TRACE ( 'current_dtl_row.hours:'
2601 || current_dtl_row.hours
2602 );
2603 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2604 END IF;
2605
2606 IF current_dtl_row.hours <= deduct_hours
2607 THEN
2608 IF g_debug
2609 THEN
2610 hr_utility.set_location (l_proc, 120);
2611 END IF;
2612
2613 adjust_hours_for_premium (current_dtl_row.parent_id,
2614 current_dtl_row.tim_id,
2615 current_dtl_row.seqno,
2616 current_dtl_row.hours,
2617 sum_time_in,
2618 sum_time_out,
2619 deduct_hours,
2620 'DELETE',
2621 l_prem_adjusted
2622 );
2623
2624 IF g_debug
2625 THEN
2626 hr_utility.TRACE ('g_osp_id:' || g_osp_id);
2627 END IF;
2628
2629 IF g_osp_id IS NOT NULL
2630 THEN
2631 IF g_debug
2632 THEN
2633 hr_utility.set_location (l_proc, 130);
2634 END IF;
2635
2636 FOR osp_dtl_row IN day_of_wk_prem_dtl
2637 LOOP
2638 IF g_debug
2639 THEN
2640 hr_utility.set_location (l_proc, 140);
2641 END IF;
2642
2643 IF g_debug
2644 THEN
2645 hr_utility.TRACE ( 'osp_dtl_row.hours:'
2646 || osp_dtl_row.hours
2647 );
2648 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2649 END IF;
2650
2651 UPDATE hxt_det_hours_worked
2652 SET hours = osp_dtl_row.hours - deduct_hours,
2653 time_out =
2654 time_in
2655 + ((osp_dtl_row.hours - deduct_hours) / 24
2656 )
2657 WHERE ROWID = osp_dtl_row.dhw_rowid;
2658 END LOOP;
2659 END IF;
2660
2661 IF oth_prem_hours_paid <> 0
2662 THEN
2663
2664 IF g_debug
2665 THEN
2666 hr_utility.set_location (l_proc, 140.1);
2667 END IF;
2668
2669 FOR oth_dtl_row IN oth_prem_dtl
2670 LOOP
2671
2672 IF g_debug
2673 THEN
2674 hr_utility.set_location (l_proc, 140.2);
2675 END IF;
2676
2677 IF g_debug
2678 THEN
2679 hr_utility.TRACE ('oth_prem_dtl.hours:' || oth_dtl_row.hours);
2680 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2681 END IF;
2682
2683 UPDATE hxt_det_hours_worked
2684 SET hours = oth_dtl_row.hours - deduct_hours,
2685 time_out = time_in
2686 + ((oth_dtl_row.hours - deduct_hours) / 24)
2687 WHERE ROWID = oth_dtl_row.dhw_rowid;
2688
2689 END LOOP;
2690 END IF;
2691
2692 DELETE FROM hxt_det_hours_worked
2693 WHERE ROWID = current_dtl_row.dhw_rowid;
2694
2695 IF g_debug
2696 THEN
2697 hr_utility.TRACE ( 'current_dtl_row.hours:'
2698 || current_dtl_row.hours
2699 );
2700 END IF;
2701
2702 deduct_hours := deduct_hours - current_dtl_row.hours;
2703
2704 IF g_debug
2705 THEN
2706 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2707 END IF;
2708 ELSE
2709 IF g_debug
2710 THEN
2711 hr_utility.set_location (l_proc, 150);
2712 END IF;
2713
2714 IF l_prem_adjusted = TRUE
2715 THEN
2716 IF g_debug
2717 THEN
2718 hr_utility.set_location (l_proc, 160);
2719 END IF;
2720
2721 adjust_hours_for_premium (current_dtl_row.parent_id,
2722 current_dtl_row.tim_id,
2723 current_dtl_row.seqno,
2724 current_dtl_row.hours,
2725 sum_time_in,
2726 sum_time_out,
2727 deduct_hours,
2728 'UPDATE',
2729 l_prem_adjusted
2730 );
2731 ELSIF l_prem_adjusted = FALSE
2732 THEN
2733 IF g_debug
2734 THEN
2735 hr_utility.set_location (l_proc, 170);
2736 END IF;
2737
2738 adjust_hours_for_premium (current_dtl_row.parent_id,
2739 current_dtl_row.tim_id,
2740 current_dtl_row.seqno,
2741 current_dtl_row.hours,
2742 sum_time_in,
2743 sum_time_out,
2744 deduct_prem_hours,
2745 'UPDATE',
2746 l_prem_adjusted
2747 );
2748 END IF;
2749
2750 IF g_debug
2751 THEN
2752 hr_utility.set_location (l_proc, 180);
2753 END IF;
2754
2755 IF g_osp_id IS NOT NULL
2756 THEN
2757 IF g_debug
2758 THEN
2759 hr_utility.set_location (l_proc, 190);
2760 hr_utility.TRACE ('g_tim_id :' || g_tim_id);
2761 hr_utility.TRACE ('g_id :' || g_id);
2762 hr_utility.TRACE ('g_osp_id :' || g_osp_id);
2763 hr_utility.TRACE ('g_date_worked :' || g_date_worked);
2764 END IF;
2765
2766 FOR osp_dtl_row IN day_of_wk_prem_dtl
2767 LOOP
2768 IF g_debug
2769 THEN
2770 hr_utility.set_location (l_proc, 200);
2771 hr_utility.TRACE ('deduct_hours :' || deduct_hours);
2772 END IF;
2773
2774 UPDATE hxt_det_hours_worked
2775 SET hours = osp_dtl_row.hours - deduct_hours,
2776 time_out =
2777 time_in
2778 + ((osp_dtl_row.hours - deduct_hours) / 24
2779 )
2780 WHERE ROWID = osp_dtl_row.dhw_rowid;
2781
2782 SELECT hours
2783 INTO test_hours
2784 FROM hxt_det_hours_worked
2785 WHERE ROWID = osp_dtl_row.dhw_rowid;
2786
2787 IF g_debug
2788 THEN
2789 hr_utility.set_location (l_proc, 200.5);
2790 hr_utility.TRACE ('test_hours :' || test_hours);
2791 END IF;
2792 END LOOP;
2793 END IF;
2794
2795 IF oth_prem_hours_paid <> 0
2796 THEN
2797
2798 IF g_debug
2799 THEN
2800 hr_utility.set_location (l_proc, 200.6);
2801 END IF;
2802
2803 FOR oth_dtl_row IN oth_prem_dtl
2804 LOOP
2805
2806 IF g_debug
2807 THEN
2808 hr_utility.set_location (l_proc, 200.7);
2809 END IF;
2810
2811 IF g_debug
2812 THEN
2813 hr_utility.TRACE ('oth_prem_dtl.hours:' || oth_dtl_row.hours);
2814 hr_utility.TRACE ('deduct_hours:' || deduct_hours);
2815 END IF;
2816
2817 UPDATE hxt_det_hours_worked
2818 SET hours = oth_dtl_row.hours - deduct_hours,
2819 time_out = time_in
2820 + ((oth_dtl_row.hours - deduct_hours) / 24)
2821 WHERE ROWID = oth_dtl_row.dhw_rowid;
2822
2823 END LOOP;
2824 END IF;
2825
2826 IF g_debug
2827 THEN
2828 hr_utility.set_location (l_proc, 210);
2829 END IF;
2830
2831 UPDATE hxt_det_hours_worked
2832 SET hours = current_dtl_row.hours - deduct_hours,
2833 time_out =
2834 time_in
2835 + ((current_dtl_row.hours - deduct_hours) / 24)
2836 WHERE ROWID = current_dtl_row.dhw_rowid;
2837
2838 deduct_hours := 0;
2839 END IF;
2840 END IF;
2841 END LOOP;
2842
2843 IF g_debug
2844 THEN
2845 hr_utility.set_location (l_proc, 220);
2846 END IF;
2847
2848 RETURN (0);
2849 END adjust_hours_for_hdp;
2850
2851 --
2852 --------------------------------------------------------------------------------
2853 --
2854 FUNCTION adjust_for_hdp (
2855 p_hours_this_segment IN NUMBER,
2856 p_error_code IN OUT NOCOPY NUMBER
2857 )
2858 RETURN NUMBER
2859 IS
2860 -- Returns the hours to be paid this segment after subtracting any applicable
2861 -- hours from the hour deduction policy.
2862 CURSOR hdp_rule_cursor
2863 IS
2864 SELECT hours, time_period
2865 FROM hxt_hour_deduction_rules thdr
2866 WHERE thdr.hdp_id = g_hdp_id
2867 AND g_date_worked BETWEEN thdr.effective_start_date
2868 AND thdr.effective_end_date;
2869
2870 CURSOR detail_hours_today
2871 IS
2872 SELECT NVL (SUM (dhw.hours), 0) det_hours
2873 FROM hxt_pay_element_types_f_ddf_v eltv,
2874 pay_element_types_f elt,
2875 hxt_det_hours_worked dhw,
2876 hxt_sum_hours_worked shw --<-- New Table
2877 WHERE elt.element_type_id = dhw.element_type_id
2878 AND shw.ID = dhw.parent_id --<-- New Join
2879 AND shw.element_type_id IS NULL
2880 --<-- New check: No Hours Override
2881 AND dhw.date_worked BETWEEN elt.effective_start_date
2882 AND elt.effective_end_date
2883 AND eltv.element_type_id = elt.element_type_id
2884 AND dhw.date_worked BETWEEN eltv.effective_start_date
2885 AND eltv.effective_end_date
2886 AND eltv.hxt_earning_category IN ('REG', 'OVT')
2887 AND dhw.tim_id = g_tim_id
2888 AND dhw.date_worked = g_date_worked;
2889
2890 CURSOR hdp_hours_deducted_today
2891 IS
2892 SELECT (NVL (sum_hours, 0) - NVL (det_hours, 0))
2893 FROM hxt_hdp_sum_hours_worked_v shw,
2894 hxt_hdp_det_hours_worked_v dhw
2895 WHERE dhw.det_date = g_date_worked
2896 AND dhw.det_tim_id = g_tim_id
2897 AND shw.sum_date = dhw.det_date
2898 AND shw.sum_tim_id = dhw.det_tim_id;
2899
2900 CURSOR get_sum_time_out
2901 IS
2902 SELECT time_in, time_out
2903 FROM hxt_sum_hours_worked
2904 WHERE ID = g_id;
2905
2906 addback_hours NUMBER := 0;
2907 deduct_hours NUMBER := 0;
2908 daily_total_hours NUMBER;
2909 hours_paid_already NUMBER := 0;
2910 sum_time_out DATE := NULL;
2911 sum_time_in DATE := NULL;
2912 l_proc VARCHAR2 (250);
2913 BEGIN
2914 IF g_debug
2915 THEN
2916 l_proc := 'hxt_time_detail.adjust_for_hdp';
2917 hr_utility.set_location (l_proc, 10);
2918 hr_utility.TRACE ('g_hdp_id :' || g_hdp_id);
2919 END IF;
2920
2921 IF g_hdp_id IS NULL
2922 THEN
2923 IF g_debug
2924 THEN
2925 hr_utility.set_location (l_proc, 20);
2926 END IF;
2927
2928 RETURN (p_hours_this_segment);
2929 END IF;
2930
2931 IF g_debug
2932 THEN
2933 hr_utility.set_location (l_proc, 30);
2934 END IF;
2935
2936 OPEN get_sum_time_out;
2937
2938 FETCH get_sum_time_out
2939 INTO sum_time_in, sum_time_out;
2940
2941 CLOSE get_sum_time_out;
2942
2943 IF g_debug
2944 THEN
2945 hr_utility.TRACE ( 'sum_time_in :'
2946 || TO_CHAR (sum_time_in,
2947 'dd-mon-yyyy hh24:mi:ss'
2948 )
2949 );
2950 hr_utility.TRACE ( 'sum_time_out:'
2951 || TO_CHAR (sum_time_out,
2952 'dd-mon-yyyy hh24:mi:ss'
2953 )
2954 );
2955 hr_utility.TRACE ( 'g_TIME_OUT :'
2956 || TO_CHAR (g_time_out,
2957 'dd-mon-yyyy hh24:mi:ss')
2958 );
2959 END IF;
2960
2961 IF sum_time_out IS NOT NULL AND g_time_out IS NOT NULL
2962 THEN
2963 IF g_debug
2964 THEN
2965 hr_utility.set_location (l_proc, 40);
2966 END IF;
2967
2968 IF g_time_out < sum_time_out
2969 THEN
2970 IF g_debug
2971 THEN
2972 hr_utility.set_location (l_proc, 50);
2973 END IF;
2974
2975 RETURN (p_hours_this_segment);
2976 END IF;
2977 END IF;
2978
2979 IF g_debug
2980 THEN
2981 hr_utility.set_location (l_proc, 60);
2982 END IF;
2983
2984 OPEN detail_hours_today;
2985
2986 FETCH detail_hours_today
2987 INTO hours_paid_already;
2988
2989 IF g_debug
2990 THEN
2991 hr_utility.TRACE ('hours_paid_already :' || hours_paid_already);
2992 END IF;
2993
2994 CLOSE detail_hours_today;
2995
2996 OPEN hdp_hours_deducted_today;
2997
2998 FETCH hdp_hours_deducted_today
2999 INTO addback_hours;
3000
3001 IF g_debug
3002 THEN
3003 hr_utility.TRACE ('addback_hours :' || addback_hours);
3004 END IF;
3005
3006 CLOSE hdp_hours_deducted_today;
3007
3008 IF g_debug
3009 THEN
3010 hr_utility.TRACE ( 'sum_time_in :'
3011 || TO_CHAR (sum_time_in,
3012 'dd-mon-yyyy hh24:mi:ss'
3013 )
3014 );
3015 hr_utility.TRACE ( 'g_TIME_IN :'
3016 || TO_CHAR (g_time_in, 'dd-mon-yyyy hh24:mi:ss')
3017 );
3018 hr_utility.TRACE ('p_hours_this_segment:' || p_hours_this_segment);
3019 END IF;
3020
3021 IF sum_time_in IS NOT NULL AND g_time_in IS NOT NULL
3022 THEN
3023 IF g_debug
3024 THEN
3025 hr_utility.set_location (l_proc, 70);
3026 END IF;
3027
3028 IF g_time_in > sum_time_in
3029 THEN
3030 IF g_debug
3031 THEN
3032 hr_utility.set_location (l_proc, 80);
3033 hr_utility.TRACE ('-------g_time_in > sum_time_in------');
3034 END IF;
3035
3036 addback_hours := addback_hours - p_hours_this_segment;
3037
3038 IF g_debug
3039 THEN
3040 hr_utility.TRACE ('addback_hours :' || addback_hours);
3041 END IF;
3042 END IF;
3043 END IF;
3044
3045 IF g_debug
3046 THEN
3047 hr_utility.set_location (l_proc, 90);
3048 hr_utility.TRACE ('p_hours_this_segment:' || p_hours_this_segment);
3049 hr_utility.TRACE ('hours_paid_already :' || hours_paid_already);
3050 hr_utility.TRACE ('addback_hours :' || addback_hours);
3051 END IF;
3052
3053 daily_total_hours :=
3054 p_hours_this_segment + hours_paid_already + addback_hours;
3055
3056 IF g_debug
3057 THEN
3058 hr_utility.TRACE ('daily_total_hours :' || daily_total_hours);
3059 END IF;
3060
3061 FOR hdp_rule IN hdp_rule_cursor
3062 LOOP
3063 -- Calculate totals needed
3064 IF g_debug
3065 THEN
3066 hr_utility.set_location (l_proc, 100);
3067 hr_utility.TRACE ( 'hdp_rule.time_period:'
3068 || hdp_rule.time_period
3069 );
3070 END IF;
3071
3072 deduct_hours :=
3073 deduct_hours
3074 + ( FLOOR (daily_total_hours / hdp_rule.time_period)
3075 * hdp_rule.hours
3076 );
3077
3078 IF g_debug
3079 THEN
3080 hr_utility.TRACE ('deduct_hours :' || deduct_hours);
3081 END IF;
3082 END LOOP;
3083
3084 IF g_debug
3085 THEN
3086 hr_utility.set_location (l_proc, 110);
3087 hr_utility.TRACE ('p_hours_this_segment:' || p_hours_this_segment);
3088 hr_utility.TRACE ('deduct_hours :' || deduct_hours);
3089 hr_utility.TRACE ('addback_hours :' || addback_hours);
3090 END IF;
3091
3092 --IF p_hours_this_segment <= (deduct_hours - addback_hours) THEN
3093 --Above IF condition changed as follows for bug 3147339
3094 IF p_hours_this_segment < (deduct_hours - addback_hours)
3095 THEN
3096 IF g_debug
3097 THEN
3098 hr_utility.set_location (l_proc, 120);
3099 END IF;
3100
3101 IF adjust_for_hdp_shortage (deduct_hours - addback_hours) <> 0
3102 THEN
3103 IF g_debug
3104 THEN
3105 hr_utility.set_location (l_proc, 130);
3106 END IF;
3107
3108 fnd_message.set_name ('HXT', 'HXT_39488_CANT_DEDUCT_HOURS');
3109 p_error_code :=
3110 call_hxthxc_gen_error ('HXT',
3111 'HXT_39488_CANT_DEDUCT_HOURS',
3112 NULL,
3113 g_location,
3114 ''
3115 );
3116 --2278400 p_error_code := call_gen_error(g_location, '');
3117 END IF;
3118
3119 IF g_debug
3120 THEN
3121 hr_utility.set_location (l_proc, 140);
3122 END IF;
3123
3124 RETURN (p_hours_this_segment);
3125 END IF;
3126
3127 IF g_debug
3128 THEN
3129 hr_utility.set_location (l_proc, 150);
3130 hr_utility.TRACE ('p_hours_this_segment:' || p_hours_this_segment);
3131 hr_utility.TRACE ('deduct_hours :' || deduct_hours);
3132 hr_utility.TRACE ('addback_hours :' || addback_hours);
3133 END IF;
3134
3135 RETURN (p_hours_this_segment - (deduct_hours - addback_hours));
3136 END;
3137
3138 --
3139 --------------------------------------------------------------------------------
3140 --
3141 FUNCTION set_consecutive_days_reached (p_consecutive_days_limit IN NUMBER)
3142 RETURN BOOLEAN
3143 IS
3144 -- returns TRUE if consecutive days number of special earning rule have been
3145 -- worked days must be in the same week starting from start_day_of_week
3146 consecutive_days NUMBER;
3147 BEGIN
3148 SELECT (COUNT (DISTINCT work_date) + 1
3149 ) -- 1 added for current day which may not
3150 -- be in db
3151 INTO consecutive_days
3152 FROM hxt_daily_hours_worked_v
3153 WHERE work_date BETWEEN g_date_worked
3154 - (p_consecutive_days_limit - 1
3155 ) -- start day
3156 AND g_date_worked - 1 -- yesterday
3157 AND work_date >= NEXT_DAY (g_date_worked - 7, start_day_of_week)
3158 AND tim_id = g_tim_id;
3159
3160 g_cons_days_worked := consecutive_days;
3161
3162 IF consecutive_days >= p_consecutive_days_limit
3163 THEN
3164 RETURN TRUE;
3165 ELSE
3166 RETURN FALSE;
3167 END IF;
3168 END;
3169
3170 --
3171 -------------------------------------------------------------------------------
3172 --
3173 FUNCTION getconsecutivedaysworked (a_date_worked IN DATE)
3174 RETURN NUMBER
3175 IS
3176 CURSOR date_start_cur (
3177 c_tim_id NUMBER,
3178 c_date_worked DATE,
3179 a_date_worked DATE
3180 )
3181 IS
3182 SELECT sm.date_worked
3183 FROM hxt_sum_hours_worked sm
3184 --Added this join to support the OTLR Recurring Preiod Preference
3185 , hxt_timecards tim
3186 --WHERE sm.tim_id = c_tim_id
3187
3188 --Changed the above where clause as follows to support the
3189 --OTLR Recurring Preiod Preference.
3190 WHERE tim.for_person_id = g_person_id
3191 AND sm.tim_id = tim.ID
3192 AND sm.hours > 0
3193 AND sm.date_worked = c_date_worked
3194 AND sm.date_worked >=
3195 NEXT_DAY (a_date_worked - 7, start_day_of_week);
3196
3197 consecutive_days NUMBER := 0;
3198 i NUMBER;
3199 l_date_start DATE;
3200 l_continue BOOLEAN := TRUE;
3201 l_proc VARCHAR2 (200);
3202 BEGIN
3203 IF g_debug
3204 THEN
3205 l_proc := 'hxt_time_detail.GetConsecutiveDaysWorked';
3206 hr_utility.set_location (l_proc, 10);
3207 END IF;
3208
3209 i := 0;
3210 l_date_start := a_date_worked;
3211
3212 IF g_debug
3213 THEN
3214 hr_utility.TRACE ( 'l_date_start :'
3215 || TO_CHAR (l_date_start,
3216 'DD-MON-YYYY HH24:MI:SS'
3217 )
3218 );
3219 hr_utility.TRACE ('i :' || i);
3220 hr_utility.set_location (l_proc, 20);
3221 END IF;
3222
3223 WHILE (l_continue = TRUE AND i < 7)
3224 LOOP
3225 IF g_debug
3226 THEN
3227 hr_utility.set_location (l_proc, 30);
3228 hr_utility.TRACE ('i :' || i);
3229 hr_utility.TRACE ('g_tim_id :' || g_tim_id);
3230 hr_utility.TRACE ( 'a_date_worked :'
3231 || TO_CHAR (a_date_worked,
3232 'DD-MON-YYYY HH24:MI:SS'
3233 )
3234 );
3235 hr_utility.TRACE ('start_day_of_week :' || start_day_of_week);
3236 hr_utility.TRACE ('g_person_id :' || g_person_id);
3237 END IF;
3238
3239 OPEN date_start_cur (g_tim_id, a_date_worked - i, a_date_worked);
3240
3241 FETCH date_start_cur
3242 INTO l_date_start;
3243
3244 IF g_debug
3245 THEN
3246 hr_utility.TRACE ( 'l_date_start :'
3247 || TO_CHAR (l_date_start,
3248 'DD-MON-YYYY HH24:MI:SS'
3249 )
3250 );
3251 END IF;
3252
3253 IF date_start_cur%NOTFOUND
3254 THEN
3255 IF g_debug
3256 THEN
3257 hr_utility.set_location (l_proc, 40);
3258 END IF;
3259
3260 l_continue := FALSE;
3261 END IF;
3262
3263 CLOSE date_start_cur;
3264
3265 IF l_continue = TRUE
3266 THEN
3267 IF g_debug
3268 THEN
3269 hr_utility.set_location (l_proc, 50);
3270 END IF;
3271
3272 i := i + 1;
3273 END IF;
3274
3275 IF g_debug
3276 THEN
3277 hr_utility.set_location (l_proc, 60);
3278 END IF;
3279 END LOOP;
3280
3281 IF g_debug
3282 THEN
3283 hr_utility.set_location (l_proc, 70);
3284 hr_utility.TRACE ('i :' || i);
3285 END IF;
3286
3287 RETURN i;
3288 END;
3289
3290 --
3291 -------------------------------------------------------------------------------
3292 --
3293 FUNCTION consecutivedaysworked_for_spc (a_date_worked IN DATE)
3294 RETURN NUMBER
3295 IS
3296 CURSOR date_start_cur (
3297 c_tim_id NUMBER,
3298 c_date_worked DATE,
3299 a_date_worked DATE
3300 )
3301 IS
3302 SELECT sm.date_worked
3303 FROM hxt_sum_hours_worked sm, hxt_timecards tim
3304 WHERE tim.for_person_id = g_person_id
3305 AND sm.tim_id = tim.ID
3306 AND sm.hours > 0
3307 AND sm.date_worked = c_date_worked
3308 AND sm.date_worked >=
3309 NEXT_DAY (a_date_worked - 7, start_day_of_week);
3310
3311 CURSOR worked_elements_cur
3312 IS
3313 SELECT element_type_id
3314 FROM hxt_earn_groups eg, hxt_earn_group_types egt
3315 WHERE eg.egt_id = egt.ID AND egt.NAME = 'OTLR 7th Day Hours';
3316
3317 l_wrkd_elements_cur worked_elements_cur%ROWTYPE;
3318
3319 CURSOR chk_det_for_wrkd_elements (a_date_start DATE)
3320 IS
3321 SELECT det.element_type_id
3322 FROM hxt_det_hours_worked det, hxt_timecards tim
3323 WHERE det.tim_id = tim.ID
3324 AND tim.for_person_id = g_person_id
3325 AND det.hours > 0
3326 AND det.date_worked = a_date_start;
3327
3328 l_chk_det_elements_cur chk_det_for_wrkd_elements%ROWTYPE;
3329 consecutive_days NUMBER := 0;
3330 i NUMBER;
3331 j NUMBER;
3332 l_date_start DATE;
3333 l_continue BOOLEAN := TRUE;
3334 l_day_worked BOOLEAN := FALSE;
3335 l_proc VARCHAR2 (200);
3336 BEGIN
3337 IF g_debug
3338 THEN
3339 l_proc := 'hxt_time_detail.ConsecutiveDaysWorked_for_SPC';
3340 hr_utility.set_location (l_proc, 10);
3341 END IF;
3342
3343 i := 0;
3344 j := 0;
3345 l_date_start := a_date_worked;
3346
3347 IF g_debug
3348 THEN
3349 hr_utility.TRACE ( 'l_date_start :'
3350 || TO_CHAR (l_date_start,
3351 'DD-MON-YYYY HH24:MI:SS'
3352 )
3353 );
3354 hr_utility.TRACE ('i :' || i);
3355 hr_utility.set_location (l_proc, 20);
3356 END IF;
3357
3358 WHILE (l_continue = TRUE AND i < 7)
3359 LOOP
3360 IF g_debug
3361 THEN
3362 hr_utility.set_location (l_proc, 30);
3363 END IF;
3364
3365 l_day_worked := FALSE;
3366
3367 IF g_debug
3368 THEN
3369 hr_utility.TRACE ('i :' || i);
3370 hr_utility.TRACE ('g_tim_id :' || g_tim_id);
3371 hr_utility.TRACE ( 'a_date_worked :'
3372 || TO_CHAR (a_date_worked,
3373 'DD-MON-YYYY HH24:MI:SS'
3374 )
3375 );
3376 hr_utility.TRACE ('start_day_of_week :' || start_day_of_week);
3377 hr_utility.TRACE ('g_person_id :' || g_person_id);
3378 END IF;
3379
3380 OPEN date_start_cur (g_tim_id, a_date_worked - i, a_date_worked);
3381
3382 FETCH date_start_cur
3383 INTO l_date_start;
3384
3385 IF g_debug
3386 THEN
3387 hr_utility.TRACE ( 'l_date_start :'
3388 || TO_CHAR (l_date_start,
3389 'DD-MON-YYYY HH24:MI:SS'
3390 )
3391 );
3392 END IF;
3393
3394 IF date_start_cur%NOTFOUND
3395 THEN
3396 IF g_debug
3397 THEN
3398 hr_utility.set_location (l_proc, 40);
3399 END IF;
3400
3401 l_continue := FALSE;
3402 END IF;
3403
3404 IF g_debug
3405 THEN
3406 hr_utility.set_location (l_proc, 50);
3407 END IF;
3408
3409 IF l_continue = TRUE
3410 THEN
3411 IF g_debug
3412 THEN
3413 hr_utility.set_location (l_proc, 60);
3414 END IF;
3415
3416 -- IF a_date_worked <> l_date_start THEN
3417 IF g_debug
3418 THEN
3419 hr_utility.set_location (l_proc, 70);
3420 END IF;
3421
3422 OPEN chk_det_for_wrkd_elements (l_date_start);
3423
3424 LOOP -- fetch worked element rows
3425 IF g_debug
3426 THEN
3427 hr_utility.set_location (l_proc, 80);
3428 END IF;
3429
3430 FETCH chk_det_for_wrkd_elements
3431 INTO l_chk_det_elements_cur;
3432
3433 IF g_debug
3434 THEN
3435 hr_utility.TRACE
3436 ( 'l_chk_det_elements_cur.element_type_id:'
3437 || l_chk_det_elements_cur.element_type_id
3438 );
3439 END IF;
3440
3441 EXIT WHEN chk_det_for_wrkd_elements%NOTFOUND;
3442
3443 -- OR l_day_worked = TRUE;
3444 IF g_debug
3445 THEN
3446 hr_utility.set_location (l_proc, 90);
3447 END IF;
3448
3449 OPEN worked_elements_cur;
3450
3451 LOOP
3452 IF g_debug
3453 THEN
3454 hr_utility.set_location (l_proc, 100);
3455 END IF;
3456
3457 FETCH worked_elements_cur
3458 INTO l_wrkd_elements_cur;
3459
3460 IF g_debug
3461 THEN
3462 hr_utility.TRACE
3463 ( 'l_wrkd_elements_cur.element_type_id:'
3464 || l_wrkd_elements_cur.element_type_id
3465 );
3466 END IF;
3467
3468 EXIT WHEN worked_elements_cur%NOTFOUND;
3469
3470 IF g_debug
3471 THEN
3472 hr_utility.set_location (l_proc, 110);
3473 END IF;
3474
3475 IF (l_chk_det_elements_cur.element_type_id =
3476 l_wrkd_elements_cur.element_type_id
3477 )
3478 THEN
3479 IF g_debug
3480 THEN
3481 hr_utility.set_location (l_proc, 120);
3482 END IF;
3483
3484 l_day_worked := TRUE;
3485
3486 -- CLOSE worked_elements_cur;
3487 IF g_debug
3488 THEN
3489 hr_utility.set_location (l_proc, 125);
3490 END IF;
3491
3492 EXIT;
3493
3494 IF g_debug
3495 THEN
3496 hr_utility.set_location (l_proc, 130);
3497 END IF;
3498 END IF;
3499
3500 IF g_debug
3501 THEN
3502 hr_utility.set_location (l_proc, 140);
3503 END IF;
3504 END LOOP;
3505
3506 CLOSE worked_elements_cur;
3507
3508 IF g_debug
3509 THEN
3510 hr_utility.set_location (l_proc, 150);
3511 END IF;
3512
3513 IF l_day_worked = TRUE
3514 THEN
3515 IF g_debug
3516 THEN
3517 hr_utility.set_location (l_proc, 160);
3518 END IF;
3519
3520 -- CLOSE chk_det_for_wrkd_elements;
3521 EXIT;
3522 END IF;
3523
3524 IF g_debug
3525 THEN
3526 hr_utility.set_location (l_proc, 170);
3527 END IF;
3528 END LOOP;
3529
3530 CLOSE chk_det_for_wrkd_elements;
3531
3532 IF g_debug
3533 THEN
3534 hr_utility.set_location (l_proc, 180);
3535 END IF;
3536
3537 -- END IF;
3538 IF (l_day_worked = TRUE) OR (l_date_start = a_date_worked)
3539 THEN
3540 IF g_debug
3541 THEN
3542 hr_utility.set_location (l_proc, 185);
3543 END IF;
3544
3545 j := j + 1;
3546
3547 IF g_debug
3548 THEN
3549 hr_utility.TRACE ('j:' || j);
3550 END IF;
3551 END IF;
3552
3553 CLOSE date_start_cur;
3554
3555 IF l_continue = TRUE
3556 THEN
3557 IF g_debug
3558 THEN
3559 hr_utility.set_location (l_proc, 190);
3560 END IF;
3561
3562 i := i + 1;
3563
3564 IF g_debug
3565 THEN
3566 hr_utility.TRACE ('i:' || i);
3567 END IF;
3568 END IF;
3569
3570 IF g_debug
3571 THEN
3572 hr_utility.set_location (l_proc, 190);
3573 END IF;
3574 END IF;
3575
3576 IF g_debug
3577 THEN
3578 hr_utility.set_location (l_proc, 200);
3579 END IF;
3580 END LOOP;
3581
3582 IF g_debug
3583 THEN
3584 hr_utility.set_location (l_proc, 210);
3585 hr_utility.TRACE ('j :' || j);
3586 END IF;
3587
3588 RETURN j;
3589 END;
3590
3591 --
3592 -------------------------------------------------------------------------------
3593 --
3594 FUNCTION adjust_abs_hrs_on_prev_days (
3595 c_tim_id IN NUMBER,
3596 c_date_worked IN DATE,
3597 c_tot_hours IN NUMBER,
3598 c_hours_left IN NUMBER,
3599 c_element_type_id IN NUMBER
3600 )
3601 RETURN NUMBER
3602 IS
3603 CURSOR reg_hrs_cur (a_tim_id NUMBER, a_date_worked DATE)
3604 IS
3605 SELECT hrw.ROWID hrw_rowid, hrw.hours, hrw.date_worked,
3606 hrw.parent_id, hrw.assignment_id,
3607 hrw.fcl_earn_reason_code, hrw.ffv_cost_center_id,
3608 hrw.tas_id, hrw.location_id, hrw.sht_id,
3609 hrw.hrw_comment, hrw.ffv_rate_code_id,
3610 hrw.rate_multiple, hrw.hourly_rate, hrw.amount,
3611 hrw.fcl_tax_rule_code, hrw.separate_check_flag,
3612 hrw.seqno, hrw.time_in, hrw.time_out, hrw.project_id,
3613 shr.earn_pol_id, hrw.tim_id, hrw.element_type_id,
3614 hrw.created_by, hrw.creation_date, hrw.last_updated_by,
3615 hrw.last_update_date, hrw.last_update_login,
3616 hrw.effective_start_date, hrw.effective_end_date,
3617 hrw.job_id, hrw.state_name, hrw.county_name,
3618 hrw.city_name, hrw.zip_code
3619 FROM hxt_pay_element_types_f_ddf_v eltv,
3620 pay_element_types_f elt,
3621 hxt_sum_hours_worked shr,
3622 hxt_det_hours_worked hrw
3623 WHERE hrw.date_worked BETWEEN NEXT_DAY (a_date_worked - 7,
3624 start_day_of_week
3625 )
3626 AND a_date_worked
3627 AND hrw.tim_id = a_tim_id
3628 AND elt.element_type_id = hrw.element_type_id
3629 AND eltv.hxt_earning_category = 'REG'
3630 AND hrw.date_worked BETWEEN elt.effective_start_date
3631 AND elt.effective_end_date
3632 AND hrw.parent_id = shr.ID
3633 AND shr.element_type_id IS NULL
3634 AND eltv.element_type_id = elt.element_type_id
3635 AND hrw.date_worked BETWEEN eltv.effective_start_date
3636 AND eltv.effective_end_date
3637 ORDER BY hrw.date_worked DESC, hrw.time_in DESC, hrw.ID DESC;
3638
3639 CURSOR clear_reg_detail_rec (c_parent_id NUMBER)
3640 IS
3641 SELECT hrw.ROWID
3642 FROM hxt_det_hours_worked hrw,
3643 pay_element_types_f elt,
3644 hxt_pay_element_types_f_ddf_v eltv
3645 WHERE hrw.parent_id = c_parent_id
3646 AND hrw.element_type_id = elt.element_type_id
3647 AND hrw.date_worked BETWEEN elt.effective_start_date
3648 AND elt.effective_end_date
3649 AND elt.element_type_id = eltv.element_type_id
3650 AND hrw.date_worked BETWEEN eltv.effective_start_date
3651 AND eltv.effective_end_date
3652 AND eltv.hxt_earning_category = 'REG';
3653
3654 CURSOR re_explode_details (c_parent_id NUMBER)
3655 IS
3656 SELECT hrw.ROWID hrw_rowid, hrw.hours, hrw.date_worked,
3657 hrw.parent_id, hrw.assignment_id, hrw.fcl_earn_reason_code,
3658 hrw.ffv_cost_center_id, hrw.tas_id, hrw.location_id,
3659 hrw.sht_id, hrw.hrw_comment, hrw.ffv_rate_code_id,
3660 hrw.rate_multiple, hrw.hourly_rate, hrw.amount,
3661 hrw.fcl_tax_rule_code, hrw.separate_check_flag, hrw.seqno,
3662 hrw.time_in, hrw.time_out, hrw.project_id, shr.earn_pol_id,
3663 hrw.tim_id, hrw.element_type_id, hrw.created_by,
3664 hrw.creation_date, hrw.last_updated_by,
3665 hrw.last_update_date, hrw.last_update_login,
3666 hrw.effective_start_date, hrw.effective_end_date,
3667 hrw.job_id, hrw.state_name, hrw.county_name, hrw.city_name,
3668 hrw.zip_code
3669 FROM hxt_det_hours_worked hrw,
3670 hxt_sum_hours_worked shr,
3671 pay_element_types_f elt,
3672 hxt_pay_element_types_f_ddf_v eltv
3673 WHERE hrw.parent_id = c_parent_id
3674 AND hrw.element_type_id = elt.element_type_id
3675 AND hrw.date_worked BETWEEN elt.effective_start_date
3676 AND elt.effective_end_date
3677 AND elt.element_type_id = eltv.element_type_id
3678 AND hrw.date_worked BETWEEN eltv.effective_start_date
3679 AND eltv.effective_end_date
3680 AND hrw.parent_id = shr.ID
3681 AND eltv.hxt_earning_category IN ('REG', 'OVT');
3682
3683 l_del_rowid ROWID;
3684 l_rule_earning_type NUMBER;
3685 l_segment_start_time DATE;
3686 l_segment_stop_time DATE;
3687 l_hours_to_pay NUMBER;
3688 l_rowid ROWID;
3689 l_hours_to_adjust NUMBER;
3690 l_days_worked NUMBER;
3691 l_abs_count NUMBER;
3692 l_reg_hrs_cur reg_hrs_cur%ROWTYPE;
3693 l_re_explode_details re_explode_details%ROWTYPE;
3694 l_update_rowid ROWID;
3695 l_time_in hxt_det_hours_worked.time_in%TYPE;
3696 l_time_out hxt_det_hours_worked.time_out%TYPE;
3697 l_hours NUMBER;
3698 l_hours_left NUMBER;
3699 l_work_plan NUMBER;
3700 l_rotation_plan NUMBER;
3701 l_rotation_or_work_plan VARCHAR2 (1);
3702 l_retcode NUMBER;
3703 l_hours NUMBER;
3704 l_shift_hours NUMBER; -- SIR212
3705 l_egp_id NUMBER; -- earning policy
3706 l_hdp_id NUMBER; -- hours deduction policy
3707 l_hdy_id NUMBER; -- holiday day ID
3708 l_sdp_id NUMBER; -- shift diff policy
3709 l_egp_type VARCHAR2 (30); -- earning policy type
3710 l_egt_id NUMBER; -- include earning group
3711 l_pep_id NUMBER; -- prem elig policy
3712 l_pip_id NUMBER; -- prem interact policy
3713 l_hcl_id NUMBER; -- holiday calendar
3714 l_hcl_elt_id NUMBER; -- holiday earning type
3715 l_sdf_id NUMBER; -- override shift diff prem
3716 l_osp_id NUMBER; -- off-shift prem
3717 l_standard_start NUMBER;
3718 l_standard_stop NUMBER;
3719 l_early_start NUMBER;
3720 l_late_stop NUMBER;
3721 l_min_tcard_intvl NUMBER;
3722 l_round_up NUMBER;
3723 l_hol_code NUMBER;
3724 l_hol_yn VARCHAR2 (1) := 'N';
3725 l_error NUMBER;
3726 l_status NUMBER;
3727 l_next_index BINARY_INTEGER := 0;
3728 l_next_parent_index BINARY_INTEGER := 0;
3729 l_delete NUMBER;
3730 l_delete_det NUMBER;
3731 l_re_explode NUMBER;
3732 i NUMBER;
3733 j NUMBER;
3734 k NUMBER;
3735 l_proc VARCHAR2 (200);
3736 BEGIN
3737 IF g_debug
3738 THEN
3739 l_proc := 'hxt_time_detail.adjust_abs_hrs_on_prev_days';
3740 hr_utility.set_location (l_proc, 10);
3741 hr_utility.TRACE ('c_tim_id:' || c_tim_id);
3742 hr_utility.TRACE ( 'c_date_worked :'
3743 || TO_CHAR (c_date_worked,
3744 'DD-MON-YYYY HH24:MI:SS'
3745 )
3746 );
3747 hr_utility.TRACE ('c_hours_left:' || c_hours_left);
3748 END IF;
3749
3750 l_hours_left := c_hours_left;
3751
3752 IF g_debug
3753 THEN
3754 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
3755 END IF;
3756
3757 IF l_hours_left = 0
3758 THEN
3759 RETURN 0;
3760 END IF;
3761
3762 IF g_parent_to_re_explode.COUNT > 0
3763 THEN
3764 l_delete := g_parent_to_re_explode.FIRST;
3765
3766 LOOP
3767 EXIT WHEN NOT g_parent_to_re_explode.EXISTS (l_delete);
3768 g_parent_to_re_explode (l_delete).parent_id := NULL;
3769 l_delete := g_parent_to_re_explode.NEXT (l_delete);
3770 END LOOP;
3771
3772 IF g_debug
3773 THEN
3774 hr_utility.TRACE
3775 ('Deleting g_parent_to_re_explode PL/SQL table');
3776 END IF;
3777
3778 g_parent_to_re_explode.DELETE;
3779 END IF;
3780
3781 OPEN reg_hrs_cur (c_tim_id, c_date_worked);
3782
3783 WHILE l_hours_left > 0
3784 LOOP
3785 IF g_debug
3786 THEN
3787 hr_utility.set_location (l_proc, 20);
3788 END IF;
3789
3790 FETCH reg_hrs_cur
3791 INTO l_reg_hrs_cur;
3792
3793 IF reg_hrs_cur%NOTFOUND
3794 THEN
3795 IF g_debug
3796 THEN
3797 hr_utility.set_location (l_proc, 30);
3798 END IF;
3799
3800 SELECT COUNT (*)
3801 INTO l_abs_count
3802 FROM hxt_pay_element_types_f_ddf_v eltv,
3803 pay_element_types_f elt,
3804 hxt_sum_hours_worked shr,
3805 hxt_timecards tim
3806 WHERE shr.date_worked BETWEEN NEXT_DAY (c_date_worked - 7,
3807 start_day_of_week
3808 )
3809 AND c_date_worked
3810 AND shr.tim_id = c_tim_id
3811 AND elt.element_type_id = shr.element_type_id
3812 AND eltv.hxt_earning_category = 'ABS'
3813 AND shr.date_worked BETWEEN elt.effective_start_date
3814 AND elt.effective_end_date
3815 AND shr.element_type_id IS NOT NULL
3816 AND eltv.element_type_id = elt.element_type_id
3817 AND shr.date_worked BETWEEN eltv.effective_start_date
3818 AND eltv.effective_end_date;
3819
3820 IF g_debug
3821 THEN
3822 hr_utility.TRACE ('l_abs_count :' || l_abs_count);
3823 END IF;
3824
3825 IF g_spc_dy_eg IS NOT NULL
3826 THEN
3827 l_days_worked :=
3828 consecutivedaysworked_for_spc (g_date_worked);
3829
3830 IF g_debug
3831 THEN
3832 hr_utility.TRACE ( 'date_worked :'
3833 || TO_CHAR (g_date_worked, 'DD/MON/YY')
3834 );
3835 hr_utility.TRACE ( 'consec_days_worked:'
3836 || TO_CHAR (consec_days_worked)
3837 );
3838 END IF;
3839 ELSE
3840 l_days_worked := getconsecutivedaysworked (g_date_worked);
3841
3842 IF g_debug
3843 THEN
3844 hr_utility.TRACE ( 'date_worked:'
3845 || TO_CHAR (g_date_worked, 'DD/MON/YY')
3846 );
3847 hr_utility.TRACE ( 'consec_days_worked:'
3848 || TO_CHAR (consec_days_worked)
3849 );
3850 END IF;
3851 END IF;
3852
3853 IF g_debug
3854 THEN
3855 hr_utility.TRACE ('l_days_worked :' || l_days_worked);
3856 END IF;
3857
3858 --If Timecard hours are all Vacation , i.e.,if a week of just vacation
3859 --,then do not calculate for an overtime amount
3860 IF l_abs_count = l_days_worked
3861 THEN
3862 IF g_debug
3863 THEN
3864 hr_utility.set_location (l_proc, 40);
3865 END IF;
3866
3867 CLOSE reg_hrs_cur;
3868
3869 RETURN 0;
3870 END IF;
3871
3872 IF g_debug
3873 THEN
3874 hr_utility.set_location (l_proc, 50);
3875 END IF;
3876
3877 CLOSE reg_hrs_cur;
3878
3879 RETURN 1;
3880 END IF;
3881
3882 --Populate plsql table g_parent_to_re_explode with the parent_id of the
3883 --REG hrs detail row(the DET row on which ABS hrs are being adjusted)
3884 --All the REG hrs rows on which the absence hrs are adjusted
3885 --will be re-exploded in order to determine the Shift Premiums to be
3886 --paid with diff hours types that changed on previous days of the week
3887 --due to this ABS adjustment.
3888 l_next_parent_index := g_parent_to_re_explode.COUNT + 1;
3889 g_parent_to_re_explode (l_next_parent_index).parent_id :=
3890 l_reg_hrs_cur.parent_id;
3891
3892 IF g_debug
3893 THEN
3894 hr_utility.set_location (l_proc, 51);
3895 END IF;
3896
3897 l_hours_to_adjust := l_reg_hrs_cur.hours;
3898
3899 IF g_debug
3900 THEN
3901 hr_utility.TRACE ('l_hours_to_adjust :' || l_hours_to_adjust);
3902 hr_utility.TRACE ('l_hours_left :' || l_hours_left);
3903 END IF;
3904
3905 IF l_hours_to_adjust <> 0
3906 THEN
3907 IF g_debug
3908 THEN
3909 hr_utility.set_location (l_proc, 55);
3910 END IF;
3911
3912 IF l_hours_to_adjust <= l_hours_left
3913 THEN
3914 IF g_debug
3915 THEN
3916 hr_utility.set_location (l_proc, 60);
3917 END IF;
3918
3919 l_hours_left := l_hours_left - l_hours_to_adjust;
3920 l_hours_to_pay := l_hours_to_adjust;
3921 l_hours_to_adjust := 0;
3922
3923 IF g_debug
3924 THEN
3925 hr_utility.TRACE ('l_hours_left :' || l_hours_left);
3926 hr_utility.TRACE ('l_hours_to_pay :' || l_hours_to_pay
3927 );
3928 hr_utility.TRACE ( 'l_hours_to_adjust :'
3929 || l_hours_to_adjust
3930 );
3931 END IF;
3932 ELSE
3933 IF g_debug
3934 THEN
3935 hr_utility.set_location (l_proc, 70);
3936 END IF;
3937
3938 l_hours_to_adjust := l_hours_to_adjust - l_hours_left;
3939 l_hours_to_pay := l_hours_left;
3940 l_hours_left := 0;
3941
3942 IF g_debug
3943 THEN
3944 hr_utility.TRACE ('l_hours_left :' || l_hours_left);
3945 hr_utility.TRACE ('l_hours_to_pay :' || l_hours_to_pay
3946 );
3947 hr_utility.TRACE ( 'l_hours_to_adjust :'
3948 || l_hours_to_adjust
3949 );
3950 END IF;
3951 END IF;
3952
3953 IF g_debug
3954 THEN
3955 hr_utility.set_location (l_proc, 80);
3956 hr_utility.TRACE ( 'l_reg_hrs_cur.parent_id :'
3957 || l_reg_hrs_cur.parent_id
3958 );
3959 hr_utility.TRACE ('c_tim_id :' || c_tim_id);
3960 hr_utility.TRACE ( 'l_reg_hrs_cur.seqno :'
3961 || l_reg_hrs_cur.seqno
3962 );
3963 hr_utility.TRACE ( 'l_reg_hrs_cur.hours :'
3964 || l_reg_hrs_cur.hours
3965 );
3966 hr_utility.TRACE ( 'l_reg_hrs_cur.date_worked :'
3967 || TO_CHAR (l_reg_hrs_cur.date_worked,
3968 'DD-MON-YYYY HH24:MI:SS'
3969 )
3970 );
3971 hr_utility.TRACE ( 'l_reg_hrs_cur.time_in :'
3972 || TO_CHAR (l_reg_hrs_cur.time_in,
3973 'DD-MON-YYYY HH24:MI:SS'
3974 )
3975 );
3976 hr_utility.TRACE ( 'l_reg_hrs_cur.time_out :'
3977 || TO_CHAR (l_reg_hrs_cur.time_out,
3978 'DD-MON-YYYY HH24:MI:SS'
3979 )
3980 );
3981 hr_utility.TRACE ( 'l_reg_hrs_cur.earn_pol_id :'
3982 || l_reg_hrs_cur.earn_pol_id
3983 );
3984 hr_utility.TRACE ( 'l_reg_hrs_cur.assignment_id :'
3985 || l_reg_hrs_cur.assignment_id
3986 );
3987 hr_utility.set_location (l_proc, 81);
3988 END IF;
3989
3990 -- Get the Policies and Premiums for current day - on which
3991 -- the REG hrs were found - where the absence hrs
3992 -- will be adjusted.
3993 hxt_util.get_policies (l_reg_hrs_cur.earn_pol_id,
3994 l_reg_hrs_cur.assignment_id,
3995 l_reg_hrs_cur.date_worked,
3996 l_work_plan,
3997 l_rotation_plan,
3998 l_egp_id,
3999 l_hdp_id,
4000 l_sdp_id,
4001 l_egp_type,
4002 l_egt_id,
4003 l_pep_id,
4004 l_pip_id,
4005 l_hcl_id,
4006 l_min_tcard_intvl,
4007 l_round_up,
4008 l_hcl_elt_id,
4009 l_error
4010 );
4011
4012 -- Check if error encountered
4013 IF g_debug
4014 THEN
4015 hr_utility.set_location (l_proc, 82);
4016 hr_utility.TRACE ('l_egp_id :' || l_egp_id);
4017 END IF;
4018
4019 IF l_error <> 0
4020 THEN
4021 IF g_debug
4022 THEN
4023 hr_utility.set_location (l_proc, 83);
4024 END IF;
4025
4026 RETURN 3;
4027 END IF;
4028
4029 -- Check if person assigned work or rotation plan
4030 IF g_debug
4031 THEN
4032 hr_utility.TRACE ('l_work_plan :' || l_work_plan);
4033 hr_utility.TRACE ('l_rotation_plan :' || l_rotation_plan);
4034 END IF;
4035
4036 IF (l_work_plan IS NOT NULL) OR (l_rotation_plan IS NOT NULL)
4037 THEN
4038 IF g_debug
4039 THEN
4040 hr_utility.set_location (l_proc, 84);
4041 END IF;
4042
4043 --Get premiums for shift
4044 hxt_util.get_shift_info (l_reg_hrs_cur.date_worked,
4045 l_work_plan,
4046 l_rotation_plan,
4047 l_osp_id,
4048 l_sdf_id,
4049 l_standard_start,
4050 l_standard_stop,
4051 l_early_start,
4052 l_late_stop,
4053 l_shift_hours --SIR212
4054 ,
4055 l_error
4056 );
4057
4058 -- Check if error encountered
4059 IF g_debug
4060 THEN
4061 hr_utility.set_location (l_proc, 85);
4062 END IF;
4063
4064 IF l_error <> 0
4065 THEN
4066 IF g_debug
4067 THEN
4068 hr_utility.set_location (l_proc, 86);
4069 END IF;
4070
4071 RETURN 3;
4072 END IF;
4073
4074 IF g_debug
4075 THEN
4076 hr_utility.set_location (l_proc, 87);
4077 END IF;
4078 END IF;
4079
4080 IF g_debug
4081 THEN
4082 hr_utility.set_location (l_proc, 88);
4083 hr_utility.TRACE ( 'l_reg_hrs_cur.parent_id:'
4084 || l_reg_hrs_cur.parent_id
4085 );
4086 END IF;
4087
4088 -- Clear up all the details for reg_hrs_cur record as it will be
4089 -- re exploded.
4090 OPEN clear_reg_detail_rec (l_reg_hrs_cur.parent_id);
4091
4092 FETCH clear_reg_detail_rec
4093 INTO l_del_rowid;
4094
4095 CLOSE clear_reg_detail_rec;
4096
4097 DELETE FROM hxt_det_hours_worked
4098 WHERE ROWID = l_del_rowid;
4099
4100 IF g_debug
4101 THEN
4102 hr_utility.set_location (l_proc, 89);
4103 hr_utility.TRACE ( 'l_reg_hrs_cur.time_in :'
4104 || TO_CHAR (l_reg_hrs_cur.time_in,
4105 'DD-MON-YYYY HH24:MI:SS'
4106 )
4107 );
4108 hr_utility.TRACE ( 'l_reg_hrs_cur.time_out :'
4109 || TO_CHAR (l_reg_hrs_cur.time_out,
4110 'DD-MON-YYYY HH24:MI:SS'
4111 )
4112 );
4113 hr_utility.TRACE ('l_hours_to_adjust:' || l_hours_to_adjust);
4114 hr_utility.TRACE
4115 ( 'l_reg_hrs_cur.time_in + (l_hours_to_adjust/24):'
4116 || TO_CHAR ( l_reg_hrs_cur.time_in
4117 + (l_hours_to_adjust / 24),
4118 'DD-MON-YYYY HH24:MI:SS'
4119 )
4120 );
4121 END IF;
4122
4123 -- Re explode the details for the REG hours left after
4124 -- determining hours required for ABS adjustments.
4125 -- Generate details
4126 l_status :=
4127 hxt_time_summary.generate_details
4128 (l_reg_hrs_cur.earn_pol_id -- earning policy
4129 ,
4130 l_egp_type -- earning policy type
4131 ,
4132 l_egt_id,
4133 l_sdp_id -- shift diff policy
4134 ,
4135 l_hdp_id,
4136 l_hcl_id,
4137 l_pep_id,
4138 l_pip_id,
4139 l_sdf_id -- override shift diff premium id
4140 ,
4141 l_osp_id -- off-shift premium id
4142 ,
4143 l_standard_start,
4144 l_standard_stop,
4145 l_early_start,
4146 l_late_stop,
4147 l_hol_yn,
4148 g_person_id,
4149 'TIMC' -- calling source
4150 ,
4151 l_reg_hrs_cur.parent_id,
4152 l_reg_hrs_cur.tim_id,
4153 l_reg_hrs_cur.date_worked,
4154 l_reg_hrs_cur.assignment_id,
4155 l_hours_to_adjust -- i.e., the REG hours
4156 ,
4157 l_reg_hrs_cur.time_in,
4158 ( l_reg_hrs_cur.time_in
4159 + (l_hours_to_adjust / 24)
4160 ),
4161 l_reg_hrs_cur.element_type_id,
4162 l_reg_hrs_cur.fcl_earn_reason_code,
4163 l_reg_hrs_cur.ffv_cost_center_id,
4164 NULL,
4165 l_reg_hrs_cur.tas_id,
4166 l_reg_hrs_cur.location_id,
4167 l_reg_hrs_cur.sht_id,
4168 l_reg_hrs_cur.hrw_comment,
4169 l_reg_hrs_cur.ffv_rate_code_id,
4170 NULL, -- l_reg_hrs_cur.rate_multiple,
4171 NULL, -- l_reg_hrs_cur.hourly_rate,
4172 NULL, -- l_reg_hrs_cur.amount,
4173 l_reg_hrs_cur.fcl_tax_rule_code,
4174 l_reg_hrs_cur.separate_check_flag,
4175 l_reg_hrs_cur.seqno,
4176 l_reg_hrs_cur.created_by,
4177 l_reg_hrs_cur.creation_date,
4178 l_reg_hrs_cur.last_updated_by,
4179 l_reg_hrs_cur.last_update_date,
4180 l_reg_hrs_cur.last_update_login,
4181 g_period_start_date,
4182 NULL -- rowid
4183 ,
4184 l_reg_hrs_cur.effective_start_date,
4185 l_reg_hrs_cur.effective_end_date,
4186 l_reg_hrs_cur.project_id,
4187 l_reg_hrs_cur.job_id,
4188 NULL,
4189 NULL,
4190 NULL,
4191 'CORRECTION',
4192 'N',
4193 l_reg_hrs_cur.state_name,
4194 l_reg_hrs_cur.county_name,
4195 l_reg_hrs_cur.city_name,
4196 l_reg_hrs_cur.zip_code
4197 );
4198
4199 IF g_debug
4200 THEN
4201 hr_utility.set_location (l_proc, 90);
4202 END IF;
4203
4204 IF l_status <> 0
4205 THEN
4206 IF g_debug
4207 THEN
4208 hr_utility.set_location (l_proc, 91);
4209 END IF;
4210
4211 RETURN 3;
4212 END IF;
4213
4214 IF g_debug
4215 THEN
4216 hr_utility.set_location (l_proc, 92);
4217 END IF;
4218
4219 -- Now generate the detail records for c_element_type_id
4220 -- i.e., the OT or the DT that gets adjusted on
4221 -- reg_hrs_cur.date_worked
4222 IF l_reg_hrs_cur.time_in IS NOT NULL
4223 THEN
4224 IF g_debug
4225 THEN
4226 hr_utility.set_location (l_proc, 101);
4227 END IF;
4228
4229 l_segment_start_time :=
4230 l_reg_hrs_cur.time_in
4231 + (l_hours_to_adjust / 24);
4232 l_segment_stop_time :=
4233 l_segment_start_time
4234 + (l_hours_to_pay / 24);
4235 ELSE -- time_in is null, i.e., time entered in hours
4236 IF g_debug
4237 THEN
4238 hr_utility.set_location (l_proc, 102);
4239 END IF;
4240
4241 l_segment_start_time := NULL;
4242 l_segment_stop_time := NULL;
4243 END IF;
4244
4245 IF g_debug
4246 THEN
4247 hr_utility.TRACE ( 'l_segment_start_time :'
4248 || TO_CHAR (l_segment_start_time,
4249 'DD-MON-YYYY HH24:MI:SS'
4250 )
4251 );
4252 hr_utility.TRACE ( 'l_segment_stop_time :'
4253 || TO_CHAR (l_segment_stop_time,
4254 'DD-MON-YYYY HH24:MI:SS'
4255 )
4256 );
4257 END IF;
4258
4259 --BEGIN SIR 491
4260 IF g_debug
4261 THEN
4262 hr_utility.TRACE ( 'l_reg_hrs_cur.parent_id:'
4263 || l_reg_hrs_cur.parent_id
4264 );
4265 hr_utility.TRACE ('c_tim_id :' || c_tim_id);
4266 hr_utility.TRACE ( 'c_element_type_id :'
4267 || c_element_type_id
4268 );
4269 hr_utility.set_location (l_proc, 103);
4270 END IF;
4271
4272 l_status :=
4273 hxt_time_summary.generate_details
4274 (l_reg_hrs_cur.earn_pol_id -- earning policy
4275 ,
4276 l_egp_type -- earning policy type
4277 ,
4278 l_egt_id,
4279 l_sdp_id -- shift diff policy
4280 ,
4281 l_hdp_id,
4282 l_hcl_id,
4283 l_pep_id,
4284 l_pip_id,
4285 l_sdf_id -- override shift diff premium id
4286 ,
4287 l_osp_id -- off-shift premium id
4288 ,
4289 l_standard_start,
4290 l_standard_stop,
4291 l_early_start,
4292 l_late_stop,
4293 l_hol_yn,
4294 g_person_id,
4295 'TIMC' -- calling source
4296 ,
4297 l_reg_hrs_cur.parent_id,
4298 l_reg_hrs_cur.tim_id,
4299 l_reg_hrs_cur.date_worked,
4300 l_reg_hrs_cur.assignment_id,
4301 l_hours_to_pay,
4302 l_segment_start_time,
4303 l_segment_stop_time,
4304 c_element_type_id -- i.e., OT or DT
4305 ,
4306 l_reg_hrs_cur.fcl_earn_reason_code,
4307 l_reg_hrs_cur.ffv_cost_center_id,
4308 NULL,
4309 l_reg_hrs_cur.tas_id,
4310 l_reg_hrs_cur.location_id,
4311 l_reg_hrs_cur.sht_id,
4312 l_reg_hrs_cur.hrw_comment,
4313 l_reg_hrs_cur.ffv_rate_code_id,
4314 NULL, -- l_reg_hrs_cur.rate_multiple,
4315 NULL, -- l_reg_hrs_cur.hourly_rate,
4316 NULL, -- l_reg_hrs_cur.amount,
4317 l_reg_hrs_cur.fcl_tax_rule_code,
4318 l_reg_hrs_cur.separate_check_flag,
4319 l_reg_hrs_cur.seqno,
4320 l_reg_hrs_cur.created_by,
4321 l_reg_hrs_cur.creation_date,
4322 l_reg_hrs_cur.last_updated_by,
4323 l_reg_hrs_cur.last_update_date,
4324 l_reg_hrs_cur.last_update_login,
4325 g_period_start_date,
4326 NULL -- rowid
4327 ,
4328 l_reg_hrs_cur.effective_start_date,
4329 l_reg_hrs_cur.effective_end_date,
4330 l_reg_hrs_cur.project_id,
4331 l_reg_hrs_cur.job_id,
4332 NULL,
4333 NULL,
4334 NULL,
4335 'CORRECTION',
4336 'N',
4337 l_reg_hrs_cur.state_name,
4338 l_reg_hrs_cur.county_name,
4339 l_reg_hrs_cur.city_name,
4340 l_reg_hrs_cur.zip_code
4341 );
4342
4343 IF g_debug
4344 THEN
4345 hr_utility.set_location (l_proc, 104);
4346 END IF;
4347
4348 IF l_status <> 0
4349 THEN
4350 IF g_debug
4351 THEN
4352 hr_utility.set_location (l_proc, 105);
4353 END IF;
4354
4355 RETURN 3;
4356 END IF;
4357
4358 IF g_debug
4359 THEN
4360 hr_utility.set_location (l_proc, 106);
4361 END IF;
4362 END IF; -- end if l_hours_to_adjust <> 0;
4363
4364 IF g_debug
4365 THEN
4366 hr_utility.set_location (l_proc, 107);
4367 END IF;
4368 END LOOP; -- While l_hours_left > 0
4369
4370 -- After adjusting all the absence hrs, populate the details
4371 --( i.e. REG, OT and DT hours) of all the adjusted days in
4372 -- g_re_explode_detail plsql table.
4373 -- Then delete the details(i.e all the rows including Reg,OT,
4374 -- DT and all the premiums) of all the adjusted days and
4375 -- re-explode them based on the plsql data in order to pay
4376 -- the Shift Premiums, associated with the REG, OT and DT
4377 -- hours, correctly.
4378 IF g_debug
4379 THEN
4380 hr_utility.TRACE ('FYI');
4381 END IF;
4382
4383 i := g_parent_to_re_explode.FIRST;
4384
4385 LOOP
4386 EXIT WHEN NOT g_parent_to_re_explode.EXISTS (i);
4387
4388 IF g_debug
4389 THEN
4390 hr_utility.set_location (l_proc, 107.1);
4391 hr_utility.TRACE ('i:' || i);
4392 hr_utility.TRACE ( 'g_parent_to_re_explode(i).parent_id:'
4393 || g_parent_to_re_explode (i).parent_id
4394 );
4395 hr_utility.set_location (l_proc, 107.2);
4396 END IF;
4397
4398 i := g_parent_to_re_explode.NEXT (i);
4399 END LOOP;
4400
4401 IF g_debug
4402 THEN
4403 hr_utility.TRACE ('END FYI');
4404 hr_utility.set_location (l_proc, 107.3);
4405 hr_utility.TRACE ( 'g_parent_to_re_explode.count:'
4406 || g_parent_to_re_explode.COUNT
4407 );
4408 END IF;
4409
4410 j := g_parent_to_re_explode.FIRST;
4411
4412 LOOP
4413 EXIT WHEN NOT g_parent_to_re_explode.EXISTS (j);
4414
4415 IF g_debug
4416 THEN
4417 hr_utility.set_location (l_proc, 107.4);
4418 hr_utility.TRACE ('j:' || j);
4419 hr_utility.TRACE ( 'g_parent_to_re_explode(j).parent_id:'
4420 || g_parent_to_re_explode (j).parent_id
4421 );
4422 END IF;
4423
4424 IF g_re_explode_detail.COUNT > 0
4425 THEN
4426 IF g_debug
4427 THEN
4428 hr_utility.set_location (l_proc, 107.5);
4429 END IF;
4430
4431 l_delete_det := g_re_explode_detail.FIRST;
4432
4433 LOOP
4434 EXIT WHEN NOT g_re_explode_detail.EXISTS (l_delete_det);
4435 g_re_explode_detail (l_delete_det).earn_pol_id := NULL;
4436 g_re_explode_detail (l_delete_det).parent_id := NULL;
4437 g_re_explode_detail (l_delete_det).tim_id := NULL;
4438 g_re_explode_detail (l_delete_det).date_worked := NULL;
4439 g_re_explode_detail (l_delete_det).assignment_id := NULL;
4440 g_re_explode_detail (l_delete_det).hours := NULL;
4441 g_re_explode_detail (l_delete_det).time_in := NULL;
4442 g_re_explode_detail (l_delete_det).time_out := NULL;
4443 g_re_explode_detail (l_delete_det).element_type_id := NULL;
4444 g_re_explode_detail (l_delete_det).fcl_earn_reason_code :=
4445 NULL;
4446 g_re_explode_detail (l_delete_det).ffv_cost_center_id :=
4447 NULL;
4448 g_re_explode_detail (l_delete_det).tas_id := NULL;
4449 g_re_explode_detail (l_delete_det).location_id := NULL;
4450 g_re_explode_detail (l_delete_det).sht_id := NULL;
4451 g_re_explode_detail (l_delete_det).hrw_comment := NULL;
4452 g_re_explode_detail (l_delete_det).ffv_rate_code_id := NULL;
4453 g_re_explode_detail (l_delete_det).rate_multiple := NULL;
4454 g_re_explode_detail (l_delete_det).hourly_rate := NULL;
4455 g_re_explode_detail (l_delete_det).amount := NULL;
4456 g_re_explode_detail (l_delete_det).fcl_tax_rule_code :=
4457 NULL;
4458 g_re_explode_detail (l_delete_det).separate_check_flag :=
4459 NULL;
4460 g_re_explode_detail (l_delete_det).seqno := NULL;
4461 g_re_explode_detail (l_delete_det).created_by := NULL;
4462 g_re_explode_detail (l_delete_det).creation_date := NULL;
4463 g_re_explode_detail (l_delete_det).last_updated_by := NULL;
4464 g_re_explode_detail (l_delete_det).last_update_date := NULL;
4465 g_re_explode_detail (l_delete_det).last_update_login :=
4466 NULL;
4467 g_re_explode_detail (l_delete_det).effective_start_date :=
4468 NULL;
4469 g_re_explode_detail (l_delete_det).effective_end_date :=
4470 NULL;
4471 g_re_explode_detail (l_delete_det).project_id := NULL;
4472 g_re_explode_detail (l_delete_det).job_id := NULL;
4473 g_re_explode_detail (l_delete_det).state_name := NULL;
4474 g_re_explode_detail (l_delete_det).county_name := NULL;
4475 g_re_explode_detail (l_delete_det).city_name := NULL;
4476 g_re_explode_detail (l_delete_det).zip_code := NULL;
4477 l_delete_det := g_re_explode_detail.NEXT (l_delete_det);
4478 END LOOP;
4479
4480 IF g_debug
4481 THEN
4482 hr_utility.TRACE
4483 ('Deleting g_re_explode_detail PL/SQL table');
4484 END IF;
4485
4486 g_re_explode_detail.DELETE;
4487 END IF;
4488
4489 IF g_debug
4490 THEN
4491 hr_utility.set_location (l_proc, 107.6);
4492 END IF;
4493
4494 -- Populate the g_re_explode_detail plsql table with the details of
4495 -- the rows that need to be re-exploded
4496 OPEN re_explode_details (g_parent_to_re_explode (j).parent_id);
4497
4498 IF g_debug
4499 THEN
4500 hr_utility.set_location (l_proc, 107.61);
4501 END IF;
4502
4503 LOOP
4504 FETCH re_explode_details
4505 INTO l_re_explode_details;
4506
4507 EXIT WHEN re_explode_details%NOTFOUND;
4508
4509 IF g_debug
4510 THEN
4511 hr_utility.set_location (l_proc, 108);
4512 END IF;
4513
4514 l_next_index := g_re_explode_detail.COUNT + 1;
4515
4516 IF g_debug
4517 THEN
4518 hr_utility.TRACE ('l_next_index:' || l_next_index);
4519 END IF;
4520
4521 g_re_explode_detail (l_next_index).earn_pol_id :=
4522 l_re_explode_details.earn_pol_id;
4523 g_re_explode_detail (l_next_index).parent_id :=
4524 l_re_explode_details.parent_id;
4525 g_re_explode_detail (l_next_index).tim_id :=
4526 l_re_explode_details.tim_id;
4527 g_re_explode_detail (l_next_index).date_worked :=
4528 l_re_explode_details.date_worked;
4529 g_re_explode_detail (l_next_index).assignment_id :=
4530 l_re_explode_details.assignment_id;
4531 g_re_explode_detail (l_next_index).hours :=
4532 l_re_explode_details.hours;
4533 g_re_explode_detail (l_next_index).time_in :=
4534 l_re_explode_details.time_in;
4535 g_re_explode_detail (l_next_index).time_out :=
4536 l_re_explode_details.time_out;
4537 g_re_explode_detail (l_next_index).element_type_id :=
4538 l_re_explode_details.element_type_id;
4539 g_re_explode_detail (l_next_index).fcl_earn_reason_code :=
4540 l_re_explode_details.fcl_earn_reason_code;
4541 g_re_explode_detail (l_next_index).ffv_cost_center_id :=
4542 l_re_explode_details.ffv_cost_center_id;
4543 g_re_explode_detail (l_next_index).tas_id :=
4544 l_re_explode_details.tas_id;
4545 g_re_explode_detail (l_next_index).location_id :=
4546 l_re_explode_details.location_id;
4547 g_re_explode_detail (l_next_index).sht_id :=
4548 l_re_explode_details.sht_id;
4549 g_re_explode_detail (l_next_index).hrw_comment :=
4550 l_re_explode_details.hrw_comment;
4551 g_re_explode_detail (l_next_index).ffv_rate_code_id :=
4552 l_re_explode_details.ffv_rate_code_id;
4553 g_re_explode_detail (l_next_index).rate_multiple :=
4554 l_re_explode_details.rate_multiple;
4555 g_re_explode_detail (l_next_index).hourly_rate :=
4556 l_re_explode_details.hourly_rate;
4557 g_re_explode_detail (l_next_index).amount :=
4558 l_re_explode_details.amount;
4559 g_re_explode_detail (l_next_index).fcl_tax_rule_code :=
4560 l_re_explode_details.fcl_tax_rule_code;
4561 g_re_explode_detail (l_next_index).separate_check_flag :=
4562 l_re_explode_details.separate_check_flag;
4563 g_re_explode_detail (l_next_index).seqno :=
4564 l_re_explode_details.seqno;
4565 g_re_explode_detail (l_next_index).created_by :=
4566 l_re_explode_details.created_by;
4567 g_re_explode_detail (l_next_index).creation_date :=
4568 l_re_explode_details.creation_date;
4569 g_re_explode_detail (l_next_index).last_updated_by :=
4570 l_re_explode_details.last_updated_by;
4571 g_re_explode_detail (l_next_index).last_update_date :=
4572 l_re_explode_details.last_update_date;
4573 g_re_explode_detail (l_next_index).last_update_login :=
4574 l_re_explode_details.last_update_login;
4575 g_re_explode_detail (l_next_index).effective_start_date :=
4576 l_re_explode_details.effective_start_date;
4577 g_re_explode_detail (l_next_index).effective_end_date :=
4578 l_re_explode_details.effective_end_date;
4579 g_re_explode_detail (l_next_index).project_id :=
4580 l_re_explode_details.project_id;
4581 g_re_explode_detail (l_next_index).job_id :=
4582 l_re_explode_details.job_id;
4583 g_re_explode_detail (l_next_index).state_name :=
4584 l_re_explode_details.state_name;
4585 g_re_explode_detail (l_next_index).county_name :=
4586 l_re_explode_details.county_name;
4587 g_re_explode_detail (l_next_index).city_name :=
4588 l_re_explode_details.city_name;
4589 g_re_explode_detail (l_next_index).zip_code :=
4590 l_re_explode_details.zip_code;
4591 END LOOP; -- end populating g_re_explode_detail plsql table
4592
4593 IF g_debug
4594 THEN
4595 hr_utility.set_location (l_proc, 109);
4596 END IF;
4597
4598 CLOSE re_explode_details;
4599
4600 IF g_debug
4601 THEN
4602 hr_utility.set_location (l_proc, 109.1);
4603 hr_utility.TRACE ('parent_id:' || l_reg_hrs_cur.parent_id);
4604 END IF;
4605
4606 -- Clear all the detail records for l_reg_hrs_cur.parent_id
4607 DELETE FROM hxt_det_hours_worked
4608 WHERE parent_id = g_parent_to_re_explode (j).parent_id;
4609
4610 IF g_debug
4611 THEN
4612 hr_utility.TRACE ('FYI');
4613 END IF;
4614
4615 k := g_re_explode_detail.FIRST;
4616
4617 LOOP
4618 EXIT WHEN NOT g_re_explode_detail.EXISTS (k);
4619
4620 IF g_debug
4621 THEN
4622 hr_utility.set_location (l_proc, 109.2);
4623 hr_utility.TRACE ('k:' || k);
4624 hr_utility.TRACE ( 'g_re_explode_detail(k).earn_pol_id:'
4625 || g_re_explode_detail (k).earn_pol_id
4626 );
4627 hr_utility.TRACE ( 'g_re_explode_detail(k).parent_id:'
4628 || g_re_explode_detail (k).parent_id
4629 );
4630 hr_utility.TRACE ( 'g_re_explode_detail(k).tim_id:'
4631 || g_re_explode_detail (k).tim_id
4632 );
4633 hr_utility.TRACE ( 'g_re_explode_detail(k).date_worked:'
4634 || g_re_explode_detail (k).date_worked
4635 );
4636 hr_utility.TRACE ( 'g_re_explode_detail(k).assignment_id:'
4637 || g_re_explode_detail (k).assignment_id
4638 );
4639 hr_utility.TRACE ( 'g_re_explode_detail(k).hours:'
4640 || g_re_explode_detail (k).hours
4641 );
4642 hr_utility.TRACE ( 'g_re_explode_detail(k).time_in:'
4643 || TO_CHAR
4644 (g_re_explode_detail (k).time_in,
4645 'DD-MON-YYYY HH24:MI:SS'
4646 )
4647 );
4648 hr_utility.TRACE ( 'g_re_explode_detail(k).time_out:'
4649 || TO_CHAR
4650 (g_re_explode_detail (k).time_out,
4651 'DD-MON-YYYY HH24:MI:SS'
4652 )
4653 );
4654 hr_utility.TRACE
4655 ( 'g_re_explode_detail(k).element_type_id:'
4656 || g_re_explode_detail (k).element_type_id
4657 );
4658 hr_utility.TRACE
4659 ( 'g_re_explode_detail(k).fcl_earn_reason_code:'
4660 || g_re_explode_detail (k).fcl_earn_reason_code
4661 );
4662 hr_utility.TRACE
4663 ( 'g_re_explode_detail(k).ffv_cost_center_id:'
4664 || g_re_explode_detail (k).ffv_cost_center_id
4665 );
4666 hr_utility.TRACE ( 'g_re_explode_detail(k).tas_id:'
4667 || g_re_explode_detail (k).tas_id
4668 );
4669 hr_utility.TRACE ( 'g_re_explode_detail(k).location_id:'
4670 || g_re_explode_detail (k).location_id
4671 );
4672 hr_utility.TRACE ( 'g_re_explode_detail(k).sht_id:'
4673 || g_re_explode_detail (k).sht_id
4674 );
4675 hr_utility.TRACE ( 'g_re_explode_detail(k).hrw_comment:'
4676 || g_re_explode_detail (k).hrw_comment
4677 );
4678 hr_utility.TRACE
4679 ( 'g_re_explode_detail(k).ffv_rate_code_id:'
4680 || g_re_explode_detail (k).ffv_rate_code_id
4681 );
4682 hr_utility.TRACE ( 'g_re_explode_detail(k).rate_multiple:'
4683 || g_re_explode_detail (k).rate_multiple
4684 );
4685 hr_utility.TRACE ( 'g_re_explode_detail(k).hourly_rate:'
4686 || g_re_explode_detail (k).hourly_rate
4687 );
4688 hr_utility.TRACE ( 'g_re_explode_detail(k).amount:'
4689 || g_re_explode_detail (k).amount
4690 );
4691 hr_utility.TRACE
4692 ( 'g_re_explode_detail(k).fcl_tax_rule_code:'
4693 || g_re_explode_detail (k).fcl_tax_rule_code
4694 );
4695 hr_utility.TRACE
4696 ( 'g_re_explode_detail(k).separate_check_flag:'
4697 || g_re_explode_detail (k).separate_check_flag
4698 );
4699 hr_utility.TRACE ( 'g_re_explode_detail(k).seqno:'
4700 || g_re_explode_detail (k).seqno
4701 );
4702 hr_utility.TRACE ( 'g_re_explode_detail(k).created_by:'
4703 || g_re_explode_detail (k).created_by
4704 );
4705 hr_utility.TRACE ( 'g_re_explode_detail(k).creation_date:'
4706 || g_re_explode_detail (k).creation_date
4707 );
4708 hr_utility.TRACE
4709 ( 'g_re_explode_detail(k).last_updated_by:'
4710 || g_re_explode_detail (k).last_updated_by
4711 );
4712 hr_utility.TRACE
4713 ( 'g_re_explode_detail(k).last_update_date:'
4714 || g_re_explode_detail (k).last_update_date
4715 );
4716 hr_utility.TRACE
4717 ( 'g_re_explode_detail(k).last_update_login:'
4718 || g_re_explode_detail (k).last_update_login
4719 );
4720 hr_utility.TRACE
4721 ( 'g_re_explode_detail(k).effective_start_date:'
4722 || g_re_explode_detail (k).effective_start_date
4723 );
4724 hr_utility.TRACE
4725 ( 'g_re_explode_detail(k).effective_end_date:'
4726 || g_re_explode_detail (k).effective_end_date
4727 );
4728 hr_utility.TRACE ( 'g_re_explode_detail(k).project_id:'
4729 || g_re_explode_detail (k).project_id
4730 );
4731 hr_utility.TRACE ( 'g_re_explode_detail(k).job_id:'
4732 || g_re_explode_detail (k).job_id
4733 );
4734 hr_utility.set_location (l_proc, 109.22);
4735 END IF;
4736
4737 k := g_re_explode_detail.NEXT (k);
4738 END LOOP;
4739
4740 IF g_debug
4741 THEN
4742 hr_utility.TRACE ('END FYI');
4743 hr_utility.set_location (l_proc, 109.23);
4744 hr_utility.TRACE ( 'g_re_explode_detail.count:'
4745 || g_re_explode_detail.COUNT
4746 );
4747 END IF;
4748
4749 -- Re-explode the detail records
4750 l_re_explode := g_re_explode_detail.FIRST;
4751
4752 LOOP
4753 EXIT WHEN NOT g_re_explode_detail.EXISTS (l_re_explode);
4754
4755 IF g_debug
4756 THEN
4757 hr_utility.set_location (l_proc, 109.3);
4758 hr_utility.TRACE ('l_re_explode:' || l_re_explode);
4759 hr_utility.TRACE
4760 ( 'g_re_explode_detail(l_re_explode).earn_pol_id:'
4761 || g_re_explode_detail (l_re_explode).earn_pol_id
4762 );
4763 hr_utility.TRACE
4764 ( 'g_re_explode_detail(l_re_explode).parent_id:'
4765 || g_re_explode_detail (l_re_explode).parent_id
4766 );
4767 hr_utility.TRACE
4768 ( 'g_re_explode_detail(l_re_explode).tim_id:'
4769 || g_re_explode_detail (l_re_explode).tim_id
4770 );
4771 hr_utility.TRACE
4772 ( 'g_re_explode_detail(l_re_explode).date_worked:'
4773 || g_re_explode_detail (l_re_explode).date_worked
4774 );
4775 hr_utility.TRACE
4776 ( 'g_re_explode_detail(l_re_explode).assignment_id:'
4777 || g_re_explode_detail (l_re_explode).assignment_id
4778 );
4779 hr_utility.TRACE
4780 ( 'g_re_explode_detail(l_re_explode).hours:'
4781 || g_re_explode_detail (l_re_explode).hours
4782 );
4783 hr_utility.TRACE
4784 ( 'g_re_explode_detail(l_re_explode).time_in:'
4785 || TO_CHAR
4786 (g_re_explode_detail (l_re_explode).time_in,
4787 'DD-MON-YYYY HH24:MI:SS'
4788 )
4789 );
4790 hr_utility.TRACE
4791 ( 'g_re_explode_detail(l_re_explode).time_out:'
4792 || TO_CHAR
4793 (g_re_explode_detail (l_re_explode).time_out,
4794 'DD-MON-YYYY HH24:MI:SS'
4795 )
4796 );
4797 hr_utility.TRACE
4798 ( 'g_re_explode_detail(l_re_explode).element_type_id:'
4799 || g_re_explode_detail (l_re_explode).element_type_id
4800 );
4801 hr_utility.TRACE
4802 ( 'g_re_explode_detail(l_re_explode).fcl_earn_reason_code:'
4803 || g_re_explode_detail (l_re_explode).fcl_earn_reason_code
4804 );
4805 hr_utility.TRACE
4806 ( 'g_re_explode_detail(l_re_explode).ffv_cost_center_id:'
4807 || g_re_explode_detail (l_re_explode).ffv_cost_center_id
4808 );
4809 hr_utility.TRACE
4810 ( 'g_re_explode_detail(l_re_explode).tas_id:'
4811 || g_re_explode_detail (l_re_explode).tas_id
4812 );
4813 hr_utility.TRACE
4814 ( 'g_re_explode_detail(l_re_explode).location_id:'
4815 || g_re_explode_detail (l_re_explode).location_id
4816 );
4817 hr_utility.TRACE
4818 ( 'g_re_explode_detail(l_re_explode).sht_id:'
4819 || g_re_explode_detail (l_re_explode).sht_id
4820 );
4821 hr_utility.TRACE
4822 ( 'g_re_explode_detail(l_re_explode).hrw_comment:'
4823 || g_re_explode_detail (l_re_explode).hrw_comment
4824 );
4825 hr_utility.TRACE
4826 ( 'g_re_explode_detail(l_re_explode).ffv_rate_code_id:'
4827 || g_re_explode_detail (l_re_explode).ffv_rate_code_id
4828 );
4829 hr_utility.TRACE
4830 ( 'g_re_explode_detail(l_re_explode).rate_multiple:'
4831 || g_re_explode_detail (l_re_explode).rate_multiple
4832 );
4833 hr_utility.TRACE
4834 ( 'g_re_explode_detail(l_re_explode).hourly_rate:'
4835 || g_re_explode_detail (l_re_explode).hourly_rate
4836 );
4837 hr_utility.TRACE
4838 ( 'g_re_explode_detail(l_re_explode).amount:'
4839 || g_re_explode_detail (l_re_explode).amount
4840 );
4841 hr_utility.TRACE
4842 ( 'g_re_explode_detail(l_re_explode).fcl_tax_rule_code:'
4843 || g_re_explode_detail (l_re_explode).fcl_tax_rule_code
4844 );
4845 hr_utility.TRACE
4846 ( 'g_re_explode_detail(l_re_explode).separate_check_flag:'
4847 || g_re_explode_detail (l_re_explode).separate_check_flag
4848 );
4849 hr_utility.TRACE
4850 ( 'g_re_explode_detail(l_re_explode).seqno:'
4851 || g_re_explode_detail (l_re_explode).seqno
4852 );
4853 hr_utility.TRACE
4854 ( 'g_re_explode_detail(l_re_explode).created_by:'
4855 || g_re_explode_detail (l_re_explode).created_by
4856 );
4857 hr_utility.TRACE
4858 ( 'g_re_explode_detail(l_re_explode).creation_date:'
4859 || g_re_explode_detail (l_re_explode).creation_date
4860 );
4861 hr_utility.TRACE
4862 ( 'g_re_explode_detail(l_re_explode).last_updated_by:'
4863 || g_re_explode_detail (l_re_explode).last_updated_by
4864 );
4865 hr_utility.TRACE
4866 ( 'g_re_explode_detail(l_re_explode).last_update_date:'
4867 || g_re_explode_detail (l_re_explode).last_update_date
4868 );
4869 hr_utility.TRACE
4870 ( 'g_re_explode_detail(l_re_explode).last_update_login:'
4871 || g_re_explode_detail (l_re_explode).last_update_login
4872 );
4873 hr_utility.TRACE
4874 ( 'g_re_explode_detail(l_re_explode).effective_start_date:'
4875 || g_re_explode_detail (l_re_explode).effective_start_date
4876 );
4877 hr_utility.TRACE
4878 ( 'g_re_explode_detail(l_re_explode).effective_end_date:'
4879 || g_re_explode_detail (l_re_explode).effective_end_date
4880 );
4881 hr_utility.TRACE
4882 ( 'g_re_explode_detail(l_re_explode).project_id:'
4883 || g_re_explode_detail (l_re_explode).project_id
4884 );
4885 hr_utility.TRACE
4886 ( 'g_re_explode_detail(l_re_explode).job_id:'
4887 || g_re_explode_detail (l_re_explode).job_id
4888 );
4889 END IF;
4890
4891 -- Generate details
4892 l_status :=
4893 hxt_time_summary.generate_details
4894 (g_re_explode_detail (l_re_explode).earn_pol_id
4895 --earning policy
4896 ,
4897 l_egp_type -- earning policy type
4898 ,
4899 l_egt_id,
4900 l_sdp_id -- shift diff policy
4901 ,
4902 l_hdp_id,
4903 l_hcl_id,
4904 l_pep_id,
4905 l_pip_id,
4906 l_sdf_id -- override shift diff premium id
4907 ,
4908 l_osp_id -- off-shift premium id
4909 ,
4910 l_standard_start,
4911 l_standard_stop,
4912 l_early_start,
4913 l_late_stop,
4914 l_hol_yn,
4915 g_person_id,
4916 'TIMC' -- calling source
4917 ,
4918 g_re_explode_detail (l_re_explode).parent_id,
4919 g_re_explode_detail (l_re_explode).tim_id,
4920 g_re_explode_detail (l_re_explode).date_worked,
4921 g_re_explode_detail (l_re_explode).assignment_id,
4922 g_re_explode_detail (l_re_explode).hours,
4923 g_re_explode_detail (l_re_explode).time_in,
4924 g_re_explode_detail (l_re_explode).time_out,
4925 g_re_explode_detail (l_re_explode).element_type_id,
4926 g_re_explode_detail (l_re_explode).fcl_earn_reason_code,
4927 g_re_explode_detail (l_re_explode).ffv_cost_center_id,
4928 NULL,
4929 g_re_explode_detail (l_re_explode).tas_id,
4930 g_re_explode_detail (l_re_explode).location_id,
4931 g_re_explode_detail (l_re_explode).sht_id,
4932 g_re_explode_detail (l_re_explode).hrw_comment,
4933 g_re_explode_detail (l_re_explode).ffv_rate_code_id,
4934 NULL, -- g_re_explode_detail (l_re_explode).rate_multiple,
4935 NULL, -- g_re_explode_detail (l_re_explode).hourly_rate,
4936 NULL, -- g_re_explode_detail (l_re_explode).amount,
4937 g_re_explode_detail (l_re_explode).fcl_tax_rule_code,
4938 g_re_explode_detail (l_re_explode).separate_check_flag,
4939 g_re_explode_detail (l_re_explode).seqno,
4940 g_re_explode_detail (l_re_explode).created_by,
4941 g_re_explode_detail (l_re_explode).creation_date,
4942 g_re_explode_detail (l_re_explode).last_updated_by,
4943 g_re_explode_detail (l_re_explode).last_update_date,
4944 g_re_explode_detail (l_re_explode).last_update_login,
4945 g_period_start_date,
4946 NULL -- rowid
4947 ,
4948 g_re_explode_detail (l_re_explode).effective_start_date,
4949 g_re_explode_detail (l_re_explode).effective_end_date,
4950 g_re_explode_detail (l_re_explode).project_id,
4951 g_re_explode_detail (l_re_explode).job_id,
4952 NULL,
4953 NULL,
4954 NULL,
4955 'CORRECTION',
4956 'N',
4957 g_re_explode_detail (l_re_explode).state_name,
4958 g_re_explode_detail (l_re_explode).county_name,
4959 g_re_explode_detail (l_re_explode).city_name,
4960 g_re_explode_detail (l_re_explode).zip_code
4961 );
4962
4963 IF g_debug
4964 THEN
4965 hr_utility.set_location (l_proc, 109.4);
4966 hr_utility.TRACE ('l_status:' || l_status);
4967 END IF;
4968
4969 IF l_status <> 0
4970 THEN
4971 IF g_debug
4972 THEN
4973 hr_utility.set_location (l_proc, 109.5);
4974 END IF;
4975
4976 RETURN 3;
4977 END IF;
4978
4979 IF g_debug
4980 THEN
4981 hr_utility.set_location (l_proc, 109.6);
4982 END IF;
4983
4984 l_re_explode := g_re_explode_detail.NEXT (l_re_explode);
4985 END LOOP; -- g_re_explode_detail.first .. g_re_explode_detail.last
4986
4987 j := g_parent_to_re_explode.NEXT (j);
4988 END LOOP;
4989
4990 -- g_parent_to_re_explode.first .. g_parent_to_re_explode.last
4991 IF g_debug
4992 THEN
4993 hr_utility.set_location (l_proc, 110);
4994 END IF;
4995
4996 CLOSE reg_hrs_cur;
4997
4998 IF g_debug
4999 THEN
5000 hr_utility.set_location (l_proc, 120);
5001 END IF;
5002
5003 RETURN 0;
5004 END adjust_abs_hrs_on_prev_days;
5005
5006 --
5007 ------------------------------------------------------------------------------
5008 --
5009 -- we have a problem where employees transition over 40 hours late
5010 -- in the week, and the transition takes place as a result of an absence.
5011 -- For example, a person works:
5012 -- M T W T F S
5013 -- 12 12 12 8V
5014 -- explodes as 12 12 12 8V reg
5015 --
5016 -- it should 12 12 8 8V
5017 -- explode as 4OT
5018 --
5019 FUNCTION adjust_for_absence (
5020 a_tim_id NUMBER,
5021 a_ep_id NUMBER,
5022 a_date_worked DATE
5023 )
5024 RETURN NUMBER
5025 IS
5026 CURSOR daily_earn_rules_cur2 (
5027 c_earn_policy NUMBER,
5028 c_date_worked DATE
5029 )
5030 IS
5031 SELECT er.hours, er.element_type_id
5032 FROM hxt_earning_rules er
5033 WHERE er.egr_type = 'DAY'
5034 AND er.egp_id = c_earn_policy
5035 AND c_date_worked BETWEEN er.effective_start_date
5036 AND er.effective_end_date
5037 ORDER BY er.seq_no;
5038
5039 CURSOR weekly_earn_rules_cur2 (
5040 c_earn_policy NUMBER,
5041 c_date_worked DATE
5042 )
5043 IS
5044 SELECT er.hours, er.element_type_id
5045 FROM hxt_earning_rules er
5046 WHERE er.egr_type = 'WKL'
5047 AND er.egp_id = c_earn_policy
5048 AND c_date_worked BETWEEN er.effective_start_date
5049 AND er.effective_end_date
5050 ORDER BY er.seq_no;
5051
5052 -- Following cursor changed for bug 4444969
5053 /*
5054 CURSOR get_wkl_tot_incl_hrs_2day
5055 IS
5056 SELECT NVL (SUM (hrw.hours), 0)
5057 FROM hxt_det_hours_worked hrw,
5058 hxt_timecards tim,
5059 hxt_earn_groups erg,
5060 hxt_earn_group_types egt,
5061 hxt_earning_policies erp,
5062 hxt_add_elem_info_f aei
5063 WHERE tim.for_person_id = g_person_id
5064 AND hrw.tim_id = tim.ID
5065 AND erp.ID = g_ep_id
5066 AND egt.ID = erp.egt_id
5067 AND erg.egt_id = egt.ID
5068 AND erg.element_type_id = hrw.element_type_id
5069 AND hrw.element_type_id = aei.element_type_id
5070 AND ( -- get weekly total to date
5071 (hrw.date_worked BETWEEN NEXT_DAY (g_date_worked - 7,
5072 start_day_of_week
5073 )
5074 AND (g_date_worked - 1)
5075 )
5076 OR
5077 -- get any hours worked on this day that were entered before the
5078 -- current row, i.e., parent_id of the rest of the rows entered
5079 -- for this day will be less than the current row.
5080 -- i.e., for example when entering regular as well as vac hrs on
5081 -- the same day but in two different rows, then get the hrs for the
5082 -- rows that were entered before the current row that is being
5083 -- processed for the day
5084 ( -- AND aei.earning_category <> 'ABS'
5085 hrw.date_worked = g_date_worked
5086 AND hrw.parent_id < g_id
5087 )
5088 )
5089 AND hrw.date_worked BETWEEN erp.effective_start_date
5090 AND erp.effective_end_date;
5091 */
5092 -- This change considers the hours entered, while totaling for the week,
5093 -- irrespective of the sequence in which the rows for a day were entered.
5094 CURSOR get_wkl_tot_incl_hrs_2day
5095 IS
5096 SELECT NVL (SUM (hrw.hours), 0)
5097 FROM hxt_det_hours_worked hrw,
5098 hxt_timecards tim,
5099 hxt_earn_groups erg,
5100 hxt_earn_group_types egt,
5101 hxt_earning_policies erp,
5102 hxt_add_elem_info_f aei
5103 WHERE tim.for_person_id = g_person_id
5104 AND hrw.tim_id = tim.ID
5105 AND erp.ID = g_ep_id
5106 AND egt.ID = erp.egt_id
5107 AND erg.egt_id = egt.ID
5108 AND erg.element_type_id = hrw.element_type_id
5109 AND hrw.element_type_id = aei.element_type_id
5110 AND -- get weekly total to date
5111 hrw.date_worked BETWEEN NEXT_DAY (g_date_worked - 7,
5112 start_day_of_week
5113 )
5114 AND g_date_worked
5115 AND hrw.date_worked BETWEEN erp.effective_start_date
5116 AND erp.effective_end_date
5117 AND hrw.date_worked BETWEEN aei.effective_start_date
5118 AND aei.effective_end_date
5119 AND sysdate BETWEEN aei.effective_start_date
5120 AND aei.effective_end_date; /* Bug: 6674738 */
5121
5122 l_hours_left NUMBER;
5123 l_first_daily_elem NUMBER;
5124 l_second_daily_elem NUMBER;
5125 l_third_daily_elem NUMBER;
5126 l_first_daily_cap NUMBER;
5127 l_second_daily_cap NUMBER;
5128 l_third_daily_cap NUMBER;
5129 l_first_elem NUMBER;
5130 l_second_elem NUMBER;
5131 l_third_elem NUMBER;
5132 l_first_cap NUMBER;
5133 l_second_cap NUMBER;
5134 l_third_cap NUMBER;
5135 l_tot_hours NUMBER;
5136 l_error_return NUMBER := 0;
5137 l_earning_category VARCHAR2 (10); -- category of earning
5138 l_proc VARCHAR2 (200);
5139 BEGIN
5140 IF g_debug
5141 THEN
5142 l_proc := 'hxt_time_detail.adjust_for_absence';
5143 hr_utility.set_location (l_proc, 10);
5144 hr_utility.TRACE ('a_ep_id:' || a_ep_id);
5145 hr_utility.TRACE ( 'a_date_worked :'
5146 || TO_CHAR (a_date_worked,
5147 'DD-MON-YYYY HH24:MI:SS'
5148 )
5149 );
5150 END IF;
5151
5152 IF g_ep_type = 'SPECIAL'
5153 THEN
5154 hr_utility.set_location (l_proc, 10.5);
5155
5156 OPEN daily_earn_rules_cur2 (a_ep_id, a_date_worked);
5157
5158 FETCH daily_earn_rules_cur2
5159 INTO l_first_daily_cap, l_first_daily_elem;
5160
5161 IF g_debug
5162 THEN
5163 hr_utility.TRACE ('l_first_daily_cap :' || l_first_daily_cap);
5164 hr_utility.TRACE ('l_first_daily_elem:' || l_first_daily_elem);
5165 END IF;
5166
5167 IF daily_earn_rules_cur2%FOUND
5168 THEN
5169 IF g_debug
5170 THEN
5171 hr_utility.set_location (l_proc, 11);
5172 END IF;
5173
5174 FETCH daily_earn_rules_cur2
5175 INTO l_second_daily_cap, l_second_daily_elem;
5176
5177 IF g_debug
5178 THEN
5179 hr_utility.TRACE ( 'l_second_daily_cap :'
5180 || l_second_daily_cap
5181 );
5182 hr_utility.TRACE ( 'l_second_daily_elem:'
5183 || l_second_daily_elem
5184 );
5185 END IF;
5186
5187 IF daily_earn_rules_cur2%FOUND
5188 THEN
5189 IF g_debug
5190 THEN
5191 hr_utility.set_location (l_proc, 12);
5192 END IF;
5193
5194 FETCH daily_earn_rules_cur2
5195 INTO l_third_daily_cap, l_third_daily_elem;
5196
5197 IF g_debug
5198 THEN
5199 hr_utility.TRACE ( 'l_third_daily_cap :'
5200 || l_third_daily_cap
5201 );
5202 hr_utility.TRACE ( 'l_third_daily_elem:'
5203 || l_third_daily_elem
5204 );
5205 END IF;
5206
5207 IF daily_earn_rules_cur2%FOUND
5208 THEN
5209 IF g_debug
5210 THEN
5211 hr_utility.set_location (l_proc, 13);
5212 END IF;
5213
5214 NULL;
5215 ELSE
5216 IF g_debug
5217 THEN
5218 hr_utility.set_location (l_proc, 14);
5219 END IF;
5220
5221 l_third_daily_cap := 999;
5222 END IF;
5223 ELSE
5224 IF g_debug
5225 THEN
5226 hr_utility.set_location (l_proc, 15);
5227 END IF;
5228
5229 l_second_daily_cap := 999;
5230 END IF;
5231 ELSE
5232 IF g_debug
5233 THEN
5234 hr_utility.set_location (l_proc, 16);
5235 END IF;
5236
5237 CLOSE daily_earn_rules_cur2;
5238
5239 hxt_util.DEBUG ('Return code is 2 from loc B');
5240 -- debug only --HXT115
5241 RETURN 2;
5242 END IF;
5243
5244 IF g_debug
5245 THEN
5246 hr_utility.set_location (l_proc, 20);
5247 END IF;
5248
5249 CLOSE daily_earn_rules_cur2;
5250 END IF;
5251
5252 OPEN weekly_earn_rules_cur2 (a_ep_id, a_date_worked);
5253
5254 FETCH weekly_earn_rules_cur2
5255 INTO l_first_cap, l_first_elem;
5256
5257 IF g_debug
5258 THEN
5259 hr_utility.TRACE ('l_first_cap :' || l_first_cap);
5260 hr_utility.TRACE ('l_first_elem:' || l_first_elem);
5261 END IF;
5262
5263 IF weekly_earn_rules_cur2%FOUND
5264 THEN
5265 IF g_debug
5266 THEN
5267 hr_utility.set_location (l_proc, 25);
5268 END IF;
5269
5270 FETCH weekly_earn_rules_cur2
5271 INTO l_second_cap, l_second_elem;
5272
5273 IF g_debug
5274 THEN
5275 hr_utility.TRACE ('l_second_cap :' || l_second_cap);
5276 hr_utility.TRACE ('l_second_elem:' || l_second_elem);
5277 END IF;
5278
5279 IF weekly_earn_rules_cur2%FOUND
5280 THEN
5281 IF g_debug
5282 THEN
5283 hr_utility.set_location (l_proc, 30);
5284 END IF;
5285
5286 FETCH weekly_earn_rules_cur2
5287 INTO l_third_cap, l_third_elem;
5288
5289 IF g_debug
5290 THEN
5291 hr_utility.TRACE ('l_third_cap :' || l_third_cap);
5292 hr_utility.TRACE ('l_third_elem:' || l_third_elem);
5293 END IF;
5294
5295 IF weekly_earn_rules_cur2%FOUND
5296 THEN
5297 IF g_debug
5298 THEN
5299 hr_utility.set_location (l_proc, 40);
5300 END IF;
5301
5302 NULL;
5303 ELSE
5304 IF g_debug
5305 THEN
5306 hr_utility.set_location (l_proc, 50);
5307 END IF;
5308
5309 l_third_cap := 999;
5310 END IF;
5311 ELSE
5312 IF g_debug
5313 THEN
5314 hr_utility.set_location (l_proc, 60);
5315 END IF;
5316
5317 l_second_cap := 999;
5318 END IF;
5319 ELSE
5320 IF g_debug
5321 THEN
5322 hr_utility.set_location (l_proc, 70);
5323 END IF;
5324
5325 CLOSE weekly_earn_rules_cur2;
5326
5327 hxt_util.DEBUG ('Return code is 2 from loc B');
5328 -- debug only --HXT115
5329 RETURN 2;
5330 END IF;
5331
5332 IF g_debug
5333 THEN
5334 hr_utility.set_location (l_proc, 80);
5335 END IF;
5336
5337 CLOSE weekly_earn_rules_cur2;
5338
5339 -- Get weekly total including today. For today only get the hours other than
5340 -- ABS hours, since these need to be included in the total hrs for the week
5341 -- when determining how many ABS hrs need to be adjusted as OT hrs.
5342 -- Say for e.g., Weekly rule cap is 40
5343 -- hrs entered for the week are as follows:
5344 -- MON TUE WED THURS
5345 -- REG 9 5 5
5346 -- VAC 2 6 10 6
5347 -- The total hours for the week on Thurs when entering 5 hrs reg is 32.
5348 -- Now when entering 6 hrs VAC on Thurs the total weekly hours should be
5349 -- calculated as 32(Mon + Tue + Wed) + 5 hrs REG on Thurs = 37 hrs.
5350
5351 -- l_earning_category := hxt_util.element_cat(g_element_type_id
5352 -- ,g_date_worked);
5353 IF g_debug
5354 THEN
5355 hr_utility.set_location (l_proc, 81);
5356 hr_utility.TRACE ('l_earning_category:' || l_earning_category);
5357 END IF;
5358
5359 /* IF l_earning_category <> 'ABS' THEN
5360 hr_utility.set_location(l_proc,82);
5361 l_tot_hours := get_weekly_total_to_date;
5362 ELSIF l_earning_category = 'ABS' THEN
5363 hr_utility.set_location(l_proc,83);
5364 OPEN get_wkl_tot_incl_non_abs_2day;
5365 FETCH get_wkl_tot_incl_non_abs_2day into l_tot_hours;
5366 CLOSE get_wkl_tot_incl_non_abs_2day;
5367 END IF; */
5368 IF g_debug
5369 THEN
5370 hr_utility.TRACE ('start_day_of_week:' || start_day_of_week);
5371 hr_utility.TRACE ('g_person_id :' || g_person_id);
5372 hr_utility.TRACE ('g_ep_id :' || g_ep_id);
5373 hr_utility.TRACE ('g_id(parent_id) :' || g_id);
5374 hr_utility.TRACE ( 'g_date_worked :'
5375 || TO_CHAR (g_date_worked, 'dd/mon/yy')
5376 );
5377 END IF;
5378
5379 -- l_tot_hours := get_weekly_total_to_date;
5380 OPEN get_wkl_tot_incl_hrs_2day;
5381
5382 FETCH get_wkl_tot_incl_hrs_2day
5383 INTO l_tot_hours;
5384
5385 CLOSE get_wkl_tot_incl_hrs_2day;
5386
5387 IF g_debug
5388 THEN
5389 hr_utility.TRACE ('l_tot_hours :' || l_tot_hours);
5390 END IF;
5391
5392 -- Bug 4444969 fix
5393 -- While processing a row, the g_hours(hrs entered on the row being
5394 -- processed) are subtracted from the above total so that the Overtime
5395 -- can be calculated correctly. Subtracting is required since the
5396 -- above cursor brings back the total hrs from the details table and
5397 -- the record being processed already exists in the details table
5398 -- (since hxt_time_pay.pay is called before the call to
5399 -- adjust_for_absence function
5400 l_tot_hours := l_tot_hours - g_hours;
5401
5402 IF g_debug
5403 THEN
5404 hr_utility.TRACE ('l_tot_hours :' || l_tot_hours);
5405 hr_utility.TRACE ('l_first_cap :' || l_first_cap);
5406 hr_utility.TRACE ('g_hours :' || g_hours);
5407 END IF;
5408
5409 --If total weekly hours are less than the first weekly cap:
5410 IF l_tot_hours <= l_first_cap
5411 THEN
5412 IF g_debug
5413 THEN
5414 hr_utility.set_location (l_proc, 90);
5415 END IF;
5416
5417 IF (l_tot_hours + g_hours) <= l_first_cap
5418 THEN
5419 IF g_debug
5420 THEN
5421 hr_utility.set_location (l_proc, 95);
5422 END IF;
5423
5424 -- Nothing to adjust as per the Earning Policy's Weekly caps.
5425
5426 -- And nothing gets adjusted on the basis of the daily EP rules as per
5427 -- the current functionality of the application. It is considered as an
5428 -- override as long as the weekly cap limits are not reached.
5429 -- Since the Earning Group is a counter for Weekly caps only, the
5430 -- application currently lacks enough information to take care of
5431 -- ABS adjustments based on EP daily rules. That's why commented out the
5432 -- following code otherwise it would double count the ABS hours that
5433 -- need to be adjusted based on both daily as well as weekly rules,
5434 -- screwing up the adjustment on previous days.
5435 -- So, as of now, the ABS hours get adjusted only when the weekly cap
5436 -- limit is reached, they are considered as overrides when daily EP rules
5437 -- are getting applied.
5438 /*
5439 -- but if it is a SPECIAL Earning Policy then check if any hours
5440 -- need to be adjusted based on Earning Policy's Daily caps.
5441
5442 IF (l_first_cap - l_tot_hours) >= g_hours THEN
5443 hr_utility.set_location(l_proc,100);
5444 hr_utility.trace('l_first_daily_cap :'||l_first_daily_cap);
5445 hr_utility.trace('l_second_daily_cap :'||l_second_daily_cap);
5446 IF g_EP_TYPE = 'SPECIAL' THEN
5447 hr_utility.set_location(l_proc,105);
5448 IF g_hours <= l_first_daily_cap THEN
5449 hr_utility.set_location(l_proc,110);
5450 -- Nothing to adjust as per daily caps.
5451 l_hours_left := 0;
5452 ELSIF l_first_daily_cap < g_hours AND
5453 g_hours <= l_second_daily_cap THEN
5454 hr_utility.set_location(l_proc,115);
5455 l_hours_left := g_hours -l_first_daily_cap;
5456 hr_utility.trace('l_hours_left :'||l_hours_left);
5457 l_error_return := adjust_abs_hrs_on_prev_days
5458 (a_tim_id
5459 ,a_date_worked
5460 ,l_tot_hours
5461 ,l_hours_left
5462 ,l_second_elem);
5463 hr_utility.set_location(l_proc,120);
5464 hr_utility.trace('l_error_return :'||l_error_return);
5465 ELSIF l_second_daily_cap < g_hours THEN
5466 hr_utility.set_location(l_proc,125);
5467 l_hours_left := g_hours - l_second_daily_cap;
5468 hr_utility.trace('l_hours_left :'||l_hours_left);
5469 l_error_return := adjust_abs_hrs_on_prev_days
5470 (a_tim_id
5471 ,a_date_worked
5472 ,l_tot_hours
5473 ,l_hours_left
5474 ,l_third_elem);
5475 hr_utility.set_location(l_proc,130);
5476 hr_utility.trace('l_error_return :'||l_error_return);
5477 IF l_error_return <> 0 THEN
5478 hr_utility.set_location(l_proc,135);
5479 return l_error_return;
5480 END IF;
5481 hr_utility.set_location(l_proc,140);
5482 l_hours_left := l_second_daily_cap - l_first_daily_cap;
5483 hr_utility.trace('l_hours_left :'||l_hours_left);
5484 l_error_return := adjust_abs_hrs_on_prev_days
5485 (a_tim_id
5486 ,a_date_worked
5487 ,l_tot_hours
5488 ,l_hours_left
5489 ,l_second_elem);
5490 hr_utility.set_location(l_proc,145);
5491 hr_utility.trace('l_error_return :'||l_error_return);
5492 END IF;
5493 hr_utility.set_location(l_proc,150);
5494 END IF; -- g_EP_TYPE = 'SPECIAL'
5495 hr_utility.set_location(l_proc,155);
5496 END IF; -- (first_cap - l_tot_hours) >= g_hours
5497 hr_utility.set_location(l_proc,160);
5498 */
5499 -- Since nothing to adjust, implies return back
5500 l_error_return := 0;
5501
5502 IF g_debug
5503 THEN
5504 hr_utility.set_location (l_proc, 165);
5505 hr_utility.TRACE ('l_first_cap:' || l_first_cap);
5506 hr_utility.TRACE ('l_second_cap:' || l_second_cap);
5507 hr_utility.TRACE ('l_tot_hours:' || l_tot_hours);
5508 END IF;
5509 ELSIF l_first_cap < (l_tot_hours + g_hours)
5510 AND (l_tot_hours + g_hours) <= l_second_cap
5511 THEN
5512 IF g_debug
5513 THEN
5514 hr_utility.set_location (l_proc, 170);
5515 END IF;
5516
5517 l_hours_left := (l_tot_hours + g_hours) - l_first_cap;
5518
5519 IF g_debug
5520 THEN
5521 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
5522 END IF;
5523
5524 l_error_return :=
5525 adjust_abs_hrs_on_prev_days (a_tim_id,
5526 a_date_worked,
5527 l_tot_hours,
5528 l_hours_left,
5529 l_second_elem
5530 );
5531
5532 IF g_debug
5533 THEN
5534 hr_utility.set_location (l_proc, 175);
5535 hr_utility.TRACE ('l_error_return:' || l_error_return);
5536 END IF;
5537 ELSIF l_second_cap < (l_tot_hours + g_hours)
5538 THEN
5539 IF g_debug
5540 THEN
5541 hr_utility.set_location (l_proc, 180);
5542 END IF;
5543
5544 l_hours_left := (l_tot_hours + g_hours) - l_second_cap;
5545
5546 IF g_debug
5547 THEN
5548 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
5549 END IF;
5550
5551 l_error_return :=
5552 adjust_abs_hrs_on_prev_days (a_tim_id,
5553 a_date_worked,
5554 l_tot_hours,
5555 l_hours_left,
5556 l_third_elem
5557 );
5558
5559 IF g_debug
5560 THEN
5561 hr_utility.set_location (l_proc, 185);
5562 hr_utility.TRACE ('l_error_return:' || l_error_return);
5563 END IF;
5564
5565 IF l_error_return <> 0
5566 THEN
5567 IF g_debug
5568 THEN
5569 hr_utility.set_location (l_proc, 190);
5570 END IF;
5571
5572 RETURN l_error_return;
5573 END IF;
5574
5575 l_hours_left := l_second_cap - l_first_cap;
5576
5577 IF g_debug
5578 THEN
5579 hr_utility.set_location (l_proc, 195);
5580 END IF;
5581
5582 l_error_return :=
5583 adjust_abs_hrs_on_prev_days (a_tim_id,
5584 a_date_worked,
5585 l_tot_hours,
5586 l_hours_left,
5587 l_second_elem
5588 );
5589
5590 IF g_debug
5591 THEN
5592 hr_utility.set_location (l_proc, 200);
5593 END IF;
5594 END IF;
5595
5596 IF g_debug
5597 THEN
5598 hr_utility.set_location (l_proc, 205);
5599 END IF;
5600 --IF total weekly hours are between first weekly cap and second weekly cap:
5601 ELSIF l_first_cap < l_tot_hours AND l_tot_hours <= l_second_cap
5602 THEN
5603 IF g_debug
5604 THEN
5605 hr_utility.set_location (l_proc, 210);
5606 END IF;
5607
5608 IF (l_tot_hours + g_hours) <= l_second_cap
5609 THEN
5610 IF g_debug
5611 THEN
5612 hr_utility.set_location (l_proc, 215);
5613 END IF;
5614
5615 l_hours_left := g_hours;
5616
5617 IF g_debug
5618 THEN
5619 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
5620 END IF;
5621
5622 l_error_return :=
5623 adjust_abs_hrs_on_prev_days (a_tim_id,
5624 a_date_worked,
5625 l_tot_hours,
5626 l_hours_left,
5627 l_second_elem
5628 );
5629
5630 IF g_debug
5631 THEN
5632 hr_utility.set_location (l_proc, 220);
5633 hr_utility.TRACE ('l_error_return:' || l_error_return);
5634 END IF;
5635 ELSIF l_second_cap < (l_tot_hours + g_hours)
5636 THEN
5637 IF g_debug
5638 THEN
5639 hr_utility.set_location (l_proc, 225);
5640 END IF;
5641
5642 l_hours_left := (l_tot_hours + g_hours) - l_second_cap;
5643
5644 IF g_debug
5645 THEN
5646 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
5647 END IF;
5648
5649 l_error_return :=
5650 adjust_abs_hrs_on_prev_days (a_tim_id,
5651 a_date_worked,
5652 l_tot_hours,
5653 l_hours_left,
5654 l_third_elem
5655 );
5656
5657 IF g_debug
5658 THEN
5659 hr_utility.set_location (l_proc, 230);
5660 hr_utility.TRACE ('l_error_return:' || l_error_return);
5661 END IF;
5662
5663 IF l_error_return <> 0
5664 THEN
5665 IF g_debug
5666 THEN
5667 hr_utility.set_location (l_proc, 235);
5668 END IF;
5669
5670 RETURN l_error_return;
5671 END IF;
5672
5673 IF g_debug
5674 THEN
5675 hr_utility.set_location (l_proc, 240);
5676 END IF;
5677
5678 l_hours_left := l_second_cap - l_tot_hours;
5679
5680 IF g_debug
5681 THEN
5682 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
5683 END IF;
5684
5685 l_error_return :=
5686 adjust_abs_hrs_on_prev_days (a_tim_id,
5687 a_date_worked,
5688 l_tot_hours,
5689 l_hours_left,
5690 l_second_elem
5691 );
5692
5693 IF g_debug
5694 THEN
5695 hr_utility.set_location (l_proc, 245);
5696 hr_utility.TRACE ('l_error_return:' || l_error_return);
5697 END IF;
5698 END IF;
5699
5700 IF g_debug
5701 THEN
5702 hr_utility.set_location (l_proc, 250);
5703 END IF;
5704 --IF total weekly hours are greater than second weekly cap:
5705 ELSIF l_tot_hours > l_second_cap
5706 THEN
5707 IF g_debug
5708 THEN
5709 hr_utility.set_location (l_proc, 255);
5710 END IF;
5711
5712 l_hours_left := g_hours;
5713
5714 IF g_debug
5715 THEN
5716 hr_utility.TRACE ('l_hours_left:' || l_hours_left);
5717 END IF;
5718
5719 l_error_return :=
5720 adjust_abs_hrs_on_prev_days (a_tim_id,
5721 a_date_worked,
5722 l_tot_hours,
5723 l_hours_left,
5724 l_third_elem
5725 );
5726
5727 IF g_debug
5728 THEN
5729 hr_utility.set_location (l_proc, 260);
5730 hr_utility.TRACE ('l_error_return:' || l_error_return);
5731 END IF;
5732 END IF;
5733
5734 IF g_debug
5735 THEN
5736 hr_utility.set_location (l_proc, 270);
5737 END IF;
5738
5739 RETURN l_error_return;
5740 END adjust_for_absence;
5741
5742 PROCEDURE select_weekly_hours (
5743 p_rule_to_pay OUT NOCOPY VARCHAR2,
5744 p_hours_to_pay_this_rule OUT NOCOPY NUMBER,
5745 p_element_type_id_to_pay OUT NOCOPY NUMBER
5746 )
5747 IS
5748 BEGIN
5749 IF g_debug
5750 THEN
5751 hr_utility.set_location ('select_weekly_hours', 1);
5752 hr_utility.TRACE
5753 ( 'p_element_type_id_to_pay i.e weekly_earning_type:'
5754 || weekly_earning_type
5755 );
5756 hr_utility.TRACE ('hours_left_to_pay :' || hours_left_to_pay);
5757 hr_utility.TRACE ('weekly_rule_cap:' || weekly_rule_cap);
5758 hr_utility.TRACE ( 'hours_paid_weekly_rule :'
5759 || hours_paid_weekly_rule
5760 );
5761 END IF;
5762
5763 p_rule_to_pay := 'WKL';
5764 p_element_type_id_to_pay := /* SPR C148 current_weekly_earning*/
5765 weekly_earning_type;
5766 p_hours_to_pay_this_rule :=
5767 LEAST (hours_left_to_pay,
5768 (weekly_rule_cap - hours_paid_weekly_rule
5769 )
5770 );
5771
5772 IF g_debug
5773 THEN
5774 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
5775 || p_hours_to_pay_this_rule
5776 );
5777 hr_utility.set_location ('select_weekly_hours', 2);
5778 END IF;
5779 END select_weekly_hours;
5780
5781 --------------------------------------------------------------------------------
5782 PROCEDURE select_hol_weekly_hours (
5783 p_rule_to_pay OUT NOCOPY VARCHAR2,
5784 p_hours_to_pay_this_rule OUT NOCOPY NUMBER,
5785 p_element_type_id_to_pay OUT NOCOPY NUMBER
5786 )
5787 IS
5788 BEGIN
5789 IF g_debug
5790 THEN
5791 hr_utility.set_location ('select_hol_weekly_hours', 10);
5792 END IF;
5793
5794 p_rule_to_pay := 'DAY';
5795 p_hours_to_pay_this_rule :=
5796 LEAST (hours_left_to_pay,
5797 (daily_rule_cap - hours_paid_daily_rule
5798 )
5799 );
5800 p_element_type_id_to_pay := daily_earning_type;
5801
5802 IF g_debug
5803 THEN
5804 hr_utility.set_location ('select_hol_weekly_hours', 20);
5805 END IF;
5806 END select_hol_weekly_hours;
5807
5808 --------------------------------------------------------------------------------
5809 PROCEDURE select_rule_and_hours (
5810 p_error_code OUT NOCOPY NUMBER,
5811 p_rule_to_pay OUT NOCOPY VARCHAR2,
5812 p_hours_to_pay_this_rule OUT NOCOPY NUMBER,
5813 p_element_type_id OUT NOCOPY NUMBER
5814 )
5815 IS
5816 -- Selects the rule type, hours, and earning element id to be paid on the
5817 -- current sub-segment.
5818 -- Daily rules are paid until either weekly or special cap is hit.
5819 -- Special rule is only applicable if consecutive days have been reached.
5820 -- It then acts like a daily rule in that its base can be overridden by the
5821 -- weekly cap until the special hours cap is hit.
5822 -- returns 0 for success, 2 for error
5823 srh_rule VARCHAR2 (4);
5824 -- local used for error checking
5825 l_error_return NUMBER := 0;
5826 l_first_weekly_rule NUMBER;
5827
5828 CURSOR get_weekly_cap (i_earn_policy NUMBER)
5829 IS
5830 SELECT er.hours
5831 FROM hxt_earning_rules er
5832 WHERE er.egr_type = 'WKL'
5833 AND er.egp_id = i_earn_policy
5834 AND g_date_worked BETWEEN er.effective_start_date
5835 AND er.effective_end_date
5836 ORDER BY er.seq_no;
5837
5838 lv_override_hrs NUMBER := 0;
5839 lv_override_element NUMBER;
5840 BEGIN
5841 IF g_debug
5842 THEN
5843 hr_utility.set_location ('select_rule_and_hours', 10);
5844 END IF;
5845
5846 OPEN get_weekly_cap (g_ep_id);
5847
5848 FETCH get_weekly_cap
5849 INTO l_first_weekly_rule;
5850
5851 IF g_debug
5852 THEN
5853 hr_utility.TRACE ( 'first_weekly_rule :'
5854 || l_first_weekly_rule
5855 );
5856 END IF;
5857
5858 CLOSE get_weekly_cap;
5859
5860 p_error_code := 0;
5861
5862 IF consecutive_days_reached = FALSE
5863 THEN
5864 IF g_debug
5865 THEN
5866 hr_utility.set_location ('select_rule_and_hours', 20);
5867 hr_utility.TRACE ( 'hours_paid_weekly_rule :'
5868 || hours_paid_weekly_rule
5869 );
5870 hr_utility.TRACE ( 'weekly_rule_cap :'
5871 || weekly_rule_cap
5872 );
5873 hr_utility.TRACE ( 'first_daily_rule_cap :'
5874 || first_daily_rule_cap
5875 );
5876 hr_utility.TRACE ( 'get_weekly_total_to_date :'
5877 || get_weekly_total_to_date
5878 );
5879 hr_utility.TRACE ( 'l_first_weekly_rule :'
5880 || l_first_weekly_rule
5881 );
5882 END IF;
5883
5884 IF (first_weekly_cap_reached = TRUE)
5885 THEN -- hours paid over weekly cap
5886 IF g_debug
5887 THEN
5888 hr_utility.set_location ('Select_rule_and_hours', 30);
5889 hr_utility.TRACE ( 'hours_left_to_pay :'
5890 || hours_left_to_pay
5891 );
5892 hr_utility.TRACE ( 'weekly_rule_cap :'
5893 || weekly_rule_cap
5894 );
5895 hr_utility.TRACE ( 'hours_paid_weekly_rule :'
5896 || hours_paid_weekly_rule
5897 );
5898 END IF;
5899
5900 -- MHANDA Added this code for SPECIAL g_ep_type,where there are
5901 -- more than two weekly earning caps for example:
5902 -- the earning policy having weekly earning rules as
5903 -- Weekly Regular - 40 hrs
5904 -- Weekly Overtime - 52 hrs
5905 -- Weekly Doubletime - 99 hrs
5906 srh_rule := 'WKL';
5907
5908 IF g_debug
5909 THEN
5910 hr_utility.set_location ('select_rule_and_hours', 40);
5911 END IF;
5912
5913 p_hours_to_pay_this_rule :=
5914 LEAST (hours_left_to_pay,
5915 (weekly_rule_cap - hours_paid_weekly_rule
5916 )
5917 );
5918 p_element_type_id := weekly_earning_type;
5919
5920 IF g_debug
5921 THEN
5922 hr_utility.TRACE ( 'p_hours_to_pay_this_rule :'
5923 || p_hours_to_pay_this_rule
5924 );
5925 hr_utility.TRACE ('p_element_type_id :' || p_element_type_id);
5926 END IF;
5927 /*IF weekly_rule_cap > l_first_weekly_rule THEN
5928 IF second_weekly_cap_reached = TRUE THEN
5929 srh_rule := 'WKL';
5930 hr_utility.set_location('select_rule_and_hours',40);
5931 p_hours_to_pay_this_rule := LEAST(hours_left_to_pay,
5932 (weekly_rule_cap - hours_paid_for_dtime_elig));
5933 p_element_type_id := weekly_earning_type;
5934 hr_utility.trace('p_hours_to_pay_this_rule :'
5935 ||p_hours_to_pay_this_rule);
5936 hr_utility.trace('p_element_type_id :'||p_element_type_id);
5937 ELSE
5938 srh_rule := 'WKL';
5939 hr_utility.set_location('select_rule_and_hours',50);
5940 p_hours_to_pay_this_rule := LEAST(hours_left_to_pay,
5941 (weekly_rule_cap - hours_paid_weekly_rule));
5942 p_element_type_id := weekly_earning_type;
5943 hr_utility.trace('p_hours_to_pay_this_rule :'
5944 ||p_hours_to_pay_this_rule);
5945 hr_utility.trace('p_element_type_id :'||p_element_type_id);
5946 END IF;
5947 ELSE
5948 srh_rule := 'WKL';
5949 hr_utility.set_location('select_rule_and_hours',60);
5950 p_hours_to_pay_this_rule := LEAST(hours_left_to_pay,
5951 (weekly_rule_cap - hours_paid_weekly_rule)) ;
5952 p_element_type_id := weekly_earning_type;
5953 hr_utility.trace('p_hours_to_pay_this_rule :'
5954 ||p_hours_to_pay_this_rule);
5955 hr_utility.trace('p_element_type_id :'||p_element_type_id);
5956 END IF;*/
5957 ELSIF (first_weekly_cap_reached = FALSE)
5958 OR ( seven_day_cal_rule = TRUE
5959 AND g_cons_days_worked = 5
5960 AND p_rule_to_pay = 'DAY'
5961 )
5962 OR -- added this and condition for
5963 -- bug 1801337 because rule to pay
5964 -- is DAY
5965 (five_day_cal_rule = TRUE AND g_cons_days_worked = 4
5966 )
5967 OR ( five_day_cal_rule = FALSE
5968 AND seven_day_cal_rule = FALSE
5969 AND get_weekly_total_to_date <
5970 ( l_first_weekly_rule
5971 - NVL (first_daily_rule_cap, 0)
5972 )
5973 )
5974 THEN
5975 IF g_debug
5976 THEN
5977 hr_utility.set_location ('select_rule_and_hours', 70);
5978 END IF;
5979
5980 srh_rule := 'DAY';
5981
5982 IF end_of_day_rules
5983 THEN
5984 -- flag set when no more daily rules found
5985 -- it is not an error at that time as it allowed as long as another
5986 -- sub-segment does not need daily rules to pay
5987 IF g_debug
5988 THEN
5989 hr_utility.set_location ('select_rule_and_hours', 80);
5990 END IF;
5991
5992 fnd_message.set_name ('HXT', 'HXT_39294_ERN_RUL_NF');
5993 p_error_code :=
5994 call_hxthxc_gen_error ('HXT',
5995 'HXT_39294_ERN_RUL_NF',
5996 NULL,
5997 LOCATION,
5998 ''
5999 );
6000 --2278400 p_error_code := call_gen_error(location, '');
6001 p_hours_to_pay_this_rule := 0;
6002 ELSE
6003 IF g_debug
6004 THEN
6005 hr_utility.set_location ('select_rule_and_hours', 90);
6006 END IF;
6007
6008 overtime_hoursoverride (g_date_worked,
6009 g_egt_id,
6010 g_tim_id,
6011 lv_override_hrs,
6012 lv_override_element
6013 );
6014
6015 IF g_debug
6016 THEN
6017 hr_utility.TRACE ('lv_override_hrs :'
6018 || lv_override_hrs
6019 );
6020 hr_utility.TRACE ( 'lv_override_element :'
6021 || lv_override_element
6022 );
6023 hr_utility.set_location ('select_rule_and_hours', 91);
6024 hr_utility.TRACE ( 'hours_left_to_pay :'
6025 || hours_left_to_pay
6026 );
6027 hr_utility.TRACE ('daily_rule_cap :' || daily_rule_cap);
6028 hr_utility.TRACE ( 'hours_paid_daily_rule:'
6029 || hours_paid_daily_rule
6030 );
6031 hr_utility.TRACE ( 'first_daily_rule_cap :'
6032 || first_daily_rule_cap
6033 );
6034 END IF;
6035
6036 IF (hours_paid_daily_rule - lv_override_hrs) <
6037 first_daily_rule_cap
6038 THEN
6039 IF g_debug
6040 THEN
6041 hr_utility.set_location ('select_rule_and_hours',
6042 100);
6043 END IF;
6044
6045 p_hours_to_pay_this_rule :=
6046 LEAST (LEAST (hours_left_to_pay,
6047 daily_rule_cap
6048 - ( hours_paid_daily_rule
6049 - lv_override_hrs
6050 )
6051 ),
6052 (weekly_rule_cap - hours_paid_weekly_rule
6053 )
6054 );
6055
6056 -- Changed for Bug 1801337 because rule to pay is DAY
6057 -- p_hours_to_pay_this_rule := LEAST(hours_left_to_pay,
6058 -- daily_rule_cap - hours_paid_daily_rule);
6059 IF g_debug
6060 THEN
6061 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
6062 || p_hours_to_pay_this_rule
6063 );
6064 END IF;
6065
6066 IF daily_earning_type = lv_override_element
6067 AND p_hours_to_pay_this_rule > lv_override_hrs
6068 THEN
6069 IF g_debug
6070 THEN
6071 hr_utility.set_location ('select_rule_and_hours',
6072 101
6073 );
6074 END IF;
6075
6076 p_hours_to_pay_this_rule :=
6077 p_hours_to_pay_this_rule - lv_override_hrs;
6078 ELSIF daily_earning_type = lv_override_element
6079 AND p_hours_to_pay_this_rule <= lv_override_hrs
6080 THEN
6081 IF g_debug
6082 THEN
6083 hr_utility.TRACE ( 'lv_override_hrs:'
6084 || lv_override_hrs
6085 );
6086 hr_utility.TRACE ( 'daily_earning_type:'
6087 || daily_earning_type
6088 );
6089 hr_utility.TRACE ( 'first_daily_rule_cap:'
6090 || first_daily_rule_cap
6091 );
6092 END IF;
6093
6094 IF lv_override_hrs >=
6095 daily_rule_cap - first_daily_rule_cap
6096 THEN
6097 IF g_debug
6098 THEN
6099 hr_utility.set_location
6100 ('select_rule_and_hours',
6101 102
6102 );
6103 END IF;
6104
6105 p_hours_to_pay_this_rule := 0;
6106 END IF;
6107 END IF;
6108 ELSE
6109 IF g_debug
6110 THEN
6111 hr_utility.set_location ('select_rule_and_hours',
6112 105);
6113 hr_utility.TRACE ( 'hours_left_to_pay :'
6114 || hours_left_to_pay
6115 );
6116 hr_utility.TRACE ( 'daily_rule_cap :'
6117 || daily_rule_cap
6118 );
6119 hr_utility.TRACE ( 'hours_paid_daily_rule:'
6120 || hours_paid_daily_rule
6121 );
6122 END IF;
6123
6124 IF daily_earning_type = lv_override_element
6125 THEN
6126 IF hours_left_to_pay <=
6127 ( daily_rule_cap
6128 - (hours_paid_daily_rule - lv_override_hrs)
6129 )
6130 THEN
6131 IF g_debug
6132 THEN
6133 hr_utility.set_location
6134 ('select_rule_and_hours',
6135 110
6136 );
6137 END IF;
6138
6139 p_hours_to_pay_this_rule :=
6140 LEAST (hours_left_to_pay,
6141 (daily_rule_cap
6142 - (hours_paid_daily_rule)
6143 )
6144 );
6145 ELSE
6146 IF g_debug
6147 THEN
6148 hr_utility.set_location
6149 ('select_rule_and_hours',
6150 115
6151 );
6152 END IF;
6153
6154 p_hours_to_pay_this_rule :=
6155 LEAST (hours_left_to_pay,
6156 daily_rule_cap
6157 - (hours_paid_daily_rule
6158 - lv_override_hrs
6159 )
6160 );
6161 END IF;
6162 ELSE
6163 IF g_debug
6164 THEN
6165 hr_utility.set_location ('select_rule_and_hours',
6166 116
6167 );
6168 END IF;
6169
6170 p_hours_to_pay_this_rule :=
6171 LEAST (hours_left_to_pay,
6172 daily_rule_cap
6173 - (hours_paid_daily_rule - lv_override_hrs
6174 )
6175 );
6176 END IF;
6177
6178 IF g_debug
6179 THEN
6180 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
6181 || p_hours_to_pay_this_rule
6182 );
6183 END IF;
6184
6185 IF daily_earning_type = lv_override_element
6186 AND p_hours_to_pay_this_rule > lv_override_hrs
6187 THEN
6188 IF g_debug
6189 THEN
6190 hr_utility.set_location ('select_rule_and_hours',
6191 120
6192 );
6193 END IF;
6194
6195 p_hours_to_pay_this_rule :=
6196 p_hours_to_pay_this_rule - lv_override_hrs;
6197 ELSIF daily_earning_type = lv_override_element
6198 AND p_hours_to_pay_this_rule <= lv_override_hrs
6199 THEN
6200 IF g_debug
6201 THEN
6202 hr_utility.set_location ('select_rule_and_hours',
6203 125
6204 );
6205 hr_utility.TRACE ( 'lv_override_hrs:'
6206 || lv_override_hrs
6207 );
6208 hr_utility.TRACE ( 'daily_earning_type:'
6209 || daily_earning_type
6210 );
6211 hr_utility.TRACE ( 'first_daily_rule_cap:'
6212 || first_daily_rule_cap
6213 );
6214 END IF;
6215
6216 IF lv_override_hrs >=
6217 daily_rule_cap - first_daily_rule_cap
6218 THEN
6219 IF g_debug
6220 THEN
6221 hr_utility.set_location
6222 ('select_rule_and_hours',
6223 130
6224 );
6225 END IF;
6226
6227 p_hours_to_pay_this_rule := 0;
6228 END IF;
6229 END IF;
6230 END IF;
6231 END IF;
6232
6233 IF g_debug
6234 THEN
6235 hr_utility.set_location ('select_rule_and_hours', 135);
6236 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
6237 || p_hours_to_pay_this_rule
6238 );
6239 END IF;
6240
6241 p_element_type_id := daily_earning_type;
6242
6243 IF g_debug
6244 THEN
6245 hr_utility.TRACE ('p_element_type_id :' || p_element_type_id
6246 );
6247 END IF;
6248 /*ELSE -- hours paid over weekly cap
6249 hr_utility.set_location('select_rule_and_hours',120);
6250 hr_utility.trace('hours_left_to_pay :'||hours_left_to_pay);
6251 hr_utility.trace('weekly_rule_cap :'||weekly_rule_cap);
6252 hr_utility.trace('hours_paid_weekly_rule :'||hours_paid_weekly_rule);
6253 srh_rule := 'WKL';
6254 hr_utility.set_location('select_rule_and_hours',130);
6255 p_hours_to_pay_this_rule := LEAST(hours_left_to_pay,(weekly_rule_cap -
6256 hours_paid_weekly_rule)) ;
6257 p_element_type_id := weekly_earning_type;
6258 hr_utility.trace('p_hours_to_pay_this_rule :'||p_hours_to_pay_this_rule);
6259 hr_utility.trace('p_element_type_id :'||p_element_type_id);
6260 */
6261 END IF;
6262 ELSE -- special days limit reached
6263 IF g_debug
6264 THEN
6265 hr_utility.set_location ('select_rule_and_hours', 140);
6266 END IF;
6267
6268 IF hours_paid_daily_rule < special_daily_cap
6269 THEN
6270 IF g_debug
6271 THEN
6272 hr_utility.set_location ('select_rule_and_hours', 150);
6273 END IF;
6274
6275 srh_rule := 'SPC';
6276 p_hours_to_pay_this_rule :=
6277 LEAST (hours_left_to_pay,
6278 (special_daily_cap - hours_paid_daily_rule
6279 )
6280 );
6281 p_element_type_id := special_earning_type; -- SPR C355
6282
6283 IF g_debug
6284 THEN
6285 hr_utility.TRACE ('p_element_type_id :' || p_element_type_id
6286 );
6287 END IF;
6288 ELSE -- over special days and hours limits
6289 IF g_debug
6290 THEN
6291 hr_utility.set_location ('select_rule_and_hours', 160);
6292 END IF;
6293
6294 srh_rule := 'SPC';
6295 p_hours_to_pay_this_rule := hours_left_to_pay;
6296 p_element_type_id := special_earning_type2;
6297
6298 -- SPR C355 - chg'd to type2
6299 IF g_debug
6300 THEN
6301 hr_utility.TRACE ('p_element_type_id :' || p_element_type_id
6302 );
6303 END IF;
6304 END IF;
6305 END IF;
6306
6307 p_rule_to_pay := srh_rule;
6308
6309 IF g_debug
6310 THEN
6311 hr_utility.TRACE ('p_rule_to_pay :' || p_rule_to_pay);
6312 END IF;
6313
6314 IF srh_rule IS NULL
6315 THEN
6316 IF g_debug
6317 THEN
6318 hr_utility.set_location ('select_rule_and_hours', 170);
6319 END IF;
6320
6321 fnd_message.set_name ('HXT', 'HXT_39295_ERN_TYPE_NF');
6322 p_error_code :=
6323 call_hxthxc_gen_error ('HXT',
6324 'HXT_39295_ERN_TYPE_NF',
6325 NULL,
6326 LOCATION,
6327 ''
6328 );
6329 --2278400 p_error_code := call_gen_error(location, '');
6330 END IF;
6331
6332 IF g_debug
6333 THEN
6334 hr_utility.set_location ('select_rule_and_hours', 180);
6335 END IF;
6336 EXCEPTION
6337 WHEN OTHERS
6338 THEN
6339 IF g_debug
6340 THEN
6341 hr_utility.set_location ('select_rule_and_hours', 190);
6342 END IF;
6343
6344 fnd_message.set_name ('HXT', 'HXT_39274_OR_ERR_SEL_ERN_TYP');
6345 p_error_code :=
6346 call_hxthxc_gen_error ('HXT',
6347 'HXT_39274_OR_ERR_SEL_ERN_TYP',
6348 NULL,
6349 LOCATION,
6350 '',
6351 SQLERRM
6352 );
6353 --2278400 p_error_code := call_gen_error(location, '', sqlerrm);
6354 END;
6355
6356 --------------------------------------------------------------------------------
6357 PROCEDURE use_points_to_select_rule_hrs (
6358 p_error_code OUT NOCOPY NUMBER,
6359 p_rule_to_pay OUT NOCOPY VARCHAR2,
6360 p_hours_to_pay_this_rule OUT NOCOPY NUMBER,
6361 p_element_type_id OUT NOCOPY NUMBER
6362 )
6363 IS
6364 CURSOR special_earning_rules (
6365 i_earn_policy NUMBER,
6366 i_days NUMBER,
6367 spc_hrs_paid NUMBER
6368 )
6369 IS
6370 SELECT er.hours, er.element_type_id, er.days
6371 FROM hxt_earning_rules er
6372 WHERE er.egr_type = 'SPC'
6373 AND er.days = i_days
6374 AND er.days IS NOT NULL
6375 AND er.egp_id = i_earn_policy
6376 AND g_date_worked BETWEEN er.effective_start_date
6377 AND er.effective_end_date
6378 AND er.hours > spc_hrs_paid
6379 ORDER BY er.days DESC, er.hours ASC;
6380
6381 CURSOR daily_earning_rules (i_earn_policy NUMBER)
6382 IS
6383 SELECT er.hours, er.element_type_id
6384 FROM hxt_earning_rules er
6385 WHERE er.egr_type = 'DAY'
6386 AND er.egp_id = i_earn_policy
6387 AND g_date_worked BETWEEN er.effective_start_date
6388 AND er.effective_end_date
6389 ORDER BY er.seq_no;
6390
6391 CURSOR daily_earning_rules2 (i_earn_policy NUMBER, daily_cap NUMBER)
6392 IS
6393 SELECT er.hours, er.element_type_id
6394 FROM hxt_earning_rules er
6395 WHERE er.egr_type = 'DAY'
6396 AND er.egp_id = i_earn_policy
6397 AND g_date_worked BETWEEN er.effective_start_date
6398 AND er.effective_end_date
6399 AND er.hours > daily_cap
6400 ORDER BY er.seq_no;
6401
6402 CURSOR weekly_earning_rules (i_earn_policy NUMBER)
6403 IS
6404 SELECT er.hours, er.element_type_id
6405 FROM hxt_earning_rules er
6406 WHERE er.egr_type = 'WKL'
6407 AND er.egp_id = i_earn_policy
6408 AND g_date_worked BETWEEN er.effective_start_date
6409 AND er.effective_end_date
6410 ORDER BY er.seq_no;
6411
6412 CURSOR weekly_earning_rules2 (i_earn_policy NUMBER, weekly_cap NUMBER)
6413 IS
6414 SELECT er.hours, er.element_type_id
6415 FROM hxt_earning_rules er
6416 WHERE er.egr_type = 'WKL'
6417 AND er.egp_id = i_earn_policy
6418 AND g_date_worked BETWEEN er.effective_start_date
6419 AND er.effective_end_date
6420 AND er.hours > weekly_cap
6421 ORDER BY er.seq_no;
6422
6423 CURSOR elements_in_earn_groups (i_earn_policy NUMBER)
6424 IS
6425 SELECT eg.element_type_id
6426 FROM hxt_earn_groups eg
6427 WHERE eg.egt_id = (SELECT ep.egt_id
6428 FROM hxt_earning_policies ep
6429 WHERE ep.ID = g_ep_id);
6430
6431 CURSOR all_detail_hours_spc (
6432 cursor_day_worked DATE,
6433 cursor_person_id NUMBER,
6434 cursor_tim_id NUMBER
6435 )
6436 IS
6437 SELECT daily_hours
6438 FROM hxt_daily_hours_worked_v
6439 WHERE work_date || '' = cursor_day_worked
6440 AND tim_id = cursor_tim_id;
6441
6442 CURSOR weekly_earn_category_total --(cp_earning_category VARCHAR2) BUG 5499459
6443 IS
6444 SELECT NVL (SUM (hrw.hours), 0)
6445 FROM hxt_pay_element_types_f_ddf_v eltv,
6446 pay_element_types_f elt2,
6447 hxt_det_hours_worked hrw,
6448 hxt_timecards tim,
6449 hxt_earn_groups erg,
6450 hxt_earn_group_types egt,
6451 hxt_earning_policies erp
6452 WHERE tim.for_person_id = g_person_id
6453 AND hrw.tim_id = tim.ID
6454 AND hrw.date_worked BETWEEN NEXT_DAY (g_date_worked - 7,
6455 g_start_day_of_week
6456 )
6457 AND g_date_worked
6458 AND erp.ID = g_ep_id
6459 AND egt.ID = erp.egt_id
6460 AND erg.egt_id = egt.ID
6461 AND erg.element_type_id = hrw.element_type_id
6462 AND hrw.date_worked BETWEEN erp.effective_start_date
6463 AND erp.effective_end_date
6464 AND hrw.element_type_id = elt2.element_type_id
6465 AND hrw.date_worked BETWEEN elt2.effective_start_date
6466 AND elt2.effective_end_date
6467 AND elt2.element_type_id = eltv.element_type_id
6468 AND hrw.date_worked BETWEEN eltv.effective_start_date
6469 AND eltv.effective_end_date;
6470 --AND eltv.hxt_earning_category = cp_earning_category; BUG 5499459
6471
6472 daily_element_type_id NUMBER;
6473 daily_earning_cap NUMBER;
6474 daily_earning_cap2 NUMBER;
6475 spc_daily_earning_cap NUMBER;
6476 spc_element_type_id NUMBER;
6477 special_days NUMBER;
6478 weekly_element_type_id NUMBER;
6479 l_combo_elem_id NUMBER;
6480 weekly_earning_cap NUMBER;
6481 weekly_earning_cap2 NUMBER;
6482 l_element_type_id NUMBER;
6483 total_hours_to_pay NUMBER := 0;
6484 spc_hours_paid NUMBER := 0;
6485 total_hrs_worked_on_spc NUMBER := 0;
6486 spc_hours NUMBER := 0;
6487 hours_paid_for_week NUMBER := 0;
6488 hours_paid_for_day NUMBER := 0;
6489 hours_for_points NUMBER;
6490 --no.of hours considered for calculating
6491 --points for the current segment.
6492 hours_left NUMBER;
6493 --no.of hours left to be paid for the day.
6494 segment_points NUMBER;
6495 --points assigned to the current element.
6496 total_daily_points NUMBER := 0;
6497 --summation of segment points for a day.
6498 total_weekly_points NUMBER := 0;
6499 --summation of segment points for weekly rule
6500 l_points_assigned NUMBER;
6501 l_weekly_total NUMBER; --total hours worked that week
6502 l_daily_total NUMBER; --total hours worked that day
6503 l_daily_index BINARY_INTEGER := 0;
6504 l_weekly_index BINARY_INTEGER := 0;
6505 l_spc_index BINARY_INTEGER := 0;
6506 k NUMBER := 0;
6507 j NUMBER := 0;
6508 h NUMBER := 0;
6509 special_day BOOLEAN := FALSE;
6510 l_left_over_hours NUMBER := 0;
6511 l_category_index BINARY_INTEGER := 0;
6512 l_wkl_category_index BINARY_INTEGER := 0;
6513 l_dy_wk_combo_index BINARY_INTEGER := 0;
6514 l_reg_for_day NUMBER;
6515 l_dy_wk_reg_elem_id NUMBER;
6516 l_ovt_for_day NUMBER;
6517 l_dy_wk_ovt_elem_id NUMBER;
6518 l_dt_for_day NUMBER;
6519 l_dy_wk_dt_elem_id NUMBER;
6520 wky_reg_incl_dy_reg_expl NUMBER;
6521 l_weekly_reg_hrs NUMBER;
6522 l_weekly_reg_cap NUMBER;
6523 total_combo_points NUMBER := 0;
6524 l_greatest_points NUMBER := 0;
6525 l_total_daily_hrs NUMBER := 0;
6526 l_total_combo_hrs NUMBER := 0;
6527 use_weekly_reg VARCHAR2 (1) := 'N';
6528 use_weekly_ot VARCHAR2 (1) := 'N';
6529 use_weekly_dt VARCHAR2 (1) := 'N';
6530 use_daily_reg VARCHAR2 (1) := 'N';
6531 use_daily_ot VARCHAR2 (1) := 'N';
6532 use_daily_dt VARCHAR2 (1) := 'N';
6533 l_override_hrs NUMBER := 0;
6534 l_override_element NUMBER;
6535 hrs_already_paid BOOLEAN := FALSE;
6536 prev_daily_cap NUMBER := 0;
6537 prev_weekly_cap NUMBER := 0;
6538 l_proc VARCHAR2 (50);
6539
6540 PROCEDURE init_for_wkl_combine_pts_cal (
6541 l_use_weekly_reg IN VARCHAR2,
6542 l_use_weekly_ot IN VARCHAR2,
6543 l_use_weekly_dt IN VARCHAR2,
6544 l_weekly_reg_cap IN NUMBER,
6545 l_dy_wk_reg_elem_id OUT NOCOPY pay_element_types_f.element_type_id%TYPE,
6546 l_dy_wk_ovt_elem_id OUT NOCOPY pay_element_types_f.element_type_id%TYPE,
6547 l_dy_wk_dt_elem_id OUT NOCOPY pay_element_types_f.element_type_id%TYPE,
6548 l_use_daily_reg OUT NOCOPY VARCHAR2,
6549 l_use_daily_ot OUT NOCOPY VARCHAR2,
6550 l_use_daily_dt OUT NOCOPY VARCHAR2,
6551 l_reg_for_day OUT NOCOPY NUMBER,
6552 l_ovt_for_day OUT NOCOPY NUMBER,
6553 l_dt_for_day OUT NOCOPY NUMBER,
6554 wky_reg_incl_dy_reg_expl OUT NOCOPY NUMBER,
6555 l_weekly_reg_hrs OUT NOCOPY NUMBER
6556 )
6557 IS
6558 l_proc VARCHAR2 (50);
6559 BEGIN
6560 IF g_debug
6561 THEN
6562 l_proc := 'HXT_TIME_DETAIL.init_for_wkl_combine_pts_cal';
6563 hr_utility.set_location (l_proc, 10);
6564 END IF;
6565
6566 OPEN weekly_earn_category_total; --('REG');
6567
6568 FETCH weekly_earn_category_total
6569 INTO l_weekly_reg_hrs;
6570
6571 IF g_debug
6572 THEN
6573 hr_utility.TRACE ('l_weekly_REG_hrs:' || l_weekly_reg_hrs);
6574 END IF;
6575
6576 CLOSE weekly_earn_category_total;
6577
6578 -- Determine the daily REG, OT, DT hrs and the element types
6579 -- that need to be used for the rest of the week's explosion.
6580 FOR i IN 1 .. g_daily_explosion.COUNT
6581 LOOP
6582 IF g_debug
6583 THEN
6584 hr_utility.set_location (l_proc, 20);
6585 END IF;
6586
6587 IF g_daily_explosion (i).earning_category = 'REG'
6588 THEN
6589 IF g_debug
6590 THEN
6591 hr_utility.set_location (l_proc, 30);
6592 END IF;
6593
6594 l_reg_for_day := g_daily_explosion (i).hours_to_pay;
6595
6596 IF g_debug
6597 THEN
6598 hr_utility.TRACE ('l_reg_for_day:' || l_reg_for_day);
6599 END IF;
6600
6601 IF l_weekly_reg_hrs >= l_weekly_reg_cap
6602 AND l_use_weekly_reg = 'Y'
6603 THEN
6604 IF g_debug
6605 THEN
6606 hr_utility.set_location (l_proc, 40);
6607 END IF;
6608
6609 l_dy_wk_reg_elem_id :=
6610 g_weekly_earn_category (i).element_type_id;
6611 ELSE
6612 IF g_debug
6613 THEN
6614 hr_utility.set_location (l_proc, 50);
6615 END IF;
6616
6617 l_use_daily_reg := 'Y';
6618 l_dy_wk_reg_elem_id :=
6619 g_daily_explosion (i).element_type_id;
6620 END IF;
6621
6622 IF g_debug
6623 THEN
6624 hr_utility.set_location (l_proc, 60);
6625 hr_utility.TRACE ( 'l_dy_wk_reg_elem_id:'
6626 || l_dy_wk_reg_elem_id
6627 );
6628 END IF;
6629 ELSIF g_daily_explosion (i).earning_category = 'OVT'
6630 THEN
6631 IF g_debug
6632 THEN
6633 hr_utility.set_location (l_proc, 70);
6634 END IF;
6635
6636 l_ovt_for_day := g_daily_explosion (i).hours_to_pay;
6637
6638 IF g_debug
6639 THEN
6640 hr_utility.TRACE ('l_ovt_for_day:' || l_ovt_for_day);
6641 END IF;
6642
6643 IF l_weekly_reg_hrs >= l_weekly_reg_cap
6644 AND use_weekly_ot = 'Y'
6645 THEN
6646 IF g_debug
6647 THEN
6648 hr_utility.set_location (l_proc, 80);
6649 END IF;
6650
6651 l_dy_wk_ovt_elem_id :=
6652 g_weekly_earn_category (i).element_type_id;
6653 ELSE
6654 IF g_debug
6655 THEN
6656 hr_utility.set_location (l_proc, 90);
6657 END IF;
6658
6659 l_use_daily_ot := 'Y';
6660 l_dy_wk_ovt_elem_id :=
6661 g_daily_explosion (i).element_type_id;
6662 END IF;
6663
6664 IF g_debug
6665 THEN
6666 hr_utility.set_location (l_proc, 100);
6667 hr_utility.TRACE ( 'l_dy_wk_ovt_elem_id:'
6668 || l_dy_wk_ovt_elem_id
6669 );
6670 END IF;
6671 ELSIF g_daily_explosion (i).earning_category = 'DT'
6672 THEN
6673 IF g_debug
6674 THEN
6675 hr_utility.set_location (l_proc, 110);
6676 END IF;
6677
6678 l_dt_for_day := g_daily_explosion (i).hours_to_pay;
6679
6680 IF l_weekly_reg_hrs >= l_weekly_reg_cap
6681 AND use_weekly_dt = 'Y'
6682 THEN
6683 IF g_debug
6684 THEN
6685 hr_utility.set_location (l_proc, 120);
6686 END IF;
6687
6688 l_dy_wk_dt_elem_id :=
6689 g_weekly_earn_category (i).element_type_id;
6690 ELSE
6691 IF g_debug
6692 THEN
6693 hr_utility.set_location (l_proc, 130);
6694 END IF;
6695
6696 l_use_daily_dt := 'Y';
6697 l_dy_wk_dt_elem_id :=
6698 g_daily_explosion (i).element_type_id;
6699 END IF;
6700
6701 IF g_debug
6702 THEN
6703 hr_utility.set_location (l_proc, 140);
6704 hr_utility.TRACE ('l_dt_for_day:' || l_dt_for_day);
6705 hr_utility.TRACE ( 'l_dy_wk_dt_elem_id:'
6706 || l_dy_wk_dt_elem_id
6707 );
6708 END IF;
6709 END IF;
6710
6711 IF g_debug
6712 THEN
6713 hr_utility.set_location (l_proc, 150);
6714 END IF;
6715 END LOOP;
6716
6717 IF g_debug
6718 THEN
6719 hr_utility.set_location (l_proc, 160);
6720 END IF;
6721
6722 OPEN weekly_earning_rules (g_ep_id);
6723
6724 FETCH weekly_earning_rules
6725 INTO weekly_earning_cap, weekly_element_type_id;
6726
6727 IF g_debug
6728 THEN
6729 hr_utility.TRACE ('weekly_earning_cap:' || weekly_earning_cap);
6730 hr_utility.TRACE ( 'weekly_element_type_id:'
6731 || weekly_element_type_id
6732 );
6733 END IF;
6734
6735 CLOSE weekly_earning_rules;
6736
6737 IF g_debug
6738 THEN
6739 hr_utility.set_location (l_proc, 170);
6740 hr_utility.TRACE ('l_weekly_reg_hrs:' || l_weekly_reg_hrs);
6741 hr_utility.TRACE ('l_reg_for_day:' || l_reg_for_day);
6742 END IF;
6743
6744 -- Calculate the weekly reg total including today's REG hrs
6745 wky_reg_incl_dy_reg_expl := l_weekly_reg_hrs + l_reg_for_day;
6746
6747 IF g_debug
6748 THEN
6749 hr_utility.TRACE ( 'wky_reg_incl_dy_reg_expl:'
6750 || wky_reg_incl_dy_reg_expl
6751 );
6752 hr_utility.set_location (l_proc, 180);
6753 END IF;
6754 END;
6755 -- Selects the rule type, hours, and earning element id to be paid on the
6756 -- current sub-segment.
6757 -- Populate the daily array with the daily explosion based on the daily
6758 -- earning rules and the weekly array with the weekly explosion based on the
6759 -- weekly earning rules.
6760 -- Calculate the daily and the weekly points based on the rules and the
6761 -- points counter,for example
6762 -- Setup Data:
6763 -- Earnings Group Regular
6764 -- Earnings Policy Extra Element Information Points Assigned
6765 -- Daily Regular 8 Regular 1
6766 -- Daily Overtime 12 Overtime 1.5
6767 -- Daily DoubleTime 24 Double Time 2
6768 -- Weekly Regular 40 Holiday 0
6769 -- Weekly Overtime 999
6770 -- Special - 7 Overtime 8
6771 -- Special - 7 DoubleTime 24
6772 -- Holiday Holiday 8
6773 --
6774 -- Earnings Policy Explosion would be ,if working 14 hrs a day :
6775 -- Say Monday -14 Hours
6776 -- 8/4/2(Daily Rule) -Points:(8x1)+(4x1.5)+(2x2)= 18
6777 -- 14/0/0 (Weekly Rule)-Points:(14x1) = 14
6778 -- Use the rule that produces the higher number of points.
6779 -- Special rule is only applicable if consecutive days have been reached.
6780 -- It then acts like a daily rule in that its base can be overridden by the
6781 -- weekly cap until the special hours cap is hit.
6782 -- returns 0 for success, 2 for error
6783 -- Set hours_left_to_pay = 0 when last record from the array is fetched
6784 BEGIN
6785 g_debug := hr_utility.debug_enabled;
6786
6787 IF g_debug
6788 THEN
6789 l_proc := 'hxt_time_detail.use_points_to_select_rule_hrs';
6790 hr_utility.set_location (l_proc, 10);
6791 END IF;
6792
6793 -- Populate the g_daily_earn_category plsql table with element type, hrs
6794 -- and earning Category for each element.
6795 FOR daily_categories IN daily_earning_rules (g_ep_id)
6796 LOOP
6797 IF g_debug
6798 THEN
6799 hr_utility.set_location (l_proc, 15);
6800 hr_utility.TRACE ( 'daily_categories.hours :'
6801 || daily_categories.hours
6802 );
6803 hr_utility.TRACE ( 'daily_categories.element_type_id :'
6804 || daily_categories.element_type_id
6805 );
6806 END IF;
6807
6808 l_category_index := l_category_index + 1;
6809 g_daily_earn_category (l_category_index).element_type_id :=
6810 daily_categories.element_type_id;
6811 g_daily_earn_category (l_category_index).hours :=
6812 daily_categories.hours;
6813
6814 IF l_category_index = 1
6815 THEN
6816 IF g_debug
6817 THEN
6818 hr_utility.set_location (l_proc, 20);
6819 END IF;
6820
6821 g_daily_earn_category (l_category_index).earning_category :=
6822 'REG';
6823 ELSIF l_category_index = 2
6824 THEN
6825 IF g_debug
6826 THEN
6827 hr_utility.set_location (l_proc, 25);
6828 END IF;
6829
6830 g_daily_earn_category (l_category_index).earning_category :=
6831 'OVT';
6832 ELSIF l_category_index = 3
6833 THEN
6834 IF g_debug
6835 THEN
6836 hr_utility.set_location (l_proc, 30);
6837 END IF;
6838
6839 g_daily_earn_category (l_category_index).earning_category :=
6840 'DT';
6841 END IF;
6842
6843 IF g_debug
6844 THEN
6845 hr_utility.set_location (l_proc, 35);
6846 END IF;
6847 END LOOP;
6848
6849 IF g_debug
6850 THEN
6851 hr_utility.set_location (l_proc, 40);
6852 END IF;
6853
6854 FOR i IN 1 .. g_daily_earn_category.COUNT
6855 LOOP
6856 IF g_debug
6857 THEN
6858 hr_utility.set_location (l_proc, 45);
6859 hr_utility.TRACE ( 'daily_element_type_id:'
6860 || g_daily_earn_category (i).element_type_id
6861 );
6862 hr_utility.TRACE ( 'daily_hours:'
6863 || g_daily_earn_category (i).hours
6864 );
6865 hr_utility.TRACE ( 'daily_earning_category:'
6866 || g_daily_earn_category (i).earning_category
6867 );
6868 hr_utility.set_location (l_proc, 50);
6869 END IF;
6870 END LOOP;
6871
6872 -- Populate the g_weekly_earn_category plsql table with element type, hrs
6873 -- and earning Category for each element.
6874 FOR weekly_categories IN weekly_earning_rules (g_ep_id)
6875 LOOP
6876 IF g_debug
6877 THEN
6878 hr_utility.set_location (l_proc, 55);
6879 hr_utility.TRACE ( 'weekly_categories.hours :'
6880 || weekly_categories.hours
6881 );
6882 hr_utility.TRACE ( 'weekly_categories.element_type_id :'
6883 || weekly_categories.element_type_id
6884 );
6885 END IF;
6886
6887 l_wkl_category_index := l_wkl_category_index + 1;
6888 g_weekly_earn_category (l_wkl_category_index).element_type_id :=
6889 weekly_categories.element_type_id;
6890 g_weekly_earn_category (l_wkl_category_index).hours :=
6891 weekly_categories.hours;
6892
6893 IF l_wkl_category_index = 1
6894 THEN
6895 IF g_debug
6896 THEN
6897 hr_utility.set_location (l_proc, 60);
6898 END IF;
6899
6900 g_weekly_earn_category (l_wkl_category_index).earning_category :=
6901 'REG';
6902 l_weekly_reg_cap :=
6903 g_weekly_earn_category (l_wkl_category_index).hours;
6904
6905 IF g_weekly_earn_category (1).element_type_id <>
6906 g_daily_earn_category (1).element_type_id
6907 THEN
6908 use_weekly_reg := 'Y';
6909 END IF;
6910 ELSIF l_wkl_category_index = 2
6911 THEN
6912 IF g_debug
6913 THEN
6914 hr_utility.set_location (l_proc, 65);
6915 END IF;
6916
6917 g_weekly_earn_category (l_wkl_category_index).earning_category :=
6918 'OVT';
6919
6920 IF g_weekly_earn_category (2).element_type_id <>
6921 g_daily_earn_category (2).element_type_id
6922 THEN
6923 use_weekly_ot := 'Y';
6924 END IF;
6925 ELSIF l_wkl_category_index = 3
6926 THEN
6927 IF g_debug
6928 THEN
6929 hr_utility.set_location (l_proc, 70);
6930 END IF;
6931
6932 g_weekly_earn_category (l_wkl_category_index).earning_category :=
6933 'DT';
6934
6935 IF g_weekly_earn_category (3).element_type_id <>
6936 g_daily_earn_category (3).element_type_id
6937 THEN
6938 use_weekly_dt := 'Y';
6939 END IF;
6940 END IF;
6941
6942 IF g_debug
6943 THEN
6944 hr_utility.set_location (l_proc, 75);
6945 END IF;
6946 END LOOP;
6947
6948 IF g_debug
6949 THEN
6950 hr_utility.set_location (l_proc, 80);
6951 END IF;
6952
6953 FOR i IN 1 .. g_weekly_earn_category.COUNT
6954 LOOP
6955 IF g_debug
6956 THEN
6957 hr_utility.set_location (l_proc, 85);
6958 hr_utility.TRACE ( 'weekly_element_type_id:'
6959 || g_weekly_earn_category (i).element_type_id
6960 );
6961 hr_utility.TRACE ( 'weekly_hours:'
6962 || g_weekly_earn_category (i).hours
6963 );
6964 hr_utility.TRACE ( 'weekly_earning_category:'
6965 || g_weekly_earn_category (i).earning_category
6966 );
6967 hr_utility.set_location (l_proc, 90);
6968 END IF;
6969 END LOOP;
6970
6971 IF g_debug
6972 THEN
6973 hr_utility.set_location (l_proc, 100);
6974 hr_utility.TRACE ('g_explosion_to_use :' || g_explosion_to_use);
6975 END IF;
6976
6977 IF g_explosion_to_use IS NOT NULL
6978 THEN
6979 IF g_debug
6980 THEN
6981 hr_utility.set_location (l_proc, 110);
6982 END IF;
6983
6984 IF g_explosion_to_use = 'SPC'
6985 THEN
6986 IF g_debug
6987 THEN
6988 hr_utility.set_location (l_proc, 120);
6989 END IF;
6990
6991 FOR i IN g_special_explosion.FIRST .. g_special_explosion.LAST
6992 LOOP
6993 IF g_debug
6994 THEN
6995 hr_utility.set_location (l_proc, 130);
6996 hr_utility.TRACE ('i:' || i);
6997 hr_utility.TRACE
6998 ( 'g_special_explosion(i).element_type_id:'
6999 || g_special_explosion (i).element_type_id
7000 );
7001 END IF;
7002 END LOOP;
7003
7004 IF g_debug
7005 THEN
7006 hr_utility.set_location (l_proc, 140);
7007 END IF;
7008
7009 g_count := g_count + 1;
7010
7011 IF g_debug
7012 THEN
7013 hr_utility.TRACE ('g_count:' || g_count);
7014 END IF;
7015
7016 p_error_code := 0;
7017 p_rule_to_pay := 'SPC';
7018 p_hours_to_pay_this_rule :=
7019 g_special_explosion (g_count).hours_to_pay;
7020 p_element_type_id :=
7021 g_special_explosion (g_count).element_type_id;
7022
7023 IF g_debug
7024 THEN
7025 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
7026 || p_hours_to_pay_this_rule
7027 );
7028 hr_utility.TRACE ( 'p_element_type_id :'
7029 || p_element_type_id
7030 );
7031 END IF;
7032
7033 IF g_count = g_special_explosion.COUNT
7034 THEN
7035 IF g_debug
7036 THEN
7037 hr_utility.set_location (l_proc, 150);
7038 END IF;
7039
7040 hours_left_to_pay := 0;
7041 g_explosion_to_use := NULL;
7042 g_count := 0;
7043 special_day := FALSE;
7044
7045 IF g_debug
7046 THEN
7047 hr_utility.TRACE ( 'hours_left_to_pay :'
7048 || hours_left_to_pay
7049 );
7050 hr_utility.TRACE ( 'g_explosion_to_use:'
7051 || g_explosion_to_use
7052 );
7053 END IF;
7054 END IF;
7055
7056 RETURN;
7057 ELSIF g_explosion_to_use = 'COMBO'
7058 THEN
7059 IF g_debug
7060 THEN
7061 hr_utility.set_location (l_proc, 160);
7062 END IF;
7063
7064 FOR i IN
7065 g_dy_wk_combo_explosion.FIRST .. g_dy_wk_combo_explosion.LAST
7066 LOOP
7067 IF g_debug
7068 THEN
7069 hr_utility.TRACE ('i:' || i);
7070 hr_utility.TRACE
7071 ( 'g_dy_wk_combo_explosion(i).element_type_id:'
7072 || g_dy_wk_combo_explosion (i).element_type_id
7073 );
7074 END IF;
7075 END LOOP;
7076
7077 IF g_debug
7078 THEN
7079 hr_utility.set_location (l_proc, 165);
7080 END IF;
7081
7082 g_count := g_count + 1;
7083
7084 IF g_debug
7085 THEN
7086 hr_utility.TRACE ('g_count:' || g_count);
7087 END IF;
7088
7089 p_error_code := 0;
7090 p_rule_to_pay := 'DAY';
7091 p_hours_to_pay_this_rule :=
7092 g_dy_wk_combo_explosion (g_count).hours_to_pay;
7093 p_element_type_id :=
7094 g_dy_wk_combo_explosion (g_count).element_type_id;
7095
7096 IF g_debug
7097 THEN
7098 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
7099 || p_hours_to_pay_this_rule
7100 );
7101 hr_utility.TRACE ( 'p_element_type_id :'
7102 || p_element_type_id
7103 );
7104 END IF;
7105
7106 IF g_count = g_dy_wk_combo_explosion.COUNT
7107 THEN
7108 IF g_debug
7109 THEN
7110 hr_utility.set_location (l_proc, 170);
7111 END IF;
7112
7113 hours_left_to_pay := 0;
7114 g_explosion_to_use := NULL;
7115 g_count := 0;
7116
7117 IF g_debug
7118 THEN
7119 hr_utility.TRACE ( 'hours_left_to_pay :'
7120 || hours_left_to_pay
7121 );
7122 hr_utility.TRACE ( 'g_explosion_to_use:'
7123 || g_explosion_to_use
7124 );
7125 END IF;
7126 END IF;
7127
7128 RETURN;
7129 ELSIF g_explosion_to_use = 'DAILY'
7130 THEN
7131 IF g_debug
7132 THEN
7133 hr_utility.set_location (l_proc, 175);
7134 END IF;
7135
7136 FOR i IN g_daily_explosion.FIRST .. g_daily_explosion.LAST
7137 LOOP
7138 IF g_debug
7139 THEN
7140 hr_utility.TRACE ('i:' || i);
7141 hr_utility.TRACE
7142 ( 'g_daily_explosion(i).element_type_id:'
7143 || g_daily_explosion (i).element_type_id
7144 );
7145 END IF;
7146 END LOOP;
7147
7148 IF g_debug
7149 THEN
7150 hr_utility.set_location (l_proc, 180);
7151 END IF;
7152
7153 g_count := g_count + 1;
7154
7155 IF g_debug
7156 THEN
7157 hr_utility.TRACE ('g_count:' || g_count);
7158 END IF;
7159
7160 p_error_code := 0;
7161 p_rule_to_pay := 'DAY';
7162 p_hours_to_pay_this_rule :=
7163 g_daily_explosion (g_count).hours_to_pay;
7164 p_element_type_id :=
7165 g_daily_explosion (g_count).element_type_id;
7166
7167 IF g_debug
7168 THEN
7169 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
7170 || p_hours_to_pay_this_rule
7171 );
7172 hr_utility.TRACE ( 'p_element_type_id :'
7173 || p_element_type_id
7174 );
7175 END IF;
7176
7177 IF g_count = g_daily_explosion.COUNT
7178 THEN
7179 IF g_debug
7180 THEN
7181 hr_utility.set_location (l_proc, 185);
7182 END IF;
7183
7184 hours_left_to_pay := 0;
7185 g_explosion_to_use := NULL;
7186 g_count := 0;
7187
7188 IF g_debug
7189 THEN
7190 hr_utility.TRACE ( 'hours_left_to_pay :'
7191 || hours_left_to_pay
7192 );
7193 hr_utility.TRACE ( 'g_explosion_to_use:'
7194 || g_explosion_to_use
7195 );
7196 END IF;
7197 END IF;
7198
7199 RETURN;
7200 ELSIF g_explosion_to_use = 'WEEKLY'
7201 THEN
7202 IF g_debug
7203 THEN
7204 hr_utility.set_location (l_proc, 190);
7205 END IF;
7206
7207 FOR i IN g_weekly_explosion.FIRST .. g_weekly_explosion.LAST
7208 LOOP
7209 IF g_debug
7210 THEN
7211 hr_utility.TRACE ('i:' || i);
7212 hr_utility.TRACE
7213 ( 'g_weekly_explosion(i).element_type_id:'
7214 || g_weekly_explosion (i).element_type_id
7215 );
7216 END IF;
7217 END LOOP;
7218
7219 IF g_debug
7220 THEN
7221 hr_utility.set_location (l_proc, 200);
7222 END IF;
7223
7224 g_count := g_count + 1;
7225
7226 IF g_debug
7227 THEN
7228 hr_utility.TRACE ('g_count:' || g_count);
7229 END IF;
7230
7231 p_error_code := 0;
7232 p_rule_to_pay := 'WKL';
7233 p_hours_to_pay_this_rule :=
7234 g_weekly_explosion (g_count).hours_to_pay;
7235 p_element_type_id :=
7236 g_weekly_explosion (g_count).element_type_id;
7237
7238 IF g_debug
7239 THEN
7240 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
7241 || p_hours_to_pay_this_rule
7242 );
7243 hr_utility.TRACE ( 'p_element_type_id :'
7244 || p_element_type_id
7245 );
7246 END IF;
7247
7248 IF g_count = g_weekly_explosion.COUNT
7249 THEN
7250 IF g_debug
7251 THEN
7252 hr_utility.set_location (l_proc, 210);
7253 END IF;
7254
7255 hours_left_to_pay := 0;
7256 g_explosion_to_use := NULL;
7257 g_count := 0;
7258
7259 IF g_debug
7260 THEN
7261 hr_utility.TRACE ( 'hours_left_to_pay :'
7262 || hours_left_to_pay
7263 );
7264 hr_utility.TRACE ( 'g_explosion_to_use:'
7265 || g_explosion_to_use
7266 );
7267 hr_utility.TRACE ('g_count :' || g_count);
7268 END IF;
7269 END IF;
7270
7271 RETURN;
7272 END IF;
7273 ELSIF g_explosion_to_use IS NULL
7274 THEN
7275 IF g_debug
7276 THEN
7277 hr_utility.set_location (l_proc, 220);
7278 hr_utility.TRACE ('g_ep_id :' || g_ep_id);
7279 END IF;
7280
7281 IF consecutive_days_reached = TRUE
7282 THEN
7283 IF g_debug
7284 THEN
7285 hr_utility.set_location (l_proc, 230);
7286 END IF;
7287
7288 -- Get the contiguous hours worked on the special day
7289 -- Following code changed to fix 2839573
7290 spc_hours_paid := NVL (previous_detail_hours_day, 0);
7291
7292 IF g_debug
7293 THEN
7294 hr_utility.TRACE ('spc_hours_paid :' || spc_hours_paid);
7295 hr_utility.TRACE ('g_hours :' || g_hours);
7296 END IF;
7297
7298 total_hrs_worked_on_spc := g_hours + NVL (spc_hours_paid, 0);
7299
7300 IF g_debug
7301 THEN
7302 hr_utility.TRACE ( 'total_hrs_worked_on_spc :'
7303 || total_hrs_worked_on_spc
7304 );
7305 END IF;
7306
7307 /*
7308 IF g_time_in IS NOT NULL
7309 THEN
7310 hr_utility.set_location (l_proc, 240);
7311 spc_hours_paid :=
7312 contig_hours_worked (g_date_worked, g_egt_id, g_tim_id);
7313 hr_utility.TRACE ('spc_hours_paid :' || spc_hours_paid);
7314 hr_utility.TRACE ('g_hours :' || g_hours);
7315 total_hrs_worked_on_spc :=
7316 g_hours + NVL (spc_hours_paid, 0);
7317 hr_utility.TRACE ( 'total_hrs_worked_on_spc :'
7318 || total_hrs_worked_on_spc
7319 );
7320 ELSE
7321 hr_utility.set_location (l_proc, 250);
7322 OPEN all_detail_hours_spc (g_date_worked,
7323 g_person_id,
7324 g_tim_id
7325 );
7326
7327 FETCH all_detail_hours_spc
7328 INTO spc_hours_paid;
7329
7330 hr_utility.TRACE ('spc_hours_paid :' || spc_hours_paid);
7331 CLOSE all_detail_hours_spc;
7332
7333 hr_utility.TRACE ('g_hours :' || g_hours);
7334 total_hrs_worked_on_spc := g_hours + NVL (spc_hours_paid, 0);
7335 hr_utility.TRACE ( 'total_hrs_worked_on_spc :'
7336 || total_hrs_worked_on_spc
7337 );
7338 END IF;
7339 */
7340 IF g_debug
7341 THEN
7342 hr_utility.set_location (l_proc, 240);
7343 END IF;
7344
7345 -- Commented out the following as the fix for 2828201 was to do with
7346 -- the total hours not being calculated correctly when entering time
7347 -- as HOURS rather than time in/time out.
7348 -- This was fixed by adding the cursor all_detail_hours_spc to calculate
7349 -- the total hours worked on the SPC day when entering time as straight
7350 -- hours, whether hours entered for the SPC day being entered on a single
7351 -- row(bug 2828201) or multiple rows(bug 2839573).
7352
7353 -- Moved outside loop for bug 2828201
7354 -- total_hrs_worked_on_spc := g_hours + spc_hours_paid;
7355 -- END IF;
7356 -- total_hrs_worked_on_spc := g_hours + NVL(spc_hours_paid,0);
7357
7358 -- next line changed as follows for bug 2852695
7359 -- OPEN special_earning_rules(g_ep_id, consec_days_worked);
7360 OPEN special_earning_rules (g_ep_id,
7361 consec_days_worked,
7362 spc_hours_paid
7363 );
7364
7365 LOOP
7366 IF g_debug
7367 THEN
7368 hr_utility.set_location (l_proc, 270);
7369 END IF;
7370
7371 FETCH special_earning_rules
7372 INTO spc_daily_earning_cap, spc_element_type_id,
7373 special_days;
7374
7375 IF g_debug
7376 THEN
7377 hr_utility.TRACE ( 'spc_daily_earning_cap :'
7378 || spc_daily_earning_cap
7379 );
7380 hr_utility.TRACE ( 'spc_element_type_id :'
7381 || spc_element_type_id
7382 );
7383 hr_utility.TRACE ( 'special_days :'
7384 || special_days
7385 );
7386 hr_utility.TRACE ( 'spc_hours_paid :'
7387 || spc_hours_paid
7388 );
7389 hr_utility.TRACE ('g_hours :'
7390 || g_hours
7391 );
7392 hr_utility.TRACE ( 'total_hrs_worked_on_spc :'
7393 || total_hrs_worked_on_spc
7394 );
7395 END IF;
7396
7397 EXIT WHEN spc_hours_paid = total_hrs_worked_on_spc
7398 OR special_earning_rules%NOTFOUND;
7399
7400 IF special_earning_rules%FOUND
7401 THEN
7402 IF g_debug
7403 THEN
7404 hr_utility.set_location (l_proc, 280);
7405 END IF;
7406
7407 special_day := TRUE;
7408 g_explosion_to_use := 'SPC';
7409 END IF;
7410
7411 IF spc_hours_paid < total_hrs_worked_on_spc
7412 THEN
7413 IF g_debug
7414 THEN
7415 hr_utility.set_location (l_proc, 290);
7416 END IF;
7417
7418 spc_hours :=
7419 LEAST ((spc_daily_earning_cap - spc_hours_paid),
7420 (total_hrs_worked_on_spc - spc_hours_paid
7421 )
7422 );
7423 l_spc_index := l_spc_index + 1;
7424 g_special_explosion (l_spc_index).element_type_id :=
7425 spc_element_type_id;
7426 g_special_explosion (l_spc_index).hours_to_pay :=
7427 spc_hours;
7428
7429 FOR i IN 1 .. g_special_explosion.COUNT
7430 LOOP
7431 IF g_debug
7432 THEN
7433 hr_utility.TRACE
7434 ( 'spc_element_type_id:'
7435 || g_special_explosion (i).element_type_id
7436 );
7437 hr_utility.TRACE
7438 ( 'hours_to_pay in plsql table:'
7439 || g_special_explosion (i).hours_to_pay
7440 );
7441 END IF;
7442 END LOOP;
7443
7444 spc_hours_paid := spc_hours_paid + spc_hours;
7445
7446 IF g_debug
7447 THEN
7448 hr_utility.TRACE ('spc_hours_paid:' || spc_hours_paid);
7449 END IF;
7450 END IF;
7451
7452 IF g_debug
7453 THEN
7454 hr_utility.set_location (l_proc, 300);
7455 END IF;
7456 END LOOP;
7457
7458 IF g_debug
7459 THEN
7460 hr_utility.set_location (l_proc, 310);
7461 END IF;
7462
7463 CLOSE special_earning_rules;
7464 END IF;
7465
7466 IF special_day = FALSE
7467 THEN
7468 IF g_debug
7469 THEN
7470 hr_utility.set_location (l_proc, 320);
7471 END IF;
7472
7473 --
7474 -----------------------------BEGIN Daily Points Calculation---------------------
7475 --
7476 OPEN daily_earning_rules (g_ep_id);
7477
7478 IF g_debug
7479 THEN
7480 hr_utility.set_location (l_proc, 330);
7481 END IF;
7482
7483 -- Commented out the following. Instead calling the adjust_for_hdp funtion
7484 -- to determine the hours that are left to be paid, since hours need to be
7485 -- deducted based on the hour deduction policy if assigned to the employee.
7486 -- hours_left := g_hours;
7487 -- hours_left := adjust_for_hdp (p_hours_worked, error_code);
7488 hours_left := p_hours_worked;
7489
7490 IF g_debug
7491 THEN
7492 hr_utility.TRACE ('hours_left :' || hours_left);
7493 hr_utility.TRACE ('l_override_hrs :' || l_override_hrs);
7494 hr_utility.TRACE ( 'g_date_worked :'
7495 || TO_CHAR (g_date_worked,
7496 'DD-MON-YYYY HH24:MI:SS'
7497 )
7498 );
7499 hr_utility.TRACE ('g_egt_id :' || g_egt_id);
7500 hr_utility.TRACE ('g_tim_id :' || g_tim_id);
7501 END IF;
7502
7503 overtime_hoursoverride (g_date_worked,
7504 g_egt_id,
7505 g_tim_id,
7506 l_override_hrs,
7507 l_override_element
7508 );
7509
7510 IF g_debug
7511 THEN
7512 hr_utility.TRACE ('l_override_hrs :' || l_override_hrs);
7513 hr_utility.TRACE ( 'l_override_element :'
7514 || l_override_element
7515 );
7516 END IF;
7517
7518 LOOP
7519 IF g_debug
7520 THEN
7521 hr_utility.set_location (l_proc, 340);
7522 END IF;
7523
7524 hrs_already_paid := FALSE;
7525 h := h + 1;
7526
7527 FETCH daily_earning_rules
7528 INTO daily_earning_cap, daily_element_type_id;
7529
7530 IF g_debug
7531 THEN
7532 hr_utility.TRACE ( 'daily_earning_cap :'
7533 || daily_earning_cap
7534 );
7535 hr_utility.TRACE ( 'daily_element_type_id :'
7536 || daily_element_type_id
7537 );
7538 END IF;
7539
7540 IF h = 1
7541 THEN
7542 IF g_debug
7543 THEN
7544 hr_utility.set_location (l_proc, 350);
7545 END IF;
7546
7547 hours_paid_for_day := NVL (previous_detail_hours_day, 0);
7548 --hours_paid_for_day:=hours_paid_for_day-2;
7549 -- Changed the following to take into account the hour deduction policy.
7550 -- Total hours to pay should be the hours left after deducting the hours
7551 -- based on the hour deduction policy.
7552 -- total_hours_to_pay := g_hours + hours_paid_for_day;
7553 total_hours_to_pay := hours_left + hours_paid_for_day;
7554 END IF;
7555
7556 IF g_debug
7557 THEN
7558 hr_utility.set_location (l_proc, 360);
7559 hr_utility.TRACE ( 'hours_paid_for_day :'
7560 || hours_paid_for_day
7561 );
7562 hr_utility.TRACE ('g_hours :' || g_hours);
7563 hr_utility.TRACE ( 'total_hours_to_pay :'
7564 || total_hours_to_pay
7565 );
7566 END IF;
7567
7568 EXIT WHEN hours_left = 0 AND h > 1;
7569
7570 IF g_debug
7571 THEN
7572 hr_utility.set_location (l_proc, 370);
7573 END IF;
7574
7575 /* IF hours_paid_for_day < total_hours_to_pay THEN
7576 hr_utility.set_location(l_proc,100);
7577 hours_for_points := LEAST( (daily_earning_cap - hours_paid_for_day)
7578 ,(g_hours - hours_paid_for_day) );
7579 hr_utility.trace('hours_for_points :'||hours_for_points);
7580 */
7581 /* IF hours_paid_for_day < daily_earning_cap THEN
7582 hours_for_points :=LEAST(g_hours,(daily_earning_cap - hours_paid_for_day));
7583 hr_utility.set_location(l_proc,100);
7584 hr_utility.trace('hours_for_points :'||hours_for_points);
7585 */
7586 IF g_debug
7587 THEN
7588 hr_utility.TRACE ('hours_left:' || hours_left);
7589 hr_utility.TRACE ( 'hours_paid_for_day:'
7590 || hours_paid_for_day
7591 );
7592 hr_utility.TRACE ('l_override_hrs:' || l_override_hrs);
7593 hr_utility.TRACE ( 'daily_earning_cap:'
7594 || daily_earning_cap
7595 );
7596 END IF;
7597
7598 IF hours_left >= 0
7599 THEN
7600 IF g_debug
7601 THEN
7602 hr_utility.set_location (l_proc, 380);
7603 END IF;
7604
7605 IF (hours_paid_for_day - l_override_hrs) >=
7606 daily_earning_cap
7607 THEN
7608 -- Commented the next line for bug 2853355 since l_daily_total is not
7609 -- used anymore.
7610 -- OR l_daily_total >= daily_earning_cap THEN
7611 IF g_debug
7612 THEN
7613 hr_utility.set_location (l_proc, 390);
7614 END IF;
7615
7616 -- next line changed for bug 2822172
7617 OPEN daily_earning_rules2 (g_ep_id,
7618 hours_paid_for_day
7619 - l_override_hrs
7620 );
7621
7622 -- daily_earning_cap);
7623 FETCH daily_earning_rules2
7624 INTO daily_earning_cap2, daily_element_type_id;
7625
7626 IF g_debug
7627 THEN
7628 hr_utility.TRACE ( 'daily_earning_cap2 :'
7629 || daily_earning_cap2
7630 );
7631 hr_utility.TRACE ( 'daily_element_type_id :'
7632 || daily_element_type_id
7633 );
7634 END IF;
7635
7636 CLOSE daily_earning_rules2;
7637
7638 hours_for_points :=
7639 LEAST ((daily_earning_cap2 - hours_paid_for_day),
7640 hours_left
7641 );
7642
7643 -- Added the following for Bug:5095198
7644
7645 IF daily_element_type_id = l_override_element
7646 AND hours_for_points <= l_override_hrs
7647 THEN
7648 IF g_debug
7649 THEN
7650 hr_utility.TRACE ( 'l_override_hrs:'
7651 || l_override_hrs
7652 );
7653 hr_utility.TRACE ( 'daily_earning_cap2:'
7654 || daily_earning_cap2
7655 );
7656 hr_utility.TRACE ( 'daily_earning_cap:'
7657 || daily_earning_cap
7658 );
7659 END IF;
7660
7661 IF l_override_hrs >=
7662 daily_earning_cap2 - daily_earning_cap
7663 THEN
7664 IF g_debug
7665 THEN
7666 hr_utility.set_location (l_proc, 390.1);
7667 END IF;
7668
7669 hrs_already_paid := TRUE;
7670 hours_for_points := 0;
7671 segment_points := 0;
7672 END IF;
7673 END IF;
7674
7675 IF g_debug
7676 THEN
7677 hr_utility.TRACE ( 'hours_for_points :'
7678 || hours_for_points
7679 );
7680 END IF;
7681 ELSE
7682 IF g_debug
7683 THEN
7684 hr_utility.set_location (l_proc, 400);
7685 END IF;
7686
7687 IF daily_element_type_id = l_override_element
7688 THEN
7689 IF hours_left <=
7690 ( daily_earning_cap
7691 - (hours_paid_for_day - l_override_hrs)
7692 )
7693 THEN
7694 IF g_debug
7695 THEN
7696 hr_utility.set_location (l_proc, 400.1);
7697 END IF;
7698
7699 hours_for_points :=
7700 LEAST (hours_left,
7701 ( daily_earning_cap
7702 - (hours_paid_for_day)
7703 )
7704 );
7705 ELSE
7706 IF g_debug
7707 THEN
7708 hr_utility.set_location (l_proc, 400.2);
7709 END IF;
7710
7711 hours_for_points :=
7712 LEAST (hours_left,
7713 ( daily_earning_cap
7714 - (hours_paid_for_day
7715 - l_override_hrs
7716 )
7717 )
7718 );
7719 END IF;
7720 ELSE
7721 IF g_debug
7722 THEN
7723 hr_utility.set_location (l_proc, 400.3);
7724 END IF;
7725
7726 hours_for_points :=
7727 LEAST (hours_left,
7728 ( daily_earning_cap
7729 - (hours_paid_for_day - l_override_hrs
7730 )
7731 )
7732 );
7733 END IF;
7734
7735 IF g_debug
7736 THEN
7737 hr_utility.TRACE ( 'hours_for_points :'
7738 || hours_for_points
7739 );
7740 END IF;
7741
7742 -- Say for example entering time as follows:
7743 -- hrs element
7744 -- 13 (no override)
7745 -- 2 OT
7746 -- This should explode to
7747 -- 13 hrs -> 8/2/3
7748 -- 2 OT -> 2
7749 -- From the above logic we get the hours for the 2nd
7750 -- Daily Cap element i.e., LEAST(5,(12-(10 - 2))
7751 -- i.e., 4 hrs OT
7752 -- But since 2 hrs OT already overriden => (4 - 2)OT left
7753 -- to be paid
7754 IF daily_element_type_id = l_override_element
7755 AND hours_for_points > l_override_hrs
7756 THEN
7757 IF g_debug
7758 THEN
7759 hr_utility.set_location (l_proc, 401);
7760 END IF;
7761
7762 hrs_already_paid := FALSE;
7763 hours_for_points :=
7764 hours_for_points - l_override_hrs;
7765 ELSIF daily_element_type_id = l_override_element
7766 AND hours_for_points <= l_override_hrs
7767 THEN
7768 IF g_debug
7769 THEN
7770 hr_utility.TRACE ( 'l_override_hrs:'
7771 || l_override_hrs
7772 );
7773 hr_utility.TRACE ( 'daily_earning_cap:'
7774 || daily_earning_cap
7775 );
7776 hr_utility.TRACE ( 'prev_daily_cap:'
7777 || prev_daily_cap
7778 );
7779 END IF;
7780
7781 IF l_override_hrs >=
7782 daily_earning_cap - prev_daily_cap
7783 THEN
7784 IF g_debug
7785 THEN
7786 hr_utility.set_location (l_proc, 402);
7787 END IF;
7788
7789 hrs_already_paid := TRUE;
7790 hours_for_points := 0;
7791 segment_points := 0;
7792 ELSE
7793 IF g_debug
7794 THEN
7795 hr_utility.set_location (l_proc, 402.1);
7796 END IF;
7797
7798 hrs_already_paid := FALSE;
7799 END IF;
7800 END IF;
7801
7802 IF g_debug
7803 THEN
7804 hr_utility.set_location (l_proc, 403);
7805 hr_utility.TRACE ( 'hours_for_points :'
7806 || hours_for_points
7807 );
7808 END IF;
7809 END IF;
7810
7811 IF g_debug
7812 THEN
7813 hr_utility.set_location (l_proc, 405);
7814 hr_utility.TRACE ('segment_points:' || segment_points);
7815 END IF;
7816
7817 IF hrs_already_paid = FALSE
7818 THEN
7819 IF g_debug
7820 THEN
7821 hr_utility.set_location (l_proc, 410);
7822 END IF;
7823
7824 hours_left := (hours_left - (hours_for_points));
7825
7826 IF g_debug
7827 THEN
7828 hr_utility.TRACE ('hours_left :' || hours_left);
7829 END IF;
7830
7831 SELECT NVL (points_assigned, 0)
7832 INTO l_points_assigned
7833 FROM hxt_add_elem_info_f aei
7834 WHERE aei.element_type_id = daily_element_type_id
7835 AND g_date_worked BETWEEN aei.effective_start_date
7836 AND aei.effective_end_date;
7837
7838 IF g_debug
7839 THEN
7840 hr_utility.TRACE ( 'l_points_assigned :'
7841 || l_points_assigned
7842 );
7843 END IF;
7844
7845 segment_points := hours_for_points * l_points_assigned;
7846
7847 IF g_debug
7848 THEN
7849 hr_utility.TRACE ( 'segment_points :'
7850 || segment_points
7851 );
7852 END IF;
7853
7854 l_daily_index := l_daily_index + 1;
7855 g_daily_explosion (l_daily_index).element_type_id :=
7856 daily_element_type_id;
7857 g_daily_explosion (l_daily_index).hours_to_pay :=
7858 hours_for_points;
7859
7860 FOR i IN 1 .. g_daily_earn_category.COUNT
7861 LOOP
7862 IF g_debug
7863 THEN
7864 hr_utility.set_location (l_proc, 420);
7865 hr_utility.TRACE ( 'daily_element_type_id:'
7866 || daily_element_type_id
7867 );
7868 hr_utility.TRACE
7869 ( 'g_daily_earn_category(i).element_type_id:'
7870 || g_daily_earn_category (i).element_type_id
7871 );
7872 END IF;
7873
7874 IF g_daily_earn_category (i).element_type_id =
7875 daily_element_type_id
7876 THEN
7877 IF g_debug
7878 THEN
7879 hr_utility.set_location (l_proc, 430);
7880 END IF;
7881
7882 g_daily_explosion (l_daily_index).earning_category :=
7883 g_daily_earn_category (i).earning_category;
7884 END IF;
7885
7886 IF g_debug
7887 THEN
7888 hr_utility.set_location (l_proc, 440);
7889 END IF;
7890 END LOOP;
7891
7892 IF g_debug
7893 THEN
7894 hr_utility.set_location (l_proc, 450);
7895 END IF;
7896
7897 FOR i IN 1 .. g_daily_explosion.COUNT
7898 LOOP
7899 IF g_debug
7900 THEN
7901 hr_utility.set_location (l_proc, 460);
7902 hr_utility.TRACE
7903 ( 'daily_element_type_id:'
7904 || g_daily_explosion (i).element_type_id
7905 );
7906 hr_utility.TRACE
7907 ( 'hours_to_pay in plsql table:'
7908 || g_daily_explosion (i).hours_to_pay
7909 );
7910 hr_utility.set_location (l_proc, 470);
7911 END IF;
7912 END LOOP;
7913
7914 IF g_debug
7915 THEN
7916 hr_utility.set_location (l_proc, 480);
7917 END IF;
7918
7919 -- Added the following for bug 2853355.
7920 IF g_debug
7921 THEN
7922 hr_utility.set_location (l_proc, 490);
7923 hr_utility.TRACE ( 'hours_paid_for_day:'
7924 || hours_paid_for_day
7925 );
7926 hr_utility.TRACE ( 'hours_for_points:'
7927 || hours_for_points
7928 );
7929 hr_utility.TRACE ( 'l_override_hrs:'
7930 || l_override_hrs
7931 );
7932 END IF;
7933
7934 hours_paid_for_day :=
7935 hours_paid_for_day + hours_for_points;
7936
7937 IF g_debug
7938 THEN
7939 hr_utility.TRACE ( 'hours_paid_for_day:'
7940 || hours_paid_for_day
7941 );
7942 hr_utility.set_location (l_proc, 500);
7943 END IF;
7944 END IF;
7945 END IF;
7946
7947 IF g_debug
7948 THEN
7949 hr_utility.set_location (l_proc, 510);
7950 END IF;
7951
7952 total_daily_points := total_daily_points + segment_points;
7953
7954 IF g_debug
7955 THEN
7956 hr_utility.TRACE ( 'total_daily_points :'
7957 || total_daily_points
7958 );
7959 END IF;
7960
7961 prev_daily_cap := daily_earning_cap;
7962
7963 IF g_debug
7964 THEN
7965 hr_utility.TRACE ('prev_daily_cap:' || prev_daily_cap);
7966 END IF;
7967
7968 IF g_debug
7969 THEN
7970 hr_utility.TRACE ( 'total_hours_to_pay :'
7971 || total_hours_to_pay
7972 );
7973 hr_utility.TRACE ( 'hours_paid_for_day :'
7974 || hours_paid_for_day
7975 );
7976 END IF;
7977
7978 -- EXIT WHEN hours_paid_for_day = g_hours;
7979 -- EXIT WHEN total_hours_to_pay = hours_paid_for_day;
7980 IF g_debug
7981 THEN
7982 hr_utility.set_location (l_proc, 520);
7983 END IF;
7984 END LOOP;
7985
7986 IF g_debug
7987 THEN
7988 hr_utility.set_location (l_proc, 530);
7989 END IF;
7990
7991 CLOSE daily_earning_rules;
7992
7993 --
7994 ------------------------------END Daily Points calculation----------------------
7995 --
7996 --
7997 ---------------------------BEGIN Weekly Points Calculation----------------------
7998 --
7999 IF g_debug
8000 THEN
8001 hr_utility.TRACE ('use_weekly_REG:' || use_weekly_reg);
8002 hr_utility.TRACE ('use_weekly_OT:' || use_weekly_ot);
8003 hr_utility.TRACE ('use_weekly_DT:' || use_weekly_dt);
8004 hr_utility.TRACE ('l_weekly_reg_cap:' || l_weekly_reg_cap);
8005 END IF;
8006
8007 -- Initialize the variables before calculating the weekly points
8008 init_for_wkl_combine_pts_cal (use_weekly_reg,
8009 use_weekly_ot,
8010 use_weekly_dt,
8011 l_weekly_reg_cap,
8012 l_dy_wk_reg_elem_id,
8013 l_dy_wk_ovt_elem_id,
8014 l_dy_wk_dt_elem_id,
8015 use_daily_reg,
8016 use_daily_ot,
8017 use_daily_dt,
8018 l_reg_for_day,
8019 l_ovt_for_day,
8020 l_dt_for_day,
8021 wky_reg_incl_dy_reg_expl,
8022 l_weekly_reg_hrs
8023 );
8024
8025 IF g_debug
8026 THEN
8027 hr_utility.TRACE ( 'l_dy_wk_reg_elem_id:'
8028 || l_dy_wk_reg_elem_id
8029 );
8030 hr_utility.TRACE ( 'l_dy_wk_ovt_elem_id:'
8031 || l_dy_wk_ovt_elem_id
8032 );
8033 hr_utility.TRACE ('l_dy_wk_dt_elem_id:'
8034 || l_dy_wk_dt_elem_id
8035 );
8036 hr_utility.TRACE ('use_daily_reg:' || use_daily_reg);
8037 hr_utility.TRACE ('use_daily_ot:' || use_daily_ot);
8038 hr_utility.TRACE ('use_daily_dt:' || use_daily_dt);
8039 hr_utility.TRACE ('l_reg_for_day:' || l_reg_for_day);
8040 hr_utility.TRACE ('l_ovt_for_day:' || l_ovt_for_day);
8041 hr_utility.TRACE ('l_dt_for_day:' || l_dt_for_day);
8042 hr_utility.TRACE ( 'wky_reg_incl_dy_reg_expl:'
8043 || wky_reg_incl_dy_reg_expl
8044 );
8045 hr_utility.TRACE ('l_weekly_REG_hrs:' || l_weekly_reg_hrs);
8046 END IF;
8047
8048 OPEN weekly_earning_rules (g_ep_id);
8049
8050 IF g_debug
8051 THEN
8052 hr_utility.set_location (l_proc, 620);
8053 END IF;
8054
8055 -- Commented out the following. Instead calling the adjust_for_hdp funtion
8056 -- to determine the hours that are left to be paid, since hours need to be
8057 -- deducted based on the hour deduction policy if assigned to the employee.
8058 -- hours_left := g_hours;
8059 -- hours_left := adjust_for_hdp (p_hours_worked, error_code);
8060 hours_left := p_hours_worked;
8061
8062 IF g_debug
8063 THEN
8064 hr_utility.TRACE ('hours_left :' || hours_left);
8065 END IF;
8066
8067 -- line added for bug 2822172
8068 hours_for_points := 0;
8069
8070 LOOP
8071 IF g_debug
8072 THEN
8073 hr_utility.set_location (l_proc, 625);
8074 END IF;
8075
8076 j := j + 1;
8077
8078 FETCH weekly_earning_rules
8079 INTO weekly_earning_cap, weekly_element_type_id;
8080
8081 IF g_debug
8082 THEN
8083 hr_utility.TRACE ( 'weekly_earning_cap :'
8084 || weekly_earning_cap
8085 );
8086 hr_utility.TRACE ( 'weekly_element_type_id :'
8087 || weekly_element_type_id
8088 );
8089 END IF;
8090
8091 -- line commented for bug 2822172
8092 -- IF j = 1 THEN
8093 IF g_debug
8094 THEN
8095 hr_utility.set_location (l_proc, 630);
8096 hr_utility.TRACE ( 'get_weekly_total_prev_days:'
8097 || get_weekly_total_prev_days
8098 );
8099 hr_utility.TRACE ( 'previous_detail_hours_day:'
8100 || previous_detail_hours_day
8101 );
8102 hr_utility.TRACE ('hours_for_points:' || hours_for_points);
8103 END IF;
8104
8105 -- line changed for bug 2822172
8106 -- hours_paid_for_week := get_weekly_total;
8107 hours_paid_for_week :=
8108 get_weekly_total_prev_days
8109 + NVL (previous_detail_hours_day, 0)
8110 + hours_for_points;
8111
8112 -- line commented for bug 2822172
8113 -- END IF;
8114 IF g_debug
8115 THEN
8116 hr_utility.set_location (l_proc, 635);
8117 hr_utility.TRACE ( 'hours_paid_for_week :'
8118 || hours_paid_for_week
8119 );
8120 hr_utility.TRACE ('g_hours :' || g_hours);
8121 END IF;
8122
8123 -- Following condition modified for bug 3868995
8124 -- EXIT WHEN hours_left = 0;
8125 EXIT WHEN hours_left = 0 AND j > 1;
8126
8127 IF g_debug
8128 THEN
8129 hr_utility.set_location (l_proc, 640);
8130 END IF;
8131
8132 -- Following condition modified for bug 3868995
8133 -- IF hours_left > 0 THEN
8134 IF hours_left >= 0
8135 THEN
8136 IF g_debug
8137 THEN
8138 hr_utility.set_location (l_proc, 645);
8139 END IF;
8140
8141 IF (hours_paid_for_week - l_override_hrs) >=
8142 weekly_earning_cap
8143 OR l_weekly_total >= weekly_earning_cap
8144 THEN
8145 IF g_debug
8146 THEN
8147 hr_utility.set_location (l_proc, 650);
8148 END IF;
8149
8150 -- line changed for bug 2822172
8151 OPEN weekly_earning_rules2 (g_ep_id,
8152 hours_paid_for_week
8153 ); -- weekly_earning_cap);
8154
8155 FETCH weekly_earning_rules2
8156 INTO weekly_earning_cap2, weekly_element_type_id;
8157
8158 IF g_debug
8159 THEN
8160 hr_utility.TRACE ( 'weekly_earning_cap2 :'
8161 || weekly_earning_cap2
8162 );
8163 hr_utility.TRACE ( 'weekly_element_type_id :'
8164 || weekly_element_type_id
8165 );
8166 END IF;
8167
8168 CLOSE weekly_earning_rules2;
8169
8170 hours_for_points :=
8171 LEAST ((weekly_earning_cap2 - hours_paid_for_week
8172 ),
8173 hours_left
8174 );
8175
8176 -- ADDED BY MV TO AVOID INFINITE LOOP
8177 IF (hours_for_points = 0)
8178 THEN
8179 l_left_over_hours := hours_left;
8180 ELSE
8181 l_left_over_hours := 0;
8182 END IF;
8183
8184 -- I tried this first but it didn't work, it caused outer issues.
8185 -- hours_for_points := hours_left;
8186 -- END ADDED BY MV TO AVOID INFINITE LOOP
8187 IF g_debug
8188 THEN
8189 hr_utility.TRACE ( 'hours_for_points :'
8190 || hours_for_points
8191 );
8192 END IF;
8193 ELSE
8194 IF g_debug
8195 THEN
8196 hr_utility.set_location (l_proc, 655);
8197 END IF;
8198
8199 IF weekly_element_type_id = l_override_element
8200 THEN
8201 IF hours_left <=
8202 ( weekly_earning_cap
8203 - (hours_paid_for_week - l_override_hrs)
8204 )
8205 THEN
8206 IF g_debug
8207 THEN
8208 hr_utility.set_location (l_proc, 655.1);
8209 END IF;
8210
8211 hours_for_points :=
8212 LEAST (hours_left,
8213 ( weekly_earning_cap
8214 - (hours_paid_for_week)
8215 )
8216 );
8217 ELSE
8218 IF g_debug
8219 THEN
8220 hr_utility.set_location (l_proc, 655.2);
8221 END IF;
8222
8223 hours_for_points :=
8224 LEAST (hours_left,
8225 ( weekly_earning_cap
8226 - ( hours_paid_for_week
8227 - l_override_hrs
8228 )
8229 )
8230 );
8231 END IF;
8232 ELSE
8233 IF g_debug
8234 THEN
8235 hr_utility.set_location (l_proc, 655.3);
8236 END IF;
8237
8238 hours_for_points :=
8239 LEAST (hours_left,
8240 ( weekly_earning_cap
8241 - (hours_paid_for_week - l_override_hrs
8242 )
8243 )
8244 );
8245 END IF;
8246
8247 IF g_debug
8248 THEN
8249 hr_utility.TRACE ( 'hours_for_points :'
8250 || hours_for_points
8251 );
8252 END IF;
8253
8254 -- Say for example entering time as follows:
8255 -- hrs element
8256 -- 13 (no override)
8257 -- 2 OT
8258 -- This should explode to
8259 -- 13 hrs -> 8/2/3
8260 -- 2 OT -> 2
8261 -- From the above logic we get the hours for the 2nd
8262 -- Daily Cap element i.e., LEAST(5,(12-(10 - 2))
8263 -- i.e., 4 hrs OT
8264 -- But since 2 hrs OT already overriden => (4 - 2)OT left
8265 -- to be paid
8266 IF weekly_element_type_id = l_override_element
8267 AND hours_for_points > l_override_hrs
8268 THEN
8269 IF g_debug
8270 THEN
8271 hr_utility.set_location (l_proc, 656);
8272 END IF;
8273
8274 hrs_already_paid := FALSE;
8275 hours_for_points :=
8276 hours_for_points - l_override_hrs;
8277 ELSIF weekly_element_type_id = l_override_element
8278 AND hours_for_points <= l_override_hrs
8279 THEN
8280 IF g_debug
8281 THEN
8282 hr_utility.TRACE ( 'l_override_hrs:'
8283 || l_override_hrs
8284 );
8285 hr_utility.TRACE ( 'weekly_earning_cap:'
8286 || weekly_earning_cap
8287 );
8288 hr_utility.TRACE ( 'prev_weekly_cap:'
8289 || prev_weekly_cap
8290 );
8291 END IF;
8292
8293 IF l_override_hrs >=
8294 weekly_earning_cap - prev_weekly_cap
8295 THEN
8296 IF g_debug
8297 THEN
8298 hr_utility.set_location (l_proc, 657);
8299 END IF;
8300
8301 hrs_already_paid := TRUE;
8302 hours_for_points := 0;
8303 segment_points := 0;
8304 ELSE
8305 IF g_debug
8306 THEN
8307 hr_utility.set_location (l_proc, 658);
8308 END IF;
8309
8310 hrs_already_paid := FALSE;
8311 END IF;
8312 END IF;
8313
8314 IF g_debug
8315 THEN
8316 hr_utility.set_location (l_proc, 659);
8317 hr_utility.TRACE ( 'hours_for_points :'
8318 || hours_for_points
8319 );
8320 END IF;
8321 END IF;
8322
8323 /*
8324 hours_for_points :=
8325 LEAST (hours_left,
8326 (weekly_earning_cap - hours_paid_for_week
8327 )
8328 );
8329 hr_utility.TRACE ( 'hours_for_points :'
8330 || hours_for_points
8331 );
8332 END IF;
8333 */
8334 IF g_debug
8335 THEN
8336 hr_utility.set_location (l_proc, 659.1);
8337 hr_utility.TRACE ('segment_points:' || segment_points);
8338 END IF;
8339
8340 IF hrs_already_paid = FALSE
8341 THEN
8342 IF g_debug
8343 THEN
8344 hr_utility.set_location (l_proc, 660);
8345 END IF;
8346
8347 hours_left :=
8348 (hours_left - hours_for_points - l_left_over_hours
8349 );
8350
8351 IF g_debug
8352 THEN
8353 hr_utility.TRACE ('hours_left :' || hours_left);
8354 END IF;
8355
8356 -- Added the following FOR LOOP to determine the elements that
8357 -- need to be paid when the Daily(REG,OT,DT) and Weekly(REG,OT,DT)
8358 -- elements in the Earning Policy rules are different.
8359 FOR i IN 1 .. g_weekly_earn_category.COUNT
8360 LOOP
8361 IF g_debug
8362 THEN
8363 hr_utility.set_location (l_proc, 661);
8364 hr_utility.TRACE
8365 ( 'g_weekly_earn_category(i).element_type_id:'
8366 || g_weekly_earn_category (i).element_type_id
8367 );
8368 hr_utility.TRACE
8369 ( 'g_weekly_earn_category(i).earning_category:'
8370 || g_weekly_earn_category (i).earning_category
8371 );
8372 hr_utility.TRACE ( 'weekly_element_type_id:'
8373 || weekly_element_type_id
8374 );
8375 hr_utility.TRACE ( 'use_daily_REG:'
8376 || use_daily_reg
8377 );
8378 hr_utility.TRACE ('use_daily_OT:'
8379 || use_daily_ot
8380 );
8381 hr_utility.TRACE ('use_daily_DT:'
8382 || use_daily_dt
8383 );
8384 hr_utility.TRACE ( 'use_weekly_REG:'
8385 || use_weekly_reg
8386 );
8387 hr_utility.TRACE ( 'use_weekly_OT:'
8388 || use_weekly_ot
8389 );
8390 hr_utility.TRACE ( 'use_weekly_DT:'
8391 || use_weekly_dt
8392 );
8393 END IF;
8394
8395 IF g_weekly_earn_category (i).earning_category =
8396 'REG'
8397 AND g_weekly_earn_category (i).element_type_id =
8398 weekly_element_type_id
8399 AND use_daily_reg = 'Y'
8400 THEN
8401 IF g_debug
8402 THEN
8403 hr_utility.set_location (l_proc, 662);
8404 END IF;
8405
8406 weekly_element_type_id := l_dy_wk_reg_elem_id;
8407 EXIT;
8408 ELSIF g_weekly_earn_category (i).earning_category =
8409 'OVT'
8410 AND g_weekly_earn_category (i).element_type_id =
8411 weekly_element_type_id
8412 AND use_daily_ot = 'Y'
8413 THEN
8414 IF g_debug
8415 THEN
8416 hr_utility.set_location (l_proc, 663);
8417 END IF;
8418
8419 weekly_element_type_id := l_dy_wk_ovt_elem_id;
8420 EXIT;
8421 ELSIF g_weekly_earn_category (i).earning_category =
8422 'DT'
8423 AND g_weekly_earn_category (i).element_type_id =
8424 weekly_element_type_id
8425 AND use_daily_dt = 'Y'
8426 THEN
8427 IF g_debug
8428 THEN
8429 hr_utility.set_location (l_proc, 664);
8430 END IF;
8431
8432 weekly_element_type_id := l_dy_wk_dt_elem_id;
8433 EXIT;
8434 END IF;
8435
8436 IF g_debug
8437 THEN
8438 hr_utility.set_location (l_proc, 665);
8439 END IF;
8440 END LOOP;
8441
8442 IF g_debug
8443 THEN
8444 hr_utility.set_location (l_proc, 670);
8445 hr_utility.TRACE ( 'weekly_element_type_id:'
8446 || weekly_element_type_id
8447 );
8448 END IF;
8449
8450 SELECT NVL (points_assigned, 0)
8451 INTO l_points_assigned
8452 FROM hxt_add_elem_info_f aei
8453 WHERE aei.element_type_id = weekly_element_type_id
8454 AND g_date_worked BETWEEN aei.effective_start_date
8455 AND aei.effective_end_date;
8456
8457 IF g_debug
8458 THEN
8459 hr_utility.TRACE ( 'l_points_assigned :'
8460 || l_points_assigned
8461 );
8462 END IF;
8463
8464 segment_points := hours_for_points * l_points_assigned;
8465
8466 IF g_debug
8467 THEN
8468 hr_utility.TRACE ( 'segment_points :'
8469 || segment_points
8470 );
8471 END IF;
8472
8473 l_weekly_index := l_weekly_index + 1;
8474 g_weekly_explosion (l_weekly_index).element_type_id :=
8475 weekly_element_type_id;
8476 g_weekly_explosion (l_weekly_index).hours_to_pay :=
8477 hours_for_points;
8478
8479 FOR i IN 1 .. g_weekly_earn_category.COUNT
8480 LOOP
8481 IF g_debug
8482 THEN
8483 hr_utility.set_location (l_proc, 675);
8484 hr_utility.TRACE ( 'weekly_element_type_id:'
8485 || weekly_element_type_id
8486 );
8487 hr_utility.TRACE
8488 ( 'g_weekly_earn_category(i).element_type_id:'
8489 || g_weekly_earn_category (i).element_type_id
8490 );
8491 END IF;
8492
8493 IF g_weekly_earn_category (i).element_type_id =
8494 weekly_element_type_id
8495 THEN
8496 IF g_debug
8497 THEN
8498 hr_utility.set_location (l_proc, 680);
8499 END IF;
8500
8501 g_weekly_explosion (l_weekly_index).earning_category :=
8502 g_weekly_earn_category (i).earning_category;
8503 END IF;
8504
8505 IF g_debug
8506 THEN
8507 hr_utility.set_location (l_proc, 685);
8508 END IF;
8509 END LOOP;
8510
8511 FOR i IN 1 .. g_weekly_explosion.COUNT
8512 LOOP
8513 IF g_debug
8514 THEN
8515 hr_utility.TRACE
8516 ( 'weekly_element_type_id:'
8517 || g_weekly_explosion (i).element_type_id
8518 );
8519 hr_utility.TRACE
8520 ( 'hours_to_pay in plsql table:'
8521 || g_weekly_explosion (i).hours_to_pay
8522 );
8523 hr_utility.TRACE
8524 ( 'earning_category:'
8525 || g_weekly_explosion (i).earning_category
8526 );
8527 END IF;
8528 END LOOP;
8529
8530 -- hours_paid_for_week := hours_paid_for_week + hours_for_points;
8531 IF g_debug
8532 THEN
8533 hr_utility.TRACE ( 'hours_paid_for_week:'
8534 || hours_paid_for_week
8535 );
8536 hr_utility.TRACE ( 'hours_for_points:'
8537 || hours_for_points
8538 );
8539 hr_utility.TRACE ( 'l_override_hrs:'
8540 || l_override_hrs
8541 );
8542 END IF;
8543
8544 l_weekly_total :=
8545 hours_paid_for_week + hours_for_points;
8546
8547 IF g_debug
8548 THEN
8549 hr_utility.TRACE ( 'l_weekly_total :'
8550 || l_weekly_total
8551 );
8552 END IF;
8553
8554 OPEN elements_in_earn_groups (g_ep_id);
8555
8556 LOOP
8557 IF g_debug
8558 THEN
8559 hr_utility.set_location (l_proc, 690);
8560 END IF;
8561
8562 FETCH elements_in_earn_groups
8563 INTO l_element_type_id;
8564
8565 EXIT WHEN elements_in_earn_groups%NOTFOUND;
8566
8567 IF g_debug
8568 THEN
8569 hr_utility.TRACE ( 'l_element_type_id :'
8570 || l_element_type_id
8571 );
8572 hr_utility.TRACE ( 'hours_for_points :'
8573 || hours_for_points
8574 );
8575 hr_utility.TRACE ( 'hours_paid_for_week:'
8576 || hours_paid_for_week
8577 );
8578 END IF;
8579
8580 IF weekly_element_type_id = l_element_type_id
8581 THEN
8582 IF g_debug
8583 THEN
8584 hr_utility.set_location (l_proc, 695);
8585 END IF;
8586
8587 hours_paid_for_week :=
8588 hours_paid_for_week + hours_for_points;
8589 END IF;
8590
8591 IF g_debug
8592 THEN
8593 hr_utility.TRACE ( 'hours_paid_for_week:'
8594 || hours_paid_for_week
8595 );
8596 hr_utility.set_location (l_proc, 700);
8597 END IF;
8598 END LOOP;
8599
8600 IF g_debug
8601 THEN
8602 hr_utility.set_location (l_proc, 710);
8603 END IF;
8604
8605 CLOSE elements_in_earn_groups;
8606
8607 IF g_debug
8608 THEN
8609 hr_utility.set_location (l_proc, 715);
8610 END IF;
8611 END IF;
8612 END IF;
8613
8614 l_weekly_reg_hrs := l_weekly_reg_hrs + hours_for_points;
8615
8616 -- Once the weekly regular hrs including today's REG hrs reaches
8617 -- the weekly REG cap, the daily OT and DT elements should
8618 -- not be paid anymore(in cases where daily rules elements are
8619 -- different than the elements used for weekly rules)
8620 IF l_weekly_reg_hrs >= l_weekly_reg_cap
8621 THEN
8622 use_daily_ot := 'N';
8623 use_daily_dt := 'N';
8624 END IF;
8625
8626 IF g_debug
8627 THEN
8628 hr_utility.set_location (l_proc, 720);
8629 END IF;
8630
8631 total_weekly_points := total_weekly_points + segment_points;
8632
8633 IF g_debug
8634 THEN
8635 hr_utility.TRACE ( 'total_weekly_points :'
8636 || total_weekly_points
8637 );
8638 END IF;
8639 END LOOP;
8640
8641 IF g_debug
8642 THEN
8643 hr_utility.set_location (l_proc, 725);
8644 hr_utility.TRACE ( 'total_daily_points :'
8645 || total_daily_points
8646 );
8647 hr_utility.TRACE ( 'total_weekly_points :'
8648 || total_weekly_points
8649 );
8650 END IF;
8651
8652 CLOSE weekly_earning_rules;
8653
8654 --
8655 ------------------------END Weekly Points Calculation---------------------------
8656 --
8657
8658 --
8659 --------------------BEGIN Combination Points Calculation------------------------
8660 --
8661 -- The logic being used for calculating the combination points is as follows:
8662 -- Say for example:
8663 -- Earning Policy - Daily
8664 -- REG,OT, DT : 8,12,24
8665 -- Weekly
8666 -- REG,OT : 40,999
8667 -- Earning Group - REG
8668
8669 -- Example 1:
8670 -- Timecard Entered:
8671 -- DAY Mon Tue Wed Thur Fri Sat
8672 -- HRS 14 14 14 14 14 14
8673 -- Mon to Fri the explosion will be 8,4,2
8674 -- The issue arises for Sat. We need to apply a combination of Daily and Weekly
8675 -- rules on this day. So, the logic being followed here is to explode this day
8676 -- based on daily rules and then apply the weekly rules on the Daily REG hrs.
8677 -- We already have the explosion based on Daily rules for this day in the
8678 -- g_daily_explosion plsql table. Now apply the weekly rule on the Daily REG hrs
8679 -- So, for Sat 14 hrs daily explosion in g_daily_explosion plsql table will be:
8680 -- 8 REG
8681 -- 4 OT
8682 -- 2 DT
8683 -- Now apply Weekly rule on 8 hrs REG, which would explode to 8 OT(since 40 REG
8684 -- weekly cap has already been reached)
8685 -- Now add this 8 OT to the Daily OT which would result in the following
8686 -- explosion:
8687 -- 0 REG
8688 -- 12(4 + 8) OT
8689 -- 2 DT
8690
8691 -- Example 2:
8692 -- Timecard Entered:
8693 -- DAY Mon Tue Wed Thur Fri Sat
8694 -- HRS 8 8 8 8 1 13
8695 -- Mon to Fri explosion is:
8696 -- REG 8 8 8 8 1
8697 -- OT
8698 -- DT
8699 -- Now the daily explosion for 13 hrs on Sat in g_daily_explosion is:
8700 -- REG 8
8701 -- OT 4
8702 -- DT 1
8703 -- Applying weekly rules on 8 REG explodes to 7 REG + 1 OT
8704 -- So the combine explosion for sat would be:
8705 -- REG 7
8706 -- OT 4 + 1 = 5
8707 -- DT 1
8708 IF g_debug
8709 THEN
8710 hr_utility.TRACE
8711 ( 'fnd_profile.VALUE (''HXT_CA_LABOR_RULE''):'
8712 || fnd_profile.VALUE ('HXT_CA_LABOR_RULE')
8713 );
8714 END IF;
8715
8716 -- If the following profile is set to 'YES', only then calculate the
8717 -- combination points.
8718 IF (NVL (fnd_profile.VALUE ('HXT_CA_LABOR_RULE'), 'N') = 'Y')
8719 THEN
8720 IF g_debug
8721 THEN
8722 hr_utility.set_location (l_proc, 726);
8723 hr_utility.TRACE ('use_weekly_REG:' || use_weekly_reg);
8724 hr_utility.TRACE ('use_weekly_OT:' || use_weekly_ot);
8725 hr_utility.TRACE ('use_weekly_DT:' || use_weekly_dt);
8726 hr_utility.TRACE ('l_weekly_reg_cap:' || l_weekly_reg_cap
8727 );
8728 END IF;
8729
8730 -- Initialize the variables before calculating the combine points
8731 init_for_wkl_combine_pts_cal (use_weekly_reg,
8732 use_weekly_ot,
8733 use_weekly_dt,
8734 l_weekly_reg_cap,
8735 l_dy_wk_reg_elem_id,
8736 l_dy_wk_ovt_elem_id,
8737 l_dy_wk_dt_elem_id,
8738 use_daily_reg,
8739 use_daily_ot,
8740 use_daily_dt,
8741 l_reg_for_day,
8742 l_ovt_for_day,
8743 l_dt_for_day,
8744 wky_reg_incl_dy_reg_expl,
8745 l_weekly_reg_hrs
8746 );
8747
8748 IF g_debug
8749 THEN
8750 hr_utility.set_location (l_proc, 727);
8751 hr_utility.TRACE ( 'l_dy_wk_reg_elem_id:'
8752 || l_dy_wk_reg_elem_id
8753 );
8754 hr_utility.TRACE ( 'l_dy_wk_ovt_elem_id:'
8755 || l_dy_wk_ovt_elem_id
8756 );
8757 hr_utility.TRACE ( 'l_dy_wk_dt_elem_id:'
8758 || l_dy_wk_dt_elem_id
8759 );
8760 hr_utility.TRACE ('use_daily_reg:' || use_daily_reg);
8761 hr_utility.TRACE ('use_daily_ot:' || use_daily_ot);
8762 hr_utility.TRACE ('use_daily_dt:' || use_daily_dt);
8763 hr_utility.TRACE ('l_reg_for_day:' || l_reg_for_day);
8764 hr_utility.TRACE ('l_ovt_for_day:' || l_ovt_for_day);
8765 hr_utility.TRACE ('l_dt_for_day:' || l_dt_for_day);
8766 hr_utility.TRACE ( 'wky_reg_incl_dy_reg_expl:'
8767 || wky_reg_incl_dy_reg_expl
8768 );
8769 hr_utility.TRACE ('l_weekly_REG_hrs:' || l_weekly_reg_hrs);
8770 END IF;
8771
8772 FOR i IN 1 .. g_dy_wk_combo_explosion.COUNT
8773 LOOP
8774 IF g_debug
8775 THEN
8776 hr_utility.set_location (l_proc, 730);
8777 hr_utility.TRACE
8778 ( 'combo_element_type_id:'
8779 || g_dy_wk_combo_explosion (i).element_type_id
8780 );
8781 hr_utility.TRACE
8782 ( 'hours_to_pay in plsql table:'
8783 || g_dy_wk_combo_explosion (i).hours_to_pay
8784 );
8785 END IF;
8786 END LOOP;
8787
8788 IF g_debug
8789 THEN
8790 hr_utility.TRACE ( ' g_daily_explosion.COUNT:'
8791 || g_daily_explosion.COUNT
8792 );
8793 END IF;
8794
8795 FOR i IN 1 .. g_daily_explosion.COUNT
8796 LOOP
8797 IF g_debug
8798 THEN
8799 hr_utility.set_location (l_proc, 735);
8800 hr_utility.TRACE
8801 ( 'daily_element_type_id:'
8802 || g_daily_explosion (i).element_type_id
8803 );
8804 hr_utility.TRACE ( 'hours_to_pay in plsql table:'
8805 || g_daily_explosion (i).hours_to_pay
8806 );
8807 hr_utility.TRACE
8808 ( 'earning_category:'
8809 || g_daily_explosion (i).earning_category
8810 );
8811 hr_utility.set_location (l_proc, 740);
8812 END IF;
8813 END LOOP;
8814
8815 OPEN weekly_earning_rules (g_ep_id);
8816
8817 FETCH weekly_earning_rules
8818 INTO weekly_earning_cap, weekly_element_type_id;
8819
8820 IF g_debug
8821 THEN
8822 hr_utility.TRACE ( 'weekly_earning_cap:'
8823 || weekly_earning_cap
8824 );
8825 hr_utility.TRACE ( 'weekly_element_type_id:'
8826 || weekly_element_type_id
8827 );
8828 END IF;
8829
8830 CLOSE weekly_earning_rules;
8831
8832 IF g_debug
8833 THEN
8834 hr_utility.TRACE ( 'wky_reg_incl_dy_reg_expl:'
8835 || wky_reg_incl_dy_reg_expl
8836 );
8837 hr_utility.TRACE ( 'weekly_earning_cap:'
8838 || weekly_earning_cap
8839 );
8840 END IF;
8841
8842 -- Check if the weekly REG including today's REG hrs is greater
8843 -- than the weekly REG cap then proceed further to calculate the
8844 -- combination points.
8845 IF wky_reg_incl_dy_reg_expl >= weekly_earning_cap
8846 OR g_hours = 0
8847 THEN
8848 IF g_debug
8849 THEN
8850 hr_utility.set_location (l_proc, 745);
8851 END IF;
8852
8853 OPEN weekly_earning_rules (g_ep_id);
8854
8855 hours_left := NVL(l_reg_for_day, 0); -- added NVL for 5441313
8856
8857 IF g_debug
8858 THEN
8859 hr_utility.TRACE ('hours_left :' || hours_left);
8860 END IF;
8861
8862 hours_for_points := 0;
8863
8864 LOOP
8865 IF g_debug
8866 THEN
8867 hr_utility.set_location (l_proc, 750);
8868 END IF;
8869
8870 k := k + 1;
8871
8872 FETCH weekly_earning_rules
8873 INTO weekly_earning_cap, weekly_element_type_id;
8874
8875 IF g_debug
8876 THEN
8877 hr_utility.TRACE ( 'weekly_earning_cap :'
8878 || weekly_earning_cap
8879 );
8880 hr_utility.TRACE ( 'weekly_element_type_id :'
8881 || weekly_element_type_id
8882 );
8883 END IF;
8884
8885 hours_paid_for_week :=
8886 get_weekly_total_prev_days
8887 + NVL (previous_detail_hours_day, 0)
8888 + hours_for_points;
8889
8890 IF g_debug
8891 THEN
8892 hr_utility.set_location (l_proc, 755);
8893 hr_utility.TRACE ( 'hours_paid_for_week :'
8894 || hours_paid_for_week
8895 );
8896 hr_utility.TRACE ( 'g_hours :'
8897 || g_hours
8898 );
8899 END IF;
8900
8901 EXIT WHEN hours_left = 0 AND k > 1;
8902
8903 IF g_debug
8904 THEN
8905 hr_utility.set_location (l_proc, 760);
8906 END IF;
8907
8908 IF hours_left >= 0
8909 THEN
8910 IF g_debug
8911 THEN
8912 hr_utility.set_location (l_proc, 770);
8913 hr_utility.TRACE ( 'hours_paid_for_week :'
8914 || hours_paid_for_week
8915 );
8916 hr_utility.TRACE ( 'weekly_earning_cap :'
8917 || weekly_earning_cap
8918 );
8919 END IF;
8920
8921 IF (hours_paid_for_week - l_override_hrs) >= weekly_earning_cap
8922 THEN
8923 IF g_debug
8924 THEN
8925 hr_utility.set_location (l_proc, 780);
8926 END IF;
8927
8928 OPEN weekly_earning_rules2 (g_ep_id,
8929 hours_paid_for_week
8930 );
8931
8932 FETCH weekly_earning_rules2
8933 INTO weekly_earning_cap2,
8934 weekly_element_type_id;
8935
8936 IF g_debug
8937 THEN
8938 hr_utility.TRACE
8939 ( 'weekly_earning_cap2 :'
8940 || weekly_earning_cap2
8941 );
8942 hr_utility.TRACE
8943 ( 'weekly_element_type_id :'
8944 || weekly_element_type_id
8945 );
8946 END IF;
8947
8948 CLOSE weekly_earning_rules2;
8949
8950 hours_for_points :=
8951 LEAST (( weekly_earning_cap2
8952 - hours_paid_for_week
8953 ),
8954 hours_left
8955 );
8956
8957 IF (hours_for_points = 0)
8958 THEN
8959 IF g_debug
8960 THEN
8961 hr_utility.set_location (l_proc, 790);
8962 END IF;
8963
8964 l_left_over_hours := hours_left;
8965 ELSE
8966 IF g_debug
8967 THEN
8968 hr_utility.set_location (l_proc, 800);
8969 END IF;
8970
8971 l_left_over_hours := 0;
8972 END IF;
8973
8974 IF g_debug
8975 THEN
8976 hr_utility.set_location (l_proc, 810);
8977 hr_utility.TRACE ( 'hours_for_points :'
8978 || hours_for_points
8979 );
8980 END IF;
8981 ELSE
8982 IF g_debug
8983 THEN
8984 hr_utility.set_location (l_proc, 815);
8985 END IF;
8986
8987 IF weekly_element_type_id = l_override_element
8988 THEN
8989 IF hours_left <=
8990 ( weekly_earning_cap
8991 - (hours_paid_for_week - l_override_hrs)
8992 )
8993 THEN
8994 IF g_debug
8995 THEN
8996 hr_utility.set_location (l_proc, 815.1);
8997 END IF;
8998
8999 hours_for_points :=
9000 LEAST (hours_left,
9001 ( weekly_earning_cap
9002 - (hours_paid_for_week)
9003 )
9004 );
9005 ELSE
9006 IF g_debug
9007 THEN
9008 hr_utility.set_location (l_proc, 815.2);
9009 END IF;
9010
9011 hours_for_points :=
9012 LEAST (hours_left,
9013 ( weekly_earning_cap
9014 - ( hours_paid_for_week
9015 - l_override_hrs
9016 )
9017 )
9018 );
9019 END IF;
9020 ELSE
9021 IF g_debug
9022 THEN
9023 hr_utility.set_location (l_proc, 815.3);
9024 END IF;
9025
9026 hours_for_points :=
9027 LEAST (hours_left,
9028 ( weekly_earning_cap
9029 - (hours_paid_for_week - l_override_hrs
9030 )
9031 )
9032 );
9033 END IF;
9034
9035 IF g_debug
9036 THEN
9037 hr_utility.TRACE ( 'hours_for_points :'
9038 || hours_for_points
9039 );
9040 END IF;
9041
9042 -- Say for example entering time as follows:
9043 -- hrs element
9044 -- 13 (no override)
9045 -- 2 OT
9046 -- This should explode to
9047 -- 13 hrs -> 8/2/3
9048 -- 2 OT -> 2
9049 -- From the above logic we get the hours for the 2nd
9050 -- Daily Cap element i.e., LEAST(5,(12-(10 - 2))
9051 -- i.e., 4 hrs OT
9052 -- But since 2 hrs OT already overriden => (4 - 2)OT left
9053 -- to be paid
9054
9055 IF weekly_element_type_id = l_override_element
9056 AND hours_for_points > l_override_hrs
9057 THEN
9058 IF g_debug
9059 THEN
9060 hr_utility.set_location (l_proc, 816);
9061 END IF;
9062
9063 hrs_already_paid := FALSE;
9064 hours_for_points :=
9065 hours_for_points - l_override_hrs;
9066 ELSIF weekly_element_type_id = l_override_element
9067 AND hours_for_points <= l_override_hrs
9068 THEN
9069 IF g_debug
9070 THEN
9071 hr_utility.TRACE ( 'l_override_hrs:'
9072 || l_override_hrs
9073 );
9074 hr_utility.TRACE ( 'weekly_earning_cap:'
9075 || weekly_earning_cap
9076 );
9077 hr_utility.TRACE ( 'prev_weekly_cap:'
9078 || prev_weekly_cap
9079 );
9080 END IF;
9081
9082 IF l_override_hrs >=
9083 weekly_earning_cap - prev_weekly_cap
9084 THEN
9085 IF g_debug
9086 THEN
9087 hr_utility.set_location (l_proc, 817);
9088 END IF;
9089
9090 hrs_already_paid := TRUE;
9091 hours_for_points := 0;
9092 segment_points := 0;
9093 ELSE
9094 IF g_debug
9095 THEN
9096 hr_utility.set_location (l_proc, 818);
9097 END IF;
9098
9099 hrs_already_paid := FALSE;
9100 END IF;
9101 END IF;
9102
9103 IF g_debug
9104 THEN
9105 hr_utility.set_location (l_proc, 819);
9106 hr_utility.TRACE ( 'hours_for_points :'
9107 || hours_for_points
9108 );
9109 END IF;
9110 END IF;
9111
9112 /*
9113 hours_for_points :=
9114 LEAST (hours_left,
9115 ( weekly_earning_cap
9116 - hours_paid_for_week
9117 )
9118 );
9119
9120 IF g_debug
9121 THEN
9122 hr_utility.TRACE ( 'hours_for_points :'
9123 || hours_for_points
9124 );
9125 END IF;
9126 END IF;
9127 */
9128
9129 IF g_debug
9130 THEN
9131 hr_utility.set_location (l_proc, 819.1);
9132 hr_utility.TRACE ('segment_points:' || segment_points);
9133 END IF;
9134
9135 IF hrs_already_paid = FALSE
9136 THEN
9137 IF g_debug
9138 THEN
9139 hr_utility.set_location (l_proc, 820);
9140 END IF;
9141
9142 hours_left :=
9143 (hours_left - hours_for_points
9144 - l_left_over_hours
9145 );
9146
9147 IF g_debug
9148 THEN
9149 hr_utility.TRACE ('hours_left :' || hours_left);
9150 hr_utility.TRACE ( ' l_dy_wk_reg_elem_id:'
9151 || l_dy_wk_reg_elem_id
9152 );
9153 hr_utility.TRACE ( ' l_dy_wk_ovt_elem_id:'
9154 || l_dy_wk_ovt_elem_id
9155 );
9156 hr_utility.TRACE ( ' l_dy_wk_dt_elem_id:'
9157 || l_dy_wk_dt_elem_id
9158 );
9159 hr_utility.TRACE ( ' l_ovt_for_day:'
9160 || l_ovt_for_day
9161 );
9162 hr_utility.TRACE ( ' l_dt_for_day:'
9163 || l_dt_for_day
9164 );
9165 END IF;
9166
9167 FOR i IN 1 .. g_weekly_earn_category.COUNT
9168 LOOP
9169 IF g_debug
9170 THEN
9171 hr_utility.set_location (l_proc, 825);
9172 hr_utility.TRACE
9173 ( 'daily_element_type_id:'
9174 || daily_element_type_id
9175 );
9176 hr_utility.TRACE
9177 ( 'g_weekly_earn_category(i).element_type_id:'
9178 || g_weekly_earn_category (i).element_type_id
9179 );
9180 hr_utility.TRACE
9181 ( 'g_weekly_earn_category(i).earning_category:'
9182 || g_weekly_earn_category (i).earning_category
9183 );
9184 hr_utility.TRACE
9185 ( 'weekly_element_type_id:'
9186 || weekly_element_type_id
9187 );
9188 hr_utility.TRACE ( 'use_daily_REG:'
9189 || use_daily_reg
9190 );
9191 hr_utility.TRACE ( 'use_daily_OT:'
9192 || use_daily_ot
9193 );
9194 hr_utility.TRACE ( 'use_daily_DT:'
9195 || use_daily_dt
9196 );
9197 hr_utility.TRACE ( 'use_weekly_REG:'
9198 || use_weekly_reg
9199 );
9200 hr_utility.TRACE ( 'use_weekly_OT:'
9201 || use_weekly_ot
9202 );
9203 hr_utility.TRACE ( 'use_weekly_DT:'
9204 || use_weekly_dt
9205 );
9206 END IF;
9207
9208 -- Determine whether daily or weekly OT, DT elements
9209 -- need to be paid(in cases where the daily and
9210 -- weekly elements are different)
9211 IF g_weekly_earn_category (i).earning_category =
9212 'REG'
9213 AND g_weekly_earn_category (i).element_type_id =
9214 weekly_element_type_id
9215 AND use_daily_reg = 'Y'
9216 THEN
9217 IF g_debug
9218 THEN
9219 hr_utility.set_location (l_proc, 830);
9220 END IF;
9221
9222 weekly_element_type_id := l_dy_wk_reg_elem_id;
9223 EXIT;
9224 ELSIF g_weekly_earn_category (i).earning_category =
9225 'OVT'
9226 AND g_weekly_earn_category (i).element_type_id =
9227 weekly_element_type_id
9228 AND use_daily_ot = 'Y'
9229 THEN
9230 IF g_debug
9231 THEN
9232 hr_utility.set_location (l_proc, 835);
9233 END IF;
9234
9235 weekly_element_type_id := l_dy_wk_ovt_elem_id;
9236 EXIT;
9237 ELSIF g_weekly_earn_category (i).earning_category =
9238 'DT'
9239 AND g_weekly_earn_category (i).element_type_id =
9240 weekly_element_type_id
9241 AND use_daily_dt = 'Y'
9242 THEN
9243 IF g_debug
9244 THEN
9245 hr_utility.set_location (l_proc, 840);
9246 END IF;
9247
9248 weekly_element_type_id := l_dy_wk_dt_elem_id;
9249 EXIT;
9250 END IF;
9251
9252 IF g_debug
9253 THEN
9254 hr_utility.set_location (l_proc, 845);
9255 END IF;
9256 END LOOP;
9257
9258 IF g_debug
9259 THEN
9260 hr_utility.set_location (l_proc, 846);
9261 hr_utility.TRACE ( 'weekly_element_type_id:'
9262 || weekly_element_type_id
9263 );
9264 END IF;
9265
9266 IF weekly_element_type_id = l_dy_wk_ovt_elem_id
9267 THEN
9268 IF g_debug
9269 THEN
9270 hr_utility.set_location (l_proc, 850);
9271 END IF;
9272
9273 hours_for_points :=
9274 hours_for_points + l_ovt_for_day;
9275 ELSIF weekly_element_type_id = l_dy_wk_dt_elem_id
9276 THEN
9277 IF g_debug
9278 THEN
9279 hr_utility.set_location (l_proc, 855);
9280 END IF;
9281
9282 hours_for_points :=
9283 hours_for_points + l_dt_for_day;
9284 END IF;
9285
9286 IF g_debug
9287 THEN
9288 hr_utility.set_location (l_proc, 860);
9289 END IF;
9290
9291 SELECT NVL (points_assigned, 0)
9292 INTO l_points_assigned
9293 FROM hxt_add_elem_info_f aei
9294 WHERE aei.element_type_id = weekly_element_type_id
9295 AND g_date_worked BETWEEN aei.effective_start_date
9296 AND aei.effective_end_date;
9297
9298 IF g_debug
9299 THEN
9300 hr_utility.TRACE ( 'l_points_assigned :'
9301 || l_points_assigned
9302 );
9303 hr_utility.TRACE ( ' weekly_element_type_id:'
9304 || weekly_element_type_id
9305 );
9306 END IF;
9307
9308 segment_points :=
9309 hours_for_points * l_points_assigned;
9310
9311 IF g_debug
9312 THEN
9313 hr_utility.TRACE ( 'segment_points :'
9314 || segment_points
9315 );
9316 END IF;
9317
9318 l_dy_wk_combo_index := l_dy_wk_combo_index + 1;
9319 g_dy_wk_combo_explosion (l_dy_wk_combo_index).element_type_id :=
9320 weekly_element_type_id;
9321 g_dy_wk_combo_explosion (l_dy_wk_combo_index).hours_to_pay :=
9322 hours_for_points;
9323
9324 IF g_debug
9325 THEN
9326 hr_utility.set_location (l_proc, 865);
9327 END IF;
9328
9329 FOR i IN 1 .. g_dy_wk_combo_explosion.COUNT
9330 LOOP
9331 IF g_debug
9332 THEN
9333 hr_utility.set_location (l_proc, 870);
9334 hr_utility.TRACE
9335 ( 'combo_element_type_id:'
9336 || g_dy_wk_combo_explosion (i).element_type_id
9337 );
9338 hr_utility.TRACE
9339 ( 'hours_to_pay in plsql table:'
9340 || g_dy_wk_combo_explosion (i).hours_to_pay
9341 );
9342 END IF;
9343 END LOOP;
9344
9345 IF g_debug
9346 THEN
9347 hr_utility.set_location (l_proc, 875);
9348 hr_utility.TRACE ('hours_left :' || hours_left);
9349 END IF;
9350 END IF; /*End hrs_already_paid = FALSE */
9351 END IF;
9352
9353 IF g_debug
9354 THEN
9355 hr_utility.set_location (l_proc, 880);
9356 END IF;
9357
9358 l_weekly_reg_hrs :=
9359 l_weekly_reg_hrs + hours_for_points;
9360
9361 -- Once the weekly regular hrs including today's REG hrs reaches
9362 -- the weekly REG cap, the Daily OT and DT elements should
9363 -- not be paid anymore(in cases where daily rules elements are
9364 -- different than the elements used for weekly rules)
9365 IF l_weekly_reg_hrs >= l_weekly_reg_cap
9366 THEN
9367 use_daily_ot := 'N';
9368 use_daily_dt := 'N';
9369 END IF;
9370
9371 total_combo_points :=
9372 total_combo_points + segment_points;
9373
9374 IF g_debug
9375 THEN
9376 hr_utility.TRACE ( 'total_combo_points :'
9377 || total_combo_points
9378 );
9379 END IF;
9380 END LOOP;
9381
9382 IF g_debug
9383 THEN
9384 hr_utility.set_location (l_proc, 885);
9385 END IF;
9386
9387 CLOSE weekly_earning_rules;
9388
9389 FOR i IN 1 .. g_dy_wk_combo_explosion.COUNT
9390 LOOP
9391 IF g_debug
9392 THEN
9393 hr_utility.set_location (l_proc, 890);
9394 hr_utility.TRACE ('i:' || i);
9395 hr_utility.TRACE
9396 ( 'combo_element_type_id:'
9397 || g_dy_wk_combo_explosion (i).element_type_id
9398 );
9399 hr_utility.TRACE
9400 ( 'hours_to_pay in plsql table:'
9401 || g_dy_wk_combo_explosion (i).hours_to_pay
9402 );
9403 END IF;
9404
9405 l_total_combo_hrs :=
9406 l_total_combo_hrs
9407 + g_dy_wk_combo_explosion (i).hours_to_pay;
9408 END LOOP;
9409
9410 IF g_debug
9411 THEN
9412 hr_utility.set_location (l_proc, 895);
9413 END IF;
9414
9415 l_dy_wk_combo_index := g_dy_wk_combo_explosion.COUNT;
9416
9417 IF g_debug
9418 THEN
9419 hr_utility.TRACE ( 'g_dy_wk_combo_explosion.COUNT:'
9420 || g_dy_wk_combo_explosion.COUNT
9421 );
9422 hr_utility.TRACE ( 'l_total_combo_hrs:'
9423 || l_total_combo_hrs
9424 );
9425 hr_utility.TRACE ( 'l_dy_wk_combo_index:'
9426 || l_dy_wk_combo_index
9427 );
9428 END IF;
9429
9430 -- Once the Weekly rules have been applied to the REG hrs
9431 -- in the g_daily_explosion for the day, populate the
9432 -- g_dy_wk_combo_explosion table with the rest of the
9433 -- g_daily_explosion records for the day.
9434 FOR i IN 1 .. g_daily_explosion.COUNT
9435 LOOP
9436 IF g_debug
9437 THEN
9438 hr_utility.set_location (l_proc, 900);
9439 hr_utility.TRACE
9440 ( 'daily_element_type_id:'
9441 || g_daily_explosion (i).element_type_id
9442 );
9443 hr_utility.TRACE ( 'hours_to_pay in plsql table:'
9444 || g_daily_explosion (i).hours_to_pay
9445 );
9446 hr_utility.TRACE
9447 ( 'earning_category:'
9448 || g_daily_explosion (i).earning_category
9449 );
9450 END IF;
9451
9452 l_combo_elem_id :=
9453 g_daily_explosion (i).element_type_id;
9454 l_total_daily_hrs :=
9455 l_total_daily_hrs
9456 + g_daily_explosion (i).hours_to_pay;
9457
9458 IF g_debug
9459 THEN
9460 hr_utility.TRACE ( 'l_combo_elem_id:'
9461 || l_combo_elem_id
9462 );
9463 hr_utility.TRACE ( 'l_total_daily_hrs:'
9464 || l_total_daily_hrs
9465 );
9466 hr_utility.TRACE ( 'l_total_combo_hrs:'
9467 || l_total_combo_hrs
9468 );
9469 END IF;
9470
9471 IF l_total_daily_hrs > l_total_combo_hrs
9472 THEN
9473 IF g_debug
9474 THEN
9475 hr_utility.set_location (l_proc, 910);
9476 END IF;
9477
9478 FOR j IN 1 .. g_weekly_earn_category.COUNT
9479 LOOP
9480 IF g_debug
9481 THEN
9482 hr_utility.set_location (l_proc, 911);
9483 hr_utility.TRACE
9484 ( 'g_weekly_earn_category(j).element_type_id:'
9485 || g_weekly_earn_category (j).element_type_id
9486 );
9487 hr_utility.TRACE
9488 ( 'g_daily_explosion (i).element_type_id:'
9489 || g_daily_explosion (i).element_type_id
9490 );
9491 hr_utility.TRACE
9492 ( 'g_weekly_earn_category(j).earning_category:'
9493 || g_weekly_earn_category (j).earning_category
9494 );
9495 hr_utility.TRACE ( 'use_daily_OT:'
9496 || use_daily_ot
9497 );
9498 hr_utility.TRACE ( 'use_daily_DT:'
9499 || use_daily_dt
9500 );
9501 END IF;
9502
9503 IF (get_weekly_total_prev_days >=
9504 l_weekly_reg_cap
9505 )
9506 THEN
9507 IF g_daily_explosion (i).earning_category =
9508 g_weekly_earn_category (j).earning_category
9509 AND g_weekly_earn_category (j).earning_category =
9510 'OVT'
9511 AND use_daily_ot = 'N'
9512 THEN
9513 IF g_debug
9514 THEN
9515 hr_utility.set_location (l_proc, 912);
9516 END IF;
9517
9518 l_combo_elem_id :=
9519 g_weekly_earn_category (j).element_type_id;
9520 EXIT;
9521 ELSIF g_daily_explosion (i).earning_category =
9522 g_weekly_earn_category (j).earning_category
9523 AND g_weekly_earn_category (j).earning_category =
9524 'DT'
9525 AND use_daily_dt = 'N'
9526 THEN
9527 IF g_debug
9528 THEN
9529 hr_utility.set_location (l_proc, 913);
9530 END IF;
9531
9532 l_combo_elem_id :=
9533 g_weekly_earn_category (j).element_type_id;
9534 EXIT;
9535 END IF;
9536 END IF;
9537
9538 IF g_debug
9539 THEN
9540 hr_utility.set_location (l_proc, 914);
9541 END IF;
9542 END LOOP;
9543
9544 IF g_debug
9545 THEN
9546 hr_utility.set_location (l_proc, 915);
9547 hr_utility.TRACE ( 'l_combo_elem_id:'
9548 || l_combo_elem_id
9549 );
9550 END IF;
9551
9552 l_dy_wk_combo_index := l_dy_wk_combo_index + 1;
9553 g_dy_wk_combo_explosion (l_dy_wk_combo_index).element_type_id :=
9554 l_combo_elem_id;
9555 g_dy_wk_combo_explosion (l_dy_wk_combo_index).hours_to_pay :=
9556 g_daily_explosion (i).hours_to_pay;
9557 l_total_combo_hrs :=
9558 l_total_combo_hrs
9559 + g_dy_wk_combo_explosion (l_dy_wk_combo_index).hours_to_pay;
9560
9561 FOR i IN 1 .. g_dy_wk_combo_explosion.COUNT
9562 LOOP
9563 IF g_debug
9564 THEN
9565 hr_utility.set_location (l_proc, 916);
9566 hr_utility.TRACE
9567 ( 'combo_element_type_id:'
9568 || g_dy_wk_combo_explosion (i).element_type_id
9569 );
9570 hr_utility.TRACE
9571 ( 'hours_to_pay in plsql table:'
9572 || g_dy_wk_combo_explosion (i).hours_to_pay
9573 );
9574 END IF;
9575 END LOOP;
9576
9577 IF g_debug
9578 THEN
9579 hr_utility.set_location (l_proc, 920);
9580 END IF;
9581
9582 SELECT NVL (points_assigned, 0)
9583 INTO l_points_assigned
9584 FROM hxt_add_elem_info_f aei
9585 WHERE aei.element_type_id = l_combo_elem_id
9586 AND g_date_worked BETWEEN aei.effective_start_date
9587 AND aei.effective_end_date;
9588
9589 segment_points :=
9590 g_daily_explosion (i).hours_to_pay
9591 * l_points_assigned;
9592
9593 IF g_debug
9594 THEN
9595 hr_utility.TRACE ( 'segment_points :'
9596 || segment_points
9597 );
9598 END IF;
9599
9600 total_combo_points :=
9601 total_combo_points + segment_points;
9602
9603 IF g_debug
9604 THEN
9605 hr_utility.TRACE ( 'total_combo_points :'
9606 || total_combo_points
9607 );
9608 END IF;
9609 END IF;
9610
9611 IF g_debug
9612 THEN
9613 hr_utility.set_location (l_proc, 925);
9614 END IF;
9615 END LOOP;
9616
9617 IF g_debug
9618 THEN
9619 hr_utility.set_location (l_proc, 930);
9620 END IF;
9621 END IF;
9622 END IF;
9623
9624 --
9625 ----------------------END Combination Points Calculation------------------------
9626 --
9627 IF g_debug
9628 THEN
9629 hr_utility.set_location (l_proc, 935);
9630 hr_utility.TRACE
9631 ( 'fnd_profile.VALUE (''HXT_CA_LABOR_RULE''):'
9632 || fnd_profile.VALUE ('HXT_CA_LABOR_RULE')
9633 );
9634 END IF;
9635
9636 -- IF the following profile set to 'Yes' then include combination
9637 -- points while determining the greatest of the Daily, Weekly and
9638 -- combination points.
9639 -- If all the three are of same points then 'Combination' takes the
9640 -- precedence. The order of precedence in case of 'EQUAL' points is
9641 -- as follows:
9642 -- Combination
9643 -- Weekly
9644 -- Daily
9645 IF (NVL (fnd_profile.VALUE ('HXT_CA_LABOR_RULE'), 'N') = 'Y')
9646 THEN
9647 IF g_debug
9648 THEN
9649 hr_utility.set_location (l_proc, 936);
9650 END IF;
9651
9652 l_greatest_points :=
9653 GREATEST (total_daily_points,
9654 total_weekly_points,
9655 total_combo_points
9656 );
9657
9658 IF g_debug
9659 THEN
9660 hr_utility.TRACE ( 'l_greatest_points:'
9661 || l_greatest_points
9662 );
9663 END IF;
9664
9665 IF l_greatest_points = total_combo_points
9666 THEN
9667 IF g_debug
9668 THEN
9669 hr_utility.set_location (l_proc, 940);
9670 END IF;
9671
9672 g_explosion_to_use := 'COMBO';
9673 ELSIF l_greatest_points = total_weekly_points
9674 THEN
9675 IF g_debug
9676 THEN
9677 hr_utility.set_location (l_proc, 945);
9678 END IF;
9679
9680 g_explosion_to_use := 'WEEKLY';
9681 ELSIF l_greatest_points = total_daily_points
9682 THEN
9683 IF g_debug
9684 THEN
9685 hr_utility.set_location (l_proc, 950);
9686 END IF;
9687
9688 g_explosion_to_use := 'DAILY';
9689 END IF;
9690 -- Else determine the greatest of Daily and Weekly points
9691 -- If Weekly and Daily both come out to be of same points then
9692 -- Weekly takes precedence over Daily.
9693 ELSE
9694 IF g_debug
9695 THEN
9696 hr_utility.set_location (l_proc, 960);
9697 END IF;
9698
9699 IF total_weekly_points > total_daily_points
9700 THEN
9701 IF g_debug
9702 THEN
9703 hr_utility.set_location (l_proc, 970);
9704 END IF;
9705
9706 g_explosion_to_use := 'WEEKLY';
9707 ELSIF total_daily_points > total_weekly_points
9708 THEN
9709 IF g_debug
9710 THEN
9711 hr_utility.set_location (l_proc, 980);
9712 END IF;
9713
9714 g_explosion_to_use := 'DAILY';
9715 ELSIF total_daily_points = total_weekly_points
9716 THEN
9717 IF g_debug
9718 THEN
9719 hr_utility.set_location (l_proc, 990);
9720 END IF;
9721
9722 g_explosion_to_use := 'WEEKLY';
9723 END IF;
9724 END IF;
9725
9726 IF g_debug
9727 THEN
9728 hr_utility.set_location (l_proc, 991);
9729 END IF;
9730 END IF; -- IF special_day = FALSE
9731
9732 IF g_debug
9733 THEN
9734 hr_utility.set_location (l_proc, 992);
9735 END IF;
9736
9737 IF g_explosion_to_use = 'SPC'
9738 THEN
9739 IF g_debug
9740 THEN
9741 hr_utility.set_location (l_proc, 993);
9742 END IF;
9743
9744 FOR i IN g_special_explosion.FIRST .. g_special_explosion.LAST
9745 LOOP
9746 IF g_debug
9747 THEN
9748 hr_utility.TRACE ('i:' || i);
9749 hr_utility.TRACE
9750 ( 'g_special_explosion(i).element_type_id:'
9751 || g_special_explosion (i).element_type_id
9752 );
9753 END IF;
9754 END LOOP;
9755
9756 IF g_debug
9757 THEN
9758 hr_utility.set_location (l_proc, 994);
9759 END IF;
9760
9761 g_count := g_count + 1;
9762
9763 IF g_debug
9764 THEN
9765 hr_utility.TRACE ('g_count:' || g_count);
9766 END IF;
9767
9768 p_error_code := 0;
9769 p_rule_to_pay := 'SPC';
9770 p_hours_to_pay_this_rule :=
9771 g_special_explosion (g_count).hours_to_pay;
9772 p_element_type_id :=
9773 g_special_explosion (g_count).element_type_id;
9774
9775 IF g_debug
9776 THEN
9777 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
9778 || p_hours_to_pay_this_rule
9779 );
9780 hr_utility.TRACE ( 'p_element_type_id :'
9781 || p_element_type_id
9782 );
9783 END IF;
9784
9785 IF g_count = g_special_explosion.COUNT
9786 THEN
9787 IF g_debug
9788 THEN
9789 hr_utility.set_location (l_proc, 995);
9790 END IF;
9791
9792 hours_left_to_pay := 0;
9793 g_explosion_to_use := NULL;
9794 g_count := 0;
9795 special_day := FALSE;
9796
9797 IF g_debug
9798 THEN
9799 hr_utility.TRACE ( 'hours_left_to_pay :'
9800 || hours_left_to_pay
9801 );
9802 hr_utility.TRACE ( 'g_explosion_to_use:'
9803 || g_explosion_to_use
9804 );
9805 hr_utility.TRACE ('g_count :' || g_count);
9806 END IF;
9807 END IF;
9808
9809 IF g_debug
9810 THEN
9811 hr_utility.set_location (l_proc, 996);
9812 END IF;
9813
9814 RETURN;
9815 ELSIF g_explosion_to_use = 'COMBO'
9816 THEN
9817 IF g_debug
9818 THEN
9819 hr_utility.set_location (l_proc, 997);
9820 END IF;
9821
9822 FOR i IN
9823 g_dy_wk_combo_explosion.FIRST .. g_dy_wk_combo_explosion.LAST
9824 LOOP
9825 IF g_debug
9826 THEN
9827 hr_utility.TRACE ('i:' || i);
9828 hr_utility.TRACE
9829 ( 'g_dy_wk_combo_explosion(i).element_type_id:'
9830 || g_dy_wk_combo_explosion (i).element_type_id
9831 );
9832 END IF;
9833 END LOOP;
9834
9835 IF g_debug
9836 THEN
9837 hr_utility.set_location (l_proc, 998);
9838 END IF;
9839
9840 g_count := g_count + 1;
9841
9842 IF g_debug
9843 THEN
9844 hr_utility.TRACE ('g_count:' || g_count);
9845 END IF;
9846
9847 p_error_code := 0;
9848 p_rule_to_pay := 'DAY';
9849 p_hours_to_pay_this_rule :=
9850 g_dy_wk_combo_explosion (g_count).hours_to_pay;
9851 p_element_type_id :=
9852 g_dy_wk_combo_explosion (g_count).element_type_id;
9853
9854 IF g_debug
9855 THEN
9856 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
9857 || p_hours_to_pay_this_rule
9858 );
9859 hr_utility.TRACE ( 'p_element_type_id :'
9860 || p_element_type_id
9861 );
9862 END IF;
9863
9864 IF g_count = g_dy_wk_combo_explosion.COUNT
9865 THEN
9866 IF g_debug
9867 THEN
9868 hr_utility.set_location (l_proc, 1000);
9869 END IF;
9870
9871 hours_left_to_pay := 0;
9872 g_explosion_to_use := NULL;
9873 g_count := 0;
9874
9875 IF g_debug
9876 THEN
9877 hr_utility.TRACE ( 'hours_left_to_pay :'
9878 || hours_left_to_pay
9879 );
9880 hr_utility.TRACE ( 'g_explosion_to_use:'
9881 || g_explosion_to_use
9882 );
9883 hr_utility.TRACE ('g_count :' || g_count);
9884 END IF;
9885 END IF;
9886
9887 IF g_debug
9888 THEN
9889 hr_utility.set_location (l_proc, 1010);
9890 END IF;
9891
9892 RETURN;
9893 ELSIF g_explosion_to_use = 'DAILY'
9894 THEN
9895 IF g_debug
9896 THEN
9897 hr_utility.set_location (l_proc, 1015);
9898 END IF;
9899
9900 FOR i IN g_daily_explosion.FIRST .. g_daily_explosion.LAST
9901 LOOP
9902 IF g_debug
9903 THEN
9904 hr_utility.TRACE ('i:' || i);
9905 hr_utility.TRACE
9906 ( 'g_daily_explosion(i).element_type_id:'
9907 || g_daily_explosion (i).element_type_id
9908 );
9909 END IF;
9910 END LOOP;
9911
9912 IF g_debug
9913 THEN
9914 hr_utility.set_location (l_proc, 1020);
9915 END IF;
9916
9917 g_count := g_count + 1;
9918
9919 IF g_debug
9920 THEN
9921 hr_utility.TRACE ('g_count:' || g_count);
9922 END IF;
9923
9924 p_error_code := 0;
9925 p_rule_to_pay := 'DAY';
9926 p_hours_to_pay_this_rule :=
9927 g_daily_explosion (g_count).hours_to_pay;
9928 p_element_type_id :=
9929 g_daily_explosion (g_count).element_type_id;
9930
9931 IF g_debug
9932 THEN
9933 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
9934 || p_hours_to_pay_this_rule
9935 );
9936 hr_utility.TRACE ( 'p_element_type_id :'
9937 || p_element_type_id
9938 );
9939 END IF;
9940
9941 IF g_count = g_daily_explosion.COUNT
9942 THEN
9943 IF g_debug
9944 THEN
9945 hr_utility.set_location (l_proc, 1025);
9946 END IF;
9947
9948 hours_left_to_pay := 0;
9949 g_explosion_to_use := NULL;
9950 g_count := 0;
9951
9952 IF g_debug
9953 THEN
9954 hr_utility.TRACE ( 'hours_left_to_pay :'
9955 || hours_left_to_pay
9956 );
9957 hr_utility.TRACE ( 'g_explosion_to_use:'
9958 || g_explosion_to_use
9959 );
9960 hr_utility.TRACE ('g_count :' || g_count);
9961 END IF;
9962 END IF;
9963
9964 IF g_debug
9965 THEN
9966 hr_utility.set_location (l_proc, 1030);
9967 END IF;
9968
9969 RETURN;
9970 ELSIF g_explosion_to_use = 'WEEKLY'
9971 THEN
9972 IF g_debug
9973 THEN
9974 hr_utility.set_location (l_proc, 1035);
9975 END IF;
9976
9977 FOR i IN g_weekly_explosion.FIRST .. g_weekly_explosion.LAST
9978 LOOP
9979 IF g_debug
9980 THEN
9981 hr_utility.TRACE ('i:' || i);
9982 hr_utility.TRACE
9983 ( 'g_weekly_explosion(i).element_type_id:'
9984 || g_weekly_explosion (i).element_type_id
9985 );
9986 END IF;
9987 END LOOP;
9988
9989 IF g_debug
9990 THEN
9991 hr_utility.set_location (l_proc, 1040);
9992 END IF;
9993
9994 g_count := g_count + 1;
9995
9996 IF g_debug
9997 THEN
9998 hr_utility.TRACE ('g_count:' || g_count);
9999 END IF;
10000
10001 p_error_code := 0;
10002 p_rule_to_pay := 'WKL';
10003 p_hours_to_pay_this_rule :=
10004 g_weekly_explosion (g_count).hours_to_pay;
10005 p_element_type_id :=
10006 g_weekly_explosion (g_count).element_type_id;
10007
10008 IF g_debug
10009 THEN
10010 hr_utility.TRACE ( 'p_hours_to_pay_this_rule:'
10011 || p_hours_to_pay_this_rule
10012 );
10013 hr_utility.TRACE ( 'p_element_type_id :'
10014 || p_element_type_id
10015 );
10016 END IF;
10017
10018 IF g_count = g_weekly_explosion.COUNT
10019 THEN
10020 IF g_debug
10021 THEN
10022 hr_utility.set_location (l_proc, 1045);
10023 END IF;
10024
10025 hours_left_to_pay := 0;
10026 g_explosion_to_use := NULL;
10027 g_count := 0;
10028
10029 IF g_debug
10030 THEN
10031 hr_utility.TRACE ( 'hours_left_to_pay :'
10032 || hours_left_to_pay
10033 );
10034 hr_utility.TRACE ( 'g_explosion_to_use:'
10035 || g_explosion_to_use
10036 );
10037 hr_utility.TRACE ('g_count :' || g_count);
10038 END IF;
10039 END IF;
10040
10041 IF g_debug
10042 THEN
10043 hr_utility.set_location (l_proc, 1050);
10044 END IF;
10045
10046 RETURN;
10047 END IF;
10048
10049 IF g_debug
10050 THEN
10051 hr_utility.set_location (l_proc, 1055);
10052 END IF;
10053 END IF; --g_explosion_to_use is not null
10054
10055 IF g_debug
10056 THEN
10057 hr_utility.set_location (l_proc, 1060);
10058 END IF;
10059 END;
10060
10061 --------------------------------------------------------------------------------
10062 PROCEDURE reset_rules (
10063 p_hours_paid_daily_rule IN OUT NOCOPY NUMBER,
10064 p_hours_paid_weekly_rule IN OUT NOCOPY NUMBER,
10065 p_fetch_next_day OUT NOCOPY BOOLEAN,
10066 p_fetch_next_week OUT NOCOPY BOOLEAN,
10067 p_rule_used IN VARCHAR2
10068 )
10069 IS
10070 -- recalculates total accumulations towards meeting the various caps
10071 -- after a sub-segment has been paid
10072 -- 'fetch next' set to true if a cap has been met and a new rule is needed
10073 BEGIN
10074 IF g_debug
10075 THEN
10076 hr_utility.set_location ('Reset_rules', 1);
10077 END IF;
10078
10079 p_fetch_next_day := FALSE;
10080 p_fetch_next_week := FALSE;
10081
10082 IF g_debug
10083 THEN
10084 hr_utility.TRACE ('g_egt_id :' || g_egt_id);
10085 hr_utility.TRACE ( 'element_type_id_to_pay :'
10086 || element_type_id_to_pay
10087 );
10088 hr_utility.TRACE ( 'special_and_weekly_base :'
10089 || special_and_weekly_base
10090 );
10091 hr_utility.TRACE ( 'g_date_worked :'
10092 || TO_CHAR (g_date_worked, 'dd/mon/yy')
10093 );
10094 hr_utility.TRACE ('p_rule_used :' || p_rule_used);
10095 hr_utility.TRACE ( 'hours_to_pay_this_rule :'
10096 || hours_to_pay_this_rule
10097 );
10098 hr_utility.TRACE ( 'p_hours_paid_daily_rule :'
10099 || p_hours_paid_daily_rule
10100 );
10101 hr_utility.TRACE ( 'p_hours_paid_weekly_rule:'
10102 || p_hours_paid_weekly_rule
10103 );
10104 hr_utility.TRACE ('daily_rule_cap :' || daily_rule_cap);
10105 hr_utility.TRACE ('weekly_rule_cap :' || weekly_rule_cap);
10106 END IF;
10107
10108 IF g_egt_id IS NULL
10109 OR p_rule_used = 'WKL'
10110 OR hxt_td_util.include_for_ot_cap (g_egt_id,
10111 element_type_id_to_pay,
10112 special_and_weekly_base,
10113 g_date_worked
10114 )
10115 THEN
10116 -- everything counted if no include group
10117
10118 --Added this for Bug 1801337 because when rule to pay is 'WKL'
10119 --and hours_to_pay_this_rule = 0 then next fetch should be set to true so that
10120 --the 'Loop Counter Exceeded' error does not occur and the next row of the
10121 --weekly_earn_rule_cur is fetched
10122 IF g_debug
10123 THEN
10124 hr_utility.set_location ('reset_rules', 2);
10125 END IF;
10126
10127 IF p_rule_used = 'WKL' AND hours_to_pay_this_rule = 0
10128 THEN
10129 IF g_debug
10130 THEN
10131 hr_utility.set_location ('reset_rules', 3);
10132 END IF;
10133
10134 p_fetch_next_week := TRUE;
10135 first_weekly_cap_reached := TRUE;
10136 END IF;
10137
10138 p_hours_paid_daily_rule :=
10139 p_hours_paid_daily_rule + hours_to_pay_this_rule;
10140 p_hours_paid_weekly_rule :=
10141 p_hours_paid_weekly_rule + hours_to_pay_this_rule;
10142
10143 IF g_debug
10144 THEN
10145 hr_utility.TRACE ( 'p_hours_paid_daily_rule :'
10146 || p_hours_paid_daily_rule
10147 );
10148 hr_utility.TRACE ( 'p_hours_paid_weekly_rule:'
10149 || p_hours_paid_weekly_rule
10150 );
10151 END IF;
10152 ELSIF p_rule_used = 'DAY' OR p_rule_used = 'SPC'
10153 THEN -- SPR C355
10154 -- OT daily hours not counted for weekly cap
10155 IF g_debug
10156 THEN
10157 hr_utility.set_location ('reset_rules', 4);
10158 END IF;
10159
10160 p_hours_paid_daily_rule :=
10161 p_hours_paid_daily_rule + hours_to_pay_this_rule;
10162
10163 IF g_debug
10164 THEN
10165 hr_utility.TRACE ( 'p_hours_paid_daily_rule :'
10166 || p_hours_paid_daily_rule
10167 );
10168 END IF;
10169 END IF;
10170
10171 IF p_hours_paid_daily_rule >= daily_rule_cap
10172 AND p_rule_used = 'DAY'
10173 AND consecutive_days_reached = FALSE
10174 THEN
10175 -- do not reset daily hours if counting toward special cap
10176 IF g_debug
10177 THEN
10178 hr_utility.set_location ('reset_rules', 5);
10179 END IF;
10180
10181 p_fetch_next_day := TRUE;
10182 END IF;
10183
10184 -- Bug 1801337 mhanda
10185 -- If the OTM day starts with the day policy, it completes the day policy.
10186 -- If the OTM day starts eligible for the week policy it uses the week policy.
10187 -- If the OTM day starts with the Special policy, then it uses the special day.
10188 -- FAZ-MHANDA changed this condition on 26-oct-02
10189 IF p_hours_paid_weekly_rule >= weekly_rule_cap
10190 THEN
10191 -- FAZ-MHANDA commented on 26-oct-02
10192 -- IF (p_hours_paid_weekly_rule - p_hours_paid_daily_rule) > weekly_rule_cap THEN
10193 IF g_debug
10194 THEN
10195 hr_utility.set_location ('reset_rules', 6);
10196 END IF;
10197
10198 p_fetch_next_week := TRUE;
10199 first_weekly_cap_reached := TRUE;
10200 ELSIF p_hours_paid_weekly_rule < weekly_rule_cap
10201 THEN
10202 IF g_debug
10203 THEN
10204 hr_utility.set_location ('reset_rules', 7);
10205 END IF;
10206
10207 first_weekly_cap_reached := FALSE;
10208 END IF;
10209
10210 IF g_debug
10211 THEN
10212 hr_utility.set_location ('reset_rules', 8);
10213 END IF;
10214 END;
10215 ----------------------------Gen Special Main Section ---------------------------
10216 BEGIN -- Gen Special
10217 g_debug := hr_utility.debug_enabled;
10218 hxt_util.DEBUG ('Top of Gen_Special.'); -- debug only --HXT115
10219 hxt_util.DEBUG ('person id ' || TO_CHAR (g_person_id));
10220
10221 -- debug only --HXT115
10222 IF g_debug
10223 THEN
10224 hr_utility.TRACE ('--------------Gen Special-----------------');
10225 hr_utility.set_location ('hxt_time_detail.gen_special', 1);
10226 hr_utility.TRACE ( 'p_time_in :'
10227 || TO_CHAR (p_time_in, 'DD-MON-YYYY HH24:MI:SS')
10228 );
10229 hr_utility.TRACE ( 'p_time_out :'
10230 || TO_CHAR (p_time_out, 'DD_MON-YYYY HH24:MI:SS')
10231 );
10232 hr_utility.TRACE ('person id :' || TO_CHAR (g_person_id));
10233 END IF;
10234
10235 IF g_special_explosion.COUNT > 0
10236 THEN
10237 FOR i IN g_special_explosion.FIRST .. g_special_explosion.LAST
10238 LOOP
10239 g_special_explosion (i).element_type_id := NULL;
10240 g_special_explosion (i).hours_to_pay := NULL;
10241 END LOOP;
10242
10243 IF g_debug
10244 THEN
10245 hr_utility.TRACE ('Deleted g_special_explosion PL/SQL table');
10246 END IF;
10247
10248 g_special_explosion.DELETE;
10249 END IF;
10250
10251 IF g_dy_wk_combo_explosion.COUNT > 0
10252 THEN
10253 FOR i IN
10254 g_dy_wk_combo_explosion.FIRST .. g_dy_wk_combo_explosion.LAST
10255 LOOP
10256 g_dy_wk_combo_explosion (i).element_type_id := NULL;
10257 g_dy_wk_combo_explosion (i).hours_to_pay := NULL;
10258 END LOOP;
10259
10260 IF g_debug
10261 THEN
10262 hr_utility.TRACE ('Deleted combo PL/SQL table');
10263 END IF;
10264
10265 g_dy_wk_combo_explosion.DELETE;
10266 END IF;
10267
10268 IF g_daily_explosion.COUNT > 0
10269 THEN
10270 FOR i IN g_daily_explosion.FIRST .. g_daily_explosion.LAST
10271 LOOP
10272 g_daily_explosion (i).element_type_id := NULL;
10273 g_daily_explosion (i).hours_to_pay := NULL;
10274 g_daily_explosion (i).earning_category := NULL;
10275 END LOOP;
10276
10277 IF g_debug
10278 THEN
10279 hr_utility.TRACE ('Deleted daily PL/SQL table');
10280 END IF;
10281
10282 g_daily_explosion.DELETE;
10283 END IF;
10284
10285 IF g_weekly_explosion.COUNT > 0
10286 THEN
10287 FOR i IN g_weekly_explosion.FIRST .. g_weekly_explosion.LAST
10288 LOOP
10289 g_weekly_explosion (i).element_type_id := NULL;
10290 g_weekly_explosion (i).hours_to_pay := NULL;
10291 g_weekly_explosion (i).earning_category := NULL;
10292 END LOOP;
10293
10294 IF g_debug
10295 THEN
10296 hr_utility.TRACE ('Deleted weekly PL/SQL table');
10297 END IF;
10298
10299 g_weekly_explosion.DELETE;
10300 END IF;
10301
10302 IF g_daily_earn_category.COUNT > 0
10303 THEN
10304 FOR i IN g_daily_earn_category.FIRST .. g_daily_earn_category.LAST
10305 LOOP
10306 g_daily_earn_category (i).element_type_id := NULL;
10307 g_daily_earn_category (i).hours := NULL;
10308 g_daily_earn_category (i).earning_category := NULL;
10309 END LOOP;
10310
10311 IF g_debug
10312 THEN
10313 hr_utility.TRACE ('Deleted g_daily_earn_category PL/SQL table');
10314 END IF;
10315
10316 g_daily_earn_category.DELETE;
10317 END IF;
10318
10319 IF g_weekly_earn_category.COUNT > 0
10320 THEN
10321 FOR i IN g_weekly_earn_category.FIRST .. g_weekly_earn_category.LAST
10322 LOOP
10323 g_weekly_earn_category (i).element_type_id := NULL;
10324 g_weekly_earn_category (i).hours := NULL;
10325 g_weekly_earn_category (i).earning_category := NULL;
10326 END LOOP;
10327
10328 IF g_debug
10329 THEN
10330 hr_utility.TRACE ('Deleted g_weekly_earn_category PL/SQL table');
10331 END IF;
10332
10333 g_weekly_earn_category.DELETE;
10334 END IF;
10335
10336 -- Determine which earning rule TYPE should be used.
10337 -- If element category is null, means hours passed are hours worked that day.
10338 -- Pay hours using regular daily rules, unless hours worked are on a holiday.
10339 -- Then pay hours using holiday rules.
10340 -- Determine the Earning Category - Validated earlier
10341 IF g_debug
10342 THEN
10343 hr_utility.TRACE ('g_element_type_id :' || g_element_type_id);
10344 END IF;
10345
10346 IF g_element_type_id IS NULL
10347 THEN
10348 summary_earning_category := NULL;
10349 ELSE
10350 -- BEGIN ORACLE bug #712501
10351 summary_earning_category :=
10352 hxt_util.element_cat (g_element_type_id, g_date_worked);
10353 -- END ORACLE bug #712501
10354 END IF;
10355
10356 IF g_debug
10357 THEN
10358 hr_utility.TRACE ( 'summary_earning_category :'
10359 || summary_earning_category
10360 );
10361 hr_utility.set_location ('hxt_time_detail.gen_special', 2);
10362 END IF;
10363
10364 IF summary_earning_category IS NULL
10365 THEN --- regular hours worked
10366 IF g_hol_yn = 'Y' AND holiday_rule_found(g_ep_id, g_date_worked)
10367 THEN --- day is a holiday
10368 rule_type_to_pay := 'HOL'; --- then use holiday rules
10369 ELSE --- normal work day
10370 rule_type_to_pay := 'DAY'; --- then use daily rules
10371 END IF;
10372 ELSIF summary_earning_category IN
10373 ('ABS', 'OVT', 'REG', 'SDF', 'OTH', 'OSP', 'REG2')
10374 THEN
10375 rule_type_to_pay := 'ABS';
10376 ELSE
10377 rule_type_to_pay := NULL;
10378 fnd_message.set_name ('HXT', 'HXT_39304_INV_ERN_CAT');
10379 ERROR_CODE :=
10380 call_hxthxc_gen_error ('HXT',
10381 'HXT_39304_INV_ERN_CAT',
10382 NULL,
10383 LOCATION,
10384 ''
10385 );
10386
10387 --2278400 error_code := call_gen_error(location, '');
10388 IF ERROR_CODE > l_error_return
10389 THEN
10390 l_error_return := ERROR_CODE;
10391 END IF;
10392 END IF;
10393
10394 IF g_debug
10395 THEN
10396 hr_utility.TRACE ('rule_type_to_pay :' || rule_type_to_pay);
10397 END IF;
10398
10399 OPEN check_spc_dy_eg;
10400
10401 FETCH check_spc_dy_eg
10402 INTO g_spc_dy_eg;
10403
10404 CLOSE check_spc_dy_eg;
10405
10406 IF g_debug
10407 THEN
10408 hr_utility.TRACE ('g_SPC_DY_EG:' || g_spc_dy_eg);
10409 END IF;
10410
10411 IF rule_type_to_pay = 'ABS'
10412 THEN
10413 IF g_debug
10414 THEN
10415 hr_utility.set_location ('hxt_time_detail.gen_special', 3);
10416 hr_utility.TRACE
10417 ('-----------Entering rule_type_to_pay = ABS------------');
10418 END IF;
10419
10420 -- Pay absence hours with earning element from Summary (parent) record.
10421 IF g_debug
10422 THEN
10423 hr_utility.TRACE ('g_sdf_id:' || g_sdf_id);
10424 hr_utility.TRACE ('g_osp_id:' || g_osp_id);
10425 END IF;
10426
10427 ERROR_CODE :=
10428 pay (p_hours_worked,
10429 g_element_type_id,
10430 p_time_in,
10431 p_time_out,
10432 g_date_worked,
10433 g_id -- parent id
10434 ,
10435 g_assignment_id,
10436 g_fcl_earn_reason_code,
10437 g_ffv_cost_center_id,
10438 g_ffv_labor_account_id,
10439 g_tas_id,
10440 g_location_id,
10441 g_sht_id,
10442 g_hrw_comment,
10443 g_ffv_rate_code_id,
10444 g_rate_multiple,
10445 g_hourly_rate,
10446 g_amount,
10447 g_fcl_tax_rule_code,
10448 g_separate_check_flag,
10449 g_project_id -- ,g_GROUP_ID
10450 ,
10451 g_ep_id,
10452 a_state_name => g_state_name,
10453 a_county_name => g_county_name,
10454 a_city_name => g_city_name,
10455 a_zip_code => g_zip_code
10456 );
10457
10458 IF g_debug
10459 THEN
10460 hr_utility.set_location ('hxt_time_detail.gen_special', 4);
10461 END IF;
10462
10463 IF ERROR_CODE <> 0
10464 THEN
10465 IF ERROR_CODE > l_error_return
10466 THEN
10467 l_error_return := ERROR_CODE;
10468 END IF;
10469
10470 hxt_util.DEBUG ( 'Loc D. Return code is '
10471 || TO_CHAR (l_error_return)
10472 );
10473
10474 IF g_debug
10475 THEN
10476 hr_utility.TRACE ( 'Loc D. Return code is :'
10477 || TO_CHAR (l_error_return)
10478 );
10479 END IF;
10480
10481 RETURN l_error_return;
10482 END IF;
10483
10484 IF g_debug
10485 THEN
10486 hr_utility.set_location ('hxt_time_detail.gen_special', 4.2);
10487 hr_utility.TRACE ( 'date_worked :'
10488 || TO_CHAR (g_date_worked, 'DD/MON/YY')
10489 );
10490 hr_utility.TRACE ('g_call_adjust_abs :' || g_call_adjust_abs);
10491 hr_utility.TRACE ('g_ep_id:' || g_ep_id);
10492 hr_utility.TRACE ('g_element_type_id:' || g_element_type_id);
10493 END IF;
10494
10495 IF g_call_adjust_abs = 'Y'
10496 THEN
10497 IF g_debug
10498 THEN
10499 hr_utility.set_location ('hxt_time_detail.gen_special', 4.3);
10500 END IF;
10501
10502 -- begin 688072
10503 IF g_ep_type IN ('WEEKLY', 'SPECIAL')
10504 THEN
10505 -- Bug 2795054
10506 IF g_debug
10507 THEN
10508 hr_utility.set_location ('hxt_time_detail.gen_special',
10509 4.4);
10510 END IF;
10511
10512 -- Bug 2795054
10513 -- Check if the Absence element count towards the Weekly Overtime cap,
10514 -- if yes only then call adjust for absence to re-adjust these absence
10515 -- hours over the previous days of the week.
10516 l_abs_in_eg := NULL;
10517
10518 OPEN check_abs_elem;
10519
10520 FETCH check_abs_elem
10521 INTO l_abs_in_eg;
10522
10523 CLOSE check_abs_elem;
10524
10525 IF g_debug
10526 THEN
10527 hr_utility.TRACE ('l_abs_in_eg:' || l_abs_in_eg);
10528 END IF;
10529
10530 IF (l_abs_in_eg IS NOT NULL)
10531 THEN
10532 IF g_debug
10533 THEN
10534 hr_utility.set_location ('hxt_time_detail.gen_special',
10535 4.5
10536 );
10537 END IF;
10538
10539 ERROR_CODE :=
10540 adjust_for_absence (g_tim_id, g_ep_id, g_date_worked);
10541
10542 IF g_debug
10543 THEN
10544 hr_utility.set_location ('hxt_time_detail.gen_special',
10545 5
10546 );
10547 hr_utility.TRACE ('error_code :' || ERROR_CODE);
10548 END IF;
10549
10550 --SIR491 Begin
10551 IF ERROR_CODE = 1
10552 THEN
10553 IF g_debug
10554 THEN
10555 hr_utility.set_location
10556 ('hxt_time_detail.gen_special',
10557 5.1
10558 );
10559 END IF;
10560
10561 fnd_message.set_name ('HXT', 'HXT_39577_NO_HOURS_ADJUST');
10562 ERROR_CODE :=
10563 call_hxthxc_gen_error ('HXT',
10564 'HXT_39577_NO_HOURS_ADJUST',
10565 NULL,
10566 LOCATION,
10567 ''
10568 );
10569 --2278400 error_code := call_gen_error(location, '');
10570 ELSIF ERROR_CODE = 2
10571 THEN
10572 IF g_debug
10573 THEN
10574 hr_utility.set_location
10575 ('hxt_time_detail.gen_special',
10576 5.2
10577 );
10578 END IF;
10579
10580 fnd_message.set_name ('HXT',
10581 'HXT_39311_WKLY_ERN_RULES_NF'
10582 );
10583 ERROR_CODE :=
10584 call_hxthxc_gen_error ('HXT',
10585 'HXT_39311_WKLY_ERN_RULES_NF',
10586 NULL,
10587 LOCATION,
10588 ''
10589 );
10590 -- 2278400 error_code := call_gen_error(location, '');
10591 ELSIF ERROR_CODE = 3
10592 THEN
10593 IF g_debug
10594 THEN
10595 hr_utility.set_location
10596 ('hxt_time_detail.gen_special',
10597 5.3
10598 );
10599 END IF;
10600
10601 fnd_message.set_name ('HXT', 'HXT_39578_PAY_FAILED');
10602 ERROR_CODE :=
10603 call_hxthxc_gen_error ('HXT',
10604 'HXT_39578_PAY_FAILED',
10605 NULL,
10606 LOCATION,
10607 ''
10608 );
10609 -- 2278400 error_code := call_gen_error(location, '');
10610 END IF;
10611
10612 IF g_debug
10613 THEN
10614 hr_utility.TRACE ('l_error_return :' || l_error_return);
10615 END IF;
10616
10617 IF ERROR_CODE > l_error_return
10618 THEN
10619 IF g_debug
10620 THEN
10621 hr_utility.set_location
10622 ('hxt_time_detail.gen_special',
10623 6
10624 );
10625 END IF;
10626
10627 l_error_return := ERROR_CODE;
10628
10629 IF g_debug
10630 THEN
10631 hr_utility.TRACE ( 'Loc E. Return code is :'
10632 || TO_CHAR (l_error_return)
10633 );
10634 END IF;
10635 END IF;
10636
10637 --SIR491 END
10638 IF g_debug
10639 THEN
10640 hr_utility.set_location ('hxt_time_detail.gen_special',
10641 6.1
10642 );
10643 END IF;
10644 END IF;
10645
10646 IF g_debug
10647 THEN
10648 hr_utility.set_location ('hxt_time_detail.gen_special',
10649 6.2);
10650 END IF;
10651 END IF;
10652
10653 IF g_debug
10654 THEN
10655 hr_utility.set_location ('hxt_time_detail.gen_special', 6.3);
10656 END IF;
10657 -- end 688072
10658 END IF;
10659 ELSE -- rule_type_to_pay <> ABS
10660 IF g_debug
10661 THEN
10662 hr_utility.set_location ('hxt_time_detail.gen_special', 7);
10663 hr_utility.TRACE
10664 ('------------rule_type_to_pay <> ABS------------');
10665 END IF;
10666
10667 -- Loop through the earning rules for the earning policy
10668 -- Finish when the hours to be paid are all done
10669 -- all_detail_hours shows the hours for the day already in detail records
10670 previous_detail_hours_day :=
10671 contig_hours_worked (g_date_worked, g_egt_id, g_tim_id);
10672
10673 IF g_debug
10674 THEN
10675 hr_utility.TRACE ( 'previous_detail_hours_day :'
10676 || previous_detail_hours_day
10677 );
10678 END IF;
10679
10680 hours_paid_daily_rule := NVL (previous_detail_hours_day, 0);
10681
10682 --from daily view
10683 IF g_debug
10684 THEN
10685 hr_utility.TRACE ('hours_paid_daily_rule:'
10686 || hours_paid_daily_rule
10687 );
10688 END IF;
10689
10690 -- The previous call to procedure adjust_for_hdp has been commented
10691 -- out(not -- used anymore)
10692 -- hours_left_to_pay := adjust_for_hdp (p_hours_worked, ERROR_CODE);
10693 hours_left_to_pay := p_hours_worked;
10694
10695 IF g_debug
10696 THEN
10697 hr_utility.TRACE ('hours_left_to_pay:' || hours_left_to_pay);
10698 END IF;
10699
10700 IF ERROR_CODE > l_error_return
10701 THEN
10702 IF g_debug
10703 THEN
10704 hr_utility.set_location ('hxt_time_detail.gen_special', 10);
10705 END IF;
10706
10707 l_error_return := ERROR_CODE;
10708 hxt_util.DEBUG ( 'Loc F. Return code is '
10709 || TO_CHAR (l_error_return)
10710 ); -- debug only
10711
10712 IF g_debug
10713 THEN
10714 hr_utility.TRACE ( 'Loc F. Return code is :'
10715 || TO_CHAR (l_error_return)
10716 );
10717 END IF;
10718 END IF;
10719
10720 hxt_util.DEBUG ('Hours left to pay is '
10721 || TO_CHAR (hours_left_to_pay)
10722 ); -- debug only --HXT115
10723
10724 -- Open the daily earning rules cursor and fetch the special row.
10725 -- If none is found the consecutive day limit flag is set to false.
10726 -- This can be done this way now as there is only one special rule allowed.
10727 -- If more are allowed in the future a loop may be needed to go through the
10728 -- rules.
10729 -- Weekly set to 999 if none found.
10730 IF g_debug
10731 THEN
10732 hr_utility.set_location ('hxt_time_detail.gen_special', 11);
10733 END IF;
10734
10735 seven_day_cal_rule := FALSE;
10736 five_day_cal_rule := FALSE;
10737 consecutive_days_reached := FALSE;
10738
10739 OPEN daily_earn_rules_cur (g_ep_id, 'SPC');
10740
10741 FETCH daily_earn_rules_cur
10742 INTO special_daily_cap, special_earning_type,
10743 consecutive_days_limit;
10744
10745 IF g_debug
10746 THEN
10747 hr_utility.TRACE ('special_daily_cap :' || special_daily_cap);
10748 hr_utility.TRACE ( 'special_earning_type :'
10749 || special_earning_type
10750 );
10751 hr_utility.TRACE ( 'consecutive_days_limit :'
10752 || consecutive_days_limit
10753 );
10754 END IF;
10755
10756 IF daily_earn_rules_cur%FOUND
10757 THEN
10758 IF g_debug
10759 THEN
10760 hr_utility.set_location ('hxt_time_detail.gen_special', 12);
10761 END IF;
10762
10763 -- Now that we know there is at least one day rule, determine how many
10764 -- consecutive days worked. Use the rule with the highest day number
10765 -- less than or equal to consec days worked.
10766 CLOSE daily_earn_rules_cur;
10767
10768 IF g_debug
10769 THEN
10770 hr_utility.TRACE ('g_SPC_DY_EG:' || g_spc_dy_eg);
10771 END IF;
10772
10773 IF g_spc_dy_eg IS NOT NULL
10774 THEN
10775 consec_days_worked :=
10776 consecutivedaysworked_for_spc (g_date_worked);
10777
10778 IF g_debug
10779 THEN
10780 hr_utility.TRACE ( 'date_worked :'
10781 || TO_CHAR (g_date_worked, 'DD/MON/YY')
10782 );
10783 hr_utility.TRACE ( 'consec_days_worked:'
10784 || TO_CHAR (consec_days_worked)
10785 );
10786 END IF;
10787 ELSE
10788 consec_days_worked := getconsecutivedaysworked (g_date_worked);
10789
10790 IF g_debug
10791 THEN
10792 hr_utility.TRACE ( 'date_worked:'
10793 || TO_CHAR (g_date_worked, 'DD/MON/YY')
10794 );
10795 hr_utility.TRACE ( 'consec_days_worked:'
10796 || TO_CHAR (consec_days_worked)
10797 );
10798 END IF;
10799 END IF;
10800
10801 OPEN spc_earn_rules_cur (g_ep_id, consec_days_worked);
10802
10803 FETCH spc_earn_rules_cur
10804 INTO special_daily_cap, special_earning_type,
10805 consecutive_days_limit;
10806
10807 hxt_util.DEBUG ( 'cap,earn_type,days'
10808 || TO_CHAR (special_daily_cap)
10809 || ',' -- debug only
10810 || TO_CHAR (special_earning_type)
10811 || ',' -- debug only
10812 || TO_CHAR (consecutive_days_limit)
10813 ); -- debug only
10814
10815 IF g_debug
10816 THEN
10817 hr_utility.TRACE ( 'special_daily_cap :'
10818 || TO_CHAR (special_daily_cap)
10819 );
10820 hr_utility.TRACE ( 'special_earning_type :'
10821 || TO_CHAR (special_earning_type)
10822 );
10823 hr_utility.TRACE ( 'consecutive_days_limit:'
10824 || TO_CHAR (consecutive_days_limit)
10825 );
10826 END IF;
10827
10828 IF spc_earn_rules_cur%FOUND
10829 THEN
10830 IF g_debug
10831 THEN
10832 hr_utility.set_location ('hxt_time_detail.gen_special', 13);
10833 END IF;
10834
10835 FETCH spc_earn_rules_cur
10836 INTO special_daily_cap2, special_earning_type2,
10837 consecutive_days_limit2;
10838
10839 IF consecutive_days_limit <> consecutive_days_limit2
10840 THEN
10841 IF g_debug
10842 THEN
10843 hr_utility.set_location ('hxt_time_detail.gen_special',
10844 14
10845 );
10846 END IF;
10847
10848 special_daily_cap2 := 99;
10849 special_earning_type2 := NULL;
10850 END IF;
10851
10852 IF consec_days_worked >= consecutive_days_limit
10853 THEN
10854 IF g_debug
10855 THEN
10856 hr_utility.set_location ('hxt_time_detail.gen_special',
10857 15
10858 );
10859 END IF;
10860
10861 consecutive_days_reached := TRUE;
10862 ELSE
10863 IF g_debug
10864 THEN
10865 hr_utility.set_location ('hxt_time_detail.gen_special',
10866 16
10867 );
10868 END IF;
10869
10870 consecutive_days_reached := FALSE;
10871 END IF;
10872
10873 IF consecutive_days_limit = 7
10874 THEN
10875 IF g_debug
10876 THEN
10877 hr_utility.set_location ('hxt_time_detail.gen_special',
10878 17
10879 );
10880 END IF;
10881
10882 seven_day_cal_rule := TRUE;
10883 ELSIF consecutive_days_limit = 5
10884 THEN
10885 IF g_debug
10886 THEN
10887 hr_utility.set_location ('hxt_time_detail.gen_special',
10888 18
10889 );
10890 END IF;
10891
10892 five_day_cal_rule := TRUE;
10893 END IF;
10894
10895 hxt_util.DEBUG ( '2nd cap,earn_type,days,reached'
10896 || TO_CHAR (special_daily_cap2)
10897 || ',' -- debug only
10898 || TO_CHAR (special_earning_type2)
10899 || ',' -- debug only
10900 || TO_CHAR (consecutive_days_limit2)
10901 ); -- debug only
10902
10903 IF g_debug
10904 THEN
10905 hr_utility.TRACE ( 'special_daily_cap2 :'
10906 || TO_CHAR (special_daily_cap2)
10907 );
10908 hr_utility.TRACE ( 'special_earning_type2 :'
10909 || TO_CHAR (special_earning_type2)
10910 );
10911 hr_utility.TRACE ( 'consecutive_days_limit2 :'
10912 || TO_CHAR (consecutive_days_limit2)
10913 );
10914 END IF;
10915 ELSE -- spc_earn_rules_cur NOT FOUND
10916 IF g_debug
10917 THEN
10918 hr_utility.set_location ('hxt_time_detail.gen_special', 19);
10919 END IF;
10920
10921 special_daily_cap := 99;
10922 special_earning_type := NULL;
10923 special_daily_cap2 := 99;
10924 special_earning_type2 := NULL;
10925 END IF;
10926 ELSE -- daily_earn_rules_cur NOT FOUND (NO SPECIAL (DAYS) RULE)
10927 IF g_debug
10928 THEN
10929 hr_utility.set_location ('hxt_time_detail.gen_special', 20);
10930 END IF;
10931
10932 CLOSE daily_earn_rules_cur;
10933 END IF;
10934
10935 -- Open the daily and weekly cursors and fetch the first row of each.
10936 -- The two must be processed differently now as the daily hours are for the
10937 -- earning type of the current daily rule while the weekly earning type is
10938 -- applied to the hours of the next weekly rule if there are any.
10939 OPEN daily_earn_rules_cur (g_ep_id, 'DAY');
10940
10941 FETCH daily_earn_rules_cur
10942 INTO daily_rule_cap, daily_earning_type, dummy_days;
10943
10944 first_daily_rule_cap := daily_rule_cap;
10945
10946 IF g_debug
10947 THEN
10948 hr_utility.TRACE ('first_daily_rule_cap:' || first_daily_rule_cap);
10949 hr_utility.TRACE ('g_EP_TYPE :' || g_ep_type);
10950 END IF;
10951
10952 IF (daily_earn_rules_cur%NOTFOUND AND (g_ep_type = 'WEEKLY'))
10953 THEN
10954 IF g_debug
10955 THEN
10956 hr_utility.set_location ('hxt_time_detail.gen_special', 21);
10957 hr_utility.TRACE
10958 ('daily_earn_rules_cur NOTFOUND and EP_TYPE = WEEKLY');
10959 END IF;
10960
10961 daily_rule_cap := 24;
10962 first_daily_rule_cap := 24;
10963 END IF;
10964
10965 IF (daily_earn_rules_cur%NOTFOUND AND (g_ep_type <> 'WEEKLY'))
10966 THEN
10967 IF g_debug
10968 THEN
10969 hr_utility.set_location ('hxt_time_detail.gen_special', 22);
10970 hr_utility.TRACE
10971 ('daily_earn_rules_cur NOTFOUND and EP_TYPE<>WEEKLY');
10972 END IF;
10973
10974 fnd_message.set_name ('HXT', 'HXT_39307_DAILY_BASE_REC_NF');
10975 ERROR_CODE :=
10976 call_hxthxc_gen_error ('HXT',
10977 'HXT_39307_DAILY_BASE_REC_NF',
10978 NULL,
10979 LOCATION,
10980 ''
10981 );
10982
10983 --2278400 error_code := call_gen_error(location, '');
10984 IF ERROR_CODE > l_error_return
10985 THEN
10986 l_error_return := ERROR_CODE;
10987 hxt_util.DEBUG ( 'Loc G. Return code is '
10988 || TO_CHAR (l_error_return)
10989 );
10990
10991 IF g_debug
10992 THEN
10993 hr_utility.TRACE ( 'Loc G. Return code is:'
10994 || TO_CHAR (l_error_return)
10995 );
10996 END IF;
10997 END IF;
10998 END IF;
10999
11000 special_and_weekly_base := daily_earning_type;
11001
11002 IF g_debug
11003 THEN
11004 hr_utility.TRACE ( 'special_and_weekly_base :'
11005 || special_and_weekly_base
11006 );
11007 END IF;
11008
11009 -- base for special and weekly earnings as none can be specified except
11010 -- on a weekly type policy
11011 IF rule_type_to_pay <> 'DAY'
11012 THEN -- for now only HOL
11013 IF g_debug
11014 THEN
11015 hr_utility.set_location ('hxt_time_detail.gen_special', 23);
11016 END IF;
11017
11018 CLOSE daily_earn_rules_cur; -- opened with parameter DAY
11019
11020 OPEN daily_earn_rules_cur (g_ep_id, rule_type_to_pay);
11021
11022 -- open for HOL rules
11023 FETCH daily_earn_rules_cur
11024 INTO daily_rule_cap, daily_earning_type, dummy_days;
11025
11026 IF daily_earn_rules_cur%NOTFOUND
11027 THEN
11028 IF g_debug
11029 THEN
11030 hr_utility.set_location ('hxt_time_detail.gen_special', 24);
11031 END IF;
11032
11033 end_of_day_rules := TRUE;
11034 END IF;
11035 END IF;
11036
11037 IF g_debug
11038 THEN
11039 hr_utility.TRACE ('g_ep_id :' || g_ep_id);
11040 END IF;
11041
11042 OPEN weekly_earn_rules_cur (g_ep_id);
11043
11044 IF g_debug
11045 THEN
11046 hr_utility.TRACE
11047 ('---------OPEN weekly_earn_rules_cur-----------');
11048 END IF;
11049
11050 FETCH weekly_earn_rules_cur
11051 INTO weekly_rule_cap, weekly_earning_type;
11052
11053 IF g_debug
11054 THEN
11055 hr_utility.TRACE
11056 ('---------FETCHED weekly_earn_rules_cur----------');
11057 hr_utility.TRACE ('weekly_rule_cap :' || weekly_rule_cap);
11058 hr_utility.TRACE ('weekly_earning_type :' || weekly_earning_type);
11059 END IF;
11060
11061 IF weekly_earn_rules_cur%NOTFOUND
11062 THEN
11063 IF g_debug
11064 THEN
11065 hr_utility.set_location ('hxt_time_detail.gen_special', 25);
11066 END IF;
11067
11068 IF g_ep_type = 'WEEKLY'
11069 THEN
11070 IF g_debug
11071 THEN
11072 hr_utility.set_location ('hxt_time_detail.gen_special', 26);
11073 END IF;
11074
11075 fnd_message.set_name ('HXT', 'HXT_39311_WKLY_ERN_RULES_NF');
11076 ERROR_CODE :=
11077 call_hxthxc_gen_error ('HXT',
11078 'HXT_39311_WKLY_ERN_RULES_NF',
11079 NULL,
11080 LOCATION,
11081 ''
11082 );
11083
11084 --2278400 error_code := call_gen_error(location, '');
11085 IF ERROR_CODE > l_error_return
11086 THEN
11087 IF g_debug
11088 THEN
11089 hr_utility.set_location ('hxt_time_detail.gen_special',
11090 27
11091 );
11092 END IF;
11093
11094 l_error_return := ERROR_CODE;
11095 hxt_util.DEBUG ( 'Loc H. Return code is '
11096 || TO_CHAR (l_error_return)
11097 );
11098 END IF; --SIR014
11099 ELSE
11100 IF g_debug
11101 THEN
11102 hr_utility.set_location ('hxt_time_detail.gen_special', 28);
11103 END IF;
11104
11105 weekly_rule_cap := 999;
11106 hours_paid_weekly_rule := 0;
11107 END IF;
11108 END IF;
11109
11110
11111 -- Bug 6854096
11112 -- Reverted back the below changes made for 5260857.
11113 -- This was done to cater for a slight change in OT explosion
11114 -- when straight time was entered in place of hours, in case
11115 -- an SDP is attached. This change would actually topple up the
11116 -- rest of weekly explosion, and hence reverting it back.
11117 -- The original issue remains unanswered now, and need to fix that
11118 -- with another bug. Nevertheless, its a corner scenario.
11119
11120 /*
11121 hours_paid_weekly_rule := --get_weekly_total; -- SPR C148
11122 get_weekly_total_prev_days --M. Bhammar bug 5260857
11123 + NVL (previous_detail_hours_day, 0);
11124 */
11125
11126 hours_paid_weekly_rule := get_weekly_total; -- SPR C148
11127
11128
11129
11130 -- hours_paid_weekly_rule := get_weekly_total_to_date('REG');
11131 IF g_debug
11132 THEN
11133 hr_utility.TRACE ( 'hours_paid_weekly_rule :'
11134 || hours_paid_weekly_rule
11135 );
11136 END IF;
11137
11138 -- HXT_UTIL.DEBUG('get_weekly_total is '||to_char(hours_paid_weekly_rule));
11139 IF hours_paid_weekly_rule >= weekly_rule_cap
11140 THEN
11141 IF g_debug
11142 THEN
11143 hr_utility.set_location ('hxt_time_detail.gen_special', 29);
11144 END IF;
11145
11146 first_weekly_cap_reached := TRUE;
11147 END IF;
11148
11149 b_first_time := TRUE;
11150 l_time_in := p_time_in;
11151 l_time_out := p_time_out;
11152
11153 IF g_debug
11154 THEN
11155 hr_utility.TRACE ('l_time_in :' || TO_CHAR (l_time_in, 'HH24:MI'));
11156 hr_utility.TRACE ('l_time_out:' || TO_CHAR (l_time_out, 'HH24:MI')
11157 );
11158 END IF;
11159
11160 --SIR494 We must allow the loop to process at least once or we will not be able
11161 --SIR494 to pay rows where hours are zero but an amount has been entered PWM 09FEB00
11162 --SIR494 WHILE hours_left_to_pay <> 0 AND error_code = 0 LOOP
11163 WHILE ( (hours_left_to_pay <> 0 AND ERROR_CODE = 0)
11164 OR ( b_first_time = TRUE
11165 AND NVL (l_use_points_assigned, 'N') = 'N'
11166 )
11167 ) -- Added this AND clause for
11168 -- bug 2956224 fix.
11169 LOOP
11170 IF g_debug
11171 THEN
11172 hr_utility.set_location ('hxt_time_detail.gen_special', 30);
11173 END IF;
11174
11175 IF g_ep_type = 'WEEKLY' AND rule_type_to_pay <> 'HOL'
11176 THEN
11177 IF g_debug
11178 THEN
11179 hr_utility.set_location ('hxt_time_detail.gen_special', 31);
11180 END IF;
11181
11182 select_weekly_hours (rule_to_pay,
11183 hours_to_pay_this_rule,
11184 element_type_id_to_pay
11185 );
11186
11187 IF g_debug
11188 THEN
11189 hr_utility.set_location ('hxt_time_detail.gen_special',
11190 31.5
11191 );
11192 END IF;
11193
11194 IF ERROR_CODE > l_error_return
11195 THEN
11196 IF g_debug
11197 THEN
11198 hr_utility.set_location ('hxt_time_detail.gen_special',
11199 32
11200 );
11201 END IF;
11202
11203 l_error_return := ERROR_CODE;
11204 hxt_util.DEBUG ( 'Loc I. Return code is'
11205 || TO_CHAR (l_error_return)
11206 );
11207 END IF;
11208 ELSIF g_ep_type IN ('WEEKLY', 'SPECIAL')
11209 AND rule_type_to_pay = 'HOL'
11210 THEN
11211 IF g_debug
11212 THEN
11213 hr_utility.set_location ('hxt_time_detail.gen_special',
11214 32.1
11215 );
11216 END IF;
11217
11218 select_hol_weekly_hours (rule_to_pay,
11219 hours_to_pay_this_rule,
11220 element_type_id_to_pay
11221 );
11222
11223 IF ERROR_CODE > l_error_return
11224 THEN
11225 IF g_debug
11226 THEN
11227 hr_utility.set_location ('hxt_time_detail.gen_special',
11228 32.5
11229 );
11230 END IF;
11231
11232 l_error_return := ERROR_CODE;
11233 hxt_util.DEBUG ( 'Loc I. Return code is'
11234 || TO_CHAR (l_error_return)
11235 );
11236 END IF;
11237 ELSE
11238 IF g_debug
11239 THEN
11240 hr_utility.set_location ('hxt_time_detail.gen_special', 33);
11241 END IF;
11242
11243 --MHANDA Determine whether the rules to be applied use the
11244 --points counter.
11245 SELECT use_points_assigned
11246 INTO l_use_points_assigned
11247 FROM hxt_earning_policies
11248 WHERE ID = g_ep_id;
11249
11250 IF g_debug
11251 THEN
11252 hr_utility.TRACE ( 'use_points_assigned? :'
11253 || l_use_points_assigned
11254 );
11255 END IF;
11256
11257 IF l_use_points_assigned = 'N' OR l_use_points_assigned IS NULL
11258 THEN
11259 IF g_debug
11260 THEN
11261 hr_utility.set_location ('hxt_time_detail.gen_special',
11262 33.1
11263 );
11264 END IF;
11265
11266 select_rule_and_hours (ERROR_CODE,
11267 rule_to_pay,
11268 hours_to_pay_this_rule,
11269 element_type_id_to_pay
11270 );
11271 ELSIF l_use_points_assigned = 'Y'
11272 THEN
11273 IF g_debug
11274 THEN
11275 hr_utility.set_location ('hxt_time_detail.gen_special',
11276 33.2
11277 );
11278 END IF;
11279
11280 use_points_to_select_rule_hrs (ERROR_CODE,
11281 rule_to_pay,
11282 hours_to_pay_this_rule,
11283 element_type_id_to_pay
11284 );
11285
11286 IF g_debug
11287 THEN
11288 hr_utility.set_location ('hxt_time_detail.gen_special',
11289 33.3
11290 );
11291 END IF;
11292 END IF;
11293
11294 IF ERROR_CODE > l_error_return
11295 THEN
11296 IF g_debug
11297 THEN
11298 hr_utility.set_location ('hxt_time_detail.gen_special',
11299 34
11300 );
11301 END IF;
11302
11303 l_error_return := ERROR_CODE;
11304 hxt_util.DEBUG ( 'Loc J. Return code is'
11305 || TO_CHAR (l_error_return)
11306 );
11307 END IF; --SIR014
11308 END IF;
11309
11310 IF g_debug
11311 THEN
11312 hr_utility.TRACE ('g_hours :' || g_hours);
11313 END IF;
11314
11315 IF l_use_points_assigned = 'N' OR l_use_points_assigned IS NULL
11316 THEN
11317 IF g_hours >= 0
11318 THEN
11319 IF g_debug
11320 THEN
11321 hr_utility.set_location ('hxt_time_detail.gen_special',
11322 35
11323 );
11324 hr_utility.TRACE ( 'hours_to_pay_this_rule :'
11325 || hours_to_pay_this_rule
11326 );
11327 END IF;
11328
11329 hours_to_pay_this_rule :=
11330 GREATEST (hours_to_pay_this_rule, 0);
11331
11332 IF g_debug
11333 THEN
11334 hr_utility.TRACE ( 'hours_to_pay_this_rule :'
11335 || hours_to_pay_this_rule
11336 );
11337 END IF;
11338 -- can be negative if a rule was
11339 END IF;
11340 END IF;
11341
11342 IF g_debug
11343 THEN
11344 hr_utility.TRACE ('error_code :' || ERROR_CODE);
11345 END IF;
11346
11347 IF ( (hours_to_pay_this_rule > 0 AND ERROR_CODE = 0)
11348 OR (b_first_time = TRUE)
11349 )
11350 THEN
11351 IF g_debug
11352 THEN
11353 hr_utility.set_location ('hxt_time_detail.gen_special', 36);
11354 hr_utility.TRACE ( 'l_time_in :'
11355 || TO_CHAR (l_time_in, 'HH24:MI')
11356 );
11357 hr_utility.TRACE ( 'l_time_out:'
11358 || TO_CHAR (l_time_out, 'HH24:MI')
11359 );
11360 END IF;
11361
11362 -- l_time_out := l_time_in + (hours_to_pay_this_rule/24);
11363 l_time_in := ROUND (l_time_in, 'MI');
11364 l_time_out :=
11365 ROUND (l_time_in + (hours_to_pay_this_rule / 24), 'MI');
11366
11367 IF g_debug
11368 THEN
11369 hr_utility.TRACE ( 'l_time_in :'
11370 || TO_CHAR (l_time_in, 'HH24:MI')
11371 );
11372 hr_utility.TRACE ( 'l_time_out:'
11373 || TO_CHAR (l_time_out, 'HH24:MI')
11374 );
11375 hr_utility.TRACE ('********RM BEFORE CALL TO PAY**********');
11376 hr_utility.TRACE ( 'hours_to_pay_this_rule IS : *** : '
11377 || TO_CHAR (hours_to_pay_this_rule)
11378 );
11379 hr_utility.TRACE ( 'l_time_in IS : *** : '
11380 || TO_CHAR (l_time_in,
11381 'DD-MON-YYYY HH24:MI:SS'
11382 )
11383 );
11384 hr_utility.TRACE ( 'l_time_out IS : *** : '
11385 || TO_CHAR (l_time_out,
11386 'DD-MON-YYYY HH24:MI:SS'
11387 )
11388 );
11389 hr_utility.TRACE ( 'element_type_id_to_pay IS : *** : '
11390 || TO_CHAR (element_type_id_to_pay)
11391 );
11392 hr_utility.TRACE ( 'g_date_worked IS : *** : '
11393 || TO_CHAR (g_date_worked, 'DD-MON-YYYY')
11394 );
11395 END IF;
11396
11397 ERROR_CODE :=
11398 pay (hours_to_pay_this_rule,
11399 element_type_id_to_pay,
11400 l_time_in,
11401 l_time_out,
11402 g_date_worked,
11403 g_id -- parent id
11404 ,
11405 g_assignment_id,
11406 g_fcl_earn_reason_code,
11407 g_ffv_cost_center_id,
11408 g_ffv_labor_account_id,
11409 g_tas_id,
11410 g_location_id,
11411 g_sht_id,
11412 g_hrw_comment,
11413 g_ffv_rate_code_id,
11414 g_rate_multiple,
11415 g_hourly_rate,
11416 g_amount,
11417 g_fcl_tax_rule_code,
11418 g_separate_check_flag,
11419 g_project_id --,g_GROUP_ID
11420 ,
11421 g_ep_id,
11422 a_state_name => g_state_name,
11423 a_county_name => g_county_name,
11424 a_city_name => g_city_name,
11425 a_zip_code => g_zip_code
11426 );
11427
11428 IF ERROR_CODE <> 0
11429 THEN
11430 IF g_debug
11431 THEN
11432 hr_utility.set_location ('hxt_time_detail.gen_special',
11433 37
11434 );
11435 END IF;
11436
11437 IF ERROR_CODE > l_error_return
11438 THEN
11439 IF g_debug
11440 THEN
11441 hr_utility.set_location
11442 ('hxt_time_detail.gen_special',
11443 38
11444 );
11445 END IF;
11446
11447 l_error_return := ERROR_CODE;
11448 END IF;
11449
11450 hxt_util.DEBUG ( 'Loc K. Return code is '
11451 || TO_CHAR (l_error_return)
11452 );
11453 RETURN l_error_return;
11454 --return error_code;
11455 END IF;
11456
11457 IF g_debug
11458 THEN
11459 hr_utility.set_location ('hxt_time_detail.gen_special', 39);
11460 hr_utility.TRACE ( 'hours_left_to_pay :'
11461 || TO_CHAR (hours_left_to_pay)
11462 );
11463 END IF;
11464
11465 hxt_util.DEBUG ( 'Ahrslefttopay is '
11466 || TO_CHAR (hours_left_to_pay)
11467 );
11468
11469 IF g_debug
11470 THEN
11471 hr_utility.TRACE ( 'hours_to_pay_this_rule :'
11472 || TO_CHAR (hours_to_pay_this_rule)
11473 );
11474 hr_utility.TRACE ( 'l_use_points_assigned :'
11475 || l_use_points_assigned
11476 );
11477 END IF;
11478
11479 l_time_in := l_time_in + (hours_to_pay_this_rule / 24);
11480
11481 IF l_use_points_assigned = 'N' OR l_use_points_assigned IS NULL
11482 THEN
11483 IF g_debug
11484 THEN
11485 hr_utility.set_location ('hxt_time_detail.gen_special',
11486 39.5
11487 );
11488 END IF;
11489
11490 hours_left_to_pay :=
11491 hours_left_to_pay - hours_to_pay_this_rule;
11492 END IF;
11493
11494 IF g_debug
11495 THEN
11496 hr_utility.set_location ('hxt_time_detail.gen_special', 40);
11497 hr_utility.TRACE ( 'hours_left_to_pay :'
11498 || TO_CHAR (hours_left_to_pay)
11499 );
11500 END IF;
11501
11502 hxt_util.DEBUG ( 'Bhrslefttopay is '
11503 || TO_CHAR (hours_left_to_pay)
11504 );
11505 END IF;
11506
11507 b_first_time := FALSE;
11508
11509 IF l_use_points_assigned = 'N' OR l_use_points_assigned IS NULL
11510 THEN
11511 IF hours_left_to_pay >= 0 AND ERROR_CODE = 0
11512 THEN
11513 IF g_debug
11514 THEN
11515 hr_utility.set_location ('hxt_time_detail.gen_special',
11516 41
11517 );
11518 END IF;
11519
11520 --changed to >= in order to payback wkly if cap hit at 0
11521 reset_rules (hours_paid_daily_rule,
11522 hours_paid_weekly_rule,
11523 fetch_next_day,
11524 fetch_next_week,
11525 rule_to_pay
11526 );
11527
11528 -- MHANDA Added to fetch the next weekly cap once the
11529 -- weekly cap is reached
11530 IF hours_paid_weekly_rule >= weekly_rule_cap
11531 AND g_ep_type = 'SPECIAL'
11532 THEN
11533 IF g_debug
11534 THEN
11535 hr_utility.set_location
11536 ('hxt_time_detail.gen_special',
11537 41.5
11538 );
11539 END IF;
11540
11541 fetch_next_week := TRUE;
11542 END IF;
11543
11544 IF fetch_next_day = TRUE
11545 THEN
11546 IF g_debug
11547 THEN
11548 hr_utility.set_location
11549 ('hxt_time_detail.gen_special',
11550 42
11551 );
11552 END IF;
11553
11554 FETCH daily_earn_rules_cur
11555 INTO daily_rule_cap, daily_earning_type, dummy_days;
11556
11557 IF g_debug
11558 THEN
11559 hr_utility.TRACE ( 'daily_rule_cap :'
11560 || daily_rule_cap
11561 );
11562 hr_utility.TRACE ( 'daily_earning_type :'
11563 || daily_earning_type
11564 );
11565 hr_utility.TRACE ('dummy_days :' || dummy_days);
11566 END IF;
11567
11568 IF daily_earn_rules_cur%NOTFOUND
11569 THEN
11570 IF g_debug
11571 THEN
11572 hr_utility.set_location
11573 ('hxt_time_detail.gen_special',
11574 43
11575 );
11576 END IF;
11577
11578 end_of_day_rules := TRUE;
11579 END IF;
11580 END IF;
11581
11582 IF fetch_next_week = TRUE
11583 THEN
11584 IF g_debug
11585 THEN
11586 hr_utility.set_location
11587 ('hxt_time_detail.gen_special',
11588 44
11589 );
11590 END IF;
11591
11592 current_weekly_earning := weekly_earning_type;
11593
11594 IF g_debug
11595 THEN
11596 hr_utility.TRACE ( 'current_weekly_earning :'
11597 || current_weekly_earning
11598 );
11599 END IF;
11600
11601 FETCH weekly_earn_rules_cur
11602 INTO weekly_rule_cap, weekly_earning_type;
11603
11604 IF g_debug
11605 THEN
11606 hr_utility.TRACE ( 'weekly_rule_cap :'
11607 || weekly_rule_cap
11608 );
11609 hr_utility.TRACE ( 'weekly_earning_type :'
11610 || weekly_earning_type
11611 );
11612 END IF;
11613
11614 -- MHANDA checking whether the person is eligible for doubletime
11615 -- once the weekly overtime cap is reached ,when the earning
11616 -- policy is of type SPECIAL
11617 IF g_ep_type = 'SPECIAL'
11618 THEN
11619 hours_paid_for_dtime_elig :=
11620 get_wkly_total_for_doubletime;
11621
11622 IF g_debug
11623 THEN
11624 hr_utility.TRACE ( 'hours_paid_for_dtime_elig :'
11625 || hours_paid_for_dtime_elig
11626 );
11627 END IF;
11628
11629 IF hours_paid_for_dtime_elig >= weekly_rule_cap
11630 THEN
11631 second_weekly_cap_reached := TRUE;
11632
11633 IF hours_paid_for_dtime_elig > weekly_rule_cap
11634 THEN
11635 hours_paid_weekly_rule :=
11636 get_wkly_total_for_doubletime;
11637 END IF;
11638 END IF;
11639 END IF;
11640
11641 -- MHANDA getting total number of hours after which the person
11642 -- is eligible for doubletime i.e., when second weekly cap is
11643 -- reached,when earning policy type is WEEKLY.
11644 /* IF g_EP_TYPE = 'WEEKLY' THEN
11645 hours_paid_weekly_rule := get_wkly_total_for_doubletime;
11646 hr_utility.trace('hours_paid_weekly_rule :'||hours_paid_weekly_rule);
11647 END IF;
11648 */
11649 IF weekly_earn_rules_cur%NOTFOUND
11650 THEN
11651 IF g_debug
11652 THEN
11653 hr_utility.set_location
11654 ('hxt_time_detail.gen_special',
11655 45
11656 );
11657 END IF;
11658
11659 weekly_rule_cap := 999;
11660 END IF;
11661 END IF; -- fetch_next_week = TRUE
11662 ELSIF hours_left_to_pay < 0
11663 THEN
11664 IF g_debug
11665 THEN
11666 hr_utility.set_location ('hxt_time_detail.gen_special',
11667 46
11668 );
11669 END IF;
11670
11671 IF g_hours >= 0
11672 THEN
11673 IF g_debug
11674 THEN
11675 hr_utility.set_location
11676 ('hxt_time_detail.gen_special',
11677 47
11678 );
11679 END IF;
11680
11681 fnd_message.set_name ('HXT',
11682 'HXT_39303_HRS_PD_GRT_HRS_PAY'
11683 );
11684 ERROR_CODE :=
11685 call_hxthxc_gen_error ('HXT',
11686 'HXT_39303_HRS_PD_GRT_HRS_PAY',
11687 NULL,
11688 LOCATION,
11689 ''
11690 );
11691
11692 --2278400 error_code := call_gen_error(location, '');
11693 IF ERROR_CODE > l_error_return
11694 THEN
11695 IF g_debug
11696 THEN
11697 hr_utility.set_location
11698 ('hxt_time_detail.gen_special',
11699 48
11700 );
11701 END IF;
11702
11703 l_error_return := ERROR_CODE;
11704 hxt_util.DEBUG ( 'Loc L. Return code is'
11705 || TO_CHAR (l_error_return)
11706 );
11707 END IF; --SIR014
11708 ELSE
11709 IF g_debug
11710 THEN
11711 hr_utility.set_location
11712 ('hxt_time_detail.gen_special',
11713 49
11714 );
11715 END IF;
11716
11717 hours_left_to_pay := 0;
11718 END IF;
11719
11720 IF g_debug
11721 THEN
11722 hr_utility.set_location ('hxt_time_detail.gen_special',
11723 50
11724 );
11725 END IF;
11726 END IF; --hours_left_to_pay > 0 and error_code = 0
11727 END IF; --l_use_points_assigned = 'N'
11728
11729 loop_counter := loop_counter + 1;
11730
11731 IF loop_counter > 50
11732 THEN
11733 IF g_debug
11734 THEN
11735 hr_utility.set_location ('hxt_time_detail.gen_special', 52);
11736 END IF;
11737
11738 fnd_message.set_name ('HXT', 'HXT_39305_LOOP_LIMIT_EXC');
11739 ERROR_CODE :=
11740 call_hxthxc_gen_error ('HXT',
11741 'HXT_39305_LOOP_LIMIT_EXC',
11742 NULL,
11743 LOCATION,
11744 ''
11745 );
11746
11747 --2278400 error_code := call_gen_error(location, '');
11748 IF ERROR_CODE > l_error_return
11749 THEN
11750 IF g_debug
11751 THEN
11752 hr_utility.set_location ('hxt_time_detail.gen_special',
11753 53
11754 );
11755 END IF;
11756
11757 l_error_return := ERROR_CODE;
11758 END IF;
11759
11760 hxt_util.DEBUG ( 'Loc M. Return code is'
11761 || TO_CHAR (l_error_return)
11762 );
11763 END IF;
11764
11765 IF g_debug
11766 THEN
11767 hr_utility.set_location ('hxt_time_detail.gen_special', 54);
11768 END IF;
11769 END LOOP; -- While hours_left_to_pay <> 0 AND error_code = 0
11770
11771 CLOSE daily_earn_rules_cur;
11772
11773 CLOSE weekly_earn_rules_cur;
11774
11775 IF seven_day_cal_rule = TRUE
11776 AND g_cons_days_worked = 6
11777 AND ERROR_CODE = 0
11778 THEN
11779 IF g_debug
11780 THEN
11781 hr_utility.set_location ('hxt_time_detail.gen_special', 54.5);
11782 END IF;
11783
11784 l_day_total := get_daily_total;
11785
11786 IF g_debug
11787 THEN
11788 hr_utility.TRACE ('l_day_total :' || l_day_total);
11789 END IF;
11790
11791 IF l_day_total > 12
11792 THEN
11793 IF g_debug
11794 THEN
11795 hr_utility.set_location ('hxt_time_detail.gen_special', 55);
11796 END IF;
11797
11798 ERROR_CODE := adjust_for_double_time (l_day_total);
11799
11800 IF ERROR_CODE = 0
11801 THEN
11802 IF g_debug
11803 THEN
11804 hr_utility.set_location ('hxt_time_detail.gen_special',
11805 56
11806 );
11807 END IF;
11808
11809 NULL;
11810 ELSIF ERROR_CODE = 1
11811 THEN
11812 IF g_debug
11813 THEN
11814 hr_utility.set_location ('hxt_time_detail.gen_special',
11815 57
11816 );
11817 END IF;
11818
11819 fnd_message.set_name ('HXT', 'HXT_39474_6TH_DAY_OT_NF');
11820 ERROR_CODE :=
11821 call_hxthxc_gen_error ('HXT',
11822 'HXT_39474_6TH_DAY_OT_NF',
11823 NULL,
11824 LOCATION,
11825 ''
11826 );
11827 -- 2278400 error_code := call_gen_error(location, '');
11828 ELSIF ERROR_CODE = 2
11829 THEN
11830 IF g_debug
11831 THEN
11832 hr_utility.set_location ('hxt_time_detail.gen_special',
11833 58
11834 );
11835 END IF;
11836
11837 fnd_message.set_name ('HXT', 'HXT_39475_1ST_RULE_NF');
11838 ERROR_CODE :=
11839 call_hxthxc_gen_error ('HXT',
11840 'HXT_39475_1ST_RULE_NF',
11841 NULL,
11842 LOCATION,
11843 ''
11844 );
11845 --2278400 error_code := call_gen_error(location, '');
11846 ELSIF ERROR_CODE = 3
11847 THEN
11848 IF g_debug
11849 THEN
11850 hr_utility.set_location ('hxt_time_detail.gen_special',
11851 59
11852 );
11853 END IF;
11854
11855 fnd_message.set_name ('HXT', 'HXT_39476_2ND_RULE_NF');
11856 ERROR_CODE :=
11857 call_hxthxc_gen_error ('HXT',
11858 'HXT_39476_2ND_RULE_NF',
11859 NULL,
11860 LOCATION,
11861 ''
11862 );
11863 -- 2278400 error_code := call_gen_error(location, '');
11864 ELSIF ERROR_CODE = 4
11865 THEN
11866 IF g_debug
11867 THEN
11868 hr_utility.set_location ('hxt_time_detail.gen_special',
11869 60
11870 );
11871 END IF;
11872
11873 fnd_message.set_name ('HXT', 'HXT_39477_3RD_RULE_NF');
11874 ERROR_CODE :=
11875 call_hxthxc_gen_error ('HXT',
11876 'HXT_39477_3RD_RULE_NF',
11877 NULL,
11878 LOCATION,
11879 ''
11880 );
11881 -- 2278400 error_code := call_gen_error(location, '');
11882 ELSIF ERROR_CODE = 5
11883 THEN
11884 IF g_debug
11885 THEN
11886 hr_utility.set_location ('hxt_time_detail.gen_special',
11887 61
11888 );
11889 END IF;
11890
11891 fnd_message.set_name ('HXT', 'HXT_39478_ERR_IN_MOD_PAY');
11892 ERROR_CODE :=
11893 call_hxthxc_gen_error ('HXT',
11894 'HXT_39478_ERR_IN_MOD_PAY',
11895 NULL,
11896 LOCATION,
11897 ''
11898 );
11899 --2278400 error_code := call_gen_error(location, '');
11900 END IF;
11901
11902 IF ERROR_CODE > l_error_return
11903 THEN
11904 IF g_debug
11905 THEN
11906 hr_utility.set_location ('hxt_time_detail.gen_special',
11907 62
11908 );
11909 END IF;
11910
11911 l_error_return := ERROR_CODE;
11912 hxt_util.DEBUG ( 'Loc N. Return code is '
11913 || TO_CHAR (l_error_return)
11914 );
11915 END IF;
11916
11917 IF g_debug
11918 THEN
11919 hr_utility.set_location ('hxt_time_detail.gen_special', 63);
11920 END IF;
11921 END IF;
11922
11923 IF g_debug
11924 THEN
11925 hr_utility.set_location ('hxt_time_detail.gen_special', 64);
11926 END IF;
11927 END IF;
11928
11929 IF g_debug
11930 THEN
11931 hr_utility.TRACE
11932 ('-----------Leaving rule_type_to_pay = ABS------------');
11933 END IF;
11934 END IF; -- rule_type_to_pay = 'ABS'
11935
11936 -- the following function deletes erroneously generated detail rows
11937 -- that have zero hours and time_in is equal to time_out. These rows have
11938 -- caused endless looping in the get_contig_hours function. The cursor in
11939 -- get_contig_hours has been altered to exclude rows where time_in =
11940 -- time_out and delete_zero_hour_details removes these invalid rows from
11941 -- table hxt_det_hours_worked. PWM 06-MAR-00
11942 ERROR_CODE :=
11943 (delete_zero_hour_details (g_tim_id, g_ep_id, g_osp_id,
11944 g_date_worked)
11945 );
11946
11947 IF ERROR_CODE > l_error_return
11948 THEN
11949 l_error_return := ERROR_CODE;
11950 hxt_util.DEBUG ('Loc O. Return code is ' || TO_CHAR (l_error_return));
11951 END IF;
11952
11953 /* MHANDA - Changed on 10/22/2001
11954 Commenting out this function call as it is updating all
11955 overtime records to Zero and time in and time out to be the
11956 same for earning policy with 3 tier weekly rules
11957 error_code := adjust_for_3tier(g_tim_id,
11958 g_ep_id,
11959 g_date_worked);
11960
11961 IF error_code > l_error_return THEN
11962 l_error_return := error_code;
11963 HXT_UTIL.DEBUG('Loc P. Return code is '||to_char(l_error_return));
11964 End if;
11965 */
11966
11967 -- Combine the exploded chunks if they are contiguous for an element
11968 ERROR_CODE := combine_contig_chunks;
11969
11970 IF ERROR_CODE > l_error_return
11971 THEN
11972 l_error_return := ERROR_CODE;
11973 hxt_util.DEBUG ('Loc O. Return code is ' || TO_CHAR (l_error_return));
11974 END IF;
11975
11976 ERROR_CODE := adjust_hours_for_hdp;
11977
11978 IF ERROR_CODE > l_error_return
11979 THEN
11980 IF g_debug
11981 THEN
11982 hr_utility.set_location ('hxt_time_detail.gen_special', 65);
11983 END IF;
11984
11985 l_error_return := ERROR_CODE;
11986 hxt_util.DEBUG ('Loc F. Return code is ' || TO_CHAR (l_error_return));
11987
11988 -- debug only
11989 IF g_debug
11990 THEN
11991 hr_utility.TRACE ( 'Loc F. Return code is :'
11992 || TO_CHAR (l_error_return)
11993 );
11994 END IF;
11995 END IF;
11996
11997 RETURN (l_error_return);
11998 EXCEPTION
11999 WHEN OTHERS
12000 THEN
12001 fnd_message.set_name ('HXT', 'HXT_39269_ORACLE_ERROR');
12002 ERROR_CODE :=
12003 call_hxthxc_gen_error ('HXT',
12004 'HXT_39269_ORACLE_ERROR',
12005 NULL,
12006 LOCATION,
12007 ''
12008 );
12009 --2278400 error_code := call_gen_error(location, '');
12010 hxt_util.DEBUG ('Loc Q. Return code is ' || TO_CHAR (ERROR_CODE));
12011 hxt_util.DEBUG ('code is ' || SQLERRM);
12012 RETURN (ERROR_CODE);
12013 END; -- gen special
12014
12015 FUNCTION delete_zero_hour_details (
12016 a_tim_id NUMBER,
12017 a_ep_id NUMBER,
12018 a_osp_id NUMBER,
12019 a_date_worked DATE
12020 )
12021 RETURN NUMBER
12022 IS
12023 /* SIR538 This cursor was deleting detail rows that had amounts, but zero hours
12024 so it was re-written. PWM 03-MAR-00 */
12025 CURSOR zero_hrs_cur (c_tim_id NUMBER, c_date_worked DATE)
12026 IS
12027 SELECT hrw.ROWID hrw_rowid
12028 FROM hxt_det_hours_worked hrw
12029 WHERE hrw.date_worked <= c_date_worked
12030 AND hrw.tim_id = c_tim_id
12031 AND ( (
12032 -- To take care of errorneous records created after the records
12033 -- have been transferred to OTLR/BEE and then TC modified to zero
12034 -- hrs(i.e., basically to delete TC) in SS
12035 (NVL (hrw.hours, 0) = 0)
12036 AND (NVL (hrw.amount, 0) = 0)
12037 AND (hrw.time_in = hrw.time_out)
12038 AND (hrw.time_in IS NOT NULL)
12039 AND (hrw.time_out IS NOT NULL)
12040 AND (hrw.retro_batch_id IS NOT NULL)
12041 )
12042 OR ( (NVL (hrw.hours, 0) = 0)
12043 AND (NVL (hrw.amount, 0) = 0)
12044 -- Commented out the following in order to delete the erroneous
12045 -- records generated when updating a TC already transferred to BEE.
12046 AND (hrw.retro_batch_id IS NULL
12047 ) -- Put it back for 3536182
12048 -- Added this OR condition to delete erroneously generated
12049 -- Shift diff Premium records where amount is not null and
12050 -- time_in is equal to time_out.
12051 OR ( (NVL (hrw.hours, 0) = 0)
12052 AND NVL (hrw.amount, 0) <> 0
12053 AND hrw.time_in = hrw.time_out
12054 AND hrw.retro_batch_id IS NULL
12055 )
12056 )
12057 );
12058
12059 CURSOR duplicate_flat_dy_prems (
12060 c_tim_id NUMBER,
12061 c_osp_id NUMBER,
12062 c_date_worked DATE
12063 )
12064 IS
12065 SELECT dhw.ROWID dhw_rowid, dhw.ID, dhw.parent_id, dhw.tim_id,
12066 dhw.hours, dhw.time_in, dhw.time_out, dhw.seqno,
12067 eltv.hxt_premium_amount, eltv.hxt_earning_category,
12068 dhw.element_type_id
12069 FROM hxt_pay_element_types_f_ddf_v eltv,
12070 pay_element_types_f elt,
12071 hxt_det_hours_worked_f dhw
12072 WHERE dhw.tim_id = c_tim_id
12073 AND dhw.date_worked = c_date_worked
12074 AND elt.element_type_id = dhw.element_type_id
12075 AND dhw.date_worked BETWEEN elt.effective_start_date
12076 AND elt.effective_end_date
12077 AND eltv.element_type_id = elt.element_type_id
12078 AND elt.element_type_id = c_osp_id
12079 AND dhw.date_worked BETWEEN eltv.effective_start_date
12080 AND eltv.effective_end_date
12081 AND eltv.hxt_earning_category = 'OSP'
12082 AND eltv.hxt_premium_type = 'FIXED'
12083 AND dhw.ID >
12084 (SELECT /*+ NO_UNNEST */
12085 MIN (hdw.ID)
12086 FROM hxt_det_hours_worked_f hdw
12087 WHERE hdw.tim_id = dhw.tim_id
12088 AND hdw.date_worked = c_date_worked
12089 AND hdw.element_type_id = dhw.element_type_id
12090 AND SYSDATE BETWEEN hdw.effective_start_date and hdw.effective_end_date)
12091 ORDER BY dhw.date_worked DESC,
12092 dhw.time_in DESC,
12093 dhw.seqno DESC,
12094 dhw.parent_id DESC;
12095
12096 l_error_code NUMBER := 0;
12097 LOCATION VARCHAR2 (120) := g_location || ':DDTL';
12098 BEGIN
12099 IF g_debug
12100 THEN
12101 hr_utility.set_location ('hxt_time_detail.delete_zero_hour_details',
12102 10
12103 );
12104 END IF;
12105
12106 FOR zero_rec IN zero_hrs_cur (a_tim_id, a_date_worked)
12107 LOOP -- through detail rows and delete zero hour rows
12108 IF g_debug
12109 THEN
12110 hr_utility.set_location
12111 ('hxt_time_detail.delete_zero_hour_details',
12112 20
12113 );
12114 END IF;
12115
12116 DELETE FROM hxt_det_hours_worked
12117 WHERE ROWID = zero_rec.hrw_rowid;
12118 END LOOP;
12119
12120 FOR dup_flat_amt_rec IN duplicate_flat_dy_prems (a_tim_id,
12121 a_osp_id,
12122 a_date_worked
12123 )
12124 LOOP
12125 -- through flat amount day prem records and delete duplicates
12126 -- for a day. Flat amount Day Premium should be paid only once a day.
12127 IF g_debug
12128 THEN
12129 hr_utility.set_location
12130 ('hxt_time_detail.delete_zero_hour_details',
12131 30
12132 );
12133 END IF;
12134
12135 DELETE FROM hxt_det_hours_worked
12136 WHERE ROWID = dup_flat_amt_rec.dhw_rowid;
12137 END LOOP;
12138
12139 IF g_debug
12140 THEN
12141 hr_utility.set_location ('hxt_time_detail.delete_zero_hour_details',
12142 40
12143 );
12144 END IF;
12145
12146 RETURN 0;
12147 EXCEPTION
12148 WHEN NO_DATA_FOUND
12149 THEN
12150 RETURN 0;
12151 WHEN OTHERS
12152 THEN
12153 fnd_message.set_name ('HXT', 'HXT_39579_DELETE_DETAIL_ERR');
12154 l_error_code :=
12155 call_hxthxc_gen_error ('HXT',
12156 'HXT_39579_DELETE_DETAIL_ERR',
12157 NULL,
12158 LOCATION,
12159 '',
12160 SQLERRM
12161 );
12162 --2278400 l_error_code := call_gen_error(location, '', sqlerrm);
12163 END delete_zero_hour_details;
12164
12165 -- end delete_zero_hour_details;
12166 FUNCTION combine_contig_chunks
12167 RETURN NUMBER
12168 IS
12169 /* This cursor brings back the distinct element_types, that exploded in the
12170 detail block ,for a summary record */
12171 CURSOR c_distinct_elements (a_parent_id NUMBER)
12172 IS
12173 SELECT DISTINCT element_type_id
12174 FROM hxt_det_hours_worked hrw
12175 WHERE hrw.parent_id = a_parent_id;
12176
12177 /* This cursor brings back all the detail records for an element */
12178 CURSOR c_detail_chunks (a_parent_id NUMBER, a_element_type_id NUMBER)
12179 IS
12180 SELECT hrw.ROWID hrw_rowid, hrw.time_in, hrw.time_out, hrw.hours,
12181 hrw.amount, hrw.hourly_rate, hrw.rate_multiple,
12182 hrw.prev_wage_code
12183 FROM hxt_det_hours_worked hrw
12184 WHERE hrw.parent_id = a_parent_id
12185 AND hrw.element_type_id = a_element_type_id
12186 ORDER BY time_in, time_out;
12187
12188 l_error_code NUMBER := 0;
12189 LOCATION VARCHAR2 (120) := g_location || ':DDTL';
12190 row_id VARCHAR2 (50); --hxt_det_hours_worked.rowid%TYPE;
12191 row_id1 VARCHAR2 (50); --hxt_det_hours_worked.rowid%TYPE;
12192 ln_row_id VARCHAR2 (50); --hxt_det_hours_worked.rowid%TYPE;
12193 start_time hxt_det_hours_worked.time_in%TYPE;
12194 end_time hxt_det_hours_worked.time_out%TYPE;
12195 hours hxt_det_hours_worked.hours%TYPE;
12196 ln_hours hxt_det_hours_worked.hours%TYPE;
12197 ln_amount hxt_det_hours_worked.amount%TYPE;
12198 ln_hourly_rate hxt_det_hours_worked.hourly_rate%TYPE;
12199 ln_rate_multiple hxt_det_hours_worked.rate_multiple%TYPE;
12200 lv_prev_wage_code hxt_det_hours_worked.prev_wage_code%TYPE;
12201 start_time1 hxt_det_hours_worked.time_in%TYPE;
12202 end_time1 hxt_det_hours_worked.time_out%TYPE;
12203 hours1 hxt_det_hours_worked.hours%TYPE;
12204 ln_amount1 hxt_det_hours_worked.amount%TYPE;
12205 ln_hourly_rate1 hxt_det_hours_worked.hourly_rate%TYPE;
12206 ln_rate_multiple1 hxt_det_hours_worked.rate_multiple%TYPE;
12207 lv_prev_wage_code1 hxt_det_hours_worked.prev_wage_code%TYPE;
12208 ln_start_time hxt_det_hours_worked.time_in%TYPE;
12209 ln_end_time hxt_det_hours_worked.time_out%TYPE;
12210 ln_hours_worked hxt_det_hours_worked.hours%TYPE;
12211 l_proc VARCHAR2 (250);
12212 BEGIN
12213 IF g_debug
12214 THEN
12215 l_proc := 'hxt_time_detail.combine_contig_chunks';
12216 hr_utility.set_location (l_proc, 10);
12217 hr_utility.TRACE ('g_id:' || g_id);
12218 END IF;
12219
12220 FOR elem_rec IN c_distinct_elements (g_id)
12221 -- Loop through detail rows for each element and if contiguous times found
12222 -- then combine them into one.
12223 LOOP
12224 IF g_debug
12225 THEN
12226 hr_utility.set_location (l_proc, 20);
12227 hr_utility.TRACE ( 'elem_rec.element_type_id :'
12228 || elem_rec.element_type_id
12229 );
12230 END IF;
12231
12232 IF c_distinct_elements%NOTFOUND
12233 THEN
12234 IF g_debug
12235 THEN
12236 hr_utility.set_location (l_proc, 25);
12237 END IF;
12238
12239 EXIT;
12240 END IF;
12241
12242 OPEN c_detail_chunks (g_id, elem_rec.element_type_id);
12243
12244 FETCH c_detail_chunks
12245 INTO row_id, start_time, end_time, hours, ln_amount, ln_hourly_rate,
12246 ln_rate_multiple, lv_prev_wage_code;
12247
12248 IF g_debug
12249 THEN
12250 hr_utility.TRACE ('row_id :' || row_id);
12251 hr_utility.TRACE ( 'start_time :'
12252 || TO_CHAR (start_time,
12253 'DD-MON-YYYY HH24:MI:SS')
12254 );
12255 hr_utility.TRACE ( 'end_time :'
12256 || TO_CHAR (end_time, 'DD-MON-YYYY HH24:MI:SS')
12257 );
12258 hr_utility.TRACE ('hours :' || hours);
12259 hr_utility.TRACE ('ln_amount :' || ln_amount);
12260 hr_utility.TRACE ('ln_hourly_rate :' || ln_hourly_rate);
12261 hr_utility.TRACE ('ln_rate_multiple :' || ln_rate_multiple);
12262 hr_utility.TRACE ('lv_prev_wage_code :' || lv_prev_wage_code);
12263 END IF;
12264
12265 IF c_detail_chunks%FOUND
12266 THEN
12267 IF g_debug
12268 THEN
12269 hr_utility.set_location (l_proc, 30);
12270 END IF;
12271
12272 ln_row_id := row_id;
12273 ln_start_time := start_time;
12274 ln_end_time := end_time;
12275 ln_hours := hours;
12276
12277 IF g_debug
12278 THEN
12279 hr_utility.TRACE ('ln_row_id :' || ln_row_id);
12280 hr_utility.TRACE ( 'ln_start_time :'
12281 || TO_CHAR (ln_start_time,
12282 'DD-MON-YYYY HH24:MI:SS'
12283 )
12284 );
12285 hr_utility.TRACE ( 'ln_end_time :'
12286 || TO_CHAR (ln_end_time,
12287 'DD-MON-YYYY HH24:MI:SS'
12288 )
12289 );
12290 hr_utility.TRACE ('ln_hours :' || ln_hours);
12291 END IF;
12292 END IF;
12293
12294 LOOP
12295 IF g_debug
12296 THEN
12297 hr_utility.set_location (l_proc, 35);
12298 END IF;
12299
12300 FETCH c_detail_chunks
12301 INTO row_id1, start_time1, end_time1, hours1, ln_amount1,
12302 ln_hourly_rate1, ln_rate_multiple1, lv_prev_wage_code1;
12303
12304 IF g_debug
12305 THEN
12306 hr_utility.TRACE ('row_id1 :' || row_id1);
12307 hr_utility.TRACE ( 'start_time1 :'
12308 || TO_CHAR (start_time1,
12309 'DD-MON-YYYY HH24:MI:SS'
12310 )
12311 );
12312 hr_utility.TRACE ( 'end_time1 :'
12313 || TO_CHAR (end_time1,
12314 'DD-MON-YYYY HH24:MI:SS'
12315 )
12316 );
12317 hr_utility.TRACE ('hours1 :' || hours1);
12318 hr_utility.TRACE ('ln_amount1 :' || ln_amount1);
12319 hr_utility.TRACE ('ln_hourly_rate1 :' || ln_hourly_rate1);
12320 hr_utility.TRACE ('ln_rate_multiple1 :' || ln_rate_multiple1);
12321 hr_utility.TRACE ('lv_prev_wage_code1 :' || lv_prev_wage_code1);
12322 END IF;
12323
12324 IF c_detail_chunks%NOTFOUND
12325 THEN
12326 IF g_debug
12327 THEN
12328 hr_utility.set_location (l_proc, 40);
12329 END IF;
12330
12331 CLOSE c_detail_chunks;
12332
12333 EXIT;
12334 END IF;
12335
12336 IF g_debug
12337 THEN
12338 hr_utility.TRACE ( 'ln_end_time :'
12339 || TO_CHAR (ln_end_time,
12340 'DD-MON-YYYY HH24:MI:SS'
12341 )
12342 );
12343 hr_utility.TRACE ( 'start_time1 :'
12344 || TO_CHAR (start_time1,
12345 'DD-MON-YYYY HH24:MI:SS'
12346 )
12347 );
12348 hr_utility.TRACE ('ln_hours :' || ln_hours);
12349 hr_utility.TRACE ('hours1 :' || hours1);
12350 hr_utility.TRACE ('ln_amount :' || ln_amount);
12351 hr_utility.TRACE ('ln_hourly_rate :' || ln_hourly_rate);
12352 hr_utility.TRACE ('ln_rate_multiple :' || ln_rate_multiple);
12353 hr_utility.TRACE ('lv_prev_wage_code:' || lv_prev_wage_code);
12354 END IF;
12355
12356 IF ln_end_time IS NULL
12357 THEN
12358 -- implies that Time entered in HOURS and not IN/OUT time.
12359 -- Combine the hours rows for the element.
12360 IF g_debug
12361 THEN
12362 hr_utility.set_location (l_proc, 45);
12363 END IF;
12364
12365 -- Check if amount, hourly rate, rate multiple or prev wage code is
12366 -- the same for the segment chunks. If so then combine the chunks
12367 -- otherwise explode the chunk as it is.
12368 IF NVL (ln_amount, -1) = NVL (ln_amount1, -1)
12369 AND NVL (ln_hourly_rate, -1) = NVL (ln_hourly_rate1, -1)
12370 AND NVL (ln_rate_multiple, -1) = NVL (ln_rate_multiple1, -1)
12371 AND NVL (lv_prev_wage_code, -1) =
12372 NVL (lv_prev_wage_code1,
12373 -1)
12374 THEN
12375 IF g_debug
12376 THEN
12377 hr_utility.set_location (l_proc, 50);
12378 END IF;
12379
12380 ln_hours := ln_hours + hours1;
12381
12382 IF g_debug
12383 THEN
12384 hr_utility.TRACE ('ln_hours :' || ln_hours);
12385 hr_utility.TRACE ('row_id1 :' || row_id1);
12386 END IF;
12387
12388 DELETE FROM hxt_det_hours_worked
12389 WHERE ROWID = row_id1;
12390
12391 UPDATE hxt_det_hours_worked
12392 SET hours = ln_hours
12393 WHERE ROWID = ln_row_id;
12394 END IF;
12395
12396 IF g_debug
12397 THEN
12398 hr_utility.set_location (l_proc, 55);
12399 END IF;
12400 ELSIF ln_end_time = start_time1
12401 THEN
12402 IF g_debug
12403 THEN
12404 hr_utility.set_location (l_proc, 60);
12405 END IF;
12406
12407 -- Check if amount, hourly rate, rate multiple or prev wage code is
12408 -- the same for the segment chunks. If so then combine the chunks
12409 -- otherwise explode the chunk as it is.
12410 IF NVL (ln_amount, -1) = NVL (ln_amount1, -1)
12411 AND NVL (ln_hourly_rate, -1) = NVL (ln_hourly_rate1, -1)
12412 AND NVL (ln_rate_multiple, -1) = NVL (ln_rate_multiple1, -1)
12413 AND NVL (lv_prev_wage_code, -1) =
12414 NVL (lv_prev_wage_code1,
12415 -1)
12416 THEN
12417 IF g_debug
12418 THEN
12419 hr_utility.set_location (l_proc, 65);
12420 END IF;
12421
12422 ln_end_time := end_time1;
12423
12424 IF g_debug
12425 THEN
12426 hr_utility.TRACE ( 'ln_end_time :'
12427 || TO_CHAR (ln_end_time,
12428 'DD-MON-YYYY HH24:MI:SS'
12429 )
12430 );
12431 hr_utility.TRACE ('row_id1 :' || row_id1);
12432 END IF;
12433
12434 DELETE FROM hxt_det_hours_worked
12435 WHERE ROWID = row_id1;
12436
12437 IF g_debug
12438 THEN
12439 hr_utility.set_location (l_proc, 70);
12440 END IF;
12441
12442 IF ln_amount1 IS NOT NULL
12443 THEN
12444 IF g_debug
12445 THEN
12446 hr_utility.set_location (l_proc, 75);
12447 END IF;
12448
12449 ln_hours_worked := 0;
12450
12451 IF g_debug
12452 THEN
12453 hr_utility.TRACE ( 'ln_hours_worked :'
12454 || ln_hours_worked
12455 );
12456 END IF;
12457 ELSE
12458 IF g_debug
12459 THEN
12460 hr_utility.set_location (l_proc, 80);
12461 END IF;
12462
12463 ln_hours_worked := ((ln_end_time - ln_start_time) * 24);
12464
12465 IF g_debug
12466 THEN
12467 hr_utility.TRACE ( 'ln_hours_worked :'
12468 || ln_hours_worked
12469 );
12470 END IF;
12471 END IF;
12472
12473 IF g_debug
12474 THEN
12475 hr_utility.TRACE ('ln_row_id :' || ln_row_id);
12476 END IF;
12477
12478 UPDATE hxt_det_hours_worked
12479 SET time_out = ln_end_time,
12480 hours = ln_hours_worked
12481 WHERE ROWID = ln_row_id;
12482 ELSE
12483 IF g_debug
12484 THEN
12485 hr_utility.set_location (l_proc, 85);
12486 END IF;
12487
12488 ln_start_time := start_time1;
12489 ln_end_time := end_time1;
12490 ln_hours := ((ln_end_time - ln_start_time) * 24);
12491 ln_row_id := row_id1;
12492 ln_amount := ln_amount1;
12493 ln_hourly_rate := ln_hourly_rate1;
12494 ln_rate_multiple := ln_rate_multiple1;
12495 lv_prev_wage_code := lv_prev_wage_code1;
12496
12497 IF g_debug
12498 THEN
12499 hr_utility.TRACE ('ln_row_id :' || ln_row_id);
12500 hr_utility.TRACE ( 'ln_start_time :'
12501 || TO_CHAR (ln_start_time,
12502 'DD-MON-YYYY HH24:MI:SS'
12503 )
12504 );
12505 hr_utility.TRACE ( 'ln_end_time :'
12506 || TO_CHAR (ln_end_time,
12507 'DD-MON-YYYY HH24:MI:SS'
12508 )
12509 );
12510 hr_utility.TRACE ('ln_hours :' || ln_hours);
12511 hr_utility.TRACE ('ln_amount :' || ln_amount);
12512 hr_utility.TRACE ('ln_hourly_rate :' || ln_hourly_rate);
12513 hr_utility.TRACE ('ln_rate_multiple :'
12514 || ln_rate_multiple
12515 );
12516 hr_utility.TRACE ( 'lv_prev_wage_code:'
12517 || lv_prev_wage_code
12518 );
12519 END IF;
12520 END IF;
12521
12522 IF g_debug
12523 THEN
12524 hr_utility.set_location (l_proc, 90);
12525 END IF;
12526 END IF;
12527
12528 IF g_debug
12529 THEN
12530 hr_utility.set_location (l_proc, 95);
12531 END IF;
12532 END LOOP;
12533
12534 IF g_debug
12535 THEN
12536 hr_utility.set_location (l_proc, 100);
12537 END IF;
12538 END LOOP;
12539
12540 IF g_debug
12541 THEN
12542 hr_utility.set_location (l_proc, 110);
12543 END IF;
12544
12545 RETURN 0;
12546 EXCEPTION
12547 WHEN NO_DATA_FOUND
12548 THEN
12549 IF g_debug
12550 THEN
12551 hr_utility.set_location (l_proc, 120);
12552 END IF;
12553
12554 RETURN 0;
12555 WHEN OTHERS
12556 THEN
12557 IF g_debug
12558 THEN
12559 hr_utility.set_location (l_proc, 130);
12560 END IF;
12561
12562 fnd_message.set_name ('HXT', 'HXT_XXXXX_COMBINE_HRS_ERR');
12563 l_error_code :=
12564 call_hxthxc_gen_error ('HXT',
12565 'HXT_XXXXX_COMBINE_HRS_ERR',
12566 NULL,
12567 LOCATION,
12568 '',
12569 SQLERRM
12570 );
12571 END combine_contig_chunks;
12572
12573 FUNCTION pay (
12574 a_hours_to_pay IN NUMBER,
12575 a_pay_element_type_id IN NUMBER,
12576 a_time_in IN DATE,
12577 a_time_out IN DATE,
12578 a_date_worked IN DATE,
12579 a_id IN NUMBER,
12580 a_assignment_id IN NUMBER,
12581 a_fcl_earn_reason_code IN VARCHAR2,
12582 a_ffv_cost_center_id IN NUMBER,
12583 a_ffv_labor_account_id IN NUMBER,
12584 a_tas_id IN NUMBER,
12585 a_location_id IN NUMBER,
12586 a_sht_id IN NUMBER,
12587 a_hrw_comment IN VARCHAR2,
12588 a_ffv_rate_code_id IN NUMBER,
12589 a_rate_multiple IN NUMBER,
12590 a_hourly_rate IN NUMBER,
12591 a_amount IN NUMBER,
12592 a_fcl_tax_rule_code IN VARCHAR2,
12593 a_separate_check_flag IN VARCHAR2,
12594 a_project_id IN NUMBER,
12595 -- a_GROUP_ID IN NUMBER,
12596 a_earn_policy_id IN NUMBER,
12597 a_sdf_id IN NUMBER DEFAULT NULL,
12598 a_state_name IN VARCHAR2 DEFAULT NULL,
12599 a_county_name IN VARCHAR2 DEFAULT NULL,
12600 a_city_name IN VARCHAR2 DEFAULT NULL,
12601 a_zip_code IN VARCHAR2 DEFAULT NULL
12602 )
12603 RETURN NUMBER
12604 IS
12605 -- declare local variables
12606 l_work_plan NUMBER;
12607 l_rotation_plan NUMBER;
12608 l_retcode NUMBER;
12609 l_hours NUMBER;
12610 l_shift_hours NUMBER;
12611 l_hdp_id NUMBER;
12612 l_hol_id NUMBER;
12613 l_sdp_id NUMBER;
12614 l_ep_type hxt_earning_policies.fcl_earn_type%TYPE;
12615 l_egt_id NUMBER;
12616 l_pep_id NUMBER;
12617 l_pip_id NUMBER;
12618 l_hcl_id NUMBER;
12619 l_hcl_elt_id NUMBER;
12620 l_sdf_id NUMBER;
12621 l_osp_id NUMBER;
12622 l_standard_start NUMBER;
12623 l_standard_stop NUMBER;
12624 l_early_start NUMBER;
12625 l_late_stop NUMBER;
12626 l_min_tcard_intvl NUMBER;
12627 l_round_up NUMBER;
12628 l_hol_code NUMBER;
12629 l_hol_yn VARCHAR2 (1) := 'N';
12630 l_error NUMBER;
12631 l_overtime_type VARCHAR2 (4); --OVEREARN
12632 l_errmsg VARCHAR2 (400);
12633 l_earn_id NUMBER;
12634 error_in_gen_pol EXCEPTION; -- OVEREARN
12635 error_in_policies EXCEPTION;
12636 error_in_shift_info EXCEPTION;
12637 error_in_check_hol EXCEPTION;
12638 l_proc VARCHAR2 (200);
12639 l_det_count NUMBER;
12640
12641 -- Bug 7388588
12642 -- Forced hints and modified the below query to get rid of the
12643 -- performance issue.
12644 /*
12645 CURSOR csr_test_for_osp (p_assignment_id NUMBER, p_date_worked DATE)
12646 IS
12647 SELECT hws.off_shift_prem_id
12648 FROM hxt_shifts hs,
12649 hxt_work_shifts hws,
12650 hxt_per_aei_ddf_v aeiv,
12651 hxt_rotation_schedules hrs
12652 WHERE aeiv.assignment_id = p_assignment_id
12653 AND p_date_worked BETWEEN aeiv.effective_start_date
12654 AND aeiv.effective_end_date
12655 AND hrs.rtp_id = aeiv.hxt_rotation_plan
12656 AND hrs.start_date =
12657 (SELECT MAX (start_date)
12658 FROM hxt_rotation_schedules
12659 WHERE rtp_id = hrs.rtp_id AND start_date <= p_date_worked)
12660 AND hws.tws_id = hrs.tws_id
12661 AND hws.week_day = TO_CHAR (p_date_worked, 'DY')
12662 AND hws.sht_id = hs.ID;
12663
12664 */
12665
12666 CURSOR csr_test_for_osp (p_assignment_id NUMBER, p_date_worked DATE)
12667 IS
12668 SELECT /*+ ORDERED
12669 INDEX(hrs hxt_rotation_schedules_pk)
12670 USE_NL(aeiv hrs)
12671 USE_NL(hrs hws) */
12672 hws.off_shift_prem_id
12673 FROM hxt_per_aei_ddf_v aeiv,
12674 hxt_rotation_schedules hrs,
12675 hxt_work_shifts hws,
12676 hxt_shifts hs
12677 WHERE aeiv.assignment_id = p_assignment_id
12678 AND p_date_worked BETWEEN aeiv.effective_start_date
12679 AND aeiv.effective_end_date
12680 AND hrs.rtp_id = aeiv.hxt_rotation_plan
12681 AND hrs.start_date <= p_date_worked
12682 AND hws.tws_id = hrs.tws_id
12683 AND hws.week_day = TO_CHAR (p_date_worked, 'DY')
12684 AND hws.sht_id = hs.ID
12685 ORDER BY hrs.start_date DESC;
12686
12687 BEGIN
12688 IF g_debug
12689 THEN
12690 l_proc := 'hxt_time_detail.pay';
12691 hr_utility.set_location (l_proc, 10);
12692 hr_utility.TRACE ( 'a_time_in :'
12693 || TO_CHAR (a_time_in, 'DD-MON-YYYY HH24:MI:SS')
12694 );
12695 hr_utility.TRACE ( 'a_time_out:'
12696 || TO_CHAR (a_time_out, 'DD-MON-YYYY HH24:MI:SS')
12697 );
12698 hr_utility.TRACE ('g_sdf_id :' || g_sdf_id);
12699 END IF;
12700
12701 IF a_hours_to_pay = 0 and (a_amount is null or a_amount = 0) /* Bug: 5744162 */
12702 THEN
12703 SELECT count(*)
12704 INTO l_det_count
12705 FROM hxt_det_hours_worked_f
12706 WHERE date_worked = a_date_worked
12707 AND assignment_id = a_assignment_id;
12708
12709 IF l_det_count = 0 THEN
12710 RETURN 0;
12711 END IF;
12712 END IF;
12713
12714 IF g_id <> a_id
12715 THEN
12716 IF g_debug
12717 THEN
12718 hr_utility.set_location (l_proc, 20);
12719 END IF;
12720
12721 -- We have backed up to a previous day to apply overtime due
12722 -- to an absence at the end of the week so we need to get the
12723 -- rules for the new day we are processing
12724
12725 -- get policy information for the actual date worked
12726
12727 -- Get policies assigned to person
12728 BEGIN
12729 IF g_debug
12730 THEN
12731 hr_utility.set_location (l_proc, 30);
12732 END IF;
12733
12734 hxt_util.get_policies (a_earn_policy_id,
12735 a_assignment_id,
12736 a_date_worked,
12737 l_work_plan,
12738 l_rotation_plan,
12739 l_earn_id,
12740 l_hdp_id,
12741 l_sdp_id,
12742 l_ep_type,
12743 l_egt_id,
12744 l_pep_id,
12745 l_pip_id,
12746 l_hcl_id,
12747 l_min_tcard_intvl,
12748 l_round_up,
12749 l_hcl_elt_id,
12750 l_error
12751 );
12752
12753 IF g_debug
12754 THEN
12755 hr_utility.set_location (l_proc, 40);
12756 hr_utility.TRACE ('l_sdp_id:' || l_sdp_id);
12757 hr_utility.TRACE ('l_pep_id:' || l_pep_id);
12758 END IF;
12759
12760 -- Check if error encountered
12761 IF l_error <> 0
12762 THEN
12763 IF g_debug
12764 THEN
12765 hr_utility.set_location (l_proc, 50);
12766 END IF;
12767
12768 RAISE error_in_policies;
12769 END IF;
12770
12771 IF g_debug
12772 THEN
12773 hr_utility.set_location (l_proc, 60);
12774 END IF;
12775 END;
12776
12777 IF g_debug
12778 THEN
12779 hr_utility.set_location (l_proc, 70);
12780 END IF;
12781
12782 -- Check if person assigned work or rotation plan
12783 BEGIN
12784 IF (l_work_plan IS NOT NULL) OR (l_rotation_plan IS NOT NULL)
12785 THEN
12786 IF g_debug
12787 THEN
12788 hr_utility.set_location (l_proc, 80);
12789 END IF;
12790
12791 -- Get premiums for shift
12792 hxt_util.get_shift_info (a_date_worked,
12793 l_work_plan,
12794 l_rotation_plan,
12795 l_osp_id,
12796 l_sdf_id,
12797 l_standard_start,
12798 l_standard_stop,
12799 l_early_start,
12800 l_late_stop,
12801 l_shift_hours,
12802 l_error
12803 );
12804
12805 IF g_debug
12806 THEN
12807 hr_utility.set_location (l_proc, 90);
12808 hr_utility.TRACE ('l_sdf_id :' || l_sdf_id);
12809 hr_utility.TRACE ('l_osp_id :' || l_osp_id);
12810 END IF;
12811
12812 -- Check if error encountered
12813 IF l_error <> 0
12814 THEN
12815 IF g_debug
12816 THEN
12817 hr_utility.set_location (l_proc, 100);
12818 END IF;
12819
12820 RAISE error_in_shift_info;
12821 END IF;
12822
12823 -- IF shift override id i.e., l_sdf_id is NULL then
12824 -- set it to Shift diff ID - from the shift differential policy
12825 IF l_sdf_id IS NULL
12826 THEN
12827 IF g_debug
12828 THEN
12829 hr_utility.set_location (l_proc, 105);
12830 END IF;
12831
12832 l_sdf_id := a_sdf_id;
12833
12834 IF g_debug
12835 THEN
12836 hr_utility.TRACE ('l_sdf_id :' || l_sdf_id);
12837 END IF;
12838 END IF;
12839
12840 IF g_debug
12841 THEN
12842 hr_utility.set_location (l_proc, 110);
12843 END IF;
12844 END IF; -- person assigned work or rotation plan
12845
12846 IF g_debug
12847 THEN
12848 hr_utility.set_location (l_proc, 120);
12849 END IF;
12850 END;
12851
12852 -- Get holiday earning, day before/after, etc
12853 BEGIN
12854 IF g_debug
12855 THEN
12856 hr_utility.set_location (l_proc, 130);
12857 END IF;
12858
12859 hxt_util.check_for_holiday (a_date_worked,
12860 l_hcl_id,
12861 l_hol_id,
12862 l_hours,
12863 l_retcode
12864 );
12865
12866 IF g_debug
12867 THEN
12868 hr_utility.set_location (l_proc, 135);
12869 END IF;
12870
12871 -- Check if holiday
12872 IF l_retcode = 1
12873 THEN
12874 IF g_debug
12875 THEN
12876 hr_utility.set_location (l_proc, 140);
12877 END IF;
12878
12879 -- Set holiday code
12880 l_hol_yn := 'Y';
12881 END IF; -- holiday or not
12882
12883 IF g_debug
12884 THEN
12885 hr_utility.set_location (l_proc, 145);
12886 END IF;
12887 EXCEPTION
12888 -- Check for error
12889 WHEN OTHERS
12890 THEN
12891 IF g_debug
12892 THEN
12893 hr_utility.set_location (l_proc, 150);
12894 END IF;
12895
12896 l_errmsg := SQLCODE;
12897 RAISE error_in_check_hol;
12898 END;
12899
12900 IF g_debug
12901 THEN
12902 hr_utility.set_location (l_proc, 155);
12903 END IF;
12904
12905 OPEN csr_test_for_osp (a_assignment_id, a_date_worked);
12906
12907 FETCH csr_test_for_osp
12908 INTO l_osp_id;
12909
12910 CLOSE csr_test_for_osp;
12911
12912 RETURN hxt_time_pay.pay (a_earn_policy_id, --SIR337
12913 l_ep_type,
12914 l_egt_id,
12915 a_sdf_id,
12916 l_hdp_id,
12917 l_hol_id,
12918 l_pep_id,
12919 l_pip_id,
12920 NULL, --g_sdovr_id,
12921 l_osp_id,
12922 l_hol_yn,
12923 g_person_id,
12924 g_location,
12925 a_id,
12926 g_tim_id,
12927 a_date_worked,
12928 a_assignment_id,
12929 a_hours_to_pay,
12930 a_time_in,
12931 a_time_out,
12932 a_pay_element_type_id,
12933 a_fcl_earn_reason_code,
12934 a_ffv_cost_center_id,
12935 a_ffv_labor_account_id,
12936 a_tas_id,
12937 a_location_id,
12938 a_sht_id,
12939 a_hrw_comment,
12940 a_ffv_rate_code_id,
12941 a_rate_multiple,
12942 a_hourly_rate,
12943 a_amount,
12944 a_fcl_tax_rule_code,
12945 a_separate_check_flag,
12946 g_seqno, -- not used for anything
12947 g_created_by,
12948 g_creation_date,
12949 g_last_updated_by,
12950 g_last_update_date,
12951 g_last_update_login,
12952 g_effective_start_date,
12953 g_effective_end_date, -- C431
12954 a_project_id,
12955 g_pay_status, -- RETROPAY
12956 g_pa_status, -- PROJACCT
12957 g_retro_batch_id, -- RETROPAY
12958 g_state_name => a_state_name,
12959 g_county_name => a_county_name,
12960 g_city_name => a_city_name,
12961 g_zip_code => a_zip_code
12962 -- a_GROUP_ID -- HXT11i1
12963 );
12964
12965 IF g_debug
12966 THEN
12967 hr_utility.set_location (l_proc, 160);
12968 END IF;
12969 ELSE
12970 IF g_debug
12971 THEN
12972 hr_utility.set_location (l_proc, 165);
12973 hr_utility.TRACE ('a_sdf_id :' || a_sdf_id);
12974 END IF;
12975
12976 OPEN csr_test_for_osp (a_assignment_id, a_date_worked);
12977
12978 FETCH csr_test_for_osp
12979 INTO g_osp_id;
12980
12981 CLOSE csr_test_for_osp;
12982
12983 RETURN hxt_time_pay.pay (g_ep_id,
12984 g_ep_type,
12985 g_egt_id,
12986 g_sdf_id,
12987 g_hdp_id,
12988 g_hol_id,
12989 g_pep_id,
12990 g_pip_id,
12991 g_sdovr_id,
12992 g_osp_id,
12993 g_hol_yn,
12994 g_person_id,
12995 g_location,
12996 a_id,
12997 g_tim_id,
12998 a_date_worked,
12999 a_assignment_id,
13000 a_hours_to_pay,
13001 a_time_in,
13002 a_time_out,
13003 a_pay_element_type_id,
13004 a_fcl_earn_reason_code,
13005 a_ffv_cost_center_id,
13006 a_ffv_labor_account_id,
13007 a_tas_id,
13008 a_location_id,
13009 a_sht_id,
13010 a_hrw_comment,
13011 a_ffv_rate_code_id,
13012 a_rate_multiple,
13013 a_hourly_rate,
13014 a_amount,
13015 a_fcl_tax_rule_code,
13016 a_separate_check_flag,
13017 g_seqno,
13018 g_created_by,
13019 g_creation_date,
13020 g_last_updated_by,
13021 g_last_update_date,
13022 g_last_update_login,
13023 g_effective_start_date,
13024 g_effective_end_date,
13025 a_project_id,
13026 g_pay_status,
13027 g_pa_status,
13028 g_retro_batch_id,
13029 g_state_name => a_state_name,
13030 g_county_name => a_county_name,
13031 g_city_name => a_city_name,
13032 g_zip_code => a_zip_code
13033 -- a_GROUP_ID
13034 );
13035
13036 IF g_debug
13037 THEN
13038 hr_utility.set_location (l_proc, 170);
13039 END IF;
13040 END IF;
13041
13042 IF g_debug
13043 THEN
13044 hr_utility.set_location (l_proc, 175);
13045 END IF;
13046 EXCEPTION
13047 --Begin OVEREARN
13048 WHEN error_in_gen_pol
13049 THEN
13050 IF g_debug
13051 THEN
13052 hr_utility.set_location (l_proc, 180);
13053 END IF;
13054
13055 fnd_message.set_name ('HXT', 'HXT_39440_GEN_EP_ERR');
13056 RETURN call_hxthxc_gen_error ('HXT',
13057 'HXT_39440_GEN_EP_ERR',
13058 NULL,
13059 g_location,
13060 '',
13061 SQLERRM
13062 );
13063 --2278400 RETURN call_gen_error(g_location, '', sqlerrm);
13064 --End OVEREARN
13065 WHEN error_in_policies
13066 THEN
13067 IF g_debug
13068 THEN
13069 hr_utility.set_location (l_proc, 185);
13070 END IF;
13071
13072 fnd_message.set_name ('HXT', 'HXT_39171_ERN_POL_OP_VIOL');
13073 RETURN call_hxthxc_gen_error ('HXT',
13074 'HXT_39171_ERN_POL_OP_VIOL',
13075 NULL,
13076 g_location,
13077 '',
13078 SQLERRM
13079 );
13080 --2278400 RETURN call_gen_error(g_location, '', sqlerrm);
13081 WHEN error_in_shift_info
13082 THEN
13083 IF g_debug
13084 THEN
13085 hr_utility.set_location (l_proc, 190);
13086 END IF;
13087
13088 fnd_message.set_name ('HXT', 'HXT_39172_SHF_PREMS_OP_VIOL');
13089 RETURN call_hxthxc_gen_error ('HXT',
13090 'HXT_39172_SHF_PREMS_OP_VIOL',
13091 NULL,
13092 g_location,
13093 '',
13094 SQLERRM
13095 );
13096 --2278400 RETURN call_gen_error(g_location, '', sqlerrm);
13097 WHEN error_in_check_hol
13098 THEN
13099 IF g_debug
13100 THEN
13101 hr_utility.set_location (l_proc, 195);
13102 END IF;
13103
13104 fnd_message.set_name ('HXT', 'HXT_39173_HOL_OP_VIOL');
13105 RETURN call_hxthxc_gen_error ('HXT',
13106 'HXT_39173_HOL_OP_VIOL',
13107 NULL,
13108 g_location,
13109 '',
13110 SQLERRM
13111 );
13112 --2278400 RETURN call_gen_error(g_location, '', sqlerrm);
13113 WHEN OTHERS
13114 THEN
13115 IF g_debug
13116 THEN
13117 hr_utility.set_location (l_proc, 200);
13118 END IF;
13119
13120 fnd_message.set_name ('HXT', 'HXT_39269_ORACLE_ERROR');
13121 RETURN call_hxthxc_gen_error ('HXT',
13122 'HXT_39269_ORACLE_ERROR',
13123 NULL,
13124 g_location,
13125 '',
13126 SQLERRM
13127 );
13128 --2278400 RETURN call_gen_error(g_location, '', sqlerrm);
13129 END; --pay
13130
13131 --------------------------------------------------------------------------------
13132 --BEGIN HXT11i1
13133 FUNCTION contig_hours_worked (
13134 p_date_worked IN hxt_det_hours_worked_f.date_worked%TYPE,
13135 p_egt_id IN hxt_earn_groups.egt_id%TYPE,
13136 p_tim_id IN hxt_det_hours_worked_f.tim_id%TYPE
13137 )
13138 RETURN hxt_det_hours_worked.hours%TYPE
13139 IS
13140 /* Local Variable Declaration */
13141 l_worked_hours hxt_det_hours_worked.hours%TYPE := 0;
13142
13143 /*Cursor Declaration */
13144 CURSOR csr_work_hrs (
13145 p_date_worked hxt_det_hours_worked_f.date_worked%TYPE,
13146 p_tim_id hxt_det_hours_worked_f.tim_id%TYPE
13147 )
13148 IS
13149 SELECT hrw.hours, hrw.element_type_id, eltv.hxt_earning_category
13150 FROM hxt_det_hours_worked hrw,
13151 hxt_pay_element_types_f_ddf_v eltv,
13152 pay_element_types_f elt
13153 WHERE elt.element_type_id = hrw.element_type_id
13154 AND hrw.date_worked BETWEEN elt.effective_start_date
13155 AND elt.effective_end_date
13156 AND eltv.element_type_id = elt.element_type_id
13157 AND hrw.date_worked BETWEEN eltv.effective_start_date
13158 AND eltv.effective_end_date
13159 AND hrw.tim_id = p_tim_id
13160 AND hrw.date_worked = p_date_worked
13161 AND ( ( hrw.time_in IS NOT NULL
13162 AND hrw.time_out IS NOT NULL
13163 AND hrw.time_in <> hrw.time_out
13164 )
13165 OR (hrw.time_in IS NULL AND hrw.time_out IS NULL)
13166 )
13167 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y'; /* Bug: 4489952 */
13168
13169 FUNCTION in_earnings_group (
13170 p_element_type_id IN hxt_earn_groups.element_type_id%TYPE,
13171 p_egt_id IN hxt_earn_groups.egt_id%TYPE
13172 )
13173 RETURN BOOLEAN
13174 AS
13175 CURSOR csr_in_earnings_group (
13176 p_element_type_id hxt_earn_groups.element_type_id%TYPE,
13177 p_egt_id hxt_earn_groups.egt_id%TYPE
13178 )
13179 IS
13180 SELECT 1
13181 FROM hxt_earn_group_types hegt, hxt_earn_groups heg
13182 WHERE hegt.ID = p_egt_id
13183 AND heg.egt_id = p_egt_id
13184 AND heg.element_type_id = p_element_type_id;
13185
13186 l_found csr_in_earnings_group%ROWTYPE;
13187 l_in_earnings_group BOOLEAN := FALSE;
13188 BEGIN
13189 OPEN csr_in_earnings_group (p_element_type_id, p_egt_id);
13190
13191 FETCH csr_in_earnings_group
13192 INTO l_found;
13193
13194 IF (csr_in_earnings_group%FOUND)
13195 THEN
13196 l_in_earnings_group := TRUE;
13197 END IF;
13198
13199 CLOSE csr_in_earnings_group;
13200
13201 RETURN l_in_earnings_group;
13202 END in_earnings_group;
13203 /* Main Function */
13204 BEGIN
13205
13206 <<process_hrs>>
13207 FOR rec_work_hrs IN csr_work_hrs (p_date_worked, p_tim_id)
13208 LOOP
13209 IF ( (rec_work_hrs.hxt_earning_category IN ('REG', 'OVT'))
13210 OR ( (rec_work_hrs.hxt_earning_category = 'ABS')
13211 AND (in_earnings_group (rec_work_hrs.element_type_id,
13212 p_egt_id
13213 )
13214 )
13215 )
13216 )
13217 THEN
13218 l_worked_hours := l_worked_hours + rec_work_hrs.hours;
13219 END IF;
13220 END LOOP process_hrs;
13221
13222 RETURN l_worked_hours;
13223 END contig_hours_worked;
13224
13225 --
13226 -------------------------------------------------------------------------------
13227 --
13228 PROCEDURE overtime_hoursoverride (
13229 p_date_worked IN hxt_det_hours_worked_f.date_worked%TYPE,
13230 p_egt_id IN hxt_earn_groups.egt_id%TYPE,
13231 p_tim_id IN hxt_det_hours_worked_f.tim_id%TYPE,
13232 p_override_hrs OUT NOCOPY hxt_det_hours_worked_f.hours%TYPE,
13233 p_override_element OUT NOCOPY hxt_det_hours_worked_f.element_type_id%TYPE
13234 )
13235 -- RETURN hxt_det_hours_worked.hours%TYPE
13236 IS
13237 /* Local Variable Declaration */
13238 l_worked_hours hxt_det_hours_worked.hours%TYPE := 0;
13239 l_element_type_id hxt_det_hours_worked.element_type_id%TYPE;
13240
13241 /*Cursor Declaration */
13242 CURSOR csr_override_hrs (
13243 p_date_worked hxt_det_hours_worked_f.date_worked%TYPE,
13244 p_tim_id hxt_det_hours_worked_f.tim_id%TYPE
13245 )
13246 IS
13247 SELECT hrw.hours, hrw.element_type_id, eltv.hxt_earning_category
13248 FROM hxt_sum_hours_worked hrw,
13249 hxt_pay_element_types_f_ddf_v eltv,
13250 pay_element_types_f elt
13251 WHERE elt.element_type_id = hrw.element_type_id
13252 AND hrw.date_worked BETWEEN elt.effective_start_date
13253 AND elt.effective_end_date
13254 AND eltv.element_type_id = elt.element_type_id
13255 AND hrw.date_worked BETWEEN eltv.effective_start_date
13256 AND eltv.effective_end_date
13257 AND hrw.tim_id = p_tim_id
13258 AND hrw.date_worked = p_date_worked
13259 AND ( ( hrw.time_in IS NOT NULL
13260 AND hrw.time_out IS NOT NULL
13261 AND hrw.time_in <> hrw.time_out
13262 )
13263 OR (hrw.time_in IS NULL AND hrw.time_out IS NULL)
13264 )
13265 -- Following condition to get total for override hrs only
13266 AND hrw.element_type_id IS NOT NULL
13267 AND nvl(eltv.exclude_from_explosion, 'N') <> 'Y'; /* Bug: 4489952 */
13268
13269 l_proc VARCHAR2 (500);
13270 /* Main Function */
13271 BEGIN
13272 IF g_debug
13273 THEN
13274 l_proc := 'hxt_time_detail.Overtime_Hoursoverride';
13275 hr_utility.set_location (l_proc, 10);
13276 END IF;
13277
13278 <<process_hrs>>
13279 IF g_debug
13280 THEN
13281 hr_utility.set_location (l_proc, 20);
13282 END IF;
13283
13284 FOR rec_work_hrs IN csr_override_hrs (p_date_worked, p_tim_id)
13285 LOOP
13286 IF g_debug
13287 THEN
13288 hr_utility.set_location (l_proc, 30);
13289 hr_utility.TRACE ( 'rec_work_hrs.hxt_earning_category:'
13290 || rec_work_hrs.hxt_earning_category
13291 );
13292 hr_utility.TRACE ('rec_work_hrs.hours:' || rec_work_hrs.hours);
13293 hr_utility.TRACE ( 'rec_work_hrs.element_type_id:'
13294 || rec_work_hrs.element_type_id
13295 );
13296 END IF;
13297
13298 IF rec_work_hrs.hxt_earning_category = 'OVT'
13299 THEN
13300 IF g_debug
13301 THEN
13302 hr_utility.set_location (l_proc, 40);
13303 END IF;
13304
13305 l_worked_hours := l_worked_hours + rec_work_hrs.hours;
13306 l_element_type_id := rec_work_hrs.element_type_id;
13307
13308 IF g_debug
13309 THEN
13310 hr_utility.TRACE ('l_worked_hours:' || l_worked_hours);
13311 hr_utility.TRACE ('l_element_type_id:' || l_element_type_id);
13312 END IF;
13313 END IF;
13314
13315 IF g_debug
13316 THEN
13317 hr_utility.set_location (l_proc, 50);
13318 END IF;
13319 END LOOP process_hrs;
13320
13321 IF g_debug
13322 THEN
13323 hr_utility.set_location (l_proc, 60);
13324 END IF;
13325
13326 -- RETURN NVL (l_worked_hours, 0);
13327 p_override_hrs := l_worked_hours;
13328 p_override_element := l_element_type_id;
13329
13330 IF g_debug
13331 THEN
13332 hr_utility.TRACE ('p_override_hrs:' || p_override_hrs);
13333 hr_utility.TRACE ('p_override_element:' || p_override_element);
13334 END IF;
13335 END overtime_hoursoverride;
13336 --
13337 -------------------------------------------------------------------------------
13338 --
13339 END; -- package