src/Controller/Kanban/AffaireController.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Kanban;
  3. use App\Entity\Clients\Client;
  4. use App\Entity\Kanban\Colonne;
  5. use App\Entity\Kanban\Fiche;
  6. use App\Entity\Notes\Categorie;
  7. use App\Entity\Notes\Note;
  8. use App\Entity\Projets\ProjetUtilisateur;
  9. use App\Entity\Utilisateur\Contact;
  10. use App\Library\Datatable\Util\Datatable;
  11. use App\Security\Voter\EntityVoter;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Component\Validator\Validator\ValidatorInterface;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. class AffaireController extends AbstractController
  21. {
  22.     /**
  23.      * @Route("/tunnels/affaire/modifier-contact/{id}/{contact}", name="dtc_kanban_fiche_contact_changer")
  24.      */
  25.     public function changeContactAction(Request $requestFiche $ficheContact $contact nullEntityManagerInterface $em)
  26.     {
  27.         if (is_object($contact)) {
  28.             $fiche->setContact($contact);
  29.         } else {
  30.             $fiche->setContact(null);
  31.         }
  32.         $em->persist($fiche);
  33.         $em->flush();
  34.         $headers = [
  35.             'Content-Type'                 => 'application/json',
  36.             'Access-Control-Allow-Origin'  => '*',
  37.             'Access-Control-Allow-Methods' => 'POST',
  38.         ];
  39.         return new JsonResponse(['data' => '1']);
  40.     }
  41.     /**
  42.      * @Route("/tunnels/affaire/afficher/{id}", name="dtc_kanban_affaire_fiche")
  43.      */
  44.     public function afficherAction(Request $requestFiche $ficheEntityManagerInterface $em)
  45.     {
  46.         $user          $this->getUser();
  47.         //$droit = $this->isGranted(EntityVoter::SHOW, "DTCKanbanBundle:Fiche");
  48.         $droit false;
  49.         if (is_object($user->getType()) and ($user->getType()->getId() != "1" and $user->getType()->getId() != "2")) {
  50.             if ($fiche->getUtilisateur()->getId() == $user->getId()) {
  51.                 $droit true;
  52.             } else {
  53.                 //$repo_equipe = $em->getRepository('DTCKanbanBundle:Equipe');
  54.                 $repo_equipe  $em->getRepository(ProjetUtilisateur::class);
  55.                 $equipier_obj $repo_equipe->findOneBy(["fiche" => $fiche"utilisateur" => $user]);
  56.                 if (is_object($equipier_obj)) {
  57.                     $droit true;
  58.                 }
  59.             }
  60.         } else {
  61.             $droit true;
  62.         }
  63.         if ( ! $droit) {
  64.             $referer    $request->headers->get('referer');
  65.             $currentUrl $request->getUri();
  66.             $this->addFlash('warning''Accès non autorisé');
  67.             if ($referer != "" && $referer != $currentUrl) {
  68.                 return $this->redirect($referer);
  69.             } else {
  70.                 return $this->redirectToRoute('dtcfo_homepage', []);
  71.             }
  72.         }
  73.         $titre_construit " ";
  74.         $adresseMail     "";
  75.         $telephone       "";
  76.         if ($fiche->getBudget() != "") {
  77.             $titre_construit .= "&nbsp;/ ".number_format($fiche->getBudget(), 2','' ')."&euro; ";
  78.         }
  79.         if (is_object($fiche->getClient())) {
  80.             $titre_construit .= "<div class='gauche' style='_font-size:12px;margin-left:10px;'>".$fiche->getClient()->getNom()."</div>";
  81.             if ($fiche->getClient()->getEmail() != "") {
  82.                 $titre_construit .= "<div class='gauche' style='_font-size:12px;margin-left:10px;'><a href='mailto:".$fiche->getClient()->getEmail()."'>".$fiche->getClient()->getEmail(
  83.                     )."</a></div>";
  84.             }
  85.             if ($fiche->getClient()->getTelephone() != "") {
  86.                 $titre_construit .= "<div class='gauche' style='_font-size:12px;margin-left:10px;'><a href='phone:".$fiche->getClient()->getTelephone()."'>".$fiche->getClient(
  87.                     )->getTelephone()."</a></div>";
  88.             }
  89.         }
  90.         $titre_modal "<div class='gauche' style=''>".$fiche->getLibelle()." : </div>".$titre_construit;
  91.         $titre_modal $fiche->getLibelle();
  92.         $errors      "";
  93.         $parent      "";
  94.         $url         "";
  95.         //$fichier->setVersion("1");
  96.         $repo_notes    $em->getRepository(Note::class);
  97.         $repo_colonnes $em->getRepository(Colonne::class);
  98.         $repo_contact  $em->getRepository(Contact::class);
  99.         $contactDefaut "";
  100.         if (is_object($fiche->getContact())) {
  101.             $contactDefaut $fiche->getContact();
  102.         } elseif (is_object($fiche->getClient())) {
  103.             $contactDefaut $repo_contact->getContactDefautClient($fiche->getClient());
  104.         }
  105.         $categories_notes $em->getRepository(Categorie::class)->findAll();;
  106.         $notes $repo_notes->findBy(["fiche" => $fiche], ["dateDebut" => "DESC"]);
  107.         $tempsRestant     "0";
  108.         $pourcentagePasse "0";
  109.         $now        time(); // or your date as well
  110.         $your_date  strtotime($fiche->getDate()->format("Y-m-d"));
  111.         $datediff   $now $your_date;
  112.         $tempsPasse round($datediff / (60 60 24));
  113.         if (is_object($fiche->getDatePrevisionelle())) {
  114.             $now          time();// or your date as well
  115.             $your_date    strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  116.             $datediff     $your_date $now;
  117.             $tempsRestant round($datediff / (60 60 24));
  118.             $now        time($fiche->getDate()->format("Y-m-d"));// or your date as well
  119.             $your_date  strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  120.             $datediff   $your_date $now;
  121.             $tempsTotal round($datediff / (60 60 24));
  122.             $pourcentagePasse 0;
  123.             if ($tempsTotal 0) {
  124.                 $pourcentagePasse round($tempsPasse 100 $tempsTotal);
  125.             }
  126.         }
  127.         //$colonnes = $repo_colonnes->findBy(array("kanban"=>$fiche->getColonne()->getKanban()),array("position"=>"ASC"));
  128.         $colonnes = [];
  129.         if (is_object($fiche->getColonne()) && is_object($fiche->getColonne()->getKanban()->getColonne())) {
  130.             $colonnes $repo_colonnes->findBy(["kanban" => $fiche->getColonne()->getKanban()->getColonne()->getKanban()], ["position" => "ASC"]);
  131.         } elseif (is_object($fiche->getColonne())) {
  132.             $colonnes $repo_colonnes->findBy(["kanban" => $fiche->getColonne()->getKanban()], ["position" => "ASC"]);
  133.         }
  134.         return $this->render(
  135.             'Kanban/Affaire/afficher.html.twig',
  136.             [
  137.                 'contactDefaut'    => $contactDefaut,
  138.                 'colonnes'         => $colonnes,
  139.                 'fiche'            => $fiche,
  140.                 'notes'            => $notes,
  141.                 'errors'           => $errors,
  142.                 "pourcentagePasse" => $pourcentagePasse,
  143.                 "tempsRestant"     => $tempsRestant,
  144.                 "tempsPasse"       => $tempsPasse,
  145.                 "categories_notes" => $categories_notes,
  146.             ]
  147.         );
  148.         //$rendu = $this->renderView('Kanban/Fiche/afficher_modal.html.twig', array('contactDefaut'=>$contactDefaut,'colonnes'=>$colonnes,'fiche'=>$fiche,'notes'=>$notes,'errors'=>$errors,"pourcentagePasse"=>$pourcentagePasse,"tempsRestant"=>$tempsRestant,"tempsPasse"=>$tempsPasse,"categories_notes"=>$categories_notes));
  149.         $rendu $this->renderView(
  150.             'Kanban/Affaire/afficher.html.twig',
  151.             [
  152.                 'contactDefaut'    => $contactDefaut,
  153.                 'colonnes'         => $colonnes,
  154.                 'fiche'            => $fiche,
  155.                 'notes'            => $notes,
  156.                 'errors'           => $errors,
  157.                 "pourcentagePasse" => $pourcentagePasse,
  158.                 "tempsRestant"     => $tempsRestant,
  159.                 "tempsPasse"       => $tempsPasse,
  160.                 "categories_notes" => $categories_notes,
  161.             ]
  162.         );
  163.         return new JsonResponse(['rendu' => $rendu'titre' => $titre_modal]);
  164.     }
  165.     /**
  166.      * @Route("/tunnels/affaire/afficher2/{id}", name="dtc_kanban_affaire_fiche_2")
  167.      */
  168.     public function afficher2Action(Request $requestFiche $ficheEntityManagerInterface $em)
  169.     {
  170.         $titre_construit " ";
  171.         $adresseMail     "";
  172.         $telephone       "";
  173.         if ($fiche->getBudget() != "") {
  174.             $titre_construit .= "&nbsp;/ ".number_format($fiche->getBudget(), 2','' ')."&euro; ";
  175.         }
  176.         if (is_object($fiche->getClient())) {
  177.             $titre_construit .= "<div class='gauche' style='_font-size:12px;margin-left:10px;'>".$fiche->getClient()->getNom()."</div>";
  178.             if ($fiche->getClient()->getEmail() != "") {
  179.                 $titre_construit .= "<div class='gauche' style='_font-size:12px;margin-left:10px;'><a href='mailto:".$fiche->getClient()->getEmail()."'>".$fiche->getClient()->getEmail(
  180.                     )."</a></div>";
  181.             }
  182.             if ($fiche->getClient()->getTelephone() != "") {
  183.                 $titre_construit .= "<div class='gauche' style='_font-size:12px;margin-left:10px;'><a href='phone:".$fiche->getClient()->getTelephone()."'>".$fiche->getClient(
  184.                     )->getTelephone()."</a></div>";
  185.             }
  186.         }
  187.         $titre_modal "<div class='gauche' style=''>".$fiche->getLibelle()." : </div>".$titre_construit;
  188.         $titre_modal $fiche->getLibelle();
  189.         $errors      "";
  190.         $parent      "";
  191.         $url         "";
  192.         //$fichier->setVersion("1");
  193.         $repo_notes    $em->getRepository(Note::class);
  194.         $repo_colonnes $em->getRepository(Colonne::class);
  195.         $repo_contact  $em->getRepository(Contact::class);
  196.         $contactDefaut "";
  197.         if (is_object($fiche->getClient())) {
  198.             $contactDefaut $repo_contact->getContactDefautClient($fiche->getClient());
  199.         }
  200.         $categories_notes $em->getRepository(Categorie::class)->findAll();;
  201.         $notes $repo_notes->findBy(["fiche" => $fiche], ["dateDebut" => "DESC"]);
  202.         $tempsRestant     "0";
  203.         $pourcentagePasse "0";
  204.         $now        time(); // or your date as well
  205.         $your_date  strtotime($fiche->getDate()->format("Y-m-d"));
  206.         $datediff   $now $your_date;
  207.         $tempsPasse round($datediff / (60 60 24));
  208.         if (is_object($fiche->getDatePrevisionelle())) {
  209.             $now          time();// or your date as well
  210.             $your_date    strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  211.             $datediff     $your_date $now;
  212.             $tempsRestant round($datediff / (60 60 24));
  213.             $now        time($fiche->getDate()->format("Y-m-d"));// or your date as well
  214.             $your_date  strtotime($fiche->getDatePrevisionelle()->format("Y-m-d"));
  215.             $datediff   $your_date $now;
  216.             $tempsTotal round($datediff / (60 60 24));
  217.             $pourcentagePasse round($tempsPasse 100 $tempsTotal);
  218.         }
  219.         //$colonnes = $repo_colonnes->findBy(array("kanban"=>$fiche->getColonne()->getKanban()),array("position"=>"ASC"));
  220.         $colonnes $repo_colonnes->findBy(["kanban" => "1"], ["position" => "ASC"]);
  221.         return $this->render(
  222.             'Kanban/Affaire/afficher_2.html.twig',
  223.             [
  224.                 'contactDefaut'    => $contactDefaut,
  225.                 'colonnes'         => $colonnes,
  226.                 'fiche'            => $fiche,
  227.                 'notes'            => $notes,
  228.                 'errors'           => $errors,
  229.                 "pourcentagePasse" => $pourcentagePasse,
  230.                 "tempsRestant"     => $tempsRestant,
  231.                 "tempsPasse"       => $tempsPasse,
  232.                 "categories_notes" => $categories_notes,
  233.             ]
  234.         );
  235.         //$rendu = $this->renderView('Kanban/Fiche/afficher_modal.html.twig', array('contactDefaut'=>$contactDefaut,'colonnes'=>$colonnes,'fiche'=>$fiche,'notes'=>$notes,'errors'=>$errors,"pourcentagePasse"=>$pourcentagePasse,"tempsRestant"=>$tempsRestant,"tempsPasse"=>$tempsPasse,"categories_notes"=>$categories_notes));
  236.         $rendu $this->renderView(
  237.             'Kanban/Affaire/afficher_2.html.twig',
  238.             [
  239.                 'contactDefaut'    => $contactDefaut,
  240.                 'colonnes'         => $colonnes,
  241.                 'fiche'            => $fiche,
  242.                 'notes'            => $notes,
  243.                 'errors'           => $errors,
  244.                 "pourcentagePasse" => $pourcentagePasse,
  245.                 "tempsRestant"     => $tempsRestant,
  246.                 "tempsPasse"       => $tempsPasse,
  247.                 "categories_notes" => $categories_notes,
  248.             ]
  249.         );
  250.         return new JsonResponse(['rendu' => $rendu'titre' => $titre_modal]);
  251.     }
  252.     /**
  253.      * @Route("", name="")
  254.      */
  255.     public function listerAction(Request $request$id$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  256.     {
  257.         if ($type == 'client') {
  258.             $repo_objet $em->getRepository(Client::class);
  259.             $objet      $repo_objet->find($id);
  260.         }
  261.         $tableau_class_cellule   = [];
  262.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [0], "visible" => true"orderable" => true"searchable" => true];
  263.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [1], "visible" => true"orderable" => true"searchable" => true];
  264.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [2], "visible" => true"orderable" => true"searchable" => true];
  265.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [3], "visible" => true"orderable" => true"searchable" => true];
  266.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [4], "visible" => true"orderable" => true"searchable" => true];
  267.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [5], "visible" => true"orderable" => true"searchable" => true];
  268.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-right""targets" => [6], "visible" => true"orderable" => true"searchable" => true];
  269.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [7], "visible" => true"orderable" => true"searchable" => true];
  270.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [8], "visible" => true"orderable" => true"searchable" => true];
  271.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [9], "visible" => true"orderable" => true"searchable" => true];
  272.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id text-center""targets" => [10], "visible" => true];
  273.         $this->datatable($datatable$translator$objet$type);
  274.         //return $this->render('Utilisateur/Contact/lister.html.twig', array('tableauClassColonne'=>$tableau_class_cellule,"id"=>$id,"type"=>$type));
  275.         return $this->render('Kanban/Affaire/lister.html.twig', ['tableauClassColonne' => $tableau_class_cellule"id" => $id"type" => $type]);
  276.     }
  277.     /**
  278.      * set datatable configs
  279.      *
  280.      * @return \App\Library\Datatable\Util\Datatable
  281.      */
  282.     private function datatable(Datatable $datatableTranslatorInterface $translator$objet$type "")
  283.     {
  284.         $type_jointure 'x.'.$type;
  285.         $datatable->setDatatableId('dta-affaire')
  286.                   ->setEntity(Fiche::class, "x")
  287.                   ->setFields(
  288.                       [
  289.                           //"ID"    => 'x.id',
  290.                           $translator->trans("Référence")          => 'x.id',
  291.                           $translator->trans("Libellé")            => 'x.libelle',
  292.                           $translator->trans("Tunnel")             => 't.libelle',
  293.                           $translator->trans("Étape")              => 'col.libelle',
  294.                           $translator->trans("Client")             => 'c.raisonSociale',
  295.                           $translator->trans("Contact")            => 'co.prenom',
  296.                           $translator->trans("Budget")             => 'x.budget',
  297.                           $translator->trans("Potentiel")          => 'x.potentiel',
  298.                           $translator->trans("Probabilité")        => 'x.propabilite',
  299.                           $translator->trans("Date aboutissement") => 'x.datePrevisionelle',
  300.                           $translator->trans("Région")             => 'r.libelle',
  301.                           //"Défaut"    => 'x.defaut',
  302.                           "Actions"                                => 'x.id',
  303.                           "_identifier_"                           => 'x.id',
  304.                       ]
  305.                   )
  306.                   ->addJoin('x.kanban''t'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  307.                   ->addJoin('x.colonne''col'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  308.                   ->addJoin('x.client''c'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  309.                   ->addJoin('x.contact''co'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  310.                   ->addJoin('x.region''r'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  311.                   ->setRenderers(
  312.                       [
  313.                           => [
  314.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  315.                               'params' => [
  316.                                   'edit_route' => 'dtc_kanban_affaire_fiche',
  317.                               ],
  318.                           ],
  319.                           => [
  320.                               'view'   => 'FO/DataTable/edit_texte.html.twig',
  321.                               'params' => [
  322.                                   'objet' => Fiche::class,
  323.                                   'champ' => 'setLibelle',
  324.                               ],
  325.                           ],
  326.                           /*
  327.                           1 => array(
  328.                           'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
  329.                            'params' => array(
  330.                                       'edit_route'    => 'dtc_kanban_affaire_fiche'
  331.                                   ),
  332.                           ),
  333.                           */
  334.                           => [
  335.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  336.                               'params' => [
  337.                                   'edit_route'   => 'dtc_kanban_afficher',
  338.                                   'typeDocument' => 'tunnel',
  339.                               ],
  340.                           ],
  341.                           => [
  342.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  343.                               'params' => [
  344.                                   'edit_route'   => 'dtc_client_modifier',
  345.                                   'typeDocument' => 'client',
  346.                               ],
  347.                           ],
  348.                           => [
  349.                               'view'   => 'FO/DataTable/select_contact_affaire.html.twig',
  350.                               'params' => [
  351.                                   'edit_route'   => 'dtc_client_modifier',
  352.                                   'typeDocument' => 'client',
  353.                               ],
  354.                           ],
  355.                           6  => [
  356.                               'view'   => 'FO/DataTable/edit_texte_prix.html.twig',
  357.                               'params' => [
  358.                                   'objet' => Fiche::class,
  359.                                   'champ' => 'setBudget',
  360.                               ],
  361.                           ],
  362.                           /*
  363.                           6 => array(
  364.                           'view' => 'FO/DataTable/prix.html.twig',
  365.                           'params' => array(
  366.                            )
  367.                           ),
  368.                           */
  369.                           7  => [
  370.                               'view'   => 'FO/DataTable/edit_texte.html.twig',
  371.                               'params' => [
  372.                                   'objet'    => Fiche::class,
  373.                                   'champ'    => 'setPotentiel',
  374.                                   'position' => 'text-center',
  375.                               ],
  376.                           ],
  377.                           8  => [
  378.                               'view'   => 'FO/DataTable/edit_texte.html.twig',
  379.                               'params' => [
  380.                                   'objet'    => Fiche::class,
  381.                                   'champ'    => 'setPropabilite',
  382.                                   'position' => 'text-center',
  383.                               ],
  384.                           ],
  385.                           9  => [
  386.                               'view'   => 'FO/DataTable/edit_texte_date.html.twig',
  387.                               'params' => [
  388.                                   'objet'    => Fiche::class,
  389.                                   'champ'    => 'setDatePrevisionelle"',
  390.                                   'position' => 'text-center',
  391.                               ],
  392.                           ],
  393.                           /*
  394.                           9=> array(
  395.                               'view' => 'FO/DataTable/date.html.twig',
  396.                               'params' => array(
  397.                                   ),
  398.                           ),
  399.                           */
  400.                           11 => [
  401.                               'view'   => 'FO/DataTable/actions.html.twig',
  402.                               'params' => [
  403.                                   'edit_route' => 'dtc_kanban_affaire_fiche',
  404.                                   'objet'      => Fiche::class,
  405.                                   //'supprimer_route'  => 'dtc_contact_supprimer',
  406.                                   //'id'    => $objet->getId(),
  407.                                   //'type'    => $type,
  408.                                   //'entite'    => 'contact',
  409.                                   //'objet'    => "DTCUtilisateurBundle:Contact"
  410.                               ],
  411.                           ],
  412.                       ]
  413.                   )
  414.                   ->setOrder("x.date""desc")
  415.                   ->setSearch(true)
  416.                   ->setSearchFields([012345679]);
  417.         $where               $type_jointure." = :objet AND (x.statutFiche is NULL or x.statutFiche = :gagne or x.statutFiche = :perdu)";
  418.         $parametres          = [];
  419.         $parametres["gagne"] = "1";
  420.         $parametres["perdu"] = "2";
  421.         $parametres["objet"] = $objet;
  422.         if ($where != "") {
  423.             $datatable->setWhere(
  424.                 $where,
  425.                 $parametres
  426.             );
  427.         }
  428.         return $datatable;
  429.     }
  430.     /**
  431.      * Grid action
  432.      * @return Response
  433.      */
  434.     /**
  435.      * @Route("/affaires/grid/{id}/{type}", name="dtc_affaire_liste_grid")
  436.      */
  437.     public function gridAction(Request $request$id ""$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  438.     {
  439.         if ($type == 'client') {
  440.             $repo_objet $em->getRepository(Client::class);
  441.             $objet      $repo_objet->find($id);
  442.         }
  443.         return $this->datatable($datatable$translator$objet$type)->execute();
  444.     }
  445. }