Skip to content

Commit 7e04285

Browse files
authored
Merge pull request #2584 from objectcomputing/feature-2583/add-fields-to-hours-upload-services
Feature 2583/add fields to hours upload services
2 parents 614e704 + ba18f8e commit 7e04285

File tree

8 files changed

+87
-25
lines changed

8 files changed

+87
-25
lines changed

server/src/main/java/com/objectcomputing/checkins/services/employee_hours/EmployeeHours.java

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.objectcomputing.checkins.services.employee_hours;
22

33
import com.objectcomputing.checkins.converter.LocalDateConverter;
4+
import com.objectcomputing.checkins.util.Util;
45
import io.micronaut.core.annotation.Introspected;
6+
import io.micronaut.core.annotation.Nullable;
57
import io.micronaut.data.annotation.AutoPopulated;
68
import io.micronaut.data.annotation.TypeDef;
79
import io.micronaut.data.model.DataType;
@@ -74,7 +76,19 @@ public class EmployeeHours {
7476
@TypeDef(type = DataType.DATE, converter = LocalDateConverter.class)
7577
private LocalDate asOfDate;
7678

77-
public EmployeeHours(UUID id, @NotNull String employeeId, @NotNull Float contributionHours, Float billableHours, Float ptoHours, LocalDate updatedDate, Float targetHours, LocalDate asOfDate) {
79+
@Column(name="billable_utilization")
80+
@TypeDef(type = DataType.FLOAT)
81+
@Schema(description ="Billable utilization hours")
82+
@Nullable
83+
private Float billableUtilization;
84+
85+
@Column(name="overtime_worked")
86+
@TypeDef(type = DataType.FLOAT)
87+
@Schema(description ="Number of hours of overtime worked")
88+
@Nullable
89+
private Float overtimeWorked;
90+
91+
public EmployeeHours(UUID id, @NotNull String employeeId, @NotNull Float contributionHours, Float billableHours, Float ptoHours, LocalDate updatedDate, Float targetHours, LocalDate asOfDate, @Nullable Float billableUtilization, @Nullable Float overtimeWorked) {
7892
this.id = id;
7993
this.employeeId = employeeId;
8094
this.contributionHours = contributionHours;
@@ -83,10 +97,12 @@ public EmployeeHours(UUID id, @NotNull String employeeId, @NotNull Float contrib
8397
this.updatedDate = updatedDate;
8498
this.targetHours = targetHours;
8599
this.asOfDate = asOfDate;
100+
this.billableUtilization = billableUtilization;
101+
this.overtimeWorked = overtimeWorked;
86102
}
87103

88-
public EmployeeHours(@NotNull String employeeId, @NotNull Float contributionHours, @NotNull Float billableHours, @NotNull Float ptoHours, LocalDate updatedDate, @NotNull Float targetHours, LocalDate asOfDate) {
89-
this(null, employeeId, contributionHours, billableHours, ptoHours, updatedDate, targetHours, asOfDate);
104+
public EmployeeHours(@NotNull String employeeId, @NotNull Float contributionHours, @NotNull Float billableHours, @NotNull Float ptoHours, LocalDate updatedDate, @NotNull Float targetHours, LocalDate asOfDate, @Nullable Float billableUtilization, @Nullable Float overtimeWorked) {
105+
this(null, employeeId, contributionHours, billableHours, ptoHours, updatedDate, targetHours, asOfDate, billableUtilization, overtimeWorked);
90106
}
91107

92108
@Override
@@ -101,12 +117,15 @@ public boolean equals(Object o) {
101117
employeeId.equals(that.employeeId) &&
102118
updatedDate.equals(that.updatedDate) &&
103119
Float.compare(that.targetHours, targetHours) == 0 &&
104-
asOfDate.equals(that.asOfDate) ;
120+
asOfDate.equals(that.asOfDate) &&
121+
Util.floatCompareNullSafeAndEqualWhenBothNull(that.billableUtilization, this.billableUtilization) == 0 &&
122+
Util.floatCompareNullSafeAndEqualWhenBothNull(that.overtimeWorked, this.overtimeWorked) == 0
123+
;
105124
}
106125

107126
@Override
108127
public int hashCode() {
109-
return Objects.hash(id, employeeId, contributionHours, billableHours, ptoHours, updatedDate,targetHours, asOfDate);
128+
return Objects.hash(id, employeeId, contributionHours, billableHours, ptoHours, updatedDate,targetHours, asOfDate, billableUtilization, overtimeWorked);
110129
}
111130

112131
@Override
@@ -120,6 +139,8 @@ public String toString() {
120139
", updatedDate=" + updatedDate +
121140
", targetHours=" + targetHours +
122141
", asOfDate=" + asOfDate +
142+
", billableUtilization=" + this.billableUtilization +
143+
", overtimeWorked=" + this.overtimeWorked +
123144
'}';
124145
}
125146
}

server/src/main/java/com/objectcomputing/checkins/services/employee_hours/EmployeeHoursCSVHelper.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,22 @@ public static List<EmployeeHours> employeeHrsCsv(InputStream inputStream) throws
3131
.parse(input);
3232
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy");
3333
for (CSVRecord csvRecord : csvParser) {
34-
EmployeeHours employeeHours = new EmployeeHours(csvRecord.get("employeeId"),
35-
Float.parseFloat(csvRecord.get("contributionHours")),
36-
Float.parseFloat(csvRecord.get("billableHours")),
37-
Float.parseFloat(csvRecord.get("ptoHours")), LocalDate.now(), Float.parseFloat(csvRecord.get("targetHours")),
38-
LocalDate.parse(csvRecord.get("asOfDate"), formatter));
34+
String billableUtilizationString = csvRecord.get("billableUtilization");
35+
Float billableUtilization = (billableUtilizationString == null) ? null : Float.parseFloat(billableUtilizationString);
36+
String overtimeWorkedString = csvRecord.get("overtimeWorked");
37+
Float overtimeWorked = (overtimeWorkedString == null) ? null : Float.parseFloat(overtimeWorkedString);
38+
EmployeeHours employeeHours = new EmployeeHours
39+
(
40+
csvRecord.get("employeeId"),
41+
Float.parseFloat(csvRecord.get("contributionHours")),
42+
Float.parseFloat(csvRecord.get("billableHours")),
43+
Float.parseFloat(csvRecord.get("ptoHours")),
44+
LocalDate.now(),
45+
Float.parseFloat(csvRecord.get("targetHours")),
46+
LocalDate.parse(csvRecord.get("asOfDate"), formatter),
47+
billableUtilization,
48+
overtimeWorked
49+
);
3950
employeeHoursList.add(employeeHours);
4051
}
4152
return employeeHoursList;

server/src/main/java/com/objectcomputing/checkins/util/Util.java

+7
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,11 @@ public static List<String> nullSafeUUIDListToStringList(List<UUID> uuidList) {
3131
}
3232
return stringsList;
3333
}
34+
35+
public static int floatCompareNullSafeAndEqualWhenBothNull(Float f1, Float f2) {
36+
if (f1 == null && f2 == null) return 0;
37+
if (f1 == null || f2 == null) return 1;
38+
return Float.compare(f1, f2);
39+
}
40+
3441
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE employee_hours ADD column billable_utilization decimal;
2+
ALTER TABLE employee_hours ADD column overtime_worked decimal;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
employeeId,contributionHours,billableHours,ptoHours,targetHours,asOfDate
2-
mr-bill-employee,12,123,1234,1850,"8/20/2021"
3-
mr-bill-employee-pdl,13,124,1235,0,"8/20/2021"
1+
employeeId,contributionHours,billableHours,ptoHours,targetHours,asOfDate,billableUtilization,overtimeWorked
2+
mr-bill-employee,12,123,1234,1850,"8/20/2021",0,50
3+
mr-bill-employee-pdl,13,124,1235,0,"8/20/2021",,

web-ui/src/components/contribution_hours/ProgressBar.jsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ const propTypes = {
3131
* The value of the progress indicator for the determinate and buffer variants.
3232
* Value between 0 and 100.
3333
*/
34-
billableHours: PropTypes.number,
35-
contributionHours: PropTypes.number.isRequired,
36-
targetHours: PropTypes.number.isRequired,
37-
ptoHours: PropTypes.number
34+
billableHours: PropTypes.number,
35+
contributionHours: PropTypes.number.isRequired,
36+
targetHours: PropTypes.number.isRequired,
37+
ptoHours: PropTypes.number,
38+
billableUtilization: PropTypes.number,
39+
overtimeWorked: PropTypes.number,
3840
};
3941

4042
const LinearBuffer = ({
41-
billableHours,
42-
contributionHours = 925,
43-
targetHours = 1850,
44-
ptoHours = 0
43+
billableHours,
44+
contributionHours = 925,
45+
targetHours = 1850,
46+
ptoHours = 0,
47+
billableUtilization,
48+
overtimeWorked,
4549
}) => {
4650
return (
4751
<Root className={classes.root}>
@@ -63,8 +67,7 @@ const LinearBuffer = ({
6367
style={{ display: 'block' }}
6468
>
6569
Billable Hours: {billableHours} - Contribution Hours:{' '}
66-
{contributionHours} - Target Hours: {targetHours} - PTO Hours:{' '}
67-
{ptoHours}
70+
{contributionHours} - Target Hours: {targetHours} - PTO Hours:{' '} {ptoHours} - Billable Utilization:{' '} {(billableUtilization) ? billableUtilization : '(none)'} - Overtime Worked:{' '} {(overtimeWorked) ? overtimeWorked : '(none)'}
6871
</Typography>
6972
</Root>
7073
);

web-ui/src/components/contribution_hours/ProgressBar.test.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import ProgressBar from './ProgressBar';
33
import renderer from 'react-test-renderer';
44

55
it('has billable hours', () => {
6-
snapshot(<ProgressBar props={(1200, 1500, 1850)} />);
6+
snapshot(<ProgressBar props={(1200, 1500, 1850, 0, 0, 0)} />);
77
});
88

99
it('has no billable hours', () => {
10-
snapshot(<ProgressBar props={(0, 1500, 1850)} />);
10+
snapshot(<ProgressBar props={(0, 1500, 1850, 0, 0, 0)} />);
1111
});

web-ui/src/components/contribution_hours/__snapshots__/ProgressBar.test.jsx.snap

+18
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ exports[`has billable hours 1`] = `
3737
1850
3838
- PTO Hours:
3939
40+
4041
0
42+
- Billable Utilization:
43+
44+
45+
(none)
46+
- Overtime Worked:
47+
48+
49+
(none)
4150
</p>
4251
</div>
4352
</div>
@@ -80,7 +89,16 @@ exports[`has no billable hours 1`] = `
8089
1850
8190
- PTO Hours:
8291
92+
8393
0
94+
- Billable Utilization:
95+
96+
97+
(none)
98+
- Overtime Worked:
99+
100+
101+
(none)
84102
</p>
85103
</div>
86104
</div>

0 commit comments

Comments
 (0)