* do not traverse into invoice template subdirectories (#3735) * fix security open api definition * fix currency can be null, removed fluent interface * merged release 1.30.3 * allow to pre-fill timesheet metafields via URL * fix api description * added test accounts with simpler names and password * upgrade to Symfony 6.2 * removed FrameworkExtraBundle (by Sensio) and replaced with new native SF annotations * fixed symfony 6.2 deprecations * fixed #3768
62 lines
2.4 KiB
PHP
62 lines
2.4 KiB
PHP
<?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\Form\Model\DateRange;
|
|
use App\Project\ProjectStatisticService;
|
|
use App\Reporting\ProjectDateRange\ProjectDateRangeForm;
|
|
use App\Reporting\ProjectDateRange\ProjectDateRangeQuery;
|
|
use Symfony\Component\ExpressionLanguage\Expression;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
final class ProjectDateRangeController extends AbstractController
|
|
{
|
|
#[Route(path: '/reporting/project_daterange', name: 'report_project_daterange', methods: ['GET', 'POST'])]
|
|
#[IsGranted('report:project')]
|
|
#[IsGranted(new Expression("is_granted('budget_any', 'project')"))]
|
|
public function __invoke(Request $request, ProjectStatisticService $service)
|
|
{
|
|
$dateFactory = $this->getDateTimeFactory();
|
|
$user = $this->getUser();
|
|
|
|
$query = new ProjectDaterangeQuery($dateFactory->getStartOfMonth(), $user);
|
|
$form = $this->createFormForGetRequest(ProjectDateRangeForm::class, $query, [
|
|
'timezone' => $user->getTimezone()
|
|
]);
|
|
$form->submit($request->query->all(), false);
|
|
|
|
$dateRange = new DateRange(true);
|
|
$dateRange->setBegin($query->getMonth());
|
|
$dateRange->setEnd($dateFactory->getEndOfMonth($dateRange->getBegin()));
|
|
|
|
$projects = $service->findProjectsForDateRange($query, $dateRange);
|
|
$entries = $service->getBudgetStatisticModelForProjectsByDateRange($projects, $dateRange->getBegin(), $dateRange->getEnd(), $dateRange->getEnd());
|
|
|
|
$byCustomer = [];
|
|
foreach ($entries as $entry) {
|
|
$customer = $entry->getProject()->getCustomer();
|
|
if (!isset($byCustomer[$customer->getId()])) {
|
|
$byCustomer[$customer->getId()] = ['customer' => $customer, 'projects' => []];
|
|
}
|
|
$byCustomer[$customer->getId()]['projects'][] = $entry;
|
|
}
|
|
|
|
return $this->render('reporting/project_daterange.html.twig', [
|
|
'report_title' => 'report_project_daterange',
|
|
'entries' => $byCustomer,
|
|
'form' => $form->createView(),
|
|
'queryEnd' => $dateRange->getEnd(),
|
|
]);
|
|
}
|
|
}
|