<?php
namespace App\Controller;
use App\Query\TaskQuery;
use App\Query\UserQuery;
use App\Repository\TasksRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
class IndexController extends AbstractController
{
/**
* @Route("/", name="app_index")
*/
public function index(
TaskQuery $taskQuery,
Request $request
): Response
{
$defaultDateFrom = (new \DateTime())->format('01/01/Y');
$session = $request->getSession();
if ($request->isXmlHttpRequest()) {
if ($request->isMethod('POST')) {
$session->set('dateFrom', $request->request->get('dateFrom'));
$session->set('dateTo', $request->request->get('dateTo'));
}
$params = [
'dateFrom' => $session->get('dateFrom', $defaultDateFrom),
'dateTo' => $session->get('dateTo'),
];
$data = $taskQuery->generateTaskByUser($params);
dump($data);
// PCZ
return $this->json([
'data' => array_values($data['tasks']),
'totalJh' => $data['totalJh'],
'totalcoutJh' => $this->renderView('index/_filter_currency.html.twig', ['price' => $data['totalcoutJh']]),
'totalcoutTasks' => $this->renderView('index/_filter_currency.html.twig', ['price' => $data['totalcoutTasks']]),
//'totalcoutJhVente' => $this->renderView('index/_filter_currency.html.twig', ['price' => $data['totalcoutJhVente']]),
'totalcoutTasksVente' => $this->renderView('index/_filter_currency.html.twig', ['price' => $data['totalcoutTasksVente']]),
]);
}
$params = [
'dateFrom' => $session->get('dateFrom', $defaultDateFrom),
'dateTo' => $session->get('dateTo'),
];
return $this->render('index/index.html.twig', [
'data' => [],
'params' => $params
]);
}
/**
* @Route("/suivi", name="app_follow_up")
*/
public function followUp(
TaskQuery $taskQuery,
Request $request
): Response
{
$defaultDateFrom = (new \DateTime())->format('01/01/Y');
$session = $request->getSession();
if ($request->isMethod('POST')) {
$session->set('dateFrom', $request->request->get('dateFrom'));
$session->set('dateTo', $request->request->get('dateTo'));
}
$params = [
'dateFrom' => $session->get('dateFrom', $defaultDateFrom),
'dateTo' => $session->get('dateTo'),
];
return $this->render('index/follow-up.html.twig', [
'data' => $taskQuery->generateTaskByProduct($params),
'colors' => $taskQuery->getColor(),
'params' => $params
]);
}
}