src/Controller/GestionComerciale/CommandeController.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\GestionComerciale\Commande;
  4. use App\Entity\GestionComerciale\StatutCommande;
  5. use App\Model\GestionCommerciale\TypeDocumentCommercial;
  6. use App\Form\GestionComerciale\CommandeType;
  7. use App\Library\Datatable\Util\Datatable;
  8. use App\Library\Uploader\Services\FileUploader;
  9. use App\Security\Voter\EntityVoter;
  10. use App\Service\GestionComerciale\EmailService;
  11. use App\Service\GestionComerciale\CommandeService;
  12. use App\Service\Taxes\TaxeService;
  13. use App\Service\Utilisateur\ColonneTableauService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use JMS\Serializer\SerializerBuilder;
  16. use Knp\Component\Pager\PaginatorInterface;
  17. use Knp\Snappy\Pdf;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\DependencyInjection\Container;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  25. use Symfony\Component\HttpFoundation\Cookie;
  26. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  27. use Symfony\Component\Validator\Validator\ValidatorInterface;
  28. use Symfony\Contracts\Translation\TranslatorInterface;
  29. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  30. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  31. class CommandeController extends AbstractController
  32. {
  33.     /**
  34.      * @Route("/compte/commande", name="dtc_commande_liste")
  35.      */
  36.     public function listerAction(Request $requestEntityManagerInterface $emDatatable $datatableTranslatorInterface $translatorColonneTableauService $serviceColonneTableau)
  37.     {
  38.         $tableau_class_cellule = array();
  39.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [0], "visible" => false"orderable" => true];
  40.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [1],"title"=>'<i style="font-size:1.5em;" class="fa fa-clipboard">'"visible" => true"orderable" => true];
  41.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-left""targets" => [2], "visible" => true"orderable" => true];
  42.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-right""targets" => [3],"title"=>'<i style="font-size:1.5em;" class="fa fa-calendar"> <b>/</b> <i style="" class="fa fa-euro">&nbsp;&nbsp; '"visible" => true"orderable" => true];
  43.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [4],"title"=>'<i style="font-size:1.5em;" class="fa fa-gear">'"visible" => true"orderable" => false];
  44.         $response = new Response();
  45.         $this->datatable($request$em$datatable$translator$response);
  46.         $param $request->query->all();
  47.         return $this->render('GestionComerciale/Commande/lister.html.twig',
  48.             [
  49.                 'tableauClassColonne' => $tableau_class_cellule,
  50.                 'parametres'=> $param,
  51.             ]
  52.             ,$response);
  53.     }
  54.     /**
  55.      * set datatable configs
  56.      *
  57.      * @return \App\Library\Datatable\Util\Datatable
  58.      */
  59.     private function datatable(Request $requestEntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  60.     {
  61.         $user $this->getUser();
  62.         $param $request->query->all();
  63.         $datatable
  64.             ->setDatatableId('liste_commande')
  65.             ->setEntity(Commande::class, "x")
  66.             ->setFields(
  67.                 [
  68.                     $translator->trans("ID")              => 'x.id',
  69.                     'date' => 'x.date',
  70.                     $translator->trans("RÉFÉRENCE")             => 'x.reference',
  71.                     $translator->trans("Total HT")             => 'x.total',
  72.                     $translator->trans("Actions")      => 'x.id',
  73.                     "_identifier_"                     => 'x.id',
  74.                 ]
  75.             )
  76.             //->addJoin('x.transporteur', 't', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  77.             ->addJoin('x.statutCommande''s'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  78.             ->addJoin('x.utilisateur''u'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  79.             ->setRenderers(
  80.                 [
  81.                     => [
  82.                         'view' => 'FO/DataTable/type_document_vente.html.twig',
  83.                     ],
  84.                     => [
  85.                         'view' => 'FO/DataTable/reference_document_commercail.html.twig',
  86.                     ],
  87.                     /*
  88.                     2 => [
  89.                         'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  90.                         'params' => [
  91.                             'edit_route' => 'dtc_commande_liste',
  92.                         ],
  93.                     ],
  94.                     */
  95.                     => [
  96.                         'view' => 'FO/DataTable/prix_commande_heure.html.twig',
  97.                     ],
  98.                     => [
  99.                         'view'   => 'FO/DataTable/actions.html.twig',
  100.                         'params' => [
  101.                             'edit_route'                  => 'dtc_commande_liste',
  102.                             'objet'                       => Commande::class,
  103.                             'deplier'                     => false,
  104.                             'table'                       => "liste_commande",
  105.                         ],
  106.                     ],
  107.                 ]
  108.             )
  109.             ->setMultiple([])
  110.             ->setOrder("x.date""desc")
  111.             ->setSearch(true)
  112.             ->setSearchFields([]);
  113.         $where "x.typeDocumentCommercial = :typeDocumentCommercial and x.client = :client and x.statutCommande != :statutLivre and x.statutCommande != :statutAnnule";
  114.         $client_id 10000000000000;
  115.         if($user->getClient())  $client_id $user->getClient()->getId();
  116.         $parameters = ['typeDocumentCommercial' => TypeDocumentCommercial::COMMANDE,'client'=>$client_id,'statutLivre'=>29,'statutAnnule'=>7];
  117.         if (array_key_exists('parametres'$param)) {
  118.             $response = new Response();
  119.             if (array_key_exists('client'$param["parametres"]) and $param["parametres"]["client"] > 0) {
  120.                 //$datatable->addJoin('x.client', 'client', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  121.                 $parameters["client"] = $param["parametres"]["client"];
  122.                 if ($where != "") {
  123.                     $where .= " AND ";
  124.                 }
  125.                 $where .= "c.id = :client";
  126.             }
  127.             if (array_key_exists('date_debut'$param["parametres"]) and $param["parametres"]["date_debut"] != "") {
  128.                 $param["parametres"]["date_debut"] = \DateTime::createFromFormat('d/m/Y'$param["parametres"]["date_debut"]);
  129.                 $param["parametres"]["date_debut"]->setTime(000000);
  130.                 $parameters["date_debut"] = $param["parametres"]["date_debut"];
  131.                 if ($where != "") {
  132.                     $where .= " AND ";
  133.                 }
  134.                 $where .= "x.date >= :date_debut";
  135.             }
  136.             if (array_key_exists('transporteur'$param["parametres"]) and $param["parametres"]["transporteur"] > 0) {
  137.                 //$datatable->addJoin('x.client', 'client', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  138.                 $parameters["transporteur"] = $param["parametres"]["transporteur"];
  139.                 if ($where != "") {
  140.                     $where .= " AND ";
  141.                 }
  142.                 $where .= "t.id = :transporteur";
  143.             }
  144.             if (array_key_exists('date_fin'$param["parametres"]) and $param["parametres"]["date_fin"] != "") {
  145.                 $param["parametres"]["date_fin"] = \DateTime::createFromFormat('d/m/Y'$param["parametres"]["date_fin"]);
  146.                 $param["parametres"]["date_fin"]->setTime(235959);
  147.                 $parameters["date_fin"] = $param["parametres"]["date_fin"];
  148.                 if ($where != "") {
  149.                     $where .= " AND ";
  150.                 }
  151.                 $where .= "x.date <= :date_fin";
  152.             }
  153.         }
  154.         if ($where != '') {
  155.             $datatable->setWhere($where$parameters);
  156.             $qb $datatable->getQueryBuilder()->getDoctrineQueryBuilder();
  157.         }
  158.         return $datatable;
  159.     }
  160.     /**
  161.      * @Route("/compte/commande/grid", name="dtc_commande_liste_grid")
  162.      */
  163.     public function gridAction(Request $requestEntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  164.     {
  165.         return $this->datatable($request$em$datatable$translator)->execute();
  166.     }
  167.     /**
  168.      * @Route("/compte/commande/pdf/{id}", name="dtc_commande_pdf", requirements={"id"="\d+"})
  169.      */
  170.     public function showPdf(Commande $commande,CommandeService $commandeService): Response
  171.     {
  172.         $user $this->getUser();
  173.         if(is_object($user->getClient()) && $user->getClient()->getId() == $commande->getClient()->getId()) {
  174.             if( $commande->getIdImport() > 0) {
  175.                 $commandeService->importDocumentsErp($commande->getClient()->getId(),["devis","commandes","bls","factures"],["log"=>false,"id_doc_erp"=>$commande->getIdImport()],NULL);
  176.             }
  177.             $response $commandeService->getPdfDocument($commande);
  178.             if (!$response) {
  179.                 throw $this->createNotFoundException("PDF introuvable");
  180.             }
  181.         }
  182.         else {
  183.             throw $this->createNotFoundException("Non autorisé");
  184.         }
  185.         return $response;
  186.     }
  187. }