added project filter in user-list reports (#4615)

This commit is contained in:
Kevin Papst
2024-02-07 18:00:29 +01:00
committed by GitHub
parent e98732f44a
commit 7abe787778
13 changed files with 139 additions and 60 deletions

View File

@@ -12,8 +12,8 @@ namespace App\Timesheet;
use App\Entity\User;
use App\Model\DailyStatistic;
use App\Model\MonthlyStatistic;
use App\Repository\Query\TimesheetStatisticQuery;
use App\Repository\TimesheetRepository;
use DateTime;
use DateTimeInterface;
final class TimesheetStatisticService
@@ -23,13 +23,15 @@ final class TimesheetStatisticService
}
/**
* @param DateTimeInterface $begin
* @param DateTimeInterface $end
* @param User[] $users
* @return DailyStatistic[]
*/
public function getDailyStatistics(DateTimeInterface $begin, DateTimeInterface $end, array $users): array
public function getDailyStatistics(TimesheetStatisticQuery $query): array
{
$begin = $query->getBegin();
$end = $query->getEnd();
$users = $query->getUsers();
$project = $query->getProject();
/** @var DailyStatistic[] $stats */
$stats = [];
@@ -63,6 +65,13 @@ final class TimesheetStatisticService
->addGroupBy('billable')
;
if ($project !== null) {
$qb
->andWhere($qb->expr()->eq('t.project', ':project'))
->setParameter('project', $project)
;
}
$results = $qb->getQuery()->getResult();
foreach ($results as $row) {
@@ -241,7 +250,7 @@ final class TimesheetStatisticService
return $stats;
}
public function findFirstRecordDate(User $user): ?DateTime
public function findFirstRecordDate(User $user): ?\DateTimeImmutable
{
$result = $this->repository->createQueryBuilder('t')
->select('MIN(t.begin)')
@@ -254,19 +263,19 @@ final class TimesheetStatisticService
return null;
}
return new DateTime((string) $result, new \DateTimeZone($user->getTimezone()));
return new \DateTimeImmutable((string) $result, new \DateTimeZone($user->getTimezone()));
}
/**
* Returns an array of Year statistics.
*
* @param DateTime $begin
* @param DateTime $end
* @param User[] $users
* @return MonthlyStatistic[]
*/
public function getMonthlyStats(DateTime $begin, DateTime $end, array $users): array
public function getMonthlyStats(TimesheetStatisticQuery $query): array
{
$begin = $query->getBegin();
$end = $query->getEnd();
$users = $query->getUsers();
$project = $query->getProject();
/** @var MonthlyStatistic[] $stats */
$stats = [];
@@ -297,6 +306,13 @@ final class TimesheetStatisticService
->addGroupBy('billable')
;
if ($project !== null) {
$qb
->andWhere($qb->expr()->eq('t.project', ':project'))
->setParameter('project', $project)
;
}
$results = $qb->getQuery()->getResult();
foreach ($results as $row) {