From ec612d1046d51ae8ffc15bec6022ad83fca7e045 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Wed, 19 Aug 2020 10:08:25 +0200 Subject: [PATCH] fix duration calculation for multiple entries of same activity --- src/Repository/TimesheetRepository.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Repository/TimesheetRepository.php b/src/Repository/TimesheetRepository.php index 00f762f5..2518053f 100644 --- a/src/Repository/TimesheetRepository.php +++ b/src/Repository/TimesheetRepository.php @@ -416,7 +416,7 @@ class TimesheetRepository extends EntityRepository $newDateBegin = clone $endTmp; } - // make sure to exclude entries that are outside the requested timerange: + // make sure to exclude entries that are outside the requested time-range: // these entries can exist if you have long running entries that started before $begin // for statistical reasons we have to include everything between $begin and $end while // excluding everything that is outside of that range @@ -449,6 +449,7 @@ class TimesheetRepository extends EntityRepository . '_' . $result->getProject()->getId() . '_' . $result->getActivity()->getId() ; + if (!isset($results[$dateKey]['details'][$detailsId])) { $results[$dateKey]['details'][$detailsId] = [ 'project' => $result->getProject(), @@ -456,10 +457,10 @@ class TimesheetRepository extends EntityRepository 'duration' => 0, 'rate' => 0, ]; - - $results[$dateKey]['details'][$detailsId]['duration'] += $duration; - $results[$dateKey]['details'][$detailsId]['rate'] += $rate; } + + $results[$dateKey]['details'][$detailsId]['duration'] += $duration; + $results[$dateKey]['details'][$detailsId]['rate'] += $rate; } $beginTmp = $newDateBegin;