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