src/Controller/GestionComerciale/CommandeValidationClientController.php line 253

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\GestionComerciale\Commande;
  4. use App\Entity\GestionComerciale\CommandeValidationClient;
  5. use App\Library\Datatable\Util\Datatable;
  6. use App\Service\FO\SocieteService;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\JsonResponse;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Validator\Validator\ValidatorInterface;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. class CommandeValidationClientController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/public/devis/decision/", name="dtc_devis_choix_client")
  19.      */
  20.     public function AccepteRefuserDevisAction(Request $requestEntityManagerInterface $emSocieteService $service_societe)
  21.     {
  22.         $repo_commande_validation_client $em->getRepository(CommandeValidationClient::class);
  23.         $commande                 null;
  24.         $commandeValidationClient null;
  25.         $jeton                    "A";
  26.         $get                      $request->query->all();
  27.         $valide                   false;
  28.         $confirmer                false;
  29.         $devisDejaAccepte         false;
  30.         $accept                   "";
  31.         $commandeValidationClient "";
  32.         if (array_key_exists('token'$get) && $get["token"] != "") {
  33.             $commandeValidationClient $repo_commande_validation_client->findOneBy(["jeton" => $get["token"]]);
  34.         }
  35.         if (is_object($commandeValidationClient)) {
  36.             if (array_key_exists('token'$get) && $get["token"] == $commandeValidationClient->getJeton()) {
  37.                 $valide true;
  38.                 if (is_object($commandeValidationClient->getCommande())) {
  39.                     $commande $commandeValidationClient->getCommande();
  40.                 } else {
  41.                     $valide false;
  42.                 }
  43.             }
  44.         }
  45.         if (array_key_exists('accept'$get) && ($get["accept"] == "1" or $get["accept"] == "0")) {
  46.             $accept intval($get["accept"]);
  47.         } else {
  48.             $valide false;
  49.         }
  50.         if ($valide) {
  51.             if (array_key_exists('confirm'$get) && ($get["confirm"] == "1") && ! is_object($commandeValidationClient->getDateChoixClient())) {
  52.                 $confirmer true;
  53.                 if ($accept == "1") {
  54.                     $commandeValidationClient->setStatut(true);
  55.                 } else {
  56.                     $commandeValidationClient->setStatut(false);
  57.                 }
  58.                 $commandeValidationClient->setDateChoixClient(new \Datetime());
  59.                 $em->persist($commandeValidationClient);
  60.                 $em->flush();
  61.                 $destinataires_mails_valide = [];
  62.                 if (is_object($commande->getAssistanteCommercial()) && filter_var($commande->getAssistanteCommercial()->getEmail(), FILTER_VALIDATE_EMAIL)) {
  63.                     $destinataires_mails_valide[] = $commande->getAssistanteCommercial()->getEmail();
  64.                 }
  65.                 if (is_object($commande->getCommercial()) && filter_var($commande->getCommercial()->getEmail(), FILTER_VALIDATE_EMAIL)) {
  66.                     $destinataires_mails_valide[] = $commande->getCommercial()->getEmail();
  67.                 }
  68.                 if (is_object($commande->getUtilisateur()) && filter_var($commande->getUtilisateur()->getEmail(), FILTER_VALIDATE_EMAIL)) {
  69.                     $destinataires_mails_valide[] = $commande->getCommercial()->getEmail();
  70.                 }
  71.                 if (count($destinataires_mails_valide) > 0) {
  72.                     $societe $service_societe->getSociete();
  73.                     $contact "";
  74.                     if (is_object($commandeValidationClient->getContact())) {
  75.                         $contact $commandeValidationClient->getContact()->getPrenom()." ".$commandeValidationClient->getContact()->getNom()." (".$commandeValidationClient->getEmail().")";
  76.                     } else {
  77.                         $contact $commandeValidationClient->getEmail();
  78.                     }
  79.                     if ($commandeValidationClient->getStatut()) {
  80.                         $sujet_mail "Acceptation du Devis ".$commande->getReference();
  81.                         $phrase     "Le Devis ".$commande->getReference()." vient d'être accepté par ".$contact;
  82.                     } else {
  83.                         $sujet_mail "Refus du Devis ".$commande->getReference();
  84.                         $phrase     "Le Devis".$commande->getReference()." vient d'être refusé par ".$contact;
  85.                     }
  86.                     $message_mail "<div style='line-height:13px;'>
  87.                                     Bonjour,<br/>                                                            
  88.                                     ".$phrase."                                    
  89.                                     </div>
  90.                                     ";
  91.                     $donnees_email = [
  92.                         'titre'         => $sujet_mail,
  93.                         'message'       => $message_mail,
  94.                         'destinataires' => $destinataires_mails_valide,
  95.                         'images'        => "",
  96.                         'documents'     => "",
  97.                     ];
  98.                     //$emailService = $this->get('dtc.email');
  99.                     //$emailService->envoyerEmailClassique($donnees_email);
  100.                 }
  101.             }
  102.         }
  103.         return $this->render('GestionComerciale/CommandeValidationClient/accepter_refuser_devis.html.twig', [
  104.             "commandeValidationClient" => $commandeValidationClient,
  105.             "valide"                   => $valide,
  106.             "accept"                   => intval($accept),
  107.             "confirmer"                => $confirmer,
  108.             "commande"                 => $commande,
  109.             "devisDejaAccepte"         => $devisDejaAccepte,
  110.         ]);
  111.     }
  112.     /**
  113.      * @Route("", name="")
  114.      */
  115.     public function listerAction(Request $request$id "0"$type "a"EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  116.     {
  117.         $tableau_class_cellule = [];
  118.         $tableau_class_cellule[] = ["orderable" => false"searchable" => false"className" => "visible_export colonne_id text-center""targets" => [0], "visible" => true];
  119.         $tableau_class_cellule[] = ["orderable" => false"searchable" => false"className" => "visible_export colonne_id text-center""targets" => [1], "visible" => true];
  120.         $tableau_class_cellule[] = ["orderable" => false"searchable" => false"className" => "visible_export colonne_id text-center""targets" => [2], "visible" => true];
  121.         $tableau_class_cellule[] = ["orderable" => false"searchable" => false"className" => "visible_export colonne_id ""targets" => [3], "visible" => true];
  122.         $tableau_class_cellule[] = ["orderable" => false"searchable" => false"className" => "visible_export colonne_id ""targets" => [4], "visible" => true];
  123.         $modal $request->query->get('modal');
  124.         $qte   $request->query->get('qte');
  125.         if ($type == "commande") {
  126.             $repo_objet $em->getRepository(Commande::class);
  127.         }
  128.         $objet $repo_objet->find($id);
  129.         if (is_object($objet)) {
  130.             if ($type == "commande") {
  131.                 $this->datatableCommande($objet$type$datatable$translator);
  132.             }
  133.             return $this->render('GestionComerciale/CommandeValidationClient/lister.html.twig', ['tableauClassColonne' => $tableau_class_cellule"id" => $id"type" => $type]
  134.             );
  135.         }
  136.     }
  137.     /**
  138.      * set datatable configs
  139.      *
  140.      * @return \App\Library\Datatable\Util\Datatable
  141.      */
  142.     private function datatableCommande($objet$type ""Datatable $datatableTranslatorInterface $translator)
  143.     {
  144.         $type_jointure 'x.'.$type;
  145.         $datatable->setDatatableId('dta-commande-validation-client')
  146.                   ->setEntity(CommandeValidationClient::class, "x")
  147.                   ->setFields(
  148.                       [
  149.                           $translator->trans("Date demande")  => 'x.date',
  150.                           $translator->trans("Date décision") => 'x.dateChoixClient',
  151.                           $translator->trans("Décision")      => 'x.statut',
  152.                           $translator->trans("Contact")       => 'x.id',
  153.                           $translator->trans("Email")         => 'x.email',
  154.                           "_identifier_" => 'x.id',
  155.                       ]
  156.                   )
  157.             //->addJoin('x.article', 'a', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  158.             //->addJoin('x.articleCommande', 'ac', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN, \Doctrine\ORM\Query\Expr\Join::WITH, 'ac.article = x.id')
  159.             //->addJoin('ac.commande', 'c', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN, \Doctrine\ORM\Query\Expr\Join::WITH, 'c.id = ac.commande')
  160.                   ->setWhere(
  161.                 'x.commande = :objet',
  162.                 ['objet' => $objet]
  163.             )
  164.                   ->setRenderers(
  165.                       [
  166.                           => [
  167.                               'view'   => 'FO/DataTable/heure.html.twig',
  168.                               'params' => [
  169.                                   'commande' => $objet,
  170.                               ],
  171.                           ],
  172.                           => [
  173.                               'view'   => 'FO/DataTable/heure.html.twig',
  174.                               'params' => [
  175.                                   'commande' => $objet,
  176.                               ],
  177.                           ],
  178.                           => [
  179.                               'view'   => 'FO/DataTable/booleen_null.html.twig',
  180.                               'params' => [
  181.                                   'commande' => $objet,
  182.                               ],
  183.                           ],
  184.                           => [
  185.                               'view'   => 'FO/DataTable/contact_decision.html.twig',
  186.                               'params' => [
  187.                                   'commande' => $objet,
  188.                               ],
  189.                           ],
  190.                       ]
  191.                   )
  192.             //->setOrder("x.id", "desc")
  193.             //->setSearch(true)
  194.                   ->setGroupBy("x.id")//->setSearchFields(array(1,2))
  195.         ;
  196.         return $datatable;
  197.     }
  198.     /**
  199.      * @Route("/validation-client/grid/{id}/{type}", name="dtc_commande_validation_client_grid")
  200.      */
  201.     public function gridAction(Request $request$id ""$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  202.     {
  203.         if ($type == "commande") {
  204.             $repo_objet $em->getRepository(Commande::class);
  205.         }
  206.         $objet $repo_objet->find($id);
  207.         if (is_object($objet) and $type == "commande") {
  208.             return $this->datatableCommande($objet$type$datatable$translator)->execute();
  209.         }
  210.     }
  211. }