Skip to content

Commit be434b7

Browse files
committed
Fix weekly goal calc if in last week of the year
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
1 parent 1d44dca commit be434b7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

model/facade/action/GetPersonalSummaryByLoginDateAction.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ protected function doExecute() {
195195
}
196196
$totalResults = $dao->getPersonalSummary($user->getId(), $this->date);
197197

198+
$totalResults['weekly_goal'] = 0;
198199
if( $this->currentJourney ) {
199200
$extraGoalHoursSet = 0;
200201
$weeksTillEndOfJourneyPeriod = $this->getWeeksTillEndOfJourneyPeriod();
201-
$extraGoalHoursSet += $this->currentUserGoal->getExtraHours() / $weeksTillEndOfJourneyPeriod;
202-
203-
$originalHoursToBeWorked = ($this->getWorkableHoursInThisPeriod() - $this->getWorkedHoursInThisPeriod())/ $weeksTillEndOfJourneyPeriod;
204-
$totalResults['weekly_goal'] = round( ( $originalHoursToBeWorked + $extraGoalHoursSet ) * 60);
205-
} else {
206-
$totalResults['weekly_goal'] = 0;
202+
if ($weeksTillEndOfJourneyPeriod > 0) {
203+
$extraGoalHoursSet += $this->currentUserGoal->getExtraHours() / $weeksTillEndOfJourneyPeriod;
204+
$originalHoursToBeWorked = ($this->getWorkableHoursInThisPeriod() - $this->getWorkedHoursInThisPeriod())/ $weeksTillEndOfJourneyPeriod;
205+
$totalResults['weekly_goal'] = round( ( $originalHoursToBeWorked + $extraGoalHoursSet ) * 60);
206+
}
207207
}
208208
return $totalResults;
209209

0 commit comments

Comments
 (0)