-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBonuses.vb
349 lines (341 loc) · 19.2 KB
/
Bonuses.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
Sub CalcBonuses()
Dim Names() As String
ReDim Preserve Names(100)
Dim Costs() As Double
ReDim Preserve Costs(100)
Dim Start As Long
Dim Finish As Long
Dim Entered As Boolean: Entered = False
Dim ShouldBeEntered As Boolean: ShouldBeEntered = True
Dim BeginDate As String
Dim EndDate As String
Dim TempString As String
Call BuildNames
Call ValidateJobs
For x = 2 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Columns.Count
If ActiveWorkbook.Worksheets("Bonuses").Cells(1, x).Value = "" Then
Exit For
End If
Dim Jobs() As String
Jobs = Split(ActiveWorkbook.Worksheets("Bonuses").Cells(1, x).Value, "||")
For Job = 0 To UBound(Jobs)
BeginDate = ""
EndDate = ""
If InStr(Jobs(Job), "(") > 0 Then
TempString = Split(Jobs(Job), "(")(1)
TempString = Split(TempString, ")")(0)
BeginDate = Split(TempString, "|")(0)
EndDate = Split(TempString, "|")(1)
Jobs(Job) = Split(Jobs(Job), "(")(0)
End If
For y = 1 To ActiveWorkbook.Worksheets("MetadataDB").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("MetadataDB").Cells(y, 1).Value = Jobs(Job) Then
Start = ActiveWorkbook.Worksheets("MetadataDB").Cells(y, 2).Value
If BeginDate <> "" Then
Do While True
If DateCompare2(BeginDate, ActiveWorkbook.Worksheets("HoursDB").Cells(Start, 5).Value) Then
Exit Do
Else
Start = Start + 1
End If
Loop
End If
Finish = ActiveWorkbook.Worksheets("MetadataDB").Cells(y, 3).Value
If EndDate <> "" Then
Do While True
If DateCompare2(ActiveWorkbook.Worksheets("HoursDB").Cells(Finish, 5).Value, EndDate) Then
Exit Do
Else
Finish = Finish - 1
End If
Loop
End If
Exit For
End If
Next
For y = Start - 1 To Finish + 1
If ActiveWorkbook.Worksheets("HoursDB").Cells(y, 8).Value = Jobs(Job) Then
For z = 2 To ActiveWorkbook.Worksheets("Employees").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Employees").Cells(z, 5) = ActiveWorkbook.Worksheets("HoursDB").Cells(y, 1).Value Then
If ActiveWorkbook.Worksheets("Employees").Cells(z, 3).Value <> "0" Then
Dim index As Integer: index = -1
For i = 0 To UBound(Names)
If Names(i) = ActiveWorkbook.Worksheets("HoursDB").Cells(y, 1).Value Then
index = i
Exit For
End If
Next
If index = -1 Then
For i = 0 To UBound(Names)
If Names(i) = "" Then
Names(i) = ActiveWorkbook.Worksheets("HoursDB").Cells(y, 1).Value
index = i
Dim TempName As String
Dim TempCost As Double
For j = i To 1 Step -1
If StrComp(Names(j - 1), Names(j), vbTextCompare) = 1 Then
TempName = Names(j - 1)
Names(j - 1) = Names(j)
Names(j) = TempName
TempCost = Costs(j - 1)
Costs(j - 1) = Costs(j)
Costs(j) = TempCost
index = j - 1
Else
index = j
Exit For
End If
Next
Exit For
End If
Next
End If
Dim Wage As Double: Wage = DetermineWage(ActiveWorkbook.Worksheets("HoursDB").Cells(y, 1), ActiveWorkbook.Worksheets("HoursDB").Cells(y, 5).Value)
If IsOvertime(ActiveWorkbook.Worksheets("HoursDB").Cells(y, 4).Value) Then
Wage = Wage * 1.5
End If
Costs(index) = Costs(index) + Wage * ActiveWorkbook.Worksheets("HoursDB").Cells(y, 3).Value
End If
End If
Next
End If
Next
Next
Dim TotalCost As Double: TotalCost = 0
For y = 0 To UBound(Costs)
TotalCost = TotalCost + Costs(y)
Next
Dim Ind As Integer
For y = 0 To UBound(Costs)
Dim K As Integer: K = 4
Do While ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value <> ""
If ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value = Names(y) Then
ActiveWorkbook.Worksheets("Bonuses").Cells(K, x).Value = Round((Costs(y) / TotalCost) * ActiveWorkbook.Worksheets("Bonuses").Cells(3, x).Value * 0.6, 2)
End If
K = K + 1
Loop
Next
K = 4
Do While ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value <> ""
If ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value = "Barber, David J" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(K, x).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(3, x).Value * 0.052, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value = "Carter, Timothy J" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(K, x).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(3, x).Value * 0.078, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value = "Friedline, Kyle" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(K, x).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(3, x).Value * 0.008, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value = "Houston, Audra" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(K, x).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(3, x).Value * 0.008, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(K, 1).Value = "Hull, Curtis R" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(K, x).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(3, x).Value * 0.004, 2)
End If
K = K + 1
Loop
For y = 0 To UBound(Costs)
Costs(y) = 0
Names(y) = ""
Next
Next
End Sub
Sub TimBonuses()
Dim Names() As String: Names = BuildNamesReturned()
Dim Wages() As Double: ReDim Wages(UBound(Names))
Dim Hours() As Double: ReDim Hours(UBound(Names))
Dim Jobs() As String
Dim x As Integer
Dim y As Integer
Dim z As Long
Dim i As Long
Dim j As Integer
Dim BeginDate As String
Dim EndDate As String
Dim TotalBonus As Double: TotalBonus = ActiveWorkbook.Worksheets("Bonuses").Cells(3, 2).Value
Dim TotalCost As Double
Call ValidateJobs
For x = 2 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Columns.Count
Jobs = Split(ActiveWorkbook.Worksheets("Bonuses").Cells(1, x).Value, "||")
For y = 0 To UBound(Jobs)
BeginDate = ""
EndDate = ""
If InStr(Jobs(y), "(") > 0 Then
TempString = Split(Jobs(y), "(")(1)
TempString = Split(TempString, ")")(0)
BeginDate = Split(TempString, "|")(0)
EndDate = Split(TempString, "|")(1)
Jobs(y) = Split(Jobs(y), "(")(0)
End If
For z = 1 To ActiveWorkbook.Worksheets("MetadataDB").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("MetadataDB").Cells(z, 1).Value = Jobs(y) Then
For i = ActiveWorkbook.Worksheets("MetadataDB").Cells(z, 2).Value To ActiveWorkbook.Worksheets("MetadataDB").Cells(z, 3).Value
If ActiveWorkbook.Worksheets("HoursDB").Cells(i, 8).Value = Jobs(y) Then
For j = 0 To UBound(Names)
If StrComp(Names(j), ActiveWorkbook.Worksheets("HoursDB").Cells(i, 1).Value, vbTextCompare) = 0 Then
If BeginDate <> "" Then
If DateCompare2(ActiveWorkbook.Worksheets("HoursDB").Cells(i, 5).Value, BeginDate) Then
Exit For
End If
End If
If EndDate <> "" Then
If DateCompare2(EndDate, ActiveWorkbook.Worksheets("HoursDB").Cells(i, 5).Value) Then
Exit For
End If
End If
Wages(j) = Wages(j) + DetermineWage(Names(j), ActiveWorkbook.Worksheets("HoursDB").Cells(i, 5).Value) * ActiveWorkbook.Worksheets("HoursDB").Cells(i, 3).Value * OvertimeModifier(ActiveWorkbook.Worksheets("HoursDB").Cells(i, 4).Value)
Hours(j) = Hours(j) + ActiveWorkbook.Worksheets("HoursDB").Cells(i, 3).Value
End If
Next
End If
Next
Exit For
End If
Next
Next
Next
Call BuildNames
For x = 0 To UBound(Names)
For y = 4 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Bonuses").Cells(y, 1).Value = Names(x) Then
ActiveWorkbook.Worksheets("Bonuses").Cells(y, 3).Value = Wages(x)
ActiveWorkbook.Worksheets("Bonuses").Cells(y, 4).Value = Hours(x)
TotalCost = TotalCost + Wages(x)
End If
Next
Next
For x = 4 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Barber, David J" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.052)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Carter, Timothy J" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.078)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Friedline, Kyle" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.008)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Houston, Audra" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.008)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Hull, Curtis R" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.004)
Else
For y = 0 To UBound(Names)
If Names(y) = ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round((Wages(y) / TotalCost) * 0.6 * TotalBonus)
If ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value > 0 Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value, 2)
End If
End If
Next
End If
Next
End Sub
Public Sub TimeRangeBonus(Start As String, Ending As String)
Dim Names() As String: Names = BuildNamesReturned()
Dim Wages() As Double: ReDim Wages(UBound(Names))
Dim Hours() As Double: ReDim Hours(UBound(Names))
Dim x As Long
Dim y As Integer
Dim TotalBonus As Double: TotalBonus = ActiveWorkbook.Worksheets("Bonuses").Cells(3, 2).Value
Dim SpecialNames() As String: SpecialNames = Split("Barber, David J|Carter, Timothy J|Friedline, Kyle|Houston, Audra|Hull, Curtis R", "|")
For x = BinDateSearch(Start, "HoursDB", 5, False) To BinDateSearch(Ending, "HoursDB", 5, True)
For y = 0 To UBound(Names)
If StrComp(ActiveWorkbook.Worksheets("HoursDB").Cells(x, 1).Value, Names(y), vbTextCompare) = 0 Then
Hours(y) = Hours(y) + ActiveWorkbook.Worksheets("HoursDB").Cells(x, 3).Value
Wages(y) = Wages(y) + DetermineWage(Names(y), ActiveWorkbook.Worksheets("HoursDB").Cells(x, 5).Value) * ActiveWorkbook.Worksheets("HoursDB").Cells(x, 3).Value * OvertimeModifier(ActiveWorkbook.Worksheets("HoursDB").Cells(x, 4).Value)
Exit For
End If
Next
Next
Call BuildNames
For x = 0 To UBound(Names)
For y = 4 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Bonuses").Cells(y, 1).Value = Names(x) Then
ActiveWorkbook.Worksheets("Bonuses").Cells(y, 3).Value = Wages(x)
ActiveWorkbook.Worksheets("Bonuses").Cells(y, 4).Value = Hours(x)
If IsNotIn(Names(x), SpecialNames, UBound(SpecialNames)) Then
TotalCost = TotalCost + Wages(x)
End If
End If
Next
Next
For x = 4 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Barber, David J" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.052)
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Carter, Timothy J" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.078)
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / 585, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Friedline, Kyle" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.008)
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Houston, Audra" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.008)
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value, 2)
ElseIf ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value = "Hull, Curtis R" Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round(TotalBonus * 0.004)
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value, 2)
Else
For y = 0 To UBound(Names)
If Names(y) = ActiveWorkbook.Worksheets("Bonuses").Cells(x, 1).Value Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value = Round((Wages(y) / TotalCost) * 0.6 * TotalBonus)
If ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value > 0 Then
ActiveWorkbook.Worksheets("Bonuses").Cells(x, 5).Value = Round(ActiveWorkbook.Worksheets("Bonuses").Cells(x, 2).Value / ActiveWorkbook.Worksheets("Bonuses").Cells(x, 4).Value, 2)
End If
End If
Next
End If
Next
End Sub
Public Sub Wrapper()
Call TimeRangeBonus("7-1-17", "9-30-17")
End Sub
Public Function BuildNamesReturned() As String()
Dim x As Integer
Dim Returned() As String: ReDim Returned(50)
Dim ReturnedPointer As Integer: ReturnedPointer = 0
For x = 2 To ActiveWorkbook.Worksheets("Employees").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Employees").Cells(x, 3).Value = 1 Then
If ReturnedPointer = UBound(Returned) Then
ReDim Preserve Returned(ReturnedPointer * 2)
End If
Returned(ReturnedPointer) = ActiveWorkbook.Worksheets("Employees").Cells(x, 5).Value
ReturnedPointer = ReturnedPointer + 1
End If
Next
ReDim Preserve Returned(ReturnedPointer - 1)
BuildNamesReturned = Returned
End Function
Sub BuildNames()
Dim CurentIndex As Integer: CurentIndex = 4
Dim Found As Boolean: Found = True
For x = 2 To ActiveWorkbook.Worksheets("Employees").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("Employees").Cells(x, 3).Value = 1 Then
If StrComp(ActiveWorkbook.Worksheets("Employees").Cells(x, 5), "Carter, Timothy J", vbTextCompare) = 1 And Found Then
ActiveWorkbook.Worksheets("Bonuses").Cells(CurentIndex, 1).Value = "Carter, Timothy J"
CurentIndex = CurentIndex + 1
Found = False
End If
ActiveWorkbook.Worksheets("Bonuses").Cells(CurentIndex, 1).Value = ActiveWorkbook.Worksheets("Employees").Cells(x, 5).Value
CurentIndex = CurentIndex + 1
End If
Next
End Sub
Sub ValidateJobs()
Dim x As Integer
Dim y As Integer
Dim Found As Boolean: Found = False
Dim jobname() As String
For x = 2 To ActiveWorkbook.Worksheets("Bonuses").UsedRange.Columns.Count
If ActiveWorkbook.Worksheets("Bonuses").Cells(1, x).Value = "" Then
Exit For
End If
For y = 2 To ActiveWorkbook.Worksheets("MetadataDB").UsedRange.Rows.Count
If ActiveWorkbook.Worksheets("MetadataDB").Cells(y, 1).Value = "" Then
Exit For
End If
jobname = Split(ActiveWorkbook.Worksheets("MetadataDB").Cells(y, 1).Value, ":")
If StrComp(jobname(UBound(jobname)), ActiveWorkbook.Worksheets("Bonuses").Cells(1, x).Value, vbTextCompare) = 0 Then
If Found Then
MsgBox ActiveWorkbook.Worksheets("Bonuses").Cells(1, x).Value
Else
Found = True
End If
End If
Next
Found = False
Next
End Sub