<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App\Controller\Admin;

use App\Entity\Appareil;
use App\Entity\EquipementFamille;
use App\Entity\EquipementPuissance;
use App\Entity\EquipementTranche;
use App\Entity\EvenementObjet;
use App\Entity\GroupeDroitPortail;
use App\Entity\Option;
use App\Entity\Produit;
use App\Entity\ProduitPhoto;
use App\Entity\ProduitStockSite;
use App\Entity\Site;
use App\Entity\TypeAppareil;
use App\Entity\TypePlanification;
use App\Entity\TypeSav;
use App\Entity\TypeUtilisateur;
use App\Entity\Utilisateur;
use App\Form\UtilisateurType;
use App\Service\FiltreManager;
use App\Service\TarifManager;
use App\Utils\Functions;
use AppBundle\Entity\Filtre;
use Proxies\__CG__\App\Entity\CategoriePro;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Entity\SectorisationVersion;
use App\Entity\Secteur;
use App\Repository\SectorisationVersionRepository;

/**
 * @Route("/configuration")
 * @IsGranted("ROLE_USER")
 *
 */
class ConfigurationController extends ParentAdminController
{
    /**
     * Lists all entities.
     * @Route("/clients", methods="GET", name="categ_clients")
     */
    public function listClients(Request $request, SerializerInterface $serializer): Response
    {
        $tabs = [
            [
                'name' => 'Catégories professionnelles',
                'entityName' => 'CategoriePro',
                'columns' => [['dataField' => 'libelle', 'caption' => 'Libellé', 'width'=> '50%','sortOrder' => 'asc', 'validationRules' => [["type" =>'required']]]],
                'rang_tri' => false,
                'delete_path' => $this->generateUrl('delete_categorie_professionnelle'),
                'check_path' => 'check_categorie_professionnelle',
                ],
            ['name' => 'Documentation', 'entityName' => '', 'columns' => [], 'rang_tri' => false],
        ];

        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * deleteCategorie professionnelles
     * @Route("/categorie_professionnelle/{idCategorieProfessionnelle}", methods="DELETE", name="delete_categorie_professionnelle")
     */
    public function deleteCategorieProfessionnelle($idCategorieProfessionnelle = null) {
        if ($idCategorieProfessionnelle) {
            $categorieProfessionnelle = $this->getDoctrine()->getRepository(CategoriePro::class)->find($idCategorieProfessionnelle);
            if ($categorieProfessionnelle) {
                if ($categorieProfessionnelle->getClients()->count() != 0) {
                    return new JsonResponse(['messages' => ['error' => ["Suppression impossible car des clients possèdent cette catégorie professionnelle"]]], Response::HTTP_OK);
                } else {
                    $this->getDoctrine()->getManager()->remove($categorieProfessionnelle);
                    $this->getDoctrine()->getManager()->flush();
                }
            }

        }

        return new JsonResponse(['messages' => ['success' => ["Suppression effectuée avec succès"]]], Response::HTTP_OK);
    }
    /**
     * deleteCategorie professionnelles
     * @Route("/check/categorie_professionnelle/{id}", methods="POST", name="check_categorie_professionnelle")
     */
    public function checkCategorieProfessionnelle(Request $request, $id = null) {
        $datas = $request->request->all();
        foreach($datas as $key => $value) {
            $datas[$key] = Functions::clearData($value);
        }

        if ($datas) {
            $categorieProfessionnelle = $this->getDoctrine()->getRepository(CategoriePro::class)->findByLibelle($datas['libelle'], $id);
            if ($categorieProfessionnelle) {
                return new JsonResponse(['messages' => ['error' => ["Impossible d'effectuer la création, cette Catégorie existe déjà"]]], 443);
            }
        }
        return new JsonResponse([], Response::HTTP_OK);
    }

    /**
     * delete Equipement Tranche
     * @Route("/equipement_tranche/{idEquipementTranche}", methods="DELETE", name="delete_equipement_tranche")
     */
    public function deleteEquipementTranche($idEquipementTranche = null) {
        if ($idEquipementTranche) {
            $equipementTranche = $this->getDoctrine()->getRepository(EquipementTranche::class)->find($idEquipementTranche);
            if ($equipementTranche) {
                if ($equipementTranche->getEquipements()->count() != 0) {
                    return new JsonResponse(['messages' => ['error' => ["Suppression impossible car des équipements possèdent cette Tranche"]]], Response::HTTP_OK);
                } else {
                    $this->getDoctrine()->getManager()->remove($equipementTranche);
                    $this->getDoctrine()->getManager()->flush();
                }
            }
        }
        return new JsonResponse(['messages' => ['success' => ["Suppression effectuée avec succès"]]], Response::HTTP_OK);
    }

    /**
     * delete Equipement Tranche
     * @Route("/check/equipement_tranche/{id}", methods="POST", name="check_equipement_tranche")
     */
    public function checkEquipementTranche(Request $request, $id = null) {
        $em = $this->getDoctrine()->getManager();
        $datas = $request->request->all();
        foreach($datas as $key => $value) {
            $datas[$key] = Functions::clearData($value);
        }

        if ($datas) {
            //on check d'abord qu'on a pas un equipement tranche du meme age et si c'est l
            $equipementTranche = $this->getDoctrine()->getRepository(EquipementTranche::class)->findByAge($datas['age'],$id);

            if ($equipementTranche) {
                return new JsonResponse(['messages' => ['error' => ["Impossible d'effectuer la création, cette tranche existe déjà"]]], 443);
            }
        }
        return new JsonResponse([], Response::HTTP_OK);
    }

    /**
     * check Equipement Famille
     * @Route("/check/equipement_famille/{id}", methods="POST", name="check_equipement_famille")
     */
    public function checkEquipementFamille(Request $request, $id = null) {
        $em = $this->getDoctrine()->getManager();
        $datas = $request->request->all();
        foreach($datas as $key => $value) {
            $datas[$key] = Functions::clearData($value);
        }

        if ($datas) {
            //on check d'abord qu'on a pas un equipement tranche du meme age et si c'est l
            $equipementFamille = $this->getDoctrine()->getRepository(EquipementFamille::class)->findByLibelle($datas['libelle'],$id);

            if ($equipementFamille) {
                return new JsonResponse(['messages' => ['error' => ["Impossible d'effectuer la création, cette Famille existe déjà"]]], 443);
            }
        }
        return new JsonResponse([], Response::HTTP_OK);
    }

    /**
     * Lists all entities.
     * @Route("/produits", methods="GET", name="list_produits")
     */
    public function listProduit(Request $request, SerializerInterface $serializer): Response
    {
        //récupération des familles
        $familles = json_decode($this->getDatas('Famille', $request, $serializer)->getContent(), true);
        $tabs = [
            ['name' => 'Catégories', 'entityName' => 'Category', 'columns' => ['libelle', 'age', 'plus_value'], 'rang_tri' => false],
            ['name' => 'Familles', 'entityName' => 'Famille', 'columns' => [['dataField' =>'id', 'width' => '100'], 'libelle'], 'rang_tri' => false],
            ['name' => 'Types', 'entityName' => 'Type', 'columns' =>
                [
                    'modele',
                    'libelle', 'controleDuCo',
                    ['dataField' =>'dateDebut', 'dataType' => 'date'],
                    ['dataField' =>'dateFin', 'dataType' => 'date'],
                    ['dataField' =>'famille_produit',
                        'caption' => 'Famille de produit',
                        'dataType' => 'number',
                        'lookup' => [
                            'dataSource'=>  "common.createCustomStore('Famille')",
                            'displayExpr'=> "libelle",
                            'valueExpr'=> "id",
                        ]
                    ]
                ] ,
                'rang_tri' => false
            ],
            ['name' => 'Options', 'entityName' => 'Option', 'columns' => ['designation', 'libelle'], 'rang_tri' => false],
            ['name' => 'Puissances', 'entityName' => 'Puissance', 'columns' => ['libelle'] , 'rang_tri' => false],
        ];

        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * Lists all entities.
     * @Route("/tablette_agent", methods="GET", name="list_tablette_agent")
     */
    public function listTabletteAgent(): Response
    {
        $tabs = [
            ['name' => 'Observations standards', 'entityName' => 'Observation', 'columns' => [['dataField' => 'rang_tri', 'caption' => 'N°',  'dataType' => 'number','sortOrder' => 'asc', 'allowEditing'=> false, 'width' => 130   ], ['dataField' => 'texte', 'caption' => 'Libellé']], 'rang_tri' => true],
        ];

        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * Lists all entities.
     * @Route("/utilisateurs", methods="GET", name="list_utilisateurs")
     */
    public function listUtilisateurs(FiltreManager $filtreManager): Response
    {
        $datas = [
            'columns' => [
                ['dataField' => 'sitesListe', 'caption' => 'Site(s)'],
                ['dataField' => 'prenom', 'caption' => 'Prénom'],
                ['dataField' => 'nom', 'caption' => 'Nom' ],
                ['dataField' => 'login', 'caption' => 'Login'],
                ['dataField' =>'type_name', 'caption' => 'Type'],
                ['dataField'=> 'roles_name', 'caption' => 'Role'],
                ['dataField' => 'actif', 'dataType' => 'boolean', 'width' => 130]
            ],
            'rang_tri' => false,
            'filtreDefaut' => $filtreManager->getDefaultFilter($this->getUser(), 'Utilisateur'),
            'filtreDefautUtilisateur' => $filtreManager->getDefaultFilterUtilisateur($this->getUser(), 'Utilisateur'),
        ];

        $actions = [
            ['name' => 'Utilisateur', 'icon' => 'fa-plus', 'class' => 'btn-success', 'id' => 'link-add-' . 'Utilisateur'],
        ];

        //form user
        $formView = $this->createForm(UtilisateurType::class, null, ['action' => $this->generateUrl('parent_createform', ['page' => 'Utilisateur'])])->createView();

        return $this->render('admin/list.html.twig', [
            'datagrid_style' => 'full',
            'page' => 'Utilisateur',
            'datas' => $datas,
            'actions' => $actions,
            'form' => $formView,
            'show_path' => $this->generateUrl('show_utilisateur', ['id' => 1]),
            ] );
    }


    /**
     * Lists all entities.
     * @Route("/utilisateur/{id}", methods="GET", name="show_utilisateur")
     */
    public function showUtilisateur(Utilisateur $user): Response
    {
        //form user
        $formView = $this->createForm(UtilisateurType::class, $user, ['action' => $this->generateUrl('parent_patchform', ['id' => $user->getId(),'page' => 'Utilisateur'])])->createView();

        $actions = [
            ['name' => 'Enregistrer', 'icon' => 'fa-save', 'id' => '', 'class' => 'btn-save', 'href' => '', 'form' => 'form_show_utilisateur', 'type' => 'button', 'type_att' => 'submit'],
        ];
        if ($user && $user->getActif() == true)
            $actions[] = ['name' => 'Supprimer', 'type' => 'button', 'icon' => 'fa-trash', 'class' => 'btn-danger', 'href' => $this->generateUrl('parent_disable', ['page' => 'Utilisateur', 'id' => $user->getId(), 'redirect' => 'list_utilisateurs']), 'confirm' => true];


        //si la personne à le droit de modification
        $groupeDroits = $this->getDoctrine()->getManager()->getRepository(GroupeDroitPortail::class)->findAll();

        return $this->render('configuration/user_show.html.twig', [
            'user' => $user,
            'form' => $formView,
            'page' => 'Utilisateur',
            'actions' => $actions,
            'groupeDroits' => $groupeDroits
        ]);
    }

    /**
     * @Route("/utilisateurs/site-select", name="utilisateur_site_select")
     */
    public function getSiteSelect(Request $request)
    {
        $utilisateur = new Utilisateur();
        $type_utilisateur_id = $request->query->get('type_utilisateur');
        $type = ($type_utilisateur_id) ? $this->getDoctrine()->getManager()->getRepository(TypeUtilisateur::class)->find($type_utilisateur_id) : null;

        $utilisateur->setTypeUtilisateur($type);
        $form = $this->createForm(UtilisateurType::class, $utilisateur);

        return $this->render('configuration/_site.html.twig', [
            'userForm' => $form->createView(),
        ]);
    }

    /**
     * @Route("/utilisateurs/site-sub-select/{user}", name="utilisateur_sub_select")
     * @ParamConverter("user", class="App:Utilisateur")
     */
    public function getSubSelect(Utilisateur $user)
    {
        $usersAvailable = $this->getDoctrine()->getManager()->getRepository(Utilisateur::class)->getSubordonneeAvailable($user);

        return $this->render('configuration/_select_sub.html.twig', [
            'subs' => $usersAvailable,
            'userId' => $user->getId()
        ]);
    }

    /**
     * @Route("/utilisateurs/add_sub/{user}", methods="POST", name="utilisateur_add_sub")
     * @ParamConverter("user", class="App:Utilisateur")
     */
    public function addSub(Utilisateur $user, Request $request, SerializerInterface $serializer)
    {
        $em = $this->getDoctrine()->getManager();
        $sub = $em->getRepository(Utilisateur::class)->find($request->request->get('subordonnee'));
        $user->addUtilisateur($sub);
        $em->persist($user);

        $em->flush();

        $this->addFlash('success', 'Ajout subordonnée avec succès');
        $data = json_decode($serializer->serialize($sub, 'json', ['ignored_attributes' => parent::getIgnoredAttributes()]), true);

        return new JsonResponse(['entite' => $data], 200);
    }

    /**
     * attachements.
     * @Route("/attachements", methods="GET", name="list_attachements")
     */
    public function listAttachements(): Response
    {
        $tabs = [
            ['name' => 'Règles génériques ', 'entityName' => 'RegleAttachement', 'columns' => ['rangTri', 'libelle', 'valeur'], 'rang_tri' => true],
            ['name' => 'Règles par profil ', 'entityName' => 'RegleAttachementProfil', 'columns' => ['rangTri', 'profil', ['dataField' =>'plafond',
                'caption' => 'Plafond de points'], 'coefficient'], 'rang_tri' => true],
        ];
        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * attachements.
     * @Route("/agents", methods="GET", name="list_agents_configuration")
     */
    public function listAgents(): Response
    {
        $tabs = [
            ['name' => 'Qualifications ', 'entityName' => '', 'columns' => [], 'rang_tri' => false],
            ['name' => 'Appareils', 'entityName' => 'Appareil', 'columns' => [
                ['dataField' =>'site',
                    'caption' => 'Site',
                    'dataType' => 'number',
                    'validationRules' => [["type" =>'required']],
                    'lookup' => [
                        'dataSource'=>  "common.createCustomStore('Site')",
                        'displayExpr'=> "nom",
                        'valueExpr'=> "id",
                    ],
                    'allowEditing'=> true,
                ],
                [
                    'dataField' => 'type_appareil',
                    'caption' => 'Libellé appareil',
                    'dataType' => 'number',
                    'validationRules' => [["type" =>'required']],
                    'sortOrder' => 'asc',
                    'lookup' => [
                        'dataSource'=>  "common.createCustomStore('TypeAppareil')",
                        'displayExpr'=> "libelle",
                        'valueExpr'=> "id",
                    ],
                    'editorOptions' => ['acceptCustomValue' => true],
                    'allowAdd' => true,
                    'allowEditing'=> true,
                    ],
                ['dataField' => 'marque', 'caption' => 'Marque','allowEditing'=> true],
                ['dataField' => 'modele', 'caption' => 'Modèle','allowEditing'=> true],
                ['dataField' => 'commentaire', 'caption' => 'Commentaire','allowEditing'=> true],
                ['dataField' => 'typeMetrologique', 'caption' => 'Type', 'lookup' => ['dataSource' => ['Métrologique', 'Hors Métrologique', 'Autre']], 'validationRules' => [["type" =>'required']] ,'allowEditing'=> true],
                ['dataField' => 'actif', 'dataType' => 'boolean']
                ],'rang_tri' => false,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  false, 'allowAdding' => true],
                'create_path' => 'configuration_create_appareil',
                'check_path' => 'configuration_check_appareil'
            ],
            ['name' => 'Formations', 'entityName' => '', 'columns' => [], 'rang_tri' => false],
        ];
        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * @Route("/equipements", methods="GET", name="list_equipements")
     */
    public function listEquipements(): Response
    {
        $options = $this->getDoctrine()->getManager()->getRepository(Option::class)->findAllArray();
        $puissances = $this->getDoctrine()->getManager()->getRepository(EquipementPuissance::class)->findAllArray();
        $familleEquipements = $this->getDoctrine()->getManager()->getRepository(EquipementFamille::class)->findAllArray();

        $tabs = [
            ['name' => 'Tranches ', 'entityName' => 'EquipementTranche', 'columns' => [
                ['dataField' => 'age', 'caption' => 'Age', 'sortOrder' => 'asc','validationRules' => [["type" =>'required']]],
                ['dataField' => 'plus_value', 'dataType' => 'number', 'caption' => 'Plus-value']],
                'rang_tri' => false,
                'delete_path' => $this->generateUrl('delete_equipement_tranche'),
                'check_path' => 'check_equipement_tranche',

            ],
            ['name' => 'Familles', 'entityName' => 'EquipementFamille', 'columns' => [
                ['dataField' => 'code', 'caption' => 'ID', 'width' => '30px', 'sortOrder' => 'asc','allowEditing'=> false],
                ['dataField' => 'libelle', 'caption' => 'Libellé famille produit', 'width' => '45%', 'validationRules' => [["type" =>'required']]]
            ], 'rang_tri' => false, 'create_path' => 'create_maj_equipement_famille', 'patch_path' => 'create_maj_equipement_famille', 'check_path' => 'check_equipement_famille',
                'disableOnlyEditing' => ['code'],],
            ['name' => 'Options', 'entityName' => 'Option', 'columns' => [
                ['dataField' => 'libelle_court', 'caption' => 'Désignation option','sortOrder' => 'asc', 'validationRules' => [["type" =>'required']]],
                ['dataField' => 'libelle_long', 'caption' => 'Libellé option', 'validationRules' => [["type" =>'required']]]
            ], 'rang_tri' => false],
            ['name' => 'Puissances', 'entityName' => 'EquipementPuissance', 'columns' => [['dataField' => 'libelle', 'caption' => 'Puissance', 'sortOrder' => 'asc', 'width'=> '50%', 'alignment' => 'left', 'validationRules' => [["type" =>'required']]]], 'rang_tri' => false],
            ['name' => 'Types', 'entityName' => 'EquipementType', 'patch_path' => 'patch_equipement_type', 'columns' => [
                ['dataField' => 'type','sortOrder' => 'asc', 'caption' => 'Type', 'validationRules' => [["type" =>'required']]],
                ['dataField' => 'libelle', 'caption' => 'Libellé type équipement', 'width' => '420px', 'validationRules' => [["type" =>'required']]],
                ['dataField' => 'equipement_puissance_IDs', 'caption' => 'Puissance(s)', 'fieldDisplay' => 'libelle', 'calculateDisplayValue' => true, 'calculateFilterExpression' => true, 'encodeHtml' => false, 'alignment' => 'center', 'width' => '100px'],
                ['dataField' => 'option_IDs', 'caption' => 'Option(s)',  'width' => '180px', 'alignment' => 'center',
                    'encodeHtml' => false,
                    'fieldDisplay' => 'libelle_court',
                    'calculateDisplayValue' => true,
                    'calculateFilterExpression' => true,
                    'onEditorPrepared' => 'Voir les options',
                ],
                ['dataField' => 'ctrl_co', 'caption' => 'Contrôle CO', 'width' => 'auto'],
                ['dataField' => 'date_debut', 'caption' => 'Date début', 'dataType' => "date", 'format' => 'shortDate'],
                ['dataField' => 'date_fin', 'caption' => 'Date fin', 'dataType' => "date", 'format' => 'shortDate'],
                ['dataField' => 'equipement_famille_IDs', 'caption' => 'Famille équipement', 'encodeHtml' => false, 'fieldDisplay' => 'libelle', 'calculateDisplayValue' => true, 'calculateFilterExpression' => true, 'validationRules' => [["type" =>'required']]],
                ], 'rang_tri' => false, 'onEditorPreparing' => ['equipement_puissance_IDs' => ['getData' => 'EquipementPuissance', 'datas' => $puissances, 'field' => 'libelle'], 'option_IDs' => ['datas' => $options, 'field' => 'libelle_court', 'getData' => 'Option'], 'equipement_famille_IDs' => ['datas' => $familleEquipements, 'field' => 'libelle', 'getData' => 'EquipementFamille']]
            ],
        ];

        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * @Route("/produits", methods="GET", name="list_produits")
     */
    public function listProduits(): Response
    {
        $tabs = [
            ['name' => 'Pièces équipement MEAUX ', 'entityName' => 'ProduitStockSite',
                'columns' => [
                    ['dataField' => 's_nom','caption' => 'Site', 'alignment' => 'center', 'dataType' => 'string'],
                    ['dataField' => 'p_code','caption' => 'Code produit AGI', 'alignment' => 'center', 'dataType' => 'string'],
                    ['dataField' => 'p_designation', 'caption' => 'Désignation', 'dataType' => 'string'],
                    ['dataField' => 'p_gtin','caption' => 'Code GTIN', 'alignment' => 'center', 'dataType' => 'string'],
                    ['dataField' => 'fa_libelle','caption' => 'Code famille AGI', 'alignment' => 'center', 'dataType' => 'string'],
                    ['dataField' => 'p_gu_etendue','caption' => 'GU (en année)', 'alignment' => 'center', 'dataType' => 'number'],
                    ['dataField' => 'p_prix_ht','caption' => 'Tarif HT', 'align' => 'alignment', 'dataType' => 'number'],
                    ['dataField' => 'pt_visible_tablette','caption' => 'Visible Tablette', 'alignment' => 'center', 'dataType' => 'string'],
                    ]
                , 'rang_tri' => false,
                'get_path' => $this->generateUrl('get_produits_type', ['type' => 'equipement_meaux']),
                'editing' => [ 'mode' => "row", 'allowUpdating' => false,  'allowDeleting' =>  false, 'allowAdding' => false], 'remoteOperations' => ['groupPaging' =>  true],
            ],
            ['name' => 'Consommables MEAUX ', 'entityName' => 'ProduitStockSite',
                'columns' => [
                    ['dataField' => 's_nom','caption' => 'Site', 'alignment' => 'center', 'dataType' => 'string', 'allowEditing'=> false],
                    ['dataField' => 'p_code','caption' => 'Code produit AGI', 'alignment' => 'center', 'dataType' => 'string', 'allowEditing'=> false],
                    ['dataField' => 'p_designation', 'caption' => 'Désignation', 'dataType' => 'string', 'allowEditing'=> false],
                    ['dataField' => 'p_gtin','caption' => 'Code GTIN', 'alignment' => 'center', 'dataType' => 'string', 'allowEditing'=> false],
                    ['dataField' => 'fa_libelle','caption' => 'Code famille AGI', 'alignment' => 'center', 'dataType' => 'string', 'allowEditing'=> false],
                    ['dataField' => 'p_prix_ht','caption' => 'Tarif HT', 'align' => 'alignment', 'dataType' => 'number', 'allowEditing'=> false],
                    ['dataField' => 'pt_gere_en_stock','caption' => 'Géré en stock', 'alignment' => 'center', 'dataType' => 'string', 'lookup' => ['dataSource' => ['oui', 'non']]],
                    ['dataField' => 'pp_photo','caption' => 'Photo', 'alignment' => 'center', 'dataType' => 'string', 'allowEditing'=> false],
                ]
                , 'rang_tri' => false,
                'get_path' => $this->generateUrl('get_produits_type', ['type' => 'consommables_meaux']),
                'patch_path' => 'patch_produit_type',
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  false, 'allowAdding' => false],
                'remoteOperations' => ['groupPaging' =>  true],
            ],
            ['name' => 'Consommables SITE', 'entityName' => 'Produit',
                'columns' => [
                    ['dataField' => 's_nom','caption' => 'Site', 'alignment' => 'center', 'dataType' => 'string',
                        'lookup' => [
                            'dataSource'=>  "common.createCustomStore('Site')",
                            'displayExpr'=> "nom",
                            'valueExpr'=> "nom",
                        ],
                        'validationRules' => [["type" =>'required']],
                    ],
                    ['dataField' => 'p_code','caption' => 'Code produit', 'alignment' => 'center', 'dataType' => 'string', 'validationRules' => [["type" =>'required']]],
                    ['dataField' => 'p_designation', 'caption' => 'Désignation', 'dataType' => 'string', 'validationRules' => [["type" =>'required']]],
                    ['dataField' => 'p_gtin','caption' => 'Code GTIN', 'alignment' => 'center', 'dataType' => 'string'],
                    ['dataField' => 'pt_emplacement','caption' => 'Emplacement', 'alignment' => 'center', 'dataType' => 'string'],
                    ['dataField' => 'pt_gere_en_stock','caption' => 'Géré en stock', 'alignment' => 'center', 'dataType' => 'string', 'lookup' => ['dataSource' => ['oui', 'non']]],
                    ['dataField' => 'p_prix_ht','caption' => 'Tarif HT', 'align' => 'alignment', 'dataType' => 'number', 'validationRules' => [["type" =>'numeric']]],
                    ['dataField' => 'pp_photo','caption' => 'Photo', 'alignment' => 'center', 'dataType' => 'string', 'allowEditing'=> false],
                ],
                'rang_tri' => false,
                'get_path' => $this->generateUrl('get_produits_type', ['type' => 'consommables_site']),
                'patch_path' => 'create_maj_produit',
                'create_path' => 'create_maj_produit',
                'remoteOperations' => ['groupPaging' =>  true],
            ]
        ];

        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * create one entity.
     * @Route("/check/appareil/{id}", methods="POST", name="configuration_check_appareil")
     */
    public function checkAppareil(Request $request, $id = null) {
        $em = $this->getDoctrine()->getManager();
        $datas = $request->request->all();
        foreach($datas as $key => $value) {
            $datas[$key] = Functions::clearData($value);
        }

        if ($datas) {
            if ($id) $oldAppareil = $em->getRepository(Appareil::class)->find((int)$id);

            $typeAppareil = (isset($datas['type_appareil'])) ? $em->getRepository(TypeAppareil::class)->find((int)$datas['type_appareil']) : $oldAppareil->getTypeAppareil();
            $site = isset($datas['site']) ? $em->getRepository(Site::class)->find((int)$datas['site']) : $oldAppareil->getSite();
            $datas['marque'] = (isset($datas['marque'])) ? $datas['marque'] : ((!$id) ? null : $oldAppareil->getMarque());
            $datas['modele'] = (isset($datas['modele'])) ? $datas['modele'] : ((!$id) ? null : $oldAppareil->getModele());

            //on recherche si on a pas un doublon
            $appareilExist = $em->getRepository(Appareil::class)->findByInfos($site,$datas['modele'],$datas['marque'], $typeAppareil, $id);

            if ($appareilExist) {
                return new JsonResponse(['messages' => ['error' => ["Impossible d'effectuer la création, cet appareil existe déjà"]]], 443);
            } else {
                return new JsonResponse(null, Response::HTTP_OK);
            }
        }
    }

    /**
     * create one entity.
     * @Route("/create/appareil", methods="POST", name="configuration_create_appareil")
     */
    public function createAppareil(Request $request) {
        $em = $this->getDoctrine()->getManager();
        $datas = $request->request->all();
        foreach($datas as $key => $value) {
            $datas[$key] = Functions::clearData($value);
        }

        if ($datas) {
            $appareil = new Appareil();

            if (!empty($datas['commentaire'])) $appareil->setCommentaire($datas['commentaire']);
            if (!empty($datas['marque'])) $appareil->setMarque($datas['marque']);
            if (!empty($datas['modele'])) $appareil->setModele($datas['modele']);
            if (Functions::isSetAndNotEmpty($datas['typeMetrologique'])) $appareil->setTypeMetrologique($datas['typeMetrologique']);
            if (!empty($datas['type_appareil'])){
                $typeAppareil = $em->getRepository(TypeAppareil::class)->find((int)$datas['type_appareil']);
                if (!$typeAppareil) {
                    $typeAppareil = new TypeAppareil();
                    $typeAppareil->setLibelle($datas['type_appareil']);
                    $em->persist($typeAppareil);
                }
                $appareil->setTypeAppareil($typeAppareil);
            }
            if (Functions::isSetAndNotEmpty($datas['site'])){
                $site = $em->getRepository(Site::class)->find((int)$datas['site']);
                if ($site) $appareil->setSite($site);
            }
            if (isset($datas['actif'])) {
                if ($datas['actif'] == 'true') $appareil->setActif(true);
                else  $appareil->setActif(false);
            } else {
                $appareil->setActif(false);
            }

            $em->persist($appareil);
            $em->flush();
        }

        return new JsonResponse(['messages' => ['success' => ["Création effectuée avec succès"]]], Response::HTTP_OK);
    }

    /**
     * Lists all entities.
     * @Route("/sectorisation", methods="GET", name="sectorisation")
     */
    public function sectorisation(): Response
    {
        $datas = [
            'columns' => [
                ['dataField' => 'id', 'caption' => 'Identifiant', 'alignment' => 'left' ,'sortOrder' => 'asc'],
                ['dataField' =>'profil_name', 'caption' => 'Type'],
                ['dataField' => 'nomComplet', 'caption' => 'Nom'],
                ['dataField' =>'nom_responsable', 'caption' => 'Nom responsable'],
                ['dataField' => 'groupe_affectation', 'caption' => 'Groupe', 'alignment' => 'left', 'visible' => false],
                ['dataField' => 'planifiable', 'caption' => 'Planifiable', 'visible' => false],
                ['dataField' => 'adresse', 'caption' => 'Adresse', 'visible' => false ],
                ['dataField' => 'telephone', 'caption' => 'Téléphone', 'visible' => false],
                ['dataField' => 'qualifications', 'caption' => 'Qualification', 'encodeHtml' => false, 'visible' => false],
                ['dataField' => 'poleLibelle', 'caption' => 'Pôle', 'visible' => false],

            ],
            'position' => false,
            'column_autowidth' => false,
            'rang_tri' => false,
            'get_path' => $this->generateUrl('get_agents'),
        ];

        $actions = [
            ['name' => 'Enregistrer dans mes filtres', 'icon' => 'fa-save', 'id' => 'openpopup', 'class' => 'btn-save', 'href' => ''],
        ];

        return $this->render('configuration/sectorisation.html.twig', [
            'page' => 'Utilisateur',
            'resHisto' => ['0' => ['id'=>'1', 'date_mep' => '30/11/2021', 'date_modif' => '30/11/2021', 'commentaires' => 'blablabla', 'date_mep_format' => '30/11/2021']],
            'resResponsables' => ['0' => ['code_agent' => '1', 'prenom_agent' => 'Prénom Res', 'nom_agent' => 'Nom Res']],
            'resAgents' => ['0' => ['code_agent' => '1', 'prenom_agent' => 'Prénom Agent', 'nom_agent' => 'Nom Agent', 'famille0' => '12', 'famille1' => '12', 'famille2' => '12', 'famille3' => '12', 'nb_clients' => '48', 'code_groupe' => '1']],
            'dateJour' => '30/11/2021',
            'version' => '1',
            'user' => ['site' => 'ROSNY'],
            'datagrid_style' => 'full',
            'actions' => $actions,
            'datas' => $datas
        ]);
    }

    /**
     * @Route("/planning", methods="GET", name="list_planning")
     */
    public function listPlanning(): Response
    {
        $typeAppareils = $this->getDoctrine()->getManager()->getRepository(TypeAppareil::class)->findAllArray();
        $typePlanificationMaladie = $this->getDoctrine()->getManager()->getRepository(TypePlanification::class)->findOneBy(['code' => 'MALADIE']);
        $typePlanificationReserve = $this->getDoctrine()->getManager()->getRepository(TypePlanification::class)->findOneBy(['code' => 'RESERVE']);
        $typePlanificationFormation = $this->getDoctrine()->getManager()->getRepository(TypePlanification::class)->findOneBy(['code' => 'FORMATION']);
        $typePlanificationReunion = $this->getDoctrine()->getManager()->getRepository(TypePlanification::class)->findOneBy(['code' => 'REUNION']);
        $typePlanificationVoiture = $this->getDoctrine()->getManager()->getRepository(TypePlanification::class)->findOneBy(['code' => 'VOITURE']);
        $typePlanificationTest = $this->getDoctrine()->getManager()->getRepository(TypePlanification::class)->findOneBy(['code' => 'TEST']);

        $tabs = [
            ['name' => 'Type planification', 'entityName' => 'TypePlanification', 'patch_path' => 'patch_type_planification', 'columns' => [
                ['dataField' => 'categorie_planif_name', 'caption' => 'Catégorie planification', 'allowEditing'=> false, 'width' => '180px'],
                ['dataField' => 'code', 'caption' => 'Code', 'sortOrder' => 'asc', 'alignment' => 'left', 'allowEditing'=> false],
                ['dataField' => 'code_court', 'caption' => 'Code court', 'allowEditing'=> false],
                ['dataField' => 'libelle', 'caption' => 'Libelle', 'allowEditing'=> false, 'width' => '280px'],
                ['dataField' => 'libelle_fact', 'caption' => 'Libelle facture', 'allowEditing'=> false, 'width' => '280px'],
                ['dataField' => 'nb_agent', 'caption' => 'Nombre agent'],
                ['dataField' => 'type_duree.id', 'caption' => 'Type durée',
                    'dataType' => 'number',
                    'alignment' => 'left',
                    'lookup' => [
                        'dataSource'=>  "common.createCustomStore('TypeDuree')",
                        'displayExpr'=> "libelle",
                        'valueExpr'=> "id",
                    ],
                    'validationRules' => [["type" =>'required']],
//                    'allowEditing'=> false
                ],
                ['dataField' => 'duree', 'caption' => 'Durée'],
                ['dataField' => 'type_appareil_IDs', 'caption' => 'Type appareil',  'width' => '180px', 'alignment' => 'center',
                    'encodeHtml' => false,
                    'fieldDisplay' => 'libelle',
                    'calculateDisplayValue' => true,
                    'calculateFilterExpression' => true,
                    'onEditorPrepared' => 'Voir les types d\'appareil'
                ],
                ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center', 'width' => '80px'],
                ['dataField' => 'couleur', 'caption' => 'Couleur', 'allowEditing'=> false, 'alignment' => 'center', 'width' => '80px'],
            ],
                'rang_tri' => false,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  false, 'allowAdding' => false, 'useIcons' => true],
                'onEditorPreparing' => ['type_appareil_IDs' => ['datas' => $typeAppareils, 'field' => 'libelle', 'getData' => 'TypeAppareil']]
            ],
            ['name' => 'Absence', 'entityName' => 'InterventionMotifAbsence', 'patch_path' => 'patch_intervention_motif_absence', 'columns' => [
                ['dataField' => 'libelle', 'caption' => 'Libelle', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50]],
                ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
            ],
                'rang_tri' => false,
                'columnAutoWidth' => true,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
            ],
            ['name' => 'Maladie', 'entityName' => 'EvenementObjet', 'create_path' => 'patch_evenement_objet', 'patch_path' => 'patch_evenement_objet', 'param' => $typePlanificationMaladie->getId(), 'columns' => [
                ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
            ],
                'get_path' => $this->generateUrl('get_evenement_objets', ['idtype_planification' => $typePlanificationMaladie->getId()]),
                'rang_tri' => false,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
            ],
            ['name' => 'Formation', 'template' => 'admin/list_datagrid_tab_navleft', 'navleft' => [
                ['id_onglet' => 'formation_theme', 'name' => 'Thèmes', 'entityName' => 'Formation', 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 80], 'width' => '550px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ],
                ['id_onglet' => 'formation_lieu', 'name' => 'Lieux', 'entityName' => 'EvenementLieu', 'create_path' => 'patch_evenement_lieu', 'patch_path' => 'patch_evenement_lieu', 'param' => $typePlanificationFormation->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_lieux', ['idtype_planification' => $typePlanificationFormation->getId()]),
                    'delete_path' => $this->generateUrl('delete_evenement_lieu'),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ],
                ['id_onglet' => 'formation_organisme', 'name' => 'Organisme', 'entityName' => 'EvenementObjet', 'create_path' => 'patch_evenement_objet', 'patch_path' => 'patch_evenement_objet', 'param' => $typePlanificationFormation->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_objets', ['idtype_planification' => $typePlanificationFormation->getId()]),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ]]
            ],
            ['name' => 'Réunion', 'template' => 'admin/list_datagrid_tab_navleft', 'navleft' => [
                ['id_onglet' => 'reunion_theme', 'name' => 'Thèmes', 'entityName' => 'EvenementObjet', 'create_path' => 'patch_evenement_objet', 'patch_path' => 'patch_evenement_objet', 'param' => $typePlanificationReunion->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_objets', ['idtype_planification' => $typePlanificationReunion->getId()]),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ],
                ['id_onglet' => 'reunion_lieu', 'name' => 'Lieux', 'entityName' => 'EvenementLieu', 'create_path' => 'patch_evenement_lieu', 'patch_path' => 'patch_evenement_lieu', 'param' => $typePlanificationReunion->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_lieux', ['idtype_planification' => $typePlanificationReunion->getId()]),
                    'delete_path' => $this->generateUrl('delete_evenement_lieu'),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ]]
            ],
            ['name' => 'Test', 'template' => 'admin/list_datagrid_tab_navleft', 'navleft' => [
                ['id_onglet' => 'test_operation', 'name' => 'Opérations', 'entityName' => 'EvenementObjet', 'create_path' => 'patch_evenement_objet', 'patch_path' => 'patch_evenement_objet', 'param' => $typePlanificationTest->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_objets', ['idtype_planification' => $typePlanificationTest->getId()]),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ],
                ['id_onglet' => 'test_lieu','name' => 'Lieux', 'entityName' => 'EvenementLieu', 'create_path' => 'patch_evenement_lieu', 'patch_path' => 'patch_evenement_lieu', 'param' => $typePlanificationTest->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_lieux', ['idtype_planification' => $typePlanificationTest->getId()]),
                    'delete_path' => $this->generateUrl('delete_evenement_lieu'),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ]]
            ],
            ['name' => 'Voiture', 'template' => 'admin/list_datagrid_tab_navleft', 'navleft' => [
                ['id_onglet' => 'voiture_operation', 'name' => 'Opérations', 'entityName' => 'EvenementObjet', 'create_path' => 'patch_evenement_objet', 'patch_path' => 'patch_evenement_objet', 'param' => $typePlanificationVoiture->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_objets', ['idtype_planification' => $typePlanificationVoiture->getId()]),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ],
                ['id_onglet' => 'voiture_lieu','name' => 'Lieux', 'entityName' => 'EvenementLieu', 'create_path' => 'patch_evenement_lieu', 'patch_path' => 'patch_evenement_lieu', 'param' => $typePlanificationVoiture->getId(), 'columns' => [
                    ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                    ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                    ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
                ],
                    'get_path' => $this->generateUrl('get_evenement_lieux', ['idtype_planification' => $typePlanificationVoiture->getId()]),
                    'delete_path' => $this->generateUrl('delete_evenement_lieu'),
                    'rang_tri' => false,
                    'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
                ]]
            ],
            ['name' => 'Initiative', 'entityName' => 'PlanningInitiativeDetail', 'columns' => [
                ['dataField' => 'planning_initiative_type.id', 'caption' => 'Type initiative',
                    'dataType' => 'number',
                    'alignment' => 'left',
                    'lookup' => [
                        'dataSource'=>  "common.createCustomStore('PlanningInitiativeType')",
                        'displayExpr'=> "libelle",
                        'valueExpr'=> "id",
                        ],
                    'validationRules' => [["type" =>'required']],
                    'allowEditing'=> true,
                ],
                ['dataField' => 'nom', 'caption' => 'Nom', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50]],
                ['dataField' => 'prenom', 'caption' => 'Prénom', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50]],
                ['dataField' => 'societe', 'caption' => 'Société', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50]],
                ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
            ],
                'rang_tri' => false,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
            ],
            ['name' => 'Réserve', 'entityName' => 'EvenementObjet', 'create_path' => 'patch_evenement_objet', 'patch_path' => 'patch_evenement_objet', 'param' => $typePlanificationReserve->getId(), 'columns' => [
                ['dataField' => 'libelle_court', 'caption' => 'Libelle court', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 20], 'width' => '200px'],
                ['dataField' => 'libelle_long', 'caption' => 'Libelle long', 'sortOrder' => 'asc', 'alignment' => 'left', 'editorOptions' => ['maxLength' => 50], 'width' => '400px'],
                ['dataField' => 'actif', 'dataType' => 'boolean', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center'],
            ],
                'get_path' => $this->generateUrl('get_evenement_objets', ['idtype_planification' => $typePlanificationReserve->getId()]),
                'rang_tri' => false,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  true, 'allowAdding' => true]
            ]
        ];
        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

    /**
     * @Route("/agence", methods="GET", name="list_agence")
     */
    public function listAgence(): Response
    {

        $tabs = [
            [
                'columns' => [
                    ['dataField' => 'site.id', 'caption' => 'Site',
                        'dataType' => 'number',
                        'alignment' => 'left',
                        'lookup' => [
                            'dataSource'=>  "common.createCustomStore('Site')",
                            'displayExpr'=> "nom",
                            'valueExpr'=> "id",
                        ],
                        'validationRules' => [["type" =>'required']]
                    ],
                    ['dataField' => 'nom', 'caption' => 'Nom', 'editorOptions' => ['maxLength' => 30]],
                    ['dataField' => 'raison_sociale', 'caption' => 'Raison sociale', 'editorOptions' => ['maxLength' => 40]],
                    ['dataField' => 'type_societe', 'caption' => 'Type société', 'editorOptions' => ['maxLength' => 40]],
                    ['dataField' => 'banque', 'caption' => 'Banque', 'editorOptions' => ['maxLength' => 20]],
                    ['dataField' => 'num_tel', 'caption' => 'Téléphone'],
                    ['dataField' => 'code_client_agi', 'caption' => 'Code AGI', 'editorOptions' => ['maxLength' => 9]],
                    ['dataField' => 'privilege', 'caption' => 'Opération privilège', 'dataType' => 'boolean', 'width' => '150px', 'lookup' => ['valueExpr' => 'value', 'displayExpr' => 'text','dataSource' => [['value' => true, 'text' => 'Actif'], ['value'=> false, 'text' => "Inactif"]]], 'alignment' => 'center']
                ],
                'name' => 'Agences',
                'entityName' => 'Agence',
                'rang_tri' => false,
                'editing' => [ 'mode' => "row", 'allowUpdating' => true,  'allowDeleting' =>  false, 'allowAdding' => true]
            ]
        ];

        return $this->render('admin/list.html.twig', ['datagrid_style' => 'tab', 'tabs' => $tabs]);
    }

}


