export user-list reports in excel (#3154)

This commit is contained in:
Kevin Papst
2022-02-14 17:55:10 +01:00
committed by GitHub
parent 7da7468965
commit 1852d71974
12 changed files with 594 additions and 356 deletions

View File

@@ -199,15 +199,24 @@ final class ReportByUserController extends AbstractController
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;

View File

@@ -1,241 +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\Configuration\SystemConfiguration;
use App\Controller\AbstractController;
use App\Model\DailyStatistic;
use App\Model\MonthlyStatistic;
use App\Reporting\MonthlyUserList;
use App\Reporting\MonthlyUserListForm;
use App\Reporting\WeeklyUserList;
use App\Reporting\WeeklyUserListForm;
use App\Reporting\YearlyUserList;
use App\Reporting\YearlyUserListForm;
use App\Repository\Query\UserQuery;
use App\Repository\UserRepository;
use App\Timesheet\TimesheetStatisticService;
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_reporting') and is_granted('view_other_timesheet')")
*/
final class ReportUsersListController extends AbstractController
{
private $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
/**
* @Route(path="/yearly_users_list", name="report_yearly_users", methods={"GET","POST"})
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function yearlyUsersList(Request $request, SystemConfiguration $systemConfiguration, TimesheetStatisticService $statisticService): Response
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $this->userRepository->getUsersForQuery($query);
$defaultDate = $dateTimeFactory->createDateTime('01 january this year 00:00:00');
if (null !== ($financialYear = $systemConfiguration->getFinancialYearStart())) {
$defaultDate = $this->getDateTimeFactory()->createStartOfFinancialYear($financialYear);
}
$values = new YearlyUserList();
$values->setDate(clone $defaultDate);
$form = $this->createForm(YearlyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
]);
$form->submit($request->query->all(), false);
if ($form->isSubmitted() && !$form->isValid()) {
$values->setDate(clone $defaultDate);
}
if ($values->getDate() === null) {
$values->setDate(clone $defaultDate);
}
$start = $values->getDate();
// there is a potential edge case bug for financial years:
// the last month will be skipped, if the financial year started on a different day than the first
$end = $dateTimeFactory->createEndOfFinancialYear($start);
$monthStats = [];
$hasData = true;
if (!empty($allUsers)) {
$monthStats = $statisticService->getMonthlyStats($start, $end, $allUsers);
}
if (empty($monthStats)) {
$monthStats = [new MonthlyStatistic($start, $end, $currentUser)];
$hasData = false;
}
return $this->render('reporting/report_user_list_monthly.html.twig', [
'report_title' => 'report_yearly_users',
'box_id' => 'yearly-user-list-reporting-box',
'form' => $form->createView(),
'stats' => $monthStats,
'hasData' => $hasData,
]);
}
/**
* @Route(path="/monthly_users_list", name="report_monthly_users", methods={"GET","POST"})
*/
public function monthlyUsersList(Request $request, TimesheetStatisticService $statisticService): Response
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $this->userRepository->getUsersForQuery($query);
$values = new MonthlyUserList();
$values->setDate($dateTimeFactory->getStartOfMonth());
$form = $this->createForm(MonthlyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
]);
$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');
$previous = clone $start;
$previous->modify('-1 month');
$next = clone $start;
$next->modify('+1 month');
$dayStats = [];
$hasData = true;
if (!empty($allUsers)) {
$dayStats = $statisticService->getDailyStatistics($start, $end, $allUsers);
}
if (empty($dayStats)) {
$dayStats = [new DailyStatistic($start, $end, $currentUser)];
$hasData = false;
}
return $this->render('reporting/report_user_list.html.twig', [
'report_title' => 'report_monthly_users',
'box_id' => 'monthly-user-list-reporting-box',
'form' => $form->createView(),
'current' => $start,
'next' => $next,
'previous' => $previous,
'subReportDate' => $values->getDate(),
'subReportRoute' => 'report_user_month',
'stats' => $dayStats,
'hasData' => $hasData,
]);
}
/**
* @Route(path="/weekly_users_list", name="report_weekly_users", methods={"GET","POST"})
*/
public function weeklyUsersList(Request $request, TimesheetStatisticService $statisticService): Response
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $this->userRepository->getUsersForQuery($query);
$values = new WeeklyUserList();
$values->setDate($dateTimeFactory->getStartOfWeek());
$form = $this->createForm(WeeklyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
]);
$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());
$previous = clone $start;
$previous->modify('-1 week');
$next = clone $start;
$next->modify('+1 week');
$dayStats = [];
$hasData = true;
if (!empty($allUsers)) {
$dayStats = $statisticService->getDailyStatistics($start, $end, $allUsers);
}
if (empty($dayStats)) {
$dayStats = [new DailyStatistic($start, $end, $currentUser)];
$hasData = false;
}
return $this->render('reporting/report_user_list.html.twig', [
'report_title' => 'report_weekly_users',
'box_id' => 'weekly-user-list-reporting-box',
'form' => $form->createView(),
'current' => $start,
'next' => $next,
'previous' => $previous,
'subReportDate' => $values->getDate(),
'subReportRoute' => 'report_user_week',
'stats' => $dayStats,
'hasData' => $hasData,
]);
}
}

View File

@@ -0,0 +1,127 @@
<?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\Export\Spreadsheet\Writer\BinaryFileResponseWriter;
use App\Export\Spreadsheet\Writer\XlsxWriter;
use App\Model\DailyStatistic;
use App\Reporting\MonthlyUserList;
use App\Reporting\MonthlyUserListForm;
use App\Repository\Query\UserQuery;
use App\Repository\UserRepository;
use App\Timesheet\TimesheetStatisticService;
use PhpOffice\PhpSpreadsheet\Reader\Html;
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_reporting') and is_granted('view_other_timesheet')")
*/
final class ReportUsersMonthController extends AbstractController
{
/**
* @Route(path="/monthly_users_list", name="report_monthly_users", methods={"GET","POST"})
*/
public function report(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
{
return $this->render(
'reporting/report_user_list.html.twig',
$this->getData($request, $statisticService, $userRepository)
);
}
/**
* @Route(path="/export/monthly_users_list", name="report_monthly_users_export", methods={"GET","POST"})
*/
public function export(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
{
$data = $this->getData($request, $statisticService, $userRepository);
$content = $this->container->get('twig')->render('reporting/report_user_list_export.html.twig', $data);
$reader = new Html();
$spreadsheet = $reader->loadFromString($content);
$writer = new BinaryFileResponseWriter(new XlsxWriter(), 'kimai-export-users-weekly');
return $writer->getFileResponse($spreadsheet);
}
private function getData(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): array
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $userRepository->getUsersForQuery($query);
$values = new MonthlyUserList();
$values->setDate($dateTimeFactory->getStartOfMonth());
$form = $this->createForm(MonthlyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
]);
$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');
$previous = clone $start;
$previous->modify('-1 month');
$next = clone $start;
$next->modify('+1 month');
$dayStats = [];
$hasData = true;
if (!empty($allUsers)) {
$dayStats = $statisticService->getDailyStatistics($start, $end, $allUsers);
}
if (empty($dayStats)) {
$dayStats = [new DailyStatistic($start, $end, $currentUser)];
$hasData = false;
}
return [
'report_title' => 'report_monthly_users',
'box_id' => 'monthly-user-list-reporting-box',
'export_route' => 'report_monthly_users_export',
'form' => $form->createView(),
'current' => $start,
'next' => $next,
'previous' => $previous,
'decimal' => $values->isDecimal(),
'subReportDate' => $values->getDate(),
'subReportRoute' => 'report_user_month',
'stats' => $dayStats,
'hasData' => $hasData,
];
}
}

View File

@@ -0,0 +1,124 @@
<?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\Export\Spreadsheet\Writer\BinaryFileResponseWriter;
use App\Export\Spreadsheet\Writer\XlsxWriter;
use App\Model\DailyStatistic;
use App\Reporting\WeeklyUserList;
use App\Reporting\WeeklyUserListForm;
use App\Repository\Query\UserQuery;
use App\Repository\UserRepository;
use App\Timesheet\TimesheetStatisticService;
use PhpOffice\PhpSpreadsheet\Reader\Html;
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_reporting') and is_granted('view_other_timesheet')")
*/
final class ReportUsersWeekController extends AbstractController
{
/**
* @Route(path="/weekly_users_list", name="report_weekly_users", methods={"GET","POST"})
*/
public function report(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
{
return $this->render(
'reporting/report_user_list.html.twig',
$this->getData($request, $statisticService, $userRepository)
);
}
/**
* @Route(path="/export/weekly_users_list", name="report_weekly_users_export", methods={"GET","POST"})
*/
public function export(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
{
$data = $this->getData($request, $statisticService, $userRepository);
$content = $this->container->get('twig')->render('reporting/report_user_list_export.html.twig', $data);
$reader = new Html();
$spreadsheet = $reader->loadFromString($content);
$writer = new BinaryFileResponseWriter(new XlsxWriter(), 'kimai-export-users-weekly');
return $writer->getFileResponse($spreadsheet);
}
private function getData(Request $request, TimesheetStatisticService $statisticService, UserRepository $userRepository): array
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $userRepository->getUsersForQuery($query);
$values = new WeeklyUserList();
$values->setDate($dateTimeFactory->getStartOfWeek());
$form = $this->createForm(WeeklyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
]);
$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());
$previous = clone $start;
$previous->modify('-1 week');
$next = clone $start;
$next->modify('+1 week');
$dayStats = [];
$hasData = true;
if (!empty($allUsers)) {
$dayStats = $statisticService->getDailyStatistics($start, $end, $allUsers);
}
if (empty($dayStats)) {
$dayStats = [new DailyStatistic($start, $end, $currentUser)];
$hasData = false;
}
return [
'report_title' => 'report_weekly_users',
'box_id' => 'weekly-user-list-reporting-box',
'export_route' => 'report_weekly_users_export',
'form' => $form->createView(),
'current' => $start,
'next' => $next,
'previous' => $previous,
'decimal' => $values->isDecimal(),
'subReportDate' => $values->getDate(),
'subReportRoute' => 'report_user_week',
'stats' => $dayStats,
'hasData' => $hasData,
];
}
}

View File

@@ -0,0 +1,130 @@
<?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\Configuration\SystemConfiguration;
use App\Controller\AbstractController;
use App\Export\Spreadsheet\Writer\BinaryFileResponseWriter;
use App\Export\Spreadsheet\Writer\XlsxWriter;
use App\Model\MonthlyStatistic;
use App\Reporting\YearlyUserList;
use App\Reporting\YearlyUserListForm;
use App\Repository\Query\UserQuery;
use App\Repository\UserRepository;
use App\Timesheet\TimesheetStatisticService;
use Exception;
use PhpOffice\PhpSpreadsheet\Reader\Html;
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_reporting') and is_granted('view_other_timesheet')")
*/
final class ReportUsersYearController extends AbstractController
{
/**
* @Route(path="/yearly_users_list", name="report_yearly_users", methods={"GET","POST"})
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function report(Request $request, SystemConfiguration $systemConfiguration, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
{
return $this->render(
'reporting/report_user_list_monthly.html.twig',
$this->getData($request, $systemConfiguration, $statisticService, $userRepository)
);
}
/**
* @Route(path="/export/yearly_users_list", name="report_yearly_users_export", methods={"GET","POST"})
*
* @param Request $request
* @return Response
* @throws Exception
*/
public function export(Request $request, SystemConfiguration $systemConfiguration, TimesheetStatisticService $statisticService, UserRepository $userRepository): Response
{
$data = $this->getData($request, $systemConfiguration, $statisticService, $userRepository);
$content = $this->container->get('twig')->render('reporting/report_user_list_monthly_export.html.twig', $data);
$reader = new Html();
$spreadsheet = $reader->loadFromString($content);
$writer = new BinaryFileResponseWriter(new XlsxWriter(), 'kimai-export-users-yearly');
return $writer->getFileResponse($spreadsheet);
}
private function getData(Request $request, SystemConfiguration $systemConfiguration, TimesheetStatisticService $statisticService, UserRepository $userRepository): array
{
$currentUser = $this->getUser();
$dateTimeFactory = $this->getDateTimeFactory();
$query = new UserQuery();
$query->setCurrentUser($currentUser);
$allUsers = $userRepository->getUsersForQuery($query);
$defaultDate = $dateTimeFactory->createDateTime('01 january this year 00:00:00');
if (null !== ($financialYear = $systemConfiguration->getFinancialYearStart())) {
$defaultDate = $this->getDateTimeFactory()->createStartOfFinancialYear($financialYear);
}
$values = new YearlyUserList();
$values->setDate(clone $defaultDate);
$form = $this->createForm(YearlyUserListForm::class, $values, [
'timezone' => $dateTimeFactory->getTimezone()->getName(),
'start_date' => $values->getDate(),
]);
$form->submit($request->query->all(), false);
if ($form->isSubmitted() && !$form->isValid()) {
$values->setDate(clone $defaultDate);
}
if ($values->getDate() === null) {
$values->setDate(clone $defaultDate);
}
$start = $values->getDate();
// there is a potential edge case bug for financial years:
// the last month will be skipped, if the financial year started on a different day than the first
$end = $dateTimeFactory->createEndOfFinancialYear($start);
$monthStats = [];
$hasData = true;
if (!empty($allUsers)) {
$monthStats = $statisticService->getMonthlyStats($start, $end, $allUsers);
}
if (empty($monthStats)) {
$monthStats = [new MonthlyStatistic($start, $end, $currentUser)];
$hasData = false;
}
return [
'report_title' => 'report_yearly_users',
'box_id' => 'yearly-user-list-reporting-box',
'export_route' => 'report_yearly_users_export',
'decimal' => $values->isDecimal(),
'form' => $form->createView(),
'stats' => $monthStats,
'hasData' => $hasData,
];
}
}

View File

@@ -15,6 +15,7 @@ abstract class AbstractUserList
* @var \DateTime
*/
private $date;
private $decimal = false;
public function getDate(): ?\DateTime
{
@@ -25,4 +26,14 @@ abstract class AbstractUserList
{
$this->date = $date;
}
public function isDecimal(): bool
{
return $this->decimal;
}
public function setDecimal(bool $decimal): void
{
$this->decimal = $decimal;
}
}

View File

@@ -15,67 +15,15 @@
{% block box_title %}
{{ form_widget(form.date) }}
{% endblock %}
{% block box_tools %}
<button class="btn btn-default btn-sm" formaction="{{ path(export_route) }}" type="submit"><i class="{{ 'download'|icon }}"></i></button>
{% endblock %}
{% block box_body_class %}{{ box_id }} table-responsive {% if hasData %}no-padding{% endif %}{% endblock %}
{% block box_body %}
{% if not hasData %}
{{ widgets.nothing_found() }}
{% else %}
{% set absoluteTotals = 0 %}
{% set totals = {} %}
<table class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
{% for day in stats.0.getDateTimes() %}
<th class="text-center text-nowrap{% if day is weekend %} weekend{% endif %}{% if day is today %} today{% endif %}">
{{ day|date_weekday }}
</th>
{% set totals = totals|merge({(day|report_date): 0}) %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for userDay in stats %}
{% set usersTotalDuration = 0 %}
<tr class="user">
<td class="text-nowrap">
{{ widgets.label_dot(userDay.user.displayName, userDay.user.color) }}
</td>
{% for day in userDay.days %}
{% if day.totalDuration > 0 %}
{% set usersTotalDuration = usersTotalDuration + day.totalDuration %}
{% set absoluteTotals = absoluteTotals + day.totalDuration %}
{% endif %}
{% set totals = totals|merge({(day.date|report_date): (totals[day.date|report_date] + day.totalDuration)}) %}
{% endfor %}
<th class="text-nowrap text-center total">
<a href="{{ path(subReportRoute, {'date': subReportDate|report_date, 'user': userDay.user.id}) }}">{{ usersTotalDuration|duration }}</a>
</th>
{% for day in userDay.days %}
<td class="text-nowrap text-center day-total{% if day.date is weekend %} weekend{% endif %}{% if day.date is today %} today{% endif %}">
{% if day.totalDuration > 0 %}
{{ day.totalDuration|duration }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="summary">
<td>{{ 'stats.durationTotal'|trans }}</td>
<td class="text-center text-nowrap">
{{ absoluteTotals|duration }}
</td>
{% for id, duration in totals %}
<td class="text-center text-nowrap">
{{ duration|duration }}
</td>
{% endfor %}
</tr>
</tfoot>
</table>
{% embed 'reporting/report_user_list_data.html.twig' %}{% endembed %}
{% endif %}
{% endblock %}
{% endembed %}

View File

@@ -0,0 +1,69 @@
{% set absoluteTotals = 0 %}
{% set totals = {} %}
<table class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>&nbsp;</th>
<th class="text-center">{{ 'stats.durationTotal'|trans }}</th>
{% for day in stats.0.getDateTimes() %}
<th class="text-center text-nowrap{% if day is weekend %} weekend{% endif %}{% if day is today %} today{% endif %}">
{% block period_name %}
{{ day|date_weekday }}
{% endblock %}
</th>
{% set totals = totals|merge({(day|report_date): 0}) %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for userPeriod in stats %}
{% set usersTotalDuration = 0 %}
<tr class="user">
<td class="text-nowrap">
{% block user_column %}
{% from "macros/widgets.html.twig" import label_dot %}
{{ label_dot(userPeriod.user.displayName, userPeriod.user.color) }}
{% endblock %}
</td>
{% for period in userPeriod.days %}
{% if period.totalDuration > 0 %}
{% set usersTotalDuration = usersTotalDuration + period.totalDuration %}
{% set absoluteTotals = absoluteTotals + period.totalDuration %}
{% endif %}
{% set totals = totals|merge({(period.date|report_date): (totals[period.date|report_date] + period.totalDuration)}) %}
{% endfor %}
<th class="text-nowrap text-center total">
{% block total_duration_user %}
<a href="{{ path(subReportRoute, {'date': subReportDate|report_date, 'user': userPeriod.user.id}) }}">{{ usersTotalDuration|duration(decimal) }}</a>
{% endblock %}
</th>
{% for period in userPeriod.days %}
<td class="text-nowrap text-center day-total{% if period.date is weekend %} weekend{% endif %}{% if period.date is today %} today{% endif %}">
{% if period.totalDuration > 0 %}
{% block duration %}
{{ period.totalDuration|duration(decimal) }}
{% endblock %}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="summary">
<td>{{ 'stats.durationTotal'|trans }}</td>
<td class="text-center text-nowrap">
{% block total_duration %}
{{ absoluteTotals|duration(decimal) }}
{% endblock %}
</td>
{% for id, total in totals %}
<td class="text-center text-nowrap">
{% block total_duration_period %}
{{ total|duration(decimal) }}
{% endblock %}
</td>
{% endfor %}
</tr>
</tfoot>
</table>

View File

@@ -0,0 +1,20 @@
{% embed 'reporting/report_user_list_data.html.twig' %}
{% block user_column %}
{{ userPeriod.user.displayName }}
{% endblock %}
{% block duration -%}
=VALUE("{{ period.totalDuration|duration(true) }}")
{%- endblock %}
{% block total_duration_user -%}
=VALUE("{{ usersTotalDuration|duration(true) }}")
{%- endblock %}
{% block total_duration -%}
=VALUE("{{ absoluteTotals|duration(true) }}")
{%- endblock %}
{% block total_duration_period -%}
=VALUE("{{ total|duration(true) }}")
{%- endblock %}
{% block period_name %}
{{ day|date_short }}
{% endblock %}
{% endembed %}

View File

@@ -5,78 +5,25 @@
{% block report %}
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% from "macros/widgets.html.twig" import nothing_found, action_button %}
{% block box_before %}
{{ form_start(form, {'attr': {'class': 'form-inline form-reporting'}}) }}
{% endblock %}
{% block box_after %}
{{ form_end(form) }}
{% endblock %}
{% block box_tools %}
<button class="btn btn-default btn-sm" formaction="{{ path(export_route) }}" type="submit"><i class="{{ 'download'|icon }}"></i></button>
{% endblock %}
{% block box_title %}
{{ form_widget(form.date) }}
{% endblock %}
{% block box_body_class %}{{ box_id }} table-responsive {% if hasData %}no-padding{% endif %}{% endblock %}
{% block box_body %}
{% if not hasData %}
{{ widgets.nothing_found() }}
{{ nothing_found() }}
{% else %}
{% set totals = {} %}
<table class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>&nbsp;</th>
<th>&nbsp;</th>
{% for month in stats.0.getDateTimes() %}
<th class="text-center text-nowrap">
<a href="{{ path('report_monthly_users', {'date': month|report_date}) }}">
{{ month|month_name }}<br>
{{ month|date_format('Y') }}
</a>
</th>
{% set totals = totals|merge({(month|report_date): 0}) %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for userYear in stats|filter(row => row.user is not null) %}
{% set usersTotalDuration = 0 %}
<tr class="user">
<td class="text-nowrap">
{{ widgets.label_dot(userYear.user.displayName, userYear.user.color) }}
</td>
{% for mid, month in userYear.months %}
{% if month.totalDuration > 0 %}
{% set usersTotalDuration = usersTotalDuration + month.totalDuration %}
{% endif %}
{% endfor %}
<th class="text-nowrap text-center total">
{{ usersTotalDuration|duration }}
</th>
{% for mid, month in userYear.getMonths() %}
<td class="text-nowrap text-center day-total">
{% if month.totalDuration > 0 %}
<a href="{{ path('report_user_month', {'date': create_date(month.date.format('Y') ~'-'~month.date.format('m')~'-01')|report_date, 'user': userYear.user.id}) }}" data-toggle="tooltip" title="{{ 'label.billable'|trans }}: {{ month.billableDuration|duration }}">
{{ month.totalDuration|duration }}
</a>
{% set totals = totals|merge({(month.date|report_date): (totals[month.date|report_date] + month.totalDuration)}) %}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="summary">
<td>{{ 'stats.durationTotal'|trans }}</td>
<td>&nbsp;</td>
{% for id, total in totals %}
<td class="text-center text-nowrap">
{{ total|duration }}
</td>
{% endfor %}
</tr>
</tfoot>
</table>
{% embed 'reporting/report_user_list_monthly_data.html.twig' %}{% endembed %}
{% endif %}
{% endblock %}
{% endembed %}

View File

@@ -0,0 +1,74 @@
{% set absoluteTotals = 0 %}
{% set totals = {} %}
<table class="table table-bordered table-hover dataTable">
<thead>
<tr>
<th>&nbsp;</th>
<th class="text-center">{{ 'stats.durationTotal'|trans }}</th>
{% for month in stats.0.getDateTimes() %}
<th class="text-center text-nowrap">
{% block period_name %}
<a href="{{ path('report_monthly_users', {'date': month|report_date}) }}">
{{ month|month_name }}<br>
{{ month|date_format('Y') }}
</a>
{% endblock %}
</th>
{% set totals = totals|merge({(month|report_date): 0}) %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for userPeriod in stats|filter(row => row.user is not null) %}
{% set usersTotalDuration = 0 %}
<tr class="user">
<td class="text-nowrap">
{% block user_column %}
{% from "macros/widgets.html.twig" import label_dot %}
{{ label_dot(userPeriod.user.displayName, userPeriod.user.color) }}
{% endblock %}
</td>
{% for mid, period in userPeriod.months %}
{% if period.totalDuration > 0 %}
{% set usersTotalDuration = usersTotalDuration + period.totalDuration %}
{% set absoluteTotals = absoluteTotals + period.totalDuration %}
{% endif %}
{% endfor %}
<th class="text-nowrap text-center total">
{% block total_duration_user %}
{{ usersTotalDuration|duration(decimal) }}
{% endblock %}
</th>
{% for mid, period in userPeriod.months %}
<td class="text-nowrap text-center day-total">
{% if period.totalDuration > 0 %}
{% block duration %}
<a href="{{ path('report_user_month', {'date': create_date(period.date.format('Y') ~'-'~period.date.format('m')~'-01')|report_date, 'user': userPeriod.user.id}) }}" data-toggle="tooltip" title="{{ 'label.billable'|trans }}: {{ period.billableDuration|duration(decimal) }}">
{{ period.totalDuration|duration(decimal) }}
</a>
{% endblock %}
{% set totals = totals|merge({(period.date|report_date): (totals[period.date|report_date] + period.totalDuration)}) %}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr class="summary">
<td>{{ 'stats.durationTotal'|trans }}</td>
<td class="text-center text-nowrap">
{% block total_duration %}
{{ absoluteTotals|duration(decimal) }}
{% endblock %}
</td>
{% for id, total in totals %}
<td class="text-center text-nowrap">
{% block total_duration_period %}
{{ total|duration(decimal) }}
{% endblock %}
</td>
{% endfor %}
</tr>
</tfoot>
</table>

View File

@@ -0,0 +1,20 @@
{% embed 'reporting/report_user_list_monthly_data.html.twig' %}
{% block user_column %}
{{ userPeriod.user.displayName }}
{% endblock %}
{% block duration -%}
=VALUE("{{ period.totalDuration|duration(true) }}")
{%- endblock %}
{% block total_duration_user -%}
=VALUE("{{ usersTotalDuration|duration(true) }}")
{%- endblock %}
{% block total_duration -%}
=VALUE("{{ absoluteTotals|duration(true) }}")
{%- endblock %}
{% block total_duration_period -%}
=VALUE("{{ total|duration(true) }}")
{%- endblock %}
{% block period_name %}
{{ month|month_name }} {{ month|date_format('Y') }}
{% endblock %}
{% endembed %}