Click here to Skip to main content
14,638,114 members
Rate this:
Please Sign up or sign in to vote.
See more:
OH for the love of god, for some reason i cant make sense of this, please someone help. This is what i have

Timecard Object/Class
MinutesRegular as Integer
MinutesOvertimeDailyRate1 as Integer
MinutesOvertimeDailyRate2 as Integer
MinutesOvertimeWeeklyRate1 as Integer
MinutesOvertimeWeeklyRate2 as Integer
MinutesTotal as Integer
WageRegular as Double
WageOvertimeDailyRate1 as Double
WageOvertimeDailyRate2 as Double
WageOvertimeWeeklyRate1 as Double
WageOvertimeWeeklyRate2 as Double
WageTotal as Double
DeductedMinutes as Integer

OvertimeRule Object/Class
OvertimeID As Long
OvertimeName As String 
IncludeLeaveHours As Boolean 
OvertimeRate1 As Decimal
OvertimeRate2 As Decimal 
WeeklyThreshold1 As Decimal
WeeklyThreshold2 As Decimal
MondayThreshold1 As Decimal
MondayThreshold2 As Decimal
TuesdayThreshold1 As Decimal
TuesdayThreshold2 As Decimal
WednesdayThreshold1 As Decimal 
WednesdayThreshold2 As Decimal
ThursdayThreshold1 As Decimal
ThursdayThreshold2 As Decimal 
FridayThreshold1 As Decimal
FridayThreshold2 As Decimal
SaturdayThreshold1 As Decimal 
SaturdayThreshold2 As Decimal
SundayThreshold1 As Decimal
SundayThreshold2 As Decimal
SixthDaySetting1 As String
SixthDaySetting2 As String 
SeventhDaySetting1 As String 
SeventhDaySetting2 As String 

So upon Closing the period, All Timecards within the pay period are retrieved from the database.
All deducted minutes are applied,then the Leave times are calculated, then the daily OT, then each timecard is saved, All is good up to this point, then a call to calculateWeeklyOT and this is where i have the problem for some reason:
At this point say an employee has worked 12.5 hours each day for 7 days, 30 mins gets deducted because of the autotime deduction(Non relevant really) but The MinutesRegular will show 720 minutes and deductedMinutes will show 30 for each day, Daily OT is anything over 8 hours so MinutesOvertimeDailyRate1 shows 240 minutes, which updates minutesRegular to 480 minutes for each day. The Timecards are already sorted by startdatetime so so far i have the following

Private Sub CalculateWeeklyOvertime()
       Dim TotalMinutes As Decimal
       Dim OT1Applied As Decimal = 0
       Dim OT2Applied As Decimal = 0
       Dim TimeWorked As Decimal = 0
       Dim MinutesOverOT1 As Decimal = 0
       Dim MinutesOverOT2 As Decimal = 0
       Dim WeeklyThreshold1 As Decimal = OT.WeeklyThreshold1 * 60
       Dim WeeklyThreshold2 As Decimal = OT.WeeklyThreshold2 * 60

       'calculatedTimecardList is sorted in ascending order by Startdatetime
       For Each Timecard In CalculatedTimecardList

           'Check to see if this is a leave timecard and if so, if it should be calculated in WOT
           If Timecard.EntryType = 2 Then
               If TCC.PayrollSettings.IncludeLeaveInOvertimeCalcs = False Then
                   'skip the rest of the caluclations and continue on to the next timecard
                   Continue For
               End If
           End If

           'track the total minutes so we know when we are over the thresholds
           TotalMinutes += Timecard.MinutesRegular + Timecard.MinutesOvertimeDailyRate1 + Timecard.MinutesOvertimeDailyRate2
           TimeWorked = Timecard.MinutesRegular + Timecard.MinutesOvertimeDailyRate1 + Timecard.MinutesOvertimeDailyRate2
           MinutesOverOT1 = TotalMinutes - WeeklyThreshold1
           MinutesOverOT2 = TotalMinutes - WeeklyThreshold2

           'do not apply if there is  no WOT2
           If OT.WeeklyThreshold2 = 0 Then
               Timecard.MinutesOvertimeWeeklyRate2 = 0

               'we have a treshold, check to see if the totalminutes is over that threshold
               If TotalMinutes > WeeklyThreshold2 Then
                   'Total Minutes is over the Threshold

               End If

           End If

           'do not apply if there is  no WOT1
           If OT.WeeklyThreshold1 <= 0 Then
               Timecard.MinutesOvertimeWeeklyRate1 = 0
               If TotalMinutes > WeeklyThreshold1 Then
                   'Total Minutes is over the Threshold

               End If
           End If


   End Sub

What Im trying to do is to record the Weekly Overtime On Each Timecard and whether its WOT1 or WOt2
So if given this example of 12.5 hours, .5 hours deducted, so 12 hours a day
The Minutes Regular being 480 and DailyOT1 240
I should get a result like this
MinutesReg 	DOT1 	DOt2 	WOt1 	WOT2
480		240
480		240
480		240
0		240		480	
0		240		480
0		240			480
0		240			480

I really cant get this, im probably over complicating this, or over thinking or something but any help at all, i would be grateful, it seem like such a trivial thing. I know its alot to read but the basics is i want each timecard to record its own WOT1 and WOT2 (WOT1 being 40 hours and WOT2 being 60 hours). Thanks again if you an assist in any way.
Updated 17-Sep-14 10:26am
Sergey Alexandrovich Kryukov 17-Sep-14 16:17pm
"I really can't get it" is not informative enough. Could you, instead of being focused on concrete figures, explain it properly? What piece of code should do what, what did you expect from it, what did you observe instead, what make you think that the observed result is wrong? The problem looks really simple; did you try to use the debugger to see from what place the discrepancy starts? When you figure it out, you could rethink the design of the code...
Sergey Alexandrovich Kryukov 17-Sep-14 17:13pm
And how about using the debugger?
Maciej Los 17-Sep-14 16:28pm
I agree with Sergey.
Maciej Los 4-Nov-14 18:03pm
Is it solved or not?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100