src/Controller/GestionComerciale/FabricationAnomaliesController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\GestionComerciale\Fabrication;
  4. use App\Entity\GestionComerciale\StatutCommande;
  5. use App\Entity\GestionComerciale\StatutFabrication;
  6. use App\Form\GestionComerciale\FabricationAnomalieType;
  7. use App\Form\GestionComerciale\SupprimerFabricationAnomalieType;
  8. use App\Library\Datatable\Util\Datatable;
  9. use App\Service\Fabrication\OqtonService;
  10. use App\Service\GestionComerciale\CommandeService;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\Validator\Validator\ValidatorInterface;
  18. use Symfony\Contracts\Translation\TranslatorInterface;
  19. class FabricationAnomaliesController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/vente/fabrications-anomalies", name="dtc_fabrication_anomalies_liste")
  23.      */
  24.     public function listerAction(Request $request$fabricationParente ''$fabricationMultiple ''$prestation ''$commandeFournisseur ''Datatable $datatable,TranslatorInterface $translator
  25.     ) {
  26.         $this->datatable($datatable$translator);
  27.         $tableauClassColonne = [];
  28.         $tableauClassColonne   = [];
  29.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [0], "visible" => false"orderable" => false];
  30.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [1], "visible" => true"orderable" => false];
  31.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [2], "visible" => true"orderable" => true];
  32.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [3], "visible" => true"orderable" => true];
  33.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [4], "visible" => true"orderable" => true];
  34.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [5], "visible" => true"orderable" => true];
  35.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [6], "visible" => true"orderable" => true];
  36.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [7], "visible" => true"orderable" => true];
  37.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [8], "visible" => true"orderable" => true];
  38.         $tableauClassColonne[] = ["className" => "colonne_id text-left""targets" => [9], "visible" => true"orderable" => true];
  39.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [10], "visible" => true"orderable" => false];
  40.         $tableauClassColonne   = [];
  41.         $template 'GestionComerciale/Anomalies/lister-fabrication.html.twig';
  42.         return $this->render($template, [
  43.             'tableauClassColonne' => $tableauClassColonne,
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route("/vente/fabrication-anomalies/grid", name="dtc_fabrication_anomalies_liste_grid")
  48.      */
  49.     public function gridAction(Request $requestDatatable $datatableTranslatorInterface $translator)
  50.     {
  51.         return $this->datatable($datatable$translator)->execute();
  52.     }
  53.     /**
  54.      * set datatable configs
  55.      *
  56.      * @return \App\Library\Datatable\Util\Datatable
  57.      */
  58.     private function datatable(Datatable $datatableTranslatorInterface $translator)
  59.     {
  60.         $parameters = ["statutFabrication"=>4];
  61.         $datatable
  62.             ->setDatatableId('dta-anomalie-fabrication')
  63.             ->setEntity(Fabrication::class, "x")
  64.             ->setFields(
  65.                 [
  66.                     $translator->trans("ID")               => 'x.id',
  67.                     $translator->trans("Date")             => 'x.date',
  68.                     $translator->trans("Réf")              => 'x.reference',
  69.                     $translator->trans("Commandde")              => 'c.reference',
  70.                     $translator->trans("Client")              => 'clt.nom',
  71.                     $translator->trans("Article")              => 'a.reference',
  72.                     $translator->trans("Libellé")              => 'a.libelle',
  73.                     $translator->trans("Anomalie")         => 'ra.libelle',
  74.                     $translator->trans("Commentaire")         => 'x.commentaireAnomalie',
  75.                     $translator->trans("Actions")          => 'x.id',
  76.                     "_identifier_"                         => 'x.id',
  77.                 ]
  78.             )
  79.             ->addJoin('x.statutFabrication''s'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  80.             ->addJoin('x.raisonAnomalie''ra'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  81.             ->addJoin('x.articleCommandeCommandeClient''ac'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  82.             ->addJoin('ac.commande''c'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  83.             ->addJoin('c.client''clt'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  84.             ->addJoin('ac.article''a'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  85.             ->setRenderers(
  86.                 [
  87.                     => [
  88.                         'view' => 'FO/DataTable/heure.html.twig',
  89.                     ],
  90.                     => [
  91.                         'view'   => 'FO/DataTable/actions.html.twig',
  92.                         'params' => [
  93.                             'supprimer_route'    => 'dtc_fabrication_anomalies_supprimer',
  94.                             'objet'        => Fabrication::class,
  95.                             'deplier'      => false,
  96.                             'table' => "dta-anomalie-fabrication",
  97.                             'page_affiche' => "anomalies",
  98.                         ],
  99.                     ],
  100.                 ]
  101.             )
  102.             ->setSearch(true)
  103.             ->setSearchFields([])
  104.             ->setOrder('x.date''ASC');
  105.         $where ' x.raisonAnomalie is not null and x.statutFabrication != :statutFabrication';
  106.         if ($where != '') {
  107.             $datatable->setWhere($where$parameters);
  108.         }
  109.         return $datatable;
  110.     }
  111.     /**
  112.      * @Route("/fabrication/anomalie/ajouter/{id}", name="dtc_fabrication_anomalies_ajouter")
  113.      */
  114.     public function ajouterAction(Request         $requestFabrication $fabricationEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator,
  115.                                   CommandeService $commandeService
  116.     ) {
  117.         $titre_modal $translator->trans("Indiquer un défaut sur la fabrication");
  118.         $form   $this->createForm(FabricationAnomalieType::class, $fabrication);
  119.         $errors "";
  120.         $form->handleRequest($request);
  121.         if ($form->isSubmitted()) {
  122.             if ($form->isValid()) {
  123.                 $rendu '';
  124.                 $url   '';
  125.                 $get $request->query->all();
  126.                 $this->addFlash('notice'$translator->trans('Défaut ajouté avec succès !'));
  127.                 $donnees=[];
  128.                 $donnees["message"]=" : ".$fabrication->getReference()." ".$fabrication->getArticleCommandeCommandeClient()->getReference()." (id:".$fabrication->getArticleCommandeCommandeClient()->getId().") : ".$fabrication->getRaisonAnomalie()->getLibelle();
  129.                 $commandeService->creerHistorique($fabrication->getArticleCommandeCommandeClient()->getCommande(), 'anomalie_fabrication',$donnees);
  130.                 $fabrication->setCaisse(null);
  131.                 $em->persist($fabrication);
  132.                 $em->flush();
  133.                 $url "";
  134.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  135.                     return new Response(
  136.                         json_encode(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]),
  137.                         200,
  138.                         ['Content-Type' => 'application/json']
  139.                     );
  140.                 }
  141.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url], 200, ['Content-Type' => 'application/json']);
  142.             } else {
  143.                 $errors $validator->validate($fabrication);
  144.                 $rendu  $this->renderView('GestionComerciale/Anomalies/ajouter-fabrication.html.twig', ['form' => $form->createView(), 'errors' => $errors'fabrication' => $fabrication]);
  145.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  146.             }
  147.         }
  148.         $rendu $this->renderView('GestionComerciale/Anomalies/ajouter-fabrication.html.twig', ['form' => $form->createView(), 'errors' => $errors'fabrication' => $fabrication]);
  149.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  150.     }
  151.     /**
  152.      * @Route("/fabrication/anomalie/supprimer/{id}", name="dtc_fabrication_anomalies_supprimer")
  153.      */
  154.     public function supprimerAction(Request $requestFabrication $fabricationEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator,CommandeService $commandeService,OqtonService $oqtonService)
  155.     {
  156.         $titre_modal $translator->trans("Demande de confirmation");
  157.         $user        $this->getUser();
  158.         $get         $request->query->all();
  159.         $messageModal "";
  160.         $form   $this->createForm(SupprimerFabricationAnomalieType::class, $fabrication);
  161.         $errors "";
  162.         $form->handleRequest($request);
  163.         if ($form->isSubmitted()) {
  164.             if ($form->isValid()) {
  165.                 $donnees=[];
  166.                 $donnees["message"]=" : ".$fabrication->getReference()." ".$fabrication->getArticleCommandeCommandeClient()->getReference()." (id:".$fabrication->getArticleCommandeCommandeClient()->getId().")";
  167.                 $donnees["fichier"] = $fabrication->getArticleCommandeCommandeClient()->getFichier();
  168.                 $commandeService->creerHistorique($fabrication->getArticleCommandeCommandeClient()->getCommande(), 'supprimer_anomalie_fabrication',$donnees);
  169.                 if($fabrication->getArticleCommandeCommandeClient()->getArticle()->getType()->getId() === Fabrication::ADDITIVE) {
  170.                     $oqtonService->sendApresDefautOrder($fabrication->getArticleCommandeCommandeClient());
  171.                 }
  172.                 else if($fabrication->getArticleCommandeCommandeClient()->getArticle()->getType()->getId() === Fabrication::DEDUCTIVE) {
  173.                 }
  174.                 $fabrication->setStatutFabrication($em->getReference(StatutFabrication::class, 4));
  175.                 $em->persist($fabrication);
  176.                 //$fabrication->setRaisonAnomalie(NULL);
  177.                 $fabrication->getArticleCommandeCommandeClient()->getCommande()->setStatutAmodifier(true);
  178.                 $em->persist($fabrication->getArticleCommandeCommandeClient()->getCommande());
  179.                 $fabrication->setArticleCommandeCommandeClient(NULL);
  180.                 $fabrication->setCommentaireAnomalie(NULL);
  181.                 $fabrication->setRaisonAnomalie(NULL);
  182.                 // Annuler la fabrication
  183.                 // Selon type fabrication renvoyé à Oqton
  184.                 // Renommer fichier avec préfixe "SAV"
  185.                 $em->persist($fabrication);
  186.                 $em->flush();
  187.                 $url "";
  188.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  189.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]],
  190.                         200,
  191.                         ['Content-Type' => 'application/json']
  192.                     );
  193.                 } else {
  194.                     $this->addFlash('notice'$translator->trans('Défaut supprimé avec succès !'));
  195.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  196.                 }
  197.             } else {
  198.                 $errors $validator->validate($fabrication);
  199.                 $rendu  $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
  200.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  201.             }
  202.         }
  203.         else {
  204.             if($fabrication->getTypeFabrication() == Fabrication::DEDUCTIVE) {
  205.                 $messageModal "La suppresion du défaut va relancer la fabrication de l'élément : <br/> ".$fabrication->getArticle()->getReference()." <br/>Commande : ".$fabrication->getArticleCommandeCommandeClient()->getCommande()->getReference();
  206.             }
  207.             elseif($fabrication->getTypeFabrication() == Fabrication::ADDITIVE) {
  208.                 $messageModal "La suppresion du défaut va envoyer un nouveau fichier à Oqton et relancer la fabrication de l'élément : <br/> ".$fabrication->getArticle()->getReference()." <br/>Commande : ".$fabrication->getArticleCommandeCommandeClient()->getCommande()->getReference();
  209.             }
  210.         }
  211.         $rendu $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors,'messageModal'=>$messageModal]);
  212.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  213.     }
  214. }