financial year setting + new users working time per year report (#2547)
This commit is contained in:
@@ -70,7 +70,11 @@ final class ProfileController extends AbstractController
|
||||
public function indexAction(User $profile, TimesheetRepository $repository, LocaleSettings $localeSettings)
|
||||
{
|
||||
$userStats = $repository->getUserStatistics($profile);
|
||||
$monthlyStats = $repository->getMonthlyStats($profile);
|
||||
|
||||
$begin = $userStats->getFirstEntry() ?? $this->getDateTimeFactory()->getStartOfMonth();
|
||||
$end = $this->getDateTimeFactory()->getEndOfMonth();
|
||||
$monthlyStats = $repository->getMonthlyStats($begin, $end, $profile);
|
||||
arsort($monthlyStats);
|
||||
|
||||
$viewVars = [
|
||||
'tab' => 'charts',
|
||||
|
||||
@@ -184,6 +184,10 @@ final class ReportByUserController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Day[] $data
|
||||
* @return array
|
||||
*/
|
||||
private function prepareReportData(array $data): array
|
||||
{
|
||||
$days = [];
|
||||
@@ -194,7 +198,6 @@ final class ReportByUserController extends AbstractController
|
||||
|
||||
$rows = [];
|
||||
|
||||
/** @var Day $day */
|
||||
foreach ($data as $day) {
|
||||
$dayId = $day->getDay()->format('Ymd');
|
||||
foreach ($day->getDetails() as $id => $detail) {
|
||||
|
||||
@@ -9,12 +9,16 @@
|
||||
|
||||
namespace App\Controller\Reporting;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Controller\AbstractController;
|
||||
use App\Model\Statistic\Day;
|
||||
use App\Model\Statistic\Year;
|
||||
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\TimesheetRepository;
|
||||
use App\Repository\UserRepository;
|
||||
@@ -26,7 +30,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
/**
|
||||
* @Route(path="/reporting")
|
||||
* @Security("is_granted('view_reporting') and is_granted('view_other_timesheet')")
|
||||
* @Security("is_granted('view_reporting') and is_granted('view_other_reporting') and is_granted('view_other_timesheet')")
|
||||
*/
|
||||
final class ReportUsersListController extends AbstractController
|
||||
{
|
||||
@@ -45,6 +49,141 @@ final class ReportUsersListController extends AbstractController
|
||||
$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): Response
|
||||
{
|
||||
$currentUser = $this->getUser();
|
||||
$dateTimeFactory = $this->getDateTimeFactory();
|
||||
$localeFormats = $this->getLocaleFormats($request->getLocale());
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
|
||||
$values = new YearlyUserList();
|
||||
$values->setDate(clone $defaultDate);
|
||||
|
||||
$form = $this->createForm(YearlyUserListForm::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(clone $defaultDate);
|
||||
}
|
||||
|
||||
if ($values->getDate() === null) {
|
||||
$values->setDate(clone $defaultDate);
|
||||
}
|
||||
|
||||
$start = $values->getDate();
|
||||
$end = $this->getDateTimeFactory()->createEndOfFinancialYear($start);
|
||||
|
||||
$months = [];
|
||||
$totals = [];
|
||||
foreach ($allUsers as $user) {
|
||||
$rows[] = [
|
||||
'years' => $this->timesheetRepository->getMonthlyStats($start, $end, $user),
|
||||
'user' => $user
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($rows[0])) {
|
||||
/** @var Year $year */
|
||||
foreach ($rows[0]['years'] as $year) {
|
||||
foreach ($year->getMonths() as $month) {
|
||||
$date = new \DateTime();
|
||||
$date->setDate((int) $year->getYear(), $month->getMonthNumber(), 1);
|
||||
$date->setTime(0, 0, 0);
|
||||
$months[$date->format('Ym')] = $date;
|
||||
}
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
foreach ($row['years'] as $year) {
|
||||
foreach ($year->getMonths() as $month) {
|
||||
$date = new \DateTime();
|
||||
$date->setDate((int) $year->getYear(), $month->getMonthNumber(), 1);
|
||||
$totalsId = $date->format('Ym');
|
||||
if (!isset($totals[$totalsId])) {
|
||||
$totals[$totalsId] = 0;
|
||||
}
|
||||
$totals[$totalsId] += $month->getTotalDuration();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
foreach ($allUsers as $user) {
|
||||
$rows[] = [
|
||||
'days' => $this->timesheetRepository->getDailyStats($user, $start, $end),
|
||||
'user' => $user
|
||||
];
|
||||
}
|
||||
|
||||
$userYears = [];
|
||||
|
||||
if (isset($rows[0])) {
|
||||
foreach ($rows[0]['days'] as $day) {
|
||||
$months[$day->getDay()->format('Ym')] = $day->getDay();
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$userYear = ['user' => $row['user']];
|
||||
foreach ($row['days'] as $day) {
|
||||
$yearId = $day->getDay()->format('Y');
|
||||
$monthId = $day->getDay()->format('m');
|
||||
$totalsId = $yearId.$monthId;
|
||||
|
||||
if (!array_key_exists('years', $userYear)) {
|
||||
$userYear['years'] = [];
|
||||
}
|
||||
if (!array_key_exists($yearId, $userYear['years'])) {
|
||||
$userYear['years'][$yearId] = ['year' => $yearId];
|
||||
}
|
||||
if (!array_key_exists('months', $userYear['years'][$yearId])) {
|
||||
$userYear['years'][$yearId]['months'] = [];
|
||||
}
|
||||
if (!array_key_exists($monthId, $userYear['years'][$yearId]['months'])) {
|
||||
$userYear['years'][$yearId]['months'][$monthId] = ['month' => $monthId, 'totalDuration' => 0];
|
||||
}
|
||||
if (!array_key_exists($totalsId, $totals)) {
|
||||
$totals[$totalsId] = 0;
|
||||
}
|
||||
|
||||
$totals[$totalsId] += $day->getTotalDuration();
|
||||
$userYear['years'][$yearId]['months'][$monthId]['totalDuration'] += $day->getTotalDuration();;
|
||||
}
|
||||
$userYears[] = $userYear;
|
||||
}
|
||||
}
|
||||
$rows = $userYears;
|
||||
*/
|
||||
|
||||
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(),
|
||||
'rows' => $rows,
|
||||
'months' => $months,
|
||||
'totals' => $totals,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/monthly_users_list", name="report_monthly_users", methods={"GET","POST"})
|
||||
*
|
||||
@@ -89,11 +228,11 @@ final class ReportUsersListController extends AbstractController
|
||||
$end = clone $start;
|
||||
$end->modify('last day of 23:59:59');
|
||||
|
||||
$previousMonth = clone $start;
|
||||
$previousMonth->modify('-1 month');
|
||||
$previous = clone $start;
|
||||
$previous->modify('-1 month');
|
||||
|
||||
$nextMonth = clone $start;
|
||||
$nextMonth->modify('+1 month');
|
||||
$next = clone $start;
|
||||
$next->modify('+1 month');
|
||||
|
||||
foreach ($allUsers as $user) {
|
||||
$rows[] = [
|
||||
@@ -103,12 +242,22 @@ final class ReportUsersListController extends AbstractController
|
||||
}
|
||||
|
||||
$days = [];
|
||||
$totals = [];
|
||||
|
||||
if (isset($rows[0])) {
|
||||
/** @var Day $day */
|
||||
foreach ($rows[0]['days'] as $day) {
|
||||
$days[$day->getDay()->format('Ymd')] = $day->getDay();
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
foreach ($row['days'] as $day) {
|
||||
$totalsId = $day->getDay()->format('Ymd');
|
||||
if (!isset($totals[$totalsId])) {
|
||||
$totals[$totalsId] = 0;
|
||||
}
|
||||
$totals[$totalsId] += $day->getTotalDuration();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('reporting/report_user_list.html.twig', [
|
||||
@@ -117,9 +266,10 @@ final class ReportUsersListController extends AbstractController
|
||||
'form' => $form->createView(),
|
||||
'rows' => $rows,
|
||||
'days' => $days,
|
||||
'totals' => $totals,
|
||||
'current' => $start,
|
||||
'next' => $nextMonth,
|
||||
'previous' => $previousMonth,
|
||||
'next' => $next,
|
||||
'previous' => $previous,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -164,11 +314,11 @@ final class ReportUsersListController extends AbstractController
|
||||
$start = $dateTimeFactory->getStartOfWeek($values->getDate());
|
||||
$end = $dateTimeFactory->getEndOfWeek($values->getDate());
|
||||
|
||||
$previousWeek = clone $start;
|
||||
$previousWeek->modify('-1 week');
|
||||
$previous = clone $start;
|
||||
$previous->modify('-1 week');
|
||||
|
||||
$nextWeek = clone $start;
|
||||
$nextWeek->modify('+1 week');
|
||||
$next = clone $start;
|
||||
$next->modify('+1 week');
|
||||
|
||||
foreach ($allUsers as $user) {
|
||||
$rows[] = [
|
||||
@@ -178,12 +328,22 @@ final class ReportUsersListController extends AbstractController
|
||||
}
|
||||
|
||||
$days = [];
|
||||
$totals = [];
|
||||
|
||||
if (isset($rows[0])) {
|
||||
/** @var Day $day */
|
||||
foreach ($rows[0]['days'] as $day) {
|
||||
$days[$day->getDay()->format('Ymd')] = $day->getDay();
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
foreach ($row['days'] as $day) {
|
||||
$totalsId = $day->getDay()->format('Ymd');
|
||||
if (!isset($totals[$totalsId])) {
|
||||
$totals[$totalsId] = 0;
|
||||
}
|
||||
$totals[$totalsId] += $day->getTotalDuration();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('reporting/report_user_list.html.twig', [
|
||||
@@ -192,9 +352,10 @@ final class ReportUsersListController extends AbstractController
|
||||
'form' => $form->createView(),
|
||||
'rows' => $rows,
|
||||
'days' => $days,
|
||||
'totals' => $totals,
|
||||
'current' => $start,
|
||||
'next' => $nextWeek,
|
||||
'previous' => $previousWeek,
|
||||
'next' => $next,
|
||||
'previous' => $previous,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Form\Model\Configuration;
|
||||
use App\Form\Model\SystemConfiguration as SystemConfigurationModel;
|
||||
use App\Form\SystemConfigurationForm;
|
||||
use App\Form\Type\ArrayToCommaStringType;
|
||||
use App\Form\Type\DatePickerType;
|
||||
use App\Form\Type\DateTimeTextType;
|
||||
use App\Form\Type\DayTimeType;
|
||||
use App\Form\Type\LanguageType;
|
||||
@@ -507,6 +508,12 @@ final class SystemConfigurationController extends AbstractController
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setRequired(false)
|
||||
->setType(TextType::class),
|
||||
(new Configuration())
|
||||
->setName('company.financial_year')
|
||||
->setTranslationDomain('system-configuration')
|
||||
->setRequired(false)
|
||||
->setType(DatePickerType::class)
|
||||
->setOptions(['input' => 'string']),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user