src/Controller/GestionComerciale/AnomaliesController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\GestionComerciale\Commande;
  4. use App\Entity\Rangements\Caisse;
  5. use App\Entity\GestionComerciale\StatutCommande;
  6. use App\Form\GestionComerciale\CommandeAnomalieType;
  7. use App\Form\GestionComerciale\CaisseAnomalieType;
  8. use App\Library\Datatable\Util\Datatable;
  9. use App\Service\GestionComerciale\CommandeService;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Validator\Validator\ValidatorInterface;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. class AnomaliesController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("/vente/commande-anomalies", name="dtc_commande_anomalies_liste")
  22.      */
  23.     public function listerAction(Request             $request$fabricationParente ''$fabricationMultiple ''$prestation ''$commandeFournisseur ''Datatable $datatable,
  24.                                  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.html.twig';
  42.         return $this->render($template, [
  43.             'tableauClassColonne' => $tableauClassColonne,
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route("/vente/commande-anomalies/grid", name="dtc_commande_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 = [];
  61.         $datatable->setEntity(Caisse::class, "x")
  62.             ->setFields(
  63.                 [
  64.                     $translator->trans("ID")               => 'x.id',
  65.                     $translator->trans("Libelle")         => 'x.libelle',
  66.                     $translator->trans("Code barre")         => 'x.ean',
  67.                     $translator->trans("Anomalie")         => 'ra.libelle',
  68.                     $translator->trans("Client")         => 'c.nom',
  69.                     $translator->trans("Commentaire")         => 'x.commentaireAnomalie',
  70.                     $translator->trans("Actions")          => 'x.id',
  71.                     "_identifier_"                         => 'x.id',
  72.                 ]
  73.             )
  74.             ->addJoin('x.raisonAnomalie''ra'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  75.             ->addJoin('x.client''c'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  76.             ->setRenderers(
  77.                 [
  78.                     => [
  79.                         'view'   => 'FO/DataTable/actions.html.twig',
  80.                         'params' => [
  81.                             '__edit_route' => 'dtc_document_commercial_modifier',
  82.                             //'supprimer_route'    => 'dtc_commande_supprimer',
  83.                             'objet'        => Caisse::class,
  84.                             'deplier_caisse'      => true,
  85.                             'objet_deplier' => "deplier-tr-caisse-simplifie",
  86.                             'page_affiche' => "anomalies",
  87.                         ],
  88.                     ],
  89.                 ]
  90.             )
  91.             ->setSearch(true)
  92.             //->setSearchFields(array(3,4,5,7,8,9,10,11))
  93.             ->setSearchFields([])
  94.             //->setOrder('x.date', 'ASC');
  95.             ;
  96.         $where 'x.raisonAnomalie is not null';
  97.         if ($where != '') {
  98.             $datatable->setWhere($where$parameters);
  99.         }
  100.         return $datatable;
  101.     }
  102.     /**
  103.      * set datatable configs
  104.      *
  105.      * @return \App\Library\Datatable\Util\Datatable
  106.      */
  107.     private function __datatable(Datatable $datatableTranslatorInterface $translator)
  108.     {
  109.         $parameters = [];
  110.         $datatable->setEntity(Commande::class, "x")
  111.                   ->setFields(
  112.                       [
  113.                           $translator->trans("ID")               => 'x.id',
  114.                           $translator->trans("Date")             => 'x.date',
  115.                           $translator->trans("Réf")              => 'x.reference',
  116.                           $translator->trans("Réf marktepplace") => 'x.referenceMarketPlace',
  117.                           $translator->trans("Origine")          => 'cmp.libelle',
  118.                           $translator->trans("Statut")           => 's.libelle',
  119.                           $translator->trans("Transporteur")     => 't.libelle',
  120.                           $translator->trans("Anomalie")         => 'ra.libelle',
  121.                           $translator->trans("Actions")          => 'x.id',
  122.                           "_identifier_"                         => 'x.id',
  123.                       ]
  124.                   )
  125.                   ->addJoin('x.compteMarketPlace''cmp'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  126.                   ->addJoin('x.statutCommande''s'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  127.                   ->addJoin('x.transporteur''t'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  128.                   ->addJoin('x.raisonAnomalie''ra'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  129.                   ->setRenderers(
  130.                       [
  131.                           => [
  132.                               'view' => 'FO/DataTable/heure.html.twig',
  133.                           ],
  134.                           => [
  135.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  136.                               'params' => [
  137.                                   //'edit_route'    => 'dtc_bon_preparation_modifier'
  138.                                   'edit_route' => 'auto',
  139.                               ],
  140.                           ],
  141.                           => [
  142.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  143.                               'params' => [
  144.                                   //'edit_route'    => 'dtc_bon_preparation_modifier'
  145.                                   'edit_route' => 'auto',
  146.                               ],
  147.                           ],
  148.                           => [
  149.                               'view'   => 'FO/DataTable/modifier_transporteur.html.twig',
  150.                               'params' => [
  151.                                   'edit_route' => '',
  152.                               ],
  153.                           ],
  154.                           => [
  155.                               'view'   => 'FO/DataTable/actions.html.twig',
  156.                               'params' => [
  157.                                   '__edit_route' => 'dtc_document_commercial_modifier',
  158.                                   //'supprimer_route'    => 'dtc_commande_supprimer',
  159.                                   'objet'        => Commande::class,
  160.                                   'deplier'      => true,
  161.                                   'mode_deplier' => "simplifie",
  162.                                   'page_affiche' => "anomalies",
  163.                               ],
  164.                           ],
  165.                           /*
  166.                           0 => array(
  167.                           'view' => 'FO/DataTable/actions-interface-simplifie.html.twig',
  168.                           'params' => array(
  169.                           'afficher_icone_reception'    => false,
  170.                           'edit_route'    => 'dtc_fabrication_simplifie_reception',
  171.                           //'supprimer_route'    => 'dtc_fabrication_supprimer',
  172.                           'objet'    => 'DTCGestionComercialeBundle:Fabrication',
  173.                           'fabrication' => true,
  174.                           'commandeFournisseur' => $commandeFournisseur,
  175.                           'fabricationMultiple' => $fabricationMultiple
  176.                       ),
  177.                   ),
  178.                   */
  179.                       ]
  180.                   )
  181.                   ->setSearch(true)
  182.             //->setSearchFields(array(3,4,5,7,8,9,10,11))
  183.                   ->setSearchFields([])
  184.                   ->setOrder('x.date''ASC');
  185.         $parameters["typeDocumentCommercial"] = 4;
  186.         $parameters["statutEmballe"]         = 31;
  187.         $parameters["statutCommande"]         = [3233];
  188.         $where                                '(x.typeDocumentCommercial = :typeDocumentCommercial and x.statutCommande IN (:statutCommande))';
  189.         $where                               .= ' OR (x.transporteur is null and x.statutCommande = :statutCommandeAccepte and x.compteMarketPlace is not null)';
  190.         $where                               .= ' OR (x.statutCommande != :statutEmballe and  x.raisonAnomalie is not null and x.typeDocumentCommercial = :typeDocumentCommercial )';
  191.         $parameters["statutCommandeAccepte"] = 9;
  192.         if ($where != '') {
  193.             $datatable->setWhere($where$parameters);
  194.         }
  195.         return $datatable;
  196.     }
  197.     /**
  198.      * @Route("/vente/commande-anomalies/{id}", name="dtc_commande_anomalies_ajouter")
  199.      */
  200.     public function ajouterAction(Request $requestCaisse $caisseEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validatorCommandeService $commandeService)
  201.     {
  202.         $titre_modal $translator->trans("Indiquer une anomalie sur la boite");
  203.         $get $request->query->all();
  204.         if ( ! empty($get["type"]) && $get["type"] == "etiquette") {
  205.             $titre_modal $translator->trans("Indiquer une anomalie d'étiquette");
  206.         }
  207.         $form   $this->createForm(CaisseAnomalieType::class, $caisse);
  208.         $errors "";
  209.         $form->handleRequest($request);
  210.         if ($form->isSubmitted()) {
  211.             if ($form->isValid()) {
  212.                 //$this->container->get('dtc.commande')->creerHistorique($commande, 'dtc_gestioncomercialebundle_commande_transporteur');
  213.                 //$rendu = $this->renderView('layout-errors.html.twig');
  214.                 $rendu '';
  215.                 $url   '';
  216.                 $this->addFlash('notice'$translator->trans('Anomalie ajoutée avec succès !'));
  217.                 if ( ! empty($get["type"]) && $get["type"] == "emballage") {
  218.                     //$statutCommande = $em->getRepository(StatutCommande::class)->find(33);
  219.                     //$commande->setStatutCommande($statutCommande);
  220.                     //$commandeService->creerHistorique($commande, 31, ["message" => " : ".$commande->getRaisonAnomalie()->getLibelle()]);
  221.                 } elseif ( ! empty($get["type"]) && $get["type"] == "etiquette") {
  222.                    // $commandeService->creerHistorique($commande, 32, ["message" => " : ".$commande->getRaisonAnomalie()->getLibelle()]);
  223.                 }
  224.                 $em->persist($caisse);
  225.                 $em->flush();
  226.                 $url "";
  227.                 if ( ! empty($get["type"]) && $get["type"] == "emballage" && ! empty($get["lp"]) && $get["lp"] != "") {
  228.                     $url $this->generateUrl('dtc_liste_preparation_simplifie_scan_produit_action', ["id" => $get["lp"]]);
  229.                 } elseif ( ! empty($get["type"]) && $get["type"] == "etiquette" && ! empty($get["lp"]) && $get["lp"] != "") {
  230.                     $url $this->generateUrl('dtc_liste_preparation_simplifie_scan_produit_action', ["id" => $get["lp"]]);
  231.                 } else {
  232.                     $url $this->generateUrl('dtcfo_homepage', ["ms" => "1"]);
  233.                 }
  234.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url], 200, ['Content-Type' => 'application/json']);
  235.             } else {
  236.                 $errors $validator->validate($caisse);
  237.                 $rendu  $this->renderView('GestionComerciale/Anomalies/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
  238.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  239.             }
  240.         }
  241.         $rendu $this->renderView('GestionComerciale/Anomalies/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'caisse' => $caisse]);
  242.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  243.     }
  244.     /**
  245.      * @Route("/old/vente/commande-anomaliesccccc/{id}", name="dtc_commande_anomalies_ajouter_old")
  246.      */
  247.     public function ___ajouterAction(Request $requestCommande $commandeEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validatorCommandeService $commandeService)
  248.      {
  249.         $titre_modal $translator->trans("Indiquer une anomalie sur la commande");
  250.         $form   $this->createForm(CommandeAnomalieType::class, $commande);
  251.         $errors "";
  252.         $form->handleRequest($request);
  253.         if ( ! $form->isSubmitted()) {
  254.             if(is_object($commande->getCommande()) && count($commande->getCommande()->getArticleCommande())>0) {
  255.                 foreach($commande->getCommande()->getArticleCommande() as $acBloquer) {
  256.                     if($acBloquer->isBloquer()) {
  257.                         $this->addFlash('warning'$translator->trans('L\'élement '.$acBloquer->getArticle()->getReference().' est bloqué !'));
  258.                     }
  259.                 }
  260.             }
  261.         }
  262.         if ( ! $form->isSubmitted() && is_object($commande->getCommande()) && $commande->getCommande()->getAbloquer()) {
  263.             $this->addFlash('warning'$translator->trans('La commande est bloquée !'));
  264.         }
  265.         if ($form->isSubmitted()) {
  266.             if ($form->isValid()) {
  267.                 //$this->container->get('dtc.commande')->creerHistorique($commande, 'dtc_gestioncomercialebundle_commande_transporteur');
  268.                 //$rendu = $this->renderView('layout-errors.html.twig');
  269.                 $rendu '';
  270.                 $url   '';
  271.                 $get $request->query->all();
  272.                 $this->addFlash('notice'$translator->trans('Anomalie ajoutée avec succès !'));
  273.                 if ( ! empty($get["type"]) && $get["type"] == "emballage") {
  274.                     $statutCommande $em->getRepository(StatutCommande::class)->find(33);
  275.                     $commande->setStatutCommande($statutCommande);
  276.                     $commandeService->creerHistorique($commande31, ["message" => " : ".$commande->getRaisonAnomalie()->getLibelle()]);
  277.                 } elseif ( ! empty($get["type"]) && $get["type"] == "etiquette") {
  278.                     $commandeService->creerHistorique($commande32, ["message" => " : ".$commande->getRaisonAnomalie()->getLibelle()]);
  279.                 }
  280.                 $em->persist($commande);
  281.                 $em->flush();
  282.                 $url "";
  283.                 if ( ! empty($get["type"]) && $get["type"] == "emballage" && ! empty($get["lp"]) && $get["lp"] != "") {
  284.                     $url $this->generateUrl('dtc_liste_preparation_simplifie_scan_produit_action', ["id" => $get["lp"]]);
  285.                 } elseif ( ! empty($get["type"]) && $get["type"] == "etiquette" && ! empty($get["lp"]) && $get["lp"] != "") {
  286.                     $url $this->generateUrl('dtc_liste_preparation_simplifie_scan_produit_action', ["id" => $get["lp"]]);
  287.                 } else {
  288.                     $url $this->generateUrl('dtcfo_homepage', ["ms" => "1"]);
  289.                 }
  290.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url], 200, ['Content-Type' => 'application/json']);
  291.             } else {
  292.                 $errors $validator->validate($commande);
  293.                 $rendu  $this->renderView('GestionComerciale/Anomalies/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
  294.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  295.             }
  296.         }
  297.         $rendu $this->renderView('GestionComerciale/Anomalies/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'commande' => $commande]);
  298.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  299.     }
  300. }