financial year setting + new users working time per year report (#2547)

This commit is contained in:
Kevin Papst
2021-05-14 18:40:48 +02:00
committed by GitHub
parent a9da5f8476
commit f7aa3c1e13
59 changed files with 1690 additions and 217 deletions

View File

@@ -16,7 +16,7 @@ abstract class AbstractWidgetType implements WidgetInterface
/**
* @var string
*/
protected $id = '';
protected $id;
/**
* @var string
*/
@@ -39,7 +39,11 @@ abstract class AbstractWidgetType implements WidgetInterface
public function getId(): string
{
return $this->id;
if (!empty($this->id)) {
return $this->id;
}
return (new \ReflectionClass($this))->getShortName();
}
public function setData($data): self

View File

@@ -0,0 +1,34 @@
<?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\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Repository\TimesheetRepository;
final class ActiveUsersYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
parent::__construct($repository, $systemConfiguration);
$this->setId('activeUsersYear');
$this->setOption('icon', 'user');
$this->setOption('color', 'yellow');
$this->setTitle('stats.userActiveYear');
}
public function getData(array $options = [])
{
$this->titleYear = 'stats.userActiveFinancialYear';
$this->setQuery(TimesheetRepository::STATS_QUERY_USER);
$this->setQueryWithUser(false);
return parent::getData($options);
}
}

View File

@@ -0,0 +1,35 @@
<?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\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Repository\TimesheetRepository;
final class AmountYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
parent::__construct($repository, $systemConfiguration);
$this->setId('amountYear');
$this->setOption('dataType', 'money');
$this->setOption('icon', 'money');
$this->setOption('color', 'yellow');
$this->setTitle('stats.amountYear');
}
public function getData(array $options = [])
{
$this->titleYear = 'stats.amountFinancialYear';
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
$this->setQueryWithUser(false);
return parent::getData($options);
}
}

View File

@@ -0,0 +1,52 @@
<?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\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Repository\TimesheetRepository;
use App\Timesheet\DateTimeFactory;
class CounterYear extends SimpleStatisticChart
{
private $systemConfiguration;
/**
* @var string|null
*/
protected $titleYear;
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
parent::__construct($repository);
$this->systemConfiguration = $systemConfiguration;
$this->setOption('dataType', 'int');
}
public function getData(array $options = [])
{
$this->begin = '01 january this year 00:00:00';
$this->end = '31 december this year 23:59:59';
if (null !== ($financialYear = $this->systemConfiguration->getFinancialYearStart())) {
$factory = new DateTimeFactory($this->getTimezone());
$this->begin = $factory->createStartOfFinancialYear($financialYear);
$this->end = $factory->createEndOfFinancialYear($this->begin);
if (!empty($this->titleYear)) {
$this->setTitle($this->titleYear);
}
}
return parent::getData($options);
}
public function getTemplateName(): string
{
return 'widget/widget-counter.html.twig';
}
}

View File

@@ -0,0 +1,35 @@
<?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\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Repository\TimesheetRepository;
final class DurationYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
parent::__construct($repository, $systemConfiguration);
$this->setId('durationYear');
$this->setOption('dataType', 'duration');
$this->setOption('icon', 'duration');
$this->setOption('color', 'yellow');
$this->setTitle('stats.durationYear');
}
public function getData(array $options = [])
{
$this->titleYear = 'stats.durationFinancialYear';
$this->setQuery(TimesheetRepository::STATS_QUERY_DURATION);
$this->setQueryWithUser(false);
return parent::getData($options);
}
}

View File

@@ -9,6 +9,7 @@
namespace App\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Entity\User;
use App\Repository\TimesheetRepository;
use App\Timesheet\DateTimeFactory;
@@ -16,22 +17,15 @@ use DateTime;
final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
{
/**
* @var TimesheetRepository
*/
private $repository;
private $systemConfiguration;
public function __construct(TimesheetRepository $repository)
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
$this->repository = $repository;
$this->systemConfiguration = $systemConfiguration;
$this->setId('PaginatedWorkingTimeChart');
$this->setTitle('stats.yourWorkingHours');
$this->setOptions([
'year' => (new DateTime('now'))->format('o'),
'week' => (new DateTime('now'))->format('W'),
'type' => 'bar',
]);
}
public function setUser(User $user): void
@@ -48,10 +42,15 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
{
$options = parent::getOptions($options);
if (!\in_array($options['type'], ['bar', 'line'])) {
if (!\array_key_exists('type', $options) || !\in_array($options['type'], ['bar', 'line'])) {
$options['type'] = 'bar';
}
if (!\array_key_exists('year', $options)) {
$options['year'] = (new DateTime('now'))->format('o');
$options['week'] = (new DateTime('now'))->format('W');
}
return $options;
}
@@ -91,6 +90,25 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
$thisMonth = ($dateTimeFactory->createDateTime())->setISODate($year, $week, 1)->setTime(0, 0, 0);
}
$dayBegin = $dateTimeFactory->createDateTime('00:00:00');
$dayEnd = $dateTimeFactory->createDateTime('23:59:59');
$monthBegin = (clone $weekBegin)->setDate((int) $weekBegin->format('Y'), (int) $weekBegin->format('n'), 1)->setTime(0, 0, 0);
$monthEnd = (clone $weekBegin)->setDate((int) $weekBegin->format('Y'), (int) $weekBegin->format('n'), (int) $weekBegin->format('t'))->setTime(23, 59, 59);
$yearBegin = $dateTimeFactory->createDateTime(sprintf('01 january %s 00:00:00', $year));
$yearEnd = $dateTimeFactory->createDateTime(sprintf('31 december %s 23:59:59', $year));
$yearData = $this->repository->getStatistic('duration', $yearBegin, $yearEnd, $user);
$financialYearData = null;
$financialYearBegin = null;
if (null !== ($financialYear = $this->systemConfiguration->getFinancialYearStart())) {
$financialYearBegin = $dateTimeFactory->createStartOfFinancialYear($financialYear);
$financialYearEnd = $dateTimeFactory->createEndOfFinancialYear($financialYearBegin);
$financialYearData = $this->repository->getStatistic('duration', $financialYearBegin, $financialYearEnd, $user);
}
return [
'begin' => clone $weekBegin,
'end' => clone $weekEnd,
@@ -98,30 +116,12 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
'thisMonth' => $thisMonth,
'lastWeekInYear' => $lastWeekInYear,
'lastWeekInLastYear' => $lastWeekInLastYear,
'day' => $this->repository->getStatistic(
'duration',
$dateTimeFactory->createDateTime('00:00:00'),
$dateTimeFactory->createDateTime('23:59:59'),
$user
),
'week' => $this->repository->getStatistic(
'duration',
$weekBegin,
$weekEnd,
$user
),
'month' => $this->repository->getStatistic(
'duration',
(clone $weekBegin)->setDate((int) $weekBegin->format('Y'), (int) $weekBegin->format('n'), 1)->setTime(0, 0, 0),
(clone $weekBegin)->setDate((int) $weekBegin->format('Y'), (int) $weekBegin->format('n'), (int) $weekBegin->format('t'))->setTime(23, 59, 59),
$user
),
'year' => $this->repository->getStatistic(
'duration',
$dateTimeFactory->createDateTime(sprintf('01 january %s 00:00:00', $year)),
$dateTimeFactory->createDateTime(sprintf('31 december %s 23:59:59', $year)),
$user
),
'day' => $this->repository->getStatistic('duration', $dayBegin, $dayEnd, $user),
'week' => $this->repository->getStatistic('duration', $weekBegin, $weekEnd, $user),
'month' => $this->repository->getStatistic('duration', $monthBegin, $monthEnd, $user),
'year' => $yearData,
'financial' => $financialYearData,
'financialBegin' => $financialYearBegin,
];
}
}

View File

@@ -24,13 +24,13 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
*/
private $query;
/**
* @var string
* @var string|\DateTime
*/
private $begin;
protected $begin;
/**
* @var string
* @var string|\DateTime
*/
private $end;
protected $end;
/**
* @var User|null
*/
@@ -83,6 +83,16 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
return $this;
}
public function getTimezone(): \DateTimeZone
{
$timezone = date_default_timezone_get();
if (null !== $this->user) {
$timezone = $this->user->getTimezone();
}
return new \DateTimeZone($timezone);
}
/**
* @param array $options
* @return mixed|null
@@ -90,14 +100,18 @@ class SimpleStatisticChart extends SimpleWidget implements UserWidget
*/
public function getData(array $options = [])
{
$timezone = date_default_timezone_get();
if (null !== $this->user) {
$timezone = $this->user->getTimezone();
}
$timezone = new \DateTimeZone($timezone);
$timezone = $this->getTimezone();
$begin = !empty($this->begin) ? new \DateTime($this->begin, $timezone) : null;
$end = !empty($this->end) ? new \DateTime($this->end, $timezone) : null;
$begin = $this->begin;
$end = $this->end;
if (!empty($begin) && \is_string($begin)) {
$begin = new \DateTime($begin, $timezone);
}
if (!empty($end) && \is_string($end)) {
$end = new \DateTime($end, $timezone);
}
try {
if (true === $this->queryWithUser) {

View File

@@ -0,0 +1,35 @@
<?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\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Repository\TimesheetRepository;
final class UserAmountYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
parent::__construct($repository, $systemConfiguration);
$this->setId('userAmountYear');
$this->setOption('dataType', 'money');
$this->setOption('icon', 'money');
$this->setOption('color', 'yellow');
$this->setTitle('stats.amountYear');
}
public function getData(array $options = [])
{
$this->titleYear = 'stats.amountFinancialYear';
$this->setQuery(TimesheetRepository::STATS_QUERY_RATE);
$this->setQueryWithUser(true);
return parent::getData($options);
}
}

View File

@@ -0,0 +1,35 @@
<?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\Widget\Type;
use App\Configuration\SystemConfiguration;
use App\Repository\TimesheetRepository;
final class UserDurationYear extends CounterYear
{
public function __construct(TimesheetRepository $repository, SystemConfiguration $systemConfiguration)
{
parent::__construct($repository, $systemConfiguration);
$this->setId('userDurationYear');
$this->setOption('dataType', 'duration');
$this->setOption('icon', 'duration');
$this->setOption('color', 'yellow');
}
public function getData(array $options = [])
{
$this->setTitle('stats.durationYear');
$this->titleYear = 'stats.durationFinancialYear';
$this->setQuery(TimesheetRepository::STATS_QUERY_DURATION);
$this->setQueryWithUser(true);
return parent::getData($options);
}
}