src/Controller/Adresses/AdresseController.php line 564

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Adresses;
  3. use App\Entity\Adresses\Adresse;
  4. use App\Entity\Articles\ArticleAutomatique;
  5. use App\Entity\Clients\Client;
  6. use App\Entity\Fournisseurs\Fournisseur;
  7. use App\Entity\GestionComerciale\Commande;
  8. use App\Entity\Localisation\Type;
  9. use App\Entity\Localisation\Zone;
  10. use App\Entity\Transporteurs\Transporteur;
  11. use App\Entity\Utilisateur\Utilisateur;
  12. use App\Entity\Utilisateur\UtilisateurZoneGeographique;
  13. use App\Form\Adresses\AdresseType;
  14. use App\Form\Adresses\SupprimerAdresseType;
  15. use App\Library\Datatable\Util\Datatable;
  16. use App\Security\Voter\EntityVoter;
  17. use App\Service\Adresses\AdresseService;
  18. use App\Service\Clients\ClientService;
  19. use App\Service\Fournisseurs\FournisseurService;
  20. use App\Service\Utilisateur\ColonneTableauService;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use DTS\eBaySDK\FileTransfer\Types\Data;
  23. use JMS\Serializer\SerializerBuilder;
  24. use Knp\Component\Pager\PaginatorInterface;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\JsonResponse;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use Symfony\Component\Security\Core\Security;
  31. use Symfony\Component\Validator\Validator\ValidatorInterface;
  32. use Symfony\Contracts\Translation\TranslatorInterface;
  33. class AdresseController extends AbstractController
  34. {
  35.     /**
  36.      * @Route("/adresse/nouveau/{id}/{type}", name="dtc_adresse_ajouter")
  37.      */
  38.     public function ajouterAction(Request            $requeststring $idstring $typeSecurity $securityEntityManagerInterface $emTranslatorInterface $translator,
  39.                                   ValidatorInterface $validatorFournisseurService $fournisseurServiceClientService $clientServiceAdresseService $adresseService
  40.     ) {
  41.         $titre_modal $translator->trans("Nouvelle adresse");
  42.         $page        $request->query->get('page');
  43.         $adresse     = new Adresse();
  44.         /** @var Utilisateur $user */
  45.         $user $security->getUser();
  46.         $adresse->setUtilisateur($user);
  47.         $get $request->query->all();
  48.         $france $em->getRepository(Zone::class)->find(370095);
  49.         $adresse->setPays($france);
  50.         $repo_utilisateur_zone_geographique $em->getRepository(UtilisateurZoneGeographique::class);
  51.         $form   $this->createForm(AdresseType::class, $adresse);
  52.         $errors "";
  53.         $form->handleRequest($request);
  54.         if ($form->isSubmitted()) {
  55.             $post $request->request->all();
  56.             if ($form->isValid()) {
  57.                 if ($type == 'client') {
  58.                     $repo_objet $em->getRepository(Client::class);
  59.                     $objet      $repo_objet->find($id);
  60.                     $adresse->setClient($objet);
  61.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $objet->getId(), 'tab' => 'adresses']);
  62.                 } elseif ($type == 'transporteur') {
  63.                     $repo_objet $em->getRepository(Transporteur::class);
  64.                     $objet      $repo_objet->find($id);
  65.                     $adresse->setTransporteur($objet);
  66.                     $url $this->generateUrl('dtc_transporteur_modifier', ['id' => $objet->getId(), 'tab' => 'adresses']);
  67.                 } elseif ($type == 'fournisseur') {
  68.                     $repo_objet $em->getRepository(Fournisseur::class);
  69.                     $objet      $repo_objet->find($id);
  70.                     $adresse->setFournisseur($objet);
  71.                     $url $this->generateUrl('dtc_fournisseur_modifier', ['id' => $objet->getId(), 'tab' => 'adresses']);
  72.                 } elseif ($type == 'commande') {
  73.                     $repo_objet $em->getRepository(Commande::class);
  74.                     $objet      $repo_objet->find($id);
  75.                     $client     $objet->getClient();
  76.                     $adresse->setClient($client);
  77.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $client->getId(), 'tab' => 'adresses']);
  78.                 }
  79.                 //echo "===>";
  80.                 if ( ! is_object($adresse->getPays())) {
  81.                     //echo "ERREUR PAYS";
  82.                     if ($post["paysSelect"] != '') {
  83.                         $post["paysSelect"] = substr($post["paysSelect"], 1, -1);
  84.                         $typePays $em->getRepository(Type::class)->find(1);
  85.                         $pays     = new Zone();
  86.                         $pays->setTitre($post["paysSelect"]);
  87.                         $pays->setTitreFormat($post["paysSelect"]);
  88.                         $pays->setType($typePays);
  89.                         $pays->setUtilisateur($user);
  90.                         $em->persist($pays);
  91.                         $adresse->setPays($pays);
  92.                         $post $request->request->all();
  93.                     } else {
  94.                         $adresse->setPays(null);
  95.                     }
  96.                 } else {
  97.                     $pays $adresse->getPays();
  98.                 }
  99.                 if ( ! is_object($adresse->getVille())) {
  100.                     if ($post["villeSelect"] != '') {
  101.                         $post["villeSelect"]      = substr($post["villeSelect"], 1, -1);
  102.                         $post["codePostalSelect"] = substr($post["codePostalSelect"], 1, -1);
  103.                         $typeVille $em->getRepository(Type::class)->find(4);
  104.                         $ville     = new Zone();
  105.                         $ville->setTitre($post["villeSelect"]);
  106.                         $ville->setTitreFormat($post["villeSelect"]);
  107.                         $ville->setCodePostal($post["codePostalSelect"]);
  108.                         $ville->setType($typeVille);
  109.                         if (is_object($pays)) {
  110.                             $ville->setPaysId($pays);
  111.                         }
  112.                         $ville->setUtilisateur($user);
  113.                         if ($ville->getParentId() == null and $post["dtc_adressesbundle_adresse"]['zoneLivraison'] != "") {
  114.                             $zonelivraison $post["dtc_adressesbundle_adresse"]['zoneLivraison'];
  115.                             $repo_zone        $em->getRepository(Zone::class);
  116.                             $newzonelivraison $repo_zone->findOneBy(['zoneLivraison' => $zonelivraison]);
  117.                             $ville->setParentId($newzonelivraison);
  118.                         }
  119.                         $em->persist($ville);
  120.                         $adresse->setVille($ville);
  121.                         $adresse->setCodePostal($ville);
  122.                         $post $request->request->all();
  123.                     } else {
  124.                         $adresse->setVille(null);
  125.                         $adresse->setCodePostal(null);
  126.                     }
  127.                 } else {
  128.                     $ville $adresse->getVille();
  129.                 }
  130.                 //print_r($post);
  131.                 // exit;
  132.                 $em->persist($adresse);
  133.                 $em->flush();
  134.                 if ($type == 'fournisseur') {
  135.                     $em->refresh($adresse);
  136.                     $message_historique            = [];
  137.                     $message_historique["titre"]   = "Création d'une nouvelle adresse";
  138.                     $message_historique["message"] = $adresse->getLibelle()." (id : ".$adresse->getId().")";
  139.                     $fournisseurService->creerHistorique($objet'defaut'$message_historique);
  140.                 } elseif ($type == 'client') {
  141.                     $em->refresh($adresse);
  142.                     $message_historique            = [];
  143.                     $message_historique["titre"]   = "Création d'une nouvelle adresse";
  144.                     $message_historique["message"] = $adresse->getLibelle()." (id : ".$adresse->getId().")";
  145.                     $clientService->creerHistorique($objet'defaut'$message_historique);
  146.                 }
  147.                 $adresseService->sauvegarderLatLngAdresse($adresse);
  148.                 if (is_object($objet)) {
  149.                     $this->majAdressesParDefaut($adresse$objet$em);
  150.                 }
  151.                 if ($page == 'commande' || $page == 'commandeF') {
  152.                     $pays_obj null;
  153.                     $pays_id  null;
  154.                     $pro      null;
  155.                     $dataTva  1;
  156.                     $paysUe   "0";
  157.                     if (is_object($adresse->getPays())) {
  158.                         if ($adresse->getPays()->getId() != "370095" && $adresse->getPays()->getEurope()) {
  159.                             $paysUe "1";
  160.                         }
  161.                         if ($pro == && $adresse->getPays()->getId() != "370095") {
  162.                             $dataTva 0;
  163.                         }
  164.                         if ($pro == && $adresse->getPays()->getEurope() == false) {
  165.                             $dataTva 0;
  166.                         }
  167.                         $pays_obj $adresse->getPays();
  168.                         $pays_id  $adresse->getPays()->getId();
  169.                     }
  170.                     if (is_object($adresse->getClient()) && is_object($adresse->getClient()->getCompta()) && $adresse->getClient()->getCompta()->getTva() == 0) {
  171.                         //    echo "eeee";
  172.                         $dataTva 0;
  173.                     }
  174.                     $data_societe               "";
  175.                     $data_numero                "";
  176.                     $data_rue                   "";
  177.                     $data_complement            "";
  178.                     $data_complement2           "";
  179.                     $data_cp                    "";
  180.                     $data_ville                 "";
  181.                     $data_secteur               "";
  182.                     $data_secteur_libelle       "";
  183.                     $data_secteur_obj           "";
  184.                     $data_commercial            "";
  185.                     $data_assistante_commercial "";
  186.                     $data_societe      $adresse->getSociete();
  187.                     $data_numero       $adresse->getNumero();
  188.                     $data_rue          $adresse->getRue();
  189.                     $data_complement   $adresse->getComplement();
  190.                     $data_complement_2 $adresse->getComplement2();
  191.                     if (is_object($adresse->getCodePostal())) {
  192.                         $data_cp $adresse->getCodePostal()->getCodePostal();
  193.                     }
  194.                     if (is_object($adresse->getVille())) {
  195.                         $data_ville $adresse->getVille()->getTitre();
  196.                     }
  197.                     $repo_zone $em->getRepository(Zone::class);
  198.                     if ($data_cp != "") {
  199.                         $data_secteur_obj $repo_zone->findSecteurGeograhiqueByCodePostal($data_cp$pays_id);
  200.                         //echo "XXX";
  201.                     }
  202.                     if ( ! is_object($data_secteur_obj) && is_object($pays_obj) && is_object($pays_obj->getSecteurGeographique())) {
  203.                         $data_secteur_obj $pays_obj;
  204.                         //echo "YYYY";
  205.                     }
  206.                     //echo "AAAA";
  207.                     if (is_object($data_secteur_obj) && is_object($data_secteur_obj->getSecteurGeographique())) {
  208.                         $data_secteur               $data_secteur_obj->getSecteurGeographique()->getId();
  209.                         $data_secteur_libelle       $data_secteur_obj->getSecteurGeographique()->getLibelle();
  210.                         $data_assistante_commercial $repo_utilisateur_zone_geographique->findAssistanteCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  211.                         $data_commercial            $repo_utilisateur_zone_geographique->findCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  212.                     }
  213.                     if (is_object($data_secteur_obj) && is_object($data_secteur_obj->getSecteurGeographique())) {
  214.                         $data_secteur               $data_secteur_obj->getSecteurGeographique()->getId();
  215.                         $data_secteur_libelle       $data_secteur_obj->getSecteurGeographique()->getLibelle();
  216.                         $data_assistante_commercial $repo_utilisateur_zone_geographique->findAssistanteCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  217.                         $data_commercial            $repo_utilisateur_zone_geographique->findCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  218.                     }
  219.                     $tab_rendu = [
  220.                         'rendu'      => '',
  221.                         'valide'     => '1',
  222.                         'url'        => '',
  223.                         'type'       => $request->query->get('type_adresse'),
  224.                         'libelle'    => $adresse->getLibelle(),
  225.                         'id_adresse' => $adresse->getId(),
  226.                     ];
  227.                     $tab_rendu['pro']                   = $pro;
  228.                     $tab_rendu['ue']                    = $paysUe;
  229.                     $tab_rendu['tva']                   = $dataTva;
  230.                     $tab_rendu['societe']               = $data_societe;
  231.                     $tab_rendu['numero']                = $data_numero;
  232.                     $tab_rendu['rue']                   = $data_rue;
  233.                     $tab_rendu['complement']            = $data_complement;
  234.                     $tab_rendu['complement2']           = $data_complement2;
  235.                     $tab_rendu['cp']                    = $data_cp;
  236.                     $tab_rendu['ville']                 = $data_ville;
  237.                     $tab_rendu['secteur']               = $data_secteur;
  238.                     $tab_rendu['secteur-libelle']       = $data_secteur_libelle;
  239.                     $tab_rendu['commercial']            = $data_commercial;
  240.                     $tab_rendu['assistante-commercial'] = $data_assistante_commercial;
  241.                     return new Response(json_encode($tab_rendu));
  242.                 } else {
  243.                     if (array_key_exists('table'$get) && $get["table"] != "") {
  244.                         return new Response(
  245.                             json_encode(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]),
  246.                             200,
  247.                             ['Content-Type' => 'application/json']
  248.                         );
  249.                     } else {
  250.                         $this->addFlash('notice',$translator->trans('Adresse ajoutée avec succès !'));
  251.                         return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  252.                     }
  253.                 }
  254.             } else {
  255.                 $errors $validator->validate($adresse);
  256.                 $rendu  $this->renderView('Adresses/Adresse/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  257.                 return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]));
  258.             }
  259.         }
  260.         $repo_objet $em->getRepository(Client::class);
  261.         $client     $repo_objet->find($id);
  262.         $rendu $this->renderView('Adresses/Adresse/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'client' => $client]
  263.         );
  264.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  265.         //return $this->render('Adresses/Adresse/ajouter.html.twig', array('form' => $form->createView(),'errors'=>$errors,'id'=>$id,'type'=>$type));
  266.     }
  267.     /**
  268.      * @Route("/adresse/modifier/{objet}/{id}/{type}", name="dtc_adresse_modifier")
  269.      */
  270.     public function modifierAction(Request                $requestAdresse $objet$id$typeTranslatorInterface $translatorValidatorInterface $validator,
  271.                                    EntityManagerInterface $emFournisseurService $fournisseurServiceClientService $clientServiceAdresseService $adresseService
  272.     ) {
  273.         $adresse     $objet;
  274.         $titre_modal $translator->trans("Modifier adresse");
  275.         $get         $request->query->all();
  276.         /** @var Utilisateur $user */
  277.         $user $this->getUser();
  278.         $adresse->setUtilisateur($user);
  279.         $form   $this->createForm(AdresseType::class, $adresse);
  280.         $errors "";
  281.         $form->handleRequest($request);
  282.         $post $request->request->all();
  283.         if ($form->isSubmitted() && $adresse->getIdPrestashop() == '') {
  284.             $droit $this->isGranted(EntityVoter::UPDATEAdresse::class);
  285.             if ( ! $droit) {
  286.                 $rendu $this->renderView(
  287.                     'Adresses/Adresse/ajouter.html.twig',
  288.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]
  289.                 );
  290.                 return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]));
  291.             }
  292.             if ($form->isValid()) {
  293.                 if ($type == 'client') {
  294.                     $repo_objet $em->getRepository(Client::class);
  295.                     $objet      $repo_objet->find($id);
  296.                     $adresse->setClient($objet);
  297.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $objet->getId(), 'tab' => 'adresses']);
  298.                 } elseif ($type == 'transporteur') {
  299.                     $repo_objet $em->getRepository(Transporteur::class);
  300.                     $objet      $repo_objet->find($id);
  301.                     $adresse->setTransporteur($objet);
  302.                     $url $this->generateUrl('dtc_transporteur_modifier', ['id' => $objet->getId(), 'tab' => 'adresses']);
  303.                 } elseif ($type == 'fournisseur') {
  304.                     $repo_objet $em->getRepository(Fournisseur::class);
  305.                     $objet      $repo_objet->find($id);
  306.                     $adresse->setFournisseur($objet);
  307.                     $url $this->generateUrl('dtc_fournisseur_modifier', ['id' => $objet->getId(), 'tab' => 'adresses']);
  308.                 }
  309.                 if ( ! is_object($adresse->getPays())) {
  310.                     //echo "ERREUR PAYS";
  311.                     if ($post["paysSelect"] != '') {
  312.                         $post["paysSelect"] = substr($post["paysSelect"], 1, -1);
  313.                         $typePays $em->getRepository(Type::class)->find(1);
  314.                         $pays     = new Zone();
  315.                         $pays->setTitre($post["paysSelect"]);
  316.                         $pays->setTitreFormat($post["paysSelect"]);
  317.                         $pays->setType($typePays);
  318.                         $pays->setUtilisateur($user);
  319.                         $em->persist($pays);
  320.                         $adresse->setPays($pays);
  321.                         $post $request->request->all();
  322.                     } else {
  323.                         $adresse->setPays(null);
  324.                     }
  325.                 } else {
  326.                     $pays $adresse->getPays();
  327.                 }
  328.                 if ( ! is_object($adresse->getVille())) {
  329.                     if ($post["villeSelect"] != '') {
  330.                         $post["villeSelect"]      = substr($post["villeSelect"], 1, -1);
  331.                         $post["codePostalSelect"] = substr($post["codePostalSelect"], 1, -1);
  332.                         $typeVille $em->getRepository(Type::class)->find(4);
  333.                         $ville     = new Zone();
  334.                         $ville->setTitre($post["villeSelect"]);
  335.                         $ville->setTitreFormat($post["villeSelect"]);
  336.                         $ville->setCodePostal($post["codePostalSelect"]);
  337.                         $ville->setType($typeVille);
  338.                         if (is_object($pays)) {
  339.                             $ville->setPaysId($pays);
  340.                         }
  341.                         $ville->setUtilisateur($user);
  342.                         $em->persist($ville);
  343.                         $adresse->setVille($ville);
  344.                         $adresse->setCodePostal($ville);
  345.                         $post $request->request->all();
  346.                     } else {
  347.                         $adresse->setVille(null);
  348.                         $adresse->setCodePostal(null);
  349.                     }
  350.                 } else {
  351.                     $ville $adresse->getVille();
  352.                 }
  353.                 $em->persist($adresse);
  354.                 $em->flush();
  355.                 if ($type == 'fournisseur') {
  356.                     $em->refresh($adresse);
  357.                     $message_historique            = [];
  358.                     $message_historique["titre"]   = "Modification d'une adresse";
  359.                     $message_historique["message"] = $adresse->getLibelle()." (id : ".$adresse->getId().")";
  360.                     $fournisseurService->creerHistorique($objet'defaut'$message_historique);
  361.                 } elseif ($type == 'client') {
  362.                     $em->refresh($adresse);
  363.                     $message_historique            = [];
  364.                     $message_historique["titre"]   = "Modification d'une adresse";
  365.                     $message_historique["message"] = $adresse->getLibelle()." (id : ".$adresse->getId().")";
  366.                     $clientService->creerHistorique($objet'defaut'$message_historique);
  367.                 }
  368.                 $adresseService->sauvegarderLatLngAdresse($adresse);
  369.                 if (is_object($objet)) {
  370.                     $this->majAdressesParDefaut($adresse$objet$em);
  371.                 }
  372.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  373.                     return new Response(
  374.                         json_encode(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]),
  375.                         200,
  376.                         ['Content-Type' => 'application/json']
  377.                     );
  378.                 } else {
  379.                     $this->addFlash('notice',$translator->trans('Adresse modifié avec succès !'));
  380.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  381.                 }
  382.             } else {
  383.                 $errors $validator->validate($adresse);
  384.                 $rendu  $this->renderView(
  385.                     'Adresses/Adresse/ajouter.html.twig',
  386.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet'adresse' => $adresse]
  387.                 );
  388.                 return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]));
  389.             }
  390.         }
  391.         $rendu $this->renderView(
  392.             'Adresses/Adresse/ajouter.html.twig',
  393.             ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet'adresse' => $adresse]
  394.         );
  395.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal], 200);
  396.     }
  397.     /**
  398.      * @Route("/adresse/supprimer/{objet}/{id}/{type}", name="dtc_adresse_supprimer")
  399.      */
  400.     public function supprimerAction(Request $requestAdresse $objet$id$typeEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  401.     {
  402.         $adresse     $objet;
  403.         $titre_modal $translator->trans("Demande de confirmation");
  404.         $user        $this->getUser();
  405.         $get         $request->query->all();
  406.         $form        $this->createForm(SupprimerAdresseType::class, $adresse);
  407.         $errors      "";
  408.         $form->handleRequest($request);
  409.         if ($form->isSubmitted()) {
  410.             if ($form->isValid()) {
  411.                 $em->remove($adresse);
  412.                 $em->flush();
  413.                 if ($type == 'client') {
  414.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $id'tab' => 'adresses']);
  415.                 } elseif ($type == 'transporteur') {
  416.                     $url $this->generateUrl('dtc_transporteur_modifier', ['id' => $id'tab' => 'adresses']);
  417.                 } elseif ($type == 'fournisseur') {
  418.                     $url $this->generateUrl('dtc_fournisseur_modifier', ['id' => $id'tab' => 'adresses']);
  419.                 }
  420.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  421.                     return new Response(
  422.                         json_encode(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]),
  423.                         200,
  424.                         ['Content-Type' => 'application/json']
  425.                     );
  426.                 } else {
  427.                     $this->addFlash('notice',$translator->trans('Adresse supprimée avec succès !'));
  428.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  429.                 }
  430.             } else {
  431.                 $errors $validator->validate($adresse);
  432.                 $rendu  $this->renderView(
  433.                     'FO/Supprimer/supprimer.html.twig',
  434.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]
  435.                 );
  436.                 return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]));
  437.             }
  438.         }
  439.         $rendu $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]);
  440.         return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]));
  441.     }
  442.     private function datatable($objet$type ""Datatable $datatableTranslatorInterface $translator)
  443.     {
  444.         $type_jointure 'x.'.$type;
  445.         $datatable->setDatatableId('dta-adresses')
  446.                   ->setEntity(Adresse::class, "x")
  447.                   ->setFields(
  448.                       [
  449.                           //$translator->trans("ID") =>  'x.id',
  450.                          $translator->trans("Libellé")      => 'x.libelle',
  451.                          $translator->trans("Numéro")       => 'x.numero',
  452.                          $translator->trans("Rue")          => 'x.rue',
  453.                          $translator->trans("Complément")   => 'x.complement',
  454.                          $translator->trans("Complément 2") => 'x.complement2',
  455.                          $translator->trans("Code postal")  => 'cp.codePostal',
  456.                          $translator->trans("Ville")        => 'v.titre',
  457.                          $translator->trans("Pays")         => 'p.titre',
  458.                          $translator->trans("Facturation")    => 'x.facturationDefaut',
  459.                          $translator->trans("Livraison")      => 'x.livraisonDefaut',
  460.                          $translator->trans("Expédition Fac") => 'x.facturationExpeditionDefaut',
  461.                          $translator->trans("Actions") => 'x.id',
  462.                           "_identifier_"                             => 'x.id',
  463.                       ]
  464.                   )
  465.                   ->addJoin('x.ville''v'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  466.                   ->addJoin('x.codePostal''cp'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  467.                   ->addJoin('x.pays''p'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  468.                   ->setWhere(
  469.                       $type_jointure.' = :objet AND x.visible = 1',
  470.                       ['objet' => $objet]
  471.                   )
  472.                   ->setRenderers(
  473.                       [
  474.                           => [
  475.                               'view'   => 'FO/DataTable/abreviation.html.twig',
  476.                               'params' => [],
  477.                           ],
  478.                           => [
  479.                               'view'   => 'FO/DataTable/abreviation.html.twig',
  480.                               'params' => [],
  481.                           ],
  482.                           => [
  483.                               'view'   => 'FO/DataTable/abreviation.html.twig',
  484.                               'params' => [],
  485.                           ],
  486.                           => [
  487.                               'view'   => 'FO/DataTable/abreviation.html.twig',
  488.                               'params' => [],
  489.                           ],
  490.                           => [
  491.                               'view'   => 'FO/DataTable/abreviation.html.twig',
  492.                               'params' => [],
  493.                           ],
  494.                           8  => [
  495.                               'view'   => 'FO/DataTable/booleen.html.twig',
  496.                               'params' => [],
  497.                           ],
  498.                           9  => [
  499.                               'view'   => 'FO/DataTable/booleen.html.twig',
  500.                               'params' => [],
  501.                           ],
  502.                           10 => [
  503.                               'view'   => 'FO/DataTable/booleen.html.twig',
  504.                               'params' => [],
  505.                           ],
  506.                           11 => [
  507.                               'view'   => 'FO/DataTable/actions_modal.html.twig',
  508.                               'params' => [
  509.                                   'edit_route'       => 'dtc_adresse_modifier',
  510.                                   'supprimer_route'  => 'dtc_adresse_supprimer',
  511.                                   'id'               => $objet->getId(),
  512.                                   'type'             => $type,
  513.                                   'entite'           => 'adresse',
  514.                                   'objet'            => Adresse::class,
  515.                                   'table'            => "dta-adresses",
  516.                                   'history'          => true,
  517.                                   'visualiser_route' => 'dtc_adresse_visualiser_map',
  518.                               ],
  519.                           ],
  520.                           /*0=> array(
  521.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  522.                               'params' => array(
  523.                                       'objet'    => 'DTCAdressesBundle:Adresse',
  524.                                       'champ'    => 'setLibelle',
  525.                                   ),
  526.                           ),
  527.                           1=> array(
  528.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  529.                               'params' => array(
  530.                                       'objet'    => 'DTCAdressesBundle:Adresse',
  531.                                       'champ'    => 'setNumero',
  532.                                   ),
  533.                           ),
  534.                           2=> array(
  535.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  536.                               'params' => array(
  537.                                       'objet'    => 'DTCAdressesBundle:Adresse',
  538.                                       'champ'    => 'setRue',
  539.                                   ),
  540.                           ),
  541.                           3=> array(
  542.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  543.                               'params' => array(
  544.                                       'objet'    => 'DTCAdressesBundle:Adresse',
  545.                                       'champ'    => 'setComplement',
  546.                                   ),
  547.                           ),
  548.                           4=> array(
  549.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  550.                               'params' => array(
  551.                                       'objet'    => 'DTCAdressesBundle:Adresse',
  552.                                       'champ'    => 'setComplement2',
  553.                                   ),
  554.                           ),*/
  555.                       ]
  556.                   )
  557.                   ->setOrder("x.id""asc")
  558.                   ->setSearch(true)
  559.                   ->setSearchFields([]);
  560.         return $datatable;
  561.     }
  562.     /**
  563.      * @Route("/adresse/grid/{id}/{type}", name="dtc_adresse_liste_grid")
  564.      */
  565.     public function gridAction($id ""$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  566.     {
  567.         if ($type == 'client') {
  568.             $repo_objet $em->getRepository(Client::class);
  569.             $objet      $repo_objet->find($id);
  570.         } elseif ($type == 'transporteur') {
  571.             $repo_objet $em->getRepository(Transporteur::class);
  572.             $objet      $repo_objet->find($id);
  573.         } elseif ($type == 'fournisseur') {
  574.             $repo_objet $em->getRepository(Fournisseur::class);
  575.             $objet      $repo_objet->find($id);
  576.         }
  577.         return $this->datatable($objet$type$datatable,  $translator)->execute();
  578.     }
  579.     /**
  580.      * @Route("/adresse/client/{id}", name="dtc_liste_adresse_client")
  581.      */
  582.     public function listerAdresseClientAction(Request $request$idEntityManagerInterface $emClientService $clientService)
  583.     {
  584.         $options            '';
  585.         $optionsLivraison   '';
  586.         $optionsFacturation '';
  587.         $transporteurDefaut '';
  588.         $optionsVehicule    '';
  589.         $ArticlesAuto       = [];
  590.         $pro                "0";
  591.         $cpt                0;
  592.         $type               $request->query->get('type');
  593.         $adresseLivraisonId "";
  594.         $repo_client   $em->getRepository(Client::class);
  595.         $repo_adresse  $em->getRepository(Adresse::class);
  596.         $repo_commande $em->getRepository(Commande::class);
  597.         $repo_utilisateur_zone_geographique $em->getRepository(UtilisateurZoneGeographique::class);
  598.         $repo_zone                          $em->getRepository(Zone::class);
  599.         if ($type == 'commande') {
  600.             $commande $repo_commande->find($id);
  601.             if (is_object($commande->getAdresseLivraison())) {
  602.                 $adresseLivraisonId $commande->getAdresseLivraison()->getId();
  603.             }
  604.             $client $commande->getClient();
  605.         } else {
  606.             $client $repo_client->find($id);
  607.         }
  608.         $est_pro $clientService->estPro($client);
  609.         if ($est_pro) {
  610.             $pro "1";
  611.         }
  612.         $repoArticleAutomatique $em->getRepository(ArticleAutomatique::class);
  613.         $ArticlesAuto = [];
  614.         if ($client->getAccepteProduitAuto() or is_null($client->getAccepteProduitAuto())) {
  615.             $ArticlesAuto $repoArticleAutomatique->getArticlesAutomatiqueDisponible($client);
  616.         }
  617.         /*
  618.         if(is_object($client->getTypeClient())) {
  619.             if($client->getTypeClient()->getId() == "2") $pro = "1";
  620.         }
  621.         */
  622.         $paysUe   "0";
  623.         $dataTva  1;
  624.         $adresses $repo_adresse->findBy(['client' => $client'visible' => 1]);
  625.         //foreach($client->getAdresses() as $adresse){
  626.         foreach ($adresses as $adresse) {
  627.             $selected            "";
  628.             $selectedLivraison   "";
  629.             $selectedFacturation "";
  630.             $paysUe              "0";
  631.             $dataTva             1;
  632.             $pays_obj null;
  633.             $pays_id  null;
  634.             if (is_object($adresse->getPays())) {
  635.                 if ($adresse->getPays()->getId() != "370095" && $adresse->getPays()->getEurope()) {
  636.                     $paysUe "1";
  637.                 }
  638.                 if ($pro == && $adresse->getPays()->getId() != "370095") {
  639.                     $dataTva 0;
  640.                 }
  641.                 if ($pro == && $adresse->getPays()->getEurope() == false) {
  642.                     $dataTva 0;
  643.                 }
  644.                 $pays_obj $adresse->getPays();
  645.                 $pays_id  $adresse->getPays()->getId();
  646.             }
  647.             //echo "BBBB ".$client->getCompta()->getId();
  648.             if (is_object($client->getCompta()) && $client->getCompta()->getTva() == 0) {
  649.                 //    echo "eeee";
  650.                 $dataTva 0;
  651.             }
  652.             if ($type == 'commande') {
  653.                 if ($adresseLivraisonId == $adresse->getId()) {
  654.                     $selected 'selected="selected"';
  655.                 }
  656.             }
  657.             if ($adresse->getLivraisonDefaut() == 1) {
  658.                 $selectedLivraison 'selected="selected"';
  659.             }
  660.             if ($adresse->getFacturationDefaut() == 1) {
  661.                 $selectedFacturation 'selected="selected"';
  662.             }
  663.             /*
  664.            if(is_object($client->)) {
  665.            }
  666.            */
  667.             //if($cpt == 0) $selected = 'selected="selected"';
  668.             //$options .='<option '.$selected.' data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId().'">'.$adresse->getLibelle().'</option>';
  669.             $data_liv_cp    "";
  670.             $data_liv_ville "";
  671.             $data_liv_pays  "";
  672.             $data_fac_cp    "";
  673.             $data_fac_ville "";
  674.             $data_fac_pays  "";
  675.             $libelleAdresse $adresse->getLibelle()." ";
  676.             //$libelleAdresse = "";
  677.             if ($adresse->getNumero() != "") {
  678.                 $libelleAdresse .= $adresse->getNumero().', ';
  679.             }
  680.             if ($adresse->getRue() != "") {
  681.                 $libelleAdresse .= $adresse->getRue().' ';
  682.             }
  683.             if ($adresse->getComplement() != "") {
  684.                 $libelleAdresse .= $adresse->getComplement().' ';
  685.             }
  686.             if ($adresse->getComplement2() != "") {
  687.                 $libelleAdresse .= $adresse->getComplement2().' ';
  688.             }
  689.             if (is_object($adresse->getCodePostal())) {
  690.                 $libelleAdresse .= $adresse->getCodePostal()->getCodePostal().' ';
  691.             }
  692.             if (is_object($adresse->getVille())) {
  693.                 $libelleAdresse .= $adresse->getVille()->getTitre().' ';
  694.             }
  695.             if (is_object($adresse->getPays())) {
  696.                 $libelleAdresse .= $adresse->getPays()->getTitre();
  697.             }
  698.             $data_liv_societe      $adresse->getSociete();
  699.             $data_liv_numero       $adresse->getNumero();
  700.             $data_liv_rue          $adresse->getRue();
  701.             $data_liv_complement   $adresse->getComplement();
  702.             $data_liv_complement_2 $adresse->getComplement2();
  703.             if (is_object($adresse->getCodePostal())) {
  704.                 $data_liv_cp $adresse->getCodePostal()->getCodePostal();
  705.             }
  706.             if (is_object($adresse->getVille())) {
  707.                 $data_liv_ville $adresse->getVille()->getTitre();
  708.             }
  709.             if (is_object($adresse->getPays())) {
  710.                 $data_liv_pays $adresse->getPays()->getTitre();
  711.             }
  712.             $data_fac_societe      $adresse->getSociete();
  713.             $data_fac_numero       $adresse->getNumero();
  714.             $data_fac_rue          $adresse->getRue();
  715.             $data_fac_complement   $adresse->getComplement();
  716.             $data_fac_complement_2 $adresse->getComplement2();
  717.             if (is_object($adresse->getCodePostal())) {
  718.                 $data_fac_cp $adresse->getCodePostal()->getCodePostal();
  719.             }
  720.             if (is_object($adresse->getVille())) {
  721.                 $data_fac_ville $adresse->getVille()->getTitre();
  722.             }
  723.             if (is_object($adresse->getPays())) {
  724.                 $data_fac_pays $adresse->getPays()->getTitre();
  725.             }
  726.             $data_secteur               "";
  727.             $data_secteur_libelle       "";
  728.             $data_secteur_obj           "";
  729.             $data_commercial            "";
  730.             $data_assistante_commercial "";
  731.             if (isset($data_fac_cp) && $data_fac_cp != "") {
  732.                 $data_secteur_obj $repo_zone->findSecteurGeograhiqueByCodePostal($data_fac_cp$pays_id);
  733.             }
  734.             if ( ! is_object($data_secteur_obj) && is_object($pays_obj) && is_object($pays_obj->getSecteurGeographique())) {
  735.                 $data_secteur_obj $pays_obj;
  736.                 //echo "AA".$data_secteur_obj->getSecteurGeographique()->getLibelle();
  737.             } else {
  738.                 //echo "BB (".$data_fac_cp.") ".$data_secteur_obj->getTitre();
  739.             }
  740.             if (is_object($data_secteur_obj) && is_object($data_secteur_obj->getSecteurGeographique())) {
  741.                 $data_secteur         $data_secteur_obj->getSecteurGeographique()->getId();
  742.                 $data_secteur_libelle $data_secteur_obj->getSecteurGeographique()->getLibelle();
  743.                 $data_assistante_commercial $repo_utilisateur_zone_geographique->findAssistanteCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  744.                 $data_commercial            $repo_utilisateur_zone_geographique->findCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  745.             }
  746.             $options .= '<option '.$selected.' data-tva="'.$dataTva.'" data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId().'">'.$libelleAdresse.'</option>';
  747.             $optionsLivraison   .= '<option data-secteur-libelle="'.$data_secteur_libelle.'"  data-secteur="'.$data_secteur.'"  data-commercial="'.$data_commercial.'"  data-assistante-commercial="'.$data_assistante_commercial.'"  data-societe="'.$data_liv_societe.'"  data-numero="'.$data_liv_numero.'"  data-rue="'.$data_liv_rue.'"  data-complement="'.$data_liv_complement.'"  data-complement2="'.$data_liv_complement_2.'"  data-cp="'.$data_liv_cp.'"  data-ville="'.$data_liv_ville.'" data-pays="'.$data_liv_pays.'" '.$selectedLivraison.' data-tva="'.$dataTva.'" data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId(
  748.                 ).'">'.$libelleAdresse.'</option>';
  749.             $optionsFacturation .= '<option data-secteur-libelle="'.$data_secteur_libelle.'"  data-secteur="'.$data_secteur.'"  data-commercial="'.$data_commercial.'"  data-assistante-commercial="'.$data_assistante_commercial.'"  data-societe="'.$data_fac_societe.'"  data-numero="'.$data_fac_numero.'"  data-rue="'.$data_fac_rue.'"  data-complement="'.$data_fac_complement.'"  data-complement2="'.$data_fac_complement_2.'"  data-cp="'.$data_fac_cp.'"  data-ville="'.$data_fac_ville.'" data-pays="'.$data_fac_pays.'" '.$selectedFacturation.' data-tva="'.$dataTva.'" data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId(
  750.                 ).'">'.$libelleAdresse.'</option>';
  751.             //$options .='<option '.$selected.' data-tva="'.$dataTva.'" data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId().'">'.$libelleAdresse.'</option>';
  752.             //$optionsLivraison .='<option '.$selectedLivraison.' data-tva="'.$dataTva.'" data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId().'">'.$libelleAdresse.'</option>';
  753.             //$optionsFacturation .='<option '.$selectedFacturation.' data-tva="'.$dataTva.'" data-pro="'.$pro.'" data-ue="'.$paysUe.'" value="'.$adresse->getId().'">'.$libelleAdresse.'</option>';
  754.             $cpt++;
  755.         }
  756.         //$optionsVehicule .='<option data-km="" data-ct="" data-serie="" data-immat="" data-modele="" data-marque="" value="">Choisissez</option>';
  757.         foreach ($client->getVehiculesClient() as $vehicule) {
  758.             $selected    "";
  759.             $dataMarque  "";
  760.             $dataModele  "";
  761.             $dataLibelle $vehicule->getLibelle();
  762.             $dataImmat   $vehicule->getImmatriculation();
  763.             $dataSerie   $vehicule->getNumSerie();
  764.             if (is_object($vehicule->getDateControleTechnique())) {
  765.                 $dataCT $vehicule->getDateControleTechnique()->format("d/m/Y");
  766.             } else {
  767.                 $dataCT "";
  768.             }
  769.             $dataKm $vehicule->getKilometrage();
  770.             //if($cpt == 0) $selected = 'selected="selected"';
  771.             $libelleVehicule "";
  772.             if (is_object($vehicule->getMarque())) {
  773.                 $libelleVehicule .= $vehicule->getMarque()->getLibelle();
  774.                 $dataMarque      $vehicule->getMarque()->getLibelle();
  775.             }
  776.             if (is_object($vehicule->getModele())) {
  777.                 $libelleVehicule .= " ".$vehicule->getModele()->getLibelle();
  778.                 $dataModele      $vehicule->getModele()->getLibelle();
  779.             } else {
  780.                 $dataModele $vehicule->getLibelle();
  781.             }
  782.             if ($libelleVehicule != "") {
  783.                 $libelleVehicule .= " : ";
  784.             }
  785.             $libelleVehicule .= " ".$vehicule->getNumSerie();
  786.             $optionsVehicule .= '<option data-libelle="'.$dataLibelle.'"  data-km="'.$dataKm.'" data-ct="'.$dataCT.'" data-serie="'.$dataSerie.'" data-immat="'.$dataImmat.'" data-modele="'.$dataModele.'"  data-marque="'.$dataMarque.'" '.$selected.' value="'.$vehicule->getId(
  787.                 ).'">'.$dataLibelle.' ('.$dataImmat.')</option>';
  788.             $cpt++;
  789.         }
  790.         $optionsVehicule .= '<option data-km="" data-ct="" data-serie="" data-immat="" data-modele="" data-marque="" value="">Aucun</option>';
  791.         if (is_object($client->getTransporteur())) {
  792.             $transporteurDefaut $client->getTransporteur()->getId();
  793.         }
  794.         $listeContacts "";
  795.         $listeContacts .= '<tr class="entete-contacts">
  796.                                                      <th>
  797.                                                          Nom/Service
  798.                                                      </th>
  799.                                                      <th>
  800.                                                          Email/Tel
  801.                                                      </th>
  802.                                                  </tr>';
  803.         if ($client->getEmail() != "" or $client->getTelephone() != "") {
  804.             $listeContacts .= "<tr>";
  805.             $listeContacts .= "<td>";
  806.             $listeContacts .= "</td>";
  807.             $listeContacts .= "<td>";
  808.             $listeContacts .= '<a href="mailto:'.$client->getEmail().'">'.$client->getEmail().'</a>';
  809.             if ($client->getTelephone() != "") {
  810.                 $listeContacts .= ' <br/><a href="tel:'.$client->getTelephone().'">'.$client->getTelephone().'</a>';
  811.             }
  812.             $listeContacts .= "</td>";
  813.             $listeContacts .= "</tr>";
  814.         }
  815.         if (count($client->getContacts()) > 0) {
  816.             $compteur_contact 0;
  817.             foreach ($client->getContacts() as $contact) {
  818.                 $listeContacts .= "<tr>";
  819.                 $listeContacts .= "<td>";
  820.                 $listeContacts .= count($client->getContacts())." ".$contact->getNom()." ".$contact->getPrenom();
  821.                 if ($contact->getService() != "") {
  822.                     $listeContacts .= ' <br/><b>'.$contact->getService().'</b>';
  823.                 }
  824.                 $listeContacts .= "</td>";
  825.                 $listeContacts .= "<td>";
  826.                 $listeContacts .= '<a href="mailto:'.$contact->getEmail().'">'.$contact->getEmail().'</a>';
  827.                 if ($contact->getTelephone() != "") {
  828.                     $listeContacts .= ' <br/><a href="tel:'.$contact->getTelephone().'">'.$contact->getTelephone().'</a>';
  829.                 }
  830.                 $listeContacts .= "</td>";
  831.                 $listeContacts .= "</tr>";
  832.                 $compteur_contact++;
  833.                 if ($compteur_contact 10) {
  834.                     break;
  835.                 }
  836.             }
  837.             if (count($client->getContacts()) > 10) {
  838.                 $plus          count($client->getContacts()) - 10;
  839.                 $listeContacts .= "<tr>";
  840.                 $listeContacts .= "<td colspan='2' class='text-right'>";
  841.                 $url_afficher_client_contacts $this->generateUrl('dtc_client_afficher_modal', ['id' => $client->getId(), 'tab' => 'contacts']);
  842.                 $listeContacts .= "<span class='open-modal-form hand' data-width='1100' data-link='".$url_afficher_client_contacts."' data-toggle='modal' data-target='#blocModal'>+".$plus." contacts</span>";
  843.                 $listeContacts .= "</td>";
  844.                 $listeContacts .= "</tr>";
  845.             }
  846.         }
  847.         $referenceCommandeClientObligatoire $client->getReferenceClientObligatoire();
  848.         return new JsonResponse(
  849.             [
  850.                 'options'                    => $options,
  851.                 'optionsVehicule'            => $optionsVehicule,
  852.                 'transporteurDefaut'         => $transporteurDefaut,
  853.                 'listeContacts'              => $listeContacts,
  854.                 'valide'                     => '0',
  855.                 'referenceClientObligatoire' => $referenceCommandeClientObligatoire,
  856.                 'paysUe'                     => $paysUe,
  857.                 'pro'                        => $pro,
  858.                 'optionsLivraison'           => $optionsLivraison,
  859.                 'optionsFacturation'         => $optionsFacturation,
  860.                 'articlesAuto'               => $ArticlesAuto,
  861.                 'telephone'                  => $client->getTelephone(),
  862.                 'telephone2'                 => $client->getTelephone2(),
  863.                 'email'                      => $client->getEmail(),
  864.             ],
  865.             200,
  866.             ['Content-Type' => 'application/json']
  867.         );
  868.     }
  869.     public function majAdressesParDefaut($adresse$objetEntityManagerInterface $em)
  870.     {
  871.         if (method_exists($objet'getAdresses') && ($adresse->getFacturationDefaut() == || $adresse->getLivraisonDefaut() == || $adresse->getFacturationExpeditionDefaut() == 1)) {
  872.             foreach ($objet->getAdresses() as $adress) {
  873.                 if ($adresse->getFacturationDefaut() == && $adresse->getId() != $adress->getId()) {
  874.                     $adress->setFacturationDefaut(false);
  875.                 }
  876.                 if ($adresse->getLivraisonDefaut() == && $adresse->getId() != $adress->getId()) {
  877.                     $adress->setLivraisonDefaut(false);
  878.                 }
  879.                 if ($adresse->getFacturationExpeditionDefaut() == && $adresse->getId() != $adress->getId()) {
  880.                     $adress->setFacturationExpeditionDefaut(false);
  881.                 }
  882.                 $em->persist($adress);
  883.             }
  884.             $em->flush();
  885.         }
  886.     }
  887.     /**
  888.      * @Route("/adresse-map/load", name="dtc_adresse_map_load")
  889.      */
  890.     public function mapLoadAction(Request $requestEntityManagerInterface $entityManager)
  891.     {
  892.         $donnees $request->query->all();
  893.         $repo_adresse  $entityManager->getRepository(Adresse::class);
  894.         $adressesBrut  $repo_adresse->getAdressesMap($donnees);
  895.         $centre        = ['lat' => 50.293'lng' => 2.7819];
  896.         $user          $this->getUser();
  897.         $adresseDepart $repo_adresse->findOneBy(['personnel' => $user->getId(), 'depart' => true]);
  898.         if (is_object($adresseDepart)) {
  899.             $centre = ['lat' => floatval($adresseDepart->getLatitude()), 'lng' => floatval($adresseDepart->getLongitude())];
  900.         }
  901.         $adresses = [];
  902.         //$image = $this->get('templating.helper.assets')->getUrl('images/marker-test.jpg', 'DTCNoogaaBundle');
  903.         //$image = $this->get('templating.helper.assets')->getUrl('images/marker-test.jpg', 'bundles/noogaamaps/images/');
  904.         $baseurl $request->getScheme().'://'.$request->getHttpHost().$request->getBasePath();
  905.         foreach ($adressesBrut as $adresse) {
  906.             $adresseLitterale '';
  907.             $adresseLitterale .= $adresse['statutNote'].' ';
  908.             if ($adresse['numero'] != '') {
  909.                 $adresseLitterale .= $adresse['numero'].' ';
  910.             }
  911.             if ($adresse['rue'] != '') {
  912.                 $adresseLitterale .= $adresse['rue'].' ';
  913.             }
  914.             if ($adresse['complement'] != '') {
  915.                 $adresseLitterale .= $adresse['complement'].' ';
  916.             }
  917.             if ($adresse['complement2'] != '') {
  918.                 $adresseLitterale .= $adresse['complement2'].' ';
  919.             }
  920.             if ($adresse['code_postal']) {
  921.                 $adresseLitterale .= $adresse['code_postal'].' ';
  922.             }
  923.             if ($adresse['ville']) {
  924.                 $adresseLitterale .= $adresse['ville'].' ';
  925.             }
  926.             if ($adresse['statutNote'] == '') {
  927.                 $icon $baseurl.'/bundles/noogaamaps/images/marker35x35-1.png';
  928.             } else {
  929.                 $icon $baseurl.'/bundles/noogaamaps/images/marker35x35-'.$adresse['statutNote'].'.png';
  930.             }
  931.             //$icon = '';
  932.             //$icon = $baseurl.'/bundles/noogaamaps/images/marker35x35-1.png';
  933.             $adresses[] = [
  934.                 'position'         => [
  935.                     'lat' => floatval($adresse['latitude']),
  936.                     'lng' => floatval($adresse['longitude']),
  937.                 ],
  938.                 'idClient'         => $adresse['idClient'],
  939.                 'idAdresse'        => $adresse['id'],
  940.                 'note'             => $adresse['noteId'],
  941.                 'icon'             => $icon,
  942.                 'adresseLitterale' => $adresseLitterale,
  943.                 'raisonSociale'    => $adresse['raisonSociale'],
  944.                 'icons'            => [
  945.                     'spider-1' => $icon $baseurl.'/bundles/noogaamaps/images/marker45x45-etape-1.png',
  946.                     'spider-2' => $icon $baseurl.'/bundles/noogaamaps/images/marker45x45-etape-2.png',
  947.                     'spider-3' => $icon $baseurl.'/bundles/noogaamaps/images/marker45x45-etape-3.png',
  948.                 ],
  949.             ];
  950.         }
  951.         if (count($adressesBrut) == 1) {
  952.             $centre = ['lat' => floatval($adressesBrut[0]['latitude']), 'lng' => floatval($adressesBrut[0]['longitude'])];
  953.         }
  954.         //var adresse = {position:{lat: {{adresse.latitude}}, lng: {{adresse.longitude}}}, idClient: {{adresse.client.id}}};
  955.         $response = new JsonResponse();
  956.         $response->setData([
  957.                                'adresses' => $adresses,
  958.                                'centre'   => $centre,
  959.                            ]);
  960.         return $response;
  961.     }
  962.     /**
  963.      * @Route("/adresse-map/{id}/visualiser", name="dtc_adresse_visualiser_map")
  964.      */
  965.     public function mapVisualiserAction(Request $requestAdresse $adresseEntityManagerInterface $emTranslatorInterface $translator)
  966.     {
  967.         $titre_modal $translator->trans("Visualiser l'adresse");
  968.         $mapApiKey   $this->getParameter('map_api_key');
  969.         $errors      '';
  970.         if ($request->isMethod('POST')) {
  971.             $lat $request->request->get('lat');
  972.             $lng $request->request->get('lng');
  973.             if ($lat != '' && $lng != '') {
  974.                 $adresse->setLatitude($lat);
  975.                 $adresse->setLongitude($lng);
  976.                 $em->persist($adresse);
  977.                 $em->flush();
  978.                 $this->addFlash(
  979.                     'notice',
  980.                    $translator->trans('La position a été modifiée !')
  981.                 );
  982.             }
  983.         }
  984.         $rendu $this->renderView('Adresses/Adresse/visualiser-map.html.twig', ['adresse' => $adresse'errors' => $errors'mapApiKey' => $mapApiKey]);
  985.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  986.     }
  987.     /**
  988.      * @Route("/adresse/charger-tableau/{id}/{type}", name="dtc_adresse_charger_tableau")
  989.      */
  990.     public function chargerTableauAction(Request $requestEntityManagerInterface $em$id "0"$type "")
  991.     {
  992.         $objet '';
  993.         if ($type == 'client') {
  994.             $repo_objet $em->getRepository(Client::class);
  995.             $objet      $repo_objet->find($id);
  996.         } elseif ($type == 'transporteur') {
  997.             $repo_objet $em->getRepository(Transporteur::class);
  998.             $objet      $repo_objet->find($id);
  999.         } elseif ($type == 'fournisseur') {
  1000.             $repo_objet $em->getRepository(Fournisseur::class);
  1001.             $objet      $repo_objet->find($id);
  1002.         }
  1003.         $rendu $this->renderView('Adresses/Adresse/charger_tableau.html.twig', ["id" => $id"type" => $type"objet" => $objet]);
  1004.         return new JsonResponse(['rendu' => $rendu]);
  1005.     }
  1006.     /**
  1007.      * @Route("/adresse/recherche", name="dtc_adresse_recherche")
  1008.      */
  1009.     public function rechercheAction(Request $requestEntityManagerInterface $emPaginatorInterface $paginator)
  1010.     {
  1011.         $q      $request->query->get('q');
  1012.         $client $request->query->get('client');
  1013.         $repo $em->getRepository(Adresse::class);
  1014.         if (empty($request->query->get('client'))) {
  1015.             $results = [];
  1016.         } else {
  1017.             $results $repo->getRechercheAdresse($q25, ['client' => $request->query->get('client')]);
  1018.         }
  1019.         $pagination $paginator->paginate(
  1020.             $results/* query NOT result */
  1021.             $request->query->getInt('page'1)/*page number*/,
  1022.             10/*limit per page*/
  1023.         );
  1024.         $pagination_results $pagination->getItems();
  1025.         $pagination_results_array $pagination->getItems();
  1026.         $option_placeholde  = ["libelle" => "Sélectionnez""id" => "0"];
  1027.         if ($request->query->getInt('page'1) == 1) {
  1028.             array_unshift($pagination_results_array$option_placeholde);
  1029.         }
  1030.         $pagination->setItems($pagination_results);
  1031.         $serializer SerializerBuilder::create()->build();
  1032.         return JsonResponse::fromJsonString($serializer->serialize($pagination'json'));
  1033.     }
  1034.     /**
  1035.      * @Route("/adresse/{id}/{type}", name="dtc_adresse_liste")
  1036.      */
  1037.     public function listerAction($idEntityManagerInterface $emDatatable $datatableTranslatorInterface $translator$type ""$objet "")
  1038.     {
  1039.         if ($type == 'client') {
  1040.             $repo_objet $em->getRepository(Client::class);
  1041.             $objet      $repo_objet->find($id);
  1042.         } elseif ($type == 'transporteur') {
  1043.             $repo_objet $em->getRepository(Transporteur::class);
  1044.             $objet      $repo_objet->find($id);
  1045.         } elseif ($type == 'fournisseur') {
  1046.             $repo_objet $em->getRepository(Fournisseur::class);
  1047.             $objet      $repo_objet->find($id);
  1048.         }
  1049.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [0], "visible" => true"orderable" => true"searchable" => true];
  1050.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [1], "visible" => true"orderable" => true"searchable" => true];
  1051.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [2], "visible" => true"orderable" => true"searchable" => true];
  1052.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [3], "visible" => true"orderable" => true"searchable" => true];
  1053.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [4], "visible" => true"orderable" => true"searchable" => true];
  1054.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [5], "visible" => true"orderable" => true"searchable" => true];
  1055.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [6], "visible" => true"orderable" => true"searchable" => true];
  1056.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [7], "visible" => true];
  1057.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [11], "visible" => true"orderable" => false];
  1058.         $this->datatable($objet$type$datatable$translator);
  1059.         return $this->render('Adresses/Adresse/lister.html.twig', ['tableauClassColonne' => $tableau_class_cellule"id" => $id"type" => $type]);
  1060.     }
  1061. }