Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATLDEV-331 fix subtraced hours #75

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ public Response updateTotalTargetHours(@Context HttpServletRequest request, @Pat
return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
}

Response response = permissionService.checkUserPermission();
Response response = permissionService.checkRootPermission();
if (response != null)
return response;

Expand All @@ -1201,6 +1201,36 @@ public Response updateTotalTargetHours(@Context HttpServletRequest request, @Pat
}
}

@POST
@Path("updateSubtractedHours/{hours}")
public Response updateSubtractedHours(@Context HttpServletRequest request, @PathParam("hours") int hours){
ApplicationUser user;

try {
user = permissionService.checkIfUserExists();
} catch (PermissionException e) {
return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
}

Response response = permissionService.checkRootPermission();
if (response != null)
return response;

try{
Timesheet sheet = sheetService.getTimesheetByUser(user.getKey());

if(sheet != null) {
sheet.setHoursDeducted(hours);
sheet.save();
}

return Response.ok(new JsonTimesheet(sheet)).build();
}
catch (ServiceException e){
return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
}
}

@DELETE
@Path("deleteLecture")
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class JsonTimesheet {
@JsonDeserialize(using = DateAndTimeDeserialize.class)
private Date latestEntryDate;
@XmlElement
private int targetHourPractice;
private int targetHoursRemaining;
@XmlElement
private int targetHours;
@XmlElement
Expand All @@ -71,16 +71,18 @@ public final class JsonTimesheet {
public JsonTimesheet(Timesheet timesheet) {
this.timesheetID = timesheet.getID();
this.userKey = timesheet.getUserKey();
this.lectures = timesheet.getLectures();
this.reason = timesheet.getReason();
this.latestEntryDate = timesheet.getLatestEntryBeginDate();
this.targetHourPractice = timesheet.getHoursCompleted();
this.displayName = timesheet.getDisplayName();
this.state = timesheet.getState();

this.targetHours = timesheet.getTargetHours();
this.targetHoursCompleted = timesheet.getHoursCompleted();
this.lectures = timesheet.getLectures();
this.targetHoursRemoved = timesheet.getHoursDeducted();
this.state = timesheet.getState();
this.displayName = timesheet.getDisplayName();
this.reason = timesheet.getReason();

this.targetHoursCompleted = timesheet.getHoursCompleted() - this.targetHoursRemoved;
this.targetHoursRemaining = this.targetHours - this.targetHoursCompleted;

this.latestEntryDate = timesheet.getLatestEntryBeginDate();
if (timesheet.firstEntry() != null) {
this.firstEntryDate = timesheet.firstEntry().getBeginDate();
}
Expand Down Expand Up @@ -133,12 +135,12 @@ public void setLatestEntryDate(Date latestEntryDate) {
this.latestEntryDate = latestEntryDate;
}

public int getTargetHourPractice() {
return targetHourPractice;
public int getTargetHoursRemaining() {
return targetHoursRemaining;
}

public void setTargetHourPractice(int targetHourPractice) {
this.targetHourPractice = targetHourPractice;
public void setTargetHoursRemaining(int targetHoursRemaining) {
this.targetHoursRemaining = targetHoursRemaining;
}


Expand Down Expand Up @@ -203,7 +205,7 @@ public boolean equals(Object o) {
if (latestEntryDate != that.latestEntryDate) {
return false;
}
if (targetHourPractice != that.targetHourPractice) {
if (targetHoursRemaining != that.targetHoursRemaining) {
return false;
}
if (targetHours != that.targetHours) {
Expand Down Expand Up @@ -231,7 +233,7 @@ public int hashCode() {
result = 31 * result + lectures.hashCode();
result = 31 * result + reason.hashCode();
//result = 31 * result + latestEntryDate.hashCode();
result = 31 * result + targetHourPractice;
result = 31 * result + targetHoursRemaining;
result = 31 * result + targetHours;
result = 31 * result + targetHoursCompleted;
result = 31 * result + targetHoursRemoved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ public JsonUserInformation (Timesheet timesheet) {
this.state = timesheet.getState();
this.latestEntryDate = timesheet.getLatestEntryBeginDate();

this.remainingHours = (timesheet.getTargetHours() - timesheet.getHoursCompleted()
+ timesheet.getHoursDeducted());
this.targetTotalHours = timesheet.getTargetHours();
this.totalHours = timesheet.getHoursCompleted() - timesheet.getHoursDeducted();
this.remainingHours = this.targetTotalHours - this.totalHours;

this.totalHours = timesheet.getHoursCompleted();
this.email = ComponentAccessor.getUserManager().getUserByKey(timesheet.getUserKey()).getEmailAddress();
this.timesheetID = timesheet.getID();

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/css/timesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,14 @@ code {
color: forestgreen;
margin-left: 6px;
}

#edit-subtracted-hours{
cursor: pointer;
margin-left: 6px;
}

#submit-subtracted-hours{
cursor: pointer;
color: forestgreen;
margin-left: 6px;
}
15 changes: 8 additions & 7 deletions src/main/resources/js/timesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ AJS.toInit(function () {
timesheetID: existingTimesheetData.timesheetID,
lectures: lectures,
reason: AJS.$("#timesheet-substract-hours-text").val(),
targetHourPractice: toFixed(AJS.$("#timesheet-hours-practical").val(), 2),
targetHours: AJS.$("#timesheet-hours-text").val(),
targetHoursCompleted: toFixed(AJS.$("#timesheet-hours-practical").val() - AJS.$("#timesheet-hours-substract").val(), 2),
targetHourPractice: toFixed(AJS.$("#timesheet-finished-hours").val(), 2),
targetHours: AJS.$("#timesheet-target-hours").val(),
targetHoursCompleted: toFixed(AJS.$("#timesheet-finished-hours").val() - AJS.$("#timesheet-hours-substract").val(), 2),
targetHoursRemoved: toFixed(AJS.$("#timesheet-hours-substract").val(), 2),
firstEntryDate: existingTimesheetData.firstEntryDate,
latestEntryDate: existingTimesheetData.latestEntryDate,
state: existingTimesheetData.state
state: existingTimesheetData.state,
targetHoursRemaining: existingTimesheetData.targetHoursRemaining
};

var timesheetUpdated = AJS.$.ajax({
Expand Down Expand Up @@ -235,7 +236,7 @@ function projectedFinishDate(timesheetData, entryData) {
var entries = entryData[0];
var rem = timesheet.targetHours - timesheet.targetHoursCompleted + timesheet.targetHoursRemoved;
if (rem <= 0) {
AJS.$("#timesheet-finish-date").val(new Date().toLocaleDateString("en-US"));
AJS.$("#timesheet-projected-finish").val(new Date().toLocaleDateString("en-US"));
return;
// already finished...
}
Expand All @@ -249,14 +250,14 @@ function projectedFinishDate(timesheetData, entryData) {
}
}
if(sumLast30Days === 0) {
AJS.$("#timesheet-finish-date").val("Not enough entries to compute");
AJS.$("#timesheet-projected-finish").val("Not enough entries to compute");
return;
}
var hoursLast30Days = sumLast30Days / (1000 * 60 * 60);
var remDays = rem * 30 / hoursLast30Days;
var finishDate = new Date();
finishDate.setDate(finishDate.getDate() + remDays);
AJS.$("#timesheet-finish-date").val(finishDate.toLocaleDateString("en-US"));
AJS.$("#timesheet-projected-finish").val(finishDate.toLocaleDateString("en-US"));
}

function setOwnerLabel(timesheet) {
Expand Down
Loading