Skip to content

Commit

Permalink
Fix weekly goal calc if in last week of the year
Browse files Browse the repository at this point in the history
If the week in case is the last week of the year,
this method would fail because weeksTillEndOfJourneyPeriod
is 0, causing a division by 0 exception

Fixes #432
  • Loading branch information
anarute committed Oct 1, 2021
1 parent 1d44dca commit be434b7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions model/facade/action/GetPersonalSummaryByLoginDateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ protected function doExecute() {
}
$totalResults = $dao->getPersonalSummary($user->getId(), $this->date);

$totalResults['weekly_goal'] = 0;
if( $this->currentJourney ) {
$extraGoalHoursSet = 0;
$weeksTillEndOfJourneyPeriod = $this->getWeeksTillEndOfJourneyPeriod();
$extraGoalHoursSet += $this->currentUserGoal->getExtraHours() / $weeksTillEndOfJourneyPeriod;

$originalHoursToBeWorked = ($this->getWorkableHoursInThisPeriod() - $this->getWorkedHoursInThisPeriod())/ $weeksTillEndOfJourneyPeriod;
$totalResults['weekly_goal'] = round( ( $originalHoursToBeWorked + $extraGoalHoursSet ) * 60);
} else {
$totalResults['weekly_goal'] = 0;
if ($weeksTillEndOfJourneyPeriod > 0) {
$extraGoalHoursSet += $this->currentUserGoal->getExtraHours() / $weeksTillEndOfJourneyPeriod;
$originalHoursToBeWorked = ($this->getWorkableHoursInThisPeriod() - $this->getWorkedHoursInThisPeriod())/ $weeksTillEndOfJourneyPeriod;
$totalResults['weekly_goal'] = round( ( $originalHoursToBeWorked + $extraGoalHoursSet ) * 60);
}
}
return $totalResults;

Expand Down

0 comments on commit be434b7

Please sign in to comment.