I need help with this because I'm stuck. Can someone help me to do this procedure in a smart and easy way?
We have a table where we store timestamps on employees when it starts and ends the workday. Now we need to create a procedure that returns three (over_time_1, over_time_2, over_time_3) overtime calculations in hours. Parameter in to the procedure will be start date, end date, and employee number from the tblEmployeeTimestamp table. Start date and end date can be on different days if the employee work at night etc.
The procedure's calculation rules should be as below.
To know if it's a public holiday and "an extra day off" it's defined in a table tblSchema containing employee number, type and date.
over_time_1:
Monday - Friday 06:00:00 - 06:40:00 //IF employee has number 100-999 and 2000-2999
Monday - Friday 06:00:00 - 06:50:00 //IF employee has number 1000-1999
Monday - Friday 16:00:00 - 20:00:00
Friday 13:00:00 - 16:00:00
OT2 00:00:00 - 23:59:59 //IF employee has number 100-999 and 1000-1999
over_time_2:
Monday evening - Friday morning 20:00:00 – 06:00:00
over_time_3:
Friday evening – Monday morning 20:00:00 - 06.00:00
OT1 00:00:00 - 23:59:59
Examples:
tblEmployeeTimestamp
Employee---Startdate-------------Endate-------------
----------------------------------------------------
250--------2015-10-05 06:40:00---2015-10-05 13:00:00
tblSchema
Employee---Date----------Type---
--------------------------------
250--------2015-12-24----OT1 //Christmas. Public holiday
250--------2015-12-27----OT2 //Working day between holidays
OT1 = Public holiday. (Not weekend)
OT2 = An extra day off, taken to add a weekend to a public holiday. Working day between holidays