src/Controller/DashboardController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Dashboard;
  4. use App\Entity\Objectif;
  5. use App\Form\DashboardType;
  6. use App\Repository\LeadRepository;
  7. use App\Repository\ObjectifRepository;
  8. use App\Repository\UserRepository;
  9. use DateTime;
  10. use DateTimeImmutable;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. /**
  19.  *@Route("/performances")
  20.  */
  21. class DashboardController extends AbstractController
  22. {
  23.     public $em;
  24.     public function __construct(EntityManagerInterface $em)
  25.     {
  26.         $this->em $em;
  27.     }
  28.     private function compareDate($start$end$value)
  29.     {
  30.         return ($value >= $start && $value <= $end);
  31.     }
  32.     /**
  33.      *@Route("/", name="dashboard.index", methods={"GET", "POST"})
  34.      */
  35.     public function index(Request $requestEntityManagerInterface $entityManagerUserRepository $userRepository): Response
  36.     {
  37.         $filterDate true;
  38.         if ($request->query->get('start_date')) {
  39.             $filterDate true;
  40.             $date_start DateTime::createFromFormat('m-d-Y'$request->query->get('start_date'));
  41.             $date_start->setTime(00);
  42.         } else {
  43.             $date_start = new DateTime();
  44.             $date_start->setDate(date('Y'), date('m'), 1)->setTime(00);
  45.         }
  46.         if ($request->query->get('end_date')) {
  47.             $filterDate true;
  48.             $date_end DateTime::createFromFormat('m-d-Y'$request->query->get('end_date'));
  49.             $date_end->setTime(00)->modify("+1 days");
  50.         } else {
  51.             $date_end DateTime::createFromFormat('m-d-Y'date('m-d-Y'));
  52.             $date_end = new DateTime();
  53.             $date_end->setDate(date('Y'), date('m') + 11)->setTime(00);
  54.         }
  55.         if ($request->getSession()->get('userPossess') == 'all') {
  56.             $users $userRepository->getAllAgent($this->getUser()->getId());
  57.         } else {
  58.             $users[] = $userRepository->find($request->getSession()->get('userPossess')->getId());
  59.         }
  60.         $objectifs $users[0]->getObjectifs();
  61.         $objectif null;
  62.         if ($request->getSession()->get('userPossess') != "all") {
  63.             $nb_mandat_annuel_cumul 0;
  64.             $nb_rdv_annuel_cumul 0;
  65.             $ca_annuel_cumul 0;
  66.             $currentYear 0;
  67.             $avancement_terrain 0;
  68.             $avancement_reseau 0;
  69.             $avancement_digital 0;
  70.             $avancement_digital_payant 0;
  71.             foreach ($objectifs as $objectif) {
  72.                 if ($currentYear != $objectif->getCreatedAt()->format('Y')) {
  73.                     $currentYear $objectif->getCreatedAt()->format('Y');
  74.                     if ($currentYear >= $date_start->format('Y') && $currentYear <= $date_end->format('Y')) {
  75.                         $objectif $objectif->getObjectif();
  76.                         if ($objectif != null) {
  77.                             $nb_estimation ceil(($objectif['taux_conversion_rdv_to_mandat'] / 100) * $objectif['objectif']['vente_annuel']);
  78.                             $nb_contact_vendeur_acheteur = ($nb_estimation 8);
  79.                             $ca_annuel_cumul += $objectif['objectif']['ca_annuel'];
  80.                             $nb_mandat_annuel_cumul += $objectif['objectif']['vente_annuel'];
  81.                             $nb_rdv_annuel_cumul += $objectif['objectif']['nb_rdv_estimation_todo'];
  82.                             $avancement_terrain $this->progression('Actions_de_prospection_terrain');
  83.                             $avancement_reseau $this->progression('Actions_entretien_réseau');
  84.                             $avancement_digital $this->progression('Actions_digitales_gratuites');
  85.                             $avancement_digital_payant $this->progression('Actions_digitales_payantes');
  86.                         }
  87.                     }
  88.                 }
  89.             }
  90.         }
  91.         $tasks_late = [];
  92.         $tasks_todo = [];
  93.         $automatisation = [];
  94.         $mandats = [];
  95.         $rdvs = [];
  96.         $leads = [];
  97.         $leads_lost = [];
  98.         $ca_potentiel = [];
  99.         $ca_previsionnel = [];
  100.         $ca_genere = [];
  101.         $lead_entrant = [];
  102.         $all_lead = [];
  103.         $lead_seller = [];
  104.         $lead_buyer = [];
  105.         $lead_partner = [];
  106.         $all_lead_buyer = [];
  107.         $all_lead_seller = [];
  108.         $all_lead_partner = [];
  109.         foreach ($users as $user) {
  110.             /**
  111.              * Recherche des tâches en retard
  112.              */
  113.             foreach ($user->getTasksActor() as $task) {
  114.                 if ($filterDate) {
  115.                     if ($task->getArchive() == false || $task->getDateArchive() > $date_end) {
  116.                         if ($this->compareDate($date_start$date_end$task->getDueDate())) {
  117.                             $tasks_todo[] = $task;
  118.                         }
  119.                         if ($task->getDueDate() < $date_start) {
  120.                             $tasks_late[] = $task;
  121.                         }
  122.                     }
  123.                 } else {
  124.                     if ($task->getDueDate() <= new DateTime('now')) {
  125.                         $tasks_late[] = $task;
  126.                     } else {
  127.                         $tasks_todo[] = $task;
  128.                     }
  129.                 }
  130.             }
  131.             /**
  132.              * Récupération des leads de l'utilisateur
  133.              * Si l'argument "all" est passé, on récupère tout les leads qui ont l'id possessor = à l'id de l'utilisateur courant. (admin)
  134.              */
  135.             $lead $user->getLeads();
  136.             $lead_entrant $user->getLeadsByPossessor();
  137.             /**
  138.              * If empty pour éviter les doublons dans le cas du "all"
  139.              */
  140.             foreach ($lead as $l) {
  141.                 if ($l->getAutomatisation() == 1) {
  142.                     $automatisation[] = $l;
  143.                 }
  144.                 if ($l->getState() >= && $l->getState() <= && $l->isSeller()) {
  145.                     if ($filterDate) {
  146.                         if ($l->getMandat() != null && $this->compareDate($date_start$date_end, new DateTime($l->getMandat()[$l->getState()]['update_at']['date']))) {
  147.                             $mandats[] = $l;
  148.                             switch ($l->getState()) {
  149.                                 case 5:
  150.                                     $ca_potentiel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  151.                                     // $ca_previsionnel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  152.                                     break;
  153.                                 case 6:
  154.                                     // $ca_potentiel[] = $l->getMandat()[$l->getState()]['amount_property'] ?? 0;
  155.                                     $ca_previsionnel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  156.                                     break;
  157.                                 case 7:
  158.                                     // $ca_potentiel[] = $l->getMandat()[$l->getState()]['amount_property'] ?? 0;
  159.                                     // $ca_previsionnel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  160.                                     $ca_genere[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  161.                                     break;
  162.                             }
  163.                             if ($l->getState() >= && $l->getState() <= && $l->isSeller()) {
  164.                                 $rdvs[] = $l;
  165.                             }
  166.                         }
  167.                     } else {
  168.                         switch ($l->getState()) {
  169.                             case 5:
  170.                                 $ca_potentiel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  171.                                 // $ca_previsionnel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  172.                                 break;
  173.                             case 6:
  174.                                 // $ca_potentiel[] = $l->getMandat()[$l->getState()]['amount_property'] ?? 0;
  175.                                 $ca_previsionnel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  176.                                 break;
  177.                             case 7:
  178.                                 // $ca_potentiel[] = $l->getMandat()[$l->getState()]['amount_property'] ?? 0;
  179.                                 // $ca_previsionnel[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  180.                                 $ca_genere[] = $l->getMandat()[$l->getState()]['amount_fees'] ?? 0;
  181.                                 break;
  182.                         }
  183.                         if ($l->getState() >= && $l->getState() <= && $l->isSeller()) {
  184.                             $rdvs[] = $l;
  185.                         }
  186.                     }
  187.                 }
  188.                 if ($filterDate) {
  189.                     if ($this->compareDate($date_start$date_end$l->getCreatedAt())) {
  190.                         $leads[] = $l;
  191.                         if ($l->getIntention() == 0$lead_buyer[] = $l;
  192.                         if ($l->getIntention() == 1$lead_seller[] = $l;
  193.                         if ($l->getIntention() == 2$lead_partner[] = $l;
  194.                         if ($l->getState() == 9) {
  195.                             $leads_lost[] = $l;
  196.                         }
  197.                     }
  198.                 } else {
  199.                     $leads[] = $l;
  200.                     if ($l->getIntention() == 0$lead_buyer[] = $l;
  201.                     if ($l->getIntention() == 1$lead_seller[] = $l;
  202.                     if ($l->getIntention() == 2$lead_partner[] = $l;
  203.                     if ($l->getState() == 9) {
  204.                         $leads_lost[] = $l;
  205.                     }
  206.                 }
  207.             }
  208.         }
  209.         foreach ($lead_entrant as $le) {
  210.             if ($filterDate) {
  211.                 if ($this->compareDate($date_start$date_end$le->getCreatedAt())) {
  212.                     $all_lead[] = $le;
  213.                     if ($le->getIntention() == 0$all_lead_buyer[] = $le;
  214.                     if ($le->getIntention() == 1$all_lead_seller[] = $le;
  215.                     if ($le->getIntention() == 2$all_lead_partner[] = $le;
  216.                 }
  217.             } else {
  218.                 $all_lead[] = $le;
  219.                 if ($le->getIntention() == 0$all_lead_buyer[] = $le;
  220.                 if ($le->getIntention() == 1$all_lead_seller[] = $le;
  221.                 if ($le->getIntention() == 2$all_lead_partner[] = $le;
  222.             }
  223.         }
  224.         $paramsRender =  [
  225.             'ca_potentiel' => array_sum($ca_potentiel),
  226.             'ca_previsionnel' => array_sum($ca_previsionnel),
  227.             'ca_genere' => array_sum($ca_genere),
  228.             'current_page' => 'home',
  229.             'tasks_late' => count($tasks_late),
  230.             'tasks_todo' => count($tasks_todo),
  231.             'automatisation' => count($automatisation),
  232.             'mandats' => count($mandats),
  233.             'rdvs' => count($rdvs),
  234.             'leads' => count($leads),
  235.             'all_lead' => count($all_lead),
  236.             'leads_lost' => count($leads_lost),
  237.             'lead_buyer' => count($lead_buyer),
  238.             'lead_seller' => count($lead_seller),
  239.             'lead_partner' => count($lead_partner),
  240.             'all_lead_buyer' => count($all_lead_buyer),
  241.             'all_lead_seller' => count($all_lead_seller),
  242.             'all_lead_partner' => count($all_lead_partner),
  243.         ];
  244.         if ($objectif != null) {
  245.             $paramsRender['avancement_terrain'] = $avancement_terrain;
  246.             $paramsRender['avancement_reseau'] = $avancement_reseau;
  247.             $paramsRender['avancement_digital'] = $avancement_digital;
  248.             $paramsRender['avancement_digital_payant'] = $avancement_digital_payant;
  249.             // $paramsRender['nb_contact_todo'] = $nb_contact_vendeur_acheteur; // Pas utilisé
  250.             // $paramsRender['objectifs'] = $objectif['objectif']; // à enlever
  251.             $paramsRender['ca_annuel_cumul'] = $ca_annuel_cumul;
  252.             $paramsRender['nb_mandat_annuel_cumul'] = $nb_mandat_annuel_cumul;
  253.             $paramsRender['nb_rdv_annuel_cumul'] = $nb_rdv_annuel_cumul;
  254.         }
  255.         if ($request->isXmlHttpRequest()) {
  256.             return new JsonResponse([
  257.                 'perf' => $this->renderView('dashboard/perf.html.twig'$paramsRender),
  258.             ]);
  259.         }
  260.         return $this->render('dashboard/index.html.twig'$paramsRender);
  261.     }
  262.     private function progression($action)
  263.     {
  264.         $currentValue 0;
  265.         $maxValue 0;
  266.         $plans $this->getUser()->getObjectifs()[0]->getPlans();
  267.         for ($i 0$i count($plans[$action]) - 1$i++) {
  268.             if (isset($plans[$action][$i]['missions'])) {
  269.                 for ($j 0$j count($plans[$action][$i]['missions']) - 1$j++) {
  270.                     $currentValue += $plans[$action][$i]['missions'][$j]['value'];
  271.                     $maxValue += $plans[$action][$i]['missions'][$j]['value_max'];
  272.                 }
  273.             } else {
  274.                 $currentValue += $plans[$action][$i]['value'];
  275.                 $maxValue += $plans[$action][$i]['value_max'];
  276.             }
  277.         }
  278.         return ceil(($currentValue 100) / $maxValue);
  279.     }
  280.     /**
  281.      *@Route("/actions/", name="dashboard.actions", methods={"GET"})
  282.      */
  283.     public function actions(Request $request)
  284.     {
  285.         $objectif $this->getUser()->getObjectifs()[0];
  286.         if ($objectif == null) {
  287.             return $this->redirectToRoute('objectif.index', [], Response::HTTP_SEE_OTHER);
  288.         }
  289.         $objectif $objectif->getObjectif();
  290.         if ($objectif != null) {
  291.             $nb_estimation ceil(($objectif['taux_conversion_rdv_to_mandat'] / 100) * $objectif['objectif']['vente_annuel']);
  292.             $nb_contact_vendeur_acheteur = ($nb_estimation 8);
  293.             $avancement_terrain $this->progression('Actions_de_prospection_terrain');
  294.             $avancement_reseau $this->progression('Actions_entretien_réseau');
  295.             $avancement_digital $this->progression('Actions_digitales_gratuites');
  296.             $avancement_digital_payant $this->progression('Actions_digitales_payantes');
  297.         }
  298.         // if ($request->isXmlHttpRequest()) {
  299.         //     return $content;
  300.         // }
  301.         return $this->render(
  302.             'dashboard/plan_actions.html.twig',
  303.             [
  304.                 'current_page' => 'actions',
  305.                 'avancement_terrain' => $avancement_terrain,
  306.                 'avancement_reseau' => $avancement_reseau,
  307.                 'avancement_digital' => $avancement_digital,
  308.                 'avancement_digital_payant' => $avancement_digital_payant,
  309.             ]
  310.         );
  311.     }
  312.     /**
  313.      *@Route("/action", name="dashboard.action", methods={"GET"})
  314.      */
  315.     public function action(Request $request)
  316.     {
  317.         $objectifs $this->getUser()->getObjectifs()[0];
  318.         if ($objectifs == null) {
  319.             return $this->redirectToRoute('objectif.index', [], Response::HTTP_SEE_OTHER);
  320.         }
  321.         if ($request->isXmlHttpRequest()) {
  322.             return new JsonResponse([
  323.                 'action' => $this->renderView('dashboard/action_terrain.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_de_prospection_terrain']]),
  324.                 'title' => 'Actions prospection terrain',
  325.             ]);
  326.         }
  327.         return $this->render(
  328.             'dashboard/actions.html.twig',
  329.             [
  330.                 'current_page' => 'actions',
  331.                 'title' => 'Actions prospection terrain',
  332.                 'data' => $this->renderView('dashboard/action_terrain.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_de_prospection_terrain']])
  333.             ]
  334.         );
  335.     }
  336.     /**
  337.      *@Route("/action/action-terrain", name="dashboard.action_terrain", methods={"GET"})
  338.      */
  339.     public function action_terrain(Request $request)
  340.     {
  341.         $objectifs $this->getUser()->getObjectifs()[0];
  342.         if ($objectifs == null) {
  343.             return $this->redirectToRoute('objectif.index', [], Response::HTTP_SEE_OTHER);
  344.         }
  345.         if ($request->isXmlHttpRequest()) {
  346.             return new JsonResponse([
  347.                 'action' => $this->renderView('dashboard/action_terrain.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_de_prospection_terrain']]),
  348.                 'title' => 'Actions prospection terrain',
  349.             ]);
  350.         }
  351.         return $this->render(
  352.             'dashboard/actions.html.twig',
  353.             [
  354.                 'current_page' => 'actions',
  355.                 'title' => 'Actions prospection terrain',
  356.                 'data' => $this->renderView('dashboard/action_terrain.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_de_prospection_terrain']])
  357.             ]
  358.         );
  359.     }
  360.     /**
  361.      *@Route("/action/action-entretien-reseau", name="dashboard.action_entretien_reseau", methods={"GET"})
  362.      */
  363.     public function action_entretien_reseau(Request $request)
  364.     {
  365.         $objectifs $this->getUser()->getObjectifs()[0];
  366.         if ($objectifs == null) {
  367.             return $this->redirectToRoute('objectif.index', [], Response::HTTP_SEE_OTHER);
  368.         }
  369.         if ($request->isXmlHttpRequest()) {
  370.             return new JsonResponse([
  371.                 'action' => $this->renderView('dashboard/action_entretien_reseau.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_entretien_réseau']]),
  372.                 'title' => 'Actions entretien réseau',
  373.             ]);
  374.         }
  375.         return $this->render(
  376.             'dashboard/actions.html.twig',
  377.             [
  378.                 'current_page' => 'actions',
  379.                 'title' => 'Actions entretien réseau',
  380.                 'data' => $this->renderView('dashboard/action_entretien_reseau.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_entretien_réseau']])
  381.             ]
  382.         );
  383.     }
  384.     /**
  385.      *@Route("/action/action-prospection-digital", name="dashboard.action_prospection_digital", methods={"GET"})
  386.      */
  387.     public function action_prospection_digital(Request $request)
  388.     {
  389.         $objectifs $this->getUser()->getObjectifs()[0];
  390.         if ($objectifs == null) {
  391.             return $this->redirectToRoute('objectif.index', [], Response::HTTP_SEE_OTHER);
  392.         }
  393.         if ($request->isXmlHttpRequest()) {
  394.             return new JsonResponse([
  395.                 'action' => $this->renderView('dashboard/action_prospection_digital.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_digitales_gratuites']]),
  396.                 'title' => 'Actions prospection digital',
  397.             ]);
  398.         }
  399.         return $this->render(
  400.             'dashboard/actions.html.twig',
  401.             [
  402.                 'current_page' => 'actions',
  403.                 'title' => 'Actions prospection digital',
  404.                 'data' => $this->renderView('dashboard/action_prospection_digital.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_digitales_gratuites']])
  405.             ]
  406.         );
  407.     }
  408.     /**
  409.      *@Route("/action/action-prospection-digital-payante", name="dashboard.action_prospection_digital_payante", methods={"GET"})
  410.      */
  411.     public function action_prospection_digital_payante(Request $request)
  412.     {
  413.         $objectifs $this->getUser()->getObjectifs()[0];
  414.         if ($request->isXmlHttpRequest()) {
  415.             return new JsonResponse([
  416.                 'action' => $this->renderView('dashboard/action_prospection_digital_payante.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_digitales_payantes']]),
  417.                 'title' => 'Actions prospection digital payante',
  418.             ]);
  419.         }
  420.         return $this->render(
  421.             'dashboard/actions.html.twig',
  422.             [
  423.                 'current_page' => 'actions',
  424.                 'title' => 'Actions prospection digital payante',
  425.                 'data' => $this->renderView('dashboard/action_prospection_digital_payante.html.twig', ['current_page' => 'actions''data' => $objectifs->getPlans()['Actions_digitales_payantes']])
  426.             ]
  427.         );
  428.     }
  429.     /**
  430.      *@Route("/update-action", name="dashboard.update_action", methods={"POST"})
  431.      */
  432.     public function update_action(Request $requestEntityManagerInterface $em)
  433.     {
  434.         $objectifs $this->getUser()->getObjectifs()[0];
  435.         $actions $objectifs->getPlans();
  436.         for ($i 0$i count($actions[$request->request->get('action_name')]) - 1$i++) {
  437.             if ($request->request->get('submission_name') != '') {
  438.                 for ($j 0$j count($actions[$request->request->get('action_name')][$i]['missions']); $j++) {
  439.                     if ($actions[$request->request->get('action_name')][$i]['missions'][$j]['name'] == $request->request->get('submission_name')) {
  440.                         $actions[$request->request->get('action_name')][$i]['missions'][$j]['value'] = $request->request->get('value');
  441.                         break;
  442.                     }
  443.                 }
  444.             } else {
  445.                 if ($actions[$request->request->get('action_name')][$i]['name'] == $request->request->get('mission_name')) {
  446.                     $actions[$request->request->get('action_name')][$i]['value'] = $request->request->get('value');
  447.                     break;
  448.                 }
  449.             }
  450.         }
  451.         $objectifs->setPlans($actions);
  452.         $em->flush($objectifs);
  453.         if ($request->isXmlHttpRequest()) {
  454.             return new JsonResponse(true);
  455.         }
  456.     }
  457.     /**
  458.      *@Route("/comparaison", name="dashboard.compare", methods={"GET", "POST"})
  459.      */
  460.     public function compare(Request $requestObjectifRepository $objectifRepository)
  461.     {
  462.         return $this->comparaison($request$objectifRepository'Actions_de_prospection_terrain''compare_action_terrain');
  463.     }
  464.     /**
  465.      *@Route("/comparaison/action-terrain", name="dashboard.compare_action_terrain", methods={"GET"})
  466.      */
  467.     public function compare_action_terrain(Request $requestObjectifRepository $objectifRepository)
  468.     {
  469.         return $this->comparaison($request$objectifRepository'Actions_de_prospection_terrain''compare_action_terrain');
  470.     }
  471.     /**
  472.      *@Route("/comparaison/action-entretien-reseau", name="dashboard.compare_action_entretien_reseau", methods={"GET"})
  473.      */
  474.     public function compare_action_entretien_reseau(Request $requestObjectifRepository $objectifRepository)
  475.     {
  476.         return $this->comparaison($request$objectifRepository'Actions_entretien_réseau''compare_action_entretien_reseau');
  477.     }
  478.     /**
  479.      *@Route("/comparaison/action-prospection-digital", name="dashboard.compare_action_prospection_digital", methods={"GET"})
  480.      */
  481.     public function compare_action_prospection_digital(Request $requestObjectifRepository $objectifRepository)
  482.     {
  483.         return $this->comparaison($request$objectifRepository'Actions_digitales_gratuites''compare_action_prospection_digital');
  484.     }
  485.     /**
  486.      *@Route("/comparaison/action-prospection-digital-payantes", name="dashboard.compare_action_prospection_digital_payantes", methods={"GET"})
  487.      */
  488.     public function compare_action_prospection_digital_payantes(Request $requestObjectifRepository $objectifRepository)
  489.     {
  490.         return $this->comparaison($request$objectifRepository'Actions_digitales_payantes''compare_action_prospection_digital_payante');
  491.     }
  492.     private function comparaison(Request $requestObjectifRepository $objectifRepositorystring $actionstring $template)
  493.     {
  494.         foreach ($this->getUser()->getObjectifs() as $objectif) {
  495.             $selectObjectif[$objectif->getId()] = $objectif->getCreatedAt();
  496.         }
  497.         if ($request->query->get('dateSelect') || $request->query->get('dateSelect2')) {
  498.             $objectifs =  $objectifRepository->find($request->query->get('dateSelect'));
  499.             if (empty($objectifs) || $objectifs->getUser() != $this->getUser()) $objectifs $this->getUser()->getObjectifs()[0];
  500.             $objectifs2 =  $objectifRepository->find($request->query->get('dateSelect2'));
  501.             if (empty($objectifs2) || $objectifs2->getUser() != $this->getUser()) $objectifs2 $this->getUser()->getObjectifs()[1];
  502.         } else {
  503.             $objectifs $this->getUser()->getObjectifs()[0];
  504.             $objectifs2 $this->getUser()->getObjectifs()[1];
  505.         }
  506.         if ($objectifs == null) {
  507.             return $this->redirectToRoute('objectif.index', [], Response::HTTP_SEE_OTHER);
  508.         }
  509.         if ($objectifs2 == null) {
  510.             $objectifs2 $objectifs;
  511.         }
  512.         $date1 $objectifs->getId();
  513.         $date2 $objectifs2->getId();
  514.         if ($request->isXmlHttpRequest()) {
  515.             return new JsonResponse([
  516.                 'action' => $this->renderView('dashboard/' $template '.html.twig', ['current_page' => 'compare''data' => $objectifs->getPlans()[$action], 'data2' => $objectifs2->getPlans()[$action]]),
  517.                 'title' => str_replace('_'' '$action),
  518.             ]);
  519.         }
  520.         return $this->render(
  521.             'dashboard/compares.html.twig',
  522.             [
  523.                 'date1' => $date1,
  524.                 'date2' => $date2,
  525.                 'selectDate' => $selectObjectif,
  526.                 'current_page' => 'compare',
  527.                 'title' => str_replace('_'' '$action),
  528.                 'data' => $this->renderView('dashboard/' $template '.html.twig', ['current_page' => 'compare''data' => $objectifs->getPlans()[$action], 'data2' => $objectifs2->getPlans()[$action]])
  529.             ]
  530.         );
  531.     }
  532.     /**
  533.      *@Route("/comparaison/contact-evolution", name="dashboard.contact_evolution", methods={"GET"})
  534.      */
  535.     public function contact_evolution(Request $requestLeadRepository $leadRepositoryObjectifRepository $objectifRepository)
  536.     {
  537.         $monthFr = ['janvier''février''mars''avril''mai''juin''juillet''août''septembre''octobre''novembre''décembre'];
  538.         $monthEn = ['January''February''March''April''May''June''July''August''September''October''November''December'];
  539.         $year1 = new DateTimeImmutable("now");
  540.         $year1 $year1->setDate(date('Y'), 11);
  541.         $year1 $year1->setTimestamp(strtotime('-3 month'$year1->getTimestamp()));
  542.         $year1 = new DateTimeImmutable($year1->format('d-m-Y'));
  543.         $year1->setTime(000);
  544.         $year2 = new DateTimeImmutable("now");
  545.         $year2 $year2->setDate(date('Y'), 1231)->setTime(235959);
  546.         $leads_unfiltered $leadRepository->findLeadsBetweenDate($year1$year2$this->getUser());
  547.         $leads = [];
  548.         $mois $year1->format('m');
  549.         $annee $year1->format('Y');
  550.         for ($i 0$i 15$i++) {
  551.             if ($mois 12) {
  552.                 $mois 1;
  553.                 $annee += 1;
  554.             }
  555.             $leads['achat'][$monthFr[$mois 1] . ' ' $annee] = 0;
  556.             $leads['vente'][$monthFr[$mois 1] . ' ' $annee] = 0;
  557.             $leads['partenaire'][$monthFr[$mois 1] . ' ' $annee] = 0;
  558.             $leads['n/a'][$monthFr[$mois 1] . ' ' $annee] = 0;
  559.             $mois++;
  560.         }
  561.         foreach ($leads_unfiltered as $lead) {
  562.             $month $monthFr[array_search($lead->getCreatedAt()->format('F'), $monthEn)] . ' ' $lead->getCreatedAt()->format('Y');
  563.             if ($lead->getIntention() === 0$leads['achat'][$month] = $leads['achat'][$month] + 1;
  564.             elseif ($lead->getIntention() == 1$leads['vente'][$month] = $leads['vente'][$month] + 1;
  565.             elseif ($lead->getIntention() == 2$leads['partenaire'][$month] = $leads['partenaire'][$month] + 1;
  566.             else $leads['n/a'][$month] = $leads['n/a'][$month] + 1;
  567.         }
  568.         foreach ($this->getUser()->getObjectifs() as $objectif) {
  569.             $selectObjectif[$objectif->getId()] = $objectif->getCreatedAt();
  570.         }
  571.         if ($request->query->get('dateSelect') || $request->query->get('dateSelect2')) {
  572.             $objectifs =  $objectifRepository->find($request->query->get('dateSelect'));
  573.             if (empty($objectifs) || $objectifs->getUser() != $this->getUser()) $objectifs $this->getUser()->getObjectifs()[0];
  574.             $objectifs2 =  $objectifRepository->find($request->query->get('dateSelect2'));
  575.             if (empty($objectifs2) || $objectifs2->getUser() != $this->getUser()) $objectifs2 $this->getUser()->getObjectifs()[1];
  576.         } else {
  577.             $objectifs $this->getUser()->getObjectifs()[0];
  578.             $objectifs2 $this->getUser()->getObjectifs()[1];
  579.         }
  580.         $date1 $objectifs->getId();
  581.         $date2 $objectifs2->getId();
  582.         if ($request->isXmlHttpRequest()) {
  583.             return new JsonResponse([
  584.                 'action' => $this->renderView('dashboard/contact-evolution.html.twig', ['current_page' => 'compare''data' => $leads]),
  585.                 'title' => 'Evolution nouveaux contacts',
  586.             ]);
  587.         }
  588.         return $this->render(
  589.             'dashboard/compares.html.twig',
  590.             [
  591.                 'date1' => $date1,
  592.                 'date2' => $date2,
  593.                 'selectDate' => $selectObjectif,
  594.                 'current_page' => 'compare',
  595.                 'title' => 'Evolution nouveaux contacts',
  596.                 'data' => $this->renderView('dashboard/contact-evolution.html.twig', ['current_page' => 'compare''data' => $leads])
  597.             ]
  598.         );
  599.     }
  600.     /**
  601.      *@Route("/comparaison/rdv-mandat-evolution", name="dashboard.rdv_mandat_evolution", methods={"GET"})
  602.      */
  603.     public function rdv_mandat_evolution(Request $requestLeadRepository $leadRepositoryObjectifRepository $objectifRepository)
  604.     {
  605.         $monthFr = ['janvier''février''mars''avril''mai''juin''juillet''août''septembre''octobre''novembre''décembre'];
  606.         $monthEn = ['January''February''March''April''May''June''July''August''September''October''November''December'];
  607.         $year1 = new DateTimeImmutable("now");
  608.         $year1 $year1->setDate(date('Y'), 11);
  609.         $year1 $year1->setTimestamp(strtotime('-3 month'$year1->getTimestamp()));
  610.         $year1 = new DateTimeImmutable($year1->format('d-m-Y'));
  611.         $year1->setTime(000);
  612.         $year2 = new DateTimeImmutable("now");
  613.         $year2 $year2->setDate(date('Y'), 1231)->setTime(235959);
  614.         $leads_unfiltered $leadRepository->findLeadsWithMandat($this->getUser());
  615.         $leads = [];
  616.         $mois $year1->format('m');
  617.         $annee $year1->format('Y');
  618.         for ($i 0$i 15$i++) {
  619.             if ($mois 12) {
  620.                 $mois 1;
  621.                 $annee += 1;
  622.             }
  623.             $leads['nb_rdv_estimation'][$monthFr[$mois 1] . ' ' $annee] = 0;
  624.             $objectif $objectifRepository->findByDate(date('Y-m-d'strtotime($annee.'-'.$mois.'-01')), $this->getUser());
  625.             if(!empty($objectif)){
  626.                 $leads['nb_rdv_objectif'][$monthFr[$mois 1] . ' ' $annee] = ceil($objectif[0]->getObjectif()['objectif']['nb_rdv_estimation_todo'] / 12);
  627.             }else{
  628.                 $leads['nb_rdv_objectif'][$monthFr[$mois 1] . ' ' $annee] = [];
  629.             }
  630.             $leads['mandat_signe'][$monthFr[$mois 1] . ' ' $annee] = 0;
  631.             if(!empty($objectif)){
  632.                 $leads['mandat_objectif'][$monthFr[$mois 1] . ' ' $annee] = ceil(($objectif[0]->getObjectif()['objectif']['nb_unite_todo'] / 2) / 12);
  633.             }else{
  634.                 $leads['mandat_objectif'][$monthFr[$mois 1] . ' ' $annee] = [];
  635.             }
  636.             $mois++;
  637.         }
  638.         foreach($leads_unfiltered as $lead){
  639.             $mandat $lead->getMandat();
  640.             $month $monthFr[array_search(date('F'strtotime($mandat[$lead->getState()]['update_at']['date'])), $monthEn)] . ' ' date('Y'strtotime($mandat[$lead->getState()]['update_at']['date']));
  641.             if ($lead->getState() >= && $lead->getState() <= && $lead->isSeller()) {
  642.                 // RENDEZ VOUS
  643.                 $leads['nb_rdv_estimation'][$month] += 1;
  644.             }
  645.             if ($lead->getState() >= && $lead->getState() <= && $lead->isSeller()) {
  646.                 // MANDATS
  647.                 $leads['mandat_signe'][$month] += 1;
  648.             }
  649.         }
  650.         foreach ($this->getUser()->getObjectifs() as $objectif) {
  651.             $selectObjectif[$objectif->getId()] = $objectif->getCreatedAt();
  652.         }
  653.         if ($request->query->get('dateSelect') || $request->query->get('dateSelect2')) {
  654.             $objectifs =  $objectifRepository->find($request->query->get('dateSelect'));
  655.             if (empty($objectifs) || $objectifs->getUser() != $this->getUser()) $objectifs $this->getUser()->getObjectifs()[0];
  656.             $objectifs2 =  $objectifRepository->find($request->query->get('dateSelect2'));
  657.             if (empty($objectifs2) || $objectifs2->getUser() != $this->getUser()) $objectifs2 $this->getUser()->getObjectifs()[1];
  658.         } else {
  659.             $objectifs $this->getUser()->getObjectifs()[0];
  660.             $objectifs2 $this->getUser()->getObjectifs()[1];
  661.         }
  662.         $date1 $objectifs->getId();
  663.         $date2 $objectifs2->getId();
  664.         if ($request->isXmlHttpRequest()) {
  665.             return new JsonResponse([
  666.                 'action' => $this->renderView('dashboard/contact-rdv-mandat.html.twig', ['current_page' => 'compare''data' => $leads]),
  667.                 'title' => 'Evolution prise de rendez-vous et mandat',
  668.             ]);
  669.         }
  670.         return $this->render(
  671.             'dashboard/compares.html.twig',
  672.             [
  673.                 'date1' => $date1,
  674.                 'date2' => $date2,
  675.                 'selectDate' => $selectObjectif,
  676.                 'current_page' => 'compare',
  677.                 'title' => 'Evolution prise de rendez-vous et mandat',
  678.                 'data' => $this->renderView('dashboard/contact-rdv-mandat.html.twig', ['current_page' => 'compare''data' => $leads])
  679.             ]
  680.         );
  681.     }
  682. }