src/Controller/ReportController.php line 47

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\EmployeeService;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. /**
  10.  * @Route("/report")
  11.  */
  12. class ReportController extends AbstractController
  13. {
  14.     private EmployeeService $employeeService;
  15.     public function __construct(EmployeeService $employeeService)
  16.     {
  17.         $this->employeeService $employeeService;
  18.     }
  19.     /**
  20.      * @Route("/daily", name="report_daily")
  21.      * @IsGranted("REPORT_DAILY")
  22.      */
  23.     public function daily(Request $request): Response
  24.     {
  25.         $date $request->get('date') ?? (new \DateTime())->format('d/m/Y');
  26.         $data $this->employeeService->getEmployeesHourLogReport($date$date);
  27.         return $this->render(
  28.             'report/daily.html.twig', [
  29.                 'data' => $data,
  30.                 'date' => $date,
  31.                 'title' => 'Rapport Journalier : ' $date,
  32.                 'menu' => 'report_daily'
  33.             ]
  34.         );
  35.     }
  36.     /**
  37.      * @Route("/custom_range", name="report_custom_range")
  38.      * @IsGranted("REPORT_CUSTOM_RANGE")
  39.      */
  40.     public function custom(Request $request): Response
  41.     {
  42.         $startDate $request->get('startDate') ?? (new \DateTime())->format('d/m/Y');
  43.         $endDate $request->get('endDate') ?? (new \DateTime())->format('d/m/Y');
  44.         $data $this->employeeService->getEmployeesHourLogReport($startDate$endDate);
  45.         return $this->render(
  46.             'report/custom.html.twig', [
  47.                 'data' => $data,
  48.                 'startDate' => $startDate,
  49.                 'endDate' => $endDate,
  50.                 'title' => sprintf('Rapport entre le %s et le %s'$startDate$endDate),
  51.                 'menu' => 'report_custom_range'
  52.             ]
  53.         );
  54.     }
  55.     /**
  56.      * @Route("/month", name="report_month")
  57.      * @IsGranted("REPORT_MONTH")
  58.      */
  59.     public function month(Request $request): Response
  60.     {
  61.         $years = [
  62.             '2021',
  63.             '2022',
  64.             '2023'
  65.         ];
  66.         $months = [
  67.             '01' => 'Janvier',
  68.             '02' => 'Février',
  69.             '03' => 'Mars',
  70.             '04' => 'Avril',
  71.             '05' => 'Mai',
  72.             '06' => 'Juin',
  73.             '07' => 'Juillet',
  74.             '08' => 'Août',
  75.             '09' => 'Septembre',
  76.             '10' => 'Octobre',
  77.             '11' => 'Novembre',
  78.             '12' => 'Décembre',
  79.         ];
  80.         $date = new \DateTime();
  81.         $month $request->get('month') ?? $date->format('m');
  82.         $year $request->get('year') ?? $date->format('Y');
  83.         //setting date
  84.         $date = new \DateTime();
  85.         $date->setDate($year$month1);
  86.         $startDate $date->format('d/m/Y');
  87.         $date->modify('last day of this month');
  88.         $endDate $date->format('d/m/Y');
  89.         $data $this->employeeService->getEmployeesHourLogReport($startDate$endDate);
  90.         return $this->render(
  91.             'report/month.html.twig', [
  92.                 'data' => $data,
  93.                 'startDate' => $startDate,
  94.                 'endDate' => $endDate,
  95.                 'title' => sprintf('Rapport entre le %s et le %s'$startDate$endDate),
  96.                 'menu' => 'report_month',
  97.                 'years' => $years,
  98.                 'months' => $months,
  99.                 'month' => $month,
  100.                 'year' => $year
  101.             ]
  102.         );
  103.     }
  104. }