src/Controller/JIT/DashboardController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller\JIT;
  3. use App\Common\Controller\DefaultController;
  4. use App\Entity\JIT\Person;
  5. use App\Entity\JIT\Property;
  6. use App\Entity\JIT\Search;
  7. use App\Form\JIT\PersonP2Type;
  8. use App\Form\JIT\PropertyPType;
  9. use App\Repository\JIT\MovementRepository;
  10. use App\Repository\JIT\PersonRepository;
  11. use App\Repository\JIT\PropertyRepository;
  12. use App\Service\Logger;
  13. use App\Service\Uploader\PersonIdentityUploader;
  14. use App\Service\Uploader\PictureUploader;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  16. use Symfony\Component\Form\Extension\Core\Type\DateType;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. /**
  22.  * @Route("/jit/dashboard")
  23.  */
  24. class DashboardController extends DefaultController {
  25.     protected $menu 10;
  26.     protected $limit 4;
  27.     /**
  28.      * @Route("/", name="pr_jit_dashboard_index", methods="GET")
  29.      * @Route("/", name="jit_index", methods="GET")
  30.      * 
  31.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  32.      */
  33.     public function index(): Response {
  34.         $cuser $this->getUser();
  35.         if($cuser->getPerson() === null && $cuser->isSelfOwner()){
  36.             return $this->redirectToRoute('pr_jit_dashboard_start1');
  37.         }
  38.         return $this->render('jit/dashboard/default.html.twig', [
  39.                     'menu' => $this->menu,
  40.         ]);
  41.     }
  42.     /**
  43.      * @Route("/proprietaire", name="pr_jit_dashboard2_index", methods="GET")
  44.      * 
  45.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  46.      */
  47.     public function index2(): Response {
  48.         $cuser $this->getUser();
  49.         if($cuser->getPerson() === null && $cuser->isSelfOwner()){
  50.             return $this->redirectToRoute('pr_jit_dashboard_start1');
  51.         }
  52.         return $this->render('jit/dashboard/proprietaire.html.twig', [
  53.                     'menu' => $this->menu,
  54.         ]);
  55.     }
  56.     /**
  57.      * @Route("/account", name="pr_jit_dashboard_account", methods="GET|POST")
  58.      * 
  59.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  60.      */
  61.     public function account(MovementRepository $mRepositoryRequest $request): Response {
  62.         // creates a task object and initializes some data for this example
  63.         $search = new Search();
  64.         $form $this->createFormBuilder($search)
  65.                 ->add('startDate'DateType::class, [
  66.                     'required' => false,
  67.                     'widget' => 'single_text',
  68.                 ])
  69.                 ->add('endDate'DateType::class, [
  70.                     'required' => false,
  71.                     'widget' => 'single_text',
  72.                 ])
  73.                 ->getForm();
  74.         $form->handleRequest($request);
  75.         $start null;
  76.         $end null;
  77.         if ($form->isSubmitted() && $form->isValid()) {
  78.             $start $search->getStartDate();
  79.             $end $search->getEndDate();
  80.         }
  81.         $accounts $this->getUser()->getAccounts();
  82.         $movements $mRepository->findByAccounts($accounts$start$end);
  83.         return $this->render('jit/dashboard/account.html.twig', [
  84.                     'menu' => $this->menu,
  85.                     'form' => $form->createView(),
  86.                     'movements' => $movements,
  87.         ]);
  88.     }
  89.     /**
  90.      * @Route("/property", name="pr_jit_dashboard_property", methods="GET|POST")
  91.      * 
  92.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  93.      */
  94.     public function property(TranslatorInterface $translator): Response {
  95.         return $this->render('jit/dashboard/property.html.twig', [
  96.                     'menu' => $this->menu,
  97.         ]);
  98.     }
  99.     /**
  100.      * @Route("/start", name="pr_jit_dashboard_start", methods="GET|POST")
  101.      * 
  102.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  103.      */
  104.     public function start(TranslatorInterface $translator): Response {
  105.         return $this->render('jit/dashboard/start.html.twig', [
  106.                     'menu' => $this->menu,
  107.         ]);
  108.     }
  109.     /**
  110.      * @Route("/document", name="pr_jit_dashboard_document", methods="GET|POST")
  111.      * 
  112.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  113.      */
  114.     public function document(TranslatorInterface $translator): Response {
  115.         return $this->render('jit/dashboard/document.html.twig', [
  116.                     'menu' => $this->menu,
  117.         ]);
  118.     }
  119.     /**
  120.      * @Route("/start1", name="pr_jit_dashboard_start1", methods="GET|POST")
  121.      * 
  122.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  123.      */
  124.     public function addPersonP(PersonRepository $repositoryRequest $requestPersonIdentityUploader $fileUploaderTranslatorInterface $translatorLogger $logger): Response {
  125.         
  126.         $cuser $this->getUser();
  127.         if($cuser->getPerson() !== null){
  128.             return $this->redirectToRoute('pr_jit_dashboard_index');
  129.         }
  130.         $person = new Person();
  131.         $person->setPfl(Person::PROFIL_PROPRITAIRE);
  132.         $person->setAccount($cuser);
  133.         $person->setFnm($cuser->getFullname());
  134.         $person->setEmail($cuser->getEmail());
  135.         $person->setTel1($cuser->getPhone());
  136.         $form $this->createForm(PersonP2Type::class, $person, ['user' => $cuser]);
  137.         $form->handleRequest($request);
  138.         if ($form->isSubmitted() && $form->isValid()) {
  139.             //Save Identity file
  140.             $file $person->getIFile();
  141.             if ($file) {
  142.                 $newFileName $fileUploader->upload($file);
  143.                 $person->setIdf($newFileName);
  144.             }
  145.             //Save Picture file
  146.             $pfile $person->getPFile();
  147.             if ($pfile) {
  148.                 $newFileName $fileUploader->upload($pfile);
  149.                 $person->setPicture($newFileName);
  150.             }
  151.             //Add User
  152.             if ($form->get('createUser')->getData()) {
  153.                 $person->createUser();
  154.             }
  155.             $repository->add($persontrue);
  156.             $logger->logging($this->getUser(), $personLogger::ACTION_ADD);
  157.             $this->addFlash('success'$translator->trans('tt_message.add_successfully'));
  158.             return $this->redirectToRoute('pr_jit_dashboard_start2');
  159.         } else {
  160.             $logger->logging($this->getUser(), $personLogger::ACTION_ADD_FORM);
  161.         }
  162.         return $this->render('jit/dashboard/start1.html.twig', [
  163.                     'our_form' => $form->createView(),
  164.                     'menu' => $this->menu,
  165.         ]);
  166.     }
  167.     /**
  168.      * @Route("/start2", name="pr_jit_dashboard_start2", methods="GET|POST")
  169.      * 
  170.      * @Security("is_granted('ROLE_JIT_DASHBOARD_INDEX')")
  171.      */
  172.     public function addProperty(PropertyRepository $repositoryPictureUploader $fileUploaderRequest $requestTranslatorInterface $translatorLogger $logger): Response {
  173.         $cuser $this->getUser();
  174.         $person $cuser->getPerson();
  175.         if($person === null || $cuser->isSelfOwner()){
  176.             return $this->redirectToRoute('pr_jit_dashboard_start1');
  177.         }
  178.         $property = new Property();
  179.         $property->setOwner($person);
  180.         $form $this->createForm(PropertyPType::class, $property, ['person' => $property->getOwner()]);
  181.         $form->handleRequest($request);
  182.         if ($form->isSubmitted() && $form->isValid()) {
  183.             //Save Pictures
  184.             $pictures $property->getPictures();
  185.             foreach ($pictures as $picture) {
  186.                 $file $picture->getImage();
  187.                 if ($file) {
  188.                     $newImg $fileUploader->upload($file);
  189.                     $picture->setImg($newImg);
  190.                     $logger->logging($this->getUser(), $pictureLogger::ACTION_ADD);
  191.                 }
  192.             }
  193.             $repository->add($propertytrue);
  194.             $logger->logging($this->getUser(), $propertyLogger::ACTION_ADD);
  195.             $this->addFlash('success'$translator->trans('tt_message.add_successfully'));
  196.             return $this->redirectToRoute('pr_jit_dashboard_index');
  197.         } else {
  198.             $logger->logging($this->getUser(), $propertyLogger::ACTION_ADD_FORM);
  199.         }
  200.         return $this->render('jit/dashboard/start2.html.twig', [
  201.                     'our_form' => $form->createView(),
  202.                     'menu' => $this->menu,
  203.         ]);
  204.     }
  205. }