src/Controller/GestionComerciale/AnomaliesColisageController.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\GestionComerciale\Colisage;
  4. use App\Entity\GestionComerciale\Commande;
  5. use App\Entity\Rangements\Caisse;
  6. use App\Entity\GestionComerciale\StatutCommande;
  7. use App\Form\GestionComerciale\CommandeAnomalieType;
  8. use App\Form\GestionComerciale\ColisageAnomalieType;
  9. use App\Library\Datatable\Util\Datatable;
  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 AnomaliesColisageController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/vente/colisage-anomalies", name="dtc_colisage_anomalies_liste")
  23.      */
  24.     public function listerAction(Request             $request$fabricationParente ''$fabricationMultiple ''$prestation ''$commandeFournisseur ''Datatable $datatable,
  25.                                  TranslatorInterface $translator
  26.     ) {
  27.         $this->datatable($datatable$translator);
  28.         $tableauClassColonne = [];
  29.         $tableauClassColonne   = [];
  30.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [0], "visible" => false"orderable" => false];
  31.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [1], "visible" => true"orderable" => false];
  32.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [2], "visible" => true"orderable" => true];
  33.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [3], "visible" => true"orderable" => true];
  34.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [4], "visible" => true"orderable" => true];
  35.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [5], "visible" => true"orderable" => true];
  36.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [6], "visible" => true"orderable" => true];
  37.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [7], "visible" => true"orderable" => true];
  38.         $tableauClassColonne[] = ["className" => "colonne_id text-center""targets" => [8], "visible" => true"orderable" => true];
  39.         $tableauClassColonne[] = ["className" => "colonne_id text-left""targets" => [9], "visible" => true"orderable" => true];
  40.         $tableauClassColonne[] = ["className" => "colonne_id""targets" => [10], "visible" => true"orderable" => false];
  41.         $tableauClassColonne   = [];
  42.         $template 'GestionComerciale/AnomaliesColisage/lister.html.twig';
  43.         return $this->render($template, [
  44.             'tableauClassColonne' => $tableauClassColonne,
  45.         ]);
  46.     }
  47.     /**
  48.      * @Route("/vente/colisage-anomalies/grid", name="dtc_colisage_anomalies_liste_grid")
  49.      */
  50.     public function gridAction(Request $requestDatatable $datatableTranslatorInterface $translator)
  51.     {
  52.         return $this->datatable($datatable$translator)->execute();
  53.     }
  54.     /**
  55.      * set datatable configs
  56.      *
  57.      * @return \App\Library\Datatable\Util\Datatable
  58.      */
  59.     private function datatable(Datatable $datatableTranslatorInterface $translator)
  60.     {
  61.         $parameters = [];
  62.         $datatable->setEntity(Colisage::class, "x")
  63.             ->setFields(
  64.                 [
  65.                     $translator->trans("ID")               => 'x.id',
  66.                     $translator->trans("Référence")               => 'x.reference',
  67.                     $translator->trans("Anomalie")         => 'ra.libelle',
  68.                     $translator->trans("Commentaire")         => 'x.commentaireAnomalie',
  69.                     $translator->trans("Actions")          => 'x.id',
  70.                     "_identifier_"                         => 'x.id',
  71.                 ]
  72.             )
  73.             ->addJoin('x.raisonAnomalie''ra'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  74.             //->addJoin('x.client', 'c', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  75.             ->setRenderers(
  76.                 [
  77.                     => [
  78.                         'view'   => 'FO/DataTable/actions.html.twig',
  79.                         'params' => [
  80.                             //'supprimer_route'    => 'dtc_commande_supprimer',
  81.                             'objet'        => Colisage::class,
  82.                             'page_affiche' => "anomalies_etiquettes",
  83.                         ],
  84.                     ],
  85.                 ]
  86.             )
  87.             ->setSearch(true)
  88.             //->setSearchFields(array(3,4,5,7,8,9,10,11))
  89.             ->setSearchFields([])
  90.             //->setOrder('x.date', 'ASC');
  91.             ;
  92.         $where 'x.raisonAnomalie is not null';
  93.         if ($where != '') {
  94.             $datatable->setWhere($where$parameters);
  95.         }
  96.         return $datatable;
  97.     }
  98.     /**
  99.      * @Route("/vente/colisage-anomalies/{id}", name="dtc_colisage_anomalies_ajouter")
  100.      */
  101.     public function ajouterAction(Request $requestColisage $colisageEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validatorCommandeService $commandeService)
  102.     {
  103.         $titre_modal $translator->trans("Indiquer une anomalie d'étiquette");
  104.         $get $request->query->all();
  105.         $form   $this->createForm(ColisageAnomalieType::class, $colisage);
  106.         $errors "";
  107.         $form->handleRequest($request);
  108.         if ($form->isSubmitted()) {
  109.             if ($form->isValid()) {
  110.                 $rendu '';
  111.                 $url   '';
  112.                 $this->addFlash('notice'$translator->trans('Anomalie ajoutée avec succès !'));
  113.                 $em->persist($colisage);
  114.                 $em->flush();
  115.                 $url "";
  116.                 if ( ! empty($get["type"]) && $get["type"] == "emballage" && ! empty($get["lp"]) && $get["lp"] != "") {
  117.                     $url $this->generateUrl('dtc_liste_preparation_simplifie_scan_produit_action', ["id" => $get["lp"]]);
  118.                 } elseif ( ! empty($get["type"]) && $get["type"] == "etiquette" && ! empty($get["lp"]) && $get["lp"] != "") {
  119.                     $url $this->generateUrl('dtc_liste_preparation_simplifie_scan_produit_action', ["id" => $get["lp"]]);
  120.                 } else {
  121.                     $url $this->generateUrl('dtcfo_homepage', ["ms" => "1"]);
  122.                 }
  123.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url], 200, ['Content-Type' => 'application/json']);
  124.             } else {
  125.                 $errors $validator->validate($caisse);
  126.                 $rendu  $this->renderView('GestionComerciale/Anomalies/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
  127.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  128.             }
  129.         }
  130.         $rendu $this->renderView('GestionComerciale/Anomalies/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'colisage' => $colisage]);
  131.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  132.     }
  133. }