new report: week for users (#2494)

This commit is contained in:
Kevin Papst
2021-04-07 22:20:19 +02:00
committed by GitHub
parent cdad5913ca
commit 2ce6e815ff
27 changed files with 729 additions and 510 deletions

View File

@@ -43,17 +43,20 @@ final class SamlController extends AbstractController
$session = $request->getSession();
$authErrorKey = Security::AUTHENTICATION_ERROR;
$error = null;
if ($request->attributes->has($authErrorKey)) {
$error = $request->attributes->get($authErrorKey);
} elseif (null !== $session && $session->has($authErrorKey)) {
$error = $session->get($authErrorKey);
$session->remove($authErrorKey);
} else {
$error = null;
}
if ($error) {
throw new \RuntimeException($error->getMessage());
if (\is_object($error) && method_exists($error, 'getMessage')) {
$error = $error->getMessage();
}
throw new \RuntimeException($error);
}
$this->oneLoginAuth->login($session->get('_security.main.target_path'));

View File

@@ -0,0 +1,230 @@
<?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\Model\Statistic\Day;
use App\Reporting\MonthByUser;
use App\Reporting\MonthByUserForm;
use App\Reporting\WeekByUser;
use App\Reporting\WeekByUserForm;
use App\Repository\TimesheetRepository;
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
{
/**
* @var TimesheetRepository
*/
private $timesheetRepository;
public function __construct(TimesheetRepository $timesheetRepository)
{
$this->timesheetRepository = $timesheetRepository;
}
private function canSelectUser(): bool
{
// also found in App\EventSubscriber\Actions\UserSubscriber
if (!$this->isGranted('view_other_timesheet')) {
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);
$localeFormats = $this->getLocaleFormats($request->getLocale());
$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(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$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->timesheetRepository->getDailyStats($selectedUser, $start, $end);
$rows = $this->prepareReportData($data);
return $this->render('reporting/report_by_user.html.twig', [
'report_title' => 'report_user_month',
'box_id' => 'user-month-reporting-box',
'form' => $form->createView(),
'days' => $data,
'rows' => $rows,
'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);
$localeFormats = $this->getLocaleFormats($request->getLocale());
$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(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$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->timesheetRepository->getDailyStats($selectedUser, $start, $end);
$rows = $this->prepareReportData($data);
return $this->render('reporting/report_by_user.html.twig', [
'report_title' => 'report_user_week',
'box_id' => 'user-week-reporting-box',
'form' => $form->createView(),
'days' => $data,
'rows' => $rows,
'user' => $selectedUser,
'current' => $start,
'next' => $next,
'previous' => $previous,
]);
}
private function prepareReportData(array $data): array
{
$days = [];
foreach ($data as $day) {
$days[$day->getDay()->format('Ymd')] = ['date' => $day->getDay(), 'duration' => 0];
}
$rows = [];
/** @var Day $day */
foreach ($data as $day) {
$dayId = $day->getDay()->format('Ymd');
foreach ($day->getDetails() as $id => $detail) {
$projectId = $detail['project']->getId();
if (!\array_key_exists($projectId, $rows)) {
$rows[$projectId] = [
'project' => $detail['project'],
'duration' => 0,
'days' => $days,
'activities' => [],
];
}
$rows[$projectId]['duration'] += $detail['duration'];
$rows[$projectId]['days'][$dayId]['duration'] += $detail['duration'];
$activityId = $detail['activity']->getId();
if (!\array_key_exists($activityId, $rows[$projectId]['activities'])) {
$rows[$projectId]['activities'][$activityId] = [
'activity' => $detail['activity'],
'duration' => 0,
'days' => $days,
];
}
$rows[$projectId]['activities'][$activityId]['duration'] += $detail['duration'];
$rows[$projectId]['activities'][$activityId]['days'][$dayId]['duration'] += $detail['duration'];
}
}
return $rows;
}
}

View File

@@ -0,0 +1,200 @@
<?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\Model\Statistic\Day;
use App\Reporting\MonthlyUserList;
use App\Reporting\MonthlyUserListForm;
use App\Reporting\WeeklyUserList;
use App\Reporting\WeeklyUserListForm;
use App\Repository\Query\UserQuery;
use App\Repository\TimesheetRepository;
use App\Repository\UserRepository;
use Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(path="/reporting")
* @Security("is_granted('view_reporting') and is_granted('view_other_timesheet')")
*/
final class ReportUsersListController extends AbstractController
{
/**
* @var TimesheetRepository
*/
private $timesheetRepository;
/**
* @var UserRepository
*/
private $userRepository;
public function __construct(TimesheetRepository $timesheetRepository, UserRepository $userRepository)
{
$this->timesheetRepository = $timesheetRepository;
$this->userRepository = $userRepository;
}
/**
* @Route(path="/monthly_users_list", name="report_monthly_users", methods={"GET","POST"})
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function monthlyUsersList(Request $request): Response
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$localeFormats = $this->getLocaleFormats($request->getLocale());
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $this->userRepository->getUsersForQuery($query);
$rows = [];
$values = new MonthlyUserList();
$values->setDate($dateTimeFactory->getStartOfMonth());
$form = $this->createForm(MonthlyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$form->submit($request->query->all(), false);
if ($form->isSubmitted() && !$form->isValid()) {
$values->setDate($dateTimeFactory->getStartOfMonth());
}
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');
$previousMonth = clone $start;
$previousMonth->modify('-1 month');
$nextMonth = clone $start;
$nextMonth->modify('+1 month');
foreach ($allUsers as $user) {
$rows[] = [
'days' => $this->timesheetRepository->getDailyStats($user, $start, $end),
'user' => $user
];
}
$days = [];
if (isset($rows[0])) {
/** @var Day $day */
foreach ($rows[0]['days'] as $day) {
$days[$day->getDay()->format('Ymd')] = $day->getDay();
}
}
return $this->render('reporting/report_user_list.html.twig', [
'report_title' => 'report_monthly_users',
'box_id' => 'monthly-user-list-reporting-box',
'form' => $form->createView(),
'rows' => $rows,
'days' => $days,
'current' => $start,
'next' => $nextMonth,
'previous' => $previousMonth,
]);
}
/**
* @Route(path="/weekly_users_list", name="report_weekly_users", methods={"GET","POST"})
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function weeklyUsersList(Request $request): Response
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$localeFormats = $this->getLocaleFormats($request->getLocale());
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $this->userRepository->getUsersForQuery($query);
$rows = [];
$values = new WeeklyUserList();
$values->setDate($dateTimeFactory->getStartOfWeek());
$form = $this->createForm(WeeklyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$form->submit($request->query->all(), false);
if ($form->isSubmitted() && !$form->isValid()) {
$values->setDate($dateTimeFactory->getStartOfWeek());
}
if ($values->getDate() === null) {
$values->setDate($dateTimeFactory->getStartOfWeek());
}
$start = $dateTimeFactory->getStartOfWeek($values->getDate());
$end = $dateTimeFactory->getEndOfWeek($values->getDate());
$previousWeek = clone $start;
$previousWeek->modify('-1 week');
$nextWeek = clone $start;
$nextWeek->modify('+1 week');
foreach ($allUsers as $user) {
$rows[] = [
'days' => $this->timesheetRepository->getDailyStats($user, $start, $end),
'user' => $user
];
}
$days = [];
if (isset($rows[0])) {
/** @var Day $day */
foreach ($rows[0]['days'] as $day) {
$days[$day->getDay()->format('Ymd')] = $day->getDay();
}
}
return $this->render('reporting/report_user_list.html.twig', [
'report_title' => 'report_weekly_users',
'box_id' => 'weekly-user-list-reporting-box',
'form' => $form->createView(),
'rows' => $rows,
'days' => $days,
'current' => $start,
'next' => $nextWeek,
'previous' => $previousWeek,
]);
}
}

View File

@@ -9,23 +9,10 @@
namespace App\Controller;
use App\Model\Statistic\Day;
use App\Reporting\MonthByUser;
use App\Reporting\MonthByUserForm;
use App\Reporting\MonthlyUserList;
use App\Reporting\MonthlyUserListForm;
use App\Reporting\ReportingService;
use App\Reporting\WeekByUser;
use App\Reporting\WeekByUserForm;
use App\Repository\Query\UserQuery;
use App\Repository\TimesheetRepository;
use App\Repository\UserRepository;
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;
/**
* Controller used to render reports.
@@ -35,21 +22,6 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
*/
final class ReportingController extends AbstractController
{
/**
* @var TimesheetRepository
*/
private $timesheetRepository;
/**
* @var UserRepository
*/
private $userRepository;
public function __construct(TimesheetRepository $timesheetRepository, UserRepository $userRepository)
{
$this->timesheetRepository = $timesheetRepository;
$this->userRepository = $userRepository;
}
/**
* @Route(path="/", name="reporting", methods={"GET"})
*
@@ -83,266 +55,4 @@ final class ReportingController extends AbstractController
return $this->redirectToRoute($route);
}
private function canSelectUser(): bool
{
// also found in App\EventSubscriber\Actions\UserSubscriber
if (!$this->isGranted('view_other_timesheet')) {
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);
$localeFormats = $this->getLocaleFormats($request->getLocale());
$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(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$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->timesheetRepository->getDailyStats($selectedUser, $start, $end);
$rows = $this->prepareMonthlyData($data);
return $this->render('reporting/month_by_user.html.twig', [
'form' => $form->createView(),
'days' => $data,
'rows' => $rows,
'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);
$localeFormats = $this->getLocaleFormats($request->getLocale());
$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(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$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->timesheetRepository->getDailyStats($selectedUser, $start, $end);
$rows = $this->prepareMonthlyData($data);
return $this->render('reporting/week_by_user.html.twig', [
'form' => $form->createView(),
'days' => $data,
'rows' => $rows,
'user' => $selectedUser,
'current' => $start,
'next' => $next,
'previous' => $previous,
]);
}
/**
* @Route(path="/monthly_users_list", name="report_monthly_users", methods={"GET","POST"})
* @Security("is_granted('view_other_timesheet')")
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function monthlyUsersList(Request $request): Response
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$localeFormats = $this->getLocaleFormats($request->getLocale());
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $this->userRepository->getUsersForQuery($query);
$rows = [];
$values = new MonthlyUserList();
$values->setDate($dateTimeFactory->getStartOfMonth());
$form = $this->createForm(MonthlyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
'format' => $localeFormats->getDateTypeFormat(),
]);
$form->submit($request->query->all(), false);
if ($form->isSubmitted() && !$form->isValid()) {
$values->setDate($dateTimeFactory->getStartOfMonth());
}
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');
$previousMonth = clone $start;
$previousMonth->modify('-1 month');
$nextMonth = clone $start;
$nextMonth->modify('+1 month');
foreach ($allUsers as $user) {
$rows[] = [
'days' => $this->timesheetRepository->getDailyStats($user, $start, $end),
'user' => $user
];
}
$days = [];
if (isset($rows[0])) {
/** @var Day $day */
foreach ($rows[0]['days'] as $day) {
$days[$day->getDay()->format('Ymd')] = $day->getDay();
}
}
return $this->render('reporting/monthly_user_list.html.twig', [
'form' => $form->createView(),
'rows' => $rows,
'days' => $days,
'current' => $start,
'next' => $nextMonth,
'previous' => $previousMonth,
]);
}
private function prepareMonthlyData(array $data): array
{
$days = [];
foreach ($data as $day) {
$days[$day->getDay()->format('Ymd')] = ['date' => $day->getDay(), 'duration' => 0];
}
$rows = [];
/** @var Day $day */
foreach ($data as $day) {
$dayId = $day->getDay()->format('Ymd');
foreach ($day->getDetails() as $id => $detail) {
$projectId = $detail['project']->getId();
if (!\array_key_exists($projectId, $rows)) {
$rows[$projectId] = [
'project' => $detail['project'],
'duration' => 0,
'days' => $days,
'activities' => [],
];
}
$rows[$projectId]['duration'] += $detail['duration'];
$rows[$projectId]['days'][$dayId]['duration'] += $detail['duration'];
$activityId = $detail['activity']->getId();
if (!\array_key_exists($activityId, $rows[$projectId]['activities'])) {
$rows[$projectId]['activities'][$activityId] = [
'activity' => $detail['activity'],
'duration' => 0,
'days' => $days,
];
}
$rows[$projectId]['activities'][$activityId]['duration'] += $detail['duration'];
$rows[$projectId]['activities'][$activityId]['days'][$dayId]['duration'] += $detail['duration'];
}
}
return $rows;
}
}

View File

@@ -10,6 +10,7 @@
namespace App\EventSubscriber\Actions;
use App\Event\PageActionsEvent;
use App\Reporting\Report;
use App\Reporting\ReportingService;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
@@ -34,7 +35,11 @@ class ReportingSubscriber extends AbstractActionsSubscriber
$reports = $this->reportingService->getAvailableReports($event->getUser());
foreach ($reports as $report) {
$event->addActionToSubmenu('reporting', $report->getId(), ['title' => $report->getLabel(), 'translation_domain' => 'reporting', 'url' => $this->path($report->getRoute()), 'class' => 'toolbar-action report-' . $report->getId()]);
$subMenu = 'reporting';
if ($report instanceof Report) {
$subMenu = $report->getReportIcon();
}
$event->addActionToSubmenu($subMenu, $report->getId(), ['title' => $report->getLabel(), 'translation_domain' => 'reporting', 'url' => $this->path($report->getRoute()), 'class' => 'toolbar-action report-' . $report->getId()]);
}
$event->addHelp($this->documentationLink('reporting.html'));

View File

@@ -95,7 +95,7 @@ final class MenuSubscriber implements EventSubscriberInterface
if ($auth->isGranted('view_reporting')) {
$reporting = new MenuItemModel('reporting', 'menu.reporting', 'reporting', [], $this->getIcon('reporting'));
$reporting->setChildRoutes(['report_user_week', 'report_user_month', 'report_monthly_users']);
$reporting->setChildRoutes(['report_user_week', 'report_user_month', 'report_weekly_users', 'report_monthly_users', 'report_project_view']);
$menu->addChild($reporting);
}

View File

@@ -316,7 +316,8 @@ abstract class AbstractToolbarForm extends AbstractType
'choices' => [
'label.asc' => BaseQuery::ORDER_ASC,
'label.desc' => BaseQuery::ORDER_DESC
]
],
'search' => false,
]);
}
@@ -340,7 +341,8 @@ abstract class AbstractToolbarForm extends AbstractType
}
$builder->add('orderBy', ChoiceType::class, [
'label' => 'label.orderBy',
'choices' => $all
'choices' => $all,
'search' => false,
]);
}

View File

@@ -0,0 +1,28 @@
<?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;
abstract class AbstractUserList
{
/**
* @var \DateTime
*/
private $date;
public function getDate(): ?\DateTime
{
return $this->date;
}
public function setDate(\DateTime $date): void
{
$this->date = $date;
}
}

View File

@@ -9,22 +9,6 @@
namespace App\Reporting;
final class MonthlyUserList
final class MonthlyUserList extends AbstractUserList
{
/**
* @var \DateTime
*/
private $date;
public function getDate(): ?\DateTime
{
return $this->date;
}
public function setDate(\DateTime $date): MonthlyUserList
{
$this->date = $date;
return $this;
}
}

View File

@@ -14,12 +14,16 @@ final class Report implements ReportInterface
private $id;
private $label;
private $route;
private $reportIcon = 'reporting';
public function __construct(string $id, string $route, string $label)
public function __construct(string $id, string $route, string $label, ?string $reportIcon = null)
{
$this->id = $id;
$this->route = $route;
$this->label = $label;
if (null !== $reportIcon) {
$this->reportIcon = $reportIcon;
}
}
public function getRoute(): string
@@ -36,4 +40,9 @@ final class Report implements ReportInterface
{
return $this->label;
}
public function getReportIcon(): string
{
return $this->reportIcon;
}
}

View File

@@ -42,13 +42,14 @@ final class ReportingService
$event = new ReportingEvent($user);
if ($this->security->isGranted('view_reporting')) {
$event->addReport(new Report(self::DEFAULT_VIEW, 'report_user_week', 'report_user_week'));
$event->addReport(new Report('month_by_user', 'report_user_month', 'report_user_month'));
if ($this->security->isGranted('budget_project')) {
$event->addReport(new Report('project_view', 'report_project_view', 'report_project_view'));
}
$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'));
if ($this->security->isGranted('view_other_timesheet')) {
$event->addReport(new Report('monthly_users_list', 'report_monthly_users', 'report_monthly_users'));
$event->addReport(new Report('weekly_users_list', 'report_weekly_users', 'report_weekly_users', 'user'));
$event->addReport(new Report('monthly_users_list', 'report_monthly_users', 'report_monthly_users', 'user'));
}
if ($this->security->isGranted('budget_project')) {
$event->addReport(new Report('project_view', 'report_project_view', 'report_project_view', 'project'));
}
$this->dispatcher->dispatch($event);

View 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 WeeklyUserList extends AbstractUserList
{
}

View 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\Reporting;
use App\Form\Type\WeekPickerType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class WeeklyUserListForm 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', WeekPickerType::class, [
'model_timezone' => $options['timezone'],
'view_timezone' => $options['timezone'],
'start_date' => $options['start_date'],
'format' => $options['format'],
]);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => WeeklyUserList::class,
'timezone' => date_default_timezone_get(),
'start_date' => new \DateTime(),
'format' => DateType::HTML5_FORMAT,
'csrf_protection' => false,
'method' => 'GET',
]);
}
}

View File

@@ -51,7 +51,7 @@
</button>
<ul class="dropdown-menu">
<li>
<a href="?removeDefaultQuery={{ form.vars.data.bookmark.name }}" id="removeDefaultQuery">{{ 'action.delete'|trans }}</a>
<a href="?removeDefaultQuery={{ form.vars.data.bookmark.name }}" id="removeDefaultQuery">{{ 'label.remove_default'|trans }}</a>
</li>
</ul>
{% else %}

View File

@@ -147,7 +147,7 @@
{% endmacro %}
{% macro badge(title, color) %}
<span class="badge" style="background-color:{{ color }}">{{ title }}</span>
<span class="badge" style="background-color:{{ color }}; color:{{ color|font_contrast }}">{{ title }}</span>
{% endmacro %}
{% macro alert(type, description, title, icon) %}

View File

@@ -1,112 +0,0 @@
{% extends 'reporting/layout.html.twig' %}
{% block report_title %}{{ 'report_user_month'|trans({}, 'reporting') }}{% endblock %}
{% block report %}
{% set hasData = false %}
{% for day in days %}
{% if day.details is not empty %}
{% set hasData = true %}
{% endif %}
{% endfor %}
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% block box_before %}
{{ form_start(form, {'action': path('report_user_month'), 'attr': {'class': 'form-inline'}}) }}
{% endblock %}
{% block box_after %}
{{ form_end(form) }}
{% endblock %}
{% block box_title %}
{% if form.user is defined %}
{{ form_row(form.user, {'label': false}) }}
{% else %}
{{ widgets.username(user) }}
{% endif %}
{{ form_widget(form.date) }}
{% endblock %}
{% block box_body_class %}user-month-reporting-box table-responsive{% if hasData %} no-padding{% endif %}{% endblock %}
{% block box_body %}
{% if not hasData %}
{{ widgets.nothing_found() }}
{% else %}
<table class="table table-bordered table-hover dataTable">
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
{% for day in days %}
<th class="text-center text-nowrap{% if day.day is weekend %} weekend{% endif %}">
{{ day.day|day_name(true) }}<br>
{{ day.day|date_format('d.m') }}
</th>
{% endfor %}
</tr>
{% for project in rows %}
<tr class="project">
<td class="text-nowrap">
<strong>{{ widgets.label_project(project.project) }}</strong>
</td>
<th class="text-nowrap text-center total">{{ project.duration|duration }}</th>
{% for day in project.days %}
<td class="text-nowrap text-center day-total{% if day.date is weekend %} weekend{% endif %}">
{% if day.duration > 0 %}
<strong>{{ day.duration|duration }}</strong>
{% endif %}
</td>
{% endfor %}
</tr>
{% for activity in project.activities %}
<tr class="activity">
<td class="text-nowrap">
{{ widgets.label_activity(activity.activity) }}
</td>
<th class="text-nowrap text-center total">{{ activity.duration|duration }}</th>
{% for day in activity.days %}
<td class="text-nowrap text-center day-total{% if day.date is weekend %} weekend{% endif %}">
{% if day.duration > 0 %}
{{ day.duration|duration }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
{% endfor %}
{% set total = 0 %}
<tr class="summary">
{% for day in days %}
{% set total = total + day.totalDuration %}
{% endfor %}
<th></th>
<th class="text-nowrap text-center total">{{ total|duration }}</th>
{% for day in days %}
<th class="text-nowrap text-center day-total{% if day.day is weekend %} weekend{% endif %}">
{% if day.totalDuration > 0 %}
{{ day.totalDuration|duration }}
{% endif %}
</th>
{% endfor %}
</tr>
</table>
{% endif %}
{% endblock %}
{% endembed %}
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
document.addEventListener('kimai.initialized', function() {
{% if form.user is defined %}
$('#{{ form.user.vars.id }}').on('change', function(ev) {
$(this).closest('form').submit();
});
{% endif %}
$('#{{ form.date.vars.id }}').on('change', function(ev) {
$(this).closest('form').submit();
});
});
</script>
{% endblock %}

View File

@@ -1,6 +1,6 @@
{% extends 'reporting/layout.html.twig' %}
{% block report_title %}{{ 'report_user_week'|trans({}, 'reporting') }}{% endblock %}
{% block report_title %}{{ report_title|trans({}, 'reporting') }}{% endblock %}
{% block report %}
@@ -14,7 +14,7 @@
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% block box_before %}
{{ form_start(form, {'action': path('report_user_week'), 'attr': {'class': 'form-inline'}}) }}
{{ form_start(form, {'attr': {'class': 'form-inline'}}) }}
{% endblock %}
{% block box_after %}
{{ form_end(form) }}
@@ -27,7 +27,7 @@
{% endif %}
{{ form_widget(form.date) }}
{% endblock %}
{% block box_body_class %}user-week-reporting-box table-responsive{% if hasData %} no-padding{% endif %}{% endblock %}
{% block box_body_class %}{{ box_id }} table-responsive{% if hasData %} no-padding{% endif %}{% endblock %}
{% block box_body %}
{% if not hasData %}
{{ widgets.nothing_found() }}

View File

@@ -1,13 +1,13 @@
{% extends 'reporting/layout.html.twig' %}
{% block report_title %}{{ 'report_monthly_users'|trans({}, 'reporting') }}{% endblock %}
{% block report_title %}{{ report_title|trans({}, 'reporting') }}{% endblock %}
{% block report %}
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% block box_before %}
{{ form_start(form, {'action': path('report_monthly_users'), 'attr': {'class': 'form-inline'}}) }}
{{ form_start(form, {'attr': {'class': 'form-inline'}}) }}
{% endblock %}
{% block box_after %}
{{ form_end(form) }}
@@ -15,7 +15,7 @@
{% block box_title %}
{{ form_widget(form.date) }}
{% endblock %}
{% block box_body_class %}monthly-user-list-reporting-box table-responsive no-padding{% endblock %}
{% block box_body_class %}{{ box_id }} table-responsive no-padding{% endblock %}
{% block box_body %}
<table class="table table-bordered table-hover dataTable">
<tr>
@@ -29,19 +29,19 @@
{% endfor %}
</tr>
{% for userDay in rows %}
{% set usersMonthDuration = 0 %}
{% set usersTotalDuration = 0 %}
<tr class="user">
<td class="text-nowrap">
<strong>{{ widgets.username(userDay.user) }}</strong>
</td>
{% for day in userDay.days %}
{% if day.totalDuration > 0 %}
{% set usersMonthDuration = usersMonthDuration + day.totalDuration %}
{% set usersTotalDuration = usersTotalDuration + day.totalDuration %}
{% endif %}
{% endfor %}
<th class="text-nowrap text-center total">
{% if usersMonthDuration > 0 %}
{{ usersMonthDuration|duration }}
{% if usersTotalDuration > 0 %}
{{ usersTotalDuration|duration }}
{% endif %}
</th>
{% for day in userDay.days %}

View File

@@ -0,0 +1,60 @@
<?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\Tests\Controller\Reporting;
use App\Entity\User;
use App\Tests\Controller\ControllerBaseTest;
use App\Tests\DataFixtures\TimesheetFixtures;
/**
* @group integration
*/
class ReportByUserControllerTest extends ControllerBaseTest
{
protected function importReportingFixture(string $role)
{
$fixture = new TimesheetFixtures();
$fixture->setAmount(50);
$fixture->setAmountRunning(10);
$fixture->setUser($this->getUserByRole($role));
$fixture->setStartDate(new \DateTime());
$this->importFixture($fixture);
}
public function testWeekByUserIsSecure()
{
$this->assertUrlIsSecured('/reporting/week_by_user');
}
public function testMonthByUserIsSecure()
{
$this->assertUrlIsSecured('/reporting/month_by_user');
}
public function testUserWeekReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$this->importReportingFixture(User::ROLE_SUPER_ADMIN);
$this->assertAccessIsGranted($client, '/reporting/week_by_user?user=4&date=12999119191');
self::assertStringContainsString('<div class="box-body user-week-reporting-box', $client->getResponse()->getContent());
$option = $client->getCrawler()->filterXPath("//select[@id='user']/option[@selected]");
self::assertEquals(4, $option->attr('value'));
}
public function testUserMonthReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importReportingFixture(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/reporting/month_by_user?user=4&date=12999119191');
self::assertStringContainsString('<div class="box-body user-month-reporting-box', $client->getResponse()->getContent());
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
self::assertEquals(0, $select->count());
}
}

View File

@@ -0,0 +1,70 @@
<?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\Tests\Controller\Reporting;
use App\Entity\User;
use App\Tests\Controller\ControllerBaseTest;
use App\Tests\DataFixtures\TimesheetFixtures;
/**
* @group integration
*/
class ReportUsersListControllerTest extends ControllerBaseTest
{
protected function importReportingFixture(string $role)
{
$fixture = new TimesheetFixtures();
$fixture->setAmount(50);
$fixture->setAmountRunning(10);
$fixture->setUser($this->getUserByRole($role));
$fixture->setStartDate(new \DateTime());
$this->importFixture($fixture);
}
public function testWeeklyListIsSecure()
{
$this->assertUrlIsSecured('/reporting/weekly_users_list');
}
public function testMonthlyListIsSecure()
{
$this->assertUrlIsSecured('/reporting/monthly_users_list');
}
public function testWeeklyUsersListIsSecureForUserRole()
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/weekly_users_list');
}
public function testMonthlyUsersListIsSecureForUserRole()
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/monthly_users_list');
}
public function testWeeklyUsersReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importReportingFixture(User::ROLE_TEAMLEAD);
$this->assertAccessIsGranted($client, '/reporting/weekly_users_list');
self::assertStringContainsString('<div class="box-body weekly-user-list-reporting-box', $client->getResponse()->getContent());
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
self::assertEquals(0, $select->count());
}
public function testMonthlyUsersReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importReportingFixture(User::ROLE_TEAMLEAD);
$this->assertAccessIsGranted($client, '/reporting/monthly_users_list');
self::assertStringContainsString('<div class="box-body monthly-user-list-reporting-box', $client->getResponse()->getContent());
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
self::assertEquals(0, $select->count());
}
}

View File

@@ -10,7 +10,6 @@
namespace App\Tests\Controller;
use App\Entity\User;
use App\Tests\DataFixtures\TimesheetFixtures;
/**
* @group integration
@@ -22,73 +21,12 @@ class ReportingControllerTest extends ControllerBaseTest
$this->assertUrlIsSecured('/reporting');
}
public function testWeekByUserIsSecure()
{
$this->assertUrlIsSecured('/reporting/week_by_user');
}
public function testMonthByUserIsSecure()
{
$this->assertUrlIsSecured('/reporting/month_by_user');
}
public function testMonthlyListIsSecure()
{
$this->assertUrlIsSecured('/reporting/monthly_users_list');
}
public function testMonthlyUsersListIsSecureForUserRole()
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/monthly_users_list');
}
protected function importReportingFixture(string $role)
{
$fixture = new TimesheetFixtures();
$fixture->setAmount(50);
$fixture->setAmountRunning(10);
$fixture->setUser($this->getUserByRole($role));
$fixture->setStartDate(new \DateTime());
$this->importFixture($fixture);
}
public function testRedirectForDefaultReportUrl()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importReportingFixture(User::ROLE_USER);
$this->request($client, '/reporting/');
$this->assertIsRedirect($client, $this->createUrl('/reporting/week_by_user'));
$client->followRedirect();
self::assertStringContainsString('<div class="box-body user-week-reporting-box', $client->getResponse()->getContent());
}
public function testUserWeekReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$this->importReportingFixture(User::ROLE_SUPER_ADMIN);
$this->assertAccessIsGranted($client, '/reporting/week_by_user?user=4&date=12999119191');
self::assertStringContainsString('<div class="box-body user-week-reporting-box', $client->getResponse()->getContent());
$option = $client->getCrawler()->filterXPath("//select[@id='user']/option[@selected]");
self::assertEquals(4, $option->attr('value'));
}
public function testUserMonthReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importReportingFixture(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/reporting/month_by_user?user=4&date=12999119191');
self::assertStringContainsString('<div class="box-body user-month-reporting-box', $client->getResponse()->getContent());
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
self::assertEquals(0, $select->count());
}
public function testMonthlyUsersReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importReportingFixture(User::ROLE_TEAMLEAD);
$this->assertAccessIsGranted($client, '/reporting/monthly_users_list');
self::assertStringContainsString('<div class="box-body monthly-user-list-reporting-box', $client->getResponse()->getContent());
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
self::assertEquals(0, $select->count());
}
}

View File

@@ -25,5 +25,9 @@ class ReportTest extends TestCase
self::assertEquals('id', $report->getId());
self::assertEquals('route', $report->getRoute());
self::assertEquals('label', $report->getLabel());
self::assertEquals('reporting', $report->getReportIcon());
$report = new Report('id', 'route', 'label', 'foo');
self::assertEquals('foo', $report->getReportIcon());
}
}

View File

@@ -47,6 +47,6 @@ class ReportingServiceTest extends TestCase
$sut = $this->getSut(true);
$reports = $sut->getAvailableReports(new User());
self::assertIsArray($reports);
self::assertCount(4, $reports);
self::assertCount(5, $reports);
}
}

View File

@@ -66,7 +66,11 @@
</trans-unit>
<trans-unit id="label.set_as_default">
<source>label.set_as_default</source>
<target>Als Standard-Einstellung speichern</target>
<target>Einstellung als Suchfavorit speichern</target>
</trans-unit>
<trans-unit id="label.remove_default">
<source>label.remove_default</source>
<target>Suchfavorit löschen</target>
</trans-unit>
<trans-unit id="label.asc">
<source>label.asc</source>

View File

@@ -66,7 +66,11 @@
</trans-unit>
<trans-unit id="label.set_as_default">
<source>label.set_as_default</source>
<target>Save as default setting</target>
<target>Save setting as search favourite</target>
</trans-unit>
<trans-unit id="label.remove_default">
<source>label.remove_default</source>
<target>Delete search favourite</target>
</trans-unit>
<trans-unit id="label.asc">
<source>label.asc</source>

View File

@@ -10,6 +10,10 @@
<source>report_user_month</source>
<target>Monatsansicht für einen Benutzer</target>
</trans-unit>
<trans-unit id="report_weekly_users">
<source>report_weekly_users</source>
<target>Wochenansicht für alle Benutzer</target>
</trans-unit>
<trans-unit id="report_monthly_users">
<source>report_monthly_users</source>
<target>Monatsansicht für alle Benutzer</target>

View File

@@ -10,6 +10,10 @@
<source>report_user_month</source>
<target>Monthly view for one user</target>
</trans-unit>
<trans-unit id="report_weekly_users">
<source>report_weekly_users</source>
<target>Weekly view for all users</target>
</trans-unit>
<trans-unit id="report_monthly_users">
<source>report_monthly_users</source>
<target>Monthly view for all users</target>