new user-year reporting and data-type chooser (#3155)
This commit is contained in:
121
src/Controller/Reporting/AbstractUserReportController.php
Normal file
121
src/Controller/Reporting/AbstractUserReportController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Reporting;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Entity\User;
|
||||
use App\Model\DailyStatistic;
|
||||
use App\Model\DateStatisticInterface;
|
||||
use App\Model\Statistic\StatisticDate;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Timesheet\TimesheetStatisticService;
|
||||
use DateTime;
|
||||
|
||||
abstract class AbstractUserReportController extends AbstractController
|
||||
{
|
||||
protected $statisticService;
|
||||
private $projectRepository;
|
||||
private $activityRepository;
|
||||
|
||||
public function __construct(TimesheetStatisticService $statisticService, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
|
||||
{
|
||||
$this->statisticService = $statisticService;
|
||||
$this->projectRepository = $projectRepository;
|
||||
$this->activityRepository = $activityRepository;
|
||||
}
|
||||
|
||||
protected function canSelectUser(): bool
|
||||
{
|
||||
// also found in App\EventSubscriber\Actions\UserSubscriber
|
||||
if (!$this->isGranted('view_other_timesheet') || !$this->isGranted('view_other_reporting')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getStatisticDataRaw(DateTime $begin, DateTime $end, User $user): array
|
||||
{
|
||||
return $this->statisticService->getDailyStatisticsGrouped($begin, $end, [$user]);
|
||||
}
|
||||
|
||||
protected function createStatisticModel(DateTime $begin, DateTime $end, User $user): DateStatisticInterface
|
||||
{
|
||||
return new DailyStatistic($begin, $end, $user);
|
||||
}
|
||||
|
||||
protected function prepareReport(DateTime $begin, DateTime $end, User $user): array
|
||||
{
|
||||
$data = $this->getStatisticDataRaw($begin, $end, $user);
|
||||
|
||||
$data = array_pop($data);
|
||||
$projectIds = [];
|
||||
$activityIds = [];
|
||||
|
||||
foreach ($data as $projectId => $projectValues) {
|
||||
$projectIds[$projectId] = $projectId;
|
||||
$dailyProjectStatistic = $this->createStatisticModel($begin, $end, $user);
|
||||
foreach ($projectValues['activities'] as $activityId => $activityValues) {
|
||||
$activityIds[$activityId] = $activityId;
|
||||
if (!isset($data[$projectId]['duration'])) {
|
||||
$data[$projectId]['duration'] = 0;
|
||||
}
|
||||
if (!isset($data[$projectId]['rate'])) {
|
||||
$data[$projectId]['rate'] = 0.0;
|
||||
}
|
||||
if (!isset($data[$projectId]['internalRate'])) {
|
||||
$data[$projectId]['internalRate'] = 0.0;
|
||||
}
|
||||
if (!isset($data[$projectId]['activities'][$activityId]['duration'])) {
|
||||
$data[$projectId]['activities'][$activityId]['duration'] = 0;
|
||||
}
|
||||
if (!isset($data[$projectId]['activities'][$activityId]['rate'])) {
|
||||
$data[$projectId]['activities'][$activityId]['rate'] = 0.0;
|
||||
}
|
||||
if (!isset($data[$projectId]['activities'][$activityId]['internalRate'])) {
|
||||
$data[$projectId]['activities'][$activityId]['internalRate'] = 0.0;
|
||||
}
|
||||
/** @var StatisticDate $date */
|
||||
foreach ($activityValues['data']->getData() as $date) {
|
||||
$statisticDate = $dailyProjectStatistic->getByDateTime($date->getDate());
|
||||
$statisticDate->setTotalDuration($statisticDate->getTotalDuration() + $date->getTotalDuration());
|
||||
$statisticDate->setTotalRate($statisticDate->getTotalRate() + $date->getTotalRate());
|
||||
$statisticDate->setTotalInternalRate($statisticDate->getTotalInternalRate() + $date->getTotalInternalRate());
|
||||
$data[$projectId]['duration'] = $data[$projectId]['duration'] + $date->getTotalDuration();
|
||||
$data[$projectId]['rate'] = $data[$projectId]['rate'] + $date->getTotalRate();
|
||||
$data[$projectId]['internalRate'] = $data[$projectId]['internalRate'] + $date->getTotalInternalRate();
|
||||
$data[$projectId]['activities'][$activityId]['duration'] = $data[$projectId]['activities'][$activityId]['duration'] + $date->getTotalDuration();
|
||||
$data[$projectId]['activities'][$activityId]['rate'] = $data[$projectId]['activities'][$activityId]['rate'] + $date->getTotalRate();
|
||||
$data[$projectId]['activities'][$activityId]['internalRate'] = $data[$projectId]['activities'][$activityId]['internalRate'] + $date->getTotalInternalRate();
|
||||
}
|
||||
}
|
||||
$data[$projectId]['data'] = $dailyProjectStatistic;
|
||||
}
|
||||
|
||||
$activities = $this->activityRepository->findByIds($activityIds);
|
||||
foreach ($activities as $activity) {
|
||||
$activityIds[$activity->getId()] = $activity;
|
||||
}
|
||||
|
||||
foreach ($data as $projectId => $projectValues) {
|
||||
foreach ($projectValues['activities'] as $activityId => $activityValues) {
|
||||
$data[$projectId]['activities'][$activityId]['activity'] = $activityIds[$activityId];
|
||||
}
|
||||
}
|
||||
|
||||
$projects = $this->projectRepository->findByIds($projectIds);
|
||||
foreach ($projects as $project) {
|
||||
$data[$project->getId()]['project'] = $project;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Reporting;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Entity\User;
|
||||
use App\Model\DailyStatistic;
|
||||
use App\Model\Statistic\StatisticDate;
|
||||
use App\Reporting\MonthByUser;
|
||||
use App\Reporting\MonthByUserForm;
|
||||
use App\Reporting\WeekByUser;
|
||||
use App\Reporting\WeekByUserForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Timesheet\TimesheetStatisticService;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting")
|
||||
* @Security("is_granted('view_reporting')")
|
||||
*/
|
||||
final class ReportByUserController extends AbstractController
|
||||
{
|
||||
private $statisticService;
|
||||
private $projectRepository;
|
||||
private $activityRepository;
|
||||
|
||||
public function __construct(TimesheetStatisticService $statisticService, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
|
||||
{
|
||||
$this->statisticService = $statisticService;
|
||||
$this->projectRepository = $projectRepository;
|
||||
$this->activityRepository = $activityRepository;
|
||||
}
|
||||
|
||||
private function canSelectUser(): bool
|
||||
{
|
||||
// also found in App\EventSubscriber\Actions\UserSubscriber
|
||||
if (!$this->isGranted('view_other_timesheet') || !$this->isGranted('view_other_reporting')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/month_by_user", name="report_user_month", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function monthByUser(Request $request): Response
|
||||
{
|
||||
$currentUser = $this->getUser();
|
||||
$dateTimeFactory = $this->getDateTimeFactory($currentUser);
|
||||
$canChangeUser = $this->canSelectUser();
|
||||
|
||||
$values = new MonthByUser();
|
||||
$values->setUser($currentUser);
|
||||
$values->setDate($dateTimeFactory->getStartOfMonth());
|
||||
|
||||
$form = $this->createForm(MonthByUserForm::class, $values, [
|
||||
'include_user' => $canChangeUser,
|
||||
'timezone' => $dateTimeFactory->getTimezone()->getName(),
|
||||
'start_date' => $values->getDate(),
|
||||
]);
|
||||
|
||||
$form->submit($request->query->all(), false);
|
||||
|
||||
if ($values->getUser() === null) {
|
||||
$values->setUser($currentUser);
|
||||
}
|
||||
|
||||
if ($currentUser !== $values->getUser() && !$canChangeUser) {
|
||||
throw new AccessDeniedException('User is not allowed to see other users timesheet');
|
||||
}
|
||||
|
||||
if ($values->getDate() === null) {
|
||||
$values->setDate($dateTimeFactory->getStartOfMonth());
|
||||
}
|
||||
|
||||
$start = $values->getDate();
|
||||
$start->modify('first day of 00:00:00');
|
||||
|
||||
$end = clone $start;
|
||||
$end->modify('last day of 23:59:59');
|
||||
|
||||
$selectedUser = $values->getUser();
|
||||
|
||||
$previousMonth = clone $start;
|
||||
$previousMonth->modify('-1 month');
|
||||
|
||||
$nextMonth = clone $start;
|
||||
$nextMonth->modify('+1 month');
|
||||
|
||||
$data = $this->prepareReport($start, $end, $selectedUser);
|
||||
|
||||
return $this->render('reporting/report_by_user.html.twig', [
|
||||
'report_title' => 'report_user_month',
|
||||
'box_id' => 'user-month-reporting-box',
|
||||
'form' => $form->createView(),
|
||||
'rows' => $data,
|
||||
'days' => new DailyStatistic($start, $end, $selectedUser),
|
||||
'user' => $selectedUser,
|
||||
'current' => $start,
|
||||
'next' => $nextMonth,
|
||||
'previous' => $previousMonth,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/week_by_user", name="report_user_week", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function weekByUser(Request $request): Response
|
||||
{
|
||||
$currentUser = $this->getUser();
|
||||
$dateTimeFactory = $this->getDateTimeFactory($currentUser);
|
||||
$canChangeUser = $this->canSelectUser();
|
||||
|
||||
$values = new WeekByUser();
|
||||
$values->setUser($currentUser);
|
||||
$values->setDate($dateTimeFactory->getStartOfWeek());
|
||||
|
||||
$form = $this->createForm(WeekByUserForm::class, $values, [
|
||||
'include_user' => $canChangeUser,
|
||||
'timezone' => $dateTimeFactory->getTimezone()->getName(),
|
||||
'start_date' => $values->getDate(),
|
||||
]);
|
||||
|
||||
$form->submit($request->query->all(), false);
|
||||
|
||||
if ($values->getUser() === null) {
|
||||
$values->setUser($currentUser);
|
||||
}
|
||||
|
||||
if ($currentUser !== $values->getUser() && !$canChangeUser) {
|
||||
throw new AccessDeniedException('User is not allowed to see other users timesheet');
|
||||
}
|
||||
|
||||
if ($values->getDate() === null) {
|
||||
$values->setDate($dateTimeFactory->getStartOfWeek());
|
||||
}
|
||||
|
||||
$start = $dateTimeFactory->getStartOfWeek($values->getDate());
|
||||
$end = $dateTimeFactory->getEndOfWeek($values->getDate());
|
||||
$selectedUser = $values->getUser();
|
||||
|
||||
$previous = clone $start;
|
||||
$previous->modify('-1 week');
|
||||
|
||||
$next = clone $start;
|
||||
$next->modify('+1 week');
|
||||
|
||||
$data = $this->prepareReport($start, $end, $selectedUser);
|
||||
|
||||
return $this->render('reporting/report_by_user.html.twig', [
|
||||
'report_title' => 'report_user_week',
|
||||
'box_id' => 'user-week-reporting-box',
|
||||
'form' => $form->createView(),
|
||||
'days' => new DailyStatistic($start, $end, $selectedUser),
|
||||
'rows' => $data,
|
||||
'user' => $selectedUser,
|
||||
'current' => $start,
|
||||
'next' => $next,
|
||||
'previous' => $previous,
|
||||
]);
|
||||
}
|
||||
|
||||
private function prepareReport(DateTime $begin, DateTime $end, User $user): array
|
||||
{
|
||||
$data = $this->statisticService->getDailyStatisticsGrouped($begin, $end, [$user]);
|
||||
|
||||
$data = array_pop($data);
|
||||
$projectIds = [];
|
||||
$activityIds = [];
|
||||
|
||||
foreach ($data as $projectId => $projectValues) {
|
||||
$projectIds[$projectId] = $projectId;
|
||||
$dailyProjectStatistic = new DailyStatistic($begin, $end, $user);
|
||||
foreach ($projectValues['activities'] as $activityId => $activityValues) {
|
||||
$activityIds[$activityId] = $activityId;
|
||||
if (!isset($data[$projectId]['duration'])) {
|
||||
$data[$projectId]['duration'] = 0;
|
||||
}
|
||||
if (!isset($data[$projectId]['rate'])) {
|
||||
$data[$projectId]['rate'] = 0.0;
|
||||
}
|
||||
if (!isset($data[$projectId]['activities'][$activityId]['duration'])) {
|
||||
$data[$projectId]['activities'][$activityId]['duration'] = 0;
|
||||
}
|
||||
if (!isset($data[$projectId]['activities'][$activityId]['rate'])) {
|
||||
$data[$projectId]['activities'][$activityId]['rate'] = 0.0;
|
||||
}
|
||||
/** @var StatisticDate $day */
|
||||
foreach ($activityValues['days']->getDays() as $day) {
|
||||
$statDay = $dailyProjectStatistic->getDayByDateTime($day->getDate());
|
||||
$statDay->setTotalDuration($statDay->getTotalDuration() + $day->getDuration());
|
||||
$statDay->setTotalRate($statDay->getTotalRate() + $day->getRate());
|
||||
$data[$projectId]['duration'] = $data[$projectId]['duration'] + $day->getDuration();
|
||||
$data[$projectId]['rate'] = $data[$projectId]['rate'] + $day->getRate();
|
||||
$data[$projectId]['activities'][$activityId]['duration'] = $data[$projectId]['activities'][$activityId]['duration'] + $day->getDuration();
|
||||
$data[$projectId]['activities'][$activityId]['rate'] = $data[$projectId]['activities'][$activityId]['rate'] + $day->getRate();
|
||||
}
|
||||
}
|
||||
$data[$projectId]['days'] = $dailyProjectStatistic;
|
||||
}
|
||||
|
||||
$activities = $this->activityRepository->findByIds($activityIds);
|
||||
foreach ($activities as $activity) {
|
||||
$activityIds[$activity->getId()] = $activity;
|
||||
}
|
||||
|
||||
foreach ($data as $projectId => $projectValues) {
|
||||
foreach ($projectValues['activities'] as $activityId => $activityValues) {
|
||||
$data[$projectId]['activities'][$activityId]['activity'] = $activityIds[$activityId];
|
||||
}
|
||||
}
|
||||
|
||||
$projects = $this->projectRepository->findByIds($projectIds);
|
||||
foreach ($projects as $project) {
|
||||
$data[$project->getId()]['project'] = $project;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,13 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting")
|
||||
* @Route(path="/reporting/users")
|
||||
* @Security("is_granted('view_reporting') and is_granted('view_other_reporting') and is_granted('view_other_timesheet')")
|
||||
*/
|
||||
final class ReportUsersMonthController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route(path="/monthly_users_list", name="report_monthly_users", methods={"GET","POST"})
|
||||
* @Route(path="/month", name="report_monthly_users", methods={"GET","POST"})
|
||||
*/
|
||||
public function report(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
|
||||
{
|
||||
@@ -42,7 +42,7 @@ final class ReportUsersMonthController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/export/monthly_users_list", name="report_monthly_users_export", methods={"GET","POST"})
|
||||
* @Route(path="/month_export", name="report_monthly_users_export", methods={"GET","POST"})
|
||||
*/
|
||||
public function export(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
|
||||
{
|
||||
@@ -53,7 +53,7 @@ final class ReportUsersMonthController extends AbstractController
|
||||
$reader = new Html();
|
||||
$spreadsheet = $reader->loadFromString($content);
|
||||
|
||||
$writer = new BinaryFileResponseWriter(new XlsxWriter(), 'kimai-export-users-weekly');
|
||||
$writer = new BinaryFileResponseWriter(new XlsxWriter(), 'kimai-export-users-monthly');
|
||||
|
||||
return $writer->getFileResponse($spreadsheet);
|
||||
}
|
||||
@@ -110,6 +110,8 @@ final class ReportUsersMonthController extends AbstractController
|
||||
}
|
||||
|
||||
return [
|
||||
'period_attribute' => 'days',
|
||||
'dataType' => $values->getSumType(),
|
||||
'report_title' => 'report_monthly_users',
|
||||
'box_id' => 'monthly-user-list-reporting-box',
|
||||
'export_route' => 'report_monthly_users_export',
|
||||
|
||||
@@ -25,13 +25,13 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting")
|
||||
* @Route(path="/reporting/users")
|
||||
* @Security("is_granted('view_reporting') and is_granted('view_other_reporting') and is_granted('view_other_timesheet')")
|
||||
*/
|
||||
final class ReportUsersWeekController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route(path="/weekly_users_list", name="report_weekly_users", methods={"GET","POST"})
|
||||
* @Route(path="/week", name="report_weekly_users", methods={"GET","POST"})
|
||||
*/
|
||||
public function report(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
|
||||
{
|
||||
@@ -42,7 +42,7 @@ final class ReportUsersWeekController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/export/weekly_users_list", name="report_weekly_users_export", methods={"GET","POST"})
|
||||
* @Route(path="/week_export", name="report_weekly_users_export", methods={"GET","POST"})
|
||||
*/
|
||||
public function export(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
|
||||
{
|
||||
@@ -107,6 +107,8 @@ final class ReportUsersWeekController extends AbstractController
|
||||
}
|
||||
|
||||
return [
|
||||
'period_attribute' => 'days',
|
||||
'dataType' => $values->getSumType(),
|
||||
'report_title' => 'report_weekly_users',
|
||||
'box_id' => 'weekly-user-list-reporting-box',
|
||||
'export_route' => 'report_weekly_users_export',
|
||||
|
||||
@@ -27,13 +27,13 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting")
|
||||
* @Route(path="/reporting/users")
|
||||
* @Security("is_granted('view_reporting') and is_granted('view_other_reporting') and is_granted('view_other_timesheet')")
|
||||
*/
|
||||
final class ReportUsersYearController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route(path="/yearly_users_list", name="report_yearly_users", methods={"GET","POST"})
|
||||
* @Route(path="/year", name="report_yearly_users", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
@@ -48,7 +48,7 @@ final class ReportUsersYearController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/export/yearly_users_list", name="report_yearly_users_export", methods={"GET","POST"})
|
||||
* @Route(path="/year_export", name="report_yearly_users_export", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
@@ -118,6 +118,9 @@ final class ReportUsersYearController extends AbstractController
|
||||
}
|
||||
|
||||
return [
|
||||
'query' => $values,
|
||||
'period_attribute' => 'months',
|
||||
'dataType' => $values->getSumType(),
|
||||
'report_title' => 'report_yearly_users',
|
||||
'box_id' => 'yearly-user-list-reporting-box',
|
||||
'export_route' => 'report_yearly_users_export',
|
||||
|
||||
101
src/Controller/Reporting/UserMonthController.php
Normal file
101
src/Controller/Reporting/UserMonthController.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\DailyStatistic;
|
||||
use App\Reporting\MonthByUser;
|
||||
use App\Reporting\MonthByUserForm;
|
||||
use Exception;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting/user")
|
||||
* @Security("is_granted('view_reporting')")
|
||||
*/
|
||||
final class UserMonthController extends AbstractUserReportController
|
||||
{
|
||||
/**
|
||||
* @Route(path="/month", name="report_user_month", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function monthByUser(Request $request): Response
|
||||
{
|
||||
return $this->render('reporting/report_by_user.html.twig', $this->getData($request));
|
||||
}
|
||||
|
||||
private function getData(Request $request): array
|
||||
{
|
||||
$currentUser = $this->getUser();
|
||||
$dateTimeFactory = $this->getDateTimeFactory($currentUser);
|
||||
$canChangeUser = $this->canSelectUser();
|
||||
|
||||
$values = new MonthByUser();
|
||||
$values->setUser($currentUser);
|
||||
$values->setDate($dateTimeFactory->getStartOfMonth());
|
||||
|
||||
$form = $this->createForm(MonthByUserForm::class, $values, [
|
||||
'include_user' => $canChangeUser,
|
||||
'timezone' => $dateTimeFactory->getTimezone()->getName(),
|
||||
'start_date' => $values->getDate(),
|
||||
]);
|
||||
|
||||
$form->submit($request->query->all(), false);
|
||||
|
||||
if ($values->getUser() === null) {
|
||||
$values->setUser($currentUser);
|
||||
}
|
||||
|
||||
if ($currentUser !== $values->getUser() && !$canChangeUser) {
|
||||
throw new AccessDeniedException('User is not allowed to see other users timesheet');
|
||||
}
|
||||
|
||||
if ($values->getDate() === null) {
|
||||
$values->setDate($dateTimeFactory->getStartOfMonth());
|
||||
}
|
||||
|
||||
$start = $values->getDate();
|
||||
$start->modify('first day of 00:00:00');
|
||||
|
||||
$end = clone $start;
|
||||
$end->modify('last day of 23:59:59');
|
||||
|
||||
$selectedUser = $values->getUser();
|
||||
|
||||
$previousMonth = clone $start;
|
||||
$previousMonth->modify('-1 month');
|
||||
|
||||
$nextMonth = clone $start;
|
||||
$nextMonth->modify('+1 month');
|
||||
|
||||
$data = $this->prepareReport($start, $end, $selectedUser);
|
||||
|
||||
return [
|
||||
'decimal' => $values->isDecimal(),
|
||||
'dataType' => $values->getSumType(),
|
||||
'report_title' => 'report_user_month',
|
||||
'box_id' => 'user-month-reporting-box',
|
||||
'form' => $form->createView(),
|
||||
'rows' => $data,
|
||||
'period' => new DailyStatistic($start, $end, $selectedUser),
|
||||
'user' => $selectedUser,
|
||||
'current' => $start,
|
||||
'next' => $nextMonth,
|
||||
'previous' => $previousMonth,
|
||||
];
|
||||
}
|
||||
}
|
||||
97
src/Controller/Reporting/UserWeekController.php
Normal file
97
src/Controller/Reporting/UserWeekController.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\DailyStatistic;
|
||||
use App\Reporting\WeekByUser;
|
||||
use App\Reporting\WeekByUserForm;
|
||||
use Exception;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting/user")
|
||||
* @Security("is_granted('view_reporting')")
|
||||
*/
|
||||
final class UserWeekController extends AbstractUserReportController
|
||||
{
|
||||
/**
|
||||
* @Route(path="/week", name="report_user_week", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function weekByUser(Request $request): Response
|
||||
{
|
||||
return $this->render('reporting/report_by_user.html.twig', $this->getData($request));
|
||||
}
|
||||
|
||||
private function getData(Request $request): array
|
||||
{
|
||||
$currentUser = $this->getUser();
|
||||
$dateTimeFactory = $this->getDateTimeFactory($currentUser);
|
||||
$canChangeUser = $this->canSelectUser();
|
||||
|
||||
$values = new WeekByUser();
|
||||
$values->setUser($currentUser);
|
||||
$values->setDate($dateTimeFactory->getStartOfWeek());
|
||||
|
||||
$form = $this->createForm(WeekByUserForm::class, $values, [
|
||||
'include_user' => $canChangeUser,
|
||||
'timezone' => $dateTimeFactory->getTimezone()->getName(),
|
||||
'start_date' => $values->getDate(),
|
||||
]);
|
||||
|
||||
$form->submit($request->query->all(), false);
|
||||
|
||||
if ($values->getUser() === null) {
|
||||
$values->setUser($currentUser);
|
||||
}
|
||||
|
||||
if ($currentUser !== $values->getUser() && !$canChangeUser) {
|
||||
throw new AccessDeniedException('User is not allowed to see other users timesheet');
|
||||
}
|
||||
|
||||
if ($values->getDate() === null) {
|
||||
$values->setDate($dateTimeFactory->getStartOfWeek());
|
||||
}
|
||||
|
||||
$start = $dateTimeFactory->getStartOfWeek($values->getDate());
|
||||
$end = $dateTimeFactory->getEndOfWeek($values->getDate());
|
||||
$selectedUser = $values->getUser();
|
||||
|
||||
$previous = clone $start;
|
||||
$previous->modify('-1 week');
|
||||
|
||||
$next = clone $start;
|
||||
$next->modify('+1 week');
|
||||
|
||||
$data = $this->prepareReport($start, $end, $selectedUser);
|
||||
|
||||
return [
|
||||
'decimal' => $values->isDecimal(),
|
||||
'dataType' => $values->getSumType(),
|
||||
'report_title' => 'report_user_week',
|
||||
'box_id' => 'user-week-reporting-box',
|
||||
'form' => $form->createView(),
|
||||
'period' => new DailyStatistic($start, $end, $selectedUser),
|
||||
'rows' => $data,
|
||||
'user' => $selectedUser,
|
||||
'current' => $start,
|
||||
'next' => $next,
|
||||
'previous' => $previous,
|
||||
];
|
||||
}
|
||||
}
|
||||
109
src/Controller/Reporting/UserYearController.php
Normal file
109
src/Controller/Reporting/UserYearController.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\DateStatisticInterface;
|
||||
use App\Model\MonthlyStatistic;
|
||||
use App\Reporting\YearByUser;
|
||||
use App\Reporting\YearByUserForm;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting/user")
|
||||
* @Security("is_granted('view_reporting')")
|
||||
*/
|
||||
final class UserYearController extends AbstractUserReportController
|
||||
{
|
||||
/**
|
||||
* @Route(path="/year", name="report_user_year", methods={"GET","POST"})
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function yearByUser(Request $request): Response
|
||||
{
|
||||
return $this->render('reporting/report_by_user_year.html.twig', $this->getData($request));
|
||||
}
|
||||
|
||||
private function getData(Request $request): array
|
||||
{
|
||||
$currentUser = $this->getUser();
|
||||
$dateTimeFactory = $this->getDateTimeFactory($currentUser);
|
||||
$canChangeUser = $this->canSelectUser();
|
||||
|
||||
$values = new YearByUser();
|
||||
$values->setUser($currentUser);
|
||||
$values->setDate($dateTimeFactory->createStartOfYear());
|
||||
|
||||
$form = $this->createForm(YearByUserForm::class, $values, [
|
||||
'include_user' => $canChangeUser,
|
||||
'timezone' => $dateTimeFactory->getTimezone()->getName(),
|
||||
'start_date' => $values->getDate(),
|
||||
]);
|
||||
|
||||
$form->submit($request->query->all(), false);
|
||||
|
||||
if ($values->getUser() === null) {
|
||||
$values->setUser($currentUser);
|
||||
}
|
||||
|
||||
if ($currentUser !== $values->getUser() && !$canChangeUser) {
|
||||
throw new AccessDeniedException('User is not allowed to see other users timesheet');
|
||||
}
|
||||
|
||||
if ($values->getDate() === null) {
|
||||
$values->setDate($dateTimeFactory->createStartOfYear());
|
||||
}
|
||||
|
||||
$start = $dateTimeFactory->createStartOfYear($values->getDate());
|
||||
$end = $dateTimeFactory->createEndOfYear($values->getDate());
|
||||
$selectedUser = $values->getUser();
|
||||
|
||||
$previous = clone $start;
|
||||
$previous->modify('-1 year');
|
||||
|
||||
$next = clone $start;
|
||||
$next->modify('+1 year');
|
||||
|
||||
$data = $this->prepareReport($start, $end, $selectedUser);
|
||||
|
||||
return [
|
||||
'decimal' => $values->isDecimal(),
|
||||
'dataType' => $values->getSumType(),
|
||||
'report_title' => 'report_user_year',
|
||||
'box_id' => 'user-year-reporting-box',
|
||||
'form' => $form->createView(),
|
||||
'period' => new MonthlyStatistic($start, $end, $selectedUser),
|
||||
'rows' => $data,
|
||||
'user' => $selectedUser,
|
||||
'current' => $start,
|
||||
'next' => $next,
|
||||
'previous' => $previous,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getStatisticDataRaw(DateTime $begin, DateTime $end, User $user): array
|
||||
{
|
||||
return $this->statisticService->getMonthlyStatisticsGrouped($begin, $end, [$user]);
|
||||
}
|
||||
|
||||
protected function createStatisticModel(DateTime $begin, DateTime $end, User $user): DateStatisticInterface
|
||||
{
|
||||
return new MonthlyStatistic($begin, $end, $user);
|
||||
}
|
||||
}
|
||||
57
src/Form/Type/ReportSumType.php
Normal file
57
src/Form/Type/ReportSumType.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
|
||||
class ReportSumType extends AbstractType
|
||||
{
|
||||
private $authorizationChecker;
|
||||
|
||||
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
|
||||
{
|
||||
$this->authorizationChecker = $authorizationChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
]);
|
||||
|
||||
$resolver->setDefault('choices', function (Options $options) {
|
||||
$choices = ['stats.durationTotal' => 'duration'];
|
||||
|
||||
if ($this->authorizationChecker->isGranted('view_rate_other_timesheet')) {
|
||||
$choices['stats.amountTotal'] = 'rate';
|
||||
$choices['label.rate_internal'] = 'internalRate';
|
||||
}
|
||||
|
||||
return $choices;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ use App\Model\Statistic\StatisticDate;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
|
||||
final class DailyStatistic
|
||||
final class DailyStatistic implements DateStatisticInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, StatisticDate>
|
||||
@@ -61,11 +61,26 @@ final class DailyStatistic
|
||||
return array_values($this->days);
|
||||
}
|
||||
|
||||
/**
|
||||
* For unified frontend access
|
||||
*
|
||||
* @return StatisticDate[]
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->getDays();
|
||||
}
|
||||
|
||||
public function getDayByDateTime(\DateTimeInterface $date): ?StatisticDate
|
||||
{
|
||||
return $this->getDay($date->format('Y'), $date->format('m'), $date->format('d'));
|
||||
}
|
||||
|
||||
public function getByDateTime(\DateTimeInterface $date): ?StatisticDate
|
||||
{
|
||||
return $this->getDayByDateTime($date);
|
||||
}
|
||||
|
||||
public function getDayByReportDate(string $date): ?StatisticDate
|
||||
{
|
||||
$this->setupDays();
|
||||
|
||||
30
src/Model/DateStatisticInterface.php
Normal file
30
src/Model/DateStatisticInterface.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Model\Statistic\StatisticDate;
|
||||
use DateTimeInterface;
|
||||
|
||||
interface DateStatisticInterface
|
||||
{
|
||||
/**
|
||||
* For unified frontend access
|
||||
*
|
||||
* @return StatisticDate[]
|
||||
*/
|
||||
public function getData(): array;
|
||||
|
||||
public function getByDateTime(DateTimeInterface $date): ?StatisticDate;
|
||||
|
||||
/**
|
||||
* @return DateTimeInterface[]
|
||||
*/
|
||||
public function getDateTimes(): array;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ use App\Model\Statistic\StatisticDate;
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
|
||||
final class MonthlyStatistic
|
||||
final class MonthlyStatistic implements DateStatisticInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, array<int, StatisticDate>>
|
||||
@@ -107,6 +107,26 @@ final class MonthlyStatistic
|
||||
return $all;
|
||||
}
|
||||
|
||||
/**
|
||||
* For unified frontend access
|
||||
*
|
||||
* @return StatisticDate[]
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->getMonths();
|
||||
}
|
||||
|
||||
public function getMonthByDateTime(DateTimeInterface $date): ?StatisticDate
|
||||
{
|
||||
return $this->getMonth($date->format('Y'), $date->format('m'));
|
||||
}
|
||||
|
||||
public function getByDateTime(DateTimeInterface $date): ?StatisticDate
|
||||
{
|
||||
return $this->getMonthByDateTime($date);
|
||||
}
|
||||
|
||||
public function getMonth(string $year, string $month): ?StatisticDate
|
||||
{
|
||||
$this->setupYears();
|
||||
|
||||
@@ -11,11 +11,9 @@ namespace App\Reporting;
|
||||
|
||||
abstract class AbstractUserList
|
||||
{
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $date;
|
||||
private $decimal = false;
|
||||
private $sumType = 'duration';
|
||||
|
||||
public function getDate(): ?\DateTime
|
||||
{
|
||||
@@ -36,4 +34,18 @@ abstract class AbstractUserList
|
||||
{
|
||||
$this->decimal = $decimal;
|
||||
}
|
||||
|
||||
public function getSumType(): string
|
||||
{
|
||||
return $this->sumType;
|
||||
}
|
||||
|
||||
public function setSumType(string $sumType): void
|
||||
{
|
||||
if (!\in_array($sumType, ['duration', 'rate', 'internalRate'])) {
|
||||
throw new \InvalidArgumentException('Unknown sum type');
|
||||
}
|
||||
|
||||
$this->sumType = $sumType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,38 +11,17 @@ namespace App\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
abstract class DateByUser
|
||||
abstract class DateByUser extends AbstractUserList
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $date;
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(User $user): self
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?\DateTime
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(\DateTime $date): self
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Reporting;
|
||||
|
||||
use App\Form\Type\MonthPickerType;
|
||||
use App\Form\Type\ReportSumType;
|
||||
use App\Form\Type\UserType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -41,6 +42,7 @@ class MonthByUserForm extends AbstractType
|
||||
if ($options['include_user']) {
|
||||
$builder->add('user', UserType::class, ['width' => false]);
|
||||
}
|
||||
$builder->add('sumType', ReportSumType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace App\Reporting;
|
||||
|
||||
use App\Form\Type\MonthPickerType;
|
||||
use App\Form\Type\ReportSumType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -36,6 +37,7 @@ class MonthlyUserListForm extends AbstractType
|
||||
'view_timezone' => $options['timezone'],
|
||||
'start_date' => $options['start_date'],
|
||||
]);
|
||||
$builder->add('sumType', ReportSumType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,6 +44,7 @@ final class ReportingService
|
||||
if ($this->security->isGranted('view_reporting')) {
|
||||
$event->addReport(new Report('week_by_user', 'report_user_week', 'report_user_week', 'user'));
|
||||
$event->addReport(new Report('month_by_user', 'report_user_month', 'report_user_month', 'user'));
|
||||
$event->addReport(new Report('year_by_user', 'report_user_year', 'report_user_year', 'user'));
|
||||
if ($this->security->isGranted('view_other_reporting') && $this->security->isGranted('view_other_timesheet')) {
|
||||
$event->addReport(new Report('weekly_users_list', 'report_weekly_users', 'report_weekly_users', 'users'));
|
||||
$event->addReport(new Report('monthly_users_list', 'report_monthly_users', 'report_monthly_users', 'users'));
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Reporting;
|
||||
|
||||
use App\Form\Type\ReportSumType;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\WeekPickerType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
@@ -41,6 +42,7 @@ class WeekByUserForm extends AbstractType
|
||||
if ($options['include_user']) {
|
||||
$builder->add('user', UserType::class, ['width' => false]);
|
||||
}
|
||||
$builder->add('sumType', ReportSumType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Reporting;
|
||||
|
||||
use App\Form\Type\ReportSumType;
|
||||
use App\Form\Type\WeekPickerType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -36,6 +37,7 @@ class WeeklyUserListForm extends AbstractType
|
||||
'view_timezone' => $options['timezone'],
|
||||
'start_date' => $options['start_date'],
|
||||
]);
|
||||
$builder->add('sumType', ReportSumType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
14
src/Reporting/YearByUser.php
Normal file
14
src/Reporting/YearByUser.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Reporting;
|
||||
|
||||
final class YearByUser extends DateByUser
|
||||
{
|
||||
}
|
||||
62
src/Reporting/YearByUserForm.php
Normal file
62
src/Reporting/YearByUserForm.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Reporting;
|
||||
|
||||
use App\Form\Type\ReportSumType;
|
||||
use App\Form\Type\UserType;
|
||||
use App\Form\Type\YearPickerType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class YearByUserForm extends AbstractType
|
||||
{
|
||||
/**
|
||||
* Simplify cross-linking between pages by removing the block prefix.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('date', YearPickerType::class, [
|
||||
'model_timezone' => $options['timezone'],
|
||||
'view_timezone' => $options['timezone'],
|
||||
'start_date' => $options['start_date'],
|
||||
]);
|
||||
|
||||
if ($options['include_user']) {
|
||||
$builder->add('user', UserType::class, ['width' => false]);
|
||||
}
|
||||
$builder->add('sumType', ReportSumType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => YearByUser::class,
|
||||
'timezone' => date_default_timezone_get(),
|
||||
'start_date' => new \DateTime(),
|
||||
'include_user' => false,
|
||||
'csrf_protection' => false,
|
||||
'method' => 'GET',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace App\Reporting;
|
||||
|
||||
use App\Form\Type\ReportSumType;
|
||||
use App\Form\Type\YearPickerType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -37,6 +38,7 @@ class YearlyUserListForm extends AbstractType
|
||||
'start_date' => $options['start_date'],
|
||||
'show_range' => true,
|
||||
]);
|
||||
$builder->add('sumType', ReportSumType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -156,6 +156,19 @@ class DateTimeFactory
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function createEndOfYear(?DateTime $date = null): DateTime
|
||||
{
|
||||
if (null === $date) {
|
||||
$date = $this->createDateTime();
|
||||
} else {
|
||||
$date = clone $date;
|
||||
}
|
||||
|
||||
$date->modify('last day of december 23:59:59');
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function createStartOfFinancialYear(?string $financialYear = null): DateTime
|
||||
{
|
||||
$defaultDate = $this->createDateTime('01 january this year 00:00:00');
|
||||
|
||||
@@ -143,11 +143,11 @@ final class TimesheetStatisticService
|
||||
$stats[$uid][$pid] = ['project' => $pid, 'activities' => []];
|
||||
}
|
||||
if (!isset($stats[$uid][$pid]['activities'][$aid])) {
|
||||
$stats[$uid][$pid]['activities'][$aid] = ['activity' => $aid, 'days' => new DailyStatistic($begin, $end, $usersById[$uid])];
|
||||
$stats[$uid][$pid]['activities'][$aid] = ['activity' => $aid, 'data' => new DailyStatistic($begin, $end, $usersById[$uid])];
|
||||
}
|
||||
|
||||
/** @var DailyStatistic $days */
|
||||
$days = $stats[$uid][$pid]['activities'][$aid]['days'];
|
||||
$days = $stats[$uid][$pid]['activities'][$aid]['data'];
|
||||
$day = $days->getDayByReportDate($row['date']);
|
||||
|
||||
if ($day === null) {
|
||||
@@ -167,6 +167,85 @@ final class TimesheetStatisticService
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal only for core development
|
||||
* @param DateTime $begin
|
||||
* @param DateTime $end
|
||||
* @param User[] $users
|
||||
* @return array<int, MonthlyStatistic[]>
|
||||
*/
|
||||
public function getMonthlyStatisticsGrouped(DateTime $begin, DateTime $end, array $users): array
|
||||
{
|
||||
/** @var MonthlyStatistic[] $stats */
|
||||
$stats = [];
|
||||
$usersById = [];
|
||||
|
||||
foreach ($users as $user) {
|
||||
$usersById[$user->getId()] = $user;
|
||||
if (!isset($stats[$user->getId()])) {
|
||||
$stats[$user->getId()] = [];
|
||||
}
|
||||
}
|
||||
|
||||
$qb = $this->repository->createQueryBuilder('t');
|
||||
$qb
|
||||
->select('COALESCE(SUM(t.rate), 0.0) as rate')
|
||||
->addSelect('COALESCE(SUM(t.duration), 0) as duration')
|
||||
->addSelect('COALESCE(SUM(t.internalRate), 0) as internalRate')
|
||||
->addSelect('t.billable as billable')
|
||||
->addSelect('IDENTITY(t.user) as user')
|
||||
->addSelect('IDENTITY(t.project) as project')
|
||||
->addSelect('IDENTITY(t.activity) as activity')
|
||||
->addSelect('YEAR(t.date) as year')
|
||||
->addSelect('MONTH(t.date) as month')
|
||||
->where($qb->expr()->isNotNull('t.end'))
|
||||
->andWhere($qb->expr()->between('t.begin', ':begin', ':end'))
|
||||
->andWhere($qb->expr()->in('t.user', ':user'))
|
||||
->setParameter('begin', $begin)
|
||||
->setParameter('end', $end)
|
||||
->setParameter('user', $users)
|
||||
->groupBy('year')
|
||||
->addGroupBy('month')
|
||||
->addGroupBy('project')
|
||||
->addGroupBy('activity')
|
||||
->addGroupBy('user')
|
||||
->addGroupBy('billable')
|
||||
;
|
||||
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
foreach ($results as $row) {
|
||||
$uid = $row['user'];
|
||||
$pid = $row['project'];
|
||||
$aid = $row['activity'];
|
||||
if (!isset($stats[$uid][$pid])) {
|
||||
$stats[$uid][$pid] = ['project' => $pid, 'activities' => []];
|
||||
}
|
||||
if (!isset($stats[$uid][$pid]['activities'][$aid])) {
|
||||
$stats[$uid][$pid]['activities'][$aid] = ['activity' => $aid, 'data' => new MonthlyStatistic($begin, $end, $usersById[$uid])];
|
||||
}
|
||||
|
||||
/** @var MonthlyStatistic $months */
|
||||
$months = $stats[$uid][$pid]['activities'][$aid]['data'];
|
||||
$month = $months->getMonth((string) $row['year'], (string) $row['month']);
|
||||
|
||||
if ($month === null) {
|
||||
// timezone differences
|
||||
continue;
|
||||
}
|
||||
|
||||
$month->setTotalDuration($month->getTotalDuration() + (int) $row['duration']);
|
||||
$month->setTotalRate($month->getTotalRate() + (float) $row['rate']);
|
||||
$month->setTotalInternalRate($month->getTotalInternalRate() + (float) $row['internalRate']);
|
||||
if ($row['billable']) {
|
||||
$month->setBillableRate((float) $row['rate']);
|
||||
$month->setBillableDuration((int) $row['duration']);
|
||||
}
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
public function findFirstRecordDate(User $user): ?DateTime
|
||||
{
|
||||
$result = $this->repository->createQueryBuilder('t')
|
||||
|
||||
@@ -39,6 +39,7 @@ final class IconExtension extends AbstractExtension
|
||||
'debug' => 'far fa-file-alt',
|
||||
'delete' => 'far fa-trash-alt',
|
||||
'details' => 'fas fa-info-circle',
|
||||
'display' => 'fas fa-layer-group',
|
||||
'doctor' => 'fas fa-medkit',
|
||||
'dot' => 'fas fa-circle',
|
||||
'download' => 'fas fa-download',
|
||||
|
||||
Reference in New Issue
Block a user